On Apr 6, 12:03 pm, Michael Orlitzky <mich...@orlitzky.com> wrote: > I sort of buy that, but if, > > sage: f = function('f', x) > > doesn't make `f` a function, that's a user-interface WTF =)
I would tend to agree, but it's a fact of life that function('f',x) returns the symbolic function f evaluated at x. The docstring of "function" doesn't help either. The confusion between the nature of f and f(x) is a usual one in calculus. The vagueness actually lies more in the nature of 'x' than the nature of 'f': Is 'x' a polynomial variable? an arbitrary real number? an arbitrary complex number? The identity element in the ring of differentiable functions on R? > After #12801, I'm having trouble reconciling these two examples: > > sage: f = function('f', x) > sage: g = function('g') > sage: f.diff(x).substitute_function(f,g) > D[0](f)(x) > > versus, > > sage: f = function('f') > sage: g = function('g') > sage: f(x).diff(x).substitute_function(f,g) > D[0](g)(x) > > It would be slightly better I think if the first example worked, but I > can live with using the second (although I never would have discovered > it on my own). Again, the result of "function('f',x)" is the expression "f(x)", which does not occur in "D[0](f)(x)". Really, substitute_function should throw an error if it is asked to substitute something that cannot be viewed as a "function". Note that function('f',x)(3) throws a deprecation warning. Life would be much clearer if that were to finally become a proper error. > What I would /really/ like to be able to do is, > > midpoint = (1/2)*( f(a) + f(b) ) > > and then approximate multiple functions by swapping out the symbolic `f` > for a real function like sine. which you *can* provided you avoid the pitfall of "function('f',x)": sage: f=function('f') sage: var('a,b') (a, b) sage: midpoint = (1/2)*( f(a) + f(b) ) sage: midpoint 1/2*f(a) + 1/2*f(b) sage: midpoint.substitute_function(f,sin) 1/2*sin(a) + 1/2*sin(b) You can even make that into a function of a,b sage: mp (a, b) |--> 1/2*f(a) + 1/2*f(b) although substitute_function silently changes the nature of the object [I think that's a bug]: sage: mp.substitute_function(f,sin) 1/2*sin(a) + 1/2*sin(b) [now we just have an expression in a,b again] That said, I think your confusion shows that it's probably better if function('f',x) were to be deprecated in favour of function('f')(x). The relevant bit of information to glean from the notation is that f takes one argument. You can already indicate the valid number of arguments: sage: f= function('f',nargs=3) sage: f(1,2) TypeError: Symbolic function f takes exactly 3 arguments (2 given) The attribute f.number_of_arguments() doesn't seem to get much use though: sage: sage.symbolic.operators.FDerivativeOperator(f,[3]) D[3](f) is happily produced but can never be successfully evaluated. -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org