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 / physics0 / pd0_gen.h

78 lines · 4079 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/* PD-0 hidden generators (spec section 4 and 9.1 NC-1). THE ONLY place the
18 * equations live. Included by pd0_world.c (world process), pd0_oracle.c and
19 * pd0_score.c (harness side). The learner, ladder checker and planner must
20 * never include this header or link pd0_gen.o: tests/physics0/isolation.sh
21 * greps their symbol tables for every pd0_gen_* symbol (spec G5). */
22#ifndef PD0_GEN_H
23#define PD0_GEN_H
24
25#include <stdint.h>
26
27#include "physics0/pd0_relation.h"
28#include "physics0/pd0_rng.h"
29#include "physics0/pd0_wire.h"
30
31enum { PD0_L0 = 0, PD0_L1, PD0_L2, PD0_L3, PD0_L4, PD0_L5, PD0_L6, PD0_LEVEL_NULL = 7, PD0_LEVELS = 8 };
32#define PD0_MAX_CONST 4
33#define PD0_L6_REDRAW_CAP 1000 /* spec 4.1 rev 3 */
34
35/* one declared constant range (micro), in draw order; the single table the
36 * generator draws from and the oracle range check reads (spec 4.1) */
37typedef struct { const char *name; int64_t lo, hi; } pd0_crange;
38
39typedef struct {
40 int level;
41 int64_t k[PD0_MAX_CONST]; /* constants in draw order (micro) */
42 int64_t sigma_obs; /* L5 observation noise, else 0 */
43 int64_t sigma_null; /* NULL world draw sd, else 0 */
44 int n_hidden; /* L6: 1 */
45 int redraws; /* L6: m,q redraws used by the 0.7*k stability rule (spec 4.1 rev 3) */
46 int invalid; /* L6: 1 if the redraw cap was reached: the seed is invalid and skipped */
47} pd0_gen;
48
49const char *pd0_gen_level_name(int level);
50/* describe record for a level (spec table section 4) */
51int pd0_gen_desc(int level, pd0_desc *d);
52/* declared constant ranges of a level in draw order; returns the count (0: none) */
53int pd0_gen_const_table(int level, const pd0_crange **t);
54/* reset box of observed variable var (spec 4 rev 3; the describe record carries all of them) and scoring boxes (spec 6.1 rev 3:
55 * in-box = reset box, extrap = 1.5 x it) */
56void pd0_gen_reset_box(int level, int var, int64_t *lo, int64_t *hi);
57void pd0_gen_score_box(int level, int var, int extrap, int64_t *lo, int64_t *hi);
58/* draw the level's constants from the "const" stream of seed; returns -1 for an invalid
59 * L6 seed (redraw cap reached, g->invalid set, g->redraws recorded) */
60int pd0_gen_init(pd0_gen *g, int level, uint64_t seed);
61int pd0_gen_init_cap(pd0_gen *g, int level, uint64_t seed, int redraw_cap); /* cap is a parameter for tests */
62/* one tick: old state in, new state out (explicit Euler, simultaneous).
63 * u[] has one entry per channel (undriven channels 0). noise/null streams are
64 * the world's; obs_out receives what the learner sees (state + noise, or the
65 * null draw). Returns 1 if any observed or hidden variable left +-PD0_BOUND
66 * (state_out then holds the offending values but must not be revealed). */
67int pd0_gen_step(const pd0_gen *g, const int64_t *s_in, int64_t h_in, const int64_t *u, int64_t dt,
68 int64_t *s_out, int64_t *h_out, int64_t *obs_out, pd0_rng *noise, pd0_rng *null);
69/* observation of a reset (noise for L5, else the state) */
70void pd0_gen_observe_reset(const pd0_gen *g, const int64_t *s, int64_t *obs_out, pd0_rng *noise);
71/* the true relation in PDLAW1 delta form (coefficients in micro, dt folded
72 * in), for the oracle (section 4.2 V1) and the 6.3 structure check.
73 * NULL world: 0 equations. */
74int pd0_gen_true_relation(const pd0_gen *g, int64_t dt, pd0_relation *out);
75/* S* of section 6.2 */
76int pd0_gen_true_size(int level);
77
78#endif