@aleph-ai/tinyaleph 1.0.2 → 1.2.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/README.md CHANGED
@@ -10,10 +10,19 @@ A novel computational paradigm that encodes meaning as prime number signatures,
10
10
  ## Features
11
11
 
12
12
  - **Prime Semantics**: Encode concepts as unique prime number signatures
13
- - **Hypercomplex Algebra**: 16-dimensional sedenion space with non-commutative multiplication
13
+ - **Hypercomplex Algebra**: 16-dimensional sedenion space with non-commutative multiplication, exp/log/slerp
14
14
  - **Oscillator Dynamics**: Kuramoto-model synchronization for coherent reasoning
15
+ - **Stochastic Dynamics**: Noise-robust Kuramoto with Langevin, colored, and thermal noise models
16
+ - **Prime Entanglement**: Graph-based tracking of prime relationships and co-occurrences
17
+ - **Event Streaming**: Real-time monitoring with EventEmitter pattern and async iteration
15
18
  - **Entropy Minimization**: Reasoning as reduction of semantic uncertainty
16
19
  - **Multiple Backends**: Semantic (NLP), Cryptographic (hashing), Scientific (quantum-inspired)
20
+ - **Formal Type System**: Typed term calculus with N(p)/A(p)/S types and ordering constraints
21
+ - **Reduction Semantics**: Strong normalization with prime-preserving operators
22
+ - **Lambda Translation**: Model-theoretic semantics via λ-calculus embedding
23
+ - **Enochian Vocabulary**: 21-letter angelic alphabet with prime basis and sedenion operations
24
+ - **ResoFormer Architecture**: Complete prime-indexed transformer with multi-head attention
25
+ - **Multi-Z Memory**: Hierarchical memory with fast/slow/permanent channels
17
26
 
18
27
  ## Installation
19
28
 
@@ -167,6 +176,137 @@ kuramoto.step(0.01);
167
176
  console.log('Order parameter:', kuramoto.orderParameter());
168
177
  ```
169
178
 
179
+ ### Extended Synchronization Models
180
+
181
+ Five advanced Kuramoto-family models for complex synchronization dynamics:
182
+
183
+ ```javascript
184
+ const {
185
+ NetworkKuramoto, // Topology-aware coupling
186
+ AdaptiveKuramoto, // Hebbian plasticity
187
+ SakaguchiKuramoto, // Phase frustration (chimera states)
188
+ SmallWorldKuramoto, // Watts-Strogatz topology
189
+ MultiSystemCoupling // Cross-system synchronization
190
+ } = require('@aleph-ai/tinyaleph');
191
+
192
+ // Network Kuramoto with custom topology
193
+ const network = new NetworkKuramoto(frequencies, adjacencyMatrix, 0.5);
194
+ network.setFromEntanglementGraph(entanglementGraph, primeList);
195
+
196
+ // Adaptive Kuramoto with Hebbian learning
197
+ const adaptive = new AdaptiveKuramoto(frequencies, 0.3, 0.02);
198
+ // Coupling evolves: "concepts that sync together link together"
199
+
200
+ // Sakaguchi-Kuramoto with phase frustration
201
+ const sakaguchi = new SakaguchiKuramoto(frequencies, 0.5, Math.PI/4);
202
+ console.log('State:', sakaguchi.classifyState()); // synchronized/chimera/incoherent
203
+
204
+ // Small-world topology
205
+ const smallWorld = new SmallWorldKuramoto(frequencies, 4, 0.1, 0.5);
206
+ console.log('Small-world coefficient:', smallWorld.smallWorldCoefficient());
207
+
208
+ // Multi-system coupling (hierarchical or peer-to-peer)
209
+ const multi = new MultiSystemCoupling([system1, system2, system3]);
210
+ console.log('Inter-system coherence:', multi.interSystemCoherence());
211
+ ```
212
+
213
+ ### Stochastic Kuramoto Models
214
+
215
+ Noise-robust synchronization with Langevin dynamics:
216
+
217
+ ```javascript
218
+ const {
219
+ StochasticKuramoto, // White noise Langevin dynamics
220
+ ColoredNoiseKuramoto, // Ornstein-Uhlenbeck noise
221
+ ThermalKuramoto // Temperature-dependent coupling
222
+ } = require('@aleph-ai/tinyaleph');
223
+
224
+ // White noise model
225
+ const stochastic = new StochasticKuramoto(frequencies, {
226
+ coupling: 0.5,
227
+ noiseIntensity: 0.1
228
+ });
229
+
230
+ stochastic.evolve(100, 0.01);
231
+ const { mean, stdDev } = stochastic.orderParameterWithUncertainty(50, 0.01);
232
+
233
+ // Colored noise (Ornstein-Uhlenbeck process)
234
+ const colored = new ColoredNoiseKuramoto(frequencies, {
235
+ correlationTime: 2.0,
236
+ noiseIntensity: 0.1
237
+ });
238
+
239
+ // Thermal model with temperature-dependent noise
240
+ const thermal = new ThermalKuramoto(frequencies, { temperature: 2.0 });
241
+ thermal.setTemperature(4.0); // Higher temp = more noise
242
+ const Tc = thermal.estimateCriticalTemperature();
243
+ ```
244
+
245
+ ### Prime Entanglement Graph
246
+
247
+ Track prime relationships from co-occurrence and resonance:
248
+
249
+ ```javascript
250
+ const { PrimeEntanglementGraph } = require('@aleph-ai/tinyaleph');
251
+
252
+ const graph = new PrimeEntanglementGraph([2, 3, 5, 7, 11]);
253
+
254
+ // Record co-occurrences
255
+ graph.observe([2, 3], [5, 7], 0.8);
256
+ graph.observe([5, 7], [11], 0.6);
257
+
258
+ // Query relationships
259
+ const neighbors = graph.neighbors(7, 2); // 2-hop neighborhood
260
+ const path = graph.shortestPath(2, 11);
261
+
262
+ // Graph metrics
263
+ const cc = graph.clusteringCoefficient(5);
264
+ const stats = graph.stats();
265
+
266
+ // Convert to Kuramoto network
267
+ const adjacency = graph.toAdjacencyMatrix([2, 3, 5, 7, 11]);
268
+ ```
269
+
270
+ ### Event-Driven Streaming
271
+
272
+ Real-time monitoring and async iteration:
273
+
274
+ ```javascript
275
+ const {
276
+ AlephEventEmitter,
277
+ AlephMonitor,
278
+ EvolutionStream
279
+ } = require('@aleph-ai/tinyaleph');
280
+
281
+ // Event emitter with throttling
282
+ const emitter = new AlephEventEmitter();
283
+ emitter.throttle('tick', 100); // Max once per 100ms
284
+
285
+ emitter.on('collapse', ({ from, to, probability }) => {
286
+ console.log(`Collapsed with p=${probability}`);
287
+ });
288
+
289
+ emitter.on('sync', ({ orderParameter }) => {
290
+ console.log(`Synchronized: r=${orderParameter}`);
291
+ });
292
+
293
+ // Promise-based waiting
294
+ const data = await emitter.waitFor('ready', 5000);
295
+
296
+ // Async iteration over evolution
297
+ const stream = EvolutionStream.fromEvolvable(kuramoto);
298
+
299
+ for await (const state of stream.take(100)) {
300
+ console.log(state.orderParameter);
301
+ }
302
+
303
+ // Stream operators
304
+ const filtered = stream
305
+ .filter(s => s.entropy < 2.0)
306
+ .map(s => s.orderParameter)
307
+ .take(50);
308
+ ```
309
+
170
310
  ### Entropy and Stability
171
311
 
172
312
  ```javascript
@@ -180,6 +320,216 @@ const lambda = estimateLyapunov(entropyTimeSeries);
180
320
  console.log('Stable:', lambda < 0);
181
321
  ```
182
322
 
323
+ ### Hypercomplex Algebra Extensions
324
+
325
+ Extended operations for smooth interpolation and rotations:
326
+
327
+ ```javascript
328
+ const { Hypercomplex } = require('@aleph-ai/tinyaleph');
329
+
330
+ const q1 = Hypercomplex.fromArray([1, 0, 0, 0]);
331
+ const q2 = Hypercomplex.fromAxisAngle(4, [0, 0, 1], Math.PI/2);
332
+
333
+ // Exponential and logarithm
334
+ const expQ = q1.exp();
335
+ const logQ = q2.log();
336
+
337
+ // Smooth interpolation (slerp)
338
+ for (let t = 0; t <= 1; t += 0.1) {
339
+ const interpolated = q1.slerp(q2, t);
340
+ }
341
+
342
+ // Rotation operations
343
+ const rotated = q2.sandwich(vector);
344
+ const axis = q2.toAxisAngle();
345
+
346
+ // Power operations
347
+ const squared = q1.pow(2);
348
+ const cubed = q1.powInt(3);
349
+ ```
350
+
351
+ ### Multi-Z Channel Primeon Ladder
352
+
353
+ Hierarchical memory with different decay rates:
354
+
355
+ ```javascript
356
+ const { PrimeonZLadderMulti, createAdiabaticSchedule } = require('@aleph-ai/tinyaleph');
357
+
358
+ const ladder = new PrimeonZLadderMulti({
359
+ N: 32,
360
+ zChannels: [
361
+ { name: 'fast', dz: 1, leak: 0.2, decay: 0.1 },
362
+ { name: 'slow', dz: 1, leak: 0.01, decay: 0.001 },
363
+ { name: 'permanent', dz: 1, leak: 0.0, decay: 0.0 }
364
+ ],
365
+ J: 0.25
366
+ });
367
+
368
+ // Per-channel metrics
369
+ const metrics = ladder.channelMetrics();
370
+ console.log('Fast entropy:', metrics.fast.entropy);
371
+ console.log('Slow Z-flux:', metrics.slow.totalFlux);
372
+
373
+ // Adiabatic parameter schedules
374
+ const Jt = createAdiabaticSchedule(0.1, 0.5, 100, 'sinusoidal');
375
+ const ladder2 = new PrimeonZLadderMulti({ N: 16, Jt });
376
+ ```
377
+
378
+ ### ResoFormer Architecture
379
+
380
+ Complete prime-indexed transformer:
381
+
382
+ ```javascript
383
+ const {
384
+ ResoFormer,
385
+ ResoFormerBlock,
386
+ ResonantMultiHeadAttention,
387
+ PrimeFFN,
388
+ SparsePrimeState
389
+ } = require('@aleph-ai/tinyaleph');
390
+
391
+ // Create sparse prime states
392
+ const state1 = SparsePrimeState.fromPrimes([2, 3, 5]);
393
+ const state2 = SparsePrimeState.fromPrimes([7, 11, 13]);
394
+
395
+ // Multi-head attention
396
+ const attention = new ResonantMultiHeadAttention({
397
+ numHeads: 8,
398
+ numPrimes: 4096
399
+ });
400
+
401
+ const result = attention.forward(state1, [state2], [state2]);
402
+
403
+ // Full ResoFormer model
404
+ const model = new ResoFormer({
405
+ numLayers: 6,
406
+ numHeads: 8,
407
+ hiddenDim: 256
408
+ });
409
+
410
+ const outputs = model.forward([state1, state2]);
411
+ ```
412
+
413
+ ## Formal Semantics
414
+
415
+ ### Typed Term Calculus
416
+
417
+ The library implements a formal type system for prime-based compositional semantics:
418
+
419
+ ```javascript
420
+ const { N, A, FUSE, CHAIN, SENTENCE, TypeChecker } = require('@aleph-ai/tinyaleph');
421
+
422
+ // Create typed terms
423
+ const noun7 = N(7); // N(7) - noun indexed by prime 7
424
+ const adj3 = A(3); // A(3) - adjective indexed by prime 3
425
+
426
+ // Adjective application with ordering constraint (p < q)
427
+ const chain = adj3.apply(noun7); // A(3)N(7) is valid since 3 < 7
428
+
429
+ // Triadic fusion where p+q+r is prime
430
+ const fused = FUSE(3, 5, 11); // 3+5+11 = 19 (prime) ✓
431
+
432
+ // Sentence composition
433
+ const s1 = SENTENCE(7);
434
+ const s2 = SENTENCE(11);
435
+ const compound = SEQ(s1, s2); // s₁ ◦ s₂
436
+
437
+ // Type checking
438
+ const checker = new TypeChecker();
439
+ console.log(checker.inferType(noun7)); // 'N'
440
+ console.log(checker.checkApplication(adj3, noun7)); // { valid: true }
441
+ ```
442
+
443
+ ### Reduction Semantics
444
+
445
+ Strong normalization with prime-preserving operators:
446
+
447
+ ```javascript
448
+ const {
449
+ ReductionSystem,
450
+ ResonanceOperator,
451
+ NextPrimeOperator,
452
+ demonstrateStrongNormalization
453
+ } = require('@aleph-ai/tinyaleph');
454
+
455
+ // Create reduction system
456
+ const reduction = new ReductionSystem();
457
+
458
+ // Add prime-preserving operators
459
+ reduction.addOperator(new ResonanceOperator(2)); // Resonance at p=2
460
+ reduction.addOperator(new NextPrimeOperator()); // Map to next prime
461
+
462
+ // Normalize a term sequence
463
+ const result = reduction.normalize([7, 11, 13]);
464
+ console.log(result.normalForm); // Canonical form
465
+ console.log(result.steps); // Reduction trace
466
+
467
+ // Demonstrate strong normalization
468
+ const proof = demonstrateStrongNormalization([3, 5, 7], reduction);
469
+ console.log(proof.terminates); // true (guaranteed!)
470
+ ```
471
+
472
+ ### Lambda Calculus Translation
473
+
474
+ Model-theoretic semantics via τ translation:
475
+
476
+ ```javascript
477
+ const {
478
+ Translator,
479
+ LambdaEvaluator,
480
+ Semantics
481
+ } = require('@aleph-ai/tinyaleph');
482
+
483
+ // Translate prime terms to λ-expressions
484
+ const translator = new Translator();
485
+ const lambda = translator.translateNoun(N(7)); // Constant 7
486
+ const appLambda = translator.translateChain(chain);
487
+
488
+ // Evaluate λ-expressions
489
+ const evaluator = new LambdaEvaluator();
490
+ const normal = evaluator.normalize(appLambda);
491
+
492
+ // Model-theoretic interpretation
493
+ const semantics = new Semantics();
494
+ semantics.domain = [2, 3, 5, 7, 11, 13]; // Prime domain
495
+ const value = semantics.interpret(N(7)); // 7
496
+ ```
497
+
498
+ ### Enochian Vocabulary
499
+
500
+ The 21-letter angelic alphabet with prime basis and sedenion operations:
501
+
502
+ ```javascript
503
+ const {
504
+ EnochianEngine,
505
+ ENOCHIAN_ALPHABET,
506
+ PRIME_BASIS,
507
+ CORE_VOCABULARY,
508
+ SedenionElement
509
+ } = require('@aleph-ai/tinyaleph/apps/sentient/lib/enochian-vocabulary');
510
+
511
+ // 21-letter alphabet with prime mappings
512
+ console.log(ENOCHIAN_ALPHABET['A']); // { prime: 3, value: 1, angle: 51.43 }
513
+ console.log(PRIME_BASIS); // [7, 11, 13, 17, 19, 23, 29]
514
+
515
+ // Enochian engine for word processing
516
+ const engine = new EnochianEngine();
517
+
518
+ // Parse and compute word prime value
519
+ const parsed = engine.parseWord('MADRIAX'); // "O ye heavens"
520
+ console.log(parsed.primeValue);
521
+ console.log(parsed.letters);
522
+
523
+ // Sedenion operations (16-dimensional)
524
+ const s1 = new SedenionElement([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
525
+ const s2 = new SedenionElement([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
526
+ const product = s1.multiply(s2); // Non-commutative!
527
+
528
+ // Access core vocabulary (35+ Enochian words)
529
+ console.log(CORE_VOCABULARY['OL']); // "I" (first person)
530
+ console.log(CORE_VOCABULARY['ZORGE']); // "be friendly unto"
531
+ ```
532
+
183
533
  ## API Overview
184
534
 
185
535
  ### Main Exports
@@ -191,12 +541,49 @@ console.log('Stable:', lambda < 0);
191
541
  | `SemanticBackend` | Natural language processing |
192
542
  | `CryptographicBackend` | Hashing and key derivation |
193
543
  | `ScientificBackend` | Quantum-inspired computation |
194
- | `Hypercomplex` | Sedenion algebra |
544
+ | `Hypercomplex` | Sedenion algebra with exp/log/slerp |
195
545
  | `Oscillator` / `OscillatorBank` | Phase-amplitude oscillators |
196
546
  | `KuramotoModel` | Coupled oscillator synchronization |
547
+ | `NetworkKuramoto` | Topology-aware coupling |
548
+ | `AdaptiveKuramoto` | Hebbian plasticity |
549
+ | `SakaguchiKuramoto` | Phase frustration / chimera states |
550
+ | `SmallWorldKuramoto` | Watts-Strogatz topology |
551
+ | `MultiSystemCoupling` | Cross-system synchronization |
552
+ | `StochasticKuramoto` | Langevin noise dynamics |
553
+ | `ColoredNoiseKuramoto` | Ornstein-Uhlenbeck noise |
554
+ | `ThermalKuramoto` | Temperature-dependent coupling |
555
+ | `PrimeEntanglementGraph` | Prime relationship tracking |
556
+ | `AlephEventEmitter` | Event-driven monitoring |
557
+ | `AlephMonitor` | Engine state monitoring |
558
+ | `EvolutionStream` | Async iteration over evolution |
559
+ | `PrimeonZLadderMulti` | Multi-channel Z memory |
560
+ | `ResoFormer` | Prime-indexed transformer |
561
+ | `SparsePrimeState` | Sparse prime activations |
197
562
  | `hash(input)` | Quick semantic hash |
198
563
  | `deriveKey(pass, salt)` | Quick key derivation |
199
564
 
565
+ ### Formal Semantics Exports
566
+
567
+ | Export | Description |
568
+ |--------|-------------|
569
+ | `N(prime)` | Create noun term N(p) |
570
+ | `A(prime)` | Create adjective term A(p) |
571
+ | `FUSE(p, q, r)` | Create triadic fusion |
572
+ | `CHAIN(ops, noun)` | Create operator chain |
573
+ | `SENTENCE(expr)` | Create sentence from noun |
574
+ | `SEQ(s1, s2)` | Sequential composition |
575
+ | `IMPL(s1, s2)` | Implication |
576
+ | `TypeChecker` | Type inference and checking |
577
+ | `ReductionSystem` | Reduction semantics engine |
578
+ | `ResonanceOperator` | Prime resonance operator |
579
+ | `NextPrimeOperator` | Next prime mapping |
580
+ | `ModularOperator` | Modular arithmetic |
581
+ | `Translator` | λ-calculus translation |
582
+ | `LambdaEvaluator` | β-reduction evaluator |
583
+ | `Semantics` | Model-theoretic interpretation |
584
+ | `EnochianEngine` | Enochian language processing |
585
+ | `SedenionElement` | 16D hypercomplex operations |
586
+
200
587
  ### Sub-modules
201
588
 
202
589
  ```javascript
@@ -210,6 +597,32 @@ const backends = require('@aleph-ai/tinyaleph/backends');
210
597
  const engine = require('@aleph-ai/tinyaleph/engine');
211
598
  ```
212
599
 
600
+ ### New Physics Exports
601
+
602
+ | Export | Description |
603
+ |--------|-------------|
604
+ | `StochasticKuramoto` | White noise Langevin dynamics |
605
+ | `ColoredNoiseKuramoto` | Ornstein-Uhlenbeck colored noise |
606
+ | `ThermalKuramoto` | Temperature-dependent coupling |
607
+ | `PrimeonZLadderMulti` | Hierarchical Z memory channels |
608
+ | `createAdiabaticSchedule` | Parameter sweep schedules |
609
+
610
+ ### New Core Exports
611
+
612
+ | Export | Description |
613
+ |--------|-------------|
614
+ | `PrimeEntanglementGraph` | Prime co-occurrence tracking |
615
+ | `AlephEventEmitter` | Event pub/sub system |
616
+ | `AlephMonitor` | Engine monitoring wrapper |
617
+ | `EvolutionStream` | Async iteration for dynamics |
618
+ | `ResoFormer` | Full transformer model |
619
+ | `ResoFormerBlock` | Single transformer block |
620
+ | `ResonantMultiHeadAttention` | Multi-head attention |
621
+ | `PrimeFFN` | Feed-forward network |
622
+ | `PrimeLayerNorm` | Prime-preserving normalization |
623
+ | `PositionalPrimeEncoding` | Position as prime phases |
624
+ | `SparsePrimeState` | Sparse activation storage |
625
+
213
626
  ## Documentation
214
627
 
215
628
  Full documentation is available in the `docs/` directory:
@@ -224,6 +637,12 @@ Full documentation is available in the `docs/` directory:
224
637
 
225
638
  - **[Reference](./docs/reference/README.md)**: Complete API documentation
226
639
  - Core module, physics module, backends, engine
640
+
641
+ - **[Formal Semantics Examples](./examples/formal-semantics/README.md)**: New formal system demos
642
+ - Typed terms and type checking
643
+ - Reduction and normalization
644
+ - Lambda translation
645
+ - Enochian language
227
646
 
228
647
  ## Examples
229
648
 
@@ -241,6 +660,12 @@ npm run benchmark
241
660
 
242
661
  # Interactive chat
243
662
  npm run chat
663
+
664
+ # Formal semantics examples
665
+ node examples/formal-semantics/01-typed-terms.js
666
+ node examples/formal-semantics/02-reduction.js
667
+ node examples/formal-semantics/03-lambda-translation.js
668
+ node examples/formal-semantics/04-enochian-language.js
244
669
  ```
245
670
 
246
671
  ## Architecture
@@ -263,6 +688,28 @@ npm run chat
263
688
  │ • Prime encode │ │ • Key derive │ │ • Wave collapse │
264
689
  │ • Transforms │ │ • Verify │ │ • Measurement │
265
690
  └─────────────────┘ └─────────────────┘ └─────────────────┘
691
+
692
+ ┌─────────────────────────────────────────────────────────────────┐
693
+ │ Formal Semantics Layer │
694
+ ├─────────────────┬─────────────────┬─────────────────────────────┤
695
+ │ Type System │ Reduction │ Lambda Translation │
696
+ │ │ │ │
697
+ │ • N(p), A(p), S │ • Small-step → │ • τ: Terms → λ-expressions │
698
+ │ • FUSE(p,q,r) │ • ⊕ operators │ • β-reduction │
699
+ │ • ◦ composition │ • Normal forms │ • Model interpretation │
700
+ │ • ⇒ implication │ • Confluence │ • Semantic domains │
701
+ └─────────────────┴─────────────────┴─────────────────────────────┘
702
+
703
+ ┌─────────────────────────────────────────────────────────────────┐
704
+ │ Enochian Language Module │
705
+ ├─────────────────────────────────────────────────────────────────┤
706
+ │ • 21-letter alphabet with prime mappings │
707
+ │ • Prime basis PE = {7, 11, 13, 17, 19, 23, 29} │
708
+ │ • Twist angles κ(p) = 360/p degrees │
709
+ │ • 16-dimensional sedenion operations │
710
+ │ • Core vocabulary (35+ words) │
711
+ │ • The Nineteen Calls (traditional invocations) │
712
+ └─────────────────────────────────────────────────────────────────┘
266
713
  ```
267
714
 
268
715
  ## Requirements