lean4-htt/tests/lean/run/splitIssue.lean
Leonardo de Moura 22b5c957e9
chore: rename automatically generated "unfold" theorems (#3767)
Given a definition `foo`, they were previously called `foo._unfold`
until 4.7.0. We tried to rename them to `foo.def`, but it created too
many issues in the Mathlib repo. We decided to rename it again to
`foo.eq_def`. The new name is also consistent with the `eq_<idx>`
theorems generated for different "cases". That is, `foo.eq_def` is the
equality theorem for the whole definition, and `foo.eq_<idx>` is the
equality theorem for case `<idx>`.

cc @semorrison
2024-03-25 21:41:26 +00:00

46 lines
1.2 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 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
-- 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]