{-# OPTIONS --allow-unsolved-metas #-}
open import Padova2024.EquationalReasoning
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
data _<_ : ℕ → ℕ → Set where
base : {n : ℕ} → n < succ n
step : {a b : ℕ} → a < b → a < succ b
_+_ : ℕ → ℕ → ℕ
zero + b = b
succ a + b = succ (a + b)
half : ℕ → ℕ
half zero = zero
half (succ zero) = zero
half (succ (succ n)) = succ (half n)
_ : half (succ (succ (succ zero))) ≡ succ zero
_ = refl
lemma-half< : (a : ℕ) → half (succ a) < succ a
lemma-half< a = {!!}
module Option-1 where
{-# TERMINATING #-}
digits : ℕ → ℕ
digits zero = zero
digits (succ n) = succ (digits (half (succ n)))
{-# TERMINATING #-}
loop : ℕ → ℕ
loop n = loop (succ n)
module Option-2 where
{-# NON_TERMINATING #-}
digits : ℕ → ℕ
digits zero = zero
digits (succ n) = succ (digits (half (succ n)))
new-lemma : (n : ℕ) → digits (succ n) ≡ succ (digits (half (succ n)))
new-lemma n = {!!}
module Option-3 where
module Option-4 where
digits : ℕ → ℕ
digits n = go (n + n) n
where
go : ℕ → ℕ → ℕ
go zero n = zero
go (succ gas) zero = zero
go (succ gas) (succ n) = succ (go gas (half (succ n)))
lemma : (n : ℕ) → digits (succ n) ≡ succ (digits (half (succ n)))
lemma n = {!!}
module Option-5 where
data Acc : ℕ → Set where
acc : {n : ℕ} → (f : (m : ℕ) → (m<n : m < n) → Acc m) → Acc n
lemma-zero-is-accessible : Acc zero
lemma-zero-is-accessible = acc (λ { m () })
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
}
ℕ-wellfounded : (n : ℕ) → Acc n
ℕ-wellfounded n = {!!}
go : (n : ℕ) → Acc n → ℕ
go zero p = zero
go (succ n) (acc f) = succ (go (half (succ n)) (f (half (succ n)) (lemma-half< n)))
digits : ℕ → ℕ
digits n = go n (ℕ-wellfounded n)
lemma-go-extensional : (n : ℕ) (p q : Acc n) → go n p ≡ go n q
lemma-go-extensional zero p q = refl
lemma-go-extensional (succ n) (acc f) (acc g) = cong succ (lemma-go-extensional (half (succ n)) _ _)
lemma : (n : ℕ) → digits (succ n) ≡ succ (digits (half (succ n)))
lemma n = begin
digits (succ n) ≡⟨⟩
go (succ n) (ℕ-wellfounded (succ n)) ≡⟨⟩
succ (go (half (succ n)) _) ≡⟨ cong succ (lemma-go-extensional (half (succ n)) _ _) ⟩
succ (go (half (succ n)) (ℕ-wellfounded (half (succ n)))) ≡⟨⟩
succ (digits (half (succ n))) ∎