Four of five runs conserve perfectly; three are ecologically worthless

M4.5 closes M4 by measuring what aggregation costs, and adds no library code
except one defect fix the measurement found.

One rule is written once and applied at both resolutions. The control is what
makes the rest mean anything: with one member per class a class average is that
member, so the two runs must agree exactly, and they do, tick by tick, in every
channel. A deliberate one-unit drift in the aggregate rule is caught by it, so the
instrument is verified rather than assumed. Without it a measured gap would be
indistinguishable from a transcription mistake in one of the two runs.

The result is reported, not smoothed into a tolerance. At class widths ten and
fifty the aggregate population survives ten thousand ticks within 375 parts per
thousand on population and 43 on energy. At twenty-five, one hundred and two
hundred it dies out entirely while the individual run sustains seventy-five
members: a false extinction caused by resolution alone, because a whole class
starves the moment its average cannot pay upkeep, where individuals starve a few
at a time and the survivors keep the shared per-capita share up.

The collapse is not monotone in class width. Twenty-five destroys the population
and fifty sustains it. An earlier version of the test asserted that coarser is
never better; the measurement refuted it, so the assertion went rather than the
widths being chosen to make it hold. The non-monotonicity is asserted now, because
it is surprising and because the warning written around it could otherwise become
wrong without failing. A tier policy cannot assume degradation worsens smoothly as
classes widen, and M4.6 inherits that.

Conservation was exact at every tick on both sides of all five runs, including the
three that died out. That is the clearest available demonstration of the thing
ECOLOGY_MODEL keeps saying: conservation is not ecological evidence.

Two flaws in my own experiment were found before any number was believed. The
aggregate model had been producing overlapping classes, so the model measured was
not one a cohort could represent; newborns now extend the youngest class while it
is narrower than the width, and every step is checked to construct a valid Cohort.
The first figures were discarded.

The comparison also found a real M4.3 defect, which is what a validation milestone
is for. plan_advance checked affordability with arrivals added before losses were
taken, but emitted the ledger legs outflows-first, so an interval affordable as a
whole underflowed leg by leg and was refused at commit. A fifty-tick interval
shedding 10,480 against 6,950 held while drawing 13,080 in reproduced it. Arrivals
are the first leg now, matching the order the arithmetic was checked in, with a
regression and a corrected escrow expectation in an existing test.

Release 38/38, analysis, ASan 38/38 and clang-format all ran and passed here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-24 21:57:00 -04:00
co-authored by Claude Opus 5
parent 14e0c1af5e
commit b4c3da56e9
11 changed files with 1155 additions and 11 deletions
+51 -8
View File
@@ -154,11 +154,15 @@ void death_predation_and_migration_move_biomass_once() {
CHECK(plan->after().population() == 52 * residual_scale);
CHECK(plan->after().reserve() == held(920, 9'200));
CHECK(plan->legs().size() == 4);
auto ledger = world();
auto registry = registry_holding(before);
// The escrow has to be able to fund the immigrants it sends.
const std::array seed{Transfer{{5}, elsewhere, held(7, 7)}};
CHECK(ledger.transfer(ledger.last_action() + 1, seed).has_value());
// The escrow has to be able to fund the immigrants it sends, and the arrival
// is the first leg, so it must already hold that much before anything moves.
auto seeded = std::array<Inventory, reservoir_count>{};
seeded[backing.value - 1] = before.reserve();
seeded[elsewhere.value - 1] = held(10, 100);
auto created = Ledger::create(seeded);
CHECK(created.has_value());
auto ledger = std::move(*created);
const auto total = ledger.conserved_totals();
const auto committed = commit_advance(ledger, registry, *plan);
CHECK(committed.has_value());
@@ -168,10 +172,11 @@ void death_predation_and_migration_move_biomass_once() {
CHECK(ledger.balances()[backing.value - 1] == committed->reserve());
CHECK(ledger.balances()[detritus.value - 1] == held(40, 400));
CHECK(ledger.balances()[predators.value - 1] == held(30, 300));
// The escrow received twenty energy and two hundred matter and gave back ten
// and one hundred, so from seven it stands at seventeen and a hundred and
// seven. The legs apply in order, so it can fund the immigrants it sends.
CHECK(ledger.balances()[elsewhere.value - 1] == held(17, 107));
// The escrow sent ten energy and a hundred matter, then received twenty and
// two hundred, so from exactly what it needed to send it stands at ten and a
// hundred more. Arrivals are the first leg, which is what makes an interval
// affordable as a whole applicable leg by leg.
CHECK(ledger.balances()[elsewhere.value - 1] == held(20, 200));
}
void a_proposal_that_would_go_below_zero_is_refused_not_clamped() {
@@ -369,6 +374,43 @@ void a_stale_proposal_is_refused_and_changes_nothing() {
CHECK(once.last_action() == settled_action);
}
void an_interval_affordable_only_with_its_arrivals_still_commits() {
// The cohort sheds more than it currently holds, and receives more than enough
// to cover it. The interval as a whole is affordable, and planning says so, so
// commit must apply it: the ledger applies legs in sequence, and an outflow
// placed before the inflow would underflow a reservoir the interval affords.
// Found by the M4.5 comparison, where a fifty-tick interval shed 10,480 against
// 6,950 held while drawing 13,080 in, and was refused with ledger_failure.
const auto before = standing();
CHECK(before.reserve() == held(1'000, 10'000));
auto crossing = request();
crossing.flux.to_detritus = held(1'400, 14'000); // More than is held.
crossing.flux.from_elsewhere = held(1'900, 19'000); // Covers it and more.
crossing.after = {{0, 100, 40, held(1'500, 15'000), 0}, {100, 200, 20, Inventory{}, 0}};
const auto plan = plan_advance(before, crossing);
CHECK(plan.has_value());
CHECK(plan->after().reserve() == held(1'500, 15'000));
// The arrival is the first leg, so nothing underflows on the way through.
CHECK(plan->legs().size() == 2);
CHECK(plan->legs()[0].to == backing);
CHECK(plan->legs()[0].amount == held(1'900, 19'000));
CHECK(plan->legs()[1].from == backing);
auto registry = registry_holding(before);
// The escrow has to be able to fund what it sends.
auto seeded = std::array<Inventory, reservoir_count>{};
seeded[backing.value - 1] = before.reserve();
seeded[elsewhere.value - 1] = held(2'000, 20'000);
auto funded = Ledger::create(seeded);
CHECK(funded.has_value());
const auto total = funded->conserved_totals();
const auto committed = commit_advance(*funded, registry, *plan);
CHECK(committed.has_value());
CHECK(funded->conserved_totals() == total);
CHECK(funded->balances()[backing.value - 1] == held(1'500, 15'000));
CHECK(funded->balances()[detritus.value - 1] == held(1'400, 14'000));
CHECK(funded->balances()[elsewhere.value - 1] == held(100, 1'000));
}
void seeded_intervals_conserve_over_and_over() {
// Many intervals of pseudo-random bounded flux. Nothing here is an ecology:
// the point is that whatever a model proposes, the accounting either closes
@@ -488,6 +530,7 @@ int main() try {
a_vacant_cohort_is_not_an_extinction();
the_declared_result_must_be_what_the_fluxes_imply();
a_stale_proposal_is_refused_and_changes_nothing();
an_interval_affordable_only_with_its_arrivals_still_commits();
seeded_intervals_conserve_over_and_over();
a_moved_from_plan_is_still_a_whole_plan();
std::cout << "PASS interval accounting, refusal without clamping and seeded conservation\n";