Hi Greg,

 Hope the following code helps you in implementing your function:

from sage.symbolic.function import SymbolicFunction
class real_nth_root_class(SymbolicFunction):
   def __init__(self):
       SymbolicFunction.__init__(self, 'real_nth_root', nargs=2)
   def _evalf_(self, x, n, parent=None):
       # Handle python floats which do not have the 'nth_root' method
       if isinstance(x, float):
           return float(RDF(x).nth_root(n))
       return parent(x).nth_root(n)

real_nth_root = real_nth_root_class()


In actual usage:

sage: real_nth_root( x, 3)
real_nth_root(x, 3)
sage: f(x) = real_nth_root( x, 3)
sage: f
x |--> real_nth_root(x, 3)
sage: plot( real_nth_root( x, 3), -5, 5 )
# plots the graph.


 Regards,
   basu.


On Fri 11 Jul 2014 06:23:21 AM SGT, Gregory Bard wrote:
I think we have a consensus that we should do *something* but unless I
am very much mistaken, the suggestion from Vincent Delecroix and Nils
Bruin that we make a symbolic function has advantages.

I was looking at Nils's code, but I have to confess that I don't
understand that code. Actually, I wasn't able to get the following to
work, but I have a feeling that I am making a minor and stupid mistake
with the syntax.

################
from sage.symbolic.function import SymbolicFunction
class nth_root(SymbolicFunction):
    def __init__(self):
        SymbolicFunction.__init__(self, 'nth_root', nargs=2)
    def _evalf_(self, n, x, parent=None):
        return parent(x).nth_root(n)

plot( nth_root( x, 3), -5, 5 )
################

Maybe someone here could explain exactly what the distinction is or
what the pros/cons are for my approach versus Nils's? I have no idea.

I have also posted this on Sage-Edu, but perhaps all future replies
should be restricted to Sage-Devel and not Sage-Edu?
---Greg

On Wednesday, June 25, 2014 1:10:06 AM UTC-4, Gregory Bard wrote:

    As Vincent and Niles have brought up, there might be advantages to it
    being a symbolic function. How does one actually go about making that
    happen? Is this an intrusive change, or an easy one? I really have no
    idea...
    ---Greg


    On Sun, Jun 22, 2014 at 5:00 PM, Vincent Delecroix
    <20100.delecr...@gmail.com <mailto:20100.delecr...@gmail.com>> wrote:
    > As Niles already said it would be better to have it as a
    symbolic function
    >
    > sage: f(x) = real_nth_root(x, 5)
    > sage: f
    > x |--> real_nth_root(x,5)
    >
    > 2014-06-22 22:36 UTC+02:00, Gregory Bard
    <gregory.bard1...@gmail.com <mailto:gregory.bard1...@gmail.com>>:
    >> Yes, that is reasonable. Let us call it "real_nth_root"
    instead, as
    >> suggested by Nicolas Thiery. Any other requests/comments?
    >>
    >> It would be superb if this could be resolved by June 30th, when my
    >> book goes to the American Mathematical Society for publication...
    >> ---Greg
    >>
    >> On Sun, Jun 22, 2014 at 9:02 AM, William Stein
    <wst...@gmail.com <mailto:wst...@gmail.com>> wrote:
    >>> On Sun, Jun 22, 2014 at 8:27 AM, Nicolas M. Thiery
    >>> <nicolas.thi...@u-psud.fr <mailto:nicolas.thi...@u-psud.fr>>
    wrote:
    >>>> On Fri, Jun 20, 2014 at 06:33:52PM -0700, Gregory Bard wrote:
    >>>>> 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 ):
    >>>>
    >>>> Just 2 cents of outsider feedback since I have not followed the
    >>>> discussion, and am not knowledgeable on the topic. This names
    suggests
    >>>> to me that we look at all the real roots of n (for whatever this
    >>>> means), and then take the n-th one.  So maybe real_nth_root
    instead?
    >>>
    >>> +1
    >>>
    >>>>
    >>>> Cheers,
    >>>>                                 Nicolas
    >>>> --
    >>>> Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net
    <mailto:nthi...@users.sf.net>>
    >>>> http://Nicolas.Thiery.name/
    >>>>
    >>>> --
    >>>> You received this message because you are subscribed to the
    Google Groups
    >>>> "sage-devel" group.
    >>>> To unsubscribe from this group and stop receiving emails from
    it, send an
    >>>> email to sage-devel+unsubscr...@googlegroups.com
    <mailto:sage-devel%2bunsubscr...@googlegroups.com>.
    >>>> To post to this group, send email to
    sage-devel@googlegroups.com <mailto:sage-devel@googlegroups.com>.
    >>>> Visit this group at http://groups.google.com/group/sage-devel
    <http://groups.google.com/group/sage-devel>.
    >>>> For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.
    >>>
    >>>
    >>>
    >>> --
    >>> William Stein
    >>> Professor of Mathematics
    >>> University of Washington
    >>> http://wstein.org
    >>>
    >>> --
    >>> You received this message because you are subscribed to a
    topic in the
    >>> Google Groups "sage-devel" group.
    >>> To unsubscribe from this topic, visit
    >>>
    https://groups.google.com/d/topic/sage-devel/Q8VLKBypcJk/unsubscribe
    <https://groups.google.com/d/topic/sage-devel/Q8VLKBypcJk/unsubscribe>.

    >>> To unsubscribe from this group and all its topics, send an
    email to
    >>> sage-devel+unsubscr...@googlegroups.com
    <mailto:sage-devel%2bunsubscr...@googlegroups.com>.
    >>> To post to this group, send email to
    sage-devel@googlegroups.com <mailto:sage-devel@googlegroups.com>.
    >>> Visit this group at http://groups.google.com/group/sage-devel
    <http://groups.google.com/group/sage-devel>.
    >>> For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.
    >>
    >> --
    >> You received this message because you are subscribed to the
    Google Groups
    >> "sage-devel" group.
    >> To unsubscribe from this group and stop receiving emails from
    it, send an
    >> email to sage-devel+unsubscr...@googlegroups.com
    <mailto:sage-devel%2bunsubscr...@googlegroups.com>.
    >> To post to this group, send email to
    sage-devel@googlegroups.com <mailto:sage-devel@googlegroups.com>.
    >> Visit this group at http://groups.google.com/group/sage-devel
    <http://groups.google.com/group/sage-devel>.
    >> For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.
    >>
    >
    > --
    > You received this message because you are subscribed to a topic
    in the Google Groups "sage-devel" group.
    > To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/sage-devel/Q8VLKBypcJk/unsubscribe
    <https://groups.google.com/d/topic/sage-devel/Q8VLKBypcJk/unsubscribe>.

    > To unsubscribe from this group and all its topics, send an email
    to sage-devel+unsubscr...@googlegroups.com
    <mailto:sage-devel%2bunsubscr...@googlegroups.com>.
    > To post to this group, send email to sage-devel@googlegroups.com
    <mailto:sage-devel@googlegroups.com>.
    > Visit this group at http://groups.google.com/group/sage-devel
    <http://groups.google.com/group/sage-devel>.
    > For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.

--
You received this message because you are subscribed to a topic in the
Google Groups "sage-devel" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/sage-devel/Q8VLKBypcJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
sage-devel+unsubscr...@googlegroups.com
<mailto:sage-devel+unsubscr...@googlegroups.com>.
To post to this group, send email to sage-devel@googlegroups.com
<mailto:sage-devel@googlegroups.com>.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to