-
Notifications
You must be signed in to change notification settings - Fork 1
/
polynomial_derivative.py
222 lines (175 loc) · 6.62 KB
/
polynomial_derivative.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sage.misc.misc_c import prod
from sage.functions.other import factorial
from sage.functions.other import binomial
from sage.structure.element import have_same_parent
from matrix_of_vectors import items_of_vector
##############################################################################
# Polynomials as differential operators
##############################################################################
def polynomial_derivative_on_basis(e, f):
"""
Return the differentiation of `f` by `e`.
INPUT:
- `e`, `f` -- exponent vectors representing two monomials `X^e` and `X^f`
(type: :class:`sage.rings.polynomial.polydict.ETuple`)
OUTPUT:
- a pair `(g,c)` where `g` is an exponent vector and `c` a
coefficient, representing the term `c X^g`, or :obj:`None` if
the result is zero.
Let `R=K[X]` be a multivariate polynomial ring. Write `X^e` for
the monomial with exponent vector `e`, and `p(\partial)` the
differential operator obtained by substituting each variable `x`
in `p` by `\frac{\partial}{\partial x}`.
This returns `X^e(\partial)(X^f)`
EXAMPLES::
sage: from sage.rings.polynomial.polydict import ETuple
sage: polynomial_derivative_on_basis(ETuple((4,0)), ETuple((4,0)))
((0, 0), 24)
sage: polynomial_derivative_on_basis(ETuple((0,3)), ETuple((0,3)))
((0, 0), 6)
sage: polynomial_derivative_on_basis(ETuple((0,1)), ETuple((0,3)))
((0, 2), 3)
sage: polynomial_derivative_on_basis(ETuple((2,0)), ETuple((4,0)))
((2, 0), 12)
sage: polynomial_derivative_on_basis(ETuple((2,1)), ETuple((4,3)))
((2, 2), 36)
sage: polynomial_derivative_on_basis(ETuple((1,3)), ETuple((1,2)))
sage: polynomial_derivative_on_basis(ETuple((2,0)), ETuple((1,2)))
"""
g = f.esub(e)
if any(i < 0 for i in g):
return None
return (g, prod(factorial(i)/factorial(j) for (i,j) in zip(f,g)))
def polynomial_derivative(p, q): # this just extends a function by bilinearity; we would want it to be built using ModulesWithBasis
"""
Return the derivative of `q` w.r.t. `p`.
INPUT:
- `p`, `q` -- two polynomials in the same multivariate polynomial ring `\K[X]`
OUTPUT: a polynomial
The polynomial `p(\partial)(q)`, where `p(\partial)` the
differential operator obtained by substituting each variable `x`
in `p` by `\frac{\partial}{\partial x}`.
EXAMPLES::
sage: R = QQ['x,y']
sage: x,y = R.gens()
sage: polynomial_derivative(x, x)
1
sage: polynomial_derivative(x, x^3)
3*x^2
sage: polynomial_derivative(x^2, x^3)
6*x
sage: polynomial_derivative(x+y, x^3)
3*x^2
sage: polynomial_derivative(x+y, x^3*y^3)
3*x^3*y^2 + 3*x^2*y^3
sage: p = -x^2*y + 3*y^2
sage: q = x*(x+2*y+1)^3
sage: polynomial_derivative(p, q)
72*x^2 + 144*x*y + 36*x - 48*y - 24
sage: -diff(q, [x,x,y]) + 3 * diff(q, [y,y])
72*x^2 + 144*x*y + 36*x - 48*y - 24
"""
if not have_same_parent(p,q):
raise ValueError("p and q should have the same parent")
R = p.parent()
result = R.zero() # We would want to use R.sum_of_terms_if_not_None
for (e1, c1) in items_of_vector(p):
for (e2, c2) in items_of_vector(q):
m = polynomial_derivative_on_basis(e1,e2)
if m is None:
continue
(e3,c3) = m
result += R({e3: c1*c2*c3})
return result
def fiej(i, j, d): # fiejcoeff_on_highest_weight
"""
INPUT:
- `i`, `j`, `d` -- nonnegative integers
OUTPUT: a nonnegative integer
Let $f = x\partial_y and e = y\partial_x$, and `p` be a highest
weight polynomial of weight `d`. Then `c=fiej(i,j,d)` is such
that `f^i e^j p = c e^{j-i} p`. `c` is given by the formula::
.. MATH:: \prod_{k = j-i+1}^j (kd - 2 \binom{k}{2})
EXAMPLES::
sage: R = QQ['x,y']
sage: R.inject_variables()
Defining x, y
sage: def f(p): return x*diff(p,y)
sage: def e(p): return y*diff(p,x)
sage: fiej(0,0,3)
1
sage: fiej(0,1,3)
1
sage: f(e(x^3)) / x^3
3
sage: fiej(1,1,3)
3
sage: f(f(e(x^3)))
0
sage: fiej(2,1,3)
0
sage: fiej(0,2,3)
1
sage: f(e(e(x^3))) / e(x^3)
4
sage: fiej(1,2,3)
4
sage: f(f(e(e(x^3)))) / x^3
12
sage: fiej(2,2,3)
12
sage: fiej(0,3,3)
1
sage: f(e(e(e(x^3)))) / e(e(x^3))
3
sage: fiej(1,3,3)
3
sage: f(f(e(e(e(x^3))))) / e(x^3)
12
sage: f(f(f(e(e(e(x^3)))))) / x^3
36
sage: fiej(3,3,3)
36
sage: fiej(4,3,3)
0
sage: f(f(f(e(e(e(x^9)))))) / x^9
3024
sage: fiej(3,3,9)
3024
"""
return binomial(j, i) * binomial(d-j+i,i) * factorial(i)**2
#return prod( k*d - 2*binomial(k,2) for k in range(j-i+1,j+1) )
def string_matrix(d, l):
"""
Return the string matrix for `d`, `l`
Let `p = \sum e^j p^{(j)}` where each `p^{(j)}` is a highest
weight vector, and the sum is homogeneous.
Then `f^i(p)` is also a linear combination of the e^j
This return a matrix whose `i`-th row contains the coefficients of
the expansion of `f^i(p)` as a linear combination of the
`e^(j-i)p^{(j)}`.
"""
return matrix(l, l, lambda i,j: fiej(i,j,d+2*j))
"""
Consistency checks::
sage: P = DiagonalPolynomialRing(QQ,2,1) #not tested
sage: for mu in Partitions(2): #not tested
....: assert P.harmonic_space_by_shape(mu,use_lie='multipolarization').hilbert_polynomial() == harmonic_character(mu) #not tested
sage: P = DiagonalPolynomialRing(QQ,3,2) #not tested
sage: for mu in Partitions(3): #not tested
....: assert P.harmonic_space_by_shape(mu,use_lie='multipolarization').hilbert_polynomial() == harmonic_character(mu) #not tested
This does not work yet::
sage: P = DiagonalPolynomialRing(QQ,4,3) #not tested
sage: for mu in Partitions(4): #not tested
....: assert P.harmonic_space_by_shape(mu,use_lie='multipolarization').hilbert_polynomial() == harmonic_character(mu) #not tested
AssertionError
sage: mu #not tested
[2, 1, 1]
sage: harmonic_character(mu) #not tested
s[1, 1] + s[2, 1] + s[3] + s[3, 1] + s[4] + s[5]
sage: P.harmonic_space_by_shape(mu,use_lie='multipolarization').hilbert_polynomial() #not tested
s[1, 1] + s[2, 1] + s[3] + s[4] + s[5]
Somehow missing 3,1 by polarizing from 5???
"""