pt 1 done

This commit is contained in:
Michael Zhang 2021-10-07 12:27:23 -05:00
parent 7149274cf4
commit 0eec924486
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -29,87 +29,34 @@ fromBin12 = refl
-- to -- to
------------------------------------------------------- -------------------------------------------------------
data Σ (A : Set) (B : A Set) : Set where inc : Bin Bin
⟨_,_⟩ : (x : A) B x Σ A B inc O = O I
inc (w I) = w II
inc (w II) = (inc w) I
: {A : Set} (B : A Set) Set to : Bin
{A} B = Σ A B to 0 = O
to (suc n) with to n
... | O = O I
... | w I = w II
... | w II = (inc w) I
∃-syntax = to2 : to 2 O II
syntax ∃-syntax (λ x B) = ∃[ x ] B to2 = refl
record Terminating (n : ) : Set where to3 : to 3 O I I
inductive to3 = refl
constructor box
field
call : {m : } m < n Terminating m
open Terminating
term : (n : ) Terminating n to4 : to 4 O I II
term 0 .call () to4 = refl
term (suc n) .call ≤′-refl = term n
term (suc n) .call (≤′-step sm≤n) = term n .call sm≤n
data Parity : (n m : ) Set where to5 : to 5 O II I
isEven : {n m : } (m * 2 n) Parity n m to5 = refl
isOdd : {n m : } (1 + m * 2 n) Parity n m
data LooseParity : (n m : ) Set where -------------------------------------------------------
looseEven : {n m : } (m * 2 ≤′ n) LooseParity n m -- from∘to
looseOdd : {n m : } (1 + m * 2 ≤′ n) LooseParity n m -------------------------------------------------------
-- determine the parity of any given from∘to : n from (to n) n
parity? : (n : ) ∃[ m ] Parity n m
parity? zero = zero , isEven refl
parity? (suc n) with parity? n
... | m , isEven p = m , isOdd (cong suc p)
... | m , isOdd {n} p = suc m , isEven {n = suc n} {m = suc m} (trans (+-assoc 1 1 (m * 2)) (cong suc p))
checkParity0 : parity? 0 0 , isEven refl to∘from : b to (from b) b
checkParity0 = refl
checkParity1 : parity? 1 0 , isOdd refl
checkParity1 = refl
checkParity3 : parity? 3 1 , isOdd refl
checkParity3 = refl
checkParity15 : parity? 15 7 , isOdd refl
checkParity15 = refl
checkParity128 : parity? 128 64 , isEven refl
checkParity128 = refl
-- need to show that Parity implies LooseParity
loosen : {n m : } Parity n m LooseParity n m
loosen (isEven refl) = looseEven ≤′-refl
loosen (isOdd refl) = looseOdd ≤′-refl
-- show that LooseParity implies Terminating
postulate
looseTerm : {n m : } LooseParity n m Terminating m
-- looseTerm {n} {m = zero} (looseEven ≤′-refl) .call ()
-- looseTerm {n} {m = suc m₁} (looseEven ≤′-refl) .call p = {! looseTerm {n = n} {m = m₁} (looseEven ≤′-refl) !}
open import Debug.Trace
postulate
makeProofEven : (n m : ) m * 2 n suc m ≤′ suc n
makeProofOdd : (n m : ) suc (m * 2) n suc m ≤′ suc n
to' : (n : ) Terminating n Bin
to' zero _ = O
to' (suc n) (box mWit) with parity? n
-- this means n is odd
... | m , isOdd p = (to' m (mWit (makeProofOdd n m p))) II
-- this means n is even
... | m , isEven p = (to' m (mWit (makeProofEven n m p))) I
to : (n : ) Bin
to n = to' n (term n)
toBin0 : to 0 O
toBin0 = refl
toBin1 : to 3 O I I
toBin1 = refl