Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 623c846

Browse files
committed
feat(data/mv_polynomial/variables): add facts about vars and mul (#4149)
More from the Witt vectors branch. Co-authored by: Johan Commelin <johan@commelin.net> Co-authored-by: Rob Lewis <rob.y.lewis@gmail.com>
1 parent 6603c6d commit 623c846

File tree

1 file changed

+80
-4
lines changed

1 file changed

+80
-4
lines changed

src/data/mv_polynomial/variables.lean

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ variables [comm_semiring α] {p q : mv_polynomial σ α}
7272

7373
section degrees
7474

75+
/-! ### `degrees` -/
76+
7577
/--
7678
The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
7779
@@ -204,6 +206,8 @@ end degrees
204206

205207
section vars
206208

209+
/-! ### `vars` -/
210+
207211
/-- `vars p` is the set of variables appearing in the polynomial `p` -/
208212
def vars (p : mv_polynomial σ α) : finset σ := p.degrees.to_finset
209213

@@ -219,6 +223,10 @@ by rw [vars, degrees_C, multiset.to_finset_zero]
219223
@[simp] lemma vars_X (h : 0 ≠ (1 : α)) : (X n : mv_polynomial σ α).vars = {n} :=
220224
by rw [X, vars_monomial h.symm, finsupp.support_single_ne_zero (one_ne_zero : 10)]
221225

226+
lemma mem_vars (i : σ) :
227+
i ∈ p.vars ↔ ∃ (d : σ →₀ ℕ) (H : d ∈ p.support), i ∈ d.support :=
228+
by simp only [vars, multiset.mem_to_finset, mem_degrees, coeff, finsupp.mem_support_iff, exists_prop]
229+
222230
lemma mem_support_not_mem_vars_zero {f : mv_polynomial σ α} {x : σ →₀ ℕ} (H : x ∈ f.support) {v : σ} (h : v ∉ vars f) :
223231
x v = 0 :=
224232
begin
@@ -251,6 +259,71 @@ begin
251259
exact hx
252260
end
253261

262+
section mul
263+
264+
lemma vars_mul (φ ψ : mv_polynomial σ α) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars :=
265+
begin
266+
intro i,
267+
simp only [mem_vars, finset.mem_union],
268+
rintro ⟨d, hd, hi⟩,
269+
rw [finsupp.mem_support_iff, ← coeff, coeff_mul] at hd,
270+
contrapose! hd, cases hd,
271+
rw finset.sum_eq_zero,
272+
rintro ⟨d₁, d₂⟩ H,
273+
rw finsupp.mem_antidiagonal_support at H,
274+
subst H,
275+
obtain H|H : i ∈ d₁.support ∨ i ∈ d₂.support,
276+
{ simpa only [finset.mem_union] using finsupp.support_add hi, },
277+
{ suffices : coeff d₁ φ = 0, by simp [this],
278+
rw [coeff, ← finsupp.not_mem_support_iff], intro, solve_by_elim, },
279+
{ suffices : coeff d₂ ψ = 0, by simp [this],
280+
rw [coeff, ← finsupp.not_mem_support_iff], intro, solve_by_elim, },
281+
end
282+
283+
@[simp] lemma vars_one : (1 : mv_polynomial σ α).vars = ∅ :=
284+
vars_C
285+
286+
lemma vars_pow (φ : mv_polynomial σ α) (n : ℕ) : (φ ^ n).vars ⊆ φ.vars :=
287+
begin
288+
induction n with n ih,
289+
{ simp },
290+
{ rw pow_succ,
291+
apply finset.subset.trans (vars_mul _ _),
292+
exact finset.union_subset (finset.subset.refl _) ih }
293+
end
294+
295+
/--
296+
The variables of the product of a family of polynomials
297+
are a subset of the union of the sets of variables of each polynomial.
298+
-/
299+
lemma vars_prod {ι : Type*} {s : finset ι} (f : ι → mv_polynomial σ α) :
300+
(∏ i in s, f i).vars ⊆ s.bind (λ i, (f i).vars) :=
301+
begin
302+
apply s.induction_on,
303+
{ simp },
304+
{ intros a s hs hsub,
305+
simp only [hs, finset.bind_insert, finset.prod_insert, not_false_iff],
306+
apply finset.subset.trans (vars_mul _ _),
307+
exact finset.union_subset_union (finset.subset.refl _) hsub }
308+
end
309+
310+
section integral_domain
311+
variables {A : Type*} [integral_domain A]
312+
313+
lemma vars_C_mul (a : A) (ha : a ≠ 0) (φ : mv_polynomial σ A) : (C a * φ).vars = φ.vars :=
314+
begin
315+
ext1 i,
316+
simp only [mem_vars, exists_prop, finsupp.mem_support_iff],
317+
apply exists_congr,
318+
intro d,
319+
apply and_congr _ iff.rfl,
320+
rw [← coeff, ← coeff, coeff_C_mul, mul_ne_zero_iff, eq_true_intro ha, true_and],
321+
end
322+
323+
end integral_domain
324+
325+
end mul
326+
254327
section sum
255328

256329
variables {ι : Type*} (t : finset ι) (φ : ι → mv_polynomial σ α)
@@ -304,10 +377,6 @@ lemma vars_monomial_single (i : σ) {e : ℕ} {r : α} (he : e ≠ 0) (hr : r
304377
(monomial (finsupp.single i e) r).vars = {i} :=
305378
by rw [vars_monomial hr, finsupp.support_single_ne_zero he]
306379

307-
lemma mem_vars (i : σ) :
308-
i ∈ p.vars ↔ ∃ (d : σ →₀ ℕ) (H : d ∈ p.support), i ∈ d.support :=
309-
by simp only [vars, multiset.mem_to_finset, mem_degrees, coeff, finsupp.mem_support_iff, exists_prop]
310-
311380
lemma vars_eq_support_bind_support : p.vars = p.support.bind finsupp.support :=
312381
by { ext i, rw [mem_vars, finset.mem_bind] }
313382

@@ -317,12 +386,17 @@ end vars
317386

318387
section degree_of
319388

389+
/-! ### `degree_of` -/
390+
320391
/-- `degree_of n p` gives the highest power of X_n that appears in `p` -/
321392
def degree_of (n : σ) (p : mv_polynomial σ α) : ℕ := p.degrees.count n
322393

323394
end degree_of
324395

325396
section total_degree
397+
398+
/-! ### `total_degree` -/
399+
326400
/-- `total_degree p` gives the maximum |s| over the monomials X^s in `p` -/
327401
def total_degree (p : mv_polynomial σ α) : ℕ := p.support.sup (λs, s.sum $ λn e, e)
328402

@@ -451,6 +525,8 @@ end total_degree
451525

452526
section eval_vars
453527

528+
/-! ### `vars` and `eval` -/
529+
454530
variables {R : Type u} {A : Type v} {S : Type w} (f : σ → A)
455531
variables [comm_semiring R] [comm_semiring A] [algebra R A] [comm_semiring S]
456532

0 commit comments

Comments
 (0)