Decide affordability where composition is known

A construction transition could require more of an element than was
available, because the check compared net mass. A step growing a body
from 13 to 14 femtograms nets one femtogram but acquires a carbon and a
nitrogen while freeing one of other, and released other pays for neither.
Matching totals let one element silently fund another.

Net mass was never the right question, and the layer asking it could not
ask a better one: plan_development has no composition. A single scalar
pool could not carry the answer either, since it cannot say that carbon
is plentiful while nitrogen is not. The environment now states what is
available per ledger channel.

plan_development keeps a total-mass bound, which is sound because net
never exceeds gross, but it is a proposal rather than an authority.
metabolic_budget narrows it to the largest step whose own intake fits
channel by channel, and reports the growth that step actually funds. That
revises ADR-0031 on this point, recorded in both ADRs.

The tests place a single femtogram in each channel in turn and require
that no step needing a different element is funded, that nothing is
acquired beyond what is present, and that the mass-only plan would have
admitted the step; a carbon and a nitrogen together then fund it exactly.
Across six target sizes by seven growth fractions by four stock levels,
every reported intake fits the availability channel by channel and never
exceeds the proposed step. Confirmed to fail with the check removed.

The releasing case moved to a target of 20 femtograms, where the step
occurs at the full rule step rather than depending on a scarce supply
that the corrected plan no longer bounds the same way.

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 13:02:44 -04:00
co-authored by Claude Opus 5
parent e0fd4680f6
commit 36ee71cfe9
9 changed files with 226 additions and 55 deletions
+14 -9
View File
@@ -30,7 +30,12 @@ Genome build(const GenomeDraft& source) {
check(genome.has_value());
return *genome;
}
constexpr EnvironmentState temperate{293'150, 1'000'000'000};
// Development bounds growth by total mass, so a single channel carries the supply
// here; which elements a step consumes is settled in metabolism_tests.
constexpr evo::accounting::Inventory supply(std::uint64_t matter, std::uint64_t energy) {
return {{energy}, {evo::accounting::Femtograms{matter}, {}, {}, {}}};
}
constexpr EnvironmentState temperate{293'150, supply(1'000'000'000, 1'000'000'000)};
void hand_calculated_phenotype() {
const auto genome = build(draft());
@@ -75,7 +80,7 @@ void identical_inputs_give_identical_phenotypes() {
for (std::uint32_t realized = 0; realized <= 1000; realized += 125) {
for (std::uint32_t damage = 0; damage <= 1000; damage += 250) {
for (const auto temperature : {0U, 293'150U, 400'000U}) {
const EnvironmentState environment{temperature, 1'000'000};
const EnvironmentState environment{temperature, supply(1'000'000, 1'000'000)};
const auto first = derive_phenotype(genome, {realized, damage}, environment);
const auto second = derive_phenotype(genome, {realized, damage}, environment);
CHECK(first && second && *first == *second);
@@ -117,14 +122,14 @@ void thermal_shortfall_is_reported_not_enforced() {
const auto tolerant = build(source);
const auto bare = build(draft());
for (const auto offset : {0U, 5'000U}) {
const EnvironmentState warm{293'150 + offset, 0};
const EnvironmentState warm{293'150 + offset, {}};
const auto inside = derive_phenotype(tolerant, {1000, 0}, warm);
CHECK(inside && inside->thermal_shortfall == 0);
}
const EnvironmentState hot{293'150 + 8'000, 0};
const EnvironmentState hot{293'150 + 8'000, {}};
const auto stressed = derive_phenotype(tolerant, {1000, 0}, hot);
CHECK(stressed && stressed->thermal_shortfall == 3'000);
const EnvironmentState cold{293'150 - 8'000, 0};
const EnvironmentState cold{293'150 - 8'000, {}};
const auto chilled = derive_phenotype(tolerant, {1000, 0}, cold);
CHECK(chilled && chilled->thermal_shortfall == 3'000); // Symmetric about the reference.
// Without the capability every deviation is reported in full.
@@ -167,14 +172,14 @@ void plans_are_bounded_and_funded() {
CHECK(funded->material_required == 2'632'000); // 22832000 - 20200000
CHECK(funded->energy_required == 105'280); // material * 40 per 1000 fg
// One femtogram short of the full step buys exactly the largest step that fits.
const EnvironmentState tight{293'150, 2'631'999};
const EnvironmentState tight{293'150, supply(2'631'999, 1'000'000'000)};
const auto reduced = plan_development(genome, {500, 0}, tight);
CHECK(reduced);
CHECK(reduced->after == (GrowthState{549, 0}));
CHECK(reduced->material_required == 2'624'000);
CHECK(reduced->material_required <= tight.available_material);
CHECK(reduced->material_required <= tight.available.matter[0].value);
// No material funds no growth, and nothing is granted.
const EnvironmentState barren{293'150, 0};
const EnvironmentState barren{293'150, {}};
const auto refused = plan_development(genome, {500, 0}, barren);
CHECK(refused && refused->after == (GrowthState{500, 0}));
CHECK(refused->material_required == 0 && refused->energy_required == 0);
@@ -198,7 +203,7 @@ void flooring_consequences() {
{Capability::membrane, 1, 0},
{Capability::target_size, 1, 0}};
const auto tiny = build(source);
const EnvironmentState barren{293'150, 0};
const EnvironmentState barren{293'150, {}};
const auto plan = plan_development(tiny, {500, 0}, barren);
CHECK(plan && plan->after == (GrowthState{550, 0}));
CHECK(plan->material_required == 0 && plan->energy_required == 0);