Analysis I, Section 2.1

This file is a translation of Section 2.1 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:

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.

namespace Chapter2

Assumption 2.6 (Existence of natural numbers). Here we use an explicit construction of the natural numbers (using an inductive type). For a more axiomatic approach, see the epilogue to this chapter.

inductive Nat where | zero : Nat | succ : Nat Nat deriving Repr, DecidableEq -- this allows `decide` to work on `Nat`

Axiom 2.1 (0 is a natural number)

instance Nat.instZero : Zero Nat := zero 0 : Nat#check (0:Nat)
0 : Nat
/-- Axiom 2.2 (Successor of a natural number is a natural number) -/ postfix:100 "++" => Nat.succfun n => n++ : Nat → Nat#check (fun n n++)
fun n => n++ : Nat → Nat

Definition 2.1.3 (Definition of the numerals 0, 1, 2, etc.). Note: to avoid ambiguity, one may need to use explicit casts such as (0:Nat), (1:Nat), etc. to refer to this Chapter's version of the natural numbers.

instance Nat.instOfNat {n:_root_.Nat} : OfNat Nat n where ofNat := _root_.Nat.rec 0 (fun _ n n++) ninstance Nat.instOne : One Nat := 1 lemma Nat.zero_succ : 0++ = 1 := 0++ = 1 All goals completed! 🐙1 : Nat#check (1:Nat)
1 : Nat
lemma Nat.one_succ : 1++ = 2 := 1++ = 2 All goals completed! 🐙2 : Nat#check (2:Nat)
2 : Nat
/-- Proposition 2.1.4 (3 is a natural number)-/ lemma Nat.two_succ : 2++ = 3 := 2++ = 3 All goals completed! 🐙3 : Nat#check (3:Nat)
3 : Nat

Axiom 2.3 (0 is not the successor of any natural number)

theorem Nat.succ_ne (n:Nat) : n++ 0 := n:Natn++0 n:Nath:n++ = 0False All goals completed! 🐙

Proposition 2.1.6 (4 is not equal to zero)

theorem Nat.four_ne : (4:Nat) 0 := 40 -- By definition, 4 = 3++. 3++0 -- By axiom 2.3, 3++ is not zero. All goals completed! 🐙

Axiom 2.4 (Different natural numbers have different successors)

theorem Nat.succ_cancel {n m:Nat} (hnm: n++ = m++) : n = m := n:Natm:Nathnm:n++ = m++n = m rwa [succ.injEqn:Natm:Nathnm:n = mn = m at hnm

Axiom 2.4 (Different natural numbers have different successors)

theorem Nat.succ_ne_succ (n m:Nat) : n m n++ m++ := n:Natm:Natnmn++m++ n:Natm:Nath:nmn++m++ n:Natm:Nath:n++ = m++n = m All goals completed! 🐙

Proposition 2.1.8 (6 is not equal to 2)

theorem Nat.six_ne_two : (6:Nat) 2 := 62 -- this proof is written to follow the structure of the original text. h:6 = 2False h:5++ = 1++False h:5 = 1False h:4++ = 0++False h:4 = 0False h:4 = 0this:40False All goals completed! 🐙

One can also prove this sort of result by the decide tactic

theorem Nat.six_ne_two' : (6:Nat) 2 := 62 All goals completed! 🐙

Axiom 2.5 (principle of mathematical induction).

theorem Nat.induction (P : Nat Prop) (hbase : P 0) (hind : n, P n P (n++)) : n, P n := P:NatProphbase:P 0hind:∀ (n : Nat), P nP (n++)∀ (n : Nat), P n P:NatProphbase:P 0hind:∀ (n : Nat), P nP (n++)n:NatP n induction n with | zero => All goals completed! 🐙 | succ n ih => All goals completed! 🐙abbrev Nat.recurse (f: Nat Nat Nat) (c: Nat) : Nat Nat := fun n match n with | 0 => c | n++ => f n (recurse f c n)

Proposition 2.1.16 (recursive definitions).

theorem Nat.recurse_zero (f: Nat Nat Nat) (c: Nat) : Nat.recurse f c 0 = c := f:NatNatNatc:Natrecurse f c 0 = c All goals completed! 🐙

Proposition 2.1.16 (recursive definitions).

theorem Nat.recurse_succ (f: Nat Nat Nat) (c: Nat) (n: Nat) : recurse f c (n++) = f n (recurse f c n) := f:NatNatNatc:Natn:Natrecurse f c (n++) = f n (recurse f c n) All goals completed! 🐙

Proposition 2.1.16 (recursive definitions).

theorem Nat.eq_recurse (f: Nat Nat Nat) (c: Nat) (a: Nat Nat) : (a 0 = c n, a (n++) = f n (a n)) a = recurse f c := f:NatNatNatc:Nata:NatNat(a 0 = c∀ (n : Nat), a (n++) = f n (a n))a = recurse f c f:NatNatNatc:Nata:NatNat(a 0 = c∀ (n : Nat), a (n++) = f n (a n))a = recurse f cf:NatNatNatc:Nata:NatNata = recurse f ca 0 = c∀ (n : Nat), a (n++) = f n (a n) f:NatNatNatc:Nata:NatNat(a 0 = c∀ (n : Nat), a (n++) = f n (a n))a = recurse f c f:NatNatNatc:Nata:NatNath0:a 0 = chsucc:∀ (n : Nat), a (n++) = f n (a n)a = recurse f c -- this proof is written to follow the structure of the original text. f:NatNatNatc:Nata:NatNath0:a 0 = chsucc:∀ (n : Nat), a (n++) = f n (a n)∀ (x : Nat), a x = recurse f c x; f:NatNatNatc:Nata:NatNath0:a 0 = chsucc:∀ (n : Nat), a (n++) = f n (a n)a 0 = recurse f c 0f:NatNatNatc:Nata:NatNath0:a 0 = chsucc:∀ (n : Nat), a (n++) = f n (a n)∀ (n : Nat), a n = recurse f c na (n++) = recurse f c (n++) f:NatNatNatc:Nata:NatNath0:a 0 = chsucc:∀ (n : Nat), a (n++) = f n (a n)a 0 = recurse f c 0 All goals completed! 🐙 f:NatNatNatc:Nata:NatNath0:a 0 = chsucc:∀ (n : Nat), a (n++) = f n (a n)n:Nathn:a n = recurse f c na (n++) = recurse f c (n++) All goals completed! 🐙 f:NatNatNatc:Nata:NatNath:a = recurse f ca 0 = c∀ (n : Nat), a (n++) = f n (a n) f:NatNatNatc:Nata:NatNath:a = recurse f crecurse f c 0 = c∀ (n : Nat), recurse f c (n++) = f n (recurse f c n) f:NatNatNatc:Nata:NatNath:a = recurse f crecurse f c 0 = cf:NatNatNatc:Nata:NatNath:a = recurse f c∀ (n : Nat), recurse f c (n++) = f n (recurse f c n) f:NatNatNatc:Nata:NatNath:a = recurse f crecurse f c 0 = c All goals completed! 🐙 All goals completed! 🐙

Proposition 2.1.16 (recursive definitions).

theorem Nat.recurse_uniq (f: Nat Nat Nat) (c: Nat) : ∃! (a: Nat Nat), a 0 = c n, a (n++) = f n (a n) := f:NatNatNatc:Nat∃! a, a 0 = c∀ (n : Nat), a (n++) = f n (a n) f:NatNatNatc:Natrecurse f c 0 = c∀ (n : Nat), recurse f c (n++) = f n (recurse f c n)f:NatNatNatc:Nat∀ (y : NatNat), (y 0 = c∀ (n : Nat), y (n++) = f n (y n))y = recurse f c f:NatNatNatc:Natrecurse f c 0 = c∀ (n : Nat), recurse f c (n++) = f n (recurse f c n) f:NatNatNatc:Natrecurse f c 0 = cf:NatNatNatc:Nat∀ (n : Nat), recurse f c (n++) = f n (recurse f c n) f:NatNatNatc:Natrecurse f c 0 = c All goals completed! 🐙 f:NatNatNatc:Nat∀ (n : Nat), recurse f c (n++) = f n (recurse f c n) All goals completed! 🐙 f:NatNatNatc:Nata:NatNat(a 0 = c∀ (n : Nat), a (n++) = f n (a n))a = recurse f c All goals completed! 🐙end Chapter2