Make construction reproduce the body it claims to build

Construction composed the mass difference instead of differencing the two
composed bodies. Those are not the same: composing the difference throws
away the rounding the existing body already carries, so the budget summed
to the right total while funding individual channels short or over. At
target mass 1001 growing from 10 to 60 it funded C25 N7 P2 other16,
leaving nitrogen and phosphorus one short each and other two over, so
spending it could not produce the body the same rules derive.

Construction is now the per-channel difference between the composed
bodies, which funds C25 N8 P3 other14 for that case.

That difference can be negative on a channel, because the remainder rule
is not monotone: a body growing from 13 to 14 femtograms sees other fall
from 6 to 5. Construction is therefore a transition with an intake and a
release rather than a single requirement, and the release is a rounding
artifact bounded by a few femtograms, not excretion.

The invariant held + intake - release == reached is asserted per channel
for the reported case, for the releasing case, across six target sizes by
seven growth fractions by four material budgets, and across a forty-step
walk from nothing to full growth where accumulated intake and release are
checked against the whole history. The net of every transition is also
asserted to equal what a plan charges material for. These tests were
confirmed to fail against the previous implementation.

Native Release, clang-tidy analysis, ASan and format checks pass 19/19.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-23 12:26:40 -04:00
co-authored by Claude Opus 5
parent be71d4f441
commit e0fd4680f6
5 changed files with 197 additions and 25 deletions
@@ -42,6 +42,17 @@ of and not only how much. A split assigns the first three channels by share and
gives the remainder to the last, so mass is conserved exactly and a body can be
spent through the ledger without a rounding leak.
Construction is the difference between the two composed bodies, not the
composition of the mass difference. Those are not the same: composing the
difference discards the rounding the existing body already carries, so a budget
built that way sums to the right total while funding individual channels short or
over, and spending it could not produce the body the same rules derive. Because
that remainder rule is not monotone per channel, a step can also free a femtogram
as the shares rebalance, so construction is a transition with both an intake and a
release rather than a single requirement. The release is a rounding artifact
bounded by a few femtograms, not excretion, and the invariant is exact: the body
held, plus intake, minus release, is the body reached, on every channel.
Reproduction investment is the body scaled by the genome's reproduction fraction,
with its energy priced at the same construction rate as the organism's own tissue:
building offspring tissue costs what building your own does. A genome without the
+22
View File
@@ -519,6 +519,28 @@ drives a real `FeedingCommunity` tick, the ledger totals are identical before an
after, and a bite one femtogram past the derived cap is refused by the existing
M2.3 contract. The opening inventory is checked to be exactly the caller's.
Review of `be71d4f` found one defect (2026-09-23): construction composed the mass
difference rather than differencing the two composed bodies, which discards the
rounding the existing body already carries. At target mass 1001 growing from 10 to
60, it funded C25 N7 P2 other16: the right total, but nitrogen and phosphorus one
short each and other two over, so spending the budget could not produce the body
the same rules derive. Construction is now the per-channel difference between the
composed bodies, which funds C25 N8 P3 other14 for that case.
Because the remainder rule is not monotone per channel, that difference can be
negative on a channel, so construction became a transition with an intake and a
release rather than a single requirement: a body growing from 13 to 14 femtograms
acquires one carbon and one nitrogen while freeing one from other. The release is
a rounding artifact bounded by a few femtograms, not excretion.
The invariant `held + intake - release == reached` is now asserted per channel for
the reviewer's exact case, for the releasing case, across six target sizes by
seven growth fractions by four material budgets, and across a forty-step walk from
nothing to full growth where the accumulated intake and release are checked
against the whole history. The net of every transition is also asserted to equal
what `plan_development` charges material for. These tests were confirmed to fail
against the previous implementation.
Coverage limitation: as in M3.2, the overflow guards are unreachable through the
public API at schema 1 ranges and are recorded rather than covered by a test that
could not fail. The small integer helpers are duplicated between `development.cpp`