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

Commit 30413fc

Browse files
chore(algebra): generalize typeclass arguments from field to semifield (#18597)
This generalizes some typeclass arguments from `field` to `semifield` and `division_ring` to `division_semiring`. The proof for `map_inv_nat_cast_smul` had to be rewritten, as it was previously proved in terms of `map_inv_int_cast_smul`. The latter is now instead proved in terms of the former. Forward-ported in leanprover-community/mathlib4#2926 Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
1 parent 13e18cf commit 30413fc

7 files changed

Lines changed: 65 additions & 54 deletions

File tree

src/algebra/module/basic.lean

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -381,27 +381,32 @@ lemma map_nat_cast_smul [add_comm_monoid M] [add_comm_monoid M₂] {F : Type*}
381381
f ((x : R) • a) = (x : S) • f a :=
382382
by simp only [←nsmul_eq_smul_cast, map_nsmul]
383383

384-
lemma map_inv_int_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
384+
lemma map_inv_nat_cast_smul [add_comm_monoid M] [add_comm_monoid M₂] {F : Type*}
385385
[add_monoid_hom_class F M M₂] (f : F)
386-
(R S : Type*) [division_ring R] [division_ring S] [module R M] [module S M₂]
387-
(n : ) (x : M) :
386+
(R S : Type*) [division_semiring R] [division_semiring S] [module R M] [module S M₂]
387+
(n : ) (x : M) :
388388
f ((n⁻¹ : R) • x) = (n⁻¹ : S) • f x :=
389389
begin
390390
by_cases hR : (n : R) = 0; by_cases hS : (n : S) = 0,
391391
{ simp [hR, hS] },
392392
{ suffices : ∀ y, f y = 0, by simp [this], clear x, intro x,
393-
rw [← inv_smul_smul₀ hS (f x), ← map_int_cast_smul f R S], simp [hR] },
393+
rw [← inv_smul_smul₀ hS (f x), ← map_nat_cast_smul f R S], simp [hR] },
394394
{ suffices : ∀ y, f y = 0, by simp [this], clear x, intro x,
395-
rw [← smul_inv_smul₀ hR x, map_int_cast_smul f R S, hS, zero_smul] },
396-
{ rw [← inv_smul_smul₀ hS (f _), ← map_int_cast_smul f R S, smul_inv_smul₀ hR] }
395+
rw [← smul_inv_smul₀ hR x, map_nat_cast_smul f R S, hS, zero_smul] },
396+
{ rw [← inv_smul_smul₀ hS (f _), ← map_nat_cast_smul f R S, smul_inv_smul₀ hR] }
397397
end
398398

399-
lemma map_inv_nat_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
399+
lemma map_inv_int_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
400400
[add_monoid_hom_class F M M₂] (f : F)
401401
(R S : Type*) [division_ring R] [division_ring S] [module R M] [module S M₂]
402-
(n : ℕ) (x : M) :
403-
f ((n⁻¹ : R) • x) = (n⁻¹ : S) • f x :=
404-
by exact_mod_cast map_inv_int_cast_smul f R S n x
402+
(z : ℤ) (x : M) :
403+
f ((z⁻¹ : R) • x) = (z⁻¹ : S) • f x :=
404+
begin
405+
obtain ⟨n, rfl | rfl⟩ := z.eq_coe_or_neg,
406+
{ rw [int.cast_coe_nat, int.cast_coe_nat, map_inv_nat_cast_smul _ R S] },
407+
{ simp_rw [int.cast_neg, int.cast_coe_nat, inv_neg, neg_smul, map_neg,
408+
map_inv_nat_cast_smul _ R S] },
409+
end
405410

406411
lemma map_rat_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
407412
[add_monoid_hom_class F M M₂] (f : F)
@@ -421,34 +426,34 @@ instance subsingleton_rat_module (E : Type*) [add_comm_group E] : subsingleton (
421426
⟨λ P Q, module.ext' P Q $ λ r x,
422427
@map_rat_smul _ _ _ _ P Q _ _ (add_monoid_hom.id E) r x⟩
423428

429+
/-- If `E` is a vector space over two division semirings `R` and `S`, then scalar multiplications
430+
agree on inverses of natural numbers in `R` and `S`. -/
431+
lemma inv_nat_cast_smul_eq {E : Type*} (R S : Type*) [add_comm_monoid E] [division_semiring R]
432+
[division_semiring S] [module R E] [module S E] (n : ℕ) (x : E) :
433+
(n⁻¹ : R) • x = (n⁻¹ : S) • x :=
434+
map_inv_nat_cast_smul (add_monoid_hom.id E) R S n x
435+
424436
/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications
425437
agree on inverses of integer numbers in `R` and `S`. -/
426438
lemma inv_int_cast_smul_eq {E : Type*} (R S : Type*) [add_comm_group E] [division_ring R]
427439
[division_ring S] [module R E] [module S E] (n : ℤ) (x : E) :
428440
(n⁻¹ : R) • x = (n⁻¹ : S) • x :=
429441
map_inv_int_cast_smul (add_monoid_hom.id E) R S n x
430442

431-
/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications
432-
agree on inverses of natural numbers in `R` and `S`. -/
433-
lemma inv_nat_cast_smul_eq {E : Type*} (R S : Type*) [add_comm_group E] [division_ring R]
434-
[division_ring S] [module R E] [module S E] (n : ℕ) (x : E) :
435-
(n⁻¹ : R) • x = (n⁻¹ : S) • x :=
436-
map_inv_nat_cast_smul (add_monoid_hom.id E) R S n x
443+
/-- If `E` is a vector space over a division ring `R` and has a monoid action by `α`, then that
444+
action commutes by scalar multiplication of inverses of natural numbers in `R`. -/
445+
lemma inv_nat_cast_smul_commE : Type*} (R : Type*) [add_comm_monoid E] [division_semiring R]
446+
[monoid α] [module R E] [distrib_mul_action α E] (n : ℕ) (s : α) (x : E) :
447+
(n⁻¹ : R) • s • x = s • (n⁻¹ : R) • x :=
448+
(map_inv_nat_cast_smul (distrib_mul_action.to_add_monoid_hom E s) R R n x).symm
437449

438-
/-- If `E` is a vector space over a division rings `R` and has a monoid action by `α`, then that
450+
/-- If `E` is a vector space over a division ring `R` and has a monoid action by `α`, then that
439451
action commutes by scalar multiplication of inverses of integers in `R` -/
440452
lemma inv_int_cast_smul_comm {α E : Type*} (R : Type*) [add_comm_group E] [division_ring R]
441453
[monoid α] [module R E] [distrib_mul_action α E] (n : ℤ) (s : α) (x : E) :
442454
(n⁻¹ : R) • s • x = s • (n⁻¹ : R) • x :=
443455
(map_inv_int_cast_smul (distrib_mul_action.to_add_monoid_hom E s) R R n x).symm
444456

445-
/-- If `E` is a vector space over a division rings `R` and has a monoid action by `α`, then that
446-
action commutes by scalar multiplication of inverses of natural numbers in `R`. -/
447-
lemma inv_nat_cast_smul_comm {α E : Type*} (R : Type*) [add_comm_group E] [division_ring R]
448-
[monoid α] [module R E] [distrib_mul_action α E] (n : ℕ) (s : α) (x : E) :
449-
(n⁻¹ : R) • s • x = s • (n⁻¹ : R) • x :=
450-
(map_inv_nat_cast_smul (distrib_mul_action.to_add_monoid_hom E s) R R n x).symm
451-
452457
/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications
453458
agree on rational numbers in `R` and `S`. -/
454459
lemma rat_cast_smul_eq {E : Type*} (R S : Type*) [add_comm_group E] [division_ring R]

src/algebra/periodic.lean

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected lemma periodic.const_smul [add_monoid α] [group γ] [distrib_mul_acti
103103
periodic (λ x, f (a • x)) (a⁻¹ • c) :=
104104
λ x, by simpa only [smul_add, smul_inv_smul] using h (a • x)
105105

106-
lemma periodic.const_smul₀ [add_comm_monoid α] [division_ring γ] [module γ α]
106+
lemma periodic.const_smul₀ [add_comm_monoid α] [division_semiring γ] [module γ α]
107107
(h : periodic f c) (a : γ) :
108108
periodic (λ x, f (a • x)) (a⁻¹ • c) :=
109109
begin
@@ -112,7 +112,7 @@ begin
112112
simpa only [smul_add, smul_inv_smul₀ ha] using h (a • x),
113113
end
114114

115-
protected lemma periodic.const_mul [division_ring α] (h : periodic f c) (a : α) :
115+
protected lemma periodic.const_mul [division_semiring α] (h : periodic f c) (a : α) :
116116
periodic (λ x, f (a * x)) (a⁻¹ * c) :=
117117
h.const_smul₀ a
118118

@@ -121,29 +121,29 @@ lemma periodic.const_inv_smul [add_monoid α] [group γ] [distrib_mul_action γ
121121
periodic (λ x, f (a⁻¹ • x)) (a • c) :=
122122
by simpa only [inv_inv] using h.const_smul a⁻¹
123123

124-
lemma periodic.const_inv_smul₀ [add_comm_monoid α] [division_ring γ] [module γ α]
124+
lemma periodic.const_inv_smul₀ [add_comm_monoid α] [division_semiring γ] [module γ α]
125125
(h : periodic f c) (a : γ) :
126126
periodic (λ x, f (a⁻¹ • x)) (a • c) :=
127127
by simpa only [inv_inv] using h.const_smul₀ a⁻¹
128128

129-
lemma periodic.const_inv_mul [division_ring α] (h : periodic f c) (a : α) :
129+
lemma periodic.const_inv_mul [division_semiring α] (h : periodic f c) (a : α) :
130130
periodic (λ x, f (a⁻¹ * x)) (a * c) :=
131131
h.const_inv_smul₀ a
132132

133-
lemma periodic.mul_const [division_ring α] (h : periodic f c) (a : α) :
133+
lemma periodic.mul_const [division_semiring α] (h : periodic f c) (a : α) :
134134
periodic (λ x, f (x * a)) (c * a⁻¹) :=
135135
h.const_smul₀ $ mul_opposite.op a
136136

137-
lemma periodic.mul_const' [division_ring α]
137+
lemma periodic.mul_const' [division_semiring α]
138138
(h : periodic f c) (a : α) :
139139
periodic (λ x, f (x * a)) (c / a) :=
140140
by simpa only [div_eq_mul_inv] using h.mul_const a
141141

142-
lemma periodic.mul_const_inv [division_ring α] (h : periodic f c) (a : α) :
142+
lemma periodic.mul_const_inv [division_semiring α] (h : periodic f c) (a : α) :
143143
periodic (λ x, f (x * a⁻¹)) (c * a) :=
144144
h.const_inv_smul₀ $ mul_opposite.op a
145145

146-
lemma periodic.div_const [division_ring α] (h : periodic f c) (a : α) :
146+
lemma periodic.div_const [division_semiring α] (h : periodic f c) (a : α) :
147147
periodic (λ x, f (x / a)) (c * a) :=
148148
by simpa only [div_eq_mul_inv] using h.mul_const_inv a
149149

@@ -425,12 +425,12 @@ lemma antiperiodic.const_smul [add_monoid α] [has_neg β] [group γ] [distrib_m
425425
antiperiodic (λ x, f (a • x)) (a⁻¹ • c) :=
426426
λ x, by simpa only [smul_add, smul_inv_smul] using h (a • x)
427427

428-
lemma antiperiodic.const_smul₀ [add_comm_monoid α] [has_neg β] [division_ring γ] [module γ α]
428+
lemma antiperiodic.const_smul₀ [add_comm_monoid α] [has_neg β] [division_semiring γ] [module γ α]
429429
(h : antiperiodic f c) {a : γ} (ha : a ≠ 0) :
430430
antiperiodic (λ x, f (a • x)) (a⁻¹ • c) :=
431431
λ x, by simpa only [smul_add, smul_inv_smul₀ ha] using h (a • x)
432432

433-
lemma antiperiodic.const_mul [division_ring α] [has_neg β]
433+
lemma antiperiodic.const_mul [division_semiring α] [has_neg β]
434434
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
435435
antiperiodic (λ x, f (a * x)) (a⁻¹ * c) :=
436436
h.const_smul₀ ha
@@ -440,32 +440,33 @@ lemma antiperiodic.const_inv_smul [add_monoid α] [has_neg β] [group γ] [distr
440440
antiperiodic (λ x, f (a⁻¹ • x)) (a • c) :=
441441
by simpa only [inv_inv] using h.const_smul a⁻¹
442442

443-
lemma antiperiodic.const_inv_smul₀ [add_comm_monoid α] [has_neg β] [division_ring γ] [module γ α]
443+
lemma antiperiodic.const_inv_smul₀
444+
[add_comm_monoid α] [has_neg β] [division_semiring γ] [module γ α]
444445
(h : antiperiodic f c) {a : γ} (ha : a ≠ 0) :
445446
antiperiodic (λ x, f (a⁻¹ • x)) (a • c) :=
446447
by simpa only [inv_inv] using h.const_smul₀ (inv_ne_zero ha)
447448

448-
lemma antiperiodic.const_inv_mul [division_ring α] [has_neg β]
449+
lemma antiperiodic.const_inv_mul [division_semiring α] [has_neg β]
449450
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
450451
antiperiodic (λ x, f (a⁻¹ * x)) (a * c) :=
451452
h.const_inv_smul₀ ha
452453

453-
lemma antiperiodic.mul_const [division_ring α] [has_neg β]
454+
lemma antiperiodic.mul_const [division_semiring α] [has_neg β]
454455
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
455456
antiperiodic (λ x, f (x * a)) (c * a⁻¹) :=
456457
h.const_smul₀ $ (mul_opposite.op_ne_zero_iff a).mpr ha
457458

458-
lemma antiperiodic.mul_const' [division_ring α] [has_neg β]
459+
lemma antiperiodic.mul_const' [division_semiring α] [has_neg β]
459460
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
460461
antiperiodic (λ x, f (x * a)) (c / a) :=
461462
by simpa only [div_eq_mul_inv] using h.mul_const ha
462463

463-
lemma antiperiodic.mul_const_inv [division_ring α] [has_neg β]
464+
lemma antiperiodic.mul_const_inv [division_semiring α] [has_neg β]
464465
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
465466
antiperiodic (λ x, f (x * a⁻¹)) (c * a) :=
466467
h.const_inv_smul₀ $ (mul_opposite.op_ne_zero_iff a).mpr ha
467468

468-
protected lemma antiperiodic.div_inv [division_ring α] [has_neg β]
469+
protected lemma antiperiodic.div_inv [division_semiring α] [has_neg β]
469470
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
470471
antiperiodic (λ x, f (x / a)) (c * a) :=
471472
by simpa only [div_eq_mul_inv] using h.mul_const_inv ha

src/algebra/star/basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,15 @@ lemma ring_hom.star_apply {S : Type*} [non_assoc_semiring S] [comm_semiring R] [
310310
alias star_ring_end_self_apply ← complex.conj_conj
311311
alias star_ring_end_self_apply ← is_R_or_C.conj_conj
312312

313-
@[simp] lemma star_inv' [division_ring R] [star_ring R] (x : R) : star (x⁻¹) = (star x)⁻¹ :=
313+
@[simp] lemma star_inv' [division_semiring R] [star_ring R] (x : R) : star (x⁻¹) = (star x)⁻¹ :=
314314
op_injective $ (map_inv₀ (star_ring_equiv : R ≃+* Rᵐᵒᵖ) x).trans (op_inv (star x)).symm
315315

316-
@[simp] lemma star_zpow₀ [division_ring R] [star_ring R] (x : R) (z : ℤ) :
316+
@[simp] lemma star_zpow₀ [division_semiring R] [star_ring R] (x : R) (z : ℤ) :
317317
star (x ^ z) = star x ^ z :=
318318
op_injective $ (map_zpow₀ (star_ring_equiv : R ≃+* Rᵐᵒᵖ) x z).trans (op_zpow (star x) z).symm
319319

320320
/-- When multiplication is commutative, `star` preserves division. -/
321-
@[simp] lemma star_div' [field R] [star_ring R] (x y : R) : star (x / y) = star x / star y :=
321+
@[simp] lemma star_div' [semifield R] [star_ring R] (x y : R) : star (x / y) = star x / star y :=
322322
map_div₀ (star_ring_end R) _ _
323323

324324
@[simp] lemma star_bit0 [add_monoid R] [star_add_monoid R] (r : R) :

src/algebra/star/module.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ This file also provides some lemmas that need `algebra.module.basic` imported to
3333
section smul_lemmas
3434
variables {R M : Type*}
3535

36+
@[simp] lemma star_nat_cast_smul [semiring R] [add_comm_monoid M] [module R M] [star_add_monoid M]
37+
(n : ℕ) (x : M) : star ((n : R) • x) = (n : R) • star x :=
38+
map_nat_cast_smul (star_add_equiv : M ≃+ M) R R n x
39+
3640
@[simp] lemma star_int_cast_smul [ring R] [add_comm_group M] [module R M] [star_add_monoid M]
3741
(n : ℤ) (x : M) : star ((n : R) • x) = (n : R) • star x :=
3842
map_int_cast_smul (star_add_equiv : M ≃+ M) R R n x
3943

40-
@[simp] lemma star_nat_cast_smul [semiring R] [add_comm_monoid M] [module R M] [star_add_monoid M]
41-
(n : ℕ) (x : M) : star ((n : R) • x) = (n : R) • star x :=
42-
map_nat_cast_smul (star_add_equiv : M ≃+ M) R R n x
44+
@[simp] lemma star_inv_nat_cast_smul [division_semiring R] [add_comm_monoid M] [module R M]
45+
[star_add_monoid M] (n : ℕ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x :=
46+
map_inv_nat_cast_smul (star_add_equiv : M ≃+ M) R R n x
4347

4448
@[simp] lemma star_inv_int_cast_smul [division_ring R] [add_comm_group M] [module R M]
4549
[star_add_monoid M] (n : ℤ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x :=
4650
map_inv_int_cast_smul (star_add_equiv : M ≃+ M) R R n x
4751

48-
@[simp] lemma star_inv_nat_cast_smul [division_ring R] [add_comm_group M] [module R M]
49-
[star_add_monoid M] (n : ℕ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x :=
50-
map_inv_nat_cast_smul (star_add_equiv : M ≃+ M) R R n x
51-
5252
@[simp] lemma star_rat_cast_smul [division_ring R] [add_comm_group M] [module R M]
5353
[star_add_monoid M] (n : ℚ) (x : M) : star ((n : R) • x) = (n : R) • star x :=
5454
map_rat_cast_smul (star_add_equiv : M ≃+ M) _ _ _ x

src/algebra/star/pointwise.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ instance [has_star α] [has_trivial_star α] : has_trivial_star (set α) :=
117117
protected lemma star_inv [group α] [star_semigroup α] (s : set α) : (s⁻¹)⋆ = (s⋆)⁻¹ :=
118118
by { ext, simp only [mem_star, mem_inv, star_inv] }
119119

120-
protected lemma star_inv' [division_ring α] [star_ring α] (s : set α) : (s⁻¹)⋆ = (s⋆)⁻¹ :=
120+
protected lemma star_inv' [division_semiring α] [star_ring α] (s : set α) : (s⁻¹)⋆ = (s⋆)⁻¹ :=
121121
by { ext, simp only [mem_star, mem_inv, star_inv'] }
122122

123123
end set

src/algebra/star/self_adjoint.lean

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,20 @@ star_int_cast _
166166

167167
end ring
168168

169-
section division_ring
170-
variables [division_ring R] [star_ring R]
169+
section division_semiring
170+
variables [division_semiring R] [star_ring R]
171171

172172
lemma inv {x : R} (hx : is_self_adjoint x) : is_self_adjoint x⁻¹ :=
173173
by simp only [is_self_adjoint_iff, star_inv', hx.star_eq]
174174

175175
lemma zpow {x : R} (hx : is_self_adjoint x) (n : ℤ) : is_self_adjoint (x ^ n):=
176176
by simp only [is_self_adjoint_iff, star_zpow₀, hx.star_eq]
177177

178+
end division_semiring
179+
180+
section division_ring
181+
variables [division_ring R] [star_ring R]
182+
178183
lemma _root_.is_self_adjoint_rat_cast (x : ℚ) : is_self_adjoint (x : R) :=
179184
star_rat_cast _
180185

src/data/matrix/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ matrix.ext $ by simp
15371537
[star_add_monoid α] [module R α] (c : ℤ) (M : matrix m n α) : ((c : R) • M)ᴴ = (c : R) • Mᴴ :=
15381538
matrix.ext $ by simp
15391539

1540-
@[simp] lemma conj_transpose_inv_nat_cast_smul [division_ring R] [add_comm_group α]
1540+
@[simp] lemma conj_transpose_inv_nat_cast_smul [division_semiring R] [add_comm_monoid α]
15411541
[star_add_monoid α] [module R α] (c : ℕ) (M : matrix m n α) : ((c : R)⁻¹ • M)ᴴ = (c : R)⁻¹ • Mᴴ :=
15421542
matrix.ext $ by simp
15431543

0 commit comments

Comments
 (0)