2014-12-11 06:25:40 +00:00
|
|
|
import data.vector
|
|
|
|
open nat vector
|
|
|
|
|
2014-12-12 01:32:39 +00:00
|
|
|
definition fib : nat → nat,
|
|
|
|
fib 0 := 1,
|
|
|
|
fib 1 := 1,
|
|
|
|
fib (a+2) := (fib a ↓ lt.step (lt.base a)) + (fib (a+1) ↓ lt.base (a+1))
|
|
|
|
[wf] lt.wf
|
|
|
|
|
|
|
|
definition gcd : nat → nat → nat,
|
|
|
|
gcd 0 x := x,
|
|
|
|
gcd x 0 := x,
|
|
|
|
gcd (succ x) (succ y) := if y ≤ x
|
|
|
|
then gcd (x - y) (succ y) ↓ !sigma.lex.left (lt_succ_of_le (sub_le x y))
|
|
|
|
else gcd (succ x) (y - x) ↓ !sigma.lex.right (lt_succ_of_le (sub_le y x))
|
|
|
|
[wf] sigma.lex.wf lt.wf (λ x, lt.wf)
|
2014-12-11 06:25:40 +00:00
|
|
|
|
|
|
|
definition add : nat → nat → nat,
|
|
|
|
add zero b := b,
|
|
|
|
add (succ a) b := succ (add a b)
|
|
|
|
|
|
|
|
definition map {A B C : Type} (f : A → B → C) : Π {n}, vector A n → vector B n → vector C n,
|
|
|
|
map nil nil := nil,
|
|
|
|
map (a :: va) (b :: vb) := f a b :: map va vb
|
|
|
|
|
|
|
|
|
|
|
|
definition half : nat → nat,
|
|
|
|
half 0 := 0,
|
|
|
|
half 1 := 0,
|
|
|
|
half (x+2) := half x + 1
|
|
|
|
|
|
|
|
variables {A B : Type}
|
|
|
|
inductive image_of (f : A → B) : B → Type :=
|
|
|
|
mk : Π a, image_of f (f a)
|
|
|
|
|
|
|
|
definition inv {f : A → B} : Π b, image_of f b → A,
|
|
|
|
inv ⌞f a⌟ (image_of.mk f a) := a
|