# Why, in any equation, are repeated solutions given by Sage only once?

In the example

var('f, q, r, h, i, g, x, y, z')
eq1 = x^5 - x^4 - 2*x^3 + 2*x^2 + x - 1
solve(eq1==0,x)


Where, this equation is also equal to (x-1)^3*(x+1)^2, but I obtain the following solution:

[x == -1, x == 1]


Let's say that, in any equation, repeated solutions are given by Sage only once.

Then, how can I, in our example, obtain the following complete solution?

[x == -1, x == -1, x == 1, x == 1, x == 1]

edit retag close merge delete

Sort by ยป oldest newest most voted

In order to cover also the multiplicities of the solutions of an algebraic equation, one has the following chances:

$(1)$ Use solve with the option multiplicities=True:

var('x');
f = x^5 - x^4 - 2*x^3 + 2*x^2 + x - 1
solve(f==0, x, multiplicities=True)


This gives:

([x == -1, x == 1], [2, 3])


indicating that the solutions $x=-1$ and respectively $x=1$ have multiplicities $2$, and respectively $3$. To obtain this information, just ask for the doc string of the used function solve:

sage: ?solve

Signature:      solve(f, *args, **kwds)
Docstring:
Algebraically solve an equation or system of equations (over the
complex numbers) for given variables. Inequalities and systems of
inequalities are also supported.

INPUT:

* "f" - equation or system of equations (given by a list or tuple)

* "*args" - variables to solve for.

* "solution_dict" - bool (default: False); if True or non-zero,
return a list of dictionaries containing the solutions. If there
are no solutions, return an empty list (rather than a list
containing an empty dictionary). Likewise, if there's only a
single solution, return a list containing one dictionary with
that solution.

There are a few optional keywords if you are trying to solve a
single equation.  They may only be used in that context.

* "multiplicities" - bool (default: False); if True, return
corresponding multiplicities.  This keyword is incompatible with
"to_poly_solve=True" and does not make any sense when solving
inequalities.


and many other lines.

$(2)$ Use an algebraic object, thus making the used polynomial element in a polynomial ring, then ask for the roots of the polynomial.

R.<x> = PolynomialRing(QQ)
f = x^5 - x^4 - 2*x^3 + 2*x^2 + x - 1
f.roots()


This gives:

[(-1, 2), (1, 3)]


a list of tuples of the shape ( solution, its multiplicity ). So the solution $x=-1$ has multiplicity $2$, and the solution $x=1$ has multiplicity $3$.

This time, if the multiplicities are not wanted, we can ask for this other version of the result...

sage: f.roots(multiplicities=False)
[-1, 1]

more

Thanks a lot!

( 2022-07-14 17:49:39 +0200 )edit

What about this system of equations, which has a repeated root and and we want to know what it is: var('a,b,c,d,e,f,g,x') sols = solve([(a - g) + 2, - (ag - b) - 1, - (bg - c), - (cg - d) + 10, - (dg - e) - 22, - fg - 2, - (eg - f) + 14], a,b,c,d,e,f,g, solution_dict=true) [{g: sol[g]} for sol in sols]

( 2022-07-23 18:49:59 +0200 )edit