@@ -33,13 +33,12 @@ variables {R : Type u} {a : R} {m n : ℕ}
33
33
section semiring
34
34
variables [semiring R] {p q : polynomial R}
35
35
36
- instance : inhabited (polynomial R) := finsupp .inhabited
36
+ instance : inhabited (polynomial R) := add_monoid_algebra .inhabited _ _
37
37
instance : semiring (polynomial R) := add_monoid_algebra.semiring
38
38
instance : has_scalar R (polynomial R) := add_monoid_algebra.has_scalar
39
39
instance : semimodule R (polynomial R) := add_monoid_algebra.semimodule
40
40
41
- instance subsingleton [subsingleton R] : subsingleton (polynomial R) :=
42
- ⟨λ _ _, ext (λ _, subsingleton.elim _ _)⟩
41
+ instance [subsingleton R] : unique (polynomial R) := add_monoid_algebra.unique
43
42
44
43
@[simp] lemma support_zero : (0 : polynomial R).support = ∅ := rfl
45
44
@@ -48,15 +47,15 @@ def monomial (n : ℕ) (a : R) : polynomial R := finsupp.single n a
48
47
49
48
@[simp] lemma monomial_zero_right (n : ℕ) :
50
49
monomial n (0 : R) = 0 :=
51
- by simp [monomial]
50
+ finsupp.single_zero
52
51
53
52
lemma monomial_add (n : ℕ) (r s : R) :
54
53
monomial n (r + s) = monomial n r + monomial n s :=
55
- by simp [monomial]
54
+ finsupp.single_add
56
55
57
56
lemma monomial_mul_monomial (n m : ℕ) (r s : R) :
58
57
monomial n r * monomial m s = monomial (n + m) (r * s) :=
59
- by simp only [monomial, single_mul_single]
58
+ add_monoid_algebra. single_mul_single
60
59
61
60
62
61
/-- `X` is the polynomial variable (aka indeterminant). -/
@@ -80,19 +79,12 @@ by rw [mul_assoc, X_pow_mul, ←mul_assoc]
80
79
lemma commute_X (p : polynomial R) : commute X p := X_mul
81
80
82
81
/-- coeff p n is the coefficient of X^n in p -/
83
- def coeff (p : polynomial R) := p.to_fun
82
+ def coeff (p : polynomial R) : ℕ → R := @coe_fn (ℕ →₀ R) _ p
84
83
85
84
@[simp] lemma coeff_mk (s) (f) (h) : coeff (finsupp.mk s f h : polynomial R) = f := rfl
86
85
87
86
lemma coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 :=
88
- by { dsimp [monomial, single, finsupp.single], congr, }
89
-
90
- /--
91
- This lemma is needed for occasions when we break through the abstraction from
92
- `polynomial` to `finsupp`; ideally it wouldn't be necessary at all.
93
- -/
94
- lemma coeff_single : coeff (single n a) m = if n = m then a else 0 :=
95
- coeff_monomial
87
+ by { dsimp [monomial, coeff], rw finsupp.single_apply, congr }
96
88
97
89
@[simp] lemma coeff_zero (n : ℕ) : coeff (0 : polynomial R) n = 0 := rfl
98
90
@@ -105,37 +97,20 @@ coeff_monomial
105
97
lemma coeff_X : coeff (X : polynomial R) n = if 1 = n then 1 else 0 := coeff_monomial
106
98
107
99
theorem ext_iff {p q : polynomial R} : p = q ↔ ∀ n, coeff p n = coeff q n :=
108
- ⟨λ h n, h ▸ rfl, finsupp.ext⟩
100
+ finsupp.ext_iff
109
101
110
102
@[ext] lemma ext {p q : polynomial R} : (∀ n, coeff p n = coeff q n) → p = q :=
111
- (@ext_iff _ _ p q). 2
103
+ finsupp.ext
112
104
113
105
-- this has the same content as the subsingleton
114
106
lemma eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : polynomial R) : p = 0 :=
115
107
by rw [←one_smul R p, ←h, zero_smul]
116
108
117
109
lemma support_monomial (n) (a : R) (H : a ≠ 0 ) : (monomial n a).support = singleton n :=
118
- begin
119
- ext,
120
- have m3 : a_1 ∈ (monomial n a).support ↔ coeff (monomial n a) a_1 ≠ 0 := (monomial n a).mem_support_to_fun a_1,
121
- rw [finset.mem_singleton, m3, coeff_monomial],
122
- split_ifs,
123
- { rwa [h, eq_self_iff_true, iff_true], },
124
- { rw [← @not_not (a_1=n)],
125
- apply not_congr,
126
- rw [eq_self_iff_true, true_iff, ← ne.def],
127
- symmetry,
128
- assumption, },
129
- end
110
+ finsupp.support_single_ne_zero H
130
111
131
112
lemma support_monomial' (n) (a : R) : (monomial n a).support ⊆ singleton n :=
132
- begin
133
- by_cases h : a = 0 ,
134
- { rw [h, monomial_zero_right, support_zero],
135
- exact finset.empty_subset {n}, },
136
- { rw support_monomial n a h,
137
- exact finset.subset.refl {n}, },
138
- end
113
+ finsupp.support_single_subset
139
114
140
115
lemma X_pow_eq_monomial (n) : X ^ n = monomial n (1 :R) :=
141
116
begin
@@ -167,7 +142,6 @@ section comm_semiring
167
142
variables [comm_semiring R]
168
143
169
144
instance : comm_semiring (polynomial R) := add_monoid_algebra.comm_semiring
170
- instance : comm_monoid (polynomial R) := comm_semiring.to_comm_monoid (polynomial R)
171
145
172
146
end comm_semiring
173
147
@@ -188,11 +162,7 @@ instance [comm_ring R] : comm_ring (polynomial R) := add_monoid_algebra.comm_rin
188
162
section nonzero_semiring
189
163
190
164
variables [semiring R] [nontrivial R]
191
- instance : nontrivial (polynomial R) :=
192
- begin
193
- refine nontrivial_of_ne 0 1 _, intro h,
194
- have := coeff_zero 0 , revert this , rw h, simp,
195
- end
165
+ instance : nontrivial (polynomial R) := add_monoid_algebra.nontrivial
196
166
197
167
lemma X_ne_zero : (X : polynomial R) ≠ 0 :=
198
168
mt (congr_arg (λ p, coeff p 1 )) (by simp)
0 commit comments