@aleph-ai/tinyaleph 1.3.0 → 1.4.1

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.
package/core/hilbert.js CHANGED
@@ -1014,4 +1014,654 @@ module.exports = {
1014
1014
  // Constants
1015
1015
  PHI,
1016
1016
  DELTA_S
1017
- };
1017
+ };
1018
+
1019
+ // ============================================================================
1020
+ // P-ADIC COHERENCE (from Quantum_Semantics paper)
1021
+ // ============================================================================
1022
+
1023
+ /**
1024
+ * Calculate p-adic norm |x|_p
1025
+ *
1026
+ * For prime p, the p-adic norm of integer x is:
1027
+ * |x|_p = p^(-v_p(x)) where v_p(x) is the largest power of p dividing x
1028
+ *
1029
+ * @param {number} x - Integer value
1030
+ * @param {number} p - Prime number
1031
+ * @returns {number} p-adic norm
1032
+ */
1033
+ function pAdicNorm(x, p) {
1034
+ if (x === 0) return 0;
1035
+
1036
+ let power = 0;
1037
+ let n = Math.abs(Math.floor(x));
1038
+
1039
+ while (n % p === 0 && n > 0) {
1040
+ power++;
1041
+ n = Math.floor(n / p);
1042
+ }
1043
+
1044
+ return Math.pow(p, -power);
1045
+ }
1046
+
1047
+ /**
1048
+ * Calculate p-adic valuation v_p(x)
1049
+ * The highest power of p dividing x
1050
+ *
1051
+ * @param {number} x - Integer value
1052
+ * @param {number} p - Prime number
1053
+ * @returns {number} p-adic valuation
1054
+ */
1055
+ function pAdicValuation(x, p) {
1056
+ if (x === 0) return Infinity;
1057
+
1058
+ let power = 0;
1059
+ let n = Math.abs(Math.floor(x));
1060
+
1061
+ while (n % p === 0 && n > 0) {
1062
+ power++;
1063
+ n = Math.floor(n / p);
1064
+ }
1065
+
1066
+ return power;
1067
+ }
1068
+
1069
+ /**
1070
+ * P-adic coherence between two PrimeStates
1071
+ *
1072
+ * Measures coherence in p-adic metric for each prime p.
1073
+ * From Quantum_Semantics paper: uses p-adic structure for
1074
+ * capturing "closeness" in divisibility sense.
1075
+ *
1076
+ * @param {PrimeState} state1 - First state
1077
+ * @param {PrimeState} state2 - Second state
1078
+ * @param {Array<number>} primes - Primes to compute p-adic coherence for
1079
+ * @returns {Object} p-adic coherence metrics
1080
+ */
1081
+ function pAdicCoherence(state1, state2, primes = [2, 3, 5]) {
1082
+ const coherences = {};
1083
+
1084
+ for (const p of primes) {
1085
+ // Get amplitude magnitudes for this prime in both states
1086
+ const amp1 = state1.get(p);
1087
+ const amp2 = state2.get(p);
1088
+
1089
+ const mag1 = amp1 ? amp1.norm() : 0;
1090
+ const mag2 = amp2 ? amp2.norm() : 0;
1091
+
1092
+ // Discretize magnitudes to integers for p-adic comparison
1093
+ const int1 = Math.round(mag1 * 1000);
1094
+ const int2 = Math.round(mag2 * 1000);
1095
+
1096
+ // p-adic distance: |x - y|_p
1097
+ const diff = Math.abs(int1 - int2);
1098
+ const pNorm = pAdicNorm(diff, p);
1099
+
1100
+ // Coherence is 1 - normalized p-adic distance
1101
+ // Small p-adic norm (high valuation) means closer in p-adic sense
1102
+ coherences[p] = pNorm < 1e-10 ? 1.0 : Math.exp(-pNorm);
1103
+ }
1104
+
1105
+ // Overall p-adic coherence (geometric mean)
1106
+ const values = Object.values(coherences);
1107
+ const geometric = Math.pow(
1108
+ values.reduce((prod, v) => prod * Math.max(0.001, v), 1),
1109
+ 1 / values.length
1110
+ );
1111
+
1112
+ return {
1113
+ byPrime: coherences,
1114
+ overall: geometric
1115
+ };
1116
+ }
1117
+
1118
+ // ============================================================================
1119
+ // MÖBIUS AND EULER TOTIENT OPERATORS (from qis.pdf)
1120
+ // ============================================================================
1121
+
1122
+ /**
1123
+ * Möbius function μ(n)
1124
+ *
1125
+ * μ(n) = 1 if n = 1
1126
+ * μ(n) = (-1)^k if n is product of k distinct primes
1127
+ * μ(n) = 0 if n has squared prime factor
1128
+ *
1129
+ * @param {number} n - Positive integer
1130
+ * @returns {number} Möbius function value
1131
+ */
1132
+ function mobiusFunction(n) {
1133
+ if (n === 1) return 1;
1134
+
1135
+ const { factorize } = require('./prime');
1136
+ const factors = factorize(n);
1137
+
1138
+ // Check for squared factors
1139
+ for (const exp of Object.values(factors)) {
1140
+ if (exp > 1) return 0;
1141
+ }
1142
+
1143
+ // Count distinct prime factors
1144
+ const k = Object.keys(factors).length;
1145
+ return Math.pow(-1, k);
1146
+ }
1147
+
1148
+ /**
1149
+ * Euler's totient function φ(n)
1150
+ *
1151
+ * Counts integers 1 ≤ k ≤ n that are coprime to n.
1152
+ * φ(n) = n · Π(1 - 1/p) for all primes p dividing n
1153
+ *
1154
+ * @param {number} n - Positive integer
1155
+ * @returns {number} Euler totient
1156
+ */
1157
+ function eulerTotient(n) {
1158
+ if (n === 1) return 1;
1159
+
1160
+ const { factorize } = require('./prime');
1161
+ const factors = factorize(n);
1162
+
1163
+ let result = n;
1164
+ for (const p of Object.keys(factors)) {
1165
+ const prime = parseInt(p);
1166
+ result = result * (1 - 1/prime);
1167
+ }
1168
+
1169
+ return Math.round(result);
1170
+ }
1171
+
1172
+ /**
1173
+ * Extended Resonance Operators including Möbius and Euler Totient
1174
+ *
1175
+ * From qis.pdf:
1176
+ * - M̂|n⟩ = μ(n)|n⟩ (Möbius operator)
1177
+ * - Ê|n⟩ = exp(2πiφ(n)/n)|n⟩ (Euler phase operator)
1178
+ */
1179
+ const ExtendedOperators = {
1180
+ /**
1181
+ * Möbius Operator: M̂|p⟩ = μ(p)|p⟩
1182
+ * For primes, μ(p) = -1 always
1183
+ *
1184
+ * This operator distinguishes "even" vs "odd" prime products
1185
+ * and annihilates states with squared factors.
1186
+ */
1187
+ M(state) {
1188
+ const result = new PrimeState(state.primes);
1189
+ for (const p of state.primes) {
1190
+ const mu = mobiusFunction(p);
1191
+ result.amplitudes.set(p, state.get(p).scale(mu));
1192
+ }
1193
+ return result;
1194
+ },
1195
+
1196
+ /**
1197
+ * Euler Phase Operator: Ê|n⟩ = exp(2πiφ(n)/n)|n⟩
1198
+ *
1199
+ * Applies phase rotation based on Euler's totient function.
1200
+ * For prime p: φ(p) = p-1, so phase = 2π(p-1)/p
1201
+ */
1202
+ E(state) {
1203
+ const result = new PrimeState(state.primes);
1204
+ for (const p of state.primes) {
1205
+ const phi = eulerTotient(p);
1206
+ const phase = 2 * Math.PI * phi / p;
1207
+ const rotation = Complex.fromPolar(1, phase);
1208
+ result.amplitudes.set(p, state.get(p).mul(rotation));
1209
+ }
1210
+ return result;
1211
+ },
1212
+
1213
+ /**
1214
+ * Divisor Count Operator
1215
+ * D̂|n⟩ = d(n)|n⟩ where d(n) is number of divisors
1216
+ */
1217
+ D(state) {
1218
+ const result = new PrimeState(state.primes);
1219
+ for (const p of state.primes) {
1220
+ // For prime p, d(p) = 2
1221
+ result.amplitudes.set(p, state.get(p).scale(2));
1222
+ }
1223
+ return result;
1224
+ },
1225
+
1226
+ /**
1227
+ * Liouville Operator
1228
+ * L̂|n⟩ = λ(n)|n⟩ where λ(n) = (-1)^Ω(n) (Ω = total prime factors with multiplicity)
1229
+ */
1230
+ L(state) {
1231
+ const result = new PrimeState(state.primes);
1232
+ for (const p of state.primes) {
1233
+ // For prime p, Ω(p) = 1, so λ(p) = -1
1234
+ result.amplitudes.set(p, state.get(p).scale(-1));
1235
+ }
1236
+ return result;
1237
+ }
1238
+ };
1239
+
1240
+ // ============================================================================
1241
+ // KNOWLEDGE RESONANCE Γ_know (from Quantum_Semantics)
1242
+ // ============================================================================
1243
+
1244
+ /**
1245
+ * Knowledge Resonance Calculator
1246
+ *
1247
+ * From Quantum_Semantics paper: evaluates how conceptual primes align
1248
+ * across a semantic network. Measures coherence of meaning.
1249
+ *
1250
+ * Γ_know = Σ_ij J_ij · R_i · R_j / Σ_i |R_i|²
1251
+ *
1252
+ * Where J_ij are coupling strengths and R_i are resonance values.
1253
+ */
1254
+ class KnowledgeResonanceCalculator {
1255
+ /**
1256
+ * @param {Object} options - Configuration
1257
+ */
1258
+ constructor(options = {}) {
1259
+ // Coupling matrix (semantic adjacency)
1260
+ this.couplings = options.couplings || new Map();
1261
+
1262
+ // Golden ratio for harmonic weighting
1263
+ this.phi = (1 + Math.sqrt(5)) / 2;
1264
+
1265
+ // Base coupling for unknown pairs
1266
+ this.baseCoupling = options.baseCoupling || 0.1;
1267
+ }
1268
+
1269
+ /**
1270
+ * Set coupling strength between two concept primes
1271
+ * @param {number} p1 - First prime
1272
+ * @param {number} p2 - Second prime
1273
+ * @param {number} strength - Coupling strength J_ij
1274
+ */
1275
+ setCoupling(p1, p2, strength) {
1276
+ const key = `${Math.min(p1, p2)}:${Math.max(p1, p2)}`;
1277
+ this.couplings.set(key, strength);
1278
+ }
1279
+
1280
+ /**
1281
+ * Get coupling strength
1282
+ */
1283
+ getCoupling(p1, p2) {
1284
+ const key = `${Math.min(p1, p2)}:${Math.max(p1, p2)}`;
1285
+ if (this.couplings.has(key)) {
1286
+ return this.couplings.get(key);
1287
+ }
1288
+
1289
+ // Default: coupling based on prime ratio proximity to PHI
1290
+ const ratio = Math.max(p1, p2) / Math.min(p1, p2);
1291
+ const phiDistance = Math.abs(ratio - this.phi);
1292
+ return this.baseCoupling * Math.exp(-phiDistance);
1293
+ }
1294
+
1295
+ /**
1296
+ * Calculate knowledge resonance for a PrimeState
1297
+ *
1298
+ * @param {PrimeState} state - Concept state
1299
+ * @returns {Object} Resonance metrics
1300
+ */
1301
+ calculate(state) {
1302
+ const primes = state.primes.filter(p => state.get(p).norm() > 1e-10);
1303
+
1304
+ if (primes.length === 0) {
1305
+ return { gamma: 0, selfEnergy: 0, interactionEnergy: 0 };
1306
+ }
1307
+
1308
+ // Self-energy: Σ_i |R_i|²
1309
+ let selfEnergy = 0;
1310
+ for (const p of primes) {
1311
+ selfEnergy += state.get(p).norm2();
1312
+ }
1313
+
1314
+ // Interaction energy: Σ_ij J_ij · R_i · R_j
1315
+ let interactionEnergy = 0;
1316
+ for (let i = 0; i < primes.length; i++) {
1317
+ for (let j = i + 1; j < primes.length; j++) {
1318
+ const J = this.getCoupling(primes[i], primes[j]);
1319
+ const R_i = state.get(primes[i]).norm();
1320
+ const R_j = state.get(primes[j]).norm();
1321
+ interactionEnergy += J * R_i * R_j;
1322
+ }
1323
+ }
1324
+
1325
+ // Knowledge resonance Γ_know
1326
+ const gamma = selfEnergy > 0
1327
+ ? interactionEnergy / selfEnergy
1328
+ : 0;
1329
+
1330
+ return {
1331
+ gamma,
1332
+ selfEnergy,
1333
+ interactionEnergy,
1334
+ dominantPrimes: primes.slice(0, 3),
1335
+ coherenceLevel: this.interpretGamma(gamma)
1336
+ };
1337
+ }
1338
+
1339
+ /**
1340
+ * Interpret gamma value
1341
+ */
1342
+ interpretGamma(gamma) {
1343
+ if (gamma > 0.7) return 'high_coherence';
1344
+ if (gamma > 0.4) return 'moderate_coherence';
1345
+ if (gamma > 0.1) return 'low_coherence';
1346
+ return 'fragmented';
1347
+ }
1348
+
1349
+ /**
1350
+ * Calculate resonance between two states
1351
+ */
1352
+ resonanceBetween(state1, state2) {
1353
+ // Combined state
1354
+ const combined = state1.add(state2).normalize();
1355
+ const r1 = this.calculate(state1);
1356
+ const r2 = this.calculate(state2);
1357
+ const rCombined = this.calculate(combined);
1358
+
1359
+ // Synergy: combined > individual sum
1360
+ const synergy = rCombined.gamma - (r1.gamma + r2.gamma) / 2;
1361
+
1362
+ return {
1363
+ state1Gamma: r1.gamma,
1364
+ state2Gamma: r2.gamma,
1365
+ combinedGamma: rCombined.gamma,
1366
+ synergy,
1367
+ isConstructive: synergy > 0
1368
+ };
1369
+ }
1370
+ }
1371
+
1372
+ // ============================================================================
1373
+ // FIBONACCI WAVELET ALIGNMENT (from Quantum_Semantics)
1374
+ // ============================================================================
1375
+
1376
+ /**
1377
+ * Fibonacci Wavelet Generator
1378
+ *
1379
+ * Creates wavelets at Fibonacci-scaled frequencies for
1380
+ * multi-resolution semantic analysis.
1381
+ */
1382
+ class FibonacciWaveletBank {
1383
+ /**
1384
+ * @param {number} size - Wavelet size
1385
+ * @param {number} scales - Number of Fibonacci scales
1386
+ */
1387
+ constructor(size = 256, scales = 7) {
1388
+ this.size = size;
1389
+ this.phi = (1 + Math.sqrt(5)) / 2;
1390
+
1391
+ // Generate Fibonacci-scaled wavelets
1392
+ this.wavelets = [];
1393
+ for (let n = -3; n <= scales - 4; n++) {
1394
+ const scale = Math.pow(this.phi, n);
1395
+ this.wavelets.push(this.generateWavelet(scale));
1396
+ }
1397
+ }
1398
+
1399
+ /**
1400
+ * Generate a Gabor wavelet at given scale
1401
+ * @param {number} scale - Scale factor
1402
+ */
1403
+ generateWavelet(scale) {
1404
+ const wavelet = new Float64Array(this.size);
1405
+ const center = this.size / 2;
1406
+
1407
+ for (let i = 0; i < this.size; i++) {
1408
+ const t = (i - center) / scale;
1409
+ // Gabor wavelet: cos(t) * exp(-t²/2)
1410
+ wavelet[i] = Math.cos(t) * Math.exp(-t * t / (2 * scale * scale));
1411
+ }
1412
+
1413
+ return { scale, data: wavelet };
1414
+ }
1415
+
1416
+ /**
1417
+ * Compute Fibonacci wavelet transform of a signal
1418
+ * @param {Array<number>} signal - Input signal
1419
+ * @returns {Array<Object>} Wavelet coefficients per scale
1420
+ */
1421
+ transform(signal) {
1422
+ const results = [];
1423
+
1424
+ for (const wavelet of this.wavelets) {
1425
+ const coefficients = this.convolve(signal, wavelet.data);
1426
+ const energy = coefficients.reduce((sum, c) => sum + c * c, 0);
1427
+
1428
+ results.push({
1429
+ scale: wavelet.scale,
1430
+ coefficients,
1431
+ energy,
1432
+ peak: Math.max(...coefficients.map(Math.abs))
1433
+ });
1434
+ }
1435
+
1436
+ return results;
1437
+ }
1438
+
1439
+ /**
1440
+ * Convolution
1441
+ */
1442
+ convolve(signal, kernel) {
1443
+ const output = new Array(signal.length).fill(0);
1444
+ const halfK = Math.floor(kernel.length / 2);
1445
+
1446
+ for (let i = 0; i < signal.length; i++) {
1447
+ let sum = 0;
1448
+ for (let j = 0; j < kernel.length; j++) {
1449
+ const signalIdx = i + j - halfK;
1450
+ if (signalIdx >= 0 && signalIdx < signal.length) {
1451
+ sum += signal[signalIdx] * kernel[j];
1452
+ }
1453
+ }
1454
+ output[i] = sum;
1455
+ }
1456
+
1457
+ return output;
1458
+ }
1459
+
1460
+ /**
1461
+ * Check alignment with Fibonacci sequence
1462
+ * @param {Array<Object>} transformResult - Wavelet transform output
1463
+ */
1464
+ measureAlignment(transformResult) {
1465
+ // Check if energy is concentrated at PHI-related scales
1466
+ const totalEnergy = transformResult.reduce((sum, r) => sum + r.energy, 0);
1467
+
1468
+ if (totalEnergy < 1e-10) return { aligned: false, score: 0 };
1469
+
1470
+ // Score based on PHI-power scale concentration
1471
+ let alignedEnergy = 0;
1472
+ for (const result of transformResult) {
1473
+ // Check if scale is close to a PHI power
1474
+ const logScale = Math.log(result.scale) / Math.log(this.phi);
1475
+ const isPhiPower = Math.abs(logScale - Math.round(logScale)) < 0.1;
1476
+
1477
+ if (isPhiPower) {
1478
+ alignedEnergy += result.energy;
1479
+ }
1480
+ }
1481
+
1482
+ const score = alignedEnergy / totalEnergy;
1483
+
1484
+ return {
1485
+ aligned: score > 0.5,
1486
+ score,
1487
+ dominantScale: transformResult.reduce(
1488
+ (max, r) => r.energy > max.energy ? r : max,
1489
+ transformResult[0]
1490
+ ).scale
1491
+ };
1492
+ }
1493
+ }
1494
+
1495
+ // ============================================================================
1496
+ // PATTERN CLASSIFICATION (Zero/Infinity/Fibonacci from Quantum_Semantics)
1497
+ // ============================================================================
1498
+
1499
+ /**
1500
+ * Semantic Pattern Detector
1501
+ *
1502
+ * Detects fundamental patterns in semantic waves:
1503
+ * - Zero Pattern: convergence/nullification
1504
+ * - Infinity Pattern: divergence/expansion
1505
+ * - Fibonacci Pattern: golden ratio harmony
1506
+ */
1507
+ class SemanticPatternDetector {
1508
+ constructor(options = {}) {
1509
+ this.phi = (1 + Math.sqrt(5)) / 2;
1510
+ this.zeroThreshold = options.zeroThreshold || 0.1;
1511
+ this.infinityThreshold = options.infinityThreshold || 5.0;
1512
+ this.fibThreshold = options.fibThreshold || 0.1;
1513
+ }
1514
+
1515
+ /**
1516
+ * Detect zero pattern (semantic nullification)
1517
+ * Occurs when concepts cancel each other
1518
+ */
1519
+ detectZeroPattern(state) {
1520
+ const entropy = state.entropy();
1521
+ const norm = state.norm();
1522
+
1523
+ // Zero pattern: high entropy (spread out) + low total amplitude
1524
+ if (norm < this.zeroThreshold) {
1525
+ return {
1526
+ detected: true,
1527
+ strength: 1 - norm / this.zeroThreshold,
1528
+ type: 'convergence'
1529
+ };
1530
+ }
1531
+
1532
+ // Check for cancellation in pairs
1533
+ let cancellationScore = 0;
1534
+ const primes = state.primes;
1535
+
1536
+ for (let i = 0; i < primes.length; i++) {
1537
+ for (let j = i + 1; j < primes.length; j++) {
1538
+ const amp1 = state.get(primes[i]);
1539
+ const amp2 = state.get(primes[j]);
1540
+
1541
+ // Opposite phases with similar magnitudes -> cancellation
1542
+ const phaseDiff = Math.abs(amp1.phase() - amp2.phase());
1543
+ const magRatio = Math.min(amp1.norm(), amp2.norm()) /
1544
+ (Math.max(amp1.norm(), amp2.norm()) + 1e-10);
1545
+
1546
+ if (Math.abs(phaseDiff - Math.PI) < 0.3 && magRatio > 0.5) {
1547
+ cancellationScore += magRatio;
1548
+ }
1549
+ }
1550
+ }
1551
+
1552
+ return {
1553
+ detected: cancellationScore > 1,
1554
+ strength: Math.min(1, cancellationScore / 3),
1555
+ type: 'interference'
1556
+ };
1557
+ }
1558
+
1559
+ /**
1560
+ * Detect infinity pattern (semantic expansion)
1561
+ * Occurs when concepts reinforce unboundedly
1562
+ */
1563
+ detectInfinityPattern(state) {
1564
+ const amplitudes = state.primes.map(p => state.get(p).norm());
1565
+ const maxAmp = Math.max(...amplitudes);
1566
+ const meanAmp = amplitudes.reduce((s, a) => s + a, 0) / amplitudes.length;
1567
+
1568
+ // Infinity pattern: one or few primes dominate strongly
1569
+ const dominanceRatio = maxAmp / (meanAmp + 1e-10);
1570
+
1571
+ if (dominanceRatio > this.infinityThreshold) {
1572
+ return {
1573
+ detected: true,
1574
+ strength: Math.min(1, dominanceRatio / 10),
1575
+ type: 'divergence',
1576
+ dominantPrime: state.dominant(1)[0].p
1577
+ };
1578
+ }
1579
+
1580
+ return { detected: false, strength: 0, type: 'stable' };
1581
+ }
1582
+
1583
+ /**
1584
+ * Detect Fibonacci/Golden pattern
1585
+ * Occurs when amplitude ratios approximate PHI
1586
+ */
1587
+ detectFibonacciPattern(state) {
1588
+ const primes = state.primes.filter(p => state.get(p).norm() > 0.01);
1589
+ if (primes.length < 2) {
1590
+ return { detected: false, score: 0 };
1591
+ }
1592
+
1593
+ // Sort by amplitude
1594
+ const sorted = primes
1595
+ .map(p => ({ p, amp: state.get(p).norm() }))
1596
+ .sort((a, b) => b.amp - a.amp);
1597
+
1598
+ // Check consecutive amplitude ratios for PHI
1599
+ let phiCount = 0;
1600
+ let totalPairs = 0;
1601
+
1602
+ for (let i = 0; i < sorted.length - 1; i++) {
1603
+ const ratio = sorted[i].amp / (sorted[i + 1].amp + 1e-10);
1604
+ const phiDistance = Math.abs(ratio - this.phi);
1605
+
1606
+ if (phiDistance < this.fibThreshold) {
1607
+ phiCount++;
1608
+ }
1609
+ totalPairs++;
1610
+ }
1611
+
1612
+ const score = totalPairs > 0 ? phiCount / totalPairs : 0;
1613
+
1614
+ return {
1615
+ detected: score > 0.3,
1616
+ score,
1617
+ phiRatioCount: phiCount,
1618
+ dominantPair: sorted.length >= 2
1619
+ ? [sorted[0].p, sorted[1].p]
1620
+ : null
1621
+ };
1622
+ }
1623
+
1624
+ /**
1625
+ * Full pattern classification
1626
+ */
1627
+ classify(state) {
1628
+ const zero = this.detectZeroPattern(state);
1629
+ const infinity = this.detectInfinityPattern(state);
1630
+ const fib = this.detectFibonacciPattern(state);
1631
+
1632
+ // Determine dominant pattern
1633
+ let dominant = 'neutral';
1634
+ let confidence = 0;
1635
+
1636
+ if (zero.detected && zero.strength > confidence) {
1637
+ dominant = 'zero';
1638
+ confidence = zero.strength;
1639
+ }
1640
+ if (infinity.detected && infinity.strength > confidence) {
1641
+ dominant = 'infinity';
1642
+ confidence = infinity.strength;
1643
+ }
1644
+ if (fib.detected && fib.score > confidence) {
1645
+ dominant = 'fibonacci';
1646
+ confidence = fib.score;
1647
+ }
1648
+
1649
+ return {
1650
+ dominant,
1651
+ confidence,
1652
+ patterns: { zero, infinity, fibonacci: fib },
1653
+ entropy: state.entropy()
1654
+ };
1655
+ }
1656
+ }
1657
+
1658
+ // Export new classes and functions
1659
+ module.exports.pAdicNorm = pAdicNorm;
1660
+ module.exports.pAdicValuation = pAdicValuation;
1661
+ module.exports.pAdicCoherence = pAdicCoherence;
1662
+ module.exports.mobiusFunction = mobiusFunction;
1663
+ module.exports.eulerTotient = eulerTotient;
1664
+ module.exports.ExtendedOperators = ExtendedOperators;
1665
+ module.exports.KnowledgeResonanceCalculator = KnowledgeResonanceCalculator;
1666
+ module.exports.FibonacciWaveletBank = FibonacciWaveletBank;
1667
+ module.exports.SemanticPatternDetector = SemanticPatternDetector;