Is your feature request related to a problem? Please describe.
This is a followup to #20076. It would be nice to have first class support to convert between SymPy Polynomials and pydrake.symbolic.Polynomial.
Note that currently this is not possible. Consider the following code.
The result is that sympy_poly has generators x and x**2. The reason for this is that drake_sym.to_sympy(drake_poly.ToExpression(), memo=x_drake_to_sympy) has in its expression tree:
Pow(Symbol('x'), Float('2.0', precision=53)
Since the exponent of x**2 is a Float and not an Integer, then Sympy cannot cast it to a polynomial properly.
Describe the solution you'd like
Ideally we can write the above code as:
Is your feature request related to a problem? Please describe. This is a followup to #20076. It would be nice to have first class support to convert between SymPy Polynomials and pydrake.symbolic.Polynomial.
Note that currently this is not possible. Consider the following code.
The result is that
sympy_poly
has generatorsx
andx**2
. The reason for this is thatdrake_sym.to_sympy(drake_poly.ToExpression(), memo=x_drake_to_sympy)
has in its expression tree:Since the exponent of
x**2
is a Float and not an Integer, then Sympy cannot cast it to a polynomial properly.Describe the solution you'd like Ideally we can write the above code as:
and avoid all the casting back and forth between the expressions.
At the very least, drake's
ExpressionKind::Pow
should be converted to sympy'sPow(x, Integer(*))
rather thanPow(x, Float(*))
whenever possible.