← notes

An average that was wrong 261 times

Nov 13, 2026

Three simulated sensors: one spikes, one drifts, one freezes. A plain average was wrong in 261 of 399 cycles. Mru was wrong in none and silent in 120.

Replicas compute the same thing and should agree bit for bit. Sensors measure the same thing and never agree exactly. Run 4 adds the second kind of voting. select() in quorum/src/sensor.rs works within a tolerance. With three readings it takes the median, if another reading is within the tolerance of it. With two, their midpoint, if they agree. With one, the reading goes out marked Unchecked. Otherwise nothing goes out. A sensor is excluded only after a set number of outlier cycles in a row, so one spike is forgiven.

The median is one line, a.min(b).max(a.max(b).min(c)). A unit test caught a tie bug in the first version before it was committed.

Segment four feeds three simulated sensors through the F´ component SensorVoter, tolerance 2.00, noise up to 0.50. Sensor 1 spikes for three cycles at 60. Sensor 2 starts to drift at 120. Sensor 0 freezes at 260. Over 399 cycles: 279 correct, zero wrong, and 120 withheld from cycle 279, when the two sensors left no longer agreed. Sensor 2 was excluded at 137. A plain average of the same readings was wrong in 261 cycles.

Five new Kani proofs cover every input, not a sample: an agreed value is agreed and in range, an outlier is never chosen, Unchecked comes only from one reading, the median is a median, and exclusion comes exactly at the limit, for limits 1 to 6 over every run of six cycles.

The website counts proofs with a script. It said 11. The script looked for proofs in lib.rs, and the five new ones are in sensor.rs. Ten minutes later it looked in both, and the count was 16.