lean4-htt/tests/lean/run/issue10431.lean
Joachim Breitner 8655f7706f
refactor: structural recursion: prove .eq_def directly (#10606)
This PR changes how Lean proves the equational theorems for structural
recursion. The core idea is to let-bind the `f` argument to `brecOn` and
rewriting `.brecOn` with an unfolding theorem. This means no extra case
split for the `.rec` in `.brecOn` is needed, and `simp` doesn't change
the `f` argument which can break the definitional equality with the
defined function. With this, we can prove the unfolding theorem first,
and derive the equational theorems from that, like for all other ways of
defining recursive functions.

Backs out the changes from #10415, the old strategy works well with the
new goals.

Fixes #5667
Fixes #10431
Fixes #10195
Fixes #2962
2025-10-07 12:53:09 +00:00

78 lines
1.9 KiB
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.

inductive L (α : Type u) : Type u where
| nil : L α
| cons : α → L α → L α
def L.eq [BEq α] (xs ys : L α) : Bool :=
match _ : xs.ctorIdx == ys.ctorIdx with
| false => false
| true =>
match xs, ys with
| .nil, .nil => true
| .cons x xs, .cons y ys => x == y && xs.eq ys
/--
info: theorem L.eq.eq_def.{u_1} : ∀ {α : Type u_1} [inst : BEq α] (xs ys : L α),
xs.eq ys =
match h : xs.ctorIdx == ys.ctorIdx with
| false => false
| true =>
match xs, ys, h with
| L.nil, L.nil, h => true
| L.cons x xs, L.cons y ys, h => x == y && xs.eq ys
-/
#guard_msgs in
#print sig L.eq.eq_def
-- and mutual
mutual
inductive L1 (α : Type u) : Type u where
| nil : L1 α
| cons : α → L2 α → L1 α
inductive L2 (α : Type u) : Type u where
| nil : L2 α
| cons : α → L1 α → L2 α
end
mutual
def L1.eq [BEq α] (xs ys : L1 α) : Bool :=
match _ : xs.ctorIdx == ys.ctorIdx with
| false => false
| true =>
match xs, ys with
| .nil, .nil => true
| .cons x xs, .cons y ys => x == y && xs.eq ys
def L2.eq [BEq α] (xs ys : L2 α) : Bool :=
match _ : xs.ctorIdx == ys.ctorIdx with
| false => false
| true =>
match xs, ys with
| .nil, .nil => true
| .cons x xs, .cons y ys => x == y && xs.eq ys
end
/--
info: theorem L1.eq.eq_def.{u_1} : ∀ {α : Type u_1} [inst : BEq α] (xs ys : L1 α),
xs.eq ys =
match h : xs.ctorIdx == ys.ctorIdx with
| false => false
| true =>
match xs, ys, h with
| L1.nil, L1.nil, h => true
| L1.cons x xs, L1.cons y ys, h => x == y && xs.eq ys
-/
#guard_msgs in
#print sig L1.eq.eq_def
/--
info: theorem L2.eq.eq_def.{u_1} : ∀ {α : Type u_1} [inst : BEq α] (xs ys : L2 α),
xs.eq ys =
match h : xs.ctorIdx == ys.ctorIdx with
| false => false
| true =>
match xs, ys, h with
| L2.nil, L2.nil, h => true
| L2.cons x xs, L2.cons y ys, h => x == y && xs.eq ys
-/
#guard_msgs in
#print sig L2.eq.eq_def