4 ms·
replacing sum 1..n with n\*(n-1): https://godbolt.org/z/nLV1vb https://godbolt.org/z/nLV1vb
by nwallin 7y ago
replacing sum 1..n with n\*(n-1): https://godbolt.org/z/nLV1vb https://godbolt.org/z/nLV1vb
- lifthrasiir 7y agoThat kind of thing is actually fully general, and called the scalar evolution (SCEV) analysis. LLVM for example has a full engine [1] for solving all sort of polynomial recurrences, so you can solve, say, sum i^2 with clang too: https://godbolt.org/z/-nHe78 https://godbolt.org/z/-nHe78 [1] https://github.com/llvm-mirror/llvm/blob/master/lib/Analysis/ScalarEvolution.cpp https://github.com/llvm-mirror/llvm/blob/master/lib/Analysis...