title: Given f, is there an automatic way to calculate fprime for Newton's method?
body: <p>The following was ported from the pseudo-code from the Wikipedia article on <a href="http://en.wikipedia.org/wiki/Newton%27s_method" rel="nofollow">Newton's method</a>:</p>
  
  <pre><code>#! /usr/bin/env python3
  # https://en.wikipedia.org/wiki/Newton's_method
  import sys
  
  x0 = 1
  f = lambda x: x ** 2 - 2
  fprime = lambda x: 2 * x
  tolerance = 1e-10
  epsilon = sys.float_info.epsilon
  maxIterations = 20
  
  for i in range(maxIterations):
      denominator = fprime(x0)
      if abs(denominator) &lt; epsilon:
          print('WARNING: Denominator is too small')
          break
      newtonX = x0 - f(x0) / denominator
      if abs(newtonX - x0) &lt; tolerance:
          print('The root is', newtonX)
          break
      x0 = newtonX
  else:
      print('WARNING: Not able to find solution within the desired tolerance of', tolerance)
      print('The last computed approximate root was', newtonX)
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Is there an automated way to calculate some form of <code>fprime</code> given some form of <code>f</code> in Python 3.x?</p>