Аналіз I, Додаток A.1: Математичні твердження

Вступ до математичних тверджень. Демонструє деякі базові тактики та синтаксис Lean.

2 + 2 = 4 : Prop
2 + 2 = 5 : Prop

Кожне добре сформульоване твердження або істинне, або хибне...

example (P:Prop) : (P=true) ∨ (P=false) := P:Prop⊢ P = (true = true) ∨ P = (false = true) P:Prop⊢ P ∨ ¬P; All goals completed! 🐙

.. але не одночасно.

example (P:Prop) : ¬ ((P=true) ∧ (P=false)) := P:Prop⊢ ¬(P = (true = true) ∧ P = (false = true)) All goals completed! 🐙
-- Примітка: `P=true` та `P=false` спрощуються до `P` та `¬P` відповідно.

Щоб довести істинність твердження, достатньо показати, що воно не є хибним,

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! 🐙

тоді як для того, щоб довести, що твердження хибне, достатньо довести, що воно не є істинним.

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! 🐙

Це твердження істінне, але навряд чи буде дуже корисним.

example : 2 = 2 := rfl

Це твердження також істінне, але не дуже ефективне.

example : 4 ≤ 4 := ⊢ 4 ≤ 4 All goals completed! 🐙
2 + 3 * 5 : ℕ
2 + 3 * 5 = 17 : Prop
Prime (30 + 5) : Prop
30 + 5 ≤ 42 - 7 : Prop

Кон'юнкція

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! 🐙

Диз'юнкція

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! 🐙
Xor' (a b : Prop) : Prop

Заперечення

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 _fvar.17324 ↔ Even _fvar.17324 := Int.not_odd_iff_even⊢ ¬(Even x ∧ x ≥ 0) ↔ Odd x ∨ x < 0 x:ℤthis✝:¬Odd _fvar.17324 ↔ Even _fvar.17324 := Int.not_odd_iff_eventhis:¬_fvar.17324 ≥ 0 ↔ _fvar.17324 < 0 := Int.not_le⊢ ¬(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:¬_fvar.29943 ≥ 2 ↔ _fvar.29943 < 2 := Int.not_le⊢ ¬(x ≥ 2 ∧ x ≤ 6) ↔ x < 2 ∨ x > 6 x:ℤthis✝:¬_fvar.29943 ≥ 2 ↔ _fvar.29943 < 2 := Int.not_lethis:¬_fvar.29943 ≤ 6 ↔ _fvar.29943 > 6 := Int.not_le⊢ ¬(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:¬_fvar.46563 ≥ 1 ↔ _fvar.46563 < 1 := not_le⊢ ¬(x ≥ 1 ∧ x ≤ -1) ↔ x < 1 ∨ x > -1 x:ℝthis✝:¬_fvar.46563 ≥ 1 ↔ _fvar.46563 < 1 := not_lethis:¬_fvar.46563 ≤ -1 ↔ _fvar.46563 > -1 := not_le⊢ ¬(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! 🐙

Тоді і тільки тоді (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! 🐙 -- Цей рядок необов'язковий tfae_have 1 ↔ 3 := X:PropY:PropZ:ProphXY:X ↔ YhXZ:X ↔ Z⊢ [X, Y, Z].TFAE All goals completed! 🐙 -- Цей рядок необов'язковий All goals completed! 🐙

Зверніть увагу, що для методу Invalid dotted identifier notation: The expected type of `.out` could not be determined.out індексація починається з 0, на відміну від тактики Unknown identifier `tfae_have`tfae_have.

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! 🐙

Вправа A.1.1. Заповніть перше sorry : ?m.1sorry чимось прийнятним

declaration uses 'sorry'example {X Y:Prop} : ¬ ((X ∨ Y) ∧ ¬ (X ∧ Y)) ↔ sorry := X:PropY:Prop⊢ ¬((X ∨ Y) ∧ ¬(X ∧ Y)) ↔ sorry All goals completed! 🐙

Вправа A.1.2. Заповніть перше sorry : ?m.1sorry чимось прийнятним

declaration uses 'sorry'example {X Y:Prop} : ¬ (X ↔ Y) ↔ sorry := X:PropY:Prop⊢ ¬(X ↔ Y) ↔ sorry All goals completed! 🐙

Вправа A.1.3.

def declaration uses 'sorry'Exercise_A_1_3 : Decidable (∀ (X Y: Prop), (X → Y) → (¬X → ¬ Y) → (X ↔ Y)) := ⊢ Decidable (∀ (X Y : Prop), (X → Y) → (¬X → ¬Y) → (X ↔ Y)) -- перший рядок цієї конструкції має бути або `apply isTrue`, або `apply isFalse`, залежно від того, чи вважаєте ви дане твердження істинним чи хибним. All goals completed! 🐙

Вправа A.1.4.

def declaration uses 'sorry'Exercise_A_1_4 : Decidable (∀ (X Y: Prop), (X → Y) → (¬Y → ¬ X) → (X ↔ Y)) := ⊢ Decidable (∀ (X Y : Prop), (X → Y) → (¬Y → ¬X) → (X ↔ Y)) -- перший рядок цієї конструкції має бути або `apply isTrue`, або `apply isFalse`. All goals completed! 🐙

Вправа A.1.5.

def declaration uses 'sorry'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) -- перший рядок цієї конструкції має бути або `apply isTrue`, або `apply isFalse`. All goals completed! 🐙

Вправа A.1.6.

def declaration uses 'sorry'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) -- перший рядок цієї конструкції має бути або `apply isTrue`, або `apply isFalse`. All goals completed! 🐙