A working project, first cut for comment

Flow Engines

Spreadsheets, build systems, energy charts and insurance programmes are the same shape. They differ in the algebra carried on the wires. This is an attempt to say that in types, draw it with one renderer, and run it on whichever engine suits the scale.

Andrew Condon, with Claude. Written 26 November 2026 from the project's working notes. Everything described here exists and passes its own tests unless it says otherwise. Much of the code is private for now; excerpts are quoted below.

The idea

Many fields draw the same picture. There are things that hold a value, processes that compute, and connections between them. A spreadsheet has columns and formulas. A Makefile has files and rules. A life cycle assessment has materials and processes. A reinsurance programme has losses and terms.

A survey across about twenty fields found nearly one structure and only a handful of algebras over it. What a step is allowed to do, and what must hold afterwards, is what varies: mass is conserved, or money is split by "the lesser of", or nothing is conserved and only dependency matters.

If that is right, three things follow, and the project tests each.

  • One value, one renderer. The shape is a single typed value. A picture of it is drawn by one library, whose layouts are held to stated laws.
  • The engine is a choice. A model is a plan. It can be evaluated in memory, as a database query, by a solver, or by the operating system. Every engine must agree with a small reference evaluator.
  • Types remove errors, they do not report them. A spreadsheet whose formulas cannot name a row number has no off-by-one. A lookup by a key held to the column it looks up cannot miss.

The intended reader of the finished thing is someone who does not think of themselves as a programmer. They see tables sitting in a flow, with functions between them.

The shape, and the renderer

hylograph-flow is the shape as a PureScript value. A flow has items (what holds a value), steps (what computes, with named ports) and wires (a step reads an item, or writes one). There is no wire from item to item or from step to step. Whatever a domain knows rides in three type parameters that the library never inspects.

Three things are deliberately kept out of the value: what is drawn (a projection), run state (an overlay), and grouping (a group can be closed into one step and opened again).

hylograph-flow-render draws a projection. A layout engine is a value that names the laws it promises to keep, so any engine's output can be checked and measured in the same way. The package has a layered engine that is a plain graph when every edge is equal and a Sankey when a wire says how wide it is, a columns engine for nodes the caller sizes (a table of rows is one), and an engine that keeps order as groups open and close. A layout is data: boxes, ports and routes, from which the SVG is derived.

An energy flow chart with its groups closed: a few broad boxes joined by ribbons
Lawrence Livermore's 2024 US energy flow chart, transcribed by hand and drawn by the renderer with its groups closed.
The same chart with every group opened into its parts
The same flow with every group open. Order is kept across the change, and every sampled frame of the transition carries its widths.

One shape, a few algebras

The taxonomy below is a synthesis of two literature surveys commissioned for the project. It should be read as a hypothesis. The surveys mark each claim as read or recalled, and several of the unifying statements are the surveyors' own inferences.

ClassA step isWhat holdsFieldsNatural engine
Linear recipesso much of each thing per unit of activityconservation of a projected quantity, often only approximately in real datalife cycle assessment, input-output economics, material flow, bills of materials, double-entry accountsrecursion with a cache, or a recursive query; with loops, a linear solve
Clamps"the lesser of" and "the excess over"conservation exactly; not proportionality, so order of aggregation is part of the meaninginsurance and reinsurance, securitisation waterfalls, clearinga monotone fixed point
Nothing conserveda dependency or a gateoutputs are determined by inputs; provenance propagatesbuild systems, lineage, software bills of materials, fault trees, spreadsheetsa query over a semiring
With timea rate, or a step with statea stock integrates its flowssystem dynamics, epidemiology, a battery, a loana fold over steps; an integrator
Optimiseda technology with a capacitybalances as constraintsenergy system models, dispatcha linear programme

Two findings from the surveys shaped the design. Real data does not balance, so an imbalance must be a value that is reported with a tolerance, not something the types forbid. And aggregation does not commute with solving: totals of a solved system can be grouped freely, but grouped recipes solved again give a different answer.

Seven small proofs

Each row of that table has a small working demonstration. All seven follow one pattern: the model is stated in PureScript, a reference engine evaluates it, a second engine evaluates the same tables, and the two are asserted equal. Each also has a law that is tested, with a spoiled case that must fail.

The pictures are drawn from each demonstration's own results with the project's libraries. Figures marked invented are invented.

1Linear recipes: two cars, in PureScript and in DuckDB

Claim
A model of a petrol car and an electric car, from mine to scrapyard, is a set of recipes and a demand. Working out what the demand requires is a recursive query, and many cars are many rows of one query.
Result
The query, the PureScript recursion and the original hand-written model agree on every transfer of mass, to 1.5e-11 kg, across 96 cases. 500 cars take 9 ms.
Found
The second battery pack is a threshold on years, so it belongs in the demand and not in any recipe.

The model, PureScript

type Exchange =
  { direction :: Direction   -- Takes | Gives
  , item      :: ItemName
  , perUnit   :: Number }

type Recipe =
  { process   :: ProcessName
  , place     :: Place
  , reference :: ItemName
  , role      :: Role        -- Makes | Treats
  , exchanges :: Array Exchange }

type Demand = { item :: ItemName, quantity :: Number }

pull :: forall substance
      . System substance
     -> Array Demand
     -> Either (Array Problem) Solved

The same engine, SQL

WITH RECURSIVE need(case_number, variant,
                    process, activity) AS (
    SELECT demand.case_number, demand.variant,
           recipe.process, demand.quantity
    FROM demand
    JOIN recipe ON recipe.variant = demand.variant
               AND recipe.reference = demand.item
  UNION ALL
    SELECT need.case_number, need.variant,
           asks.asked, need.activity * asks.per_unit
    FROM need
    JOIN asks ON asks.variant = need.variant
             AND asks.asker = need.process
)
SELECT case_number, variant, process,
       sum(activity) AS activity
FROM need
GROUP BY case_number, variant, process;
Two Sankey diagrams of mass, a petrol car above an electric car
Both cars as Sankeys of mass, drawn from the query's transfers at one scale. Air and rock dominate, so most ribbons are at the least width and not to scale. The numbers are the car model's own, with its caveats.

2Linear recipes with a loop

Claim
With a loop, the recursion becomes a series, and its limit is a linear solve. The series cut off at any depth falls short by an amount that is itself a value.
Result
Grid loss, where generating electricity asks for some of itself, uses the model's own figure and settles in 7 to 9 rounds. A loop with a gain of one or more is reported as having no solution.
Found
Grouping the mines into one process before solving gives 50,929 kg of rock moved. Solving first and grouping after gives 63,699 kg. A dense solve in PureScript takes 14 s at 800 processes, so real input-output tables need an outside solver.
A flow with a ribbon that turns back onto its own process, and two charts of a series converging
The loop drawn as a ribbon that turns back on its process, and the series by depth approaching the solve.

3Clamps: one loss through a reinsurance programme

Claim
A step that takes "the lesser of" conserves exactly but is not proportional, so the order in which losses are added is part of the meaning.
Result
Money is in whole cents and conservation is exact. The evaluator and DuckDB agree on 242,216 amounts. A ring of reinsurers who cede to each other settles when limits or an outside share stop it, and is reported as not settling otherwise.
Found
A loss of 540 at three locations with a deductible of 50: taken at each location the insured bears 140.00; taken once on the event, 50.00.

The terms, PureScript

data Term
  = Deductible Cents
  | Limit Cents
  | Layer { attachment :: Cents, limit :: Cents }
  | QuotaShare BasisPoints
  | Franchise Cents

applyTerm :: Term -> Cents -> Split
-- Split = { taken :: Cents, left :: Cents }

The same, SQL

least(
  greatest(amount - attachment, 0),
  coalesce(lim, amount)
) * share // 10000
Three Sankey diagrams of an insured loss split between parties; in the second and third the insured's box differs
One event through the programme, then the same loss with the deductible taken per location and per event. Teal ribbons end at the party that bears them. The programme and its figures are invented.

4Nothing conserved: one graph, several readings

Claim
The marks drawn on a spreadsheet or a build are not special cases. Each is one dependency graph evaluated in a semiring: two operations, one along a path and one across paths.
Result
A loan workbook and a 225-module build under five readings: depends on, number of paths, which sources, longest chain, nearest source. "Which sources" equals the rule the picture already used for cells that rest on a hand-set value. The modules reached from three edited sources are exactly the thirteen marked as rebuilt.
Found
By column the loan has a circle (closing, opening, closing). Readings that only ask "whether" settle in four rounds; counting paths never does. By cell there is no circle, and 2189 paths from one hand-set cell to the total.
The same small dependency graph drawn five times with different values on its nodes
The loan's graph five times, one reading each. Same graph, different numbers on it.

5With time: a house, its panels and its battery over a day

Claim
With time, a step has state. A day is a table with a row per hour, each reading the row before. Summed, the day is again a balanced flow with the battery's change as one more term.
Result
A PureScript fold, a DuckDB recursive query and an existing simulation of the house agree across 288 configurations and 6,912 hours.
Found
SQL window functions alone get 54 of 192 battery houses right as a running total, 122 with a floor at empty, and all 192 only with a window over every pair of steps. That is where a spreadsheet's running total ends and a state machine begins. At 15-minute steps the grid's supply moves by up to 0.2 kWh.
Line charts of a battery's level through a winter and a summer day, and Sankey diagrams of each day's energy
The battery's level with its bounds, sun and load behind it, and each day summed. The numbers are the house model's, several of them assumed.

6Optimised: the same house, with the plan chosen

Claim
When the plan is chosen and not evaluated, the engine is a solver, reached as a library call and not trusted.
Result
PureScript writes the problem as generic tables. A Julia script (JuMP with HiGHS) that knows nothing about houses solves it. The plan is then run through the laws of the previous demonstration, and its optimality is verified in PureScript from the solver's duals.
Found
The simple rule is already optimal in 148 of 192 houses. A whole year (52,560 variables) solves in 0.7 s; starting Julia costs about 2 s.
Line charts comparing a battery's level under a simple rule and under the optimal plan, with cheap hours shaded
The rule against the best plan, cheap hours shaded. The tariff is invented.

7Builds: the plan is ours, the executor is the operating system

Claim
Deciding what to rebuild is a pure computation. Running the recipes is not ours to reimplement.
Result
For a real Makefile of 24 file targets, in seven states of the file system: the plan equals what make -n says it will run, exactly the planned files are rewritten, and the output equals a build from nothing.
Found
A prerequisite that a recipe reads and the Makefile does not declare is invisible to both the plan and make. They agree, and are wrong together. See Builds.

Spreadsheets with no cell addresses

The spreadsheet work asks the question once asked of goto. If positional references are simply left out, is the result a toy, or a system that is sound on real work?

The law: every reference is to a whole column of a whole table, or of a declared sequence of tables. No constructor takes a row number, an offset or a count. A formula is written once on a column and applies to every row.

The test is an importer. It reads a real workbook, makes it legal, evaluates the legal form by its structure, and compares every computed cell with the value Excel stored.

400 workbooks of the Enron sample, 515,878 formula cellsCellsShare
Legal, as one expression for its column302,99858.7%
Legal, but said cell by cell62,01412.0%
Legal, a declared import from another workbook36,9517.2%
Entered: a formula that reads no cell2,6280.5%
Refused by design (a cell that reads itself, indirect addressing)10,6962.1%
Gap: the model cannot yet say it100,59119.5%

Where the model computes a value it equals Excel's in 362,291 cells and differs in 5,349. Eighty workbooks are reproduced completely. So about 78% of real formula cells are legal with no positional construct at all. A fifth are still gaps, which is why this is not yet an answer.

A workbook of our own, written with Excel tables and SUMIFS, now imports with 540 of 865 formula cells equal to Excel's and none different.

The picture: tables in a flow, at three distances

A sheet is drawn as tables joined by ribbons. A ribbon is as wide as the rows it feeds. There are three distances: every row, rows hidden in the middle, and an x-ray with no values at all, where each table is a record of its columns. The x-ray is the type signature of the sheet.

Everything ordinary is grey. Colour is kept for what a reader should ask about.

A loan as tables joined by ribbons, with the middle rows of the long table hidden
A 120-month loan with rows hidden. A row with a hand-set cell, and a row where the rate changes, are never hidden.
The same loan with no values: each table shows only its columns and their origins
The same sheet as an x-ray. The rate's two ranges run into the column in two colours; the hand-set interest leaves by its own yellow strand.
A hand set this value
A column in ranges, one per row of a dated table
As found: a formula the model cannot say yet
From outside, not yet checked
No mark: one formula for every row

None of these is called an error. A value typed over a formula is "set by hand", and it carries a reason or the words "no reason given". The principle is that a column a hand has touched is a different type from one that no hand has, so the two cannot be mistaken for each other.

The loan as types (a sketch of where the model is heading, not yet the model)

data Cell a
  = AsComputed a
  | SetByHand { reason :: Reason, value :: a, formulaGave :: a }

type Rates = Since Month (Rate Year)              -- a value in force from each key until the next

type Payments = Series Month
  ( rate     :: Stepped    (Rate Year)            -- two ranges, from Rates
  , opening  :: Resting    (Money EUR)            -- reads closing, which rests on a hand
  , interest :: Overridden (Money EUR)            -- one cell set by hand
  , paid     :: Entered    (Money EUR)
  , closing  :: Resting    (Money EUR) )

type Loan =
  { principal :: One (Money EUR), rates :: Rates, paid :: …, byHand :: ByHand Month ( interest :: Money EUR ) }
  -> { payments :: Payments, totalInterest :: One (Resting (Money EUR)) }

Two constructs were added this week. A conditional fold can hold several tests, which is SUMIFS. And an entered value can be held to a declared choice, either listed values or the keys of another table's column. A lookup by such a value cannot miss, so #N/A is removed by construction for that lookup.

Builds, drawn and explained

A build is the same picture. Targets are rows of a table keyed by name, a pattern rule is one formula for every row, and a rule written out for one target is an override. What one run did to each row is a value with a reason: kept, or rebuilt because its source changed or because a prerequisite was rebuilt.

The seventh proof left one failure standing: a file a recipe reads without declaring it. A companion store records what each step actually read during a run. With that record the undeclared read shows in the picture, with no build from nothing.

A build drawn as tables in a flow, with one red ribbon from a source file marked not in the Makefile to a target marked out of date
A real run. The red ribbon is a read the Makefile does not declare; the target it reaches is out of date, and neither make nor the plan can see it. Scroll sideways: fitting a wide picture to the page is not solved.

The same picture is drawn for a real PureScript build, from the journal of a run. The pieces have names: Warrant keeps the journal of what each run read and did, Güell makes the picture from it, and Brunel, an operations application, shows it on its Build tab. The subject below is Minard, one of our own codebases.

An application's Build tab showing packages as tables joined by ribbons, with one module marked edited and compiled
Brunel's Build tab, rows hidden. One module was edited; the hidden stretches say how many of their rows were compiled because of it. Each of our packages is a table with a row for each module, and the registry's 113 packages are one table.

What that build showed (932 modules, 103 of them ours):

  • A comment added to the most-imported module recompiles it and all 68 modules that import from it, and nothing else. The compiler has no early cut-off.
  • The same file touched but unchanged compiles nothing, where a rule by time would rebuild 69. The compiler decides by content.

What we read

Two surveys were written for the project, one of the physical and economic sciences and one of finance, risk, accounting and software. They were written by Claude and each claim in them is marked as read from the source or recalled. Nothing below has been independently verified, and the notes say where a source turned out to fit less well than hoped.

SourceWhy it matters hereStatus
Rick Lupton, "Flow programming" (preprint, 2025)Recipes per unit of activity, "pull production" and "push consumption", and a marked non-linear step. The nearest existing thing to the recipes above.read
Lupton and Allwood, hybrid Sankey diagrams (2017), and floWeaverThe dataset and the diagram definition kept apart, with conservation written down.read
ledger-semantics (Lean 4)Accounting with the balance law as a theorem, held to a production tool by bisimulation. The method of holding two engines equal is the same.read
Green, Karvounarakis and Tannen, provenance semirings (2007)"One graph, many algebras" for the class where nothing is conserved. The fourth proof found the fit is loose: it evaluates paths, where the paper's objects are derivations.recalled
Baez and others, stock and flow diagrams, and AlgebraicJuliaThe same idea with time: one structure, several semantics, composed.read
Bain, "Insurance Spirals and the Lloyd's Market" (1999); Eisenberg and Noe on clearingCessions in a circle as a fixed point. That the two are one form is the surveyor's inference.read inferred
Mokhov, Mitchell and Peyton Jones, "Build Systems à la Carte"The taxonomy of build systems, and correctness as "equals a build from scratch".recalled
Hermans and others on spreadsheet smellsWhat existing linters look for, as a baseline for the importer.surveyed

The claim we most want tested by someone who knows these fields: that insurance terms, securitisation waterfalls and clearing are one algebra of clamps. The surveyor found no source that states it across all three.

What is missing

  • No shared library yet. The seven proofs each wrote their own tables and comparisons. What they have in common (a plan as data, a reference engine, a residual as a value, variants chosen by the view, an order of aggregation) is described seven times and written nowhere.
  • No real data in the proofs. The cars and the house are our own models. The insurance programme and the tariff are invented. The obvious first real datasets are an open life cycle inventory and a plain-text accounting journal.
  • The spreadsheet work has an importer and no editor. Nothing yet lets a person make a sheet.
  • A fifth of real formula cells are still gaps, most of them several tables sharing one sheet.
  • The renderer has no axes or time, cannot put words on a ribbon, and cannot fit a wide picture to a page. Text widths in tables are estimated, and sometimes collide.
  • Sources are lost when a model's figures become recipe coefficients.
  • The unifying claims are inferences. Each wants a source or a small proof before it is leaned on.

The code

Everything is PureScript, with SQL for DuckDB and one Julia script. The two libraries are public and published to the PureScript registry. The rest is private while it is unsettled; ask for access.

PieceWhat it isState
hylograph-flowThe shape: items, steps, wires, projections, groupingsPublic, 0.2.0
hylograph-flow-renderLayout engines as values with laws; measures; one drawingPublic, 0.7.1
flow-enginesThe seven proofs and their galleryPrivate
Sheets model, importer and tables pictureThe law, the evaluator, the measure against Excel, the x-rayPrivate
Build picture and run journalA build as tables in a flow, with what each step readPrivate

What would help most from a reader: where an idea did not come across, which claim you do not believe, and which field you know that does not fit the table.