@aleph-ai/tinyaleph 1.2.0 → 1.3.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 +187 -2
- package/backends/bioinformatics/binding.js +503 -0
- package/backends/bioinformatics/dna-computing.js +664 -0
- package/backends/bioinformatics/encoding.js +339 -0
- package/backends/bioinformatics/folding.js +454 -0
- package/backends/bioinformatics/genetic-code.js +269 -0
- package/backends/bioinformatics/index.js +522 -0
- package/backends/bioinformatics/transcription.js +221 -0
- package/backends/bioinformatics/translation.js +264 -0
- package/backends/index.js +25 -1
- package/core/compound.js +532 -0
- package/core/hilbert.js +454 -1
- package/core/index.js +106 -12
- package/core/inference.js +605 -0
- package/core/resonance.js +245 -616
- package/core/symbols/archetypes.js +478 -0
- package/core/symbols/base.js +302 -0
- package/core/symbols/elements.js +487 -0
- package/core/symbols/hieroglyphs.js +303 -0
- package/core/symbols/iching.js +471 -0
- package/core/symbols/index.js +77 -0
- package/core/symbols/tarot.js +211 -0
- package/core/symbols.js +22 -0
- package/docs/design/BIOINFORMATICS_BACKEND_DESIGN.md +493 -0
- package/docs/guide/06-symbolic-ai.md +370 -0
- package/docs/guide/README.md +2 -1
- package/docs/reference/05-symbolic-ai.md +570 -0
- package/docs/reference/06-bioinformatics.md +546 -0
- package/docs/reference/README.md +32 -2
- package/docs/theory/11-prgraph-memory.md +559 -0
- package/docs/theory/12-resonant-attention.md +661 -0
- package/modular.js +33 -1
- package/package.json +1 -1
- package/physics/index.js +16 -0
- package/physics/kuramoto-coupled-ladder.js +603 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
# Symbolic AI and Resonance Attention
|
|
2
|
+
|
|
3
|
+
This guide covers the symbolic AI components ported from symprime and enhanced with tinyaleph's ResoFormer resonance attention mechanism.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The symbolic AI system provides:
|
|
8
|
+
|
|
9
|
+
1. **Symbol Database** - 184+ emoji symbols with prime assignments and cultural tags
|
|
10
|
+
2. **Semantic Inference** - Pattern matching and resonance-enhanced text→symbol mapping
|
|
11
|
+
3. **Compound Builder** - Multi-symbol concepts through prime multiplication
|
|
12
|
+
4. **Resonance Calculator** - Golden ratio-based harmony measurement
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
const {
|
|
18
|
+
inferWithResonance,
|
|
19
|
+
inferMostResonant,
|
|
20
|
+
getSymbol,
|
|
21
|
+
createCompound,
|
|
22
|
+
symbolDatabase,
|
|
23
|
+
resonanceSignature
|
|
24
|
+
} = require('./core');
|
|
25
|
+
|
|
26
|
+
// Infer symbols from text with resonance ranking
|
|
27
|
+
const symbols = inferWithResonance('The hero fought the shadow in the temple');
|
|
28
|
+
console.log(symbols.map(s => s.symbol.unicode).join(' '));
|
|
29
|
+
// → 👩 🌑 ⛩️ 🦸
|
|
30
|
+
|
|
31
|
+
// Find symbol that harmonizes best with context
|
|
32
|
+
const context = [getSymbol('warrior'), getSymbol('temple')];
|
|
33
|
+
const best = inferMostResonant('sword', context);
|
|
34
|
+
console.log(`${best.symbol.unicode} resonance: ${best.contextResonance}`);
|
|
35
|
+
// → 🗡️ resonance: 0.2993
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Symbol Database
|
|
39
|
+
|
|
40
|
+
### Categories
|
|
41
|
+
|
|
42
|
+
| Category | Count | Examples |
|
|
43
|
+
|----------|-------|----------|
|
|
44
|
+
| PEOPLE_ARCHETYPES | 50 | 🦸 hero, ⚔️ warrior, 🧙 sage |
|
|
45
|
+
| PLACES_LOCATIONS | 31 | ⛰️ mountain, ⛩️ temple, 🌊 ocean |
|
|
46
|
+
| OBJECTS_TOOLS | 36 | 🗡️ sword, 🔑 key, 📜 scroll |
|
|
47
|
+
| ABSTRACT_CONCEPTS | 37 | ❤️ love, 🦁 courage, ☮️ peace |
|
|
48
|
+
| NATURAL_ELEMENTS | 30 | 🔥 fire, 💧 water, ⚡ thunder |
|
|
49
|
+
|
|
50
|
+
### Cultural Tags
|
|
51
|
+
|
|
52
|
+
Each symbol is tagged with cultural context:
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
const athena = getSymbol('athena');
|
|
56
|
+
console.log(athena);
|
|
57
|
+
// {
|
|
58
|
+
// id: 'athena',
|
|
59
|
+
// unicode: '🦉',
|
|
60
|
+
// prime: 89,
|
|
61
|
+
// meaning: 'Athena - Goddess of wisdom',
|
|
62
|
+
// culturalTags: ['greek', 'mythology', 'wisdom']
|
|
63
|
+
// }
|
|
64
|
+
|
|
65
|
+
// Find all Greek symbols
|
|
66
|
+
const greekSymbols = symbolDatabase.getSymbolsByTag('greek');
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Prime Encoding
|
|
70
|
+
|
|
71
|
+
Every symbol has a unique prime number. Concepts combine through multiplication:
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
// Encode concepts to prime signature
|
|
75
|
+
const signature = symbolDatabase.encode(['hero', 'journey', 'mountain']);
|
|
76
|
+
// → 8035067n (product of primes)
|
|
77
|
+
|
|
78
|
+
// Decode back to symbols
|
|
79
|
+
const symbols = symbolDatabase.decode(signature);
|
|
80
|
+
// → [hero, journey, mountain]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Semantic Inference
|
|
84
|
+
|
|
85
|
+
### Basic Inference
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
const { inferSymbol, inferSymbols } = require('./core');
|
|
89
|
+
|
|
90
|
+
// Direct match
|
|
91
|
+
inferSymbol('warrior');
|
|
92
|
+
// → { symbol: ⚔️, method: 'direct', confidence: 1.0 }
|
|
93
|
+
|
|
94
|
+
// Pattern match
|
|
95
|
+
inferSymbol('mighty knight');
|
|
96
|
+
// → { symbol: ⚔️, method: 'regex', confidence: 0.85 }
|
|
97
|
+
|
|
98
|
+
// Semantic match
|
|
99
|
+
inferSymbol('brave protagonist');
|
|
100
|
+
// → { symbol: 🦸, method: 'semantic', confidence: 0.7 }
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Resonance-Enhanced Inference
|
|
104
|
+
|
|
105
|
+
The key innovation: using ResoFormer attention to rank symbols by how well they "harmonize" together.
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
const { inferWithResonance } = require('./core');
|
|
109
|
+
|
|
110
|
+
const text = 'The hero fought the shadow in the temple of fire';
|
|
111
|
+
const results = inferWithResonance(text);
|
|
112
|
+
|
|
113
|
+
for (const r of results) {
|
|
114
|
+
console.log(`${r.symbol.unicode} ${r.symbol.id}`);
|
|
115
|
+
console.log(` confidence: ${r.confidence}`);
|
|
116
|
+
console.log(` resonance bonus: ${r.resonanceBonus}`);
|
|
117
|
+
console.log(` attention weight: ${r.attentionWeight}`);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### How Resonance Selection Works
|
|
122
|
+
|
|
123
|
+
1. **Prime State Conversion**: Each symbol becomes a `SparsePrimeState`
|
|
124
|
+
2. **Cultural Activation**: Related symbols (via tags) get partial activation
|
|
125
|
+
3. **Resonance Scoring**: `Res(i,j) = α·Jaccard + β·QuaternionAlign + γ·PhaseCoherence`
|
|
126
|
+
4. **Attention Weighting**: Softmax over resonance scores
|
|
127
|
+
5. **Ranking**: Symbols sorted by attention weight
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
// Under the hood:
|
|
131
|
+
const state = symbolToState(symbol); // Convert to SparsePrimeState
|
|
132
|
+
const score = resonanceScore(state1, state2); // Calculate harmony
|
|
133
|
+
const { weights } = resonantAttention(query, keys, values); // Apply attention
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Context-Aware Selection
|
|
137
|
+
|
|
138
|
+
Find symbols that resonate with existing context:
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
const { inferMostResonant, getSymbol } = require('./core');
|
|
142
|
+
|
|
143
|
+
// Build context
|
|
144
|
+
const context = [
|
|
145
|
+
getSymbol('warrior'),
|
|
146
|
+
getSymbol('temple'),
|
|
147
|
+
getSymbol('fire')
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
// Find most harmonious addition
|
|
151
|
+
const best = inferMostResonant('weapon', context);
|
|
152
|
+
// → 🗡️ sword (high resonance with warrior/temple/fire)
|
|
153
|
+
|
|
154
|
+
// Compare with other options
|
|
155
|
+
const shield = inferMostResonant('shield', context);
|
|
156
|
+
const bow = inferMostResonant('bow', context);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Compound Symbols
|
|
160
|
+
|
|
161
|
+
### Pre-built Compounds
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
const { getCompound, compoundBuilder } = require('./core');
|
|
165
|
+
|
|
166
|
+
const greekWarrior = getCompound('greek_warrior');
|
|
167
|
+
console.log(`${greekWarrior.unicode} - ${greekWarrior.meaning}`);
|
|
168
|
+
// → ⚔️⛩️🦉 - Greek Warrior: Temple guardian blessed by Athena
|
|
169
|
+
|
|
170
|
+
// Available compounds:
|
|
171
|
+
// greek_warrior, viking_warrior, samurai_warrior
|
|
172
|
+
// philosopher_king, shadow_self
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Creating Compounds
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
const { createCompound, compoundBuilder } = require('./core');
|
|
179
|
+
|
|
180
|
+
// Create a new compound
|
|
181
|
+
const fireMage = createCompound('fire_mage',
|
|
182
|
+
['magician', 'fire', 'staff'],
|
|
183
|
+
'Fire Mage - Wielder of flame magic',
|
|
184
|
+
['fantasy', 'magic', 'elemental']
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// Calculate internal resonance
|
|
188
|
+
const resonance = compoundBuilder.calculateCompoundResonance(fireMage);
|
|
189
|
+
console.log(`Internal harmony: ${resonance.toFixed(4)}`);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Cultural Variants
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
const { compoundBuilder } = require('./core');
|
|
196
|
+
|
|
197
|
+
// Create Norse variant of Greek warrior
|
|
198
|
+
const norseWarrior = compoundBuilder.createCulturalVariant(
|
|
199
|
+
'greek_warrior',
|
|
200
|
+
'norse',
|
|
201
|
+
['ocean'], // Additional Norse symbols
|
|
202
|
+
'Norse-influenced warrior of the seas'
|
|
203
|
+
);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Symbol Sequences
|
|
207
|
+
|
|
208
|
+
For narratives and temporal ordering:
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
const { createSequence, getSequence } = require('./core');
|
|
212
|
+
|
|
213
|
+
// Pre-built: hero's journey
|
|
214
|
+
const journey = getSequence('heros_journey');
|
|
215
|
+
// → 🦸 → 🛤️ → 🌀 → 💥 → 🦋
|
|
216
|
+
|
|
217
|
+
// Create custom sequence
|
|
218
|
+
const loveStory = createSequence('love_story',
|
|
219
|
+
['lover', 'love', 'conflict', 'unity'],
|
|
220
|
+
'narrative',
|
|
221
|
+
'Classic love story arc'
|
|
222
|
+
);
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Golden Ratio Resonance
|
|
226
|
+
|
|
227
|
+
### Theory
|
|
228
|
+
|
|
229
|
+
Primes whose ratio approaches φ ≈ 1.618 have "natural harmony":
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
R(p1, p2) = 1/ratio + φ_bonus
|
|
233
|
+
where φ_bonus = 0.3 if |ratio - φ| < 0.1
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Usage
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
const {
|
|
240
|
+
calculateResonance,
|
|
241
|
+
findGoldenPairs,
|
|
242
|
+
resonanceSignature,
|
|
243
|
+
ResonanceCalculator
|
|
244
|
+
} = require('./core');
|
|
245
|
+
|
|
246
|
+
// Calculate resonance between primes
|
|
247
|
+
calculateResonance(3, 5); // → 0.9 (Fibonacci pair!)
|
|
248
|
+
calculateResonance(7, 11); // → 0.936 (close to φ)
|
|
249
|
+
calculateResonance(2, 17); // → 0.118 (far from φ)
|
|
250
|
+
|
|
251
|
+
// Find golden pairs in a set
|
|
252
|
+
const pairs = findGoldenPairs([2, 3, 5, 7, 11, 13]);
|
|
253
|
+
// → [{ p1: 3, p2: 5, ratio: 1.667 }, ...]
|
|
254
|
+
|
|
255
|
+
// Signature for a symbol set
|
|
256
|
+
const symbols = ['hero', 'journey', 'mountain'];
|
|
257
|
+
const primes = symbols.map(s => getSymbol(s).prime);
|
|
258
|
+
const sig = resonanceSignature(primes);
|
|
259
|
+
console.log(`Mean resonance: ${sig.mean.toFixed(4)}`);
|
|
260
|
+
console.log(`Golden pairs: ${sig.goldenCount}`);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Resonance Matrix
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
const calc = new ResonanceCalculator();
|
|
267
|
+
const primes = [2, 3, 5, 7, 11];
|
|
268
|
+
const matrix = calc.calculateMatrix(primes);
|
|
269
|
+
|
|
270
|
+
// matrix[i][j] = resonance between primes[i] and primes[j]
|
|
271
|
+
// Diagonal = 1.0 (self-resonance)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Entity Extraction
|
|
275
|
+
|
|
276
|
+
Simple NER-like extraction before inference:
|
|
277
|
+
|
|
278
|
+
```javascript
|
|
279
|
+
const { extractEntities, extractAndInfer } = require('./core');
|
|
280
|
+
|
|
281
|
+
const text = 'The hero John traveled to the ancient temple';
|
|
282
|
+
|
|
283
|
+
// Extract entities
|
|
284
|
+
const entities = extractEntities(text);
|
|
285
|
+
// → ['john', 'hero', 'temple', 'ancient temple']
|
|
286
|
+
|
|
287
|
+
// Extract and infer in one step
|
|
288
|
+
const symbols = extractAndInfer(text);
|
|
289
|
+
// → [{ entity: 'hero', symbol: 🦸 }, { entity: 'temple', symbol: ⛩️ }]
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Examples
|
|
293
|
+
|
|
294
|
+
Run the example files to see everything in action:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
# Resonance theory
|
|
298
|
+
node examples/05-symbolic-resonance.js
|
|
299
|
+
|
|
300
|
+
# Symbol database
|
|
301
|
+
node examples/06-symbol-database.js
|
|
302
|
+
|
|
303
|
+
# Semantic inference with resonance
|
|
304
|
+
node examples/07-semantic-inference.js
|
|
305
|
+
|
|
306
|
+
# Compound symbols
|
|
307
|
+
node examples/08-compound-symbols.js
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Integration with ResoFormer
|
|
311
|
+
|
|
312
|
+
The symbolic AI system uses ResoFormer's core primitives:
|
|
313
|
+
|
|
314
|
+
| Symbolic AI | ResoFormer Component |
|
|
315
|
+
|------------|---------------------|
|
|
316
|
+
| `symbolToState()` | `SparsePrimeState` |
|
|
317
|
+
| `calculateCandidateResonance()` | `resonanceScore()` |
|
|
318
|
+
| `resonanceSelect()` | `resonantAttention()` |
|
|
319
|
+
| `inferMostResonant()` | Weighted resonance scoring |
|
|
320
|
+
|
|
321
|
+
This creates a unified system where:
|
|
322
|
+
- Symbols are prime-indexed
|
|
323
|
+
- Cultural similarity uses sparse prime overlap
|
|
324
|
+
- Disambiguation uses quaternionic attention
|
|
325
|
+
- Harmony measurement uses golden ratio theory
|
|
326
|
+
|
|
327
|
+
## API Reference
|
|
328
|
+
|
|
329
|
+
### Symbol Database
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
getSymbol(id: string): Symbol | null
|
|
333
|
+
getSymbolByPrime(prime: number): Symbol | null
|
|
334
|
+
symbolDatabase.search(query: string): Symbol[]
|
|
335
|
+
symbolDatabase.getByCategory(category: SymbolCategory): Symbol[]
|
|
336
|
+
symbolDatabase.getSymbolsByTag(tag: string): Symbol[]
|
|
337
|
+
symbolDatabase.encode(ids: string[]): bigint
|
|
338
|
+
symbolDatabase.decode(signature: bigint): Symbol[]
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Semantic Inference
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
inferSymbol(text: string): InferenceResult | null
|
|
345
|
+
inferSymbols(entities: string[]): InferenceResult[]
|
|
346
|
+
inferWithResonance(text: string, options?): InferenceResult[]
|
|
347
|
+
inferMostResonant(text: string, context: Symbol[]): InferenceResult
|
|
348
|
+
extractEntities(text: string): string[]
|
|
349
|
+
extractAndInfer(text: string): InferenceResult[]
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Compound Builder
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
createCompound(id, componentIds, meaning, culturalTags?): CompoundSymbol
|
|
356
|
+
getCompound(id: string): CompoundSymbol | null
|
|
357
|
+
createSequence(id, symbolIds, type, description?): SymbolSequence
|
|
358
|
+
getSequence(id: string): SymbolSequence | null
|
|
359
|
+
compoundBuilder.calculateCompoundResonance(compound): number
|
|
360
|
+
compoundBuilder.createCulturalVariant(baseId, culture, addSymbols, meaning): CompoundSymbol
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Resonance Calculator
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
calculateResonance(p1: number, p2: number): number
|
|
367
|
+
findGoldenPairs(primes: number[]): GoldenPair[]
|
|
368
|
+
resonanceSignature(primes: number[]): { mean, variance, goldenCount }
|
|
369
|
+
ResonanceCalculator.findMostResonant(target, candidates): { prime, resonance }
|
|
370
|
+
ResonanceCalculator.findClusters(primes, threshold): number[][]
|
package/docs/guide/README.md
CHANGED
|
@@ -9,7 +9,8 @@ This section provides hands-on guidance for using Aleph in your projects. Whethe
|
|
|
9
9
|
3. [Cryptographic Applications](./03-cryptographic.md) - Hashing and key derivation
|
|
10
10
|
4. [Scientific Computing](./04-scientific.md) - Quantum simulation
|
|
11
11
|
5. [LLM Integration](./05-llm-integration.md) - Coupling with language models
|
|
12
|
-
6. [
|
|
12
|
+
6. [Symbolic AI & Resonance](./06-symbolic-ai.md) - Symbol inference with attention
|
|
13
|
+
7. [Advanced Techniques](./07-advanced.md) - Power user guide
|
|
13
14
|
|
|
14
15
|
---
|
|
15
16
|
|