Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
296 changes: 296 additions & 0 deletions specs/physics/sacred_lattice.t27
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
// SPDX-License-Identifier: Apache-2.0
// specs/physics/sacred_lattice.t27 -- the formula V = n * 3^k * pi^m * phi^p * e^q as an ADDRESS of a
// number, with the chance of every fit measured, not assumed.
//
// THE MODEL (D. Vasilev, S. Pellis, "Low-Complexity Algebraic Representations of Physical Constants",
// April 2026, eq. 1-2 and 4): for n in 1..9 and integers k, m, p, q with |k| + |m| + |p| + |q| <= C,
// ln V = ln n + k ln 3 + m ln pi + p ln phi + q.
// So the grammar is a lattice in log space, and the best fit of a target X is the nearest lattice
// point to ln X. Five small integers name a number: that is a codec, and this spec keeps it as one
// (`best_code` packs the five into one i64, `code_value` unpacks it).
//
// WHAT A FIT IS WORTH. A lattice dense enough fits anything. Measured on the Railway lab, 2026-10-18,
// 200 000 log-uniform random targets in [1e-3, 1e4]:
// C = 4: 2 889 points, P(err < 0.1%) = 22.5%, median err 0.315%
// C = 6: 11 601 points, P(err < 0.1%) = 62.3%, median err 0.072%, P(err < 0.01%) = 9.0%
// C = 8: 32 841 points, P(err < 0.1%) = 93.6%, median err 0.026%
// Those numbers follow a Poisson law, P(err < x) = 1 - exp(-2 x RHO), with RHO = 483 points per unit
// of ln at C = 6 (it gives 62% and 9.2%). `chance` is that law. The ten dimensionless targets in
// `REAL_*` below fit within 0.1% at C = 6 six times out of ten -- the rate a random number gets.
// The grid of the 2026-02 TZ (each exponent -20..20, no cap) has 25 431 849 points: it fits any
// number to about 1e-5, so a fit on it carries no information at all.
//
// WHAT IT DOES NOT CLAIM: no fit here is a derivation, and none is labelled EXACT or DERIVED. A fit
// is SUGGESTED only when its chance, multiplied by the number of targets tried, is under 5%; none of
// the ten passes. m_p/m_e = 6 pi^5 (18.8 ppm) is the best of them and is Lenz's 1951 observation
// (F. Lenz, Phys. Rev. 82, 554), not a new one; its chance is 1.8% per target, 17% over ten.
// Fits of quantities with units (m_H in GeV, H0 in km/s/Mpc, T_CMB in K, an age in Gyr) are not
// made: changing the unit moves the target and the lattice still fits it.
// alpha_phi = phi^-3 / 2 (the paper's eq. 11) is not in the grammar, n = 1/2 is not in 1..9; the
// nearest grammar point is 3 * 3^-2 * phi^2 * e^-2, 594 ppm away.
// Physics that needs a constant reads the measured value (CODATA 2022, PDG 2024): see
// specs/t27f/particle_field.t27, which never takes a constant from this lattice.
// phi^2 + 1/phi^2 = 3 | TRINITY

module sacred_lattice {

pub const PHI : f64 = 1.6180339887498948;
pub const LN3 : f64 = 1.0986122886681098;
pub const LNPI : f64 = 1.1447298858494002;
pub const LNPHI : f64 = 0.48121182505960347;
pub const RHO_C6 : f64 = 483.0; // effective points per unit of ln at C = 6 (lab, 200k targets)
pub const LN_LO : f64 = -6.907755278982137; // ln 1e-3
pub const LN_HI : f64 = 9.210340371976184; // ln 1e4

pub const LABEL_EXACT : u8 = 0; // an identity: holds to the last bit (phi^2 + phi^-2 = 3)
pub const LABEL_MEASURED : u8 = 1; // CODATA / PDG value with its uncertainty
pub const LABEL_SUGGESTED : u8 = 2; // a lattice fit unlikely to be chance after all trials
pub const LABEL_UNKNOWN : u8 = 3; // a lattice fit at the chance rate: says nothing

// Ten dimensionless targets (CODATA 2022, PDG 2024 central values).
pub const REAL_ALPHA_INV : f64 = 137.035999177;
pub const REAL_MP_ME : f64 = 1836.15267343;
pub const REAL_MMU_ME : f64 = 206.7682830;
pub const REAL_MTAU_ME : f64 = 3477.23;
pub const REAL_SIN2_THW : f64 = 0.23122;
pub const REAL_ALPHA_S : f64 = 0.1180;
pub const REAL_OMEGA_L : f64 = 0.6847;
pub const REAL_SIN2_TH12 : f64 = 0.307;
pub const REAL_SIN2_TH23 : f64 = 0.546;
pub const REAL_VUS : f64 = 0.2243;
pub const ALPHA_S_SIGMA : f64 = 0.0009; // PDG 2024 world average uncertainty

fn iabs(x: i64) -> i64 {
if (x < 0) {
return 0 - x;
}
return x;
}

// ln of the lattice point (n, k, m, p, q).
fn address_ln(n: i64, k: i64, m: i64, p: i64, q: i64) -> f64 {
return @log(n as f64) + (k as f64) * LN3 + (m as f64) * LNPI + (p as f64) * LNPHI + (q as f64);
}

fn value(n: i64, k: i64, m: i64, p: i64, q: i64) -> f64 {
return @exp(address_ln(n, k, m, p, q));
}

// Relative distance between two positive numbers given by their logs.
fn rel_from_ln(a: f64, b: f64) -> f64 {
return @abs(@exp(a - b) - 1.0);
}

// Number of grammar points at complexity C (n in 1..9).
fn lattice_size(c: i64) -> i64 {
var count : i64 = 0;
var k : i64 = 0 - c;
while (k <= c) {
var m : i64 = 0 - c;
while (m <= c) {
var p : i64 = 0 - c;
while (p <= c) {
var q : i64 = 0 - c;
while (q <= c) {
if (iabs(k) + iabs(m) + iabs(p) + iabs(q) <= c) {
count = count + 9;
}
q = q + 1;
}
p = p + 1;
}
m = m + 1;
}
k = k + 1;
}
return count;
}

// Pack an address into one i64: n, then k, m, p, q each offset by 32 in base 64.
fn pack(n: i64, k: i64, m: i64, p: i64, q: i64) -> i64 {
return (((n * 64 + (k + 32)) * 64 + (m + 32)) * 64 + (p + 32)) * 64 + (q + 32);
}

fn code_n(code: i64) -> i64 {
return @divTrunc(code, 16777216);
}

fn code_digit(code: i64, place: i64) -> i64 {
var c : i64 = code;
var i : i64 = 0;
while (i < place) {
c = @divTrunc(c, 64);
i = i + 1;
}
return @mod(c, 64) - 32;
}

fn code_value(code: i64) -> f64 {
return value(code_n(code), code_digit(code, 3), code_digit(code, 2), code_digit(code, 1), code_digit(code, 0));
}

// The nearest grammar point to x at complexity C, as a packed address.
fn best_code(x: f64, c: i64) -> i64 {
const t = @log(x);
var best : f64 = 1.0e9;
var code : i64 = 0;
var k : i64 = 0 - c;
while (k <= c) {
var m : i64 = 0 - c;
while (m <= c) {
var p : i64 = 0 - c;
while (p <= c) {
var q : i64 = 0 - c;
while (q <= c) {
if (iabs(k) + iabs(m) + iabs(p) + iabs(q) <= c) {
var n : i64 = 1;
while (n <= 9) {
const e = rel_from_ln(address_ln(n, k, m, p, q), t);
if (e < best) {
best = e;
code = pack(n, k, m, p, q);
}
n = n + 1;
}
}
q = q + 1;
}
p = p + 1;
}
m = m + 1;
}
k = k + 1;
}
return code;
}

fn best_err(x: f64, c: i64) -> f64 {
return @abs(code_value(best_code(x, c)) / x - 1.0);
}

// Chance that a random target lands this close to some lattice point (Poisson law, see header).
fn chance(err: f64, rho: f64) -> f64 {
return 1.0 - @exp(0.0 - 2.0 * err * rho);
}

// A fit is SUGGESTED only when it would be rare even after `trials` targets were tried.
fn label(err: f64, rho: f64, trials: f64) -> u8 {
if (chance(err, rho) * trials < 0.05) {
return LABEL_SUGGESTED;
}
return LABEL_UNKNOWN;
}

// Deterministic log-uniform targets in [1e-3, 1e4]: the null model, reproducible bit for bit.
fn lcg(seed: i64) -> i64 {
return @mod(seed * 1103515245 + 12345, 2147483648);
}

fn null_hits(count: i64, seed0: i64, c: i64, tol: f64) -> i64 {
var seed : i64 = seed0;
var hits : i64 = 0;
var i : i64 = 0;
while (i < count) {
seed = lcg(seed);
const u = (seed as f64) / 2147483648.0;
const x = @exp(LN_LO + u * (LN_HI - LN_LO));
if (best_err(x, c) < tol) {
hits = hits + 1;
}
i = i + 1;
}
return hits;
}

fn real_hits(c: i64, tol: f64) -> i64 {
var h : i64 = 0;
if (best_err(REAL_ALPHA_INV, c) < tol) { h = h + 1; }
if (best_err(REAL_MP_ME, c) < tol) { h = h + 1; }
if (best_err(REAL_MMU_ME, c) < tol) { h = h + 1; }
if (best_err(REAL_MTAU_ME, c) < tol) { h = h + 1; }
if (best_err(REAL_SIN2_THW, c) < tol) { h = h + 1; }
if (best_err(REAL_ALPHA_S, c) < tol) { h = h + 1; }
if (best_err(REAL_OMEGA_L, c) < tol) { h = h + 1; }
if (best_err(REAL_SIN2_TH12, c) < tol) { h = h + 1; }
if (best_err(REAL_SIN2_TH23, c) < tol) { h = h + 1; }
if (best_err(REAL_VUS, c) < tol) { h = h + 1; }
return h;
}

fn trinity(phi: f64) -> f64 {
return phi * phi + 1.0 / (phi * phi);
}

// Points of the uncapped grid with every exponent in -span..span.
fn grid_size(span: i64) -> i64 {
const w = 2 * span + 1;
return 9 * w * w * w * w;
}

test "the trinity identity is exact: phi^2 + phi^-2 = 3" {
assert(@abs(trinity(PHI) - 3.0) < 1.0e-15);
assert(@abs(trinity((1.0 + @sqrt(5.0)) / 2.0) - 3.0) < 1.0e-15);
}

test "the lattice sizes match the lab count" {
assert(lattice_size(4) == 2889);
assert(lattice_size(6) == 11601);
assert(lattice_size(8) == 32841);
}

test "the TZ grid -20..20 has 25 431 849 points" {
assert(grid_size(20) == 25431849);
}

test "an address round-trips through its packed code" {
const code = pack(4, 2, 0 - 1, 1, 2);
assert(code_n(code) == 4);
assert(code_digit(code, 3) == 2);
assert(code_digit(code, 2) == 0 - 1);
assert(code_digit(code, 1) == 1);
assert(code_digit(code, 0) == 2);
}

test "1/alpha sits at 4 * 3^2 * pi^-1 * phi * e^2, 243 ppm away" {
const code = best_code(REAL_ALPHA_INV, 6);
assert(code == pack(4, 2, 0 - 1, 1, 2));
const e = best_err(REAL_ALPHA_INV, 6);
assert(e > 0.000242 && e < 0.000244);
assert(label(e, RHO_C6, 10.0) == LABEL_UNKNOWN);
}

test "m_p/m_e = 6 pi^5 is the best fit and is still not SUGGESTED over ten targets" {
assert(best_code(REAL_MP_ME, 6) == pack(6, 0, 5, 0, 0));
const e = best_err(REAL_MP_ME, 6);
assert(e > 0.0000187 && e < 0.0000189);
assert(chance(e, RHO_C6) > 0.017 && chance(e, RHO_C6) < 0.019);
assert(label(e, RHO_C6, 10.0) == LABEL_UNKNOWN);
assert(label(e, RHO_C6, 1.0) == LABEL_SUGGESTED);
}

test "the Poisson law reproduces the lab null rates at C = 6" {
assert(@abs(chance(0.001, RHO_C6) - 0.623) < 0.01);
assert(@abs(chance(0.0001, RHO_C6) - 0.090) < 0.005);
}

test "random numbers fit within 0.1% as often as the real constants do" {
assert(null_hits(64, 27, 6, 0.001) == 42);
assert(real_hits(6, 0.001) == 6);
// 42/64 = 66% for noise, 6/10 = 60% for physics: no excess over chance.
}

test "alpha_s is measured too coarsely to test any lattice point" {
assert(chance(ALPHA_S_SIGMA / REAL_ALPHA_S, RHO_C6) > 0.99);
}

test "phi^-3 / 2 is not a grammar point; the nearest one is 594 ppm off" {
const x = (@sqrt(5.0) - 2.0) / 2.0;
assert(best_code(x, 6) == pack(3, 0 - 2, 0, 2, 0 - 2));
assert(@abs(best_err(x, 6) - 0.000594) < 0.000001);
}

invariant "no lattice fit is ever labelled exact or measured" {
assert(label(0.0, RHO_C6, 1.0) == LABEL_SUGGESTED);
assert(label(1.0, RHO_C6, 1.0) == LABEL_UNKNOWN);
}
}
Loading
Loading