3 ms·
> Recursion The thing is, in simple cases recursion can easily be replaced with iteration, and in complex cases it is hard to reason about. Fortran didn’t (use
by Koshkin 3y ago
> Recursion
The thing is, in simple cases recursion can easily be replaced with iteration, and in complex cases it is hard to reason about. Fortran didn’t (use to) have support for it, which made it a perfect tool for writing high-performance code.
- AnimalMuppet 3y agoCounterexample: adaptive quadrature. It's pretty simple to reason about, but it would be a bit of a mess to try to do iteratively. Adaptive quadrature is numeric integration, with an accuracy that is better than an error bound. It uses a three-point and a five-point approximation of the integral value on a region. From the difference between the two, it makes an estimate of the error. If the error is above the error bound, it splits the interval in half, and recursively calls itself twice with the two halves of the interval (and both times with half the error bound). I mean, you could iteratively do that with a queue of intervals and error bounds, and a running total of the ones that met their error bound, but that seems messier than the recursive version.
- brudgers 3y agoRecursion is inductive. Inductive methods are very common in everyday life. [1] Formal inductive logic is not. Maybe it's unsuitability for rhetoric plays a role.
- brudgers 3y agoBeware of the Turing tar-pit in which everything is possible but nothing of interest is easy. --Epigram 54 The two major advantages of recursion over iteration are off-by-one errors.