Python Derivative Function Formula