Analysis I, Appendix A.5: Nested quantifiers
Some examples of nested quantifiers in Lean
example : ∀ x > (0:ℝ), ∃ y > 0, y^2 = x := ⊢ ∀ x > 0, ∃ y > 0, y ^ 2 = x
x:ℝhx:x > 0⊢ ∃ y > 0, y ^ 2 = x
x:ℝhx:x > 0⊢ √x > 0 ∧ √x ^ 2 = x
x:ℝhx:x > 0⊢ √x > 0x:ℝhx:x > 0⊢ √x ^ 2 = x
x:ℝhx:x > 0⊢ √x > 0 All goals completed! 🐙
x:ℝhx:x > 0⊢ 0 ≤ x
All goals completed! 🐙namespace SwanExamplevariable (Swans:Type)variable (isBlack : Swans → Prop)example : (¬ ∀ s:Swans, isBlack s) = (∃ s:Swans, ¬ isBlack s) := Swans:TypeisBlack:Swans → Prop⊢ (¬∀ (s : Swans), isBlack s) = ∃ s, ¬isBlack s
All goals completed! 🐙example : (¬ ∃ s:Swans, isBlack s) = (∀ s:Swans, ¬ isBlack s) := Swans:TypeisBlack:Swans → Prop⊢ (¬∃ s, isBlack s) = ∀ (s : Swans), ¬isBlack s
All goals completed! 🐙end SwanExampleexample : (¬ ∀ x, (0 < x ∧ x < Real.pi/2) → Real.cos x ≥ 0) = (∃ x, (0 < x ∧ x < Real.pi/2) ∧ Real.cos x < 0) := ⊢ (¬∀ (x : ℝ), 0 < x ∧ x < Real.pi / 2 → Real.cos x ≥ 0) = ∃ x, (0 < x ∧ x < Real.pi / 2) ∧ Real.cos x < 0
⊢ (∃ x, 0 < x ∧ x < Real.pi / 2 ∧ Real.cos x < 0) ↔ ∃ x, (0 < x ∧ x < Real.pi / 2) ∧ Real.cos x < 0
All goals completed! 🐙example : (¬ ∃ x:ℝ, x^2 + x + 1 = 0) = (∀ x:ℝ, x^2 + x + 1 ≠ 0) := ⊢ (¬∃ x, x ^ 2 + x + 1 = 0) = ∀ (x : ℝ), x ^ 2 + x + 1 ≠ 0
All goals completed! 🐙theorem square_expand : ∀ (x:ℝ), (x + 1)^2 = x^2 + 2 * x + 1 := ⊢ ∀ (x : ℝ), (x + 1) ^ 2 = x ^ 2 + 2 * x + 1
x:ℝ⊢ (x + 1) ^ 2 = x ^ 2 + 2 * x + 1
All goals completed! 🐙example : (Real.pi+1)^2 = Real.pi^2 + 2 * Real.pi + 1 := ⊢ (Real.pi + 1) ^ 2 = Real.pi ^ 2 + 2 * Real.pi + 1
All goals completed! 🐙 -- one can also use `exact square_expand _`example : ∀ (y:ℝ), (Real.cos y + 1)^2 = Real.cos y^2 + 2 * Real.cos y + 1 := ⊢ ∀ (y : ℝ), (Real.cos y + 1) ^ 2 = Real.cos y ^ 2 + 2 * Real.cos y + 1
y:ℝ⊢ (Real.cos y + 1) ^ 2 = Real.cos y ^ 2 + 2 * Real.cos y + 1
All goals completed! 🐙theorem solve_quadratic : ∃ (x:ℝ), x^2 + 2 * x - 8 = 0 := ⊢ ∃ x, x ^ 2 + 2 * x - 8 = 0
⊢ 2 ^ 2 + 2 * 2 - 8 = 0
All goals completed! 🐙/- The following proof will not typecheck.
example : Real.pi^2 + 2 * Real.pi - 8 = 0 := by
apply solve_quadratic
-/
namespace Remark_A_5_1variable (Man : Type)variable (Mortal : Man → Prop)example
(premise : ∀ m : Man, Mortal m)
(Socrates : Man) :
Mortal Socrates := Man:TypeMortal:Man → Proppremise:∀ (m : Man), Mortal mSocrates:Man⊢ Mortal Socrates
All goals completed! 🐙 -- `exact premise Socrates` would also workend Remark_A_5_1example :
(∀ a:ℝ, ∀ b:ℝ, (a+b)^2 = a^2 + 2*a*b + b^2)
= (∀ b:ℝ, ∀ a:ℝ, (a+b)^2 = a^2 + 2*a*b + b^2)
:= ⊢ (∀ (a b : ℝ), (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2) = ∀ (b a : ℝ), (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2
All goals completed! 🐙example :
(∃ a:ℝ, ∃ b:ℝ, a^2 + b^2 = 0)
= (∃ b:ℝ, ∃ a:ℝ, a^2 + b^2 = 0)
:= ⊢ (∃ a b, a ^ 2 + b ^ 2 = 0) = ∃ b a, a ^ 2 + b ^ 2 = 0
All goals completed! 🐙example : ∀ n:ℤ, ∃ m:ℤ, m > n := ⊢ ∀ (n : ℤ), ∃ m, m > n
n:ℤ⊢ ∃ m, m > n
n:ℤ⊢ n + 1 > n
All goals completed! 🐙example : ¬ ∃ m:ℤ, ∀ n:ℤ, m > n := ⊢ ¬∃ m, ∀ (n : ℤ), m > n
h:∃ m, ∀ (n : ℤ), m > n⊢ False
m:ℤhm:∀ (n : ℤ), m > n⊢ False -- `obtain ⟨m, hm⟩ := h` would also work here
m:ℤhm:m > m + 1⊢ False
All goals completed! 🐙Exercise A.5.1
def Exercise_A_5_1a : Decidable (∀ x > (0:ℝ), ∀ y > (0:ℝ), y^2 = x ) := ⊢ Decidable (∀ x > 0, ∀ y > 0, y ^ 2 = x)
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙def Exercise_A_5_1b : Decidable (∃ x > (0:ℝ), ∀ y > (0:ℝ), y^2 = x ) := ⊢ Decidable (∃ x > 0, ∀ y > 0, y ^ 2 = x)
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙def Exercise_A_5_1c : Decidable (∃ x > (0:ℝ), ∃ y > (0:ℝ), y^2 = x ) := ⊢ Decidable (∃ x > 0, ∃ y > 0, y ^ 2 = x)
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙def Exercise_A_5_1d : Decidable (∀ y > (0:ℝ), ∃ x > (0:ℝ), y^2 = x ) := ⊢ Decidable (∀ y > 0, ∃ x > 0, y ^ 2 = x)
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙def Exercise_A_5_1e : Decidable (∃ y > (0:ℝ), ∀ x > (0:ℝ), y^2 = x ) := ⊢ Decidable (∃ y > 0, ∀ x > 0, y ^ 2 = x)
-- the first line of this construction should be either `apply isTrue` or `apply isFalse`.
All goals completed! 🐙