add programmatic output for approximation in stereo.1

This commit is contained in:
queue-miscreant 2025-07-22 03:26:00 -05:00
parent 01f7014fcf
commit 8fb3ddad8f

View File

@ -24,6 +24,7 @@ categories:
```{python}
#| echo: false
from IPython.display import display, Code
import sympy
from sympy.abc import t
```
@ -200,7 +201,7 @@ This action of squaring *z* means that as *t* ranges from $-\infty$ to $\infty$,
Let's go on a brief tangent and compare these expressions to their
transcendental trigonometric counterparts.
Graphing the real and imaginary parts separately shows how much they resemble
$\cos(\pi t)$ and $\sin(\pi t)$ around 0[^1].
$\cos(\pi t)$ and $\sin(\pi t)$ around zero[^1].
[^1]: An approximation of a function as the ratio of two polynomials is called a
[Padé approximant](https://en.wikipedia.org/wiki/Pad%C3%A9_approximant).
@ -376,28 +377,21 @@ A best-case analysis of the above approximation, given some value *t* is...
...or 15 FLOPs.
On a more optimistic note, a Monte Carlo test of the above approximation on my computer yields
promising results when compared with GCC's `libm` implementations of `sin` and `cos`
(also tested with `cexp`).
promising results when compared with GCC's `libm` implementations of `sin`, `cos`, and `cexp`.
```{}
Timing for 100000 math.h sin and cos: 5409619ns
Timing for 100000 approximations: 2408645ns
Approximation faster, speedup: 3000974ns (2.25x)
Squared error in cosines:
Average: 0.000051 (0.713743% error)
Largest: 0.000174 (1.320551% error)
Input: 0.729202
Value: -0.659428
Approximation: -0.672634
Squared error in sines:
Average: 0.000070 (0.835334% error)
Largest: 0.000288 (1.698413% error)
Input: 0.729202
Value: 0.475669
Approximation: 0.458685
```{python}
#| echo: false
for file in [
"approx-results/results_math.txt",
"approx-results/results_complex.txt",
]:
with open(file) as a:
display(Code(a.read()))
```
For the source which I used to generate this output, see the repository linked below.
For the source which I used to generate this output, see the repository linked at the bottom
of this article.
Even though results can be inaccurate, this exercise in the algebraic manipulation
of complex numbers is fairly interesting since it requires no calculus to define,
@ -453,6 +447,7 @@ $$
These are exactly the same expressions which appear in the real and imaginary components
of the ratio between $1 + ti$ and its conjugate.
Compared to the algebra using complex numbers, this is quite a bit more work.
One might ask whether, given a proper arithmetic setting, this can be extended to three dimensions.
In other words, we want to find the projection of a sphere using some new number system
@ -707,5 +702,6 @@ However, I feel like it fails to provide an algebraic motivation for quaternions
or even stereography in the first place.
Hopefully, my remarks on the algebraic approach can be used to augment the information in the video.
<!-- TODO: better repository link -->
Diagrams created with GeoGebra and Matplotlib.
Repository with approximations (as well as GeoGebra files) available [here](https://github.com/queue-miscreant/approx-trig).