-
Notifications
You must be signed in to change notification settings - Fork 41
feat(fields): add fast Mersenne31 arithmetic #257
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
26213cc
feat(fields): add Mersenne31 field scaffold
varunthakore c04266d
feat(fields): implement fast Mersenne31 arithmetic
varunthakore 3f3e409
chore(fields): add comments
varunthakore f0c0a3f
refactor(fields): modularize Mersenne31 basic and fast implementations
varunthakore 34021d7
doc(fields): add Mersenne31 to readme
varunthakore 5068d4c
test(fields): add Mersenne31 tests
varunthakore d6e4881
Merge branch 'main' into mersenne31
dhsorens 4f57ff2
fix(fields): export Mersenne compatibility module
dhsorens 1a7a8e5
Merge branch 'main' into mersenne31
dhsorens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,16 @@ | ||
| /- | ||
| Copyright (c) 2024 ArkLib Contributors. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Quang Dao | ||
| Authors: Quang Dao, Varun Thakore | ||
| -/ | ||
| module | ||
|
|
||
| public import CompPoly.Fields.PrattCertificate | ||
| public import CompPoly.Fields.Mersenne31 | ||
|
|
||
| /-! | ||
| # Mersenne prime field `2^{31} - 1` | ||
| # Deprecated Mersenne31 compatibility import | ||
|
|
||
| This is the field used in Circle STARKs. | ||
| This module re-exports `CompPoly.Fields.Mersenne31` for compatibility with the former import path. | ||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Mersenne31 | ||
|
|
||
| @[reducible] | ||
| def fieldSize : Nat := 2 ^ 31 - 1 | ||
|
|
||
| abbrev Field := ZMod fieldSize | ||
|
|
||
| theorem is_prime : Nat.Prime fieldSize := by | ||
| unfold fieldSize | ||
| pratt | ||
|
|
||
| end Mersenne31 | ||
| deprecated_module "Use `CompPoly.Fields.Mersenne31` instead" (since := "2026-08-25") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /- | ||
| Copyright (c) 2024 CompPoly Contributors. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Quang Dao, Varun Thakore | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import CompPoly.Fields.Mersenne31.Basic | ||
| public import CompPoly.Fields.Mersenne31.Fast | ||
|
|
||
| /-! | ||
| # Mersenne31 prime field `2^{31} - 1` | ||
|
|
||
| Facade module for the Mersenne31 field. It re-exports the canonical `ZMod` model | ||
| from `CompPoly.Fields.Mersenne31.Basic` and the native-word implementation from | ||
| `CompPoly.Fields.Mersenne31.Fast`. | ||
| -/ | ||
|
|
||
| @[expose] public section | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /- | ||
| Copyright (c) 2024 CompPoly Contributors. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Quang Dao, Varun Thakore | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import CompPoly.Fields.Basic | ||
| public import CompPoly.Fields.PrattCertificate | ||
|
|
||
| /-! | ||
| # Mersenne prime field `2^{31} - 1` | ||
|
|
||
| This is the field used in Circle STARKs. | ||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Mersenne31 | ||
|
|
||
| /-- The Mersenne31 prime modulus `2^31 - 1`. -/ | ||
| @[reducible] | ||
| def fieldSize : Nat := 2 ^ 31 - 1 | ||
|
|
||
| /-- The canonical mathematical Mersenne31 field, implemented as integers modulo | ||
| `fieldSize`. -/ | ||
| abbrev Field := ZMod fieldSize | ||
|
|
||
| /-- The Mersenne31 modulus is prime, verified by a Pratt certificate. -/ | ||
| theorem is_prime : Nat.Prime fieldSize := by | ||
| unfold fieldSize | ||
| pratt | ||
|
|
||
| /-- Register primality of `fieldSize` for Mathlib instances such as `ZMod.instField`. -/ | ||
| instance : Fact (Nat.Prime fieldSize) := ⟨is_prime⟩ | ||
|
|
||
| /-- The canonical Mersenne31 carrier is a field because its modulus is prime. -/ | ||
| instance : _root_.Field Field := ZMod.instField fieldSize | ||
|
|
||
| /-- Mersenne31 has characteristic different from two. -/ | ||
| instance : NonBinaryField Field where | ||
| char_neq_2 := by | ||
| -- `decide` can discharge this concrete ZMod equality. | ||
| simpa [Field, fieldSize] using | ||
| (by decide : (2 : ZMod (2 ^ 31 - 1)) ≠ 0) | ||
|
|
||
| end Mersenne31 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.