Skip to content
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

[Merged by Bors] - feat(number_theory/lucas_lehmer): prime (2^127 - 1) #2842

Closed
wants to merge 89 commits into from

Conversation

semorrison
Copy link
Collaborator

This PR

  1. proves the sufficiency of the Lucas-Lehmer test for Mersenne primes
  2. provides a tactic that uses norm_num to do each step of the calculation of Lucas-Lehmer residues
  3. proves 2^127 - 1 = 170141183460469231731687303715884105727 is prime

It doesn't

  1. prove the necessity of the Lucas-Lehmer test (mathlib certainly has the necessary material if someone wants to do this)
  2. use the trick n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1] that is essential to calculating Lucas-Lehmer residues quickly
  3. manage to prove any "computer era" primes are prime! (Although my guess is that 2^521 - 1 would run in <1 day with the current implementation.)

I think using "the trick" is very plausible, and would be a fun project for someone who wanted to experiment with certified/fast arithmetic in Lean. It likely would make much larger Mersenne primes accessible.

This is a tidy-up and completion of work started by a student, Ainsley Pahljina.

@semorrison
Copy link
Collaborator Author

I've moved the examples (except for two very trivial and fast ones) to the archive/examples/ directory, and added cross-references in both directions.

@sgouezel
Copy link
Collaborator

sgouezel commented Jun 4, 2020

This looks good to me now. Are there still comments, or can we merge it?

Copy link
Collaborator

@bryangingechen bryangingechen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor docstring formatting suggestions.

archive/examples/mersenne_primes.lean Show resolved Hide resolved
src/number_theory/lucas_lehmer.lean Outdated Show resolved Hide resolved
src/number_theory/lucas_lehmer.lean Outdated Show resolved Hide resolved
src/number_theory/lucas_lehmer.lean Outdated Show resolved Hide resolved
src/number_theory/lucas_lehmer.lean Outdated Show resolved Hide resolved
src/number_theory/lucas_lehmer.lean Outdated Show resolved Hide resolved
bryangingechen and others added 2 commits June 5, 2020 07:38
Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com>
@jcommelin
Copy link
Member

Let's get this merged!

@robertylewis
Copy link
Member

I took the liberty of shortening a few proofs.

There are quite a few nonterminal simps, but since the file is pretty self contained, I think they'll only break if/when someone edits this development. So I won't complain too much.

On where the tutorials belong: the current setup is fine for now. Ideally, I think someone shouldn't have to read the mathlib source code to figure out how to use a certain interface. If an interface demands explanation beyond doc strings, the tutorials folder seems like the right place. Often these kinds of explanations aren't local to a single file ("how do I use linear algebra?" or "how do I use category theory"?). Spreading tutorial-style examples throughout the library makes it hard to find any of them, hard to generate html, hard to automatically link to them, etc. Certainly we're missing a lot of this kind of documentation right now. The tutorials folder is pretty empty.

bors merge

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Jun 6, 2020
bors bot pushed a commit that referenced this pull request Jun 6, 2020
This PR
1. proves the sufficiency of the Lucas-Lehmer test for Mersenne primes
2. provides a tactic that uses `norm_num` to do each step of the calculation of Lucas-Lehmer residues
3. proves 2^127 - 1 = 170141183460469231731687303715884105727 is prime

It doesn't
1. prove the necessity of the Lucas-Lehmer test (mathlib certainly has the necessary material if someone wants to do this)
2. use the trick `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]` that is essential to calculating Lucas-Lehmer residues quickly
3. manage to prove any "computer era" primes are prime! (Although my guess is that 2^521 - 1 would run in <1 day with the current implementation.)

I think using "the trick" is very plausible, and would be a fun project for someone who wanted to experiment with certified/fast arithmetic in Lean. It likely would make much larger Mersenne primes accessible.

This is a tidy-up and completion of work started by a student, Ainsley Pahljina.
@bors
Copy link

bors bot commented Jun 6, 2020

Build failed:

@robertylewis robertylewis removed the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Jun 6, 2020
@robertylewis
Copy link
Member

The build is failing now because of changes to the algebraic hierarchy.

@robertylewis robertylewis added the awaiting-author A reviewer has asked the author a question or requested changes label Jun 6, 2020
@bryangingechen bryangingechen removed the awaiting-author A reviewer has asked the author a question or requested changes label Jun 6, 2020
@bryangingechen
Copy link
Collaborator

bors r+

@github-actions github-actions bot added the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Jun 6, 2020
bors bot pushed a commit that referenced this pull request Jun 6, 2020
This PR
1. proves the sufficiency of the Lucas-Lehmer test for Mersenne primes
2. provides a tactic that uses `norm_num` to do each step of the calculation of Lucas-Lehmer residues
3. proves 2^127 - 1 = 170141183460469231731687303715884105727 is prime

It doesn't
1. prove the necessity of the Lucas-Lehmer test (mathlib certainly has the necessary material if someone wants to do this)
2. use the trick `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]` that is essential to calculating Lucas-Lehmer residues quickly
3. manage to prove any "computer era" primes are prime! (Although my guess is that 2^521 - 1 would run in <1 day with the current implementation.)

I think using "the trick" is very plausible, and would be a fun project for someone who wanted to experiment with certified/fast arithmetic in Lean. It likely would make much larger Mersenne primes accessible.

This is a tidy-up and completion of work started by a student, Ainsley Pahljina.
@bors
Copy link

bors bot commented Jun 6, 2020

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Jun 6, 2020
This PR
1. proves the sufficiency of the Lucas-Lehmer test for Mersenne primes
2. provides a tactic that uses `norm_num` to do each step of the calculation of Lucas-Lehmer residues
3. proves 2^127 - 1 = 170141183460469231731687303715884105727 is prime

It doesn't
1. prove the necessity of the Lucas-Lehmer test (mathlib certainly has the necessary material if someone wants to do this)
2. use the trick `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]` that is essential to calculating Lucas-Lehmer residues quickly
3. manage to prove any "computer era" primes are prime! (Although my guess is that 2^521 - 1 would run in <1 day with the current implementation.)

I think using "the trick" is very plausible, and would be a fun project for someone who wanted to experiment with certified/fast arithmetic in Lean. It likely would make much larger Mersenne primes accessible.

This is a tidy-up and completion of work started by a student, Ainsley Pahljina.
@bors
Copy link

bors bot commented Jun 6, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(number_theory/lucas_lehmer): prime (2^127 - 1) [Merged by Bors] - feat(number_theory/lucas_lehmer): prime (2^127 - 1) Jun 6, 2020
@bors bors bot closed this Jun 6, 2020
@bors bors bot deleted the lucas_lehmer2 branch June 6, 2020 18:14
cipher1024 pushed a commit to cipher1024/mathlib that referenced this pull request Mar 15, 2022
…nity#2842)

This PR
1. proves the sufficiency of the Lucas-Lehmer test for Mersenne primes
2. provides a tactic that uses `norm_num` to do each step of the calculation of Lucas-Lehmer residues
3. proves 2^127 - 1 = 170141183460469231731687303715884105727 is prime

It doesn't
1. prove the necessity of the Lucas-Lehmer test (mathlib certainly has the necessary material if someone wants to do this)
2. use the trick `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]` that is essential to calculating Lucas-Lehmer residues quickly
3. manage to prove any "computer era" primes are prime! (Although my guess is that 2^521 - 1 would run in <1 day with the current implementation.)

I think using "the trick" is very plausible, and would be a fun project for someone who wanted to experiment with certified/fast arithmetic in Lean. It likely would make much larger Mersenne primes accessible.

This is a tidy-up and completion of work started by a student, Ainsley Pahljina.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants