Subtraction: example of intertwined proofs and definitions. #
The difference of natural numbers is not a natural number. We see three ways of overcoming this problem, which illustrate various important concepts in Lean.
The first two are in an earlier module while the third is in this one.
Here we subtract natural numbers only when given a proof that the second is less than or equal to the first. Note that as any two terms whose type is the same proposition are equal by definition, the value will not depend on the specific proof.
Equations
- Nat.«term_-₀_» = Lean.ParserDescr.trailingNode `Nat.term_-₀_ 1022 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "-₀") (Lean.ParserDescr.cat `term 0))
Instances For
Note that in Lean 4
there is a result Nat.sub_add_cancel
which is analogous to minus_add_cancel
above. However the statement of the result requires that the subtraction is valid.
#check Nat.sub_add_cancel -- Nat.sub_add_cancel {n m : ℕ} (h : m ≤ n) : n - m + m = n