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 / src / turing / ty_prd2.h
| 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 | /* PRD2: mixture-capable prediction file (EXP-002D Stage A). New files only; |
| 18 | * PRD1 (ty_prd.*) and the qint.v1 Gaussian scorer (ty_qcont.*) are not changed. |
| 19 | * Format: docs/turing/PRD2_PREDICTION_FORMAT.md. Header "PRD2", u32 version 2, |
| 20 | * u32 count, u32 first_index; record: u32 index, u32 family, u32 K, u32 reserved, |
| 21 | * then K x (f64 pi, f64 loc, f64 scale). Family 0 needs K = 1 and pi = 1 exactly; |
| 22 | * family 2 needs 1 <= K <= 8, each 0 < pi <= 1, |sum pi - 1| <= 1e-9. Nothing is |
| 23 | * renormalized. Every refusal is TYQ_FAIL_PROTOCOL plus a reason code. */ |
| 24 | #ifndef TURING_TY_PRD2_H |
| 25 | #define TURING_TY_PRD2_H |
| 26 | |
| 27 | #include "turing/ty_qcont.h" |
| 28 | |
| 29 | enum tyq_prd2_reason { |
| 30 | PRD2_R_NONE = 0, |
| 31 | PRD2_R_MAGIC, PRD2_R_VERSION, PRD2_R_SIZE, PRD2_R_COUNT, PRD2_R_INDEX, |
| 32 | PRD2_R_FAMILY, PRD2_R_K, PRD2_R_RESERVED, |
| 33 | PRD2_R_WEIGHT_NONFINITE, PRD2_R_WEIGHT_RANGE, PRD2_R_WEIGHT_SUM, PRD2_R_GAUSS_WEIGHT, |
| 34 | PRD2_R_LOC, PRD2_R_SCALE |
| 35 | }; |
| 36 | const char *tyq_prd2_reason_name(int r); |
| 37 | |
| 38 | typedef struct { uint32_t n, first_index; tyq_pred *rec; } ty_prd2; |
| 39 | |
| 40 | /* Family 0: comp[0] holds pi/loc/scale and K == 1 (loc/scale mirrored into p->loc/scale). |
| 41 | * Family 2: comp[0..K-1]. reason may be NULL. */ |
| 42 | int ty_prd2_validate(const tyq_pred *p, int *reason); |
| 43 | int ty_prd2_parse(const uint8_t *buf, size_t len, uint32_t first_index, uint32_t count, |
| 44 | ty_prd2 *out, int *reason); |
| 45 | int ty_prd2_encode(const ty_prd2 *p, uint8_t **buf, size_t *len); |
| 46 | void ty_prd2_free(ty_prd2 *p); |
| 47 | |
| 48 | /* qint.v1 bits of a validated PRD2 record (Gaussian delegates to ty_qcont_bits; |
| 49 | * mixture = -log2 sum_j pi_j 2^-b_j, floor hit if any component was raised). */ |
| 50 | int ty_qcont2_bits(const tyq_pred *p, int64_t k, double *bits, int *floor_hit); |
| 51 | int ty_qcont2_point_ub(const tyq_pred *p, int64_t k, int64_t *ub, int *floor_hit); |
| 52 | int ty_qcont2_sum_ub(const tyq_pred *p, const int64_t *k, size_t n, |
| 53 | int64_t *ld_ub, uint64_t *floor_hits); |
| 54 | |
| 55 | #endif |