How to factor out a constant?

23 views
Skip to first unread message

Paul Royik

unread,
Dec 14, 2021, 8:53:28 AM12/14/21
to sympy
In any expression, how to factor a constant (that doesn't depend on certain symbols)?

For example (-2xy+2).factor_function(x,y) should give 2, (1-xy).

as_coeff_mul doesn't work.

Oscar Benjamin

unread,
Dec 14, 2021, 9:22:39 AM12/14/21
to sympy
Maybe factor_terms is what you want:

In [50]: factor_terms(-2*x*y + 2)
Out[50]: 2⋅(-x⋅y + 1)

--
Oscar
Reply all
Reply to author
Forward
0 new messages