Analysis I, Appendix A.4: Variables and quantifiers
Some examples of how variables and quantifiers are used in Lean
namespace VariableExample1variable (X:Type) (x y:X)-- #check x+y = y+x -- this will not typecheck
end VariableExample1namespace VariableExample2variable (x:ℝ)example (h: x = 2) : x + 3 = 5 := x:ℝh:x = 2⊢ x + 3 = 5 All goals completed! 🐙example (h: x ≠ 2) : x + 3 ≠ 5 := x:ℝh:x ≠ 2⊢ x + 3 ≠ 5
x:ℝh:x + 3 = 5⊢ x = 2
All goals completed! 🐙example : ¬ ∀ (x:ℝ), x + 3 = 5 := x:ℝ⊢ ¬∀ (x : ℝ), x + 3 = 5
x:ℝ⊢ ∃ x, ¬x + 3 = 5
x:ℝ⊢ ¬0 + 3 = 5
All goals completed! 🐙example : ¬ ∀ (x:ℝ), x + 3 ≠ 5 := x:ℝ⊢ ¬∀ (x : ℝ), x + 3 ≠ 5
x:ℝ⊢ ∃ x, x + 3 = 5
x:ℝ⊢ 2 + 3 = 5
All goals completed! 🐙example : ∃ (x:ℝ), x + 3 = 5 := x:ℝ⊢ ∃ x, x + 3 = 5
x:ℝ⊢ 2 + 3 = 5
All goals completed! 🐙example : ∀ (x:ℝ), (x+1)^2 = x^2 + 2*x + 1 := x:ℝ⊢ ∀ (x : ℝ), (x + 1) ^ 2 = x ^ 2 + 2 * x + 1
x✝:ℝx:ℝ⊢ (x + 1) ^ 2 = x ^ 2 + 2 * x + 1
All goals completed! 🐙end VariableExample2A dummy statement is in place here for this example.
example : 0 = 0 := ⊢ 0 = 0
x:ℕ := 342⊢ 0 = 0
have : x + 155 = 497 := ⊢ 0 = 0
x:ℕ := 342⊢ 342 + 155 = 497
All goals completed! 🐙
All goals completed! 🐙example : ¬ ∀ (x:ℝ), x + 155 = 497 := ⊢ ¬∀ (x : ℝ), x + 155 = 497
⊢ ∃ x, ¬x + 155 = 497
⊢ ¬0 + 155 = 497
All goals completed! 🐙example : ¬ ∀ x > (0:ℝ), x^2 > x := ⊢ ¬∀ x > 0, x ^ 2 > x
⊢ ∃ x, 0 < x ∧ x ^ 2 ≤ x
⊢ 0 < 0.5 ∧ 0.5 ^ 2 ≤ 0.5
All goals completed! 🐙/- The code below will not typecheck.
example : ∀ (x:ℝ), x + 3 = 5 := by
use 2
sorry
-/
example : ∀ x, (3 < x ∧ x < 2) → (6 < 2*x ∧ 2*x < 4) := ⊢ ∀ (x : ℕ), 3 < x ∧ x < 2 → 6 < 2 * x ∧ 2 * x < 4
x:ℕ⊢ 3 < x ∧ x < 2 → 6 < 2 * x ∧ 2 * x < 4
x:ℕh:3 < x ∧ x < 2⊢ 6 < 2 * x ∧ 2 * x < 4
x:ℕh1:3 < xh2:x < 2⊢ 6 < 2 * x ∧ 2 * x < 4
-- the previous three lines can be golfed to `intro x ⟨ h1, h2 ⟩`
x:ℕh1:3 < xh2:x < 2⊢ 6 < 2 * xx:ℕh1:3 < xh2:x < 2⊢ 2 * x < 4
x:ℕh1:3 < xh2:x < 2⊢ 6 < 2 * x All goals completed! 🐙
All goals completed! 🐙example : ∃ (x:ℝ), x^2 + 2*x - 8 = 0 := ⊢ ∃ x, x ^ 2 + 2 * x - 8 = 0
⊢ 2 ^ 2 + 2 * 2 - 8 = 0
All goals completed! 🐙example : ¬ ∃ x, (3 < x ∧ x < 2) ∧ (6 < 2*x ∧ 2*x < 4) := ⊢ ¬∃ x, (3 < x ∧ x < 2) ∧ 6 < 2 * x ∧ 2 * x < 4
⊢ ∀ (x : ℕ), 3 < x → x < 2 → 6 < 2 * x → 4 ≤ 2 * x
x:ℕh1:3 < xh2:x < 2h3:6 < 2 * x⊢ 4 ≤ 2 * x
All goals completed! 🐙