Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One solution is to consider $U'$ as not a generic notation for the derivative (it is not, as pointed out, because it suppresses with respect to which variable the derivative is taken). The question then is really how to specify a non-generic derivative for a formal symbolic function. Reading the documentation of function, there is a way of specifying specific differentiation rules via the derivative_func argument. One way is to denote $U'$ by Up. Letting that print as $U'$ is a matter of specifying a special LaTeX representative of your function, for which there are separate tools. Then it's just a matter of telling the system that D[0](U) should yield Up. We make the code slightly more general. Amend code as you see fit if you really want to allow U to be a function in more variables and allow differentiation to those as well. I think you'll need to specify special names for all those derivatives then, because I suspect that the automatic simplification rules for D[i](U)(x,y,z) will otherwise get stuck in an infinite loop (I haven't checkde that, though).

This should do the trick:

def special_diff(i,Up):
    def deriv(*args,**kwargs):
        if kwargs['diff_param'] == i:
            return Up(*args[1:])
        else:
            raise ValueError("cannot differentiate this function wrt. {}".format(i))
    return deriv

Up=function('Up')
U=function('U',derivative_func=special_diff(0,Up))