data _≡_ {X : Set} : X → X → Set where
refl : {x : X} → x ≡ x
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
half : ℕ → ℕ
half zero = zero
half (succ zero) = zero
half (succ (succ n)) = succ (half n)
data _<_ : ℕ → ℕ → Set where
base : {n : ℕ} → n < succ n
step : {a b : ℕ} → a < b → a < succ b
lemma-half< : (a : ℕ) → half (succ a) < succ a
lemma-half< a = {!!}
_ : half (succ (succ (succ (succ zero)))) ≡ succ (succ zero)
_ = refl
module Option-1 where
{-# TERMINATING #-}
digits : ℕ → ℕ
digits zero = zero
digits (succ n) = succ (digits (half (succ n)))
lemma-digits : (n : ℕ) → digits (succ n) ≡ succ (digits (half (succ n)))
lemma-digits n = refl
_ : digits (succ (succ (succ (succ zero)))) ≡ succ (succ (succ zero))
_ = refl
_ : digits (succ (succ (succ zero))) ≡ succ (succ zero)
_ = refl
{-# TERMINATING #-}
weird : zero ≡ succ zero
weird = weird
data ⊥ : Set where
{-# TERMINATING #-}
weird' : ⊥
weird' = weird'
module Option-2 where
{-# NON_TERMINATING #-}
digits : ℕ → ℕ
digits zero = zero
digits (succ n) = succ (digits (half (succ n)))
f : (n : ℕ) → digits n ≡ digits n
f n = refl
module Option-3 where
data Bin : Set where
[] : Bin
_O : Bin → Bin
_I : Bin → Bin
decode : Bin → ℕ
decode xs = {!!}
succ' : Bin → Bin
succ' [] = [] I
succ' (xs O) = xs I
succ' (xs I) = (succ' xs) O
encode : ℕ → Bin
encode zero = []
encode (succ n) = succ' (encode n)
length : Bin → ℕ
length [] = zero
length (xs O) = succ (length xs)
length (xs I) = succ (length xs)
digits : ℕ → ℕ
digits n = length (encode n)
_ : digits (succ (succ (succ zero))) ≡ succ (succ zero)
_ = refl
module Option-4 where
digits : ℕ → ℕ
digits n = go n n
where
go : ℕ → ℕ → ℕ
go zero gas = zero
go (succ n) zero = zero
go (succ n) (succ gas) = succ (go (half (succ n)) gas)
_ : digits (succ (succ (succ zero))) ≡ succ (succ zero)
_ = refl
_ : digits (succ (succ (succ (succ zero)))) ≡ succ (succ (succ zero))
_ = refl
lemma-digits : (n : ℕ) → digits (succ n) ≡ succ (digits (half (succ n)))
lemma-digits n = {!!}
module Option-4' where
data Maybe (X : Set) : Set where
nothing : Maybe X
just : X → Maybe X
succ' : Maybe ℕ → Maybe ℕ
succ' nothing = nothing
succ' (just n) = just (succ n)
go : ℕ → ℕ → Maybe ℕ
go zero gas = just zero
go (succ n) zero = nothing
go (succ n) (succ gas) = succ' (go (half (succ n)) gas)
digits : ℕ → Maybe ℕ
digits n = go n n
digits' : ℕ → ℕ
digits' = {!!}
module Option-5 where
data Acc : ℕ → Set where
acc : {x : ℕ} → ((y : ℕ) → y < x → Acc y) → Acc x
lemma-zero-is-accessible : Acc zero
lemma-zero-is-accessible = acc (λ y ())
lemma-one-is-accessible : Acc (succ zero)
lemma-one-is-accessible = acc (λ { zero base → lemma-zero-is-accessible })
lemma-two-is-accessible : Acc (succ (succ zero))
lemma-two-is-accessible = acc (λ { .(succ zero) base → lemma-one-is-accessible ; .zero (step base) → lemma-zero-is-accessible })
theorem-ℕ-well-founded : (n : ℕ) → Acc n
theorem-ℕ-well-founded n = {!!}
go : (n : ℕ) → Acc n → ℕ
go zero gas = zero
go (succ n) (acc f) = succ (go (half (succ n)) (f (half (succ n)) (lemma-half< n)))
digits : ℕ → ℕ
digits n = go n (theorem-ℕ-well-founded n)
lemma-digits : (n : ℕ) → digits (succ n) ≡ succ (digits (half (succ n)))
lemma-digits n = {!!}
data G : ℕ → ℕ → Set where
base : G zero zero
step : {n y : ℕ} → G (half (succ n)) y → G (succ n) (succ y)
lemma-G-is-functional : {a b b' : ℕ} → G a b → G a b' → b ≡ b'
lemma-G-is-functional = {!!}
data Σ (X : Set) (Y : X → Set) : Set where
_,_ : (x : X) → Y x → Σ X Y
lemma-G-is-total : (a : ℕ) → Σ ℕ (G a)
lemma-G-is-total a = {!!} , {!!}
lemma-G-is-computed-by-function : (a : ℕ) → G a (digits a)
lemma-G-is-computed-by-function a = {!!}