diff --git a/references.bib b/references.bib
index f63c1f2c16..d1252647df 100644
--- a/references.bib
+++ b/references.bib
@@ -10,6 +10,16 @@ @online{100theorems
url = {https://www.cs.ru.nl/~freek/100/}
}
+@book{AZ18,
+ author = {Aigner, Martin and Ziegler, G\"{u}nter M.},
+ title = {Proofs from THE BOOK},
+ year = {2018},
+ isbn = {3662572648},
+ publisher = {Springer Publishing Company, Incorporated},
+ edition = {6th},
+ abstract = {This revised and enlarged sixth edition of Proofs from THE BOOK features an entirely new chapter on Van der Waerdens permanent conjecture, as well as additional, highly original and delightful proofs in other chapters.}
+}
+
@article{AKS15,
title = {Univalent Categories and the {{Rezk}} Completion},
author = {Ahrens, Benedikt and Kapulkin, Krzysztof and Shulman, Michael},
@@ -44,6 +54,16 @@ @article{AL19
langid = {english}
}
+@book{Andrews94,
+ title = {Number Theory},
+ author = {Andrews, G.E.},
+ isbn = {9780486682525},
+ lccn = {lc94005243},
+ series = {Dover Books on Mathematics},
+ year = {1994},
+ publisher = {Dover Publications}
+}
+
@misc{Anel24,
title = {The category of $\pi$-finite spaces},
author = {Mathieu Anel},
@@ -66,16 +86,16 @@ @misc{Awodey22
}
@article{BauerTaylor2009,
- author = {Bauer, Andrej and Taylor, Paul},
- title = {The {D}edekind Reals in Abstract {S}tone Duality},
- journal = {Mathematical Structures in Computer Science},
- publisher = {Cambridge University Press},
- year = 2009,
- volume = 19,
- pages = {757--838},
- doi = {10.1017/S0960129509007695},
- url = {PaulTaylor.EU/ASD/dedras/},
- amsclass = {03F60, 06E15, 18C20, 26E40, 54D45, 65G40}
+ author = {Bauer, Andrej and Taylor, Paul},
+ title = {The {D}edekind Reals in Abstract {S}tone Duality},
+ journal = {Mathematical Structures in Computer Science},
+ publisher = {Cambridge University Press},
+ year = 2009,
+ volume = 19,
+ pages = {757--838},
+ doi = {10.1017/S0960129509007695},
+ url = {https://paultaylor.eu/ASD/dedras/},
+ amsclass = {03F60, 06E15, 18C20, 26E40, 54D45, 65G40}
}
@online{BCDE21,
@@ -390,6 +410,15 @@ @article{Esc21b
url = {https://martinescardo.github.io/TypeTopology/InjectiveTypes.Article.html}
}
+@book{Euler1748,
+ author = {Leonhard Euler},
+ title = {Introductio in analysin infinitorum},
+ year = {1748},
+ publisher = {Typographia Academiae Imperialis Petropolitanae},
+ url = {https://archive.org/details/introductioanaly00eule_0},
+ note = {Accessed: 2025-01-20}
+}
+
@book{FBL73,
author = {Fraenkel, Abraham A. and Bar-Hillel, Yehoshua and Levy,
Azriel},
@@ -413,6 +442,28 @@ @online{Felixwellen/DCHoTT-Agda
howpublished = {{{GitHub}} repository}
}
+@misc{Fibonacci1202,
+ author = {Fibonacci},
+ title = {Liber Abaci},
+ year = {1202},
+ note = {A scanned copy of Fibonacci's *Liber Abaci* is available through the Linda Hall Library Digital Collections.},
+ url = {https://old.maa.org/press/periodicals/convergence/mathematical-treasure-fibonacci-s-liber-abaci}
+}
+
+@book {Golan1999,
+ author = {Golan, Jonathan S.},
+ title = {Semirings and their applications},
+ publisher = {Kluwer Academic Publishers, Dordrecht},
+ year = {1999},
+ pages = {xii+381},
+ isbn = {0-7923-5786-8},
+ mrclass = {16Y60 (68Q01)},
+ mrnumber = {1746739},
+ mrreviewer = {Udo\ Hebisch},
+ doi = {10.1007/978-94-015-9333-5},
+ url = {https://doi.org/10.1007/978-94-015-9333-5},
+}
+
@online{GGMS24,
title = {The {{Category}} of {{Iterative Sets}} in {{Homotopy Type Theory}} and {{Univalent Foundations}}},
author = {Gratzer, Daniel and Gylterud, Håkon and Mörtberg, Anders and Stenholm, Elisabeth},
@@ -427,6 +478,16 @@ @online{GGMS24
keywords = {Computer Science - Logic in Computer Science,Mathematics - Logic}
}
+@book{HW08,
+ title = {{An Introduction to the Theory of Numbers (6th edition)}},
+ author = {Hardy, G. H. and Wright, Edward M. and Heath-Brown, D. R. and Silverman, Joseph H.},
+ isbn = {0199219869},
+ keywords = {congruences, primitive roots, residue systems, instructional exposition},
+ publisher = {Oxford University Press},
+ year = {2008},
+ abstract = {{The sixth edition of the classic undergraduate text in elementary number theory includes a new chapter on elliptic curves and their role in the proof of Fermat's Last Theorem, a foreword by Andrew Wiles and extensively revised and updated end-of-chapter notes.}},
+}
+
@article{KECA17,
title = {{Notions of Anonymous Existence in {{Martin-L\"of}} Type Theory}},
author = {Nicolai Kraus and Martín Escardó and Thierry Coquand and Thorsten Altenkirch},
@@ -479,6 +540,41 @@ @misc{Lavenir23
primaryclass = {math.AT}
}
+@book{Leibniz1693,
+ author = {Gottfried Wilhelm Leibniz},
+ title = {De geometria analysis},
+ year = {1693},
+ publisher = {Leibniz's own press, Vienna},
+ note = {This text is often cited as one of Leibniz's early works on calculus.}
+}
+
+@book{Leveque12volI,
+ title = {Topics in Number Theory, Volume I},
+ author = {LeVeque, W.J.},
+ isbn = {9780486152080},
+ series = {Dover Books on Mathematics},
+ year = {2012},
+ publisher = {Dover Publications}
+}
+
+@book{Leveque12volII,
+ title = {Topics in Number Theory, Volume II},
+ author = {LeVeque, W.J.},
+ isbn = {9780486152080},
+ series = {Dover Books on Mathematics},
+ year = {2012},
+ publisher = {Dover Publications}
+}
+
+@book{lucas1891,
+ title = {Théorie des Nombres},
+ author = {Lucas, Édouard},
+ year = {1891},
+ publisher = {Gauthier-Villars},
+ address = {Paris},
+ url = {https://archive.org/details/thoriedesnombr01lucauoft}
+}
+
@incollection{Makkai98,
author = {Makkai, M.},
title = {Towards a categorical foundation of mathematics},
@@ -608,6 +704,32 @@ @misc{Mye21
primaryclass = {math.CT}
}
+@article {NoronhaGalvao1978,
+ author = {{Noronha-Galv\~ao}, Maria Luísa},
+ title = {Ideals in the semiring {$N$}},
+ journal = {Portugal. Math.},
+ fjournal = {Portugaliae Mathematica},
+ volume = {37},
+ year = {1978},
+ number = {1-2},
+ pages = {113--117},
+ issn = {0032-5155,1662-2758},
+ mrclass = {16A78 (20M25)},
+ mrnumber = {620304},
+}
+
+@book {NZM,
+ author = {Niven, Ivan and Zuckerman, Herbert S. and Montgomery, Hugh L.},
+ title = {An introduction to the theory of numbers},
+ edition = {Fifth},
+ publisher = {John Wiley \& Sons, Inc., New York},
+ year = {1991},
+ pages = {xiv+529},
+ isbn = {0-471-62546-9},
+ mrclass = {11-01},
+ mrnumber = {1083765},
+}
+
@online{oeis,
title = {The {{On-Line Encyclopedia}} of {{Integer Sequences}}},
author = {OEIS Foundation Inc.},
@@ -631,6 +753,15 @@ @phdthesis{Qui16
langid = {english}
}
+@book{Recorde1557,
+ author = {Robert Recorde},
+ title = {The Whetstone of Witte},
+ year = {1557},
+ publisher = {Printed by John Daye, London},
+ note = {This work contains the first recorded use of the equals sign (=).},
+ url = {https://archive.org/embed/TheWhetstoneOfWitte}
+}
+
@book{Rie17,
title = {Category {{Theory}} in {{Context}}},
author = {Riehl, Emily},
@@ -730,6 +861,18 @@ @article{RSS20
keywords = {Computer Science - Logic in Computer Science,F.3.1,F.3.1 F.4.1,F.4.1,Mathematics - Category Theory,Mathematics - Logic}
}
+@article{Saidak2006,
+ author = {Saidak, Filip},
+ title = {A New Proof of Euclid's Theorem},
+ journal = {The American Mathematical Monthly},
+ volume = {113},
+ number = {10},
+ pages = {937--938},
+ year = {2006},
+ doi = {10.2307/27642094},
+ mrnumber = {2271540}
+}
+
@online{Shu14SplittingIdempotents,
title = {Splitting {{Idempotents}}},
author = {Shulman, Mike},
@@ -938,3 +1081,14 @@ @online{Warn24
pubstate = {preprint},
keywords = {Mathematics - Algebraic Topology,Mathematics - Category Theory}
}
+
+@book{Widmann1489,
+ author = {Johannes Widmann},
+ title = {Behende und hüpsche Rechenung auff allen Kauffmanschafft},
+ year = {1489},
+ publisher = {Conrad Kachelofen},
+ address = {Leipzig},
+ note = {First use of "+" and "−" symbols in printed mathematics},
+ language = {German},
+ url = {https://www.loc.gov/item/49038907}
+}
diff --git a/src/commutative-algebra/groups-of-units-commutative-rings.lagda.md b/src/commutative-algebra/groups-of-units-commutative-rings.lagda.md
index f3fcd5aac1..218fb440e2 100644
--- a/src/commutative-algebra/groups-of-units-commutative-rings.lagda.md
+++ b/src/commutative-algebra/groups-of-units-commutative-rings.lagda.md
@@ -11,6 +11,7 @@ open import category-theory.functors-large-precategories
open import commutative-algebra.commutative-rings
open import commutative-algebra.homomorphisms-commutative-rings
+open import commutative-algebra.invertible-elements-commutative-rings
open import commutative-algebra.precategory-of-commutative-rings
open import foundation.dependent-pair-types
@@ -35,8 +36,9 @@ open import ring-theory.groups-of-units-rings
## Idea
-The **group of units** of a
-[commutative ring](commutative-algebra.commutative-rings.md) `A` is the
+The
+{{#concept "group of units" Disambiguation="commutative ring" WD="unit" WDID=Q118084}}
+of a [commutative ring](commutative-algebra.commutative-rings.md) `A` is the
[abelian group](group-theory.abelian-groups.md) consisting of all the
[invertible elements](commutative-algebra.invertible-elements-commutative-rings.md)
in `A`. Equivalently, the group of units of `A` is the
@@ -177,6 +179,14 @@ module _
inclusion-group-of-units-Commutative-Ring =
inclusion-group-of-units-Ring (ring-Commutative-Ring A)
+ is-invertible-element-inclusion-group-of-units-Commutative-Ring :
+ (x : type-group-of-units-Commutative-Ring) →
+ is-invertible-element-Commutative-Ring A
+ ( inclusion-group-of-units-Commutative-Ring x)
+ is-invertible-element-inclusion-group-of-units-Commutative-Ring =
+ is-invertible-element-inclusion-group-of-units-Ring
+ ( ring-Commutative-Ring A)
+
preserves-mul-inclusion-group-of-units-Commutative-Ring :
{x y : type-group-of-units-Commutative-Ring} →
inclusion-group-of-units-Commutative-Ring
@@ -324,3 +334,22 @@ preserves-id-functor-Large-Precategory
group-of-units-commutative-ring-functor-Large-Precategory {X = A} =
preserves-id-hom-group-of-units-hom-Commutative-Ring A
```
+
+### Negatives of units
+
+```agda
+module _
+ {l : Level} (A : Commutative-Ring l)
+ where
+
+ neg-group-of-units-Commutative-Ring :
+ type-group-of-units-Commutative-Ring A →
+ type-group-of-units-Commutative-Ring A
+ neg-group-of-units-Commutative-Ring =
+ neg-group-of-units-Ring (ring-Commutative-Ring A)
+
+ neg-unit-group-of-units-Commutative-Ring :
+ type-group-of-units-Commutative-Ring A
+ neg-unit-group-of-units-Commutative-Ring =
+ neg-unit-group-of-units-Ring (ring-Commutative-Ring A)
+```
diff --git a/src/commutative-algebra/invertible-elements-commutative-rings.lagda.md b/src/commutative-algebra/invertible-elements-commutative-rings.lagda.md
index ebc4116027..ab8e95e1fd 100644
--- a/src/commutative-algebra/invertible-elements-commutative-rings.lagda.md
+++ b/src/commutative-algebra/invertible-elements-commutative-rings.lagda.md
@@ -9,6 +9,7 @@ module commutative-algebra.invertible-elements-commutative-rings where
```agda
open import commutative-algebra.commutative-rings
+open import foundation.action-on-identifications-functions
open import foundation.contractible-types
open import foundation.dependent-pair-types
open import foundation.identity-types
@@ -70,7 +71,7 @@ module _
( ring-Commutative-Ring A)
```
-### Aight invertible elements of commutative rings
+### Right invertible elements of commutative rings
```agda
module _
@@ -241,7 +242,7 @@ module _
is-invertible-element-inverse-Ring (ring-Commutative-Ring A)
```
-### Any invertible element of a monoid has a contractible type of right inverses
+### Any invertible element of a commutative ring has a contractible type of right inverses
```agda
module _
@@ -255,7 +256,7 @@ module _
is-contr-is-right-invertible-element-Ring (ring-Commutative-Ring A)
```
-### Any invertible element of a monoid has a contractible type of left inverses
+### Any invertible element of a commutative ring has a contractible type of left inverses
```agda
module _
@@ -269,7 +270,7 @@ module _
is-contr-is-left-invertible-Ring (ring-Commutative-Ring A)
```
-### The unit of a monoid is invertible
+### The unit of a commutative ring is invertible
```agda
module _
@@ -290,9 +291,17 @@ module _
is-invertible-element-Commutative-Ring A (one-Commutative-Ring A)
is-invertible-element-one-Commutative-Ring =
is-invertible-element-one-Ring (ring-Commutative-Ring A)
+
+ is-invertible-element-is-one-Commutative-Ring :
+ (x : type-Commutative-Ring A) → one-Commutative-Ring A = x →
+ is-invertible-element-Commutative-Ring A x
+ is-invertible-element-is-one-Commutative-Ring =
+ is-invertible-element-is-one-Ring (ring-Commutative-Ring A)
```
-### Invertible elements are closed under multiplication
+### A product `xy` is invertible if and only if both `x` and `y` are invertible
+
+#### Invertible elements are closed under multiplication
```agda
module _
@@ -324,6 +333,46 @@ module _
is-invertible-element-mul-Ring (ring-Commutative-Ring A)
```
+#### If `xy` is invertible then so is `x`
+
+```agda
+module _
+ {l : Level} (A : Commutative-Ring l) (x y : type-Commutative-Ring A)
+ where
+
+ is-invertible-element-left-factor-Commutative-Ring :
+ is-invertible-element-Commutative-Ring A (mul-Commutative-Ring A x y) →
+ is-invertible-element-Commutative-Ring A x
+ pr1 (is-invertible-element-left-factor-Commutative-Ring (u , p , q)) =
+ mul-Commutative-Ring A y u
+ pr1 (pr2 (is-invertible-element-left-factor-Commutative-Ring (u , p , q))) =
+ inv (associative-mul-Commutative-Ring A x y u) ∙ p
+ pr2 (pr2 (is-invertible-element-left-factor-Commutative-Ring (u , p , q))) =
+ right-swap-mul-Commutative-Ring A y u x ∙
+ ap (mul-Commutative-Ring' A u) (commutative-mul-Commutative-Ring A y x) ∙
+ p
+```
+
+#### If `xy` is invertible then so is `y`
+
+```agda
+module _
+ {l : Level} (A : Commutative-Ring l) (x y : type-Commutative-Ring A)
+ where
+
+ is-invertible-element-right-factor-Commutative-Ring :
+ is-invertible-element-Commutative-Ring A (mul-Commutative-Ring A x y) →
+ is-invertible-element-Commutative-Ring A y
+ pr1 (is-invertible-element-right-factor-Commutative-Ring (u , p , q)) =
+ mul-Commutative-Ring A u x
+ pr1 (pr2 (is-invertible-element-right-factor-Commutative-Ring (u , p , q))) =
+ left-swap-mul-Commutative-Ring A y u x ∙
+ ap (mul-Commutative-Ring A u) (commutative-mul-Commutative-Ring A y x) ∙
+ q
+ pr2 (pr2 (is-invertible-element-right-factor-Commutative-Ring (u , p , q))) =
+ associative-mul-Commutative-Ring A u x y ∙ q
+```
+
### The inverse of an invertible element is invertible
```agda
diff --git a/src/commutative-algebra/powers-of-elements-commutative-semirings.lagda.md b/src/commutative-algebra/powers-of-elements-commutative-semirings.lagda.md
index 0bda772d1a..0ae3eadf64 100644
--- a/src/commutative-algebra/powers-of-elements-commutative-semirings.lagda.md
+++ b/src/commutative-algebra/powers-of-elements-commutative-semirings.lagda.md
@@ -8,8 +8,10 @@ module commutative-algebra.powers-of-elements-commutative-semirings where
```agda
open import commutative-algebra.commutative-semirings
+open import commutative-algebra.homomorphisms-commutative-semirings
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
open import foundation.identity-types
@@ -36,6 +38,21 @@ power-Commutative-Semiring A = power-Semiring (semiring-Commutative-Semiring A)
## Properties
+### `1ⁿ = 1`
+
+```agda
+module _
+ {l : Level} (A : Commutative-Semiring l)
+ where
+
+ power-one-Commutative-Semiring :
+ (n : ℕ) →
+ power-Commutative-Semiring A n (one-Commutative-Semiring A) =
+ one-Commutative-Semiring A
+ power-one-Commutative-Semiring =
+ power-one-Semiring (semiring-Commutative-Semiring A)
+```
+
### `xⁿ⁺¹ = xⁿx`
```agda
@@ -51,6 +68,21 @@ module _
power-succ-Semiring (semiring-Commutative-Semiring A)
```
+### `xⁿ⁺¹ = xxⁿ`
+
+```agda
+module _
+ {l : Level} (A : Commutative-Semiring l)
+ where
+
+ power-succ-Commutative-Semiring' :
+ (n : ℕ) (x : type-Commutative-Semiring A) →
+ power-Commutative-Semiring A (succ-ℕ n) x =
+ mul-Commutative-Semiring A x (power-Commutative-Semiring A n x)
+ power-succ-Commutative-Semiring' =
+ power-succ-Semiring' (semiring-Commutative-Semiring A)
+```
+
### Powers by sums of natural numbers are products of powers
```agda
@@ -68,7 +100,7 @@ module _
distributive-power-add-Semiring (semiring-Commutative-Semiring A)
```
-### If `x` commutes with `y`, then powers distribute over the product of `x` and `y`
+### Powers distribute over products
```agda
module _
@@ -87,3 +119,38 @@ module _
( n)
( commutative-mul-Commutative-Semiring A x y)
```
+
+### Powers by products of natural numbers are iterated powers
+
+```agda
+module _
+ {l : Level} (A : Commutative-Semiring l)
+ where
+
+ power-mul-Commutative-Semiring :
+ (m n : ℕ) {x : type-Commutative-Semiring A} →
+ power-Commutative-Semiring A (m *ℕ n) x =
+ power-Commutative-Semiring A n (power-Commutative-Semiring A m x)
+ power-mul-Commutative-Semiring =
+ power-mul-Semiring (semiring-Commutative-Semiring A)
+```
+
+### Homomorphisms of semirings preserve powers
+
+```agda
+module _
+ {l1 l2 : Level}
+ (A : Commutative-Semiring l1) (B : Commutative-Semiring l2)
+ (f : hom-Commutative-Semiring A B)
+ where
+
+ preserves-powers-hom-Commutative-Semiring :
+ (n : ℕ) (x : type-Commutative-Semiring A) →
+ map-hom-Commutative-Semiring A B f (power-Commutative-Semiring A n x) =
+ power-Commutative-Semiring B n (map-hom-Commutative-Semiring A B f x)
+ preserves-powers-hom-Commutative-Semiring =
+ preserves-powers-hom-Semiring
+ ( semiring-Commutative-Semiring A)
+ ( semiring-Commutative-Semiring B)
+ ( f)
+```
diff --git a/src/elementary-number-theory.lagda.md b/src/elementary-number-theory.lagda.md
index 8c83736e27..ffd7bda570 100644
--- a/src/elementary-number-theory.lagda.md
+++ b/src/elementary-number-theory.lagda.md
@@ -90,6 +90,7 @@ open import elementary-number-theory.initial-segments-natural-numbers public
open import elementary-number-theory.integer-fractions public
open import elementary-number-theory.integer-partitions public
open import elementary-number-theory.integers public
+open import elementary-number-theory.irrationality-square-root-of-2 public
open import elementary-number-theory.jacobi-symbol public
open import elementary-number-theory.kolakoski-sequence public
open import elementary-number-theory.legendre-symbol public
@@ -106,7 +107,7 @@ open import elementary-number-theory.monoid-of-natural-numbers-with-addition pub
open import elementary-number-theory.monoid-of-natural-numbers-with-maximum public
open import elementary-number-theory.multiplication-integer-fractions public
open import elementary-number-theory.multiplication-integers public
-open import elementary-number-theory.multiplication-lists-of-natural-numbers public
+open import elementary-number-theory.products-lists-of-natural-numbers public
open import elementary-number-theory.multiplication-natural-numbers public
open import elementary-number-theory.multiplication-positive-and-negative-integers public
open import elementary-number-theory.multiplication-rational-numbers public
@@ -126,6 +127,7 @@ open import elementary-number-theory.nonzero-integers public
open import elementary-number-theory.nonzero-natural-numbers public
open import elementary-number-theory.nonzero-rational-numbers public
open import elementary-number-theory.ordinal-induction-natural-numbers public
+open import elementary-number-theory.parity-integers public
open import elementary-number-theory.parity-natural-numbers public
open import elementary-number-theory.peano-arithmetic public
open import elementary-number-theory.pisano-periods public
@@ -136,7 +138,7 @@ open import elementary-number-theory.positive-integer-fractions public
open import elementary-number-theory.positive-integers public
open import elementary-number-theory.positive-rational-numbers public
open import elementary-number-theory.powers-integers public
-open import elementary-number-theory.powers-of-two public
+open import elementary-number-theory.2-adic-decomposition public
open import elementary-number-theory.prime-numbers public
open import elementary-number-theory.products-of-natural-numbers public
open import elementary-number-theory.proper-divisors-natural-numbers public
@@ -172,6 +174,8 @@ open import elementary-number-theory.triangular-numbers public
open import elementary-number-theory.twin-prime-conjecture public
open import elementary-number-theory.type-arithmetic-natural-numbers public
open import elementary-number-theory.unit-elements-standard-finite-types public
+open import elementary-number-theory.unit-integers public
+open import elementary-number-theory.unit-similarity-integers public
open import elementary-number-theory.unit-similarity-standard-finite-types public
open import elementary-number-theory.universal-property-conatural-numbers public
open import elementary-number-theory.universal-property-integers public
diff --git a/src/elementary-number-theory/2-adic-decomposition.lagda.md b/src/elementary-number-theory/2-adic-decomposition.lagda.md
new file mode 100644
index 0000000000..7c2b8f7788
--- /dev/null
+++ b/src/elementary-number-theory/2-adic-decomposition.lagda.md
@@ -0,0 +1,424 @@
+# 2-Adic decomposition
+
+```agda
+module elementary-number-theory.2-adic-decomposition where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.based-strong-induction-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.exponentiation-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.largest-power-divisors-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
+open import elementary-number-theory.strong-induction-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.contractible-types
+open import foundation.dependent-pair-types
+open import foundation.embeddings
+open import foundation.equality-cartesian-product-types
+open import foundation.equality-dependent-pair-types
+open import foundation.function-types
+open import foundation.functoriality-dependent-pair-types
+open import foundation.logical-equivalences
+open import foundation.propositional-maps
+open import foundation.propositions
+open import foundation.sets
+open import foundation.split-surjective-maps
+open import foundation.subtypes
+open import foundation.transport-along-identifications
+open import foundation.type-arithmetic-dependent-pair-types
+open import foundation.unit-type
+open import foundation.universe-levels
+
+open import foundation-core.cartesian-product-types
+open import foundation-core.coproduct-types
+open import foundation-core.empty-types
+open import foundation-core.equivalences
+open import foundation-core.fibers-of-maps
+open import foundation-core.identity-types
+open import foundation-core.injective-maps
+```
+
+
+
+## Idea
+
+The {{#concept "2-adic decomposition" Agda=2-adic-decomposition-ℕ}} of a
+[natural number](elementary-number-theory.natural-numbers.md) $n$ is a
+factorization of $n$ into a
+[power](elementary-number-theory.exponentiation-natural-numbers.md) of $2$ and
+an [odd](elementary-number-theory.parity-natural-numbers.md) natural number.
+
+The $2$-adic decomposition of the natural numbers can be used to construct an
+[equivalence](foundation-core.equivalences.md)
+$\mathbb{N}\times\mathbb{N} \simeq \mathbb{N}$ by mapping
+
+$$
+ (m , n) \mapsto 2^m(2n + 1) - 1.
+$$
+
+The exponent $k$ such that the 2-adic decomposition of $n$ is $2^k \cdot m=n$ is
+called the
+{{#concept "2-adic valuation" Disambiguation="natural numbers" Agda=valuation-2-adic-decomposition-ℕ}}
+of $n$.
+
+## Definitions
+
+### The $2$-adic composition function
+
+```agda
+2-adic-composition-ℕ : ℕ → ℕ → ℕ
+2-adic-composition-ℕ k l = 2 ^ℕ k *ℕ odd-number-ℕ l
+```
+
+### The type of $2$-adic decompositions of a natural number
+
+```agda
+2-adic-decomposition-ℕ : ℕ → UU lzero
+2-adic-decomposition-ℕ n =
+ Σ ℕ (λ k → Σ ℕ (λ l → 2-adic-composition-ℕ k l = n))
+
+module _
+ (n : ℕ) (d : 2-adic-decomposition-ℕ n)
+ where
+
+ fiber-2-adic-composition-2-adic-decomposition-ℕ :
+ fiber (λ x → 2-adic-composition-ℕ (pr1 x) (pr2 x)) n
+ fiber-2-adic-composition-2-adic-decomposition-ℕ =
+ ((pr1 d , pr1 (pr2 d)) , pr2 (pr2 d))
+
+ valuation-2-adic-decomposition-ℕ : ℕ
+ valuation-2-adic-decomposition-ℕ = pr1 d
+
+ exp-valuation-2-adic-decomposition-ℕ : ℕ
+ exp-valuation-2-adic-decomposition-ℕ =
+ 2 ^ℕ valuation-2-adic-decomposition-ℕ
+
+ is-nonzero-exp-valuation-2-adic-decomposition-ℕ :
+ is-nonzero-ℕ exp-valuation-2-adic-decomposition-ℕ
+ is-nonzero-exp-valuation-2-adic-decomposition-ℕ =
+ is-nonzero-exp-ℕ 2 valuation-2-adic-decomposition-ℕ (is-nonzero-succ-ℕ 1)
+
+ index-odd-factor-2-adic-decomposition-ℕ : ℕ
+ index-odd-factor-2-adic-decomposition-ℕ = pr1 (pr2 d)
+
+ odd-factor-2-adic-decomposition-ℕ : ℕ
+ odd-factor-2-adic-decomposition-ℕ =
+ odd-number-ℕ index-odd-factor-2-adic-decomposition-ℕ
+
+ is-odd-odd-factor-2-adic-decomposition-ℕ :
+ is-odd-ℕ odd-factor-2-adic-decomposition-ℕ
+ is-odd-odd-factor-2-adic-decomposition-ℕ =
+ is-odd-odd-number-ℕ index-odd-factor-2-adic-decomposition-ℕ
+
+ eq-2-adic-decomposition-ℕ :
+ 2-adic-composition-ℕ
+ valuation-2-adic-decomposition-ℕ
+ index-odd-factor-2-adic-decomposition-ℕ =
+ n
+ eq-2-adic-decomposition-ℕ = pr2 (pr2 d)
+
+ div-exp-valuation-2-adic-decomposition-ℕ :
+ div-ℕ exp-valuation-2-adic-decomposition-ℕ n
+ pr1 div-exp-valuation-2-adic-decomposition-ℕ =
+ odd-factor-2-adic-decomposition-ℕ
+ pr2 div-exp-valuation-2-adic-decomposition-ℕ =
+ commutative-mul-ℕ
+ odd-factor-2-adic-decomposition-ℕ
+ exp-valuation-2-adic-decomposition-ℕ ∙
+ eq-2-adic-decomposition-ℕ
+
+ is-power-divisor-exp-valuation-2-adic-decomposition-ℕ :
+ is-power-divisor-ℕ 2 n
+ exp-valuation-2-adic-decomposition-ℕ
+ pr1 (pr1 (is-power-divisor-exp-valuation-2-adic-decomposition-ℕ)) =
+ valuation-2-adic-decomposition-ℕ
+ pr2 (pr1 (is-power-divisor-exp-valuation-2-adic-decomposition-ℕ)) =
+ refl
+ pr2 (is-power-divisor-exp-valuation-2-adic-decomposition-ℕ) =
+ div-exp-valuation-2-adic-decomposition-ℕ
+
+ is-largest-power-divisor-exp-valuation-2-adic-decomposition-ℕ :
+ is-largest-power-divisor-ℕ 2 n exp-valuation-2-adic-decomposition-ℕ
+ pr1 is-largest-power-divisor-exp-valuation-2-adic-decomposition-ℕ =
+ is-power-divisor-exp-valuation-2-adic-decomposition-ℕ
+ pr2 is-largest-power-divisor-exp-valuation-2-adic-decomposition-ℕ y
+ ((k , refl) , K) =
+ leq-exponent-div-exp-ℕ
+ ( 2)
+ ( valuation-2-adic-decomposition-ℕ)
+ ( k)
+ ( star)
+ ( div-exp-2-left-factor-div-exp-2-mul-ℕ k
+ ( exp-valuation-2-adic-decomposition-ℕ)
+ ( odd-factor-2-adic-decomposition-ℕ)
+ ( concatenate-div-eq-ℕ K (inv eq-2-adic-decomposition-ℕ))
+ ( is-odd-odd-factor-2-adic-decomposition-ℕ))
+```
+
+## Properties
+
+### The type of 2-adic decompositions of any natural number is a proposition
+
+```agda
+eq-valuation-2-adic-decomposition-ℕ :
+ (n : ℕ) (H K : 2-adic-decomposition-ℕ n) →
+ valuation-2-adic-decomposition-ℕ n H = valuation-2-adic-decomposition-ℕ n K
+eq-valuation-2-adic-decomposition-ℕ n H K =
+ eq-valuation-is-largest-power-divisor-ℕ 2 n
+ ( exp-valuation-2-adic-decomposition-ℕ n H)
+ ( exp-valuation-2-adic-decomposition-ℕ n K)
+ ( star)
+ ( is-largest-power-divisor-exp-valuation-2-adic-decomposition-ℕ n H)
+ ( is-largest-power-divisor-exp-valuation-2-adic-decomposition-ℕ n K)
+
+eq-exp-valuation-2-adic-decomposition-ℕ :
+ (n : ℕ) (H K : 2-adic-decomposition-ℕ n) →
+ exp-valuation-2-adic-decomposition-ℕ n H =
+ exp-valuation-2-adic-decomposition-ℕ n K
+eq-exp-valuation-2-adic-decomposition-ℕ n H K =
+ ap (2 ^ℕ_) (eq-valuation-2-adic-decomposition-ℕ n H K)
+
+eq-odd-factor-2-adic-decomposition-ℕ :
+ (n : ℕ) (H K : 2-adic-decomposition-ℕ n) →
+ odd-factor-2-adic-decomposition-ℕ n H = odd-factor-2-adic-decomposition-ℕ n K
+eq-odd-factor-2-adic-decomposition-ℕ n H K =
+ is-injective-left-mul-ℕ
+ ( exp-valuation-2-adic-decomposition-ℕ n H)
+ ( is-nonzero-exp-valuation-2-adic-decomposition-ℕ n H)
+ ( ( eq-2-adic-decomposition-ℕ n H) ∙
+ ( inv (eq-2-adic-decomposition-ℕ n K)) ∙
+ ( ap
+ ( _*ℕ odd-factor-2-adic-decomposition-ℕ n K)
+ ( inv (eq-exp-valuation-2-adic-decomposition-ℕ n H K))))
+
+eq-index-odd-factor-2-adic-decomposition-ℕ :
+ (n : ℕ) (H K : 2-adic-decomposition-ℕ n) →
+ index-odd-factor-2-adic-decomposition-ℕ n H =
+ index-odd-factor-2-adic-decomposition-ℕ n K
+eq-index-odd-factor-2-adic-decomposition-ℕ n H K =
+ is-injective-odd-number-ℕ (eq-odd-factor-2-adic-decomposition-ℕ n H K)
+
+all-elements-equal-2-adic-decomposition-ℕ :
+ (n : ℕ) → all-elements-equal (2-adic-decomposition-ℕ n)
+all-elements-equal-2-adic-decomposition-ℕ n H@(k , m , p) K@(k' , m' , p') =
+ eq-pair-Σ
+ ( eq-valuation-2-adic-decomposition-ℕ n H K)
+ ( eq-type-subtype
+ ( λ x → Id-Prop ℕ-Set _ _)
+ ( eq-index-odd-factor-2-adic-decomposition-ℕ n
+ ( k' ,
+ tr
+ ( λ x → Σ ℕ (λ y → 2-adic-composition-ℕ x y = n))
+ ( eq-valuation-2-adic-decomposition-ℕ n H K)
+ ( m , p))
+ ( K)))
+
+is-prop-2-adic-decomposition-ℕ :
+ (n : ℕ) → is-prop (2-adic-decomposition-ℕ n)
+is-prop-2-adic-decomposition-ℕ n =
+ is-prop-all-elements-equal (all-elements-equal-2-adic-decomposition-ℕ n)
+```
+
+### The values of the $2$-adic composition function are nonzero
+
+```agda
+is-nonzero-2-adic-composition-ℕ :
+ (k l : ℕ) → is-nonzero-ℕ (2-adic-composition-ℕ k l)
+is-nonzero-2-adic-composition-ℕ k l =
+ is-nonzero-mul-ℕ
+ ( 2 ^ℕ k)
+ ( odd-number-ℕ l)
+ ( is-nonzero-exp-ℕ 2 k is-nonzero-two-ℕ)
+ ( is-nonzero-odd-number-ℕ l)
+```
+
+### Any number that has a $2$-adic decomposition is nonzero
+
+```agda
+is-nonzero-2-adic-decomposition-ℕ :
+ (n : ℕ) → 2-adic-decomposition-ℕ n → is-nonzero-ℕ n
+is-nonzero-2-adic-decomposition-ℕ ._ (k , l , refl) =
+ is-nonzero-2-adic-composition-ℕ k l
+```
+
+### Every odd number has a $2$-adic decomposition
+
+```agda
+2-adic-decomposition-is-odd-ℕ :
+ (n : ℕ) → is-odd-ℕ n → 2-adic-decomposition-ℕ n
+pr1 (2-adic-decomposition-is-odd-ℕ n H) =
+ 0
+pr1 (pr2 (2-adic-decomposition-is-odd-ℕ n H)) =
+ pr1 (has-odd-expansion-is-odd-ℕ n H)
+pr2 (pr2 (2-adic-decomposition-is-odd-ℕ n H)) =
+ left-unit-law-mul-ℕ _ ∙ pr2 (has-odd-expansion-is-odd-ℕ n H)
+```
+
+### Every nonzero natural number has a $2$-adic decomposition
+
+```agda
+module _
+ (n : ℕ) (H : is-nonzero-ℕ n)
+ where
+
+ valuation-2-adic-decomposition-is-nonzero-ℕ :
+ ℕ
+ valuation-2-adic-decomposition-is-nonzero-ℕ =
+ valuation-largest-power-divisor-ℕ 2 n star H
+
+ exp-valuation-2-adic-decomposition-is-nonzero-ℕ :
+ ℕ
+ exp-valuation-2-adic-decomposition-is-nonzero-ℕ =
+ 2 ^ℕ valuation-2-adic-decomposition-is-nonzero-ℕ
+
+ div-exp-valuation-2-adic-decomposition-is-nonzero-ℕ :
+ div-ℕ exp-valuation-2-adic-decomposition-is-nonzero-ℕ n
+ div-exp-valuation-2-adic-decomposition-is-nonzero-ℕ =
+ div-largest-power-divisor-ℕ 2 n star H
+
+ is-upper-bound-valuation-2-adic-decomposition-is-nonzero-ℕ :
+ (k : ℕ) → div-ℕ (2 ^ℕ k) n →
+ k ≤-ℕ valuation-2-adic-decomposition-is-nonzero-ℕ
+ is-upper-bound-valuation-2-adic-decomposition-is-nonzero-ℕ =
+ is-upper-bound-valuation-largest-power-divisor-ℕ 2 n star H
+
+ odd-factor-2-adic-decomposition-is-nonzero-ℕ :
+ ℕ
+ odd-factor-2-adic-decomposition-is-nonzero-ℕ =
+ quotient-div-ℕ
+ ( exp-valuation-2-adic-decomposition-is-nonzero-ℕ)
+ ( n)
+ ( div-exp-valuation-2-adic-decomposition-is-nonzero-ℕ)
+
+ is-odd-odd-factor-2-adic-decomposition-is-nonzero-ℕ :
+ is-odd-ℕ odd-factor-2-adic-decomposition-is-nonzero-ℕ
+ is-odd-odd-factor-2-adic-decomposition-is-nonzero-ℕ K =
+ neg-succ-leq-ℕ
+ ( valuation-2-adic-decomposition-is-nonzero-ℕ)
+ ( is-upper-bound-valuation-2-adic-decomposition-is-nonzero-ℕ
+ ( succ-ℕ valuation-2-adic-decomposition-is-nonzero-ℕ)
+ ( tr
+ ( is-divisor-ℕ n)
+ ( inv (exp-succ-ℕ 2 valuation-2-adic-decomposition-is-nonzero-ℕ))
+ ( div-div-quotient-div-ℕ 2 n
+ ( 2 ^ℕ valuation-2-adic-decomposition-is-nonzero-ℕ)
+ ( div-exp-valuation-2-adic-decomposition-is-nonzero-ℕ)
+ ( K))))
+
+ has-odd-expansion-odd-factor-2-adic-decomposition-is-nonzero-ℕ :
+ has-odd-expansion-ℕ odd-factor-2-adic-decomposition-is-nonzero-ℕ
+ has-odd-expansion-odd-factor-2-adic-decomposition-is-nonzero-ℕ =
+ has-odd-expansion-is-odd-ℕ
+ odd-factor-2-adic-decomposition-is-nonzero-ℕ
+ is-odd-odd-factor-2-adic-decomposition-is-nonzero-ℕ
+
+ index-odd-factor-2-adic-decomposition-is-nonzero-ℕ :
+ ℕ
+ index-odd-factor-2-adic-decomposition-is-nonzero-ℕ =
+ pr1 has-odd-expansion-odd-factor-2-adic-decomposition-is-nonzero-ℕ
+
+ eq-index-odd-factor-2-adic-decomposition-is-nonzero-ℕ :
+ odd-number-ℕ index-odd-factor-2-adic-decomposition-is-nonzero-ℕ =
+ odd-factor-2-adic-decomposition-is-nonzero-ℕ
+ eq-index-odd-factor-2-adic-decomposition-is-nonzero-ℕ =
+ pr2 has-odd-expansion-odd-factor-2-adic-decomposition-is-nonzero-ℕ
+
+ eq-2-adic-decomposition-is-nonzero-ℕ :
+ 2-adic-composition-ℕ
+ ( valuation-2-adic-decomposition-is-nonzero-ℕ)
+ ( index-odd-factor-2-adic-decomposition-is-nonzero-ℕ) =
+ n
+ eq-2-adic-decomposition-is-nonzero-ℕ =
+ ( ap
+ ( 2 ^ℕ valuation-2-adic-decomposition-is-nonzero-ℕ *ℕ_)
+ ( eq-index-odd-factor-2-adic-decomposition-is-nonzero-ℕ)) ∙
+ ( eq-quotient-div-ℕ'
+ ( 2 ^ℕ valuation-2-adic-decomposition-is-nonzero-ℕ)
+ ( n)
+ ( div-exp-valuation-2-adic-decomposition-is-nonzero-ℕ))
+
+ 2-adic-decomposition-is-nonzero-ℕ :
+ 2-adic-decomposition-ℕ n
+ pr1 2-adic-decomposition-is-nonzero-ℕ =
+ valuation-2-adic-decomposition-is-nonzero-ℕ
+ pr1 (pr2 2-adic-decomposition-is-nonzero-ℕ) =
+ index-odd-factor-2-adic-decomposition-is-nonzero-ℕ
+ pr2 (pr2 2-adic-decomposition-is-nonzero-ℕ) =
+ eq-2-adic-decomposition-is-nonzero-ℕ
+
+ is-largest-power-divisor-exp-valuation-2-adic-decomposition-is-nonzero-ℕ :
+ is-largest-power-divisor-ℕ 2 n
+ exp-valuation-2-adic-decomposition-is-nonzero-ℕ
+ is-largest-power-divisor-exp-valuation-2-adic-decomposition-is-nonzero-ℕ =
+ is-largest-power-divisor-exp-valuation-2-adic-decomposition-ℕ n
+ 2-adic-decomposition-is-nonzero-ℕ
+```
+
+### A logical equivalence between the type of 2-adic decompositions and the fibers of the successor function
+
+```agda
+logical-equiv-fiber-2-adic-composition-fiber-succ-ℕ :
+ (n : ℕ) →
+ fiber (λ x → 2-adic-composition-ℕ (pr1 x) (pr2 x)) n ↔ fiber succ-ℕ n
+pr1 (logical-equiv-fiber-2-adic-composition-fiber-succ-ℕ n) ((x , y) , p) =
+ fiber-succ-is-successor-ℕ
+ ( is-successor-is-nonzero-ℕ
+ ( is-nonzero-2-adic-decomposition-ℕ n (x , y , p)))
+pr2 (logical-equiv-fiber-2-adic-composition-fiber-succ-ℕ n) (m , refl) =
+ fiber-2-adic-composition-2-adic-decomposition-ℕ n
+ ( 2-adic-decomposition-is-nonzero-ℕ (succ-ℕ m) (is-nonzero-succ-ℕ m))
+```
+
+### The type of 2-adic decompositions of a nonzero natural number is contractible
+
+```agda
+is-contr-2-adic-decomposition-ℕ :
+ (n : ℕ) → is-nonzero-ℕ n → is-contr (2-adic-decomposition-ℕ n)
+is-contr-2-adic-decomposition-ℕ n H =
+ is-proof-irrelevant-is-prop
+ ( is-prop-2-adic-decomposition-ℕ n)
+ ( 2-adic-decomposition-is-nonzero-ℕ n H)
+```
+
+### The 2-adic composition function is a propositional map
+
+```agda
+is-prop-map-2-adic-composition-ℕ :
+ is-prop-map (λ x → 2-adic-composition-ℕ (pr1 x) (pr2 x))
+is-prop-map-2-adic-composition-ℕ n =
+ is-prop-equiv
+ ( associative-Σ ℕ _ _)
+ ( is-prop-2-adic-decomposition-ℕ n)
+```
+
+### The 2-adic composition function is an embedding
+
+```agda
+is-emb-2-adic-composition-ℕ :
+ is-emb (λ x → 2-adic-composition-ℕ (pr1 x) (pr2 x))
+is-emb-2-adic-composition-ℕ =
+ is-emb-is-prop-map is-prop-map-2-adic-composition-ℕ
+
+2-adic-composition-emb-ℕ :
+ ℕ × ℕ ↪ ℕ
+pr1 2-adic-composition-emb-ℕ (x , y) = 2-adic-composition-ℕ x y
+pr2 2-adic-composition-emb-ℕ = is-emb-2-adic-composition-ℕ
+```
+
+### The 2-adic composition function is injective
+
+```agda
+is-injective-2-adic-composition-ℕ :
+ is-injective (λ x → 2-adic-composition-ℕ (pr1 x) (pr2 x))
+is-injective-2-adic-composition-ℕ =
+ is-injective-is-emb is-emb-2-adic-composition-ℕ
+```
diff --git a/src/elementary-number-theory/absolute-value-integers.lagda.md b/src/elementary-number-theory/absolute-value-integers.lagda.md
index 59455c73a5..d0297d3ee5 100644
--- a/src/elementary-number-theory/absolute-value-integers.lagda.md
+++ b/src/elementary-number-theory/absolute-value-integers.lagda.md
@@ -31,7 +31,9 @@ open import foundation.unit-type
The {{#concept "absolute value" Disambiguation="of an integer" Agda=abs-ℤ}} of
an integer is the natural number with the same distance from `0`.
-## Definition
+## Definitions
+
+### The absolute value of an integer
```agda
abs-ℤ : ℤ → ℕ
@@ -92,7 +94,7 @@ predecessor-law-abs-ℤ (inr (inl star)) =
predecessor-law-abs-ℤ (inr (inr zero-ℕ)) =
star
predecessor-law-abs-ℤ (inr (inr (succ-ℕ x))) =
- preserves-leq-succ-ℕ x (succ-ℕ x) (succ-leq-ℕ x)
+ leq-succ-leq-ℕ x (succ-ℕ x) (succ-leq-ℕ x)
```
### `|x + 1| ≤ |x| + 1`
@@ -103,7 +105,7 @@ successor-law-abs-ℤ :
successor-law-abs-ℤ (inl zero-ℕ) =
star
successor-law-abs-ℤ (inl (succ-ℕ x)) =
- preserves-leq-succ-ℕ x (succ-ℕ x) (succ-leq-ℕ x)
+ leq-succ-leq-ℕ x (succ-ℕ x) (succ-leq-ℕ x)
successor-law-abs-ℤ (inr (inl star)) =
refl-leq-ℕ zero-ℕ
successor-law-abs-ℤ (inr (inr x)) =
@@ -178,36 +180,36 @@ is-nonzero-abs-ℤ :
is-nonzero-abs-ℤ (inr (inr x)) H = is-nonzero-succ-ℕ x
```
-### The absolute value function is multiplicative
+### The absolute value distributes over multiplication
```agda
-multiplicative-abs-ℤ' :
- (x y : ℤ) → abs-ℤ (explicit-mul-ℤ x y) = (abs-ℤ x) *ℕ (abs-ℤ y)
-multiplicative-abs-ℤ' (inl x) (inl y) =
+distributive-abs-mul-ℤ' :
+ (x y : ℤ) → abs-ℤ (explicit-mul-ℤ x y) = abs-ℤ x *ℕ abs-ℤ y
+distributive-abs-mul-ℤ' (inl x) (inl y) =
abs-int-ℕ _
-multiplicative-abs-ℤ' (inl x) (inr (inl star)) =
+distributive-abs-mul-ℤ' (inl x) (inr (inl star)) =
inv (right-zero-law-mul-ℕ x)
-multiplicative-abs-ℤ' (inl x) (inr (inr y)) =
+distributive-abs-mul-ℤ' (inl x) (inr (inr y)) =
( abs-neg-ℤ (inl ((x *ℕ (succ-ℕ y)) +ℕ y))) ∙
( abs-int-ℕ ((succ-ℕ x) *ℕ (succ-ℕ y)))
-multiplicative-abs-ℤ' (inr (inl star)) (inl y) =
+distributive-abs-mul-ℤ' (inr (inl star)) (inl y) =
refl
-multiplicative-abs-ℤ' (inr (inr x)) (inl y) =
+distributive-abs-mul-ℤ' (inr (inr x)) (inl y) =
( abs-neg-ℤ (inl ((x *ℕ (succ-ℕ y)) +ℕ y))) ∙
( abs-int-ℕ (succ-ℕ ((x *ℕ (succ-ℕ y)) +ℕ y)))
-multiplicative-abs-ℤ' (inr (inl star)) (inr (inl star)) =
+distributive-abs-mul-ℤ' (inr (inl star)) (inr (inl star)) =
refl
-multiplicative-abs-ℤ' (inr (inl star)) (inr (inr x)) =
+distributive-abs-mul-ℤ' (inr (inl star)) (inr (inr x)) =
refl
-multiplicative-abs-ℤ' (inr (inr x)) (inr (inl star)) =
+distributive-abs-mul-ℤ' (inr (inr x)) (inr (inl star)) =
inv (right-zero-law-mul-ℕ (succ-ℕ x))
-multiplicative-abs-ℤ' (inr (inr x)) (inr (inr y)) =
+distributive-abs-mul-ℤ' (inr (inr x)) (inr (inr y)) =
abs-int-ℕ _
-multiplicative-abs-ℤ :
- (x y : ℤ) → abs-ℤ (x *ℤ y) = (abs-ℤ x) *ℕ (abs-ℤ y)
-multiplicative-abs-ℤ x y =
- ap abs-ℤ (compute-mul-ℤ x y) ∙ multiplicative-abs-ℤ' x y
+distributive-abs-mul-ℤ :
+ (x y : ℤ) → abs-ℤ (x *ℤ y) = abs-ℤ x *ℕ abs-ℤ y
+distributive-abs-mul-ℤ x y =
+ ap abs-ℤ (compute-mul-ℤ x y) ∙ distributive-abs-mul-ℤ' x y
```
### `|(-x)y| = |xy|`
diff --git a/src/elementary-number-theory/addition-integers.lagda.md b/src/elementary-number-theory/addition-integers.lagda.md
index 0074401613..614bd337cf 100644
--- a/src/elementary-number-theory/addition-integers.lagda.md
+++ b/src/elementary-number-theory/addition-integers.lagda.md
@@ -341,6 +341,25 @@ abstract
associative-add-ℤ
```
+### Swapping the order of iterated addition
+
+```agda
+abstract
+ right-swap-add-ℤ :
+ (x y z : ℤ) → (x +ℤ y) +ℤ z = (x +ℤ z) +ℤ y
+ right-swap-add-ℤ x y z =
+ associative-add-ℤ x y z ∙
+ ap (x +ℤ_) (commutative-add-ℤ y z) ∙
+ inv (associative-add-ℤ x z y)
+
+ left-swap-add-ℤ :
+ (x y z : ℤ) → x +ℤ (y +ℤ z) = y +ℤ (x +ℤ z)
+ left-swap-add-ℤ x y z =
+ inv (associative-add-ℤ x y z) ∙
+ ap (_+ℤ z) (commutative-add-ℤ x y) ∙
+ associative-add-ℤ y x z
+```
+
### Addition by `x` is a binary equivalence
```agda
diff --git a/src/elementary-number-theory/addition-natural-numbers.lagda.md b/src/elementary-number-theory/addition-natural-numbers.lagda.md
index 2bb395a863..12bf527ab6 100644
--- a/src/elementary-number-theory/addition-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/addition-natural-numbers.lagda.md
@@ -26,7 +26,21 @@ open import foundation.sets
-## Definition
+## Idea
+
+The {{#concept "addition" Disambiguation="natural numbers" Agda=_+ℕ_}} operation
+on the [natural numbers](elementary-number-theory.natural-numbers.md) is a
+binary operation $m,n\mapsto m+n$ on the natural numbers given by $n$ times
+iteratively taking the successor of the number $m$.
+
+The notation $+$ for addition and $-$ for subtraction appeared first in print in
+1489 in _Behende und hüpsche Rechenung auff allen Kauffmanschafft_ by
+[Johannes Widmann](https://en.wikipedia.org/wiki/Johannes_Widmann), for example
+on page 327 of {{#cite Widmann1489}}.
+
+## Definitions
+
+### Addition on the natural numbers
```agda
add-ℕ : ℕ → ℕ → ℕ
@@ -138,6 +152,25 @@ abstract
associative-add-ℕ
```
+### Swapping iterated addition
+
+```agda
+abstract
+ right-swap-add-ℕ :
+ (x y z : ℕ) → (x +ℕ y) +ℕ z = (x +ℕ z) +ℕ y
+ right-swap-add-ℕ x y z =
+ associative-add-ℕ x y z ∙
+ ap (add-ℕ x) (commutative-add-ℕ y z) ∙
+ inv (associative-add-ℕ x z y)
+
+ left-swap-add-ℕ :
+ (x y z : ℕ) → x +ℕ (y +ℕ z) = y +ℕ (x +ℕ z)
+ left-swap-add-ℕ x y z =
+ inv (associative-add-ℕ x y z) ∙
+ ap (add-ℕ' z) (commutative-add-ℕ x y) ∙
+ associative-add-ℕ y x z
+```
+
### Addition by a fixed element on either side is injective
```agda
@@ -208,3 +241,7 @@ abstract
- The commutative monoid of the natural numbers with addition is defined in
[`monoid-of-natural-numbers-with-addition`](elementary-number-theory.monoid-of-natural-numbers-with-addition.md).
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/archimedean-property-natural-numbers.lagda.md b/src/elementary-number-theory/archimedean-property-natural-numbers.lagda.md
index 0f84a8ced9..1251ff8154 100644
--- a/src/elementary-number-theory/archimedean-property-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/archimedean-property-natural-numbers.lagda.md
@@ -7,6 +7,7 @@ module elementary-number-theory.archimedean-property-natural-numbers where
Imports
```agda
+open import elementary-number-theory.addition-natural-numbers
open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.euclidean-division-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
@@ -16,34 +17,44 @@ open import elementary-number-theory.strict-inequality-natural-numbers
open import foundation.dependent-pair-types
open import foundation.existential-quantification
+open import foundation.identity-types
open import foundation.transport-along-identifications
```
-## Definition
+## Idea
The
{{#concept "Archimedean property" Disambiguation="natural numbers" Agda=archimedean-property-ℕ}}
of the [natural numbers](elementary-number-theory.natural-numbers.md) is that
-for any nonzero natural number `x` and any natural number `y`, there is an
+for any [nonzero natural number](elementary-number-theory.nonzero-natural-numbers.md) `x` and any natural number `y`, there is an
`n : ℕ` such that `y < n *ℕ x`.
+## Definitions
+
+### The Archimedian property of the natural numbers
+
```agda
abstract
archimedean-property-ℕ :
- (x y : ℕ) → is-nonzero-ℕ x → exists ℕ (λ n → le-ℕ-Prop y (n *ℕ x))
+ (x y : ℕ) → is-nonzero-ℕ x → exists-structure ℕ (λ n → y <-ℕ n *ℕ x)
archimedean-property-ℕ x y nonzero-x =
intro-exists
- (succ-ℕ (quotient-euclidean-division-ℕ x y))
- ( tr
- ( λ z → z <-ℕ succ-ℕ (quotient-euclidean-division-ℕ x y) *ℕ x)
- ( eq-euclidean-division-ℕ x y)
- ( preserves-le-left-add-ℕ
+ ( succ-ℕ (quotient-euclidean-division-ℕ x y))
+ ( concatenate-eq-le-eq-ℕ
+ ( y)
+ ( quotient-euclidean-division-ℕ x y *ℕ x +ℕ
+ remainder-euclidean-division-ℕ x y)
+ ( quotient-euclidean-division-ℕ x y *ℕ x +ℕ x)
+ ( succ-ℕ (quotient-euclidean-division-ℕ x y) *ℕ x)
+ ( inv (eq-euclidean-division-ℕ x y))
+ ( preserves-strict-order-right-add-ℕ
( quotient-euclidean-division-ℕ x y *ℕ x)
( remainder-euclidean-division-ℕ x y)
( x)
- ( strict-upper-bound-remainder-euclidean-division-ℕ x y nonzero-x)))
+ ( strict-upper-bound-remainder-euclidean-division-ℕ x y nonzero-x))
+ ( inv (left-successor-law-mul-ℕ (quotient-euclidean-division-ℕ x y) x)))
```
## External links
diff --git a/src/elementary-number-theory/based-strong-induction-natural-numbers.lagda.md b/src/elementary-number-theory/based-strong-induction-natural-numbers.lagda.md
index 52541dc0ab..5de7713d58 100644
--- a/src/elementary-number-theory/based-strong-induction-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/based-strong-induction-natural-numbers.lagda.md
@@ -101,7 +101,7 @@ succ-based-strong-ind-ℕ :
((x : ℕ) → leq-ℕ k x → based-□-≤-ℕ k P x → P (succ-ℕ x)) →
(n : ℕ) → leq-ℕ k n → based-□-≤-ℕ k P n → based-□-≤-ℕ k P (succ-ℕ n)
succ-based-strong-ind-ℕ k P pS n N f m M H =
- cases-succ-based-strong-ind-ℕ k P pS n N f m M (cases-leq-succ-ℕ H)
+ cases-succ-based-strong-ind-ℕ k P pS n N f m M (decide-leq-succ-ℕ m n H)
cases-htpy-succ-based-strong-ind-ℕ :
{l : Level} (k : ℕ) (P : ℕ → UU l)
@@ -122,7 +122,7 @@ htpy-succ-based-strong-ind-ℕ :
(m : ℕ) (M : k ≤-ℕ m) (H : leq-ℕ m (succ-ℕ n)) (K : leq-ℕ m n) →
succ-based-strong-ind-ℕ k P pS n N f m M H = f m M K
htpy-succ-based-strong-ind-ℕ k P pS n N f m M H =
- cases-htpy-succ-based-strong-ind-ℕ k P pS n N f m M (cases-leq-succ-ℕ H)
+ cases-htpy-succ-based-strong-ind-ℕ k P pS n N f m M (decide-leq-succ-ℕ m n H)
cases-eq-succ-based-strong-ind-ℕ :
{l : Level} (k : ℕ) (P : ℕ → UU l)
@@ -144,7 +144,8 @@ eq-succ-based-strong-ind-ℕ :
(H : leq-ℕ (succ-ℕ n) (succ-ℕ n)) →
succ-based-strong-ind-ℕ k P pS n N f (succ-ℕ n) M H = pS n N f
eq-succ-based-strong-ind-ℕ k P pS n N f M H =
- cases-eq-succ-based-strong-ind-ℕ k P pS n N f M (cases-leq-succ-ℕ H)
+ cases-eq-succ-based-strong-ind-ℕ k P pS n N f M
+ ( decide-leq-succ-ℕ (succ-ℕ n) n H)
```
### The inductive step in the proof of based strong induction
@@ -353,7 +354,7 @@ eq-inductive-step-compute-succ-based-strong-ind-ℕ k P p0 pS n N m M =
cases-eq-inductive-step-compute-succ-based-strong-ind-ℕ
k P p0 pS i I' I m M
( J)
- ( cases-leq-succ-ℕ J)
+ ( decide-leq-succ-ℕ m i J)
( α))
( n)
( N)
@@ -412,7 +413,7 @@ based-strong-ind-ℕ' :
(p0 : P k (refl-leq-ℕ k)) →
(pS : (x : ℕ) → (H : k ≤-ℕ x) →
based-□-≤-ℕ' k P x →
- P (succ-ℕ x) (preserves-leq-succ-ℕ k x H))
+ P (succ-ℕ x) (leq-succ-leq-ℕ k x H))
(n : ℕ) → (H : k ≤-ℕ n) → P n H
based-strong-ind-ℕ' {l} k P p0 pS n H =
based-strong-ind-ℕ
@@ -425,10 +426,10 @@ based-strong-ind-ℕ' {l} k P p0 pS n H =
( p0))
( λ x H p →
apply-dependent-universal-property-contr
- ( preserves-leq-succ-ℕ k x H)
+ ( leq-succ-leq-ℕ k x H)
( is-proof-irrelevant-is-prop
( is-prop-leq-ℕ k (succ-ℕ x))
- ( preserves-leq-succ-ℕ k x H))
+ ( leq-succ-leq-ℕ k x H))
( P (succ-ℕ x))
( pS x H ( compute-base-□-≤-ℕ' k P x p)))
( n)
diff --git a/src/elementary-number-theory/bezouts-lemma-integers.lagda.md b/src/elementary-number-theory/bezouts-lemma-integers.lagda.md
index 1b169fb860..3e507b064e 100644
--- a/src/elementary-number-theory/bezouts-lemma-integers.lagda.md
+++ b/src/elementary-number-theory/bezouts-lemma-integers.lagda.md
@@ -122,7 +122,7 @@ bezouts-lemma-eqn-to-int x y H =
( minimal-positive-distance-y-coeff (abs-ℤ x) (abs-ℤ y) H)))
( abs-ℤ y)))
( inv
- ( multiplicative-abs-ℤ
+ ( distributive-abs-mul-ℤ
( int-ℕ (minimal-positive-distance-x-coeff (abs-ℤ x) (abs-ℤ y) H))
( x))))
= dist-ℕ
@@ -143,7 +143,7 @@ bezouts-lemma-eqn-to-int x y H =
( minimal-positive-distance-x-coeff (abs-ℤ x) (abs-ℤ y) H))
( x))))
( inv
- ( multiplicative-abs-ℤ
+ ( distributive-abs-mul-ℤ
( int-ℕ (minimal-positive-distance-y-coeff (abs-ℤ x) (abs-ℤ y) H))
( y))))
diff --git a/src/elementary-number-theory/bezouts-lemma-natural-numbers.lagda.md b/src/elementary-number-theory/bezouts-lemma-natural-numbers.lagda.md
index 681142d4bb..1dc139938d 100755
--- a/src/elementary-number-theory/bezouts-lemma-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/bezouts-lemma-natural-numbers.lagda.md
@@ -22,6 +22,7 @@ open import elementary-number-theory.inequality-integers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.integers
open import elementary-number-theory.lower-bounds-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
open import elementary-number-theory.modular-arithmetic
open import elementary-number-theory.multiplication-integers
open import elementary-number-theory.multiplication-natural-numbers
@@ -799,13 +800,14 @@ is-inhabited-pos-distance-between-multiples (succ-ℕ x) y = pair (succ-ℕ x)
minimal-pos-distance-between-multiples :
(x y : ℕ) → minimal-element-ℕ (pos-distance-between-multiples x y)
-minimal-pos-distance-between-multiples x y = well-ordering-principle-ℕ
- (pos-distance-between-multiples x y)
- (λ z → is-decidable-function-type
- (is-decidable-neg (is-decidable-is-zero-ℕ (x +ℕ y)))
- (is-decidable-product (is-decidable-neg (is-decidable-is-zero-ℕ z))
- (is-decidable-is-distance-between-multiples-ℕ x y z)))
- (is-inhabited-pos-distance-between-multiples x y)
+minimal-pos-distance-between-multiples x y =
+ well-ordering-principle-ℕ
+ ( pos-distance-between-multiples x y)
+ ( λ z → is-decidable-function-type
+ ( is-decidable-neg (is-decidable-is-zero-ℕ (x +ℕ y)))
+ ( is-decidable-product (is-decidable-neg (is-decidable-is-zero-ℕ z))
+ ( is-decidable-is-distance-between-multiples-ℕ x y z)))
+ ( pr2 (is-inhabited-pos-distance-between-multiples x y))
minimal-positive-distance : (x y : ℕ) → ℕ
minimal-positive-distance x y = pr1 (minimal-pos-distance-between-multiples x y)
@@ -1368,7 +1370,7 @@ remainder-min-dist-succ-x-is-distance x y =
coeff-nonnegative : leq-ℤ one-ℤ ((int-ℕ q) *ℤ (int-ℕ s))
coeff-nonnegative = tr (leq-ℤ one-ℤ)
(inv (mul-int-ℕ q s)) (leq-int-ℕ 1 (q *ℕ s)
- (leq-succ-le-ℕ 0 (q *ℕ s) (le-is-nonzero-ℕ (q *ℕ s)
+ (leq-succ-le-ℕ 0 (q *ℕ s) (le-zero-is-nonzero-ℕ (q *ℕ s)
(is-nonzero-mul-ℕ q s quotient-min-dist-succ-x-nonzero
min-dist-succ-x-coeff-nonzero))))
diff --git a/src/elementary-number-theory/bounded-divisibility-natural-numbers.lagda.md b/src/elementary-number-theory/bounded-divisibility-natural-numbers.lagda.md
new file mode 100644
index 0000000000..ec00a48f98
--- /dev/null
+++ b/src/elementary-number-theory/bounded-divisibility-natural-numbers.lagda.md
@@ -0,0 +1,398 @@
+# Bounded divisibility of natural numbers
+
+```agda
+module elementary-number-theory.bounded-divisibility-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.decidable-types
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.binary-relations
+open import foundation.cartesian-product-types
+open import foundation.decidable-propositions
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.empty-types
+open import foundation.equivalences
+open import foundation.identity-types
+open import foundation.propositions
+open import foundation.sets
+open import foundation.subtypes
+open import foundation.transport-along-identifications
+open import foundation.type-arithmetic-dependent-pair-types
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+Consider two [natural numbers](elementary-number-theory.natural-numbers.md) `m`
+and `n`. The
+{{#concept "bounded divisibility relation" Disambiguation="natural numbers" Agda=bounded-div-ℕ}}
+is a [binary relation](foundation.binary-relations.md) on the type of
+[natural numbers](elementary-number-theory.natural-numbers.md), where we say
+that a number `n` is bounded divisible by `m` if there is an integer `q ≤ n`
+such that `q * m = n`.
+
+The bounded divisibility relation is a slight strengthening of the
+[divisibility relation](elementary-number-theory.divisibility-natural-numbers.md)
+by ensuring that the quotient is bounded from above by `n`. This ensures that
+the bounded divisibility relation is valued in
+[propositions](foundation-core.propositions.md) for all `m` and `n`, unlike the
+divisibility relation. Since the bounded divisibility relation is
+[logically equivalent](foundation.logical-equivalences.md) to the divisibility
+relation, but it is always valued in the propositions, we use the bounded
+divisibility relation in the definition of the [poset](order-theory.posets.md)
+of the
+[natural numbers ordered by division](elementary-number-theory.poset-of-natural-numbers-ordered-by-divisibility.md).
+
+## Definitions
+
+### The bounded divisibility predicate
+
+```agda
+module _
+ (m n : ℕ)
+ where
+
+ bounded-div-ℕ : UU lzero
+ bounded-div-ℕ = Σ ℕ (λ k → (k ≤-ℕ n) × (k *ℕ m = n))
+
+ quotient-bounded-div-ℕ : bounded-div-ℕ → ℕ
+ quotient-bounded-div-ℕ = pr1
+
+ upper-bound-quotient-bounded-div-ℕ :
+ (H : bounded-div-ℕ) → quotient-bounded-div-ℕ H ≤-ℕ n
+ upper-bound-quotient-bounded-div-ℕ H = pr1 (pr2 H)
+
+ eq-quotient-bounded-div-ℕ :
+ (H : bounded-div-ℕ) → quotient-bounded-div-ℕ H *ℕ m = n
+ eq-quotient-bounded-div-ℕ H = pr2 (pr2 H)
+
+ eq-quotient-bounded-div-ℕ' :
+ (H : bounded-div-ℕ) → m *ℕ quotient-bounded-div-ℕ H = n
+ eq-quotient-bounded-div-ℕ' H =
+ commutative-mul-ℕ m (quotient-bounded-div-ℕ H) ∙ eq-quotient-bounded-div-ℕ H
+```
+
+## Properties
+
+### If a nonzero number `n` is bounded divisible by `m`, then its quotient is nonzero
+
+```agda
+is-nonzero-quotient-bounded-div-ℕ :
+ (m n : ℕ) → is-nonzero-ℕ n → (H : bounded-div-ℕ m n) →
+ is-nonzero-ℕ (quotient-bounded-div-ℕ m n H)
+is-nonzero-quotient-bounded-div-ℕ m n N H refl =
+ N (inv (eq-quotient-bounded-div-ℕ m n H))
+```
+
+### If a nonzero number `n` is bounded divisible by `m`, then `m` is bounded from above by `n`
+
+**Proof.** Suppose that `q ≤ n` is such that `q * m = n`. Since `n` is assumed
+to be nonzero, it follows that `q` is nonzero. Therefore it follows that
+`m ≤ q * m = n`.
+
+```agda
+upper-bound-divisor-bounded-div-ℕ :
+ (m n : ℕ) → is-nonzero-ℕ n → bounded-div-ℕ m n → m ≤-ℕ n
+upper-bound-divisor-bounded-div-ℕ m n H K =
+ concatenate-leq-eq-ℕ m
+ ( leq-mul-is-nonzero-ℕ'
+ ( quotient-bounded-div-ℕ m n K)
+ ( m)
+ ( is-nonzero-quotient-bounded-div-ℕ m n H K))
+ ( eq-quotient-bounded-div-ℕ m n K)
+```
+
+### If `n` is bounded divisible by a number `m`, then `n` is bounded divisible by its quotient by `m`
+
+```agda
+bounded-div-quotient-bounded-div-ℕ :
+ (m n : ℕ) (H : bounded-div-ℕ m n) →
+ bounded-div-ℕ (quotient-bounded-div-ℕ m n H) n
+bounded-div-quotient-bounded-div-ℕ m zero-ℕ (q , b , p) =
+ ( 0 , refl-leq-ℕ 0 , refl)
+bounded-div-quotient-bounded-div-ℕ m (succ-ℕ n) H@(q , b , p) =
+ ( m ,
+ upper-bound-divisor-bounded-div-ℕ m (succ-ℕ n) (is-nonzero-succ-ℕ n) H ,
+ commutative-mul-ℕ m (quotient-bounded-div-ℕ m (succ-ℕ n) H) ∙
+ eq-quotient-bounded-div-ℕ m (succ-ℕ n) H)
+```
+
+### Bounded divisibility is decidable
+
+```agda
+is-decidable-bounded-div-ℕ :
+ (m n : ℕ) → is-decidable (bounded-div-ℕ m n)
+is-decidable-bounded-div-ℕ m n =
+ is-decidable-bounded-Σ-ℕ'
+ ( n)
+ ( λ x → mul-ℕ x m = n)
+ ( λ x → has-decidable-equality-ℕ (mul-ℕ x m) n)
+```
+
+### Concatenating equality and bounded divisibility
+
+```agda
+concatenate-eq-bounded-div-ℕ :
+ {x y z : ℕ} → x = y → bounded-div-ℕ y z → bounded-div-ℕ x z
+concatenate-eq-bounded-div-ℕ refl p = p
+
+concatenate-bounded-div-eq-ℕ :
+ {x y z : ℕ} → bounded-div-ℕ x y → y = z → bounded-div-ℕ x z
+concatenate-bounded-div-eq-ℕ p refl = p
+
+concatenate-eq-bounded-div-eq-ℕ :
+ {x y z w : ℕ} → x = y → bounded-div-ℕ y z → z = w → bounded-div-ℕ x w
+concatenate-eq-bounded-div-eq-ℕ refl p refl = p
+```
+
+### The quotients of a natural number `n` by two natural numbers `c` and `d` are equal if `c` and `d` are equal
+
+Since the quotient is defined in terms of explicit proofs of divisibility, we
+assume arbitrary proofs of dibisibility on both sides.
+
+```agda
+eq-quotient-bounded-div-eq-divisor-ℕ :
+ (c d n : ℕ) → is-nonzero-ℕ c → c = d →
+ (H : bounded-div-ℕ c n) → (I : bounded-div-ℕ d n) →
+ quotient-bounded-div-ℕ c n H = quotient-bounded-div-ℕ d n I
+eq-quotient-bounded-div-eq-divisor-ℕ c d n N p H I =
+ is-injective-left-mul-ℕ c N
+ ( tr
+ ( λ x → c *ℕ quotient-bounded-div-ℕ c n H = x *ℕ quotient-bounded-div-ℕ d n I)
+ ( inv p)
+ ( commutative-mul-ℕ c (quotient-bounded-div-ℕ c n H) ∙
+ eq-quotient-bounded-div-ℕ c n H ∙
+ inv (eq-quotient-bounded-div-ℕ d n I) ∙
+ commutative-mul-ℕ (quotient-bounded-div-ℕ d n I) d))
+```
+
+### If two natural numbers are equal and one is divisible by a number `d`, then the other is divisible by `d` and their quotients are the same
+
+The first part of the claim was proven above. Since the quotient is defined in
+terms of explicit proofs of divisibility, we assume arbitrary proofs of
+dibisibility on both sides.
+
+```agda
+eq-quotient-bounded-div-eq-is-nonzero-divisor-ℕ :
+ {d m n : ℕ} → is-nonzero-ℕ d → m = n → (H : bounded-div-ℕ d m) (K : bounded-div-ℕ d n) →
+ quotient-bounded-div-ℕ d m H = quotient-bounded-div-ℕ d n K
+eq-quotient-bounded-div-eq-is-nonzero-divisor-ℕ N refl H K =
+ is-injective-right-mul-ℕ _ N
+ ( eq-quotient-bounded-div-ℕ _ _ H ∙ inv (eq-quotient-bounded-div-ℕ _ _ K))
+
+eq-quotient-bounded-div-eq-is-nonzero-ℕ :
+ {d m n : ℕ} → is-nonzero-ℕ m → m = n → (H : bounded-div-ℕ d m) (K : bounded-div-ℕ d n) →
+ quotient-bounded-div-ℕ d m H = quotient-bounded-div-ℕ d n K
+eq-quotient-bounded-div-eq-is-nonzero-ℕ {zero-ℕ} N refl H K =
+ ex-falso
+ ( N
+ ( inv (eq-quotient-bounded-div-ℕ _ _ H) ∙
+ right-zero-law-mul-ℕ (quotient-bounded-div-ℕ _ _ H)))
+eq-quotient-bounded-div-eq-is-nonzero-ℕ {succ-ℕ d} N refl H K =
+ eq-quotient-bounded-div-eq-is-nonzero-divisor-ℕ
+ ( is-nonzero-succ-ℕ d) refl H K
+```
+
+### Bounded divisibility is a property
+
+```agda
+abstract
+ is-prop-bounded-div-ℕ :
+ (k n : ℕ) → is-prop (bounded-div-ℕ k n)
+ is-prop-bounded-div-ℕ zero-ℕ n =
+ is-prop-all-elements-equal
+ ( λ (q , b , p) (q' , b' , p') →
+ eq-type-subtype
+ ( λ u → product-Prop (leq-ℕ-Prop u n) (Id-Prop ℕ-Set _ _))
+ ( is-zero-leq-zero-ℕ q
+ ( concatenate-leq-eq-ℕ q b (inv p ∙ right-zero-law-mul-ℕ q)) ∙
+ inv
+ ( is-zero-leq-zero-ℕ q'
+ ( concatenate-leq-eq-ℕ q' b'
+ ( inv p' ∙ right-zero-law-mul-ℕ q')))))
+ is-prop-bounded-div-ℕ (succ-ℕ k) n =
+ is-prop-all-elements-equal
+ ( λ (q , b , p) (q' , b' , p') →
+ eq-type-subtype
+ ( λ u → product-Prop (leq-ℕ-Prop u n) (Id-Prop ℕ-Set _ _))
+ ( eq-quotient-bounded-div-eq-divisor-ℕ
+ ( succ-ℕ k)
+ ( succ-ℕ k)
+ ( n)
+ ( is-nonzero-succ-ℕ k)
+ ( refl)
+ ( q , b , p)
+ ( q' , b' , p')))
+
+bounded-div-ℕ-Prop : (k n : ℕ) → Prop lzero
+pr1 (bounded-div-ℕ-Prop k n) = bounded-div-ℕ k n
+pr2 (bounded-div-ℕ-Prop k n) = is-prop-bounded-div-ℕ k n
+
+bounded-div-ℕ-Decidable-Prop : (k n : ℕ) → Decidable-Prop lzero
+pr1 (bounded-div-ℕ-Decidable-Prop k n) = bounded-div-ℕ k n
+pr1 (pr2 (bounded-div-ℕ-Decidable-Prop k n)) = is-prop-bounded-div-ℕ k n
+pr2 (pr2 (bounded-div-ℕ-Decidable-Prop k n)) = is-decidable-bounded-div-ℕ k n
+```
+
+### The quotient of two numbers by any two proofs bounded divisibility are the same
+
+```agda
+compute-quotient-bounded-div-ℕ :
+ {m m' n n' : ℕ} (q : m = m') (p : n = n')
+ (H : bounded-div-ℕ m n) (K : bounded-div-ℕ m' n') →
+ quotient-bounded-div-ℕ m n H = quotient-bounded-div-ℕ m' n' K
+compute-quotient-bounded-div-ℕ refl refl H K =
+ ap
+ ( quotient-bounded-div-ℕ _ _)
+ { H}
+ { K}
+ ( eq-is-prop (is-prop-bounded-div-ℕ _ _))
+```
+
+### `0` is bounded divisible by any natural number
+
+```agda
+bounded-div-zero-ℕ :
+ (n : ℕ) → bounded-div-ℕ n 0
+pr1 (bounded-div-zero-ℕ n) = 0
+pr1 (pr2 (bounded-div-zero-ℕ n)) = refl-leq-ℕ 0
+pr2 (pr2 (bounded-div-zero-ℕ n)) = left-zero-law-mul-ℕ n
+
+is-zero-quotient-bounded-div-zero-ℕ :
+ (n : ℕ) (H : bounded-div-ℕ n 0) →
+ is-zero-ℕ (quotient-bounded-div-ℕ n 0 H)
+is-zero-quotient-bounded-div-zero-ℕ n H =
+ is-zero-leq-zero-ℕ
+ ( quotient-bounded-div-ℕ n 0 H)
+ ( upper-bound-quotient-bounded-div-ℕ n 0 H)
+
+is-zero-quotient-bounded-div-is-zero-ℕ :
+ (m n : ℕ) (H : bounded-div-ℕ m n) →
+ is-zero-ℕ n → is-zero-ℕ (quotient-bounded-div-ℕ m n H)
+is-zero-quotient-bounded-div-is-zero-ℕ m .zero-ℕ H refl =
+ is-zero-quotient-bounded-div-zero-ℕ m H
+```
+
+### If a number is bounded divisible by `0`, then it is `0`
+
+```agda
+is-zero-bounded-div-zero-divisor-ℕ :
+ (n : ℕ) → bounded-div-ℕ 0 n → is-zero-ℕ n
+is-zero-bounded-div-zero-divisor-ℕ n H =
+ inv (eq-quotient-bounded-div-ℕ 0 n H) ∙
+ right-zero-law-mul-ℕ (quotient-bounded-div-ℕ 0 n H)
+
+is-zero-quotient-bounded-div-zero-divisor-ℕ :
+ (n : ℕ) (H : bounded-div-ℕ 0 n) →
+ is-zero-ℕ (quotient-bounded-div-ℕ 0 n H)
+is-zero-quotient-bounded-div-zero-divisor-ℕ n H =
+ is-zero-quotient-bounded-div-is-zero-ℕ 0 n H
+ ( is-zero-bounded-div-zero-divisor-ℕ n H)
+
+is-zero-bounded-div-is-zero-divisor-ℕ :
+ (m n : ℕ) → bounded-div-ℕ m n → is-zero-ℕ m → is-zero-ℕ n
+is-zero-bounded-div-is-zero-divisor-ℕ .zero-ℕ n H refl =
+ is-zero-bounded-div-zero-divisor-ℕ n H
+
+is-zero-quotient-bounded-div-is-zero-divisor-ℕ :
+ (m n : ℕ) (H : bounded-div-ℕ m n) →
+ is-zero-ℕ m → is-zero-ℕ (quotient-bounded-div-ℕ m n H)
+is-zero-quotient-bounded-div-is-zero-divisor-ℕ m n H p =
+ is-zero-quotient-bounded-div-is-zero-ℕ m n H
+ ( is-zero-bounded-div-is-zero-divisor-ℕ m n H p)
+```
+
+### The divisibility relation is a partial order on the natural numbers
+
+The [poset](order-theory.posets.md) of natural numbers ordered by divisibility
+is defined in
+[`elementary-number-theory.poset-of-natural-numbers-ordered-by-divisibility`](elementary-number-theory.poset-of-natural-numbers-ordered-by-divisibility.md).
+
+```agda
+refl-bounded-div-ℕ : is-reflexive bounded-div-ℕ
+pr1 (refl-bounded-div-ℕ zero-ℕ) = 0
+pr1 (pr2 (refl-bounded-div-ℕ zero-ℕ)) = refl-leq-ℕ 0
+pr2 (pr2 (refl-bounded-div-ℕ zero-ℕ)) = refl
+pr1 (refl-bounded-div-ℕ (succ-ℕ n)) = 1
+pr1 (pr2 (refl-bounded-div-ℕ (succ-ℕ n))) = leq-zero-ℕ n
+pr2 (pr2 (refl-bounded-div-ℕ (succ-ℕ n))) = left-unit-law-mul-ℕ (succ-ℕ n)
+
+bounded-div-eq-ℕ : (x y : ℕ) → x = y → bounded-div-ℕ x y
+bounded-div-eq-ℕ x .x refl = refl-bounded-div-ℕ x
+
+antisymmetric-bounded-div-ℕ : is-antisymmetric bounded-div-ℕ
+antisymmetric-bounded-div-ℕ zero-ℕ n H K =
+ inv (is-zero-bounded-div-zero-divisor-ℕ n H)
+antisymmetric-bounded-div-ℕ (succ-ℕ m) zero-ℕ H K =
+ is-zero-bounded-div-zero-divisor-ℕ (succ-ℕ m) K
+antisymmetric-bounded-div-ℕ (succ-ℕ m) (succ-ℕ n) H K =
+ antisymmetric-leq-ℕ
+ ( succ-ℕ m)
+ ( succ-ℕ n)
+ ( upper-bound-divisor-bounded-div-ℕ
+ ( succ-ℕ m)
+ ( succ-ℕ n)
+ ( is-nonzero-succ-ℕ n)
+ ( H))
+ ( upper-bound-divisor-bounded-div-ℕ
+ ( succ-ℕ n)
+ ( succ-ℕ m)
+ ( is-nonzero-succ-ℕ m)
+ ( K))
+
+quotient-transitive-bounded-div-ℕ :
+ (m n k : ℕ) → bounded-div-ℕ n k → bounded-div-ℕ m n → ℕ
+quotient-transitive-bounded-div-ℕ m n k K H =
+ quotient-bounded-div-ℕ n k K *ℕ quotient-bounded-div-ℕ m n H
+
+eq-quotient-transitive-bounded-div-ℕ :
+ (m n k : ℕ) (K : bounded-div-ℕ n k) (H : bounded-div-ℕ m n) →
+ quotient-transitive-bounded-div-ℕ m n k K H *ℕ m = k
+eq-quotient-transitive-bounded-div-ℕ m n k K H =
+ ( associative-mul-ℕ
+ ( quotient-bounded-div-ℕ n k K)
+ ( quotient-bounded-div-ℕ m n H)
+ ( m)) ∙
+ ( ap
+ ( mul-ℕ (quotient-bounded-div-ℕ n k K))
+ ( eq-quotient-bounded-div-ℕ m n H)) ∙
+ ( eq-quotient-bounded-div-ℕ n k K)
+
+upper-bound-quotient-transitive-bounded-div-ℕ :
+ (m n k : ℕ) (K : bounded-div-ℕ n k) (H : bounded-div-ℕ m n) →
+ quotient-transitive-bounded-div-ℕ m n k K H ≤-ℕ k
+upper-bound-quotient-transitive-bounded-div-ℕ zero-ℕ n k K H =
+ leq-is-zero-ℕ
+ ( quotient-transitive-bounded-div-ℕ 0 n k K H)
+ ( k)
+ ( right-zero-law-mul-is-zero-ℕ
+ ( quotient-bounded-div-ℕ n k K)
+ ( quotient-bounded-div-ℕ 0 n H)
+ ( is-zero-quotient-bounded-div-zero-divisor-ℕ n H))
+upper-bound-quotient-transitive-bounded-div-ℕ (succ-ℕ m) n k K H =
+ leq-left-factor-eq-ℕ
+ ( quotient-transitive-bounded-div-ℕ (succ-ℕ m) n k K H)
+ ( succ-ℕ m)
+ ( k)
+ ( is-nonzero-succ-ℕ m)
+ ( eq-quotient-transitive-bounded-div-ℕ (succ-ℕ m) n k K H)
+
+transitive-bounded-div-ℕ : is-transitive bounded-div-ℕ
+pr1 (transitive-bounded-div-ℕ m n k K H) =
+ quotient-transitive-bounded-div-ℕ m n k K H
+pr1 (pr2 (transitive-bounded-div-ℕ m n k K H)) =
+ upper-bound-quotient-transitive-bounded-div-ℕ m n k K H
+pr2 (pr2 (transitive-bounded-div-ℕ m n k K H)) =
+ eq-quotient-transitive-bounded-div-ℕ m n k K H
+```
diff --git a/src/elementary-number-theory/bounded-natural-numbers.lagda.md b/src/elementary-number-theory/bounded-natural-numbers.lagda.md
new file mode 100644
index 0000000000..830699c005
--- /dev/null
+++ b/src/elementary-number-theory/bounded-natural-numbers.lagda.md
@@ -0,0 +1,130 @@
+# Bounded natural numbers
+
+```agda
+module elementary-number-theory.bounded-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.congruence-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.modular-arithmetic-standard-finite-types
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+
+open import foundation.dependent-pair-types
+open import foundation.equivalences
+open import foundation.retractions
+open import foundation.sections
+open import foundation.sets
+open import foundation.subtypes
+open import foundation.universe-levels
+
+open import univalent-combinatorics.counting
+open import univalent-combinatorics.finite-types
+open import univalent-combinatorics.standard-finite-types
+```
+
+
+
+## Idea
+
+The type of {{#concept "bounded natural numbers" Agda=bounded-ℕ}} with upper
+bound $n$ is the type
+
+$$
+ \mathbb{N}_{\leq n} := \{k : ℕ \mid k \leq n\}.
+$$
+
+The type $\mathbb{N}_{\leq n}$ is [equivalent](foundation-core.equivalences.md)
+to the [standard finite type](univalent-combinatorics.standard-finite-types.md)
+$\mathsf{Fin}(n+1)$.
+
+## Definition
+
+### The bounded natural numbers
+
+```agda
+bounded-ℕ : ℕ → UU lzero
+bounded-ℕ n = Σ ℕ (λ k → k ≤-ℕ n)
+
+nat-bounded-ℕ : (n : ℕ) → bounded-ℕ n → ℕ
+nat-bounded-ℕ n = pr1
+
+upper-bound-nat-bounded-ℕ : (n : ℕ) (x : bounded-ℕ n) → nat-bounded-ℕ n x ≤-ℕ n
+upper-bound-nat-bounded-ℕ n = pr2
+```
+
+## Properties
+
+### The type of bounded natural numbers is a set
+
+```agda
+is-set-bounded-ℕ :
+ (n : ℕ) → is-set (bounded-ℕ n)
+is-set-bounded-ℕ n =
+ is-set-type-subtype
+ ( λ k → leq-ℕ-Prop k n)
+ ( is-set-ℕ)
+```
+
+### The type $\mathbb{N}_{\leq b}$ is equivalent to the standard finite type $\mathsf{Fin}(n+1)$
+
+```agda
+bounded-nat-Fin :
+ (n : ℕ) → Fin (succ-ℕ n) → bounded-ℕ n
+pr1 (bounded-nat-Fin n x) = nat-Fin (succ-ℕ n) x
+pr2 (bounded-nat-Fin n x) = upper-bound-nat-Fin n x
+
+fin-bounded-ℕ :
+ (n : ℕ) → bounded-ℕ n → Fin (succ-ℕ n)
+fin-bounded-ℕ n x =
+ mod-succ-ℕ n (nat-bounded-ℕ n x)
+
+is-section-fin-bounded-ℕ :
+ (n : ℕ) → is-section (bounded-nat-Fin n) (fin-bounded-ℕ n)
+is-section-fin-bounded-ℕ n i =
+ eq-type-subtype
+ ( λ x → leq-ℕ-Prop x n)
+ ( eq-cong-le-ℕ
+ ( succ-ℕ n)
+ ( nat-Fin (succ-ℕ n) (fin-bounded-ℕ n i))
+ ( nat-bounded-ℕ n i)
+ ( strict-upper-bound-nat-Fin (succ-ℕ n) (fin-bounded-ℕ n i))
+ ( le-succ-leq-ℕ (nat-bounded-ℕ n i) n (upper-bound-nat-bounded-ℕ n i))
+ ( cong-nat-mod-succ-ℕ n (nat-bounded-ℕ n i)))
+
+is-retraction-fin-bounded-ℕ :
+ (n : ℕ) → is-retraction (bounded-nat-Fin n) (fin-bounded-ℕ n)
+is-retraction-fin-bounded-ℕ n =
+ is-section-nat-Fin n
+
+is-equiv-bounded-nat-Fin :
+ (n : ℕ) → is-equiv (bounded-nat-Fin n)
+is-equiv-bounded-nat-Fin n =
+ is-equiv-is-invertible
+ ( fin-bounded-ℕ n)
+ ( is-section-fin-bounded-ℕ n)
+ ( is-retraction-fin-bounded-ℕ n)
+
+equiv-count-bounded-ℕ :
+ (n : ℕ) → Fin (succ-ℕ n) ≃ bounded-ℕ n
+pr1 (equiv-count-bounded-ℕ n) = bounded-nat-Fin n
+pr2 (equiv-count-bounded-ℕ n) = is-equiv-bounded-nat-Fin n
+
+count-bounded-ℕ :
+ (n : ℕ) → count (bounded-ℕ n)
+pr1 (count-bounded-ℕ n) = succ-ℕ n
+pr2 (count-bounded-ℕ n) = equiv-count-bounded-ℕ n
+
+is-finite-bounded-ℕ :
+ (n : ℕ) → is-finite (bounded-ℕ n)
+is-finite-bounded-ℕ n =
+ is-finite-count (count-bounded-ℕ n)
+```
+
+## See also
+
+- [The strictly bounded natural numbers](elementary-number-theory.strictly-bounded-natural-numbers.md)
diff --git a/src/elementary-number-theory/cofibonacci.lagda.md b/src/elementary-number-theory/cofibonacci.lagda.md
index e2a6f001ba..d88d3387be 100644
--- a/src/elementary-number-theory/cofibonacci.lagda.md
+++ b/src/elementary-number-theory/cofibonacci.lagda.md
@@ -11,6 +11,7 @@ open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.fibonacci-sequence
open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
open import elementary-number-theory.modular-arithmetic-standard-finite-types
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.pisano-periods
@@ -34,7 +35,7 @@ The {{#concept "cofibonacci sequence" Agda=cofibonacci}} is the unique function
`G : ℕ → ℕ` satisfying the property that
```text
- div-ℕ (G m) n ↔ div-ℕ m (Fibonacci-ℕ n).
+ div-ℕ (G m) n ↔ div-ℕ m (fibonacci-ℕ n).
```
The sequence starts
@@ -51,16 +52,16 @@ The sequence starts
```agda
is-multiple-of-cofibonacci : (m x : ℕ) → UU lzero
is-multiple-of-cofibonacci m x =
- is-nonzero-ℕ m → is-nonzero-ℕ x × div-ℕ m (Fibonacci-ℕ x)
+ is-nonzero-ℕ m → is-nonzero-ℕ x × div-ℕ m (fibonacci-ℕ x)
is-decidable-is-multiple-of-cofibonacci :
(m x : ℕ) → is-decidable (is-multiple-of-cofibonacci m x)
is-decidable-is-multiple-of-cofibonacci m x =
is-decidable-function-type
- ( is-decidable-is-nonzero-ℕ m)
+ ( is-decidable-zero-is-nonzero-ℕ m)
( is-decidable-product
- ( is-decidable-is-nonzero-ℕ x)
- ( is-decidable-div-ℕ m (Fibonacci-ℕ x)))
+ ( is-decidable-zero-is-nonzero-ℕ x)
+ ( is-decidable-div-ℕ m (fibonacci-ℕ x)))
cofibonacci-multiple : (m : ℕ) → Σ ℕ (is-multiple-of-cofibonacci m)
cofibonacci-multiple zero-ℕ = pair zero-ℕ (λ f → (ex-falso (f refl)))
@@ -79,7 +80,7 @@ least-multiple-of-cofibonacci m =
well-ordering-principle-ℕ
( is-multiple-of-cofibonacci m)
( is-decidable-is-multiple-of-cofibonacci m)
- ( cofibonacci-multiple m)
+ ( pr2 (cofibonacci-multiple m))
cofibonacci : ℕ → ℕ
cofibonacci m = pr1 (least-multiple-of-cofibonacci m)
@@ -112,12 +113,12 @@ is-zero-cofibonacci-zero-ℕ =
```agda
forward-is-left-adjoint-cofibonacci :
- (m n : ℕ) → div-ℕ (cofibonacci m) n → div-ℕ m (Fibonacci-ℕ n)
+ (m n : ℕ) → div-ℕ (cofibonacci m) n → div-ℕ m (fibonacci-ℕ n)
forward-is-left-adjoint-cofibonacci zero-ℕ n H =
tr
( div-ℕ zero-ℕ)
( ap
- ( Fibonacci-ℕ)
+ ( fibonacci-ℕ)
( inv
( is-zero-div-zero-ℕ n
( tr (λ t → div-ℕ t n) is-zero-cofibonacci-zero-ℕ H))))
@@ -125,7 +126,7 @@ forward-is-left-adjoint-cofibonacci zero-ℕ n H =
forward-is-left-adjoint-cofibonacci (succ-ℕ m) zero-ℕ H =
div-zero-ℕ (succ-ℕ m)
forward-is-left-adjoint-cofibonacci (succ-ℕ m) (succ-ℕ n) H =
- div-Fibonacci-div-ℕ
+ div-fibonacci-div-ℕ
( succ-ℕ m)
( cofibonacci (succ-ℕ m))
( succ-ℕ n)
@@ -137,11 +138,11 @@ forward-is-left-adjoint-cofibonacci (succ-ℕ m) (succ-ℕ n) H =
{-
converse-is-left-adjoint-cofibonacci :
- (m n : ℕ) → div-ℕ m (Fibonacci-ℕ n) → div-ℕ (cofibonacci m) n
+ (m n : ℕ) → div-ℕ m (fibonacci-ℕ n) → div-ℕ (cofibonacci m) n
converse-is-left-adjoint-cofibonacci m n H = {!!}
is-left-adjoint-cofibonacci :
- (m n : ℕ) → div-ℕ (cofibonacci m) n ↔ div-ℕ m (Fibonacci-ℕ n)
+ (m n : ℕ) → div-ℕ (cofibonacci m) n ↔ div-ℕ m (fibonacci-ℕ n)
is-left-adjoint-cofibonacci m n = {!!}
-}
```
diff --git a/src/elementary-number-theory/collatz-conjecture.lagda.md b/src/elementary-number-theory/collatz-conjecture.lagda.md
index 9c44a48d71..2cc9fef51c 100644
--- a/src/elementary-number-theory/collatz-conjecture.lagda.md
+++ b/src/elementary-number-theory/collatz-conjecture.lagda.md
@@ -7,7 +7,7 @@ module elementary-number-theory.collatz-conjecture where
Imports
```agda
-open import elementary-number-theory.modular-arithmetic-standard-finite-types
+open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
diff --git a/src/elementary-number-theory/congruence-integers.lagda.md b/src/elementary-number-theory/congruence-integers.lagda.md
index 9844348d01..c993c7b4c6 100644
--- a/src/elementary-number-theory/congruence-integers.lagda.md
+++ b/src/elementary-number-theory/congruence-integers.lagda.md
@@ -16,6 +16,8 @@ open import elementary-number-theory.divisibility-integers
open import elementary-number-theory.integers
open import elementary-number-theory.multiplication-integers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.unit-integers
+open import elementary-number-theory.unit-similarity-integers
open import foundation.action-on-identifications-functions
open import foundation.binary-relations
@@ -57,23 +59,25 @@ is-discrete-cong-ℤ .zero-ℤ refl x y K =
eq-diff-ℤ (is-zero-div-zero-ℤ (x -ℤ y) K)
is-unit-cong-succ-ℤ : (k x : ℤ) → cong-ℤ k x (succ-ℤ x) → is-unit-ℤ k
-pr1 (is-unit-cong-succ-ℤ k x (pair y p)) = neg-ℤ y
-pr2 (is-unit-cong-succ-ℤ k x (pair y p)) =
- ( left-negative-law-mul-ℤ y k) ∙
- ( is-injective-neg-ℤ
- ( ( neg-neg-ℤ (y *ℤ k)) ∙
- ( ( p) ∙
- ( ( ap (x +ℤ_) (neg-succ-ℤ x)) ∙
- ( ( right-predecessor-law-add-ℤ x (neg-ℤ x)) ∙
- ( ap pred-ℤ (right-inverse-law-add-ℤ x)))))))
+is-unit-cong-succ-ℤ k x (y , p) =
+ is-unit-div-one-ℤ k
+ ( neg-ℤ y ,
+ ( left-negative-law-mul-ℤ y k) ∙
+ ( is-injective-neg-ℤ
+ ( ( neg-neg-ℤ (y *ℤ k)) ∙
+ ( ( p) ∙
+ ( ( ap (x +ℤ_) (neg-succ-ℤ x)) ∙
+ ( ( right-predecessor-law-add-ℤ x (neg-ℤ x)) ∙
+ ( ap pred-ℤ (right-inverse-law-add-ℤ x))))))))
is-unit-cong-pred-ℤ : (k x : ℤ) → cong-ℤ k x (pred-ℤ x) → is-unit-ℤ k
-pr1 (is-unit-cong-pred-ℤ k x (pair y p)) = y
-pr2 (is-unit-cong-pred-ℤ k x (pair y p)) =
- ( p) ∙
- ( ( ap (x +ℤ_) (neg-pred-ℤ x)) ∙
- ( ( right-successor-law-add-ℤ x (neg-ℤ x)) ∙
- ( ap succ-ℤ (right-inverse-law-add-ℤ x))))
+is-unit-cong-pred-ℤ k x (y , p) =
+ is-unit-div-one-ℤ k
+ ( y ,
+ ( p) ∙
+ ( ( ap (x +ℤ_) (neg-pred-ℤ x)) ∙
+ ( ( right-successor-law-add-ℤ x (neg-ℤ x)) ∙
+ ( ap succ-ℤ (right-inverse-law-add-ℤ x)))))
refl-cong-ℤ : (k : ℤ) → is-reflexive (cong-ℤ k)
pr1 (refl-cong-ℤ k x) = zero-ℤ
diff --git a/src/elementary-number-theory/congruence-natural-numbers.lagda.md b/src/elementary-number-theory/congruence-natural-numbers.lagda.md
index d4c0ff60a4..82012e8878 100644
--- a/src/elementary-number-theory/congruence-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/congruence-natural-numbers.lagda.md
@@ -27,6 +27,33 @@ open import univalent-combinatorics.standard-finite-types
+## Idea
+
+Two [natural numbers](elementary-number-theory.natural-numbers.md) `x` and `y`
+are said to be
+{{#concept "congruent" Disambiguation="natural numbers" Agda=cong-ℕ WDID=Q3773677 WD="congruence of integers"}}
+modulo `k` if their
+[distance](elementary-number-theory.distance-natural-numbers.md) `dist-ℕ x y` is
+[divisible](elementary-number-theory.divisibility-natural-numbers.md) by `k`,
+i.e., if
+
+```text
+ k | dist-ℕ x y.
+```
+
+For each natural number `k`, the congruence relation modulo `k` defines an
+[equivalence relation](foundation.equivalence-relations.md). Furthermore, the
+congruence relations respect
+[addition](elementary-number-theory.addition-natural-numbers.md) and
+[multiplication](elementary-number-theory.multiplication-natural-numbers.md).
+
+[Quotienting](foundation.set-quotients.md) by the congruence relation leads to
+[modular arithmetic](elementary-number-theory.modular-arithmetic.md). Properties
+of the congruence relation with respect to the
+[standard finite types](univalent-combinatorics.standard-finite-types.md) are
+formalized in the file
+[`modular-arithmetic-standard-finite-types`](elementary-number-theory.modular-arithmetic-standard-finite-types.md).
+
## Properties
### The congruence relations on the natural numbers
@@ -36,56 +63,44 @@ cong-ℕ :
ℕ → ℕ → ℕ → UU lzero
cong-ℕ k x y = div-ℕ k (dist-ℕ x y)
-_≡_mod_ : ℕ → ℕ → ℕ → UU lzero
-x ≡ y mod k = cong-ℕ k x y
-
-concatenate-eq-cong-eq-ℕ :
- (k : ℕ) {x1 x2 x3 x4 : ℕ} →
- x1 = x2 → cong-ℕ k x2 x3 → x3 = x4 → cong-ℕ k x1 x4
-concatenate-eq-cong-eq-ℕ k refl H refl = H
+_≡_mod-ℕ_ : ℕ → ℕ → ℕ → UU lzero
+x ≡ y mod-ℕ k = cong-ℕ k x y
+```
-concatenate-eq-cong-ℕ :
- (k : ℕ) {x1 x2 x3 : ℕ} →
- x1 = x2 → cong-ℕ k x2 x3 → cong-ℕ k x1 x3
-concatenate-eq-cong-ℕ k refl H = H
+## Properties
-concatenate-cong-eq-ℕ :
- (k : ℕ) {x1 x2 x3 : ℕ} →
- cong-ℕ k x1 x2 → x2 = x3 → cong-ℕ k x1 x3
-concatenate-cong-eq-ℕ k H refl = H
+### Any two natural numbers are congruent to each other modulo `1`
+```agda
is-indiscrete-cong-one-ℕ :
- (x y : ℕ) → cong-ℕ 1 x y
+ (x y : ℕ) → x ≡ y mod-ℕ 1
is-indiscrete-cong-one-ℕ x y = div-one-ℕ (dist-ℕ x y)
+```
-is-discrete-cong-zero-ℕ :
- (x y : ℕ) → cong-ℕ zero-ℕ x y → x = y
-is-discrete-cong-zero-ℕ x y (pair k p) =
- eq-dist-ℕ x y ((inv p) ∙ (right-zero-law-mul-ℕ k))
-
-cong-zero-ℕ :
- (k : ℕ) → cong-ℕ k k zero-ℕ
-pr1 (cong-zero-ℕ k) = 1
-pr2 (cong-zero-ℕ k) =
- (left-unit-law-mul-ℕ k) ∙ (inv (right-unit-law-dist-ℕ k))
+### Congruence of natural numbers is a reflexive relation
+```agda
refl-cong-ℕ : (k : ℕ) → is-reflexive (cong-ℕ k)
pr1 (refl-cong-ℕ k x) = zero-ℕ
pr2 (refl-cong-ℕ k x) =
(left-zero-law-mul-ℕ (succ-ℕ k)) ∙ (inv (dist-eq-ℕ x x refl))
cong-identification-ℕ :
- (k : ℕ) {x y : ℕ} → x = y → cong-ℕ k x y
+ (k : ℕ) {x y : ℕ} → x = y → x ≡ y mod-ℕ k
cong-identification-ℕ k {x} refl = refl-cong-ℕ k x
+```
+
+### Congruence of natural numbers is a symmetric relation
+```agda
symmetric-cong-ℕ : (k : ℕ) → is-symmetric (cong-ℕ k)
-pr1 (symmetric-cong-ℕ k x y (pair d p)) = d
-pr2 (symmetric-cong-ℕ k x y (pair d p)) = p ∙ (symmetric-dist-ℕ x y)
+pr1 (symmetric-cong-ℕ k x y (d , p)) = d
+pr2 (symmetric-cong-ℕ k x y (d , p)) = p ∙ (symmetric-dist-ℕ x y)
+```
-cong-zero-ℕ' : (k : ℕ) → cong-ℕ k zero-ℕ k
-cong-zero-ℕ' k =
- symmetric-cong-ℕ k k zero-ℕ (cong-zero-ℕ k)
+### Congruence of natural numbers is a transitive relation
+```agda
transitive-cong-ℕ : (k : ℕ) → is-transitive (cong-ℕ k)
transitive-cong-ℕ k x y z e d with is-total-dist-ℕ x y z
transitive-cong-ℕ k x y z e d | inl α =
@@ -96,39 +111,60 @@ transitive-cong-ℕ k x y z e d | inr (inl α) =
transitive-cong-ℕ k x y z e d | inr (inr α) =
div-left-summand-ℕ k (dist-ℕ x z) (dist-ℕ x y) d
( concatenate-div-eq-ℕ e (inv α))
+```
+
+### Concatenating congruence and equality
+
+```agda
+concatenate-eq-cong-eq-ℕ :
+ (k : ℕ) {x1 x2 x3 x4 : ℕ} →
+ x1 = x2 → x2 ≡ x3 mod-ℕ k → x3 = x4 → x1 ≡ x4 mod-ℕ k
+concatenate-eq-cong-eq-ℕ k refl H refl = H
+
+concatenate-eq-cong-ℕ :
+ (k : ℕ) {x1 x2 x3 : ℕ} →
+ x1 = x2 → x2 ≡ x3 mod-ℕ k → x1 ≡ x3 mod-ℕ k
+concatenate-eq-cong-ℕ k refl H = H
+
+concatenate-cong-eq-ℕ :
+ (k : ℕ) {x1 x2 x3 : ℕ} →
+ x1 ≡ x2 mod-ℕ k → x2 = x3 → x1 ≡ x3 mod-ℕ k
+concatenate-cong-eq-ℕ k H refl = H
concatenate-cong-eq-cong-ℕ :
{k x1 x2 x3 x4 : ℕ} →
- cong-ℕ k x1 x2 → x2 = x3 → cong-ℕ k x3 x4 → cong-ℕ k x1 x4
+ x1 ≡ x2 mod-ℕ k → x2 = x3 → x3 ≡ x4 mod-ℕ k → x1 ≡ x4 mod-ℕ k
concatenate-cong-eq-cong-ℕ {k} {x} {y} {.y} {z} H refl K =
transitive-cong-ℕ k x y z K H
concatenate-eq-cong-eq-cong-eq-ℕ :
(k : ℕ) {x1 x2 x3 x4 x5 x6 : ℕ} →
- x1 = x2 → cong-ℕ k x2 x3 → x3 = x4 →
- cong-ℕ k x4 x5 → x5 = x6 → cong-ℕ k x1 x6
+ x1 = x2 → x2 ≡ x3 mod-ℕ k → x3 = x4 →
+ x4 ≡ x5 mod-ℕ k → x5 = x6 → x1 ≡ x6 mod-ℕ k
concatenate-eq-cong-eq-cong-eq-ℕ k
{x} {.x} {y} {.y} {z} {.z} refl H refl K refl =
transitive-cong-ℕ k x y z K H
```
+### If the distance between two natural numbers is strictly less than `k`, then they are congruent modulo `k` if and only if they are equal
+
```agda
eq-cong-le-dist-ℕ :
- (k x y : ℕ) → le-ℕ (dist-ℕ x y) k → cong-ℕ k x y → x = y
+ (k x y : ℕ) → le-ℕ (dist-ℕ x y) k → x ≡ y mod-ℕ k → x = y
eq-cong-le-dist-ℕ k x y H K =
eq-dist-ℕ x y (is-zero-div-ℕ k (dist-ℕ x y) H K)
```
+### Any two numbers strictly less than `k` are congruent modulo `k` if and only if they are equal
+
```agda
eq-cong-le-ℕ :
- (k x y : ℕ) → le-ℕ x k → le-ℕ y k → cong-ℕ k x y → x = y
+ (k x y : ℕ) → le-ℕ x k → le-ℕ y k → x ≡ y mod-ℕ k → x = y
eq-cong-le-ℕ k x y H K =
eq-cong-le-dist-ℕ k x y (strict-upper-bound-dist-ℕ k x y H K)
-```
-```agda
eq-cong-nat-Fin :
- (k : ℕ) (x y : Fin k) → cong-ℕ k (nat-Fin k x) (nat-Fin k y) → x = y
+ (k : ℕ) (x y : Fin k) → nat-Fin k x ≡ nat-Fin k y mod-ℕ k → x = y
eq-cong-nat-Fin (succ-ℕ k) x y H =
is-injective-nat-Fin (succ-ℕ k)
( eq-cong-le-ℕ (succ-ℕ k) (nat-Fin (succ-ℕ k) x) (nat-Fin (succ-ℕ k) y)
@@ -137,36 +173,75 @@ eq-cong-nat-Fin (succ-ℕ k) x y H =
( H))
```
+### Any natural number is congruent to `0` modulo itself
+
+```agda
+cong-zero-ℕ :
+ (k : ℕ) → k ≡ 0 mod-ℕ k
+pr1 (cong-zero-ℕ k) = 1
+pr2 (cong-zero-ℕ k) =
+ (left-unit-law-mul-ℕ k) ∙ (inv (right-unit-law-dist-ℕ k))
+
+cong-zero-ℕ' : (k : ℕ) → 0 ≡ k mod-ℕ k
+cong-zero-ℕ' k =
+ symmetric-cong-ℕ k k zero-ℕ (cong-zero-ℕ k)
+```
+
+### The inclusion of `0` from `Fin (k + 1)` into `ℕ` is congruent to `0` modulo `k + 1`
+
```agda
cong-is-zero-nat-zero-Fin :
- {k : ℕ} → cong-ℕ (succ-ℕ k) (nat-Fin (succ-ℕ k) (zero-Fin k)) zero-ℕ
+ {k : ℕ} → nat-Fin (succ-ℕ k) (zero-Fin k) ≡ 0 mod-ℕ succ-ℕ k
cong-is-zero-nat-zero-Fin {k} =
cong-identification-ℕ (succ-ℕ k) (is-zero-nat-zero-Fin {k})
```
+### Any two natural numbers that are congruent modulo `0` are equal
+
+In other words, the congruence relation modulo `0` is discrete.
+
```agda
-eq-cong-zero-ℕ : (x y : ℕ) → cong-ℕ zero-ℕ x y → x = y
-eq-cong-zero-ℕ x y H =
- eq-dist-ℕ x y (is-zero-div-zero-ℕ (dist-ℕ x y) H)
+is-discrete-cong-zero-ℕ :
+ (x y : ℕ) → x ≡ y mod-ℕ 0 → x = y
+is-discrete-cong-zero-ℕ x y (k , p) =
+ eq-dist-ℕ x y (inv p ∙ right-zero-law-mul-ℕ k)
+```
+
+### If `x` and `x + 1` are congruent modulo `k`, then `k = 1`
-is-one-cong-succ-ℕ : {k : ℕ} (x : ℕ) → cong-ℕ k x (succ-ℕ x) → is-one-ℕ k
+```agda
+is-one-cong-succ-ℕ : {k : ℕ} (x : ℕ) → x ≡ succ-ℕ x mod-ℕ k → is-one-ℕ k
is-one-cong-succ-ℕ {k} x H =
is-one-div-one-ℕ k (tr (div-ℕ k) (is-one-dist-succ-ℕ x) H)
```
+### A number is divisible by `k` if and only if it is congruent to `0` modulo `k`
+
+```agda
+div-cong-zero-ℕ :
+ (k x : ℕ) → x ≡ 0 mod-ℕ k → div-ℕ k x
+div-cong-zero-ℕ k x =
+ tr (div-ℕ k) (right-unit-law-dist-ℕ x)
+
+cong-zero-div-ℕ :
+ (k x : ℕ) → div-ℕ k x → x ≡ 0 mod-ℕ k
+cong-zero-div-ℕ k x =
+ tr (div-ℕ k) (inv (right-unit-law-dist-ℕ x))
+```
+
### Congruence is invariant under scalar multiplication
```agda
scalar-invariant-cong-ℕ :
- (k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (z *ℕ x) (z *ℕ y)
-pr1 (scalar-invariant-cong-ℕ k x y z (pair d p)) = z *ℕ d
-pr2 (scalar-invariant-cong-ℕ k x y z (pair d p)) =
+ (k x y z : ℕ) → x ≡ y mod-ℕ k → z *ℕ x ≡ z *ℕ y mod-ℕ k
+pr1 (scalar-invariant-cong-ℕ k x y z (d , p)) = z *ℕ d
+pr2 (scalar-invariant-cong-ℕ k x y z (d , p)) =
( associative-mul-ℕ z d k) ∙
( ( ap (z *ℕ_) p) ∙
( left-distributive-mul-dist-ℕ x y z))
scalar-invariant-cong-ℕ' :
- (k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (x *ℕ z) (y *ℕ z)
+ (k x y z : ℕ) → x ≡ y mod-ℕ k → x *ℕ z ≡ y *ℕ z mod-ℕ k
scalar-invariant-cong-ℕ' k x y z H =
concatenate-eq-cong-eq-ℕ k
( commutative-mul-ℕ x z)
@@ -179,7 +254,7 @@ scalar-invariant-cong-ℕ' k x y z H =
```agda
congruence-mul-ℕ :
(k : ℕ) {x y x' y' : ℕ} →
- cong-ℕ k x x' → cong-ℕ k y y' → cong-ℕ k (x *ℕ y) (x' *ℕ y')
+ x ≡ x' mod-ℕ k → y ≡ y' mod-ℕ k → x *ℕ y ≡ x' *ℕ y' mod-ℕ k
congruence-mul-ℕ k {x} {y} {x'} {y'} H K =
transitive-cong-ℕ k (x *ℕ y) (x *ℕ y') (x' *ℕ y')
( scalar-invariant-cong-ℕ' k x x' y' H)
@@ -190,13 +265,13 @@ congruence-mul-ℕ k {x} {y} {x'} {y'} H K =
```agda
translation-invariant-cong-ℕ :
- (k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (z +ℕ x) (z +ℕ y)
-pr1 (translation-invariant-cong-ℕ k x y z (pair d p)) = d
-pr2 (translation-invariant-cong-ℕ k x y z (pair d p)) =
+ (k x y z : ℕ) → x ≡ y mod-ℕ k → z +ℕ x ≡ z +ℕ y mod-ℕ k
+pr1 (translation-invariant-cong-ℕ k x y z (d , p)) = d
+pr2 (translation-invariant-cong-ℕ k x y z (d , p)) =
p ∙ inv (translation-invariant-dist-ℕ z x y)
translation-invariant-cong-ℕ' :
- (k x y z : ℕ) → cong-ℕ k x y → cong-ℕ k (x +ℕ z) (y +ℕ z)
+ (k x y z : ℕ) → x ≡ y mod-ℕ k → x +ℕ z ≡ y +ℕ z mod-ℕ k
translation-invariant-cong-ℕ' k x y z H =
concatenate-eq-cong-eq-ℕ k
( commutative-add-ℕ x z)
@@ -204,13 +279,13 @@ translation-invariant-cong-ℕ' k x y z H =
( commutative-add-ℕ z y)
step-invariant-cong-ℕ :
- (k x y : ℕ) → cong-ℕ k x y → cong-ℕ k (succ-ℕ x) (succ-ℕ y)
+ (k x y : ℕ) → x ≡ y mod-ℕ k → succ-ℕ x ≡ succ-ℕ y mod-ℕ k
step-invariant-cong-ℕ k x y = translation-invariant-cong-ℕ' k x y 1
reflects-cong-add-ℕ :
- {k : ℕ} (x : ℕ) {y z : ℕ} → cong-ℕ k (x +ℕ y) (x +ℕ z) → cong-ℕ k y z
-pr1 (reflects-cong-add-ℕ {k} x {y} {z} (pair d p)) = d
-pr2 (reflects-cong-add-ℕ {k} x {y} {z} (pair d p)) =
+ {k : ℕ} (x : ℕ) {y z : ℕ} → x +ℕ y ≡ x +ℕ z mod-ℕ k → y ≡ z mod-ℕ k
+pr1 (reflects-cong-add-ℕ {k} x {y} {z} (d , p)) = d
+pr2 (reflects-cong-add-ℕ {k} x {y} {z} (d , p)) =
p ∙ translation-invariant-dist-ℕ x y z
reflects-cong-left-add-ℕ :
@@ -220,7 +295,7 @@ pr2 (reflects-cong-left-add-ℕ {k} x {y} {z} (d , p)) =
p ∙ translation-invariant-dist-ℕ' z x y
reflects-cong-add-ℕ' :
- {k : ℕ} (x : ℕ) {y z : ℕ} → cong-ℕ k (add-ℕ' x y) (add-ℕ' x z) → cong-ℕ k y z
+ {k : ℕ} (x : ℕ) {y z : ℕ} → y +ℕ x ≡ z +ℕ x mod-ℕ k → y ≡ z mod-ℕ k
reflects-cong-add-ℕ' {k} x {y} {z} H =
reflects-cong-add-ℕ x {y} {z}
( concatenate-eq-cong-eq-ℕ k
@@ -228,3 +303,43 @@ reflects-cong-add-ℕ' {k} x {y} {z} H =
( H)
( commutative-add-ℕ z x))
```
+
+### The congruence relations respect addition
+
+```agda
+congruence-add-ℕ :
+ (k : ℕ) {x y x' y' : ℕ} →
+ x ≡ x' mod-ℕ k → y ≡ y' mod-ℕ k → x +ℕ y ≡ x' +ℕ y' mod-ℕ k
+congruence-add-ℕ k {x} {y} {x'} {y'} H K =
+ transitive-cong-ℕ k (x +ℕ y) (x +ℕ y') (x' +ℕ y')
+ ( translation-invariant-cong-ℕ' k x x' y' H)
+ ( translation-invariant-cong-ℕ k y y' x K)
+
+congruence-right-summand-ℕ :
+ (k : ℕ) {x y x' y' : ℕ} →
+ cong-ℕ k x x' → cong-ℕ k (x +ℕ y) (x' +ℕ y') → cong-ℕ k y y'
+congruence-right-summand-ℕ k {x} {y} {x'} {y'} H K =
+ reflects-cong-add-ℕ x {y}
+ ( transitive-cong-ℕ k
+ ( x +ℕ y)
+ ( x' +ℕ y')
+ ( x +ℕ y')
+ ( translation-invariant-cong-ℕ' k x' x y'
+ ( symmetric-cong-ℕ k x x' H))
+ ( K))
+
+congruence-left-summand-ℕ :
+ (k : ℕ) {x y x' y' : ℕ} →
+ cong-ℕ k y y' → cong-ℕ k (x +ℕ y) (x' +ℕ y') → cong-ℕ k x x'
+congruence-left-summand-ℕ k {x} {y} {x'} {y'} H K =
+ congruence-right-summand-ℕ k {y} {x} {y'} {x'} H
+ ( concatenate-eq-cong-ℕ k
+ ( commutative-add-ℕ y x)
+ ( concatenate-cong-eq-ℕ k {x1 = x +ℕ y}
+ ( K)
+ ( commutative-add-ℕ x' y')))
+```
+
+## See also
+
+- [Congruence relations on the integers](elementary-number-theory.congruence-integers.md)
diff --git a/src/elementary-number-theory/decidable-maps-natural-numbers.lagda.md b/src/elementary-number-theory/decidable-maps-natural-numbers.lagda.md
new file mode 100644
index 0000000000..c7a0cd8d47
--- /dev/null
+++ b/src/elementary-number-theory/decidable-maps-natural-numbers.lagda.md
@@ -0,0 +1,22 @@
+# Decidable maps into the natural numbers
+
+```agda
+module elementary-number-theory.decidable-maps-natural-numbers where
+```
+
+Imports
+
+```agda
+
+```
+
+
+
+## Idea
+
+Consider a map $f : A \to \mathbb{N}$ into the
+[natural numbers](elementary-number-theory.natural-numbers.md). Then $f$ is said
+to be a {{#concept "decidable map" Disambiguation="natural numbers"}} if its
+[fibers](foundation-core.fibers-of-maps.md) are
+[decidable](foundation.decidable-types.md), i.e., if it is a
+[decidable map](foundation.decidable-maps.md).
diff --git a/src/elementary-number-theory/decidable-subtypes-natural-numbers.lagda.md b/src/elementary-number-theory/decidable-subtypes-natural-numbers.lagda.md
new file mode 100644
index 0000000000..d092cf2e5f
--- /dev/null
+++ b/src/elementary-number-theory/decidable-subtypes-natural-numbers.lagda.md
@@ -0,0 +1,166 @@
+# Decidable subtypes of the natural numbers
+
+```agda
+module elementary-number-theory.decidable-subtypes-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.bounded-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.maximal-structured-natural-numbers
+open import elementary-number-theory.maximum-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.well-ordering-principle-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.decidable-subtypes
+open import foundation.dependent-pair-types
+open import foundation.empty-types
+open import foundation.equivalences
+open import foundation.function-types
+open import foundation.inhabited-subtypes
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.transport-along-identifications
+open import foundation.type-arithmetic-dependent-pair-types
+open import foundation.universe-levels
+
+open import univalent-combinatorics.counting
+open import univalent-combinatorics.dependent-pair-types
+open import univalent-combinatorics.finite-types
+open import univalent-combinatorics.standard-finite-types
+open import univalent-combinatorics.decidable-subtypes
+```
+
+
+
+## Idea
+
+In this file we study [decidable subtypes](foundation.decidable-subtypes.md) of
+the [natural numbers](elementary-number-theory.natural-numbers.md). The type of
+all decidable subtypes of the natural numbers is the _decidable powerset of the
+natural numbers_.
+
+As a direct consequence of the
+[well-ordering principle](elementary-number-theory.well-ordering-principle-natural-numbers.md)
+of the natural numbers, which is formulated for decidable structures over the
+natural numbers, it follows that every
+[inhabited](foundation.inhabited-subtypes.md) decidable subtype of the natural
+numbers has a least element. We also show that every finite decidable subtype
+has a largest element.
+
+## Properties
+
+### Inhabited decidable subtypes of the natural numbers have a minimal element
+
+```agda
+module _
+ {l : Level} (P : decidable-subtype l ℕ)
+ where
+
+ well-ordering-principle-decidable-subtype-ℕ :
+ is-inhabited-subtype (subtype-decidable-subtype P) →
+ minimal-element-ℕ (is-in-decidable-subtype P)
+ well-ordering-principle-decidable-subtype-ℕ H =
+ apply-universal-property-trunc-Prop H
+ ( minimal-element-ℕ-Prop (subtype-decidable-subtype P))
+ ( λ (n , p) →
+ well-ordering-principle-ℕ
+ ( is-in-decidable-subtype P)
+ ( is-decidable-decidable-subtype P)
+ ( p))
+```
+
+### Inhatbited finite decidable subtypes of the natural numbers have a maximal element
+
+```agda
+module _
+ {l : Level} (P : decidable-subtype l ℕ)
+ where
+
+ nat-maximal-element-count-type-decidable-subtype-ℕ :
+ count (type-decidable-subtype P) → ℕ
+ nat-maximal-element-count-type-decidable-subtype-ℕ (n , e) =
+ max-standard-finite-family-ℕ n
+ ( inclusion-decidable-subtype P ∘ map-equiv e)
+
+ is-in-subtype-maximal-element-count-type-decidable-subtype-ℕ :
+ (e : count (type-decidable-subtype P)) →
+ type-decidable-subtype P →
+ is-in-decidable-subtype P
+ ( nat-maximal-element-count-type-decidable-subtype-ℕ e)
+ is-in-subtype-maximal-element-count-type-decidable-subtype-ℕ (zero-ℕ , e) x =
+ ex-falso (map-inv-equiv e x)
+ is-in-subtype-maximal-element-count-type-decidable-subtype-ℕ
+ ( succ-ℕ n , e) x =
+ tr
+ ( is-in-decidable-subtype P)
+ ( pr2
+ ( is-attained-max-standard-finite-family-succ-ℕ n
+ ( inclusion-decidable-subtype P ∘ map-equiv e)))
+ ( pr2
+ ( map-equiv e
+ ( pr1
+ ( is-attained-max-standard-finite-family-succ-ℕ n
+ ( inclusion-decidable-subtype P ∘ map-equiv e)))))
+
+ is-upper-bound-maximal-element-count-type-decidable-subtype-ℕ :
+ (e : count (type-decidable-subtype P)) →
+ (i : ℕ) → is-in-decidable-subtype P i →
+ i ≤-ℕ nat-maximal-element-count-type-decidable-subtype-ℕ e
+ is-upper-bound-maximal-element-count-type-decidable-subtype-ℕ
+ (zero-ℕ , e) i p =
+ ex-falso (map-inv-equiv e (i , p))
+ is-upper-bound-maximal-element-count-type-decidable-subtype-ℕ
+ (succ-ℕ n , e) i p =
+ tr
+ ( λ x → x ≤-ℕ _)
+ ( ap pr1 (is-section-map-inv-equiv e (i , p)))
+ ( is-upper-bound-max-standard-finite-family-ℕ
+ ( succ-ℕ n)
+ ( inclusion-decidable-subtype P ∘ map-equiv e)
+ ( map-inv-equiv e (i , p)))
+
+ maximal-element-count-type-decidable-subtype-ℕ :
+ count (type-decidable-subtype P) →
+ type-decidable-subtype P →
+ maximal-element-ℕ (is-in-decidable-subtype P)
+ pr1 (maximal-element-count-type-decidable-subtype-ℕ e K) =
+ nat-maximal-element-count-type-decidable-subtype-ℕ e
+ pr1 (pr2 (maximal-element-count-type-decidable-subtype-ℕ e K)) =
+ is-in-subtype-maximal-element-count-type-decidable-subtype-ℕ e K
+ pr2 (pr2 (maximal-element-count-type-decidable-subtype-ℕ e K)) i p =
+ is-upper-bound-maximal-element-count-type-decidable-subtype-ℕ e i p
+
+ maximal-element-is-finite-decidable-subtype-ℕ :
+ is-finite (type-decidable-subtype P) →
+ is-inhabited-subtype (subtype-decidable-subtype P) →
+ maximal-element-ℕ (is-in-decidable-subtype P)
+ maximal-element-is-finite-decidable-subtype-ℕ H K =
+ apply-twice-universal-property-trunc-Prop H K
+ ( maximal-element-ℕ-Prop (subtype-decidable-subtype P))
+ ( maximal-element-count-type-decidable-subtype-ℕ)
+```
+
+### Decidable subtypes with a maximal element are finite
+
+```agda
+module _
+ {l : Level} (P : decidable-subtype l ℕ)
+ where
+
+ is-finite-maximal-element-decidable-subtype-ℕ :
+ maximal-element-ℕ (is-in-decidable-subtype P) →
+ is-finite (type-decidable-subtype P)
+ is-finite-maximal-element-decidable-subtype-ℕ (m , H , K) =
+ is-finite-equiv
+ ( ( right-unit-law-Σ-is-contr
+ ( λ (x , p) → is-proof-irrelevant-leq-ℕ x m (K x p))) ∘e
+ ( equiv-right-swap-Σ))
+ ( is-finite-type-decidable-subtype
+ ( P ∘ pr1)
+ ( is-finite-bounded-ℕ m))
+```
diff --git a/src/elementary-number-theory/decidable-total-order-integers.lagda.md b/src/elementary-number-theory/decidable-total-order-integers.lagda.md
index f4e2772ec7..49dab8a4a9 100644
--- a/src/elementary-number-theory/decidable-total-order-integers.lagda.md
+++ b/src/elementary-number-theory/decidable-total-order-integers.lagda.md
@@ -8,13 +8,20 @@ module elementary-number-theory.decidable-total-order-integers where
```agda
open import elementary-number-theory.inequality-integers
+open import elementary-number-theory.integers
open import foundation.dependent-pair-types
open import foundation.propositional-truncations
open import foundation.universe-levels
+open import order-theory.decidable-posets
+open import order-theory.decidable-preorders
open import order-theory.decidable-total-orders
+open import order-theory.decidable-total-preorders
+open import order-theory.posets
+open import order-theory.preorders
open import order-theory.total-orders
+open import order-theory.total-preorders
```
@@ -26,18 +33,47 @@ The type of [integers](elementary-number-theory.integers.md)
[standard ordering relation](elementary-number-theory.inequality-integers.md)
forms a [decidable total order](order-theory.decidable-total-orders.md).
-## Definition
+## Definitions
+
+### The totally ordered set of integers ordered by inequality
```agda
+ℤ-Preorder : Preorder lzero lzero
+pr1 ℤ-Preorder = ℤ
+pr1 (pr2 ℤ-Preorder) = leq-ℤ-Prop
+pr1 (pr2 (pr2 ℤ-Preorder)) = refl-leq-ℤ
+pr2 (pr2 (pr2 ℤ-Preorder)) = transitive-leq-ℤ
+
+ℤ-Decidable-Preorder : Decidable-Preorder lzero lzero
+pr1 ℤ-Decidable-Preorder = ℤ-Preorder
+pr2 ℤ-Decidable-Preorder = is-decidable-leq-ℤ
+
+ℤ-Poset : Poset lzero lzero
+pr1 ℤ-Poset = ℤ-Preorder
+pr2 ℤ-Poset a b = antisymmetric-leq-ℤ
+
+ℤ-Decidable-Poset : Decidable-Poset lzero lzero
+pr1 ℤ-Decidable-Poset = ℤ-Poset
+pr2 ℤ-Decidable-Poset = is-decidable-leq-ℤ
+
is-total-leq-ℤ : is-total-Poset ℤ-Poset
is-total-leq-ℤ x y = unit-trunc-Prop (linear-leq-ℤ x y)
+ℤ-Total-Preorder : Total-Preorder lzero lzero
+pr1 ℤ-Total-Preorder = ℤ-Preorder
+pr2 ℤ-Total-Preorder a b = unit-trunc-Prop (linear-leq-ℤ a b)
+
+ℤ-Decidable-Total-Preorder : Decidable-Total-Preorder lzero lzero
+pr1 ℤ-Decidable-Total-Preorder = ℤ-Preorder
+pr1 (pr2 ℤ-Decidable-Total-Preorder) a b = unit-trunc-Prop (linear-leq-ℤ a b)
+pr2 (pr2 ℤ-Decidable-Total-Preorder) = is-decidable-leq-ℤ
+
ℤ-Total-Order : Total-Order lzero lzero
pr1 ℤ-Total-Order = ℤ-Poset
-pr2 ℤ-Total-Order = is-total-leq-ℤ
+pr2 ℤ-Total-Order a b = unit-trunc-Prop (linear-leq-ℤ a b)
ℤ-Decidable-Total-Order : Decidable-Total-Order lzero lzero
pr1 ℤ-Decidable-Total-Order = ℤ-Poset
-pr1 (pr2 ℤ-Decidable-Total-Order) = is-total-leq-ℤ
+pr1 (pr2 ℤ-Decidable-Total-Order) a b = unit-trunc-Prop (linear-leq-ℤ a b)
pr2 (pr2 ℤ-Decidable-Total-Order) = is-decidable-leq-ℤ
```
diff --git a/src/elementary-number-theory/decidable-types.lagda.md b/src/elementary-number-theory/decidable-types.lagda.md
index 047ada9a91..c9f26e8218 100644
--- a/src/elementary-number-theory/decidable-types.lagda.md
+++ b/src/elementary-number-theory/decidable-types.lagda.md
@@ -35,33 +35,36 @@ decidable.
```agda
is-decidable-Σ-ℕ :
- {l : Level} (m : ℕ) (P : ℕ → UU l) (d : is-decidable-fam P) →
- is-decidable (Σ ℕ (λ x → (leq-ℕ m x) × (P x))) → is-decidable (Σ ℕ P)
-is-decidable-Σ-ℕ m P d (inl (pair x (pair l p))) = inl (pair x p)
+ {l : Level} (m : ℕ) (P : ℕ → UU l) → is-decidable-fam P →
+ is-decidable (Σ ℕ (λ x → m ≤-ℕ x × P x)) → is-decidable (Σ ℕ P)
+is-decidable-Σ-ℕ m P d (inl (x , l , p)) =
+ inl (x , p)
is-decidable-Σ-ℕ zero-ℕ P d (inr f) =
- inr (λ p → f (pair (pr1 p) (pair star (pr2 p))))
-is-decidable-Σ-ℕ (succ-ℕ m) P d (inr f) with d zero-ℕ
-... | inl p = inl (pair zero-ℕ p)
+ inr (λ p → f (pr1 p , star , pr2 p))
+is-decidable-Σ-ℕ (succ-ℕ m) P d (inr f)
+ with
+ d 0
+... | inl p = inl (0 , p)
... | inr g with
is-decidable-Σ-ℕ m
( P ∘ succ-ℕ)
( λ x → d (succ-ℕ x))
- ( inr (λ p → f (pair (succ-ℕ (pr1 p)) (pr2 p))))
-... | inl p = inl (pair (succ-ℕ (pr1 p)) (pr2 p))
+ ( inr (λ p → f (succ-ℕ (pr1 p) , pr2 p)))
+... | inl p = inl (succ-ℕ (pr1 p) , pr2 p)
... | inr h = inr α
where
α : Σ ℕ P → empty
- α (pair zero-ℕ p) = g p
- α (pair (succ-ℕ x) p) = h (pair x p)
+ α (zero-ℕ , p) = g p
+ α (succ-ℕ x , p) = h (x , p)
```
### Bounded sums of decidable families over ℕ are decidable
```agda
is-decidable-bounded-Σ-ℕ :
- {l1 l2 : Level} (m : ℕ) (P : ℕ → UU l1) (Q : ℕ → UU l2)
- (dP : is-decidable-fam P) (dQ : is-decidable-fam Q)
- (H : is-upper-bound-ℕ P m) → is-decidable (Σ ℕ (λ x → (P x) × (Q x)))
+ {l1 l2 : Level} (m : ℕ) (P : ℕ → UU l1) (Q : ℕ → UU l2) →
+ is-decidable-fam P → is-decidable-fam Q →
+ is-upper-bound-ℕ P m → is-decidable (Σ ℕ (λ x → (P x) × (Q x)))
is-decidable-bounded-Σ-ℕ m P Q dP dQ H =
is-decidable-Σ-ℕ
( succ-ℕ m)
@@ -76,11 +79,11 @@ is-decidable-bounded-Σ-ℕ m P Q dP dQ H =
( pr1 (pr2 p))))
is-decidable-bounded-Σ-ℕ' :
- {l : Level} (m : ℕ) (P : ℕ → UU l) (d : is-decidable-fam P) →
- is-decidable (Σ ℕ (λ x → (leq-ℕ x m) × (P x)))
+ {l : Level} (m : ℕ) (P : ℕ → UU l) →
+ is-decidable-fam P → is-decidable (Σ ℕ (λ x → x ≤-ℕ m × P x))
is-decidable-bounded-Σ-ℕ' m P d =
is-decidable-bounded-Σ-ℕ m
- ( λ x → leq-ℕ x m)
+ ( λ x → x ≤-ℕ m)
( P)
( λ x → is-decidable-leq-ℕ x m)
( d)
@@ -91,20 +94,19 @@ is-decidable-bounded-Σ-ℕ' m P d =
```agda
is-decidable-strictly-bounded-Σ-ℕ :
- {l1 l2 : Level} (m : ℕ) (P : ℕ → UU l1) (Q : ℕ → UU l2)
- (dP : is-decidable-fam P) (dQ : is-decidable-fam Q)
- (H : is-strict-upper-bound-ℕ P m) →
+ {l1 l2 : Level} (m : ℕ) (P : ℕ → UU l1) (Q : ℕ → UU l2) →
+ is-decidable-fam P → is-decidable-fam Q → is-strict-upper-bound-ℕ P m →
is-decidable (Σ ℕ (λ x → (P x) × (Q x)))
is-decidable-strictly-bounded-Σ-ℕ m P Q dP dQ H =
is-decidable-bounded-Σ-ℕ m P Q dP dQ
( is-upper-bound-is-strict-upper-bound-ℕ P m H)
is-decidable-strictly-bounded-Σ-ℕ' :
- {l : Level} (m : ℕ) (P : ℕ → UU l) (d : is-decidable-fam P) →
- is-decidable (Σ ℕ (λ x → (le-ℕ x m) × (P x)))
+ {l : Level} (m : ℕ) (P : ℕ → UU l) →
+ is-decidable-fam P → is-decidable (Σ ℕ (λ x → x <-ℕ m × P x))
is-decidable-strictly-bounded-Σ-ℕ' m P d =
is-decidable-strictly-bounded-Σ-ℕ m
- ( λ x → le-ℕ x m)
+ ( λ x → x <-ℕ m)
( P)
( λ x → is-decidable-le-ℕ x m)
( d)
@@ -115,8 +117,9 @@ is-decidable-strictly-bounded-Σ-ℕ' m P d =
```agda
is-decidable-Π-ℕ :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) (m : ℕ) →
- is-decidable ((x : ℕ) → (leq-ℕ m x) → P x) → is-decidable ((x : ℕ) → P x)
+ {l : Level} (P : ℕ → UU l) →
+ is-decidable-fam P → (m : ℕ) → is-decidable ((x : ℕ) → m ≤-ℕ x → P x) →
+ is-decidable ((x : ℕ) → P x)
is-decidable-Π-ℕ P d zero-ℕ (inr nH) = inr (λ f → nH (λ x y → f x))
is-decidable-Π-ℕ P d zero-ℕ (inl H) = inl (λ x → H x (leq-zero-ℕ x))
is-decidable-Π-ℕ P d (succ-ℕ m) (inr nH) = inr (λ f → nH (λ x y → f x))
@@ -136,8 +139,9 @@ is-decidable-Π-ℕ P d (succ-ℕ m) (inl H) with d zero-ℕ
```agda
is-decidable-bounded-Π-ℕ :
- {l1 l2 : Level} (P : ℕ → UU l1) (Q : ℕ → UU l2) (dP : is-decidable-fam P) →
- (dQ : is-decidable-fam Q) (m : ℕ) (H : is-upper-bound-ℕ P m) →
+ {l1 l2 : Level} (P : ℕ → UU l1) (Q : ℕ → UU l2) →
+ is-decidable-fam P → is-decidable-fam Q →
+ (m : ℕ) → is-upper-bound-ℕ P m →
is-decidable ((x : ℕ) → P x → Q x)
is-decidable-bounded-Π-ℕ P Q dP dQ m H =
is-decidable-Π-ℕ
@@ -147,11 +151,11 @@ is-decidable-bounded-Π-ℕ P Q dP dQ m H =
( inl (λ x l p → ex-falso (contradiction-leq-ℕ x m (H x p) l)))
is-decidable-bounded-Π-ℕ' :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) (m : ℕ) →
- is-decidable ((x : ℕ) → (leq-ℕ x m) → P x)
+ {l : Level} (P : ℕ → UU l) →
+ is-decidable-fam P → (m : ℕ) → is-decidable ((x : ℕ) → x ≤-ℕ m → P x)
is-decidable-bounded-Π-ℕ' P d m =
is-decidable-bounded-Π-ℕ
- ( λ x → leq-ℕ x m)
+ ( λ x → x ≤-ℕ m)
( P)
( λ x → is-decidable-leq-ℕ x m)
( d)
@@ -163,18 +167,19 @@ is-decidable-bounded-Π-ℕ' P d m =
```agda
is-decidable-strictly-bounded-Π-ℕ :
- {l1 l2 : Level} (P : ℕ → UU l1) (Q : ℕ → UU l2) (dP : is-decidable-fam P) →
- (dQ : is-decidable-fam Q) (m : ℕ) (H : is-strict-upper-bound-ℕ P m) →
+ {l1 l2 : Level} (P : ℕ → UU l1) (Q : ℕ → UU l2) →
+ is-decidable-fam P → is-decidable-fam Q →
+ (m : ℕ) → is-strict-upper-bound-ℕ P m →
is-decidable ((x : ℕ) → P x → Q x)
is-decidable-strictly-bounded-Π-ℕ P Q dP dQ m H =
is-decidable-bounded-Π-ℕ P Q dP dQ m (λ x p → leq-le-ℕ x m (H x p))
is-decidable-strictly-bounded-Π-ℕ' :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) (m : ℕ) →
- is-decidable ((x : ℕ) → le-ℕ x m → P x)
+ {l : Level} (P : ℕ → UU l) → is-decidable-fam P →
+ (m : ℕ) → is-decidable ((x : ℕ) → x <-ℕ m → P x)
is-decidable-strictly-bounded-Π-ℕ' P d m =
is-decidable-strictly-bounded-Π-ℕ
- ( λ x → le-ℕ x m)
+ ( λ x → x <-ℕ m)
( P)
( λ x → is-decidable-le-ℕ x m)
( d)
diff --git a/src/elementary-number-theory/difference-integers.lagda.md b/src/elementary-number-theory/difference-integers.lagda.md
index 6cd796526c..78b8eee55e 100644
--- a/src/elementary-number-theory/difference-integers.lagda.md
+++ b/src/elementary-number-theory/difference-integers.lagda.md
@@ -27,9 +27,11 @@ are derived there.
## Definition
+### The difference of two integers
+
```agda
diff-ℤ : ℤ → ℤ → ℤ
-diff-ℤ x y = x +ℤ (neg-ℤ y)
+diff-ℤ x y = x +ℤ neg-ℤ y
infixl 36 _-ℤ_
_-ℤ_ = diff-ℤ
@@ -38,6 +40,13 @@ ap-diff-ℤ : {x x' y y' : ℤ} → x = x' → y = y' → x -ℤ y = x' -
ap-diff-ℤ p q = ap-binary diff-ℤ p q
```
+### The difference of two integers with the negative integer on the left
+
+```agda
+left-diff-ℤ : ℤ → ℤ → ℤ
+left-diff-ℤ x y = neg-ℤ x +ℤ y
+```
+
## Properties
### Two integers with a difference equal to zero are equal
diff --git a/src/elementary-number-theory/dirichlet-convolution.lagda.md b/src/elementary-number-theory/dirichlet-convolution.lagda.md
index 0745ebdfe9..6216a71cdb 100644
--- a/src/elementary-number-theory/dirichlet-convolution.lagda.md
+++ b/src/elementary-number-theory/dirichlet-convolution.lagda.md
@@ -9,7 +9,7 @@ module elementary-number-theory.dirichlet-convolution where
```agda
open import elementary-number-theory.arithmetic-functions
open import elementary-number-theory.bounded-sums-arithmetic-functions
-open import elementary-number-theory.modular-arithmetic-standard-finite-types
+open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.nonzero-natural-numbers
diff --git a/src/elementary-number-theory/distance-natural-numbers.lagda.md b/src/elementary-number-theory/distance-natural-numbers.lagda.md
index 6026c735da..d3e76bc765 100644
--- a/src/elementary-number-theory/distance-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/distance-natural-numbers.lagda.md
@@ -29,10 +29,19 @@ open import foundation.universe-levels
## Idea
The
-{{#concept "distance function" Disambiguation="between natural numbers" Agda=dist-ℕ}}
+{{#concept "distance function" Disambiguation="natural numbers" Agda=dist-ℕ}}
between [natural numbers](elementary-number-theory.natural-numbers.md) measures
-how far two natural numbers are apart. In the agda-unimath library we often
-prefer to work with `dist-ℕ` over the partially defined subtraction operation.
+how far two natural numbers are apart. If the
+[inequality](elementary-number-theory.inequality-natural-numbers.md) $x \leq y$
+holds, then the distance between $x$ and $y$ is the unique natural number $d$
+equipped with an [identification](foundation-core.identity-types.md)
+$x + d = y$.
+
+**Note.** In the agda-unimath library, we often prefer to work with `dist-ℕ`
+over the subtraction operation, which is either partially defined or it returns
+nonsensical values. Not only is the distance function sensibly defined for any
+pair of natural numbers, but it also satisfies the more pleasant and predictable
+properties of a [metric](metric-spaces.metric-spaces.md).
## Definition
@@ -104,39 +113,39 @@ right-unit-law-dist-ℕ (succ-ℕ n) = refl
```agda
triangle-inequality-dist-ℕ :
- (m n k : ℕ) → (dist-ℕ m n) ≤-ℕ ((dist-ℕ m k) +ℕ (dist-ℕ k n))
+ (m n k : ℕ) → dist-ℕ m n ≤-ℕ dist-ℕ m k +ℕ dist-ℕ k n
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = star
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = star
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ =
tr
- ( leq-ℕ (succ-ℕ n))
+ ( succ-ℕ n ≤-ℕ_)
( inv (left-unit-law-add-ℕ (succ-ℕ n)))
( refl-leq-ℕ (succ-ℕ n))
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (left-unit-law-dist-ℕ n)))
( triangle-inequality-dist-ℕ zero-ℕ n k)
- ( ( ap (succ-ℕ ∘ (_+ℕ (dist-ℕ k n))) (left-unit-law-dist-ℕ k)) ∙
+ ( ( ap (succ-ℕ ∘ (_+ℕ dist-ℕ k n)) (left-unit-law-dist-ℕ k)) ∙
( inv (left-successor-law-add-ℕ k (dist-ℕ k n))))
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = refl-leq-ℕ (succ-ℕ m)
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (right-unit-law-dist-ℕ m)))
( triangle-inequality-dist-ℕ m zero-ℕ k)
- ( ap (succ-ℕ ∘ ((dist-ℕ m k) +ℕ_)) (right-unit-law-dist-ℕ k))
+ ( ap (succ-ℕ ∘ (dist-ℕ m k +ℕ_)) (right-unit-law-dist-ℕ k))
triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ =
concatenate-leq-eq-ℕ
( dist-ℕ m n)
( transitive-leq-ℕ
( dist-ℕ m n)
- ( succ-ℕ ((dist-ℕ m zero-ℕ) +ℕ (dist-ℕ zero-ℕ n)))
- ( succ-ℕ (succ-ℕ ((dist-ℕ m zero-ℕ) +ℕ (dist-ℕ zero-ℕ n))))
- ( succ-leq-ℕ (succ-ℕ ((dist-ℕ m zero-ℕ) +ℕ (dist-ℕ zero-ℕ n))))
+ ( succ-ℕ (dist-ℕ m zero-ℕ +ℕ dist-ℕ zero-ℕ n))
+ ( succ-ℕ (succ-ℕ (dist-ℕ m zero-ℕ +ℕ dist-ℕ zero-ℕ n)))
+ ( succ-leq-ℕ (succ-ℕ (dist-ℕ m zero-ℕ +ℕ dist-ℕ zero-ℕ n)))
( transitive-leq-ℕ
( dist-ℕ m n)
- ( (dist-ℕ m zero-ℕ) +ℕ (dist-ℕ zero-ℕ n))
- ( succ-ℕ ((dist-ℕ m zero-ℕ) +ℕ (dist-ℕ zero-ℕ n)))
- ( succ-leq-ℕ ((dist-ℕ m zero-ℕ) +ℕ (dist-ℕ zero-ℕ n)))
+ ( dist-ℕ m zero-ℕ +ℕ dist-ℕ zero-ℕ n)
+ ( succ-ℕ (dist-ℕ m zero-ℕ +ℕ dist-ℕ zero-ℕ n))
+ ( succ-leq-ℕ (dist-ℕ m zero-ℕ +ℕ dist-ℕ zero-ℕ n))
( triangle-inequality-dist-ℕ m n zero-ℕ)))
( ( ap
( succ-ℕ ∘ succ-ℕ)
@@ -150,7 +159,7 @@ triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
```agda
is-additive-right-inverse-dist-ℕ :
- (x y : ℕ) → x ≤-ℕ y → x +ℕ (dist-ℕ x y) = y
+ (x y : ℕ) → x ≤-ℕ y → x +ℕ dist-ℕ x y = y
is-additive-right-inverse-dist-ℕ zero-ℕ zero-ℕ H = refl
is-additive-right-inverse-dist-ℕ zero-ℕ (succ-ℕ y) star =
left-unit-law-add-ℕ (succ-ℕ y)
@@ -185,7 +194,7 @@ rewrite-right-dist-add-ℕ x .(dist-ℕ x z) z H refl =
is-additive-right-inverse-dist-ℕ x z H
is-difference-dist-ℕ :
- (x y : ℕ) → x ≤-ℕ y → x +ℕ (dist-ℕ x y) = y
+ (x y : ℕ) → x ≤-ℕ y → x +ℕ dist-ℕ x y = y
is-difference-dist-ℕ zero-ℕ zero-ℕ H = refl
is-difference-dist-ℕ zero-ℕ (succ-ℕ y) H = left-unit-law-add-ℕ (succ-ℕ y)
is-difference-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
@@ -193,7 +202,7 @@ is-difference-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
( ap succ-ℕ (is-difference-dist-ℕ x y H))
is-difference-dist-ℕ' :
- (x y : ℕ) → x ≤-ℕ y → (dist-ℕ x y) +ℕ x = y
+ (x y : ℕ) → x ≤-ℕ y → dist-ℕ x y +ℕ x = y
is-difference-dist-ℕ' x y H =
( commutative-add-ℕ (dist-ℕ x y) x) ∙
( is-difference-dist-ℕ x y H)
@@ -213,8 +222,8 @@ dist-add-ℕ' x y = symmetric-dist-ℕ (x +ℕ y) x ∙ dist-add-ℕ x y
```agda
triangle-equality-dist-ℕ :
- (x y z : ℕ) → (x ≤-ℕ y) → (y ≤-ℕ z) →
- (dist-ℕ x y) +ℕ (dist-ℕ y z) = dist-ℕ x z
+ (x y z : ℕ) → x ≤-ℕ y → y ≤-ℕ z →
+ dist-ℕ x y +ℕ dist-ℕ y z = dist-ℕ x z
triangle-equality-dist-ℕ zero-ℕ zero-ℕ zero-ℕ H1 H2 = refl
triangle-equality-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ z) star star =
ap succ-ℕ (left-unit-law-add-ℕ z)
@@ -227,40 +236,40 @@ triangle-equality-dist-ℕ (succ-ℕ x) (succ-ℕ y) (succ-ℕ z) H1 H2 =
cases-dist-ℕ :
(x y z : ℕ) → UU lzero
cases-dist-ℕ x y z =
- ( (dist-ℕ x y) +ℕ (dist-ℕ y z) = dist-ℕ x z) +
- ( ( (dist-ℕ y z) +ℕ (dist-ℕ x z) = dist-ℕ x y) +
- ( (dist-ℕ x z) +ℕ (dist-ℕ x y) = dist-ℕ y z))
+ ( dist-ℕ x y +ℕ dist-ℕ y z = dist-ℕ x z) +
+ ( ( dist-ℕ y z +ℕ dist-ℕ x z = dist-ℕ x y) +
+ ( dist-ℕ x z +ℕ dist-ℕ x y = dist-ℕ y z))
is-total-dist-ℕ :
(x y z : ℕ) → cases-dist-ℕ x y z
is-total-dist-ℕ x y z with order-three-elements-ℕ x y z
-is-total-dist-ℕ x y z | inl (inl (pair H1 H2)) =
+is-total-dist-ℕ x y z | inl (inl (H1 , H2)) =
inl (triangle-equality-dist-ℕ x y z H1 H2)
-is-total-dist-ℕ x y z | inl (inr (pair H1 H2)) =
+is-total-dist-ℕ x y z | inl (inr (H1 , H2)) =
inr
( inl
( ( commutative-add-ℕ (dist-ℕ y z) (dist-ℕ x z)) ∙
- ( ( ap ((dist-ℕ x z) +ℕ_) (symmetric-dist-ℕ y z)) ∙
+ ( ( ap (dist-ℕ x z +ℕ_) (symmetric-dist-ℕ y z)) ∙
( triangle-equality-dist-ℕ x z y H1 H2))))
-is-total-dist-ℕ x y z | inr (inl (inl (pair H1 H2))) =
+is-total-dist-ℕ x y z | inr (inl (inl (H1 , H2))) =
inr
( inl
- ( ( ap ((dist-ℕ y z) +ℕ_) (symmetric-dist-ℕ x z)) ∙
+ ( ( ap (dist-ℕ y z +ℕ_) (symmetric-dist-ℕ x z)) ∙
( ( triangle-equality-dist-ℕ y z x H1 H2) ∙
( symmetric-dist-ℕ y x))))
-is-total-dist-ℕ x y z | inr (inl (inr (pair H1 H2))) =
+is-total-dist-ℕ x y z | inr (inl (inr (H1 , H2))) =
inr
( inr
- ( ( ap ((dist-ℕ x z) +ℕ_) (symmetric-dist-ℕ x y)) ∙
+ ( ( ap (dist-ℕ x z +ℕ_) (symmetric-dist-ℕ x y)) ∙
( ( commutative-add-ℕ (dist-ℕ x z) (dist-ℕ y x)) ∙
( triangle-equality-dist-ℕ y x z H1 H2))))
-is-total-dist-ℕ x y z | inr (inr (inl (pair H1 H2))) =
+is-total-dist-ℕ x y z | inr (inr (inl (H1 , H2))) =
inr
( inr
- ( ( ap (_+ℕ (dist-ℕ x y)) (symmetric-dist-ℕ x z)) ∙
+ ( ( ap (_+ℕ dist-ℕ x y) (symmetric-dist-ℕ x z)) ∙
( ( triangle-equality-dist-ℕ z x y H1 H2) ∙
( symmetric-dist-ℕ z y))))
-is-total-dist-ℕ x y z | inr (inr (inr (pair H1 H2))) =
+is-total-dist-ℕ x y z | inr (inr (inr (H1 , H2))) =
inl
( ( ap-add-ℕ (symmetric-dist-ℕ x y) (symmetric-dist-ℕ y z)) ∙
( ( commutative-add-ℕ (dist-ℕ y x) (dist-ℕ z y)) ∙
@@ -283,7 +292,7 @@ leq-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
```agda
strict-upper-bound-dist-ℕ :
- (b x y : ℕ) → le-ℕ x b → le-ℕ y b → le-ℕ (dist-ℕ x y) b
+ (b x y : ℕ) → x <-ℕ b → y <-ℕ b → dist-ℕ x y <-ℕ b
strict-upper-bound-dist-ℕ (succ-ℕ b) zero-ℕ y H K = K
strict-upper-bound-dist-ℕ (succ-ℕ b) (succ-ℕ x) zero-ℕ H K = H
strict-upper-bound-dist-ℕ (succ-ℕ b) (succ-ℕ x) (succ-ℕ y) H K =
@@ -294,14 +303,14 @@ strict-upper-bound-dist-ℕ (succ-ℕ b) (succ-ℕ x) (succ-ℕ y) H K =
```agda
right-successor-law-dist-ℕ :
- (x y : ℕ) → leq-ℕ x y → dist-ℕ x (succ-ℕ y) = succ-ℕ (dist-ℕ x y)
+ (x y : ℕ) → x ≤-ℕ y → dist-ℕ x (succ-ℕ y) = succ-ℕ (dist-ℕ x y)
right-successor-law-dist-ℕ zero-ℕ zero-ℕ star = refl
right-successor-law-dist-ℕ zero-ℕ (succ-ℕ y) star = refl
right-successor-law-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
right-successor-law-dist-ℕ x y H
left-successor-law-dist-ℕ :
- (x y : ℕ) → leq-ℕ y x → dist-ℕ (succ-ℕ x) y = succ-ℕ (dist-ℕ x y)
+ (x y : ℕ) → y ≤-ℕ x → dist-ℕ (succ-ℕ x) y = succ-ℕ (dist-ℕ x y)
left-successor-law-dist-ℕ zero-ℕ zero-ℕ star = refl
left-successor-law-dist-ℕ (succ-ℕ x) zero-ℕ star = refl
left-successor-law-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
@@ -330,7 +339,7 @@ translation-invariant-dist-ℕ' k m n =
```agda
left-distributive-mul-dist-ℕ :
- (m n k : ℕ) → k *ℕ (dist-ℕ m n) = dist-ℕ (k *ℕ m) (k *ℕ n)
+ (m n k : ℕ) → k *ℕ dist-ℕ m n = dist-ℕ (k *ℕ m) (k *ℕ n)
left-distributive-mul-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = refl
left-distributive-mul-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) =
left-distributive-mul-dist-ℕ zero-ℕ zero-ℕ k
@@ -350,11 +359,11 @@ left-distributive-mul-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
( ( ap-dist-ℕ
( right-successor-law-mul-ℕ (succ-ℕ k) m)
( right-successor-law-mul-ℕ (succ-ℕ k) n)) ∙
- ( ( translation-invariant-dist-ℕ
- ( succ-ℕ k)
- ( (succ-ℕ k) *ℕ m)
- ( (succ-ℕ k) *ℕ n)) ∙
- ( inv (left-distributive-mul-dist-ℕ m n (succ-ℕ k)))))
+ ( translation-invariant-dist-ℕ'
+ ( succ-ℕ k)
+ ( succ-ℕ k *ℕ m)
+ ( succ-ℕ k *ℕ n)) ∙
+ ( inv (left-distributive-mul-dist-ℕ m n (succ-ℕ k))))
left-distributive-mul-dist-ℕ' :
(m n k : ℕ) → dist-ℕ (k *ℕ m) (k *ℕ n) = k *ℕ (dist-ℕ m n)
@@ -362,7 +371,7 @@ left-distributive-mul-dist-ℕ' m n k =
inv (left-distributive-mul-dist-ℕ m n k)
right-distributive-mul-dist-ℕ :
- (x y k : ℕ) → (dist-ℕ x y) *ℕ k = dist-ℕ (x *ℕ k) (y *ℕ k)
+ (x y k : ℕ) → dist-ℕ x y *ℕ k = dist-ℕ (x *ℕ k) (y *ℕ k)
right-distributive-mul-dist-ℕ x y k =
( commutative-mul-ℕ (dist-ℕ x y) k) ∙
( ( left-distributive-mul-dist-ℕ x y k) ∙
diff --git a/src/elementary-number-theory/divisibility-integers.lagda.md b/src/elementary-number-theory/divisibility-integers.lagda.md
index bed59408c3..4a6a6d3bfe 100644
--- a/src/elementary-number-theory/divisibility-integers.lagda.md
+++ b/src/elementary-number-theory/divisibility-integers.lagda.md
@@ -19,6 +19,8 @@ open import elementary-number-theory.nonnegative-integers
open import elementary-number-theory.nonpositive-integers
open import elementary-number-theory.nonzero-integers
open import elementary-number-theory.positive-and-negative-integers
+open import elementary-number-theory.unit-integers
+open import elementary-number-theory.unit-similarity-integers
open import foundation.action-on-identifications-functions
open import foundation.binary-relations
@@ -41,8 +43,13 @@ open import foundation.universe-levels
## Idea
+On this page we define the
+{{#concept "divisibility" Disambiguation="integers" Agda=div-ℤ WD="divisibility" WDID=Q5284415}}
+relation on the [integers](elementary-number-theory.integers.md).
+
An integer `m` is said to **divide** an integer `n` if there exists an integer
-`k` equipped with an identification `km = n`. Using the
+`k` equipped with an [identification](foundation-core.identity-types.md)
+`km = n`. Using the
[Curry–Howard interpretation](https://en.wikipedia.org/wiki/Curry–Howard_correspondence)
of logic into type theory, we express divisibility as follows:
@@ -50,17 +57,14 @@ of logic into type theory, we express divisibility as follows:
div-ℤ m n := Σ (k : ℤ), k *ℤ m = n.
```
-If `n` is a nonzero integer, then `div-ℤ m n` is always a proposition in the
-sense that the type `div-ℤ m n` contains at most one element.
-
-We also introduce **unit integers**, which are integers that divide the integer
-`1`, and an equivalence relation `sim-unit-ℤ` on the integers in which two
-integers `x` and `y` are equivalent if there exists a unit integer `u` such that
-`ux = y`. These two concepts help establish further properties of the
-divisibility relation on the integers.
+If `n` is a [nonzero integer](elementary-number-theory.nonzero-integers.md),
+then `div-ℤ m n` is always a [proposition](foundation-core.propositions.md) in
+the sense that the type `div-ℤ m n` contains at most one element.
## Definitions
+### Divisibility of the integers
+
```agda
div-ℤ : ℤ → ℤ → UU lzero
div-ℤ d x = Σ ℤ (λ k → k *ℤ d = x)
@@ -95,43 +99,38 @@ concatenate-eq-div-eq-ℤ :
concatenate-eq-div-eq-ℤ refl p refl = p
```
-### Unit integers
-
-```agda
-is-unit-ℤ : ℤ → UU lzero
-is-unit-ℤ x = div-ℤ x one-ℤ
-
-unit-ℤ : UU lzero
-unit-ℤ = Σ ℤ is-unit-ℤ
-
-int-unit-ℤ : unit-ℤ → ℤ
-int-unit-ℤ = pr1
-
-is-unit-int-unit-ℤ : (x : unit-ℤ) → is-unit-ℤ (int-unit-ℤ x)
-is-unit-int-unit-ℤ = pr2
-
-div-is-unit-ℤ :
- (x y : ℤ) → is-unit-ℤ x → div-ℤ x y
-pr1 (div-is-unit-ℤ x y (pair d p)) = y *ℤ d
-pr2 (div-is-unit-ℤ x y (pair d p)) =
- associative-mul-ℤ y d x ∙ (ap (y *ℤ_) p ∙ right-unit-law-mul-ℤ y)
-```
-
-### The equivalence relation `sim-unit-ℤ`
+## Properties
-We define the equivalence relation `sim-unit-ℤ` in such a way that
-`sim-unit-ℤ x y` is always a proposition.
+### A natural number `m` divides a natural number `n` if and only if `m` divides `n` as integers
```agda
-presim-unit-ℤ : ℤ → ℤ → UU lzero
-presim-unit-ℤ x y = Σ unit-ℤ (λ u → (pr1 u) *ℤ x = y)
+div-int-div-ℕ :
+ {m n : ℕ} → div-ℕ m n → div-ℤ (int-ℕ m) (int-ℕ n)
+pr1 (div-int-div-ℕ {m} {n} (pair d p)) = int-ℕ d
+pr2 (div-int-div-ℕ {m} {n} (pair d p)) = mul-int-ℕ d m ∙ ap int-ℕ p
-sim-unit-ℤ : ℤ → ℤ → UU lzero
-sim-unit-ℤ x y = ¬ (is-zero-ℤ x × is-zero-ℤ y) → presim-unit-ℤ x y
+div-div-int-ℕ :
+ {m n : ℕ} → div-ℤ (int-ℕ m) (int-ℕ n) → div-ℕ m n
+div-div-int-ℕ {zero-ℕ} {n} (pair d p) =
+ div-eq-ℕ zero-ℕ n
+ ( inv (is-injective-int-ℕ (inv p ∙ right-zero-law-mul-ℤ d)))
+pr1 (div-div-int-ℕ {succ-ℕ m} {n} (pair d p)) = abs-ℤ d
+pr2 (div-div-int-ℕ {succ-ℕ m} {n} (pair d p)) =
+ is-injective-int-ℕ
+ ( ( inv (mul-int-ℕ (abs-ℤ d) (succ-ℕ m))) ∙
+ ( ( ap
+ ( _*ℤ (inr (inr m)))
+ { int-abs-ℤ d}
+ { d}
+ ( int-abs-is-nonnegative-ℤ d
+ ( is-nonnegative-left-factor-mul-ℤ
+ { d}
+ { inr (inr m)}
+ ( is-nonnegative-eq-ℤ (inv p) (is-nonnegative-int-ℕ n))
+ ( star)))) ∙
+ ( p)))
```
-## Properties
-
### Divisibility by a nonzero integer is a property
```agda
@@ -180,6 +179,26 @@ is-zero-div-zero-ℤ :
is-zero-div-zero-ℤ x (pair d p) = inv p ∙ right-zero-law-mul-ℤ d
```
+### A unit integer divides every integer
+
+```agda
+div-is-unit-ℤ :
+ (x y : ℤ) → is-unit-ℤ x → div-ℤ x y
+pr1 (div-is-unit-ℤ x y (d , p , q)) = y *ℤ d
+pr2 (div-is-unit-ℤ x y (d , p , q)) =
+ associative-mul-ℤ y d x ∙ (ap (y *ℤ_) q ∙ right-unit-law-mul-ℤ y)
+```
+
+### An integer is a unit if and only if it divides $1$
+
+```agda
+div-one-is-unit-ℤ : (x : ℤ) → is-unit-ℤ x → div-ℤ x one-ℤ
+div-one-is-unit-ℤ x (d , p , q) = (d , q)
+
+is-unit-div-one-ℤ : (x : ℤ) → div-ℤ x one-ℤ → is-unit-ℤ x
+is-unit-div-one-ℤ x (d , p) = (d , commutative-mul-ℤ x d ∙ p , p)
+```
+
### The quotient of `x` by one is `x`
```agda
@@ -202,16 +221,6 @@ is-zero-is-zero-div-ℤ : (x k : ℤ) → div-ℤ k x → is-zero-ℤ k → is-z
is-zero-is-zero-div-ℤ x .zero-ℤ k-div-x refl = is-zero-div-zero-ℤ x k-div-x
```
-### If `x` divides both `y` and `z`, then it divides `y + z`
-
-```agda
-div-add-ℤ : (x y z : ℤ) → div-ℤ x y → div-ℤ x z → div-ℤ x (y +ℤ z)
-pr1 (div-add-ℤ x y z (pair d p) (pair e q)) = d +ℤ e
-pr2 (div-add-ℤ x y z (pair d p) (pair e q)) =
- ( right-distributive-mul-add-ℤ d e x) ∙
- ( ap-add-ℤ p q)
-```
-
### If `x` divides `y` then `x` divides any multiple of `y`
```agda
@@ -246,17 +255,58 @@ pr2 (neg-div-ℤ x y (pair d p)) =
by p
```
+### If `x` divides two out of the three integers `y`, `z`, and `y + z`, then it divides the third
+
+```agda
+div-add-ℤ : (x y z : ℤ) → div-ℤ x y → div-ℤ x z → div-ℤ x (y +ℤ z)
+pr1 (div-add-ℤ x y z (pair d p) (pair e q)) = d +ℤ e
+pr2 (div-add-ℤ x y z (pair d p) (pair e q)) =
+ ( right-distributive-mul-add-ℤ d e x) ∙
+ ( ap-add-ℤ p q)
+
+div-right-summand-ℤ :
+ (x y z : ℤ) → div-ℤ x y → div-ℤ x (y +ℤ z) → div-ℤ x z
+div-right-summand-ℤ x y z H K =
+ tr
+ ( div-ℤ x)
+ ( is-retraction-left-add-neg-ℤ y z)
+ ( div-add-ℤ x
+ ( neg-ℤ y)
+ ( y +ℤ z)
+ ( div-neg-ℤ x y H)
+ ( K))
+
+div-left-summand-ℤ :
+ (x y z : ℤ) → div-ℤ x z → div-ℤ x (y +ℤ z) → div-ℤ x y
+div-left-summand-ℤ x y z H K =
+ tr
+ ( div-ℤ x)
+ ( is-retraction-right-add-neg-ℤ z y)
+ ( div-add-ℤ x
+ ( y +ℤ z)
+ ( neg-ℤ z)
+ ( K)
+ ( div-neg-ℤ x z H))
+```
+
### Multiplication preserves divisibility
```agda
preserves-div-mul-ℤ :
+ (k l x y : ℤ) → div-ℤ k x → div-ℤ l y → div-ℤ (k *ℤ l) (x *ℤ y)
+pr1 (preserves-div-mul-ℤ k l x y (q , α) (p , β)) = q *ℤ p
+pr2 (preserves-div-mul-ℤ k l x y (q , α) (p , β)) =
+ interchange-law-mul-mul-ℤ q p k l ∙ ap-mul-ℤ α β
+
+preserves-div-left-mul-ℤ :
(k x y : ℤ) → div-ℤ x y → div-ℤ (k *ℤ x) (k *ℤ y)
-pr1 (preserves-div-mul-ℤ k x y (pair q p)) = q
-pr2 (preserves-div-mul-ℤ k x y (pair q p)) =
- ( inv (associative-mul-ℤ q k x)) ∙
- ( ( ap (_*ℤ x) (commutative-mul-ℤ q k)) ∙
- ( ( associative-mul-ℤ k q x) ∙
- ( ap (k *ℤ_) p)))
+preserves-div-left-mul-ℤ k x y H =
+ preserves-div-mul-ℤ k x k y (refl-div-ℤ k) H
+
+preserves-div-right-mul-ℤ :
+ (k x y : ℤ) → div-ℤ x y → div-ℤ (x *ℤ k) (y *ℤ k)
+preserves-div-right-mul-ℤ k x y H =
+ preserves-div-mul-ℤ x k y k H (refl-div-ℤ k)
```
### Multiplication by a nonzero number reflects divisibility
@@ -292,268 +342,7 @@ div-div-quotient-div-ℤ x y d H K =
tr
( div-ℤ (d *ℤ x))
( eq-quotient-div-ℤ' d y H)
- ( preserves-div-mul-ℤ d x (quotient-div-ℤ d y H) K)
-```
-
-### Comparison of divisibility on `ℕ` and on `ℤ`
-
-```agda
-div-int-div-ℕ :
- {x y : ℕ} → div-ℕ x y → div-ℤ (int-ℕ x) (int-ℕ y)
-pr1 (div-int-div-ℕ {x} {y} (pair d p)) = int-ℕ d
-pr2 (div-int-div-ℕ {x} {y} (pair d p)) = mul-int-ℕ d x ∙ ap int-ℕ p
-
-div-div-int-ℕ :
- {x y : ℕ} → div-ℤ (int-ℕ x) (int-ℕ y) → div-ℕ x y
-div-div-int-ℕ {zero-ℕ} {y} (pair d p) =
- div-eq-ℕ zero-ℕ y
- ( inv (is-injective-int-ℕ (is-zero-div-zero-ℤ (int-ℕ y) (pair d p))))
-pr1 (div-div-int-ℕ {succ-ℕ x} {y} (pair d p)) = abs-ℤ d
-pr2 (div-div-int-ℕ {succ-ℕ x} {y} (pair d p)) =
- is-injective-int-ℕ
- ( ( inv (mul-int-ℕ (abs-ℤ d) (succ-ℕ x))) ∙
- ( ( ap
- ( _*ℤ (inr (inr x)))
- { int-abs-ℤ d}
- { d}
- ( int-abs-is-nonnegative-ℤ d
- ( is-nonnegative-left-factor-mul-ℤ
- { d}
- { inr (inr x)}
- ( is-nonnegative-eq-ℤ (inv p) (is-nonnegative-int-ℕ y))
- ( star)))) ∙
- ( p)))
-```
-
-### An integer is a unit if and only if it is `1` or `-1`
-
-```agda
-is-one-or-neg-one-ℤ : ℤ → UU lzero
-is-one-or-neg-one-ℤ x = (is-one-ℤ x) + (is-neg-one-ℤ x)
-
-is-unit-one-ℤ : is-unit-ℤ one-ℤ
-is-unit-one-ℤ = refl-div-ℤ one-ℤ
-
-one-unit-ℤ : unit-ℤ
-pr1 one-unit-ℤ = one-ℤ
-pr2 one-unit-ℤ = is-unit-one-ℤ
-
-is-unit-is-one-ℤ :
- (x : ℤ) → is-one-ℤ x → is-unit-ℤ x
-is-unit-is-one-ℤ .one-ℤ refl = is-unit-one-ℤ
-
-is-unit-neg-one-ℤ : is-unit-ℤ neg-one-ℤ
-pr1 is-unit-neg-one-ℤ = neg-one-ℤ
-pr2 is-unit-neg-one-ℤ = refl
-
-neg-one-unit-ℤ : unit-ℤ
-pr1 neg-one-unit-ℤ = neg-one-ℤ
-pr2 neg-one-unit-ℤ = is-unit-neg-one-ℤ
-
-is-unit-is-neg-one-ℤ :
- (x : ℤ) → is-neg-one-ℤ x → is-unit-ℤ x
-is-unit-is-neg-one-ℤ .neg-one-ℤ refl = is-unit-neg-one-ℤ
-
-is-unit-is-one-or-neg-one-ℤ :
- (x : ℤ) → is-one-or-neg-one-ℤ x → is-unit-ℤ x
-is-unit-is-one-or-neg-one-ℤ x (inl p) = is-unit-is-one-ℤ x p
-is-unit-is-one-or-neg-one-ℤ x (inr p) = is-unit-is-neg-one-ℤ x p
-
-is-one-or-neg-one-is-unit-ℤ :
- (x : ℤ) → is-unit-ℤ x → is-one-or-neg-one-ℤ x
-is-one-or-neg-one-is-unit-ℤ (inl zero-ℕ) (pair d p) = inr refl
-is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (pair (inl zero-ℕ) p) =
- ex-falso (Eq-eq-ℤ (inv p ∙ compute-mul-ℤ neg-one-ℤ (inl (succ-ℕ x))))
-is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (pair (inl (succ-ℕ d)) p) =
- ex-falso (Eq-eq-ℤ (inv p ∙ compute-mul-ℤ (inl (succ-ℕ d)) (inl (succ-ℕ x))))
-is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (pair (inr (inl star)) p) =
- ex-falso (Eq-eq-ℤ (inv p ∙ compute-mul-ℤ zero-ℤ (inl (succ-ℕ x))))
-is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (pair (inr (inr zero-ℕ)) p) =
- ex-falso (Eq-eq-ℤ (inv p ∙ compute-mul-ℤ one-ℤ (inl (succ-ℕ x))))
-is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (pair (inr (inr (succ-ℕ d))) p) =
- ex-falso
- ( Eq-eq-ℤ (inv p ∙ compute-mul-ℤ (inr (inr (succ-ℕ d))) (inl (succ-ℕ x))))
-is-one-or-neg-one-is-unit-ℤ (inr (inl star)) (pair d p) =
- ex-falso (Eq-eq-ℤ (inv (right-zero-law-mul-ℤ d) ∙ p))
-is-one-or-neg-one-is-unit-ℤ (inr (inr zero-ℕ)) (pair d p) = inl refl
-is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (pair (inl zero-ℕ) p) =
- ex-falso (Eq-eq-ℤ (inv p ∙ compute-mul-ℤ neg-one-ℤ (inr (inr (succ-ℕ x)))))
-is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (pair (inl (succ-ℕ d)) p) =
- ex-falso
- ( Eq-eq-ℤ (inv p ∙ compute-mul-ℤ (inl (succ-ℕ d)) (inr (inr (succ-ℕ x)))))
-is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (pair (inr (inl star)) p) =
- ex-falso (Eq-eq-ℤ (inv p ∙ compute-mul-ℤ zero-ℤ (inr (inr (succ-ℕ x)))))
-is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (pair (inr (inr zero-ℕ)) p) =
- ex-falso (Eq-eq-ℤ (inv p ∙ compute-mul-ℤ one-ℤ (inr (inr (succ-ℕ x)))))
-is-one-or-neg-one-is-unit-ℤ
- (inr (inr (succ-ℕ x))) (pair (inr (inr (succ-ℕ d))) p) =
- ex-falso
- ( Eq-eq-ℤ
- ( inv p ∙ compute-mul-ℤ (inr (inr (succ-ℕ d))) (inr (inr (succ-ℕ x)))))
-```
-
-### Units are idempotent
-
-```agda
-idempotent-is-unit-ℤ : {x : ℤ} → is-unit-ℤ x → x *ℤ x = one-ℤ
-idempotent-is-unit-ℤ {x} H =
- f (is-one-or-neg-one-is-unit-ℤ x H)
- where
- f : is-one-or-neg-one-ℤ x → x *ℤ x = one-ℤ
- f (inl refl) = refl
- f (inr refl) = refl
-
-abstract
- is-one-is-unit-int-ℕ : (x : ℕ) → is-unit-ℤ (int-ℕ x) → is-one-ℕ x
- is-one-is-unit-int-ℕ x H with is-one-or-neg-one-is-unit-ℤ (int-ℕ x) H
- ... | inl p = is-injective-int-ℕ p
- ... | inr p = ex-falso (tr is-nonnegative-ℤ p (is-nonnegative-int-ℕ x))
-```
-
-### The product `xy` is a unit if and only if both `x` and `y` are units
-
-```agda
-is-unit-mul-ℤ :
- (x y : ℤ) → is-unit-ℤ x → is-unit-ℤ y → is-unit-ℤ (x *ℤ y)
-pr1 (is-unit-mul-ℤ x y (pair d p) (pair e q)) = e *ℤ d
-pr2 (is-unit-mul-ℤ x y (pair d p) (pair e q)) =
- ( associative-mul-ℤ e d (x *ℤ y)) ∙
- ( ( ap
- ( e *ℤ_)
- ( ( inv (associative-mul-ℤ d x y)) ∙
- ( ap (_*ℤ y) p))) ∙
- ( q))
-
-mul-unit-ℤ : unit-ℤ → unit-ℤ → unit-ℤ
-pr1 (mul-unit-ℤ (pair x H) (pair y K)) = x *ℤ y
-pr2 (mul-unit-ℤ (pair x H) (pair y K)) = is-unit-mul-ℤ x y H K
-
-is-unit-left-factor-mul-ℤ :
- (x y : ℤ) → is-unit-ℤ (x *ℤ y) → is-unit-ℤ x
-pr1 (is-unit-left-factor-mul-ℤ x y (pair d p)) = d *ℤ y
-pr2 (is-unit-left-factor-mul-ℤ x y (pair d p)) =
- associative-mul-ℤ d y x ∙ (ap (d *ℤ_) (commutative-mul-ℤ y x) ∙ p)
-
-is-unit-right-factor-ℤ :
- (x y : ℤ) → is-unit-ℤ (x *ℤ y) → is-unit-ℤ y
-is-unit-right-factor-ℤ x y (pair d p) =
- is-unit-left-factor-mul-ℤ y x
- ( pair d (ap (d *ℤ_) (commutative-mul-ℤ y x) ∙ p))
-```
-
-### The relations `presim-unit-ℤ` and `sim-unit-ℤ` are logically equivalent
-
-```agda
-sim-unit-presim-unit-ℤ :
- {x y : ℤ} → presim-unit-ℤ x y → sim-unit-ℤ x y
-sim-unit-presim-unit-ℤ {x} {y} H f = H
-
-presim-unit-sim-unit-ℤ :
- {x y : ℤ} → sim-unit-ℤ x y → presim-unit-ℤ x y
-presim-unit-sim-unit-ℤ {inl x} {inl y} H = H (λ t → Eq-eq-ℤ (pr1 t))
-presim-unit-sim-unit-ℤ {inl x} {inr y} H = H (λ t → Eq-eq-ℤ (pr1 t))
-presim-unit-sim-unit-ℤ {inr x} {inl y} H = H (λ t → Eq-eq-ℤ (pr2 t))
-pr1 (presim-unit-sim-unit-ℤ {inr (inl star)} {inr (inl star)} H) = one-unit-ℤ
-pr2 (presim-unit-sim-unit-ℤ {inr (inl star)} {inr (inl star)} H) = refl
-presim-unit-sim-unit-ℤ {inr (inl star)} {inr (inr y)} H =
- H (λ t → Eq-eq-ℤ (pr2 t))
-presim-unit-sim-unit-ℤ {inr (inr x)} {inr (inl star)} H =
- H (λ t → Eq-eq-ℤ (pr1 t))
-presim-unit-sim-unit-ℤ {inr (inr x)} {inr (inr y)} H =
- H (λ t → Eq-eq-ℤ (pr1 t))
-```
-
-### The relations `presim-unit-ℤ` and `sim-unit-ℤ` relate `zero-ℤ` only to itself
-
-```agda
-is-nonzero-presim-unit-ℤ :
- {x y : ℤ} → presim-unit-ℤ x y → is-nonzero-ℤ x → is-nonzero-ℤ y
-is-nonzero-presim-unit-ℤ {x} {y} (pair (pair v (pair u α)) β) f p =
- Eq-eq-ℤ (ap (_*ℤ u) (inv q) ∙ (commutative-mul-ℤ v u ∙ α))
- where
- q : is-zero-ℤ v
- q = is-injective-right-mul-ℤ x f {v} {zero-ℤ} (β ∙ p)
-
-is-nonzero-sim-unit-ℤ :
- {x y : ℤ} → sim-unit-ℤ x y → is-nonzero-ℤ x → is-nonzero-ℤ y
-is-nonzero-sim-unit-ℤ H f =
- is-nonzero-presim-unit-ℤ (H (f ∘ pr1)) f
-
-is-zero-sim-unit-ℤ :
- {x y : ℤ} → sim-unit-ℤ x y → is-zero-ℤ x → is-zero-ℤ y
-is-zero-sim-unit-ℤ {x} {y} H p =
- double-negation-elim-is-decidable
- ( has-decidable-equality-ℤ y zero-ℤ)
- ( λ g → g (inv (β g) ∙ (ap ((u g) *ℤ_) p ∙ right-zero-law-mul-ℤ (u g))))
- where
- K : is-nonzero-ℤ y → presim-unit-ℤ x y
- K g = H (λ (u , v) → g v)
- u : is-nonzero-ℤ y → ℤ
- u g = pr1 (pr1 (K g))
- v : is-nonzero-ℤ y → ℤ
- v g = pr1 (pr2 (pr1 (K g)))
- β : (g : is-nonzero-ℤ y) → (u g) *ℤ x = y
- β g = pr2 (K g)
-```
-
-### The relations `presim-unit-ℤ` and `sim-unit-ℤ` are equivalence relations
-
-```agda
-refl-presim-unit-ℤ : is-reflexive presim-unit-ℤ
-pr1 (refl-presim-unit-ℤ x) = one-unit-ℤ
-pr2 (refl-presim-unit-ℤ x) = left-unit-law-mul-ℤ x
-
-refl-sim-unit-ℤ : is-reflexive sim-unit-ℤ
-refl-sim-unit-ℤ x f = refl-presim-unit-ℤ x
-
-presim-unit-eq-ℤ : {x y : ℤ} → x = y → presim-unit-ℤ x y
-presim-unit-eq-ℤ {x} refl = refl-presim-unit-ℤ x
-
-sim-unit-eq-ℤ : {x y : ℤ} → x = y → sim-unit-ℤ x y
-sim-unit-eq-ℤ {x} refl = refl-sim-unit-ℤ x
-
-symmetric-presim-unit-ℤ : is-symmetric presim-unit-ℤ
-symmetric-presim-unit-ℤ x y (pair (pair u H) p) =
- f (is-one-or-neg-one-is-unit-ℤ u H)
- where
- f : is-one-or-neg-one-ℤ u → presim-unit-ℤ y x
- pr1 (f (inl refl)) = one-unit-ℤ
- pr2 (f (inl refl)) = inv p
- pr1 (f (inr refl)) = neg-one-unit-ℤ
- pr2 (f (inr refl)) = inv (inv (neg-neg-ℤ x) ∙ ap (neg-one-ℤ *ℤ_) p)
-
-symmetric-sim-unit-ℤ : is-symmetric sim-unit-ℤ
-symmetric-sim-unit-ℤ x y H f =
- symmetric-presim-unit-ℤ x y (H (λ p → f (pair (pr2 p) (pr1 p))))
-
-is-nonzero-sim-unit-ℤ' :
- {x y : ℤ} → sim-unit-ℤ x y → is-nonzero-ℤ y → is-nonzero-ℤ x
-is-nonzero-sim-unit-ℤ' {x} {y} H =
- is-nonzero-sim-unit-ℤ (symmetric-sim-unit-ℤ x y H)
-
-is-zero-sim-unit-ℤ' :
- {x y : ℤ} → sim-unit-ℤ x y → is-zero-ℤ y → is-zero-ℤ x
-is-zero-sim-unit-ℤ' {x} {y} H = is-zero-sim-unit-ℤ (symmetric-sim-unit-ℤ x y H)
-
-transitive-presim-unit-ℤ : is-transitive presim-unit-ℤ
-transitive-presim-unit-ℤ x y z (pair (pair v K) q) (pair (pair u H) p) =
- f (is-one-or-neg-one-is-unit-ℤ u H) (is-one-or-neg-one-is-unit-ℤ v K)
- where
- f : is-one-or-neg-one-ℤ u → is-one-or-neg-one-ℤ v → presim-unit-ℤ x z
- pr1 (f (inl refl) (inl refl)) = one-unit-ℤ
- pr2 (f (inl refl) (inl refl)) = p ∙ q
- pr1 (f (inl refl) (inr refl)) = neg-one-unit-ℤ
- pr2 (f (inl refl) (inr refl)) = ap neg-ℤ p ∙ q
- pr1 (f (inr refl) (inl refl)) = neg-one-unit-ℤ
- pr2 (f (inr refl) (inl refl)) = p ∙ q
- pr1 (f (inr refl) (inr refl)) = one-unit-ℤ
- pr2 (f (inr refl) (inr refl)) = inv (neg-neg-ℤ x) ∙ (ap neg-ℤ p ∙ q)
-
-transitive-sim-unit-ℤ : is-transitive sim-unit-ℤ
-transitive-sim-unit-ℤ x y z K H f =
- transitive-presim-unit-ℤ x y z
- ( K (λ (p , q) → f (is-zero-sim-unit-ℤ' H p , q)))
- ( H (λ (p , q) → f (p , is-zero-sim-unit-ℤ K q)))
+ ( preserves-div-left-mul-ℤ d x (quotient-div-ℤ d y H) K)
```
### `sim-unit-ℤ x y` holds if and only if `x|y` and `y|x`
@@ -567,42 +356,37 @@ antisymmetric-div-ℤ x y (pair d p) (pair e q) H =
f : is-decidable (is-zero-ℤ x) → presim-unit-ℤ x y
f (inl refl) = presim-unit-eq-ℤ (inv (right-zero-law-mul-ℤ d) ∙ p)
pr1 (pr1 (f (inr g))) = d
- pr1 (pr2 (pr1 (f (inr g)))) = e
- pr2 (pr2 (pr1 (f (inr g)))) =
- is-injective-left-mul-ℤ x g
- ( ( commutative-mul-ℤ x (e *ℤ d)) ∙
- ( ( associative-mul-ℤ e d x) ∙
- ( ( ap (e *ℤ_) p) ∙
- ( q ∙ inv (right-unit-law-mul-ℤ x)))))
+ pr2 (pr1 (f (inr g))) =
+ is-unit-div-one-ℤ d
+ ( e ,
+ is-injective-left-mul-ℤ x g
+ ( ( commutative-mul-ℤ x (e *ℤ d)) ∙
+ ( ( associative-mul-ℤ e d x) ∙
+ ( ( ap (e *ℤ_) p) ∙
+ ( q ∙ inv (right-unit-law-mul-ℤ x))))))
pr2 (f (inr g)) = p
```
-### `sim-unit-ℤ |x| x` holds
+### If `x ~ x'` and `y ~ y'` are unit similar, then `x | y` holds if and only if `x' | y'` holds
```agda
-sim-unit-abs-ℤ : (x : ℤ) → sim-unit-ℤ (int-abs-ℤ x) x
-pr1 (sim-unit-abs-ℤ (inl x) f) = neg-one-unit-ℤ
-pr2 (sim-unit-abs-ℤ (inl x) f) = refl
-sim-unit-abs-ℤ (inr (inl star)) = refl-sim-unit-ℤ zero-ℤ
-sim-unit-abs-ℤ (inr (inr x)) = refl-sim-unit-ℤ (inr (inr x))
-
div-presim-unit-ℤ :
{x y x' y' : ℤ} → presim-unit-ℤ x x' → presim-unit-ℤ y y' →
div-ℤ x y → div-ℤ x' y'
pr1 (div-presim-unit-ℤ {x} {y} {x'} {y'} (pair u q) (pair v r) (pair d p)) =
- ((int-unit-ℤ v) *ℤ d) *ℤ (int-unit-ℤ u)
+ (int-unit-ℤ v *ℤ d) *ℤ (int-unit-ℤ u)
pr2 (div-presim-unit-ℤ {x} {y} {x'} {y'} (pair u q) (pair v r) (pair d p)) =
( ap ((((int-unit-ℤ v) *ℤ d) *ℤ (int-unit-ℤ u)) *ℤ_) (inv q)) ∙
( ( associative-mul-ℤ
- ( (int-unit-ℤ v) *ℤ d)
+ ( int-unit-ℤ v *ℤ d)
( int-unit-ℤ u)
- ( (int-unit-ℤ u) *ℤ x)) ∙
+ ( int-unit-ℤ u *ℤ x)) ∙
( ( ap
- ( ((int-unit-ℤ v) *ℤ d) *ℤ_)
+ ( (int-unit-ℤ v *ℤ d) *ℤ_)
( ( inv (associative-mul-ℤ (int-unit-ℤ u) (int-unit-ℤ u) x)) ∙
- ( ap (_*ℤ x) (idempotent-is-unit-ℤ (is-unit-int-unit-ℤ u))))) ∙
+ ( ap (_*ℤ x) (idempotent-is-unit-ℤ (is-unit-unit-ℤ u))))) ∙
( ( associative-mul-ℤ (int-unit-ℤ v) d x) ∙
- ( ( ap ((int-unit-ℤ v) *ℤ_) p) ∙
+ ( ( ap (int-unit-ℤ v *ℤ_) p) ∙
( r)))))
div-sim-unit-ℤ :
@@ -610,66 +394,53 @@ div-sim-unit-ℤ :
div-ℤ x y → div-ℤ x' y'
div-sim-unit-ℤ {x} {y} {x'} {y'} H K =
div-presim-unit-ℤ (presim-unit-sim-unit-ℤ H) (presim-unit-sim-unit-ℤ K)
+```
-div-int-abs-div-ℤ :
+### An integer `x` divides an integer `y` if and only if its absolute value `|x|` divides `y`
+
+```agda
+div-int-abs-divisor-div-ℤ :
{x y : ℤ} → div-ℤ x y → div-ℤ (int-abs-ℤ x) y
-div-int-abs-div-ℤ {x} {y} =
+div-int-abs-divisor-div-ℤ {x} {y} =
div-sim-unit-ℤ
( symmetric-sim-unit-ℤ (int-abs-ℤ x) x (sim-unit-abs-ℤ x))
( refl-sim-unit-ℤ y)
-div-div-int-abs-ℤ :
+div-div-int-abs-divisor-ℤ :
{x y : ℤ} → div-ℤ (int-abs-ℤ x) y → div-ℤ x y
-div-div-int-abs-ℤ {x} {y} =
+div-div-int-abs-divisor-ℤ {x} {y} =
div-sim-unit-ℤ (sim-unit-abs-ℤ x) (refl-sim-unit-ℤ y)
```
-### If we have that `sim-unit-ℤ x y`, then they must differ only by sign
+### An integer `a` divides an integer `b` if and only if the natural number `|a|` divides the natural number `|b|`
```agda
-is-plus-or-minus-sim-unit-ℤ :
- {x y : ℤ} → sim-unit-ℤ x y → is-plus-or-minus-ℤ x y
-is-plus-or-minus-sim-unit-ℤ {x} {y} H with ( is-decidable-is-zero-ℤ x)
-is-plus-or-minus-sim-unit-ℤ {x} {y} H | inl z =
- inl (z ∙ inv (is-zero-sim-unit-ℤ H z))
-is-plus-or-minus-sim-unit-ℤ {x} {y} H | inr nz
- with
- ( is-one-or-neg-one-is-unit-ℤ
- ( int-unit-ℤ (pr1 (H (λ u → nz (pr1 u)))))
- ( is-unit-int-unit-ℤ (pr1 (H (λ u → nz (pr1 u))))))
-is-plus-or-minus-sim-unit-ℤ {x} {y} H | inr nz | inl pos =
- inl
- ( equational-reasoning
- x
- = one-ℤ *ℤ x
- by (inv (left-unit-law-mul-ℤ x))
- = (int-unit-ℤ (pr1 (H (λ u → nz (pr1 u))))) *ℤ x
- by inv (ap (_*ℤ x) pos)
- = y
- by pr2 (H (λ u → nz (pr1 u))))
-is-plus-or-minus-sim-unit-ℤ {x} {y} H | inr nz | inr p =
- inr
- ( equational-reasoning
- neg-ℤ x
- = (int-unit-ℤ (pr1 (H (λ u → nz (pr1 u))))) *ℤ x
- by ap (_*ℤ x) (inv p)
- = y
- by pr2 (H (λ u → nz (pr1 u))))
+div-abs-div-ℤ :
+ (a b : ℤ) → div-ℤ a b → div-ℕ (abs-ℤ a) (abs-ℤ b)
+div-abs-div-ℤ a b H =
+ div-div-int-ℕ
+ ( div-sim-unit-ℤ
+ ( symmetric-sim-unit-ℤ _ _ (sim-unit-abs-ℤ a))
+ ( symmetric-sim-unit-ℤ _ _ (sim-unit-abs-ℤ b))
+ ( H))
+
+div-div-abs-ℤ :
+ (a b : ℤ) → div-ℕ (abs-ℤ a) (abs-ℤ b) → div-ℤ a b
+div-div-abs-ℤ a b H =
+ div-sim-unit-ℤ
+ ( sim-unit-abs-ℤ a)
+ ( sim-unit-abs-ℤ b)
+ ( div-int-div-ℕ H)
```
-### If `sim-unit-ℤ x y` holds and both `x` and `y` have the same sign, then `x = y`
+### Divisibility on the integers is decidable
```agda
-eq-sim-unit-is-nonnegative-ℤ :
- {a b : ℤ} → is-nonnegative-ℤ a → is-nonnegative-ℤ b → sim-unit-ℤ a b → a = b
-eq-sim-unit-is-nonnegative-ℤ {a} {b} H H' K =
- rec-coproduct
- ( id)
- ( λ K' →
- eq-is-zero-ℤ
- ( is-zero-is-nonnegative-neg-is-nonnegative-ℤ H
- ( is-nonnegative-eq-ℤ (inv K') H'))
- ( is-zero-is-nonnegative-neg-is-nonnegative-ℤ H'
- ( is-nonnegative-eq-ℤ (inv (neg-neg-ℤ a) ∙ ap neg-ℤ K') H)))
- ( is-plus-or-minus-sim-unit-ℤ K)
+is-decidable-div-ℤ :
+ (a b : ℤ) → is-decidable (div-ℤ a b)
+is-decidable-div-ℤ a b =
+ is-decidable-iff
+ ( div-div-abs-ℤ a b)
+ ( div-abs-div-ℤ a b)
+ ( is-decidable-div-ℕ _ _)
```
diff --git a/src/elementary-number-theory/divisibility-natural-numbers.lagda.md b/src/elementary-number-theory/divisibility-natural-numbers.lagda.md
index 9bf81abc22..83d2779a26 100644
--- a/src/elementary-number-theory/divisibility-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/divisibility-natural-numbers.lagda.md
@@ -8,7 +8,10 @@ module elementary-number-theory.divisibility-natural-numbers where
```agda
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.bounded-divisibility-natural-numbers
+open import elementary-number-theory.decidable-types
open import elementary-number-theory.distance-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
@@ -16,15 +19,24 @@ open import elementary-number-theory.strict-inequality-natural-numbers
open import foundation.action-on-identifications-functions
open import foundation.binary-relations
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-propositions
+open import foundation.decidable-types
open import foundation.dependent-pair-types
open import foundation.empty-types
+open import foundation.equivalences
+open import foundation.function-types
open import foundation.identity-types
open import foundation.logical-equivalences
open import foundation.negated-equality
open import foundation.negation
open import foundation.propositional-maps
open import foundation.propositions
+open import foundation.sets
+open import foundation.subtypes
open import foundation.transport-along-identifications
+open import foundation.type-arithmetic-dependent-pair-types
open import foundation.type-arithmetic-empty-type
open import foundation.unit-type
open import foundation.universe-levels
@@ -34,8 +46,12 @@ open import foundation.universe-levels
## Idea
+On this page we define the
+{{#concept "divisibility" Disambiguation="natural numbers" Agda=div-ℕ WD="divisibility" WDID=Q5284415}}
+relation on the [natural numbers](elementary-number-theory.natural-numbers.md).
A natural number `m` is said to **divide** a natural number `n` if there exists
-a natural number `k` equipped with an identification `km = n`. Using the
+a natural number `k` equipped with an
+[identification](foundation-core.identifications.md) `km = n`. Using the
[Curry–Howard interpretation](https://en.wikipedia.org/wiki/Curry–Howard_correspondence)
of logic into type theory, we express divisibility as follows:
@@ -43,36 +59,68 @@ of logic into type theory, we express divisibility as follows:
div-ℕ m n := Σ (k : ℕ), k *ℕ m = n.
```
-If `n` is a nonzero natural number, then `div-ℕ m n` is always a proposition in
-the sense that the type `div-ℕ m n` contains at most one element.
+If `n` is a
+[nonzero natural number](elementary-number-theory.nonzero-natural-numbers.md),
+then the type `div-ℕ m n` is always a
+[proposition](foundation-core.propositions.md) in the sense that the type
+`div-ℕ m n` contains at most one element.
+
+The divisibility relation is
+[logically equivalent](foundation.logical-equivalences.md), though not
+[equivalent](foundation-core.equivalences.md), to the
+[bounded divisibility relation](elementary-number-theory.bounded-divisibility-natural-numbers.md),
+which is defined by
+
+```text
+ bounded-div-ℕ m n := Σ (k : ℕ), (k ≤ n) × (k *ℕ m = n).
+```
+
+The discrepancy between divisibility and bounded divisibility is manifested at
+`(0 , 0)`. Note that `div-ℕ 0 0 ≃ ℕ`, while `bounded-div-ℕ 0 0` is
+[contractible](foundation-core.contractible-types.md). For all other values we
+have `div-ℕ m n ≃ bounded-div-ℕ m n`.
+
+When a natural number
+`n is divisible by a natural number `m`, with an element `H : div-ℕ m
+n`, then we define the {{#concept "quotient" Disambiguation="divisibility of natural numbers" Agda=quotient-div-ℕ}} to be the unique number `q
+≤ n`such that`q \* m = n`.
## Definitions
+### The divisibility relation on the natural numbers
+
+We introduce the divisibility relation on the natural numbers, and some
+infrastructure.
+
+**Note:** Perhaps a more natural name for `pr1-div-ℕ`, the number `q` such that
+`q * d = n`, would be `quotient-div-ℕ`. However, since the divisibility
+relation is not always a proposition, the quotient could have some undesirable
+properties. Later in this file, we will define `quotient-div-ℕ` to the the
+quotient of the bounded divisibility relation, which is logically equivalent to
+the divisibility relation.
+
```agda
-div-ℕ : ℕ → ℕ → UU lzero
-div-ℕ m n = Σ ℕ (λ k → k *ℕ m = n)
+module _
+ (m n : ℕ)
+ where
-quotient-div-ℕ : (x y : ℕ) → div-ℕ x y → ℕ
-quotient-div-ℕ x y H = pr1 H
+ div-ℕ : UU lzero
+ div-ℕ = Σ ℕ (λ k → k *ℕ m = n)
-eq-quotient-div-ℕ :
- (x y : ℕ) (H : div-ℕ x y) → (quotient-div-ℕ x y H) *ℕ x = y
-eq-quotient-div-ℕ x y H = pr2 H
+ pr1-div-ℕ : div-ℕ → ℕ
+ pr1-div-ℕ = pr1
-eq-quotient-div-ℕ' :
- (x y : ℕ) (H : div-ℕ x y) → x *ℕ (quotient-div-ℕ x y H) = y
-eq-quotient-div-ℕ' x y H =
- commutative-mul-ℕ x (quotient-div-ℕ x y H) ∙ eq-quotient-div-ℕ x y H
+ eq-pr1-div-ℕ : (H : div-ℕ) → pr1-div-ℕ H *ℕ m = n
+ eq-pr1-div-ℕ = pr2
-div-quotient-div-ℕ :
- (d x : ℕ) (H : div-ℕ d x) → div-ℕ (quotient-div-ℕ d x H) x
-pr1 (div-quotient-div-ℕ d x (u , p)) = d
-pr2 (div-quotient-div-ℕ d x (u , p)) = commutative-mul-ℕ d u ∙ p
-```
+ eq-pr1-div-ℕ' : (H : div-ℕ) → m *ℕ pr1-div-ℕ H = n
+ eq-pr1-div-ℕ' H =
+ commutative-mul-ℕ m (pr1-div-ℕ H) ∙ eq-pr1-div-ℕ H
-### Concatenating equality and divisibility
+ div-bounded-div-ℕ : bounded-div-ℕ m n → div-ℕ
+ pr1 (div-bounded-div-ℕ H) = quotient-bounded-div-ℕ m n H
+ pr2 (div-bounded-div-ℕ H) = eq-quotient-bounded-div-ℕ m n H
-```agda
concatenate-eq-div-ℕ :
{x y z : ℕ} → x = y → div-ℕ y z → div-ℕ x z
concatenate-eq-div-ℕ refl p = p
@@ -86,39 +134,185 @@ concatenate-eq-div-eq-ℕ :
concatenate-eq-div-eq-ℕ refl p refl = p
```
+### The predicate of being a divisor of a natural number
+
+```agda
+is-divisor-ℕ : ℕ → ℕ → UU lzero
+is-divisor-ℕ n x = div-ℕ x n
+```
+
## Properties
-### The quotients of a natural number `n` by two natural numbers `p` and `q` are equal if `p` and `q` are equal
+### Divisibility and bounded divisibility are logically equivalent
+
+#### If `n` is divisible by a number `m` with proof of divisibility `(q , p)`, then `n` is divisible by the number `q`.
```agda
-eq-quotient-div-eq-div-ℕ :
- (x y z : ℕ) → is-nonzero-ℕ x → x = y →
- (H : div-ℕ x z) → (I : div-ℕ y z) →
- quotient-div-ℕ x z H = quotient-div-ℕ y z I
-eq-quotient-div-eq-div-ℕ x y z n e H I =
- is-injective-left-mul-ℕ
- ( x)
- ( n)
- ( tr
- ( λ p →
- x *ℕ (quotient-div-ℕ x z H) =
- p *ℕ (quotient-div-ℕ y z I))
- ( inv e)
- ( commutative-mul-ℕ x (quotient-div-ℕ x z H) ∙
- ( eq-quotient-div-ℕ x z H ∙
- ( inv (eq-quotient-div-ℕ y z I) ∙
- commutative-mul-ℕ (quotient-div-ℕ y z I) y))))
+div-pr1-div-ℕ :
+ (m n : ℕ) (H : div-ℕ m n) → div-ℕ (pr1-div-ℕ m n H) n
+pr1 (div-pr1-div-ℕ m n (u , p)) = m
+pr2 (div-pr1-div-ℕ m n (u , p)) = commutative-mul-ℕ m u ∙ p
+```
+
+#### If `x` is nonzero and `d | x`, then `d ≤ x`
+
+```agda
+leq-div-succ-ℕ : (d x : ℕ) → div-ℕ d (succ-ℕ x) → leq-ℕ d (succ-ℕ x)
+leq-div-succ-ℕ d x (succ-ℕ k , p) =
+ concatenate-leq-eq-ℕ d (leq-mul-ℕ' k d) p
+
+leq-div-ℕ : (d x : ℕ) → is-nonzero-ℕ x → div-ℕ d x → leq-ℕ d x
+leq-div-ℕ d x f H with is-successor-is-nonzero-ℕ f
+... | (y , refl) = leq-div-succ-ℕ d y H
+
+leq-pr1-div-ℕ :
+ (d x : ℕ) → is-nonzero-ℕ x → (H : div-ℕ d x) → leq-ℕ (pr1-div-ℕ d x H) x
+leq-pr1-div-ℕ d x f H =
+ leq-div-ℕ (pr1-div-ℕ d x H) x f (div-pr1-div-ℕ d x H)
+```
+
+#### The logical equivalence of divisibility and bounded divisibility
+
+```agda
+bounded-div-div-ℕ : (m n : ℕ) → div-ℕ m n → bounded-div-ℕ m n
+bounded-div-div-ℕ m zero-ℕ (q , p) = (0 , refl-leq-ℕ 0 , left-zero-law-mul-ℕ m)
+bounded-div-div-ℕ m (succ-ℕ n) (q , p) =
+ ( q , leq-pr1-div-ℕ m (succ-ℕ n) (is-nonzero-succ-ℕ n) (q , p) , p)
+
+logical-equivalence-bounded-div-div-ℕ :
+ (m n : ℕ) → bounded-div-ℕ m n ↔ div-ℕ m n
+pr1 (logical-equivalence-bounded-div-div-ℕ m n) =
+ div-bounded-div-ℕ m n
+pr2 (logical-equivalence-bounded-div-div-ℕ m n) =
+ bounded-div-div-ℕ m n
+```
+
+#### The quotient of a natural number by a number it is divisible by
+
+```agda
+module _
+ (m n : ℕ)
+ where
+
+ quotient-div-ℕ : div-ℕ m n → ℕ
+ quotient-div-ℕ H =
+ quotient-bounded-div-ℕ m n (bounded-div-div-ℕ m n H)
+
+ eq-quotient-div-ℕ : (H : div-ℕ m n) → quotient-div-ℕ H *ℕ m = n
+ eq-quotient-div-ℕ H =
+ eq-quotient-bounded-div-ℕ m n (bounded-div-div-ℕ m n H)
+
+ eq-quotient-div-ℕ' : (H : div-ℕ m n) → m *ℕ quotient-div-ℕ H = n
+ eq-quotient-div-ℕ' H =
+ eq-quotient-bounded-div-ℕ' m n (bounded-div-div-ℕ m n H)
+
+ upper-bound-quotient-div-ℕ :
+ (H : div-ℕ m n) → quotient-div-ℕ H ≤-ℕ n
+ upper-bound-quotient-div-ℕ H =
+ upper-bound-quotient-bounded-div-ℕ m n (bounded-div-div-ℕ m n H)
+
+ div-quotient-div-ℕ :
+ (H : div-ℕ m n) → div-ℕ (quotient-div-ℕ H) n
+ div-quotient-div-ℕ H =
+ div-bounded-div-ℕ
+ ( quotient-div-ℕ H)
+ ( n)
+ ( bounded-div-quotient-bounded-div-ℕ m n (bounded-div-div-ℕ m n H))
```
-### Divisibility by a nonzero natural number is a property
+### The quotient by divisibility of two equal dividends by two equal divisors are equal
+
+```agda
+compute-quotient-div-ℕ :
+ {m m' n n' : ℕ} (q : m = m') (p : n = n')
+ (H : div-ℕ m n) (K : div-ℕ m' n') →
+ quotient-div-ℕ m n H = quotient-div-ℕ m' n' K
+compute-quotient-div-ℕ q p H K =
+ compute-quotient-bounded-div-ℕ q p
+ ( bounded-div-div-ℕ _ _ H)
+ ( bounded-div-div-ℕ _ _ K)
+
+compute-quotient-div-is-nonzero-dividend-ℕ :
+ {m m' n n' : ℕ} (q : m = m') (p : n = n')
+ (H : div-ℕ m n) (K : div-ℕ m' n') →
+ is-nonzero-ℕ n' → quotient-div-ℕ m n H = pr1 K
+compute-quotient-div-is-nonzero-dividend-ℕ {m} {m'} {n} {zero-ℕ} q p H K f =
+ ex-falso (f refl)
+compute-quotient-div-is-nonzero-dividend-ℕ {m} {m'} {n} {succ-ℕ n'} q p H K f =
+ compute-quotient-div-ℕ q p H K
+
+compute-quotient-div-is-nonzero-divisor-ℕ :
+ {m m' n n' : ℕ} (q : m = m') (p : n = n')
+ (H : div-ℕ m n) (K : div-ℕ m' n') →
+ is-nonzero-ℕ m' → quotient-div-ℕ m n H = pr1 K
+compute-quotient-div-is-nonzero-divisor-ℕ {m} {zero-ℕ} {n} {n'} q p H K f =
+ ex-falso (f refl)
+compute-quotient-div-is-nonzero-divisor-ℕ
+ {m} {succ-ℕ m'} {n} {zero-ℕ} q p H (zero-ℕ , K) f =
+ is-zero-leq-zero-ℕ
+ ( quotient-div-ℕ m n H)
+ ( concatenate-leq-eq-ℕ
+ ( quotient-div-ℕ m n H)
+ ( upper-bound-quotient-div-ℕ m n H)
+ ( p))
+compute-quotient-div-is-nonzero-divisor-ℕ
+ {m} {succ-ℕ m'} {n} {succ-ℕ n'} q p H K f =
+ compute-quotient-div-is-nonzero-dividend-ℕ q p H K (is-nonzero-succ-ℕ n')
+```
+
+### The quotients of a natural number `n` by two natural numbers `c` and `d` are equal if `c` and `d` are equal
+
+Since the quotient is defined in terms of explicit proofs of divisibility, we
+assume arbitrary proofs of dibisibility on both sides.
```agda
-is-prop-div-ℕ : (k x : ℕ) → is-nonzero-ℕ k → is-prop (div-ℕ k x)
-is-prop-div-ℕ k x f = is-prop-map-is-emb (is-emb-right-mul-ℕ k f) x
+eq-quotient-div-eq-divisor-ℕ :
+ (c d n : ℕ) → is-nonzero-ℕ c → c = d → (H : div-ℕ c n) (I : div-ℕ d n) →
+ pr1-div-ℕ c n H = pr1-div-ℕ d n I
+eq-quotient-div-eq-divisor-ℕ c d n N p H I =
+ is-injective-left-mul-ℕ c N
+ ( tr
+ ( λ x → c *ℕ pr1-div-ℕ c n H = x *ℕ pr1-div-ℕ d n I)
+ ( inv p)
+ ( commutative-mul-ℕ c (pr1-div-ℕ c n H) ∙
+ eq-pr1-div-ℕ c n H ∙
+ inv (eq-pr1-div-ℕ d n I) ∙
+ commutative-mul-ℕ (pr1-div-ℕ d n I) d))
+```
+
+### If two natural numbers are equal and one is divisible by a number `d`, then the other is divisible by `d` and their quotients are the same
+
+The first part of the claim was proven above. Since the quotient is defined in
+terms of explicit proofs of divisibility, we assume arbitrary proofs of
+dibisibility on both sides.
+
+```agda
+eq-quotient-div-eq-is-nonzero-divisor-ℕ :
+ {d m n : ℕ} → is-nonzero-ℕ d → m = n → (H : div-ℕ d m) (K : div-ℕ d n) →
+ quotient-div-ℕ d m H = quotient-div-ℕ d n K
+eq-quotient-div-eq-is-nonzero-divisor-ℕ N refl H K =
+ is-injective-right-mul-ℕ _ N
+ ( eq-quotient-div-ℕ _ _ H ∙ inv (eq-quotient-div-ℕ _ _ K))
+
+eq-quotient-div-eq-is-nonzero-ℕ :
+ {d m n : ℕ} → is-nonzero-ℕ m → m = n → (H : div-ℕ d m) (K : div-ℕ d n) →
+ quotient-div-ℕ d m H = quotient-div-ℕ d n K
+eq-quotient-div-eq-is-nonzero-ℕ {zero-ℕ} N refl H K =
+ ex-falso
+ ( N
+ ( inv (eq-quotient-div-ℕ _ _ H) ∙
+ right-zero-law-mul-ℕ (quotient-div-ℕ _ _ H)))
+eq-quotient-div-eq-is-nonzero-ℕ {succ-ℕ d} N refl H K =
+ eq-quotient-div-eq-is-nonzero-divisor-ℕ
+ ( is-nonzero-succ-ℕ d) refl H K
```
### The divisibility relation is a partial order on the natural numbers
+The [poset](order-theory.posets.md) of natural numbers ordered by divisibility
+is defined in
+[`elementary-number-theory.poset-of-natural-numbers-ordered-by-divisibility`](elementary-number-theory.poset-of-natural-numbers-ordered-by-divisibility.md).
+
```agda
refl-div-ℕ : is-reflexive div-ℕ
pr1 (refl-div-ℕ x) = 1
@@ -127,13 +321,16 @@ pr2 (refl-div-ℕ x) = left-unit-law-mul-ℕ x
div-eq-ℕ : (x y : ℕ) → x = y → div-ℕ x y
div-eq-ℕ x .x refl = refl-div-ℕ x
+neq-neg-div-ℕ : (x y : ℕ) → ¬ div-ℕ x y → x ≠ y
+neq-neg-div-ℕ x y H p = H (div-eq-ℕ x y p)
+
antisymmetric-div-ℕ : is-antisymmetric div-ℕ
antisymmetric-div-ℕ zero-ℕ zero-ℕ H K = refl
-antisymmetric-div-ℕ zero-ℕ (succ-ℕ y) (pair k p) K =
+antisymmetric-div-ℕ zero-ℕ (succ-ℕ y) (k , p) K =
inv (right-zero-law-mul-ℕ k) ∙ p
-antisymmetric-div-ℕ (succ-ℕ x) zero-ℕ H (pair l q) =
+antisymmetric-div-ℕ (succ-ℕ x) zero-ℕ H (l , q) =
inv q ∙ right-zero-law-mul-ℕ l
-antisymmetric-div-ℕ (succ-ℕ x) (succ-ℕ y) (pair k p) (pair l q) =
+antisymmetric-div-ℕ (succ-ℕ x) (succ-ℕ y) (k , p) (l , q) =
( inv (left-unit-law-mul-ℕ (succ-ℕ x))) ∙
( ( ap
( _*ℕ (succ-ℕ x))
@@ -145,47 +342,11 @@ antisymmetric-div-ℕ (succ-ℕ x) (succ-ℕ y) (pair k p) (pair l q) =
( p))
transitive-div-ℕ : is-transitive div-ℕ
-pr1 (transitive-div-ℕ x y z (pair l q) (pair k p)) = l *ℕ k
-pr2 (transitive-div-ℕ x y z (pair l q) (pair k p)) =
+pr1 (transitive-div-ℕ x y z (l , q) (k , p)) = l *ℕ k
+pr2 (transitive-div-ℕ x y z (l , q) (k , p)) =
associative-mul-ℕ l k x ∙ (ap (l *ℕ_) p ∙ q)
```
-### If `x` is nonzero and `d | x`, then `d ≤ x`
-
-```agda
-leq-div-succ-ℕ : (d x : ℕ) → div-ℕ d (succ-ℕ x) → leq-ℕ d (succ-ℕ x)
-leq-div-succ-ℕ d x (pair (succ-ℕ k) p) =
- concatenate-leq-eq-ℕ d (leq-mul-ℕ' k d) p
-
-leq-div-ℕ : (d x : ℕ) → is-nonzero-ℕ x → div-ℕ d x → leq-ℕ d x
-leq-div-ℕ d x f H with is-successor-is-nonzero-ℕ f
-... | (pair y refl) = leq-div-succ-ℕ d y H
-
-leq-quotient-div-ℕ :
- (d x : ℕ) → is-nonzero-ℕ x → (H : div-ℕ d x) → leq-ℕ (quotient-div-ℕ d x H) x
-leq-quotient-div-ℕ d x f H =
- leq-div-ℕ (quotient-div-ℕ d x H) x f (div-quotient-div-ℕ d x H)
-
-leq-quotient-div-ℕ' :
- (d x : ℕ) → is-nonzero-ℕ d → (H : div-ℕ d x) → leq-ℕ (quotient-div-ℕ d x H) x
-leq-quotient-div-ℕ' d zero-ℕ f (zero-ℕ , p) = star
-leq-quotient-div-ℕ' d zero-ℕ f (succ-ℕ n , p) =
- f (is-zero-right-is-zero-add-ℕ _ d p)
-leq-quotient-div-ℕ' d (succ-ℕ x) f H =
- leq-quotient-div-ℕ d (succ-ℕ x) (is-nonzero-succ-ℕ x) H
-```
-
-### If `x` is nonzero, if `d | x` and `d ≠ x`, then `d < x`
-
-```agda
-le-div-succ-ℕ :
- (d x : ℕ) → div-ℕ d (succ-ℕ x) → d ≠ succ-ℕ x → le-ℕ d (succ-ℕ x)
-le-div-succ-ℕ d x H f = le-leq-neq-ℕ (leq-div-succ-ℕ d x H) f
-
-le-div-ℕ : (d x : ℕ) → is-nonzero-ℕ x → div-ℕ d x → d ≠ x → le-ℕ d x
-le-div-ℕ d x H K f = le-leq-neq-ℕ (leq-div-ℕ d x H K) f
-```
-
### `1` divides any number
```agda
@@ -219,7 +380,7 @@ div-is-zero-ℕ :
div-is-zero-ℕ k .zero-ℕ refl = div-zero-ℕ k
```
-### `0 | x` implies `x = 0` and `x | 1` implies `x = 1`
+### `0 | x` implies `x = 0`
```agda
is-zero-div-zero-ℕ : (x : ℕ) → div-ℕ zero-ℕ x → is-zero-ℕ x
@@ -227,6 +388,21 @@ is-zero-div-zero-ℕ x H = antisymmetric-div-ℕ x zero-ℕ (div-zero-ℕ x) H
is-zero-is-zero-div-ℕ : (x y : ℕ) → div-ℕ x y → is-zero-ℕ x → is-zero-ℕ y
is-zero-is-zero-div-ℕ .zero-ℕ y d refl = is-zero-div-zero-ℕ y d
+
+is-zero-quotient-div-is-zero-dividend-ℕ :
+ (x y : ℕ) (H : div-ℕ x y) → is-zero-ℕ y → is-zero-ℕ (quotient-div-ℕ x y H)
+is-zero-quotient-div-is-zero-dividend-ℕ x ._ H refl =
+ is-zero-leq-zero-ℕ
+ ( quotient-div-ℕ x 0 H)
+ ( upper-bound-quotient-div-ℕ x 0 H)
+
+is-zero-quotient-div-is-zero-divisor-ℕ :
+ (x y : ℕ) (H : div-ℕ x y) → is-zero-ℕ x → is-zero-ℕ (quotient-div-ℕ x y H)
+is-zero-quotient-div-is-zero-divisor-ℕ x y H p =
+ is-zero-quotient-div-is-zero-dividend-ℕ x y H
+ ( ( inv (eq-quotient-div-ℕ x y H)) ∙
+ ( ap (quotient-div-ℕ x y H *ℕ_) p) ∙
+ ( right-zero-law-mul-ℕ (quotient-div-ℕ x y H)))
```
### Any divisor of a nonzero number is nonzero
@@ -237,6 +413,16 @@ is-nonzero-div-ℕ :
is-nonzero-div-ℕ .zero-ℕ x H K refl = K (is-zero-div-zero-ℕ x H)
```
+### If `d` divides a nonzero number `x`, then the quotient `x/d` is also nonzero
+
+```agda
+is-nonzero-quotient-div-ℕ :
+ {d x : ℕ} (H : div-ℕ d x) →
+ is-nonzero-ℕ x → is-nonzero-ℕ (quotient-div-ℕ d x H)
+is-nonzero-quotient-div-ℕ {d} {x} H K =
+ is-nonzero-quotient-bounded-div-ℕ d x K (bounded-div-div-ℕ d x H)
+```
+
### Any divisor of a number at least `1` is at least `1`
```agda
@@ -246,13 +432,31 @@ leq-one-div-ℕ d x H L =
leq-one-is-nonzero-ℕ d (is-nonzero-div-ℕ d x H (is-nonzero-leq-one-ℕ x L))
```
+### If `d` divides a number `1 ≤ x`, then `1 ≤ x/d`
+
+```agda
+leq-one-quotient-div-ℕ :
+ (d x : ℕ) (H : div-ℕ d x) → leq-ℕ 1 x → leq-ℕ 1 (quotient-div-ℕ d x H)
+leq-one-quotient-div-ℕ d x H K =
+ leq-one-div-ℕ
+ ( quotient-div-ℕ d x H)
+ ( x)
+ ( div-quotient-div-ℕ d x H)
+ ( K)
+
+leq-one-quotient-div-is-nonzero-ℕ :
+ (d x : ℕ) (H : div-ℕ d x) → is-nonzero-ℕ x → leq-ℕ 1 (quotient-div-ℕ d x H)
+leq-one-quotient-div-is-nonzero-ℕ d x H N =
+ leq-one-quotient-div-ℕ d x H (leq-one-is-nonzero-ℕ x N)
+```
+
### If `x < d` and `d | x`, then `x` must be `0`
```agda
is-zero-div-ℕ :
(d x : ℕ) → le-ℕ x d → div-ℕ d x → is-zero-ℕ x
is-zero-div-ℕ d zero-ℕ H D = refl
-is-zero-div-ℕ d (succ-ℕ x) H (pair (succ-ℕ k) p) =
+is-zero-div-ℕ d (succ-ℕ x) H (succ-ℕ k , p) =
ex-falso
( contradiction-le-ℕ
( succ-ℕ x) d H
@@ -260,18 +464,151 @@ is-zero-div-ℕ d (succ-ℕ x) H (pair (succ-ℕ k) p) =
( leq-add-ℕ' d (k *ℕ d)) p))
```
+### `a/a = 1`
+
+```agda
+is-idempotent-quotient-div-ℕ :
+ (a : ℕ) → is-nonzero-ℕ a → (H : div-ℕ a a) → is-one-ℕ (quotient-div-ℕ a a H)
+is-idempotent-quotient-div-ℕ zero-ℕ nz (u , p) = ex-falso (nz refl)
+is-idempotent-quotient-div-ℕ (succ-ℕ a) nz (u , p) =
+ is-one-is-left-unit-mul-ℕ u a p
+```
+
+### If `x` is nonzero, if `d | x` and `d ≠ x`, then `d < x`
+
+```agda
+le-div-succ-ℕ :
+ (d x : ℕ) → div-ℕ d (succ-ℕ x) → d ≠ succ-ℕ x → le-ℕ d (succ-ℕ x)
+le-div-succ-ℕ d x H f = le-leq-neq-ℕ (leq-div-succ-ℕ d x H) f
+
+le-div-ℕ : (d x : ℕ) → is-nonzero-ℕ x → div-ℕ d x → d ≠ x → le-ℕ d x
+le-div-ℕ d x H K f = le-leq-neq-ℕ (leq-div-ℕ d x H K) f
+```
+
### If `x` divides `y` then `x` divides any multiple of `y`
```agda
div-mul-ℕ :
(k x y : ℕ) → div-ℕ x y → div-ℕ x (k *ℕ y)
-div-mul-ℕ k x y H =
- transitive-div-ℕ x y (k *ℕ y) (pair k refl) H
+pr1 (div-mul-ℕ k x y H) = k *ℕ quotient-div-ℕ x y H
+pr2 (div-mul-ℕ k x y H) =
+ associative-mul-ℕ k (quotient-div-ℕ x y H) x ∙
+ ap (k *ℕ_) (eq-quotient-div-ℕ x y H)
div-mul-ℕ' :
(k x y : ℕ) → div-ℕ x y → div-ℕ x (y *ℕ k)
div-mul-ℕ' k x y H =
tr (div-ℕ x) (commutative-mul-ℕ k y) (div-mul-ℕ k x y H)
+
+compute-quotient-div-mul-ℕ :
+ (k x y : ℕ) (H : div-ℕ x y) (K : div-ℕ x (k *ℕ y)) →
+ quotient-div-ℕ x (k *ℕ y) K = k *ℕ quotient-div-ℕ x y H
+compute-quotient-div-mul-ℕ k zero-ℕ y H K =
+ is-zero-quotient-div-is-zero-divisor-ℕ 0 (k *ℕ y) K refl ∙
+ inv (right-zero-law-mul-ℕ k) ∙
+ ap (k *ℕ_) (inv (is-zero-quotient-div-is-zero-divisor-ℕ 0 y H refl))
+compute-quotient-div-mul-ℕ k (succ-ℕ x) y H K =
+ compute-quotient-div-is-nonzero-divisor-ℕ
+ ( refl)
+ ( refl)
+ ( K)
+ ( div-mul-ℕ k (succ-ℕ x) y H)
+ ( is-nonzero-succ-ℕ x)
+
+compute-quotient-div-mul-ℕ' :
+ (k x y : ℕ) (H : div-ℕ x y) (K : div-ℕ x (y *ℕ k)) →
+ quotient-div-ℕ x (y *ℕ k) K = quotient-div-ℕ x y H *ℕ k
+compute-quotient-div-mul-ℕ' k x y H K =
+ ( compute-quotient-div-ℕ refl
+ ( commutative-mul-ℕ y k)
+ ( K)
+ ( concatenate-div-eq-ℕ K (commutative-mul-ℕ y k))) ∙
+ ( compute-quotient-div-mul-ℕ k x y H
+ ( concatenate-div-eq-ℕ K (commutative-mul-ℕ y k))) ∙
+ ( commutative-mul-ℕ k (quotient-div-ℕ x y H))
+```
+
+### Divisibility is decidable
+
+```agda
+is-decidable-div-ℕ :
+ (m n : ℕ) → is-decidable (div-ℕ m n)
+is-decidable-div-ℕ m n =
+ is-decidable-iff
+ ( div-bounded-div-ℕ m n)
+ ( bounded-div-div-ℕ m n)
+ ( is-decidable-bounded-div-ℕ m n)
+```
+
+### Divisibility is a property except at `(0,0)`
+
+```agda
+is-prop-div-ℕ :
+ (k x : ℕ) → is-nonzero-ℕ k + is-nonzero-ℕ x → is-prop (div-ℕ k x)
+is-prop-div-ℕ k x (inl H) = is-prop-map-is-emb (is-emb-right-mul-ℕ k H) x
+is-prop-div-ℕ zero-ℕ x (inr H) =
+ is-prop-is-proof-irrelevant
+ ( λ (q , p) → ex-falso (H (inv p ∙ right-zero-law-mul-ℕ q)))
+is-prop-div-ℕ (succ-ℕ k) x (inr H) =
+ is-prop-map-is-emb (is-emb-right-mul-ℕ (succ-ℕ k) (is-nonzero-succ-ℕ k)) x
+
+div-ℕ-Decidable-Prop : (d x : ℕ) → is-nonzero-ℕ d → Decidable-Prop lzero
+pr1 (div-ℕ-Decidable-Prop d x H) = div-ℕ d x
+pr1 (pr2 (div-ℕ-Decidable-Prop d x H)) = is-prop-div-ℕ d x (inl H)
+pr2 (pr2 (div-ℕ-Decidable-Prop d x H)) = is-decidable-div-ℕ d x
+```
+
+### If `b` divides `a` and `c` divides `b`, then `a/b · b/c = a/c`
+
+We use our convention that $0/0 = 0$ to avoid the hypothesis that $c$ is nonzero.
+
+```agda
+simplify-mul-quotient-div-ℕ :
+ (a b c : ℕ) →
+ (H : div-ℕ b a) (K : div-ℕ c b) (L : div-ℕ c a) →
+ quotient-div-ℕ b a H *ℕ quotient-div-ℕ c b K = quotient-div-ℕ c a L
+simplify-mul-quotient-div-ℕ a b zero-ℕ H K L =
+ ( ap
+ ( quotient-div-ℕ b a H *ℕ_)
+ ( is-zero-quotient-div-is-zero-divisor-ℕ 0 b K refl)) ∙
+ ( right-zero-law-mul-ℕ (quotient-div-ℕ b a H)) ∙
+ ( inv (is-zero-quotient-div-is-zero-divisor-ℕ 0 a L refl))
+simplify-mul-quotient-div-ℕ a b (succ-ℕ c) H K L =
+ is-injective-right-mul-ℕ (succ-ℕ c) (is-nonzero-succ-ℕ c)
+ ( equational-reasoning
+ (a/b *ℕ b/c+1) *ℕ succ-ℕ c
+ = a/b *ℕ (b/c+1 *ℕ succ-ℕ c)
+ by associative-mul-ℕ a/b b/c+1 (succ-ℕ c)
+ = a/b *ℕ b
+ by ap (a/b *ℕ_) (eq-quotient-div-ℕ (succ-ℕ c) b K)
+ = a
+ by eq-quotient-div-ℕ b a H
+ = a/c+1 *ℕ succ-ℕ c
+ by inv (eq-quotient-div-ℕ (succ-ℕ c) a L))
+ where
+ a/b : ℕ
+ a/b = quotient-div-ℕ b a H
+ b/c+1 : ℕ
+ b/c+1 = quotient-div-ℕ (succ-ℕ c) b K
+ a/c+1 : ℕ
+ a/c+1 = quotient-div-ℕ (succ-ℕ c) a L
+```
+
+### Suppose `b | a` and `c | b`. If `d` divides `b/c` then `d` divides `a/c`
+
+```agda
+div-quotient-div-div-quotient-div-ℕ :
+ {a b c d : ℕ} (H : div-ℕ b a) (K : div-ℕ c b) (L : div-ℕ c a) →
+ div-ℕ d (quotient-div-ℕ c b K) → div-ℕ d (quotient-div-ℕ c a L)
+div-quotient-div-div-quotient-div-ℕ {a} {b} {c} {d} H K L M =
+ tr
+ ( div-ℕ d)
+ ( simplify-mul-quotient-div-ℕ a b c H K L)
+ ( div-mul-ℕ
+ ( quotient-div-ℕ b a H)
+ ( d)
+ ( quotient-div-ℕ c b K)
+ ( M))
```
### A 3-for-2 property of division with respect to addition
@@ -279,19 +616,20 @@ div-mul-ℕ' k x y H =
```agda
div-add-ℕ :
(d x y : ℕ) → div-ℕ d x → div-ℕ d y → div-ℕ d (x +ℕ y)
-pr1 (div-add-ℕ d x y (pair n p) (pair m q)) = n +ℕ m
-pr2 (div-add-ℕ d x y (pair n p) (pair m q)) =
+pr1 (div-add-ℕ d x y (n , p) (m , q)) = n +ℕ m
+pr2 (div-add-ℕ d x y (n , p) (m , q)) =
( right-distributive-mul-add-ℕ n m d) ∙
( ap-add-ℕ p q)
div-left-summand-ℕ :
(d x y : ℕ) → div-ℕ d y → div-ℕ d (x +ℕ y) → div-ℕ d x
-div-left-summand-ℕ zero-ℕ x y (pair m q) (pair n p) =
- pair zero-ℕ
+div-left-summand-ℕ zero-ℕ x y (m , q) (n , p) =
+ pair
+ ( zero-ℕ)
( ( inv (right-zero-law-mul-ℕ n)) ∙
( p ∙ (ap (x +ℕ_) ((inv q) ∙ (right-zero-law-mul-ℕ m)))))
-pr1 (div-left-summand-ℕ (succ-ℕ d) x y (pair m q) (pair n p)) = dist-ℕ m n
-pr2 (div-left-summand-ℕ (succ-ℕ d) x y (pair m q) (pair n p)) =
+pr1 (div-left-summand-ℕ (succ-ℕ d) x y (m , q) (n , p)) = dist-ℕ m n
+pr2 (div-left-summand-ℕ (succ-ℕ d) x y (m , q) (n , p)) =
is-injective-right-add-ℕ (m *ℕ (succ-ℕ d))
( ( inv
( ( right-distributive-mul-add-ℕ m (dist-ℕ m n) (succ-ℕ d)) ∙
@@ -301,7 +639,7 @@ pr2 (div-left-summand-ℕ (succ-ℕ d) x y (pair m q) (pair n p)) =
( ( ap
( _*ℕ (succ-ℕ d))
( is-additive-right-inverse-dist-ℕ m n
- ( reflects-order-mul-ℕ d m n
+ ( reflects-order-mul-succ-ℕ d m n
( concatenate-eq-leq-eq-ℕ q
( leq-add-ℕ' y x)
( inv p))))) ∙
@@ -324,40 +662,62 @@ is-one-div-ℕ x y H K = is-one-div-one-ℕ x (div-right-summand-ℕ x y 1 H K)
```agda
preserves-div-mul-ℕ :
+ (k l x y : ℕ) → div-ℕ k x → div-ℕ l y → div-ℕ (k *ℕ l) (x *ℕ y)
+pr1 (preserves-div-mul-ℕ k l x y (q , α) (p , β)) = q *ℕ p
+pr2 (preserves-div-mul-ℕ k l x y (q , α) (p , β)) =
+ interchange-law-mul-mul-ℕ q p k l ∙ ap-mul-ℕ α β
+
+preserves-div-left-mul-ℕ :
(k x y : ℕ) → div-ℕ x y → div-ℕ (k *ℕ x) (k *ℕ y)
-pr1 (preserves-div-mul-ℕ k x y (pair q p)) = q
-pr2 (preserves-div-mul-ℕ k x y (pair q p)) =
- ( inv (associative-mul-ℕ q k x)) ∙
- ( ( ap (_*ℕ x) (commutative-mul-ℕ q k)) ∙
- ( ( associative-mul-ℕ k q x) ∙
- ( ap (k *ℕ_) p)))
+preserves-div-left-mul-ℕ k x y =
+ preserves-div-mul-ℕ k x k y (refl-div-ℕ k)
+
+preserves-div-right-mul-ℕ :
+ (k x y : ℕ) → div-ℕ x y → div-ℕ (x *ℕ k) (y *ℕ k)
+preserves-div-right-mul-ℕ k x y H =
+ preserves-div-mul-ℕ x k y k H (refl-div-ℕ k)
```
### Multiplication by a nonzero number reflects divisibility
```agda
-reflects-div-mul-ℕ :
- (k x y : ℕ) → is-nonzero-ℕ k → div-ℕ (k *ℕ x) (k *ℕ y) → div-ℕ x y
-pr1 (reflects-div-mul-ℕ k x y H (pair q p)) = q
-pr2 (reflects-div-mul-ℕ k x y H (pair q p)) =
- is-injective-left-mul-ℕ k H
- ( ( inv (associative-mul-ℕ k q x)) ∙
- ( ( ap (_*ℕ x) (commutative-mul-ℕ k q)) ∙
- ( ( associative-mul-ℕ q k x) ∙
- ( p))))
-```
-
-### If a nonzero number `d` divides `y`, then `dx` divides `y` if and only if `x` divides the quotient `y/d`
+reflects-div-left-mul-ℕ :
+ (m a b : ℕ) → is-nonzero-ℕ m → div-ℕ (m *ℕ a) (m *ℕ b) → div-ℕ a b
+pr1 (reflects-div-left-mul-ℕ m a b H K) = quotient-div-ℕ (m *ℕ a) (m *ℕ b) K
+pr2 (reflects-div-left-mul-ℕ m a b H K) =
+ is-injective-left-mul-ℕ m H
+ ( ( left-swap-mul-ℕ m
+ ( quotient-div-ℕ (m *ℕ a) (m *ℕ b) K)
+ ( a)) ∙
+ ( eq-quotient-div-ℕ (m *ℕ a) (m *ℕ b) K))
+
+reflects-div-right-mul-ℕ :
+ (m a b : ℕ) → is-nonzero-ℕ m → div-ℕ (a *ℕ m) (b *ℕ m) → div-ℕ a b
+reflects-div-right-mul-ℕ m a b H K =
+ reflects-div-left-mul-ℕ m a b H
+ ( concatenate-eq-div-eq-ℕ
+ ( commutative-mul-ℕ m a)
+ ( K)
+ ( commutative-mul-ℕ b m))
+```
+
+### If `d` divides `y`, then `dx` divides `y` if and only if `x` divides the quotient `y/d`
+
+This logical equivalence holds for all integers, using the convention that `0/0 = 0`.
```agda
div-quotient-div-div-ℕ :
- (x y d : ℕ) (H : div-ℕ d y) → is-nonzero-ℕ d →
+ (x y d : ℕ) (H : div-ℕ d y) →
div-ℕ (d *ℕ x) y → div-ℕ x (quotient-div-ℕ d y H)
-div-quotient-div-div-ℕ x y d H f K =
- reflects-div-mul-ℕ d x
- ( quotient-div-ℕ d y H)
- ( f)
- ( tr (div-ℕ (d *ℕ x)) (inv (eq-quotient-div-ℕ' d y H)) K)
+div-quotient-div-div-ℕ x y zero-ℕ H K =
+ div-is-zero-ℕ x
+ ( quotient-div-ℕ 0 y H)
+ ( is-zero-quotient-div-is-zero-divisor-ℕ 0 y H refl)
+div-quotient-div-div-ℕ x y (succ-ℕ d) H K =
+ reflects-div-left-mul-ℕ (succ-ℕ d) x
+ ( quotient-div-ℕ (succ-ℕ d) y H)
+ ( is-nonzero-succ-ℕ d)
+ ( tr (div-ℕ (succ-ℕ d *ℕ x)) (inv (eq-quotient-div-ℕ' (succ-ℕ d) y H)) K)
div-div-quotient-div-ℕ :
(x y d : ℕ) (H : div-ℕ d y) →
@@ -366,117 +726,29 @@ div-div-quotient-div-ℕ x y d H K =
tr
( div-ℕ (d *ℕ x))
( eq-quotient-div-ℕ' d y H)
- ( preserves-div-mul-ℕ d x (quotient-div-ℕ d y H) K)
-```
-
-### If `d` divides a nonzero number `x`, then the quotient `x/d` is also nonzero
-
-```agda
-is-nonzero-quotient-div-ℕ :
- {d x : ℕ} (H : div-ℕ d x) →
- is-nonzero-ℕ x → is-nonzero-ℕ (quotient-div-ℕ d x H)
-is-nonzero-quotient-div-ℕ {d} {.(k *ℕ d)} (pair k refl) =
- is-nonzero-left-factor-mul-ℕ k d
-```
-
-### If `d` divides a number `1 ≤ x`, then `1 ≤ x/d`
-
-```agda
-leq-one-quotient-div-ℕ :
- (d x : ℕ) (H : div-ℕ d x) → leq-ℕ 1 x → leq-ℕ 1 (quotient-div-ℕ d x H)
-leq-one-quotient-div-ℕ d x H K =
- leq-one-div-ℕ
- ( quotient-div-ℕ d x H)
- ( x)
- ( div-quotient-div-ℕ d x H)
- ( K)
-```
-
-### `a/a = 1`
-
-```agda
-is-idempotent-quotient-div-ℕ :
- (a : ℕ) → is-nonzero-ℕ a → (H : div-ℕ a a) → is-one-ℕ (quotient-div-ℕ a a H)
-is-idempotent-quotient-div-ℕ zero-ℕ nz (u , p) = ex-falso (nz refl)
-is-idempotent-quotient-div-ℕ (succ-ℕ a) nz (u , p) =
- is-one-is-left-unit-mul-ℕ u a p
-```
-
-### If `b` divides `a` and `c` divides `b` and `c` is nonzero, then `a/b · b/c = a/c`
-
-```agda
-simplify-mul-quotient-div-ℕ :
- {a b c : ℕ} → is-nonzero-ℕ c →
- (H : div-ℕ b a) (K : div-ℕ c b) (L : div-ℕ c a) →
- ( (quotient-div-ℕ b a H) *ℕ (quotient-div-ℕ c b K)) =
- ( quotient-div-ℕ c a L)
-simplify-mul-quotient-div-ℕ {a} {b} {c} nz H K L =
- is-injective-right-mul-ℕ c nz
- ( equational-reasoning
- (a/b *ℕ b/c) *ℕ c
- = a/b *ℕ (b/c *ℕ c)
- by associative-mul-ℕ a/b b/c c
- = a/b *ℕ b
- by ap (a/b *ℕ_) (eq-quotient-div-ℕ c b K)
- = a
- by eq-quotient-div-ℕ b a H
- = a/c *ℕ c
- by inv (eq-quotient-div-ℕ c a L))
- where
- a/b : ℕ
- a/b = quotient-div-ℕ b a H
- b/c : ℕ
- b/c = quotient-div-ℕ c b K
- a/c : ℕ
- a/c = quotient-div-ℕ c a L
-```
+ ( preserves-div-left-mul-ℕ d x (quotient-div-ℕ d y H) K)
-### If `d | a` and `d` is nonzero, then `x | a/d` if and only if `xd | a`
+div-div-quotient-div-ℕ' :
+ (x y d : ℕ) (H : div-ℕ d y) →
+ ((K : div-ℕ d y) → div-ℕ x (quotient-div-ℕ d y K)) → div-ℕ (d *ℕ x) y
+div-div-quotient-div-ℕ' x y d H K =
+ div-div-quotient-div-ℕ x y d H (K H)
-```agda
simplify-div-quotient-div-ℕ :
- {a d x : ℕ} → is-nonzero-ℕ d → (H : div-ℕ d a) →
- (div-ℕ x (quotient-div-ℕ d a H)) ↔ (div-ℕ (x *ℕ d) a)
-pr1 (pr1 (simplify-div-quotient-div-ℕ nz H) (u , p)) = u
-pr2 (pr1 (simplify-div-quotient-div-ℕ {a} {d} {x} nz H) (u , p)) =
- equational-reasoning
- u *ℕ (x *ℕ d)
- = (u *ℕ x) *ℕ d
- by inv (associative-mul-ℕ u x d)
- = (quotient-div-ℕ d a H) *ℕ d
- by ap (_*ℕ d) p
- = a
- by eq-quotient-div-ℕ d a H
-pr1 (pr2 (simplify-div-quotient-div-ℕ nz H) (u , p)) = u
-pr2 (pr2 (simplify-div-quotient-div-ℕ {a} {d} {x} nz H) (u , p)) =
- is-injective-right-mul-ℕ d nz
- ( equational-reasoning
- (u *ℕ x) *ℕ d
- = u *ℕ (x *ℕ d)
- by associative-mul-ℕ u x d
- = a
- by p
- = (quotient-div-ℕ d a H) *ℕ d
- by inv (eq-quotient-div-ℕ d a H))
-```
-
-### Suppose `H : b | a` and `K : c | b`, where `c` is nonzero. If `d` divides `b/c` then `d` divides `a/c`
-
-```agda
-div-quotient-div-div-quotient-div-ℕ :
- {a b c d : ℕ} → is-nonzero-ℕ c → (H : div-ℕ b a)
- (K : div-ℕ c b) (L : div-ℕ c a) →
- div-ℕ d (quotient-div-ℕ c b K) →
- div-ℕ d (quotient-div-ℕ c a L)
-div-quotient-div-div-quotient-div-ℕ {a} {b} {c} {d} nz H K L M =
- tr
- ( div-ℕ d)
- ( simplify-mul-quotient-div-ℕ nz H K L)
- ( div-mul-ℕ
- ( quotient-div-ℕ b a H)
- ( d)
- ( quotient-div-ℕ c b K)
- ( M))
+ {a d x : ℕ} (H : div-ℕ d a) →
+ div-ℕ x (quotient-div-ℕ d a H) ↔ div-ℕ (d *ℕ x) a
+pr1 (simplify-div-quotient-div-ℕ {a} {d} {x} H) =
+ div-div-quotient-div-ℕ x a d H
+pr2 (simplify-div-quotient-div-ℕ {a} {d} {x} H) =
+ div-quotient-div-div-ℕ x a d H
+
+simplify-div-quotient-div-ℕ' :
+ {a d x : ℕ} (H : div-ℕ d a) →
+ div-ℕ x (quotient-div-ℕ d a H) ↔ div-ℕ (x *ℕ d) a
+pr1 (simplify-div-quotient-div-ℕ' {a} {d} {x} H) =
+ tr (λ u → div-ℕ u a) (commutative-mul-ℕ d x) ∘ div-div-quotient-div-ℕ x a d H
+pr2 (simplify-div-quotient-div-ℕ' {a} {d} {x} H) =
+ div-quotient-div-div-ℕ x a d H ∘ tr (λ u → div-ℕ u a) (commutative-mul-ℕ x d)
```
### If `x` is nonzero and `d | x`, then `x/d = 1` if and only if `d = x`
@@ -489,7 +761,8 @@ is-one-quotient-div-ℕ d .d f H refl = is-idempotent-quotient-div-ℕ d f H
eq-is-one-quotient-div-ℕ :
(d x : ℕ) → (H : div-ℕ d x) → is-one-ℕ (quotient-div-ℕ d x H) → d = x
-eq-is-one-quotient-div-ℕ d x (.1 , q) refl = inv (left-unit-law-mul-ℕ d) ∙ q
+eq-is-one-quotient-div-ℕ d (succ-ℕ x) (.1 , q) refl =
+ inv (left-unit-law-mul-ℕ d) ∙ q
```
### If `x` is nonzero and `d | x`, then `x/d = x` if and only if `d = 1`
@@ -497,21 +770,26 @@ eq-is-one-quotient-div-ℕ d x (.1 , q) refl = inv (left-unit-law-mul-ℕ d) ∙
```agda
compute-quotient-div-is-one-ℕ :
(d x : ℕ) → (H : div-ℕ d x) → is-one-ℕ d → quotient-div-ℕ d x H = x
-compute-quotient-div-is-one-ℕ .1 x (u , q) refl =
+compute-quotient-div-is-one-ℕ .1 zero-ℕ H refl = refl
+compute-quotient-div-is-one-ℕ .1 (succ-ℕ x) (u , q) refl =
inv (right-unit-law-mul-ℕ u) ∙ q
is-one-divisor-ℕ :
(d x : ℕ) → is-nonzero-ℕ x → (H : div-ℕ d x) →
quotient-div-ℕ d x H = x → is-one-ℕ d
-is-one-divisor-ℕ d x f (.x , q) refl =
- is-injective-left-mul-ℕ x f (q ∙ inv (right-unit-law-mul-ℕ x))
+is-one-divisor-ℕ d zero-ℕ N H p = ex-falso (N refl)
+is-one-divisor-ℕ d (succ-ℕ x) N (.(succ-ℕ x) , q) refl =
+ is-injective-left-mul-ℕ
+ ( succ-ℕ x)
+ ( N)
+ ( q ∙ inv (right-unit-law-mul-ℕ (succ-ℕ x)))
```
### If `x` is nonzero and `d | x` is a nontrivial divisor, then `x/d < x`
```agda
le-quotient-div-ℕ :
- (d x : ℕ) → is-nonzero-ℕ x → (H : div-ℕ d x) → ¬ (is-one-ℕ d) →
+ (d x : ℕ) → is-nonzero-ℕ x → (H : div-ℕ d x) → ¬ is-one-ℕ d →
le-ℕ (quotient-div-ℕ d x H) x
le-quotient-div-ℕ d x f H g =
map-left-unit-law-coproduct-is-empty
@@ -521,5 +799,14 @@ le-quotient-div-ℕ d x f H g =
( eq-or-le-leq-ℕ
( quotient-div-ℕ d x H)
( x)
- ( leq-quotient-div-ℕ d x f H))
+ ( upper-bound-quotient-div-ℕ d x H))
```
+
+## See also
+
+- [Bounded divisibility of natural numbers](elementary-number-theory.bounded-divisibility-natural-numbers.md)
+- [Greatest common divisors of natural numbers](elementary-number-theory.greatest-common-divisors-natural-numbers.md)
+- [Nontrivial divisors of natural numbers](elementary-number-theory.nontrivial-divisors-natural-numbers.md)
+- [Prime divisors](elementary-number-theory.prime-divisors-natural-numbers.md)
+- [Proper divisors of natural numbers](elementary-number-theory.proper-divisors-natural-numbers.md)
+- [The poset of natural numbers ordered by divisibility](elementary-number-theory.poset-of-natural-numbers-ordered-by-divisibility.md)
diff --git a/src/elementary-number-theory/equality-natural-numbers.lagda.md b/src/elementary-number-theory/equality-natural-numbers.lagda.md
index bb335e5e58..cafef33b84 100644
--- a/src/elementary-number-theory/equality-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/equality-natural-numbers.lagda.md
@@ -19,6 +19,7 @@ open import foundation.equivalences
open import foundation.function-types
open import foundation.fundamental-theorem-of-identity-types
open import foundation.identity-types
+open import foundation.injective-maps
open import foundation.propositions
open import foundation.set-truncations
open import foundation.sets
@@ -27,6 +28,7 @@ open import foundation.universe-levels
open import foundation-core.decidable-propositions
open import foundation-core.discrete-types
+open import foundation-core.embeddings
open import foundation-core.torsorial-type-families
```
@@ -132,8 +134,8 @@ is-decidable-is-zero-ℕ n = has-decidable-equality-ℕ n zero-ℕ
is-decidable-is-zero-ℕ' : (n : ℕ) → is-decidable (is-zero-ℕ' n)
is-decidable-is-zero-ℕ' n = has-decidable-equality-ℕ zero-ℕ n
-is-decidable-is-nonzero-ℕ : (n : ℕ) → is-decidable (is-nonzero-ℕ n)
-is-decidable-is-nonzero-ℕ n =
+is-decidable-zero-is-nonzero-ℕ : (n : ℕ) → is-decidable (is-nonzero-ℕ n)
+is-decidable-zero-is-nonzero-ℕ n =
is-decidable-neg (is-decidable-is-zero-ℕ n)
is-decidable-is-one-ℕ : (n : ℕ) → is-decidable (is-one-ℕ n)
@@ -179,3 +181,11 @@ is-equiv-Eq-eq-ℕ {m} {n} =
equiv-unit-trunc-ℕ-Set : ℕ ≃ type-trunc-Set ℕ
equiv-unit-trunc-ℕ-Set = equiv-unit-trunc-Set ℕ-Set
```
+
+### The successor embedding
+
+```agda
+succ-emb-ℕ : ℕ ↪ ℕ
+pr1 succ-emb-ℕ = succ-ℕ
+pr2 succ-emb-ℕ = is-emb-is-injective is-set-ℕ is-injective-succ-ℕ
+```
diff --git a/src/elementary-number-theory/euclid-mullin-sequence.lagda.md b/src/elementary-number-theory/euclid-mullin-sequence.lagda.md
index be53df7a65..921c25be1b 100644
--- a/src/elementary-number-theory/euclid-mullin-sequence.lagda.md
+++ b/src/elementary-number-theory/euclid-mullin-sequence.lagda.md
@@ -7,8 +7,8 @@ module elementary-number-theory.euclid-mullin-sequence where
Imports
```agda
-open import elementary-number-theory.fundamental-theorem-of-arithmetic
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.nontrivial-divisors-natural-numbers
open import elementary-number-theory.products-of-natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
open import elementary-number-theory.strong-induction-natural-numbers
diff --git a/src/elementary-number-theory/euclidean-division-natural-numbers.lagda.md b/src/elementary-number-theory/euclidean-division-natural-numbers.lagda.md
index 1ef17f8247..075827b7ed 100644
--- a/src/elementary-number-theory/euclidean-division-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/euclidean-division-natural-numbers.lagda.md
@@ -10,6 +10,7 @@ module elementary-number-theory.euclidean-division-natural-numbers where
open import elementary-number-theory.addition-natural-numbers
open import elementary-number-theory.congruence-natural-numbers
open import elementary-number-theory.distance-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.modular-arithmetic-standard-finite-types
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
@@ -28,55 +29,42 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-Euclidean division is division with remainder, i.e., the Euclidean division of
-`n` by `d` is the largest natural number `k ≤ n/d`, and the remainder is the
-unique natural number `r < d` such that `kd + r = n`.
+{{#concept "Euclidean division" Agda=euclidean-division-ℕ}} is a binary
+operation on the [natural numbers](elementary-number-theory.natural-numbers.md)
+that returns the division with remainder. In other words, the Euclidean division
+of `n` by `d` gives the unique pair of natural numbers `q` and `r < d` such that
+the identification `qd + r = n` holds.
+
+There are several ways of specifying Euclidean division. Since we have already
+defined the
+[congruence relations](elementary-number-theory.congruence-natural-numbers.md)
+independently, we can define the Euclidean division of a natural number `n` by
+`d` as the data consisting of:
+
+- A natural number `r`, called the
+ {{#concept "remainder" Disambiguation="Euclidean division of natural numbers" Agda=remainder-euclidean-division-ℕ}}
+- A proof that `r` is congruent to `n` modulo `d`
+- A proof that if `d ≠ 0`, then `r < d`.
+
+Given that `r` is congruent to `n` modulo `d` we obtain a number `q` such that
+`d * q = dist-ℕ r x`, where `dist-ℕ` is the
+[distance function](elementary-number-theory.distance-natural-numbers.md). This
+number `q` is the
+{{#concept "quotient" Disambiguation="Euclidean divistion of naturalnumbers" Agda=quotient-euclidean-division-ℕ}}
+after Euclidean division.
+
+Note that if `d = 0`, then the unique natural number that is congruent to `n`
+modulo `d` is the number `n` itself. The type of this data is therefore always
+[contractible](foundation-core.contractible-types.md), even in the case
+`d = 0`.
## Definitions
-### Euclidean division via an array of natural numbers
-
-The following definition produces for each `k : ℕ` a sequence of sequences as
-follows:
-
-```text
- This is column k
- ↓
- 0,…,0,0,0,0,0,0,0,… -- The sequence at row 0 is the constant sequence
- 1,0,…,0,0,0,0,0,0,… -- We append 1's at the start
- ⋮
- 1,…,1,0,…,0,0,0,0,… -- This is row k+1
- 2,1,…,1,0,0,0,0,0,… -- After k+1 steps we append 2's at the start
- ⋮
- 2,…,2,1,…,1,0,…,0,… -- This is row 2(k+1)
- 3,2,…,2,1,…,1,0,0,… -- After another k+1 steps we append 3's at the start
- ⋮
-```
-
-This produces an array of natural numbers. We find the quotient of the euclidean
-division of `n` by `k+1` in the `k`-th column of the `n`-th row of this array.
-We will arbitrarily set the quotient of the euclidean division of `n` by `0` to
-`0` in this definition.
-
-```agda
-array-quotient-euclidean-division-ℕ : ℕ → ℕ → ℕ → ℕ
-array-quotient-euclidean-division-ℕ k zero-ℕ m = zero-ℕ
-array-quotient-euclidean-division-ℕ k (succ-ℕ n) zero-ℕ =
- succ-ℕ (array-quotient-euclidean-division-ℕ k n k)
-array-quotient-euclidean-division-ℕ k (succ-ℕ n) (succ-ℕ m) =
- array-quotient-euclidean-division-ℕ k n m
-
-quotient-euclidean-division-ℕ' : ℕ → ℕ → ℕ
-quotient-euclidean-division-ℕ' zero-ℕ n = zero-ℕ
-quotient-euclidean-division-ℕ' (succ-ℕ k) n =
- array-quotient-euclidean-division-ℕ k n k
-```
-
### Euclidean division via modular arithmetic
```agda
euclidean-division-ℕ :
- (k x : ℕ) → Σ ℕ (λ r → (cong-ℕ k x r) × (is-nonzero-ℕ k → le-ℕ r k))
+ (k x : ℕ) → Σ ℕ (λ r → (x ≡ r mod-ℕ k) × (is-nonzero-ℕ k → le-ℕ r k))
pr1 (euclidean-division-ℕ zero-ℕ x) = x
pr1 (pr2 (euclidean-division-ℕ zero-ℕ x)) = refl-cong-ℕ zero-ℕ x
pr2 (pr2 (euclidean-division-ℕ zero-ℕ x)) f = ex-falso (f refl)
@@ -95,7 +83,7 @@ remainder-euclidean-division-ℕ k x =
pr1 (euclidean-division-ℕ k x)
cong-euclidean-division-ℕ :
- (k x : ℕ) → cong-ℕ k x (remainder-euclidean-division-ℕ k x)
+ (k x : ℕ) → x ≡ remainder-euclidean-division-ℕ k x mod-ℕ k
cong-euclidean-division-ℕ k x =
pr1 (pr2 (euclidean-division-ℕ k x))
@@ -110,17 +98,16 @@ quotient-euclidean-division-ℕ k x =
eq-quotient-euclidean-division-ℕ :
(k x : ℕ) →
- ( (quotient-euclidean-division-ℕ k x) *ℕ k) =
+ ( quotient-euclidean-division-ℕ k x *ℕ k) =
( dist-ℕ x (remainder-euclidean-division-ℕ k x))
eq-quotient-euclidean-division-ℕ k x =
pr2 (cong-euclidean-division-ℕ k x)
eq-euclidean-division-ℕ :
(k x : ℕ) →
- ( add-ℕ
- ( (quotient-euclidean-division-ℕ k x) *ℕ k)
- ( remainder-euclidean-division-ℕ k x)) =
- ( x)
+ quotient-euclidean-division-ℕ k x *ℕ k +ℕ
+ remainder-euclidean-division-ℕ k x =
+ x
eq-euclidean-division-ℕ zero-ℕ x =
( inv
( ap
@@ -129,7 +116,7 @@ eq-euclidean-division-ℕ zero-ℕ x =
( left-unit-law-add-ℕ x)
eq-euclidean-division-ℕ (succ-ℕ k) x =
( ap
- ( _+ℕ (remainder-euclidean-division-ℕ (succ-ℕ k) x))
+ ( _+ℕ remainder-euclidean-division-ℕ (succ-ℕ k) x)
( ( pr2 (cong-euclidean-division-ℕ (succ-ℕ k) x)) ∙
( symmetric-dist-ℕ x
( remainder-euclidean-division-ℕ (succ-ℕ k) x)))) ∙
@@ -137,9 +124,55 @@ eq-euclidean-division-ℕ (succ-ℕ k) x =
( leq-nat-mod-succ-ℕ k x))
```
+### Euclidean division via an array of natural numbers
+
+The following definition produces for each `k : ℕ` a sequence of sequences as
+follows:
+
+```text
+ This is column k
+ ↓
+ 0,…,0,0,0,0,0,0,0,… -- The sequence at row 0 is the constant sequence
+ 1,0,…,0,0,0,0,0,0,… -- We append 1's at the start
+ ⋮
+ 1,…,1,0,…,0,0,0,0,… -- This is row k+1
+ 2,1,…,1,0,0,0,0,0,… -- After k+1 steps we append 2's at the start
+ ⋮
+ 2,…,2,1,…,1,0,…,0,… -- This is row 2(k+1)
+ 3,2,…,2,1,…,1,0,0,… -- After another k+1 steps we append 3's at the start
+ ⋮
+```
+
+This produces an array of natural numbers. We find the quotient of the euclidean
+division of `n` by `k+1` in the `k`-th column of the `n`-th row of this array.
+We will arbitrarily set the quotient of the euclidean division of `n` by `0` to
+`0` in this definition.
+
```agda
-map-extended-euclidean-algorithm : ℕ × ℕ → ℕ × ℕ
-pr1 (map-extended-euclidean-algorithm (pair x y)) = y
-pr2 (map-extended-euclidean-algorithm (pair x y)) =
- remainder-euclidean-division-ℕ y x
+array-quotient-euclidean-division-ℕ : ℕ → ℕ → ℕ → ℕ
+array-quotient-euclidean-division-ℕ k zero-ℕ m = zero-ℕ
+array-quotient-euclidean-division-ℕ k (succ-ℕ n) zero-ℕ =
+ succ-ℕ (array-quotient-euclidean-division-ℕ k n k)
+array-quotient-euclidean-division-ℕ k (succ-ℕ n) (succ-ℕ m) =
+ array-quotient-euclidean-division-ℕ k n m
+
+quotient-euclidean-division-ℕ' : ℕ → ℕ → ℕ
+quotient-euclidean-division-ℕ' zero-ℕ n = zero-ℕ
+quotient-euclidean-division-ℕ' (succ-ℕ k) n =
+ array-quotient-euclidean-division-ℕ k n k
+```
+
+## Properties
+
+### If `d` divides a number `n`, then its quotient by euclidean division is its quotient by division
+
+Suppose `q * d = n`. Then the congruence class `r` of `n` modulo `d` is `0`, so
+the distance between `r` and `n` is `n`.
+
+```text
+compute-euclidean-division-div-ℕ :
+ (d n : ℕ) (H : div-ℕ d n) →
+ quotient-euclidean-division-ℕ d n = quotient-div-ℕ d n H
+compute-euclidean-division-div-ℕ d n H =
+ {!eq-quotient-div-eq-is-nonzero-divisor-ℕ!}
```
diff --git a/src/elementary-number-theory/exponentiation-natural-numbers.lagda.md b/src/elementary-number-theory/exponentiation-natural-numbers.lagda.md
index abbf1734ae..25650a3b7a 100644
--- a/src/elementary-number-theory/exponentiation-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/exponentiation-natural-numbers.lagda.md
@@ -10,13 +10,37 @@ module elementary-number-theory.exponentiation-natural-numbers where
open import commutative-algebra.powers-of-elements-commutative-semirings
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.bounded-divisibility-natural-numbers
open import elementary-number-theory.commutative-semiring-of-natural-numbers
+open import elementary-number-theory.distance-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.strictly-inflationary-functions-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.products-of-natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+open import elementary-number-theory.strong-induction-natural-numbers
open import foundation.action-on-identifications-functions
+open import foundation.coproduct-types
+open import foundation.decidable-embeddings
+open import foundation.decidable-maps
+open import foundation.dependent-pair-types
+open import foundation.embeddings
+open import foundation.empty-types
+open import foundation.fibers-of-maps
open import foundation.identity-types
+open import foundation.injective-maps
+open import foundation.negated-equality
+open import foundation.unit-type
+open import foundation.universe-levels
+
+open import order-theory.order-preserving-maps-posets
+open import order-theory.strict-order-preserving-maps
+
+open import univalent-combinatorics.finite-maps
```
@@ -25,64 +49,178 @@ open import foundation.identity-types
The {{#concept "exponential" Agda=exp-ℕ WD="exponentiation" WDID=Q33456}} $m^n$
of two [natural numbers](elementary-number-theory.natural-numbers.md) is the
-number obtained by multiplying $m$ with itself $n$ times.
+number obtained by multiplying $m$ with itself $n$ times. We use the following
+terminology in our formalization and naming scheme:
+
+- The number $m^n$ is the **$n$th power** of $m$.
+- The number $m^n$ is an **exponential**.
+- The number $n$ in $m^n$ is called the **exponent** of the exponential.
+- The number $m$ in $m^n$ is the **base** of the exponential.
+- The operation $m,n \mapsto m^n$ is called **exponentiation**.
+- The function $n \mapsto m^n$ is the **exponentiation function** with base $m$.
+- The function $m \mapsto m^n$ is the **$n$th power function**. Specific
+ instances are [squaring](elementary-number-theory.squares-natural-numbers.md)
+ and [cubing](elementary-number-theory.cubes-natural-numbers.md).
+
+The natural numbers satisfy Tarski's high school arithmetic laws for
+exponentiation.
## Definition
+### Powers of natural numbers
+
+The function `power-ℕ n : ℕ → ℕ` defines $n$th power of a natural number $m$.
+
+```agda
+power-ℕ : ℕ → ℕ → ℕ
+power-ℕ = power-Commutative-Semiring ℕ-Commutative-Semiring
+```
+
+### The predicate of being an $n$th power
+
+```agda
+is-power-ℕ : ℕ → ℕ → UU lzero
+is-power-ℕ m n = fiber (power-ℕ n) m
+```
+
+### Exponentiation of natural numbers
+
+The function `exp-ℕ : ℕ → ℕ → ℕ` defines the exponentiation map
+$m,n \mapsto m^n$. Note that this is just the power function, with the order of
+its arguments swapped.
+
```agda
exp-ℕ : ℕ → ℕ → ℕ
-exp-ℕ m 0 = 1
-exp-ℕ m (succ-ℕ n) = (exp-ℕ m n) *ℕ m
+exp-ℕ m n = power-ℕ n m
infixr 45 _^ℕ_
_^ℕ_ = exp-ℕ
```
+### The predicate of being an exponential of a given natural number
+
```agda
-power-ℕ : ℕ → ℕ → ℕ
-power-ℕ = power-Commutative-Semiring ℕ-Commutative-Semiring
+is-exponential-ℕ : ℕ → ℕ → UU lzero
+is-exponential-ℕ m n = fiber (exp-ℕ m) n
+
+valuation-is-exponential-ℕ :
+ (m n : ℕ) → is-exponential-ℕ m n → ℕ
+valuation-is-exponential-ℕ m n = pr1
+
+eq-valuation-is-exponential-ℕ :
+ (m n : ℕ) (H : is-exponential-ℕ m n) →
+ exp-ℕ m (valuation-is-exponential-ℕ m n H) = n
+eq-valuation-is-exponential-ℕ m n = pr2
```
## Properties
-### Tarski's high school arithmetic laws for exponentiation
+### `1ⁿ = 1`
```agda
annihilation-law-exp-ℕ : (n : ℕ) → 1 ^ℕ n = 1
-annihilation-law-exp-ℕ zero-ℕ = refl
-annihilation-law-exp-ℕ (succ-ℕ n) =
- right-unit-law-mul-ℕ (1 ^ℕ n) ∙ annihilation-law-exp-ℕ n
+annihilation-law-exp-ℕ = power-one-Commutative-Semiring ℕ-Commutative-Semiring
+```
+
+### `mⁿ⁺¹ = mⁿm`
+
+```agda
+exp-succ-ℕ :
+ (m n : ℕ) → m ^ℕ succ-ℕ n = m ^ℕ n *ℕ m
+exp-succ-ℕ m n =
+ power-succ-Commutative-Semiring ℕ-Commutative-Semiring n m
+```
+
+### `mⁿ⁺¹ = mmⁿ`
+
+```agda
+exp-succ-ℕ' :
+ (m n : ℕ) → m ^ℕ succ-ℕ n = m *ℕ m ^ℕ n
+exp-succ-ℕ' m n =
+ power-succ-Commutative-Semiring' ℕ-Commutative-Semiring n m
+```
+
+### Powers by sums of natural numbers are products of powers
+```agda
left-distributive-exp-add-ℕ :
- (x y z : ℕ) → x ^ℕ (y +ℕ z) = (x ^ℕ y) *ℕ (x ^ℕ z)
-left-distributive-exp-add-ℕ x y zero-ℕ = inv (right-unit-law-mul-ℕ (x ^ℕ y))
-left-distributive-exp-add-ℕ x y (succ-ℕ z) =
- ( ap (_*ℕ x) (left-distributive-exp-add-ℕ x y z)) ∙
- ( associative-mul-ℕ (x ^ℕ y) (x ^ℕ z) x)
+ (m n : ℕ) {x : ℕ} → x ^ℕ (m +ℕ n) = x ^ℕ m *ℕ x ^ℕ n
+left-distributive-exp-add-ℕ =
+ distributive-power-add-Commutative-Semiring ℕ-Commutative-Semiring
+```
+
+### Powers distribute over products
+```agda
right-distributive-exp-mul-ℕ :
- (x y z : ℕ) → (x *ℕ y) ^ℕ z = (x ^ℕ z) *ℕ (y ^ℕ z)
-right-distributive-exp-mul-ℕ x y zero-ℕ = refl
-right-distributive-exp-mul-ℕ x y (succ-ℕ z) =
- ( ap (_*ℕ (x *ℕ y)) (right-distributive-exp-mul-ℕ x y z)) ∙
- ( interchange-law-mul-mul-ℕ (x ^ℕ z) (y ^ℕ z) x y)
+ (n : ℕ) (x y : ℕ) → (x *ℕ y) ^ℕ n = x ^ℕ n *ℕ y ^ℕ n
+right-distributive-exp-mul-ℕ =
+ distributive-power-mul-Commutative-Semiring ℕ-Commutative-Semiring
+```
+
+### Powers by products of natural numbers are iterated powers
-exp-mul-ℕ : (x y z : ℕ) → x ^ℕ (y *ℕ z) = (x ^ℕ y) ^ℕ z
-exp-mul-ℕ x zero-ℕ z = inv (annihilation-law-exp-ℕ z)
-exp-mul-ℕ x (succ-ℕ y) z =
- ( left-distributive-exp-add-ℕ x (y *ℕ z) z) ∙
- ( ( ap (_*ℕ (x ^ℕ z)) (exp-mul-ℕ x y z)) ∙
- ( inv (right-distributive-exp-mul-ℕ (x ^ℕ y) x z)))
+```agda
+exp-mul-ℕ :
+ (m n : ℕ) {x : ℕ} → x ^ℕ (m *ℕ n) = (x ^ℕ m) ^ℕ n
+exp-mul-ℕ =
+ power-mul-Commutative-Semiring ℕ-Commutative-Semiring
```
-### The exponent $m^n$ is always nonzero
+### The exponent $m^n$ is nonzero if $m$ is nonzero
```agda
is-nonzero-exp-ℕ :
(m n : ℕ) → is-nonzero-ℕ m → is-nonzero-ℕ (m ^ℕ n)
-is-nonzero-exp-ℕ m zero-ℕ p = is-nonzero-one-ℕ
-is-nonzero-exp-ℕ m (succ-ℕ n) p =
- is-nonzero-mul-ℕ (m ^ℕ n) m (is-nonzero-exp-ℕ m n p) p
+is-nonzero-exp-ℕ m zero-ℕ H =
+ is-nonzero-one-ℕ
+is-nonzero-exp-ℕ m (succ-ℕ zero-ℕ) H = H
+is-nonzero-exp-ℕ m (succ-ℕ (succ-ℕ n)) H =
+ is-nonzero-mul-ℕ (m ^ℕ succ-ℕ n) m (is-nonzero-exp-ℕ m (succ-ℕ n) H) H
+
+le-zero-exp-ℕ :
+ (m n : ℕ) → 0 <-ℕ m → 0 <-ℕ m ^ℕ n
+le-zero-exp-ℕ m zero-ℕ H =
+ star
+le-zero-exp-ℕ m (succ-ℕ zero-ℕ) H =
+ H
+le-zero-exp-ℕ m (succ-ℕ (succ-ℕ n)) H =
+ preserves-strict-order-mul-ℕ
+ ( 0)
+ ( m ^ℕ succ-ℕ n)
+ ( 0)
+ ( m)
+ ( le-zero-exp-ℕ m (succ-ℕ n) H)
+ ( H)
+
+leq-one-exp-ℕ :
+ (m n : ℕ) → 1 ≤-ℕ m → 1 ≤-ℕ m ^ℕ n
+leq-one-exp-ℕ m n H =
+ leq-one-is-nonzero-ℕ
+ ( m ^ℕ n)
+ ( is-nonzero-exp-ℕ m n (is-nonzero-leq-one-ℕ m H))
+```
+
+### The exponent $m^n$ of a number $m>1$ by a nonzero number $n$ is strictly greater than $0$
+
+```agda
+le-one-exp-ℕ :
+ (m n : ℕ) → 1 <-ℕ m → is-nonzero-ℕ n → 1 <-ℕ m ^ℕ n
+le-one-exp-ℕ (succ-ℕ (succ-ℕ m)) zero-ℕ H K = ex-falso (K refl)
+le-one-exp-ℕ (succ-ℕ (succ-ℕ m)) (succ-ℕ zero-ℕ) H K = star
+le-one-exp-ℕ (succ-ℕ (succ-ℕ m)) (succ-ℕ (succ-ℕ n)) H K =
+ concatenate-le-leq-ℕ 1
+ ( succ-ℕ (succ-ℕ m) ^ℕ succ-ℕ n)
+ ( succ-ℕ (succ-ℕ m) ^ℕ succ-ℕ (succ-ℕ n))
+ ( le-one-exp-ℕ (succ-ℕ (succ-ℕ m)) (succ-ℕ n) H (is-nonzero-succ-ℕ n))
+ ( concatenate-eq-leq-eq-ℕ
+ ( inv (right-unit-law-mul-ℕ (succ-ℕ (succ-ℕ m) ^ℕ succ-ℕ n)))
+ ( preserves-order-right-mul-ℕ
+ ( succ-ℕ (succ-ℕ m) ^ℕ succ-ℕ n)
+ ( 1)
+ ( succ-ℕ (succ-ℕ m))
+ ( star))
+ ( exp-succ-ℕ (succ-ℕ (succ-ℕ m)) (succ-ℕ n)))
```
### The exponent $m^n$ is equal to the $n$-fold product of $m$
@@ -91,6 +229,316 @@ is-nonzero-exp-ℕ m (succ-ℕ n) p =
compute-constant-product-ℕ :
(m n : ℕ) → Π-ℕ n (λ _ → m) = exp-ℕ m n
compute-constant-product-ℕ m zero-ℕ = refl
-compute-constant-product-ℕ m (succ-ℕ n) =
- ap (_*ℕ m) (compute-constant-product-ℕ m n)
+compute-constant-product-ℕ m (succ-ℕ zero-ℕ) = left-unit-law-add-ℕ m
+compute-constant-product-ℕ m (succ-ℕ (succ-ℕ n)) =
+ ap (_*ℕ m) (compute-constant-product-ℕ m (succ-ℕ n))
+```
+
+### The base of the exponent divides its successor exponents
+
+```agda
+div-exp-succ-ℕ :
+ (m n : ℕ) → div-ℕ m (m ^ℕ succ-ℕ n)
+pr1 (div-exp-succ-ℕ m n) = m ^ℕ n
+pr2 (div-exp-succ-ℕ m n) = inv (exp-succ-ℕ m n)
+
+div-exp-succ-ℕ' :
+ (m n : ℕ) → div-ℕ (m ^ℕ n) (m ^ℕ succ-ℕ n)
+pr1 (div-exp-succ-ℕ' m n) = m
+pr2 (div-exp-succ-ℕ' m n) = inv (exp-succ-ℕ' m n)
+
+div-exp-is-successor-ℕ :
+ (m n : ℕ) → is-successor-ℕ n → div-ℕ m (m ^ℕ n)
+div-exp-is-successor-ℕ m .(succ-ℕ k) (k , refl) =
+ div-exp-succ-ℕ m k
+
+div-exp-ℕ :
+ (m n : ℕ) → is-nonzero-ℕ n → div-ℕ m (m ^ℕ n)
+div-exp-ℕ m n H =
+ div-exp-is-successor-ℕ m n (is-successor-is-nonzero-ℕ H)
+
+bounded-div-exp-ℕ :
+ (m n : ℕ) → is-nonzero-ℕ n → bounded-div-ℕ m (m ^ℕ n)
+bounded-div-exp-ℕ m n H =
+ bounded-div-div-ℕ m (m ^ℕ n) (div-exp-ℕ m n H)
+```
+
+### If an exponential of a number greater than $1$ is equal to $1$, then its exponent is $0$
+
+```agda
+is-zero-exponent-is-one-exp-ℕ :
+ (m n : ℕ) → 1 <-ℕ m → is-one-ℕ (m ^ℕ n) → is-zero-ℕ n
+is-zero-exponent-is-one-exp-ℕ m zero-ℕ H K =
+ refl
+is-zero-exponent-is-one-exp-ℕ m (succ-ℕ n) H p =
+ ex-falso
+ ( neq-le-ℕ
+ ( 1)
+ ( m ^ℕ n *ℕ m)
+ ( concatenate-leq-le-ℕ 1
+ ( m ^ℕ n)
+ ( m ^ℕ n *ℕ m)
+ ( leq-one-exp-ℕ m n (leq-le-ℕ 1 m H))
+ ( concatenate-eq-le-ℕ
+ ( m ^ℕ n)
+ ( m ^ℕ n *ℕ 1)
+ ( m ^ℕ n *ℕ m)
+ ( inv (right-unit-law-mul-ℕ (m ^ℕ n)))
+ ( preserves-strict-order-left-mul-ℕ
+ ( m ^ℕ n)
+ ( 1)
+ ( m)
+ ( is-nonzero-exp-ℕ m n (is-nonzero-le-ℕ 1 m H)) H)))
+ ( inv p ∙ exp-succ-ℕ m n))
+```
+
+### The function $n \mapsto m^n$ is injective and an embedding for any $m>1$
+
+```agda
+is-injective-exp-ℕ :
+ (m : ℕ) → 1 <-ℕ m → is-injective (m ^ℕ_)
+is-injective-exp-ℕ m H {zero-ℕ} {zero-ℕ} p =
+ refl
+is-injective-exp-ℕ m H {zero-ℕ} {succ-ℕ l} p =
+ inv (is-zero-exponent-is-one-exp-ℕ m (succ-ℕ l) H (inv p))
+is-injective-exp-ℕ m H {succ-ℕ k} {zero-ℕ} p =
+ is-zero-exponent-is-one-exp-ℕ m (succ-ℕ k) H p
+is-injective-exp-ℕ m H {succ-ℕ k} {succ-ℕ l} p =
+ ap
+ ( succ-ℕ)
+ ( is-injective-exp-ℕ m H {k} {l}
+ ( is-injective-right-mul-ℕ m
+ ( is-nonzero-le-ℕ 1 m H)
+ ( inv (exp-succ-ℕ m k) ∙ p ∙ exp-succ-ℕ m l)))
+
+is-emb-exp-ℕ :
+ (m : ℕ) → 1 <-ℕ m → is-emb (m ^ℕ_)
+is-emb-exp-ℕ m H =
+ is-emb-is-injective is-set-ℕ (is-injective-exp-ℕ m H)
+```
+
+### Exponentiating a nonzero number is an order preserving function
+
+```agda
+preserves-order-exponent-exp-ℕ :
+ (m : ℕ) → is-nonzero-ℕ m →
+ preserves-order-Poset ℕ-Poset ℕ-Poset (m ^ℕ_)
+preserves-order-exponent-exp-ℕ m H zero-ℕ zero-ℕ K =
+ refl-leq-ℕ 1
+preserves-order-exponent-exp-ℕ m H zero-ℕ (succ-ℕ k) K =
+ leq-one-exp-ℕ m (succ-ℕ k) (leq-one-is-nonzero-ℕ m H)
+preserves-order-exponent-exp-ℕ m H (succ-ℕ n) (succ-ℕ k) K =
+ concatenate-eq-leq-eq-ℕ
+ ( exp-succ-ℕ m n)
+ ( preserves-order-mul-ℕ
+ ( m ^ℕ n)
+ ( m ^ℕ k)
+ ( m)
+ ( m)
+ ( preserves-order-exponent-exp-ℕ m H n k K)
+ ( refl-leq-ℕ m))
+ ( inv (exp-succ-ℕ m k))
+```
+
+### Exponentiating a number strictly greater than $1$ is a strictly order preserving function
+
+```agda
+preserves-strict-order-exponent-exp-ℕ :
+ (m : ℕ) → 1 <-ℕ m →
+ preserves-strict-order-map-Strict-Preorder
+ ( ℕ-Strict-Preorder)
+ ( ℕ-Strict-Preorder)
+ ( m ^ℕ_)
+preserves-strict-order-exponent-exp-ℕ m H zero-ℕ (succ-ℕ k) K =
+ le-one-exp-ℕ m (succ-ℕ k) H (is-nonzero-succ-ℕ k)
+preserves-strict-order-exponent-exp-ℕ m H (succ-ℕ n) (succ-ℕ k) K =
+ concatenate-eq-le-eq-ℕ
+ ( m ^ℕ succ-ℕ n)
+ ( m ^ℕ n *ℕ m)
+ ( m ^ℕ k *ℕ m)
+ ( m ^ℕ succ-ℕ k)
+ ( exp-succ-ℕ m n)
+ ( preserves-strict-order-right-mul-ℕ
+ ( m)
+ ( m ^ℕ n)
+ ( m ^ℕ k)
+ ( is-nonzero-le-ℕ 1 m H)
+ ( preserves-strict-order-exponent-exp-ℕ m H n k K))
+ ( inv (exp-succ-ℕ m k))
+```
+
+### The function $n \mapsto m^n$ is strictly inflationary for any $11$ reflects divisibility into inequality
+
+```agda
+leq-exponent-div-exp-ℕ :
+ (m n k : ℕ) → 1 <-ℕ m → div-ℕ (m ^ℕ k) (m ^ℕ n) → k ≤-ℕ n
+leq-exponent-div-exp-ℕ m zero-ℕ zero-ℕ H K = refl-leq-ℕ 0
+leq-exponent-div-exp-ℕ m zero-ℕ (succ-ℕ k) H K =
+ neq-le-ℕ 1 m H
+ ( inv (is-one-div-one-ℕ (m ^ℕ succ-ℕ k) K) ∙
+ exp-succ-ℕ m k ∙
+ ap
+ ( λ x → m ^ℕ x *ℕ m)
+ ( is-zero-leq-zero-ℕ k
+ ( leq-exponent-div-exp-ℕ m 0 k H
+ ( transitive-div-ℕ
+ ( m ^ℕ k)
+ ( m ^ℕ succ-ℕ k)
+ ( 1)
+ ( K)
+ ( div-exp-succ-ℕ' m k)))) ∙
+ left-unit-law-mul-ℕ m)
+leq-exponent-div-exp-ℕ m (succ-ℕ n) zero-ℕ H K = leq-zero-ℕ (succ-ℕ n)
+leq-exponent-div-exp-ℕ m (succ-ℕ n) (succ-ℕ k) H K =
+ leq-exponent-div-exp-ℕ m n k H
+ ( reflects-div-right-mul-ℕ m
+ ( m ^ℕ k)
+ ( m ^ℕ n)
+ ( is-nonzero-le-ℕ 1 m H)
+ ( concatenate-eq-div-eq-ℕ (inv (exp-succ-ℕ m k)) K (exp-succ-ℕ m n)))
+```
+
+### If $m^k \mid m^n$ and $m$ is nonzero, then its quotient is $m^{d(n,k)}$
+
+In the case where $m=0$ we have $0^n \mid 0^n$. For any nonzero number $n$ this
+would give $0 \mid 0$. The quotient of $0$ divided by $0$ is the unique number
+$k \leq 0$ such that $k\cdot 0=0$, i.e., it is $0$. However, since $d(n,n)=0$ we
+have $m^{d(n,n)}=1$, which isn't the quotient under our definitions.
+
+```agda
+valuation-is-exponent-div-exp-exp-ℕ :
+ (m n k : ℕ) → is-nonzero-ℕ m → div-ℕ (m ^ℕ k) (m ^ℕ n) → ℕ
+valuation-is-exponent-div-exp-exp-ℕ m n k H K =
+ dist-ℕ n k
+
+eq-valuation-is-exponent-div-exp-exp-ℕ :
+ (m n k : ℕ) (H : is-nonzero-ℕ m) (K : div-ℕ (m ^ℕ k) (m ^ℕ n)) →
+ exp-ℕ m (valuation-is-exponent-div-exp-exp-ℕ m n k H K) =
+ quotient-div-ℕ (m ^ℕ k) (m ^ℕ n) K
+eq-valuation-is-exponent-div-exp-exp-ℕ zero-ℕ n k H K =
+ ex-falso (H refl)
+eq-valuation-is-exponent-div-exp-exp-ℕ (succ-ℕ zero-ℕ) n k H K =
+ annihilation-law-exp-ℕ (dist-ℕ n k) ∙
+ compute-quotient-div-ℕ
+ ( inv (annihilation-law-exp-ℕ k))
+ ( inv (annihilation-law-exp-ℕ n))
+ ( refl-div-ℕ 1)
+ ( K)
+eq-valuation-is-exponent-div-exp-exp-ℕ (succ-ℕ (succ-ℕ m)) n k H K =
+ is-injective-left-mul-ℕ
+ ( succ-ℕ (succ-ℕ m) ^ℕ k)
+ ( is-nonzero-exp-ℕ (succ-ℕ (succ-ℕ m)) k H)
+ ( inv (left-distributive-exp-add-ℕ k (dist-ℕ n k)) ∙
+ ap (succ-ℕ (succ-ℕ m) ^ℕ_) (ap (k +ℕ_) (symmetric-dist-ℕ n k) ∙
+ is-difference-dist-ℕ k n
+ ( leq-exponent-div-exp-ℕ (succ-ℕ (succ-ℕ m)) n k star K)) ∙
+ inv
+ ( eq-quotient-div-ℕ'
+ ( succ-ℕ (succ-ℕ m) ^ℕ k)
+ ( succ-ℕ (succ-ℕ m) ^ℕ n)
+ ( K)))
+
+is-exponent-div-exp-exp-ℕ :
+ (m n k : ℕ) → is-nonzero-ℕ m → (K : div-ℕ (m ^ℕ k) (m ^ℕ n)) →
+ is-exponential-ℕ m (quotient-div-ℕ (m ^ℕ k) (m ^ℕ n) K)
+pr1 (is-exponent-div-exp-exp-ℕ m n k H K) =
+ valuation-is-exponent-div-exp-exp-ℕ m n k H K
+pr2 (is-exponent-div-exp-exp-ℕ m n k H K) =
+ eq-valuation-is-exponent-div-exp-exp-ℕ m n k H K
```
diff --git a/src/elementary-number-theory/factorials.lagda.md b/src/elementary-number-theory/factorials.lagda.md
index 05851e426e..19453e3b7c 100644
--- a/src/elementary-number-theory/factorials.lagda.md
+++ b/src/elementary-number-theory/factorials.lagda.md
@@ -7,11 +7,14 @@ module elementary-number-theory.factorials where
Imports
```agda
+open import elementary-number-theory.addition-natural-numbers
open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.greatest-common-divisor-natural-numbers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.relatively-prime-natural-numbers
open import foundation.coproduct-types
open import foundation.dependent-pair-types
@@ -27,7 +30,9 @@ The {{#concept "factorial" WD="factorial" WDID=Q120976 Agda=factorial-ℕ}} `n!`
of a number `n`, counts the number of ways to linearly order `n` distinct
objects.
-## Definition
+## Definitions
+
+### Factorial numbers
```agda
factorial-ℕ : ℕ → ℕ
@@ -35,6 +40,13 @@ factorial-ℕ 0 = 1
factorial-ℕ (succ-ℕ m) = (factorial-ℕ m) *ℕ (succ-ℕ m)
```
+### Successors of factorial numbers
+
+```agda
+succ-factorial-ℕ : ℕ → ℕ
+succ-factorial-ℕ n = succ-ℕ (factorial-ℕ n)
+```
+
## Properties
```agda
@@ -73,7 +85,91 @@ leq-factorial-ℕ (succ-ℕ n) =
( is-nonzero-factorial-ℕ n)
```
+### For any nonzero natural number $n$, the successor factorial of $n$ and $n$ itself are relatively prime
+
+Note that the assumption that $n$ is nonzero is necessary, because the numbers $0$ and $0! + 1$ have greatest common divisor $2$.
+
+```agda
+is-one-is-common-divisor-id-succ-factorial-ℕ :
+ (n d : ℕ) → is-nonzero-ℕ n →
+ is-common-divisor-ℕ n (succ-factorial-ℕ n) d → is-one-ℕ d
+is-one-is-common-divisor-id-succ-factorial-ℕ n d H (K , L) =
+ is-one-div-one-ℕ d
+ ( div-right-summand-ℕ d
+ ( factorial-ℕ n)
+ ( 1)
+ ( transitive-div-ℕ d n
+ ( factorial-ℕ n)
+ ( div-factorial-ℕ n n (refl-leq-ℕ n) H)
+ ( K))
+ ( L))
+
+relatively-prime-id-succ-factorial-ℕ :
+ (n : ℕ) → is-nonzero-ℕ n → is-relatively-prime-ℕ n (succ-factorial-ℕ n)
+relatively-prime-id-succ-factorial-ℕ n H =
+ is-one-is-common-divisor-id-succ-factorial-ℕ
+ ( n)
+ ( gcd-ℕ n (succ-factorial-ℕ n))
+ ( H)
+ ( is-common-divisor-gcd-ℕ n (succ-factorial-ℕ n))
+```
+
+### The successor factorials of $n$ and $n+1$ are relatively prime for any nonzero $n$
+
+This property is stated as exercise 53 in section 1.2 of {{#cite NZM}}. This exercise was stated in a setting where the natural numbers start at $1$. The assumption that $n$ is nonzero is necessary, because $0! + 1 = 2$ and $1! + 1 = 2$.
+
+**Proof.** First, we observe that
+
+```text
+ ((n + 1)! + 1) + n = n!(n + 1) + (n + 1)
+ = (n! + 1)(n + 1).
+```
+
+This shows that if `d` is a common divisor of `n! + 1` and `(n + 1)! + 1`, then `d` is a divisor of `n`. However, `n` and `n! + 1` are relatively prime if `n` is nonzero, so it follows that `d = 1`.
+
+```agda
+recursive-law-succ-factorial-ℕ :
+ (n : ℕ) → succ-factorial-ℕ (succ-ℕ n) +ℕ n = succ-factorial-ℕ n *ℕ succ-ℕ n
+recursive-law-succ-factorial-ℕ n =
+ left-successor-law-add-ℕ (factorial-ℕ (succ-ℕ n)) n ∙
+ inv (left-successor-law-mul-ℕ (factorial-ℕ n) (succ-ℕ n))
+
+is-one-is-common-divisor-consecutive-succ-factorial-ℕ :
+ (n d : ℕ) → is-nonzero-ℕ n →
+ is-common-divisor-ℕ (succ-factorial-ℕ n) (succ-factorial-ℕ (succ-ℕ n)) d →
+ is-one-ℕ d
+is-one-is-common-divisor-consecutive-succ-factorial-ℕ n d H (K , L) =
+ is-one-is-common-divisor-id-succ-factorial-ℕ n d H
+ ( ( div-right-summand-ℕ
+ ( d)
+ ( succ-factorial-ℕ (succ-ℕ n))
+ ( n)
+ ( L)
+ ( concatenate-div-eq-ℕ
+ ( div-mul-ℕ' (succ-ℕ n) d (succ-factorial-ℕ n) K)
+ ( inv (recursive-law-succ-factorial-ℕ n)))) ,
+ ( K))
+
+is-relatively-prime-consecutive-succ-factorial-ℕ :
+ (n : ℕ) → is-nonzero-ℕ n →
+ is-relatively-prime-ℕ (succ-factorial-ℕ n) (succ-factorial-ℕ (succ-ℕ n))
+is-relatively-prime-consecutive-succ-factorial-ℕ n H =
+ is-one-is-common-divisor-consecutive-succ-factorial-ℕ
+ ( n)
+ ( gcd-ℕ
+ ( succ-factorial-ℕ n)
+ ( succ-factorial-ℕ (succ-ℕ n)))
+ ( H)
+ ( is-common-divisor-gcd-ℕ
+ ( succ-factorial-ℕ n)
+ ( succ-factorial-ℕ (succ-ℕ n)))
+```
+
## External links
- [Factorial](https://en.wikipedia.org/wiki/Factorial) at Wikipedia
- [A000142](https://oeis.org/A000142) in the OEIS
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/farey-fractions.lagda.md b/src/elementary-number-theory/farey-fractions.lagda.md
new file mode 100644
index 0000000000..fd09ece4d8
--- /dev/null
+++ b/src/elementary-number-theory/farey-fractions.lagda.md
@@ -0,0 +1,205 @@
+# Farey fractions
+
+```agda
+module elementary-number-theory.farey-fractions where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.binary-relations
+open import foundation.empty-types
+open import foundation.identity-types
+open import foundation.negation
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+A {{#concept "Farey fraction" Agda=farey-fraction}} is a
+[reduced](elementary-number-theory.reduced-integer-fractions.md)
+[integer fraction](elementary-number-theory.integer-fractions.md) between $0$
+and $1$ inclusive. More specifically, a Farey fraction of order $n$ is a reduced
+integer fraction between $0$ and $1$ whose denominator does not exceed $n$.
+
+The Farey fractions ℱ can be inductively generated mutually with a binary
+relation $R$ with the following constructors:
+
+```text
+ 0 : ℱ
+ 1 : ℱ
+ 𝓂 : (x y : ℱ) → ℛ x y → ℱ
+
+ 𝓈 : ℛ 0 1
+ 𝓇 : (x y : ℱ) (r : ℛ x y) → ℛ x (𝓂 x y r)
+ 𝓁 : (x y : ℱ) (r : ℛ x y) → ℛ (𝓂 x y r) y
+```
+
+The operation $m$ returns the
+{{#concept "mediant" Disambiguation="Farey fractions" Agda=mediant-farey-fraction}}
+of two adjacent Farey fractions. The elements $0$ and $1$ in the type of Farey
+fractions represent the Farey fractions $0/1$ and $1/1$. Given two adjacent
+Farey fractions representing $a/b$ and $c/d$, the mediant of $a/b$ and $c/d$ is
+the Farey fraction representing
+
+$$
+ \frac{a+c}{b+d}.
+$$
+
+The mediant of any two adjacent Farey fractions representing reduced fractions
+$a/b$ and $c/d$ represents again a reduced fraction.
+
+Farey fractions appear in Chapter 3 of {{#cite HW08}}, but they are covered in
+more detail in Chapter 6 of {{#cite NZM}}.
+
+## Definitions
+
+### The inductively generated Farey fractions
+
+```agda
+mutual
+
+ data
+ farey-fraction : UU lzero
+ where
+
+ zero-farey-fraction : farey-fraction
+ one-farey-fraction : farey-fraction
+
+ mediant-farey-fraction :
+ (x y : farey-fraction) → adjacent-farey-fraction x y → farey-fraction
+
+ data
+ adjacent-farey-fraction : farey-fraction → farey-fraction → UU lzero
+ where
+
+ adjacent-zero-one-farey-fraction :
+ adjacent-farey-fraction zero-farey-fraction one-farey-fraction
+
+ right-adjacent-mediant-farey-fraction :
+ (x y : farey-fraction) (H : adjacent-farey-fraction x y) →
+ adjacent-farey-fraction x (mediant-farey-fraction x y H)
+
+ left-adjacent-mediant-farey-fraction :
+ (x y : farey-fraction) (H : adjacent-farey-fraction x y) →
+ adjacent-farey-fraction (mediant-farey-fraction x y H) y
+```
+
+### The inclusion of Farey fractions into the integer fractions
+
+```agda
+numerator-farey-fraction :
+ farey-fraction → ℕ
+numerator-farey-fraction zero-farey-fraction =
+ 0
+numerator-farey-fraction one-farey-fraction =
+ 1
+numerator-farey-fraction (mediant-farey-fraction x y H) =
+ numerator-farey-fraction x +ℕ numerator-farey-fraction y
+
+denominator-farey-fraction :
+ farey-fraction → ℕ
+denominator-farey-fraction zero-farey-fraction =
+ 1
+denominator-farey-fraction one-farey-fraction =
+ 1
+denominator-farey-fraction (mediant-farey-fraction x y H) =
+ denominator-farey-fraction x +ℕ denominator-farey-fraction y
+```
+
+## Properties
+
+### Any two adjacent Farey fractions $a/b$ and $c/d$ satisfy $bc = ad + 1$
+
+Equivalently, two adjacent Farey fractions $a/b$ and $c/d$ satisfy the relation
+
+$$
+ bc - ad = 1.
+$$
+
+This is also known as the **characteristic property of adjacent Farey
+fractions**.
+
+```agda
+characteristic-property-adjacent-farey-fraction :
+ (x y : farey-fraction) (r : adjacent-farey-fraction x y) →
+ denominator-farey-fraction x *ℕ numerator-farey-fraction y =
+ numerator-farey-fraction x *ℕ denominator-farey-fraction y +ℕ 1
+characteristic-property-adjacent-farey-fraction ._ ._
+ adjacent-zero-one-farey-fraction =
+ refl
+characteristic-property-adjacent-farey-fraction x ._
+ ( right-adjacent-mediant-farey-fraction .x y r) =
+ left-distributive-mul-add-ℕ
+ ( denominator-farey-fraction x)
+ ( numerator-farey-fraction x)
+ ( numerator-farey-fraction y) ∙
+ ap-add-ℕ
+ ( commutative-mul-ℕ
+ ( denominator-farey-fraction x)
+ ( numerator-farey-fraction x))
+ ( characteristic-property-adjacent-farey-fraction x y r) ∙
+ ap
+ ( succ-ℕ)
+ ( inv
+ ( left-distributive-mul-add-ℕ
+ ( numerator-farey-fraction x)
+ ( denominator-farey-fraction x)
+ ( denominator-farey-fraction y)))
+characteristic-property-adjacent-farey-fraction ._ y
+ ( left-adjacent-mediant-farey-fraction x .y r) =
+ right-distributive-mul-add-ℕ
+ ( denominator-farey-fraction x)
+ ( denominator-farey-fraction y)
+ ( numerator-farey-fraction y) ∙
+ ap-add-ℕ
+ ( characteristic-property-adjacent-farey-fraction x y r)
+ ( commutative-mul-ℕ
+ ( denominator-farey-fraction y)
+ ( numerator-farey-fraction y)) ∙
+ left-successor-law-add-ℕ
+ ( numerator-farey-fraction x *ℕ denominator-farey-fraction y)
+ ( numerator-farey-fraction y *ℕ denominator-farey-fraction y) ∙
+ ap
+ ( succ-ℕ)
+ ( inv
+ ( right-distributive-mul-add-ℕ
+ ( numerator-farey-fraction x)
+ ( numerator-farey-fraction y)
+ ( denominator-farey-fraction y)))
+```
+
+### There is no adjacency from any Farey fraction to $0$
+
+```agda
+not-adjacent-zero-farey-fraction :
+ (x : farey-fraction) → ¬ adjacent-farey-fraction x zero-farey-fraction
+not-adjacent-zero-farey-fraction ._
+ ( left-adjacent-mediant-farey-fraction x ._ r) =
+ not-adjacent-zero-farey-fraction x r
+```
+
+### There is no adjacency from $1$ to any Farey fraction
+
+```agda
+not-adjacent-one-farey-fraction :
+ (x : farey-fraction) → ¬ adjacent-farey-fraction one-farey-fraction x
+not-adjacent-one-farey-fraction
+ ( mediant-farey-fraction one-farey-fraction y s) r =
+ not-adjacent-one-farey-fraction y s
+```
+
+## See also
+
+- [Unbounded Farey fractions](elementary-number-theory.unbounded-farey-fractions.md)
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/fermat-numbers.lagda.md b/src/elementary-number-theory/fermat-numbers.lagda.md
index 8a76e9fc21..9e777d0092 100644
--- a/src/elementary-number-theory/fermat-numbers.lagda.md
+++ b/src/elementary-number-theory/fermat-numbers.lagda.md
@@ -8,11 +8,31 @@ module elementary-number-theory.fermat-numbers where
```agda
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.congruence-natural-numbers
+open import elementary-number-theory.distance-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.exponentiation-natural-numbers
+open import elementary-number-theory.greatest-common-divisor-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.modular-arithmetic-standard-finite-types
+open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
open import elementary-number-theory.products-of-natural-numbers
+open import elementary-number-theory.relatively-prime-natural-numbers
+open import elementary-number-theory.squares-natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
open import elementary-number-theory.strong-induction-natural-numbers
+open import foundation.action-on-identifications-functions
+open import foundation.coproduct-types
+open import foundation.dependent-pair-types
+open import foundation.function-types
+open import foundation.identity-types
+open import foundation.negated-equality
+open import foundation.transport-along-identifications
+open import foundation.unit-type
+
open import univalent-combinatorics.standard-finite-types
```
@@ -20,7 +40,7 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-{{#concept "Fermat numbers" WD="Fermat number" WDID=Q207264 Agda=fermat-number-ℕ}}
+{{#concept "Fermat numbers" WD="Fermat number" WDID=Q207264 OEIS=A000215 Agda=fermat-number-ℕ}}
are numbers of the form $F_n := 2^{2^n}+1$. The first five Fermat numbers are
```text
@@ -28,7 +48,7 @@ are numbers of the form $F_n := 2^{2^n}+1$. The first five Fermat numbers are
```
The sequence of Fermat numbers is listed as A000215 in the
-[Online Encyclopedia of Integer Sequences](literature.oeis.md).
+[Online Encyclopedia of Integer Sequences](literature.oeis.md) {{#cite OEIS}}.
Alternatively, the Fermat numbers can be defined with
[strong induction](elementary-number-theory.strong-induction-natural-numbers.md)
@@ -40,12 +60,17 @@ F (n + 1) := 2 + Π_{i≤n} F_i
```
This recurrence implies that any two Fermat numbers are
-[relatively prime](elementary-number-theory.relatively-prime-natural-numbers.md).
+[relatively prime](elementary-number-theory.relatively-prime-natural-numbers.md),
+because it follows from this recurrence that any divisor of two distinct Fermat
+numbers must divide the number $2$. Since the Fermat numbers are all odd, this
+implies that any divisor of two distinct Fermat numbers must be the number $1$.
+
Goldbach used this observation to prove the
-[infinitude of primes](elementary-number-theory.infinitude-of-primes.md): Since
-there are infinitely many Fermat numbers, and all of them are relatively prime,
-there must be infinitely many prime numbers. Fermat numbers also feature in a
-series of long-standing open problems in mathematics, including:
+[infinitude of primes](elementary-number-theory.infinitude-of-primes.md)
+{{#cite AZ18}} : Since there are infinitely many Fermat numbers, and all of them
+are relatively prime, there must be infinitely many prime numbers. Fermat
+numbers also feature in a series of long-standing open problems in mathematics,
+including:
- Are there infinitely many prime Fermat numbers?
- Is $F_n$ composite for all $n\geq 5$?
@@ -71,9 +96,168 @@ recursive-fermat-number-ℕ =
( succ-ℕ n)
( λ i → f (nat-Fin (succ-ℕ n) i) (upper-bound-nat-Fin n i)))
( 2))
+
+compute-succ-recursive-fermat-number-ℕ :
+ (n : ℕ) →
+ recursive-fermat-number-ℕ (succ-ℕ n) =
+ Π-ℕ (succ-ℕ n) (λ i → recursive-fermat-number-ℕ (nat-Fin (succ-ℕ n) i)) +ℕ 2
+compute-succ-recursive-fermat-number-ℕ =
+ compute-succ-strong-rec-ℕ 3
+ ( λ n f →
+ add-ℕ
+ ( Π-ℕ
+ ( succ-ℕ n)
+ ( λ i → f (nat-Fin (succ-ℕ n) i) (upper-bound-nat-Fin n i)))
+ ( 2))
+```
+
+## Properties
+
+### Every Fermat number is greater than $2$
+
+```agda
+leq-two-fermat-number-ℕ :
+ (n : ℕ) → 2 ≤-ℕ fermat-number-ℕ n
+leq-two-fermat-number-ℕ n = leq-one-exp-ℕ 2 (2 ^ℕ n) star
+```
+
+### Every Fermat number is odd
+
+```agda
+is-odd-fermat-number-ℕ :
+ (n : ℕ) → is-odd-ℕ (fermat-number-ℕ n)
+is-odd-fermat-number-ℕ n =
+ is-odd-succ-is-even-ℕ
+ ( 2 ^ℕ (2 ^ℕ n))
+ ( div-exp-ℕ 2 (2 ^ℕ n) (is-nonzero-exp-ℕ 2 n (is-nonzero-succ-ℕ 1)))
+```
+
+### The distance from a Fermat number to the number $2$
+
+Any Fermat number of the form $F(n+1)=2^{2^{n+1}}+1$ can be computed as
+
+$$
+ F(n+1)-2=(2^{2^n})^2-1=(2^{2^n}+1)(2^{2^n}-1)=F(n)(F(n)-2).
+$$
+
+```agda
+dist-fermat-number-two-ℕ :
+ (n : ℕ) →
+ dist-ℕ (fermat-number-ℕ n) 2 =
+ Π-ℕ n (λ k → fermat-number-ℕ (nat-Fin n k))
+dist-fermat-number-two-ℕ zero-ℕ = refl
+dist-fermat-number-two-ℕ (succ-ℕ n) =
+ ap (λ x → dist-ℕ x 1) (ap (2 ^ℕ_) (exp-succ-ℕ 2 n) ∙ exp-mul-ℕ (2 ^ℕ n) 2) ∙
+ distance-of-squares-ℕ (2 ^ℕ 2 ^ℕ n) 1 ∙
+ ap (_*ℕ fermat-number-ℕ n) (dist-fermat-number-two-ℕ n)
+```
+
+### Computing the $n$-th Fermat number as the product of all the previous Fermat numbers plus $2$
+
+```agda
+compute-fermat-number-ℕ :
+ (n : ℕ) →
+ fermat-number-ℕ n = Π-ℕ n (λ k → fermat-number-ℕ (nat-Fin n k)) +ℕ 2
+compute-fermat-number-ℕ n =
+ ( inv
+ ( rewrite-right-dist-add-ℕ 2
+ ( Π-ℕ n (λ k → fermat-number-ℕ (nat-Fin n k)))
+ ( fermat-number-ℕ n)
+ ( leq-two-fermat-number-ℕ n)
+ ( inv
+ ( ( symmetric-dist-ℕ 2 (fermat-number-ℕ n)) ∙
+ ( dist-fermat-number-two-ℕ n))))) ∙
+ ( commutative-add-ℕ 2 (Π-ℕ n (λ k → fermat-number-ℕ (nat-Fin n k))))
+```
+
+### The $n$th Fermat number is equal to the $n$th recursive Fermat number
+
+**Proof.** The proof is by strong induction on the natural numbers. The base
+case holds by reflexivity. For the inductive step, assume that
+
+```agda
+compute-recursive-fermat-number-ℕ :
+ (n : ℕ) → recursive-fermat-number-ℕ n = fermat-number-ℕ n
+compute-recursive-fermat-number-ℕ =
+ strong-ind-ℕ
+ ( λ n → recursive-fermat-number-ℕ n = fermat-number-ℕ n)
+ ( refl)
+ ( λ n H →
+ ( compute-succ-recursive-fermat-number-ℕ n) ∙
+ ( ap
+ ( _+ℕ 2)
+ ( preserves-htpy-Π-ℕ
+ ( succ-ℕ n)
+ ( λ i → H (nat-Fin (succ-ℕ n) i) (upper-bound-nat-Fin n i)))) ∙
+ ( inv (compute-fermat-number-ℕ (succ-ℕ n))))
+```
+
+### Any two distinct Fermat numbers are relatively prime
+
+**Proof.** By the recursive definition of the Fermat numbers, we have that
+$F_{n+1}=(\prod_{n=0}^n F_n) + 2$. This implies that if $d$ divides $F_m$ and
+$F_n$ for some $n>m$, then $d|2$. However, the Fermat numbers are odd, so $d=1$.
+
+```agda
+is-one-div-fermat-number-nat-Fin-ℕ :
+ (n d : ℕ) (i : Fin n) →
+ div-ℕ d (fermat-number-ℕ (nat-Fin n i)) →
+ div-ℕ d (fermat-number-ℕ n) →
+ is-one-ℕ d
+is-one-div-fermat-number-nat-Fin-ℕ (succ-ℕ n) d i H K =
+ is-one-is-odd-div-two-ℕ d
+ ( div-right-summand-ℕ d
+ ( Π-ℕ (succ-ℕ n) (λ j → fermat-number-ℕ (nat-Fin (succ-ℕ n) j)))
+ ( 2)
+ ( transitive-div-ℕ d
+ ( fermat-number-ℕ (nat-Fin (succ-ℕ n) i))
+ ( Π-ℕ (succ-ℕ n) (λ j → fermat-number-ℕ (nat-Fin (succ-ℕ n) j)))
+ ( div-factor-Π-ℕ (succ-ℕ n) (fermat-number-ℕ ∘ nat-Fin (succ-ℕ n)) i)
+ ( H))
+ ( concatenate-div-eq-ℕ K (compute-fermat-number-ℕ (succ-ℕ n))))
+ ( is-odd-div-is-odd-ℕ d
+ ( fermat-number-ℕ (succ-ℕ n))
+ ( is-odd-fermat-number-ℕ (succ-ℕ n))
+ ( K))
+
+is-one-div-fermat-number-le-ℕ :
+ (m n d : ℕ) → m <-ℕ n →
+ div-ℕ d (fermat-number-ℕ m) → div-ℕ d (fermat-number-ℕ n) → is-one-ℕ d
+is-one-div-fermat-number-le-ℕ m (succ-ℕ n) d H K L =
+ is-one-div-fermat-number-nat-Fin-ℕ
+ ( succ-ℕ n)
+ ( d)
+ ( mod-succ-ℕ n m)
+ ( tr
+ ( div-ℕ d ∘ fermat-number-ℕ)
+ ( inv (eq-nat-mod-succ-ℕ n m H))
+ ( K))
+ ( L)
+
+is-one-is-common-divisor-fermat-number-ℕ :
+ (m n d : ℕ) → m ≠ n →
+ is-common-divisor-ℕ (fermat-number-ℕ m) (fermat-number-ℕ n) d → is-one-ℕ d
+is-one-is-common-divisor-fermat-number-ℕ m n d H (K , L) =
+ rec-coproduct
+ ( λ u → is-one-div-fermat-number-le-ℕ m n d u K L)
+ ( λ u → is-one-div-fermat-number-le-ℕ n m d u L K)
+ ( decide-le-neq-ℕ m n H)
+
+is-relatively-prime-fermat-number-ℕ :
+ (m n : ℕ) → m ≠ n →
+ is-relatively-prime-ℕ (fermat-number-ℕ m) (fermat-number-ℕ n)
+is-relatively-prime-fermat-number-ℕ m n H =
+ is-one-is-common-divisor-fermat-number-ℕ m n
+ ( gcd-ℕ (fermat-number-ℕ m) (fermat-number-ℕ n))
+ ( H)
+ ( is-common-divisor-gcd-ℕ (fermat-number-ℕ m) (fermat-number-ℕ n))
```
## External link
- [Fermat number](https://en.wikipedia.org/wiki/Fermat_number) at Wikipedia
- [A000215](https://oeis.org/A000215) in the OEIS
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/fibonacci-sequence.lagda.md b/src/elementary-number-theory/fibonacci-sequence.lagda.md
index 89af95e039..7f014d7c57 100644
--- a/src/elementary-number-theory/fibonacci-sequence.lagda.md
+++ b/src/elementary-number-theory/fibonacci-sequence.lagda.md
@@ -8,16 +8,26 @@ module elementary-number-theory.fibonacci-sequence where
```agda
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.distance-natural-numbers
+open import elementary-number-theory.exponentiation-natural-numbers
open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.greatest-common-divisor-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.integers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
open import elementary-number-theory.relatively-prime-natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+open import elementary-number-theory.squares-natural-numbers
+open import elementary-number-theory.sums-of-natural-numbers
open import foundation.action-on-identifications-functions
open import foundation.dependent-pair-types
+open import foundation.function-types
open import foundation.identity-types
open import foundation.transport-along-identifications
+open import foundation.unit-type
```
@@ -25,7 +35,7 @@ open import foundation.transport-along-identifications
## Idea
The
-{{#concept "Fibonacci sequence" WD="Fibonacci sequence" WDID=Q23835349 Agda=Fibonacci-ℕ}}
+{{#concept "Fibonacci sequence" WD="Fibonacci sequence" WDID=Q23835349 Agda=fibonacci-ℕ OEIS=A000045}}
is a recursively defined [sequence](foundation.sequences.md) of
[natural numbers](elementary-number-theory.natural-numbers.md) given by the
equations
@@ -43,18 +53,29 @@ Fibonacci numbers are
Fₙ 0 1 1 2 3 5 8 13 21 34
```
+The Fibonacci sequence was introduced by
+[Leonardo Fibonacci](https://en.wikipedia.org/wiki/Fibonacci) in 1202 in his
+book _Liber Abaci_ {{#cite Fibonacci1202}}.
+
## Definitions
-### The standard definition using pattern matching
+### The Fibonacci sequence
+
+```agda
+fibonacci-ℕ : ℕ → ℕ
+fibonacci-ℕ 0 = 0
+fibonacci-ℕ (succ-ℕ 0) = 1
+fibonacci-ℕ (succ-ℕ (succ-ℕ n)) = fibonacci-ℕ (succ-ℕ n) +ℕ fibonacci-ℕ n
+```
+
+### The Fibonacci sequence in the integers
```agda
-Fibonacci-ℕ : ℕ → ℕ
-Fibonacci-ℕ 0 = 0
-Fibonacci-ℕ (succ-ℕ 0) = 1
-Fibonacci-ℕ (succ-ℕ (succ-ℕ n)) = (Fibonacci-ℕ (succ-ℕ n)) +ℕ (Fibonacci-ℕ n)
+fibonacci-ℤ : ℕ → ℤ
+fibonacci-ℤ = int-ℕ ∘ fibonacci-ℕ
```
-### A definition using the induction principle of `ℕ`
+### The Fibonacci sequence defined directly with the induction principle of `ℕ`
The above definition of the Fibonacci sequence uses Agda's powerful pattern
matching definitions. Below, we will give a definition of the Fibonacci sequence
@@ -72,30 +93,42 @@ Such a function is easy to give with induction, using the map $ℕ² → ℕ²$
takes a pair `(m,n)` to the pair `(n,n+m)`. Starting the iteration with `(0,1)`
we obtain the Fibonacci sequence by taking the first projection.
-However, we haven't defined cartesian products or booleans yet. Therefore we
-mimic the above idea, using $ℕ → ℕ$ instead of $ℕ²$.
+Furthermore, it is possible to define the fibonacci sequence without using
+cartesian products, mimicing the above idea using $\mathbb{N} \to \matbb{N}$
+instead of $\mathbb{N}^2$.
```agda
-shift-one : ℕ → (ℕ → ℕ) → (ℕ → ℕ)
-shift-one n f = ind-ℕ n (λ x y → f x)
-
-shift-two : ℕ → ℕ → (ℕ → ℕ) → (ℕ → ℕ)
-shift-two m n f = shift-one m (shift-one n f)
-
-Fibo-zero-ℕ : ℕ → ℕ
-Fibo-zero-ℕ = shift-two 0 1 (λ x → 0)
-
-Fibo-succ-ℕ : (ℕ → ℕ) → (ℕ → ℕ)
-Fibo-succ-ℕ f = shift-two (f 1) ((f 1) +ℕ (f 0)) (λ x → 0)
-
-Fibo-function : ℕ → ℕ → ℕ
-Fibo-function =
+shift-one :
+ ℕ → (ℕ → ℕ) → (ℕ → ℕ)
+shift-one n f =
+ ind-ℕ n (λ x y → f x)
+
+shift-two :
+ ℕ → ℕ → (ℕ → ℕ) → (ℕ → ℕ)
+shift-two m n f =
+ shift-one m (shift-one n f)
+
+fibo-zero-ℕ :
+ ℕ → ℕ
+fibo-zero-ℕ =
+ shift-two 0 1 (λ x → 0)
+
+fibo-succ-ℕ :
+ (ℕ → ℕ) → (ℕ → ℕ)
+fibo-succ-ℕ f =
+ shift-two (f 1) ((f 1) +ℕ (f 0)) (λ x → 0)
+
+fibo-function :
+ ℕ → ℕ → ℕ
+fibo-function =
ind-ℕ
- ( Fibo-zero-ℕ)
- ( λ n → Fibo-succ-ℕ)
+ ( fibo-zero-ℕ)
+ ( λ n → fibo-succ-ℕ)
-Fibo : ℕ → ℕ
-Fibo k = Fibo-function k 0
+fibo-ℕ :
+ ℕ → ℕ
+fibo-ℕ k =
+ fibo-function k 0
```
## Properties
@@ -103,67 +136,68 @@ Fibo k = Fibo-function k 0
### `F(m+n+1) = F(m+1)F(n+1) + F(m)F(n)`
```agda
-Fibonacci-add-ℕ :
+fibonacci-add-ℕ :
(m n : ℕ) →
- Fibonacci-ℕ (m +ℕ (succ-ℕ n)) =
- ( (Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ (succ-ℕ n))) +ℕ
- ( (Fibonacci-ℕ m) *ℕ (Fibonacci-ℕ n))
-Fibonacci-add-ℕ m zero-ℕ =
+ fibonacci-ℕ (m +ℕ succ-ℕ n) =
+ fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ (succ-ℕ n) +ℕ
+ fibonacci-ℕ m *ℕ fibonacci-ℕ n
+fibonacci-add-ℕ m zero-ℕ =
ap-add-ℕ
- ( inv (right-unit-law-mul-ℕ (Fibonacci-ℕ (succ-ℕ m))))
- ( inv (right-zero-law-mul-ℕ (Fibonacci-ℕ m)))
-Fibonacci-add-ℕ m (succ-ℕ n) =
- ( ap Fibonacci-ℕ (inv (left-successor-law-add-ℕ m (succ-ℕ n)))) ∙
- ( Fibonacci-add-ℕ (succ-ℕ m) n) ∙
+ ( inv (right-unit-law-mul-ℕ (fibonacci-ℕ (succ-ℕ m))))
+ ( inv (right-zero-law-mul-ℕ (fibonacci-ℕ m)))
+fibonacci-add-ℕ m (succ-ℕ n) =
+ ( ap fibonacci-ℕ (inv (left-successor-law-add-ℕ m (succ-ℕ n)))) ∙
+ ( fibonacci-add-ℕ (succ-ℕ m) n) ∙
( ap
- ( _+ℕ ((Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ n)))
+ ( _+ℕ fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ n)
( right-distributive-mul-add-ℕ
- ( Fibonacci-ℕ (succ-ℕ m))
- ( Fibonacci-ℕ m)
- ( Fibonacci-ℕ (succ-ℕ n)))) ∙
+ ( fibonacci-ℕ (succ-ℕ m))
+ ( fibonacci-ℕ m)
+ ( fibonacci-ℕ (succ-ℕ n)))) ∙
( associative-add-ℕ
- ( (Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ (succ-ℕ n)))
- ( (Fibonacci-ℕ m) *ℕ (Fibonacci-ℕ (succ-ℕ n)))
- ( (Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ n))) ∙
+ ( fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ (succ-ℕ n))
+ ( fibonacci-ℕ m *ℕ fibonacci-ℕ (succ-ℕ n))
+ ( fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ n)) ∙
( ap
- ( ((Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ (succ-ℕ n))) +ℕ_)
+ ( fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ (succ-ℕ n) +ℕ_)
( commutative-add-ℕ
- ( (Fibonacci-ℕ m) *ℕ (Fibonacci-ℕ (succ-ℕ n)))
- ( (Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ n)))) ∙
+ ( fibonacci-ℕ m *ℕ fibonacci-ℕ (succ-ℕ n))
+ ( fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ n))) ∙
( inv
( associative-add-ℕ
- ( (Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ (succ-ℕ n)))
- ( (Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ n))
- ( (Fibonacci-ℕ m) *ℕ (Fibonacci-ℕ (succ-ℕ n))))) ∙
+ ( fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ (succ-ℕ n))
+ ( fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ n)
+ ( fibonacci-ℕ m *ℕ fibonacci-ℕ (succ-ℕ n)))) ∙
( ap
- ( _+ℕ ((Fibonacci-ℕ m) *ℕ (Fibonacci-ℕ (succ-ℕ n))))
+ ( _+ℕ fibonacci-ℕ m *ℕ fibonacci-ℕ (succ-ℕ n))
( inv
( left-distributive-mul-add-ℕ
- ( Fibonacci-ℕ (succ-ℕ m))
- ( Fibonacci-ℕ (succ-ℕ n))
- ( Fibonacci-ℕ n))))
+ ( fibonacci-ℕ (succ-ℕ m))
+ ( fibonacci-ℕ (succ-ℕ n))
+ ( fibonacci-ℕ n))))
```
### Consecutive Fibonacci numbers are relatively prime
```agda
is-one-div-fibonacci-succ-div-fibonacci-ℕ :
- (d n : ℕ) → div-ℕ d (Fibonacci-ℕ n) → div-ℕ d (Fibonacci-ℕ (succ-ℕ n)) →
+ (d n : ℕ) → div-ℕ d (fibonacci-ℕ n) → div-ℕ d (fibonacci-ℕ (succ-ℕ n)) →
is-one-ℕ d
-is-one-div-fibonacci-succ-div-fibonacci-ℕ d zero-ℕ H K = is-one-div-one-ℕ d K
+is-one-div-fibonacci-succ-div-fibonacci-ℕ d zero-ℕ H K =
+ is-one-div-one-ℕ d K
is-one-div-fibonacci-succ-div-fibonacci-ℕ d (succ-ℕ n) H K =
is-one-div-fibonacci-succ-div-fibonacci-ℕ d n
- ( div-right-summand-ℕ d (Fibonacci-ℕ (succ-ℕ n)) (Fibonacci-ℕ n) H K)
+ ( div-right-summand-ℕ d (fibonacci-ℕ (succ-ℕ n)) (fibonacci-ℕ n) H K)
( H)
relatively-prime-fibonacci-fibonacci-succ-ℕ :
- (n : ℕ) → is-relatively-prime-ℕ (Fibonacci-ℕ n) (Fibonacci-ℕ (succ-ℕ n))
+ (n : ℕ) → is-relatively-prime-ℕ (fibonacci-ℕ n) (fibonacci-ℕ (succ-ℕ n))
relatively-prime-fibonacci-fibonacci-succ-ℕ n =
is-one-div-fibonacci-succ-div-fibonacci-ℕ
- ( gcd-ℕ (Fibonacci-ℕ n) (Fibonacci-ℕ (succ-ℕ n)))
+ ( gcd-ℕ (fibonacci-ℕ n) (fibonacci-ℕ (succ-ℕ n)))
( n)
- ( div-left-factor-gcd-ℕ (Fibonacci-ℕ n) (Fibonacci-ℕ (succ-ℕ n)))
- ( div-right-factor-gcd-ℕ (Fibonacci-ℕ n) (Fibonacci-ℕ (succ-ℕ n)))
+ ( div-left-factor-gcd-ℕ (fibonacci-ℕ n) (fibonacci-ℕ (succ-ℕ n)))
+ ( div-right-factor-gcd-ℕ (fibonacci-ℕ n) (fibonacci-ℕ (succ-ℕ n)))
```
### A 3-for-2 property of divisibility of Fibonacci numbers
@@ -171,59 +205,352 @@ relatively-prime-fibonacci-fibonacci-succ-ℕ n =
We prove that if an two of the following three properties hold, then so does the
third:
-1. `d | Fibonacci-ℕ m`
-2. `d | Fibonacci-ℕ n`
-3. `d | Fibonacci-ℕ (m +ℕ n)`.
+1. `d | fibonacci-ℕ m`
+2. `d | fibonacci-ℕ n`
+3. `d | fibonacci-ℕ (m +ℕ n)`.
```agda
-div-Fibonacci-add-ℕ :
- (d m n : ℕ) → div-ℕ d (Fibonacci-ℕ m) → div-ℕ d (Fibonacci-ℕ n) →
- div-ℕ d (Fibonacci-ℕ (m +ℕ n))
-div-Fibonacci-add-ℕ d m zero-ℕ H1 H2 = H1
-div-Fibonacci-add-ℕ d m (succ-ℕ n) H1 H2 =
+div-fibonacci-add-ℕ :
+ (d m n : ℕ) → div-ℕ d (fibonacci-ℕ m) → div-ℕ d (fibonacci-ℕ n) →
+ div-ℕ d (fibonacci-ℕ (m +ℕ n))
+div-fibonacci-add-ℕ d m zero-ℕ H1 H2 =
+ H1
+div-fibonacci-add-ℕ d m (succ-ℕ n) H1 H2 =
tr
( div-ℕ d)
- ( inv (Fibonacci-add-ℕ m n))
+ ( inv (fibonacci-add-ℕ m n))
( div-add-ℕ d
- ( (Fibonacci-ℕ (succ-ℕ m)) *ℕ (Fibonacci-ℕ (succ-ℕ n)))
- ( (Fibonacci-ℕ m) *ℕ (Fibonacci-ℕ n))
- ( div-mul-ℕ (Fibonacci-ℕ (succ-ℕ m)) d (Fibonacci-ℕ (succ-ℕ n)) H2)
+ ( fibonacci-ℕ (succ-ℕ m) *ℕ fibonacci-ℕ (succ-ℕ n))
+ ( fibonacci-ℕ m *ℕ fibonacci-ℕ n)
+ ( div-mul-ℕ (fibonacci-ℕ (succ-ℕ m)) d (fibonacci-ℕ (succ-ℕ n)) H2)
( tr
( div-ℕ d)
- ( commutative-mul-ℕ (Fibonacci-ℕ n) (Fibonacci-ℕ m))
- ( div-mul-ℕ (Fibonacci-ℕ n) d (Fibonacci-ℕ m) H1)))
+ ( commutative-mul-ℕ (fibonacci-ℕ n) (fibonacci-ℕ m))
+ ( div-mul-ℕ (fibonacci-ℕ n) d (fibonacci-ℕ m) H1)))
```
### If `m | n`, then `d | F(m)` implies `d | F(n)`
```agda
-div-Fibonacci-div-ℕ :
- (d m n : ℕ) → div-ℕ m n → div-ℕ d (Fibonacci-ℕ m) → div-ℕ d (Fibonacci-ℕ n)
-div-Fibonacci-div-ℕ d m .zero-ℕ (zero-ℕ , refl) H = div-zero-ℕ d
-div-Fibonacci-div-ℕ d zero-ℕ .(k *ℕ zero-ℕ) (succ-ℕ k , refl) H =
+div-fibonacci-div-ℕ :
+ (d m n : ℕ) → div-ℕ m n → div-ℕ d (fibonacci-ℕ m) → div-ℕ d (fibonacci-ℕ n)
+div-fibonacci-div-ℕ d m .zero-ℕ (zero-ℕ , refl) H =
+ div-zero-ℕ d
+div-fibonacci-div-ℕ d zero-ℕ .(k *ℕ zero-ℕ) (succ-ℕ k , refl) H =
tr
( div-ℕ d)
- ( ap Fibonacci-ℕ (inv (right-zero-law-mul-ℕ (succ-ℕ k))))
+ ( ap fibonacci-ℕ (inv (right-zero-law-mul-ℕ (succ-ℕ k))))
( div-zero-ℕ d)
-div-Fibonacci-div-ℕ d (succ-ℕ m) ._ (succ-ℕ k , refl) H =
- div-Fibonacci-add-ℕ d
- ( k *ℕ (succ-ℕ m))
+div-fibonacci-div-ℕ d (succ-ℕ m) ._ (succ-ℕ k , refl) H =
+ div-fibonacci-add-ℕ d
+ ( k *ℕ succ-ℕ m)
( succ-ℕ m)
- ( div-Fibonacci-div-ℕ d
- ( succ-ℕ m)
- ( k *ℕ (succ-ℕ m))
- ( pair k refl)
- ( H))
+ ( div-fibonacci-div-ℕ d (succ-ℕ m) (k *ℕ succ-ℕ m) (k , refl) H)
( H)
```
-### Fibonacci-ℕ is an order preserving map on ℕ ordered by divisibility
+### The function `fibonacci-ℕ` is an order preserving map on the natural numbers ordered by divisibility
+
+```agda
+preserves-div-fibonacci-ℕ :
+ (m n : ℕ) → div-ℕ m n → div-ℕ (fibonacci-ℕ m) (fibonacci-ℕ n)
+preserves-div-fibonacci-ℕ m n H =
+ div-fibonacci-div-ℕ (fibonacci-ℕ m) m n H (refl-div-ℕ (fibonacci-ℕ m))
+```
+
+### The sum of the first $n + 1$ Fibonacci numbers
+
+We show that
+
+$$
+ \sum_{k=0}^n F_k = F_{n+2}-1
+$$
```agda
-preserves-div-Fibonacci-ℕ :
- (m n : ℕ) → div-ℕ m n → div-ℕ (Fibonacci-ℕ m) (Fibonacci-ℕ n)
-preserves-div-Fibonacci-ℕ m n H =
- div-Fibonacci-div-ℕ (Fibonacci-ℕ m) m n H (refl-div-ℕ (Fibonacci-ℕ m))
+sum-of-fibonacci-ℕ :
+ ℕ → ℕ
+sum-of-fibonacci-ℕ n =
+ bounded-sum-ℕ n (λ k _ → fibonacci-ℕ k)
+
+compute-sum-of-fibonacci-ℕ' :
+ (n : ℕ) → succ-ℕ (sum-of-fibonacci-ℕ n) = fibonacci-ℕ (n +ℕ 2)
+compute-sum-of-fibonacci-ℕ' zero-ℕ =
+ refl
+compute-sum-of-fibonacci-ℕ' (succ-ℕ n) =
+ ( inv
+ ( left-successor-law-add-ℕ
+ ( bounded-sum-ℕ n (λ k _ → fibonacci-ℕ k))
+ ( fibonacci-ℕ (succ-ℕ n)))) ∙
+ ( ap (_+ℕ fibonacci-ℕ (succ-ℕ n)) (compute-sum-of-fibonacci-ℕ' n))
+
+compute-sum-of-fibonacci-ℕ :
+ (n : ℕ) → sum-of-fibonacci-ℕ n = dist-ℕ (fibonacci-ℕ (n +ℕ 2)) 1
+compute-sum-of-fibonacci-ℕ n =
+ ( rewrite-left-add-dist-ℕ
+ ( bounded-sum-ℕ n (λ k _ → fibonacci-ℕ k))
+ ( 1)
+ ( fibonacci-ℕ (n +ℕ 2))
+ ( compute-sum-of-fibonacci-ℕ' n)) ∙
+ ( symmetric-dist-ℕ 1 (fibonacci-ℕ (n +ℕ 2)))
+
+le-sum-of-fibonacci-ℕ :
+ (n : ℕ) → sum-of-fibonacci-ℕ n <-ℕ fibonacci-ℕ (n +ℕ 2)
+le-sum-of-fibonacci-ℕ n =
+ concatenate-le-eq-ℕ
+ ( sum-of-fibonacci-ℕ n)
+ ( succ-ℕ (sum-of-fibonacci-ℕ n))
+ ( fibonacci-ℕ (n +ℕ 2))
+ ( succ-le-ℕ (sum-of-fibonacci-ℕ n))
+ ( compute-sum-of-fibonacci-ℕ' n)
+```
+
+### The sum of the first $n$ oddly indexed Fibonacci numbers
+
+We show that
+
+$$
+ \sum_{k=0}^{n-1} F_{2k+1} = F_{2n}.
+$$
+
+```agda
+strictly-bounded-sum-fibonacci-odd-number-ℕ :
+ ℕ → ℕ
+strictly-bounded-sum-fibonacci-odd-number-ℕ n =
+ strictly-bounded-sum-ℕ n (λ k _ → fibonacci-ℕ (odd-number-ℕ k))
+
+compute-strictly-bounded-sum-fibonacci-odd-number-ℕ :
+ (n : ℕ) →
+ strictly-bounded-sum-fibonacci-odd-number-ℕ n = fibonacci-ℕ (2 *ℕ n)
+compute-strictly-bounded-sum-fibonacci-odd-number-ℕ zero-ℕ =
+ refl
+compute-strictly-bounded-sum-fibonacci-odd-number-ℕ (succ-ℕ n) =
+ ( ap
+ ( _+ℕ fibonacci-ℕ (odd-number-ℕ n))
+ ( compute-strictly-bounded-sum-fibonacci-odd-number-ℕ n)) ∙
+ ( commutative-add-ℕ
+ ( fibonacci-ℕ (2 *ℕ n))
+ ( fibonacci-ℕ (odd-number-ℕ n))) ∙
+ ( inv (ap fibonacci-ℕ (left-distributive-mul-add-ℕ 2 n 1)))
+```
+
+### The sum of the first $n + 1$ evenly indexed Fibonacci numbers
+
+We show that
+
+$$
+ \sum_{k=0}^{n} F_{2k} = F_{2n+1} - 1.
+$$
+
+```agda
+bounded-sum-fibonacci-even-ℕ :
+ ℕ → ℕ
+bounded-sum-fibonacci-even-ℕ n =
+ bounded-sum-ℕ n (λ k _ → fibonacci-ℕ (even-number-ℕ k))
+
+compute-bounded-sum-fibonacci-even-ℕ' :
+ (n : ℕ) →
+ succ-ℕ (bounded-sum-fibonacci-even-ℕ n) = fibonacci-ℕ (odd-number-ℕ n)
+compute-bounded-sum-fibonacci-even-ℕ' zero-ℕ =
+ refl
+compute-bounded-sum-fibonacci-even-ℕ' (succ-ℕ n) =
+ ( right-swap-add-ℕ
+ ( bounded-sum-fibonacci-even-ℕ n)
+ ( fibonacci-ℕ (even-number-ℕ (succ-ℕ n)))
+ ( 1)) ∙
+ ( ap-add-ℕ
+ ( compute-bounded-sum-fibonacci-even-ℕ' n)
+ ( ap fibonacci-ℕ (even-number-succ-ℕ n))) ∙
+ ( commutative-add-ℕ
+ ( fibonacci-ℕ (odd-number-ℕ n))
+ ( fibonacci-ℕ (succ-ℕ (odd-number-ℕ n)))) ∙
+ ( inv (ap fibonacci-ℕ (odd-number-succ-ℕ n)))
+
+compute-bounded-sum-fibonacci-even-ℕ :
+ (n : ℕ) →
+ bounded-sum-fibonacci-even-ℕ n = dist-ℕ (fibonacci-ℕ (odd-number-ℕ n)) 1
+compute-bounded-sum-fibonacci-even-ℕ n =
+ ( rewrite-left-add-dist-ℕ
+ ( bounded-sum-fibonacci-even-ℕ n)
+ ( 1)
+ ( fibonacci-ℕ (odd-number-ℕ n))
+ ( compute-bounded-sum-fibonacci-even-ℕ' n)) ∙
+ ( symmetric-dist-ℕ 1 (fibonacci-ℕ (odd-number-ℕ n)))
+
+le-bounded-sum-fibonacci-even-ℕ :
+ (n : ℕ) → bounded-sum-fibonacci-even-ℕ n <-ℕ fibonacci-ℕ (odd-number-ℕ n)
+le-bounded-sum-fibonacci-even-ℕ n =
+ concatenate-le-eq-ℕ
+ ( bounded-sum-fibonacci-even-ℕ n)
+ ( succ-ℕ (bounded-sum-fibonacci-even-ℕ n))
+ ( fibonacci-ℕ (odd-number-ℕ n))
+ ( succ-le-ℕ (bounded-sum-fibonacci-even-ℕ n))
+ ( compute-bounded-sum-fibonacci-even-ℕ' n)
+```
+
+### A strict bound on the growth of the Fibonacci numbers
+
+The $n$th Fibonacci number is always strictly less than $\phi^n$, where $\phi$
+is the golden ratio. This strict inequality is due to Édouard Lucas, who proved
+it in the late 19th century {{#cite lucas1891}}. We will prove a rational
+version of this claim by showing that $F_n<(\frac{b}{a})^n$ for any rational
+number $\frac{b}{a}>\phi$
+
+A variation of this claim also appears on pages 7 and 8 in section 1.2 of
+{{#cite Leveque12volI}} as an instructive example of a proof by induction, where
+he shows that $F_n<(\frac{7}{4})^n$. This upper bound works for any fraction
+$\frac{b}{a}$ where $a(b+a)Imports
+
+```agda
+open import elementary-number-theory.decidable-subtypes-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.maximal-structured-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.well-ordering-principle-natural-numbers
+
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-subtypes
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.equivalences
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.functoriality-dependent-pair-types
+open import foundation.logical-equivalences
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.subtypes
+open import foundation.type-arithmetic-cartesian-product-types
+open import foundation.type-arithmetic-coproduct-types
+open import foundation.universe-levels
+
+open import univalent-combinatorics.coproduct-types
+open import univalent-combinatorics.finite-maps
+open import univalent-combinatorics.finite-types
+open import univalent-combinatorics.decidable-subtypes
+```
+
+
+
+## Idea
+
+A map $f : A \to \mathbb{N}$ is said to be a
+{{#concept "finite map" Disambiguation="natural numbers"}} if its
+[fibers](foundation-core.finite-types.md) are
+[finite](univalent-combinatorics.finite-types.md).
+
+Finite maps are
+[decidable](elementary-number-theory.decidable-maps-natural-numbers.md). Every
+finite map $f : \mathbb{N} \to \mathbb{N}$ has a definite lowest value, and for
+every finite map $f : \mathbb{N} \to \mathbb{N}$ that takes a value below $B$
+there is a largest number $k$ such that $f(k) \leq b$.
+
+The condition that $f : \mathbb{N} \to \mathbb{N}$ is finite is equivalent to
+the condition that for every natural number $n$, if $f$ has a value below $n$
+there is a maximal number $k$ such that $f(k)\leq n$.
+
+## Definitions
+
+### The predicate of being a finite map into the natural numbers
+
+```agda
+module _
+ {l : Level} {A : UU l} (f : A → ℕ)
+ where
+
+ is-finite-prop-map-ℕ : Prop l
+ is-finite-prop-map-ℕ = is-finite-prop-map f
+
+ is-finite-map-ℕ : UU l
+ is-finite-map-ℕ = is-finite-map f
+
+ is-prop-is-finite-map-ℕ : is-prop is-finite-map-ℕ
+ is-prop-is-finite-map-ℕ = is-prop-is-finite-map f
+```
+
+### The maximal value-bound input property of a function on the natural numbers
+
+The maximal value-bound input property asserts that for every natural number $n$
+there is a maximal number $k$ for which $f(k)\leq n$. Note that it is not
+necessarily the case that the value $f(k)$ is itself maximal.
+
+This property doesn't seem to have a widely recognized name, so we use an
+explicit descriptor. Suggestions are welcome.
+
+```agda
+module _
+ (f : ℕ → ℕ) (n : ℕ)
+ where
+
+ is-value-bound-input-ℕ :
+ (k : ℕ) → UU lzero
+ is-value-bound-input-ℕ k =
+ f k ≤-ℕ n
+
+ is-prop-is-value-bound-input-ℕ :
+ (k : ℕ) → is-prop (is-value-bound-input-ℕ k)
+ is-prop-is-value-bound-input-ℕ k =
+ is-prop-leq-ℕ (f k) n
+
+ is-decidable-is-value-bound-input-ℕ :
+ (k : ℕ) → is-decidable (is-value-bound-input-ℕ k)
+ is-decidable-is-value-bound-input-ℕ k =
+ is-decidable-leq-ℕ (f k) n
+
+ is-value-bound-input-subtype-ℕ :
+ subtype lzero ℕ
+ pr1 (is-value-bound-input-subtype-ℕ k) =
+ is-value-bound-input-ℕ k
+ pr2 (is-value-bound-input-subtype-ℕ k) =
+ is-prop-is-value-bound-input-ℕ k
+
+ is-value-bound-input-decidable-subtype-ℕ :
+ decidable-subtype lzero ℕ
+ pr1 (is-value-bound-input-decidable-subtype-ℕ k) =
+ is-value-bound-input-ℕ k
+ pr1 (pr2 (is-value-bound-input-decidable-subtype-ℕ k)) =
+ is-prop-is-value-bound-input-ℕ k
+ pr2 (pr2 (is-value-bound-input-decidable-subtype-ℕ k)) =
+ is-decidable-is-value-bound-input-ℕ k
+
+maximal-value-bound-input-property-ℕ :
+ (ℕ → ℕ) → UU lzero
+maximal-value-bound-input-property-ℕ f =
+ (n k : ℕ) → f k ≤-ℕ n → maximal-element-ℕ (is-value-bound-input-ℕ f n)
+```
+
+### The maximal structured value-bound input property of a function on the natural numbers
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-structured-value-bound-input-ℕ :
+ (f : ℕ → ℕ) (n k : ℕ) → UU l
+ is-structured-value-bound-input-ℕ f n k =
+ f k ≤-ℕ n × P (f k)
+
+ is-prop-is-structured-value-bound-input-ℕ :
+ ((x : ℕ) → is-prop (P x)) →
+ (f : ℕ → ℕ) (n k : ℕ) → is-prop (is-structured-value-bound-input-ℕ f n k)
+ is-prop-is-structured-value-bound-input-ℕ H f n k =
+ is-prop-product (is-prop-leq-ℕ (f k) n) (H (f k))
+
+ is-decidable-is-structured-value-bound-input-ℕ :
+ is-decidable-fam P → (f : ℕ → ℕ) (n k : ℕ) →
+ is-decidable (is-structured-value-bound-input-ℕ f n k)
+ is-decidable-is-structured-value-bound-input-ℕ d f n k =
+ is-decidable-product (is-decidable-leq-ℕ (f k) n) (d (f k))
+
+module _
+ {l : Level} (P : ℕ → Prop l)
+ where
+
+ is-structured-value-bound-input-subtype-ℕ :
+ (f : ℕ → ℕ) (n : ℕ) → subtype l ℕ
+ pr1 (is-structured-value-bound-input-subtype-ℕ f n k) =
+ is-structured-value-bound-input-ℕ (type-Prop ∘ P) f n k
+ pr2 (is-structured-value-bound-input-subtype-ℕ f n k) =
+ is-prop-is-structured-value-bound-input-ℕ
+ ( type-Prop ∘ P)
+ ( is-prop-type-Prop ∘ P)
+ ( f)
+ ( n)
+ ( k)
+
+module _
+ {l : Level} (P : decidable-subtype l ℕ)
+ where
+
+ is-structured-value-bound-input-decidable-subtype-ℕ :
+ (f : ℕ → ℕ) (n : ℕ) → decidable-subtype l ℕ
+ pr1 (is-structured-value-bound-input-decidable-subtype-ℕ f n k) =
+ is-structured-value-bound-input-ℕ (is-in-decidable-subtype P) f n k
+ pr1 (pr2 (is-structured-value-bound-input-decidable-subtype-ℕ f n k)) =
+ is-prop-is-structured-value-bound-input-ℕ
+ ( is-in-decidable-subtype P)
+ ( is-prop-is-in-decidable-subtype P)
+ ( f)
+ ( n)
+ ( k)
+ pr2 (pr2 (is-structured-value-bound-input-decidable-subtype-ℕ f n k)) =
+ is-decidable-is-structured-value-bound-input-ℕ
+ ( is-in-decidable-subtype P)
+ ( is-decidable-decidable-subtype P)
+ ( f)
+ ( n)
+ ( k)
+
+maximal-structured-value-bound-input-property-ℕ :
+ {l : Level} (P : ℕ → UU l) → (ℕ → ℕ) → UU l
+maximal-structured-value-bound-input-property-ℕ P f =
+ (n k : ℕ) → f k ≤-ℕ n → P (f k) →
+ maximal-element-ℕ (is-structured-value-bound-input-ℕ P f n)
+```
+
+## Properties
+
+### Any finite map on the natural numbers satisfies the maximal value-bound input property
+
+**Proof.** Consider a map $f : \mathbb{N} \to \mathbb{N}$ with finite fibers,
+and consider natural numbers $n$ and $k$ such that $f(k) \leq n$. Since $f$ has
+finite fibers, it follows that the type
+
+$$
+ \sum_{i:\mathbb{N}}f(i)\leq n
+$$
+
+is a finite decidable subtype of the natural numbers, with at least one element.
+
+For the converse, suppose that $f$ satisfies the maximal value-bound input
+property. The fiber of $f$ at $n$ is a decidable subtype of the type
+
+$$
+ \sum_{i:\mathbb{N}}f(i)\leq n.
+$$
+
+Since the type above itself is a decidable subtype of the natural numbers with a
+maximal element, it is finite. It therefore follows that the fiber of $f$ at $n$
+is finite.
+
+```agda
+module _
+ (f : ℕ → ℕ) (H : is-finite-map-ℕ f)
+ where
+
+ is-finite-is-value-bound-input-decidable-subtype-ℕ :
+ (n : ℕ) → is-finite (type-subtype (is-value-bound-input-subtype-ℕ f n))
+ is-finite-is-value-bound-input-decidable-subtype-ℕ zero-ℕ =
+ is-finite-equiv'
+ ( equiv-tot
+ ( λ x →
+ equiv-iff-is-prop
+ ( is-prop-is-value-bound-input-ℕ f 0 x)
+ ( is-set-ℕ (f x) 0)
+ ( is-zero-leq-zero-ℕ (f x))
+ ( leq-eq-ℕ (f x) 0)))
+ ( H 0)
+ is-finite-is-value-bound-input-decidable-subtype-ℕ (succ-ℕ n) =
+ is-finite-equiv'
+ ( left-distributive-Σ-coproduct ℕ _ _ ∘e
+ ( equiv-tot (λ x → compute-leq-succ-ℕ (f x) n)))
+ ( is-finite-coproduct
+ ( is-finite-is-value-bound-input-decidable-subtype-ℕ n)
+ ( H (succ-ℕ n)))
+
+ maximal-value-bound-input-property-is-finite-map-ℕ :
+ maximal-value-bound-input-property-ℕ f
+ maximal-value-bound-input-property-is-finite-map-ℕ n k K =
+ maximal-element-is-finite-decidable-subtype-ℕ
+ ( is-value-bound-input-decidable-subtype-ℕ f n)
+ ( is-finite-is-value-bound-input-decidable-subtype-ℕ n)
+ ( unit-trunc-Prop (k , K))
+
+ nat-maximal-value-bound-input-property-is-finite-map-ℕ :
+ (n k : ℕ) → f k ≤-ℕ n → ℕ
+ nat-maximal-value-bound-input-property-is-finite-map-ℕ n k K =
+ nat-maximal-element-ℕ
+ ( is-value-bound-input-ℕ f n)
+ ( maximal-value-bound-input-property-is-finite-map-ℕ n k K)
+
+ is-upper-bound-nat-maximal-value-bound-input-property-is-finite-map-ℕ :
+ (n k : ℕ) (K : f k ≤-ℕ n) (x : ℕ) → f x ≤-ℕ n →
+ x ≤-ℕ nat-maximal-value-bound-input-property-is-finite-map-ℕ n k K
+ is-upper-bound-nat-maximal-value-bound-input-property-is-finite-map-ℕ n k K =
+ is-upper-bound-maximal-element-ℕ
+ ( is-value-bound-input-ℕ f n)
+ ( maximal-value-bound-input-property-is-finite-map-ℕ n k K)
+
+ is-value-bound-input-maximal-value-bound-input-property-is-finite-map-ℕ :
+ (n k : ℕ) (K : f k ≤-ℕ n) →
+ is-value-bound-input-ℕ f n
+ ( nat-maximal-value-bound-input-property-is-finite-map-ℕ n k K)
+ is-value-bound-input-maximal-value-bound-input-property-is-finite-map-ℕ
+ n k K =
+ structure-maximal-element-ℕ
+ ( is-value-bound-input-ℕ f n)
+ ( maximal-value-bound-input-property-is-finite-map-ℕ n k K)
+```
+
+### Any finite map on the natural numbers satisfies the maximal structured value-bound input property
+
+Consider the following data:
+
+- A family $P$ of decidable types over the natural numbers
+- A finite map $f$
+- A natural number $n$
+- A natural number $k$ such that $f(k) \leq n$ equipped with an element of type
+ $P(f(k))$.
+
+Then there is a largest natural number $m$ such that $f(m) \leq n$ equipped with
+an element of type $P(f(m))$.
+
+**Example.** For any natural number $1 \leq n$ there exists a largest number $m$
+such that $m^2 \mid n$. Indeed, if we let $P(x)$ be the decidable predicate that
+$x$ divides $n$ and $f$ the
+[squaring function](elementary-number-theory.squares-natural-numbers.md). The
+squaring function has finite fibers and we have $1^2 \leq n$ and $1^2 \mid n$.
+The theorem thus gives us a largest number $m$ such that $m^2 \mid n$. We carry
+out this example in the module about
+[Square-free decompositions](elementary-number-theory.square-free-decompositions-natural-numbers.md).
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P)
+ (f : ℕ → ℕ) (H : is-finite-map-ℕ f)
+ where
+
+ maximal-structured-value-bound-input-property-is-finite-map-ℕ :
+ maximal-structured-value-bound-input-property-ℕ P f
+ maximal-structured-value-bound-input-property-is-finite-map-ℕ n k K p =
+ ( ( nat-bounded-maximal-element-ℕ
+ ( λ x → is-value-bound-input-ℕ f n x × P (f x))
+ ( nat-maximal-value-bound-input-property-is-finite-map-ℕ f H n k K)
+ ( b)) ,
+ ( structure-bounded-maximal-element-ℕ
+ ( λ x → is-value-bound-input-ℕ f n x × P (f x))
+ ( nat-maximal-value-bound-input-property-is-finite-map-ℕ f H n k K)
+ ( b)) ,
+ ( λ x (u , v) →
+ is-upper-bound-bounded-maximal-element-ℕ
+ ( λ x → is-value-bound-input-ℕ f n x × P (f x))
+ ( nat-maximal-value-bound-input-property-is-finite-map-ℕ f H n k K)
+ ( b)
+ ( x)
+ ( ( is-upper-bound-nat-maximal-value-bound-input-property-is-finite-map-ℕ
+ f H n k K x u) ,
+ ( u) ,
+ ( v))))
+ where
+
+ b =
+ bounded-maximal-element-instance-ℕ
+ ( λ x → is-value-bound-input-ℕ f n x × P (f x))
+ ( λ x → is-decidable-product (is-decidable-leq-ℕ (f x) n) (d (f x)))
+ ( nat-maximal-value-bound-input-property-is-finite-map-ℕ f H n k K)
+ ( k)
+ ( is-upper-bound-nat-maximal-value-bound-input-property-is-finite-map-ℕ
+ f H n k K k K)
+ ( K , p)
+```
diff --git a/src/elementary-number-theory/fundamental-theorem-of-arithmetic.lagda.md b/src/elementary-number-theory/fundamental-theorem-of-arithmetic.lagda.md
index 6badd26e4b..ecfcab87c3 100644
--- a/src/elementary-number-theory/fundamental-theorem-of-arithmetic.lagda.md
+++ b/src/elementary-number-theory/fundamental-theorem-of-arithmetic.lagda.md
@@ -13,11 +13,15 @@ open import elementary-number-theory.decidable-total-order-natural-numbers
open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.lists-of-prime-numbers
open import elementary-number-theory.lower-bounds-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
open import elementary-number-theory.modular-arithmetic-standard-finite-types
-open import elementary-number-theory.multiplication-lists-of-natural-numbers
+open import elementary-number-theory.products-lists-of-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.multiplicative-decompositions-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.nontrivial-divisors-natural-numbers
open import elementary-number-theory.prime-numbers
open import elementary-number-theory.relatively-prime-natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
@@ -41,10 +45,11 @@ open import foundation.unit-type
open import foundation.universe-levels
open import lists.concatenation-lists
+open import lists.elementhood-relation-lists
open import lists.functoriality-lists
open import lists.lists
open import lists.permutation-lists
-open import lists.predicates-on-lists
+open import lists.universal-quantification-lists
open import lists.sort-by-insertion-lists
open import lists.sorted-lists
```
@@ -73,7 +78,8 @@ in several ways:
[equal](foundation-core.identity-types.md) to `n` is contractible.
Note that the [univalence axiom](foundation-core.univalence.md) is neccessary to
-prove the second uniqueness property of prime factorizations.
+prove the second uniqueness property of prime factorizations. On this page we
+will prove the fundamental theorem using the first approach.
The fundamental theorem of arithmetic is the
[80th](literature.100-theorems.md#80) theorem on
@@ -88,61 +94,84 @@ A list of natural numbers is a prime decomposition of a natural number `n` if:
- The list is sorted.
- Every element of the list is prime.
-- The product of the element of the list is equal to `n`.
+- The list is a
+ [multiplicative decomposition](elementary-number-theory.multiplicative-decompositions-natural-numbers.md)
+ of `n`.
```agda
-is-prime-list-ℕ :
- list ℕ → UU lzero
-is-prime-list-ℕ = for-all-list ℕ is-prime-ℕ-Prop
-
-is-prop-is-prime-list-ℕ :
- (l : list ℕ) → is-prop (is-prime-list-ℕ l)
-is-prop-is-prime-list-ℕ = is-prop-for-all-list ℕ is-prime-ℕ-Prop
-
-is-prime-list-primes-ℕ :
- (l : list Prime-ℕ) → is-prime-list-ℕ (map-list nat-Prime-ℕ l)
-is-prime-list-primes-ℕ nil = raise-star
-is-prime-list-primes-ℕ (cons x l) =
- (is-prime-Prime-ℕ x) , (is-prime-list-primes-ℕ l)
-
module _
(x : ℕ)
(l : list ℕ)
where
- is-decomposition-list-ℕ :
- UU lzero
- is-decomposition-list-ℕ =
- mul-list-ℕ l = x
-
- is-prop-is-decomposition-list-ℕ :
- is-prop (is-decomposition-list-ℕ)
- is-prop-is-decomposition-list-ℕ = is-set-ℕ (mul-list-ℕ l) x
-
is-prime-decomposition-list-ℕ :
UU lzero
is-prime-decomposition-list-ℕ =
is-sorted-list ℕ-Decidable-Total-Order l ×
( is-prime-list-ℕ l ×
- is-decomposition-list-ℕ)
+ is-multiplicative-decomposition-list-ℕ x l)
- is-sorted-list-is-prime-decomposition-list-ℕ :
+ is-sorted-is-prime-decomposition-list-ℕ :
is-prime-decomposition-list-ℕ →
is-sorted-list ℕ-Decidable-Total-Order l
- is-sorted-list-is-prime-decomposition-list-ℕ D = pr1 D
+ is-sorted-is-prime-decomposition-list-ℕ D =
+ pr1 D
is-prime-list-is-prime-decomposition-list-ℕ :
- is-prime-decomposition-list-ℕ →
- is-prime-list-ℕ l
+ is-prime-decomposition-list-ℕ → is-prime-list-ℕ l
is-prime-list-is-prime-decomposition-list-ℕ D =
pr1 (pr2 D)
- is-decomposition-list-is-prime-decomposition-list-ℕ :
+ is-multiplicative-decomposition-is-prime-decomposition-list-ℕ :
is-prime-decomposition-list-ℕ →
- is-decomposition-list-ℕ
- is-decomposition-list-is-prime-decomposition-list-ℕ D =
+ is-multiplicative-decomposition-list-ℕ x l
+ is-multiplicative-decomposition-is-prime-decomposition-list-ℕ D =
pr2 (pr2 D)
+ le-one-list-is-prime-decomposition-list-ℕ :
+ is-prime-decomposition-list-ℕ →
+ for-all-list l (le-ℕ 1)
+ le-one-list-is-prime-decomposition-list-ℕ H =
+ map-for-all-list l
+ ( le-one-is-prime-ℕ)
+ ( is-prime-list-is-prime-decomposition-list-ℕ H)
+
+ leq-one-list-is-prime-decomposition-list-ℕ :
+ is-prime-decomposition-list-ℕ →
+ for-all-list l (leq-ℕ 1)
+ leq-one-list-is-prime-decomposition-list-ℕ H =
+ map-for-all-list l
+ ( leq-le-ℕ 1)
+ ( le-one-list-is-prime-decomposition-list-ℕ H)
+
+ eq-is-prime-decomposition-list-ℕ :
+ is-prime-decomposition-list-ℕ →
+ mul-list-ℕ l = x
+ eq-is-prime-decomposition-list-ℕ H =
+ pr2 (is-multiplicative-decomposition-is-prime-decomposition-list-ℕ H)
+
+ leq-one-is-prime-decomposition-list-ℕ :
+ is-prime-decomposition-list-ℕ → 1 ≤-ℕ x
+ leq-one-is-prime-decomposition-list-ℕ H =
+ tr
+ ( leq-ℕ 1)
+ ( eq-is-prime-decomposition-list-ℕ H)
+ ( leq-one-mul-list-ℕ l (leq-one-list-is-prime-decomposition-list-ℕ H))
+
+ is-list-of-nontrivial-divisors-is-prime-dicomposition-list-ℕ :
+ is-prime-decomposition-list-ℕ →
+ is-list-of-nontrivial-divisors-ℕ x l
+ is-list-of-nontrivial-divisors-is-prime-dicomposition-list-ℕ H =
+ is-list-of-nontrivial-divisors-is-multiplicative-decomposition-list-ℕ x l
+ ( is-multiplicative-decomposition-is-prime-decomposition-list-ℕ H)
+
+ is-list-of-nontrivial-divisors-is-prime-decomposition-list-ℕ :
+ is-prime-decomposition-list-ℕ →
+ is-list-of-nontrivial-divisors-ℕ x l
+ is-list-of-nontrivial-divisors-is-prime-decomposition-list-ℕ D =
+ is-list-of-nontrivial-divisors-is-multiplicative-decomposition-list-ℕ x l
+ ( is-multiplicative-decomposition-is-prime-decomposition-list-ℕ D)
+
is-prop-is-prime-decomposition-list-ℕ :
is-prop (is-prime-decomposition-list-ℕ)
is-prop-is-prime-decomposition-list-ℕ =
@@ -150,323 +179,181 @@ module _
( is-prop-is-sorted-list ℕ-Decidable-Total-Order l)
( is-prop-product
( is-prop-is-prime-list-ℕ l)
- ( is-prop-is-decomposition-list-ℕ))
+ ( is-prop-is-multiplicative-decomposition-list-ℕ x l))
is-prime-decomposition-list-ℕ-Prop : Prop lzero
pr1 is-prime-decomposition-list-ℕ-Prop = is-prime-decomposition-list-ℕ
pr2 is-prime-decomposition-list-ℕ-Prop = is-prop-is-prime-decomposition-list-ℕ
-```
-
-### Nontrivial divisors
-
-Nontrivial divisors of a natural number are divisors strictly greater than `1`.
-```agda
-is-nontrivial-divisor-ℕ : (n x : ℕ) → UU lzero
-is-nontrivial-divisor-ℕ n x = (le-ℕ 1 x) × (div-ℕ x n)
-
-is-prop-is-nontrivial-divisor-ℕ :
- (n x : ℕ) → is-prop (is-nontrivial-divisor-ℕ n x)
-is-prop-is-nontrivial-divisor-ℕ n x =
- is-prop-Σ
- ( is-prop-le-ℕ 1 x)
- ( λ p → is-prop-div-ℕ x n (is-nonzero-le-ℕ 1 x p))
-
-is-nontrivial-divisor-ℕ-Prop : (n x : ℕ) → Prop lzero
-pr1 (is-nontrivial-divisor-ℕ-Prop n x) = is-nontrivial-divisor-ℕ n x
-pr2 (is-nontrivial-divisor-ℕ-Prop n x) = is-prop-is-nontrivial-divisor-ℕ n x
-
-is-decidable-is-nontrivial-divisor-ℕ :
- (n x : ℕ) → is-decidable (is-nontrivial-divisor-ℕ n x)
-is-decidable-is-nontrivial-divisor-ℕ n x =
- is-decidable-product (is-decidable-le-ℕ 1 x) (is-decidable-div-ℕ x n)
-
-is-nontrivial-divisor-diagonal-ℕ :
- (n : ℕ) → le-ℕ 1 n → is-nontrivial-divisor-ℕ n n
-pr1 (is-nontrivial-divisor-diagonal-ℕ n H) = H
-pr2 (is-nontrivial-divisor-diagonal-ℕ n H) = refl-div-ℕ n
-```
+module _
+ (x y : ℕ) (l : list ℕ) (H : is-prime-decomposition-list-ℕ x (cons y l))
+ where
-If `l` is a prime decomposition of `n`, then `l` is a list of nontrivial
-divisors of `n`.
+ is-prime-head-is-prime-decomposition-cons-list-ℕ :
+ is-prime-ℕ y
+ is-prime-head-is-prime-decomposition-cons-list-ℕ =
+ pr1 (is-prime-list-is-prime-decomposition-list-ℕ x (cons y l) H)
-```agda
-is-list-of-nontrivial-divisors-ℕ :
- ℕ → list ℕ → UU lzero
-is-list-of-nontrivial-divisors-ℕ x nil = unit
-is-list-of-nontrivial-divisors-ℕ x (cons y l) =
- (is-nontrivial-divisor-ℕ x y) × (is-list-of-nontrivial-divisors-ℕ x l)
-
-is-nontrivial-divisors-div-list-ℕ :
- (x y : ℕ) → div-ℕ x y → (l : list ℕ) →
- is-list-of-nontrivial-divisors-ℕ x l → is-list-of-nontrivial-divisors-ℕ y l
-is-nontrivial-divisors-div-list-ℕ x y d nil H = star
-is-nontrivial-divisors-div-list-ℕ x y d (cons z l) H =
- ( pr1 (pr1 H) , transitive-div-ℕ z x y d (pr2 (pr1 H))) ,
- is-nontrivial-divisors-div-list-ℕ x y d l (pr2 H)
-
-is-divisor-head-is-decomposition-list-ℕ :
- (x : ℕ) (y : ℕ) (l : list ℕ) →
- is-decomposition-list-ℕ x (cons y l) →
- div-ℕ y x
-pr1 (is-divisor-head-is-decomposition-list-ℕ x y l D) =
- mul-list-ℕ l
-pr2 (is-divisor-head-is-decomposition-list-ℕ x y l D) =
- commutative-mul-ℕ (mul-list-ℕ l) y ∙ D
-
-is-nontrivial-divisor-head-is-decomposition-is-prime-list-ℕ :
- (x : ℕ) (y : ℕ) (l : list ℕ) →
- is-decomposition-list-ℕ x (cons y l) →
- is-prime-list-ℕ (cons y l) →
- is-nontrivial-divisor-ℕ x y
-pr1 (is-nontrivial-divisor-head-is-decomposition-is-prime-list-ℕ x y l D P) =
- le-one-is-prime-ℕ y (pr1 P)
-pr2 (is-nontrivial-divisor-head-is-decomposition-is-prime-list-ℕ x y l D P) =
- is-divisor-head-is-decomposition-list-ℕ x y l D
-
-is-list-of-nontrivial-divisors-is-decomposition-is-prime-list-ℕ :
- (x : ℕ) → (l : list ℕ) →
- is-decomposition-list-ℕ x l →
- is-prime-list-ℕ l →
- is-list-of-nontrivial-divisors-ℕ x l
-is-list-of-nontrivial-divisors-is-decomposition-is-prime-list-ℕ x nil _ _ = star
-is-list-of-nontrivial-divisors-is-decomposition-is-prime-list-ℕ
- ( x)
- ( cons y l)
- ( D)
- ( P) =
- ( is-nontrivial-divisor-head-is-decomposition-is-prime-list-ℕ x y l D P ,
- is-nontrivial-divisors-div-list-ℕ
- ( mul-list-ℕ l)
+ is-prime-tail-is-prime-decomposition-cons-list-ℕ :
+ is-prime-list-ℕ l
+ is-prime-tail-is-prime-decomposition-cons-list-ℕ =
+ pr2 (is-prime-list-is-prime-decomposition-list-ℕ x (cons y l) H)
+
+ le-one-head-is-prime-decomposition-cons-list-ℕ :
+ 1 <-ℕ y
+ le-one-head-is-prime-decomposition-cons-list-ℕ =
+ le-one-is-prime-ℕ y is-prime-head-is-prime-decomposition-cons-list-ℕ
+
+ div-head-is-prime-decomposition-cons-list-ℕ :
+ div-ℕ y x
+ div-head-is-prime-decomposition-cons-list-ℕ =
+ div-head-is-multiplicative-decomposition-cons-list-ℕ
( x)
- ( y , D)
+ ( y)
( l)
- ( is-list-of-nontrivial-divisors-is-decomposition-is-prime-list-ℕ
- ( mul-list-ℕ l)
- ( l)
- ( refl)
- ( pr2 P)))
-
-is-divisor-head-prime-decomposition-list-ℕ :
- (x : ℕ) (y : ℕ) (l : list ℕ) →
- is-prime-decomposition-list-ℕ x (cons y l) →
- div-ℕ y x
-is-divisor-head-prime-decomposition-list-ℕ x y l D =
- is-divisor-head-is-decomposition-list-ℕ
- ( x)
- ( y)
- ( l)
- ( is-decomposition-list-is-prime-decomposition-list-ℕ x (cons y l) D)
-
-is-nontrivial-divisor-head-prime-decomposition-list-ℕ :
- (x : ℕ) (y : ℕ) (l : list ℕ) →
- is-prime-decomposition-list-ℕ x (cons y l) →
- is-nontrivial-divisor-ℕ x y
-is-nontrivial-divisor-head-prime-decomposition-list-ℕ x y l D =
- is-nontrivial-divisor-head-is-decomposition-is-prime-list-ℕ
- ( x)
- ( y)
- ( l)
- ( is-decomposition-list-is-prime-decomposition-list-ℕ x (cons y l) D)
- ( is-prime-list-is-prime-decomposition-list-ℕ x (cons y l) D)
-
-is-list-of-nontrivial-divisors-is-prime-decomposition-list-ℕ :
- (x : ℕ) → (l : list ℕ) →
- is-prime-decomposition-list-ℕ x l →
- is-list-of-nontrivial-divisors-ℕ x l
-is-list-of-nontrivial-divisors-is-prime-decomposition-list-ℕ x l D =
- is-list-of-nontrivial-divisors-is-decomposition-is-prime-list-ℕ
- ( x)
- ( l)
- ( is-decomposition-list-is-prime-decomposition-list-ℕ x l D)
- ( is-prime-list-is-prime-decomposition-list-ℕ x l D)
-```
-
-## Lemmas
-
-### Every natural number strictly greater than `1` has a least nontrivial divisor
-
-```agda
-least-nontrivial-divisor-ℕ :
- (n : ℕ) → le-ℕ 1 n → minimal-element-ℕ (is-nontrivial-divisor-ℕ n)
-least-nontrivial-divisor-ℕ n H =
- well-ordering-principle-ℕ
- ( is-nontrivial-divisor-ℕ n)
- ( is-decidable-is-nontrivial-divisor-ℕ n)
- ( n , is-nontrivial-divisor-diagonal-ℕ n H)
-
-nat-least-nontrivial-divisor-ℕ : (n : ℕ) → le-ℕ 1 n → ℕ
-nat-least-nontrivial-divisor-ℕ n H = pr1 (least-nontrivial-divisor-ℕ n H)
-
-nat-least-nontrivial-divisor-ℕ' : ℕ → ℕ
-nat-least-nontrivial-divisor-ℕ' zero-ℕ = 0
-nat-least-nontrivial-divisor-ℕ' (succ-ℕ zero-ℕ) = 1
-nat-least-nontrivial-divisor-ℕ' (succ-ℕ (succ-ℕ n)) =
- nat-least-nontrivial-divisor-ℕ (succ-ℕ (succ-ℕ n)) star
-
-le-one-least-nontrivial-divisor-ℕ :
- (n : ℕ) (H : le-ℕ 1 n) → le-ℕ 1 (nat-least-nontrivial-divisor-ℕ n H)
-le-one-least-nontrivial-divisor-ℕ n H =
- pr1 (pr1 (pr2 (least-nontrivial-divisor-ℕ n H)))
-
-div-least-nontrivial-divisor-ℕ :
- (n : ℕ) (H : le-ℕ 1 n) → div-ℕ (nat-least-nontrivial-divisor-ℕ n H) n
-div-least-nontrivial-divisor-ℕ n H =
- pr2 (pr1 (pr2 (least-nontrivial-divisor-ℕ n H)))
-
-is-minimal-least-nontrivial-divisor-ℕ :
- (n : ℕ) (H : le-ℕ 1 n) (x : ℕ) (K : le-ℕ 1 x) (d : div-ℕ x n) →
- leq-ℕ (nat-least-nontrivial-divisor-ℕ n H) x
-is-minimal-least-nontrivial-divisor-ℕ n H x K d =
- pr2 (pr2 (least-nontrivial-divisor-ℕ n H)) x (K , d)
-```
-
-### The least nontrivial divisor of a number `> 1` is nonzero
-
-```agda
-abstract
- is-nonzero-least-nontrivial-divisor-ℕ :
- (n : ℕ) (H : le-ℕ 1 n) → is-nonzero-ℕ (nat-least-nontrivial-divisor-ℕ n H)
- is-nonzero-least-nontrivial-divisor-ℕ n H =
- is-nonzero-div-ℕ
- ( nat-least-nontrivial-divisor-ℕ n H)
- ( n)
- ( div-least-nontrivial-divisor-ℕ n H)
- ( λ where refl → H)
-```
-
-### The least nontrivial divisor of a number `> 1` is prime
+ ( is-multiplicative-decomposition-is-prime-decomposition-list-ℕ x
+ ( cons y l)
+ ( H))
+
+ quotient-head-is-prime-decomposition-cons-list-ℕ :
+ ℕ
+ quotient-head-is-prime-decomposition-cons-list-ℕ =
+ quotient-div-ℕ y x div-head-is-prime-decomposition-cons-list-ℕ
+
+ eq-quotient-head-is-prime-decomposition-cons-list-ℕ :
+ quotient-head-is-prime-decomposition-cons-list-ℕ *ℕ y = x
+ eq-quotient-head-is-prime-decomposition-cons-list-ℕ =
+ eq-quotient-div-ℕ y x div-head-is-prime-decomposition-cons-list-ℕ
+
+ leq-one-quotient-head-is-prime-decomposition-cons-list-ℕ :
+ 1 ≤-ℕ quotient-head-is-prime-decomposition-cons-list-ℕ
+ leq-one-quotient-head-is-prime-decomposition-cons-list-ℕ =
+ leq-one-quotient-div-ℕ y x
+ ( div-head-is-prime-decomposition-cons-list-ℕ)
+ ( leq-one-is-prime-decomposition-list-ℕ x (cons y l) H)
+
+ is-nontrivial-divisor-head-is-prime-decomposition-cons-list-ℕ :
+ is-nontrivial-divisor-ℕ x y
+ is-nontrivial-divisor-head-is-prime-decomposition-cons-list-ℕ =
+ is-nontrivial-divisor-head-is-multiplicative-decomposition-cons-list-ℕ
+ ( x)
+ ( y)
+ ( l)
+ ( is-multiplicative-decomposition-is-prime-decomposition-list-ℕ x
+ ( cons y l)
+ ( H))
+
+ le-one-is-prime-decomposition-cons-list-ℕ :
+ le-ℕ 1 x
+ le-one-is-prime-decomposition-cons-list-ℕ =
+ concatenate-le-leq-ℕ 1 y x
+ ( le-one-head-is-prime-decomposition-cons-list-ℕ)
+ ( leq-div-ℕ
+ ( y)
+ ( x)
+ ( is-nonzero-leq-one-ℕ x
+ ( leq-one-is-prime-decomposition-list-ℕ x (cons y l) H))
+ ( div-head-is-prime-decomposition-cons-list-ℕ))
-```agda
-is-prime-least-nontrivial-divisor-ℕ :
- (n : ℕ) (H : le-ℕ 1 n) → is-prime-ℕ (nat-least-nontrivial-divisor-ℕ n H)
-pr1 (is-prime-least-nontrivial-divisor-ℕ n H x) (K , L) =
- map-right-unit-law-coproduct-is-empty
- ( is-one-ℕ x)
- ( le-ℕ 1 x)
- ( λ p →
- contradiction-le-ℕ x l
- ( le-div-ℕ x l
- ( is-nonzero-least-nontrivial-divisor-ℕ n H)
- ( L)
- ( K))
- ( is-minimal-least-nontrivial-divisor-ℕ n H x p
- ( transitive-div-ℕ x l n (div-least-nontrivial-divisor-ℕ n H) L)))
- ( eq-or-le-leq-ℕ' 1 x
- ( leq-one-div-ℕ x n
- ( transitive-div-ℕ x l n
- ( div-least-nontrivial-divisor-ℕ n H) L)
- ( leq-le-ℕ 1 n H)))
- where
- l = nat-least-nontrivial-divisor-ℕ n H
-pr1 (pr2 (is-prime-least-nontrivial-divisor-ℕ n H .1) refl) =
- neq-le-ℕ (le-one-least-nontrivial-divisor-ℕ n H)
-pr2 (pr2 (is-prime-least-nontrivial-divisor-ℕ n H .1) refl) =
- div-one-ℕ _
+ is-sorted-tail-is-prime-decomposition-cons-list-ℕ :
+ is-sorted-list ℕ-Decidable-Total-Order l
+ is-sorted-tail-is-prime-decomposition-cons-list-ℕ =
+ is-sorted-tail-is-sorted-list
+ ( ℕ-Decidable-Total-Order)
+ ( cons y l)
+ ( is-sorted-is-prime-decomposition-list-ℕ x (cons y l) H)
+
+ le-one-tail-is-prime-decomposition-cons-list-ℕ :
+ for-all-list l (le-ℕ 1)
+ le-one-tail-is-prime-decomposition-cons-list-ℕ =
+ pr2 (le-one-list-is-prime-decomposition-list-ℕ x (cons y l) H)
+
+ compute-quotient-head-is-prime-decomposition-cons-list-ℕ :
+ quotient-head-is-prime-decomposition-cons-list-ℕ =
+ mul-list-ℕ l
+ compute-quotient-head-is-prime-decomposition-cons-list-ℕ =
+ is-injective-right-mul-ℕ y
+ ( is-nonzero-is-prime-ℕ y
+ ( is-prime-head-is-prime-decomposition-cons-list-ℕ))
+ ( ( eq-quotient-head-is-prime-decomposition-cons-list-ℕ) ∙
+ ( inv (eq-is-prime-decomposition-list-ℕ x (cons y l) H)) ∙
+ ( commutative-mul-ℕ y (mul-list-ℕ l)))
+
+ is-multiplicative-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ :
+ is-multiplicative-decomposition-list-ℕ
+ ( quotient-head-is-prime-decomposition-cons-list-ℕ)
+ ( l)
+ pr1
+ is-multiplicative-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ =
+ le-one-tail-is-prime-decomposition-cons-list-ℕ
+ pr2
+ is-multiplicative-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ =
+ inv compute-quotient-head-is-prime-decomposition-cons-list-ℕ
+
+ is-prime-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ :
+ is-prime-decomposition-list-ℕ
+ ( quotient-head-is-prime-decomposition-cons-list-ℕ)
+ ( l)
+ is-prime-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ =
+ ( is-sorted-tail-is-prime-decomposition-cons-list-ℕ ,
+ is-prime-tail-is-prime-decomposition-cons-list-ℕ ,
+ is-multiplicative-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ)
```
-### The least prime divisor of a number `1 < n`
+### The type of prime decompositions of a natural number
```agda
-nat-least-prime-divisor-ℕ : (x : ℕ) → le-ℕ 1 x → ℕ
-nat-least-prime-divisor-ℕ x H = nat-least-nontrivial-divisor-ℕ x H
-
-is-prime-least-prime-divisor-ℕ :
- (x : ℕ) (H : le-ℕ 1 x) → is-prime-ℕ (nat-least-prime-divisor-ℕ x H)
-is-prime-least-prime-divisor-ℕ x H = is-prime-least-nontrivial-divisor-ℕ x H
-
-least-prime-divisor-ℕ : (x : ℕ) → le-ℕ 1 x → Prime-ℕ
-pr1 (least-prime-divisor-ℕ x H) = nat-least-prime-divisor-ℕ x H
-pr2 (least-prime-divisor-ℕ x H) = is-prime-least-prime-divisor-ℕ x H
-
-div-least-prime-divisor-ℕ :
- (x : ℕ) (H : le-ℕ 1 x) → div-ℕ (nat-least-prime-divisor-ℕ x H) x
-div-least-prime-divisor-ℕ x H = div-least-nontrivial-divisor-ℕ x H
-
-quotient-div-least-prime-divisor-ℕ :
- (x : ℕ) (H : le-ℕ 1 x) → ℕ
-quotient-div-least-prime-divisor-ℕ x H =
- quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ x H)
- ( x)
- ( div-least-prime-divisor-ℕ x H)
-
-leq-quotient-div-least-prime-divisor-ℕ :
- (x : ℕ) (H : le-ℕ 1 (succ-ℕ x)) →
- leq-ℕ (quotient-div-least-prime-divisor-ℕ (succ-ℕ x) H) x
-leq-quotient-div-least-prime-divisor-ℕ x H =
- leq-quotient-div-is-prime-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ x) H)
- ( x)
- ( is-prime-least-prime-divisor-ℕ (succ-ℕ x) H)
- ( div-least-prime-divisor-ℕ (succ-ℕ x) H)
+prime-decomposition-list-ℕ :
+ (x : ℕ) → UU lzero
+prime-decomposition-list-ℕ x =
+ Σ (list ℕ) (λ l → is-prime-decomposition-list-ℕ x l)
```
-## The fundamental theorem of arithmetic (with lists)
+## The fundamental theorem of arithmetic
### Existence
-#### The list given by the fundamental theorem of arithmetic
+#### The list of primes in the prime decomposition of a number
```agda
-list-primes-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) → leq-ℕ 1 x → list Prime-ℕ
-list-primes-fundamental-theorem-arithmetic-ℕ zero-ℕ ()
-list-primes-fundamental-theorem-arithmetic-ℕ (succ-ℕ x) H =
+successor-step-list-of-primes-fundamental-theorem-arithmetic-ℕ :
+ (n : ℕ) → 1 ≤-ℕ n → ((m : ℕ) → 1 ≤-ℕ m → m ≤-ℕ n → list Prime-ℕ) →
+ list Prime-ℕ
+successor-step-list-of-primes-fundamental-theorem-arithmetic-ℕ n N f =
+ cons
+ ( prime-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
+ ( f
+ ( quotient-div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
+ ( leq-one-quotient-div-ℕ
+ ( nat-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
+ ( succ-ℕ n)
+ ( div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
+ ( leq-succ-leq-ℕ 1 n N))
+ ( upper-bound-quotient-div-least-prime-divisor-ℕ n (le-succ-leq-ℕ 1 n N)))
+
+list-of-primes-fundamental-theorem-arithmetic-ℕ :
+ (n : ℕ) → 1 ≤-ℕ n → list Prime-ℕ
+list-of-primes-fundamental-theorem-arithmetic-ℕ =
based-strong-ind-ℕ 1
- ( λ _ → list Prime-ℕ)
+ ( λ n → list Prime-ℕ)
( nil)
- ( λ n N f →
- cons
- ( least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( f
- ( quotient-div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( leq-one-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( succ-ℕ n)
- ( div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( preserves-leq-succ-ℕ 1 n N))
- ( leq-quotient-div-least-prime-divisor-ℕ n (le-succ-leq-ℕ 1 n N))))
- ( succ-ℕ x)
- ( H)
+ ( successor-step-list-of-primes-fundamental-theorem-arithmetic-ℕ)
list-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) → leq-ℕ 1 x → list ℕ
+ (x : ℕ) → 1 ≤-ℕ x → list ℕ
list-fundamental-theorem-arithmetic-ℕ x H =
- map-list nat-Prime-ℕ (list-primes-fundamental-theorem-arithmetic-ℕ x H)
+ map-list nat-Prime-ℕ (list-of-primes-fundamental-theorem-arithmetic-ℕ x H)
```
-#### Computational rules for the list given by the fundamental theorem of arithmetic
+#### Computation rules for the list of primes in the prime decomposition of a number
```agda
-helper-compute-list-primes-fundamental-theorem-arithmetic-succ-ℕ :
- (x : ℕ) → (H : leq-ℕ 1 x) →
- based-strong-ind-ℕ 1
- ( λ _ → list Prime-ℕ)
- ( nil)
- ( λ n N f →
- cons
- ( least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( f
- ( quotient-div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( leq-one-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( succ-ℕ n)
- ( div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( preserves-leq-succ-ℕ 1 n N))
- ( leq-quotient-div-least-prime-divisor-ℕ n (le-succ-leq-ℕ 1 n N))))
- ( x)
- ( H) =
- list-primes-fundamental-theorem-arithmetic-ℕ x H
-helper-compute-list-primes-fundamental-theorem-arithmetic-succ-ℕ (succ-ℕ x) H =
- refl
-
-compute-list-primes-fundamental-theorem-arithmetic-succ-ℕ :
- (x : ℕ) → (H : 1 ≤-ℕ x) →
- list-primes-fundamental-theorem-arithmetic-ℕ (succ-ℕ x) star =
+compute-list-of-primes-fundamental-theorem-arithmetic-succ-ℕ :
+ (x : ℕ) (H : 1 ≤-ℕ x) →
+ list-of-primes-fundamental-theorem-arithmetic-ℕ (succ-ℕ x) star =
cons
- ( least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( list-primes-fundamental-theorem-arithmetic-ℕ
+ ( prime-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
+ ( list-of-primes-fundamental-theorem-arithmetic-ℕ
( quotient-div-least-prime-divisor-ℕ
( succ-ℕ x)
( le-succ-leq-ℕ 1 x H))
@@ -474,41 +361,20 @@ compute-list-primes-fundamental-theorem-arithmetic-succ-ℕ :
( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
( succ-ℕ x)
( div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( preserves-leq-succ-ℕ 1 x H)))
-compute-list-primes-fundamental-theorem-arithmetic-succ-ℕ x H =
+ ( leq-succ-leq-ℕ 1 x H)))
+compute-list-of-primes-fundamental-theorem-arithmetic-succ-ℕ x H =
compute-succ-based-strong-ind-ℕ
( 1)
( λ _ → list Prime-ℕ)
( nil)
- ( λ n N f →
- cons
- ( least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( f
- ( quotient-div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( leq-one-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( succ-ℕ n)
- ( div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( preserves-leq-succ-ℕ 1 n N))
- ( leq-quotient-div-least-prime-divisor-ℕ n (le-succ-leq-ℕ 1 n N))))
+ ( successor-step-list-of-primes-fundamental-theorem-arithmetic-ℕ)
( x)
( H)
- ( star) ∙
- ap
- ( cons (least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H)))
- ( helper-compute-list-primes-fundamental-theorem-arithmetic-succ-ℕ
- ( quotient-div-least-prime-divisor-ℕ
- ( succ-ℕ x)
- ( le-succ-leq-ℕ 1 x H))
- ( leq-one-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( succ-ℕ x)
- ( div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( preserves-leq-succ-ℕ 1 x H)))
+ ( star)
compute-list-fundamental-theorem-arithmetic-succ-ℕ :
- (x : ℕ) → (H : leq-ℕ 1 x) →
- list-fundamental-theorem-arithmetic-ℕ (succ-ℕ x) star =
+ (x : ℕ) (H : 1 ≤-ℕ x) →
+ list-fundamental-theorem-arithmetic-ℕ (succ-ℕ x) _ =
cons
( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
( list-fundamental-theorem-arithmetic-ℕ
@@ -519,38 +385,52 @@ compute-list-fundamental-theorem-arithmetic-succ-ℕ :
( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
( succ-ℕ x)
( div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( preserves-leq-succ-ℕ 1 x H)))
+ ( leq-succ-leq-ℕ 1 x H)))
compute-list-fundamental-theorem-arithmetic-succ-ℕ x H =
ap
( map-list nat-Prime-ℕ)
- ( compute-list-primes-fundamental-theorem-arithmetic-succ-ℕ x H)
+ ( compute-list-of-primes-fundamental-theorem-arithmetic-succ-ℕ x H)
```
-#### Proof that the list given by the fundamental theorem of arithmetic is a prime decomposition
+#### The list of primes in the prime decomposition of a number is a prime decomposition
```agda
is-prime-list-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) →
+ (x : ℕ) (H : 1 ≤-ℕ x) →
is-prime-list-ℕ (list-fundamental-theorem-arithmetic-ℕ x H)
is-prime-list-fundamental-theorem-arithmetic-ℕ x H =
- is-prime-list-primes-ℕ (list-primes-fundamental-theorem-arithmetic-ℕ x H)
+ is-prime-list-list-Prime-ℕ
+ ( list-of-primes-fundamental-theorem-arithmetic-ℕ x H)
+
+le-one-list-fundamental-theorem-arithmetic-ℕ :
+ (x : ℕ) (H : 1 ≤-ℕ x) →
+ for-all-list (list-fundamental-theorem-arithmetic-ℕ x H) (le-ℕ 1)
+le-one-list-fundamental-theorem-arithmetic-ℕ x H =
+ map-for-all-list
+ ( list-fundamental-theorem-arithmetic-ℕ x H)
+ ( le-one-is-prime-ℕ)
+ ( is-prime-list-fundamental-theorem-arithmetic-ℕ x H)
-is-decomposition-list-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) →
- is-decomposition-list-ℕ x (list-fundamental-theorem-arithmetic-ℕ x H)
-is-decomposition-list-fundamental-theorem-arithmetic-ℕ x H =
+is-multiplicative-decomposition-list-fundamental-theorem-arithmetic-ℕ :
+ (x : ℕ) (H : 1 ≤-ℕ x) →
+ is-multiplicative-decomposition-list-ℕ x
+ ( list-fundamental-theorem-arithmetic-ℕ x H)
+is-multiplicative-decomposition-list-fundamental-theorem-arithmetic-ℕ =
based-strong-ind-ℕ' 1
( λ n N →
- is-decomposition-list-ℕ n (list-fundamental-theorem-arithmetic-ℕ n N))
- ( refl)
+ is-multiplicative-decomposition-list-ℕ n
+ ( list-fundamental-theorem-arithmetic-ℕ n N))
+ ( for-all-nil-list (le-ℕ 1) , refl)
( λ n N f →
- tr
- ( λ p → is-decomposition-list-ℕ (succ-ℕ n) p)
- ( inv (compute-list-fundamental-theorem-arithmetic-succ-ℕ n N))
- ( ( ap
- ( ( nat-least-prime-divisor-ℕ
- ( succ-ℕ n)
- ( le-succ-leq-ℕ 1 n N)) *ℕ_)
+ ( le-one-list-fundamental-theorem-arithmetic-ℕ (succ-ℕ n) star) ,
+ ( ( ap
+ ( mul-list-ℕ)
+ ( compute-list-fundamental-theorem-arithmetic-succ-ℕ n N)) ∙
+ ( ap
+ ( ( nat-least-prime-divisor-ℕ
+ ( succ-ℕ n)
+ ( le-succ-leq-ℕ 1 n N)) *ℕ_)
+ ( pr2
( f
( quotient-div-least-prime-divisor-ℕ
( succ-ℕ n)
@@ -559,33 +439,30 @@ is-decomposition-list-fundamental-theorem-arithmetic-ℕ x H =
( nat-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
( succ-ℕ n)
( div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( preserves-leq-succ-ℕ 1 n N))
- ( leq-quotient-div-least-prime-divisor-ℕ
+ ( leq-succ-leq-ℕ 1 n N))
+ ( upper-bound-quotient-div-least-prime-divisor-ℕ
( n)
- ( le-succ-leq-ℕ 1 n N)))) ∙
- eq-quotient-div-ℕ'
- ( nat-least-prime-divisor-ℕ
- ( succ-ℕ n)
- ( le-succ-leq-ℕ 1 n N))
+ ( le-succ-leq-ℕ 1 n N))))) ∙
+ ( eq-quotient-div-ℕ'
+ ( nat-least-prime-divisor-ℕ
( succ-ℕ n)
- ( div-least-prime-divisor-ℕ
- ( succ-ℕ n)
- ( le-succ-leq-ℕ 1 n N))))
- ( x)
- ( H)
+ ( le-succ-leq-ℕ 1 n N))
+ ( succ-ℕ n)
+ ( div-least-prime-divisor-ℕ
+ ( succ-ℕ n)
+ ( le-succ-leq-ℕ 1 n N)))))
is-list-of-nontrivial-divisors-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) →
+ (x : ℕ) (H : 1 ≤-ℕ x) →
is-list-of-nontrivial-divisors-ℕ x (list-fundamental-theorem-arithmetic-ℕ x H)
is-list-of-nontrivial-divisors-fundamental-theorem-arithmetic-ℕ x H =
- is-list-of-nontrivial-divisors-is-decomposition-is-prime-list-ℕ
+ is-list-of-nontrivial-divisors-is-multiplicative-decomposition-list-ℕ
( x)
( list-fundamental-theorem-arithmetic-ℕ x H)
- ( is-decomposition-list-fundamental-theorem-arithmetic-ℕ x H)
- ( is-prime-list-fundamental-theorem-arithmetic-ℕ x H)
+ ( is-multiplicative-decomposition-list-fundamental-theorem-arithmetic-ℕ x H)
is-least-element-list-least-prime-divisor-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) (l : list ℕ) →
+ (x : ℕ) (H : 1 ≤-ℕ x) (l : list ℕ) →
is-list-of-nontrivial-divisors-ℕ
( quotient-div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
( l) →
@@ -595,7 +472,7 @@ is-least-element-list-least-prime-divisor-ℕ :
( l)
is-least-element-list-least-prime-divisor-ℕ x H nil D = raise-star
is-least-element-list-least-prime-divisor-ℕ x H (cons y l) D =
- is-minimal-least-nontrivial-divisor-ℕ
+ ( is-minimal-least-nontrivial-divisor-ℕ
( succ-ℕ x)
( le-succ-leq-ℕ 1 x H)
( y)
@@ -604,15 +481,12 @@ is-least-element-list-least-prime-divisor-ℕ x H (cons y l) D =
( y)
( quotient-div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
( succ-ℕ x)
- ( div-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( succ-ℕ x)
- ( div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H)))
+ ( div-quotient-div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
( pr2 (pr1 D))) ,
- is-least-element-list-least-prime-divisor-ℕ x H l (pr2 D)
+ is-least-element-list-least-prime-divisor-ℕ x H l (pr2 D))
is-least-element-head-list-fundamental-theorem-arithmetic-succ-ℕ :
- (x : ℕ) → (H : leq-ℕ 1 x) →
+ (x : ℕ) (H : 1 ≤-ℕ x) →
is-least-element-list
( ℕ-Decidable-Total-Order)
( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
@@ -622,28 +496,24 @@ is-least-element-head-list-fundamental-theorem-arithmetic-succ-ℕ :
( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
( succ-ℕ x)
( div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( preserves-leq-succ-ℕ 1 x H)))
+ ( leq-succ-leq-ℕ 1 x H)))
is-least-element-head-list-fundamental-theorem-arithmetic-succ-ℕ x H =
is-least-element-list-least-prime-divisor-ℕ
( x)
( H)
( list-fundamental-theorem-arithmetic-ℕ
( quotient-div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( leq-one-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
+ ( leq-one-quotient-div-least-prime-divisor-ℕ
( succ-ℕ x)
- ( div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( preserves-leq-succ-ℕ 1 x H)))
+ ( le-succ-leq-ℕ 1 x H)))
( is-list-of-nontrivial-divisors-fundamental-theorem-arithmetic-ℕ
( quotient-div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( leq-one-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
+ ( leq-one-quotient-div-least-prime-divisor-ℕ
( succ-ℕ x)
- ( div-least-prime-divisor-ℕ (succ-ℕ x) (le-succ-leq-ℕ 1 x H))
- ( preserves-leq-succ-ℕ 1 x H)))
+ ( le-succ-leq-ℕ 1 x H)))
is-sorted-least-element-list-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) → (H : leq-ℕ 1 x) →
+ (x : ℕ) (H : 1 ≤-ℕ x) →
is-sorted-least-element-list
( ℕ-Decidable-Total-Order)
( list-fundamental-theorem-arithmetic-ℕ x H)
@@ -662,21 +532,19 @@ is-sorted-least-element-list-fundamental-theorem-arithmetic-ℕ x H =
( l))
( inv (compute-list-fundamental-theorem-arithmetic-succ-ℕ n N))
( is-least-element-head-list-fundamental-theorem-arithmetic-succ-ℕ n N ,
- f
- ( quotient-div-least-prime-divisor-ℕ
+ f ( quotient-div-least-prime-divisor-ℕ
( succ-ℕ n)
( le-succ-leq-ℕ 1 n N))
- ( leq-one-quotient-div-ℕ
- ( nat-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
+ ( leq-one-quotient-div-least-prime-divisor-ℕ
( succ-ℕ n)
- ( div-least-prime-divisor-ℕ (succ-ℕ n) (le-succ-leq-ℕ 1 n N))
- ( preserves-leq-succ-ℕ 1 n N))
- ( leq-quotient-div-least-prime-divisor-ℕ n (le-succ-leq-ℕ 1 n N))))
+ ( le-succ-leq-ℕ 1 n N))
+ ( upper-bound-quotient-div-least-prime-divisor-ℕ n
+ ( le-succ-leq-ℕ 1 n N))))
( x)
( H)
is-sorted-list-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) → (H : leq-ℕ 1 x) →
+ (x : ℕ) (H : 1 ≤-ℕ x) →
is-sorted-list
( ℕ-Decidable-Total-Order)
( list-fundamental-theorem-arithmetic-ℕ x H)
@@ -687,134 +555,68 @@ is-sorted-list-fundamental-theorem-arithmetic-ℕ x H =
( is-sorted-least-element-list-fundamental-theorem-arithmetic-ℕ x H)
is-prime-decomposition-list-fundamental-theorem-arithmetic-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) →
+ (x : ℕ) (H : 1 ≤-ℕ x) →
is-prime-decomposition-list-ℕ x (list-fundamental-theorem-arithmetic-ℕ x H)
pr1 (is-prime-decomposition-list-fundamental-theorem-arithmetic-ℕ x H) =
is-sorted-list-fundamental-theorem-arithmetic-ℕ x H
pr1 (pr2 (is-prime-decomposition-list-fundamental-theorem-arithmetic-ℕ x H)) =
is-prime-list-fundamental-theorem-arithmetic-ℕ x H
pr2 (pr2 (is-prime-decomposition-list-fundamental-theorem-arithmetic-ℕ x H)) =
- is-decomposition-list-fundamental-theorem-arithmetic-ℕ x H
+ is-multiplicative-decomposition-list-fundamental-theorem-arithmetic-ℕ x H
+
+prime-decomposition-fundamental-theorem-arithmetic-ℕ :
+ (x : ℕ) (H : 1 ≤-ℕ x) → prime-decomposition-list-ℕ x
+pr1 (prime-decomposition-fundamental-theorem-arithmetic-ℕ x H) =
+ list-fundamental-theorem-arithmetic-ℕ x H
+pr2 (prime-decomposition-fundamental-theorem-arithmetic-ℕ x H) =
+ is-prime-decomposition-list-fundamental-theorem-arithmetic-ℕ x H
```
### Uniqueness
-#### Definition of the type of prime decomposition of an integer
+#### The type of prime decompositions of any natural number is contractible
```agda
-prime-decomposition-list-ℕ :
- (x : ℕ) → (leq-ℕ 1 x) → UU lzero
-prime-decomposition-list-ℕ x _ =
- Σ (list ℕ) (λ l → is-prime-decomposition-list-ℕ x l)
-```
-
-#### `prime-decomposition-list-ℕ n` is contractible for every `n`
-
-```agda
-prime-decomposition-fundamental-theorem-arithmetic-list-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) → prime-decomposition-list-ℕ x H
-pr1 (prime-decomposition-fundamental-theorem-arithmetic-list-ℕ x H) =
- list-fundamental-theorem-arithmetic-ℕ x H
-pr2 (prime-decomposition-fundamental-theorem-arithmetic-list-ℕ x H) =
- is-prime-decomposition-list-fundamental-theorem-arithmetic-ℕ x H
-
-le-one-is-nonempty-prime-decomposition-list-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) (y : ℕ) (l : list ℕ) →
- is-prime-decomposition-list-ℕ x (cons y l) →
- le-ℕ 1 x
-le-one-is-nonempty-prime-decomposition-list-ℕ x H y l D =
- concatenate-le-leq-ℕ
- {x = 1}
- {y = y}
- {z = x}
- ( le-one-is-prime-ℕ
- ( y)
- ( pr1 (is-prime-list-is-prime-decomposition-list-ℕ x (cons y l) D)))
- ( leq-div-ℕ
- ( y)
- ( x)
- ( is-nonzero-leq-one-ℕ x H)
- ( mul-list-ℕ l ,
- ( commutative-mul-ℕ (mul-list-ℕ l) y ∙
- is-decomposition-list-is-prime-decomposition-list-ℕ x (cons y l) D)))
-
-is-in-prime-decomposition-is-nontrivial-prime-divisor-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) (l : list ℕ) →
- is-prime-decomposition-list-ℕ x l →
- ( y : ℕ) →
- div-ℕ y x →
- is-prime-ℕ y →
- y ∈-list l
-is-in-prime-decomposition-is-nontrivial-prime-divisor-ℕ x H nil D y d p =
+is-in-prime-decomposition-is-prime-divisor-ℕ :
+ (x : ℕ) (H : 1 ≤-ℕ x) (l : list ℕ) → is-prime-decomposition-list-ℕ x l →
+ (y : ℕ) → div-ℕ y x → is-prime-ℕ y → y ∈-list l
+is-in-prime-decomposition-is-prime-divisor-ℕ x H nil D y d p =
ex-falso
- ( contradiction-le-ℕ
- ( 1)
- ( x)
- ( concatenate-le-leq-ℕ
- {x = 1}
- {y = y}
- {z = x}
- ( le-one-is-prime-ℕ y p)
- ( leq-div-ℕ
- ( y)
- ( x)
- ( is-nonzero-leq-one-ℕ x H)
- ( d)))
- ( leq-eq-ℕ
- ( x)
- ( 1)
- ( inv (is-decomposition-list-is-prime-decomposition-list-ℕ x nil D))))
-is-in-prime-decomposition-is-nontrivial-prime-divisor-ℕ x H (cons z l) D y d p =
+ ( no-prime-divisors-one-ℕ y p
+ ( tr (div-ℕ y) (inv (eq-is-prime-decomposition-list-ℕ x nil D)) d))
+is-in-prime-decomposition-is-prime-divisor-ℕ x H (cons z l) D y d p =
rec-coproduct
- ( λ e → tr (λ w → w ∈-list (cons z l)) (inv e) (is-head z l))
+ ( λ p → tr (_∈-list cons z l) (inv p) (is-head z l))
( λ e →
- is-in-tail
- ( y)
- ( z)
- ( l)
- ( is-in-prime-decomposition-is-nontrivial-prime-divisor-ℕ
- ( quotient-div-ℕ
- ( z)
- ( x)
- ( is-divisor-head-prime-decomposition-list-ℕ x z l D))
- ( leq-one-quotient-div-ℕ
- ( z)
- ( x)
- ( is-divisor-head-prime-decomposition-list-ℕ x z l D)
- ( H))
+ is-in-tail y z l
+ ( is-in-prime-decomposition-is-prime-divisor-ℕ
+ ( quotient-head-is-prime-decomposition-cons-list-ℕ x z l D)
+ ( leq-one-quotient-head-is-prime-decomposition-cons-list-ℕ
+ x z l D)
( l)
- ( ( is-sorted-tail-is-sorted-list
- ( ℕ-Decidable-Total-Order)
- ( cons z l)
- ( is-sorted-list-is-prime-decomposition-list-ℕ x (cons z l) D)) ,
- ( pr2
- ( is-prime-list-is-prime-decomposition-list-ℕ x (cons z l) D)) ,
- ( refl))
+ ( is-prime-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ
+ x z l D)
( y)
- ( div-right-factor-coprime-ℕ
- ( y)
- ( z)
- ( mul-list-ℕ l)
+ ( div-right-factor-coprime-ℕ y z
+ ( quotient-head-is-prime-decomposition-cons-list-ℕ x z l D)
( tr
- ( λ x → div-ℕ y x)
- ( inv
- ( is-decomposition-list-is-prime-decomposition-list-ℕ
- ( x)
- ( cons z l)
- ( D)))
+ ( div-ℕ y)
+ ( ( inv
+ ( eq-quotient-head-is-prime-decomposition-cons-list-ℕ
+ x z l D)) ∙
+ ( commutative-mul-ℕ _ z))
( d))
( is-relatively-prime-is-prime-ℕ
( y)
( z)
( p)
- ( pr1
- ( is-prime-list-is-prime-decomposition-list-ℕ x (cons z l) D))
+ ( is-prime-head-is-prime-decomposition-cons-list-ℕ x z l D)
( e)))
( p)))
( has-decidable-equality-ℕ y z)
is-lower-bound-head-prime-decomposition-list-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) (y : ℕ) (l : list ℕ) →
+ (x : ℕ) (H : 1 ≤-ℕ x) (y : ℕ) (l : list ℕ) →
is-prime-decomposition-list-ℕ x (cons y l) →
is-lower-bound-ℕ (is-nontrivial-divisor-ℕ x) y
is-lower-bound-head-prime-decomposition-list-ℕ x H y l D m d =
@@ -833,8 +635,8 @@ is-lower-bound-head-prime-decomposition-list-ℕ x H y l D m d =
( y)
( nat-least-prime-divisor-ℕ m (pr1 d))
( l)
- ( is-sorted-list-is-prime-decomposition-list-ℕ x (cons y l) D)
- ( is-in-prime-decomposition-is-nontrivial-prime-divisor-ℕ
+ ( is-sorted-is-prime-decomposition-list-ℕ x (cons y l) D)
+ ( is-in-prime-decomposition-is-prime-divisor-ℕ
( x)
( H)
( cons y l)
@@ -850,7 +652,7 @@ is-lower-bound-head-prime-decomposition-list-ℕ x H y l D m d =
( refl-leq-ℕ y))
eq-head-prime-decomposition-list-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) (y z : ℕ) (p q : list ℕ) →
+ (x : ℕ) (H : 1 ≤-ℕ x) (y z : ℕ) (p q : list ℕ) →
is-prime-decomposition-list-ℕ x (cons y p) →
is-prime-decomposition-list-ℕ x (cons z q) →
y = z
@@ -860,14 +662,14 @@ eq-head-prime-decomposition-list-ℕ x H y z p q I J =
( all-elements-equal-minimal-element-ℕ
( is-nontrivial-divisor-ℕ-Prop x)
( y ,
- is-nontrivial-divisor-head-prime-decomposition-list-ℕ x y p I ,
+ is-nontrivial-divisor-head-is-prime-decomposition-cons-list-ℕ x y p I ,
is-lower-bound-head-prime-decomposition-list-ℕ x H y p I)
( z ,
- is-nontrivial-divisor-head-prime-decomposition-list-ℕ x z q J ,
+ is-nontrivial-divisor-head-is-prime-decomposition-cons-list-ℕ x z q J ,
is-lower-bound-head-prime-decomposition-list-ℕ x H z q J))
eq-prime-decomposition-list-ℕ :
- (x : ℕ) (H : leq-ℕ 1 x) (p q : list ℕ) →
+ (x : ℕ) (H : 1 ≤-ℕ x) (p q : list ℕ) →
is-prime-decomposition-list-ℕ x p →
is-prime-decomposition-list-ℕ x q →
p = q
@@ -878,21 +680,21 @@ eq-prime-decomposition-list-ℕ x H (cons y l) nil I J =
( contradiction-le-ℕ
( 1)
( x)
- ( le-one-is-nonempty-prime-decomposition-list-ℕ x H y l I)
+ ( le-one-is-prime-decomposition-cons-list-ℕ x y l I)
( leq-eq-ℕ
( x)
( 1)
- ( inv ( is-decomposition-list-is-prime-decomposition-list-ℕ x nil J))))
+ ( inv (eq-is-prime-decomposition-list-ℕ x nil J))))
eq-prime-decomposition-list-ℕ x H nil (cons y l) I J =
ex-falso
( contradiction-le-ℕ
( 1)
( x)
- ( le-one-is-nonempty-prime-decomposition-list-ℕ x H y l J)
+ ( le-one-is-prime-decomposition-cons-list-ℕ x y l J)
( leq-eq-ℕ
( x)
( 1)
- ( inv (is-decomposition-list-is-prime-decomposition-list-ℕ x nil I))))
+ ( inv (eq-is-prime-decomposition-list-ℕ x nil I))))
eq-prime-decomposition-list-ℕ x H (cons y l) (cons z p) I J =
eq-Eq-list
( cons y l)
@@ -902,50 +704,29 @@ eq-prime-decomposition-list-ℕ x H (cons y l) (cons z p) I J =
( l)
( p)
( eq-prime-decomposition-list-ℕ
- ( quotient-div-ℕ
- ( y)
- ( x)
- ( is-divisor-head-prime-decomposition-list-ℕ x y l I))
- ( leq-one-quotient-div-ℕ
- ( y)
- ( x)
- ( is-divisor-head-prime-decomposition-list-ℕ x y l I)
- ( H))
+ ( quotient-head-is-prime-decomposition-cons-list-ℕ x y l I)
+ ( leq-one-quotient-head-is-prime-decomposition-cons-list-ℕ x y l I)
( l)
( p)
- ( ( is-sorted-tail-is-sorted-list
- ( ℕ-Decidable-Total-Order)
- ( cons y l)
- ( is-sorted-list-is-prime-decomposition-list-ℕ x (cons y l) I)) ,
- pr2 (is-prime-list-is-prime-decomposition-list-ℕ x (cons y l) I) ,
- refl)
- ( ( is-sorted-tail-is-sorted-list
- ( ℕ-Decidable-Total-Order)
- ( cons z p)
- ( is-sorted-list-is-prime-decomposition-list-ℕ x (cons z p) J)) ,
- pr2 (is-prime-list-is-prime-decomposition-list-ℕ x (cons z p) J) ,
- tr
- ( λ y → is-decomposition-list-ℕ y p)
- ( eq-quotient-div-eq-div-ℕ
- ( z)
- ( y)
- ( x)
- ( is-nonzero-is-prime-ℕ
- ( z)
- ( pr1
- ( is-prime-list-is-prime-decomposition-list-ℕ
- ( x)
- ( cons z p)
- ( J))))
- ( inv (eq-head-prime-decomposition-list-ℕ x H y z l p I J))
- ( is-divisor-head-prime-decomposition-list-ℕ x z p J)
- ( is-divisor-head-prime-decomposition-list-ℕ x y l I))
- ( refl)))))
+ ( is-prime-decomposition-tail-quotient-head-is-prime-decomposition-cons-list-ℕ
+ x y l I)
+ ( ( is-sorted-tail-is-prime-decomposition-cons-list-ℕ x z p J) ,
+ ( is-prime-tail-is-prime-decomposition-cons-list-ℕ x z p J) ,
+ ( le-one-tail-is-prime-decomposition-cons-list-ℕ x z p J) ,
+ ( eq-quotient-div-eq-divisor-ℕ z y x
+ ( is-nonzero-is-prime-ℕ z
+ ( is-prime-head-is-prime-decomposition-cons-list-ℕ x z p J))
+ ( inv (eq-head-prime-decomposition-list-ℕ x H y z l p I J))
+ ( div-head-is-prime-decomposition-cons-list-ℕ x z p J)
+ ( div-head-is-prime-decomposition-cons-list-ℕ x y l I)) ∙
+ ( inv
+ ( compute-quotient-head-is-prime-decomposition-cons-list-ℕ
+ x y l I))))))
fundamental-theorem-arithmetic-list-ℕ :
- (x : ℕ) → (H : leq-ℕ 1 x) → is-contr (prime-decomposition-list-ℕ x H)
+ (x : ℕ) → (H : 1 ≤-ℕ x) → is-contr (prime-decomposition-list-ℕ x)
pr1 (fundamental-theorem-arithmetic-list-ℕ x H) =
- prime-decomposition-fundamental-theorem-arithmetic-list-ℕ x H
+ prime-decomposition-fundamental-theorem-arithmetic-ℕ x H
pr2 (fundamental-theorem-arithmetic-list-ℕ x H) d =
eq-type-subtype
( is-prime-decomposition-list-ℕ-Prop x)
@@ -968,73 +749,58 @@ is-prime-list-concat-list-ℕ nil q Pp Pq = Pq
is-prime-list-concat-list-ℕ (cons x p) q Pp Pq =
pr1 Pp , is-prime-list-concat-list-ℕ p q (pr2 Pp) Pq
-all-elements-is-prime-list-ℕ :
+is-prime-is-in-list-ℕ :
(p : list ℕ) → UU lzero
-all-elements-is-prime-list-ℕ p = (x : ℕ) → x ∈-list p → is-prime-ℕ x
+is-prime-is-in-list-ℕ p = (x : ℕ) → x ∈-list p → is-prime-ℕ x
-all-elements-is-prime-list-tail-ℕ :
- (p : list ℕ) (x : ℕ) (P : all-elements-is-prime-list-ℕ (cons x p)) →
- all-elements-is-prime-list-ℕ p
-all-elements-is-prime-list-tail-ℕ p x P y I = P y (is-in-tail y x p I)
+is-prime-is-in-list-tail-ℕ :
+ (p : list ℕ) (x : ℕ) (P : is-prime-is-in-list-ℕ (cons x p)) →
+ is-prime-is-in-list-ℕ p
+is-prime-is-in-list-tail-ℕ p x P y I = P y (is-in-tail y x p I)
-all-elements-is-prime-list-is-prime-list-ℕ :
- (p : list ℕ) → is-prime-list-ℕ p → all-elements-is-prime-list-ℕ p
-all-elements-is-prime-list-is-prime-list-ℕ (cons x p) P .x (is-head .x .p) =
+is-prime-is-in-list-is-prime-list-ℕ :
+ (p : list ℕ) → is-prime-list-ℕ p → is-prime-is-in-list-ℕ p
+is-prime-is-in-list-is-prime-list-ℕ (cons x p) P .x (is-head .x .p) =
pr1 P
-all-elements-is-prime-list-is-prime-list-ℕ
+is-prime-is-in-list-is-prime-list-ℕ
( cons x p)
( P)
( y)
( is-in-tail .y .x .p I) =
- all-elements-is-prime-list-is-prime-list-ℕ p (pr2 P) y I
+ is-prime-is-in-list-is-prime-list-ℕ p (pr2 P) y I
-is-prime-list-all-elements-is-prime-list-ℕ :
- (p : list ℕ) → all-elements-is-prime-list-ℕ p → is-prime-list-ℕ p
-is-prime-list-all-elements-is-prime-list-ℕ nil P = raise-star
-is-prime-list-all-elements-is-prime-list-ℕ (cons x p) P =
+is-prime-list-is-prime-is-in-list-ℕ :
+ (p : list ℕ) → is-prime-is-in-list-ℕ p → is-prime-list-ℕ p
+is-prime-list-is-prime-is-in-list-ℕ nil P = raise-star
+is-prime-list-is-prime-is-in-list-ℕ (cons x p) P =
P x (is-head x p) ,
- is-prime-list-all-elements-is-prime-list-ℕ
+ is-prime-list-is-prime-is-in-list-ℕ
( p)
- ( all-elements-is-prime-list-tail-ℕ p x P)
+ ( is-prime-is-in-list-tail-ℕ p x P)
is-prime-list-permute-list-ℕ :
- (p : list ℕ) (t : Permutation (length-list p)) → is-prime-list-ℕ p →
+ (p : list ℕ) (t : permutation (length-list p)) → is-prime-list-ℕ p →
is-prime-list-ℕ (permute-list p t)
is-prime-list-permute-list-ℕ p t P =
- is-prime-list-all-elements-is-prime-list-ℕ
+ is-prime-list-is-prime-is-in-list-ℕ
( permute-list p t)
- ( λ x I → all-elements-is-prime-list-is-prime-list-ℕ
- ( p)
- ( P)
- ( x)
- ( is-in-list-is-in-permute-list
- ( p)
- ( t)
- ( x)
- ( I)))
-
-is-decomposition-list-concat-list-ℕ :
- (n m : ℕ) (p q : list ℕ) →
- is-decomposition-list-ℕ n p → is-decomposition-list-ℕ m q →
- is-decomposition-list-ℕ (n *ℕ m) (concat-list p q)
-is-decomposition-list-concat-list-ℕ n m p q Dp Dq =
- ( eq-mul-list-concat-list-ℕ p q ∙
- ( ap (mul-ℕ (mul-list-ℕ p)) Dq ∙
- ap (λ n → n *ℕ m) Dp))
+ ( λ x I →
+ is-prime-is-in-list-is-prime-list-ℕ p P x
+ ( is-in-list-is-in-permute-list p t x I))
is-decomposition-list-permute-list-ℕ :
- (n : ℕ) (p : list ℕ) (t : Permutation (length-list p)) →
- is-decomposition-list-ℕ n p →
- is-decomposition-list-ℕ n (permute-list p t)
+ (n : ℕ) (p : list ℕ) (t : permutation (length-list p)) →
+ is-multiplicative-decomposition-list-ℕ n p →
+ is-multiplicative-decomposition-list-ℕ n (permute-list p t)
is-decomposition-list-permute-list-ℕ n p t D =
- inv (invariant-permutation-mul-list-ℕ p t) ∙ D
+ {!!} -- inv (permutation-invariant-mul-list-ℕ p t) ∙ D
is-prime-decomposition-list-sort-concatenation-ℕ :
- (x y : ℕ) (H : leq-ℕ 1 x) (I : leq-ℕ 1 y) (p q : list ℕ) →
+ (x y : ℕ) (H : 1 ≤-ℕ x) (I : 1 ≤-ℕ y) (p q : list ℕ) →
is-prime-decomposition-list-ℕ x p →
is-prime-decomposition-list-ℕ y q →
is-prime-decomposition-list-ℕ
- (x *ℕ y)
+ ( x *ℕ y)
( insertion-sort-list
( ℕ-Decidable-Total-Order)
( concat-list p q))
@@ -1063,7 +829,7 @@ pr2
( pr2
( is-prime-decomposition-list-sort-concatenation-ℕ x y H I p q Dp Dq)) =
tr
- ( λ p → is-decomposition-list-ℕ (x *ℕ y) p)
+ ( λ p → is-multiplicative-decomposition-list-ℕ (x *ℕ y) p)
( inv
( eq-permute-list-permutation-insertion-sort-list
( ℕ-Decidable-Total-Order)
@@ -1074,19 +840,20 @@ pr2
( permutation-insertion-sort-list
( ℕ-Decidable-Total-Order)
( concat-list p q))
- ( is-decomposition-list-concat-list-ℕ
+ ( is-multiplicative-decomposition-concat-list-ℕ
( x)
( y)
( p)
( q)
- ( is-decomposition-list-is-prime-decomposition-list-ℕ x p Dp)
- ( is-decomposition-list-is-prime-decomposition-list-ℕ y q Dq)))
+ ( is-multiplicative-decomposition-is-prime-decomposition-list-ℕ x p Dp)
+ ( is-multiplicative-decomposition-is-prime-decomposition-list-ℕ
+ y q Dq)))
prime-decomposition-list-sort-concatenation-ℕ :
- (x y : ℕ) (H : leq-ℕ 1 x) (I : leq-ℕ 1 y) (p q : list ℕ) →
+ (x y : ℕ) (H : 1 ≤-ℕ x) (I : 1 ≤-ℕ y) (p q : list ℕ) →
is-prime-decomposition-list-ℕ x p →
is-prime-decomposition-list-ℕ y q →
- prime-decomposition-list-ℕ (x *ℕ y) (preserves-leq-mul-ℕ 1 x 1 y H I)
+ prime-decomposition-list-ℕ (x *ℕ y)
pr1 (prime-decomposition-list-sort-concatenation-ℕ x y H I p q Dp Dq) =
insertion-sort-list ℕ-Decidable-Total-Order (concat-list p q)
pr2 (prime-decomposition-list-sort-concatenation-ℕ x y H I p q Dp Dq) =
diff --git a/src/elementary-number-theory/greatest-common-divisor-integers.lagda.md b/src/elementary-number-theory/greatest-common-divisor-integers.lagda.md
index fc8abf413d..9a1397032f 100644
--- a/src/elementary-number-theory/greatest-common-divisor-integers.lagda.md
+++ b/src/elementary-number-theory/greatest-common-divisor-integers.lagda.md
@@ -17,6 +17,8 @@ open import elementary-number-theory.natural-numbers
open import elementary-number-theory.nonnegative-integers
open import elementary-number-theory.positive-and-negative-integers
open import elementary-number-theory.positive-integers
+open import elementary-number-theory.unit-integers
+open import elementary-number-theory.unit-similarity-integers
open import foundation.action-on-identifications-functions
open import foundation.cartesian-product-types
@@ -127,13 +129,13 @@ is-common-divisor-int-abs-is-common-divisor-ℤ :
{x y d : ℤ} →
is-common-divisor-ℤ x y d → is-common-divisor-ℤ x y (int-abs-ℤ d)
is-common-divisor-int-abs-is-common-divisor-ℤ =
- map-product div-int-abs-div-ℤ div-int-abs-div-ℤ
+ map-product div-int-abs-divisor-div-ℤ div-int-abs-divisor-div-ℤ
is-common-divisor-is-common-divisor-int-abs-ℤ :
{x y d : ℤ} →
is-common-divisor-ℤ x y (int-abs-ℤ d) → is-common-divisor-ℤ x y d
is-common-divisor-is-common-divisor-int-abs-ℤ =
- map-product div-div-int-abs-ℤ div-div-int-abs-ℤ
+ map-product div-div-int-abs-divisor-ℤ div-div-int-abs-divisor-ℤ
is-common-divisor-is-gcd-ℤ :
(a b d : ℤ) → is-gcd-ℤ a b d → is-common-divisor-ℤ a b d
@@ -147,7 +149,7 @@ is-gcd-int-is-gcd-ℕ :
{x y d : ℕ} → is-gcd-ℕ x y d → is-gcd-ℤ (int-ℕ x) (int-ℕ y) (int-ℕ d)
pr1 (is-gcd-int-is-gcd-ℕ {x} {y} {d} H) = is-nonnegative-int-ℕ d
pr1 (pr2 (is-gcd-int-is-gcd-ℕ {x} {y} {d} H) k) =
- ( ( ( ( div-div-int-abs-ℤ) ∘
+ ( ( ( ( div-div-int-abs-divisor-ℤ) ∘
( div-int-div-ℕ)) ∘
( pr1 (H (abs-ℤ k)))) ∘
( is-common-divisor-is-common-divisor-int-ℕ)) ∘
@@ -157,7 +159,7 @@ pr2 (pr2 (is-gcd-int-is-gcd-ℕ {x} {y} {d} H) k) =
( is-common-divisor-int-is-common-divisor-ℕ)) ∘
( pr2 (H (abs-ℤ k)))) ∘
( div-div-int-ℕ)) ∘
- ( div-int-abs-div-ℤ)
+ ( div-int-abs-divisor-div-ℤ)
is-gcd-is-gcd-int-ℕ :
{x y d : ℕ} → is-gcd-ℤ (int-ℕ x) (int-ℕ y) (int-ℕ d) → is-gcd-ℕ x y d
@@ -316,7 +318,7 @@ is-commutative-gcd-ℤ x y =
is-one-is-gcd-one-ℤ : {b x : ℤ} → is-gcd-ℤ one-ℤ b x → is-one-ℤ x
is-one-is-gcd-one-ℤ {b} {x} H with
( is-one-or-neg-one-is-unit-ℤ x
- ( pr1 (is-common-divisor-is-gcd-ℤ one-ℤ b x H)))
+ ( is-unit-div-one-ℤ x (pr1 (is-common-divisor-is-gcd-ℤ one-ℤ b x H))))
... | inl p = p
... | inr p = ex-falso (tr is-nonnegative-ℤ p (pr1 H))
@@ -330,7 +332,7 @@ is-one-gcd-one-ℤ b = is-one-is-gcd-one-ℤ (is-gcd-gcd-ℤ one-ℤ b)
is-one-is-gcd-one-ℤ' : {a x : ℤ} → is-gcd-ℤ a one-ℤ x → is-one-ℤ x
is-one-is-gcd-one-ℤ' {a} {x} H with
( is-one-or-neg-one-is-unit-ℤ x
- ( pr2 (is-common-divisor-is-gcd-ℤ a one-ℤ x H)))
+ ( is-unit-div-one-ℤ x (pr2 (is-common-divisor-is-gcd-ℤ a one-ℤ x H))))
... | inl p = p
... | inr p = ex-falso (tr is-nonnegative-ℤ p (pr1 H))
diff --git a/src/elementary-number-theory/greatest-common-divisor-natural-numbers.lagda.md b/src/elementary-number-theory/greatest-common-divisor-natural-numbers.lagda.md
index 13347d69ac..f580d860e9 100644
--- a/src/elementary-number-theory/greatest-common-divisor-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/greatest-common-divisor-natural-numbers.lagda.md
@@ -15,6 +15,7 @@ open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.euclidean-division-natural-numbers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.lower-bounds-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
open import elementary-number-theory.modular-arithmetic-standard-finite-types
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
@@ -170,7 +171,7 @@ abstract
well-ordering-principle-ℕ
( is-multiple-of-gcd-ℕ a b)
( is-decidable-is-multiple-of-gcd-ℕ a b)
- ( pair (a +ℕ b) (sum-is-multiple-of-gcd-ℕ a b))
+ ( sum-is-multiple-of-gcd-ℕ a b)
gcd-ℕ : ℕ → ℕ → ℕ
gcd-ℕ a b = pr1 (GCD-ℕ a b)
@@ -364,8 +365,8 @@ preserves-is-common-divisor-mul-ℕ :
is-common-divisor-ℕ (k *ℕ a) (k *ℕ b) (k *ℕ d)
preserves-is-common-divisor-mul-ℕ k a b d =
map-product
- ( preserves-div-mul-ℕ k d a)
- ( preserves-div-mul-ℕ k d b)
+ ( preserves-div-left-mul-ℕ k d a)
+ ( preserves-div-left-mul-ℕ k d b)
reflects-is-common-divisor-mul-ℕ :
(k a b d : ℕ) → is-nonzero-ℕ k →
@@ -373,8 +374,8 @@ reflects-is-common-divisor-mul-ℕ :
is-common-divisor-ℕ a b d
reflects-is-common-divisor-mul-ℕ k a b d H =
map-product
- ( reflects-div-mul-ℕ k d a H)
- ( reflects-div-mul-ℕ k d b H)
+ ( reflects-div-left-mul-ℕ k d a H)
+ ( reflects-div-left-mul-ℕ k d b H)
```
### `gcd-ℕ 1 b = 1`
@@ -423,54 +424,54 @@ is-id-is-gcd-zero-ℕ' {a} {x} H = is-id-is-gcd-zero-ℕ {a} {x}
```agda
is-common-divisor-quotients-div-quotient-ℕ :
- {a b d e n : ℕ} → is-nonzero-ℕ e → (H : is-common-divisor-ℕ a b d)
+ {a b d e n : ℕ} → (H : is-common-divisor-ℕ a b d)
(K : div-ℕ e d) → div-ℕ n (quotient-div-ℕ e d K) →
(M : is-common-divisor-ℕ a b e) →
is-common-divisor-ℕ
( quotient-div-ℕ e a (pr1 M))
( quotient-div-ℕ e b (pr2 M))
( n)
-pr1 (is-common-divisor-quotients-div-quotient-ℕ nz H K L M) =
- div-quotient-div-div-quotient-div-ℕ nz (pr1 H) K (pr1 M) L
-pr2 (is-common-divisor-quotients-div-quotient-ℕ nz H K L M) =
- div-quotient-div-div-quotient-div-ℕ nz (pr2 H) K (pr2 M) L
+pr1 (is-common-divisor-quotients-div-quotient-ℕ H K L M) =
+ div-quotient-div-div-quotient-div-ℕ (pr1 H) K (pr1 M) L
+pr2 (is-common-divisor-quotients-div-quotient-ℕ H K L M) =
+ div-quotient-div-div-quotient-div-ℕ (pr2 H) K (pr2 M) L
simplify-is-common-divisor-quotient-div-ℕ :
- {a b d x : ℕ} → is-nonzero-ℕ d → (H : is-common-divisor-ℕ a b d) →
+ {a b d x : ℕ} (H : is-common-divisor-ℕ a b d) →
is-common-divisor-ℕ
( quotient-div-ℕ d a (pr1 H))
( quotient-div-ℕ d b (pr2 H))
( x) ↔
is-common-divisor-ℕ a b (x *ℕ d)
-pr1 (pr1 (simplify-is-common-divisor-quotient-div-ℕ nz H) K) =
- forward-implication (simplify-div-quotient-div-ℕ nz (pr1 H)) (pr1 K)
-pr2 (pr1 (simplify-is-common-divisor-quotient-div-ℕ nz H) K) =
- forward-implication (simplify-div-quotient-div-ℕ nz (pr2 H)) (pr2 K)
-pr1 (pr2 (simplify-is-common-divisor-quotient-div-ℕ nz H) K) =
- backward-implication (simplify-div-quotient-div-ℕ nz (pr1 H)) (pr1 K)
-pr2 (pr2 (simplify-is-common-divisor-quotient-div-ℕ nz H) K) =
- backward-implication (simplify-div-quotient-div-ℕ nz (pr2 H)) (pr2 K)
+pr1 (pr1 (simplify-is-common-divisor-quotient-div-ℕ H) K) =
+ forward-implication (simplify-div-quotient-div-ℕ' (pr1 H)) (pr1 K)
+pr2 (pr1 (simplify-is-common-divisor-quotient-div-ℕ H) K) =
+ forward-implication (simplify-div-quotient-div-ℕ' (pr2 H)) (pr2 K)
+pr1 (pr2 (simplify-is-common-divisor-quotient-div-ℕ H) K) =
+ backward-implication (simplify-div-quotient-div-ℕ' (pr1 H)) (pr1 K)
+pr2 (pr2 (simplify-is-common-divisor-quotient-div-ℕ H) K) =
+ backward-implication (simplify-div-quotient-div-ℕ' (pr2 H)) (pr2 K)
```
### The greatest common divisor of `a/d` and `b/d` is `gcd(a,b)/d`
```agda
is-gcd-quotient-div-gcd-ℕ :
- {a b d : ℕ} → is-nonzero-ℕ d → (H : is-common-divisor-ℕ a b d) →
+ {a b d : ℕ} (H : is-common-divisor-ℕ a b d) →
is-gcd-ℕ
( quotient-div-ℕ d a (pr1 H))
( quotient-div-ℕ d b (pr2 H))
( quotient-div-ℕ d
( gcd-ℕ a b)
( div-gcd-is-common-divisor-ℕ a b d H))
-is-gcd-quotient-div-gcd-ℕ {a} {b} {d} nz H x =
+is-gcd-quotient-div-gcd-ℕ {a} {b} {d} H x =
logical-equivalence-reasoning
is-common-divisor-ℕ
( quotient-div-ℕ d a (pr1 H))
( quotient-div-ℕ d b (pr2 H))
( x)
↔ is-common-divisor-ℕ a b (x *ℕ d)
- by simplify-is-common-divisor-quotient-div-ℕ nz H
+ by simplify-is-common-divisor-quotient-div-ℕ H
↔ div-ℕ (x *ℕ d) (gcd-ℕ a b)
by is-gcd-gcd-ℕ a b (x *ℕ d)
↔ div-ℕ x
@@ -479,7 +480,7 @@ is-gcd-quotient-div-gcd-ℕ {a} {b} {d} nz H x =
( div-gcd-is-common-divisor-ℕ a b d H))
by
inv-iff
- ( simplify-div-quotient-div-ℕ nz
+ ( simplify-div-quotient-div-ℕ'
( div-gcd-is-common-divisor-ℕ a b d H))
```
diff --git a/src/elementary-number-theory/ideals-natural-numbers.lagda.md b/src/elementary-number-theory/ideals-natural-numbers.lagda.md
new file mode 100644
index 0000000000..9c0ab95264
--- /dev/null
+++ b/src/elementary-number-theory/ideals-natural-numbers.lagda.md
@@ -0,0 +1,17 @@
+# Ideals of natural numbers
+
+```agda
+module elementary-number-theory.ideals-natural-numbers where
+```
+
+Imports
+
+```agda
+
+```
+
+
+
+## Idea
+
+Since the [natural numbers](elementary-number-theory.natural-numbers.md) only form a [commutative semiring](elementary-number-theory.commutative-semiring-of-natural-numbers.md), their ideals aren't as easily defined as [ideals](ring-theory.ideals-rings.md) on a [ring](ring-theory.rings.md)
diff --git a/src/elementary-number-theory/inequality-integer-fractions.lagda.md b/src/elementary-number-theory/inequality-integer-fractions.lagda.md
index e87b85c1c3..5dba1c8552 100644
--- a/src/elementary-number-theory/inequality-integer-fractions.lagda.md
+++ b/src/elementary-number-theory/inequality-integer-fractions.lagda.md
@@ -167,8 +167,8 @@ module _
(p q p' q' : fraction-ℤ) (H : sim-fraction-ℤ p p') (K : sim-fraction-ℤ q q')
where
- preserves-leq-sim-fraction-ℤ : leq-fraction-ℤ p q → leq-fraction-ℤ p' q'
- preserves-leq-sim-fraction-ℤ I =
+ leq-sim-fraction-ℤ : leq-fraction-ℤ p q → leq-fraction-ℤ p' q'
+ leq-sim-fraction-ℤ I =
concatenate-sim-leq-fraction-ℤ p' p q'
( symmetric-sim-fraction-ℤ p p' H)
( concatenate-leq-sim-fraction-ℤ p q q' I K)
diff --git a/src/elementary-number-theory/inequality-integers.lagda.md b/src/elementary-number-theory/inequality-integers.lagda.md
index 1e9c9063f6..14159cf347 100644
--- a/src/elementary-number-theory/inequality-integers.lagda.md
+++ b/src/elementary-number-theory/inequality-integers.lagda.md
@@ -22,19 +22,18 @@ open import elementary-number-theory.positive-integers
open import foundation.action-on-identifications-functions
open import foundation.coproduct-types
open import foundation.decidable-propositions
+open import foundation.decidable-types
open import foundation.dependent-pair-types
open import foundation.function-types
open import foundation.functoriality-coproduct-types
open import foundation.identity-types
open import foundation.negated-equality
open import foundation.negation
+open import foundation.propositional-truncations
open import foundation.propositions
open import foundation.transport-along-identifications
open import foundation.unit-type
open import foundation.universe-levels
-
-open import order-theory.posets
-open import order-theory.preorders
```
@@ -49,220 +48,391 @@ defines the
{{#concept "standard ordering" Disambiguation="integers" Agda=leq-ℤ}} on the
integers.
+Alternatively, the standard ordering can be defined as a `data` type by
+specifying the constructors
+
+```text
+ r : (x : ℤ) → x ≤ x
+ s : (x y : ℤ) → x ≤ y → x ≤ y + 1.
+```
+
+We will introduce both orderings and prove that they are equivalent.
+
## Definition
### Inequality on the integers
```agda
leq-ℤ-Prop : ℤ → ℤ → Prop lzero
-leq-ℤ-Prop x y = subtype-nonnegative-ℤ (y -ℤ x)
+leq-ℤ-Prop a b = subtype-nonnegative-ℤ (b -ℤ a)
leq-ℤ : ℤ → ℤ → UU lzero
-leq-ℤ x y = type-Prop (leq-ℤ-Prop x y)
+leq-ℤ a b = type-Prop (leq-ℤ-Prop a b)
-is-prop-leq-ℤ : (x y : ℤ) → is-prop (leq-ℤ x y)
-is-prop-leq-ℤ x y = is-prop-type-Prop (leq-ℤ-Prop x y)
+is-prop-leq-ℤ : (a b : ℤ) → is-prop (leq-ℤ a b)
+is-prop-leq-ℤ a b = is-prop-type-Prop (leq-ℤ-Prop a b)
infix 30 _≤-ℤ_
_≤-ℤ_ = leq-ℤ
```
+### Inductive definition of inequality on the integers
+
+```agda
+data
+ inductive-leq-ℤ :
+ ℤ → ℤ → UU lzero
+ where
+
+ refl-inductive-leq-ℤ :
+ (a : ℤ) → inductive-leq-ℤ a a
+
+ succ-inductive-leq-ℤ :
+ (a b : ℤ) → inductive-leq-ℤ a b → inductive-leq-ℤ a (succ-ℤ b)
+
+refl-inductive-leq-ℤ' :
+ (a b : ℤ) → a = b → inductive-leq-ℤ a b
+refl-inductive-leq-ℤ' a .a refl = refl-inductive-leq-ℤ a
+
+succ-inductive-leq-ℤ' :
+ (a b c : ℤ) (p : succ-ℤ b = c) → inductive-leq-ℤ a b → inductive-leq-ℤ a c
+succ-inductive-leq-ℤ' a b .(succ-ℤ b) refl H = succ-inductive-leq-ℤ a b H
+```
+
## Properties
### Inequality on the integers is reflexive, antisymmetric and transitive
```agda
-refl-leq-ℤ : (k : ℤ) → leq-ℤ k k
-refl-leq-ℤ k = tr is-nonnegative-ℤ (inv (right-inverse-law-add-ℤ k)) star
+refl-leq-ℤ : (a : ℤ) → a ≤-ℤ a
+refl-leq-ℤ a = tr is-nonnegative-ℤ (inv (right-inverse-law-add-ℤ a)) star
-antisymmetric-leq-ℤ : {x y : ℤ} → leq-ℤ x y → leq-ℤ y x → x = y
-antisymmetric-leq-ℤ {x} {y} H K =
+antisymmetric-leq-ℤ : {a b : ℤ} → a ≤-ℤ b → b ≤-ℤ a → a = b
+antisymmetric-leq-ℤ {a} {b} H K =
eq-diff-ℤ
( is-zero-is-nonnegative-neg-is-nonnegative-ℤ K
- ( is-nonnegative-eq-ℤ (inv (distributive-neg-diff-ℤ x y)) H))
+ ( is-nonnegative-eq-ℤ (inv (distributive-neg-diff-ℤ a b)) H))
-transitive-leq-ℤ : (k l m : ℤ) → leq-ℤ l m → leq-ℤ k l → leq-ℤ k m
-transitive-leq-ℤ k l m H K =
+transitive-leq-ℤ : (a b c : ℤ) → b ≤-ℤ c → a ≤-ℤ b → a ≤-ℤ c
+transitive-leq-ℤ a b c H K =
is-nonnegative-eq-ℤ
- ( triangle-diff-ℤ m l k)
+ ( triangle-diff-ℤ c b a)
( is-nonnegative-add-ℤ H K)
```
### Inequality on the integers is decidable
```agda
-is-decidable-leq-ℤ : (x y : ℤ) → (leq-ℤ x y) + ¬ (leq-ℤ x y)
-is-decidable-leq-ℤ x y = is-decidable-is-nonnegative-ℤ (y -ℤ x)
-
-leq-ℤ-Decidable-Prop : (x y : ℤ) → Decidable-Prop lzero
-leq-ℤ-Decidable-Prop x y =
- ( leq-ℤ x y ,
- is-prop-leq-ℤ x y ,
- is-decidable-leq-ℤ x y)
+is-decidable-leq-ℤ : (a b : ℤ) → is-decidable (a ≤-ℤ b)
+is-decidable-leq-ℤ a b = is-decidable-is-nonnegative-ℤ (b -ℤ a)
+
+leq-ℤ-Decidable-Prop : (a b : ℤ) → Decidable-Prop lzero
+pr1 (leq-ℤ-Decidable-Prop a b) = a ≤-ℤ b
+pr1 (pr2 (leq-ℤ-Decidable-Prop a b)) = is-prop-leq-ℤ a b
+pr2 (pr2 (leq-ℤ-Decidable-Prop a b)) = is-decidable-leq-ℤ a b
```
### Inequality on the integers is linear
```agda
-linear-leq-ℤ : (x y : ℤ) → (leq-ℤ x y) + (leq-ℤ y x)
-linear-leq-ℤ x y =
+linear-leq-ℤ : (a b : ℤ) → (a ≤-ℤ b) + (b ≤-ℤ a)
+linear-leq-ℤ a b =
map-coproduct
( λ H →
is-nonnegative-is-positive-ℤ
( is-positive-eq-ℤ
- ( distributive-neg-diff-ℤ x y)
+ ( distributive-neg-diff-ℤ a b)
( is-positive-neg-is-negative-ℤ H)))
( id)
( decide-is-negative-is-nonnegative-ℤ)
```
+### Chaining rules for equality and inequality
+
+```agda
+concatenate-eq-leq-eq-ℤ :
+ {a b c d : ℤ} → a = b → b ≤-ℤ c → c = d → a ≤-ℤ d
+concatenate-eq-leq-eq-ℤ refl H refl = H
+
+concatenate-leq-eq-ℤ :
+ (a : ℤ) {b c : ℤ} → a ≤-ℤ b → b = c → a ≤-ℤ c
+concatenate-leq-eq-ℤ a H refl = H
+
+concatenate-eq-leq-ℤ :
+ {a b : ℤ} (c : ℤ) → a = b → b ≤-ℤ c → a ≤-ℤ c
+concatenate-eq-leq-ℤ c refl H = H
+```
+
### An integer is lesser than its successor
```agda
-succ-leq-ℤ : (k : ℤ) → leq-ℤ k (succ-ℤ k)
-succ-leq-ℤ k =
+succ-leq-ℤ : (a : ℤ) → a ≤-ℤ succ-ℤ a
+succ-leq-ℤ a =
is-nonnegative-eq-ℤ
( inv
- ( ( left-successor-law-add-ℤ k (neg-ℤ k)) ∙
- ( ap succ-ℤ (right-inverse-law-add-ℤ k))))
+ ( ( left-successor-law-add-ℤ a (neg-ℤ a)) ∙
+ ( ap succ-ℤ (right-inverse-law-add-ℤ a))))
( star)
-leq-ℤ-succ-leq-ℤ : (k l : ℤ) → leq-ℤ k l → leq-ℤ k (succ-ℤ l)
-leq-ℤ-succ-leq-ℤ k l = transitive-leq-ℤ k l (succ-ℤ l) (succ-leq-ℤ l)
+leq-succ-leq-ℤ : (a b : ℤ) → a ≤-ℤ b → a ≤-ℤ succ-ℤ b
+leq-succ-leq-ℤ a b = transitive-leq-ℤ a b (succ-ℤ b) (succ-leq-ℤ b)
```
-### Chaining rules for equality and inequality
+### Inequality on the integers is equivalent to the inductively defined inequality on the integers
```agda
-concatenate-eq-leq-eq-ℤ :
- {x' x y y' : ℤ} → x' = x → leq-ℤ x y → y = y' → leq-ℤ x' y'
-concatenate-eq-leq-eq-ℤ refl H refl = H
-
-concatenate-leq-eq-ℤ :
- (x : ℤ) {y y' : ℤ} → leq-ℤ x y → y = y' → leq-ℤ x y'
-concatenate-leq-eq-ℤ x H refl = H
-
-concatenate-eq-leq-ℤ :
- {x x' : ℤ} (y : ℤ) → x' = x → leq-ℤ x y → leq-ℤ x' y
-concatenate-eq-leq-ℤ y refl H = H
+leq-inductive-leq-ℤ :
+ (a b : ℤ) → inductive-leq-ℤ a b → a ≤-ℤ b
+leq-inductive-leq-ℤ a .a (refl-inductive-leq-ℤ .a) =
+ refl-leq-ℤ a
+leq-inductive-leq-ℤ a .(succ-ℤ b) (succ-inductive-leq-ℤ .a b H) =
+ leq-succ-leq-ℤ a b (leq-inductive-leq-ℤ a b H)
+
+inductive-leq-leq-ℤ' :
+ (a b c : ℤ) (p : diff-ℤ b a = c) → is-nonnegative-ℤ c → inductive-leq-ℤ a b
+inductive-leq-leq-ℤ' a b (inr (inl star)) p H =
+ refl-inductive-leq-ℤ' a b (inv (eq-diff-ℤ p))
+inductive-leq-leq-ℤ' a b (inr (inr zero-ℕ)) p star =
+ succ-inductive-leq-ℤ' a a b
+ ( is-left-add-one-succ-ℤ a ∙
+ ap (_+ℤ a) (inv p) ∙
+ is-section-right-add-neg-ℤ a b)
+ ( refl-inductive-leq-ℤ a)
+inductive-leq-leq-ℤ' a b (inr (inr (succ-ℕ x))) p star =
+ succ-inductive-leq-ℤ' a
+ ( a +ℤ inr (inr x))
+ ( b)
+ ( inv (right-successor-law-add-ℤ a (inr (inr x))) ∙
+ ap (a +ℤ_) (inv p) ∙
+ commutative-add-ℤ a (diff-ℤ b a) ∙
+ is-section-right-add-neg-ℤ a b)
+ ( inductive-leq-leq-ℤ' a
+ ( a +ℤ inr (inr x))
+ ( inr (inr x))
+ ( commutative-add-ℤ (a +ℤ inr (inr x)) (neg-ℤ a) ∙
+ is-retraction-left-add-neg-ℤ a (inr (inr x)))
+ ( star))
+
+inductive-leq-leq-ℤ :
+ (a b : ℤ) → a ≤-ℤ b → inductive-leq-ℤ a b
+inductive-leq-leq-ℤ a b =
+ inductive-leq-leq-ℤ' a b (diff-ℤ b a) refl
```
### Addition on the integers preserves inequality
```agda
-preserves-leq-left-add-ℤ :
- (z x y : ℤ) → leq-ℤ x y → leq-ℤ (x +ℤ z) (y +ℤ z)
-preserves-leq-left-add-ℤ z x y =
- is-nonnegative-eq-ℤ (inv (right-translation-diff-ℤ y x z))
-
-preserves-leq-right-add-ℤ :
- (z x y : ℤ) → leq-ℤ x y → leq-ℤ (z +ℤ x) (z +ℤ y)
-preserves-leq-right-add-ℤ z x y =
- is-nonnegative-eq-ℤ (inv (left-translation-diff-ℤ y x z))
-
-preserves-leq-add-ℤ :
- {a b c d : ℤ} → leq-ℤ a b → leq-ℤ c d → leq-ℤ (a +ℤ c) (b +ℤ d)
-preserves-leq-add-ℤ {a} {b} {c} {d} H K =
+preserves-order-left-add-ℤ :
+ (c a b : ℤ) → a ≤-ℤ b → a +ℤ c ≤-ℤ b +ℤ c
+preserves-order-left-add-ℤ c a b =
+ is-nonnegative-eq-ℤ (inv (right-translation-diff-ℤ b a c))
+
+preserves-order-right-add-ℤ :
+ (c a b : ℤ) → a ≤-ℤ b → c +ℤ a ≤-ℤ c +ℤ b
+preserves-order-right-add-ℤ c a b =
+ is-nonnegative-eq-ℤ (inv (left-translation-diff-ℤ b a c))
+
+preserves-order-add-ℤ :
+ {a b c d : ℤ} → a ≤-ℤ b → c ≤-ℤ d → a +ℤ c ≤-ℤ b +ℤ d
+preserves-order-add-ℤ {a} {b} {c} {d} H K =
transitive-leq-ℤ
( a +ℤ c)
( b +ℤ c)
( b +ℤ d)
- ( preserves-leq-right-add-ℤ b c d K)
- ( preserves-leq-left-add-ℤ c a b H)
+ ( preserves-order-right-add-ℤ b c d K)
+ ( preserves-order-left-add-ℤ c a b H)
```
### Addition on the integers reflects inequality
```agda
-reflects-leq-left-add-ℤ :
- (z x y : ℤ) → leq-ℤ (x +ℤ z) (y +ℤ z) → leq-ℤ x y
-reflects-leq-left-add-ℤ z x y =
- is-nonnegative-eq-ℤ (right-translation-diff-ℤ y x z)
-
-reflects-leq-right-add-ℤ :
- (z x y : ℤ) → leq-ℤ (z +ℤ x) (z +ℤ y) → leq-ℤ x y
-reflects-leq-right-add-ℤ z x y =
- is-nonnegative-eq-ℤ (left-translation-diff-ℤ y x z)
+reflects-order-left-add-ℤ :
+ (c a b : ℤ) → a +ℤ c ≤-ℤ b +ℤ c → a ≤-ℤ b
+reflects-order-left-add-ℤ c a b =
+ is-nonnegative-eq-ℤ (right-translation-diff-ℤ b a c)
+
+reflects-order-right-add-ℤ :
+ (c a b : ℤ) → c +ℤ a ≤-ℤ c +ℤ b → a ≤-ℤ b
+reflects-order-right-add-ℤ c a b =
+ is-nonnegative-eq-ℤ (left-translation-diff-ℤ b a c)
```
### The inclusion of ℕ into ℤ preserves inequality
```agda
-leq-int-ℕ : (x y : ℕ) → leq-ℕ x y → leq-ℤ (int-ℕ x) (int-ℕ y)
-leq-int-ℕ zero-ℕ y H =
+leq-int-ℕ : (m n : ℕ) → m ≤-ℕ n → int-ℕ m ≤-ℤ int-ℕ n
+leq-int-ℕ zero-ℕ n H =
tr
( is-nonnegative-ℤ)
- ( inv (right-unit-law-add-ℤ (int-ℕ y)))
- ( is-nonnegative-int-ℕ y)
-leq-int-ℕ (succ-ℕ x) (succ-ℕ y) H = tr (is-nonnegative-ℤ)
- ( inv (diff-succ-ℤ (int-ℕ y) (int-ℕ x)) ∙
- ( ap (_-ℤ (succ-ℤ (int-ℕ x))) (succ-int-ℕ y) ∙
- ap ((int-ℕ (succ-ℕ y)) -ℤ_) (succ-int-ℕ x)))
- ( leq-int-ℕ x y H)
+ ( inv (right-unit-law-add-ℤ (int-ℕ n)))
+ ( is-nonnegative-int-ℕ n)
+leq-int-ℕ (succ-ℕ m) (succ-ℕ n) H = tr (is-nonnegative-ℤ)
+ ( inv (diff-succ-ℤ (int-ℕ n) (int-ℕ m)) ∙
+ ( ap (_-ℤ (succ-ℤ (int-ℕ m))) (succ-int-ℕ n) ∙
+ ap ((int-ℕ (succ-ℕ n)) -ℤ_) (succ-int-ℕ m)))
+ ( leq-int-ℕ m n H)
```
-### The partially ordered set of integers ordered by inequality
+### Transposing summands in inequalities
```agda
-ℤ-Preorder : Preorder lzero lzero
-ℤ-Preorder =
- (ℤ , leq-ℤ-Prop , refl-leq-ℤ , transitive-leq-ℤ)
+transpose-left-summand-leq-ℤ :
+ (a b c : ℤ) → a ≤-ℤ b +ℤ c → neg-ℤ b +ℤ a ≤-ℤ c
+transpose-left-summand-leq-ℤ a b c H =
+ reflects-order-right-add-ℤ b
+ ( neg-ℤ b +ℤ a)
+ ( c)
+ ( concatenate-eq-leq-ℤ (b +ℤ c) (is-section-left-add-neg-ℤ b a) H)
+
+inv-transpose-left-summand-leq-ℤ :
+ (a b c : ℤ) → neg-ℤ b +ℤ a ≤-ℤ c → a ≤-ℤ b +ℤ c
+inv-transpose-left-summand-leq-ℤ a b c H =
+ concatenate-eq-leq-ℤ
+ ( b +ℤ c)
+ ( inv (is-section-left-add-neg-ℤ b a))
+ ( preserves-order-right-add-ℤ b (neg-ℤ b +ℤ a) c H)
+
+transpose-left-summand-leq-ℤ' :
+ (a b c : ℤ) → b +ℤ a ≤-ℤ c → a ≤-ℤ neg-ℤ b +ℤ c
+transpose-left-summand-leq-ℤ' a b c H =
+ inv-transpose-left-summand-leq-ℤ a (neg-ℤ b) c
+ ( concatenate-eq-leq-ℤ c (ap (add-ℤ' a) (neg-neg-ℤ b)) H)
+
+inv-transpose-left-summand-leq-ℤ' :
+ (a b c : ℤ) → a ≤-ℤ neg-ℤ b +ℤ c → b +ℤ a ≤-ℤ c
+inv-transpose-left-summand-leq-ℤ' a b c H =
+ concatenate-eq-leq-ℤ c
+ ( ap (add-ℤ' a) (inv (neg-neg-ℤ b)))
+ ( transpose-left-summand-leq-ℤ a (neg-ℤ b) c H)
+
+transpose-right-summand-leq-ℤ :
+ (a b c : ℤ) → a ≤-ℤ b +ℤ c → a +ℤ neg-ℤ c ≤-ℤ b
+transpose-right-summand-leq-ℤ a b c H =
+ reflects-order-left-add-ℤ c
+ ( a +ℤ neg-ℤ c)
+ ( b)
+ ( concatenate-eq-leq-ℤ (b +ℤ c) (is-section-right-add-neg-ℤ c a) H)
+
+inv-transpose-right-summand-leq-ℤ :
+ (a b c : ℤ) → a +ℤ neg-ℤ c ≤-ℤ b → a ≤-ℤ b +ℤ c
+inv-transpose-right-summand-leq-ℤ a b c H =
+ concatenate-eq-leq-ℤ
+ ( b +ℤ c)
+ ( inv (is-section-right-add-neg-ℤ c a))
+ ( preserves-order-left-add-ℤ c (a +ℤ neg-ℤ c) b H)
+
+transpose-right-summand-leq-ℤ' :
+ (a b c : ℤ) → a +ℤ c ≤-ℤ b → a ≤-ℤ b +ℤ neg-ℤ c
+transpose-right-summand-leq-ℤ' a b c H =
+ inv-transpose-right-summand-leq-ℤ a b
+ ( neg-ℤ c)
+ ( concatenate-eq-leq-ℤ b (ap (add-ℤ a) (neg-neg-ℤ c)) H)
+
+inv-transpose-right-summand-leq-ℤ' :
+ (a b c : ℤ) → a ≤-ℤ b +ℤ neg-ℤ c → a +ℤ c ≤-ℤ b
+inv-transpose-right-summand-leq-ℤ' a b c H =
+ concatenate-eq-leq-ℤ b
+ ( ap (add-ℤ a) (inv (neg-neg-ℤ c)))
+ ( transpose-right-summand-leq-ℤ a b (neg-ℤ c) H)
+```
+
+### The operation taking integers to their negatives reverses their order
-ℤ-Poset : Poset lzero lzero
-ℤ-Poset = (ℤ-Preorder , λ x y → antisymmetric-leq-ℤ)
+**Proof.** If `a ≤ b`, then `b - a` is nonnegative. Note that
+`b - a = (-a) - (-b)`, which is therefore also nonnegative, implying that
+`-b ≤ -a`.
+
+```agda
+reverses-order-neg-ℤ :
+ (a b : ℤ) → a ≤-ℤ b → neg-ℤ b ≤-ℤ neg-ℤ a
+reverses-order-neg-ℤ a b =
+ tr
+ ( is-nonnegative-ℤ)
+ ( ( commutative-add-ℤ b (neg-ℤ a)) ∙
+ ( ap (add-ℤ (neg-ℤ a)) (inv (neg-neg-ℤ b))))
```
-### An integer `x` is nonnegative if and only if `0 ≤ x`
+### The operation taking integers to their negative reversely reflects their order
+
+```agda
+reversely-reflects-order-neg-ℤ :
+ (a b : ℤ) → neg-ℤ a ≤-ℤ neg-ℤ b → b ≤-ℤ a
+reversely-reflects-order-neg-ℤ a b =
+ tr
+ ( is-nonnegative-ℤ)
+ ( ap (add-ℤ (neg-ℤ b)) (neg-neg-ℤ a) ∙ commutative-add-ℤ (neg-ℤ b) a)
+```
+
+### Transposing negatives in inequalities
+
+```agda
+transpose-right-neg-leq-ℤ :
+ (a b : ℤ) → b ≤-ℤ neg-ℤ a → a ≤-ℤ neg-ℤ b
+transpose-right-neg-leq-ℤ a b H =
+ reversely-reflects-order-neg-ℤ
+ ( neg-ℤ b)
+ ( a)
+ ( concatenate-eq-leq-ℤ (neg-ℤ a) (neg-neg-ℤ b) H)
+
+transpose-left-neg-leq-ℤ :
+ (a b : ℤ) → neg-ℤ b ≤-ℤ a → neg-ℤ a ≤-ℤ b
+transpose-left-neg-leq-ℤ a b H =
+ reversely-reflects-order-neg-ℤ b
+ ( neg-ℤ a)
+ ( concatenate-leq-eq-ℤ (neg-ℤ b) H (inv (neg-neg-ℤ a)))
+```
+
+### An integer `a` is nonnegative if and only if `0 ≤ a`
```agda
module _
- (x : ℤ)
+ (a : ℤ)
where
abstract
- leq-zero-is-nonnegative-ℤ : is-nonnegative-ℤ x → leq-ℤ zero-ℤ x
+ leq-zero-is-nonnegative-ℤ : is-nonnegative-ℤ a → zero-ℤ ≤-ℤ a
leq-zero-is-nonnegative-ℤ =
- is-nonnegative-eq-ℤ (inv (right-zero-law-diff-ℤ x))
+ is-nonnegative-eq-ℤ (inv (right-zero-law-diff-ℤ a))
- is-nonnegative-leq-zero-ℤ : leq-ℤ zero-ℤ x → is-nonnegative-ℤ x
+ is-nonnegative-leq-zero-ℤ : zero-ℤ ≤-ℤ a → is-nonnegative-ℤ a
is-nonnegative-leq-zero-ℤ =
- is-nonnegative-eq-ℤ (right-zero-law-diff-ℤ x)
+ is-nonnegative-eq-ℤ (right-zero-law-diff-ℤ a)
```
### An integer greater than or equal to a nonnegative integer is nonnegative
```agda
module _
- (x y : ℤ) (I : leq-ℤ x y)
+ (a b : ℤ) (I : a ≤-ℤ b)
where
abstract
- is-nonnegative-leq-nonnegative-ℤ : is-nonnegative-ℤ x → is-nonnegative-ℤ y
+ is-nonnegative-leq-nonnegative-ℤ : is-nonnegative-ℤ a → is-nonnegative-ℤ b
is-nonnegative-leq-nonnegative-ℤ H =
- is-nonnegative-leq-zero-ℤ y
+ is-nonnegative-leq-zero-ℤ b
( transitive-leq-ℤ
( zero-ℤ)
- ( x)
- ( y)
+ ( a)
+ ( b)
( I)
- ( leq-zero-is-nonnegative-ℤ x H))
+ ( leq-zero-is-nonnegative-ℤ a H))
```
-### An integer `x` is nonpositive if and only if `x ≤ 0`
+### An integer `a` is nonpositive if and only if `a ≤ 0`
```agda
module _
- (x : ℤ)
+ (a : ℤ)
where
abstract
- leq-zero-is-nonpositive-ℤ : is-nonpositive-ℤ x → leq-ℤ x zero-ℤ
+ leq-zero-is-nonpositive-ℤ : is-nonpositive-ℤ a → a ≤-ℤ zero-ℤ
leq-zero-is-nonpositive-ℤ = is-nonnegative-neg-is-nonpositive-ℤ
- is-nonpositive-leq-zero-ℤ : leq-ℤ x zero-ℤ → is-nonpositive-ℤ x
+ is-nonpositive-leq-zero-ℤ : a ≤-ℤ zero-ℤ → is-nonpositive-ℤ a
is-nonpositive-leq-zero-ℤ H =
is-nonpositive-eq-ℤ
- ( neg-neg-ℤ x)
+ ( neg-neg-ℤ a)
( is-nonpositive-neg-is-nonnegative-ℤ H)
```
@@ -270,21 +440,30 @@ module _
```agda
module _
- (x y : ℤ) (I : leq-ℤ x y)
+ (a b : ℤ) (I : a ≤-ℤ b)
where
abstract
- is-nonpositive-leq-nonpositive-ℤ : is-nonpositive-ℤ y → is-nonpositive-ℤ x
+ is-nonpositive-leq-nonpositive-ℤ : is-nonpositive-ℤ b → is-nonpositive-ℤ a
is-nonpositive-leq-nonpositive-ℤ H =
- is-nonpositive-leq-zero-ℤ x
+ is-nonpositive-leq-zero-ℤ a
( transitive-leq-ℤ
- ( x)
- ( y)
+ ( a)
+ ( b)
( zero-ℤ)
- ( leq-zero-is-nonpositive-ℤ y H)
+ ( leq-zero-is-nonpositive-ℤ b H)
( I))
```
+### A positive integer is greater than or equal to `0`
+
+```agda
+leq-zero-is-positive-ℤ :
+ (a : ℤ) → is-positive-ℤ a → zero-ℤ ≤-ℤ a
+leq-zero-is-positive-ℤ a H =
+ leq-zero-is-nonnegative-ℤ a (is-nonnegative-is-positive-ℤ H)
+```
+
## See also
- The decidable total order on the integers is defined in
diff --git a/src/elementary-number-theory/inequality-natural-numbers.lagda.md b/src/elementary-number-theory/inequality-natural-numbers.lagda.md
index a31c50691d..167b09f2cd 100644
--- a/src/elementary-number-theory/inequality-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/inequality-natural-numbers.lagda.md
@@ -10,21 +10,26 @@ module elementary-number-theory.inequality-natural-numbers where
open import category-theory.precategories
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
open import foundation.action-on-identifications-functions
open import foundation.binary-relations
open import foundation.cartesian-product-types
+open import foundation.contractible-types
open import foundation.coproduct-types
open import foundation.decidable-types
open import foundation.dependent-pair-types
open import foundation.empty-types
+open import foundation.equivalences
open import foundation.function-types
open import foundation.functoriality-coproduct-types
open import foundation.identity-types
+open import foundation.logical-equivalences
open import foundation.negation
open import foundation.propositions
+open import foundation.sections
open import foundation.unit-type
open import foundation.universe-levels
@@ -68,7 +73,7 @@ data leq-ℕ' : ℕ → ℕ → UU lzero where
```agda
is-prop-leq-ℕ :
- (m n : ℕ) → is-prop (leq-ℕ m n)
+ (m n : ℕ) → is-prop (m ≤-ℕ n)
is-prop-leq-ℕ zero-ℕ zero-ℕ = is-prop-unit
is-prop-leq-ℕ zero-ℕ (succ-ℕ n) = is-prop-unit
is-prop-leq-ℕ (succ-ℕ m) zero-ℕ = is-prop-empty
@@ -77,13 +82,18 @@ is-prop-leq-ℕ (succ-ℕ m) (succ-ℕ n) = is-prop-leq-ℕ m n
leq-ℕ-Prop : ℕ → ℕ → Prop lzero
pr1 (leq-ℕ-Prop m n) = leq-ℕ m n
pr2 (leq-ℕ-Prop m n) = is-prop-leq-ℕ m n
+
+is-proof-irrelevant-leq-ℕ :
+ (m n : ℕ) → m ≤-ℕ n → is-contr (m ≤-ℕ n)
+is-proof-irrelevant-leq-ℕ m n =
+ is-proof-irrelevant-is-prop (is-prop-leq-ℕ m n)
```
### Inequality on the natural numbers is decidable
```agda
is-decidable-leq-ℕ :
- (m n : ℕ) → is-decidable (leq-ℕ m n)
+ (m n : ℕ) → is-decidable (m ≤-ℕ n)
is-decidable-leq-ℕ zero-ℕ zero-ℕ = inl star
is-decidable-leq-ℕ zero-ℕ (succ-ℕ n) = inl star
is-decidable-leq-ℕ (succ-ℕ m) zero-ℕ = inr id
@@ -120,7 +130,7 @@ leq-eq-ℕ m .m refl = refl-leq-ℕ m
### Inequality on the natural numbers is transitive
```agda
-transitive-leq-ℕ : is-transitive leq-ℕ
+transitive-leq-ℕ : is-transitive _≤-ℕ_
transitive-leq-ℕ zero-ℕ m l p q = star
transitive-leq-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-leq-ℕ n m l p q
@@ -173,22 +183,19 @@ linear-leq-ℕ (succ-ℕ m) (succ-ℕ n) = linear-leq-ℕ m n
cases-order-three-elements-ℕ :
(x y z : ℕ) → UU lzero
cases-order-three-elements-ℕ x y z =
- ( ( leq-ℕ x y × leq-ℕ y z) +
- ( leq-ℕ x z × leq-ℕ z y)) +
- ( ( ( leq-ℕ y z × leq-ℕ z x) +
- ( leq-ℕ y x × leq-ℕ x z)) +
- ( ( leq-ℕ z x × leq-ℕ x y) +
- ( leq-ℕ z y × leq-ℕ y x)))
+ ( x ≤-ℕ y × y ≤-ℕ z + x ≤-ℕ z × z ≤-ℕ y) +
+ ( ( y ≤-ℕ z × z ≤-ℕ x + y ≤-ℕ x × x ≤-ℕ z) +
+ ( z ≤-ℕ x × x ≤-ℕ y + z ≤-ℕ y × y ≤-ℕ x))
order-three-elements-ℕ :
(x y z : ℕ) → cases-order-three-elements-ℕ x y z
-order-three-elements-ℕ zero-ℕ zero-ℕ zero-ℕ = inl (inl (pair star star))
-order-three-elements-ℕ zero-ℕ zero-ℕ (succ-ℕ z) = inl (inl (pair star star))
-order-three-elements-ℕ zero-ℕ (succ-ℕ y) zero-ℕ = inl (inr (pair star star))
+order-three-elements-ℕ zero-ℕ zero-ℕ zero-ℕ = inl (inl (star , star))
+order-three-elements-ℕ zero-ℕ zero-ℕ (succ-ℕ z) = inl (inl (star , star))
+order-three-elements-ℕ zero-ℕ (succ-ℕ y) zero-ℕ = inl (inr (star , star))
order-three-elements-ℕ zero-ℕ (succ-ℕ y) (succ-ℕ z) =
inl (map-coproduct (pair star) (pair star) (linear-leq-ℕ y z))
order-three-elements-ℕ (succ-ℕ x) zero-ℕ zero-ℕ =
- inr (inl (inl (pair star star)))
+ inr (inl (inl (star , star)))
order-three-elements-ℕ (succ-ℕ x) zero-ℕ (succ-ℕ z) =
inr (inl (map-coproduct (pair star) (pair star) (linear-leq-ℕ z x)))
order-three-elements-ℕ (succ-ℕ x) (succ-ℕ y) zero-ℕ =
@@ -201,19 +208,23 @@ order-three-elements-ℕ (succ-ℕ x) (succ-ℕ y) (succ-ℕ z) =
```agda
leq-zero-ℕ :
- (n : ℕ) → zero-ℕ ≤-ℕ n
+ (n : ℕ) → 0 ≤-ℕ n
leq-zero-ℕ n = star
+
+leq-is-zero-ℕ :
+ (m n : ℕ) → is-zero-ℕ m → m ≤-ℕ n
+leq-is-zero-ℕ .zero-ℕ n refl = leq-zero-ℕ n
```
### Any natural number less than zero is zero
```agda
is-zero-leq-zero-ℕ :
- (x : ℕ) → x ≤-ℕ zero-ℕ → is-zero-ℕ x
+ (x : ℕ) → x ≤-ℕ 0 → is-zero-ℕ x
is-zero-leq-zero-ℕ zero-ℕ star = refl
is-zero-leq-zero-ℕ' :
- (x : ℕ) → x ≤-ℕ zero-ℕ → is-zero-ℕ' x
+ (x : ℕ) → x ≤-ℕ 0 → is-zero-ℕ' x
is-zero-leq-zero-ℕ' zero-ℕ star = refl
```
@@ -233,107 +244,138 @@ is-nonzero-leq-one-ℕ .zero-ℕ () refl
### Any natural number is less than or equal to its own successor
```agda
-succ-leq-ℕ : (n : ℕ) → n ≤-ℕ (succ-ℕ n)
+succ-leq-ℕ : (n : ℕ) → n ≤-ℕ succ-ℕ n
succ-leq-ℕ zero-ℕ = star
succ-leq-ℕ (succ-ℕ n) = succ-leq-ℕ n
```
-### Any natural number less than or equal to `n+1` is either less than or equal to `n` or it is `n+1`
-
-```agda
-decide-leq-succ-ℕ :
- (m n : ℕ) → m ≤-ℕ (succ-ℕ n) → (m ≤-ℕ n) + (m = succ-ℕ n)
-decide-leq-succ-ℕ zero-ℕ zero-ℕ l = inl star
-decide-leq-succ-ℕ zero-ℕ (succ-ℕ n) l = inl star
-decide-leq-succ-ℕ (succ-ℕ m) zero-ℕ l =
- inr (ap succ-ℕ (is-zero-leq-zero-ℕ m l))
-decide-leq-succ-ℕ (succ-ℕ m) (succ-ℕ n) l =
- map-coproduct id (ap succ-ℕ) (decide-leq-succ-ℕ m n l)
-```
-
### If `m` is less than `n`, then it is less than `n+1`
```agda
-preserves-leq-succ-ℕ :
- (m n : ℕ) → m ≤-ℕ n → m ≤-ℕ (succ-ℕ n)
-preserves-leq-succ-ℕ m n p = transitive-leq-ℕ m n (succ-ℕ n) (succ-leq-ℕ n) p
+leq-succ-leq-ℕ :
+ (m n : ℕ) → m ≤-ℕ n → m ≤-ℕ succ-ℕ n
+leq-succ-leq-ℕ m n p = transitive-leq-ℕ m n (succ-ℕ n) (succ-leq-ℕ n) p
```
### The successor of `n` is not less than or equal to `n`
```agda
neg-succ-leq-ℕ :
- (n : ℕ) → ¬ (leq-ℕ (succ-ℕ n) n)
+ (n : ℕ) → ¬ (succ-ℕ n ≤-ℕ n)
neg-succ-leq-ℕ zero-ℕ = id
neg-succ-leq-ℕ (succ-ℕ n) = neg-succ-leq-ℕ n
```
-### If `m ≤ n + 1` then either `m ≤ n` or `m = n + 1`
+### `m ≤ n` if and only if `n + 1 ≰ m`
```agda
-cases-leq-succ-ℕ :
- {m n : ℕ} → leq-ℕ m (succ-ℕ n) → (leq-ℕ m n) + (m = succ-ℕ n)
-cases-leq-succ-ℕ {zero-ℕ} {n} star = inl star
-cases-leq-succ-ℕ {succ-ℕ m} {zero-ℕ} p =
- inr (ap succ-ℕ (antisymmetric-leq-ℕ m zero-ℕ p star))
-cases-leq-succ-ℕ {succ-ℕ m} {succ-ℕ n} p =
- map-coproduct id (ap succ-ℕ) (cases-leq-succ-ℕ p)
+contradiction-leq-ℕ : (m n : ℕ) → m ≤-ℕ n → ¬ (succ-ℕ n ≤-ℕ m)
+contradiction-leq-ℕ (succ-ℕ m) (succ-ℕ n) H K = contradiction-leq-ℕ m n H K
-cases-leq-succ-reflexive-leq-ℕ :
- {n : ℕ} → cases-leq-succ-ℕ {succ-ℕ n} {n} (refl-leq-ℕ n) = inr refl
-cases-leq-succ-reflexive-leq-ℕ {zero-ℕ} = refl
-cases-leq-succ-reflexive-leq-ℕ {succ-ℕ n} =
- ap (map-coproduct id (ap succ-ℕ)) cases-leq-succ-reflexive-leq-ℕ
+contradiction-leq-ℕ' : (m n : ℕ) → succ-ℕ n ≤-ℕ m → ¬ (m ≤-ℕ n)
+contradiction-leq-ℕ' m n K H = contradiction-leq-ℕ m n H K
```
-### `m ≤ n` if and only if `n + 1 ≰ m`
+### Any natural number less than or equal to `n+1` is either less than or equal to `n` or it is `n+1`
```agda
-contradiction-leq-ℕ : (m n : ℕ) → m ≤-ℕ n → ¬ ((succ-ℕ n) ≤-ℕ m)
-contradiction-leq-ℕ (succ-ℕ m) (succ-ℕ n) H K = contradiction-leq-ℕ m n H K
+decide-leq-succ-ℕ :
+ (m n : ℕ) → m ≤-ℕ succ-ℕ n → (m ≤-ℕ n) + (m = succ-ℕ n)
+decide-leq-succ-ℕ zero-ℕ zero-ℕ l = inl star
+decide-leq-succ-ℕ zero-ℕ (succ-ℕ n) l = inl star
+decide-leq-succ-ℕ (succ-ℕ m) zero-ℕ l =
+ inr (ap succ-ℕ (is-zero-leq-zero-ℕ m l))
+decide-leq-succ-ℕ (succ-ℕ m) (succ-ℕ n) l =
+ map-coproduct id (ap succ-ℕ) (decide-leq-succ-ℕ m n l)
-contradiction-leq-ℕ' : (m n : ℕ) → (succ-ℕ n) ≤-ℕ m → ¬ (m ≤-ℕ n)
-contradiction-leq-ℕ' m n K H = contradiction-leq-ℕ m n H K
+inv-decide-leq-succ-ℕ :
+ (m n : ℕ) → (m ≤-ℕ n) + (m = succ-ℕ n) → m ≤-ℕ succ-ℕ n
+inv-decide-leq-succ-ℕ m n (inl H) =
+ transitive-leq-ℕ m n (succ-ℕ n) (leq-succ-leq-ℕ n n (refl-leq-ℕ n)) H
+inv-decide-leq-succ-ℕ m n (inr p) =
+ leq-eq-ℕ m (succ-ℕ n) p
+
+all-elements-equal-cases-leq-succ-ℕ :
+ (m n : ℕ) → all-elements-equal ((m ≤-ℕ n) + (m = succ-ℕ n))
+all-elements-equal-cases-leq-succ-ℕ m n (inl H) (inl K) =
+ ap inl (eq-is-prop (is-prop-leq-ℕ m n))
+all-elements-equal-cases-leq-succ-ℕ .(succ-ℕ n) n (inl H) (inr refl) =
+ ex-falso (neg-succ-leq-ℕ n H)
+all-elements-equal-cases-leq-succ-ℕ .(succ-ℕ n) n (inr refl) (inl K) =
+ ex-falso (neg-succ-leq-ℕ n K)
+all-elements-equal-cases-leq-succ-ℕ .(succ-ℕ n) n (inr refl) (inr q) =
+ ap inr (eq-is-prop (is-set-ℕ (succ-ℕ n) (succ-ℕ n)))
+
+is-prop-cases-leq-succ-ℕ :
+ (m n : ℕ) → is-prop ((m ≤-ℕ n) + (m = succ-ℕ n))
+is-prop-cases-leq-succ-ℕ m n =
+ is-prop-all-elements-equal (all-elements-equal-cases-leq-succ-ℕ m n)
+
+compute-leq-succ-ℕ :
+ (m n : ℕ) → m ≤-ℕ succ-ℕ n ≃ (m ≤-ℕ n) + (m = succ-ℕ n)
+compute-leq-succ-ℕ m n =
+ equiv-iff-is-prop
+ ( is-prop-leq-ℕ m (succ-ℕ n))
+ ( is-prop-cases-leq-succ-ℕ m n)
+ ( decide-leq-succ-ℕ m n)
+ ( inv-decide-leq-succ-ℕ m n)
+
+decide-leq-refl-succ-ℕ :
+ {n : ℕ} → decide-leq-succ-ℕ (succ-ℕ n) n (refl-leq-ℕ n) = inr refl
+decide-leq-refl-succ-ℕ {zero-ℕ} = refl
+decide-leq-refl-succ-ℕ {succ-ℕ n} =
+ ap (map-coproduct id (ap succ-ℕ)) decide-leq-refl-succ-ℕ
+```
+
+### The inequality `m ≤ n` holds if and only if either `m = n` or the inequality `m + 1 ≤ n` holds
+
+```agda
+decide-leq-ℕ :
+ (m n : ℕ) → m ≤-ℕ n → (m = n) + (succ-ℕ m ≤-ℕ n)
+decide-leq-ℕ m zero-ℕ H = inl (is-zero-leq-zero-ℕ m H)
+decide-leq-ℕ zero-ℕ (succ-ℕ n) H = inr (leq-zero-ℕ n)
+decide-leq-ℕ (succ-ℕ m) (succ-ℕ n) H =
+ map-coproduct (ap succ-ℕ) id (decide-leq-ℕ m n H)
```
### Addition preserves inequality of natural numbers
```agda
-preserves-leq-left-add-ℕ :
- (k m n : ℕ) → m ≤-ℕ n → (m +ℕ k) ≤-ℕ (n +ℕ k)
-preserves-leq-left-add-ℕ zero-ℕ m n = id
-preserves-leq-left-add-ℕ (succ-ℕ k) m n H = preserves-leq-left-add-ℕ k m n H
+preserves-order-left-add-ℕ :
+ (k m n : ℕ) → m ≤-ℕ n → m +ℕ k ≤-ℕ n +ℕ k
+preserves-order-left-add-ℕ zero-ℕ m n = id
+preserves-order-left-add-ℕ (succ-ℕ k) m n H = preserves-order-left-add-ℕ k m n H
-preserves-leq-right-add-ℕ : (k m n : ℕ) → m ≤-ℕ n → (k +ℕ m) ≤-ℕ (k +ℕ n)
-preserves-leq-right-add-ℕ k m n H =
+preserves-order-right-add-ℕ : (k m n : ℕ) → m ≤-ℕ n → k +ℕ m ≤-ℕ k +ℕ n
+preserves-order-right-add-ℕ k m n H =
concatenate-eq-leq-eq-ℕ
( commutative-add-ℕ k m)
- ( preserves-leq-left-add-ℕ k m n H)
+ ( preserves-order-left-add-ℕ k m n H)
( commutative-add-ℕ n k)
-preserves-leq-add-ℕ :
- {m m' n n' : ℕ} → m ≤-ℕ m' → n ≤-ℕ n' → (m +ℕ n) ≤-ℕ (m' +ℕ n')
-preserves-leq-add-ℕ {m} {m'} {n} {n'} H K =
+preserves-order-add-ℕ :
+ {m m' n n' : ℕ} → m ≤-ℕ m' → n ≤-ℕ n' → m +ℕ n ≤-ℕ m' +ℕ n'
+preserves-order-add-ℕ {m} {m'} {n} {n'} H K =
transitive-leq-ℕ
( m +ℕ n)
( m' +ℕ n)
( m' +ℕ n')
- ( preserves-leq-right-add-ℕ m' n n' K)
- ( preserves-leq-left-add-ℕ n m m' H)
+ ( preserves-order-right-add-ℕ m' n n' K)
+ ( preserves-order-left-add-ℕ n m m' H)
```
### Addition reflects inequality of natural numbers
```agda
-reflects-leq-left-add-ℕ :
- (k m n : ℕ) → (m +ℕ k) ≤-ℕ (n +ℕ k) → m ≤-ℕ n
-reflects-leq-left-add-ℕ zero-ℕ m n = id
-reflects-leq-left-add-ℕ (succ-ℕ k) m n = reflects-leq-left-add-ℕ k m n
-
-reflects-leq-right-add-ℕ :
- (k m n : ℕ) → (k +ℕ m) ≤-ℕ (k +ℕ n) → m ≤-ℕ n
-reflects-leq-right-add-ℕ k m n H =
- reflects-leq-left-add-ℕ k m n
+reflects-order-left-add-ℕ :
+ (k m n : ℕ) → m +ℕ k ≤-ℕ n +ℕ k → m ≤-ℕ n
+reflects-order-left-add-ℕ zero-ℕ m n = id
+reflects-order-left-add-ℕ (succ-ℕ k) m n = reflects-order-left-add-ℕ k m n
+
+reflects-order-right-add-ℕ :
+ (k m n : ℕ) → k +ℕ m ≤-ℕ k +ℕ n → m ≤-ℕ n
+reflects-order-right-add-ℕ k m n H =
+ reflects-order-left-add-ℕ k m n
( concatenate-eq-leq-eq-ℕ
( commutative-add-ℕ m k)
( H)
@@ -343,7 +385,7 @@ reflects-leq-right-add-ℕ k m n H =
### `m ≤ m + n` for any two natural numbers `m` and `n`
```agda
-leq-add-ℕ : (m n : ℕ) → m ≤-ℕ (m +ℕ n)
+leq-add-ℕ : (m n : ℕ) → m ≤-ℕ m +ℕ n
leq-add-ℕ m zero-ℕ = refl-leq-ℕ m
leq-add-ℕ m (succ-ℕ n) =
transitive-leq-ℕ
@@ -353,17 +395,31 @@ leq-add-ℕ m (succ-ℕ n) =
( succ-leq-ℕ (m +ℕ n))
( leq-add-ℕ m n)
-leq-add-ℕ' : (m n : ℕ) → m ≤-ℕ (n +ℕ m)
+leq-add-ℕ' : (m n : ℕ) → m ≤-ℕ n +ℕ m
leq-add-ℕ' m n =
concatenate-leq-eq-ℕ m (leq-add-ℕ m n) (commutative-add-ℕ m n)
```
+### If `m + n ≤ k`, then both `m ≤ k` and `n ≤ k` hold
+
+```agda
+leq-right-summand-ℕ :
+ (m n k : ℕ) → m +ℕ n ≤-ℕ k → n ≤-ℕ k
+leq-right-summand-ℕ m n k H =
+ transitive-leq-ℕ n (m +ℕ n) k H (leq-add-ℕ' n m)
+
+leq-left-summand-ℕ :
+ (m n k : ℕ) → m +ℕ n ≤-ℕ k → m ≤-ℕ k
+leq-left-summand-ℕ m n k H =
+ transitive-leq-ℕ m (m +ℕ n) k H (leq-add-ℕ m n)
+```
+
### We have `n ≤ m` if and only if there is a number `l` such that `l+n=m`
```agda
subtraction-leq-ℕ : (n m : ℕ) → n ≤-ℕ m → Σ ℕ (λ l → l +ℕ n = m)
-subtraction-leq-ℕ zero-ℕ m p = pair m refl
-subtraction-leq-ℕ (succ-ℕ n) (succ-ℕ m) p = pair (pr1 P) (ap succ-ℕ (pr2 P))
+subtraction-leq-ℕ zero-ℕ m p = (m , refl)
+subtraction-leq-ℕ (succ-ℕ n) (succ-ℕ m) p = (pr1 P , ap succ-ℕ (pr2 P))
where
P : Σ ℕ (λ l' → l' +ℕ n = m)
P = subtraction-leq-ℕ n m p
@@ -377,88 +433,145 @@ leq-subtraction-ℕ (succ-ℕ n) (succ-ℕ m) l p =
### Multiplication preserves inequality of natural numbers
```agda
-preserves-leq-left-mul-ℕ :
- (k m n : ℕ) → m ≤-ℕ n → (m *ℕ k) ≤-ℕ (n *ℕ k)
-preserves-leq-left-mul-ℕ k zero-ℕ n p = star
-preserves-leq-left-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
- preserves-leq-left-add-ℕ k
+preserves-order-left-mul-ℕ :
+ (k m n : ℕ) → m ≤-ℕ n → m *ℕ k ≤-ℕ n *ℕ k
+preserves-order-left-mul-ℕ k zero-ℕ n p = star
+preserves-order-left-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
+ preserves-order-left-add-ℕ k
( m *ℕ k)
( n *ℕ k)
- ( preserves-leq-left-mul-ℕ k m n p)
+ ( preserves-order-left-mul-ℕ k m n p)
-preserves-leq-right-mul-ℕ :
- (k m n : ℕ) → m ≤-ℕ n → (k *ℕ m) ≤-ℕ (k *ℕ n)
-preserves-leq-right-mul-ℕ k m n H =
+preserves-order-right-mul-ℕ :
+ (k m n : ℕ) → m ≤-ℕ n → k *ℕ m ≤-ℕ k *ℕ n
+preserves-order-right-mul-ℕ k m n H =
concatenate-eq-leq-eq-ℕ
( commutative-mul-ℕ k m)
- ( preserves-leq-left-mul-ℕ k m n H)
+ ( preserves-order-left-mul-ℕ k m n H)
( commutative-mul-ℕ n k)
-preserves-leq-mul-ℕ :
- (m m' n n' : ℕ) → m ≤-ℕ m' → n ≤-ℕ n' → (m *ℕ n) ≤-ℕ (m' *ℕ n')
-preserves-leq-mul-ℕ m m' n n' H K =
+preserves-order-mul-ℕ :
+ (m m' n n' : ℕ) → m ≤-ℕ m' → n ≤-ℕ n' → m *ℕ n ≤-ℕ m' *ℕ n'
+preserves-order-mul-ℕ m m' n n' H K =
transitive-leq-ℕ
( m *ℕ n)
( m' *ℕ n)
( m' *ℕ n')
- ( preserves-leq-right-mul-ℕ m' n n' K)
- ( preserves-leq-left-mul-ℕ n m m' H)
+ ( preserves-order-right-mul-ℕ m' n n' K)
+ ( preserves-order-left-mul-ℕ n m m' H)
```
### Multiplication by a nonzero natural number reflects inequality of natural numbers
```agda
-reflects-order-mul-ℕ :
- (k m n : ℕ) → (m *ℕ (succ-ℕ k)) ≤-ℕ (n *ℕ (succ-ℕ k)) → m ≤-ℕ n
-reflects-order-mul-ℕ k zero-ℕ n p = star
-reflects-order-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
- reflects-order-mul-ℕ k m n
- ( reflects-leq-left-add-ℕ
+reflects-order-mul-succ-ℕ :
+ (k m n : ℕ) → m *ℕ succ-ℕ k ≤-ℕ n *ℕ succ-ℕ k → m ≤-ℕ n
+reflects-order-mul-succ-ℕ k zero-ℕ n p = star
+reflects-order-mul-succ-ℕ k (succ-ℕ m) (succ-ℕ n) p =
+ reflects-order-mul-succ-ℕ k m n
+ ( reflects-order-left-add-ℕ
( succ-ℕ k)
( m *ℕ (succ-ℕ k))
( n *ℕ (succ-ℕ k))
( p))
-reflects-order-mul-ℕ' :
- (k m n : ℕ) → ((succ-ℕ k) *ℕ m) ≤-ℕ ((succ-ℕ k) *ℕ n) → m ≤-ℕ n
-reflects-order-mul-ℕ' k m n H =
- reflects-order-mul-ℕ k m n
+reflects-order-mul-succ-ℕ' :
+ (k m n : ℕ) → succ-ℕ k *ℕ m ≤-ℕ succ-ℕ k *ℕ n → m ≤-ℕ n
+reflects-order-mul-succ-ℕ' k m n H =
+ reflects-order-mul-succ-ℕ k m n
( concatenate-eq-leq-eq-ℕ
( commutative-mul-ℕ m (succ-ℕ k))
( H)
( commutative-mul-ℕ (succ-ℕ k) n))
+
+reflects-order-mul-ℕ :
+ (k m n : ℕ) → is-nonzero-ℕ k → m *ℕ k ≤-ℕ n *ℕ k → m ≤-ℕ n
+reflects-order-mul-ℕ k m n H with
+ is-successor-is-nonzero-ℕ H
+... | (k' , refl) = reflects-order-mul-succ-ℕ k' m n
+
+reflects-order-mul-ℕ' :
+ (k m n : ℕ) → is-nonzero-ℕ k → k *ℕ m ≤-ℕ k *ℕ n → m ≤-ℕ n
+reflects-order-mul-ℕ' k m n H K =
+ reflects-order-mul-ℕ k m n H
+ ( concatenate-eq-leq-eq-ℕ
+ ( commutative-mul-ℕ m k)
+ ( K)
+ ( commutative-mul-ℕ k n))
```
### Any number `x` is less than or equal to a nonzero multiple of itself
```agda
leq-mul-ℕ :
- (k x : ℕ) → x ≤-ℕ (x *ℕ (succ-ℕ k))
+ (k x : ℕ) → x ≤-ℕ x *ℕ succ-ℕ k
leq-mul-ℕ k x =
concatenate-eq-leq-ℕ
- ( x *ℕ (succ-ℕ k))
+ ( x *ℕ succ-ℕ k)
( inv (right-unit-law-mul-ℕ x))
- ( preserves-leq-right-mul-ℕ x 1 (succ-ℕ k) (leq-zero-ℕ k))
+ ( preserves-order-right-mul-ℕ x 1 (succ-ℕ k) (leq-zero-ℕ k))
leq-mul-ℕ' :
- (k x : ℕ) → x ≤-ℕ ((succ-ℕ k) *ℕ x)
+ (k x : ℕ) → x ≤-ℕ succ-ℕ k *ℕ x
leq-mul-ℕ' k x =
concatenate-leq-eq-ℕ x
( leq-mul-ℕ k x)
( commutative-mul-ℕ x (succ-ℕ k))
leq-mul-is-nonzero-ℕ :
- (k x : ℕ) → is-nonzero-ℕ k → x ≤-ℕ (x *ℕ k)
+ (k x : ℕ) → is-nonzero-ℕ k → x ≤-ℕ x *ℕ k
leq-mul-is-nonzero-ℕ k x H with is-successor-is-nonzero-ℕ H
-... | pair l refl = leq-mul-ℕ l x
+... | (l , refl) = leq-mul-ℕ l x
leq-mul-is-nonzero-ℕ' :
- (k x : ℕ) → is-nonzero-ℕ k → x ≤-ℕ (k *ℕ x)
+ (k x : ℕ) → is-nonzero-ℕ k → x ≤-ℕ k *ℕ x
leq-mul-is-nonzero-ℕ' k x H with is-successor-is-nonzero-ℕ H
-... | pair l refl = leq-mul-ℕ' l x
+... | (l , refl) = leq-mul-ℕ' l x
+```
+
+### If `m * n ≤ k` and `m` is nonzero, then `n ≤ k`
+
+```agda
+leq-right-factor-mul-succ-ℕ :
+ (m n k : ℕ) → succ-ℕ m *ℕ n ≤-ℕ k → n ≤-ℕ k
+leq-right-factor-mul-succ-ℕ m n =
+ leq-right-summand-ℕ (m *ℕ n) n
+
+leq-right-factor-ℕ :
+ (m n k : ℕ) → is-nonzero-ℕ m → m *ℕ n ≤-ℕ k → n ≤-ℕ k
+leq-right-factor-ℕ zero-ℕ n k H K = ex-falso (H refl)
+leq-right-factor-ℕ (succ-ℕ m) n k H K = leq-right-factor-mul-succ-ℕ m n k K
+
+leq-right-factor-eq-ℕ :
+ (m n k : ℕ) → is-nonzero-ℕ m → m *ℕ n = k → n ≤-ℕ k
+leq-right-factor-eq-ℕ m n .(m *ℕ n) H refl =
+ leq-mul-is-nonzero-ℕ' m n H
+```
+
+### If `m * n ≤ k` and `n` is nonzero, then `m ≤ k`
+
+```agda
+leq-left-factor-mul-succ-ℕ :
+ (m n k : ℕ) → m *ℕ succ-ℕ n ≤-ℕ k → m ≤-ℕ k
+leq-left-factor-mul-succ-ℕ m n k H =
+ leq-right-summand-ℕ
+ ( m *ℕ n)
+ ( m)
+ ( k)
+ ( concatenate-eq-leq-ℕ k (inv (right-successor-law-mul-ℕ m n)) H)
+
+leq-left-factor-ℕ :
+ (m n k : ℕ) → is-nonzero-ℕ n → m *ℕ n ≤-ℕ k → m ≤-ℕ k
+leq-left-factor-ℕ m zero-ℕ k H K = ex-falso (H refl)
+leq-left-factor-ℕ m (succ-ℕ n) k H K = leq-left-factor-mul-succ-ℕ m n k K
+
+leq-left-factor-eq-ℕ :
+ (m n k : ℕ) → is-nonzero-ℕ n → m *ℕ n = k → m ≤-ℕ k
+leq-left-factor-eq-ℕ m n .(m *ℕ n) H refl =
+ leq-mul-is-nonzero-ℕ n m H
```
## See also
-- Strict inequality of the natural numbers is defined in
- [`strict-inequality-natural-numbers`](elementary-number-theory.strict-inequality-natural-numbers.md)
+- [The bounded natural numbers](elementary-number-theory.bounded-natural-numbers.md)
+- [Strict inequality of the natural numbers](elementary-number-theory.strict-inequality-natural-numbers.md)
diff --git a/src/elementary-number-theory/inequality-rational-numbers.lagda.md b/src/elementary-number-theory/inequality-rational-numbers.lagda.md
index 12ddd6f34a..62cd2945da 100644
--- a/src/elementary-number-theory/inequality-rational-numbers.lagda.md
+++ b/src/elementary-number-theory/inequality-rational-numbers.lagda.md
@@ -169,10 +169,10 @@ module _
where
abstract
- preserves-leq-rational-fraction-ℤ :
+ preserves-order-rational-fraction-ℤ :
leq-fraction-ℤ p q → leq-ℚ (rational-fraction-ℤ p) (rational-fraction-ℤ q)
- preserves-leq-rational-fraction-ℤ =
- preserves-leq-sim-fraction-ℤ
+ preserves-order-rational-fraction-ℤ =
+ leq-sim-fraction-ℤ
( p)
( q)
( reduce-fraction-ℤ p)
@@ -317,11 +317,11 @@ module _
preserves-leq-right-add-ℚ : leq-ℚ x y → leq-ℚ (z +ℚ x) (z +ℚ y)
preserves-leq-right-add-ℚ = backward-implication iff-translate-left-leq-ℚ
- reflects-leq-left-add-ℚ : leq-ℚ (x +ℚ z) (y +ℚ z) → leq-ℚ x y
- reflects-leq-left-add-ℚ = forward-implication iff-translate-right-leq-ℚ
+ reflects-order-left-add-ℚ : leq-ℚ (x +ℚ z) (y +ℚ z) → leq-ℚ x y
+ reflects-order-left-add-ℚ = forward-implication iff-translate-right-leq-ℚ
- reflects-leq-right-add-ℚ : leq-ℚ (z +ℚ x) (z +ℚ y) → leq-ℚ x y
- reflects-leq-right-add-ℚ = forward-implication iff-translate-left-leq-ℚ
+ reflects-order-right-add-ℚ : leq-ℚ (z +ℚ x) (z +ℚ y) → leq-ℚ x y
+ reflects-order-right-add-ℚ = forward-implication iff-translate-left-leq-ℚ
```
### Addition on the rational numbers preserves inequality
diff --git a/src/elementary-number-theory/inequality-standard-finite-types.lagda.md b/src/elementary-number-theory/inequality-standard-finite-types.lagda.md
index d21985ad6f..97d7b4191e 100644
--- a/src/elementary-number-theory/inequality-standard-finite-types.lagda.md
+++ b/src/elementary-number-theory/inequality-standard-finite-types.lagda.md
@@ -84,24 +84,24 @@ leq-succ-Fin :
leq-succ-Fin (succ-ℕ k) (inl x) = leq-succ-Fin k x
leq-succ-Fin (succ-ℕ k) (inr star) = star
-preserves-leq-nat-Fin :
+preserves-order-nat-Fin :
(k : ℕ) {x y : Fin k} → leq-Fin k x y → leq-ℕ (nat-Fin k x) (nat-Fin k y)
-preserves-leq-nat-Fin (succ-ℕ k) {inl x} {inl y} H =
- preserves-leq-nat-Fin k H
-preserves-leq-nat-Fin (succ-ℕ k) {inl x} {inr star} H =
+preserves-order-nat-Fin (succ-ℕ k) {inl x} {inl y} H =
+ preserves-order-nat-Fin k H
+preserves-order-nat-Fin (succ-ℕ k) {inl x} {inr star} H =
leq-le-ℕ (nat-Fin k x) k (strict-upper-bound-nat-Fin k x)
-preserves-leq-nat-Fin (succ-ℕ k) {inr star} {inr star} H =
+preserves-order-nat-Fin (succ-ℕ k) {inr star} {inr star} H =
refl-leq-ℕ k
-reflects-leq-nat-Fin :
+reflects-order-nat-Fin :
(k : ℕ) {x y : Fin k} → leq-ℕ (nat-Fin k x) (nat-Fin k y) → leq-Fin k x y
-reflects-leq-nat-Fin (succ-ℕ k) {inl x} {inl y} H =
- reflects-leq-nat-Fin k H
-reflects-leq-nat-Fin (succ-ℕ k) {inr star} {inl y} H =
+reflects-order-nat-Fin (succ-ℕ k) {inl x} {inl y} H =
+ reflects-order-nat-Fin k H
+reflects-order-nat-Fin (succ-ℕ k) {inr star} {inl y} H =
ex-falso
( contradiction-le-ℕ (nat-Fin k y) k (strict-upper-bound-nat-Fin k y) H)
-reflects-leq-nat-Fin (succ-ℕ k) {inl x} {inr star} H = star
-reflects-leq-nat-Fin (succ-ℕ k) {inr star} {inr star} H = star
+reflects-order-nat-Fin (succ-ℕ k) {inl x} {inr star} H = star
+reflects-order-nat-Fin (succ-ℕ k) {inr star} {inr star} H = star
```
### The partial order on the standard finite types
diff --git a/src/elementary-number-theory/infinitude-of-primes.lagda.md b/src/elementary-number-theory/infinitude-of-primes.lagda.md
index 2da5b37a90..782c96c736 100644
--- a/src/elementary-number-theory/infinitude-of-primes.lagda.md
+++ b/src/elementary-number-theory/infinitude-of-primes.lagda.md
@@ -104,7 +104,10 @@ is-not-one-larger-prime-ℕ :
is-not-one-larger-prime-ℕ n H p with is-successor-is-nonzero-ℕ H
... | pair k refl =
neq-le-ℕ {1} {larger-prime-ℕ n}
- ( concatenate-leq-le-ℕ {1} {succ-ℕ k} {larger-prime-ℕ n} star
+ ( concatenate-leq-le-ℕ 1
+ ( succ-ℕ k)
+ ( larger-prime-ℕ n)
+ ( star)
( le-larger-prime-ℕ (succ-ℕ k)))
( inv p)
@@ -186,6 +189,13 @@ prime-counting-ℕ (succ-ℕ n) =
( prime-counting-ℕ n)
```
+### A very weak lower bound on the prime counting function
+
+In section 2.2 of {{#cite HW08}}, Hardy and Wright illustrate how Euclid's proof
+of the infinitued of primes can be used to derive a lower bound on the prime
+counting function. This lower bound is extremely weak, but could nevertheless be
+found illustrative.
+
## References
{{#bibliography}}
diff --git a/src/elementary-number-theory/inflationary-functions-natural-numbers.lagda.md b/src/elementary-number-theory/inflationary-functions-natural-numbers.lagda.md
new file mode 100644
index 0000000000..baf3d4d0b1
--- /dev/null
+++ b/src/elementary-number-theory/inflationary-functions-natural-numbers.lagda.md
@@ -0,0 +1,84 @@
+# Inflationary functions on the natural numbers
+
+```agda
+module
+ elementary-number-theory.inflationary-functions-natural-numbers
+ where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.universe-levels
+
+open import order-theory.inflationary-maps-posets
+```
+
+
+
+## Idea
+
+A function $f : \mathbb{N} \to \mathbb{N}$ is an
+{{#concept "inflationary function" Disambiguation="natural numbers" Agda=is-inflationary-ℕ}}
+if the implication
+
+$$
+ (x \leq y) \to (f(x) \leq f(y))
+$$
+
+holds for every $x,y:\mathbb{N}$. If $f$ is an inflationary function on the
+natural numbers such that $f(0) \leq b$ for some natural number $b$, then there
+is a maximal natural number $k$ such that $f(k) \leq b$.
+
+## Definitions
+
+### The predicate of being an inflationary map on the natural numbers
+
+```agda
+is-inflationary-ℕ : (ℕ → ℕ) → UU lzero
+is-inflationary-ℕ =
+ is-inflationary-map-Poset ℕ-Poset
+```
+
+### Inflationary maps on the natural numbers
+
+```agda
+inflationary-map-ℕ : UU lzero
+inflationary-map-ℕ =
+ inflationary-map-Poset ℕ-Poset
+
+map-inflationary-map-ℕ :
+ inflationary-map-ℕ → ℕ → ℕ
+map-inflationary-map-ℕ =
+ map-inflationary-map-Poset ℕ-Poset
+
+is-inflationary-inflationary-map-ℕ :
+ (f : inflationary-map-ℕ) →
+ is-inflationary-ℕ (map-inflationary-map-ℕ f)
+is-inflationary-inflationary-map-ℕ =
+ is-inflationary-inflationary-map-Poset ℕ-Poset
+
+fiber-inflationary-map-ℕ :
+ (f : inflationary-map-ℕ) → ℕ → UU lzero
+fiber-inflationary-map-ℕ f = fiber (map-inflationary-map-ℕ f)
+```
+
+## Properties
+
+### Being a value of an inflationary map is decidable
+
+```agda
+is-decidable-fiber-inflationary-map-ℕ :
+ (f : inflationary-map-ℕ) →
+ is-decidable-fam (fiber-inflationary-map-ℕ f)
+is-decidable-fiber-inflationary-map-ℕ = {!!}
+```
+
+### For any inflationary map $f$ with $f(0) \leq b$, there is a maximal number $k$ such that $f(k) \leq b$
diff --git a/src/elementary-number-theory/integer-fractions.lagda.md b/src/elementary-number-theory/integer-fractions.lagda.md
index dea0da34e6..21c5a49459 100644
--- a/src/elementary-number-theory/integer-fractions.lagda.md
+++ b/src/elementary-number-theory/integer-fractions.lagda.md
@@ -10,6 +10,7 @@ module elementary-number-theory.integer-fractions where
open import elementary-number-theory.greatest-common-divisor-integers
open import elementary-number-theory.integers
open import elementary-number-theory.multiplication-integers
+open import elementary-number-theory.natural-numbers
open import elementary-number-theory.nonzero-integers
open import elementary-number-theory.positive-and-negative-integers
open import elementary-number-theory.positive-integers
@@ -64,6 +65,10 @@ denominator-fraction-ℤ x = pr1 (positive-denominator-fraction-ℤ x)
is-positive-denominator-fraction-ℤ :
(x : fraction-ℤ) → is-positive-ℤ (denominator-fraction-ℤ x)
is-positive-denominator-fraction-ℤ x = pr2 (positive-denominator-fraction-ℤ x)
+
+nat-denominator-fraction-ℤ : fraction-ℤ → ℕ
+nat-denominator-fraction-ℤ x =
+ nat-positive-ℤ (positive-denominator-fraction-ℤ x)
```
### Inclusion of the integers
@@ -129,12 +134,35 @@ fraction-ℤ-Set : Set lzero
fraction-ℤ-Set = fraction-ℤ , is-set-fraction-ℤ
```
+### The standard equivalence relation on integer fractions
+
+Two integer fractions `a/b` and `c/d` are said to be equivalent if they satisfy
+the equation
+
+```text
+ ad = cb.
+```
+
+This relation is obviously reflexive and symmetric. To see that it is
+transitive, suppose that `a/b ~ c/d` and that `c/d ~ e/f`. Since `d` is
+positive, we have the implication
+
+```text
+ (af)d = (eb)d → af = eb.
+```
+
+Therefore it suffices to show that `(af)d = (eb)d`. To see this, we calculate
+
+```text
+ (af)d = (ad)f = (cb)f = (cf)b = (ed)b = (eb)d.
+```
+
```agda
sim-fraction-ℤ-Prop : fraction-ℤ → fraction-ℤ → Prop lzero
sim-fraction-ℤ-Prop x y =
Id-Prop ℤ-Set
- ((numerator-fraction-ℤ x) *ℤ (denominator-fraction-ℤ y))
- ((numerator-fraction-ℤ y) *ℤ (denominator-fraction-ℤ x))
+ ( numerator-fraction-ℤ x *ℤ denominator-fraction-ℤ y)
+ ( numerator-fraction-ℤ y *ℤ denominator-fraction-ℤ x)
sim-fraction-ℤ : fraction-ℤ → fraction-ℤ → UU lzero
sim-fraction-ℤ x y = type-Prop (sim-fraction-ℤ-Prop x y)
@@ -150,54 +178,11 @@ symmetric-sim-fraction-ℤ x y r = inv r
abstract
transitive-sim-fraction-ℤ : is-transitive sim-fraction-ℤ
- transitive-sim-fraction-ℤ x y z s r =
- is-injective-right-mul-ℤ
- ( denominator-fraction-ℤ y)
+ transitive-sim-fraction-ℤ (a , b , pb) y@(c , d , pd) (e , f , pf) s r =
+ is-injective-right-mul-ℤ d
( is-nonzero-denominator-fraction-ℤ y)
- ( ( associative-mul-ℤ
- ( numerator-fraction-ℤ x)
- ( denominator-fraction-ℤ z)
- ( denominator-fraction-ℤ y)) ∙
- ( ap
- ( (numerator-fraction-ℤ x) *ℤ_)
- ( commutative-mul-ℤ
- ( denominator-fraction-ℤ z)
- ( denominator-fraction-ℤ y))) ∙
- ( inv
- ( associative-mul-ℤ
- ( numerator-fraction-ℤ x)
- ( denominator-fraction-ℤ y)
- ( denominator-fraction-ℤ z))) ∙
- ( ap ( _*ℤ (denominator-fraction-ℤ z)) r) ∙
- ( associative-mul-ℤ
- ( numerator-fraction-ℤ y)
- ( denominator-fraction-ℤ x)
- ( denominator-fraction-ℤ z)) ∙
- ( ap
- ( (numerator-fraction-ℤ y) *ℤ_)
- ( commutative-mul-ℤ
- ( denominator-fraction-ℤ x)
- ( denominator-fraction-ℤ z))) ∙
- ( inv
- ( associative-mul-ℤ
- ( numerator-fraction-ℤ y)
- ( denominator-fraction-ℤ z)
- ( denominator-fraction-ℤ x))) ∙
- ( ap (_*ℤ (denominator-fraction-ℤ x)) s) ∙
- ( associative-mul-ℤ
- ( numerator-fraction-ℤ z)
- ( denominator-fraction-ℤ y)
- ( denominator-fraction-ℤ x)) ∙
- ( ap
- ( (numerator-fraction-ℤ z) *ℤ_)
- ( commutative-mul-ℤ
- ( denominator-fraction-ℤ y)
- ( denominator-fraction-ℤ x))) ∙
- ( inv
- ( associative-mul-ℤ
- ( numerator-fraction-ℤ z)
- ( denominator-fraction-ℤ x)
- ( denominator-fraction-ℤ y))))
+ ( right-swap-mul-ℤ a f d ∙ ap (_*ℤ f) r ∙
+ right-swap-mul-ℤ c b f ∙ ap (_*ℤ b) s ∙ right-swap-mul-ℤ e d b)
equivalence-relation-sim-fraction-ℤ : equivalence-relation lzero fraction-ℤ
pr1 equivalence-relation-sim-fraction-ℤ = sim-fraction-ℤ-Prop
diff --git a/src/elementary-number-theory/irrationality-square-root-of-2.lagda.md b/src/elementary-number-theory/irrationality-square-root-of-2.lagda.md
new file mode 100644
index 0000000000..ed8ae2a93a
--- /dev/null
+++ b/src/elementary-number-theory/irrationality-square-root-of-2.lagda.md
@@ -0,0 +1,65 @@
+# The irrationality of the square root of 2
+
+```agda
+module elementary-number-theory.irrationality-square-root-of-2 where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-integers
+open import elementary-number-theory.integer-fractions
+open import elementary-number-theory.integers
+open import elementary-number-theory.multiplication-integer-fractions
+open import elementary-number-theory.multiplication-integers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.reduced-integer-fractions
+open import elementary-number-theory.squares-natural-numbers
+
+open import foundation.coproduct-types
+open import foundation.dependent-pair-types
+open import foundation.identity-types
+open import foundation.negation
+```
+
+
+
+## Idea
+
+The {{#concept "irrationality of √2" Agda=irrationality-sqrt-2}} is the theorem
+that there is no [rational number](elementary-number-theory.rational-numbers.md)
+whose square is $2$.
+
+**Proof.** Suppose that there is a rational number $q$ such that $q^2 = 2$. Then
+we can represent $q$ as a
+[reduced integer fraction](elementary-number-theory.reduced-integer-fractions.md)
+$\frac{a}{b}$ such that
+
+$$
+a^2 = 2b^2.
+$$
+
+Since $a^2$ is an
+[even number](elementary-number-theory.parity-natural-numbers.md), it follows
+that $a$ is an even number. In other words, $a = 2k$ for some number $k$. This
+implies that $a^2 = 4k^2$, and thus we see that
+
+$$
+2k^2 = b^2.
+$$
+
+Now we see that $b^2$ is even, which implies that $b$ is even. The consequence
+that both $a$ and $b$ are even contradicts the assumption that $\frac{a}{b}$ is
+a reduced fraction.
+
+## Properties
+
+### There is no reduced fraction whose square is $2$
+
+```text
+not-two-square-reduced-fraction-ℤ :
+ (x : fraction-ℤ) (H : is-reduced-fraction-ℤ x) →
+ ¬ sim-fraction-ℤ (mul-fraction-ℤ x x) (in-fraction-ℤ (int-ℕ 2))
+not-two-square-reduced-fraction-ℤ x@(a , b , pb) H K =
+ {!!}
+```
diff --git a/src/elementary-number-theory/jacobi-symbol.lagda.md b/src/elementary-number-theory/jacobi-symbol.lagda.md
index b7c291a319..f4b447aa87 100644
--- a/src/elementary-number-theory/jacobi-symbol.lagda.md
+++ b/src/elementary-number-theory/jacobi-symbol.lagda.md
@@ -53,5 +53,7 @@ jacobi-symbol a (succ-ℕ (succ-ℕ n)) =
( mul-ℤ)
( map-list
( swap-Π legendre-symbol a)
- ( list-primes-fundamental-theorem-arithmetic-ℕ (succ-ℕ (succ-ℕ n)) star))
+ ( list-of-primes-fundamental-theorem-arithmetic-ℕ
+ ( succ-ℕ (succ-ℕ n))
+ ( star)))
```
diff --git a/src/elementary-number-theory/kolakoski-sequence.lagda.md b/src/elementary-number-theory/kolakoski-sequence.lagda.md
index 602bc2597a..4177f4a729 100644
--- a/src/elementary-number-theory/kolakoski-sequence.lagda.md
+++ b/src/elementary-number-theory/kolakoski-sequence.lagda.md
@@ -48,7 +48,7 @@ kolakoski-helper-inductive :
((i : ℕ) → i ≤-ℕ n → bool × (bool × (Σ ℕ (λ j → j ≤-ℕ i)))) →
bool × (bool × (Σ ℕ (λ j → j ≤-ℕ (succ-ℕ n))))
kolakoski-helper-inductive n f with f n (refl-leq-ℕ n)
-... | b , false , i , H = b , true , i , preserves-leq-succ-ℕ i n H
+... | b , false , i , H = b , true , i , leq-succ-leq-ℕ i n H
... | b , true , i , H with f i H
... | true , true , j , K = neg-bool b , true , succ-ℕ i , H
... | true , false , j , K = neg-bool b , false , succ-ℕ i , H
diff --git a/src/elementary-number-theory/largest-power-divisors-natural-numbers.lagda.md b/src/elementary-number-theory/largest-power-divisors-natural-numbers.lagda.md
new file mode 100644
index 0000000000..52e6ce6bf8
--- /dev/null
+++ b/src/elementary-number-theory/largest-power-divisors-natural-numbers.lagda.md
@@ -0,0 +1,208 @@
+# Largest power divisors of natural numbers
+
+```agda
+module elementary-number-theory.largest-power-divisors-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.exponentiation-natural-numbers
+open import elementary-number-theory.finite-maps-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.maximal-structured-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+open import elementary-number-theory.upper-bounds-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.identity-types
+open import foundation.logical-equivalences
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+The
+{{#concept "largest power divisor" Disambiguation="natural numbers" Agda=largest-power-divisor-ℕ}}
+of a [natural number](elementary-number-theory.natural-numbers.md) $n$ with base
+$m$ is the
+[largest number](elementary-number-theory.maximal-structured-natural-numbers.md)
+of the form $m^k$ that
+[divides](elementary-number-theory.divisibility-natural-numbers.md) $n$.
+
+## Definitions
+
+### Power divisors of natural numbers
+
+```agda
+is-power-divisor-ℕ : ℕ → ℕ → ℕ → UU lzero
+is-power-divisor-ℕ m n x = is-exponential-ℕ m x × div-ℕ x n
+
+valuation-is-power-divisor-ℕ :
+ (m n x : ℕ) → is-power-divisor-ℕ m n x → ℕ
+valuation-is-power-divisor-ℕ m n x H =
+ pr1 (pr1 H)
+
+compute-exp-valuation-is-power-divisor-ℕ :
+ (m n x : ℕ) (H : is-power-divisor-ℕ m n x) →
+ m ^ℕ valuation-is-power-divisor-ℕ m n x H = x
+compute-exp-valuation-is-power-divisor-ℕ m n x H =
+ pr2 (pr1 H)
+```
+
+### The predicate of being the largest power divisor of a natural number
+
+```agda
+module _
+ (m n x : ℕ)
+ where
+
+ is-largest-power-divisor-ℕ : UU lzero
+ is-largest-power-divisor-ℕ =
+ Σ ( is-power-divisor-ℕ m n x)
+ ( λ H →
+ (y : ℕ) (K : is-power-divisor-ℕ m n y) →
+ valuation-is-power-divisor-ℕ m n y K ≤-ℕ
+ valuation-is-power-divisor-ℕ m n x H)
+
+ is-power-divisor-is-largest-power-divisor-ℕ :
+ is-largest-power-divisor-ℕ → is-power-divisor-ℕ m n x
+ is-power-divisor-is-largest-power-divisor-ℕ =
+ pr1
+
+ valuation-is-largest-power-divisor-ℕ :
+ is-largest-power-divisor-ℕ → ℕ
+ valuation-is-largest-power-divisor-ℕ H =
+ valuation-is-power-divisor-ℕ m n x
+ ( is-power-divisor-is-largest-power-divisor-ℕ H)
+
+ compute-exp-valuation-is-largest-power-divisor-ℕ :
+ (H : is-largest-power-divisor-ℕ) →
+ m ^ℕ valuation-is-largest-power-divisor-ℕ H = x
+ compute-exp-valuation-is-largest-power-divisor-ℕ H =
+ compute-exp-valuation-is-power-divisor-ℕ m n x
+ ( is-power-divisor-is-largest-power-divisor-ℕ H)
+
+ is-upper-bound-valuation-is-largest-power-divisor-ℕ :
+ (H : is-largest-power-divisor-ℕ) →
+ (y : ℕ) (K : is-power-divisor-ℕ m n y) →
+ valuation-is-power-divisor-ℕ m n y K ≤-ℕ
+ valuation-is-largest-power-divisor-ℕ H
+ is-upper-bound-valuation-is-largest-power-divisor-ℕ =
+ pr2
+```
+
+### The largest power divisor of a nonzero natural number
+
+```agda
+module _
+ (m n : ℕ) (H : 1 <-ℕ m) (K : is-nonzero-ℕ n)
+ where
+
+ largest-power-divisor-ℕ :
+ maximal-element-ℕ
+ ( is-structured-value-bound-input-ℕ (is-divisor-ℕ n) (m ^ℕ_) n)
+ largest-power-divisor-ℕ =
+ maximal-structured-value-bound-input-property-is-finite-map-ℕ
+ ( is-divisor-ℕ n)
+ ( λ x → is-decidable-div-ℕ x n)
+ ( m ^ℕ_)
+ ( is-finite-map-exp-ℕ m H)
+ ( n)
+ ( 0)
+ ( leq-one-is-nonzero-ℕ n K)
+ ( div-one-ℕ n)
+
+ valuation-largest-power-divisor-ℕ :
+ ℕ
+ valuation-largest-power-divisor-ℕ =
+ nat-maximal-element-ℕ
+ ( is-structured-value-bound-input-ℕ (is-divisor-ℕ n) (m ^ℕ_) n)
+ ( largest-power-divisor-ℕ)
+
+ nat-largest-power-divisor-ℕ :
+ ℕ
+ nat-largest-power-divisor-ℕ =
+ m ^ℕ valuation-largest-power-divisor-ℕ
+
+ upper-bound-nat-largest-power-divisor-ℕ :
+ m ^ℕ valuation-largest-power-divisor-ℕ ≤-ℕ n
+ upper-bound-nat-largest-power-divisor-ℕ =
+ pr1
+ ( structure-maximal-element-ℕ
+ ( is-structured-value-bound-input-ℕ (is-divisor-ℕ n) (m ^ℕ_) n)
+ ( largest-power-divisor-ℕ))
+
+ div-largest-power-divisor-ℕ :
+ div-ℕ (m ^ℕ valuation-largest-power-divisor-ℕ) n
+ div-largest-power-divisor-ℕ =
+ pr2
+ ( structure-maximal-element-ℕ
+ ( is-structured-value-bound-input-ℕ (is-divisor-ℕ n) (m ^ℕ_) n)
+ ( largest-power-divisor-ℕ))
+
+ is-power-divisor-largest-power-divisor-ℕ :
+ is-power-divisor-ℕ m n nat-largest-power-divisor-ℕ
+ pr1 (pr1 is-power-divisor-largest-power-divisor-ℕ) =
+ valuation-largest-power-divisor-ℕ
+ pr2 (pr1 is-power-divisor-largest-power-divisor-ℕ) =
+ refl
+ pr2 is-power-divisor-largest-power-divisor-ℕ =
+ div-largest-power-divisor-ℕ
+
+ is-upper-bound-valuation-largest-power-divisor-ℕ :
+ (k : ℕ) → div-ℕ (m ^ℕ k) n → k ≤-ℕ valuation-largest-power-divisor-ℕ
+ is-upper-bound-valuation-largest-power-divisor-ℕ k L =
+ is-upper-bound-maximal-element-ℕ
+ ( is-structured-value-bound-input-ℕ (is-divisor-ℕ n) (m ^ℕ_) n)
+ ( largest-power-divisor-ℕ)
+ ( k)
+ ( leq-div-ℕ (m ^ℕ k) n K L , L)
+
+ is-largest-power-divisor-largest-power-divisor-ℕ :
+ is-largest-power-divisor-ℕ m n nat-largest-power-divisor-ℕ
+ pr1 is-largest-power-divisor-largest-power-divisor-ℕ =
+ is-power-divisor-largest-power-divisor-ℕ
+ pr2 is-largest-power-divisor-largest-power-divisor-ℕ y ((k , refl) , K) =
+ is-upper-bound-valuation-largest-power-divisor-ℕ k K
+```
+
+### Any two largest power divisors are equal
+
+```agda
+module _
+ (m n x y : ℕ) (H : 1 <-ℕ m)
+ where
+
+ eq-valuation-is-largest-power-divisor-ℕ :
+ (H : is-largest-power-divisor-ℕ m n x)
+ (K : is-largest-power-divisor-ℕ m n y) →
+ valuation-is-largest-power-divisor-ℕ m n x H =
+ valuation-is-largest-power-divisor-ℕ m n y K
+ eq-valuation-is-largest-power-divisor-ℕ H K =
+ antisymmetric-leq-ℕ
+ ( valuation-is-largest-power-divisor-ℕ m n x H)
+ ( valuation-is-largest-power-divisor-ℕ m n y K)
+ ( is-upper-bound-valuation-is-largest-power-divisor-ℕ m n y K x
+ ( is-power-divisor-is-largest-power-divisor-ℕ m n x H))
+ ( is-upper-bound-valuation-is-largest-power-divisor-ℕ m n x H y
+ ( is-power-divisor-is-largest-power-divisor-ℕ m n y K))
+
+ eq-is-largest-power-divisor-ℕ :
+ is-largest-power-divisor-ℕ m n x → is-largest-power-divisor-ℕ m n y →
+ x = y
+ eq-is-largest-power-divisor-ℕ H K =
+ inv (compute-exp-valuation-is-largest-power-divisor-ℕ m n x H) ∙
+ ap (m ^ℕ_) (eq-valuation-is-largest-power-divisor-ℕ H K) ∙
+ compute-exp-valuation-is-largest-power-divisor-ℕ m n y K
+```
+
+## See also
+
+- [2-adic decomposition](elementary-number-theory.2-adic-decomposition.md)
diff --git a/src/elementary-number-theory/lists-of-prime-numbers.lagda.md b/src/elementary-number-theory/lists-of-prime-numbers.lagda.md
new file mode 100644
index 0000000000..f47377c5b1
--- /dev/null
+++ b/src/elementary-number-theory/lists-of-prime-numbers.lagda.md
@@ -0,0 +1,55 @@
+# Lists of prime numbers
+
+```agda
+module elementary-number-theory.lists-of-prime-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.prime-numbers
+
+open import foundation.dependent-pair-types
+open import foundation.propositions
+open import foundation.unit-type
+open import foundation.universe-levels
+
+open import lists.functoriality-lists
+open import lists.lists
+open import lists.universal-quantification-lists
+```
+
+
+
+## Idea
+
+A {{#concept "list of prime numbers"}} is a [list](lists.lists.md) of
+[natural numbers](elementary-number-theory.natural-numbers.md) such that each
+number in the list is [prime](elementary-number-theory.prime-numbers.md).
+
+## Definitions
+
+### The predicate on lists of natural numbers of being a list of prime numbers
+
+```agda
+is-prime-list-ℕ :
+ list ℕ → UU lzero
+is-prime-list-ℕ l = for-all-list l is-prime-ℕ
+
+is-prop-is-prime-list-ℕ :
+ (l : list ℕ) → is-prop (is-prime-list-ℕ l)
+is-prop-is-prime-list-ℕ l = is-prop-for-all-list l is-prime-ℕ-Prop
+```
+
+## Properties
+
+### Any list of prime numbers is a prime list
+
+```agda
+is-prime-list-list-Prime-ℕ :
+ (l : list Prime-ℕ) → is-prime-list-ℕ (map-list nat-Prime-ℕ l)
+is-prime-list-list-Prime-ℕ nil = raise-star
+is-prime-list-list-Prime-ℕ (cons x l) =
+ ( is-prime-Prime-ℕ x , is-prime-list-list-Prime-ℕ l)
+```
diff --git a/src/elementary-number-theory/lower-bounds-natural-numbers.lagda.md b/src/elementary-number-theory/lower-bounds-natural-numbers.lagda.md
index 1a84c70750..dc7d1441ac 100644
--- a/src/elementary-number-theory/lower-bounds-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/lower-bounds-natural-numbers.lagda.md
@@ -1,4 +1,4 @@
-# Lower bounds of type families over the natural numbers
+# Lower bounds for structured natural numbers
```agda
module elementary-number-theory.lower-bounds-natural-numbers where
@@ -9,9 +9,20 @@ module elementary-number-theory.lower-bounds-natural-numbers where
```agda
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+open import foundation.decidable-types
open import foundation.dependent-pair-types
+open import foundation.double-negation
+open import foundation.empty-types
+open import foundation.function-types
+open import foundation.identity-types
+open import foundation.logical-equivalences
+open import foundation.negation
+open import foundation.propositional-extensionality
open import foundation.propositions
+open import foundation.transport-along-identifications
+open import foundation.type-arithmetic-empty-type
open import foundation.universe-levels
```
@@ -19,16 +30,79 @@ open import foundation.universe-levels
## Idea
-A lower bound for a type family `P` over the natural numbers is a natural number
-`n` such that `P x → n ≤ x` for all `x : ℕ`.
+Consider a type family $P$ over the
+[natural numbers](elementary-number-theory.natural-numbers.md). A
+{{#concept "structured natural number"}} is simply a natural number $n$ equipped
+with an element $P(n)$. In this file we consider various upper bounds for
+structured natural numbers, and relations between them. This file builds the
+prerequisite infrastructure for the
+[well-ordering principle](elementary-number-theory.well-ordering-principle-natural-numbers.md)
+of the natural numbers, and its direct consequences.
-## Definition
+- A natural number $n$ is said to be a
+ {{#concept "lower bound" Disambiguation="structured natural numbers" Agda=is-lower-bound-ℕ}}
+ if there is a function from $P(x)$ to the type $n \leq x$ for all
+ $x : \mathbb{N}$.
+- A natural number $n$ is said to be a
+ {{#concept "strict lower bound" Disambiguation="structured natural numbers" Agda=is-strict-lower-bound-ℕ}}
+ if there is a function from $P(x)$ to the type $n < x$ for all
+ $x : \mathbb{N}$.
+- A natural number $n$ is said to be a
+ {{#concept "largest lower bound" Disambiguation="structured natural numbers" Agda=is-largest-lower-bound-ℕ}}
+ if any natural number $x$ is a lower bound if and only if $x \leq n$.
+- A natural number $n$ is said to be a
+ {{#concept "largest strict lower bound" Disambiguation="structured natural numbers" Agda=is-largest-strict-lower-bound-ℕ}}
+ if any natural number $x$ is a strict lower bound if and only if $x \leq n$.
+
+## Definitions
+
+### Lower bounds
```agda
is-lower-bound-ℕ :
- {l : Level} (P : ℕ → UU l) (n : ℕ) → UU l
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
is-lower-bound-ℕ P n =
- (m : ℕ) → P m → leq-ℕ n m
+ (m : ℕ) → P m → n ≤-ℕ m
+```
+
+### Strict lower bounds
+
+```agda
+is-strict-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) → UU l
+is-strict-lower-bound-ℕ P n =
+ (m : ℕ) → P m → n <-ℕ m
+```
+
+### Largest lower bounds
+
+```agda
+is-largest-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
+is-largest-lower-bound-ℕ P n =
+ (x : ℕ) → is-lower-bound-ℕ P x ↔ x ≤-ℕ n
+
+is-lower-bound-is-largest-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-largest-lower-bound-ℕ P n → is-lower-bound-ℕ P n
+is-lower-bound-is-largest-lower-bound-ℕ P n H =
+ backward-implication (H n) (refl-leq-ℕ n)
+
+leq-is-largest-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-largest-lower-bound-ℕ P n →
+ (m : ℕ) → is-lower-bound-ℕ P m → m ≤-ℕ n
+leq-is-largest-lower-bound-ℕ P n H m =
+ forward-implication (H m)
+```
+
+### Largest strict lower bounds
+
+```agda
+is-largest-strict-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
+is-largest-strict-lower-bound-ℕ P n =
+ (x : ℕ) → is-strict-lower-bound-ℕ P x ↔ x ≤-ℕ n
```
## Properties
@@ -37,15 +111,174 @@ is-lower-bound-ℕ P n =
```agda
module _
- {l1 : Level} {P : ℕ → UU l1}
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-prop-is-lower-bound-ℕ :
+ (n : ℕ) → is-prop (is-lower-bound-ℕ P n)
+ is-prop-is-lower-bound-ℕ n =
+ is-prop-Π (λ x → is-prop-function-type (is-prop-leq-ℕ n x))
+
+ is-lower-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-lower-bound-ℕ-Prop n) = is-lower-bound-ℕ P n
+ pr2 (is-lower-bound-ℕ-Prop n) = is-prop-is-lower-bound-ℕ n
+```
+
+### Being a strict lower bound is a property
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-prop-is-strict-lower-bound-ℕ :
+ (n : ℕ) → is-prop (is-strict-lower-bound-ℕ P n)
+ is-prop-is-strict-lower-bound-ℕ n =
+ is-prop-Π (λ x → is-prop-function-type (is-prop-le-ℕ n x))
+
+ is-strict-lower-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-strict-lower-bound-ℕ-Prop n) = is-strict-lower-bound-ℕ P n
+ pr2 (is-strict-lower-bound-ℕ-Prop n) = is-prop-is-strict-lower-bound-ℕ n
+```
+
+### Being a largest lower bound is a property
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-prop-is-largest-lower-bound-ℕ :
+ (n : ℕ) → is-prop (is-largest-lower-bound-ℕ P n)
+ is-prop-is-largest-lower-bound-ℕ n =
+ is-prop-Π
+ ( λ x → is-prop-iff-Prop (is-lower-bound-ℕ-Prop P x) (leq-ℕ-Prop x n))
+
+ is-largest-lower-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-largest-lower-bound-ℕ-Prop n) = is-largest-lower-bound-ℕ P n
+ pr2 (is-largest-lower-bound-ℕ-Prop n) = is-prop-is-largest-lower-bound-ℕ n
+```
+
+### Being a largest strict lower bound is a property
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
where
- abstract
- is-prop-is-lower-bound-ℕ : (x : ℕ) → is-prop (is-lower-bound-ℕ P x)
- is-prop-is-lower-bound-ℕ x =
- is-prop-Π (λ y → is-prop-function-type (is-prop-leq-ℕ x y))
+ is-prop-is-largest-strict-lower-bound-ℕ :
+ (n : ℕ) → is-prop (is-largest-strict-lower-bound-ℕ P n)
+ is-prop-is-largest-strict-lower-bound-ℕ n =
+ is-prop-Π
+ ( λ x →
+ is-prop-iff-Prop (is-strict-lower-bound-ℕ-Prop P x) (leq-ℕ-Prop x n))
+
+ is-largest-strict-lower-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-largest-strict-lower-bound-ℕ-Prop n) =
+ is-largest-strict-lower-bound-ℕ P n
+ pr2 (is-largest-strict-lower-bound-ℕ-Prop n) =
+ is-prop-is-largest-strict-lower-bound-ℕ n
+```
+
+### A strict lower bound is a lower bound
+
+```agda
+is-lower-bound-is-strict-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-strict-lower-bound-ℕ P n → is-lower-bound-ℕ P n
+is-lower-bound-is-strict-lower-bound-ℕ P n H x p =
+ leq-le-ℕ n x (H x p)
+```
+
+### Any two largest lower bounds are equal
+
+```agda
+eq-is-largest-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (m n : ℕ) →
+ is-largest-lower-bound-ℕ P m → is-largest-lower-bound-ℕ P n → m = n
+eq-is-largest-lower-bound-ℕ P m n H K =
+ antisymmetric-leq-ℕ m n
+ ( leq-is-largest-lower-bound-ℕ P n K m
+ ( is-lower-bound-is-largest-lower-bound-ℕ P m H))
+ ( leq-is-largest-lower-bound-ℕ P m H n
+ ( is-lower-bound-is-largest-lower-bound-ℕ P n K))
+```
+
+### If $n$ is a largest lower bound, then $n + 1$ is not a largest lower bound
+
+```agda
+is-largest-lower-bound-succ-is-largest-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-largest-lower-bound-ℕ P n → ¬ is-largest-lower-bound-ℕ P (succ-ℕ n)
+is-largest-lower-bound-succ-is-largest-lower-bound-ℕ P n H K =
+ has-no-fixed-points-succ-ℕ n
+ ( eq-is-largest-lower-bound-ℕ P (succ-ℕ n) n K H)
+```
- is-lower-bound-ℕ-Prop : (x : ℕ) → Prop l1
- pr1 (is-lower-bound-ℕ-Prop x) = is-lower-bound-ℕ P x
- pr2 (is-lower-bound-ℕ-Prop x) = is-prop-is-lower-bound-ℕ x
+### If $n + 1$ is a lower bound and $P (n + 1)$ is empty, then $n$ is a lower bound
+
+```agda
+increase-is-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-lower-bound-ℕ P n → ¬ P n → is-lower-bound-ℕ P (succ-ℕ n)
+increase-is-lower-bound-ℕ P n H f m p =
+ map-left-unit-law-coproduct-is-empty
+ ( n = m)
+ ( succ-ℕ n ≤-ℕ m)
+ ( λ α → f (tr P (inv α) p))
+ ( decide-leq-ℕ n m (H m p))
+```
+
+### Any successor natural number $n + 1$ such that $P (n + 1)$ is empty is not a largest lower bound
+
+```agda
+is-not-largest-lower-bound-is-empty-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ ¬ P n → ¬ is-largest-lower-bound-ℕ P n
+is-not-largest-lower-bound-is-empty-ℕ P n f H =
+ neg-succ-leq-ℕ n
+ ( leq-is-largest-lower-bound-ℕ P
+ ( n)
+ ( H)
+ ( succ-ℕ n)
+ ( increase-is-lower-bound-ℕ P n
+ ( is-lower-bound-is-largest-lower-bound-ℕ P n H)
+ ( f)))
+```
+
+### The type $P$ at the largest lower bound is nonempty
+
+```agda
+is-nonempty-structure-is-in-family-is-largest-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-largest-lower-bound-ℕ P n → is-nonempty (P n)
+is-nonempty-structure-is-in-family-is-largest-lower-bound-ℕ P n H f =
+ is-not-largest-lower-bound-is-empty-ℕ P n f H
+```
+
+### Any largest lower bound of a family of decidable types over $\mathbb{N}$ is structured in $P$
+
+```agda
+structure-largest-lower-bound-is-decidable-fam-ℕ :
+ {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) →
+ (n : ℕ) → is-largest-lower-bound-ℕ P n → P n
+structure-largest-lower-bound-is-decidable-fam-ℕ P d n H =
+ double-negation-elim-is-decidable
+ ( d n)
+ ( is-nonempty-structure-is-in-family-is-largest-lower-bound-ℕ P n H)
+```
+
+### Any lower bound equipped with structure is a largest lower bound
+
+```agda
+is-largest-lower-bound-is-lower-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ P n → is-lower-bound-ℕ P n → is-largest-lower-bound-ℕ P n
+pr1 (is-largest-lower-bound-is-lower-bound-ℕ P n p H m) K = K n p
+pr2 (is-largest-lower-bound-is-lower-bound-ℕ P n p H m) K x q =
+ transitive-leq-ℕ m n x (H x q) K
```
diff --git a/src/elementary-number-theory/maximal-structured-natural-numbers.lagda.md b/src/elementary-number-theory/maximal-structured-natural-numbers.lagda.md
new file mode 100644
index 0000000000..cea52a87ac
--- /dev/null
+++ b/src/elementary-number-theory/maximal-structured-natural-numbers.lagda.md
@@ -0,0 +1,178 @@
+# Maximal structured natural numbers
+
+```agda
+module elementary-number-theory.maximal-structured-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.lower-bounds-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.upper-bounds-natural-numbers
+
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.function-types
+open import foundation.propositions
+open import foundation.subtypes
+open import foundation.universe-levels
+```
+
+
+
+Consider a type family $P$ over $\mathbb{N}$. A
+{{#concept "maximal structured natural number" Agda=maximal-element-ℕ}} in $P$
+is a natural number $n$ equipped with an element $p : P(n)$ such that $n$ is an
+[upper bound](elementary-number-theory.upper-bounds-natural-numbers.md) for $P$.
+
+Forthermore, a
+{{#concept "bounded maximal structured natural number" Agda=bounded-maximal-element-ℕ}}
+in $P$ with bound $b$ is a natural number $n \leq b$ equipped with an element
+$p : P(n)$ such that $n$ is an upper bound of for the type family
+$x \mapsto (x \leq b) × P(x)$.
+
+## Definitions
+
+### The predicate of being a maximal structured natural number
+
+```agda
+is-maximal-element-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
+is-maximal-element-ℕ P n =
+ P n × is-upper-bound-ℕ P n
+```
+
+### Maximal elements
+
+```agda
+maximal-element-ℕ :
+ {l : Level} (P : ℕ → UU l) → UU l
+maximal-element-ℕ P =
+ Σ ℕ (is-maximal-element-ℕ P)
+
+module _
+ {l : Level} (P : ℕ → UU l) (n : maximal-element-ℕ P)
+ where
+
+ nat-maximal-element-ℕ : ℕ
+ nat-maximal-element-ℕ = pr1 n
+
+ structure-maximal-element-ℕ : P nat-maximal-element-ℕ
+ structure-maximal-element-ℕ = pr1 (pr2 n)
+
+ is-upper-bound-maximal-element-ℕ : is-upper-bound-ℕ P nat-maximal-element-ℕ
+ is-upper-bound-maximal-element-ℕ = pr2 (pr2 n)
+
+ is-least-upper-bound-maximal-element-ℕ :
+ is-least-upper-bound-ℕ P nat-maximal-element-ℕ
+ is-least-upper-bound-maximal-element-ℕ =
+ is-least-upper-bound-is-upper-bound-ℕ P
+ ( nat-maximal-element-ℕ)
+ ( structure-maximal-element-ℕ)
+ ( is-upper-bound-maximal-element-ℕ)
+```
+
+### The predicate of being a maximal bounded structured natural number
+
+```agda
+bounded-family-family-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → ℕ → UU l
+bounded-family-family-ℕ P b n = n ≤-ℕ b × P n
+
+is-maximal-bounded-element-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → ℕ → UU l
+is-maximal-bounded-element-ℕ P b =
+ is-maximal-element-ℕ (bounded-family-family-ℕ P b)
+```
+
+### Bounded maximal elements
+
+```agda
+bounded-maximal-element-ℕ :
+ {l : Level} (P : ℕ → UU l) (b : ℕ) → UU l
+bounded-maximal-element-ℕ P b =
+ maximal-element-ℕ (bounded-family-family-ℕ P b)
+
+module _
+ {l : Level} (P : ℕ → UU l) (b : ℕ) (n : bounded-maximal-element-ℕ P b)
+ where
+
+ nat-bounded-maximal-element-ℕ : ℕ
+ nat-bounded-maximal-element-ℕ = pr1 n
+
+ upper-bound-bounded-maximal-element-ℕ : nat-bounded-maximal-element-ℕ ≤-ℕ b
+ upper-bound-bounded-maximal-element-ℕ = pr1 (pr1 (pr2 n))
+
+ structure-bounded-maximal-element-ℕ : P nat-bounded-maximal-element-ℕ
+ structure-bounded-maximal-element-ℕ = pr2 (pr1 (pr2 n))
+
+ is-upper-bound-bounded-maximal-element-ℕ :
+ is-upper-bound-ℕ (bounded-family-family-ℕ P b) nat-bounded-maximal-element-ℕ
+ is-upper-bound-bounded-maximal-element-ℕ = pr2 (pr2 n)
+
+ is-least-upper-bound-bounded-maximal-element-ℕ :
+ is-least-upper-bound-ℕ
+ ( bounded-family-family-ℕ P b)
+ ( nat-bounded-maximal-element-ℕ)
+ is-least-upper-bound-bounded-maximal-element-ℕ =
+ is-least-upper-bound-is-upper-bound-ℕ
+ ( bounded-family-family-ℕ P b)
+ ( nat-bounded-maximal-element-ℕ)
+ ( upper-bound-bounded-maximal-element-ℕ ,
+ structure-bounded-maximal-element-ℕ)
+ ( is-upper-bound-bounded-maximal-element-ℕ)
+```
+
+## Properties
+
+### The type of maximal elements of a subtype has at most one element
+
+```agda
+module _
+ {l1 : Level} (P : ℕ → Prop l1)
+ where
+
+ all-elements-equal-maximal-element-ℕ :
+ all-elements-equal (maximal-element-ℕ (λ n → type-Prop (P n)))
+ all-elements-equal-maximal-element-ℕ
+ (x , p , l) (y , q , k) =
+ eq-type-subtype
+ ( λ n →
+ product-Prop
+ ( _ , is-prop-type-Prop (P n))
+ ( is-upper-bound-ℕ-Prop (type-Prop ∘ P) n))
+ ( antisymmetric-leq-ℕ x y (k x p) (l y q))
+
+ is-prop-maximal-element-ℕ :
+ is-prop (maximal-element-ℕ (λ n → type-Prop (P n)))
+ is-prop-maximal-element-ℕ =
+ is-prop-all-elements-equal all-elements-equal-maximal-element-ℕ
+
+ maximal-element-ℕ-Prop : Prop l1
+ pr1 maximal-element-ℕ-Prop = maximal-element-ℕ (λ n → type-Prop (P n))
+ pr2 maximal-element-ℕ-Prop = is-prop-maximal-element-ℕ
+```
+
+### A natural number is a largest lower bound if and only if it is a maximal element of the type of lower bounds
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l) (n : ℕ)
+ where
+
+ is-maximal-lower-bound-is-largest-lower-bound-ℕ :
+ is-largest-lower-bound-ℕ P n → is-maximal-element-ℕ (is-lower-bound-ℕ P) n
+ pr1 (is-maximal-lower-bound-is-largest-lower-bound-ℕ H) =
+ is-lower-bound-is-largest-lower-bound-ℕ P n H
+ pr2 (is-maximal-lower-bound-is-largest-lower-bound-ℕ H) m K =
+ leq-is-largest-lower-bound-ℕ P n H m K
+
+ is-largest-lower-bound-is-maximal-lower-bound-ℕ :
+ is-maximal-element-ℕ (is-lower-bound-ℕ P) n → is-largest-lower-bound-ℕ P n
+ pr1 (is-largest-lower-bound-is-maximal-lower-bound-ℕ H m) K =
+ pr2 H m K
+ pr2 (is-largest-lower-bound-is-maximal-lower-bound-ℕ H m) K x p =
+ transitive-leq-ℕ m n x (pr1 H x p) K
+```
diff --git a/src/elementary-number-theory/maximum-natural-numbers.lagda.md b/src/elementary-number-theory/maximum-natural-numbers.lagda.md
index 97038be80f..0f3b2507b3 100644
--- a/src/elementary-number-theory/maximum-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/maximum-natural-numbers.lagda.md
@@ -8,14 +8,23 @@ module elementary-number-theory.maximum-natural-numbers where
```agda
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.natural-numbers
open import foundation.action-on-identifications-binary-functions
open import foundation.action-on-identifications-functions
open import foundation.coproduct-types
+open import foundation.decidable-types
open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.coproduct-types
+open import foundation.functoriality-coproduct-types
+open import foundation.functoriality-dependent-pair-types
open import foundation.identity-types
+open import foundation.negated-equality
+open import foundation.type-arithmetic-empty-type
open import foundation.unit-type
open import order-theory.least-upper-bounds-posets
@@ -27,7 +36,20 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-We define the operation of maximum (least upper bound) for the natural numbers.
+The {{#concept "maximum" Disambiguation="natural numbers" Agda=max-ℕ}} of two
+[natural numbers](elementary-number-theory.natural-numbers.md) is a binary
+operation that returns the largest of two natural numbers. It is defined
+recursively by
+
+```text
+ max-ℕ 0 n = n
+ max-ℕ (m + 1) 0 = m + 1
+ max-ℕ (m + 1) (n + 1) = (max m n) + 1.
+```
+
+Furthermore, we define the maximum of any
+[standard finite](univalent-combinatorics.standard-finite-types.md) family of
+natural numbers.
## Definition
@@ -49,9 +71,10 @@ max-ℕ' x y = max-ℕ y x
### Maximum of elements of standard finite types
```agda
-max-Fin-ℕ : (n : ℕ) → (Fin n → ℕ) → ℕ
-max-Fin-ℕ zero-ℕ f = zero-ℕ
-max-Fin-ℕ (succ-ℕ n) f = max-ℕ (f (inr star)) (max-Fin-ℕ n (λ k → f (inl k)))
+max-standard-finite-family-ℕ : (n : ℕ) → (Fin n → ℕ) → ℕ
+max-standard-finite-family-ℕ zero-ℕ f = zero-ℕ
+max-standard-finite-family-ℕ (succ-ℕ n) f =
+ max-ℕ (max-standard-finite-family-ℕ n (λ k → f (inl k))) (f (inr star))
```
## Properties
@@ -68,7 +91,7 @@ leq-max-ℕ (succ-ℕ k) (succ-ℕ m) zero-ℕ H K = H
leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H K = leq-max-ℕ k m n H K
leq-left-leq-max-ℕ :
- (k m n : ℕ) → (max-ℕ m n) ≤-ℕ k → m ≤-ℕ k
+ (k m n : ℕ) → max-ℕ m n ≤-ℕ k → m ≤-ℕ k
leq-left-leq-max-ℕ k zero-ℕ zero-ℕ H = star
leq-left-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = star
leq-left-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = H
@@ -76,18 +99,18 @@ leq-left-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-left-leq-max-ℕ k m n H
leq-right-leq-max-ℕ :
- (k m n : ℕ) → (max-ℕ m n) ≤-ℕ k → n ≤-ℕ k
+ (k m n : ℕ) → max-ℕ m n ≤-ℕ k → n ≤-ℕ k
leq-right-leq-max-ℕ k zero-ℕ zero-ℕ H = star
leq-right-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = H
leq-right-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = star
leq-right-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-right-leq-max-ℕ k m n H
-left-leq-max-ℕ : (m n : ℕ) → leq-ℕ m (max-ℕ m n)
+left-leq-max-ℕ : (m n : ℕ) → m ≤-ℕ max-ℕ m n
left-leq-max-ℕ m n =
leq-left-leq-max-ℕ (max-ℕ m n) m n (refl-leq-ℕ (max-ℕ m n))
-right-leq-max-ℕ : (m n : ℕ) → leq-ℕ n (max-ℕ m n)
+right-leq-max-ℕ : (m n : ℕ) → n ≤-ℕ max-ℕ m n
right-leq-max-ℕ m n =
leq-right-leq-max-ℕ (max-ℕ m n) m n (refl-leq-ℕ (max-ℕ m n))
@@ -181,3 +204,85 @@ right-distributive-add-max-ℕ x y z =
( ( left-distributive-add-max-ℕ z x y) ∙
( ap-max-ℕ (commutative-add-ℕ z x) (commutative-add-ℕ z y)))
```
+
+### Decide the maximum value
+
+```agda
+decide-max-ℕ :
+ (m n : ℕ) → (max-ℕ m n = m) + (max-ℕ m n = n)
+decide-max-ℕ zero-ℕ n =
+ inr refl
+decide-max-ℕ (succ-ℕ m) zero-ℕ =
+ inl refl
+decide-max-ℕ (succ-ℕ m) (succ-ℕ n) =
+ map-coproduct (ap succ-ℕ) (ap succ-ℕ) (decide-max-ℕ m n)
+
+is-left-max-ℕ :
+ (m n : ℕ) → max-ℕ m n ≠ n → max-ℕ m n = m
+is-left-max-ℕ m n H =
+ map-right-unit-law-coproduct-is-empty
+ ( max-ℕ m n = m)
+ ( max-ℕ m n = n)
+ ( H)
+ ( decide-max-ℕ m n)
+
+is-right-max-ℕ :
+ (m n : ℕ) → max-ℕ m n ≠ m → max-ℕ m n = n
+is-right-max-ℕ m n H =
+ map-left-unit-law-coproduct-is-empty
+ ( max-ℕ m n = m)
+ ( max-ℕ m n = n)
+ ( H)
+ ( decide-max-ℕ m n)
+```
+
+### The maximum of a standard finite family of natural numbers with at least one element is attained
+
+```agda
+is-attained-max-standard-finite-family-succ-ℕ' :
+ (n : ℕ) (f : Fin (succ-ℕ n) → ℕ) →
+ is-decidable (max-standard-finite-family-ℕ (succ-ℕ n) f = f (inr star)) →
+ fiber f (max-standard-finite-family-ℕ (succ-ℕ n) f)
+is-attained-max-standard-finite-family-succ-ℕ' zero-ℕ f d =
+ ( inr star , refl)
+is-attained-max-standard-finite-family-succ-ℕ' (succ-ℕ n) f (inl p) =
+ ( inr star , inv p)
+is-attained-max-standard-finite-family-succ-ℕ' (succ-ℕ n) f (inr np) =
+ map-Σ
+ ( λ k → f k = _)
+ ( inl)
+ ( λ k p →
+ ( p) ∙
+ ( inv
+ ( is-left-max-ℕ
+ ( max-standard-finite-family-ℕ (succ-ℕ n) (f ∘ inl))
+ ( f (inr star))
+ ( np))))
+ ( is-attained-max-standard-finite-family-succ-ℕ' n
+ ( f ∘ inl)
+ ( has-decidable-equality-ℕ _ _))
+
+is-attained-max-standard-finite-family-succ-ℕ :
+ (n : ℕ) (f : Fin (succ-ℕ n) → ℕ) →
+ fiber f (max-standard-finite-family-ℕ (succ-ℕ n) f)
+is-attained-max-standard-finite-family-succ-ℕ n f =
+ is-attained-max-standard-finite-family-succ-ℕ' n f
+ ( has-decidable-equality-ℕ _ _)
+```
+
+### The maximum of a standard finite family of natural numbers is an upper bound
+
+```agda
+is-upper-bound-max-standard-finite-family-ℕ :
+ (n : ℕ) (f : Fin n → ℕ) (i : Fin n) →
+ f i ≤-ℕ max-standard-finite-family-ℕ n f
+is-upper-bound-max-standard-finite-family-ℕ (succ-ℕ n) f (inl x) =
+ transitive-leq-ℕ
+ ( f (inl x))
+ ( max-standard-finite-family-ℕ n (f ∘ inl))
+ ( max-standard-finite-family-ℕ (succ-ℕ n) f)
+ ( left-leq-max-ℕ (max-standard-finite-family-ℕ n (f ∘ inl)) (f (inr star)))
+ ( is-upper-bound-max-standard-finite-family-ℕ n (f ∘ inl) x)
+is-upper-bound-max-standard-finite-family-ℕ (succ-ℕ n) f (inr star) =
+ right-leq-max-ℕ (max-standard-finite-family-ℕ n (f ∘ inl)) (f (inr star))
+```
diff --git a/src/elementary-number-theory/mersenne-exponents.lagda.md b/src/elementary-number-theory/mersenne-exponents.lagda.md
new file mode 100644
index 0000000000..40c7af86fc
--- /dev/null
+++ b/src/elementary-number-theory/mersenne-exponents.lagda.md
@@ -0,0 +1,35 @@
+# Mersenne exponents
+
+```agda
+module elementary-number-theory.mersenne-exponents where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.mersenne-primes
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.prime-numbers
+
+open import foundation.cartesian-product-types
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+A {{#concept "Mersenne exponent" Agda=mersenne-exponent-ℕ OEIS=A000043}} is a
+[prime number](elementary-number-theory.prime-numbers.md) $p$ such that the
+[Mersenne number](elementary-number-theory.mersenne-numbers.md) $M_p$ is a
+[Mersenne prime](elementary-number-theory.mersenne-primes.md).
+
+## Definitions
+
+### The predicate of being a Mersenne exponent
+
+```agda
+is-mersenne-exponent-ℕ : ℕ → UU lzero
+is-mersenne-exponent-ℕ n =
+ is-prime-ℕ n × is-prime-mersenne-number-ℕ n
+```
diff --git a/src/elementary-number-theory/mersenne-numbers.lagda.md b/src/elementary-number-theory/mersenne-numbers.lagda.md
new file mode 100644
index 0000000000..f8c2855c2f
--- /dev/null
+++ b/src/elementary-number-theory/mersenne-numbers.lagda.md
@@ -0,0 +1,74 @@
+# Mersenne numbers
+
+```agda
+module elementary-number-theory.mersenne-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.exponentiation-natural-numbers
+open import elementary-number-theory.infinitude-of-primes
+open import elementary-number-theory.natural-numbers
+
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+The $n$th {{#concept "Mersenne number" Agda=mersenne-number-ℕ OEIS=A000225}}
+$M_n$ is defined to be
+
+$$
+ M_n := 2^n-1.
+$$
+
+[Mersenne primes](elementary-number-theory.mersenne-primes.md) are Mersenne
+numbers that are [prime](elementary-number-theory.prime-numbers.md).
+
+## Definitions
+
+### The Mersenne numbers
+
+```agda
+mersenne-number-ℕ :
+ ℕ → ℕ
+mersenne-number-ℕ n =
+ pred-is-nonzero-ℕ (exp-ℕ 2 n) (is-nonzero-exp-ℕ 2 n is-nonzero-two-ℕ)
+```
+
+### The Mersenne numbers of prime powers
+
+Some sources only refer to numbers of the form $2^p-1$ with $p$ prime as
+Mersenne numbers. The sequence $n ↦ 2^{p(n)}-1$, where $p(n)$ is the $n$th prime
+number, is listed as A001348 in the [OEIS](literature.oeis.md) {{#cite OEIS}}.
+The first few numbers in this sequence are
+
+```text
+ 3, 7, 31, 127, 2047, ...
+```
+
+```agda
+mersenne-number-prime-ℕ :
+ ℕ → ℕ
+mersenne-number-prime-ℕ =
+ mersenne-number-ℕ ∘ prime-ℕ
+```
+
+### The predicate of being a Mersenne number
+
+```agda
+is-mersenne-number-ℕ :
+ ℕ → UU lzero
+is-mersenne-number-ℕ =
+ fiber mersenne-number-ℕ
+```
+
+## See also
+
+- [Mersenne exponents](elementary-number-theory.mersenne-exponents.md)
+- [Mersenne primes](elementary-number-theory.mersenne-primes.md)
diff --git a/src/elementary-number-theory/mersenne-primes.lagda.md b/src/elementary-number-theory/mersenne-primes.lagda.md
index 072edc42fe..e3fc94020a 100644
--- a/src/elementary-number-theory/mersenne-primes.lagda.md
+++ b/src/elementary-number-theory/mersenne-primes.lagda.md
@@ -9,6 +9,7 @@ module elementary-number-theory.mersenne-primes where
```agda
open import elementary-number-theory.distance-natural-numbers
open import elementary-number-theory.exponentiation-natural-numbers
+open import elementary-number-theory.mersenne-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.prime-numbers
@@ -22,14 +23,28 @@ open import foundation.universe-levels
## Idea
-A Mersenne prime is a prime number that is one less than a power of two.
+A
+{{#concept "Mersenne prime" Agda=is-mersenne-prime-ℕ WDID=Q186875 WD="Mersenne prime"}}
+is a [prime number](elementary-number-theory.prime-numbers.md) that is one less
+than a
+[power of two](elementary-number-theory.exponentiation-natural-numbers.md).
-## Definition
+## Definitions
+
+### The predicate of being a Mersenne prime
```agda
-is-mersenne-prime : ℕ → UU lzero
-is-mersenne-prime n = is-prime-ℕ n × Σ ℕ (λ k → dist-ℕ (exp-ℕ 2 k) 1 = n)
+is-mersenne-prime-ℕ :
+ ℕ → UU lzero
+is-mersenne-prime-ℕ n =
+ is-prime-ℕ n × is-mersenne-number-ℕ n
+```
-is-mersenne-prime-power : ℕ → UU lzero
-is-mersenne-prime-power k = is-prime-ℕ (dist-ℕ (exp-ℕ 2 k) 1)
+### The predicate on Mersenne numbers of being prime
+
+```agda
+is-prime-mersenne-number-ℕ :
+ ℕ → UU lzero
+is-prime-mersenne-number-ℕ k =
+ is-prime-ℕ (mersenne-number-ℕ k)
```
diff --git a/src/elementary-number-theory/minimal-structured-natural-numbers.lagda.md b/src/elementary-number-theory/minimal-structured-natural-numbers.lagda.md
new file mode 100644
index 0000000000..857a021b37
--- /dev/null
+++ b/src/elementary-number-theory/minimal-structured-natural-numbers.lagda.md
@@ -0,0 +1,148 @@
+# Minimal structured natural numbers
+
+```agda
+module elementary-number-theory.minimal-structured-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.lower-bounds-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.upper-bounds-natural-numbers
+
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.empty-types
+open import foundation.function-types
+open import foundation.propositions
+open import foundation.subtypes
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+Consider a type family $P$ over $\mathbb{N}$. A
+{{#concept "minimal structured natural number" Agda=minimal-element-ℕ}} in $P$
+is a natural number $n$ equipped with an element $p : P(n)$ such that $n$ is a
+[lower bound](elementary-number-theory.lower-bounds-natural-numbers.md) for $P$.
+
+## Definitions
+
+### The predicate of being a minimal structured natural number
+
+```agda
+is-minimal-element-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
+is-minimal-element-ℕ P n = P n × is-lower-bound-ℕ P n
+```
+
+### Minimal elements
+
+```agda
+minimal-element-ℕ :
+ {l : Level} (P : ℕ → UU l) → UU l
+minimal-element-ℕ P = Σ ℕ (is-minimal-element-ℕ P)
+
+module _
+ {l : Level} (P : ℕ → UU l) (n : minimal-element-ℕ P)
+ where
+
+ nat-minimal-element-ℕ : ℕ
+ nat-minimal-element-ℕ = pr1 n
+
+ structure-minimal-element-ℕ : P nat-minimal-element-ℕ
+ structure-minimal-element-ℕ = pr1 (pr2 n)
+
+ is-lower-bound-minimal-element-ℕ : is-lower-bound-ℕ P nat-minimal-element-ℕ
+ is-lower-bound-minimal-element-ℕ = pr2 (pr2 n)
+
+ is-largest-lower-bound-minimal-element-ℕ :
+ is-largest-lower-bound-ℕ P nat-minimal-element-ℕ
+ is-largest-lower-bound-minimal-element-ℕ =
+ is-largest-lower-bound-is-lower-bound-ℕ P
+ ( nat-minimal-element-ℕ)
+ ( structure-minimal-element-ℕ)
+ ( is-lower-bound-minimal-element-ℕ)
+```
+
+## Properties
+
+### The type of minimal elements of a subtype has at most one element
+
+```agda
+module _
+ {l1 : Level} (P : ℕ → Prop l1)
+ where
+
+ all-elements-equal-minimal-element-ℕ :
+ all-elements-equal (minimal-element-ℕ (λ n → type-Prop (P n)))
+ all-elements-equal-minimal-element-ℕ
+ (x , p , l) (y , q , k) =
+ eq-type-subtype
+ ( λ n →
+ product-Prop
+ ( _ , is-prop-type-Prop (P n))
+ ( is-lower-bound-ℕ-Prop (type-Prop ∘ P) n))
+ ( antisymmetric-leq-ℕ x y (l y q) (k x p))
+
+ is-prop-minimal-element-ℕ :
+ is-prop (minimal-element-ℕ (λ n → type-Prop (P n)))
+ is-prop-minimal-element-ℕ =
+ is-prop-all-elements-equal all-elements-equal-minimal-element-ℕ
+
+ minimal-element-ℕ-Prop : Prop l1
+ pr1 minimal-element-ℕ-Prop = minimal-element-ℕ (λ n → type-Prop (P n))
+ pr2 minimal-element-ℕ-Prop = is-prop-minimal-element-ℕ
+```
+
+### Shifting minimal elements
+
+If $P(0)$ is a decidable type, then we can obtain a minimal structured element
+of $P$ from a minimal structured element of $n\mapsto P(n+1)$.
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ shift-minimal-element-ℕ :
+ is-decidable (P 0) → minimal-element-ℕ (P ∘ succ-ℕ) → minimal-element-ℕ P
+ shift-minimal-element-ℕ (inl p) m =
+ ( 0 , p , λ x _ → leq-zero-ℕ x)
+ pr1 (shift-minimal-element-ℕ (inr f) m) =
+ succ-ℕ (nat-minimal-element-ℕ (P ∘ succ-ℕ) m)
+ pr1 (pr2 (shift-minimal-element-ℕ (inr f) m)) =
+ structure-minimal-element-ℕ (P ∘ succ-ℕ) m
+ pr2 (pr2 (shift-minimal-element-ℕ (inr f) m)) zero-ℕ p =
+ ex-falso (f p)
+ pr2 (pr2 (shift-minimal-element-ℕ (inr f) m)) (succ-ℕ x) p =
+ is-lower-bound-minimal-element-ℕ (P ∘ succ-ℕ) m x p
+```
+
+### A natural number is a least upper bound if and only if it is a minimal element of the type of upper bounds
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l) (n : ℕ)
+ where
+
+ is-minimal-upper-bound-is-least-upper-bound-ℕ :
+ is-least-upper-bound-ℕ P n → is-minimal-element-ℕ (is-upper-bound-ℕ P) n
+ pr1 (is-minimal-upper-bound-is-least-upper-bound-ℕ H) =
+ is-upper-bound-is-least-upper-bound-ℕ P n H
+ pr2 (is-minimal-upper-bound-is-least-upper-bound-ℕ H) m K =
+ leq-is-least-upper-bound-ℕ P n H m K
+
+ is-least-upper-bound-is-minimal-upper-bound-ℕ :
+ is-minimal-element-ℕ (is-upper-bound-ℕ P) n → is-least-upper-bound-ℕ P n
+ pr1 (is-least-upper-bound-is-minimal-upper-bound-ℕ H m) K =
+ pr2 H m K
+ pr2 (is-least-upper-bound-is-minimal-upper-bound-ℕ H m) K x p =
+ transitive-leq-ℕ x n m K (pr1 H x p)
+```
diff --git a/src/elementary-number-theory/modular-arithmetic-standard-finite-types.lagda.md b/src/elementary-number-theory/modular-arithmetic-standard-finite-types.lagda.md
index e7205258f8..aca1cbe6bc 100644
--- a/src/elementary-number-theory/modular-arithmetic-standard-finite-types.lagda.md
+++ b/src/elementary-number-theory/modular-arithmetic-standard-finite-types.lagda.md
@@ -15,6 +15,7 @@ open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
open import foundation.action-on-identifications-binary-functions
open import foundation.action-on-identifications-functions
@@ -60,7 +61,7 @@ mod-three-ℕ = mod-succ-ℕ 2
```agda
cong-nat-succ-Fin :
(k : ℕ) (x : Fin k) →
- cong-ℕ k (nat-Fin k (succ-Fin k x)) (succ-ℕ (nat-Fin k x))
+ nat-Fin k (succ-Fin k x) ≡ succ-ℕ (nat-Fin k x) mod-ℕ k
cong-nat-succ-Fin (succ-ℕ k) (inl x) =
cong-identification-ℕ
( succ-ℕ k)
@@ -77,7 +78,7 @@ cong-nat-succ-Fin (succ-ℕ k) (inr _) =
( cong-zero-ℕ' (succ-ℕ k))
cong-nat-mod-succ-ℕ :
- (k x : ℕ) → cong-ℕ (succ-ℕ k) (nat-Fin (succ-ℕ k) (mod-succ-ℕ k x)) x
+ (k x : ℕ) → nat-Fin (succ-ℕ k) (mod-succ-ℕ k x) ≡ x mod-ℕ succ-ℕ k
cong-nat-mod-succ-ℕ k zero-ℕ = cong-is-zero-nat-zero-Fin
cong-nat-mod-succ-ℕ k (succ-ℕ x) =
transitive-cong-ℕ
@@ -93,7 +94,7 @@ cong-nat-mod-succ-ℕ k (succ-ℕ x) =
```agda
cong-eq-mod-succ-ℕ :
- (k x y : ℕ) → mod-succ-ℕ k x = mod-succ-ℕ k y → cong-ℕ (succ-ℕ k) x y
+ (k x y : ℕ) → mod-succ-ℕ k x = mod-succ-ℕ k y → x ≡ y mod-ℕ succ-ℕ k
cong-eq-mod-succ-ℕ k x y p =
concatenate-cong-eq-cong-ℕ {succ-ℕ k} {x}
( symmetric-cong-ℕ (succ-ℕ k) (nat-Fin (succ-ℕ k) (mod-succ-ℕ k x)) x
@@ -106,7 +107,7 @@ cong-eq-mod-succ-ℕ k x y p =
```agda
eq-mod-succ-cong-ℕ :
- (k x y : ℕ) → cong-ℕ (succ-ℕ k) x y → mod-succ-ℕ k x = mod-succ-ℕ k y
+ (k x y : ℕ) → x ≡ y mod-ℕ succ-ℕ k → mod-succ-ℕ k x = mod-succ-ℕ k y
eq-mod-succ-cong-ℕ k x y H =
eq-cong-nat-Fin
( succ-ℕ k)
@@ -192,6 +193,21 @@ leq-nat-mod-succ-ℕ k (succ-ℕ x) =
( leq-nat-succ-Fin (succ-ℕ k) (mod-succ-ℕ k x))
```
+### If `x < k + 1`, then `x` is equal to its residue modulo `k + 1`
+
+```agda
+eq-nat-mod-succ-ℕ :
+ (k x : ℕ) → x <-ℕ succ-ℕ k → nat-Fin (succ-ℕ k) (mod-succ-ℕ k x) = x
+eq-nat-mod-succ-ℕ k x H =
+ eq-cong-le-ℕ
+ ( succ-ℕ k)
+ ( nat-Fin (succ-ℕ k) (mod-succ-ℕ k x))
+ ( x)
+ ( strict-upper-bound-nat-Fin (succ-ℕ k) (mod-succ-ℕ k x))
+ ( H)
+ ( cong-nat-mod-succ-ℕ k x)
+```
+
## Operations
### Addition on the standard finite sets
@@ -211,18 +227,14 @@ ap-add-Fin k p q = ap-binary (add-Fin k) p q
cong-add-Fin :
{k : ℕ} (x y : Fin k) →
- cong-ℕ k (nat-Fin k (add-Fin k x y)) ((nat-Fin k x) +ℕ (nat-Fin k y))
+ nat-Fin k (add-Fin k x y) ≡ (nat-Fin k x) +ℕ (nat-Fin k y) mod-ℕ k
cong-add-Fin {succ-ℕ k} x y =
cong-nat-mod-succ-ℕ k ((nat-Fin (succ-ℕ k) x) +ℕ (nat-Fin (succ-ℕ k) y))
cong-add-ℕ :
{k : ℕ} (x y : ℕ) →
- cong-ℕ
- ( succ-ℕ k)
- ( add-ℕ
- ( nat-Fin (succ-ℕ k) (mod-succ-ℕ k x))
- ( nat-Fin (succ-ℕ k) (mod-succ-ℕ k y)))
- ( x +ℕ y)
+ nat-Fin (k +ℕ 1) (mod-succ-ℕ k x) +ℕ nat-Fin (k +ℕ 1) (mod-succ-ℕ k y) ≡
+ x +ℕ y mod-ℕ k +ℕ 1
cong-add-ℕ {k} x y =
transitive-cong-ℕ
( succ-ℕ k)
@@ -244,38 +256,6 @@ cong-add-ℕ {k} x y =
( nat-Fin (succ-ℕ k) (mod-succ-ℕ k y))
( cong-nat-mod-succ-ℕ k x))
-congruence-add-ℕ :
- (k : ℕ) {x y x' y' : ℕ} →
- cong-ℕ k x x' → cong-ℕ k y y' → cong-ℕ k (x +ℕ y) (x' +ℕ y')
-congruence-add-ℕ k {x} {y} {x'} {y'} H K =
- transitive-cong-ℕ k (x +ℕ y) (x +ℕ y') (x' +ℕ y')
- ( translation-invariant-cong-ℕ' k x x' y' H)
- ( translation-invariant-cong-ℕ k y y' x K)
-
-cong-right-summand-ℕ :
- (k : ℕ) {x y x' y' : ℕ} →
- cong-ℕ k x x' → cong-ℕ k (x +ℕ y) (x' +ℕ y') → cong-ℕ k y y'
-cong-right-summand-ℕ k {x} {y} {x'} {y'} H K =
- reflects-cong-add-ℕ x {y}
- ( transitive-cong-ℕ k
- ( x +ℕ y)
- ( x' +ℕ y')
- ( x +ℕ y')
- ( translation-invariant-cong-ℕ' k x' x y'
- ( symmetric-cong-ℕ k x x' H))
- ( K))
-
-cong-left-summand-ℕ :
- (k : ℕ) {x y x' y' : ℕ} →
- cong-ℕ k y y' → cong-ℕ k (x +ℕ y) (x' +ℕ y') → cong-ℕ k x x'
-cong-left-summand-ℕ k {x} {y} {x'} {y'} H K =
- cong-right-summand-ℕ k {y} {x} {y'} {x'} H
- ( concatenate-eq-cong-ℕ k
- ( commutative-add-ℕ y x)
- ( concatenate-cong-eq-ℕ k {x1 = x +ℕ y}
- ( K)
- ( commutative-add-ℕ x' y')))
-
mod-succ-add-ℕ :
(k x y : ℕ) →
mod-succ-ℕ k (x +ℕ y) =
@@ -315,7 +295,7 @@ ap-dist-Fin k p q = ap-binary (dist-Fin k) p q
cong-dist-Fin :
{k : ℕ} (x y : Fin k) →
- cong-ℕ k (nat-Fin k (dist-Fin k x y)) (dist-ℕ (nat-Fin k x) (nat-Fin k y))
+ nat-Fin k (dist-Fin k x y) ≡ dist-ℕ (nat-Fin k x) (nat-Fin k y) mod-ℕ k
cong-dist-Fin {succ-ℕ k} x y =
cong-nat-mod-succ-ℕ k (dist-ℕ (nat-Fin (succ-ℕ k) x) (nat-Fin (succ-ℕ k) y))
```
@@ -330,7 +310,7 @@ neg-Fin (succ-ℕ k) x =
cong-neg-Fin :
{k : ℕ} (x : Fin k) →
- cong-ℕ k (nat-Fin k (neg-Fin k x)) (dist-ℕ (nat-Fin k x) k)
+ nat-Fin k (neg-Fin k x) ≡ dist-ℕ (nat-Fin k x) k mod-ℕ k
cong-neg-Fin {succ-ℕ k} x =
cong-nat-mod-succ-ℕ k (dist-ℕ (nat-Fin (succ-ℕ k) x) (succ-ℕ k))
```
@@ -354,7 +334,7 @@ ap-mul-Fin k p q = ap-binary (mul-Fin k) p q
cong-mul-Fin :
{k : ℕ} (x y : Fin k) →
- cong-ℕ k (nat-Fin k (mul-Fin k x y)) ((nat-Fin k x) *ℕ (nat-Fin k y))
+ nat-Fin k (mul-Fin k x y) ≡ (nat-Fin k x) *ℕ (nat-Fin k y) mod-ℕ k
cong-mul-Fin {succ-ℕ k} x y =
cong-nat-mod-succ-ℕ k ((nat-Fin (succ-ℕ k) x) *ℕ (nat-Fin (succ-ℕ k) y))
```
@@ -1062,26 +1042,3 @@ equiv-neg-Fin :
pr1 (equiv-neg-Fin k) = neg-Fin k
pr2 (equiv-neg-Fin k) = is-equiv-neg-Fin k
```
-
-## Properties
-
-### Divisibility is a decidable relation on `ℕ`
-
-```agda
-is-decidable-div-ℕ : (d x : ℕ) → is-decidable (div-ℕ d x)
-is-decidable-div-ℕ zero-ℕ x =
- is-decidable-iff
- ( div-eq-ℕ zero-ℕ x)
- ( inv ∘ (is-zero-div-zero-ℕ x))
- ( is-decidable-is-zero-ℕ' x)
-is-decidable-div-ℕ (succ-ℕ d) x =
- is-decidable-iff
- ( div-is-zero-mod-succ-ℕ d x)
- ( is-zero-mod-succ-ℕ d x)
- ( is-decidable-is-zero-Fin (mod-succ-ℕ d x))
-
-div-ℕ-Decidable-Prop : (d x : ℕ) → is-nonzero-ℕ d → Decidable-Prop lzero
-pr1 (div-ℕ-Decidable-Prop d x H) = div-ℕ d x
-pr1 (pr2 (div-ℕ-Decidable-Prop d x H)) = is-prop-div-ℕ d x H
-pr2 (pr2 (div-ℕ-Decidable-Prop d x H)) = is-decidable-div-ℕ d x
-```
diff --git a/src/elementary-number-theory/modular-arithmetic.lagda.md b/src/elementary-number-theory/modular-arithmetic.lagda.md
index b75b74c017..402aebf13e 100644
--- a/src/elementary-number-theory/modular-arithmetic.lagda.md
+++ b/src/elementary-number-theory/modular-arithmetic.lagda.md
@@ -20,6 +20,7 @@ open import elementary-number-theory.multiplication-integers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.nonnegative-integers
+open import elementary-number-theory.unit-integers
open import foundation.action-on-identifications-binary-functions
open import foundation.action-on-identifications-functions
@@ -782,20 +783,6 @@ has-no-fixed-points-succ-Fin {succ-ℕ k} x =
has-no-fixed-points-succ-ℤ-Mod (succ-ℕ k) x
```
-### Divisibility is decidable
-
-```agda
-is-decidable-div-ℤ : (d x : ℤ) → is-decidable (div-ℤ d x)
-is-decidable-div-ℤ d x =
- is-decidable-iff
- ( div-div-int-abs-ℤ ∘ div-is-zero-mod-ℤ (abs-ℤ d) x)
- ( is-zero-mod-div-ℤ (abs-ℤ d) x ∘ div-int-abs-div-ℤ)
- ( has-decidable-equality-ℤ-Mod
- ( abs-ℤ d)
- ( mod-ℤ (abs-ℤ d) x)
- ( zero-ℤ-Mod (abs-ℤ d)))
-```
-
### `mod-ℤ` is surjective
```agda
diff --git a/src/elementary-number-theory/multiplication-integer-fractions.lagda.md b/src/elementary-number-theory/multiplication-integer-fractions.lagda.md
index 33ca87b0b6..e280b9c755 100644
--- a/src/elementary-number-theory/multiplication-integer-fractions.lagda.md
+++ b/src/elementary-number-theory/multiplication-integer-fractions.lagda.md
@@ -13,6 +13,7 @@ open import elementary-number-theory.integer-fractions
open import elementary-number-theory.integers
open import elementary-number-theory.multiplication-integers
open import elementary-number-theory.multiplication-positive-and-negative-integers
+open import elementary-number-theory.positive-integers
open import foundation.action-on-identifications-binary-functions
open import foundation.action-on-identifications-functions
@@ -31,16 +32,36 @@ on the [integers](elementary-number-theory.integers.md) to
the basic properties of multiplication on integer fraction only hold up to
fraction similarity.
-## Definition
+## Definitions
+
+### Multiplication of integer fractions
```agda
+numerator-mul-fraction-ℤ :
+ (x y : fraction-ℤ) → ℤ
+numerator-mul-fraction-ℤ x y =
+ numerator-fraction-ℤ x *ℤ numerator-fraction-ℤ y
+
+positive-denominator-mul-fraction-ℤ :
+ (x y : fraction-ℤ) → positive-ℤ
+positive-denominator-mul-fraction-ℤ x y =
+ mul-positive-ℤ
+ ( positive-denominator-fraction-ℤ x)
+ ( positive-denominator-fraction-ℤ y)
+
+denominator-mul-fraction-ℤ :
+ (x y : fraction-ℤ) → ℤ
+denominator-mul-fraction-ℤ x y =
+ int-positive-ℤ (positive-denominator-mul-fraction-ℤ x y)
+
+is-positive-denominator-mul-fraction-ℤ :
+ (x y : fraction-ℤ) → is-positive-ℤ (denominator-mul-fraction-ℤ x y)
+is-positive-denominator-mul-fraction-ℤ x y =
+ is-positive-int-positive-ℤ (positive-denominator-mul-fraction-ℤ x y)
+
mul-fraction-ℤ : fraction-ℤ → fraction-ℤ → fraction-ℤ
-pr1 (mul-fraction-ℤ (m , n , n-pos) (m' , n' , n'-pos)) =
- m *ℤ m'
-pr1 (pr2 (mul-fraction-ℤ (m , n , n-pos) (m' , n' , n'-pos))) =
- n *ℤ n'
-pr2 (pr2 (mul-fraction-ℤ (m , n , n-pos) (m' , n' , n'-pos))) =
- is-positive-mul-ℤ n-pos n'-pos
+pr1 (mul-fraction-ℤ x y) = numerator-mul-fraction-ℤ x y
+pr2 (mul-fraction-ℤ x y) = positive-denominator-mul-fraction-ℤ x y
mul-fraction-ℤ' : fraction-ℤ → fraction-ℤ → fraction-ℤ
mul-fraction-ℤ' x y = mul-fraction-ℤ y x
@@ -98,8 +119,8 @@ right-unit-law-mul-fraction-ℤ (n , d , p) =
associative-mul-fraction-ℤ :
(x y z : fraction-ℤ) →
sim-fraction-ℤ
- (mul-fraction-ℤ (mul-fraction-ℤ x y) z)
- (mul-fraction-ℤ x (mul-fraction-ℤ y z))
+ ( mul-fraction-ℤ (mul-fraction-ℤ x y) z)
+ ( mul-fraction-ℤ x (mul-fraction-ℤ y z))
associative-mul-fraction-ℤ (nx , dx , dxp) (ny , dy , dyp) (nz , dz , dzp) =
ap-mul-ℤ (associative-mul-ℤ nx ny nz) (inv (associative-mul-ℤ dx dy dz))
```
@@ -119,8 +140,8 @@ commutative-mul-fraction-ℤ (nx , dx , dxp) (ny , dy , dyp) =
left-distributive-mul-add-fraction-ℤ :
(x y z : fraction-ℤ) →
sim-fraction-ℤ
- (mul-fraction-ℤ x (add-fraction-ℤ y z))
- (add-fraction-ℤ (mul-fraction-ℤ x y) (mul-fraction-ℤ x z))
+ ( mul-fraction-ℤ x (add-fraction-ℤ y z))
+ ( add-fraction-ℤ (mul-fraction-ℤ x y) (mul-fraction-ℤ x z))
left-distributive-mul-add-fraction-ℤ
(nx , dx , dxp) (ny , dy , dyp) (nz , dz , dzp) =
( ap
diff --git a/src/elementary-number-theory/multiplication-integers.lagda.md b/src/elementary-number-theory/multiplication-integers.lagda.md
index d8c89edf3b..5223aecf0e 100644
--- a/src/elementary-number-theory/multiplication-integers.lagda.md
+++ b/src/elementary-number-theory/multiplication-integers.lagda.md
@@ -161,10 +161,9 @@ left-successor-law-mul-ℤ (inr (inl star)) l =
left-successor-law-mul-ℤ (inr (inr n)) l = refl
left-successor-law-mul-ℤ' :
- (k l : ℤ) → (succ-ℤ k) *ℤ l = (k *ℤ l) +ℤ l
+ (k l : ℤ) → succ-ℤ k *ℤ l = k *ℤ l +ℤ l
left-successor-law-mul-ℤ' k l =
- left-successor-law-mul-ℤ k l ∙
- commutative-add-ℤ l (k *ℤ l)
+ left-successor-law-mul-ℤ k l ∙ commutative-add-ℤ l (k *ℤ l)
left-predecessor-law-mul-ℤ :
(k l : ℤ) → (pred-ℤ k) *ℤ l = (neg-ℤ l) +ℤ (k *ℤ l)
@@ -181,10 +180,9 @@ left-predecessor-law-mul-ℤ (inr (inr (succ-ℕ x))) l =
( associative-add-ℤ (neg-ℤ l) l ((in-pos-ℤ x) *ℤ l))
left-predecessor-law-mul-ℤ' :
- (k l : ℤ) → (pred-ℤ k) *ℤ l = (k *ℤ l) +ℤ (neg-ℤ l)
+ (k l : ℤ) → pred-ℤ k *ℤ l = k *ℤ l -ℤ l
left-predecessor-law-mul-ℤ' k l =
- left-predecessor-law-mul-ℤ k l ∙
- commutative-add-ℤ (neg-ℤ l) (k *ℤ l)
+ left-predecessor-law-mul-ℤ k l ∙ commutative-add-ℤ (neg-ℤ l) (k *ℤ l)
right-successor-law-mul-ℤ :
(k l : ℤ) → k *ℤ (succ-ℤ l) = k +ℤ (k *ℤ l)
@@ -225,10 +223,9 @@ right-successor-law-mul-ℤ (inr (inr (succ-ℕ n))) l =
( associative-add-ℤ (inr (inr (succ-ℕ n))) l ((inr (inr n)) *ℤ l)))))
right-successor-law-mul-ℤ' :
- (k l : ℤ) → k *ℤ (succ-ℤ l) = (k *ℤ l) +ℤ k
+ (k l : ℤ) → k *ℤ succ-ℤ l = k *ℤ l +ℤ k
right-successor-law-mul-ℤ' k l =
- right-successor-law-mul-ℤ k l ∙
- commutative-add-ℤ k (k *ℤ l)
+ right-successor-law-mul-ℤ k l ∙ commutative-add-ℤ k (k *ℤ l)
right-predecessor-law-mul-ℤ :
(k l : ℤ) → k *ℤ (pred-ℤ l) = (neg-ℤ k) +ℤ (k *ℤ l)
@@ -265,10 +262,28 @@ right-predecessor-law-mul-ℤ (inr (inr (succ-ℕ n))) l =
( associative-add-ℤ (inl (succ-ℕ n)) l ((inr (inr n)) *ℤ l)))))
right-predecessor-law-mul-ℤ' :
- (k l : ℤ) → k *ℤ (pred-ℤ l) = (k *ℤ l) +ℤ (neg-ℤ k)
+ (k l : ℤ) → k *ℤ pred-ℤ l = k *ℤ l -ℤ k
right-predecessor-law-mul-ℤ' k l =
- right-predecessor-law-mul-ℤ k l ∙
- commutative-add-ℤ (neg-ℤ k) (k *ℤ l)
+ right-predecessor-law-mul-ℤ k l ∙ commutative-add-ℤ (neg-ℤ k) (k *ℤ l)
+
+double-successor-law-mul-ℤ :
+ (k l : ℤ) → succ-ℤ k *ℤ succ-ℤ l = k *ℤ l +ℤ k +ℤ l +ℤ int-ℕ 1
+double-successor-law-mul-ℤ k l =
+ left-successor-law-mul-ℤ' k (succ-ℤ l) ∙
+ ap-add-ℤ
+ ( right-successor-law-mul-ℤ' k l)
+ ( inv (right-add-one-ℤ l)) ∙
+ inv (associative-add-ℤ (k *ℤ l +ℤ k) l (int-ℕ 1))
+
+double-predecessor-law-mul-ℤ :
+ (k l : ℤ) → pred-ℤ k *ℤ pred-ℤ l = ((k *ℤ l -ℤ k) -ℤ l) +ℤ int-ℕ 1
+double-predecessor-law-mul-ℤ k l =
+ left-predecessor-law-mul-ℤ' k (pred-ℤ l) ∙
+ ap-add-ℤ
+ ( right-predecessor-law-mul-ℤ' k l)
+ ( ap neg-ℤ (inv (right-add-neg-one-ℤ l)) ∙
+ distributive-neg-add-ℤ l neg-one-ℤ) ∙
+ inv (associative-add-ℤ (k *ℤ l -ℤ k) (neg-ℤ l) (int-ℕ 1))
```
### Multiplication on the integers distributes on the right over addition
@@ -364,6 +379,25 @@ left-distributive-mul-add-ℤ m k l =
( ap-add-ℤ (commutative-mul-ℤ k m) (commutative-mul-ℤ l m)))
```
+### Distributivity of multiplication over addition on both sides
+
+For any four integers `a`, `b`, `c`, and `d` we have
+
+```text
+ (a + b)(c + d) = (ac + ad) + (bc + bd).
+```
+
+```agda
+double-distributive-mul-add-ℤ :
+ (a b c d : ℤ) →
+ (a +ℤ b) *ℤ (c +ℤ d) = (a *ℤ c +ℤ a *ℤ d) +ℤ (b *ℤ c +ℤ b *ℤ d)
+double-distributive-mul-add-ℤ a b c d =
+ right-distributive-mul-add-ℤ a b (c +ℤ d) ∙
+ ap-add-ℤ
+ ( left-distributive-mul-add-ℤ a c d)
+ ( left-distributive-mul-add-ℤ b c d)
+```
+
### Right multiplication by the negative of an integer is the negative of the multiplication
```agda
@@ -402,6 +436,24 @@ interchange-law-mul-mul-ℤ =
associative-mul-ℤ
```
+### Swapping the order of multiplication from one side
+
+```agda
+right-swap-mul-ℤ :
+ (x y z : ℤ) → (x *ℤ y) *ℤ z = (x *ℤ z) *ℤ y
+right-swap-mul-ℤ x y z =
+ associative-mul-ℤ x y z ∙
+ ap (x *ℤ_) (commutative-mul-ℤ y z) ∙
+ inv (associative-mul-ℤ x z y)
+
+left-swap-mul-ℤ :
+ (x y z : ℤ) → x *ℤ (y *ℤ z) = y *ℤ (x *ℤ z)
+left-swap-mul-ℤ x y z =
+ inv (associative-mul-ℤ x y z) ∙
+ ap (_*ℤ z) (commutative-mul-ℤ x y) ∙
+ associative-mul-ℤ y x z
+```
+
### Computing multiplication of integers that come from natural numbers
```agda
diff --git a/src/elementary-number-theory/multiplication-lists-of-natural-numbers.lagda.md b/src/elementary-number-theory/multiplication-lists-of-natural-numbers.lagda.md
deleted file mode 100644
index 85b452a28c..0000000000
--- a/src/elementary-number-theory/multiplication-lists-of-natural-numbers.lagda.md
+++ /dev/null
@@ -1,67 +0,0 @@
-# Multiplication of the elements of a list of natural numbers
-
-```agda
-module elementary-number-theory.multiplication-lists-of-natural-numbers where
-```
-
-Imports
-
-```agda
-open import elementary-number-theory.addition-natural-numbers
-open import elementary-number-theory.multiplication-natural-numbers
-open import elementary-number-theory.natural-numbers
-
-open import finite-group-theory.permutations-standard-finite-types
-
-open import foundation.action-on-identifications-functions
-open import foundation.identity-types
-
-open import lists.concatenation-lists
-open import lists.lists
-open import lists.permutation-lists
-```
-
-
-
-## Idea
-
-Given a list of natural number `l`, we define the product of the element of the
-list.
-
-## Definition
-
-```agda
-mul-list-ℕ :
- list ℕ → ℕ
-mul-list-ℕ = fold-list 1 mul-ℕ
-```
-
-## Properties
-
-### `mul-list-ℕ` is invariant by permutation
-
-```agda
-invariant-permutation-mul-list-ℕ :
- (l : list ℕ) (t : Permutation (length-list l)) →
- mul-list-ℕ l = mul-list-ℕ (permute-list l t)
-invariant-permutation-mul-list-ℕ =
- invariant-permutation-fold-list
- ( 1)
- ( mul-ℕ)
- ( λ a1 a2 b →
- ( inv (associative-mul-ℕ a1 a2 b) ∙
- ( ap (λ n → n *ℕ b) (commutative-mul-ℕ a1 a2) ∙
- ( associative-mul-ℕ a2 a1 b))))
-```
-
-### `mul-list-ℕ` of a concatenation of lists
-
-```agda
-eq-mul-list-concat-list-ℕ :
- (p q : list ℕ) →
- (mul-list-ℕ (concat-list p q)) = (mul-list-ℕ p) *ℕ (mul-list-ℕ q)
-eq-mul-list-concat-list-ℕ nil q = inv (left-unit-law-add-ℕ (mul-list-ℕ q))
-eq-mul-list-concat-list-ℕ (cons x p) q =
- ap (mul-ℕ x) (eq-mul-list-concat-list-ℕ p q) ∙
- inv (associative-mul-ℕ x (mul-list-ℕ p) (mul-list-ℕ q))
-```
diff --git a/src/elementary-number-theory/multiplication-natural-numbers.lagda.md b/src/elementary-number-theory/multiplication-natural-numbers.lagda.md
index c4d6dd3e5f..eae4eecaff 100644
--- a/src/elementary-number-theory/multiplication-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/multiplication-natural-numbers.lagda.md
@@ -68,18 +68,38 @@ triple-ℕ x = 3 *ℕ x
## Properties
+### The zero laws for multiplication
+
+For any natural number `x` we have `0x = x0 = 0`.
+
```agda
abstract
left-zero-law-mul-ℕ :
(x : ℕ) → zero-ℕ *ℕ x = zero-ℕ
left-zero-law-mul-ℕ x = refl
+ left-zero-law-mul-is-zero-ℕ :
+ (x y : ℕ) → is-zero-ℕ x → is-zero-ℕ (x *ℕ y)
+ left-zero-law-mul-is-zero-ℕ .zero-ℕ y refl =
+ left-zero-law-mul-ℕ y
+
right-zero-law-mul-ℕ :
(x : ℕ) → x *ℕ zero-ℕ = zero-ℕ
right-zero-law-mul-ℕ zero-ℕ = refl
right-zero-law-mul-ℕ (succ-ℕ x) =
( right-unit-law-add-ℕ (x *ℕ zero-ℕ)) ∙ (right-zero-law-mul-ℕ x)
+ right-zero-law-mul-is-zero-ℕ :
+ (x y : ℕ) → is-zero-ℕ y → is-zero-ℕ (x *ℕ y)
+ right-zero-law-mul-is-zero-ℕ x .zero-ℕ refl =
+ right-zero-law-mul-ℕ x
+```
+
+### The unit laws for multiplication
+
+For any natural number `x` we have `1x = x1 = x`.
+
+```agda
abstract
right-unit-law-mul-ℕ :
(x : ℕ) → x *ℕ 1 = x
@@ -90,29 +110,57 @@ abstract
(x : ℕ) → 1 *ℕ x = x
left-unit-law-mul-ℕ zero-ℕ = refl
left-unit-law-mul-ℕ (succ-ℕ x) = ap succ-ℕ (left-unit-law-mul-ℕ x)
+```
+### The successor laws for multiplication
+
+For any two natural numbers `x` and `y` we have:
+
+```text
+ (x + 1)y = xy + y -- The left successor law
+ x(y + 1) = xy + x -- The right successor law
+ (x + 1)(y + 1) = xy + x + y + 1 -- The double successor law
+```
+
+```agda
abstract
left-successor-law-mul-ℕ :
- (x y : ℕ) → (succ-ℕ x) *ℕ y = (x *ℕ y) +ℕ y
+ (x y : ℕ) → succ-ℕ x *ℕ y = x *ℕ y +ℕ y
left-successor-law-mul-ℕ x y = refl
right-successor-law-mul-ℕ :
- (x y : ℕ) → x *ℕ (succ-ℕ y) = x +ℕ (x *ℕ y)
+ (x y : ℕ) → x *ℕ succ-ℕ y = x *ℕ y +ℕ x
right-successor-law-mul-ℕ zero-ℕ y = refl
right-successor-law-mul-ℕ (succ-ℕ x) y =
- ( ( ap (λ t → succ-ℕ (t +ℕ y)) (right-successor-law-mul-ℕ x y)) ∙
- ( ap succ-ℕ (associative-add-ℕ x (x *ℕ y) y))) ∙
- ( inv (left-successor-law-add-ℕ x ((x *ℕ y) +ℕ y)))
+ ap
+ ( succ-ℕ)
+ ( ap (add-ℕ' y) (right-successor-law-mul-ℕ x y) ∙
+ right-swap-add-ℕ (mul-ℕ x y) x y)
+
+ double-successor-law-mul-ℕ :
+ (x y : ℕ) → succ-ℕ x *ℕ succ-ℕ y = x *ℕ y +ℕ x +ℕ y +ℕ 1
+ double-successor-law-mul-ℕ x y =
+ left-successor-law-mul-ℕ x (succ-ℕ y) ∙
+ ap
+ ( add-ℕ' (succ-ℕ y))
+ ( right-successor-law-mul-ℕ x y)
+```
+
+### Multiplication is commutative
+```agda
abstract
commutative-mul-ℕ :
(x y : ℕ) → x *ℕ y = y *ℕ x
commutative-mul-ℕ zero-ℕ y = inv (right-zero-law-mul-ℕ y)
commutative-mul-ℕ (succ-ℕ x) y =
- ( commutative-add-ℕ (x *ℕ y) y) ∙
- ( ( ap (y +ℕ_) (commutative-mul-ℕ x y)) ∙
- ( inv (right-successor-law-mul-ℕ y x)))
+ ap (add-ℕ' y) (commutative-mul-ℕ x y) ∙
+ inv (right-successor-law-mul-ℕ y x)
+```
+
+### The distributive laws of multiplication over addition
+```agda
abstract
left-distributive-mul-add-ℕ :
(x y z : ℕ) → x *ℕ (y +ℕ z) = (x *ℕ y) +ℕ (x *ℕ z)
@@ -137,14 +185,32 @@ abstract
( ( ap (_+ℕ (z *ℕ y)) (commutative-mul-ℕ z x)) ∙
( ap ((x *ℕ z) +ℕ_) (commutative-mul-ℕ z y))))
+abstract
+ double-distributive-mul-add-ℕ :
+ (w x y z : ℕ) → (w +ℕ x) *ℕ (y +ℕ z) = w *ℕ y +ℕ w *ℕ z +ℕ x *ℕ y +ℕ x *ℕ z
+ double-distributive-mul-add-ℕ w x y z =
+ ( right-distributive-mul-add-ℕ w x (y +ℕ z)) ∙
+ ( ap-add-ℕ
+ ( left-distributive-mul-add-ℕ w y z)
+ ( left-distributive-mul-add-ℕ x y z)) ∙
+ ( inv (associative-add-ℕ (w *ℕ y +ℕ w *ℕ z) (x *ℕ y) (x *ℕ z)))
+```
+
+### Multiplication is associative
+
+```agda
abstract
associative-mul-ℕ :
(x y z : ℕ) → (x *ℕ y) *ℕ z = x *ℕ (y *ℕ z)
associative-mul-ℕ zero-ℕ y z = refl
associative-mul-ℕ (succ-ℕ x) y z =
( right-distributive-mul-add-ℕ (x *ℕ y) y z) ∙
- ( ap (_+ℕ (y *ℕ z)) (associative-mul-ℕ x y z))
+ ( ap (_+ℕ y *ℕ z) (associative-mul-ℕ x y z))
+```
+
+### For any natural number we have `2x = x2 = x + x`
+```agda
left-two-law-mul-ℕ :
(x : ℕ) → 2 *ℕ x = x +ℕ x
left-two-law-mul-ℕ x =
@@ -154,16 +220,48 @@ left-two-law-mul-ℕ x =
right-two-law-mul-ℕ :
(x : ℕ) → x *ℕ 2 = x +ℕ x
right-two-law-mul-ℕ x =
- ( right-successor-law-mul-ℕ x 1) ∙
- ( ap (x +ℕ_) (right-unit-law-mul-ℕ x))
+ right-successor-law-mul-ℕ x 1 ∙
+ ap (_+ℕ x) (right-unit-law-mul-ℕ x)
+```
+
+### The interchange laws for multipliplication interchanging over itself
+
+For any four natural numbers `x`, `y`, `u`, and `v` we have
+
+```text
+ (xy)(uv) = (xu)(yv)
+```
+```agda
interchange-law-mul-mul-ℕ : interchange-law mul-ℕ mul-ℕ
interchange-law-mul-mul-ℕ =
interchange-law-commutative-and-associative
mul-ℕ
commutative-mul-ℕ
associative-mul-ℕ
+```
+
+### Swapping the order of multiplication
+
+```agda
+left-swap-mul-ℕ :
+ (m n x : ℕ) → m *ℕ (n *ℕ x) = n *ℕ (m *ℕ x)
+left-swap-mul-ℕ m n x =
+ ( inv (associative-mul-ℕ m n x)) ∙
+ ( ap (_*ℕ x) (commutative-mul-ℕ m n)) ∙
+ ( associative-mul-ℕ n m x)
+
+right-swap-mul-ℕ :
+ (x m n : ℕ) → (x *ℕ m) *ℕ n = (x *ℕ n) *ℕ m
+right-swap-mul-ℕ x m n =
+ ( associative-mul-ℕ x m n) ∙
+ ( ap (x *ℕ_) (commutative-mul-ℕ m n)) ∙
+ ( inv (associative-mul-ℕ x n m))
+```
+### Multiplication by a nonzero natural number is injective
+
+```agda
is-injective-right-mul-succ-ℕ :
(k : ℕ) → is-injective (_*ℕ (succ-ℕ k))
is-injective-right-mul-succ-ℕ k {zero-ℕ} {zero-ℕ} p = refl
@@ -201,7 +299,11 @@ is-emb-left-mul-ℕ x H =
is-emb-right-mul-ℕ : (x : ℕ) → is-nonzero-ℕ x → is-emb (_*ℕ x)
is-emb-right-mul-ℕ x H =
is-emb-is-injective is-set-ℕ (is-injective-right-mul-ℕ x H)
+```
+### A product of natural numbers is nonzero if and only if both its factors are nonzero
+
+```agda
is-nonzero-mul-ℕ :
(x y : ℕ) → is-nonzero-ℕ x → is-nonzero-ℕ y → is-nonzero-ℕ (x *ℕ y)
is-nonzero-mul-ℕ x y H K p =
@@ -216,7 +318,7 @@ is-nonzero-right-factor-mul-ℕ :
is-nonzero-right-factor-mul-ℕ x .zero-ℕ H refl = H (right-zero-law-mul-ℕ x)
```
-We conclude that $y = 1$ if $(x+1)y = x+1$.
+### If $(x+1)y = x+1$ then it follows that $y = 1$
```agda
is-one-is-right-unit-mul-ℕ :
@@ -258,6 +360,7 @@ neq-mul-ℕ m n p =
( ( m *ℕ (succ-ℕ n)) +ℕ n)
( ( p) ∙
( ( right-successor-law-mul-ℕ (succ-ℕ m) (succ-ℕ n)) ∙
+ ( commutative-add-ℕ _ (succ-ℕ m)) ∙
( ap ((succ-ℕ m) +ℕ_) (left-successor-law-mul-ℕ m (succ-ℕ n)))))
```
@@ -289,3 +392,5 @@ is-zero-mul-ℕ-is-zero-summand x y (inr H) =
- [Squares of natural numbers](elementary-number-theory.squares-natural-numbers.md)
- [Cubes of natural numbers](elementary-number-theory.cubes-natural-numbers.md)
+- [Pronic numbers](elementary-number-theory.pronic-numbers.md), i.e., numbers of
+ the form $n(n+1)$.
diff --git a/src/elementary-number-theory/multiplicative-decompositions-natural-numbers.lagda.md b/src/elementary-number-theory/multiplicative-decompositions-natural-numbers.lagda.md
new file mode 100644
index 0000000000..c42eb9f057
--- /dev/null
+++ b/src/elementary-number-theory/multiplicative-decompositions-natural-numbers.lagda.md
@@ -0,0 +1,190 @@
+# Multiplicative decompositions of natural numbers
+
+```agda
+module
+ elementary-number-theory.multiplicative-decompositions-natural-numbers
+ where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.products-lists-of-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.nontrivial-divisors-natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.identity-types
+open import foundation.propositions
+open import foundation.unit-type
+open import foundation.universe-levels
+
+open import lists.concatenation-lists
+open import lists.lists
+open import lists.universal-quantification-lists
+```
+
+
+
+## Idea
+
+A
+{{#concept "multiplicative decomposition" Disambiguation="natural numbers" Agda=is-multiplicative-decomposition-ℕ}}
+of a [natural number](elementary-number-theory.natural-numbers.md) `n` is a
+[list](lists.lists.md) `l` of natural numbers
+[strictly greater than](elementary-number-theory.strict-inequality-natural-numbers.md)
+`1`, such that the
+[product](elementary-number-theory.products-lists-of-natural-numbers.md) of the
+numbers in this list is [equal to](foundation-core.identity-types.md) `n`.
+
+## Definitions
+
+### The predicate on lists of natural numbers of being a product decomposition of a given number
+
+```agda
+module _
+ (n : ℕ)
+ (l : list ℕ)
+ where
+
+ is-multiplicative-decomposition-list-ℕ :
+ UU lzero
+ is-multiplicative-decomposition-list-ℕ =
+ ( for-all-list l (le-ℕ 1)) × (mul-list-ℕ l = n)
+
+ is-prop-is-multiplicative-decomposition-list-ℕ :
+ is-prop (is-multiplicative-decomposition-list-ℕ)
+ is-prop-is-multiplicative-decomposition-list-ℕ =
+ is-prop-product
+ ( is-prop-for-all-list l (le-ℕ-Prop 1))
+ ( is-set-ℕ (mul-list-ℕ l) n)
+
+ le-one-list-is-multiplicative-decomposition-list-ℕ :
+ is-multiplicative-decomposition-list-ℕ →
+ for-all-list l (le-ℕ 1)
+ le-one-list-is-multiplicative-decomposition-list-ℕ = pr1
+
+ eq-is-multiplicative-decomposition-list-ℕ :
+ is-multiplicative-decomposition-list-ℕ →
+ mul-list-ℕ l = n
+ eq-is-multiplicative-decomposition-list-ℕ = pr2
+```
+
+## Properties
+
+### Any list of numbers strictly greater than 1 is a multiplicative decomposition of its product
+
+```agda
+is-multiplicative-decomposition-mul-list-ℕ :
+ (l : list ℕ) →
+ for-all-list l (le-ℕ 1) →
+ is-multiplicative-decomposition-list-ℕ (mul-list-ℕ l) l
+pr1 (is-multiplicative-decomposition-mul-list-ℕ l H) = H
+pr2 (is-multiplicative-decomposition-mul-list-ℕ l H) = refl
+```
+
+### The head and tail of a multiplicative decomposition of a number are strictly greater than 1
+
+```agda
+module _
+ (n x : ℕ) (l : list ℕ)
+ where
+
+ le-one-head-is-multiplicative-decomposition-cons-list-ℕ :
+ is-multiplicative-decomposition-list-ℕ n (cons x l) →
+ 1 <-ℕ x
+ le-one-head-is-multiplicative-decomposition-cons-list-ℕ H =
+ pr1 (le-one-list-is-multiplicative-decomposition-list-ℕ n (cons x l) H)
+
+ le-one-tail-list-is-multiplicative-decomposition-cons-list-ℕ :
+ is-multiplicative-decomposition-list-ℕ n (cons x l) →
+ for-all-list l (le-ℕ 1)
+ le-one-tail-list-is-multiplicative-decomposition-cons-list-ℕ H =
+ pr2 (le-one-list-is-multiplicative-decomposition-list-ℕ n (cons x l) H)
+```
+
+### If `l` is a multiplicative decomposition of a number `n`, then `l` is a list of nontrivial divisors of `l`
+
+```agda
+div-head-is-multiplicative-decomposition-cons-list-ℕ :
+ (n x : ℕ) (l : list ℕ) →
+ is-multiplicative-decomposition-list-ℕ n (cons x l) →
+ div-ℕ x n
+pr1 (div-head-is-multiplicative-decomposition-cons-list-ℕ n x l H) =
+ mul-list-ℕ l
+pr2 (div-head-is-multiplicative-decomposition-cons-list-ℕ n x l H) =
+ commutative-mul-ℕ (mul-list-ℕ l) x ∙
+ eq-is-multiplicative-decomposition-list-ℕ n (cons x l) H
+
+div-tail-is-multiplicative-decomposition-cons-list-ℕ :
+ (n x : ℕ) (l : list ℕ) →
+ is-multiplicative-decomposition-list-ℕ n (cons x l) →
+ div-ℕ (mul-list-ℕ l) n
+pr1 (div-tail-is-multiplicative-decomposition-cons-list-ℕ n x l H) =
+ x
+pr2 (div-tail-is-multiplicative-decomposition-cons-list-ℕ n x l H) =
+ eq-is-multiplicative-decomposition-list-ℕ n (cons x l) H
+
+is-nontrivial-divisor-head-is-multiplicative-decomposition-cons-list-ℕ :
+ (n x : ℕ) (l : list ℕ) →
+ is-multiplicative-decomposition-list-ℕ n (cons x l) →
+ is-nontrivial-divisor-ℕ n x
+pr1
+ ( is-nontrivial-divisor-head-is-multiplicative-decomposition-cons-list-ℕ
+ n x l H) =
+ le-one-head-is-multiplicative-decomposition-cons-list-ℕ n x l H
+pr2
+ ( is-nontrivial-divisor-head-is-multiplicative-decomposition-cons-list-ℕ
+ n x l H) =
+ div-head-is-multiplicative-decomposition-cons-list-ℕ n x l H
+
+is-list-of-nontrivial-divisors-is-multiplicative-decomposition-list-ℕ :
+ (n : ℕ) (l : list ℕ) →
+ is-multiplicative-decomposition-list-ℕ n l →
+ is-list-of-nontrivial-divisors-ℕ n l
+is-list-of-nontrivial-divisors-is-multiplicative-decomposition-list-ℕ n nil H =
+ raise-star
+is-list-of-nontrivial-divisors-is-multiplicative-decomposition-list-ℕ
+ ( n)
+ ( cons x l)
+ ( H) =
+ ( is-nontrivial-divisor-head-is-multiplicative-decomposition-cons-list-ℕ
+ n x l H ,
+ is-list-of-nontrivial-divisors-div-ℕ
+ ( mul-list-ℕ l)
+ ( n)
+ ( div-tail-is-multiplicative-decomposition-cons-list-ℕ n x l H)
+ ( l)
+ ( is-list-of-nontrivial-divisors-is-multiplicative-decomposition-list-ℕ
+ ( mul-list-ℕ l)
+ ( l)
+ ( is-multiplicative-decomposition-mul-list-ℕ l
+ ( le-one-tail-list-is-multiplicative-decomposition-cons-list-ℕ n x l
+ ( H)))))
+```
+
+### The concatenation of two multiplicative decompositions is a multiplicative decomposition
+
+```agda
+is-multiplicative-decomposition-concat-list-ℕ :
+ (n m : ℕ) (p q : list ℕ) →
+ is-multiplicative-decomposition-list-ℕ n p →
+ is-multiplicative-decomposition-list-ℕ m q →
+ is-multiplicative-decomposition-list-ℕ (n *ℕ m) (concat-list p q)
+pr1 (is-multiplicative-decomposition-concat-list-ℕ n m l k H K) =
+ for-all-concat-list l k
+ ( le-ℕ 1)
+ ( le-one-list-is-multiplicative-decomposition-list-ℕ n l H)
+ ( le-one-list-is-multiplicative-decomposition-list-ℕ m k K)
+pr2 (is-multiplicative-decomposition-concat-list-ℕ n m l k H K) =
+ compute-mul-concat-list-ℕ l k ∙
+ ap-mul-ℕ
+ ( eq-is-multiplicative-decomposition-list-ℕ n l H)
+ ( eq-is-multiplicative-decomposition-list-ℕ m k K)
+```
diff --git a/src/elementary-number-theory/natural-numbers.lagda.md b/src/elementary-number-theory/natural-numbers.lagda.md
index d31e35ab6d..1e885e5b13 100644
--- a/src/elementary-number-theory/natural-numbers.lagda.md
+++ b/src/elementary-number-theory/natural-numbers.lagda.md
@@ -11,6 +11,7 @@ open import foundation.dependent-pair-types
open import foundation.universe-levels
open import foundation-core.empty-types
+open import foundation-core.fibers-of-maps
open import foundation-core.function-types
open import foundation-core.identity-types
open import foundation-core.injective-maps
@@ -22,9 +23,16 @@ open import foundation-core.negation
## Idea
The {{#concept "natural numbers" WD="natural number" WDID=Q21199 Agda=ℕ}} is an
-inductively generated type by the zero element and the successor function. The
-induction principle for the natural numbers works to construct sections of type
-families over the natural numbers.
+inductive type generated by the
+{{#concept "zero" Disambiguation="natural number" Agda=zero-ℕ WDID=Q204 WD="zero"}}
+element and the
+{{#concept "successor function" Disambiguation="natural numbers" Agda=succ-ℕ WDID=Q7632653 WD="successor function"}}.
+The
+{{#concept "induction principle" Disambiguation="natural numbers" Agda=ind-ℕ WDID=Q178377 WD="mathematical induction"}}
+for the natural numbers works to construct sections of type families over the
+natural numbers. Another name for the induction principle for the natural
+numbers is
+{{#concept "mathematical induction" Agda=ind-ℕ WDID=Q178377 WD="mathematical induction"}}.
## Definitions
@@ -47,7 +55,7 @@ fourth-succ-ℕ : ℕ → ℕ
fourth-succ-ℕ = succ-ℕ ∘ third-succ-ℕ
```
-### Useful predicates on the natural numbers
+### The predicate of being zero
These predicates can of course be asserted directly without much trouble.
However, using the defined predicates ensures uniformity, and helps naming
@@ -59,19 +67,47 @@ is-zero-ℕ n = (n = zero-ℕ)
is-zero-ℕ' : ℕ → UU lzero
is-zero-ℕ' n = (zero-ℕ = n)
+```
+
+### The predicate of being a successor
+```agda
is-successor-ℕ : ℕ → UU lzero
is-successor-ℕ n = Σ ℕ (λ y → n = succ-ℕ y)
+fiber-succ-is-successor-ℕ :
+ {n : ℕ} → is-successor-ℕ n → fiber succ-ℕ n
+fiber-succ-is-successor-ℕ (x , p) = (x , inv p)
+
+pred-is-successor-ℕ :
+ (n : ℕ) → is-successor-ℕ n → ℕ
+pred-is-successor-ℕ n H = pr1 H
+
+eq-pred-is-successor-ℕ :
+ (n : ℕ) (H : is-successor-ℕ n) → succ-ℕ (pred-is-successor-ℕ n H) = n
+eq-pred-is-successor-ℕ n H = inv (pr2 H)
+```
+
+### The predicate of being nonzero
+
+```agda
is-nonzero-ℕ : ℕ → UU lzero
is-nonzero-ℕ n = ¬ (is-zero-ℕ n)
+```
+
+### The predicate of being `1`
+```agda
is-one-ℕ : ℕ → UU lzero
is-one-ℕ n = (n = 1)
is-one-ℕ' : ℕ → UU lzero
is-one-ℕ' n = (1 = n)
+```
+
+### The predicate of not being `1`
+```agda
is-not-one-ℕ : ℕ → UU lzero
is-not-one-ℕ n = ¬ (is-one-ℕ n)
@@ -110,7 +146,7 @@ is-injective-succ-ℕ : is-injective succ-ℕ
is-injective-succ-ℕ refl = refl
```
-### Successors are nonzero
+### A natural number is nonzero if and only if it is a successor
```agda
is-nonzero-succ-ℕ : (x : ℕ) → is-nonzero-ℕ (succ-ℕ x)
@@ -124,11 +160,25 @@ is-successor-is-nonzero-ℕ {zero-ℕ} H = ex-falso (H refl)
pr1 (is-successor-is-nonzero-ℕ {succ-ℕ x} H) = x
pr2 (is-successor-is-nonzero-ℕ {succ-ℕ x} H) = refl
+pred-is-nonzero-ℕ :
+ (n : ℕ) → is-nonzero-ℕ n → ℕ
+pred-is-nonzero-ℕ n H =
+ pred-is-successor-ℕ n (is-successor-is-nonzero-ℕ H)
+
+eq-pred-is-nonzero-ℕ :
+ (n : ℕ) (H : is-nonzero-ℕ n) → succ-ℕ (pred-is-nonzero-ℕ n H) = n
+eq-pred-is-nonzero-ℕ n H =
+ eq-pred-is-successor-ℕ n (is-successor-is-nonzero-ℕ H)
+```
+
+### The successor function has no fixed points
+
+```agda
has-no-fixed-points-succ-ℕ : (x : ℕ) → ¬ (succ-ℕ x = x)
has-no-fixed-points-succ-ℕ x ()
```
-### Basic nonequalities
+### The first few nonzero numbers
```agda
is-nonzero-one-ℕ : is-nonzero-ℕ 1
@@ -142,16 +192,20 @@ is-nonzero-two-ℕ ()
is-not-one-two-ℕ : is-not-one-ℕ 2
is-not-one-two-ℕ ()
+
+is-nonzero-three-ℕ : is-nonzero-ℕ 3
+is-nonzero-three-ℕ ()
+
+is-nonzero-four-ℕ : is-nonzero-ℕ 4
+is-nonzero-four-ℕ ()
```
## See also
-- The based induction principle is defined in
- [`based-induction-natural-numbers`](elementary-number-theory.based-induction-natural-numbers.md).
-- The strong induction principle is defined in
- [`strong-induction-natural-numbers`](elementary-number-theory.strong-induction-natural-numbers.md).
-- The based strong induction principle is defined in
- [`based-strong-induction-natural-numbers`](elementary-number-theory.based-strong-induction-natural-numbers.md).
+- [The based induction principle](elementary-number-theory.based-induction-natural-numbers.md).
+- [The strong induction principle](elementary-number-theory.strong-induction-natural-numbers.md).
+- [The based strong induction principle](elementary-number-theory.based-strong-induction-natural-numbers.md).
+- [The conatural numbers](elementary-number-theory.conatural-numbers.md)
## References
diff --git a/src/elementary-number-theory/nicomachuss-theorem.lagda.md b/src/elementary-number-theory/nicomachuss-theorem.lagda.md
new file mode 100644
index 0000000000..adc06e5d4b
--- /dev/null
+++ b/src/elementary-number-theory/nicomachuss-theorem.lagda.md
@@ -0,0 +1,129 @@
+# Nicomachus's Theorem
+
+```agda
+module elementary-number-theory.nicomachuss-theorem where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.cubes-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
+open import elementary-number-theory.pronic-numbers
+open import elementary-number-theory.squares-natural-numbers
+open import elementary-number-theory.sums-of-natural-numbers
+open import elementary-number-theory.triangular-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.identity-types
+open import foundation.transport-along-identifications
+
+open import univalent-combinatorics.standard-finite-types
+```
+
+
+
+## Idea
+
+{{#concept "Nicomachus's Theorem" Agda=nicomachuss-theorem-ℕ WDID=Q2197859 WD="squared triangular number"}}
+asserts that the [sum](elementary-number-theory.sums-natural-numbers.md) from
+`k = 0` to `n` of the
+[cube](elemenatary-number-theory.cubes-natural-numbers.md) `k³` is
+[equal to](foundation-core.identity-types.md) the
+[square](elementary-number-theory.squares-natural-numbers.md) of the `n`th
+[triangular number](elementary-number-theory.triangular-numbers.md), i.e., it
+asserts that
+
+$$
+ \sum_{k=0}^n k^3 = \left(\sum_{k=0}^n k \right)^2.
+$$
+
+This identity is a common exercise in introductory sections on mathematical
+induction. As such, it can be found as exercise 2 in section 1.2 of
+{{#cite Andrews94}}, or exercise 2(c) of section 1.2 in {{#cite Leveque12volI}}.
+
+**Proof.** Recall that the $n$th triangular number is $n(n+1)/2$. We will prove
+by induction that
+
+$$
+ 4\sum_{k=0}^n k^3 = 4\left(\sum_{k=0}^n k \right)^2.
+$$
+
+This allows us to avoid carrying along division by 4 throughout the proof. In
+the base case we have
+
+$$
+ 4\sum_{k=0}^0 k^3 = 4·0^3 = 4·0^2 = 4(0·1/2)^2.
+$$
+
+For the inductive step, assume that the identity holds for `n`. Then we have
+
+$$
+ 4\sum_{k=0}^{n+1} k^3 = (n(n+1))^2 + 4(n+1)^3 = ((n+1)(n+2))^2,
+$$
+
+where the last step follows by algebra. This completes the proof.
+
+## Properties
+
+### The square of the pronic number of a successor
+
+We have `((n + 1) _ (n + 2))² = (n _ (n + 1))² + 4 \* (n + 1)³
+
+```agda
+compute-square-pronic-number-succ-ℕ :
+ (n : ℕ) →
+ square-ℕ (pronic-number-ℕ (succ-ℕ n)) =
+ square-ℕ (pronic-number-ℕ n) +ℕ 4 *ℕ cube-ℕ (succ-ℕ n)
+compute-square-pronic-number-succ-ℕ n =
+ ( ap square-ℕ (commutative-mul-ℕ (succ-ℕ n) (succ-ℕ (succ-ℕ n)))) ∙
+ ( distributive-square-mul-ℕ (succ-ℕ (succ-ℕ n)) (succ-ℕ n)) ∙
+ ( ap (_*ℕ (square-ℕ (succ-ℕ n))) (square-succ-succ-ℕ' n)) ∙
+ ( right-distributive-mul-add-ℕ
+ ( square-ℕ n)
+ ( 4 *ℕ succ-ℕ n)
+ ( square-ℕ (succ-ℕ n))) ∙
+ ( ap-add-ℕ
+ ( inv (distributive-square-mul-ℕ n (succ-ℕ n)))
+ ( associative-mul-ℕ 4 (succ-ℕ n) (square-ℕ (succ-ℕ n)) ∙
+ ap (mul-ℕ 4) (commutative-mul-ℕ (succ-ℕ n) (square-ℕ (succ-ℕ n)))))
+```
+
+### Nicomachus's theorem
+
+```agda
+nicomachuss-theorem-ℕ' :
+ (n : ℕ) →
+ 4 *ℕ sum-Fin-ℕ (succ-ℕ n) (λ i → cube-ℕ (nat-Fin (succ-ℕ n) i)) =
+ 4 *ℕ square-ℕ (triangular-number-ℕ n)
+nicomachuss-theorem-ℕ' zero-ℕ = refl
+nicomachuss-theorem-ℕ' (succ-ℕ n) =
+ ( left-distributive-mul-add-ℕ 4
+ ( sum-Fin-ℕ (succ-ℕ n) (λ i → cube-ℕ (nat-Fin (succ-ℕ n) i)))
+ ( cube-ℕ (succ-ℕ n))) ∙
+ ( ap
+ ( _+ℕ 4 *ℕ cube-ℕ (succ-ℕ n))
+ ( ( nicomachuss-theorem-ℕ' n) ∙
+ ( inv (distributive-square-mul-ℕ 2 (triangular-number-ℕ n))) ∙
+ ( ap square-ℕ (compute-triangular-number-ℕ' n)))) ∙
+ ( inv (compute-square-pronic-number-succ-ℕ n)) ∙
+ ( ap square-ℕ (inv (compute-triangular-number-ℕ' (succ-ℕ n)))) ∙
+ ( distributive-square-mul-ℕ 2 (triangular-number-ℕ (succ-ℕ n)))
+
+nicomachuss-theorem-ℕ :
+ (n : ℕ) →
+ sum-Fin-ℕ (succ-ℕ n) (λ i → cube-ℕ (nat-Fin (succ-ℕ n) i)) =
+ square-ℕ (triangular-number-ℕ n)
+nicomachuss-theorem-ℕ n =
+ is-injective-left-mul-ℕ 4
+ ( is-nonzero-four-ℕ)
+ ( nicomachuss-theorem-ℕ' n)
+```
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/nontrivial-divisors-natural-numbers.lagda.md b/src/elementary-number-theory/nontrivial-divisors-natural-numbers.lagda.md
new file mode 100644
index 0000000000..9852a68d93
--- /dev/null
+++ b/src/elementary-number-theory/nontrivial-divisors-natural-numbers.lagda.md
@@ -0,0 +1,276 @@
+# Nontrivial divisors of natural numbers
+
+```agda
+module elementary-number-theory.nontrivial-divisors-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.prime-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+open import elementary-number-theory.well-ordering-principle-natural-numbers
+
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.identity-types
+open import foundation.propositions
+open import foundation.type-arithmetic-empty-type
+open import foundation.unit-type
+open import foundation.universe-levels
+
+open import lists.lists
+open import lists.universal-quantification-lists
+```
+
+
+
+## Idea
+
+A {{#concept "nontrivial divisor"}} of a
+[natural number](elementary-number-theory.natural-numbers.md) is a
+[divisor](elementary-number-theory.divisibility-natural-numbers.md)
+[strictly greater](elementary-number-theory.strict-inequality-natural-numbers.md)
+than `1`.
+
+Every number strictly greater than `1` has a least nontrivial divisor, which is
+a [prime number](elementary-number-theory.prime-numbers.md). This fact is
+essential in the
+[Fundamental Theorem of Arithmetic](elementary-number-theory.fundamental-theorem-of-arithmetic.md).
+
+## Definitions
+
+### Nontrivial divisors
+
+Nontrivial divisors of a natural number are divisors strictly greater than `1`.
+
+```agda
+module _
+ (n x : ℕ)
+ where
+
+ is-nontrivial-divisor-ℕ : UU lzero
+ is-nontrivial-divisor-ℕ = (1 <-ℕ x) × (div-ℕ x n)
+
+ is-prop-is-nontrivial-divisor-ℕ : is-prop is-nontrivial-divisor-ℕ
+ is-prop-is-nontrivial-divisor-ℕ =
+ is-prop-Σ
+ ( is-prop-le-ℕ 1 x)
+ ( λ p → is-prop-div-ℕ x n (inl (is-nonzero-le-ℕ 1 x p)))
+
+ is-nontrivial-divisor-ℕ-Prop : Prop lzero
+ pr1 is-nontrivial-divisor-ℕ-Prop = is-nontrivial-divisor-ℕ
+ pr2 is-nontrivial-divisor-ℕ-Prop = is-prop-is-nontrivial-divisor-ℕ
+
+ le-one-is-nontrivial-divisor-ℕ :
+ is-nontrivial-divisor-ℕ → 1 <-ℕ x
+ le-one-is-nontrivial-divisor-ℕ = pr1
+
+ div-is-nontrivial-divisor-ℕ :
+ is-nontrivial-divisor-ℕ → div-ℕ x n
+ div-is-nontrivial-divisor-ℕ = pr2
+```
+
+### Lists of nontrivial divisors of a number
+
+```agda
+is-list-of-nontrivial-divisors-ℕ :
+ ℕ → list ℕ → UU lzero
+is-list-of-nontrivial-divisors-ℕ n l =
+ for-all-list l (is-nontrivial-divisor-ℕ n)
+```
+
+## Properties
+
+### Being a nontrivial divisor is decidable
+
+```agda
+is-decidable-is-nontrivial-divisor-ℕ :
+ (n x : ℕ) → is-decidable (is-nontrivial-divisor-ℕ n x)
+is-decidable-is-nontrivial-divisor-ℕ n x =
+ is-decidable-product (is-decidable-le-ℕ 1 x) (is-decidable-div-ℕ x n)
+```
+
+### Any number strictly greater than `1` is a nontrivial divisor of itself
+
+```agda
+is-nontrivial-divisor-diagonal-ℕ :
+ (n : ℕ) → le-ℕ 1 n → is-nontrivial-divisor-ℕ n n
+pr1 (is-nontrivial-divisor-diagonal-ℕ n H) = H
+pr2 (is-nontrivial-divisor-diagonal-ℕ n H) = refl-div-ℕ n
+```
+
+### Any nontrivial divisor of a number `x` that divides a number `y` is a nontrivial divisor of `y`
+
+```agda
+is-nontrivial-divisor-div-ℕ :
+ (m n k : ℕ) → div-ℕ n k →
+ is-nontrivial-divisor-ℕ n m → is-nontrivial-divisor-ℕ k m
+pr1 (is-nontrivial-divisor-div-ℕ m n k H K) =
+ le-one-is-nontrivial-divisor-ℕ n m K
+pr2 (is-nontrivial-divisor-div-ℕ m n k H K) =
+ transitive-div-ℕ m n k H (div-is-nontrivial-divisor-ℕ n m K)
+```
+
+### Any list of nontrivial divisors of a number `x` that divides a number `y` is a list of nontrivial divisors of `y`
+
+```agda
+is-list-of-nontrivial-divisors-div-ℕ :
+ (x y : ℕ) → div-ℕ x y → (l : list ℕ) →
+ is-list-of-nontrivial-divisors-ℕ x l → is-list-of-nontrivial-divisors-ℕ y l
+is-list-of-nontrivial-divisors-div-ℕ x y d nil H = raise-star
+pr1 (is-list-of-nontrivial-divisors-div-ℕ x y d (cons z l) (H , K)) =
+ is-nontrivial-divisor-div-ℕ z x y d H
+pr2 (is-list-of-nontrivial-divisors-div-ℕ x y d (cons z l) (H , K)) =
+ is-list-of-nontrivial-divisors-div-ℕ x y d l K
+```
+
+### Every natural number strictly greater than `1` has a least nontrivial divisor
+
+```agda
+least-nontrivial-divisor-ℕ :
+ (n : ℕ) → le-ℕ 1 n → minimal-element-ℕ (is-nontrivial-divisor-ℕ n)
+least-nontrivial-divisor-ℕ n H =
+ well-ordering-principle-ℕ
+ ( is-nontrivial-divisor-ℕ n)
+ ( is-decidable-is-nontrivial-divisor-ℕ n)
+ ( is-nontrivial-divisor-diagonal-ℕ n H)
+
+nat-least-nontrivial-divisor-ℕ : (n : ℕ) → le-ℕ 1 n → ℕ
+nat-least-nontrivial-divisor-ℕ n H = pr1 (least-nontrivial-divisor-ℕ n H)
+
+nat-least-nontrivial-divisor-ℕ' : ℕ → ℕ
+nat-least-nontrivial-divisor-ℕ' zero-ℕ = 0
+nat-least-nontrivial-divisor-ℕ' (succ-ℕ zero-ℕ) = 1
+nat-least-nontrivial-divisor-ℕ' (succ-ℕ (succ-ℕ n)) =
+ nat-least-nontrivial-divisor-ℕ (succ-ℕ (succ-ℕ n)) star
+
+le-one-least-nontrivial-divisor-ℕ :
+ (n : ℕ) (H : le-ℕ 1 n) → le-ℕ 1 (nat-least-nontrivial-divisor-ℕ n H)
+le-one-least-nontrivial-divisor-ℕ n H =
+ pr1 (pr1 (pr2 (least-nontrivial-divisor-ℕ n H)))
+
+div-least-nontrivial-divisor-ℕ :
+ (n : ℕ) (H : le-ℕ 1 n) → div-ℕ (nat-least-nontrivial-divisor-ℕ n H) n
+div-least-nontrivial-divisor-ℕ n H =
+ pr2 (pr1 (pr2 (least-nontrivial-divisor-ℕ n H)))
+
+is-minimal-least-nontrivial-divisor-ℕ :
+ (n : ℕ) (H : le-ℕ 1 n) (x : ℕ) (K : 1 <-ℕ x) (d : div-ℕ x n) →
+ leq-ℕ (nat-least-nontrivial-divisor-ℕ n H) x
+is-minimal-least-nontrivial-divisor-ℕ n H x K d =
+ pr2 (pr2 (least-nontrivial-divisor-ℕ n H)) x (K , d)
+```
+
+### The least nontrivial divisor of a number `> 1` is nonzero
+
+```agda
+abstract
+ is-nonzero-least-nontrivial-divisor-ℕ :
+ (n : ℕ) (H : le-ℕ 1 n) → is-nonzero-ℕ (nat-least-nontrivial-divisor-ℕ n H)
+ is-nonzero-least-nontrivial-divisor-ℕ n H =
+ is-nonzero-div-ℕ
+ ( nat-least-nontrivial-divisor-ℕ n H)
+ ( n)
+ ( div-least-nontrivial-divisor-ℕ n H)
+ ( λ where refl → H)
+```
+
+### The least nontrivial divisor of a number `> 1` is prime
+
+```agda
+is-prime-least-nontrivial-divisor-ℕ :
+ (n : ℕ) (H : le-ℕ 1 n) → is-prime-ℕ (nat-least-nontrivial-divisor-ℕ n H)
+pr1 (is-prime-least-nontrivial-divisor-ℕ n H x) (K , L) =
+ map-right-unit-law-coproduct-is-empty
+ ( is-one-ℕ x)
+ ( 1 <-ℕ x)
+ ( λ p →
+ contradiction-le-ℕ x
+ ( nat-least-nontrivial-divisor-ℕ n H)
+ ( le-div-ℕ x
+ ( nat-least-nontrivial-divisor-ℕ n H)
+ ( is-nonzero-least-nontrivial-divisor-ℕ n H)
+ ( L)
+ ( K))
+ ( is-minimal-least-nontrivial-divisor-ℕ n H x p
+ ( transitive-div-ℕ x
+ ( nat-least-nontrivial-divisor-ℕ n H)
+ ( n)
+ ( div-least-nontrivial-divisor-ℕ n H)
+ ( L))))
+ ( eq-or-le-leq-ℕ' 1 x
+ ( leq-one-div-ℕ x n
+ ( transitive-div-ℕ x
+ ( nat-least-nontrivial-divisor-ℕ n H)
+ ( n)
+ ( div-least-nontrivial-divisor-ℕ n H)
+ ( L))
+ ( leq-le-ℕ 1 n H)))
+pr1 (pr2 (is-prime-least-nontrivial-divisor-ℕ n H .1) refl) =
+ neq-le-ℕ 1
+ ( nat-least-nontrivial-divisor-ℕ n H)
+ ( le-one-least-nontrivial-divisor-ℕ n H)
+pr2 (pr2 (is-prime-least-nontrivial-divisor-ℕ n H .1) refl) =
+ div-one-ℕ _
+```
+
+### The least prime divisor of a number `1 < n`
+
+```agda
+nat-least-prime-divisor-ℕ : (x : ℕ) → 1 <-ℕ x → ℕ
+nat-least-prime-divisor-ℕ x H = nat-least-nontrivial-divisor-ℕ x H
+
+is-prime-least-prime-divisor-ℕ :
+ (x : ℕ) (H : 1 <-ℕ x) → is-prime-ℕ (nat-least-prime-divisor-ℕ x H)
+is-prime-least-prime-divisor-ℕ x H = is-prime-least-nontrivial-divisor-ℕ x H
+
+prime-least-prime-divisor-ℕ : (x : ℕ) → 1 <-ℕ x → Prime-ℕ
+pr1 (prime-least-prime-divisor-ℕ x H) = nat-least-prime-divisor-ℕ x H
+pr2 (prime-least-prime-divisor-ℕ x H) = is-prime-least-prime-divisor-ℕ x H
+
+div-least-prime-divisor-ℕ :
+ (x : ℕ) (H : 1 <-ℕ x) → div-ℕ (nat-least-prime-divisor-ℕ x H) x
+div-least-prime-divisor-ℕ x H = div-least-nontrivial-divisor-ℕ x H
+
+quotient-div-least-prime-divisor-ℕ :
+ (x : ℕ) (H : 1 <-ℕ x) → ℕ
+quotient-div-least-prime-divisor-ℕ x H =
+ quotient-div-ℕ
+ ( nat-least-prime-divisor-ℕ x H)
+ ( x)
+ ( div-least-prime-divisor-ℕ x H)
+
+div-quotient-div-least-prime-divisor-ℕ :
+ (x : ℕ) (H : 1 <-ℕ x) → div-ℕ (quotient-div-least-prime-divisor-ℕ x H) x
+div-quotient-div-least-prime-divisor-ℕ x H =
+ div-quotient-div-ℕ
+ ( nat-least-prime-divisor-ℕ x H)
+ ( x)
+ ( div-least-prime-divisor-ℕ x H)
+
+leq-one-quotient-div-least-prime-divisor-ℕ :
+ (x : ℕ) (H : 1 <-ℕ x) → 1 ≤-ℕ quotient-div-least-prime-divisor-ℕ x H
+leq-one-quotient-div-least-prime-divisor-ℕ x H =
+ leq-one-quotient-div-ℕ
+ ( nat-least-prime-divisor-ℕ x H)
+ ( x)
+ ( div-least-prime-divisor-ℕ x H)
+ ( leq-le-ℕ 1 x H)
+
+upper-bound-quotient-div-least-prime-divisor-ℕ :
+ (x : ℕ) (H : 1 <-ℕ succ-ℕ x) →
+ quotient-div-least-prime-divisor-ℕ (succ-ℕ x) H ≤-ℕ x
+upper-bound-quotient-div-least-prime-divisor-ℕ x H =
+ upper-bound-quotient-div-is-prime-ℕ
+ ( nat-least-prime-divisor-ℕ (succ-ℕ x) H)
+ ( x)
+ ( is-prime-least-prime-divisor-ℕ (succ-ℕ x) H)
+ ( div-least-prime-divisor-ℕ (succ-ℕ x) H)
+```
diff --git a/src/elementary-number-theory/number-of-divisors.lagda.md b/src/elementary-number-theory/number-of-divisors.lagda.md
new file mode 100644
index 0000000000..788e38d582
--- /dev/null
+++ b/src/elementary-number-theory/number-of-divisors.lagda.md
@@ -0,0 +1,250 @@
+# The number of divisors function
+
+```agda
+module elementary-number-theory.number-of-divisors where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.bounded-divisibility-natural-numbers
+open import elementary-number-theory.bounded-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.modular-arithmetic-standard-finite-types
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.squares-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.decidable-subtypes
+open import foundation.dependent-pair-types
+open import foundation.fixed-points-endofunctions
+open import foundation.function-types
+open import foundation.identity-types
+open import foundation.involutions
+open import foundation.propositions
+open import foundation.sets
+open import foundation.subtypes
+open import foundation.universe-levels
+
+open import univalent-combinatorics.counting
+open import univalent-combinatorics.counting-decidable-subtypes
+open import univalent-combinatorics.standard-finite-types
+```
+
+
+
+## Idea
+
+The
+{{#concept "number of divisors" Agda=number-of-divisors-ℕ OEIS=A000005 WDID=Q12890701 WD="number of divisors"}}
+$\tau(n)$ of a [natural number](elementary-number-theory.natural-numbers.md) $n$
+is the number of natural numbers $d \leq n$ that
+[divide](elementary-number-theory.divisibility.natural-numbers.md) the number
+$n$, i.e.,
+
+$$
+ \tau(n) := |\{d \in \mathbb{N} \mid d|n\}|.
+$$
+
+The number of divisors function is listed as A000005 in the
+[OEIS](literature.oeis.md) {{#cite oeis}}.
+
+## Definitions
+
+### The type of divisors
+
+```agda
+decidable-subtype-of-divisors-ℕ :
+ (n : ℕ) → decidable-subtype lzero (bounded-ℕ n)
+decidable-subtype-of-divisors-ℕ n i =
+ bounded-div-ℕ-Decidable-Prop (nat-bounded-ℕ n i) n
+
+divisor-ℕ :
+ ℕ → UU lzero
+divisor-ℕ n =
+ type-decidable-subtype (decidable-subtype-of-divisors-ℕ n)
+
+nat-divisor-ℕ :
+ (n : ℕ) → divisor-ℕ n → ℕ
+nat-divisor-ℕ n =
+ nat-bounded-ℕ n ∘ pr1
+
+bounded-div-divisor-ℕ :
+ (n : ℕ) (d : divisor-ℕ n) → bounded-div-ℕ (nat-divisor-ℕ n d) n
+bounded-div-divisor-ℕ n =
+ pr2
+
+div-divisor-ℕ :
+ (n : ℕ) (d : divisor-ℕ n) → div-ℕ (nat-divisor-ℕ n d) n
+div-divisor-ℕ n d =
+ div-bounded-div-ℕ (nat-divisor-ℕ n d) n (bounded-div-divisor-ℕ n d)
+
+eq-divisor-ℕ :
+ (n : ℕ) (x y : divisor-ℕ n) →
+ nat-divisor-ℕ n x = nat-divisor-ℕ n y → x = y
+eq-divisor-ℕ n x y p =
+ eq-type-subtype
+ ( λ i → bounded-div-ℕ-Prop (nat-bounded-ℕ n i) n)
+ ( eq-type-subtype
+ ( λ x → leq-ℕ-Prop x n)
+ ( p))
+
+is-set-divisor-ℕ :
+ (n : ℕ) → is-set (divisor-ℕ n)
+is-set-divisor-ℕ n =
+ is-set-type-subtype
+ ( λ i → bounded-div-ℕ-Prop (nat-bounded-ℕ n i) n)
+ ( is-set-bounded-ℕ n)
+
+divisor-ℕ-Set :
+ (n : ℕ) → Set lzero
+pr1 (divisor-ℕ-Set n) = divisor-ℕ n
+pr2 (divisor-ℕ-Set n) = is-set-divisor-ℕ n
+
+upper-bound-divisor-ℕ :
+ (n : ℕ) (d : divisor-ℕ n) → nat-divisor-ℕ n d ≤-ℕ n
+upper-bound-divisor-ℕ n =
+ upper-bound-nat-bounded-ℕ n ∘ pr1
+
+nat-quotient-divisor-ℕ :
+ (n : ℕ) → divisor-ℕ n → ℕ
+nat-quotient-divisor-ℕ n (d , H) =
+ quotient-bounded-div-ℕ (nat-bounded-ℕ n d) n H
+
+upper-bound-quotient-divisor-ℕ :
+ (n : ℕ) (d : divisor-ℕ n) → nat-quotient-divisor-ℕ n d ≤-ℕ n
+upper-bound-quotient-divisor-ℕ n (d , H) =
+ upper-bound-quotient-bounded-div-ℕ (nat-bounded-ℕ n d) n H
+
+eq-quotient-divisor-ℕ :
+ (n : ℕ) (d : divisor-ℕ n) →
+ nat-quotient-divisor-ℕ n d *ℕ nat-divisor-ℕ n d = n
+eq-quotient-divisor-ℕ n d =
+ eq-quotient-bounded-div-ℕ (nat-divisor-ℕ n d) n (bounded-div-divisor-ℕ n d)
+
+eq-quotient-divisor-ℕ' :
+ (n : ℕ) (d : divisor-ℕ n) →
+ nat-divisor-ℕ n d *ℕ nat-quotient-divisor-ℕ n d = n
+eq-quotient-divisor-ℕ' n d =
+ eq-quotient-bounded-div-ℕ' (nat-divisor-ℕ n d) n (bounded-div-divisor-ℕ n d)
+
+quotient-divisor-ℕ :
+ (n : ℕ) → divisor-ℕ n → divisor-ℕ n
+pr1 (pr1 (quotient-divisor-ℕ n d)) =
+ nat-quotient-divisor-ℕ n d
+pr2 (pr1 (quotient-divisor-ℕ n d)) =
+ upper-bound-quotient-divisor-ℕ n d
+pr1 (pr2 (quotient-divisor-ℕ n d)) =
+ nat-divisor-ℕ n d
+pr1 (pr2 (pr2 (quotient-divisor-ℕ n d))) =
+ upper-bound-divisor-ℕ n d
+pr2 (pr2 (pr2 (quotient-divisor-ℕ n d))) =
+ eq-quotient-divisor-ℕ' n d
+```
+
+### The number of divisors function
+
+Note that the entry `number-of-elements-decidable-subtype` refers to
+`count-decidable-subtype'`, which is `abstract` and therefore doesn't compute.
+
+```agda
+count-divisor-ℕ :
+ (n : ℕ) → count (divisor-ℕ n)
+count-divisor-ℕ n =
+ count-decidable-subtype
+ ( decidable-subtype-of-divisors-ℕ n)
+ ( count-bounded-ℕ n)
+
+number-of-divisors-ℕ : ℕ → ℕ
+number-of-divisors-ℕ n =
+ number-of-elements-decidable-subtype
+ ( decidable-subtype-of-divisors-ℕ n)
+ ( count-bounded-ℕ n)
+```
+
+### Involution on the type of divisors
+
+For every natural number `n : ℕ`, the map `d ↦ n/d` mapping a divisor of `n` to
+its quotient is an involution. This operation has a fixed point precisely when
+`n` is a [square number](elementary-number-theory.square-natural-numbers.md).
+
+```agda
+is-involution-quotient-divisor-ℕ :
+ (n : ℕ) → is-involution (quotient-divisor-ℕ n)
+is-involution-quotient-divisor-ℕ n d =
+ eq-divisor-ℕ n (quotient-divisor-ℕ n (quotient-divisor-ℕ n d)) d refl
+```
+
+### The involution on the type of divisors of `n` has a fixed point if and only if `n` is a square number
+
+```agda
+is-square-has-fixed-point-quotient-divisor-ℕ :
+ (n : ℕ) → fixed-point (quotient-divisor-ℕ n) → is-square-ℕ n
+pr1 (is-square-has-fixed-point-quotient-divisor-ℕ n (d , p)) =
+ nat-divisor-ℕ n d
+pr2 (is-square-has-fixed-point-quotient-divisor-ℕ n (d , p)) =
+ ( inv (eq-quotient-divisor-ℕ n d)) ∙
+ ( ap (_*ℕ nat-divisor-ℕ n d) (ap (nat-divisor-ℕ n) p))
+
+square-root-divisor-is-square-ℕ :
+ (n : ℕ) (H : is-square-ℕ n) → divisor-ℕ n
+square-root-divisor-is-square-ℕ ._ (n , refl) =
+ ( ( n , is-inflationary-square-ℕ n) ,
+ ( is-inflationary-bounded-div-square-ℕ n))
+
+is-fixed-point-square-root-divisor-is-square-ℕ :
+ (n : ℕ) (H : is-square-ℕ n) →
+ quotient-divisor-ℕ n (square-root-divisor-is-square-ℕ n H) =
+ square-root-divisor-is-square-ℕ n H
+is-fixed-point-square-root-divisor-is-square-ℕ ._ H@(n , refl) =
+ eq-divisor-ℕ
+ ( square-ℕ n)
+ ( quotient-divisor-ℕ _ (square-root-divisor-is-square-ℕ _ H))
+ ( square-root-divisor-is-square-ℕ _ H)
+ ( refl)
+
+has-fixed-point-quotient-divisor-is-square-ℕ :
+ (n : ℕ) → is-square-ℕ n → fixed-point (quotient-divisor-ℕ n)
+pr1 (has-fixed-point-quotient-divisor-is-square-ℕ n H) =
+ square-root-divisor-is-square-ℕ n H
+pr2 (has-fixed-point-quotient-divisor-is-square-ℕ n H) =
+ is-fixed-point-square-root-divisor-is-square-ℕ n H
+```
+
+### The type of fixed points of the involution on the type of divisors is a proposition
+
+This essentially claims that only the square root of a square can be the fixed
+point of the involution on the type of divisors.
+
+```agda
+all-elements-equal-fixed-point-quotient-divisor-ℕ :
+ (n : ℕ) → all-elements-equal (fixed-point (quotient-divisor-ℕ n))
+all-elements-equal-fixed-point-quotient-divisor-ℕ n (x , p) (y , q) =
+ eq-type-subtype
+ ( λ d → Id-Prop (divisor-ℕ-Set n) (quotient-divisor-ℕ n d) d)
+ ( eq-divisor-ℕ n x y
+ ( is-injective-square-ℕ
+ ( ( ap (nat-divisor-ℕ n x *ℕ_) (ap (nat-divisor-ℕ n) (inv p))) ∙
+ ( eq-quotient-divisor-ℕ' n x) ∙
+ ( inv (eq-quotient-divisor-ℕ' n y)) ∙
+ ( ap (nat-divisor-ℕ n y *ℕ_) (ap (nat-divisor-ℕ n) q)))))
+
+is-prop-fixed-point-quotient-divisor-ℕ :
+ (n : ℕ) → is-prop (fixed-point (quotient-divisor-ℕ n))
+is-prop-fixed-point-quotient-divisor-ℕ n =
+ is-prop-all-elements-equal
+ ( all-elements-equal-fixed-point-quotient-divisor-ℕ n)
+```
+
+## Remarks
+
+In the properties above we have shown that the quotient operation on the type of
+divisors of any natural number $n$ is an involution with at most one fixed
+point, and it has a fixed point if and only if $n$ is square. This implies that
+the number of divisors is odd if and only if $n$ is a square. However, in the
+agda-unimath library we don't have the appropriate infrastructure yet for
+counting the elements of types with involutions. The conclusion that the number
+of divisors of $n$ is odd if and only if $n$ is a square will be formalized in
+the future.
diff --git a/src/elementary-number-theory/parity-integers.lagda.md b/src/elementary-number-theory/parity-integers.lagda.md
new file mode 100644
index 0000000000..79a423c4ae
--- /dev/null
+++ b/src/elementary-number-theory/parity-integers.lagda.md
@@ -0,0 +1,427 @@
+# Parity of the integers
+
+```agda
+module elementary-number-theory.parity-integers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.absolute-value-integers
+open import elementary-number-theory.addition-integers
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.difference-integers
+open import elementary-number-theory.divisibility-integers
+open import elementary-number-theory.inequality-integers
+open import elementary-number-theory.integers
+open import elementary-number-theory.multiplication-integers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
+open import elementary-number-theory.positive-and-negative-integers
+open import elementary-number-theory.unit-similarity-integers
+
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.empty-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.functoriality-coproduct-types
+open import foundation.identity-types
+open import foundation.negation
+open import foundation.transport-along-identifications
+open import foundation.unit-type
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+{{#concept "Parity" WD="parity" WDID=Q141160}}
+[partitions](foundation.partitions.md) the
+[integers](elementary-number-theory.integers.md) into two
+[classes](foundation.equivalence-relations.md): the
+{{#concept "even" Disambiguation="integer" Agda=is-even-ℤ WD="even number" WDID=Q13366104}}
+and the
+{{#concept "odd" Disambiguation="integer" Agda=is-odd-ℤ WD="odd number" WDID=Q13366129}}
+integers. Even integers are those that are
+[divisible](elementary-number-theory.divisibility-integers.md) by two, and odd
+integers are those that aren't.
+
+## Definitions
+
+### Even integers
+
+```agda
+is-even-ℤ : ℤ → UU lzero
+is-even-ℤ a = div-ℤ (int-ℕ 2) a
+```
+
+### The bi-infinite sequence of even integers
+
+```agda
+even-integer-ℤ : ℤ → ℤ
+even-integer-ℤ a = int-ℕ 2 *ℤ a
+```
+
+### Odd integers
+
+```agda
+is-odd-ℤ : ℤ → UU lzero
+is-odd-ℤ a = ¬ (is-even-ℤ a)
+```
+
+### The bi-infinite sequence of odd integers
+
+```agda
+odd-integer-ℤ : ℤ → ℤ
+odd-integer-ℤ a = int-ℕ 2 *ℤ a +ℤ one-ℤ
+```
+
+### The type of odd expansions of an integer
+
+```agda
+has-odd-expansion-ℤ : ℤ → UU lzero
+has-odd-expansion-ℤ = fiber odd-integer-ℤ
+```
+
+## Properties
+
+### Even integers are closed under equality
+
+```agda
+is-even-eq-ℤ : {a b : ℤ} → a = b → is-even-ℤ b → is-even-ℤ a
+is-even-eq-ℤ refl H = H
+
+is-even-eq-ℤ' : {a b : ℤ} → a = b → is-even-ℤ a → is-even-ℤ b
+is-even-eq-ℤ' refl H = H
+```
+
+### Odd integers are closed under equality
+
+```agda
+is-odd-eq-ℤ : {a b : ℤ} → a = b → is-odd-ℤ b → is-odd-ℤ a
+is-odd-eq-ℤ refl H = H
+
+is-odd-eq-ℤ' : {a b : ℤ} → a = b → is-odd-ℤ a → is-odd-ℤ b
+is-odd-eq-ℤ' refl H = H
+```
+
+### A natural number is even if and only if it is even as an integer
+
+```agda
+is-even-int-is-even-ℕ : (n : ℕ) → is-even-ℕ n → is-even-ℤ (int-ℕ n)
+is-even-int-is-even-ℕ n H = div-int-div-ℕ H
+
+is-even-is-even-int-ℕ : (n : ℕ) → is-even-ℤ (int-ℕ n) → is-even-ℕ n
+is-even-is-even-int-ℕ n H = div-div-int-ℕ H
+```
+
+### A natural number is odd if and only if it is odd as an integer
+
+```agda
+is-odd-int-is-odd-ℕ : (n : ℕ) → is-odd-ℕ n → is-odd-ℤ (int-ℕ n)
+is-odd-int-is-odd-ℕ n H K = H (is-even-is-even-int-ℕ n K)
+
+is-odd-is-odd-int-ℕ : (n : ℕ) → is-odd-ℤ (int-ℕ n) → is-odd-ℕ n
+is-odd-is-odd-int-ℕ n H K = H (is-even-int-is-even-ℕ n K)
+```
+
+### An integer is even if and only if its absolute value is an even integer
+
+```agda
+is-even-int-abs-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → is-even-ℤ (int-abs-ℤ a)
+is-even-int-abs-is-even-ℤ a =
+ div-sim-unit-ℤ
+ ( refl-sim-unit-ℤ (int-ℕ 2))
+ ( symmetric-sim-unit-ℤ (int-abs-ℤ a) a (sim-unit-abs-ℤ a))
+
+is-even-is-even-int-abs-ℤ :
+ (a : ℤ) → is-even-ℤ (int-abs-ℤ a) → is-even-ℤ a
+is-even-is-even-int-abs-ℤ a =
+ div-sim-unit-ℤ
+ ( refl-sim-unit-ℤ (int-ℕ 2))
+ ( sim-unit-abs-ℤ a)
+
+is-even-abs-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → is-even-ℕ (abs-ℤ a)
+is-even-abs-is-even-ℤ a H =
+ is-even-is-even-int-ℕ (abs-ℤ a) (is-even-int-abs-is-even-ℤ a H)
+
+is-even-is-even-abs-ℤ :
+ (a : ℤ) → is-even-ℕ (abs-ℤ a) → is-even-ℤ a
+is-even-is-even-abs-ℤ a H =
+ is-even-is-even-int-abs-ℤ a (is-even-int-is-even-ℕ (abs-ℤ a) H)
+```
+
+### An integer is odd if and only if its absolute value is an odd integer
+
+```agda
+is-odd-int-abs-is-odd-ℤ : (a : ℤ) → is-odd-ℤ a → is-odd-ℤ (int-abs-ℤ a)
+is-odd-int-abs-is-odd-ℤ a H K = H (is-even-is-even-int-abs-ℤ a K)
+
+is-odd-is-odd-int-abs-ℤ : (a : ℤ) → is-odd-ℤ (int-abs-ℤ a) → is-odd-ℤ a
+is-odd-is-odd-int-abs-ℤ a H K = H (is-even-int-abs-is-even-ℤ a K)
+
+is-odd-abs-is-odd-ℤ : (a : ℤ) → is-odd-ℤ a → is-odd-ℕ (abs-ℤ a)
+is-odd-abs-is-odd-ℤ a H K = H (is-even-is-even-abs-ℤ a K)
+
+is-odd-is-odd-abs-ℤ : (a : ℤ) → is-odd-ℕ (abs-ℤ a) → is-odd-ℤ a
+is-odd-is-odd-abs-ℤ a H K = H (is-even-abs-is-even-ℤ a K)
+```
+
+### Being even or odd is decidable
+
+```agda
+is-decidable-is-even-ℤ :
+ (a : ℤ) → is-decidable (is-even-ℤ a)
+is-decidable-is-even-ℤ a =
+ is-decidable-iff
+ ( is-even-is-even-abs-ℤ a)
+ ( is-even-abs-is-even-ℤ a)
+ ( is-decidable-is-even-ℕ (abs-ℤ a))
+
+is-decidable-is-odd-ℤ : (a : ℤ) → is-decidable (is-odd-ℤ a)
+is-decidable-is-odd-ℤ a = is-decidable-neg (is-decidable-is-even-ℤ a)
+```
+
+### An integer is even if and only if it is not odd
+
+```agda
+is-even-is-not-odd-ℤ :
+ (a : ℤ) → ¬ (is-odd-ℤ a) → is-even-ℤ a
+is-even-is-not-odd-ℤ a =
+ double-negation-elim-is-decidable (is-decidable-is-even-ℤ a)
+```
+
+### `0` is an even integer
+
+```agda
+is-even-zero-ℤ : is-even-ℤ zero-ℤ
+is-even-zero-ℤ = is-even-int-is-even-ℕ 0 is-even-zero-ℕ
+```
+
+### `1` is an odd integer
+
+```agda
+is-odd-one-ℤ : is-odd-ℤ one-ℤ
+is-odd-one-ℤ = is-odd-int-is-odd-ℕ 1 is-odd-one-ℕ
+```
+
+### `-1` is an odd integer
+
+```agda
+is-odd-neg-one-ℤ : is-odd-ℤ neg-one-ℤ
+is-odd-neg-one-ℤ H =
+ is-odd-one-ℤ (div-left-summand-ℤ (int-ℕ 2) one-ℤ neg-one-ℤ H is-even-zero-ℤ)
+```
+
+### An integer `x` is even if and only if `x + 2` is even
+
+```agda
+is-even-is-even-add-two-ℤ :
+ (a : ℤ) → is-even-ℤ (a +ℤ int-ℕ 2) → is-even-ℤ a
+is-even-is-even-add-two-ℤ a =
+ div-left-summand-ℤ (int-ℕ 2) a (int-ℕ 2) (refl-div-ℤ (int-ℕ 2))
+
+is-even-add-two-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → is-even-ℤ (a +ℤ int-ℕ 2)
+is-even-add-two-is-even-ℤ a H =
+ div-add-ℤ (int-ℕ 2) a (int-ℕ 2) H (refl-div-ℤ (int-ℕ 2))
+```
+
+### An integer `x` is odd if and only if `x + 2` is odd
+
+```agda
+is-odd-is-odd-add-two-ℤ : (a : ℤ) → is-odd-ℤ (a +ℤ int-ℕ 2) → is-odd-ℤ a
+is-odd-is-odd-add-two-ℤ a H K = H (is-even-add-two-is-even-ℤ a K)
+
+is-odd-add-two-is-odd-ℤ : (a : ℤ) → is-odd-ℤ a → is-odd-ℤ (a +ℤ int-ℕ 2)
+is-odd-add-two-is-odd-ℤ a H K = H (is-even-is-even-add-two-ℤ a K)
+```
+
+### Either `a` or `a + 1` is even
+
+```agda
+is-even-or-is-even-add-one-int-ℕ :
+ (n : ℕ) → is-even-ℤ (int-ℕ n) + is-even-ℤ (int-ℕ n +ℤ one-ℤ)
+is-even-or-is-even-add-one-int-ℕ n =
+ map-coproduct
+ ( is-even-int-is-even-ℕ n)
+ ( tr is-even-ℤ (inv (add-int-ℕ n 1)) ∘ is-even-int-is-even-ℕ (succ-ℕ n))
+ ( is-even-or-is-even-succ-ℕ n)
+
+is-even-or-is-even-add-one-ℤ :
+ (a : ℤ) → is-even-ℤ a + is-even-ℤ (a +ℤ one-ℤ)
+is-even-or-is-even-add-one-ℤ (inl zero-ℕ) = inr is-even-zero-ℤ
+is-even-or-is-even-add-one-ℤ (inl (succ-ℕ x)) = {!!}
+is-even-or-is-even-add-one-ℤ (inr (inl star)) = inl is-even-zero-ℤ
+is-even-or-is-even-add-one-ℤ (inr (inr x)) = {!!}
+```
+
+### If an integer `x` is even, then `x + 1` is odd
+
+```agda
+is-odd-add-one-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → is-odd-ℤ (a +ℤ one-ℤ)
+is-odd-add-one-is-even-ℤ a H K =
+ is-odd-one-ℤ (div-right-summand-ℤ (int-ℕ 2) a one-ℤ H K)
+```
+
+### If an integer `x` is even, then `x - 1` is odd
+
+```agda
+is-odd-add-neg-one-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → is-odd-ℤ (a -ℤ one-ℤ)
+is-odd-add-neg-one-is-even-ℤ a H K =
+ is-odd-neg-one-ℤ (div-right-summand-ℤ (int-ℕ 2) a neg-one-ℤ H K)
+```
+
+### If an integer `x + 1` is even, then `x` is odd
+
+```agda
+is-odd-is-even-add-one-ℤ :
+ (a : ℤ) → is-even-ℤ (a +ℤ one-ℤ) → is-odd-ℤ a
+is-odd-is-even-add-one-ℤ a H K =
+ is-odd-one-ℤ (div-right-summand-ℤ (int-ℕ 2) a one-ℤ K H)
+```
+
+### If an integer `a - 1` is even, then `a` is odd
+
+```agda
+is-odd-is-even-add-neg-one-ℤ :
+ (a : ℤ) → is-even-ℤ (a -ℤ one-ℤ) → is-odd-ℤ a
+is-odd-is-even-add-neg-one-ℤ a H K =
+ is-odd-neg-one-ℤ (div-right-summand-ℤ (int-ℕ 2) a neg-one-ℤ K H)
+```
+
+### If an integer `x` is odd, then `x + 1` is even
+
+```agda
+is-even-add-one-is-odd-ℤ :
+ (a : ℤ) → is-odd-ℤ a → is-even-ℤ (a +ℤ one-ℤ)
+is-even-add-one-is-odd-ℤ a H =
+ is-even-is-not-odd-ℤ
+ ( a +ℤ one-ℤ)
+ ( λ K →
+ {!is-odd-!})
+```
+
+### If an integer is even, then its predecessor is odd
+
+```agda
+is-odd-pred-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → is-odd-ℤ (pred-ℤ a)
+is-odd-pred-is-even-ℤ a H =
+ is-odd-eq-ℤ (is-right-add-neg-one-pred-ℤ a) (is-odd-add-neg-one-is-even-ℤ a H)
+```
+
+### If the successor of an integer `a` is even, then `a` is odd
+
+```agda
+is-odd-is-even-succ-ℤ :
+ (a : ℤ) → is-even-ℤ (succ-ℤ a) → is-odd-ℤ a
+is-odd-is-even-succ-ℤ a H =
+ is-odd-is-even-add-one-ℤ a (is-even-eq-ℤ' (is-right-add-one-succ-ℤ a) H)
+```
+
+### If the predecessor of an integer is even, then it is odd
+
+```agda
+is-odd-is-even-pred-ℤ :
+ (a : ℤ) → is-even-ℤ (pred-ℤ a) → is-odd-ℤ a
+is-odd-is-even-pred-ℤ a H =
+ is-odd-is-even-add-neg-one-ℤ a
+ ( is-even-eq-ℤ' (is-right-add-neg-one-pred-ℤ a) H)
+```
+
+### If an integer `x + 1` is odd, then `x` is even
+
+```text
+is-even-is-odd-succ-ℕ :
+ (n : ℕ) → is-odd-ℕ (succ-ℕ n) → is-even-ℕ n
+is-even-is-odd-succ-ℕ n p =
+ is-even-is-even-succ-succ-ℕ
+ ( n)
+ ( is-even-succ-is-odd-ℕ (succ-ℕ n) p)
+```
+
+### An integer is odd if and only if it has an odd expansion
+
+```agda
+is-odd-has-odd-expansion-ℤ : (a : ℤ) → has-odd-expansion-ℤ a → is-odd-ℤ a
+is-odd-has-odd-expansion-ℤ ._ (x , refl) =
+ is-odd-add-one-is-even-ℤ (int-ℕ 2 *ℤ x) (x , commutative-mul-ℤ x (int-ℕ 2))
+
+has-odd-expansion-neg-one-ℤ : has-odd-expansion-ℤ neg-one-ℤ
+pr1 has-odd-expansion-neg-one-ℤ = neg-one-ℤ
+pr2 has-odd-expansion-neg-one-ℤ = refl
+
+is-even-integer-below-ℤ :
+ (a b : ℤ) → UU lzero
+is-even-integer-below-ℤ a b = is-even-ℤ b × (b ≤-ℤ a)
+
+is-decidable-is-even-integer-below-ℤ :
+ (a b : ℤ) → is-decidable (is-even-integer-below-ℤ a b)
+is-decidable-is-even-integer-below-ℤ a b =
+ is-decidable-product (is-decidable-is-even-ℤ b) (is-decidable-leq-ℤ b a)
+
+instance-even-integer-below-ℤ :
+ (a : ℤ) → Σ ℤ (is-even-integer-below-ℤ a)
+instance-even-integer-below-ℤ (inl x) = {!!}
+instance-even-integer-below-ℤ (inr (inl x)) =
+ ( zero-ℤ , is-even-zero-ℤ , refl-leq-ℤ zero-ℤ)
+instance-even-integer-below-ℤ (inr (inr x)) =
+ ( zero-ℤ , is-even-zero-ℤ , leq-zero-is-positive-ℤ (inr (inr x)) star)
+
+has-odd-expansion-is-odd-ℤ :
+ (a : ℤ) → is-odd-ℤ a → has-odd-expansion-ℤ a
+has-odd-expansion-is-odd-ℤ a H = {!!}
+```
+
+```text
+is-odd-has-odd-expansion-ℕ : (n : ℕ) → has-odd-expansion-ℕ n → is-odd-ℕ n
+is-odd-has-odd-expansion-ℕ .(succ-ℕ (m *ℕ 2)) (m , refl) =
+ is-odd-succ-is-even-ℕ (m *ℕ 2) (m , refl)
+
+has-odd-expansion-is-odd : (n : ℕ) → is-odd-ℕ n → has-odd-expansion-ℕ n
+has-odd-expansion-is-odd zero-ℕ p = ex-falso (p is-even-zero-ℕ)
+has-odd-expansion-is-odd (succ-ℕ zero-ℕ) p = 0 , refl
+has-odd-expansion-is-odd (succ-ℕ (succ-ℕ n)) p =
+ ( succ-ℕ (pr1 s)) , ap (succ-ℕ ∘ succ-ℕ) (pr2 s)
+ where
+ s : has-odd-expansion-ℕ n
+ s = has-odd-expansion-is-odd n (is-odd-is-odd-succ-succ-ℕ n p)
+```
+
+### A number is even if and only if it is divisible by an even number
+
+```text
+is-even-div-is-even-ℕ :
+ (n m : ℕ) → is-even-ℕ m → div-ℕ m n → is-even-ℕ n
+is-even-div-is-even-ℕ ._ ._ (m' , refl) (k , refl) =
+ k *ℕ m' , associative-mul-ℕ k m' 2
+
+is-even-div-4-ℕ :
+ (n : ℕ) → div-ℕ 4 n → is-even-ℕ n
+is-even-div-4-ℕ n = is-even-div-is-even-ℕ n 4 (2 , refl)
+```
+
+### If any two out of `x`, `y`, and `x + y` are even, then so is the third
+
+```text
+is-even-add-ℕ :
+ (m n : ℕ) → is-even-ℕ m → is-even-ℕ n → is-even-ℕ (add-ℕ m n)
+is-even-add-ℕ = div-add-ℕ 2
+
+is-even-left-summand-ℕ :
+ (m n : ℕ) → is-even-ℕ n → is-even-ℕ (add-ℕ m n) → is-even-ℕ m
+is-even-left-summand-ℕ = div-left-summand-ℕ 2
+
+is-even-right-summand-ℕ :
+ (m n : ℕ) → is-even-ℕ m → is-even-ℕ (add-ℕ m n) → is-even-ℕ n
+is-even-right-summand-ℕ = div-right-summand-ℕ 2
+```
diff --git a/src/elementary-number-theory/parity-natural-numbers.lagda.md b/src/elementary-number-theory/parity-natural-numbers.lagda.md
index 78da36cfb4..74e9e94987 100644
--- a/src/elementary-number-theory/parity-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/parity-natural-numbers.lagda.md
@@ -7,19 +7,35 @@ module elementary-number-theory.parity-natural-numbers where
Imports
```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.bounded-divisibility-natural-numbers
+open import elementary-number-theory.congruence-natural-numbers
+open import elementary-number-theory.distance-natural-numbers
open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.euclidean-division-natural-numbers
+open import elementary-number-theory.exponentiation-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.modular-arithmetic-standard-finite-types
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.prime-numbers
+open import elementary-number-theory.proper-divisors-natural-numbers
open import foundation.action-on-identifications-functions
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
open import foundation.decidable-types
open import foundation.dependent-pair-types
+open import foundation.double-negation
open import foundation.empty-types
+open import foundation.fibers-of-maps
open import foundation.function-types
open import foundation.identity-types
+open import foundation.injective-maps
open import foundation.negation
+open import foundation.transport-along-identifications
+open import foundation.unit-type
open import foundation.universe-levels
```
@@ -27,22 +43,148 @@ open import foundation.universe-levels
## Idea
-Parity partitions the natural numbers into two classes: the even and the odd
-natural numbers. Even natural numbers are those that are divisible by two, and
-odd natural numbers are those that aren't.
+{{#concept "Parity" WD="parity" WDID=Q141160}}
+[partitions](foundation.partitions.md) the [natural
+numbers](elementary-number-theory.natural numbers.md) into two
+[classes](foundation.equivalence-relations.md): the
+{{#concept "even" Disambiguation="natural number" Agda=is-even-ℕ WD="even number" WDID=Q13366104}}
+and the
+{{#concept "odd" Disambiguation="natural number" Agda=is-odd-ℕ WD="odd number" WDID=Q13366129}}
+natural numbers. Even natural numbers are those that are
+[divisible](elementary-number-theory.divisibility-natural numbers.md) by two,
+and odd natural numbers are those that aren't.
## Definition
+### Even natural numbers
+
```agda
-is-even-ℕ : ℕ → UU lzero
-is-even-ℕ n = div-ℕ 2 n
+is-even-ℕ :
+ ℕ → UU lzero
+is-even-ℕ n =
+ div-ℕ 2 n
+
+quotient-is-even-ℕ :
+ (n : ℕ) → is-even-ℕ n → ℕ
+quotient-is-even-ℕ =
+ quotient-div-ℕ 2
+
+upper-bound-quotient-is-even-ℕ :
+ (n : ℕ) (H : is-even-ℕ n) → quotient-is-even-ℕ n H ≤-ℕ n
+upper-bound-quotient-is-even-ℕ =
+ upper-bound-quotient-div-ℕ 2
+
+eq-quotient-is-even-ℕ :
+ (n : ℕ) (H : is-even-ℕ n) → quotient-is-even-ℕ n H *ℕ 2 = n
+eq-quotient-is-even-ℕ =
+ eq-quotient-div-ℕ 2
+
+eq-quotient-is-even-ℕ' :
+ (n : ℕ) (H : is-even-ℕ n) → 2 *ℕ quotient-is-even-ℕ n H = n
+eq-quotient-is-even-ℕ' =
+ eq-quotient-div-ℕ' 2
+```
+
+### The sequence of even numbers
-is-odd-ℕ : ℕ → UU lzero
-is-odd-ℕ n = ¬ (is-even-ℕ n)
+```agda
+even-number-ℕ :
+ ℕ → ℕ
+even-number-ℕ n =
+ 2 *ℕ n
+```
+
+### Odd natural numbers
+
+```agda
+is-odd-ℕ :
+ ℕ → UU lzero
+is-odd-ℕ n =
+ ¬ (is-even-ℕ n)
+```
+
+### The sequence of odd numbers
+
+```agda
+odd-number-ℕ :
+ ℕ → ℕ
+odd-number-ℕ n =
+ succ-ℕ (2 *ℕ n)
+```
+
+### The predicate of having an odd expansion
+
+```agda
+has-odd-expansion-ℕ : ℕ → UU lzero
+has-odd-expansion-ℕ n = fiber odd-number-ℕ n
```
## Properties
+### The $n+1$st even number
+
+```agda
+even-number-succ-ℕ :
+ (n : ℕ) → even-number-ℕ (succ-ℕ n) = even-number-ℕ n +ℕ 2
+even-number-succ-ℕ n = left-distributive-mul-add-ℕ 2 n 1
+```
+
+### The $n+1$st odd number
+
+```agda
+odd-number-succ-ℕ :
+ (n : ℕ) → odd-number-ℕ (succ-ℕ n) = 2 *ℕ n +ℕ 3
+odd-number-succ-ℕ n =
+ ap succ-ℕ (even-number-succ-ℕ n)
+```
+
+### The $n$th even number is even
+
+```agda
+is-even-even-number-ℕ :
+ (n : ℕ) → is-even-ℕ (even-number-ℕ n)
+pr1 (is-even-even-number-ℕ n) = n
+pr2 (is-even-even-number-ℕ n) = commutative-mul-ℕ n 2
+```
+
+### The even number function is injective
+
+```agda
+is-injective-even-number-ℕ :
+ is-injective even-number-ℕ
+is-injective-even-number-ℕ =
+ is-injective-left-mul-ℕ 2 (is-nonzero-succ-ℕ 1)
+```
+
+### The odd number function is injective
+
+```agda
+is-injective-odd-number-ℕ :
+ is-injective odd-number-ℕ
+is-injective-odd-number-ℕ =
+ is-injective-comp is-injective-even-number-ℕ is-injective-succ-ℕ
+```
+
+### Even natural numbers are closed under equality
+
+```agda
+is-even-eq-ℕ : {m n : ℕ} → m = n → is-even-ℕ n → is-even-ℕ m
+is-even-eq-ℕ refl H = H
+
+is-even-eq-ℕ' : {m n : ℕ} → m = n → is-even-ℕ m → is-even-ℕ n
+is-even-eq-ℕ' refl H = H
+```
+
+### Odd natural numbers are closed under equality
+
+```agda
+is-odd-eq-ℕ : {m n : ℕ} → m = n → is-odd-ℕ n → is-odd-ℕ m
+is-odd-eq-ℕ refl H = H
+
+is-odd-eq-ℕ' : {m n : ℕ} → m = n → is-odd-ℕ m → is-odd-ℕ n
+is-odd-eq-ℕ' refl H = H
+```
+
### Being even or odd is decidable
```agda
@@ -53,12 +195,27 @@ is-decidable-is-odd-ℕ : (x : ℕ) → is-decidable (is-odd-ℕ x)
is-decidable-is-odd-ℕ x = is-decidable-neg (is-decidable-is-even-ℕ x)
```
+### A number is even if and only if it is not odd
+
+```agda
+is-even-is-not-odd-ℕ : (x : ℕ) → ¬ (is-odd-ℕ x) → is-even-ℕ x
+is-even-is-not-odd-ℕ x =
+ double-negation-elim-is-decidable (is-decidable-is-even-ℕ x)
+
+is-not-odd-is-even-ℕ : (x : ℕ) → is-even-ℕ x → ¬ (is-odd-ℕ x)
+is-not-odd-is-even-ℕ x = intro-double-negation
+```
+
### `0` is an even natural number
```agda
is-even-zero-ℕ : is-even-ℕ 0
is-even-zero-ℕ = div-zero-ℕ 2
+```
+
+### `1` is an odd natural number
+```agda
is-odd-one-ℕ : is-odd-ℕ 1
is-odd-one-ℕ H = Eq-eq-ℕ (is-one-div-one-ℕ 2 H)
```
@@ -138,22 +295,370 @@ is-odd-is-even-succ-ℕ n p =
( is-odd-succ-is-even-ℕ (succ-ℕ n) p)
```
-### A natural number `x` is odd if and only if there is a natural number `y` such that `succ-ℕ (y *ℕ 2) = x`
+### A natural number is odd if and only if it has an odd expansion
```agda
-has-odd-expansion : ℕ → UU lzero
-has-odd-expansion x = Σ ℕ (λ y → (succ-ℕ (y *ℕ 2)) = x)
+is-odd-has-odd-expansion-ℕ : (n : ℕ) → has-odd-expansion-ℕ n → is-odd-ℕ n
+is-odd-has-odd-expansion-ℕ .(succ-ℕ (2 *ℕ m)) (m , refl) =
+ is-odd-succ-is-even-ℕ (2 *ℕ m) (m , commutative-mul-ℕ m 2)
+
+has-odd-expansion-is-odd-ℕ : (n : ℕ) → is-odd-ℕ n → has-odd-expansion-ℕ n
+has-odd-expansion-is-odd-ℕ zero-ℕ p = ex-falso (p is-even-zero-ℕ)
+has-odd-expansion-is-odd-ℕ (succ-ℕ zero-ℕ) p = (0 , refl)
+has-odd-expansion-is-odd-ℕ (succ-ℕ (succ-ℕ n)) p =
+ ( succ-ℕ (pr1 s)) ,
+ ap (succ-ℕ ∘ succ-ℕ) (left-successor-law-add-ℕ _ _ ∙ pr2 s)
+ where
+ s : has-odd-expansion-ℕ n
+ s = has-odd-expansion-is-odd-ℕ n (is-odd-is-odd-succ-succ-ℕ n p)
-is-odd-has-odd-expansion : (n : ℕ) → has-odd-expansion n → is-odd-ℕ n
-is-odd-has-odd-expansion .(succ-ℕ (m *ℕ 2)) (m , refl) =
- is-odd-succ-is-even-ℕ (m *ℕ 2) (m , refl)
+is-odd-odd-number-ℕ : (n : ℕ) → is-odd-ℕ (odd-number-ℕ n)
+is-odd-odd-number-ℕ n = is-odd-has-odd-expansion-ℕ (odd-number-ℕ n) (n , refl)
+```
-has-odd-expansion-is-odd : (n : ℕ) → is-odd-ℕ n → has-odd-expansion n
-has-odd-expansion-is-odd zero-ℕ p = ex-falso (p is-even-zero-ℕ)
-has-odd-expansion-is-odd (succ-ℕ zero-ℕ) p = 0 , refl
-has-odd-expansion-is-odd (succ-ℕ (succ-ℕ n)) p =
- ( succ-ℕ (pr1 s)) , ap (succ-ℕ ∘ succ-ℕ) (pr2 s)
- where
- s : has-odd-expansion n
- s = has-odd-expansion-is-odd n (is-odd-is-odd-succ-succ-ℕ n p)
+### A number is even if and only if it is divisible by an even number
+
+```agda
+is-even-div-is-even-ℕ :
+ (m n : ℕ) → is-even-ℕ m → div-ℕ m n → is-even-ℕ n
+is-even-div-is-even-ℕ ._ ._ (m' , refl) (k , refl) =
+ k *ℕ m' , associative-mul-ℕ k m' 2
+
+is-even-div-4-ℕ :
+ (n : ℕ) → div-ℕ 4 n → is-even-ℕ n
+is-even-div-4-ℕ n = is-even-div-is-even-ℕ 4 n (2 , refl)
+```
+
+### Any divisor of an odd number is odd
+
+```agda
+is-odd-div-is-odd-ℕ :
+ (m n : ℕ) → is-odd-ℕ n → div-ℕ m n → is-odd-ℕ m
+is-odd-div-is-odd-ℕ m n H K L =
+ H (is-even-div-is-even-ℕ m n L K)
+```
+
+### Any odd divisor of `2` is equal to `1`
+
+```agda
+is-one-is-odd-div-two-ℕ :
+ (n : ℕ) → div-ℕ n 2 → is-odd-ℕ n → is-one-ℕ n
+is-one-is-odd-div-two-ℕ n H K =
+ is-one-is-proper-divisor-two-ℕ n
+ ( ( neq-neg-div-ℕ 2 n K ∘ inv) ,
+ ( H))
+```
+
+### A number is even if and only if it is congruent to `0` modulo `2`
+
+```agda
+is-0-mod-2-is-even-ℕ :
+ (n : ℕ) → is-even-ℕ n → n ≡ 0 mod-ℕ 2
+is-0-mod-2-is-even-ℕ =
+ cong-zero-div-ℕ 2
+
+is-even-is-0-mod-2-ℕ :
+ (n : ℕ) → n ≡ 0 mod-ℕ 2 → is-even-ℕ n
+is-even-is-0-mod-2-ℕ =
+ div-cong-zero-ℕ 2
+```
+
+### A natural number is odd if and only if it is congruent to `1` modulo `2`
+
+```agda
+is-1-mod-2-has-odd-expansion-ℕ :
+ (n : ℕ) → has-odd-expansion-ℕ n → n ≡ 1 mod-ℕ 2
+is-1-mod-2-has-odd-expansion-ℕ ._ (k , refl) =
+ translation-invariant-cong-ℕ' 2
+ ( 2 *ℕ k)
+ ( 0)
+ ( 1)
+ ( is-0-mod-2-is-even-ℕ
+ ( 2 *ℕ k)
+ ( is-even-even-number-ℕ k ))
+
+is-1-mod-2-is-odd-ℕ :
+ (n : ℕ) → is-odd-ℕ n → n ≡ 1 mod-ℕ 2
+is-1-mod-2-is-odd-ℕ n H =
+ is-1-mod-2-has-odd-expansion-ℕ n (has-odd-expansion-is-odd-ℕ n H)
+
+is-odd-is-1-mod-2-ℕ :
+ (n : ℕ) → n ≡ 1 mod-ℕ 2 → is-odd-ℕ n
+is-odd-is-1-mod-2-ℕ zero-ℕ H K =
+ is-not-one-two-ℕ (is-one-div-one-ℕ 2 H)
+is-odd-is-1-mod-2-ℕ (succ-ℕ n) H K =
+ is-odd-one-ℕ
+ ( div-right-summand-ℕ 2 n 1 (tr (div-ℕ 2) (right-unit-law-dist-ℕ n) H) K)
+```
+
+### If a successor number `n + 1` is even, then its quotient after division by `2` is at most `n`
+
+**Proof.** Suppose that `q * 2 = n + 1` for some natural number `q`. Then `q`
+is a successor, say `q = q' + 1`. It follows that
+
+```text
+ q + 1 ≤ q + q' + 1 = q + q = q * 2 = n + 1.
+```
+
+This implies that `q ≤ n`.
+
+```agda
+upper-bound-quotient-bounded-div-two-succ-ℕ :
+ (n : ℕ) (H : bounded-div-ℕ 2 (succ-ℕ n)) →
+ quotient-bounded-div-ℕ 2 (succ-ℕ n) H ≤-ℕ n
+upper-bound-quotient-bounded-div-two-succ-ℕ n (succ-ℕ q , H , p) =
+ concatenate-leq-eq-ℕ
+ ( succ-ℕ (succ-ℕ q))
+ ( preserves-order-right-add-ℕ (succ-ℕ q) 1 (succ-ℕ q) star)
+ ( inv (right-two-law-mul-ℕ (succ-ℕ q)) ∙ p)
+
+upper-bound-quotient-is-even-succ-ℕ :
+ (n : ℕ) (H : is-even-ℕ (succ-ℕ n)) →
+ quotient-is-even-ℕ (succ-ℕ n) H ≤-ℕ n
+upper-bound-quotient-is-even-succ-ℕ n H =
+ upper-bound-quotient-bounded-div-two-succ-ℕ n
+ ( bounded-div-div-ℕ 2 (succ-ℕ n) H)
+```
+
+### If any two out of `x`, `y`, and `x + y` are even, then so is the third
+
+```agda
+is-even-add-ℕ :
+ (m n : ℕ) → is-even-ℕ m → is-even-ℕ n → is-even-ℕ (add-ℕ m n)
+is-even-add-ℕ = div-add-ℕ 2
+
+is-even-left-summand-ℕ :
+ (m n : ℕ) → is-even-ℕ n → is-even-ℕ (add-ℕ m n) → is-even-ℕ m
+is-even-left-summand-ℕ = div-left-summand-ℕ 2
+
+is-even-right-summand-ℕ :
+ (m n : ℕ) → is-even-ℕ m → is-even-ℕ (add-ℕ m n) → is-even-ℕ n
+is-even-right-summand-ℕ = div-right-summand-ℕ 2
+```
+
+### If any two out of `x`, `y`, and `x + y` are odd, then the third number is even
+
+```agda
+is-even-add-is-odd-ℕ :
+ (m n : ℕ) → is-odd-ℕ m → is-odd-ℕ n → is-even-ℕ (m +ℕ n)
+is-even-add-is-odd-ℕ m zero-ℕ H K = ex-falso (K is-even-zero-ℕ)
+is-even-add-is-odd-ℕ m (succ-ℕ zero-ℕ) H K =
+ is-even-succ-is-odd-ℕ m H
+is-even-add-is-odd-ℕ m (succ-ℕ (succ-ℕ n)) H K =
+ is-even-succ-succ-is-even-ℕ
+ ( add-ℕ m n)
+ ( is-even-add-is-odd-ℕ m n H (is-odd-is-odd-succ-succ-ℕ n K))
+
+is-even-left-summand-is-odd-ℕ :
+ (m n : ℕ) → is-odd-ℕ n → is-odd-ℕ (m +ℕ n) → is-even-ℕ m
+is-even-left-summand-is-odd-ℕ m zero-ℕ H K = ex-falso (H is-even-zero-ℕ)
+is-even-left-summand-is-odd-ℕ m (succ-ℕ zero-ℕ) H K =
+ is-even-is-odd-succ-ℕ m K
+is-even-left-summand-is-odd-ℕ m (succ-ℕ (succ-ℕ n)) H K =
+ is-even-left-summand-is-odd-ℕ m n
+ ( is-odd-is-odd-succ-succ-ℕ n H)
+ ( is-odd-is-odd-succ-succ-ℕ (m +ℕ n) K)
+
+is-even-right-summand-is-odd-ℕ :
+ (m n : ℕ) → is-odd-ℕ m → is-odd-ℕ (m +ℕ n) → is-even-ℕ n
+is-even-right-summand-is-odd-ℕ m zero-ℕ H K = is-even-zero-ℕ
+is-even-right-summand-is-odd-ℕ m (succ-ℕ zero-ℕ) H K =
+ ex-falso (K (is-even-succ-is-odd-ℕ m H))
+is-even-right-summand-is-odd-ℕ m (succ-ℕ (succ-ℕ n)) H K =
+ is-even-succ-succ-is-even-ℕ n
+ ( is-even-right-summand-is-odd-ℕ m n H
+ ( is-odd-is-odd-succ-succ-ℕ (m +ℕ n) K))
+```
+
+### If one of the summands is even and the other is odd, then the sum is odd
+
+```agda
+is-odd-add-is-odd-left-summand-ℕ :
+ (m n : ℕ) → is-odd-ℕ m → is-even-ℕ n → is-odd-ℕ (m +ℕ n)
+is-odd-add-is-odd-left-summand-ℕ m n H K L =
+ H (is-even-left-summand-ℕ m n K L)
+
+is-odd-add-is-odd-right-summand-ℕ :
+ (m n : ℕ) → is-even-ℕ m → is-odd-ℕ n → is-odd-ℕ (m +ℕ n)
+is-odd-add-is-odd-right-summand-ℕ m n H K L =
+ K (is-even-right-summand-ℕ m n H L)
+```
+
+### Either `n` or `n + 1` is even
+
+```agda
+abstract
+ is-even-or-is-even-succ-ℕ :
+ (n : ℕ) → is-even-ℕ n + is-even-ℕ (succ-ℕ n)
+ is-even-or-is-even-succ-ℕ n
+ with
+ is-decidable-is-even-ℕ n
+ ... | inl H = inl H
+ ... | inr H = inr (is-even-succ-is-odd-ℕ n H)
```
+
+### Either `n` or `n + 1` is odd
+
+```agda
+abstract
+ is-odd-or-is-odd-succ-ℕ :
+ (n : ℕ) → is-odd-ℕ n + is-odd-ℕ (succ-ℕ n)
+ is-odd-or-is-odd-succ-ℕ n
+ with
+ is-decidable-is-odd-ℕ n
+ ... | inl H = inl H
+ ... | inr H = inr (is-odd-succ-is-even-ℕ n (is-even-is-not-odd-ℕ n H))
+```
+
+### The sum `n + n` is even
+
+```agda
+is-even-add-self-ℕ : (n : ℕ) → is-even-ℕ (n +ℕ n)
+is-even-add-self-ℕ n = (n , right-two-law-mul-ℕ n)
+```
+
+### The sum `n + (n + 1)` is odd
+
+```agda
+is-odd-add-succ-self-ℕ :
+ (n : ℕ) → is-odd-ℕ (n +ℕ succ-ℕ n)
+is-odd-add-succ-self-ℕ n =
+ is-odd-succ-is-even-ℕ (n +ℕ n) (is-even-add-self-ℕ n)
+```
+
+### Odd numbers are nonzero
+
+```agda
+is-nonzero-odd-number-ℕ :
+ (n : ℕ) → is-nonzero-ℕ (odd-number-ℕ n)
+is-nonzero-odd-number-ℕ n = is-nonzero-succ-ℕ (2 *ℕ n)
+
+is-nonzero-is-odd-ℕ :
+ (n : ℕ) → is-odd-ℕ n → is-nonzero-ℕ n
+is-nonzero-is-odd-ℕ .zero-ℕ H refl = H is-even-zero-ℕ
+```
+
+### A product $mn$ is odd if and only if both factors are odd
+
+```agda
+has-odd-expansion-mul-odd-number-ℕ :
+ (k l : ℕ) → has-odd-expansion-ℕ (odd-number-ℕ k *ℕ odd-number-ℕ l)
+pr1 (has-odd-expansion-mul-odd-number-ℕ k l) =
+ 2 *ℕ (k *ℕ l) +ℕ k +ℕ l
+pr2 (has-odd-expansion-mul-odd-number-ℕ k l) =
+ ( ap
+ ( succ-ℕ)
+ ( ( left-distributive-mul-add-ℕ 2 (2 *ℕ (k *ℕ l) +ℕ k) l) ∙
+ ( ap-add-ℕ
+ ( ( left-distributive-mul-add-ℕ 2 (2 *ℕ (k *ℕ l)) k) ∙
+ ( ap-add-ℕ
+ ( ap (2 *ℕ_) (left-swap-mul-ℕ 2 k l) ∙
+ inv (associative-mul-ℕ 2 k (2 *ℕ l)))
+ ( inv (right-unit-law-mul-ℕ (2 *ℕ k)))))
+ ( inv (left-unit-law-mul-ℕ (2 *ℕ l)))))) ∙
+ ( inv (double-distributive-mul-add-ℕ (2 *ℕ k) 1 (2 *ℕ l) 1))
+
+has-odd-expansion-mul-has-odd-expansion-ℕ :
+ (m n : ℕ) → has-odd-expansion-ℕ m → has-odd-expansion-ℕ n →
+ has-odd-expansion-ℕ (m *ℕ n)
+has-odd-expansion-mul-has-odd-expansion-ℕ m n (k , refl) (l , refl) =
+ has-odd-expansion-mul-odd-number-ℕ k l
+
+is-odd-mul-is-odd-ℕ :
+ (m n : ℕ) → is-odd-ℕ m → is-odd-ℕ n → is-odd-ℕ (m *ℕ n)
+is-odd-mul-is-odd-ℕ m n H K =
+ is-odd-has-odd-expansion-ℕ
+ ( m *ℕ n)
+ ( has-odd-expansion-mul-has-odd-expansion-ℕ m n
+ ( has-odd-expansion-is-odd-ℕ m H)
+ ( has-odd-expansion-is-odd-ℕ n K))
+
+is-odd-left-factor-is-odd-mul-ℕ :
+ (m n : ℕ) → is-odd-ℕ (m *ℕ n) → is-odd-ℕ m
+is-odd-left-factor-is-odd-mul-ℕ m n H K =
+ H (is-even-div-is-even-ℕ m (m *ℕ n) K (n , commutative-mul-ℕ n m))
+
+is-odd-right-factor-is-odd-mul-ℕ :
+ (m n : ℕ) → is-odd-ℕ (m *ℕ n) → is-odd-ℕ n
+is-odd-right-factor-is-odd-mul-ℕ m n H K =
+ H (is-even-div-is-even-ℕ n (m *ℕ n) K (m , refl))
+```
+
+### If a product $mn$ is even and one of the factors is odd, then the other is even
+
+```agda
+is-even-left-factor-is-even-mul-ℕ :
+ (m n : ℕ) → is-even-ℕ (m *ℕ n) → is-odd-ℕ n → is-even-ℕ m
+is-even-left-factor-is-even-mul-ℕ m n H K =
+ is-even-is-not-odd-ℕ m (λ L → is-odd-mul-is-odd-ℕ m n L K H)
+
+is-even-right-factor-is-even-mul-ℕ :
+ (m n : ℕ) → is-even-ℕ (m *ℕ n) → is-odd-ℕ m → is-even-ℕ n
+is-even-right-factor-is-even-mul-ℕ m n H K =
+ is-even-is-not-odd-ℕ n (λ L → is-odd-mul-is-odd-ℕ m n K L H)
+```
+
+### If a power of $2$ divides $mn$ and one of the factors is odd, then the other is divisible by the power of $2$
+
+The proof is by induction, and the base case is trivial. For the inductive step, assume that $2^{k+1} \mid mn$. Then the product $mn$ is even, and therefore $m$ is even. Let $m' := m/2$. Now it follows that $2^k \mid m'n$. By the inductive hypothesis, we conclude that $2^k \mid m'$, which is xequivalent to $2^{k+1} \mid m$.
+
+**Note.** This result should eventually be formalized as an instance of the following lemma: If $a \mid bc$ and $\gcd(a,c)=1$, then $a\mid b$.
+
+```agda
+div-exp-2-left-factor-div-exp-2-mul-ℕ :
+ (k m n : ℕ) → div-ℕ (2 ^ℕ k) (m *ℕ n) → is-odd-ℕ n → div-ℕ (2 ^ℕ k) m
+div-exp-2-left-factor-div-exp-2-mul-ℕ zero-ℕ m n H K =
+ div-one-ℕ m
+div-exp-2-left-factor-div-exp-2-mul-ℕ (succ-ℕ k) m n H K =
+ concatenate-eq-div-ℕ
+ ( exp-succ-ℕ' 2 k)
+ ( div-div-quotient-div-ℕ'
+ ( 2 ^ℕ k)
+ ( m)
+ ( 2)
+ ( is-even-left-factor-is-even-mul-ℕ m n
+ ( is-even-div-is-even-ℕ
+ ( 2 ^ℕ succ-ℕ k)
+ ( m *ℕ n)
+ ( 2 ^ℕ k , inv (exp-succ-ℕ 2 k))
+ ( H))
+ ( K))
+ ( λ L →
+ div-exp-2-left-factor-div-exp-2-mul-ℕ k
+ ( quotient-div-ℕ 2 m L)
+ ( n)
+ ( concatenate-div-eq-ℕ
+ ( div-quotient-div-div-ℕ
+ ( 2 ^ℕ k)
+ ( m *ℕ n)
+ ( 2)
+ ( is-even-div-is-even-ℕ
+ ( 2 ^ℕ succ-ℕ k)
+ ( m *ℕ n)
+ ( div-exp-ℕ 2 (succ-ℕ k) (is-nonzero-succ-ℕ k))
+ ( H))
+ ( concatenate-eq-div-ℕ (inv (exp-succ-ℕ' 2 k)) H))
+ ( compute-quotient-div-mul-ℕ' n 2 m L
+ ( is-even-div-is-even-ℕ
+ ( 2 ^ℕ succ-ℕ k)
+ ( m *ℕ n)
+ ( div-exp-ℕ 2 (succ-ℕ k) (is-nonzero-succ-ℕ k))
+ ( H))))
+ ( K)))
+
+div-exp-2-right-factor-div-exp-2-mul-ℕ :
+ (k m n : ℕ) → div-ℕ (2 ^ℕ k) (m *ℕ n) → is-odd-ℕ m → div-ℕ (2 ^ℕ k) n
+div-exp-2-right-factor-div-exp-2-mul-ℕ k m n H =
+ div-exp-2-left-factor-div-exp-2-mul-ℕ k n m
+ ( concatenate-div-eq-ℕ H (commutative-mul-ℕ m n))
+```
+
+## See also
+
+Further laws of parity are proven in other files, e.g.:
+
+- [Parity of integers](elementary-number-theory.parity-integers.md)
+- [Squares of natural numbers](elementary-number-theory.squares-natural-numbers.md).
+ Here we also show that the sum of the first $n$ odd numbers is $n^2$.
+- The fact that the pronic numbers $n(n+1)$ are even is proven in
+ [Pronic numbers](elementary-number-theory.pronic-numbers.md).
diff --git a/src/elementary-number-theory/pell-numbers.lagda.md b/src/elementary-number-theory/pell-numbers.lagda.md
new file mode 100644
index 0000000000..7affdda926
--- /dev/null
+++ b/src/elementary-number-theory/pell-numbers.lagda.md
@@ -0,0 +1,51 @@
+# Pell numbers
+
+```agda
+module elementary-number-theory.pell-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+```
+
+
+
+## Idea
+
+The $n$th {{#concept "Pell number" Agda=pell-number-ℕ OEIS=A0000129 WDID=Q1386491 WD="Pell number"}} is the number $P(n)$, which are defined recursively by
+
+```text
+ P 0 := 0
+ P 1 := 1
+ P (n + 2) := 2 · P (n + 1) + P n.
+```
+
+The first few Pell numbers are
+
+```text
+ index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
+ -------------+------+------+------+------+------+------+------+------+------+
+ Pell number | 0 | 1 | 2 | 5 | 12 | 29 | 70 | 169 | 408 |
+```
+
+The sequence of Pell numbers is listed as A0000129 in the [OEIS](literature.oeis.md) {{#cite oeis}}. Any two consecutive Pell numbers are [relatively prime](elementary-number-theory.relatively-prime-natural-numbers.md).
+
+## Definitions
+
+### The Pell numbers
+
+```agda
+pell-number-ℕ : ℕ → ℕ
+pell-number-ℕ zero-ℕ = 0
+pell-number-ℕ (succ-ℕ zero-ℕ) = 1
+pell-number-ℕ (succ-ℕ (succ-ℕ n)) =
+ 2 *ℕ pell-number-ℕ (succ-ℕ n) +ℕ pell-number-ℕ n
+```
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/pisano-periods.lagda.md b/src/elementary-number-theory/pisano-periods.lagda.md
index f765a59fb3..e6720052f1 100644
--- a/src/elementary-number-theory/pisano-periods.lagda.md
+++ b/src/elementary-number-theory/pisano-periods.lagda.md
@@ -11,6 +11,7 @@ open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.fibonacci-sequence
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.lower-bounds-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
open import elementary-number-theory.modular-arithmetic-standard-finite-types
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
@@ -108,7 +109,7 @@ compute-fibonacci-pair-Fin :
(k : ℕ) (n : ℕ) →
Id
( fibonacci-pair-Fin k n)
- ( mod-succ-ℕ k (Fibonacci-ℕ n) , mod-succ-ℕ k (Fibonacci-ℕ (succ-ℕ n)))
+ ( mod-succ-ℕ k (fibonacci-ℕ n) , mod-succ-ℕ k (fibonacci-ℕ (succ-ℕ n)))
compute-fibonacci-pair-Fin k zero-ℕ = refl
compute-fibonacci-pair-Fin k (succ-ℕ zero-ℕ) =
ap-binary pair refl (right-unit-law-add-Fin k (one-Fin k))
@@ -121,8 +122,8 @@ compute-fibonacci-pair-Fin k (succ-ℕ (succ-ℕ n)) =
( ap pr1 (compute-fibonacci-pair-Fin k (succ-ℕ n)))) ∙
( inv
( mod-succ-add-ℕ k
- ( Fibonacci-ℕ (succ-ℕ (succ-ℕ n)))
- ( Fibonacci-ℕ (succ-ℕ n)))))
+ ( fibonacci-ℕ (succ-ℕ (succ-ℕ n)))
+ ( fibonacci-ℕ (succ-ℕ n)))))
```
### Repetitions in the Fibonacci sequence on `Fin (k + 1) × Fin (k + 1)`
@@ -173,6 +174,9 @@ cases-is-repetition-of-zero-pisano-period k zero-ℕ y p q = refl
cases-is-repetition-of-zero-pisano-period k (succ-ℕ x) zero-ℕ p q =
ex-falso
( concatenate-eq-le-eq-ℕ
+ ( succ-ℕ x)
+ ( pr1 (is-ordered-repetition-pisano-period k))
+ ( pisano-period k) zero-ℕ
( inv p)
( pr1 (pr2 (is-ordered-repetition-pisano-period k)))
( q))
@@ -184,6 +188,10 @@ cases-is-repetition-of-zero-pisano-period k (succ-ℕ x) (succ-ℕ y) p q =
R : is-ordered-repetition-fibonacci-pair-Fin k y
R = triple x
( concatenate-eq-le-eq-ℕ
+ ( succ-ℕ x)
+ ( pr1 (is-ordered-repetition-pisano-period k))
+ ( pisano-period k)
+ ( succ-ℕ y)
( inv p)
( pr1 (pr2 (is-ordered-repetition-pisano-period k)))
( q))
@@ -219,26 +227,27 @@ le-zero-pisano-period :
(k : ℕ) → le-ℕ zero-ℕ (pisano-period k)
le-zero-pisano-period k =
concatenate-eq-le-ℕ
- { x = zero-ℕ}
- { y = pr1 (is-ordered-repetition-pisano-period k)}
- { z = pisano-period k}
+ ( zero-ℕ)
+ ( pr1 (is-ordered-repetition-pisano-period k))
+ ( pisano-period k)
( inv (is-repetition-of-zero-pisano-period k))
( pr1 (pr2 (is-ordered-repetition-pisano-period k)))
is-nonzero-pisano-period :
(k : ℕ) → is-nonzero-ℕ (pisano-period k)
is-nonzero-pisano-period k p =
- ex-falso (concatenate-le-eq-ℕ (le-zero-pisano-period k) p)
+ ex-falso
+ ( concatenate-le-eq-ℕ 0 (pisano-period k) 0 (le-zero-pisano-period k) p)
```
### `k + 1` divides the Fibonacci number at `pisano-period k`
```agda
div-fibonacci-pisano-period :
- (k : ℕ) → div-ℕ (succ-ℕ k) (Fibonacci-ℕ (pisano-period k))
+ (k : ℕ) → div-ℕ (succ-ℕ k) (fibonacci-ℕ (pisano-period k))
div-fibonacci-pisano-period k =
div-is-zero-mod-succ-ℕ k
- ( Fibonacci-ℕ (pisano-period k))
+ ( fibonacci-ℕ (pisano-period k))
( ( ap pr1 (inv (compute-fibonacci-pair-Fin k (pisano-period k)))) ∙
( inv
( ap pr1
diff --git a/src/elementary-number-theory/poset-of-natural-numbers-ordered-by-divisibility.lagda.md b/src/elementary-number-theory/poset-of-natural-numbers-ordered-by-divisibility.lagda.md
index 4977a5e18b..9f6af0c203 100644
--- a/src/elementary-number-theory/poset-of-natural-numbers-ordered-by-divisibility.lagda.md
+++ b/src/elementary-number-theory/poset-of-natural-numbers-ordered-by-divisibility.lagda.md
@@ -9,6 +9,7 @@ module
Imports
```agda
+open import elementary-number-theory.bounded-divisibility-natural-numbers
open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
@@ -32,50 +33,39 @@ open import order-theory.preorders
The **poset of natural numbers ordered by divisibility** consists of the
[natural numbers](elementary-number-theory.natural-numbers.md) and its ordering
-is defined by `m ≤ n := m | n`, i.e., by
-[divisibility](elementary-number-theory.divisibility-natural-numbers.md).
-
-The divisibility relation `m | n` on the natural numbers, however, is only
-valued in the [propositions](foundation.propositions.md) when both `m` and `n`
-are [nonzero](elementary-number-theory.nonzero-natural-numbers.md). We therefore
-redefine the divisibility relation in the following way: A number `m` is said to
-**divide** a number `n` if there
-[merely exists](foundation.existential-quantification.md) a number `k` such that
-`km = n`. Since mere existence is defined via the
-[propoositional truncation](foundation.propositional-truncations.md), this can
-be stated alternatively as the proposition
-
-```text
- trunc-Prop (div-ℕ m n).
-```
-
-In other words, we simply force the divisibility relation to take values in
-propositions by identifying all witnesses of divisibility.
+is defined by
+[bounded divisibility](elementary-number-theory.bounded-divisibility-natural-numbers.md),
+i.e., the type `m ≤ n` is defined to be the type of natural numbers `q ≤ n` such
+that `q * m = n`.
+
+Recall that bounded divisibility is
+[logically equivalent](foundation.logical-equivalences.md) to the more standard
+[divisibility relation](elementar-number-theory.divisibility-natural-numbers.md).
+However, the divisibility relation `m | n` is only valued in the
+[propositions](foundation.propositions.md) when both `m` and `n` are
+[nonzero](elementary-number-theory.nonzero-natural-numbers.md). On the other
+hand, bounded divisibility is always valued in propositions. By using bounded
+divisibility we avoid the need for
+[propoositional truncation](foundation.propositional-truncations.md).
## Definition
```agda
leq-prop-ℕ-Div : ℕ → ℕ → Prop lzero
-leq-prop-ℕ-Div m n = trunc-Prop (div-ℕ m n)
+leq-prop-ℕ-Div = bounded-div-ℕ-Prop
leq-ℕ-Div : ℕ → ℕ → UU lzero
leq-ℕ-Div m n = type-Prop (leq-prop-ℕ-Div m n)
refl-leq-ℕ-Div : (n : ℕ) → leq-ℕ-Div n n
-refl-leq-ℕ-Div n = unit-trunc-Prop (refl-div-ℕ n)
+refl-leq-ℕ-Div = refl-bounded-div-ℕ
antisymmetric-leq-ℕ-Div : (m n : ℕ) → leq-ℕ-Div m n → leq-ℕ-Div n m → m = n
-antisymmetric-leq-ℕ-Div m n H K =
- apply-twice-universal-property-trunc-Prop H K
- ( Id-Prop ℕ-Set _ _)
- ( antisymmetric-div-ℕ m n)
+antisymmetric-leq-ℕ-Div = antisymmetric-bounded-div-ℕ
transitive-leq-ℕ-Div :
(m n o : ℕ) → leq-ℕ-Div n o → leq-ℕ-Div m n → leq-ℕ-Div m o
-transitive-leq-ℕ-Div m n o H K =
- apply-twice-universal-property-trunc-Prop H K
- ( leq-prop-ℕ-Div m o)
- ( λ H' K' → unit-trunc-Prop (transitive-div-ℕ m n o H' K'))
+transitive-leq-ℕ-Div = transitive-bounded-div-ℕ
ℕ-Div-Preorder : Preorder lzero lzero
pr1 ℕ-Div-Preorder = ℕ
diff --git a/src/elementary-number-theory/positive-and-negative-integers.lagda.md b/src/elementary-number-theory/positive-and-negative-integers.lagda.md
index 844b95a8b8..5080475c92 100644
--- a/src/elementary-number-theory/positive-and-negative-integers.lagda.md
+++ b/src/elementary-number-theory/positive-and-negative-integers.lagda.md
@@ -172,7 +172,7 @@ is-nonpositive-neg-is-nonnegative-ℤ {inr (inl x)} H = H
is-nonpositive-neg-is-nonnegative-ℤ {inr (inr x)} H = H
neg-nonnegative-ℤ : nonnegative-ℤ → nonpositive-ℤ
-neg-nonnegative-ℤ (x , H) = neg-ℤ x , is-nonpositive-neg-is-nonnegative-ℤ H
+neg-nonnegative-ℤ (x , H) = (neg-ℤ x , is-nonpositive-neg-is-nonnegative-ℤ H)
```
#### The negative of a nonpositive integer is nonnegative
diff --git a/src/elementary-number-theory/positive-integers.lagda.md b/src/elementary-number-theory/positive-integers.lagda.md
index 5ac772e16d..122af48408 100644
--- a/src/elementary-number-theory/positive-integers.lagda.md
+++ b/src/elementary-number-theory/positive-integers.lagda.md
@@ -131,6 +131,14 @@ positive-ℤ-Set : Set lzero
positive-ℤ-Set = positive-ℤ , is-set-positive-ℤ
```
+### Integers of the form `in-pos-ℤ n` are positive
+
+```agda
+is-positive-in-pos-ℤ :
+ (n : ℕ) → is-positive-ℤ (in-pos-ℤ n)
+is-positive-in-pos-ℤ n = star
+```
+
### The successor of a positive integer is positive
```agda
diff --git a/src/elementary-number-theory/powers-of-two.lagda.md b/src/elementary-number-theory/powers-of-two.lagda.md
deleted file mode 100644
index d856d60206..0000000000
--- a/src/elementary-number-theory/powers-of-two.lagda.md
+++ /dev/null
@@ -1,208 +0,0 @@
-# Powers of two
-
-```agda
-module elementary-number-theory.powers-of-two where
-```
-
-Imports
-
-```agda
-open import elementary-number-theory.addition-natural-numbers
-open import elementary-number-theory.divisibility-natural-numbers
-open import elementary-number-theory.exponentiation-natural-numbers
-open import elementary-number-theory.inequality-natural-numbers
-open import elementary-number-theory.multiplication-natural-numbers
-open import elementary-number-theory.natural-numbers
-open import elementary-number-theory.parity-natural-numbers
-open import elementary-number-theory.strong-induction-natural-numbers
-
-open import foundation.action-on-identifications-functions
-open import foundation.dependent-pair-types
-open import foundation.equality-cartesian-product-types
-open import foundation.function-types
-open import foundation.split-surjective-maps
-open import foundation.transport-along-identifications
-open import foundation.universe-levels
-
-open import foundation-core.cartesian-product-types
-open import foundation-core.coproduct-types
-open import foundation-core.empty-types
-open import foundation-core.equivalences
-open import foundation-core.identity-types
-open import foundation-core.injective-maps
-```
-
-
-
-## Idea
-
-Any natural number `x` can be written as `(2^u(2v-1))-1` for some pair of
-natural numbers `(u , v)`
-
-```agda
-pair-expansion : ℕ → UU lzero
-pair-expansion n =
- Σ (ℕ × ℕ)
- ( λ p →
- ( (exp-ℕ 2 (pr1 p)) *ℕ (succ-ℕ ((pr2 p) *ℕ 2))) =
- succ-ℕ n)
-
-is-nonzero-pair-expansion :
- (u v : ℕ) →
- is-nonzero-ℕ ((exp-ℕ 2 u) *ℕ (succ-ℕ (v *ℕ 2)))
-is-nonzero-pair-expansion u v =
- is-nonzero-mul-ℕ _ _
- ( is-nonzero-exp-ℕ 2 u is-nonzero-two-ℕ)
- ( is-nonzero-succ-ℕ _)
-
-abstract
- has-pair-expansion-is-even-or-odd :
- (n : ℕ) → is-even-ℕ n + is-odd-ℕ n → pair-expansion n
- has-pair-expansion-is-even-or-odd n =
- strong-ind-ℕ
- ( λ m → (is-even-ℕ m + is-odd-ℕ m) → (pair-expansion m))
- ( λ x → (0 , 0) , refl)
- ( λ k f →
- ( λ where
- ( inl x) →
- ( let s = has-odd-expansion-is-odd k (is-odd-is-even-succ-ℕ k x)
- in
- pair
- ( 0 , (succ-ℕ (pr1 s)))
- ( ( ap ((succ-ℕ ∘ succ-ℕ) ∘ succ-ℕ) (left-unit-law-add-ℕ _)) ∙
- ( ( ap (succ-ℕ ∘ succ-ℕ) (pr2 s)))))
- ( inr x) →
- ( let e : is-even-ℕ k
- e = is-even-is-odd-succ-ℕ k x
-
- t : (pr1 e) ≤-ℕ k
- t = leq-quotient-div-ℕ' 2 k is-nonzero-two-ℕ e
-
- s : (pair-expansion (pr1 e))
- s = f (pr1 e) t (is-decidable-is-even-ℕ (pr1 e))
- in
- pair
- ( succ-ℕ (pr1 (pr1 s)) , pr2 (pr1 s))
- ( ( ap
- ( _*ℕ (succ-ℕ ((pr2 (pr1 s)) *ℕ 2)))
- ( commutative-mul-ℕ (exp-ℕ 2 (pr1 (pr1 s))) 2)) ∙
- ( ( associative-mul-ℕ 2
- ( exp-ℕ 2 (pr1 (pr1 s)))
- ( succ-ℕ ((pr2 (pr1 s)) *ℕ 2))) ∙
- ( ( ap (2 *ℕ_) (pr2 s)) ∙
- ( ( ap succ-ℕ
- ( left-successor-law-add-ℕ (0 +ℕ (pr1 e)) (pr1 e))) ∙
- ( ( ap
- ( succ-ℕ ∘ succ-ℕ)
- ( ap (_+ℕ (pr1 e)) (left-unit-law-add-ℕ (pr1 e)))) ∙
- ( ( ap
- ( succ-ℕ ∘ succ-ℕ)
- ( inv (right-two-law-mul-ℕ (pr1 e)))) ∙
- ( ( ap (succ-ℕ ∘ succ-ℕ) (pr2 e))))))))))))
- ( n)
-
-has-pair-expansion : (n : ℕ) → pair-expansion n
-has-pair-expansion n =
- has-pair-expansion-is-even-or-odd n (is-decidable-is-even-ℕ n)
-```
-
-### If `(u , v)` and `(u' , v')` are the pairs corresponding the same number `x`, then `u = u'` and `v = v'`
-
-```agda
-is-pair-expansion-unique :
- (u u' v v' : ℕ) →
- ((exp-ℕ 2 u) *ℕ (succ-ℕ (v *ℕ 2))) =
- ((exp-ℕ 2 u') *ℕ (succ-ℕ (v' *ℕ 2))) →
- (u = u') × (v = v')
-is-pair-expansion-unique zero-ℕ zero-ℕ v v' p =
- ( pair refl
- ( is-injective-right-mul-ℕ 2 is-nonzero-two-ℕ
- ( is-injective-left-add-ℕ 0 (is-injective-succ-ℕ p))))
-is-pair-expansion-unique zero-ℕ (succ-ℕ u') v v' p =
- ex-falso (s t)
- where
- s : is-odd-ℕ (succ-ℕ (0 +ℕ (v *ℕ 2)))
- s = is-odd-has-odd-expansion _
- ( v , ap succ-ℕ (inv (left-unit-law-add-ℕ _)))
- t : is-even-ℕ (succ-ℕ (0 +ℕ (v *ℕ 2)))
- t = tr is-even-ℕ (inv p) (div-mul-ℕ' _ 2 _ ((exp-ℕ 2 u') , refl))
-is-pair-expansion-unique (succ-ℕ u) zero-ℕ v v' p =
- ex-falso (s t)
- where
- s : is-odd-ℕ (succ-ℕ (0 +ℕ (v' *ℕ 2)))
- s = is-odd-has-odd-expansion _
- ( v' , ap succ-ℕ (inv (left-unit-law-add-ℕ _)))
- t : is-even-ℕ (succ-ℕ (0 +ℕ (v' *ℕ 2)))
- t = tr is-even-ℕ p (div-mul-ℕ' _ 2 _ ((exp-ℕ 2 u) , refl))
-is-pair-expansion-unique (succ-ℕ u) (succ-ℕ u') v v' p =
- pu , pv
- where
- q :
- ((exp-ℕ 2 u) *ℕ (succ-ℕ (v *ℕ 2))) =
- ((exp-ℕ 2 u') *ℕ (succ-ℕ (v' *ℕ 2)))
- q = is-injective-left-mul-ℕ 2 is-nonzero-two-ℕ
- ( inv (associative-mul-ℕ 2 (exp-ℕ 2 u) (succ-ℕ (v *ℕ 2))) ∙
- ( ( ap (_*ℕ (succ-ℕ (v *ℕ 2)))
- ( commutative-mul-ℕ 2 (exp-ℕ 2 u))) ∙
- ( ( p) ∙
- ( ( ap (_*ℕ (succ-ℕ (v' *ℕ 2)))
- ( commutative-mul-ℕ (exp-ℕ 2 u') 2)) ∙
- ( associative-mul-ℕ 2 (exp-ℕ 2 u') (succ-ℕ (v' *ℕ 2)))))))
- pu : (succ-ℕ u) = (succ-ℕ u')
- pu = ap succ-ℕ (pr1 (is-pair-expansion-unique u u' v v' q))
- pv : v = v'
- pv = pr2 (is-pair-expansion-unique u u' v v' q)
-```
-
-A pairing function is a bijection between `ℕ × ℕ` and `ℕ`.
-
-## Definition
-
-```agda
-pairing-map : ℕ × ℕ → ℕ
-pairing-map (u , v) =
- pr1 (is-successor-is-nonzero-ℕ (is-nonzero-pair-expansion u v))
-```
-
-### Pairing function is split surjective
-
-```agda
-is-split-surjective-pairing-map : is-split-surjective pairing-map
-is-split-surjective-pairing-map n =
- (u , v) , is-injective-succ-ℕ (q ∙ s)
- where
- u = pr1 (pr1 (has-pair-expansion n))
- v = pr2 (pr1 (has-pair-expansion n))
- s = pr2 (has-pair-expansion n)
- r = is-successor-is-nonzero-ℕ (is-nonzero-pair-expansion u v)
- q :
- ( succ-ℕ (pairing-map (u , v))) =
- ( (exp-ℕ 2 u) *ℕ (succ-ℕ (v *ℕ 2)))
- q = inv (pr2 r)
-```
-
-### Pairing function is injective
-
-```agda
-is-injective-pairing-map : is-injective pairing-map
-is-injective-pairing-map {u , v} {u' , v'} p =
- ( eq-pair' (is-pair-expansion-unique u u' v v' q))
- where
- r = is-successor-is-nonzero-ℕ (is-nonzero-pair-expansion u v)
- s = is-successor-is-nonzero-ℕ (is-nonzero-pair-expansion u' v')
- q :
- ( (exp-ℕ 2 u) *ℕ (succ-ℕ (v *ℕ 2))) =
- ( (exp-ℕ 2 u') *ℕ (succ-ℕ (v' *ℕ 2)))
- q = (pr2 r) ∙ (ap succ-ℕ p ∙ inv (pr2 s))
-```
-
-### Pairing function is equivalence
-
-```agda
-is-equiv-pairing-map : is-equiv pairing-map
-is-equiv-pairing-map =
- is-equiv-is-split-surjective-is-injective
- pairing-map
- is-injective-pairing-map
- is-split-surjective-pairing-map
-```
diff --git a/src/elementary-number-theory/prime-divisors-natural-numbers.lagda.md b/src/elementary-number-theory/prime-divisors-natural-numbers.lagda.md
new file mode 100644
index 0000000000..25a07823ea
--- /dev/null
+++ b/src/elementary-number-theory/prime-divisors-natural-numbers.lagda.md
@@ -0,0 +1,77 @@
+# Prime divisors of natural numbers
+
+```agda
+module elementary-number-theory.prime-divisors-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.prime-numbers
+
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-propositions
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.propositions
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+A {{#concept "prime divisor" Disambiguation="natural numbers" Agda=is-prime-divisor-ℕ}} of a [natural number](elementary-number-theory.natural-numbers.md) $n$ is a [prime number](elementary-number-theory.prime-numbers.md) $p$ which is a [divisor](elementary-number-theory.divisibility-natural-numbers.md) of $n$.
+
+## Definitions
+
+### The predicate of being a prime divisor
+
+```agda
+module _
+ (n d : ℕ)
+ where
+
+ is-prime-divisor-ℕ :
+ UU lzero
+ is-prime-divisor-ℕ =
+ is-prime-ℕ d × is-divisor-ℕ n d
+
+ is-prop-is-prime-divisor-ℕ :
+ is-prop is-prime-divisor-ℕ
+ is-prop-is-prime-divisor-ℕ =
+ is-prop-Σ
+ ( is-prop-is-prime-ℕ d)
+ ( λ H → is-prop-div-ℕ d n (inl (is-nonzero-is-prime-ℕ d H)))
+
+ is-prime-divisor-prop-ℕ :
+ Prop lzero
+ pr1 is-prime-divisor-prop-ℕ =
+ is-prime-divisor-ℕ
+ pr2 is-prime-divisor-prop-ℕ =
+ is-prop-is-prime-divisor-ℕ
+
+ is-decidable-is-prime-divisor-ℕ :
+ is-decidable is-prime-divisor-ℕ
+ is-decidable-is-prime-divisor-ℕ =
+ is-decidable-product (is-decidable-is-prime-ℕ d) (is-decidable-div-ℕ d n)
+
+ is-decidable-prop-is-prime-divisor-ℕ :
+ is-decidable-prop is-prime-divisor-ℕ
+ pr1 is-decidable-prop-is-prime-divisor-ℕ =
+ is-prop-is-prime-divisor-ℕ
+ pr2 is-decidable-prop-is-prime-divisor-ℕ =
+ is-decidable-is-prime-divisor-ℕ
+
+ is-prime-divisor-decidable-prop-ℕ :
+ Decidable-Prop lzero
+ pr1 is-prime-divisor-decidable-prop-ℕ =
+ is-prime-divisor-ℕ
+ pr2 is-prime-divisor-decidable-prop-ℕ =
+ is-decidable-prop-is-prime-divisor-ℕ
+```
+
+
diff --git a/src/elementary-number-theory/prime-numbers.lagda.md b/src/elementary-number-theory/prime-numbers.lagda.md
index 930d240933..d045439b73 100644
--- a/src/elementary-number-theory/prime-numbers.lagda.md
+++ b/src/elementary-number-theory/prime-numbers.lagda.md
@@ -27,6 +27,7 @@ open import foundation.fundamental-theorem-of-identity-types
open import foundation.identity-types
open import foundation.logical-equivalences
open import foundation.negated-equality
+open import foundation.negation
open import foundation.propositions
open import foundation.torsorial-type-families
open import foundation.transport-along-identifications
@@ -38,7 +39,10 @@ open import foundation.universe-levels
## Idea
-A prime number is a natural number of which 1 is the only proper divisor.
+A {{#concept "prime number" Agda=is-prime-ℕ WDID=Q49008 WD="prime number"}} is a
+[natural number](elementary-number-theory.natural-numbers.md) of which 1 is the
+only
+[proper divisor](elementary-number-theory.proper-divisors-natural-numbers.md).
## Definition
@@ -50,6 +54,18 @@ This is a direct interpretation of what it means to be prime.
is-prime-ℕ : ℕ → UU lzero
is-prime-ℕ n = (x : ℕ) → (is-proper-divisor-ℕ n x ↔ is-one-ℕ x)
+module _
+ {n : ℕ} (H : is-prime-ℕ n)
+ where
+
+ is-one-is-proper-divisor-is-prime-ℕ :
+ (x : ℕ) → is-proper-divisor-ℕ n x → is-one-ℕ x
+ is-one-is-proper-divisor-is-prime-ℕ x = forward-implication (H x)
+
+ is-proper-divisor-is-one-is-prime-ℕ :
+ (x : ℕ) → is-one-ℕ x → is-proper-divisor-ℕ n x
+ is-proper-divisor-is-one-is-prime-ℕ x = backward-implication (H x)
+
Prime-ℕ : UU lzero
Prime-ℕ = Σ ℕ is-prime-ℕ
@@ -76,6 +92,16 @@ is-one-is-proper-divisor-ℕ n =
is-prime-easy-ℕ : ℕ → UU lzero
is-prime-easy-ℕ n = (is-not-one-ℕ n) × (is-one-is-proper-divisor-ℕ n)
+
+module _
+ {n : ℕ} (H : is-prime-easy-ℕ n)
+ where
+
+ is-not-one-is-prime-easy-ℕ : is-not-one-ℕ n
+ is-not-one-is-prime-easy-ℕ = pr1 H
+
+ is-one-is-proper-divisor-is-prime-easy-ℕ : is-one-is-proper-divisor-ℕ n
+ is-one-is-proper-divisor-is-prime-easy-ℕ = pr2 H
```
### Third definition of prime numbers
@@ -94,9 +120,8 @@ is-nonzero-is-prime-ℕ :
(n : ℕ) → is-prime-ℕ n → is-nonzero-ℕ n
is-nonzero-is-prime-ℕ n H p =
is-not-one-two-ℕ
- ( pr1
- ( H 2)
- ( tr (λ k → 2 ≠ k) (inv p) ( is-nonzero-two-ℕ) ,
+ ( is-one-is-proper-divisor-is-prime-ℕ H 2
+ ( tr (λ k → 2 ≠ k) (inv p) (is-nonzero-two-ℕ) ,
tr (div-ℕ 2) (inv p) (0 , refl)))
```
@@ -104,7 +129,8 @@ is-nonzero-is-prime-ℕ n H p =
```agda
is-not-one-is-prime-ℕ : (n : ℕ) → is-prime-ℕ n → is-not-one-ℕ n
-is-not-one-is-prime-ℕ n H p = pr1 (pr2 (H 1) refl) (inv p)
+is-not-one-is-prime-ℕ n H p =
+ pr1 (is-proper-divisor-is-one-is-prime-ℕ H 1 refl) (inv p)
```
### A prime is strictly greater than `1`
@@ -142,33 +168,40 @@ is-prop-has-unique-proper-divisor-ℕ n = is-property-is-contr
### The three definitions of primes are equivalent
```agda
-is-prime-easy-is-prime-ℕ : (n : ℕ) → is-prime-ℕ n → is-prime-easy-ℕ n
-pr1 (is-prime-easy-is-prime-ℕ n H) = is-not-one-is-prime-ℕ n H
-pr2 (is-prime-easy-is-prime-ℕ n H) x = pr1 (H x)
-
-is-prime-is-prime-easy-ℕ : (n : ℕ) → is-prime-easy-ℕ n → is-prime-ℕ n
-pr1 (is-prime-is-prime-easy-ℕ n H x) = pr2 H x
-pr1 (pr2 (is-prime-is-prime-easy-ℕ n H .(succ-ℕ zero-ℕ)) refl) q = pr1 H (inv q)
-pr2 (pr2 (is-prime-is-prime-easy-ℕ n H .(succ-ℕ zero-ℕ)) refl) = div-one-ℕ n
+is-prime-easy-is-prime-ℕ :
+ (n : ℕ) → is-prime-ℕ n → is-prime-easy-ℕ n
+pr1 (is-prime-easy-is-prime-ℕ n H) =
+ is-not-one-is-prime-ℕ n H
+pr2 (is-prime-easy-is-prime-ℕ n H) =
+ is-one-is-proper-divisor-is-prime-ℕ H
+
+is-prime-is-prime-easy-ℕ :
+ (n : ℕ) → is-prime-easy-ℕ n → is-prime-ℕ n
+pr1 (is-prime-is-prime-easy-ℕ n H x) =
+ is-one-is-proper-divisor-is-prime-easy-ℕ H x
+pr1 (pr2 (is-prime-is-prime-easy-ℕ n H .(succ-ℕ zero-ℕ)) refl) q =
+ is-not-one-is-prime-easy-ℕ H (inv q)
+pr2 (pr2 (is-prime-is-prime-easy-ℕ n H .(succ-ℕ zero-ℕ)) refl) =
+ div-one-ℕ n
has-unique-proper-divisor-is-prime-ℕ :
(n : ℕ) → is-prime-ℕ n → has-unique-proper-divisor-ℕ n
has-unique-proper-divisor-is-prime-ℕ n H =
fundamental-theorem-id'
- ( λ x p → pr2 (H x) (inv p))
+ ( λ x p → is-proper-divisor-is-one-is-prime-ℕ H x (inv p))
( λ x →
is-equiv-has-converse-is-prop
( is-set-ℕ 1 x)
( is-prop-is-proper-divisor-ℕ n x)
- ( λ p → inv (pr1 (H x) p)))
+ ( λ p → inv (is-one-is-proper-divisor-is-prime-ℕ H x p)))
is-prime-has-unique-proper-divisor-ℕ :
(n : ℕ) → has-unique-proper-divisor-ℕ n → is-prime-ℕ n
pr1 (is-prime-has-unique-proper-divisor-ℕ n H x) K =
ap pr1
( eq-is-contr H
- { pair x K}
- { pair 1 (is-proper-divisor-one-is-proper-divisor-ℕ K)})
+ { (x , K)}
+ { (1 , is-proper-divisor-one-is-proper-divisor-ℕ K)})
pr2 (is-prime-has-unique-proper-divisor-ℕ n H .1) refl =
is-proper-divisor-one-is-proper-divisor-ℕ (pr2 (center H))
```
@@ -180,7 +213,9 @@ is-decidable-is-prime-easy-ℕ : (n : ℕ) → is-decidable (is-prime-easy-ℕ n
is-decidable-is-prime-easy-ℕ zero-ℕ =
inr
( λ H →
- is-not-one-two-ℕ (pr2 H 2 (is-proper-divisor-zero-succ-ℕ 1)))
+ is-not-one-two-ℕ
+ ( is-one-is-proper-divisor-is-prime-easy-ℕ H 2
+ ( is-proper-divisor-zero-succ-ℕ 1)))
is-decidable-is-prime-easy-ℕ (succ-ℕ n) =
is-decidable-product
( is-decidable-neg (is-decidable-is-one-ℕ (succ-ℕ n)))
@@ -204,12 +239,12 @@ is-decidable-is-prime-ℕ n =
```agda
is-one-is-proper-divisor-two-ℕ : is-one-is-proper-divisor-ℕ 2
-is-one-is-proper-divisor-two-ℕ zero-ℕ (pair f (pair k p)) =
+is-one-is-proper-divisor-two-ℕ zero-ℕ (f , k , p) =
ex-falso (f (inv (right-zero-law-mul-ℕ k) ∙ p))
-is-one-is-proper-divisor-two-ℕ (succ-ℕ zero-ℕ) (pair f H) = refl
-is-one-is-proper-divisor-two-ℕ (succ-ℕ (succ-ℕ zero-ℕ)) (pair f H) =
+is-one-is-proper-divisor-two-ℕ (succ-ℕ zero-ℕ) (f , H) = refl
+is-one-is-proper-divisor-two-ℕ (succ-ℕ (succ-ℕ zero-ℕ)) (f , H) =
ex-falso (f refl)
-is-one-is-proper-divisor-two-ℕ (succ-ℕ (succ-ℕ (succ-ℕ x))) (pair f H) =
+is-one-is-proper-divisor-two-ℕ (succ-ℕ (succ-ℕ (succ-ℕ x))) (f , H) =
ex-falso (leq-div-succ-ℕ (succ-ℕ (succ-ℕ (succ-ℕ x))) 1 H)
is-prime-easy-two-ℕ : is-prime-easy-ℕ 2
@@ -224,24 +259,40 @@ is-prime-two-ℕ =
### If a prime number `p` divides a nonzero number `x`, then `x/p < x`
```agda
-le-quotient-div-is-prime-ℕ :
+strict-upper-bound-quotient-div-is-prime-ℕ :
(p x : ℕ) → is-nonzero-ℕ x → is-prime-ℕ p →
- (H : div-ℕ p x) → le-ℕ (quotient-div-ℕ p x H) x
-le-quotient-div-is-prime-ℕ p x N P H =
+ (H : div-ℕ p x) → quotient-div-ℕ p x H <-ℕ x
+strict-upper-bound-quotient-div-is-prime-ℕ p x N P H =
le-quotient-div-ℕ p x N H (is-not-one-is-prime-ℕ p P)
```
### If a prime number `p` divides a number `x + 1`, then `(x + 1)/p ≤ x`
+Note that this upper bound is slightly sharper than the usual upper bound
+`x + 1` we get for arbitrary quotients of divisible natural numbers.
+
```agda
-leq-quotient-div-is-prime-ℕ :
+upper-bound-quotient-div-is-prime-ℕ :
(p x : ℕ) → is-prime-ℕ p →
- (H : div-ℕ p (succ-ℕ x)) → leq-ℕ (quotient-div-ℕ p (succ-ℕ x) H) x
-leq-quotient-div-is-prime-ℕ p x P H =
+ (H : div-ℕ p (succ-ℕ x)) → quotient-div-ℕ p (succ-ℕ x) H ≤-ℕ x
+upper-bound-quotient-div-is-prime-ℕ p x P H =
leq-le-succ-ℕ
( quotient-div-ℕ p (succ-ℕ x) H)
( x)
- ( le-quotient-div-is-prime-ℕ p (succ-ℕ x) (is-nonzero-succ-ℕ x) P H)
+ ( strict-upper-bound-quotient-div-is-prime-ℕ p
+ ( succ-ℕ x)
+ ( is-nonzero-succ-ℕ x)
+ ( P)
+ ( H))
+```
+
+### The number `1` has no prime divisors
+
+```agda
+no-prime-divisors-one-ℕ :
+ (p : ℕ) → is-prime-ℕ p → ¬ (div-ℕ p 1)
+no-prime-divisors-one-ℕ p H K =
+ is-not-one-is-prime-ℕ p H (is-one-div-one-ℕ p K)
```
## See also
diff --git a/src/elementary-number-theory/products-lists-of-natural-numbers.lagda.md b/src/elementary-number-theory/products-lists-of-natural-numbers.lagda.md
new file mode 100644
index 0000000000..08a6cb8dfb
--- /dev/null
+++ b/src/elementary-number-theory/products-lists-of-natural-numbers.lagda.md
@@ -0,0 +1,79 @@
+# Products of lists of natural numbers
+
+```agda
+module elementary-number-theory.products-lists-of-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+
+open import finite-group-theory.permutations-standard-finite-types
+
+open import foundation.action-on-identifications-functions
+open import foundation.dependent-pair-types
+open import foundation.identity-types
+
+open import lists.concatenation-lists
+open import lists.lists
+open import lists.permutation-lists
+open import lists.universal-quantification-lists
+```
+
+
+
+## Idea
+
+Given a [list](lists.lists.md) of
+[natural numbers](elementary-number-theory.natural-numbers.md) $l$, we define
+the {{#concept "product" Disambiguation="list of natural numbers"}} of the
+elements of $l$ by recursively multiplying all its elements.
+
+## Definitions
+
+### The product of the elements of a list
+
+```agda
+mul-list-ℕ :
+ list ℕ → ℕ
+mul-list-ℕ = fold-list 1 mul-ℕ
+```
+
+## Properties
+
+### The product of any list of natural numbers greater than one is greater than one
+
+```agda
+leq-one-mul-list-ℕ :
+ (l : list ℕ) (H : for-all-list l (leq-ℕ 1)) → 1 ≤-ℕ mul-list-ℕ l
+leq-one-mul-list-ℕ nil H = refl-leq-ℕ 1
+leq-one-mul-list-ℕ (cons n l) (H , K) =
+ preserves-order-mul-ℕ 1 n 1 (mul-list-ℕ l) H (leq-one-mul-list-ℕ l K)
+```
+
+### `mul-list-ℕ` is permutation invariant
+
+```agda
+permutation-invariant-mul-list-ℕ :
+ (l : list ℕ) (t : permutation (length-list l)) →
+ mul-list-ℕ l = mul-list-ℕ (permute-list l t)
+permutation-invariant-mul-list-ℕ =
+ permutation-invariant-fold-list 1 mul-ℕ left-swap-mul-ℕ
+```
+
+### `mul-list-ℕ` of a concatenation of lists
+
+```agda
+compute-mul-concat-list-ℕ :
+ (p q : list ℕ) →
+ mul-list-ℕ (concat-list p q) = mul-list-ℕ p *ℕ mul-list-ℕ q
+compute-mul-concat-list-ℕ nil q =
+ inv (left-unit-law-add-ℕ (mul-list-ℕ q))
+compute-mul-concat-list-ℕ (cons x p) q =
+ ap (mul-ℕ x) (compute-mul-concat-list-ℕ p q) ∙
+ inv (associative-mul-ℕ x (mul-list-ℕ p) (mul-list-ℕ q))
+```
diff --git a/src/elementary-number-theory/products-of-natural-numbers.lagda.md b/src/elementary-number-theory/products-of-natural-numbers.lagda.md
index bf853f365e..9254b56aa4 100644
--- a/src/elementary-number-theory/products-of-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/products-of-natural-numbers.lagda.md
@@ -7,17 +7,23 @@ module elementary-number-theory.products-of-natural-numbers where
Imports
```agda
+open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
+open import foundation.action-on-identifications-functions
open import foundation.coproduct-types
+open import foundation.dependent-pair-types
+open import foundation.function-extensionality
open import foundation.function-types
+open import foundation.homotopies
open import foundation.identity-types
open import foundation.unit-type
open import lists.lists
+open import univalent-combinatorics.skipping-element-standard-finite-types
open import univalent-combinatorics.standard-finite-types
```
@@ -25,17 +31,15 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-The product of a list of natural numbers is defined by iterated multiplication.
+The
+{{#concept "product" Disambiguation="standard finite family of natural numbers"}}
+of a [standard finite](univalent-combinatorics.standard-finite-types.md) family
+of [natural numbers](elementary-number-theory.natural-numbers.md) is defined by
+iterated
+[multiplication](elementary-number-theory.multiplication-natural-numbers.md).
## Definitions
-### Products of lists of natural numbers
-
-```agda
-product-list-ℕ : list ℕ → ℕ
-product-list-ℕ = fold-list 1 mul-ℕ
-```
-
### Products of families of natural numbers indexed by standard finite types
```agda
@@ -60,7 +64,11 @@ le-one-Π-ℕ :
(k : ℕ) (f : Fin k → ℕ) →
0 <-ℕ k → ((i : Fin k) → 1 <-ℕ f i) → 1 <-ℕ Π-ℕ k f
le-one-Π-ℕ (succ-ℕ zero-ℕ) f H K =
- concatenate-le-eq-ℕ (K (inr star)) (inv (unit-law-Π-ℕ f (inr star)))
+ concatenate-le-eq-ℕ 1
+ ( f (inr star))
+ ( Π-ℕ 1 f)
+ ( K (inr star))
+ ( inv (unit-law-Π-ℕ f (inr star)))
le-one-Π-ℕ (succ-ℕ (succ-ℕ k)) f H K =
le-one-mul-ℕ
( Π-ℕ (succ-ℕ k) (f ∘ inl))
@@ -68,3 +76,46 @@ le-one-Π-ℕ (succ-ℕ (succ-ℕ k)) f H K =
( le-one-Π-ℕ (succ-ℕ k) (f ∘ inl) star (K ∘ inl))
( K (inr star))
```
+
+### Products preserve pointwise identifications
+
+```agda
+preserves-htpy-Π-ℕ :
+ (k : ℕ) {f g : Fin k → ℕ} (H : f ~ g) → Π-ℕ k f = Π-ℕ k g
+preserves-htpy-Π-ℕ k H =
+ ap (Π-ℕ k) (eq-htpy H)
+```
+
+### Any factor of a product of natural numbers divides the product
+
+```agda
+quotient-div-factor-Π-ℕ :
+ (k : ℕ) (f : Fin k → ℕ) (i : Fin k) → ℕ
+quotient-div-factor-Π-ℕ (succ-ℕ k) f i =
+ Π-ℕ k (f ∘ skip-Fin k i)
+
+eq-quotient-div-factor-Π-ℕ :
+ (k : ℕ) (f : Fin k → ℕ) (i : Fin k) →
+ quotient-div-factor-Π-ℕ k f i *ℕ f i = Π-ℕ k f
+eq-quotient-div-factor-Π-ℕ (succ-ℕ zero-ℕ) f (inr star) =
+ refl
+eq-quotient-div-factor-Π-ℕ (succ-ℕ (succ-ℕ k)) f (inl i) =
+ ( right-swap-mul-ℕ
+ ( Π-ℕ k (f ∘ inl ∘ skip-Fin k i))
+ ( f (inr star))
+ ( f (inl i))) ∙
+ ( ap (_*ℕ f (inr star)) (eq-quotient-div-factor-Π-ℕ (succ-ℕ k) (f ∘ inl) i))
+eq-quotient-div-factor-Π-ℕ (succ-ℕ (succ-ℕ k)) f (inr star) =
+ refl
+
+div-factor-Π-ℕ :
+ (k : ℕ) (f : Fin k → ℕ) (i : Fin k) → div-ℕ (f i) (Π-ℕ k f)
+pr1 (div-factor-Π-ℕ k f i) =
+ quotient-div-factor-Π-ℕ k f i
+pr2 (div-factor-Π-ℕ k f i) =
+ eq-quotient-div-factor-Π-ℕ k f i
+```
+
+## See also
+
+- [Products of lists of natural numbers](elementary-number-theory.products-lists-of-natural-numbers.md)
diff --git a/src/elementary-number-theory/pronic-numbers.lagda.md b/src/elementary-number-theory/pronic-numbers.lagda.md
new file mode 100644
index 0000000000..ade43009c3
--- /dev/null
+++ b/src/elementary-number-theory/pronic-numbers.lagda.md
@@ -0,0 +1,229 @@
+# The pronic numbers
+
+```agda
+module elementary-number-theory.pronic-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
+open import elementary-number-theory.sums-of-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.dependent-pair-types
+open import foundation.coproduct-types
+open import foundation.identity-types
+open import foundation.transport-along-identifications
+
+open import univalent-combinatorics.standard-finite-types
+```
+
+
+
+## Idea
+
+The
+{{#concept "pronic numbers" Agda=pronic-number-ℕ WD="pronic number" WDID=Q1486643}}
+are the [natural numbers](elementary-number-theory.natural-numbers.md) of the
+form
+
+$$
+ n(n+1).
+$$
+
+The pronic numbers satisfy the recurrence
+
+$$
+ a_{n+1} = a_n + 2(n+1).
+$$
+
+The sequence `0, 2, 6, 12, 20, 30, 42, …` of pronic numbers is listed as
+[A002378](https://oeis.org/A002378) in the [OEIS](literature.oeis.md)
+{{#cite OEIS}}. The $n$th pronic number is
+[even](elementary-number-theory.parity-natural-numbers.md) for every $n$, and it
+is twice the $n$th
+[triangular number](elementary-number-theory.triangular-numbers.md).
+
+## Definitions
+
+### The pronic numbers
+
+```agda
+pronic-number-ℕ : ℕ → ℕ
+pronic-number-ℕ n = n *ℕ succ-ℕ n
+```
+
+### The iterated pronic numbers
+
+The iterated pronic numbers are listed as [https://oeis.org/A007018) in the OEIS
+{{#cite OEIS}}. Saidak {{#cite Saidak2006}} showed that the $n$th iterated
+pronic number has at least $n$ prime factors, to obtain a new proof of the
+[infinitude of primes](elementary-number-theory.infinitude-of-primes.md) as
+recently as 2006.
+
+Saidak's proof of the infinitude of primes is as follows. Write $N_n$ for the
+$n$th iterated pronic number. Then $N_0 = 1$, which has at least $0$
+[prime](elementary-number-theory.prime-numbers.md)
+[divisors](elementary-number-theory.divisibility-natural-numbers.md). Assume
+that $N_n$ has at least $n$ prime divisors. The number $N_n + 1$ is coprime to
+$N_n$, so its prime divisors are distinct from the prime divisors of $N_n$.
+Since $N_n + 1 > 1$, it has at least one prime divisor, so it follows that
+$N_n(N_n + 1)$ has at least $n+1$ prime divisors. Therefore, there are
+infinitely many primes.
+
+```agda
+iterated-pronic-number-ℕ :
+ ℕ → ℕ
+iterated-pronic-number-ℕ zero-ℕ =
+ 1
+iterated-pronic-number-ℕ (succ-ℕ n) =
+ pronic-number-ℕ (iterated-pronic-number-ℕ n)
+```
+
+## Properties
+
+### The pronic number of a successor
+
+```agda
+pronic-number-succ-ℕ :
+ (n : ℕ) → pronic-number-ℕ (succ-ℕ n) = pronic-number-ℕ n +ℕ 2 *ℕ succ-ℕ n
+pronic-number-succ-ℕ n =
+ ( left-distributive-mul-add-ℕ (succ-ℕ n) n 2) ∙
+ ( ap-add-ℕ (commutative-mul-ℕ (succ-ℕ n) n) (commutative-mul-ℕ (succ-ℕ n) 2))
+```
+
+### The $n$th pronic number $n(n + 1)$ is even
+
+```agda
+abstract
+ is-even-pronic-number-ℕ :
+ (n : ℕ) → is-even-ℕ (pronic-number-ℕ n)
+ is-even-pronic-number-ℕ n
+ with is-even-or-is-even-succ-ℕ n
+ ... | inl H =
+ is-even-div-is-even-ℕ
+ ( n)
+ ( pronic-number-ℕ n)
+ ( H)
+ ( succ-ℕ n , commutative-mul-ℕ (succ-ℕ n) n)
+ ... | inr H =
+ is-even-div-is-even-ℕ
+ ( succ-ℕ n)
+ ( pronic-number-ℕ n)
+ ( H)
+ ( n , refl)
+```
+
+### The $(n+1)$st pronic number
+
+We have `(n + 1) * (n + 2) = n * (n + 1) + 2 * (n + 1)`
+
+```agda
+compute-pronic-number-succ-ℕ :
+ (n : ℕ) → pronic-number-ℕ (succ-ℕ n) = pronic-number-ℕ n +ℕ 2 *ℕ succ-ℕ n
+compute-pronic-number-succ-ℕ n =
+ commutative-mul-ℕ (succ-ℕ n) (succ-ℕ (succ-ℕ n)) ∙
+ right-distributive-mul-add-ℕ n 2 (succ-ℕ n)
+```
+
+### The sum of pronic numbers
+
+The sum of the pronic numbers from $1$ to $n$ is given by the identity
+
+$$
+ \sum_{k=0}^n k(k+1) = \frac{n(n+1)(n+3)}{3} = 2\binom{n+3}{3}
+$$
+
+This sequence of numbers starts out as
+
+$$
+ 0,\ 2, 8,\ 20,\ 40,\ 70,\ \ldots
+$$
+
+and it is listed as A007290 in the [OEIS](literature.oeis.md) {{#cite OEIS}}.
+The computation of the sum of pronic numbers is stated as exercise 4 in section
+1.2 of {{#cite Andrews94}}.
+
+```agda
+sum-of-pronic-numbers-ℕ : ℕ → ℕ
+sum-of-pronic-numbers-ℕ n =
+ sum-Fin-ℕ (succ-ℕ n) (λ i → pronic-number-ℕ (nat-Fin (succ-ℕ n) i))
+
+dividend-sum-of-pronic-numbers-ℕ : ℕ → ℕ
+dividend-sum-of-pronic-numbers-ℕ n = pronic-number-ℕ n *ℕ succ-ℕ (succ-ℕ n)
+
+dividend-sum-of-pronic-numbers-succ-ℕ :
+ (n : ℕ) →
+ dividend-sum-of-pronic-numbers-ℕ (succ-ℕ n) =
+ dividend-sum-of-pronic-numbers-ℕ n +ℕ 3 *ℕ pronic-number-ℕ (succ-ℕ n)
+dividend-sum-of-pronic-numbers-succ-ℕ n =
+ ( commutative-mul-ℕ (pronic-number-ℕ (succ-ℕ n)) (n +ℕ 3)) ∙
+ ( right-distributive-mul-add-ℕ n 3 (pronic-number-ℕ (succ-ℕ n))) ∙
+ ( ap
+ ( _+ℕ 3 *ℕ pronic-number-ℕ (succ-ℕ n))
+ ( inv (associative-mul-ℕ n (succ-ℕ n) (succ-ℕ (succ-ℕ n)))))
+
+div-3-dividend-sum-of-pronic-numbers-ℕ :
+ (n : ℕ) → div-ℕ 3 (dividend-sum-of-pronic-numbers-ℕ n)
+div-3-dividend-sum-of-pronic-numbers-ℕ zero-ℕ = div-zero-ℕ 3
+div-3-dividend-sum-of-pronic-numbers-ℕ (succ-ℕ n) =
+ tr
+ ( div-ℕ 3)
+ ( inv (dividend-sum-of-pronic-numbers-succ-ℕ n))
+ ( div-add-ℕ 3
+ ( dividend-sum-of-pronic-numbers-ℕ n)
+ ( 3 *ℕ pronic-number-ℕ (succ-ℕ n))
+ ( div-3-dividend-sum-of-pronic-numbers-ℕ n)
+ ( div-mul-ℕ' (pronic-number-ℕ (succ-ℕ n)) 3 3 (refl-div-ℕ 3)))
+
+value-sum-of-pronic-numbers-ℕ : ℕ → ℕ
+value-sum-of-pronic-numbers-ℕ n =
+ quotient-div-ℕ 3
+ ( dividend-sum-of-pronic-numbers-ℕ n)
+ ( div-3-dividend-sum-of-pronic-numbers-ℕ n)
+
+eq-value-sum-of-pronic-numbers-ℕ :
+ (n : ℕ) →
+ 3 *ℕ value-sum-of-pronic-numbers-ℕ n = dividend-sum-of-pronic-numbers-ℕ n
+eq-value-sum-of-pronic-numbers-ℕ n =
+ eq-quotient-div-ℕ' 3
+ ( dividend-sum-of-pronic-numbers-ℕ n)
+ ( div-3-dividend-sum-of-pronic-numbers-ℕ n)
+
+compute-sum-of-pronic-numbers-ℕ' :
+ (n : ℕ) →
+ 3 *ℕ sum-of-pronic-numbers-ℕ n = dividend-sum-of-pronic-numbers-ℕ n
+compute-sum-of-pronic-numbers-ℕ' zero-ℕ = refl
+compute-sum-of-pronic-numbers-ℕ' (succ-ℕ n) =
+ ( left-distributive-mul-add-ℕ 3
+ ( sum-of-pronic-numbers-ℕ n)
+ ( pronic-number-ℕ (succ-ℕ n))) ∙
+ ( ap
+ ( _+ℕ 3 *ℕ pronic-number-ℕ (succ-ℕ n))
+ ( compute-sum-of-pronic-numbers-ℕ' n)) ∙
+ ( inv (dividend-sum-of-pronic-numbers-succ-ℕ n))
+
+compute-sum-of-pronic-numbers-ℕ :
+ (n : ℕ) → sum-of-pronic-numbers-ℕ n = value-sum-of-pronic-numbers-ℕ n
+compute-sum-of-pronic-numbers-ℕ n =
+ is-injective-left-mul-ℕ 3
+ ( is-nonzero-succ-ℕ 2)
+ ( ( compute-sum-of-pronic-numbers-ℕ' n) ∙
+ ( inv (eq-value-sum-of-pronic-numbers-ℕ n)))
+```
+
+## See also
+
+- [Nicomachus's Theorem](elementary-number-theory.nicomachuss-theorem.md)
+- [Square pyramidal numbers](elementary-number-theory.square-pyramidal-numbers.md)
+- [Squares of natural numbers](elementary-number-theory.squares-natural-numbers.md)
+- [Triangular numbers](elementary-number-theory.triangular-numbers.md)
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/proper-divisors-natural-numbers.lagda.md b/src/elementary-number-theory/proper-divisors-natural-numbers.lagda.md
index 0f35339378..508de8c27f 100644
--- a/src/elementary-number-theory/proper-divisors-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/proper-divisors-natural-numbers.lagda.md
@@ -16,6 +16,7 @@ open import elementary-number-theory.natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
open import foundation.cartesian-product-types
+open import foundation.coproduct-types
open import foundation.decidable-types
open import foundation.dependent-pair-types
open import foundation.empty-types
@@ -31,32 +32,51 @@ open import foundation.universe-levels
## Idea
-A proper divisor of a natural number `n` is a natural number `d ≠ n` that
-divides `n`.
+A
+{{#concept "proper divisor" Disambituation="natural numbers" Agda=is-proper-divisor-ℕ}}
+of a [natural number](elementary-number-theory.natural-numbers.md) `n` is a
+natural number `d ≠ n` that
+[divides](elementary-number-theory.divisbility-natural-numbers.md) `n`.
+
+## Definitions
+
+### The predicate of being a proper divisor of a natural number
```agda
is-proper-divisor-ℕ : ℕ → ℕ → UU lzero
is-proper-divisor-ℕ n d = (d ≠ n) × (div-ℕ d n)
+```
+
+## Properties
+
+### Being a proper divisor of a natural number is decidable
+```agda
is-decidable-is-proper-divisor-ℕ :
(n d : ℕ) → is-decidable (is-proper-divisor-ℕ n d)
is-decidable-is-proper-divisor-ℕ n d =
is-decidable-product
( is-decidable-neg (has-decidable-equality-ℕ d n))
( is-decidable-div-ℕ d n)
+```
+
+### Any successor is a proper divisor of $0$
+```agda
is-proper-divisor-zero-succ-ℕ : (n : ℕ) → is-proper-divisor-ℕ zero-ℕ (succ-ℕ n)
pr1 (is-proper-divisor-zero-succ-ℕ n) = is-nonzero-succ-ℕ n
pr2 (is-proper-divisor-zero-succ-ℕ n) = div-zero-ℕ (succ-ℕ n)
+```
+### Any proper divisor of a natural number is strictly smaller than its dividend
+
+```agda
le-is-proper-divisor-ℕ :
(x y : ℕ) → is-nonzero-ℕ y → is-proper-divisor-ℕ y x → le-ℕ x y
le-is-proper-divisor-ℕ x y H K =
le-leq-neq-ℕ (leq-div-ℕ x y H (pr2 K)) (pr1 K)
```
-## Properties
-
### Being a proper divisor is a property
```agda
@@ -64,7 +84,9 @@ is-prop-is-proper-divisor-ℕ : (n d : ℕ) → is-prop (is-proper-divisor-ℕ n
is-prop-is-proper-divisor-ℕ n zero-ℕ (pair f g) =
ex-falso (f (inv (is-zero-div-zero-ℕ n g)))
is-prop-is-proper-divisor-ℕ n (succ-ℕ d) =
- is-prop-product is-prop-neg (is-prop-div-ℕ (succ-ℕ d) n (is-nonzero-succ-ℕ d))
+ is-prop-product
+ ( is-prop-neg)
+ ( is-prop-div-ℕ (succ-ℕ d) n (inl (is-nonzero-succ-ℕ d)))
```
### If a natural number has a proper divisor, then `1` is a proper divisor
@@ -94,3 +116,22 @@ le-one-quotient-div-is-proper-divisor-ℕ d x f H g =
( quotient-div-ℕ d x H)
( leq-one-quotient-div-ℕ d x H (leq-one-is-nonzero-ℕ x f)))
```
+
+### A divisor `d` of a number `n` is a proper divisor if and only if `x ∤ d`
+
+```agda
+neg-div-is-proper-divisor-ℕ :
+ (d n : ℕ) → is-proper-divisor-ℕ n d → ¬ div-ℕ n d
+neg-div-is-proper-divisor-ℕ d n (np , H) K =
+ np (antisymmetric-div-ℕ d n H K)
+
+is-proper-divisor-neg-div-ℕ :
+ (d n : ℕ) → div-ℕ d n → ¬ div-ℕ n d → is-proper-divisor-ℕ n d
+pr1 (is-proper-divisor-neg-div-ℕ d .d H K) refl = K H
+pr2 (is-proper-divisor-neg-div-ℕ d n H K) = H
+```
+
+## See also
+
+- [Prime numbers](elementary-number-theory.prime-numbers.md)
+- [Nontrivial divisors](elementary-number-theory.nontrivial-divisors-natural-numbers.md)
diff --git a/src/elementary-number-theory/rational-numbers.lagda.md b/src/elementary-number-theory/rational-numbers.lagda.md
index 001db38b16..734f124dcc 100644
--- a/src/elementary-number-theory/rational-numbers.lagda.md
+++ b/src/elementary-number-theory/rational-numbers.lagda.md
@@ -311,6 +311,13 @@ pr1 reflecting-map-sim-fraction = rational-fraction-ℤ
pr2 reflecting-map-sim-fraction {x} {y} H = eq-ℚ-sim-fraction-ℤ x y H
```
+## See also
+
+- [Farey fractions](elementary-number-theory.farey-fractions.md) encode the type
+ of rational numbers between $0$ and $1$ by a mutual recursive construction.
+- [Unbounded Farey fractions](elementary-number-theory.unbounded-farey-fractions.md)
+ encode the type of all rational numbers by a mutal recursive construction.
+
## References
{{#bibliography}}
diff --git a/src/elementary-number-theory/reduced-integer-fractions.lagda.md b/src/elementary-number-theory/reduced-integer-fractions.lagda.md
index b74d316dd3..8a63db9ec7 100644
--- a/src/elementary-number-theory/reduced-integer-fractions.lagda.md
+++ b/src/elementary-number-theory/reduced-integer-fractions.lagda.md
@@ -19,6 +19,7 @@ open import elementary-number-theory.natural-numbers
open import elementary-number-theory.positive-and-negative-integers
open import elementary-number-theory.positive-integers
open import elementary-number-theory.relatively-prime-integers
+open import elementary-number-theory.unit-similarity-integers
open import foundation.action-on-identifications-functions
open import foundation.coproduct-types
@@ -38,12 +39,17 @@ open import foundation.universe-levels
## Idea
-A reduced fraction is a fraction in which its numerator and denominator are
-coprime.
+A {{#concept "reduced fraction" Agda=is-reduced-fraction-ℤ}} is a
+[fraction](elementary-number-theory.integer-fractions.md) in which its numerator
+and denominator are
+[coprime](elementary-number-theory.relatively-prime-integers.md). In the module
+[`elementary-number-theory.rational-numbers`](elementary-number-theory.rational-numbers.md)
+we will define the type `ℚ` of rational numbers to be the type of reduced
+integer fractions.
## Definitions
-### Reduced fraction
+### The predicate of being a reduced fraction
```agda
is-reduced-fraction-ℤ : fraction-ℤ → UU lzero
@@ -580,3 +586,7 @@ unique-reduce-fraction-ℤ x y H =
( eq-is-prop
( is-prop-is-positive-ℤ (int-reduce-denominator-fraction-ℤ y))))))
```
+
+## See also
+
+- [The type of rational numbers](elementary-number-theory.rational-numbers.md)
diff --git a/src/elementary-number-theory/relatively-prime-natural-numbers.lagda.md b/src/elementary-number-theory/relatively-prime-natural-numbers.lagda.md
index 01f59c2f4b..3d21e55146 100644
--- a/src/elementary-number-theory/relatively-prime-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/relatively-prime-natural-numbers.lagda.md
@@ -131,9 +131,7 @@ is-relatively-prime-quotient-div-gcd-ℕ a b nz =
( is-gcd-gcd-ℕ
( quotient-div-ℕ (gcd-ℕ a b) a (div-left-factor-gcd-ℕ a b))
( quotient-div-ℕ (gcd-ℕ a b) b (div-right-factor-gcd-ℕ a b)))
- ( is-gcd-quotient-div-gcd-ℕ
- ( is-nonzero-gcd-ℕ a b nz)
- ( is-common-divisor-gcd-ℕ a b))) ∙
+ ( is-gcd-quotient-div-gcd-ℕ (is-common-divisor-gcd-ℕ a b))) ∙
( is-idempotent-quotient-div-ℕ
( gcd-ℕ a b)
( is-nonzero-gcd-ℕ a b nz)
diff --git a/src/elementary-number-theory/sieve-of-eratosthenes.lagda.md b/src/elementary-number-theory/sieve-of-eratosthenes.lagda.md
index 1727176161..9cdfa1b484 100644
--- a/src/elementary-number-theory/sieve-of-eratosthenes.lagda.md
+++ b/src/elementary-number-theory/sieve-of-eratosthenes.lagda.md
@@ -85,9 +85,9 @@ pr2 (in-sieve-of-eratosthenes-succ-factorial-ℕ zero-ℕ) x l d =
( is-zero-is-zero-div-ℕ x 2 d (is-zero-leq-zero-ℕ x l)))
pr1 (in-sieve-of-eratosthenes-succ-factorial-ℕ (succ-ℕ n)) =
concatenate-leq-le-ℕ
- { succ-ℕ n}
- { factorial-ℕ (succ-ℕ n)}
- { succ-ℕ (factorial-ℕ (succ-ℕ n))}
+ ( succ-ℕ n)
+ ( factorial-ℕ (succ-ℕ n))
+ ( succ-ℕ (factorial-ℕ (succ-ℕ n)))
( leq-factorial-ℕ (succ-ℕ n))
( succ-le-ℕ (factorial-ℕ (succ-ℕ n)))
pr2 (in-sieve-of-eratosthenes-succ-factorial-ℕ (succ-ℕ n)) x l (pair y p) with
diff --git a/src/elementary-number-theory/square-pyramidal-numbers.lagda.md b/src/elementary-number-theory/square-pyramidal-numbers.lagda.md
new file mode 100644
index 0000000000..285c1d87b8
--- /dev/null
+++ b/src/elementary-number-theory/square-pyramidal-numbers.lagda.md
@@ -0,0 +1,180 @@
+# The square pyramidal numbers
+
+```agda
+module elementary-number-theory.square-pyramidal-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.multiplication-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
+open import elementary-number-theory.pronic-numbers
+open import elementary-number-theory.squares-natural-numbers
+open import elementary-number-theory.sums-of-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.identity-types
+open import foundation.transport-along-identifications
+
+open import univalent-combinatorics.standard-finite-types
+```
+
+
+
+## Idea
+
+The $n$th
+{{#concept "square pyramidal number" Agda=square-pyramidal-number-ℕ OEIS=A000330 WDID=Q18949 WD="square pyramidal number"}}
+is the [sum](elementary-number-theory.sums-of-natural-numbers.md) of
+[squares](elementary-number-theory.squares-natural-numbers.md)
+
+$$
+ 1^2 + 2^2 + \cdots + n^2.
+$$
+
+A common exercise in mathematical induction states that the $n$th square
+pyramidal number is equal to
+
+$$
+ \frac{n(n+1)(2n+1)}{6}.
+$$
+
+The sequence of square pyramidal numbers is listed as A000330 in the
+[OEIS](literature.oeis.md) {{#cite OEIS}}.
+
+## Definitions
+
+### The square pyramidal numbers
+
+```agda
+square-pyramidal-number-ℕ : ℕ → ℕ
+square-pyramidal-number-ℕ n =
+ sum-Fin-ℕ (succ-ℕ n) (λ i → square-ℕ (nat-Fin (succ-ℕ n) i))
+```
+
+## Properties
+
+### Computing the square pyramidal numbers
+
+We will prove the identity
+
+$$
+ \sum_{k=0}^n k^2 = \frac{n(n+1)(2n+1)}{6}.
+$$
+
+In order to prove this, we first show that the sequence $a_n := n(n+1)(2n+1)$
+satisfies the recurrence
+
+$$
+ a_{n+1} = a_n + 6(n+1)^2.
+$$
+
+By this recurrence it follows that each $a_n$ is
+[divisible](elementary-number-theory.divisibility-natural-numbers.md) by $6$,
+and that $a_n$ is $6$ times the $n$th pyramidal number.
+
+The computation of the square pyramidal numbers is a common exercise in
+elementary number theory texts, such as exercise 1 of section 1.2 in
+{{#cite Andrews94}}.
+
+```agda
+dividend-square-pyramidal-number-ℕ : ℕ → ℕ
+dividend-square-pyramidal-number-ℕ n = pronic-number-ℕ n *ℕ odd-number-ℕ n
+
+dividend-square-pyramidal-number-succ-ℕ :
+ (n : ℕ) →
+ dividend-square-pyramidal-number-ℕ (succ-ℕ n) =
+ dividend-square-pyramidal-number-ℕ n +ℕ 6 *ℕ square-ℕ (succ-ℕ n)
+dividend-square-pyramidal-number-succ-ℕ n =
+ ( associative-mul-ℕ
+ ( succ-ℕ n)
+ ( succ-ℕ (succ-ℕ n))
+ ( odd-number-ℕ (succ-ℕ n))) ∙
+ ( ap
+ ( succ-ℕ n *ℕ_)
+ ( ( ap
+ ( succ-ℕ (succ-ℕ n) *ℕ_)
+ ( ap succ-ℕ (left-distributive-mul-add-ℕ 2 n 1))) ∙
+ ( left-distributive-mul-add-ℕ (succ-ℕ (succ-ℕ n)) (odd-number-ℕ n) 2) ∙
+ ( ( ap-add-ℕ
+ ( right-distributive-mul-add-ℕ n 2 (odd-number-ℕ n))
+ ( ( commutative-mul-ℕ (succ-ℕ (succ-ℕ n)) 2) ∙
+ ( left-distributive-mul-add-ℕ 2 (succ-ℕ n) 1))) ∙
+ ( associative-add-ℕ
+ ( n *ℕ odd-number-ℕ n)
+ ( 2 *ℕ odd-number-ℕ n)
+ ( 2 *ℕ succ-ℕ n +ℕ 2) ∙
+ ( ap
+ ( n *ℕ odd-number-ℕ n +ℕ_)
+ ( ( left-swap-add-ℕ (2 *ℕ odd-number-ℕ n) (2 *ℕ succ-ℕ n) 2) ∙
+ ( ap
+ ( 2 *ℕ succ-ℕ n +ℕ_)
+ ( inv (left-distributive-mul-add-ℕ 2 (odd-number-ℕ n) 1))) ∙
+ ( ap
+ ( 2 *ℕ succ-ℕ n +ℕ_)
+ ( ( ap (2 *ℕ_) (inv (left-distributive-mul-add-ℕ 2 n 1))) ∙
+ ( inv (associative-mul-ℕ 2 2 (succ-ℕ n))))) ∙
+ ( inv (right-distributive-mul-add-ℕ 2 4 (succ-ℕ n))))))))) ∙
+ ( left-distributive-mul-add-ℕ
+ ( succ-ℕ n)
+ ( n *ℕ odd-number-ℕ n)
+ ( 6 *ℕ succ-ℕ n)) ∙
+ ( ap-add-ℕ
+ ( ( left-swap-mul-ℕ (succ-ℕ n) n (odd-number-ℕ n)) ∙
+ ( inv (associative-mul-ℕ n (succ-ℕ n) (odd-number-ℕ n))))
+ ( left-swap-mul-ℕ (succ-ℕ n) 6 (succ-ℕ n)))
+
+div-6-dividend-square-pyramidal-number-ℕ :
+ (n : ℕ) → div-ℕ 6 (dividend-square-pyramidal-number-ℕ n)
+div-6-dividend-square-pyramidal-number-ℕ zero-ℕ = div-zero-ℕ 6
+div-6-dividend-square-pyramidal-number-ℕ (succ-ℕ n) =
+ tr
+ ( div-ℕ 6)
+ ( inv (dividend-square-pyramidal-number-succ-ℕ n))
+ ( div-add-ℕ 6
+ ( dividend-square-pyramidal-number-ℕ n)
+ ( 6 *ℕ square-ℕ (succ-ℕ n))
+ ( div-6-dividend-square-pyramidal-number-ℕ n)
+ ( div-mul-ℕ' (square-ℕ (succ-ℕ n)) 6 6 (refl-div-ℕ 6)))
+
+value-square-pyramidal-number-ℕ : ℕ → ℕ
+value-square-pyramidal-number-ℕ n =
+ quotient-div-ℕ 6
+ ( dividend-square-pyramidal-number-ℕ n)
+ ( div-6-dividend-square-pyramidal-number-ℕ n)
+
+eq-value-square-pyramidal-number-ℕ :
+ (n : ℕ) →
+ 6 *ℕ value-square-pyramidal-number-ℕ n = dividend-square-pyramidal-number-ℕ n
+eq-value-square-pyramidal-number-ℕ n =
+ eq-quotient-div-ℕ' 6
+ ( dividend-square-pyramidal-number-ℕ n)
+ ( div-6-dividend-square-pyramidal-number-ℕ n)
+
+compute-square-pyramidal-number-ℕ' :
+ (n : ℕ) →
+ 6 *ℕ square-pyramidal-number-ℕ n = dividend-square-pyramidal-number-ℕ n
+compute-square-pyramidal-number-ℕ' zero-ℕ = refl
+compute-square-pyramidal-number-ℕ' (succ-ℕ n) =
+ ( left-distributive-mul-add-ℕ 6
+ ( square-pyramidal-number-ℕ n)
+ ( square-ℕ (succ-ℕ n))) ∙
+ ( ap (_+ℕ 6 *ℕ square-ℕ (succ-ℕ n)) (compute-square-pyramidal-number-ℕ' n)) ∙
+ ( inv (dividend-square-pyramidal-number-succ-ℕ n))
+
+compute-square-pyramidal-number-ℕ :
+ (n : ℕ) → square-pyramidal-number-ℕ n = value-square-pyramidal-number-ℕ n
+compute-square-pyramidal-number-ℕ n =
+ is-injective-left-mul-ℕ 6
+ ( is-nonzero-succ-ℕ 5)
+ ( ( compute-square-pyramidal-number-ℕ' n) ∙
+ ( inv (eq-value-square-pyramidal-number-ℕ n)))
+```
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/squares-integers.lagda.md b/src/elementary-number-theory/squares-integers.lagda.md
index 2497b17b33..04d300199e 100644
--- a/src/elementary-number-theory/squares-integers.lagda.md
+++ b/src/elementary-number-theory/squares-integers.lagda.md
@@ -1,4 +1,4 @@
-# Squares in the integers
+# Squares of integers
```agda
module elementary-number-theory.squares-integers where
@@ -8,11 +8,15 @@ module elementary-number-theory.squares-integers where
```agda
open import elementary-number-theory.absolute-value-integers
+open import elementary-number-theory.addition-integers
+open import elementary-number-theory.addition-natural-numbers
open import elementary-number-theory.integers
open import elementary-number-theory.multiplication-integers
+open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.multiplication-positive-and-negative-integers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.nonnegative-integers
+open import elementary-number-theory.parity-integers
open import elementary-number-theory.positive-and-negative-integers
open import elementary-number-theory.positive-integers
open import elementary-number-theory.squares-natural-numbers
@@ -24,6 +28,7 @@ open import foundation.dependent-pair-types
open import foundation.identity-types
open import foundation.logical-equivalences
open import foundation.negation
+open import foundation.unit-type
open import foundation.universe-levels
open import foundation-core.cartesian-product-types
@@ -32,24 +37,75 @@ open import foundation-core.transport-along-identifications
-## Definition
+## Idea
+
+The {{#concept "square" Disambiguation="integer" Agda=square-ℤ}} `a²` of an
+[integer](elementary-number-theory.integers.md) `a` is the
+[product](elementary-number-theory.multiplication-natural-numbers.md)
+
+```text
+ a² := a * a
+```
+
+of `a` with itself.
+
+## Definitions
+
+### The square of an integer
```agda
square-ℤ : ℤ → ℤ
square-ℤ a = mul-ℤ a a
+```
+### The cube of an integer
+
+```agda
cube-ℤ : ℤ → ℤ
cube-ℤ a = mul-ℤ (square-ℤ a) a
+```
+
+### The predicate on integers of being square
+```agda
is-square-ℤ : ℤ → UU lzero
is-square-ℤ a = Σ ℤ (λ x → a = square-ℤ x)
+```
+
+### The square root of a square integer
+```agda
square-root-ℤ : (a : ℤ) → is-square-ℤ a → ℤ
square-root-ℤ _ (root , _) = root
```
## Properties
+### The integer square of a natural number is the integer of its square
+
+```agda
+compute-square-int-ℕ : (n : ℕ) → square-ℤ (int-ℕ n) = int-ℕ (square-ℕ n)
+compute-square-int-ℕ n = mul-int-ℕ n n
+```
+
+### The square of an integer is the square of its absolute value
+
+```agda
+compute-square-abs-ℤ : (a : ℤ) → square-ℤ a = int-ℕ (square-ℕ (abs-ℤ a))
+compute-square-abs-ℤ (inl x) = compute-mul-ℤ (inl x) (inl x)
+compute-square-abs-ℤ (inr (inl star)) = refl
+compute-square-abs-ℤ (inr (inr x)) = mul-int-ℕ (succ-ℕ x) (succ-ℕ x)
+
+compute-square-abs-ℤ' :
+ (a : ℤ) → square-ℤ a = square-ℤ (int-abs-ℤ a)
+compute-square-abs-ℤ' (inl x) =
+ compute-mul-ℤ (inl x) (inl x) ∙ inv (mul-int-ℕ (succ-ℕ x) (succ-ℕ x))
+compute-square-abs-ℤ' (inr (inl star)) =
+ refl
+compute-square-abs-ℤ' (inr (inr x)) =
+ refl
+```
+
### Squares in ℤ are nonnegative
```agda
@@ -59,22 +115,29 @@ is-nonnegative-square-ℤ a =
( λ H → is-nonnegative-is-positive-ℤ (is-positive-mul-negative-ℤ H H))
( λ H → is-nonnegative-mul-ℤ H H)
( decide-is-negative-is-nonnegative-ℤ {a})
+
+is-nonnegative-is-square-ℤ : {a : ℤ} → is-square-ℤ a → is-nonnegative-ℤ a
+is-nonnegative-is-square-ℤ (r , refl) = is-nonnegative-square-ℤ r
+```
+
+### The square of an integer is equal to the square of its negative
+
+```agda
+compute-square-neg-ℤ :
+ (a : ℤ) → square-ℤ a = square-ℤ (neg-ℤ a)
+compute-square-neg-ℤ a = inv (double-negative-law-mul-ℤ a a)
```
### The squares in ℤ are exactly the squares in ℕ
```agda
is-square-int-is-square-nat : {n : ℕ} → is-square-ℕ n → is-square-ℤ (int-ℕ n)
-is-square-int-is-square-nat (root , pf-square) =
- ( ( int-ℕ root) ,
- ( ( ap int-ℕ pf-square) ∙
- ( inv (mul-int-ℕ root root))))
+is-square-int-is-square-nat (r , refl) =
+ ( int-ℕ r , inv (compute-square-int-ℕ r))
is-square-nat-is-square-int : {a : ℤ} → is-square-ℤ a → is-square-ℕ (abs-ℤ a)
-is-square-nat-is-square-int (root , pf-square) =
- ( ( abs-ℤ root) ,
- ( ( ap abs-ℤ pf-square) ∙
- ( multiplicative-abs-ℤ root root)))
+is-square-nat-is-square-int (r , refl) =
+ ( abs-ℤ r , distributive-abs-mul-ℤ r r)
iff-is-square-int-is-square-nat :
(n : ℕ) → is-square-ℕ n ↔ is-square-ℤ (int-ℕ n)
@@ -84,17 +147,16 @@ pr2 (iff-is-square-int-is-square-nat n) H =
iff-is-nonneg-square-nat-is-square-int :
(a : ℤ) → is-square-ℤ a ↔ is-nonnegative-ℤ a × is-square-ℕ (abs-ℤ a)
-pr1 (iff-is-nonneg-square-nat-is-square-int a) (root , pf-square) =
- ( ( tr is-nonnegative-ℤ (inv pf-square) (is-nonnegative-square-ℤ root)) ,
- ( is-square-nat-is-square-int (root , pf-square)))
-pr2
- ( iff-is-nonneg-square-nat-is-square-int a) (pf-nonneg , (root , pf-square)) =
- ( ( int-ℕ root) ,
- ( ( inv (int-abs-is-nonnegative-ℤ a pf-nonneg)) ∙
- ( pr2 (is-square-int-is-square-nat (root , pf-square)))))
+pr1 (iff-is-nonneg-square-nat-is-square-int a) H =
+ ( is-nonnegative-is-square-ℤ H , is-square-nat-is-square-int H)
+pr2 (iff-is-nonneg-square-nat-is-square-int a) (H , r , p) =
+ ( int-ℕ r ,
+ inv (int-abs-is-nonnegative-ℤ a H) ∙
+ ap int-ℕ p ∙
+ inv (compute-square-int-ℕ r))
```
-### Squareness in ℤ is decidable
+### Being a square integer is decidable
```agda
is-decidable-is-square-ℤ : (a : ℤ) → is-decidable (is-square-ℤ a)
@@ -107,3 +169,102 @@ is-decidable-is-square-ℤ (inr (inr n)) =
( is-square-nat-is-square-int)
( is-decidable-is-square-ℕ (succ-ℕ n))
```
+
+### Squares of successors
+
+For any integer `a` we have the equation
+
+```text
+ (a + 1)² = a² + 2a + 1.
+```
+
+```agda
+square-succ-ℤ :
+ (a : ℤ) → square-ℤ (succ-ℤ a) = square-ℤ a +ℤ int-ℕ 2 *ℤ a +ℤ int-ℕ 1
+square-succ-ℤ a =
+ double-successor-law-mul-ℤ a a ∙
+ ap (_+ℤ int-ℕ 1) (associative-add-ℤ (square-ℤ a) a a)
+```
+
+### Squares of double successors
+
+For any `n` we have `(n + 2)² = n² + 4n + 4`
+
+```agda
+square-succ-succ-ℤ :
+ (a : ℤ) →
+ square-ℤ (succ-ℤ (succ-ℤ a)) = square-ℤ a +ℤ int-ℕ 4 *ℤ a +ℤ int-ℕ 4
+square-succ-succ-ℤ a =
+ ap
+ ( square-ℤ)
+ ( ap succ-ℤ (inv (right-add-one-ℤ a)) ∙
+ inv (right-add-one-ℤ (a +ℤ one-ℤ)) ∙
+ associative-add-ℤ a one-ℤ one-ℤ) ∙
+ double-distributive-mul-add-ℤ a (int-ℕ 2) a (int-ℕ 2) ∙
+ inv
+ ( associative-add-ℤ (square-ℤ a +ℤ a *ℤ int-ℕ 2) (int-ℕ 2 *ℤ a) (int-ℕ 4)) ∙
+ ap
+ ( _+ℤ int-ℕ 4)
+ ( associative-add-ℤ (square-ℤ a) (a *ℤ int-ℕ 2) (int-ℕ 2 *ℤ a) ∙
+ ap
+ ( square-ℤ a +ℤ_)
+ ( ap (_+ℤ int-ℕ 2 *ℤ a) (commutative-mul-ℤ a (int-ℕ 2)) ∙
+ inv (right-distributive-mul-add-ℤ (int-ℕ 2) (int-ℕ 2) a)))
+```
+
+### Squares distribute over multiplication
+
+```agda
+distributive-square-mul-ℤ :
+ (a b : ℤ) → square-ℤ (a *ℤ b) = square-ℤ a *ℤ square-ℤ b
+distributive-square-mul-ℤ a b =
+ interchange-law-mul-mul-ℤ a b a b
+```
+
+### Equivalent characterizations of a number being even in terms of its square
+
+Consider a integer `n`. The following are equivalent:
+
+- The number `n` is even.
+- Its square is even.
+- Its square is divisible by 4.
+
+```agda
+div-four-square-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → div-ℤ 4 (square-ℤ a)
+div-four-square-is-even-ℤ a H = ?
+```
+
+```text
+div-four-square-is-even-ℤ :
+ (a : ℤ) → is-even-ℤ a → div-ℤ 4 (square-ℤ a)
+dif-four-square-is-even-ℤ = ?
+
+is-even-square-is-even-ℤ :
+ (n : ℤ) → is-even-ℤ n → is-even-ℤ (square-ℤ n)
+is-even-square-is-even-ℤ .(m *ℤ 2) (m , refl) =
+ is-even-div-4-ℤ _ (div-four-square-is-even-ℤ (m *ℤ 2) (m , refl))
+
+is-even-is-even-square-ℤ :
+ (n : ℤ) → is-even-ℤ (square-ℤ n) → is-even-ℤ n
+is-even-is-even-square-ℤ zero-ℤ H = is-even-zero-ℤ
+is-even-is-even-square-ℤ (succ-ℤ zero-ℤ) (zero-ℤ , ())
+is-even-is-even-square-ℤ (succ-ℤ zero-ℤ) (succ-ℤ k , ())
+is-even-is-even-square-ℤ (succ-ℤ (succ-ℤ n)) (m , p) =
+ is-even-succ-succ-is-even-ℤ n
+ ( is-even-is-even-square-ℤ n
+ ( is-even-left-summand-ℤ
+ ( square-ℤ n)
+ ( 4 *ℤ n)
+ ( is-even-div-4-ℤ (4 *ℤ n) (n , commutative-mul-ℤ n 4))
+ ( is-even-left-summand-ℤ
+ ( square-ℤ n +ℤ 4 *ℤ n)
+ ( 4)
+ ( 2 , refl)
+ ( m , p ∙ square-succ-succ-ℤ n))))
+
+is-even-div-four-square-ℤ :
+ (n : ℤ) → div-ℤ 4 (square-ℤ n) → is-even-ℤ n
+is-even-div-four-square-ℤ n H =
+ is-even-is-even-square-ℤ n (is-even-div-4-ℤ (square-ℤ n) H)
+```
diff --git a/src/elementary-number-theory/squares-natural-numbers.lagda.md b/src/elementary-number-theory/squares-natural-numbers.lagda.md
index f8afd7063e..098953bf8d 100644
--- a/src/elementary-number-theory/squares-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/squares-natural-numbers.lagda.md
@@ -1,4 +1,4 @@
-# Squares in the natural numbers
+# Squares of natural numbers
```agda
module elementary-number-theory.squares-natural-numbers where
@@ -8,22 +8,36 @@ module elementary-number-theory.squares-natural-numbers where
```agda
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.bounded-divisibility-natural-numbers
+open import elementary-number-theory.congruence-natural-numbers
open import elementary-number-theory.decidable-types
+open import elementary-number-theory.distance-natural-numbers
+open import elementary-number-theory.divisibility-natural-numbers
open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.exponentiation-natural-numbers
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.parity-natural-numbers
+open import elementary-number-theory.pronic-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+open import elementary-number-theory.sums-of-natural-numbers
+open import foundation.action-on-identifications-functions
open import foundation.coproduct-types
open import foundation.decidable-types
open import foundation.dependent-pair-types
+open import foundation.empty-types
open import foundation.identity-types
+open import foundation.injective-maps
open import foundation.negation
open import foundation.unit-type
open import foundation.universe-levels
open import foundation-core.cartesian-product-types
open import foundation-core.transport-along-identifications
+
+open import univalent-combinatorics.standard-finite-types
```
@@ -46,7 +60,7 @@ of `n` with itself.
```agda
square-ℕ : ℕ → ℕ
-square-ℕ n = mul-ℕ n n
+square-ℕ n = n *ℕ n
```
### The predicate of being a square of a natural number
@@ -65,19 +79,58 @@ square-root-ℕ _ (root , _) = root
## Properties
+### Squares are second powers
+
+The equality `square-ℕ n = n ^ℕ 2` holds by definition.
+
+```agda
+compute-exp-2-ℕ :
+ (n : ℕ) → square-ℕ n = n ^ℕ 2
+compute-exp-2-ℕ n = refl
+```
+
### Squares of successors
+For any `n` we have the equations
+
+```text
+ (n + 1)² = (n + 2)n + 1
+ (n + 1)² = n² + 2n + 1.
+```
+
```agda
-square-succ-ℕ :
- (n : ℕ) →
- square-ℕ (succ-ℕ n) = succ-ℕ ((succ-ℕ (succ-ℕ n)) *ℕ n)
+square-succ-ℕ' :
+ (n : ℕ) → square-ℕ (succ-ℕ n) = (n +ℕ 2) *ℕ n +ℕ 1
+square-succ-ℕ' n =
+ right-successor-law-mul-ℕ (succ-ℕ n) n
+
+square-succ-ℕ : (n : ℕ) → square-ℕ (succ-ℕ n) = square-ℕ n +ℕ 2 *ℕ n +ℕ 1
square-succ-ℕ n =
- ( right-successor-law-mul-ℕ (succ-ℕ n) n) ∙
- ( commutative-add-ℕ (succ-ℕ n) ((succ-ℕ n) *ℕ n))
+ square-succ-ℕ' n ∙ ap succ-ℕ (right-distributive-mul-add-ℕ n 2 n)
+```
+
+### Squares of nonzero numbers are nonzero
+
+```agda
+is-nonzero-square-is-successor-ℕ :
+ (n : ℕ) → is-successor-ℕ n → is-nonzero-ℕ (square-ℕ n)
+is-nonzero-square-is-successor-ℕ ._ (n , refl) =
+ is-nonzero-is-successor-ℕ ((n +ℕ 2) *ℕ n , square-succ-ℕ' n)
+
+is-nonzero-square-is-nonzero-ℕ :
+ (n : ℕ) → is-nonzero-ℕ n → is-nonzero-ℕ (square-ℕ n)
+is-nonzero-square-is-nonzero-ℕ n H =
+ is-nonzero-square-is-successor-ℕ n (is-successor-is-nonzero-ℕ H)
+```
+
+### Squares of double successors
+For any `n` we have `(n + 2)² = n² + 4n + 4`
+
+```agda
square-succ-succ-ℕ :
(n : ℕ) →
- square-ℕ (succ-ℕ (succ-ℕ n)) = square-ℕ n +ℕ 2 *ℕ n +ℕ 2 *ℕ n +ℕ 4
+ square-ℕ (succ-ℕ (succ-ℕ n)) = square-ℕ n +ℕ 4 *ℕ n +ℕ 4
square-succ-succ-ℕ n =
equational-reasoning
square-ℕ (n +ℕ 2)
@@ -93,86 +146,525 @@ square-succ-succ-ℕ n =
( ap-add-ℕ {square-ℕ n +ℕ 2 *ℕ n} {2 *ℕ (n +ℕ 2)}
( refl)
( left-distributive-mul-add-ℕ 2 n 2))
+ = square-ℕ n +ℕ (2 *ℕ n +ℕ 2 *ℕ n +ℕ 4)
+ by
+ associative-add-ℕ (square-ℕ n) (2 *ℕ n) (2 *ℕ n +ℕ 4)
+ = square-ℕ n +ℕ 4 *ℕ n +ℕ 4
+ by
+ ap
+ ( add-ℕ (square-ℕ n))
+ ( ap
+ ( add-ℕ' 4)
+ ( ( inv (associative-add-ℕ (2 *ℕ n) (0 +ℕ n) n)) ∙
+ ( inv (ap (add-ℕ' n) (associative-add-ℕ (2 *ℕ n) 0 n)))))
+
+square-succ-succ-ℕ' :
+ (n : ℕ) → square-ℕ (succ-ℕ (succ-ℕ n)) = square-ℕ n +ℕ 4 *ℕ (n +ℕ 1)
+square-succ-succ-ℕ' n =
+ square-succ-succ-ℕ n ∙
+ ap (square-ℕ n +ℕ_) (inv (left-distributive-mul-add-ℕ 4 n 1))
```
-### `n > √n` for `n > 1`
-
-The idea is to assume `n = m + 2 ≤ sqrt(m + 2)` for some `m : ℕ` and derive a
-contradiction by squaring both sides of the inequality
-
-```agda
-greater-than-square-root-ℕ :
- (n root : ℕ) → ¬ ((n +ℕ 2 ≤-ℕ root) × (n +ℕ 2 = square-ℕ root))
-greater-than-square-root-ℕ n root (pf-leq , pf-eq) =
- reflects-leq-left-add-ℕ
- ( square-ℕ root)
- ( square-ℕ n +ℕ 2 *ℕ n +ℕ n +ℕ 2)
- ( 0)
- ( tr
- ( leq-ℕ (square-ℕ n +ℕ 2 *ℕ n +ℕ n +ℕ 2 +ℕ square-ℕ root))
- ( inv (left-unit-law-add-ℕ (square-ℕ root)))
- ( concatenate-eq-leq-ℕ
- ( square-ℕ root)
- ( inv
- ( lemma ∙
- ( ap-add-ℕ {square-ℕ n +ℕ 2 *ℕ n +ℕ n +ℕ 2} {n +ℕ 2}
- ( refl)
- ( pf-eq))))
- ( preserves-leq-mul-ℕ (n +ℕ 2) root (n +ℕ 2) root pf-leq pf-leq)))
- where
- lemma : square-ℕ (n +ℕ 2) = square-ℕ n +ℕ 2 *ℕ n +ℕ n +ℕ 2 +ℕ n +ℕ 2
- lemma =
- equational-reasoning
- square-ℕ (n +ℕ 2)
- = square-ℕ n +ℕ 2 *ℕ n +ℕ 2 *ℕ n +ℕ 4
- by (square-succ-succ-ℕ n)
- = square-ℕ n +ℕ 2 *ℕ n +ℕ (n +ℕ 2 +ℕ n +ℕ 2)
- by
- ( ap-add-ℕ {square-ℕ n +ℕ 2 *ℕ n} {2 *ℕ n +ℕ 4}
- ( refl)
- ( equational-reasoning
- 2 *ℕ n +ℕ 4
- = n +ℕ n +ℕ 2 +ℕ 2
- by
- ( ap-add-ℕ {2 *ℕ n} {4}
- ( left-two-law-mul-ℕ n)
- ( refl))
- = n +ℕ 2 +ℕ 2 +ℕ n
- by (commutative-add-ℕ n (n +ℕ 2 +ℕ 2))
- = n +ℕ 2 +ℕ (2 +ℕ n)
- by (associative-add-ℕ (n +ℕ 2) 2 n)
- = n +ℕ 2 +ℕ (n +ℕ 2)
- by
- ( ap-add-ℕ {n +ℕ 2} {2 +ℕ n}
- ( refl)
- ( commutative-add-ℕ 2 n))))
- = square-ℕ n +ℕ 2 *ℕ n +ℕ n +ℕ 2 +ℕ n +ℕ 2
- by
- ( inv
- ( associative-add-ℕ
- ( square-ℕ n +ℕ 2 *ℕ n)
- ( n +ℕ 2)
- ( n +ℕ 2)))
-```
-
-### Squareness in ℕ is decidable
-
-```agda
-is-decidable-big-root :
- (n : ℕ) → is-decidable (Σ ℕ (λ root → (n ≤-ℕ root) × (n = square-ℕ root)))
-is-decidable-big-root 0 = inl (0 , star , refl)
-is-decidable-big-root 1 = inl (1 , star , refl)
-is-decidable-big-root (succ-ℕ (succ-ℕ n)) =
- inr (λ H → greater-than-square-root-ℕ n (pr1 H) (pr2 H))
+### The square function is order preserving
+
+```agda
+preserves-order-square-ℕ :
+ (m n : ℕ) → m ≤-ℕ n → square-ℕ m ≤-ℕ square-ℕ n
+preserves-order-square-ℕ m n H =
+ preserves-order-mul-ℕ m n m n H H
+
+preserves-strict-order-square-ℕ :
+ (m n : ℕ) → m <-ℕ n → square-ℕ m <-ℕ square-ℕ n
+preserves-strict-order-square-ℕ m n H =
+ preserves-strict-order-mul-ℕ m n m n H H
+```
+
+### The square function reflects the order on the natural numbers
+
+For any two natural numbers `m` and `n` we have `m² ≤ n² → m ≤ n` and
+`m² < n² → m < n`.
+
+```agda
+reflects-order-square-ℕ :
+ (m n : ℕ) → square-ℕ m ≤-ℕ square-ℕ n → m ≤-ℕ n
+reflects-order-square-ℕ m n H =
+ leq-not-le-ℕ n m
+ ( λ K →
+ contradiction-le-ℕ
+ ( square-ℕ n)
+ ( square-ℕ m)
+ ( preserves-strict-order-square-ℕ n m K)
+ ( H))
+
+reflects-strict-order-square-ℕ :
+ (m n : ℕ) → square-ℕ m <-ℕ square-ℕ n → m <-ℕ n
+reflects-strict-order-square-ℕ m n H =
+ le-not-leq-ℕ n m
+ ( λ K →
+ contradiction-le-ℕ
+ ( square-ℕ m)
+ ( square-ℕ n)
+ ( H)
+ ( preserves-order-square-ℕ n m K))
+
+le-zero-le-zero-square-ℕ :
+ (n : ℕ) → 0 <-ℕ square-ℕ n → 0 <-ℕ n
+le-zero-le-zero-square-ℕ n =
+ reflects-strict-order-square-ℕ 0 n
+```
+
+### The square function is injective
+
+```agda
+is-injective-square-ℕ : is-injective square-ℕ
+is-injective-square-ℕ {x} {y} p =
+ antisymmetric-leq-ℕ x y
+ ( reflects-order-square-ℕ x y (leq-eq-ℕ (square-ℕ x) (square-ℕ y) p))
+ ( reflects-order-square-ℕ y x (leq-eq-ℕ (square-ℕ y) (square-ℕ x) (inv p)))
+```
+
+### Squares distribute over multiplication
+
+```agda
+distributive-square-mul-ℕ :
+ (m n : ℕ) → square-ℕ (m *ℕ n) = square-ℕ m *ℕ square-ℕ n
+distributive-square-mul-ℕ m n =
+ interchange-law-mul-mul-ℕ m n m n
+```
+
+### The square function is inflationary
+
+```agda
+is-inflationary-square-ℕ :
+ (n : ℕ) → n ≤-ℕ square-ℕ n
+is-inflationary-square-ℕ zero-ℕ =
+ star
+is-inflationary-square-ℕ (succ-ℕ n) =
+ concatenate-eq-leq-ℕ
+ ( square-ℕ (succ-ℕ n))
+ ( inv (right-unit-law-mul-ℕ (succ-ℕ n)))
+ ( preserves-order-right-mul-ℕ (succ-ℕ n) 1 (succ-ℕ n) star)
+```
+
+### If a number `n` has a square root, then the square root is at most `n`
+
+```agda
+upper-bound-square-root-ℕ :
+ (n : ℕ) (H : is-square-ℕ n) → square-root-ℕ n H ≤-ℕ n
+upper-bound-square-root-ℕ .(square-ℕ x) (x , refl) =
+ is-inflationary-square-ℕ x
+```
+
+### Any number greater than 1 is strictly less than its square
+
+```agda
+strict-is-inflationary-square-ℕ :
+ (n : ℕ) → 1 <-ℕ n → n <-ℕ square-ℕ n
+strict-is-inflationary-square-ℕ (succ-ℕ (succ-ℕ zero-ℕ)) H = star
+strict-is-inflationary-square-ℕ (succ-ℕ (succ-ℕ (succ-ℕ n))) H =
+ concatenate-le-eq-ℕ
+ ( n +ℕ 3)
+ ( (n +ℕ 4) *ℕ (n +ℕ 2) +ℕ 1)
+ ( square-ℕ (n +ℕ 3))
+ ( transitive-le-ℕ
+ ( n +ℕ 2)
+ ( square-ℕ (n +ℕ 2))
+ ( square-ℕ (n +ℕ 2) +ℕ (n +ℕ 2) +ℕ (n +ℕ 2))
+ ( transitive-le-ℕ
+ ( square-ℕ (n +ℕ 2))
+ ( square-ℕ (n +ℕ 2) +ℕ (n +ℕ 2))
+ ( square-ℕ (n +ℕ 2) +ℕ (n +ℕ 2) +ℕ (n +ℕ 2))
+ ( le-add-succ-ℕ (square-ℕ (n +ℕ 2) +ℕ (n +ℕ 2)) (n +ℕ 1))
+ ( le-add-succ-ℕ (square-ℕ (n +ℕ 2)) (n +ℕ 1)))
+ ( strict-is-inflationary-square-ℕ (succ-ℕ (succ-ℕ n)) star))
+ ( inv (square-succ-ℕ' (n +ℕ 2)))
+```
+
+### If a number `n` greater than 1 has a square root, then its square root is strictly smaller than `n`
+
+```agda
+strict-upper-bound-square-root-ℕ :
+ (n : ℕ) → 1 <-ℕ n → (H : is-square-ℕ n) → square-root-ℕ n H <-ℕ n
+strict-upper-bound-square-root-ℕ ._ B (succ-ℕ (succ-ℕ x) , refl) =
+ strict-is-inflationary-square-ℕ (x +ℕ 2) star
+```
+
+### If `n² ≤ n`, then `n ≤ 1`
+
+```agda
+leq-one-leq-square-ℕ :
+ (n : ℕ) → square-ℕ n ≤-ℕ n → n ≤-ℕ 1
+leq-one-leq-square-ℕ zero-ℕ H = star
+leq-one-leq-square-ℕ (succ-ℕ zero-ℕ) H = star
+leq-one-leq-square-ℕ (succ-ℕ (succ-ℕ n)) H =
+ ex-falso
+ ( contradiction-le-ℕ
+ ( n +ℕ 2)
+ ( square-ℕ (n +ℕ 2))
+ ( strict-is-inflationary-square-ℕ (n +ℕ 2) star)
+ ( H))
+```
+
+### If the square root of a perfect square `n` is greater than or equal to `n`, then `n ≤ 1`
+
+```agda
+leq-one-leq-square-root-ℕ :
+ (n : ℕ) (H : is-square-ℕ n) → n ≤-ℕ square-root-ℕ n H → n ≤-ℕ 1
+leq-one-leq-square-root-ℕ ._ (x , refl) H =
+ leq-one-leq-square-ℕ (square-ℕ x) (preserves-order-square-ℕ (square-ℕ x) x H)
+```
+
+### The strict inequality `n² < n` never holds
+
+```agda
+not-le-square-ℕ :
+ (n : ℕ) → ¬ (square-ℕ n <-ℕ n)
+not-le-square-ℕ n H =
+ contradiction-le-ℕ
+ ( square-ℕ n)
+ ( n)
+ ( H)
+ ( is-inflationary-square-ℕ n)
+```
+
+### Being a square natural number is decidable
+
+```agda
+has-greater-root-ℕ : (n : ℕ) → UU lzero
+has-greater-root-ℕ n = Σ ℕ (λ x → (n ≤-ℕ x) × (n = square-ℕ x))
+
+is-decidable-has-greater-root-ℕ :
+ (n : ℕ) → is-decidable (has-greater-root-ℕ n)
+is-decidable-has-greater-root-ℕ 0 = inl (0 , star , refl)
+is-decidable-has-greater-root-ℕ 1 = inl (1 , star , refl)
+is-decidable-has-greater-root-ℕ (succ-ℕ (succ-ℕ n)) =
+ inr ( λ (x , b , p) → leq-one-leq-square-root-ℕ (n +ℕ 2) (x , p) b)
is-decidable-is-square-ℕ : (n : ℕ) → is-decidable (is-square-ℕ n)
is-decidable-is-square-ℕ n =
is-decidable-Σ-ℕ n
( λ x → n = square-ℕ x)
( λ x → has-decidable-equality-ℕ n (square-ℕ x))
- ( is-decidable-big-root n)
+ ( is-decidable-has-greater-root-ℕ n)
+```
+
+### Any number divides its own square
+
+In other words, the squaring function is inflationary with respect to
+divisibility.
+
+```agda
+is-inflationary-bounded-div-square-ℕ :
+ (n : ℕ) → bounded-div-ℕ n (square-ℕ n)
+pr1 (is-inflationary-bounded-div-square-ℕ n) = n
+pr1 (pr2 (is-inflationary-bounded-div-square-ℕ n)) = is-inflationary-square-ℕ n
+pr2 (pr2 (is-inflationary-bounded-div-square-ℕ n)) = refl
+
+is-inflationary-div-square-ℕ :
+ (n : ℕ) → div-ℕ n (square-ℕ n)
+is-inflationary-div-square-ℕ n =
+ div-bounded-div-ℕ n (square-ℕ n) (is-inflationary-bounded-div-square-ℕ n)
+```
+
+### Equivalent characterizations of a number being even in terms of its square
+
+Consider a natural number `n`. The following are equivalent:
+
+- The number `n` is even.
+- Its square is even.
+- Its square is divisible by 4.
+
+```agda
+compute-square-even-number-ℕ :
+ (n : ℕ) → square-ℕ (even-number-ℕ n) = 4 *ℕ square-ℕ n
+compute-square-even-number-ℕ n =
+ distributive-square-mul-ℕ 2 n
+
+div-four-square-is-even-ℕ :
+ (n : ℕ) → is-even-ℕ n → div-ℕ 4 (square-ℕ n)
+pr1 (div-four-square-is-even-ℕ .(m *ℕ 2) (m , refl)) =
+ square-ℕ m
+pr2 (div-four-square-is-even-ℕ .(m *ℕ 2) (m , refl)) =
+ inv (distributive-square-mul-ℕ m 2)
+
+is-even-square-is-even-ℕ :
+ (n : ℕ) → is-even-ℕ n → is-even-ℕ (square-ℕ n)
+is-even-square-is-even-ℕ .(m *ℕ 2) (m , refl) =
+ is-even-div-4-ℕ _ (div-four-square-is-even-ℕ (m *ℕ 2) (m , refl))
+
+is-even-is-even-square-ℕ :
+ (n : ℕ) → is-even-ℕ (square-ℕ n) → is-even-ℕ n
+is-even-is-even-square-ℕ zero-ℕ H = is-even-zero-ℕ
+is-even-is-even-square-ℕ (succ-ℕ zero-ℕ) (zero-ℕ , ())
+is-even-is-even-square-ℕ (succ-ℕ zero-ℕ) (succ-ℕ k , ())
+is-even-is-even-square-ℕ (succ-ℕ (succ-ℕ n)) (m , p) =
+ is-even-succ-succ-is-even-ℕ n
+ ( is-even-is-even-square-ℕ n
+ ( is-even-left-summand-ℕ
+ ( square-ℕ n)
+ ( 4 *ℕ n)
+ ( is-even-div-4-ℕ (4 *ℕ n) (n , commutative-mul-ℕ n 4))
+ ( is-even-left-summand-ℕ
+ ( square-ℕ n +ℕ 4 *ℕ n)
+ ( 4)
+ ( 2 , refl)
+ ( m , p ∙ square-succ-succ-ℕ n))))
+
+is-even-div-four-square-ℕ :
+ (n : ℕ) → div-ℕ 4 (square-ℕ n) → is-even-ℕ n
+is-even-div-four-square-ℕ n H =
+ is-even-is-even-square-ℕ n (is-even-div-4-ℕ (square-ℕ n) H)
+```
+
+### Equivalent characterizations of a number being odd in terms of its square
+
+Consider a natural number `n`. The following are equivalent:
+
+- The number `n` is odd.
+- Its square is odd.
+- Its square is congruent to `1` modulo `4`.
+- Its square is congruent to `1` modulo `8`.
+
+**Proof.** If `n` is of the form `2k + 1`, then its square is of the form
+`4k(k+1) + 1`. Since the number `k(k + 1)` is even, it follows that the square
+of an odd number is congruent to `1` modulo `8`. Further more, since squares of
+even numbers are even, and hence not congruent to `1` modulo `8`, we get a
+logical equivalence.
+
+```agda
+square-odd-number-ℕ : ℕ → ℕ
+square-odd-number-ℕ n = 4 *ℕ square-ℕ n +ℕ 4 *ℕ n +ℕ 1
+
+square-odd-number-ℕ' : ℕ → ℕ
+square-odd-number-ℕ' n = 4 *ℕ (n *ℕ (n +ℕ 1)) +ℕ 1
+
+compute-square-odd-number-ℕ :
+ (n : ℕ) → square-ℕ (odd-number-ℕ n) = square-odd-number-ℕ n
+compute-square-odd-number-ℕ n =
+ square-succ-ℕ (2 *ℕ n) ∙
+ ap
+ ( succ-ℕ)
+ ( ap-add-ℕ
+ ( compute-square-even-number-ℕ n)
+ ( inv (associative-mul-ℕ 2 2 n)))
+
+compute-square-odd-number-ℕ' :
+ (n : ℕ) → square-ℕ (odd-number-ℕ n) = square-odd-number-ℕ' n
+compute-square-odd-number-ℕ' n =
+ compute-square-odd-number-ℕ n ∙
+ inv
+ ( ap
+ ( succ-ℕ)
+ ( ( ap (4 *ℕ_) ( right-successor-law-mul-ℕ n n)) ∙
+ ( left-distributive-mul-add-ℕ 4 (square-ℕ n) n)))
+
+compute-distance-to-1-square-odd-number-ℕ :
+ (n : ℕ) → dist-ℕ (square-ℕ (odd-number-ℕ n)) 1 = 4 *ℕ (n *ℕ (n +ℕ 1))
+compute-distance-to-1-square-odd-number-ℕ n =
+ ( ap (λ x → dist-ℕ x 1) (compute-square-odd-number-ℕ' n)) ∙
+ ( right-unit-law-dist-ℕ _)
+
+has-odd-expansion-square-has-odd-expansion-ℕ :
+ (n : ℕ) → has-odd-expansion-ℕ n → has-odd-expansion-ℕ (square-ℕ n)
+pr1 (has-odd-expansion-square-has-odd-expansion-ℕ ._ (k , refl)) =
+ 2 *ℕ (k *ℕ (k +ℕ 1))
+pr2 (has-odd-expansion-square-has-odd-expansion-ℕ ._ (k , refl)) =
+ inv
+ ( ( compute-square-odd-number-ℕ' k) ∙
+ ( ap succ-ℕ (associative-mul-ℕ 2 2 (k *ℕ (k +ℕ 1)))))
+
+is-odd-square-is-odd-ℕ :
+ (n : ℕ) → is-odd-ℕ n → is-odd-ℕ (square-ℕ n)
+is-odd-square-is-odd-ℕ n H =
+ is-odd-has-odd-expansion-ℕ
+ ( square-ℕ n)
+ ( has-odd-expansion-square-has-odd-expansion-ℕ n
+ ( has-odd-expansion-is-odd-ℕ n H))
+
+is-odd-is-odd-square-ℕ :
+ (n : ℕ) → is-odd-ℕ (square-ℕ n) → is-odd-ℕ n
+is-odd-is-odd-square-ℕ n =
+ map-neg (is-even-square-is-even-ℕ n)
+
+is-1-mod-4-square-has-odd-expansion-ℕ :
+ (n : ℕ) → has-odd-expansion-ℕ n → square-ℕ n ≡ 1 mod-ℕ 4
+is-1-mod-4-square-has-odd-expansion-ℕ ._ (k , refl) =
+ tr
+ ( div-ℕ 4)
+ ( inv (compute-distance-to-1-square-odd-number-ℕ k))
+ ( div-mul-ℕ' (k *ℕ (k +ℕ 1)) 4 4 (refl-div-ℕ 4))
+
+is-1-mod-8-square-has-odd-expansion-ℕ :
+ (n : ℕ) → has-odd-expansion-ℕ n → square-ℕ n ≡ 1 mod-ℕ 8
+is-1-mod-8-square-has-odd-expansion-ℕ ._ (k , refl) =
+ tr
+ ( div-ℕ 8)
+ ( inv (compute-distance-to-1-square-odd-number-ℕ k))
+ ( preserves-div-mul-ℕ 4 2 4
+ ( k *ℕ (k +ℕ 1))
+ ( refl-div-ℕ 4)
+ ( is-even-pronic-number-ℕ k))
+
+is-1-mod-8-square-is-odd-ℕ :
+ (n : ℕ) → is-odd-ℕ n → square-ℕ n ≡ 1 mod-ℕ 8
+is-1-mod-8-square-is-odd-ℕ n H =
+ is-1-mod-8-square-has-odd-expansion-ℕ n (has-odd-expansion-is-odd-ℕ n H)
+```
+
+### Any two odd squares are congruent modulo `8`
+
+This solves exercise 6 of section 2.1 in {{#cite Andrews94}}.
+
+```agda
+cong-8-square-odd-number-ℕ :
+ (m n : ℕ) → is-odd-ℕ m → is-odd-ℕ n → square-ℕ m ≡ square-ℕ n mod-ℕ 8
+cong-8-square-odd-number-ℕ m n H K =
+ transitive-cong-ℕ 8
+ ( square-ℕ m)
+ ( 1)
+ ( square-ℕ n)
+ ( symmetric-cong-ℕ 8 (square-ℕ n) 1 (is-1-mod-8-square-is-odd-ℕ n K))
+ ( is-1-mod-8-square-is-odd-ℕ m H)
+```
+
+### Squaring preserves divisibility
+
+```agda
+module _
+ (m n : ℕ) (H : div-ℕ m n)
+ where
+
+ quotient-div-square-ℕ : ℕ
+ quotient-div-square-ℕ = square-ℕ (quotient-div-ℕ m n H)
+
+ upper-bound-quotient-div-square-ℕ :
+ quotient-div-square-ℕ ≤-ℕ square-ℕ n
+ upper-bound-quotient-div-square-ℕ =
+ preserves-order-square-ℕ
+ ( quotient-div-ℕ m n H)
+ ( n)
+ ( upper-bound-quotient-div-ℕ m n H)
+
+ eq-quotient-div-square-ℕ :
+ quotient-div-square-ℕ *ℕ square-ℕ m = square-ℕ n
+ eq-quotient-div-square-ℕ =
+ inv (distributive-square-mul-ℕ (quotient-div-ℕ m n H) m) ∙
+ ap square-ℕ (eq-quotient-div-ℕ m n H)
+
+ bounded-div-square-ℕ : bounded-div-ℕ (square-ℕ m) (square-ℕ n)
+ pr1 bounded-div-square-ℕ = quotient-div-square-ℕ
+ pr1 (pr2 bounded-div-square-ℕ) = upper-bound-quotient-div-square-ℕ
+ pr2 (pr2 bounded-div-square-ℕ) = eq-quotient-div-square-ℕ
+
+ preserves-div-square-ℕ : div-ℕ (square-ℕ m) (square-ℕ n)
+ pr1 preserves-div-square-ℕ = quotient-div-square-ℕ
+ pr2 preserves-div-square-ℕ = eq-quotient-div-square-ℕ
+
+ compute-quotient-div-square-ℕ :
+ (K : div-ℕ (square-ℕ m) (square-ℕ n)) →
+ quotient-div-ℕ (square-ℕ m) (square-ℕ n) K = quotient-div-square-ℕ
+ compute-quotient-div-square-ℕ K =
+ compute-quotient-bounded-div-ℕ
+ ( refl)
+ ( refl)
+ ( bounded-div-div-ℕ (square-ℕ m) (square-ℕ n) K)
+ ( bounded-div-square-ℕ)
+```
+
+### Squares of sums of natural numbers
+
+```agda
+square-add-ℕ :
+ (m n : ℕ) → square-ℕ (m +ℕ n) = square-ℕ m +ℕ 2 *ℕ (m *ℕ n) +ℕ square-ℕ n
+square-add-ℕ m n =
+ ( double-distributive-mul-add-ℕ m n m n) ∙
+ ( ap
+ ( _+ℕ square-ℕ n)
+ ( ( associative-add-ℕ (square-ℕ m) (m *ℕ n) (n *ℕ m)) ∙
+ ( ap
+ ( square-ℕ m +ℕ_)
+ ( ( ap (m *ℕ n +ℕ_) (commutative-mul-ℕ n m)) ∙
+ ( inv (left-two-law-mul-ℕ (m *ℕ n)))))))
+```
+
+### The formula for the distance between squares
+
+The formula for the distance between squares is more commonly known as the
+formula for the difference of squares. However, since we prefer using the
+distance operation on the natural numbers over the partial difference operation,
+we will state and prove the analogous formula using the distance function.
+
+The formula for the difference of squares of integers is formalized in its usual
+form.
+
+```agda
+distance-of-squares-ℕ' :
+ (m n k : ℕ) → m +ℕ k = n →
+ dist-ℕ (square-ℕ m) (square-ℕ n) = dist-ℕ m n *ℕ (m +ℕ n)
+distance-of-squares-ℕ' m ._ k refl =
+ ( ap
+ ( dist-ℕ (square-ℕ m))
+ ( ( square-add-ℕ m k) ∙
+ ( associative-add-ℕ (square-ℕ m) (2 *ℕ (m *ℕ k)) (square-ℕ k)))) ∙
+ ( dist-add-ℕ (square-ℕ m) (2 *ℕ (m *ℕ k) +ℕ square-ℕ k)) ∙
+ ( ap
+ ( _+ℕ square-ℕ k)
+ ( inv (associative-mul-ℕ 2 m k) ∙ ap (_*ℕ k) (left-two-law-mul-ℕ m))) ∙
+ ( inv (right-distributive-mul-add-ℕ (m +ℕ m) k k)) ∙
+ ( ap (_*ℕ k) (associative-add-ℕ m m k)) ∙
+ ( commutative-mul-ℕ (m +ℕ (m +ℕ k)) k) ∙
+ ( ap (_*ℕ (m +ℕ (m +ℕ k))) (inv (dist-add-ℕ m k)))
+
+abstract
+ distance-of-squares-ℕ :
+ (m n : ℕ) → dist-ℕ (square-ℕ m) (square-ℕ n) = dist-ℕ m n *ℕ (m +ℕ n)
+ distance-of-squares-ℕ m n
+ with
+ linear-leq-ℕ m n
+ ... | inl H =
+ distance-of-squares-ℕ' m n
+ ( pr1 (subtraction-leq-ℕ m n H))
+ ( commutative-add-ℕ m _ ∙ pr2 (subtraction-leq-ℕ m n H))
+ ... | inr H =
+ ( symmetric-dist-ℕ (square-ℕ m) (square-ℕ n)) ∙
+ ( distance-of-squares-ℕ' n m
+ ( pr1 (subtraction-leq-ℕ n m H))
+ ( commutative-add-ℕ n _ ∙ pr2 (subtraction-leq-ℕ n m H))) ∙
+ ( ap-mul-ℕ (symmetric-dist-ℕ n m) (commutative-add-ℕ n m))
+```
+
+### The $n$th square is the sum of the first $n$ odd numbers
+
+We show that
+
+$$
+ 1 + 3 + \cdots + (2n+1) = n^2.
+$$
+
+This solves exercise 5 in section 1.2 of {{#cite Andrews94}}.
+
+```agda
+sum-of-odd-numbers-ℕ : ℕ → ℕ
+sum-of-odd-numbers-ℕ n =
+ sum-Fin-ℕ n (λ i → odd-number-ℕ (nat-Fin n i))
+
+compute-sum-of-odd-numbers-ℕ :
+ (n : ℕ) → sum-of-odd-numbers-ℕ n = square-ℕ n
+compute-sum-of-odd-numbers-ℕ zero-ℕ = refl
+compute-sum-of-odd-numbers-ℕ (succ-ℕ zero-ℕ) = refl
+compute-sum-of-odd-numbers-ℕ (succ-ℕ (succ-ℕ n)) =
+ ( ap
+ ( _+ℕ odd-number-ℕ (succ-ℕ n))
+ ( compute-sum-of-odd-numbers-ℕ (succ-ℕ n))) ∙
+ ( inv (square-succ-ℕ (succ-ℕ n)))
```
## See also
- [Cubes of natural numbers](elementary-number-theory.cubes-natural-numbers.md)
+- [Square pyramidal numbers](elementary-number-theory.square-pyramidal-numbers.md)
+- [Squares of integers](elementary-number-theory.squares-integers.md)
+
+## References
+
+{{#bibliography}}
diff --git a/src/elementary-number-theory/strict-inequality-natural-numbers.lagda.md b/src/elementary-number-theory/strict-inequality-natural-numbers.lagda.md
index 623bc26c65..6627447c28 100644
--- a/src/elementary-number-theory/strict-inequality-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/strict-inequality-natural-numbers.lagda.md
@@ -29,6 +29,8 @@ open import foundation.propositions
open import foundation.transport-along-identifications
open import foundation.unit-type
open import foundation.universe-levels
+
+open import order-theory.strict-preorders
```
@@ -46,8 +48,8 @@ le-ℕ-Prop (succ-ℕ n) (succ-ℕ m) = le-ℕ-Prop n m
le-ℕ : ℕ → ℕ → UU lzero
le-ℕ n m = type-Prop (le-ℕ-Prop n m)
-is-prop-le-ℕ : (n : ℕ) → (m : ℕ) → is-prop (le-ℕ n m)
-is-prop-le-ℕ n m = is-prop-type-Prop (le-ℕ-Prop n m)
+is-prop-le-ℕ : (m n : ℕ) → is-prop (le-ℕ m n)
+is-prop-le-ℕ m n = is-prop-type-Prop (le-ℕ-Prop m n)
infix 30 _<-ℕ_
_<-ℕ_ = le-ℕ
@@ -59,23 +61,23 @@ _<-ℕ_ = le-ℕ
```agda
concatenate-eq-le-eq-ℕ :
- {x y z w : ℕ} → x = y → le-ℕ y z → z = w → le-ℕ x w
-concatenate-eq-le-eq-ℕ refl p refl = p
+ (m n k l : ℕ) → m = n → n <-ℕ k → k = l → m <-ℕ l
+concatenate-eq-le-eq-ℕ m n k .k refl p refl = p
concatenate-eq-le-ℕ :
- {x y z : ℕ} → x = y → le-ℕ y z → le-ℕ x z
-concatenate-eq-le-ℕ refl p = p
+ (m n k : ℕ) → m = n → n <-ℕ k → m <-ℕ k
+concatenate-eq-le-ℕ m .m k refl p = p
concatenate-le-eq-ℕ :
- {x y z : ℕ} → le-ℕ x y → y = z → le-ℕ x z
-concatenate-le-eq-ℕ p refl = p
+ (m n k : ℕ) → m <-ℕ n → n = k → m <-ℕ k
+concatenate-le-eq-ℕ m n .n p refl = p
```
### Strict inequality on the natural numbers is decidable
```agda
is-decidable-le-ℕ :
- (m n : ℕ) → is-decidable (le-ℕ m n)
+ (m n : ℕ) → is-decidable (m <-ℕ n)
is-decidable-le-ℕ zero-ℕ zero-ℕ = inr id
is-decidable-le-ℕ zero-ℕ (succ-ℕ n) = inl star
is-decidable-le-ℕ (succ-ℕ m) zero-ℕ = inr id
@@ -85,56 +87,64 @@ is-decidable-le-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-le-ℕ m n
### If `m < n` then `n` must be nonzero
```agda
-is-nonzero-le-ℕ : (m n : ℕ) → le-ℕ m n → is-nonzero-ℕ n
+is-nonzero-le-ℕ : (m n : ℕ) → m <-ℕ n → is-nonzero-ℕ n
is-nonzero-le-ℕ m .zero-ℕ () refl
```
### Any nonzero natural number is strictly greater than `0`
```agda
-le-is-nonzero-ℕ : (n : ℕ) → is-nonzero-ℕ n → le-ℕ zero-ℕ n
-le-is-nonzero-ℕ zero-ℕ H = H refl
-le-is-nonzero-ℕ (succ-ℕ n) H = star
+le-zero-is-nonzero-ℕ : (n : ℕ) → is-nonzero-ℕ n → zero-ℕ <-ℕ n
+le-zero-is-nonzero-ℕ zero-ℕ H = H refl
+le-zero-is-nonzero-ℕ (succ-ℕ n) H = star
```
### No natural number is strictly less than zero
```agda
contradiction-le-zero-ℕ :
- (m : ℕ) → (le-ℕ m zero-ℕ) → empty
+ (n : ℕ) → ¬ (n <-ℕ zero-ℕ)
contradiction-le-zero-ℕ zero-ℕ ()
-contradiction-le-zero-ℕ (succ-ℕ m) ()
+contradiction-le-zero-ℕ (succ-ℕ n) ()
+```
+
+### Any natural number strictly greater than another natural number is strictly greater than `0`
+
+```agda
+le-zero-le-ℕ :
+ (m n : ℕ) → m <-ℕ n → 0 <-ℕ n
+le-zero-le-ℕ m (succ-ℕ n) H = star
```
### No successor is strictly less than one
```agda
contradiction-le-one-ℕ :
- (n : ℕ) → le-ℕ (succ-ℕ n) 1 → empty
+ (n : ℕ) → ¬ (succ-ℕ n <-ℕ 1)
contradiction-le-one-ℕ zero-ℕ ()
contradiction-le-one-ℕ (succ-ℕ n) ()
```
-### The strict inequality on the natural numbers is anti-reflexive
+### The strict inequality on the natural numbers is irreflexive
```agda
-anti-reflexive-le-ℕ : (n : ℕ) → ¬ (n <-ℕ n)
-anti-reflexive-le-ℕ zero-ℕ ()
-anti-reflexive-le-ℕ (succ-ℕ n) = anti-reflexive-le-ℕ n
+irreflexive-le-ℕ : (n : ℕ) → ¬ (n <-ℕ n)
+irreflexive-le-ℕ zero-ℕ ()
+irreflexive-le-ℕ (succ-ℕ n) = irreflexive-le-ℕ n
```
### If `x < y` then `x ≠ y`
```agda
-neq-le-ℕ : {x y : ℕ} → le-ℕ x y → x ≠ y
-neq-le-ℕ {zero-ℕ} {succ-ℕ y} H = is-nonzero-succ-ℕ y ∘ inv
-neq-le-ℕ {succ-ℕ x} {succ-ℕ y} H p = neq-le-ℕ H (is-injective-succ-ℕ p)
+neq-le-ℕ : (m n : ℕ) → m <-ℕ n → m ≠ n
+neq-le-ℕ zero-ℕ (succ-ℕ n) H = is-nonzero-succ-ℕ n ∘ inv
+neq-le-ℕ (succ-ℕ m) (succ-ℕ n) H p = neq-le-ℕ m n H (is-injective-succ-ℕ p)
```
### The strict inequality on the natural numbers is antisymmetric
```agda
-antisymmetric-le-ℕ : (m n : ℕ) → le-ℕ m n → le-ℕ n m → m = n
+antisymmetric-le-ℕ : (m n : ℕ) → m <-ℕ n → n <-ℕ m → m = n
antisymmetric-le-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (antisymmetric-le-ℕ m n p q)
```
@@ -142,17 +152,22 @@ antisymmetric-le-ℕ (succ-ℕ m) (succ-ℕ n) p q =
### The strict inequality on the natural numbers is transitive
```agda
-transitive-le-ℕ : (n m l : ℕ) → (le-ℕ n m) → (le-ℕ m l) → (le-ℕ n l)
+transitive-le-ℕ : (n m l : ℕ) → m <-ℕ l → n <-ℕ m → n <-ℕ l
transitive-le-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ l) p q = star
transitive-le-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-le-ℕ n m l p q
+
+concatenate-le-eq-le-ℕ :
+ (a b c d : ℕ) → a <-ℕ b → b = c → c <-ℕ d → a <-ℕ d
+concatenate-le-eq-le-ℕ a b .b d H refl K =
+ transitive-le-ℕ a b d K H
```
### A sharper variant of transitivity
```agda
transitive-le-ℕ' :
- (k l m : ℕ) → (le-ℕ k l) → (le-ℕ l (succ-ℕ m)) → le-ℕ k m
+ (k l m : ℕ) → k <-ℕ l → l <-ℕ succ-ℕ m → k <-ℕ m
transitive-le-ℕ' zero-ℕ zero-ℕ m () s
transitive-le-ℕ' (succ-ℕ k) zero-ℕ m () s
transitive-le-ℕ' zero-ℕ (succ-ℕ l) zero-ℕ star s =
@@ -167,7 +182,7 @@ transitive-le-ℕ' (succ-ℕ k) (succ-ℕ l) (succ-ℕ m) t s =
### The strict inequality on the natural numbers is linear
```agda
-linear-le-ℕ : (x y : ℕ) → (le-ℕ x y) + ((x = y) + (le-ℕ y x))
+linear-le-ℕ : (x y : ℕ) → x <-ℕ y + ((x = y) + y <-ℕ x)
linear-le-ℕ zero-ℕ zero-ℕ = inr (inl refl)
linear-le-ℕ zero-ℕ (succ-ℕ y) = inl star
linear-le-ℕ (succ-ℕ x) zero-ℕ = inr (inr star)
@@ -175,21 +190,45 @@ linear-le-ℕ (succ-ℕ x) (succ-ℕ y) =
map-coproduct id (map-coproduct (ap succ-ℕ) id) (linear-le-ℕ x y)
```
+### Given two unequal natural numbers, we can decide their strict ordering
+
+```agda
+decide-le-neq-ℕ :
+ (m n : ℕ) → m ≠ n → (m <-ℕ n) + (n <-ℕ m)
+decide-le-neq-ℕ zero-ℕ zero-ℕ H = ex-falso (H refl)
+decide-le-neq-ℕ zero-ℕ (succ-ℕ n) H = inl star
+decide-le-neq-ℕ (succ-ℕ m) zero-ℕ H = inr star
+decide-le-neq-ℕ (succ-ℕ m) (succ-ℕ n) H =
+ decide-le-neq-ℕ m n (λ p → H (ap succ-ℕ p))
+```
+
+### The strict preorder of natural numbers
+
+```agda
+ℕ-Strict-Preorder : Strict-Preorder lzero lzero
+pr1 ℕ-Strict-Preorder = ℕ
+pr1 (pr2 ℕ-Strict-Preorder) = le-ℕ-Prop
+pr1 (pr2 (pr2 ℕ-Strict-Preorder)) = irreflexive-le-ℕ
+pr2 (pr2 (pr2 ℕ-Strict-Preorder)) = transitive-le-ℕ
+```
+
### `n < m` if and only if there exists a nonzero natural number `l` such that `l + n = m`
```agda
subtraction-le-ℕ :
- (n m : ℕ) → le-ℕ n m → Σ ℕ (λ l → (is-nonzero-ℕ l) × (l +ℕ n = m))
-subtraction-le-ℕ zero-ℕ m p = pair m (pair (is-nonzero-le-ℕ zero-ℕ m p) refl)
+ (n m : ℕ) → n <-ℕ m → Σ ℕ (λ l → is-nonzero-ℕ l × (l +ℕ n = m))
+subtraction-le-ℕ zero-ℕ m p =
+ ( m , is-nonzero-le-ℕ zero-ℕ m p , refl)
subtraction-le-ℕ (succ-ℕ n) (succ-ℕ m) p =
- pair (pr1 P) (pair (pr1 (pr2 P)) (ap succ-ℕ (pr2 (pr2 P))))
+ ( pr1 P , pr1 (pr2 P) , ap succ-ℕ (pr2 (pr2 P)))
where
+
P : Σ ℕ (λ l' → (is-nonzero-ℕ l') × (l' +ℕ n = m))
P = subtraction-le-ℕ n m p
-le-subtraction-ℕ : (n m l : ℕ) → is-nonzero-ℕ l → l +ℕ n = m → le-ℕ n m
+le-subtraction-ℕ : (n m l : ℕ) → is-nonzero-ℕ l → l +ℕ n = m → n <-ℕ m
le-subtraction-ℕ zero-ℕ m l q p =
- tr (λ x → le-ℕ zero-ℕ x) p (le-is-nonzero-ℕ l q)
+ tr (λ x → le-ℕ zero-ℕ x) p (le-zero-is-nonzero-ℕ l q)
le-subtraction-ℕ (succ-ℕ n) (succ-ℕ m) l q p =
le-subtraction-ℕ n m l q (is-injective-succ-ℕ p)
```
@@ -197,7 +236,7 @@ le-subtraction-ℕ (succ-ℕ n) (succ-ℕ m) l q p =
### Any natural number is strictly less than its successor
```agda
-succ-le-ℕ : (n : ℕ) → le-ℕ n (succ-ℕ n)
+succ-le-ℕ : (n : ℕ) → n <-ℕ succ-ℕ n
succ-le-ℕ zero-ℕ = star
succ-le-ℕ (succ-ℕ n) = succ-le-ℕ n
```
@@ -206,32 +245,37 @@ succ-le-ℕ (succ-ℕ n) = succ-le-ℕ n
```agda
preserves-le-succ-ℕ :
- (m n : ℕ) → le-ℕ m n → le-ℕ m (succ-ℕ n)
+ (m n : ℕ) → m <-ℕ n → m <-ℕ succ-ℕ n
preserves-le-succ-ℕ m n H =
- transitive-le-ℕ m n (succ-ℕ n) H (succ-le-ℕ n)
+ transitive-le-ℕ m n (succ-ℕ n) (succ-le-ℕ n) H
```
### Concatenating strict and nonstrict inequalities
```agda
concatenate-leq-le-ℕ :
- {x y z : ℕ} → x ≤-ℕ y → le-ℕ y z → le-ℕ x z
-concatenate-leq-le-ℕ {zero-ℕ} {zero-ℕ} {succ-ℕ z} H K = star
-concatenate-leq-le-ℕ {zero-ℕ} {succ-ℕ y} {succ-ℕ z} H K = star
-concatenate-leq-le-ℕ {succ-ℕ x} {succ-ℕ y} {succ-ℕ z} H K =
- concatenate-leq-le-ℕ {x} {y} {z} H K
+ (x y z : ℕ) → x ≤-ℕ y → y <-ℕ z → x <-ℕ z
+concatenate-leq-le-ℕ zero-ℕ zero-ℕ (succ-ℕ z) H K = star
+concatenate-leq-le-ℕ zero-ℕ (succ-ℕ y) (succ-ℕ z) H K = star
+concatenate-leq-le-ℕ (succ-ℕ x) (succ-ℕ y) (succ-ℕ z) H K =
+ concatenate-leq-le-ℕ x y z H K
concatenate-le-leq-ℕ :
- {x y z : ℕ} → le-ℕ x y → y ≤-ℕ z → le-ℕ x z
-concatenate-le-leq-ℕ {zero-ℕ} {succ-ℕ y} {succ-ℕ z} H K = star
-concatenate-le-leq-ℕ {succ-ℕ x} {succ-ℕ y} {succ-ℕ z} H K =
- concatenate-le-leq-ℕ {x} {y} {z} H K
+ (x y z : ℕ) → x <-ℕ y → y ≤-ℕ z → x <-ℕ z
+concatenate-le-leq-ℕ zero-ℕ (succ-ℕ y) (succ-ℕ z) H K = star
+concatenate-le-leq-ℕ (succ-ℕ x) (succ-ℕ y) (succ-ℕ z) H K =
+ concatenate-le-leq-ℕ x y z H K
+
+concatenate-leq-le-leq-ℕ :
+ (w x y z : ℕ) → w ≤-ℕ x → x <-ℕ y → y ≤-ℕ z → w <-ℕ z
+concatenate-leq-le-leq-ℕ w x y z H K L =
+ concatenate-leq-le-ℕ w x z H (concatenate-le-leq-ℕ x y z K L)
```
### If `m < n` then `n ≰ m`
```agda
-contradiction-le-ℕ : (m n : ℕ) → le-ℕ m n → ¬ (n ≤-ℕ m)
+contradiction-le-ℕ : (m n : ℕ) → m <-ℕ n → ¬ (n ≤-ℕ m)
contradiction-le-ℕ zero-ℕ (succ-ℕ n) H K = K
contradiction-le-ℕ (succ-ℕ m) (succ-ℕ n) H = contradiction-le-ℕ m n H
```
@@ -239,27 +283,27 @@ contradiction-le-ℕ (succ-ℕ m) (succ-ℕ n) H = contradiction-le-ℕ m n H
### If `n ≤ m` then `m ≮ n`
```agda
-contradiction-le-ℕ' : (m n : ℕ) → n ≤-ℕ m → ¬ (le-ℕ m n)
+contradiction-le-ℕ' : (m n : ℕ) → n ≤-ℕ m → ¬ (m <-ℕ n)
contradiction-le-ℕ' m n K H = contradiction-le-ℕ m n H K
```
### If `m ≮ n` then `n ≤ m`
```agda
-leq-not-le-ℕ : (m n : ℕ) → ¬ (le-ℕ m n) → n ≤-ℕ m
+leq-not-le-ℕ : (m n : ℕ) → ¬ (m <-ℕ n) → n ≤-ℕ m
leq-not-le-ℕ zero-ℕ zero-ℕ H = star
leq-not-le-ℕ zero-ℕ (succ-ℕ n) H = ex-falso (H star)
leq-not-le-ℕ (succ-ℕ m) zero-ℕ H = star
leq-not-le-ℕ (succ-ℕ m) (succ-ℕ n) H = leq-not-le-ℕ m n H
```
-### If `n ≰ m` then `m < n`
+### If `m ≰ n` then `n < m`
```agda
-le-not-leq-ℕ : (m n : ℕ) → ¬ (n ≤-ℕ m) → le-ℕ m n
+le-not-leq-ℕ : (m n : ℕ) → ¬ (m ≤-ℕ n) → n <-ℕ m
le-not-leq-ℕ zero-ℕ zero-ℕ H = ex-falso (H star)
-le-not-leq-ℕ zero-ℕ (succ-ℕ n) H = star
-le-not-leq-ℕ (succ-ℕ m) zero-ℕ H = ex-falso (H star)
+le-not-leq-ℕ zero-ℕ (succ-ℕ n) H = ex-falso (H star)
+le-not-leq-ℕ (succ-ℕ m) zero-ℕ H = star
le-not-leq-ℕ (succ-ℕ m) (succ-ℕ n) H = le-not-leq-ℕ m n H
```
@@ -267,7 +311,7 @@ le-not-leq-ℕ (succ-ℕ m) (succ-ℕ n) H = le-not-leq-ℕ m n H
```agda
leq-le-ℕ :
- (x y : ℕ) → le-ℕ x y → x ≤-ℕ y
+ (x y : ℕ) → x <-ℕ y → x ≤-ℕ y
leq-le-ℕ zero-ℕ (succ-ℕ y) H = star
leq-le-ℕ (succ-ℕ x) (succ-ℕ y) H = leq-le-ℕ x y H
```
@@ -276,7 +320,7 @@ leq-le-ℕ (succ-ℕ x) (succ-ℕ y) H = leq-le-ℕ x y H
```agda
leq-le-succ-ℕ :
- (x y : ℕ) → le-ℕ x (succ-ℕ y) → x ≤-ℕ y
+ (x y : ℕ) → x <-ℕ succ-ℕ y → x ≤-ℕ y
leq-le-succ-ℕ zero-ℕ y H = star
leq-le-succ-ℕ (succ-ℕ x) (succ-ℕ y) H = leq-le-succ-ℕ x y H
```
@@ -285,7 +329,7 @@ leq-le-succ-ℕ (succ-ℕ x) (succ-ℕ y) H = leq-le-succ-ℕ x y H
```agda
leq-succ-le-ℕ :
- (x y : ℕ) → le-ℕ x y → leq-ℕ (succ-ℕ x) y
+ (x y : ℕ) → x <-ℕ y → succ-ℕ x ≤-ℕ y
leq-succ-le-ℕ zero-ℕ (succ-ℕ y) H = star
leq-succ-le-ℕ (succ-ℕ x) (succ-ℕ y) H = leq-succ-le-ℕ x y H
```
@@ -303,8 +347,9 @@ le-leq-succ-ℕ (succ-ℕ x) (succ-ℕ y) H = le-leq-succ-ℕ x y H
```agda
le-succ-leq-ℕ :
- (x y : ℕ) → leq-ℕ x y → le-ℕ x (succ-ℕ y)
-le-succ-leq-ℕ zero-ℕ y H = star
+ (x y : ℕ) → x ≤-ℕ y → x <-ℕ succ-ℕ y
+le-succ-leq-ℕ zero-ℕ zero-ℕ H = star
+le-succ-leq-ℕ zero-ℕ (succ-ℕ y) H = star
le-succ-leq-ℕ (succ-ℕ x) (succ-ℕ y) H = le-succ-leq-ℕ x y H
```
@@ -312,18 +357,18 @@ le-succ-leq-ℕ (succ-ℕ x) (succ-ℕ y) H = le-succ-leq-ℕ x y H
```agda
eq-or-le-leq-ℕ :
- (x y : ℕ) → leq-ℕ x y → ((x = y) + (le-ℕ x y))
+ (x y : ℕ) → x ≤-ℕ y → ((x = y) + x <-ℕ y)
eq-or-le-leq-ℕ zero-ℕ zero-ℕ H = inl refl
eq-or-le-leq-ℕ zero-ℕ (succ-ℕ y) H = inr star
eq-or-le-leq-ℕ (succ-ℕ x) (succ-ℕ y) H =
map-coproduct (ap succ-ℕ) id (eq-or-le-leq-ℕ x y H)
eq-or-le-leq-ℕ' :
- (x y : ℕ) → leq-ℕ x y → ((y = x) + (le-ℕ x y))
+ (x y : ℕ) → x ≤-ℕ y → ((y = x) + x <-ℕ y)
eq-or-le-leq-ℕ' x y H = map-coproduct inv id (eq-or-le-leq-ℕ x y H)
leq-eq-or-le-ℕ :
- (x y : ℕ) → ((x = y) + (le-ℕ x y)) → leq-ℕ x y
+ (x y : ℕ) → ((x = y) + x <-ℕ y) → x ≤-ℕ y
leq-eq-or-le-ℕ x .x (inl refl) = refl-leq-ℕ x
leq-eq-or-le-ℕ x y (inr l) = leq-le-ℕ x y l
```
@@ -331,7 +376,7 @@ leq-eq-or-le-ℕ x y (inr l) = leq-le-ℕ x y l
### If `x ≤ y` and `x ≠ y` then `x < y`
```agda
-le-leq-neq-ℕ : {x y : ℕ} → x ≤-ℕ y → x ≠ y → le-ℕ x y
+le-leq-neq-ℕ : {x y : ℕ} → x ≤-ℕ y → x ≠ y → x <-ℕ y
le-leq-neq-ℕ {zero-ℕ} {zero-ℕ} l f = ex-falso (f refl)
le-leq-neq-ℕ {zero-ℕ} {succ-ℕ y} l f = star
le-leq-neq-ℕ {succ-ℕ x} {succ-ℕ y} l f =
@@ -341,54 +386,271 @@ le-leq-neq-ℕ {succ-ℕ x} {succ-ℕ y} l f =
### For any two natural numbers `x` and `y`, either `x < y` or `y ≤ x`
```agda
-decide-le-leq-ℕ : (x y : ℕ) → le-ℕ x y + leq-ℕ y x
+decide-le-leq-ℕ : (x y : ℕ) → x <-ℕ y + y ≤-ℕ x
decide-le-leq-ℕ x zero-ℕ = inr star
decide-le-leq-ℕ zero-ℕ (succ-ℕ _) = inl star
decide-le-leq-ℕ (succ-ℕ x) (succ-ℕ y) = decide-le-leq-ℕ x y
```
-### If `1 < x` and `1 < y`, then `1 < xy`
-
-```agda
-le-one-mul-ℕ : (x y : ℕ) → 1 <-ℕ x → 1 <-ℕ y → 1 <-ℕ (x *ℕ y)
-le-one-mul-ℕ (succ-ℕ (succ-ℕ x)) (succ-ℕ (succ-ℕ y)) star star = star
-```
-
-### Strict inequality on the natural numbers is invariant by translation
+### `x < x + y` for any nonzero natural number `y`
```agda
-eq-translate-right-le-ℕ : (z x y : ℕ) → le-ℕ (x +ℕ z) (y +ℕ z) = le-ℕ x y
-eq-translate-right-le-ℕ zero-ℕ x y = refl
-eq-translate-right-le-ℕ (succ-ℕ z) x y = eq-translate-right-le-ℕ z x y
+le-add-succ-ℕ :
+ (x y : ℕ) → x <-ℕ x +ℕ succ-ℕ y
+le-add-succ-ℕ zero-ℕ y = star
+le-add-succ-ℕ (succ-ℕ x) y =
+ concatenate-le-eq-ℕ x
+ ( x +ℕ succ-ℕ y)
+ ( succ-ℕ x +ℕ y)
+ ( le-add-succ-ℕ x y)
+ ( inv (left-successor-law-add-ℕ x y))
-eq-translate-left-le-ℕ : (z x y : ℕ) → le-ℕ (z +ℕ x) (z +ℕ y) = le-ℕ x y
-eq-translate-left-le-ℕ z x y =
- ap-binary le-ℕ (commutative-add-ℕ z x) (commutative-add-ℕ z y) ∙
- eq-translate-right-le-ℕ z x y
+le-add-ℕ :
+ (x y : ℕ) → is-nonzero-ℕ y → x <-ℕ x +ℕ y
+le-add-ℕ x zero-ℕ H = ex-falso (H refl)
+le-add-ℕ x (succ-ℕ y) H = le-add-succ-ℕ x y
```
-### Addition on the natural numbers preserves strict inequality
+### If `1 < x` and `1 < y`, then `1 < xy`
```agda
-preserves-le-right-add-ℕ : (z x y : ℕ) → le-ℕ x y → le-ℕ (x +ℕ z) (y +ℕ z)
-preserves-le-right-add-ℕ zero-ℕ x y I = I
-preserves-le-right-add-ℕ (succ-ℕ z) x y I = preserves-le-right-add-ℕ z x y I
-
-preserves-le-left-add-ℕ : (z x y : ℕ) → le-ℕ x y → le-ℕ (z +ℕ x) (z +ℕ y)
-preserves-le-left-add-ℕ z x y I =
- binary-tr
- le-ℕ
- (commutative-add-ℕ x z)
- (commutative-add-ℕ y z)
- (preserves-le-right-add-ℕ z x y I)
+le-one-mul-ℕ : (x y : ℕ) → 1 <-ℕ x → 1 <-ℕ y → 1 <-ℕ (x *ℕ y)
+le-one-mul-ℕ (succ-ℕ (succ-ℕ x)) (succ-ℕ (succ-ℕ y)) star star = star
+```
-preserves-le-add-ℕ :
- {a b c d : ℕ} → le-ℕ a b → le-ℕ c d → le-ℕ (a +ℕ c) (b +ℕ d)
-preserves-le-add-ℕ {a} {b} {c} {d} H K =
+### Addition is strictly order preserving
+
+```agda
+preserves-strict-order-left-add-ℕ :
+ (a b c : ℕ) → a <-ℕ b → a +ℕ c <-ℕ b +ℕ c
+preserves-strict-order-left-add-ℕ zero-ℕ (succ-ℕ b) c H =
+ concatenate-eq-le-eq-ℕ
+ ( 0 +ℕ c)
+ ( c)
+ ( c +ℕ succ-ℕ b)
+ ( succ-ℕ b +ℕ c)
+ ( left-unit-law-add-ℕ c)
+ ( le-add-succ-ℕ c b)
+ ( commutative-add-ℕ c (succ-ℕ b))
+preserves-strict-order-left-add-ℕ (succ-ℕ a) (succ-ℕ b) c H =
+ concatenate-eq-le-eq-ℕ
+ ( succ-ℕ a +ℕ c)
+ ( succ-ℕ (a +ℕ c))
+ ( succ-ℕ (b +ℕ c))
+ ( succ-ℕ b +ℕ c)
+ ( left-successor-law-add-ℕ a c)
+ ( preserves-strict-order-left-add-ℕ a b c H)
+ ( inv (left-successor-law-add-ℕ b c))
+
+preserves-strict-order-right-add-ℕ :
+ (a c d : ℕ) → c <-ℕ d → a +ℕ c <-ℕ a +ℕ d
+preserves-strict-order-right-add-ℕ a c d H =
+ concatenate-eq-le-eq-ℕ
+ ( a +ℕ c)
+ ( c +ℕ a)
+ ( d +ℕ a)
+ ( a +ℕ d)
+ ( commutative-add-ℕ a c)
+ ( preserves-strict-order-left-add-ℕ c d a H)
+ ( commutative-add-ℕ d a)
+
+preserves-strict-order-add-ℕ :
+ (a b c d : ℕ) → a <-ℕ b → c <-ℕ d → a +ℕ c <-ℕ b +ℕ d
+preserves-strict-order-add-ℕ a b c d H K =
transitive-le-ℕ
- (a +ℕ c)
- (b +ℕ c)
- (b +ℕ d)
- (preserves-le-right-add-ℕ c a b H)
- (preserves-le-left-add-ℕ b c d K)
-```
+ ( a +ℕ c)
+ ( b +ℕ c)
+ ( b +ℕ d)
+ ( preserves-strict-order-right-add-ℕ b c d K)
+ ( preserves-strict-order-left-add-ℕ a b c H)
+```
+
+### Addition reflects the strict ordering
+
+```agda
+reflects-strict-order-left-add-ℕ :
+ (a b c : ℕ) → a +ℕ c <-ℕ b +ℕ c → a <-ℕ b
+reflects-strict-order-left-add-ℕ a b zero-ℕ H =
+ H
+reflects-strict-order-left-add-ℕ a b (succ-ℕ c) H =
+ reflects-strict-order-left-add-ℕ a b c H
+
+reflects-strict-order-right-add-ℕ :
+ (a c d : ℕ) → a +ℕ c <-ℕ a +ℕ d → c <-ℕ d
+reflects-strict-order-right-add-ℕ zero-ℕ c d H =
+ concatenate-eq-le-eq-ℕ c
+ ( 0 +ℕ c)
+ ( 0 +ℕ d)
+ ( d)
+ ( inv (left-unit-law-add-ℕ c))
+ ( H)
+ ( left-unit-law-add-ℕ d)
+reflects-strict-order-right-add-ℕ (succ-ℕ a) c d H =
+ reflects-strict-order-right-add-ℕ a
+ ( succ-ℕ c)
+ ( succ-ℕ d)
+ ( concatenate-eq-le-eq-ℕ
+ ( a +ℕ succ-ℕ c)
+ ( succ-ℕ a +ℕ c)
+ ( succ-ℕ a +ℕ d)
+ ( a +ℕ succ-ℕ d)
+ ( inv (left-successor-law-add-ℕ a c))
+ ( H)
+ ( left-successor-law-add-ℕ a d))
+```
+
+### Strict inequality on the natural numbers is translation invariant
+
+```agda
+right-translation-invariant-le-ℕ : (z x y : ℕ) → x +ℕ z <-ℕ y +ℕ z = x <-ℕ y
+right-translation-invariant-le-ℕ zero-ℕ x y =
+ refl
+right-translation-invariant-le-ℕ (succ-ℕ z) x y =
+ right-translation-invariant-le-ℕ z x y
+
+left-translation-invariant-le-ℕ : (z x y : ℕ) → z +ℕ x <-ℕ z +ℕ y = x <-ℕ y
+left-translation-invariant-le-ℕ z x y =
+ ap-binary le-ℕ (commutative-add-ℕ z x) (commutative-add-ℕ z y) ∙
+ right-translation-invariant-le-ℕ z x y
+```
+
+### Multiplication is strictly order preserving
+
+```agda
+preserves-strict-order-mul-ℕ :
+ (a b c d : ℕ) → a <-ℕ b → c <-ℕ d → a *ℕ c <-ℕ b *ℕ d
+preserves-strict-order-mul-ℕ zero-ℕ (succ-ℕ b) zero-ℕ (succ-ℕ d) H K = star
+preserves-strict-order-mul-ℕ zero-ℕ (succ-ℕ b) (succ-ℕ c) (succ-ℕ d) H K = star
+preserves-strict-order-mul-ℕ (succ-ℕ a) (succ-ℕ b) zero-ℕ (succ-ℕ d) H K =
+ concatenate-eq-le-ℕ
+ ( a *ℕ 0)
+ ( 0)
+ ( succ-ℕ b *ℕ succ-ℕ d)
+ ( right-zero-law-mul-ℕ a)
+ ( star)
+preserves-strict-order-mul-ℕ (succ-ℕ a) (succ-ℕ b) (succ-ℕ c) (succ-ℕ d) H K =
+ concatenate-eq-le-eq-ℕ
+ ( succ-ℕ a *ℕ succ-ℕ c)
+ ( a *ℕ c +ℕ a +ℕ c +ℕ 1)
+ ( b *ℕ d +ℕ b +ℕ d +ℕ 1)
+ ( succ-ℕ b *ℕ succ-ℕ d)
+ ( double-successor-law-mul-ℕ a c)
+ ( preserves-strict-order-add-ℕ
+ ( a *ℕ c +ℕ a)
+ ( b *ℕ d +ℕ b)
+ ( c)
+ ( d)
+ ( preserves-strict-order-add-ℕ
+ ( a *ℕ c)
+ ( b *ℕ d)
+ ( a)
+ ( b)
+ ( preserves-strict-order-mul-ℕ a b c d H K)
+ ( H))
+ ( K))
+ ( inv (double-successor-law-mul-ℕ b d))
+```
+
+### Multiplication by a nonzero natural number on the left or right is strictly order preserving
+
+```agda
+preserves-strict-order-left-mul-succ-ℕ :
+ (k x y : ℕ) → x <-ℕ y → succ-ℕ k *ℕ x <-ℕ succ-ℕ k *ℕ y
+preserves-strict-order-left-mul-succ-ℕ zero-ℕ x y H =
+ concatenate-eq-le-eq-ℕ
+ ( 1 *ℕ x)
+ ( x)
+ ( y)
+ ( 1 *ℕ y)
+ ( left-unit-law-mul-ℕ x)
+ ( H)
+ ( inv (left-unit-law-mul-ℕ y))
+preserves-strict-order-left-mul-succ-ℕ (succ-ℕ k) x y H =
+ concatenate-eq-le-eq-ℕ
+ ( succ-ℕ (succ-ℕ k) *ℕ x)
+ ( succ-ℕ k *ℕ x +ℕ x)
+ ( succ-ℕ k *ℕ y +ℕ y)
+ ( succ-ℕ (succ-ℕ k) *ℕ y)
+ ( left-successor-law-mul-ℕ (succ-ℕ k) x)
+ ( preserves-strict-order-add-ℕ
+ ( succ-ℕ k *ℕ x)
+ ( succ-ℕ k *ℕ y)
+ ( x)
+ ( y)
+ ( preserves-strict-order-left-mul-succ-ℕ k x y H)
+ ( H))
+ ( inv (left-successor-law-mul-ℕ (succ-ℕ k) y))
+
+preserves-strict-order-left-mul-is-successor-ℕ :
+ (k x y : ℕ) → is-successor-ℕ k → x <-ℕ y → k *ℕ x <-ℕ k *ℕ y
+preserves-strict-order-left-mul-is-successor-ℕ .(succ-ℕ l) x y (l , refl) =
+ preserves-strict-order-left-mul-succ-ℕ l x y
+
+preserves-strict-order-left-mul-ℕ :
+ (k x y : ℕ) → is-nonzero-ℕ k → x <-ℕ y → k *ℕ x <-ℕ k *ℕ y
+preserves-strict-order-left-mul-ℕ k x y H =
+ preserves-strict-order-left-mul-is-successor-ℕ k x y
+ ( is-successor-is-nonzero-ℕ H)
+
+preserves-strict-order-right-mul-succ-ℕ :
+ (k x y : ℕ) → x <-ℕ y → x *ℕ succ-ℕ k <-ℕ y *ℕ succ-ℕ k
+preserves-strict-order-right-mul-succ-ℕ zero-ℕ x y H =
+ concatenate-eq-le-eq-ℕ
+ ( x *ℕ 1)
+ ( x)
+ ( y)
+ ( y *ℕ 1)
+ ( right-unit-law-mul-ℕ x)
+ ( H)
+ ( inv (right-unit-law-mul-ℕ y))
+preserves-strict-order-right-mul-succ-ℕ (succ-ℕ k) x y H =
+ concatenate-eq-le-eq-ℕ
+ ( x *ℕ succ-ℕ (succ-ℕ k))
+ ( x *ℕ succ-ℕ k +ℕ x)
+ ( y *ℕ succ-ℕ k +ℕ y)
+ ( y *ℕ succ-ℕ (succ-ℕ k))
+ ( right-successor-law-mul-ℕ x (succ-ℕ k))
+ ( preserves-strict-order-add-ℕ
+ ( x *ℕ succ-ℕ k)
+ ( y *ℕ succ-ℕ k)
+ ( x)
+ ( y)
+ ( preserves-strict-order-right-mul-succ-ℕ k x y H)
+ ( H))
+ ( inv (right-successor-law-mul-ℕ y (succ-ℕ k)))
+
+preserves-strict-order-right-mul-is-successor-ℕ :
+ (k x y : ℕ) → is-successor-ℕ k → x <-ℕ y → x *ℕ k <-ℕ y *ℕ k
+preserves-strict-order-right-mul-is-successor-ℕ .(succ-ℕ l) x y (l , refl) =
+ preserves-strict-order-right-mul-succ-ℕ l x y
+
+preserves-strict-order-right-mul-ℕ :
+ (k x y : ℕ) → is-nonzero-ℕ k → x <-ℕ y → x *ℕ k <-ℕ y *ℕ k
+preserves-strict-order-right-mul-ℕ k x y H =
+ preserves-strict-order-right-mul-is-successor-ℕ k x y
+ ( is-successor-is-nonzero-ℕ H)
+```
+
+### Multiplying with a nonzero element is an inflationary function
+
+```agda
+is-inflationary-left-mul-ℕ :
+ (k n : ℕ) → is-nonzero-ℕ k → n ≤-ℕ k *ℕ n
+is-inflationary-left-mul-ℕ k n H =
+ concatenate-eq-leq-ℕ
+ ( k *ℕ n)
+ ( inv (left-unit-law-mul-ℕ n))
+ ( preserves-order-left-mul-ℕ n 1 k (leq-one-is-nonzero-ℕ k H))
+
+is-inflationary-right-mul-ℕ :
+ (k n : ℕ) → is-nonzero-ℕ k → n ≤-ℕ n *ℕ k
+is-inflationary-right-mul-ℕ k n H =
+ concatenate-leq-eq-ℕ
+ ( n)
+ ( is-inflationary-left-mul-ℕ k n H)
+ ( commutative-mul-ℕ k n)
+```
+
+## See also
+
+- [The strictly bounded natural numbers](elementary-number-theory.strictly-bounded-natural-numbers.md)
diff --git a/src/elementary-number-theory/strictly-bounded-natural-numbers.lagda.md b/src/elementary-number-theory/strictly-bounded-natural-numbers.lagda.md
new file mode 100644
index 0000000000..c8f78bc0ef
--- /dev/null
+++ b/src/elementary-number-theory/strictly-bounded-natural-numbers.lagda.md
@@ -0,0 +1,127 @@
+# Strictly bounded natural numbers
+
+```agda
+module elementary-number-theory.strictly-bounded-natural-numbers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.congruence-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.modular-arithmetic-standard-finite-types
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+
+open import foundation.dependent-pair-types
+open import foundation.equivalences
+open import foundation.retractions
+open import foundation.sections
+open import foundation.sets
+open import foundation.subtypes
+open import foundation.universe-levels
+
+open import univalent-combinatorics.counting
+open import univalent-combinatorics.standard-finite-types
+```
+
+
+
+## Idea
+
+The type of
+{{#concept "strictly bounded natural numbers" Agda=strictly-bounded-ℕ}} with
+strict upper bound $n$ is the type
+
+$$
+ \mathbb{N}_{< n} := \{k : ℕ \mid k < n\}.
+$$
+
+The type $\mathbb{N}_{\leq n}$ is [equivalent](foundation-core.equivalences.md)
+to the [standard finite type](univalent-combinatorics.standard-finite-types.md)
+$\mathsf{Fin}(n+1)$.
+
+## Definition
+
+### The strictly bounded natural numbers
+
+```agda
+strictly-bounded-ℕ : ℕ → UU lzero
+strictly-bounded-ℕ n = Σ ℕ (λ k → k <-ℕ n)
+
+nat-strictly-bounded-ℕ :
+ (n : ℕ) → strictly-bounded-ℕ n → ℕ
+nat-strictly-bounded-ℕ n =
+ pr1
+
+strict-upper-bound-nat-strictly-bounded-ℕ :
+ (n : ℕ) (x : strictly-bounded-ℕ n) → nat-strictly-bounded-ℕ n x <-ℕ n
+strict-upper-bound-nat-strictly-bounded-ℕ n =
+ pr2
+```
+
+## Properties
+
+### The type of bounded natural numbers is a set
+
+```agda
+is-set-strictly-bounded-ℕ :
+ (n : ℕ) → is-set (strictly-bounded-ℕ n)
+is-set-strictly-bounded-ℕ n =
+ is-set-type-subtype
+ ( λ k → le-ℕ-Prop k n)
+ ( is-set-ℕ)
+```
+
+### The type $\mathbb{N}_{\leq b}$ is equivalent to the standard finite type $\mathsf{Fin}(n+1)$
+
+```agda
+strictly-bounded-nat-Fin :
+ (n : ℕ) → Fin n → strictly-bounded-ℕ n
+pr1 (strictly-bounded-nat-Fin n i) = nat-Fin n i
+pr2 (strictly-bounded-nat-Fin n i) = strict-upper-bound-nat-Fin n i
+
+fin-strictly-bounded-ℕ :
+ (n : ℕ) → strictly-bounded-ℕ n → Fin n
+fin-strictly-bounded-ℕ (succ-ℕ n) x =
+ mod-succ-ℕ n (nat-strictly-bounded-ℕ (succ-ℕ n) x)
+
+is-section-fin-strictly-bounded-ℕ :
+ (n : ℕ) → is-section (strictly-bounded-nat-Fin n) (fin-strictly-bounded-ℕ n)
+is-section-fin-strictly-bounded-ℕ (succ-ℕ n) i =
+ eq-type-subtype
+ ( λ x → le-ℕ-Prop x (succ-ℕ n))
+ ( eq-nat-mod-succ-ℕ n
+ ( nat-strictly-bounded-ℕ (succ-ℕ n) i)
+ ( strict-upper-bound-nat-strictly-bounded-ℕ (succ-ℕ n) i))
+
+is-retraction-fin-strictly-bounded-ℕ :
+ (n : ℕ) →
+ is-retraction (strictly-bounded-nat-Fin n) (fin-strictly-bounded-ℕ n)
+is-retraction-fin-strictly-bounded-ℕ (succ-ℕ n) i =
+ is-section-nat-Fin n i
+
+is-equiv-strictly-bounded-nat-Fin :
+ (n : ℕ) → is-equiv (strictly-bounded-nat-Fin n)
+is-equiv-strictly-bounded-nat-Fin n =
+ is-equiv-is-invertible
+ ( fin-strictly-bounded-ℕ n)
+ ( is-section-fin-strictly-bounded-ℕ n)
+ ( is-retraction-fin-strictly-bounded-ℕ n)
+
+equiv-count-strictly-bounded-ℕ :
+ (n : ℕ) → Fin n ≃ strictly-bounded-ℕ n
+pr1 (equiv-count-strictly-bounded-ℕ n) =
+ strictly-bounded-nat-Fin n
+pr2 (equiv-count-strictly-bounded-ℕ n) =
+ is-equiv-strictly-bounded-nat-Fin n
+
+count-strictly-bounded-ℕ :
+ (n : ℕ) → count (strictly-bounded-ℕ n)
+pr1 (count-strictly-bounded-ℕ n) = n
+pr2 (count-strictly-bounded-ℕ n) = equiv-count-strictly-bounded-ℕ n
+```
+
+## See also
+
+- [The bounded natural numbers](elementary-number-theory.bounded-natural-numbers.md)
diff --git a/src/elementary-number-theory/strictly-inflationary-functions-natural-numbers.lagda.md b/src/elementary-number-theory/strictly-inflationary-functions-natural-numbers.lagda.md
new file mode 100644
index 0000000000..e84aabf481
--- /dev/null
+++ b/src/elementary-number-theory/strictly-inflationary-functions-natural-numbers.lagda.md
@@ -0,0 +1,112 @@
+# Strictly inflationary functions on the natural numbers
+
+```agda
+module
+ elementary-number-theory.strictly-inflationary-functions-natural-numbers
+ where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.decidable-types
+open import elementary-number-theory.equality-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.strict-inequality-natural-numbers
+
+open import foundation.decidable-maps
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.identity-types
+open import foundation.universe-levels
+
+open import order-theory.strictly-inflationary-maps-strict-preorders
+
+open import univalent-combinatorics.dependent-pair-types
+```
+
+
+
+## Idea
+
+A function $f : \mathbb{N} \to \mathbb{N}$ is a
+{{#concept "strictly inflationary function" Disambiguation="natural numbers" Agda=is-strictly-inflationary-ℕ}}
+if the implication
+
+$$
+ (x < y) \to (f(x) < f(y))
+$$
+
+holds for every $x,y:\mathbb{N}$. If $f$ is a strictly inflationary function on
+the natural numbers such that $f(0) \leq b$ for some natural number $b$, then
+there is a maximal natural number $k$ such that $f(k) \leq b$.
+
+## Definitions
+
+### The predicate of being a strictly inflationary map on the natural numbers
+
+```agda
+is-strictly-inflationary-map-ℕ : (ℕ → ℕ) → UU lzero
+is-strictly-inflationary-map-ℕ =
+ is-strictly-inflationary-map-Strict-Preorder ℕ-Strict-Preorder
+```
+
+### Strictly inflationary maps on the natural numbers
+
+```agda
+strictly-inflationary-map-ℕ : UU lzero
+strictly-inflationary-map-ℕ =
+ strictly-inflationary-map-Strict-Preorder ℕ-Strict-Preorder
+
+map-strictly-inflationary-map-ℕ :
+ strictly-inflationary-map-ℕ → ℕ → ℕ
+map-strictly-inflationary-map-ℕ =
+ map-strictly-inflationary-map-Strict-Preorder ℕ-Strict-Preorder
+
+is-strictly-inflationary-strictly-inflationary-map-ℕ :
+ (f : strictly-inflationary-map-ℕ) →
+ is-strictly-inflationary-map-ℕ (map-strictly-inflationary-map-ℕ f)
+is-strictly-inflationary-strictly-inflationary-map-ℕ =
+ is-strictly-inflationary-strictly-inflationary-map-Strict-Preorder
+ ℕ-Strict-Preorder
+
+fiber-strictly-inflationary-map-ℕ :
+ (f : strictly-inflationary-map-ℕ) → ℕ → UU lzero
+fiber-strictly-inflationary-map-ℕ f = fiber (map-strictly-inflationary-map-ℕ f)
+```
+
+## Properties
+
+### Strictly inflationary maps on the natural numbers are inflationary
+
+```agda
+is-inflationary-strictly-inflationary-map-ℕ :
+ (f : strictly-inflationary-map-ℕ)
+ (n : ℕ) → n ≤-ℕ map-strictly-inflationary-map-ℕ f n
+is-inflationary-strictly-inflationary-map-ℕ f n =
+ leq-le-ℕ n
+ ( map-strictly-inflationary-map-ℕ f n)
+ ( is-strictly-inflationary-strictly-inflationary-map-ℕ f n)
+```
+
+### Strictly inflationary maps are decidable
+
+```agda
+is-decidable-map-is-strictly-inflationary-map-ℕ :
+ {f : ℕ → ℕ} → is-strictly-inflationary-map-ℕ f → is-decidable-map f
+is-decidable-map-is-strictly-inflationary-map-ℕ {f} H n =
+ is-decidable-iff
+ ( λ (x , K , p) → (x , p))
+ ( λ (x , p) → (x , concatenate-le-eq-ℕ x (f x) n (H x) p , p))
+ ( is-decidable-strictly-bounded-Σ-ℕ' n
+ ( λ x → f x = n)
+ ( λ x → has-decidable-equality-ℕ (f x) n))
+
+is-decidable-map-strictly-inflationary-map-ℕ :
+ (f : strictly-inflationary-map-ℕ) →
+ is-decidable-map (map-strictly-inflationary-map-ℕ f)
+is-decidable-map-strictly-inflationary-map-ℕ (f , H) n =
+ is-decidable-map-is-strictly-inflationary-map-ℕ H n
+```
diff --git a/src/elementary-number-theory/strictly-ordered-pairs-of-natural-numbers.lagda.md b/src/elementary-number-theory/strictly-ordered-pairs-of-natural-numbers.lagda.md
index faab496e28..fa7d1c929b 100644
--- a/src/elementary-number-theory/strictly-ordered-pairs-of-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/strictly-ordered-pairs-of-natural-numbers.lagda.md
@@ -26,7 +26,7 @@ open import foundation.universe-levels
## Idea
-A strictly ordered pair of natural numbers consists of `x y : ℕ` such that
+A {{#concept "strictly ordered pair of natural numbers" Agda=strictly-ordered-pair-ℕ}} consists of `x y : ℕ` satisfying the [strict inequality](elementary-number-theory.strict-inequality-natural-numbers.md)
`x < y`.
## Definition
@@ -58,7 +58,7 @@ module _
pair-of-distinct-elements-strictly-ordered-pair-ℕ :
strictly-ordered-pair-ℕ → pair-of-distinct-elements ℕ
pair-of-distinct-elements-strictly-ordered-pair-ℕ (a , b , H) =
- (a , b , neq-le-ℕ H)
+ (a , b , neq-le-ℕ a b H)
```
### Any pair of distinct elements of natural numbers can be strictly ordered
diff --git a/src/elementary-number-theory/strong-induction-natural-numbers.lagda.md b/src/elementary-number-theory/strong-induction-natural-numbers.lagda.md
index 6a0bf777c5..bd4d82a5c3 100644
--- a/src/elementary-number-theory/strong-induction-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/strong-induction-natural-numbers.lagda.md
@@ -74,7 +74,7 @@ succ-strong-ind-ℕ :
{l : Level} (P : ℕ → UU l) → ((k : ℕ) → (□-≤-ℕ P k) → P (succ-ℕ k)) →
(k : ℕ) → (□-≤-ℕ P k) → (□-≤-ℕ P (succ-ℕ k))
succ-strong-ind-ℕ P pS k H m p =
- cases-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p)
+ cases-succ-strong-ind-ℕ P pS k H m (decide-leq-succ-ℕ m k p)
cases-htpy-succ-strong-ind-ℕ :
{l : Level} (P : ℕ → UU l) (pS : (k : ℕ) → (□-≤-ℕ P k) → P (succ-ℕ k)) →
@@ -93,7 +93,7 @@ htpy-succ-strong-ind-ℕ :
( succ-strong-ind-ℕ P pS k H m p) =
( H m q)
htpy-succ-strong-ind-ℕ P pS k H m p q =
- cases-htpy-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p) q
+ cases-htpy-succ-strong-ind-ℕ P pS k H m (decide-leq-succ-ℕ m k p) q
cases-eq-succ-strong-ind-ℕ :
{l : Level} (P : ℕ → UU l) (pS : (k : ℕ) → (□-≤-ℕ P k) → P (succ-ℕ k)) →
@@ -113,7 +113,7 @@ eq-succ-strong-ind-ℕ :
( (succ-strong-ind-ℕ P pS k H (succ-ℕ k) p)) =
( pS k H)
eq-succ-strong-ind-ℕ P pS k H p =
- cases-eq-succ-strong-ind-ℕ P pS k H (cases-leq-succ-ℕ p)
+ cases-eq-succ-strong-ind-ℕ P pS k H (decide-leq-succ-ℕ (succ-ℕ k) k p)
```
### The inductive step
@@ -161,7 +161,7 @@ cases-eq-compute-succ-strong-ind-ℕ :
( m : ℕ) (p : leq-ℕ m n) →
( induction-strong-ind-ℕ P (zero-strong-ind-ℕ P p0)
( λ k z m₁ z₁ →
- cases-succ-strong-ind-ℕ P pS k z m₁ (cases-leq-succ-ℕ z₁))
+ cases-succ-strong-ind-ℕ P pS k z m₁ (decide-leq-succ-ℕ m₁ k z₁))
n m p) =
( strong-ind-ℕ P p0 pS m)) →
( m : ℕ) (p : leq-ℕ m (succ-ℕ n)) →
@@ -190,10 +190,10 @@ cases-eq-compute-succ-strong-ind-ℕ P p0 pS n α .(succ-ℕ n) p (inr refl) =
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( λ k H m p₁ →
- cases-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p₁))
+ cases-succ-strong-ind-ℕ P pS k H m (decide-leq-succ-ℕ m k p₁))
n)
( succ-ℕ n))
- ( cases-leq-succ-reflexive-leq-ℕ)))
+ ( decide-leq-refl-succ-ℕ)))
eq-compute-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
@@ -202,14 +202,14 @@ eq-compute-succ-strong-ind-ℕ :
( m : ℕ) (p : leq-ℕ m n) →
( induction-strong-ind-ℕ P (zero-strong-ind-ℕ P p0)
( λ k z m₁ z₁ →
- cases-succ-strong-ind-ℕ P pS k z m₁ (cases-leq-succ-ℕ z₁))
+ cases-succ-strong-ind-ℕ P pS k z m₁ (decide-leq-succ-ℕ m₁ k z₁))
n m p) =
( strong-ind-ℕ P p0 pS m)
eq-compute-succ-strong-ind-ℕ P p0 pS zero-ℕ zero-ℕ _ = refl
eq-compute-succ-strong-ind-ℕ P p0 pS (succ-ℕ n) m p =
cases-eq-compute-succ-strong-ind-ℕ P p0 pS n
( eq-compute-succ-strong-ind-ℕ P p0 pS n) m p
- ( cases-leq-succ-ℕ p)
+ ( decide-leq-succ-ℕ m n p)
compute-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
diff --git a/src/elementary-number-theory/sums-of-natural-numbers.lagda.md b/src/elementary-number-theory/sums-of-natural-numbers.lagda.md
index a026d32a7c..3790c80f92 100644
--- a/src/elementary-number-theory/sums-of-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/sums-of-natural-numbers.lagda.md
@@ -8,6 +8,8 @@ module elementary-number-theory.sums-of-natural-numbers where
```agda
open import elementary-number-theory.addition-natural-numbers
+open import elementary-number-theory.distance-natural-numbers
+open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
@@ -27,6 +29,7 @@ open import foundation.whiskering-homotopies-composition
open import lists.lists
open import univalent-combinatorics.counting
+open import univalent-combinatorics.skipping-element-standard-finite-types
open import univalent-combinatorics.standard-finite-types
```
@@ -34,7 +37,36 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-The values of a map `f : X → ℕ` out of a finite type `X` can be summed up.
+Consider a family of
+[natural numbers](elementary-number-theory.natural-numbers.md)
+$a : \mathsf{Fin}(n) → \mathbb{N}$ indexed by a
+[standard finite type](univalent-combinatorics.standard-finite-types.md)
+$\mathsf{Fin}(n)$. The
+{{#concept "sum" Disambiguation="natural numbers" Agda=sum-Fin-ℕ}}
+
+$$
+\sum_{0\leq i
+## Idea
+
+The $n$th {{#concept "triangular number" Agda=triangular-number-ℕ}} is the
+[sum](elementary-number-theory.sums-of-natural-numbers.md) of the
+[natural numbers](elementary-number-theory.natural-numbers.md) up to $n$.
+Alternatively, the triangular numbers can be defined inductively by
+
+```text
+ T 0 := 0
+ T (n + 1) := T n + (n + 1).
+```
+
+A classic inductive proof, which is often used as the first example when
+introducing students to mathematical induction, establishes the famous fact that
+
+```text
+ T n = n(n + 1)/2.
+```
+
+In other words, the $n$th triangular number is half the $n$th
+[pronic number](elementary-number-theory.pronic-numbers.md).
+
## Definition
+### The sum definition of the triangular numbers
+
```agda
triangular-number-ℕ : ℕ → ℕ
-triangular-number-ℕ 0 = 0
-triangular-number-ℕ (succ-ℕ n) = (triangular-number-ℕ n) +ℕ (succ-ℕ n)
+triangular-number-ℕ n = bounded-sum-ℕ n (λ x H → x)
+```
+
+### The inductive definition of the triangular numbers
+
+```agda
+inductive-triangular-number-ℕ : ℕ → ℕ
+inductive-triangular-number-ℕ 0 = 0
+inductive-triangular-number-ℕ (succ-ℕ n) =
+ inductive-triangular-number-ℕ n +ℕ succ-ℕ n
```
+
+## Properties
+
+### The two definitions of triangular numbers are the same
+
+```agda
+compute-inductive-triangular-number-ℕ :
+ (n : ℕ) → inductive-triangular-number-ℕ n = triangular-number-ℕ n
+compute-inductive-triangular-number-ℕ zero-ℕ = refl
+compute-inductive-triangular-number-ℕ (succ-ℕ n) =
+ ap (add-ℕ' (succ-ℕ n)) (compute-inductive-triangular-number-ℕ n)
+```
+
+### The $n$th triangular number is $\frac{1}{2}n(n+1)$
+
+**Proof.** The claim is equivalent to the claim that
+
+$$
+ 2 \cdot \left(\sum_{i\leq n} i\right) = n(n+1).
+$$
+
+We prove this claim to avoid an early division by two, and the proof is by
+induction on $n$. In the base case both sides of the equality are $0$. For the
+inductive step, assume that $2 \cdot \sum_{i\leq n} i = n(n+1)$. Then we can
+compute
+
+$$
+2 \cdot \sum_{i\leq n+1} i = 2 \cdot \left(\sum_{i\leq n} i\right)+ 2(n+1) = n(n+1) + ((n+1) + (n+1)) = (n+1)(n+2).
+$$
+
+```agda
+value-triangular-number-ℕ : ℕ → ℕ
+value-triangular-number-ℕ n =
+ quotient-div-ℕ 2 (pronic-number-ℕ n) (is-even-pronic-number-ℕ n)
+
+compute-triangular-number-ℕ' :
+ (n : ℕ) → 2 *ℕ triangular-number-ℕ n = pronic-number-ℕ n
+compute-triangular-number-ℕ' zero-ℕ = refl
+compute-triangular-number-ℕ' (succ-ℕ n) =
+ left-distributive-mul-add-ℕ 2 (triangular-number-ℕ n) (succ-ℕ n) ∙
+ ap-add-ℕ (compute-triangular-number-ℕ' n) (left-two-law-mul-ℕ (succ-ℕ n)) ∙
+ inv (associative-add-ℕ (n *ℕ succ-ℕ n) (succ-ℕ n) (succ-ℕ n)) ∙
+ inv (right-successor-law-mul-ℕ (succ-ℕ n) (succ-ℕ n))
+
+compute-triangular-number-ℕ :
+ (n : ℕ) →
+ triangular-number-ℕ n =
+ quotient-div-ℕ 2 (pronic-number-ℕ n) (is-even-pronic-number-ℕ n)
+compute-triangular-number-ℕ n =
+ is-injective-left-mul-ℕ 2
+ ( is-nonzero-two-ℕ)
+ ( compute-triangular-number-ℕ' n ∙
+ inv (eq-quotient-div-ℕ 2 (n *ℕ succ-ℕ n) (is-even-pronic-number-ℕ n)) ∙
+ commutative-mul-ℕ (value-triangular-number-ℕ n) 2)
+```
+
+## See also
+
+- [Nicomachus's Theorem](elementary-number-theory.nicomachuss-theorem.md)
diff --git a/src/elementary-number-theory/type-arithmetic-natural-numbers.lagda.md b/src/elementary-number-theory/type-arithmetic-natural-numbers.lagda.md
index 9d3fa6833f..7f367cf3d4 100644
--- a/src/elementary-number-theory/type-arithmetic-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/type-arithmetic-natural-numbers.lagda.md
@@ -9,14 +9,18 @@ module elementary-number-theory.type-arithmetic-natural-numbers where
```agda
open import elementary-number-theory.addition-natural-numbers
open import elementary-number-theory.divisibility-natural-numbers
+open import elementary-number-theory.equality-natural-numbers
open import elementary-number-theory.integers
open import elementary-number-theory.multiplication-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.parity-natural-numbers
-open import elementary-number-theory.powers-of-two
+open import elementary-number-theory.2-adic-decomposition
open import foundation.action-on-identifications-functions
+open import foundation.commuting-triangles-of-maps
+open import foundation.contractible-maps
open import foundation.dependent-pair-types
+open import foundation.embeddings
open import foundation.function-types
open import foundation.functoriality-cartesian-product-types
open import foundation.functoriality-coproduct-types
@@ -167,32 +171,70 @@ equiv-iterated-coproduct-ℕ (succ-ℕ n) =
### The product `ℕ × ℕ` is equivalent to `ℕ`
-```agda
-ℕ×ℕ≃ℕ : (ℕ × ℕ) ≃ ℕ
-ℕ×ℕ≃ℕ = pair pairing-map is-equiv-pairing-map
+The [2-adic composition map](elementary-number-theory.2-adic-decomposition.md)
+$\mathbb{N}\times\mathbb{N} \to \mathbb{N}$ is an
+[embedding](foundation-core.embeddings.md) which fits in a
+[commuting triangle](foundation-core.commuting-triangles-of-maps.md)
+
+```text
+ ℕ × ℕ -----> ℕ
+ \ /
+ 2-adic-composition-ℕ \ / succ-ℕ
+ \ /
+ ∨ ∨
+ ℕ.
+```
-map-ℕ-to-ℕ×ℕ : ℕ → ℕ × ℕ
-map-ℕ-to-ℕ×ℕ = map-inv-is-equiv (pr2 ℕ×ℕ≃ℕ)
+Since the [image](foundation.images.md) of the 2-adic composition function
+consists precisely of the
+[nonzero natural numbers](elementary-number-theory.nonzero-natural-numbers.md),
+the top map in this triangle is an equivalence.
-is-equiv-map-ℕ-to-ℕ×ℕ : is-equiv map-ℕ-to-ℕ×ℕ
-is-equiv-map-ℕ-to-ℕ×ℕ = is-equiv-map-inv-is-equiv (pr2 ℕ×ℕ≃ℕ)
+```agda
+pairing-equiv-ℕ : ℕ × ℕ ≃ ℕ
+pairing-equiv-ℕ =
+ equiv-domain-logical-equiv-fiber-emb
+ ( 2-adic-composition-emb-ℕ)
+ ( succ-emb-ℕ)
+ ( logical-equiv-fiber-2-adic-composition-fiber-succ-ℕ)
+
+pairing-map-ℕ : ℕ × ℕ → ℕ
+pairing-map-ℕ = map-equiv pairing-equiv-ℕ
+
+map-inv-pairing-equiv-ℕ : ℕ → ℕ × ℕ
+map-inv-pairing-equiv-ℕ = map-inv-equiv pairing-equiv-ℕ
+
+is-equiv-map-inv-pairing-equiv-ℕ : is-equiv map-inv-pairing-equiv-ℕ
+is-equiv-map-inv-pairing-equiv-ℕ =
+ is-equiv-map-inv-equiv pairing-equiv-ℕ
+
+coherence-triangle-pairing-map-ℕ :
+ coherence-triangle-maps
+ ( λ x → 2-adic-composition-ℕ (pr1 x) (pr2 x))
+ ( succ-ℕ)
+ ( pairing-map-ℕ)
+coherence-triangle-pairing-map-ℕ =
+ coherence-triangle-equiv-domain-logical-equiv-fiber-emb
+ ( 2-adic-composition-emb-ℕ)
+ ( succ-emb-ℕ)
+ ( logical-equiv-fiber-2-adic-composition-fiber-succ-ℕ)
```
### The iterated coproduct `ℕ × ℕ × ... × ℕ` is equivalent to `ℕ` for any n
```agda
equiv-iterated-product-ℕ :
- (n : ℕ) → (iterate n (_×_ ℕ) ℕ) ≃ ℕ
+ (n : ℕ) → iterate n (ℕ ×_) ℕ ≃ ℕ
equiv-iterated-product-ℕ zero-ℕ = id-equiv
equiv-iterated-product-ℕ (succ-ℕ n) =
- ( ℕ×ℕ≃ℕ) ∘e
+ ( pairing-equiv-ℕ) ∘e
( equiv-product id-equiv (equiv-iterated-product-ℕ n))
```
### The coproduct `(Fin n) + ℕ` is equivalent to `N` for any standard finite `Fin n`
```agda
-equiv-coproduct-Fin-ℕ : (n : ℕ) → ((Fin n) + ℕ) ≃ ℕ
+equiv-coproduct-Fin-ℕ : (n : ℕ) → Fin n + ℕ ≃ ℕ
equiv-coproduct-Fin-ℕ zero-ℕ = left-unit-law-coproduct ℕ
equiv-coproduct-Fin-ℕ (succ-ℕ n) =
( equiv-coproduct-Fin-ℕ n) ∘e
@@ -203,7 +245,7 @@ equiv-coproduct-Fin-ℕ (succ-ℕ n) =
### The product `(Fin n) × ℕ` is equivalent to `N` for any standard finite `Fin n` where n is nonzero
```agda
-equiv-product-Fin-ℕ : (n : ℕ) → ((Fin (succ-ℕ n)) × ℕ) ≃ ℕ
+equiv-product-Fin-ℕ : (n : ℕ) → Fin (succ-ℕ n) × ℕ ≃ ℕ
equiv-product-Fin-ℕ zero-ℕ =
( left-unit-law-coproduct ℕ) ∘e
( ( equiv-coproduct (left-absorption-product ℕ) left-unit-law-product) ∘e
diff --git a/src/elementary-number-theory/unbounded-farey-fractions.lagda.md b/src/elementary-number-theory/unbounded-farey-fractions.lagda.md
new file mode 100644
index 0000000000..c4f4c98d97
--- /dev/null
+++ b/src/elementary-number-theory/unbounded-farey-fractions.lagda.md
@@ -0,0 +1,80 @@
+# Unbounded Farey fractions
+
+```agda
+module elementary-number-theory.unbounded-farey-fractions where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.integers
+
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+[Farey fractions](elementary-number-theory.farey-fractions.md) are a way of
+encoding all [rational numbers](elementary-number-theory.rational-numbers.md)
+between $0$ and $1$ inclusive. This idea can be generalized to encode all
+rational numbers.
+
+The type of
+{{#concept "unbounded Farey fractions" Agda=unbounded-farey-fraction}} is an
+inductive type that is mutually defined with an adjacency relation, given with
+the following constructors:
+
+```text
+ 𝒾 : ℤ → ℱ
+ 𝓂 : (x y : ℱ) → ℛ x y → ℱ
+
+ 𝓈 : (a : ℤ) → ℛ (𝒾 a) (𝒾 (a + 1))
+ 𝓇 : (x y : ℱ) (r : ℛ x y) → ℛ x (𝓂 x y r)
+ 𝓁 : (x y : ℱ) (r : ℛ x y) → ℛ (𝓂 x y r) y.
+```
+
+## Definitions
+
+### Unbounded Farey fractions
+
+```agda
+mutual
+
+ data
+ unbounded-farey-fraction : UU lzero
+ where
+
+ farey-integer :
+ ℤ → unbounded-farey-fraction
+
+ mediant-unbounded-farey-fraction :
+ (x y : unbounded-farey-fraction) →
+ adjacent-unbounded-farey-fraction x y → unbounded-farey-fraction
+
+ data
+ adjacent-unbounded-farey-fraction :
+ unbounded-farey-fraction → unbounded-farey-fraction → UU lzero
+ where
+
+ adjacent-farey-integer-succ :
+ (a : ℤ) →
+ adjacent-unbounded-farey-fraction
+ ( farey-integer a)
+ ( farey-integer (succ-ℤ a))
+
+ right-adjacent-mediant-unbounded-farey-fraction :
+ (x y : unbounded-farey-fraction)
+ (H : adjacent-unbounded-farey-fraction x y) →
+ adjacent-unbounded-farey-fraction
+ ( x)
+ ( mediant-unbounded-farey-fraction x y H)
+
+ left-adjacent-mediant-unbounded-farey-fraction :
+ (x y : unbounded-farey-fraction)
+ (H : adjacent-unbounded-farey-fraction x y) →
+ adjacent-unbounded-farey-fraction
+ ( mediant-unbounded-farey-fraction x y H)
+ ( y)
+```
diff --git a/src/elementary-number-theory/unit-elements-standard-finite-types.lagda.md b/src/elementary-number-theory/unit-elements-standard-finite-types.lagda.md
index 4b6f36cc3b..84cbfc3a49 100644
--- a/src/elementary-number-theory/unit-elements-standard-finite-types.lagda.md
+++ b/src/elementary-number-theory/unit-elements-standard-finite-types.lagda.md
@@ -68,7 +68,7 @@ pr2 (is-unit-neg-one-Fin {succ-ℕ k}) =
( concatenate-eq-cong-ℕ
( succ-ℕ (succ-ℕ k))
{ x3 = 1}
- ( square-succ-ℕ k)
+ ( square-succ-ℕ' k)
( pair k
( ( commutative-mul-ℕ k (succ-ℕ (succ-ℕ k))) ∙
( inv (right-unit-law-dist-ℕ ((succ-ℕ (succ-ℕ k)) *ℕ k))))))
diff --git a/src/elementary-number-theory/unit-integers.lagda.md b/src/elementary-number-theory/unit-integers.lagda.md
new file mode 100644
index 0000000000..a7ffb3d4df
--- /dev/null
+++ b/src/elementary-number-theory/unit-integers.lagda.md
@@ -0,0 +1,217 @@
+# Unit integers
+
+```agda
+module elementary-number-theory.unit-integers where
+```
+
+Imports
+
+```agda
+open import commutative-algebra.groups-of-units-commutative-rings
+open import commutative-algebra.invertible-elements-commutative-rings
+
+open import elementary-number-theory.equality-integers
+open import elementary-number-theory.integers
+open import elementary-number-theory.multiplication-integers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.nonnegative-integers
+open import elementary-number-theory.ring-of-integers
+
+open import foundation.action-on-identifications-functions
+open import foundation.coproduct-types
+open import foundation.dependent-pair-types
+open import foundation.empty-types
+open import foundation.identity-types
+open import foundation.negation
+open import foundation.transport-along-identifications
+open import foundation.unit-type
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+An [integer](elementary-number-theory.integers.md) $a$ is said to be a
+{{#concept "unit" Disambiguation="integer" Agda=unit-ℤ WD="unit" WDID=Q118084}}
+if it [divides](elementary-number-theory.divisibility-integers.md) the integer
+$1$, i.e., if there exists an integer $b$ such that
+
+$$
+ab=1.
+$$
+
+Note that the predicate of being a unit is expressed without explicitly
+referring to divisibility of the integers in order to avoid cyclic dependencies
+in the library. Some properties of divisibility involving unit integers are
+studied in
+[`elementary-number-theory.divisibility-integers`](elementary-number-theory.divisibility-integers.md`).
+
+## Definitions
+
+### Unit integers
+
+```agda
+is-unit-ℤ : ℤ → UU lzero
+is-unit-ℤ = is-invertible-element-Commutative-Ring ℤ-Commutative-Ring
+
+is-nonunit-ℤ : ℤ → UU lzero
+is-nonunit-ℤ a = ¬ is-unit-ℤ a
+
+unit-ℤ : UU lzero
+unit-ℤ = type-group-of-units-Commutative-Ring ℤ-Commutative-Ring
+
+int-unit-ℤ : unit-ℤ → ℤ
+int-unit-ℤ = inclusion-group-of-units-Commutative-Ring ℤ-Commutative-Ring
+
+is-unit-unit-ℤ : (x : unit-ℤ) → is-unit-ℤ (int-unit-ℤ x)
+is-unit-unit-ℤ =
+ is-invertible-element-inclusion-group-of-units-Commutative-Ring
+ ℤ-Commutative-Ring
+```
+
+### The predicate of being $1$ or $-1$
+
+```agda
+is-one-or-neg-one-ℤ : ℤ → UU lzero
+is-one-or-neg-one-ℤ x = (is-one-ℤ x) + (is-neg-one-ℤ x)
+```
+
+### The unit integer $1$
+
+```agda
+is-unit-one-ℤ : is-unit-ℤ one-ℤ
+is-unit-one-ℤ = is-invertible-element-one-Commutative-Ring ℤ-Commutative-Ring
+
+one-unit-ℤ : unit-ℤ
+one-unit-ℤ = unit-group-of-units-Commutative-Ring ℤ-Commutative-Ring
+
+is-unit-is-one-ℤ : (x : ℤ) → is-one-ℤ x → is-unit-ℤ x
+is-unit-is-one-ℤ x p =
+ is-invertible-element-is-one-Commutative-Ring ℤ-Commutative-Ring x (inv p)
+```
+
+### The unit integer $-1$
+
+```agda
+is-unit-neg-one-ℤ : is-unit-ℤ neg-one-ℤ
+is-unit-neg-one-ℤ = (neg-one-ℤ , refl , refl)
+
+neg-one-unit-ℤ : unit-ℤ
+pr1 neg-one-unit-ℤ = neg-one-ℤ
+pr2 neg-one-unit-ℤ = is-unit-neg-one-ℤ
+
+is-unit-is-neg-one-ℤ :
+ (x : ℤ) → is-neg-one-ℤ x → is-unit-ℤ x
+is-unit-is-neg-one-ℤ .neg-one-ℤ refl = is-unit-neg-one-ℤ
+```
+
+## Properties
+
+### The product $xy$ is a unit if and only if both $x$ and $y$ are units
+
+```agda
+is-unit-mul-ℤ :
+ (x y : ℤ) → is-unit-ℤ x → is-unit-ℤ y → is-unit-ℤ (x *ℤ y)
+is-unit-mul-ℤ = is-invertible-element-mul-Commutative-Ring ℤ-Commutative-Ring
+
+mul-unit-ℤ : unit-ℤ → unit-ℤ → unit-ℤ
+mul-unit-ℤ = mul-group-of-units-Commutative-Ring ℤ-Commutative-Ring
+
+is-unit-left-factor-mul-ℤ :
+ (x y : ℤ) → is-unit-ℤ (x *ℤ y) → is-unit-ℤ x
+is-unit-left-factor-mul-ℤ =
+ is-invertible-element-left-factor-Commutative-Ring ℤ-Commutative-Ring
+
+is-unit-right-factor-ℤ :
+ (x y : ℤ) → is-unit-ℤ (x *ℤ y) → is-unit-ℤ y
+is-unit-right-factor-ℤ =
+ is-invertible-element-right-factor-Commutative-Ring ℤ-Commutative-Ring
+```
+
+### An integer is a unit if and only if it is $1$ or $-1$
+
+```agda
+is-unit-is-one-or-neg-one-ℤ :
+ (x : ℤ) → is-one-or-neg-one-ℤ x → is-unit-ℤ x
+is-unit-is-one-or-neg-one-ℤ x (inl p) = is-unit-is-one-ℤ x p
+is-unit-is-one-or-neg-one-ℤ x (inr p) = is-unit-is-neg-one-ℤ x p
+
+is-one-or-neg-one-is-unit-ℤ :
+ (x : ℤ) → is-unit-ℤ x → is-one-or-neg-one-ℤ x
+is-one-or-neg-one-is-unit-ℤ (inl zero-ℕ) (d , p) = inr refl
+is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (inl zero-ℕ , p , q) =
+ ex-falso (Eq-eq-ℤ (inv q ∙ compute-mul-ℤ neg-one-ℤ (inl (succ-ℕ x))))
+is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (inl (succ-ℕ d) , p , q) =
+ ex-falso (Eq-eq-ℤ (inv q ∙ compute-mul-ℤ (inl (succ-ℕ d)) (inl (succ-ℕ x))))
+is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (inr (inl star) , p , q) =
+ ex-falso (Eq-eq-ℤ (inv q ∙ compute-mul-ℤ zero-ℤ (inl (succ-ℕ x))))
+is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (inr (inr zero-ℕ) , p , q) =
+ ex-falso (Eq-eq-ℤ (inv q ∙ compute-mul-ℤ one-ℤ (inl (succ-ℕ x))))
+is-one-or-neg-one-is-unit-ℤ (inl (succ-ℕ x)) (inr (inr (succ-ℕ d)) , p , q) =
+ ex-falso
+ ( Eq-eq-ℤ (inv q ∙ compute-mul-ℤ (inr (inr (succ-ℕ d))) (inl (succ-ℕ x))))
+is-one-or-neg-one-is-unit-ℤ (inr (inl star)) (d , p , q) =
+ ex-falso (Eq-eq-ℤ (inv (right-zero-law-mul-ℤ d) ∙ q))
+is-one-or-neg-one-is-unit-ℤ (inr (inr zero-ℕ)) (d , p , q) = inl refl
+is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (inl zero-ℕ , p , q) =
+ ex-falso (Eq-eq-ℤ (inv q ∙ compute-mul-ℤ neg-one-ℤ (inr (inr (succ-ℕ x)))))
+is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (inl (succ-ℕ d) , p , q) =
+ ex-falso
+ ( Eq-eq-ℤ (inv q ∙ compute-mul-ℤ (inl (succ-ℕ d)) (inr (inr (succ-ℕ x)))))
+is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (inr (inl star) , p , q) =
+ ex-falso (Eq-eq-ℤ (inv q ∙ compute-mul-ℤ zero-ℤ (inr (inr (succ-ℕ x)))))
+is-one-or-neg-one-is-unit-ℤ (inr (inr (succ-ℕ x))) (inr (inr zero-ℕ) , p , q) =
+ ex-falso (Eq-eq-ℤ (inv q ∙ compute-mul-ℤ one-ℤ (inr (inr (succ-ℕ x)))))
+is-one-or-neg-one-is-unit-ℤ
+ (inr (inr (succ-ℕ x))) (inr (inr (succ-ℕ d)) , p , q) =
+ ex-falso
+ ( Eq-eq-ℤ
+ ( inv q ∙ compute-mul-ℤ (inr (inr (succ-ℕ d))) (inr (inr (succ-ℕ x)))))
+```
+
+### Some examples of integers that aren't units
+
+```agda
+abstract
+ is-nonunit-zero-ℤ : is-nonunit-ℤ zero-ℤ
+ is-nonunit-zero-ℤ H
+ with
+ is-one-or-neg-one-is-unit-ℤ zero-ℤ H
+ ... | inl ()
+ ... | inr ()
+
+abstract
+ is-nonunit-two-ℤ : is-nonunit-ℤ (int-ℕ 2)
+ is-nonunit-two-ℤ H
+ with
+ is-one-or-neg-one-is-unit-ℤ (int-ℕ 2) H
+ ... | inl ()
+ ... | inr ()
+
+abstract
+ is-nonunit-three-ℤ : is-nonunit-ℤ (int-ℕ 3)
+ is-nonunit-three-ℤ H
+ with
+ is-one-or-neg-one-is-unit-ℤ (int-ℕ 3) H
+ ... | inl ()
+ ... | inr ()
+```
+
+### Unit integers are idempotent
+
+```agda
+idempotent-is-unit-ℤ : {x : ℤ} → is-unit-ℤ x → x *ℤ x = one-ℤ
+idempotent-is-unit-ℤ {x} H =
+ f (is-one-or-neg-one-is-unit-ℤ x H)
+ where
+ f : is-one-or-neg-one-ℤ x → x *ℤ x = one-ℤ
+ f (inl refl) = refl
+ f (inr refl) = refl
+
+abstract
+ is-one-is-unit-int-ℕ : (x : ℕ) → is-unit-ℤ (int-ℕ x) → is-one-ℕ x
+ is-one-is-unit-int-ℕ x H with is-one-or-neg-one-is-unit-ℤ (int-ℕ x) H
+ ... | inl p = is-injective-int-ℕ p
+ ... | inr p = ex-falso (tr is-nonnegative-ℤ p (is-nonnegative-int-ℕ x))
+```
diff --git a/src/elementary-number-theory/unit-similarity-integers.lagda.md b/src/elementary-number-theory/unit-similarity-integers.lagda.md
new file mode 100644
index 0000000000..c5b26b74e1
--- /dev/null
+++ b/src/elementary-number-theory/unit-similarity-integers.lagda.md
@@ -0,0 +1,237 @@
+# Unit similarity of integers
+
+```agda
+module elementary-number-theory.unit-similarity-integers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.absolute-value-integers
+open import elementary-number-theory.equality-integers
+open import elementary-number-theory.integers
+open import elementary-number-theory.multiplication-integers
+open import elementary-number-theory.nonnegative-integers
+open import elementary-number-theory.nonzero-integers
+open import elementary-number-theory.unit-integers
+
+open import foundation.action-on-identifications-functions
+open import foundation.binary-relations
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.function-types
+open import foundation.identity-types
+open import foundation.negation
+open import foundation.unit-type
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+Two [integers](elementary-number-theory.integers.md) $a$ and $b$ are said to be
+{{#concept "unit similar" Disambiguation="integers" Agda=sim-unit-ℤ}} if
+
+```text
+¬ (is-nonzero-ℤ a × is-nonzero-ℤ b) → Σ (u : unit-ℤ) ua=b.
+```
+
+The idea is that $a$ and $b$ are unit similar if there exists a
+[unit integer](elementary-number-theory.unit-integers.md) $u$ such that $ua=b$.
+However, this type is not a proposition if both $a$ and $b$ are $0$. The unit
+similarity relation has therefore a slightly more complicated expression.
+
+The unit similarity relation is an
+[equivalence relation](foundation.equivalence-relations.md) on the integers.
+
+## Definitions
+
+### The equivalence relation `sim-unit-ℤ`
+
+```agda
+presim-unit-ℤ : ℤ → ℤ → UU lzero
+presim-unit-ℤ x y = Σ unit-ℤ (λ u → int-unit-ℤ u *ℤ x = y)
+
+sim-unit-ℤ : ℤ → ℤ → UU lzero
+sim-unit-ℤ x y = ¬ (is-zero-ℤ x × is-zero-ℤ y) → presim-unit-ℤ x y
+```
+
+## Properties
+
+### The relations `presim-unit-ℤ` and `sim-unit-ℤ` are logically equivalent
+
+```agda
+sim-unit-presim-unit-ℤ :
+ {x y : ℤ} → presim-unit-ℤ x y → sim-unit-ℤ x y
+sim-unit-presim-unit-ℤ {x} {y} H f = H
+
+presim-unit-sim-unit-ℤ :
+ {x y : ℤ} → sim-unit-ℤ x y → presim-unit-ℤ x y
+presim-unit-sim-unit-ℤ {inl x} {inl y} H = H (λ t → Eq-eq-ℤ (pr1 t))
+presim-unit-sim-unit-ℤ {inl x} {inr y} H = H (λ t → Eq-eq-ℤ (pr1 t))
+presim-unit-sim-unit-ℤ {inr x} {inl y} H = H (λ t → Eq-eq-ℤ (pr2 t))
+pr1 (presim-unit-sim-unit-ℤ {inr (inl star)} {inr (inl star)} H) = one-unit-ℤ
+pr2 (presim-unit-sim-unit-ℤ {inr (inl star)} {inr (inl star)} H) = refl
+presim-unit-sim-unit-ℤ {inr (inl star)} {inr (inr y)} H =
+ H (λ t → Eq-eq-ℤ (pr2 t))
+presim-unit-sim-unit-ℤ {inr (inr x)} {inr (inl star)} H =
+ H (λ t → Eq-eq-ℤ (pr1 t))
+presim-unit-sim-unit-ℤ {inr (inr x)} {inr (inr y)} H =
+ H (λ t → Eq-eq-ℤ (pr1 t))
+```
+
+### The relations `presim-unit-ℤ` and `sim-unit-ℤ` relate `zero-ℤ` only to itself
+
+```agda
+is-nonzero-presim-unit-ℤ :
+ {x y : ℤ} → presim-unit-ℤ x y → is-nonzero-ℤ x → is-nonzero-ℤ y
+is-nonzero-presim-unit-ℤ {x} {y} ((v , (u , (α , α'))) , β) f p =
+ Eq-eq-ℤ (ap (_*ℤ u) (inv q) ∙ commutative-mul-ℤ v u ∙ α')
+ where
+ q : is-zero-ℤ v
+ q = is-injective-right-mul-ℤ x f (β ∙ p)
+
+is-nonzero-sim-unit-ℤ :
+ {x y : ℤ} → sim-unit-ℤ x y → is-nonzero-ℤ x → is-nonzero-ℤ y
+is-nonzero-sim-unit-ℤ H f =
+ is-nonzero-presim-unit-ℤ (H (f ∘ pr1)) f
+
+is-zero-sim-unit-ℤ :
+ {x y : ℤ} → sim-unit-ℤ x y → is-zero-ℤ x → is-zero-ℤ y
+is-zero-sim-unit-ℤ {x} {y} H p =
+ double-negation-elim-is-decidable
+ ( has-decidable-equality-ℤ y zero-ℤ)
+ ( λ g → g (inv (β g) ∙ (ap ((u g) *ℤ_) p ∙ right-zero-law-mul-ℤ (u g))))
+ where
+ K : is-nonzero-ℤ y → presim-unit-ℤ x y
+ K g = H (λ (u , v) → g v)
+ u : is-nonzero-ℤ y → ℤ
+ u g = pr1 (pr1 (K g))
+ v : is-nonzero-ℤ y → ℤ
+ v g = pr1 (pr2 (pr1 (K g)))
+ β : (g : is-nonzero-ℤ y) → (u g) *ℤ x = y
+ β g = pr2 (K g)
+```
+
+### The relations `presim-unit-ℤ` and `sim-unit-ℤ` are equivalence relations
+
+```agda
+refl-presim-unit-ℤ : is-reflexive presim-unit-ℤ
+pr1 (refl-presim-unit-ℤ x) = one-unit-ℤ
+pr2 (refl-presim-unit-ℤ x) = left-unit-law-mul-ℤ x
+
+refl-sim-unit-ℤ : is-reflexive sim-unit-ℤ
+refl-sim-unit-ℤ x f = refl-presim-unit-ℤ x
+
+presim-unit-eq-ℤ : {x y : ℤ} → x = y → presim-unit-ℤ x y
+presim-unit-eq-ℤ {x} refl = refl-presim-unit-ℤ x
+
+sim-unit-eq-ℤ : {x y : ℤ} → x = y → sim-unit-ℤ x y
+sim-unit-eq-ℤ {x} refl = refl-sim-unit-ℤ x
+
+symmetric-presim-unit-ℤ : is-symmetric presim-unit-ℤ
+symmetric-presim-unit-ℤ x y (pair (pair u H) p) =
+ f (is-one-or-neg-one-is-unit-ℤ u H)
+ where
+ f : is-one-or-neg-one-ℤ u → presim-unit-ℤ y x
+ pr1 (f (inl refl)) = one-unit-ℤ
+ pr2 (f (inl refl)) = inv p
+ pr1 (f (inr refl)) = neg-one-unit-ℤ
+ pr2 (f (inr refl)) = inv (inv (neg-neg-ℤ x) ∙ ap (neg-one-ℤ *ℤ_) p)
+
+symmetric-sim-unit-ℤ : is-symmetric sim-unit-ℤ
+symmetric-sim-unit-ℤ x y H f =
+ symmetric-presim-unit-ℤ x y (H (λ p → f (pair (pr2 p) (pr1 p))))
+
+is-nonzero-sim-unit-ℤ' :
+ {x y : ℤ} → sim-unit-ℤ x y → is-nonzero-ℤ y → is-nonzero-ℤ x
+is-nonzero-sim-unit-ℤ' {x} {y} H =
+ is-nonzero-sim-unit-ℤ (symmetric-sim-unit-ℤ x y H)
+
+is-zero-sim-unit-ℤ' :
+ {x y : ℤ} → sim-unit-ℤ x y → is-zero-ℤ y → is-zero-ℤ x
+is-zero-sim-unit-ℤ' {x} {y} H = is-zero-sim-unit-ℤ (symmetric-sim-unit-ℤ x y H)
+
+transitive-presim-unit-ℤ : is-transitive presim-unit-ℤ
+transitive-presim-unit-ℤ x y z (pair (pair v K) q) (pair (pair u H) p) =
+ f (is-one-or-neg-one-is-unit-ℤ u H) (is-one-or-neg-one-is-unit-ℤ v K)
+ where
+ f : is-one-or-neg-one-ℤ u → is-one-or-neg-one-ℤ v → presim-unit-ℤ x z
+ pr1 (f (inl refl) (inl refl)) = one-unit-ℤ
+ pr2 (f (inl refl) (inl refl)) = p ∙ q
+ pr1 (f (inl refl) (inr refl)) = neg-one-unit-ℤ
+ pr2 (f (inl refl) (inr refl)) = ap neg-ℤ p ∙ q
+ pr1 (f (inr refl) (inl refl)) = neg-one-unit-ℤ
+ pr2 (f (inr refl) (inl refl)) = p ∙ q
+ pr1 (f (inr refl) (inr refl)) = one-unit-ℤ
+ pr2 (f (inr refl) (inr refl)) = inv (neg-neg-ℤ x) ∙ (ap neg-ℤ p ∙ q)
+
+transitive-sim-unit-ℤ : is-transitive sim-unit-ℤ
+transitive-sim-unit-ℤ x y z K H f =
+ transitive-presim-unit-ℤ x y z
+ ( K (λ (p , q) → f (is-zero-sim-unit-ℤ' H p , q)))
+ ( H (λ (p , q) → f (p , is-zero-sim-unit-ℤ K q)))
+```
+
+### `sim-unit-ℤ |x| x` holds
+
+```agda
+sim-unit-abs-ℤ : (x : ℤ) → sim-unit-ℤ (int-abs-ℤ x) x
+pr1 (sim-unit-abs-ℤ (inl x) f) = neg-one-unit-ℤ
+pr2 (sim-unit-abs-ℤ (inl x) f) = refl
+sim-unit-abs-ℤ (inr (inl star)) = refl-sim-unit-ℤ zero-ℤ
+sim-unit-abs-ℤ (inr (inr x)) = refl-sim-unit-ℤ (inr (inr x))
+```
+
+### If we have that `sim-unit-ℤ x y`, then they must differ only by sign
+
+```agda
+is-plus-or-minus-sim-unit-ℤ :
+ {x y : ℤ} → sim-unit-ℤ x y → is-plus-or-minus-ℤ x y
+is-plus-or-minus-sim-unit-ℤ {x} {y} H with ( is-decidable-is-zero-ℤ x)
+is-plus-or-minus-sim-unit-ℤ {x} {y} H | inl z =
+ inl (z ∙ inv (is-zero-sim-unit-ℤ H z))
+is-plus-or-minus-sim-unit-ℤ {x} {y} H | inr nz
+ with
+ ( is-one-or-neg-one-is-unit-ℤ
+ ( int-unit-ℤ (pr1 (H (λ u → nz (pr1 u)))))
+ ( is-unit-unit-ℤ (pr1 (H (λ u → nz (pr1 u))))))
+is-plus-or-minus-sim-unit-ℤ {x} {y} H | inr nz | inl pos =
+ inl
+ ( equational-reasoning
+ x
+ = one-ℤ *ℤ x
+ by (inv (left-unit-law-mul-ℤ x))
+ = (int-unit-ℤ (pr1 (H (λ u → nz (pr1 u))))) *ℤ x
+ by inv (ap (_*ℤ x) pos)
+ = y
+ by pr2 (H (λ u → nz (pr1 u))))
+is-plus-or-minus-sim-unit-ℤ {x} {y} H | inr nz | inr p =
+ inr
+ ( equational-reasoning
+ neg-ℤ x
+ = (int-unit-ℤ (pr1 (H (λ u → nz (pr1 u))))) *ℤ x
+ by ap (_*ℤ x) (inv p)
+ = y
+ by pr2 (H (λ u → nz (pr1 u))))
+```
+
+### If `sim-unit-ℤ x y` holds and both `x` and `y` have the same sign, then `x = y`
+
+```agda
+eq-sim-unit-is-nonnegative-ℤ :
+ {a b : ℤ} → is-nonnegative-ℤ a → is-nonnegative-ℤ b → sim-unit-ℤ a b → a = b
+eq-sim-unit-is-nonnegative-ℤ {a} {b} H H' K =
+ rec-coproduct
+ ( id)
+ ( λ K' →
+ eq-is-zero-ℤ
+ ( is-zero-is-nonnegative-neg-is-nonnegative-ℤ H
+ ( is-nonnegative-eq-ℤ (inv K') H'))
+ ( is-zero-is-nonnegative-neg-is-nonnegative-ℤ H'
+ ( is-nonnegative-eq-ℤ (inv (neg-neg-ℤ a) ∙ ap neg-ℤ K') H)))
+ ( is-plus-or-minus-sim-unit-ℤ K)
+```
diff --git a/src/elementary-number-theory/upper-bounds-natural-numbers.lagda.md b/src/elementary-number-theory/upper-bounds-natural-numbers.lagda.md
index 2a0529164b..1d8cc032d7 100644
--- a/src/elementary-number-theory/upper-bounds-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/upper-bounds-natural-numbers.lagda.md
@@ -1,4 +1,4 @@
-# Upper bounds for type families over the natural numbers
+# Upper bounds for structured natural numbers
```agda
module elementary-number-theory.upper-bounds-natural-numbers where
@@ -11,6 +11,19 @@ open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
+open import foundation.coproduct-types
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.double-negation
+open import foundation.empty-types
+open import foundation.function-types
+open import foundation.identity-types
+open import foundation.logical-equivalences
+open import foundation.negation
+open import foundation.propositional-extensionality
+open import foundation.propositions
+open import foundation.transport-along-identifications
+open import foundation.type-arithmetic-empty-type
open import foundation.universe-levels
```
@@ -18,19 +31,39 @@ open import foundation.universe-levels
## Idea
-A type family over the natural numbers has an upper bound `n`, if there is a
-function from `P x` to the type `x ≤ n` for all `x : ℕ`. Similar for strict
-upper bounds.
+Consider a type family $P$ over the
+[natural numbers](elementary-number-theory.natural-numbers.md). A
+{{#concept "structured natural number"}} is simply a natural number $n$ equipped
+with an element $P(n)$. In this file we consider various upper bounds for
+structured natural numbers, and relations between them. This file builds the
+prerequisite infrastructure for the
+[well-ordering principle](elementary-number-theory.well-ordering-principle-natural-numbers.md)
+of the natural numbers, and its direct consequences.
-## Definition
+- A natural number $n$ is said to be an
+ {{#concept "upper bound" Disambiguation="structured natural numbers" Agda=is-upper-bound-ℕ}}
+ if there is a function from $P(x)$ to the type $x \leq n$ for all
+ $x : \mathbb{N}$.
+- A natural number $n$ is said to be a
+ {{#concept "strict upper bound" Disambiguation="structured natural numbers" Agda=is-strict-upper-bound-ℕ}}
+ if there is a function from $P(x)$ to the type $x < n$ for all
+ $x : \mathbb{N}$.
+- A natural number $n$ is said to be a
+ {{#concept "least upper bound" Disambiguation="structured natural numbers" Agda=is-least-upper-bound-ℕ}}
+ if any natural number $x$ is an upper bound if and only if $n \leq x$.
+- A natural number $n$ is said to be a
+ {{#concept "least strict upper bound" Disambiguation="structured natural numbers" Agda=is-least-strict-upper-bound-ℕ}}
+ if any natural number $x$ is a strict upper bound if and only if $n \leq x$.
+
+## Definitions
### Upper bounds
```agda
is-upper-bound-ℕ :
- {l : Level} (P : ℕ → UU l) (n : ℕ) → UU l
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
is-upper-bound-ℕ P n =
- (m : ℕ) → P m → leq-ℕ m n
+ (m : ℕ) → P m → m ≤-ℕ n
```
### Strict upper bounds
@@ -39,11 +72,119 @@ is-upper-bound-ℕ P n =
is-strict-upper-bound-ℕ :
{l : Level} (P : ℕ → UU l) (n : ℕ) → UU l
is-strict-upper-bound-ℕ P n =
- (m : ℕ) → P m → le-ℕ m n
+ (m : ℕ) → P m → m <-ℕ n
+```
+
+### Least upper bounds
+
+```agda
+is-least-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
+is-least-upper-bound-ℕ P n =
+ (x : ℕ) → is-upper-bound-ℕ P x ↔ n ≤-ℕ x
+
+is-upper-bound-is-least-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-least-upper-bound-ℕ P n → is-upper-bound-ℕ P n
+is-upper-bound-is-least-upper-bound-ℕ P n H =
+ backward-implication (H n) (refl-leq-ℕ n)
+
+leq-is-least-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-least-upper-bound-ℕ P n →
+ (m : ℕ) → is-upper-bound-ℕ P m → n ≤-ℕ m
+leq-is-least-upper-bound-ℕ P n H m =
+ forward-implication (H m)
+```
+
+### Least strict upper bounds
+
+```agda
+is-least-strict-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) → ℕ → UU l
+is-least-strict-upper-bound-ℕ P n =
+ (x : ℕ) → is-strict-upper-bound-ℕ P x ↔ n ≤-ℕ x
```
## Properties
+### Being an upper bound is a property
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-prop-is-upper-bound-ℕ :
+ (n : ℕ) → is-prop (is-upper-bound-ℕ P n)
+ is-prop-is-upper-bound-ℕ n =
+ is-prop-Π (λ x → is-prop-function-type (is-prop-leq-ℕ x n))
+
+ is-upper-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-upper-bound-ℕ-Prop n) = is-upper-bound-ℕ P n
+ pr2 (is-upper-bound-ℕ-Prop n) = is-prop-is-upper-bound-ℕ n
+```
+
+### Being a strict upper bound is a property
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-prop-is-strict-upper-bound-ℕ :
+ (n : ℕ) → is-prop (is-strict-upper-bound-ℕ P n)
+ is-prop-is-strict-upper-bound-ℕ n =
+ is-prop-Π (λ x → is-prop-function-type (is-prop-le-ℕ x n))
+
+ is-strict-upper-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-strict-upper-bound-ℕ-Prop n) = is-strict-upper-bound-ℕ P n
+ pr2 (is-strict-upper-bound-ℕ-Prop n) = is-prop-is-strict-upper-bound-ℕ n
+```
+
+### Being a least upper bound is a property
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-prop-is-least-upper-bound-ℕ :
+ (n : ℕ) → is-prop (is-least-upper-bound-ℕ P n)
+ is-prop-is-least-upper-bound-ℕ n =
+ is-prop-Π
+ ( λ x → is-prop-iff-Prop (is-upper-bound-ℕ-Prop P x) (leq-ℕ-Prop n x))
+
+ is-least-upper-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-least-upper-bound-ℕ-Prop n) = is-least-upper-bound-ℕ P n
+ pr2 (is-least-upper-bound-ℕ-Prop n) = is-prop-is-least-upper-bound-ℕ n
+```
+
+### Being a least strict upper bound is a property
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l)
+ where
+
+ is-prop-is-least-strict-upper-bound-ℕ :
+ (n : ℕ) → is-prop (is-least-strict-upper-bound-ℕ P n)
+ is-prop-is-least-strict-upper-bound-ℕ n =
+ is-prop-Π
+ ( λ x →
+ is-prop-iff-Prop (is-strict-upper-bound-ℕ-Prop P x) (leq-ℕ-Prop n x))
+
+ is-least-strict-upper-bound-ℕ-Prop :
+ (n : ℕ) → Prop l
+ pr1 (is-least-strict-upper-bound-ℕ-Prop n) =
+ is-least-strict-upper-bound-ℕ P n
+ pr2 (is-least-strict-upper-bound-ℕ-Prop n) =
+ is-prop-is-least-strict-upper-bound-ℕ n
+```
+
### A strict upper bound is an upper bound
```agda
@@ -53,3 +194,151 @@ is-upper-bound-is-strict-upper-bound-ℕ :
is-upper-bound-is-strict-upper-bound-ℕ P n H x p =
leq-le-ℕ x n (H x p)
```
+
+### Any two least upper bounds are equal
+
+```agda
+eq-is-least-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (m n : ℕ) →
+ is-least-upper-bound-ℕ P m → is-least-upper-bound-ℕ P n → m = n
+eq-is-least-upper-bound-ℕ P m n H K =
+ antisymmetric-leq-ℕ m n
+ ( leq-is-least-upper-bound-ℕ P m H n
+ ( is-upper-bound-is-least-upper-bound-ℕ P n K))
+ ( leq-is-least-upper-bound-ℕ P n K m
+ ( is-upper-bound-is-least-upper-bound-ℕ P m H))
+```
+
+### If $n + 1$ is a least upper bound, then $n$ is not a least upper bound
+
+```agda
+is-not-least-upper-bound-is-least-upper-bound-succ-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-least-upper-bound-ℕ P (succ-ℕ n) → ¬ (is-least-upper-bound-ℕ P n)
+is-not-least-upper-bound-is-least-upper-bound-succ-ℕ P n H K =
+ has-no-fixed-points-succ-ℕ n (eq-is-least-upper-bound-ℕ P (succ-ℕ n) n H K)
+```
+
+### If $n + 1$ is an upper bound and $P (n + 1)$ is empty, then $n$ is an upper bound
+
+```agda
+decrease-is-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-upper-bound-ℕ P (succ-ℕ n) → ¬ P (succ-ℕ n) → is-upper-bound-ℕ P n
+decrease-is-upper-bound-ℕ P n H f m p =
+ map-right-unit-law-coproduct-is-empty
+ ( m ≤-ℕ n)
+ ( m = succ-ℕ n)
+ ( λ α → f (tr P α p))
+ ( decide-leq-succ-ℕ m n (H m p))
+```
+
+### Any successor natural number $n + 1$ such that $P (n + 1)$ is empty is not a least upper bound
+
+```agda
+is-not-least-upper-bound-is-empty-succ-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ ¬ P (succ-ℕ n) → ¬ is-least-upper-bound-ℕ P (succ-ℕ n)
+is-not-least-upper-bound-is-empty-succ-ℕ P n f H =
+ neg-succ-leq-ℕ n
+ ( leq-is-least-upper-bound-ℕ P
+ ( succ-ℕ n)
+ ( H)
+ ( n)
+ ( decrease-is-upper-bound-ℕ P n
+ ( is-upper-bound-is-least-upper-bound-ℕ P (succ-ℕ n) H)
+ ( f)))
+```
+
+### Given a structured natural number, any natural number $n$ such that $P(n)$ is empty is not least upper bound
+
+```agda
+is-not-least-upper-bound-is-empty-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ (m : ℕ) → P m → ¬ (P n) → ¬ is-least-upper-bound-ℕ P n
+is-not-least-upper-bound-is-empty-ℕ P zero-ℕ m p f H =
+ f ( tr P
+ ( is-zero-leq-zero-ℕ m (is-upper-bound-is-least-upper-bound-ℕ P 0 H m p))
+ ( p))
+is-not-least-upper-bound-is-empty-ℕ P (succ-ℕ n) m p f H =
+ is-not-least-upper-bound-is-empty-succ-ℕ P n f H
+```
+
+### Given a number with an element in $P$, the type $P$ at the least upper bound is nonempty
+
+```agda
+is-nonempty-structure-is-in-family-is-least-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ is-least-upper-bound-ℕ P n → (m : ℕ) → P m → is-nonempty (P n)
+is-nonempty-structure-is-in-family-is-least-upper-bound-ℕ P n H m p f =
+ is-not-least-upper-bound-is-empty-ℕ P n m p f H
+```
+
+### Given a structured number in a decidable type family $P$, the least upper bound is structured in $P$
+
+```agda
+structure-least-upper-bound-is-decidable-fam-ℕ :
+ {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) →
+ (n : ℕ) → is-least-upper-bound-ℕ P n → (m : ℕ) → P m → P n
+structure-least-upper-bound-is-decidable-fam-ℕ P d n H m p =
+ double-negation-elim-is-decidable
+ ( d n)
+ ( is-nonempty-structure-is-in-family-is-least-upper-bound-ℕ P n H m p)
+```
+
+### Any upper bound equipped with structure is a least upper bound
+
+```agda
+is-least-upper-bound-is-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (n : ℕ) →
+ P n → is-upper-bound-ℕ P n → is-least-upper-bound-ℕ P n
+pr1 (is-least-upper-bound-is-upper-bound-ℕ P n p H m) K = K n p
+pr2 (is-least-upper-bound-is-upper-bound-ℕ P n p H m) K x q =
+ transitive-leq-ℕ x n m K (H x q)
+```
+
+### Any element greater than an upper bound is an upper bound
+
+```agda
+is-upper-bound-leq-is-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) →
+ (b : ℕ) → is-upper-bound-ℕ P b →
+ (n : ℕ) → b ≤-ℕ n → is-upper-bound-ℕ P n
+is-upper-bound-leq-is-upper-bound-ℕ P b H n K x p =
+ transitive-leq-ℕ x b n K (H x p)
+```
+
+### Being an upper bound of a decidable type family is decidable, given an upper bound
+
+The type family `is-upper-bound-ℕ P` is an example of a type family `Q` over the
+natural numbers satisfying
+
+```text
+ Q b → Π (n : ℕ), is-decidable (Q n)
+```
+
+for any natural number `b`.
+
+```agda
+is-decidable-is-upper-bound-ℕ' :
+ {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) →
+ (b : ℕ) → is-upper-bound-ℕ P b → is-decidable (P b) →
+ (n : ℕ) → is-decidable (is-upper-bound-ℕ P n)
+is-decidable-is-upper-bound-ℕ' P d zero-ℕ H e n =
+ inl (is-upper-bound-leq-is-upper-bound-ℕ P 0 H n (leq-zero-ℕ n))
+is-decidable-is-upper-bound-ℕ' P d (succ-ℕ b) H (inl p) n =
+ is-decidable-iff'
+ ( inv-iff (is-least-upper-bound-is-upper-bound-ℕ P (succ-ℕ b) p H n))
+ ( is-decidable-leq-ℕ (succ-ℕ b) n)
+is-decidable-is-upper-bound-ℕ' P d (succ-ℕ b) H (inr f) =
+ is-decidable-is-upper-bound-ℕ' P d b
+ ( decrease-is-upper-bound-ℕ P b H f)
+ ( d b)
+
+is-decidable-is-upper-bound-ℕ :
+ {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) →
+ (b : ℕ) → is-upper-bound-ℕ P b →
+ (n : ℕ) → is-decidable (is-upper-bound-ℕ P n)
+is-decidable-is-upper-bound-ℕ P d b H =
+ is-decidable-is-upper-bound-ℕ' P d b H (d b)
+```
diff --git a/src/elementary-number-theory/well-ordering-principle-natural-numbers.lagda.md b/src/elementary-number-theory/well-ordering-principle-natural-numbers.lagda.md
index a72905645f..2a0a08a875 100644
--- a/src/elementary-number-theory/well-ordering-principle-natural-numbers.lagda.md
+++ b/src/elementary-number-theory/well-ordering-principle-natural-numbers.lagda.md
@@ -7,15 +7,20 @@ module elementary-number-theory.well-ordering-principle-natural-numbers where
Imports
```agda
+open import elementary-number-theory.decidable-types
open import elementary-number-theory.inequality-natural-numbers
open import elementary-number-theory.lower-bounds-natural-numbers
+open import elementary-number-theory.maximal-structured-natural-numbers
+open import elementary-number-theory.minimal-structured-natural-numbers
open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.upper-bounds-natural-numbers
open import foundation.cartesian-product-types
open import foundation.coproduct-types
open import foundation.decidable-types
open import foundation.dependent-pair-types
open import foundation.empty-types
+open import foundation.function-types
open import foundation.functoriality-dependent-pair-types
open import foundation.hilberts-epsilon-operators
open import foundation.identity-types
@@ -30,109 +35,186 @@ open import foundation.universe-levels
## Idea
-The well-ordering principle of the natural numbers asserts that for every family
-of decidable types over ℕ equipped with a natural number `n` and an element
-`p : P n`, we can find a least natural number `n₀` with an element `p₀ : P n₀`.
+The
+{{#concept "well-ordering principle of the natural numbers" WDID=Q2488476 WD="well-ordering principle"}}
+asserts that for every family of
+[decidable types](foundation.decidable-types.md) over ℕ equipped with a natural
+number `n` and an element `p : P n`, we can find a least natural number `n₀`
+with an element `p₀ : P n₀`.
-## Theorem
+The well-ordering principle has some useful consequences:
+
+- For any family `P` of decidable types equipped with a natural number `n ≥ b`
+ and an element `p : P n` we can find a least natural number `n₀ ≥ b` with an
+ element `p₀ : P n₀`.
+- For any family `P` of decidable types equipped with an element `n ≤ b` and an
+ element `p : P n` we can find a largest natural number `n₁ ≤ b` with an
+ element `p₁ : P n₁`.
+- For any
+ [strictly inflationary map](order-theory.inflationary-maps-strictly-ordered-types.md)
+ `f : ℕ → ℕ` such that `f 0 ≤ b` we can find a largest natural number `n₁` such
+ that `f n₁ ≤ b`.
+
+## Theorems
+
+### The Well-Ordering Principle
```agda
-minimal-element-ℕ :
- {l : Level} (P : ℕ → UU l) → UU l
-minimal-element-ℕ P = Σ ℕ (λ n → (P n) × (is-lower-bound-ℕ P n))
+well-ordering-principle-ℕ' :
+ {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) → is-decidable (P 0) →
+ (n : ℕ) → P n → minimal-element-ℕ P
+well-ordering-principle-ℕ' P d (inl p0) n p =
+ ( 0 , p0 , λ m _ → leq-zero-ℕ m)
+well-ordering-principle-ℕ' P d (inr f) zero-ℕ p =
+ ex-falso (f p)
+well-ordering-principle-ℕ' P d (inr f) (succ-ℕ n) p =
+ shift-minimal-element-ℕ P
+ ( inr f)
+ ( well-ordering-principle-ℕ' (P ∘ succ-ℕ) (d ∘ succ-ℕ) (d 1) n p)
module _
- {l1 : Level} (P : ℕ → Prop l1)
+ {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) {n : ℕ} (p : P n)
where
- all-elements-equal-minimal-element-ℕ :
- all-elements-equal (minimal-element-ℕ (λ n → type-Prop (P n)))
- all-elements-equal-minimal-element-ℕ
- (pair x (pair p l)) (pair y (pair q k)) =
- eq-type-subtype
- ( λ n →
- product-Prop
- ( pair _ (is-prop-type-Prop (P n)))
- ( is-lower-bound-ℕ-Prop n))
- ( antisymmetric-leq-ℕ x y (l y q) (k x p))
-
- is-prop-minimal-element-ℕ :
- is-prop (minimal-element-ℕ (λ n → type-Prop (P n)))
- is-prop-minimal-element-ℕ =
- is-prop-all-elements-equal all-elements-equal-minimal-element-ℕ
-
- minimal-element-ℕ-Prop : Prop l1
- pr1 minimal-element-ℕ-Prop = minimal-element-ℕ (λ n → type-Prop (P n))
- pr2 minimal-element-ℕ-Prop = is-prop-minimal-element-ℕ
-
-is-minimal-element-succ-ℕ :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P)
- (m : ℕ) (pm : P (succ-ℕ m))
- (is-lower-bound-m : is-lower-bound-ℕ (λ x → P (succ-ℕ x)) m) →
- ¬ (P zero-ℕ) → is-lower-bound-ℕ P (succ-ℕ m)
-is-minimal-element-succ-ℕ P d m pm is-lower-bound-m neg-p0 zero-ℕ p0 =
- ex-falso (neg-p0 p0)
-is-minimal-element-succ-ℕ
- P d zero-ℕ pm is-lower-bound-m neg-p0 (succ-ℕ n) psuccn =
- leq-zero-ℕ n
-is-minimal-element-succ-ℕ
- P d (succ-ℕ m) pm is-lower-bound-m neg-p0 (succ-ℕ n) psuccn =
- is-lower-bound-m n psuccn
-
-well-ordering-principle-succ-ℕ :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P)
- (n : ℕ) (p : P (succ-ℕ n)) →
- is-decidable (P zero-ℕ) →
- minimal-element-ℕ (λ m → P (succ-ℕ m)) → minimal-element-ℕ P
-well-ordering-principle-succ-ℕ P d n p (inl p0) u =
- ( 0 , p0 , λ m q → leq-zero-ℕ m)
-well-ordering-principle-succ-ℕ P d n p (inr neg-p0) (m , pm , is-min-m) =
- ( succ-ℕ m , pm , is-minimal-element-succ-ℕ P d m pm is-min-m neg-p0)
-
-well-ordering-principle-ℕ :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) →
- Σ ℕ P → minimal-element-ℕ P
-pr1 (well-ordering-principle-ℕ P d (pair zero-ℕ p)) = zero-ℕ
-pr1 (pr2 (well-ordering-principle-ℕ P d (pair zero-ℕ p))) = p
-pr2 (pr2 (well-ordering-principle-ℕ P d (pair zero-ℕ p))) m q = leq-zero-ℕ m
-well-ordering-principle-ℕ P d (pair (succ-ℕ n) p) =
- well-ordering-principle-succ-ℕ P d n p (d zero-ℕ)
- ( well-ordering-principle-ℕ
- ( λ m → P (succ-ℕ m))
- ( λ m → d (succ-ℕ m))
- ( pair n p))
-
-number-well-ordering-principle-ℕ :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) (nP : Σ ℕ P) → ℕ
-number-well-ordering-principle-ℕ P d nP =
- pr1 (well-ordering-principle-ℕ P d nP)
+ well-ordering-principle-ℕ :
+ minimal-element-ℕ P
+ well-ordering-principle-ℕ =
+ well-ordering-principle-ℕ' P d (d 0) n p
+
+ nat-well-ordering-principle-ℕ :
+ ℕ
+ nat-well-ordering-principle-ℕ =
+ nat-minimal-element-ℕ P well-ordering-principle-ℕ
+
+ structure-nat-well-ordering-principle-ℕ :
+ P nat-well-ordering-principle-ℕ
+ structure-nat-well-ordering-principle-ℕ =
+ structure-minimal-element-ℕ P well-ordering-principle-ℕ
+
+ is-lower-bound-nat-well-ordering-principle-ℕ :
+ is-lower-bound-ℕ P nat-well-ordering-principle-ℕ
+ is-lower-bound-nat-well-ordering-principle-ℕ =
+ is-lower-bound-minimal-element-ℕ P well-ordering-principle-ℕ
+
+ is-largest-lower-bound-nat-well-ordering-principle-ℕ :
+ is-largest-lower-bound-ℕ P nat-well-ordering-principle-ℕ
+ is-largest-lower-bound-nat-well-ordering-principle-ℕ =
+ is-largest-lower-bound-minimal-element-ℕ P well-ordering-principle-ℕ
```
-### The well-ordering principle returns `0` if `P 0` holds
+## Properties
-This is independently of the input `(pair n p) : Σ ℕ P`.
+### The well-ordering principle returns `0` if `P 0` holds
```agda
-is-zero-well-ordering-principle-succ-ℕ :
- {l : Level} (P : ℕ → UU l) (d : is-decidable-fam P)
- (n : ℕ) (p : P (succ-ℕ n)) (d0 : is-decidable (P zero-ℕ)) →
- (x : minimal-element-ℕ (λ m → P (succ-ℕ m))) (p0 : P zero-ℕ) →
- pr1 (well-ordering-principle-succ-ℕ P d n p d0 x) = zero-ℕ
-is-zero-well-ordering-principle-succ-ℕ P d n p (inl p0) x q0 =
- refl
-is-zero-well-ordering-principle-succ-ℕ P d n p (inr np0) x q0 =
- ex-falso (np0 q0)
+is-zero-well-ordering-principle-ℕ' :
+ {l : Level} (P : ℕ → UU l)
+ (d : is-decidable-fam P) (d0 : is-decidable (P 0)) →
+ (n : ℕ) (p : P n) → P 0 →
+ is-zero-ℕ (nat-minimal-element-ℕ P (well-ordering-principle-ℕ' P d d0 n p))
+is-zero-well-ordering-principle-ℕ' P d (inl x) n p p0 = refl
+is-zero-well-ordering-principle-ℕ' P d (inr f) n p p0 = ex-falso (f p0)
is-zero-well-ordering-principle-ℕ :
{l : Level} (P : ℕ → UU l) (d : is-decidable-fam P) →
- (x : Σ ℕ P) → P zero-ℕ → is-zero-ℕ (number-well-ordering-principle-ℕ P d x)
-is-zero-well-ordering-principle-ℕ P d (pair zero-ℕ p) p0 = refl
-is-zero-well-ordering-principle-ℕ P d (pair (succ-ℕ m) p) =
- is-zero-well-ordering-principle-succ-ℕ P d m p (d zero-ℕ)
- ( well-ordering-principle-ℕ
- ( λ z → P (succ-ℕ z))
- ( λ x → d (succ-ℕ x))
- ( pair m p))
+ {n : ℕ} (p : P n) → P 0 → is-zero-ℕ (nat-well-ordering-principle-ℕ P d p)
+is-zero-well-ordering-principle-ℕ P d p p0 =
+ is-zero-well-ordering-principle-ℕ' P d (d 0) _ p p0
+```
+
+### Every decidable type family over `ℕ` equipped with an instance of an element with an upper bound has a bounded maximal element
+
+```agda
+module _
+ {l : Level} (P : ℕ → UU l) (d : (x : ℕ) → is-decidable (P x)) (b : ℕ)
+ where
+
+ minimal-upper-bound-bounded-family-ℕ :
+ minimal-element-ℕ (is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ minimal-upper-bound-bounded-family-ℕ =
+ well-ordering-principle-ℕ
+ ( is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ ( is-decidable-is-upper-bound-ℕ
+ ( bounded-family-family-ℕ P b)
+ ( λ x → is-decidable-product (is-decidable-leq-ℕ x b) (d x))
+ ( b)
+ ( λ x → pr1))
+ ( λ x → pr1)
+
+ nat-bounded-maximal-element-instance-ℕ :
+ ℕ
+ nat-bounded-maximal-element-instance-ℕ =
+ nat-minimal-element-ℕ
+ ( is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ ( minimal-upper-bound-bounded-family-ℕ)
+
+ is-upper-bound-bounded-maximal-element-instance-ℕ :
+ is-upper-bound-ℕ
+ ( bounded-family-family-ℕ P b)
+ ( nat-bounded-maximal-element-instance-ℕ)
+ is-upper-bound-bounded-maximal-element-instance-ℕ =
+ structure-minimal-element-ℕ
+ ( is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ ( minimal-upper-bound-bounded-family-ℕ)
+
+ is-largest-lower-bound-minimal-upper-bound-bounded-family-ℕ :
+ is-largest-lower-bound-ℕ
+ ( is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ ( nat-bounded-maximal-element-instance-ℕ)
+ is-largest-lower-bound-minimal-upper-bound-bounded-family-ℕ =
+ is-largest-lower-bound-minimal-element-ℕ
+ ( is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ ( minimal-upper-bound-bounded-family-ℕ)
+
+ upper-bound-nat-bounded-maximal-element-instance-ℕ :
+ nat-bounded-maximal-element-instance-ℕ ≤-ℕ b
+ upper-bound-nat-bounded-maximal-element-instance-ℕ =
+ is-lower-bound-is-largest-lower-bound-ℕ
+ ( is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ ( nat-bounded-maximal-element-instance-ℕ)
+ ( is-largest-lower-bound-minimal-upper-bound-bounded-family-ℕ)
+ ( b)
+ ( λ x → pr1)
+
+ is-least-upper-bound-nat-bounded-maximal-element-instance-ℕ :
+ is-least-upper-bound-ℕ
+ ( bounded-family-family-ℕ P b)
+ ( nat-bounded-maximal-element-instance-ℕ)
+ pr1 (is-least-upper-bound-nat-bounded-maximal-element-instance-ℕ x) =
+ is-lower-bound-is-largest-lower-bound-ℕ
+ ( is-upper-bound-ℕ (bounded-family-family-ℕ P b))
+ ( nat-bounded-maximal-element-instance-ℕ)
+ ( is-largest-lower-bound-minimal-upper-bound-bounded-family-ℕ)
+ ( x)
+ pr2 (is-least-upper-bound-nat-bounded-maximal-element-instance-ℕ x) =
+ is-upper-bound-leq-is-upper-bound-ℕ
+ ( bounded-family-family-ℕ P b)
+ ( nat-bounded-maximal-element-instance-ℕ)
+ ( is-upper-bound-bounded-maximal-element-instance-ℕ)
+ ( x)
+
+ structure-bounded-maximal-element-instance-ℕ :
+ (m : ℕ) → m ≤-ℕ b → P m →
+ P nat-bounded-maximal-element-instance-ℕ
+ structure-bounded-maximal-element-instance-ℕ m H p =
+ pr2
+ ( structure-least-upper-bound-is-decidable-fam-ℕ
+ ( bounded-family-family-ℕ P b)
+ ( λ x → is-decidable-product (is-decidable-leq-ℕ x b) (d x))
+ ( nat-bounded-maximal-element-instance-ℕ)
+ ( is-least-upper-bound-nat-bounded-maximal-element-instance-ℕ)
+ ( m)
+ ( H , p))
+
+ bounded-maximal-element-instance-ℕ :
+ (m : ℕ) → m ≤-ℕ b → P m → bounded-maximal-element-ℕ P b
+ pr1 (bounded-maximal-element-instance-ℕ m H p) =
+ nat-bounded-maximal-element-instance-ℕ
+ pr1 (pr2 (bounded-maximal-element-instance-ℕ m H p)) =
+ ( upper-bound-nat-bounded-maximal-element-instance-ℕ ,
+ structure-bounded-maximal-element-instance-ℕ m H p)
+ pr2 (pr2 (bounded-maximal-element-instance-ℕ m H p)) =
+ is-upper-bound-bounded-maximal-element-instance-ℕ
```
### The ε-operator for decidable subtypes of ℕ
@@ -143,8 +225,9 @@ is-zero-well-ordering-principle-ℕ P d (pair (succ-ℕ m) p) =
(d : (x : ℕ) → is-decidable (type-Prop (P x))) →
ε-operator-Hilbert (type-subtype P)
ε-operator-decidable-subtype-ℕ {l1} P d t =
- tot ( λ x → pr1)
- ( apply-universal-property-trunc-Prop t
- ( minimal-element-ℕ-Prop P)
- ( well-ordering-principle-ℕ (λ x → type-Prop (P x)) d))
+ tot
+ ( λ x → pr1)
+ ( apply-universal-property-trunc-Prop t
+ ( minimal-element-ℕ-Prop P)
+ ( λ (n , p) → well-ordering-principle-ℕ (type-Prop ∘ P) d p))
```
diff --git a/src/elementary-number-theory/well-ordering-principles-integers.lagda.md b/src/elementary-number-theory/well-ordering-principles-integers.lagda.md
new file mode 100644
index 0000000000..bb24df943f
--- /dev/null
+++ b/src/elementary-number-theory/well-ordering-principles-integers.lagda.md
@@ -0,0 +1,272 @@
+# Well-ordering principles for the integers
+
+```agda
+module elementary-number-theory.well-ordering-principles-integers where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.addition-integers
+open import elementary-number-theory.difference-integers
+open import elementary-number-theory.inequality-integers
+open import elementary-number-theory.integers
+open import elementary-number-theory.natural-numbers
+open import elementary-number-theory.nonnegative-integers
+open import elementary-number-theory.positive-and-negative-integers
+open import elementary-number-theory.positive-integers
+open import elementary-number-theory.well-ordering-principle-natural-numbers
+
+open import foundation.action-on-identifications-functions
+open import foundation.cartesian-product-types
+open import foundation.coproduct-types
+open import foundation.decidable-types
+open import foundation.dependent-pair-types
+open import foundation.function-types
+open import foundation.functoriality-dependent-pair-types
+open import foundation.identity-types
+open import foundation.transport-along-identifications
+open import foundation.universe-levels
+```
+
+
+
+## Idea
+
+The [poset of integers](elementary-number-theory.inequality-integers.md) does
+not satisfy the
+[well-ordering principle of the natural numbers](elementary-number-theory.well-ordering-principle-natural-numbers.md).
+However, there are several useful approximations of the well-ordering principle
+for the [integers](elementary-number-theory.integers.md) that are worth
+recording:
+
+- For every family `A` of [decidable types](foundation.decidable-types.md) over
+ `ℤ` that is bounded from below and comes equipped with an integer `a` and an
+ element of type `A a`, we can find a least integer `a₀` equipped with an
+ element of type `A a₀`. Here, a type family `A` over the integers is bounded
+ from below if it comes equipped with a
+ [lower bound](order-theory.lower-bounds-posets.md) `b` such that `b ≤ x` for
+ all `x : ℤ` equipped with an element of type `A x`.
+- For every family `A` of [decidable types](foundation.decidable-types.md) over
+ `ℤ` that is bounded from above and comes equipped with an integer `a` and an
+ element of type `A a`, we can find a largest integer `a₀` equipped with an
+ element of type `A a₀`. Here, a type family `A` over the integers is bounded
+ from above if it comes equipped with an
+ [upper bound](order-theory.lower-bounds-posets.md) `b` such that `x ≤ b` for
+ all `x : ℤ` equipped with an element of type `A x`.
+
+## Definitions
+
+### Minimal elements
+
+```agda
+module _
+ {l1 : Level} (A : ℤ → UU l1)
+ where
+
+ minimal-element-ℤ : UU l1
+ minimal-element-ℤ = Σ ℤ (λ a → A a × ((b : ℤ) → A b → a ≤-ℤ b))
+```
+
+### Translations of minimal elements
+
+```agda
+module _
+ {l1 : Level} (A : ℤ → UU l1) (a : ℤ)
+ where
+
+ translation-minimal-element-ℤ :
+ minimal-element-ℤ (λ x → A (x +ℤ a)) → minimal-element-ℤ A
+ translation-minimal-element-ℤ =
+ map-Σ
+ ( λ x → A x × ((y : ℤ) → A y → x ≤-ℤ y))
+ ( λ x → x +ℤ a)
+ ( λ x (b , H) →
+ ( b ,
+ λ y c →
+ inv-transpose-right-summand-leq-ℤ' x y a
+ ( H ( diff-ℤ y a)
+ ( tr A (inv (is-section-right-add-neg-ℤ a y)) c))))
+```
+
+### Maximal elements
+
+```agda
+module _
+ {l1 : Level} (A : ℤ → UU l1)
+ where
+
+ maximal-element-ℤ : UU l1
+ maximal-element-ℤ = Σ ℤ (λ a → A a × ((b : ℤ) → A b → b ≤-ℤ a))
+```
+
+### Reflections of minimal and maximal elements
+
+```agda
+module _
+ {l1 : Level} (A : ℤ → UU l1)
+ where
+
+ reflect-minimal-element-ℤ :
+ minimal-element-ℤ (A ∘ neg-ℤ) → maximal-element-ℤ A
+ reflect-minimal-element-ℤ =
+ map-Σ
+ ( λ x → A x × ((y : ℤ) → A y → y ≤-ℤ x))
+ ( neg-ℤ)
+ ( λ x (a , H) →
+ ( a ,
+ λ y b →
+ transpose-right-neg-leq-ℤ y x
+ ( H (neg-ℤ y) (tr A (inv (neg-neg-ℤ y)) b))))
+
+ reflect-maximal-element-ℤ :
+ maximal-element-ℤ (A ∘ neg-ℤ) → minimal-element-ℤ A
+ reflect-maximal-element-ℤ =
+ map-Σ
+ ( λ x → A x × ((y : ℤ) → A y → x ≤-ℤ y))
+ ( neg-ℤ)
+ λ x (a , H) →
+ ( a ,
+ λ y b →
+ transpose-left-neg-leq-ℤ x y
+ ( H (neg-ℤ y) (tr A (inv (neg-neg-ℤ y)) b)))
+```
+
+### The well-ordering principle for the nonnegative integers
+
+The
+{{#concept "well-ordering principle for the nonnegative integers" Agda=well-ordering-principle-nonnegative-ℤ}}
+states that for any family `A` of decidable types over `ℤ` such that the
+implication `A x → is-nonnegative-ℤ x` holds for any `x : ℤ`, if we are given an
+element `(a , a) : Σ ℤ A` then there is a minimal integer `a₀` equipped with an
+element of type `A a₀`.
+
+```agda
+module _
+ {l1 : Level} {A : ℤ → UU l1} (d : (x : ℤ) → is-decidable (A x))
+ where
+
+ well-ordering-principle-nonnegative-ℤ' :
+ ((x : ℤ) → A x → is-nonnegative-ℤ x) →
+ minimal-element-ℕ (A ∘ int-ℕ) → minimal-element-ℤ A
+ pr1 (well-ordering-principle-nonnegative-ℤ' H (n , x , K)) =
+ int-ℕ n
+ pr1 (pr2 (well-ordering-principle-nonnegative-ℤ' H (n , x , K))) =
+ x
+ pr2 (pr2 (well-ordering-principle-nonnegative-ℤ' H (n , x , K))) b y =
+ concatenate-leq-eq-ℤ (int-ℕ n) (leq-int-ℕ n m (K m (tr A (inv α) y))) α
+ where
+
+ m : ℕ
+ m = nat-nonnegative-ℤ (b , H b y)
+
+ α : int-ℕ m = b
+ α = ap pr1 (is-section-nat-nonnegative-ℤ (b , H b y))
+
+ well-ordering-principle-nonnegative-ℤ :
+ ((x : ℤ) → A x → is-nonnegative-ℤ x) → Σ ℤ A → minimal-element-ℤ A
+ well-ordering-principle-nonnegative-ℤ H (a , x) =
+ well-ordering-principle-nonnegative-ℤ' H
+ ( well-ordering-principle-ℕ
+ ( A ∘ int-ℕ)
+ ( d ∘ int-ℕ)
+ ( map-Σ
+ ( A ∘ int-ℕ)
+ ( nat-nonnegative-ℤ)
+ ( λ x → id)
+ ( ( a , H a x) ,
+ ( tr A
+ ( inv (ap pr1 (is-section-nat-nonnegative-ℤ (a , H a x))))
+ ( x)))))
+```
+
+### The well-ordering principle for the positive integers
+
+The
+{{#concept "well-ordering principle for the positive integers" Agda=well-ordering-principle-positive-ℤ}}
+states that for any family `A` of decidable types over `ℤ` such that the
+implication `A x → is-positive-ℤ x` holds for any `x : ℤ`, if we are given an
+element `(a , a) : Σ ℤ A` then there is a minimal integer `a₀` equipped with an
+element of type `A a₀`.
+
+```agda
+module _
+ {l1 : Level} {A : ℤ → UU l1} (d : (x : ℤ) → is-decidable (A x))
+ where
+
+ well-ordering-principle-positive-ℤ :
+ ((x : ℤ) → A x → is-positive-ℤ x) → Σ ℤ A → minimal-element-ℤ A
+ well-ordering-principle-positive-ℤ H (a , x) =
+ well-ordering-principle-nonnegative-ℤ d
+ ( λ b y → is-nonnegative-is-positive-ℤ (H b y))
+ ( a , x)
+```
+
+### The lower bounded well-ordering principle for the integers
+
+```agda
+module _
+ {l1 : Level} {A : ℤ → UU l1} (d : (x : ℤ) → is-decidable (A x))
+ (b : ℤ) (H : (a : ℤ) → A a → b ≤-ℤ a) ((a , x) : Σ ℤ A)
+ where
+
+ lower-bounded-well-ordering-principle-ℤ :
+ minimal-element-ℤ A
+ lower-bounded-well-ordering-principle-ℤ =
+ translation-minimal-element-ℤ A b
+ ( well-ordering-principle-nonnegative-ℤ
+ ( λ c → d (c +ℤ b))
+ ( λ c z →
+ tr
+ ( is-nonnegative-ℤ)
+ ( is-retraction-right-add-neg-ℤ b c)
+ ( H (c +ℤ b) z) )
+ ( diff-ℤ a b , tr A (inv (is-section-right-add-neg-ℤ b a)) x))
+
+ integer-lower-bounded-well-ordering-principle-ℤ : ℤ
+ integer-lower-bounded-well-ordering-principle-ℤ =
+ pr1 lower-bounded-well-ordering-principle-ℤ
+
+ structure-lower-bounded-well-ordering-principle-ℤ :
+ A integer-lower-bounded-well-ordering-principle-ℤ
+ structure-lower-bounded-well-ordering-principle-ℤ =
+ pr1 (pr2 lower-bounded-well-ordering-principle-ℤ)
+
+ is-least-element-integer-lower-bounded-well-ordering-principle-ℤ :
+ (a : ℤ) → A a → integer-lower-bounded-well-ordering-principle-ℤ ≤-ℤ a
+ is-least-element-integer-lower-bounded-well-ordering-principle-ℤ =
+ pr2 (pr2 lower-bounded-well-ordering-principle-ℤ)
+```
+
+### The upper bounded well-ordering principle for the integers
+
+```agda
+module _
+ {l1 : Level} {A : ℤ → UU l1} (d : (x : ℤ) → is-decidable (A x))
+ (b : ℤ) (H : (a : ℤ) → A a → a ≤-ℤ b) ((a , x) : Σ ℤ A)
+ where
+
+ upper-bounded-well-ordering-principle-ℤ :
+ maximal-element-ℤ A
+ upper-bounded-well-ordering-principle-ℤ =
+ reflect-minimal-element-ℤ A
+ ( lower-bounded-well-ordering-principle-ℤ
+ ( λ x → d (neg-ℤ x))
+ ( neg-ℤ b)
+ ( λ x y → transpose-left-neg-leq-ℤ b x (H (neg-ℤ x) y))
+ ( neg-ℤ a , tr A (inv (neg-neg-ℤ a)) x))
+
+ integer-upper-bounded-well-ordering-principle-ℤ : ℤ
+ integer-upper-bounded-well-ordering-principle-ℤ =
+ pr1 upper-bounded-well-ordering-principle-ℤ
+
+ structure-upper-bounded-well-ordering-principle-ℤ :
+ A integer-upper-bounded-well-ordering-principle-ℤ
+ structure-upper-bounded-well-ordering-principle-ℤ =
+ pr1 (pr2 upper-bounded-well-ordering-principle-ℤ)
+
+ is-largest-element-integer-upper-bounded-well-ordering-principle-ℤ :
+ (a : ℤ) → A a → a ≤-ℤ integer-upper-bounded-well-ordering-principle-ℤ
+ is-largest-element-integer-upper-bounded-well-ordering-principle-ℤ =
+ pr2 (pr2 upper-bounded-well-ordering-principle-ℤ)
+```
diff --git a/src/finite-group-theory/permutations-standard-finite-types.lagda.md b/src/finite-group-theory/permutations-standard-finite-types.lagda.md
index 0be0d3314d..33ff631df2 100644
--- a/src/finite-group-theory/permutations-standard-finite-types.lagda.md
+++ b/src/finite-group-theory/permutations-standard-finite-types.lagda.md
@@ -48,13 +48,13 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-A permutation of `Fin n` is an automorphism of `Fin n`.
+A {{#concept "permutation" Disambiguation="standard finite type"}} on a [standard finite type](univalent-combinatorics.standard-finite-types.md) `Fin n` is an [automorphism](foundation.automorphisms.md) of `Fin n`.
## Definitions
```agda
-Permutation : (n : ℕ) → UU lzero
-Permutation n = Aut (Fin n)
+permutation : (n : ℕ) → UU lzero
+permutation n = Aut (Fin n)
```
## Properties
@@ -63,14 +63,12 @@ Permutation n = Aut (Fin n)
```agda
list-transpositions-permutation-Fin' :
- (n : ℕ) (f : Permutation (succ-ℕ n)) →
+ (n : ℕ) (f : permutation (succ-ℕ n)) →
(x : Fin (succ-ℕ n)) → Id (map-equiv f (inr star)) x →
- ( list
- ( Σ
- ( Fin (succ-ℕ n) → Decidable-Prop lzero)
- ( λ P →
- has-cardinality-ℕ 2
- ( Σ (Fin (succ-ℕ n)) (type-Decidable-Prop ∘ P)))))
+ list
+ ( Σ ( Fin (succ-ℕ n) → Decidable-Prop lzero)
+ ( λ P →
+ has-cardinality-ℕ 2 (Σ (Fin (succ-ℕ n)) (type-Decidable-Prop ∘ P))))
list-transpositions-permutation-Fin' zero-ℕ f x p = nil
list-transpositions-permutation-Fin' (succ-ℕ n) f (inl x) p =
cons
@@ -93,7 +91,7 @@ list-transpositions-permutation-Fin' (succ-ℕ n) f (inl x) p =
{ inr star}
{ inl x}
( neq-inr-inl)
- f' : (Permutation (succ-ℕ n))
+ f' : permutation (succ-ℕ n)
f' =
map-inv-equiv
( extend-equiv-Maybe (Fin-Set (succ-ℕ n)))
@@ -110,11 +108,11 @@ list-transpositions-permutation-Fin' (succ-ℕ n) f (inr star) p =
( Fin-succ-Fin-transposition (succ-ℕ n))
( list-transpositions-permutation-Fin' n f' (map-equiv f' (inr star)) refl)
where
- f' : (Permutation (succ-ℕ n))
+ f' : permutation (succ-ℕ n)
f' = map-inv-equiv (extend-equiv-Maybe (Fin-Set (succ-ℕ n))) (pair f p)
list-transpositions-permutation-Fin :
- (n : ℕ) (f : Permutation n) →
+ (n : ℕ) (f : permutation n) →
( list
( Σ
( Fin n → Decidable-Prop lzero)
@@ -125,7 +123,7 @@ list-transpositions-permutation-Fin (succ-ℕ n) f =
abstract
retraction-permutation-list-transpositions-Fin' :
- (n : ℕ) (f : Permutation (succ-ℕ n)) →
+ (n : ℕ) (f : permutation (succ-ℕ n)) →
(x : Fin (succ-ℕ n)) → Id (map-equiv f (inr star)) x →
(y z : Fin (succ-ℕ n)) → Id (map-equiv f y) z →
Id
@@ -189,7 +187,7 @@ abstract
{ inl x}
( neq-inr-inl)
P :
- Σ ( Permutation (succ-ℕ (succ-ℕ n)))
+ Σ ( permutation (succ-ℕ (succ-ℕ n)))
( λ g → Id (map-equiv g (inr star)) (inr star))
P =
pair
@@ -200,9 +198,9 @@ abstract
{ inr star}
{ inl x}
( neq-inr-inl)))
- F' : (Permutation (succ-ℕ n))
+ F' : permutation (succ-ℕ n)
F' = map-inv-equiv (extend-equiv-Maybe (Fin-Set (succ-ℕ n))) P
- lemma2 : (map-equiv (transposition t) (inl z)) = (inl z)
+ lemma2 : map-equiv (transposition t) (inl z) = inl z
lemma2 =
is-fixed-point-standard-transposition
( has-decidable-equality-Fin (succ-ℕ (succ-ℕ n)))
@@ -283,7 +281,7 @@ abstract
{ inl x}
( neq-inr-inl)
P :
- Σ ( Permutation (succ-ℕ (succ-ℕ n)))
+ Σ ( permutation (succ-ℕ (succ-ℕ n)))
( λ g → Id (map-equiv g (inr star)) (inr star))
P = pair
( transposition t ∘e f)
@@ -293,7 +291,7 @@ abstract
{ inr star}
{ inl x}
( neq-inr-inl))
- F' : (Permutation (succ-ℕ n))
+ F' : permutation (succ-ℕ n)
F' = map-inv-equiv (extend-equiv-Maybe (Fin-Set (succ-ℕ n))) P
lemma :
Id
@@ -358,7 +356,7 @@ abstract
{ inr star}
{ inl x}
( neq-inr-inl)
- F' : (Permutation (succ-ℕ n))
+ F' : permutation (succ-ℕ n)
F' =
map-inv-equiv
( extend-equiv-Maybe (Fin-Set (succ-ℕ n)))
@@ -398,7 +396,7 @@ abstract
n f' (map-equiv f' (inr star)) refl y (map-equiv f' y) refl)) ∙
( computation-inv-extend-equiv-Maybe (Fin-Set (succ-ℕ n)) f p y)))
where
- f' : (Permutation (succ-ℕ n))
+ f' : permutation (succ-ℕ n)
f' = map-inv-equiv (extend-equiv-Maybe (Fin-Set (succ-ℕ n))) (pair f p)
retraction-permutation-list-transpositions-Fin'
(succ-ℕ n) f (inr star) p (inl y) (inr star) q =
@@ -428,11 +426,11 @@ abstract
( inr star)) ∙
( inv p))
where
- f' : (Permutation (succ-ℕ n))
+ f' : permutation (succ-ℕ n)
f' = map-inv-equiv (extend-equiv-Maybe (Fin-Set (succ-ℕ n))) (pair f p)
retraction-permutation-list-transpositions-Fin :
- (n : ℕ) (f : Permutation n) →
+ (n : ℕ) (f : permutation n) →
htpy-equiv
( permutation-list-transpositions
( list-transpositions-permutation-Fin n f))
@@ -447,7 +445,7 @@ abstract
permutation-list-standard-transpositions-Fin :
(n : ℕ) →
list (Σ (Fin n × Fin n) (λ (i , j) → i ≠ j)) →
- Permutation n
+ permutation n
permutation-list-standard-transpositions-Fin n =
fold-list
( id-equiv)
@@ -455,7 +453,7 @@ permutation-list-standard-transpositions-Fin n =
standard-transposition (has-decidable-equality-Fin n) neq ∘e p)
list-standard-transpositions-permutation-Fin :
- (n : ℕ) (f : Permutation n) →
+ (n : ℕ) (f : permutation n) →
list (Σ (Fin n × Fin n) (λ (i , j) → i ≠ j))
list-standard-transpositions-permutation-Fin n f =
map-list
@@ -496,7 +494,7 @@ private
htpy-permutation-list n l)
retraction-permutation-list-standard-transpositions-Fin :
- (n : ℕ) (f : Permutation n) →
+ (n : ℕ) (f : permutation n) →
htpy-equiv
( permutation-list-standard-transpositions-Fin
( n)
diff --git a/src/finite-group-theory/transpositions-standard-finite-types.lagda.md b/src/finite-group-theory/transpositions-standard-finite-types.lagda.md
index bd345f2692..cbe388472a 100644
--- a/src/finite-group-theory/transpositions-standard-finite-types.lagda.md
+++ b/src/finite-group-theory/transpositions-standard-finite-types.lagda.md
@@ -57,7 +57,7 @@ module _
(n : ℕ) (i j : Fin n) (neq : i ≠ j)
where
- transposition-Fin : Permutation n
+ transposition-Fin : permutation n
transposition-Fin = standard-transposition (has-decidable-equality-Fin n) neq
map-transposition-Fin : Fin n → Fin n
@@ -109,7 +109,7 @@ module _
refl
is-involution-map-swap-two-last-elements-transposition-Fin (inr star) = refl
- swap-two-last-elements-transposition-Fin : Permutation (succ-ℕ (succ-ℕ n))
+ swap-two-last-elements-transposition-Fin : permutation (succ-ℕ (succ-ℕ n))
pr1 swap-two-last-elements-transposition-Fin =
map-swap-two-last-elements-transposition-Fin
pr2 swap-two-last-elements-transposition-Fin =
@@ -197,7 +197,7 @@ We show that this definiton is an instance of the previous one.
```agda
adjacent-transposition-Fin :
(n : ℕ) → (k : Fin n) →
- Permutation (succ-ℕ n)
+ permutation (succ-ℕ n)
adjacent-transposition-Fin (succ-ℕ n) (inl x) =
equiv-coproduct (adjacent-transposition-Fin n x) id-equiv
adjacent-transposition-Fin (succ-ℕ n) (inr x) =
@@ -567,7 +567,7 @@ list-adjacent-transpositions-transposition-Fin
( inl (inr star)) = cons (inr star) nil
permutation-list-adjacent-transpositions :
- (n : ℕ) → list (Fin n) → Permutation (succ-ℕ n)
+ (n : ℕ) → list (Fin n) → permutation (succ-ℕ n)
permutation-list-adjacent-transpositions n nil = id-equiv
permutation-list-adjacent-transpositions n (cons x l) =
adjacent-transposition-Fin n x ∘e
diff --git a/src/foundation-core/function-types.lagda.md b/src/foundation-core/function-types.lagda.md
index e9ac42fc1f..e1118e021b 100644
--- a/src/foundation-core/function-types.lagda.md
+++ b/src/foundation-core/function-types.lagda.md
@@ -14,7 +14,10 @@ open import foundation.universe-levels
## Idea
-Functions are primitive in Agda. Here we construct some basic functions
+A {{#concept "function"}} is a way of associating to each element $x$ of a domain type an element $f(x)$ of a type $B(x)$, which possibly depends on the input $x$. Functions are primitive in Agda. In this file we construct some basic functions.
+
+The term "function" was first coined by Leibniz, who used the term to describe quantities related to curves, such as slopes, tangents, and
+areas. The concept of functions was first given a precise definition by Euler {{#cite Euler1748}} in paragraph 4 of Chapter 1. Euler also introduced the now familiar notation $f(x)$ for functions.
## Examples
diff --git a/src/foundation-core/identity-types.lagda.md b/src/foundation-core/identity-types.lagda.md
index b4c54955d7..babae9bbfb 100644
--- a/src/foundation-core/identity-types.lagda.md
+++ b/src/foundation-core/identity-types.lagda.md
@@ -43,7 +43,7 @@ type is the least reflexive relation.
We include two notations for the identity type. First, we introduce the identity
type using Martin-Löf's original notation `Id`. Then we introduce as a secondary
-option the infix notation `_=_`.
+option the infix notation `_=_`. The notation for equality was first used by the Welsh physician and mathematician [Robert Recorde](https://en.wikipedia.org/wiki/Robert_Recorde) in 1557. He introduced the notation on [page 237](https://archive.org/details/TheWhetstoneOfWitte/page/n237/mode/2up) of {{#cite Recorde1557}} "bicause noe.2.thynges,can be moare equalle".
**Note**: The equals sign in the infix notation is not the standard equals sign
on your keyboard, but it is the
diff --git a/src/foundation/decidable-propositions.lagda.md b/src/foundation/decidable-propositions.lagda.md
index ef885f24e7..9317b684e1 100644
--- a/src/foundation/decidable-propositions.lagda.md
+++ b/src/foundation/decidable-propositions.lagda.md
@@ -218,18 +218,30 @@ abstract
### Decidable propositions have a count
```agda
+count-is-decidable-prop :
+ {l : Level} {X : UU l} → is-decidable-prop X → count X
+count-is-decidable-prop (H , inl x) =
+ count-is-contr (is-proof-irrelevant-is-prop H x)
+count-is-decidable-prop (H , inr f) =
+ count-is-empty f
+
count-is-decidable-Prop :
- {l : Level} (P : Prop l) →
- is-decidable (type-Prop P) → count (type-Prop P)
-count-is-decidable-Prop P (inl x) =
- count-is-contr (is-proof-irrelevant-is-prop (is-prop-type-Prop P) x)
-count-is-decidable-Prop P (inr x) =
- count-is-empty x
+ {l : Level} (P : Prop l) →
+ is-decidable (type-Prop P) → count (type-Prop P)
+count-is-decidable-Prop P d =
+ count-is-decidable-prop (is-prop-type-Prop P , d)
```
### Decidable propositions are finite
```agda
+abstract
+ is-finite-is-decidable-prop :
+ {l : Level} {X : UU l} →
+ is-decidable-prop X → is-finite X
+ is-finite-is-decidable-prop H =
+ is-finite-count (count-is-decidable-prop H)
+
abstract
is-finite-is-decidable-Prop :
{l : Level} (P : Prop l) →
@@ -237,12 +249,13 @@ abstract
is-finite-is-decidable-Prop P x =
is-finite-count (count-is-decidable-Prop P x)
-is-finite-type-Decidable-Prop :
- {l : Level} (P : Decidable-Prop l) → is-finite (type-Decidable-Prop P)
-is-finite-type-Decidable-Prop P =
- is-finite-is-decidable-Prop
- ( prop-Decidable-Prop P)
- ( is-decidable-Decidable-Prop P)
+abstract
+ is-finite-type-Decidable-Prop :
+ {l : Level} (P : Decidable-Prop l) → is-finite (type-Decidable-Prop P)
+ is-finite-type-Decidable-Prop P =
+ is-finite-is-decidable-Prop
+ ( prop-Decidable-Prop P)
+ ( is-decidable-Decidable-Prop P)
```
### The type of decidable propositions of any universe level is finite
diff --git a/src/foundation/embeddings.lagda.md b/src/foundation/embeddings.lagda.md
index 6631d6bead..1c1f5587fc 100644
--- a/src/foundation/embeddings.lagda.md
+++ b/src/foundation/embeddings.lagda.md
@@ -17,6 +17,7 @@ open import foundation.functoriality-cartesian-product-types
open import foundation.functoriality-dependent-pair-types
open import foundation.fundamental-theorem-of-identity-types
open import foundation.identity-types
+open import foundation.logical-equivalences
open import foundation.transport-along-identifications
open import foundation.truncated-maps
open import foundation.universe-levels
@@ -454,3 +455,48 @@ module _
( equiv-fiber f (f a))
( is-contr-fibers-values-is-emb' e a)
```
+
+### A family of logical equivalences between the fibers of two embeddings into a type induces an equivalence between their domain types
+
+```agda
+module _
+ {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3}
+ (f : A ↪ X) (g : B ↪ X)
+ (H : (x : X) → fiber (map-emb f) x ↔ fiber (map-emb g) x)
+ where
+
+ fam-equiv-logical-equiv-fiber-emb :
+ (x : X) → fiber (map-emb f) x ≃ fiber (map-emb g) x
+ fam-equiv-logical-equiv-fiber-emb x =
+ equiv-iff
+ ( fiber-emb-Prop f x)
+ ( fiber-emb-Prop g x)
+ ( forward-implication (H x))
+ ( backward-implication (H x))
+
+ equiv-domain-logical-equiv-fiber-emb :
+ A ≃ B
+ equiv-domain-logical-equiv-fiber-emb =
+ equiv-total-fiber (map-emb g) ∘e
+ equiv-tot fam-equiv-logical-equiv-fiber-emb ∘e
+ inv-equiv-total-fiber (map-emb f)
+
+ map-equiv-domain-logical-equiv-fiber-emb :
+ A → B
+ map-equiv-domain-logical-equiv-fiber-emb =
+ map-equiv equiv-domain-logical-equiv-fiber-emb
+
+ coherence-triangle-equiv-domain-logical-equiv-fiber-emb :
+ coherence-triangle-maps
+ ( map-emb f)
+ ( map-emb g)
+ ( map-equiv-domain-logical-equiv-fiber-emb)
+ coherence-triangle-equiv-domain-logical-equiv-fiber-emb a =
+ inv (pr2 (forward-implication (H (map-emb f a)) (a , refl)))
+```
+
+## See also
+
+- [Propositional maps (core)](foundation-core.propositional-maps.md)
+- [Propositional-maps](foundation.propositional-maps.md)
+- [Subtype duality](foundation.subtype-duality.md)
diff --git a/src/foundation/iterated-cartesian-product-types.lagda.md b/src/foundation/iterated-cartesian-product-types.lagda.md
index ab1849056b..9b5542ae28 100644
--- a/src/foundation/iterated-cartesian-product-types.lagda.md
+++ b/src/foundation/iterated-cartesian-product-types.lagda.md
@@ -144,29 +144,29 @@ equiv-product-iterated-product-lists (cons x p) q =
```agda
permutation-iterated-product-Fin-Π :
- {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : Permutation n) → UU l
+ {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : permutation n) → UU l
permutation-iterated-product-Fin-Π n A t =
iterated-product-Fin-Π n (A ∘ map-equiv t)
equiv-permutation-iterated-product-Fin-Π :
- {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : Permutation n) →
+ {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : permutation n) →
permutation-iterated-product-Fin-Π n A t ≃ iterated-product-Fin-Π n A
equiv-permutation-iterated-product-Fin-Π n A t =
equiv-Π (λ z → A z) t (λ a → id-equiv)
eq-permutation-iterated-product-Fin-Π :
- {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : Permutation n) →
+ {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : permutation n) →
permutation-iterated-product-Fin-Π n A t = iterated-product-Fin-Π n A
eq-permutation-iterated-product-Fin-Π n A t =
eq-equiv (equiv-permutation-iterated-product-Fin-Π n A t)
permutation-iterated-product-Fin-recursive :
- {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : Permutation n) → UU l
+ {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : permutation n) → UU l
permutation-iterated-product-Fin-recursive n A t =
iterated-product-Fin-recursive n (A ∘ map-equiv t)
equiv-permutation-iterated-product-Fin-recursive :
- {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : Permutation n) →
+ {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : permutation n) →
permutation-iterated-product-Fin-recursive n A t ≃
iterated-product-Fin-recursive n A
equiv-permutation-iterated-product-Fin-recursive n A t =
@@ -175,19 +175,19 @@ equiv-permutation-iterated-product-Fin-recursive n A t =
( equiv-iterated-product-Fin-recursive-Π n (A ∘ map-equiv t))
eq-permutation-iterated-product-Fin-recursive :
- {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : Permutation n) →
+ {l : Level} (n : ℕ) (A : (Fin n → UU l)) (t : permutation n) →
permutation-iterated-product-Fin-recursive n A t =
iterated-product-Fin-recursive n A
eq-permutation-iterated-product-Fin-recursive n A t =
eq-equiv (equiv-permutation-iterated-product-Fin-recursive n A t)
permutation-iterated-product-lists :
- {l : Level} (L : list (UU l)) (t : Permutation (length-list L)) → UU l
+ {l : Level} (L : list (UU l)) (t : permutation (length-list L)) → UU l
permutation-iterated-product-lists L t =
iterated-product-lists (permute-list L t)
equiv-permutation-iterated-product-lists :
- {l : Level} (L : list (UU l)) (t : Permutation (length-list L)) →
+ {l : Level} (L : list (UU l)) (t : permutation (length-list L)) →
permutation-iterated-product-lists L t ≃
iterated-product-lists L
equiv-permutation-iterated-product-lists L t =
@@ -209,7 +209,7 @@ equiv-permutation-iterated-product-lists L t =
( equiv-iterated-product-Fin-recursive-lists (permute-list L t))))))
eq-permutation-iterated-product-lists :
- {l : Level} (L : list (UU l)) (t : Permutation (length-list L)) →
+ {l : Level} (L : list (UU l)) (t : permutation (length-list L)) →
permutation-iterated-product-lists L t =
iterated-product-lists L
eq-permutation-iterated-product-lists L t =
diff --git a/src/foundation/iterating-functions.lagda.md b/src/foundation/iterating-functions.lagda.md
index 339d4eed0c..dcc947bd16 100644
--- a/src/foundation/iterating-functions.lagda.md
+++ b/src/foundation/iterating-functions.lagda.md
@@ -148,10 +148,11 @@ module _
(k l : ℕ) (f : X → X) (x : X) →
iterate (exp-ℕ l k) f x = iterate k (iterate l) f x
iterate-exp-ℕ zero-ℕ l f x = refl
- iterate-exp-ℕ (succ-ℕ k) l f x =
- ( iterate-mul-ℕ (exp-ℕ l k) l f x) ∙
- ( ( iterate-exp-ℕ k l (iterate l f) x) ∙
- ( inv (htpy-eq (reassociate-iterate-succ-ℕ k (iterate l) f) x)))
+ iterate-exp-ℕ (succ-ℕ zero-ℕ) l f x = refl
+ iterate-exp-ℕ (succ-ℕ (succ-ℕ k)) l f x =
+ ( iterate-mul-ℕ (exp-ℕ l (succ-ℕ k)) l f x) ∙
+ ( ( iterate-exp-ℕ (succ-ℕ k) l (iterate l f) x) ∙
+ ( inv (htpy-eq (reassociate-iterate-succ-ℕ (succ-ℕ k) (iterate l) f) x)))
module _
{l : Level} (X : Set l)
diff --git a/src/foundation/subtype-duality.lagda.md b/src/foundation/subtype-duality.lagda.md
index abd64501e7..597d3853c9 100644
--- a/src/foundation/subtype-duality.lagda.md
+++ b/src/foundation/subtype-duality.lagda.md
@@ -22,6 +22,16 @@ open import foundation-core.propositions
+## Idea
+
+The {{#concept "subtype duality" Agda=equiv-Fiber-Prop}} principle establishes an equivalence
+
+$$
+ \left(\sum_{A:\mathcal{U}} X\hookrightarrow A\right) \simeq (A \to \mathrm{Prop}),
+$$
+
+In other words, it establishes a unique correspondence between [embeddings](foundation-core.embeddings.md) into a type $A$, and [subtypes](foundation-core.subtypes.md) of $A$.
+
## Theorem
### Subtype duality
@@ -36,7 +46,11 @@ equiv-Fiber-Prop :
equiv-Fiber-Prop l A =
( equiv-Fiber-structure l is-prop A) ∘e
( equiv-tot (λ X → equiv-tot equiv-is-prop-map-is-emb))
+```
+
+### Inhabited type duality
+```agda
Slice-surjection : (l : Level) {l1 : Level} (A : UU l1) → UU (lsuc l ⊔ l1)
Slice-surjection l A = Σ (UU l) (λ X → X ↠ A)
diff --git a/src/foundation/type-arithmetic-cartesian-product-types.lagda.md b/src/foundation/type-arithmetic-cartesian-product-types.lagda.md
index 4d0d338b3b..798dae6897 100644
--- a/src/foundation/type-arithmetic-cartesian-product-types.lagda.md
+++ b/src/foundation/type-arithmetic-cartesian-product-types.lagda.md
@@ -110,6 +110,13 @@ module _
inv-right-unit-law-product-is-contr =
inv-equiv right-unit-law-product-is-contr
+module _
+ {l1 l2 : Level} {A : UU l1} {B : UU l2} (H : A → is-contr B)
+ where
+
+ right-unit-law-product-is-contr' : A × B ≃ A
+ right-unit-law-product-is-contr' = right-unit-law-Σ-is-contr H
+
module _
{l1 l2 : Level} {A : UU l1} {B : UU l2} (is-contr-A : is-contr A)
where
@@ -132,6 +139,14 @@ module _
equiv-pr2-product-is-contr : (A × B) ≃ B
pr1 equiv-pr2-product-is-contr = pr2
pr2 equiv-pr2-product-is-contr = is-equiv-pr2-product-is-contr
+
+module _
+ {l1 l2 : Level} {A : UU l1} {B : UU l2} (H : B → is-contr A)
+ where
+
+ left-unit-law-product-is-contr' : A × B ≃ B
+ left-unit-law-product-is-contr' =
+ right-unit-law-product-is-contr' H ∘e commutative-product
```
### Adding redundant properties
diff --git a/src/foundation/type-duality.lagda.md b/src/foundation/type-duality.lagda.md
index c2beea330e..7582ccd9e2 100644
--- a/src/foundation/type-duality.lagda.md
+++ b/src/foundation/type-duality.lagda.md
@@ -314,3 +314,4 @@ fiber-Σ {l1} {l2} X A =
- In [`foundation.binary-type-duality`](foundation.binary-type-duality.md) we
show that [binary relations](foundation.binary-relations.md) are equivalently
described as [spans of types](foundation.spans.md).
+- [Subtype duality](foundation.subtype-duality.md)
diff --git a/src/group-theory/commutative-monoids.lagda.md b/src/group-theory/commutative-monoids.lagda.md
index 89b8b3f6aa..a3cde60757 100644
--- a/src/group-theory/commutative-monoids.lagda.md
+++ b/src/group-theory/commutative-monoids.lagda.md
@@ -19,6 +19,8 @@ open import foundation.universe-levels
open import group-theory.monoids
open import group-theory.semigroups
+
+open import structured-types.magmas
```
@@ -66,6 +68,10 @@ module _
monoid-Commutative-Monoid : Monoid l
monoid-Commutative-Monoid = pr1 M
+ unital-magma-Commutative-Monoid : Unital-Magma l
+ unital-magma-Commutative-Monoid =
+ unital-magma-Monoid monoid-Commutative-Monoid
+
semigroup-Commutative-Monoid : Semigroup l
semigroup-Commutative-Monoid = semigroup-Monoid monoid-Commutative-Monoid
diff --git a/src/group-theory/invertible-elements-monoids.lagda.md b/src/group-theory/invertible-elements-monoids.lagda.md
index c50cf77558..2f6b9aa379 100644
--- a/src/group-theory/invertible-elements-monoids.lagda.md
+++ b/src/group-theory/invertible-elements-monoids.lagda.md
@@ -19,6 +19,7 @@ open import foundation.injective-maps
open import foundation.propositions
open import foundation.sets
open import foundation.subtypes
+open import foundation.transport-along-identifications
open import foundation.universe-levels
open import group-theory.monoids
@@ -289,9 +290,34 @@ module _
left-unit-law-mul-Monoid M (unit-Monoid M)
pr2 (pr2 is-invertible-element-unit-Monoid) =
left-unit-law-mul-Monoid M (unit-Monoid M)
+
+ is-invertible-element-is-unit-Monoid :
+ (x : type-Monoid M) → unit-Monoid M = x →
+ is-invertible-element-Monoid M x
+ is-invertible-element-is-unit-Monoid .(unit-Monoid M) refl =
+ is-invertible-element-unit-Monoid
+```
+
+### The inverse of an invertible element is invertible
+
+```agda
+module _
+ {l : Level} (M : Monoid l)
+ where
+
+ is-invertible-element-inv-is-invertible-element-Monoid :
+ {x : type-Monoid M} (H : is-invertible-element-Monoid M x) →
+ is-invertible-element-Monoid M (inv-is-invertible-element-Monoid M H)
+ pr1 (is-invertible-element-inv-is-invertible-element-Monoid {x} H) = x
+ pr1 (pr2 (is-invertible-element-inv-is-invertible-element-Monoid H)) =
+ is-left-inverse-inv-is-invertible-element-Monoid M H
+ pr2 (pr2 (is-invertible-element-inv-is-invertible-element-Monoid H)) =
+ is-right-inverse-inv-is-invertible-element-Monoid M H
```
-### Invertible elements are closed under multiplication
+### If two of the three elements `x`, `y`, and `xy` are invertible, then so is the third
+
+#### Invertible elements are closed under multiplication
```agda
module _
@@ -349,21 +375,52 @@ module _
( is-left-invertible-is-invertible-element-Monoid M y K))
```
-### The inverse of an invertible element is invertible
+#### If `y` and `xy` are invertible, then so is `x`
```agda
module _
- {l : Level} (M : Monoid l)
+ {l : Level} (M : Monoid l) (x y : type-Monoid M)
where
- is-invertible-element-inv-is-invertible-element-Monoid :
- {x : type-Monoid M} (H : is-invertible-element-Monoid M x) →
- is-invertible-element-Monoid M (inv-is-invertible-element-Monoid M H)
- pr1 (is-invertible-element-inv-is-invertible-element-Monoid {x} H) = x
- pr1 (pr2 (is-invertible-element-inv-is-invertible-element-Monoid H)) =
- is-left-inverse-inv-is-invertible-element-Monoid M H
- pr2 (pr2 (is-invertible-element-inv-is-invertible-element-Monoid H)) =
- is-right-inverse-inv-is-invertible-element-Monoid M H
+ is-invertible-element-left-factor-Monoid :
+ is-invertible-element-Monoid M y →
+ is-invertible-element-Monoid M (mul-Monoid M x y) →
+ is-invertible-element-Monoid M x
+ is-invertible-element-left-factor-Monoid H@(y' , Ly , Ry) K =
+ tr
+ ( is-invertible-element-Monoid M)
+ ( associative-mul-Monoid M x y y' ∙
+ ap (mul-Monoid M x) Ly ∙
+ right-unit-law-mul-Monoid M x)
+ ( is-invertible-element-mul-Monoid M
+ ( mul-Monoid M x y)
+ ( y')
+ ( K)
+ ( is-invertible-element-inv-is-invertible-element-Monoid M H))
+```
+
+#### If `x` and `xy` are invertible, then so is `y`
+
+```agda
+module _
+ {l : Level} (M : Monoid l) (x y : type-Monoid M)
+ where
+
+ is-invertible-element-right-factor-Monoid :
+ is-invertible-element-Monoid M x →
+ is-invertible-element-Monoid M (mul-Monoid M x y) →
+ is-invertible-element-Monoid M y
+ is-invertible-element-right-factor-Monoid H@(x' , Lx , Rx) K =
+ tr
+ ( is-invertible-element-Monoid M)
+ ( inv (associative-mul-Monoid M x' x y) ∙
+ ap (mul-Monoid' M y) Rx ∙
+ left-unit-law-mul-Monoid M y)
+ ( is-invertible-element-mul-Monoid M
+ ( x')
+ ( mul-Monoid M x y)
+ ( is-invertible-element-inv-is-invertible-element-Monoid M H)
+ ( K))
```
### An element is invertible if and only if multiplying by it is an equivalence
diff --git a/src/group-theory/monoids.lagda.md b/src/group-theory/monoids.lagda.md
index 6a0c542cfc..b422a3f3e4 100644
--- a/src/group-theory/monoids.lagda.md
+++ b/src/group-theory/monoids.lagda.md
@@ -18,6 +18,7 @@ open import foundation.universe-levels
open import group-theory.semigroups
+open import structured-types.magmas
open import structured-types.h-spaces
open import structured-types.wild-monoids
```
@@ -48,6 +49,9 @@ module _
semigroup-Monoid : Semigroup l
semigroup-Monoid = pr1 M
+ magma-Monoid : Magma l
+ magma-Monoid = magma-Semigroup semigroup-Monoid
+
is-unital-Monoid : is-unital-Semigroup semigroup-Monoid
is-unital-Monoid = pr2 M
@@ -94,6 +98,10 @@ module _
right-unit-law-mul-Monoid : (x : type-Monoid) → mul-Monoid x unit-Monoid = x
right-unit-law-mul-Monoid = pr2 (pr2 has-unit-Monoid)
+ unital-magma-Monoid : Unital-Magma l
+ pr1 unital-magma-Monoid = magma-Monoid
+ pr2 unital-magma-Monoid = has-unit-Monoid
+
left-swap-mul-Monoid :
{x y z : type-Monoid} → mul-Monoid x y = mul-Monoid y x →
mul-Monoid x (mul-Monoid y z) =
diff --git a/src/group-theory/powers-of-elements-monoids.lagda.md b/src/group-theory/powers-of-elements-monoids.lagda.md
index 66c4e4f41b..e9d0e489f9 100644
--- a/src/group-theory/powers-of-elements-monoids.lagda.md
+++ b/src/group-theory/powers-of-elements-monoids.lagda.md
@@ -25,10 +25,20 @@ open import group-theory.monoids
## Idea
-The **power operation** on a [monoid](group-theory.monoids.md) is the map
+The {{#concept "power operation" Disambiguation="monoid" Agda=power-Monoid}} on a [monoid](group-theory.monoids.md) is the map
`n x ↦ xⁿ`, which is defined by [iteratively](foundation.iterating-functions.md)
multiplying `x` with itself `n` times.
+We define the power operation such that the following equalities hold by definition:
+
+```text
+ x⁰ ≐ 1
+ x¹ ≐ x
+ xⁿ⁺² ≐ xⁿ⁺¹ · x.
+```
+
+This setup requires one extra step for the most basic properties, but it avoids having a superficial factor of the multiplicative unit in its definition for `n ≥ 1`.
+
## Definitions
### Powers of elements of monoids
diff --git a/src/group-theory/semigroups.lagda.md b/src/group-theory/semigroups.lagda.md
index 4709573fcf..fda03b20cd 100644
--- a/src/group-theory/semigroups.lagda.md
+++ b/src/group-theory/semigroups.lagda.md
@@ -13,6 +13,8 @@ open import foundation.dependent-pair-types
open import foundation.identity-types
open import foundation.sets
open import foundation.universe-levels
+
+open import structured-types.magmas
```
@@ -99,6 +101,10 @@ module _
( associative-mul-Semigroup _ _ _) ∙
( ap (mul-Semigroup _) (left-swap-mul-Semigroup H)) ∙
( inv (associative-mul-Semigroup _ _ _))
+
+ magma-Semigroup : Magma l
+ pr1 magma-Semigroup = type-Semigroup
+ pr2 magma-Semigroup = mul-Semigroup
```
### The structure of a semigroup
diff --git a/src/linear-algebra/vectors.lagda.md b/src/linear-algebra/vectors.lagda.md
index a870ba74c9..75ab5fbf56 100644
--- a/src/linear-algebra/vectors.lagda.md
+++ b/src/linear-algebra/vectors.lagda.md
@@ -29,6 +29,8 @@ open import foundation.unit-type
open import foundation.universe-levels
open import foundation.whiskering-higher-homotopies-composition
+open import lists.lists
+
open import univalent-combinatorics.involution-standard-finite-types
open import univalent-combinatorics.standard-finite-types
```
@@ -71,9 +73,9 @@ module _
revert-vec empty-vec = empty-vec
revert-vec (x ∷ v) = snoc-vec (revert-vec v) x
- all-vec : {l2 : Level} {n : ℕ} → (P : A → UU l2) → vec A n → UU l2
- all-vec P empty-vec = raise-unit _
- all-vec P (x ∷ v) = P x × all-vec P v
+ for-all-vec : {l2 : Level} {n : ℕ} → (P : A → UU l2) → vec A n → UU l2
+ for-all-vec P empty-vec = raise-unit _
+ for-all-vec P (x ∷ v) = P x × for-all-vec P v
component-vec :
(n : ℕ) → vec A n → Fin n → A
@@ -85,7 +87,7 @@ module _
is-head : {n : ℕ} (a : A) (l : vec A n) → a ∈-vec (a ∷ l)
is-in-tail : {n : ℕ} (a x : A) (l : vec A n) → a ∈-vec l → a ∈-vec (x ∷ l)
- index-in-vec : (n : ℕ) → (a : A) → (v : vec A n) → a ∈-vec v → Fin n
+ index-in-vec : (n : ℕ) (a : A) (v : vec A n) → a ∈-vec v → Fin n
index-in-vec (succ-ℕ n) a (.a ∷ v) (is-head .a .v) =
inr star
index-in-vec (succ-ℕ n) a (x ∷ v) (is-in-tail .a .x .v I) =
@@ -149,6 +151,16 @@ module _
eq-component-functional-vec-index-in-functional-vec n x v I = pr2 I
```
+### The definition of `fold-vec`
+
+```agda
+fold-vec :
+ {l1 l2 : Level} {A : UU l1} {B : UU l2} (b : B) (μ : A → (B → B)) →
+ {n : ℕ} → vec A n → B
+fold-vec b μ {0} _ = b
+fold-vec b μ (a ∷ l) = μ a (fold-vec b μ l)
+```
+
## Properties
### Characterizing equality of listed vectors
@@ -436,3 +448,54 @@ compute-tr-vec :
(x ∷ tr (vec A) (is-injective-succ-ℕ p) v)
compute-tr-vec refl v x = refl
```
+
+### Back and forth between vectors and lists
+
+```agda
+module _
+ {l : Level} {A : UU l}
+ where
+
+ list-vec : (n : ℕ) → vec A n → list A
+ list-vec zero-ℕ _ = nil
+ list-vec (succ-ℕ n) (x ∷ l) = cons x (list-vec n l)
+
+ vec-list : (l : list A) → vec A (length-list l)
+ vec-list nil = empty-vec
+ vec-list (cons x l) = x ∷ vec-list l
+
+ is-section-vec-list : (λ l → list-vec (length-list l) (vec-list l)) ~ id
+ is-section-vec-list nil = refl
+ is-section-vec-list (cons x l) = ap (cons x) (is-section-vec-list l)
+
+ is-retraction-vec-list :
+ ( λ (x : Σ ℕ (λ n → vec A n)) →
+ ( length-list (list-vec (pr1 x) (pr2 x)) ,
+ vec-list (list-vec (pr1 x) (pr2 x)))) ~
+ id
+ is-retraction-vec-list (zero-ℕ , empty-vec) = refl
+ is-retraction-vec-list (succ-ℕ n , (x ∷ v)) =
+ ap
+ ( λ v → succ-ℕ (pr1 v) , (x ∷ (pr2 v)))
+ ( is-retraction-vec-list (n , v))
+```
+
+### Back and forth between functional vectors and lists
+
+```agda
+module _
+ {l : Level} {A : UU l}
+ where
+
+ list-functional-vec : (n : ℕ) → functional-vec A n → list A
+ list-functional-vec zero-ℕ v =
+ nil
+ list-functional-vec (succ-ℕ n) v =
+ cons (v (inr star)) (list-functional-vec n (v ∘ inl))
+
+ functional-vec-list : (l : list A) → functional-vec A (length-list l)
+ functional-vec-list nil =
+ empty-functional-vec
+ functional-vec-list (cons x l) =
+ cons-functional-vec (length-list l) x (functional-vec-list l)
+```
diff --git a/src/lists.lagda.md b/src/lists.lagda.md
index 0263108995..ca2b96a680 100644
--- a/src/lists.lagda.md
+++ b/src/lists.lagda.md
@@ -13,7 +13,7 @@ open import lists.lists public
open import lists.lists-discrete-types public
open import lists.permutation-lists public
open import lists.permutation-vectors public
-open import lists.predicates-on-lists public
+open import lists.universal-quantification-lists public
open import lists.quicksort-lists public
open import lists.reversing-lists public
open import lists.sort-by-insertion-lists public
diff --git a/src/lists/arrays.lagda.md b/src/lists/arrays.lagda.md
index 054ea39af4..a784a71eef 100644
--- a/src/lists/arrays.lagda.md
+++ b/src/lists/arrays.lagda.md
@@ -24,6 +24,7 @@ open import foundation.universe-levels
open import linear-algebra.vectors
+open import lists.elementhood-relation-lists
open import lists.lists
open import univalent-combinatorics.involution-standard-finite-types
@@ -34,8 +35,11 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-An array is a pair of a natural number `n`, and a function from `Fin n` to `A`.
-We show that arrays and lists are equivalent.
+An {{#concept "array" Agda=array}} is a pair consisting of a [natural number](elementary-number-theory.natural-numbers.md) `n`, and a [functional vector](linear-algebra.vectors.md) of `n` elements of `A`. The concept of array is [equivalent](foundation-core.equivalences.md) to the concept of [list](lists.lists.md).
+
+## Definitions
+
+### Arrays
```agda
array : {l : Level} → UU l → UU l
@@ -84,48 +88,13 @@ module _
revert-array (n , t) = (n , λ k → t (opposite-Fin n k))
```
-### The definition of `fold-vec`
-
-```agda
-fold-vec :
- {l1 l2 : Level} {A : UU l1} {B : UU l2} (b : B) (μ : A → (B → B)) →
- {n : ℕ} → vec A n → B
-fold-vec b μ {0} _ = b
-fold-vec b μ (a ∷ l) = μ a (fold-vec b μ l)
-```
-
## Properties
-### The types of lists and arrays are equivalent
-
```agda
module _
{l : Level} {A : UU l}
where
- list-vec : (n : ℕ) → (vec A n) → list A
- list-vec zero-ℕ _ = nil
- list-vec (succ-ℕ n) (x ∷ l) = cons x (list-vec n l)
-
- vec-list : (l : list A) → vec A (length-list l)
- vec-list nil = empty-vec
- vec-list (cons x l) = x ∷ vec-list l
-
- is-section-vec-list : (λ l → list-vec (length-list l) (vec-list l)) ~ id
- is-section-vec-list nil = refl
- is-section-vec-list (cons x l) = ap (cons x) (is-section-vec-list l)
-
- is-retraction-vec-list :
- ( λ (x : Σ ℕ (λ n → vec A n)) →
- ( length-list (list-vec (pr1 x) (pr2 x)) ,
- vec-list (list-vec (pr1 x) (pr2 x)))) ~
- id
- is-retraction-vec-list (zero-ℕ , empty-vec) = refl
- is-retraction-vec-list (succ-ℕ n , (x ∷ v)) =
- ap
- ( λ v → succ-ℕ (pr1 v) , (x ∷ (pr2 v)))
- ( is-retraction-vec-list (n , v))
-
list-array : array A → list A
list-array (n , t) = list-vec n (listed-vec-functional-vec n t)
diff --git a/src/lists/dependent-lists.lagda.md b/src/lists/dependent-lists.lagda.md
new file mode 100644
index 0000000000..c90245f348
--- /dev/null
+++ b/src/lists/dependent-lists.lagda.md
@@ -0,0 +1,44 @@
+# Dependent lists
+
+```agda
+module lists.dependent-lists where
+```
+
+Imports
+
+```agda
+open import foundation.universe-levels
+
+open import lists.lists
+```
+
+
+
+## Idea
+
+Consider a dependent type `B` over a type `A`, and let `l` be a [list](lists.lists.md)` of elements of `A`. A {{#concept "dependent list" Agda=dependent-list}} of elements of `B` over `l` consists of a choice of an element `B x` for every element of `l`. More formally, the type `dependent-list B l` of dependent lists is a data type with constructors
+
+```text
+ nil-dependent-list : dependent-list B nil
+ cons-dependent-list : B x → dependent-list B l → dependent-list B (cons x l)
+```
+
+Note that the type `dependent-list B l` is [equivalent](foundation-core.equivalences.md) to the [universal quantification](lists.universal-quantification-lists.md) over the elements of `l` at `B`.
+
+## Definitions
+
+### Dependent lists
+
+```agda
+module _
+ {l1 l2 : Level} {A : UU l2} (B : A → UU l2)
+ where
+
+ data dependent-list : (l : list A) → UU (l1 ⊔ l2)
+ where
+ nil-dependent-list :
+ dependent-list nil
+ cons-dependent-list :
+ (a : A) (l : list A) → B a → dependent-list l → dependent-list (cons a l)
+```
+
diff --git a/src/lists/elementhood-relation-lists.lagda.md b/src/lists/elementhood-relation-lists.lagda.md
new file mode 100644
index 0000000000..40ed06d8cb
--- /dev/null
+++ b/src/lists/elementhood-relation-lists.lagda.md
@@ -0,0 +1,262 @@
+# The elementhood relation on lists
+
+```agda
+module lists.elementhood-relation-lists where
+```
+
+Imports
+
+```agda
+open import foundation.action-on-identifications-functions
+open import foundation.commuting-squares-of-maps
+open import foundation.commuting-triangles-of-maps
+open import foundation.coproduct-types
+open import foundation.dependent-pair-types
+open import foundation.empty-types
+open import foundation.equality-dependent-pair-types
+open import foundation.equivalences
+open import foundation.function-types
+open import foundation.functoriality-dependent-pair-types
+open import foundation.identity-types
+open import foundation.raising-universe-levels
+open import foundation.retractions
+open import foundation.sections
+open import foundation.unit-type
+open import foundation.universe-levels
+
+open import linear-algebra.vectors
+
+open import lists.lists
+
+open import univalent-combinatorics.counting
+open import univalent-combinatorics.finite-types
+open import univalent-combinatorics.standard-finite-types
+```
+
+
+
+## Idea
+
+Consider a [list](lists.lists.md) `l` of elements of a type `A`. We say that an element `a : A` is an {{#concept "element" Disambiguation="lists" Agda=_∈-list_}} of `l` if there is an element of type `a ∈-list l`, which is the data type with constructors
+
+```text
+ is-head : (a : A) (l : list A) → a ∈-list cons a l
+ is-in-tail : (a x : A) (l : list) → a ∈-list l → a ∈-list cons x l
+```
+
+Equivalently, the elementhood relation can be defined inductively by
+
+```text
+ a ∈-list nil := empty
+ a ∈-list (cons x l) := (a = x) + (a ∈-list l).
+```
+
+The elementhood relation is a special case of the [elementhood relation](trees.elementhood-relation-w-types.md) on [W-types](trees.w-types.md) and the [elementhood relation](trees.elementhood-relation-coalgebras-polynomial-endofunctors.md) of [coalgebras](trees.coalgebras-polynomial-endofunctors.md) of [polynomial endofunctors](trees.polynomial-endofunctors.md).
+
+## Definitions
+
+### The elementhood predicate on lists
+
+```agda
+infix 6 _∈-list_
+
+data _∈-list_ {l1 : Level} {A : UU l1} : A → list A → UU l1 where
+ is-head : (a : A) (l : list A) → a ∈-list cons a l
+ is-in-tail : (a x : A) (l : list A) → a ∈-list l → a ∈-list cons x l
+```
+
+### The recursive definition of the elementhood relation
+
+```agda
+elementhood-list : {l1 : Level} {A : UU l1} → A → list A → UU l1
+elementhood-list a nil = raise-empty _
+elementhood-list a (cons x l) = (a = x) + (elementhood-list a l)
+```
+
+## Properties
+
+### The `nil` list has no elements
+
+```agda
+module _
+ {l1 : Level} {A : UU l1}
+ where
+
+ is-empty-∈-nil-list : (x : A) → is-empty (x ∈-list nil)
+ is-empty-∈-nil-list x ()
+```
+
+### The two definitions of the elementhood relation are equivalent
+
+```agda
+module _
+ {l1 : Level} {A : UU l1}
+ where
+
+ map-compute-elementhood-list :
+ (a : A) (l : list A) → elementhood-list a l → a ∈-list l
+ map-compute-elementhood-list a nil (map-raise ())
+ map-compute-elementhood-list a (cons .a l) (inl refl) =
+ is-head a l
+ map-compute-elementhood-list a (cons x l) (inr H) =
+ is-in-tail a x l (map-compute-elementhood-list a l H)
+
+ map-inv-compute-elementhood-list :
+ (a : A) (l : list A) → a ∈-list l → elementhood-list a l
+ map-inv-compute-elementhood-list a .(cons a l) (is-head .a l) =
+ inl refl
+ map-inv-compute-elementhood-list a .(cons x l) (is-in-tail .a x l H) =
+ inr (map-inv-compute-elementhood-list a l H)
+
+ is-section-map-inv-compute-elementhood-list :
+ (a : A) (l : list A) →
+ is-section
+ ( map-compute-elementhood-list a l)
+ ( map-inv-compute-elementhood-list a l)
+ is-section-map-inv-compute-elementhood-list a .(cons a l) (is-head .a l) =
+ refl
+ is-section-map-inv-compute-elementhood-list a ._ (is-in-tail .a x l H) =
+ ap (is-in-tail a x l) (is-section-map-inv-compute-elementhood-list a l H)
+
+ is-retraction-map-inv-compute-elementhood-list :
+ (a : A) (l : list A) →
+ is-retraction
+ ( map-compute-elementhood-list a l)
+ ( map-inv-compute-elementhood-list a l)
+ is-retraction-map-inv-compute-elementhood-list a nil (map-raise ())
+ is-retraction-map-inv-compute-elementhood-list a (cons .a l) (inl refl) =
+ refl
+ is-retraction-map-inv-compute-elementhood-list a (cons x l) (inr H) =
+ ap inr (is-retraction-map-inv-compute-elementhood-list a l H)
+
+ is-equiv-map-compute-elementhood-list :
+ (a : A) (l : list A) → is-equiv (map-compute-elementhood-list a l)
+ is-equiv-map-compute-elementhood-list a l =
+ is-equiv-is-invertible
+ ( map-inv-compute-elementhood-list a l)
+ ( is-section-map-inv-compute-elementhood-list a l)
+ ( is-retraction-map-inv-compute-elementhood-list a l)
+
+ compute-elementhood-list :
+ (a : A) (l : list A) → elementhood-list a l ≃ (a ∈-list l)
+ pr1 (compute-elementhood-list a l) = map-compute-elementhood-list a l
+ pr2 (compute-elementhood-list a l) = is-equiv-map-compute-elementhood-list a l
+```
+
+### The type of all elements of a list is equivalent to the standard finite type with the length of the list as its number of elements
+
+Furthermore, there is a commuting triangle
+
+```text
+ ≃
+ Fin (length l) ----> element l
+ \ /
+ vec-list l \ / pr1
+ ∨ ∨
+ X,
+```
+
+where the top equivalence is the counting of the type of elements of `l`
+
+```agda
+module _
+ {l1 : Level} {A : UU l1}
+ where
+
+ element-list : list A → UU l1
+ element-list l = Σ A (_∈-list l)
+
+ element-element-list :
+ (l : list A) → element-list l → A
+ element-element-list l = pr1
+
+ cons-element-list :
+ (x : A) (l : list A) →
+ element-list l → element-list (cons x l)
+ cons-element-list x l =
+ tot (λ z → is-in-tail z x l)
+
+ map-compute-element-list :
+ (l : list A) → Fin (length-list l) → element-list l
+ map-compute-element-list (cons x l) (inl i) =
+ cons-element-list x l (map-compute-element-list l i)
+ map-compute-element-list (cons x l) (inr _) =
+ (x , is-head x l)
+
+ coherence-square-cons-element-list :
+ (x : A) (l : list A) →
+ coherence-square-maps
+ ( map-compute-element-list l)
+ ( inl-Fin (length-list l))
+ ( cons-element-list x l)
+ ( map-compute-element-list (cons x l))
+ coherence-square-cons-element-list x l a = refl
+
+ map-inv-compute-element-list :
+ (l : list A) → element-list l → Fin (length-list l)
+ map-inv-compute-element-list (cons x l) (.x , is-head .x .l) =
+ inr star
+ map-inv-compute-element-list (cons x l) (a , is-in-tail .a .x .l H) =
+ inl (map-inv-compute-element-list l (a , H))
+
+ is-section-map-inv-compute-element-list :
+ (l : list A) →
+ is-section
+ ( map-compute-element-list l)
+ ( map-inv-compute-element-list l)
+ is-section-map-inv-compute-element-list
+ ( cons x l)
+ ( .x , is-head .x .l) =
+ refl
+ is-section-map-inv-compute-element-list
+ ( cons x l)
+ ( a , is-in-tail .a .x .l H) =
+ ap
+ ( cons-element-list x l)
+ ( is-section-map-inv-compute-element-list l (a , H))
+
+ is-retraction-map-inv-compute-element-list :
+ (l : list A) →
+ is-retraction
+ ( map-compute-element-list l)
+ ( map-inv-compute-element-list l)
+ is-retraction-map-inv-compute-element-list (cons x l) (inl i) =
+ ap inl (is-retraction-map-inv-compute-element-list l i)
+ is-retraction-map-inv-compute-element-list (cons x l) (inr star) =
+ refl
+
+ is-equiv-map-compute-element-list :
+ (l : list A) → is-equiv (map-compute-element-list l)
+ is-equiv-map-compute-element-list l =
+ is-equiv-is-invertible
+ ( map-inv-compute-element-list l)
+ ( is-section-map-inv-compute-element-list l)
+ ( is-retraction-map-inv-compute-element-list l)
+
+ compute-element-list :
+ (l : list A) → Fin (length-list l) ≃ element-list l
+ pr1 (compute-element-list l) =
+ map-compute-element-list l
+ pr2 (compute-element-list l) =
+ is-equiv-map-compute-element-list l
+
+ count-element-list :
+ (l : list A) → count (element-list l)
+ pr1 (count-element-list l) = length-list l
+ pr2 (count-element-list l) = compute-element-list l
+
+ is-finite-element-list :
+ (l : list A) → is-finite (element-list l)
+ is-finite-element-list l = is-finite-count (count-element-list l)
+
+ triangle-compute-element-list :
+ (l : list A) →
+ coherence-triangle-maps
+ ( functional-vec-list l)
+ ( element-element-list l)
+ ( map-compute-element-list l)
+ triangle-compute-element-list (cons x l) (inl i) =
+ triangle-compute-element-list l i
+ triangle-compute-element-list (cons x l) (inr star) =
+ refl
+```
diff --git a/src/lists/lists.lagda.md b/src/lists/lists.lagda.md
index dfa10f3084..11960a5c33 100644
--- a/src/lists/lists.lagda.md
+++ b/src/lists/lists.lagda.md
@@ -112,16 +112,6 @@ length-list : {l : Level} {A : UU l} → list A → ℕ
length-list = fold-list 0 (λ a → succ-ℕ)
```
-### The elementhood predicate on lists
-
-```agda
-infix 6 _∈-list_
-
-data _∈-list_ {l : Level} {A : UU l} : A → list A → UU l where
- is-head : (a : A) (l : list A) → a ∈-list (cons a l)
- is-in-tail : (a x : A) (l : list A) → a ∈-list l → a ∈-list (cons x l)
-```
-
## Properties
### A list that uses cons is not nil
@@ -405,3 +395,7 @@ is-equiv-map-algebra-list A =
( is-section-map-inv-algebra-list A)
( is-retraction-map-inv-algebra-list A)
```
+
+## See also
+
+- [The elementhood relation on lists](lists.elementhood-relation-lists.md)
diff --git a/src/lists/permutation-lists.lagda.md b/src/lists/permutation-lists.lagda.md
index 26ca630086..5c7812e703 100644
--- a/src/lists/permutation-lists.lagda.md
+++ b/src/lists/permutation-lists.lagda.md
@@ -24,6 +24,7 @@ open import linear-algebra.functoriality-vectors
open import linear-algebra.vectors
open import lists.arrays
+open import lists.elementhood-relation-lists
open import lists.functoriality-lists
open import lists.lists
open import lists.permutation-vectors
@@ -45,7 +46,7 @@ module _
{l : Level} {A : UU l}
where
- permute-list : (l : list A) → Permutation (length-list l) → list A
+ permute-list : (l : list A) → permutation (length-list l) → list A
permute-list l s =
list-vec
( length-list l)
@@ -58,12 +59,12 @@ module _
is-permutation-list : (list A → list A) → UU l
is-permutation-list f =
(l : list A) →
- Σ ( Permutation (length-list l))
+ Σ ( permutation (length-list l))
( λ t → f l = permute-list l t)
permutation-is-permutation-list :
(f : list A → list A) → is-permutation-list f →
- ((l : list A) → Permutation (length-list l))
+ ((l : list A) → permutation (length-list l))
permutation-is-permutation-list f P l = pr1 (P l)
eq-permute-list-permutation-is-permutation-list :
@@ -79,7 +80,7 @@ module _
```agda
length-permute-list :
- (l : list A) (t : Permutation (length-list l)) →
+ (l : list A) (t : permutation (length-list l)) →
length-list (permute-list l t) = (length-list l)
length-permute-list l t =
compute-length-list-list-vec
@@ -91,7 +92,7 @@ module _
```agda
eq-vec-list-permute-list :
- (l : list A) (f : Permutation (length-list l)) →
+ (l : list A) (f : permutation (length-list l)) →
permute-vec (length-list l) (vec-list l) f =
tr
( vec A)
@@ -123,7 +124,7 @@ module _
```agda
is-in-list-is-in-permute-list :
- (l : list A) (t : Permutation (length-list l)) (x : A) →
+ (l : list A) (t : permutation (length-list l)) (x : A) →
x ∈-list (permute-list l t) → x ∈-list l
is-in-list-is-in-permute-list l t x I =
is-in-list-is-in-vec-list
@@ -147,7 +148,7 @@ module _
( I))))
is-in-permute-list-is-in-list :
- (l : list A) (t : Permutation (length-list l)) (x : A) →
+ (l : list A) (t : permutation (length-list l)) (x : A) →
x ∈-list l → x ∈-list (permute-list l t)
is-in-permute-list-is-in-list l t x I =
is-in-list-is-in-vec-list
@@ -181,12 +182,12 @@ module _
fold-vec b μ (tr (vec A) eq v) = fold-vec b μ v
invariant-fold-vec-tr v refl = refl
- invariant-permutation-fold-list :
- (l : list A) → (f : Permutation (length-list l)) →
+ permutation-invariant-fold-list :
+ (l : list A) → (f : permutation (length-list l)) →
fold-list b μ l = fold-list b μ (permute-list l f)
- invariant-permutation-fold-list l f =
+ permutation-invariant-fold-list l f =
( inv (htpy-fold-list-fold-vec b μ l) ∙
- ( invariant-permutation-fold-vec b μ C (vec-list l) f ∙
+ ( permutation-invariant-fold-vec b μ C (vec-list l) f ∙
( ap (fold-vec b μ) (eq-vec-list-permute-list l f) ∙
( ( invariant-fold-vec-tr
{ m = length-list l}
@@ -200,14 +201,14 @@ module _
```agda
compute-tr-permute-vec :
{l : Level} {A : UU l} {n m : ℕ}
- (e : n = m) (v : vec A n) (t : Permutation m) →
+ (e : n = m) (v : vec A n) (t : permutation m) →
tr
( vec A)
( e)
( permute-vec
( n)
( v)
- ( tr Permutation (inv e) t)) =
+ ( tr permutation (inv e) t)) =
permute-vec
( m)
( tr (vec A) e v)
@@ -222,7 +223,7 @@ compute-tr-map-vec f refl v = refl
helper-compute-list-vec-map-vec-permute-vec-vec-list :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
- (f : A → B) (p : list A) (t : Permutation (length-list p)) →
+ (f : A → B) (p : list A) (t : permutation (length-list p)) →
tr
( vec B)
( inv (length-permute-list p t))
@@ -250,7 +251,7 @@ helper-compute-list-vec-map-vec-permute-vec-vec-list f p t =
compute-list-vec-map-vec-permute-vec-vec-list :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
- (f : A → B) (p : list A) (t : Permutation (length-list p)) →
+ (f : A → B) (p : list A) (t : permutation (length-list p)) →
list-vec
( length-list p)
( map-vec f (permute-vec (length-list p) (vec-list p) t)) =
@@ -266,8 +267,8 @@ compute-list-vec-map-vec-permute-vec-vec-list f p t =
eq-map-list-permute-list :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
- (f : A → B) (p : list A) (t : Permutation (length-list p)) →
- permute-list (map-list f p) (tr Permutation (inv (length-map-list f p)) t) =
+ (f : A → B) (p : list A) (t : permutation (length-list p)) →
+ permute-list (map-list f p) (tr permutation (inv (length-map-list f p)) t) =
map-list f (permute-list p t)
eq-map-list-permute-list {B = B} f p t =
( ( ap
@@ -282,7 +283,7 @@ eq-map-list-permute-list {B = B} f p t =
( permute-vec
( length-list (map-list f p))
( x)
- ( tr Permutation (inv (length-map-list f p)) t)))
+ ( tr permutation (inv (length-map-list f p)) t)))
( vec-list-map-list-map-vec-list' f p)) ∙
( ( compute-tr-permute-vec
( length-map-list f p)
diff --git a/src/lists/permutation-vectors.lagda.md b/src/lists/permutation-vectors.lagda.md
index 4099f1bfe0..f77bcc3a13 100644
--- a/src/lists/permutation-vectors.lagda.md
+++ b/src/lists/permutation-vectors.lagda.md
@@ -50,7 +50,7 @@ module _
{l : Level} {A : UU l}
where
- permute-vec : (n : ℕ) → vec A n → Permutation n → vec A n
+ permute-vec : (n : ℕ) → vec A n → permutation n → vec A n
permute-vec n v s =
listed-vec-functional-vec n (functional-vec-vec n v ∘ (map-equiv s))
```
@@ -61,12 +61,12 @@ module _
is-permutation-vec : (n : ℕ) → (vec A n → vec A n) → UU l
is-permutation-vec n f =
(v : vec A n) →
- Σ ( Permutation n)
+ Σ ( permutation n)
( λ t → f v = permute-vec n v t)
permutation-is-permutation-vec :
(n : ℕ) (f : vec A n → vec A n) → is-permutation-vec n f →
- (v : vec A n) → Permutation n
+ (v : vec A n) → permutation n
permutation-is-permutation-vec n f P v = pr1 (P v)
eq-permute-vec-permutation-is-permutation-vec :
@@ -91,7 +91,7 @@ module _
compute-composition-permute-vec :
(n : ℕ)
(v : vec A n) →
- (a b : Permutation n) →
+ (a b : permutation n) →
permute-vec n v (a ∘e b) = permute-vec n (permute-vec n v a) b
compute-composition-permute-vec n v a b =
ap
@@ -129,7 +129,7 @@ module _
(n : ℕ)
(v : vec A n)
(x : A)
- (t : Permutation n) →
+ (t : permutation n) →
permute-vec (succ-ℕ n) (x ∷ v) (equiv-coproduct t id-equiv) =
(x ∷ permute-vec n v t)
compute-equiv-coproduct-permutation-id-equiv-permute-vec n v x t =
@@ -146,7 +146,7 @@ module _
ap-permute-vec :
{n : ℕ}
- (a : Permutation n)
+ (a : permutation n)
{v w : vec A n} →
v = w →
permute-vec n v a = permute-vec n w a
@@ -157,13 +157,13 @@ module _
```agda
is-in-functional-vec-is-in-permute-functional-vec :
- (n : ℕ) (v : Fin n → A) (t : Permutation n) (x : A) →
+ (n : ℕ) (v : Fin n → A) (t : permutation n) (x : A) →
in-functional-vec n x (v ∘ map-equiv t) → in-functional-vec n x v
is-in-functional-vec-is-in-permute-functional-vec n v t x (k , refl) =
map-equiv t k , refl
is-in-vec-is-in-permute-vec :
- (n : ℕ) (v : vec A n) (t : Permutation n) (x : A) →
+ (n : ℕ) (v : vec A n) (t : permutation n) (x : A) →
x ∈-vec (permute-vec n v t) → x ∈-vec v
is-in-vec-is-in-permute-vec n v t x I =
is-in-vec-is-in-functional-vec
@@ -182,13 +182,13 @@ module _
( is-in-functional-vec-is-in-vec n (permute-vec n v t) x I)))
is-in-permute-functional-vec-is-in-functional-vec :
- (n : ℕ) (v : Fin n → A) (t : Permutation n) (x : A) →
+ (n : ℕ) (v : Fin n → A) (t : permutation n) (x : A) →
in-functional-vec n x v → in-functional-vec n x (v ∘ map-equiv t)
is-in-permute-functional-vec-is-in-functional-vec n v t x (k , refl) =
map-inv-equiv t k , ap v (inv (is-section-map-inv-equiv t k))
is-in-permute-vec-is-in-vec :
- (n : ℕ) (v : vec A n) (t : Permutation n) (x : A) →
+ (n : ℕ) (v : vec A n) (t : permutation n) (x : A) →
x ∈-vec v → x ∈-vec (permute-vec n v t)
is-in-permute-vec-is-in-vec n v t x I =
is-in-vec-is-in-functional-vec
@@ -346,10 +346,10 @@ module _
( transposition-Fin (succ-ℕ n) i j neq)
( permutation-list-standard-transpositions-Fin (succ-ℕ n) l))))))
- invariant-permutation-fold-vec :
- {n : ℕ} → (v : vec A n) → (f : Permutation n) →
+ permutation-invariant-fold-vec :
+ {n : ℕ} → (v : vec A n) → (f : permutation n) →
fold-vec b μ v = fold-vec b μ (permute-vec n v f)
- invariant-permutation-fold-vec {n} v f =
+ permutation-invariant-fold-vec {n} v f =
( ( invariant-list-transpositions-fold-vec
( v)
( list-standard-transpositions-permutation-Fin n f)) ∙
@@ -369,7 +369,7 @@ module _
```agda
eq-map-vec-permute-vec :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
- (f : A → B) {n : ℕ} (v : vec A n) (t : Permutation n) →
+ (f : A → B) {n : ℕ} (v : vec A n) (t : permutation n) →
permute-vec n (map-vec f v) t =
map-vec f (permute-vec n v t)
eq-map-vec-permute-vec f {n} v t =
diff --git a/src/lists/predicates-on-lists.lagda.md b/src/lists/predicates-on-lists.lagda.md
deleted file mode 100644
index 4d52edb669..0000000000
--- a/src/lists/predicates-on-lists.lagda.md
+++ /dev/null
@@ -1,40 +0,0 @@
-# Predicates on lists
-
-```agda
-module lists.predicates-on-lists where
-```
-
-Imports
-
-```agda
-open import foundation.propositions
-open import foundation.unit-type
-open import foundation.universe-levels
-
-open import lists.lists
-```
-
-
-
-## Definitions
-
-### For all
-
-```agda
-module _
- {l1 l2 : Level} (X : UU l1) (P : X → Prop l2)
- where
-
- for-all-list-Prop :
- (l : list X) → Prop l2
- for-all-list-Prop nil = raise-unit-Prop l2
- for-all-list-Prop (cons x l) = product-Prop (P x) (for-all-list-Prop l)
-
- for-all-list :
- (l : list X) → UU l2
- for-all-list l = type-Prop (for-all-list-Prop l)
-
- is-prop-for-all-list :
- (l : list X) → is-prop (for-all-list l)
- is-prop-for-all-list l = is-prop-type-Prop (for-all-list-Prop l)
-```
diff --git a/src/lists/sort-by-insertion-lists.lagda.md b/src/lists/sort-by-insertion-lists.lagda.md
index c14433df58..ffc3c2d59a 100644
--- a/src/lists/sort-by-insertion-lists.lagda.md
+++ b/src/lists/sort-by-insertion-lists.lagda.md
@@ -13,6 +13,9 @@ open import foundation.dependent-pair-types
open import foundation.identity-types
open import foundation.universe-levels
+open import linear-algebra.vectors
+
+
open import lists.arrays
open import lists.lists
open import lists.permutation-lists
@@ -62,7 +65,7 @@ module _
permutation-insertion-sort-list :
(l : list (type-Decidable-Total-Order X)) →
- Permutation (length-list l)
+ permutation (length-list l)
permutation-insertion-sort-list =
permutation-list-is-sort-list
X
diff --git a/src/lists/sort-by-insertion-vectors.lagda.md b/src/lists/sort-by-insertion-vectors.lagda.md
index 56d1870c3a..04bc0e900d 100644
--- a/src/lists/sort-by-insertion-vectors.lagda.md
+++ b/src/lists/sort-by-insertion-vectors.lagda.md
@@ -89,7 +89,7 @@ module _
(x y : type-Decidable-Total-Order X)
(l : vec (type-Decidable-Total-Order X) n) →
leq-or-strict-greater-Decidable-Poset X x y →
- Permutation (succ-ℕ (succ-ℕ (n)))
+ permutation (succ-ℕ (succ-ℕ (n)))
helper-permutation-insertion-sort-vec x y l (inl _) = id-equiv
helper-permutation-insertion-sort-vec {0} x y empty-vec (inr _) =
swap-two-last-elements-transposition-Fin 0
@@ -106,7 +106,7 @@ module _
permutation-insertion-sort-vec :
{n : ℕ}
(v : vec (type-Decidable-Total-Order X) n) →
- Permutation n
+ permutation n
permutation-insertion-sort-vec {zero-ℕ} empty-vec = id-equiv
permutation-insertion-sort-vec {1} l = id-equiv
permutation-insertion-sort-vec {succ-ℕ (succ-ℕ n)} (x ∷ y ∷ l) =
diff --git a/src/lists/sorted-lists.lagda.md b/src/lists/sorted-lists.lagda.md
index dbd5f1f37e..ccdb8a6727 100644
--- a/src/lists/sorted-lists.lagda.md
+++ b/src/lists/sorted-lists.lagda.md
@@ -17,6 +17,7 @@ open import foundation.universe-levels
open import linear-algebra.vectors
open import lists.arrays
+open import lists.elementhood-relation-lists
open import lists.lists
open import lists.sorted-vectors
@@ -58,6 +59,10 @@ module _
### The proposition that an element is less or equal than every element in a list
```agda
+module _
+ {l1 l2 : Level} (X : Decidable-Total-Order l1 l2)
+ where
+
is-least-element-list-Prop :
type-Decidable-Total-Order X →
list (type-Decidable-Total-Order X) → Prop l2
@@ -78,9 +83,13 @@ module _
### If a list is sorted, then its tail is also sorted
```agda
+module _
+ {l1 l2 : Level} (X : Decidable-Total-Order l1 l2)
+ where
+
is-sorted-tail-is-sorted-list :
(l : list (type-Decidable-Total-Order X)) →
- is-sorted-list l → is-sorted-list (tail-list l)
+ is-sorted-list X l → is-sorted-list X (tail-list l)
is-sorted-tail-is-sorted-list nil _ = raise-star
is-sorted-tail-is-sorted-list (cons x nil) s = raise-star
is-sorted-tail-is-sorted-list (cons x (cons y l)) s = pr2 s
@@ -89,10 +98,14 @@ module _
### If a list is sorted then its head is less or equal than every element in the list
```agda
+module _
+ {l1 l2 : Level} (X : Decidable-Total-Order l1 l2)
+ where
+
leq-element-in-list-leq-head-is-sorted-list :
(x y z : type-Decidable-Total-Order X)
(l : list (type-Decidable-Total-Order X)) →
- is-sorted-list (cons y l) →
+ is-sorted-list X (cons y l) →
z ∈-list (cons y l) →
leq-Decidable-Total-Order X x y →
leq-Decidable-Total-Order X x z
@@ -119,12 +132,16 @@ module _
### An equivalent definition of being sorted
```agda
+module _
+ {l1 l2 : Level} (X : Decidable-Total-Order l1 l2)
+ where
+
is-sorted-least-element-list-Prop :
list (type-Decidable-Total-Order X) → Prop l2
is-sorted-least-element-list-Prop nil = raise-unit-Prop l2
is-sorted-least-element-list-Prop (cons x l) =
product-Prop
- ( is-least-element-list-Prop x l)
+ ( is-least-element-list-Prop X x l)
( is-sorted-least-element-list-Prop l)
is-sorted-least-element-list :
@@ -134,7 +151,7 @@ module _
is-sorted-list-is-sorted-least-element-list :
(l : list (type-Decidable-Total-Order X)) →
- is-sorted-least-element-list l → is-sorted-list l
+ is-sorted-least-element-list l → is-sorted-list X l
is-sorted-list-is-sorted-least-element-list nil _ =
raise-star
is-sorted-list-is-sorted-least-element-list (cons x nil) _ =
@@ -149,10 +166,14 @@ module _
### If a vector `v` of length `n` is sorted, then the list `list-vec n v` is also sorted
```agda
+module _
+ {l1 l2 : Level} (X : Decidable-Total-Order l1 l2)
+ where
+
is-sorted-list-is-sorted-vec :
(n : ℕ) (v : vec (type-Decidable-Total-Order X) n) →
is-sorted-vec X v →
- is-sorted-list (list-vec n v)
+ is-sorted-list X (list-vec n v)
is-sorted-list-is-sorted-vec 0 v S = raise-star
is-sorted-list-is-sorted-vec 1 (x ∷ v) S = raise-star
is-sorted-list-is-sorted-vec (succ-ℕ (succ-ℕ n)) (x ∷ y ∷ v) S =
diff --git a/src/lists/sorted-vectors.lagda.md b/src/lists/sorted-vectors.lagda.md
index dbb2353d4f..3e9a7117a4 100644
--- a/src/lists/sorted-vectors.lagda.md
+++ b/src/lists/sorted-vectors.lagda.md
@@ -201,7 +201,7 @@ module _
(n : ℕ)
(x : type-Decidable-Total-Order X)
(fv : functional-vec (type-Decidable-Total-Order X) n)
- (a : Permutation n) →
+ (a : permutation n) →
is-least-element-functional-vec n x fv →
is-least-element-functional-vec n x (fv ∘ map-equiv a)
is-least-element-permute-functional-vec n x fv a p k =
@@ -247,7 +247,7 @@ module _
{n : ℕ}
(x : type-Decidable-Total-Order X)
(v : vec (type-Decidable-Total-Order X) n)
- (a : Permutation n) →
+ (a : permutation n) →
is-least-element-vec x v →
is-least-element-vec x (permute-vec n v a)
is-least-element-permute-vec {n} x v a p =
diff --git a/src/lists/sorting-algorithms-lists.lagda.md b/src/lists/sorting-algorithms-lists.lagda.md
index 14b5f6541e..2b99d85fcd 100644
--- a/src/lists/sorting-algorithms-lists.lagda.md
+++ b/src/lists/sorting-algorithms-lists.lagda.md
@@ -58,7 +58,7 @@ module _
permutation-list-is-sort-list :
is-sort-list → (l : list (type-Decidable-Total-Order X)) →
- Permutation (length-list l)
+ permutation (length-list l)
permutation-list-is-sort-list S l =
permutation-is-permutation-list f (is-permutation-list-is-sort-list S) l
diff --git a/src/lists/sorting-algorithms-vectors.lagda.md b/src/lists/sorting-algorithms-vectors.lagda.md
index 029591d5fb..a6c9cc1a18 100644
--- a/src/lists/sorting-algorithms-vectors.lagda.md
+++ b/src/lists/sorting-algorithms-vectors.lagda.md
@@ -55,7 +55,7 @@ module _
is-permutation-vec-is-sort-vec S n = pr1 (S n)
permutation-vec-is-sort-vec :
- is-sort-vec → (n : ℕ) → vec (type-Decidable-Total-Order X) n → Permutation n
+ is-sort-vec → (n : ℕ) → vec (type-Decidable-Total-Order X) n → permutation n
permutation-vec-is-sort-vec S n v =
permutation-is-permutation-vec n f (is-permutation-vec-is-sort-vec S n) v
diff --git a/src/lists/universal-quantification-lists.lagda.md b/src/lists/universal-quantification-lists.lagda.md
new file mode 100644
index 0000000000..a57bf8e722
--- /dev/null
+++ b/src/lists/universal-quantification-lists.lagda.md
@@ -0,0 +1,273 @@
+# Universal quantification over the elements of lists
+
+```agda
+module lists.universal-quantification-lists where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.contractible-types
+open import foundation.dependent-pair-types
+open import foundation.empty-types
+open import foundation.equality-cartesian-product-types
+open import foundation.equivalences
+open import foundation.function-extensionality
+open import foundation.function-types
+open import foundation.functoriality-cartesian-product-types
+open import foundation.identity-types
+open import foundation.propositions
+open import foundation.retractions
+open import foundation.sections
+open import foundation.unit-type
+open import foundation.universe-levels
+
+open import lists.concatenation-lists
+open import lists.elementhood-relation-lists
+open import lists.lists
+open import lists.permutation-lists
+
+open import finite-group-theory.permutations-standard-finite-types
+```
+
+
+
+## Idea
+
+Consider a predicate `P` on a type `X`, and consider a [list](lists.lists.md)
+`l` of elements of `X`. The
+{{#concept "universal quantification" Disambiguation="elements of a list" Agda=for-all-list}}
+of `P` over the elements of `l` is the type of choices of elements `P x` for
+each element `x ∈ l`. More specifically, the universal quantification `∀ l P` of
+`P` over `l` is defined inductively by
+
+```text
+ ∀ nil P := unit
+ ∀ (cons x l) P := (P x) × (∀ l P)
+```
+
+Alternatively, the universal quantification over the elements of a list can be
+defined directly by
+
+```text
+ ∀ l P := (x : X) → x ∈ l → P x.
+```
+
+These definitions are [equivalent](foundation-core.equivalences.md). However,
+note that the inductive definition of the universal quantification has the same
+universe level as `P`, while the direct definition is of universe level
+`l1 ⊔ l2`, where `l1` is the universe level of `X` and `l2` is the universe
+level of `P`.
+
+Note that the universal quantification over the elements of a list `l` is
+equivalent to the type of [dependent lists](lists.dependent-lists.md) of
+elements of `P` over `l`.
+
+## Definitions
+
+### Universal quantification over the elements of a list
+
+```agda
+module _
+ {l1 l2 : Level} {X : UU l1}
+ where
+
+ for-all-list :
+ (l : list X) (P : X → UU l2) → UU l2
+ for-all-list nil P = raise-unit l2
+ for-all-list (cons x l) P = P x × for-all-list l P
+
+ for-all-nil-list :
+ (P : X → UU l2) → for-all-list nil P
+ for-all-nil-list P = raise-star
+
+ head-for-all-cons-list :
+ (x : X) (l : list X) (P : X → UU l2) → for-all-list (cons x l) P → P x
+ head-for-all-cons-list x l P H = pr1 H
+
+ tail-for-all-cons-list :
+ (x : X) (l : list X) (P : X → UU l2) →
+ for-all-list (cons x l) P → for-all-list l P
+ tail-for-all-cons-list x l P H = pr2 H
+```
+
+### Universal quantification by a predicate valued in propositions
+
+```agda
+module _
+ {l1 l2 : Level} {X : UU l1}
+ where
+
+ is-prop-for-all-list :
+ (l : list X) (P : X → Prop l2) → is-prop (for-all-list l (type-Prop ∘ P))
+ is-prop-for-all-list nil P =
+ is-prop-raise-unit
+ is-prop-for-all-list (cons x l) P =
+ is-prop-product (is-prop-type-Prop (P x)) (is-prop-for-all-list l P)
+
+ for-all-list-Prop :
+ (l : list X) (P : X → Prop l2) → Prop l2
+ pr1 (for-all-list-Prop l P) = for-all-list l (type-Prop ∘ P)
+ pr2 (for-all-list-Prop l P) = is-prop-for-all-list l P
+```
+
+### Universal quantification over the elements of a list
+
+```agda
+module _
+ {l1 l2 : Level} {X : UU l1} (l : list X) (P : X → UU l2)
+ where
+
+ for-all-elements-list : UU (l1 ⊔ l2)
+ for-all-elements-list = (x : X) → x ∈-list l → P x
+
+for-all-elements-nil-list :
+ {l1 l2 : Level} {X : UU l1} (P : X → UU l2) → for-all-elements-list nil P
+for-all-elements-nil-list P x ()
+
+for-all-elements-cons-list :
+ {l1 l2 : Level} {X : UU l1} (x : X) (l : list X) (P : X → UU l2) →
+ P x → for-all-elements-list l P → for-all-elements-list (cons x l) P
+for-all-elements-cons-list x l P a b .x (is-head .x .l) = a
+for-all-elements-cons-list x l P a b y (is-in-tail .y .x .l H) = b y H
+
+head-for-all-elements-cons-list :
+ {l1 l2 : Level} {X : UU l1} (x : X) (l : list X) (P : X → UU l2) →
+ for-all-elements-list (cons x l) P → P x
+head-for-all-elements-cons-list x l P H = H x (is-head x l)
+
+tail-for-all-elements-cons-list :
+ {l1 l2 : Level} {X : UU l1} (x : X) (l : list X) (P : X → UU l2) →
+ for-all-elements-list (cons x l) P → for-all-elements-list l P
+tail-for-all-elements-cons-list x l P H y K = H y (is-in-tail y x l K)
+```
+
+## Properties
+
+### The two definitions of universal quantification over the elements of a list are equivalent
+
+```agda
+module _
+ {l1 l2 : Level} {X : UU l1}
+ where
+
+ is-contr-for-all-elements-nil-list :
+ (P : X → UU l2) → is-contr (for-all-elements-list nil P)
+ pr1 (is-contr-for-all-elements-nil-list P) =
+ for-all-elements-nil-list P
+ pr2 (is-contr-for-all-elements-nil-list P) H =
+ eq-htpy (λ x → eq-htpy (λ K → ex-falso (is-empty-∈-nil-list x K)))
+
+ compute-for-all-elements-nil-list :
+ (P : X → UU l2) → for-all-elements-list nil P ≃ raise-unit l2
+ compute-for-all-elements-nil-list P =
+ equiv-is-contr
+ ( is-contr-for-all-elements-nil-list P)
+ ( is-contr-raise-unit)
+
+ module _
+ (x : X) (l : list X) (P : X → UU l2)
+ where
+
+ map-compute-for-all-elements-cons-list :
+ P x × for-all-elements-list l P → for-all-elements-list (cons x l) P
+ map-compute-for-all-elements-cons-list (a , b) =
+ for-all-elements-cons-list x l P a b
+
+ map-inv-compute-for-all-elements-cons-list :
+ for-all-elements-list (cons x l) P → P x × for-all-elements-list l P
+ pr1 (map-inv-compute-for-all-elements-cons-list H) =
+ head-for-all-elements-cons-list x l P H
+ pr2 (map-inv-compute-for-all-elements-cons-list H) =
+ tail-for-all-elements-cons-list x l P H
+
+ is-section-map-inv-compute-for-all-elements-cons-list' :
+ (H : for-all-elements-list (cons x l) P) →
+ (y : X) (K : y ∈-list cons x l) →
+ map-compute-for-all-elements-cons-list
+ ( map-inv-compute-for-all-elements-cons-list H)
+ ( y)
+ ( K) =
+ H y K
+ is-section-map-inv-compute-for-all-elements-cons-list' H y (is-head .y .l) =
+ refl
+ is-section-map-inv-compute-for-all-elements-cons-list' H y
+ ( is-in-tail .y .x .l K) =
+ refl
+
+ is-section-map-inv-compute-for-all-elements-cons-list :
+ is-section
+ map-compute-for-all-elements-cons-list
+ map-inv-compute-for-all-elements-cons-list
+ is-section-map-inv-compute-for-all-elements-cons-list H =
+ eq-htpy
+ ( λ y →
+ eq-htpy
+ ( is-section-map-inv-compute-for-all-elements-cons-list' H y))
+
+ is-retraction-map-inv-compute-for-all-elements-cons-list :
+ is-retraction
+ map-compute-for-all-elements-cons-list
+ map-inv-compute-for-all-elements-cons-list
+ is-retraction-map-inv-compute-for-all-elements-cons-list H =
+ refl
+
+ is-equiv-map-compute-for-all-elements-cons-list :
+ is-equiv map-compute-for-all-elements-cons-list
+ is-equiv-map-compute-for-all-elements-cons-list =
+ is-equiv-is-invertible
+ map-inv-compute-for-all-elements-cons-list
+ is-section-map-inv-compute-for-all-elements-cons-list
+ is-retraction-map-inv-compute-for-all-elements-cons-list
+
+ compute-for-all-elements-cons-list :
+ P x × for-all-elements-list l P ≃ for-all-elements-list (cons x l) P
+ pr1 compute-for-all-elements-cons-list =
+ map-compute-for-all-elements-cons-list
+ pr2 compute-for-all-elements-cons-list =
+ is-equiv-map-compute-for-all-elements-cons-list
+
+ compute-for-all-list :
+ (l : list X) (P : X → UU l2) →
+ for-all-elements-list l P ≃ for-all-list l P
+ compute-for-all-list nil P = compute-for-all-elements-nil-list P
+ compute-for-all-list (cons x l) P =
+ ( equiv-product id-equiv (compute-for-all-list l P)) ∘e
+ ( inv-equiv (compute-for-all-elements-cons-list x l P))
+```
+
+### If a predicate implies another predicate, then its universal quantification over the elements of a list implies the universal-quantification of the other predicate
+
+```agda
+map-for-all-list :
+ {l1 l2 l3 : Level} {X : UU l1} {P : X → UU l2} {Q : X → UU l3} →
+ (l : list X) → ((x : X) → P x → Q x) →
+ for-all-list l P → for-all-list l Q
+map-for-all-list nil f H = raise-star
+pr1 (map-for-all-list (cons x l) f (H , K)) = f _ H
+pr2 (map-for-all-list (cons x l) f (H , K)) = map-for-all-list l f K
+```
+
+### If two lists satisfy a universally quantified predicate, then so does their concatenation
+
+```agda
+for-all-concat-list :
+ {l1 l2 : Level} {X : UU l1} (l k : list X) (P : X → UU l2) →
+ for-all-list l P → for-all-list k P → for-all-list (concat-list l k) P
+for-all-concat-list nil k P H K = K
+pr1 (for-all-concat-list (cons x l) k P H K) =
+ head-for-all-cons-list x l P H
+pr2 (for-all-concat-list (cons x l) k P H K) =
+ for-all-concat-list l k P (tail-for-all-cons-list x l P H) K
+```
+
+### If a lists satisfies a universally quantified predicate, then so does any permutation of the list
+
+```text
+for-all-permute-list :
+ {l1 l2 : Level} {X : UU l1} (l : list X) (P : X → UU l2)
+ (e : permutation (length-list l)) →
+ for-all-list l P → for-all-list (permute-list l e) P
+for-all-permute-list l P e H = {!!}
+```
diff --git a/src/literature.lagda.md b/src/literature.lagda.md
index 97fa876ae4..ff3cb013a5 100644
--- a/src/literature.lagda.md
+++ b/src/literature.lagda.md
@@ -1,8 +1,10 @@
-# Formalization of results from the literature
+# Formalization of results from the
-> This page is currently under construction. To see what's happening behind the
-> scenes, see the associated GitHub issue
-> [#1055](https://github.com/UniMath/agda-unimath/issues/1055).
+On this page we highlight some publications that have been formalized in
+agda-unimath. We are still working on giving a more complete overview of the
+papers we have formalized. To what's happening behind the scenes, see the
+associated GitHub issue
+[#1055](https://github.com/UniMath/agda-unimath/issues/1055).
## Modules in the literature namespace
diff --git a/src/literature/andrews-number-theory.lagda.md b/src/literature/andrews-number-theory.lagda.md
new file mode 100644
index 0000000000..486e3ae4eb
--- /dev/null
+++ b/src/literature/andrews-number-theory.lagda.md
@@ -0,0 +1,90 @@
+# Andrews, G. E., Number Theory
+
+This file collects references to formalization of constructions and theorems
+from {{#cite Andrews94}}.
+
+```agda
+module literature.andrews-number-theory where
+```
+
+## Part 1 Multiplicativity–Divisibility
+
+### Chapter 1 Basis Representation
+
+#### Section 1–1 Basis Representation
+
+Theorem 1–1 establishes the identity for [triangular numbers](elementary-number-theory.triangular-numbers.md)
+
+```agda
+open import elementary-number-theory.triangular-numbers using
+ ( compute-triangular-number-ℕ)
+```
+
+Theorem 1–2 is the formula for the geometric series stated for real numbers. This would be best formalized as an identity of polynomials. However, we don't have polynomials yet.
+
+Corollary 1–1 states that the [exponential function](elementary-number-theory.exponentiation-natural-numbers.md) is [strictly inflationary](elementary-number-theory.strictly-inflationary-functions-natural-numbers.md).
+
+```agda
+open import elementary-number-theory.exponentiation-natural-numbers using
+ ( is-strictly-inflationary-exp-ℕ)
+```
+
+Exercise 1–1 asks to compute the $n$th [square pyramidal number](elementary-number-theory.square-pyramidal-numbers.md)
+
+```agda
+open import elementary-number-theory.square-pyramidal-numbers using
+ ( compute-square-pyramidal-number-ℕ)
+```
+
+Exercise 1–2 asks to prove [Nicomachus's theorem](elementary-number-theory.nicomachuss-theorem.md)
+
+```agda
+open import elementary-number-theory.nicomachuss-theorem using
+ ( nicomachuss-theorem-ℕ)
+```
+
+Exercise 1–3 is a polynomial identity, which we have to skip for now.
+
+Exercise 1–4 computes the sum of the first $n$ [pronic numbers](elementary-number-theory.pronic-numbers.md)
+
+```agda
+open import elementary-number-theory.pronic-numbers using
+ ( compute-sum-of-pronic-numbers-ℕ)
+```
+
+Exercise 1–5 computes the sum of the first $n$ [odd numbers](elementary-number-theory.parity-natural-numbers.md)
+
+```agda
+open import elementary-number-theory.squares-natural-numbers using
+ ( compute-sum-of-odd-numbers-ℕ)
+```
+
+Exercise 1–6 asks to compute the sum of the first $n$ multiplicative inverses of the pronic numbers. The infrastructure exists in the library, but we haven't done so yet.
+
+Exercise 1–7 computes the sum of the first $n$ Fibonacci numbers
+
+```agda
+open import elementary-number-theory.fibonacci-sequence using
+ ( compute-sum-of-fibonacci-ℕ)
+```
+
+Exercise 1–8 computes the sum of the first $n$ oddly indexed Fibonacci numbers
+
+```agda
+open import elementary-number-theory.fibonacci-sequence using
+ ( compute-strictly-bounded-sum-fibonacci-odd-number-ℕ)
+```
+
+Exercise 1–9 computes the sum of the first $n$ evenly indexed Fibonacci numbers
+
+```agda
+open import elementary-number-theory.fibonacci-sequence using
+ ( compute-bounded-sum-fibonacci-even-ℕ)
+```
+
+Exercise 1–10 asks to prove
+[Cassini's identity](https://en.wikipedia.org/wiki/Cassini_and_Catalan_identities), named after the Italian mathematican and astronomer Giovanni Domenico Cassini, who proved the result in 1680. Note that this identity has two further generalizations, one due to Eugène Catalan and one due to Steven Vajda.
+
+```agda
+
+```
diff --git a/src/literature/introduction-to-homotopy-type-theory.lagda.md b/src/literature/introduction-to-homotopy-type-theory.lagda.md
index 73694d20ac..6b08b723a7 100644
--- a/src/literature/introduction-to-homotopy-type-theory.lagda.md
+++ b/src/literature/introduction-to-homotopy-type-theory.lagda.md
@@ -1290,10 +1290,10 @@ open import elementary-number-theory.modular-arithmetic-standard-finite-types us
**Proposition 7.5.4.** A 3-for-2 property of congruences.
```agda
-open import elementary-number-theory.modular-arithmetic-standard-finite-types using
+open import elementary-number-theory.congruence-natural-numbers using
( congruence-add-ℕ -- x ≡ x' → y ≡ y' → (x + y ≡ x' + y')
- ; cong-right-summand-ℕ -- x ≡ x' → (x + y ≡ x' + y') → y ≡ y'
- ; cong-left-summand-ℕ -- y ≡ y' → (x + y ≡ x' + y') → x ≡ x'
+ ; congruence-right-summand-ℕ -- x ≡ x' → (x + y ≡ x' + y') → y ≡ y'
+ ; congruence-left-summand-ℕ -- y ≡ y' → (x + y ≡ x' + y') → x ≡ x'
)
```
diff --git a/src/literature/oeis.lagda.md b/src/literature/oeis.lagda.md
index 9ecf4af942..d86451b823 100644
--- a/src/literature/oeis.lagda.md
+++ b/src/literature/oeis.lagda.md
@@ -20,28 +20,43 @@ open import foundation.function-types
## Sequences
-### [A000001](https://oeis.org/A000001) The number of groups of order `n`
+### A000001 – The number of groups of order `n`
```agda
open import finite-group-theory.finite-groups using
( number-of-groups-of-order)
```
-### [A000002](https://oeis.org/A000002) The Kolakoski sequence
+OEIS: [A000001](https://oeis.org/A000001)
+
+### A000002 – The Kolakoski sequence
```agda
open import elementary-number-theory.kolakoski-sequence using
( kolakoski)
```
-### [A000004](https://oeis.org/A000004) The zero sequence
+OEIS: [A000002](https://oeis.org/A000002)
+
+### A000004 – The zero sequence
```agda
A000004 : ℕ → ℕ
A000004 _ = zero-ℕ
```
-### [A000007](https://oeis.org/A000007) The characteristic function for 0
+OEIS: [A000004](https://oeis.org/A000004)
+
+### A000005 – The number of divisors
+
+```agda
+open import elementary-number-theory.number-of-divisors using
+ ( number-of-divisors-ℕ)
+```
+
+OEIS: [A000005](https://oeis.org/A000005)
+
+### A000007 – The characteristic function for 0
```agda
A000007 : ℕ → ℕ
@@ -49,160 +64,287 @@ A000007 zero-ℕ = 1
A000007 (succ-ℕ _) = 0
```
-### [A000010](https://oeis.org/A000010) Euler's totient function
+OEIS: [A000007](https://oeis.org/A000007)
+
+### A000010 – Euler's totient function
```agda
open import elementary-number-theory.eulers-totient-function using
( eulers-totient-function-relatively-prime)
```
-### [A000012](https://oeis.org/A000012) All 1's sequence
+OEIS: [A000010](https://oeis.org/A000010)
+
+### A000012 – All 1's sequence
```agda
A000012 : ℕ → ℕ
A000012 _ = 1
```
-### [A000027](https://oeis.org/A000027) The positive integers
+OEIS: [A000012](https://oeis.org/A000012)
+
+### A000027 – The positive integers
```agda
A000027 : ℕ → ℕ
A000027 = succ-ℕ
```
-### [A000040](https://oeis.org/A000040) The prime numbers
+OEIS: [A000027](https://oeis.org/A000027)
+
+### A000040 – The prime numbers
```agda
open import elementary-number-theory.infinitude-of-primes using
( prime-ℕ)
```
-### [A000045](https://oeis.org/A000045) The Fibonacci sequence
+OEIS: [A000040](https://oeis.org/A000040)
+
+### A000043 – The Mersenne exponents
+
+```agda
+open import elementary-number-theory.mersenne-exponents using
+ ( is-mersenne-exponent-ℕ)
+```
+
+OEIS: [A000043](https://oeis.org/A000043)
+
+### A000045 – The Fibonacci sequence
```agda
open import elementary-number-theory.fibonacci-sequence using
- ( Fibonacci-ℕ)
+ ( fibonacci-ℕ)
```
-### [A000058](https://oeis.org/A000058) Sylvester's sequence
+OEIS: [A000045](https://oeis.org/A000045)
+
+### A000058 – Sylvester's sequence
```agda
open import elementary-number-theory.sylvesters-sequence using
( sylvesters-sequence-ℕ)
```
-### [A000079](https://oeis.org/A000079) Powers of `2`
+OEIS: [A000058](https://oeis.org/A000058)
+
+### A000079 – Powers of `2`
```agda
A000079 : ℕ → ℕ
A000079 = exp-ℕ 2
```
-### [A000108](https://oeis.org/A000108) The Catalan numbers
+OEIS: [A000079](https://oeis.org/A000079)
+
+### A000108 – The Catalan numbers
```agda
open import elementary-number-theory.catalan-numbers using
( catalan-numbers)
```
-### [A000110](https://oeis.org/A000110) The Bell numbers
+OEIS: [A000108](https://oeis.org/A000108)
+
+### A000110 – The Bell numbers
```agda
open import elementary-number-theory.bell-numbers using
( bell-number-ℕ)
```
-### [A000142](https://oeis.org/A000142) Factorials
+OEIS: [A000110](https://oeis.org/A000110)
+
+### A000142 – Factorials
```agda
open import elementary-number-theory.factorials using
( factorial-ℕ)
```
-### [A000215](https://oeis.org/A000215) The Fermat numbers
+OEIS: [A000142](https://oeis.org/A000142)
+
+### A000215 – The Fermat numbers
```agda
open import elementary-number-theory.fermat-numbers using
( fermat-number-ℕ)
```
-### [A000244](https://oeis.org/A000244) Powers of `3`
+OEIS: [A000215](https://oeis.org/A000215)
+
+### A000217 – The triangular numbers
+
+```agda
+open import elementary-number-theory.triangular-numbers using
+ ( triangular-number-ℕ)
+```
+
+OEIS: [A000217](https://oeis.org/A000217)
+
+### A000225 – Mersenne numbers
+
+```agda
+open import elementary-number-theory.mersenne-numbers using
+ ( mersenne-number-ℕ)
+```
+
+OEIS: [A000225](https://oeis.org/A000225)
+
+### A000244 – Powers of `3`
```agda
A000244 : ℕ → ℕ
A000244 = exp-ℕ 3
```
-### [A000720](https://oeis.org/A000720) The prime counting function
+OEIS: [A000244](https://oeis.org/A000244)
+
+### A000330 – The square pyramidal numbers
+
+```agda
+open import elementary-number-theory.square-pyramidal-numbers using
+ ( square-pyramidal-number-ℕ)
+```
+
+OEIS: [A000330](https://oeis.org/A000330)
+
+### A000720 – The prime counting function
```agda
open import elementary-number-theory.infinitude-of-primes using
( prime-counting-ℕ)
```
-### [A000945](https://oeis.org/A000945) The Euclid–Mullin sequence
+OEIS: [A000720](https://oeis.org/A000720)
+
+### A000945 – The Euclid–Mullin sequence
```agda
open import elementary-number-theory.euclid-mullin-sequence using
( euclid-mullin-ℕ)
```
-### [A001175](https://oeis.org/A001175) Pisano periods
+OEIS: [A000945](https://oeis.org/A000945)
+
+### A001175 – Pisano periods
```agda
open import elementary-number-theory.pisano-periods using
( pisano-period)
```
-### [A001177](https://oeis.org/A001177) The cofibonacci sequence
+OEIS: [A001175](https://oeis.org/A001175)
+
+### A001177 – The cofibonacci sequence
```agda
open import elementary-number-theory.cofibonacci using
( cofibonacci)
```
-### [A001477](https://oeis.org/A001477) The natural numbers
+OEIS: [A001177](https://oeis.org/A001177)
+
+### A001348 – The Mersenne numbers (at primes)
+
+```agda
+open import elementary-number-theory.mersenne-numbers using
+ ( mersenne-number-prime-ℕ)
+```
+
+OEIS: [A001348](https://oeis.org/A001348)
+
+### A001477 – The natural numbers
```agda
A001477 : ℕ → ℕ
A001477 = id
```
-### [A003090](https://oeis.org/A003090) The number of main classes of Latin squares of order `n`
+OEIS: [A001477](https://oeis.org/A001477)
+
+### A002378 – The pronic numbers
+
+```agda
+open import elementary-number-theory.pronic-numbers using
+ ( pronic-number-ℕ)
+```
+
+OEIS: [A002378](https://oeis.org/A002378)
+
+### A003090 – The number of main classes of Latin squares of order `n`
```agda
open import univalent-combinatorics.main-classes-of-latin-squares using
( number-of-main-classes-of-Latin-squares-of-order)
```
-### [A006369](https://oeis.org/A006369) Collatz' bijection
+OEIS: [A003090](https://oeis.org/A003090)
+
+### A005408 – The odd numbers
+
+```agda
+open import elementary-number-theory.parity-natural-numbers using
+ ( odd-number-ℕ)
+```
+
+OEIS: [A005408](https://oeis.org/A005408)
+
+### A005843 – The nonnegative natural numbers
+
+```agda
+open import elementary-number-theory.parity-natural-numbers using
+ ( even-number-ℕ)
+```
+
+OEIS: [A005843](https://oeis.org/A005843)
+
+### A006369 – Collatz' bijection
```agda
open import elementary-number-theory.collatz-bijection using
( map-collatz-bijection)
```
-### [A027851](https://oeis.org/A027851) The number of semigroups of order `n` up to isomorphism
+OEIS: [A006369](https://oeis.org/A006369)
+
+### A007018 – The iterated pronic numbers
+
+```agda
+open import elementary-number-theory.pronic-numbers using
+ ( iterated-pronic-number-ℕ)
+```
+
+OEIS: [A007018](https://oeis.org/A007018)
+
+### A027851 – The number of semigroups of order `n` up to isomorphism
```agda
open import finite-group-theory.finite-semigroups using
( number-of-semigroups-of-order)
```
-### [A046859](https://oeis.org/A046859) The main diagonal of the Ackermann–Péter function
+OEIS: [A027851](https://oeis.org/A027851)
+
+### A046859 – The main diagonal of the Ackermann–Péter function
```agda
open import elementary-number-theory.ackermann-function using
( simplified-ackermann-ℕ)
```
-### [A058129](https://oeis.org/A058129) The number of monoids of order `n` up to isomorphism
+OEIS: [A046859](https://oeis.org/A046859)
+
+### A058129 – The number of monoids of order `n` up to isomorphism
```agda
open import finite-group-theory.finite-monoids using
( number-of-monoids-of-order)
```
+OEIS: [A058129](https://oeis.org/A058129)
+
## References
{{#bibliography}}
diff --git a/src/metric-spaces/metric-space-of-rational-numbers.lagda.md b/src/metric-spaces/metric-space-of-rational-numbers.lagda.md
index 8ad75841c4..bac11d40c4 100644
--- a/src/metric-spaces/metric-space-of-rational-numbers.lagda.md
+++ b/src/metric-spaces/metric-space-of-rational-numbers.lagda.md
@@ -217,7 +217,7 @@ module _
lower-neighborhood-leq-ℚ d (x +ℚ u) (x +ℚ v) →
lower-neighborhood-leq-ℚ d u v
reflects-lower-neighborhood-leq-add-ℚ =
- ( reflects-leq-right-add-ℚ x v (u +ℚ rational-ℚ⁺ d)) ∘
+ ( reflects-order-right-add-ℚ x v (u +ℚ rational-ℚ⁺ d)) ∘
( tr (leq-ℚ (x +ℚ v)) (associative-add-ℚ x u (rational-ℚ⁺ d)))
```
diff --git a/src/order-theory/strictly-inflationary-maps-strict-preorders.lagda.md b/src/order-theory/strictly-inflationary-maps-strict-preorders.lagda.md
index d8a4672caa..ea8d15df33 100644
--- a/src/order-theory/strictly-inflationary-maps-strict-preorders.lagda.md
+++ b/src/order-theory/strictly-inflationary-maps-strict-preorders.lagda.md
@@ -84,10 +84,10 @@ module _
map-strictly-inflationary-map-Strict-Preorder =
pr1 f
- is-inflationary-strictly-inflationary-map-Strict-Preorder :
+ is-strictly-inflationary-strictly-inflationary-map-Strict-Preorder :
is-strictly-inflationary-map-Strict-Preorder P
( map-strictly-inflationary-map-Strict-Preorder)
- is-inflationary-strictly-inflationary-map-Strict-Preorder =
+ is-strictly-inflationary-strictly-inflationary-map-Strict-Preorder =
pr2 f
```
diff --git a/src/ring-theory/groups-of-units-rings.lagda.md b/src/ring-theory/groups-of-units-rings.lagda.md
index 16e293804e..15924cbe35 100644
--- a/src/ring-theory/groups-of-units-rings.lagda.md
+++ b/src/ring-theory/groups-of-units-rings.lagda.md
@@ -9,8 +9,10 @@ module ring-theory.groups-of-units-rings where
```agda
open import category-theory.functors-large-precategories
+open import foundation.dependent-pair-types
open import foundation.identity-types
open import foundation.propositions
+open import foundation.subtypes
open import foundation.universe-levels
open import group-theory.cores-monoids
@@ -32,8 +34,9 @@ open import ring-theory.rings
## Idea
-The **group of units** of a [ring](ring-theory.rings.md) `R` is the
-[group](group-theory.groups.md) consisting of all the
+The {{#concept "group of units" Disambiguation="ring" WD="unit" WDID=Q118084}}
+of a [ring](ring-theory.rings.md) `R` is the [group](group-theory.groups.md)
+consisting of all the
[invertible elements](ring-theory.invertible-elements-rings.md) in `R`.
Equivalently, the group of units of `R` is the
[core](group-theory.cores-monoids.md) of the multiplicative
@@ -41,6 +44,8 @@ Equivalently, the group of units of `R` is the
## Definitions
+### The group of units of a ring
+
```agda
module _
{l : Level} (R : Ring l)
@@ -136,6 +141,13 @@ module _
inclusion-group-of-units-Ring =
inclusion-core-Monoid (multiplicative-monoid-Ring R)
+ is-invertible-element-inclusion-group-of-units-Ring :
+ (x : type-group-of-units-Ring) →
+ is-invertible-element-Ring R
+ ( inclusion-group-of-units-Ring x)
+ is-invertible-element-inclusion-group-of-units-Ring =
+ is-in-subtype-inclusion-subtype subtype-group-of-units-Ring
+
preserves-mul-inclusion-group-of-units-Ring :
{x y : type-group-of-units-Ring} →
inclusion-group-of-units-Ring (mul-group-of-units-Ring x y) =
@@ -210,7 +222,7 @@ module _
( hom-multiplicative-monoid-hom-Ring R S f)
```
-#### The functorial laws of `group-of-units-Ring`
+#### The functorial laws of the group-of-units functor
```agda
module _
@@ -245,7 +257,7 @@ module _
( hom-multiplicative-monoid-hom-Ring R S f)
```
-#### The functor `group-of-units-Ring`
+#### The group-of-units functor
```agda
group-of-units-ring-functor-Large-Precategory :
@@ -266,3 +278,21 @@ preserves-id-functor-Large-Precategory
group-of-units-ring-functor-Large-Precategory {X = R} =
preserves-id-hom-group-of-units-hom-Ring R
```
+
+### Negatives of units
+
+```agda
+module _
+ {l : Level} (R : Ring l)
+ where
+
+ neg-group-of-units-Ring :
+ type-group-of-units-Ring R → type-group-of-units-Ring R
+ pr1 (neg-group-of-units-Ring (x , H)) = neg-Ring R x
+ pr2 (neg-group-of-units-Ring (x , H)) = is-invertible-element-neg-Ring R x H
+
+ neg-unit-group-of-units-Ring :
+ type-group-of-units-Ring R
+ neg-unit-group-of-units-Ring =
+ neg-group-of-units-Ring (unit-group-of-units-Ring R)
+```
diff --git a/src/ring-theory/ideals-semirings.lagda.md b/src/ring-theory/ideals-semirings.lagda.md
index 801c43f0b9..48c987fdd1 100644
--- a/src/ring-theory/ideals-semirings.lagda.md
+++ b/src/ring-theory/ideals-semirings.lagda.md
@@ -9,8 +9,13 @@ module ring-theory.ideals-semirings where
```agda
open import foundation.cartesian-product-types
open import foundation.dependent-pair-types
+open import foundation.equivalences
+open import foundation.fundamental-theorem-of-identity-types
open import foundation.identity-types
open import foundation.propositions
+open import foundation.subtype-identity-principle
+open import foundation.subtypes
+open import foundation.torsorial-type-families
open import foundation.universe-levels
open import group-theory.submonoids
@@ -36,200 +41,26 @@ correspondence to congruences. We will call such ideals **normal**.
## Definitions
-### Additive submonoids
-
-```agda
-module _
- {l1 : Level} (R : Semiring l1)
- where
-
- is-additive-submonoid-Semiring :
- {l2 : Level} → subset-Semiring l2 R → UU (l1 ⊔ l2)
- is-additive-submonoid-Semiring =
- is-submonoid-subset-Monoid (additive-monoid-Semiring R)
-```
-
-### Left ideals
-
-```agda
-module _
- {l1 : Level} (R : Semiring l1)
- where
-
- is-left-ideal-subset-Semiring :
- {l2 : Level} → subset-Semiring l2 R → UU (l1 ⊔ l2)
- is-left-ideal-subset-Semiring P =
- is-additive-submonoid-Semiring R P ×
- is-closed-under-left-multiplication-subset-Semiring R P
-
-left-ideal-Semiring :
- (l : Level) {l1 : Level} (R : Semiring l1) → UU (lsuc l ⊔ l1)
-left-ideal-Semiring l R =
- Σ (subset-Semiring l R) (is-left-ideal-subset-Semiring R)
-
-module _
- {l1 l2 : Level} (R : Semiring l1) (I : left-ideal-Semiring l2 R)
- where
-
- subset-left-ideal-Semiring : subset-Semiring l2 R
- subset-left-ideal-Semiring = pr1 I
-
- is-in-left-ideal-Semiring : type-Semiring R → UU l2
- is-in-left-ideal-Semiring x = type-Prop (subset-left-ideal-Semiring x)
-
- type-left-ideal-Semiring : UU (l1 ⊔ l2)
- type-left-ideal-Semiring = type-subset-Semiring R subset-left-ideal-Semiring
-
- inclusion-left-ideal-Semiring : type-left-ideal-Semiring → type-Semiring R
- inclusion-left-ideal-Semiring =
- inclusion-subset-Semiring R subset-left-ideal-Semiring
-
- ap-inclusion-left-ideal-Semiring :
- (x y : type-left-ideal-Semiring) → x = y →
- inclusion-left-ideal-Semiring x = inclusion-left-ideal-Semiring y
- ap-inclusion-left-ideal-Semiring =
- ap-inclusion-subset-Semiring R subset-left-ideal-Semiring
-
- is-in-subset-inclusion-left-ideal-Semiring :
- (x : type-left-ideal-Semiring) →
- is-in-left-ideal-Semiring (inclusion-left-ideal-Semiring x)
- is-in-subset-inclusion-left-ideal-Semiring =
- is-in-subset-inclusion-subset-Semiring R subset-left-ideal-Semiring
-
- is-closed-under-eq-left-ideal-Semiring :
- {x y : type-Semiring R} → is-in-left-ideal-Semiring x →
- (x = y) → is-in-left-ideal-Semiring y
- is-closed-under-eq-left-ideal-Semiring =
- is-closed-under-eq-subset-Semiring R subset-left-ideal-Semiring
-
- is-closed-under-eq-left-ideal-Semiring' :
- {x y : type-Semiring R} → is-in-left-ideal-Semiring y →
- (x = y) → is-in-left-ideal-Semiring x
- is-closed-under-eq-left-ideal-Semiring' =
- is-closed-under-eq-subset-Semiring' R subset-left-ideal-Semiring
-
- is-left-ideal-subset-left-ideal-Semiring :
- is-left-ideal-subset-Semiring R subset-left-ideal-Semiring
- is-left-ideal-subset-left-ideal-Semiring = pr2 I
-
- is-additive-submonoid-left-ideal-Semiring :
- is-additive-submonoid-Semiring R subset-left-ideal-Semiring
- is-additive-submonoid-left-ideal-Semiring =
- pr1 is-left-ideal-subset-left-ideal-Semiring
-
- contains-zero-left-ideal-Semiring :
- is-in-left-ideal-Semiring (zero-Semiring R)
- contains-zero-left-ideal-Semiring =
- pr1 is-additive-submonoid-left-ideal-Semiring
-
- is-closed-under-addition-left-ideal-Semiring :
- is-closed-under-addition-subset-Semiring R subset-left-ideal-Semiring
- is-closed-under-addition-left-ideal-Semiring =
- pr2 is-additive-submonoid-left-ideal-Semiring
-
- is-closed-under-left-multiplication-left-ideal-Semiring :
- is-closed-under-left-multiplication-subset-Semiring R
- subset-left-ideal-Semiring
- is-closed-under-left-multiplication-left-ideal-Semiring =
- pr2 is-left-ideal-subset-left-ideal-Semiring
-```
-
-### Right ideals
-
-```agda
-module _
- {l1 : Level} (R : Semiring l1)
- where
-
- is-right-ideal-subset-Semiring :
- {l2 : Level} → subset-Semiring l2 R → UU (l1 ⊔ l2)
- is-right-ideal-subset-Semiring P =
- is-additive-submonoid-Semiring R P ×
- is-closed-under-right-multiplication-subset-Semiring R P
-
-right-ideal-Semiring :
- (l : Level) {l1 : Level} (R : Semiring l1) → UU (lsuc l ⊔ l1)
-right-ideal-Semiring l R =
- Σ (subset-Semiring l R) (is-right-ideal-subset-Semiring R)
-
-module _
- {l1 l2 : Level} (R : Semiring l1) (I : right-ideal-Semiring l2 R)
- where
-
- subset-right-ideal-Semiring : subset-Semiring l2 R
- subset-right-ideal-Semiring = pr1 I
-
- is-in-right-ideal-Semiring : type-Semiring R → UU l2
- is-in-right-ideal-Semiring x = type-Prop (subset-right-ideal-Semiring x)
-
- type-right-ideal-Semiring : UU (l1 ⊔ l2)
- type-right-ideal-Semiring =
- type-subset-Semiring R subset-right-ideal-Semiring
-
- inclusion-right-ideal-Semiring : type-right-ideal-Semiring → type-Semiring R
- inclusion-right-ideal-Semiring =
- inclusion-subset-Semiring R subset-right-ideal-Semiring
-
- ap-inclusion-right-ideal-Semiring :
- (x y : type-right-ideal-Semiring) → x = y →
- inclusion-right-ideal-Semiring x = inclusion-right-ideal-Semiring y
- ap-inclusion-right-ideal-Semiring =
- ap-inclusion-subset-Semiring R subset-right-ideal-Semiring
-
- is-in-subset-inclusion-right-ideal-Semiring :
- (x : type-right-ideal-Semiring) →
- is-in-right-ideal-Semiring (inclusion-right-ideal-Semiring x)
- is-in-subset-inclusion-right-ideal-Semiring =
- is-in-subset-inclusion-subset-Semiring R subset-right-ideal-Semiring
-
- is-closed-under-eq-right-ideal-Semiring :
- {x y : type-Semiring R} → is-in-right-ideal-Semiring x →
- (x = y) → is-in-right-ideal-Semiring y
- is-closed-under-eq-right-ideal-Semiring =
- is-closed-under-eq-subset-Semiring R subset-right-ideal-Semiring
-
- is-closed-under-eq-right-ideal-Semiring' :
- {x y : type-Semiring R} → is-in-right-ideal-Semiring y →
- (x = y) → is-in-right-ideal-Semiring x
- is-closed-under-eq-right-ideal-Semiring' =
- is-closed-under-eq-subset-Semiring' R subset-right-ideal-Semiring
-
- is-right-ideal-subset-right-ideal-Semiring :
- is-right-ideal-subset-Semiring R subset-right-ideal-Semiring
- is-right-ideal-subset-right-ideal-Semiring = pr2 I
-
- is-additive-submonoid-right-ideal-Semiring :
- is-additive-submonoid-Semiring R subset-right-ideal-Semiring
- is-additive-submonoid-right-ideal-Semiring =
- pr1 is-right-ideal-subset-right-ideal-Semiring
-
- contains-zero-right-ideal-Semiring :
- is-in-right-ideal-Semiring (zero-Semiring R)
- contains-zero-right-ideal-Semiring =
- pr1 is-additive-submonoid-right-ideal-Semiring
-
- is-closed-under-addition-right-ideal-Semiring :
- is-closed-under-addition-subset-Semiring R subset-right-ideal-Semiring
- is-closed-under-addition-right-ideal-Semiring =
- pr2 is-additive-submonoid-right-ideal-Semiring
-
- is-closed-under-right-multiplication-right-ideal-Semiring :
- is-closed-under-right-multiplication-subset-Semiring R
- subset-right-ideal-Semiring
- is-closed-under-right-multiplication-right-ideal-Semiring =
- pr2 is-right-ideal-subset-right-ideal-Semiring
-```
-
-### Two-sided ideals
+### Ideals of semirings
```agda
is-ideal-subset-Semiring :
{l1 l2 : Level} (R : Semiring l1) (P : subset-Semiring l2 R) → UU (l1 ⊔ l2)
is-ideal-subset-Semiring R P =
- is-additive-submonoid-Semiring R P ×
+ is-additive-submonoid-subset-Semiring R P ×
( is-closed-under-left-multiplication-subset-Semiring R P ×
is-closed-under-right-multiplication-subset-Semiring R P)
+is-prop-is-ideal-subset-Semiring :
+ {l1 l2 : Level} (R : Semiring l1) (P : subset-Semiring l2 R) →
+ is-prop (is-ideal-subset-Semiring R P)
+is-prop-is-ideal-subset-Semiring R P =
+ is-prop-product
+ ( is-prop-is-additive-submonoid-subset-Semiring R P)
+ ( is-prop-product
+ ( is-prop-is-closed-under-left-multiplication-subset-Semiring R P)
+ ( is-prop-is-closed-under-right-multiplication-subset-Semiring R P))
+
ideal-Semiring :
(l : Level) {l1 : Level} (R : Semiring l1) → UU (lsuc l ⊔ l1)
ideal-Semiring l R =
@@ -242,6 +73,10 @@ module _
subset-ideal-Semiring : subset-Semiring l2 R
subset-ideal-Semiring = pr1 I
+ is-ideal-ideal-Semiring :
+ is-ideal-subset-Semiring R subset-ideal-Semiring
+ is-ideal-ideal-Semiring = pr2 I
+
is-in-ideal-Semiring : type-Semiring R → UU l2
is-in-ideal-Semiring =
is-in-subset-Semiring R subset-ideal-Semiring
@@ -289,7 +124,7 @@ module _
is-ideal-subset-ideal-Semiring = pr2 I
is-additive-submonoid-ideal-Semiring :
- is-additive-submonoid-Semiring R subset-ideal-Semiring
+ is-additive-submonoid-subset-Semiring R subset-ideal-Semiring
is-additive-submonoid-ideal-Semiring =
pr1 is-ideal-subset-ideal-Semiring
@@ -318,3 +153,65 @@ module _
pr1 (pr2 submonoid-ideal-Semiring) = contains-zero-ideal-Semiring
pr2 (pr2 submonoid-ideal-Semiring) = is-closed-under-addition-ideal-Semiring
```
+
+## Properties
+
+### Characterizing equality of ideals in semirings
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1) (I : ideal-Semiring l2 R)
+ where
+
+ has-same-elements-ideal-Semiring :
+ (J : ideal-Semiring l3 R) → UU (l1 ⊔ l2 ⊔ l3)
+ has-same-elements-ideal-Semiring J =
+ has-same-elements-subtype
+ ( subset-ideal-Semiring R I)
+ ( subset-ideal-Semiring R J)
+
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : ideal-Semiring l2 R)
+ where
+
+ refl-has-same-elements-ideal-Semiring :
+ has-same-elements-ideal-Semiring R I I
+ refl-has-same-elements-ideal-Semiring =
+ refl-has-same-elements-subtype (subset-ideal-Semiring R I)
+
+ is-torsorial-has-same-elements-ideal-Semiring :
+ is-torsorial (has-same-elements-ideal-Semiring R I)
+ is-torsorial-has-same-elements-ideal-Semiring =
+ is-torsorial-Eq-subtype
+ ( is-torsorial-has-same-elements-subtype (subset-ideal-Semiring R I))
+ ( is-prop-is-ideal-subset-Semiring R)
+ ( subset-ideal-Semiring R I)
+ ( refl-has-same-elements-ideal-Semiring)
+ ( is-ideal-ideal-Semiring R I)
+
+ has-same-elements-eq-ideal-Semiring :
+ (J : ideal-Semiring l2 R) →
+ (I = J) → has-same-elements-ideal-Semiring R I J
+ has-same-elements-eq-ideal-Semiring .I refl =
+ refl-has-same-elements-ideal-Semiring
+
+ is-equiv-has-same-elements-eq-ideal-Semiring :
+ (J : ideal-Semiring l2 R) → is-equiv (has-same-elements-eq-ideal-Semiring J)
+ is-equiv-has-same-elements-eq-ideal-Semiring =
+ fundamental-theorem-id
+ is-torsorial-has-same-elements-ideal-Semiring
+ has-same-elements-eq-ideal-Semiring
+
+ extensionality-ideal-Semiring :
+ (J : ideal-Semiring l2 R) →
+ (I = J) ≃ has-same-elements-ideal-Semiring R I J
+ pr1 (extensionality-ideal-Semiring J) =
+ has-same-elements-eq-ideal-Semiring J
+ pr2 (extensionality-ideal-Semiring J) =
+ is-equiv-has-same-elements-eq-ideal-Semiring J
+
+ eq-has-same-elements-ideal-Semiring :
+ (J : ideal-Semiring l2 R) → has-same-elements-ideal-Semiring R I J → I = J
+ eq-has-same-elements-ideal-Semiring J =
+ map-inv-equiv (extensionality-ideal-Semiring J)
+```
diff --git a/src/ring-theory/invertible-elements-rings.lagda.md b/src/ring-theory/invertible-elements-rings.lagda.md
index 5066846791..9f9781e0c5 100644
--- a/src/ring-theory/invertible-elements-rings.lagda.md
+++ b/src/ring-theory/invertible-elements-rings.lagda.md
@@ -221,7 +221,7 @@ module _
( multiplicative-monoid-Ring R)
```
-### Any invertible element of a monoid has a contractible type of right inverses
+### Any invertible element of a ring has a contractible type of right inverses
```agda
module _
@@ -236,7 +236,7 @@ module _
( multiplicative-monoid-Ring R)
```
-### Any invertible element of a monoid has a contractible type of left inverses
+### Any invertible element of a ring has a contractible type of left inverses
```agda
module _
@@ -251,7 +251,7 @@ module _
( multiplicative-monoid-Ring R)
```
-### The unit of a monoid is invertible
+### The unit of a ring is invertible
```agda
module _
@@ -275,9 +275,18 @@ module _
is-invertible-element-one-Ring =
is-invertible-element-unit-Monoid
( multiplicative-monoid-Ring R)
+
+ is-invertible-element-is-one-Ring :
+ (x : type-Ring R) → one-Ring R = x →
+ is-invertible-element-Ring R x
+ is-invertible-element-is-one-Ring =
+ is-invertible-element-is-unit-Monoid
+ ( multiplicative-monoid-Ring R)
```
-### Invertible elements are closed under multiplication
+### If two of the three elements `x`, `y`, and `xy` are invertible, then so is the third
+
+#### Invertible elements are closed under multiplication
```agda
module _
@@ -312,6 +321,42 @@ module _
( multiplicative-monoid-Ring R)
```
+#### If `y` and `xy` are invertible, then so is `x`
+
+```agda
+module _
+ {l : Level} (R : Ring l) (x y : type-Ring R)
+ where
+
+ is-invertible-element-left-factor-Ring :
+ is-invertible-element-Ring R y →
+ is-invertible-element-Ring R (mul-Ring R x y) →
+ is-invertible-element-Ring R x
+ is-invertible-element-left-factor-Ring =
+ is-invertible-element-left-factor-Monoid
+ ( multiplicative-monoid-Ring R)
+ ( x)
+ ( y)
+```
+
+#### If `x` and `xy` are invertible, then so is `y`
+
+```agda
+module _
+ {l : Level} (R : Ring l) (x y : type-Ring R)
+ where
+
+ is-invertible-element-right-factor-Ring :
+ is-invertible-element-Ring R x →
+ is-invertible-element-Ring R (mul-Ring R x y) →
+ is-invertible-element-Ring R y
+ is-invertible-element-right-factor-Ring =
+ is-invertible-element-right-factor-Monoid
+ ( multiplicative-monoid-Ring R)
+ ( x)
+ ( y)
+```
+
### Invertible elements are closed under negatives
```agda
diff --git a/src/ring-theory/left-ideals-generated-by-subsets-rings.lagda.md b/src/ring-theory/left-ideals-generated-by-subsets-rings.lagda.md
index 45001b74cb..2ee0d560d7 100644
--- a/src/ring-theory/left-ideals-generated-by-subsets-rings.lagda.md
+++ b/src/ring-theory/left-ideals-generated-by-subsets-rings.lagda.md
@@ -42,9 +42,9 @@ open import ring-theory.subsets-rings
## Idea
-The **left ideal generated by a [subset](ring-theory.subsets-rings.md)** `S` of
-a [ring](ring-theory.rings.md) `R` is the least left ideal in `R` containing
-`S`.
+The {{#concept "left ideal generated by a subset" Disambiguation="rings" Agda=left-ideal-subset-Ring}} `S` of
+a [ring](ring-theory.rings.md) `R` is the least [left ideal](ring-theory.left-ideals-rings.md) in `R` containing
+the [subset](ring-theory.subsets-rings.md) `S`.
## Definitions
diff --git a/src/ring-theory/left-ideals-generated-by-subsets-semirings.lagda.md b/src/ring-theory/left-ideals-generated-by-subsets-semirings.lagda.md
new file mode 100644
index 0000000000..0f69449590
--- /dev/null
+++ b/src/ring-theory/left-ideals-generated-by-subsets-semirings.lagda.md
@@ -0,0 +1,527 @@
+# Left ideals generated by subsets of semirings
+
+```agda
+module ring-theory.left-ideals-generated-by-subsets-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.action-on-identifications-functions
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.identity-types
+open import foundation.logical-equivalences
+open import foundation.powersets
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.subtypes
+open import foundation.transport-along-identifications
+open import foundation.unions-subtypes
+open import foundation.universe-levels
+
+open import lists.concatenation-lists
+open import lists.functoriality-lists
+open import lists.lists
+
+open import order-theory.galois-connections-large-posets
+open import order-theory.least-upper-bounds-large-posets
+open import order-theory.order-preserving-maps-large-posets
+open import order-theory.order-preserving-maps-large-preorders
+open import order-theory.reflective-galois-connections-large-posets
+
+open import ring-theory.left-ideals-semirings
+open import ring-theory.left-linear-combinations-of-elements-semirings
+open import ring-theory.monoids-with-semiring-actions
+open import ring-theory.poset-of-left-ideals-semirings
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+```
+
+
+
+## Idea
+
+The {{#concept "left ideal generated by a subset" Disambiguation="semirings" Agda=left-ideal-subset-Semiring}} `S` of
+a [semiring](ring-theory.semirings.md) `R` is the least [left ideal](ring-theory.left-ideals-semirings.md) in `R` containing
+the [subset](ring-theory.subsets-semirings.md) `S`.
+
+## Definitions
+
+### The universal property of left ideals generated by a subset of a semiring
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1) (S : subset-Semiring l2 R)
+ (I : left-ideal-Semiring l3 R) (H : S ⊆ subset-left-ideal-Semiring R I)
+ where
+
+ is-left-ideal-generated-by-subset-Semiring : UUω
+ is-left-ideal-generated-by-subset-Semiring =
+ {l : Level} (J : left-ideal-Semiring l R) →
+ S ⊆ subset-left-ideal-Semiring R J →
+ subset-left-ideal-Semiring R I ⊆ subset-left-ideal-Semiring R J
+```
+
+### The universal property of left ideals generated by a family of subsets of a semiring
+
+```agda
+module _
+ {l1 l2 l3 l4 : Level} (R : Semiring l1) {U : UU l2}
+ (S : U → subset-Semiring l3 R)
+ (I : left-ideal-Semiring l4 R)
+ (H : (α : U) → S α ⊆ subset-left-ideal-Semiring R I)
+ where
+
+ is-left-ideal-generated-by-family-of-subsets-Semiring : UUω
+ is-left-ideal-generated-by-family-of-subsets-Semiring =
+ {l : Level} (J : left-ideal-Semiring l R) →
+ ((α : U) → S α ⊆ subset-left-ideal-Semiring R J) →
+ leq-left-ideal-Semiring R I J
+```
+
+### The universal property of left ideals generated by a family of elements in a semiring
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1) {U : UU l2} (a : U → type-Semiring R)
+ (I : left-ideal-Semiring l3 R) (H : (α : U) → is-in-left-ideal-Semiring R I (a α))
+ where
+
+ is-left-ideal-generated-by-family-of-elements-Semiring : UUω
+ is-left-ideal-generated-by-family-of-elements-Semiring =
+ {l : Level} (J : left-ideal-Semiring l R) →
+ ((α : U) → is-in-left-ideal-Semiring R J (a α)) →
+ leq-left-ideal-Semiring R I J
+```
+
+### Construction of the Galois connection of left ideals generated by subsets
+
+#### Left ideals generated by subsets
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (S : subset-Semiring l2 R)
+ where
+
+ subset-left-ideal-subset-Semiring' : type-Semiring R → UU (l1 ⊔ l2)
+ subset-left-ideal-subset-Semiring' =
+ is-left-linear-combination-subset-Semiring R S
+
+ subset-left-ideal-subset-Semiring : subset-Semiring (l1 ⊔ l2) R
+ subset-left-ideal-subset-Semiring =
+ is-mere-left-linear-combination-prop-subset-Semiring R S
+
+ is-in-left-ideal-subset-Semiring : type-Semiring R → UU (l1 ⊔ l2)
+ is-in-left-ideal-subset-Semiring =
+ is-in-subtype subset-left-ideal-subset-Semiring
+
+ contains-zero-left-ideal-subset-Semiring :
+ contains-zero-subset-Semiring R subset-left-ideal-subset-Semiring
+ contains-zero-left-ideal-subset-Semiring =
+ unit-trunc-Prop (nil , refl)
+
+ is-closed-under-addition-left-ideal-subset-Semiring :
+ is-closed-under-addition-subset-Semiring R subset-left-ideal-subset-Semiring
+ is-closed-under-addition-left-ideal-subset-Semiring x y H K =
+ apply-twice-universal-property-trunc-Prop H K
+ ( subset-left-ideal-subset-Semiring _)
+ ( λ H' K' →
+ unit-trunc-Prop
+ ( is-left-linear-combination-mul-monoid-Semiring R
+ ( additive-monoid-Semiring R)
+ ( λ r (s , p) → mul-Semiring R r s)
+ ( x)
+ ( y)
+ ( H')
+ ( K')))
+
+ is-closed-under-left-multiplication-left-ideal-subset-Semiring :
+ is-closed-under-left-multiplication-subset-Semiring R
+ ( subset-left-ideal-subset-Semiring)
+ is-closed-under-left-multiplication-left-ideal-subset-Semiring r x H =
+ apply-universal-property-trunc-Prop H
+ ( subset-left-ideal-subset-Semiring _)
+ ( λ H' →
+ unit-trunc-Prop
+ ( is-left-linear-combination-action-Semiring
+ ( R)
+ ( additive-monoid-with-left-semiring-action-Semiring R)
+ ( λ t (s , H) → mul-Semiring R t s)
+ ( λ s t (a , H) → associative-mul-Semiring R s t a)
+ ( r)
+ ( x)
+ ( H')))
+
+ left-ideal-subset-Semiring :
+ left-ideal-Semiring (l1 ⊔ l2) R
+ pr1 left-ideal-subset-Semiring =
+ subset-left-ideal-subset-Semiring
+ pr1 (pr1 (pr2 left-ideal-subset-Semiring)) =
+ contains-zero-left-ideal-subset-Semiring
+ pr2 (pr1 (pr2 left-ideal-subset-Semiring)) =
+ is-closed-under-addition-left-ideal-subset-Semiring
+ pr2 (pr2 left-ideal-subset-Semiring) =
+ is-closed-under-left-multiplication-left-ideal-subset-Semiring
+
+ contains-subset-left-ideal-subset-Semiring :
+ S ⊆ subset-left-ideal-subset-Semiring
+ contains-subset-left-ideal-subset-Semiring s H =
+ unit-trunc-Prop
+ ( ( unit-list (one-Semiring R , (s , H))) ,
+ ( right-unit-law-add-Semiring R (mul-Semiring R (one-Semiring R) s)) ∙
+ ( left-unit-law-mul-Semiring R s))
+
+ contains-left-linear-combinations-left-ideal-subset-Semiring :
+ {l3 : Level} (I : left-ideal-Semiring l3 R) →
+ S ⊆ subset-left-ideal-Semiring R I →
+ (x : left-linear-combination-subset-Semiring R S) →
+ is-in-left-ideal-Semiring R I
+ ( ev-left-linear-combination-subset-Semiring R S x)
+ contains-left-linear-combinations-left-ideal-subset-Semiring I H nil =
+ contains-zero-left-ideal-Semiring R I
+ contains-left-linear-combinations-left-ideal-subset-Semiring I H
+ ( cons (r , (s , K)) l) =
+ is-closed-under-addition-left-ideal-Semiring R I
+ ( mul-Semiring R r s)
+ ( ev-left-linear-combination-subset-Semiring R S l)
+ ( is-closed-under-left-multiplication-left-ideal-Semiring R I r s (H s K))
+ ( contains-left-linear-combinations-left-ideal-subset-Semiring I H l)
+
+ is-left-ideal-generated-by-subset-left-ideal-subset-Semiring :
+ is-left-ideal-generated-by-subset-Semiring R S
+ ( left-ideal-subset-Semiring)
+ ( contains-subset-left-ideal-subset-Semiring)
+ is-left-ideal-generated-by-subset-left-ideal-subset-Semiring {l} J K x H =
+ apply-universal-property-trunc-Prop H (subset-left-ideal-Semiring R J x) P
+ where
+ P : subset-left-ideal-subset-Semiring' x → is-in-left-ideal-Semiring R J x
+ P (pair c refl) =
+ contains-left-linear-combinations-left-ideal-subset-Semiring J K c
+
+ is-closed-under-eq-left-ideal-subset-Semiring :
+ {x y : type-Semiring R} → is-in-left-ideal-subset-Semiring x →
+ (x = y) → is-in-left-ideal-subset-Semiring y
+ is-closed-under-eq-left-ideal-subset-Semiring =
+ is-closed-under-eq-left-ideal-Semiring R left-ideal-subset-Semiring
+
+ is-closed-under-eq-left-ideal-subset-Semiring' :
+ {x y : type-Semiring R} → is-in-left-ideal-subset-Semiring y →
+ (x = y) → is-in-left-ideal-subset-Semiring x
+ is-closed-under-eq-left-ideal-subset-Semiring' =
+ is-closed-under-eq-left-ideal-Semiring' R left-ideal-subset-Semiring
+```
+
+#### The subset relation is preserved by generating left ideals
+
+```agda
+module _
+ {l1 : Level} (A : Semiring l1)
+ where
+
+ preserves-order-left-ideal-subset-Semiring :
+ {l2 l3 : Level} (S : subset-Semiring l2 A) (T : subset-Semiring l3 A) →
+ S ⊆ T →
+ leq-left-ideal-Semiring A
+ ( left-ideal-subset-Semiring A S)
+ ( left-ideal-subset-Semiring A T)
+ preserves-order-left-ideal-subset-Semiring S T H =
+ is-left-ideal-generated-by-subset-left-ideal-subset-Semiring A S
+ ( left-ideal-subset-Semiring A T)
+ ( transitive-leq-subtype S T
+ ( subset-left-ideal-subset-Semiring A T)
+ ( contains-subset-left-ideal-subset-Semiring A T)
+ ( H))
+
+ left-ideal-subset-hom-large-poset-Semiring :
+ hom-Large-Poset
+ ( λ l2 → l1 ⊔ l2)
+ ( powerset-Large-Poset (type-Semiring A))
+ ( left-ideal-Semiring-Large-Poset A)
+ map-hom-Large-Preorder left-ideal-subset-hom-large-poset-Semiring =
+ left-ideal-subset-Semiring A
+ preserves-order-hom-Large-Preorder
+ left-ideal-subset-hom-large-poset-Semiring =
+ preserves-order-left-ideal-subset-Semiring
+```
+
+#### The Galois connection `S ↦ (S)`
+
+```agda
+module _
+ {l1 : Level} (A : Semiring l1)
+ where
+
+ adjoint-relation-left-ideal-subset-Semiring :
+ {l2 l3 : Level} (S : subset-Semiring l2 A) (I : left-ideal-Semiring l3 A) →
+ leq-left-ideal-Semiring A (left-ideal-subset-Semiring A S) I ↔
+ (S ⊆ subset-left-ideal-Semiring A I)
+ pr1 (adjoint-relation-left-ideal-subset-Semiring S I) H =
+ transitive-leq-subtype S
+ ( subset-left-ideal-subset-Semiring A S)
+ ( subset-left-ideal-Semiring A I)
+ ( H)
+ ( contains-subset-left-ideal-subset-Semiring A S)
+ pr2 (adjoint-relation-left-ideal-subset-Semiring S I) =
+ is-left-ideal-generated-by-subset-left-ideal-subset-Semiring A S I
+
+ left-ideal-subset-galois-connection-Semiring :
+ galois-connection-Large-Poset
+ ( l1 ⊔_) (λ l → l)
+ ( powerset-Large-Poset (type-Semiring A))
+ ( left-ideal-Semiring-Large-Poset A)
+ lower-adjoint-galois-connection-Large-Poset
+ left-ideal-subset-galois-connection-Semiring =
+ left-ideal-subset-hom-large-poset-Semiring A
+ upper-adjoint-galois-connection-Large-Poset
+ left-ideal-subset-galois-connection-Semiring =
+ subset-left-ideal-hom-large-poset-Semiring A
+ adjoint-relation-galois-connection-Large-Poset
+ left-ideal-subset-galois-connection-Semiring =
+ adjoint-relation-left-ideal-subset-Semiring
+```
+
+#### The reflective Galois connection `S ↦ (S)`
+
+```agda
+module _
+ {l1 : Level} (A : Semiring l1)
+ where
+
+ forward-inclusion-is-reflective-left-ideal-subset-galois-connection-Semiring :
+ {l2 : Level} (I : left-ideal-Semiring l2 A) →
+ leq-left-ideal-Semiring A
+ ( left-ideal-subset-Semiring A (subset-left-ideal-Semiring A I))
+ ( I)
+ forward-inclusion-is-reflective-left-ideal-subset-galois-connection-Semiring
+ I =
+ is-left-ideal-generated-by-subset-left-ideal-subset-Semiring A
+ ( subset-left-ideal-Semiring A I)
+ ( I)
+ ( refl-leq-left-ideal-Semiring A I)
+
+ backward-inclusion-is-reflective-left-ideal-subset-galois-connection-Semiring :
+ {l2 : Level} (I : left-ideal-Semiring l2 A) →
+ leq-left-ideal-Semiring A I
+ ( left-ideal-subset-Semiring A (subset-left-ideal-Semiring A I))
+ backward-inclusion-is-reflective-left-ideal-subset-galois-connection-Semiring
+ I =
+ contains-subset-left-ideal-subset-Semiring A
+ ( subset-left-ideal-Semiring A I)
+
+ is-reflective-left-ideal-subset-galois-connection-Semiring :
+ is-reflective-galois-connection-Large-Poset
+ ( powerset-Large-Poset (type-Semiring A))
+ ( left-ideal-Semiring-Large-Poset A)
+ ( left-ideal-subset-galois-connection-Semiring A)
+ pr1 (is-reflective-left-ideal-subset-galois-connection-Semiring I) =
+ forward-inclusion-is-reflective-left-ideal-subset-galois-connection-Semiring
+ I
+ pr2 (is-reflective-left-ideal-subset-galois-connection-Semiring I) =
+ backward-inclusion-is-reflective-left-ideal-subset-galois-connection-Semiring
+ I
+
+ left-ideal-subset-reflective-galois-connection-Semiring :
+ reflective-galois-connection-Large-Poset
+ ( powerset-Large-Poset (type-Semiring A))
+ ( left-ideal-Semiring-Large-Poset A)
+ galois-connection-reflective-galois-connection-Large-Poset
+ left-ideal-subset-reflective-galois-connection-Semiring =
+ left-ideal-subset-galois-connection-Semiring A
+ is-reflective-reflective-galois-connection-Large-Poset
+ left-ideal-subset-reflective-galois-connection-Semiring =
+ is-reflective-left-ideal-subset-galois-connection-Semiring
+```
+
+### The left ideal generated by a family of subsets of a semiring
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1) {U : UU l2} (S : U → subset-Semiring l3 R)
+ where
+
+ generating-subset-left-ideal-family-of-subsets-Semiring :
+ subset-Semiring (l2 ⊔ l3) R
+ generating-subset-left-ideal-family-of-subsets-Semiring x =
+ union-family-of-subtypes S x
+
+ left-ideal-family-of-subsets-Semiring : left-ideal-Semiring (l1 ⊔ l2 ⊔ l3) R
+ left-ideal-family-of-subsets-Semiring =
+ left-ideal-subset-Semiring R
+ generating-subset-left-ideal-family-of-subsets-Semiring
+
+ subset-left-ideal-family-of-subsets-Semiring :
+ subset-Semiring (l1 ⊔ l2 ⊔ l3) R
+ subset-left-ideal-family-of-subsets-Semiring =
+ subset-left-ideal-subset-Semiring R
+ generating-subset-left-ideal-family-of-subsets-Semiring
+
+ is-in-left-ideal-family-of-subsets-Semiring :
+ type-Semiring R → UU (l1 ⊔ l2 ⊔ l3)
+ is-in-left-ideal-family-of-subsets-Semiring =
+ is-in-left-ideal-subset-Semiring R
+ generating-subset-left-ideal-family-of-subsets-Semiring
+
+ contains-subset-left-ideal-family-of-subsets-Semiring :
+ {α : U} → (S α) ⊆ subset-left-ideal-family-of-subsets-Semiring
+ contains-subset-left-ideal-family-of-subsets-Semiring {α} x H =
+ contains-subset-left-ideal-subset-Semiring R
+ ( generating-subset-left-ideal-family-of-subsets-Semiring)
+ ( x)
+ ( unit-trunc-Prop (α , H))
+
+ is-left-ideal-generated-by-family-of-subsets-left-ideal-family-of-subsets-Semiring :
+ is-left-ideal-generated-by-family-of-subsets-Semiring R S
+ ( left-ideal-family-of-subsets-Semiring)
+ ( λ α → contains-subset-left-ideal-family-of-subsets-Semiring)
+ is-left-ideal-generated-by-family-of-subsets-left-ideal-family-of-subsets-Semiring
+ J H =
+ is-left-ideal-generated-by-subset-left-ideal-subset-Semiring R
+ ( generating-subset-left-ideal-family-of-subsets-Semiring)
+ ( J)
+ ( λ y q →
+ apply-universal-property-trunc-Prop q
+ ( subset-left-ideal-Semiring R J y)
+ ( λ (α , K) → H α y K))
+```
+
+### The left ideal generated by a family of elements in a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) {I : UU l1} (a : I → type-Semiring R)
+ where
+
+ generating-subset-left-ideal-family-of-elements-Semiring :
+ subset-Semiring l1 R
+ generating-subset-left-ideal-family-of-elements-Semiring x =
+ trunc-Prop (fiber a x)
+
+ left-ideal-family-of-elements-Semiring :
+ left-ideal-Semiring l1 R
+ left-ideal-family-of-elements-Semiring =
+ left-ideal-subset-Semiring R
+ generating-subset-left-ideal-family-of-elements-Semiring
+
+ subset-left-ideal-family-of-elements-Semiring :
+ subset-Semiring l1 R
+ subset-left-ideal-family-of-elements-Semiring =
+ subset-left-ideal-subset-Semiring R
+ generating-subset-left-ideal-family-of-elements-Semiring
+
+ is-in-left-ideal-family-of-elements-Semiring :
+ type-Semiring R → UU l1
+ is-in-left-ideal-family-of-elements-Semiring =
+ is-in-left-ideal-subset-Semiring R
+ generating-subset-left-ideal-family-of-elements-Semiring
+
+ contains-element-left-ideal-family-of-elements-Semiring :
+ (i : I) → is-in-left-ideal-family-of-elements-Semiring (a i)
+ contains-element-left-ideal-family-of-elements-Semiring i =
+ contains-subset-left-ideal-subset-Semiring R
+ ( generating-subset-left-ideal-family-of-elements-Semiring)
+ ( a i)
+ ( unit-trunc-Prop (i , refl))
+
+ abstract
+ is-left-ideal-generated-by-family-of-elements-left-ideal-family-of-elements-Semiring :
+ is-left-ideal-generated-by-family-of-elements-Semiring R a
+ left-ideal-family-of-elements-Semiring
+ contains-element-left-ideal-family-of-elements-Semiring
+ is-left-ideal-generated-by-family-of-elements-left-ideal-family-of-elements-Semiring
+ J H =
+ is-left-ideal-generated-by-subset-left-ideal-subset-Semiring R
+ ( generating-subset-left-ideal-family-of-elements-Semiring)
+ ( J)
+ ( λ x p →
+ apply-universal-property-trunc-Prop p
+ ( subset-left-ideal-Semiring R J x)
+ ( λ where (i , refl) → H i))
+```
+
+## Properties
+
+### The left ideal generated by the underlying subset of an left ideal `I` is `I` itself
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : left-ideal-Semiring l2 R)
+ where
+
+ cases-forward-inclusion-idempotent-left-ideal-subset-Semiring :
+ (l : left-linear-combination-subset-Semiring R (subset-left-ideal-Semiring R I)) →
+ is-in-left-ideal-Semiring R I
+ ( ev-left-linear-combination-subset-Semiring R (subset-left-ideal-Semiring R I) l)
+ cases-forward-inclusion-idempotent-left-ideal-subset-Semiring nil =
+ contains-zero-left-ideal-Semiring R I
+ cases-forward-inclusion-idempotent-left-ideal-subset-Semiring
+ ( cons (x , y , u) l) =
+ is-closed-under-addition-left-ideal-Semiring R I
+ ( mul-Semiring R x y)
+ ( ev-left-linear-combination-subset-Semiring R
+ ( subset-left-ideal-Semiring R I)
+ ( l))
+ ( is-closed-under-left-multiplication-left-ideal-Semiring R I x y u)
+ ( cases-forward-inclusion-idempotent-left-ideal-subset-Semiring l)
+
+ abstract
+ forward-inclusion-idempotent-left-ideal-subset-Semiring :
+ leq-left-ideal-Semiring R
+ ( left-ideal-subset-Semiring R (subset-left-ideal-Semiring R I))
+ ( I)
+ forward-inclusion-idempotent-left-ideal-subset-Semiring x H =
+ apply-universal-property-trunc-Prop H
+ ( subset-left-ideal-Semiring R I x)
+ ( λ where
+ ( l , refl) →
+ cases-forward-inclusion-idempotent-left-ideal-subset-Semiring l)
+
+ backward-inclusion-idempotent-left-ideal-subset-Semiring :
+ leq-left-ideal-Semiring R
+ ( I)
+ ( left-ideal-subset-Semiring R (subset-left-ideal-Semiring R I))
+ backward-inclusion-idempotent-left-ideal-subset-Semiring =
+ contains-subset-left-ideal-subset-Semiring R
+ ( subset-left-ideal-Semiring R I)
+
+ idempotent-left-ideal-subset-Semiring :
+ has-same-elements-left-ideal-Semiring R
+ ( left-ideal-subset-Semiring R (subset-left-ideal-Semiring R I))
+ ( I)
+ pr1 (idempotent-left-ideal-subset-Semiring x) =
+ forward-inclusion-idempotent-left-ideal-subset-Semiring x
+ pr2 (idempotent-left-ideal-subset-Semiring x) =
+ backward-inclusion-idempotent-left-ideal-subset-Semiring x
+```
+
+### The operation `S ↦ (S)` preserves least upper bounds
+
+In
+[`ring-theory.joins-left-ideals-semirings`](ring-theory.joins-left-ideals-semirings.md)
+we will convert this fact to the fact that `S ↦ (S)` preserves joins.
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {U : UU l2} (S : U → subset-Semiring l3 R)
+ where
+
+ preserves-least-upper-bounds-left-ideal-subset-Semiring :
+ {l4 : Level} (T : subset-Semiring l4 R) →
+ is-least-upper-bound-family-of-elements-Large-Poset
+ ( powerset-Large-Poset (type-Semiring R))
+ ( S)
+ ( T) →
+ is-least-upper-bound-family-of-elements-Large-Poset
+ ( left-ideal-Semiring-Large-Poset R)
+ ( λ α → left-ideal-subset-Semiring R (S α))
+ ( left-ideal-subset-Semiring R T)
+ preserves-least-upper-bounds-left-ideal-subset-Semiring =
+ preserves-join-lower-adjoint-galois-connection-Large-Poset
+ ( powerset-Large-Poset (type-Semiring R))
+ ( left-ideal-Semiring-Large-Poset R)
+ ( left-ideal-subset-galois-connection-Semiring R)
+ ( S)
+```
diff --git a/src/ring-theory/left-ideals-rings.lagda.md b/src/ring-theory/left-ideals-rings.lagda.md
index c0d2710a89..b7668f4c21 100644
--- a/src/ring-theory/left-ideals-rings.lagda.md
+++ b/src/ring-theory/left-ideals-rings.lagda.md
@@ -18,6 +18,7 @@ open import foundation.subtypes
open import foundation.torsorial-type-families
open import foundation.universe-levels
+open import ring-theory.left-ideals-semirings
open import ring-theory.rings
open import ring-theory.subsets-rings
```
@@ -26,7 +27,7 @@ open import ring-theory.subsets-rings
## Idea
-A **left ideal** in a [ring](ring-theory.rings.md) `R` is a left submodule of
+A {{#concept "left ideal" Disambiguation="rings" Agda=left-ideal-Ring}} in a [ring](ring-theory.rings.md) `R` is a left submodule of
`R`.
## Definitions
@@ -40,92 +41,99 @@ module _
is-left-ideal-subset-Ring :
{l2 : Level} → subset-Ring l2 R → UU (l1 ⊔ l2)
- is-left-ideal-subset-Ring S =
- is-additive-subgroup-subset-Ring R S ×
- is-closed-under-left-multiplication-subset-Ring R S
+ is-left-ideal-subset-Ring =
+ is-left-ideal-subset-Semiring (semiring-Ring R)
is-prop-is-left-ideal-subset-Ring :
{l2 : Level} (S : subset-Ring l2 R) → is-prop (is-left-ideal-subset-Ring S)
- is-prop-is-left-ideal-subset-Ring S =
- is-prop-product
- ( is-prop-is-additive-subgroup-subset-Ring R S)
- ( is-prop-is-closed-under-left-multiplication-subset-Ring R S)
+ is-prop-is-left-ideal-subset-Ring =
+ is-prop-is-left-ideal-subset-Semiring (semiring-Ring R)
left-ideal-Ring :
(l : Level) {l1 : Level} (R : Ring l1) → UU (lsuc l ⊔ l1)
-left-ideal-Ring l R = Σ (subset-Ring l R) (is-left-ideal-subset-Ring R)
+left-ideal-Ring l R =
+ left-ideal-Semiring l (semiring-Ring R)
module _
{l1 l2 : Level} (R : Ring l1) (I : left-ideal-Ring l2 R)
where
subset-left-ideal-Ring : subset-Ring l2 R
- subset-left-ideal-Ring = pr1 I
+ subset-left-ideal-Ring =
+ subset-left-ideal-Semiring (semiring-Ring R) I
is-in-left-ideal-Ring : type-Ring R → UU l2
- is-in-left-ideal-Ring x = type-Prop (subset-left-ideal-Ring x)
+ is-in-left-ideal-Ring =
+ is-in-left-ideal-Semiring (semiring-Ring R) I
type-left-ideal-Ring : UU (l1 ⊔ l2)
type-left-ideal-Ring = type-subset-Ring R subset-left-ideal-Ring
inclusion-left-ideal-Ring : type-left-ideal-Ring → type-Ring R
- inclusion-left-ideal-Ring = inclusion-subset-Ring R subset-left-ideal-Ring
+ inclusion-left-ideal-Ring =
+ inclusion-left-ideal-Semiring (semiring-Ring R) I
ap-inclusion-left-ideal-Ring :
(x y : type-left-ideal-Ring) → x = y →
inclusion-left-ideal-Ring x = inclusion-left-ideal-Ring y
ap-inclusion-left-ideal-Ring =
- ap-inclusion-subset-Ring R subset-left-ideal-Ring
+ ap-inclusion-left-ideal-Semiring (semiring-Ring R) I
is-in-subset-inclusion-left-ideal-Ring :
(x : type-left-ideal-Ring) →
is-in-left-ideal-Ring (inclusion-left-ideal-Ring x)
is-in-subset-inclusion-left-ideal-Ring =
- is-in-subset-inclusion-subset-Ring R subset-left-ideal-Ring
+ is-in-subset-inclusion-left-ideal-Semiring (semiring-Ring R) I
is-closed-under-eq-left-ideal-Ring :
{x y : type-Ring R} → is-in-left-ideal-Ring x →
(x = y) → is-in-left-ideal-Ring y
is-closed-under-eq-left-ideal-Ring =
- is-closed-under-eq-subset-Ring R subset-left-ideal-Ring
+ is-closed-under-eq-left-ideal-Semiring (semiring-Ring R) I
is-closed-under-eq-left-ideal-Ring' :
{x y : type-Ring R} → is-in-left-ideal-Ring y →
(x = y) → is-in-left-ideal-Ring x
is-closed-under-eq-left-ideal-Ring' =
- is-closed-under-eq-subset-Ring' R subset-left-ideal-Ring
+ is-closed-under-eq-left-ideal-Semiring' (semiring-Ring R) I
is-left-ideal-subset-left-ideal-Ring :
is-left-ideal-subset-Ring R subset-left-ideal-Ring
- is-left-ideal-subset-left-ideal-Ring = pr2 I
+ is-left-ideal-subset-left-ideal-Ring =
+ is-left-ideal-subset-left-ideal-Semiring (semiring-Ring R) I
- is-additive-subgroup-subset-left-ideal-Ring :
- is-additive-subgroup-subset-Ring R subset-left-ideal-Ring
- is-additive-subgroup-subset-left-ideal-Ring =
- pr1 is-left-ideal-subset-left-ideal-Ring
+ is-additive-submonoid-subset-left-ideal-Ring :
+ is-additive-submonoid-subset-Ring R subset-left-ideal-Ring
+ is-additive-submonoid-subset-left-ideal-Ring =
+ is-additive-submonoid-subset-left-ideal-Semiring (semiring-Ring R) I
contains-zero-left-ideal-Ring : is-in-left-ideal-Ring (zero-Ring R)
contains-zero-left-ideal-Ring =
- pr1 is-additive-subgroup-subset-left-ideal-Ring
+ contains-zero-left-ideal-Semiring (semiring-Ring R) I
is-closed-under-addition-left-ideal-Ring :
is-closed-under-addition-subset-Ring R subset-left-ideal-Ring
is-closed-under-addition-left-ideal-Ring =
- pr1 (pr2 is-additive-subgroup-subset-left-ideal-Ring)
-
- is-closed-under-negatives-left-ideal-Ring :
- is-closed-under-negatives-subset-Ring R subset-left-ideal-Ring
- is-closed-under-negatives-left-ideal-Ring =
- pr2 (pr2 is-additive-subgroup-subset-left-ideal-Ring)
+ is-closed-under-addition-left-ideal-Semiring (semiring-Ring R) I
is-closed-under-left-multiplication-left-ideal-Ring :
is-closed-under-left-multiplication-subset-Ring R subset-left-ideal-Ring
is-closed-under-left-multiplication-left-ideal-Ring =
- pr2 is-left-ideal-subset-left-ideal-Ring
+ is-closed-under-left-multiplication-left-ideal-Semiring (semiring-Ring R) I
+
+ is-additive-subgroup-left-ideal-Ring :
+ is-additive-subgroup-subset-Ring R subset-left-ideal-Ring
+ is-additive-subgroup-left-ideal-Ring =
+ is-additive-subgroup-is-closed-under-left-multiplication-subset-Ring
+ ( R)
+ ( subset-left-ideal-Ring)
+ ( is-additive-submonoid-subset-left-ideal-Ring)
+ ( is-closed-under-left-multiplication-left-ideal-Ring)
is-left-ideal-left-ideal-Ring :
is-left-ideal-subset-Ring R subset-left-ideal-Ring
- is-left-ideal-left-ideal-Ring = pr2 I
+ is-left-ideal-left-ideal-Ring =
+ is-left-ideal-left-ideal-Semiring (semiring-Ring R) I
```
## Properties
@@ -139,10 +147,8 @@ module _
has-same-elements-left-ideal-Ring :
(J : left-ideal-Ring l3 R) → UU (l1 ⊔ l2 ⊔ l3)
- has-same-elements-left-ideal-Ring J =
- has-same-elements-subtype
- ( subset-left-ideal-Ring R I)
- ( subset-left-ideal-Ring R J)
+ has-same-elements-left-ideal-Ring =
+ has-same-elements-left-ideal-Semiring (semiring-Ring R) I
module _
{l1 l2 : Level} (R : Ring l1) (I : left-ideal-Ring l2 R)
@@ -151,43 +157,34 @@ module _
refl-has-same-elements-left-ideal-Ring :
has-same-elements-left-ideal-Ring R I I
refl-has-same-elements-left-ideal-Ring =
- refl-has-same-elements-subtype (subset-left-ideal-Ring R I)
+ refl-has-same-elements-left-ideal-Semiring (semiring-Ring R) I
is-torsorial-has-same-elements-left-ideal-Ring :
is-torsorial (has-same-elements-left-ideal-Ring R I)
is-torsorial-has-same-elements-left-ideal-Ring =
- is-torsorial-Eq-subtype
- ( is-torsorial-has-same-elements-subtype (subset-left-ideal-Ring R I))
- ( is-prop-is-left-ideal-subset-Ring R)
- ( subset-left-ideal-Ring R I)
- ( refl-has-same-elements-left-ideal-Ring)
- ( is-left-ideal-left-ideal-Ring R I)
+ is-torsorial-has-same-elements-left-ideal-Semiring (semiring-Ring R) I
has-same-elements-eq-left-ideal-Ring :
(J : left-ideal-Ring l2 R) →
(I = J) → has-same-elements-left-ideal-Ring R I J
- has-same-elements-eq-left-ideal-Ring .I refl =
- refl-has-same-elements-left-ideal-Ring
+ has-same-elements-eq-left-ideal-Ring =
+ has-same-elements-eq-left-ideal-Semiring (semiring-Ring R) I
is-equiv-has-same-elements-eq-left-ideal-Ring :
(J : left-ideal-Ring l2 R) →
is-equiv (has-same-elements-eq-left-ideal-Ring J)
is-equiv-has-same-elements-eq-left-ideal-Ring =
- fundamental-theorem-id
- is-torsorial-has-same-elements-left-ideal-Ring
- has-same-elements-eq-left-ideal-Ring
+ is-equiv-has-same-elements-eq-left-ideal-Semiring (semiring-Ring R) I
extensionality-left-ideal-Ring :
(J : left-ideal-Ring l2 R) →
(I = J) ≃ has-same-elements-left-ideal-Ring R I J
- pr1 (extensionality-left-ideal-Ring J) =
- has-same-elements-eq-left-ideal-Ring J
- pr2 (extensionality-left-ideal-Ring J) =
- is-equiv-has-same-elements-eq-left-ideal-Ring J
+ extensionality-left-ideal-Ring =
+ extensionality-left-ideal-Semiring (semiring-Ring R) I
eq-has-same-elements-left-ideal-Ring :
(J : left-ideal-Ring l2 R) →
has-same-elements-left-ideal-Ring R I J → I = J
- eq-has-same-elements-left-ideal-Ring J =
- map-inv-equiv (extensionality-left-ideal-Ring J)
+ eq-has-same-elements-left-ideal-Ring =
+ eq-has-same-elements-left-ideal-Semiring (semiring-Ring R) I
```
diff --git a/src/ring-theory/left-ideals-semirings.lagda.md b/src/ring-theory/left-ideals-semirings.lagda.md
new file mode 100644
index 0000000000..fd5167ec4d
--- /dev/null
+++ b/src/ring-theory/left-ideals-semirings.lagda.md
@@ -0,0 +1,194 @@
+# Left ideals of semirings
+
+```agda
+module ring-theory.left-ideals-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.equivalences
+open import foundation.fundamental-theorem-of-identity-types
+open import foundation.identity-types
+open import foundation.propositions
+open import foundation.subtype-identity-principle
+open import foundation.subtypes
+open import foundation.torsorial-type-families
+open import foundation.universe-levels
+
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+```
+
+
+
+## Idea
+
+A {{#concept "left ideal" Disambiguation="semiring" Agda=left-ideal-Semiring}} in a [semiring](ring-theory.semirings.md) `R` is a left submodule of
+`R`.
+
+## Definitions
+
+### Left ideals
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1)
+ where
+
+ is-left-ideal-subset-Semiring :
+ {l2 : Level} → subset-Semiring l2 R → UU (l1 ⊔ l2)
+ is-left-ideal-subset-Semiring S =
+ is-additive-submonoid-subset-Semiring R S ×
+ is-closed-under-left-multiplication-subset-Semiring R S
+
+ is-prop-is-left-ideal-subset-Semiring :
+ {l2 : Level} (S : subset-Semiring l2 R) →
+ is-prop (is-left-ideal-subset-Semiring S)
+ is-prop-is-left-ideal-subset-Semiring S =
+ is-prop-product
+ ( is-prop-is-additive-submonoid-subset-Semiring R S)
+ ( is-prop-is-closed-under-left-multiplication-subset-Semiring R S)
+
+left-ideal-Semiring :
+ (l : Level) {l1 : Level} (R : Semiring l1) → UU (lsuc l ⊔ l1)
+left-ideal-Semiring l R =
+ Σ (subset-Semiring l R) (is-left-ideal-subset-Semiring R)
+
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : left-ideal-Semiring l2 R)
+ where
+
+ subset-left-ideal-Semiring : subset-Semiring l2 R
+ subset-left-ideal-Semiring = pr1 I
+
+ is-in-left-ideal-Semiring : type-Semiring R → UU l2
+ is-in-left-ideal-Semiring x = type-Prop (subset-left-ideal-Semiring x)
+
+ type-left-ideal-Semiring : UU (l1 ⊔ l2)
+ type-left-ideal-Semiring = type-subset-Semiring R subset-left-ideal-Semiring
+
+ inclusion-left-ideal-Semiring :
+ type-left-ideal-Semiring → type-Semiring R
+ inclusion-left-ideal-Semiring =
+ inclusion-subset-Semiring R subset-left-ideal-Semiring
+
+ ap-inclusion-left-ideal-Semiring :
+ (x y : type-left-ideal-Semiring) → x = y →
+ inclusion-left-ideal-Semiring x = inclusion-left-ideal-Semiring y
+ ap-inclusion-left-ideal-Semiring =
+ ap-inclusion-subset-Semiring R subset-left-ideal-Semiring
+
+ is-in-subset-inclusion-left-ideal-Semiring :
+ (x : type-left-ideal-Semiring) →
+ is-in-left-ideal-Semiring (inclusion-left-ideal-Semiring x)
+ is-in-subset-inclusion-left-ideal-Semiring =
+ is-in-subset-inclusion-subset-Semiring R subset-left-ideal-Semiring
+
+ is-closed-under-eq-left-ideal-Semiring :
+ {x y : type-Semiring R} → is-in-left-ideal-Semiring x →
+ (x = y) → is-in-left-ideal-Semiring y
+ is-closed-under-eq-left-ideal-Semiring =
+ is-closed-under-eq-subset-Semiring R subset-left-ideal-Semiring
+
+ is-closed-under-eq-left-ideal-Semiring' :
+ {x y : type-Semiring R} → is-in-left-ideal-Semiring y →
+ (x = y) → is-in-left-ideal-Semiring x
+ is-closed-under-eq-left-ideal-Semiring' =
+ is-closed-under-eq-subset-Semiring' R subset-left-ideal-Semiring
+
+ is-left-ideal-subset-left-ideal-Semiring :
+ is-left-ideal-subset-Semiring R subset-left-ideal-Semiring
+ is-left-ideal-subset-left-ideal-Semiring = pr2 I
+
+ is-additive-submonoid-subset-left-ideal-Semiring :
+ is-additive-submonoid-subset-Semiring R subset-left-ideal-Semiring
+ is-additive-submonoid-subset-left-ideal-Semiring =
+ pr1 is-left-ideal-subset-left-ideal-Semiring
+
+ contains-zero-left-ideal-Semiring :
+ is-in-left-ideal-Semiring (zero-Semiring R)
+ contains-zero-left-ideal-Semiring =
+ pr1 is-additive-submonoid-subset-left-ideal-Semiring
+
+ is-closed-under-addition-left-ideal-Semiring :
+ is-closed-under-addition-subset-Semiring R subset-left-ideal-Semiring
+ is-closed-under-addition-left-ideal-Semiring =
+ pr2 is-additive-submonoid-subset-left-ideal-Semiring
+
+ is-closed-under-left-multiplication-left-ideal-Semiring :
+ is-closed-under-left-multiplication-subset-Semiring R
+ ( subset-left-ideal-Semiring)
+ is-closed-under-left-multiplication-left-ideal-Semiring =
+ pr2 is-left-ideal-subset-left-ideal-Semiring
+
+ is-left-ideal-left-ideal-Semiring :
+ is-left-ideal-subset-Semiring R subset-left-ideal-Semiring
+ is-left-ideal-left-ideal-Semiring = pr2 I
+```
+
+## Properties
+
+### Characterizing equality of left ideals in semirings
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1) (I : left-ideal-Semiring l2 R)
+ where
+
+ has-same-elements-left-ideal-Semiring :
+ (J : left-ideal-Semiring l3 R) → UU (l1 ⊔ l2 ⊔ l3)
+ has-same-elements-left-ideal-Semiring J =
+ has-same-elements-subtype
+ ( subset-left-ideal-Semiring R I)
+ ( subset-left-ideal-Semiring R J)
+
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : left-ideal-Semiring l2 R)
+ where
+
+ refl-has-same-elements-left-ideal-Semiring :
+ has-same-elements-left-ideal-Semiring R I I
+ refl-has-same-elements-left-ideal-Semiring =
+ refl-has-same-elements-subtype (subset-left-ideal-Semiring R I)
+
+ is-torsorial-has-same-elements-left-ideal-Semiring :
+ is-torsorial (has-same-elements-left-ideal-Semiring R I)
+ is-torsorial-has-same-elements-left-ideal-Semiring =
+ is-torsorial-Eq-subtype
+ ( is-torsorial-has-same-elements-subtype (subset-left-ideal-Semiring R I))
+ ( is-prop-is-left-ideal-subset-Semiring R)
+ ( subset-left-ideal-Semiring R I)
+ ( refl-has-same-elements-left-ideal-Semiring)
+ ( is-left-ideal-left-ideal-Semiring R I)
+
+ has-same-elements-eq-left-ideal-Semiring :
+ (J : left-ideal-Semiring l2 R) →
+ (I = J) → has-same-elements-left-ideal-Semiring R I J
+ has-same-elements-eq-left-ideal-Semiring .I refl =
+ refl-has-same-elements-left-ideal-Semiring
+
+ is-equiv-has-same-elements-eq-left-ideal-Semiring :
+ (J : left-ideal-Semiring l2 R) →
+ is-equiv (has-same-elements-eq-left-ideal-Semiring J)
+ is-equiv-has-same-elements-eq-left-ideal-Semiring =
+ fundamental-theorem-id
+ is-torsorial-has-same-elements-left-ideal-Semiring
+ has-same-elements-eq-left-ideal-Semiring
+
+ extensionality-left-ideal-Semiring :
+ (J : left-ideal-Semiring l2 R) →
+ (I = J) ≃ has-same-elements-left-ideal-Semiring R I J
+ pr1 (extensionality-left-ideal-Semiring J) =
+ has-same-elements-eq-left-ideal-Semiring J
+ pr2 (extensionality-left-ideal-Semiring J) =
+ is-equiv-has-same-elements-eq-left-ideal-Semiring J
+
+ eq-has-same-elements-left-ideal-Semiring :
+ (J : left-ideal-Semiring l2 R) →
+ has-same-elements-left-ideal-Semiring R I J → I = J
+ eq-has-same-elements-left-ideal-Semiring J =
+ map-inv-equiv (extensionality-left-ideal-Semiring J)
+```
diff --git a/src/ring-theory/left-linear-combinations-of-elements-rings.lagda.md b/src/ring-theory/left-linear-combinations-of-elements-rings.lagda.md
new file mode 100644
index 0000000000..7c27f978b9
--- /dev/null
+++ b/src/ring-theory/left-linear-combinations-of-elements-rings.lagda.md
@@ -0,0 +1,164 @@
+# Left linear combinations with respect to rings
+
+```agda
+module ring-theory.left-linear-combinations-of-elements-rings where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.universe-levels
+
+open import ring-theory.rings
+open import ring-theory.subsets-rings
+
+open import lists.lists
+
+open import structured-types.magmas
+```
+
+
+
+## Idea
+
+Consider a [ring](ring-theory.rings.md) $R$ and a type $A$. A {#concept "left linear combination"}} of elements of $R$ is a [list](lists.lists.md) of pairs $(r,a)$ consisting of an element $r:R$ and an element $a:A$.
+
+Furthermore, if we are given an action $\mu : R \to A \to M$ taking values in a [unital magma](structured-types.magmas.md) $(M,+,0)$, then we can evaluate a left linear combination $((r_0,a_0),\ldots,(r_{n-1},a_{n-1}))$ by defining
+
+$$
+ ev((r_0,a_0),\ldots,(r_{n-1},a_{n-1})) := \sum_{i=0}^{n-1} \mu(r_i,a_i).
+$$
+
+To be explicit, left linear combinations of elements of a type $A$ have the ring coefficients on the left.
+
+
+## Definitions
+
+### The type of left linear combinations
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (A : UU l2)
+ where
+
+ left-linear-combination-Ring :
+ UU (l1 ⊔ l2)
+ left-linear-combination-Ring =
+ list (type-Ring R × A)
+```
+
+### Evaluating left linear combinations of elements in unital magmas
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Ring R → A → type-Unital-Magma M)
+ where
+
+ ev-left-linear-combination-Ring :
+ left-linear-combination-Ring R A → type-Unital-Magma M
+ ev-left-linear-combination-Ring nil =
+ unit-Unital-Magma M
+ ev-left-linear-combination-Ring (cons (r , a) l) =
+ mul-Unital-Magma M (μ r a) (ev-left-linear-combination-Ring l)
+```
+
+### The predicate of being a left linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Ring R → A → type-Unital-Magma M)
+ where
+
+ is-left-linear-combination-Ring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-left-linear-combination-Ring =
+ fiber (ev-left-linear-combination-Ring R M μ)
+```
+
+### The predicate of being a mere left linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Ring R → A → type-Unital-Magma M)
+ where
+
+ is-mere-left-linear-combination-prop-Ring :
+ type-Unital-Magma M → Prop (l1 ⊔ l2 ⊔ l3)
+ is-mere-left-linear-combination-prop-Ring x =
+ trunc-Prop (is-left-linear-combination-Ring R M μ x)
+
+ is-mere-left-linear-combination-Ring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-mere-left-linear-combination-Ring x =
+ type-trunc-Prop (is-left-linear-combination-Ring R M μ x)
+
+ is-prop-is-mere-left-linear-combination-Ring :
+ (x : type-Unital-Magma M) →
+ is-prop (is-mere-left-linear-combination-Ring x)
+ is-prop-is-mere-left-linear-combination-Ring x =
+ is-prop-type-trunc-Prop
+```
+
+### Left linear combinations of subsets of a ring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (S : subset-Ring l2 R)
+ where
+
+ left-linear-combination-subset-Ring :
+ UU (l1 ⊔ l2)
+ left-linear-combination-subset-Ring =
+ left-linear-combination-Ring R (type-subset-Ring R S)
+
+ ev-left-linear-combination-subset-Ring :
+ left-linear-combination-subset-Ring → type-Ring R
+ ev-left-linear-combination-subset-Ring =
+ ev-left-linear-combination-Ring R
+ ( additive-unital-magma-Ring R)
+ ( λ r s → mul-Ring R r (inclusion-subset-Ring R S s))
+
+ is-left-linear-combination-subset-Ring :
+ type-Ring R → UU (l1 ⊔ l2)
+ is-left-linear-combination-subset-Ring =
+ is-left-linear-combination-Ring R
+ ( additive-unital-magma-Ring R)
+ ( λ r s → mul-Ring R r (inclusion-subset-Ring R S s))
+```
+
+### Left linear combinations of families of elements in a ring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) {I : UU l2} (a : I → type-Ring R)
+ where
+
+ left-linear-combination-family-of-elements-Ring :
+ UU (l1 ⊔ l2)
+ left-linear-combination-family-of-elements-Ring =
+ left-linear-combination-subset-Ring R (trunc-Prop ∘ fiber a)
+
+ ev-left-linear-combination-family-of-elements-Ring :
+ left-linear-combination-family-of-elements-Ring → type-Ring R
+ ev-left-linear-combination-family-of-elements-Ring =
+ ev-left-linear-combination-subset-Ring R
+ ( trunc-Prop ∘ fiber a)
+
+ is-left-linear-combination-family-of-elements-Ring :
+ type-Ring R → UU (l1 ⊔ l2)
+ is-left-linear-combination-family-of-elements-Ring =
+ is-left-linear-combination-subset-Ring R
+ ( trunc-Prop ∘ fiber a)
+```
diff --git a/src/ring-theory/left-linear-combinations-of-elements-semirings.lagda.md b/src/ring-theory/left-linear-combinations-of-elements-semirings.lagda.md
new file mode 100644
index 0000000000..2bb7561a9c
--- /dev/null
+++ b/src/ring-theory/left-linear-combinations-of-elements-semirings.lagda.md
@@ -0,0 +1,306 @@
+# Left linear combinations with respect to semirings
+
+```agda
+module ring-theory.left-linear-combinations-of-elements-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.action-on-identifications-binary-functions
+open import foundation.action-on-identifications-functions
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.identity-types
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.universe-levels
+
+open import group-theory.monoids
+
+open import ring-theory.monoids-with-semiring-actions
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+
+open import lists.concatenation-lists
+open import lists.functoriality-lists
+open import lists.lists
+
+open import structured-types.magmas
+```
+
+
+
+## Idea
+
+Consider a [semiring](ring-theory.semirings.md) $R$ and a type $A$. A {#concept "left linear combination"}} of elements of $R$ is a [list](lists.lists.md) of pairs $(r,a)$ consisting of an element $r:R$ and an element $a:A$.
+
+Furthermore, if we are given an action $\mu : R \to A \to M$ taking values in a [unital magma](structured-types.magmas.md) $(M,+,0)$, then we can evaluate a left linear combination $((r_0,a_0),\ldots,(r_{n-1},a_{n-1}))$ by defining
+
+$$
+ ev((r_0,a_0),\ldots,(r_{n-1},a_{n-1})) := \sum_{i=0}^{n-1} \mu(r_i,a_i).
+$$
+
+To be explicit, left linear combinations of elements of a type $A$ have the semiring coefficients on the left.
+
+
+## Definitions
+
+### The type of left linear combinations
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (A : UU l2)
+ where
+
+ left-linear-combination-Semiring :
+ UU (l1 ⊔ l2)
+ left-linear-combination-Semiring =
+ list (type-Semiring R × A)
+```
+
+### Multiplying linear combinations by a scalar
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) {A : UU l2}
+ where
+
+ mul-left-linear-combination-Semiring :
+ type-Semiring R →
+ left-linear-combination-Semiring R A →
+ left-linear-combination-Semiring R A
+ mul-left-linear-combination-Semiring r =
+ map-list (λ (s , a) → (mul-Semiring R r s , a))
+```
+
+### Evaluating left linear combinations of elements
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2}
+ where
+
+ ev-unital-magma-left-linear-combination-Semiring :
+ (M : Unital-Magma l3) (μ : type-Semiring R → A → type-Unital-Magma M) →
+ left-linear-combination-Semiring R A → type-Unital-Magma M
+ ev-unital-magma-left-linear-combination-Semiring M μ nil =
+ unit-Unital-Magma M
+ ev-unital-magma-left-linear-combination-Semiring M μ (cons (r , a) l) =
+ mul-Unital-Magma M
+ ( μ r a)
+ ( ev-unital-magma-left-linear-combination-Semiring M μ l)
+
+ ev-monoid-left-linear-combination-Semiring :
+ (M : Monoid l3) (μ : type-Semiring R → A → type-Monoid M) →
+ left-linear-combination-Semiring R A → type-Monoid M
+ ev-monoid-left-linear-combination-Semiring M =
+ ev-unital-magma-left-linear-combination-Semiring (unital-magma-Monoid M)
+```
+
+### The predicate of being a left linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2}
+ where
+
+ is-left-linear-combination-Semiring :
+ (M : Unital-Magma l3) (μ : type-Semiring R → A → type-Unital-Magma M) →
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-left-linear-combination-Semiring M μ =
+ fiber (ev-unital-magma-left-linear-combination-Semiring R M μ)
+
+ is-left-linear-combination-monoid-Semiring :
+ (M : Monoid l3) (μ : type-Semiring R → A → type-Monoid M) →
+ type-Monoid M → UU (l1 ⊔ l2 ⊔ l3)
+ is-left-linear-combination-monoid-Semiring M =
+ is-left-linear-combination-Semiring (unital-magma-Monoid M)
+```
+
+### The predicate of being a mere left linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Semiring R → A → type-Unital-Magma M)
+ where
+
+ is-mere-left-linear-combination-prop-Semiring :
+ type-Unital-Magma M → Prop (l1 ⊔ l2 ⊔ l3)
+ is-mere-left-linear-combination-prop-Semiring x =
+ trunc-Prop (is-left-linear-combination-Semiring R M μ x)
+
+ is-mere-left-linear-combination-Semiring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-mere-left-linear-combination-Semiring x =
+ type-trunc-Prop (is-left-linear-combination-Semiring R M μ x)
+
+ is-prop-is-mere-left-linear-combination-Semiring :
+ (x : type-Unital-Magma M) →
+ is-prop (is-mere-left-linear-combination-Semiring x)
+ is-prop-is-mere-left-linear-combination-Semiring x =
+ is-prop-type-trunc-Prop
+```
+
+### Left linear combinations of subsets of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (S : subset-Semiring l2 R)
+ where
+
+ left-linear-combination-subset-Semiring :
+ UU (l1 ⊔ l2)
+ left-linear-combination-subset-Semiring =
+ left-linear-combination-Semiring R (type-subset-Semiring R S)
+
+ ev-left-linear-combination-subset-Semiring :
+ left-linear-combination-subset-Semiring → type-Semiring R
+ ev-left-linear-combination-subset-Semiring =
+ ev-unital-magma-left-linear-combination-Semiring R
+ ( additive-unital-magma-Semiring R)
+ ( λ r s → mul-Semiring R r (inclusion-subset-Semiring R S s))
+
+ is-left-linear-combination-subset-Semiring :
+ type-Semiring R → UU (l1 ⊔ l2)
+ is-left-linear-combination-subset-Semiring =
+ is-left-linear-combination-Semiring R
+ ( additive-unital-magma-Semiring R)
+ ( λ r s → mul-Semiring R r (inclusion-subset-Semiring R S s))
+
+ is-mere-left-linear-combination-prop-subset-Semiring :
+ type-Semiring R → Prop (l1 ⊔ l2)
+ is-mere-left-linear-combination-prop-subset-Semiring =
+ is-mere-left-linear-combination-prop-Semiring R
+ ( additive-unital-magma-Semiring R)
+ ( λ r s → mul-Semiring R r (inclusion-subset-Semiring R S s))
+```
+
+### Left linear combinations of families of elements in a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) {I : UU l2} (a : I → type-Semiring R)
+ where
+
+ left-linear-combination-family-of-elements-Semiring :
+ UU (l1 ⊔ l2)
+ left-linear-combination-family-of-elements-Semiring =
+ left-linear-combination-subset-Semiring R (trunc-Prop ∘ fiber a)
+
+ ev-unital-magma-left-linear-combination-family-of-elements-Semiring :
+ left-linear-combination-family-of-elements-Semiring → type-Semiring R
+ ev-unital-magma-left-linear-combination-family-of-elements-Semiring =
+ ev-left-linear-combination-subset-Semiring R (trunc-Prop ∘ fiber a)
+
+ is-left-linear-combination-family-of-elements-Semiring :
+ type-Semiring R → UU (l1 ⊔ l2)
+ is-left-linear-combination-family-of-elements-Semiring =
+ is-left-linear-combination-subset-Semiring R (trunc-Prop ∘ fiber a)
+```
+
+## Properties
+
+### Given a left action of a semiring $R$ on a type $A$ with values in a monoid, the evaluation function preserves concatenation
+
+We assume a monoid here, because we need associativity for the multiplicative operation of the monoid.
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Monoid l3)
+ (μ : type-Semiring R → A → type-Monoid M)
+ where
+
+ preserves-concat-ev-monoid-left-linear-combination-Semiring :
+ (u v : left-linear-combination-Semiring R A) →
+ ev-monoid-left-linear-combination-Semiring R M
+ ( μ)
+ ( concat-list u v) =
+ mul-Monoid M
+ ( ev-monoid-left-linear-combination-Semiring R M μ u)
+ ( ev-monoid-left-linear-combination-Semiring R M μ v)
+ preserves-concat-ev-monoid-left-linear-combination-Semiring nil v =
+ inv
+ ( left-unit-law-mul-Monoid M
+ ( ev-monoid-left-linear-combination-Semiring R M μ v))
+ preserves-concat-ev-monoid-left-linear-combination-Semiring
+ ( cons (r , s) u) v =
+ ( ap
+ ( mul-Monoid M (μ r s))
+ ( preserves-concat-ev-monoid-left-linear-combination-Semiring u v)) ∙
+ ( inv
+ ( associative-mul-Monoid M
+ ( μ r s)
+ ( ev-monoid-left-linear-combination-Semiring R M μ u)
+ ( ev-monoid-left-linear-combination-Semiring R M μ v)))
+
+ is-left-linear-combination-mul-monoid-Semiring :
+ (x y : type-Monoid M) →
+ is-left-linear-combination-monoid-Semiring R M μ x →
+ is-left-linear-combination-monoid-Semiring R M μ y →
+ is-left-linear-combination-monoid-Semiring R M μ (mul-Monoid M x y)
+ is-left-linear-combination-mul-monoid-Semiring x y (u , refl) (v , refl) =
+ ( concat-list u v ,
+ preserves-concat-ev-monoid-left-linear-combination-Semiring u v)
+```
+
+### Evaluation of linear combinations preserves scalar multiplication
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Monoid-With-Left-Semiring-Action l3 R)
+ (μ : type-Semiring R → A → type-Monoid-With-Left-Semiring-Action R M)
+ (α :
+ (s r : type-Semiring R) (a : A) →
+ μ (mul-Semiring R s r) a =
+ action-Monoid-With-Left-Semiring-Action R M s (μ r a))
+ where
+
+ preserves-mul-ev-left-linear-combination-Semiring :
+ (r : type-Semiring R) (u : left-linear-combination-Semiring R A) →
+ ev-monoid-left-linear-combination-Semiring R
+ ( monoid-Monoid-With-Left-Semiring-Action R M)
+ ( μ)
+ ( mul-left-linear-combination-Semiring R r u) =
+ action-Monoid-With-Left-Semiring-Action R M r
+ ( ev-monoid-left-linear-combination-Semiring R
+ ( monoid-Monoid-With-Left-Semiring-Action R M)
+ ( μ)
+ ( u))
+ preserves-mul-ev-left-linear-combination-Semiring r nil =
+ inv (right-absorption-law-action-Monoid-With-Left-Semiring-Action R M r)
+ preserves-mul-ev-left-linear-combination-Semiring r (cons (s , a) u) =
+ ap-binary
+ ( mul-Monoid-With-Left-Semiring-Action R M)
+ ( α r s a)
+ ( preserves-mul-ev-left-linear-combination-Semiring r u) ∙
+ inv
+ ( left-distributive-action-mul-Monoid-With-Left-Semiring-Action R M r
+ ( μ s a)
+ ( ev-monoid-left-linear-combination-Semiring R
+ ( monoid-Monoid-With-Left-Semiring-Action R M)
+ ( μ)
+ ( u)))
+
+ is-left-linear-combination-action-Semiring :
+ (r : type-Semiring R) (x : type-Monoid-With-Left-Semiring-Action R M) →
+ is-left-linear-combination-monoid-Semiring R
+ ( monoid-Monoid-With-Left-Semiring-Action R M)
+ ( μ)
+ ( x) →
+ is-left-linear-combination-monoid-Semiring R
+ ( monoid-Monoid-With-Left-Semiring-Action R M)
+ ( μ)
+ ( action-Monoid-With-Left-Semiring-Action R M r x)
+ is-left-linear-combination-action-Semiring r x (u , refl) =
+ ( mul-left-linear-combination-Semiring R r u ,
+ preserves-mul-ev-left-linear-combination-Semiring r u)
+```
diff --git a/src/ring-theory/linear-combinations-of-elements-rings.lagda.md b/src/ring-theory/linear-combinations-of-elements-rings.lagda.md
new file mode 100644
index 0000000000..dd8dce8017
--- /dev/null
+++ b/src/ring-theory/linear-combinations-of-elements-rings.lagda.md
@@ -0,0 +1,200 @@
+# Linear combinations with respect to rings
+
+```agda
+module ring-theory.linear-combinations-of-elements-rings where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.sets
+open import foundation.universe-levels
+
+open import ring-theory.rings
+open import ring-theory.subsets-rings
+
+open import lists.lists
+
+open import structured-types.magmas
+```
+
+
+
+## Idea
+
+Consider a [ring](ring-theory.rings.md) $R$ and a type $A$. A {#concept "linear combination"}} of elements of $A$ is a [list](lists.lists.md) of pairs $(r,a,s)$ consisting of an element $r,s:R$ and an element $a:A$.
+
+Furthermore, if we are given an action $\mu : R \to A \to R \to M$ taking values in a [unital magma](structured-types.magmas.md) $(M,+,0)$, then we can evaluate a linear combination $((r_0,a_0,s_0),\ldots,(r_{n-1},a_{n-1},s_{n-1}))$ by defining
+
+$$
+ ev((r_0,a_0,s_0),\ldots,(r_{n-1},a_{n-1},s_{n-1})) :=
+ \sum_{i=0}^{n-1} \mu(r_i,a_i,s_i).
+$$
+
+To be explicit, linear combinations of elements of a type $A$ have the ring coefficients on both sides.
+
+## Definitions
+
+### The type of linear combinations
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (A : UU l2)
+ where
+
+ linear-combination-Ring :
+ UU (l1 ⊔ l2)
+ linear-combination-Ring =
+ list (type-Ring R × A × type-Ring R)
+```
+
+### Evaluating linear combinations of elements in unital magmas
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Ring R → A → type-Ring R → type-Unital-Magma M)
+ where
+
+ ev-linear-combination-Ring :
+ linear-combination-Ring R A → type-Unital-Magma M
+ ev-linear-combination-Ring nil =
+ unit-Unital-Magma M
+ ev-linear-combination-Ring (cons (r , a , s) l) =
+ mul-Unital-Magma M (μ r a s) (ev-linear-combination-Ring l)
+```
+
+### The predicate of being a linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Ring R → A → type-Ring R → type-Unital-Magma M)
+ where
+
+ is-linear-combination-Ring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-linear-combination-Ring =
+ fiber (ev-linear-combination-Ring R M μ)
+```
+
+### The predicate of being a mere linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Ring R → A → type-Ring R → type-Unital-Magma M)
+ where
+
+ is-mere-linear-combination-prop-Ring :
+ type-Unital-Magma M → Prop (l1 ⊔ l2 ⊔ l3)
+ is-mere-linear-combination-prop-Ring x =
+ trunc-Prop (is-linear-combination-Ring R M μ x)
+
+ is-mere-linear-combination-Ring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-mere-linear-combination-Ring x =
+ type-trunc-Prop (is-linear-combination-Ring R M μ x)
+
+ is-prop-is-mere-linear-combination-Ring :
+ (x : type-Unital-Magma M) →
+ is-prop (is-mere-linear-combination-Ring x)
+ is-prop-is-mere-linear-combination-Ring x =
+ is-prop-type-trunc-Prop
+```
+
+### Linear combinations of subsets of a ring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (S : subset-Ring l2 R)
+ where
+
+ linear-combination-subset-Ring :
+ UU (l1 ⊔ l2)
+ linear-combination-subset-Ring =
+ linear-combination-Ring R (type-subset-Ring R S)
+
+ ev-linear-combination-subset-Ring :
+ linear-combination-subset-Ring → type-Ring R
+ ev-linear-combination-subset-Ring =
+ ev-linear-combination-Ring R
+ ( additive-unital-magma-Ring R)
+ ( λ r s →
+ mul-Ring R (mul-Ring R r (inclusion-subset-Ring R S s)))
+
+ is-linear-combination-subset-Ring :
+ type-Ring R → UU (l1 ⊔ l2)
+ is-linear-combination-subset-Ring =
+ is-linear-combination-Ring R
+ ( additive-unital-magma-Ring R)
+ ( λ r s →
+ mul-Ring R (mul-Ring R r (inclusion-subset-Ring R S s)))
+```
+
+### Linear combinations of families of elements in a ring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) {I : UU l2} (a : I → type-Ring R)
+ where
+
+ linear-combination-family-of-elements-Ring :
+ UU (l1 ⊔ l2)
+ linear-combination-family-of-elements-Ring =
+ linear-combination-subset-Ring R (trunc-Prop ∘ fiber a)
+
+ ev-linear-combination-family-of-elements-Ring :
+ linear-combination-family-of-elements-Ring → type-Ring R
+ ev-linear-combination-family-of-elements-Ring =
+ ev-linear-combination-subset-Ring R
+ ( trunc-Prop ∘ fiber a)
+
+ is-linear-combination-family-of-elements-Ring :
+ type-Ring R → UU (l1 ⊔ l2)
+ is-linear-combination-family-of-elements-Ring =
+ is-linear-combination-subset-Ring R
+ ( trunc-Prop ∘ fiber a)
+```
+
+### Linear combinations of a single element in a ring
+
+Even though left linear combinations and right linear combinations of a single element $a$ in a ring $R$ can always be written in the form $(r,a)$ or $(a,r)$, resepectively, i.e., any element of the form $r_0a + \cdots + r_{n-1}a$ is equal to an element of the form $ra$ and similar for right linear combinations, the two-sided case is a bit different in that there might be rings in which an element of the form
+
+$$
+ r_0as_0 + \cdots + r_{n-1}as_{n-1}
+$$
+
+is not equal to an element of the form $ras$, because the distributivity laws don't apply in this more general case.
+
+```agda
+module _
+ {l1 : Level} (R : Ring l1) (a : type-Ring R)
+ where
+
+ linear-combination-element-Ring :
+ UU l1
+ linear-combination-element-Ring =
+ linear-combination-subset-Ring R (λ y → Id-Prop (set-Ring R) y a)
+
+ ev-linear-combination-element-Ring :
+ linear-combination-element-Ring → type-Ring R
+ ev-linear-combination-element-Ring =
+ ev-linear-combination-subset-Ring R
+ ( λ y → Id-Prop (set-Ring R) y a)
+
+ is-linear-combination-element-Ring :
+ type-Ring R → UU l1
+ is-linear-combination-element-Ring =
+ is-linear-combination-subset-Ring R
+ ( λ y → Id-Prop (set-Ring R) y a)
+```
diff --git a/src/ring-theory/linear-combinations-of-elements-semirings.lagda.md b/src/ring-theory/linear-combinations-of-elements-semirings.lagda.md
new file mode 100644
index 0000000000..5bcf5562eb
--- /dev/null
+++ b/src/ring-theory/linear-combinations-of-elements-semirings.lagda.md
@@ -0,0 +1,200 @@
+# Linear combinations with respect to semirings
+
+```agda
+module ring-theory.linear-combinations-of-elements-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.sets
+open import foundation.universe-levels
+
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+
+open import lists.lists
+
+open import structured-types.magmas
+```
+
+
+
+## Idea
+
+Consider a [semiring](ring-theory.semirings.md) $R$ and a type $A$. A {#concept "linear combination"}} of elements of $A$ is a [list](lists.lists.md) of pairs $(r,a,s)$ consisting of an element $r,s:R$ and an element $a:A$.
+
+Furthermore, if we are given an action $\mu : R \to A \to R \to M$ taking values in a [unital magma](structured-types.magmas.md) $(M,+,0)$, then we can evaluate a linear combination $((r_0,a_0,s_0),\ldots,(r_{n-1},a_{n-1},s_{n-1}))$ by defining
+
+$$
+ ev((r_0,a_0,s_0),\ldots,(r_{n-1},a_{n-1},s_{n-1})) :=
+ \sum_{i=0}^{n-1} \mu(r_i,a_i,s_i).
+$$
+
+To be explicit, linear combinations of elements of a type $A$ have the semiring coefficients on both sides.
+
+## Definitions
+
+### The type of linear combinations
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (A : UU l2)
+ where
+
+ linear-combination-Semiring :
+ UU (l1 ⊔ l2)
+ linear-combination-Semiring =
+ list (type-Semiring R × A × type-Semiring R)
+```
+
+### Evaluating linear combinations of elements in unital magmas
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Semiring R → A → type-Semiring R → type-Unital-Magma M)
+ where
+
+ ev-linear-combination-Semiring :
+ linear-combination-Semiring R A → type-Unital-Magma M
+ ev-linear-combination-Semiring nil =
+ unit-Unital-Magma M
+ ev-linear-combination-Semiring (cons (r , a , s) l) =
+ mul-Unital-Magma M (μ r a s) (ev-linear-combination-Semiring l)
+```
+
+### The predicate of being a linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Semiring R → A → type-Semiring R → type-Unital-Magma M)
+ where
+
+ is-linear-combination-Semiring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-linear-combination-Semiring =
+ fiber (ev-linear-combination-Semiring R M μ)
+```
+
+### The predicate of being a mere linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : type-Semiring R → A → type-Semiring R → type-Unital-Magma M)
+ where
+
+ is-mere-linear-combination-prop-Semiring :
+ type-Unital-Magma M → Prop (l1 ⊔ l2 ⊔ l3)
+ is-mere-linear-combination-prop-Semiring x =
+ trunc-Prop (is-linear-combination-Semiring R M μ x)
+
+ is-mere-linear-combination-Semiring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-mere-linear-combination-Semiring x =
+ type-trunc-Prop (is-linear-combination-Semiring R M μ x)
+
+ is-prop-is-mere-linear-combination-Semiring :
+ (x : type-Unital-Magma M) →
+ is-prop (is-mere-linear-combination-Semiring x)
+ is-prop-is-mere-linear-combination-Semiring x =
+ is-prop-type-trunc-Prop
+```
+
+### Linear combinations of subsets of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (S : subset-Semiring l2 R)
+ where
+
+ linear-combination-subset-Semiring :
+ UU (l1 ⊔ l2)
+ linear-combination-subset-Semiring =
+ linear-combination-Semiring R (type-subset-Semiring R S)
+
+ ev-linear-combination-subset-Semiring :
+ linear-combination-subset-Semiring → type-Semiring R
+ ev-linear-combination-subset-Semiring =
+ ev-linear-combination-Semiring R
+ ( additive-unital-magma-Semiring R)
+ ( λ r s →
+ mul-Semiring R (mul-Semiring R r (inclusion-subset-Semiring R S s)))
+
+ is-linear-combination-subset-Semiring :
+ type-Semiring R → UU (l1 ⊔ l2)
+ is-linear-combination-subset-Semiring =
+ is-linear-combination-Semiring R
+ ( additive-unital-magma-Semiring R)
+ ( λ r s →
+ mul-Semiring R (mul-Semiring R r (inclusion-subset-Semiring R S s)))
+```
+
+### Linear combinations of families of elements in a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) {I : UU l2} (a : I → type-Semiring R)
+ where
+
+ linear-combination-family-of-elements-Semiring :
+ UU (l1 ⊔ l2)
+ linear-combination-family-of-elements-Semiring =
+ linear-combination-subset-Semiring R (trunc-Prop ∘ fiber a)
+
+ ev-linear-combination-family-of-elements-Semiring :
+ linear-combination-family-of-elements-Semiring → type-Semiring R
+ ev-linear-combination-family-of-elements-Semiring =
+ ev-linear-combination-subset-Semiring R
+ ( trunc-Prop ∘ fiber a)
+
+ is-linear-combination-family-of-elements-Semiring :
+ type-Semiring R → UU (l1 ⊔ l2)
+ is-linear-combination-family-of-elements-Semiring =
+ is-linear-combination-subset-Semiring R
+ ( trunc-Prop ∘ fiber a)
+```
+
+### Linear combinations of a single element in a semiring
+
+Even though left linear combinations and right linear combinations of a single element $a$ in a semiring $R$ can always be written in the form $(r,a)$ or $(a,r)$, resepectively, i.e., any element of the form $r_0a + \cdots + r_{n-1}a$ is equal to an element of the form $ra$ and similar for right linear combinations, the two-sided case is a bit different in that there might be semirings in which an element of the form
+
+$$
+ r_0as_0 + \cdots + r_{n-1}as_{n-1}
+$$
+
+is not equal to an element of the form $ras$, because the distributivity laws don't apply in this more general case.
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1) (a : type-Semiring R)
+ where
+
+ linear-combination-element-Semiring :
+ UU l1
+ linear-combination-element-Semiring =
+ linear-combination-subset-Semiring R (λ y → Id-Prop (set-Semiring R) y a)
+
+ ev-linear-combination-element-Semiring :
+ linear-combination-element-Semiring → type-Semiring R
+ ev-linear-combination-element-Semiring =
+ ev-linear-combination-subset-Semiring R
+ ( λ y → Id-Prop (set-Semiring R) y a)
+
+ is-linear-combination-element-Semiring :
+ type-Semiring R → UU l1
+ is-linear-combination-element-Semiring =
+ is-linear-combination-subset-Semiring R
+ ( λ y → Id-Prop (set-Semiring R) y a)
+```
diff --git a/src/ring-theory/monoids-with-semiring-actions.lagda.md b/src/ring-theory/monoids-with-semiring-actions.lagda.md
new file mode 100644
index 0000000000..16cc5fabee
--- /dev/null
+++ b/src/ring-theory/monoids-with-semiring-actions.lagda.md
@@ -0,0 +1,207 @@
+# Monoids with semiring actions
+
+```agda
+module ring-theory.monoids-with-semiring-actions where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.identity-types
+open import foundation.sets
+open import foundation.universe-levels
+
+open import group-theory.monoids
+
+open import ring-theory.semirings
+```
+
+
+
+## Idea
+
+Consider a [semiring](ring-theory.semirings.md) $R$.
+A {{#concept "monoid with a left semiring action" Agda=Monoid-With-Left-Semiring-Action}}
+from $R$ consists of a [monoid](group-theory.monoids.md) $M$ and a binary operation $\mu : R \to M \to M$ satisfying the axioms of a ring action:
+
+1. The action distributes from the left over monoid multiplication:
+ $$
+ r(xy) = (rx)(ry).
+ $$
+2. The action distributes from the right over addition in the semiring:
+ $$
+ (r+s)x = (rx)(sx).
+ $$
+3. Associativity of the action
+ $$
+ (sr)x = s(rx).
+ $$
+4. The unit element of the semiring acts as the identity
+ $$
+ 1x = x.
+ $$
+5. The unit element of the monoid absorbs any action
+ $$
+ r1 = 1.
+ $$
+
+## Definitions
+
+### Left actions of semirings on monoids
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (M : Monoid l2)
+ where
+
+ left-action-semiring-Monoid : UU (l1 ⊔ l2)
+ left-action-semiring-Monoid =
+ Σ ( type-Semiring R → type-Monoid M → type-Monoid M)
+ ( λ μ →
+ ( (r : type-Semiring R) (x y : type-Monoid M) →
+ μ r (mul-Monoid M x y) = mul-Monoid M (μ r x) (μ r y)) ×
+ ( (r s : type-Semiring R) (x : type-Monoid M) →
+ μ (add-Semiring R r s) x = mul-Monoid M (μ r x) (μ s x)) ×
+ ( (s r : type-Semiring R) (x : type-Monoid M) →
+ μ (mul-Semiring R s r) x = μ s (μ r x)) ×
+ ( (x : type-Monoid M) → μ (one-Semiring R) x = x) ×
+ ( (r : type-Semiring R) → μ r (unit-Monoid M) = unit-Monoid M))
+```
+
+### Monoids with left semiring actions
+
+```agda
+Monoid-With-Left-Semiring-Action :
+ {l1 : Level} (l2 : Level) (R : Semiring l1) → UU (l1 ⊔ lsuc l2)
+Monoid-With-Left-Semiring-Action l2 R =
+ Σ ( Monoid l2) (left-action-semiring-Monoid R)
+
+module _
+ {l1 l2 : Level} (R : Semiring l1) (M : Monoid-With-Left-Semiring-Action l2 R)
+ where
+
+ monoid-Monoid-With-Left-Semiring-Action :
+ Monoid l2
+ monoid-Monoid-With-Left-Semiring-Action =
+ pr1 M
+
+ set-Monoid-With-Left-Semiring-Action :
+ Set l2
+ set-Monoid-With-Left-Semiring-Action =
+ set-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ type-Monoid-With-Left-Semiring-Action :
+ UU l2
+ type-Monoid-With-Left-Semiring-Action =
+ type-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ is-set-type-Monoid-With-Left-Semiring-Action :
+ is-set type-Monoid-With-Left-Semiring-Action
+ is-set-type-Monoid-With-Left-Semiring-Action =
+ is-set-type-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ mul-Monoid-With-Left-Semiring-Action :
+ (x y : type-Monoid-With-Left-Semiring-Action) → type-Monoid-With-Left-Semiring-Action
+ mul-Monoid-With-Left-Semiring-Action =
+ mul-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ associative-mul-Monoid-With-Left-Semiring-Action :
+ (x y z : type-Monoid-With-Left-Semiring-Action) →
+ mul-Monoid-With-Left-Semiring-Action (mul-Monoid-With-Left-Semiring-Action x y) z =
+ mul-Monoid-With-Left-Semiring-Action x (mul-Monoid-With-Left-Semiring-Action y z)
+ associative-mul-Monoid-With-Left-Semiring-Action =
+ associative-mul-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ unit-Monoid-With-Left-Semiring-Action :
+ type-Monoid-With-Left-Semiring-Action
+ unit-Monoid-With-Left-Semiring-Action =
+ unit-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ left-unit-law-mul-Monoid-With-Left-Semiring-Action :
+ (x : type-Monoid-With-Left-Semiring-Action) →
+ mul-Monoid-With-Left-Semiring-Action
+ ( unit-Monoid-With-Left-Semiring-Action)
+ ( x) =
+ x
+ left-unit-law-mul-Monoid-With-Left-Semiring-Action =
+ left-unit-law-mul-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ right-unit-law-mul-Monoid-With-Left-Semiring-Action :
+ (x : type-Monoid-With-Left-Semiring-Action) →
+ mul-Monoid-With-Left-Semiring-Action
+ ( x)
+ ( unit-Monoid-With-Left-Semiring-Action) =
+ ( x)
+ right-unit-law-mul-Monoid-With-Left-Semiring-Action =
+ right-unit-law-mul-Monoid monoid-Monoid-With-Left-Semiring-Action
+
+ action-Monoid-With-Left-Semiring-Action :
+ type-Semiring R → type-Monoid-With-Left-Semiring-Action →
+ type-Monoid-With-Left-Semiring-Action
+ action-Monoid-With-Left-Semiring-Action =
+ pr1 (pr2 M)
+
+ left-distributive-action-mul-Monoid-With-Left-Semiring-Action :
+ (r : type-Semiring R) (x y : type-Monoid-With-Left-Semiring-Action) →
+ action-Monoid-With-Left-Semiring-Action r
+ ( mul-Monoid-With-Left-Semiring-Action x y) =
+ mul-Monoid-With-Left-Semiring-Action
+ ( action-Monoid-With-Left-Semiring-Action r x)
+ ( action-Monoid-With-Left-Semiring-Action r y)
+ left-distributive-action-mul-Monoid-With-Left-Semiring-Action =
+ pr1 (pr2 (pr2 M))
+
+ right-distributive-action-add-Monoid-With-Left-Semiring-Action :
+ (r s : type-Semiring R) (x : type-Monoid-With-Left-Semiring-Action) →
+ action-Monoid-With-Left-Semiring-Action (add-Semiring R r s) x =
+ mul-Monoid-With-Left-Semiring-Action
+ ( action-Monoid-With-Left-Semiring-Action r x)
+ ( action-Monoid-With-Left-Semiring-Action s x)
+ right-distributive-action-add-Monoid-With-Left-Semiring-Action =
+ pr1 (pr2 (pr2 (pr2 M)))
+
+ associative-action-Monoid-With-Left-Semiring-Action :
+ (s r : type-Semiring R) (x : type-Monoid-With-Left-Semiring-Action) →
+ action-Monoid-With-Left-Semiring-Action (mul-Semiring R s r) x =
+ action-Monoid-With-Left-Semiring-Action s
+ ( action-Monoid-With-Left-Semiring-Action r x)
+ associative-action-Monoid-With-Left-Semiring-Action =
+ pr1 (pr2 (pr2 (pr2 (pr2 M))))
+
+ left-unit-law-action-Monoid-With-Left-Semiring-Action :
+ (x : type-Monoid-With-Left-Semiring-Action) →
+ action-Monoid-With-Left-Semiring-Action (one-Semiring R) x = x
+ left-unit-law-action-Monoid-With-Left-Semiring-Action =
+ pr1 (pr2 (pr2 (pr2 (pr2 (pr2 M)))))
+
+ right-absorption-law-action-Monoid-With-Left-Semiring-Action :
+ (r : type-Semiring R) →
+ action-Monoid-With-Left-Semiring-Action r
+ ( unit-Monoid-With-Left-Semiring-Action) =
+ unit-Monoid-With-Left-Semiring-Action
+ right-absorption-law-action-Monoid-With-Left-Semiring-Action =
+ pr2 (pr2 (pr2 (pr2 (pr2 (pr2 M)))))
+```
+
+## Properties
+
+### The underlying additive monoid of a semiring is a monoid with a left semiring action
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1)
+ where
+
+ additive-monoid-with-left-semiring-action-Semiring :
+ Monoid-With-Left-Semiring-Action l1 R
+ additive-monoid-with-left-semiring-action-Semiring =
+ ( additive-monoid-Semiring R ,
+ mul-Semiring R ,
+ left-distributive-mul-add-Semiring R ,
+ right-distributive-mul-add-Semiring R ,
+ associative-mul-Semiring R ,
+ left-unit-law-mul-Semiring R ,
+ right-zero-law-mul-Semiring R)
+```
diff --git a/src/ring-theory/poset-of-left-ideals-semirings.lagda.md b/src/ring-theory/poset-of-left-ideals-semirings.lagda.md
new file mode 100644
index 0000000000..d1f2c3de0b
--- /dev/null
+++ b/src/ring-theory/poset-of-left-ideals-semirings.lagda.md
@@ -0,0 +1,178 @@
+# The poset of left ideals of a semiring
+
+```agda
+module ring-theory.poset-of-left-ideals-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.binary-relations
+open import foundation.dependent-pair-types
+open import foundation.identity-types
+open import foundation.powersets
+open import foundation.propositions
+open import foundation.subtypes
+open import foundation.universe-levels
+
+open import order-theory.large-posets
+open import order-theory.large-preorders
+open import order-theory.order-preserving-maps-large-posets
+open import order-theory.order-preserving-maps-large-preorders
+open import order-theory.similarity-of-elements-large-posets
+
+open import ring-theory.left-ideals-semirings
+open import ring-theory.semirings
+```
+
+
+
+## Idea
+
+The [left ideals](ring-theory.left-ideals-semirings.md) of a
+[semiring](ring-theory.semirings.md) form a [large poset](order-theory.large-posets.md)
+ordered by inclusion.
+
+## Definition
+
+### The inclusion relation on left ideals
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1)
+ where
+
+ leq-prop-left-ideal-Semiring :
+ {l2 l3 : Level} →
+ left-ideal-Semiring l2 R → left-ideal-Semiring l3 R → Prop (l1 ⊔ l2 ⊔ l3)
+ leq-prop-left-ideal-Semiring I J =
+ leq-prop-subtype
+ ( subset-left-ideal-Semiring R I)
+ ( subset-left-ideal-Semiring R J)
+
+ leq-left-ideal-Semiring :
+ {l2 l3 : Level} →
+ left-ideal-Semiring l2 R → left-ideal-Semiring l3 R → UU (l1 ⊔ l2 ⊔ l3)
+ leq-left-ideal-Semiring I J =
+ subset-left-ideal-Semiring R I ⊆ subset-left-ideal-Semiring R J
+
+ is-prop-leq-left-ideal-Semiring :
+ {l2 l3 : Level}
+ (I : left-ideal-Semiring l2 R) (J : left-ideal-Semiring l3 R) →
+ is-prop (leq-left-ideal-Semiring I J)
+ is-prop-leq-left-ideal-Semiring I J =
+ is-prop-leq-subtype
+ ( subset-left-ideal-Semiring R I)
+ ( subset-left-ideal-Semiring R J)
+
+ refl-leq-left-ideal-Semiring :
+ {l2 : Level} → is-reflexive (leq-left-ideal-Semiring {l2})
+ refl-leq-left-ideal-Semiring I =
+ refl-leq-subtype (subset-left-ideal-Semiring R I)
+
+ transitive-leq-left-ideal-Semiring :
+ {l2 l3 l4 : Level}
+ (I : left-ideal-Semiring l2 R)
+ (J : left-ideal-Semiring l3 R)
+ (K : left-ideal-Semiring l4 R) →
+ leq-left-ideal-Semiring J K →
+ leq-left-ideal-Semiring I J →
+ leq-left-ideal-Semiring I K
+ transitive-leq-left-ideal-Semiring I J K =
+ transitive-leq-subtype
+ ( subset-left-ideal-Semiring R I)
+ ( subset-left-ideal-Semiring R J)
+ ( subset-left-ideal-Semiring R K)
+
+ antisymmetric-leq-left-ideal-Semiring :
+ {l2 : Level} → is-antisymmetric (leq-left-ideal-Semiring {l2})
+ antisymmetric-leq-left-ideal-Semiring I J U V =
+ eq-has-same-elements-left-ideal-Semiring R I J (λ x → U x , V x)
+```
+
+### The large poset of left ideals
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1)
+ where
+
+ left-ideal-Semiring-Large-Preorder :
+ Large-Preorder (λ l2 → l1 ⊔ lsuc l2) (λ l2 l3 → l1 ⊔ l2 ⊔ l3)
+ type-Large-Preorder left-ideal-Semiring-Large-Preorder l =
+ left-ideal-Semiring l R
+ leq-prop-Large-Preorder left-ideal-Semiring-Large-Preorder =
+ leq-prop-left-ideal-Semiring R
+ refl-leq-Large-Preorder left-ideal-Semiring-Large-Preorder =
+ refl-leq-left-ideal-Semiring R
+ transitive-leq-Large-Preorder left-ideal-Semiring-Large-Preorder =
+ transitive-leq-left-ideal-Semiring R
+
+ left-ideal-Semiring-Large-Poset :
+ Large-Poset (λ l2 → l1 ⊔ lsuc l2) (λ l2 l3 → l1 ⊔ l2 ⊔ l3)
+ large-preorder-Large-Poset left-ideal-Semiring-Large-Poset =
+ left-ideal-Semiring-Large-Preorder
+ antisymmetric-leq-Large-Poset left-ideal-Semiring-Large-Poset =
+ antisymmetric-leq-left-ideal-Semiring R
+```
+
+### The similarity relation on left ideals in a semiring
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1)
+ where
+
+ sim-prop-left-ideal-Semiring :
+ {l2 l3 : Level}
+ (I : left-ideal-Semiring l2 R) (J : left-ideal-Semiring l3 R) →
+ Prop (l1 ⊔ l2 ⊔ l3)
+ sim-prop-left-ideal-Semiring =
+ sim-prop-Large-Poset (left-ideal-Semiring-Large-Poset R)
+
+ sim-left-ideal-Semiring :
+ {l2 l3 : Level}
+ (I : left-ideal-Semiring l2 R) (J : left-ideal-Semiring l3 R) →
+ UU (l1 ⊔ l2 ⊔ l3)
+ sim-left-ideal-Semiring = sim-Large-Poset (left-ideal-Semiring-Large-Poset R)
+
+ is-prop-sim-left-ideal-Semiring :
+ {l2 l3 : Level}
+ (I : left-ideal-Semiring l2 R) (J : left-ideal-Semiring l3 R) →
+ is-prop (sim-left-ideal-Semiring I J)
+ is-prop-sim-left-ideal-Semiring =
+ is-prop-sim-Large-Poset (left-ideal-Semiring-Large-Poset R)
+
+ eq-sim-left-ideal-Semiring :
+ {l2 : Level}
+ (I J : left-ideal-Semiring l2 R) → sim-left-ideal-Semiring I J → I = J
+ eq-sim-left-ideal-Semiring = eq-sim-Large-Poset (left-ideal-Semiring-Large-Poset R)
+```
+
+## Properties
+
+### The forgetful function from left ideals to subsets preserves inclusions
+
+```agda
+module _
+ {l : Level} (R : Semiring l)
+ where
+
+ preserves-order-subset-left-ideal-Semiring :
+ {l1 l2 : Level}
+ (I : left-ideal-Semiring l1 R) (J : left-ideal-Semiring l2 R) →
+ leq-left-ideal-Semiring R I J →
+ subset-left-ideal-Semiring R I ⊆ subset-left-ideal-Semiring R J
+ preserves-order-subset-left-ideal-Semiring I J H = H
+
+ subset-left-ideal-hom-large-poset-Semiring :
+ hom-Large-Poset
+ ( λ l → l)
+ ( left-ideal-Semiring-Large-Poset R)
+ ( powerset-Large-Poset (type-Semiring R))
+ map-hom-Large-Preorder subset-left-ideal-hom-large-poset-Semiring =
+ subset-left-ideal-Semiring R
+ preserves-order-hom-Large-Preorder
+ subset-left-ideal-hom-large-poset-Semiring =
+ preserves-order-subset-left-ideal-Semiring
+```
diff --git a/src/ring-theory/powers-of-elements-rings.lagda.md b/src/ring-theory/powers-of-elements-rings.lagda.md
index e7a4956cc4..7323ef32e8 100644
--- a/src/ring-theory/powers-of-elements-rings.lagda.md
+++ b/src/ring-theory/powers-of-elements-rings.lagda.md
@@ -39,6 +39,18 @@ power-Ring R = power-Semiring (semiring-Ring R)
## Properties
+### `0ⁿ⁺¹ = 0`
+
+```agda
+module _
+ {l : Level} (R : Ring l)
+ where
+
+ power-zero-succ-Ring :
+ (n : ℕ) → power-Ring R (succ-ℕ n) (zero-Ring R) = zero-Ring R
+ power-zero-succ-Ring = power-zero-succ-Semiring (semiring-Ring R)
+```
+
### `xⁿ⁺¹ = xⁿx` and `xⁿ⁺¹ = xxⁿ`
```agda
diff --git a/src/ring-theory/powers-of-elements-semirings.lagda.md b/src/ring-theory/powers-of-elements-semirings.lagda.md
index ca2f29b47c..c7798b6794 100644
--- a/src/ring-theory/powers-of-elements-semirings.lagda.md
+++ b/src/ring-theory/powers-of-elements-semirings.lagda.md
@@ -16,6 +16,7 @@ open import foundation.universe-levels
open import group-theory.powers-of-elements-monoids
+open import ring-theory.homomorphisms-semirings
open import ring-theory.semirings
```
@@ -48,6 +49,21 @@ module _
power-one-Semiring = power-unit-Monoid (multiplicative-monoid-Semiring R)
```
+### `0ⁿ⁺¹ = 0`
+
+```agda
+module _
+ {l : Level} (R : Semiring l)
+ where
+
+ power-zero-succ-Semiring :
+ (n : ℕ) → power-Semiring R (succ-ℕ n) (zero-Semiring R) = zero-Semiring R
+ power-zero-succ-Semiring zero-ℕ = refl
+ power-zero-succ-Semiring (succ-ℕ n) =
+ right-zero-law-mul-Semiring R
+ ( power-Semiring R (succ-ℕ n) (zero-Semiring R))
+```
+
### `xⁿ⁺¹ = xⁿx`
```agda
@@ -145,3 +161,21 @@ module _
power-Semiring R (m *ℕ n) x = power-Semiring R n (power-Semiring R m x)
power-mul-Semiring = power-mul-Monoid (multiplicative-monoid-Semiring R)
```
+
+### Homomorphisms of semirings preserve powers
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (S : Semiring l2) (f : hom-Semiring R S)
+ where
+
+ preserves-powers-hom-Semiring :
+ (n : ℕ) (x : type-Semiring R) →
+ map-hom-Semiring R S f (power-Semiring R n x) =
+ power-Semiring S n (map-hom-Semiring R S f x)
+ preserves-powers-hom-Semiring =
+ preserves-powers-hom-Monoid
+ ( multiplicative-monoid-Semiring R)
+ ( multiplicative-monoid-Semiring S)
+ ( hom-multiplicative-monoid-hom-Semiring R S f)
+```
diff --git a/src/ring-theory/principal-ideals-semirings.lagda.md b/src/ring-theory/principal-ideals-semirings.lagda.md
new file mode 100644
index 0000000000..f06fc3069c
--- /dev/null
+++ b/src/ring-theory/principal-ideals-semirings.lagda.md
@@ -0,0 +1,304 @@
+# Principal ideals of semirings
+
+```agda
+module ring-theory.principal-ideals-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.action-on-identifications-functions
+open import foundation.dependent-pair-types
+open import foundation.existential-quantification
+open import foundation.identity-types
+open import foundation.logical-equivalences
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.sets
+open import foundation.universe-levels
+
+open import ring-theory.ideals-semirings
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+```
+
+
+
+## Idea
+
+An [ideal](ring-theory.semirings.md) $I$ of a [semiring](ring-theory.semirings.md) $R$ is said to be a {{#concept "principal ideal" Disambiguation="semiring" Agda=is-principal-ideal-Semiring}} if there exists an element $a \in I$ so that every element $I$ is a linear combination of $a$s {{#cite golan1999}}. In other words, the ideal $I$ is principal if there exists an element $a$ such that for every element $b$ the [logical equivalence](foundation.logical-equivalences.md)
+
+$$
+ b ∈ I \Leftrightarrow \exists_{(x_1,y_1),\ldots,(x_n,y_n):R^2)} x_1 ay_1+\cdots x_naby_n = b.
+$$
+
+holds.
+
+## Definitions
+
+### The predicate of being a principal left ideal of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : left-ideal-Semiring l2 R)
+ where
+
+ is-principal-left-ideal-Semiring : UU (l1 ⊔ l2)
+ is-principal-left-ideal-Semiring =
+ exists
+ ( type-Semiring R)
+ ( λ a →
+ Π-Prop
+ ( type-Semiring R)
+ ( λ b →
+ iff-Prop
+ ( subset-left-ideal-Semiring R I b)
+ ( ∃ ( type-Semiring R)
+ ( λ x →
+ Id-Prop
+ ( set-Semiring R)
+ ( mul-Semiring R x a)
+ ( b)))))
+```
+
+### The predicate of being a principal right ideal of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : right-ideal-Semiring l2 R)
+ where
+
+ is-principal-right-ideal-Semiring : UU (l1 ⊔ l2)
+ is-principal-right-ideal-Semiring =
+ exists
+ ( type-Semiring R)
+ ( λ a →
+ Π-Prop
+ ( type-Semiring R)
+ ( λ b →
+ iff-Prop
+ ( subset-right-ideal-Semiring R I b)
+ ( ∃ ( type-Semiring R)
+ ( λ y →
+ Id-Prop
+ ( set-Semiring R)
+ ( mul-Semiring R a y)
+ ( b)))))
+```
+
+### The predicate of being a principal ideal of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : ideal-Semiring l2 R)
+ where
+
+ is-principal-ideal-Semiring : UU (l1 ⊔ l2)
+ is-principal-ideal-Semiring =
+ exists
+ ( type-Semiring R)
+ ( λ a →
+ Π-Prop
+ ( type-Semiring R)
+ ( λ b →
+ iff-Prop
+ ( subset-ideal-Semiring R I b)
+ ( ∃ ( type-Semiring R)
+ ( λ x →
+ ∃ ( type-Semiring R)
+ ( λ y →
+ Id-Prop
+ ( set-Semiring R)
+ ( mul-Semiring R (mul-Semiring R x a) y)
+ ( b))))))
+```
+
+### The principal left ideal generated by an element
+
+The principal left ideal generated by an element $a$ consists of all element of the form $xa$.
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1) (a : type-Semiring R)
+ where
+
+ subset-principal-left-ideal-Semiring : subset-Semiring l1 R
+ subset-principal-left-ideal-Semiring b =
+ ∃ ( type-Semiring R)
+ ( λ x → Id-Prop (set-Semiring R) (mul-Semiring R x a) b)
+
+ is-in-principal-left-ideal-Semiring : type-Semiring R → UU l1
+ is-in-principal-left-ideal-Semiring =
+ is-in-subset-Semiring R subset-principal-left-ideal-Semiring
+
+ contains-zero-principal-left-ideal-Semiring :
+ is-in-principal-left-ideal-Semiring (zero-Semiring R)
+ contains-zero-principal-left-ideal-Semiring =
+ intro-exists (zero-Semiring R) (left-zero-law-mul-Semiring R a)
+
+ is-closed-under-addition-principal-left-ideal-Semiring :
+ is-closed-under-addition-subset-Semiring R
+ subset-principal-left-ideal-Semiring
+ is-closed-under-addition-principal-left-ideal-Semiring x y H K =
+ apply-twice-universal-property-trunc-Prop H K
+ ( subset-principal-left-ideal-Semiring (add-Semiring R x y))
+ ( λ (u , p) (v , q) →
+ intro-exists
+ ( add-Semiring R u v)
+ ( right-distributive-mul-add-Semiring R u v a ∙
+ ap-add-Semiring R p q))
+
+ is-additive-submonoid-principal-left-ideal-Semiring :
+ is-additive-submonoid-Semiring R subset-principal-left-ideal-Semiring
+ pr1 is-additive-submonoid-principal-left-ideal-Semiring =
+ contains-zero-principal-left-ideal-Semiring
+ pr2 is-additive-submonoid-principal-left-ideal-Semiring =
+ is-closed-under-addition-principal-left-ideal-Semiring
+
+ is-closed-under-left-multiplication-principal-left-ideal-Semiring :
+ is-closed-under-left-multiplication-subset-Semiring R
+ subset-principal-left-ideal-Semiring
+ is-closed-under-left-multiplication-principal-left-ideal-Semiring x y H =
+ apply-universal-property-trunc-Prop H
+ ( subset-principal-left-ideal-Semiring (mul-Semiring R x y))
+ ( λ (u , p) →
+ intro-exists
+ ( mul-Semiring R x u)
+ ( associative-mul-Semiring R x u a ∙ ap (mul-Semiring R x) p))
+
+ is-left-ideal-principal-left-ideal-Semiring :
+ is-left-ideal-subset-Semiring R subset-principal-left-ideal-Semiring
+ pr1 is-left-ideal-principal-left-ideal-Semiring =
+ is-additive-submonoid-principal-left-ideal-Semiring
+ pr2 is-left-ideal-principal-left-ideal-Semiring =
+ is-closed-under-left-multiplication-principal-left-ideal-Semiring
+
+ principal-left-ideal-Semiring :
+ left-ideal-Semiring l1 R
+ pr1 principal-left-ideal-Semiring =
+ subset-principal-left-ideal-Semiring
+ pr2 principal-left-ideal-Semiring =
+ is-left-ideal-principal-left-ideal-Semiring
+
+ is-principal-principal-left-ideal-Semiring :
+ is-principal-left-ideal-Semiring R principal-left-ideal-Semiring
+ is-principal-principal-left-ideal-Semiring =
+ intro-exists a (λ b → id-iff)
+```
+
+### The principal right ideal generated by an element
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1) (a : type-Semiring R)
+ where
+
+ subset-principal-right-ideal-Semiring : subset-Semiring l1 R
+ subset-principal-right-ideal-Semiring b =
+ ∃ ( type-Semiring R)
+ ( λ x → Id-Prop (set-Semiring R) (mul-Semiring R a x) b)
+
+ is-in-principal-right-ideal-Semiring : type-Semiring R → UU l1
+ is-in-principal-right-ideal-Semiring =
+ is-in-subset-Semiring R subset-principal-right-ideal-Semiring
+
+ contains-zero-principal-right-ideal-Semiring :
+ is-in-principal-right-ideal-Semiring (zero-Semiring R)
+ contains-zero-principal-right-ideal-Semiring =
+ intro-exists (zero-Semiring R) (right-zero-law-mul-Semiring R a)
+
+ is-closed-under-addition-principal-right-ideal-Semiring :
+ is-closed-under-addition-subset-Semiring R
+ subset-principal-right-ideal-Semiring
+ is-closed-under-addition-principal-right-ideal-Semiring x y H K =
+ apply-twice-universal-property-trunc-Prop H K
+ ( subset-principal-right-ideal-Semiring (add-Semiring R x y))
+ ( λ (u , p) (v , q) →
+ intro-exists
+ ( add-Semiring R u v)
+ ( left-distributive-mul-add-Semiring R a u v ∙
+ ap-add-Semiring R p q))
+
+ is-additive-submonoid-principal-right-ideal-Semiring :
+ is-additive-submonoid-Semiring R subset-principal-right-ideal-Semiring
+ pr1 is-additive-submonoid-principal-right-ideal-Semiring =
+ contains-zero-principal-right-ideal-Semiring
+ pr2 is-additive-submonoid-principal-right-ideal-Semiring =
+ is-closed-under-addition-principal-right-ideal-Semiring
+
+ is-closed-under-right-multiplication-principal-right-ideal-Semiring :
+ is-closed-under-right-multiplication-subset-Semiring R
+ subset-principal-right-ideal-Semiring
+ is-closed-under-right-multiplication-principal-right-ideal-Semiring x y H =
+ apply-universal-property-trunc-Prop H
+ ( subset-principal-right-ideal-Semiring (mul-Semiring R x y))
+ ( λ (u , p) →
+ intro-exists
+ ( mul-Semiring R u y)
+ ( inv (associative-mul-Semiring R a u y) ∙ ap (mul-Semiring' R y) p))
+
+ is-right-ideal-principal-right-ideal-Semiring :
+ is-right-ideal-subset-Semiring R subset-principal-right-ideal-Semiring
+ pr1 is-right-ideal-principal-right-ideal-Semiring =
+ is-additive-submonoid-principal-right-ideal-Semiring
+ pr2 is-right-ideal-principal-right-ideal-Semiring =
+ is-closed-under-right-multiplication-principal-right-ideal-Semiring
+
+ principal-right-ideal-Semiring :
+ right-ideal-Semiring l1 R
+ pr1 principal-right-ideal-Semiring =
+ subset-principal-right-ideal-Semiring
+ pr2 principal-right-ideal-Semiring =
+ is-right-ideal-principal-right-ideal-Semiring
+
+ is-principal-principal-right-ideal-Semiring :
+ is-principal-right-ideal-Semiring R principal-right-ideal-Semiring
+ is-principal-principal-right-ideal-Semiring =
+ intro-exists a (λ b → id-iff)
+```
+
+### The principal ideal generated by an element
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1) (a : type-Semiring R)
+ where
+
+ subset-principal-ideal-Semiring : subset-Semiring l1 R
+ subset-principal-ideal-Semiring b =
+ ∃ ( type-Semiring R)
+ ( λ x →
+ ∃ ( type-Semiring R)
+ ( λ y →
+ Id-Prop (set-Semiring R) (mul-Semiring R (mul-Semiring R x a) y) b))
+
+ is-in-principal-ideal-Semiring : type-Semiring R → UU l1
+ is-in-principal-ideal-Semiring =
+ is-in-subset-Semiring R subset-principal-ideal-Semiring
+
+ contains-zero-principal-ideal-Semiring :
+ is-in-principal-ideal-Semiring (zero-Semiring R)
+ contains-zero-principal-ideal-Semiring =
+ intro-exists
+ ( zero-Semiring R)
+ ( intro-exists
+ ( zero-Semiring R)
+ ( right-zero-law-mul-Semiring R (mul-Semiring R (zero-Semiring R) a)))
+
+ is-closed-under-addition-principal-ideal-Semiring :
+ is-closed-under-addition-subset-Semiring R
+ subset-principal-ideal-Semiring
+ is-closed-under-addition-principal-ideal-Semiring x y H K =
+ apply-twice-universal-property-trunc-Prop H K
+ ( subset-principal-ideal-Semiring (add-Semiring R x y))
+ ( λ (u , H') (v , K') →
+ apply-twice-universal-property-trunc-Prop H' K'
+ ( subset-principal-ideal-Semiring (add-Semiring R x y))
+ ( λ (s , p) (t , q) →
+ {!!}))
+
+```
+
+## References
+
+{{#bibliography}}
diff --git a/src/ring-theory/products-ideals-rings.lagda.md b/src/ring-theory/products-ideals-rings.lagda.md
index 73cb6e9253..b63eb9886c 100644
--- a/src/ring-theory/products-ideals-rings.lagda.md
+++ b/src/ring-theory/products-ideals-rings.lagda.md
@@ -113,13 +113,13 @@ module _
(L : ideal-Ring l5 A)
where
- preserves-leq-product-ideal-Ring :
+ preserves-order-product-ideal-Ring :
leq-ideal-Ring A I J →
leq-ideal-Ring A K L →
leq-ideal-Ring A
( product-ideal-Ring A I K)
( product-ideal-Ring A J L)
- preserves-leq-product-ideal-Ring p q =
+ preserves-order-product-ideal-Ring p q =
is-product-product-ideal-Ring A I K
( product-ideal-Ring A J L)
( λ x y u v →
@@ -134,21 +134,21 @@ module _
(K : ideal-Ring l4 A)
where
- preserves-leq-left-product-ideal-Ring :
+ preserves-order-left-product-ideal-Ring :
leq-ideal-Ring A I J →
leq-ideal-Ring A
( product-ideal-Ring A I K)
( product-ideal-Ring A J K)
- preserves-leq-left-product-ideal-Ring p =
- preserves-leq-product-ideal-Ring A I J K K p
+ preserves-order-left-product-ideal-Ring p =
+ preserves-order-product-ideal-Ring A I J K K p
( refl-leq-ideal-Ring A K)
- preserves-leq-right-product-ideal-Ring :
+ preserves-order-right-product-ideal-Ring :
leq-ideal-Ring A J K →
leq-ideal-Ring A
( product-ideal-Ring A I J)
( product-ideal-Ring A I K)
- preserves-leq-right-product-ideal-Ring =
- preserves-leq-product-ideal-Ring A I I J K
+ preserves-order-right-product-ideal-Ring =
+ preserves-order-product-ideal-Ring A I I J K
( refl-leq-ideal-Ring A I)
```
diff --git a/src/ring-theory/products-left-ideals-rings.lagda.md b/src/ring-theory/products-left-ideals-rings.lagda.md
index 553c0eacf9..e4655f1c4e 100644
--- a/src/ring-theory/products-left-ideals-rings.lagda.md
+++ b/src/ring-theory/products-left-ideals-rings.lagda.md
@@ -118,13 +118,13 @@ module _
(L : left-ideal-Ring l5 A)
where
- preserves-leq-product-left-ideal-Ring :
+ preserves-order-product-left-ideal-Ring :
leq-left-ideal-Ring A I J →
leq-left-ideal-Ring A K L →
leq-left-ideal-Ring A
( product-left-ideal-Ring A I K)
( product-left-ideal-Ring A J L)
- preserves-leq-product-left-ideal-Ring p q =
+ preserves-order-product-left-ideal-Ring p q =
is-product-product-left-ideal-Ring A I K
( product-left-ideal-Ring A J L)
( λ x y u v →
@@ -139,21 +139,21 @@ module _
(K : left-ideal-Ring l4 A)
where
- preserves-leq-left-product-left-ideal-Ring :
+ preserves-order-left-product-left-ideal-Ring :
leq-left-ideal-Ring A I J →
leq-left-ideal-Ring A
( product-left-ideal-Ring A I K)
( product-left-ideal-Ring A J K)
- preserves-leq-left-product-left-ideal-Ring p =
- preserves-leq-product-left-ideal-Ring A I J K K p
+ preserves-order-left-product-left-ideal-Ring p =
+ preserves-order-product-left-ideal-Ring A I J K K p
( refl-leq-left-ideal-Ring A K)
- preserves-leq-right-product-left-ideal-Ring :
+ preserves-order-right-product-left-ideal-Ring :
leq-left-ideal-Ring A J K →
leq-left-ideal-Ring A
( product-left-ideal-Ring A I J)
( product-left-ideal-Ring A I K)
- preserves-leq-right-product-left-ideal-Ring =
- preserves-leq-product-left-ideal-Ring A I I J K
+ preserves-order-right-product-left-ideal-Ring =
+ preserves-order-product-left-ideal-Ring A I I J K
( refl-leq-left-ideal-Ring A I)
```
diff --git a/src/ring-theory/products-right-ideals-rings.lagda.md b/src/ring-theory/products-right-ideals-rings.lagda.md
index 22cf1b4cfe..cf6227ccc1 100644
--- a/src/ring-theory/products-right-ideals-rings.lagda.md
+++ b/src/ring-theory/products-right-ideals-rings.lagda.md
@@ -118,13 +118,13 @@ module _
(L : right-ideal-Ring l5 A)
where
- preserves-leq-product-right-ideal-Ring :
+ preserves-order-product-right-ideal-Ring :
leq-right-ideal-Ring A I J →
leq-right-ideal-Ring A K L →
leq-right-ideal-Ring A
( product-right-ideal-Ring A I K)
( product-right-ideal-Ring A J L)
- preserves-leq-product-right-ideal-Ring p q =
+ preserves-order-product-right-ideal-Ring p q =
is-product-product-right-ideal-Ring A I K
( product-right-ideal-Ring A J L)
( λ x y u v →
@@ -139,21 +139,21 @@ module _
(K : right-ideal-Ring l4 A)
where
- preserves-leq-left-product-right-ideal-Ring :
+ preserves-order-left-product-right-ideal-Ring :
leq-right-ideal-Ring A I J →
leq-right-ideal-Ring A
( product-right-ideal-Ring A I K)
( product-right-ideal-Ring A J K)
- preserves-leq-left-product-right-ideal-Ring p =
- preserves-leq-product-right-ideal-Ring A I J K K p
+ preserves-order-left-product-right-ideal-Ring p =
+ preserves-order-product-right-ideal-Ring A I J K K p
( refl-leq-right-ideal-Ring A K)
- preserves-leq-right-product-right-ideal-Ring :
+ preserves-order-right-product-right-ideal-Ring :
leq-right-ideal-Ring A J K →
leq-right-ideal-Ring A
( product-right-ideal-Ring A I J)
( product-right-ideal-Ring A I K)
- preserves-leq-right-product-right-ideal-Ring =
- preserves-leq-product-right-ideal-Ring A I I J K
+ preserves-order-right-product-right-ideal-Ring =
+ preserves-order-product-right-ideal-Ring A I I J K
( refl-leq-right-ideal-Ring A I)
```
diff --git a/src/ring-theory/right-ideals-semirings.lagda.md b/src/ring-theory/right-ideals-semirings.lagda.md
new file mode 100644
index 0000000000..48f392a530
--- /dev/null
+++ b/src/ring-theory/right-ideals-semirings.lagda.md
@@ -0,0 +1,195 @@
+# Right ideals of semirings
+
+```agda
+module ring-theory.right-ideals-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.equivalences
+open import foundation.fundamental-theorem-of-identity-types
+open import foundation.identity-types
+open import foundation.propositions
+open import foundation.subtype-identity-principle
+open import foundation.subtypes
+open import foundation.torsorial-type-families
+open import foundation.universe-levels
+
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+```
+
+
+
+## Idea
+
+A {{#concept "right ideal" Disambiguation="semiring" Agda=right-ideal-Semiring}} in a [semiring](ring-theory.semirings.md) `R` is a right submodule of
+`R`.
+
+## Definitions
+
+### Right ideals
+
+```agda
+module _
+ {l1 : Level} (R : Semiring l1)
+ where
+
+ is-right-ideal-subset-Semiring :
+ {l2 : Level} → subset-Semiring l2 R → UU (l1 ⊔ l2)
+ is-right-ideal-subset-Semiring P =
+ is-additive-submonoid-subset-Semiring R P ×
+ is-closed-under-right-multiplication-subset-Semiring R P
+
+ is-prop-is-right-ideal-subset-Semiring :
+ {l2 : Level} (S : subset-Semiring l2 R) →
+ is-prop (is-right-ideal-subset-Semiring S)
+ is-prop-is-right-ideal-subset-Semiring S =
+ is-prop-product
+ ( is-prop-is-additive-submonoid-subset-Semiring R S)
+ ( is-prop-is-closed-under-right-multiplication-subset-Semiring R S)
+
+right-ideal-Semiring :
+ (l : Level) {l1 : Level} (R : Semiring l1) → UU (lsuc l ⊔ l1)
+right-ideal-Semiring l R =
+ Σ (subset-Semiring l R) (is-right-ideal-subset-Semiring R)
+
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : right-ideal-Semiring l2 R)
+ where
+
+ subset-right-ideal-Semiring : subset-Semiring l2 R
+ subset-right-ideal-Semiring = pr1 I
+
+ is-in-right-ideal-Semiring : type-Semiring R → UU l2
+ is-in-right-ideal-Semiring x = type-Prop (subset-right-ideal-Semiring x)
+
+ type-right-ideal-Semiring : UU (l1 ⊔ l2)
+ type-right-ideal-Semiring = type-subset-Semiring R subset-right-ideal-Semiring
+
+ inclusion-right-ideal-Semiring :
+ type-right-ideal-Semiring → type-Semiring R
+ inclusion-right-ideal-Semiring =
+ inclusion-subset-Semiring R subset-right-ideal-Semiring
+
+ ap-inclusion-right-ideal-Semiring :
+ (x y : type-right-ideal-Semiring) → x = y →
+ inclusion-right-ideal-Semiring x = inclusion-right-ideal-Semiring y
+ ap-inclusion-right-ideal-Semiring =
+ ap-inclusion-subset-Semiring R subset-right-ideal-Semiring
+
+ is-in-subset-inclusion-right-ideal-Semiring :
+ (x : type-right-ideal-Semiring) →
+ is-in-right-ideal-Semiring (inclusion-right-ideal-Semiring x)
+ is-in-subset-inclusion-right-ideal-Semiring =
+ is-in-subset-inclusion-subset-Semiring R subset-right-ideal-Semiring
+
+ is-closed-under-eq-right-ideal-Semiring :
+ {x y : type-Semiring R} → is-in-right-ideal-Semiring x →
+ (x = y) → is-in-right-ideal-Semiring y
+ is-closed-under-eq-right-ideal-Semiring =
+ is-closed-under-eq-subset-Semiring R subset-right-ideal-Semiring
+
+ is-closed-under-eq-right-ideal-Semiring' :
+ {x y : type-Semiring R} → is-in-right-ideal-Semiring y →
+ (x = y) → is-in-right-ideal-Semiring x
+ is-closed-under-eq-right-ideal-Semiring' =
+ is-closed-under-eq-subset-Semiring' R subset-right-ideal-Semiring
+
+ is-right-ideal-subset-right-ideal-Semiring :
+ is-right-ideal-subset-Semiring R subset-right-ideal-Semiring
+ is-right-ideal-subset-right-ideal-Semiring = pr2 I
+
+ is-additive-submonoid-subset-right-ideal-Semiring :
+ is-additive-submonoid-subset-Semiring R subset-right-ideal-Semiring
+ is-additive-submonoid-subset-right-ideal-Semiring =
+ pr1 is-right-ideal-subset-right-ideal-Semiring
+
+ contains-zero-right-ideal-Semiring :
+ is-in-right-ideal-Semiring (zero-Semiring R)
+ contains-zero-right-ideal-Semiring =
+ pr1 is-additive-submonoid-subset-right-ideal-Semiring
+
+ is-closed-under-addition-right-ideal-Semiring :
+ is-closed-under-addition-subset-Semiring R subset-right-ideal-Semiring
+ is-closed-under-addition-right-ideal-Semiring =
+ pr2 is-additive-submonoid-subset-right-ideal-Semiring
+
+ is-closed-under-right-multiplication-right-ideal-Semiring :
+ is-closed-under-right-multiplication-subset-Semiring R
+ subset-right-ideal-Semiring
+ is-closed-under-right-multiplication-right-ideal-Semiring =
+ pr2 is-right-ideal-subset-right-ideal-Semiring
+
+ is-right-ideal-right-ideal-Semiring :
+ is-right-ideal-subset-Semiring R subset-right-ideal-Semiring
+ is-right-ideal-right-ideal-Semiring = pr2 I
+```
+
+## Properties
+
+### Characterizing equality of right ideals in semirings
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1) (I : right-ideal-Semiring l2 R)
+ where
+
+ has-same-elements-right-ideal-Semiring :
+ (J : right-ideal-Semiring l3 R) → UU (l1 ⊔ l2 ⊔ l3)
+ has-same-elements-right-ideal-Semiring J =
+ has-same-elements-subtype
+ ( subset-right-ideal-Semiring R I)
+ ( subset-right-ideal-Semiring R J)
+
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : right-ideal-Semiring l2 R)
+ where
+
+ refl-has-same-elements-right-ideal-Semiring :
+ has-same-elements-right-ideal-Semiring R I I
+ refl-has-same-elements-right-ideal-Semiring =
+ refl-has-same-elements-subtype (subset-right-ideal-Semiring R I)
+
+ is-torsorial-has-same-elements-right-ideal-Semiring :
+ is-torsorial (has-same-elements-right-ideal-Semiring R I)
+ is-torsorial-has-same-elements-right-ideal-Semiring =
+ is-torsorial-Eq-subtype
+ ( is-torsorial-has-same-elements-subtype
+ ( subset-right-ideal-Semiring R I))
+ ( is-prop-is-right-ideal-subset-Semiring R)
+ ( subset-right-ideal-Semiring R I)
+ ( refl-has-same-elements-right-ideal-Semiring)
+ ( is-right-ideal-right-ideal-Semiring R I)
+
+ has-same-elements-eq-right-ideal-Semiring :
+ (J : right-ideal-Semiring l2 R) →
+ (I = J) → has-same-elements-right-ideal-Semiring R I J
+ has-same-elements-eq-right-ideal-Semiring .I refl =
+ refl-has-same-elements-right-ideal-Semiring
+
+ is-equiv-has-same-elements-eq-right-ideal-Semiring :
+ (J : right-ideal-Semiring l2 R) →
+ is-equiv (has-same-elements-eq-right-ideal-Semiring J)
+ is-equiv-has-same-elements-eq-right-ideal-Semiring =
+ fundamental-theorem-id
+ is-torsorial-has-same-elements-right-ideal-Semiring
+ has-same-elements-eq-right-ideal-Semiring
+
+ extensionality-right-ideal-Semiring :
+ (J : right-ideal-Semiring l2 R) →
+ (I = J) ≃ has-same-elements-right-ideal-Semiring R I J
+ pr1 (extensionality-right-ideal-Semiring J) =
+ has-same-elements-eq-right-ideal-Semiring J
+ pr2 (extensionality-right-ideal-Semiring J) =
+ is-equiv-has-same-elements-eq-right-ideal-Semiring J
+
+ eq-has-same-elements-right-ideal-Semiring :
+ (J : right-ideal-Semiring l2 R) →
+ has-same-elements-right-ideal-Semiring R I J → I = J
+ eq-has-same-elements-right-ideal-Semiring J =
+ map-inv-equiv (extensionality-right-ideal-Semiring J)
+```
diff --git a/src/ring-theory/right-linear-combinations-of-elements-rings.lagda.md b/src/ring-theory/right-linear-combinations-of-elements-rings.lagda.md
new file mode 100644
index 0000000000..1932248150
--- /dev/null
+++ b/src/ring-theory/right-linear-combinations-of-elements-rings.lagda.md
@@ -0,0 +1,163 @@
+# Right linear combinations with respect to rings
+
+```agda
+module ring-theory.right-linear-combinations-of-elements-rings where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.universe-levels
+
+open import ring-theory.rings
+open import ring-theory.subsets-rings
+
+open import lists.lists
+
+open import structured-types.magmas
+```
+
+
+
+## Idea
+
+Consider a [ring](ring-theory.rings.md) $R$ and a type $A$. A {#concept "right linear combination"}} of elements of $R$ is a [list](lists.lists.md) of pairs $(a,r)$ consisting of an element $a:A$ and an element $r:R$.
+
+Furthermore, if we are given an action $\mu : A \to R \to M$ taking values in a [unital magma](structured-types.magmas.md) $(M,+,0)$, then we can evaluate a right linear combination $((a_0,r_0),\ldots,(a_{n-1},r_{n-1}))$ by defining
+
+$$
+ ev((a_0,r_0),\ldots,(a_{n-1},r_{n-1})) := \sum_{i=0}^{n-1} \mu(a_i,r_i).
+$$
+
+To be explicit, right linear combinations of elements of a type $A$ have the ring coefficients on the right.
+
+## Definitions
+
+### The type of right linear combinations
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (A : UU l2)
+ where
+
+ right-linear-combination-Ring :
+ UU (l1 ⊔ l2)
+ right-linear-combination-Ring =
+ list (A × type-Ring R)
+```
+
+### Evaluating right linear combinations of elements in unital magmas
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : A → type-Ring R → type-Unital-Magma M)
+ where
+
+ ev-right-linear-combination-Ring :
+ right-linear-combination-Ring R A → type-Unital-Magma M
+ ev-right-linear-combination-Ring nil =
+ unit-Unital-Magma M
+ ev-right-linear-combination-Ring (cons (a , r) l) =
+ mul-Unital-Magma M (μ a r) (ev-right-linear-combination-Ring l)
+```
+
+### The predicate of being a right linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : A → type-Ring R → type-Unital-Magma M)
+ where
+
+ is-right-linear-combination-Ring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-right-linear-combination-Ring =
+ fiber (ev-right-linear-combination-Ring R M μ)
+```
+
+### The predicate of being a mere right linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Ring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : A → type-Ring R → type-Unital-Magma M)
+ where
+
+ is-mere-right-linear-combination-prop-Ring :
+ type-Unital-Magma M → Prop (l1 ⊔ l2 ⊔ l3)
+ is-mere-right-linear-combination-prop-Ring x =
+ trunc-Prop (is-right-linear-combination-Ring R M μ x)
+
+ is-mere-right-linear-combination-Ring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-mere-right-linear-combination-Ring x =
+ type-trunc-Prop (is-right-linear-combination-Ring R M μ x)
+
+ is-prop-is-mere-right-linear-combination-Ring :
+ (x : type-Unital-Magma M) →
+ is-prop (is-mere-right-linear-combination-Ring x)
+ is-prop-is-mere-right-linear-combination-Ring x =
+ is-prop-type-trunc-Prop
+```
+
+### Right linear combinations of subsets of a ring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (S : subset-Ring l2 R)
+ where
+
+ right-linear-combination-subset-Ring :
+ UU (l1 ⊔ l2)
+ right-linear-combination-subset-Ring =
+ right-linear-combination-Ring R (type-subset-Ring R S)
+
+ ev-right-linear-combination-subset-Ring :
+ right-linear-combination-subset-Ring → type-Ring R
+ ev-right-linear-combination-subset-Ring =
+ ev-right-linear-combination-Ring R
+ ( additive-unital-magma-Ring R)
+ ( λ s → mul-Ring R (inclusion-subset-Ring R S s))
+
+ is-right-linear-combination-subset-Ring :
+ type-Ring R → UU (l1 ⊔ l2)
+ is-right-linear-combination-subset-Ring =
+ is-right-linear-combination-Ring R
+ ( additive-unital-magma-Ring R)
+ ( λ s → mul-Ring R (inclusion-subset-Ring R S s))
+```
+
+### Right linear combinations of families of elements in a ring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) {I : UU l2} (a : I → type-Ring R)
+ where
+
+ right-linear-combination-family-of-elements-Ring :
+ UU (l1 ⊔ l2)
+ right-linear-combination-family-of-elements-Ring =
+ right-linear-combination-subset-Ring R (trunc-Prop ∘ fiber a)
+
+ ev-right-linear-combination-family-of-elements-Ring :
+ right-linear-combination-family-of-elements-Ring → type-Ring R
+ ev-right-linear-combination-family-of-elements-Ring =
+ ev-right-linear-combination-subset-Ring R
+ ( trunc-Prop ∘ fiber a)
+
+ is-right-linear-combination-family-of-elements-Ring :
+ type-Ring R → UU (l1 ⊔ l2)
+ is-right-linear-combination-family-of-elements-Ring =
+ is-right-linear-combination-subset-Ring R
+ ( trunc-Prop ∘ fiber a)
+```
diff --git a/src/ring-theory/right-linear-combinations-of-elements-semirings.lagda.md b/src/ring-theory/right-linear-combinations-of-elements-semirings.lagda.md
new file mode 100644
index 0000000000..3571008e50
--- /dev/null
+++ b/src/ring-theory/right-linear-combinations-of-elements-semirings.lagda.md
@@ -0,0 +1,163 @@
+# Right linear combinations with respect to semirings
+
+```agda
+module ring-theory.right-linear-combinations-of-elements-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.function-types
+open import foundation.propositional-truncations
+open import foundation.propositions
+open import foundation.universe-levels
+
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+
+open import lists.lists
+
+open import structured-types.magmas
+```
+
+
+
+## Idea
+
+Consider a [semiring](ring-theory.semirings.md) $R$ and a type $A$. A {#concept "right linear combination"}} of elements of $R$ is a [list](lists.lists.md) of pairs $(a,r)$ consisting of an element $a:A$ and an element $r:R$.
+
+Furthermore, if we are given an action $\mu : A \to R \to M$ taking values in a [unital magma](structured-types.magmas.md) $(M,+,0)$, then we can evaluate a right linear combination $((a_0,r_0),\ldots,(a_{n-1},r_{n-1}))$ by defining
+
+$$
+ ev((a_0,r_0),\ldots,(a_{n-1},r_{n-1})) := \sum_{i=0}^{n-1} \mu(a_i,r_i).
+$$
+
+To be explicit, right linear combinations of elements of a type $A$ have the semiring coefficients on the right.
+
+## Definitions
+
+### The type of right linear combinations
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (A : UU l2)
+ where
+
+ right-linear-combination-Semiring :
+ UU (l1 ⊔ l2)
+ right-linear-combination-Semiring =
+ list (A × type-Semiring R)
+```
+
+### Evaluating right linear combinations of elements in unital magmas
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : A → type-Semiring R → type-Unital-Magma M)
+ where
+
+ ev-right-linear-combination-Semiring :
+ right-linear-combination-Semiring R A → type-Unital-Magma M
+ ev-right-linear-combination-Semiring nil =
+ unit-Unital-Magma M
+ ev-right-linear-combination-Semiring (cons (a , r) l) =
+ mul-Unital-Magma M (μ a r) (ev-right-linear-combination-Semiring l)
+```
+
+### The predicate of being a right linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : A → type-Semiring R → type-Unital-Magma M)
+ where
+
+ is-right-linear-combination-Semiring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-right-linear-combination-Semiring =
+ fiber (ev-right-linear-combination-Semiring R M μ)
+```
+
+### The predicate of being a mere right linear combination
+
+```agda
+module _
+ {l1 l2 l3 : Level} (R : Semiring l1)
+ {A : UU l2} (M : Unital-Magma l3)
+ (μ : A → type-Semiring R → type-Unital-Magma M)
+ where
+
+ is-mere-right-linear-combination-prop-Semiring :
+ type-Unital-Magma M → Prop (l1 ⊔ l2 ⊔ l3)
+ is-mere-right-linear-combination-prop-Semiring x =
+ trunc-Prop (is-right-linear-combination-Semiring R M μ x)
+
+ is-mere-right-linear-combination-Semiring :
+ type-Unital-Magma M → UU (l1 ⊔ l2 ⊔ l3)
+ is-mere-right-linear-combination-Semiring x =
+ type-trunc-Prop (is-right-linear-combination-Semiring R M μ x)
+
+ is-prop-is-mere-right-linear-combination-Semiring :
+ (x : type-Unital-Magma M) →
+ is-prop (is-mere-right-linear-combination-Semiring x)
+ is-prop-is-mere-right-linear-combination-Semiring x =
+ is-prop-type-trunc-Prop
+```
+
+### Right linear combinations of subsets of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (S : subset-Semiring l2 R)
+ where
+
+ right-linear-combination-subset-Semiring :
+ UU (l1 ⊔ l2)
+ right-linear-combination-subset-Semiring =
+ right-linear-combination-Semiring R (type-subset-Semiring R S)
+
+ ev-right-linear-combination-subset-Semiring :
+ right-linear-combination-subset-Semiring → type-Semiring R
+ ev-right-linear-combination-subset-Semiring =
+ ev-right-linear-combination-Semiring R
+ ( additive-unital-magma-Semiring R)
+ ( λ s → mul-Semiring R (inclusion-subset-Semiring R S s))
+
+ is-right-linear-combination-subset-Semiring :
+ type-Semiring R → UU (l1 ⊔ l2)
+ is-right-linear-combination-subset-Semiring =
+ is-right-linear-combination-Semiring R
+ ( additive-unital-magma-Semiring R)
+ ( λ s → mul-Semiring R (inclusion-subset-Semiring R S s))
+```
+
+### Right linear combinations of families of elements in a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) {I : UU l2} (a : I → type-Semiring R)
+ where
+
+ right-linear-combination-family-of-elements-Semiring :
+ UU (l1 ⊔ l2)
+ right-linear-combination-family-of-elements-Semiring =
+ right-linear-combination-subset-Semiring R (trunc-Prop ∘ fiber a)
+
+ ev-right-linear-combination-family-of-elements-Semiring :
+ right-linear-combination-family-of-elements-Semiring → type-Semiring R
+ ev-right-linear-combination-family-of-elements-Semiring =
+ ev-right-linear-combination-subset-Semiring R
+ ( trunc-Prop ∘ fiber a)
+
+ is-right-linear-combination-family-of-elements-Semiring :
+ type-Semiring R → UU (l1 ⊔ l2)
+ is-right-linear-combination-family-of-elements-Semiring =
+ is-right-linear-combination-subset-Semiring R
+ ( trunc-Prop ∘ fiber a)
+```
diff --git a/src/ring-theory/rings.lagda.md b/src/ring-theory/rings.lagda.md
index 757f7994ee..e1acfb2833 100644
--- a/src/ring-theory/rings.lagda.md
+++ b/src/ring-theory/rings.lagda.md
@@ -39,6 +39,8 @@ open import lists.concatenation-lists
open import lists.lists
open import ring-theory.semirings
+
+open import structured-types.magmas
```
@@ -84,6 +86,9 @@ module _
additive-monoid-Ring : Monoid l
additive-monoid-Ring = monoid-Ab ab-Ring
+ additive-unital-magma-Ring : Unital-Magma l
+ additive-unital-magma-Ring = unital-magma-Monoid additive-monoid-Ring
+
additive-semigroup-Ring : Semigroup l
additive-semigroup-Ring = semigroup-Ab ab-Ring
diff --git a/src/ring-theory/semirings.lagda.md b/src/ring-theory/semirings.lagda.md
index 982869d8d3..7887825593 100644
--- a/src/ring-theory/semirings.lagda.md
+++ b/src/ring-theory/semirings.lagda.md
@@ -24,6 +24,8 @@ open import foundation.universe-levels
open import group-theory.commutative-monoids
open import group-theory.monoids
open import group-theory.semigroups
+
+open import structured-types.magmas
```
@@ -81,6 +83,10 @@ module _
additive-monoid-Semiring =
monoid-Commutative-Monoid additive-commutative-monoid-Semiring
+ additive-unital-magma-Semiring : Unital-Magma l
+ additive-unital-magma-Semiring =
+ unital-magma-Monoid additive-monoid-Semiring
+
additive-semigroup-Semiring : Semigroup l
additive-semigroup-Semiring =
semigroup-Commutative-Monoid additive-commutative-monoid-Semiring
diff --git a/src/ring-theory/subsets-rings.lagda.md b/src/ring-theory/subsets-rings.lagda.md
index df9a3f2c84..3c8e43061f 100644
--- a/src/ring-theory/subsets-rings.lagda.md
+++ b/src/ring-theory/subsets-rings.lagda.md
@@ -7,6 +7,8 @@ module ring-theory.subsets-rings where
Imports
```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
open import foundation.identity-types
open import foundation.propositional-extensionality
open import foundation.propositions
@@ -17,6 +19,7 @@ open import foundation.universe-levels
open import group-theory.subgroups-abelian-groups
open import ring-theory.rings
+open import ring-theory.subsets-semirings
```
@@ -32,33 +35,43 @@ A subset of a ring is a subtype of the underlying type of a ring
```agda
subset-Ring :
(l : Level) {l1 : Level} (R : Ring l1) → UU (lsuc l ⊔ l1)
-subset-Ring l R = subtype l (type-Ring R)
+subset-Ring l R =
+ subset-Semiring l (semiring-Ring R)
is-set-subset-Ring :
(l : Level) {l1 : Level} (R : Ring l1) → is-set (subset-Ring l R)
is-set-subset-Ring l R =
- is-set-function-type is-set-type-Prop
+ is-set-subset-Semiring l (semiring-Ring R)
module _
{l1 l2 : Level} (R : Ring l1) (S : subset-Ring l2 R)
where
- is-in-subset-Ring : type-Ring R → UU l2
- is-in-subset-Ring = is-in-subtype S
+ is-in-subset-Ring :
+ type-Ring R → UU l2
+ is-in-subset-Ring =
+ is-in-subset-Semiring (semiring-Ring R) S
- is-prop-is-in-subset-Ring : (x : type-Ring R) → is-prop (is-in-subset-Ring x)
- is-prop-is-in-subset-Ring = is-prop-is-in-subtype S
+ is-prop-is-in-subset-Ring :
+ (x : type-Ring R) → is-prop (is-in-subset-Ring x)
+ is-prop-is-in-subset-Ring =
+ is-prop-is-in-subset-Semiring (semiring-Ring R) S
- type-subset-Ring : UU (l1 ⊔ l2)
- type-subset-Ring = type-subtype S
+ type-subset-Ring :
+ UU (l1 ⊔ l2)
+ type-subset-Ring =
+ type-subset-Semiring (semiring-Ring R) S
- inclusion-subset-Ring : type-subset-Ring → type-Ring R
- inclusion-subset-Ring = inclusion-subtype S
+ inclusion-subset-Ring :
+ type-subset-Ring → type-Ring R
+ inclusion-subset-Ring =
+ inclusion-subset-Semiring (semiring-Ring R) S
ap-inclusion-subset-Ring :
(x y : type-subset-Ring) →
x = y → (inclusion-subset-Ring x = inclusion-subset-Ring y)
- ap-inclusion-subset-Ring = ap-inclusion-subtype S
+ ap-inclusion-subset-Ring =
+ ap-inclusion-subset-Semiring (semiring-Ring R) S
is-in-subset-inclusion-subset-Ring :
(x : type-subset-Ring) → is-in-subset-Ring (inclusion-subset-Ring x)
@@ -68,12 +81,12 @@ module _
is-closed-under-eq-subset-Ring :
{x y : type-Ring R} → is-in-subset-Ring x → (x = y) → is-in-subset-Ring y
is-closed-under-eq-subset-Ring =
- is-closed-under-eq-subtype S
+ is-closed-under-eq-subset-Semiring (semiring-Ring R) S
is-closed-under-eq-subset-Ring' :
{x y : type-Ring R} → is-in-subset-Ring y → (x = y) → is-in-subset-Ring x
is-closed-under-eq-subset-Ring' =
- is-closed-under-eq-subtype' S
+ is-closed-under-eq-subset-Semiring' (semiring-Ring R) S
```
### The condition that a subset contains zero
@@ -84,14 +97,16 @@ module _
where
contains-zero-subset-Ring : UU l2
- contains-zero-subset-Ring = is-in-subset-Ring R S (zero-Ring R)
+ contains-zero-subset-Ring =
+ contains-zero-subset-Semiring (semiring-Ring R) S
```
### The condition that a subset contains one
```agda
contains-one-subset-Ring : UU l2
- contains-one-subset-Ring = is-in-subset-Ring R S (one-Ring R)
+ contains-one-subset-Ring =
+ contains-one-subset-Semiring (semiring-Ring R) S
```
### The condition that a subset is closed under addition
@@ -99,9 +114,7 @@ module _
```agda
is-closed-under-addition-subset-Ring : UU (l1 ⊔ l2)
is-closed-under-addition-subset-Ring =
- {x y : type-Ring R} →
- is-in-subset-Ring R S x → is-in-subset-Ring R S y →
- is-in-subset-Ring R S (add-Ring R x y)
+ is-closed-under-addition-subset-Semiring (semiring-Ring R) S
```
### The condition that a subset is closed under negatives
@@ -118,58 +131,57 @@ module _
```agda
is-closed-under-multiplication-subset-Ring : UU (l1 ⊔ l2)
is-closed-under-multiplication-subset-Ring =
- (x y : type-Ring R) → is-in-subset-Ring R S x → is-in-subset-Ring R S y →
- is-in-subset-Ring R S (mul-Ring R x y)
+ is-closed-under-multiplication-subset-Semiring (semiring-Ring R) S
```
### The condition that a subset is closed under multiplication from the left by an arbitrary element
```agda
- is-closed-under-left-multiplication-subset-Ring-Prop : Prop (l1 ⊔ l2)
- is-closed-under-left-multiplication-subset-Ring-Prop =
- Π-Prop
- ( type-Ring R)
- ( λ x →
- Π-Prop
- ( type-Ring R)
- ( λ y →
- function-Prop
- ( is-in-subset-Ring R S y)
- ( S (mul-Ring R x y))))
+ is-closed-under-left-multiplication-prop-subset-Ring : Prop (l1 ⊔ l2)
+ is-closed-under-left-multiplication-prop-subset-Ring =
+ is-closed-under-left-multiplication-prop-subset-Semiring
+ ( semiring-Ring R)
+ ( S)
is-closed-under-left-multiplication-subset-Ring : UU (l1 ⊔ l2)
is-closed-under-left-multiplication-subset-Ring =
- type-Prop is-closed-under-left-multiplication-subset-Ring-Prop
+ is-closed-under-left-multiplication-subset-Semiring (semiring-Ring R) S
is-prop-is-closed-under-left-multiplication-subset-Ring :
is-prop is-closed-under-left-multiplication-subset-Ring
is-prop-is-closed-under-left-multiplication-subset-Ring =
- is-prop-type-Prop is-closed-under-left-multiplication-subset-Ring-Prop
+ is-prop-is-closed-under-left-multiplication-subset-Semiring
+ ( semiring-Ring R)
+ ( S)
```
### The condition that a subset is closed-under-multiplication from the right by an arbitrary element
```agda
- is-closed-under-right-multiplication-subset-Ring-Prop : Prop (l1 ⊔ l2)
- is-closed-under-right-multiplication-subset-Ring-Prop =
- Π-Prop
- ( type-Ring R)
- ( λ x →
- Π-Prop
- ( type-Ring R)
- ( λ y →
- function-Prop
- ( is-in-subset-Ring R S x)
- ( S (mul-Ring R x y))))
+ is-closed-under-right-multiplication-prop-subset-Ring : Prop (l1 ⊔ l2)
+ is-closed-under-right-multiplication-prop-subset-Ring =
+ is-closed-under-right-multiplication-prop-subset-Semiring
+ ( semiring-Ring R)
+ ( S)
is-closed-under-right-multiplication-subset-Ring : UU (l1 ⊔ l2)
is-closed-under-right-multiplication-subset-Ring =
- type-Prop is-closed-under-right-multiplication-subset-Ring-Prop
+ is-closed-under-right-multiplication-subset-Semiring (semiring-Ring R) S
is-prop-is-closed-under-right-multiplication-subset-Ring :
is-prop is-closed-under-right-multiplication-subset-Ring
is-prop-is-closed-under-right-multiplication-subset-Ring =
- is-prop-type-Prop is-closed-under-right-multiplication-subset-Ring-Prop
+ is-prop-is-closed-under-right-multiplication-subset-Semiring
+ ( semiring-Ring R)
+ ( S)
+```
+
+### The condition that a subset is an additive submonoid
+
+```agda
+ is-additive-submonoid-subset-Ring : UU (l1 ⊔ l2)
+ is-additive-submonoid-subset-Ring =
+ contains-zero-subset-Ring × is-closed-under-addition-subset-Ring
```
### The condition that a subset is an additive subgroup
@@ -181,7 +193,8 @@ module _
is-additive-subgroup-subset-Ring :
{l2 : Level} → subset-Ring l2 R → UU (l1 ⊔ l2)
- is-additive-subgroup-subset-Ring = is-subgroup-Ab (ab-Ring R)
+ is-additive-subgroup-subset-Ring =
+ is-subgroup-Ab (ab-Ring R)
is-prop-is-additive-subgroup-subset-Ring :
{l2 : Level} (A : subset-Ring l2 R) →
@@ -189,3 +202,61 @@ module _
is-prop-is-additive-subgroup-subset-Ring =
is-prop-is-subgroup-Ab (ab-Ring R)
```
+
+## Properties
+
+### Any subset that is closed under left or right multiplication is closed under negatives
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (S : subset-Ring l2 R)
+ where
+
+ is-closed-under-negatives-is-closed-under-left-multiplication-subset-Ring :
+ is-closed-under-left-multiplication-subset-Ring R S →
+ is-closed-under-negatives-subset-Ring R S
+ is-closed-under-negatives-is-closed-under-left-multiplication-subset-Ring
+ H {x} K =
+ is-closed-under-eq-subset-Ring R S
+ ( H (neg-one-Ring R) x K)
+ ( mul-neg-one-Ring R x)
+
+ is-closed-under-negatives-is-closed-under-right-multiplication-subset-Ring :
+ is-closed-under-right-multiplication-subset-Ring R S →
+ is-closed-under-negatives-subset-Ring R S
+ is-closed-under-negatives-is-closed-under-right-multiplication-subset-Ring
+ H {x} K =
+ is-closed-under-eq-subset-Ring R S
+ ( H x (neg-one-Ring R) K)
+ ( mul-neg-one-Ring' R x)
+```
+
+### Any additive submonoid of a ring that is closed under left or right multiplication is an additive subgroup
+
+```agda
+module _
+ {l1 l2 : Level} (R : Ring l1) (S : subset-Ring l2 R)
+ where
+
+ is-additive-subgroup-is-closed-under-left-multiplication-subset-Ring :
+ is-additive-submonoid-subset-Ring R S →
+ is-closed-under-left-multiplication-subset-Ring R S →
+ is-additive-subgroup-subset-Ring R S
+ is-additive-subgroup-is-closed-under-left-multiplication-subset-Ring
+ (H , K) L =
+ ( H ,
+ K ,
+ is-closed-under-negatives-is-closed-under-left-multiplication-subset-Ring
+ R S L)
+
+ is-additive-subgroup-is-closed-under-right-multiplication-subset-Ring :
+ is-additive-submonoid-subset-Ring R S →
+ is-closed-under-right-multiplication-subset-Ring R S →
+ is-additive-subgroup-subset-Ring R S
+ is-additive-subgroup-is-closed-under-right-multiplication-subset-Ring
+ (H , K) L =
+ ( H ,
+ K ,
+ is-closed-under-negatives-is-closed-under-right-multiplication-subset-Ring
+ R S L)
+```
diff --git a/src/ring-theory/subsets-semirings.lagda.md b/src/ring-theory/subsets-semirings.lagda.md
index 0236a79809..9c80ebe955 100644
--- a/src/ring-theory/subsets-semirings.lagda.md
+++ b/src/ring-theory/subsets-semirings.lagda.md
@@ -7,6 +7,8 @@ module ring-theory.subsets-semirings where
Imports
```agda
+open import foundation.cartesian-product-types
+open import foundation.dependent-pair-types
open import foundation.identity-types
open import foundation.propositional-extensionality
open import foundation.propositions
@@ -87,6 +89,11 @@ module _
contains-zero-subset-Semiring : UU l2
contains-zero-subset-Semiring = is-in-subtype S (zero-Semiring R)
+
+ is-prop-contains-zero-subset-Semiring :
+ is-prop contains-zero-subset-Semiring
+ is-prop-contains-zero-subset-Semiring =
+ is-prop-is-in-subtype S (zero-Semiring R)
```
### The condition that a subset contains one
@@ -94,6 +101,11 @@ module _
```agda
contains-one-subset-Semiring : UU l2
contains-one-subset-Semiring = is-in-subtype S (one-Semiring R)
+
+ is-prop-contains-one-subset-Semiring :
+ is-prop contains-one-subset-Semiring
+ is-prop-contains-one-subset-Semiring =
+ is-prop-is-in-subtype S (one-Semiring R)
```
### The condition that a subset is closed under addition
@@ -101,9 +113,19 @@ module _
```agda
is-closed-under-addition-subset-Semiring : UU (l1 ⊔ l2)
is-closed-under-addition-subset-Semiring =
- (x y : type-Semiring R) →
+ {x y : type-Semiring R} →
is-in-subtype S x → is-in-subtype S y →
is-in-subtype S (add-Semiring R x y)
+
+ is-prop-is-closed-under-addition-subset-Semiring :
+ is-prop is-closed-under-addition-subset-Semiring
+ is-prop-is-closed-under-addition-subset-Semiring =
+ is-prop-implicit-Π
+ ( λ x →
+ is-prop-implicit-Π
+ ( λ y →
+ is-prop-function-type
+ ( is-prop-function-type (is-prop-is-in-subtype S _))))
```
### The condition that a subset is closed under multiplication
@@ -113,6 +135,16 @@ module _
is-closed-under-multiplication-subset-Semiring =
(x y : type-Semiring R) → is-in-subtype S x → is-in-subtype S y →
is-in-subtype S (mul-Semiring R x y)
+
+ is-prop-is-closed-under-multiplication-subset-Semiring :
+ is-prop is-closed-under-multiplication-subset-Semiring
+ is-prop-is-closed-under-multiplication-subset-Semiring =
+ is-prop-Π
+ ( λ x →
+ is-prop-Π
+ ( λ y →
+ is-prop-function-type
+ ( is-prop-function-type (is-prop-is-in-subtype S _))))
```
### The condition that a subset is closed under multiplication from the left by an arbitrary element
@@ -122,13 +154,55 @@ module _
is-closed-under-left-multiplication-subset-Semiring =
(x y : type-Semiring R) → is-in-subtype S y →
is-in-subtype S (mul-Semiring R x y)
+
+ is-prop-is-closed-under-left-multiplication-subset-Semiring :
+ is-prop is-closed-under-left-multiplication-subset-Semiring
+ is-prop-is-closed-under-left-multiplication-subset-Semiring =
+ is-prop-Π
+ ( λ x →
+ is-prop-Π (λ y → is-prop-function-type (is-prop-is-in-subtype S _)))
+
+ is-closed-under-left-multiplication-prop-subset-Semiring : Prop (l1 ⊔ l2)
+ pr1 is-closed-under-left-multiplication-prop-subset-Semiring =
+ is-closed-under-left-multiplication-subset-Semiring
+ pr2 is-closed-under-left-multiplication-prop-subset-Semiring =
+ is-prop-is-closed-under-left-multiplication-subset-Semiring
```
-### The condition that a subset is closed-under-multiplication from the right by an arbitrary element
+### The condition that a subset is closed under multiplication from the right by an arbitrary element
```agda
is-closed-under-right-multiplication-subset-Semiring : UU (l1 ⊔ l2)
is-closed-under-right-multiplication-subset-Semiring =
(x y : type-Semiring R) → is-in-subtype S x →
is-in-subtype S (mul-Semiring R x y)
+
+ is-prop-is-closed-under-right-multiplication-subset-Semiring :
+ is-prop is-closed-under-right-multiplication-subset-Semiring
+ is-prop-is-closed-under-right-multiplication-subset-Semiring =
+ is-prop-Π
+ ( λ x →
+ is-prop-Π (λ y → is-prop-function-type (is-prop-is-in-subtype S _)))
+
+ is-closed-under-right-multiplication-prop-subset-Semiring : Prop (l1 ⊔ l2)
+ pr1 is-closed-under-right-multiplication-prop-subset-Semiring =
+ is-closed-under-right-multiplication-subset-Semiring
+ pr2 is-closed-under-right-multiplication-prop-subset-Semiring =
+ is-prop-is-closed-under-right-multiplication-subset-Semiring
+```
+
+### The condition that a subset of a semiring is an additive submonoid
+
+```agda
+ is-additive-submonoid-subset-Semiring : UU (l1 ⊔ l2)
+ is-additive-submonoid-subset-Semiring =
+ contains-zero-subset-Semiring ×
+ is-closed-under-addition-subset-Semiring
+
+ is-prop-is-additive-submonoid-subset-Semiring :
+ is-prop is-additive-submonoid-subset-Semiring
+ is-prop-is-additive-submonoid-subset-Semiring =
+ is-prop-product
+ ( is-prop-contains-zero-subset-Semiring)
+ ( is-prop-is-closed-under-addition-subset-Semiring)
```
diff --git a/src/ring-theory/subtractive-ideals-semirings.lagda.md b/src/ring-theory/subtractive-ideals-semirings.lagda.md
new file mode 100644
index 0000000000..f391fccbf1
--- /dev/null
+++ b/src/ring-theory/subtractive-ideals-semirings.lagda.md
@@ -0,0 +1,77 @@
+# Subtractive ideals of semirings
+
+```agda
+module ring-theory.subtractive-ideals-semirings where
+```
+
+Imports
+
+```agda
+open import foundation.subtypes
+open import foundation.universe-levels
+
+open import ring-theory.ideals-semirings
+open import ring-theory.semirings
+open import ring-theory.subsets-semirings
+```
+
+
+
+## Idea
+
+An [ideal](ring-theory.ideals-semirings.md) $I$ of a [semiring](ring-theory.semirings.md) $R$ is said to be a {{#concept "subtractive ideal" Disambiguation="semirings" Agda=is-subtractive-ideal-Semiring}} if for every $a,b : R$ such that $a\in S$ and $a+b \in S$, we have $b \in S$.
+
+## Definitions
+
+### Subtractive subsets of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : subset-Semiring l2 R)
+ where
+
+ is-subtractive-subset-Semiring :
+ UU (l1 ⊔ l2)
+ is-subtractive-subset-Semiring =
+ (a b : type-Semiring R) →
+ is-in-subtype I a → is-in-subtype I (add-Semiring R a b) → is-in-subtype I b
+```
+
+### Subtractive ideals of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : ideal-Semiring l2 R)
+ where
+
+ is-subtractive-ideal-Semiring :
+ UU (l1 ⊔ l2)
+ is-subtractive-ideal-Semiring =
+ is-subtractive-subset-Semiring R (subset-ideal-Semiring R I)
+```
+
+### Subtractive left ideals of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : left-ideal-Semiring l2 R)
+ where
+
+ is-subtractive-left-ideal-Semiring :
+ UU (l1 ⊔ l2)
+ is-subtractive-left-ideal-Semiring =
+ is-subtractive-subset-Semiring R (subset-left-ideal-Semiring R I)
+```
+
+### Subtractive right ideals of a semiring
+
+```agda
+module _
+ {l1 l2 : Level} (R : Semiring l1) (I : right-ideal-Semiring l2 R)
+ where
+
+ is-subtractive-right-ideal-Semiring :
+ UU (l1 ⊔ l2)
+ is-subtractive-right-ideal-Semiring =
+ is-subtractive-subset-Semiring R (subset-right-ideal-Semiring R I)
+```
diff --git a/src/set-theory/countable-sets.lagda.md b/src/set-theory/countable-sets.lagda.md
index 023911e269..68bf2d9ffd 100644
--- a/src/set-theory/countable-sets.lagda.md
+++ b/src/set-theory/countable-sets.lagda.md
@@ -459,12 +459,12 @@ module _
( unit-trunc-Prop
( pair
( map-maybe-product ∘
- ( map-product (pr1 h) (pr1 h') ∘ map-ℕ-to-ℕ×ℕ))
+ ( map-product (pr1 h) (pr1 h') ∘ map-inv-pairing-equiv-ℕ))
( is-surjective-comp
( is-surjective-map-maybe-product)
( is-surjective-comp
( is-surjective-map-product (pr2 h) (pr2 h'))
- ( is-surjective-is-equiv (is-equiv-map-ℕ-to-ℕ×ℕ)))))))
+ ( is-surjective-is-equiv (is-equiv-map-inv-pairing-equiv-ℕ)))))))
```
In particular, the sets ℕ + ℕ, ℕ × ℕ, and ℤ are countable.
diff --git a/src/structured-types/magmas.lagda.md b/src/structured-types/magmas.lagda.md
index 13372059eb..f61e86aaaa 100644
--- a/src/structured-types/magmas.lagda.md
+++ b/src/structured-types/magmas.lagda.md
@@ -52,13 +52,41 @@ is-unital-Magma M = is-unital (mul-Magma M)
Unital-Magma : (l : Level) → UU (lsuc l)
Unital-Magma l = Σ (Magma l) is-unital-Magma
-magma-Unital-Magma :
- {l : Level} → Unital-Magma l → Magma l
-magma-Unital-Magma M = pr1 M
-
-is-unital-magma-Unital-Magma :
- {l : Level} (M : Unital-Magma l) → is-unital-Magma (magma-Unital-Magma M)
-is-unital-magma-Unital-Magma M = pr2 M
+module _
+ {l : Level} (M : Unital-Magma l)
+ where
+
+ magma-Unital-Magma : Magma l
+ magma-Unital-Magma = pr1 M
+
+ type-Unital-Magma :
+ UU l
+ type-Unital-Magma =
+ type-Magma magma-Unital-Magma
+
+ mul-Unital-Magma :
+ (x y : type-Unital-Magma) → type-Unital-Magma
+ mul-Unital-Magma =
+ mul-Magma magma-Unital-Magma
+
+ is-unital-magma-Unital-Magma :
+ is-unital-Magma magma-Unital-Magma
+ is-unital-magma-Unital-Magma = pr2 M
+
+ unit-Unital-Magma :
+ type-Unital-Magma
+ unit-Unital-Magma =
+ pr1 is-unital-magma-Unital-Magma
+
+ left-unit-law-mul-Unital-Magma :
+ (x : type-Unital-Magma) → mul-Unital-Magma unit-Unital-Magma x = x
+ left-unit-law-mul-Unital-Magma =
+ pr1 (pr2 is-unital-magma-Unital-Magma)
+
+ right-unit-law-mul-Unital-Magma :
+ (x : type-Unital-Magma) → mul-Unital-Magma x unit-Unital-Magma = x
+ right-unit-law-mul-Unital-Magma =
+ pr2 (pr2 is-unital-magma-Unital-Magma)
```
### Semigroups
diff --git a/src/univalent-combinatorics/counting-decidable-subtypes.lagda.md b/src/univalent-combinatorics/counting-decidable-subtypes.lagda.md
index 2dc4eea133..5d6b13a671 100644
--- a/src/univalent-combinatorics/counting-decidable-subtypes.lagda.md
+++ b/src/univalent-combinatorics/counting-decidable-subtypes.lagda.md
@@ -106,11 +106,16 @@ abstract
count-decidable-subtype :
{l1 l2 : Level} {X : UU l1} (P : decidable-subtype l2 X) →
- (count X) → count (type-decidable-subtype P)
+ count X → count (type-decidable-subtype P)
count-decidable-subtype P e =
count-decidable-subtype' P
( number-of-elements-count e)
( equiv-count e)
+
+number-of-elements-decidable-subtype :
+ {l1 l2 : Level} {X : UU l1} (P : decidable-subtype l2 X) (e : count X) → ℕ
+number-of-elements-decidable-subtype P e =
+ number-of-elements-count (count-decidable-subtype P e)
```
### The elements in the domain of a decidable embedding can be counted if the elements of the codomain can be counted
diff --git a/src/univalent-combinatorics/counting.lagda.md b/src/univalent-combinatorics/counting.lagda.md
index b9c4fa6d19..fba02151bd 100644
--- a/src/univalent-combinatorics/counting.lagda.md
+++ b/src/univalent-combinatorics/counting.lagda.md
@@ -34,10 +34,12 @@ open import univalent-combinatorics.standard-finite-types
## Idea
-The elements of a type `X` can be counted by establishing an equivalence
+A {{#concept "count" Agda=count WDID=Q247154 WD=counting}} of the elements of a type `X` consists of a [natural number](elementary-number-theory.natural-numbers.md) `n` and an [equivalence](foundation-core.equivalences.md)
`Fin n ≃ X`.
-## Definition
+## Definitions
+
+### Counts of a type
```agda
count : {l : Level} → UU l → UU l
@@ -191,7 +193,7 @@ has-decidable-equality-count (pair k e) =
has-decidable-equality-equiv' e (has-decidable-equality-Fin k)
```
-### This with a count are either inhabited or empty
+### Types with a count are either inhabited or empty
```agda
is-inhabited-or-empty-count :
@@ -217,3 +219,7 @@ count-type-trunc-Prop (pair (succ-ℕ k) e) =
( is-prop-type-trunc-Prop)
( unit-trunc-Prop (map-equiv e (zero-Fin k))))
```
+
+## See also
+
+- [Finite types](univalent-combinatorics.finite-types.md)
diff --git a/src/univalent-combinatorics/cycle-prime-decomposition-natural-numbers.lagda.md b/src/univalent-combinatorics/cycle-prime-decomposition-natural-numbers.lagda.md
index f1c5ab49c3..23eaec6c21 100644
--- a/src/univalent-combinatorics/cycle-prime-decomposition-natural-numbers.lagda.md
+++ b/src/univalent-combinatorics/cycle-prime-decomposition-natural-numbers.lagda.md
@@ -82,7 +82,7 @@ to the cycle prime decomposition of `n *ℕ m`.
equiv-product-cycle-prime-decomposition-ℕ :
(n m : ℕ) → (H : leq-ℕ 1 n) → (I : leq-ℕ 1 m) →
( cycle-prime-decomposition-ℕ n H × cycle-prime-decomposition-ℕ m I) ≃
- cycle-prime-decomposition-ℕ (n *ℕ m) (preserves-leq-mul-ℕ 1 n 1 m H I)
+ cycle-prime-decomposition-ℕ (n *ℕ m) (preserves-order-mul-ℕ 1 n 1 m H I)
equiv-product-cycle-prime-decomposition-ℕ n m H I =
( ( equiv-eq
( ap
@@ -98,7 +98,7 @@ equiv-product-cycle-prime-decomposition-ℕ n m H I =
( eq-is-contr'
( fundamental-theorem-arithmetic-list-ℕ
( n *ℕ m)
- ( preserves-leq-mul-ℕ 1 n 1 m H I))
+ ( preserves-order-mul-ℕ 1 n 1 m H I))
( prime-decomposition-list-sort-concatenation-ℕ
( n)
( m)
@@ -114,7 +114,7 @@ equiv-product-cycle-prime-decomposition-ℕ n m H I =
I))
( prime-decomposition-fundamental-theorem-arithmetic-list-ℕ
(n *ℕ m)
- ( preserves-leq-mul-ℕ 1 n 1 m H I))))))) ∘e
+ ( preserves-order-mul-ℕ 1 n 1 m H I))))))) ∘e
( equiv-eq
( ap
( iterated-product-lists)
@@ -136,7 +136,7 @@ equiv-product-cycle-prime-decomposition-ℕ n m H I =
( list-fundamental-theorem-arithmetic-ℕ n H)
( list-fundamental-theorem-arithmetic-ℕ m I)))
( tr
- ( Permutation)
+ ( permutation)
( inv
( length-map-list
( Cyclic-Type lzero)
diff --git a/src/univalent-combinatorics/finite-maps.lagda.md b/src/univalent-combinatorics/finite-maps.lagda.md
new file mode 100644
index 0000000000..1af4bb61e5
--- /dev/null
+++ b/src/univalent-combinatorics/finite-maps.lagda.md
@@ -0,0 +1,63 @@
+# Finite maps
+
+```agda
+module univalent-combinatorics.finite-maps where
+```
+
+Imports
+
+```agda
+open import elementary-number-theory.natural-numbers
+
+open import foundation.decidable-embeddings
+open import foundation.decidable-propositions
+open import foundation.dependent-pair-types
+open import foundation.fibers-of-maps
+open import foundation.propositions
+open import foundation.universe-levels
+
+open import univalent-combinatorics.finite-types
+```
+
+
+
+## Idea
+
+A map $f : A \to B$ is said to be a {{#concept "finite map"}} if its [fibers](foundation-core.finite-types.md) are [finite](univalent-combinatorics.finite-types.md).
+
+Finite maps are [decidable](elementary-number-theory.decidable-maps-natural-numbers.md).
+
+## Definitions
+
+### The predicate of being a finite map
+
+```agda
+module _
+ {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B)
+ where
+
+ is-finite-prop-map : Prop (l1 ⊔ l2)
+ is-finite-prop-map =
+ Π-Prop B (λ y → is-finite-Prop (fiber f y))
+
+ is-finite-map : UU (l1 ⊔ l2)
+ is-finite-map = type-Prop is-finite-prop-map
+
+ is-prop-is-finite-map : is-prop is-finite-map
+ is-prop-is-finite-map = is-prop-type-Prop is-finite-prop-map
+```
+
+## Properties
+
+### Decidable embeddings are finite maps
+
+```agda
+module _
+ {l1 l2 : Level} {A : UU l1} {B : UU l2} {f : A → B}
+ where
+
+ is-finite-map-is-decidable-emb :
+ is-decidable-emb f → is-finite-map f
+ is-finite-map-is-decidable-emb H x =
+ is-finite-is-decidable-prop (is-decidable-prop-map-is-decidable-emb H x)
+```
diff --git a/src/univalent-combinatorics/inequality-types-with-counting.lagda.md b/src/univalent-combinatorics/inequality-types-with-counting.lagda.md
index 137bb6bd70..8e3e667f47 100644
--- a/src/univalent-combinatorics/inequality-types-with-counting.lagda.md
+++ b/src/univalent-combinatorics/inequality-types-with-counting.lagda.md
@@ -63,24 +63,24 @@ transitive-leq-count (pair k e) {x} {y} {z} =
( map-inv-equiv e y)
( map-inv-equiv-count (pair k e) z)
-preserves-leq-equiv-count :
+preserves-order-equiv-count :
{l : Level} {X : UU l} (e : count X)
{x y : Fin (number-of-elements-count e)} →
leq-Fin (number-of-elements-count e) x y →
leq-count e (map-equiv-count e x) (map-equiv-count e y)
-preserves-leq-equiv-count e {x} {y} H =
+preserves-order-equiv-count e {x} {y} H =
concatenate-eq-leq-eq-Fin
( number-of-elements-count e)
( is-retraction-map-inv-equiv (equiv-count e) x)
( H)
( inv (is-retraction-map-inv-equiv (equiv-count e) y))
-reflects-leq-equiv-count :
+reflects-order-equiv-count :
{l : Level} {X : UU l} (e : count X)
{x y : Fin (number-of-elements-count e)} →
leq-count e (map-equiv-count e x) (map-equiv-count e y) →
leq-Fin (number-of-elements-count e) x y
-reflects-leq-equiv-count e {x} {y} H =
+reflects-order-equiv-count e {x} {y} H =
concatenate-eq-leq-eq-Fin
( number-of-elements-count e)
( inv (is-retraction-map-inv-equiv (equiv-count e) x))
diff --git a/src/univalent-combinatorics/pigeonhole-principle.lagda.md b/src/univalent-combinatorics/pigeonhole-principle.lagda.md
index 8c52386070..e845f9d55a 100644
--- a/src/univalent-combinatorics/pigeonhole-principle.lagda.md
+++ b/src/univalent-combinatorics/pigeonhole-principle.lagda.md
@@ -347,6 +347,10 @@ module _
apply-universal-property-trunc-Prop K empty-Prop
( λ d → is-not-emb-le-count e d f
( concatenate-eq-le-eq-ℕ
+ ( number-of-elements-count d)
+ ( number-of-elements-is-finite K)
+ ( number-of-elements-is-finite H)
+ ( number-of-elements-count e)
( compute-number-of-elements-is-finite d K)
( p)
( inv (compute-number-of-elements-is-finite e H)))
diff --git a/src/univalent-combinatorics/sequences-finite-types.lagda.md b/src/univalent-combinatorics/sequences-finite-types.lagda.md
index e9cd8106af..d908fcbaea 100644
--- a/src/univalent-combinatorics/sequences-finite-types.lagda.md
+++ b/src/univalent-combinatorics/sequences-finite-types.lagda.md
@@ -8,6 +8,7 @@ module univalent-combinatorics.sequences-finite-types where
```agda
open import elementary-number-theory.decidable-types
+open import elementary-number-theory.minimal-structured-natural-numbers
open import elementary-number-theory.natural-numbers
open import elementary-number-theory.strict-inequality-natural-numbers
open import elementary-number-theory.well-ordering-principle-natural-numbers
@@ -135,7 +136,7 @@ minimal-element-repetition-of-values-sequence-Fin k f =
is-decidable-strictly-bounded-Σ-ℕ' x
( λ y → f y = f x)
( λ y → has-decidable-equality-Fin k (f y) (f x)))
- ( v , u , H , p)
+ ( u , H , p)
where
r = ordered-repetition-of-values-sequence-Fin k f
u = pr1 (pr1 r)
diff --git a/src/univalent-combinatorics/standard-finite-trees.lagda.md b/src/univalent-combinatorics/standard-finite-trees.lagda.md
index 9ef39e079f..7416c54e1b 100644
--- a/src/univalent-combinatorics/standard-finite-trees.lagda.md
+++ b/src/univalent-combinatorics/standard-finite-trees.lagda.md
@@ -50,7 +50,8 @@ number-nodes-Tree-Fin (tree-Fin (succ-ℕ n) f) =
height-Tree-Fin : Tree-Fin → ℕ
height-Tree-Fin (tree-Fin zero-ℕ f) = zero-ℕ
height-Tree-Fin (tree-Fin (succ-ℕ n) f) =
- succ-ℕ (max-Fin-ℕ (succ-ℕ n) (λ k → height-Tree-Fin (f k)))
+ succ-ℕ
+ ( max-standard-finite-family-ℕ (succ-ℕ n) (λ k → height-Tree-Fin (f k)))
is-leaf-Tree-Fin : Tree-Fin → UU lzero
is-leaf-Tree-Fin (tree-Fin zero-ℕ _) = unit
diff --git a/src/univalent-combinatorics/standard-finite-types.lagda.md b/src/univalent-combinatorics/standard-finite-types.lagda.md
index 31d90d106c..cf0600bdc5 100644
--- a/src/univalent-combinatorics/standard-finite-types.lagda.md
+++ b/src/univalent-combinatorics/standard-finite-types.lagda.md
@@ -237,8 +237,8 @@ strict-upper-bound-nat-Fin (succ-ℕ k) (inl x) =
( nat-Fin k x)
( k)
( succ-ℕ k)
- ( strict-upper-bound-nat-Fin k x)
( succ-le-ℕ k)
+ ( strict-upper-bound-nat-Fin k x)
strict-upper-bound-nat-Fin (succ-ℕ k) (inr star) =
succ-le-ℕ k
@@ -246,7 +246,7 @@ upper-bound-nat-Fin :
(k : ℕ) (x : Fin (succ-ℕ k)) → leq-ℕ (nat-Fin (succ-ℕ k) x) k
upper-bound-nat-Fin zero-ℕ (inr star) = star
upper-bound-nat-Fin (succ-ℕ k) (inl x) =
- preserves-leq-succ-ℕ (nat-Fin (succ-ℕ k) x) k (upper-bound-nat-Fin k x)
+ leq-succ-leq-ℕ (nat-Fin (succ-ℕ k) x) k (upper-bound-nat-Fin k x)
upper-bound-nat-Fin (succ-ℕ k) (inr star) = refl-leq-ℕ (succ-ℕ k)
upper-bound-nat-Fin' :
@@ -258,9 +258,19 @@ is-injective-nat-Fin : (k : ℕ) → is-injective (nat-Fin k)
is-injective-nat-Fin (succ-ℕ k) {inl x} {inl y} p =
ap inl (is-injective-nat-Fin k p)
is-injective-nat-Fin (succ-ℕ k) {inl x} {inr star} p =
- ex-falso (neq-le-ℕ (strict-upper-bound-nat-Fin k x) p)
+ ex-falso
+ ( neq-le-ℕ
+ ( nat-Fin k x)
+ ( nat-Fin (succ-ℕ k) (inr star))
+ ( strict-upper-bound-nat-Fin k x)
+ ( p))
is-injective-nat-Fin (succ-ℕ k) {inr star} {inl y} p =
- ex-falso (neq-le-ℕ (strict-upper-bound-nat-Fin k y) (inv p))
+ ex-falso
+ ( neq-le-ℕ
+ ( nat-Fin (succ-ℕ k) (inl y))
+ ( nat-Fin (succ-ℕ k) (inr star))
+ ( strict-upper-bound-nat-Fin k y)
+ ( inv p))
is-injective-nat-Fin (succ-ℕ k) {inr star} {inr star} p =
refl
@@ -491,3 +501,9 @@ is-preunivalent-Fin : is-preunivalent Fin
is-preunivalent-Fin =
is-preunivalent-retraction-equiv-tr-Set Fin-Set retraction-equiv-tr-Fin
```
+
+## See also
+
+- [The bounded natural numbers](elementary-number-theory.bounded-natural-numbers.md)
+- [The strictly bounded natural numbers](elementary-number-theory.strictly-bounded-natural-numbers.md)
+- [Modular arithmetic on the standard finite types](elementary-number-theory.modular-arithmetic-standard-finite-types.md)