You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now if the user writes a recursive function without annotation, Lean tries
structural recursion on each argument
well-founded recursion with GuessLex
If the user wants to be explicit about well-founded recursion, they can use termination_by x. But they have no way of indicating that they want to use structural recursion on a specific argument.
Right now the above search procedure is not slow, so the need isn’t high, but once we have structural recursion on mutually recursive functions, the first step might consider many combinations, and it would be good if the user can just declare their intent.
Furthermore, if the user can be specific, they get a less noisy error message when the derecursifying fails.
Initial proposal for the syntax is
termination_by structurally x -- if x is bound before the colon
termination_by structurally x => x -- if x is bound after the colon
in analogy to the existing termination_by. This way, no new “definition trailing keyword” is introduced.
It can also be extended to more variants in the future, such as termination_by tail-recursion (which isn’t really “termination”, sigh.)
Once we have this, then termination_by? should not force well-founded recursion and should, if lean detects structural recursion, suggest the corresponding termination_by structurally … annotation.
Community Feedback
(none yet)
Impact
Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.
Reacted by Arthur Adjedj, Bhavik Mehta, James Sully and Jozef Mikušinec
I think it should be styled closer to options in tactic syntax, e.g. termination_by (method := structural). This also gives a bit more freedom to tweak the syntax without clashing with either the expr or ident parser.
I can't comment on the implementation here, but the proposal is something I would absolutely find valuable. Can we, however, make sure that the expected behaviour is documented somewhere?
Yes, of course! I hope that by the end of the year there will be an amazing reference manual that’s a joy to keep updated as I add features. Until then we are a bit in a limbo. But that’s for the reminder to at least keep the docstring on termination_by up-to-date (docstring extended in c3398e3).
Activity
nomeata commentedon Apr 15, 2024
I am happy to hear alternative syntax ideas; the
termination_by structurally xsuggested above is somewhat clunky.digama0 commentedon Apr 15, 2024
I think it should be styled closer to options in tactic syntax, e.g.
termination_by (method := structural). This also gives a bit more freedom to tweak the syntax without clashing with either the expr or ident parser.b-mehta commentedon Jun 26, 2024
I can't comment on the implementation here, but the proposal is something I would absolutely find valuable. Can we, however, make sure that the expected behaviour is documented somewhere?
nomeata commentedon Jun 26, 2024
Yes, of course! I hope that by the end of the year there will be an amazing reference manual that’s a joy to keep updated as I add features. Until then we are a bit in a limbo. But that’s for the reminder to at least keep the docstring on
termination_byup-to-date (docstring extended in c3398e3).feat: termination_by structural (#4542)