This improves Lean’s capabilities to guess the termination measure for
well-founded
recursion, by also trying lexicographic orders. For example:
def ackermann (n m : Nat) := match n, m with
| 0, m => m + 1
| .succ n, 0 => ackermann n 1
| .succ n, .succ m => ackermann n (ackermann (n + 1) m)
now just works.
The module docstring of `Lean.Elab.PreDefinition.WF.GuessLex` tells the
technical story.
Fixes #2837
23 lines
534 B
Text
23 lines
534 B
Text
/-!
|
|
Another “tricky” example from “Finding Lexicographic Orders for Termination Proofs in
|
|
Isabelle/HOL” by Lukas Bulwahn, Alexander Krauss, and Tobias Nipkow,
|
|
10.1007/978-3-540-74591-4_5.
|
|
|
|
Works out of the box!
|
|
-/
|
|
|
|
mutual
|
|
def pedal : Nat → Nat → Nat → Nat
|
|
| 0, _m, c => c
|
|
| _n, 0, c => c
|
|
| n+1, m+1, c =>
|
|
if n < m
|
|
then coast n m (c + m + 1)
|
|
else pedal n (m + 1) (c + m + 1)
|
|
|
|
def coast : Nat → Nat → Nat → Nat
|
|
| n, m , c =>
|
|
if n < m
|
|
then coast n (m - 1) (c + n)
|
|
else pedal n m (c + n)
|
|
end
|