Skip to content
PL & Formal Methods · Verification & Testing

Verification, Property Testing & Benchmarks

Weyl’s five-layer verification pyramid, property-based testing of algebraic normal forms, cross-backend differential testing, error-lattice checks, mutation testing, and Criterion benchmarks.

Weyl’s trusted computing base (TCB) is organized around a small trusted kernel, independent oracles, and deterministic replay. Because physical derivations span symbolic algebra, multi-precision numerical perturbation theory, and universal theorem proving, no single testing layer suffices. Weyl structures verification as a five-layer pyramid—from millisecond PR checks to nightly end-to-end physics runs—reinforced by mutation testing, replay auditing, and performance regression gates.

Five-Layer Verification Pyramid ​

The first three layers run on every Pull Request for fast feedback; the top two run nightly and before releases to validate full physical workflows:

LayerScopeTooling & HarnessCadence
L1 Unit & PropertyAlgebra axioms, Fp\mathbb{F}_p arithmetic, CRT/Wang reconstruction, error-lattice lawsproptest, dense matrices (≤6\le 6 qubits)Every PR
L2 Frontend & TypesParser fuzzing, diagnostic snapshots, positive/negative T-rule tests, type-checker matrix oraclecargo-fuzz, insta, random programs (≤10\le 10 qubits)Every PR
L3 Differential Kernelweyl-cas sort-merge vs naive hash table; spill vs RAM; 1/4/641/4/64-thread byte equalityCustom differential driverEvery PR (small scale)
L4 Physical Gold StandardsStage A free-fermion exact comparison to order 14; literature pCUT tables; D(Z2)D(\mathbb{Z}_2) modular dataCanonical text + SHA-256 hashesNightly
L5 Oracles & TheoremsStage B double-double ED residual slopes; end-to-end weylc run; Lean 4 proof re-checkingweyl-oracle, weyl-leanNightly / Release

Static Type Checking and Frontend Testing (L2) ​

Frontend verification tests the behavior and physics diagnostics of λWeyl\lambda_{\mathrm{Weyl}} rules on concrete cases (note that static type checking is incomplete by design, and testing does not replace a formal soundness proof; see Type System §8). Every typing rule in weyl-types (T-Ham, T-Bdy, T-Pcut, T-Braid, T-Solve, and others) is exercised by both positive tests and at least one rejected program—such as anti-Hermitian products triggering E0301, non-commuting H0H_0 triggering E0413, or extrapolated scalars in exact claims triggering E0330—with both human diagnostics and machine-readable JSON proof chains locked by insta snapshots. Beyond hand-crafted cases, a differential matrix oracle expands randomly generated small programs (≤10\le 10 qubits, plus non-abelian G∈{S3,D4,Q8}G \in \{S_3, D_4, Q_8\}) into dense matrices to independently verify every static claim of Hermiticity, commutation, anyon charge, and conserved stabilizer set Cons(H)\mathrm{Cons}(H). In parallel, cargo-fuzz continuously feeds arbitrary byte streams into the lexer and parser to ensure panic-free recovery and valid UTF-8 span slicing.

rust
#[test]
fn type_checker_soundness_vs_dense_matrix_oracle() {
    for seed in 0..256u64 {
        let prog = random_local_hamiltonian(/*n_qubits=*/ 8, seed);
        let typed = weyl_types::check_program(&prog).expect("well-typed random model");
        let h_mat = expand_to_dense_matrix(&prog.hamiltonian);
        // Static Herm guarantee => exact matrix equality H == H†
        if typed.herm == Herm::Herm {
            assert_eq!(h_mat, h_mat.conjugate_transpose());
        }
        // Static Cons(H) => exact zero commutator with H
        for stab in typed.conserved_stabilizers() {
            let s_mat = expand_to_dense_matrix(stab);
            assert!(is_zero_matrix(&(h_mat.mul(&s_mat) - s_mat.mul(&h_mat))));
        }
    }
}

Property-Based Testing of Algebraic Normal Forms (L1) ​

Core algebraic laws in weyl-canonical and weyl-num are tested across thousands of randomly generated words and coefficient vectors using proptest:

rust
proptest! {
    #[test]
    fn graded_algebra_axioms(a in arb_pauli_word(6), b in arb_pauli_word(6), c in arb_pauli_word(6)) {
        // 1. Associativity: (a * b) * c == a * (b * c) including Z_4 global phase
        prop_assert_eq!(mul_word(&mul_word(&a, &b), &c), mul_word(&a, &mul_word(&b, &c)));
        // 2. Adjoint involution: (a * b)† == b† * a†
        prop_assert_eq!(adjoint(&mul_word(&a, &b)), mul_word(&adjoint(&b), &adjoint(&a)));
        // 3. Exact element-wise agreement with 2^6 × 2^6 dense matrix multiplication
        prop_assert_eq!(to_dense(&mul_word(&a, &b)), dense_matmul(&to_dense(&a), &to_dense(&b)));
    }
}

For linear combinations under the Lie bracket [a,b]=ab−ba[a, b] = ab - ba, property tests additionally verify distributivity and the Jacobi identity:

[a,[b,c]]+[b,[c,a]]+[c,[a,b]]=0[a, [b, c]] + [b, [c, a]] + [c, [a, b]] = 0

In weyl-num, property suites validate 63-bit prime-field (Fp\mathbb{F}_p) axioms, centered multi-prime CRT recovery, and uniqueness of Wang’s rational reconstruction whenever M>2NDM > 2ND.

Cross-Backend Differential Testing (L3–L5) ​

Weyl requires outputs to be independent of execution path and concurrency level, and differential testing enforces this requirement across three boundaries. At Layer 3, weyl-cas maintains a simple hash-table reference normalize_naive; for any generated multiset of terms, the differential driver compares normalize_naive against pure in-memory radix sort-merge, a tiny MemBudget forcing multi-way NVMe disk spills, and 1/4/641/4/64-thread parallel runs, asserting byte-for-byte identical output streams across all four.

At Layer 4, the 2D Toric Code Stage A benchmark serves as an exact analytical oracle: its free-fermion solution gives dispersion ω(k)=21+x2−2xcos⁡k\omega(k) = 2\sqrt{1 + x^2 - 2x\cos k} and ground-state energy e0=−12π∫02π1+x2−2xcos⁡k dke_0 = -\frac{1}{2\pi}\int_0^{2\pi}\sqrt{1 + x^2 - 2x\cos k}\,dk, against which all pCUT rational series coefficients tδt_\delta and e0e_0 up to order 14 are compared term-by-term with zero tolerance. For non-integrable Stage B perturbations at Layer 5, weyl-oracle constructs an independent double-double (~106-bit significand) Lanczos MatVec directly from the raw HIR Hamiltonian without reusing pCUT stabilizer maps; along fixed rays (x,κ1,κ2)=t(α,β1,β2)(x, \kappa_1, \kappa_2) = t(\alpha, \beta_1, \beta_2), it checks that the log-log residual slope matches the first omitted order r<Lr < L within a tolerance of 0.30.3, returning Inconclusive whenever numerical noise or finite-size wrapping interferes.

Below is the L3 differential driver comparing naive, pure-RAM, spilled, and multi-threaded runs, followed by L5 oracle telemetry:

rust
#[test]
fn differential_sort_merge_vs_naive_spill_and_threads() {
    let raw = generate_random_terms(50_000, /*n_primes=*/ 4, /*seed=*/ 0x5745_594c);
    let expected = normalize_naive(&raw);

    // 1. Pure in-memory sort-merge (1 thread vs 8 threads)
    let ram_1t = normalize_with(&raw, MemBudget { max_bytes: 256 << 20 }, None, 1);
    let ram_8t = normalize_with(&raw, MemBudget { max_bytes: 256 << 20 }, None, 8);
    // 2. Tiny budget (64 KiB) forcing multi-way NVMe disk spill + loser-tree merge
    let spilled = normalize_with(&raw, MemBudget { max_bytes: 64 << 10 }, Some(tmp_dir()), 4);

    assert_eq!(ram_1t.as_wire_bytes(), expected.as_wire_bytes());
    assert_eq!(ram_8t.as_wire_bytes(), expected.as_wire_bytes());
    assert_eq!(spilled.as_wire_bytes(), expected.as_wire_bytes());
}

When an L5 oracle detects a mismatch, it emits structured telemetry with deterministic hints (generated strictly by compiler rules such as newly appearing cluster lengths, never by an LLM):

json
{
  "schema": "weyl.telemetry",
  "run_id": "r-000173",
  "node": "cluster.eval",
  "status": "oracle_failed",
  "ir": { "layer": "KIR", "terms_peak": 48211033, "bytes_peak": 21474836480, "spill_bytes": 0 },
  "oracle": {
    "kind": "ed",
    "verdict": "fail",
    "observable": "gap",
    "residual_slope": 8.9,
    "expected_slope": 13.0,
    "precision": "double-double",
    "size_L": 16,
    "first_bad_order": 8
  },
  "hints": ["terms at order 8 involve clusters of length 9 for the first time"]
}

Error-Lattice Soundness Checks ​

Dedicated property suites audit the error lattice E=I×Pfin(Src)\mathbb{E} = \mathcal{I} \times \mathcal{P}_{\mathrm{fin}}(\mathrm{Src}). They verify reflexivity, antisymmetry, and transitivity of ⊑\sqsubseteq, together with monotonicity of ⊕\oplus and valuation-aware ⊛\circledast, and confirm that monomial ideals remain minimal Dickson-basis antichains with no redundant generators after every merge. Crucially, the suites enforce a no-silent-downgrade invariant: passing an ED oracle, Padé extrapolation, or e-graph rewrite can never downgrade Trunc or Epi back to Exact, and any value carrying a non-empty epistemic set EE is statically rejected by exact claim a = b (E0330).

rust
proptest! {
    #[test]
    fn error_lattice_no_silent_downgrade(e1 in arb_err(), e2 in arb_err(), v1 in 0u32..4, v2 in 0u32..4) {
        let sum = add_err(&e1, &e2);
        let prod = mul_err(&e1, v1, &e2, v2);
        // Epistemic provenance sets are monotonically non-decreasing under all ops
        prop_assert!(e1.epi.is_subset(&sum.epi) && e2.epi.is_subset(&sum.epi));
        prop_assert!(e1.epi.is_subset(&prod.epi) && e2.epi.is_subset(&prod.epi));
        // Any non-Exact input prevents the sum from ever collapsing back to Exact
        if !e1.is_exact() || !e2.is_exact() {
            prop_assert!(!sum.is_exact());
        }
    }
}

Mutation Testing: Auditing the Oracles ​

To verify that the oracles genuinely detect subtle kernel bugs, weyl/crates/weylc/tests/mutations.rs injects controlled faults and asserts that Layer 4 or Layer 5 fails with an accurate first_bad_order diagnostic:

Injected FaultAlgebraic / Physical BreakageCatching LayerDiagnostic Requirement
Flip sign of a single pCUT C(m)C(m)Corrupts order-kk effective HamiltonianL4 / L5oracle_failed with first_bad_order == k
Drop all clusters of length ℓ\ellBreaks linked-cluster additivity at order ℓ−1\ell - 1L4 / L5first_bad_order matches first order using ℓ\ell
Corrupt one Pauli 3×33 \times 3 phase entryBreaks local commutation & adjoint phaseL1 / L4Fails both dense-matrix and free-fermion checks
Omit one stabilizer generatorCorrupts sector energy function Q(s,ℓ)Q(s, \ell)L4 / L5ED residual slope deviates from expected rr

Scheduler Equivalence & Deterministic Replay

Running the same derivation under the built-in heuristic scheduler, a random scheduler, and the LLM MCP scheduler must produce byte-identical published results. Nightly CI also replays every append-only action log via weylc replay <log> to confirm identical output hashes, and re-checks all Lean 4 theorem certificates against pinned Mathlib revisions.

Performance Regression Benchmarks (weyl/benches/) ​

Weyl tracks three hot-path metrics via criterion, recorded in weyl/benches/baseline.json; any PR regressing a core metric by more than 10% blocks merge:

BenchmarkTarget CrateReference BaselineThroughput / Memory Ceiling
merge/normalize_1M_terms_single_coreweyl-cas stream sort-merge82.89 ms≈1.21×107\approx 1.21 \times 10^7 terms/s single-core (target ≥107\ge 10^7/s); 10810^8 terms ≤64 GB\le 64\text{ GB} RAM
pcut/tables_dq_2_order_8weyl-series flow recursion1.71 msExact Q\mathbb{Q} memoized table generation + disk cache
lanczos/step_L10_W2_ddweyl-oracle double-double MatVec6.28 ms106-bit significand single-sector Lanczos iteration
bash
# Run all unit and proptest property suites (L1–L3)
cargo test --workspace

# Run mutation tests to verify oracle fault detection
cargo test -p weylc --test mutations

# Replay a nightly action log and verify byte-identical output hashes
weylc replay logs/nightly-stage-b.jsonl --verify-hash

# Run Criterion benchmarks against weyl/benches/baseline.json (>10% regression blocks merge)
cargo bench --workspace

CI and Release Gate Checklist ​

Every merge and release enforces tiered verification gates. Pull requests must clear the merge gate, which runs the L1 property suites, L2 positive and negative type snapshots, L3 term-stream differential tests, and Criterion benchmarks with regressions bounded by ≤10%\le 10\%. The nightly gate escalates to the L4 Stage A 14th-order free-fermion zero-tolerance check, L5 Stage B double-double ED residual slopes, the full mutation suite, and the weylc replay determinism audit. Finally, the release gate requires full Lean 4 re-verification of all built-in theorems (modular_relations, ssb_boundary, twisted_boundary) on pinned Mathlib, alongside byte-identical equivalence across the heuristic, random, and LLM schedulers.

Weyl v0.1 · MIT License