Skip to content
Advertisement

Substitute the variables of a polynomial with caracas (Sympy)

I have a long polynomial in four variables x, y, z, w:

JavaScript

I’m working with R. I want to use the caracas package (a wrapper of Sympy) to get this expression as a polynomial after doing a change of variables. Namely, I want to substitue x, y, z and w by

JavaScript

respectively. I tried subs with no luck. Here is the only working way I found:

JavaScript

But after 30 minutes the computation of poly is not finished. Is there a more efficient way?

Advertisement

Answer

Rather than generating the full expression and then requesting coefficients of the expansion when you are done, you can take it term-by-term. I have done so twice with the full expression, but you can do so with the toy expression that is followed by your full expression as a comment:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement