inductive even : nat → Type
| ev0 : even 0
| ev2 : ∀ n, even n → even (n + 2)
open even
#check @even.rec
theorem even_add : ∀ n m, even n → even m → even (n + m)
| _ 0 pf (ev0) := pf
| n (m' + 2) pf (ev2 _ pf') :=
-- pf : even n
-- Goal: even (n + m' + 2)
ev2 _ (even_add n m' pf pf')
def t2 : (Σ n : nat, even n) := sigma.mk 0 ev0
-- even.rec :
-- Π {C : Π (a : ℕ), even a → Sort u_1},
-- C 0 ev0 →
-- (∀ n a , C n a → C (n + 2) (ev2 n a))
-- → ∀ n p, C n p
#check (ev2 _ (ev2 _ (ev2 _ (ev0))))
-- Tree are binary search tree
inductive tree : Type
| leaf : nat → tree
| branch : tree → tree → tree
open tree
def t1 := branch (branch (leaf 2) (leaf 3)) (leaf 5)
inductive bst' : nat → nat → Type
| leaf : ∀ n, bst' n n
| branch :
∀ {a b c d},
bst' a b →
bst' c d →
b ≤ c →
bst' a d
def t3 := bst'.branch
(bst'.branch
(bst'.leaf 2)
(bst'.leaf 3) (dec_trivial))
(bst'.leaf 5)
(dec_trivial)
lemma p1 : bst' t1 2 5 :=
let pf1a := bst'.leaf 2 in
let pf1b := bst'.leaf 3 in
let pf1 := bst'.branch pf1a pf1b (dec_trivial) in
let pf2 := bst'.leaf 5 in
bst'.branch pf1 pf2 (dec_trivial)
def bst : tree → Type := λ t, Σ a b, bst' t a b
-- Exercise: has_length
inductive has_length : list nat → nat → Type
| oliver : has_length [] 0
| calvin :
∀ {a l n},
has_length l n →
has_length (a :: l) (n + 1)
def length : list nat → nat
| [] := 0
| (a :: l) := (length l) + 1
inductive list' : nat → Type
| nil : list' 0
| cons : ∀ n, nat → list' n → list' (n + 1)