/// Penumbra: Rotational Closure — Layer 8 /// Provenance: Lean 4 → LambdaIR → MiniC → C → Safe Rust /// Source: HeytingLean/Generative/PrimeStability/RotationalClosure.lean /// Compute minimal period of x₀ under iteration of F pub fn minimal_period(f: impl Fn(&T) -> T, x0: &T, max_iter: u64) -> Option { let mut current = x0.clone(); for i in 1..=max_iter { current = f(¤t); if current == *x0 { return Some(i); } } None } /// Check if n is prime pub fn is_prime(n: u64) -> bool { if n < 2 { return false; } if n < 4 { return true; } if n % 2 == 0 || n % 3 == 0 { return false; } let mut i = 5u64; while i * i <= n { if n % i == 0 || n % (i + 2) == 0 { return false; } i += 6; } true } /// Theorem preserved: stability_hierarchy /// A massive (period > 1), indecomposable closure has prime period ≥ 2. pub fn stability_hierarchy(period: u64, decomposable: bool) -> bool { period > 1 && !decomposable && is_prime(period) && period >= 2 } #[cfg(test)] mod tests { use super::*; #[test] fn electron_period_two() { // Involution: 0 -> 1 -> 0 let period = minimal_period(|x: &u8| 1 - x, &0u8, 100); assert_eq!(period, Some(2)); } #[test] fn identity_period_one() { let period = minimal_period(|x: &u8| *x, &0u8, 100); assert_eq!(period, Some(1)); } #[test] fn prime_stability() { assert!(stability_hierarchy(2, false)); // Electron: stable assert!(stability_hierarchy(3, false)); // Prime: stable assert!(!stability_hierarchy(4, false)); // Composite: unstable assert!(!stability_hierarchy(1, false)); // Identity: not massive assert!(!stability_hierarchy(2, true)); // Decomposable: not stable } }