5 ms·
Personally I go with the recursive definition. Use the trig identity cos(x)^2 + 1 = cos(2x). 2cos(x)^2 - 1 = cos(2x). 2(2cos(x)^2 - 1)^2 - 1 = 2cos(2x)
by IIAOPSW 4y ago
Personally I go with the recursive definition. Use the trig identity cos(x)^2 + 1 = cos(2x).
2cos(x)^2 - 1 = cos(2x).
2(2cos(x)^2 - 1)^2 - 1 = 2cos(2x)^2 - 1 = cos(4x)
2(2(2cos(x)^2 - 1)^2 - 1)^2 - 1 = 2cos(4x)^2 - 1 = cos(8x)
Keep squaring, doubling and subtracting one one the left. Keep raising by powers of 2 in the argument on the right. Eventually, if you're working with rational numbers, multiplication by 2^k moves all k fractional bits over to the integer side of the decimal, and then integer times pi is the base case of the recursion. If you rescale the units so that pi = 2^(n-1) for some n, you don't even have to think about the non-fractional part. The register value circling back to 0 is supposed to happen anyway.
You could Just as easily recursively define cos to "spiral downwards in x rather than outwards", each recursive layer reducing the argument of x by a factor of 2 until it reduces down to the precomputed value cos(machine precision).
This was all just circular reasoning
- austinjp 4y ago> This was all just circular reasoning. Nice :)