4 ms·
The real power of this isn't just differentiating a given function; as others have pointed out, you can do this in, e.g., C with function pointers. Having firs
by kkylin 9y ago
The real power of this isn't just differentiating a given function; as others have pointed out, you can do this in, e.g., C with function pointers. Having first-class procedures and closures means you can actually return the derivative as a function. This lets you do things that the simple example doesn't show. For a physics example, see https://mitpress.mit.edu/sites/default/files/titles/content/sicm/book-Z-H-37.html#%_sec_Temp_235 https://mitpress.mit.edu/sites/default/files/titles/content/... : given a Hamiltonian (generalized energy) describing a mechanical system, you can automatically construct a function that computes the associated Hamiltonian vector field. Pass the vector field and an initial condition into a numerical integrator, and out pops the trajectory.
- kkylin 9y agoTo clarify, the relevance is that deriving the vector field from the Hamiltonian requires taking partial derivatives; see the linked section from Structure and Interpretation of Classical Mechanics (SICM) by Sussman and Wisdom w/ Mayer. Closures lets one do this by composing functions in a way that mirrors the mathematical structure. Note in the SICM implementation, the partial derivatives are computed exactly, not numerically, but the resulting ODEs are integrated numerically.