Ronan Paixão wrote: > Em Sex, 2008-11-21 às 16:44 -0700, dean moore escreveu: >> Haven't posted anything to this list in a long time. Posting to both >> lists -- unsure of proper bin. >> >> Searched & googled, couldn't find this previously reported or solved >> -- sorry if I'm spamming. >> >> Running SAGE Version 3.1.2 on Ubuntu Linux in notebook, though about >> same happened >> command line. >> >> Scenario one: >> >> f = x**2 # Quadratic function >> g = f.derivative() >> print g >> print g(3) >> >> get >> 2 x >> >> 6 >> Good & wonderful. >> >> Scenario two: >> >> f = x # Constant function >> g = f.derivative() >> print g >> print g(3) >> >> get >> 1 >> Traceback (click to the left for traceback) >> ... >> >> ValueError: the number of arguments must be less than or equal to 0 >> 1 >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> >> File "/home/dino/.sage/sage_notebook/worksheets/admin/3/code/15.py", line >> 9, in <module> >> print g(Integer(3)) >> File >> "/home/dino/Desktop/sage-3.1.2-debian-x86_64-intel-x86_64-Linux/local/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/", >> line 1, in <module> >> >> >> File >> "/home/dino/Desktop/sage-3.1.2-debian-x86_64-intel-x86_64-Linux/local/lib/python2.5/site-packages/sage/calculus/calculus.py", >> line 1671, in __call__ >> raise ValueError, "the number of arguments must be less than or equal >> to %s"%len(self.variables()) >> >> ValueError: the number of arguments must be less than or equal to 0 >> >> Why does SAGE dislike calling a constant function a function? >> > > The problem lies in that when you say f = x, you're not creating a > function, but just assigning x to another variable name. > The difference is subtle, but here is some example to clarify: > > f = x > print type(f) > g = f.derivative() > print type(g) > f(x) = x > print type(f) > g = f.derivative() > print type(g) > > You get: > <class 'sage.calculus.calculus.SymbolicVariable'> > <class 'sage.calculus.calculus.SymbolicConstant'> > <class 'sage.calculus.calculus.CallableSymbolicExpression'> > <class 'sage.calculus.calculus.CallableSymbolicExpression'> > > Notice that when you explicitly use f(x) sage interprets that as a > function. Your scenario one works because when you use x**2 you're > applying an operation to a variable x and sage implicitly sees this > differently. Also, you still get something different: > > f = x**2 > print type(f) > > <class 'sage.calculus.calculus.SymbolicArithmetic'> > > But that is also callable as a function.
Great explanation. And so you see the following: sage: f(x)=x sage: g=f.derivative() sage: g x |--> 1 sage: g(3) 1 sage: g(x) 1 Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@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-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---