Search code examples
pythonsympypolynomials

Is there a SymPy function that simplifies(shortens) a polynomial expression?


I use SymPy to calculate Bezier curves and my output for x coordinate is

6.0*t**3 + 12.0*t**2*(1 - t) + 6.0*t*(t**2 - 2*t + 1)

while the desired output is 6*t. If you do the math both of these outputs are the same, but one is just not in the shortest form. Any suggestion what to use?


Solution

  • You can achieve this using simplify() function:

    >>> simplify(6.0*t**3 + 12.0*t**2*(1 - t) + 6.0*t*(t**2 - 2*t + 1))
    6.0t