Zulip Chat Archive

Stream: lean4

Topic: A `termination_by` puzzle


François G. Dorais (Apr 05 2023 at 03:36):

Why doesn't fooSS work? Obviously it's because of termination_by but I don't understand exactly why. How does termination_by change the inductive definition?

def foo : Nat  Nat  Nat
| 0, 0 => 0
| 0, n+1 => foo 0 n
| m+1, n => foo m n
termination_by foo m n => m + n

theorem foo00 : foo 0 0 = 0 := rfl -- works

theorem foo0S : foo 0 (n+1) = foo 0 n := rfl -- works

theorem fooS0 : foo (m+1) 0 = foo m 0 := rfl -- works

theorem fooSS : foo (m+1) (n+1) = foo m (n+1) := rfl -- fails!?

François G. Dorais (Apr 05 2023 at 03:48):

PS: To avoid confusion, foo is identically zero, so fooSS is definitely true.

Mario Carneiro (Apr 05 2023 at 04:43):

by rw [foo] works

Mario Carneiro (Apr 05 2023 at 04:44):

the answer to your question is that when you use termination_by it uses well-founded recursion instead of structural recursion to define the function, and WF definitions generally don't have many definitional equalities, you have to use the defining equations directly

François G. Dorais (Apr 05 2023 at 15:30):

Thanks Mario. I've figured out that I can access what I wanted to know using the option trace.Elab.definition.wf (the wf is what I couldn't figure out before Mario's hint).

František Silváši 🦉 (Jul 29 2023 at 09:37):

[deleted]


Last updated: Dec 20 2023 at 11:08 UTC