Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit bc65b7c

Browse files
committed
feat(data/list/basic): add list.range_map (#13777)
* add `list.range_map` and `list.range_map_coe`; * add `submonoid.closure_eq_image_prod` and `add_submonoid.closure_eq_image_prod`.
1 parent 992e26f commit bc65b7c

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/data/list/basic.lean

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,28 @@ lemma map_bind (g : β → list γ) (f : α → β) :
185185
| [] := rfl
186186
| (a::l) := by simp only [cons_bind, map_cons, map_bind l]
187187

188+
lemma range_map (f : α → β) : set.range (map f) = {l | ∀ x ∈ l, x ∈ set.range f} :=
189+
begin
190+
refine set.subset.antisymm (set.range_subset_iff.2 $
191+
λ l, forall_mem_map_iff.2 $ λ y _, set.mem_range_self _) (λ l hl, _),
192+
induction l with a l ihl, { exact ⟨[], rfl⟩ },
193+
rcases ihl (λ x hx, hl x $ subset_cons _ _ hx) with ⟨l, rfl⟩,
194+
rcases hl a (mem_cons_self _ _) with ⟨a, rfl⟩,
195+
exact ⟨a :: l, map_cons _ _ _⟩
196+
end
197+
198+
lemma range_map_coe (s : set α) : set.range (map (coe : s → α)) = {l | ∀ x ∈ l, x ∈ s} :=
199+
by rw [range_map, subtype.range_coe]
200+
188201
/-- If each element of a list can be lifted to some type, then the whole list can be lifted to this
189202
type. -/
190203
instance [h : can_lift α β] : can_lift (list α) (list β) :=
191204
{ coe := list.map h.coe,
192205
cond := λ l, ∀ x ∈ l, can_lift.cond β x,
193206
prf := λ l H,
194207
begin
195-
induction l with a l ihl, { exact ⟨[], rfl⟩ },
196-
rcases ihl (λ x hx, H x (or.inr hx)) with ⟨l, rfl⟩,
197-
rcases can_lift.prf a (H a (or.inl rfl)) with ⟨a, rfl⟩,
198-
exact ⟨a :: l, rfl⟩
208+
rw [← set.mem_range, range_map],
209+
exact λ a ha, can_lift.prf a (H a ha),
199210
end}
200211

201212
/-! ### length -/

src/group_theory/submonoid/membership.lean

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,17 @@ lemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift (coe : s →
285285
by rw [mrange_eq_map, ← free_monoid.closure_range_of, map_mclosure, ← set.range_comp,
286286
free_monoid.lift_comp_of, subtype.range_coe]
287287

288+
@[to_additive] lemma closure_eq_image_prod (s : set M) :
289+
(closure s : set M) = list.prod '' {l : list M | ∀ x ∈ l, x ∈ s} :=
290+
begin
291+
rw [closure_eq_mrange, coe_mrange, ← list.range_map_coe, ← set.range_comp],
292+
refl
293+
end
294+
288295
@[to_additive]
289296
lemma exists_list_of_mem_closure {s : set M} {x : M} (hx : x ∈ closure s) :
290297
∃ (l : list M) (hl : ∀ y ∈ l, y ∈ s), l.prod = x :=
291-
begin
292-
rw [closure_eq_mrange, mem_mrange] at hx,
293-
rcases hx with ⟨l, hx⟩,
294-
exact ⟨list.map coe l, λ y hy, let ⟨z, hz, hy⟩ := list.mem_map.1 hy in hy ▸ z.2, hx⟩
295-
end
298+
by rwa [← set_like.mem_coe, closure_eq_image_prod, set.mem_image_iff_bex] at hx
296299

297300
@[to_additive]
298301
lemma exists_multiset_of_mem_closure {M : Type*} [comm_monoid M] {s : set M}

0 commit comments

Comments
 (0)