@@ -20,6 +20,7 @@ instance {α : Type u} [semilattice_sup α] : is_idempotent α (⊔) := ⟨assum
2020namespace finset
2121variables [semilattice_sup_bot α]
2222
23+ /-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/
2324def sup (s : finset β) (f : β → α) : α := s.fold (⊔) ⊥ f
2425
2526variables {s s₁ s₂ : finset β} {f : β → α}
@@ -91,6 +92,8 @@ have ∀(s : finset α) (f : α →₀ β), s = f.support → p f,
9192 end ),
9293this _ _ rfl
9394
95+ /-- Multivariate polynomial, where `σ` is the index set of the variables and
96+ `α` is the coefficient ring -/
9497def mv_polynomial (σ : Type *) (α : Type *) [comm_semiring α] := (σ →₀ ℕ) →₀ α
9598
9699namespace mv_polynomial
@@ -105,10 +108,13 @@ instance : has_add (mv_polynomial σ α) := finsupp.has_add
105108instance : has_mul (mv_polynomial σ α) := finsupp.has_mul
106109instance : comm_semiring (mv_polynomial σ α) := finsupp.to_comm_semiring
107110
111+ /-- monomial s a is the monomial `a * X^s` -/
108112def monomial (s : σ →₀ ℕ) (a : α) : mv_polynomial σ α := single s a
109113
114+ /-- C a is the constant polynomial with value a -/
110115def C (a : α) : mv_polynomial σ α := monomial 0 a
111116
117+ /-- X n is the polynomial with value X_n -/
112118def X (n : σ) : mv_polynomial σ α := monomial (single n 1 ) 1
113119
114120@[simp] lemma C_0 : C 0 = (0 : mv_polynomial σ α) := by simp [C, monomial]; refl
@@ -165,6 +171,7 @@ finsupp.single_induction_on p
165171section eval
166172variables {f : σ → α}
167173
174+ /-- Evaluate a polynomial `p` given a valuation `f` of all the variables -/
168175def eval (p : mv_polynomial σ α) (f : σ → α) : α :=
169176p.sum (λs a, a * s.prod (λn e, f n ^ e))
170177
@@ -209,6 +216,7 @@ end eval
209216
210217section vars
211218
219+ /-- `vars p` is the set of variables appearing in the polynomial `p` -/
212220def vars (p : mv_polynomial σ α) : finset σ := p.support.bind finsupp.support
213221
214222@[simp] lemma vars_0 : (0 : mv_polynomial σ α).vars = ∅ :=
@@ -230,11 +238,13 @@ calc (X n : mv_polynomial σ α).vars = (single n 1).support : vars_monomial h.s
230238end vars
231239
232240section degree_of
241+ /-- `degree_of n p` gives the highest power of X_n that appears in `p` -/
233242def degree_of (n : σ) (p : mv_polynomial σ α) : ℕ := p.support.sup (λs, s n)
234243
235244end degree_of
236245
237246section total_degree
247+ /-- `total_degree p` gives the maximum |s| over the monomials X^s in `p` -/
238248def total_degree (p : mv_polynomial σ α) : ℕ := p.support.sup (λs, s.sum $ λn e, e)
239249
240250end total_degree
0 commit comments