lean4-htt/tests/lean/run/recCommonPrefixAlpha.lean
Joachim Breitner 78146190e5
feat: mutual recursion: allow common prefix up to alpha-equivalence (#5041)
@arthur-adjedj was very confused when a mutually recursive definition
didn't work as expected, and the reason was that he used different names
for the fixed parameters.

It seems plausible to simply allow that and calculate the fixed-prefix
up to alpha renaming.

It does mean, though, that, for example, termination proof goals will
mention the names as used by the first function. But probably better
than simply failing. And we could even fix that later (by passing down
the
actual names, and renmaing the variables in the context of the mvar,
depending on the “current function”) should it bother our users.
2024-08-19 15:00:03 +00:00

34 lines
813 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Structural
mutual
def f1 (α : Type) : List α → Nat
| [] => 0
| _ :: xs => f2 α xs + 1
termination_by structural n => n
-- NB β, not α. Used to prevent this from working (with an unhelpful error message)
def f2 (β : Type) : List β → Nat
| [] => 0
| _ :: xs => f1 β xs + 1
termination_by structural n => n
end
end Structural
namespace WF
mutual
def f1 (α : Type) : List α → Nat
| [] => 0
| _ :: xs => f2 α xs + 1
termination_by n => n
-- NB β, not α. Used to prevent this from working (with an unhelpful error message)
def f2 (β : Type) : List β → Nat
| [] => 0
| _ :: xs => f1 β xs + 1
termination_by n => n
decreasing_by
-- NB: The proof goal for `f2` mentions `α`, not `β`. Could be fixed in theory if we really care
guard_hyp α : Type
decreasing_tactic
end
end WF