Skip to content

Book cauchy reals#1182

Draft
marcinjangrzybowski wants to merge 34 commits intoagda:masterfrom
marcinjangrzybowski:book-cauchy-reals
Draft

Book cauchy reals#1182
marcinjangrzybowski wants to merge 34 commits intoagda:masterfrom
marcinjangrzybowski:book-cauchy-reals

Conversation

@marcinjangrzybowski
Copy link
Contributor

@marcinjangrzybowski marcinjangrzybowski commented Jan 22, 2025

This is an implementation of real numbers as defined in Chapter 11.3: Cauchy Reals of the HoTT Book.
(Note: results 11.3.11 and 11.3.50 are currently missing.)

Modules:

  • Cubical/HITs/CauchyReals/Base.agda
  • Cubical/HITs/CauchyReals/Closeness.agda
  • Cubical/HITs/CauchyReals/Continuous.agda
  • Cubical/HITs/CauchyReals/Inverse.agda
  • Cubical/HITs/CauchyReals/Lems.agda
  • Cubical/HITs/CauchyReals/Lipschitz.agda
  • Cubical/HITs/CauchyReals/Multiplication.agda
  • Cubical/HITs/CauchyReals/Order.agda

These modules closely follow the book. However, I had to adjust the order of definitions due to the issue discussed here: HoTT/book#899.

Additionally, the following modules:

  • Cubical/HITs/CauchyReals/Sequence.agda
  • Cubical/HITs/CauchyReals/Derivative.agda

are attempts to benchmark the definitions and evaluate their behavior. In Derivative.agda, I've managed to derive the Power rule (for natural exponents). In Sequence.agda, I defined exp (currently only for ℚ₊), allowing the definition of e.

To implement these properly (assuming we want to continue without countable choice or LEM), I plan to consult some books on constructive analysis. The HoTT Book references "Errett Bishop. Foundations of Constructive Analysis," but I welcome other suggestions.

While the development is not yet up to library standards, everything currently type checks. I will likely split this into smaller PRs. There is one remaining definition, invℝ, hidden behind abstract. However, I have a promising idea based on previous optimizations to expose it (or at least manage its evaluation more controllably by guarding it with lockUnit).

There is some redundancy, as I am still experimenting with different versions of definitions.

TODO:

  • Implement square root
  • Implement chain rule
  • Complete results 11.3.11 and 11.3.50 from the HoTT Book
  • Extend exp to all reals and provide a characterization
  • Properly generalize convergence tests and add a few more
  • Define logarithm
  • Parameterize definitions by implementation of Rationals
  • Figure out a more elegant way to employ CommRingSolver (temporary solution in Cubical/HITs/CauchyReals/Lems.agda)

@felixwellen
Copy link
Collaborator

Congrats! This is great :-)
Why don't you use opaque instead of abstract?

@marcinjangrzybowski
Copy link
Contributor Author

I did not saw opaque utilised too much thru the library, did not considered it really :), will do now thanks!

Copy link
Contributor

@anshwad10 anshwad10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops accidentally started a review

LorenzoMolena and others added 15 commits November 19, 2025 09:52
* 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 (agda#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 (agda#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>
* 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 (agda#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 (agda#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'`

* add `Rationals.Fast`

---------

Co-authored-by: Ettore Forigo <ettore.forigo@gmail.com>
Co-authored-by: Marcin Jan Turek-Grzybowski <marcinjangrzybowski@gmail.com>
* add fixity for `_≤_` in `PseudolatticeStr`, add `Properties` file

* add `≤→∧≡Left` and `≥→∧≡Right` into the `Properties` module. Add `isPropIsPseudolattice` into the the `Base` file

* add equivalences of Pseudolattices and other basic properties, following similar modules

* remove implicit universe levels in the type of `PseudolatticeEquiv`
* Fast int properties with pl and ocr instances (agda#23)

* 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 (agda#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 (agda#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>

* edit `zero-≤pos`, using an easier proof, add  `zero-<possuc`

---------

Co-authored-by: Ettore Forigo <ettore.forigo@gmail.com>
Co-authored-by: Marcin Jan Turek-Grzybowski <marcinjangrzybowski@gmail.com>
…Order`, add `0<` and its property into `Int.Fast.Order`, add Fast Rationals. The module `Rationals.Fast.Order.Properties` is still WIP, but the uncommented code currently typechecks
@marcinjangrzybowski
Copy link
Contributor Author

this is result of explorative development, code is messy but everything typechecks
It is intended to be moved piece-by-piece to smaller PRs, we are planning code sprint focused on cleaning this up and refactoring during AIM XLI

  • Nth roots are equivalences on non-negative real numbers
  • rational power of real numbers, extended to real power of positive real numbers
  • log/exp isomorphism , group isomorphism between additive and multiplicative group on reals
    exp-log-group-hom : GroupHom +Groupℝ ·₊Groupℝ
  • trigonometric functions and their inverses (equivalences on restricted domain)
  • pi defined as smallest period of cos/sin
  • sin' = cos , lots of trigonometric identities
  • Rieman integral, both directions of Fundamental theorem of calculus
  • Circle on plane is equivalent to interval with welded ends (with arbitrary small overlap)
  • mean value theorem, etc...
  • uniform continuity, derivatives of power series
  • basic Convergence tests
  • bits and pieces of MetricSpaces

@mortberg
Copy link
Collaborator

Wow, sounds very cool! Are you relying on any classical axioms or is everything constructive?

@marcinjangrzybowski
Copy link
Contributor Author

everything constructive

@marcinjangrzybowski
Copy link
Contributor Author

after implementing HoTT chapter on cauchy reals I roughly followed Bishop (as book was advising :))

@marcinjangrzybowski
Copy link
Contributor Author

and of course Auke Booij , Analysis in Univalent Type Theory

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.

5 participants