This problem set practises the tactics of Lecture 3 and the first induction of Lecture 4. The problems get harder in order. Propositional logic comes first (Problem 1, Problem 2, Problem 3, Problem 4), then quantifiers (Problem 5, Problem 6), a chain of equations (Problem 7), and an induction (Problem 8).

How to work on it. Open the lean/ folder (not the course root) in VS Code with the Lean 4 extension, then open LeanFV/Homework/HW01.lean. Each problem below names its theorem in that file, such as HW01.and_swap. Replace the sorry with a proof, watching the goal in the infoview as you go. The file is finished when it shows no sorry warnings. You can also work in a notebook: start it with leanmagic.setup("import LeanFV.Homework.HW01") and copy a statement into a %%lean cell.

The file imports nothing, so you have core Lean only. That covers every tactic you need: write exists 3 (or ⟨3, ?_⟩ with refine) where Lecture 3 used Mathlib’s use 3. omega, decide, simp, grind and exact? are all available. Each solution below is collapsed; open it after you have a proof of your own, or after you have been stuck for a while. Many proofs are correct, and yours need not match.

Propositional logic

Problem 1 (Chain two implications).

Prove (p → q) → (q → r) → p → r (HW01.imp_chain).

Problem 2 (Swap a conjunction).

Prove p ∧ q → q ∧ p (HW01.and_swap). Take the hypothesis apart instead of using .1 and .2.

Problem 3 (Distribute ∧ over ∨).

Prove p ∧ (q ∨ r) → (p ∧ q) ∨ (p ∧ r) (HW01.and_or_split).

Problem 4 (A De Morgan law).

Prove ¬(p ∨ q) → ¬p ∧ ¬q (HW01.not_or_split).

Quantifiers

Problem 5 (Split a universal conjunction).

For predicates P Q : α → Prop, prove (∀ x, P x ∧ Q x) → (∀ x, P x) ∧ (∀ x, Q x) (HW01.forall_and_split).

Problem 6 (An even number above n).

Prove that above every natural number there is an even one: ∀ n : Nat, ∃ m, n < m ∧ m % 2 = 0 (HW01.exists_even_above).

Equations

Problem 7 (Rewrite, then compute).

From h1 : a = b + 2 and h2 : b = 2 * c, prove a + c = 3 * c + 2 (HW01.rewrite_chain). Use rw for the substitution and something else for the arithmetic.

A first induction

Problem 8 (Sum of odd numbers).

The homework file defines the sum of the first n odd numbers:

def sumOdd : Nat → Nat
  | 0 => 0
  | n + 1 => sumOdd n + (2 * n + 1)

Prove sumOdd n = n * n (HW01.sum_odd).

Back to Lecture 3 · Lecture 4