Question about computing the partial derivatives of a multivariate polynomial

Hi all, I got stuck on computing the partial derivatives of a multivariate polynomial.

The following is my code:

using TypedPolynomials
using LinearAlgebra

@polyvar p1 p2 p3 p4 p5 p6 p11 p12 p13 p21 p22 p23 p31 p32 p33
A = [p1 p2 p3]
AT = transpose(A)

B = [p4 p5 p6]
BT = transpose(B)
P = AT*A + BT*B

M=copy(P)
M[1,1] = 2*M[1,1]
M[2,2] = 2*M[2,2]
M[3,3] = 2*M[3,3]

differentiate(det(M), P[1,1])

Here, matrix P is like:

 p1² + p4²        p1p2 + p4p5       p1p3 + p4p6
 p1p2 + p4p5      p2² + p5²         p2p3 + p5p6
 p1p3 + p4p6      p2p3 + p5p6       p3² + p6²  

I want to compute the partial derivative of det(M) with respect to P[1,1], i.e. p1² + p4². But I still couldn’t find a way to compute it. There’s always an error, which is shown below:

ERROR: MethodError: no method matching iterate(::Polynomial{Int64,Term{Int64,Monomial{(p1, p2, p3, p4, p5, p6),6}},Array{Term{Int64,Monomial{(p1, p2, p3, p4, p5, p6),6}},1}})

Is there a package that can be used to solve this problem? Really appreciate!

I guess you have to apply the chain rule yourself for such a non-standard case (this may help).

1 Like

I don’t think there’s such a thing as the partial derivative of a multi-variate polynomial by another multi-variate polynomial; at least not without additional structure (e.g. a metric). What is the result you expect?

2 Likes

Yes, I agree with you. And there’s no package or methods that have been already written that can be used to solve this problem.

I’m expecting the derivative of a specific polynomial. For instance, computing the derivative of

x1^2 + x2^2 + x3^3

with respect to

x1+x2

Everyone knows what you means when you say "the derivative with respect to x1" or "the derivative with respect to x2". It is not clear what you would mean by "the derivative with respect to x1 + x2" or, say, "the derivative with respect to x1^2 * x2". Whatever definition you have in mind is probably not as standard as you seem to think it is. What definition are you using?

To expand a bit on the maths: the partial derivative \frac{\partial}{\partial x_1} implicitly also depends on the coordinates x_2, x_3, \cdots because it computes a slope along the submanifold where x_2,x_3,\cdots are constant. So you can’t just ask for the result of, say, \frac{\partial}{\partial(x_1^2x_2)} without specifying the coordinate system that x_1^2x_2 is a part of.

2 Likes