Skip to content

Commit cb179b1

Browse files
committed
chore: Final cleanup before NNRat.cast (#12360)
This is the parts of the diff of #11203 which don't mention `NNRat.cast`. * Use more `where` notation. * Write `qsmul := _` instead of `qsmul := qsmulRec _` to make the instances more robust to definition changes. * Delete `qsmulRec`. * Move `qsmul` before `ratCast_def` in instance declarations. * Name more instances. * Rename `rat_smul` to `qsmul`.
1 parent b57f05f commit cb179b1

File tree

30 files changed

+145
-189
lines changed

30 files changed

+145
-189
lines changed

Mathlib/Algebra/DirectLimit.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,13 +1005,13 @@ protected theorem inv_mul_cancel {p : Ring.DirectLimit G f} (hp : p ≠ 0) : inv
10051005
See note [reducible non-instances]. -/
10061006
@[reducible]
10071007
protected noncomputable def field [DirectedSystem G fun i j h => f' i j h] :
1008-
Field (Ring.DirectLimit G fun i j h => f' i j h) :=
1008+
Field (Ring.DirectLimit G fun i j h => f' i j h) where
10091009
-- This used to include the parent CommRing and Nontrivial instances,
10101010
-- but leaving them implicit avoids a very expensive (2-3 minutes!) eta expansion.
1011-
{ inv := inv G fun i j h => f' i j h
1012-
mul_inv_cancel := fun p => DirectLimit.mul_inv_cancel G fun i j h => f' i j h
1013-
inv_zero := dif_pos rfl
1014-
qsmul := qsmulRec _ }
1011+
inv := inv G fun i j h => f' i j h
1012+
mul_inv_cancel := fun p => DirectLimit.mul_inv_cancel G fun i j h => f' i j h
1013+
inv_zero := dif_pos rfl
1014+
qsmul := _
10151015
#align field.direct_limit.field Field.DirectLimit.field
10161016

10171017
end

Mathlib/Algebra/Field/Defs.lean

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,7 @@ better definitional properties). Instead, use the coercion. -/
6868
def Rat.castRec [NatCast K] [IntCast K] [Div K] (q : ℚ) : K := q.num / q.den
6969
#align rat.cast_rec Rat.castRec
7070

71-
/-- The default definition of the scalar multiplication by `ℚ` on a division ring `K`.
72-
73-
`q • x` is defined as `↑q * x`.
74-
75-
Do not use directly (instances of `DivisionRing` are allowed to override that default for
76-
better definitional properties). Instead use the `•` notation. -/
77-
def qsmulRec (coe : ℚ → K) [Mul K] (a : ℚ) (x : K) : K :=
78-
coe a * x
79-
#align qsmul_rec qsmulRec
71+
#noalign qsmul_rec
8072

8173
/-- A `DivisionSemiring` is a `Semiring` with multiplicative inverses for nonzero elements.
8274
@@ -113,7 +105,8 @@ class DivisionRing (α : Type*)
113105
protected ratCast_def (q : ℚ) : (Rat.cast q : α) = q.num / q.den := by intros; rfl
114106
/-- Scalar multiplication by a rational number.
115107
116-
Set this to `qsmulRec _` unless there is a risk of a `Module ℚ _` instance diamond.
108+
Unless there is a risk of a `Module ℚ _` instance diamond, write `qsmul := _`. This will set
109+
`qsmul` to `(Rat.cast · * ·)` thanks to unification in the default proof of `qsmul_def`.
117110
118111
Do not use directly. Instead use the `•` notation. -/
119112
protected qsmul : ℚ → α → α

Mathlib/Algebra/Field/IsField.lean

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,17 @@ theorem not_isField_of_subsingleton (R : Type u) [Semiring R] [Subsingleton R] :
6363
open scoped Classical
6464

6565
/-- Transferring from `IsField` to `Semifield`. -/
66-
noncomputable def IsField.toSemifield {R : Type u} [Semiring R] (h : IsField R) : Semifield R :=
67-
{ ‹Semiring R›, h with
68-
inv := fun a => if ha : a = 0 then 0 else Classical.choose (IsField.mul_inv_cancel h ha),
69-
inv_zero := dif_pos rfl,
70-
mul_inv_cancel := fun a ha => by
71-
convert Classical.choose_spec (IsField.mul_inv_cancel h ha)
72-
exact dif_neg ha }
66+
noncomputable def IsField.toSemifield {R : Type u} [Semiring R] (h : IsField R) : Semifield R where
67+
__ := ‹Semiring R›
68+
__ := h
69+
inv a := if ha : a = 0 then 0 else Classical.choose (h.mul_inv_cancel ha)
70+
inv_zero := dif_pos rfl
71+
mul_inv_cancel a ha := by convert Classical.choose_spec (h.mul_inv_cancel ha); exact dif_neg ha
7372
#align is_field.to_semifield IsField.toSemifield
7473

7574
/-- Transferring from `IsField` to `Field`. -/
7675
noncomputable def IsField.toField {R : Type u} [Ring R] (h : IsField R) : Field R :=
77-
{ ‹Ring R›, IsField.toSemifield h with qsmul := qsmulRec _ }
76+
{ ‹Ring R›, IsField.toSemifield h with qsmul := _ }
7877
#align is_field.to_field IsField.toField
7978

8079
/-- For each field, and for each nonzero element of said field, there is a unique inverse.

Mathlib/Algebra/Field/MinimalAxioms.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def Field.ofMinimalAxioms (K : Type u)
4242
{ exists_pair_ne := exists_pair_ne
4343
mul_inv_cancel := mul_inv_cancel
4444
inv_zero := inv_zero
45-
qsmul := qsmulRec _ }
45+
qsmul := _ }

Mathlib/Algebra/Field/Opposite.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ instance instDivisionSemiring [DivisionSemiring α] : DivisionSemiring αᵐᵒ
3838
instance instDivisionRing [DivisionRing α] : DivisionRing αᵐᵒᵖ where
3939
__ := instRing
4040
__ := instDivisionSemiring
41+
qsmul := _
4142
ratCast_def q := unop_injective <| by rw [unop_ratCast, Rat.cast_def, unop_div,
4243
unop_natCast, unop_intCast, Int.commute_cast, div_eq_mul_inv]
43-
qsmul := qsmulRec _
4444

4545
instance instSemifield [Semifield α] : Semifield αᵐᵒᵖ where
4646
__ := instCommSemiring
@@ -61,9 +61,9 @@ instance instDivisionSemiring [DivisionSemiring α] : DivisionSemiring αᵃᵒ
6161
instance instDivisionRing [DivisionRing α] : DivisionRing αᵃᵒᵖ where
6262
__ := instRing
6363
__ := instDivisionSemiring
64+
qsmul := _
6465
ratCast_def q := unop_injective <| by rw [unop_ratCast, Rat.cast_def, unop_div, unop_natCast,
6566
unop_intCast, div_eq_mul_inv]
66-
qsmul := qsmulRec _
6767

6868
instance instSemifield [Semifield α] : Semifield αᵃᵒᵖ where
6969
__ := instCommSemiring

Mathlib/Algebra/Field/ULift.lean

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ variable {α : Type u} {x y : ULift.{v} α}
2121

2222
namespace ULift
2323

24-
instance [RatCast α] : RatCast (ULift α) := ⟨(up ·)⟩
24+
instance instRatCast [RatCast α] : RatCast (ULift α) where ratCast q := up q
2525

26-
@[simp, norm_cast]
27-
theorem up_ratCast [RatCast α] (q : ℚ) : up (q : α) = q :=
28-
rfl
26+
@[simp, norm_cast] lemma up_ratCast [RatCast α] (q : ℚ) : up (q : α) = q := rfl
27+
@[simp, norm_cast] lemma down_ratCast [RatCast α] (q : ℚ) : down (q : ULift α) = q := rfl
2928
#align ulift.up_rat_cast ULift.up_ratCast
30-
31-
@[simp, norm_cast]
32-
theorem down_ratCast [RatCast α] (q : ℚ) : down (q : ULift α) = q :=
33-
rfl
3429
#align ulift.down_rat_cast ULift.down_ratCast
3530

3631
instance divisionSemiring [DivisionSemiring α] : DivisionSemiring (ULift α) := by

Mathlib/Algebra/Order/CauSeq/Completion.lean

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,9 @@ section
203203
variable {α : Type*} [LinearOrderedField α]
204204
variable {β : Type*} [DivisionRing β] {abv : β → α} [IsAbsoluteValue abv]
205205

206-
instance : RatCast (Cauchy abv) :=
207-
fun q => ofRat q⟩
206+
instance instRatCast : RatCast (Cauchy abv) where ratCast q := ofRat q
208207

209-
@[simp, coe]
210-
theorem ofRat_ratCast (q : ℚ) : ofRat (↑q : β) = (q : (Cauchy abv)) :=
211-
rfl
208+
@[simp, norm_cast] lemma ofRat_ratCast (q : ℚ) : ofRat (q : β) = (q : Cauchy abv) := rfl
212209
#align cau_seq.completion.of_rat_rat_cast CauSeq.Completion.ofRat_ratCast
213210

214211
noncomputable instance : Inv (Cauchy abv) :=
@@ -275,8 +272,8 @@ noncomputable instance Cauchy.divisionRing : DivisionRing (Cauchy abv) where
275272
exists_pair_ne := ⟨0, 1, zero_ne_one⟩
276273
inv_zero := inv_zero
277274
mul_inv_cancel x := CauSeq.Completion.mul_inv_cancel
278-
ratCast_def q := by rw [← ofRat_ratCast, Rat.cast_def, ofRat_div, ofRat_natCast, ofRat_intCast]
279275
qsmul := (· • ·)
276+
ratCast_def q := by rw [← ofRat_ratCast, Rat.cast_def, ofRat_div, ofRat_natCast, ofRat_intCast]
280277
qsmul_def q x := Quotient.inductionOn x fun f ↦ congr_arg mk <| ext fun i ↦ Rat.smul_def _ _
281278

282279
/-- Show the first 10 items of a representative of this equivalence class of cauchy sequences.

Mathlib/Algebra/Polynomial/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,9 +1263,9 @@ section DivisionRing
12631263

12641264
variable [DivisionRing R]
12651265

1266-
theorem rat_smul_eq_C_mul (a : ℚ) (f : R[X]) : a • f = Polynomial.C (a : R) * f := by
1266+
theorem qsmul_eq_C_mul (a : ℚ) (f : R[X]) : a • f = Polynomial.C (a : R) * f := by
12671267
rw [← Rat.smul_one_eq_coe, ← Polynomial.smul_C, C_1, smul_one_mul]
1268-
#align polynomial.rat_smul_eq_C_mul Polynomial.rat_smul_eq_C_mul
1268+
#align polynomial.rat_smul_eq_C_mul Polynomial.qsmul_eq_C_mul
12691269

12701270
end DivisionRing
12711271

Mathlib/CategoryTheory/Preadditive/Schur.lean

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,19 @@ theorem isIso_iff_nonzero [HasKernels C] {X Y : C} [Simple X] [Simple Y] (f : X
5858
fun w => isIso_of_hom_simple w⟩
5959
#align category_theory.is_iso_iff_nonzero CategoryTheory.isIso_iff_nonzero
6060

61+
open scoped Classical in
6162
/-- In any preadditive category with kernels,
62-
the endomorphisms of a simple object form a division ring.
63-
-/
64-
noncomputable instance [HasKernels C] {X : C} [Simple X] : DivisionRing (End X) := by
65-
classical exact
66-
{ (inferInstance : Ring (End X)) with
67-
inv := fun f =>
68-
if h : f = 0 then 0
69-
else
70-
haveI := isIso_of_hom_simple h
71-
inv f
72-
exists_pair_ne := ⟨𝟙 X, 0, id_nonzero _⟩
73-
inv_zero := dif_pos rfl
74-
mul_inv_cancel := fun f h => by
75-
dsimp
76-
rw [dif_neg h]
77-
haveI := isIso_of_hom_simple h
78-
exact IsIso.inv_hom_id f
79-
qsmul := qsmulRec _ }
63+
the endomorphisms of a simple object form a division ring. -/
64+
noncomputable instance [HasKernels C] {X : C} [Simple X] : DivisionRing (End X) where
65+
inv f := if h : f = 0 then 0 else haveI := isIso_of_hom_simple h; inv f
66+
exists_pair_ne := ⟨𝟙 X, 0, id_nonzero _⟩
67+
inv_zero := dif_pos rfl
68+
mul_inv_cancel f hf := by
69+
dsimp
70+
rw [dif_neg hf]
71+
haveI := isIso_of_hom_simple hf
72+
exact IsIso.inv_hom_id f
73+
qsmul := _
8074

8175
open FiniteDimensional
8276

Mathlib/Data/Complex/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ lemma div_im (z w : ℂ) : (z / w).im = z.im * w.re / normSq w - z.re * w.im / n
818818
noncomputable instance instField : Field ℂ where
819819
mul_inv_cancel := @Complex.mul_inv_cancel
820820
inv_zero := Complex.inv_zero
821-
ratCast_def q := by ext <;> simp [Rat.cast_def, div_re, div_im, mul_div_mul_comm]
822821
qsmul := (· • ·)
822+
ratCast_def q := by ext <;> simp [Rat.cast_def, div_re, div_im, mul_div_mul_comm]
823823
qsmul_def n z := ext_iff.2 <| by simp [Rat.smul_def, smul_re, smul_im]
824824
#align complex.field Complex.instField
825825

0 commit comments

Comments
 (0)