Day 21: Week 3 review: what was really proved?
Read a definition together with a theorem about it, and say exactly what was proved.
This week was about what makes a statement mean something different from what it looks like:
-
def: a name for a body. Lean does not read the name; read the body. -
Cases and recursion: compute small cases by hand to see what a definition does.
-
Structures and namespaces:
p.x,n.succ,h.1; a structure can hide hypotheses, andopencan hide where a name comes from. -
Hidden arguments:
{ },[ ], and undeclared names (autoImplicit) are all “for every”.@shows everything. -
Number types:
Nat,Int, ℝ.↑is a conversion, and where it happens matters. -
Junk values:
x / 0 = 0,√(-4) = 0. Shorthand:∀ ε > 0uses →,∃ δ > 0uses ∧.
Try it on this one before you read the verdict:
def avg (a b : Nat) : Nat := (a + b) / 2
theorem avg_between (h : a ≤ b) : a ≤ avg a b ∧ avg a b ≤ b := a:Natb:Nath:a ≤ b⊢ a ≤ avg a b ∧ avg a b ≤ b
a:Natb:Nath:a ≤ b⊢ a ≤ (a + b) / 2 ∧ (a + b) / 2 ≤ b
All goals completed! 🐙
-
avgis aNataverage: it rounds down, soavg 3 4 = 3. -
aandbare never declared: autoImplicit makes them hidden “for every” variables, of typeNatbecauseavgneeds them. -
h : a ≤ bis a real hypothesis.
For all natural numbers a ≤ b, the rounded-down average of a and b lies between a and b.
That is a true and honest statement, but about rounded-down averages of natural numbers, not averages of real numbers.