Skip to content

Commit 907572f

Browse files
astrainfinitaBeibeiX0
authored andcommitted
chore: remove MulAction ℚ α → MulAction ℚ≥0 α instances (leanprover-community#30671)
This fixes the instances diamond in the `NNRat` action.
1 parent 563f45c commit 907572f

4 files changed

Lines changed: 25 additions & 54 deletions

File tree

Mathlib/Algebra/Algebra/Rat.lean

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Kenny Lau, Yury Kudryashov
55
-/
66
import Mathlib.Algebra.Algebra.Defs
7-
import Mathlib.Algebra.GroupWithZero.Action.Basic
87
import Mathlib.Algebra.Module.Equiv.Defs
98
import Mathlib.Data.Rat.Cast.CharZero
109

@@ -28,24 +27,7 @@ theorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra
2827
end RingHom
2928

3029
namespace NNRat
31-
variable [DivisionSemiring R] [CharZero R]
32-
33-
section Semiring
34-
variable [Semiring S] [Module ℚ≥0 S]
35-
36-
variable (R) in
37-
/-- `nnqsmul` is equal to any other module structure via a cast. -/
38-
lemma cast_smul_eq_nnqsmul [Module R S] (q : ℚ≥0) (a : S) : (q : R) • a = q • a := by
39-
refine MulAction.injective₀ (G₀ := ℚ≥0) (Nat.cast_ne_zero.2 q.den_pos.ne') ?_
40-
dsimp
41-
rw [← mul_smul, den_mul_eq_num, Nat.cast_smul_eq_nsmul, Nat.cast_smul_eq_nsmul, ← smul_assoc,
42-
nsmul_eq_mul q.den, ← cast_natCast, ← cast_mul, den_mul_eq_num, cast_natCast,
43-
Nat.cast_smul_eq_nsmul]
44-
45-
end Semiring
46-
47-
section DivisionSemiring
48-
variable [DivisionSemiring S] [CharZero S]
30+
variable [DivisionSemiring R] [CharZero R] [DivisionSemiring S] [CharZero S]
4931

5032
instance _root_.DivisionSemiring.toNNRatAlgebra : Algebra ℚ≥0 R where
5133
smul_def' := smul_def
@@ -64,28 +46,10 @@ instance instSMulCommClass [SMulCommClass R S S] : SMulCommClass ℚ≥0 R S whe
6446
instance instSMulCommClass' [SMulCommClass S R S] : SMulCommClass R ℚ≥0 S :=
6547
have := SMulCommClass.symm S R S; SMulCommClass.symm _ _ _
6648

67-
end DivisionSemiring
6849
end NNRat
6950

7051
namespace Rat
71-
variable [DivisionRing R] [CharZero R]
72-
73-
section Ring
74-
variable [Ring S] [Module ℚ S]
75-
76-
variable (R) in
77-
/-- `qsmul` is equal to any other module structure via a cast. -/
78-
lemma cast_smul_eq_qsmul [Module R S] (q : ℚ) (a : S) : (q : R) • a = q • a := by
79-
refine MulAction.injective₀ (G₀ := ℚ) (Nat.cast_ne_zero.2 q.den_pos.ne') ?_
80-
dsimp
81-
rw [← mul_smul, den_mul_eq_num, Nat.cast_smul_eq_nsmul, Int.cast_smul_eq_zsmul, ← smul_assoc,
82-
nsmul_eq_mul q.den, ← cast_natCast, ← cast_mul, den_mul_eq_num, cast_intCast,
83-
Int.cast_smul_eq_zsmul]
84-
85-
end Ring
86-
87-
section DivisionRing
88-
variable [DivisionRing S] [CharZero S]
52+
variable [DivisionRing R] [CharZero R] [DivisionRing S] [CharZero S]
8953

9054
instance _root_.DivisionRing.toRatAlgebra : Algebra ℚ R where
9155
smul_def' := smul_def
@@ -108,8 +72,6 @@ instance instSMulCommClass [SMulCommClass R S S] : SMulCommClass ℚ R S where
10872
instance instSMulCommClass' [SMulCommClass S R S] : SMulCommClass R ℚ S :=
10973
have := SMulCommClass.symm S R S; SMulCommClass.symm _ _ _
11074

111-
end DivisionRing
112-
11375
instance algebra_rat_subsingleton {R} [Semiring R] : Subsingleton (Algebra ℚ R) :=
11476
fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩
11577

Mathlib/Algebra/Module/Rat.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ instance IsScalarTower.rat {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [
7171
[Module ℚ R] [Module ℚ M] : IsScalarTower ℚ R M where
7272
smul_assoc r x y := map_rat_smul ((smulAddHom R M).flip y) r x
7373

74+
/-- `nnqsmul` is equal to any other module structure via a cast. -/
75+
lemma NNRat.cast_smul_eq_nnqsmul (R : Type*) [DivisionSemiring R]
76+
[MulAction R M] [MulAction ℚ≥0 M] [IsScalarTower ℚ≥0 R M]
77+
(q : ℚ≥0) (x : M) : (q : R) • x = q • x := by
78+
rw [← one_smul R x, ← smul_assoc, ← smul_assoc]; simp
79+
80+
/-- `qsmul` is equal to any other module structure via a cast. -/
81+
lemma Rat.cast_smul_eq_qsmul (R : Type*) [DivisionRing R]
82+
[MulAction R M] [MulAction ℚ M] [IsScalarTower ℚ R M]
83+
(q : ℚ) (x : M) : (q : R) • x = q • x := by
84+
rw [← one_smul R x, ← smul_assoc, ← smul_assoc]; simp
85+
7486
section
7587
variable {α : Type u} {M : Type v}
7688

Mathlib/Algebra/Order/Module/Rat.lean

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Copyright (c) 2024 Yaël Dillies. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Yaël Dillies
55
-/
6+
import Mathlib.Algebra.Module.Rat
67
import Mathlib.Algebra.Order.Module.Basic
7-
import Mathlib.Data.NNRat.Lemmas
88
import Mathlib.Data.Rat.Cast.Order
99

1010
/-!
@@ -13,13 +13,19 @@ import Mathlib.Data.Rat.Cast.Order
1313

1414
variable {α : Type*}
1515

16-
instance PosSMulMono.nnrat_of_rat [Preorder α] [MulAction ℚ α] [PosSMulMono ℚ α] :
16+
instance PosSMulMono.nnrat_of_rat [Preorder α] [MulAction ℚ α] [MulAction ℚ≥0 α]
17+
[IsScalarTower ℚ≥0 ℚ α] [PosSMulMono ℚ α] :
1718
PosSMulMono ℚ≥0 α where
18-
smul_le_smul_of_nonneg_left _q hq _a₁ _a₂ ha := smul_le_smul_of_nonneg_left (α := ℚ) ha hq
19+
smul_le_smul_of_nonneg_left _q hq _a₁ _a₂ ha := by
20+
rw [← NNRat.cast_smul_eq_nnqsmul ℚ, ← NNRat.cast_smul_eq_nnqsmul ℚ]
21+
exact smul_le_smul_of_nonneg_left (α := ℚ) ha hq
1922

20-
instance PosSMulStrictMono.nnrat_of_rat [Preorder α] [MulAction ℚ α] [PosSMulStrictMono ℚ α] :
23+
instance PosSMulStrictMono.nnrat_of_rat [Preorder α] [MulAction ℚ≥0 α] [MulAction ℚ α]
24+
[IsScalarTower ℚ≥0 ℚ α] [PosSMulStrictMono ℚ α] :
2125
PosSMulStrictMono ℚ≥0 α where
22-
smul_lt_smul_of_pos_left _q hq _a₁ _a₂ ha := smul_lt_smul_of_pos_left (α := ℚ) ha hq
26+
smul_lt_smul_of_pos_left _q hq _a₁ _a₂ ha := by
27+
rw [← NNRat.cast_smul_eq_nnqsmul ℚ, ← NNRat.cast_smul_eq_nnqsmul ℚ]
28+
exact smul_lt_smul_of_pos_left (α := ℚ) ha hq
2329

2430
section LinearOrderedAddCommGroup
2531
variable [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]

Mathlib/Data/NNRat/Lemmas.lean

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Authors: Yaël Dillies, Bhavik Mehta
55
-/
66
import Mathlib.Algebra.Field.Rat
77
import Mathlib.Algebra.Group.Indicator
8-
import Mathlib.Algebra.GroupWithZero.Action.End
98
import Mathlib.Algebra.Order.Field.Rat
109
import Mathlib.Data.Rat.Lemmas
1110
import Mathlib.Tactic.Zify
@@ -23,14 +22,6 @@ open scoped NNRat
2322
namespace NNRat
2423
variable {α : Type*} {q : ℚ≥0}
2524

26-
/-- A `MulAction` over `ℚ` restricts to a `MulAction` over `ℚ≥0`. -/
27-
instance [MulAction ℚ α] : MulAction ℚ≥0 α :=
28-
MulAction.compHom α coeHom.toMonoidHom
29-
30-
/-- A `DistribMulAction` over `ℚ` restricts to a `DistribMulAction` over `ℚ≥0`. -/
31-
instance [AddCommMonoid α] [DistribMulAction ℚ α] : DistribMulAction ℚ≥0 α :=
32-
DistribMulAction.compHom α coeHom.toMonoidHom
33-
3425
@[simp, norm_cast]
3526
lemma coe_indicator (s : Set α) (f : α → ℚ≥0) (a : α) :
3627
((s.indicator f a : ℚ≥0) : ℚ) = s.indicator (fun x ↦ ↑(f x)) a :=

0 commit comments

Comments
 (0)