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:

Probability [0, 1].

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:

Probability [0, 1].

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_exploitation_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.

AUSTERITY = 'austerity'
BRIBERY = 'bribery'
CRISIS = 'crisis'
IRON_FIST = 'iron_fist'
NO_CHANGE = 'no_change'
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 of (decision

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_organic_composition(constant_capital, variable_capital)[source]

Calculate organic composition of capital: OCC = c / v.

The organic composition represents the ratio of “dead labor” (machinery, materials) to “living labor” (wages). As capitalism develops, OCC tends to rise.

This is the Epoch 2 formula. Currently a placeholder.

Parameters:
  • constant_capital (float) – Investment in machinery, materials (c)

  • variable_capital (float) – Wages paid to labor (v)

Return type:

float

Returns:

Organic composition ratio (0.0 to infinity)

Example

>>> calculate_organic_composition(50, 100)
0.5
>>> calculate_organic_composition(400, 100)
4.0
Epoch 2 Data Requirements:

OCC varies systematically by industry and occupation. QCEW/NAICS industry codes serve as proxy for capital-intensity.

Industry-to-OCC mapping (representative coefficients):

NAICS

Industry

Typical OCC

11

Agriculture

1.5 - 2.5

21

Mining/Extraction

4.0 - 8.0

22

Utilities

6.0 - 10.0

23

Construction

0.8 - 1.5

31-33

Manufacturing

2.0 - 5.0

42

Wholesale Trade

0.5 - 1.0

44-45

Retail Trade

0.3 - 0.8

51

Information

2.0 - 4.0

52

Finance/Insurance

0.2 - 0.5

54

Professional Services

0.2 - 0.5

62

Healthcare

1.0 - 2.0

72

Accommodation/Food

0.5 - 1.0

Occupation-to-class mapping (SOC codes):

QCEW provides employment by industry, which correlates with occupation mix. High-OCC industries employ more machine operators (SOC 51xxxx) and fewer service workers (SOC 35xxxx-39xxxx).

Data sources:
  • QCEW: total_wages_all_workers by county × NAICS → v

  • BLS Capital-Labor tables: industry OCC coefficients

  • BEA Fixed Assets: capital stock by industry → c baseline

Transformation:

QCEW(county, naics) → variable_capital = total_wages
BLS(naics) → occ_coefficient (industry average)
constant_capital = variable_capital * occ_coefficient
OCC = c / v = occ_coefficient

Note

Higher OCC means more capital-intensive production. In Marx’s examples: - OCC = 0.5: Early capitalism (labor-intensive) - OCC = 4.0: Advanced capitalism (capital-intensive)

See ai-docs/epochs/epoch3/epoch2-trpf.yaml for specification.

babylon.formulas.calculate_rate_of_profit(surplus_value, constant_capital, variable_capital)[source]

Calculate Marx’s rate of profit: p’ = s / (c + v).

This is the Epoch 2 formula for proper OCC-based TRPF calculation. Currently a placeholder - full implementation in Epoch 2.

Parameters:
  • surplus_value (float) – Value extracted beyond wages (s)

  • constant_capital (float) – Investment in machinery, materials (c)

  • variable_capital (float) – Wages paid to labor (v)

Return type:

float

Returns:

Rate of profit as decimal (0.0 to 1.0+)

Example

>>> calculate_rate_of_profit(100, 50, 100)  # Marx's first example
0.6666666666666666
>>> calculate_rate_of_profit(100, 400, 100)  # Marx's third example
0.2
Epoch 2 Data Requirements:

QCEW field mappings for parameter derivation:

variable_capital (v):
  • QCEW field: total_wages_all_workers

  • Interpretation: Total wages paid = living labor cost

  • Aggregation: Sum by county FIPS + industry NAICS

constant_capital (c):
  • QCEW fields: Not directly available

  • Derivation: Cross-reference with BEA Fixed Assets tables

  • Proxy method: c = v * industry_occ_coefficient

  • Industry OCC coefficients from BLS capital-labor ratios by NAICS

surplus_value (s):
  • QCEW fields: Not directly available

  • Derivation: s = industry_output - c - v

  • Cross-reference: BEA GDP-by-industry for output values

  • Proxy method: s = v * exploitation_rate where exploitation rate varies by industry (manufacturing ~150%, services ~100%)

Transformation pipeline:

QCEW(county, naics) → QCEWRecord
BEA(naics) → industry_occ_coefficient, industry_output
v = qcew.total_wages_all_workers
c = v * industry_occ_coefficient
s = industry_output - c - v  # or v * exploitation_rate as proxy

Note

Full implementation requires: - constant_capital/variable_capital fields on Bourgeoisie entities - surplus_extracted tracking per tick - OCC dynamics (automation investments shifting c/v ratio)

See ai-docs/epochs/epoch3/epoch2-trpf.yaml for specification.

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-docs/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
__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

alpha_21: float = 0.0006
alpha_31: float = 0.0
alpha_32: float = 0.0
alpha_41: 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
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)
__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

beta: tuple[float, float, float, float] = (-0.1, -0.15, -0.1, -0.05)
equilibrium: tuple[float, float, float, float] = (0.305, 0.382, 0.294, 0.02)
omega: tuple[float, float, float, float] = (0.05, 0.08, 0.05, 0.03)
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 (Graph) – Undirected or directed NetworkX graph.

  • u (int | str) – Source node.

  • v (int | 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.

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.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

>>> calculate_threat_score([(0.4, 0.8, 1.0, 1.0)])
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
>>> calculate_solidarity_amplification(0.5, [(0.8, 0.6, 0.7, 0.4)])
0.567
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

>>> 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,
... )
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

>>> compute_ideology_transmission(
...     caregiver_ideology=0.3, institutional_hegemony=0.8,
...     caregiver_weight=0.7, institutional_weight=0.3,
... )
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, wage_paid_for_d_g2=12000)
48000.0

Modules

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 intensity 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).

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.