Skip to content

Handwired: explicit construction and behavioral checks

Can Handwired's declared numeric programs inform a bounded, independently checked route from authored state transitions to COGANT's Active Inference matrices?

Status: 2026-10-15 — provisional research and implementation guidance. Handwired inspected at 4ea7fcb27ebe93acf49b9f29a93e162b975bad46; COGANT mapping inspected at 3a9e6319bcb08390e64b1335357dbe57f8071d8b. This note is not a claim that arbitrary source translation preserves behavior. For the existing semantic interpretation, see Active Inference mapping.

What the project actually provides

The root README introduces conversion of ordinary JavaScript into a neural network. The operational documentation narrows that description: authors write JavaScript builder code that appends a fixed numeric program to a Circuit; there is no existing-JavaScript source compiler. The shared runtime executes on the CPU; the JSON-search demo has its own WebGPU path. Thus adopting the idea does not require adding a JavaScript frontend, a neural-network dependency, or a GPU backend to COGANT. README, operational introduction.

The actual instruction vocabulary is affine, ReGLU, boolean rounding, and indexed reads. Compilation groups dependency layers, eliminates operations unreachable from requested outputs, and can lower declared one-hot selections into gathers. A builder loop emits a bounded graph; it is not an unbounded runtime loop. These are construction and optimization mechanisms, not a general program-equivalence theorem. Instruction and compilation contract, runtime implementation.

The source-table API separates constants, inputs, events, and persistent state. It checks declarations, checks next-state values, and requires finite outputs. The host owns event ingestion, timing, writeback, and rendering. In the toggle example it also supplies spring matrices and decides which evaluations commit state. Consequently a circuit check alone does not validate event ordering, timing, DOM effects, or the surrounding application's behavior. Cell policies and evaluator, checked evaluation, toggle host.

Exactness and differentiation have separate contracts

Handwired's reference semantics use FP32 rounding and stored accumulation order. Equality is to that calculation, ignoring signed zero, rather than arbitrary JavaScript float64 or real arithmetic. Source ranges, grids, exact bits, and one-hot groups constrain optimizations; caller declarations are promises that require checks. Some algebraic rewrites have narrower domains than the native operations they resemble. Numerical contract, macro limits.

A reproduced counterexample is emitMaximum(2**24, -1) == 16777215, while native Math.max returns 16777216. The more restricted operation must not be described as an unrestricted replacement. Indexed reads likewise require a declared bounded integer domain for their intended table semantics; fractional inputs are not interchangeable with one-hot interpolation. Maximum implementation, index tests.

The backward pass differentiates intended arithmetic rather than literal FP32 rounding. A reached boolean decision rejects by default unless a straight-through policy is selected; an indexed read also requires an explicit gradient policy. A surrogate supplies a training convention, not the exact derivative of a hard decision. This prevents importing the README's differentiability shorthand into claims about COGANT's discrete actions or about successful learning. Backward implementation.

The useful testing pattern

Handwired separates three questions:

  1. Does the compiled executor reproduce the numeric IR? validateTensorEvaluation compares live wires with reference evaluation using exact JavaScript equality. This detects a corrupted compiled result but both evaluators consume the same constructed program. Validator.
  2. Did builder rewrites preserve their intended expressions? The differential suite records an independent expression tree before rewriting. Continuous values use a stated tolerance; boolean results require exact agreement. Seeded randomized cases exercise folding, composition, deduplication, and other rewrite shapes. Independent builder oracle, comparison policy.
  3. Does the authored program implement the intended application? The toggle test compares a separate JavaScript implementation over event traces, includes explicit expected decisions, and checks boundary coordinates and simultaneous-event ordering. It rejects an off-grid pointer input. This is stronger than executor agreement and still bounded to the exercised behavior. Toggle tests.

This layered evidence strategy is more directly reusable than the particular neural arithmetic.

Mapping to COGANT

COGANT already separates symbolic state-space compilation, numerical A/B/C/D construction, and an agent runtime. Its graph-derived matrices explicitly use heuristics; the hidden-state axis follows compiled variable nodes, not necessarily the Cartesian product of their values. The existing B builder uses write/mutate evidence and can truncate a large tensor by graph degree. An authored finite-state model therefore needs its own explicit state axis and validation contract rather than being relabeled as an exact instance of that heuristic route. State-space compiler, matrix derivation and axes, state-axis binding, B construction and truncation.

The following is a proposed implementation direction, not an observed existing capability:

Priority COGANT boundary Adaptation and acceptance condition
First statespace/ authored input Require ordered, nonempty, unique state/action/observation labels; total transition and observation kernels; an explicit prior and preferences. Preserve label order in the resulting axes. Distinguish complete state configurations from variable names.
First Explicit A/B/C/D construction Use A[observation][state], B[next_state][state][action], observation log preferences C, and initial probabilities D. Reject nonfinite/negative probabilities, unknown labels, missing cases, and incorrect probability mass. Do not silently repair a malformed kernel.
First Resource contract Check the dense allocation size before construction, including A and B. Reject an exceeded explicit-model budget. Truncation changes the modeled domain and cannot retain a claim of complete bounded coverage.
First Independent behavioral verification For every declared state/action pair, compare the resulting B column with a separately authored transition oracle. Test observation columns independently. Include a normalization-preserving wrong-successor mutation; it must pass shape/simplex checks and fail behavior checks.
Next runtime/ integration Exercise the resulting matrices through the existing raw-matrix entry point with a small event-controlled example. Keep an exhaustive kernel check separate from action selection, posterior updates, learning, and timing.
Later Export and empirical calibration Carry explicit-versus-inferred provenance and label axes into artifacts; add stochastic kernels or measured trace estimates only with their own uncertainty and data contracts. Benchmark before considering sparse execution or GPU lowering.

The matrix orientation and raw-matrix runtime entry point are already compatible with this direction. However, the runtime's transition helper normalizes results and its step also performs inference and action selection; these behaviors are not substitutes for validating the authored kernel before execution. Runtime transition, raw-matrix adapter and inference step.

For a deterministic transition function on the declared finite domain, one-hot B columns can represent the authored next-state table. Exhaustive basis-state checks establish agreement on that domain; they do not prove extraction fidelity for arbitrary repositories, preservation of external side effects, or optimal Active Inference policies. The observation model, prior, and preferences remain authored modeling decisions. A transition table alone does not identify them.

Reuse boundaries and attribution

Reuse explicit declarations, stable axes, bounded construction, separate host/runtime responsibilities, independent reference implementations, and failing corruption controls. Avoid adopting FP32-specific gates as probability arithmetic, assuming differentiability implies useful gradients, validating only normalized shapes, or importing UI behavior changes as semantics-preserving compiler optimizations. Handwired explicitly distinguishes application choices such as destination hit-testing and delayed values from behavior-preserving constructions. Behavior choices.

Handwired is MIT licensed, copyright 2026 Cheng Lou. Reusing code or substantial documentation requires retaining the copyright and permission notice. A conceptual adaptation should cite the pinned upstream work and describe what was independently implemented; no Handwired dependency or vendored source is proposed here. License.

Checks performed for this note

The pinned checkout was clean before and after validation. Bun 1.4.3 ran the actual CPU suite without installing dependencies; all task cache and temporary bindings remained on GitVault. No Python environment, GPU benchmark, browser, full lab suite, or end-to-end COGANT implementation was exercised by this research task.

Scenario Invocation from pinned Handwired checkout Binary observable Captured artifact in the COGANT project root
Runtime and application reference tests bun test tests/runtime template/toggle.test.ts Exit 0; 177 pass, 0 fail, 12 files .omo/evidence/handwired-research/cpu-tests.log and cpu-tests.exit
Non-vacuous validators and numerical limit HANDWIRED_SOURCE_ROOT="$PWD" bun ../../worktrees/cogant-handwired-20261015/.omo/evidence/handwired-research/negative-controls.ts Exit 0; corruption, invalid one-hot, and out-of-range inputs rejected; maximum counterexample reproduced .omo/evidence/handwired-research/negative-controls.ts, negative-controls.log, and negative-controls.exit

These are bounded CPU observations at the stated cut, not transferred correctness or performance results for COGANT. The evidence directory is local execution material; the durable public sources are the commit-pinned links above.