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

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/sympy/CH3PR12MB943286CEB392CDC093CCC58BCFA9A%40CH3PR12MB9432.namprd12.prod.outlook.com.

Reply via email to