Re: [sage-devel] sqrt() returns wrong result for large inputs

2010-10-26 Thread Francois Maltey
David Roe wrote : I posted a patch there that should fix it; I have to work on other stuff, but if someone else wants to take over and write some doctests, make sure it works in lots of cases... David On Mon, Oct 25, 2010 at 17:14, Burcin Erocal bur...@erocal.org mailto:bur...@erocal.org

Re: [sage-devel] sqrt() returns wrong result for large inputs

2010-10-26 Thread Robert Bradshaw
On Tue, Oct 26, 2010 at 1:03 AM, Francois Maltey fmal...@nerim.fr wrote: David Roe wrote : I posted a patch there that should fix it; I have to work on other stuff, but if someone else wants to take over and write some doctests, make sure it works in lots of cases... David On Mon, Oct 25,

[sage-devel] sqrt() returns wrong result for large inputs

2010-10-25 Thread G Hahn
Hi while calculating the integer part of square roots I realized that sqrt() returns wrong results for large inputs (although the sqrt() command itself accepts bignum values). example: int(sqrt(2^94533)) I guess that this is due to the fact that SAGE simplifies the expression above as sqrt(2) *

Re: [sage-devel] sqrt() returns wrong result for large inputs

2010-10-25 Thread Francois Maltey
Georg wrote : while calculating the integer part of square roots I realized that sqrt() returns wrong results for large inputs (although the sqrt() command itself accepts bignum values). example: int(sqrt(2^94533)) int isn't a mathematical Sage type, but Integer is a Sage type. And Integer

Re: [sage-devel] sqrt() returns wrong result for large inputs

2010-10-25 Thread John Cremona
When you do sqrt(2^m) when m is odd, say m=2*k+1, the returned value is symbolically 2*k * sqrt(2): sage: sqrt(2^101) 1125899906842624*sqrt(2) Now using Integer() to round that will evaluate sqrt(2) approximately to standard precision, which is not enough. Instead, use the isqrt() method for

Re: [sage-devel] sqrt() returns wrong result for large inputs

2010-10-25 Thread David Roe
This is a good workaround, but the original problem can be traced to the function sage.symbolic.expression.Expression.__int__ def __int__(self): #FIXME: can we do better? return int(self.n(prec=100)) Presumably you could adaptively estimate to higher precision until your error interval

Re: [sage-devel] sqrt() returns wrong result for large inputs

2010-10-25 Thread Burcin Erocal
On Mon, 25 Oct 2010 17:00:39 -0400 David Roe r...@math.harvard.edu wrote: This is a good workaround, but the original problem can be traced to the function sage.symbolic.expression.Expression.__int__ def __int__(self): #FIXME: can we do better? return int(self.n(prec=100))

Re: [sage-devel] sqrt() returns wrong result for large inputs

2010-10-25 Thread David Roe
I posted a patch there that should fix it; I have to work on other stuff, but if someone else wants to take over and write some doctests, make sure it works in lots of cases... David On Mon, Oct 25, 2010 at 17:14, Burcin Erocal bur...@erocal.org wrote: On Mon, 25 Oct 2010 17:00:39 -0400 David