mathlib4 icon indicating copy to clipboard operation
mathlib4 copied to clipboard

feat: use @[csimp] to use exponentiation by repeated squaring at runtime

Open kim-em opened this issue 1 year ago • 3 comments

Using a @[csimp] attribute we can replace npowRec at runtime with an algorithm that uses repeated squaring, without affecting the definitional properties of npowRec.

The prototypical application is that

#eval (3 : ZMod 49999)^49998

used to stack overflow, but now runs fine.

(This is an output of the "Formalization and Computer Algebra Systems" group at https://aimath.org/workshops/upcoming/cyberinfrastructure/.)


  • [x] depends on: #8884

Open in Gitpod

kim-em avatar Dec 08 '23 00:12 kim-em

This PR/issue depends on:

  • ~~leanprover-community/mathlib4#8884~~ By Dependent Issues (🤖). Happy coding!

I believe everyone's concerns have been addressed. There other PR (https://github.com/leanprover-community/mathlib4/pull/9154) is a few dependent PRs deep. I don't think it makes sense to wait.

Please address the merge conflicts created by #6262 removing the default values for npow and zpow and then send it off.

Thanks. I think this is really great for connections to computation.

bors delegate+

mattrobball avatar Mar 09 '24 14:03 mattrobball

:v: semorrison can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

mathlib-bors[bot] avatar Mar 09 '24 14:03 mathlib-bors[bot]

If anyone would like to take over this PR, I'd be happy!

kim-em avatar Apr 24 '24 03:04 kim-em

PR summary ba89098f97

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ k + npowBinRec + npowBinRec.go_spec + npowBinRecAuto + npowRec' + npowRec'_mul_comm + npowRec'_succ + npowRec'_two_mul + npowRecAuto + npowRec_eq + npowRec_eq_npowBinRec + nsmulBinRec + nsmulRec' + nsmulRec_eq_nsmulBinRec + p

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.

github-actions[bot] avatar Oct 15 '24 20:10 github-actions[bot]

bors d+

j-loreaux avatar Oct 15 '24 20:10 j-loreaux

:v: kim-em can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

mathlib-bors[bot] avatar Oct 15 '24 20:10 mathlib-bors[bot]

bors d=mattrobball

j-loreaux avatar Oct 15 '24 20:10 j-loreaux

:v: mattrobball can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

mathlib-bors[bot] avatar Oct 15 '24 20:10 mathlib-bors[bot]

bors merge

mattrobball avatar Oct 15 '24 22:10 mattrobball

Pull request successfully merged into master.

Build succeeded:

mathlib-bors[bot] avatar Oct 15 '24 23:10 mathlib-bors[bot]