babylon.formulas

Mathematical formulas for the Babylon simulation.

This module contains the pure mathematical functions that drive the dialectical mechanics of the simulation. These are deterministic functions with no side effects - the same inputs always produce the same outputs.

Key Formulas: 1. Fundamental Theorem of MLM-TW:

  • Imperial Rent: Phi(Wp, Psip) = alpha * Wp * (1 - Psip)

  • Labor Aristocracy: Wc/Vc > 1

  • Consciousness Drift: dPsic/dt = k(1 - Wc/Vc) - lambda*Psic

  1. Survival Calculus: - Acquiescence: P(S|A) = 1 / (1 + e^(-k(x - x_critical))) - Revolution: P(S|R) = Cohesion / (Repression + epsilon) - Loss Aversion: lambda = 2.25

  2. Unequal Exchange: - Exchange Ratio: epsilon = (Lp/Lc) * (Wc/Wp) - Prebisch-Singer Effect

babylon.formulas.calculate_labor_aristocracy_ratio(core_wages, value_produced)[source]

Wc/Vc ratio. When > 1, worker receives more than produced.

Parameters:
  • core_wages (float) – Wages received.

  • value_produced (float) – Value produced.

Return type:

float

Returns:

Labor aristocracy ratio.

Raises:

ValueError – If value_produced <= 0.

Examples

>>> calculate_labor_aristocracy_ratio(120.0, 100.0)
1.2
babylon.formulas.is_labor_aristocracy(core_wages, value_produced)[source]

True if Wc/Vc > 1 (receives more than produces).

Parameters:
  • core_wages (float) – Wages received.

  • value_produced (float) – Value produced.

Return type:

bool

Returns:

True if labor aristocracy.

Raises:

ValueError – If value_produced <= 0.

Examples

>>> is_labor_aristocracy(120.0, 100.0)
True
>>> is_labor_aristocracy(80.0, 100.0)
False
babylon.formulas.calculate_consciousness_drift(core_wages, value_produced, current_consciousness, sensitivity_k, decay_lambda, solidarity_pressure=0.0, wage_change=0.0)[source]

dPsi/dt = k(1 - Wc/Vc) - lambda*Psi + bifurcation.

Parameters:
  • core_wages (float) – Wages received.

  • value_produced (float) – Value produced.

  • current_consciousness (float) – Current level [0, 1].

  • sensitivity_k (float) – Material conditions sensitivity.

  • decay_lambda (float) – Consciousness decay rate.

  • solidarity_pressure (float) – Incoming SOLIDARITY strength.

  • wage_change (float) – Wage delta (negative = crisis).

Return type:

float

Returns:

Consciousness drift rate (positive = revolutionary).

Raises:

ValueError – If value_produced <= 0.

babylon.formulas.calculate_acquiescence_probability(wealth, subsistence_threshold, steepness_k)[source]

P(S|A) sigmoid. At threshold, probability = 0.5.

Parameters:
  • wealth (float) – Current wealth/resources.

  • subsistence_threshold (float) – Minimum for survival (x_critical).

  • steepness_k (float) – Curve steepness.

Return type:

float

Returns:

Survival probability via acquiescence, in [0, 1]. The sigmoid is mathematically bounded by construction.

Examples

>>> calculate_acquiescence_probability(100.0, 100.0, 0.1)
0.5
babylon.formulas.calculate_revolution_probability(cohesion, repression)[source]

P(S|R) = Cohesion / (Repression + eps). Capped at 1.0.

Parameters:
  • cohesion (float) – Organization level [0, 1].

  • repression (float) – State violence capacity [0, 1].

Return type:

float

Returns:

Survival probability via revolution, in [0, 1]. Bounded below by the early-return for non-positive cohesion and above by min(1.0, ...).

Examples

>>> calculate_revolution_probability(0.8, 0.2)
1.0
>>> calculate_revolution_probability(0.0, 0.5)
0.0
babylon.formulas.calculate_crossover_threshold(cohesion, repression, subsistence_threshold, steepness_k)[source]

Wealth level where P(S|R) = P(S|A) (revolution becomes rational).

Parameters:
  • cohesion (float) – Organization level.

  • repression (float) – State violence capacity.

  • subsistence_threshold (float) – Acquiescence threshold.

  • steepness_k (float) – Acquiescence curve steepness.

Return type:

float

Returns:

Crossover wealth level [0, 1].

babylon.formulas.apply_loss_aversion(value)[source]

Amplify losses by 2.25x (Kahneman-Tversky).

Parameters:

value (float) – Raw value change (negative = loss).

Return type:

float

Returns:

Perceived value (losses amplified).

Examples

>>> apply_loss_aversion(100.0)
100.0
>>> apply_loss_aversion(-100.0)
-225.0
babylon.formulas.calculate_exchange_ratio(periphery_labor_hours, core_labor_hours, core_wage, periphery_wage)[source]

Calculate exchange ratio: epsilon = (Lp/Lc) * (Wc/Wp).

The exchange ratio quantifies unequal exchange. When epsilon > 1, the periphery gives more value than it receives.

Parameters:
  • periphery_labor_hours (float) – Labor hours in periphery

  • core_labor_hours (float) – Labor hours in core for same product

  • core_wage (float) – Core wage rate

  • periphery_wage (float) – Periphery wage rate

Return type:

float

Returns:

Exchange ratio

Raises:

ValueError – If any denominator value is zero or negative

Examples

>>> calculate_exchange_ratio(100.0, 100.0, 20.0, 5.0)  # Equal labor, 4x wage gap
4.0
>>> calculate_exchange_ratio(200.0, 100.0, 20.0, 10.0)  # 2x labor, 2x wage
4.0
>>> calculate_exchange_ratio(100.0, 100.0, 10.0, 10.0)  # Fair exchange
1.0
babylon.formulas.calculate_unequal_exchange_rate(exchange_ratio)[source]

Convert exchange ratio to exploitation rate percentage.

epsilon = 2 means 100% exploitation (double value extracted). epsilon = 1 means 0% exploitation (fair exchange).

Parameters:

exchange_ratio (float) – The exchange ratio epsilon

Return type:

float

Returns:

Exploitation rate as a percentage

babylon.formulas.calculate_value_transfer(production_value, exchange_ratio)[source]

Calculate value transferred from periphery to core.

Value transfer = production * (1 - 1/epsilon)

Parameters:
  • production_value (float) – Value of peripheral production

  • exchange_ratio (float) – The exchange ratio epsilon

Return type:

float

Returns:

Value transferred to core

babylon.formulas.prebisch_singer_effect(initial_price, production_increase, elasticity)[source]

Calculate Prebisch-Singer effect on commodity prices.

Terms of trade decline for commodity exporters: More production -> lower prices -> same poverty.

Parameters:
  • initial_price (float) – Initial commodity price

  • production_increase (float) – Fractional increase in production (0.2 = 20%)

  • elasticity (float) – Price elasticity of demand (typically negative)

Return type:

float

Returns:

New price after production increase

babylon.formulas.calculate_solidarity_transmission(source_consciousness, target_consciousness, solidarity_strength, activation_threshold=0.3)[source]

Calculate consciousness delta via solidarity edge.

Parameters:
  • source_consciousness (float) – Source consciousness level [0, 1].

  • target_consciousness (float) – Target consciousness level [0, 1].

  • solidarity_strength (float) – Edge strength [0, 1].

  • activation_threshold (float) – Minimum source level for transmission.

Return type:

float

Returns:

Change in target consciousness. Negative if target > source.

Examples

>>> round(calculate_solidarity_transmission(0.8, 0.2, 0.5), 2)
0.3
>>> calculate_solidarity_transmission(0.2, 0.5, 0.5)  # Below threshold
0.0
babylon.formulas.compute_agitation_delta(exploitation_rate_delta, imperial_rent_delta, visibility_delta, defines=None)[source]

Convert value tensor changes into agitation increment.

Agitation is generated by three sources of material crisis:

  1. Rising exploitation rate (Δ(s/v) > 0): Workers produce more surplus relative to wages.

  2. Declining imperial rent (ΔΦ < 0): Core workers losing their bribe from unequal exchange.

  3. Increasing reproductive visibility (Δg₃₃ > 0): Previously invisible care work becoming monetized/contested.

Formula:

Δagitation = max(0, Δ(s/v)) × α_e
           + max(0, -ΔΦ) × α_r
           + max(0, Δg₃₃) × α_v
Parameters:
  • exploitation_rate_delta (float) – Change in s/v since last tick.

  • imperial_rent_delta (float) – Change in Φ since last tick (negative = crisis).

  • visibility_delta (float) – Change in g₃₃ since last tick.

  • defines (ConsciousnessDefines | None) – Optional custom coefficients.

Return type:

float

Returns:

Non-negative agitation increment.

babylon.formulas.compute_exploitation_visibility(exploitation_rate, imperial_rent, defines=None)[source]

Determine how visible exploitation is to a population.

Imperial rent acts as an opacity filter on exploitation: when workers receive a “bribe” via unequal exchange with the periphery, the exploitation that does exist becomes obscured by material comfort.

Formula:

visibility = s/v / (s/v + Φ × opacity + ε)

When Φ = 0 (periphery), visibility approaches 1.0 for high s/v. When Φ > 0 (core), visibility is dampened.

Parameters:
  • exploitation_rate (float) – Current s/v ratio for this population.

  • imperial_rent (float) – Current Φ (positive = core, negative = periphery).

  • defines (ConsciousnessDefines | None) – Optional custom coefficients.

Return type:

float

Returns:

Exploitation visibility in [0, 1].

babylon.formulas.compute_reification_buffer(imperial_rent, total_v)[source]

Measure commodity fetishism from imperial rent.

The reification buffer represents how much the commodity form obscures underlying class relations. Higher imperial rent means core workers experience class relations as “natural” rather than exploitative — the bribe makes the system appear to work.

Formula:

reification = |Φ| / (|Φ| + v + ε)
Parameters:
  • imperial_rent (float) – Current Φ (positive or negative).

  • total_v (float) – Total variable capital in the local economy.

  • defines – Optional custom coefficients.

Return type:

float

Returns:

Reification buffer in [0, 1].

babylon.formulas.route_agitation_to_ternary(agitation, solidarity_factor, education_pressure, defines=None)[source]

Route accumulated agitation into ternary consciousness shifts.

Agitation is consumed and routed to (Δr, Δl, Δf) based on:

  1. Solidarity determines the revolutionary vs fascist split. With solidarity, agitation routes to r (class consciousness). Without solidarity, agitation routes to f (fascism).

  2. Education pressure biases the split toward revolutionary. This is the mechanized effect of the EDUCATE verb.

  3. Liberal drain absorbs a fraction as liberal drift.

Formula:

consumed = agitation × consumption_rate
effective_solidarity = min(1.0, solidarity + education_pressure)
Δr = consumed × effective_solidarity × routing_scale
Δf = consumed × (1 - effective_solidarity) × routing_scale
Δl = -(Δr + Δf) × liberal_backpressure
Parameters:
  • agitation (float) – Accumulated agitation on this node [0, ∞).

  • solidarity_factor (float) – Incoming SOLIDARITY edge strength [0, 1].

  • education_pressure (float) – Education pressure on community [0, 1].

  • defines (ConsciousnessDefines | None) – Optional custom coefficients.

Return type:

tuple[float, float, float]

Returns:

Tuple of (Δr, Δl, Δf) — directional shifts in ternary space. Δl is typically negative (agitation drains liberal tendency).

babylon.formulas.normalize_to_simplex(r, lib, f)[source]

Project (r, l, f) onto the probability simplex (r + l + f = 1).

The simplex constraint ensures consciousness is a valid probability distribution. Values below zero are clamped. If the sum is below 1, the remainder is assigned to liberal (hegemonic default). If above 1, values are scaled proportionally.

Parameters:
  • r (float) – Revolutionary tendency [may be any float].

  • lib (float) – Liberal tendency [may be any float].

  • f (float) – Fascist tendency [may be any float].

Return type:

tuple[float, float, float]

Returns:

Tuple of (r, lib, f) satisfying r + lib + f ≈ 1.0, all >= 0.

class babylon.formulas.BourgeoisieDecision[source]

Bases: object

Enumeration of bourgeoisie decision types.

Sprint 3.4.4: Dynamic Balance - The “Driver” decisions based on imperial rent pool level and aggregate class tension.

NO_CHANGE = 'no_change'
BRIBERY = 'bribery'
AUSTERITY = 'austerity'
IRON_FIST = 'iron_fist'
CRISIS = 'crisis'
babylon.formulas.calculate_bourgeoisie_decision(pool_ratio, aggregate_tension, high_threshold=0.7, low_threshold=0.3, critical_threshold=0.1, bribery_wage_delta=0.05, austerity_wage_delta=-0.05, iron_fist_repression_delta=0.10, crisis_wage_delta=-0.15, crisis_repression_delta=0.20, bribery_tension_threshold=0.3, iron_fist_tension_threshold=0.5)[source]

Calculate bourgeoisie policy decision based on pool level and tension.

Sprint 3.4.4: Dynamic Balance - The bourgeoisie as a rational actor responding to material conditions.

Decision Matrix:

pool_ratio >= high AND tension < bribery_tension -> BRIBERY pool_ratio < critical -> CRISIS (emergency measures) pool_ratio < low AND tension > iron_fist_tension -> IRON_FIST pool_ratio < low AND tension <= iron_fist_tension -> AUSTERITY else -> NO_CHANGE (maintain status quo)

Parameters:
  • pool_ratio (float) – Current pool / initial pool (0.0 to 1.0+)

  • aggregate_tension (float) – Average tension across class relationships (0.0 to 1.0)

  • high_threshold (float) – Pool ratio above which prosperity is declared (default 0.7)

  • low_threshold (float) – Pool ratio below which austerity begins (default 0.3)

  • critical_threshold (float) – Pool ratio below which crisis fires (default 0.1)

  • bribery_wage_delta (float) – Wage increase during prosperity (default 0.05)

  • austerity_wage_delta (float) – Wage cut during austerity (default -0.05)

  • iron_fist_repression_delta (float) – Repression increase during iron fist (default 0.10)

  • crisis_wage_delta (float) – Emergency wage cut during crisis (default -0.15)

  • crisis_repression_delta (float) – Emergency repression spike (default 0.20)

  • bribery_tension_threshold (float) – Max tension for bribery policy (default 0.3)

  • iron_fist_tension_threshold (float) – Min tension for iron fist policy (default 0.5)

Returns:

str, wage_delta: float, repression_delta: float) - decision: One of BourgeoisieDecision values - wage_delta: Change to wage rate (positive = increase) - repression_delta: Change to repression level (positive = increase)

Return type:

tuple[str, float, float]

Example

# Prosperity: high pool, low tension -> increase wages decision, wage_d, repr_d = calculate_bourgeoisie_decision(0.8, 0.2) # Returns (“bribery”, 0.05, 0.0)

# Crisis: pool below critical -> emergency measures decision, wage_d, repr_d = calculate_bourgeoisie_decision(0.05, 0.5) # Returns (“crisis”, -0.15, 0.20)

babylon.formulas.calculate_biocapacity_delta(regeneration_rate, max_biocapacity, extraction_intensity, current_biocapacity, entropy_factor=1.2)[source]

Calculate change in biocapacity stock: dB = R - (E * eta).

The core metabolic formula. Extraction always costs more than the raw value obtained due to entropy/waste (eta > 1.0).

Parameters:
  • regeneration_rate (float) – Fraction of max_biocapacity restored per tick [0, 1]

  • max_biocapacity (float) – Maximum biocapacity ceiling

  • extraction_intensity (float) – Current extraction pressure [0, 1]

  • current_biocapacity (float) – Current biocapacity stock

  • entropy_factor (float) – Waste multiplier for extraction (default 1.2)

Return type:

float

Returns:

Change in biocapacity (positive = regeneration, negative = depletion)

Examples

>>> calculate_biocapacity_delta(0.02, 100.0, 0.0, 50.0)  # No extraction
2.0
>>> calculate_biocapacity_delta(0.02, 100.0, 0.05, 50.0)  # Light extraction
-1.0
>>> calculate_biocapacity_delta(0.02, 100.0, 0.0, 100.0)  # At max, no regen
0.0
babylon.formulas.calculate_overshoot_ratio(total_consumption, total_biocapacity, max_ratio=999.0)[source]

Calculate ecological overshoot ratio: O = C / B.

When O > 1.0, consumption exceeds biocapacity (overshoot). When O <= 1.0, the system is within ecological limits.

Parameters:
  • total_consumption (float) – Total consumption needs across all entities

  • total_biocapacity (float) – Total available biocapacity

  • max_ratio (float) – Cap for ratio when biocapacity depleted (default 999.0)

Return type:

float

Returns:

Overshoot ratio (>1.0 = ecological overshoot)

Examples

>>> calculate_overshoot_ratio(100.0, 200.0)  # Sustainable
0.5
>>> calculate_overshoot_ratio(200.0, 100.0)  # Overshoot
2.0
>>> calculate_overshoot_ratio(100.0, 0.0)  # Depleted biocapacity
999.0
babylon.formulas.calculate_rent_pool_decay(current_pool, decay_rate)[source]

Apply TRPF rent pool decay (background evaporation).

Models the tendency of accumulated surplus to erode over time, representing the contradiction between the tendency to accumulate and the tendency of profit rates to fall.

Parameters:
  • current_pool (float) – Current imperial rent pool value

  • decay_rate (float) – Per-tick decay rate (default 0.002 = 0.2%)

Return type:

float

Returns:

Decayed pool value (always >= 0)

Example

>>> calculate_rent_pool_decay(100.0, 0.002)
99.8
>>> calculate_rent_pool_decay(100.0, 0.0)
100.0

Note

At default decay 0.002: - After 52 ticks (1 year): ~90% remaining - After 520 ticks (10 years): ~35% remaining - After 1040 ticks (20 years): ~12% remaining

babylon.formulas.calculate_trpf_multiplier(tick, trpf_coefficient, floor=0.1)[source]

Calculate TRPF efficiency multiplier (Epoch 1 Surrogate).

Models Marx’s Tendency of the Rate of Profit to Fall as a time-dependent decay of extraction efficiency. This is a surrogate for proper organic composition tracking.

The multiplier declines linearly from 1.0 at tick 0, representing how rising organic composition of capital reduces profit rates over time under capitalist accumulation.

Parameters:
  • tick (int) – Current simulation tick (0-indexed)

  • trpf_coefficient (float) – Decay rate per tick (default 0.0005)

  • floor (float) – Minimum multiplier (default 0.1 = 10% efficiency floor)

Return type:

float

Returns:

Multiplier in range [floor, 1.0]

Example

>>> calculate_trpf_multiplier(0, 0.0005)
1.0
>>> calculate_trpf_multiplier(1000, 0.0005)
0.5
>>> calculate_trpf_multiplier(2000, 0.0005)
0.1

Note

At default coefficient 0.0005: - tick 0: 100% efficiency - tick 520 (10 years): 74% efficiency - tick 1040 (20 years): 48% efficiency - tick 1800+: floors at 10% efficiency

Full OCC-based TRPF calculation planned for Epoch 2. See ai/epoch2-trpf.yaml for specification.

Theoretical Basis:

Marx, Capital Vol. 3, Chapters 13-15: Rate of Profit p’ = s / (c + v) As OCC (c/v) rises, p’ falls even with constant exploitation rate (s/v).

babylon.formulas.calculate_mortality_rate(wealth_per_capita, subsistence_needs, inequality, attrition_base_factor=_DEFINES.vitality.attrition_base_factor)[source]

Calculate mortality rate using coverage_ratio threshold.

The formula ensures that with high inequality (e.g., 0.8), you need almost 2x subsistence (1.8 coverage) to prevent deaths.

Parameters:
  • wealth_per_capita (float) – Total wealth / population.

  • subsistence_needs (float) – Per-capita subsistence requirement (s_bio + s_class).

  • inequality (float) – Gini coefficient [0, 1].

  • attrition_base_factor (float)

Return type:

float

Returns:

Attrition rate [0, 1] representing fraction of population that dies.

class babylon.formulas.ClassDynamicsParams(alpha_41=0.0, alpha_31=0.0, alpha_21=0.0006, alpha_32=0.0, alpha_42=0.0, alpha_43=0.0, delta_1=0.001, delta_2=0.002, delta_3=0.001, gamma_3=0.0057)[source]

Bases: object

Parameters for class wealth dynamics ODE system.

All rates are per-tick (convert from quarterly by dividing by ticks_per_quarter).

Parameters:
alpha_41

Extraction rate from proletariat to bourgeoisie.

alpha_31

Extraction rate from labor aristocracy to bourgeoisie.

alpha_21

Extraction rate from petty bourgeoisie to bourgeoisie.

alpha_32

Rent-seeking from labor aristocracy to petty bourgeoisie.

alpha_42

Extraction from proletariat to petty bourgeoisie.

alpha_43

Extraction from proletariat to labor aristocracy.

delta_1

Redistribution rate from bourgeoisie (taxation).

delta_2

Redistribution rate from petty bourgeoisie.

delta_3

Redistribution rate from labor aristocracy.

gamma_3

Imperial rent formation rate (superwages).

Examples

>>> params = ClassDynamicsParams()
>>> params.gamma_3
0.0057
alpha_41: float = 0.0
alpha_31: float = 0.0
alpha_21: float = 0.0006
alpha_32: float = 0.0
alpha_42: float = 0.0
alpha_43: float = 0.0
delta_1: float = 0.001
delta_2: float = 0.002
delta_3: float = 0.001
gamma_3: float = 0.0057
__init__(alpha_41=0.0, alpha_31=0.0, alpha_21=0.0006, alpha_32=0.0, alpha_42=0.0, alpha_43=0.0, delta_1=0.001, delta_2=0.002, delta_3=0.001, gamma_3=0.0057)
Parameters:
Return type:

None

class babylon.formulas.SecondOrderParams(beta=(-0.1, -0.15, -0.1, -0.05), omega=(0.05, 0.08, 0.05, 0.03), equilibrium=(0.305, 0.382, 0.294, 0.02))[source]

Bases: object

Second-order dynamics parameters for momentum effects.

Parameters:
beta

Damping coefficients (negative = mean-reverting).

omega

Natural frequencies of oscillation.

equilibrium

Attractor wealth shares (W*).

Examples

>>> params = SecondOrderParams()
>>> params.equilibrium
(0.305, 0.382, 0.294, 0.02)
beta: tuple[float, float, float, float] = (-0.1, -0.15, -0.1, -0.05)
omega: tuple[float, float, float, float] = (0.05, 0.08, 0.05, 0.03)
equilibrium: tuple[float, float, float, float] = (0.305, 0.382, 0.294, 0.02)
__init__(beta=(-0.1, -0.15, -0.1, -0.05), omega=(0.05, 0.08, 0.05, 0.03), equilibrium=(0.305, 0.382, 0.294, 0.02))
Parameters:
Return type:

None

babylon.formulas.calculate_class_dynamics_derivative(wealth_shares, params=None, resistances=(0.0, 0.0, 0.0, 0.0))[source]

Compute dW/dt for all four classes (first-order system).

Implements:

dW₁/dt = α₄₁W₄ + α₃₁W₃ + α₂₁W₂ - δ₁W₁ dW₂/dt = α₃₂W₃ + α₄₂W₄ - α₂₁W₂ - δ₂W₂ dW₃/dt = α₄₃W₄ + γ₃ - α₃₁W₃ - α₃₂W₃ - δ₃W₃ dW₄/dt = -(dW₁ + dW₂ + dW₃)

Parameters:
Return type:

tuple[float, float, float, float]

Returns:

(dW₁/dt, dW₂/dt, dW₃/dt, dW₄/dt) derivatives.

Examples

>>> shares = (0.30, 0.36, 0.30, 0.04)
>>> dW = calculate_class_dynamics_derivative(shares)
>>> abs(sum(dW)) < 1e-10  # Sum constraint
True
babylon.formulas.calculate_equilibrium_deviation(wealth_shares, equilibrium=None)[source]

Calculate total deviation from equilibrium wealth distribution.

Useful for detecting when the system is far from steady state.

Parameters:
Return type:

float

Returns:

Sum of squared deviations from equilibrium.

Examples

>>> result = calculate_equilibrium_deviation((0.30, 0.38, 0.29, 0.03))
>>> 0.0001 < result < 0.0003
True
babylon.formulas.calculate_full_dynamics(wealth_shares, velocities, params=None, second_order=None, resistances=(0.0, 0.0, 0.0, 0.0))[source]

Compute both first and second order derivatives.

Combines first-order wealth flows with second-order momentum dynamics.

Parameters:
Return type:

tuple[tuple[float, float, float, float], tuple[float, float, float, float]]

Returns:

Tuple of (first_derivatives, second_derivatives).

Examples

>>> shares = (0.305, 0.382, 0.294, 0.020)
>>> vels = (0.0, -0.001, 0.0006, 0.0004)
>>> dW, d2W = calculate_full_dynamics(shares, vels)
babylon.formulas.calculate_wealth_acceleration(wealth_share, velocity, equilibrium, damping=-0.1, frequency=0.05)[source]

Compute d²W/dt² for second-order dynamics.

Models momentum effects and oscillation around equilibrium:

d²W/dt² = β(dW/dt) - ω²(W - W*)

Parameters:
  • wealth_share (float) – Current wealth share W.

  • velocity (float) – First derivative dW/dt.

  • equilibrium (float) – Target equilibrium wealth share W*.

  • damping (float) – Damping coefficient (negative = mean-reverting).

  • frequency (float) – Natural frequency of oscillation.

Return type:

float

Returns:

Second derivative d²W/dt².

Examples

>>> result = calculate_wealth_acceleration(0.32, 0.001, 0.30, -0.1, 0.05)
>>> round(result, 10)
-0.00015
babylon.formulas.calculate_wealth_flow(source_share, extraction_rate, resistance=0.0)[source]

Calculate per-tick wealth flow from source class.

Parameters:
  • source_share (float) – Source class wealth share [0, 1].

  • extraction_rate (float) – Base extraction coefficient.

  • resistance (float) – Class consciousness resistance [0, 1].

Return type:

float

Returns:

Wealth delta flowing out of source class.

Examples

>>> calculate_wealth_flow(0.5, 0.01, 0.0)
0.005
>>> calculate_wealth_flow(0.5, 0.01, 0.5)  # 50% resistance
0.0025
babylon.formulas.invert_wealth_to_population(wealth_shares, target_wealth_pct=33.333)[source]

Find population percentile owning target wealth percentage.

Inverts the wealth distribution to find what fraction of the population owns a given fraction of total wealth. Uses linear interpolation.

Parameters:
  • wealth_shares (tuple[float, float, float, float]) – (top_1%, 90-99%, 50-90%, bottom_50%) shares.

  • target_wealth_pct (float) – Target cumulative wealth percentage.

Return type:

float

Returns:

Population percentile owning up to target_wealth_pct of wealth.

Examples

>>> shares = (30.7, 36.4, 30.3, 2.5)
>>> result = invert_wealth_to_population(shares, 33.333)
>>> 90.0 < result < 91.0
True
babylon.formulas.compute_ollivier_ricci(graph, u, v, alpha=0.5, weight_attr=None)[source]

Compute Ollivier-Ricci curvature for a single edge (u, v).

Parameters:
  • graph (BabylonUGraph) – Undirected or directed NetworkX graph.

  • u (str) – Source node.

  • v (str) – Target node.

  • alpha (float) – Self-loop probability weight in [0, 1]. Higher alpha = more weight on the node itself.

  • weight_attr (str | None) – Optional edge attribute name for weights. When set, probability measures distribute (1-alpha) proportional to edge weights instead of uniformly, and shortest path uses weighted distances. None = unweighted (backward compatible).

Return type:

float

Returns:

Curvature kappa(u,v) = 1 - W1(mu_u, mu_v) / d(u,v). Positive = well-connected, negative = bottleneck.

Raises:

ValueError – If u or v is not in the graph or they are not connected.

babylon.formulas.calculate_contradiction_intensity(divergence, centrality_a, centrality_b, sensitivity=1.0)[source]

Calculate the emergent intensity of a contradiction edge.

Deprecated since version spec-lawverian-C1: Superseded by calculate_wealth_asymmetry_gap(). This function fed a raw dollar-scale divergence into a [0, 1] clamp, which saturated to 1.0 on any real wealth gap and carried no information (the four-inertness-bugs “Formula” defect). Retained for the deprecation window; no production caller remains after Phase C.

Combines raw dialectical divergence (e.g. wealth gap, ideological distance) with the topological importance of the entities involved, scaling the divergence magnitude by their hypergraph centrality or degree.

Formula:

intensity = divergence * (1 + sqrt(Centrality_a * Centrality_b)) * sensitivity Bound to [0.0, 1.0]

Parameters:
  • divergence (float) – Raw difference between node states (typically [0, 1]).

  • centrality_a (float) – Network/Hypergraph centrality of node A (typically [0, 1]).

  • centrality_b (float) – Network/Hypergraph centrality of node B (typically [0, 1]).

  • sensitivity (float) – System or definition-level scaling factor.

Return type:

float

Returns:

Intensity scalar bounded [0.0, 1.0].

Example

>>> calculate_contradiction_intensity(0.5, 0.8, 0.2, 1.0)
0.7...
babylon.formulas.calculate_wealth_asymmetry_balance(wealth_a, wealth_b, epsilon=1e-9)[source]

Signed dominance of pole B over pole A, in [-1, 1].

The signed counterpart of calculate_wealth_asymmetry_gap(): \((W_b - W_a) / (W_a + W_b)\), clamped to [-1, 1]. Positive means pole B (by convention the richer/target side) dominates; negative means pole A dominates; 0 is parity. Its magnitude equals the gap. Like the gap it is exactly numeraire-invariant.

Parameters:
  • wealth_a (float) – Wealth of pole A (non-negative).

  • wealth_b (float) – Wealth of pole B (non-negative).

  • epsilon (float) – Zero-guard threshold on the pole sum; below it the balance is 0.0.

Return type:

float

Returns:

The signed balance in [-1, 1]; 0.0 when both poles are empty.

Example

>>> calculate_wealth_asymmetry_balance(10.0, 30.0)
0.5
>>> calculate_wealth_asymmetry_balance(30.0, 10.0)
-0.5

See also

calculate_wealth_asymmetry_gap(): the unsigned magnitude.

babylon.formulas.calculate_wealth_asymmetry_gap(wealth_a, wealth_b, epsilon=1e-9)[source]

Scale-free distance of a two-pole wealth relation from closure.

The gap is the normalized absolute difference of the two poles’ wealth, \(|W_b - W_a| / (W_a + W_b)\), clamped to [0, 1]: 0 when the poles are at parity (the contradiction is resolved), approaching 1 as one pole holds all the wealth. Dividing by the pole sum makes it a pure number — multiplying both wealths by any k > 0 (a change of monetary numeraire) leaves it unchanged.

epsilon guards ONLY the degenerate all-zero case (both poles empty); it is deliberately NOT added into the ratio, so the measure stays exactly numeraire-invariant rather than invariant-up-to-epsilon (this is the difference that lets the property test hold to 1e-12).

Parameters:
  • wealth_a (float) – Wealth of pole A (non-negative).

  • wealth_b (float) – Wealth of pole B (non-negative).

  • epsilon (float) – Zero-guard threshold on the pole sum; below it the gap is 0.0 (an empty relation has no measurable contradiction).

Return type:

float

Returns:

The asymmetry gap in [0, 1]; 0.0 when both poles are empty.

Example

>>> calculate_wealth_asymmetry_gap(10.0, 30.0)
0.5
>>> calculate_wealth_asymmetry_gap(0.0, 0.0)
0.0
>>> round(calculate_wealth_asymmetry_gap(1.0, 3.0), 6) == round(
...     calculate_wealth_asymmetry_gap(1000.0, 3000.0), 6)
True

See also

calculate_wealth_asymmetry_balance(): the signed counterpart.

babylon.formulas.compute_ternary_consciousness(community_type, org_landscape, substrate_floor=0.0)[source]

Compute ternary consciousness from organizational landscape.

Algorithm: 1. Sum weighted contributions per tendency.

Weight w_i = membership_density * cadre_level * cohesion.

  1. Unorganized fraction = max(0, 1 - sum(membership_densities)). Defaults to liberal (Jackson: passive acceptance is liberal hegemony).

  2. Normalize to simplex (r + l + f = 1.0).

  3. Apply substrate floor post-normalization: if r < floor, set r = floor and redistribute remaining (1-floor) to l and f proportionally.

Parameters:
  • community_type (CommunityType) – Which community this is for (used for logging).

  • org_landscape (list[OrgContribution]) – Organizations operating in the community.

  • substrate_floor (float) – Minimum r regardless of org landscape [0, 1].

Return type:

TernaryConsciousness

Returns:

TernaryConsciousness with r, l, f derived from org landscape. contestation_stored is None (uses Shannon entropy).

babylon.formulas.calculate_solidarity_potential(base_solidarity, shared_count, rent_a, rent_b, overlap_bonus=0.1, rent_penalty=0.05)[source]

Compute solidarity potential between two agents from community overlap.

Shared community membership creates conditions for solidarity formation, penalized by imperial rent differential (material divergence impedes solidarity even with shared identity).

Parameters:
  • base_solidarity (float) – Base class solidarity between the two agents.

  • shared_count (int) – Number of communities both agents share.

  • rent_a (float) – Imperial rent received by agent A.

  • rent_b (float) – Imperial rent received by agent B.

  • overlap_bonus (float) – Bonus per shared community membership.

  • rent_penalty (float) – Penalty per unit of rent differential.

Return type:

float

Returns:

Solidarity potential score (may be negative if rent gap dominates).

Examples

>>> calculate_solidarity_potential(0.3, 2, 0.0, 0.0)
0.5
>>> calculate_solidarity_potential(0.3, 0, 0.0, 0.0)
0.3
babylon.formulas.calculate_threat_score(memberships)[source]

Compute per-agent threat score from community memberships.

Each membership contributes: heat * effective_visibility * role_weight * legal_status_multiplier. The total is the sum across all memberships.

Parameters:

memberships (list[tuple[float, float, float, float]]) – List of (heat, effective_visibility, role_weight, legal_status_multiplier) tuples, one per community membership.

Return type:

float

Returns:

Cumulative threat score for the agent.

Examples

>>> round(calculate_threat_score([(0.4, 0.8, 1.0, 1.0)]), 6)
0.32
babylon.formulas.calculate_infrastructure_decay(current, decay_alpha, core_organizer_count, maintenance_factor=0.1)[source]

Compute new infrastructure after one tick of decay.

Infrastructure decays toward zero without maintenance. CORE_ORGANIZER members counteract decay proportionally.

Formula: new = current * (1 - alpha) + maintenance * alpha where maintenance = min(core_organizer_count * maintenance_factor, 1.0)

Parameters:
  • current (float) – Current infrastructure level [0, 1].

  • decay_alpha (float) – Decay rate per tick [0, 1].

  • core_organizer_count (int) – Number of CORE_ORGANIZER members remaining.

  • maintenance_factor (float) – Infrastructure contribution per CORE_ORGANIZER.

Return type:

float

Returns:

New infrastructure level after decay and maintenance, clamped to [0, 1].

Examples

>>> round(calculate_infrastructure_decay(0.5, 0.04, 0), 4)
0.48
>>> round(calculate_infrastructure_decay(0.5, 0.04, 2, 0.1), 4)
0.488
babylon.formulas.calculate_solidarity_amplification(base_strength, shared_communities)[source]

Amplify solidarity_strength based on shared community infrastructure.

For each shared community, the amplification is scaled by the community’s infrastructure, cohesion, and both agents’ membership strengths.

Formula: amplified = base * (1 + sum(infra * cohesion * str_a * str_b))

Parameters:
  • base_strength (float) – Base solidarity_strength on the SOLIDARITY edge.

  • shared_communities (list[tuple[float, float, float, float]]) – List of (infrastructure, cohesion, strength_a, strength_b) tuples, one per shared community.

Return type:

float

Returns:

Amplified solidarity strength.

Examples

>>> calculate_solidarity_amplification(0.5, [])
0.5
>>> round(calculate_solidarity_amplification(0.5, [(0.8, 0.6, 0.7, 0.4)]), 6)
0.5672
babylon.formulas.compute_community_cost_modifier(memberships, community_states)[source]

Compute compound reproduction cost modifier from community memberships.

The modifier is the product of reproduction_cost_modifier across all communities the agent belongs to. No memberships → 1.0 (no effect).

Parameters:
  • memberships (list[Any]) – Agent’s community memberships.

  • community_states (dict[Any, Any]) – Dict mapping CommunityType to CommunityState.

Return type:

float

Returns:

Multiplicative compound modifier (product of all community modifiers).

Examples

>>> compute_community_cost_modifier([], {})
1.0
babylon.formulas.compute_population_flow(*, pop_d, pop_p, pop_d_prime, birth_rate, rate_d_to_p, rate_p_to_d_prime, rate_d_prime_to_death)[source]

Compute one-tick population transitions across D/P/D’ phases.

Applies birth, transition, and death rates to compute new population in each phase. All outputs are clamped to non-negative.

Parameters:
  • pop_d (float) – Current D phase population.

  • pop_p (float) – Current P phase population.

  • pop_d_prime (float) – Current D’ phase population.

  • birth_rate (float) – Births per P-phase person per tick.

  • rate_d_to_p (float) – D → P transition rate per tick.

  • rate_p_to_d_prime (float) – P → D’ transition rate per tick.

  • rate_d_prime_to_death (float) – D’ mortality rate per tick.

Return type:

tuple[float, float, float, float, float]

Returns:

Tuple of (new_pop_d, new_pop_p, new_pop_d_prime, births, deaths).

Examples

>>> result = compute_population_flow(
...     pop_d=2150, pop_p=6050, pop_d_prime=1800,
...     birth_rate=0.0107, rate_d_to_p=0.0556,
...     rate_p_to_d_prime=0.0213, rate_d_prime_to_death=0.039,
... )
>>> abs(result[3] - 64.735) < 1  # births ≈ 64.7
True
babylon.formulas.compute_dependency_ratio(*, pop_d, pop_p, pop_d_prime)[source]

Compute dependency ratio: non-productive to productive population.

Parameters:
  • pop_d (float) – D phase population.

  • pop_p (float) – P phase population.

  • pop_d_prime (float) – D’ phase population.

Return type:

float

Returns:

(pop_d + pop_d_prime) / pop_p, or inf if pop_p is zero.

Examples

>>> compute_dependency_ratio(pop_d=2150, pop_p=6050, pop_d_prime=1800)
0.6528...
babylon.formulas.compute_legitimation_index(*, pension_coverage, ss_replacement_rate, healthcare_security, home_ownership_rate, retirement_confidence, w_home, w_health, w_retire, w_pension, w_ss)[source]

Compute weighted legitimation index from five material components.

The index measures how credibly the D’ promise is underwritten. Weight ordering reflects political judgment about which conditions most credibly back the promise.

Parameters:
  • pension_coverage (float) – Fraction with pension access [0, 1].

  • ss_replacement_rate (float) – Social Security replacement ratio [0, 1].

  • healthcare_security (float) – Fraction with secure healthcare [0, 1].

  • home_ownership_rate (float) – Home ownership rate [0, 1].

  • retirement_confidence (float) – Subjective security assessment [0, 1].

  • w_home (float) – Weight for home ownership.

  • w_health (float) – Weight for healthcare security.

  • w_retire (float) – Weight for retirement confidence.

  • w_pension (float) – Weight for pension coverage.

  • w_ss (float) – Weight for SS replacement.

Return type:

float

Returns:

Legitimation index [0, 1].

Examples

>>> round(compute_legitimation_index(
...     pension_coverage=0.73, ss_replacement_rate=0.43,
...     healthcare_security=0.60, home_ownership_rate=0.66,
...     retirement_confidence=0.50,
...     w_home=0.35, w_health=0.30, w_retire=0.20,
...     w_pension=0.10, w_ss=0.05,
... ), 6)
0.6055
babylon.formulas.compute_pareto_gini(*, alpha)[source]

Compute Gini coefficient from Pareto shape parameter.

For a Pareto distribution with shape α > 0.5:

Gini = 1 / (2α - 1)

Parameters:

alpha (float) – Pareto shape parameter (must be > 0.5).

Return type:

float

Returns:

Gini coefficient [0, 1].

Raises:

ValueError – If alpha <= 0.5 (Gini would be >= 1.0 or undefined).

Examples

>>> compute_pareto_gini(alpha=1.5)
0.5
babylon.formulas.compute_ideology_transmission(*, caregiver_ideology, institutional_hegemony, caregiver_weight, institutional_weight)[source]

Compute ideology transmitted during D→P phase transition.

Blends caregiver (family) influence with institutional hegemony (schools, media, state) to determine P-phase entry ideology.

Parameters:
  • caregiver_ideology (float) – Caregiver consciousness level.

  • institutional_hegemony (float) – Institutional hegemonic pressure.

  • caregiver_weight (float) – Weight for caregiver influence.

  • institutional_weight (float) – Weight for institutional influence.

Return type:

float

Returns:

Transmitted ideology value.

Examples

>>> round(compute_ideology_transmission(
...     caregiver_ideology=0.3, institutional_hegemony=0.8,
...     caregiver_weight=0.7, institutional_weight=0.3,
... ), 6)
0.45
babylon.formulas.compute_shadow_subsidy(*, p_g2_labor_value, wage_paid_for_d_g2)[source]

Compute shadow subsidy from intergenerational labor reproduction.

The shadow subsidy is the difference between the value of labor-power produced (P_g2) and the wages paid to P_g1 for raising D_g2. This measures the unpaid reproductive labor externalized to households.

Parameters:
  • p_g2_labor_value (float) – Value of next-generation labor-power produced.

  • wage_paid_for_d_g2 (float) – Investment in D phase child-rearing.

Return type:

float

Returns:

Shadow subsidy (always >= 0).

Examples

>>> compute_shadow_subsidy(p_g2_labor_value=60000.0, wage_paid_for_d_g2=12000.0)
48000.0
babylon.formulas.calculate_defection_probability(chauvinism, discipline)[source]

Probability an entitled org member defects under crisis.

P_defection = sigmoid(chauvinism discipline). Chauvinism is the accumulated reactionary sentiment of a labor-aristocratic recruit; discipline is the organization’s counter-pressure. At parity the probability is 0.5.

Parameters:
  • chauvinism (float) – Accumulated reactionary sentiment [0, 1].

  • discipline (float) – Organizational counter-pressure [0, 1].

Return type:

float

Returns:

Defection probability in [0, 1] (bounded by the sigmoid).

Example

>>> calculate_defection_probability(chauvinism=0.5, discipline=0.5)
0.5
babylon.formulas.calculate_entitlement_effective(base_entitlement, threat, threat_gain=_REACT.entitlement_threat_gain)[source]

Effective entitlement under threat (a threatened stake reacts harder).

effective = clamp(base + threat_gain × threat × (1 base), 0, 1). A stake under threat (loss of privilege) amplifies toward the ceiling; with no threat the effective value passes the base through unchanged.

Parameters:
  • base_entitlement (float) – The node’s base entitlement [0, 1].

  • threat (float) – Perceived threat to the stake [0, 1] (e.g., falling Φ).

  • threat_gain (float) – Amplification coefficient (default from ReactionaryDefines).

Return type:

float

Returns:

Effective entitlement in [0, 1].

Example

>>> calculate_entitlement_effective(base_entitlement=0.8, threat=0.0)
0.8
babylon.formulas.calculate_fascist_pull(agitation, entitlement, solidarity, epsilon=_REACT.solidarity_pull_epsilon)[source]

Fascist pull on an entitled stratum under crisis.

Fascist_Pull = Agitation × (Entitlement / (Solidarity + ε)).

Crisis-gated: with zero agitation the pull is zero (hegemony holds — the Fundamental Theorem). Solidarity in the denominator suppresses the pull (I.4: solidarity across the colonial divide reroutes agitation to revolution). The ε guard both prevents division by zero and sets the maximal unsuppressed pull.

Parameters:
  • agitation (float) – Raw crisis energy [0, ∞) from falling wages / rising exploitation (babylon.formulas.consciousness_routing).

  • entitlement (float) – The stratum’s stake in the imperial order [0, 1].

  • solidarity (float) – Incident solidarity strength [0, 1] — the cross-colonial bridge that dampens reaction.

  • epsilon (float) – Denominator guard (default from ReactionaryDefines).

Return type:

float

Returns:

The fascist pull (≥ 0). Compared against ReactionaryDefines.fascist_pull_threshold by the system.

Example

>>> calculate_fascist_pull(agitation=2.0, entitlement=0.8, solidarity=0.0, epsilon=0.1)
16.0
>>> calculate_fascist_pull(agitation=0.0, entitlement=0.8, solidarity=0.0)
0.0
babylon.formulas.calculate_spontaneous_riot_risk(volatility, discipline)[source]

Undirected-disorder risk for the declassed lumpenproletariat.

riot_risk = volatility × (1 discipline), clamped to [0, 1]. High volatility with low organizational discipline produces spontaneous, non-revolutionary disorder — the reactionary inverse of the organized, solidarity-building UPRISING (it destroys wealth but builds no solidarity).

Parameters:
  • volatility (float) – The stratum’s disorder propensity [0, 1].

  • discipline (float) – Organizational discipline gating the volatility [0, 1].

Return type:

float

Returns:

Riot risk in [0, 1]. Compared against ReactionaryDefines.spontaneous_riot_threshold.

Example

>>> calculate_spontaneous_riot_risk(volatility=0.8, discipline=0.0)
0.8
>>> calculate_spontaneous_riot_risk(volatility=0.8, discipline=1.0)
0.0
babylon.formulas.calculate_metabolic_impact(policy, defines=None)[source]

Return the per-tick habitability change for a given ExtractionPolicy (spec-070 FR-004).

The default mapping is:

  • INTENSIFY → -0.02

  • CONTINUE → -0.005

  • CEASE → +0.01

Override any of the three via BalkanizationDefines (no magic numbers at the system layer, Constitution III.1).

Parameters:
Return type:

float

Returns:

Per-tick habitability change to apply along each CLAIMS edge.

Raises:

ValueError – If policy is not a recognized ExtractionPolicy member.

Example

>>> from babylon.models.enums import ExtractionPolicy
>>> calculate_metabolic_impact(ExtractionPolicy.INTENSIFY)
-0.02
babylon.formulas.contiguous_influence_majority_subregion(graph, faction_id, sovereign_id, defines=None)[source]

Compute the largest contiguous H3-res-7 sub-region of a Sovereign’s territory where faction_id’s INFLUENCES.influence_level exceeds BalkanizationDefines.secession_influence_threshold (spec-070 FR-029b).

The result is a deterministic, lex-sorted frontier BFS over ADJACENCY-linked H3 res-7 hexes, restricted to hexes claimed by sovereign_id and satisfying the influence predicate.

Parameters:
  • graph (GraphProtocol) – GraphProtocol exposing query_sovereign_claims(), query_adjacent_territories(), and query_faction_influence_by_territory().

  • faction_id (str) – Candidate secessionist Faction ID.

  • sovereign_id (str) – Parent Sovereign whose territory is being analyzed.

  • defines (BalkanizationDefines | None) – Optional override defines.

Return type:

frozenset[str]

Returns:

Frozen set of Territory IDs comprising the largest contiguous sub-region. Returns the empty set if no eligible component is ≥ BalkanizationDefines.min_contiguous_hex_count.

Raises:

AttributeError – If graph does not implement the required query methods.

babylon.formulas.derive_default_multipliers_from_stance(stance, defines=None)[source]

Return the canonical 4-tuple of Faction mechanical multipliers (FR-007 + data-model.md §3.1) for a given ColonialStance.

Tuple order is:

(extraction_modifier, violence_modifier,
 class_reduction, metabolic_reduction)

The default mapping (overridable via BalkanizationDefines):

Stance

extraction

violence

class_red.

metab_red.

UPHOLD IGNORE ABOLISH

1.5 0.8 0.0

2.0 0.5 0.3

0.0 0.7 0.5

-0.5

0.0

+0.8

Parameters:
Return type:

tuple[float, float, float, float]

Returns:

4-tuple of multipliers in the canonical order above.

Raises:

KeyError – If stance is not a recognized ColonialStance member.

Example

>>> from babylon.models.enums import ColonialStance
>>> derive_default_multipliers_from_stance(ColonialStance.UPHOLD)
(1.5, 2.0, 0.0, -0.5)
babylon.formulas.derive_extraction_policy_from_stance(stance)[source]

Derive the Sovereign’s ExtractionPolicy from a Faction’s ColonialStance (spec-070 FR-003).

Mapping (data-model.md §3.2; deterministic):

  • UPHOLD → INTENSIFY

  • IGNORE → CONTINUE

  • ABOLISH → CEASE

Parameters:

stance (ColonialStance) – The ruling Faction’s colonial stance.

Return type:

ExtractionPolicy

Returns:

Derived ExtractionPolicy.

Raises:

KeyError – If stance is not a recognized ColonialStance member.

Example

>>> from babylon.models.enums import ColonialStance
>>> derive_extraction_policy_from_stance(ColonialStance.UPHOLD)
<ExtractionPolicy.INTENSIFY: 'intensify'>
babylon.formulas.detect_red_settler_trap(faction_class_reduction, faction_colonial_stance, defines=None)[source]

Detect the Red Settler Trap diagnostic condition (spec-070 FR-034).

Fires when a Faction has both:

  • class_reduction >= red_settler_trap_class_reduction_threshold (default 0.6), AND

  • colonial_stance {UPHOLD, IGNORE}

The combination represents a Faction successfully reducing class contradiction while leaving settler-colonial relations intact — the canonical RED_OGV (Occupied Garrison of the Volksgemeinschaft) trap.

Parameters:
  • faction_class_reduction (float) – Faction’s class_reduction multiplier.

  • faction_colonial_stance (ColonialStance) – Faction’s colonial_stance.

  • defines (BalkanizationDefines | None) – Optional override defines.

Return type:

bool

Returns:

True iff the trap condition is satisfied.

Example

>>> from babylon.models.enums import ColonialStance
>>> detect_red_settler_trap(0.7, ColonialStance.IGNORE)
True
>>> detect_red_settler_trap(0.7, ColonialStance.ABOLISH)
False
babylon.formulas.extrapolate_habitability(current_habitability, metabolic_impact, horizon_ticks)[source]

Linearly extrapolate a Territory’s habitability over a horizon (spec-070 FR-051, used by SovereignProjection).

Assumes constant policy (no Faction transitions during the horizon). Clamps to [0.0, 1.0].

Parameters:
  • current_habitability (float) – Current habitability ∈ [0, 1].

  • metabolic_impact (float) – Per-tick habitability change.

  • horizon_ticks (int) – Number of ticks to project forward.

Return type:

float

Returns:

Projected habitability, clamped to [0.0, 1.0].

Example

>>> round(extrapolate_habitability(0.8, -0.02, 10), 6)
0.6
>>> extrapolate_habitability(0.5, 0.01, 100)  # would overshoot
1.0
babylon.formulas.winning_faction_for_territory(graph, territory_id, incumbent_faction_id, rng)[source]

Determine the winning BalkanizationFaction for a Territory (spec-070 FR-021).

Computes argmax_f Σ INFLUENCES(f territory).influence_level with a two-stage tiebreaker:

  1. If the incumbent ruling_faction is among the tied factions, the incumbent wins (stability preserved).

  2. Otherwise, draw deterministically from rng over the sorted-ID tied set.

Parameters:
  • graph (GraphProtocol) – GraphProtocol exposing query_faction_influence_by_territory().

  • territory_id (str) – Target Territory node ID.

  • incumbent_faction_id (str | None) – ID of the Territory’s current ruling Faction, if any. May be None for unclaimed territory.

  • rng (Random) – Seeded random.Random used for deterministic tiebreaking when no incumbent participates.

Return type:

str | None

Returns:

The winning Faction ID, or None if the Territory has zero incoming INFLUENCES.

Raises:

AttributeError – If graph does not implement query_faction_influence_by_territory().

Modules

balkanization

Spec-070 Balkanization formulas (FR-003, FR-004, FR-007, FR-021, FR-029b, FR-034).

class_dynamics

Class Wealth Dynamics ODE System.

community

Community layer formulas (Feature 022).

consciousness

Ternary consciousness computation (Feature 034, US1).

consciousness_routing

Consciousness routing formulas (Spec 043 — Consciousness as Value Transparency).

constants

Shared constants for formula calculations.

contradiction

Contradiction gap formulas for the Babylon simulation.

curvature

Ollivier-Ricci curvature computation for contradiction field topology.

dynamic_balance

Dynamic Balance formulas (Sprint 3.4.4).

fundamental_theorem

Fundamental Theorem of MLM-TW.

lifecycle

D-P-D' lifecycle circuit formulas (Feature 030).

metabolic_rift

Metabolic Rift formulas (Slice 1.4).

reactionary

Reactionary-subject formulas (spec-071).

solidarity

Solidarity Transmission formula (Sprint 3.4.2).

state_ai

State AI formulas (Feature 039).

survival_calculus

Survival Calculus formulas.

trpf

Tendency of the Rate of Profit to Fall (TRPF) formulas.

unequal_exchange

Unequal Exchange formulas.

vitality

Vitality formulas for demographic mortality calculations.