-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
structural recursion: inductive parameters after varying function parameters? #4671
Comments
I pushed my proposed fix to #4672, which should soon get a mathlib branch, in case someone wants to play around with this. |
Maybe the most liberal approach would be to allow any argument order that we can possibly make sense of:
I don’t quite know if this is flexibility is really needed and worth the implementation and documentation complexity, or if we want our users to order the parameters more logically. |
We are potentially pushing limits in lean unnecessarily. Better documentation or just an error message that we can search for to get to documentation might be all that is needed. |
I don't think that flexibility is really needed: if someone really want to have their variables in a particular order they can always define a simple wrapper around the recursive definition with the correct order. |
Thanks for your feedback! The error message in #4672 is
and maybe it’s actually useable once it also says what makes it bad to depend on Suggestions for elegant concise precise formulations are welcome! |
The previous check, looking only at the type of the parameter, was too permissive and led to ill-typed terms later on. This fixes #4671. In some cases the previous code might have worked by accident, in this sense this is a breaking change. Affected functions can be fixed by reordering their parameters to that all the function parameters that occur in the parameter of the inductive type of the parameter that the function recurses on come first.
from <https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/.E2.9C.94.20Doubly-nested.20inductive/near/451204850> I really like when I can respond to bug report with “will fix in -1 weeks”
from <https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/.E2.9C.94.20Doubly-nested.20inductive/near/451204850> I really like when I can respond to bug report with “will fix in -1 weeks”
from <https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/.E2.9C.94.20Doubly-nested.20inductive/near/451204850> I really like when I can respond to bug report with “will fix in -1 weeks”
The following function is structurally recursive over a data type with an index, and the index depends on function parameters that come after the “fixed prefix”.
This makes lean stumble. This wasn’t easily visible before, because it would then try well-founded recursion, but with
termination_by structural
we can force the error to show up:My first guess was that this is a bug in
hasBadParamDeps?
, confusing the value of the inductive parameter with its type (not unlikely, as the nearbyhasBadIndexDep?
certainly has to consider the index’s type’s dependencies), and within #4575 I tried this fix:This passed our test suite and mathlib, but caused a regression to @tobiasgrosser, as reported in another comment, where the old behavior seems to have worked.
There is a fix/workaround: Reorder the function parameters appropriately so that the inductive’s parameters depend only on a fixed prefix of the function’s parameters. But I am unsure:
The text was updated successfully, but these errors were encountered: