Documentation

Bookshelf.Avigad.Chapter_8

Avigad.Chapter8 #

Induction and Recursion

Exercise 1 #

Open a namespace Hidden to avoid naming conflicts, and use the equation compiler to define addition, multiplication, and exponentiation on the natural numbers. Then use the equation compiler to derive some of their basic properties.

Exercise 2 #

Similarly, use the equation compiler to define some basic operations on lists (like the reverse function) and prove theorems about lists by induction (such as the fact that reverse (reverse xs) = xs for any list xs).

Exercise 3 #

Define your own function to carry out course-of-value recursion on the natural numbers. Similarly, see if you can figure out how to define WellFounded.fix on your own.

def Avigad.Chapter8.ex3.below {motive : NatSort u} (t : Nat) :
Sort (max 1 u)
Equations
Instances For
    noncomputable def Avigad.Chapter8.ex3.brecOn {motive : NatSort u} (t : Nat) (F : (t : Nat) → Avigad.Chapter8.ex3.below tmotive t) :
    motive t

    A copied implementation of Nat.brecOn with the motive properly supplied. Notice the noncomputable tag; the code generator does not support the recOn recursor yet, for reasons I haven't fully understood yet. This thread touches on the topic:

    https://leanprover-community.github.io/archive/stream/270676-lean4/topic/code.20generator.20does.20not.20support.20recursor.html

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Exercise 4 #

      Following the examples in Section Dependent Pattern Matching, define a function that will append two vectors. This is tricky; you will have to define an auxiliary function.

      inductive Avigad.Chapter8.ex4.Vector (α : Type u) :
      NatType u
      Instances For

        As long we flip the indices in our type signature in the resulting summation, there is no need for an auxiliary function.

        Equations
        Instances For

          Exercise 5 #

          Consider the following type of arithmetic expressions.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            Equations
            Instances For

              Constant Fusion #

              Implement "constant fusion," a procedure that simplifies subterms like 5 + 7 to 12. Using the auxiliary function simpConst, define a function "fuse": to simplify a plus or a times, first simplify the arguments recursively, and then apply simpConst` to try to simplify the result.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For