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_rng.h

58 lines · 2536 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 randomness (spec PD0_HIDDEN_EQUATION_BENCHMARK.md section 3).
18 *
19 * SplitMix64 with Vigna's published constants (increment 0x9E3779B97F4A7C15,
20 * mixers 0xBF58476D1CE4E5B9 and 0x94D049BB133111EB). The same constants are
21 * already in this repo at src/turing/history_selector.c:23-28
22 * (turing_splitmix64) and src/compiler/model/osc_model_gen.c:44; the test
23 * tests/physics0/test_pd0_world.c checks this stream against
24 * turing_splitmix64 symbol for symbol, which is the "record the check"
25 * the spec asks for (section 3, first bullet).
26 *
27 * stream(seed, tag) = SplitMix64 seeded with seed XOR fnv1a64(tag).
28 * uniform: next() % 1_000_001 (micro-units in [0, 1.0]).
29 * const draw in [lo, hi]: lo + ((hi - lo) * u) / 1_000_000.
30 * Irwin-Hall noise (four uniforms, sd of the sum 577_350 micro):
31 * e = ((u1+u2+u3+u4) - 2_000_000) * sigma / 577_350.
32 * Shared by the world (constants, noise, null) and the harness (scorer,
33 * planner seeds). Contains no generator knowledge. */
34#ifndef PD0_RNG_H
35#define PD0_RNG_H
36
37#include <stdint.h>
38
39#define PD0_MICRO 1000000LL
40#define PD0_IH_SD 577350LL /* sd of the sum of four uniforms on [0, 1e6] */
41
42/* same pedantic-safe spelling as ty_math.h:30 (ty_u128) */
43__extension__ typedef __int128 pd0_i128;
44
45typedef struct { uint64_t s; } pd0_rng;
46
47uint64_t pd0_fnv1a64(const char *tag);
48uint64_t pd0_splitmix64(uint64_t *s);
49void pd0_stream(pd0_rng *r, uint64_t seed, const char *tag);
50uint64_t pd0_next(pd0_rng *r);
51int64_t pd0_uniform(pd0_rng *r); /* 0 .. 1_000_000 */
52int64_t pd0_const(pd0_rng *r, int64_t lo, int64_t hi); /* micro-units */
53int64_t pd0_noise(pd0_rng *r, int64_t sigma_micro);
54/* product rescale: (a*b)/1e6 in 128-bit, truncating toward zero (spec 2.1) */
55int64_t pd0_mul(int64_t a, int64_t b);
56int64_t pd0_div(int64_t a, int64_t b); /* truncating, b != 0 */
57
58#endif