All,
I have a polynomial where I want to factor the portion of it that is a perfect square (example below). I have a solution that works but I want feedback if there are better or more generalizable ways to accomplish the same thing. Any specific feedback on
best practices or 'professional'/'power user' approaches would be most welcome.
Example: The polynomial (which comes from the planar restricted three-body problem): x**2 + 2*mu*x + mu**2 + y**2 -> (x+mu)**2 + y**2. The SymPy solution I have working in a Jupyter notebook:
____________________________________________________________
import sympy as sym
sym.init_printing()
mu, x, y = sym.symbols('mu x y')
expr = x**2 + 2*mu*x + mu**2 + y**2
mx_part = sum(
term for term in expr.as_ordered_terms()
if term.has(mu, x) and not term.has(y)
)
rest = expr - mx_part
sym.factor(mx_part) + rest
____________________________________________________________
Thank you all in advance,
Conrad Schiff, PhD
Professor of Physics
Capitol Technology University