@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/index.js CHANGED
@@ -4,6 +4,26 @@
4
4
 
5
5
  const { Hypercomplex } = require('./hypercomplex');
6
6
 
7
+ // CRT-Homology Module (Chinese Remainder Theorem + Birkhoff Attention + Homology Loss)
8
+ const {
9
+ extendedGCD,
10
+ modInverse,
11
+ areCoprime,
12
+ softmax,
13
+ ResidueEncoder,
14
+ CRTReconstructor,
15
+ BirkhoffProjector,
16
+ HomologyLoss,
17
+ CRTModularLayer,
18
+ CRTFusedAttention,
19
+ CoprimeSelector,
20
+ createCRTLayer,
21
+ createFusedAttention,
22
+ DEFAULT_PRIMES_SMALL,
23
+ DEFAULT_PRIMES_MEDIUM,
24
+ DEFAULT_PRIMES_SEMANTIC
25
+ } = require('./crt-homology');
26
+
7
27
  // Formal Type System (mtspbc.pdf implementation)
8
28
  const {
9
29
  NounType, AdjType, SentenceType,
@@ -30,6 +50,11 @@ const {
30
50
  Translator, TypeDirectedTranslator,
31
51
  LambdaEvaluator, Semantics, ConceptInterpreter
32
52
  } = require('./lambda');
53
+
54
+ // Enochian Packet Layer (Section 7.4)
55
+ const enochian = require('./enochian');
56
+ const enochianVocabulary = require('./enochian-vocabulary');
57
+
33
58
  const {
34
59
  FANO_LINES,
35
60
  octonionMultiplyIndex,
@@ -144,6 +169,14 @@ const {
144
169
  ResoFormer
145
170
  } = require('./rformer-layers');
146
171
 
172
+ // CRT-enhanced ResoFormer layers
173
+ const {
174
+ CRTResonantAttention,
175
+ HomologyRegularizedBlock,
176
+ CRTResoFormer,
177
+ createCRTResoFormer
178
+ } = require('./rformer-crt');
179
+
147
180
  // Prime Entanglement Graph
148
181
  const {
149
182
  EntanglementEdge,
@@ -351,5 +384,57 @@ module.exports = {
351
384
  TypeDirectedTranslator,
352
385
  LambdaEvaluator,
353
386
  Semantics,
354
- ConceptInterpreter
387
+ ConceptInterpreter,
388
+
389
+ // Enochian Packet Layer (Section 7.4 - twist-based validation)
390
+ enochian,
391
+ enochianVocabulary,
392
+ ENOCHIAN_PRIMES: enochian.ENOCHIAN_PRIMES,
393
+ ENOCHIAN_MODES: enochian.MODES,
394
+ twistAngle: enochian.twistAngle,
395
+ totalTwist: enochian.totalTwist,
396
+ isTwistClosed: enochian.isTwistClosed,
397
+ findClosedSequences: enochian.findClosedSequences,
398
+ EnochianSymbol: enochian.EnochianSymbol,
399
+ EnochianPacket: enochian.EnochianPacket,
400
+ EnochianEncoder: enochian.EnochianEncoder,
401
+ EnochianDecoder: enochian.EnochianDecoder,
402
+ EnochianPacketBuilder: enochian.EnochianPacketBuilder,
403
+ EnhancedEnochianEncoder: enochian.EnhancedEnochianEncoder,
404
+ EnhancedEnochianDecoder: enochian.EnhancedEnochianDecoder,
405
+ // Enochian Vocabulary
406
+ ENOCHIAN_ALPHABET: enochianVocabulary.ENOCHIAN_ALPHABET,
407
+ PRIME_BASIS: enochianVocabulary.PRIME_BASIS,
408
+ CORE_VOCABULARY: enochianVocabulary.CORE_VOCABULARY,
409
+ THE_NINETEEN_CALLS: enochianVocabulary.THE_NINETEEN_CALLS,
410
+ EnochianWord: enochianVocabulary.EnochianWord,
411
+ EnochianCall: enochianVocabulary.EnochianCall,
412
+ EnochianEngine: enochianVocabulary.EnochianEngine,
413
+ SedenionElement: enochianVocabulary.SedenionElement,
414
+ TwistOperator: enochianVocabulary.TwistOperator,
415
+ validateTwistClosure: enochianVocabulary.validateTwistClosure,
416
+
417
+ // CRT-Homology Module (Coprime Modular Algebra + Birkhoff Polytope + Homology Loss)
418
+ extendedGCD,
419
+ modInverse,
420
+ areCoprime,
421
+ softmax,
422
+ ResidueEncoder,
423
+ CRTReconstructor,
424
+ BirkhoffProjector,
425
+ HomologyLoss,
426
+ CRTModularLayer,
427
+ CRTFusedAttention,
428
+ CoprimeSelector,
429
+ createCRTLayer,
430
+ createFusedAttention,
431
+ DEFAULT_PRIMES_SMALL,
432
+ DEFAULT_PRIMES_MEDIUM,
433
+ DEFAULT_PRIMES_SEMANTIC,
434
+
435
+ // CRT-enhanced ResoFormer (Birkhoff attention + Homology regularization)
436
+ CRTResonantAttention,
437
+ HomologyRegularizedBlock,
438
+ CRTResoFormer,
439
+ createCRTResoFormer
355
440
  };
package/core/lambda.js CHANGED
@@ -650,39 +650,170 @@ class Semantics {
650
650
 
651
651
  // ============================================================================
652
652
  // INTERPRETATION (Section 5 - Prime → Concept mapping)
653
+ // Enhanced with PRQS Lexicon from TriadicPrimeFusion paper
653
654
  // ============================================================================
654
655
 
656
+ /**
657
+ * PRQS (Prime-Indexed Resonant Quantum Semantics) Lexicon
658
+ *
659
+ * From TriadicPrimeFusion paper §4: Core semantic primes form a minimal
660
+ * basis for expressing complex concepts. Categories emerge from prime
661
+ * number-theoretic properties:
662
+ *
663
+ * - Structural (p ≡ 1 mod 4): Form, pattern, organization
664
+ * - Dynamic (p ≡ 3 mod 4): Process, change, flow
665
+ * - Relational (p ≡ 1 mod 6): Connection, interface, boundary
666
+ * - Foundational (p ≡ 5 mod 6): Ground, identity, essence
667
+ */
668
+ const PRQS_LEXICON = {
669
+ // Core Semantic Primes (§4.1)
670
+ nouns: new Map([
671
+ // Foundational (first 10 primes)
672
+ [2, { concept: 'duality', category: 'foundation', role: 'split/pair' }],
673
+ [3, { concept: 'structure', category: 'foundation', role: 'form/frame' }],
674
+ [5, { concept: 'change', category: 'dynamic', role: 'motion/flow' }],
675
+ [7, { concept: 'identity', category: 'foundation', role: 'self/same' }],
676
+ [11, { concept: 'complexity', category: 'structural', role: 'layers/depth' }],
677
+ [13, { concept: 'relation', category: 'relational', role: 'link/bond' }],
678
+ [17, { concept: 'boundary', category: 'relational', role: 'edge/limit' }],
679
+ [19, { concept: 'observer', category: 'dynamic', role: 'witness/measure' }],
680
+ [23, { concept: 'time', category: 'dynamic', role: 'sequence/duration' }],
681
+ [29, { concept: 'space', category: 'structural', role: 'extent/place' }],
682
+
683
+ // Extended Lexicon (§4.2)
684
+ [31, { concept: 'energy', category: 'dynamic', role: 'force/potential' }],
685
+ [37, { concept: 'information', category: 'structural', role: 'pattern/signal' }],
686
+ [41, { concept: 'pattern', category: 'structural', role: 'repeat/form' }],
687
+ [43, { concept: 'recursion', category: 'dynamic', role: 'self-reference' }],
688
+ [47, { concept: 'emergence', category: 'relational', role: 'arising/novelty' }],
689
+ [53, { concept: 'coherence', category: 'relational', role: 'unity/harmony' }],
690
+ [59, { concept: 'entropy', category: 'dynamic', role: 'disorder/spread' }],
691
+ [61, { concept: 'symmetry', category: 'structural', role: 'invariance' }],
692
+ [67, { concept: 'causation', category: 'relational', role: 'origin/effect' }],
693
+ [71, { concept: 'memory', category: 'structural', role: 'retention/trace' }],
694
+ [73, { concept: 'intention', category: 'dynamic', role: 'aim/purpose' }],
695
+ [79, { concept: 'context', category: 'relational', role: 'surround/frame' }],
696
+ [83, { concept: 'resonance', category: 'dynamic', role: 'vibration/echo' }],
697
+ [89, { concept: 'transformation', category: 'dynamic', role: 'change-of-form' }],
698
+ [97, { concept: 'closure', category: 'relational', role: 'complete/whole' }],
699
+
700
+ // Higher concepts (§4.3)
701
+ [101, { concept: 'consciousness', category: 'dynamic', role: 'awareness' }],
702
+ [103, { concept: 'meaning', category: 'relational', role: 'significance' }],
703
+ [107, { concept: 'truth', category: 'foundation', role: 'correspondence' }],
704
+ [109, { concept: 'beauty', category: 'structural', role: 'harmony/form' }],
705
+ [113, { concept: 'value', category: 'relational', role: 'worth/good' }]
706
+ ]),
707
+
708
+ // Adjective/Operator mappings (§4.4)
709
+ adjectives: new Map([
710
+ [2, { concept: 'dual', category: 'foundation', intensifies: false }],
711
+ [3, { concept: 'structured', category: 'structural', intensifies: true }],
712
+ [5, { concept: 'dynamic', category: 'dynamic', intensifies: true }],
713
+ [7, { concept: 'essential', category: 'foundation', intensifies: false }],
714
+ [11, { concept: 'complex', category: 'structural', intensifies: true }],
715
+ [13, { concept: 'relational', category: 'relational', intensifies: false }],
716
+ [17, { concept: 'bounded', category: 'relational', intensifies: false }],
717
+ [19, { concept: 'observed', category: 'dynamic', intensifies: true }],
718
+ [23, { concept: 'temporal', category: 'dynamic', intensifies: false }],
719
+ [29, { concept: 'spatial', category: 'structural', intensifies: false }],
720
+ [31, { concept: 'energetic', category: 'dynamic', intensifies: true }],
721
+ [37, { concept: 'informational', category: 'structural', intensifies: true }],
722
+ [41, { concept: 'patterned', category: 'structural', intensifies: true }],
723
+ [43, { concept: 'recursive', category: 'dynamic', intensifies: true }],
724
+ [47, { concept: 'emergent', category: 'relational', intensifies: true }],
725
+ [53, { concept: 'coherent', category: 'relational', intensifies: true }],
726
+ [59, { concept: 'entropic', category: 'dynamic', intensifies: false }],
727
+ [61, { concept: 'symmetric', category: 'structural', intensifies: true }],
728
+ [67, { concept: 'causal', category: 'relational', intensifies: true }],
729
+ [71, { concept: 'remembered', category: 'structural', intensifies: false }],
730
+ [73, { concept: 'intentional', category: 'dynamic', intensifies: true }],
731
+ [79, { concept: 'contextual', category: 'relational', intensifies: false }],
732
+ [83, { concept: 'resonant', category: 'dynamic', intensifies: true }],
733
+ [89, { concept: 'transformative', category: 'dynamic', intensifies: true }],
734
+ [97, { concept: 'closed', category: 'relational', intensifies: false }]
735
+ ])
736
+ };
737
+
738
+ /**
739
+ * Semantic category classification based on prime properties
740
+ * From PRQS paper: categories emerge from quadratic residue character
741
+ */
742
+ function classifyPrime(p) {
743
+ const mod4 = p % 4;
744
+ const mod6 = p % 6;
745
+
746
+ // Primary classification
747
+ let primary;
748
+ if (mod4 === 1) {
749
+ primary = 'structural'; // Can be expressed as sum of two squares
750
+ } else if (mod4 === 3) {
751
+ primary = 'dynamic'; // Cannot be expressed as sum of two squares
752
+ } else {
753
+ primary = 'foundation'; // p = 2
754
+ }
755
+
756
+ // Secondary classification
757
+ let secondary;
758
+ if (mod6 === 1) {
759
+ secondary = 'relational'; // Closer to 6k+1 form
760
+ } else if (mod6 === 5) {
761
+ secondary = 'foundational'; // Closer to 6k-1 form
762
+ } else {
763
+ secondary = 'neutral'; // p = 2 or p = 3
764
+ }
765
+
766
+ return { primary, secondary, mod4, mod6 };
767
+ }
768
+
655
769
  /**
656
770
  * ConceptInterpreter - Maps primes to semantic concepts
771
+ * Enhanced with PRQS Lexicon for richer semantic interpretation
657
772
  */
658
773
  class ConceptInterpreter {
659
- constructor() {
660
- // Default concept mappings (can be customized)
661
- this.nounConcepts = new Map([
662
- [2, 'existence'],
663
- [3, 'unity'],
664
- [5, 'life'],
665
- [7, 'truth'],
666
- [11, 'consciousness'],
667
- [13, 'knowledge'],
668
- [17, 'wisdom'],
669
- [19, 'love'],
670
- [23, 'creation'],
671
- [29, 'infinity']
672
- ]);
673
-
674
- this.adjConcepts = new Map([
675
- [2, 'dual'],
676
- [3, 'triple'],
677
- [5, 'vital'],
678
- [7, 'true'],
679
- [11, 'conscious'],
680
- [13, 'knowing'],
681
- [17, 'wise'],
682
- [19, 'loving'],
683
- [23, 'creative'],
684
- [29, 'infinite']
685
- ]);
774
+ constructor(lexicon = PRQS_LEXICON) {
775
+ // Use PRQS lexicon by default
776
+ this.nounConcepts = new Map();
777
+ this.adjConcepts = new Map();
778
+ this.nounMetadata = new Map();
779
+ this.adjMetadata = new Map();
780
+
781
+ // Load from lexicon
782
+ for (const [prime, data] of lexicon.nouns) {
783
+ this.nounConcepts.set(prime, data.concept);
784
+ this.nounMetadata.set(prime, data);
785
+ }
786
+
787
+ for (const [prime, data] of lexicon.adjectives) {
788
+ this.adjConcepts.set(prime, data.concept);
789
+ this.adjMetadata.set(prime, data);
790
+ }
791
+ }
792
+
793
+ /**
794
+ * Get semantic category for a prime
795
+ */
796
+ getCategory(prime) {
797
+ // Check if we have metadata
798
+ if (this.nounMetadata.has(prime)) {
799
+ return this.nounMetadata.get(prime).category;
800
+ }
801
+ if (this.adjMetadata.has(prime)) {
802
+ return this.adjMetadata.get(prime).category;
803
+ }
804
+
805
+ // Derive from number-theoretic properties
806
+ return classifyPrime(prime).primary;
807
+ }
808
+
809
+ /**
810
+ * Get semantic role for a prime (if known)
811
+ */
812
+ getRole(prime) {
813
+ if (this.nounMetadata.has(prime)) {
814
+ return this.nounMetadata.get(prime).role;
815
+ }
816
+ return null;
686
817
  }
687
818
 
688
819
  /**
@@ -698,8 +829,33 @@ class ConceptInterpreter {
698
829
  return this.nounConcepts.get(p);
699
830
  }
700
831
 
701
- // Generate description for unknown primes
702
- return `concept_${p}`;
832
+ // Generate description based on prime properties
833
+ const category = classifyPrime(p);
834
+ return `${category.primary}_concept_${p}`;
835
+ }
836
+
837
+ /**
838
+ * Interpret a noun term with full metadata
839
+ */
840
+ interpretNounFull(term) {
841
+ if (!(term instanceof NounTerm)) {
842
+ throw new Error('Expected NounTerm');
843
+ }
844
+
845
+ const p = term.prime;
846
+ const concept = this.interpretNoun(term);
847
+ const category = this.getCategory(p);
848
+ const role = this.getRole(p);
849
+ const classification = classifyPrime(p);
850
+
851
+ return {
852
+ prime: p,
853
+ concept,
854
+ category,
855
+ role,
856
+ classification,
857
+ isCore: this.nounMetadata.has(p)
858
+ };
703
859
  }
704
860
 
705
861
  /**
@@ -715,7 +871,20 @@ class ConceptInterpreter {
715
871
  return this.adjConcepts.get(p);
716
872
  }
717
873
 
718
- return `modifier_${p}`;
874
+ // Generate based on category
875
+ const category = classifyPrime(p);
876
+ return `${category.primary}_modifier_${p}`;
877
+ }
878
+
879
+ /**
880
+ * Check if an adjective intensifies meaning
881
+ */
882
+ isIntensifier(prime) {
883
+ if (this.adjMetadata.has(prime)) {
884
+ return this.adjMetadata.get(prime).intensifies;
885
+ }
886
+ // Default: structural adjectives intensify
887
+ return classifyPrime(prime).primary === 'structural';
719
888
  }
720
889
 
721
890
  /**
@@ -765,12 +934,90 @@ class ConceptInterpreter {
765
934
  /**
766
935
  * Add custom concept mappings
767
936
  */
768
- addNounConcept(prime, concept) {
937
+ addNounConcept(prime, concept, metadata = {}) {
769
938
  this.nounConcepts.set(prime, concept);
939
+ if (Object.keys(metadata).length > 0) {
940
+ this.nounMetadata.set(prime, { concept, ...metadata });
941
+ }
770
942
  }
771
943
 
772
- addAdjConcept(prime, concept) {
944
+ addAdjConcept(prime, concept, metadata = {}) {
773
945
  this.adjConcepts.set(prime, concept);
946
+ if (Object.keys(metadata).length > 0) {
947
+ this.adjMetadata.set(prime, { concept, ...metadata });
948
+ }
949
+ }
950
+
951
+ /**
952
+ * Get all core semantic primes (those with explicit mappings)
953
+ */
954
+ getCorePrimes() {
955
+ const nouns = Array.from(this.nounConcepts.keys());
956
+ const adjs = Array.from(this.adjConcepts.keys());
957
+ return { nouns, adjs, all: [...new Set([...nouns, ...adjs])] };
958
+ }
959
+
960
+ /**
961
+ * Analyze semantic compatibility between two primes
962
+ * From PRQS: compatible primes have complementary categories
963
+ */
964
+ analyzeCompatibility(p1, p2) {
965
+ const cat1 = classifyPrime(p1);
966
+ const cat2 = classifyPrime(p2);
967
+
968
+ // Complementary categories have higher compatibility
969
+ const complementary = (cat1.primary !== cat2.primary);
970
+ const sameSecondary = (cat1.secondary === cat2.secondary);
971
+
972
+ // Compute compatibility score
973
+ let score = 0.5; // Base score
974
+ if (complementary) score += 0.25; // Different primary = good
975
+ if (sameSecondary) score += 0.15; // Same secondary = good
976
+ if ((p1 + p2) % 4 === 0) score += 0.1; // Sum divisible by 4
977
+
978
+ return {
979
+ p1, p2,
980
+ cat1, cat2,
981
+ complementary,
982
+ sameSecondary,
983
+ score,
984
+ interpretation: score > 0.7 ? 'highly_compatible' :
985
+ score > 0.5 ? 'compatible' : 'weakly_compatible'
986
+ };
987
+ }
988
+
989
+ /**
990
+ * Generate semantic blend for a fusion
991
+ * From PRQS: fusion creates emergent meaning
992
+ */
993
+ interpretFusionSemantic(p, q, r) {
994
+ const concepts = [p, q, r].map(prime =>
995
+ this.nounConcepts.get(prime) || `concept_${prime}`
996
+ );
997
+
998
+ const categories = [p, q, r].map(classifyPrime);
999
+
1000
+ // Count category types
1001
+ const catCounts = { structural: 0, dynamic: 0, relational: 0, foundation: 0 };
1002
+ for (const cat of categories) {
1003
+ catCounts[cat.primary] = (catCounts[cat.primary] || 0) + 1;
1004
+ }
1005
+
1006
+ // Dominant category
1007
+ const dominant = Object.entries(catCounts)
1008
+ .sort((a, b) => b[1] - a[1])[0][0];
1009
+
1010
+ // Emergent meaning description
1011
+ const emergent = `${dominant}_fusion(${concepts.join('+')})`;
1012
+
1013
+ return {
1014
+ components: concepts,
1015
+ categories,
1016
+ dominant,
1017
+ fusedPrime: p + q + r,
1018
+ emergent,
1019
+ description: `Emergent ${dominant} concept from ${concepts.join(', ')}`
1020
+ };
774
1021
  }
775
1022
  }
776
1023
 
@@ -841,5 +1088,9 @@ module.exports = {
841
1088
 
842
1089
  // Semantics
843
1090
  Semantics,
844
- ConceptInterpreter
1091
+ ConceptInterpreter,
1092
+
1093
+ // PRQS Lexicon (from TriadicPrimeFusion paper)
1094
+ PRQS_LEXICON,
1095
+ classifyPrime
845
1096
  };