@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,421 @@
|
|
|
1
|
+
# Hypercomplex Algebra
|
|
2
|
+
|
|
3
|
+
## The Cayley-Dickson Construction
|
|
4
|
+
|
|
5
|
+
Hypercomplex numbers are generalizations of complex numbers to higher dimensions. The **Cayley-Dickson construction** is a recursive method for building these algebras:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Real numbers (1D) → Complex numbers (2D) → Quaternions (4D) → Octonions (8D) → Sedenions (16D) → ...
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Each doubling introduces new properties (and loses old ones):
|
|
12
|
+
|
|
13
|
+
| Algebra | Dimension | Properties Lost |
|
|
14
|
+
|---------|-----------|-----------------|
|
|
15
|
+
| Reals | 1 | - |
|
|
16
|
+
| Complex | 2 | Ordering |
|
|
17
|
+
| Quaternions | 4 | Commutativity |
|
|
18
|
+
| Octonions | 8 | Associativity |
|
|
19
|
+
| Sedenions | 16 | Alternativity |
|
|
20
|
+
|
|
21
|
+
Aleph uses 16-dimensional sedenions because they provide:
|
|
22
|
+
- Sufficient dimensionality for rich semantic states
|
|
23
|
+
- Non-commutativity for word order encoding
|
|
24
|
+
- Zero-divisors for paradox resolution
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## The Hypercomplex Class
|
|
29
|
+
|
|
30
|
+
The core `Hypercomplex` class implements generic Cayley-Dickson algebras:
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
class Hypercomplex {
|
|
34
|
+
constructor(dim, components = null) {
|
|
35
|
+
if (!Number.isInteger(Math.log2(dim))) {
|
|
36
|
+
throw new Error('Dimension must be power of 2');
|
|
37
|
+
}
|
|
38
|
+
this.dim = dim;
|
|
39
|
+
this.c = components instanceof Float64Array
|
|
40
|
+
? components
|
|
41
|
+
: new Float64Array(dim);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Factory Methods
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
// Zero element
|
|
50
|
+
Hypercomplex.zero(16);
|
|
51
|
+
// → [0, 0, 0, ..., 0]
|
|
52
|
+
|
|
53
|
+
// Basis element
|
|
54
|
+
Hypercomplex.basis(16, 3, 1.0);
|
|
55
|
+
// → [0, 0, 0, 1, 0, ..., 0] (1 at index 3)
|
|
56
|
+
|
|
57
|
+
// Real number embedding
|
|
58
|
+
Hypercomplex.fromReal(16, 5.0);
|
|
59
|
+
// → [5, 0, 0, ..., 0]
|
|
60
|
+
|
|
61
|
+
// From array
|
|
62
|
+
Hypercomplex.fromArray([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Arithmetic Operations
|
|
68
|
+
|
|
69
|
+
### Addition and Subtraction
|
|
70
|
+
|
|
71
|
+
Component-wise, as in standard vector spaces:
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
add(other) {
|
|
75
|
+
const r = new Hypercomplex(this.dim);
|
|
76
|
+
for (let i = 0; i < this.dim; i++) {
|
|
77
|
+
r.c[i] = this.c[i] + other.c[i];
|
|
78
|
+
}
|
|
79
|
+
return r;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Scalar Multiplication
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
scale(k) {
|
|
87
|
+
const r = new Hypercomplex(this.dim);
|
|
88
|
+
for (let i = 0; i < this.dim; i++) {
|
|
89
|
+
r.c[i] = this.c[i] * k;
|
|
90
|
+
}
|
|
91
|
+
return r;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Hypercomplex Multiplication
|
|
96
|
+
|
|
97
|
+
This is where the magic happens. Hypercomplex multiplication is **non-commutative**:
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
mul(other) {
|
|
101
|
+
const r = new Hypercomplex(this.dim);
|
|
102
|
+
for (let i = 0; i < this.dim; i++) {
|
|
103
|
+
for (let j = 0; j < this.dim; j++) {
|
|
104
|
+
const [k, s] = multiplyIndices(this.dim, i, j);
|
|
105
|
+
r.c[k] += s * this.c[i] * other.c[j];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return r;
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The `multiplyIndices` function returns the target index `k` and sign `s` for the product of basis elements `eᵢ × eⱼ`.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## The Fano Plane
|
|
117
|
+
|
|
118
|
+
For octonions (8D), multiplication is defined by the **Fano plane**—a finite projective geometry with 7 points and 7 lines:
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
1
|
|
122
|
+
/|\
|
|
123
|
+
/ | \
|
|
124
|
+
2 | 4
|
|
125
|
+
/ \ | / \
|
|
126
|
+
/ \|/ \
|
|
127
|
+
3-----7-----5
|
|
128
|
+
\ /|\ /
|
|
129
|
+
\ / | \ /
|
|
130
|
+
6 | ?
|
|
131
|
+
\|/
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The seven lines of the Fano plane:
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
const FANO_LINES = [
|
|
138
|
+
[1, 2, 3],
|
|
139
|
+
[1, 4, 5],
|
|
140
|
+
[1, 6, 7],
|
|
141
|
+
[2, 4, 6],
|
|
142
|
+
[2, 5, 7],
|
|
143
|
+
[3, 4, 7],
|
|
144
|
+
[3, 5, 6]
|
|
145
|
+
];
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Octonion Multiplication
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
function octonionMultiplyIndex(i, j) {
|
|
152
|
+
if (i === 0) return [j, 1]; // e₀ is identity
|
|
153
|
+
if (j === 0) return [i, 1];
|
|
154
|
+
if (i === j) return [0, -1]; // eᵢ² = -1
|
|
155
|
+
|
|
156
|
+
// Find line containing both i and j
|
|
157
|
+
for (const line of FANO_LINES) {
|
|
158
|
+
const xi = line.indexOf(i);
|
|
159
|
+
if (xi >= 0 && line.includes(j)) {
|
|
160
|
+
const xj = line.indexOf(j);
|
|
161
|
+
const k = line[3 - xi - xj]; // Third element
|
|
162
|
+
const sign = (xj - xi + 3) % 3 === 1 ? 1 : -1;
|
|
163
|
+
return [k, sign];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return [i ^ j, 1]; // XOR fallback
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Sedenion Extension
|
|
171
|
+
|
|
172
|
+
Sedenions are built from octonions via Cayley-Dickson doubling:
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
function sedenionMultiplyIndex(i, j) {
|
|
176
|
+
if (i === 0) return [j, 1];
|
|
177
|
+
if (j === 0) return [i, 1];
|
|
178
|
+
if (i === j) return [0, -1];
|
|
179
|
+
|
|
180
|
+
const hi = i >= 8, hj = j >= 8; // Which half?
|
|
181
|
+
const li = i & 7, lj = j & 7; // Index within half
|
|
182
|
+
|
|
183
|
+
if (!hi && !hj) return octonionMultiplyIndex(li, lj);
|
|
184
|
+
if (hi && hj) {
|
|
185
|
+
const [k, s] = octonionMultiplyIndex(li, lj);
|
|
186
|
+
return [k, -s]; // Sign flip for high-high
|
|
187
|
+
}
|
|
188
|
+
if (!hi) {
|
|
189
|
+
const [k, s] = octonionMultiplyIndex(lj, li);
|
|
190
|
+
return [k + 8, s];
|
|
191
|
+
}
|
|
192
|
+
const [k, s] = octonionMultiplyIndex(li, lj);
|
|
193
|
+
return [k + 8, -s];
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Conjugation and Inverse
|
|
200
|
+
|
|
201
|
+
### Conjugate
|
|
202
|
+
|
|
203
|
+
The conjugate flips all imaginary components:
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
conjugate() {
|
|
207
|
+
const r = new Hypercomplex(this.dim);
|
|
208
|
+
r.c[0] = this.c[0]; // Real part unchanged
|
|
209
|
+
for (let i = 1; i < this.dim; i++) {
|
|
210
|
+
r.c[i] = -this.c[i]; // Imaginary parts negated
|
|
211
|
+
}
|
|
212
|
+
return r;
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Norm
|
|
217
|
+
|
|
218
|
+
The norm is the square root of the inner product:
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
norm() {
|
|
222
|
+
return Math.sqrt(this.dot(this));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
dot(other) {
|
|
226
|
+
let s = 0;
|
|
227
|
+
for (let i = 0; i < this.dim; i++) {
|
|
228
|
+
s += this.c[i] * other.c[i];
|
|
229
|
+
}
|
|
230
|
+
return s;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Inverse
|
|
235
|
+
|
|
236
|
+
The inverse uses conjugate and norm:
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
inverse() {
|
|
240
|
+
const n2 = this.dot(this);
|
|
241
|
+
if (n2 < 1e-10) return Hypercomplex.zero(this.dim);
|
|
242
|
+
return this.conjugate().scale(1 / n2);
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Warning**: In sedenions, zero-divisors exist—elements with non-zero norm whose product is zero. These elements don't have traditional inverses.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Zero-Divisors: Paradox Tunnels
|
|
251
|
+
|
|
252
|
+
A remarkable property of sedenions is the existence of **zero-divisors**:
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
isZeroDivisorWith(other) {
|
|
256
|
+
const prod = this.mul(other);
|
|
257
|
+
return this.norm() > 0.1 &&
|
|
258
|
+
other.norm() > 0.1 &&
|
|
259
|
+
prod.norm() < 0.01;
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Semantic Interpretation
|
|
264
|
+
|
|
265
|
+
Zero-divisors represent **paradoxes** or **tunnels** between concepts:
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
light × darkness = 0 (paradox)
|
|
269
|
+
→ Tunnel exists to concept "contrast"
|
|
270
|
+
|
|
271
|
+
self × other = 0 (boundary paradox)
|
|
272
|
+
→ Tunnel exists to concept "relationship"
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
When two concepts multiply to zero, they annihilate—but this annihilation reveals a deeper concept.
|
|
276
|
+
|
|
277
|
+
### Finding Zero-Divisor Pairs
|
|
278
|
+
|
|
279
|
+
```javascript
|
|
280
|
+
function findZeroDivisorPair(state) {
|
|
281
|
+
// Search for states that annihilate with the given state
|
|
282
|
+
for (let i = 0; i < dim; i++) {
|
|
283
|
+
const candidate = Hypercomplex.basis(dim, i);
|
|
284
|
+
if (state.isZeroDivisorWith(candidate)) {
|
|
285
|
+
return candidate;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Entropy and Coherence
|
|
295
|
+
|
|
296
|
+
### State Entropy
|
|
297
|
+
|
|
298
|
+
Shannon entropy measures how "spread out" a state is:
|
|
299
|
+
|
|
300
|
+
```javascript
|
|
301
|
+
entropy() {
|
|
302
|
+
const n = this.norm();
|
|
303
|
+
if (n < 1e-10) return 0;
|
|
304
|
+
let h = 0;
|
|
305
|
+
for (let i = 0; i < this.dim; i++) {
|
|
306
|
+
const p = (this.c[i] / n) ** 2;
|
|
307
|
+
if (p > 1e-10) h -= p * Math.log2(p);
|
|
308
|
+
}
|
|
309
|
+
return h;
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
- **Low entropy** (0-1): State concentrated on few dimensions → clear meaning
|
|
314
|
+
- **High entropy** (3-4): State spread across many dimensions → confused meaning
|
|
315
|
+
|
|
316
|
+
### Coherence
|
|
317
|
+
|
|
318
|
+
Coherence measures alignment between two states:
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
coherence(other) {
|
|
322
|
+
const n1 = this.norm(), n2 = other.norm();
|
|
323
|
+
if (n1 < 1e-10 || n2 < 1e-10) return 0;
|
|
324
|
+
return Math.abs(this.dot(other)) / (n1 * n2);
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
- **Coherence = 1**: States perfectly aligned (same meaning)
|
|
329
|
+
- **Coherence = 0**: States orthogonal (unrelated meanings)
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Dominant Axes
|
|
334
|
+
|
|
335
|
+
Finding which dimensions carry the most weight:
|
|
336
|
+
|
|
337
|
+
```javascript
|
|
338
|
+
dominantAxes(n = 3) {
|
|
339
|
+
return [...this.c]
|
|
340
|
+
.map((v, i) => ({ i, v: Math.abs(v) }))
|
|
341
|
+
.sort((a, b) => b.v - a.v)
|
|
342
|
+
.slice(0, n);
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
This reveals which semantic axes (corresponding to primes) are most active in a state.
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## Primes to Hypercomplex State
|
|
351
|
+
|
|
352
|
+
Converting prime signatures to hypercomplex states:
|
|
353
|
+
|
|
354
|
+
```javascript
|
|
355
|
+
primesToState(primes) {
|
|
356
|
+
const state = Hypercomplex.zero(this.dimension);
|
|
357
|
+
for (const p of primes) {
|
|
358
|
+
const angle = primeToAngle(p);
|
|
359
|
+
for (let i = 0; i < this.dimension; i++) {
|
|
360
|
+
state.c[i] += Math.cos(angle * (i + 1)) / Math.sqrt(primes.length);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return state.normalize();
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Each prime contributes a rotation to the state vector. The resulting vector exists in 16-dimensional hypercomplex space.
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
## Non-Commutative Encoding
|
|
372
|
+
|
|
373
|
+
The key insight: hypercomplex multiplication is non-commutative, so we can encode word order:
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
orderedPrimesToState(orderedTokens) {
|
|
377
|
+
let state = Hypercomplex.basis(this.dimension, 0, 1); // Identity
|
|
378
|
+
|
|
379
|
+
for (let i = 0; i < orderedTokens.length; i++) {
|
|
380
|
+
const token = orderedTokens[i];
|
|
381
|
+
const primes = token.primes;
|
|
382
|
+
|
|
383
|
+
// Convert primes to hypercomplex rotation
|
|
384
|
+
const tokenH = this.primesToHypercomplex(primes);
|
|
385
|
+
|
|
386
|
+
// Apply position-dependent phase
|
|
387
|
+
const positioned = this.applyPositionPhase(tokenH, i);
|
|
388
|
+
|
|
389
|
+
// Sequential MULTIPLICATION (non-commutative!)
|
|
390
|
+
state = state.mul(positioned);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return state.normalize();
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
Now:
|
|
398
|
+
```javascript
|
|
399
|
+
encode("dog bites man") // → state₁
|
|
400
|
+
encode("man bites dog") // → state₂
|
|
401
|
+
state₁ ≠ state₂ // Different! Order preserved!
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## Summary
|
|
407
|
+
|
|
408
|
+
Hypercomplex algebra provides:
|
|
409
|
+
|
|
410
|
+
1. **16-dimensional state space** for rich semantic representations
|
|
411
|
+
2. **Non-commutative multiplication** for encoding word order
|
|
412
|
+
3. **Zero-divisors** for representing and resolving paradoxes
|
|
413
|
+
4. **Entropy** for measuring conceptual clarity
|
|
414
|
+
5. **Coherence** for measuring semantic alignment
|
|
415
|
+
6. **Fano plane structure** for principled multiplication
|
|
416
|
+
|
|
417
|
+
The algebra is the mathematical substrate on which meaning exists.
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
## Next: [Phase Synchronization →](./03-phase-synchronization.md)
|