Documentation

Analysis.Section_4_2

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:

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.

Instances For
    @[simp]
    theorem Section_4_2.PreRat.eq (a b c d : ) (hb : b 0) (hd : d 0) :
    { numerator := a, denominator := b, nonzero := hb } { numerator := c, denominator := d, nonzero := hd } a * d = c * b
    @[reducible, inline]
    Equations
    Instances For
      @[reducible, inline]

      We give division a "junk" value of 0//1 if the denominator is zero

      Equations
      Instances For
        theorem Section_4_2.Rat.eq (a c : ) {b d : } (hb : b 0) (hd : d 0) :
        a // b = c // d a * d = c * b

        Definition 4.2.1 (Rationals)

        theorem Section_4_2.Rat.eq_diff (n : Rat) :
        ∃ (a : ) (b : ), b 0 n = a // b

        Definition 4.2.1 (Rationals)

        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

        Lemma 4.2.3 (Addition well-defined)

        Equations
        • One or more equations did not get rendered due to their size.
        theorem Section_4_2.Rat.add_eq (a c : ) {b d : } (hb : b 0) (hd : d 0) :
        a // b + c // d = (a * d + b * c) // (b * d)

        Definition 4.2.2 (Addition of rationals)

        Lemma 4.2.3 (Multiplication well-defined)

        Equations
        • One or more equations did not get rendered due to their size.
        theorem Section_4_2.Rat.mul_eq (a c : ) {b d : } (hb : b 0) (hd : d 0) :
        a // b * c // d = (a * c) // (b * d)

        Definition 4.2.2 (Multiplication of rationals)

        Lemma 4.2.3 (Negation well-defined)

        Equations
        • One or more equations did not get rendered due to their size.
        theorem Section_4_2.Rat.neg_eq (a : ) {b : } (hb : b 0) :
        -a // b = (-a) // b

        Definition 4.2.2 (Negation of rationals)

        Embedding the integers in the rationals

        Equations
        Equations
        Equations
        theorem Section_4_2.Rat.coe_Int_eq (a : ) :
        a = a // 1
        theorem Section_4_2.Rat.coe_Nat_eq (n : ) :
        n = n // 1
        theorem Section_4_2.Rat.natCast_succ (n : ) :
        ↑(n + 1) = n + 1

        natCast distributes over successor

        theorem Section_4_2.Rat.intCast_add (a b : ) :
        a + b = ↑(a + b)

        intCast distributes over addition

        theorem Section_4_2.Rat.intCast_mul (a b : ) :
        a * b = ↑(a * b)

        intCast distributes over multiplication

        theorem Section_4_2.Rat.intCast_neg (a : ) :
        -a = ↑(-a)

        intCast commutes with negation

        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.
        theorem Section_4_2.Rat.inv_eq (a : ) {b : } (hb : b 0) :
        (a // b)⁻¹ = b // a

        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.
        Equations
        theorem Section_4_2.Rat.coe_Rat_eq (a : ) {b : } (hb : b 0) :
        ↑(a / b) = a // b

        Default definition of division

        Equations
        • One or more equations did not get rendered due to their size.
        theorem Section_4_2.Rat.div_eq (q r : Rat) :
        q / r = q * r⁻¹

        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.6 (positivity)

          Equations
          Instances For

            Definition 4.2.6 (negativity)

            Equations
            Instances For

              Lemma 4.2.7 (trichotomy of rationals) / Exercise 4.2.4

              Lemma 4.2.7 (trichotomy of rationals) / Exercise 4.2.4

              Lemma 4.2.7 (trichotomy of rationals) / Exercise 4.2.4

              Lemma 4.2.7 (trichotomy of rationals) / Exercise 4.2.4

              Definition 4.2.8 (Ordering of the rationals)

              Equations

              Definition 4.2.8 (Ordering of the rationals)

              Equations
              theorem Section_4_2.Rat.lt_iff (x y : Rat) :
              x < y (x - y).isNeg
              theorem Section_4_2.Rat.le_iff (x y : Rat) :
              x y x < y x = y
              theorem Section_4_2.Rat.gt_iff (x y : Rat) :
              x > y (x - y).isPos
              theorem Section_4_2.Rat.ge_iff (x y : Rat) :
              x y x > y x = y
              theorem Section_4_2.Rat.trichotomous' (x y : Rat) :
              x > y x < y x = y

              Proposition 4.2.9(a) (order trichotomy) / Exercise 4.2.5

              theorem Section_4_2.Rat.not_gt_and_lt (x y : Rat) :
              ¬(x > y x < y)

              Proposition 4.2.9(a) (order trichotomy) / Exercise 4.2.5

              theorem Section_4_2.Rat.not_gt_and_eq (x y : Rat) :
              ¬(x > y x = y)

              Proposition 4.2.9(a) (order trichotomy) / Exercise 4.2.5

              theorem Section_4_2.Rat.not_lt_and_eq (x y : Rat) :
              ¬(x < y x = y)

              Proposition 4.2.9(a) (order trichotomy) / Exercise 4.2.5

              theorem Section_4_2.Rat.antisymm (x y : Rat) :
              x < y y > x

              Proposition 4.2.9(b) (order is anti-symmetric) / Exercise 4.2.5

              theorem Section_4_2.Rat.lt_trans {x y z : Rat} (hxy : x < y) (hyz : y < z) :
              x < z

              Proposition 4.2.9(c) (order is transitive) / Exercise 4.2.5

              theorem Section_4_2.Rat.add_lt_add_right {x y : Rat} (z : Rat) (hxy : x < y) :
              x + z < y + z

              Proposition 4.2.9(d) (addition preserves order) / Exercise 4.2.5

              theorem Section_4_2.Rat.mul_lt_mul_right {x y z : Rat} (hxy : x < y) (hz : z.isPos) :
              x * z < y * z

              Proposition 4.2.9(e) (positive multiplication preserves order) / Exercise 4.2.5

              instance Section_4_2.Rat.decidableRel :
              DecidableRel fun (x1 x2 : Rat) => x1 x2

              (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.

              theorem Section_4_2.Rat.mul_lt_mul_right_of_neg (x y z : Rat) (hxy : x < y) (hz : z.isNeg) :
              x * z > y * z

              Exercise 4.2.6

              @[reducible, inline]

              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
                @[reducible, inline]

                Not in textbook: equivalence preserves order

                Equations
                Instances For
                  @[reducible, inline]

                  Not in textbook: equivalence preserves ring operations

                  Equations
                  Instances For

                    (Not from textbook) The textbook rationals are isomorphic (as a field) to the Mathlib rationals.

                    Equations
                    Instances For