It seems that the consensus on both Sage-devel and Sage-edu is to go
with some sort of nth_real_root function. I propose the following,
which I have tested for evaluation, plotting, differentiation, and
integration. Sadly, the derivative has a Dirac delta in it, which is
... perhaps unavoidable because of the vertical tangency of the
cuberoot function at x=0. (Naturally, we can remove the asserts once
testing is completed.
---Greg
def nth_real_root( x, n ):
"""Note: n must be a positive integer. However, x is any real number.
(Otherwise this explanation will make no sense.)
For odd values of n, we return the unique real number y such
that y^n = x.
For even values of n, if x<0, there is no real number y such
that y^n = x and so we throw an exception.
For even values of n, if x=>0, then we return the unique real
number y such that y^n = x."""
if ((n in ZZ)==false):
raise RuntimeError('nth_real_root(x,n) requires n to be a
positive integer. Your n is not an integer.')
if (n<=0):
raise RuntimeError('nth_real_root(x,n) requires n to be a
positive integer. Your n is not positive.')
assert (n in ZZ)
assert (n>0)
if ((n%2) == 0):
# n is even
if (x<0):
raise RuntimeError('There is no nth real root (of a
negative number x) when n is even.')
else:
return x^(1/n)
assert ((n%2)==1)
# n is odd
return sign(x)*(abs(x))^(1/n)
On Tue, Jun 17, 2014 at 11:34 PM, <[email protected]> wrote:
> This has been brought up many times before, but I'd like to bring up
> the possibility of adding two commands to Sage: cuberoot(x) and
> nthroot(x, n)
>
> The reason is that currently plot( x^(1/3), -5, 5) only shows values for
> x>0,
> and not for x<0. The current work-around recommended is
>
> plot(sign(x)*abs(x)^(1/3), -5, 5)
> (Track ticket #11458)
>
> which replaced the hideous
>
> plot(lambda x: RR(x).nth_root(3), -5, 5, plot_points=20)
>
> This is true in classes like Precalculus and Calculus 1, where trying to
> explain
> workarounds like these would just really a headache for the instructor and
> extremely fragile students.
>
> Also the cube root can occur in many other situations and applications.
> This is urgent, because my textbook "Sage for Undergraduates" is due
> at the American Mathematical Society on June 30th.
>
> The namespace is so huge, can't we just add two more commands?
>
> I suggest:
>
> def cuberoot(x):
> return sign(x)*((x*sign(x))^(1/3))
>
> Last but not least, links to previous demands for exactly this problem:
>
> https://www.mail-archive.com/[email protected]/msg11563.html
> https://groups.google.com/forum/#!msg/sage-devel/_JeSMD-Kvfk/xeNstGrcvXQJ
> https://groups.google.com/forum/#!topic/sage-support/icZ8ekC_P4Y
> https://groups.google.com/forum/#!topic/sage-devel/_JeSMD-Kvfk
> http://trac.sagemath.org/ticket/11458
> https://sage.uwstout.edu/home/pub/32/
> https://groups.google.com/forum/#!topic/sage-support/ZtRWScqMHMM
> https://groups.google.com/forum/#!topic/sage-devel/_JeSMD-Kvfk
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sage-edu" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sage-edu/0vGw_Pd6v_Y/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-edu.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sage-edu" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-edu.
For more options, visit https://groups.google.com/d/optout.