def differentiate_finite(expr, *symbols, **kwargs):
 points = kwargs.pop('points', 1)
 x0 = kwargs.pop('x0', None)
 wrt = kwargs.pop('wrt', None)
 evaluate = kwargs.pop('evaluate', True)
 if (kwargs != {}):
  raise ValueError(('Unknown kwargs: %s' % kwargs))
 Dexpr = expr.diff(evaluate=evaluate, *symbols)
 return Dexpr.replace((lambda arg: arg.is_Derivative), (lambda arg: arg.as_finite_difference(points=points, x0=x0, wrt=wrt)))

def differentiate_finite ( expr , * symbols , ** kwargs ) : points = kwargs . pop ( 'points' , 1 ) x0 = kwargs . pop ( 'x0' , None ) wrt = kwargs . pop ( 'wrt' , None ) evaluate = kwargs . pop ( 'evaluate' , True ) if ( kwargs != { } ) : raise ValueError ( ( 'Unknown kwargs: %s' % kwargs ) ) Dexpr = expr . diff ( evaluate = evaluate , * symbols ) return Dexpr . replace ( ( lambda arg : arg . is_Derivative ) , ( lambda arg : arg . as_finite_difference ( points = points , x0 = x0 , wrt = wrt ) ) )
differentiate expr and replace derivatives with finite differences .