-
Notifications
You must be signed in to change notification settings - Fork 418
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 fails when matching on f x
where f
is argument’s subterm
#5836
Comments
I briefly investigated, and it seems that this is out of reach with the current architecture. The problem is at
If we’d But matching on For this to work I could imagine a different approach: Instead of passing down one Unfortunately this would make the FunInd transformation a bit more complicated, with multiple “below values” to rewrite. There exists a work-around: mutual
def Foo.bar (m : Foo → Foo) : Foo → Foo
| .foo f => .foo fun s => Foo.bar_aux m (f s)
termination_by structural x => x
def Foo.bar_aux (m : Foo → Foo) : Option Foo → Option Foo
| none => none
| some x => bar m x
termination_by structural x => x
end So since it’s hard to fix, and there is a work-around, I’m demoting this to low, until someone makes a point that I am underestimating the severity. |
Oh, and it’s not actually related to nested or mutual inductive: inductive Foo where
| none
| foo : (String → Foo) → Foo
/--
error: failed to infer structural recursion:
Cannot use parameter #2:
failed to eliminate recursive application
map m (f₂ s)
-/
#guard_msgs in
def Foo.map (m : Foo → Foo) : Foo → Foo
| none => none
| .foo f => .foo fun s => match f s with
| none => none
| foo f₂ => .foo fun s => map m (f₂ s)
termination_by structural x => x |
f x
where f
is argument’s subterm
There is also a comment in the code about this not working, which would work with the alternative implementation above: def g (xs : List Nat) : Nat :=
match xs with
| [] => 0
| y::ys =>
match ys with
| [] => 1
| _::_::zs => g zs + 1
| zs => g ys + 2 I know I demoted it to low, but it’s weekend, and it’s itching under my fingernails, so maybe I’ll give it a shot. |
see #5836, but I hit a roadblock (see comment in code)
Hmm, I hit a roadblock in that search in in |
Prerequisites
Please put an X between the brackets as you perform the following steps:
https://github.com/leanprover/lean4/issues
Avoid dependencies to Mathlib or Batteries.
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
Mutual/Nested structural recursion seems to fail on large inductive types.
Consider the following example:
Despite structural recursion being supported on both large inductive types and nested inductives, mixing the two leads to a failure. In a similar manner, the following function recursing over a large mutual inductive fails with the same error:
Expected behavior: No error, these functions get accepted
Actual behavior: Structural recursion fails with the following error:
Versions
Lean 4.12.0-nightly-2024-10-24
Target: x86_64-unknown-linux-gnu
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: