Stepanov's biggest blunder? The curious case of adjacent difference
3 days ago
- #Discrete Calculus
- #C++
- #Algorithm Design
- std::adjacent_difference in C++ computes differences between adjacent elements and copies the first element unmodified, which limits its practicality due to type mismatches.
- The design choice to preserve the first element was deliberate to maintain symmetry with std::partial_sum, allowing reconstruction of the original sequence.
- Discrete calculus connects std::adjacent_difference and std::partial_sum to the fundamental theorem of calculus, illustrating differentiation and integration concepts.
- The article critiques the design of std::adjacent_difference for being less generic and breaking symmetry with continuous calculus derivatives.
- The q programming language's deltas function offers a more flexible approach by allowing a seed value, maintaining symmetry without type constraints.