@@ -3,7 +3,7 @@ Copyright (c) 2017 Mario Carneiro. All rights reserved.
33Released under Apache 2.0 license as described in the file LICENSE.
44Authors: Sébastien Gouëzel, Floris van Doorn, Mario Carneiro, Martin Dvorak
55-/
6- import Mathlib.Algebra.BigOperators .List.Basic
6+ import Mathlib.Data .List.Basic
77
88#align_import data.list.join from "leanprover-community/mathlib" @"18a5306c091183ac90884daa9373fa3b178e8607"
99
@@ -14,6 +14,8 @@ This file proves basic properties of `List.join`, which concatenates a list of l
1414in `Init.Data.List.Basic`.
1515-/
1616
17+ -- Make sure we don't import algebra
18+ assert_not_exists Monoid
1719
1820variable {α β : Type *}
1921
@@ -64,31 +66,31 @@ theorem join_join (l : List (List (List α))) : l.join.join = (l.map join).join
6466 induction l <;> simp [*]
6567#align list.join_join List.join_join
6668
67- @[simp]
68- theorem length_join (L : List (List α)) : length (join L) = sum (map length L) := by
69- induction L <;> [rfl; simp only [*, join, map, sum_cons, length_append]]
70- #align list.length_join List.length_join
69+ /-- See `List.length_join` for the corresponding statement using `List.sum`. -/
70+ lemma length_join' (L : List (List α)) : length (join L) = Nat.sum (map length L) := by
71+ induction L <;> [rfl; simp only [*, join, map, Nat.sum_cons, length_append]]
7172
72- lemma countP_join (p : α → Bool) : ∀ L : List (List α), countP p L.join = (L.map (countP p)).sum
73+ /-- See `List.countP_join` for the corresponding statement using `List.sum`. -/
74+ lemma countP_join' (p : α → Bool) :
75+ ∀ L : List (List α), countP p L.join = Nat.sum (L.map (countP p))
7376 | [] => rfl
74- | a :: l => by rw [join, countP_append, map_cons, sum_cons, countP_join _ l]
75- #align list.countp_join List.countP_join
77+ | a :: l => by rw [join, countP_append, map_cons, Nat.sum_cons, countP_join' _ l]
7678
77- lemma count_join [BEq α] (L : List (List α)) (a : α) : L.join.count a = (L.map (count a)).sum :=
78- countP_join _ _
79- #align list.count_join List.count_join
79+ /-- See ` List.count_join` for the corresponding statement using `List.sum`. -/
80+ lemma count_join' [BEq α] (L : List (List α)) (a : α) :
81+ L.join.count a = Nat.sum (L.map (count a)) := countP_join' _ _
8082
81- @[simp]
82- theorem length_bind (l : List α) (f : α → List β) :
83- length (List.bind l f) = sum (map (length ∘ f) l) := by rw [List.bind, length_join, map_map]
84- #align list.length_bind List.length_bind
83+ /-- See `List.length_bind` for the corresponding statement using `List.sum`. -/
84+ lemma length_bind' (l : List α) (f : α → List β) :
85+ length (l.bind f) = Nat.sum (map (length ∘ f) l) := by rw [List.bind, length_join', map_map]
8586
86- lemma countP_bind (p : β → Bool) (l : List α) (f : α → List β) :
87- countP p (l.bind f) = sum (map (countP p ∘ f) l) := by rw [List.bind, countP_join, map_map]
87+ /-- See `List.countP_bind` for the corresponding statement using `List.sum`. -/
88+ lemma countP_bind' (p : β → Bool) (l : List α) (f : α → List β) :
89+ countP p (l.bind f) = Nat.sum (map (countP p ∘ f) l) := by rw [List.bind, countP_join', map_map]
8890
89- lemma count_bind [BEq β] (l : List α) (f : α → List β) (x : β) :
90- count x (l.bind f) = sum (map (count x ∘ f) l) := countP_bind _ _ _
91- #align list.count_bind List.count_bind
91+ /-- See ` List.count_bind` for the corresponding statement using ` List.sum`. -/
92+ lemma count_bind' [BEq β] (l : List α) (f : α → List β) (x : β) :
93+ count x (l.bind f) = Nat.sum (map (count x ∘ f) l) := countP_bind' _ _ _
9294
9395@[simp]
9496theorem bind_eq_nil {l : List α} {f : α → List β} : List.bind l f = [] ↔ ∀ x ∈ l, f x = [] :=
@@ -97,22 +99,24 @@ theorem bind_eq_nil {l : List α} {f : α → List β} : List.bind l f = [] ↔
9799#align list.bind_eq_nil List.bind_eq_nil
98100
99101/-- In a join, taking the first elements up to an index which is the sum of the lengths of the
100- first `i` sublists, is the same as taking the join of the first `i` sublists. -/
101- theorem take_sum_join (L : List (List α)) (i : ℕ) :
102- L.join.take ((L.map length).take i).sum = (L.take i).join := by
102+ first `i` sublists, is the same as taking the join of the first `i` sublists.
103+
104+ See `List.take_sum_join` for the corresponding statement using `List.sum`. -/
105+ theorem take_sum_join' (L : List (List α)) (i : ℕ) :
106+ L.join.take (Nat.sum ((L.map length).take i)) = (L.take i).join := by
103107 induction L generalizing i
104108 · simp
105109 · cases i <;> simp [take_append, *]
106- #align list.take_sum_join List.take_sum_join
107110
108111/-- In a join, dropping all the elements up to an index which is the sum of the lengths of the
109- first `i` sublists, is the same as taking the join after dropping the first `i` sublists. -/
110- theorem drop_sum_join (L : List (List α)) (i : ℕ) :
111- L.join.drop ((L.map length).take i).sum = (L.drop i).join := by
112+ first `i` sublists, is the same as taking the join after dropping the first `i` sublists.
113+
114+ See `List.drop_sum_join` for the corresponding statement using `List.sum`. -/
115+ theorem drop_sum_join' (L : List (List α)) (i : ℕ) :
116+ L.join.drop (Nat.sum ((L.map length).take i)) = (L.drop i).join := by
112117 induction L generalizing i
113118 · simp
114119 · cases i <;> simp [drop_append, *]
115- #align list.drop_sum_join List.drop_sum_join
116120
117121/-- Taking only the first `i+1` elements in a list, and then dropping the first `i` ones, one is
118122left with a list of length `1` made of the `i`-th element of the original list. -/
@@ -145,36 +149,19 @@ theorem drop_take_succ_eq_cons_nthLe (L : List α) {i : ℕ} (hi : i < L.length)
145149
146150/-- In a join of sublists, taking the slice between the indices `A` and `B - 1` gives back the
147151original sublist of index `i` if `A` is the sum of the lengths of sublists of index `< i`, and
148- `B` is the sum of the lengths of sublists of index `≤ i`. -/
149- theorem drop_take_succ_join_eq_get (L : List (List α)) (i : Fin L.length) :
150- (L.join.take ((L.map length).take (i + 1 )).sum).drop ((L.map length).take i).sum =
152+ `B` is the sum of the lengths of sublists of index `≤ i`.
153+
154+ See `List.drop_take_succ_join_eq_get` for the corresponding statement using `List.sum`. -/
155+ theorem drop_take_succ_join_eq_get' (L : List (List α)) (i : Fin L.length) :
156+ (L.join.take (Nat.sum ((L.map length).take (i + 1 )))).drop (Nat.sum ((L.map length).take i)) =
151157 get L i := by
152158 have : (L.map length).take i = ((L.take (i + 1 )).map length).take i := by
153- simp [map_take, take_take]
154- simp only [this, length_map, take_sum_join, drop_sum_join, drop_take_succ_eq_cons_get,
159+ simp [map_take, take_take, Nat.min_eq_left ]
160+ simp only [this, length_map, take_sum_join' , drop_sum_join' , drop_take_succ_eq_cons_get,
155161 join, append_nil]
156162
157- set_option linter.deprecated false in
158- /-- In a join of sublists, taking the slice between the indices `A` and `B - 1` gives back the
159- original sublist of index `i` if `A` is the sum of the lengths of sublists of index `< i`, and
160- `B` is the sum of the lengths of sublists of index `≤ i`. -/
161- @ [deprecated drop_take_succ_join_eq_get]
162- theorem drop_take_succ_join_eq_nthLe (L : List (List α)) {i : ℕ} (hi : i < L.length) :
163- (L.join.take ((L.map length).take (i + 1 )).sum).drop ((L.map length).take i).sum =
164- nthLe L i hi := by
165- have : (L.map length).take i = ((L.take (i + 1 )).map length).take i := by
166- simp [map_take, take_take]
167- simp [take_sum_join, this, drop_sum_join, drop_take_succ_eq_cons_nthLe _ hi]
168- #align list.drop_take_succ_join_eq_nth_le List.drop_take_succ_join_eq_nthLe
169-
170- /-- Auxiliary lemma to control elements in a join. -/
171- @[deprecated]
172- theorem sum_take_map_length_lt1 (L : List (List α)) {i j : ℕ} (hi : i < L.length)
173- (hj : j < (L.get ⟨i, hi⟩).length) :
174- ((L.map length).take i).sum + j < ((L.map length).take (i + 1 )).sum := by
175- simp [hi, sum_take_succ, hj]
176- #align list.sum_take_map_length_lt1 List.sum_take_map_length_lt1
177-
163+ #noalign list.drop_take_succ_join_eq_nth_le
164+ #noalign list.sum_take_map_length_lt1
178165#noalign list.sum_take_map_length_lt2
179166#noalign list.nth_le_join
180167
@@ -188,7 +175,7 @@ theorem eq_iff_join_eq (L L' : List (List α)) :
188175 · have : length (map length L) = length (map length L') := by rw [length_eq]
189176 simpa using this
190177 · intro n h₁ h₂
191- rw [← drop_take_succ_join_eq_get, ← drop_take_succ_join_eq_get, join_eq, length_eq]
178+ rw [← drop_take_succ_join_eq_get' , ← drop_take_succ_join_eq_get' , join_eq, length_eq]
192179#align list.eq_iff_join_eq List.eq_iff_join_eq
193180
194181theorem join_drop_length_sub_one {L : List (List α)} (h : L ≠ []) :
0 commit comments