pythonsage

What does a solution like r5 or c15415 mean when i use solve() from SageMath (Python)?


i implemented a system of complex valued functions and i solved it with sagemath's "solve" method.

In my solutions array i find entries like:

x1 == r5 or for different cases x1 == c15403. (and so on with diffent numbers)

Does the r5 stand for an arbitary rational number and c15403 for arbitary complex number?

Maybe someone can give me a hint where to find such stuff in the documentation.

Ty and have nice day.


Solution

  • Yes, 'c' stands for complex. I think that 'r' stands for real, 'z' stands for integer. I don't know if there is a symbol for rationals. I don't know where it's documented, but I believe this comes from Maxima, which Sage uses as a solver. See the documentation for new_variable at https://maxima.sourceforge.io/docs/manual/maxima_346.html#Functions-and-Variables-for-to_005fpoly_005fsolve, and in particular look at the first code example.

    The Sage reference manual mentions the r and z prefixes in the documentation of the solve method of symbolic relations. Slightly amended excerpt:

    If there is a parameter in the answer, that will show up as a new variable. In the following example, r1 is an arbitrary real (hence the r).

    sage: forget()
    sage: x, y = var('x, y')
    sage: solve([x + y == 3, 2*x + 2*y == 6], x, y)
    [[x == -r1 + 3, y == r1]]
    sage: b, c = var('b, c')
    sage: solve((b - 1)*(c - 1), [b, c])
    [[b == 1, c == r...], [b == r..., c == 1]]
    

    Especially with trigonometric functions, the dummy variable may be implicitly an integer (hence the z).

    sage: solve(sin(x) == cos(x), x, to_poly_solve=True)
    [x == 1/4*pi + pi*z...]
    sage: solve([cos(x)*sin(x) == 1/2, x + y == 0], x, y)
    [[x == 1/4*pi + pi*z..., y == -1/4*pi - pi*z...]]