Derive a phenotype from the genome without touching it
M3.2 adds derive_phenotype and plan_development as pure integer functions of a genome, a growth state and an environment. Nothing is stored: a phenotype is recomputed from retained inputs rather than cached, so a cached copy can always be checked against a recomputation. The risk this increment was scoped against is confusing the genome with runtime damage. Growth and damage live in a separate state that no function may write back, and no entry point takes a mutable genome. Damage changes the phenotype and leaves the encoded bytes and content digest identical, so heredity cannot carry acquired condition. The genome's development version selects a rule set, which is what makes that field worth carrying; an unknown version fails closed rather than deriving under the wrong rules. Version 1 declares every constant. The shape model is explicit rather than implied: the body is a cube of uniform declared density, so extent is an exact integer cube root and surface is six extents squared. Membrane mass follows surface and the genome's thickness, maintenance follows total mass plus a membrane upkeep term, and uptake scales with surface, so size trades uptake against maintenance. A capability the genome does not carry yields zero. A plan advances growth by at most the rule step, reduced to the largest step the available material funds exactly, never a partial one and never a grant. It reserves nothing and pays for nothing: the matching transfer does not exist until M3.3, and an apply that moved no inventory would look like a committed operation while conserving nothing. The fixture genome is an exact 20 micrometre cube, so every derived value is asserted as a hand-calculated literal, as are the half-built, damaged, maximum and cube-root-boundary cases. Determinism is checked over 45 growth and temperature combinations. The declared flooring is pinned rather than hidden: a body whose mass floors to zero advances its counter for no material, granting no structure because none exists either way. Omitted physics is a documented model limitation, not a modifier. Nothing here is balance, and no organism yet develops. Native Release, clang-tidy analysis, ASan and format checks pass 18/18; every existing golden and fingerprint is unchanged. Linux CI has not run yet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/biology/genome.hpp"
|
||||
|
||||
namespace evo::biology {
|
||||
// What an organism has actually built and lost. Runtime state, never written
|
||||
// back into the genome: heredity must not carry acquired condition.
|
||||
struct GrowthState {
|
||||
std::uint32_t realized_per_thousand{};
|
||||
std::uint32_t damage_per_thousand{};
|
||||
auto operator<=>(const GrowthState&) const = default;
|
||||
};
|
||||
struct EnvironmentState {
|
||||
std::uint32_t temperature_millikelvin{};
|
||||
// Bounds what a plan can fund. Nothing here is spent or reserved.
|
||||
std::uint64_t available_material{};
|
||||
auto operator<=>(const EnvironmentState&) const = default;
|
||||
};
|
||||
// Chosen constants, reviewable as a unit and selected by the genome's
|
||||
// development version. Declared model parameters, not balance.
|
||||
struct DevelopmentRules {
|
||||
std::uint64_t structure_density; // femtograms per cubic micrometre
|
||||
std::uint64_t membrane_density; // femtograms per cubic micrometre
|
||||
std::uint64_t maintenance_per_kilogram; // picojoules per tick per 1000 fg
|
||||
std::uint64_t membrane_upkeep_per_kilo; // picojoules per tick per 1000 fg
|
||||
std::uint64_t construction_per_kilogram; // picojoules per 1000 fg built
|
||||
std::uint64_t reference_surface; // square micrometres
|
||||
std::uint32_t reference_temperature; // millikelvin
|
||||
std::uint32_t growth_step_per_thousand; // most one plan may advance
|
||||
};
|
||||
// Dimensioned parameters derived from a genome and its runtime state. A derived
|
||||
// phenotype is not a viability claim and holds no fitness score.
|
||||
struct Phenotype {
|
||||
std::uint64_t structural_mass{}; // femtograms
|
||||
std::uint64_t membrane_mass{}; // femtograms
|
||||
std::uint64_t total_mass{}; // femtograms
|
||||
std::uint32_t extent{}; // micrometres, the cube-model side length
|
||||
std::uint64_t surface{}; // square micrometres
|
||||
std::uint64_t maintenance{}; // picojoules per tick
|
||||
std::uint32_t movement_speed{}; // micrometres per tick; zero without the capability
|
||||
std::uint64_t ingestion_rate{}; // femtograms per tick; zero without the capability
|
||||
std::uint32_t conversion_per_thousand{};
|
||||
// Millikelvin beyond the genome's tolerance. A reported quantity, not a rule.
|
||||
std::uint32_t thermal_shortfall{};
|
||||
auto operator<=>(const Phenotype&) const = default;
|
||||
};
|
||||
// A proposal. It reserves nothing, pays for nothing and commits nothing; the
|
||||
// matching transfer does not exist until M3.3.
|
||||
struct DevelopmentPlan {
|
||||
GrowthState after{};
|
||||
std::uint64_t material_required{};
|
||||
std::uint64_t energy_required{};
|
||||
auto operator<=>(const DevelopmentPlan&) const = default;
|
||||
};
|
||||
enum class DevelopmentError : std::uint8_t { unsupported_rules, invalid_growth, overflow };
|
||||
|
||||
[[nodiscard]] std::expected<DevelopmentRules, DevelopmentError>
|
||||
rules_for(std::uint32_t development_version);
|
||||
// Pure: a phenotype is recomputed from retained inputs rather than cached, so a
|
||||
// cached copy can always be checked against a recomputation.
|
||||
[[nodiscard]] std::expected<Phenotype, DevelopmentError>
|
||||
derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState environment);
|
||||
// Advances realized growth toward the target by at most the rule step, reduced to
|
||||
// the largest step the available material funds exactly. Never repairs damage.
|
||||
[[nodiscard]] std::expected<DevelopmentPlan, DevelopmentError>
|
||||
plan_development(const Genome& genome, GrowthState growth, EnvironmentState environment);
|
||||
} // namespace evo::biology
|
||||
Reference in New Issue
Block a user