def sub_func_doit(eq, func, new):
 reps = {}
 repu = {}
 for d in eq.atoms(Derivative):
  u = Dummy('u')
  repu[u] = d.subs(func, new).doit()
  reps[d] = u
 return eq.subs(reps).subs(func, new).subs(repu)

def sub_func_doit ( eq , func , new ) : reps = { } repu = { } for d in eq . atoms ( Derivative ) : u = Dummy ( 'u' ) repu [ u ] = d . subs ( func , new ) . doit ( ) reps [ d ] = u return eq . subs ( reps ) . subs ( func , new ) . subs ( repu )
when replacing the func with something else .