> So, how do we get sines and cosines without using sin and cos? [...] So we don’t need to track the angle at all, we only need to start at cos=1, sin=0 and rotate a circle around the origin to generate all the sines and cosines we need.
It's the main idea of the classic CORDIC algorithm (as mentioned by the author), used to be the most popular way to implement sin() and cos() on early underpowered calculators. https://en.wikipedia.org/wiki/CORDIC#Rotation_mode
I remember the first time I saw this and was just blown away by the fact that someone had the idea to do this. Some next-level creativity that lead to some next-level problem solving.
I feel trying these things opens a lot of avenues, that many people close for themselves, because they would ask: "but why on earth would I do this?".
I have to admit I stole the idea from this 256-byte demo (after it wiped the floor with the one I made at a demo party): http://www.pouet.net/prod.php?which=5327
I love donut.c, after I’ve been teaching my students for about 6 months and they have a basic grasp of code flow, I love to show them donut.c and just watch their minds blow ^.^
Yeah, that one wasn't too hard but it's nice to have it to check your work. I didn't go into it in the post, but the real power of SymPy is its cse() function, which I used to do all the common subexpression elimination for the integer math version at the bottom.
I think the built-in code generator is a bit strange, though: for example, it always prints integers as integers, and not as floats depending on the context, so code often doesn't typecheck.
Here's an amazing collection of JS donuts created with 140 (or less!!) characters of javascript code each. The rotaring 3D animated ones are my favorites:
https://www.dwitter.net/h/donut
It's the main idea of the classic CORDIC algorithm (as mentioned by the author), used to be the most popular way to implement sin() and cos() on early underpowered calculators. https://en.wikipedia.org/wiki/CORDIC#Rotation_mode