Q:

Sympy: Specify derivative for function

I would like to specify the derivative of a function that is also a function. Is there a way how to do this in sympy?
An example how it could look like:
import sympy as sp
x, y = sp.symbols('x, y')
fun = sp.Function("myfun")(x, y)

fun.derivative = sp.Function("myfun_derivative")(x,y)

My use case is that I want to use afterwards the sympy codegen and specify for "myfun" and for "myfun_derivative" standard methods which use numpy, because they are complex and take a long time to handle for sympy.
UPDATE Solution: 
import sympy as sp
x, y = sp.symbols('x, y')

class myfun(sp.Function):
   def fdiff(self, argindex = 1):
      return sp.Function("myfun_derivative")(x, y, argindex)

A:

A function and derivative are just expressions so you are free to define them as you wish:
>>> from sympy.abc import x
>>> f = x**2
>>> df = 2*x

So now f and df represent your function and derivative.
You could also define an object that returns these values upon initiation and differentiation:
In [10]: class myf(Function):
    ...:     def fdiff(self, i):
    ...:         assert i == 1
    ...:         return 2*x
    ...:     def __new__(self):
    ...:         return  x**2
    ...:

In [11]: myf()
Out[11]:
 2
x

In [12]: myf().diff()
Out[12]: 2·x

