Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A bug in sympy, indeed.

Another workaround, using Sage's default solver (i. e. maxima's) and filtering afterwards:

sage: [s for s in solve([x^3-y^2==21/2, 3*x*y+y==23/5],[x,y], solution_dict=True) if s[x].is_real() and s[y].is_real()]
[{x: 2.21465033180194, y: 0.6017830609212481}]

Note: unless you have compelling reasons (e. g. speed) to use numerical approximations, taking advantage of Sage's ability to use exact representations of quantities defined in exact terms is usually a good idea...

A bug in sympy, indeed.indeed. EDIT : No, it's a (non-) feature of Sage. From the docstring :

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

And below (i. e. in the "single equation" context :

"algorithm" - string (default: 'maxima'); to use SymPy's solvers set this to 'sympy'. Note that SymPy is always used for diophantine equations.

One may try to use directly the sympy solvers ; the point is to sympify the arguments (correctly...). And to convert the result back to Sage...

Another workaround, using Sage's default solver (i. e. maxima's) and filtering afterwards:afterwards :

sage: [s for s in solve([x^3-y^2==21/2, 3*x*y+y==23/5],[x,y], solution_dict=True) if s[x].is_real() and s[y].is_real()]
[{x: 2.21465033180194, y: 0.6017830609212481}]

Note: unless you have compelling reasons (e. g. speed) to use numerical approximations, taking advantage of Sage's ability to use exact representations of quantities defined in exact terms is usually a good idea...