mrkwjc
mrkwjc

Reputation: 1219

Simplification of square root of sum

Using SymPy, can I automatically simplify something like this:

sqrt(a**2 + 2ab + b**2)

to:

[(a+b), -(a+b)]?

Upvotes: 1

Views: 385

Answers (1)

smichr
smichr

Reputation: 19057

Perhaps something like:

>>> var('a b',positive=True)
(a, b)
>>> solve(x**2-(a**2 + 2*a*b + b**2), x)
[-a - b, a + b]

Upvotes: 1

Related Questions