Skip to content

feat: use nat_pow in the kernel#2310

Merged
leodemoura merged 1 commit intoleanprover:masterfrom
kim-em:nat_pow_in_kernel
Jul 10, 2023
Merged

feat: use nat_pow in the kernel#2310
leodemoura merged 1 commit intoleanprover:masterfrom
kim-em:nat_pow_in_kernel

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Jul 6, 2023

Enable using the existing lean_nat_pow function in the kernel.

This enables mathlib4's Mersenne prime checker to get beyond 2^23209 - 1 (from 1979). It's now done 2^216091 - 1 (from 1985), and I suspect that the current implementation, plus this tweak, would be sufficient to get (slowly) to the modern era if someone wanted to spend the CPU time.

bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request Jul 9, 2023
Alternative to leanprover/lean4#2310. The original implementation of the pow extension would force a `Nat.pow` application by defeq, but this should only be done for kernel-approved definitions and `Nat.pow` is not one of them. Rather than adding more things to the kernel, we can implement an efficient pow implementation by binary recursion, using the clauses:

* `a ^ (2*b) = a^b * a^b`
* `a ^ (2*b + 1) = a^b * a^b * a`



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@leodemoura leodemoura merged commit 60b8fdd into leanprover:master Jul 10, 2023
@digama0
Copy link
Copy Markdown
Collaborator

digama0 commented Jul 10, 2023

@leodemoura Just so you know, after this PR I posted a fix to norm_num (linked above) which solves the motivating issue for this change (it was not supposed to be as slow as it was). This modification is still a ~2x performance boost over building proof terms as in the linked issue, but it is no longer the 1000x improvement quoted in the PR description. I am okay with either keeping the new function or reverting it, but it is not essential to us.

@digama0
Copy link
Copy Markdown
Collaborator

digama0 commented Jul 10, 2023

There is also a missing Nat.pow around here.

kim-em added a commit to leanprover-community/mathlib4 that referenced this pull request Aug 14, 2023
Alternative to leanprover/lean4#2310. The original implementation of the pow extension would force a `Nat.pow` application by defeq, but this should only be done for kernel-approved definitions and `Nat.pow` is not one of them. Rather than adding more things to the kernel, we can implement an efficient pow implementation by binary recursion, using the clauses:

* `a ^ (2*b) = a^b * a^b`
* `a ^ (2*b + 1) = a^b * a^b * a`



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants