# Finding and differentiating with respect to variables

I have a list of polynomials in x1,x2,x3,y,z,t. I want to differentiate each list element (polynomial) recursively with respect to all xi until they vanish in the polynomial. For example, if I have the polynomial

p = x1 x3^2 y t + x2 y^2 + x1^3 z t + x1 x2 y z + x1^2 x2 y t


then I differentiate with respect to x1,x1,x2 and get 2*y*t. Alternatively, I could differentiate with respect to x3, x3, x1 and get the same result. So the final expression does not contain xi. Any idea how to do that is appreciated.

• Variables and CoefficientRules might be helpful. – Henrik Schumacher Feb 13 at 10:55
• Thanks. Sorry, still unclear how I can manage the above. – Bran Feb 13 at 11:11
• I didn't revert anything. Why isn't it a polynomial? – Bran Feb 13 at 11:19
• OK. I have now used the * notation for multiplication. – Bran Feb 13 at 11:22
• Ah, okay, that it was because we submitted the edits almost at the same time. – Henrik Schumacher Feb 13 at 11:27

We may employ CoefficientRules to obtain the coefficients of the polynomial with respect to x1, x2, x3.

p = x1 x3^2 y t + x2 y^2 + x1^3 z t + x1 x2 y z + x1^2 x2 y t;
r = CoefficientRules[p, {x1, x2, x3}]


{{3, 0, 0} -> t z, {2, 1, 0} -> t y, {1, 1, 0} -> y z, {1, 0, 2} -> t y, {0, 1, 0} -> y^2}

For example, {2, 1, 0} -> t y means that the coefficient of x1^2 x2^1 x3^0 is t y. We only have to correct for the factors that arise due to differentiation. This can be done as follows:

r[[All, 2]] *= Times @@@ (r[[All, 1]]!);
r


{{2, 1, 0} -> 2 t y, {1, 1, 0} -> y z, {1, 0, 2} -> 2 t y, {0, 1, 0} -> y^2, {0, 0, 0} -> t x^3 z}

• Thanks. So the differentiation result will be the sum of those coefficients? Also, I am getting the error "Part 2 does not exist" for the second command. – Bran Feb 13 at 12:46
• " So the differentiation result will be the sum of those coefficients?" Nope. Each of the values in the final list is a result of a separate differentiation. – Henrik Schumacher Feb 13 at 12:49
• But I need the polynomial differentiated with respect all xi and have the result as a polynomial without xi as in my example. – Bran Feb 13 at 12:55
• That's what the code above provides. There are no xi left. – Henrik Schumacher Feb 13 at 12:56
• OK, but I'm getting an error: Part 2 does not exist – Bran Feb 13 at 12:57