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

Commit 024aef0

Browse files
nomeataVierkantor
andcommitted
feat(data/pi): provide pi.mul_single (#11849)
the additive version was previously called `pi.single`, to this requires refactoring existing code. Co-authored-by: Vierkantor <vierkantor@vierkantor.com>
1 parent 8c60a92 commit 024aef0

File tree

3 files changed

+90
-62
lines changed

3 files changed

+90
-62
lines changed

src/algebra/group/pi.lean

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,51 +172,62 @@ open pi
172172

173173
variables (f)
174174

175-
/-- The zero-preserving homomorphism including a single value
175+
/-- The one-preserving homomorphism including a single value
176176
into a dependent family of values, as functions supported at a point.
177177
178-
This is the `zero_hom` version of `pi.single`. -/
179-
@[simps] def zero_hom.single [Π i, has_zero $ f i] (i : I) : zero_hom (f i) (Π i, f i) :=
180-
{ to_fun := single i,
181-
map_zero' := single_zero i }
178+
This is the `one_hom` version of `pi.mul_single`. -/
179+
@[to_additive zero_hom.single "The zero-preserving homomorphism including a single value
180+
into a dependent family of values, as functions supported at a point.
182181
183-
/-- The additive monoid homomorphism including a single additive monoid
184-
into a dependent family of additive monoids, as functions supported at a point.
182+
This is the `zero_hom` version of `pi.single`.", simps]
183+
def one_hom.single [Π i, has_one $ f i] (i : I) : one_hom (f i) (Π i, f i) :=
184+
{ to_fun := mul_single i,
185+
map_one' := mul_single_one i }
185186

186-
This is the `add_monoid_hom` version of `pi.single`. -/
187-
@[simps] def add_monoid_hom.single [Π i, add_zero_class $ f i] (i : I) : f i →+ Π i, f i :=
188-
{ to_fun := single i,
189-
map_add' := single_op₂ (λ _, (+)) (λ _, zero_add _) _,
190-
.. (zero_hom.single f i) }
187+
/-- The monoid homomorphism including a single monoid into a dependent family of additive monoids,
188+
as functions supported at a point.
189+
190+
This is the `monoid_hom` version of `pi.mul_single`. -/
191+
@[to_additive "The additive monoid homomorphism including a single additive
192+
monoid into a dependent family of additive monoids, as functions supported at a point.
193+
194+
This is the `add_monoid_hom` version of `pi.single`.", simps]
195+
def monoid_hom.single [Π i, mul_one_class $ f i] (i : I) : f i →* Π i, f i :=
196+
{ map_mul' := mul_single_op₂ (λ _, (*)) (λ _, one_mul _) _,
197+
.. (one_hom.single f i) }
191198

192199
/-- The multiplicative homomorphism including a single `mul_zero_class`
193200
into a dependent family of `mul_zero_class`es, as functions supported at a point.
194201
195202
This is the `mul_hom` version of `pi.single`. -/
196203
@[simps] def mul_hom.single [Π i, mul_zero_class $ f i] (i : I) : mul_hom (f i) (Π i, f i) :=
197204
{ to_fun := single i,
198-
map_mul' := single_op₂ (λ _, (*)) (λ _, zero_mul _) _, }
205+
map_mul' := pi.single_op₂ (λ _, (*)) (λ _, zero_mul _) _, }
199206

200207
variables {f}
201208

202-
lemma pi.single_add [Π i, add_zero_class $ f i] (i : I) (x y : f i) :
203-
single i (x + y) = single i x + single i y :=
204-
(add_monoid_hom.single f i).map_add x y
209+
@[to_additive]
210+
lemma pi.mul_single_mul [Π i, mul_one_class $ f i] (i : I) (x y : f i) :
211+
mul_single i (x * y) = mul_single i x * mul_single i y :=
212+
(monoid_hom.single f i).map_mul x y
205213

206-
lemma pi.single_neg [Π i, add_group $ f i] (i : I) (x : f i) :
207-
single i (-x) = -single i x :=
208-
(add_monoid_hom.single f i).map_neg x
214+
@[to_additive]
215+
lemma pi.mul_single_inv [Π i, group $ f i] (i : I) (x : f i) :
216+
mul_single i (x⁻¹) = (mul_single i x)⁻¹ :=
217+
(monoid_hom.single f i).map_inv x
209218

210-
lemma pi.single_sub [Π i, add_group $ f i] (i : I) (x y : f i) :
211-
single i (x - y) = single i x - single i y :=
212-
(add_monoid_hom.single f i).map_sub x y
219+
@[to_additive]
220+
lemma pi.single_div [Π i, group $ f i] (i : I) (x y : f i) :
221+
mul_single i (x / y) = mul_single i x / mul_single i y :=
222+
(monoid_hom.single f i).map_div x y
213223

214224
lemma pi.single_mul [Π i, mul_zero_class $ f i] (i : I) (x y : f i) :
215225
single i (x * y) = single i x * single i y :=
216226
(mul_hom.single f i).map_mul x y
217227

218-
lemma pi.update_eq_sub_add_single [Π i, add_group $ f i] (g : Π (i : I), f i) (x : f i) :
219-
function.update g i x = g - single i (g i) + single i x :=
228+
@[to_additive update_eq_sub_add_single]
229+
lemma pi.update_eq_div_mul_single [Π i, group $ f i] (g : Π (i : I), f i) (x : f i) :
230+
function.update g i x = g / mul_single i (g i) * mul_single i x :=
220231
begin
221232
ext j,
222233
rcases eq_or_ne i j with rfl|h,

src/algebra/group/to_additive.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ meta def tr : bool → list string → list string
202202
| is_comm ("one" :: "lt" :: s) := add_comm_prefix is_comm "pos" :: tr ff s
203203
| is_comm ("le" :: "one" :: s) := add_comm_prefix is_comm "nonpos" :: tr ff s
204204
| is_comm ("lt" :: "one" :: s) := add_comm_prefix is_comm "neg" :: tr ff s
205+
| is_comm ("mul" :: "single" :: s) := add_comm_prefix is_comm "single" :: tr ff s
205206
| is_comm ("mul" :: "support" :: s) := add_comm_prefix is_comm "support" :: tr ff s
206207
| is_comm ("mul" :: "indicator" :: s) := add_comm_prefix is_comm "indicator" :: tr ff s
207208
| is_comm ("mul" :: s) := add_comm_prefix is_comm "add" :: tr ff s

src/data/pi.lean

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,65 +85,80 @@ instance has_mul [∀ i, has_mul $ f i] :
8585
section
8686

8787
variables [decidable_eq I]
88-
variables [Π i, has_zero (f i)] [Π i, has_zero (g i)] [Π i, has_zero (h i)]
88+
variables [Π i, has_one (f i)] [Π i, has_one (g i)] [Π i, has_one (h i)]
8989

90-
/-- The function supported at `i`, with value `x` there. -/
91-
def single (i : I) (x : f i) : Π i, f i :=
92-
function.update 0 i x
90+
/-- The function supported at `i`, with value `x` there, and `1` elsewhere. -/
91+
@[to_additive pi.single "The function supported at `i`, with value `x` there, and `0` elsewhere." ]
92+
def mul_single (i : I) (x : f i) : Π i, f i :=
93+
function.update 1 i x
9394

94-
@[simp] lemma single_eq_same (i : I) (x : f i) : single i x i = x :=
95+
@[simp, to_additive]
96+
lemma mul_single_eq_same (i : I) (x : f i) : mul_single i x i = x :=
9597
function.update_same i x _
9698

97-
@[simp] lemma single_eq_of_ne {i i' : I} (h : i' ≠ i) (x : f i) : single i x i' = 0 :=
99+
@[simp, to_additive]
100+
lemma mul_single_eq_of_ne {i i' : I} (h : i' ≠ i) (x : f i) : mul_single i x i' = 1 :=
98101
function.update_noteq h x _
99102

100-
/-- Abbreviation for `single_eq_of_ne h.symm`, for ease of use by `simp`. -/
101-
@[simp] lemma single_eq_of_ne' {i i' : I} (h : i ≠ i') (x : f i) : single i x i' = 0 :=
102-
single_eq_of_ne h.symm x
103+
/-- Abbreviation for `mul_single_eq_of_ne h.symm`, for ease of use by `simp`. -/
104+
@[simp, to_additive "Abbreviation for `single_eq_of_ne h.symm`, for ease of
105+
use by `simp`."]
106+
lemma mul_single_eq_of_ne' {i i' : I} (h : i ≠ i') (x : f i) : mul_single i x i' = 1 :=
107+
mul_single_eq_of_ne h.symm x
103108

104-
@[simp] lemma single_zero (i : I) : single i (0 : f i) = 0 :=
109+
@[simp, to_additive]
110+
lemma mul_single_one (i : I) : mul_single i (1 : f i) = 1 :=
105111
function.update_eq_self _ _
106112

107-
/-- On non-dependent functions, `pi.single` can be expressed as an `ite` -/
108-
lemma single_apply {β : Sort*} [has_zero β] (i : I) (x : β) (i' : I) :
109-
single i x i' = if i' = i then x else 0 :=
110-
function.update_apply 0 i x i'
113+
/-- On non-dependent functions, `pi.mul_single` can be expressed as an `ite` -/
114+
@[to_additive "On non-dependent functions, `pi.single` can be expressed as an `ite`"]
115+
lemma mul_single_apply {β : Sort*} [has_one β] (i : I) (x : β) (i' : I) :
116+
mul_single i x i' = if i' = i then x else 1 :=
117+
function.update_apply 1 i x i'
111118

112-
/-- On non-dependent functions, `pi.single` is symmetric in the two indices. -/
113-
lemma single_comm {β : Sort*} [has_zero β] (i : I) (x : β) (i' : I) :
114-
single i x i' = single i' x i :=
115-
by simp [single_apply, eq_comm]
119+
/-- On non-dependent functions, `pi.mul_single` is symmetric in the two indices. -/
120+
@[to_additive "On non-dependent functions, `pi.single` is symmetric in the two
121+
indices."]
122+
lemma mul_single_comm {β : Sort*} [has_one β] (i : I) (x : β) (i' : I) :
123+
mul_single i x i' = mul_single i' x i :=
124+
by simp [mul_single_apply, eq_comm]
116125

117-
lemma apply_single (f' : Π i, f i → g i) (hf' : ∀ i, f' i 0 = 0) (i : I) (x : f i) (j : I):
118-
f' j (single i x j) = single i (f' i x) j :=
119-
by simpa only [pi.zero_apply, hf', single] using function.apply_update f' 0 i x j
126+
@[to_additive]
127+
lemma apply_mul_single (f' : Π i, f i → g i) (hf' : ∀ i, f' i 1 = 1) (i : I) (x : f i) (j : I):
128+
f' j (mul_single i x j) = mul_single i (f' i x) j :=
129+
by simpa only [pi.one_apply, hf', mul_single] using function.apply_update f' 1 i x j
120130

121-
lemma apply_single₂ (f' : Π i, f i → g i → h i) (hf' : ∀ i, f' i 0 0 = 0)
131+
@[to_additive apply_single₂]
132+
lemma apply_mul_single₂ (f' : Π i, f i → g i → h i) (hf' : ∀ i, f' i 1 1 = 1)
122133
(i : I) (x : f i) (y : g i) (j : I):
123-
f' j (single i x j) (single i y j) = single i (f' i x y) j :=
134+
f' j (mul_single i x j) (mul_single i y j) = mul_single i (f' i x y) j :=
124135
begin
125136
by_cases h : j = i,
126-
{ subst h, simp only [single_eq_same] },
127-
{ simp only [single_eq_of_ne h, hf'] },
137+
{ subst h, simp only [mul_single_eq_same] },
138+
{ simp only [mul_single_eq_of_ne h, hf'] },
128139
end
129140

130-
lemma single_op {g : I → Type*} [Π i, has_zero (g i)] (op : Π i, f i → g i) (h : ∀ i, op i 0 = 0)
141+
@[to_additive]
142+
lemma mul_single_op {g : I → Type*} [Π i, has_one (g i)] (op : Π i, f i → g i) (h : ∀ i, op i 1 = 1)
131143
(i : I) (x : f i) :
132-
single i (op i x) = λ j, op j (single i x j) :=
133-
eq.symm $ funext $ apply_single op h i x
144+
mul_single i (op i x) = λ j, op j (mul_single i x j) :=
145+
eq.symm $ funext $ apply_mul_single op h i x
134146

135-
lemma single_op₂ {g₁ g₂ : I → Type*} [Π i, has_zero (g₁ i)] [Π i, has_zero (g₂ i)]
136-
(op : Π i, g₁ i → g₂ i → f i) (h : ∀ i, op i 0 0 = 0) (i : I) (x₁ : g₁ i) (x₂ : g₂ i) :
137-
single i (op i x₁ x₂) = λ j, op j (single i x₁ j) (single i x₂ j) :=
138-
eq.symm $ funext $ apply_single₂ op h i x₁ x₂
147+
@[to_additive]
148+
lemma mul_single_op₂ {g₁ g₂ : I → Type*} [Π i, has_one (g₁ i)] [Π i, has_one (g₂ i)]
149+
(op : Π i, g₁ i → g₂ i → f i) (h : ∀ i, op i 1 1 = 1) (i : I) (x₁ : g₁ i) (x₂ : g₂ i) :
150+
mul_single i (op i x₁ x₂) = λ j, op j (mul_single i x₁ j) (mul_single i x₂ j) :=
151+
eq.symm $ funext $ apply_mul_single₂ op h i x₁ x₂
139152

140153
variables (f)
141154

142-
lemma single_injective (i : I) : function.injective (single i : f i → Π i, f i) :=
155+
@[to_additive]
156+
lemma mul_single_injective (i : I) : function.injective (mul_single i : f i → Π i, f i) :=
143157
function.update_injective _ i
144158

145-
@[simp] lemma single_inj (i : I) {x y : f i} : pi.single i x = pi.single i y ↔ x = y :=
146-
(pi.single_injective _ _).eq_iff
159+
@[simp, to_additive]
160+
lemma mul_single_inj (i : I) {x y : f i} : mul_single i x = mul_single i y ↔ x = y :=
161+
(pi.mul_single_injective _ _).eq_iff
147162

148163
end
149164

@@ -197,7 +212,8 @@ lemma bijective_pi_map {F : Π i, f i → g i} (hF : ∀ i, bijective (F i)) :
197212

198213
end function
199214

200-
lemma subsingleton.pi_single_eq {α : Type*} [decidable_eq I] [subsingleton I] [has_zero α]
215+
@[to_additive subsingleton.pi_single_eq]
216+
lemma subsingleton.pi_mul_single_eq {α : Type*} [decidable_eq I] [subsingleton I] [has_one α]
201217
(i : I) (x : α) :
202-
pi.single i x = λ _, x :=
203-
funext $ λ j, by rw [subsingleton.elim j i, pi.single_eq_same]
218+
pi.mul_single i x = λ _, x :=
219+
funext $ λ j, by rw [subsingleton.elim j i, pi.mul_single_eq_same]

0 commit comments

Comments
 (0)