@aleph-ai/tinyaleph 1.2.1 → 1.3.0

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
@@ -554,11 +554,464 @@ function symbolicCompute(inputStates, maxIterations = 100, coherenceThreshold =
554
554
  };
555
555
  }
556
556
 
557
+ // Constants
558
+ const PHI = (1 + Math.sqrt(5)) / 2; // Golden ratio ≈ 1.618
559
+ const DELTA_S = Math.sqrt(2); // Irrational shift
560
+
561
+ /**
562
+ * QuaternionPrime - Quaternion with prime-specific operations
563
+ * q = a + bi + cj + dk
564
+ */
565
+ class QuaternionPrime {
566
+ constructor(a = 0, b = 0, c = 0, d = 0) {
567
+ this.a = a;
568
+ this.b = b;
569
+ this.c = c;
570
+ this.d = d;
571
+ }
572
+
573
+ static fromPrime(p) {
574
+ // Encode prime in real component
575
+ return new QuaternionPrime(p, 0, 0, 0);
576
+ }
577
+
578
+ static fromAngle(theta) {
579
+ // Create unit quaternion from rotation angle around k-axis
580
+ const halfTheta = theta / 2;
581
+ return new QuaternionPrime(
582
+ Math.cos(halfTheta),
583
+ 0,
584
+ 0,
585
+ Math.sin(halfTheta)
586
+ );
587
+ }
588
+
589
+ add(other) {
590
+ return new QuaternionPrime(
591
+ this.a + other.a,
592
+ this.b + other.b,
593
+ this.c + other.c,
594
+ this.d + other.d
595
+ );
596
+ }
597
+
598
+ mul(other) {
599
+ // Hamilton product
600
+ return new QuaternionPrime(
601
+ this.a * other.a - this.b * other.b - this.c * other.c - this.d * other.d,
602
+ this.a * other.b + this.b * other.a + this.c * other.d - this.d * other.c,
603
+ this.a * other.c - this.b * other.d + this.c * other.a + this.d * other.b,
604
+ this.a * other.d + this.b * other.c - this.c * other.b + this.d * other.a
605
+ );
606
+ }
607
+
608
+ scale(k) {
609
+ return new QuaternionPrime(this.a * k, this.b * k, this.c * k, this.d * k);
610
+ }
611
+
612
+ conj() {
613
+ return new QuaternionPrime(this.a, -this.b, -this.c, -this.d);
614
+ }
615
+
616
+ norm() {
617
+ return Math.sqrt(this.a ** 2 + this.b ** 2 + this.c ** 2 + this.d ** 2);
618
+ }
619
+
620
+ normalize() {
621
+ const n = this.norm();
622
+ return n > 1e-10 ? this.scale(1 / n) : new QuaternionPrime(1, 0, 0, 0);
623
+ }
624
+ }
625
+
626
+ /**
627
+ * PrimeResonanceIdentity (PRI)
628
+ * Unique identity based on prime signatures
629
+ */
630
+ class PrimeResonanceIdentity {
631
+ constructor(signature, hash) {
632
+ this.signature = signature;
633
+ this.hash = hash;
634
+ }
635
+
636
+ static random() {
637
+ // Generate random prime signature
638
+ const primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47];
639
+ const signature = [];
640
+ for (let i = 0; i < 3; i++) {
641
+ signature.push(primes[Math.floor(Math.random() * primes.length)]);
642
+ }
643
+ const hash = signature.reduce((acc, p) => acc * p, 1) % 1000000007;
644
+ return new PrimeResonanceIdentity(signature, hash);
645
+ }
646
+
647
+ static fromSeed(seed) {
648
+ // Deterministic generation from seed
649
+ const rng = (s) => {
650
+ s = Math.sin(s * 9999.1) * 10000;
651
+ return s - Math.floor(s);
652
+ };
653
+ const primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47];
654
+ const signature = [];
655
+ let s = seed;
656
+ for (let i = 0; i < 3; i++) {
657
+ s = rng(s + i);
658
+ signature.push(primes[Math.floor(s * primes.length)]);
659
+ }
660
+ const hash = signature.reduce((acc, p) => acc * p, 1) % 1000000007;
661
+ return new PrimeResonanceIdentity(signature, hash);
662
+ }
663
+
664
+ entanglementStrength(other) {
665
+ // Compute entanglement strength based on shared primes
666
+ const shared = this.signature.filter(p => other.signature.includes(p)).length;
667
+ const strength = (2 * shared / (this.signature.length + other.signature.length)) - 0.5;
668
+ return Math.max(-1, Math.min(1, strength * 2));
669
+ }
670
+
671
+ coherence(other) {
672
+ return Math.abs(this.entanglementStrength(other));
673
+ }
674
+ }
675
+
676
+ /**
677
+ * PhaseLockedRing - Ring of phase-locked oscillators at prime frequencies
678
+ */
679
+ class PhaseLockedRing {
680
+ constructor(primes) {
681
+ this.primes = primes;
682
+ this.n = primes.length;
683
+ this.phases = new Float64Array(this.n);
684
+ this.amplitudes = new Float64Array(this.n);
685
+
686
+ // Initialize with random phases
687
+ for (let i = 0; i < this.n; i++) {
688
+ this.phases[i] = Math.random() * 2 * Math.PI;
689
+ this.amplitudes[i] = 1.0;
690
+ }
691
+
692
+ this.coupling = 0.1;
693
+ this.time = 0;
694
+ }
695
+
696
+ tick(dt) {
697
+ const newPhases = new Float64Array(this.n);
698
+
699
+ for (let i = 0; i < this.n; i++) {
700
+ // Natural frequency from prime
701
+ const omega = Math.log(this.primes[i]);
702
+
703
+ // Kuramoto coupling
704
+ let coupling = 0;
705
+ for (let j = 0; j < this.n; j++) {
706
+ if (i !== j) {
707
+ coupling += Math.sin(this.phases[j] - this.phases[i]);
708
+ }
709
+ }
710
+ coupling *= this.coupling / this.n;
711
+
712
+ newPhases[i] = this.phases[i] + (omega + coupling) * dt;
713
+ newPhases[i] %= 2 * Math.PI;
714
+ }
715
+
716
+ this.phases = newPhases;
717
+ this.time += dt;
718
+ return this;
719
+ }
720
+
721
+ orderParameter() {
722
+ // Kuramoto order parameter r = |1/N Σ e^(iθ_j)|
723
+ let realSum = 0, imagSum = 0;
724
+ for (let i = 0; i < this.n; i++) {
725
+ realSum += Math.cos(this.phases[i]);
726
+ imagSum += Math.sin(this.phases[i]);
727
+ }
728
+ return Math.sqrt(realSum ** 2 + imagSum ** 2) / this.n;
729
+ }
730
+
731
+ meanPhase() {
732
+ let realSum = 0, imagSum = 0;
733
+ for (let i = 0; i < this.n; i++) {
734
+ realSum += Math.cos(this.phases[i]);
735
+ imagSum += Math.sin(this.phases[i]);
736
+ }
737
+ return Math.atan2(imagSum, realSum);
738
+ }
739
+
740
+ toPrimeState() {
741
+ const state = new PrimeState(this.primes);
742
+ for (let i = 0; i < this.n; i++) {
743
+ state.set(this.primes[i], Complex.fromPolar(
744
+ this.amplitudes[i] / Math.sqrt(this.n),
745
+ this.phases[i]
746
+ ));
747
+ }
748
+ return state;
749
+ }
750
+ }
751
+
752
+ /**
753
+ * HolographicField - 2D holographic memory field
754
+ * Encodes PrimeStates as interference patterns
755
+ */
756
+ class HolographicField {
757
+ constructor(width, height) {
758
+ this.width = width;
759
+ this.height = height;
760
+ this.field = new Float64Array(width * height);
761
+ this.phaseField = new Float64Array(width * height);
762
+ }
763
+
764
+ encodeState(state, x, y) {
765
+ // Encode state as interference pattern around (x, y)
766
+ const primes = state.primes;
767
+
768
+ for (let i = 0; i < this.width; i++) {
769
+ for (let j = 0; j < this.height; j++) {
770
+ const idx = j * this.width + i;
771
+ const dx = i - x;
772
+ const dy = j - y;
773
+ const r = Math.sqrt(dx * dx + dy * dy) + 1;
774
+
775
+ let intensity = 0;
776
+ let phase = 0;
777
+
778
+ for (const p of primes) {
779
+ const amp = state.get(p);
780
+ if (amp.norm() > 1e-10) {
781
+ // Create ring pattern at prime frequency
782
+ const k = 2 * Math.PI / (p * 0.5);
783
+ intensity += amp.norm() * Math.cos(k * r + amp.phase());
784
+ phase += amp.phase();
785
+ }
786
+ }
787
+
788
+ this.field[idx] += intensity / primes.length;
789
+ this.phaseField[idx] = phase / primes.length;
790
+ }
791
+ }
792
+
793
+ return this;
794
+ }
795
+
796
+ maxIntensity() {
797
+ let max = 0;
798
+ for (let i = 0; i < this.field.length; i++) {
799
+ if (Math.abs(this.field[i]) > max) {
800
+ max = Math.abs(this.field[i]);
801
+ }
802
+ }
803
+ return max;
804
+ }
805
+
806
+ findPeaks(threshold = 0.1) {
807
+ const peaks = [];
808
+ const maxI = this.maxIntensity();
809
+
810
+ for (let i = 1; i < this.width - 1; i++) {
811
+ for (let j = 1; j < this.height - 1; j++) {
812
+ const idx = j * this.width + i;
813
+ const val = this.field[idx];
814
+
815
+ if (Math.abs(val) / maxI < threshold) continue;
816
+
817
+ // Check if local maximum
818
+ let isMax = true;
819
+ for (let di = -1; di <= 1; di++) {
820
+ for (let dj = -1; dj <= 1; dj++) {
821
+ if (di === 0 && dj === 0) continue;
822
+ const nidx = (j + dj) * this.width + (i + di);
823
+ if (Math.abs(this.field[nidx]) > Math.abs(val)) {
824
+ isMax = false;
825
+ break;
826
+ }
827
+ }
828
+ if (!isMax) break;
829
+ }
830
+
831
+ if (isMax) {
832
+ peaks.push({ x: i, y: j, intensity: val, phase: this.phaseField[idx] });
833
+ }
834
+ }
835
+ }
836
+
837
+ return peaks.sort((a, b) => Math.abs(b.intensity) - Math.abs(a.intensity));
838
+ }
839
+
840
+ decodeAt(x, y, radius = 5) {
841
+ // Decode state by analyzing local frequency content
842
+ const state = new PrimeState();
843
+ const samples = [];
844
+
845
+ // Sample around the point
846
+ for (let i = Math.max(0, x - radius); i < Math.min(this.width, x + radius); i++) {
847
+ for (let j = Math.max(0, y - radius); j < Math.min(this.height, y + radius); j++) {
848
+ const idx = j * this.width + i;
849
+ const r = Math.sqrt((i - x) ** 2 + (j - y) ** 2);
850
+ if (r > 0 && r <= radius) {
851
+ samples.push({ r, val: this.field[idx], phase: this.phaseField[idx] });
852
+ }
853
+ }
854
+ }
855
+
856
+ // Analyze for prime frequencies
857
+ for (const p of state.primes) {
858
+ const k = 2 * Math.PI / (p * 0.5);
859
+ let real = 0, imag = 0;
860
+
861
+ for (const s of samples) {
862
+ real += s.val * Math.cos(k * s.r);
863
+ imag += s.val * Math.sin(k * s.r);
864
+ }
865
+
866
+ const amp = Math.sqrt(real ** 2 + imag ** 2) / Math.max(1, samples.length);
867
+ const phase = Math.atan2(imag, real);
868
+
869
+ if (amp > 0.01) {
870
+ state.set(p, Complex.fromPolar(amp, phase));
871
+ }
872
+ }
873
+
874
+ return state.normalize();
875
+ }
876
+
877
+ clear() {
878
+ this.field.fill(0);
879
+ this.phaseField.fill(0);
880
+ return this;
881
+ }
882
+ }
883
+
884
+ /**
885
+ * EntangledNode - Network node with entanglement capabilities
886
+ */
887
+ class EntangledNode {
888
+ constructor(id) {
889
+ this.id = id;
890
+ this.pri = PrimeResonanceIdentity.random();
891
+ this.entanglementMap = new Map();
892
+ this.coherence = 1.0;
893
+ this.state = PrimeState.uniform();
894
+ this.holographicMemory = new HolographicField(32, 32);
895
+ this.time = 0;
896
+ }
897
+
898
+ entangleWith(other) {
899
+ const strength = this.pri.entanglementStrength(other.pri);
900
+ this.entanglementMap.set(other.id, { node: other, strength });
901
+ other.entanglementMap.set(this.id, { node: this, strength });
902
+ return strength;
903
+ }
904
+
905
+ tick(dt) {
906
+ // Update coherence based on entanglements
907
+ if (this.entanglementMap.size > 0) {
908
+ let totalStrength = 0;
909
+ for (const [, entry] of this.entanglementMap) {
910
+ totalStrength += Math.abs(entry.strength);
911
+ }
912
+ this.coherence = totalStrength / this.entanglementMap.size;
913
+ }
914
+
915
+ // Decay coherence slightly
916
+ this.coherence *= (1 - 0.01 * dt);
917
+ this.coherence = Math.max(0.1, this.coherence);
918
+
919
+ this.time += dt;
920
+ return this;
921
+ }
922
+
923
+ storeMemory(state, x, y) {
924
+ this.holographicMemory.encodeState(state, x, y);
925
+ return this;
926
+ }
927
+
928
+ recallMemory(x, y, radius = 5) {
929
+ return this.holographicMemory.decodeAt(x, y, radius);
930
+ }
931
+
932
+ getEntanglementStrength(otherId) {
933
+ const entry = this.entanglementMap.get(otherId);
934
+ return entry ? entry.strength : 0;
935
+ }
936
+ }
937
+
938
+ /**
939
+ * ResonantFragment - Fragment of resonant information
940
+ */
941
+ class ResonantFragment {
942
+ constructor(state) {
943
+ this.state = state;
944
+ this._entropy = null;
945
+ }
946
+
947
+ static fromText(text) {
948
+ const state = encodeMemory(text);
949
+ return new ResonantFragment(state);
950
+ }
951
+
952
+ static fromPrimes(primes) {
953
+ const state = new PrimeState();
954
+ const amp = 1 / Math.sqrt(primes.length);
955
+ for (const p of primes) {
956
+ if (state.amplitudes.has(p)) {
957
+ state.set(p, new Complex(amp, 0));
958
+ }
959
+ }
960
+ return new ResonantFragment(state.normalize());
961
+ }
962
+
963
+ get entropy() {
964
+ if (this._entropy === null) {
965
+ this._entropy = this.state.entropy();
966
+ }
967
+ return this._entropy;
968
+ }
969
+
970
+ dominant(n = 3) {
971
+ return this.state.dominant(n);
972
+ }
973
+
974
+ tensorWith(other) {
975
+ // Simplified tensor product: add states
976
+ const combined = this.state.add(other.state).normalize();
977
+ return new ResonantFragment(combined);
978
+ }
979
+
980
+ rotatePhase(theta) {
981
+ const rotation = Complex.fromPolar(1, theta);
982
+ const rotated = new PrimeState(this.state.primes);
983
+ for (const p of this.state.primes) {
984
+ rotated.set(p, this.state.get(p).mul(rotation));
985
+ }
986
+ return new ResonantFragment(rotated);
987
+ }
988
+
989
+ coherenceWith(other) {
990
+ return Math.sqrt(this.state.coherence(other.state));
991
+ }
992
+
993
+ clone() {
994
+ return new ResonantFragment(this.state.clone());
995
+ }
996
+ }
997
+
557
998
  module.exports = {
558
999
  Complex,
559
1000
  PrimeState,
560
1001
  ResonanceOperators,
561
1002
  EntropyDrivenEvolution,
562
1003
  encodeMemory,
563
- symbolicCompute
1004
+ symbolicCompute,
1005
+
1006
+ // New classes
1007
+ QuaternionPrime,
1008
+ PrimeResonanceIdentity,
1009
+ PhaseLockedRing,
1010
+ HolographicField,
1011
+ EntangledNode,
1012
+ ResonantFragment,
1013
+
1014
+ // Constants
1015
+ PHI,
1016
+ DELTA_S
564
1017
  };
package/core/index.js CHANGED
@@ -53,20 +53,70 @@ const {
53
53
  ResonanceOperators,
54
54
  EntropyDrivenEvolution,
55
55
  encodeMemory,
56
- symbolicCompute
57
- } = require('./hilbert');
58
-
59
- // Prime Resonance Network components
60
- const {
61
- PHI, PHI_CONJ, DELTA_S,
56
+ symbolicCompute,
62
57
  QuaternionPrime,
63
58
  PrimeResonanceIdentity,
64
59
  PhaseLockedRing,
65
60
  HolographicField,
66
61
  EntangledNode,
67
- ResonantFragment
62
+ ResonantFragment,
63
+ DELTA_S
64
+ } = require('./hilbert');
65
+
66
+ // Golden Ratio Resonance (from symprime symbolic AI)
67
+ const {
68
+ ResonanceCalculator,
69
+ resonanceSignature,
70
+ findFibonacciSequences,
71
+ PHI,
72
+ PHI_THRESHOLD,
73
+ PHI_BONUS,
74
+ calculateResonance,
75
+ findGoldenPairs,
76
+ findMostResonant
68
77
  } = require('./resonance');
69
78
 
79
+ // Symbol Database (200+ emoji symbols from symprime)
80
+ const {
81
+ SymbolDatabase,
82
+ SymbolCategory,
83
+ PrimeGenerator,
84
+ symbolDatabase,
85
+ getSymbol,
86
+ getSymbolByPrime,
87
+ search: searchSymbols,
88
+ encode: encodeSymbols,
89
+ decode: decodeSymbols
90
+ } = require('./symbols');
91
+
92
+ // Semantic Inference Engine (from symprime)
93
+ const {
94
+ SemanticInference,
95
+ EntityExtractor,
96
+ InferenceMethod,
97
+ semanticInference,
98
+ entityExtractor,
99
+ inferSymbol,
100
+ inferSymbols,
101
+ extractEntities,
102
+ extractAndInfer,
103
+ inferWithResonance,
104
+ inferMostResonant
105
+ } = require('./inference');
106
+
107
+ // Compound Builder (multi-symbol concepts from symprime)
108
+ const {
109
+ CompoundBuilder,
110
+ CompoundSymbol,
111
+ SymbolSequence,
112
+ compoundBuilder,
113
+ createCompound,
114
+ getCompound,
115
+ createSequence,
116
+ getSequence,
117
+ findCompoundsContaining
118
+ } = require('./compound');
119
+
70
120
  // ResoFormer ML primitives
71
121
  const {
72
122
  Quaternion,
@@ -154,11 +204,6 @@ module.exports = {
154
204
  EntropyDrivenEvolution,
155
205
  encodeMemory,
156
206
  symbolicCompute,
157
-
158
- // Prime Resonance Network
159
- PHI,
160
- PHI_CONJ,
161
- DELTA_S,
162
207
  QuaternionPrime,
163
208
  PrimeResonanceIdentity,
164
209
  PhaseLockedRing,
@@ -166,6 +211,55 @@ module.exports = {
166
211
  EntangledNode,
167
212
  ResonantFragment,
168
213
 
214
+ // Constants
215
+ DELTA_S,
216
+
217
+ // Golden Ratio Resonance (symprime symbolic AI)
218
+ PHI,
219
+ PHI_THRESHOLD,
220
+ PHI_BONUS,
221
+ ResonanceCalculator,
222
+ resonanceSignature,
223
+ findFibonacciSequences,
224
+ calculateResonance,
225
+ findGoldenPairs,
226
+ findMostResonant,
227
+
228
+ // Symbol Database (symprime symbolic AI)
229
+ SymbolDatabase,
230
+ SymbolCategory,
231
+ PrimeGenerator,
232
+ symbolDatabase,
233
+ getSymbol,
234
+ getSymbolByPrime,
235
+ searchSymbols,
236
+ encodeSymbols,
237
+ decodeSymbols,
238
+
239
+ // Semantic Inference (symprime symbolic AI)
240
+ SemanticInference,
241
+ EntityExtractor,
242
+ InferenceMethod,
243
+ semanticInference,
244
+ entityExtractor,
245
+ inferSymbol,
246
+ inferSymbols,
247
+ extractEntities,
248
+ extractAndInfer,
249
+ inferWithResonance,
250
+ inferMostResonant,
251
+
252
+ // Compound Builder (symprime symbolic AI)
253
+ CompoundBuilder,
254
+ CompoundSymbol,
255
+ SymbolSequence,
256
+ compoundBuilder,
257
+ createCompound,
258
+ getCompound,
259
+ createSequence,
260
+ getSequence,
261
+ findCompoundsContaining,
262
+
169
263
  // ResoFormer ML Primitives
170
264
  Quaternion,
171
265
  SparsePrimeState,