# How to avoid Mathematica output the simplified the squared root term by factoring some coefficient

When I use Mathematica to calculate some roots of an quadratic equation, it will output the simplified answer like $$\frac{-w \sqrt{-h} \sqrt{4 \theta ^2 p-4 \theta p-h}+h w+2 \theta p w}{2 \theta ( p+h)}$$. In this solution, $$r, p$$ are both required to be nonnegative. So the answer given by Mathematica may result in Imaginary solution. I knew that Mathematica has given an option that "Assumption". But when the solving equation is complex, the computation time is unbearable. So is there another method to get correct result? Or is there some simple method to calculate the product of two squared root terms?

Here is an example:

eqn = (p (p (v - w)^2 \[Theta] + h v (-w + v \[Theta])))/(2 (h + p) v)
Solve[eqn == 0, v]


The result is $$\left\{\left\{v\to \frac{-\sqrt{-h} w \sqrt{-h+4 \theta ^2 p-4 \theta p}+h w+2 \theta p w}{2 (h \theta +\theta p)}\right\},\left\{v\to \frac{\sqrt{-h} w \sqrt{-h+4 \theta ^2 p-4 \theta p}+h w+2 \theta p w}{2 (h \theta +\theta p)}\right\}\right\}$$

• sol = Simplify[Solve[eqn == 0, v], {h >= 0, p >= 0}] Commented Jun 30, 2022 at 14:59
• This answer also work! Thanks!!
– Wynn
Commented Jul 1, 2022 at 2:55

## 1 Answer

I am not entirely sure about what you were asking.. But if you want to give assumptions to Mathematica, you can do it like this, and it often reduces computation time rather than making it longer:

eqn = (p (p (v - w)^2 \[Theta] + h v (-w + v \[Theta])))/(2 (h + p) v);
FullSimplify[
Assuming[Element[r, NonNegative] && Element[p, NonNegative],
Solve[eqn == 0, v]]]
Timing[%]


Which gives the results

Where computation time is neglectible.

• Sorry for my poor English and your understanding is right. I'm a newer to Mathematica. And I used Solve[eqn==0, v, Assumptions -> {h >=0, p >= 0, \[Theta] >=0}] to find these roots, which is proved to be time-consuming. Maybe it is a bad usage for this situation. And my problem description is different from the example that h is replaced by r*p. It may confused you
– Wynn
Commented Jul 1, 2022 at 2:53