# Express roots of quadratic equation in a specific form [closed]

By solving this equation, I got two roots as follows:

Solve[1 + Subscript[a, 1]*s + Subscript[a, 2]*s^2 == 0, s]

Is there a way to express it in the form below in Mathematica?
To make it clear, with “form” I mean to say the way parameters are grouped as below. Also, I don’t need to replace rule by equal or square bracket as below.
Thank you all for the help. I thought there is a simple solution to this but it seems that I am too demanding.

=================

=================

2

=================

Let us introduce a function:

f[expr_, x_] := HoldForm[x]*Expand[expr/x];

The quadratic equation of yours is:

ss = Solve[1 + Subscript[a, 1]*s + Subscript[a, 2]*s^2 == 0, s]

Its solutions are:

ss[[1, 1, 2]]

and

ss[[2, 1, 2]]

Check it yourself, otherwise its appearance here is too cumbersome.

Now application of the above function to these two solutions:

f[ss[[1, 1, 2]], -Subscript[a, 1]/(2 Subscript[a, 2])]

f[ss[[2, 1, 2]], -Subscript[a, 1]/(2 Subscript[a, 2])]

returns what you need.

Have fun!

I think you have to do something with the equation like I did or J.M. does in his comment. For instance, your formatting function f with the solution in my answer (omitting Rule -> Equal) gives exactly what the OP seeks. +1
– Michael E2
Mar 6 at 19:12

@Michael E2 In fact the function I introduced is like the function FactorOut from the Presentations of David Park. I would recommend to use the package Presentation best of all, but as soon as not everybody has it…
– Alexei Boulbitch
Mar 7 at 9:16

The underlying form of the desired output is a product (Times) of three factors. I don’t know how much one can change its typesetting, since much of it is automatic. This gets us to the desired forms:

eqn = 1 + Subscript[a, 1]*s + Subscript[a, 2]*s^2 == 0 /.
Subscript[a, 2] -> u Subscript[a, 1]^2 /.
s -> s/Subscript[a, 1]
Solve[eqn, s] /.
{s -> sol_} :> {s -> sol/Subscript[a, 1]} /.
u -> Subscript[a, 2]/Subscript[a, 1]^2 /.
Rule -> Equal