I am going through SICP and I am not sure if this is a mistake in the book or maybe I missed something.
For calculating fast-exp
authors gave the following rules:
b^n = (b^(b/2))^2 if n is even
b^n = b * b^(n - 1) if n is odd
However when they present the implementation for the even n
we have:
((even? n) (square (fast-expt b (/ n 2))))
which in my opinion is correct.
I believe
b^n = (b^(b/2))^2 if n is even
should be changed to
b^n = (b^(n/2))^2 if n is even
.
It is hard for me to believe that in so old book there is such mistake. I also tried to find any discussion about this issue on the web but failed. Not sure what is going on here. Thanks in advance.
You're right, it's a typo - the formula should be (b^(n/2))^2
if n
is even. But it has been corrected in the errata.