Repository navigation
feat(NumberTheory): decide, #eval and norm_num for Carmichael numbers - #43965
YaelDillies wants to merge 10 commits into
Conversation
…umbers Provide both an efficient decidability instance and a `norm_num` extension to decide whether a given literal is a Carmichael number. This lets us prove that 561 is the smallest Carmichael number "in a computationally efficient manner". Generated by Claude Opus in several rounds of review to optimise various parts of the algorithms and make sure that the decidability instance works for both `#eval` and `decide`. I haven't made much of an effort to clean the proofs (existing proofs internal to `norm_num` read like garbage to me anyway). From FormalConjectures Assisted-by: Claude Opus 5.1
PR summary e3971fcc0eImport changes for modified filesNo significant changes to the import graph Import changes for all files
|
|
!bench |
|
Benchmark results for a12253a against f61f3ed are in. No significant results found. @SnirBroshi
Small changes (2🟥)
|
|
This pull request has conflicts, please merge |
joneugster
left a comment
There was a problem hiding this comment.
The PR is on the larger side for reviewing, but overall it looks good to me, thanks!
| if m % d = 0 then | ||
| (n - 1) % (d - 1) == 0 && m / d % d != 0 && korseltAux n fuel (m / d) (d + 2) true | ||
| else korseltAux n fuel m (d + 2) c |
There was a problem hiding this comment.
I'm a bit confused by the incosistent usage of = 0 and == 0. It also seems that the proof breaks very easily if you change any of these into the other form.
Could you make this more consistent and robust?
There was a problem hiding this comment.
(I'll unresolve this for context, no action needed)
Thanks for making this consistent. I wasn't quite aware how ugly the boolean version would look like, but that is a separate issue...
|
Thanks! maintainer merge |
|
🚀 Pull request has been placed on the maintainer queue by joneugster. |
Vierkantor
left a comment
There was a problem hiding this comment.
It is very nice to have decision procedures for this! Unfortunately I find this PR rather hard to read... A thorough cleanup and documentation (references!) pass would be good before merging.
|
|
||
| It is defined by structural recursion on `fuel`, so that it can be evaluated by `decide`. See | ||
| `Nat.korseltAux_eq_true_iff` for the conditions under which it is correct. -/ | ||
| def korseltAux (n fuel m d : ℕ) (c : Bool) : Bool := |
There was a problem hiding this comment.
Is this some known algorithm (by Korselt, I assume)? Could you add a citation?
There was a problem hiding this comment.
I came up with the algorithm, but it is the obvious one if you think of how to use Korselt's criterion to quickly check carmichaelness
| have : p ≠ d + 1 := by rintro rfl; have := hp.eq_two_or_odd; lia | ||
| lia | ||
|
|
||
| theorem korseltAux_iff {n fuel m d : ℕ} {c : Bool} (hd : 3 ≤ d) (hdo : d % 2 = 1) |
There was a problem hiding this comment.
I have a hard time trying to read this theorem statement, a docstring could help here (but even better would be explaining what korseltAux is trying to do).
There was a problem hiding this comment.
How is this now?
| simp +contextual [← Nat.dvd_iff_mod_eq_zero, hmp, hmp.prime, prime_dvd_prime_iff_eq, | ||
| forall_comm] | ||
| -- when `fuel = 0`, the remaining goal contradicts `hfuel` | ||
| all_goals try exact absurd hfuel (by lia [d.le_mul_self]) |
There was a problem hiding this comment.
I'm not sure why all_goals try can't be replaced with any_goals but it does show how the proof state is very hard to control here.
There was a problem hiding this comment.
This is because at this point we are both in the zero and succ branches of the induction on fuel, and exact absurd hfuel (by lia [d.le_mul_self]) fails on all goals in the succ branch. I could make the branches disjoint by duplicating the 10 lines that come before, but the current situation felt better.
Provide both an efficient decidability instance and a
norm_numextension to decide whether a given literal is a Carmichael number.This lets us prove that 561 is the smallest Carmichael number "in a computationally efficient manner". Deprecate the version of Korselt's criterion that was supposed to be used for this (but was less efficient than these new instance/extension).
Generated by Claude Opus in several rounds of review to optimise various parts of the algorithms and make sure that the decidability instance works for both
#evalanddecide. I haven't made much of an effort to clean the proofs (existing proofs internal tonorm_numread like garbage to me anyway).From FormalConjectures
Assisted-by: Claude Opus 5.1