Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add String.length_join and List.length_join #770

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Std/Data/List/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ theorem exists_of_mem_join : a ∈ join L → ∃ l, l ∈ L ∧ a ∈ l := mem_

theorem mem_join_of_mem (lL : l ∈ L) (al : a ∈ l) : a ∈ join L := mem_join.2 ⟨l, lL, al⟩

theorem length_join (l : List (List α)) : (join l).length = Nat.sum (l.map length) := by
induction l <;> simp [*]
tjf801 marked this conversation as resolved.
Show resolved Hide resolved

/-! ### bind -/

theorem mem_bind {f : α → List β} {b} {l : List α} : b ∈ l.bind f ↔ ∃ a, a ∈ l ∧ b ∈ f a := by
Expand Down
5 changes: 5 additions & 0 deletions Std/Data/String/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ theorem join_eq (ss : List String) : join ss = ⟨(ss.map data).join⟩ := go ss
@[simp] theorem data_join (ss : List String) : (join ss).data = (ss.map data).join := by
rw [join_eq]

@[simp] theorem length_data (s : String) : s.data.length = s.length := rfl

theorem length_join (l : List String) : (join l).length = Nat.sum (l.map length) := by
simp [length, List.length_join, List.map_map, (funext length_data : List.length ∘ data = length)]

theorem singleton_eq (c : Char) : singleton c = ⟨[c]⟩ := rfl

@[simp] theorem data_singleton (c : Char) : (singleton c).data = [c] := rfl
Expand Down