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
better input handling for solve() #13645
Comments
Reviewer: Burcin Erocal |
comment:1
Here is what I get:
Is this what you mean by a "crash"? Note that when you work with variables in a polynomial ring, the comparison is evaluated immediately.
In this case, the call to I suggest we close this as invalid. |
comment:2
Tanks burcin, do not close the ticket, I think that something needs to be fixed. If you say that,
Shouldn't Sage raise an exception when evaluating "a+b+a*b == 1", saying something like "Symbolic comparisons are not allowed for polynomial rings.", instead of returning False. And besides that, why is "solve([False], a)" raising such a incomprehensible "TypeError" exception ? Thanks, |
comment:3
Attachment: trac_13645-solve_input_handling.patch.gz OK. I attached a patch to fix the error message. Now we have:
Please review. Replying to @sagetrac-llpamies:
No, that operations checks for equality of polynomials. That polynomial is not equal to
This was caused by a typo. Python was complaining about a different issue when it said |
Changed reviewer from Burcin Erocal to none |
This comment has been minimized.
This comment has been minimized.
Author: Burcin Erocal |
comment:5
Should this be explicitly provided in the documentation of I have something like this in mind:
what other variables can be defined in Sage, by the way? |
comment:6
There is another problem here, not related to equality:
The last line does not work, but it could and should ! It can be done by converting polynomials to elements of the symbolic ring. |
comment:7
Here is an example code which can convert the polynomial to a symbolic expression. R.<y,z> = RR[]
a = y^2 + 2 * z^2
is_Polynomial(a) # test for polynomial a
False
is_MPolynomial(a) # test for multinomial a
True
va = a.variables()
vSR = map(SR, va)
aSR = a.subs({_x: _xs for _x,_xs in zip(va, vSR)})
type(aSR)
<type 'sage.symbolic.expression.Expression'>
solve(aSR, *vSR)
([y == -I*sqrt(2)*z, y == I*sqrt(2)*z], [1, 1]) This can be done internally in the solve function. There is only one problem to this approach. Polynomial rings can be over other fields, for instance finite fields, too. The output of solve in this case doesn't really make much sense because it loses the information that the elements are in finite fields.
So, we need some test to check whether the polynomial is defined only over reals or complexes. |
comment:8
I somehow feel like maybe it makes more sense that if we have type bool in the list of things as in Burcin's error message
That perhaps we can suggest to the user that instead of a polynomial ring, they should use symbolic variables (rather than the message about bool, which will no doubt confuse people). Of course, there is the other question of whether we want
to return I don't mind (uncharacteristically) if people can't get an answer to this, not only for the base field issue, but also because we don't want people using polynomial rings any more unless they know what they are doing. The symbolic ring should take care of all "calculus mode" users, which was not the case in the (long ago) past. |
comment:9
Yikes. Indeed, I forgot that polynomial ring elements actually evaluate to a boolean when input with comparison operators. My example will working only when the relation is (implicitly) equality to zero. Then Burcin's patch seems the right thing to do. |
comment:10
So... do you want to review this, then? |
comment:11
Replying to @kcrisman:
Yes. Positive review. I am uploading a rebased patch. |
Rebased to 5.11-beta3 |
Reviewer: Punarbasu Purkayastha |
comment:12
Attachment: trac_13645-solve_input_handling-rebased.patch.gz Patchbot apply trac_13645-solve_input_handling-rebased.patch |
This comment has been minimized.
This comment has been minimized.
Merged: sage-5.12.beta0 |
Consider the following Sage code:
If I want to do something similar with elements of a PolynomialRing the code crashes:
Apply: attachment: trac_13645-solve_input_handling-rebased.patch
CC: @kcrisman
Component: symbolics
Author: Burcin Erocal
Reviewer: Punarbasu Purkayastha
Merged: sage-5.12.beta0
Issue created by migration from https://trac.sagemath.org/ticket/13645
The text was updated successfully, but these errors were encountered: