Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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]