Analysis I, Section 4.1
This file is a translation of Section 4.1 of Analysis I to Lean 4. All numbering refers to the original text.
I have attempted to make the translation as faithful a paraphrasing as possible of the original text. When there is a choice between a more idiomatic Lean solution and a more faithful translation, I have generally chosen the latter. In particular, there will be places where the Lean code could be "golfed" to be more elegant and idiomatic, but I have consciously avoided doing so.
Main constructions and results of this section:
-
Definition of the "Section 4.1" integers,
Section_4_1.Int, as formal differencesa —— bof natural numbersa b:ℕ, up to equivalence. (This is a quotient of a scaffolding typeSection_4_1.PreInt, which consists of formal differences without any equivalence imposed.) -
ring operations and order these integers, as well as an embedding of ℕ
-
Equivalence with the Mathlib integers
_root_.Int(orℤ), which we will use going forward.
namespace Section_4_1structure PreInt where
minuend : ℕ
subtrahend : ℕDefinition 4.1.1
instance PreInt.instSetoid : Setoid PreInt where
r a b := a.minuend + b.subtrahend = b.minuend + a.subtrahend
iseqv := {
refl := ⊢ ∀ (x : PreInt), x.minuend + x.subtrahend = x.minuend + x.subtrahend All goals completed! 🐙
symm := ⊢ ∀ {x y : PreInt},
x.minuend + y.subtrahend = y.minuend + x.subtrahend → y.minuend + x.subtrahend = x.minuend + y.subtrahend All goals completed! 🐙
trans := ⊢ ∀ {x y z : PreInt},
x.minuend + y.subtrahend = y.minuend + x.subtrahend →
y.minuend + z.subtrahend = z.minuend + y.subtrahend → x.minuend + z.subtrahend = z.minuend + x.subtrahend
-- This proof is written to follow the structure of the original text.
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕh1:{ minuend := a, subtrahend := b }.minuend + { minuend := c, subtrahend := d }.subtrahend =
{ minuend := c, subtrahend := d }.minuend + { minuend := a, subtrahend := b }.subtrahendh2:{ minuend := c, subtrahend := d }.minuend + { minuend := e, subtrahend := f }.subtrahend =
{ minuend := e, subtrahend := f }.minuend + { minuend := c, subtrahend := d }.subtrahend⊢ { minuend := a, subtrahend := b }.minuend + { minuend := e, subtrahend := f }.subtrahend =
{ minuend := e, subtrahend := f }.minuend + { minuend := a, subtrahend := b }.subtrahend
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕh1:a + d = c + bh2:c + f = e + d⊢ a + f = e + b
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕh1:a + d = c + bh2:c + f = e + dh3:(fun x1 x2 => x1 + x2) (a + d) (c + f) = (fun x1 x2 => x1 + x2) (c + b) (e + d)⊢ a + f = e + b
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕh1:a + d = c + bh2:c + f = e + dh3:a + d + (c + f) = c + b + (e + d)⊢ a + f = e + b
have : (a + f) + (c + d) = (e + b) + (c + d) := calc
(a + f) + (c + d) = a + d + (c + f) := a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕh1:a + d = c + bh2:c + f = e + dh3:a + d + (c + f) = c + b + (e + d)⊢ a + f + (c + d) = a + d + (c + f) All goals completed! 🐙
_ = c + b + (e + d) := h3
_ = (e + b) + (c + d) := a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕh1:a + d = c + bh2:c + f = e + dh3:a + d + (c + f) = c + b + (e + d)⊢ c + b + (e + d) = e + b + (c + d) All goals completed! 🐙
All goals completed! 🐙
}@[simp]
theorem PreInt.eq (a b c d:ℕ) : (⟨ a,b ⟩: PreInt) ≈ ⟨ c,d ⟩ ↔ a + d = c + b := a:ℕb:ℕc:ℕd:ℕ⊢ { minuend := a, subtrahend := b } ≈ { minuend := c, subtrahend := d } ↔ a + d = c + b All goals completed! 🐙abbrev Int := Quotient PreInt.instSetoidabbrev Int.formalDiff (a b:ℕ) : Int := Quotient.mk PreInt.instSetoid ⟨ a,b ⟩infix:100 " —— " => Int.formalDiffDefinition 4.1.1 (Integers)
theorem Int.eq (a b c d:ℕ): a —— b = c —— d ↔ a + d = c + b := a:ℕb:ℕc:ℕd:ℕ⊢ a —— b = c —— d ↔ a + d = c + b
a:ℕb:ℕc:ℕd:ℕ⊢ a —— b = c —— d → a + d = c + ba:ℕb:ℕc:ℕd:ℕ⊢ a + d = c + b → a —— b = c —— d
a:ℕb:ℕc:ℕd:ℕ⊢ a —— b = c —— d → a + d = c + b All goals completed! 🐙
a:ℕb:ℕc:ℕd:ℕh:a + d = c + b⊢ a —— b = c —— d; All goals completed! 🐙Definition 4.1.1 (Integers)
theorem Int.eq_diff (n:Int) : ∃ a b, n = a —— b := n:Int⊢ ∃ a b, n = a —— b
n:Int⊢ ∀ (a : PreInt), ∃ a_1 b, Quot.mk (⇑PreInt.instSetoid) a = a_1 —— b; n:Inta:ℕb:ℕ⊢ ∃ a_1 b_1, Quot.mk ⇑PreInt.instSetoid { minuend := a, subtrahend := b } = a_1 —— b_1
n:Inta:ℕb:ℕ⊢ Quot.mk ⇑PreInt.instSetoid { minuend := a, subtrahend := b } = a —— b; All goals completed! 🐙Lemma 4.1.3 (Addition well-defined)
instance Int.instAdd : Add Int where
add := Quotient.lift₂ (fun ⟨ a, b ⟩ ⟨ c, d ⟩ ↦ (a+c) —— (b+d) ) (⊢ ∀ (a₁ b₁ a₂ b₂ : PreInt),
a₁ ≈ a₂ →
b₁ ≈ b₂ →
(fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a + c) —— (b + d))
a₁ b₁ =
(fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a + c) —— (b + d))
a₂ b₂
a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:{ minuend := a, subtrahend := b } ≈ { minuend := a', subtrahend := b' }h2:{ minuend := c, subtrahend := d } ≈ { minuend := c', subtrahend := d' }⊢ (fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a + c) —— (b + d))
{ minuend := a, subtrahend := b } { minuend := c, subtrahend := d } =
(fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a + c) —— (b + d))
{ minuend := a', subtrahend := b' } { minuend := c', subtrahend := d' }
a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ a + c + (b' + d') = a' + c' + (b + d)
calc
_ = (a+b') + (c+d') := a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ a + c + (b' + d') = a + b' + (c + d') All goals completed! 🐙
_ = (a'+b) + (c'+d) := a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ a + b' + (c + d') = a' + b + (c' + d) All goals completed! 🐙
_ = _ := a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ a' + b + (c' + d) = a' + c' + (b + d) All goals completed! 🐙)Definition 4.1.2 (Definition of addition)
theorem Int.add_eq (a b c d:ℕ) : a —— b + c —— d = (a+c)——(b+d) := Quotient.lift₂_mk _ _ _ _Lemma 4.1.3 (Multiplication well-defined)
theorem Int.mul_congr_left (a b a' b' c d : ℕ) (h: a —— b = a' —— b') : (a*c+b*d) —— (a*d+b*c) = (a'*c+b'*d) —— (a'*d+b'*c) := a:ℕb:ℕa':ℕb':ℕc:ℕd:ℕh:a —— b = a' —— b'⊢ (a * c + b * d) —— (a * d + b * c) = (a' * c + b' * d) —— (a' * d + b' * c)
a:ℕb:ℕa':ℕb':ℕc:ℕd:ℕh:a + b' = a' + b⊢ a * c + b * d + (a' * d + b' * c) = a' * c + b' * d + (a * d + b * c)
calc
_ = c*(a+b') + d*(a'+b) := a:ℕb:ℕa':ℕb':ℕc:ℕd:ℕh:a + b' = a' + b⊢ a * c + b * d + (a' * d + b' * c) = c * (a + b') + d * (a' + b) All goals completed! 🐙
_ = c*(a'+b) + d*(a+b') := a:ℕb:ℕa':ℕb':ℕc:ℕd:ℕh:a + b' = a' + b⊢ c * (a + b') + d * (a' + b) = c * (a' + b) + d * (a + b') All goals completed! 🐙
_ = _ := a:ℕb:ℕa':ℕb':ℕc:ℕd:ℕh:a + b' = a' + b⊢ c * (a' + b) + d * (a + b') = a' * c + b' * d + (a * d + b * c) All goals completed! 🐙Lemma 4.1.3 (Multiplication well-defined)
theorem Int.mul_congr_right (a b c d c' d' : ℕ) (h: c —— d = c' —— d') : (a*c+b*d) —— (a*d+b*c) = (a*c'+b*d') —— (a*d'+b*c') := a:ℕb:ℕc:ℕd:ℕc':ℕd':ℕh:c —— d = c' —— d'⊢ (a * c + b * d) —— (a * d + b * c) = (a * c' + b * d') —— (a * d' + b * c')
a:ℕb:ℕc:ℕd:ℕc':ℕd':ℕh:c + d' = c' + d⊢ a * c + b * d + (a * d' + b * c') = a * c' + b * d' + (a * d + b * c)
calc
_ = a*(c+d') + b*(c'+d) := a:ℕb:ℕc:ℕd:ℕc':ℕd':ℕh:c + d' = c' + d⊢ a * c + b * d + (a * d' + b * c') = a * (c + d') + b * (c' + d) All goals completed! 🐙
_ = a*(c'+d) + b*(c+d') := a:ℕb:ℕc:ℕd:ℕc':ℕd':ℕh:c + d' = c' + d⊢ a * (c + d') + b * (c' + d) = a * (c' + d) + b * (c + d') All goals completed! 🐙
_ = _ := a:ℕb:ℕc:ℕd:ℕc':ℕd':ℕh:c + d' = c' + d⊢ a * (c' + d) + b * (c + d') = a * c' + b * d' + (a * d + b * c) All goals completed! 🐙Lemma 4.1.3 (Multiplication well-defined)
theorem Int.mul_congr {a b c d a' b' c' d' : ℕ} (h1: a —— b = a' —— b') (h2: c —— d = c' —— d') :
(a*c+b*d) —— (a*d+b*c) = (a'*c'+b'*d') —— (a'*d'+b'*c') := a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a —— b = a' —— b'h2:c —— d = c' —— d'⊢ (a * c + b * d) —— (a * d + b * c) = (a' * c' + b' * d') —— (a' * d' + b' * c')
All goals completed! 🐙instance Int.instMul : Mul Int where
mul := Quotient.lift₂ (fun ⟨ a, b ⟩ ⟨ c, d ⟩ ↦ (a * c + b * d) —— (a * d + b * c)) (⊢ ∀ (a₁ b₁ a₂ b₂ : PreInt),
a₁ ≈ a₂ →
b₁ ≈ b₂ →
(fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a * c + b * d) —— (a * d + b * c))
a₁ b₁ =
(fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a * c + b * d) —— (a * d + b * c))
a₂ b₂
a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:{ minuend := a, subtrahend := b } ≈ { minuend := a', subtrahend := b' }h2:{ minuend := c, subtrahend := d } ≈ { minuend := c', subtrahend := d' }⊢ (fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a * c + b * d) —— (a * d + b * c))
{ minuend := a, subtrahend := b } { minuend := c, subtrahend := d } =
(fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a * c + b * d) —— (a * d + b * c))
{ minuend := a', subtrahend := b' } { minuend := c', subtrahend := d' }
a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ (fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a * c + b * d) —— (a * d + b * c))
{ minuend := a, subtrahend := b } { minuend := c, subtrahend := d } =
(fun x x_1 =>
match x with
| { minuend := a, subtrahend := b } =>
match x_1 with
| { minuend := c, subtrahend := d } => (a * c + b * d) —— (a * d + b * c))
{ minuend := a', subtrahend := b' } { minuend := c', subtrahend := d' }
a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ a —— b = a' —— b'a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ c —— d = c' —— d' a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ a —— b = a' —— b'a:ℕb:ℕc:ℕd:ℕa':ℕb':ℕc':ℕd':ℕh1:a + b' = a' + bh2:c + d' = c' + d⊢ c —— d = c' —— d' All goals completed! 🐙
)Definition 4.1.2 (Multiplication of integers)
theorem Int.mul_eq (a b c d:ℕ) : a —— b * c —— d = (a*c+b*d) —— (a*d+b*c) := Quotient.lift₂_mk _ _ _ _instance Int.instOfNat {n:ℕ} : OfNat Int n where
ofNat := n —— 0instance Int.instNatCast : NatCast Int where
natCast n := n —— 0theorem Int.ofNat_eq (n:ℕ) : ofNat(n) = n —— 0 := rfltheorem Int.natCast_eq (n:ℕ) : (n:Int) = n —— 0 := rfl@[simp]
theorem Int.natCast_ofNat (n:ℕ) : ((ofNat(n):ℕ): Int) = ofNat(n) := n:ℕ⊢ ↑(OfNat.ofNat n) = OfNat.ofNat n All goals completed! 🐙@[simp]
theorem Int.ofNat_inj (n m:ℕ) :
(ofNat(n) : Int) = (ofNat(m) : Int) ↔ ofNat(n) = ofNat(m) := n:ℕm:ℕ⊢ OfNat.ofNat n = OfNat.ofNat m ↔ OfNat.ofNat n = OfNat.ofNat m
n:ℕm:ℕ⊢ n = m ↔ OfNat.ofNat n = OfNat.ofNat m
All goals completed! 🐙@[simp]
theorem Int.natCast_inj (n m:ℕ) :
(n : Int) = (m : Int) ↔ n = m := n:ℕm:ℕ⊢ ↑n = ↑m ↔ n = m
All goals completed! 🐙example : 3 = 3 —— 0 := ⊢ 3 = 3 —— 0 All goals completed! 🐙example : 3 = 4 —— 1 := ⊢ 3 = 4 —— 1
All goals completed! 🐙Definition 4.1.4 (Negation of integers) / Exercise 4.1.2
instance Int.instNeg : Neg Int where
neg := Quotient.lift (fun ⟨ a, b ⟩ ↦ b —— a) (⊢ ∀ (a b : PreInt),
a ≈ b →
(fun x =>
match x with
| { minuend := a, subtrahend := b } => b —— a)
a =
(fun x =>
match x with
| { minuend := a, subtrahend := b } => b —— a)
b
All goals completed! 🐙)theorem Int.neg_eq (a b:ℕ) : -(a —— b) = b —— a := rflexample : -(3 —— 5) = 5 —— 3 := ⊢ -3 —— 5 = 5 —— 3 All goals completed! 🐙abbrev Int.isPos (x:Int) : Prop := ∃ (n:ℕ), n > 0 ∧ x = nabbrev Int.isNeg (x:Int) : Prop := ∃ (n:ℕ), n > 0 ∧ x = -nLemma 4.1.5 (trichotomy of integers )
theorem Int.trichotomous (x:Int) : x = 0 ∨ x.isPos ∨ x.isNeg := x:Int⊢ x = 0 ∨ x.isPos ∨ x.isNeg
-- This proof is slightly modified from that in the original text.
a:ℕb:ℕ⊢ a —— b = 0 ∨ (a —— b).isPos ∨ (a —— b).isNeg
a:ℕb:ℕthis:a < b ∨ a = b ∨ b < a⊢ a —— b = 0 ∨ (a —— b).isPos ∨ (a —— b).isNeg
a:ℕb:ℕh_lt:a < b⊢ a —— b = 0 ∨ (a —— b).isPos ∨ (a —— b).isNega:ℕb:ℕh_eq:a = b⊢ a —— b = 0 ∨ (a —— b).isPos ∨ (a —— b).isNega:ℕb:ℕh_gt:b < a⊢ a —— b = 0 ∨ (a —— b).isPos ∨ (a —— b).isNeg
a:ℕb:ℕh_lt:a < b⊢ a —— b = 0 ∨ (a —— b).isPos ∨ (a —— b).isNeg a:ℕc:ℕh_lt:a < a + c + 1⊢ a —— (a + c + 1) = 0 ∨ (a —— (a + c + 1)).isPos ∨ (a —— (a + c + 1)).isNeg
a:ℕc:ℕh_lt:a < a + c + 1⊢ (a —— (a + c + 1)).isPos ∨ (a —— (a + c + 1)).isNeg; a:ℕc:ℕh_lt:a < a + c + 1⊢ (a —— (a + c + 1)).isNeg; a:ℕc:ℕh_lt:a < a + c + 1⊢ c + 1 > 0a:ℕc:ℕh_lt:a < a + c + 1⊢ a —— (a + c + 1) = -↑(c + 1)
a:ℕc:ℕh_lt:a < a + c + 1⊢ c + 1 > 0 All goals completed! 🐙
a:ℕc:ℕh_lt:a < a + c + 1⊢ a + (c + 1) = 0 + (a + c + 1)
All goals completed! 🐙
a:ℕb:ℕh_eq:a = b⊢ a —— b = 0 ∨ (a —— b).isPos ∨ (a —— b).isNeg a:ℕb:ℕh_eq:a = b⊢ a —— b = 0; All goals completed! 🐙
b:ℕc:ℕh_gt:b < b + c + 1⊢ (b + c + 1) —— b = 0 ∨ ((b + c + 1) —— b).isPos ∨ ((b + c + 1) —— b).isNeg
b:ℕc:ℕh_gt:b < b + c + 1⊢ ((b + c + 1) —— b).isPos ∨ ((b + c + 1) —— b).isNeg; b:ℕc:ℕh_gt:b < b + c + 1⊢ ((b + c + 1) —— b).isPos; b:ℕc:ℕh_gt:b < b + c + 1⊢ c + 1 > 0b:ℕc:ℕh_gt:b < b + c + 1⊢ (b + c + 1) —— b = ↑(c + 1)
b:ℕc:ℕh_gt:b < b + c + 1⊢ c + 1 > 0 All goals completed! 🐙
b:ℕc:ℕh_gt:b < b + c + 1⊢ b + c + 1 + 0 = c + 1 + b
All goals completed! 🐙Lemma 4.1.5 (trichotomy of integers)
theorem Int.not_pos_zero (x:Int) : x = 0 ∧ x.isPos → False := x:Int⊢ x = 0 ∧ x.isPos → False
n:ℕhn:n > 0hn':0 = ↑n⊢ False
n:ℕhn:n > 0hn':0 = n⊢ False
All goals completed! 🐙Lemma 4.1.5 (trichotomy of integers)
theorem Int.not_neg_zero (x:Int) : x = 0 ∧ x.isNeg → False := x:Int⊢ x = 0 ∧ x.isNeg → False
n:ℕhn:n > 0hn':0 = -↑n⊢ False
n:ℕhn:n > 0hn':0 + n = 0 + 0⊢ False
All goals completed! 🐙Lemma 4.1.5 (trichotomy of integers)
theorem Int.not_pos_neg (x:Int) : x.isPos ∧ x.isNeg → False := x:Int⊢ x.isPos ∧ x.isNeg → False
n:ℕhn:n > 0m:ℕhm:m > 0hm':↑n = -↑m⊢ False
n:ℕhn:n > 0m:ℕhm:m > 0hm':n + m = 0 + 0⊢ False
All goals completed! 🐙Proposition 4.1.6 (laws of algebra) / Exercise 4.1.4
instance Int.instAddGroup : AddGroup Int :=
AddGroup.ofLeftAxioms (⊢ ∀ (a b c : Int), a + b + c = a + (b + c) All goals completed! 🐙) (⊢ ∀ (a : Int), 0 + a = a All goals completed! 🐙) (⊢ ∀ (a : Int), -a + a = 0 All goals completed! 🐙)Proposition 4.1.6 (laws of algebra) / Exercise 4.1.4
instance Int.instAddCommGroup : AddCommGroup Int where
add_comm := ⊢ ∀ (a b : Int), a + b = b + a All goals completed! 🐙Proposition 4.1.6 (laws of algebra) / Exercise 4.1.4
instance Int.instCommMonoid : CommMonoid Int where
mul_comm := ⊢ ∀ (a b : Int), a * b = b * a All goals completed! 🐙
mul_assoc := ⊢ ∀ (a b c : Int), a * b * c = a * (b * c)
-- This proof is written to follow the structure of the original text.
x:Inty:Intz:Int⊢ x * y * z = x * (y * z)
y:Intz:Inta:ℕb:ℕ⊢ a —— b * y * z = a —— b * (y * z)
z:Inta:ℕb:ℕc:ℕd:ℕ⊢ a —— b * c —— d * z = a —— b * (c —— d * z)
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕ⊢ a —— b * c —— d * e —— f = a —— b * (c —— d * e —— f)
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕ⊢ ((a * c + b * d) * e + (a * d + b * c) * f) —— ((a * c + b * d) * f + (a * d + b * c) * e) =
(a * (c * e + d * f) + b * (c * f + d * e)) —— (a * (c * f + d * e) + b * (c * e + d * f))
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕ⊢ (a * c + b * d) * e + (a * d + b * c) * f = a * (c * e + d * f) + b * (c * f + d * e)a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕ⊢ (a * c + b * d) * f + (a * d + b * c) * e = a * (c * f + d * e) + b * (c * e + d * f)
a:ℕb:ℕc:ℕd:ℕe:ℕf:ℕ⊢ (a * c + b * d) * e + (a * d + b * c) * f = a * (c * e + d * f) + b * (c * f + d * e) All goals completed! 🐙
All goals completed! 🐙
one_mul := ⊢ ∀ (a : Int), 1 * a = a All goals completed! 🐙
mul_one := ⊢ ∀ (a : Int), a * 1 = a All goals completed! 🐙Proposition 4.1.6 (laws of algebra) / Exercise 4.1.4
instance Int.instCommRing : CommRing Int where
left_distrib := ⊢ ∀ (a b c : Int), a * (b + c) = a * b + a * c All goals completed! 🐙
right_distrib := ⊢ ∀ (a b c : Int), (a + b) * c = a * c + b * c All goals completed! 🐙
zero_mul := ⊢ ∀ (a : Int), 0 * a = 0 All goals completed! 🐙
mul_zero := ⊢ ∀ (a : Int), a * 0 = 0 All goals completed! 🐙Definition of subtraction
theorem Int.sub_eq (a b:Int) : a - b = a + (-b) := a:Intb:Int⊢ a - b = a + -b All goals completed! 🐙theorem Int.sub_eq_formal_sub (a b:ℕ) : (a:Int) - (b:Int) = a —— b := a:ℕb:ℕ⊢ ↑a - ↑b = a —— b All goals completed! 🐙Proposition 4.1.8 (No zero divisors) / Exercise 4.1.5
theorem Int.mul_eq_zero {a b:Int} (h: a * b = 0) : a = 0 ∨ b = 0 := a:Intb:Inth:a * b = 0⊢ a = 0 ∨ b = 0 All goals completed! 🐙Corollary 4.1.9 (Cancellation law) / Exercise 4.1.6
theorem Int.mul_right_cancel₀ (a b c:Int) (h: a*c = b*c) (hc: c ≠ 0) : a = b := a:Intb:Intc:Inth:a * c = b * chc:c ≠ 0⊢ a = b All goals completed! 🐙Definition 4.1.10 (Ordering of the integers)
instance Int.instLE : LE Int where
le n m := ∃ a:ℕ, m = n + aDefinition 4.1.10 (Ordering of the integers)
instance Int.instLT : LT Int where
lt n m := (∃ a:ℕ, m = n + a) ∧ n ≠ mtheorem Int.le_iff (n m:Int) : n ≤ m ↔ ∃ a:ℕ, m = n + a := n:Intm:Int⊢ n ≤ m ↔ ∃ a, m = n + ↑a All goals completed! 🐙theorem Int.lt_iff (n m:Int): n < m ↔ (∃ a:ℕ, m = n + a) ∧ n ≠ m := n:Intm:Int⊢ n < m ↔ (∃ a, m = n + ↑a) ∧ n ≠ m All goals completed! 🐙Lemma 4.1.11(a) (Properties of order) / Exercise 4.1.7
theorem Int.gt_iff (a b:Int) : a > b ↔ ∃ n:ℕ, n ≠ 0 ∧ a = b + n := a:Intb:Int⊢ a > b ↔ ∃ n, n ≠ 0 ∧ a = b + ↑n All goals completed! 🐙Lemma 4.1.11(b) (Addition preserves order) / Exercise 4.1.7
theorem Int.add_gt_add_right {a b:Int} (c:Int) (h: a > b) : a+c > b+c := a:Intb:Intc:Inth:a > b⊢ a + c > b + c All goals completed! 🐙Lemma 4.1.11(c) (Positive multiplication preserves order) / Exercise 4.1.7
theorem Int.mul_lt_mul_of_pos_left {a b c:Int} (hab : a > b) (hc: c > 0) : a*c > b*c := a:Intb:Intc:Inthab:a > bhc:c > 0⊢ a * c > b * c All goals completed! 🐙Lemma 4.1.11(d) (Negation reverses order) / Exercise 4.1.7
theorem Int.neg_gt_neg {a b:Int} (h: a > b) : -a < -b := a:Intb:Inth:a > b⊢ -a < -b All goals completed! 🐙Lemma 4.1.11(e) (Order is transitive) / Exercise 4.1.7
theorem Int.gt_trans {a b c:Int} (hab: a > b) (hbc: b > c) : a > c := a:Intb:Intc:Inthab:a > bhbc:b > c⊢ a > c All goals completed! 🐙Lemma 4.1.11(f) (Order trichotomy) / Exercise 4.1.7
theorem Int.trichotomous' (a b c:Int) : a > b ∨ a < b ∨ a = b := a:Intb:Intc:Int⊢ a > b ∨ a < b ∨ a = b All goals completed! 🐙Lemma 4.1.11(f) (Order trichotomy) / Exercise 4.1.7
theorem Int.not_gt_and_lt (a b:Int) : ¬ (a > b ∧ a < b):= a:Intb:Int⊢ ¬(a > b ∧ a < b) All goals completed! 🐙Lemma 4.1.11(f) (Order trichotomy) / Exercise 4.1.7
theorem Int.not_gt_and_eq (a b:Int) : ¬ (a > b ∧ a = b):= a:Intb:Int⊢ ¬(a > b ∧ a = b) All goals completed! 🐙Lemma 4.1.11(f) (Order trichotomy) / Exercise 4.1.7
theorem Int.not_lt_and_eq (a b:Int) : ¬ (a < b ∧ a = b):= a:Intb:Int⊢ ¬(a < b ∧ a = b) All goals completed! 🐙
(Not from textbook) The order is decidable. This exercise is only recommended for Lean experts. Alternatively, one can establish this fact in classical logic via classical; exact Classical.decRel _.
instance Int.decidableRel : DecidableRel (· ≤ · : Int → Int → Prop) := ⊢ DecidableRel fun x1 x2 => x1 ≤ x2
All goals completed! 🐙(Not from textbook) Int has the structure of a linear ordering.
instance Int.instLinearOrder : LinearOrder Int where
le_refl := sorry
le_trans := sorry
lt_iff_le_not_le := sorry
le_antisymm := sorry
le_total := sorry
toDecidableLE := decidableRelExercise 4.1.3
theorem Int.neg_one_mul (a:Int) : -1 * a = -a := a:Int⊢ -1 * a = -a All goals completed! 🐙Exercise 4.1.8
theorem Int.no_induction : ∃ P: Int → Prop, P 0 ∧ ∀ n, P n → P (n+1) ∧ ¬ ∀ n, P n := ⊢ ∃ P, P 0 ∧ ∀ (n : Int), P n → P (n + 1) ∧ ¬∀ (n : Int), P n All goals completed! 🐙Exercise 4.1.9
theorem Int.sq_nonneg (n:Int) : n*n ≥ 0 := n:Int⊢ n * n ≥ 0 All goals completed! 🐙Exercise 4.1.9
theorem Int.sq_nonneg' (n:Int) : ∃ (m:Nat), n*n = m := n:Int⊢ ∃ m, n * n = ↑m All goals completed! 🐙Not in textbook: create an equivalence between Int and ℤ. This requires some familiarity with the API for Mathlib's version of the integers.
abbrev Int.equivInt : Int ≃ ℤ where
toFun := Quotient.lift (fun ⟨ a, b ⟩ ↦ a - b) (⊢ ∀ (a b : PreInt),
a ≈ b →
(fun x =>
match x with
| { minuend := a, subtrahend := b } => ↑a - ↑b)
a =
(fun x =>
match x with
| { minuend := a, subtrahend := b } => ↑a - ↑b)
b
All goals completed! 🐙)
invFun := sorry
left_inv n := sorry
right_inv n := sorryNot in textbook: equivalence preserves order
abbrev Int.equivInt_order : Int ≃o ℤ where
toEquiv := equivInt
map_rel_iff' := ⊢ ∀ {a b : Int}, equivInt a ≤ equivInt b ↔ a ≤ b All goals completed! 🐙Not in textbook: equivalence preserves ring operations
abbrev Int.equivInt_ring : Int ≃+* ℤ where
toEquiv := equivInt
map_add' := ⊢ ∀ (x y : Int), equivInt.toFun (x + y) = equivInt.toFun x + equivInt.toFun y All goals completed! 🐙
map_mul' := ⊢ ∀ (x y : Int), equivInt.toFun (x * y) = equivInt.toFun x * equivInt.toFun y All goals completed! 🐙end Section_4_1