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 / research / dirac-oracle / src / oracle_clifford.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * DIRAC-0 independent oracle: exact Clifford relation check. |
| 19 | * STATUS: NOT_RUN. Not compiled, not executed. No libm, no floating point. |
| 20 | * Shares no code with Omega. Entries are Gaussian INTEGERS (re,im as long long), |
| 21 | * which covers the small hand corpus; rational entries (such as 1/2) are for the |
| 22 | * basis-change check and are out of scope for this first file. |
| 23 | * |
| 24 | * Input on stdin (whitespace separated integers): |
| 25 | * d n generators and matrix size (n <= 4, d <= 4) |
| 26 | * m_0 .. m_{d-1} metric diagonal entries (integers) |
| 27 | * then for each generator, n*n entries as pairs "re im", row major. |
| 28 | * Bounds: every entry magnitude must be <= 1048576 (2^20) and each metric entry |
| 29 | * must be in {-1,0,1}; inputs outside are rejected (exit 2), so no overflow occurs. |
| 30 | * Output: one line "FAIL i j" per failing pair, then "PASS" or "FAIL_COUNT k". |
| 31 | * Exit status 0 on PASS, 1 on FAIL, 2 on bad input. |
| 32 | */ |
| 33 | #include <stdio.h> |
| 34 | |
| 35 | #define MAXD 4 |
| 36 | #define MAXN 4 |
| 37 | |
| 38 | typedef struct { long long re, im; } gi; |
| 39 | typedef struct { gi a[MAXN][MAXN]; } mat; |
| 40 | |
| 41 | static gi gmul(gi x, gi y) { |
| 42 | gi r; |
| 43 | r.re = x.re * y.re - x.im * y.im; |
| 44 | r.im = x.re * y.im + x.im * y.re; |
| 45 | return r; |
| 46 | } |
| 47 | |
| 48 | static void matmul(const mat *x, const mat *y, int n, mat *out) { |
| 49 | int i, j, k; |
| 50 | for (i = 0; i < n; i++) |
| 51 | for (j = 0; j < n; j++) { |
| 52 | gi s = {0, 0}; |
| 53 | for (k = 0; k < n; k++) { |
| 54 | gi t = gmul(x->a[i][k], y->a[k][j]); |
| 55 | s.re += t.re; |
| 56 | s.im += t.im; |
| 57 | } |
| 58 | out->a[i][j] = s; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | int main(void) { |
| 63 | int d, n, i, j, r, c; |
| 64 | long long metric[MAXD]; |
| 65 | mat g[MAXD]; |
| 66 | int fails = 0; |
| 67 | |
| 68 | if (scanf("%d %d", &d, &n) != 2) return 2; |
| 69 | if (d < 1 || d > MAXD || n < 1 || n > MAXN) return 2; |
| 70 | for (i = 0; i < d; i++) |
| 71 | if (scanf("%lld", &metric[i]) != 1 || metric[i] < -1 || metric[i] > 1) return 2; |
| 72 | for (i = 0; i < d; i++) |
| 73 | for (r = 0; r < n; r++) |
| 74 | for (c = 0; c < n; c++) |
| 75 | if (scanf("%lld %lld", &g[i].a[r][c].re, &g[i].a[r][c].im) != 2 || g[i].a[r][c].re > 1048576 || g[i].a[r][c].re < -1048576 || g[i].a[r][c].im > 1048576 || g[i].a[r][c].im < -1048576) return 2; |
| 76 | |
| 77 | for (i = 0; i < d; i++) |
| 78 | for (j = i; j < d; j++) { |
| 79 | mat p, q; |
| 80 | int bad = 0; |
| 81 | matmul(&g[i], &g[j], n, &p); |
| 82 | matmul(&g[j], &g[i], n, &q); |
| 83 | for (r = 0; r < n; r++) |
| 84 | for (c = 0; c < n; c++) { |
| 85 | long long want = (r == c && i == j) ? 2 * metric[i] : 0; |
| 86 | /* off-diagonal generators: target is 2*metric(i,j) I, metric is diagonal so it is 0 */ |
| 87 | if (p.a[r][c].re + q.a[r][c].re != want) bad = 1; |
| 88 | if (p.a[r][c].im + q.a[r][c].im != 0) bad = 1; |
| 89 | } |
| 90 | if (bad) { |
| 91 | printf("FAIL %d %d\n", i, j); |
| 92 | fails++; |
| 93 | } |
| 94 | } |
| 95 | if (fails == 0) { |
| 96 | printf("PASS\n"); |
| 97 | return 0; |
| 98 | } |
| 99 | printf("FAIL_COUNT %d\n", fails); |
| 100 | return 1; |
| 101 | } |