Reputation: 33
I have found this annoying problem in sympy. I want to simply the following simple fraction expression below but can't make it work... Sympy even recognizes the two equations as equal making it even more frustrating.
import sympy as sp
a,b,c,d = sp.symbols('a, b, c, d', positive = True)
expr = (a*b*c+2*d*a*c+b*c*d)/(2*a+b)
correct_simpl = c*(d + a*b/(2*a+b))
display(expr)
display(expr.simplify())
display(correct_simpl)
correct_simpl.equals(expr)
Upvotes: 2
Views: 80
Reputation: 19125
The following can give you your expression of taste. You can use your interactive prompt to see what each of the steps is doing. The cse
is there to collect that 2a+b
into a single term that doesn't expand when doing the expansion: r,e=cse(factor_terms(collect(expr,d)));expand(e[0]).subs(r)
Upvotes: 1