-
Notifications
You must be signed in to change notification settings - Fork 9
Task 96 #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Task 96 #189
Conversation
| (eratosthenes_sieve.go n sieve 2).toList.mergeSort | ||
| where | ||
| go (n : Nat) (sieve : Std.HashSet Nat) (curr : Nat) := | ||
| if curr < n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only go up to sqrt n if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not available without batteries. I could copy this over though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just check for curr * curr < n.
| if curr < n | ||
| then | ||
| if curr ∈ sieve | ||
| then eratosthenes_sieve.go n (sieve.filter (fun x => (x = curr ∨ x % curr != 0))) (curr + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this has the right asymptotic complexity. The filtering step takes time proportional to the number of remaining elements in sieve. In the usual sieve of Eratosthenes, you iterate from curr^2 to n with step size curr, so the time taken is proportional to something like (n - curr^2)/curr, which I think is faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I think that this is the same fundamental difference that is described in section 2 of https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf.
This PR implements the solution for task 96 using a sieve construction. I currently struggle a bit with the best definition for the primes that make the proofs simple.