def finite_diff(expression, variable, increment=1):
 expression = expression.expand()
 expression2 = expression.subs(variable, (variable + increment))
 expression2 = expression2.expand()
 return (expression2 - expression)

def finite_diff ( expression , variable , increment = 1 ) : expression = expression . expand ( ) expression2 = expression . subs ( variable , ( variable + increment ) ) expression2 = expression2 . expand ( ) return ( expression2 - expression )
takes as input a polynomial expression and the variable used to construct it and returns the difference between functions value when the input is incremented to 1 and the original function value .