# Revision history [back]

I'm not completely clear on what your question is, but here is an example of defining a differential operator. It is a function D that takes a function of one variable f and returns the derivative of f with respect to the variable.

sage: def D(f):
....:    return f.diff(*f.variables())
....:
sage: f = function('f_1', x)
sage: f.variables()
(x,)
sage: D(f)
D[0](f_1)(x)
sage: D(D(f))
D[0, 0](f_1)(x)


To explain, the function D takes a function as input and returns a function. Functions are "first class values" in Python so you can use them just as you would use a integer or string value, for example. The syntax *f.variables() takes the output of f.variables() which is a tuple (x,) and it unpacks the tuple so that we end up returning f.diff(x).