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
Structural recursion may fail due to a badly formed motive in a brecOn call
Context
I encountered this issue when trying to formalise a theory of signatures for inductive types.
Steps to Reproduce
MWE:
inductiveTyₛ (l : List Unit): Type
| U : Tyₛ l
open Tyₛ
inductiveVarₚ (d : Unit): List Unit → Type
| vz : Varₚ d [d']
| vs : Varₚ d l → Varₚ d (Bₛ :: l)
inductiveTmₛ {l : List Unit}: Tyₛ l → Unit → Type1
| arr : (T : Type) → Tmₛ A d → Tmₛ A d
| param : Varₚ d l → Tmₛ A d → Tmₛ (@U l) d
defTmₛA {l : List Unit} {d : Unit} {Aₛ : Tyₛ l} (t : Tmₛ Aₛ d): Type :=
match t with
| .arr dom cd =>
let cd := TmₛA cd
dom → cd
| _ => sorry
termination_by structural t
Expected behavior: The function gets accepted.
Actual behavior: The following error pops up:
failed to infer structural recursion:
Cannot use parameter t:
application type mismatch
@Tmₛ.brecOn l fun {d} {Aₛ} t => Type
argument
fun {d} {Aₛ} t => Type
has type
{d : Unit} → {Aₛ : Tyₛ l} → Tmₛ Aₛ d → Type 1 : Type 2
but is expected to have type
(a : Tyₛ l) → (a_1 : Unit) → Tmₛ a a_1 → Type 1 : Type 2
The issue seems to be that the motive generated for the recursive call puts arguments in the wrong order. Changing the order of arguments in the signature of Tmₛ fixes things:
defTmₛA {l : List Unit} {Aₛ : Tyₛ l} {d : Unit} (t : Tmₛ Aₛ d): Type :=
match t with
| .arr dom cd =>
let cd := TmₛA cd
dom → cd
| _ => sorry
termination_by structural t
-- works
Ok, in general there is code there for this kind of reshuffling of arguments, but it seems to be not tested enough. Maybe the tests only had one level of indices or so. I can have a look next week.
This PR fixes a bug where structural recursion did not work when indices
of the recursive argument appeared as function parameters in a different
order than in the argument's type's definition.
Fixes#6015.
This PR fixes a bug where structural recursion did not work when indices
of the recursive argument appeared as function parameters in a different
order than in the argument's type's definition.
Fixes#6015.
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
Structural recursion may fail due to a badly formed motive in a
brecOn
callContext
I encountered this issue when trying to formalise a theory of signatures for inductive types.
Steps to Reproduce
MWE:
Expected behavior: The function gets accepted.
Actual behavior: The following error pops up:
Versions
Lean 4.15.0-nightly-2024-11-08 Target: x86_64-unknown-linux-gnu
Additional Information
The issue seems to be that the motive generated for the recursive call puts arguments in the wrong order. Changing the order of arguments in the signature of
Tmₛ
fixes things: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: