@mneme-ai/core 2.19.46 → 2.19.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/chronosheaf/aczel.d.ts +72 -0
  2. package/dist/chronosheaf/aczel.d.ts.map +1 -0
  3. package/dist/chronosheaf/aczel.js +161 -0
  4. package/dist/chronosheaf/aczel.js.map +1 -0
  5. package/dist/chronosheaf/chronosheaf.test.d.ts +12 -0
  6. package/dist/chronosheaf/chronosheaf.test.d.ts.map +1 -0
  7. package/dist/chronosheaf/chronosheaf.test.js +360 -0
  8. package/dist/chronosheaf/chronosheaf.test.js.map +1 -0
  9. package/dist/chronosheaf/free_energy.d.ts +109 -0
  10. package/dist/chronosheaf/free_energy.d.ts.map +1 -0
  11. package/dist/chronosheaf/free_energy.js +142 -0
  12. package/dist/chronosheaf/free_energy.js.map +1 -0
  13. package/dist/chronosheaf/index.d.ts +35 -0
  14. package/dist/chronosheaf/index.d.ts.map +1 -0
  15. package/dist/chronosheaf/index.js +27 -0
  16. package/dist/chronosheaf/index.js.map +1 -0
  17. package/dist/chronosheaf/pain_catalog.d.ts +50 -0
  18. package/dist/chronosheaf/pain_catalog.d.ts.map +1 -0
  19. package/dist/chronosheaf/pain_catalog.js +108 -0
  20. package/dist/chronosheaf/pain_catalog.js.map +1 -0
  21. package/dist/chronosheaf/persistence.d.ts +79 -0
  22. package/dist/chronosheaf/persistence.d.ts.map +1 -0
  23. package/dist/chronosheaf/persistence.js +173 -0
  24. package/dist/chronosheaf/persistence.js.map +1 -0
  25. package/dist/chronosheaf/rg_flow.d.ts +81 -0
  26. package/dist/chronosheaf/rg_flow.d.ts.map +1 -0
  27. package/dist/chronosheaf/rg_flow.js +146 -0
  28. package/dist/chronosheaf/rg_flow.js.map +1 -0
  29. package/dist/chronosheaf/sheaf.d.ts +116 -0
  30. package/dist/chronosheaf/sheaf.d.ts.map +1 -0
  31. package/dist/chronosheaf/sheaf.js +278 -0
  32. package/dist/chronosheaf/sheaf.js.map +1 -0
  33. package/dist/chronosheaf/tropical.d.ts +98 -0
  34. package/dist/chronosheaf/tropical.d.ts.map +1 -0
  35. package/dist/chronosheaf/tropical.js +140 -0
  36. package/dist/chronosheaf/tropical.js.map +1 -0
  37. package/dist/chronosheaf/wasserstein.d.ts +75 -0
  38. package/dist/chronosheaf/wasserstein.d.ts.map +1 -0
  39. package/dist/chronosheaf/wasserstein.js +189 -0
  40. package/dist/chronosheaf/wasserstein.js.map +1 -0
  41. package/dist/cosmic/aurelian_v1947.test.d.ts +2 -0
  42. package/dist/cosmic/aurelian_v1947.test.d.ts.map +1 -0
  43. package/dist/cosmic/aurelian_v1947.test.js +34 -0
  44. package/dist/cosmic/aurelian_v1947.test.js.map +1 -0
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +8 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/whats_new.d.ts.map +1 -1
  50. package/dist/whats_new.js +8 -0
  51. package/dist/whats_new.js.map +1 -1
  52. package/package.json +1 -1
@@ -0,0 +1,278 @@
1
+ /**
2
+ * v2.19.47 — CHRONOSHEAF P2-a · sheaf cohomology over ℝ-valued presheaves.
3
+ *
4
+ * Math foundation (Leray / Grothendieck / Čech):
5
+ *
6
+ * For a base space X (we model as a finite set of "sites"), an open
7
+ * cover U = {U₀, U₁, ...}, and a presheaf F : Open(X)ᵒᵖ → Vec_ℝ,
8
+ * the Čech complex is
9
+ *
10
+ * Č^p(U, F) = ⊕_{i₀<…<i_p} F(U_{i₀} ∩ … ∩ U_{i_p})
11
+ *
12
+ * with coboundary
13
+ *
14
+ * (δσ)_{i₀…i_{p+1}} = Σ_{k=0}^{p+1} (−1)^k · ρ(σ_{i₀…î_k…i_{p+1}})
15
+ *
16
+ * and the p-th Čech cohomology
17
+ *
18
+ * H^p(U, F) = ker δ^p / im δ^{p−1}.
19
+ *
20
+ * We focus on H¹: dim H¹(U, F) = (number of independent 1-cocycles)
21
+ * − (number of independent 1-coboundaries). H¹ ≠ 0 ⟺ there exist
22
+ * local sections that agree pairwise on overlaps but cannot be glued
23
+ * into a single global section — the canonical "local OK, global
24
+ * contradiction" signal CHRONOSHEAF chases.
25
+ *
26
+ * Implementation strategy (performance + accuracy):
27
+ *
28
+ * We restrict to ℝ-valued (scalar) sections per site — sufficient
29
+ * for the AI-memory use case where each verifier returns a single
30
+ * number per overlap (a "claim value"). For overlaps the restriction
31
+ * map is the identity on ℝ.
32
+ *
33
+ * The δ⁰ matrix is the signed incidence of pairs to sites:
34
+ *
35
+ * δ⁰[ij, k] = +1 if k == j, −1 if k == i, 0 otherwise
36
+ *
37
+ * For overlaps with NO triple overlap (most code-base covers), every
38
+ * 1-cochain is automatically a cocycle (ker δ¹ = whole space), so
39
+ *
40
+ * dim H¹ = E − rank(δ⁰)
41
+ *
42
+ * where E is the number of pairs and rank(δ⁰) = N − c (vertices N
43
+ * minus connected components c of the nerve 1-skeleton). This
44
+ * reduces to a graph-theoretic computation that runs in O(N + E).
45
+ *
46
+ * When triple overlaps exist we compute δ¹ explicitly and rank-reduce
47
+ * via integer Gaussian elimination (O(min(E,T)² · max(E,T))) — fast
48
+ * enough for a Mneme catalog cover of a few hundred sites.
49
+ *
50
+ * Composes with PAIN-001 (time-direction), PAIN-004 (self-reference
51
+ * via reflexive cover), PAIN-005 (interface-coherence as global section).
52
+ */
53
+ /** Key for an unordered pair (canonical i<j by lex order of strings). */
54
+ function pairKey(a, b) {
55
+ return a < b ? `${a}${b}` : `${b}${a}`;
56
+ }
57
+ /** Union-Find for connected components. */
58
+ class UnionFind {
59
+ parent = new Map();
60
+ rank = new Map();
61
+ add(x) { if (!this.parent.has(x)) {
62
+ this.parent.set(x, x);
63
+ this.rank.set(x, 0);
64
+ } }
65
+ find(x) {
66
+ let root = x;
67
+ while (this.parent.get(root) !== root)
68
+ root = this.parent.get(root);
69
+ let cur = x;
70
+ while (cur !== root) {
71
+ const next = this.parent.get(cur);
72
+ this.parent.set(cur, root);
73
+ cur = next;
74
+ }
75
+ return root;
76
+ }
77
+ union(a, b) {
78
+ const ra = this.find(a);
79
+ const rb = this.find(b);
80
+ if (ra === rb)
81
+ return;
82
+ const r1 = this.rank.get(ra) ?? 0;
83
+ const r2 = this.rank.get(rb) ?? 0;
84
+ if (r1 < r2)
85
+ this.parent.set(ra, rb);
86
+ else if (r1 > r2)
87
+ this.parent.set(rb, ra);
88
+ else {
89
+ this.parent.set(rb, ra);
90
+ this.rank.set(ra, r1 + 1);
91
+ }
92
+ }
93
+ countComponents() {
94
+ const roots = new Set();
95
+ for (const k of this.parent.keys())
96
+ roots.add(this.find(k));
97
+ return roots.size;
98
+ }
99
+ }
100
+ /**
101
+ * Compute δ⁰(σ) for a 0-cochain σ — returns 1-cochain on every overlap.
102
+ * (δ⁰σ)_{ij} = σ_j − σ_i.
103
+ */
104
+ export function delta0(cover, sigma0) {
105
+ const out = new Map();
106
+ for (const [a, b] of cover.overlaps) {
107
+ const va = sigma0.get(a) ?? 0;
108
+ const vb = sigma0.get(b) ?? 0;
109
+ const key = pairKey(a, b);
110
+ out.set(key, (a < b ? vb - va : va - vb));
111
+ }
112
+ return out;
113
+ }
114
+ /**
115
+ * Compute δ¹(σ) for a 1-cochain σ — returns 2-cochain on every triple.
116
+ * (δ¹σ)_{ijk} = σ_{jk} − σ_{ik} + σ_{ij}.
117
+ */
118
+ export function delta1(cover, sigma1) {
119
+ const out = new Map();
120
+ if (!cover.triples)
121
+ return out;
122
+ for (const [i, j, k] of cover.triples) {
123
+ const get = (a, b) => {
124
+ const v = sigma1.get(pairKey(a, b)) ?? 0;
125
+ return a < b ? v : -v;
126
+ };
127
+ const tripleKey = [i, j, k].sort().join("");
128
+ out.set(tripleKey, get(j, k) - get(i, k) + get(i, j));
129
+ }
130
+ return out;
131
+ }
132
+ /** Check the cocycle condition δ¹σ = 0 on all triples. */
133
+ export function isCocycle(cover, sigma1, tol = 1e-9) {
134
+ if (!cover.triples)
135
+ return true;
136
+ const d = delta1(cover, sigma1);
137
+ for (const v of d.values())
138
+ if (Math.abs(v) > tol)
139
+ return false;
140
+ return true;
141
+ }
142
+ /**
143
+ * Compute dim H¹(U, F) by reducing to graph connectivity when triples
144
+ * are absent + Gaussian elimination when they're present.
145
+ */
146
+ export function cohomologyH1(cover) {
147
+ // Build connected components of the nerve 1-skeleton.
148
+ const uf = new UnionFind();
149
+ for (const s of cover.sites)
150
+ uf.add(s);
151
+ for (const [a, b] of cover.overlaps) {
152
+ uf.add(a);
153
+ uf.add(b);
154
+ uf.union(a, b);
155
+ }
156
+ const components = uf.countComponents();
157
+ const E = cover.overlaps.length;
158
+ const N = cover.sites.length;
159
+ // rank δ⁰ = N - c (number of independent edges in a spanning forest).
160
+ const rankDelta0 = Math.max(0, N - components);
161
+ // dim ker δ¹: when no triples, every 1-cochain is a cocycle → ker = E.
162
+ // When triples exist, we count rank δ¹ and ker = E - rank δ¹.
163
+ let kerDelta1 = E;
164
+ if (cover.triples && cover.triples.length > 0) {
165
+ const rankD1 = rankOfDelta1(cover);
166
+ kerDelta1 = Math.max(0, E - rankD1);
167
+ }
168
+ const h1 = Math.max(0, kerDelta1 - rankDelta0);
169
+ // Minimal obstruction witnesses: pairs whose value is the largest
170
+ // contributors to H¹. We approximate via cycle space of the multigraph:
171
+ // any edge NOT in a spanning forest is part of an independent cycle and
172
+ // contributes to H¹ when there are no triple overlaps to kill it.
173
+ const inForest = new Set();
174
+ const uf2 = new UnionFind();
175
+ for (const s of cover.sites)
176
+ uf2.add(s);
177
+ const obstructions = [];
178
+ for (const [a, b] of cover.overlaps) {
179
+ uf2.add(a);
180
+ uf2.add(b);
181
+ if (uf2.find(a) !== uf2.find(b)) {
182
+ uf2.union(a, b);
183
+ inForest.add(pairKey(a, b));
184
+ }
185
+ else {
186
+ // This edge closes a cycle → contributes to H¹ when triples don't kill it.
187
+ obstructions.push({ pair: [a, b], value: 1 });
188
+ }
189
+ }
190
+ return {
191
+ cochainDim: E,
192
+ rankDelta0,
193
+ kerDelta1,
194
+ h1,
195
+ hasObstruction: h1 > 0,
196
+ obstructions: obstructions.slice(0, h1),
197
+ components,
198
+ };
199
+ }
200
+ /**
201
+ * Rank of δ¹ via integer Gaussian elimination on the {-1, 0, +1}
202
+ * matrix indexed by triples (rows) × pairs (columns).
203
+ */
204
+ function rankOfDelta1(cover) {
205
+ const triples = cover.triples ?? [];
206
+ if (triples.length === 0)
207
+ return 0;
208
+ const pairCols = new Map();
209
+ cover.overlaps.forEach((p, idx) => pairCols.set(pairKey(p[0], p[1]), idx));
210
+ const rows = [];
211
+ for (const [i, j, k] of triples) {
212
+ const row = new Array(cover.overlaps.length).fill(0);
213
+ const sign = (a, b) => (a < b ? 1 : -1);
214
+ const col = (a, b) => pairCols.get(pairKey(a, b)) ?? -1;
215
+ const cij = col(i, j);
216
+ if (cij >= 0)
217
+ row[cij] += sign(i, j);
218
+ const cjk = col(j, k);
219
+ if (cjk >= 0)
220
+ row[cjk] += sign(j, k);
221
+ const cik = col(i, k);
222
+ if (cik >= 0)
223
+ row[cik] -= sign(i, k);
224
+ rows.push(row);
225
+ }
226
+ return gaussianRank(rows);
227
+ }
228
+ /** Row-reduce + return rank. Pure integer arithmetic in this code path. */
229
+ function gaussianRank(rows) {
230
+ if (rows.length === 0)
231
+ return 0;
232
+ const m = rows.length;
233
+ const n = rows[0].length;
234
+ const A = rows.map((r) => [...r]);
235
+ let rank = 0;
236
+ let col = 0;
237
+ for (let row = 0; row < m && col < n; col++) {
238
+ let pivot = -1;
239
+ for (let r = row; r < m; r++)
240
+ if ((A[r][col] ?? 0) !== 0) {
241
+ pivot = r;
242
+ break;
243
+ }
244
+ if (pivot < 0)
245
+ continue;
246
+ [A[row], A[pivot]] = [A[pivot], A[row]];
247
+ const piv = A[row][col];
248
+ for (let r = 0; r < m; r++) {
249
+ if (r === row)
250
+ continue;
251
+ const factor = (A[r][col] ?? 0) / piv;
252
+ if (factor === 0)
253
+ continue;
254
+ for (let c = col; c < n; c++)
255
+ A[r][c] = (A[r][c] ?? 0) - factor * (A[row][c] ?? 0);
256
+ }
257
+ rank++;
258
+ row++;
259
+ }
260
+ return rank;
261
+ }
262
+ /**
263
+ * Given a presheaf assignment (each site → numeric "claim value"), check
264
+ * whether the implied pairwise differences glue: returns the same
265
+ * SheafResult plus the gluing-residual vector.
266
+ *
267
+ * residual_{ij} = (claim_j - claim_i) restricted to U_i ∩ U_j
268
+ *
269
+ * If H¹ = 0, the residual lies in im δ⁰ → there exists a global section
270
+ * (effectively the user's claim values are all consistent). If H¹ > 0,
271
+ * the residual carries a non-trivial cocycle component.
272
+ */
273
+ export function gluingDiagnostic(cover, claimPerSite) {
274
+ const h1 = cohomologyH1(cover);
275
+ const residual = delta0(cover, claimPerSite);
276
+ return { ...h1, residual };
277
+ }
278
+ //# sourceMappingURL=sheaf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheaf.js","sourceRoot":"","sources":["../../src/chronosheaf/sheaf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAoCH,yEAAyE;AACzE,SAAS,OAAO,CAAC,CAAO,EAAE,CAAO;IAC/B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;AACzC,CAAC;AAED,2CAA2C;AAC3C,MAAM,SAAS;IACb,MAAM,GAAG,IAAI,GAAG,EAAc,CAAC;IAC/B,IAAI,GAAG,IAAI,GAAG,EAAgB,CAAC;IAC/B,GAAG,CAAC,CAAO,IAAU,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAA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C,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC;YACvC,IAAI,MAAM,KAAK,CAAC;gBAAE,SAAS;YAC3B,KAAK,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;gBAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACxF,CAAC;QACD,IAAI,EAAE,CAAC;QACP,GAAG,EAAE,CAAC;IACR,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAiB,EAAE,YAAsB;IACxE,MAAM,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAC7C,OAAO,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * v2.19.47 — CHRONOSHEAF P2-f · tropical semiring (max-plus algebra).
3
+ *
4
+ * Math foundation (Maslov / Litvinov / Pin):
5
+ *
6
+ * The tropical (max-plus) semiring (ℝ ∪ {−∞}, ⊕, ⊗) replaces
7
+ *
8
+ * a ⊕ b = max(a, b)
9
+ * a ⊗ b = a + b
10
+ * 0_⊕ = −∞
11
+ * 1_⊗ = 0
12
+ *
13
+ * Linear algebra over this semiring computes shortest / longest paths
14
+ * in weighted graphs WITHOUT iteration: matrix product A ⊗ B has
15
+ * entry (A ⊗ B)_{ij} = max_k (A_{ik} + B_{kj}). The "tropical
16
+ * polynomial" min/max of sums is exactly the Bellman-Ford fixed
17
+ * point. Inference in tropical algebra is shortest-path inference
18
+ * in polyhedral fans — and the BOTTLENECK edge (the one that
19
+ * determines the max) is always uniquely identifiable: there is
20
+ * ONE critical edge whose perturbation perturbs the result, the
21
+ * rest are slack. This makes tropical inference INTERPRETABLE in
22
+ * a way that real-number ML rarely is.
23
+ *
24
+ * AI-memory mapping (PAIN-005 interface-coherence + PAIN-006
25
+ * confidence):
26
+ *
27
+ * Verifier chains compose tropically. If verifier A returns confidence
28
+ * c_A and B returns c_B and we combine sequentially, the
29
+ * bottleneck is min(c_A, c_B) — exactly a tropical operation. The
30
+ * critical edge tells you which verifier is the weakest link, which
31
+ * gives an interpretable explanation for any composite confidence
32
+ * number (PAIN-006 fix: instead of "60%" we say "60% limited by
33
+ * verifier B which scored 60%; raise B to raise overall").
34
+ *
35
+ * Implementation: graph as adjacency map; Bellman-Ford with critical-
36
+ * edge tracking. Pure-function; O(V·E).
37
+ */
38
+ export declare const TROPICAL_ZERO: number;
39
+ export declare const TROPICAL_ONE = 0;
40
+ /** Tropical addition: a ⊕ b = max(a, b). */
41
+ export declare function tropicalAdd(a: number, b: number): number;
42
+ /** Tropical multiplication: a ⊗ b = a + b. */
43
+ export declare function tropicalMul(a: number, b: number): number;
44
+ /** Graph for tropical shortest/longest path. */
45
+ export interface TropicalGraph {
46
+ nodes: ReadonlyArray<string>;
47
+ /** Directed edges: from → [{to, weight}]. */
48
+ edges: ReadonlyMap<string, ReadonlyArray<{
49
+ to: string;
50
+ weight: number;
51
+ label?: string;
52
+ }>>;
53
+ }
54
+ export interface TropicalPathResult {
55
+ source: string;
56
+ target: string;
57
+ /** Optimal value (sum of weights along the best path). */
58
+ value: number;
59
+ /** Sequence of nodes in the path. */
60
+ path: string[];
61
+ /** Sequence of edges with their weights. */
62
+ edges: Array<{
63
+ from: string;
64
+ to: string;
65
+ weight: number;
66
+ label?: string;
67
+ }>;
68
+ /** The CRITICAL (bottleneck) edge — the one whose perturbation changes the result. */
69
+ criticalEdge: {
70
+ from: string;
71
+ to: string;
72
+ weight: number;
73
+ label?: string;
74
+ } | null;
75
+ }
76
+ /**
77
+ * Longest-path computation (semiring with ⊕ = max). For shortest-path,
78
+ * negate all weights first. We do not allow positive cycles (would
79
+ * diverge); throws if detected.
80
+ */
81
+ export declare function tropicalLongestPath(graph: TropicalGraph, source: string, target: string): TropicalPathResult | null;
82
+ /**
83
+ * Verifier chain composition. Each verifier outputs a confidence
84
+ * c ∈ [0, 1]; chain confidence = min over the chain (worst-link).
85
+ * Returns the chain value PLUS the critical verifier so we can
86
+ * explain WHY confidence is what it is (PAIN-006 interpretability).
87
+ */
88
+ export declare function verifierChainConfidence(chain: ReadonlyArray<{
89
+ id: string;
90
+ confidence: number;
91
+ }>): {
92
+ chainConfidence: number;
93
+ criticalVerifier: {
94
+ id: string;
95
+ confidence: number;
96
+ } | null;
97
+ };
98
+ //# sourceMappingURL=tropical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tropical.d.ts","sourceRoot":"","sources":["../../src/chronosheaf/tropical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,eAAO,MAAM,aAAa,QAAY,CAAC;AACvC,eAAO,MAAM,YAAY,IAAK,CAAC;AAE/B,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAA2B;AACpF,8CAA8C;AAC9C,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAkB;AAE3E,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC7B,6CAA6C;IAC7C,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAC3F;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,4CAA4C;IAC5C,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3E,sFAAsF;IACtF,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACnF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CA8DnH;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,aAAa,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,GACvD;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,CAK1F"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * v2.19.47 — CHRONOSHEAF P2-f · tropical semiring (max-plus algebra).
3
+ *
4
+ * Math foundation (Maslov / Litvinov / Pin):
5
+ *
6
+ * The tropical (max-plus) semiring (ℝ ∪ {−∞}, ⊕, ⊗) replaces
7
+ *
8
+ * a ⊕ b = max(a, b)
9
+ * a ⊗ b = a + b
10
+ * 0_⊕ = −∞
11
+ * 1_⊗ = 0
12
+ *
13
+ * Linear algebra over this semiring computes shortest / longest paths
14
+ * in weighted graphs WITHOUT iteration: matrix product A ⊗ B has
15
+ * entry (A ⊗ B)_{ij} = max_k (A_{ik} + B_{kj}). The "tropical
16
+ * polynomial" min/max of sums is exactly the Bellman-Ford fixed
17
+ * point. Inference in tropical algebra is shortest-path inference
18
+ * in polyhedral fans — and the BOTTLENECK edge (the one that
19
+ * determines the max) is always uniquely identifiable: there is
20
+ * ONE critical edge whose perturbation perturbs the result, the
21
+ * rest are slack. This makes tropical inference INTERPRETABLE in
22
+ * a way that real-number ML rarely is.
23
+ *
24
+ * AI-memory mapping (PAIN-005 interface-coherence + PAIN-006
25
+ * confidence):
26
+ *
27
+ * Verifier chains compose tropically. If verifier A returns confidence
28
+ * c_A and B returns c_B and we combine sequentially, the
29
+ * bottleneck is min(c_A, c_B) — exactly a tropical operation. The
30
+ * critical edge tells you which verifier is the weakest link, which
31
+ * gives an interpretable explanation for any composite confidence
32
+ * number (PAIN-006 fix: instead of "60%" we say "60% limited by
33
+ * verifier B which scored 60%; raise B to raise overall").
34
+ *
35
+ * Implementation: graph as adjacency map; Bellman-Ford with critical-
36
+ * edge tracking. Pure-function; O(V·E).
37
+ */
38
+ export const TROPICAL_ZERO = -Infinity; // 0 in (R∪{-∞}, ⊕)
39
+ export const TROPICAL_ONE = 0; // 1 in (R∪{-∞}, ⊗)
40
+ /** Tropical addition: a ⊕ b = max(a, b). */
41
+ export function tropicalAdd(a, b) { return Math.max(a, b); }
42
+ /** Tropical multiplication: a ⊗ b = a + b. */
43
+ export function tropicalMul(a, b) { return a + b; }
44
+ /**
45
+ * Longest-path computation (semiring with ⊕ = max). For shortest-path,
46
+ * negate all weights first. We do not allow positive cycles (would
47
+ * diverge); throws if detected.
48
+ */
49
+ export function tropicalLongestPath(graph, source, target) {
50
+ // Bellman-Ford on the max-plus semiring.
51
+ const dist = new Map();
52
+ const pred = new Map();
53
+ for (const n of graph.nodes)
54
+ dist.set(n, TROPICAL_ZERO);
55
+ dist.set(source, TROPICAL_ONE);
56
+ const V = graph.nodes.length;
57
+ let changed = true;
58
+ let iters = 0;
59
+ while (changed && iters < V) {
60
+ changed = false;
61
+ iters++;
62
+ for (const [u, out] of graph.edges) {
63
+ const du = dist.get(u) ?? TROPICAL_ZERO;
64
+ if (du === TROPICAL_ZERO)
65
+ continue;
66
+ for (const { to, weight, label } of out) {
67
+ const candidate = tropicalMul(du, weight);
68
+ const dv = dist.get(to) ?? TROPICAL_ZERO;
69
+ if (candidate > dv) {
70
+ dist.set(to, candidate);
71
+ const p = { from: u, weight };
72
+ if (label !== undefined)
73
+ p.label = label;
74
+ pred.set(to, p);
75
+ changed = true;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ // Detect positive cycles: one more pass; if anything improves, throw.
81
+ for (const [u, out] of graph.edges) {
82
+ const du = dist.get(u) ?? TROPICAL_ZERO;
83
+ if (du === TROPICAL_ZERO)
84
+ continue;
85
+ for (const { to, weight } of out) {
86
+ if (tropicalMul(du, weight) > (dist.get(to) ?? TROPICAL_ZERO)) {
87
+ throw new Error(`tropicalLongestPath: positive cycle reachable through ${u}→${to}`);
88
+ }
89
+ }
90
+ }
91
+ const targetVal = dist.get(target);
92
+ if (targetVal === undefined || targetVal === TROPICAL_ZERO)
93
+ return null;
94
+ // Reconstruct path.
95
+ const reverseNodes = [target];
96
+ const reverseEdges = [];
97
+ let cur = target;
98
+ let safety = 0;
99
+ while (cur !== source && safety++ < V + 1) {
100
+ const p = pred.get(cur);
101
+ if (!p)
102
+ return null;
103
+ const edge = { from: p.from, to: cur, weight: p.weight };
104
+ if (p.label !== undefined)
105
+ edge.label = p.label;
106
+ reverseEdges.push(edge);
107
+ reverseNodes.push(p.from);
108
+ cur = p.from;
109
+ }
110
+ const path = reverseNodes.reverse();
111
+ const edges = reverseEdges.reverse();
112
+ // Critical edge: the one with the smallest weight along the path
113
+ // (the bottleneck under min-of-sums). Equivalently, the edge whose
114
+ // ε-perturbation perturbs the path value 1:1 (slack-free edge).
115
+ let critical = null;
116
+ let minWeight = Infinity;
117
+ for (const e of edges) {
118
+ if (e.weight < minWeight) {
119
+ minWeight = e.weight;
120
+ critical = e;
121
+ }
122
+ }
123
+ return { source, target, value: targetVal, path, edges, criticalEdge: critical };
124
+ }
125
+ /**
126
+ * Verifier chain composition. Each verifier outputs a confidence
127
+ * c ∈ [0, 1]; chain confidence = min over the chain (worst-link).
128
+ * Returns the chain value PLUS the critical verifier so we can
129
+ * explain WHY confidence is what it is (PAIN-006 interpretability).
130
+ */
131
+ export function verifierChainConfidence(chain) {
132
+ if (chain.length === 0)
133
+ return { chainConfidence: 1, criticalVerifier: null };
134
+ let worst = chain[0];
135
+ for (const v of chain)
136
+ if (v.confidence < worst.confidence)
137
+ worst = v;
138
+ return { chainConfidence: worst.confidence, criticalVerifier: worst };
139
+ }
140
+ //# sourceMappingURL=tropical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tropical.js","sourceRoot":"","sources":["../../src/chronosheaf/tropical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAQ,CAAC,CAAK,mBAAmB;AAC/D,MAAM,CAAC,MAAM,YAAY,GAAI,CAAC,CAAC,CAAa,mBAAmB;AAE/D,4CAA4C;AAC5C,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,IAAY,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACpF,8CAA8C;AAC9C,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,IAAY,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAsB3E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAoB,EAAE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GAAG,CAAC,CAAC;IACtE,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;AACxE,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * v2.19.47 — CHRONOSHEAF P2-e · Wasserstein optimal transport.
3
+ *
4
+ * Math foundation (Monge 1781 / Kantorovich 1942):
5
+ *
6
+ * For two probability measures μ, ν on a metric space (X, d), and a
7
+ * cost function c(x, y) = d(x, y)^p, the p-Wasserstein distance is
8
+ *
9
+ * W_p(μ, ν) = ( inf_{γ ∈ Π(μ, ν)} ∫ d(x, y)^p dγ(x, y) )^(1/p)
10
+ *
11
+ * where Π(μ, ν) is the set of couplings (joint measures with given
12
+ * marginals). For p = 1 on the real line this reduces to
13
+ *
14
+ * W_1(μ, ν) = ∫|F_μ(t) − F_ν(t)| dt
15
+ *
16
+ * (the L¹ distance between cumulative distribution functions —
17
+ * trivial to compute exactly).
18
+ *
19
+ * For higher-dimensional or general supports we use Sinkhorn (Cuturi
20
+ * 2013): regularise the LP with an entropy penalty
21
+ *
22
+ * W_ε(μ, ν) = min_γ ⟨γ, C⟩ − ε · H(γ)
23
+ *
24
+ * and solve via iterative scaling u ← μ ⊘ Kv, v ← ν ⊘ K^T u where
25
+ * K = exp(−C / ε). Converges in O(n²/ε) iterations to a Wasserstein
26
+ * distance approximation.
27
+ *
28
+ * AI-memory mapping (PAIN-003 drift-surface + PAIN-006 confidence):
29
+ *
30
+ * The "distance between two catalog snapshots" is a 1D EMD on
31
+ * tool-name multiset distributions; the cost of moving evidence
32
+ * across modules (e.g. governor ↔ fossil ↔ ganglion) is the
33
+ * ground-metric. We use Wasserstein to score drift between
34
+ * releases (PAIN-003: 685→699→711 → bottleneck distance =
35
+ * concrete drift number), and to compare two posterior
36
+ * distributions when the support overlaps but is unequal.
37
+ *
38
+ * Implementation: 1D exact W_1 in O(n log n); Sinkhorn for general
39
+ * case in O(n² · iter); both are pure-function + numerically stable.
40
+ */
41
+ /** Discrete measure on a finite support: {value: weight}. Weights sum to total mass. */
42
+ export type DiscreteMeasure = ReadonlyMap<string, number>;
43
+ /**
44
+ * Exact 1-Wasserstein distance between two distributions on a sorted
45
+ * real line. Supports are given as Maps { coordinate (string-of-num) → mass }.
46
+ * Returns the L1 distance between cumulative distribution functions.
47
+ *
48
+ * Both measures must have equal total mass (else throws). The cost
49
+ * is intrinsic Euclidean distance on the value axis.
50
+ */
51
+ export declare function wasserstein1D(mu: DiscreteMeasure, nu: DiscreteMeasure): number;
52
+ /** Cost matrix between two finite supports. */
53
+ export type CostMatrix = ReadonlyArray<ReadonlyArray<number>>;
54
+ /**
55
+ * Sinkhorn iteration for entropic OT. Returns the approximate OT cost
56
+ * + the coupling matrix π. ε controls regularisation; lower ε = closer
57
+ * to true Wasserstein but slower convergence.
58
+ */
59
+ export declare function sinkhorn(mu: ReadonlyArray<number>, nu: ReadonlyArray<number>, C: CostMatrix, opts?: {
60
+ epsilon?: number;
61
+ maxIter?: number;
62
+ tol?: number;
63
+ }): {
64
+ cost: number;
65
+ coupling: number[][];
66
+ iterations: number;
67
+ converged: boolean;
68
+ };
69
+ /**
70
+ * Catalog-snapshot distance: takes two arrays of tool names and returns
71
+ * the W_1 distance under the "intra-family free / inter-family unit cost"
72
+ * metric. Used by PAIN-003 drift-surface analysis.
73
+ */
74
+ export declare function catalogDrift(snapA: ReadonlyArray<string>, snapB: ReadonlyArray<string>): number;
75
+ //# sourceMappingURL=wasserstein.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasserstein.d.ts","sourceRoot":"","sources":["../../src/chronosheaf/wasserstein.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,wFAAwF;AACxF,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,GAAG,MAAM,CAwB9E;AAED,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,EACzB,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,EACzB,CAAC,EAAE,UAAU,EACb,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9D;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAiDhF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CA4B/F"}