@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,601 @@
1
+ # Physics Module Reference
2
+
3
+ The physics module provides dynamical systems, synchronization, and information-theoretic primitives.
4
+
5
+ ## Oscillator (`physics/oscillator.js`)
6
+
7
+ ### createOscillator(options)
8
+
9
+ Create a phase-amplitude oscillator.
10
+
11
+ ```javascript
12
+ createOscillator(options)
13
+ ```
14
+
15
+ **Parameters:**
16
+ - `options` (Object):
17
+ - `frequency` (number): Natural frequency ω (default 1.0)
18
+ - `phase` (number): Initial phase θ in radians (default 0)
19
+ - `amplitude` (number): Oscillation amplitude A (default 1.0)
20
+ - `damping` (number): Damping coefficient γ (default 0)
21
+ - `driving` (Object): External driving force (optional)
22
+ - `frequency` (number): Driving frequency
23
+ - `amplitude` (number): Driving amplitude
24
+
25
+ **Returns:** Oscillator object
26
+
27
+ **Example:**
28
+ ```javascript
29
+ const osc = createOscillator({
30
+ frequency: 1.0,
31
+ phase: 0,
32
+ amplitude: 1.0
33
+ });
34
+ ```
35
+
36
+ ---
37
+
38
+ ### Oscillator Object
39
+
40
+ #### Properties
41
+
42
+ | Property | Type | Description |
43
+ |----------|------|-------------|
44
+ | `frequency` | number | Natural frequency ω |
45
+ | `phase` | number | Current phase θ |
46
+ | `amplitude` | number | Current amplitude A |
47
+ | `damping` | number | Damping coefficient |
48
+ | `driving` | Object | External driving parameters |
49
+ | `state` | SedenionState | Associated hypercomplex state |
50
+
51
+ ---
52
+
53
+ #### step(dt)
54
+
55
+ Advance oscillator by time step.
56
+
57
+ ```javascript
58
+ osc.step(dt)
59
+ ```
60
+
61
+ **Parameters:**
62
+ - `dt` (number): Time step size
63
+
64
+ **Returns:** void (modifies oscillator in place)
65
+
66
+ **Notes:**
67
+ - Updates phase: `θ += ω * dt`
68
+ - Applies damping: `A *= exp(-γ * dt)`
69
+ - Applies driving if configured
70
+
71
+ ---
72
+
73
+ #### getValue()
74
+
75
+ Get current oscillator value.
76
+
77
+ ```javascript
78
+ osc.getValue()
79
+ ```
80
+
81
+ **Returns:** number - `A * cos(θ)`
82
+
83
+ ---
84
+
85
+ #### getComplexValue()
86
+
87
+ Get complex oscillator value.
88
+
89
+ ```javascript
90
+ osc.getComplexValue()
91
+ ```
92
+
93
+ **Returns:** Object - `{ real: A*cos(θ), imag: A*sin(θ) }`
94
+
95
+ ---
96
+
97
+ #### excite(energy)
98
+
99
+ Add energy to the oscillator.
100
+
101
+ ```javascript
102
+ osc.excite(energy)
103
+ ```
104
+
105
+ **Parameters:**
106
+ - `energy` (number): Energy to add
107
+
108
+ **Returns:** void
109
+
110
+ **Notes:**
111
+ - Increases amplitude: `A = sqrt(A² + 2*energy)`
112
+
113
+ ---
114
+
115
+ #### damp(factor)
116
+
117
+ Apply damping to amplitude.
118
+
119
+ ```javascript
120
+ osc.damp(factor)
121
+ ```
122
+
123
+ **Parameters:**
124
+ - `factor` (number): Damping factor (0-1)
125
+
126
+ **Returns:** void
127
+
128
+ **Notes:**
129
+ - Reduces amplitude: `A *= (1 - factor)`
130
+
131
+ ---
132
+
133
+ #### synchronizeTo(targetPhase, coupling)
134
+
135
+ Move phase toward target.
136
+
137
+ ```javascript
138
+ osc.synchronizeTo(targetPhase, coupling)
139
+ ```
140
+
141
+ **Parameters:**
142
+ - `targetPhase` (number): Target phase in radians
143
+ - `coupling` (number): Coupling strength (0-1)
144
+
145
+ **Returns:** void
146
+
147
+ **Notes:**
148
+ - Phase update: `θ += coupling * sin(targetPhase - θ)`
149
+
150
+ ---
151
+
152
+ #### attachState(state)
153
+
154
+ Associate a hypercomplex state with this oscillator.
155
+
156
+ ```javascript
157
+ osc.attachState(state)
158
+ ```
159
+
160
+ **Parameters:**
161
+ - `state` (SedenionState): State to attach
162
+
163
+ **Returns:** void
164
+
165
+ ---
166
+
167
+ ## Kuramoto Model (`physics/kuramoto.js`)
168
+
169
+ ### kuramotoStep(oscillators, coupling, dt)
170
+
171
+ Advance a system of coupled oscillators by one time step.
172
+
173
+ ```javascript
174
+ kuramotoStep(oscillators, coupling, dt)
175
+ ```
176
+
177
+ **Parameters:**
178
+ - `oscillators` (Array<Oscillator>): Array of oscillators
179
+ - `coupling` (number): Global coupling strength K
180
+ - `dt` (number): Time step size
181
+
182
+ **Returns:** void (modifies oscillators in place)
183
+
184
+ **Notes:**
185
+ - Implements: `dθᵢ/dt = ωᵢ + (K/N) Σⱼ sin(θⱼ - θᵢ)`
186
+ - All-to-all coupling topology
187
+
188
+ **Example:**
189
+ ```javascript
190
+ const oscillators = [];
191
+ for (let i = 0; i < 10; i++) {
192
+ oscillators.push(createOscillator({
193
+ frequency: 1.0 + 0.1 * Math.random(),
194
+ phase: Math.random() * 2 * Math.PI
195
+ }));
196
+ }
197
+
198
+ // Evolve system
199
+ for (let t = 0; t < 1000; t++) {
200
+ kuramotoStep(oscillators, 0.5, 0.01);
201
+ }
202
+ ```
203
+
204
+ ---
205
+
206
+ ### kuramotoOrderParameter(oscillators)
207
+
208
+ Calculate the Kuramoto order parameter measuring synchronization.
209
+
210
+ ```javascript
211
+ kuramotoOrderParameter(oscillators)
212
+ ```
213
+
214
+ **Parameters:**
215
+ - `oscillators` (Array<Oscillator>): Array of oscillators
216
+
217
+ **Returns:** Object - `{ r, psi }`
218
+ - `r` (number): Order parameter magnitude [0, 1]
219
+ - `psi` (number): Mean phase
220
+
221
+ **Notes:**
222
+ - `r = 0`: Complete desynchronization
223
+ - `r = 1`: Perfect synchronization
224
+ - Formula: `r * exp(i*ψ) = (1/N) Σⱼ exp(i*θⱼ)`
225
+
226
+ **Example:**
227
+ ```javascript
228
+ const { r, psi } = kuramotoOrderParameter(oscillators);
229
+ console.log('Synchronization:', r);
230
+ console.log('Mean phase:', psi);
231
+ ```
232
+
233
+ ---
234
+
235
+ ### setCouplingFunction(fn)
236
+
237
+ Set custom coupling function for Kuramoto dynamics.
238
+
239
+ ```javascript
240
+ setCouplingFunction(fn)
241
+ ```
242
+
243
+ **Parameters:**
244
+ - `fn` (Function): Coupling function `(oscI, oscJ, global) => number`
245
+
246
+ **Returns:** void
247
+
248
+ **Example:**
249
+ ```javascript
250
+ // Distance-dependent coupling
251
+ setCouplingFunction((i, j, global) => {
252
+ const distance = Math.abs(i.index - j.index);
253
+ return Math.sin(j.phase - i.phase) / (1 + distance);
254
+ });
255
+ ```
256
+
257
+ ---
258
+
259
+ ### criticalCoupling(oscillators)
260
+
261
+ Estimate critical coupling strength for synchronization transition.
262
+
263
+ ```javascript
264
+ criticalCoupling(oscillators)
265
+ ```
266
+
267
+ **Parameters:**
268
+ - `oscillators` (Array<Oscillator>): Array of oscillators
269
+
270
+ **Returns:** number - Estimated Kc
271
+
272
+ **Notes:**
273
+ - For identical oscillators: Kc ≈ 0
274
+ - For distributed frequencies: Kc depends on distribution width
275
+
276
+ ---
277
+
278
+ ## Entropy (`physics/entropy.js`)
279
+
280
+ ### computeEntropy(state)
281
+
282
+ Calculate Shannon entropy of state distribution.
283
+
284
+ ```javascript
285
+ computeEntropy(state)
286
+ ```
287
+
288
+ **Parameters:**
289
+ - `state` (SedenionState): Hypercomplex state
290
+
291
+ **Returns:** number - Entropy in bits
292
+
293
+ **Notes:**
294
+ - Formula: `H = -Σ pᵢ log₂(pᵢ)`
295
+ - `pᵢ = |cᵢ|² / Σ|cⱼ|²`
296
+ - Range: [0, log₂(16)] for 16D
297
+
298
+ **Example:**
299
+ ```javascript
300
+ const pureState = createBasisState(0);
301
+ console.log(computeEntropy(pureState)); // 0.0
302
+
303
+ const mixedState = new SedenionState([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]).normalize();
304
+ console.log(computeEntropy(mixedState)); // 4.0 (log₂(16))
305
+ ```
306
+
307
+ ---
308
+
309
+ ### entropyRate(states)
310
+
311
+ Calculate entropy change rate over a sequence of states.
312
+
313
+ ```javascript
314
+ entropyRate(states)
315
+ ```
316
+
317
+ **Parameters:**
318
+ - `states` (Array<SedenionState>): Sequence of states
319
+
320
+ **Returns:** number - Average entropy change per step
321
+
322
+ **Example:**
323
+ ```javascript
324
+ const trajectory = [state1, state2, state3, state4];
325
+ const rate = entropyRate(trajectory);
326
+ console.log('Entropy rate:', rate);
327
+ // Negative = entropy decreasing (convergence)
328
+ // Positive = entropy increasing (divergence)
329
+ ```
330
+
331
+ ---
332
+
333
+ ### relativeEntropy(p, q)
334
+
335
+ Calculate Kullback-Leibler divergence D_KL(P || Q).
336
+
337
+ ```javascript
338
+ relativeEntropy(p, q)
339
+ ```
340
+
341
+ **Parameters:**
342
+ - `p` (SedenionState): Distribution P
343
+ - `q` (SedenionState): Distribution Q
344
+
345
+ **Returns:** number - KL divergence (non-negative)
346
+
347
+ **Notes:**
348
+ - Asymmetric: D_KL(P||Q) ≠ D_KL(Q||P)
349
+ - D_KL = 0 iff P = Q
350
+
351
+ ---
352
+
353
+ ### mutualInformation(joint, marginal1, marginal2)
354
+
355
+ Calculate mutual information I(X; Y).
356
+
357
+ ```javascript
358
+ mutualInformation(joint, marginal1, marginal2)
359
+ ```
360
+
361
+ **Parameters:**
362
+ - `joint` (SedenionState): Joint distribution P(X,Y)
363
+ - `marginal1` (SedenionState): Marginal P(X)
364
+ - `marginal2` (SedenionState): Marginal P(Y)
365
+
366
+ **Returns:** number - Mutual information
367
+
368
+ ---
369
+
370
+ ### conditionalEntropy(joint, marginal)
371
+
372
+ Calculate conditional entropy H(X|Y).
373
+
374
+ ```javascript
375
+ conditionalEntropy(joint, marginal)
376
+ ```
377
+
378
+ **Parameters:**
379
+ - `joint` (SedenionState): Joint distribution P(X,Y)
380
+ - `marginal` (SedenionState): Marginal P(Y)
381
+
382
+ **Returns:** number - Conditional entropy
383
+
384
+ ---
385
+
386
+ ## Lyapunov Exponents (`physics/lyapunov.js`)
387
+
388
+ ### lyapunov(trajectory)
389
+
390
+ Estimate largest Lyapunov exponent from a trajectory.
391
+
392
+ ```javascript
393
+ lyapunov(trajectory)
394
+ ```
395
+
396
+ **Parameters:**
397
+ - `trajectory` (Array<number>): Time series of scalar values
398
+
399
+ **Returns:** number - Estimated Lyapunov exponent λ
400
+
401
+ **Notes:**
402
+ - λ < 0: Stable (converging)
403
+ - λ = 0: Marginally stable
404
+ - λ > 0: Chaotic (diverging)
405
+
406
+ **Example:**
407
+ ```javascript
408
+ const entropies = states.map(s => s.entropy());
409
+ const lambda = lyapunov(entropies);
410
+
411
+ if (lambda < 0) {
412
+ console.log('System is converging');
413
+ } else if (lambda > 0) {
414
+ console.log('System is chaotic');
415
+ }
416
+ ```
417
+
418
+ ---
419
+
420
+ ### lyapunovSpectrum(trajectories)
421
+
422
+ Estimate full Lyapunov spectrum from multiple trajectories.
423
+
424
+ ```javascript
425
+ lyapunovSpectrum(trajectories)
426
+ ```
427
+
428
+ **Parameters:**
429
+ - `trajectories` (Array<Array<number>>): Multiple time series
430
+
431
+ **Returns:** Array<number> - Sorted exponents (largest first)
432
+
433
+ ---
434
+
435
+ ### stabilityAnalysis(state, dynamics, epsilon)
436
+
437
+ Analyze local stability around a state.
438
+
439
+ ```javascript
440
+ stabilityAnalysis(state, dynamics, epsilon)
441
+ ```
442
+
443
+ **Parameters:**
444
+ - `state` (SedenionState): State to analyze
445
+ - `dynamics` (Function): Evolution function `state => newState`
446
+ - `epsilon` (number): Perturbation size (default 1e-6)
447
+
448
+ **Returns:** Object - `{ stable, exponents, eigenvalues }`
449
+
450
+ ---
451
+
452
+ ## Collapse (`physics/collapse.js`)
453
+
454
+ ### collapse(state, target, strength)
455
+
456
+ Collapse a state toward a target.
457
+
458
+ ```javascript
459
+ collapse(state, target, strength)
460
+ ```
461
+
462
+ **Parameters:**
463
+ - `state` (SedenionState): State to collapse
464
+ - `target` (SedenionState): Target attractor
465
+ - `strength` (number): Collapse strength (0-1)
466
+
467
+ **Returns:** SedenionState - Collapsed state
468
+
469
+ **Notes:**
470
+ - `strength = 0`: No change
471
+ - `strength = 1`: Complete collapse to target
472
+ - Interpolates: `result = (1-s)*state + s*target` (normalized)
473
+
474
+ **Example:**
475
+ ```javascript
476
+ const superposition = createRandomState();
477
+ const basis = createBasisState(0);
478
+
479
+ const partial = collapse(superposition, basis, 0.5);
480
+ const full = collapse(superposition, basis, 1.0);
481
+
482
+ console.log(full.coherence(basis)); // 1.0
483
+ ```
484
+
485
+ ---
486
+
487
+ ### measurementCollapse(state, basis)
488
+
489
+ Perform measurement collapse with probabilistic outcome.
490
+
491
+ ```javascript
492
+ measurementCollapse(state, basis)
493
+ ```
494
+
495
+ **Parameters:**
496
+ - `state` (SedenionState): State to measure
497
+ - `basis` (Array<SedenionState>): Measurement basis states
498
+
499
+ **Returns:** Object - `{ outcome, probability, finalState }`
500
+
501
+ **Notes:**
502
+ - Outcome chosen probabilistically based on |⟨state|basis[i]⟩|²
503
+ - Final state is the chosen basis state
504
+
505
+ **Example:**
506
+ ```javascript
507
+ const superposition = createRandomState();
508
+ const basis = [
509
+ createBasisState(0),
510
+ createBasisState(1),
511
+ createBasisState(2)
512
+ ];
513
+
514
+ const result = measurementCollapse(superposition, basis);
515
+ console.log('Measured:', result.outcome);
516
+ console.log('Probability:', result.probability);
517
+ ```
518
+
519
+ ---
520
+
521
+ ### collapseThreshold(state)
522
+
523
+ Calculate entropy threshold for spontaneous collapse.
524
+
525
+ ```javascript
526
+ collapseThreshold(state)
527
+ ```
528
+
529
+ **Parameters:**
530
+ - `state` (SedenionState): State to evaluate
531
+
532
+ **Returns:** number - Entropy threshold
533
+
534
+ **Notes:**
535
+ - States with entropy below threshold are "collapsed"
536
+ - Threshold depends on state structure
537
+
538
+ ---
539
+
540
+ ### progressiveCollapse(state, target, steps)
541
+
542
+ Gradually collapse over multiple steps.
543
+
544
+ ```javascript
545
+ progressiveCollapse(state, target, steps)
546
+ ```
547
+
548
+ **Parameters:**
549
+ - `state` (SedenionState): Initial state
550
+ - `target` (SedenionState): Target state
551
+ - `steps` (number): Number of collapse steps
552
+
553
+ **Returns:** Array<SedenionState> - Trajectory from state to target
554
+
555
+ **Example:**
556
+ ```javascript
557
+ const trajectory = progressiveCollapse(initial, final, 10);
558
+ for (const step of trajectory) {
559
+ console.log('Entropy:', step.entropy());
560
+ }
561
+ ```
562
+
563
+ ---
564
+
565
+ ## Integration Utilities
566
+
567
+ ### rk4Step(state, derivative, dt)
568
+
569
+ Fourth-order Runge-Kutta integration step.
570
+
571
+ ```javascript
572
+ rk4Step(state, derivative, dt)
573
+ ```
574
+
575
+ **Parameters:**
576
+ - `state` (Object): Current state
577
+ - `derivative` (Function): Derivative function `state => dstate/dt`
578
+ - `dt` (number): Time step
579
+
580
+ **Returns:** Object - Updated state
581
+
582
+ ---
583
+
584
+ ### adaptiveStep(state, derivative, dt, tolerance)
585
+
586
+ Adaptive time step integration.
587
+
588
+ ```javascript
589
+ adaptiveStep(state, derivative, dt, tolerance)
590
+ ```
591
+
592
+ **Parameters:**
593
+ - `state` (Object): Current state
594
+ - `derivative` (Function): Derivative function
595
+ - `dt` (number): Initial time step
596
+ - `tolerance` (number): Error tolerance
597
+
598
+ **Returns:** Object - `{ state, dt, error }`
599
+
600
+ **Notes:**
601
+ - Automatically adjusts dt to maintain error below tolerance