interplane.Get Omega
Read in your language

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

GitHub aien-dev/omega-mv#189 (code only)

closed derived 613f9ad1f3fafebd #189

Imported from GitHub aien-dev/omega-mv#189 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 74bfd578d6cd95573b8b796161de488c4337e2e1 · Head 14f1ee7255f15cd33ab6dd9f7ce7456a86fca1ba

Apply it

git checkout -b patch-613f9ad1f3fafebd 74bfd578d6cd95573b8b796161de488c4337e2e1
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/613f9ad1f3fafebd.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/omega-mv
189
14f1ee7255f15cd33ab6dd9f7ce7456a86fca1ba
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":189,"url":"https://github.com/aien-dev/omega-mv/pull/189","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:42Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/docs/tensor/M20_OMEGA_TENSOR.md b/docs/tensor/M20_OMEGA_TENSOR.md
index e09cc14e5..841a70c2b 100644
--- a/docs/tensor/M20_OMEGA_TENSOR.md
+++ b/docs/tensor/M20_OMEGA_TENSOR.md
@@ -105,6 +105,7 @@ removed. Order and padding mutations are caught by the E1 WP-D suite.
 | Immutability / no in-place | PASS (CPU) | no write API exists; input value ids unchanged by every op; outputs never alias inputs |
 | CPU parity | PASS (CPU) | every op bit-exact vs independent reference (omega_ref_*, omega_ieee_div/sqrt, omega_ref_ffma_int, own tree copy), random + all special pairs |
 | Transcendental unary ops (EXP2, LOG2, SIGMOID, TANH) | PASS (CPU) | Host PASS, CPU tier: forge log `HIVE-M20-transc-175026` (`test-tensor` + `test-tensor-mutations`, 7/7 mutants caught). Bounded contract, NOT correctly rounded (max ulp EXP2 2, LOG2 2, SIGMOID 3, TANH 3; `docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md`). `test-tensor` section 7b: raw-bit equality with direct `omega_math_*` calls on dense, transposed, strided-slice-with-offset, transpose-of-slice, broadcast row/scalar and rank-0 operands incl. specials; canonical qNaN; unknown op / F16 / stale / missing `transc` entry refused. Mutants `TRANSC_EXP2_LOG2_SWAP`, `UNARY_VIEW_STRIDE` in `test-tensor-mutations` |
+| Constants and NEG (`omega_tensor_full`/`zeros`/`ones`, `OMEGA_TU_NEG`; answers LT-M21 CR-2) | PASS (CPU) | Host: PASS, CPU tier: forge log `HIVE-M20-const-light-193345` at pre-stack head 049611c (488 pass, 0 fail plain and ASan/UBSan; 11/11 mutants caught); re-run at stacked head queued. GB10: NOT_RUN (no GB10 tensor realization exists; row GB10 parity). Declared result, one per op: `full(v)` fills every element with the exact F32 bits of `v` (-0.0 and NaN payload kept, no canonicalization; value ids still treat all NaNs as one); `zeros` = bits `0x00000000`; `ones` = `0x3f800000`; shape rules as `from_f32` (rank <= 8, dims >= 1, elements <= 2^30, else typed error; the 2^30 boundary itself is not allocated in tests, only 2^30+1 and 2^31 are refused). `NEG` = flip bit 31 with no arithmetic and no E1 call, so neg(+0) = -0 and neg(-0) = +0 (`0 - x` would give +0, wrong); any NaN in gives the canonical quiet NaN `0x7fc00000`, matching the E1 convention "NaN results are the canonical quiet NaN" (`src/omega_numeric.h:137`); F16/BF16 refused; works with a realization that has no `transc` entry. Tests (`test-tensor` section 7c): bit-exact contents, rank 0 and 8, refusals, NEG on the 20-value special grid vs an independent bit rule, NEG through transpose, strided slice and broadcast views. Mutants `ZEROS_NEG0`, `NEG_SUB`, `NEG_NAN`, `FULL_CANON` in `test-tensor-mutations` |
 | GB10 transcendental tensor ops | NOT_RUN | GB10 transcendental tensor ops: NOT_RUN (follow-up). No GB10 `transc` entry; a table without one refuses these ops with `OMEGA_TENSOR_ERR_REALIZATION` |
 | Unary ops EXP, LOG, RELU (M20 cut ops, LT-M21 CR-1..CR-5) | PASS (CPU) | Host PASS, CPU tier: forge log `HIVE-M20-ops-light-185351` at pre-stack head 1e16a8d, re-run at stacked head queued (`test-tensor` 438 pass / 0 fail plain and ASan/UBSan; `test-tensor-mutations` 10/10 tensor mutants caught). EXP / LOG: `OMEGA_TU_EXP` / `OMEGA_TU_LOG` call the E1 Omega-defined polynomials `omega_math_exp` / `omega_math_log` (`src/omega_numeric.c:458`, `:501`) once per element through the CPU `transc` entry; the result must equal a direct E1 call bit for bit. NOT correctly rounded: E1 checks them only against binary128 within EXP 40 ulp, LOG 4 ulp (`tests/test_omega_numeric.c:376-384`; `docs/numeric/E1_GAP_TABLE.md` row 8 and the `CPU_TIER_INDEPENDENT_ORACLE` line). RELU: no E1 op; tensor-layer bit select with no float arithmetic (`src/tensor/omega_tensor.c` `relu_bits`): x > +0 (incl. +subnormals, +inf) -> x; +0, -0, negatives, -inf -> +0.0; any NaN -> canonical qNaN `OMEGA_QNAN_BITS` 0x7fc00000 (`src/omega_numeric.h:48`, as E1 returns, e.g. `src/omega_numeric.c:459`). Tests: section 7b runs EXP / LOG / RELU raw-bit vs direct E1 (RELU vs an independent field-classifying reference) on dense, transposed, strided-slice, transpose-of-slice, broadcast row/scalar and rank-0 views incl. specials (+-0, +-inf, NaN payloads, subnormals, +-2^31, exp cutoffs 88.7228 / -104); section 7c: RELU explicit bit table (-0 -> +0, NaN payloads -> 0x7fc00000), served without a `transc` entry, F16 / stale refused. Mutants `TRANSC_EXP_LOG_SWAP`, `RELU_NEG_ZERO`, `RELU_NAN_PAYLOAD` |
 | GB10 EXP / LOG tensor ops | MISSING_IMPLEMENTATION | E1 itself has no GB10 kernel for the Omega exp / log polynomials (`src/omega_numeric.c:585-588`, `gb10_encoded` false (`src/omega_numeric.h:250`); `docs/numeric/E1_GAP_TABLE.md` row 10) |
diff --git a/src/tensor/omega_tensor.c b/src/tensor/omega_tensor.c
index 478646750..534cd836a 100644
--- a/src/tensor/omega_tensor.c
+++ b/src/tensor/omega_tensor.c
@@ -665,6 +665,12 @@ static int elementwise_n(OmegaTensorCtx *ctx, OmegaNumericOp op, unsigned arity,
     for (unsigned i = 0; i < arity; i++) free(in[i]);
     return rc;
 }
+/* NEG: sign-bit flip; any NaN becomes the canonical quiet NaN. */
+static uint32_t neg_bits(uint32_t u) {
+    if ((u & 0x7f800000U) == 0x7f800000U && (u & 0x007fffffU)) return 0x7fc00000U; /* MUT:NEG_NAN */
+    return u ^ 0x80000000U; /* MUT:NEG_SUB */
+}
+
 
 /* RELU (M20 cut ops): no E1 op exists, so the tensor layer defines it as a
  * pure bit-level select on the FP32 pattern, with no float arithmetic and no
@@ -696,7 +702,7 @@ static void relu_dense(const float *src, float *dst, size_t n) {
 int omega_tensor_unary(OmegaTensorCtx *ctx, OmegaTensorUnaryOp op, OmegaTensor a, OmegaTensor *out) {
     if (!ctx || !out) return OMEGA_TENSOR_ERR_BAD_ARGS;
     if ((unsigned)op >= OMEGA_TU_COUNT) return OMEGA_TENSOR_ERR_BAD_ARGS;
-    if (op != OMEGA_TU_SQRT && op != OMEGA_TU_RELU && !ctx->real->transc) return OMEGA_TENSOR_ERR_REALIZATION;
+    if (op != OMEGA_TU_SQRT && op != OMEGA_TU_RELU && op != OMEGA_TU_NEG && !ctx->real->transc) return OMEGA_TENSOR_ERR_REALIZATION;
     TensorSlot *x;
     StorageSlot *s;
     int rc = tensor_get(ctx, a, &x, &s);
@@ -712,14 +718,41 @@ int omega_tensor_unary(OmegaTensorCtx *ctx, OmegaTensorUnaryOp op, OmegaTensor a
     if (!rc) {
         int nrc = 0;
         if (op == OMEGA_TU_RELU) relu_dense(src, buf, n);
-        else nrc = op == OMEGA_TU_SQRT ? ctx->real->elementwise(OMEGA_NOP_SQRT, src, NULL, NULL, buf, n)
-                                       : ctx->real->transc(op, src, buf, n);
+        else if (op == OMEGA_TU_NEG) {
+            uint32_t *ob = buf;
+            for (size_t i = 0; i < n; i++) ob[i] = neg_bits(omega_float_to_bits(src[i]));
+        } else {
+            nrc = op == OMEGA_TU_SQRT ? ctx->real->elementwise(OMEGA_NOP_SQRT, src, NULL, NULL, buf, n)
+                                      : ctx->real->transc(op, src, buf, n);
+        }
         if (nrc) rc = numeric_fail(ctx, nrc, *out);
     }
     free(src);
     return rc;
 }
 
+/* Constant tensors: pure bit fill, no arithmetic. */
+int omega_tensor_full(OmegaTensorCtx *ctx, uint32_t rank, const uint64_t *shape, float value,
+                      OmegaTensor *out) {
+    if (!ctx || !out) return OMEGA_TENSOR_ERR_BAD_ARGS;
+    void *buf;
+    int rc = new_dense(ctx, OMEGA_DT_F32, rank, shape, out, &buf);
+    if (rc) return rc;
+    uint32_t u = omega_float_to_bits(value); /* MUT:FULL_CANON */
+    uint32_t *p = buf;
+    size_t n = (size_t)ctx->ts[out->slot].info.elements;
+    for (size_t i = 0; i < n; i++) p[i] = u;
+    return OMEGA_TENSOR_OK;
+}
+
+int omega_tensor_zeros(OmegaTensorCtx *ctx, uint32_t rank, const uint64_t *shape, OmegaTensor *out) {
+    return omega_tensor_full(ctx, rank, shape, 0.0f, out); /* MUT:ZEROS_NEG0 */
+}
+
+int omega_tensor_ones(OmegaTensorCtx *ctx, uint32_t rank, const uint64_t *shape, OmegaTensor *out) {
+    return omega_tensor_full(ctx, rank, shape, 1.0f, out);
+}
+
 int omega_tensor_binary(OmegaTensorCtx *ctx, OmegaTensorBinaryOp op, OmegaTensor a, OmegaTensor b,
                         OmegaTensor *out) {
     if (!ctx) return OMEGA_TENSOR_ERR_BAD_ARGS;
diff --git a/src/tensor/omega_tensor.h b/src/tensor/omega_tensor.h
index 7ceac37cc..092976c8c 100644
--- a/src/tensor/omega_tensor.h
+++ b/src/tensor/omega_tensor.h
@@ -137,6 +137,10 @@ typedef enum {
      * sin(+-0) = +-0, cos(+-0) = +1. */
     OMEGA_TU_SIN,        /* omega_math_sin,     <= OMEGA_TRANSC_MAX_ULP_SIN (2)     */
     OMEGA_TU_COS,        /* omega_math_cos,     <= OMEGA_TRANSC_MAX_ULP_COS (2)     */
+    /* Pure sign-bit flip, no E1 call, no arithmetic: bits ^ 0x80000000, so
+     * neg(+0) = -0 and neg(-0) = +0. Any NaN in gives the canonical quiet
+     * NaN 0x7fc00000 (E1 convention, omega_numeric.h:137). Needs no transc. */
+    OMEGA_TU_NEG,
     OMEGA_TU_COUNT
 } OmegaTensorUnaryOp;
 
@@ -273,6 +277,15 @@ int omega_tensor_broadcast_shape(uint32_t ra, const uint64_t *sa, uint32_t rb, c
                                  uint32_t *rout, uint64_t *sout);
 
 int omega_tensor_unary(OmegaTensorCtx *ctx, OmegaTensorUnaryOp op, OmegaTensor a, OmegaTensor *out);
+/* Constant tensors (answers LT-M21 CR-2). full() writes the F32 bits of
+ * `value` exactly into every element: -0.0 and any NaN payload are kept (no
+ * canonicalization; value ids still treat all NaNs as one). zeros = +0.0
+ * (bits 0x00000000), ones = 1.0f. Shape rules as omega_tensor_from_f32
+ * (rank <= 8, dims >= 1, elements <= OMEGA_TENSOR_MAX_ELEMS). */
+int omega_tensor_full(OmegaTensorCtx *ctx, uint32_t rank, const uint64_t *shape, float value,
+                      OmegaTensor *out);
+int omega_tensor_zeros(OmegaTensorCtx *ctx, uint32_t rank, const uint64_t *shape, OmegaTensor *out);
+int omega_tensor_ones(OmegaTensorCtx *ctx, uint32_t rank, const uint64_t *shape, OmegaTensor *out);
 int omega_tensor_binary(OmegaTensorCtx *ctx, OmegaTensorBinaryOp op, OmegaTensor a, OmegaTensor b,
                         OmegaTensor *out);
 /* a*b + c rounded once (E1 FFMA), all three broadcast together. */
diff --git a/tests/test_omega_tensor.c b/tests/test_omega_tensor.c
index b1ddd02d5..e2cb97fc4 100644
--- a/tests/test_omega_tensor.c
+++ b/tests/test_omega_tensor.c
@@ -1254,6 +1254,163 @@ static void test_trig_domain(void) {
     if (!rcs) omega_tensor_release(g, S);
 }
 
+/* ---- 7c. constants and NEG (LT-M21 CR-2) ----------------------------------
+ * Expected bits come from the definitions written in this test: a fill of the
+ * given bit pattern; NEG = flip bit 31, any NaN -> 0x7fc00000. Comparisons are
+ * raw bits (NOT same(): that would treat every NaN as equal). */
+static uint32_t neg_expect(uint32_t u) {
+    if ((u & 0x7f800000U) == 0x7f800000U && (u & 0x007fffffU)) return 0x7fc00000U;
+    return u ^ 0x80000000U;
+}
+static size_t all_bits_eq(OmegaTensor t, uint32_t want) {
+    float *v = rd(t);
+    if (!v) return (size_t)-1;
+    OmegaTensorInfo in;
+    omega_tensor_info(g, t, &in);
+    size_t m = 0;
+    for (size_t i = 0; i < (size_t)in.elements; i++) m += omega_float_to_bits(v[i]) != want;
+    free(v);
+    return m;
+}
+static void test_const_neg(void) {
+    uint64_t s2[2] = {3, 5}, s8[8] = {2, 2, 2, 2, 2, 2, 2, 2}, s9[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
+    uint64_t sbig[2] = {OMEGA_TENSOR_MAX_ELEMS, 2}, sone[1] = {OMEGA_TENSOR_MAX_ELEMS + 1};
+    uint64_t szero[2] = {3, 0};
+    OmegaTensor t;
+    OmegaTensorInfo in;
+
+    CHECK(omega_tensor_zeros(g, 2, s2, &t) == 0 && all_bits_eq(t, 0x00000000U) == 0, "zeros are +0.0 bits");
+    omega_tensor_release(g, t);
+    CHECK(omega_tensor_ones(g, 2, s2, &t) == 0 && all_bits_eq(t, 0x3f800000U) == 0, "ones are 1.0f bits");
+    omega_tensor_release(g, t);
+    /* full keeps every bit pattern, -0.0 and NaN payloads included */
+    for (size_t k = 0; k < NSPECIAL; k++) {
+        int rc = omega_tensor_full(g, 2, s2, omega_bits_to_float(SPECIALS[k]), &t);
+        CHECK(rc == 0, "full special %08x rc=%d", SPECIALS[k], rc);
+        if (rc) continue;
+        CHECK(all_bits_eq(t, SPECIALS[k]) == 0, "full keeps exact bits %08x", SPECIALS[k]);
+        CHECK(omega_tensor_info(g, t, &in) == 0 && in.dtype == OMEGA_DT_F32 && in.rank == 2 &&
+                  in.shape[0] == 3 && in.shape[1] == 5 && in.elements == 15 && !in.is_view,
+              "full info %08x", SPECIALS[k]);
+        omega_tensor_release(g, t);
+    }
+    /* rank 0 and rank 8 (the limit) */
+    CHECK(omega_tensor_full(g, 0, NULL, 2.5f, &t) == 0 && all_bits_eq(t, 0x40200000U) == 0, "rank-0 full");
+    omega_tensor_release(g, t);
+    CHECK(omega_tensor_full(g, 8, s8, -1.0f, &t) == 0 && omega_tensor_info(g, t, &in) == 0 &&
+              in.elements == 256 && all_bits_eq(t, 0xbf800000U) == 0, "rank-8 full");
+    omega_tensor_release(g, t);
+    /* refusals */
+    CHECK(omega_tensor_full(g, 9, s9, 0.0f, &t) == OMEGA_TENSOR_ERR_RANK, "rank 9 refused");
+    CHECK(omega_tensor_full(g, 2, sbig, 0.0f, &t) == OMEGA_TENSOR_ERR_CAPACITY, "2^31 elements refused");
+    CHECK(omega_tensor_full(g, 1, sone, 0.0f, &t) == OMEGA_TENSOR_ERR_CAPACITY, "MAX_ELEMS+1 refused");
+    CHECK(omega_tensor_zeros(g, 2, szero, &t) == OMEGA_TENSOR_ERR_SHAPE, "zero dim refused (zeros)");
+    CHECK(omega_tensor_ones(g, 1, NULL, &t) == OMEGA_TENSOR_ERR_BAD_ARGS, "NULL shape refused (ones)");
+    CHECK(omega_tensor_full(g, 0, NULL, 0.0f, NULL) == OMEGA_TENSOR_ERR_BAD_ARGS, "NULL out refused");
+    CHECK(omega_tensor_full(NULL, 0, NULL, 0.0f, &t) == OMEGA_TENSOR_ERR_BAD_ARGS, "NULL ctx refused");
+
+    /* NEG on the special-value grid, dense */
+    float sv[NSPECIAL];
+    for (size_t i = 0; i < NSPECIAL; i++) sv[i] = omega_bits_to_float(SPECIALS[i]);
+    uint64_t sn[1] = {NSPECIAL};
+    OmegaTensor A = mk(1, sn, sv), N;
+    int rc = omega_tensor_unary(g, OMEGA_TU_NEG, A, &N);
+    CHECK(rc == 0, "neg rc=%d", rc);
+    if (!rc) {
+        float *v = rd(N);
+        for (size_t i = 0; v && i < NSPECIAL; i++)
+            CHECK(omega_float_to_bits(v[i]) == neg_expect(SPECIALS[i]), "neg(%08x) = %08x want %08x",
+                  SPECIALS[i], omega_float_to_bits(v[i]), neg_expect(SPECIALS[i]));
+        free(v);
+        omega_tensor_release(g, N);
+    }
+    /* explicit pins: +0 -> -0 and -0 -> +0 (0 - x gets +0 wrong), NaN canonical */
+    float pins[3] = {omega_bits_to_float(0x00000000U), omega_bits_to_float(0x80000000U),
+                     omega_bits_to_float(0x7fa00001U)};
+    uint64_t s3[1] = {3};
+    OmegaTensor P = mk(1, s3, pins);
+    rc = omega_tensor_unary(g, OMEGA_TU_NEG, P, &N);
+    if (!rc) {
+        float *v = rd(N);
+        CHECK(v && omega_float_to_bits(v[0]) == 0x80000000U, "neg(+0) = -0");
+        CHECK(v && omega_float_to_bits(v[1]) == 0x00000000U, "neg(-0) = +0");
+        CHECK(v && omega_float_to_bits(v[2]) == 0x7fc00000U, "neg(sNaN payload) = canonical qNaN");
+        free(v);
+        omega_tensor_release(g, N);
+    } else CHECK(0, "neg pins rc=%d", rc);
+    omega_tensor_release(g, P);
+
+    /* NEG through views: transpose, strided slice, broadcast */
+    float m[3 * 4];
+    for (size_t i = 0; i < 12; i++) m[i] = omega_bits_to_float(SPECIALS[(i * 7) % NSPECIAL]);
+    uint64_t s34[2] = {3, 4};
+    OmegaTensor M = mk(2, s34, m), T, S, B;
+    CHECK(omega_tensor_transpose(g, M, &T) == 0, "transpose");
+    rc = omega_tensor_unary(g, OMEGA_TU_NEG, T, &N);
+    if (!rc) {
+        float *v = rd(N);
+        size_t bad = 0;
+        for (size_t r = 0; v && r < 4; r++)
+            for (size_t c = 0; c < 3; c++)
+                bad += omega_float_to_bits(v[r * 3 + c]) != neg_expect(omega_float_to_bits(m[c * 4 + r]));
+        CHECK(v && bad == 0, "neg of transposed view (%zu bad)", bad);
+        free(v);
+        omega_tensor_release(g, N);
+    } else CHECK(0, "neg transpose rc=%d", rc);
+    uint64_t st1[2] = {0, 1}, sp1[2] = {3, 4}, stp[2] = {2, 2};
+    CHECK(omega_tensor_slice(g, M, st1, sp1, stp, &S) == 0, "slice");  /* rows 0,2 ; cols 1,3 */
+    rc = omega_tensor_unary(g, OMEGA_TU_NEG, S, &N);
+    if (!rc) {
+        float *v = rd(N);
+        size_t bad = 0;
+        for (size_t r = 0; v && r < 2; r++)
+            for (size_t c = 0; c < 2; c++)
+                bad += omega_float_to_bits(v[r * 2 + c]) != neg_expect(omega_float_to_bits(m[(2 * r) * 4 + 1 + 2 * c]));
+        CHECK(v && bad == 0, "neg of strided slice (%zu bad)", bad);
+        free(v);
+        omega_tensor_release(g, N);
+    } else CHECK(0, "neg slice rc=%d", rc);
+    uint64_t sb[2] = {2, NSPECIAL};
+    CHECK(omega_tensor_broadcast_to(g, A, 2, sb, &B) == 0, "broadcast_to");
+    rc = omega_tensor_unary(g, OMEGA_TU_NEG, B, &N);
+    if (!rc) {
+        float *v = rd(N);
+        size_t bad = 0;
+        for (size_t r = 0; v && r < 2; r++)
+            for (size_t c = 0; c < NSPECIAL; c++)
+                bad += omega_float_to_bits(v[r * NSPECIAL + c]) != neg_expect(SPECIALS[c]);
+        CHECK(v && bad == 0, "neg of broadcast view (%zu bad)", bad);
+        free(v);
+        omega_tensor_release(g, N);
+    } else CHECK(0, "neg broadcast rc=%d", rc);
+    /* F16 refused; NEG works with no transc entry in the realization */
+    uint16_t hh[2] = {0x3c00, 0x0000};
+    uint64_t s2h[1] = {2};
+    OmegaTensor H;
+    CHECK(omega_tensor_from_data(g, OMEGA_DT_F16, 1, s2h, hh, &H) == 0, "f16 create");
+    CHECK(omega_tensor_unary(g, OMEGA_TU_NEG, H, &N) == OMEGA_TENSOR_ERR_DTYPE, "neg of F16 refused");
+    omega_tensor_release(g, H);
+    {
+        OmegaTensorRealization nt = *omega_tensor_cpu_realization();
+        nt.transc = NULL;
+        OmegaTensorCtx *c;
+        CHECK(omega_tensor_ctx_create(8, &nt, &c) == 0, "ctx without transc");
+        OmegaTensor X, Y;
+        float one[1] = {3.0f};
+        uint64_t s1[1] = {1};
+        CHECK(omega_tensor_from_f32(c, 1, s1, one, &X) == 0, "x");
+        rc = omega_tensor_unary(c, OMEGA_TU_NEG, X, &Y);
+        float r1 = 0.0f;
+        CHECK(rc == 0 && omega_tensor_read_f32(c, Y, &r1, 1) == 0 && omega_float_to_bits(r1) == 0xc0400000U,
+              "NEG served without transc entry (rc=%d)", rc);
+        omega_tensor_ctx_destroy(c);
+    }
+    /* sources are immutable: NEG made a new tensor */
+    CHECK(all_bits_eq(A, SPECIALS[0]) != (size_t)-1, "source readable after neg");
+    OmegaTensor all[] = {A, M, T, S, B};
+    for (size_t i = 0; i < sizeof(all) / sizeof(all[0]); i++) omega_tensor_release(g, all[i]);
+}
+
 /* ---- 8. determinism ------------------------------------------------------- */
 static void kat_digest(uint8_t out[32]) {
     uint64_t save = g_rng;
@@ -1302,6 +1459,7 @@ int main(void) {
     test_relu_unary();
     test_unary2_specials();
     test_trig_domain();
+    test_const_neg();
     test_determinism();
     /* every test released what it made */
     uint32_t lt, ls;
diff --git a/tools/tensor_mutations.sh b/tools/tensor_mutations.sh
index 8a019a59b..3352a10ab 100755
--- a/tools/tensor_mutations.sh
+++ b/tools/tensor_mutations.sh
@@ -28,7 +28,11 @@ RELU_NAN_PAYLOAD|omega_tensor.c|s/return OMEGA_QNAN_BITS;/return u;/
 TRANSC_RSQRT_ERF_SWAP|omega_tensor_cpu.c|s/= omega_math_rsqrt, \(.*\)= omega_math_erf,/= omega_math_erf, \1= omega_math_rsqrt,/
 GELU_VIEW_STRIDE|omega_tensor.c|s/gather(s, .in, src);/if (op == OMEGA_TU_GELU) { dense_strides(in.rank, in.shape, in.strides); } gather(s, \&in, src);/
 TRIG_SIN_COS_SWAP|omega_tensor_cpu.c|s/= omega_math_sin, \(.*\)= omega_math_cos,/= omega_math_cos, \1= omega_math_sin,/
-TRIG_DOMAIN_NUMBER|omega_tensor_cpu.c|s/out\[i\] = f(a\[i\]);/{ out[i] = f(a[i]); if ((op == OMEGA_TU_SIN || op == OMEGA_TU_COS) \&\& out[i] != out[i]) out[i] = 0.0f; }/'
+TRIG_DOMAIN_NUMBER|omega_tensor_cpu.c|s/out\[i\] = f(a\[i\]);/{ out[i] = f(a[i]); if ((op == OMEGA_TU_SIN || op == OMEGA_TU_COS) \&\& out[i] != out[i]) out[i] = 0.0f; }/
+ZEROS_NEG0|omega_tensor.c|s/shape, 0.0f, out)/shape, -0.0f, out)/
+NEG_SUB|omega_tensor.c|s/return u ^ 0x80000000U;/return omega_float_to_bits(0.0f - omega_bits_to_float(u));/
+NEG_NAN|omega_tensor.c|s/return 0x7fc00000U;/return u ^ 0x80000000U;/
+FULL_CANON|omega_tensor.c|s/uint32_t u = omega_float_to_bits(value);/uint32_t u = canon_bits(OMEGA_DT_F32, (const uint8_t *)\&value);/'
 
 # Baseline: the unmutated build must PASS, otherwise every mutant would
 # look "caught" (e.g. the test refusing an unsuitable FP environment).