Skip to content

Commit 14151c7

Browse files
committed
refactor(Data/Rat/NNRat): move module and algebra instances (#9951)
As with #9950, this is motivated by: * Getting `NNRat` closed to `norm_num` * Being able to put an `nnrat_cast` field in `DivisionSemiring`s This brings down the number of dependencies of `NNRat` by around 600.
1 parent 9bd968e commit 14151c7

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

Mathlib/Algebra/Algebra/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ instance algebraRat {α} [DivisionRing α] [CharZero α] : Algebra ℚ α where
722722
commutes' := Rat.cast_commute
723723
#align algebra_rat algebraRat
724724

725+
/-- The rational numbers are an algebra over the non-negative rationals. -/
726+
instance : Algebra NNRat ℚ :=
727+
NNRat.coeHom.toAlgebra
728+
725729
/-- The two `Algebra ℚ ℚ` instances should coincide. -/
726730
example : algebraRat = Algebra.id ℚ :=
727731
rfl

Mathlib/Algebra/Module/Basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
55
-/
66
import Mathlib.Algebra.Function.Indicator
77
import Mathlib.Algebra.SMulWithZero
8+
import Mathlib.Data.Rat.NNRat
89
import Mathlib.GroupTheory.GroupAction.Group
910
import Mathlib.GroupTheory.GroupAction.Pi
1011
import Mathlib.Logic.Basic
@@ -473,6 +474,11 @@ theorem map_rat_smul [AddCommGroup M] [AddCommGroup M₂] [Module ℚ M] [Module
473474
map_rat_cast_smul f ℚ ℚ c x
474475
#align map_rat_smul map_rat_smul
475476

477+
478+
/-- A `Module` over `ℚ` restricts to a `Module` over `ℚ≥0`. -/
479+
instance [AddCommMonoid α] [Module ℚ α] : Module NNRat α :=
480+
Module.compHom α NNRat.coeHom
481+
476482
/-- There can be at most one `Module ℚ E` structure on an additive commutative group. -/
477483
instance subsingleton_rat_module (E : Type*) [AddCommGroup E] : Subsingleton (Module ℚ E) :=
478484
fun P Q => (Module.ext' P Q) fun r x => @map_rat_smul _ _ _ _ P Q _ _ (AddMonoidHom.id E) r x⟩

Mathlib/Data/Nat/Digits.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Mathlib.Data.Nat.Log
99
import Mathlib.Data.List.BigOperators.Lemmas
1010
import Mathlib.Data.List.Indexes
1111
import Mathlib.Data.List.Palindrome
12+
import Mathlib.Algebra.CharZero.Lemmas
1213
import Mathlib.Algebra.Parity
1314
import Mathlib.Algebra.BigOperators.Intervals
1415
import Mathlib.Tactic.IntervalCases

Mathlib/Data/Rat/NNRat.lean

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Yaël Dillies, Bhavik Mehta
55
-/
6-
import Mathlib.Algebra.Algebra.Basic
6+
import Mathlib.Algebra.Function.Indicator
77
import Mathlib.Algebra.Order.Nonneg.Field
88
import Mathlib.Data.Int.Lemmas
9+
import Mathlib.Data.Rat.Order
910

1011
#align_import data.rat.nnrat from "leanprover-community/mathlib"@"b3f4f007a962e3787aa0f3b5c7942a1317f7d88e"
1112

@@ -28,8 +29,6 @@ of `x` with `↑x`. This tactic also works for a function `f : α → ℚ` with
2829

2930
open Function
3031

31-
open BigOperators
32-
3332
/-- Nonnegative rational numbers. -/
3433
def NNRat := { q : ℚ // 0 ≤ q } deriving
3534
CanonicallyOrderedCommSemiring, CanonicallyLinearOrderedSemifield, LinearOrderedCommGroupWithZero,
@@ -215,10 +214,6 @@ theorem mk_coe_nat (n : ℕ) : @Eq ℚ≥0 (⟨(n : ℚ), n.cast_nonneg⟩ : ℚ
215214
ext (coe_natCast n).symm
216215
#align nnrat.mk_coe_nat NNRat.mk_coe_nat
217216

218-
/-- The rational numbers are an algebra over the non-negative rationals. -/
219-
instance : Algebra ℚ≥0 ℚ :=
220-
coeHom.toAlgebra
221-
222217
/-- A `MulAction` over `ℚ` restricts to a `MulAction` over `ℚ≥0`. -/
223218
instance [MulAction ℚ α] : MulAction ℚ≥0 α :=
224219
MulAction.compHom α coeHom.toMonoidHom
@@ -227,10 +222,6 @@ instance [MulAction ℚ α] : MulAction ℚ≥0 α :=
227222
instance [AddCommMonoid α] [DistribMulAction ℚ α] : DistribMulAction ℚ≥0 α :=
228223
DistribMulAction.compHom α coeHom.toMonoidHom
229224

230-
/-- A `Module` over `ℚ` restricts to a `Module` over `ℚ≥0`. -/
231-
instance [AddCommMonoid α] [Module ℚ α] : Module ℚ≥0 α :=
232-
Module.compHom α coeHom
233-
234225
@[simp]
235226
theorem coe_coeHom : ⇑coeHom = ((↑) : ℚ≥0 → ℚ) :=
236227
rfl

0 commit comments

Comments
 (0)