# Which grid errors reach the thermometer?

Henry Shin · Refactor · Mathematical companion · November 27, 2026

Give the center, edges, and corners three weights. Follow one temperature reading backward to find its sharp error bound on a square of nine cells, then carry the calculation to larger grids.

Give the center of a square grid a weight c, each of its four edge cells a weight b, and each corner a weight k. We want to know whether the center is warmer than its four neighbors on average. At the moment we take the reading, the weights are easy to choose. Can we choose three weights for the moment before it, so they predict exactly the same reading?

## Choose three weights and move them back one step

Start with nine temperatures on a 3 × 3 square. At every tick a cell keeps half its old temperature and takes one eighth of the old temperature at each of its four neighbors, north, south, east, and west. The cells just outside the square stay at zero. All nine updates use the same old grid.

Our thermometer subtracts the mean of the four edge cells from the center. Call its reading J. For a weighted sum to give J on any grid, its final weights must be c = 1, b = −1/4, and k = 0. A rotation or reflection preserves both the update and the reading. That suggests keeping one unknown per kind of cell when we move the reading backward. A weight always belongs to one cell of its kind.

Imagine adding one degree at an old edge cell. Half a degree stays there. An eighth goes to the center, an eighth to each of two corners, and an eighth goes outside. If the new reading uses weights (c, b, k), the old edge cell therefore has weight c/8 + b/2 + k/4. Send a degree from the center and then from a corner to get the other two equations. Writing primes for weights one tick earlier gives

c′ = c/2 + b/2,

b′ = c/8 + b/2 + k/4,

k′ = b/4 + k/2.

Matching the effect of a unit at each kind of cell proves the rule for every temperature field, since the update and reading are linear. One backward step takes (1, −1/4, 0) to (3/8, 0, −1/16). Look at the middle entry. An old edge cell contributes 1/8 through the center and (1/2)(−1/4) through itself. Its two contributions cancel. An error at that cell one tick before the reading is invisible to the thermometer.

## Make the errors add up

Suppose we start with the exact grid. Each computed update is allowed to add an error between −ε and +ε at each cell. More precisely, apply the stated averaging rule to the computed old grid. Subtract that prediction from the computed new value at each cell to obtain its signed local error. The errors can take any combination of values in their intervals. We want a guarantee on the final reading relative to the exact discrete recurrence.

An error at the last update is multiplied by a final weight. An error at the preceding update is multiplied by a weight one tick back. To make the reading as high as possible, put +ε where the weight is positive and −ε where it is negative. Zero weights can be left alone. The largest error after two updates is precisely

(1 + 4 · 1/4)ε = 2ε from the last update,

(3/8 + 4 · 1/16)ε = (5/8)ε from the preceding update,

giving (21/8)ε in total.

Reversing all the signs gives the other endpoint. This is what makes the bound sharp. We can describe an admissible run attaining it. For N updates, let (c_{j}, b_{j}, k_{j}) be the weights j ticks back, starting with j = 0 at the reading. The same choice of signs at every cell and time gives the exact worst-case factor

C_{N} = ∑_{j=0}^{N−1} (|c_{j}| + 4|b_{j}| + 4|k_{j}|).

## Where does 77/16 come from?

How large can C_{N} get if the grid runs all day? A signed sum is easier to calculate than a sum of absolute values. To convert one to the other, we only need the total magnitude of the negative entries. The three-weight recurrence gives the entire list of ticks at which a negative weight occurs.

Backward weights per cell. The last column adds the magnitudes of all negative cells, with their multiplicities.

| Ticks back | Center | Edge | Corner | Negative mass |
| --- | --- | --- | --- | --- |
| 0 | 1 | −1/4 | 0 | 1 |
| 1 | 3/8 | 0 | −1/16 | 1/4 |
| 2 | 3/16 | 1/32 | −1/32 | 1/8 |
| 3 | 7/64 | 1/32 | −1/128 | 1/32 |
| 4 | 9/128 | 7/256 | 1/256 | 0 |

At four ticks back all three weights are positive. Each earlier weight is a sum of these with nonnegative coefficients, so every remaining row stays positive. The total negative mass over all time is 1 + 1/4 + 1/8 + 1/32 = 45/32.

To get the signed total, put a 1 at every interior cell, let the grid run without errors, and call the center value after j ticks h_{j}. Reading this uniform starting grid with the weights j ticks back adds all the weights in row j. Equivalently, we can take the thermometer reading at tick j. The center’s next value is halfway between its present value and the mean of its neighbors, so that reading is twice the center’s loss in one tick.

c_{j} + 4b_{j} + 4k_{j} = 2(h_{j} − h_{j+1}).

Add the rows through j = N − 1. All intermediate center values cancel, leaving 2(1 − h_{N}). Heat leaks out of the boundary. Starting from ones, the largest entry after two ticks is the center at 15/16. By linearity and nonnegative weights, every further pair of ticks reduces the maximum by at least the same proportion. Thus h_{N} tends to zero and the signed total tends to 2.

Replacing a negative entry −a by its absolute value adds 2a. The least error factor that works for every run length is therefore

sup_{N} C_{N} = 2 + 2 · (45/32) = 77/16.

Every finite C_{N} is attained by the sign choice above. Those finite factors increase to 77/16, so any smaller uniform factor eventually fails. If ε = 0.01 °C, the error in the reading is at most 0.048125 °C, however long the run. A computed center excess of 0.060 °C certifies an excess of at least 0.011875 °C in the exact grid. For a physical experiment, measurement error and the accuracy of the heat model would enter as separate inputs.

## Enlarge the grid

Keep the thermometer at the center of a 5 × 5 square. The final reading still uses its four immediate neighbors. One tick earlier, though, an error two places due north can reach the northern neighbor. Its weight is (1/8)(−1/4) = −1/32. The same holds due south, east, and west. Those four cells sat outside the old 3 × 3 square. They add 4/32 to the one-tick-back absolute sum, changing the sharp two-update factor from 21/8 to 11/4.

Six weights now suffice by square symmetry. Measured from the center, representatives are (0,0), (1,0), (1,1), (2,0), (2,1), and (2,2). Their multiplicities are 1, 4, 4, 4, 8, and 4. Switch grid sizes in the calculation below and compare the two-update readings. Then move back a few more ticks and watch where negative weights survive.

[Explore the backward weights in the web edition](https://refactor.press/refactors/heat-grid#backward-weight-grid).

### Carry a reading backward on any grid

Write one forward update as x′ = Ax and the final reading as qᵀx, the sum of the cell values times their weights. We want an earlier weight vector w that gives the same reading for every x. The equation wᵀx = qᵀAx forces w = Aᵀq. Repeating this step gives w₀ = q and w_{j+1} = Aᵀw_{j}. This is the discrete adjoint. On our square, a cell sends and receives the same fractions, so the backward update uses the same stencil. For a directed update the transpose reverses which cell sends a coefficient to which.

If the actual signed error at cell v and tick t is r_{t}(v), its contribution to the final reading is w_{N−t}(v) r_{t}(v). Add over all cells and ticks for the exact error. If only bounds |r_{t}(v)| ≤ ε_{t}(v) are available, the sharp bound under those separate intervals is

∑_{t=1}^{N} ∑_{v} |w_{N−t}(v)| ε_{t}(v).

This formula works for any fixed linear update and any linear reading. For the common bound ε, each backward tick consists of applying the stencil once and adding the absolute cell weights to a running total. On an m × m square the direct calculation takes O(Nm²) arithmetic operations and two grids of O(m²) storage. Symmetry lets us store fewer weights when the update, boundary, and reading share it.

### Check the longer run with exact fractions

The calculation below returns the finite-run factor and, once every backward weight is nonnegative, the sharp all-time factor for the same center reading. The signed total is still 2 on any finite odd square of side at least three. The center-loss identity is unchanged, and from every cell a path of at most (m + 1)/2 outward steps reaches the zero boundary. Following that path carries a positive fraction of the heat outside. Over repeated blocks of that many ticks, the remaining maximum tends to zero. If the code has yet to see a nonnegative row, it reports only the finite-run result.

```text
from fractions import Fraction

def heat_bounds(side, steps):
    """Center contrast on an odd square with zero boundary."""
    if not (side >= 3 and side % 2 == 1 and steps >= 1):
        raise ValueError("use an odd side of at least 3 and a positive run length")
    directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    middle = side // 2
    weights = {(x, y): Fraction(0) for x in range(side) for y in range(side)}
    weights[middle, middle] = Fraction(1)
    for dx, dy in directions:
        weights[middle + dx, middle + dy] = Fraction(-1, 4)

    finite, negative = Fraction(0), Fraction(0)
    uniform = None
    for _ in range(steps):
        finite += sum(abs(w) for w in weights.values())
        negative += sum(max(0, -w) for w in weights.values())
        if uniform is None and min(weights.values()) >= 0:
            uniform = 2 + 2 * negative
        weights = {
            (x, y): (4 * w + sum(weights.get((x + dx, y + dy), 0)
                                  for dx, dy in directions)) / 8
            for (x, y), w in weights.items()
        }
    return finite, uniform
```

On the 3 × 3 grid, heat_bounds(3, 5) reaches the positive row in the table and returns 77/16 as its second value. On the 5 × 5 grid the first nonnegative row is eleven ticks back. With heat_bounds(5, 12) the accumulated negative mass is 279162711/134217728, and the sharp uniform factor is 413380439/67108864, about 6.15985. With ε = 0.01 °C the all-time allowance on twenty-five cells is about 0.06160 °C. Our earlier reading of +0.060 °C now needs more information to certify its sign. We can use the smaller factor for the actual run length, or tighten the local tolerance to 0.0097 °C, which suffices for every run length.

How much extra error should we allow when we push the walls twice as far from the center? The change from a 31 × 31 grid to a 63 × 63 grid costs about 2.044ε. The companion follows the same backward weights through a spreading pulse and proves what that cost approaches. [What does doubling the distance to the wall cost?](https://refactor.press/refactors/heat-grid-size)

## Related reading

In [the Hofstadter G digit shift](https://refactor.press/refactors/hofstadter-g#how-close-is-the-shift), each occupied digit contributes a signed copy of a decaying Fibonacci quantity. Here each local error contributes a signed backward weight. The digit rules restrict which contributions can coexist. On the heat grid the errors can choose their signs separately, which lets us exhibit a run attaining the bound.

Niles Pierce and Michael Giles develop adjoint weighting for errors in selected outputs of numerical PDE calculations, including pressure integrals. Their paper puts this nine-cell thermometer in the wider setting of goal-oriented error estimation. See [Adjoint and defect error bounding and correction for functional estimates (2004)](https://people.maths.ox.ac.uk/gilesm/files/jcp04.prepress.pdf).
