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
sqrt(4) returns a SymbolicComposition instead of the number 2! #4425
Comments
comment:1
This patch takes care of the problem as stated, passes tests for integer.pyx and rational.pyx; test for calculus.py times out (as it always does on my computer, not just for this patch). I am fairly certain it also does not introduce some new endless loops or other weird bugs, but that would be worth checking out by any reviewer. |
Based on 3.2.alpha0 |
comment:2
Attachment: sqrt-nonsymbolic.patch.gz I think that the .sqrt() method in Integer and Rational should call sqrt._do_sqrt instead of creating the SymbolicComposition themselves. For example, see
|
comment:3
Attachment: trac_4425.patch.gz I've attached a patch which makes the change I suggested. What are your thoughts? |
Attachment: sqrt-nonsymbolic-1.patch.gz |
comment:4
This is fine; in the meantime I did get around to implementing this. However, I also moved the prec evaluation to the _do_sqrt function as well, since it seemed consonant with your review. After thinking about it, it also makes more sense do that because if for some reason something lands in sqrt with prec which isn't RR, Rational, Integer, etc. then _do_sqrt() should still make the square root be in RR if x is positive; the previous behavior was to automatically put it in CC. Does this seem okay? |
comment:5
I attached a trivial followup patch to sqrt-nonsymbolic-1.patch which adds a docstring for the _do_sqrt function (which had no docstring) and some doctests to that function. The new docstring also clarifies that the extend option to _do_sqrt is completely ignored, and why that is the right behavior. The original patch sqrt-nonsymbolic-1.patch and that patch plus the attached followup sqrt-nonsymblic-2.patch together pass all doctests for me in rings and calculus. |
Attachment: sqrt-nonsymbolic-2.patch.gz mabshoff -- apply this and sqrt-nonsymbolic-1.patch; don't apply anything else |
comment:6
Replying to @williamstein:
This seems okay; I didn't have time to merge it but the new tests behave correctly. So this means that the following is the desired behavior for when to extend and when not to extend?
If so, then let's finally let the square root of 4 be 2! |
comment:7
Merged sqrt-nonsymbolic-1.patch and sqrt-nonsymbolic-2.patch in Sage 3.2.rc0 |
In Sage-3.1.4 we have this, which I consider wrong:
I think sqrt(foo) should first check if foo has a sqrt method, and
if so call it. I realize there is a subtle problem here, because
the integer sqrt function calls the symbolic calculus one! So we
need some sort of architecture to fix this right. This isn't trivial.
Component: basic arithmetic
Issue created by migration from https://trac.sagemath.org/ticket/4425
The text was updated successfully, but these errors were encountered: