Hacker News new | ask | show | jobs
by architectonic 850 days ago
That's called the stability of the algorithm. The first algorithm is not stable whereas the second with the logarithm is.

Another example: compare the two algorithms, that are actually pure-mathematically equal:

  def fc(x): 
      return sqrt(x+1) - sqrt(x)
  def fd(x): 
      return 1/(sqrt(x+1) + sqrt(x))

For large values of x (1e16 for example) plot the results and see the difference.

  xs = np.linspace(10\*14,10\*16,10000) 
  plt.figure(figsize=(8, 6), dpi=120) 
  plt.plot(xs,[fc(x) for x in xs]) 
  plt.plot(xs,[fd(x) for x in xs])