mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-11-15 01:25:05 +03:00
17c7240825
+ Tutorial is now developed in a separate github repo. + Moved examples to top-level + Added binary of tutorial for v0.9.10
38 lines
749 B
Idris
38 lines
749 B
Idris
module views
|
|
|
|
data Parity : Nat -> Type where
|
|
even : Parity (n + n)
|
|
odd : Parity (S (n + n))
|
|
|
|
parity : (n:Nat) -> Parity n
|
|
parity Z = even {n=Z}
|
|
parity (S Z) = odd {n=Z}
|
|
parity (S (S k)) with (parity k)
|
|
parity (S (S (j + j))) | even ?= even {n=S j}
|
|
parity (S (S (S (j + j)))) | odd ?= odd {n=S j}
|
|
|
|
natToBin : Nat -> List Bool
|
|
natToBin Z = Nil
|
|
natToBin k with (parity k)
|
|
natToBin (j + j) | even = False :: natToBin j
|
|
natToBin (S (j + j)) | odd = True :: natToBin j
|
|
|
|
|
|
---------- Proofs ----------
|
|
|
|
views.parity_lemma_2 = proof {
|
|
intro;
|
|
intro;
|
|
rewrite sym (plusSuccRightSucc j j);
|
|
trivial;
|
|
}
|
|
|
|
views.parity_lemma_1 = proof {
|
|
intro;
|
|
intro;
|
|
rewrite sym (plusSuccRightSucc j j);
|
|
trivial;
|
|
}
|
|
|
|
|