The Setting
I'm trying to use Agda's well-founded ordering to prove that something is terminating using Brouwer Trees i.e.
data Ord where
zero : Ord
succ : Ord -> Ord
limit : (Nat -> Ord) -> Ord
We can define a well-founded ordering like so:
data _≤_ where
≤-zero : ∀ {x} → zero ≤ x
≤-succ-mono : ∀ {x y} → x ≤ y → succ x ≤ succ y
≤-cocone : ∀ {x} f { k} → (x ≤ f k) → (x ≤ limit f )
≤-limiting : ∀ f {x} → ((k : ℕ) → f k ≤ x) → limit f ≤ x
And then define x < y
to be succ x ≤ y
.
The Problem
The issue is that I'm trying to show termination for mutually recursive functions. One has one argument, but the other has two arguments, and is "symmetric" i.e. there isn't one "dominant" argument that is decreasing. So I can't use a lexicographic ordering. The 2-arg function sometimes calls the 1-arg function when one of arguments is size 1, and the 1-arg function sometimes calls the 2-arg function with two arguments strictly smaller than its argument.
What I'm really trying to show is that the "maximum" of the two sizes is decreasing. We can define:
max x y = limit (\ n -> if n == 0 then x else y)
which does in fact compute a least upper bound on x
and y
for ≤
.
But, this function is not strictly monotone, i.e., there's no way to conclude that max a b < max c d
from a < c
and b < d
. And we need it to be strictly monotone to show that recursive calls are being made with the arguments strictly decreasing.
The reason we can't show this is that there's no way to show that succ (lim f) ≤ lim (\n -> succ (f n))
.
My question
Is there some kind of well-founded relation that avoids this issue?
- Can the definition of
<
and≤
be altered while keeping it well-founded, without having to reach to things like HITs? - Is there a different function that can be used instead of
max
? For example, I can imagine showing that the sum of the two ordinals is decreasing. But (I think) you run into the same issues with showing that+
is strictly monotone. - Is there different notion of ordinal, or some other well-founded relation, that doesn't suffer from this issue for
max
?
f 0 = zero; f (n+1) = succ (f n)
thenlim (λn. succ (f n))
is equal (isomorphic? idk) tolim f
(i.e. ω), which is strictly smaller thansucc (lim f)
, so ifsucc (lim f) ≤ lim (λn. succ (f n))
is where you ended up naturally, and that's refutable, maybe yourmax
is wrong? Or maybe any definition ofmax
just isn't monotone?? Better ask a set theorist $\endgroup$