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
9 show (bO x) = show x ++ "0"
10 show (bI x) = show x ++ "1"
13data Parity : Nat -> Set where
15 odd : Parity (S (n + n))
17parity : (n:Nat) -> Parity n
19parity (S O) = odd {n=O}
20parity (S (S k)) with (parity k)
21 parity (S (S (j + j))) | even ?= even {n=S j}
22 parity (S (S (S (j + j)))) | odd ?= odd {n=S j}
24natToBin : (n:Nat) -> Binary n
26natToBin (S k) with (parity k)
27 natToBin (S (j + j)) | even = bI (natToBin j)
28 natToBin (S (S (j + j))) | odd ?= bO (natToBin (S j))
32intToNat x = if (x>0) then (S (intToNat (x-1))) else O
35main = do putStr "Enter a number: "
37 print (natToBin (fromInteger (cast x)))
39---------- Proofs ----------
41natToBin_lemma_1 = proof {
44 rewrite sym (plusSuccRightSucc j j);
48parity_lemma_2 = proof {
51 rewrite sym (plusSuccRightSucc j j);
55parity_lemma_1 = proof {
58 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