Documentation

Analysis.Section_3_3

Analysis I, Section 3.3: Functions #

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:

In the rest of the book we will deprecate the Chapter 3 version of a function, and work with the Mathlib notion of a function instead. Even within this section, we will switch to the Mathlib formalism for some of the examples involving number systems such as or that have not been implemented in the Chapter 3 framework.

We will work here with the version Nat of the natural numbers internal to the Chapter 3 set theory, though usually we will use coercions to then immediately translate to the Mathlib natural numbers .

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.

structure Chapter3.Function [SetTheory] (X Y : Set) :
Type u_2

Definition 3.3.1. Function X Y is the structure of functions from X to Y. Analogous to the Mathlib type X → Y.

Instances For
    theorem Chapter3.Function.ext {inst✝ : SetTheory} {X Y : Set} {x y : Function X Y} (P : x.P = y.P) :
    x = y
    theorem Chapter3.Function.ext_iff {inst✝ : SetTheory} {X Y : Set} {x y : Function X Y} :
    x = y x.P = y.P
    noncomputable def Chapter3.Function.to_fn [SetTheory] {X Y : Set} (f : Function X Y) :

    Converting a Chapter 3 function f: Function X Y to a Mathlib function f: X → Y. The Chapter 3 definition of a function was nonconstructive, so we have to use the axiom of choice here.

    Equations
    Instances For
      noncomputable instance Chapter3.Function.inst_coefn [SetTheory] (X Y : Set) :
      CoeFun (Function X Y) fun (x : Function X Y) => X.toSubtypeY.toSubtype
      Equations
      theorem Chapter3.Function.to_fn_eval [SetTheory] {X Y : Set} (f : Function X Y) (x : X.toSubtype) :
      f.to_fn x = f.to_fn x
      @[reducible, inline]
      abbrev Chapter3.Function.mk_fn [SetTheory] {X Y : Set} (f : X.toSubtypeY.toSubtype) :

      Converting a Mathlib function to a Chapter 3 Function

      Equations
      Instances For
        theorem Chapter3.Function.eval [SetTheory] {X Y : Set} (f : Function X Y) (x : X.toSubtype) (y : Y.toSubtype) :
        y = f.to_fn x f.P x y

        Definition 3.3.1

        @[simp]
        theorem Chapter3.Function.eval_of [SetTheory] {X Y : Set} (f : X.toSubtypeY.toSubtype) (x : X.toSubtype) :
        (mk_fn f).to_fn x = f x
        @[reducible, inline]
        Equations
        Instances For
          @[reducible, inline]
          Equations
          Instances For
            @[reducible, inline]

            Create a version of a non-zero n inside Nat \ {0} for any natural number n.

            Equations
            Instances For
              @[reducible, inline]

              Example 3.3.5. The unused variable _x is underscored to avoid triggering a linter.

              Equations
              Instances For
                theorem Chapter3.Function.eq_iff [SetTheory] {X Y : Set} (f g : Function X Y) :
                f = g ∀ (x : X.toSubtype), f.to_fn x = g.to_fn x

                Definition 3.3.8 (Equality of functions)

                @[reducible, inline]

                Example 3.3.10 (simplified). The second part of the example is tricky to replicate in this formalism, so a Mathlib substitute is offered instead.

                Equations
                Instances For
                  @[reducible, inline]

                  Example 3.3.11

                  Equations
                  Instances For
                    @[reducible, inline]
                    noncomputable abbrev Chapter3.Function.comp [SetTheory] {X Y Z : Set} (g : Function Y Z) (f : Function X Y) :

                    Definition 3.3.13 (Composition)

                    Equations
                    Instances For
                      theorem Chapter3.Function.comp_eval [SetTheory] {X Y Z : Set} (g : Function Y Z) (f : Function X Y) (x : X.toSubtype) :
                      (gf).to_fn x = g.to_fn (f.to_fn x)
                      theorem Chapter3.Function.comp_eq_comp [SetTheory] {X Y Z : Set} (g : Function Y Z) (f : Function X Y) :

                      Compatibility with Mathlib's composition operation.

                      theorem Chapter3.SetTheory.Set.comp_assoc [SetTheory] {W X Y Z : Set} (h : Function Y Z) (g : Function X Y) (f : Function W X) :
                      h(gf) = (hg)f

                      Lemma 3.3.15 (Composition is associative)

                      @[reducible, inline]
                      Equations
                      Instances For
                        theorem Chapter3.Function.one_to_one_iff [SetTheory] {X Y : Set} (f : Function X Y) :
                        f.one_to_one ∀ (x x' : X.toSubtype), f.to_fn x = f.to_fn x'x = x'

                        Compatibility with Mathlib's Function.Injective. You may wish to use the unfold tactic to understand Mathlib concepts such as Function.Injective.

                        Example 3.3.18. One half of the example requires the integers, and so is expressed using Mathlib functions instead of Chapter 3 functions.

                        theorem Chapter3.SetTheory.Set.two_to_one [SetTheory] {X Y : Set} {f : Function X Y} (h : ¬f.one_to_one) :
                        ∃ (x : X.toSubtype) (x' : X.toSubtype), x x' f.to_fn x = f.to_fn x'

                        Remark 3.3.19

                        @[reducible, inline]
                        abbrev Chapter3.Function.onto [SetTheory] {X Y : Set} (f : Function X Y) :

                        Definition 3.3.20 (Onto functions)

                        Equations
                        Instances For

                          Compatibility with Mathlib's Function.Surjective

                          @[reducible, inline]
                          Equations
                          Instances For
                            @[reducible, inline]

                            Definition 3.3.23 (Bijective functions)

                            Equations
                            Instances For

                              Compatibility with Mathlib's Function.Bijective

                              theorem Chapter3.Function.bijective_incorrect_def [SetTheory] :
                              ∃ (X : Set) (Y : Set) (f : Function X Y), (∀ (x : X.toSubtype), ∃! y : Y.toSubtype, y = f.to_fn x) ¬f.bijective

                              Remark 3.3.27

                              @[reducible, inline]
                              abbrev Chapter3.Function.inverse [SetTheory] {X Y : Set} (f : Function X Y) (h : f.bijective) :

                              We cannot use the notation f⁻¹ for the inverse because in Mathlib's Inv class, the inverse of f must be exactly of the same type of f, and Function Y X is a different type from Function X Y.

                              Equations
                              Instances For
                                theorem Chapter3.Function.inverse_eval [SetTheory] {X Y : Set} {f : Function X Y} (h : f.bijective) (y : Y.toSubtype) (x : X.toSubtype) :
                                x = (f.inverse h).to_fn y f.to_fn x = y

                                Compatibility with Mathlib's notion of inverse

                                theorem Chapter3.Function.refl [SetTheory] {X Y : Set} (f : Function X Y) :
                                f = f

                                Exercise 3.3.1. Although a proof operating directly on functions would be shorter, the spirit of the exercise is to show these using the Function.eq_iff definition.

                                theorem Chapter3.Function.symm [SetTheory] {X Y : Set} (f g : Function X Y) :
                                f = g g = f
                                theorem Chapter3.Function.trans [SetTheory] {X Y : Set} {f g h : Function X Y} (hfg : f = g) (hgh : g = h) :
                                f = h
                                theorem Chapter3.Function.comp_congr [SetTheory] {X Y Z : Set} {f f' : Function X Y} (hff' : f = f') {g g' : Function Y Z} (hgg' : g = g') :
                                gf = g'f'
                                theorem Chapter3.Function.comp_of_inj [SetTheory] {X Y Z : Set} {f : Function X Y} {g : Function Y Z} (hf : f.one_to_one) (hg : g.one_to_one) :

                                Exercise 3.3.2

                                theorem Chapter3.Function.comp_of_surj [SetTheory] {X Y Z : Set} {f : Function X Y} {g : Function Y Z} (hf : f.onto) (hg : g.onto) :
                                (gf).onto

                                Exercise 3.3.3 - fill in the sorrys in the statements in a reasonable fashion.

                                theorem Chapter3.Function.comp_cancel_left [SetTheory] {X Y Z : Set} {f f' : Function X Y} {g : Function Y Z} (heq : gf = gf') (hg : g.one_to_one) :
                                f = f'

                                Exercise 3.3.4.

                                theorem Chapter3.Function.comp_cancel_right [SetTheory] {X Y Z : Set} {f : Function X Y} {g g' : Function Y Z} (heq : gf = g'f) (hf : f.onto) :
                                g = g'
                                def Chapter3.Function.comp_cancel_left_without_hg [SetTheory] :
                                Decidable (∀ (X Y Z : Set) (f f' : Function X Y) (g : Function Y Z), gf = gf'f = f')
                                Equations
                                Instances For
                                  def Chapter3.Function.comp_cancel_right_without_hg [SetTheory] :
                                  Decidable (∀ (X Y Z : Set) (f : Function X Y) (g g' : Function Y Z), gf = g'fg = g')
                                  Equations
                                  Instances For
                                    theorem Chapter3.Function.comp_injective [SetTheory] {X Y Z : Set} {f : Function X Y} {g : Function Y Z} (hinj : (gf).one_to_one) :

                                    Exercise 3.3.5.

                                    theorem Chapter3.Function.comp_surjective [SetTheory] {X Y Z : Set} {f : Function X Y} {g : Function Y Z} (hsurj : (gf).onto) :
                                    def Chapter3.Function.comp_injective' [SetTheory] :
                                    Decidable (∀ (X Y Z : Set) (f : Function X Y) (g : Function Y Z), (gf).one_to_oneg.one_to_one)
                                    Equations
                                    Instances For
                                      def Chapter3.Function.comp_surjective' [SetTheory] :
                                      Decidable (∀ (X Y Z : Set) (f : Function X Y) (g : Function Y Z), (gf).ontof.onto)
                                      Equations
                                      Instances For
                                        theorem Chapter3.Function.inverse_comp_self [SetTheory] {X Y : Set} {f : Function X Y} (h : f.bijective) (x : X.toSubtype) :
                                        (f.inverse h).to_fn (f.to_fn x) = x

                                        Exercise 3.3.6

                                        theorem Chapter3.Function.self_comp_inverse [SetTheory] {X Y : Set} {f : Function X Y} (h : f.bijective) (y : Y.toSubtype) :
                                        f.to_fn ((f.inverse h).to_fn y) = y
                                        theorem Chapter3.Function.inverse_inverse [SetTheory] {X Y : Set} {f : Function X Y} (h : f.bijective) :
                                        (f.inverse h).inverse = f
                                        theorem Chapter3.Function.comp_bijective [SetTheory] {X Y Z : Set} {f : Function X Y} {g : Function Y Z} (hf : f.bijective) (hg : g.bijective) :
                                        theorem Chapter3.Function.inv_of_comp [SetTheory] {X Y Z : Set} {f : Function X Y} {g : Function Y Z} (hf : f.bijective) (hg : g.bijective) :
                                        (gf).inverse = f.inverse hfg.inverse hg

                                        Exercise 3.3.7

                                        @[reducible, inline]
                                        abbrev Chapter3.Function.inclusion [SetTheory] {X Y : Set} (h : X Y) :

                                        Exercise 3.3.8

                                        Equations
                                        Instances For
                                          @[reducible, inline]
                                          Equations
                                          Instances For
                                            theorem Chapter3.Function.inclusion_comp [SetTheory] (X Y Z : Set) (hXY : X Y) (hYZ : Y Z) :
                                            theorem Chapter3.Function.comp_id [SetTheory] {A B : Set} (f : Function A B) :
                                            fid A = f
                                            theorem Chapter3.Function.id_comp [SetTheory] {A B : Set} (f : Function A B) :
                                            id Bf = f
                                            theorem Chapter3.Function.comp_inv [SetTheory] {A B : Set} (f : Function A B) (hf : f.bijective) :
                                            ff.inverse hf = id B
                                            theorem Chapter3.Function.inv_comp [SetTheory] {A B : Set} (f : Function A B) (hf : f.bijective) :
                                            f.inverse hff = id A
                                            theorem Chapter3.Function.glue [SetTheory] {X Y Z : Set} (hXY : Disjoint X Y) (f : Function X Z) (g : Function Y Z) :
                                            ∃! h : Function (X Y) Z, hinclusion = f hinclusion = g
                                            theorem Chapter3.Function.glue' [SetTheory] {X Y Z : Set} (f : Function X Z) (g : Function Y Z) (hfg : ∀ (x : (X Y).toSubtype), f.to_fn x, = g.to_fn x, ) :
                                            ∃! h : Function (X Y) Z, hinclusion = f hinclusion = g