@@ -69,6 +69,23 @@ instance instDistrib (n : ℕ) : Distrib (Fin n) :=
69
69
right_distrib := fun a b c => by
70
70
rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm] }
71
71
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
+
72
89
/--
73
90
Commutative ring structure on `Fin n`.
74
91
@@ -83,27 +100,22 @@ For example, for `x : Fin k` and `n : Nat`,
83
100
it causes `x < n` to be elaborated as `x < ↑n` rather than `↑x < n`,
84
101
silently introducing wraparound arithmetic.
85
102
-/
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
94
110
95
111
namespace CommRing
96
112
97
113
attribute [scoped instance] Fin.instCommRing
98
114
99
115
end CommRing
100
116
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
107
119
108
120
end Fin
109
121
0 commit comments