Recovered source transcript
1#pragma once
2#include <array>
3#include <cmath>
4#include <cstdint>
5#include <cstring>
6#include <vector>
7#include <unordered_map>
8
9namespace g16v2 {
10
11// Golden ratio constants
12constexpr double PHI = 1.6180339887498948482;
13constexpr double PSI = 0.6180339887498948482;
14constexpr double SQRT5 = 2.2360679774997896964;
15constexpr double PI = 3.1415926535897932385;
16
17// Dimension constants
18constexpr int NUM_FAMILIES = 16;
19constexpr int NUM_PLANES = 8; // 16D = 8 complex planes
20constexpr int DNA_DIM = 256;
21
22// 5000-substrate upgrade sizes
23constexpr int F = 16; // families
24constexpr int S = 5000; // substrates per family (upper bound)
25
26// Precomputed Fibonacci numbers (first 50)
27constexpr std::array<uint64_t, 50> FIB = {
28 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
29 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418,
30 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465,
31 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296,
32 433494437, 701408733, 1134903170, 1836311903, 2971215073ULL, 4807526976ULL,
33 7778742049ULL
34};
35
36// Precomputed cumulative Fibonacci (learning tick indices)
37// T[n] = F[n+2] - 1
38constexpr std::array<uint64_t, 45> FIB_CUMULATIVE = {
39 1, 2, 4, 7, 12, 20, 33, 54, 88, 143, 232, 376, 609, 986, 1596, 2583,
40 4180, 6764, 10945, 17710, 28656, 46367, 75024, 121392, 196417, 317810,
41 514228, 832039, 1346268, 2178308, 3524577, 5702886, 9227464, 14930351,
42 24157816, 39088168, 63245985, 102334154, 165580140, 267914295, 433494436,
43 701408732, 1134903169, 1836311902, 2971215072ULL
44};
45
46// Precomputed rotation frequencies ω[k] = 2π / φ^k
47constexpr std::array<double, NUM_PLANES> OMEGA = {
48 3.8832220774509332, 2.3999631939115080, 1.4832588835394252,
49 0.9167043103720828, 0.5665545731673424, 0.3501497372047404,
50 0.2164048359626020, 0.1337449012421384
51};
52
53// Precomputed coupling eigenvalues λ[k] = (2π / φ^k)²
54constexpr std::array<double, NUM_PLANES> LAMBDA = {
55 15.0794190748, 5.7598232438, 2.2000053977, 0.8403468544,
56 0.3209780697, 0.1226047960, 0.0468310987, 0.0178877485
57};
58
59// Meta-state vector (16D)
60struct Psi {
61 std::array<double, NUM_FAMILIES> x{};
62
63 double norm() const {
64 double sum = 0.0;
65 for (int i = 0; i < NUM_FAMILIES; ++i) sum += x[i] * x[i];
66 return std::sqrt(sum);
67 }
68 double norm_sq() const {
69 double sum = 0.0;
70 for (int i = 0; i < NUM_FAMILIES; ++i) sum += x[i] * x[i];
71 return sum;
72 }
73};
74
75// Per-family coherence
76struct Phi {
77 std::array<double, NUM_FAMILIES> phi{}; // φ_f for each family
78 double global = 0.5; // Φ_global = 1 / (1 + |Ω|)
79};
80
81// Signal vector (extracted from federation)
82struct Signals {
83 double dx_norm = 0.0; // |coh(t) - coh(t-1)|
84 double ed_error = 0.5; // |coh* - coh(t)|
85 double utility = 0.5; // 0.5 * cons + 0.5 * coh
86 double stability = 1.0; // 1 - dx_norm
87};
88
89// Objective decomposition
90struct Omega {
91 double surprise = 0.0; // S = α₁‖ΔΨ‖₁ + α₂‖ΔΨ‖₂²
92 double uncertainty = 0.0; // U = 1 - b²
93 double value = 0.0; // V = u · ⟨w, Ψ⟩
94 double penalty = 0.0; // P = λ · ‖Δcoh‖²
95 double total = 0.0; // Ω = S + U - V + P
96};
97
98// Rotation matrix helper (values are recomputed per tick)
99struct GoldenRotation {
100 std::array<double, NUM_PLANES> cos_theta{};
101 std::array<double, NUM_PLANES> sin_theta{};
102 void init() {
103 for (int k = 0; k < NUM_PLANES; ++k) {
104 cos_theta[k] = std::cos(OMEGA[k]);
105 sin_theta[k] = std::sin(OMEGA[k]);
106 }
107 }
108};
109
110// Coupling matrix J (symmetric 16x16)
111struct CouplingMatrix {
112 std::array<std::array<double, NUM_FAMILIES>, NUM_FAMILIES> J{};
113 double get(int f, int g) const { return J[f][g]; }
114 void set(int f, int g, double val) { J[f][g] = val; J[g][f] = val; }
115};
116
117// Family mapping metadata
118struct FamilyInfo {
119 int index;
120 const char* name;
121 const char* domain;
122};
123
124constexpr std::array<FamilyInfo, NUM_FAMILIES> FAMILIES = {{
125 {0, "Athena", "Strategy"},
126 {1, "Iris", "Vision"},
127 {2, "Hermes", "Communication"},
128 {3, "Prometheus", "Creation"},
129 {4, "Apollo", "Harmony"},
130 {5, "Hephaestus", "Craft"},
131 {6, "Demeter", "Growth"},
132 {7, "Poseidon", "Flow"},
133 {8, "Hera", "Governance"},
134 {9, "Ares", "Competition"},
135 {10, "Yad", "Programming"},
136 {11, "Lashon", "Language"},
137 {12, "Chronos", "Time"},
138 {13, "Mnemosyne", "Memory"},
139 {14, "Hypnos", "Rest"},
140 {15, "Thanatos", "Pruning"}
141}};
142
143// Plane mapping
144constexpr std::array<std::pair<int, int>, NUM_PLANES> PLANE_FAMILIES = {{
145 {0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}, {10, 11}, {12, 13}, {14, 15}
146}};
147
148constexpr std::array<std::pair<int, int>, NUM_PLANES> SEMANTIC_PLANES = {{
149 {0, 8}, // Athena-Hera
150 {10, 11}, // Yad-Lashon
151 {5, 10}, // Hephaestus-Yad
152 {13, 14}, // Mnemosyne-Hypnos
153 {3, 4}, // Prometheus-Apollo
154 {2, 7}, // Hermes-Poseidon
155 {6, 15}, // Demeter-Thanatos
156 {1, 9} // Iris-Ares
157}};
158
159// Full system state
160struct SystemState {
161 Psi psi;
162 Psi psi_prev;
163 Phi phi;
164 Signals signals;
165 Omega omega;
166 double b = 1.0;
167 double kappa = 0.0;
168 double gamma = 0.5;
169 uint64_t tick = 0;
170 uint64_t fib_index = 0;
171 uint64_t items_ingested = 0;
172 std::array<double, NUM_FAMILIES> learning_rates{};
173};
174
175// Configuration
176struct Config {
177 // Weights (calibrated)
178 std::array<double, NUM_FAMILIES> w{};
179
180 // Controller parameters
181 double gamma_min = 0.1;
182 double alpha1 = 0.5;
183 double alpha2 = 0.5;
184 double lambda = 0.1;
185
186 // Federation parameters
187 double target_coh = 0.8;
188 double lr_base = 0.05;
189 double lr_gain = 0.2;
190
191 // Ingestion parameters
192 double ingest_gate = 0.2;
193 int ingest_max = 200;
194
195 // Extension flags
196 bool use_fibonacci_timing = true;
197 bool use_golden_spiral = true;
198 bool use_cross_family_resonance = true;
199 bool use_semantic_planes = true;
200};
201
202// ---------------------------------------------------------------------------
203// 5000-substrate upgrade: per-substrate state and AGI state
204// ---------------------------------------------------------------------------
205struct SubstrateState {
206 float phi = 0.0f; // Coherence [0,1]
207 float kappa_real = 0.5f; // Verification confidence [0,1]
208 float nu = 1.0f; // Novelty (decays over time)
209 uint32_t last_tick = 0; // Last update tick
210};
211
212struct FamilyState {
213 std::vector<SubstrateState> substrates; // sparse
214 std::unordered_map<uint16_t, size_t> active_index; // substrate_id -> vec index
215 float Psi = 0.5f; // Pressure
216 float eta = 0.01f; // Plasticity
217 uint32_t served = 0; // Fairness counter
218};
219
220struct AGIState {
221 uint32_t id = 0;
222 std::array<FamilyState, F> families{};
223 float Phi_global = 0.1f; // Global coherence
224 float Omega = 0.0f; // Cumulative regret
225 uint64_t tick = 0;
226 uint64_t knowledge_bits = 0;
227};
228
229} // namespace g16v2
230