btwave: Balanced-Ternary Harmonic Waveguide and Give-Before-Take Compute Engine (Contract P0)
native/btwave/ is a 100% pure seeded OM-2 (om2) compute, transport, admission, and verification
stack compiled directly to static Linux AArch64 machine code by the 3-stage seeded Omega compiler
(omc). It contains zero C, C++, Rust, Python, or shell implementation or harness code.
Scope and Lineage
| Item | Pin / Value |
|---|---|
| Source modules | native/btwave/trit.om, native/btwave/ledger.om, native/btwave/wave_ipc.om, native/btwave/main.om |
| Pure OM-2 gate runner | native/btwave/gate.om (concatenated after native/btwave/trit.om) |
| Root bootstrap seed | omega-mv seed/rung0/seed0.hex sha256 baaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d |
| Seeded compiler source | omega-mv 713c9c079c2d97b58a2832495ddc7a374d462758 seed/omc/omc.om sha256 c86159627820cf5741be0a2a4c05df0efb78f5c91a652b986fec5d745baa62ed |
Pinned omc binary | 3-stage fixpoint seed/out/omc sha256 f4fa7951816bbd09c5eaaae6692852a70c3c305164b365027c5b683dec7d63e9 |
| Product source stream | cat trit.om ledger.om wave_ipc.om main.om sha256 29de9fda42b04b1bf51b459a0bc4612fdcfa7f93d192d0f6ad3bdd9454191689 |
| Product ELF binary | sha256 583209bf9bcf8dda9a3a976e2e45e4d19ac6cdd28a0b2dbe7e1147deb9d975a2 (79,472 B MEASURED, 3x deterministic) |
| Wolfram trace digest | b0c6399a7ae894148e8e1678a272add68385bdf67d6221044ded82216fb73575 (evidence/BTWAVE-P0/expected-trace.out) |
Non-Binary Balanced-Ternary Algebra (native/btwave/trit.om)
- SWAR 32-Trit Packed Representation (
Trit32):- Packs
32balanced trits in{-1, 0, +1}into oneulong(64 bits,2.0 bits/tritMODELED): upper32 bitshold positive carrier maskpos32, lower32 bitshold negative carrier maskneg32. - Declared as
abstract Trit32 ulong ops rotr rotl. ConstructorTrit32mkenforces the postcondition((w >> 32) & (w & 0xffffffff)) == 0; any overlapping(1, 1)carrier pair immediately triggers OM-2 contract trap10(process exit110MEASURED). - 1-op negation (
t32neg):rotr a 32swapspos32andneg32across all32lanes in a single AArch64RORinstruction (1 opMODELED, zero carries, zero sign-extension bias). - Zero-multiply wave product (
t32mul): computes all32balanced-ternary lane products in parallel via bitwiseAND/OR/ROR(0hardware integer multipliesMODELED). - Branchless inner product (
t32dot): evaluatespop32(pos32) - pop32(neg32)in[-32, +32]using shift-mask SWAR popcount (0branches,0multipliesMODELED).
- Packs
Multi-Scale Balanced-Ternary Codec (
M = 6) and16/16Hypercube Witness (M = 3):bt6enc/bt6decmap the symmetric integer lattice[-364, +364]bijectively onto3^6 = 729states (729/729exact round-tripsMODELEDandMEASURED).- Dark Consensus (
bt6enc(0) = 0): zero maps topos32 = 0, neg32 = 0(0active carriers out of32MODELEDandMEASURED), eliminating quiescent binary DC bias. - Hypercube reconstruction (
hc3enc/hc3dec): embeds all16corners of{0, 1}^4intoM = 3balanced trits (3^3 = 27 > 16statesMODELED), achieving16/16exact corner reconstruction (MEASUREDand proved in Lean 4) whereas any4central binary hyperplanes inR^3realize at most14 < 16strict sign orthants (MODELED, proved innl1_four_central_hyperplanes_r3_at_most_14).
Sylvester Walsh-Hadamard
H16Wave Spreading (h16enc/h16dec):- Encodes
5-bitsymbolsym in 0..31(4-bit Hadamard row index + 1-bit polarity) across16orthogonal ternary carriers with minimum Hamming distanced_H = 8 trits(MODELED, proved in Lean 4 and verified exhaustively in Wolfram). - Corrects
100%of0, 1, 2, 3-carrier sign flips or erasures (32/32,512/512,360/360, and1120/1120MEASURED) and fail-closed returns-1on>= 4-carrier midpoint ties (70/70MEASURED).
- Encodes
Give-Before-Take Reciprocal Ledger (native/btwave/ledger.om)
- Compile-time capability separation:
abstract CreditJ ulong(earned compute credit) andabstract GrantJ ulong(authorized compute extraction) have no implicit conversion. SwappingCreditJ,GrantJ,Trit32, orWaveDupat any call site is refused at compile time byomcwith exit status7(4/4type-swap mutants refusedMEASURED). - Mirrored waveguide frame tag:
abstract WaveDup ulongwithholds WaveDup dup32traps10(exit110MEASURED) if upper and lower 32-bit halves diverge. - Chained FIPS 180-4 SHA-256 work receipts: every admitted Give and Take stores a new 32-byte
Lchaindigest overchain32 || epoch_le8 || units_le8 || response_tc_le8(56 Bmessage).rcpt_eqcompares 32 bytes under ARM64dit 1+scrub 64. Insideldg_givethat compare is against a copy of the digest just computed, flipped only when mode is 3. The IPC host is the path that compares a received frame to a recomputed receipt (host_give_round/rx_rcpt_ok, returning-44on mismatch). Before that compare,host_give_roundrequires the returned job wave to equaljob_wave(sym)for the symbol it sent, returning-46otherwise, so Node B cannot earn credit for a wrong decode that carries a self-consistent receipt. - Reciprocity invariant:
extracted <= contributedholds initially (0 <= 0) and across every admitted or refused event; zero-contribution peers cannot extract (-9), overdrafts are refused (-10). A refusal leavesepoch,contributed,extracted, andLchainunchanged.Lrespis cleared to0at the start ofldg_step, including on refusal (MEASUREDinexpected-trace.out: case 1 stores response-120, case 2 refusal stores0, whileepoch,contributed,extracted, andLchainstay put). Lean 4 provesextracted <= contributedfor a numeric(epoch, contributed, extracted)state and admission flag; that model does not includeLrespor the codec (MEASUREDacross 16 trace cases + 23 mutants).
| Status | Meaning | Guard location |
|---|---|---|
0 | Admitted (GIVE credits work; TAKE grants compute within credit) | ldg_give / ldg_take |
-1 | Invalid opcode (op != 1 and op != 2) | ldg_step |
-2 | Non-sequential or negative epoch (req_epoch != epoch + 1) | ldg_step |
-3 | Invalid GIVE work bounds (work == 0, work > 1000, take != 0, or bad symbol) | ldg_step / ldg_give |
-4 | H16 wave decode refusal (>= 4 carrier corruptions / midpoint tie) | ldg_give |
-5 | Incomplete active carrier power (t32pow(job_wave) != 32) | ldg_give |
-6 | Scale out of admitted range (sc == 0 or |sc| > 65536) | scale_bad |
-7 | Caller set mode 3, so the computed receipt copy differs by one byte. ldg_give does not read an external receipt. The IPC host compares the child frame to a receipt it recomputes (host_give_round); a mismatch there returns -44, not -7. | ldg_give when mode == 3; IPC check is rx_rcpt_ok (returns -44) |
-8 | Invalid TAKE grant bounds (take == 0, take > 1000, or work != 0) | ldg_take |
-9 | Parasitic TAKE before any verified GIVE (contributed == 0) | ldg_take (cred_pos) |
-10 | Reciprocity overdraft (extracted + take > contributed) | ldg_take (recip_ok) |
-11 | Caller set mode 5. host_take_round sets that mode when the first 8 bytes of the frame chain differ from ldg_chid. This is not a 32-byte compare inside ldg_take. | ldg_take when mode == 5 |
-12 | Not reachable from ldg_step. The function rebuilds a mirrored tag from the epoch and checks that tag against itself. A non-mirrored WaveDup traps 10 (exit 110) in the constructor (trap-dup), which is not status -12. | no return path |
Duplex Cross-Core Waveguide (native/btwave/wave_ipc.om)
- Forks a child worker (
fork) connected over two unidirectional Linuxpipefdscarrying fixed80-byteraw binary/ternary frames (0 BJSON/Protobuf overheadMODELED). - Pins host Node A to Arm Cortex-X925 core
16and child Node B to Arm Cortex-X925 core17on NVIDIA GB10 (3900 MHzmax clock, cores3, 7, 15strictly excluded viapin_corerequirescontract) and verifies placement viacpunow. - Executes
8full-duplex waveguide rounds (4noisyH16Give jobs with 2 injected carrier flips decoded on core17; the host credits60units per round only after checking the returned job wave againstjob_wave(sym)and the receipt, earning240credit units;1overdraft Take of300units refused with-10; and3admitted Take rounds extracting180 <= 240units), completing in168,610 ns(0.169 msMEASUREDviamononson Cortex-X925 cores16and17,evidence/BTWAVE-P0/ipc.stdout;elapsed_nsvaries per run). - On any host refusal (
-41to-46,-51to-53, wrong overdraft or take status),ipc_runcloses the host pipe ends beforewaitpid(ipc_shut), Node B reads end-of-file and exits, andbtwave ipcexits with the host code (65,66, or67) instead of blocking.
Pure OM-2 Gate and Mutant Harness (native/btwave/gate.om)
Build and run from the repository root on Linux AArch64 (passing a scratch copy of
evidence/BTWAVE-P0 so committed receipt.tsv and ipc.stdout stay untouched; gate.om opens
native/btwave/*.om relative to the working directory and fails at step 5 otherwise). The
block uses a private mktemp -d directory and ends with the gate's own exit status (table below),
so a scripted run fails when the gate fails:
T=$(mktemp -d)
cat native/btwave/trit.om native/btwave/gate.om | "$OMC" > "$T/gate"
chmod +x "$T/gate"
cp -r evidence/BTWAVE-P0 "$T/ev"
"$T/gate" "$OMC" "$T/ev"; rc=$?
rm -rf "$T"
(exit "$rc")
| Gate exit | Meaning |
|---|---|
0 | BTWAVE PASS: compiler pin verified, 3x deterministic build + Wolfram trace match, cross-core IPC pass, negative controls pass, 23/23 mutants killed (including m23-ipc-peer-wrong-job, which must make btwave ipc exit 65 with empty stdout), 4/4 type swaps refused (omc error 7) |
1 | Gate check or mutant kill failed (prints step code to stderr) |
2 | Usage error |
77 | BTWAVE NOT_RUN: <omc_path> SHA-256 does not match pinned seed/out/omc |
Not Run or Not Claimed
- GB10 Blackwell GPU execution:
NOT_RUN. All measurements inBTWAVE-P0execute on Arm Cortex-X925 CPU cores16-18(and Lean 4 verification on Cortex-A725 cores0-1). - Multi-host socket / RDMA transport:
NOT_RUN. P0 waveguide transport exercises cross-core multi-processpipefdson a single Linux AArch64 host. - LLM / LoRA weight training or AEGIS capability authority:
NOT_RUN.btwaveprovides the non-binary balanced-ternary algebra, harmonic codec, and reciprocal ledger P0 engine only.