I need to prove termination of mutually recursive functions. However, only some of those functions actually (structurally) decrease their arguments, other functions do some other calculations and pass the value on, unchanged. Here's a distilled example:
mutual
def foo (n: Nat) :=
match n with
| Nat.zero => trivial
| Nat.succ pred => bar pred
def bar (n: Nat): True := foo n
end
This simple example actually compiles, because Lean figures out a workable measure on its own. However, in my actual code, I need to have explicit termination_by
clauses, because some of my recursive functions do need a more complex termination measure that Lean cannot figure out on its own, (and mutually recursive functions are required to all have termination_by
clauses if at least one does). termination_by sizeOf n
does not work, because bar
does not decrease the argument when calling foo
.
Question: How may I prove termination of the above with explicitly defined termination measures?