Skip to main content

hypergraph_rs/raster/
algebra.rs

1//! Transformation algebra (`topology-deck.html:181-193`): `s = v·e`, `r`,
2//! `T`, `Φ`. Pure, RNG-free, fully portable — no `mulberry32` needed here.
3//! Task 5.
4
5/// One row of the deck's 13-industry table.
6#[derive(Debug, Clone, PartialEq)]
7pub struct Industry {
8    pub name: String,
9    pub lane: u8,
10    pub c: f64,
11    pub v: f64,
12    pub e: f64,
13}
14
15/// The transformation-algebra outputs for a set of industries.
16#[derive(Debug, Clone, PartialEq)]
17pub struct Economy {
18    pub r: f64,
19    pub big_s: f64,
20    pub cv: f64,
21    pub t: Vec<f64>,
22    pub phi: f64,
23    pub rent_imperial: f64,
24    pub rent_internal: f64,
25}
26
27/// `s_i = v_i·e_i`; `S = Σs_i`; `CV = Σ(c_i+v_i)`; `r = S/CV`;
28/// `T_i = r·(c_i+v_i) − s_i`; `rent_imperial = −Σ_{lane=0}T_i`;
29/// `rent_internal = −Σ_{lane=1}T_i`; `Φ = Σ_{T_i>0}T_i`.
30/// Iterates `inds` in slice order (deterministic).
31pub fn transform(inds: &[Industry]) -> Economy {
32    let s: Vec<f64> = inds.iter().map(|i| i.v * i.e).collect();
33    let big_s: f64 = s.iter().sum();
34    let cv: f64 = inds.iter().map(|i| i.c + i.v).sum();
35    let r = big_s / cv;
36
37    let t: Vec<f64> = inds
38        .iter()
39        .zip(s.iter())
40        .map(|(i, s_i)| r * (i.c + i.v) - s_i)
41        .collect();
42
43    let mut rent_imperial = 0.0;
44    let mut rent_internal = 0.0;
45    let mut phi = 0.0;
46    for (i, t_i) in inds.iter().zip(t.iter()) {
47        if i.lane == 0 {
48            rent_imperial -= t_i;
49        }
50        if i.lane == 1 {
51            rent_internal -= t_i;
52        }
53        if *t_i > 0.0 {
54            phi += t_i;
55        }
56    }
57
58    Economy {
59        r,
60        big_s,
61        cv,
62        t,
63        phi,
64        rent_imperial,
65        rent_internal,
66    }
67}
68
69/// The deck's 13-industry fixture table (`topology-deck.html`, scout-verified
70/// c/v/e/lane; Task 5).
71pub fn deck_industries() -> Vec<Industry> {
72    let rows: [(&str, u8, f64, f64, f64); 13] = [
73        ("export agriculture", 0, 14.0, 10.0, 3.2),
74        ("textile assembly", 0, 10.0, 9.0, 3.0),
75        ("extractive mining", 0, 26.0, 7.0, 2.6),
76        ("migrant agriculture", 1, 9.0, 8.0, 2.4),
77        ("meatpacking", 1, 12.0, 8.0, 2.2),
78        ("logistics depots", 1, 18.0, 9.0, 1.9),
79        ("carceral labor", 1, 4.0, 5.0, 4.0),
80        ("defense aerospace", 2, 34.0, 8.0, 1.1),
81        ("suburban construction", 2, 20.0, 9.0, 1.2),
82        ("professional strata", 2, 16.0, 11.0, 0.9),
83        ("pharma IP", 3, 44.0, 6.0, 1.0),
84        ("platform rents", 3, 52.0, 7.0, 1.1),
85        ("finance", 3, 60.0, 5.0, 0.8),
86    ];
87    rows.into_iter()
88        .map(|(name, lane, c, v, e)| Industry {
89            name: name.to_string(),
90            lane,
91            c,
92            v,
93            e,
94        })
95        .collect()
96}