{-# OPTIONS --allow-unsolved-metas #-}
data _≡_ {X : Set} : X → X → Set where
refl : {x : X} → x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
data ⊥ : Set where
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-succ-monotonic : {a b : ℕ} → a < b → succ a < succ b
lemma-succ-monotonic p = {!!}
lemma-half< : (a : ℕ) → half (succ a) < succ a
lemma-half< a = {!!}
data _<'_ : ℕ → ℕ → Set where
base : {n : ℕ} → zero <' succ n
step : {a b : ℕ} → a <' b → succ a <' succ b
<→<' : {a b : ℕ} → a < b → a <' b
<→<' = {!!}
<'→< : {a b : ℕ} → a < b → a <' b
<'→< = {!!}
data Bin : Set where
[] : Bin
_O : Bin → Bin
_I : Bin → Bin
double : ℕ → ℕ
double zero = zero
double (succ n) = succ (succ (double n))
decode : Bin → ℕ
decode [] = zero
decode (xs O) = double (decode xs)
decode (xs I) = succ (double (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)
lemma-succ-succ' : (xs : Bin) → decode (succ' xs) ≡ succ (decode xs)
lemma-succ-succ' xs = {!!}
lemma-decode-encode : (n : ℕ) → decode (encode n) ≡ n
lemma-decode-encode n = {!!}
module NaiveGas where
go : ℕ → ℕ → ℕ
go zero gas = zero
go (succ n) zero = zero
go (succ n) (succ gas) = succ (go (half (succ n)) gas)
digits : ℕ → ℕ
digits n = go n n
lemma-digits : (n : ℕ) → digits (succ n) ≡ succ (digits (half (succ n)))
lemma-digits n = {!!}
module WfNat where
data Acc : ℕ → Set where
acc : {x : ℕ} → ((y : ℕ) → y < x → Acc y) → Acc x
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 p q = {!!}
data Σ (X : Set) (Y : X → Set) : Set where
_,_ : (x : X) → Y x → Σ X Y
lemma-G-is-computed-by-digits : (a : ℕ) → G a (digits a)
lemma-G-is-computed-by-digits = {!!}
module WfGen (X : Set) (_<_ : X → X → Set) where
data Acc : X → Set where
acc : {x : X} → ((y : X) → y < x → Acc y) → Acc x
invert : {x : X} → Acc x → ((y : X) → y < x → Acc y)
invert (acc f) = f
lemma-wf-irreflexive : {x : X} → Acc x → x < x → ⊥
lemma-wf-irreflexive = {!!}
lemma-no-descending-sequences : (α : ℕ → X) → ((n : ℕ) → α (succ n) < α n) → Acc (α zero) → ⊥
lemma-no-descending-sequences = {!!}
module _ {A : X → Set} (step : (x : X) → ((y : X) → y < x → A y) → A x) where
go : (x : X) → Acc x → A x
go x (acc f) = step x (λ y p → go y (f y p))
module _ (extensional : (x : X) (u v : (y : X) → y < x → A y) → ((y : X) (p : y < x) → u y p ≡ v y p) → step x u ≡ step x v) where
lemma : (x : X) (p q : Acc x) → go x p ≡ go x q
lemma = {!!}
module _ (wf : (x : X) → Acc x) where
f : (x : X) → A x
f x = go x (wf x)
theorem : (x : X) → f x ≡ step x (λ y p → f y)
theorem = {!!}