Skip to main content

wasm4pm_compat/
nightly_foundry.rs

1//! Nightly foundry — zero-cost type-law surfaces derived from process-mining papers.
2//!
3//! Always compiled (the crate is nightly-only). No cfg gate, no `RUSTFLAGS`.
4//! This is an experimental staging area; the main type law lives in
5//! [`crate::law`], [`crate::petri`], [`crate::conformance`], [`crate::process_tree`],
6//! [`crate::powl`], [`crate::formats`], and [`crate::strict`].
7//!
8//! ## Four surfaces, four nightly features, four paper mappings
9//!
10//! | Surface | Feature | Paper |
11//! |---------|---------|-------|
12//! | [`petri_law`] | `generic_const_exprs` | Murata (1989) §2 incidence matrices W⁻, W⁺ |
13//! | [`powl_law`]  | `adt_const_params`    | Kourani (2505.07052) §3 POWL fragment kinds |
14//! | [`evidence_law`] | `min_specialization` | Blue River Dam — admitted vs raw label |
15//! | [`token_law`] | `portable_simd`       | Murata §2 enabling condition `∀p: M[p] ≥ W⁻[p][t]` |
16//!
17//! ## Zero-cost guarantee
18//!
19//! Every type in this module is `#[repr(transparent)]` over a fixed-size array
20//! or a `u32`, or is a zero-sized marker.  There is no heap allocation, no
21//! runtime dispatch, and no branch in the hot path.  The nightly features move
22//! paper-derived invariants into the *type system*, not into runtime machinery.
23//!
24//! [`petri_law`]: crate::nightly_foundry::petri_law
25//! [`powl_law`]: crate::nightly_foundry::powl_law
26//! [`evidence_law`]: crate::nightly_foundry::evidence_law
27//! [`token_law`]: crate::nightly_foundry::token_law
28
29// ─────────────────────────────────────────────────────────────────────────────
30// Surface 1: Bipartite Petri-net arc matrices  (generic_const_exprs)
31// Paper: Murata (1989) IEEE Proc. 77(4) "Petri Nets: Properties, Analysis …"
32//   §2: N = (P, T, F) is bipartite; arcs in F ⊆ (P×T) ∪ (T×P).
33//   W⁻: P×T→ℕ pre-incidence, W⁺: T×P→ℕ post-incidence.
34//   Enabling: ∀p: M[p] ≥ W⁻(p,t).  Firing: M'[p] = M[p]−W⁻(p,t)+W⁺(t,p).
35//
36// `generic_const_exprs` lets us write `[u8; P * T]` as a struct field —
37// the flat arc matrix is zero-cost and bipartite-direction-safe at the type level:
38//   PreMatrix<P, T>  ≠  PostMatrix<P, T>  (same count, opposite semantics).
39// ─────────────────────────────────────────────────────────────────────────────
40
41/// **Compile-pass law**: `Marking<P>::EMPTY` is a const-generic compile-time constant.
42///
43/// ```
44/// use wasm4pm_compat::nightly_foundry::petri_law::Marking;
45/// const M0: Marking<3> = Marking::EMPTY;
46/// assert_eq!(M0.total_tokens(), 0);
47/// let m1 = Marking([1u32, 2u32, 0u32]);
48/// assert_eq!(m1.total_tokens(), 3);
49/// ```
50///
51/// **Compile-pass law**: pre-matrix enabling check and firing are sound.
52///
53/// ```
54/// use wasm4pm_compat::nightly_foundry::petri_law::{Marking, PreMatrix, PostMatrix};
55/// // 2 places, 1 transition. p0 → t0 → p1.
56/// let mut pre = PreMatrix::<2, 1>::ZERO;
57/// pre.weights[0] = 1; // W⁻(p0,t0) = 1
58/// let mut post = PostMatrix::<2, 1>::ZERO;
59/// post.weights[1] = 1; // W⁺(t0,p1) = 1
60/// let m = Marking([1u32, 0u32]);
61/// assert!(pre.is_enabled(0, &m));
62/// let m2 = post.fire(0, m, &pre);
63/// assert_eq!(m2, Marking([0u32, 1u32]));
64/// ```
65pub mod petri_law {
66    /// Token marking of exactly `P` places — M: P → ℕ.
67    ///
68    /// Paper: Murata (1989) §2 Def. 2 — M₀ ∈ ℕᴾ.
69    /// Zero-cost: `#[repr(transparent)]` over `[u32; P]`.
70    #[repr(transparent)]
71    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
72    pub struct Marking<const P: usize>(pub [u32; P]);
73
74    impl<const P: usize> Marking<P> {
75        /// Zero marking: no tokens anywhere.
76        pub const EMPTY: Self = Self([0u32; P]);
77
78        /// Total token count across all places.
79        #[inline]
80        pub fn total_tokens(&self) -> u32 {
81            let mut s = 0u32;
82            let mut i = 0;
83            while i < P {
84                s += self.0[i];
85                i += 1;
86            }
87            s
88        }
89
90        /// Token count at place `p`. Returns `None` if `p >= P`.
91        #[must_use]
92        #[inline]
93        pub fn at(&self, p: usize) -> Option<u32> {
94            self.0.get(p).copied()
95        }
96    }
97
98    impl<const P: usize> Default for Marking<P> {
99        fn default() -> Self {
100            Self::EMPTY
101        }
102    }
103
104    /// Pre-incidence matrix W⁻: P×T→ℕ, stored flat row-major as `[u8; P * T]`.
105    ///
106    /// Paper: Murata (1989) §2 — W⁻(p,t) = arc weight from place p to transition t.
107    /// Enabling condition: `∀p: M[p] ≥ W⁻(p,t)`.
108    ///
109    /// **Requires `generic_const_exprs`**: `P * T` is a const expression in a
110    /// where-bound and in the array-length field.  Zero-cost flat array, no heap.
111    pub struct PreMatrix<const P: usize, const T: usize>
112    where
113        [(); P * T]: Sized,
114    {
115        /// Row-major weights; index `p * T + t`.
116        pub weights: [u8; P * T],
117    }
118
119    impl<const P: usize, const T: usize> PreMatrix<P, T>
120    where
121        [(); P * T]: Sized,
122    {
123        /// Zero arc-weight matrix.
124        pub const ZERO: Self = Self {
125            weights: [0u8; P * T],
126        };
127
128        /// Arc weight W⁻(p, t).
129        #[inline]
130        pub fn w(&self, p: usize, t: usize) -> u8 {
131            self.weights[p * T + t]
132        }
133
134        /// Is transition `t` enabled in marking `m`?
135        ///
136        /// Paper: Murata §2 Rule 1 — t is enabled iff `∀p: M[p] ≥ W⁻(p,t)`.
137        #[inline]
138        pub fn is_enabled(&self, t: usize, m: &Marking<P>) -> bool {
139            (0..P).all(|p| m.0[p] >= self.weights[p * T + t] as u32)
140        }
141    }
142
143    impl<const P: usize, const T: usize> Default for PreMatrix<P, T>
144    where
145        [(); P * T]: Sized,
146    {
147        fn default() -> Self {
148            Self::ZERO
149        }
150    }
151
152    /// Post-incidence matrix W⁺: T×P→ℕ, stored flat row-major as `[u8; T * P]`.
153    ///
154    /// Paper: Murata §2 — W⁺(t,p) = arc weight from transition t to place p.
155    ///
156    /// Note: `PostMatrix<P,T>` and `PreMatrix<P,T>` are **distinct types** even
157    /// though `P*T == T*P` arithmetically.  The bipartite direction is in the type.
158    pub struct PostMatrix<const P: usize, const T: usize>
159    where
160        [(); T * P]: Sized,
161    {
162        /// Row-major weights; index `t * P + p`.
163        pub weights: [u8; T * P],
164    }
165
166    impl<const P: usize, const T: usize> PostMatrix<P, T>
167    where
168        [(); T * P]: Sized,
169    {
170        /// Zero arc-weight matrix.
171        pub const ZERO: Self = Self {
172            weights: [0u8; T * P],
173        };
174
175        /// Arc weight W⁺(t, p).
176        #[inline]
177        pub fn w(&self, t: usize, p: usize) -> u8 {
178            self.weights[t * P + p]
179        }
180
181        #[cfg(not(feature = "bcinr_engine"))]
182        #[inline]
183        pub fn fire(&self, t: usize, m: Marking<P>, pre: &PreMatrix<P, T>) -> Marking<P>
184        where
185            [(); P * T]: Sized,
186        {
187            let mut next = m;
188            let mut p = 0;
189            while p < P {
190                next.0[p] =
191                    next.0[p] - pre.weights[p * T + t] as u32 + self.weights[t * P + p] as u32;
192                p += 1;
193            }
194            next
195        }
196
197        #[cfg(feature = "bcinr_engine")]
198        #[inline]
199        pub fn fire(&self, t: usize, m: Marking<P>, pre: &PreMatrix<P, T>) -> Marking<P>
200        where
201            [(); P * T]: Sized,
202        {
203            let mut in_mask = 0u64;
204            let mut out_mask = 0u64;
205            let mut state_mask = 0u64;
206
207            let mut p = 0;
208            while p < P && p < 64 {
209                if pre.weights[p * T + t] > 0 {
210                    in_mask |= 1 << p;
211                }
212                if self.weights[t * P + p] > 0 {
213                    out_mask |= 1 << p;
214                }
215                if m.0[p] > 0 {
216                    state_mask |= 1 << p;
217                }
218                p += 1;
219            }
220
221            let missing_tokens = (!state_mask) & in_mask;
222            let diff_non_zero_msb = (missing_tokens | missing_tokens.wrapping_neg()) >> 63;
223            let exec_mask = diff_non_zero_msb.wrapping_sub(1);
224            let new_state_mask = (state_mask & !(in_mask & exec_mask)) | (out_mask & exec_mask);
225
226            let mut next = m;
227            p = 0;
228            while p < P && p < 64 {
229                let has_token = (new_state_mask >> p) & 1;
230                next.0[p] = has_token as u32; // Simplified binary marking mapping
231                p += 1;
232            }
233            next
234        }
235    }
236
237    impl<const P: usize, const T: usize> Default for PostMatrix<P, T>
238    where
239        [(); T * P]: Sized,
240    {
241        fn default() -> Self {
242            Self::ZERO
243        }
244    }
245}
246
247// ─────────────────────────────────────────────────────────────────────────────
248// Surface 2: Typed POWL nodes  (adt_const_params)
249// Paper: Kourani (arXiv:2505.07052) §3 — POWL recursive grammar:
250//   POWL ::= A | γ(M₁, ..., Mₙ) | P(M⁺, ≺) | τ
251//
252// `adt_const_params` + `ConstParamTy` let an enum variant become a const
253// generic: `TypedNode<{ PowlKind::Atom }>` vs `TypedNode<{ PowlKind::Partial }>`.
254// The compiler rejects calling atom-only APIs on a partial-order node.
255// Zero-cost: KIND is fully erased at runtime; the struct is just a `u32` id.
256// ─────────────────────────────────────────────────────────────────────────────
257
258/// **Compile-fail law**: an `Atom` node must NOT expose the partial-order API.
259///
260/// The `compile_fail` annotation verifies that the type system refuses the call.
261/// This module is always compiled (the crate is nightly-only; no cfg gate).
262///
263/// ```compile_fail
264/// use wasm4pm_compat::nightly_foundry::powl_law::TypedNode;
265/// let atom = TypedNode::atom(1u32);
266/// // E0599: no method `are_concurrent` found for `TypedNode<{PowlKind::Atom}>`
267/// let _ = atom.are_concurrent(&[], 1, 2);
268/// ```
269///
270/// **Compile-fail law**: `Atom` and `Silent` are distinct types; assignment must fail.
271///
272/// ```compile_fail
273/// use wasm4pm_compat::nightly_foundry::powl_law::{TypedNode, PowlKind};
274/// // E0308: mismatched types — `TypedNode<{Atom}>` ≠ `TypedNode<{Silent}>`
275/// let _: TypedNode<{ PowlKind::Silent }> = TypedNode::atom(0u32);
276/// ```
277///
278/// **Compile-pass law**: a well-formed atom node is admitted.
279///
280/// ```
281/// use wasm4pm_compat::nightly_foundry::powl_law::TypedNode;
282/// let a = TypedNode::atom(42u32);
283/// assert!(a.is_observable());
284/// assert_eq!(a.id(), 42);
285/// ```
286pub mod powl_law {
287    use core::marker::ConstParamTy;
288
289    /// POWL fragment kind — used as a const generic parameter.
290    ///
291    /// Paper: Kourani (2505.07052) §3.
292    #[derive(Debug, Clone, Copy, PartialEq, Eq, ConstParamTy)]
293    pub enum PowlKind {
294        /// Atom: single activity node (leaf), observable.
295        Atom,
296        /// Choice Graph: generalizes choice and loops into a unified structure.
297        ChoiceGraph,
298        /// Partial order: DAG of children with precedence edges.
299        Partial,
300        /// Silent step: tau, no observable activity.
301        Silent,
302    }
303
304    /// A POWL node with its fragment kind encoded at the type level.
305    ///
306    /// `KIND` is erased at runtime — the value is just a `u32` id.
307    /// Fragment-specific APIs are only available on the correct variant.
308    #[repr(transparent)]
309    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
310    pub struct TypedNode<const KIND: PowlKind>(pub u32);
311
312    // ── Atom ──────────────────────────────────────────────────────────────────
313    impl TypedNode<{ PowlKind::Atom }> {
314        #[inline]
315        pub const fn atom(id: u32) -> Self {
316            Self(id)
317        }
318        /// Atoms are always observable (carry an activity label).
319        #[inline]
320        pub const fn is_observable(&self) -> bool {
321            true
322        }
323    }
324
325    // ── Silent ────────────────────────────────────────────────────────────────
326    impl TypedNode<{ PowlKind::Silent }> {
327        #[inline]
328        pub const fn silent(id: u32) -> Self {
329            Self(id)
330        }
331        /// Silent steps are never observable.
332        #[inline]
333        pub const fn is_observable(&self) -> bool {
334            false
335        }
336    }
337
338    // ── Partial order ─────────────────────────────────────────────────────────
339
340    /// Precedence edge a ≺ b within a POWL partial-order node.
341    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
342    pub struct OrderEdge {
343        pub before: u32,
344        pub after: u32,
345    }
346
347    impl TypedNode<{ PowlKind::Partial }> {
348        #[inline]
349        pub const fn partial(id: u32) -> Self {
350            Self(id)
351        }
352
353        /// Are `a` and `b` concurrent (neither precedes the other)?
354        /// Paper: Kourani §3 — concurrency = absence of precedence in both directions.
355        #[inline]
356        pub fn are_concurrent(&self, edges: &[OrderEdge], a: u32, b: u32) -> bool {
357            let ab = edges.iter().any(|e| e.before == a && e.after == b);
358            let ba = edges.iter().any(|e| e.before == b && e.after == a);
359            !ab && !ba
360        }
361    }
362
363    // ── Choice Graph ─────────────────────────────────────────────────────────
364    impl TypedNode<{ PowlKind::ChoiceGraph }> {
365        #[inline]
366        pub const fn choice_graph(id: u32) -> Self {
367            Self(id)
368        }
369    }
370
371    // ── Universal id accessor (macro avoids repeated `where` complexity) ──────
372    macro_rules! impl_id {
373        ($kind:expr) => {
374            impl TypedNode<{ $kind }> {
375                #[inline]
376                pub const fn id(&self) -> u32 {
377                    self.0
378                }
379            }
380        };
381    }
382    impl_id!(PowlKind::Atom);
383    impl_id!(PowlKind::Silent);
384    impl_id!(PowlKind::Partial);
385    impl_id!(PowlKind::ChoiceGraph);
386}
387
388// ─────────────────────────────────────────────────────────────────────────────
389// Surface 3: Evidence-kind label via specialization  (min_specialization)
390// Doctrine: Blue River Dam — `Admitted` and `Raw` are first-class, distinct states.
391//
392// The blanket impl gives every T the label "raw".
393// The specialised impl overrides that for T: AdmittedMarker to "admitted".
394// Resolution is at compile time: no vtable, no branch, no heap.
395// ─────────────────────────────────────────────────────────────────────────────
396
397pub mod evidence_law {
398    /// Compile-time evidence-kind label — `"raw"` or `"admitted"`.
399    ///
400    /// Uses `min_specialization` to override the blanket `"raw"` impl
401    /// with `"admitted"` for any `Admitted<T>` wrapper — resolved at compile
402    /// time with no vtable and no branch.
403    pub trait EvidenceKind {
404        fn kind_label(&self) -> &'static str;
405    }
406
407    // Blanket: every T that is not Admitted<_> is "raw".
408    impl<T> EvidenceKind for T {
409        default fn kind_label(&self) -> &'static str {
410            "raw"
411        }
412    }
413
414    /// Newtype wrapper that marks a value as having crossed a named boundary.
415    /// Zero-cost: `#[repr(transparent)]` — same ABI as `T`.
416    #[repr(transparent)]
417    pub struct Admitted<T>(pub T);
418
419    // Specialization on the concrete type constructor `Admitted<T>`.
420    // `min_specialization` allows this because `Admitted<T>` is strictly
421    // more specific than the blanket `T` — it narrows on the type constructor,
422    // not on an arbitrary trait bound.
423    impl<T> EvidenceKind for Admitted<T> {
424        fn kind_label(&self) -> &'static str {
425            "admitted"
426        }
427    }
428}
429
430// ─────────────────────────────────────────────────────────────────────────────
431// Surface 4: SIMD token-enabling check  (portable_simd)
432// Paper: Murata (1989) §2 Rule 1 — t is enabled iff ∀p: M[p] ≥ W⁻(p,t).
433//
434// With portable_simd we check 4 or 8 places at once via u32x4 / u32x8.
435// For small Petri subnets this is the entire enabling condition in one
436// SIMD lane comparison + mask reduction — zero branches, no heap.
437// ─────────────────────────────────────────────────────────────────────────────
438
439pub mod token_law {
440    use core::simd::{cmp::SimdPartialOrd, u32x4, u32x8};
441
442    /// Check enabling for a 4-place subnet — single SIMD vector comparison.
443    ///
444    /// Returns `true` iff ∀p ∈ {0..4}: `marking[p] >= pre_weights[p]`.
445    #[inline]
446    pub fn transition_enabled_4(marking: [u32; 4], pre_weights: [u32; 4]) -> bool {
447        u32x4::from_array(marking)
448            .simd_ge(u32x4::from_array(pre_weights))
449            .all()
450    }
451
452    /// Check enabling for an 8-place subnet.
453    #[inline]
454    pub fn transition_enabled_8(marking: [u32; 8], pre_weights: [u32; 8]) -> bool {
455        u32x8::from_array(marking)
456            .simd_ge(u32x8::from_array(pre_weights))
457            .all()
458    }
459
460    /// Fire a transition on a 4-place marking via SIMD arithmetic.
461    ///
462    /// Paper: Murata §2 Rule 2 — `M'[p] = M[p] − W⁻[p] + W⁺[p]`.
463    /// **Requires `transition_enabled_4` was true.** No runtime check.
464    #[inline]
465    pub fn fire_4(marking: [u32; 4], pre: [u32; 4], post: [u32; 4]) -> [u32; 4] {
466        (u32x4::from_array(marking) - u32x4::from_array(pre) + u32x4::from_array(post)).to_array()
467    }
468}
469
470// ─────────────────────────────────────────────────────────────────────────────
471// Surface 5: Witness family batch check  (portable_simd + adt_const_params)
472//
473// `WitnessFamily` now derives `ConstParamTy`, so each variant is a `u8`-ordinal
474// value. We pack up to 8 family tags into a `u8x8` SIMD lane and compare all at
475// once — 8 comparisons in one instruction on architectures that support SIMD.
476//
477// Use case: checking that all witnesses in a `GraduationCandidate` belong to the
478// same family (e.g. all `Paper`) before graduation — zero runtime cost beyond the
479// SIMD load/compare/bitmask sequence.
480// ─────────────────────────────────────────────────────────────────────────────
481
482/// Batch family-membership check for up to 8 witness family tags via SIMD.
483///
484/// Each `WitnessFamily` value is cast to its `u8` ordinal. All 8 are loaded into
485/// a `u8x8` SIMD vector and compared against `target` in one operation.
486/// The result is a bitmask: bit `i` is set iff `families[i] == target`.
487///
488/// On x86-64 with SSE2 this is a single `pcmpeqb` + `pmovmskb` pair.
489/// On aarch64 with NEON it is `vceqq_u8` + `vmovmaskq_u8`.
490///
491/// # Examples
492///
493/// ```
494/// use wasm4pm_compat::nightly_foundry::families_match_simd;
495/// use wasm4pm_compat::witness::WitnessFamily;
496///
497/// let all_paper = [WitnessFamily::Paper; 8];
498/// let mask = families_match_simd(all_paper, WitnessFamily::Paper);
499/// assert_eq!(mask, 0b1111_1111u8); // all 8 match
500///
501/// let mixed = [
502///     WitnessFamily::Paper, WitnessFamily::Standard,
503///     WitnessFamily::Paper, WitnessFamily::Paper,
504///     WitnessFamily::Standard, WitnessFamily::Paper,
505///     WitnessFamily::Paper, WitnessFamily::Paper,
506/// ];
507/// let mask = families_match_simd(mixed, WitnessFamily::Paper);
508/// assert_eq!(mask, 0b1110_1101u8); // bits 1 and 4 unset (Standard slots)
509/// ```
510pub fn families_match_simd(
511    families: [crate::witness::WitnessFamily; 8],
512    target: crate::witness::WitnessFamily,
513) -> u8 {
514    use core::simd::{cmp::SimdPartialEq, u8x8};
515    let fam_vec = u8x8::from_array(families.map(|f| f as u8));
516    let target_vec = u8x8::splat(target as u8);
517    fam_vec.simd_eq(target_vec).to_bitmask() as u8
518}
519
520// ─────────────────────────────────────────────────────────────────────────────
521// Tests — always compiled (nightly-only crate, no cfg gate required)
522// ─────────────────────────────────────────────────────────────────────────────
523
524#[cfg(test)]
525mod tests {
526    use super::*;
527
528    // petri_law ────────────────────────────────────────────────────────────────
529
530    #[test]
531    fn marking_empty_is_zero() {
532        assert_eq!(petri_law::Marking::<4>::EMPTY.total_tokens(), 0);
533    }
534
535    #[test]
536    fn pre_matrix_enables_and_blocks() {
537        // 2 places, 2 transitions.
538        // W⁻(p0,t0)=1, W⁻(p1,t1)=1; all others zero.
539        let mut pre = petri_law::PreMatrix::<2, 2>::ZERO;
540        pre.weights[0] = 1; // W⁻(p0,t0): p=0,t=0 → index p*T+t = 0*2+0 = 0
541        pre.weights[3] = 1; // W⁻(p1,t1): p=1,t=1 → index p*T+t = 1*2+1 = 3
542
543        let m = petri_law::Marking([1u32, 0u32]);
544        assert!(pre.is_enabled(0, &m)); // t0 enabled: M[p0]=1 ≥ 1
545        assert!(!pre.is_enabled(1, &m)); // t1 blocked: M[p1]=0 < 1
546    }
547
548    #[test]
549    fn firing_token_moves_correctly() {
550        // 2 places, 1 transition. p0 → t0 → p1.
551        let mut pre = petri_law::PreMatrix::<2, 1>::ZERO;
552        pre.weights[0] = 1; // W⁻(p0,t0) = 1
553        let mut post = petri_law::PostMatrix::<2, 1>::ZERO;
554        post.weights[1] = 1; // W⁺(t0,p1) = 1
555
556        let m = petri_law::Marking([1u32, 0u32]);
557        assert!(pre.is_enabled(0, &m));
558        let m2 = post.fire(0, m, &pre);
559        assert_eq!(m2, petri_law::Marking([0u32, 1u32]));
560    }
561
562    // powl_law ────────────────────────────────────────────────────────────────
563
564    #[test]
565    fn atom_observable_silent_not() {
566        assert!(powl_law::TypedNode::atom(1).is_observable());
567        assert!(!powl_law::TypedNode::silent(2).is_observable());
568    }
569
570    #[test]
571    fn partial_concurrency_correct() {
572        let p = powl_law::TypedNode::partial(0);
573        let edges = [powl_law::OrderEdge {
574            before: 1,
575            after: 2,
576        }];
577        assert!(!p.are_concurrent(&edges, 1, 2)); // 1 ≺ 2: not concurrent
578        assert!(p.are_concurrent(&edges, 1, 3)); // no edge: concurrent
579    }
580
581    // evidence_law ────────────────────────────────────────────────────────────
582
583    #[test]
584    fn raw_u32_labels_raw() {
585        use evidence_law::EvidenceKind;
586        assert_eq!(42u32.kind_label(), "raw");
587    }
588
589    #[test]
590    fn admitted_wrapper_labels_admitted() {
591        use evidence_law::{Admitted, EvidenceKind};
592        assert_eq!(Admitted(42u32).kind_label(), "admitted");
593    }
594
595    // token_law ───────────────────────────────────────────────────────────────
596
597    #[test]
598    fn simd_enabled_all_met() {
599        assert!(token_law::transition_enabled_4([5, 3, 1, 0], [1, 1, 1, 0]));
600    }
601
602    #[test]
603    fn simd_enabled_one_unmet() {
604        assert!(!token_law::transition_enabled_4([5, 0, 1, 0], [1, 1, 1, 0]));
605    }
606
607    #[test]
608    fn simd_fire_moves_tokens() {
609        let m = token_law::fire_4([2, 0, 0, 0], [1, 0, 0, 0], [0, 1, 0, 0]);
610        assert_eq!(m, [1, 1, 0, 0]);
611    }
612
613    #[test]
614    fn simd_enabled_8_all_met() {
615        assert!(token_law::transition_enabled_8(
616            [9, 8, 7, 6, 5, 4, 3, 2],
617            [1, 1, 1, 1, 1, 1, 1, 1],
618        ));
619    }
620}