math - Factoring fractions in sympy -


how ask sympy factor x**2 - 3/2*x + 1/2 (x-1)*(x-1/2)? closest i've gotten is:

>>> (x**2  - rational(3/2)*x + rational(1/2)).factor() (x - 1)*(2*x - 1)/2 

a simple way:

in [1]: expr = (x**2  - rational(3/2)*x + rational(1/2))  in [2]: expr out[2]:   2   3*x   1 x  - --- + -       2    2  in [3]: fe = factor(expr)  in [4]: fe out[4]:  (x - 1)*(2*x - 1) -----------------         2          in [5]: fe.args out[5]: (1/2, x - 1, 2*x - 1)  in [6]: fe.args[0]*fe.args[2]*fe.args[1] out[6]: (x - 1)*(x - 1/2) 

that is, factor expression [3], product arguments [5], , multiply them [6]. multiplication in step [6] calls evaluation routines simplify expression, not point of expanding it.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -