Analysis I, Section 4.2 #
This file is a translation of Section 4.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 the "Section 4.2" rationals,
Section_4_2.Rat, as formal quotientsa // bof integersa b:ℤ, up to equivalence. (This is a quotient of a scaffolding typeSection_4_2.PreRat, which consists of formal quotients without any equivalence imposed.)Field operations and order on these rationals, as well as an embedding of ℕ and ℤ.
Equivalence with the Mathlib rationals
_root_.Rat(orℚ), which we will use going forward.
Note: here (and in the sequel) we use Mathlib's natural numbers ℕ and integers ℤ rather than
the Chapter 2 natural numbers and Section 4.1 integers.
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)
Instances For
Exercise 4.2.1
Equations
- Section_4_2.PreRat.instSetoid = { r := fun (a b : Section_4_2.PreRat) => a.numerator * b.denominator = b.numerator * a.denominator, iseqv := Section_4_2.PreRat.instSetoid._proof_1 }
Instances For
We give division a "junk" value of 0//1 if the denominator is zero
Equations
Instances For
Equations
- Section_4_2.«term_//_» = Lean.ParserDescr.trailingNode `Section_4_2.«term_//_» 100 101 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " // ") (Lean.ParserDescr.cat `term 101))
Instances For
Decidability of equality. Hint: modify the proof of DecidableEq Int from the previous
section. However, because formal division handles the case of zero denominator separately, it
may be more convenient to avoid that operation and work directly with the Quotient API.
Equations
- Section_4_2.Rat.decidableEq = sorry
Lemma 4.2.3 (Addition well-defined)
Equations
- One or more equations did not get rendered due to their size.
Lemma 4.2.3 (Multiplication well-defined)
Equations
- One or more equations did not get rendered due to their size.
Lemma 4.2.3 (Negation well-defined)
Equations
- One or more equations did not get rendered due to their size.
Embedding the integers in the rationals
Equations
- Section_4_2.Rat.instOfNat = { ofNat := ↑n // 1 }
Whereas the book leaves the inverse of 0 undefined, it is more convenient in Lean to assign a "junk" value to this inverse; we arbitrarily choose this junk value to be 0.
Equations
- One or more equations did not get rendered due to their size.
Proposition 4.2.4 (laws of algebra) / Exercise 4.2.3
Proposition 4.2.4 (laws of algebra) / Exercise 4.2.3
Equations
- Section_4_2.Rat.instAddCommGroup = { toAddGroup := Section_4_2.Rat.addGroup_inst, add_comm := Section_4_2.Rat.instAddCommGroup._proof_1 }
Proposition 4.2.4 (laws of algebra) / Exercise 4.2.3
Equations
- One or more equations did not get rendered due to their size.
Proposition 4.2.4 (laws of algebra) / Exercise 4.2.3
Equations
- One or more equations did not get rendered due to their size.
Default definition of division
Equations
- One or more equations did not get rendered due to their size.
Proposition 4.2.4 (laws of algebra) / Exercise 4.2.3
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Definition 4.2.8 (Ordering of the rationals)
Equations
- Section_4_2.Rat.instLT = { lt := fun (x y : Section_4_2.Rat) => (x - y).isNeg }
Definition 4.2.8 (Ordering of the rationals)
Equations
- Section_4_2.Rat.instLE = { le := fun (x y : Section_4_2.Rat) => x < y ∨ x = y }
(Not from textbook) Establish the decidability of this order.
Equations
- One or more equations did not get rendered due to their size.
(Not from textbook) Rat has the structure of a linear ordering.
Equations
- One or more equations did not get rendered due to their size.
(Not from textbook) Rat has the structure of a strict ordered ring.
Not in textbook: create an equivalence between Rat and ℚ. This requires some familiarity with the API for Mathlib's version of the rationals.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Not in textbook: equivalence preserves order
Equations
- Section_4_2.Rat.equivRat_order = { toEquiv := Section_4_2.Rat.equivRat, map_rel_iff' := @Section_4_2.Rat.equivRat_order._proof_1 }
Instances For
Not in textbook: equivalence preserves ring operations
Equations
- Section_4_2.Rat.equivRat_ring = { toEquiv := Section_4_2.Rat.equivRat, map_mul' := Section_4_2.Rat.equivRat_ring._proof_1, map_add' := Section_4_2.Rat.equivRat_ring._proof_2 }
Instances For
(Not from textbook) The textbook rationals are isomorphic (as a field) to the Mathlib rationals.