Skip to content

Commit 194033d

Browse files
committed
chore: Final cleanup before NNRat.cast
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 _`. * Move `qsmul` before `ratCast_def` in instance declarations. * Name more instances. * Rename `rat_smul` to `qsmul`. *
1 parent e408da1 commit 194033d

File tree

27 files changed

+138
-175
lines changed

27 files changed

+138
-175
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/IsField.lean

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ 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`. -/

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 α) := ⟨fun a ↦ up a
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

Mathlib/Data/Rat/Field.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ namespace Rat
3838
instance instField : Field ℚ where
3939
__ := commRing
4040
__ := commGroupWithZero
41-
ratCast_def q := (num_div_den _).symm
4241
qsmul := _
42+
ratCast_def q := (num_div_den _).symm
4343

4444
-- Extra instances to short-circuit type class resolution
4545
instance instDivisionRing : DivisionRing ℚ := by infer_instance

Mathlib/Data/Real/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ noncomputable instance instLinearOrderedField : LinearOrderedField ℝ where
573573
Ne, ofCauchy.injEq] at *
574574
exact CauSeq.Completion.inv_mul_cancel h
575575
inv_zero := by simp [← ofCauchy_zero, ← ofCauchy_inv]
576+
qsmul := _
576577
ratCast_def q := by
577578
rw [← ofCauchy_ratCast, Rat.cast_def, ofCauchy_div, ofCauchy_natCast, ofCauchy_intCast]
578-
qsmul := _
579579

580580
-- Extra instances to short-circuit type class resolution
581581
noncomputable instance : LinearOrderedAddCommGroup ℝ := by infer_instance

Mathlib/Data/ZMod/Basic.lean

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,12 +1245,10 @@ private theorem mul_inv_cancel_aux (a : ZMod p) (h : a ≠ 0) : a * a⁻¹ = 1 :
12451245
rwa [Nat.Prime.coprime_iff_not_dvd Fact.out, ← CharP.cast_eq_zero_iff (ZMod p)]
12461246

12471247
/-- Field structure on `ZMod p` if `p` is prime. -/
1248-
instance : Field (ZMod p) :=
1249-
{ inferInstanceAs (CommRing (ZMod p)), inferInstanceAs (Inv (ZMod p)),
1250-
ZMod.nontrivial p with
1251-
mul_inv_cancel := mul_inv_cancel_aux p
1252-
inv_zero := inv_zero p
1253-
qsmul := qsmulRec _ }
1248+
instance : Field (ZMod p) where
1249+
mul_inv_cancel := mul_inv_cancel_aux p
1250+
inv_zero := inv_zero p
1251+
qsmul := _
12541252

12551253
/-- `ZMod p` is an integral domain when `p` is prime. -/
12561254
instance (p : ℕ) [hp : Fact p.Prime] : IsDomain (ZMod p) := by

0 commit comments

Comments
 (0)