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

Commit 0929387

Browse files
committed
feat(group_theory/group_action/defs): add ext attributes (#11936)
This adds `ext` attributes to `has_scalar`, `mul_action`, `distrib_mul_action`, `mul_distrib_mul_action`, and `module`. The `ext` and `ext_iff` lemmas were eventually generated by `category_theory/preadditive/schur.lean` anyway - we may as well generate them much earlier. The generated lemmas are slightly uglier than the `module_ext` we already have, but it doesn't really seem worth the trouble of writing out the "nice" versions when the `ext` tactic cleans up the mess for us anyway.
1 parent 007d660 commit 0929387

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

src/algebra/group/defs.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class has_vadd (G : Type*) (P : Type*) := (vadd : G → P → P)
4343
class has_vsub (G : out_param Type*) (P : Type*) := (vsub : P → P → G)
4444

4545
/-- Typeclass for types with a scalar multiplication operation, denoted `•` (`\bu`) -/
46-
@[to_additive has_vadd]
46+
@[ext, to_additive has_vadd]
4747
class has_scalar (M : Type*) (α : Type*) := (smul : M → α → α)
4848

4949
infix ` +ᵥ `:65 := has_vadd.vadd

src/algebra/module/basic.lean

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ variables {R : Type u} {k : Type u'} {S : Type v} {M : Type w} {M₂ : Type x} {
4747
connected by a "scalar multiplication" operation `r • x : M`
4848
(where `r : R` and `x : M`) with some natural associativity and
4949
distributivity axioms similar to those on a ring. -/
50-
@[protect_proj] class module (R : Type u) (M : Type v) [semiring R]
50+
@[ext, protect_proj] class module (R : Type u) (M : Type v) [semiring R]
5151
[add_comm_monoid M] extends distrib_mul_action R M :=
5252
(add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
5353
(zero_smul : ∀x : M, (0 : R) • x = 0)
@@ -212,19 +212,14 @@ by letI := H.to_has_scalar; exact
212212

213213
end add_comm_group
214214

215-
/--
216-
To prove two module structures on a fixed `add_comm_monoid` agree,
217-
it suffices to check the scalar multiplications agree.
218-
-/
215+
/-- A variant of `module.ext` that's convenient for term-mode. -/
219216
-- We'll later use this to show `module ℕ M` and `module ℤ M` are subsingletons.
220-
@[ext]
221-
lemma module_ext {R : Type*} [semiring R] {M : Type*} [add_comm_monoid M] (P Q : module R M)
217+
lemma module.ext' {R : Type*} [semiring R] {M : Type*} [add_comm_monoid M] (P Q : module R M)
222218
(w : ∀ (r : R) (m : M), by { haveI := P, exact r • m } = by { haveI := Q, exact r • m }) :
223219
P = Q :=
224220
begin
225-
unfreezingI { rcases P with ⟨⟨⟨⟨P⟩⟩⟩⟩, rcases Q with ⟨⟨⟨⟨Q⟩⟩⟩⟩ },
226-
obtain rfl : P = Q, by { funext r m, exact w r m },
227-
congr
221+
ext,
222+
exact w _ _
228223
end
229224

230225
section module
@@ -318,7 +313,7 @@ by rw [nsmul_eq_smul_cast ℕ n x, nat.cast_id]
318313
should normally have exactly one `ℕ`-module structure by design. -/
319314
def add_comm_monoid.nat_module.unique : unique (module ℕ M) :=
320315
{ default := by apply_instance,
321-
uniq := λ P, module_ext P _ $ λ n, nat_smul_eq_nsmul P n }
316+
uniq := λ P, module.ext' P _ $ λ n, nat_smul_eq_nsmul P n }
322317

323318
instance add_comm_monoid.nat_is_scalar_tower :
324319
is_scalar_tower ℕ R M :=
@@ -360,7 +355,7 @@ by rw [zsmul_eq_smul_cast ℤ n x, int.cast_id]
360355
should normally have exactly one `ℤ`-module structure by design. -/
361356
def add_comm_group.int_module.unique : unique (module ℤ M) :=
362357
{ default := by apply_instance,
363-
uniq := λ P, module_ext P _ $ λ n, int_smul_eq_zsmul P n }
358+
uniq := λ P, module.ext' P _ $ λ n, int_smul_eq_zsmul P n }
364359

365360
end add_comm_group
366361

@@ -422,7 +417,7 @@ end add_monoid_hom
422417
an instance because `simp` becomes very slow if we have many `subsingleton` instances,
423418
see [gh-6025]. -/
424419
lemma subsingleton_rat_module (E : Type*) [add_comm_group E] : subsingleton (module ℚ E) :=
425-
⟨λ P Q, module_ext P Q $ λ r x,
420+
⟨λ P Q, module.ext' P Q $ λ r x,
426421
@add_monoid_hom.map_rat_module_smul E ‹_› P E ‹_› Q (add_monoid_hom.id _) r x⟩
427422

428423
/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications

src/category_theory/preadditive/schur.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ variables [is_alg_closed 𝕜] [linear 𝕜 C]
8787
-- These are definitionally equal, but without eta reduction Lean can't see this.
8888
-- To get around this, we use `convert I`,
8989
-- then check the various instances agree field-by-field,
90-
-- using `ext` equipped with the following extra lemmas:
91-
local attribute [ext] module distrib_mul_action mul_action has_scalar
9290

9391
/--
9492
An auxiliary lemma for Schur's lemma.

src/group_theory/group_action/defs.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ instance has_mul.to_has_scalar (α : Type*) [has_mul α] : has_scalar α α :=
7676
@[simp, to_additive] lemma smul_eq_mul (α : Type*) [has_mul α] {a a' : α} : a • a' = a * a' := rfl
7777

7878
/-- Type class for additive monoid actions. -/
79-
@[protect_proj] class add_action (G : Type*) (P : Type*) [add_monoid G] extends has_vadd G P :=
79+
@[ext, protect_proj] class add_action (G : Type*) (P : Type*) [add_monoid G] extends has_vadd G P :=
8080
(zero_vadd : ∀ p : P, (0 : G) +ᵥ p = p)
8181
(add_vadd : ∀ (g₁ g₂ : G) (p : P), (g₁ + g₂) +ᵥ p = g₁ +ᵥ (g₂ +ᵥ p))
8282

8383
/-- Typeclass for multiplicative actions by monoids. This generalizes group actions. -/
84-
@[protect_proj, to_additive]
84+
@[ext, protect_proj, to_additive]
8585
class mul_action (α : Type*) (β : Type*) [monoid α] extends has_scalar α β :=
8686
(one_smul : ∀ b : β, (1 : α) • b = b)
8787
(mul_smul : ∀ (x y : α) (b : β), (x * y) • b = x • y • b)
@@ -452,7 +452,7 @@ lemma is_scalar_tower.of_smul_one_mul {M N} [monoid N] [has_scalar M N]
452452
end compatible_scalar
453453

454454
/-- Typeclass for multiplicative actions on additive structures. This generalizes group modules. -/
455-
class distrib_mul_action (M : Type*) (A : Type*) [monoid M] [add_monoid A]
455+
@[ext] class distrib_mul_action (M : Type*) (A : Type*) [monoid M] [add_monoid A]
456456
extends mul_action M A :=
457457
(smul_add : ∀(r : M) (x y : A), r • (x + y) = r • x + r • y)
458458
(smul_zero : ∀(r : M), r • (0 : A) = 0)
@@ -547,7 +547,7 @@ end
547547

548548
/-- Typeclass for multiplicative actions on multiplicative structures. This generalizes
549549
conjugation actions. -/
550-
class mul_distrib_mul_action (M : Type*) (A : Type*) [monoid M] [monoid A]
550+
@[ext] class mul_distrib_mul_action (M : Type*) (A : Type*) [monoid M] [monoid A]
551551
extends mul_action M A :=
552552
(smul_mul : ∀ (r : M) (x y : A), r • (x * y) = (r • x) * (r • y))
553553
(smul_one : ∀ (r : M), r • (1 : A) = 1)

src/number_theory/number_field.lean

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,16 @@ namespace rat
107107

108108
open number_field
109109

110+
local attribute [instance] subsingleton_rat_module
111+
110112
instance rat.number_field : number_field ℚ :=
111113
{ to_char_zero := infer_instance,
112-
to_finite_dimensional := by { convert (infer_instance : finite_dimensional ℚ ℚ),
113-
-- The vector space structure of `ℚ` over itself can arise in multiple ways:
114-
-- all fields are vector spaces over themselves (used in `rat.finite_dimensional`)
115-
-- all char 0 fields have a canonical embedding of `ℚ` (used in `number_field`).
116-
-- Show that these coincide:
117-
ext1, simp [algebra.smul_def] } }
114+
to_finite_dimensional :=
115+
-- The vector space structure of `ℚ` over itself can arise in multiple ways:
116+
-- all fields are vector spaces over themselves (used in `rat.finite_dimensional`)
117+
-- all char 0 fields have a canonical embedding of `ℚ` (used in `number_field`).
118+
-- Show that these coincide:
119+
by convert (infer_instance : finite_dimensional ℚ ℚ), }
118120

119121
/-- The ring of integers of `ℚ` as a number field is just `ℤ`. -/
120122
noncomputable def ring_of_integers_equiv : ring_of_integers ℚ ≃+* ℤ :=

0 commit comments

Comments
 (0)