def ode_order(expr, func):
 a = Wild('a', exclude=[func])
 if expr.match(a):
  return 0
 if isinstance(expr, Derivative):
  if (expr.args[0] == func):
   return len(expr.variables)
  else:
   order = 0
   for arg in expr.args[0].args:
    order = max(order, (ode_order(arg, func) + len(expr.variables)))
   return order
 else:
  order = 0
  for arg in expr.args:
   order = max(order, ode_order(arg, func))
  return order

def ode_order ( expr , func ) : a = Wild ( 'a' , exclude = [ func ] ) if expr . match ( a ) : return 0 if isinstance ( expr , Derivative ) : if ( expr . args [ 0 ] == func ) : return len ( expr . variables ) else : order = 0 for arg in expr . args [ 0 ] . args : order = max ( order , ( ode_order ( arg , func ) + len ( expr . variables ) ) ) return order else : order = 0 for arg in expr . args : order = max ( order , ode_order ( arg , func ) ) return order
returns the order of a given differential equation with respect to func .