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 #779

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions Std/Data/List/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

@digama0 digama0 May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a cross cutting import, and also not a precise import. The needed theorem(s) should move to Std.Data.Nat.Init.Lemmas and that should be imported here. If you only need the definition then it can just be an import of Std.Data.Nat.Basic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to move the needed lemmas up into an Init folder, to reduce the imports needed here?

import Std.Tactic.Init
import Std.Tactic.Alias

Expand Down Expand Up @@ -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
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 @@ -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
Expand Down