Sines all the way down

October 8, 2026 · math · llms

Everything that repeats is a sine wearing a costume. Sound, light, your heartbeat, the 60 Hz hum of the power grid. And when the 2017 Transformer needed to tell token 5 from token 500, it reached for the same atoms: sines and cosines.

1. The world repeats

A spring bounces. A pendulum swings. Your wall power flips direction 60 times a second. A guitar string shivers. Light itself is a wave. Different costumes, same atom: something going back and forth, smoothly, forever. Mathematicians gave that atom two names, sine and cosine, and then discovered the two names were one thing seen from two angles.

2. One circle, two shadows

Walk around a unit circle. Your height above the middle is sine. Your distance to the side is cosine. Drag the dot and watch the sine wave draw itself on the right: the wave is just the dot's shadow, traced over time. Cosine is the same walk, started a quarter turn early. That is the whole secret. Every wave toy below is this circle, stacked.

The circle draws the wave

Drag the dot around the circle. The wave on the right is its vertical shadow.

34°
angle
0.56
sin: height
0.83
cos: sideways

Sine and cosine are not two ideas. They are one circle, read two ways.

3. The Fourier prism

A glass prism takes white light in and lays out its colors. Joseph Fourier's 1807 insight was the same trick for signals: any repeating pattern is a stack of pure sines, each with its own loudness. Feed a messy wave in, get its ingredient list out. Build it yourself first, then take one apart.

Build a wave

Three sine ingredients. Drag their loudness and watch the sum on top change.

$f(t) = a_1\sin(t) + a_2\sin(2t) + a_3\sin(3t)$

Take one apart

The dashed line is a square wave: on, off, on, off. Add odd harmonics and watch sines converge on it.

$\frac{4}{\pi}\left(\sin x + \frac{\sin 3x}{3} + \frac{\sin 5x}{5} + \cdots\right)$

This is not a party trick. JPEG stores your photos as stacked cosines (the DCT is Fourier's cousin). MP3 throws away the frequencies you cannot hear. Noise-cancelling headphones flip the wave upside down. MRI reads your body in frequency space. Shazam fingerprints songs by their frequency peaks. The prism is everywhere.

The symmetry breaker

Why does the sine series use only odd powers? Add an x-squared term and watch the symmetry shatter. Then try x cubed: it never breaks.

now plotting:
BROKEN
origin symmetry
1.62
worst ghost gap
odd
powers that survive

Sine has a double flip: mirror it left to right and it flips top to bottom too, $f(-x) = -f(x)$. x cubed does the same double flip, so it fits right in. x squared only flips once, so it shatters the pattern. That is why every even term in the sine series is zero: not by choice, by symmetry. Cosine is the mirror image, $f(-x) = f(x)$, so only even powers survive there.

Watch them converge

Two Lego sets, term by term. Pick a series, then add terms and watch the partial sum hunt down the true curve. Dashed gray is the target.

now plotting:
1
terms so far
2.86
worst miss, smooth parts
10
terms available

Two Lego sets. Polynomials stack powers and hug the target near the center. Waves stack frequencies and nail the repeating pattern. The square wave's ears at the jumps never fully flatten: that is the Gibbs phenomenon, and it is honest. Error is measured away from the sharp jumps.

4. tanh, the wave that isn't

One curve gets invited to wave parties by mistake: tanh. It has the S-shape, but it never repeats, it just squashes. It belongs in this post for one reason: the entire RNN era ran on it. An LSTM cell is two ideas shaking hands. The sigmoid gates decide how much gets through. The tanh decides what gets through, squashed into (-1, 1) so the signal never explodes as it loops.

The squasher, for reference

Not a wave. Rises once, then flattens. Compare with sine above: sine never stops moving.

$\tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}$

Full deep dive lives in the functions post: the sigmoid-to-tanh morph, the logit round trip, and why zero-centered outputs train faster. Read it there instead of here, this post is about waves.

5. Waves inside LLMs

Attention is blind. It looks at a bag of tokens and has no idea which came first. So the 2017 Transformer paper gave every position a fingerprint made of waves, and modern models still do. Two generations of the trick, both interactive below.

5a. Positional fingerprints (2017)

Each position gets a vector of sines and cosines at different frequencies: $\text{PE}(pos, 2i) = \sin(pos / 10000^{2i/d})$. Slow waves mark the neighborhood, fast waves mark the exact house. Drag the two positions and watch their fingerprints: nearby positions look alike, so the model can feel distance.

Two fingerprints

Each strip is one 32-number position vector. Red is positive, blue is negative.

98%
fingerprint similarity
3
positions apart
32
waves per fingerprint

5b. RoPE: rotate, don't stamp (Llama era)

Stamping a fingerprint on every token works, but modern LLMs do something slicker. Instead of adding a position vector, they rotate the query and key vectors by a position-dependent angle. Remember the imaginary-numbers toy: multiplying by $e^{i\theta}$ is a rotation. When attention multiplies a rotated query by a rotated key, the absolute positions cancel and only the relative angle survives. The model stops asking "where are you" and asks "how far apart are we," which is the question it actually wanted answered.

Relative rotation

Two positions rotate two vectors. Attention only ever sees the angle between them.

86°
relative angle
0.07
cos of it: what attention feels
3
tokens apart

Same m minus n, same relative angle, wherever the pair sits in the sequence. That is the whole trick, and it is why RoPE extrapolates to longer texts better than stamped fingerprints.

The universe repeats, so math learned to repeat. Sines went from springs to Shazam to the thing finishing your sentences. Waves all the way down.

Keep exploring

The wave family has relatives all over his drafts.