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

Commit 11e62b0

Browse files
fix(data/mv_polynomial/pderivative): rename variables and file, make it universe polymorphic (#4083)
This file originally used different variable names to the rest of `mv_polynomial`. I've changed it to now use the same conventions as the other files. I also renamed the file to `pderivative.lean` to be consistent with `derivative.lean` for polynomials. The types of the coefficient ring and the indexing variables are now universe polymorphic. The diff shows it as new files, but the only changes are fixing the statements and proofs.
1 parent 98061d1 commit 11e62b0

File tree

2 files changed

+156
-153
lines changed

2 files changed

+156
-153
lines changed

src/data/mv_polynomial/pderiv.lean

Lines changed: 0 additions & 153 deletions
This file was deleted.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Shing Tak Lam
5+
-/
6+
7+
import data.mv_polynomial.variables
8+
import tactic.ring
9+
10+
/-!
11+
# Partial derivatives of polynomials
12+
13+
This file defines the notion of the formal *partial derivative* of a polynomial,
14+
the derivative with respect to a single variable.
15+
This derivative is not connected to the notion of derivative from analysis.
16+
It is based purely on the polynomial exponents and coefficients.
17+
18+
## Main declarations
19+
20+
* `mv_polynomial.pderivative i p` : the partial derivative of `p` with respect to `i`.
21+
22+
## Notation
23+
24+
This file uses notation slightly different from other `mv_polynomial` files:
25+
26+
+ `σ : Type*` (indexing the variables)
27+
28+
+ `R : Type*` `[comm_ring R]` (the coefficients)
29+
30+
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
31+
This will give rise to a monomial in `mv_polynomial σ R` which mathematicians might call `X^s`
32+
33+
+ `a : R`
34+
35+
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
36+
37+
+ `p : mv_polynomial σ R`
38+
39+
-/
40+
41+
noncomputable theory
42+
43+
open_locale classical big_operators
44+
45+
open set function finsupp add_monoid_algebra
46+
open_locale big_operators
47+
48+
universes u
49+
variables {R : Type u}
50+
51+
namespace mv_polynomial
52+
variables {σ : Type*} {a a' a₁ a₂ : R} {s : σ →₀ ℕ}
53+
54+
section pderivative
55+
56+
variables {R} [comm_semiring R]
57+
58+
/-- `pderivative i p` is the partial derivative of `p` with respect to `i` -/
59+
def pderivative (i : σ) (p : mv_polynomial σ R) : mv_polynomial σ R :=
60+
p.sum (λ A B, monomial (A - single i 1) (B * (A i)))
61+
62+
@[simp]
63+
lemma pderivative_add {i : σ} {f g : mv_polynomial σ R} :
64+
pderivative i (f + g) = pderivative i f + pderivative i g :=
65+
begin
66+
refine sum_add_index _ _,
67+
{ simp },
68+
simp [add_mul],
69+
end
70+
71+
@[simp]
72+
lemma pderivative_monomial {i : σ} :
73+
pderivative i (monomial s a) = monomial (s - single i 1) (a * (s i)) :=
74+
by simp [pderivative]
75+
76+
@[simp]
77+
lemma pderivative_C {i : σ} : pderivative i (C a) = 0 :=
78+
suffices pderivative i (monomial 0 a) = 0, by simpa,
79+
by simp
80+
81+
@[simp]
82+
lemma pderivative_zero {i : σ} : pderivative i (0 : mv_polynomial σ R) = 0 :=
83+
suffices pderivative i (C 0 : mv_polynomial σ R) = 0, by simpa,
84+
show pderivative i (C 0 : mv_polynomial σ R) = 0, from pderivative_C
85+
86+
section
87+
variables (R)
88+
89+
/-- `pderivative : S → mv_polynomial σ R → mv_polynomial σ R` as an `add_monoid_hom` -/
90+
def pderivative.add_monoid_hom (i : σ) : mv_polynomial σ R →+ mv_polynomial σ R :=
91+
{ to_fun := pderivative i,
92+
map_zero' := pderivative_zero,
93+
map_add' := λ x y, pderivative_add, }
94+
95+
@[simp]
96+
lemma pderivative.add_monoid_hom_apply (i : σ) (p : mv_polynomial σ R) :
97+
(pderivative.add_monoid_hom R i) p = pderivative i p :=
98+
rfl
99+
end
100+
101+
lemma pderivative_eq_zero_of_not_mem_vars {i : σ} {f : mv_polynomial σ R} (h : i ∉ f.vars) :
102+
pderivative i f = 0 :=
103+
begin
104+
change (pderivative.add_monoid_hom R i) f = 0,
105+
rw [f.as_sum, add_monoid_hom.map_sum],
106+
apply finset.sum_eq_zero,
107+
intros,
108+
simp [mem_support_not_mem_vars_zero H h],
109+
end
110+
111+
lemma pderivative_monomial_single {i : σ} {n : ℕ} :
112+
pderivative i (monomial (single i n) a) = monomial (single i (n-1)) (a * n) :=
113+
by simp
114+
115+
private lemma monomial_sub_single_one_add {i : σ} {s' : σ →₀ ℕ} :
116+
monomial (s - single i 1 + s') (a * (s i) * a') =
117+
monomial (s + s' - single i 1) (a * (s i) * a') :=
118+
by by_cases h : s i = 0; simp [h, sub_single_one_add]
119+
120+
private lemma monomial_add_sub_single_one {i : σ} {s' : σ →₀ ℕ} :
121+
monomial (s + (s' - single i 1)) (a * (a' * (s' i))) =
122+
monomial (s + s' - single i 1) (a * (a' * (s' i))) :=
123+
by by_cases h : s' i = 0; simp [h, add_sub_single_one]
124+
125+
lemma pderivative_monomial_mul {i : σ} {s' : σ →₀ ℕ} :
126+
pderivative i (monomial s a * monomial s' a') =
127+
pderivative i (monomial s a) * monomial s' a' + monomial s a * pderivative i (monomial s' a') :=
128+
begin
129+
simp [monomial_sub_single_one_add, monomial_add_sub_single_one],
130+
congr,
131+
ring,
132+
end
133+
134+
@[simp]
135+
lemma pderivative_mul {i : σ} {f g : mv_polynomial σ R} :
136+
pderivative i (f * g) = pderivative i f * g + f * pderivative i g :=
137+
begin
138+
apply induction_on' f,
139+
{ apply induction_on' g,
140+
{ intros u r u' r', exact pderivative_monomial_mul },
141+
{ intros p q hp hq u r,
142+
rw [mul_add, pderivative_add, hp, hq, mul_add, pderivative_add],
143+
ring } },
144+
{ intros p q hp hq,
145+
simp [add_mul, hp, hq],
146+
ring, }
147+
end
148+
149+
@[simp]
150+
lemma pderivative_C_mul {f : mv_polynomial σ R} {i : σ} :
151+
pderivative i (C a * f) = C a * pderivative i f :=
152+
by rw [pderivative_mul, pderivative_C, zero_mul, zero_add]
153+
154+
end pderivative
155+
156+
end mv_polynomial

0 commit comments

Comments
 (0)