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

Commit fc19a4e

Browse files
committed
feat({data/finset,order/filter}/pointwise): Multiplicative action on pointwise monoids (#14214)
`mul_action`, `distrib_mul_action`, `mul_distrib_mul_action` instances for `finset` and `filter`. Also delete `set.smul_add_set` because `smul_add` proves it.
1 parent eaa771f commit fc19a4e

File tree

5 files changed

+76
-13
lines changed

5 files changed

+76
-13
lines changed

src/data/finset/n_ary.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ lemma nonempty.of_image₂_right (h : (image₂ f s t).nonempty) : t.nonempty :=
9393
@[simp] lemma image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ :=
9494
by simp_rw [←not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_distrib]
9595

96-
@[simp] lemma image₂_singleton_left : image₂ f {a} t = t.image (f a) := ext $ λ x, by simp
96+
@[simp] lemma image₂_singleton_left : image₂ f {a} t = t.image (λ b, f a b) := ext $ λ x, by simp
9797
@[simp] lemma image₂_singleton_right : image₂ f s {b} = s.image (λ a, f a b) := ext $ λ x, by simp
9898

9999
lemma image₂_singleton : image₂ f {a} {b} = {f a b} := by simp

src/data/finset/pointwise.lean

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For finsets `s` and `t`:
3434
For `α` a semigroup/monoid, `finset α` is a semigroup/monoid.
3535
As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between
3636
pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while
37-
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`.
37+
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action].
3838
3939
## Implementation notes
4040
@@ -603,7 +603,7 @@ subset_image₂
603603

604604
end has_scalar
605605

606-
/-! ### Finset addition/multiplication -/
606+
/-! ### Scalar subtraction of finsets -/
607607

608608
section has_vsub
609609
variables [decidable_eq α] [has_vsub α β] {s s₁ s₂ t t₁ t₂ : finset β} {u : finset α} {a : α}
@@ -684,7 +684,7 @@ lemma mem_smul_finset {x : β} : x ∈ a • s ↔ ∃ y, y ∈ s ∧ a • y =
684684
by simp only [finset.smul_finset_def, and.assoc, mem_image, exists_prop, prod.exists, mem_product]
685685

686686
@[simp, norm_cast, to_additive]
687-
lemma coe_smul_finset (s : finset β) : (↑(a • s) : set β) = a • s := coe_image
687+
lemma coe_smul_finset (a : α) (s : finset β) : (↑(a • s) : set β) = a • s := coe_image
688688

689689
@[to_additive] lemma smul_finset_mem_smul_finset : b ∈ s → a • b ∈ a • s := mem_image_of_mem _
690690
@[to_additive] lemma smul_finset_card_le : (a • s).card ≤ s.card := card_image_le
@@ -750,5 +750,38 @@ instance is_central_scalar [has_scalar α β] [has_scalar αᵐᵒᵖ β] [is_ce
750750
is_central_scalar α (finset β) :=
751751
⟨λ a s, coe_injective $ by simp only [coe_smul_finset, coe_smul, op_smul_eq_smul]⟩
752752

753+
/-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of
754+
`finset α` on `finset β`. -/
755+
@[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action
756+
of `finset α` on `finset β`"]
757+
protected def mul_action [decidable_eq α] [monoid α] [mul_action α β] :
758+
mul_action (finset α) (finset β) :=
759+
{ mul_smul := λ _ _ _, image₂_assoc mul_smul,
760+
one_smul := λ s, image₂_singleton_left.trans $ by simp_rw [one_smul, image_id'] }
761+
762+
/-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `finset β`.
763+
-/
764+
@[to_additive "An additive action of an additive monoid on a type `β` gives an additive action
765+
on `finset β`."]
766+
protected def mul_action_finset [monoid α] [mul_action α β] : mul_action α (finset β) :=
767+
coe_injective.mul_action _ coe_smul_finset
768+
769+
localized "attribute [instance] finset.mul_action_finset finset.add_action_finset
770+
finset.mul_action finset.add_action" in pointwise
771+
772+
/-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive
773+
multiplicative action on `finset β`. -/
774+
protected def distrib_mul_action_finset [monoid α] [add_monoid β] [distrib_mul_action α β] :
775+
distrib_mul_action α (finset β) :=
776+
function.injective.distrib_mul_action ⟨coe, coe_zero, coe_add⟩ coe_injective coe_smul_finset
777+
778+
/-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `set β`. -/
779+
protected def mul_distrib_mul_action_finset [monoid α] [monoid β] [mul_distrib_mul_action α β] :
780+
mul_distrib_mul_action α (finset β) :=
781+
function.injective.mul_distrib_mul_action ⟨coe, coe_one, coe_mul⟩ coe_injective coe_smul_finset
782+
783+
localized "attribute [instance] finset.distrib_mul_action_finset
784+
finset.mul_distrib_mul_action_finset" in pointwise
785+
753786
end instances
754787
end finset

src/data/set/pointwise.lean

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ For sets `s` and `t` and scalar `a`:
3030
For `α` a semigroup/monoid, `set α` is a semigroup/monoid.
3131
As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between
3232
pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while
33-
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`.
33+
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action].
3434
3535
Appropriate definitions and results are also transported to the additive theory via `to_additive`.
3636
@@ -1067,10 +1067,6 @@ end
10671067

10681068
end smul_with_zero
10691069

1070-
lemma smul_add_set [monoid α] [add_monoid β] [distrib_mul_action α β] (c : α) (s t : set β) :
1071-
c • (s + t) = c • s + c • t :=
1072-
image_add (distrib_mul_action.to_add_monoid_hom β c).to_add_hom
1073-
10741070
section group
10751071
variables [group α] [mul_action α β] {A B : set β} {a : α} {x : β}
10761072

src/measure_theory/function/jacobian.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ begin
330330
abel } },
331331
have : A '' (closed_ball 0 r) + closed_ball (f x) (ε * r)
332332
= {f x} + r • (A '' (closed_ball 0 1) + closed_ball 0 ε),
333-
by rw [smul_add_set, ← add_assoc, add_comm ({f x}), add_assoc, smul_closed_ball _ _ εpos.le,
333+
by rw [smul_add, ← add_assoc, add_comm ({f x}), add_assoc, smul_closed_ball _ _ εpos.le,
334334
smul_zero, singleton_add_closed_ball_zero, ← A.image_smul_set,
335335
smul_closed_ball _ _ zero_le_one, smul_zero, real.norm_eq_abs, abs_of_nonneg r0, mul_one,
336336
mul_comm],

src/order/filter/pointwise.lean

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ distribute over pointwise operations. For example,
3636
* `a +ᵥ f` (`filter.has_vadd_filter`): Translation, filter of all `a +ᵥ s` where `s ∈ f`.
3737
* `a • f` (`filter.has_scalar_filter`): Scaling, filter of all `a • s` where `s ∈ f`.
3838
39+
For `α` a semigroup/monoid, `filter α` is a semigroup/monoid.
40+
As an unfortunate side effect, this means that `n • f`, where `n : ℕ`, is ambiguous between
41+
pointwise scaling and repeated pointwise addition. See note [pointwise nat action].
42+
3943
## Implementation notes
4044
4145
We put all instances in the locale `pointwise`, so that these instances are not available by
@@ -564,9 +568,39 @@ instance is_central_scalar [has_scalar α β] [has_scalar αᵐᵒᵖ β] [is_ce
564568
is_central_scalar α (filter β) :=
565569
⟨λ a f, congr_arg (λ m, map m f) $ by exact funext (λ _, op_smul_eq_smul _ _)⟩
566570

567-
@[to_additive]
568-
instance [monoid α] [mul_action α β] : mul_action (filter α) (filter β) :=
569-
{ one_smul := λ f, by simp only [←pure_one, ←map₂_smul, map₂_pure_left, one_smul, map_id'],
571+
/-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of
572+
`filter α` on `filter β`. -/
573+
@[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action
574+
of `filter α` on `filter β`"]
575+
protected def mul_action [monoid α] [mul_action α β] : mul_action (filter α) (filter β) :=
576+
{ one_smul := λ f, map₂_pure_left.trans $ by simp_rw [one_smul, map_id'],
570577
mul_smul := λ f g h, map₂_assoc mul_smul }
571578

579+
/-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `filter β`.
580+
-/
581+
@[to_additive "An additive action of an additive monoid on a type `β` gives an additive action on
582+
`filter β`."]
583+
protected def mul_action_filter [monoid α] [mul_action α β] : mul_action α (filter β) :=
584+
{ mul_smul := λ a b f, by simp only [←map_smul, map_map, function.comp, ←mul_smul],
585+
one_smul := λ f, by simp only [←map_smul, one_smul, map_id'] }
586+
587+
localized "attribute [instance] filter.mul_action filter.add_action filter.mul_action_filter
588+
filter.add_action_filter" in pointwise
589+
590+
/-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive
591+
multiplicative action on `filter β`. -/
592+
protected def distrib_mul_action_filter [monoid α] [add_monoid β] [distrib_mul_action α β] :
593+
distrib_mul_action α (filter β) :=
594+
{ smul_add := λ _ _ _, map_map₂_distrib $ smul_add _,
595+
smul_zero := λ _, (map_pure _ _).trans $ by rw [smul_zero, pure_zero] }
596+
597+
/-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `set β`. -/
598+
protected def mul_distrib_mul_action_filter [monoid α] [monoid β] [mul_distrib_mul_action α β] :
599+
mul_distrib_mul_action α (set β) :=
600+
{ smul_mul := λ _ _ _, image_image2_distrib $ smul_mul' _,
601+
smul_one := λ _, image_singleton.trans $ by rw [smul_one, singleton_one] }
602+
603+
localized "attribute [instance] filter.distrib_mul_action_filter
604+
filter.mul_distrib_mul_action_filter" in pointwise
605+
572606
end filter

0 commit comments

Comments
 (0)