Imports
import Mathlib.TacticAnalysis I, Appendix A.1: Mathematical Statements
An introduction to mathematical statements. Showcases some basic tactics and Lean syntax.
-- Example A.1.1. What the textbook calls "statements" are objects of type `Prop` in Lean. Also, in Lean we tend to assign "junk" values to expressions that might normally be considered undefined, so discussions regarding undefined terms in the textbook should be adjusted accordingly.
#check 2+2=4#check 2+2=5/-- Every well-formed statement is either true or false... -/
example (P:Prop) : (P=true) ∨ (P=false) := P:Prop⊢ P = (true = true) ∨ P = (false = true) P:Prop⊢ P ∨ ¬P; All goals completed! 🐙/-- .. but not both. -/
example (P:Prop) : ¬ ((P=true) ∧ (P=false)) := P:Prop⊢ ¬(P = (true = true) ∧ P = (false = true)) All goals completed! 🐙-- Note: `P=true` and `P=false` simplify to `P` and `¬P` respectively.
/-- To prove that a statement is true, it suffices to show that it is not false, -/
example {P:Prop} (h: P ≠ false) : P = true := P:Proph:P ≠ (false = true)⊢ P = (true = true) P:Proph:P ≠ (false = true)⊢ P; All goals completed! 🐙/-- while to show that a statement is false, it suffices to show that it is not true. -/
example {P:Prop} (h: P ≠ true) : P = false := P:Proph:P ≠ (true = true)⊢ P = (false = true) P:Proph:P ≠ (true = true)⊢ ¬P; All goals completed! 🐙/-- This statement is true, but unlikely to be very useful. -/
example : 2 = 2 := rfl/-- This statement is also true, but not very efficient. -/
example : 4 ≤ 4 := ⊢ 4 ≤ 4 All goals completed! 🐙/- This is an expression, not a statement. -/
#check 2 + 3*5/- This is a statement, not an expression. -/
#check 2 + 3*5 = 17#check Prime (30+5)#check 30+5 ≤ 42-7/-- Conjunction -/
example {X Y: Prop} (hX: X) (hY: Y) : X ∧ Y := X:PropY:ProphX:XhY:Y⊢ X ∧ Y
X:PropY:ProphX:XhY:Y⊢ XX:PropY:ProphX:XhY:Y⊢ Y
X:PropY:ProphX:XhY:Y⊢ X All goals completed! 🐙
All goals completed! 🐙example {X Y: Prop} (hXY: X ∧ Y) : X := X:PropY:ProphXY:X ∧ Y⊢ X
All goals completed! 🐙example {X Y: Prop} (hXY: X ∧ Y) : Y := X:PropY:ProphXY:X ∧ Y⊢ Y
All goals completed! 🐙example {X Y: Prop} (hX: ¬ X) : ¬ (X ∧ Y) := X:PropY:ProphX:¬X⊢ ¬(X ∧ Y)
X:PropY:ProphX:X ∧ Y⊢ X
All goals completed! 🐙example {X Y: Prop} (hY: ¬ Y) : ¬ (X ∧ Y) := X:PropY:ProphY:¬Y⊢ ¬(X ∧ Y)
X:PropY:ProphY:X ∧ Y⊢ Y
All goals completed! 🐙example : (2+2=4) ∧ (3+3=6) := ⊢ 2 + 2 = 4 ∧ 3 + 3 = 6
⊢ 2 + 2 = 4⊢ 3 + 3 = 6
⊢ 2 + 2 = 4 All goals completed! 🐙
All goals completed! 🐙/-- Disjunction -/
example {X Y: Prop} (hX: X) : X ∨ Y := X:PropY:ProphX:X⊢ X ∨ Y
X:PropY:ProphX:X⊢ X
All goals completed! 🐙example {X Y: Prop} (hY: Y) : X ∨ Y := X:PropY:ProphY:Y⊢ X ∨ Y
X:PropY:ProphY:Y⊢ Y
All goals completed! 🐙example {X Y: Prop} (hX: ¬ X) (hY: ¬ Y) : ¬ (X ∨ Y) := X:PropY:ProphX:¬XhY:¬Y⊢ ¬(X ∨ Y)
X:PropY:ProphX:¬XhY:¬Y⊢ ¬X ∧ ¬Y
X:PropY:ProphX:¬XhY:¬Y⊢ ¬XX:PropY:ProphX:¬XhY:¬Y⊢ ¬Y
X:PropY:ProphX:¬XhY:¬Y⊢ ¬X All goals completed! 🐙
All goals completed! 🐙example : (2+2=4) ∨ (3+3=5) := ⊢ 2 + 2 = 4 ∨ 3 + 3 = 5
⊢ 2 + 2 = 4
All goals completed! 🐙example : ¬ ((2+2=5) ∨ (3+3=5)) := ⊢ ¬(2 + 2 = 5 ∨ 3 + 3 = 5)
All goals completed! 🐙example : (2+2=4) ∨ (3+3=6) := ⊢ 2 + 2 = 4 ∨ 3 + 3 = 6
⊢ 2 + 2 = 4
All goals completed! 🐙example : (2+2=4) ∧ (3+3=6) := ⊢ 2 + 2 = 4 ∧ 3 + 3 = 6
⊢ 2 + 2 = 4⊢ 3 + 3 = 6
⊢ 2 + 2 = 4 All goals completed! 🐙
All goals completed! 🐙example : (2+2=4) ∨ (2353 + 5931 = 7284) := ⊢ 2 + 2 = 4 ∨ 2353 + 5931 = 7284
⊢ 2 + 2 = 4
All goals completed! 🐙#check Xor'/-- Negation -/
example {X:Prop} : (¬ X = true) ↔ (X = false) := X:Prop⊢ ¬X = (true = true) ↔ X = (false = true) All goals completed! 🐙example {X:Prop} : (¬ X = false) ↔ (X = true) := X:Prop⊢ ¬X = (false = true) ↔ X = (true = true) All goals completed! 🐙example : ¬ (2+2=5) := ⊢ ¬2 + 2 = 5 All goals completed! 🐙example : 2+2 ≠ 5 := ⊢ 2 + 2 ≠ 5 All goals completed! 🐙example (Jane_black_hair Jane_blue_eyes:Prop) :
(¬ (Jane_black_hair ∧ Jane_blue_eyes)) ↔ (¬ Jane_black_hair ∨ ¬ Jane_blue_eyes) := Jane_black_hair:PropJane_blue_eyes:Prop⊢ ¬(Jane_black_hair ∧ Jane_blue_eyes) ↔ ¬Jane_black_hair ∨ ¬Jane_blue_eyes
Jane_black_hair:PropJane_blue_eyes:Prop⊢ Jane_black_hair → ¬Jane_blue_eyes ↔ ¬Jane_black_hair ∨ ¬Jane_blue_eyes; All goals completed! 🐙example (x:ℤ) : ¬ (Even x ∧ x ≥ 0) ↔ (Odd x ∨ x < 0) := x:ℤ⊢ ¬(Even x ∧ x ≥ 0) ↔ Odd x ∨ x < 0
x:ℤthis:¬Odd x ↔ Even x⊢ ¬(Even x ∧ x ≥ 0) ↔ Odd x ∨ x < 0
x:ℤthis✝:¬Odd x ↔ Even xthis:¬x ≥ 0 ↔ x < 0⊢ ¬(Even x ∧ x ≥ 0) ↔ Odd x ∨ x < 0
All goals completed! 🐙example (x:ℤ) : ¬ (x ≥ 2 ∧ x ≤ 6) ↔ (x < 2 ∨ x > 6) := x:ℤ⊢ ¬(x ≥ 2 ∧ x ≤ 6) ↔ x < 2 ∨ x > 6
x:ℤthis:¬x ≥ 2 ↔ x < 2⊢ ¬(x ≥ 2 ∧ x ≤ 6) ↔ x < 2 ∨ x > 6
x:ℤthis✝:¬x ≥ 2 ↔ x < 2this:¬x ≤ 6 ↔ x > 6⊢ ¬(x ≥ 2 ∧ x ≤ 6) ↔ x < 2 ∨ x > 6
All goals completed! 🐙example (John_brown_hair John_black_hair:Prop) :
(¬ (John_brown_hair ∨ John_black_hair)) ↔ (¬ John_brown_hair ∧ ¬ John_black_hair) := John_brown_hair:PropJohn_black_hair:Prop⊢ ¬(John_brown_hair ∨ John_black_hair) ↔ ¬John_brown_hair ∧ ¬John_black_hair
All goals completed! 🐙example (x:ℝ) : ¬ (x ≥ 1 ∧ x ≤ -1) ↔ (x < 1 ∨ x > -1) := x:ℝ⊢ ¬(x ≥ 1 ∧ x ≤ -1) ↔ x < 1 ∨ x > -1
x:ℝthis:¬x ≥ 1 ↔ x < 1⊢ ¬(x ≥ 1 ∧ x ≤ -1) ↔ x < 1 ∨ x > -1
x:ℝthis✝:¬x ≥ 1 ↔ x < 1this:¬x ≤ -1 ↔ x > -1⊢ ¬(x ≥ 1 ∧ x ≤ -1) ↔ x < 1 ∨ x > -1
All goals completed! 🐙example (x:ℤ) : ¬ (Even x ∨ Odd x) ↔ (¬ Even x ∧ ¬ Odd x) := x:ℤ⊢ ¬(Even x ∨ Odd x) ↔ ¬Even x ∧ ¬Odd x
All goals completed! 🐙example (X:Prop) : ¬ (¬ X) ↔ X := X:Prop⊢ ¬¬X ↔ X
All goals completed! 🐙/-- If and only if (iff) -/
example {X Y: Prop} (hXY: X ↔ Y) (hX: X) : Y := X:PropY:ProphXY:X ↔ YhX:X⊢ Y
X:PropY:ProphXY:X ↔ YhX:Y⊢ Y
All goals completed! 🐙example {X Y: Prop} (hXY: X ↔ Y) (hY: Y) : X := X:PropY:ProphXY:X ↔ YhY:Y⊢ X
X:PropY:ProphXY:X ↔ YhY:X⊢ X
All goals completed! 🐙example {X Y: Prop} (hXY: X ↔ Y) (hX: X) : Y := X:PropY:ProphXY:X ↔ YhX:X⊢ Y
All goals completed! 🐙example {X Y: Prop} (hXY: X ↔ Y) (hY: Y) : X := X:PropY:ProphXY:X ↔ YhY:Y⊢ X
All goals completed! 🐙example {X Y: Prop} (hXY: X ↔ Y) : X=Y := X:PropY:ProphXY:X ↔ Y⊢ X = Y
All goals completed! 🐙example (x:ℝ) : x = 3 ↔ 2 * x = 6 := x:ℝ⊢ x = 3 ↔ 2 * x = 6
x:ℝ⊢ x = 3 → 2 * x = 6x:ℝ⊢ 2 * x = 6 → x = 3
x:ℝ⊢ x = 3 → 2 * x = 6 x:ℝh:x = 3⊢ 2 * x = 6
All goals completed! 🐙
x:ℝh:2 * x = 6⊢ x = 3
All goals completed! 🐙example : ¬ (∀ x:ℝ, x = 3 ↔ x^2 = 9) := ⊢ ¬∀ (x : ℝ), x = 3 ↔ x ^ 2 = 9
⊢ ∃ x, ¬(x = 3 ↔ x ^ 2 = 9)
⊢ ¬(-3 = 3 ↔ (-3) ^ 2 = 9)
All goals completed! 🐙example {X Y: Prop} (hXY: X ↔ Y) (hX: ¬ X) : ¬ Y := X:PropY:ProphXY:X ↔ YhX:¬X⊢ ¬Y
X:PropY:ProphXY:X ↔ YhX:¬Xthis:Y⊢ False
X:PropY:ProphXY:X ↔ YhX:¬Xthis:X⊢ False
All goals completed! 🐙example : (2+2=5) ↔ (4+4=10) := ⊢ 2 + 2 = 5 ↔ 4 + 4 = 10
All goals completed! 🐙example {X Y Z:Prop} (hXY: X ↔ Y) (hXZ: X ↔ Z) : [X,Y,Z].TFAE := X:PropY:PropZ:ProphXY:X ↔ YhXZ:X ↔ Z⊢ [X, Y, Z].TFAE
tfae_have 1 ↔ 2 := X:PropY:PropZ:ProphXY:X ↔ YhXZ:X ↔ Z⊢ [X, Y, Z].TFAE All goals completed! 🐙 -- This line is optional
tfae_have 1 ↔ 3 := X:PropY:PropZ:ProphXY:X ↔ YhXZ:X ↔ Z⊢ [X, Y, Z].TFAE All goals completed! 🐙 -- This line is optional
All goals completed! 🐙/-- Note for the {name (full := List.TFAE.out)}`out` method that one indexes starting from 0, in contrast to the {tactic}`tfae_have` tactic. -/
example {X Y Z:Prop} (h: [X,Y,Z].TFAE) : X ↔ Y := X:PropY:PropZ:Proph:[X, Y, Z].TFAE⊢ X ↔ Y
All goals completed! 🐙/-- Exercise A.1.1. Fill in the first {syntax term}`sorry` with something reasonable. -/
example {X Y:Prop} : ¬ ((X ∨ Y) ∧ ¬ (X ∧ Y)) ↔ sorry := X:PropY:Prop⊢ ¬((X ∨ Y) ∧ ¬(X ∧ Y)) ↔ sorry All goals completed! 🐙/-- Exercise A.1.2. Fill in the first {syntax term}`sorry` with something reasonable. -/
example {X Y:Prop} : ¬ (X ↔ Y) ↔ sorry := X:PropY:Prop⊢ ¬(X ↔ Y) ↔ sorry All goals completed! 🐙Exercise A.1.3.
def Exercise_A_1_3 : Decidable (∀ (X Y: Prop), (X → Y) → (¬X → ¬ Y) → (X ↔ Y)) := ⊢ Decidable (∀ (X Y : Prop), (X → Y) → (¬X → ¬Y) → (X ↔ Y))
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`, depending on whether you believe the given statement to be true or false.
All goals completed! 🐙Exercise A.1.4.
def Exercise_A_1_4 : Decidable (∀ (X Y: Prop), (X → Y) → (¬Y → ¬ X) → (X ↔ Y)) := ⊢ Decidable (∀ (X Y : Prop), (X → Y) → (¬Y → ¬X) → (X ↔ Y))
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙Exercise A.1.5.
def Exercise_A_1_5 : Decidable (∀ (X Y Z: Prop), (X ↔ Y) → (Y ↔ Z) → [X,Y,Z].TFAE) := ⊢ Decidable (∀ (X Y Z : Prop), (X ↔ Y) → (Y ↔ Z) → [X, Y, Z].TFAE)
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙Exercise A.1.6.
def Exercise_A_1_6 : Decidable (∀ (X Y Z: Prop), (X → Y) → (Y → Z) → (Z → X) → [X,Y,Z].TFAE) := ⊢ Decidable (∀ (X Y Z : Prop), (X → Y) → (Y → Z) → (Z → X) → [X, Y, Z].TFAE)
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙