The `conv` tactic tries to close “trivial” goals after itself. As of now, it uses `try rfl`, which means it can close goals that are only trivial after reducing with default transparency. This is suboptimal * this can require a fair amount of unfolding, and possibly slow down the proof a lot. And the user cannot even prevent it. * it does not match what `rw` does, and a user might expect the two to behave the same. So this PR changes it to `with_reducible rfl`, matching `rw`’s behavior. I considered `with_reducible eq_refl` to only solve trivial goals that involve equality, but not other relations (e.g. `Perm xs xs`), but a discussion on mathlib pointed out that it’s expected and desirable to solve more general reflexive goals: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Closing.20after.20.60rw.60.2C.20.60conv.60.3A.20.60eq_refl.60.20instead.20of.20.60rfl.60/near/429851605
47 lines
1.2 KiB
Text
47 lines
1.2 KiB
Text
inductive ListSplit {α : Type u} : List α → Type u
|
||
| split l₁ l₂ : ListSplit (l₁ ++ l₂)
|
||
|
||
def splitList {α : Type _} : (l : List α) → ListSplit l
|
||
| [] => ListSplit.split [] []
|
||
| h :: t => ListSplit.split [h] t
|
||
|
||
def len : List α → Nat
|
||
| [] => 0
|
||
| a :: [] => 1
|
||
| l =>
|
||
match splitList l with
|
||
| ListSplit.split fst snd => len fst + len snd
|
||
termination_by l => l.length
|
||
decreasing_by
|
||
all_goals sorry
|
||
|
||
theorem len_nil : len ([] : List α) = 0 := by
|
||
simp [len]
|
||
|
||
-- The `simp [len]` above generated the following equation theorems for len
|
||
#check @len.eq_1
|
||
#check @len.eq_2
|
||
#check @len.eq_3 -- It is conditional, and may be tricky to use.
|
||
|
||
theorem len_1 (a : α) : len [a] = 1 := by
|
||
simp [len]
|
||
|
||
theorem len_2 (a b : α) (bs : List α) : len (a::b::bs) = 1 + len (b::bs) := by
|
||
conv => lhs; unfold len
|
||
rfl
|
||
|
||
-- The `unfold` tactic above generated the following theorem
|
||
#check @len.eq_def
|
||
|
||
theorem len_cons (a : α) (as : List α) : len (a::as) = 1 + len as := by
|
||
cases as with
|
||
| nil => simp [len_1, len_nil]
|
||
| cons b bs => simp [len_2]
|
||
|
||
theorem listlen : ∀ l : List α, l.length = len l := by
|
||
intro l
|
||
induction l with
|
||
| nil => rfl
|
||
| cons h t ih =>
|
||
simp [List.length, len_cons, ih]
|
||
rw [Nat.add_comm]
|