Skip to content

An example: a household's tax and benefit reckoner, for a country; rounding reaches fifteen figures - #117

Merged
matthewjones372 merged 17 commits into
mainfrom
claude/eager-keller-5jqwz9
Nov 19, 2026
Merged

matthewjones372 merged 17 commits into
mainfrom
claude/eager-keller-5jqwz9

Conversation

@matthewjones372

Copy link
Copy Markdown
Collaborator

An adviser works out what a family has to live on in a workbook, and shows what a pay rise is worth by typing in the new pay. A policy researcher wants that line for every household in the country. households reads such a workbook with watershed-xlsx and draws every household's line, with nothing rewritten by hand.

cargo run --release -p watershed-gpu --example households            # 500,000 households
cargo run --release -p watershed-gpu --example households -- 20000

The workbook

examples/shared/household.xlsx, written by examples/shared/household.py and worked out by LibreOffice. One household on one sheet, the rules' numbers on another, and 31 formulas of sums:

  • income tax in three bands, with an allowance taken away from high earners, and social insurance, on each adult's pay;
  • a payment for children that the higher earner pays back, a hundredth at a time;
  • income support for the adults, for up to two children, for rent up to a limit by size of family, and for childcare if every adult works; withdrawn as the household earns, reduced for savings, refused above a level of savings, and capped for those who earn little;
  • school meals for those on income support who take home little.

It uses IF, AND, OR, MAX, MIN, VLOOKUP, and ROUND, ROUNDUP and ROUNDDOWN of numbers that vary. The reader took it as written. The rules look a little like the United Kingdom's, but every number is made up and much is left out, and so are the households: nothing it prints says anything about a real country.

What the example does

  1. Reads the workbook and checks every translated cell against its saved value.
  2. Checks 300 households against LibreOffice. All 900 answers agree.
  3. Runs a made-up country and prints the averages. The first 2,000 households are also run on the graph one at a time and must match bit for bit.
  4. Does work pay. Raises each household's first adult's pay by 500, forty times over, and reads what the household has to live on at each: 41 runs of the workbook a household. It counts households by how much of the next 1,000 they keep, and those who would be worse off after some rise, and prints the worst.
  5. A reform. Income support is withdrawn at 50p in the pound, not 55p, and school meals go to everyone on income support. It reruns the country for who gains and what it costs, then draws every line again.

What the reform does, which I did not arrange: no household has less, 37% gain, and the number who would be worse off for a rise doubles (22,018 to 45,490 of 500,000). School meals then end where income support does, further up the pay scale, and for a family with four children that last pound of support is worth 1,960 a year.

A rounding fix the LibreOffice check found

The first run failed its own check by a penny. ROUND(628 - 616.715, 2) is 11.29 in LibreOffice and was 11.28 here. The subtraction loses figures: the result is held as 11.284999999999968, which is 3 parts in 10¹⁵ short of the half, and #110 allowed 4 parts in 10¹⁶. That PR said a number in the gap could round the other way; this is an ordinary sum that lands there.

A number that depends on an input is now taken for a half or a whole number within 4.5 parts in 10¹⁵ of it. That is as far as fifteen figures reach for a number starting with a 1.

  • The other side of the trade: for a number starting with a 9 this reaches up to nine times further than fifteen figures do. A number Excel would read as just short of a half, in its fifteenth figure, can be taken for the half here. The README says so.
  • functions.xlsx's Rounding sheet gains the case: a seventeenth formula, ROUND(628-x*0.55*y,2), and twelve rows, for 408 in all. Every value still agrees with LibreOffice. With the old allowance that test fails.
  • Every workbook example's checks against LibreOffice still pass: credit_loss, audit, sensitivities, quotes, illustrations and live.

Measured

On a 4-core cloud VM, one run, 500,000 households:

The country once 0.2 s
Every household's line: 20,500,000 runs of the workbook 8.8 s
LibreOffice, a household at a time 10.96 ms a household, so 62 hours for the lines (scaled)

Also

  • CI's Examples job runs households -- 20000.
  • cargo test --workspace, cargo fmt --check, clippy with and without --features cuda, and cargo doc pass.

Not run

Nothing here has run on a GPU. With --features cuda every run goes to the GPU.


Generated by Claude Code

Expressions, formulas and scenario plans have floor, on the CPU and in
the GPU kernel. It takes the last of a plan's 32 instruction codes.

watershed-xlsx builds the four rounding functions on it, for a number
that depends on a varied input and a fixed number of places. A number
within four parts in 10^16 of a half or a whole number is taken as it,
which is how 0.29 * 100 comes to 29 and 1.005 to 1.01 as they do in
Excel. The test workbook gains a Rounding sheet: sixteen formulas over
396 pairs of inputs, held to LibreOffice's values.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
credit_loss reads a workbook that works out the expected credit loss on
one mortgage, on three paths of the economy, and runs its formulas for
every loan of a made-up book at once. It checks itself against the values
saved in the workbook, against LibreOffice recalculating the workbook for
each of 300 loans, and against the graph bit for bit. Then it works the
book out again for twenty slumps, worse and likelier.

The workbook and the reference are written by shared/credit_loss.py.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
It read the reported edits once, as soon as the cell showed its old
value. With a WorkerTable the report comes after the cell repaints, so
the read could find one edit, not two. It now waits for the second, as
the file's other tests do.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
audit runs a workbook for points spread over the whole of its inputs'
ranges and at every corner of them, and says where an answer is an error
or negative. It moves each input through its range from many starting
points and says whether each answer rises, falls or turns round, and
where it jumps, closing in on each suspected jump to confirm it. Given a
later version of the workbook, it lists the cells changed and runs both
for the same points, to show which answers moved and for which inputs.

On its own it takes the credit_loss workbook and a later version that
shared/credit_loss.py writes with one change that is meant and one slip,
and checks that it finds both and where the slip reaches.

Workbook::cells lists every cell that holds a value or a formula.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
A loan in default was given the loss on a sale at today's prices, where
a loan's lifetime loss allowed for prices falling on each path. For some
loans the provision then fell as they passed 90 days past due, which the
audit example showed.

A property is now sold some quarters after a default (Model!B14, six),
at that quarter's prices on each path, in every quarter of the schedule
and for a loan already in default. The provision rises with days past
due on every line the audit tries.

Both workbooks and LibreOffice's reference are written again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
sensitivities asks the graph for the derivative of a loan's provision,
in the credit_loss workbook, by 17 of the bank's choices and by every
quarter of three paths of the economy. It checks each against nudging
that input for the workbook's own loan, then adds them up over a made-up
book to say which choices and which quarters the provision rests on. It
ends with what a slope does not see: a threshold that moves loans from
one stage to another.

A derivative no longer comes to not-a-number where a division by zero
sits on a branch that is not taken. A long formula is differentiated in
steps, and the division's step stood outside the condition guarding it,
so nothing times infinity was passed down. Where nothing comes down to a
node, nothing is now passed on through a slope that can be infinite.

The made-up loan book moves to shared/loan_book.rs, for credit_loss and
this to share.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
quotes reads a car insurance rating workbook and works out the price for
every customer it can quote: 16 million combinations of age, area,
vehicle group, years without a claim, mileage, excess and cover. It
checks itself against the values saved in the workbook, against
LibreOffice recalculating the workbook for each of 300 customers, and
against the graph for 2,000 quotes. Then it puts next quarter's rates in,
works every quote out again, and says whose price moves.

The workbook and the reference are written by shared/rating.py.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
live reads a risk desk's workbook (sixty shares, six hundred positions,
each desk's totals against its limits, and the floor's figures) and feeds
its graph a stream of prices, one change at a time. Each change works
out again only the cells that price reaches. It reports the moments a
desk goes over its limit or a position is stopped out, and afterwards
says why one of them happened, from the history the graph kept.

It checks itself against LibreOffice following the same first 300
prices, and at the end against a second graph given the final prices at
once, cell for cell and to the last bit.

The workbook and the reference are written by examples/desk.py.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
illustrations reads a workbook that works out one member's yearly
pension statement (the pot followed to retirement at three rates of
growth, the income it might buy and whether that is enough) and runs it
for every member of a made-up scheme. It checks itself against the
values saved in the workbook, against LibreOffice recalculating the
workbook for each of 300 members, and against the graph bit for bit.

Then it seeks, for each member who is short, the least they could pay in
that would put them on track: Goal Seek for every member at once, each
try a run of the workbook, and each answer checked to be the least.

The workbook and the reference are written by shared/illustration.py.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
…unding reaches fifteen figures

households reads a workbook that works out what one household has to
live on after tax, social insurance and support, and runs it for a
made-up country. Then it raises each household's pay step by step, forty
times over, to find who keeps little of a rise and who would be worse
off for one, and does the same after a reform. It checks itself against
the values saved in the workbook, against LibreOffice recalculating the
workbook for each of 300 households, and against the graph bit for bit.

That check found a penny: ROUND(628 - 616.715, 2) is 11.29 in
LibreOffice and was 11.28 here. The subtraction loses figures, and what
is left is further from the half than the rounding allowed for. A number
that depends on an input is now taken for a half or a whole number
within 4.5 parts in 10^15 of it, which is as far as fifteen figures
reach, where it was 4 parts in 10^16. The test workbook's Rounding sheet
gains that case; the old allowance fails it.

The workbook and the reference are written by shared/household.py.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
@matthewjones372
matthewjones372 merged commit 160a049 into main Nov 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants