Skip to content

Commit 71d36ec

Browse files
committed
fix: restore the NonUnitalCommRing (Fin n) instance (#25531)
`#synth NonUnitalCommRing (Fin n)` was made to fail uncecessarily in #25476; it doesn't imply `NatCast` so is not relevant to the goal of that PR. Also restores the `CommMonoid` and `HasDistribNeg` and `NeZero 1` instances.
1 parent 730e4db commit 71d36ec

File tree

11 files changed

+32
-31
lines changed

11 files changed

+32
-31
lines changed

Mathlib/AlgebraicGeometry/EllipticCurve/Affine/Point.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ lemma mk_XYIdeal'_mul_mk_XYIdeal' {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingula
398398

399399
/-! ## Norms on the affine coordinate ring -/
400400

401-
open Fin.CommRing in -- TODO: should this be refactored to avoid needing the coercion?
402401
lemma norm_smul_basis (p q : R[X]) : Algebra.norm R[X] (p • (1 : W'.CoordinateRing) + q • mk W' Y) =
403402
p ^ 2 - p * q * (C W'.a₁ * X + C W'.a₃) -
404403
q ^ 2 * (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆) := by

Mathlib/AlgebraicGeometry/EllipticCurve/Jacobian/Basic.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ associated to a Weierstrass curve `W` in Jacobian coordinates. -/
296296
noncomputable def polynomialX : MvPolynomial (Fin 3) R :=
297297
pderiv x W'.polynomial
298298

299-
open Fin.CommRing in
300299
lemma polynomialX_eq : W'.polynomialX =
301300
C W'.a₁ * X 1 * X 2 - (C 3 * X 0 ^ 2 + C (2 * W'.a₂) * X 0 * X 2 ^ 2 + C W'.a₄ * X 2 ^ 4) := by
302301
rw [polynomialX, polynomial]
@@ -321,7 +320,6 @@ associated to a Weierstrass curve `W` in Jacobian coordinates. -/
321320
noncomputable def polynomialY : MvPolynomial (Fin 3) R :=
322321
pderiv y W'.polynomial
323322

324-
open Fin.CommRing in
325323
lemma polynomialY_eq : W'.polynomialY = C 2 * X 1 + C W'.a₁ * X 0 * X 2 + C W'.a₃ * X 2 ^ 3 := by
326324
rw [polynomialY, polynomial]
327325
pderiv_simp

Mathlib/AlgebraicGeometry/EllipticCurve/Projective/Basic.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ associated to a Weierstrass curve `W` in projective coordinates. -/
287287
noncomputable def polynomialX : MvPolynomial (Fin 3) R :=
288288
pderiv x W'.polynomial
289289

290-
open Fin.CommRing in
291290
lemma polynomialX_eq : W'.polynomialX =
292291
C W'.a₁ * X 1 * X 2 - (C 3 * X 0 ^ 2 + C (2 * W'.a₂) * X 0 * X 2 + C W'.a₄ * X 2 ^ 2) := by
293292
rw [polynomialX, polynomial]
@@ -311,7 +310,6 @@ associated to a Weierstrass curve `W` in projective coordinates. -/
311310
noncomputable def polynomialY : MvPolynomial (Fin 3) R :=
312311
pderiv y W'.polynomial
313312

314-
open Fin.CommRing in
315313
lemma polynomialY_eq : W'.polynomialY =
316314
C 2 * X 1 * X 2 + C W'.a₁ * X 0 * X 2 + C W'.a₃ * X 2 ^ 2 := by
317315
rw [polynomialY, polynomial]

Mathlib/Combinatorics/Extremal/RuzsaSzemeredi.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ lemma addRothNumber_le_ruzsaSzemerediNumber :
173173
rw [← hscard, ← card_triangleIndices, ← card_triangles]
174174
exact (locallyLinear hs).le_ruzsaSzemerediNumber
175175

176-
open Fin.CommRing in -- TODO: can this be refactored to avoid using the ring structure in the proof?
177176
lemma rothNumberNat_le_ruzsaSzemerediNumberNat (n : ℕ) :
178177
(2 * n + 1) * rothNumberNat n ≤ ruzsaSzemerediNumberNat (6 * n + 3) := by
179178
let α := Fin (2 * n + 1)
180179
have : Nat.Coprime 2 (2 * n + 1) := by simp
181180
haveI : Fact (IsUnit (2 : Fin (2 * n + 1))) := ⟨by simpa using (ZMod.unitOfCoprime 2 this).isUnit⟩
181+
open scoped Fin.CommRing in
182182
calc
183183
(2 * n + 1) * rothNumberNat n
184184
_ = Fintype.card α * addRothNumber (Iio (n : α)) := by

Mathlib/Data/BitVec.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ lemma toFin_pow (x : BitVec w) (n : ℕ) : toFin (x ^ n) = x.toFin ^ n := by
5151
## Ring
5252
-/
5353

54-
open Fin.CommRing
55-
5654
-- Verify that the `HPow` instance from Lean agrees definitionally with the instance via `Monoid`.
5755
example : @instHPow (Fin (2 ^ w)) ℕ Monoid.toNatPow = Lean.Grind.Fin.instHPowFinNatOfNeZero := rfl
5856

59-
open Fin.CommRing in
6057
instance : CommSemiring (BitVec w) :=
58+
open Fin.CommRing in
6159
toFin_injective.commSemiring _
6260
rfl /- toFin_zero -/
6361
rfl /- toFin_one -/
@@ -76,6 +74,7 @@ theorem _root_.Fin.intCast_def' {n : Nat} [NeZero n] (x : Int) :
7674
dsimp [Int.cast, IntCast.intCast, Int.castDef]
7775
split <;> (simp [Fin.intCast]; omega)
7876

77+
open Fin.CommRing in
7978
@[simp] theorem _root_.Fin.val_intCast {n : Nat} [NeZero n] (x : Int) :
8079
(x : Fin n).val = (x % n).toNat := by
8180
rw [Fin.intCast_def']
@@ -90,6 +89,7 @@ theorem _root_.Fin.intCast_def' {n : Nat} [NeZero n] (x : Int) :
9089
omega
9190

9291
-- TODO: move to the Lean4 repository.
92+
open Fin.CommRing in
9393
theorem ofFin_intCast (z : ℤ) : ofFin (z : Fin (2^w)) = ↑z := by
9494
cases w
9595
case zero =>
@@ -108,8 +108,8 @@ open Fin.CommRing in
108108
theorem toFin_intCast (z : ℤ) : toFin (z : BitVec w) = z := by
109109
apply toFin_inj.mpr <| (ofFin_intCast z).symm
110110

111-
open Fin.CommRing in
112111
instance : CommRing (BitVec w) :=
112+
open Fin.CommRing in
113113
toFin_injective.commRing _
114114
toFin_zero toFin_one toFin_add toFin_mul toFin_neg toFin_sub
115115
toFin_nsmul toFin_zsmul toFin_pow toFin_natCast toFin_intCast

Mathlib/Data/ZMod/Defs.lean

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ instance instDistrib (n : ℕ) : Distrib (Fin n) :=
6969
right_distrib := fun a b c => by
7070
rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm] }
7171

72+
instance instNonUnitalCommRing (n : ℕ) [NeZero n] : NonUnitalCommRing (Fin n) where
73+
__ := Fin.addCommGroup n
74+
__ := Fin.instCommSemigroup n
75+
__ := Fin.instDistrib n
76+
zero_mul := Fin.zero_mul'
77+
mul_zero := Fin.mul_zero'
78+
79+
instance instCommMonoid (n : ℕ) [NeZero n] : CommMonoid (Fin n) where
80+
one_mul := Fin.one_mul'
81+
mul_one := Fin.mul_one'
82+
83+
/-- Note this is more general than `Fin.instCommRing` as it applies (vacuously) to `Fin 0` too. -/
84+
instance instHasDistribNeg (n : ℕ) : HasDistribNeg (Fin n) where
85+
toInvolutiveNeg := Fin.instInvolutiveNeg n
86+
mul_neg := Nat.casesOn n finZeroElim fun _i => mul_neg
87+
neg_mul := Nat.casesOn n finZeroElim fun _i => neg_mul
88+
7289
/--
7390
Commutative ring structure on `Fin n`.
7491
@@ -83,27 +100,22 @@ For example, for `x : Fin k` and `n : Nat`,
83100
it causes `x < n` to be elaborated as `x < ↑n` rather than `↑x < n`,
84101
silently introducing wraparound arithmetic.
85102
-/
86-
def instCommRing (n : ℕ) [NeZero n] : CommRing (Fin n) :=
87-
{ Fin.instAddMonoidWithOne n, Fin.addCommGroup n, Fin.instCommSemigroup n,
88-
Fin.instDistrib n with
89-
intCast n := Fin.intCast n
90-
one_mul := Fin.one_mul'
91-
mul_one := Fin.mul_one',
92-
zero_mul := Fin.zero_mul'
93-
mul_zero := Fin.mul_zero' }
103+
def instCommRing (n : ℕ) [NeZero n] : CommRing (Fin n) where
104+
__ := Fin.instAddMonoidWithOne n
105+
__ := Fin.addCommGroup n
106+
__ := Fin.instCommSemigroup n
107+
__ := Fin.instNonUnitalCommRing n
108+
__ := Fin.instCommMonoid n
109+
intCast n := Fin.intCast n
94110

95111
namespace CommRing
96112

97113
attribute [scoped instance] Fin.instCommRing
98114

99115
end CommRing
100116

101-
open Fin.CommRing in
102-
/-- Note this is more general than `Fin.instCommRing` as it applies (vacuously) to `Fin 0` too. -/
103-
def instHasDistribNeg (n : ℕ) : HasDistribNeg (Fin n) :=
104-
{ toInvolutiveNeg := Fin.instInvolutiveNeg n
105-
mul_neg := Nat.casesOn n finZeroElim fun _i => mul_neg
106-
neg_mul := Nat.casesOn n finZeroElim fun _i => neg_mul }
117+
instance (n : ℕ) [NeZero n] : NeZero (1 : Fin (n + 1)) :=
118+
open Fin.CommRing in inferInstance
107119

108120
end Fin
109121

Mathlib/FieldTheory/AxGrothendieck.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ noncomputable def genericPolyMapSurjOnOfInjOn [Finite ι]
140140
(fun i => (Equiv.sumAssoc _ _ _).symm (Sum.inr i)))))
141141
Formula.iAlls (α ⊕ Σ i : ι, mons i) ((mapsTo.imp <| injOn.imp <| surjOn).relabel Sum.inr)
142142

143-
open Fin.CommRing in -- TODO: can this be refactored to avoid using the ring structure in the proof?
144143
theorem realize_genericPolyMapSurjOnOfInjOn
145144
[Finite ι] (φ : ring.Formula (α ⊕ ι)) (mons : ι → Finset (ι →₀ ℕ)) :
146145
(K ⊨ genericPolyMapSurjOnOfInjOn φ mons) ↔

Mathlib/LinearAlgebra/LinearDisjoint.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ section
483483

484484
variable [Nontrivial R]
485485

486-
open Fin.CommRing in -- TODO: can this be refactored to avoid using the ring structure in the proof?
487486
/-- If `M` and `N` are linearly disjoint, if `M` is flat, then any two commutative
488487
elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/
489488
theorem not_linearIndependent_pair_of_commute_of_flat_left [Module.Flat R M]
@@ -500,7 +499,6 @@ theorem not_linearIndependent_pair_of_commute_of_flat_left [Module.Flat R M]
500499
repeat rw [AddSubmonoid.mk_eq_zero, ZeroMemClass.coe_eq_zero] at hm
501500
exact h.ne_zero 0 hm.2
502501

503-
open Fin.CommRing in
504502
/-- If `M` and `N` are linearly disjoint, if `N` is flat, then any two commutative
505503
elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/
506504
theorem not_linearIndependent_pair_of_commute_of_flat_right [Module.Flat R N]

Mathlib/MeasureTheory/Integral/RieszMarkovKakutani/Basic.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ section PartitionOfUnity
154154

155155
variable [T2Space X] [LocallyCompactSpace X]
156156

157-
open Fin.CommRing in -- TODO: can this be refactored to avoid using the ring structure in the proof?
158157
lemma exists_continuous_add_one_of_isCompact_nnreal
159158
{s₀ s₁ : Set X} {t : Set X} (s₀_compact : IsCompact s₀) (s₁_compact : IsCompact s₁)
160159
(t_compact : IsCompact t) (disj : Disjoint s₀ s₁) (hst : s₀ ∪ s₁ ⊆ t) :

Mathlib/SetTheory/Cardinal/Free.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ end Cardinal
105105

106106
section Nonempty
107107

108-
open Fin.CommRing in
109108
/-- A commutative ring can be constructed on any non-empty type.
110109
111110
See also `Infinite.nonempty_field`. -/
@@ -115,7 +114,7 @@ instance nonempty_commRing [Nonempty α] : Nonempty (CommRing α) := by
115114
have : NeZero (Fintype.card α) := ⟨by inhabit α; simp⟩
116115
classical
117116
obtain ⟨e⟩ := Fintype.truncEquivFin α
118-
exact ⟨e.commRing⟩
117+
exact ⟨open scoped Fin.CommRing in e.commRing⟩
119118
· have ⟨e⟩ : Nonempty (α ≃ FreeCommRing α) := by simp [← Cardinal.eq]
120119
exact ⟨e.commRing⟩
121120

0 commit comments

Comments
 (0)