Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

[Merged by Bors] - feat(number_theory): Bertrand's postulate, slightly different approach #8002

Closed
wants to merge 507 commits into from

Conversation

Smaug123
Copy link
Collaborator

@Smaug123 Smaug123 commented Jun 19, 2021

@Smaug123 Smaug123 added the WIP Work in progress label Jun 19, 2021
Copy link
Collaborator

@adomani adomani left a comment

Choose a reason for hiding this comment

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

I started looking at this PR and I am very happy that you are working on Bertrand's postulate! At the moment, I only have some golfing suggestions.

src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
@jcommelin jcommelin changed the title Bertrand's postulate, slightly different approach feat(number_theory): Bertrand's postulate, slightly different approach Jun 21, 2021
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
@Smaug123
Copy link
Collaborator Author

Good luck proving log 584 + 2 ≤ 8 - it's not true! The LHS is 8.3699.

@BoltonBailey
Copy link
Collaborator

@github-actions github-actions bot added the blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. label Aug 16, 2021
bors bot pushed a commit that referenced this pull request Aug 26, 2021
…8667)

This PR is for a new lemma (currently called `exp_bound'`) which proves `exp x` is close to its `n`th degree taylor expansion for sufficiently large `n`. Unlike the previous bound, this lemma can be instantiated on any real `x` rather than just `x` with absolute value less than or equal to 1. I am separating this lemma out from #8002 because I think it stands on its own.

The last time I checked it was sorry free - but that was before I merged with master and moved it to a different branch. It may also benefit from a little golfing.

There are a few lemmas I proved as well to support this - one about the relative size of factorials and a few about sums of geometric sequences. The ~~geometric series ones should probably be generalized and moved to another file~~ this generalization sort of exists and is in the algebra.geom_sum file. I didn't find it initially since I was searching for "geometric" not "geom".
@github-actions github-actions bot added merge-conflict Please `git merge origin/master` then a bot will remove this label. and removed blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. merge-conflict Please `git merge origin/master` then a bot will remove this label. labels Aug 26, 2021
@github-actions github-actions bot added the blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. label Sep 8, 2021
@github-actions github-actions bot added the merge-conflict Please `git merge origin/master` then a bot will remove this label. label Nov 23, 2021
@github-actions github-actions bot removed the merge-conflict Please `git merge origin/master` then a bot will remove this label. label Dec 6, 2021
@BoltonBailey
Copy link
Collaborator

Update: Since being advised to tighten up the proof a little, I have been working on some things related to the prime counting function, so we can have a better bound on that if desired. Right now, I have gone through to comment out many of the calculus based proofs, some of which seem to have broken, and which shouldn't be necessary anyway if we go the "log x / x is decreasing" route. To that end I have redone the reification of the main inequality (see real_false_inequality_is_false). Notice that even without the tightening of the binomial coefficient bound and prime counting function from the Tochiori proof, we can still do Tochiori's last step of dividing through by x and using the same log x / x logic. It remains to be seen what n_big ends up as this way, but perhaps it's worth working through anyway.

@Smaug123
Copy link
Collaborator Author

Notice that even without the tightening of the binomial coefficient bound and prime counting function from the Tochiori proof, we can still do Tochiori's last step of dividing through by x and using the same log x / x logic.

We do actually have Tochiori's bounds already, in data.nat.choose.central. I've also got #9925 which I haven't looked at for a while, but that pulls out a couple more of the lemmas from this file into data.nat.choose.central.

bors bot pushed a commit that referenced this pull request Dec 30, 2021
…10985)

Adds lemma `log_div_self_antitone_on`, which shows that `log x / x` is decreasing when `exp 1 \le x`. Needed for Bertrand's postulate (#8002).
erdOne pushed a commit that referenced this pull request Jan 1, 2022
…10985)

Adds lemma `log_div_self_antitone_on`, which shows that `log x / x` is decreasing when `exp 1 \le x`. Needed for Bertrand's postulate (#8002).
@BoltonBailey
Copy link
Collaborator

Ok, after 6 or so months, this PR is once again compiling and sorry-free, now without derivatives. There are still things left to do in terms of making the tighter Tochiori bounds on the prime counting function and binomial coefficient so that we don't have to brute force a prime over 1024. Also, generally cleaning the proof up. Ideally, each of the statements in the main inequality chain should be isolated and extracted as their own lemmas, which are then chained together in a calc proof.

@Smaug123
Copy link
Collaborator Author

@BoltonBailey Thanks for plugging away at it! The PR will get shorter once #9925 is merged and we've integrated src/data/nat/choose/central.lean into this proof; it's basically a parallel cherry-picked development of the central binomial coefficient stuff, but it's already committed to mathlib.

Copy link
Member

@urkud urkud left a comment

Choose a reason for hiding this comment

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

Thanks a lot! LGTM modulo a few minor comments but I would prefer to have one more review before merging it.
UPD: @digama0 says that there is a better proof. I'm assigning this PR to him.

src/data/nat/choose/central.lean Outdated Show resolved Hide resolved
src/data/nat/choose/factorization.lean Outdated Show resolved Hide resolved
src/data/nat/choose/factorization.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
src/number_theory/bertrand.lean Outdated Show resolved Hide resolved
@BoltonBailey
Copy link
Collaborator

@digama0 To explain what's happened with this PR since we discussed it last, and why we haven't implemented all the tricks from the Tochiori paper: We did start on these, but I think we concluded that the main thing that was causing the cutoff n to be so high was loose reasoning in the main part of the proof. After fixing these and using your proof that ln x / x is decreasing, the cutoff dropped to about n >= 700, at which point the prime-checking wasn't really the main bottleneck. So at that point I stopped working on the Tochiori lemmas and just went about cleaning up the PR.

If you still feel that the cutoff should be around 64, I can follow through on the proof that prime_counting n <= n/3 + 2, which I think is the biggest part of the Tochiori reasoning for reducing the cutoff. But when I attempted a proof of this earlier, I found it involved a lot of casework, and I wasn't sure adding a few more 10s of lines to prove a specific bound like this would ultimately decrease the compilation time.

@digama0
Copy link
Member

digama0 commented Jul 19, 2022

The prime checking is not the bottleneck, the issue is the proof of the asymptotic part. Tochiori's proof both lowers the bound and also works out numerically much better, without the need for huge high precision estimates of log.

@tb65536
Copy link
Collaborator

tb65536 commented Jul 19, 2022

The prime checking is not the bottleneck, the issue is the proof of the asymptotic part. Tochiori's proof both lowers the bound and also works out numerically much better, without the need for huge high precision estimates of log.

Tochiori's proof sounds nice. But where does the current proof use high precision estimates of log?

@BoltonBailey
Copy link
Collaborator

Tochiori's proof sounds nice. But where does the current proof use high precision estimates of log?

I think @digama0 may be thinking of a version of the proof from before you came and switched out the proof we had with the one using the concavity of sqrt * log. Indeed at many points in the past the proof has used estimates from the file data/complex/exponential_bounds. The concavity of sqrt * log doesn't use these though, so I think the proof now no longer depends on them. Indeed, it seems like switching away from the Tochiori style where we apply antitonicity of log x / x saved about 20 seconds of compilation time, comparing commit 8703762 to the current one and running set_option profiler true on the real inequality and its dependencies, the time for the Tochiori version was about ~30 sec, whereas now it's about ~8 sec.

In fact, even if I ignore the runtime from the lemmas in the Tochiori version which use the exponential bounds, I still get that the current version is about 10 seconds faster. I'm not sure it makes sense to switch back, given that it would apparently increase the running time.

@jcommelin
Copy link
Member

@digama0 🏓

@digama0
Copy link
Member

digama0 commented Jul 31, 2022

@BoltonBailey The proof does indeed look a lot better now. I gave it a once-over, a mix of golfing, optimization, and unpacking some long lines, and now the whole file compiles in about 4 seconds, comparable to much more basic files, which is a testament to all the work that went into improving those bounds. Congratulations!

bors r+

@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 Jul 31, 2022
bors bot pushed a commit that referenced this pull request Jul 31, 2022
#8002)

Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
@bors
Copy link

bors bot commented Jul 31, 2022

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(number_theory): Bertrand's postulate, slightly different approach [Merged by Bors] - feat(number_theory): Bertrand's postulate, slightly different approach Jul 31, 2022
@bors bors bot closed this Jul 31, 2022
@bors bors bot deleted the bertrand-2 branch July 31, 2022 12:35
robertylewis pushed a commit that referenced this pull request Aug 2, 2022
#8002)

Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
khwilson pushed a commit that referenced this pull request Aug 2, 2022
#8002)

Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.