The integers

Analysis I, Section 4.1: The integers

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 : TypeSection_4_1.Int, as formal differences Unknown identifier `a`sorry —— sorry : Section_4_1.Inta —— Unknown identifier `b`b of natural numbers , up to equivalence. (This is a quotient of a scaffolding type Section_4_1.PreInt : 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 Int : Type_root_.Int (or : Type), which we will use going forward.

Tips from past users

Users of the companion who have completed the exercises in this section are welcome to send their tips for future users in this section as PRs.

  • (Add tip here)

namespace Section_4_1structure PreInt where minuend : subtrahend :

Definition 4.1.1

instance declaration uses 'sorry'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 + da + f = e + b a:b:c:d:e:f:h1:a + d = c + bh2:c + f = e + dh3:?_mvar.1854 := congrArg₂ (fun x1 x2 => x1 + x2) _fvar.1847 _fvar.1848a + f = e + b; a:b:c:d:e:f:h1:a + d = c + bh2:c + f = e + dh3:_fvar.591 + _fvar.678 + (_fvar.677 + _fvar.754) = _fvar.677 + _fvar.592 + (_fvar.753 + _fvar.678) := congrArg₂ (fun x1 x2 => x1 + x2) _fvar.1847 _fvar.1848a + 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:_fvar.591 + _fvar.678 + (_fvar.677 + _fvar.754) = _fvar.677 + _fvar.592 + (_fvar.753 + _fvar.678) := congrArg₂ (fun x1 x2 => x1 + x2) _fvar.1847 _fvar.1848a + 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:_fvar.591 + _fvar.678 + (_fvar.677 + _fvar.754) = _fvar.677 + _fvar.592 + (_fvar.753 + _fvar.678) := congrArg₂ (fun x1 x2 => x1 + x2) _fvar.1847 _fvar.1848c + 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.formalDiff

Definition 4.1.1 (Integers)

theorem Int.eq (a b c d:): a —— b = c —— d a + d = c + b := Quotient.exact, a:b:c:d:a + d = c + b a —— b = c —— d a:b:c:d:h:a + d = c + ba —— b = c —— d; All goals completed! 🐙

Decidability of equality

instance Int.decidableEq : DecidableEq Int := DecidableEq Int a:Intb:IntDecidable (a = b) have : (n:PreInt) (m: PreInt), Decidable (Quotient.mk PreInt.instSetoid n = Quotient.mk PreInt.instSetoid m) := DecidableEq Int a✝:Intb✝:Inta:b:c:d:Decidable ({ minuend := a, subtrahend := b } = { minuend := c, subtrahend := d }) a✝:Intb✝:Inta:b:c:d:Decidable (a + d = c + b) All goals completed! 🐙 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, a = a_1 —— b; n:Inta:b: a_1 b_1, { minuend := a, subtrahend := b } = a_1 —— b_1; 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' + da + 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' + da + 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' + da + 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' + da' + 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' + ba * 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' + ba * 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' + bc * (a + b') + d * (a' + b) = c * (a' + b) + d * (a + b') All goals completed! 🐙 _ = _ := a:b:a':b':c:d:h:a + b' = a' + bc * (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' + da * 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' + da * 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' + da * (c + d') + b * (c' + d) = a * (c' + d) + b * (c + d') All goals completed! 🐙 _ = _ := a:b:c:d:c':d':h:c + d' = c' + da * (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' + da —— b = a' —— b'a:b:c:d:a':b':c':d':h1:a + b' = a' + bh2:c + d' = c' + dc —— d = c' —— d' a:b:c:d:a':b':c':d':h1:a + b' = a' + bh2:c + d' = c' + da —— b = a' —— b'a:b:c:d:a':b':c':d':h1:a + b' = a' + bh2:c + d' = c' + dc —— 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 := rflexample : 3 = 4 —— 1 := 3 = 4 —— 1 All goals completed! 🐙

(Not from textbook) 0 is the only natural whose cast is 0

lemma declaration uses 'sorry'Int.cast_eq_0_iff_eq_0 (n : ) : (n : Int) = 0 n = 0 := n:n = 0 n = 0 All goals completed! 🐙

Definition 4.1.4 (Negation of integers) / Exercise 4.1.2

instance declaration uses 'sorry'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 := rflabbrev Int.IsPos (x:Int) : Prop := (n:), n > 0 x = nabbrev Int.IsNeg (x:Int) : Prop := (n:), n > 0 x = -n

Lemma 4.1.5 (trichotomy of integers )

theorem Int.trichotomous (x:Int) : x = 0 x.IsPos x.IsNeg := x:Intx = 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:h_lt:a < ba —— b = 0 (a —— b).IsPos (a —— b).IsNega:a —— a = 0 (a —— a).IsPos (a —— a).IsNega:b:h_gt:b < aa —— b = 0 (a —— b).IsPos (a —— b).IsNeg a:b:h_lt:a < ba —— b = 0 (a —— b).IsPos (a —— b).IsNeg a:c:h_lt:a < a + c + 1a —— (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; refine c+1, a:c:h_lt:a < a + c + 1c + 1 > 0 All goals completed! 🐙, ?_ a:c:h_lt:a < a + c + 1a + (c + 1) = 0 + (a + c + 1); All goals completed! 🐙 a:a —— a = 0 (a —— a).IsPos (a —— a).IsNeg a:a —— a = 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; refine c+1, b:c:h_gt:b < b + c + 1c + 1 > 0 All goals completed! 🐙, ?_ b:c:h_gt:b < b + c + 1b + 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:Intx = 0 x.IsPos False n:left✝:n > 0right✝:0 = nFalse; All goals completed! 🐙

Lemma 4.1.5 (trichotomy of integers)

theorem Int.not_neg_zero (x:Int) : x = 0 x.IsNeg False := x:Intx = 0 x.IsNeg False n:left✝:n > 0hn:0 = -nFalse; n:left✝:n > 0hn:0 + n = 0 + 0False All goals completed! 🐙

Lemma 4.1.5 (trichotomy of integers)

theorem Int.not_pos_neg (x:Int) : x.IsPos x.IsNeg False := x:Intx.IsPos x.IsNeg False n:left✝¹:n > 0m:left✝:m > 0hm:n = -mFalse; n:left✝¹:n > 0m:left✝:m > 0hm:n + m = 0 + 0False All goals completed! 🐙

Proposition 4.1.6 (laws of algebra) / Exercise 4.1.4

instance declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'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 declaration uses 'sorry'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 declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'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:Intx * 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)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) 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 declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'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:Inta - b = a + -b All goals completed! 🐙
theorem declaration uses 'sorry'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 declaration uses 'sorry'Int.mul_eq_zero {a b:Int} (h: a * b = 0) : a = 0 b = 0 := a:Intb:Inth:a * b = 0a = 0 b = 0 All goals completed! 🐙

Corollary 4.1.9 (Cancellation law) / Exercise 4.1.6

theorem declaration uses 'sorry'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 0a = b All goals completed! 🐙

Definition 4.1.10 (Ordering of the integers)

instance Int.instLE : LE Int where le n m := a:, m = n + a

Definition 4.1.10 (Ordering of the integers)

instance Int.instLT : LT Int where lt n m := n m n m
theorem Int.le_iff (a b:Int) : a b t:, b = a + t := a:Intb:Inta b t, b = a + t All goals completed! 🐙theorem Int.lt_iff (a b:Int): a < b ( t:, b = a + t) a b := a:Intb:Inta < b (∃ t, b = a + t) a b All goals completed! 🐙

Lemma 4.1.11(a) (Properties of order) / Exercise 4.1.7

theorem declaration uses 'sorry'Int.lt_iff_exists_positive_difference (a b:Int) : a < b n:, n 0 b = a + n := a:Intb:Inta < b n, n 0 b = a + n All goals completed! 🐙

Lemma 4.1.11(b) (Addition preserves order) / Exercise 4.1.7

theorem declaration uses 'sorry'Int.add_lt_add_right {a b:Int} (c:Int) (h: a < b) : a+c < b+c := a:Intb:Intc:Inth:a < ba + c < b + c All goals completed! 🐙

Lemma 4.1.11(c) (Positive multiplication preserves order) / Exercise 4.1.7

theorem declaration uses 'sorry'Int.mul_lt_mul_of_pos_right {a b c:Int} (hab : a < b) (hc: 0 < c) : a*c < b*c := a:Intb:Intc:Inthab:a < bhc:0 < ca * c < b * c All goals completed! 🐙

Lemma 4.1.11(d) (Negation reverses order) / Exercise 4.1.7

theorem declaration uses 'sorry'Int.neg_gt_neg {a b:Int} (h: b < a) : -a < -b := a:Intb:Inth:b < a-a < -b All goals completed! 🐙

Lemma 4.1.11(d) (Negation reverses order) / Exercise 4.1.7

theorem declaration uses 'sorry'Int.neg_ge_neg {a b:Int} (h: b a) : -a -b := a:Intb:Inth:b a-a -b All goals completed! 🐙

Lemma 4.1.11(e) (Order is transitive) / Exercise 4.1.7

theorem declaration uses 'sorry'Int.lt_trans {a b c:Int} (hab: a < b) (hbc: b < c) : a < c := a:Intb:Intc:Inthab:a < bhbc:b < ca < c All goals completed! 🐙

Lemma 4.1.11(f) (Order trichotomy) / Exercise 4.1.7

theorem declaration uses 'sorry'Int.trichotomous' (a b:Int) : a > b a < b a = b := a:Intb:Inta > b a < b a = b All goals completed! 🐙

Lemma 4.1.11(f) (Order trichotomy) / Exercise 4.1.7

theorem declaration uses 'sorry'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 declaration uses 'sorry'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 declaration uses 'sorry'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) Establish the decidability of this order.

instance declaration uses 'sorry'declaration uses 'sorry'Int.decidableRel : DecidableRel (· ·: Int Int Prop) := DecidableRel fun x1 x2 => x1 x2 n:Intm:IntDecidable ((fun x1 x2 => x1 x2) n m) have : (n:PreInt) (m: PreInt), Decidable (Quotient.mk PreInt.instSetoid n Quotient.mk PreInt.instSetoid m) := DecidableRel fun x1 x2 => x1 x2 n:Intm:Inta:b:c:d:Decidable ({ minuend := a, subtrahend := b } { minuend := c, subtrahend := d }) n:Intm:Inta:b:c:d:Decidable (a —— b c —— d) cases (a + d).decLe (b + c) with n:Intm:Inta:b:c:d:h:a + d b + cDecidable (a —— b c —— d) n:Intm:Inta:b:c:d:h:a + d b + ca —— b c —— d All goals completed! 🐙 n:Intm:Inta:b:c:d:h:¬a + d b + cDecidable (a —— b c —— d) n:Intm:Inta:b:c:d:h:¬a + d b + c¬a —— b c —— d All goals completed! 🐙 All goals completed! 🐙

(Not from textbook) 0 is the only additive identity

lemma declaration uses 'sorry'Int.is_additive_identity_iff_eq_0 (b : Int) : ( a, a = a + b) b = 0 := b:Int(∀ (a : Int), a = a + b) b = 0 All goals completed! 🐙

(Not from textbook) Int has the structure of a linear ordering.

instance declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'Int.instLinearOrder : LinearOrder Int where le_refl := sorry le_trans := sorry lt_iff_le_not_ge := sorry le_antisymm := sorry le_total := sorry toDecidableLE := decidableRel

Exercise 4.1.3

theorem declaration uses 'sorry'Int.neg_one_mul (a:Int) : -1 * a = -a := a:Int-1 * a = -a All goals completed! 🐙

Exercise 4.1.8

theorem declaration uses 'sorry'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! 🐙

A nonnegative number squared is nonnegative. This is a special case of 4.1.9 that's useful for proving the general case. -

lemma declaration uses 'sorry'Int.sq_nonneg_of_pos (n:Int) (h: 0 n) : 0 n*n := n:Inth:0 n0 n * n All goals completed! 🐙

Exercise 4.1.9. The square of any integer is nonnegative.

theorem declaration uses 'sorry'Int.sq_nonneg (n:Int) : 0 n*n := n:Int0 n * n All goals completed! 🐙

Exercise 4.1.9

theorem declaration uses 'sorry'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 declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'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 := sorry

Not in textbook: equivalence preserves order and ring operations

abbrev declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'Int.equivInt_ordered_ring : Int ≃+*o 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! 🐙 map_le_map_iff' := {a b : Int}, equivInt.toFun a equivInt.toFun b a b All goals completed! 🐙
end Section_4_1