2015-03-09 15:42:21 +00:00
|
|
|
import data.nat
|
2015-10-14 19:27:09 +00:00
|
|
|
open nat algebra
|
2015-03-09 15:42:21 +00:00
|
|
|
|
2015-07-06 22:05:01 +00:00
|
|
|
namespace foo
|
|
|
|
|
2015-03-09 15:42:21 +00:00
|
|
|
inductive Parity : nat → Type :=
|
|
|
|
| even : ∀ n : nat, Parity (2 * n)
|
|
|
|
| odd : ∀ n : nat, Parity (2 * n + 1)
|
|
|
|
|
|
|
|
open Parity
|
|
|
|
|
|
|
|
definition parity : Π (n : nat), Parity n
|
|
|
|
| parity 0 := even 0
|
|
|
|
| parity (n+1) :=
|
|
|
|
begin
|
|
|
|
have aux : Parity n, from parity n,
|
2015-03-28 00:26:06 +00:00
|
|
|
cases aux with [k, k],
|
2015-03-09 15:42:21 +00:00
|
|
|
begin
|
2015-07-06 22:05:01 +00:00
|
|
|
apply (Parity.odd k)
|
2015-03-09 15:42:21 +00:00
|
|
|
end,
|
|
|
|
begin
|
|
|
|
change (Parity (2*k + 2*1)),
|
2015-10-14 19:27:09 +00:00
|
|
|
rewrite -left_distrib,
|
2015-07-06 22:05:01 +00:00
|
|
|
apply (Parity.even (k+1))
|
2015-03-09 15:42:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print definition parity
|
|
|
|
|
|
|
|
definition half (n : nat) : nat :=
|
|
|
|
match ⟨n, parity n⟩ with
|
|
|
|
| ⟨⌞2 * k⌟, even k⟩ := k
|
|
|
|
| ⟨⌞2 * k + 1⌟, odd k⟩ := k
|
|
|
|
end
|
2015-07-06 22:05:01 +00:00
|
|
|
|
|
|
|
end foo
|