3data Binary : Nat -> Set where
5 bO : Binary n -> Binary (n + n)
6 bI : Binary n -> Binary (S (n + n))
8instance Show (Binary n) where
10 show' : Binary n' -> String
11 show' (bO x) = show x ++ "0"
12 show' (bI x) = show x ++ "1"
15data Parity : Nat -> Set where
17 odd : Parity (S (n + n))
19parity : (n:Nat) -> Parity n
21parity (S O) = odd {n=O}
22parity (S (S k)) with (parity k)
23 parity (S (S (j + j))) | even ?= even {n=S j}
24 parity (S (S (S (j + j)))) | odd ?= odd {n=S j}
26natToBin : (n:Nat) -> Binary n
28natToBin (S k) with (parity k)
29 natToBin (S (j + j)) | even = bI (natToBin j)
30 natToBin (S (S (j + j))) | odd ?= bO (natToBin (S j))
34intToNat x = if (x>0) then (S (intToNat (x-1))) else O
37main = do putStr "Enter a number: "
39 print (natToBin (fromInteger (cast x)))
41---------- Proofs ----------
43main.parity_lemma_1 = proof {
45 rewrite sym (plusSuccRightSucc j j);
49natToBin_lemma_1 = proof {
52 rewrite sym (plusSuccRightSucc j j);
56parity_lemma_2 = proof {
59 rewrite sym (plusSuccRightSucc j j);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list