# How do I order the solution of Solve?

How can I order the solutions of Solve from the one with the smallest real part to the one with the greatest real part?

• SortBy[Re@*Last]@solutions? – kglr Feb 28 at 14:07
• @kglr exactly thanks – mattiav27 Feb 28 at 14:12
• it seems that solutions returned by Solve are already sorted in the desired order. – kglr Feb 28 at 14:23

You can wrap the output of Solve with SortBy[Re @* Last].

However, I think Solve already returns solutions in the desired order (sorted by the real parts with ties broken by the absolute values of their imaginary part).

Checking the conjecture using 1000 random polynomials:

SeedRandom
polynomials = Table[TypeSystemRandomPolynomial[], 1000];
solutions = DeleteCases[Solve[#[x] == 0., x] & /@ polynomials, {{}}];

solutions == SortBy[Re@*Last] /@ solutions
`

True

• I am considering a much more complicated expression containing continued fraction and the solution are not orderd in the correct way. If you want I can edit my post to add my expression – mattiav27 Feb 28 at 14:41