Documentation

Bookshelf.Avigad.Chapter_7

Avigad.Chapter7 #

Inductive Types

Exercise 1 #

Try defining other operations on the natural numbers, such as multiplication, the predecessor function (with pred 0 = 0), truncated subtraction (with n - m = 0 when m is greater than or equal to n), and exponentiation. Then try proving some of their basic properties, building on the theorems we have already proved.

Since many of these are already defined in Lean’s core library, you should work within a namespace named hide, or something like that, in order to avoid name clashes.

Exercise 2 #

Define some operations on lists, like a length function or the reverse function. Prove some properties, such as the following:

a. length (s ++ t) = length s + length t

b. length (reverse t) = length t

c. reverse (reverse t) = t

theorem Avigad.Chapter7.ex2.length_sum {α : Type u_1} (s : List α) (t : List α) :
theorem Avigad.Chapter7.ex2.length_inject_anywhere {α : Type u_1} (x : α) (as : List α) (bs : List α) :
List.length (as ++ [x] ++ bs) = List.length as + List.length bs + 1

Exercise 3 #

Define an inductive data type consisting of terms built up from the following constructors:

const n, a constant denoting the natural number n

var n, a variable, numbered n

plus s t, denoting the sum of s and t

times s t, denoting the product of s and t

Recursively define a function that evaluates any such term with respect to an assignment of values to the variables.