@aleph-ai/tinyaleph 1.0.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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +278 -0
  3. package/backends/cryptographic/index.js +196 -0
  4. package/backends/index.js +15 -0
  5. package/backends/interface.js +89 -0
  6. package/backends/scientific/index.js +272 -0
  7. package/backends/semantic/index.js +527 -0
  8. package/backends/semantic/surface.js +393 -0
  9. package/backends/semantic/two-layer.js +375 -0
  10. package/core/fano.js +127 -0
  11. package/core/hilbert.js +564 -0
  12. package/core/hypercomplex.js +141 -0
  13. package/core/index.js +133 -0
  14. package/core/llm.js +132 -0
  15. package/core/prime.js +184 -0
  16. package/core/resonance.js +695 -0
  17. package/core/rformer-tf.js +1086 -0
  18. package/core/rformer.js +806 -0
  19. package/core/sieve.js +350 -0
  20. package/data.json +8163 -0
  21. package/docs/EXAMPLES_PLAN.md +293 -0
  22. package/docs/README.md +159 -0
  23. package/docs/design/ALEPH_CHAT_ARCHITECTURE.md +499 -0
  24. package/docs/guide/01-quickstart.md +298 -0
  25. package/docs/guide/02-semantic-computing.md +409 -0
  26. package/docs/guide/03-cryptographic.md +420 -0
  27. package/docs/guide/04-scientific.md +494 -0
  28. package/docs/guide/05-llm-integration.md +568 -0
  29. package/docs/guide/06-advanced.md +996 -0
  30. package/docs/guide/README.md +188 -0
  31. package/docs/reference/01-core.md +695 -0
  32. package/docs/reference/02-physics.md +601 -0
  33. package/docs/reference/03-backends.md +892 -0
  34. package/docs/reference/04-engine.md +632 -0
  35. package/docs/reference/README.md +252 -0
  36. package/docs/theory/01-prime-semantics.md +327 -0
  37. package/docs/theory/02-hypercomplex-algebra.md +421 -0
  38. package/docs/theory/03-phase-synchronization.md +364 -0
  39. package/docs/theory/04-entropy-reasoning.md +348 -0
  40. package/docs/theory/05-non-commutativity.md +402 -0
  41. package/docs/theory/06-two-layer-meaning.md +414 -0
  42. package/docs/theory/07-resonant-field-interface.md +419 -0
  43. package/docs/theory/08-semantic-sieve.md +520 -0
  44. package/docs/theory/09-temporal-emergence.md +298 -0
  45. package/docs/theory/10-quaternionic-memory.md +415 -0
  46. package/docs/theory/README.md +162 -0
  47. package/engine/aleph.js +418 -0
  48. package/engine/index.js +7 -0
  49. package/index.js +23 -0
  50. package/modular.js +254 -0
  51. package/package.json +99 -0
  52. package/physics/collapse.js +95 -0
  53. package/physics/entropy.js +88 -0
  54. package/physics/index.js +65 -0
  55. package/physics/kuramoto.js +91 -0
  56. package/physics/lyapunov.js +80 -0
  57. package/physics/oscillator.js +95 -0
  58. package/types/index.d.ts +575 -0
@@ -0,0 +1,252 @@
1
+ # API Reference
2
+
3
+ Complete API documentation for all Aleph modules.
4
+
5
+ ## Modules
6
+
7
+ ### [Core Module](./01-core.md)
8
+
9
+ The foundational mathematical primitives:
10
+
11
+ - **Hypercomplex** - Sedenion algebra and Cayley-Dickson construction
12
+ - **Prime** - Prime number utilities, Gaussian and Eisenstein integers
13
+ - **Fano** - Fano plane multiplication tables for octonions
14
+ - **Sieve** - Semantic sieve algorithm for concept filtering
15
+ - **LLM** - LLM coupling utilities
16
+
17
+ ### [Physics Module](./02-physics.md)
18
+
19
+ Dynamical systems and information theory:
20
+
21
+ - **Oscillator** - Phase-amplitude oscillator creation and manipulation
22
+ - **Kuramoto** - Coupled oscillator synchronization dynamics
23
+ - **Entropy** - Shannon entropy and information measures
24
+ - **Lyapunov** - Stability analysis via Lyapunov exponents
25
+ - **Collapse** - State collapse and measurement mechanics
26
+
27
+ ### [Backends Module](./03-backends.md)
28
+
29
+ Domain-specific computation engines:
30
+
31
+ - **BackendInterface** - Abstract base class for all backends
32
+ - **SemanticBackend** - Natural language and concept processing
33
+ - **CryptographicBackend** - Hashing and key derivation
34
+ - **ScientificBackend** - Quantum-inspired computation
35
+
36
+ ### [Engine Module](./04-engine.md)
37
+
38
+ High-level orchestration:
39
+
40
+ - **AlephEngine** - Unified computation engine
41
+ - **createEngine** - Factory function for engine creation
42
+ - **registerBackend** - Backend registration system
43
+
44
+ ---
45
+
46
+ ## Quick Reference
47
+
48
+ ### Importing
49
+
50
+ ```javascript
51
+ // Full import
52
+ const aleph = require('./modular');
53
+
54
+ // Destructured import
55
+ const {
56
+ createEngine,
57
+ SemanticBackend,
58
+ CryptographicBackend,
59
+ ScientificBackend
60
+ } = require('./modular');
61
+
62
+ // Individual modules
63
+ const { SedenionState, cayleyDickson } = require('./core/hypercomplex');
64
+ const { createOscillator } = require('./physics/oscillator');
65
+ const { kuramotoStep } = require('./physics/kuramoto');
66
+ ```
67
+
68
+ ### Common Patterns
69
+
70
+ ```javascript
71
+ // Create and use semantic engine
72
+ const engine = createEngine('semantic', config);
73
+ const result = engine.run('input text');
74
+
75
+ // Direct backend usage
76
+ const backend = new SemanticBackend(config);
77
+ const primes = backend.encode('text');
78
+ const state = backend.primesToState(primes);
79
+ const output = backend.decode(primes);
80
+
81
+ // Hypercomplex operations
82
+ const a = new SedenionState(components);
83
+ const b = a.multiply(other);
84
+ const c = a.add(other).normalize();
85
+ const entropy = a.entropy();
86
+ const coherence = a.coherence(b);
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Type Conventions
92
+
93
+ ### SedenionState
94
+
95
+ The fundamental state object representing a point in 16-dimensional hypercomplex space.
96
+
97
+ ```typescript
98
+ interface SedenionState {
99
+ dimension: number; // Always 16 for sedenions
100
+ components: number[]; // 16 real components [e₀, e₁, ..., e₁₅]
101
+
102
+ // Arithmetic
103
+ add(other: SedenionState): SedenionState;
104
+ subtract(other: SedenionState): SedenionState;
105
+ multiply(other: SedenionState): SedenionState;
106
+ scale(scalar: number): SedenionState;
107
+
108
+ // Properties
109
+ norm(): number;
110
+ normalize(): SedenionState;
111
+ conjugate(): SedenionState;
112
+ inverse(): SedenionState;
113
+ entropy(): number;
114
+ coherence(other: SedenionState): number;
115
+
116
+ // Utilities
117
+ isZeroDivisorWith(other: SedenionState): boolean;
118
+ clone(): SedenionState;
119
+ toString(): string;
120
+ }
121
+ ```
122
+
123
+ ### Token
124
+
125
+ Tokenized word with metadata.
126
+
127
+ ```typescript
128
+ interface Token {
129
+ word: string; // Original word (lowercase)
130
+ primes: number[]; // Associated prime numbers
131
+ known: boolean; // Whether word is in vocabulary
132
+ isStop: boolean; // Whether word is a stop word
133
+ position: number; // Position in original text
134
+ }
135
+ ```
136
+
137
+ ### Transform
138
+
139
+ Semantic transformation rule.
140
+
141
+ ```typescript
142
+ interface Transform {
143
+ n: string; // Transform name
144
+ q: number[]; // Query primes
145
+ r: number[]; // Replacement primes
146
+ priority?: number; // Application priority
147
+ condition?: (state: SedenionState) => boolean; // Optional condition
148
+ }
149
+ ```
150
+
151
+ ### EngineResult
152
+
153
+ Standard result from engine.run().
154
+
155
+ ```typescript
156
+ interface EngineResult {
157
+ input: string; // Original input
158
+ output: string; // Decoded output
159
+ primes: number[]; // Final prime encoding
160
+ state: SedenionState; // Final hypercomplex state
161
+ entropy: number; // Final entropy
162
+ steps: TransformStep[]; // Applied transforms
163
+ }
164
+
165
+ interface TransformStep {
166
+ step: number;
167
+ transform: string;
168
+ primesBefore: number[];
169
+ primesAfter: number[];
170
+ entropyBefore: number;
171
+ entropyAfter: number;
172
+ entropyDrop: number;
173
+ }
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Error Handling
179
+
180
+ ### Common Errors
181
+
182
+ ```javascript
183
+ // Invalid dimension
184
+ const state = new SedenionState([1, 2, 3]); // Must be 16 components
185
+ // Throws: Error('SedenionState requires exactly 16 components')
186
+
187
+ // Unknown word
188
+ const primes = backend.getWordPrimes('xyzzy'); // Word not in vocabulary
189
+ // Returns: null (or empty array depending on backend)
190
+
191
+ // Division by zero
192
+ const inv = zeroState.inverse();
193
+ // Throws: Error('Cannot invert zero state')
194
+ ```
195
+
196
+ ### Safe Patterns
197
+
198
+ ```javascript
199
+ // Check before inverse
200
+ if (state.norm() > 0) {
201
+ const inv = state.inverse();
202
+ }
203
+
204
+ // Check word existence
205
+ if (backend.hasWord(word)) {
206
+ const primes = backend.getWordPrimes(word);
207
+ }
208
+
209
+ // Validate coherence range
210
+ const coherence = state1.coherence(state2);
211
+ console.assert(coherence >= 0 && coherence <= 1);
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Performance Notes
217
+
218
+ | Operation | Complexity | Notes |
219
+ |-----------|------------|-------|
220
+ | `SedenionState.multiply()` | O(n²) | n=16, uses Cayley-Dickson |
221
+ | `SedenionState.normalize()` | O(n) | Single pass |
222
+ | `SedenionState.entropy()` | O(n) | Shannon entropy |
223
+ | `SemanticBackend.encode()` | O(w×v) | w=words, v=vocabulary |
224
+ | `SemanticBackend.decode()` | O(p×v) | p=primes, v=vocabulary |
225
+ | `kuramotoStep()` | O(n²) | n=oscillators, all-to-all |
226
+
227
+ ### Memory
228
+
229
+ - `SedenionState`: ~128 bytes (16 × 8 bytes for Float64)
230
+ - `SemanticBackend`: ~10KB base + vocabulary size
231
+ - Typical vocabulary: ~10K words = ~1MB
232
+
233
+ ---
234
+
235
+ ## Module Index
236
+
237
+ | Module | File | Description |
238
+ |--------|------|-------------|
239
+ | hypercomplex | `core/hypercomplex.js` | Sedenion algebra |
240
+ | prime | `core/prime.js` | Prime utilities |
241
+ | fano | `core/fano.js` | Fano plane |
242
+ | sieve | `core/sieve.js` | Semantic sieve |
243
+ | llm | `core/llm.js` | LLM coupling |
244
+ | oscillator | `physics/oscillator.js` | Oscillator creation |
245
+ | kuramoto | `physics/kuramoto.js` | Synchronization |
246
+ | entropy | `physics/entropy.js` | Information theory |
247
+ | lyapunov | `physics/lyapunov.js` | Stability |
248
+ | collapse | `physics/collapse.js` | State collapse |
249
+ | semantic | `backends/semantic/index.js` | Semantic backend |
250
+ | cryptographic | `backends/cryptographic/index.js` | Crypto backend |
251
+ | scientific | `backends/scientific/index.js` | Science backend |
252
+ | engine | `engine/aleph.js` | Main engine |
@@ -0,0 +1,327 @@
1
+ # Prime Semantics
2
+
3
+ ## The Prime Number Foundation
4
+
5
+ Prime numbers are the atoms of arithmetic. Every positive integer can be uniquely expressed as a product of primes (Fundamental Theorem of Arithmetic). This uniqueness makes primes ideal for encoding semantic content.
6
+
7
+ ### Why Primes for Meaning?
8
+
9
+ | Property | Arithmetic | Semantics |
10
+ |----------|-----------|-----------|
11
+ | **Uniqueness** | n = Πpᵢᵏⁱ uniquely | Each concept has unique prime signature |
12
+ | **Irreducibility** | Primes cannot factor further | Core concepts are semantic atoms |
13
+ | **Composition** | Integers from prime products | Complex ideas from simple ones |
14
+ | **Infinitude** | Infinitely many primes | Infinitely many possible concepts |
15
+
16
+ ### The Semantic Prime Hypothesis
17
+
18
+ We hypothesize that meaning—like matter—has fundamental constituents. These "semantic atoms" are concepts that cannot be decomposed further:
19
+
20
+ - **EXISTENCE** (prime 2) - that something is
21
+ - **UNITY** (prime 3) - that something is one
22
+ - **FORM** (prime 5) - that something has structure
23
+ - **LOGOS** (prime 7) - that something has reason/pattern
24
+ - **PSYCHE** (prime 11) - that something has inner life
25
+ - **TELOS** (prime 13) - that something has purpose
26
+ - **DYNAMIS** (prime 17) - that something has power/potential
27
+ - **LIMIT** (prime 19) - that something has boundary
28
+
29
+ ---
30
+
31
+ ## The Ontology Mapping
32
+
33
+ Aleph uses a configurable mapping from primes to semantic content:
34
+
35
+ ```javascript
36
+ const ontology = {
37
+ 2: 'existence/being',
38
+ 3: 'unity/oneness',
39
+ 5: 'form/structure',
40
+ 7: 'logos/reason',
41
+ 11: 'psyche/soul',
42
+ 13: 'telos/purpose',
43
+ 17: 'dynamis/power',
44
+ 19: 'limit/boundary',
45
+ 23: 'intensity/degree',
46
+ 29: 'becoming/change',
47
+ 31: 'physis/nature',
48
+ 37: 'techne/craft',
49
+ 41: 'episteme/knowledge',
50
+ 43: 'doxa/opinion',
51
+ 47: 'aletheia/truth',
52
+ 53: 'kairos/timing',
53
+ // ... extends to arbitrary depth
54
+ };
55
+ ```
56
+
57
+ ### Building Complex Concepts
58
+
59
+ Complex concepts are products of prime concepts:
60
+
61
+ ```
62
+ love = [2, 3, 5]
63
+ = existence × unity × form
64
+ = "that which exists as unified form"
65
+
66
+ wisdom = [2, 7, 11]
67
+ = existence × logos × psyche
68
+ = "that which exists as reasoned soul"
69
+
70
+ knowledge = [3, 5, 7]
71
+ = unity × form × logos
72
+ = "unified structured reason"
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Prime Arithmetic as Semantic Operations
78
+
79
+ ### Union (Concept Combination)
80
+
81
+ ```javascript
82
+ love = [2, 3, 5]
83
+ truth = [7, 11, 13]
84
+
85
+ love ∪ truth = [2, 3, 5, 7, 11, 13]
86
+ // "loving truth" or "true love"
87
+ ```
88
+
89
+ ### Intersection (Common Ground)
90
+
91
+ ```javascript
92
+ wisdom = [2, 7, 11]
93
+ knowledge = [3, 5, 7]
94
+
95
+ wisdom ∩ knowledge = [7]
96
+ // logos is what wisdom and knowledge share
97
+ ```
98
+
99
+ ### Difference (Distinction)
100
+
101
+ ```javascript
102
+ wisdom - knowledge = [2, 11]
103
+ // wisdom has existence and psyche that knowledge lacks
104
+
105
+ knowledge - wisdom = [3, 5]
106
+ // knowledge has unity and form that wisdom lacks
107
+ ```
108
+
109
+ ### Product (Deep Integration)
110
+
111
+ ```javascript
112
+ love × truth = product of all prime pairs
113
+ // Creates new composite concept
114
+ ```
115
+
116
+ ---
117
+
118
+ ## The Semantic Sieve
119
+
120
+ A critical problem arises: different words might map to the same primes if our initial assignment is too coarse.
121
+
122
+ ```
123
+ lake → [water, location] → [2, 5]
124
+ ocean → [water, location] → [2, 5]
125
+ // COLLISION! Same primes, different meanings
126
+ ```
127
+
128
+ The **Semantic Sieve** algorithm resolves this:
129
+
130
+ ### Algorithm: Sieve of Distinction
131
+
132
+ ```
133
+ 1. COMPUTE signatures for all words
134
+ 2. CLUSTER words with identical signatures
135
+ 3. FOR each cluster with >1 word:
136
+ a. IF cluster > 10 words: MACRO strategy
137
+ - Ask for broad sub-categories
138
+ b. ELSE: MICRO strategy
139
+ - Find distinguishing feature for pairs
140
+ 4. MINT new primes for new distinctions
141
+ 5. REPEAT until all signatures unique
142
+ ```
143
+
144
+ ### Example Resolution
145
+
146
+ ```
147
+ Cluster: [lake, ocean, pond, sea]
148
+ All mapped to [water, location]
149
+
150
+ MACRO: Split into categories:
151
+ - Still water: [lake, pond] → add prime for "contained"
152
+ - Moving water: [ocean, sea] → add prime for "vast"
153
+
154
+ MICRO: Distinguish remaining pairs:
155
+ - lake vs pond: "large" vs "small" → add prime for "scale"
156
+ - ocean vs sea: "open" vs "bounded" → already have "limit"
157
+
158
+ Result:
159
+ lake → [2, 5, 127] (water, location, large-contained)
160
+ pond → [2, 5, 131] (water, location, small-contained)
161
+ ocean → [2, 5, 137] (water, location, large-open)
162
+ sea → [2, 5, 139, 19] (water, location, large-bounded)
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Prime-to-Frequency Mapping
168
+
169
+ Each prime maps to an oscillator frequency using the PRSC (Prime Resonance Semantic Computing) formula:
170
+
171
+ ```javascript
172
+ function primeToFrequency(p, base = 1, logScale = 10) {
173
+ return base + Math.log(p) / logScale;
174
+ }
175
+ ```
176
+
177
+ This mapping ensures:
178
+ - Larger primes → higher frequencies
179
+ - Logarithmic scaling for perceptual uniformity
180
+ - All frequencies positive and bounded
181
+
182
+ ### Frequency Table
183
+
184
+ | Prime | Concept | Frequency (Hz) |
185
+ |-------|---------|---------------|
186
+ | 2 | existence | 1.069 |
187
+ | 3 | unity | 1.110 |
188
+ | 5 | form | 1.161 |
189
+ | 7 | logos | 1.195 |
190
+ | 11 | psyche | 1.240 |
191
+ | 13 | telos | 1.257 |
192
+ | 17 | dynamis | 1.283 |
193
+ | 19 | limit | 1.294 |
194
+
195
+ When concepts are activated, their corresponding oscillators are excited and begin to interact through Kuramoto coupling.
196
+
197
+ ---
198
+
199
+ ## Prime-to-Angle Mapping
200
+
201
+ For hypercomplex state construction, primes also map to angles:
202
+
203
+ ```javascript
204
+ function primeToAngle(p) {
205
+ return (360 / p) * (Math.PI / 180);
206
+ }
207
+ ```
208
+
209
+ This mapping has deep significance:
210
+ - Prime 2 → 180° (half rotation, binary opposition)
211
+ - Prime 3 → 120° (trisection, triadic structure)
212
+ - Prime 5 → 72° (pentad, golden ratio connection)
213
+ - Prime 7 → ~51° (heptad, mystic number)
214
+
215
+ The angle determines how a prime contributes to the hypercomplex state vector.
216
+
217
+ ---
218
+
219
+ ## Gaussian and Eisenstein Extensions
220
+
221
+ For cryptographic applications, Aleph extends to algebraic integer rings:
222
+
223
+ ### Gaussian Integers Z[i]
224
+
225
+ Complex numbers with integer components: a + bi
226
+
227
+ ```javascript
228
+ class GaussianInteger {
229
+ constructor(real, imag) {
230
+ this.real = real;
231
+ this.imag = imag;
232
+ }
233
+
234
+ norm() { return this.real ** 2 + this.imag ** 2; }
235
+
236
+ isGaussianPrime() {
237
+ const n = this.norm();
238
+ if (!isPrime(n)) return false;
239
+ return n % 4 === 3 || (this.real !== 0 && this.imag !== 0);
240
+ }
241
+ }
242
+ ```
243
+
244
+ Primes split in Z[i] according to their residue mod 4:
245
+ - p ≡ 1 (mod 4): splits as (a+bi)(a-bi) where p = a² + b²
246
+ - p ≡ 3 (mod 4): remains prime
247
+ - p = 2: ramifies as -i(1+i)²
248
+
249
+ ### Eisenstein Integers Z[ω]
250
+
251
+ Where ω = e^(2πi/3) is a primitive cube root of unity:
252
+
253
+ ```javascript
254
+ class EisensteinInteger {
255
+ constructor(a, b) {
256
+ this.a = a; // a + bω
257
+ this.b = b;
258
+ }
259
+
260
+ norm() { return this.a ** 2 - this.a * this.b + this.b ** 2; }
261
+
262
+ isEisensteinPrime() {
263
+ const n = this.norm();
264
+ return isPrime(n) && n % 3 === 2;
265
+ }
266
+ }
267
+ ```
268
+
269
+ These extensions enable richer prime structures for specialized applications.
270
+
271
+ ---
272
+
273
+ ## The Vocabulary System
274
+
275
+ Aleph maintains a vocabulary mapping words to prime signatures:
276
+
277
+ ```javascript
278
+ const vocabulary = {
279
+ "love": [2, 3, 5],
280
+ "wisdom": [2, 7, 11],
281
+ "truth": [7, 11, 13],
282
+ "beauty": [2, 5, 11],
283
+ "justice": [3, 7, 19],
284
+ // ... thousands of entries
285
+ };
286
+ ```
287
+
288
+ ### Word Encoding
289
+
290
+ Unknown words are encoded by character codes:
291
+
292
+ ```javascript
293
+ wordToPrimes(word) {
294
+ return [...word].map(c => primes[c.charCodeAt(0) % primes.length]);
295
+ }
296
+ ```
297
+
298
+ This ensures every word has a prime representation, even if it's not in the vocabulary.
299
+
300
+ ### Vocabulary Learning
301
+
302
+ New vocabulary can be learned:
303
+
304
+ ```javascript
305
+ backend.learn("serendipity", [2, 29, 53]);
306
+ // Now "serendipity" maps to [existence, becoming, kairos]
307
+ // "a fortunate existence-change at the right moment"
308
+ ```
309
+
310
+ ---
311
+
312
+ ## Summary
313
+
314
+ Prime semantics provides:
315
+
316
+ 1. **Uniqueness**: Every concept has a unique prime signature
317
+ 2. **Compositionality**: Complex concepts from simple prime combinations
318
+ 3. **Algebraic structure**: Semantic operations become arithmetic operations
319
+ 4. **Frequency encoding**: Primes map to oscillator frequencies
320
+ 5. **Angle encoding**: Primes contribute to hypercomplex state geometry
321
+ 6. **Extensibility**: Algebraic extensions for specialized applications
322
+
323
+ The prime hypothesis enables rigorous mathematical treatment of meaning—something previously considered impossible.
324
+
325
+ ---
326
+
327
+ ## Next: [Hypercomplex Algebra →](./02-hypercomplex-algebra.md)