On Wed, Nov 14, 2018 at 10:32 AM Bruno Grenet wrote:
>
> As far as I can tell, this behavior is not new. The (default) choice
> made for the square root of an integer is to return an exact answer
> rather than an approximation. Thus sqrt(9) = 3, sqrt(10) = sqrt(10) and
> sqrt(12) = 2*sqrt(3). On the other hand, a floating point number is
> viewed as an approximation of a real number so the value returned by
> sqrt is then an approximation of the square root.
>
> Note that the default behavior for integers can be changed using
> optional parameters:
>
> sage: sqrt(10, prec=100)
> 3.1622776601683793319988935444
> sage: sqrt(10, prec=100, all=True)
> [3.1622776601683793319988935444, -3.1622776601683793319988935444]
I agree that this behavior makes sense.
However, one thing I do find surprising about the global sqrt
function, which is different from some other global functions (I
think, needlessly) is that it does not work as a symbolic function.
By contrast, the exp function also exhibits the above behavior, in
that it will reduce to an exact (integer) value where possible:
sage: exp(0)
1
sage: exp(2)
e^2
However, if I really wanted to have `exp(0)` as a symbolic expression
I can still do:
sage: exp(0, hold=True)
e^0
This *ought* to work the same way for sqrt or any other function IMO,
but the sqrt global does not accept the hold argument by default:
sage: sqrt(4, hold=True)
---
TypeError Traceback (most recent call last)
in ()
> 1 sqrt(Integer(4), hold=True)
/home/embray/src/sagemath/sage/local/lib/python2.7/site-packages/sage/functions/other.pyc
in sqrt(x, *args, **kwds)
884 except (AttributeError, TypeError):
885 pass
--> 886 return _do_sqrt(x, *args, **kwds)
887
888 # register sqrt in pynac symbol_table for conversion back from
other systems
TypeError: _do_sqrt() got an unexpected keyword argument 'hold'
Looking at the docstring for sqrt, this behavior is actually
documented, and it works if you explicitly coerce the argument to the
symbolic ring:
sage: sqrt(SR(4), hold=True)
sqrt(4)
But again, that seems to be inconsistent, and also an unnecessary
limitation. If hold=True is passed in that would imply that you want
a symbolic result, and that should "just work" so long as the argument
can be coerced to a symbolic expression.
Unless there's some subtle reason I'm wrong here, I'll open a ticket...
Best,
E
> Le 14/11/2018 à 09:20, Henri Girard a écrit :
> > HI,
> >
> > I am calculating a square root sqrt(9)=3
> >
> > But at 10 and over I got this answer sqrt(10)= sqrt(10) except
> > sqrt(16)=4 when it's a right square
> >
> > but sqrt(10.0)=3.16... Is it a normal answer ?
> >
> > sqrt(16)=4 works
> >
> > Any explaination ?
> >
> > Regards
> >
> > Henri
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-release" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-release+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-release@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-release.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sage-release" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sage-release+unsubscr...@googlegroups.com.
To post to this group, send email to sage-release@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-release.
For more options, visit https://groups.google.com/d/optout.