omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / spec / mixed-algebra-phase-twin.md
| 1 | # Omega mixed algebra: phase-domain Z3 digital twin (MA-8 step 0) |
| 2 | |
| 3 | Status: ADR 0019 **MA-8 step 0**, a simulated precursor of MA-8 ("physical |
| 4 | phase or external-Machine realization"). It is not MA-8 itself: there is no |
| 5 | physical device. Provenance of every result is `SIMULATED_DEVELOPMENT` |
| 6 | (ADR 0018 AR1/AR2 wording). It makes no speed, latency, energy or physical |
| 7 | claim, does no selection or ranking, and mints no semantic id or digest. It |
| 8 | may be cited as model-only evidence toward the Turing gate |
| 9 | DIGITAL_PHASE_EQUIVALENCE; it does not claim that gate. |
| 10 | |
| 11 | Code: `src/algebra/phase_twin.{h,c}` (twin), `tests/algebra/test_phase_twin.c` |
| 12 | (gates and receipt). Receipt: `evidence/MIXED_ALGEBRA/phase_twin_receipt.<sha256>.json`. |
| 13 | Commands: `make test-phase-twin` (full run into `build/`, quick run plain and |
| 14 | under ASan+UBSan with byte-identical receipts, reproduction check against the |
| 15 | committed receipt; about 90 s wall on the Spark), `make phase-twin-receipt` |
| 16 | (clean committed tree only; writes the content-addressed receipt). C11 + libm, |
| 17 | no other dependencies, CPU only. |
| 18 | |
| 19 | Sources: ADR 0019 (sections 3, 5, 6.3, 8), ADR 0018 (sections 3, 12), |
| 20 | `docs/plans/mixed-algebra/MIXED_ALGEBRA_THEORY.md` section 6, |
| 21 | `docs/plans/mixed-algebra/research/PHASE_EXPERIMENT_AND_HARDWARE.md` |
| 22 | ("research note"), all at aien-architecture `origin/main` 1438799. Oracle: |
| 23 | `oma_z3_add` / `oma_z3_mul` (`src/algebra/oma_z3.c`). |
| 24 | |
| 25 | ## Claim form |
| 26 | |
| 27 | Every result below has the form: under model profile P (the declared |
| 28 | parameters), candidate realization C versus the oracle `oma_z3`, measured X, |
| 29 | from the receipt. Nothing transfers to hardware without AR4-grade physical |
| 30 | evidence. |
| 31 | |
| 32 | ## Model |
| 33 | |
| 34 | Encoding: Z3 value k is the tone `A cos(2 pi n / 64 + 2 pi k / 3)`, so |
| 35 | `f_c = f_s / 64` and the phase is 0, 120 or 240 degrees. Converter full scale |
| 36 | is +/-1; A = 0.5 (-6.02 dBFS). Converters are mid-tread quantizers with |
| 37 | clipping (`bits = 0` means ideal). |
| 38 | |
| 39 | Addition is phasor multiplication (theory 6.1, 6.2). Three candidate |
| 40 | realizations: |
| 41 | |
| 42 | | rz_id | mechanism | where the multiply happens | |
| 43 | |---|---|---| |
| 44 | | PT_corr_product | two channels emit a and b; each is I/Q-correlated at f_c; the two correlator outputs are multiplied | complex multiply of measured phasors (research note loopback) | |
| 45 | | PT_mixer | two tones enter an ideal analog mixer; the product is digitized and correlated at 2 f_c | analog multiply (simulated) | |
| 46 | | PT_nco | 32-bit phase words `a T + b T` (T = floor(2^32/3)) wrap-add; one tone at that phase | integer phase accumulator (NCO) | |
| 47 | |
| 48 | Measurement: `I = sum x[n] cos(2 pi n / 64)`, `Q = -sum x[n] sin(2 pi n / 64)` |
| 49 | (bin 2 for mixer and doubler). Decision: `k = mod(round(theta / 120 deg), 3)`, |
| 50 | cells +/-60 degrees. |
| 51 | |
| 52 | Calibration (research note "Timing and calibration"): every |
| 53 | `interval` operations, emit k = 0 on each path `reps` times, average the |
| 54 | correlator outputs, store the phase as the path offset and the magnitude as |
| 55 | the erasure reference; then emit k = 1 `reps` times and require |
| 56 | 120 +/- `tol` degrees after correction, else a calibration fault. Later |
| 57 | correlator outputs are rotated by the stored offset. The reference is |
| 58 | time-multiplexed on the signal paths (the research note's procedure); a |
| 59 | dedicated always-on pilot tone is the hardware alternative and is not modelled. |
| 60 | |
| 61 | Flags (each fails the trial; no voting): erasure (magnitude below 0.3 x |
| 62 | reference), reject (output phase more than 30 degrees from the nearest |
| 63 | center), calibration fault (every operation in a block after a failed check). |
| 64 | |
| 65 | Noise and impairments: AWGN per sample at the ADC input (std `sigma`, |
| 66 | independent per channel); one Gaussian phase jitter per channel per frame; |
| 67 | DAC and ADC quantization; fixed per-channel path offset; linear per-channel |
| 68 | drift in simulated time (`frame_s` per frame, calibration frames included). |
| 69 | Symbol SNR at the correlator output is `rho = A^2 N / (4 sigma^2)`, equal to |
| 70 | the research note's `rho = N SNR_1 / 2`. |
| 71 | |
| 72 | Declared simplifications: the analog path is a pure phase shift at f_c applied |
| 73 | before the DAC; noise is white Gaussian; converters have no INL/DNL or spurs; |
| 74 | mixer and doubler are ideal multipliers; one shared clock (no sample slip, no |
| 75 | frequency offset); no crosstalk; no amplitude drift. |
| 76 | |
| 77 | RNG: xoshiro256** seeded by splitmix64, Gaussian by the Marsaglia polar |
| 78 | method, fixed seed per scenario (listed in the receipt). No clock or host data |
| 79 | enters the receipt except the recorded commit, dirty count and compiler |
| 80 | version, so plain and sanitizer builds write byte-identical receipts. |
| 81 | |
| 82 | ## Profiles |
| 83 | |
| 84 | | profile | f_s | N | bits DAC/ADC | use | |
| 85 | |---|---|---|---|---| |
| 86 | | A | 125 MS/s | 4096 | 14/14 | research note reference design | |
| 87 | | B | 1 MS/s | 1024 | 12/12 | research note low-rate design | |
| 88 | | B-ideal | 1 MS/s | 1024 | ideal | quantization-free control | |
| 89 | | SWEEP | 1 MS/s | 64 | ideal | gate 2; flags, jitter, offset, calibration off | |
| 90 | | P (contract) | 1 MS/s | 64 | 12/12 | gate 3; frame 128 us, rho 25 dB per input, jitter 1 deg rms, flags on, calibration every 1000 ops with 32 reference frames, tol 5 deg | |
| 91 | |
| 92 | ## Pre-registered gates and thresholds |
| 93 | |
| 94 | These thresholds are fixed in this document and in `tests/algebra/test_phase_twin.c` |
| 95 | before the committed receipt is generated. |
| 96 | |
| 97 | - **Self-checks.** Decoder boundaries (59.9 degrees -> 0, 60.1 -> 1), NCO wrap |
| 98 | pair (2,2) -> 1, argument rejection, RNG moments, the analytic add reference |
| 99 | stable between grids of 3600 and 7200 points (relative 1e-3), Craig integral |
| 100 | at 0 dB within 5e-4 of 0.1834. |
| 101 | - **Gate 1, noiseless (exhaustive).** Profiles A, B, B-ideal x realizations |
| 102 | PT_corr_product, PT_mixer, PT_nco: all 9 input pairs x 1000 repetitions |
| 103 | decode equal to `oma_z3_add`, zero mismatches, zero flags. Multiply by a known |
| 104 | constant on profile B (calibration on): 9 pairs x 1000 equal to `oma_z3_mul`. |
| 105 | Quantization sweep 16 to 1 bits is informational only. |
| 106 | - **Gate 1b, research note pass condition.** Profile A, `SNR_1` = 80 dB per |
| 107 | sample, 1 ps jitter (7.0e-4 degrees at 1.953 MHz), 3.35 degree fixed offset |
| 108 | on channel b (1 m cable), calibration on: 9 x 1000, zero failures. |
| 109 | - **Gate 2, error rate versus SNR (PT_corr_product, profile SWEEP).** At rho |
| 110 | = 0, 6, 8, 10, 12 dB per input with 1e5, 2e5, 4e5, 1e6, 4e6 trials: |
| 111 | (a) the exact add reference (numerical circular convolution of the exact |
| 112 | PSK phase density, 7200 points) lies inside the measured Wilson 99.9 % |
| 113 | interval; (b) the research note's Monte Carlo add values (3.52e-1, 5.76e-2, |
| 114 | 1.52e-2, 1.96e-3, 8.46e-5) are within 5 % of the exact reference at 10 and |
| 115 | 12 dB; (c) the single-phasor read of channel a matches Craig's exact 3-PSK |
| 116 | error inside Wilson 99.9 % wherever at least 100 errors are expected, and |
| 117 | Craig matches the research note's table within 1 %; (d) pure 15 degree |
| 118 | per-input jitter, 4e5 trials: `2 Q(60 / (sqrt2 x 15))` = 4.68e-3 inside |
| 119 | Wilson 99.9 %. |
| 120 | - **Gate 3, calibration (profile P).** Cases offset-only (50, 20 degrees), |
| 121 | drift-only (2.0, 1.5 degrees/s), offset and drift. Uncalibrated runs |
| 122 | (2e5, 1e6, 2e5 trials) must **violate** the contract: Wilson 95 % lower |
| 123 | bound above 1e-6. Calibrated runs (2e5, 1e6, 4e6 trials) must have zero |
| 124 | failures. The contract case (offset and drift, 4e6 trials) must meet the |
| 125 | contract below. |
| 126 | - **Gate 4, receipt.** Records every profile parameter, the contract, measured |
| 127 | error rates with Wilson bounds, evidence tiers per ADR 0019 section 8, the |
| 128 | Z3 multiply verdict, and field names from `src/turing/field.h` where they |
| 129 | apply (`rz_id`, `algebra`, `representation`, `tier_source`, `run_id`, |
| 130 | `git_commit`, `tree_dirty`, `toolchain`, `verified`). |
| 131 | |
| 132 | Contract (ADR 0018 `BOUNDED_STOCHASTIC`): operation Z3 add `(a + b) mod 3`, |
| 133 | realization PT_corr_product at profile P; bound: probability of a failed |
| 134 | operation (mismatch or any flag) <= 1e-6; confidence 95 %; required: zero |
| 135 | failures in at least `ceil(-ln 0.05 / 1e-6)` = 2,995,733 trials, and the |
| 136 | two-sided Wilson 95 % upper bound <= 1e-6 (hence 4,000,000 trials). |
| 137 | |
| 138 | ### Pre-registration record |
| 139 | |
| 140 | The thresholds above were written into the test code before the first full |
| 141 | run, but that run (uncommitted working tree) came before this document. One |
| 142 | parameter changed after it: profile P first used 8 calibration reference |
| 143 | frames. At rho 25 dB the k = 1 check then misfires about once per 4,000 |
| 144 | calibrations (6e-5 per check); one such false calibration fault flagged a |
| 145 | block of 1,000 operations in the drift-only and contract cases. The frame |
| 146 | count was raised to 32, which puts the check tolerance at about 8 standard |
| 147 | deviations. The contract bound, confidence, SNR, trial counts, tolerances and |
| 148 | flag thresholds did not change. This is a post-observation change to a |
| 149 | calibration parameter and is recorded here as such. |
| 150 | |
| 151 | ## Z3 multiplication |
| 152 | |
| 153 | Two unknown operands: **not realizable in this model.** Phasor multiplication |
| 154 | realizes Z3 addition. Z3 `a b` corresponds to `w^(a b) = (w^a)^b`, which is |
| 155 | exponentiation, and no bilinear phasor operation computes it (theory 6.4). A |
| 156 | decode-then-select circuit (decode b digitally, then identity, doubler or |
| 157 | constant source) is a hybrid digital realization and is not claimed. |
| 158 | |
| 159 | Multiplication by a known constant b: **realized** (gate 1): b = 0 is a constant |
| 160 | k = 0 source, b = 1 identity, b = 2 a frequency doubler (squarer read at |
| 161 | 2 f_c), since `w^(2a) = conj(w^a)`. |
| 162 | |
| 163 | ## Evidence tiers (ADR 0019 section 8) |
| 164 | |
| 165 | | item | tier | scope | |
| 166 | |---|---|---| |
| 167 | | add, noiseless, each profile x realization | E3 (all 9 pairs) | the twin model; the ideal map itself is E4 (theory 6.1 proof) | |
| 168 | | mul by known constant, noiseless | E3 | the twin model | |
| 169 | | add, bounded contract at profile P | E1 | the twin model only | |
| 170 | | SNR curve and jitter check | model validation, not a contract | agreement with analytic references | |
| 171 | | mul of two unknowns | E0: no realization exists | | |
| 172 | |
| 173 | ## What the twin proves and what it does not |
| 174 | |
| 175 | It shows that, inside the declared model, the phase encoding plus the three |
| 176 | add mechanisms compute exactly `oma_z3_add` on the whole Z3 domain; that |
| 177 | the decoder's error statistics match the analytic 3-PSK results, so the |
| 178 | contract arithmetic is right; and that the reference-frame calibration turns |
| 179 | a failing channel (offset and drift) into one that meets a 1e-6 bound at |
| 180 | rho 25 dB. |
| 181 | |
| 182 | It does **not** show that any physical board does this. ADR 0018 forbids a |
| 183 | physical analog claim without physical evidence, and there is none. It makes |
| 184 | no claim about speed, latency, energy, or cost against the digital |
| 185 | `oma_z3_add`. The noise models are idealized (list above); real converters, |
| 186 | cables, mixers and clocks have effects the twin leaves out. |
| 187 | |
| 188 | ## What a real board must meet for the contract to transfer |
| 189 | |
| 190 | A board inherits the twin's contract only if measurements (AR4 evidence) |
| 191 | show all of these at the operating point used: |
| 192 | |
| 193 | 1. One clock and PLL for DAC, ADC and NCOs; NCOs cleared on the same cycle; |
| 194 | no sample slip (one sample at `f_s / 64` is 5.625 degrees). |
| 195 | 2. Symbol SNR at the correlator output >= 25 dB per input: |
| 196 | `N SNR_1 / 2 >= 316`, measured with the board's effective bits, at -6 dBFS |
| 197 | and no clipping. |
| 198 | 3. DAC and ADC >= 12 effective bits over the used band, no spur at f_c or |
| 199 | 2 f_c above the noise that the SNR figure assumes. |
| 200 | 4. Frame-to-frame phase jitter <= 1 degree rms per channel (1.42 ns rms at |
| 201 | 1.953 MHz; 178 ns at 15.625 kHz). |
| 202 | 5. Any fixed path offset, with the k = 1 check passing (120 +/- 5 degrees). |
| 203 | 6. Phase drift <= 2 degrees/s per channel with recalibration every 1,000 |
| 204 | operations (0.13 s at profile P), or proportionally faster recalibration; |
| 205 | board temperature within 2 degrees C across a block. |
| 206 | 7. 32 reference frames per calibration step at rho 25 dB (fewer at higher |
| 207 | SNR, as long as the check's false-fault rate stays below the contract). |
| 208 | 8. Noise white and Gaussian enough that the measured error curve matches the |
| 209 | gate 2 curve; independent channels; crosstalk below the noise floor. |
| 210 | 9. For PT_mixer: mixer linear enough that the 2 f_c product term dominates, |
| 211 | and the ADC sees the product without clipping. |
| 212 | |
| 213 | ## Results (receipt `evidence/MIXED_ALGEBRA/phase_twin_receipt.5d6ca45e970faf19986490264e35db453211ffe6dfff03d1cfb10937f329a22b.json`) |
| 214 | |
| 215 | Generated by `make phase-twin-receipt` from clean commit 48ef003 (`tree_dirty` 0), |
| 216 | gcc 13.3.0. Overall **PASS**. The quick run (trial counts / 50) is byte-identical |
| 217 | between the plain and the ASan+UBSan build. |
| 218 | |
| 219 | - Gate 1: 9 configurations (A, B, B-ideal x corr_product, mixer, nco), 9,000 |
| 220 | checks each, 0 mismatches, 0 flags. Largest phase error from a cell center: |
| 221 | 3.6e-2 degrees (mixer, 12-bit). Multiply by known constant: 9,000 checks, 0 |
| 222 | failures. Quantization is harmless down to 2 bits (max 3.75 degrees); the |
| 223 | degenerate 1-bit mid-tread quantizer fails (informational). |
| 224 | - Gate 1b: 9,000 checks at the research note's reference operating point, 0 |
| 225 | failures. |
| 226 | - Gate 2, PT_corr_product add error versus rho per input (exact reference / |
| 227 | research note / twin): |
| 228 | |
| 229 | | rho | exact | note | twin (errors / trials) | Wilson 99.9 % | |
| 230 | |---|---|---|---|---| |
| 231 | | 0 dB | 3.517e-1 | 3.52e-1 | 3.531e-1 (35,314 / 1e5) | 3.48e-1 .. 3.58e-1 | |
| 232 | | 6 dB | 5.771e-2 | 5.76e-2 | 5.793e-2 (11,585 / 2e5) | 5.62e-2 .. 5.97e-2 | |
| 233 | | 8 dB | 1.514e-2 | 1.52e-2 | 1.526e-2 (6,104 / 4e5) | 1.46e-2 .. 1.59e-2 | |
| 234 | | 10 dB | 1.961e-3 | 1.96e-3 | 1.938e-3 (1,938 / 1e6) | 1.80e-3 .. 2.09e-3 | |
| 235 | | 12 dB | 8.530e-5 | 8.46e-5 | 9.125e-5 (365 / 4e6) | 7.68e-5 .. 1.08e-4 | |
| 236 | |
| 237 | Single-phasor reads match Craig's formula (for example 1.020e-4 vs 1.065e-4 |
| 238 | at 10 dB). Jitter 15 degrees per input: 4.68e-3 measured, 4.68e-3 formula. |
| 239 | - Gate 3 (profile P, contract bound 1e-6 at 95 %): uncalibrated offset-only, |
| 240 | drift-only and offset-and-drift runs fail at 1.00, 0.80 and 1.00 (contract |
| 241 | violated). Calibrated: 0 failures in 2e5, 1e6 and 4e6 operations; the |
| 242 | contract case gives Wilson 95 % upper bound 9.6e-7 and E1 bound 7.5e-7: |
| 243 | **CONTRACT_MET** under profile P. 4,000 calibrations, 0 calibration faults. |