@@ -197,15 +197,30 @@ def best_differentiate_with_tol(h0, f, x, eps):
197197 # numerical derivatives of real-valued functions can also be estimated
198198 # using a not very well known trick based on complex numbers.
199199 #
200- # Consider the Taylor series
200+ # Let f be a complex analytic function (or a complex analytic piece of a piecewise defined
201+ # function) that takes on real values for inputs on the real line. Consider the Taylor series
201202 # f(x + iε) = f(x) + i ε f'(x) + O(ε²)
202- # Therefore
203+ # where x is a real number, i = √-1, and ε is a small real number. We have
203204 # real(f(x + iε)) = f(x) + O(ε²)
204205 # imag(f(x + iε) / ε) = f'(x)
206+ # This gives us both f(x) and f'(x) with one complex-valued computation.
205207 # No cancellation, so we can take a really small ε (e.g. ε = 1e-150).
206208 #
207- # This comes from Goodfellow, Bengio and Courville (2016): Deep Learning, MIT press, p. 434:
208- # https://www.deeplearningbook.org/contents/guidelines.html
209+ # This comes from
210+ # Goodfellow, Bengio and Courville (2016): Deep Learning, MIT press, p. 434:
211+ # https://www.deeplearningbook.org/contents/guidelines.html
212+ # who cite it to originate from
213+ # William Squire and George Trapp (1998). Using Complex Variables to Estimate Derivatives
214+ # of Real Functions. SIAM Review, 40(1), 110-112. http://doi.org/10.1137/S003614459631241X
215+ # who, in turn, cite it to originate from
216+ # J. N. Lyness and C. B. Moler. 1967. Numerical differentiation of analytic functions,
217+ # SIAM J. Numer. Anal., 4, pp. 202–210.
218+ # and
219+ # J. N. Lyness. 1967. Numerical algorithms based on the theory of complex variables,
220+ # Proc. ACM 22nd Nat. Conf., Thompson Book Co., Washington, DC, pp. 124–134.
221+ #
222+ # So this technique has been known since the late 1960s, but even as of this writing,
223+ # 55 years later (2022), it has not seen much use.
209224 try :
210225 # We need a `sin` that can handle complex numbers, so stdlib's won't cut the mustard.
211226 import numpy as np
0 commit comments