Skip to content

Commit e53405b

Browse files
authored
The square root of two is irrational (#1718)
We prove both the elementary version (two is not the square of any rational number) and the real version (the square root of two is not a rational real number).
1 parent ad36dd3 commit e53405b

17 files changed

+517
-11
lines changed

src/elementary-number-theory.lagda.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ open import elementary-number-theory.unit-similarity-standard-finite-types publi
235235
open import elementary-number-theory.universal-property-conatural-numbers public
236236
open import elementary-number-theory.universal-property-integers public
237237
open import elementary-number-theory.universal-property-natural-numbers public
238+
open import elementary-number-theory.unsolvability-of-squaring-to-two-in-rational-numbers public
238239
open import elementary-number-theory.upper-bounds-natural-numbers public
239240
open import elementary-number-theory.well-ordering-principle-natural-numbers public
240241
open import elementary-number-theory.well-ordering-principle-standard-finite-types public

src/elementary-number-theory/absolute-value-integers.lagda.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,14 @@ abstract
250250
double-negative-law-mul-abs-ℤ x y =
251251
ap abs-ℤ (inv (double-negative-law-mul-ℤ x y))
252252
```
253+
254+
### `x = |x|` or `x = -|x|`
255+
256+
```agda
257+
abstract
258+
is-pos-or-neg-abs-ℤ :
259+
(x : ℤ) → (x = int-ℕ (abs-ℤ x)) + (x = neg-ℤ (int-ℕ (abs-ℤ x)))
260+
is-pos-or-neg-abs-ℤ (inr (inl unit)) = inl refl
261+
is-pos-or-neg-abs-ℤ (inr (inr n)) = inl refl
262+
is-pos-or-neg-abs-ℤ (inl n) = inr refl
263+
```

src/elementary-number-theory/multiplication-natural-numbers.lagda.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,19 @@ abstract
345345
is-zero-mul-ℕ-is-zero-right-summand x y H
346346
```
347347

348+
### Swapping laws
349+
350+
```agda
351+
abstract
352+
right-swap-mul-ℕ : (x y z : ℕ) → (x *ℕ y) *ℕ z = (x *ℕ z) *ℕ y
353+
right-swap-mul-ℕ x y z =
354+
equational-reasoning
355+
x *ℕ y *ℕ z
356+
= x *ℕ (y *ℕ z) by associative-mul-ℕ x y z
357+
= x *ℕ (z *ℕ y) by ap (x *ℕ_) (commutative-mul-ℕ y z)
358+
= x *ℕ z *ℕ y by inv (associative-mul-ℕ x z y)
359+
```
360+
348361
## See also
349362

350363
- [Squares of natural numbers](elementary-number-theory.squares-natural-numbers.md)

src/elementary-number-theory/parity-natural-numbers.lagda.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ module elementary-number-theory.parity-natural-numbers where
77
<details><summary>Imports</summary>
88

99
```agda
10+
open import elementary-number-theory.addition-natural-numbers
1011
open import elementary-number-theory.divisibility-natural-numbers
1112
open import elementary-number-theory.equality-natural-numbers
1213
open import elementary-number-theory.modular-arithmetic-standard-finite-types
1314
open import elementary-number-theory.multiplication-natural-numbers
1415
open import elementary-number-theory.natural-numbers
1516
open import elementary-number-theory.nonzero-natural-numbers
17+
open import elementary-number-theory.squares-natural-numbers
1618
1719
open import foundation.action-on-identifications-functions
20+
open import foundation.coproduct-types
1821
open import foundation.decidable-types
1922
open import foundation.dependent-pair-types
2023
open import foundation.empty-types
@@ -188,3 +191,66 @@ abstract
188191
(x y : ℕ) → is-odd-ℕ x → is-even-ℕ y → x ≠ y
189192
noneq-odd-even x y odd-x even-y x=y = odd-x (inv-tr is-even-ℕ x=y even-y)
190193
```
194+
195+
### If `x` and `y` are odd, `xy` is odd
196+
197+
```agda
198+
abstract
199+
is-odd-mul-is-odd-ℕ :
200+
(x y : ℕ) → is-odd-ℕ x → is-odd-ℕ y → is-odd-ℕ (x *ℕ y)
201+
is-odd-mul-is-odd-ℕ _ _ odd-x odd-y
202+
with has-odd-expansion-is-odd _ odd-x | has-odd-expansion-is-odd _ odd-y
203+
... | (m , refl) | (n , refl) =
204+
is-odd-has-odd-expansion _
205+
( m *ℕ (2 *ℕ n) +ℕ m +ℕ n ,
206+
( equational-reasoning
207+
succ-ℕ ((m *ℕ (2 *ℕ n) +ℕ m +ℕ n) *ℕ 2)
208+
= succ-ℕ ((m *ℕ (2 *ℕ n) +ℕ m) *ℕ 2 +ℕ n *ℕ 2)
209+
by ap succ-ℕ (right-distributive-mul-add-ℕ (m *ℕ (2 *ℕ n) +ℕ m) n 2)
210+
= (m *ℕ (2 *ℕ n) +ℕ (m *ℕ 1)) *ℕ 2 +ℕ succ-ℕ (n *ℕ 2)
211+
by
212+
ap
213+
( λ k → succ-ℕ ((m *ℕ (2 *ℕ n) +ℕ k) *ℕ 2 +ℕ n *ℕ 2))
214+
( inv (right-unit-law-mul-ℕ m))
215+
= m *ℕ (2 *ℕ n +ℕ 1) *ℕ 2 +ℕ succ-ℕ (n *ℕ 2)
216+
by
217+
ap
218+
( λ k → k *ℕ 2 +ℕ succ-ℕ (n *ℕ 2))
219+
( inv (left-distributive-mul-add-ℕ m (2 *ℕ n) 1))
220+
= m *ℕ 2 *ℕ succ-ℕ (2 *ℕ n) +ℕ succ-ℕ (n *ℕ 2)
221+
by ap (_+ℕ succ-ℕ (n *ℕ 2)) (right-swap-mul-ℕ m (succ-ℕ (2 *ℕ n)) 2)
222+
= m *ℕ 2 *ℕ succ-ℕ (n *ℕ 2) +ℕ 1 *ℕ succ-ℕ (n *ℕ 2)
223+
by
224+
ap-add-ℕ
225+
( ap (λ k → m *ℕ 2 *ℕ succ-ℕ k) (commutative-mul-ℕ 2 n))
226+
( inv (left-unit-law-mul-ℕ (succ-ℕ (n *ℕ 2))))
227+
= succ-ℕ (m *ℕ 2) *ℕ succ-ℕ (n *ℕ 2)
228+
by inv (right-distributive-mul-add-ℕ (m *ℕ 2) 1 (succ-ℕ (n *ℕ 2)))))
229+
```
230+
231+
### If `xy` is even, `x` or `y` is even
232+
233+
```agda
234+
abstract
235+
is-even-either-factor-is-even-mul-ℕ :
236+
(x y : ℕ) → is-even-ℕ (x *ℕ y) → (is-even-ℕ x) + (is-even-ℕ y)
237+
is-even-either-factor-is-even-mul-ℕ x y is-even-xy =
238+
rec-coproduct
239+
( inl)
240+
( λ is-odd-x →
241+
rec-coproduct
242+
( inr)
243+
( λ is-odd-y →
244+
ex-falso (is-odd-mul-is-odd-ℕ x y is-odd-x is-odd-y is-even-xy))
245+
( is-decidable-is-even-ℕ y))
246+
( is-decidable-is-even-ℕ x)
247+
```
248+
249+
### If `` is even, `x` is even
250+
251+
```agda
252+
abstract
253+
is-even-is-even-square-ℕ : (x : ℕ) → is-even-ℕ (square-ℕ x) → is-even-ℕ x
254+
is-even-is-even-square-ℕ x is-even-x² =
255+
rec-coproduct id id (is-even-either-factor-is-even-mul-ℕ x x is-even-x²)
256+
```

src/elementary-number-theory/positive-integers.lagda.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ open import foundation.equivalences
2323
open import foundation.existential-quantification
2424
open import foundation.function-types
2525
open import foundation.identity-types
26+
open import foundation.negation
2627
open import foundation.propositions
2728
open import foundation.retractions
2829
open import foundation.sections
@@ -91,6 +92,9 @@ module _
9192
int-positive-ℤ : ℤ
9293
int-positive-ℤ = pr1 p
9394
95+
int-ℤ⁺ : ℤ
96+
int-ℤ⁺ = int-positive-ℤ
97+
9498
is-positive-int-positive-ℤ : is-positive-ℤ int-positive-ℤ
9599
is-positive-int-positive-ℤ = pr2 p
96100
```
@@ -192,6 +196,11 @@ abstract
192196
positive-int-ℕ : ℕ → positive-ℤ
193197
positive-int-ℕ = rec-ℕ one-positive-ℤ (λ _ → succ-positive-ℤ)
194198
199+
abstract
200+
int-positive-int-ℕ : (n : ℕ) → int-positive-ℤ (positive-int-ℕ n) = in-pos-ℤ n
201+
int-positive-int-ℕ 0 = refl
202+
int-positive-int-ℕ (succ-ℕ n) = ap succ-ℤ (int-positive-int-ℕ n)
203+
195204
nat-positive-ℤ : positive-ℤ → ℕ
196205
nat-positive-ℤ (inr (inr x) , H) = x
197206
@@ -239,6 +248,13 @@ is-countable-positive-ℤ =
239248
( is-surjective-is-equiv is-equiv-positive-int-ℕ))
240249
```
241250

251+
### Zero is not positive
252+
253+
```agda
254+
not-is-positive-zero-ℤ : ¬ (is-positive-ℤ zero-ℤ)
255+
not-is-positive-zero-ℤ ()
256+
```
257+
242258
## See also
243259

244260
- The relations between positive and nonnegative, negative and nonnpositive

src/elementary-number-theory/rational-numbers.lagda.md

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ open import foundation.dependent-pair-types
2323
open import foundation.equality-cartesian-product-types
2424
open import foundation.equality-dependent-pair-types
2525
open import foundation.identity-types
26+
open import foundation.logical-equivalences
2627
open import foundation.negation
2728
open import foundation.propositions
2829
open import foundation.reflecting-maps-equivalence-relations
@@ -31,6 +32,7 @@ open import foundation.sections
3132
open import foundation.sets
3233
open import foundation.subtypes
3334
open import foundation.surjective-maps
35+
open import foundation.transport-along-identifications
3436
open import foundation.universe-levels
3537
3638
open import set-theory.countable-sets
@@ -173,20 +175,50 @@ opaque
173175

174176
## Properties
175177

176-
### The rational images of two similar integer fractions are equal
178+
### Two integer fractions are similar if and only if they are equal as rational numbers
177179

178180
```agda
179-
opaque
180-
unfolding rational-fraction-ℤ
181+
module _
182+
(x y : fraction-ℤ)
183+
where
181184
182-
eq-ℚ-sim-fraction-ℤ :
183-
(x y : fraction-ℤ) → (H : sim-fraction-ℤ x y) →
184-
rational-fraction-ℤ x = rational-fraction-ℤ y
185-
eq-ℚ-sim-fraction-ℤ x y H =
186-
eq-pair-Σ'
187-
( pair
188-
( unique-reduce-fraction-ℤ x y H)
189-
( eq-is-prop (is-prop-is-reduced-fraction-ℤ (reduce-fraction-ℤ y))))
185+
abstract opaque
186+
unfolding rational-fraction-ℤ
187+
188+
eq-ℚ-sim-fraction-ℤ :
189+
sim-fraction-ℤ x y → rational-fraction-ℤ x = rational-fraction-ℤ y
190+
eq-ℚ-sim-fraction-ℤ H =
191+
eq-pair-Σ'
192+
( pair
193+
( unique-reduce-fraction-ℤ x y H)
194+
( eq-is-prop (is-prop-is-reduced-fraction-ℤ (reduce-fraction-ℤ y))))
195+
196+
sim-fraction-ℤ-eq-ℚ :
197+
rational-fraction-ℤ x = rational-fraction-ℤ y → sim-fraction-ℤ x y
198+
sim-fraction-ℤ-eq-ℚ H =
199+
transitive-sim-fraction-ℤ
200+
( x)
201+
( reduce-fraction-ℤ y)
202+
( y)
203+
( symmetric-sim-fraction-ℤ
204+
( y)
205+
( reduce-fraction-ℤ y)
206+
( sim-reduced-fraction-ℤ y))
207+
( transitive-sim-fraction-ℤ
208+
( x)
209+
( reduce-fraction-ℤ x)
210+
( reduce-fraction-ℤ y)
211+
( tr
212+
( sim-fraction-ℤ (reduce-fraction-ℤ x))
213+
( ap fraction-ℚ H)
214+
( refl-sim-fraction-ℤ (reduce-fraction-ℤ x)))
215+
( sim-reduced-fraction-ℤ x))
216+
217+
eq-ℚ-iff-sim-fraction-ℤ :
218+
(sim-fraction-ℤ x y) ↔ (rational-fraction-ℤ x = rational-fraction-ℤ y)
219+
eq-ℚ-iff-sim-fraction-ℤ =
220+
( eq-ℚ-sim-fraction-ℤ ,
221+
sim-fraction-ℤ-eq-ℚ)
190222
```
191223

192224
### The type of rationals is a set

src/elementary-number-theory/relatively-prime-integers.lagda.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ module elementary-number-theory.relatively-prime-integers where
88

99
```agda
1010
open import elementary-number-theory.absolute-value-integers
11+
open import elementary-number-theory.divisibility-integers
1112
open import elementary-number-theory.greatest-common-divisor-integers
1213
open import elementary-number-theory.integers
1314
open import elementary-number-theory.relatively-prime-natural-numbers
1415
1516
open import foundation.action-on-identifications-functions
17+
open import foundation.dependent-pair-types
18+
open import foundation.logical-equivalences
1619
open import foundation.propositions
20+
open import foundation.transport-along-identifications
1721
open import foundation.universe-levels
1822
```
1923

@@ -60,6 +64,20 @@ abstract
6064
is-relatively-prime-is-relatively-prime-abs-ℤ {a} {b} H = ap int-ℕ H
6165
```
6266

67+
### For two relatively prime integers `x` and `y` and any integer `d`, if `d` divides `x` and `y`, `d` is a unit
68+
69+
```agda
70+
abstract
71+
is-unit-div-relatively-prime-ℤ :
72+
(x y : ℤ) (d : ℤ) → is-relatively-prime-ℤ x y →
73+
is-common-divisor-ℤ x y d → is-unit-ℤ d
74+
is-unit-div-relatively-prime-ℤ x y d gcd=1 d|x∧d|y =
75+
tr
76+
( λ k → div-ℤ d k)
77+
( gcd=1)
78+
( forward-implication (pr2 (is-gcd-gcd-ℤ x y) d) d|x∧d|y)
79+
```
80+
6381
### For any two integers `a` and `b` that are not both `0`, the integers `a/gcd(a,b)` and `b/gcd(a,b)` are relatively prime
6482

6583
```agda

src/elementary-number-theory/squares-integers.lagda.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ is-nonnegative-square-ℤ a =
6363
( decide-is-negative-is-nonnegative-ℤ {a})
6464
```
6565

66+
### The square of an embedding of a natural number is the embedding of the square of the natural number
67+
68+
```agda
69+
abstract
70+
square-int-ℕ : (n : ℕ) → square-ℤ (int-ℕ n) = int-ℕ (square-ℕ n)
71+
square-int-ℕ n = mul-int-ℕ n n
72+
```
73+
6674
### The square of the negation of `x` is the square of `x`
6775

6876
```agda
@@ -109,6 +117,32 @@ pr2
109117
( pr2 (is-square-int-is-square-nat (root , pf-square)))))
110118
```
111119

120+
### `|x|² = x²`
121+
122+
```agda
123+
abstract
124+
square-abs-ℤ : (x : ℤ) → int-ℕ (square-ℕ (abs-ℤ x)) = square-ℤ x
125+
square-abs-ℤ x =
126+
rec-coproduct
127+
( λ x=|x| →
128+
equational-reasoning
129+
int-ℕ (square-ℕ (abs-ℤ x))
130+
= square-ℤ (int-ℕ (abs-ℤ x))
131+
by inv (mul-int-ℕ (abs-ℤ x) (abs-ℤ x))
132+
= square-ℤ x
133+
by inv (ap square-ℤ x=|x|))
134+
( λ x=-|x| →
135+
equational-reasoning
136+
int-ℕ (square-ℕ (abs-ℤ x))
137+
= square-ℤ (int-abs-ℤ x)
138+
by inv (mul-int-ℕ (abs-ℤ x) (abs-ℤ x))
139+
= square-ℤ (neg-ℤ (int-abs-ℤ x))
140+
by inv (square-neg-ℤ (int-abs-ℤ x))
141+
= square-ℤ x
142+
by inv (ap square-ℤ x=-|x|))
143+
( is-pos-or-neg-abs-ℤ x)
144+
```
145+
112146
### Squareness in ℤ is decidable
113147

114148
```agda

src/elementary-number-theory/squares-natural-numbers.lagda.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ abstract
9696
( left-distributive-mul-add-ℕ 2 n 2))
9797
```
9898

99+
### Squaring distributes over multiplication
100+
101+
```agda
102+
abstract
103+
distributive-square-mul-ℕ :
104+
(m n : ℕ) → square-ℕ (m *ℕ n) = square-ℕ m *ℕ square-ℕ n
105+
distributive-square-mul-ℕ m n = interchange-law-mul-mul-ℕ m n m n
106+
```
107+
99108
### `n > √n` for `n > 1`
100109

101110
The idea is to assume `n = m + 2 ≤ sqrt(m + 2)` for some `m : ℕ` and derive a

src/elementary-number-theory/strict-inequality-integers.lagda.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ connected-le-ℤ x y H =
129129
( decide-sign-nonzero-ℤ (H ∘ eq-diff-ℤ))
130130
```
131131

132+
### Strict inequality on the integers is irreflexive
133+
134+
```agda
135+
abstract
136+
irreflexive-le-ℤ : (x : ℤ) → ¬ (le-ℤ x x)
137+
irreflexive-le-ℤ x =
138+
inv-tr
139+
( λ z → ¬ (is-positive-ℤ z))
140+
( right-inverse-law-add-ℤ x)
141+
( not-is-positive-zero-ℤ)
142+
```
143+
144+
### If `x < y`, `x ≠ y`
145+
146+
```agda
147+
abstract
148+
neq-le-ℤ : (x y : ℤ) → le-ℤ x y → x ≠ y
149+
neq-le-ℤ x _ x<x refl = irreflexive-le-ℤ x x<x
150+
151+
neq-le-ℤ' : (x y : ℤ) → le-ℤ y x → x ≠ y
152+
neq-le-ℤ' _ y y<y refl = irreflexive-le-ℤ y y<y
153+
```
154+
132155
### Any integer is strictly greater than its predecessor
133156

134157
```agda

0 commit comments

Comments
 (0)