Skip to main content
NM-RFC-0012

Typed collection and GF(2) artifacts

Design document · Original source

RFCs record designs and changes. A proposal appearing here does not mean its feature is ready to use. Explore current language support

Status recorded in the original: Proposed

Bound original source · SHA-256
55e1014748419ce68d4dcfb6398c36e16cc3a56c3fc4e71d849432c34d4bf584

  • Status: proposed
  • Revision: 2
  • Date: 2026-07-31
  • Feature flag: experimental.typedCollection
  • Depends on: NM-RFC-0005 typed classical values, NM-RFC-0011 measurement bindings

1. Purpose

sample K { ... } intentionally returns an aggregate histogram. Algorithms such as Simon need a different result: the ordered classical rows produced by individual shots. This RFC adds that bounded artifact without changing sample, introducing runtime-sized registers, or turning the browser runtime into a general classical language.

The accompanying gf2 host/Core module provides deterministic rank, null-space, and linear-system operations over those rows. It is a classical artifact API, not a reversible quantum operation and not callable from an oracle body.

2. Syntax and negotiation

The only 0.1 form is:

nm
@seed(41);

fn main() {
  let q: QReg<3> = qreg[3];
  collect<64> {
    H(q[0]);
    CNOT(q[0], q[1]);
    let rows: BitVec<2> = measure_all(q[0..1]);
  }
}

The parser accepts this form only when experimental.typedCollection=true is explicitly negotiated. CLI negotiation uses --experimental-typed-collection; Worker negotiation uses experimental.typedCollection=true; Playground negotiation is a default-off session toggle or a typedCollection=1 deep link.

K is a positive decimal integer literal known at compile time. Identifiers, expressions, runtime values, implicit capping, and runtime-sized results are forbidden. A program contains at most one collect<K> block.

3. Result type and measurement shape

The collection body contains exactly one measure_all binding, and that binding is the final runtime statement. Scalar measurement, syndrome measurement, a second measure_all, or a gate/control operation after the binding is rejected.

For

nm
let rows: BitVec<N> = measure_all(q[start..end]);

the result is an ordered artifact with the exact type Array<BitVec<N>,K>. Source-slice order is preserved. Each value is a zero/one string of width N; the artifact also records the binding, K, N, seed, element type, result type, and contract version.

The browser ceiling is K <= 4096. Exceeding the ceiling is an error rather than a warning or cap, because changing K would change the declared result type.

4. Determinism and runtime

An explicit @seed is mandatory. Re-running the same retained source, backend contract, feature negotiation, and seed must reproduce the ordered values byte-for-byte on that backend.

Statevector execution samples the pre-measurement state and projects only the resolved result slice. Stabilizer execution clones the pre-measurement tableau per shot and measures the same resolved slice. The artifact is retained in SimulationResult.typedCollection; aggregate histogram fields remain reserved for sample.

sample and collect cannot appear in the same program. Noise and mitigation are outside 0.1 because their trajectory and post-processing semantics for an ordered typed artifact have not been specified. They fail closed.

5. GF(2) module

The Core exports these bounded pure functions:

  • rankNMGF2(matrix)
  • nullSpaceNMGF2(matrix)
  • solveNMGF2(matrix, rightHandSide)

Entries are exactly 0 | 1; ragged matrices and invalid values are rejected. Matrices are bounded to 256 rows by 256 columns. Elimination is deterministic reduced row-echelon elimination over GF(2).

The solver is a discriminated result:

  • status: "unique" includes the unique solution;
  • status: "multiple" includes one particular solution, nullity, and a canonical null-space basis;
  • status: "inconsistent" includes coefficient rank, augmented rank, nullity, and the coefficient null-space.

A rank-deficient consistent system is never silently presented as a unique solution.

6. Diagnostics

Table 1
CodeMeaning
NM-COLLECT-001Feature negotiation is missing
NM-COLLECT-002More than one collection block
NM-COLLECT-003K is outside the fixed budget
NM-COLLECT-004sample and collect are combined
NM-COLLECT-005Result measurement shape is not exact
NM-COLLECT-006Explicit deterministic seed is missing
NM-COLLECT-007Noise or mitigation is requested

7. Export and compatibility

Printer and JSON IR preserve the collection metadata. OpenQASM 3 preview keeps the native measurement plus the strict N/M sidecar; importing the sidecar reconstructs collect<K>. Generic OpenQASM consumers do not gain a typed collection guarantee from comments alone. OpenQASM 2 and framework exports must report the native semantic gap rather than claiming preservation.

Stable parser behavior and existing sample output remain unchanged while the feature is disabled.

The dependency on NM-RFC-0011 is scoped: experimental.typedCollection=true permits its one required measure_all/BitVec<N> binding only inside the preprocessed collect<K> body. It does not negotiate a top-level or otherwise out-of-collection measurement binding; that still requires experimental.feedForward=true and fails with NM-FF-001 when absent. A typed-collection-only program carries program.typedCollection metadata but does not acquire an NM-RFC-0011 program.feedForward marker or branch record.

8. Simon boundary

This RFC closes only the ordered-shot and GF(2) post-processing blockers recorded by NM-RFC-0010. Generic Simon remains out of scope until the separate statevector representation work is complete and an end-to-end N >= 3 execution range is measured and published. The fixed-mask Pack 0.3 Simon record remains unchanged.

9. Acceptance

  • Parser, printer, JSON IR, QASM 3 sidecar, Core, CLI, Worker, and Playground carry the same fixed metadata.
  • Both local backends reproduce ordered values for a retained seed.
  • Oversized, unseeded, noisy, ambiguous, or unnegotiated programs fail closed.
  • GF(2) fixtures cover unique, multiple, and inconsistent systems.
  • No generic Simon or statevector ceiling increase is claimed by this RFC.