2014-11-09 06:15:30 +00:00
|
|
|
|
import data.nat.basic data.prod
|
|
|
|
|
open prod
|
|
|
|
|
|
|
|
|
|
namespace nat
|
2014-12-03 18:39:22 +00:00
|
|
|
|
namespace manual
|
2015-02-11 20:49:27 +00:00
|
|
|
|
definition brec_on {C : nat → Type} (n : nat) (F : Π (n : nat), @nat.below C n → C n) : C n :=
|
|
|
|
|
have general : C n × @nat.below C n, from
|
|
|
|
|
nat.rec_on n
|
2015-06-24 21:59:17 +00:00
|
|
|
|
(pair (F zero poly_unit.star) poly_unit.star)
|
2015-02-11 20:49:27 +00:00
|
|
|
|
(λ (n₁ : nat) (r₁ : C n₁ × @nat.below C n₁),
|
|
|
|
|
have b : @nat.below C (succ n₁), from
|
2014-11-09 06:15:30 +00:00
|
|
|
|
r₁,
|
|
|
|
|
have c : C (succ n₁), from
|
|
|
|
|
F (succ n₁) b,
|
|
|
|
|
pair c b),
|
|
|
|
|
pr₁ general
|
2014-12-03 18:39:22 +00:00
|
|
|
|
end manual
|
2014-11-09 06:15:30 +00:00
|
|
|
|
|
|
|
|
|
definition fib (n : nat) :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
nat.brec_on n (λ (n : nat),
|
|
|
|
|
nat.cases_on n
|
2015-10-13 22:39:03 +00:00
|
|
|
|
(λ (b₀ : nat.below 0), succ 0)
|
2015-02-11 20:49:27 +00:00
|
|
|
|
(λ (n₁ : nat), nat.cases_on n₁
|
2015-10-13 22:39:03 +00:00
|
|
|
|
(λ b₁ : nat.below (succ 0), succ zero)
|
2015-02-11 20:49:27 +00:00
|
|
|
|
(λ (n₂ : nat) (b₂ : nat.below (succ (succ n₂))), pr₁ b₂ + pr₁ (pr₂ b₂))))
|
2014-11-09 06:15:30 +00:00
|
|
|
|
|
|
|
|
|
theorem fib_0 : fib 0 = 1 :=
|
|
|
|
|
rfl
|
|
|
|
|
|
|
|
|
|
theorem fib_1 : fib 1 = 1 :=
|
|
|
|
|
rfl
|
|
|
|
|
|
|
|
|
|
theorem fib_s_s (n : nat) : fib (succ (succ n)) = fib (succ n) + fib n :=
|
|
|
|
|
rfl
|
|
|
|
|
|
|
|
|
|
example : fib 5 = 8 :=
|
|
|
|
|
rfl
|
|
|
|
|
|
|
|
|
|
example : fib 9 = 55 :=
|
|
|
|
|
rfl
|
|
|
|
|
end nat
|