@@ -263,15 +263,14 @@ library_note "vector space definition"
263
263
abbreviation vector_space (R : Type u) (M : Type v) [field R] [add_comm_group M] :=
264
264
semimodule R M
265
265
266
- namespace add_comm_monoid
267
- open add_monoid
266
+ section add_comm_monoid
268
267
269
- variables [add_comm_monoid M]
268
+ variables [semiring R] [ add_comm_monoid M] [semimodule R M]
270
269
271
270
/-- The natural ℕ-semimodule structure on any `add_comm_monoid`. -/
272
271
-- We don't make this a global instance, as it results in too many instances,
273
272
-- and confusing ambiguity in the notation `n • x` when `n : ℕ`.
274
- def nat_semimodule : semimodule ℕ M :=
273
+ def add_comm_monoid. nat_semimodule : semimodule ℕ M :=
275
274
{ smul := nsmul,
276
275
smul_add := λ _ _ _, nsmul_add _ _ _,
277
276
add_smul := λ _ _ _, add_nsmul _ _ _,
@@ -280,44 +279,66 @@ def nat_semimodule : semimodule ℕ M :=
280
279
zero_smul := zero_nsmul,
281
280
smul_zero := nsmul_zero }
282
281
283
- instance : subsingleton (semimodule ℕ M) :=
282
+ section
283
+ local attribute [instance] add_comm_monoid.nat_semimodule
284
+ /-- `nsmul` is defined as the `smul` action of `add_comm_monoid.nat_semimodule`. -/
285
+ lemma nsmul_def (n : ℕ) (x : M) :
286
+ n •ℕ x = n • x :=
287
+ rfl
288
+ end
289
+
290
+ section
291
+ variables (R)
292
+ /-- `nsmul` is equal to any other semimodule structure via a cast. -/
293
+ lemma nsmul_eq_smul_cast (n : ℕ) (b : M) :
294
+ n •ℕ b = (n : R) • b :=
284
295
begin
285
- split,
286
- intros P Q,
287
- ext n,
288
- -- isn't that lovely: `r • m = r • m`
289
- have one_smul : by { haveI := P, exact (1 : ℕ) • m } = by { haveI := Q, exact (1 : ℕ) • m },
290
- begin
291
- rw [@one_smul ℕ _ _ (by { haveI := P, apply_instance, }) m],
292
- rw [@one_smul ℕ _ _ (by { haveI := Q, apply_instance, }) m],
293
- end ,
296
+ rw nsmul_def,
294
297
induction n with n ih,
295
- { erw [zero_smul, zero_smul], },
296
- { rw [nat.succ_eq_add_one, add_smul, add_smul],
297
- erw ih,
298
- rw [one_smul], }
298
+ { rw [nat.cast_zero, zero_smul, zero_smul] },
299
+ { rw [nat.succ_eq_add_one, nat.cast_succ, add_smul, add_smul, one_smul, ih, one_smul] }
299
300
end
301
+ end
302
+
303
+ /-- `nsmul` is equal to any `ℕ`-semimodule structure. -/
304
+ lemma nsmul_eq_smul [semimodule ℕ M] (n : ℕ) (b : M) : n •ℕ b = n • b :=
305
+ by rw [nsmul_eq_smul_cast ℕ, n.cast_id]
306
+
307
+ /-- All `ℕ`-semimodule structures are equal. -/
308
+ instance add_comm_monoid.nat_semimodule.subsingleton : subsingleton (semimodule ℕ M) :=
309
+ ⟨λ P Q, by {
310
+ ext n,
311
+ rw [←nsmul_eq_smul, ←nsmul_eq_smul], }⟩
300
312
301
313
/-- Note this does not depend on the `nat_semimodule` definition above, to avoid issues when
302
314
diamonds occur in finding `semimodule ℕ M` instances. -/
303
- instance nat_is_scalar_tower [semiring S] [ semimodule S M] [semimodule ℕ S ] [semimodule ℕ M] :
304
- is_scalar_tower ℕ S M :=
315
+ instance add_comm_monoid. nat_is_scalar_tower [semimodule ℕ R ] [semimodule ℕ M] :
316
+ is_scalar_tower ℕ R M :=
305
317
{ smul_assoc := λ n x y, nat.rec_on n
306
318
(by simp only [zero_smul])
307
319
(λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ih]) }
308
320
321
+ instance add_comm_monoid.nat_smul_comm_class [semimodule ℕ M] : smul_comm_class ℕ R M :=
322
+ { smul_comm := λ n r m, nat.rec_on n
323
+ (by simp only [zero_smul, smul_zero])
324
+ (λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ←ih, smul_add]) }
325
+
326
+ -- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
327
+ instance add_comm_monoid.nat_smul_comm_class' [semimodule ℕ M] : smul_comm_class R ℕ M :=
328
+ smul_comm_class.symm _ _ _
329
+
309
330
end add_comm_monoid
310
331
311
- namespace add_comm_group
332
+ section add_comm_group
312
333
313
- variables [add_comm_group M]
334
+ variables [semiring S] [ring R] [ add_comm_group M] [semimodule S M] [semimodule R M]
314
335
315
336
/-- The natural ℤ-module structure on any `add_comm_group`. -/
316
337
-- We don't immediately make this a global instance, as it results in too many instances,
317
338
-- and confusing ambiguity in the notation `n • x` when `n : ℤ`.
318
339
-- We do turn it into a global instance, but only at the end of this file,
319
340
-- and I remain dubious whether this is a good idea.
320
- def int_module : module ℤ M :=
341
+ def add_comm_group. int_module : module ℤ M :=
321
342
{ smul := gsmul,
322
343
smul_add := λ _ _ _, gsmul_add _ _ _,
323
344
add_smul := λ _ _ _, add_gsmul _ _ _,
@@ -326,114 +347,53 @@ def int_module : module ℤ M :=
326
347
zero_smul := zero_gsmul,
327
348
smul_zero := gsmul_zero }
328
349
329
- instance : subsingleton (module ℤ M) :=
330
- begin
331
- split,
332
- intros P Q,
333
- ext,
334
- -- isn't that lovely: `r • m = r • m`
335
- have one_smul : by { haveI := P, exact (1 : ℤ) • m } = by { haveI := Q, exact (1 : ℤ) • m },
336
- begin
337
- rw [@one_smul ℤ _ _ (by { haveI := P, apply_instance, }) m],
338
- rw [@one_smul ℤ _ _ (by { haveI := Q, apply_instance, }) m],
339
- end ,
340
- have nat_smul : ∀ n : ℕ, by { haveI := P, exact (n : ℤ) • m } = by { haveI := Q, exact (n : ℤ) • m },
341
- begin
342
- intro n,
343
- induction n with n ih,
344
- { erw [zero_smul, zero_smul], },
345
- { rw [int.coe_nat_succ, add_smul, add_smul],
346
- erw ih,
347
- rw [one_smul], }
348
- end ,
349
- cases r,
350
- { rw [int.of_nat_eq_coe, nat_smul], },
351
- { rw [int.neg_succ_of_nat_coe, neg_smul, neg_smul, nat_smul], }
352
- end
353
-
354
- instance int_is_scalar_tower [ring S] [module S M] [semimodule ℤ S] [semimodule ℤ M] :
355
- is_scalar_tower ℤ S M :=
356
- { smul_assoc := λ n x y, int.induction_on n
357
- (by simp only [zero_smul])
358
- (λ n ih, by simp only [one_smul, add_smul, ih])
359
- (λ n ih, by simp only [one_smul, sub_smul, ih]) }
360
-
361
- end add_comm_group
362
-
363
350
section
364
- local attribute [instance] add_comm_monoid.nat_semimodule
365
-
366
- lemma semimodule.smul_eq_smul (R : Type *) [semiring R]
367
- {M : Type *} [add_comm_monoid M] [semimodule R M]
368
- (n : ℕ) (b : M) : n • b = (n : R) • b :=
369
- begin
370
- induction n with n ih,
371
- { rw [nat.cast_zero, zero_smul, zero_smul] },
372
- { change (n + 1 ) • b = (n + 1 : R) • b,
373
- rw [add_smul, add_smul, one_smul, ih, one_smul] }
374
- end
375
-
376
- lemma semimodule.nsmul_eq_smul (R : Type *) [semiring R]
377
- {M : Type *} [add_comm_monoid M] [semimodule R M] (n : ℕ) (b : M) :
378
- n •ℕ b = (n : R) • b :=
379
- semimodule.smul_eq_smul R n b
380
-
381
- lemma nat.smul_def {M : Type *} [add_comm_monoid M] (n : ℕ) (x : M) :
382
- n • x = n •ℕ x :=
383
- rfl
384
-
351
+ local attribute [instance] add_comm_group.int_module
352
+ /-- `gsmul` is defined as the `smul` action of `add_comm_group.int_module`. -/
353
+ lemma gsmul_def (n : ℤ) (x : M) : gsmul n x = n • x := rfl
385
354
end
386
355
387
- namespace nat
388
-
389
- variables [semiring R] [add_comm_monoid M] [semimodule R M] [semimodule ℕ M]
390
-
391
- instance smul_comm_class : smul_comm_class ℕ R M :=
392
- { smul_comm := λ n r m, nat.rec_on n
393
- (by simp only [zero_smul, smul_zero])
394
- (λ n ih, by simp only [succ_eq_add_one, add_smul, one_smul, ←ih, smul_add]) }
395
-
396
- -- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
397
- instance smul_comm_class' : smul_comm_class R ℕ M := smul_comm_class.symm _ _ _
398
-
399
- end nat
400
-
401
356
section
402
- local attribute [instance] add_comm_group.int_module
403
-
404
- lemma gsmul_eq_smul {M : Type *} [add_comm_group M] (n : ℤ) (x : M) : gsmul n x = n • x := rfl
405
-
406
- lemma module.gsmul_eq_smul_cast (R : Type *) [ring R] {M : Type *} [add_comm_group M] [module R M]
407
- (n : ℤ) (b : M) : gsmul n b = (n : R) • b :=
357
+ variables (R)
358
+ /-- `gsmul` is equal to any other module structure via a cast. -/
359
+ lemma gsmul_eq_smul_cast (n : ℤ) (b : M) : gsmul n b = (n : R) • b :=
408
360
begin
409
- cases n,
410
- { apply semimodule.nsmul_eq_smul, },
411
- { dsimp,
412
- rw semimodule.nsmul_eq_smul R,
413
- push_cast,
414
- rw neg_smul, }
361
+ rw gsmul_def,
362
+ induction n using int.induction_on with p hp n hn,
363
+ { rw [int.cast_zero, zero_smul, zero_smul] },
364
+ { rw [int.cast_add, int.cast_one, add_smul, add_smul, one_smul, one_smul, hp] },
365
+ { rw [int.cast_sub, int.cast_one, sub_smul, sub_smul, one_smul, one_smul, hn] },
415
366
end
416
-
417
367
end
418
368
419
- lemma module.gsmul_eq_smul {M : Type *} [add_comm_group M] [ module ℤ M]
420
- (n : ℤ) (b : M) : gsmul n b = n • b :=
421
- by rw [module. gsmul_eq_smul_cast ℤ, int .cast_id]
369
+ /-- `gsmul` is equal to any `ℤ`- module structure. -/
370
+ lemma gsmul_eq_smul [semimodule ℤ M] (n : ℤ) (b : M) : n •ℤ b = n • b :=
371
+ by rw [gsmul_eq_smul_cast ℤ, n .cast_id]
422
372
423
- namespace int
373
+ /-- All `ℤ`-module structures are equal. -/
374
+ instance add_comm_group.int_module.subsingleton : subsingleton (semimodule ℤ M) :=
375
+ ⟨λ P Q, by {
376
+ ext n,
377
+ rw [←gsmul_eq_smul, ←gsmul_eq_smul], }⟩
424
378
425
- variables [semiring R] [add_comm_group M] [semimodule R M] [semimodule ℤ M]
379
+ instance add_comm_group.int_is_scalar_tower [semimodule ℤ R] [semimodule ℤ M] :
380
+ is_scalar_tower ℤ R M :=
381
+ { smul_assoc := λ n x y, int.induction_on n
382
+ (by simp only [zero_smul])
383
+ (λ n ih, by simp only [one_smul, add_smul, ih])
384
+ (λ n ih, by simp only [one_smul, sub_smul, ih]) }
426
385
427
- instance smul_comm_class : smul_comm_class ℤ R M :=
386
+ instance add_comm_group.int_smul_comm_class [semimodule ℤ M] : smul_comm_class ℤ S M :=
428
387
{ smul_comm := λ n x y, int.induction_on n
429
388
(by simp only [zero_smul, smul_zero])
430
389
(λ n ih, by simp only [one_smul, add_smul, smul_add, ih])
431
390
(λ n ih, by simp only [one_smul, sub_smul, smul_sub, ih]) }
432
391
433
392
-- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
434
- instance smul_comm_class' : smul_comm_class R ℤ M := smul_comm_class.symm _ _ _
393
+ instance add_comm_group.int_smul_comm_class' [semimodule ℤ M] : smul_comm_class S ℤ M :=
394
+ smul_comm_class.symm _ _ _
435
395
436
- end int
396
+ end add_comm_group
437
397
438
398
namespace add_monoid_hom
439
399
@@ -442,18 +402,18 @@ namespace add_monoid_hom
442
402
lemma map_int_module_smul
443
403
[add_comm_group M] [add_comm_group M₂]
444
404
[module ℤ M] [module ℤ M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a :=
445
- by simp only [← module. gsmul_eq_smul, f.map_gsmul]
405
+ by simp only [←gsmul_eq_smul, f.map_gsmul]
446
406
447
407
lemma map_int_cast_smul
448
408
[ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]
449
409
(f : M →+ M₂) (x : ℤ) (a : M) : f ((x : R) • a) = (x : R) • f a :=
450
- by simp only [← module. gsmul_eq_smul_cast, f.map_gsmul]
410
+ by simp only [←gsmul_eq_smul_cast, f.map_gsmul]
451
411
452
412
lemma map_nat_cast_smul
453
413
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
454
414
[semimodule R M] [semimodule R M₂] (f : M →+ M₂) (x : ℕ) (a : M) :
455
415
f ((x : R) • a) = (x : R) • f a :=
456
- by simp only [← semimodule.nsmul_eq_smul , f.map_nsmul]
416
+ by simp only [←nsmul_eq_smul_cast , f.map_nsmul]
457
417
458
418
lemma map_rat_cast_smul {R : Type *} [division_ring R] [char_zero R]
459
419
{E : Type *} [add_comm_group E] [module R E] {F : Type *} [add_comm_group F] [module R F]
@@ -500,29 +460,33 @@ end
500
460
501
461
end add_monoid_hom
502
462
503
- -- We finally turn on these instances globally:
504
- attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module
505
-
506
463
section module_division_ring
507
464
/-! Some tests for the vanishing of elements in modules over division rings. -/
508
465
509
466
variables (R) [division_ring R] [add_comm_group M] [module R M]
510
467
511
- lemma smul_nat_eq_zero [char_zero R] {v : M} {n : ℕ} :
468
+ lemma smul_nat_eq_zero [semimodule ℕ M] [ char_zero R] {v : M} {n : ℕ} :
512
469
n • v = 0 ↔ n = 0 ∨ v = 0 :=
513
- by { rw [semimodule.smul_eq_smul R, smul_eq_zero], simp }
470
+ by { rw [←nsmul_eq_smul, nsmul_eq_smul_cast R, smul_eq_zero], simp }
514
471
515
- lemma eq_zero_of_smul_two_eq_zero [char_zero R] {v : M} (hv : 2 • v = 0 ) : v = 0 :=
472
+ lemma eq_zero_of_smul_two_eq_zero [semimodule ℕ M] [ char_zero R] {v : M} (hv : 2 • v = 0 ) : v = 0 :=
516
473
((smul_nat_eq_zero R).mp hv).resolve_left (by norm_num)
517
474
518
475
lemma eq_zero_of_eq_neg [char_zero R] {v : M} (hv : v = - v) : v = 0 :=
519
476
begin
477
+ -- any semimodule will do
478
+ haveI : semimodule ℕ M := add_comm_monoid.nat_semimodule,
520
479
refine eq_zero_of_smul_two_eq_zero R _,
480
+ rw ←nsmul_eq_smul,
521
481
convert add_eq_zero_iff_eq_neg.mpr hv,
522
482
abel
523
483
end
524
484
525
485
lemma ne_neg_of_ne_zero [char_zero R] {v : R} (hv : v ≠ 0 ) : v ≠ -v :=
526
- λ h, hv (eq_zero_of_eq_neg R h)
486
+ λ h, have semimodule ℕ R := add_comm_monoid.nat_semimodule, by exactI hv (eq_zero_of_eq_neg R h)
527
487
528
488
end module_division_ring
489
+
490
+ -- We finally turn on these instances globally. By doing this here, we ensure that none of the
491
+ -- lemmas about nat semimodules above are specific to these instances.
492
+ attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module
0 commit comments