Analysis I, Section 2.2: Addition #
This file is a translation of Section 2.2 of Analysis I to Lean 4. All numbering refers to the original text.
I have attempted to make the translation as faithful a paraphrasing as possible of the original text. When there is a choice between a more idiomatic Lean solution and a more faithful translation, I have generally chosen the latter. In particular, there will be places where the Lean code could be "golfed" to be more elegant and idiomatic, but I have consciously avoided doing so.
Main constructions and results of this section:
- Definition of addition and order for the "Chapter 2" natural numbers,
Chapter2.Nat. - Establishment of basic properties of addition and order.
Note: at the end of this chapter, the Chapter2.Nat class will be deprecated in favor of the
standard Mathlib class _root_.Nat, or ℕ. However, we will develop the properties of
Chapter2.Nat "by hand" for pedagogical purposes.
Tips from past users #
Users of the companion who have completed the exercises in this section are welcome to send their tips for future users in this section as PRs.
- (Add tip here)
Definition 2.2.1. (Addition of natural numbers).
Compare with Mathlib's Nat.add
Equations
- n.add m = Chapter2.Nat.recurse (fun (x sum : Chapter2.Nat) => sum++) m n
Instances For
This instance allows for the + notation to be used for natural number addition.
Equations
- Chapter2.Nat.instAdd = { add := Chapter2.Nat.add }
Compare with Mathlib's Nat.zero_add.
Compare with Mathlib's Nat.succ_add.
Lemma 2.2.2 (n + 0 = n). Compare with Mathlib's Nat.add_zero.
Lemma 2.2.3 (n+(m++) = (n+m)++). Compare with Mathlib's Nat.add_succ.
n++ = n + 1 (Why?). Compare with Mathlib's Nat.succ_eq_add_one
Proposition 2.2.4 (Addition is commutative). Compare with Mathlib's Nat.add_comm
Proposition 2.2.5 (Addition is associative) / Exercise 2.2.1
Compare with Mathlib's Nat.add_assoc.
Proposition 2.2.6 (Cancellation law).
Compare with Mathlib's Nat.add_left_cancel.
(Not from textbook) Nat can be given the structure of a commutative additive monoid.
This permits tactics such as abel to apply to the Chapter 2 natural numbers.
Equations
- One or more equations did not get rendered due to their size.
Proposition 2.2.8 (positive plus natural number is positive).
Compare with Mathlib's Nat.add_pos_left.
Compare with Mathlib's Nat.add_pos_right.
This theorem is a consequence of the previous theorem and add_comm, and grind can automatically discover such proofs.
Corollary 2.2.9 (if sum vanishes, then summands vanish).
Compare with Mathlib's Nat.add_eq_zero.
Definition 2.2.11 (Ordering of the natural numbers).
This defines the ≤ notation on the natural numbers.
Equations
- Chapter2.Nat.instLE = { le := fun (n m : Chapter2.Nat) => ∃ (a : Chapter2.Nat), m = n + a }
Definition 2.2.11 (Ordering of the natural numbers).
This defines the < notation on the natural numbers.
Equations
- Chapter2.Nat.instLT = { lt := fun (n m : Chapter2.Nat) => n ≤ m ∧ n ≠ m }
Compare with Mathlib's Nat.le_of_lt.
Compare with Mathlib's Nat.le_iff_lt_or_eq.
Proposition 2.2.12 (Basic properties of order for natural numbers) / Exercise 2.2.3
(a) (Order is reflexive). Compare with Mathlib's Nat.le_refl.
(b) (Order is transitive). The obtain tactic will be useful here.
Compare with Mathlib's Nat.le_trans.
(c) (Order is anti-symmetric). Compare with Mathlib's Nat.le_antisymm.
(d) (Addition preserves order). Compare with Mathlib's Nat.add_le_add_right.
(d) (Addition preserves order). Compare with Mathlib's Nat.add_le_add_left.
(d) (Addition preserves order). Compare with Mathlib's Nat.add_le_add_right.
(d) (Addition preserves order). Compare with Mathlib's Nat.add_le_add_left.
(e) a < b iff a++ ≤ b. Compare with Mathlib's Nat.succ_le_iff.
This lemma was a why? statement from Proposition 2.2.13,
but is more broadly useful, so is extracted here.
Proposition 2.2.13 (Trichotomy of order for natural numbers) / Exercise 2.2.4
Compare with Mathlib's trichotomous. Parts of this theorem have been placed
in the preceding Lean theorems.
(Not from textbook) Establish the decidability of this order computably. The portion of the
proof involving decidability has been provided; the remaining sorries involve claims about the
natural numbers. One could also have established this result by the classical tactic
followed by exact Classical.decRel _, but this would make this definition (as well as some
instances below) noncomputable.
Compare with Mathlib's Nat.decLe.
Equations
- One or more equations did not get rendered due to their size.
- Chapter2.Nat.zero.decLe x✝ = isTrue ⋯
Instances For
Equations
(Not from textbook) Nat has the structure of a linear ordering. This allows for tactics
such as order and calc to be applicable to the Chapter 2 natural numbers.
Equations
- One or more equations did not get rendered due to their size.
(Not from textbook) Nat has the structure of an ordered monoid. This allows for tactics
such as gcongr to be applicable to the Chapter 2 natural numbers.
Exercise 2.2.6 (backwards induction)
Compare with Mathlib's Nat.decreasingInduction.
Exercise 2.2.7 (induction from a starting point)
Compare with Mathlib's Nat.le_induction.