Skip to main content

logicaffeine_proof/
postnikov.rs

1//! The **Postnikov `k`-invariant** — the gluing data of a 2-type, and the obstruction to breaking it
2//! into a product.
3//!
4//! `two_type` built `K(A,2)` and `kan_complex` built `K(G,1)`. A general 2-truncated ∞-groupoid is *not*
5//! just a `π₁` and a `π₂` sitting side by side: by Mac Lane–Whitehead / Sinh's theorem it is classified
6//! by `(π₁ = G, π₂ = A, the G-action, k ∈ H³(G; A))`. The class `k` — the **Postnikov invariant** — is
7//! the associator of the corresponding 2-group, and it says how the two levels are *twisted*:
8//!
9//! - `k = 0` ⟺ the 2-type is the **product** `K(G,1) × K(A,2)` — the levels decouple.
10//! - `k ≠ 0` ⟺ a genuinely **entangled** 2-type, provably *not* a product.
11//!
12//! So `k` is "the single object carrying all `πₙ` *with their interactions*" reduced to one checkable
13//! cohomology class. And it is, once more, **a symmetry-breaking obstruction**: splitting the 2-type into
14//! a product is the ultimate symmetry break (decoupling `π₁` from `π₂`), and `k ≠ 0` is exactly the
15//! obstruction to it — the higher sibling of the deadlock `β₁`. We compute group cohomology directly
16//! (`A = Z/modulus`, trivial action) and crush the canonical case `H³(Z/2; Z/2) = Z/2`: the cup-cube
17//! cocycle is a 3-cocycle that is *not* a coboundary, so its 2-type is no product.
18
19use crate::two_group::FiniteGroup;
20
21fn idx(order: usize, t: &[usize]) -> usize {
22    t.iter().fold(0usize, |a, &x| a * order + x)
23}
24
25fn tuples(order: usize, n: usize) -> Vec<Vec<usize>> {
26    let mut out: Vec<Vec<usize>> = vec![vec![]];
27    for _ in 0..n {
28        let mut next = Vec::with_capacity(out.len() * order);
29        for t in &out {
30            for e in 0..order {
31                let mut u = t.clone();
32                u.push(e);
33                next.push(u);
34            }
35        }
36        out = next;
37    }
38    out
39}
40
41/// Every `n`-cochain `Gⁿ → A` (`A = Z/modulus`): `modulus^{order^n}` of them.
42fn all_cochains(order: usize, modulus: usize, n: usize) -> Vec<Vec<usize>> {
43    let len = order.pow(n as u32);
44    let mut out: Vec<Vec<usize>> = vec![vec![]];
45    for _ in 0..len {
46        let mut next = Vec::with_capacity(out.len() * modulus);
47        for t in &out {
48            for v in 0..modulus {
49                let mut u = t.clone();
50                u.push(v);
51                next.push(u);
52            }
53        }
54        out = next;
55    }
56    out
57}
58
59/// The group-cohomology coboundary `δⁿ : Cⁿ(G; A) → Cⁿ⁺¹(G; A)`, with `A = Z/modulus` and **trivial**
60/// `G`-action. `f` is a length-`order^n` table; the result is length `order^{n+1}`.
61pub fn coboundary(g: &FiniteGroup, modulus: usize, n: usize, f: &[usize]) -> Vec<usize> {
62    let order = g.order();
63    let mut out = vec![0usize; order.pow((n + 1) as u32)];
64    for t in tuples(order, n + 1) {
65        // (δf)(g_1,…,g_{n+1}) = f(g_2,…,g_{n+1}) + Σ_{i=1}^n (−1)^i f(…,g_i g_{i+1},…) + (−1)^{n+1} f(g_1,…,g_n)
66        let mut val: i64 = f[idx(order, &t[1..])] as i64;
67        for i in 1..=n {
68            let mut merged = t[..i - 1].to_vec();
69            merged.push(g.mul[t[i - 1]][t[i]]);
70            merged.extend_from_slice(&t[i + 1..]);
71            let sign = if i % 2 == 0 { 1 } else { -1 };
72            val += sign * f[idx(order, &merged)] as i64;
73        }
74        let sign = if (n + 1) % 2 == 0 { 1 } else { -1 };
75        val += sign * f[idx(order, &t[..n])] as i64;
76        out[idx(order, &t)] = val.rem_euclid(modulus as i64) as usize;
77    }
78    out
79}
80
81/// Is `f` an `n`-cocycle? (`δf = 0`)
82pub fn is_cocycle(g: &FiniteGroup, modulus: usize, n: usize, f: &[usize]) -> bool {
83    coboundary(g, modulus, n, f).iter().all(|&x| x == 0)
84}
85
86/// Is `f` an `n`-coboundary? (`f = δβ` for some `(n-1)`-cochain `β`)
87pub fn is_coboundary(g: &FiniteGroup, modulus: usize, n: usize, f: &[usize]) -> bool {
88    all_cochains(g.order(), modulus, n - 1)
89        .iter()
90        .any(|b| coboundary(g, modulus, n - 1, b) == f)
91}
92
93/// `|Hⁿ(G; A)|` — cocycles modulo coboundaries (both are subgroups of `Cⁿ`, so the order is the index).
94pub fn cohomology_size(g: &FiniteGroup, modulus: usize, n: usize) -> usize {
95    let cocycles = all_cochains(g.order(), modulus, n)
96        .into_iter()
97        .filter(|f| is_cocycle(g, modulus, n, f))
98        .count();
99    let mut coboundaries: std::collections::HashSet<Vec<usize>> = std::collections::HashSet::new();
100    for b in all_cochains(g.order(), modulus, n - 1) {
101        coboundaries.insert(coboundary(g, modulus, n - 1, &b));
102    }
103    cocycles / coboundaries.len()
104}
105
106/// The **cup product** `Cᵖ × Cᵠ → Cᵖ⁺ᵠ` (Alexander–Whitney; `Z/modulus` coefficients, trivial action,
107/// no signs): `(f ∪ h)(a₁,…,a_{p+q}) = f(a₁,…,a_p) · h(a_{p+1},…,a_{p+q})`. It makes the obstruction
108/// groups a graded ring `H*(G; A)` — the multiplicative algebra binding all the k-invariant levels.
109pub fn cup(
110    g: &FiniteGroup,
111    modulus: usize,
112    p: usize,
113    q: usize,
114    f: &[usize],
115    h: &[usize],
116) -> Vec<usize> {
117    let order = g.order();
118    let mut out = vec![0usize; order.pow((p + q) as u32)];
119    for t in tuples(order, p + q) {
120        out[idx(order, &t)] = (f[idx(order, &t[..p])] * h[idx(order, &t[p..])]) % modulus;
121    }
122    out
123}
124
125/// The **cup-square** cohomology operation `x ↦ x ∪ x : Hⁿ(−; A) → H²ⁿ(−; A)`. Over `Z/2` it is the TOP
126/// Steenrod square `Sqⁿ` — the first genuine *cohomology operation* (a natural transformation of the
127/// functor `Hⁿ(−;A)`), the secondary structure carried by the cohomology the Eilenberg–MacLane spectrum
128/// represents.
129pub fn cup_square(g: &FiniteGroup, modulus: usize, n: usize, f: &[usize]) -> Vec<usize> {
130    cup(g, modulus, n, n, f, f)
131}
132
133/// The **Bockstein** `β : Hⁿ(−; Z/2) → Hⁿ⁺¹(−; Z/2)` — the connecting homomorphism of the short exact
134/// sequence `0 → Z/2 →(×2) Z/4 → Z/2 → 0`. By a theorem of Steenrod, `β = Sq¹`. Computed honestly: lift
135/// the `Z/2`-cochain to `Z/4`, take `δ` over `Z/4` (which is even on a `Z/2`-cocycle), divide by 2, and
136/// reduce mod 2. The lowest genuine Steenrod square, reached as a connecting map rather than a cup-square.
137pub fn bockstein(g: &FiniteGroup, n: usize, c: &[usize]) -> Vec<usize> {
138    let lifted: Vec<usize> = c.iter().map(|&v| v % 4).collect();
139    let d = coboundary(g, 4, n, &lifted); // δ over Z/4
140    d.iter().map(|&v| (v / 2) % 2).collect()
141}
142
143/// The cup-power `xⁿ` of `Z/2` with `Z/2` coefficients: `α(g_1,…,g_n) = g_1·g_2·⋯·g_n` (1 iff every
144/// argument is 1). As the `n`-fold cup product of the nonzero 1-cocycle, it is an `n`-cocycle and the
145/// generator of `Hⁿ(Z/2; Z/2) = Z/2` — the explicit nonzero obstruction at level `n`.
146pub fn cup_power_z2(n: usize) -> Vec<usize> {
147    let len = 2usize.pow(n as u32);
148    let mut f = vec![0usize; len];
149    f[len - 1] = 1; // only the all-ones tuple (1,1,…,1) has product 1
150    f
151}
152
153/// The canonical nontrivial 3-cocycle (the cup-cube `x³`), generator of `H³(Z/2; Z/2) = Z/2`.
154pub fn cup_cube_z2() -> Vec<usize> {
155    cup_power_z2(3)
156}
157
158#[cfg(test)]
159#[path = "../../logicaffeine_tests/unit/logicaffeine_proof/postnikov/tests.rs"]
160mod tests;