Refactor monogramRefactor

Mathematics / Recurrences · Numerical analysis

What should you store when two modes merge?

A formula returns zero for a term that equals two. Trace the error to the choice of coordinates and build an update that works through a double root.

Begin with: Algebra and a second-order recurrence. The article introduces floating-point rounding.

Keep the Fibonacci starting values 0 and 1, but change the recurrence. This time the next term is 2. A formula that separates the sequence into two independent motions can give 0 on a computer at that very step. Where did the 2 go, and what should we have kept?

Two or zero?

Take a real parameter δ and the recurrence

sn+1 = 2sn + (δ² − 1)sn−1   (n ≥ 1).

With s₀ = 0 and s₁ = 1, substitution gives s₂ = 2 for every δ. For δ ≠ 0 the two multipliers are 1 + δ and 1 − δ. Separating their motions gives

sn = ((1 + δ)n − (1 − δ)n)/(2δ).

At n = 2 the numerator expands to 4δ. Try evaluating the displayed formula as written with δ = 2−55 in binary64 arithmetic, rounding each operation to nearest. The adjacent representable numbers below and above 1 are 1 − 2−53 and 1 + 2−52. Both proposed multipliers lie closer to 1 than to either neighbor. Both round to 1.

Squaring now gives two identical ones. Their difference is exactly zero, and the denominator 2−54 is representable. The division returns zero. The information was lost when the two multipliers were stored. We can reproduce the failure before taking a large power or accumulating a long string of rounding errors.

What the two modes almost agree on

The Fibonacci refactor found a linear quantity that updates by multiplication. Applied here, its two choices give the following weighted differences.

un = sn − (1 + δ)sn−1,   un+1 = (1 − δ)un,

vn = sn − (1 − δ)sn−1,   vn+1 = (1 + δ)vn.

What do these measurements actually record? They share the ordinary difference dn = sn − sn−1. Write pn = sn−1 for the previous term. Then

un = dn − δpn,   vn = dn + δpn.

Their average gives dn. Their difference gives 2δpn. As δ shrinks, the previous term is encoded in a smaller and smaller discrepancy. At δ = 0, any two states with the same ordinary difference have identical modal readings. For instance, the pairs of successive terms (0, 1) and (10, 11) both give u = v = 1. Their next terms are 2 and 12. An update that retains only the common reading has lost the level of the sequence.

Carry the difference forward

Keep the previous term and the ordinary difference directly. This asks for one addition to read the current term, sn = pn + dn. To update the difference, subtract sn from the original recurrence and collect the terms that survive.

dn+1 = sn+1 − sn

= (sn − sn−1) + δ²sn−1.

Moving forward shifts the current term into the previous-term slot. Together the two moves are

pn+1 = pn + dn,

dn+1 = dn + δ²pn.

Both right-hand sides use the old state. These equations work for arbitrary initial values, starting from (p₁, d₁) = (s₀, s₁ − s₀). At every step they retain both stored terms, sn−1 = pn and sn = pn + dn. The conversion uses the same addition even when the roots meet.

In the opening example the state starts at (0, 1) and advances to (1, 1). Reading the new term gives 1 + 1 = 2, exactly in binary64 as well. For a step where both parts interact, take δ = 1/4 and start the sequence at 2 and 3. The state (2, 1) advances to (3, 1 + 2/16) = (3, 9/8). It gives s₂ = 33/8, the same value as 2 · 3 − (15/16) · 2 in the original recurrence.

Compute the same sequence twice

Start at s₀ = 0, s₁ = 1. The roots are 1 + δ and 1 − δ, a distance 2δ apart. For every choice of δ, the recurrence gives exactly s₂ = 2.

At δ = 2⁻⁵⁵, both roots round to 1. The root formula returns 0 at step 2. The position and difference update returns 2.

Computed values of sₙ for δ = 2⁻⁵⁵, using binary64 arithmetic
nRoot formulaPosition and difference
202
404
808

The first calculation multiplies the two stored roots to form their powers, subtracts them, and divides by the supplied gap 2δ. The second stores pₙ = sₙ₋₁ and dₙ = sₙ − sₙ₋₁. Starting at (p₁, d₁) = (0, 1), it updates the pair to (pₙ + dₙ, dₙ + δ²pₙ) and reads off sₙ = pₙ + dₙ.

At the double root

Set δ = 0 in the two moves. The difference stays fixed and the previous term increases by that difference. After k steps a state (p, d) has become (p + kd, d). Thus for arbitrary s₀, s₁,

sn = s₀ + n(s₁ − s₀)   (n ≥ 0).

This is the two-step operator chain in concrete form. Subtract the identity from one update of the state. The remainder sends (p, d) to (d, 0), and applying that remainder twice gives zero. Each full update can therefore contribute the same increment once more. This is where the factor n comes from.

In the Fibonacci example the ordinary difference still needed input from the previous term. Here that dependence is exactly δ²pn. At the double root it vanishes, and the ordinary difference becomes the quantity that moves on its own. The level is still needed to locate the sequence.

The price of reconstructing a term

Suppose δ ≠ 0 is known exactly. Someone hands us readings un + eu and vn + ev, each with absolute error at most ε. Subtracting the readings and dividing by 2δ reconstructs the previous term with error

|(ev − eu)/(2δ)| ≤ ε/|δ|.

The bound is attained when the two errors are +ε and −ε. Equal errors cancel in the subtraction. This is a sharp absolute bound for recovering one term from separately perturbed modal readings. It describes exactly which errors the inverse change of coordinates amplifies.

There is also genuine growth in time. At the double root, increasing s₁ by η with s₀ fixed changes sn by nη, even in exact arithmetic. For fixed n and fixed initial data, the two update rules make sn a polynomial in δ², so the term itself has a regular limit as the roots meet. Carrying (p, d) avoids the small divisor in recovery. Accuracy over many steps still depends on the initial data, the growth of the recurrence, and rounding during those steps.

Continue with Compute Hofstadter G by shifting Fibonacci digits. There a rounded real number can miss an integer by one. A change in how we write the input gives an exact answer and shows how close the calculation comes to a rounding boundary.

Notes and sources

The first article derives the weighted differences and their inverse for a general second-order recurrence. Find the quantity that moves on its own.

David Goldberg explains how subtracting nearby rounded quantities exposes the errors already present in the operands, and describes the 53-bit significand of IEEE double precision. What Every Computer Scientist Should Know About Floating-Point Arithmetic, especially “Cancellation” and “Formats”.