@@ -103,10 +103,16 @@ namespace quadratic_form
103
103
104
104
variables {Q : quadratic_form R M}
105
105
106
+ instance fun_like : fun_like (quadratic_form R M) M (λ _, R) :=
107
+ { coe := to_fun,
108
+ coe_injective' := λ x y h, by cases x; cases y; congr' }
109
+
110
+ /-- Helper instance for when there's too many metavariables to apply
111
+ `fun_like.has_coe_to_fun` directly. -/
106
112
instance : has_coe_to_fun (quadratic_form R M) (λ _, M → R) := ⟨to_fun⟩
107
113
108
114
/-- The `simp` normal form for a quadratic form is `coe_fn`, not `to_fun`. -/
109
- @[simp] lemma to_fun_eq_apply : Q.to_fun = ⇑ Q := rfl
115
+ @[simp] lemma to_fun_eq_coe : Q.to_fun = ⇑ Q := rfl
110
116
111
117
lemma map_smul (a : R) (x : M) : Q (a • x) = a * a * Q x := Q.to_fun_smul a x
112
118
@@ -116,6 +122,10 @@ by { rw [←one_smul R x, ←add_smul, map_smul], norm_num }
116
122
@[simp] lemma map_zero : Q 0 = 0 :=
117
123
by rw [←@zero_smul R _ _ _ _ (0 : M), map_smul, zero_mul, zero_mul]
118
124
125
+ instance zero_hom_class : zero_hom_class (quadratic_form R M) M R :=
126
+ { map_zero := λ _, map_zero,
127
+ ..quadratic_form.fun_like }
128
+
119
129
@[simp] lemma map_neg (x : M) : Q (-x) = Q x :=
120
130
by rw [←@neg_one_smul R _ _ _ _ x, map_smul, neg_one_mul, neg_neg, one_mul]
121
131
@@ -200,12 +210,48 @@ end of_tower
200
210
201
211
variable {Q' : quadratic_form R M}
202
212
203
- @[ext] lemma ext (H : ∀ (x : M), Q x = Q' x) : Q = Q' :=
204
- by { cases Q, cases Q', congr, funext, apply H }
213
+ @[ext] lemma ext (H : ∀ (x : M), Q x = Q' x) : Q = Q' := fun_like.ext _ _ H
214
+
215
+ lemma congr_fun (h : Q = Q') (x : M) : Q x = Q' x := fun_like.congr_fun h _
205
216
206
- lemma congr_fun (h : Q = Q') (x : M) : Q x = Q' x := h ▸ rfl
217
+ lemma ext_iff : Q = Q' ↔ (∀ x, Q x = Q' x) := fun_like.ext_iff
207
218
208
- lemma ext_iff : Q = Q' ↔ (∀ x, Q x = Q' x) := ⟨congr_fun, ext⟩
219
+ /-- Copy of a `quadratic_form` with a new `to_fun` equal to the old one. Useful to fix definitional
220
+ equalities. -/
221
+ protected def copy (Q : quadratic_form R M) (Q' : M → R) (h : Q' = ⇑Q) : quadratic_form R M :=
222
+ { to_fun := Q',
223
+ to_fun_smul := h.symm ▸ Q.to_fun_smul,
224
+ polar_add_left' := h.symm ▸ Q.polar_add_left',
225
+ polar_smul_left' := h.symm ▸ Q.polar_smul_left',
226
+ polar_add_right' := h.symm ▸ Q.polar_add_right',
227
+ polar_smul_right' := h.symm ▸ Q.polar_smul_right' }
228
+
229
+ section has_scalar
230
+
231
+ variables [monoid S] [distrib_mul_action S R] [smul_comm_class S R R]
232
+
233
+ /-- `quadratic_form R M` inherits the scalar action from any algebra over `R`.
234
+
235
+ When `R` is commutative, this provides an `R`-action via `algebra.id`. -/
236
+ instance : has_scalar S (quadratic_form R M) :=
237
+ ⟨ λ a Q,
238
+ { to_fun := a • Q,
239
+ to_fun_smul := λ b x, by rw [pi.smul_apply, map_smul, pi.smul_apply, mul_smul_comm],
240
+ polar_add_left' := λ x x' y, by simp only [polar_smul, polar_add_left, smul_add],
241
+ polar_smul_left' := λ b x y, begin
242
+ simp only [polar_smul, polar_smul_left, ←mul_smul_comm, smul_eq_mul],
243
+ end ,
244
+ polar_add_right' := λ x y y', by simp only [polar_smul, polar_add_right, smul_add],
245
+ polar_smul_right' := λ b x y, begin
246
+ simp only [polar_smul, polar_smul_right, ←mul_smul_comm, smul_eq_mul],
247
+ end } ⟩
248
+
249
+ @[simp] lemma coe_fn_smul (a : S) (Q : quadratic_form R M) : ⇑(a • Q) = a • Q := rfl
250
+
251
+ @[simp] lemma smul_apply (a : S) (Q : quadratic_form R M) (x : M) :
252
+ (a • Q) x = a • Q x := rfl
253
+
254
+ end has_scalar
209
255
210
256
instance : has_zero (quadratic_form R M) :=
211
257
⟨ { to_fun := λ x, 0 ,
@@ -242,36 +288,31 @@ instance : has_add (quadratic_form R M) :=
242
288
instance : has_neg (quadratic_form R M) :=
243
289
⟨ λ Q,
244
290
{ to_fun := -Q,
245
- to_fun_smul := λ a x,
246
- by simp only [pi.neg_apply, map_smul, mul_neg],
247
- polar_add_left' := λ x x' y,
248
- by simp only [polar_neg, polar_add_left, neg_add],
249
- polar_smul_left' := λ a x y,
250
- by simp only [polar_neg, polar_smul_left, mul_neg, smul_eq_mul],
251
- polar_add_right' := λ x y y',
252
- by simp only [polar_neg, polar_add_right, neg_add],
253
- polar_smul_right' := λ a x y,
254
- by simp only [polar_neg, polar_smul_right, mul_neg, smul_eq_mul] } ⟩
291
+ to_fun_smul := λ a x,
292
+ by simp only [pi.neg_apply, map_smul, mul_neg],
293
+ polar_add_left' := λ x x' y,
294
+ by simp only [polar_neg, polar_add_left, neg_add],
295
+ polar_smul_left' := λ a x y,
296
+ by simp only [polar_neg, polar_smul_left, mul_neg, smul_eq_mul],
297
+ polar_add_right' := λ x y y',
298
+ by simp only [polar_neg, polar_add_right, neg_add],
299
+ polar_smul_right' := λ a x y,
300
+ by simp only [polar_neg, polar_smul_right, mul_neg, smul_eq_mul] } ⟩
255
301
256
302
@[simp] lemma coe_fn_neg (Q : quadratic_form R M) : ⇑(-Q) = -Q := rfl
257
303
258
304
@[simp] lemma neg_apply (Q : quadratic_form R M) (x : M) : (-Q) x = -Q x := rfl
259
305
260
- instance : add_comm_group (quadratic_form R M) :=
261
- { add := (+),
262
- zero := 0 ,
263
- neg := has_neg.neg,
264
- add_comm := λ Q Q', by { ext, simp only [add_apply, add_comm] },
265
- add_assoc := λ Q Q' Q'', by { ext, simp only [add_apply, add_assoc] },
266
- add_left_neg := λ Q, by { ext, simp only [add_apply, neg_apply, zero_apply, add_left_neg] },
267
- add_zero := λ Q, by { ext, simp only [zero_apply, add_apply, add_zero] },
268
- zero_add := λ Q, by { ext, simp only [zero_apply, add_apply, zero_add] } }
306
+ instance : has_sub (quadratic_form R M) :=
307
+ ⟨ λ Q Q', (Q + -Q').copy (Q - Q') (sub_eq_add_neg _ _) ⟩
308
+
309
+ @[simp] lemma coe_fn_sub (Q Q' : quadratic_form R M) : ⇑(Q - Q') = Q - Q' := rfl
269
310
270
- @[simp] lemma coe_fn_sub (Q Q' : quadratic_form R M) : ⇑(Q - Q') = Q - Q' :=
271
- by simp only [quadratic_form.coe_fn_neg, add_left_inj, quadratic_form.coe_fn_add, sub_eq_add_neg]
311
+ @[simp] lemma sub_apply (Q Q' : quadratic_form R M) (x : M) : (Q - Q') x = Q x - Q' x := rfl
272
312
273
- @[simp] lemma sub_apply (Q Q' : quadratic_form R M) (x : M) : (Q - Q') x = Q x - Q' x :=
274
- by simp only [quadratic_form.neg_apply, add_left_inj, quadratic_form.add_apply, sub_eq_add_neg]
313
+ instance : add_comm_group (quadratic_form R M) :=
314
+ fun_like.coe_injective.add_comm_group _
315
+ coe_fn_zero coe_fn_add coe_fn_neg coe_fn_sub (λ _ _, coe_fn_smul _ _) (λ _ _, coe_fn_smul _ _)
275
316
276
317
/-- `@coe_fn (quadratic_form R M)` as an `add_monoid_hom`.
277
318
@@ -299,38 +340,17 @@ open_locale big_operators
299
340
300
341
end sum
301
342
302
- section has_scalar
343
+ section distrib_mul_action
303
344
304
345
variables [monoid S] [distrib_mul_action S R] [smul_comm_class S R R]
305
346
306
- /-- `quadratic_form R M` inherits the scalar action from any algebra over `R`.
307
-
308
- When `R` is commutative, this provides an `R`-action via `algebra.id`. -/
309
- instance : has_scalar S (quadratic_form R M) :=
310
- ⟨ λ a Q,
311
- { to_fun := a • Q,
312
- to_fun_smul := λ b x, by rw [pi.smul_apply, map_smul, pi.smul_apply, mul_smul_comm],
313
- polar_add_left' := λ x x' y, by simp only [polar_smul, polar_add_left, smul_add],
314
- polar_smul_left' := λ b x y, begin
315
- simp only [polar_smul, polar_smul_left, ←mul_smul_comm, smul_eq_mul],
316
- end ,
317
- polar_add_right' := λ x y y', by simp only [polar_smul, polar_add_right, smul_add],
318
- polar_smul_right' := λ b x y, begin
319
- simp only [polar_smul, polar_smul_right, ←mul_smul_comm, smul_eq_mul],
320
- end } ⟩
321
-
322
- @[simp] lemma coe_fn_smul (a : S) (Q : quadratic_form R M) : ⇑(a • Q) = a • Q := rfl
323
-
324
- @[simp] lemma smul_apply (a : S) (Q : quadratic_form R M) (x : M) :
325
- (a • Q) x = a • Q x := rfl
326
-
327
347
instance : distrib_mul_action S (quadratic_form R M) :=
328
348
{ mul_smul := λ a b Q, ext (λ x, by simp only [smul_apply, mul_smul]),
329
349
one_smul := λ Q, ext (λ x, by simp only [quadratic_form.smul_apply, one_smul]),
330
350
smul_add := λ a Q Q', by { ext, simp only [add_apply, smul_apply, smul_add] },
331
351
smul_zero := λ a, by { ext, simp only [zero_apply, smul_apply, smul_zero] }, }
332
352
333
- end has_scalar
353
+ end distrib_mul_action
334
354
335
355
section module
336
356
0 commit comments