Make who breeds part of the rule, so the divergence is attributable
The two runs allocated contested breeding slots in different orders: the individual run by member insertion order, the aggregate run by stored class order, which is youngest first. When eligible parents outnumber free slots that decides which parents reproduce, for a reason that has nothing to do with averaging. The control never reached the capacity boundary and so could not see it, which left ADR-0040's central claim unsupported rather than merely imprecise. The allocation order is part of the stated rule now, oldest first, honoured at both resolutions: classes partition ages, so the oldest class holds the oldest members, and ordering inside a class stays something only the individual run can see, which is a resolution effect rather than an implementation difference. A second control sits at the capacity boundary, twelve eligible parents contending for one free slot, and both controls compare the whole distribution of members rather than censuses. That change matters by itself: whoever breeds hands the same investment to a child either way, so every total agrees while the distribution does not, and a census-only control cannot see a different parent having bred. The probe diverging only by tick 44 is that effect. Attribution was verified by mutation rather than argued. Restoring the individual run's insertion order fails the new control; restoring the aggregate run's youngest-first order fails it; the earlier one-unit drift in aggregate upkeep still fails the first. Since either allocation order alone fails, the reported divergence is attributable to averaging. My first attempt at the control was wrong and the same sweep caught it. I gave the contested fixture ages descending with the index, reasoning that this made insertion order differ from age order; it does the opposite, and the individual-side mutation passed. Ages ascend now, so oldest-first disagrees with both the insertion order and the stored class order. Without the sweep the new control would have looked like it established attribution while covering half of it. Also added the depletion check the ADR's attribution argument relies on: a shared store that ran out would make intake order-dependent too. I had written that the fixture asserts this before it did, which is now true. The measurements were regenerated and are unchanged. Saying so plainly rather than as confirmation: the finding was about what the numbers can be attributed to, not about their values. 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:
+157
-11
@@ -6,6 +6,7 @@
|
||||
#include <cstdio>
|
||||
#include <expected>
|
||||
#include <iostream>
|
||||
#include <ranges>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -52,6 +53,14 @@ constexpr std::uint64_t capacity = 200;
|
||||
[[nodiscard]] constexpr std::uint64_t per_capita(std::uint64_t living) noexcept {
|
||||
return living == 0 ? 0 : environment_energy / living;
|
||||
}
|
||||
// Who breeds when there are fewer free slots than eligible parents. This has to be
|
||||
// part of the rule rather than a consequence of how each run happens to iterate:
|
||||
// allocating contested slots in different orders changes which parents reproduce
|
||||
// independently of any averaging, and a divergence caused by that is not a
|
||||
// divergence caused by resolution. Oldest first, which both resolutions can honour:
|
||||
// classes partition ages, so the oldest class holds the oldest members. Ordering
|
||||
// within a class is the one thing only the individual run can see, and that is a
|
||||
// resolution effect rather than an implementation difference.
|
||||
} // namespace rule
|
||||
|
||||
// Matter behaves identically in all four channels here, so one number is tracked
|
||||
@@ -90,6 +99,7 @@ struct IndividualRun {
|
||||
std::uint64_t matter_store{};
|
||||
std::uint64_t births{};
|
||||
std::uint64_t deaths{};
|
||||
std::uint64_t capacity{rule::capacity};
|
||||
|
||||
[[nodiscard]] Census census() const {
|
||||
Census now;
|
||||
@@ -159,6 +169,13 @@ struct IndividualRun {
|
||||
if (!member.alive) {
|
||||
continue;
|
||||
}
|
||||
// Bounded by what is there, so the arithmetic is safe, but the fixture
|
||||
// is sized so that it never binds: if it ever did, intake would depend
|
||||
// on the order members are visited in, and a divergence caused by that
|
||||
// would look like a divergence caused by resolution. Checked rather
|
||||
// than assumed, on both sides.
|
||||
check(environment >= share);
|
||||
check(matter_store >= rule::matter_intake);
|
||||
const auto taken = std::min(share, environment);
|
||||
environment -= taken;
|
||||
member.energy += taken;
|
||||
@@ -184,18 +201,32 @@ struct IndividualRun {
|
||||
for (const auto& member : members) {
|
||||
population += member.alive ? 1 : 0;
|
||||
}
|
||||
const auto before = members.size();
|
||||
for (std::size_t index = 0; index < before; ++index) {
|
||||
auto& member = members[index];
|
||||
if (!member.alive || population >= rule::capacity) {
|
||||
continue;
|
||||
}
|
||||
if (!rule::breeds(member.age, member.energy)) {
|
||||
// Oldest first, as the rule requires, with the index breaking ties so the
|
||||
// order is total. Insertion order would have allocated contested slots to
|
||||
// different parents than the aggregate run does, which would have shown up
|
||||
// in the comparison as if resolution had caused it.
|
||||
std::vector<std::size_t> eligible;
|
||||
for (std::size_t index = 0; index < members.size(); ++index) {
|
||||
const auto& member = members[index];
|
||||
if (!member.alive || !rule::breeds(member.age, member.energy)) {
|
||||
continue;
|
||||
}
|
||||
if (member.matter < rule::investment_matter) {
|
||||
continue;
|
||||
}
|
||||
eligible.push_back(index);
|
||||
}
|
||||
std::ranges::sort(eligible, [&](std::size_t left, std::size_t right) {
|
||||
if (members[left].age != members[right].age) {
|
||||
return members[left].age > members[right].age;
|
||||
}
|
||||
return left < right;
|
||||
});
|
||||
for (const auto index : eligible) {
|
||||
if (population >= capacity) {
|
||||
break;
|
||||
}
|
||||
auto& member = members[index];
|
||||
member.energy -= rule::investment_energy;
|
||||
member.matter -= rule::investment_matter;
|
||||
members.push_back({0, rule::investment_energy, rule::investment_matter, true});
|
||||
@@ -238,6 +269,7 @@ struct AggregateRun {
|
||||
std::uint64_t detritus_matter{};
|
||||
std::uint64_t births{};
|
||||
std::uint64_t deaths{};
|
||||
std::uint64_t capacity{rule::capacity};
|
||||
|
||||
[[nodiscard]] Census census() const {
|
||||
Census now;
|
||||
@@ -298,6 +330,11 @@ struct AggregateRun {
|
||||
}
|
||||
for (auto& age : classes) {
|
||||
const auto wanted = share * age.count;
|
||||
// The same bound, and the same reason for checking it: a shared store
|
||||
// that ran out would make intake depend on the order classes are
|
||||
// visited in, which is not a resolution effect.
|
||||
check(environment >= wanted);
|
||||
check(matter_store >= rule::matter_intake * age.count);
|
||||
const auto taken = std::min(wanted, environment);
|
||||
environment -= taken;
|
||||
age.energy += taken;
|
||||
@@ -330,8 +367,11 @@ struct AggregateRun {
|
||||
std::uint64_t newborns = 0;
|
||||
std::uint64_t taken_energy = 0;
|
||||
std::uint64_t taken_matter = 0;
|
||||
for (auto& age : classes) {
|
||||
if (age.count == 0 || population + newborns >= rule::capacity) {
|
||||
// Oldest class first, which is the same allocation rule the individual run
|
||||
// follows. The classes are held youngest-first, so this walks them in
|
||||
// reverse rather than relying on the storage order.
|
||||
for (auto& age : std::ranges::reverse_view(classes)) {
|
||||
if (age.count == 0 || population + newborns >= capacity) {
|
||||
continue;
|
||||
}
|
||||
const auto average_energy = age.energy / age.count;
|
||||
@@ -343,8 +383,8 @@ struct AggregateRun {
|
||||
continue;
|
||||
}
|
||||
auto breeding = age.count;
|
||||
if (population + newborns + breeding > rule::capacity) {
|
||||
breeding = rule::capacity - population - newborns;
|
||||
if (population + newborns + breeding > capacity) {
|
||||
breeding = capacity - population - newborns;
|
||||
}
|
||||
const auto energy_moved = rule::investment_energy * breeding;
|
||||
const auto matter_moved = rule::investment_matter * breeding;
|
||||
@@ -438,6 +478,59 @@ AggregateRun founding_classes(const IndividualRun& source, std::uint64_t width)
|
||||
return Cohort::create(std::move(probe)).has_value();
|
||||
}
|
||||
|
||||
// Every living member as (age, energy, matter), sorted. Comparing censuses is not
|
||||
// enough to establish that the two runs allocate contested breeding slots to the
|
||||
// same parents: whoever breeds hands the same investment to a child either way, so
|
||||
// the totals agree while the distribution does not, and the disagreement only
|
||||
// reaches a census many ticks later. The control therefore compares distributions.
|
||||
using Portrait = std::vector<std::array<std::uint64_t, 3>>;
|
||||
|
||||
[[nodiscard]] Portrait portrait(const IndividualRun& run) {
|
||||
Portrait rows;
|
||||
for (const auto& member : run.members) {
|
||||
if (member.alive) {
|
||||
rows.push_back({member.age, member.energy, member.matter});
|
||||
}
|
||||
}
|
||||
std::ranges::sort(rows);
|
||||
return rows;
|
||||
}
|
||||
// Only meaningful at width one, where a class holds members of a single age. A
|
||||
// class may still hold several of them, because several can be born in one tick, so
|
||||
// each is expanded into its equal share; the division has to be exact or the
|
||||
// expansion would not be the distribution it claims to be, and that is checked
|
||||
// rather than assumed.
|
||||
[[nodiscard]] Portrait portrait(const AggregateRun& run) {
|
||||
Portrait rows;
|
||||
for (const auto& age : run.classes) {
|
||||
check(age.count > 0);
|
||||
check(age.energy % age.count == 0);
|
||||
check(age.matter % age.count == 0);
|
||||
for (std::uint64_t index = 0; index < age.count; ++index) {
|
||||
rows.push_back({age.age_low, age.energy / age.count, age.matter / age.count});
|
||||
}
|
||||
}
|
||||
std::ranges::sort(rows);
|
||||
return rows;
|
||||
}
|
||||
|
||||
// Ages ascend with the index, so the oldest member is the last inserted and the
|
||||
// youngest class is the first stored. Oldest-first therefore disagrees with both of
|
||||
// the orders this fixture could have drifted into: allocating in insertion order
|
||||
// would pick the first member, and walking the classes as stored would pick the
|
||||
// youngest class. Each of those, introduced alone, makes the two runs choose
|
||||
// different parents, which is what the control has to be able to see.
|
||||
IndividualRun founding_contested(std::uint64_t count, std::uint64_t capacity) {
|
||||
IndividualRun run;
|
||||
for (std::uint64_t index = 0; index < count; ++index) {
|
||||
run.members.push_back({rule::maturity + index, 100 + index, 60 + index, true});
|
||||
}
|
||||
run.environment = 100'000'000;
|
||||
run.matter_store = 100'000'000;
|
||||
run.capacity = capacity;
|
||||
return run;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The instrument check. With one member per class a class average is that member,
|
||||
// so the two runs must agree exactly. Without this a measured divergence could be
|
||||
@@ -462,12 +555,64 @@ void one_member_per_class_agrees_exactly() {
|
||||
CHECK(individual.total_matter() == aggregate.total_matter());
|
||||
CHECK(aggregate.classes.size() <= max_age_classes);
|
||||
CHECK(representable(aggregate));
|
||||
// Distributions, not just totals: a census agrees even when the two runs
|
||||
// have given the same investment to different parents.
|
||||
CHECK(portrait(individual) == portrait(aggregate));
|
||||
}
|
||||
// The control has to have exercised something, or it proves nothing.
|
||||
CHECK(individual.census().births > 0);
|
||||
CHECK(individual.census().living > 20);
|
||||
}
|
||||
|
||||
// The capacity boundary, which the control above never reaches. With fewer free
|
||||
// slots than eligible parents the allocation order decides which parents reproduce,
|
||||
// and that is an implementation choice rather than a consequence of resolution: if
|
||||
// the two runs order differently, the published divergence cannot be attributed to
|
||||
// averaging at all. One member per class again, so the two must agree exactly, and
|
||||
// distributions rather than censuses because a different parent breeding leaves
|
||||
// every total unchanged.
|
||||
void contested_breeding_slots_go_to_the_same_parents() {
|
||||
constexpr std::uint64_t count = 12;
|
||||
auto individual = founding_contested(count, count + 1);
|
||||
auto aggregate = founding_classes(individual, 1);
|
||||
aggregate.capacity = individual.capacity;
|
||||
CHECK(aggregate.classes.size() == count);
|
||||
CHECK(portrait(individual) == portrait(aggregate));
|
||||
bool contested = false;
|
||||
for (std::uint64_t tick = 0; tick < 40; ++tick) {
|
||||
// Before the step, count how many parents are eligible against how many
|
||||
// slots are free, so the test can prove it actually reached the boundary.
|
||||
std::uint64_t living = 0;
|
||||
std::uint64_t eligible = 0;
|
||||
for (const auto& member : individual.members) {
|
||||
if (!member.alive) {
|
||||
continue;
|
||||
}
|
||||
++living;
|
||||
if (rule::breeds(member.age + 1, member.energy) &&
|
||||
member.matter >= rule::investment_matter) {
|
||||
++eligible;
|
||||
}
|
||||
}
|
||||
const auto free_slots = individual.capacity > living ? individual.capacity - living : 0;
|
||||
if (eligible > free_slots && free_slots > 0) {
|
||||
contested = true;
|
||||
}
|
||||
individual.step();
|
||||
aggregate.step();
|
||||
CHECK(portrait(individual) == portrait(aggregate));
|
||||
CHECK(individual.census() == aggregate.census());
|
||||
CHECK(individual.total_energy() == aggregate.total_energy());
|
||||
CHECK(individual.total_matter() == aggregate.total_matter());
|
||||
CHECK(representable(aggregate));
|
||||
}
|
||||
// The boundary has to have been reached, or this control proves nothing about
|
||||
// allocation and is just the first control again with fewer members.
|
||||
CHECK(contested);
|
||||
CHECK(individual.census().births > 0);
|
||||
CHECK(individual.census().living == individual.capacity);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The scenario ECOLOGY_MODEL asks for, through the real conversions.
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -740,6 +885,7 @@ void the_full_scenario_conserves_and_keeps_its_genome() {
|
||||
int main() try {
|
||||
// The instrument check runs first: a failing control voids every number below.
|
||||
one_member_per_class_agrees_exactly();
|
||||
contested_breeding_slots_go_to_the_same_parents();
|
||||
aggregation_costs_something_and_coarse_classes_destroy_the_population();
|
||||
the_full_scenario_conserves_and_keeps_its_genome();
|
||||
std::cout << "PASS resolution comparison, exact control and a published envelope\n";
|
||||
|
||||
Reference in New Issue
Block a user