Skip to main content

aria_engine_core/
action.rs

1use serde::{Deserialize, Serialize};
2
3/// The five named actions of Aria Spec.
4///
5/// LOCK (§1.1): Σ = {OpticalStep, Predict, Match, Diffuse, Stutter} exactly.
6/// No sixth variant — enforced by G2 grep gate in CI.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum Action {
10    /// ψ' = U_t(ψ); UNCHANGED ⟨z, G, t⟩ — §6.1
11    OpticalStep,
12    /// z' = P(I(ψ), a_t); UNCHANGED ⟨ψ, G, t⟩ — §6.2
13    Predict,
14    /// G' = ED(G ⊕ z, G*); UNCHANGED ⟨ψ, z, t⟩ — §6.3
15    Match,
16    /// z' = Diff_G(z); t' = t+1; UNCHANGED ⟨ψ, G⟩ — §6.4
17    Diffuse,
18    /// UNCHANGED all vars — TLA stuttering semantics
19    Stutter,
20}
21
22impl Action {
23    /// All five actions in a fixed array for iteration.
24    pub const ALL: [Action; 5] = [
25        Action::OpticalStep,
26        Action::Predict,
27        Action::Match,
28        Action::Diffuse,
29        Action::Stutter,
30    ];
31
32    /// The four productive (non-stutter) actions.
33    pub const PRODUCTIVE: [Action; 4] = [
34        Action::OpticalStep,
35        Action::Predict,
36        Action::Match,
37        Action::Diffuse,
38    ];
39
40    /// Preferred Φ-cycle order: O → P → M → D (𝐂4)
41    pub const PHI_CYCLE: [Action; 4] = [
42        Action::OpticalStep,
43        Action::Predict,
44        Action::Match,
45        Action::Diffuse,
46    ];
47
48    /// Human-readable symbol for trace output.
49    pub fn symbol(&self) -> &'static str {
50        match self {
51            Action::OpticalStep => "O",
52            Action::Predict => "P",
53            Action::Match => "M",
54            Action::Diffuse => "D",
55            Action::Stutter => "S",
56        }
57    }
58}
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn action_has_exactly_five_variants() {
66        // G2 contract: exactly five variants, no more no less
67        assert_eq!(Action::ALL.len(), 5);
68        assert_eq!(Action::PRODUCTIVE.len(), 4);
69    }
70}