@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,695 @@
1
+ # Core Module Reference
2
+
3
+ The core module provides the fundamental mathematical primitives for Aleph.
4
+
5
+ ## Hypercomplex (`core/hypercomplex.js`)
6
+
7
+ ### SedenionState
8
+
9
+ The primary state object representing a point in 16-dimensional hypercomplex space.
10
+
11
+ #### Constructor
12
+
13
+ ```javascript
14
+ new SedenionState(components)
15
+ ```
16
+
17
+ **Parameters:**
18
+ - `components` (Array<number>): Exactly 16 real numbers
19
+
20
+ **Throws:**
21
+ - `Error` if components length ≠ 16
22
+
23
+ **Example:**
24
+ ```javascript
25
+ const state = new SedenionState([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
26
+ ```
27
+
28
+ ---
29
+
30
+ #### Properties
31
+
32
+ | Property | Type | Description |
33
+ |----------|------|-------------|
34
+ | `dimension` | number | Always 16 for sedenions |
35
+ | `components` | number[] | The 16 real components |
36
+
37
+ ---
38
+
39
+ #### add(other)
40
+
41
+ Add two sedenion states component-wise.
42
+
43
+ ```javascript
44
+ state.add(other)
45
+ ```
46
+
47
+ **Parameters:**
48
+ - `other` (SedenionState): State to add
49
+
50
+ **Returns:** SedenionState - New state with sum
51
+
52
+ **Example:**
53
+ ```javascript
54
+ const a = new SedenionState([1, 0, ...]);
55
+ const b = new SedenionState([0, 1, ...]);
56
+ const c = a.add(b); // [1, 1, ...]
57
+ ```
58
+
59
+ ---
60
+
61
+ #### subtract(other)
62
+
63
+ Subtract another state component-wise.
64
+
65
+ ```javascript
66
+ state.subtract(other)
67
+ ```
68
+
69
+ **Parameters:**
70
+ - `other` (SedenionState): State to subtract
71
+
72
+ **Returns:** SedenionState - New state with difference
73
+
74
+ ---
75
+
76
+ #### multiply(other)
77
+
78
+ Multiply using Cayley-Dickson sedenion multiplication.
79
+
80
+ ```javascript
81
+ state.multiply(other)
82
+ ```
83
+
84
+ **Parameters:**
85
+ - `other` (SedenionState): State to multiply with
86
+
87
+ **Returns:** SedenionState - Product state
88
+
89
+ **Notes:**
90
+ - Non-commutative: `a.multiply(b) ≠ b.multiply(a)`
91
+ - Non-associative: `(a*b)*c ≠ a*(b*c)`
92
+ - May produce zero-divisors
93
+
94
+ **Example:**
95
+ ```javascript
96
+ const a = new SedenionState([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
97
+ const b = new SedenionState([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
98
+ const c = a.multiply(b);
99
+ ```
100
+
101
+ ---
102
+
103
+ #### scale(scalar)
104
+
105
+ Multiply all components by a scalar.
106
+
107
+ ```javascript
108
+ state.scale(scalar)
109
+ ```
110
+
111
+ **Parameters:**
112
+ - `scalar` (number): Scaling factor
113
+
114
+ **Returns:** SedenionState - Scaled state
115
+
116
+ **Example:**
117
+ ```javascript
118
+ const doubled = state.scale(2);
119
+ const halved = state.scale(0.5);
120
+ ```
121
+
122
+ ---
123
+
124
+ #### norm()
125
+
126
+ Calculate the Euclidean norm (magnitude).
127
+
128
+ ```javascript
129
+ state.norm()
130
+ ```
131
+
132
+ **Returns:** number - √(Σ cᵢ²)
133
+
134
+ **Example:**
135
+ ```javascript
136
+ const unit = new SedenionState([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
137
+ console.log(unit.norm()); // 1.0
138
+ ```
139
+
140
+ ---
141
+
142
+ #### normalize()
143
+
144
+ Return a unit-norm version of this state.
145
+
146
+ ```javascript
147
+ state.normalize()
148
+ ```
149
+
150
+ **Returns:** SedenionState - State with norm = 1
151
+
152
+ **Throws:**
153
+ - `Error` if norm is zero
154
+
155
+ **Example:**
156
+ ```javascript
157
+ const scaled = state.scale(100);
158
+ const unit = scaled.normalize();
159
+ console.log(unit.norm()); // 1.0
160
+ ```
161
+
162
+ ---
163
+
164
+ #### conjugate()
165
+
166
+ Return the hypercomplex conjugate.
167
+
168
+ ```javascript
169
+ state.conjugate()
170
+ ```
171
+
172
+ **Returns:** SedenionState - Conjugate state
173
+
174
+ **Notes:**
175
+ - For sedenions: `conj([a, b, c, ...]) = [a, -b, -c, ...]`
176
+ - The real part (e₀) is unchanged, all imaginary parts are negated
177
+
178
+ ---
179
+
180
+ #### inverse()
181
+
182
+ Return the multiplicative inverse.
183
+
184
+ ```javascript
185
+ state.inverse()
186
+ ```
187
+
188
+ **Returns:** SedenionState - State where `state * inverse ≈ 1`
189
+
190
+ **Throws:**
191
+ - `Error` if norm is zero
192
+
193
+ **Example:**
194
+ ```javascript
195
+ const inv = state.inverse();
196
+ const identity = state.multiply(inv);
197
+ console.log(identity.components[0]); // ~1.0
198
+ ```
199
+
200
+ ---
201
+
202
+ #### entropy()
203
+
204
+ Calculate Shannon entropy of the normalized component distribution.
205
+
206
+ ```javascript
207
+ state.entropy()
208
+ ```
209
+
210
+ **Returns:** number - Entropy value in range [0, log₂(16)]
211
+
212
+ **Notes:**
213
+ - Lower entropy = more concentrated distribution
214
+ - Higher entropy = more spread out distribution
215
+ - Used to measure "uncertainty" of state
216
+
217
+ **Example:**
218
+ ```javascript
219
+ const pure = new SedenionState([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
220
+ console.log(pure.entropy()); // 0.0 (fully concentrated)
221
+
222
+ const mixed = new SedenionState([0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
223
+ console.log(mixed.entropy()); // 2.0 (spread across 4 components)
224
+ ```
225
+
226
+ ---
227
+
228
+ #### coherence(other)
229
+
230
+ Calculate coherence (normalized inner product) with another state.
231
+
232
+ ```javascript
233
+ state.coherence(other)
234
+ ```
235
+
236
+ **Parameters:**
237
+ - `other` (SedenionState): State to compare with
238
+
239
+ **Returns:** number - Coherence value in range [0, 1]
240
+
241
+ **Notes:**
242
+ - 1.0 = identical (parallel)
243
+ - 0.0 = orthogonal
244
+ - Commutative: `a.coherence(b) === b.coherence(a)`
245
+
246
+ **Example:**
247
+ ```javascript
248
+ const same = state.coherence(state); // 1.0
249
+ const orthogonal = e0.coherence(e1); // 0.0
250
+ ```
251
+
252
+ ---
253
+
254
+ #### isZeroDivisorWith(other)
255
+
256
+ Check if multiplication with another state produces zero.
257
+
258
+ ```javascript
259
+ state.isZeroDivisorWith(other)
260
+ ```
261
+
262
+ **Parameters:**
263
+ - `other` (SedenionState): State to check against
264
+
265
+ **Returns:** boolean - True if product norm < ε
266
+
267
+ **Notes:**
268
+ - Zero-divisors are unique to sedenions (not present in octonions or lower)
269
+ - Indicates semantic contradiction
270
+
271
+ ---
272
+
273
+ #### clone()
274
+
275
+ Create a deep copy of this state.
276
+
277
+ ```javascript
278
+ state.clone()
279
+ ```
280
+
281
+ **Returns:** SedenionState - Independent copy
282
+
283
+ ---
284
+
285
+ #### toString()
286
+
287
+ Return string representation.
288
+
289
+ ```javascript
290
+ state.toString()
291
+ ```
292
+
293
+ **Returns:** string - Format: `"[c₀, c₁, ..., c₁₅]"`
294
+
295
+ ---
296
+
297
+ ### cayleyDickson(a, b, conj)
298
+
299
+ Cayley-Dickson construction for building higher algebras.
300
+
301
+ ```javascript
302
+ cayleyDickson(a, b, conj)
303
+ ```
304
+
305
+ **Parameters:**
306
+ - `a` (Array): First half of components
307
+ - `b` (Array): Second half of components
308
+ - `conj` (Function): Conjugation function
309
+
310
+ **Returns:** Object - `{ real, imag }` parts
311
+
312
+ **Notes:**
313
+ - Used internally for sedenion multiplication
314
+ - `(a, b) * (c, d) = (ac - d̄b, da + bc̄)`
315
+
316
+ ---
317
+
318
+ ### createBasisState(index, dimension)
319
+
320
+ Create a basis state with 1 in specified position.
321
+
322
+ ```javascript
323
+ createBasisState(index, dimension)
324
+ ```
325
+
326
+ **Parameters:**
327
+ - `index` (number): Position for the 1 (0-15)
328
+ - `dimension` (number): State dimension (default 16)
329
+
330
+ **Returns:** SedenionState - Basis state eᵢ
331
+
332
+ **Example:**
333
+ ```javascript
334
+ const e0 = createBasisState(0); // [1, 0, 0, ...]
335
+ const e5 = createBasisState(5); // [0, 0, 0, 0, 0, 1, 0, ...]
336
+ ```
337
+
338
+ ---
339
+
340
+ ### createRandomState(dimension)
341
+
342
+ Create a random normalized state.
343
+
344
+ ```javascript
345
+ createRandomState(dimension)
346
+ ```
347
+
348
+ **Parameters:**
349
+ - `dimension` (number): State dimension (default 16)
350
+
351
+ **Returns:** SedenionState - Random unit state
352
+
353
+ ---
354
+
355
+ ## Prime Utilities (`core/prime.js`)
356
+
357
+ ### isPrime(n)
358
+
359
+ Check if a number is prime.
360
+
361
+ ```javascript
362
+ isPrime(n)
363
+ ```
364
+
365
+ **Parameters:**
366
+ - `n` (number): Integer to check
367
+
368
+ **Returns:** boolean
369
+
370
+ **Example:**
371
+ ```javascript
372
+ isPrime(17); // true
373
+ isPrime(18); // false
374
+ ```
375
+
376
+ ---
377
+
378
+ ### nextPrime(n)
379
+
380
+ Find the next prime ≥ n.
381
+
382
+ ```javascript
383
+ nextPrime(n)
384
+ ```
385
+
386
+ **Parameters:**
387
+ - `n` (number): Starting value
388
+
389
+ **Returns:** number - Next prime
390
+
391
+ **Example:**
392
+ ```javascript
393
+ nextPrime(10); // 11
394
+ nextPrime(11); // 11
395
+ ```
396
+
397
+ ---
398
+
399
+ ### factor(n)
400
+
401
+ Return prime factorization.
402
+
403
+ ```javascript
404
+ factor(n)
405
+ ```
406
+
407
+ **Parameters:**
408
+ - `n` (number): Integer to factor
409
+
410
+ **Returns:** Array<number> - Prime factors (with repetition)
411
+
412
+ **Example:**
413
+ ```javascript
414
+ factor(12); // [2, 2, 3]
415
+ factor(17); // [17]
416
+ ```
417
+
418
+ ---
419
+
420
+ ### primesBetween(low, high)
421
+
422
+ Generate all primes in a range.
423
+
424
+ ```javascript
425
+ primesBetween(low, high)
426
+ ```
427
+
428
+ **Parameters:**
429
+ - `low` (number): Lower bound (inclusive)
430
+ - `high` (number): Upper bound (inclusive)
431
+
432
+ **Returns:** Array<number> - All primes in range
433
+
434
+ **Example:**
435
+ ```javascript
436
+ primesBetween(10, 20); // [11, 13, 17, 19]
437
+ ```
438
+
439
+ ---
440
+
441
+ ### GaussianInteger
442
+
443
+ Class for Gaussian integers (a + bi where a,b ∈ ℤ).
444
+
445
+ ```javascript
446
+ new GaussianInteger(real, imag)
447
+ ```
448
+
449
+ **Properties:**
450
+ - `real` (number): Real part
451
+ - `imag` (number): Imaginary part
452
+
453
+ **Methods:**
454
+ - `norm()`: Returns a² + b²
455
+ - `conjugate()`: Returns GaussianInteger(a, -b)
456
+ - `multiply(other)`: Gaussian integer multiplication
457
+ - `add(other)`: Gaussian integer addition
458
+
459
+ **Example:**
460
+ ```javascript
461
+ const g = new GaussianInteger(3, 4);
462
+ console.log(g.norm()); // 25
463
+ ```
464
+
465
+ ---
466
+
467
+ ### EisensteinInteger
468
+
469
+ Class for Eisenstein integers (a + bω where ω = e^(2πi/3)).
470
+
471
+ ```javascript
472
+ new EisensteinInteger(a, b)
473
+ ```
474
+
475
+ **Properties:**
476
+ - `a` (number): First coefficient
477
+ - `b` (number): Coefficient of ω
478
+
479
+ **Methods:**
480
+ - `norm()`: Returns a² - ab + b²
481
+ - `conjugate()`: Returns EisensteinInteger(a-b, -b)
482
+ - `multiply(other)`: Eisenstein multiplication
483
+
484
+ ---
485
+
486
+ ## Fano Plane (`core/fano.js`)
487
+
488
+ ### FanoPlane
489
+
490
+ Encodes the Fano plane structure for octonion multiplication.
491
+
492
+ ```javascript
493
+ const fano = new FanoPlane();
494
+ ```
495
+
496
+ **Properties:**
497
+ - `lines`: Array of 7 lines, each containing 3 point indices
498
+ - `points`: Array of 7 points
499
+
500
+ **Methods:**
501
+
502
+ #### getTriple(i, j)
503
+
504
+ Get the third element completing a Fano line.
505
+
506
+ ```javascript
507
+ fano.getTriple(i, j)
508
+ ```
509
+
510
+ **Parameters:**
511
+ - `i` (number): First element (1-7)
512
+ - `j` (number): Second element (1-7)
513
+
514
+ **Returns:** number - Third element, or 0 if not on same line
515
+
516
+ #### sign(i, j)
517
+
518
+ Get the sign for octonion multiplication eᵢ × eⱼ.
519
+
520
+ ```javascript
521
+ fano.sign(i, j)
522
+ ```
523
+
524
+ **Parameters:**
525
+ - `i` (number): First index
526
+ - `j` (number): Second index
527
+
528
+ **Returns:** number - +1 or -1
529
+
530
+ **Notes:**
531
+ - Sign depends on cyclic ordering along Fano lines
532
+ - eᵢ × eⱼ = ±eₖ where k = getTriple(i,j)
533
+
534
+ ---
535
+
536
+ ### fanoMultiply(a, b)
537
+
538
+ Multiply two octonions using Fano plane rules.
539
+
540
+ ```javascript
541
+ fanoMultiply(a, b)
542
+ ```
543
+
544
+ **Parameters:**
545
+ - `a` (Array): 8-component octonion
546
+ - `b` (Array): 8-component octonion
547
+
548
+ **Returns:** Array - 8-component product
549
+
550
+ ---
551
+
552
+ ## Semantic Sieve (`core/sieve.js`)
553
+
554
+ ### SemanticSieve
555
+
556
+ Implements the entropy-minimizing sieve algorithm.
557
+
558
+ ```javascript
559
+ new SemanticSieve(config)
560
+ ```
561
+
562
+ **Parameters:**
563
+ - `config` (Object):
564
+ - `transforms` (Array): Available transforms
565
+ - `entropyThreshold` (number): Minimum entropy target
566
+ - `maxIterations` (number): Maximum sieve passes
567
+
568
+ ---
569
+
570
+ #### sieve(primes, state)
571
+
572
+ Apply transforms until entropy is minimized.
573
+
574
+ ```javascript
575
+ sieve.sieve(primes, state)
576
+ ```
577
+
578
+ **Parameters:**
579
+ - `primes` (Array<number>): Input prime encoding
580
+ - `state` (SedenionState): Current hypercomplex state
581
+
582
+ **Returns:** Object - `{ primes, state, steps, entropy }`
583
+
584
+ ---
585
+
586
+ #### selectTransform(primes, state)
587
+
588
+ Choose the best transform to apply next.
589
+
590
+ ```javascript
591
+ sieve.selectTransform(primes, state)
592
+ ```
593
+
594
+ **Parameters:**
595
+ - `primes` (Array<number>): Current primes
596
+ - `state` (SedenionState): Current state
597
+
598
+ **Returns:** Transform | null - Best transform or null if none applicable
599
+
600
+ **Notes:**
601
+ - Selection based on predicted entropy reduction
602
+ - Considers transform priority and conditions
603
+
604
+ ---
605
+
606
+ ## LLM Coupling (`core/llm.js`)
607
+
608
+ ### LLMCoupling
609
+
610
+ Bridge between Aleph and language models.
611
+
612
+ ```javascript
613
+ new LLMCoupling(engine, options)
614
+ ```
615
+
616
+ **Parameters:**
617
+ - `engine` (AlephEngine): Aleph engine instance
618
+ - `options` (Object):
619
+ - `entropyThreshold` (number): Max allowed entropy (default 0.3)
620
+ - `coherenceThreshold` (number): Min coherence (default 0.7)
621
+ - `collapseRate` (number): Collapse strength (default 0.8)
622
+
623
+ ---
624
+
625
+ #### encodeToField(text)
626
+
627
+ Convert text to hypercomplex field state.
628
+
629
+ ```javascript
630
+ coupling.encodeToField(text)
631
+ ```
632
+
633
+ **Parameters:**
634
+ - `text` (string): Natural language text
635
+
636
+ **Returns:** SedenionState - Field representation
637
+
638
+ ---
639
+
640
+ #### validateResponse(response, queryField)
641
+
642
+ Check if LLM response is semantically valid.
643
+
644
+ ```javascript
645
+ coupling.validateResponse(response, queryField)
646
+ ```
647
+
648
+ **Parameters:**
649
+ - `response` (string): LLM output text
650
+ - `queryField` (SedenionState): Original query field
651
+
652
+ **Returns:** Object - `{ valid, coherence, entropy, issues }`
653
+
654
+ ---
655
+
656
+ #### constrainedQuery(prompt, constraintField)
657
+
658
+ Query LLM with semantic constraints.
659
+
660
+ ```javascript
661
+ coupling.constrainedQuery(prompt, constraintField)
662
+ ```
663
+
664
+ **Parameters:**
665
+ - `prompt` (string): Query prompt
666
+ - `constraintField` (SedenionState): Constraint to enforce
667
+
668
+ **Returns:** Promise<string> - Constrained response
669
+
670
+ ---
671
+
672
+ ## Constants
673
+
674
+ ### SEDENION_DIMENSION
675
+
676
+ ```javascript
677
+ const SEDENION_DIMENSION = 16;
678
+ ```
679
+
680
+ ### OCTONION_DIMENSION
681
+
682
+ ```javascript
683
+ const OCTONION_DIMENSION = 8;
684
+ ```
685
+
686
+ ### QUATERNION_DIMENSION
687
+
688
+ ```javascript
689
+ const QUATERNION_DIMENSION = 4;
690
+ ```
691
+
692
+ ### EPSILON
693
+
694
+ ```javascript
695
+ const EPSILON = 1e-10; // Floating point comparison threshold