# Converting expression to quadratic formula

I want to manipulate and represent the following expression in a more presentable way.

-((6 (-beta + 2 beta x/n))/(8 beta + 9 n)) +
3 Sqrt[2] Sqrt[(
2 beta^2 + 9 beta n x/n - 9 beta n (x/n)^2)/(8 beta + 9 n)^2]

This looks like a quadratic formula (Not necessarily in the variable x). How can I manipulate the expression above to get the coefficients a,b,c to represent it as

$$\frac{-b \pm \sqrt{b^2-4 a c}}{2 a}$$

My formula looks like a qudratic with a=(8 beta + 9 n)

• Series[expr, {x, 0, 4}] // Normal shows that you expression is not quadratic in x Oct 29, 2023 at 19:08
• Please see the edited question Oct 29, 2023 at 19:13

I'd start by defining

f = -((6 (-β + 2 β x/n))/(8 β + 9 n)) + 3 Sqrt[2] Sqrt[(2 β^2 + 9 β n x/n - 9 β n (x/n)^2)/(8 β + 9 n)^2];

and then checking if we can find a formula $$f^2+u f+v=0$$:

f^2 + u f // Expand
(*    lots of terms    *)

notice that the three last terms in this expansion have a square root in them. Together, they are exactly zero if $$u$$ has the value

Solve[%[[-3 ;;]] == 0, u] // FullSimplify
(*    {{u -> -((12 (n - 2 x) β)/(n (9 n + 8 β)))}}

Let's try it out: this combination is indeed square-root-free,

f^2 - (12 (n - 2 x) β)/(n (9 n + 8 β)) * f // FullSimplify
(*    (18 (n - x) x β)/(n^2 (9 n + 8 β))    *)

and therefore

f^2 - (12 (n - 2 x) β)/(n (9 n + 8 β)) * f - (18 (n - x) x β)/(n^2 (9 n + 8 β)) // FullSimplify
(*    0    *)

Expand this equation by multiplying all terms by $$n^2 (8 \beta +9 n)$$:

n^2 (9 n + 8 β) * f^2 - 12 n (n - 2 x) β * f - 18 (n - x) x β // FullSimplify
(*    0    *)

Now we have a quadratic equation for $$f$$, and the formula you're looking for follows from it with

$$a = n^2 (9n+8\beta)\\ b=-12\beta n(n-2x)\\ c=-18\beta x(n-x)$$

a = n^2 (9 n + 8 β);
b = -12 n (n - 2 x) β;
c = -18 (n - x) x β;

Assuming[n > 0 && β > 0,
f == (-b + Sqrt[b^2 - 4 a c])/(2 a) // FullSimplify]
(*    True    *)
• Thank you so much!! Oct 29, 2023 at 23:18
-((6 (-beta + 2 beta x/n))/(8 beta + 9 n)) +
3 Sqrt[2] Sqrt[(2 beta^2 + 9 beta n x/n -
9 beta n (x/n)^2)/(8 beta + 9 n)^2] //
PowerExpand // FullSimplify

$$\frac{6 \text{beta} (n-2 x)+3 \sqrt{2} n \sqrt{\text{beta} \left(2 \text{beta}+\frac{9 x (n-x)}{n}\right)}}{n (8 \text{beta}+9 n)}$$

If you want it with ±:

-((6 (-beta + 2 beta x/n))/(8 beta + 9 n)) +
3 Sqrt[2] Sqrt[(2 beta^2 + 9 beta n x/n -
9 beta n (x/n)^2)/(8 beta + 9 n)^2] // FullSimplify;
PlusMinus @@ % // PowerExpand // FullSimplify

$$\frac{6 \text{beta} (n-2 x)}{n (8 \text{beta}+9 n)}\pm \frac{3 \sqrt{2} \sqrt{\text{beta}} \sqrt{2 \text{beta} n+9 x (n-x)}}{\sqrt{n} (8 \text{beta}+9 n)}$$