What is the difference between:

sage: derivative(3*x,x)(2)

which gives an error, and

sage: f(x) = 3*x
sage: derivative(f,x)(2)

which returns 3, and

sage: f(x) = 3*x
sage: derivative(f(x),x)(2)

which also gives an error?

On Aug 3, 8:41 pm, Roger <[EMAIL PROTECTED]> wrote:
> Huh.
>
> I am pretty sure I tried the *exact same thing* and it failed.
> Obviously not.
>
> On Aug 2, 12:10 pm, Robert Bradshaw <[EMAIL PROTECTED]>
> wrote:
>
> > How about
>
> > sage: f(x) = 3*x^2+x-1
> > sage: f.derivative().derivative()(5)
> > 6
>
> > On Aug 2, 2008, at 6:17 AM, Roger wrote:
>
> > > How does one then deal with the case of trying to find the second
> > > derivative of a quadratic polynomial at some particular point? I've
> > > run into this myself - you can't evaluate the resulting constant.
> > > Suggestions?
>
> > > On Aug 1, 8:51 pm, adrian <[EMAIL PROTECTED]> wrote:
> > >> I see.
>
> > >> Thanks
> > >> -Adrian.
>
> > >> On Aug 1, 5:25 pm, "William Stein" <[EMAIL PROTECTED]> wrote:
>
> > >>> On Fri, Aug 1, 2008 at 1:31 PM, adrian  
> > >>> <[EMAIL PROTECTED]> wrote:
>
> > >>>> Yes, this would work.
>
> > >>>> But (and this is what happened to me) if I define a function
> > >>>> def foo(a,b):
> > >>>>    return a.function(x)(3),b.function(x)(3)
>
> > >>>> and I try
> > >>>> foo(x,x+1)
> > >>>> my code would work,
> > >>>> but if I do foo(2,x+1)
> > >>>> it will not.
>
> > >>>> This can be done with what you wrote, I guess:
> > >>>> def foo(a,b):
> > >>>>    a=SR(a)
> > >>>>    b=SR(b)
> > >>>>    return a.function(x)(3), b.function(x)(3)
>
> > >>>> and I guess that is the reason why 3+x-x works, since it maps the
> > >>>> Integer(3) to SR(3).  This means that, in  a way, the Integer  
> > >>>> ring is
> > >>>> a subring of the Symbolic Ring, and probably could share its  
> > >>>> methods.
> > >>>> There might be some more things under consideration.
>
> > >>>> But I think it would be better to add the method, unless it breaks
> > >>>> something else.
>
> > >>> We should not add the method.    If you add it for the integers, you
> > >>> would then also want to add it for real numbers, double precision  
> > >>> numbers,
> > >>> complex numbers, etc., etc., etc., and it would never work on  
> > >>> builtin python
> > >>> types like float (where one can't add new methods).
>
> > >>> Much better is to do the following which will work in all cases:
>
> > >>> sage: def foo(a,b):
> > >>> ...      return SR(a).function(x)(3), SR(b).function(x)(3)
> > >>> sage: foo(2,3)
> > >>> (2, 3)
> > >>> sage: foo(2,3*x + 5)
> > >>> (2, 14)
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to