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,
295 ChoiceGraph,
296 Partial,
297 Silent,
298 Xor,
299 Loop,
300 }
301
302 /// A POWL node with its fragment kind encoded at the type level.
303 ///
304 /// `KIND` is erased at runtime — the value is just a `u32` id.
305 /// Fragment-specific APIs are only available on the correct variant.
306 #[repr(transparent)]
307 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
308 pub struct TypedNode<const KIND: PowlKind>(pub u32);
309
310 // ── Atom ──────────────────────────────────────────────────────────────────
311 impl TypedNode<{ PowlKind::Atom }> {
312 #[inline]
313 pub const fn atom(id: u32) -> Self {
314 Self(id)
315 }
316 /// Atoms are always observable (carry an activity label).
317 #[inline]
318 pub const fn is_observable(&self) -> bool {
319 true
320 }
321 }
322
323 // ── Silent ────────────────────────────────────────────────────────────────
324 impl TypedNode<{ PowlKind::Silent }> {
325 #[inline]
326 pub const fn silent(id: u32) -> Self {
327 Self(id)
328 }
329 /// Silent steps are never observable.
330 #[inline]
331 pub const fn is_observable(&self) -> bool {
332 false
333 }
334 }
335
336 // ── Partial order ─────────────────────────────────────────────────────────
337
338 /// Precedence edge a ≺ b within a POWL partial-order node.
339 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
340 pub struct OrderEdge {
341 pub before: u32,
342 pub after: u32,
343 }
344
345 impl TypedNode<{ PowlKind::Partial }> {
346 #[inline]
347 pub const fn partial(id: u32) -> Self {
348 Self(id)
349 }
350
351 /// Are `a` and `b` concurrent (neither precedes the other)?
352 /// Paper: Kourani §3 — concurrency = absence of precedence in both directions.
353 #[inline]
354 pub fn are_concurrent(&self, edges: &[OrderEdge], a: u32, b: u32) -> bool {
355 let ab = edges.iter().any(|e| e.before == a && e.after == b);
356 let ba = edges.iter().any(|e| e.before == b && e.after == a);
357 !ab && !ba
358 }
359 }
360
361 // ── Choice Graph ─────────────────────────────────────────────────────────
362 impl TypedNode<{ PowlKind::ChoiceGraph }> {
363 #[inline]
364 pub const fn choice_graph(id: u32) -> Self {
365 Self(id)
366 }
367 }
368
369 impl TypedNode<{ PowlKind::Xor }> {
370 #[inline]
371 pub const fn xor(id: u32) -> Self {
372 Self(id)
373 }
374 }
375
376 impl TypedNode<{ PowlKind::Loop }> {
377 #[inline]
378 pub const fn loop_node(id: u32) -> Self {
379 Self(id)
380 }
381 }
382
383 // ── Universal id accessor (macro avoids repeated `where` complexity) ──────
384 macro_rules! impl_id {
385 ($kind:expr) => {
386 impl TypedNode<{ $kind }> {
387 #[inline]
388 pub const fn id(&self) -> u32 {
389 self.0
390 }
391 }
392 };
393 }
394 impl_id!(PowlKind::Atom);
395 impl_id!(PowlKind::Silent);
396 impl_id!(PowlKind::Partial);
397 impl_id!(PowlKind::ChoiceGraph);
398 impl_id!(PowlKind::Xor);
399 impl_id!(PowlKind::Loop);
400}
401
402// ─────────────────────────────────────────────────────────────────────────────
403// Surface 3: Evidence-kind label via specialization (min_specialization)
404// Doctrine: Blue River Dam — `Admitted` and `Raw` are first-class, distinct states.
405//
406// The blanket impl gives every T the label "raw".
407// The specialised impl overrides that for T: AdmittedMarker to "admitted".
408// Resolution is at compile time: no vtable, no branch, no heap.
409// ─────────────────────────────────────────────────────────────────────────────
410
411pub mod evidence_law {
412 /// Compile-time evidence-kind label — `"raw"` or `"admitted"`.
413 ///
414 /// Uses `min_specialization` to override the blanket `"raw"` impl
415 /// with `"admitted"` for any `Admitted<T>` wrapper — resolved at compile
416 /// time with no vtable and no branch.
417 pub trait EvidenceKind {
418 fn kind_label(&self) -> &'static str;
419 }
420
421 // Blanket: every T that is not Admitted<_> is "raw".
422 impl<T> EvidenceKind for T {
423 default fn kind_label(&self) -> &'static str {
424 "raw"
425 }
426 }
427
428 /// Newtype wrapper that marks a value as having crossed a named boundary.
429 /// Zero-cost: `#[repr(transparent)]` — same ABI as `T`.
430 #[repr(transparent)]
431 pub struct Admitted<T>(pub T);
432
433 // Specialization on the concrete type constructor `Admitted<T>`.
434 // `min_specialization` allows this because `Admitted<T>` is strictly
435 // more specific than the blanket `T` — it narrows on the type constructor,
436 // not on an arbitrary trait bound.
437 impl<T> EvidenceKind for Admitted<T> {
438 fn kind_label(&self) -> &'static str {
439 "admitted"
440 }
441 }
442}
443
444// ─────────────────────────────────────────────────────────────────────────────
445// Surface 4: SIMD token-enabling check (portable_simd)
446// Paper: Murata (1989) §2 Rule 1 — t is enabled iff ∀p: M[p] ≥ W⁻(p,t).
447//
448// With portable_simd we check 4 or 8 places at once via u32x4 / u32x8.
449// For small Petri subnets this is the entire enabling condition in one
450// SIMD lane comparison + mask reduction — zero branches, no heap.
451// ─────────────────────────────────────────────────────────────────────────────
452
453pub mod token_law {
454 use core::simd::{cmp::SimdPartialOrd, u32x4, u32x8};
455
456 /// Check enabling for a 4-place subnet — single SIMD vector comparison.
457 ///
458 /// Returns `true` iff ∀p ∈ {0..4}: `marking[p] >= pre_weights[p]`.
459 #[inline]
460 pub fn transition_enabled_4(marking: [u32; 4], pre_weights: [u32; 4]) -> bool {
461 u32x4::from_array(marking)
462 .simd_ge(u32x4::from_array(pre_weights))
463 .all()
464 }
465
466 /// Check enabling for an 8-place subnet.
467 #[inline]
468 pub fn transition_enabled_8(marking: [u32; 8], pre_weights: [u32; 8]) -> bool {
469 u32x8::from_array(marking)
470 .simd_ge(u32x8::from_array(pre_weights))
471 .all()
472 }
473
474 /// Fire a transition on a 4-place marking via SIMD arithmetic.
475 ///
476 /// Paper: Murata §2 Rule 2 — `M'[p] = M[p] − W⁻[p] + W⁺[p]`.
477 /// **Requires `transition_enabled_4` was true.** No runtime check.
478 #[inline]
479 pub fn fire_4(marking: [u32; 4], pre: [u32; 4], post: [u32; 4]) -> [u32; 4] {
480 (u32x4::from_array(marking) - u32x4::from_array(pre) + u32x4::from_array(post)).to_array()
481 }
482}
483
484// ─────────────────────────────────────────────────────────────────────────────
485// Surface 5: Witness family batch check (portable_simd + adt_const_params)
486//
487// `WitnessFamily` now derives `ConstParamTy`, so each variant is a `u8`-ordinal
488// value. We pack up to 8 family tags into a `u8x8` SIMD lane and compare all at
489// once — 8 comparisons in one instruction on architectures that support SIMD.
490//
491// Use case: checking that all witnesses in a `GraduationCandidate` belong to the
492// same family (e.g. all `Paper`) before graduation — zero runtime cost beyond the
493// SIMD load/compare/bitmask sequence.
494// ─────────────────────────────────────────────────────────────────────────────
495
496/// Batch family-membership check for up to 8 witness family tags via SIMD.
497///
498/// Each `WitnessFamily` value is cast to its `u8` ordinal. All 8 are loaded into
499/// a `u8x8` SIMD vector and compared against `target` in one operation.
500/// The result is a bitmask: bit `i` is set iff `families[i] == target`.
501///
502/// On x86-64 with SSE2 this is a single `pcmpeqb` + `pmovmskb` pair.
503/// On aarch64 with NEON it is `vceqq_u8` + `vmovmaskq_u8`.
504///
505/// # Examples
506///
507/// ```
508/// use wasm4pm_compat::nightly_foundry::families_match_simd;
509/// use wasm4pm_compat::witness::WitnessFamily;
510///
511/// let all_paper = [WitnessFamily::Paper; 8];
512/// let mask = families_match_simd(all_paper, WitnessFamily::Paper);
513/// assert_eq!(mask, 0b1111_1111u8); // all 8 match
514///
515/// let mixed = [
516/// WitnessFamily::Paper, WitnessFamily::Standard,
517/// WitnessFamily::Paper, WitnessFamily::Paper,
518/// WitnessFamily::Standard, WitnessFamily::Paper,
519/// WitnessFamily::Paper, WitnessFamily::Paper,
520/// ];
521/// let mask = families_match_simd(mixed, WitnessFamily::Paper);
522/// assert_eq!(mask, 0b1110_1101u8); // bits 1 and 4 unset (Standard slots)
523/// ```
524pub fn families_match_simd(
525 families: [crate::witness::WitnessFamily; 8],
526 target: crate::witness::WitnessFamily,
527) -> u8 {
528 use core::simd::{cmp::SimdPartialEq, u8x8};
529 let fam_vec = u8x8::from_array(families.map(|f| f as u8));
530 let target_vec = u8x8::splat(target as u8);
531 fam_vec.simd_eq(target_vec).to_bitmask() as u8
532}
533
534// ─────────────────────────────────────────────────────────────────────────────
535// Tests — always compiled (nightly-only crate, no cfg gate required)
536// ─────────────────────────────────────────────────────────────────────────────
537
538#[cfg(test)]
539mod tests {
540 use super::*;
541
542 // petri_law ────────────────────────────────────────────────────────────────
543
544 #[test]
545 fn marking_empty_is_zero() {
546 assert_eq!(petri_law::Marking::<4>::EMPTY.total_tokens(), 0);
547 }
548
549 #[test]
550 fn pre_matrix_enables_and_blocks() {
551 // 2 places, 2 transitions.
552 // W⁻(p0,t0)=1, W⁻(p1,t1)=1; all others zero.
553 let mut pre = petri_law::PreMatrix::<2, 2>::ZERO;
554 pre.weights[0] = 1; // W⁻(p0,t0): p=0,t=0 → index p*T+t = 0*2+0 = 0
555 pre.weights[3] = 1; // W⁻(p1,t1): p=1,t=1 → index p*T+t = 1*2+1 = 3
556
557 let m = petri_law::Marking([1u32, 0u32]);
558 assert!(pre.is_enabled(0, &m)); // t0 enabled: M[p0]=1 ≥ 1
559 assert!(!pre.is_enabled(1, &m)); // t1 blocked: M[p1]=0 < 1
560 }
561
562 #[test]
563 fn firing_token_moves_correctly() {
564 // 2 places, 1 transition. p0 → t0 → p1.
565 let mut pre = petri_law::PreMatrix::<2, 1>::ZERO;
566 pre.weights[0] = 1; // W⁻(p0,t0) = 1
567 let mut post = petri_law::PostMatrix::<2, 1>::ZERO;
568 post.weights[1] = 1; // W⁺(t0,p1) = 1
569
570 let m = petri_law::Marking([1u32, 0u32]);
571 assert!(pre.is_enabled(0, &m));
572 let m2 = post.fire(0, m, &pre);
573 assert_eq!(m2, petri_law::Marking([0u32, 1u32]));
574 }
575
576 // powl_law ────────────────────────────────────────────────────────────────
577
578 #[test]
579 fn atom_observable_silent_not() {
580 assert!(powl_law::TypedNode::atom(1).is_observable());
581 assert!(!powl_law::TypedNode::silent(2).is_observable());
582 }
583
584 #[test]
585 fn partial_concurrency_correct() {
586 let p = powl_law::TypedNode::partial(0);
587 let edges = [powl_law::OrderEdge {
588 before: 1,
589 after: 2,
590 }];
591 assert!(!p.are_concurrent(&edges, 1, 2)); // 1 ≺ 2: not concurrent
592 assert!(p.are_concurrent(&edges, 1, 3)); // no edge: concurrent
593 }
594
595 // evidence_law ────────────────────────────────────────────────────────────
596
597 #[test]
598 fn raw_u32_labels_raw() {
599 use evidence_law::EvidenceKind;
600 assert_eq!(42u32.kind_label(), "raw");
601 }
602
603 #[test]
604 fn admitted_wrapper_labels_admitted() {
605 use evidence_law::{Admitted, EvidenceKind};
606 assert_eq!(Admitted(42u32).kind_label(), "admitted");
607 }
608
609 // token_law ───────────────────────────────────────────────────────────────
610
611 #[test]
612 fn simd_enabled_all_met() {
613 assert!(token_law::transition_enabled_4([5, 3, 1, 0], [1, 1, 1, 0]));
614 }
615
616 #[test]
617 fn simd_enabled_one_unmet() {
618 assert!(!token_law::transition_enabled_4([5, 0, 1, 0], [1, 1, 1, 0]));
619 }
620
621 #[test]
622 fn simd_fire_moves_tokens() {
623 let m = token_law::fire_4([2, 0, 0, 0], [1, 0, 0, 0], [0, 1, 0, 0]);
624 assert_eq!(m, [1, 1, 0, 0]);
625 }
626
627 #[test]
628 fn simd_enabled_8_all_met() {
629 assert!(token_law::transition_enabled_8(
630 [9, 8, 7, 6, 5, 4, 3, 2],
631 [1, 1, 1, 1, 1, 1, 1, 1],
632 ));
633 }
634}