# If $a+b=x$ and $ab=y$, what is the quickest way to solve for $a$ and $b$?

The mechanistic approach would be to simply substitute $b=y/a$ in the first equation to obtain a quadratic in $a$. But seeing the simplicity of the givens, I feel that there must be some better and elegant ways to do this.

The best way I could think of is this:

$(a-b)^2 = (a+b)^2 - 4ab \iff (a-b)^2 = x^2 - 4y \iff a-b = \pm\sqrt{x^2 - 4y}$

Solving this with $a+b=x$, we get the result.

It might be the case that there aren't many ways other than this, but that's okay. If there are, I'd be interested to read them.

Edit: Also, if we know that both $a$ and $b$ are non-negative, can we use this information for a better solution?

-
Yes. The non-negative condition comes in handy especially during special cases that i have mentioned in my answer below. – lsp Apr 5 '13 at 11:59

We would always get a quadratic.

Maybe one bit easier if we use the following observation (Viète's formulas): $$(Z-a)(Z-b)=Z^2-(a+b)Z+ab\,.$$ So, $a,b$ are just the solutions of $Z^2-xZ+y=0$.

-
(+1) You just beat me to it. – TMM Apr 5 '13 at 11:55
@Berci, yes, this is applicable to some cases, if it is easy enough to factorise. In other words, we are just guessing the answers. So maybe not generally working if the solution is not that neat. – Easy Apr 5 '13 at 11:58
What do you mean? With any method, we must get $a,b=\displaystyle\frac{x\pm\sqrt{x^2-4y}}2$. – Berci Apr 5 '13 at 13:39

Method $1$: The quadratic equation method

Method $2$ : The one you mentioned in your question.

Method $3$ : (Special Cases)

Always check for special cases and special conditions first before going about solving.

Conditions like $(a,b)$ are integers might help out. Condition like $(a,b)$ are positive might also help in some cases where you can use AM $\geq$ GM and the solution might turn out to be the equality case.

-

A standard approach (Buchberger's algorithm to find a Grobner basis) to solving systems of polynomial equations involves cancelling monomials. We can use $a$ in one equation to cancel out $ab$ as follows:

$$b (a+b) - ab = b x - y$$ $$b^2 = bx - y$$

and then solve the quadratic equation for $b$.

-