Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve should convert additional args to SR #5679

Open
williamstein opened this issue Apr 4, 2009 · 3 comments
Open

solve should convert additional args to SR #5679

williamstein opened this issue Apr 4, 2009 · 3 comments

Comments

@williamstein
Copy link
Contributor

Some code that used to work in sage-3.0.6 (or something close like
3.0.3), now break with this error message:

>>> R.<x0,x1,x2> = PolynomialRing(RR, 3)
>>> solve([symbolic_expression(x0) == 0], x0, x1, x2)

TypeError: not all arguments converted during string formatting

BUT:
sage: solve([symbolic_expression(x0) == 0], SR(x0), SR(x1), SR(x2))
([{x0: 0}], [1])

The printing problem is due to the fact that Polynomials have an
implicit conversion to sequence types triggered by this code:

       try:
           variables = tuple(args[0])
       except TypeError:
           variables = args

near the start of solve(), (Hint: tuple(args[0]) works if the first
variable is a PolynomialElement and thus the rest of the vars are
ignored and you get the bogus ((1.0000000, x0),) tuple as variables)

If that is fixed, then you get this message which does not help much more:

>>> R.<x0,x1,x2> = PolynomialRing(RR, 3)
>>> solve([symbolic_expression(x0) == 0], x0, x1, x2)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/Users/anakha/.sage/sage_notebook/worksheets/admin/12/code/55.py",
line 8, in <module>
   solve(x0 == _sage_const_0 , x0, x1, x2)
 File "/Volumes/Place/anakha/Applications/sage/local/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/",
line 1, in <module>

 File "/Users/anakha/.sage/sage_notebook/worksheets/admin/12/code/54.py",
line 22, in solve
   raise TypeError, "%s is not a valid variable."%v
TypeError: x0 is not a valid variable.

Furthermore, if you disable the type checking that is done on the
input variables, then it works as before:

>>> R.<x0,x1,x2> = PolynomialRing(RR, 3)
>>> solve([symbolic_expression(x0) == 0], x0, x1, x2)
[[x0 == 0, x1 == r10, x2 == r9]]

I don't think killing the typecheck is the way to go, but maybe
extending it to cover the polynomial elements.

Or maybe another better way to do this has come up.

Arnaud

Component: calculus

Issue created by migration from https://trac.sagemath.org/ticket/5679

@kcrisman
Copy link
Member

comment:1

In Sage 4.6.2:
{{[
sage: f = symbolic_expression(x0) == 0
sage: f.solve(x0)


TypeError: x0 is not a valid variable.
sage: f.solve(symbolic_expression(x0))
[x0 == 0]
}}}

This is because

        if not isinstance(x, Expression):
            raise TypeError, "%s is not a valid variable."%x

So I guess one could check whether SR(x) is a symbol?

sage: symbolic_expression(x0)._is_symbol()
True

Incidentally, we never get to the args[0] because you are solving a single expression, so it goes to ex.solve(*args). So maybe we should check for that... But in any case the syntax is now

sage: solve([symbolic_expression(x0) == 0, 0==0], [x0, x1, x2])
---------------------------------------------------------------------------
TypeError: x0 is not a valid variable.

which does raise the error in question.

But

sage: solve([symbolic_expression(x0) == 0, 0==0], [SR(x0), SR(x1), SR(x2)])
[[x0 == 0, x1 == r2, x2 == r1]]

Weirdly,

sage: solve([symbolic_expression(x0) == 0], SR(x0), SR(x1), SR(x2))
([x0 == 0], [1])

@kcrisman
Copy link
Member

comment:2

Incidentally, we never get to the args[0] because you are solving a single expression, so it goes to ex.solve(*args). So maybe we should check for that... But in any case the syntax is now
Weirdly,

sage: solve([symbolic_expression(x0) == 0], SR(x0), SR(x1), SR(x2))
([x0 == 0], [1])

These (tangential) things are both addressed at #10750, as it turns out.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@rwst

This comment has been minimized.

@rwst rwst changed the title fix a bug in solve and polynomial generators solve should convert additional args to SR Jul 15, 2015
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants