Petty's Notebook
ArticlesPapersnfieldAbout
Get notified when new posts are published. No spam, just math.
Alexander S. Petty  |  ©2009-2026
← Back
Spectra

The Autocorrelation Formula

January 26, 202214 min read
Companion paper: The Autocorrelation Formula →
A curved rhythm returns beside a displaced copy of itself. The relative shift changes their agreement; the autocorrelation formula reads that count through the spectrum.
A curved rhythm returns beside a displaced copy of itself. The relative shift changes their agreement; the autocorrelation formula reads that count through the spectrum.

Long division runs on two kinds of arithmetic at once. Which digit a remainder writes depends only on its size, so the digits sort the remainders into bins by order. Which remainder comes next depends on multiplying by the base, and multiplication scrambles size completely. Every repeating decimal lives where those two meet, and the simplest question you can ask there is how often a repeating block agrees with itself slid along by a few places. Writing the block out answers it one shift at a time. Here the answer comes from the bins alone, through one frequency table per prime in which every possible shift is a single line. The table also answers a slightly different question than the one you might think you asked. At forty-one it reports six matches for a word that, rotated two places, matches itself nowhere, and both numbers are right.

Start small, with the repeating block of 1/71/71/7 in base ten.

142857

Move the first digit to the end and put the two copies alongside each other.

1 4 2 8 5 7
4 2 8 5 7 1

No position agrees. Move two digits to the end, then three, four and five, and there is still nothing, because each digit occurs only once in the block and no rotation short of a full turn can bring a digit back onto itself.

Now try 1/171/171/17, whose block is 058823529411764705882352941176470588235294117647. Shift it one place and the adjacent eights leave one match and the adjacent ones leave another.

The decimal word 142857 and its one-place left rotation have no matching positions. The sixteen-digit word for one seventeenth and its rotation are split into positions one through eight and nine through sixteen. Gold cells mark the surviving eight at position three and one at position eleven. The decimal word 142857 and its one-place left rotation have no matching positions. The sixteen-digit word for one seventeenth and its rotation are split into positions one through eight and nine through sixteen. Gold cells mark the surviving eight at position three and one at position eleven.
Each word against a copy shifted one place, with agreements in gold. The sevenths agree nowhere, while the sixteen-digit word for 1/17, split across two rows, keeps two matches, the adjacent 8s at position three and the adjacent 1s at position eleven.

The number of matches at shift ℓ\ellℓ is the autocorrelation R(ℓ)R(\ell)R(ℓ). We count equal digits, not products of their numerical values. At seven the complete list is 6,0,0,0,0,06,0,0,0,0,06,0,0,0,0,0, and at seventeen it starts with sixteen self-matches and then two.

Writing out the words gives these answers directly. What I want is to see them in the remainder arithmetic that produces the words.

Following the remainders

Long division carries a remainder from one position to the next. In base ten, multiply it by ten, emit the whole-number digit, and keep the new remainder.

At denominator seventeen, a remainder of two gives

20=1⋅17+3.20=1\cdot17+3.20=1⋅17+3.

It emits one and leaves remainder three, and that remainder also emits one, because 30=1⋅17+1330=1\cdot17+1330=1⋅17+13. Those are the adjacent ones in the word. The adjacent eights have the same explanation, since remainder fifteen emits eight and leaves fourteen, and fourteen also emits eight.

A one-place shift compares each remainder with ten times that remainder, reduced modulo seventeen, and a two-place shift uses a hundred. Moving along a word has become multiplication in a finite table.

Label both edges of a square table by the remainders. Put a one in a cell when its two remainders emit the same digit, and zero otherwise. Call the table KKK.

A seventeen-by-seventeen equality table, with starting remainder r along the horizontal axis and shifted remainder s vertically. Teal cells emit equal digits. Gold circles trace s equals ten r modulo seventeen. Only the circles at two, three and fifteen, fourteen land on filled cells. The zero row and column are empty. A seventeen-by-seventeen equality table, with starting remainder r along the horizontal axis and shifted remainder s vertically. Teal cells emit equal digits. Gold circles trace s equals ten r modulo seventeen. Only the circles at two, three and fifteen, fourteen land on filled cells. The zero row and column are empty.
The same-digit table at seventeen, with teal where two remainders write the same digit. The gold circles follow multiplication by ten, and only two of them land on teal, at 2 and 3, which both write 1, and at 15 and 14, which both write 8.

The circles follow multiplication by ten, and two of them land on filled cells, at (2,3)(2,3)(2,3) and (15,14)(15,14)(15,14). The count is two again.

This is a table of remainder states and the single digits they emit. The Cross-Alignment Matrix compares whole repeating rows. The two tables are related, but their entries answer different questions.

Include a row and column labeled zero in KKK and leave both empty, since remainder zero contributes no match. The digit zero can still occur, as it does at the start of 1/171/171/17. The construction works for a prime denominator ppp and any base b≥2b\ge2b≥2 not divisible by ppp.

Two frequency labels

The Spectral Power of the Digit Function added rotating arrows within each digit bin and squared the length of each sum to get its power. That kept the length and threw away the direction, or phase. Multiplication needs to know where the bins sit, and the full equality table keeps that information.

To give it frequency coordinates, choose two labels, kkk and k′k'k′. Every filled cell (r,s)(r,s)(r,s) supplies a unit arrow whose turn depends on both labels, through kr+k′skr+k'skr+k′s, and the sum of those arrows is one entry G(k,k′)G(k,k')G(k,k′) in the cross-spectrum.

Repeat for every pair of frequency labels and a second square table appears. This is the Fourier transform of KKK in both directions, and unlike the one-variable power, it keeps enough information to recover every cell of KKK.

The old power curve has not disappeared. It occupies the opposite-label cells,

G(k,−k)=Φ(k).G(k,-k)=\Phi(k).G(k,−k)=Φ(k).

The rest of the table records the other frequency pairings.

The arrows and the two-dimensional transform

Let fd(r)f_d(r)fd​(r) indicate the bin for digit ddd, with fd(0)=0f_d(0)=0fd​(0)=0. Use the unnormalized additive transform

f^d(k)=∑r=0p−1fd(r)e−2πikr/p.\widehat f_d(k)=\sum_{r=0}^{p-1}f_d(r)e^{-2\pi i kr/p}.f​d​(k)=r=0∑p−1​fd​(r)e−2πikr/p.

The equality table and cross-spectrum are

K(r,s)=∑d=0b−1fd(r)fd(s),K(r,s)=\sum_{d=0}^{b-1}f_d(r)f_d(s),K(r,s)=d=0∑b−1​fd​(r)fd​(s), G(k,k′)=∑d=0b−1f^d(k)f^d(k′).G(k,k')=\sum_{d=0}^{b-1}\widehat f_d(k)\widehat f_d(k').G(k,k′)=d=0∑b−1​f​d​(k)f​d​(k′).

There is no conjugate in the second product. Expanding it gives one arrow for each filled cell,

G(k,k′)=∑r,s=0p−1K(r,s)e−2πi(kr+k′s)/p.G(k,k')=\sum_{r,s=0}^{p-1}K(r,s)e^{-2\pi i(kr+k's)/p}.G(k,k′)=r,s=0∑p−1​K(r,s)e−2πi(kr+k′s)/p.

Inversion divides by p2p^2p2,

K(r,s)=1p2∑k,k′=0p−1G(k,k′)e2πi(kr+k′s)/p.K(r,s)=\frac1{p^2}\sum_{k,k'=0}^{p-1}G(k,k')e^{2\pi i(kr+k's)/p}.K(r,s)=p21​k,k′=0∑p−1​G(k,k′)e2πi(kr+k′s)/p.

When k′=−kk'=-kk′=−k, the two bin coefficients become conjugates. Their product is a squared magnitude, giving Φ(k)\Phi(k)Φ(k).

These are additive frequencies of the remainder labels. They are not the frequencies around a repeating word, and the entries of GGG are not eigenvalues of the cross-alignment matrix. Equality of symbols under a shift is the classical Hamming correlation. The Autocorrelation Formula gives the finite Fourier proofs and references.

The vertical parts cancel

Reflect a nonzero remainder rrr to p−rp-rp−r and its digit changes to its complement, so in decimal the two digits add to nine. Reflect both labels of a filled cell and it stays filled, because equal digits have equal complements.

We already have an example. The cell (2,3)(2,3)(2,3) pairs with (15,14)(15,14)(15,14) modulo seventeen, and the first pair emits two ones while the reflected pair emits two eights. In the Fourier sum, reflection changes the sign of the arrow’s angle, so the two arrows have equal horizontal parts and opposite vertical parts.

The filled cells two, three and fifteen, fourteen modulo seventeen give unit Fourier arrows at opposite angles for frequency labels one, one. Their horizontal components agree and point left. Their vertical components cancel. The resultant is the real number two cosine ten pi over seventeen. The filled cells two, three and fifteen, fourteen modulo seventeen give unit Fourier arrows at opposite angles for frequency labels one, one. Their horizontal components agree and point left. Their vertical components cancel. The resultant is the real number two cosine ten pi over seventeen.
The cells (2, 3) and (15, 14) at frequency labels (1, 1). Their arrows mirror each other across the horizontal axis, so their up-and-down parts cancel and the sum lies on the real line, here pointing left, a negative number.

The up-and-down parts cancel, and the same pairing works throughout the table, so every entry of GGG is real. It can be negative, though. The power cells G(k,−k)G(k,-k)G(k,−k) are never negative, but the rest of the cross-spectrum can be.

One line through the table

The circles in the remainder grid follow s=ars=ars=ar modulo ppp. Let C(a)C(a)C(a) count the filled cells they visit. The same count can be read from GGG,

C(a)=1p∑k=0p−1G(k,−a−1k).C(a)=\frac1p\sum_{k=0}^{p-1}G(k,-a^{-1}k).C(a)=p1​k=0∑p−1​G(k,−a−1k).

For each first label kkk, select the second label −a−1k-a^{-1}k−a−1k, add those ppp entries and divide by ppp. All labels are reduced modulo ppp, and the inverse a−1a^{-1}a−1 undoes multiplication by aaa.

The line comes from cancellation. Insert s=ars=ars=ar into a Fourier arrow’s angle and the coefficient of rrr becomes k+ak′k+ak'k+ak′. If that coefficient is nonzero modulo ppp, summing over r=0,…,p−1r=0,\ldots,p-1r=0,…,p−1 takes the arrows once around a balanced circuit and they sum to zero. If k+ak′=0k+ak'=0k+ak′=0, all ppp arrows point together.

So only the line k′=−a−1kk'=-a^{-1}kk′=−a−1k survives. The ppp aligned arrows cancel one of the two factors of ppp in Fourier inversion, which leaves the 1/p1/p1/p in the formula.

The identity works for every nonzero multiplier aaa. A cyclic shift chooses a=bℓa=b^\ella=bℓ. At seven and seventeen in decimal, one repeating word visits every nonzero remainder, so

R(ℓ)=C(bℓ).R(\ell)=C(b^\ell).R(ℓ)=C(bℓ).

That equality needs the full-period condition, but the line formula does not.

Seven cells give zero

At seven every occupied bin is a singleton, so the equality table has ones only at (r,r)(r,r)(r,r) for nonzero rrr. Its transform has just two values, six when k+k′=0k+k'=0k+k′=0 modulo seven and minus one otherwise.

Two copies of the seven-by-seven cross-spectrum, with six on the modular opposite-label line and minus one elsewhere. For no shift, gold circles select seven sixes, totaling 42. For a one-place shift, circles select one six and six minus ones, totaling zero. Division by seven gives six matches and zero matches. Two copies of the seven-by-seven cross-spectrum, with six on the modular opposite-label line and minus one elsewhere. For no shift, gold circles select seven sixes, totaling 42. For a one-place shift, circles select one six and six minus ones, totaling zero. Division by seven gives six matches and zero matches.
The cross-spectrum at seven, sixes on one diagonal and minus ones everywhere else. The unshifted line runs along the sixes and adds to 42, and the one-place line wraps through the table meeting a six only at the origin, so it adds to zero.

At shift zero a=1a=1a=1, and the selected cells have opposite frequency labels. All seven contain six, their sum is 42, and 42/7=642/7=642/7=6 recovers the unshifted word’s six matches.

At shift one, a=10≡3(mod7)a=10\equiv3\pmod7a=10≡3(mod7), whose inverse is five. Negate the inverse and the line becomes k′=2kk'=2kk′=2k modulo seven. The selected cells are (0,0)(0,0)(0,0), (1,2)(1,2)(1,2), (2,4)(2,4)(2,4), (3,6)(3,6)(3,6), (4,1)(4,1)(4,1), (5,3)(5,3)(5,3) and (6,5)(6,5)(6,5), and only the first has labels whose sum is zero, so the line holds one six and six minus ones.

R(1)=6+6(−1)7=0.R(1)=\frac{6+6(-1)}7=0.R(1)=76+6(−1)​=0.

Every other nontrivial shift meets the sixes only at the origin as well. All five shifted counts vanish.

The digit argument with 142857142857142857 was shorter. The table earns its space at seventeen, where bins contain several remainders. For a one-place shift, ten has inverse twelve, the frequency line is k′=5kk'=5kk′=5k modulo seventeen, and its seventeen entries sum to 34.

A seventeen-by-seventeen signed cross-spectrum. Teal is negative, gold positive, and the page color zero on a symmetric linear scale from minus 28 to 28. Circles select k prime equals five k modulo seventeen. Those seventeen entries sum to 34, giving two matches after division by seventeen. A seventeen-by-seventeen signed cross-spectrum. Teal is negative, gold positive, and the page color zero on a symmetric linear scale from minus 28 to 28. Circles select k prime equals five k modulo seventeen. Those seventeen entries sum to 34, giving two matches after division by seventeen.
The cross-spectrum at seventeen, gold for positive entries and teal for negative on a linear scale. The circled cells trace the one-place line k′ = 5k and add up to 34, which divided by seventeen gives the two matches.

Divide by seventeen and you get two matches, the adjacent ones and the adjacent eights. The entries have changed, but the rule for reading them hasn’t.

From the match counts to the matrix eigenvalues

At seven the count vector and its normalized version are

R=(6,0,0,0,0,0),R=(6,0,0,0,0,0),R=(6,0,0,0,0,0), R/6=(1,0,0,0,0,0).R/6=(1,0,0,0,0,0).R/6=(1,0,0,0,0,0).

Every Fourier sum of the second vector is one, since only its first entry contributes and that entry receives no turn. The six eigenvalues are therefore

(1,1,1,1,1,1).(1,1,1,1,1,1).(1,1,1,1,1,1).

These are the eigenvalues of the identity matrix in The Cross-Alignment Matrix.

For a word of period LLL, its rotations have pairwise scores Au,v=R(v−u)/LA_{u,v}=R(v-u)/LAu,v​=R(v−u)/L. The resulting circulant has eigenvalues

λj=1L∑ℓ=0L−1R(ℓ)e2πijℓ/L.\lambda_j=\frac1L\sum_{\ell=0}^{L-1}R(\ell)e^{2\pi i j\ell/L}.λj​=L1​ℓ=0∑L−1​R(ℓ)e2πijℓ/L.

This transform runs around the word, with LLL positions. The transform defining GGG runs over remainder labels, with ppp positions in each direction. In the full-period case the rotations exhaust the denominator’s fractional rows. With several cycles, this calculation describes the within-cycle block, not the full cross-alignment matrix.

Eight cycles at forty-one

The decimal word for 1/411/411/41 is 024390243902439, and it repeats after five places. Forty nonzero remainders are available, so this word visits only an eighth of them, and the others form seven more cycles. Shift each word by two places and count.

Eight representative fractions at denominator forty-one, with their five-digit decimal words, two-place left rotations, and match counts. Numerators one and four contribute zero matches; two, three, five, six, eleven, and fifteen contribute one each. The reference word 02439 has no match, while the eight counts sum to six. Eight representative fractions at denominator forty-one, with their five-digit decimal words, two-place left rotations, and match counts. Numerators one and four contribute zero matches; two, three, five, six, eleven, and fifteen contribute one each. The reference word 02439 has no match, while the eight counts sum to six.
One word from each of the eight cycles at forty-one, each shifted two places. The reference word 02439 matches nowhere and so does 09756, while the other six words keep one gold match each, six in all.

The reference word contributes zero, six other cycles contribute one each, and the last cycle contributes zero, so the line formula adds them all and gives six. Six is the correct count for the whole field and zero is the correct count for the reference word. A line through GGG does not pick out a cycle just because we began with 1/411/411/41.

To pick one out, keep only its remainders when summing the Fourier arrows. The full-field cancellation no longer applies, and although an exact formula remains, it generally uses the entire frequency table instead of a single line.

The formula for a chosen cycle

Let H=⟨b⟩H=\langle b\rangleH=⟨b⟩ be the remainder cycle containing one. A cycle beginning at ccc is the coset cHcHcH. Define

ScH(m)=∑r∈cHe2πimr/p.S_{cH}(m)=\sum_{r\in cH}e^{2\pi i mr/p}.ScH​(m)=r∈cH∑​e2πimr/p.

Its shifted match count is

Rc(ℓ)=1p2∑k,k′=0p−1G(k,k′)ScH(k+bℓk′).R_c(\ell)=\frac1{p^2}\sum_{k,k'=0}^{p-1}G(k,k')S_{cH}(k+b^\ell k').Rc​(ℓ)=p21​k,k′=0∑p−1​G(k,k′)ScH​(k+bℓk′).

At forty-one this isolates five remainders from forty. Summing the eight orbit answers recovers C(10ℓ)C(10^\ell)C(10ℓ).

If the base is primitive, HHH contains every nonzero residue. Then SH(0)=p−1S_H(0)=p-1SH​(0)=p−1 and SH(m)=−1S_H(m)=-1SH​(m)=−1 for nonzero mmm. Together with ∑k,k′G(k,k′)=p2K(0,0)=0\sum_{k,k'}G(k,k')=p^2K(0,0)=0∑k,k′​G(k,k′)=p2K(0,0)=0, these values reduce the double sum to the one-line formula. For a proper subgroup, that reduction is not automatic.

Six cross-spectra, from seven to 509

The two-valued table at seven is the smallest one below. Each panel uses decimal digit bins and shows every frequency pair, with colors separating positive and negative entries. The period LLL and number of cycles are listed separately, because the table contains the whole field in every case.

Six decimal cross-spectrum heatmaps at primes seven, seventeen, forty-one, 97, 257, and 509. Horizontal and vertical coordinates are the two additive frequencies. Teal shows negative values and gold positive values of G divided by p minus one. One symmetric logarithmic scale spans minus 64 to 64 and is linear within plus or minus 0.02. Six decimal cross-spectrum heatmaps at primes seven, seventeen, forty-one, 97, 257, and 509. Horizontal and vertical coordinates are the two additive frequencies. Teal shows negative values and gold positive values of G divided by p minus one. One symmetric logarithmic scale spans minus 64 to 64 and is linear within plus or minus 0.02.
Cross-spectra for 7, 17, 41, 97, 257 and 509, gold positive and teal negative. Seven is the two-valued table from above, forty-one breaks into eight-cycle blocks, and the single-cycle tables grow finer and paler as the prime grows.

Values are divided by p−1p-1p−1, the number of nonzero remainders. The shared color scale is linear between −0.02-0.02−0.02 and 0.020.020.02 and logarithmic outside that interval, and it does not clip any entry. This is a signed cross-spectrum, not a power plot, and the logarithm changes only the display.

Each table is computed from exact digit equalities, and every nonzero multiplier’s frequency slice is checked against a direct integer count. The largest panel contains 5092=259,081509^2=259{,}0815092=259,081 cells, so open the plate to inspect them at full size.

The words and their two kinds of table

These wider plates keep the shifted words, remainder grid, frequency lines, and eight-cycle comparison together. Follow the two matches at seventeen from their positions in the word to their cells in the remainder table.

The complete words for one seventh and one seventeenth alongside their one-place rotations. Gold marks the two agreements in the longer word.
The complete words for one seventh and one seventeenth alongside their one-place rotations. Gold marks the two agreements in the longer word.
Multiplication by ten through the equality grid at seventeen. The two active path cells are labeled by their remainders and common digits.
Multiplication by ten through the equality grid at seventeen. The two active path cells are labeled by their remainders and common digits.
Two frequency lines through the cross-spectrum at seven. The circled cells give seven sixes at zero shift and one six with six minus ones at shift one.
Two frequency lines through the cross-spectrum at seven. The circled cells give seven sixes at zero shift and one six with six minus ones at shift one.
Eight decimal cycles at forty-one, each shifted by two places. The row-by-row match counts separate the reference word's zero from the whole field's six.
Eight decimal cycles at forty-one, each shifted by two places. The row-by-row match counts separate the reference word’s zero from the whole field’s six.

Rotate 024390243902439 twice and every digit misses. The six matches the line reports are out in the field, in six of the seven other cycles, and not one of them belongs to the word we started with.

Companion paper: The Autocorrelation Formula →
Share

Discussion

Sign in to join the discussion.

← All articlesRead the paper →
← Previous: The Spectral Power of the Digit Function
Next: Phase-Filtered Ramanujan Sums and the Spectral Gate →