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

branch main Branches Tags History

omega-mv / src / turing / ty_ctr1.h

96 lines · 4497 bytes Raw Blame History
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/* Turing Yield: read-only CTR1 search-trace reader (TY-2 data).
18 *
19 * Format source (read-only reference, Rust): aien-sovereign-core
20 * crates/crumbs/src/trace.rs:26 (TRACE_RECORD_BYTES = 247), :406-436
21 * (TraceRecord::encode_body field order), crates/crumbs/src/canon.rs:23-30
22 * (little-endian integers), trace.rs:460-475 (body || 32-byte BLAKE3 chain
23 * digest; files are headerless record streams, session.rs:196-203).
24 * Byte offsets in the 247-byte record:
25 * 0 "CTR1", 4 version u16 (=1), 6 kind u8, 7 result_class u8,
26 * 8 event_index u32, 12 parent u32, 16 child u32, 20 op_index u16,
27 * 22 op_origin u8, 23 prune u8, 24 verify u8, 25 fit u8, 26 hidden u8,
28 * 27 improved u8, 28 contributed u8, 29 depth u16, 31 op_id[32],
29 * 63 state_digest[32], 95 child_state_digest[32], 127 program_digest[32],
30 * 159 mismatch_before u16, 161 mismatch_after u16, 163 hamming_before u32,
31 * 167 hamming_after u32, 171 exec_cost u32, 175 search_cost u32,
32 * 179 program_steps u16, 181 oracle_index u16, 183 residual u64[4],
33 * 215 chain digest[32].
34 * The BLAKE3 chain is NOT verified here (no C BLAKE3 in the tree); integrity
35 * of the corpus is pinned by per-file SHA-256 instead (ty_record.h).
36 *
37 * The reader refuses (TY_E_FORMAT) any record outside the pinned value sets,
38 * so a corpus that drifted from the declared alphabet is never silently scored.
39 */
40#ifndef TURING_TY_CTR1_H
41#define TURING_TY_CTR1_H
42
43#include <stddef.h>
44#include <stdint.h>
45
46#define TY_CTR1_BYTES 247
47#define TY_CTR1_NOPS 15 /* base bank: src/omega_synthesis.c:11-27 via cl_program.c:149 */
48#define TY_OP_SUBMIT 15 /* op feature value used for SUBMIT events */
49#define TY_DEPTH_CLIP 7
50
51/* x_t: one outcome symbol per search event (profile section 3). */
52enum {
53 TY_O_P_EQUIV = 0, /* EXPAND, prune = CL_PRUNE_EQUIV */
54 TY_O_P_COST = 1, /* EXPAND, prune = CL_PRUNE_COST */
55 TY_O_P_FRONTIER = 2, /* EXPAND, prune = CL_PRUNE_FRONTIER_CAP */
56 TY_O_P_STEPCAP = 3, /* EXPAND, prune = CL_PRUNE_STEP_CAP */
57 TY_O_FAILED = 4, /* EXPAND, not pruned, result_class Failed */
58 TY_O_PARTIAL = 5, /* EXPAND, not pruned, result_class Partial */
59 TY_O_IMPROVED = 6, /* EXPAND, not pruned, result_class Improved */
60 TY_O_ACCEPT = 7, /* SUBMIT, result_class Verified */
61 TY_O_REJECT = 8, /* SUBMIT, result_class RejectedHidden or RejectedRobust */
62 TY_OUT_K = 9
63};
64
65/* One event: the coded symbol and the side information a model may condition on. */
66typedef struct {
67 uint8_t sym; /* x_t, 0..K-1 */
68 uint8_t op; /* op_index for EXPAND (0..14), TY_OP_SUBMIT for SUBMIT */
69 uint8_t depth; /* min(depth, TY_DEPTH_CLIP) */
70 uint8_t first; /* 1 = first event of a crumb (context resets) */
71 uint16_t crumb; /* crumb ordinal within its file (saturates at 65535) */
72 uint32_t idx; /* event_index within the crumb */
73} ty_ev;
74
75typedef struct {
76 ty_ev *ev;
77 size_t n, cap;
78 uint32_t ncrumb;
79 uint64_t gaps; /* event_index jumps inside a crumb (derive() skipped events) */
80} ty_stream;
81
82void ty_stream_init(ty_stream *s);
83void ty_stream_free(ty_stream *s);
84int ty_stream_push(ty_stream *s, const ty_ev *e);
85
86/* Map one raw 247-byte record to an event, refusing out-of-set values.
87 * prev_idx: event_index of the previous record in the same file, or -1 at the
88 * start of the file. On success *starts_crumb says whether it opens a crumb. */
89int ty_ctr1_decode(const uint8_t rec[TY_CTR1_BYTES], int64_t prev_idx, ty_ev *out, char *why, size_t whylen);
90
91/* Read a whole CTR1 file, appending to s. Checks: size % 247 == 0, every
92 * record passes ty_ctr1_decode, first record opens a crumb. Returns the number
93 * of records read, or a negative TY_E_* code with a reason in why. */
94int64_t ty_ctr1_read(const char *path, ty_stream *s, char *why, size_t whylen);
95
96#endif /* TURING_TY_CTR1_H */