You might not like it, but this is what peak compiler performance looks like.
@ela how can the compiler break down a recursive function to a mathematical statement? There is no brute force involved or is there? And does it do that only when optimizations are on?
@viduq It's not exactly brute force, but it does involve some heavy lifting in the optimizer. Tail recursion elimination turns the recursive calls into a loop. Then, induction variables of the loop are detected, and finally strength reduction, algebraic simplification finish it off.

@ela @viduq

Uh, I need Alt text to help me understand this.

😢

Advanced compiler design and implementation : Muchnick, Steven S., 1945- : Free Download, Borrow, and Streaming : Internet Archive

Includes bibliographical references (p. 801-820) and indexes

Internet Archive