# Is it possible to define (or assume) the derivative of a function

What i would like to do is define formal symbolic functions

f1 = function('f1',latex_name = 'f_1')(x)

and set their derivative or at least be able to substitute their derivative. As an example assume I defined f1,f2,f3,f4 then I would set dx f1 = f2+f3 and what I would expect is

f1.derivative(x)


to output

f2(x)+ f3(x)

edit retag close merge delete

Sort by » oldest newest most voted

I think that the short answer to your question is 'no'. However, to get the output of your example, you can still define f1 as the primitive of f2+f3:

sage: f2 = function('f2', latex_name='f_2')
sage: f3 = function('f3', latex_name='f_3')
sage: f1(x) = integrate(f2(x)+f3(x), x)
sage: diff(f1(x), x)
f2(x) + f3(x)
sage: f1.derivative(x)
x |--> f2(x) + f3(x)

more

You should be able to create a class of a function, though, and give it a custom derivative.

https://github.com/sagemath/sage/blob...

    # only one of derivative and tderivative should be defined
if hasattr(self, '_derivative_') and hasattr(self, '_tderivative_'):
raise ValueError("only one of _derivative_ or _tderivative_ should be defined.")


There are a number of examples in the src/sage/functions directory, e.g. https://github.com/sagemath/sage/blob...

more