iterating a little more,

unfortunately the "doit" fails at the next bend...

this code

from sympy import *

u,B = symbols('u B')
e = B*u #here i use an expression instead of a function
s = Function('s')(e)

is expected to give somethign like


instead it fails with the output

*rrossi@PCCB076:~/data/examples$ python3 
B*Subs(Derivative(s(_xi_1), _xi_1), (_xi_1,), (B*u,))Traceback (most recent 
call last):  File "", line 8, in <module>    aaa = { 
Derivative(e,u):symbols('DeDu'), Derivative(s,e):symbols('DsDe') }  File 
line 1070, in __new__    Can\'t calculate %s%s derivative wrt %s.''' % 
(count, ordinal, v)))ValueError: Can't calculate 1st derivative wrt B*u.*i 
guess what i should really do is to subfunction the class as your propose. 
However i do not get how to make it to work. in my case "fdiff" is simply 
not being called

class FunctionWithDerivative(Function):
    nargs = 3
    #first argument  --> the expression
    #second argument --> the variable it depends on
    #second argument --> the derivative       
    def eval(cls,expression,x,D):
        print("--------- in eval -----------------. Looks like here it is 
not creating the object ...")
        cls.expression = expression
        cls.x = x
        cls.D = D
        return cls.expression

    def fdiff(self, argindex=1):
        print("********** inside fdiff ****",self.args) 


u = symbols('u')
e = Function('e')(u)
s = FunctionWithDerivative(symbols('e'), symbols('e'), symbols('DsDe') )



rrossi@PCCB076:~/data/examples$ python3 
--------- in eval -----------------. Looks like here it is not creating the 
object ...
s =  s
diff(s,e).doit() =  0

*and what is the worst... fdiff is NOT being called...*regards

On Monday, October 17, 2016 at 8:26:04 AM UTC+2, Riccardo Rossi wrote:
> Dear Aaron,
> your suggestion did work, HOWEVER i had to upgrade sympy to 1.0. It did 
> nothing on 0.7.6 (the default one on ubuntu 16.04)
> only writing here to "document" this behaviour
> regards
> Riccardo 

You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

Reply via email to