···11+section
22+ variable {U : Type}
33+ variables {A B C : set U}
44+55+ example : ∀ x, x ∈ A ∩ C → x ∈ A ∪ B :=
66+ assume x : U,
77+ assume : x ∈ A ∩ C,
88+ show x ∈ A ∪ B, from or.inl (and.left this)
99+1010+ example : ∀ x, x ∈ -(A ∪ B) → x ∈ -A :=
1111+ assume x,
1212+ assume h1 : x ∈ -(A ∪ B),
1313+ show x ∈ -A, from
1414+ assume : x ∈ A,
1515+ show false, from h1 (or.inl this)
1616+end
1717+1818+---
1919+2020+import data.set
2121+open set
2222+2323+section
2424+variable {U : Type}
2525+2626+example (A B C : set U) : ∀ x, x ∈ A ∩ C → x ∈ A ∪ B :=
2727+assume x,
2828+assume : x ∈ A ∩ C,
2929+show x ∈ A ∪ B, from or.inl this.left
3030+3131+example (A B : set U) : ∀ x, x ∈ -(A ∪ B) → x ∈ -A :=
3232+assume x,
3333+assume : x ∈ -(A ∪ B),
3434+show x ∈ -A, from
3535+ assume : x ∈ A,
3636+ show false, from ‹ x ∈ -(A ∪ B) › (or.inl this)
3737+3838+/- defining "disjoint" -/
3939+4040+def disj (A B : set U) : Prop := ∀ ⦃x⦄, x ∈ A → x ∈ B → false
4141+4242+example (A B : set U) (h : ∀ x, ¬ (x ∈ A ∧ x ∈ B)) :
4343+ disj A B :=
4444+assume x,
4545+assume h1 : x ∈ A,
4646+assume h2 : x ∈ B,
4747+have h3 : x ∈ A ∧ x ∈ B, from and.intro h1 h2,
4848+show false, from h x h3
4949+5050+-- notice that we do not have to mention x when applying
5151+-- h : disj A B
5252+example (A B : set U) (h1 : disj A B) (x : U)
5353+ (h2 : x ∈ A) (h3 : x ∈ B) :
5454+ false :=
5555+h1 h2 h3
5656+5757+-- the same is true of ⊆
5858+example (A B : set U) (x : U) (h : A ⊆ B) (h1 : x ∈ A) :
5959+ x ∈ B :=
6060+h h1
6161+6262+example (A B C D : set U) (h1 : disj A B) (h2 : C ⊆ A)
6363+ (h3 : D ⊆ B) :
6464+ disj C D :=
6565+assume x,
6666+assume : x ∈ C,
6767+assume : x ∈ D,
6868+show false, from h1 (h2 ‹ x ∈ C › ) (h3 ‹ x ∈ D ›)
6969+end
7070+7171+---
7272+7373+import data.set
7474+open set
7575+7676+section
7777+variables {I U : Type}
7878+variables {A B : I → set U}
7979+8080+theorem Inter.intro {x : U} (h : ∀ i, x ∈ A i) : x ∈ ⋂ i, A i :=
8181+by simp; assumption
8282+8383+@[elab_simple]
8484+theorem Inter.elim {x : U} (h : x ∈ ⋂ i, A i) (i : I) : x ∈ A i :=
8585+by simp at h; apply h
8686+8787+theorem Union.intro {x : U} (i : I) (h : x ∈ A i) : x ∈ ⋃ i, A i :=
8888+by {simp, existsi i, exact h}
8989+9090+theorem Union.elim {b : Prop} {x : U}
9191+(h₁ : x ∈ ⋃ i, A i) (h₂ : ∀ (i : I), x ∈ A i → b) : b :=
9292+by {simp at h₁, cases h₁ with i h, exact h₂ i h}
9393+9494+end
9595+9696+-- BEGIN
9797+variables {I U : Type}
9898+variables (A : I → set U) (B : I → set U) (C : set U)
9999+100100+example : (⋂ i, A i) ∩ (⋂ i, B i) ⊆ (⋂ i, A i ∩ B i) :=
101101+assume x,
102102+assume h1 : x ∈ (⋂ i, A i) ∩ (⋂ i, B i),
103103+show x ∈ (⋂ i, A i ∩ B i), from
104104+ have h2 : ∀ i, x ∈ A i ∩ B i, from
105105+ assume i : I,
106106+ have x ∈ A i, from Inter.elim (h1.left) i,
107107+ have x ∈ B i, from Inter.elim (h1.right) i,
108108+ ⟨ ‹ x ∈ A i › , ‹ x ∈ B i › ⟩,
109109+ Inter.intro h2
110110+111111+example : C ∩ (⋃i, A i) ⊆ ⋃i, C ∩ A i :=
112112+assume x,
113113+assume h,
114114+have h2 : ∀ (i : I), x ∈ A i → x ∈ ⋃i, C ∩ A i, from
115115+ assume i : I,
116116+ assume h1,
117117+ have x ∈ C ∩ A i, from ⟨ h.left , h1 ⟩,
118118+ Union.intro i ‹ x ∈ C ∩ A i › ,
119119+120120+Union.elim h.right h2
121121+122122+-- END
123123+124124+---
125125+126126+import data.set
127127+open set
128128+129129+-- BEGIN
130130+variable {U : Type}
131131+variables A B C : set U
132132+133133+-- For this exercise these two facts are useful
134134+example (h1 : A ⊆ B) (h2 : B ⊆ C) : A ⊆ C :=
135135+subset.trans h1 h2
136136+137137+example : A ⊆ A :=
138138+subset.refl A
139139+140140+example (h : A ⊆ B) : powerset A ⊆ powerset B :=
141141+assume x,
142142+assume : x ∈ powerset A,
143143+have x ⊆ A, from ‹ x ∈ powerset A ›,
144144+have x ⊆ B, from subset.trans ‹ x ⊆ A › h,
145145+show x ∈ powerset B, from ‹ x ⊆ B ›
146146+147147+example (h : powerset A ⊆ powerset B) : A ⊆ B :=
148148+assume x,
149149+assume : x ∈ A,
150150+h (subset.refl A) ‹ x ∈ A ›
151151+-- END
+83
src/ch14.lean
···11+22+---
33+44+section
55+parameters {A : Type} {R : A → A → Prop}
66+parameter (irreflR : irreflexive R)
77+parameter (transR : transitive R)
88+99+local infix < := R
1010+1111+def R' (a b : A) : Prop := R a b ∨ a = b
1212+local infix ≤ := R'
1313+1414+theorem reflR' (a : A) : a ≤ a := or.inr (refl a)
1515+1616+theorem transR' {a b c : A} (h1 : a ≤ b) (h2 : b ≤ c):
1717+ a ≤ c :=
1818+ or.elim h1
1919+ (assume : a < b,
2020+ show a ≤ c, from
2121+ or.elim h2
2222+ (assume : b < c, or.inl (transR ‹ a < b › ‹ b < c ›))
2323+ (assume : b = c, or.inl (eq.subst ‹ b = c › ‹ a < b ›)))
2424+ (assume : a = b,
2525+ show a ≤ c, from
2626+ or.elim h2
2727+ (assume : b < c, or.inl (eq.symm ‹ a = b › ▸ ‹ b < c ›))
2828+ (assume : b = c, or.inr (‹ b = c › ▸ ‹ a = b ›)))
2929+3030+theorem antisymmR' {a b : A} (h1 : a ≤ b) (h2 : b ≤ a) :
3131+ a = b :=
3232+ or.elim h1
3333+ (assume : a < b,
3434+ or.elim h2
3535+ (assume : b < a, have false, from (irreflR a) (transR ‹ a < b › ‹ b < a ›), ‹ false ›.elim)
3636+ (assume : b = a, eq.symm this)
3737+ )
3838+ (assume : a = b, eq.symm (eq.symm this))
3939+end
4040+4141+---
4242+4343+section
4444+parameters {A : Type} {R : A → A → Prop}
4545+parameter (reflR : reflexive R)
4646+parameter (transR : transitive R)
4747+4848+def S (a b : A) : Prop := R a b ∧ R b a
4949+5050+example : transitive S :=
5151+assume a b c,
5252+assume h1 h2,
5353+⟨ transR h1.left h2.left , transR h2.right h1.right ⟩
5454+5555+end
5656+5757+---
5858+5959+section
6060+ parameters {A : Type} {a b c : A} {R : A → A → Prop}
6161+ parameter (Rab : R a b)
6262+ parameter (Rbc : R b c)
6363+ parameter (nRac : ¬ R a c)
6464+6565+ -- Prove one of the following two theorems:
6666+6767+ theorem R_is_strict_partial_order :
6868+ irreflexive R ∧ transitive R :=
6969+ sorry
7070+7171+ theorem R_is_not_strict_partial_order :
7272+ ¬(irreflexive R ∧ transitive R) :=
7373+ assume h : irreflexive R ∧ transitive R,
7474+ show false, from
7575+ nRac (h.right Rab Rbc)
7676+end
7777+7878+---
7979+8080+open nat
8181+8282+example : 1 ≤ 4 :=
8383+le_succ_of_le $ le_succ_of_le $ le_succ 1
+117
src/ch16.lean
···11+open function int algebra
22+33+def f (x : ℤ) : ℤ := x + 3
44+def g (x : ℤ) : ℤ := -x
55+def h (x : ℤ) : ℤ := 2 * x + 3
66+77+example : injective f :=
88+assume x1 x2,
99+assume h1 : x1 + 3 = x2 + 3, -- Lean knows this is the same as f x1 = f x2
1010+show x1 = x2, from eq_of_add_eq_add_right h1
1111+1212+example : surjective f :=
1313+assume y,
1414+have h1 : f (y - 3) = y, from calc
1515+ f (y - 3) = (y - 3) + 3 : rfl
1616+ ... = y : by rw sub_add_cancel,
1717+show ∃ x, f x = y, from exists.intro (y - 3) h1
1818+1919+example (x y : ℤ) (h : 2 * x = 2 * y) : x = y :=
2020+have h1 : 2 ≠ (0 : ℤ), from dec_trivial, -- this tells Lean to figure it out itself
2121+show x = y, from eq_of_mul_eq_mul_left h1 h
2222+2323+example (x : ℤ) : -(-x) = x := neg_neg x
2424+2525+example (A B : Type) (u : A → B) (v : B → A) (h : left_inverse u v) :
2626+ ∀ x, u (v x) = x :=
2727+h
2828+2929+example (A B : Type) (u : A → B) (v : B → A) (h : left_inverse u v) :
3030+ right_inverse v u :=
3131+h
3232+3333+-- fill in the sorry's in the following proofs
3434+3535+example : injective h :=
3636+assume x₁ x₂,
3737+assume : 2 * x₁ + 3 = 2 * x₂ + 3,
3838+have 2 * x₁ = 2 * x₂ , from eq_of_add_eq_add_right this,
3939+have 2 ≠ (0 : ℤ), from dec_trivial,
4040+show x₁ = x₂ , from eq_of_mul_eq_mul_left this ‹ 2 * x₁ = 2 * x₂ ›
4141+4242+example : surjective g :=
4343+assume y,
4444+have h₁ : g (-y) = y, from calc
4545+ g (-y) = -(-y): rfl
4646+ ... = y: by rw neg_neg,
4747+show ∃ x, g x = y, from exists.intro (-y) h₁
4848+4949+example (A B : Type) (u : A → B) (v1 : B → A) (v2 : B → A)
5050+ (h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=
5151+funext
5252+ (assume x,
5353+ calc
5454+ v1 x = v1 (u (v2 x)) : by rw (h2 x)
5555+ ... = v2 x : by rw (h1 (v2 x)))
5656+5757+---
5858+5959+import data.set
6060+open function set
6161+6262+variables {X Y : Type}
6363+variable f : X → Y
6464+variables A B : set X
6565+6666+example : f '' (A ∪ B) = f '' A ∪ f '' B :=
6767+eq_of_subset_of_subset
6868+ (assume y,
6969+ assume h1 : y ∈ f '' (A ∪ B),
7070+ exists.elim h1 $
7171+ assume x h,
7272+ have h2 : x ∈ A ∪ B, from h.left,
7373+ have h3 : f x = y, from h.right,
7474+ or.elim h2
7575+ (assume h4 : x ∈ A,
7676+ have h5 : y ∈ f '' A, from ⟨x, h4, h3⟩,
7777+ show y ∈ f '' A ∪ f '' B, from or.inl h5)
7878+ (assume h4 : x ∈ B,
7979+ have h5 : y ∈ f '' B, from ⟨x, h4, h3⟩,
8080+ show y ∈ f '' A ∪ f '' B, from or.inr h5))
8181+ (assume y,
8282+ assume h2 : y ∈ f '' A ∪ f '' B,
8383+ or.elim h2
8484+ (assume h3 : y ∈ f '' A,
8585+ exists.elim h3 $
8686+ assume x h,
8787+ have h4 : x ∈ A, from h.left,
8888+ have h5 : f x = y, from h.right,
8989+ have h6 : x ∈ A ∪ B, from or.inl h4,
9090+ show y ∈ f '' (A ∪ B), from ⟨x, h6, h5⟩)
9191+ (assume h3 : y ∈ f '' B,
9292+ exists.elim h3 $
9393+ assume x h,
9494+ have h4 : x ∈ B, from h.left,
9595+ have h5 : f x = y, from h.right,
9696+ have h6 : x ∈ A ∪ B, from or.inr h4,
9797+ show y ∈ f '' (A ∪ B), from ⟨x, h6, h5⟩))
9898+9999+-- remember, x ∈ A ∩ B is the same as x ∈ A ∧ x ∈ B
100100+example (x : X) (h1 : x ∈ A) (h2 : x ∈ B) : x ∈ A ∩ B :=
101101+and.intro h1 h2
102102+103103+example (x : X) (h1 : x ∈ A ∩ B) : x ∈ A :=
104104+and.left h1
105105+106106+-- Fill in the proof below.
107107+-- (It should take about 8 lines.)
108108+109109+example : f '' (A ∩ B) ⊆ f '' A ∩ f '' B :=
110110+assume y,
111111+assume h1 : y ∈ f '' (A ∩ B),
112112+show y ∈ f '' A ∩ f '' B, from
113113+ exists.elim h1 $
114114+ assume x h,
115115+ have y ∈ f '' A, from ⟨ x, h.left.left, h.right ⟩,
116116+ have y ∈ f '' B, from ⟨ x, h.left.right, h.right ⟩,
117117+ ⟨ ‹ y ∈ f '' A › , ‹ y ∈ f '' B › ⟩
+109
src/ch18.lean
···11+open nat
22+33+namespace hidden
44+55+theorem add_distrib (m n k: nat) : m * (n + k) = m * n + m * k :=
66+nat.rec_on k
77+ (show m * (n + 0) = m * n + m * 0, by rw [mul_zero , add_zero, add_zero])
88+ (assume k,
99+ assume ih : m * (n + k) = m * n + m * k,
1010+ show m * (n + succ k) = m * n + m * succ k, from calc
1111+ m * (n + succ k) = m * succ (n + k) : by rw add_succ
1212+ ... = m * (n + k) + m : by rw mul_succ
1313+ ... = m * n + m * k + m : by rw ih
1414+ ... = m * n + (m * k + m) : by rw add_assoc
1515+ ... = m * n + m * succ k : by rw mul_succ
1616+ )
1717+1818+theorem zero_mul (n : nat) : 0 * n = 0 :=
1919+nat.rec_on n
2020+ (show 0 * 0 = 0, from rfl)
2121+ (assume n,
2222+ assume ih : 0 * n = 0,
2323+ show 0 * succ n = 0, from calc
2424+ 0 * succ n = 0 * n + 0 : by rw mul_succ
2525+ ... = 0 + 0 : by rw ih
2626+ ... = 0 : by rw zero_add)
2727+2828+theorem one_mul (n : nat) : 1 * n = n :=
2929+nat.rec_on n
3030+ (show 1 * 0 = 0, by rw mul_zero)
3131+ (assume n,
3232+ assume ih: 1 * n = n,
3333+ show 1 * succ n = succ n, from calc
3434+ 1 * succ n = 1 * n + 1 : by rw mul_succ
3535+ ... = n + 1 : by rw ih
3636+ ... = succ n : rfl)
3737+3838+3939+theorem mul_assoc (m n k : nat) : m * (n * k) = (m * n) * k :=
4040+nat.rec_on k
4141+ (show m * (n * 0) = (m * n) * 0, by rw [mul_zero, mul_zero, mul_zero])
4242+ (assume k,
4343+ assume ih : m * (n * k) = (m * n) * k,
4444+ show m * (n * succ k) = (m * n) * succ k, from calc
4545+ m * (n * succ k) = m * (n * k + n) : by rw mul_succ
4646+ ... = m * (n * k) + m * n : by rw add_distrib
4747+ ... = (m * n) * k + m * n : by rw ih
4848+ ... = (m * n) * succ k : by rw mul_succ)
4949+5050+theorem mul_comm (m n : nat) : m * n = n * m :=
5151+nat.rec_on n
5252+ (show m * 0 = 0 * m, by rw [zero_mul,mul_zero])
5353+ (assume n,
5454+ assume ih: m * n = n * m,
5555+ show m * succ n = succ n * m, from calc
5656+ m * succ n = m * n + m : by rw mul_succ
5757+ ... = n * m + m : by rw ih
5858+ ... = succ n * m : by rw succ_mul)
5959+6060+-- END
6161+end hidden
6262+6363+6464+open nat
6565+6666+namespace hidden
6767+6868+6969+-- BEGIN
7070+theorem T1 : ∀ m n : nat, m > n → (m = n + 1) ∨ (m > n + 1) :=
7171+assume m n,
7272+assume h,
7373+have h1: succ n ≤ m, from succ_le_of_lt h,
7474+have h2 : n + 1 < m ∨ n + 1 = m, from iff.elim_left le_iff_lt_or_eq h1,
7575+or.elim h2
7676+ (assume : n + 1 < m,
7777+ show m = n + 1 ∨ m > n + 1, from or.inr this)
7878+ (assume : n + 1 = m,
7979+ have m = n + 1, from eq.symm this,
8080+ show m = n + 1 ∨ m > n + 1, from or.inl this)
8181+8282+8383+theorem T2: ∀ n : nat, n = 0 ∨ n > 0 :=
8484+assume n,
8585+have 0 = n ∨ 0 < n, from or.swap $ iff.elim_left le_iff_lt_or_eq $ zero_le n,
8686+or.elim this
8787+ (assume h1, or.inl (eq.symm h1))
8888+ (assume h1, or.inr h1)
8989+9090+9191+theorem T3 (m n : nat) : n + m = 0 → n = 0 ∧ m = 0 :=
9292+assume h,
9393+have h1: n ≥ 0, from zero_le n,
9494+have h2: m ≥ 0, from zero_le m,
9595+iff.elim_left (add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg h1 h2) h
9696+9797+theorem T4 (n m k : nat) : n * k < m * k → k > 0 ∧ n < m :=
9898+assume h,
9999+have h1 : k ≥ 0, from zero_le k,
100100+have h2 : n < m, from lt_of_mul_lt_mul_right h h1,
101101+have h3: k ≠ 0, from
102102+ assume : k = 0,
103103+ have n * 0 < m * 0, from (this ▸ h),
104104+ lt_le_antisymm this (zero_le 0),
105105+have h4: k > 0, from lt_of_le_of_ne h1 h3.symm,
106106+⟨ h4 , h2 ⟩
107107+108108+-- END
109109+end hidden
+22
src/ch19.lean
···11+import data.int.basic
22+33+open int
44+open nat
55+66+-- quotient / remainder theorem
77+theorem qt : ∀ n m : ℤ, m > 0 → ∃ q r : ℤ, n = m * q + r ∧ (0 ≤ r ∧ r < m) :=
88+assume n m h,
99+1010+exists.intro (n / m) $ exists.intro (n % m) $
1111+1212+ have HH: n = m * (n / m) + (n % m), from calc
1313+ n = n % m + m * (n / m) : by rw [int.mod_add_div]
1414+ ... = m * (n / m) + (n % m) : by rw add_comm,
1515+1616+ have HH1: 0 ≤ (n % m), from int.mod_nonneg n (ne_of_gt h),
1717+1818+ have HH2: (n % m) < m, from calc
1919+ (n % m) < abs m : int.mod_lt n (ne_of_gt h)
2020+ ... = m : abs_of_pos h,
2121+2222+ ⟨ HH , ⟨ HH1 , HH2 ⟩ ⟩
+32
src/ch4.lean
···11+variables A B C D : Prop
22+33+example : A ∧ (A → B) → B :=
44+assume h,
55+show B, from h.right h.left
66+77+88+example : A → ¬ (¬ A ∧ B) :=
99+assume h1 : A,
1010+assume h2: ¬ A ∧ B,
1111+show false, from h2.left h1
1212+1313+example : ¬ (A ∧ B) → (A → ¬ B) :=
1414+λ h1 h2 h3, h1 (⟨ h2 , h3 ⟩)
1515+1616+example (h₁ : A ∨ B) (h₂ : A → C) (h₃ : B → D) : C ∨ D :=
1717+or.elim h₁
1818+ (assume h₄ : A, show C ∨ D, from or.inl (h₂ h₄))
1919+ (assume h₄ : B, show C ∨ D, from or.inr (h₃ h₄))
2020+2121+example (h : ¬ A ∧ ¬ B) : ¬ (A ∨ B) :=
2222+assume h1 : A ∨ B,
2323+or.elim h1
2424+ (assume h2 : A, show false, from h.left h2)
2525+ (assume h3 : B, show false, from h.right h3)
2626+2727+example : ¬ (A ↔ ¬ A) :=
2828+assume h,
2929+have h1 : ¬ A, from
3030+ assume a : A,
3131+ show false, from (h.mp a) a,
3232+show false, from h1 (h.mpr h1)
+49
src/ch5.lean
···11+variables A B : Prop
22+open classical
33+44+example : ¬ A → false → A :=
55+sorry
66+77+example : ¬ A ∨ ¬ B → ¬ (A ∧ B) :=
88+assume h,
99+show ¬ (A ∧ B), from
1010+ assume h1 : A ∧ B,
1111+ show false, from
1212+ or.elim h
1313+ (assume na : ¬ A,
1414+ show false, from na h1.left)
1515+ (assume nb : ¬ B,
1616+ show false, from nb h1.right)
1717+1818+1919+-- Prove ¬ (A ∧ B) → ¬ A ∨ ¬ B by replacing the sorry's below
2020+-- by proofs.
2121+2222+lemma step1 (h₁ : ¬ (A ∧ B)) (h₂ : A) : ¬ A ∨ ¬ B :=
2323+have ¬ B, from
2424+ assume b : B,
2525+ show false, from h₁ (and.intro h₂ b),
2626+show ¬ A ∨ ¬ B, from or.inr this
2727+2828+lemma step2 (h₁ : ¬ (A ∧ B)) (h₂ : ¬ (¬ A ∨ ¬ B)) : false :=
2929+have ¬ A, from
3030+ assume : A,
3131+ have ¬ A ∨ ¬ B, from step1 h₁ ‹A›,
3232+ show false, from h₂ this,
3333+show false, from h₂ (or.inl this)
3434+3535+theorem step3 (h : ¬ (A ∧ B)) : ¬ A ∨ ¬ B :=
3636+by_contradiction
3737+ (assume h' : ¬ (¬ A ∨ ¬ B),
3838+ show false, from step2 h h')
3939+4040+example (h : ¬ B → ¬ A) : A → B :=
4141+assume a,
4242+by_contradiction (assume h1 : ¬ B, show false, from h h1 a)
4343+4444+example (h : A → B) : ¬ A ∨ B :=
4545+by_contradiction
4646+ (assume h1 : ¬ (¬ A ∨ B),
4747+ show false, from
4848+ have a : ¬ A, from assume aa : A, show false, from h1 (or.inr (h aa)),
4949+ h1 (or.inl a))
+232
src/ch9.lean
···11+section
22+ variable A : Type
33+ variable f : A → A
44+ variable P : A → Prop
55+ variable h : ∀ x, P x → P (f x)
66+77+ -- Show the following:
88+ example : ∀ y, P y → P (f (f y)) :=
99+ assume x,
1010+ assume h1: P x,
1111+ have h2 : P x → P (f x), from h x,
1212+ have h3: P (f x), from h2 h1,
1313+ have h4 : P (f x) → P (f (f x)), from h (f x),
1414+ show P (f (f x)), from h4 h3
1515+end
1616+1717+section
1818+ variable U : Type
1919+ variables A B : U → Prop
2020+2121+ example : (∀ x, A x ∧ B x) → ∀ x, A x :=
2222+ assume h : ∀ x, A x ∧ B x,
2323+ assume y,
2424+ have h1 : A y ∧ B y, from h y,
2525+ show A y, from and.left h1
2626+end
2727+2828+---
2929+3030+section
3131+ variable U : Type
3232+ variables A B C : U → Prop
3333+3434+ variable h1 : ∀ x, A x ∨ B x
3535+ variable h2 : ∀ x, A x → C x
3636+ variable h3 : ∀ x, B x → C x
3737+3838+ example : ∀ x, C x :=
3939+ assume y,
4040+ or.elim (h1 y)
4141+ (assume ha1, show C y, from (h2 y) ha1)
4242+ (assume ha2, show C y, from (h3 y) ha2)
4343+end
4444+4545+---
4646+4747+open classical -- not needed, but you can use it
4848+4949+-- This is an exercise from Chapter 4. Use it as an axiom here.
5050+axiom not_iff_not_self (P : Prop) : ¬ (P ↔ ¬ P)
5151+5252+example (Q : Prop) : ¬ (Q ↔ ¬ Q) :=
5353+not_iff_not_self Q
5454+5555+section
5656+ variable Person : Type
5757+ variable shaves : Person → Person → Prop
5858+ variable barber : Person
5959+ variable h : ∀ x, shaves barber x ↔ ¬ shaves x x
6060+6161+ -- Show the following:
6262+ example : false :=
6363+ show false, from
6464+ (not_iff_not_self (shaves barber barber)) (h barber)
6565+end
6666+6767+---
6868+6969+section
7070+ variable U : Type
7171+ variables A B : U → Prop
7272+7373+ example : (∃ x, A x) → ∃ x, A x ∨ B x :=
7474+ assume h,
7575+ exists.elim h
7676+ (assume y (h1 : A y),
7777+ exists.intro y (or.inl h1))
7878+end
7979+8080+---
8181+8282+section
8383+ variable U : Type
8484+ variables A B : U → Prop
8585+8686+ variable h1 : ∀ x, A x → B x
8787+ variable h2 : ∃ x, A x
8888+8989+ example : ∃ x, B x :=
9090+ exists.elim h2
9191+ (assume y h3,
9292+ exists.intro y (h1 y h3))
9393+end
9494+9595+---
9696+9797+variable U : Type
9898+variables A B C : U → Prop
9999+100100+example (h1 : ∃ x, A x ∧ B x) (h2 : ∀ x, B x → C x) :
101101+ ∃ x, A x ∧ C x :=
102102+exists.elim h1
103103+(assume y h3,
104104+ exists.intro y ⟨ and.left h3, h2 y (and.right h3) ⟩ )
105105+106106+---
107107+108108+variable U : Type
109109+variables A B C : U → Prop
110110+111111+example : (¬ ∃ x, A x) → ∀ x, ¬ A x :=
112112+λ h1 y h3, h1 (exists.intro y h3)
113113+114114+example : (∀ x, ¬ A x) → ¬ ∃ x, A x :=
115115+λ h1 h2, exists.elim h2 (λ y h3, h1 y h3)
116116+117117+---
118118+119119+variable U : Type
120120+variables R : U → U → Prop
121121+122122+example : (∃ x, ∀ y, R x y) → ∀ y, ∃ x, R x y :=
123123+assume h1 y,
124124+exists.elim h1
125125+(assume x (h2 : ∀ x1, R x x1),
126126+ exists.intro x (h2 y))
127127+128128+---
129129+130130+theorem foo {A : Type} {a b c : A} : a = b → c = b → a = c :=
131131+assume h1 : a = b,
132132+assume h2 : c = b,
133133+show a = c, by rw [h2,h1]
134134+-- notice that you can now use foo as a rule. The curly braces mean that
135135+-- you do not have to give A, a, b, or c
136136+137137+section
138138+ variable A : Type
139139+ variables a b c : A
140140+141141+ example (h1 : a = b) (h2 : c = b) : a = c :=
142142+ foo h1 h2
143143+end
144144+145145+section
146146+ variable {A : Type}
147147+ variables {a b c : A}
148148+149149+ -- replace the sorry with a proof, using foo and rfl, without using eq.symm.
150150+ theorem my_symm (h : b = a) : a = b :=
151151+ have h1 : a = a, from eq.refl a,
152152+ foo h1 h
153153+154154+ -- now use foo, rfl, and my_symm to prove transitivity
155155+ theorem my_trans (h1 : a = b) (h2 : b = c) : a = c :=
156156+ foo h1 (my_symm h2)
157157+end
158158+159159+---
160160+161161+-- these are the axioms for a commutative ring
162162+163163+#check @add_assoc
164164+#check @add_comm
165165+#check @add_zero
166166+#check @zero_add
167167+#check @mul_assoc
168168+#check @mul_comm
169169+#check @mul_one
170170+#check @one_mul
171171+#check @left_distrib
172172+#check @right_distrib
173173+#check @add_left_neg
174174+#check @add_right_neg
175175+#check @sub_eq_add_neg
176176+177177+variables x y z : int
178178+179179+theorem t1 : x - x = 0 :=
180180+calc
181181+x - x = x + -x : by rw sub_eq_add_neg
182182+ ... = 0 : by rw add_right_neg
183183+184184+theorem t2 (h : x + y = x + z) : y = z :=
185185+calc
186186+y = 0 + y : by rw zero_add
187187+ ... = (-x + x) + y : by rw add_left_neg
188188+ ... = -x + (x + y) : by rw add_assoc
189189+ ... = -x + (x + z) : by rw h
190190+ ... = (-x + x) + z : by rw add_assoc
191191+ ... = 0 + z : by rw add_left_neg
192192+ ... = z : by rw zero_add
193193+194194+theorem t3 (h : x + y = z + y) : x = z :=
195195+calc
196196+x = x + 0 : by rw add_zero
197197+ ... = x + (y + -y) : by rw add_right_neg
198198+ ... = (x + y) + -y : by rw add_assoc
199199+ ... = (z + y) + -y : by rw h
200200+ ... = z + (y + -y) : by rw add_assoc
201201+ ... = z + 0 : by rw add_right_neg
202202+ ... = z : by rw add_zero
203203+204204+theorem t4 (h : x + y = 0) : x = -y :=
205205+calc
206206+x = x + 0 : by rw add_zero
207207+ ... = x + (y + -y) : by rw add_right_neg
208208+ ... = (x + y) + -y : by rw add_assoc
209209+ ... = 0 + -y : by rw h
210210+ ... = -y : by rw zero_add
211211+212212+theorem t5 : x * 0 = 0 :=
213213+have h1 : x * 0 + x * 0 = x * 0 + 0, from
214214+calc
215215+ x * 0 + x * 0 = x * (0 + 0) : by rw left_distrib
216216+ ... = x * 0 : by rw add_zero
217217+ ... = x * 0 + 0 : by rw add_zero,
218218+show x * 0 = 0, from t2 _ _ _ h1
219219+220220+theorem t6 : x * (-y) = -(x * y) :=
221221+have h1 : x * (-y) + x * y = 0, from
222222+calc
223223+ x * (-y) + x * y = x * (-y + y) : by rw left_distrib
224224+ ... = x * 0 : by rw add_left_neg
225225+ ... = 0 : by rw t5 x,
226226+show x * (-y) = -(x * y), from t4 _ _ h1
227227+228228+theorem t7 : x + x = 2 * x :=
229229+calc
230230+x + x = 1 * x + 1 * x : by rw one_mul
231231+ ... = (1 + 1) * x : by rw right_distrib
232232+ ... = 2 * x : rfl