Skip to content

Update to Int.Fast#1276

Draft
LorenzoMolena wants to merge 2 commits intoagda:masterfrom
LorenzoMolena:fast-int-update
Draft

Update to Int.Fast#1276
LorenzoMolena wants to merge 2 commits intoagda:masterfrom
LorenzoMolena:fast-int-update

Conversation

@LorenzoMolena
Copy link
Contributor

This PR introduces the Fast counterparts of the modules in Cubical.Data.Int, together with the relevant order and algebraic instances.
The code is complete and typechecks, but I'm marking it as draft until a few design questions are clarified:

  • Folder organization: currently the Fast modules live inside the Int directory, but placing a Fast folder directly under Cubical.Data is also an option, and the same question applies to the instances.
  • Upcoming PR for fast rationals: I plan to submit a follow-up PR implementing fast rationals. Since rationals have fewer dependencies than integers, with little effort I should be able to replace the current implementation so that it uses the fast integer operations. Would such a replacement be welcome, or would you prefer a separate Fast namespace? In the latter case, I could also experiment with defining rational operations that prenormalize their arguments.
  • Implicit arguments in Int.Fast.Order: I noticed that many properties in Int.Fast.Order have implicit variables that are harder for Agda to infer compared to their non-fast counterparts. Should I make these arguments explicit, or keep the signatures identical for better drop-in compatibility when switching between Int and Int.Fast?

I should also note that this PR depends on #1270, #1271, and #1272.

I would greatly appreciate the maintainers' perspectives on these points. @mortberg @felixwellen @ecavallo

* add fast implementation of integers and their properties

* move properties of min and max over `ℕ` to the appropriate file

* reorganize and format code

* remove `--safe` flag

* remove `--safe` flag

* Fast int (#2)

* direct solver application

* direct solver application

---------

Co-authored-by: Marcin Jan Turek-Grzybowski <marcinjangrzybowski@gmail.com>

* add fast implementation of integers and their properties

* move properties of min and max over `ℕ` to the appropriate file

* reorganize and format code

* remove `--safe` flag

* remove `--safe` flag

* remove `--safe` flag

* Fast int (#2)

* direct solver application

* direct solver application

---------

Co-authored-by: Marcin Jan Turek-Grzybowski <marcinjangrzybowski@gmail.com>

* fix compatibility with the library

* fix compatibility after rebase, start proving properties of fast integer min and max

* add instances of `Nat` and `Int` as `Pseudolattice`, and of `Int` as `OrderedCommRing`

* fix typo, add better make from Posets to Pseudolattices

* update `makePseudolatticeFromPoset` and instances built using it

* move `maxLUB` and `minGLB` to `Data.Nat.Order`, remove unnecessary imports

* rewrite properties from `minAssoc` to `-max`, add temporary lemmas in `Nat`, add `UsingEq` into `min` and `max` over the Naturals

* fix naming clash on import

* rewrite properties from `pos+posLposMin` to `·DistNegsucLMax`

* start work on Order: adapt properties from `isProp≤` to `≤SumLeftPos`, add boolean order, suggest alternative definition `_≤'_`

* use more efficient implementation of quotient and remainder in `Int.Fast.Divisibility`

* adapt properties from `pred-≤-pred` to `0≤o→≤-·o`, move import of `Bool.Base` together with the other imports

* adapt properties from `<-·o` to `predℤ-≤-predℤ`

* adapt properties from `¬m+posk<m` to `<-+pos-trans`

* adapt properties from `<-pos+-trans` to `0<o→≤-·o-cancel`

* adapt properties from `≤-o·-cancel` to `≤→min` ; add conversions between the order over the integers and the one over the naturals ; add `maxLUB`, `minGLB` , `≤→max` , `≤→min` to `Data.Nat.Order`

* adapt properties from `≤MonotoneMin` to `_≟'_` ; add faster `_≟_` and tests. This finishes (a first but complete version) of `Data.Int.Fast`

* edit `_≤'_` using recursive order, add `_≤ᵇ_` and `_≤''_`

* update `minIdem`

* clean comments, reorganize `Fast` modules, add more properties in `Int.Fast.Order`, add `Trichotomy` and `Ordering` in `BinaryRelation`

* add fixity for `_≤_` in `PseudolatticeStr`, add `Properties` file

* edit Fast using PL and OCR instances

* remove `minIdem`, use PL instance of `Nat` in the `Int.Fast.Order` module

* simplify some proofs, with additional converions between the order on Nat and the integer order between negsuc

* Add order related instances of `Fast.Int`

* revert addition of `Trichotomy` to `BinaryRelation`, add more tests to `Int.Fast.Order`

* add missing `'` on commented test code

* adapt instances of `Int` and `Int.Fast` as `OCR`, to the branch `ocr+pl-instances'`

---------

Co-authored-by: Ettore Forigo <ettore.forigo@gmail.com>
Co-authored-by: Marcin Jan Turek-Grzybowski <marcinjangrzybowski@gmail.com>
@LorenzoMolena LorenzoMolena marked this pull request as draft November 19, 2025 08:58
@LorenzoMolena
Copy link
Contributor Author

To keep things manageable, I’ve decided to split this PR according to the following plan:

  • First, I'll submit a PR without the Order module (and all the modules depending on it).
  • Then, @marcinjangrzybowski will follow up with a PR introducing solvers for ring equations on fast integers (already present in Book cauchy reals #1182, and briefly discussed during last month's AIM)
  • Finally, I'll submit a PR adding the Order module (and the related instances for order structures), using @marcinjangrzybowski's solver to simplify many proofs.

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.

1 participant