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} ```{python}
#| echo: false #| echo: false
from IPython.display import display, Code
import sympy import sympy
from sympy.abc import t 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 Let's go on a brief tangent and compare these expressions to their
transcendental trigonometric counterparts. transcendental trigonometric counterparts.
Graphing the real and imaginary parts separately shows how much they resemble 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 [^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). [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. ...or 15 FLOPs.
On a more optimistic note, a Monte Carlo test of the above approximation on my computer yields 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` promising results when compared with GCC's `libm` implementations of `sin`, `cos`, and `cexp`.
(also tested with `cexp`).
```{} ```{python}
Timing for 100000 math.h sin and cos: 5409619ns #| echo: false
Timing for 100000 approximations: 2408645ns
Approximation faster, speedup: 3000974ns (2.25x) for file in [
Squared error in cosines: "approx-results/results_math.txt",
Average: 0.000051 (0.713743% error) "approx-results/results_complex.txt",
Largest: 0.000174 (1.320551% error) ]:
Input: 0.729202 with open(file) as a:
Value: -0.659428 display(Code(a.read()))
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
``` ```
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 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, 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 These are exactly the same expressions which appear in the real and imaginary components
of the ratio between $1 + ti$ and its conjugate. of the ratio between $1 + ti$ and its conjugate.
Compared to the algebra using complex numbers, this is quite a bit more work. 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. 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 In other words, we want to find the projection of a sphere using some new number system
@ -535,7 +530,7 @@ If you know a little group theory, you might know there are only two nonabelian
dihedral group of degree 4 dihedral group of degree 4
](https://en.wikipedia.org/wiki/Examples_of_groups#dihedral_group_of_order_8). ](https://en.wikipedia.org/wiki/Examples_of_groups#dihedral_group_of_order_8).
In the latter group, *j* and *k* are both imaginary, but square to 1 (*i* still squares to -1)[^4] . In the latter group, *j* and *k* are both imaginary, but square to 1 (*i* still squares to -1)[^4].
[^4]: I'm being a bit careless with the meanings of "1" and "-1" here. [^4]: I'm being a bit careless with the meanings of "1" and "-1" here.
Properly, these are the group identity and another group element which commutes with all others. Properly, these are the group identity and another group element which commutes with all others.
@ -707,5 +702,6 @@ However, I feel like it fails to provide an algebraic motivation for quaternions
or even stereography in the first place. or even stereography in the first place.
Hopefully, my remarks on the algebraic approach can be used to augment the information in the video. 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. Diagrams created with GeoGebra and Matplotlib.
Repository with approximations (as well as GeoGebra files) available [here](https://github.com/queue-miscreant/approx-trig). Repository with approximations (as well as GeoGebra files) available [here](https://github.com/queue-miscreant/approx-trig).