@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,298 @@
|
|
|
1
|
+
# Quick Start
|
|
2
|
+
|
|
3
|
+
Get Aleph running in 5 minutes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Clone the repository
|
|
9
|
+
git clone https://github.com/your-repo/tinyaleph.git
|
|
10
|
+
cd tinyaleph
|
|
11
|
+
|
|
12
|
+
# Install dependencies
|
|
13
|
+
npm install
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Verify Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
node -e "const { createEngine } = require('./modular'); console.log('✓ Aleph ready')"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Hello Semantic World
|
|
25
|
+
|
|
26
|
+
Create a file `hello.js`:
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
const { createEngine } = require('./modular');
|
|
30
|
+
|
|
31
|
+
// Load configuration with vocabulary and ontology
|
|
32
|
+
const config = require('./data.json');
|
|
33
|
+
|
|
34
|
+
// Create semantic engine
|
|
35
|
+
const engine = createEngine('semantic', config);
|
|
36
|
+
|
|
37
|
+
// Process a query
|
|
38
|
+
const result = engine.run('What is love?');
|
|
39
|
+
|
|
40
|
+
console.log('Input:', result.input);
|
|
41
|
+
console.log('Output:', result.output);
|
|
42
|
+
console.log('Entropy:', result.entropy.toFixed(3));
|
|
43
|
+
console.log('Coherence:', result.coherence.toFixed(3));
|
|
44
|
+
console.log('Stability:', result.stability);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run it:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
node hello.js
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Expected output:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
Input: What is love?
|
|
57
|
+
Output: affection devotion compassion
|
|
58
|
+
Entropy: 2.145
|
|
59
|
+
Coherence: 0.723
|
|
60
|
+
Stability: STABLE
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Understanding the Output
|
|
66
|
+
|
|
67
|
+
### What Happened?
|
|
68
|
+
|
|
69
|
+
1. **Tokenization**: "What is love?" → ["love"] (stop words filtered)
|
|
70
|
+
2. **Prime Encoding**: "love" → [2, 3, 5] (from vocabulary)
|
|
71
|
+
3. **Oscillator Excitation**: Primes 2, 3, 5 excited in oscillator bank
|
|
72
|
+
4. **Field Evolution**: Kuramoto dynamics run for up to 100 steps
|
|
73
|
+
5. **Frame Sampling**: Coherent frames captured during evolution
|
|
74
|
+
6. **Decoding**: Best frame decoded to words
|
|
75
|
+
|
|
76
|
+
### Key Metrics
|
|
77
|
+
|
|
78
|
+
| Metric | Meaning |
|
|
79
|
+
|--------|---------|
|
|
80
|
+
| **Entropy** | How "spread out" the meaning is. Lower = clearer |
|
|
81
|
+
| **Coherence** | How synchronized the oscillators are. Higher = more unified |
|
|
82
|
+
| **Stability** | Lyapunov classification: STABLE, MARGINAL, or CHAOTIC |
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Exploring Physics
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
const { createEngine } = require('./modular');
|
|
90
|
+
const config = require('./data.json');
|
|
91
|
+
|
|
92
|
+
const engine = createEngine('semantic', config);
|
|
93
|
+
|
|
94
|
+
// Run a query
|
|
95
|
+
engine.run('wisdom and truth');
|
|
96
|
+
|
|
97
|
+
// Examine physics state
|
|
98
|
+
const physics = engine.getPhysicsState();
|
|
99
|
+
|
|
100
|
+
console.log('State entropy:', physics.entropy.toFixed(3));
|
|
101
|
+
console.log('Order parameter:', physics.orderParameter.toFixed(3));
|
|
102
|
+
console.log('Lyapunov exponent:', physics.lyapunov.toFixed(4));
|
|
103
|
+
console.log('Coupling strength:', physics.coupling.toFixed(3));
|
|
104
|
+
console.log('Collapse probability:', physics.collapseProbability.toFixed(3));
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Multiple Queries
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
const { createEngine } = require('./modular');
|
|
113
|
+
const config = require('./data.json');
|
|
114
|
+
|
|
115
|
+
const engine = createEngine('semantic', config);
|
|
116
|
+
|
|
117
|
+
const queries = [
|
|
118
|
+
'What is truth?',
|
|
119
|
+
'How does love relate to wisdom?',
|
|
120
|
+
'Is freedom compatible with responsibility?'
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
for (const query of queries) {
|
|
124
|
+
const result = engine.run(query);
|
|
125
|
+
console.log(`\nQ: ${query}`);
|
|
126
|
+
console.log(`A: ${result.output}`);
|
|
127
|
+
console.log(` Entropy: ${result.entropy.toFixed(2)}, Coherence: ${result.coherence.toFixed(2)}`);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Batch Processing
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
const { createEngine } = require('./modular');
|
|
137
|
+
const config = require('./data.json');
|
|
138
|
+
|
|
139
|
+
const engine = createEngine('semantic', config);
|
|
140
|
+
|
|
141
|
+
const inputs = [
|
|
142
|
+
'love',
|
|
143
|
+
'wisdom',
|
|
144
|
+
'justice',
|
|
145
|
+
'beauty',
|
|
146
|
+
'truth'
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
const results = engine.runBatch(inputs);
|
|
150
|
+
|
|
151
|
+
for (const result of results) {
|
|
152
|
+
console.log(`${result.input} → ${result.output} (H=${result.entropy.toFixed(2)})`);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Continuous Evolution
|
|
159
|
+
|
|
160
|
+
Watch the physics unfold without new input:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
const { createEngine } = require('./modular');
|
|
164
|
+
const config = require('./data.json');
|
|
165
|
+
|
|
166
|
+
const engine = createEngine('semantic', config);
|
|
167
|
+
|
|
168
|
+
// Seed with a concept
|
|
169
|
+
engine.run('consciousness');
|
|
170
|
+
|
|
171
|
+
// Evolve for 50 steps
|
|
172
|
+
const states = engine.evolve(50);
|
|
173
|
+
|
|
174
|
+
console.log('Evolution trace:');
|
|
175
|
+
for (const state of states.slice(0, 10)) {
|
|
176
|
+
console.log(`Step ${state.step}: H=${state.entropy.toFixed(3)}, r=${state.orderParameter.toFixed(3)}, ${state.stability}`);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Switching Backends
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
const { createEngine, CryptographicBackend } = require('./modular');
|
|
186
|
+
const semanticConfig = require('./data.json');
|
|
187
|
+
|
|
188
|
+
// Start with semantic
|
|
189
|
+
const engine = createEngine('semantic', semanticConfig);
|
|
190
|
+
console.log('Backend:', engine.getBackendInfo().name);
|
|
191
|
+
|
|
192
|
+
let result = engine.run('love and truth');
|
|
193
|
+
console.log('Semantic output:', result.output);
|
|
194
|
+
|
|
195
|
+
// Switch to cryptographic
|
|
196
|
+
engine.setBackend(new CryptographicBackend({ dimension: 32 }));
|
|
197
|
+
console.log('Backend:', engine.getBackendInfo().name);
|
|
198
|
+
|
|
199
|
+
// Now it hashes instead
|
|
200
|
+
result = engine.run('hello world');
|
|
201
|
+
console.log('Crypto primes:', result.resultPrimes.slice(0, 5));
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Using Individual Backends
|
|
207
|
+
|
|
208
|
+
You can use backends directly without the engine:
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
const { SemanticBackend } = require('./modular');
|
|
212
|
+
const config = require('./data.json');
|
|
213
|
+
|
|
214
|
+
const backend = new SemanticBackend(config);
|
|
215
|
+
|
|
216
|
+
// Encode text to primes
|
|
217
|
+
const primes = backend.encode('love and wisdom');
|
|
218
|
+
console.log('Primes:', primes);
|
|
219
|
+
|
|
220
|
+
// Decode primes to text
|
|
221
|
+
const text = backend.decode(primes);
|
|
222
|
+
console.log('Decoded:', text);
|
|
223
|
+
|
|
224
|
+
// Get state vector
|
|
225
|
+
const state = backend.primesToState(primes);
|
|
226
|
+
console.log('State entropy:', state.entropy().toFixed(3));
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Common Patterns
|
|
232
|
+
|
|
233
|
+
### Check Semantic Similarity
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
const { SemanticBackend } = require('./modular');
|
|
237
|
+
const config = require('./data.json');
|
|
238
|
+
|
|
239
|
+
const backend = new SemanticBackend(config);
|
|
240
|
+
|
|
241
|
+
function similarity(text1, text2) {
|
|
242
|
+
const state1 = backend.textToOrderedState(text1);
|
|
243
|
+
const state2 = backend.textToOrderedState(text2);
|
|
244
|
+
return state1.coherence(state2);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
console.log('love vs affection:', similarity('love', 'affection').toFixed(3));
|
|
248
|
+
console.log('love vs hatred:', similarity('love', 'hatred').toFixed(3));
|
|
249
|
+
console.log('love vs economics:', similarity('love', 'economics').toFixed(3));
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Monitor Stability
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
const { createEngine } = require('./modular');
|
|
256
|
+
const config = require('./data.json');
|
|
257
|
+
|
|
258
|
+
const engine = createEngine('semantic', config);
|
|
259
|
+
|
|
260
|
+
// Process and check stability
|
|
261
|
+
const result = engine.run('chaos and order');
|
|
262
|
+
|
|
263
|
+
if (result.stability === 'CHAOTIC') {
|
|
264
|
+
console.log('⚠️ Unstable state detected');
|
|
265
|
+
console.log('Lyapunov:', result.lyapunov.toFixed(4));
|
|
266
|
+
} else if (result.stability === 'STABLE') {
|
|
267
|
+
console.log('✓ Stable understanding achieved');
|
|
268
|
+
} else {
|
|
269
|
+
console.log('~ Marginal stability');
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Track Collapse Events
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
const { createEngine } = require('./modular');
|
|
277
|
+
const config = require('./data.json');
|
|
278
|
+
|
|
279
|
+
const engine = createEngine('semantic', config);
|
|
280
|
+
|
|
281
|
+
for (let i = 0; i < 10; i++) {
|
|
282
|
+
const result = engine.run('quantum consciousness');
|
|
283
|
+
if (result.collapsed) {
|
|
284
|
+
console.log(`Collapse at iteration ${i}!`);
|
|
285
|
+
console.log('Post-collapse entropy:', result.entropy.toFixed(3));
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Next Steps
|
|
294
|
+
|
|
295
|
+
- [Semantic Computing →](./02-semantic-computing.md) - Deep dive into NLP
|
|
296
|
+
- [Cryptographic Applications →](./03-cryptographic.md) - Security features
|
|
297
|
+
- [Scientific Computing →](./04-scientific.md) - Quantum simulation
|
|
298
|
+
- [Theory →](../theory/README.md) - Understand the foundations
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
# Semantic Computing
|
|
2
|
+
|
|
3
|
+
This guide covers using Aleph for natural language understanding, concept mapping, and philosophical reasoning.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Semantic computing treats **concepts as the fundamental data type**. Instead of manipulating bits or strings, we manipulate meaning directly through prime arithmetic and hypercomplex states.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Creating a Semantic Engine
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { createEngine, SemanticBackend } = require('./modular');
|
|
15
|
+
|
|
16
|
+
// Load full configuration
|
|
17
|
+
const config = require('./data.json');
|
|
18
|
+
|
|
19
|
+
// Create engine
|
|
20
|
+
const engine = createEngine('semantic', config);
|
|
21
|
+
|
|
22
|
+
// Or create backend directly
|
|
23
|
+
const backend = new SemanticBackend(config);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Text Processing
|
|
29
|
+
|
|
30
|
+
### Tokenization
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
const backend = new SemanticBackend(config);
|
|
34
|
+
|
|
35
|
+
// Basic tokenization
|
|
36
|
+
const tokens = backend.tokenize('Love is the answer');
|
|
37
|
+
console.log(tokens);
|
|
38
|
+
// [
|
|
39
|
+
// { word: 'love', primes: [2,3,5], known: true, isStop: false, position: 0 },
|
|
40
|
+
// { word: 'is', primes: [...], known: true, isStop: true, position: 1 },
|
|
41
|
+
// { word: 'the', primes: [...], known: true, isStop: true, position: 2 },
|
|
42
|
+
// { word: 'answer', primes: [...], known: true, isStop: false, position: 3 }
|
|
43
|
+
// ]
|
|
44
|
+
|
|
45
|
+
// Filtered tokenization (removes stop words)
|
|
46
|
+
const filtered = backend.tokenize('Love is the answer', true);
|
|
47
|
+
console.log(filtered);
|
|
48
|
+
// [
|
|
49
|
+
// { word: 'love', primes: [2,3,5], known: true, isStop: false, position: 0 },
|
|
50
|
+
// { word: 'answer', primes: [...], known: true, isStop: false, position: 1 }
|
|
51
|
+
// ]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Encoding
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
// Encode to primes (unordered)
|
|
58
|
+
const primes = backend.encode('wisdom and truth');
|
|
59
|
+
console.log(primes); // [2, 7, 11, 7, 11, 13]
|
|
60
|
+
|
|
61
|
+
// Ordered encoding (preserves position)
|
|
62
|
+
const ordered = backend.encodeOrdered('wisdom and truth');
|
|
63
|
+
console.log(ordered);
|
|
64
|
+
// [
|
|
65
|
+
// { word: 'wisdom', primes: [2,7,11], position: 0 },
|
|
66
|
+
// { word: 'truth', primes: [7,11,13], position: 1 }
|
|
67
|
+
// ]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Decoding
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
// Decode primes to words
|
|
74
|
+
const primes = [2, 3, 5, 7, 11];
|
|
75
|
+
const words = backend.decode(primes);
|
|
76
|
+
console.log(words); // "love wisdom truth"
|
|
77
|
+
|
|
78
|
+
// The decoder uses greedy covering to find words
|
|
79
|
+
// that best match the input primes
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## State Vectors
|
|
85
|
+
|
|
86
|
+
### Prime to State Conversion
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
// Unordered (commutative)
|
|
90
|
+
const primes = [2, 3, 5];
|
|
91
|
+
const state = backend.primesToState(primes);
|
|
92
|
+
console.log('Entropy:', state.entropy());
|
|
93
|
+
console.log('Norm:', state.norm());
|
|
94
|
+
|
|
95
|
+
// Ordered (non-commutative) - preserves word order
|
|
96
|
+
const tokens = backend.encodeOrdered('dog bites man');
|
|
97
|
+
const orderedState = backend.orderedPrimesToState(tokens);
|
|
98
|
+
|
|
99
|
+
const tokens2 = backend.encodeOrdered('man bites dog');
|
|
100
|
+
const orderedState2 = backend.orderedPrimesToState(tokens2);
|
|
101
|
+
|
|
102
|
+
console.log('Same words, different order:');
|
|
103
|
+
console.log('Coherence:', orderedState.coherence(orderedState2));
|
|
104
|
+
// Should be < 1.0 because order matters
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Semantic Similarity
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
function semanticSimilarity(text1, text2, backend) {
|
|
111
|
+
const state1 = backend.textToOrderedState(text1);
|
|
112
|
+
const state2 = backend.textToOrderedState(text2);
|
|
113
|
+
return state1.coherence(state2);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const backend = new SemanticBackend(config);
|
|
117
|
+
|
|
118
|
+
console.log('Similar concepts:');
|
|
119
|
+
console.log('love vs affection:', semanticSimilarity('love', 'affection', backend));
|
|
120
|
+
console.log('wisdom vs knowledge:', semanticSimilarity('wisdom', 'knowledge', backend));
|
|
121
|
+
|
|
122
|
+
console.log('\nOpposite concepts:');
|
|
123
|
+
console.log('love vs hate:', semanticSimilarity('love', 'hate', backend));
|
|
124
|
+
console.log('truth vs falsehood:', semanticSimilarity('truth', 'falsehood', backend));
|
|
125
|
+
|
|
126
|
+
console.log('\nUnrelated concepts:');
|
|
127
|
+
console.log('love vs economics:', semanticSimilarity('love', 'economics', backend));
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Semantic Transforms
|
|
133
|
+
|
|
134
|
+
Transforms are rewrite rules that simplify or modify meaning:
|
|
135
|
+
|
|
136
|
+
### Applying Transforms
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
const transform = {
|
|
140
|
+
n: 'question_to_insight',
|
|
141
|
+
q: [curiosity_prime, unknown_prime], // Query primes
|
|
142
|
+
r: [understanding_prime, known_prime] // Result primes
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const inputPrimes = [2, 3, curiosity_prime, unknown_prime, 5];
|
|
146
|
+
const result = backend.applyTransform(inputPrimes, transform);
|
|
147
|
+
// Query primes replaced with result primes
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Transform-Based Reasoning
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
const engine = createEngine('semantic', config);
|
|
154
|
+
|
|
155
|
+
const result = engine.run('What is the meaning of life?');
|
|
156
|
+
|
|
157
|
+
console.log('Reasoning steps:');
|
|
158
|
+
for (const step of result.steps) {
|
|
159
|
+
console.log(` Step ${step.step}: ${step.transform}`);
|
|
160
|
+
console.log(` Entropy drop: ${step.entropyDrop.toFixed(3)}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
console.log('Final output:', result.output);
|
|
164
|
+
console.log('Final entropy:', result.entropy);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Vocabulary Management
|
|
170
|
+
|
|
171
|
+
### Checking Vocabulary
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
const backend = new SemanticBackend(config);
|
|
175
|
+
|
|
176
|
+
console.log('Vocabulary size:', backend.getVocabularySize());
|
|
177
|
+
console.log('Has "love":', backend.hasWord('love'));
|
|
178
|
+
console.log('Love primes:', backend.getWordPrimes('love'));
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Learning New Words
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
// Add a new word with explicit primes
|
|
185
|
+
backend.learn('serendipity', [2, 29, 53]);
|
|
186
|
+
// Now "serendipity" maps to [existence, becoming, kairos]
|
|
187
|
+
|
|
188
|
+
console.log('Learned:', backend.hasWord('serendipity'));
|
|
189
|
+
console.log('Primes:', backend.getWordPrimes('serendipity'));
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Ontology Access
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
// Get meaning of a prime
|
|
196
|
+
const meaning = backend.getOntologyMeaning(7);
|
|
197
|
+
console.log('Prime 7 means:', meaning); // "logos/reason"
|
|
198
|
+
|
|
199
|
+
// Get primes for an axis
|
|
200
|
+
const axisPrimes = backend.getAxisPrimes(0);
|
|
201
|
+
console.log('Axis 0 primes:', axisPrimes);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Two-Layer Processing
|
|
207
|
+
|
|
208
|
+
For sophisticated vocabulary handling, use the TwoLayerEngine:
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
const { TwoLayerEngine } = require('./backends/semantic/two-layer');
|
|
212
|
+
|
|
213
|
+
const engine = new TwoLayerEngine({
|
|
214
|
+
core: config
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Process with meaning and surface separation
|
|
218
|
+
const result = engine.process('love is truth');
|
|
219
|
+
|
|
220
|
+
console.log('Meaning (primes):', result.meaning.primes);
|
|
221
|
+
console.log('Meaning (entropy):', result.meaning.entropy);
|
|
222
|
+
console.log('Surface (words):', result.surface.words);
|
|
223
|
+
console.log('Surface (register):', result.surface.register);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Register Translation
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
const engine = new TwoLayerEngine({ core: config });
|
|
230
|
+
|
|
231
|
+
// Translate between registers
|
|
232
|
+
const result = engine.translate(
|
|
233
|
+
'The verity is sagacious',
|
|
234
|
+
'formal',
|
|
235
|
+
'casual'
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
console.log('Original:', result.original);
|
|
239
|
+
console.log('Translated:', result.translated);
|
|
240
|
+
// "real talk that's big brain"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Style-Specific Generation
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
const engine = new TwoLayerEngine({ core: config });
|
|
247
|
+
|
|
248
|
+
// Generate with specific style
|
|
249
|
+
const primes = [7, 11, 13]; // truth + psyche + purpose
|
|
250
|
+
|
|
251
|
+
engine.useRegister('poetic');
|
|
252
|
+
const poetic = engine.generateWithStyle(primes, 'romantic');
|
|
253
|
+
|
|
254
|
+
engine.useRegister('technical');
|
|
255
|
+
const technical = engine.generateWithStyle(primes, 'scientific');
|
|
256
|
+
|
|
257
|
+
console.log('Poetic:', poetic);
|
|
258
|
+
console.log('Technical:', technical);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Practical Applications
|
|
264
|
+
|
|
265
|
+
### Concept Clustering
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
const { createEngine, SemanticBackend } = require('./modular');
|
|
269
|
+
|
|
270
|
+
function clusterConcepts(words, backend) {
|
|
271
|
+
const states = words.map(w => ({
|
|
272
|
+
word: w,
|
|
273
|
+
state: backend.textToOrderedState(w)
|
|
274
|
+
}));
|
|
275
|
+
|
|
276
|
+
const clusters = [];
|
|
277
|
+
const used = new Set();
|
|
278
|
+
|
|
279
|
+
for (let i = 0; i < states.length; i++) {
|
|
280
|
+
if (used.has(i)) continue;
|
|
281
|
+
|
|
282
|
+
const cluster = [states[i].word];
|
|
283
|
+
used.add(i);
|
|
284
|
+
|
|
285
|
+
for (let j = i + 1; j < states.length; j++) {
|
|
286
|
+
if (used.has(j)) continue;
|
|
287
|
+
|
|
288
|
+
const similarity = states[i].state.coherence(states[j].state);
|
|
289
|
+
if (similarity > 0.7) {
|
|
290
|
+
cluster.push(states[j].word);
|
|
291
|
+
used.add(j);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
clusters.push(cluster);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return clusters;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const backend = new SemanticBackend(config);
|
|
302
|
+
const words = ['love', 'affection', 'truth', 'honesty', 'justice', 'fairness'];
|
|
303
|
+
const clusters = clusterConcepts(words, backend);
|
|
304
|
+
console.log('Clusters:', clusters);
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Semantic Search
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
function semanticSearch(query, documents, backend, topK = 5) {
|
|
311
|
+
const queryState = backend.textToOrderedState(query);
|
|
312
|
+
|
|
313
|
+
const scored = documents.map(doc => ({
|
|
314
|
+
doc,
|
|
315
|
+
score: backend.textToOrderedState(doc).coherence(queryState)
|
|
316
|
+
}));
|
|
317
|
+
|
|
318
|
+
return scored
|
|
319
|
+
.sort((a, b) => b.score - a.score)
|
|
320
|
+
.slice(0, topK);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const backend = new SemanticBackend(config);
|
|
324
|
+
const docs = [
|
|
325
|
+
'Love conquers all obstacles',
|
|
326
|
+
'The truth shall set you free',
|
|
327
|
+
'Wisdom comes from experience',
|
|
328
|
+
'Justice must be blind',
|
|
329
|
+
'Beauty is in the eye of the beholder'
|
|
330
|
+
];
|
|
331
|
+
|
|
332
|
+
const results = semanticSearch('knowledge and understanding', docs, backend);
|
|
333
|
+
for (const r of results) {
|
|
334
|
+
console.log(`${r.score.toFixed(3)}: ${r.doc}`);
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Contradiction Detection
|
|
339
|
+
|
|
340
|
+
```javascript
|
|
341
|
+
function detectContradiction(statement1, statement2, backend) {
|
|
342
|
+
const state1 = backend.textToOrderedState(statement1);
|
|
343
|
+
const state2 = backend.textToOrderedState(statement2);
|
|
344
|
+
|
|
345
|
+
// Check for zero-divisor relationship
|
|
346
|
+
if (state1.isZeroDivisorWith(state2)) {
|
|
347
|
+
return { contradicts: true, type: 'zero-divisor' };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Check for low coherence
|
|
351
|
+
const coherence = state1.coherence(state2);
|
|
352
|
+
if (coherence < 0.2) {
|
|
353
|
+
return { contradicts: true, type: 'orthogonal', coherence };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return { contradicts: false, coherence };
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const backend = new SemanticBackend(config);
|
|
360
|
+
console.log(detectContradiction('freedom is essential', 'slavery is acceptable', backend));
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Performance Tips
|
|
366
|
+
|
|
367
|
+
### Batch Processing
|
|
368
|
+
|
|
369
|
+
```javascript
|
|
370
|
+
// Process many inputs efficiently
|
|
371
|
+
const engine = createEngine('semantic', config);
|
|
372
|
+
const inputs = ['love', 'truth', 'wisdom', 'justice', 'beauty'];
|
|
373
|
+
const results = engine.runBatch(inputs);
|
|
374
|
+
|
|
375
|
+
// Results computed in sequence, oscillators carry state
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Caching States
|
|
379
|
+
|
|
380
|
+
```javascript
|
|
381
|
+
const stateCache = new Map();
|
|
382
|
+
|
|
383
|
+
function getCachedState(text, backend) {
|
|
384
|
+
if (!stateCache.has(text)) {
|
|
385
|
+
stateCache.set(text, backend.textToOrderedState(text));
|
|
386
|
+
}
|
|
387
|
+
return stateCache.get(text);
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Reducing Dimension
|
|
392
|
+
|
|
393
|
+
```javascript
|
|
394
|
+
// Lower dimension = faster, less precise
|
|
395
|
+
const fastConfig = { ...config, dimension: 8 };
|
|
396
|
+
const fastEngine = createEngine('semantic', fastConfig);
|
|
397
|
+
|
|
398
|
+
// Higher dimension = slower, more precise
|
|
399
|
+
const preciseConfig = { ...config, dimension: 32 };
|
|
400
|
+
const preciseEngine = createEngine('semantic', preciseConfig);
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
## Next Steps
|
|
406
|
+
|
|
407
|
+
- [Cryptographic Applications →](./03-cryptographic.md)
|
|
408
|
+
- [Theory: Two-Layer Meaning →](../theory/06-two-layer-meaning.md)
|
|
409
|
+
- [Reference: SemanticBackend →](../reference/03-backends.md#semantic-backend)
|