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

Commit 3a6340c

Browse files
committed
chore(data/dfinsupp): golf using quotient.map instead of quotient.lift_on (#9176)
1 parent f8d8171 commit 3a6340c

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

src/data/dfinsupp.lean

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ bundled:
8989
* `dfinsupp.map_range.linear_map`
9090
* `dfinsupp.map_range.linear_equiv`
9191
-/
92-
def map_range (f : Π i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (g : Π₀ i, β₁ i) : Π₀ i, β₂ i :=
93-
quotient.lift_on g (λ x, ⟦(⟨λ i, f i (x.1 i), x.2,
94-
λ i, or.cases_on (x.3 i) or.inl $ λ H, or.inr $ by rw [H, hf]⟩ : pre ι β₂)⟧) $ λ x y H,
95-
quotient.sound $ λ i, by simp only [H i]
92+
def map_range (f : Π i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) : (Π₀ i, β₁ i) Π₀ i, β₂ i :=
93+
quotient.map
94+
(λ x, ⟨λ i, f i (x.1 i), x.2, λ i, (x.3 i).imp_right $ λ H, by rw [H, hf]⟩)
95+
(λ x y H i, by simp only [H i])
9696

9797
@[simp] lemma map_range_apply
9898
(f : Π i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (g : Π₀ i, β₁ i) (i : ι) :
@@ -115,17 +115,17 @@ by { ext, simp only [map_range_apply, coe_zero, pi.zero_apply, hf] }
115115

116116
/-- Let `f i` be a binary operation `β₁ i → β₂ i → β i` such that `f i 0 0 = 0`.
117117
Then `zip_with f hf` is a binary operation `Π₀ i, β₁ i → Π₀ i, β₂ i → Π₀ i, β i`. -/
118-
def zip_with (f : Π i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0)
119-
(g₁ : Π₀ i, β₁ i) (g₂ : Π₀ i, β₂ i) : (Π₀ i, β i) :=
118+
def zip_with (f : Π i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) :
119+
(Π₀ i, β₁ i) → (Π₀ i, β₂ i) (Π₀ i, β i) :=
120120
begin
121-
refine quotient.lift_on₂ g₁ g₂ (λ x y, ⟦(⟨λ i, f i (x.1 i) (y.1 i), x.2 + y.2,
122-
λ i, _⟩ : pre ι β)⟧) _,
121+
refine quotient.map₂
122+
(λ x y, ⟨λ i, f i (x.1 i) (y.1 i), x.2 + y.2, λ i, _⟩) _,
123123
{ cases x.3 i with h1 h1,
124124
{ left, rw multiset.mem_add, left, exact h1 },
125125
cases y.3 i with h2 h2,
126126
{ left, rw multiset.mem_add, right, exact h2 },
127127
right, rw [h1, h2, hf] },
128-
exact λ x₁ x₂ y₁ y₂ H1 H2, quotient.sound $ λ i, by simp only [H1 i, H2 i]
128+
exact λ x₁ x₂ H1 y₁ y₂ H2 i, by simp only [H1 i, H2 i]
129129
end
130130

131131
@[simp] lemma zip_with_apply
@@ -260,10 +260,10 @@ end algebra
260260
section filter_and_subtype_domain
261261

262262
/-- `filter p f` is the function which is `f i` if `p i` is true and 0 otherwise. -/
263-
def filter [Π i, has_zero (β i)] (p : ι → Prop) [decidable_pred p] (f : Π₀ i, β i) : Π₀ i, β i :=
264-
quotient.lift_on f (λ x, ⟦(⟨λ i, if p i then x.1 i else 0, x.2,
265-
λ i, or.cases_on (x.3 i) or.inl $ λ H, or.inr $ by rw [H, if_t_t]⟩ : pre ι β)⟧) $ λ x y H,
266-
quotient.sound $ λ i, by simp only [H i]
263+
def filter [Π i, has_zero (β i)] (p : ι → Prop) [decidable_pred p] : (Π₀ i, β i) Π₀ i, β i :=
264+
quotient.map
265+
(λ x, ⟨λ i, if p i then x.1 i else 0, x.2, λ i, (x.3 i).imp_right $ λ H, by rw [H, if_t_t]⟩)
266+
(λ x y H i, by simp only [H i])
267267

268268
@[simp] lemma filter_apply [Π i, has_zero (β i)]
269269
(p : ι → Prop) [decidable_pred p] (i : ι) (f : Π₀ i, β i) :
@@ -287,19 +287,13 @@ ext $ λ i, by simp only [add_apply, filter_apply]; split_ifs; simp only [add_ze
287287

288288
/-- `subtype_domain p f` is the restriction of the finitely supported function
289289
`f` to the subtype `p`. -/
290-
def subtype_domain [Π i, has_zero (β i)] (p : ι → Prop) [decidable_pred p]
291-
(f : Π₀ i, β i) : Π₀ i : subtype p, β i :=
292-
begin
293-
fapply quotient.lift_on f,
294-
{ intro x,
295-
refine ⟦⟨λ i, x.1 (i : ι),
296-
(x.2.filter p).attach.map $ λ j, ⟨j, (multiset.mem_filter.1 j.2).2⟩, _⟩⟧,
297-
refine λ i, or.cases_on (x.3 i) (λ H, _) or.inr,
298-
left, rw multiset.mem_map, refine ⟨⟨i, multiset.mem_filter.2 ⟨H, i.2⟩⟩, _, subtype.eta _ _⟩,
299-
apply multiset.mem_attach },
300-
intros x y H,
301-
exact quotient.sound (λ i, H i)
302-
end
290+
def subtype_domain [Π i, has_zero (β i)] (p : ι → Prop) [decidable_pred p] :
291+
(Π₀ i, β i) → Π₀ i : subtype p, β i :=
292+
quotient.map
293+
(λ x, ⟨λ i, x.1 (i : ι), (x.2.filter p).attach.map $ λ j, ⟨j, (multiset.mem_filter.1 j.2).2⟩,
294+
λ i, (x.3 i).imp_left $ λ H, multiset.mem_map.2
295+
⟨⟨i, multiset.mem_filter.2 ⟨H, i.2⟩⟩, multiset.mem_attach _ _, subtype.eta _ _⟩⟩)
296+
(λ x y H i, H i)
303297

304298
@[simp] lemma subtype_domain_zero [Π i, has_zero (β i)] {p : ι → Prop} [decidable_pred p] :
305299
subtype_domain p (0 : Π₀ i, β i) = 0 :=
@@ -436,11 +430,11 @@ lemma single_eq_of_sigma_eq
436430
by { cases h, refl }
437431

438432
/-- Redefine `f i` to be `0`. -/
439-
def erase (i : ι) (f : Π₀ i, β i) : Π₀ i, β i :=
440-
quotient.lift_on f (λ x, ⟦(⟨λ j, if j = i then 0 else x.1 j, x.2,
441-
λ j, or.cases_on (x.3 j) or.inl $ λ H, or.inr $ by simp only [H, if_t_t]⟩ : pre ι β)⟧) $ λ x y H,
442-
quotient.sound $ λ j, if h : j = i then by simp only [if_pos h]
443-
else by simp only [if_neg h, H j]
433+
def erase (i : ι) : (Π₀ i, β i) Π₀ i, β i :=
434+
quotient.map
435+
(λ x, ⟨λ j, if j = i then 0 else x.1 j, x.2,
436+
λ j, (x.3 j).imp_right $ λ H, by simp only [H, if_t_t]⟩)
437+
(λ x y H j, if h : j = i then by simp only [if_pos h] else by simp only [if_neg h, H j])
444438

445439
@[simp] lemma erase_apply {i j : ι} {f : Π₀ i, β i} :
446440
(f.erase i) j = if j = i then 0 else f j :=
@@ -551,7 +545,7 @@ begin
551545
{ exact quotient.sound (λ i, rfl) },
552546
rw H3, apply ih },
553547
have H2 : p (erase i ⟦{to_fun := f, pre_support := i ::ₘ s, zero := H}⟧),
554-
{ dsimp only [erase, quotient.lift_on_mk],
548+
{ dsimp only [erase, quotient.map_mk],
555549
have H2 : ∀ j, j ∈ s ∨ ite (j = i) 0 (f j) = 0,
556550
{ intro j, cases H j with H2 H2,
557551
{ cases multiset.mem_cons.1 H2 with H3 H3,

0 commit comments

Comments
 (0)