"Christopher Diggins" cdiggins@gmail.com writes:
Upon brief inspection I notice the invariants for the two algorithms are different:
In the recursive version the invariant is (iter != 0) && (Tr + Ti <= 4.0) In the iterative version the invariant is: (i<iter) && (Tr+Ti <= limit*limit)
Good observation. I think it's a bug in the original program since we can prove that modulus^2=4 is the point of no return.
I attach a version of the iterative implementation with 4.0 harcoded. Still slower than the tail recursive version.