@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.
- package/LICENSE +21 -0
- package/README.md +278 -0
- package/backends/cryptographic/index.js +196 -0
- package/backends/index.js +15 -0
- package/backends/interface.js +89 -0
- package/backends/scientific/index.js +272 -0
- package/backends/semantic/index.js +527 -0
- package/backends/semantic/surface.js +393 -0
- package/backends/semantic/two-layer.js +375 -0
- package/core/fano.js +127 -0
- package/core/hilbert.js +564 -0
- package/core/hypercomplex.js +141 -0
- package/core/index.js +133 -0
- package/core/llm.js +132 -0
- package/core/prime.js +184 -0
- package/core/resonance.js +695 -0
- package/core/rformer-tf.js +1086 -0
- package/core/rformer.js +806 -0
- package/core/sieve.js +350 -0
- package/data.json +8163 -0
- package/docs/EXAMPLES_PLAN.md +293 -0
- package/docs/README.md +159 -0
- package/docs/design/ALEPH_CHAT_ARCHITECTURE.md +499 -0
- package/docs/guide/01-quickstart.md +298 -0
- package/docs/guide/02-semantic-computing.md +409 -0
- package/docs/guide/03-cryptographic.md +420 -0
- package/docs/guide/04-scientific.md +494 -0
- package/docs/guide/05-llm-integration.md +568 -0
- package/docs/guide/06-advanced.md +996 -0
- package/docs/guide/README.md +188 -0
- package/docs/reference/01-core.md +695 -0
- package/docs/reference/02-physics.md +601 -0
- package/docs/reference/03-backends.md +892 -0
- package/docs/reference/04-engine.md +632 -0
- package/docs/reference/README.md +252 -0
- package/docs/theory/01-prime-semantics.md +327 -0
- package/docs/theory/02-hypercomplex-algebra.md +421 -0
- package/docs/theory/03-phase-synchronization.md +364 -0
- package/docs/theory/04-entropy-reasoning.md +348 -0
- package/docs/theory/05-non-commutativity.md +402 -0
- package/docs/theory/06-two-layer-meaning.md +414 -0
- package/docs/theory/07-resonant-field-interface.md +419 -0
- package/docs/theory/08-semantic-sieve.md +520 -0
- package/docs/theory/09-temporal-emergence.md +298 -0
- package/docs/theory/10-quaternionic-memory.md +415 -0
- package/docs/theory/README.md +162 -0
- package/engine/aleph.js +418 -0
- package/engine/index.js +7 -0
- package/index.js +23 -0
- package/modular.js +254 -0
- package/package.json +99 -0
- package/physics/collapse.js +95 -0
- package/physics/entropy.js +88 -0
- package/physics/index.js +65 -0
- package/physics/kuramoto.js +91 -0
- package/physics/lyapunov.js +80 -0
- package/physics/oscillator.js +95 -0
- package/types/index.d.ts +575 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Part I: Theoretical Foundations
|
|
2
|
+
|
|
3
|
+
This section provides a deep exploration of the mathematical and conceptual foundations underlying Aleph. Understanding these foundations is essential for leveraging the full power of semantic computing.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
1. [Prime Semantics](./01-prime-semantics.md) - How prime numbers encode meaning
|
|
8
|
+
2. [Hypercomplex Algebra](./02-hypercomplex-algebra.md) - Cayley-Dickson construction and sedenions
|
|
9
|
+
3. [Phase Synchronization](./03-phase-synchronization.md) - Kuramoto oscillator dynamics
|
|
10
|
+
4. [Entropy and Reasoning](./04-entropy-reasoning.md) - Reasoning as entropy minimization
|
|
11
|
+
5. [Non-Commutativity](./05-non-commutativity.md) - Why word order matters
|
|
12
|
+
6. [Two-Layer Meaning](./06-two-layer-meaning.md) - Prime substrate vs. surface vocabulary
|
|
13
|
+
7. [Resonant Field Interface](./07-resonant-field-interface.md) - Consciousness coupling theory
|
|
14
|
+
8. [The Semantic Sieve](./08-semantic-sieve.md) - Ensuring prime uniqueness
|
|
15
|
+
9. [Temporal Emergence](./09-temporal-emergence.md) - Time as emergent from prime-resonant symbolic computation
|
|
16
|
+
10. [Quaternionic Memory Field](./10-quaternionic-memory.md) - 4D rotational semantics and non-commutative memory
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## The Paradigm Shift
|
|
21
|
+
|
|
22
|
+
Aleph represents a fundamental shift in how we think about computation:
|
|
23
|
+
|
|
24
|
+
| Traditional Computing | Semantic Computing |
|
|
25
|
+
|----------------------|-------------------|
|
|
26
|
+
| Operates on bits | Operates on concepts |
|
|
27
|
+
| Performs calculation | Performs reasoning |
|
|
28
|
+
| Produces outputs | Produces understanding |
|
|
29
|
+
| Symbolic manipulation | Meaning transformation |
|
|
30
|
+
|
|
31
|
+
### The Core Equations
|
|
32
|
+
|
|
33
|
+
The mathematical foundation rests on three key relationships:
|
|
34
|
+
|
|
35
|
+
**1. Prime Encoding**
|
|
36
|
+
```
|
|
37
|
+
concept → {p₁, p₂, ..., pₙ} where pᵢ are primes
|
|
38
|
+
```
|
|
39
|
+
Every concept can be uniquely represented as a set of prime numbers.
|
|
40
|
+
|
|
41
|
+
**2. Hypercomplex State**
|
|
42
|
+
```
|
|
43
|
+
state = Σᵢ qᵢ|pᵢ⟩ ∈ H₁₆ (16D sedenion space)
|
|
44
|
+
```
|
|
45
|
+
Prime signatures are embedded in hypercomplex space where multiplication is non-commutative.
|
|
46
|
+
|
|
47
|
+
**3. Entropy Minimization**
|
|
48
|
+
```
|
|
49
|
+
reasoning: H(state) → min
|
|
50
|
+
```
|
|
51
|
+
Reasoning is the process of transforming a high-entropy (confused) state into a low-entropy (clear) state.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## The Prime Hypothesis
|
|
56
|
+
|
|
57
|
+
The central hypothesis of Aleph is:
|
|
58
|
+
|
|
59
|
+
> **Meaning has structure, and that structure is prime.**
|
|
60
|
+
|
|
61
|
+
Just as matter is composed of atoms and atoms are composed of fundamental particles, meaning is composed of semantic atoms—irreducible concepts that combine to form complex ideas.
|
|
62
|
+
|
|
63
|
+
We identify these semantic atoms with prime numbers because:
|
|
64
|
+
|
|
65
|
+
1. **Uniqueness**: Every integer has a unique prime factorization (Fundamental Theorem of Arithmetic)
|
|
66
|
+
2. **Composition**: Primes combine through multiplication to form all integers
|
|
67
|
+
3. **Irreducibility**: Primes cannot be decomposed further
|
|
68
|
+
4. **Infinitude**: There are infinitely many primes (infinitely many base concepts possible)
|
|
69
|
+
|
|
70
|
+
### The Twist-Number Correspondence
|
|
71
|
+
|
|
72
|
+
Building on work in topological field theory, we establish a correspondence:
|
|
73
|
+
|
|
74
|
+
| Mathematical Object | Semantic Interpretation |
|
|
75
|
+
|--------------------|------------------------|
|
|
76
|
+
| Prime p | Irreducible concept |
|
|
77
|
+
| Integer n = Πpᵢᵏⁱ | Composite concept |
|
|
78
|
+
| Prime factorization | Semantic decomposition |
|
|
79
|
+
| GCD(a,b) | Common meaning |
|
|
80
|
+
| LCM(a,b) | Combined meaning |
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Why Hypercomplex?
|
|
85
|
+
|
|
86
|
+
Standard vector spaces are inadequate for semantic computing because:
|
|
87
|
+
|
|
88
|
+
1. **Commutativity**: Vector addition is commutative, but meaning is not ("dog bites man" ≠ "man bites dog")
|
|
89
|
+
2. **Flatness**: Vector spaces lack intrinsic curvature, but semantic space is curved
|
|
90
|
+
3. **No dynamics**: Vectors are static, but meaning evolves
|
|
91
|
+
|
|
92
|
+
Hypercomplex algebras (quaternions, octonions, sedenions) provide:
|
|
93
|
+
|
|
94
|
+
1. **Non-commutativity**: A × B ≠ B × A, encoding word order
|
|
95
|
+
2. **Non-associativity**: (A × B) × C ≠ A × (B × C), encoding grouping
|
|
96
|
+
3. **Zero-divisors**: A × B = 0 even when A,B ≠ 0, encoding paradoxes and tunnels
|
|
97
|
+
4. **Rich geometry**: Natural embedding of rotations and transformations
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Why Oscillators?
|
|
102
|
+
|
|
103
|
+
Static representations cannot capture the dynamic nature of thought. Aleph uses coupled oscillators because:
|
|
104
|
+
|
|
105
|
+
1. **Phase encodes state**: The phase of an oscillator represents where it is in its cycle
|
|
106
|
+
2. **Frequency encodes identity**: Different primes resonate at different frequencies
|
|
107
|
+
3. **Coupling encodes relationship**: Oscillators that interact tend to synchronize
|
|
108
|
+
4. **Order parameter measures coherence**: How synchronized a system is indicates how unified the meaning is
|
|
109
|
+
|
|
110
|
+
The Kuramoto model provides a mathematical framework for studying synchronization:
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
dθᵢ/dt = ωᵢ + (K/N) Σⱼ sin(θⱼ - θᵢ)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Where:
|
|
117
|
+
- θᵢ is the phase of oscillator i
|
|
118
|
+
- ωᵢ is its natural frequency
|
|
119
|
+
- K is the coupling strength
|
|
120
|
+
- N is the number of oscillators
|
|
121
|
+
|
|
122
|
+
When K exceeds a critical threshold, oscillators spontaneously synchronize—analogous to disparate concepts unifying into coherent understanding.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## The Architecture
|
|
127
|
+
|
|
128
|
+
Aleph's architecture mirrors these theoretical foundations:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
┌────────────────────────────────────────────────────────────┐
|
|
132
|
+
│ LAYER 1: PRIME SUBSTRATE │
|
|
133
|
+
│ │
|
|
134
|
+
│ Universal, pre-linguistic meaning structure │
|
|
135
|
+
│ Same primes = same meaning, regardless of language │
|
|
136
|
+
│ │
|
|
137
|
+
│ love = [2, 3, 5] truth = [7, 11, 13] │
|
|
138
|
+
└────────────────────────────────────────────────────────────┘
|
|
139
|
+
↕
|
|
140
|
+
┌────────────────────────────────────────────────────────────┐
|
|
141
|
+
│ LAYER 2: SURFACE VOCABULARY │
|
|
142
|
+
│ │
|
|
143
|
+
│ Language-specific, culture-dependent word choice │
|
|
144
|
+
│ Same primes → different words in different contexts │
|
|
145
|
+
│ │
|
|
146
|
+
│ [2, 3, 5] → "love" (English) │
|
|
147
|
+
│ [2, 3, 5] → "amour" (French) │
|
|
148
|
+
│ [2, 3, 5] → "❤️" (Emoji) │
|
|
149
|
+
└────────────────────────────────────────────────────────────┘
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
This two-layer architecture explains:
|
|
153
|
+
- Why translation is possible (same primes)
|
|
154
|
+
- Why translation is hard (different surface forms)
|
|
155
|
+
- Why poetry survives translation (prime resonance transcends words)
|
|
156
|
+
- Why puns don't translate (they depend on surface form)
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Continue Reading
|
|
161
|
+
|
|
162
|
+
- [Prime Semantics →](./01-prime-semantics.md)
|
package/engine/aleph.js
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AlephEngine - Unified backend-agnostic prime-based computing engine
|
|
3
|
+
*
|
|
4
|
+
* FIELD-BASED COMPUTATION:
|
|
5
|
+
* The answer emerges from oscillator dynamics, not symbolic manipulation.
|
|
6
|
+
* We excite the field, evolve it, and sample at coherent emission moments.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { Hypercomplex } = require('../core/hypercomplex');
|
|
10
|
+
const { KuramotoModel } = require('../physics/kuramoto');
|
|
11
|
+
const { stateEntropy, coherence } = require('../physics/entropy');
|
|
12
|
+
const { estimateLyapunov, adaptiveCoupling, classifyStability } = require('../physics/lyapunov');
|
|
13
|
+
const { collapseProbability, shouldCollapse, bornMeasurement } = require('../physics/collapse');
|
|
14
|
+
|
|
15
|
+
class AlephEngine {
|
|
16
|
+
constructor(backend, options = {}) {
|
|
17
|
+
this.backend = backend;
|
|
18
|
+
this.options = {
|
|
19
|
+
dampingRate: 0.02,
|
|
20
|
+
baseCoupling: 0.3,
|
|
21
|
+
collapseCoherence: 0.7,
|
|
22
|
+
collapseEntropy: 1.8,
|
|
23
|
+
maxTransformSteps: 5,
|
|
24
|
+
entropyThreshold: 0.5,
|
|
25
|
+
// Field evolution parameters
|
|
26
|
+
maxEvolutionSteps: 100, // Max timesteps to evolve
|
|
27
|
+
coherenceThreshold: 0.6, // Min order parameter for coherent emission
|
|
28
|
+
amplitudeThreshold: 0.1, // Min amplitude to consider a prime "active"
|
|
29
|
+
stableCoherence: 0.85, // Order parameter indicating stable state
|
|
30
|
+
sampleWindow: 10, // Keep best N frames
|
|
31
|
+
dt: 0.016,
|
|
32
|
+
...options
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this._initializeOscillators();
|
|
36
|
+
this._resetState();
|
|
37
|
+
this.history = [];
|
|
38
|
+
this.frames = []; // Sampled coherent frames
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_initializeOscillators() {
|
|
42
|
+
const primes = this.backend.getPrimes().slice(0, this.backend.dimension);
|
|
43
|
+
const frequencies = this.backend.primesToFrequencies(primes);
|
|
44
|
+
this.oscillators = new KuramotoModel(frequencies, this.options.baseCoupling);
|
|
45
|
+
this.primeList = primes;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_resetState() {
|
|
49
|
+
this.state = Hypercomplex.zero(this.backend.dimension);
|
|
50
|
+
this.entropy = 0;
|
|
51
|
+
this.coherenceValue = 0;
|
|
52
|
+
this.lyapunov = 0;
|
|
53
|
+
this.collapseIntegral = 0;
|
|
54
|
+
this.stability = 'MARGINAL';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Main processing pipeline: encode → excite → evolve → sample → decode
|
|
59
|
+
*
|
|
60
|
+
* FIELD-BASED COMPUTATION:
|
|
61
|
+
* The answer emerges from oscillator dynamics. We excite the field with
|
|
62
|
+
* input primes, capture the transient response (before full sync),
|
|
63
|
+
* and decode from the input-weighted field state.
|
|
64
|
+
*/
|
|
65
|
+
run(input) {
|
|
66
|
+
// 1. Encode input to primes
|
|
67
|
+
const inputPrimes = this.backend.encode(input);
|
|
68
|
+
const inputPrimeSet = new Set(inputPrimes);
|
|
69
|
+
|
|
70
|
+
// 2. Capture baseline before excitation
|
|
71
|
+
const baselineAmplitudes = [...this.oscillators.getWeightedAmplitudes()];
|
|
72
|
+
|
|
73
|
+
// 3. Excite oscillators corresponding to input primes
|
|
74
|
+
this.excite(inputPrimes);
|
|
75
|
+
|
|
76
|
+
// 4. EVOLVE field and collect INPUT-SENSITIVE frames
|
|
77
|
+
this.frames = [];
|
|
78
|
+
let evolutionSteps = 0;
|
|
79
|
+
|
|
80
|
+
// Track differential response (excited vs baseline)
|
|
81
|
+
let maxDifferential = 0;
|
|
82
|
+
let bestDifferentialFrame = null;
|
|
83
|
+
|
|
84
|
+
for (let i = 0; i < this.options.maxEvolutionSteps; i++) {
|
|
85
|
+
this.tick(this.options.dt);
|
|
86
|
+
evolutionSteps++;
|
|
87
|
+
|
|
88
|
+
const currentAmplitudes = this.oscillators.getWeightedAmplitudes();
|
|
89
|
+
const order = this.oscillators.orderParameter();
|
|
90
|
+
|
|
91
|
+
// Compute input-weighted differential response
|
|
92
|
+
// Higher score = oscillators excited by INPUT are responding more than baseline
|
|
93
|
+
let inputResponse = 0;
|
|
94
|
+
let otherResponse = 0;
|
|
95
|
+
|
|
96
|
+
for (let j = 0; j < this.primeList.length; j++) {
|
|
97
|
+
const diff = Math.abs(currentAmplitudes[j]) - Math.abs(baselineAmplitudes[j] || 0);
|
|
98
|
+
if (inputPrimeSet.has(this.primeList[j])) {
|
|
99
|
+
inputResponse += diff;
|
|
100
|
+
} else {
|
|
101
|
+
otherResponse += Math.abs(diff);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Differential: how much MORE the input primes respond vs other primes
|
|
106
|
+
const differential = inputResponse - otherResponse * 0.3;
|
|
107
|
+
|
|
108
|
+
// Sample frames with good differential response
|
|
109
|
+
if (differential > 0 && order > this.options.coherenceThreshold * 0.5) {
|
|
110
|
+
const frame = {
|
|
111
|
+
step: i,
|
|
112
|
+
order: order,
|
|
113
|
+
differential: differential,
|
|
114
|
+
amplitudes: [...currentAmplitudes],
|
|
115
|
+
entropy: this.entropy,
|
|
116
|
+
stability: this.stability
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
this.frames.push(frame);
|
|
120
|
+
|
|
121
|
+
if (differential > maxDifferential) {
|
|
122
|
+
maxDifferential = differential;
|
|
123
|
+
bestDifferentialFrame = frame;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Keep only frames with good response
|
|
127
|
+
if (this.frames.length > this.options.sampleWindow) {
|
|
128
|
+
this.frames.sort((a, b) => b.differential - a.differential);
|
|
129
|
+
this.frames = this.frames.slice(0, this.options.sampleWindow);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Stop if we found a strong coherent input-response
|
|
134
|
+
if (differential > 1.0 && order > this.options.coherenceThreshold &&
|
|
135
|
+
this.stability !== 'CHAOTIC') {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 5. SELECT best frame by differential (not just order)
|
|
141
|
+
let bestFrame = bestDifferentialFrame ||
|
|
142
|
+
(this.frames.length > 0 ? this.frames[0] : null);
|
|
143
|
+
|
|
144
|
+
// 6. DECODE from field state with input weighting
|
|
145
|
+
let resultPrimes, output, steps = [];
|
|
146
|
+
|
|
147
|
+
if (bestFrame && bestFrame.differential > 0) {
|
|
148
|
+
// Field-based: decode from transient amplitudes, weighted by input
|
|
149
|
+
resultPrimes = this.amplitudesToPrimes(bestFrame.amplitudes, inputPrimeSet);
|
|
150
|
+
output = this.backend.decode(resultPrimes);
|
|
151
|
+
} else {
|
|
152
|
+
// Fallback: symbolic reasoning (field didn't respond to input)
|
|
153
|
+
const reasoningResult = this.reason(inputPrimes);
|
|
154
|
+
resultPrimes = reasoningResult.primes;
|
|
155
|
+
output = this.backend.decode(resultPrimes);
|
|
156
|
+
steps = reasoningResult.steps;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 7. Update engine state
|
|
160
|
+
this.coherenceValue = bestFrame ? bestFrame.order : this.oscillators.orderParameter();
|
|
161
|
+
|
|
162
|
+
// 8. Check for state collapse
|
|
163
|
+
const collapsed = this.checkCollapse();
|
|
164
|
+
|
|
165
|
+
// 9. Build result object
|
|
166
|
+
const result = {
|
|
167
|
+
input,
|
|
168
|
+
inputPrimes,
|
|
169
|
+
resultPrimes,
|
|
170
|
+
output,
|
|
171
|
+
entropy: this.entropy,
|
|
172
|
+
coherence: this.coherenceValue,
|
|
173
|
+
lyapunov: this.lyapunov,
|
|
174
|
+
stability: this.stability,
|
|
175
|
+
collapsed,
|
|
176
|
+
steps,
|
|
177
|
+
evolutionSteps,
|
|
178
|
+
framesCollected: this.frames.length,
|
|
179
|
+
bestFrameOrder: bestFrame ? bestFrame.order : 0,
|
|
180
|
+
bestDifferential: bestFrame ? bestFrame.differential : 0,
|
|
181
|
+
fieldBased: bestFrame && bestFrame.differential > 0,
|
|
182
|
+
orderParameter: this.oscillators.orderParameter()
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// 10. Record history
|
|
186
|
+
this.history.push({
|
|
187
|
+
time: Date.now(),
|
|
188
|
+
input,
|
|
189
|
+
output,
|
|
190
|
+
entropy: this.entropy,
|
|
191
|
+
fieldBased: result.fieldBased
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Convert oscillator amplitudes to primes, prioritizing input-excited oscillators
|
|
199
|
+
*
|
|
200
|
+
* @param amplitudes - Current oscillator amplitudes
|
|
201
|
+
* @param inputPrimes - Set of primes that were excited by input
|
|
202
|
+
*/
|
|
203
|
+
amplitudesToPrimes(amplitudes, inputPrimes = new Set()) {
|
|
204
|
+
const activePrimes = [];
|
|
205
|
+
|
|
206
|
+
for (let i = 0; i < Math.min(amplitudes.length, this.primeList.length); i++) {
|
|
207
|
+
const amplitude = Math.abs(amplitudes[i]);
|
|
208
|
+
if (amplitude > this.options.amplitudeThreshold) {
|
|
209
|
+
const prime = this.primeList[i];
|
|
210
|
+
// Boost score for primes that were in the input
|
|
211
|
+
const inputBoost = inputPrimes.has(prime) ? 2.0 : 1.0;
|
|
212
|
+
|
|
213
|
+
activePrimes.push({
|
|
214
|
+
prime: prime,
|
|
215
|
+
amplitude: amplitude,
|
|
216
|
+
score: amplitude * inputBoost
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Sort by score (input-boosted amplitude)
|
|
222
|
+
activePrimes.sort((a, b) => b.score - a.score);
|
|
223
|
+
|
|
224
|
+
// Return just the primes
|
|
225
|
+
return activePrimes.map(p => p.prime);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Excite oscillators corresponding to given primes
|
|
230
|
+
*/
|
|
231
|
+
excite(primes) {
|
|
232
|
+
this.oscillators.exciteByPrimes(primes, this.primeList, 0.5);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Advance physics simulation by one timestep
|
|
237
|
+
*/
|
|
238
|
+
tick(dt = 0.016) {
|
|
239
|
+
// Estimate Lyapunov exponent
|
|
240
|
+
this.lyapunov = estimateLyapunov(this.oscillators.oscillators);
|
|
241
|
+
this.stability = classifyStability(this.lyapunov);
|
|
242
|
+
|
|
243
|
+
// Adapt coupling based on stability
|
|
244
|
+
this.oscillators.K = adaptiveCoupling(this.options.baseCoupling, this.lyapunov);
|
|
245
|
+
|
|
246
|
+
// Advance oscillators
|
|
247
|
+
this.oscillators.tick(dt);
|
|
248
|
+
|
|
249
|
+
// Build state from oscillator amplitudes
|
|
250
|
+
const amplitudes = this.oscillators.getWeightedAmplitudes();
|
|
251
|
+
this.state = new Hypercomplex(
|
|
252
|
+
this.backend.dimension,
|
|
253
|
+
Float64Array.from(amplitudes.slice(0, this.backend.dimension))
|
|
254
|
+
).normalize();
|
|
255
|
+
|
|
256
|
+
// Update entropy and collapse integral
|
|
257
|
+
this.entropy = stateEntropy(this.state);
|
|
258
|
+
this.collapseIntegral += this.entropy * dt * 0.1;
|
|
259
|
+
|
|
260
|
+
return this.state;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Entropy-minimizing reasoning via transform search
|
|
265
|
+
*/
|
|
266
|
+
reason(primes) {
|
|
267
|
+
const transforms = this.backend.getTransforms();
|
|
268
|
+
let current = [...new Set(primes)];
|
|
269
|
+
let state = this.backend.primesToState(current);
|
|
270
|
+
let H = stateEntropy(state);
|
|
271
|
+
const steps = [];
|
|
272
|
+
|
|
273
|
+
for (let i = 0; i < this.options.maxTransformSteps && H > this.options.entropyThreshold; i++) {
|
|
274
|
+
let best = null;
|
|
275
|
+
let bestH = H;
|
|
276
|
+
let bestPrimes = current;
|
|
277
|
+
|
|
278
|
+
// Search for entropy-reducing transform
|
|
279
|
+
for (const transform of transforms) {
|
|
280
|
+
const newPrimes = this.backend.applyTransform(current, transform);
|
|
281
|
+
|
|
282
|
+
// Skip if no change
|
|
283
|
+
if (newPrimes.length === current.length &&
|
|
284
|
+
newPrimes.every((p, idx) => current[idx] === p)) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const newState = this.backend.primesToState(newPrimes);
|
|
289
|
+
const newH = stateEntropy(newState);
|
|
290
|
+
|
|
291
|
+
if (newH < bestH) {
|
|
292
|
+
best = transform;
|
|
293
|
+
bestH = newH;
|
|
294
|
+
bestPrimes = newPrimes;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (!best) break;
|
|
299
|
+
|
|
300
|
+
steps.push({
|
|
301
|
+
step: i + 1,
|
|
302
|
+
transform: best.n || best.name || 'unnamed',
|
|
303
|
+
entropyDrop: H - bestH,
|
|
304
|
+
primes: bestPrimes.slice(0, 5)
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
current = bestPrimes;
|
|
308
|
+
state = this.backend.primesToState(current);
|
|
309
|
+
H = bestH;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return { primes: current, state, entropy: H, steps };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Check if state should collapse
|
|
317
|
+
*/
|
|
318
|
+
checkCollapse() {
|
|
319
|
+
const prob = collapseProbability(this.collapseIntegral, this.lyapunov);
|
|
320
|
+
|
|
321
|
+
if (shouldCollapse(this.coherenceValue, this.entropy, prob, {
|
|
322
|
+
minCoherence: this.options.collapseCoherence,
|
|
323
|
+
minEntropy: this.options.collapseEntropy
|
|
324
|
+
})) {
|
|
325
|
+
this.collapseIntegral = 0;
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Get current physics state for monitoring
|
|
333
|
+
*/
|
|
334
|
+
getPhysicsState() {
|
|
335
|
+
return {
|
|
336
|
+
state: this.state,
|
|
337
|
+
entropy: this.entropy,
|
|
338
|
+
coherence: this.coherenceValue,
|
|
339
|
+
lyapunov: this.lyapunov,
|
|
340
|
+
stability: this.stability,
|
|
341
|
+
coupling: this.oscillators.K,
|
|
342
|
+
orderParameter: this.oscillators.orderParameter(),
|
|
343
|
+
oscillators: this.oscillators.getState(),
|
|
344
|
+
collapseProbability: collapseProbability(this.collapseIntegral, this.lyapunov)
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Switch to a different backend at runtime
|
|
350
|
+
*/
|
|
351
|
+
setBackend(backend) {
|
|
352
|
+
this.backend = backend;
|
|
353
|
+
this._initializeOscillators();
|
|
354
|
+
this._resetState();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Get backend info
|
|
359
|
+
*/
|
|
360
|
+
getBackendInfo() {
|
|
361
|
+
return {
|
|
362
|
+
name: this.backend.getName(),
|
|
363
|
+
dimension: this.backend.dimension,
|
|
364
|
+
transformCount: this.backend.getTransforms().length,
|
|
365
|
+
primeCount: this.backend.getPrimes().length
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Perform measurement (for quantum/scientific backends)
|
|
371
|
+
*/
|
|
372
|
+
measure() {
|
|
373
|
+
return bornMeasurement(this.state);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Reset engine state without changing backend
|
|
378
|
+
*/
|
|
379
|
+
reset() {
|
|
380
|
+
this.oscillators.reset();
|
|
381
|
+
this._resetState();
|
|
382
|
+
this.history = [];
|
|
383
|
+
this.frames = [];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Get processing history
|
|
388
|
+
*/
|
|
389
|
+
getHistory(limit = 10) {
|
|
390
|
+
return this.history.slice(-limit);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Run multiple inputs in sequence
|
|
395
|
+
*/
|
|
396
|
+
runBatch(inputs) {
|
|
397
|
+
return inputs.map(input => this.run(input));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Continuously evolve state without new input
|
|
402
|
+
*/
|
|
403
|
+
evolve(steps = 10) {
|
|
404
|
+
const states = [];
|
|
405
|
+
for (let i = 0; i < steps; i++) {
|
|
406
|
+
this.tick(this.options.dt);
|
|
407
|
+
states.push({
|
|
408
|
+
step: i,
|
|
409
|
+
entropy: this.entropy,
|
|
410
|
+
orderParameter: this.oscillators.orderParameter(),
|
|
411
|
+
stability: this.stability
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
return states;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
module.exports = { AlephEngine };
|
package/engine/index.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aleph-ai/tinyaleph
|
|
3
|
+
*
|
|
4
|
+
* Prime-resonant semantic computing framework
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Hypercomplex algebra (quaternions, octonions, sedenions)
|
|
8
|
+
* - Prime-based semantic encoding
|
|
9
|
+
* - Kuramoto oscillator synchronization
|
|
10
|
+
* - Entropy-minimizing reasoning
|
|
11
|
+
* - Multiple backends (semantic, cryptographic, scientific)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const { createEngine } = require('@aleph-ai/tinyaleph');
|
|
15
|
+
*
|
|
16
|
+
* const engine = createEngine('semantic', config);
|
|
17
|
+
* const result = engine.run('What is wisdom?');
|
|
18
|
+
* console.log(result.output);
|
|
19
|
+
*
|
|
20
|
+
* @module @aleph-ai/tinyaleph
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
module.exports = require('./modular');
|