@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,364 @@
|
|
|
1
|
+
# Phase Synchronization
|
|
2
|
+
|
|
3
|
+
## The Kuramoto Model
|
|
4
|
+
|
|
5
|
+
The **Kuramoto model** is a mathematical model for describing synchronization in systems of coupled oscillators. It captures a profound phenomenon: when oscillators interact, they tend to align their phases—to "agree" on a common rhythm.
|
|
6
|
+
|
|
7
|
+
### The Governing Equation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
dθᵢ/dt = ωᵢ + (K/N) Σⱼ sin(θⱼ - θᵢ)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Where:
|
|
14
|
+
- θᵢ is the phase of oscillator i
|
|
15
|
+
- ωᵢ is its natural frequency
|
|
16
|
+
- K is the coupling strength
|
|
17
|
+
- N is the number of oscillators
|
|
18
|
+
- The sum is over all other oscillators
|
|
19
|
+
|
|
20
|
+
### Semantic Interpretation
|
|
21
|
+
|
|
22
|
+
| Kuramoto Concept | Semantic Meaning |
|
|
23
|
+
|-----------------|------------------|
|
|
24
|
+
| Oscillator | A concept with its prime frequency |
|
|
25
|
+
| Phase | Where the concept is in its "meaning cycle" |
|
|
26
|
+
| Frequency | The intrinsic nature of the concept |
|
|
27
|
+
| Coupling K | How strongly concepts influence each other |
|
|
28
|
+
| Synchronization | Conceptual agreement/understanding |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## The Oscillator Class
|
|
33
|
+
|
|
34
|
+
Individual oscillators start **quiescent** (amplitude = 0) and must be **excited** by input:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
class Oscillator {
|
|
38
|
+
constructor(frequency, phase = 0, amplitude = 0) {
|
|
39
|
+
this.freq = frequency;
|
|
40
|
+
this.phase = phase;
|
|
41
|
+
this.amplitude = amplitude; // Starts quiescent!
|
|
42
|
+
this.phaseHistory = [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
tick(dt, coupling = 0) {
|
|
46
|
+
this.phase = (this.phase + 2 * Math.PI * this.freq * dt + coupling) % (2 * Math.PI);
|
|
47
|
+
this.phaseHistory.push(this.phase);
|
|
48
|
+
if (this.phaseHistory.length > 100) this.phaseHistory.shift();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
excite(amount = 0.5) {
|
|
52
|
+
this.amplitude = Math.min(1, this.amplitude + amount);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
decay(rate = 0.02, dt = 1) {
|
|
56
|
+
this.amplitude *= (1 - rate * dt);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Key Properties
|
|
62
|
+
|
|
63
|
+
- **Frequency**: Determined by the corresponding prime
|
|
64
|
+
- **Phase**: Evolves according to frequency + coupling
|
|
65
|
+
- **Amplitude**: Represents activation level (0 = inactive, 1 = fully active)
|
|
66
|
+
- **Phase History**: Enables Lyapunov stability analysis
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## The Kuramoto Model Implementation
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
class KuramotoModel extends OscillatorBank {
|
|
74
|
+
constructor(frequencies, couplingStrength = 0.3) {
|
|
75
|
+
super(frequencies);
|
|
76
|
+
this.K = couplingStrength;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
kuramotoCoupling(osc) {
|
|
80
|
+
let coupling = 0;
|
|
81
|
+
for (const other of this.oscillators) {
|
|
82
|
+
if (other !== osc) {
|
|
83
|
+
coupling += Math.sin(other.phase - osc.phase);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return this.K * coupling / this.oscillators.length;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
tick(dt) {
|
|
90
|
+
// Each oscillator feels the pull of all others
|
|
91
|
+
super.tick(dt, (osc) => this.kuramotoCoupling(osc) * dt);
|
|
92
|
+
|
|
93
|
+
// Amplitudes decay over time
|
|
94
|
+
for (const osc of this.oscillators) {
|
|
95
|
+
osc.decay(0.02, dt);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### The Coupling Term
|
|
102
|
+
|
|
103
|
+
The coupling term `K × sin(θⱼ - θᵢ)` has beautiful properties:
|
|
104
|
+
- When θⱼ > θᵢ: positive, pulls oscillator i forward
|
|
105
|
+
- When θⱼ < θᵢ: negative, pulls oscillator i backward
|
|
106
|
+
- Net effect: phases move toward each other
|
|
107
|
+
- Strength proportional to K
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## The Order Parameter
|
|
112
|
+
|
|
113
|
+
The **order parameter** r measures how synchronized the oscillators are:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
orderParameter() {
|
|
117
|
+
let sx = 0, sy = 0;
|
|
118
|
+
for (const osc of this.oscillators) {
|
|
119
|
+
sx += osc.amplitude * Math.cos(osc.phase);
|
|
120
|
+
sy += osc.amplitude * Math.sin(osc.phase);
|
|
121
|
+
}
|
|
122
|
+
const N = this.oscillators.length;
|
|
123
|
+
return Math.sqrt((sx/N)**2 + (sy/N)**2);
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Interpretation
|
|
128
|
+
|
|
129
|
+
| Order Parameter | Meaning |
|
|
130
|
+
|-----------------|---------|
|
|
131
|
+
| r ≈ 0 | Desynchronized (incoherent, confused) |
|
|
132
|
+
| r ≈ 0.5 | Partially synchronized (emerging understanding) |
|
|
133
|
+
| r ≈ 1 | Fully synchronized (coherent understanding) |
|
|
134
|
+
|
|
135
|
+
The order parameter is Aleph's measure of **conceptual coherence**.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Mean Phase
|
|
140
|
+
|
|
141
|
+
The **mean phase** represents the "average direction" of the oscillator ensemble:
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
meanPhase() {
|
|
145
|
+
let sx = 0, sy = 0, ta = 0;
|
|
146
|
+
for (const osc of this.oscillators) {
|
|
147
|
+
sx += osc.amplitude * Math.cos(osc.phase);
|
|
148
|
+
sy += osc.amplitude * Math.sin(osc.phase);
|
|
149
|
+
ta += osc.amplitude;
|
|
150
|
+
}
|
|
151
|
+
return ta > 0 ? Math.atan2(sy/ta, sx/ta) : 0;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
When concepts synchronize, the mean phase indicates the dominant conceptual direction.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Excitation by Primes
|
|
160
|
+
|
|
161
|
+
When input arrives, we excite the oscillators corresponding to input primes:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
exciteByPrimes(primes, primeList, amount = 0.5) {
|
|
165
|
+
const primeSet = new Set(primes);
|
|
166
|
+
for (let i = 0; i < this.oscillators.length && i < primeList.length; i++) {
|
|
167
|
+
if (primeSet.has(primeList[i])) {
|
|
168
|
+
this.oscillators[i].excite(amount);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Excitation Flow
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
Input: "love and wisdom"
|
|
178
|
+
|
|
179
|
+
1. Tokenize → ["love", "wisdom"]
|
|
180
|
+
2. Encode → love = [2,3,5], wisdom = [2,7,11]
|
|
181
|
+
3. Primes → {2, 3, 5, 7, 11}
|
|
182
|
+
4. Excite oscillators for primes 2, 3, 5, 7, 11
|
|
183
|
+
5. Oscillators begin at different phases
|
|
184
|
+
6. Coupling causes synchronization
|
|
185
|
+
7. Order parameter rises as concepts unify
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Weighted Amplitudes
|
|
191
|
+
|
|
192
|
+
The engine uses amplitude-weighted phase values for state construction:
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
getWeightedAmplitudes() {
|
|
196
|
+
return this.oscillators.map(o => o.amplitude * Math.sin(o.phase));
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
This creates a state vector where:
|
|
201
|
+
- Excited oscillators contribute based on their current phase
|
|
202
|
+
- Quiescent oscillators contribute nothing
|
|
203
|
+
- The overall pattern reflects the dynamic state of the concept field
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Pairwise Coherence
|
|
208
|
+
|
|
209
|
+
Detailed coherence between oscillator pairs:
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
pairwiseCoherence() {
|
|
213
|
+
const N = this.oscillators.length;
|
|
214
|
+
let total = 0, count = 0;
|
|
215
|
+
for (let i = 0; i < N; i++) {
|
|
216
|
+
for (let j = i + 1; j < N; j++) {
|
|
217
|
+
total += Math.cos(this.oscillators[i].phase - this.oscillators[j].phase);
|
|
218
|
+
count++;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return count > 0 ? total / count : 0;
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
High pairwise coherence indicates that concepts are aligning, even before full synchronization.
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Critical Coupling
|
|
230
|
+
|
|
231
|
+
There's a critical coupling strength Kc below which synchronization cannot occur:
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
Kc ≈ 2 / (π × g(0))
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Where g(0) is the value of the frequency distribution at its center.
|
|
238
|
+
|
|
239
|
+
- **K < Kc**: Oscillators remain desynchronized
|
|
240
|
+
- **K > Kc**: Spontaneous synchronization emerges
|
|
241
|
+
- **K >> Kc**: Fast, complete synchronization
|
|
242
|
+
|
|
243
|
+
In Aleph, we use **adaptive coupling** that adjusts based on Lyapunov stability:
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
function adaptiveCoupling(baseCoupling, lyapunovExponent, gain = 0.5) {
|
|
247
|
+
if (lyapunovExponent < -0.1) return baseCoupling * (1 + gain); // Stable: increase
|
|
248
|
+
if (lyapunovExponent > 0.1) return baseCoupling * (1 - gain); // Chaotic: decrease
|
|
249
|
+
return baseCoupling; // Marginal: maintain
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## The Physics-Meaning Bridge
|
|
256
|
+
|
|
257
|
+
The oscillator dynamics create a bridge between physics and meaning:
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
PHYSICAL SEMANTIC
|
|
261
|
+
======== ========
|
|
262
|
+
|
|
263
|
+
Oscillator Resonating entity ←→ Active concept
|
|
264
|
+
|
|
265
|
+
Phase Position in cycle ←→ State of meaning
|
|
266
|
+
|
|
267
|
+
Frequency Natural rate ←→ Concept identity
|
|
268
|
+
|
|
269
|
+
Coupling Interaction force ←→ Semantic influence
|
|
270
|
+
|
|
271
|
+
Synchronization Phase alignment ←→ Understanding
|
|
272
|
+
|
|
273
|
+
Order parameter Coherence measure ←→ Clarity of thought
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Field-Based Computation
|
|
279
|
+
|
|
280
|
+
Aleph performs **field-based computation**—the answer emerges from oscillator dynamics:
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
// Main processing loop
|
|
284
|
+
run(input) {
|
|
285
|
+
// 1. Encode input to primes
|
|
286
|
+
const inputPrimes = this.backend.encode(input);
|
|
287
|
+
|
|
288
|
+
// 2. Excite corresponding oscillators
|
|
289
|
+
this.excite(inputPrimes);
|
|
290
|
+
|
|
291
|
+
// 3. Evolve the field
|
|
292
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
293
|
+
this.tick(dt);
|
|
294
|
+
|
|
295
|
+
// 4. Sample coherent frames
|
|
296
|
+
if (orderParameter > threshold) {
|
|
297
|
+
frames.push(currentState);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 5. Check for stable coherence
|
|
301
|
+
if (orderParameter > stableThreshold) {
|
|
302
|
+
break; // Coherent state reached
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 6. Decode from best frame
|
|
307
|
+
return this.decode(bestFrame);
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
The answer isn't calculated—it **crystallizes** from the dynamics.
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Transient vs. Steady State
|
|
316
|
+
|
|
317
|
+
Aleph captures the **transient response**, not just the steady state:
|
|
318
|
+
|
|
319
|
+
```javascript
|
|
320
|
+
// Track differential response
|
|
321
|
+
for (let i = 0; i < maxEvolutionSteps; i++) {
|
|
322
|
+
this.tick(dt);
|
|
323
|
+
|
|
324
|
+
// Compute input-weighted differential response
|
|
325
|
+
let inputResponse = 0, otherResponse = 0;
|
|
326
|
+
|
|
327
|
+
for (let j = 0; j < primeList.length; j++) {
|
|
328
|
+
const diff = |current[j]| - |baseline[j]|;
|
|
329
|
+
if (inputPrimes.has(primeList[j])) {
|
|
330
|
+
inputResponse += diff; // Input primes responding
|
|
331
|
+
} else {
|
|
332
|
+
otherResponse += |diff|; // Other primes responding
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const differential = inputResponse - otherResponse * 0.3;
|
|
337
|
+
|
|
338
|
+
// Sample frames with good differential (not just high order)
|
|
339
|
+
if (differential > 0) {
|
|
340
|
+
frames.push(currentFrame);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
This captures how the field **responds to input** rather than just its final state.
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## Summary
|
|
350
|
+
|
|
351
|
+
Phase synchronization provides:
|
|
352
|
+
|
|
353
|
+
1. **Dynamic representation** of concepts as oscillators
|
|
354
|
+
2. **Natural synchronization** through Kuramoto coupling
|
|
355
|
+
3. **Order parameter** as coherence measure
|
|
356
|
+
4. **Transient capture** of input-specific responses
|
|
357
|
+
5. **Adaptive coupling** for stability control
|
|
358
|
+
6. **Field-based computation** where answers emerge from dynamics
|
|
359
|
+
|
|
360
|
+
The oscillator model is the heartbeat of semantic computation.
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## Next: [Entropy and Reasoning →](./04-entropy-reasoning.md)
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# Entropy and Reasoning
|
|
2
|
+
|
|
3
|
+
## Information-Theoretic Foundations
|
|
4
|
+
|
|
5
|
+
Aleph treats reasoning as **entropy minimization**. This framing connects to fundamental physics: systems naturally evolve toward states of maximum entropy (thermodynamics), but intelligent systems can locally reduce entropy by organizing information.
|
|
6
|
+
|
|
7
|
+
### Shannon Entropy
|
|
8
|
+
|
|
9
|
+
The Shannon entropy of a probability distribution measures uncertainty:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
function shannonEntropy(probabilities) {
|
|
13
|
+
let H = 0;
|
|
14
|
+
for (const p of probabilities) {
|
|
15
|
+
if (p > 1e-10) H -= p * Math.log2(p);
|
|
16
|
+
}
|
|
17
|
+
return H;
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For a hypercomplex state, we compute entropy from the normalized component magnitudes:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
function stateEntropy(hypercomplex) {
|
|
25
|
+
const n = hypercomplex.norm();
|
|
26
|
+
if (n < 1e-10) return 0;
|
|
27
|
+
const probs = hypercomplex.c.map(v => (v / n) ** 2);
|
|
28
|
+
return shannonEntropy(probs);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Entropy as Confusion
|
|
35
|
+
|
|
36
|
+
| Entropy | Interpretation |
|
|
37
|
+
|---------|---------------|
|
|
38
|
+
| H ≈ 0 | State concentrated on one axis → pure concept |
|
|
39
|
+
| H ≈ 1 | State on two axes → binary distinction |
|
|
40
|
+
| H ≈ 2 | State on ~4 axes → moderate complexity |
|
|
41
|
+
| H ≈ 3 | State spread → confusion, unresolved meaning |
|
|
42
|
+
| H ≈ 4 | Maximum spread → maximum uncertainty |
|
|
43
|
+
|
|
44
|
+
### Example: Entropy Evolution
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
Input: "Is justice possible without mercy?"
|
|
48
|
+
|
|
49
|
+
Initial state:
|
|
50
|
+
H = 3.2 (high entropy)
|
|
51
|
+
Concepts: justice, possible, without, mercy
|
|
52
|
+
State spread across many dimensions
|
|
53
|
+
|
|
54
|
+
After transforms:
|
|
55
|
+
H = 1.4 (lower entropy)
|
|
56
|
+
Concepts: balance, wisdom
|
|
57
|
+
State concentrated on fewer dimensions
|
|
58
|
+
|
|
59
|
+
Interpretation:
|
|
60
|
+
The question resolved to a simpler understanding
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Reasoning as Entropy Minimization
|
|
66
|
+
|
|
67
|
+
The engine seeks transforms that reduce entropy:
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
reason(primes) {
|
|
71
|
+
const transforms = this.backend.getTransforms();
|
|
72
|
+
let current = [...new Set(primes)];
|
|
73
|
+
let state = this.backend.primesToState(current);
|
|
74
|
+
let H = stateEntropy(state);
|
|
75
|
+
const steps = [];
|
|
76
|
+
|
|
77
|
+
for (let i = 0; i < maxSteps && H > threshold; i++) {
|
|
78
|
+
let best = null, bestH = H, bestPrimes = current;
|
|
79
|
+
|
|
80
|
+
// Search for entropy-reducing transform
|
|
81
|
+
for (const transform of transforms) {
|
|
82
|
+
const newPrimes = this.backend.applyTransform(current, transform);
|
|
83
|
+
|
|
84
|
+
// Skip if no change
|
|
85
|
+
if (arraysEqual(newPrimes, current)) continue;
|
|
86
|
+
|
|
87
|
+
const newState = this.backend.primesToState(newPrimes);
|
|
88
|
+
const newH = stateEntropy(newState);
|
|
89
|
+
|
|
90
|
+
if (newH < bestH) {
|
|
91
|
+
best = transform;
|
|
92
|
+
bestH = newH;
|
|
93
|
+
bestPrimes = newPrimes;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!best) break; // No improvement possible
|
|
98
|
+
|
|
99
|
+
steps.push({
|
|
100
|
+
step: i + 1,
|
|
101
|
+
transform: best.name,
|
|
102
|
+
entropyDrop: H - bestH
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
current = bestPrimes;
|
|
106
|
+
H = bestH;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { primes: current, entropy: H, steps };
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### The Algorithm
|
|
114
|
+
|
|
115
|
+
1. Start with input prime set
|
|
116
|
+
2. Compute initial state and entropy
|
|
117
|
+
3. For each possible transform:
|
|
118
|
+
- Apply transform to get new primes
|
|
119
|
+
- Compute new state and entropy
|
|
120
|
+
- Track if this reduces entropy
|
|
121
|
+
4. Apply best transform
|
|
122
|
+
5. Repeat until entropy below threshold or no improvement
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Transforms as Semantic Rewrites
|
|
127
|
+
|
|
128
|
+
Transforms are semantic rewrite rules:
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
const transform = {
|
|
132
|
+
n: "question_to_answer",
|
|
133
|
+
q: [curiosity, unknown], // Query primes (must be present)
|
|
134
|
+
r: [understanding, known] // Result primes (replace query)
|
|
135
|
+
};
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Transform Application
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
applyTransform(inputPrimes, transform) {
|
|
142
|
+
const inputSet = new Set(inputPrimes);
|
|
143
|
+
|
|
144
|
+
// Check if query primes are present
|
|
145
|
+
if (!transform.q.some(p => inputSet.has(p))) {
|
|
146
|
+
return inputPrimes; // No match
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Protect core primes
|
|
150
|
+
if (transform.q.some(p => this.corePrimes.has(p))) {
|
|
151
|
+
return inputPrimes;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Apply: remove query primes, add result primes
|
|
155
|
+
const kept = inputPrimes.filter(p =>
|
|
156
|
+
this.corePrimes.has(p) || !transform.q.includes(p)
|
|
157
|
+
);
|
|
158
|
+
return [...new Set([...kept, ...transform.r])];
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Transform Types
|
|
163
|
+
|
|
164
|
+
| Type | Example | Effect |
|
|
165
|
+
|------|---------|--------|
|
|
166
|
+
| **Simplification** | complex → simple | Reduces prime count |
|
|
167
|
+
| **Unification** | A ∪ B → C | Merges concepts |
|
|
168
|
+
| **Abstraction** | instances → type | Moves up hierarchy |
|
|
169
|
+
| **Resolution** | question → answer | Resolves inquiry |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Coherence Between States
|
|
174
|
+
|
|
175
|
+
Coherence measures alignment between states:
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
function coherence(state1, state2) {
|
|
179
|
+
const n1 = state1.norm();
|
|
180
|
+
const n2 = state2.norm();
|
|
181
|
+
if (n1 < 1e-10 || n2 < 1e-10) return 0;
|
|
182
|
+
return Math.abs(state1.dot(state2)) / (n1 * n2);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Interpretation
|
|
187
|
+
|
|
188
|
+
- **Coherence = 1**: States identical (same meaning)
|
|
189
|
+
- **Coherence = 0**: States orthogonal (unrelated)
|
|
190
|
+
- **Coherence = 0.7+**: High alignment (related meanings)
|
|
191
|
+
|
|
192
|
+
High coherence with low entropy indicates clear, unified understanding.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Mutual Information
|
|
197
|
+
|
|
198
|
+
For coupled oscillator banks, mutual information measures shared structure:
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
function mutualInformation(bank1, bank2) {
|
|
202
|
+
let corr = 0;
|
|
203
|
+
const n = Math.min(bank1.oscillators.length, bank2.oscillators.length);
|
|
204
|
+
for (let i = 0; i < n; i++) {
|
|
205
|
+
corr += Math.cos(bank1.oscillators[i].phase - bank2.oscillators[i].phase);
|
|
206
|
+
}
|
|
207
|
+
return Math.max(0, corr / n);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
High mutual information indicates that two concept fields are resonating together.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Relative Entropy (KL Divergence)
|
|
216
|
+
|
|
217
|
+
KL divergence measures how one distribution differs from another:
|
|
218
|
+
|
|
219
|
+
```javascript
|
|
220
|
+
function relativeEntropy(p, q) {
|
|
221
|
+
let kl = 0;
|
|
222
|
+
for (let i = 0; i < p.length; i++) {
|
|
223
|
+
if (p[i] > 1e-10 && q[i] > 1e-10) {
|
|
224
|
+
kl += p[i] * Math.log2(p[i] / q[i]);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return kl;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
This quantifies how "surprising" distribution p is relative to expectation q.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Joint Entropy
|
|
236
|
+
|
|
237
|
+
For two states together:
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
function jointEntropy(state1, state2) {
|
|
241
|
+
const n1 = state1.norm(), n2 = state2.norm();
|
|
242
|
+
if (n1 < 1e-10 || n2 < 1e-10) return 0;
|
|
243
|
+
|
|
244
|
+
// Create joint probability distribution
|
|
245
|
+
const probs = [];
|
|
246
|
+
for (let i = 0; i < state1.dim; i++) {
|
|
247
|
+
for (let j = 0; j < state2.dim; j++) {
|
|
248
|
+
const p1 = (state1.c[i] / n1) ** 2;
|
|
249
|
+
const p2 = (state2.c[j] / n2) ** 2;
|
|
250
|
+
probs.push(p1 * p2);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return shannonEntropy(probs);
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Joint entropy captures the total information in the combined system.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Oscillator Entropy
|
|
262
|
+
|
|
263
|
+
Entropy from the oscillator bank's amplitude distribution:
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
function oscillatorEntropy(bank) {
|
|
267
|
+
const amplitudes = bank.getAmplitudes();
|
|
268
|
+
const total = amplitudes.reduce((a, b) => a + b, 0);
|
|
269
|
+
if (total < 1e-10) return 0;
|
|
270
|
+
const probs = amplitudes.map(a => a / total);
|
|
271
|
+
return shannonEntropy(probs);
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
This measures how evenly "excited" the oscillator bank is.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## The Collapse Integral
|
|
280
|
+
|
|
281
|
+
Entropy accumulates over time, driving toward collapse:
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
// In engine tick
|
|
285
|
+
this.collapseIntegral += this.entropy * dt * 0.1;
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
When the collapse integral exceeds a threshold and other conditions are met, the state "collapses" to a definite value—modeling the "aha!" moment of insight.
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Reasoning Example
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
Query: "What is the relationship between freedom and responsibility?"
|
|
296
|
+
|
|
297
|
+
Step 0: Encode
|
|
298
|
+
primes = [freedom, responsibility] = [23, 47, 19, 53]
|
|
299
|
+
entropy = 3.4
|
|
300
|
+
|
|
301
|
+
Step 1: Transform (abstraction)
|
|
302
|
+
"freedom" → "self-determination"
|
|
303
|
+
primes = [self, determination, responsibility]
|
|
304
|
+
entropy = 2.9 (↓0.5)
|
|
305
|
+
|
|
306
|
+
Step 2: Transform (unification)
|
|
307
|
+
"self-determination" + "responsibility" → "agency"
|
|
308
|
+
primes = [agency]
|
|
309
|
+
entropy = 1.2 (↓1.7)
|
|
310
|
+
|
|
311
|
+
Result:
|
|
312
|
+
The concepts unified into "agency"
|
|
313
|
+
Entropy dropped from 3.4 to 1.2
|
|
314
|
+
Understanding crystallized
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## The Insight
|
|
320
|
+
|
|
321
|
+
Entropy minimization as reasoning has profound implications:
|
|
322
|
+
|
|
323
|
+
1. **Reasoning is physical**: It follows thermodynamic principles
|
|
324
|
+
2. **Understanding is compression**: Fewer primes = clearer meaning
|
|
325
|
+
3. **Confusion is entropy**: High H = unresolved complexity
|
|
326
|
+
4. **Insight is collapse**: Sudden entropy drop = "aha!"
|
|
327
|
+
5. **Wisdom is simplicity**: Low H stable states are wise
|
|
328
|
+
|
|
329
|
+
This connects the cognitive experience of understanding to rigorous information theory.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Summary
|
|
334
|
+
|
|
335
|
+
Entropy and reasoning in Aleph:
|
|
336
|
+
|
|
337
|
+
1. **Shannon entropy** measures conceptual confusion
|
|
338
|
+
2. **Transforms** are semantic rewrite rules
|
|
339
|
+
3. **Reasoning** minimizes entropy through transforms
|
|
340
|
+
4. **Coherence** measures alignment between states
|
|
341
|
+
5. **Collapse integral** accumulates toward insight moments
|
|
342
|
+
6. **Understanding** = low entropy, high coherence
|
|
343
|
+
|
|
344
|
+
Reasoning is the process of organizing meaning toward clarity.
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## Next: [Non-Commutativity →](./05-non-commutativity.md)
|