diff --git a/Std/Data/List/Lemmas.lean b/Std/Data/List/Lemmas.lean index 45a56ba558..47302b7cc1 100644 --- a/Std/Data/List/Lemmas.lean +++ b/Std/Data/List/Lemmas.lean @@ -5,6 +5,7 @@ Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, M -/ import Std.Control.ForInStep.Lemmas import Std.Data.List.Basic +import Std.Data.Nat.Lemmas import Std.Tactic.Init import Std.Tactic.Alias @@ -365,6 +366,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 [*] + /-! ### bind -/ theorem mem_bind {f : α → List β} {b} {l : List α} : b ∈ l.bind f ↔ ∃ a, a ∈ l ∧ b ∈ f a := by diff --git a/Std/Data/String/Lemmas.lean b/Std/Data/String/Lemmas.lean index 28f9c76ad4..a3eb3ff513 100644 --- a/Std/Data/String/Lemmas.lean +++ b/Std/Data/String/Lemmas.lean @@ -516,6 +516,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