Skip to content

Commit fb5af9d

Browse files
committed
chore(RingTheory/AdjoinRoot): clean up instances (leanprover-community#37127)
Clean up `AdjoinRoot` instances using `inferInstanceAs`.
1 parent d9c36df commit fb5af9d

2 files changed

Lines changed: 14 additions & 31 deletions

File tree

Mathlib/AlgebraicGeometry/EllipticCurve/Affine/Point.lean

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ noncomputable instance : Algebra R[X] W'.CoordinateRing :=
110110
instance : IsScalarTower R R[X] W'.CoordinateRing :=
111111
Quotient.isScalarTower R R[X] _
112112

113-
set_option backward.isDefEq.respectTransparency false in
114113
instance [Subsingleton R] : Subsingleton W'.CoordinateRing :=
115114
Module.subsingleton R[X] _
116115

@@ -119,7 +118,6 @@ variable (W') in
119118
noncomputable abbrev mk : R[X][Y] →+* W'.CoordinateRing :=
120119
AdjoinRoot.mk W'.polynomial
121120

122-
set_option backward.isDefEq.respectTransparency false in
123121
open scoped Classical in
124122
variable (W') in
125123
/-- The power basis `{1, Y}` for `R[W]` over `R[X]`. -/
@@ -148,18 +146,15 @@ lemma coe_basis : (CoordinateRing.basis W' : Fin 2 → W'.CoordinateRing) = ![1,
148146
fin_cases n
149147
exacts [basis_zero, basis_one]
150148

151-
set_option backward.isDefEq.respectTransparency false in
152149
lemma smul (x : R[X]) (y : W'.CoordinateRing) : x • y = mk W' (C x) * y :=
153150
(algebraMap_smul W'.CoordinateRing x y).symm
154151

155-
set_option backward.isDefEq.respectTransparency false in
156152
lemma smul_basis_eq_zero {p q : R[X]} (hpq : p • (1 : W'.CoordinateRing) + q • mk W' Y = 0) :
157153
p = 0 ∧ q = 0 := by
158154
have h := Fintype.linearIndependent_iff.mp (CoordinateRing.basis W').linearIndependent ![p, q]
159155
rw [Fin.sum_univ_succ, basis_zero, Fin.sum_univ_one, Fin.succ_zero_eq_one, basis_one] at h
160156
exact ⟨h hpq 0, h hpq 1
161157

162-
set_option backward.isDefEq.respectTransparency false in
163158
lemma exists_smul_basis_eq (x : W'.CoordinateRing) :
164159
∃ p q : R[X], p • (1 : W'.CoordinateRing) + q • mk W' Y = x := by
165160
have h := (CoordinateRing.basis W').sum_equivFun x
@@ -408,7 +403,6 @@ lemma mk_XYIdeal'_mul_mk_XYIdeal' [DecidableEq F] {x₁ x₂ y₁ y₂ : F} (h
408403

409404
/-! ## Norms on the affine coordinate ring -/
410405

411-
set_option backward.isDefEq.respectTransparency false in
412406
lemma norm_smul_basis (p q : R[X]) : Algebra.norm R[X] (p • (1 : W'.CoordinateRing) + q • mk W' Y) =
413407
p ^ 2 - p * q * (C W'.a₁ * X + C W'.a₃) -
414408
q ^ 2 * (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆) := by
@@ -751,6 +745,7 @@ private lemma add_eq_zero (P Q : W.Point) : P + Q = 0 ↔ P = -Q := by
751745
exact fun hxy => by simpa only [add_some hxy] using some_ne_zero _
752746
· exact fun ⟨hx, hy⟩ => add_of_Y_eq hx hy
753747

748+
set_option backward.isDefEq.respectTransparency false in
754749
lemma toClass_eq_zero (P : W.Point) : toClass P = 0 ↔ P = 0 := by
755750
constructor
756751
· intro hP

Mathlib/RingTheory/AdjoinRoot.lean

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ section CommRing
6868

6969
variable [CommRing R] (f g : R[X])
7070

71-
instance instCommRing : CommRing (AdjoinRoot f) :=
72-
Ideal.Quotient.commRing _
73-
74-
instance : Inhabited (AdjoinRoot f) :=
75-
0
71+
deriving instance CommRing, Inhabited for AdjoinRoot
7672

7773
instance : DecidableEq (AdjoinRoot f) :=
7874
Classical.decEq _
@@ -97,10 +93,10 @@ def of : R →+* AdjoinRoot f :=
9793
(mk f).comp C
9894

9995
instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) :=
100-
Submodule.Quotient.instSMul' _
96+
inferInstanceAs <| SMul S (_ ⧸ _)
10197

10298
instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) :=
103-
Submodule.Quotient.distribSMul' _
99+
inferInstanceAs <| DistribSMul S (_ ⧸ _)
104100

105101
@[simp]
106102
theorem smul_mk [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R[X]) :
@@ -113,25 +109,25 @@ theorem smul_of [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R) :
113109
instance (R₁ R₂ : Type*) [SMul R₁ R₂] [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R]
114110
[IsScalarTower R₂ R R] [IsScalarTower R₁ R₂ R] (f : R[X]) :
115111
IsScalarTower R₁ R₂ (AdjoinRoot f) :=
116-
Submodule.Quotient.isScalarTower _ _
112+
inferInstanceAs <| IsScalarTower R₁ R₂ (_ ⧸ _)
117113

118114
instance (R₁ R₂ : Type*) [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R]
119115
[IsScalarTower R₂ R R] [SMulCommClass R₁ R₂ R] (f : R[X]) :
120116
SMulCommClass R₁ R₂ (AdjoinRoot f) :=
121-
Submodule.Quotient.smulCommClass _ _
117+
inferInstanceAs <| SMulCommClass R₁ R₂ (_ ⧸ _)
122118

123119
instance isScalarTower_right [DistribSMul S R] [IsScalarTower S R R] :
124120
IsScalarTower S (AdjoinRoot f) (AdjoinRoot f) :=
125-
Ideal.Quotient.isScalarTower_right
121+
inferInstanceAs <| IsScalarTower S (_ ⧸ _) (_ ⧸ _)
126122

127123
instance [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (f : R[X]) :
128124
DistribMulAction S (AdjoinRoot f) :=
129-
Submodule.Quotient.distribMulAction' _
125+
inferInstanceAs <| DistribMulAction S (_ ⧸ _)
130126

131127
/-- `R[x]/(f)` is `R`-algebra -/
132128
@[stacks 09FX "second part"]
133129
instance [CommSemiring S] [Algebra S R] : Algebra S (AdjoinRoot f) :=
134-
Ideal.Quotient.algebra S
130+
inferInstanceAs <| Algebra S (_ ⧸ _)
135131

136132
/- TODO : generalise base ring -/
137133
/-- `R`-algebra homomorphism from `R[x]` to `AdjoinRoot f` sending `X` to the `root`. -/
@@ -152,11 +148,12 @@ theorem algebraMap_eq' [CommSemiring S] [Algebra S R] :
152148
rfl
153149

154150
instance finiteType [CommSemiring S] [Algebra S R] [FiniteType S R] :
155-
FiniteType S (AdjoinRoot f) := by
156-
unfold AdjoinRoot; infer_instance
151+
FiniteType S (AdjoinRoot f) :=
152+
inferInstanceAs <| FiniteType S (_ ⧸ (_ : Ideal R[X]))
157153

158154
instance finitePresentation [CommRing S] [Algebra S R] [FinitePresentation S R] :
159-
FinitePresentation S (AdjoinRoot f) := .quotient (Submodule.fg_span_singleton f)
155+
FinitePresentation S (AdjoinRoot f) :=
156+
.quotient (Submodule.fg_span_singleton f)
160157

161158
/-- The adjoined root. -/
162159
def root : AdjoinRoot f :=
@@ -400,7 +397,6 @@ theorem isDomain_of_prime (hf : Prime f) : IsDomain (AdjoinRoot f) :=
400397
(Ideal.Quotient.isDomain_iff_prime (span {f} : Ideal R[X])).mpr <|
401398
(Ideal.span_singleton_prime hf.ne_zero).mpr hf
402399

403-
set_option backward.isDefEq.respectTransparency false in
404400
theorem noZeroSMulDivisors_of_prime_of_degree_ne_zero [IsDomain R] (hf : Prime f)
405401
(hf' : f.degree ≠ 0) : IsTorsionFree R (AdjoinRoot f) :=
406402
haveI := isDomain_of_prime hf
@@ -551,7 +547,7 @@ instance span_maximal_of_irreducible [Fact (Irreducible f)] : (span {f}).IsMaxim
551547
PrincipalIdealRing.isMaximal_of_irreducible <| Fact.out
552548

553549
noncomputable instance instGroupWithZero [Fact (Irreducible f)] : GroupWithZero (AdjoinRoot f) :=
554-
Quotient.groupWithZero (span {f} : Ideal K[X])
550+
fast_instance% Quotient.groupWithZero (span {f} : Ideal K[X])
555551

556552
/-- If `R` is a field and `f` is irreducible, then `AdjoinRoot f` is a field -/
557553
@[stacks 09FX "first part, see also 09FI"]
@@ -601,7 +597,6 @@ variable [CommRing R] {g : R[X]}
601597
theorem isIntegral_root' (hg : g.Monic) : IsIntegral R (root g) :=
602598
⟨g, hg, eval₂_root g⟩
603599

604-
set_option backward.isDefEq.respectTransparency false in
605600
/-- `AdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`.
606601
607602
This is a well-defined right inverse to `AdjoinRoot.mk`, see `AdjoinRoot.mk_leftInverse`. -/
@@ -624,7 +619,6 @@ theorem mk_leftInverse (hg : g.Monic) : Function.LeftInverse (mk g) (modByMonicH
624619
theorem mk_surjective : Function.Surjective (mk g) :=
625620
Ideal.Quotient.mk_surjective
626621

627-
set_option backward.isDefEq.respectTransparency false in
628622
/-- The elements `1, root g, ..., root g ^ (d - 1)` form a basis for `AdjoinRoot g`,
629623
where `g` is a monic polynomial of degree `d`. -/
630624
def powerBasisAux' (hg : g.Monic) : Basis (Fin g.natDegree) R (AdjoinRoot g) :=
@@ -652,14 +646,12 @@ def powerBasisAux' (hg : g.Monic) : Basis (Fin g.natDegree) R (AdjoinRoot g) :=
652646
-- This lemma could be autogenerated by `@[simps]` but unfortunately that would require
653647
-- unfolding that causes a timeout.
654648
-- This lemma should have the simp tag but this causes a lint issue.
655-
set_option backward.isDefEq.respectTransparency false in
656649
theorem powerBasisAux'_repr_symm_apply (hg : g.Monic) (c : Fin g.natDegree →₀ R) :
657650
(powerBasisAux' hg).repr.symm c = mk g (∑ i : Fin _, monomial i (c i)) :=
658651
rfl
659652

660653
-- This lemma could be autogenerated by `@[simps]` but unfortunately that would require
661654
-- unfolding that causes a timeout.
662-
set_option backward.isDefEq.respectTransparency false in
663655
@[simp]
664656
theorem powerBasisAux'_repr_apply_to_fun (hg : g.Monic) (f : AdjoinRoot g) (i : Fin g.natDegree) :
665657
(powerBasisAux' hg).repr f i = (modByMonicHom hg f).coeff ↑i :=
@@ -683,11 +675,9 @@ def powerBasis' (hg : g.Monic) : PowerBasis R (AdjoinRoot g) where
683675
have := Finset.mem_univ i
684676
contradiction
685677

686-
set_option backward.isDefEq.respectTransparency false in
687678
lemma _root_.Polynomial.Monic.free_adjoinRoot (hg : g.Monic) : Module.Free R (AdjoinRoot g) :=
688679
.of_basis (powerBasis' hg).basis
689680

690-
set_option backward.isDefEq.respectTransparency false in
691681
lemma _root_.Polynomial.Monic.finite_adjoinRoot (hg : g.Monic) : Module.Finite R (AdjoinRoot g) :=
692682
.of_basis (powerBasis' hg).basis
693683

@@ -724,7 +714,6 @@ theorem minpoly_root (hf : f ≠ 0) : minpoly K (root f) = f * C f.leadingCoeff
724714
· exact q_monic.ne_zero
725715
· rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero]
726716

727-
set_option backward.isDefEq.respectTransparency false in
728717
/-- The elements `1, root f, ..., root f ^ (d - 1)` form a basis for `AdjoinRoot f`,
729718
where `f` is an irreducible polynomial over a field of degree `d`. -/
730719
def powerBasisAux (hf : f ≠ 0) : Basis (Fin f.natDegree) K (AdjoinRoot f) := by
@@ -1084,7 +1073,6 @@ theorem Irreducible.exists_dvd_monic_irreducible_of_isIntegral {K L : Type*}
10841073
have h3 := (AdjoinRoot.minpoly_root h) ▸ minpoly.dvd_map_of_isScalarTower K L (AdjoinRoot.root f)
10851074
exact ⟨_, minpoly.monic h2, minpoly.irreducible h2, dvd_of_mul_right_dvd h3⟩
10861075

1087-
set_option backward.isDefEq.respectTransparency false in
10881076
/-- If `p : R[X]` is monic, then there exists a finite free extension of `R` that splits `p`. -/
10891077
lemma Polynomial.Monic.exists_splits_map.{u}
10901078
{R : Type u} [CommRing R] [Nontrivial R] {p : R[X]} (hp : p.Monic) :

0 commit comments

Comments
 (0)