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

Commit f8c303e

Browse files
committed
refactor(order/filter/pointwise): Localize instances (#13898)
Localize pointwise `filter` instances into the `pointwise` locale, as is done for `set` and `finset`.
1 parent 627f81b commit f8c303e

File tree

1 file changed

+72
-25
lines changed

1 file changed

+72
-25
lines changed

src/order/filter/pointwise.lean

Lines changed: 72 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ distribute over pointwise operations. For example,
3030
`t ∈ g`.
3131
* `f -ᵥ g` (`filter.has_vsub`): Scalar subtraction, filter generated by all `x -ᵥ y` where `s ∈ f`
3232
and `t ∈ g`.
33-
* `f • g` (`filter.has_smul`): Scalar multiplication, filter generated by all `x • y` where `s ∈ f`
34-
and `t ∈ g`.
33+
* `f • g` (`filter.has_scalar`): Scalar multiplication, filter generated by all `x • y` where
34+
`s ∈ f` and `t ∈ g`.
3535
* `a +ᵥ f` (`filter.has_vadd_filter`): Translation, filter of all `a +ᵥ x` where `s ∈ f`.
36-
* `a • f` (`filter.has_smul_filter`): Scaling, filter of all `a • s` where `s ∈ f`.
36+
* `a • f` (`filter.has_scalar_filter`): Scaling, filter of all `a • s` where `s ∈ f`.
37+
38+
## Implementation notes
39+
40+
We put all instances in the locale `pointwise`, so that these instances are not available by
41+
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
42+
since we expect the locale to be open whenever the instances are actually used (and making the
43+
instances reducible changes the behavior of `simp`.
3744
3845
## Tags
3946
@@ -52,9 +59,12 @@ namespace filter
5259
section one
5360
variables [has_one α] {f : filter α} {s : set α}
5461

55-
/-- `1 : filter α` is the set of sets containing `1 : α`. -/
56-
@[to_additive "`0 : filter α` is the set of sets containing `0 : α`."]
57-
instance : has_one (filter α) := ⟨principal 1
62+
/-- `1 : filter α` is defined as the filter of sets containing `1 : α` in locale `pointwise`. -/
63+
@[to_additive "`0 : filter α` is defined as the filter of sets containing `0 : α` in locale
64+
`pointwise`."]
65+
protected def has_one : has_one (filter α) := ⟨principal 1
66+
67+
localized "attribute [instance] filter.has_one filter.has_zero" in pointwise
5868

5969
@[simp, to_additive] lemma mem_one : s ∈ (1 : filter α) ↔ (1 : α) ∈ s := one_subset
6070

@@ -84,7 +94,11 @@ end one
8494
section mul
8595
variables [has_mul α] [has_mul β] {f f₁ f₂ g g₁ g₂ h : filter α} {s t : set α}
8696

87-
@[to_additive] instance : has_mul (filter α) := ⟨map₂ (*)⟩
97+
/-- The filter `f * g` is generated by `{s * t | s ∈ f, t ∈ g}` in locale `pointwise`. -/
98+
@[to_additive "The filter `f + g` is generated by `{s + t | s ∈ f, t ∈ g}` in locale `pointwise`."]
99+
protected def has_mul : has_mul (filter α) := ⟨map₂ (*)⟩
100+
101+
localized "attribute [instance] filter.has_mul filter.has_add" in pointwise
88102

89103
@[simp, to_additive] lemma map₂_mul : map₂ (*) f g = f * g := rfl
90104
@[to_additive] lemma mem_mul_iff : s ∈ f * g ↔ ∃ t₁ t₂, t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ * t₂ ⊆ s := iff.rfl
@@ -109,30 +123,42 @@ map_map₂_distrib $ map_mul m
109123

110124
end mul
111125

112-
@[to_additive]
113-
instance [semigroup α] : semigroup (filter α) :=
126+
open_locale pointwise
127+
128+
/-- `filter α` is a `semigroup` under pointwise operations if `α` is.-/
129+
@[to_additive "`filter α` is an `add_semigroup` under pointwise operations if `α` is."]
130+
protected def semigroup [semigroup α] : semigroup (filter α) :=
114131
{ mul := (*),
115132
mul_assoc := λ f g h, map₂_assoc mul_assoc }
116133

117-
@[to_additive]
118-
instance [comm_semigroup α] : comm_semigroup (filter α) :=
134+
/-- `filter α` is a `comm_semigroup` under pointwise operations if `α` is. -/
135+
@[to_additive "`filter α` is an `add_comm_semigroup` under pointwise operations if `α` is."]
136+
protected def comm_semigroup [comm_semigroup α] : comm_semigroup (filter α) :=
119137
{ mul_comm := λ f g, map₂_comm mul_comm,
120138
..filter.semigroup }
121139

122-
@[to_additive]
123-
instance [mul_one_class α] : mul_one_class (filter α) :=
140+
/-- `filter α` is a `mul_one_class` under pointwise operations if `α` is. -/
141+
@[to_additive "`filter α` is an `add_zero_class` under pointwise operations if `α` is."]
142+
protected def mul_one_class [mul_one_class α] : mul_one_class (filter α) :=
124143
{ one := 1,
125144
mul := (*),
126145
one_mul := λ f, by simp only [←pure_one, ←map₂_mul, map₂_pure_left, one_mul, map_id'],
127146
mul_one := λ f, by simp only [←pure_one, ←map₂_mul, map₂_pure_right, mul_one, map_id'] }
128147

129-
@[to_additive]
130-
instance [monoid α] : monoid (filter α) := { ..filter.mul_one_class, ..filter.semigroup }
148+
/-- `filter α` is a `monoid` under pointwise operations if `α` is. -/
149+
@[to_additive "`filter α` is an `add_monoid` under pointwise operations if `α` is."]
150+
protected def monoid [monoid α] : monoid (filter α) :=
151+
{ ..filter.mul_one_class, ..filter.semigroup }
131152

132-
@[to_additive]
133-
instance [comm_monoid α] : comm_monoid (filter α) :=
153+
/-- `filter α` is a `comm_monoid` under pointwise operations if `α` is. -/
154+
@[to_additive "`filter α` is an `add_comm_monoid` under pointwise operations if `α` is."]
155+
protected def comm_monoid [comm_monoid α] : comm_monoid (filter α) :=
134156
{ ..filter.mul_one_class, ..filter.comm_semigroup }
135157

158+
localized "attribute [instance] filter.mul_one_class filter.add_zero_class filter.semigroup
159+
filter.add_semigroup filter.comm_semigroup filter.add_comm_semigroup filter.monoid
160+
filter.add_monoid filter.comm_monoid filter.add_comm_monoid" in pointwise
161+
136162
section map
137163

138164
variables [mul_one_class α] [mul_one_class β]
@@ -183,7 +209,9 @@ variables [has_involutive_inv α] {f : filter α} {s : set α}
183209

184210
@[to_additive] lemma inv_mem_inv (hs : s ∈ f) : s⁻¹ ∈ f⁻¹ := by rwa [mem_inv, inv_preimage, inv_inv]
185211

186-
instance : has_involutive_inv (filter α) :=
212+
/-- Inversion is involutive on `filter α` if it is on `α`. -/
213+
@[to_additive "Negation is involutive on `filter α` if it is on `α`."]
214+
def has_involutive_inv : has_involutive_inv (filter α) :=
187215
{ inv_inv := λ f, map_map.trans $ by rw [inv_involutive.comp_self, map_id],
188216
..filter.has_inv }
189217

@@ -208,7 +236,11 @@ end group
208236
section div
209237
variables [has_div α] {f f₁ f₂ g g₁ g₂ h : filter α} {s t : set α}
210238

211-
@[to_additive] instance : has_div (filter α) := ⟨map₂ (/)⟩
239+
/-- The filter `f / g` is generated by `{s / t | s ∈ f, t ∈ g}` in locale `pointwise`. -/
240+
@[to_additive "The filter `f - g` is generated by `{s - t | s ∈ f, t ∈ g}` in locale `pointwise`."]
241+
protected def has_div : has_div (filter α) := ⟨map₂ (/)⟩
242+
243+
localized "attribute [instance] filter.has_div filter.has_sub" in pointwise
212244

213245
@[simp, to_additive] lemma map₂_div : map₂ (/) f g = f / g := rfl
214246
@[to_additive] lemma mem_div : s ∈ f / g ↔ ∃ t₁ t₂, t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ / t₂ ⊆ s := iff.rfl
@@ -233,6 +265,8 @@ le_map₂_iff
233265

234266
end div
235267

268+
open_locale pointwise
269+
236270
section group
237271
variables [group α] [group β] {f g : filter α} {f₂ : filter β}
238272

@@ -251,16 +285,20 @@ end group
251285
`div_inv_monoid` and `has_involutive_inv` but smaller than `group` and `group_with_zero`. -/
252286

253287
/-- `f / g = f * g⁻¹` for all `f g : filter α` if `a / b = a * b⁻¹` for all `a b : α`. -/
254-
@[to_additive "`f - g = f + -g` for all `f g : filter α` if `a - b = a + -b` for all `a b : α`."]
255-
instance div_inv_monoid [group α] : div_inv_monoid (filter α) :=
288+
@[to_additive filter.sub_neg_monoid "`f - g = f + -g` for all `f g : filter α` if `a - b = a + -b`
289+
for all `a b : α`."]
290+
protected def div_inv_monoid [group α] : div_inv_monoid (filter α) :=
256291
{ div_eq_mul_inv := λ f g, map_map₂_distrib_right div_eq_mul_inv,
257292
..filter.monoid, ..filter.has_inv, ..filter.has_div }
258293

259294
/-- `f / g = f * g⁻¹` for all `f g : filter α` if `a / b = a * b⁻¹` for all `a b : α`. -/
260-
instance div_inv_monoid' [group_with_zero α] : div_inv_monoid (filter α) :=
295+
protected def div_inv_monoid' [group_with_zero α] : div_inv_monoid (filter α) :=
261296
{ div_eq_mul_inv := λ f g, map_map₂_distrib_right div_eq_mul_inv,
262297
..filter.monoid, ..filter.has_inv, ..filter.has_div }
263298

299+
localized "attribute [instance] filter.div_inv_monoid filter.sub_neg_monoid filter.div_inv_monoid'"
300+
in pointwise
301+
264302
/-! ### Scalar addition/multiplication of filters -/
265303

266304
section smul
@@ -298,7 +336,10 @@ section vsub
298336
variables [has_vsub α β] {f f₁ f₂ g g₁ g₂ : filter β} {h : filter α} {s t : set β}
299337
include α
300338

301-
instance : has_vsub (filter α) (filter β) := ⟨map₂ (-ᵥ)⟩
339+
/-- The filter `f -ᵥ g` is generated by `{s -ᵥ t | s ∈ f, t ∈ g}` in locale `pointwise`. -/
340+
protected def has_vsub : has_vsub (filter α) (filter β) := ⟨map₂ (-ᵥ)⟩
341+
342+
localized "attribute [instance] filter.has_vsub" in pointwise
302343

303344
@[simp] lemma map₂_vsub : map₂ (-ᵥ) f g = f -ᵥ g := rfl
304345
lemma mem_vsub {s : set α} : s ∈ f -ᵥ g ↔ ∃ t₁ t₂, t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ -ᵥ t₂ ⊆ s := iff.rfl
@@ -320,8 +361,12 @@ end vsub
320361
section smul
321362
variables [has_scalar α β] {f f₁ f₂ : filter β} {s : set β} {a : α}
322363

323-
@[to_additive filter.has_vadd_filter]
324-
instance has_scalar_filter : has_scalar α (filter β) := ⟨λ a, map ((•) a)⟩
364+
/-- `a • f` is the map of `f` under `a •` in locale `pointwise`. -/
365+
@[to_additive filter.has_vadd_filter
366+
"`a +ᵥ f` is the map of `f` under `a +ᵥ` in locale `pointwise`."]
367+
protected def has_scalar_filter : has_scalar α (filter β) := ⟨λ a, map ((•) a)⟩
368+
369+
localized "attribute [instance] filter.has_scalar_filter filter.has_vadd_filter" in pointwise
325370

326371
@[simp, to_additive] lemma map_smul : map (λ b, a • b) f = a • f := rfl
327372
@[to_additive] lemma mem_smul_filter : s ∈ a • f ↔ (•) a ⁻¹' s ∈ f := iff.rfl
@@ -339,6 +384,8 @@ map_mono hf
339384

340385
end smul
341386

387+
open_locale pointwise
388+
342389
@[to_additive]
343390
instance smul_comm_class_filter [has_scalar α γ] [has_scalar β γ] [smul_comm_class α β γ] :
344391
smul_comm_class α (filter β) (filter γ) :=

0 commit comments

Comments
 (0)