Expand description
Conservation, as a thing a process must answer for rather than a property it is trusted to have.
SurfaceOptics stores reflectance and transmittance and computes absorptance
as the remainder, so a surface cannot return more light than reached it. That
is the right idea and the wrong scope: it protects one quantity at one kind of
boundary. Momentum in a collision, charge across a junction, mass through a
pipe and energy across a coupling interface are all the same problem, and all
of them are places a simulation can quietly manufacture something.
So a process reports what it holds, before and after, and the difference is
checked. A Ledger is that report; audit is that check; a Violation
names what went missing and where.
§Relative to what, exactly
Floating-point arithmetic loses the low bits of every sum, so no real integrator conserves anything exactly and a test for exact equality would fail on correct code. The loss is bounded and relative — but relative to the wrong thing if one is not careful, and this is the trap:
A well-formed system’s conserved total is often exactly zero. One domain holds a debt of 28.9 J and another holds 28.9 J of asset, and the sum is nothing. Comparing the residual against that sum makes every rounding error a 100% relative error, and the audit fires on correct code.
So a Ledger entry records the largest magnitude that went into it as well as
the total, and audit judges the change against that. Rounding error scales
with the size of the numbers being added, not with the size of their sum, and
this is the version of the tolerance that says so.
Modules§
- quantity
- The quantities worth naming. Strings rather than an enum, so a domain crate
can add its own without editing the kernel — but these spellings are the ones
auditwill match across domains, so use them.
Structs§
- Ledger
- What a process claims to be holding, by quantity name, in SI base units.
- Tolerances
- Compare two ledgers and name the first quantity that moved by more than
rel_tol, in the fixed order the ledger keeps its names. - Violation
- A conservation law that did not hold.
Traits§
- Conserves
- Something that can say what it is holding. Implemented by domains, and by anything else whose books are worth checking.
Functions§
- audit
- Audit with one tolerance for every quantity.
- audit_
with - Audit with a tolerance per quantity.