@aleph-ai/tinyaleph 1.5.6 → 1.6.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/core/alexander-module.js +1469 -0
- package/core/arithmetic-link-kernel.js +1338 -0
- package/core/index.js +95 -2
- package/examples/01-hello-world.js +69 -0
- package/examples/02-basic-hash.js +90 -0
- package/examples/02-observer-stack.js +385 -0
- package/examples/03-quantum-coin.js +136 -0
- package/examples/05-symbolic-resonance.js +146 -0
- package/examples/06-symbol-database.js +150 -0
- package/examples/07-semantic-inference.js +223 -0
- package/examples/08-compound-symbols.js +219 -0
- package/examples/README.md +170 -0
- package/examples/ai/01-embeddings.js +155 -0
- package/examples/ai/02-semantic-memory.js +243 -0
- package/examples/ai/03-reasoning.js +243 -0
- package/examples/ai/04-knowledge-graph.js +279 -0
- package/examples/ai/05-llm-integration.js +333 -0
- package/examples/ai/06-agent.js +294 -0
- package/examples/ai/07-hybrid-ai.js +223 -0
- package/examples/ai/08-entropy-reasoning.js +259 -0
- package/examples/ai/09-concept-learning.js +271 -0
- package/examples/ai/10-prompt-primes.js +312 -0
- package/examples/ai/11-rag.js +332 -0
- package/examples/ai/12-neuro-symbolic.js +321 -0
- package/examples/ai/README.md +80 -0
- package/examples/arithmetic-topology/01-legendre-symbol.js +78 -0
- package/examples/arithmetic-topology/02-redei-symbol.js +126 -0
- package/examples/arithmetic-topology/03-alk-kuramoto.js +138 -0
- package/examples/arithmetic-topology/04-alexander-module.js +117 -0
- package/examples/arithmetic-topology/05-signature-memory.js +118 -0
- package/examples/arithmetic-topology/README.md +291 -0
- package/examples/bioinformatics/01-dna-encoding.js +108 -0
- package/examples/bioinformatics/02-central-dogma.js +162 -0
- package/examples/bioinformatics/03-protein-folding.js +206 -0
- package/examples/bioinformatics/04-dna-computing.js +192 -0
- package/examples/bioinformatics/05-molecular-binding.js +209 -0
- package/examples/chat.js +105 -0
- package/examples/crt-homology/01-residue-encoding.js +87 -0
- package/examples/crt-homology/02-birkhoff-attention.js +100 -0
- package/examples/crt-homology/03-homology-loss.js +132 -0
- package/examples/crt-homology/04-crt-resoformer.js +132 -0
- package/examples/crt-homology/README.md +67 -0
- package/examples/crypto/01-password-hash.js +210 -0
- package/examples/crypto/02-key-derivation.js +210 -0
- package/examples/crypto/03-hmac.js +229 -0
- package/examples/crypto/04-file-integrity.js +263 -0
- package/examples/crypto/05-content-hash.js +263 -0
- package/examples/crypto/README.md +99 -0
- package/examples/demo-modular.js +223 -0
- package/examples/demo-two-layer.js +196 -0
- package/examples/discrete/01-integer-sine-table.js +120 -0
- package/examples/discrete/02-codebook-tunneling.js +118 -0
- package/examples/discrete/03-canonical-fusion.js +135 -0
- package/examples/discrete/04-tick-gate.js +139 -0
- package/examples/discrete/README.md +142 -0
- package/examples/formal-semantics/01-typed-terms.js +156 -0
- package/examples/formal-semantics/02-reduction.js +202 -0
- package/examples/formal-semantics/03-lambda-translation.js +206 -0
- package/examples/formal-semantics/04-enochian-language.js +257 -0
- package/examples/formal-semantics/README.md +98 -0
- package/examples/math/01-quaternions.js +237 -0
- package/examples/math/02-octonions.js +192 -0
- package/examples/math/03-prime-factorization.js +215 -0
- package/examples/math/04-vector-spaces.js +210 -0
- package/examples/math/05-gaussian-primes.js +234 -0
- package/examples/math/README.md +93 -0
- package/examples/physics/01-oscillator.js +177 -0
- package/examples/physics/02-lyapunov.js +201 -0
- package/examples/physics/03-collapse.js +183 -0
- package/examples/physics/04-kuramoto.js +212 -0
- package/examples/physics/05-entropy.js +226 -0
- package/examples/physics/05-sync-models.js +298 -0
- package/examples/physics/06-primeon-ladder.js +233 -0
- package/examples/physics/07-kuramoto-coupled-ladder.js +298 -0
- package/examples/physics/README.md +126 -0
- package/examples/resonance/01-prime-hilbert-space.js +140 -0
- package/examples/resonance/02-prime-resonance-network.js +221 -0
- package/examples/resonance/03-resoformer.js +349 -0
- package/examples/resonance/04-resoformer-training.js +329 -0
- package/examples/resonance/05-language-model.js +484 -0
- package/examples/resonance/README.md +238 -0
- package/examples/run-examples.js +417 -0
- package/examples/scientific/01-single-qubit.js +185 -0
- package/examples/scientific/02-two-qubit.js +209 -0
- package/examples/scientific/03-quantum-circuits.js +270 -0
- package/examples/scientific/04-measurement.js +229 -0
- package/examples/scientific/05-algorithms.js +245 -0
- package/examples/scientific/06-random.js +225 -0
- package/examples/scientific/07-wavefunction.js +192 -0
- package/examples/scientific/README.md +118 -0
- package/examples/semantic/01-vocabulary.js +186 -0
- package/examples/semantic/02-similarity.js +263 -0
- package/examples/semantic/03-word-algebra.js +295 -0
- package/examples/semantic/04-clustering.js +348 -0
- package/examples/semantic/05-classification.js +386 -0
- package/examples/semantic/06-dna-encoding.js +228 -0
- package/examples/semantic/07-search.js +304 -0
- package/examples/semantic/08-qa-system.js +278 -0
- package/examples/semantic/README.md +116 -0
- package/examples/topology/01-108-invariant.js +81 -0
- package/examples/topology/02-trefoil-constants.js +112 -0
- package/examples/topology/03-gauge-symmetry.js +112 -0
- package/examples/topology/04-free-energy-dynamics.js +124 -0
- package/examples/topology/README.md +129 -0
- package/index.js +32 -0
- package/modular.js +63 -2
- package/observer/agency.js +885 -0
- package/observer/assays.js +973 -0
- package/observer/boundary.js +1155 -0
- package/observer/entanglement.js +673 -0
- package/observer/hqe.js +1465 -0
- package/observer/index.js +158 -0
- package/observer/prsc.js +1289 -0
- package/observer/safety.js +815 -0
- package/observer/smf.js +1015 -0
- package/observer/symbolic-smf.js +726 -0
- package/observer/symbolic-temporal.js +790 -0
- package/observer/temporal.js +669 -0
- package/package.json +9 -3
- package/physics/alk-kuramoto.js +817 -0
- package/physics/index.js +23 -2
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Compound Symbols
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates the compound builder for creating multi-symbol concepts,
|
|
5
|
+
* cultural variants, and narrative sequences.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
CompoundBuilder,
|
|
10
|
+
CompoundSymbol,
|
|
11
|
+
SymbolSequence,
|
|
12
|
+
compoundBuilder,
|
|
13
|
+
createCompound,
|
|
14
|
+
getCompound,
|
|
15
|
+
createSequence,
|
|
16
|
+
getSequence,
|
|
17
|
+
symbolDatabase,
|
|
18
|
+
resonanceSignature
|
|
19
|
+
} = require('../core');
|
|
20
|
+
|
|
21
|
+
console.log('='.repeat(60));
|
|
22
|
+
console.log('Compound Symbol Builder');
|
|
23
|
+
console.log('='.repeat(60));
|
|
24
|
+
|
|
25
|
+
// ─────────────────────────────────────────────────────────────────
|
|
26
|
+
// Pre-built Compounds
|
|
27
|
+
// ─────────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
console.log('\n1. Pre-built Cultural Compounds');
|
|
30
|
+
console.log('-'.repeat(40));
|
|
31
|
+
|
|
32
|
+
const prebuilt = ['greek_warrior', 'viking_warrior', 'samurai_warrior', 'philosopher_king', 'shadow_self'];
|
|
33
|
+
|
|
34
|
+
for (const id of prebuilt) {
|
|
35
|
+
const c = getCompound(id);
|
|
36
|
+
if (c) {
|
|
37
|
+
const components = c.components.map(s => s.unicode).join('');
|
|
38
|
+
const resonance = compoundBuilder.calculateCompoundResonance(c);
|
|
39
|
+
console.log(` ${components} ${c.id}`);
|
|
40
|
+
console.log(` "${c.meaning}"`);
|
|
41
|
+
console.log(` prime: ${c.prime.toString().slice(0, 20)}...`);
|
|
42
|
+
console.log(` resonance: ${resonance.toFixed(4)}`);
|
|
43
|
+
console.log(` tags: [${c.culturalTags.join(', ')}]`);
|
|
44
|
+
console.log();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ─────────────────────────────────────────────────────────────────
|
|
49
|
+
// Create Custom Compounds
|
|
50
|
+
// ─────────────────────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
console.log('\n2. Create Custom Compounds');
|
|
53
|
+
console.log('-'.repeat(40));
|
|
54
|
+
|
|
55
|
+
// Fire Mage
|
|
56
|
+
const fireMage = createCompound('fire_mage',
|
|
57
|
+
['magician', 'fire', 'staff'],
|
|
58
|
+
'Fire Mage - Wielder of flame magic',
|
|
59
|
+
['fantasy', 'magic', 'elemental']
|
|
60
|
+
);
|
|
61
|
+
console.log(` Created: ${fireMage.unicode} ${fireMage.id}`);
|
|
62
|
+
console.log(` "${fireMage.meaning}"`);
|
|
63
|
+
|
|
64
|
+
// Storm Lord
|
|
65
|
+
const stormLord = createCompound('storm_lord',
|
|
66
|
+
['ruler', 'thunder', 'lightning'],
|
|
67
|
+
'Storm Lord - Master of the tempest',
|
|
68
|
+
['mythology', 'weather', 'power']
|
|
69
|
+
);
|
|
70
|
+
console.log(` Created: ${stormLord.unicode} ${stormLord.id}`);
|
|
71
|
+
console.log(` "${stormLord.meaning}"`);
|
|
72
|
+
|
|
73
|
+
// Guardian Spirit - using valid symbols
|
|
74
|
+
const guardianSpirit = createCompound('guardian_spirit',
|
|
75
|
+
['guardian', 'shadow', 'sanctuary'],
|
|
76
|
+
'Guardian Spirit - Protective ancestor spirit',
|
|
77
|
+
['spiritual', 'protection', 'ancestors']
|
|
78
|
+
);
|
|
79
|
+
console.log(` Created: ${guardianSpirit.unicode} ${guardianSpirit.id}`);
|
|
80
|
+
console.log(` "${guardianSpirit.meaning}"`);
|
|
81
|
+
|
|
82
|
+
// ─────────────────────────────────────────────────────────────────
|
|
83
|
+
// Symbol Sequences (Narratives)
|
|
84
|
+
// ─────────────────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
console.log('\n3. Pre-built Narrative Sequences');
|
|
87
|
+
console.log('-'.repeat(40));
|
|
88
|
+
|
|
89
|
+
const herosJourney = getSequence('heros_journey');
|
|
90
|
+
if (herosJourney) {
|
|
91
|
+
const icons = herosJourney.symbols.map(s => s.unicode).join(' → ');
|
|
92
|
+
console.log(` ${herosJourney.id} (${herosJourney.type})`);
|
|
93
|
+
console.log(` ${icons}`);
|
|
94
|
+
console.log(` "${herosJourney.description}"`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const alchemical = getSequence('alchemical_transformation');
|
|
98
|
+
if (alchemical) {
|
|
99
|
+
const icons = alchemical.symbols.map(s => s.unicode).join(' → ');
|
|
100
|
+
console.log(`\n ${alchemical.id} (${alchemical.type})`);
|
|
101
|
+
console.log(` ${icons}`);
|
|
102
|
+
console.log(` "${alchemical.description}"`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ─────────────────────────────────────────────────────────────────
|
|
106
|
+
// Create Custom Sequences
|
|
107
|
+
// ─────────────────────────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
console.log('\n4. Create Custom Sequences');
|
|
110
|
+
console.log('-'.repeat(40));
|
|
111
|
+
|
|
112
|
+
// Love story - using valid symbols
|
|
113
|
+
const loveStory = createSequence('love_story',
|
|
114
|
+
['lover', 'love', 'conflict', 'unity'],
|
|
115
|
+
'narrative',
|
|
116
|
+
'Classic love story arc'
|
|
117
|
+
);
|
|
118
|
+
const loveIcons = loveStory.symbols.map(s => s.unicode).join(' → ');
|
|
119
|
+
console.log(` ${loveStory.id}: ${loveIcons}`);
|
|
120
|
+
|
|
121
|
+
// Quest for knowledge
|
|
122
|
+
const knowledgeQuest = createSequence('knowledge_quest',
|
|
123
|
+
['scholar', 'path', 'library', 'sage', 'wisdom_concept'],
|
|
124
|
+
'journey',
|
|
125
|
+
'The pursuit of wisdom'
|
|
126
|
+
);
|
|
127
|
+
if (knowledgeQuest) {
|
|
128
|
+
const icons = knowledgeQuest.symbols.map(s => s.unicode).join(' → ');
|
|
129
|
+
console.log(` ${knowledgeQuest.id}: ${icons}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ─────────────────────────────────────────────────────────────────
|
|
133
|
+
// Compound Analysis
|
|
134
|
+
// ─────────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
console.log('\n5. Compound Resonance Analysis');
|
|
137
|
+
console.log('-'.repeat(40));
|
|
138
|
+
|
|
139
|
+
const compounds = compoundBuilder.getAllCompounds();
|
|
140
|
+
console.log(` Total compounds: ${compounds.length}`);
|
|
141
|
+
|
|
142
|
+
// Sort by resonance
|
|
143
|
+
const ranked = compounds
|
|
144
|
+
.map(c => ({
|
|
145
|
+
compound: c,
|
|
146
|
+
resonance: compoundBuilder.calculateCompoundResonance(c)
|
|
147
|
+
}))
|
|
148
|
+
.sort((a, b) => b.resonance - a.resonance);
|
|
149
|
+
|
|
150
|
+
console.log('\n Top 5 by internal resonance:');
|
|
151
|
+
for (const { compound, resonance } of ranked.slice(0, 5)) {
|
|
152
|
+
console.log(` ${compound.unicode} ${compound.id}: ${resonance.toFixed(4)}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ─────────────────────────────────────────────────────────────────
|
|
156
|
+
// Find Resonant Additions
|
|
157
|
+
// ─────────────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
console.log('\n6. Find Resonant Additions');
|
|
160
|
+
console.log('-'.repeat(40));
|
|
161
|
+
|
|
162
|
+
const base = getCompound('greek_warrior');
|
|
163
|
+
if (base) {
|
|
164
|
+
const candidates = ['sun', 'moon_element', 'stars', 'thunder', 'gold', 'silver'];
|
|
165
|
+
const best = compoundBuilder.findResonantAddition(base, candidates);
|
|
166
|
+
|
|
167
|
+
console.log(` Base: ${base.unicode} ${base.id}`);
|
|
168
|
+
console.log(` Candidates: [${candidates.join(', ')}]`);
|
|
169
|
+
if (best) {
|
|
170
|
+
console.log(` Most resonant addition: ${best.symbol.unicode} ${best.symbol.id} (r=${best.resonance.toFixed(4)})`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ─────────────────────────────────────────────────────────────────
|
|
175
|
+
// Cultural Variants
|
|
176
|
+
// ─────────────────────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
console.log('\n7. Cultural Variants');
|
|
179
|
+
console.log('-'.repeat(40));
|
|
180
|
+
|
|
181
|
+
// Create variants of greek_warrior
|
|
182
|
+
const norseVariant = compoundBuilder.createCulturalVariant(
|
|
183
|
+
'greek_warrior',
|
|
184
|
+
'norse',
|
|
185
|
+
['ocean'],
|
|
186
|
+
'Norse-influenced warrior of the seas'
|
|
187
|
+
);
|
|
188
|
+
console.log(` ${norseVariant.unicode} ${norseVariant.id}`);
|
|
189
|
+
console.log(` tags: [${norseVariant.culturalTags.join(', ')}]`);
|
|
190
|
+
|
|
191
|
+
const egyptianVariant = compoundBuilder.createCulturalVariant(
|
|
192
|
+
'greek_warrior',
|
|
193
|
+
'egyptian',
|
|
194
|
+
['pyramid', 'sun'],
|
|
195
|
+
'Egyptian warrior under Ra'
|
|
196
|
+
);
|
|
197
|
+
console.log(` ${egyptianVariant.unicode} ${egyptianVariant.id}`);
|
|
198
|
+
console.log(` tags: [${egyptianVariant.culturalTags.join(', ')}]`);
|
|
199
|
+
|
|
200
|
+
// ─────────────────────────────────────────────────────────────────
|
|
201
|
+
// Statistics
|
|
202
|
+
// ─────────────────────────────────────────────────────────────────
|
|
203
|
+
|
|
204
|
+
console.log('\n8. Builder Statistics');
|
|
205
|
+
console.log('-'.repeat(40));
|
|
206
|
+
|
|
207
|
+
const stats = compoundBuilder.getStats();
|
|
208
|
+
console.log(` Total compounds: ${stats.totalCompounds}`);
|
|
209
|
+
console.log(` Total sequences: ${stats.totalSequences}`);
|
|
210
|
+
console.log(` Avg components per compound: ${stats.avgComponentsPerCompound.toFixed(1)}`);
|
|
211
|
+
console.log(` Avg symbols per sequence: ${stats.avgSymbolsPerSequence.toFixed(1)}`);
|
|
212
|
+
console.log(' Cultural distribution:');
|
|
213
|
+
for (const [tag, count] of Object.entries(stats.cultureTags)) {
|
|
214
|
+
console.log(` ${tag}: ${count}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
console.log('\n' + '='.repeat(60));
|
|
218
|
+
console.log('Compounds multiply symbol primes; sequences order them narratively');
|
|
219
|
+
console.log('='.repeat(60));
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# TinyAleph Examples
|
|
2
|
+
|
|
3
|
+
Comprehensive examples demonstrating TinyAleph's capabilities across semantic processing, cryptography, quantum simulation, mathematics, physics, and AI applications.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Run a quick example
|
|
9
|
+
node examples/01-hello-world.js
|
|
10
|
+
|
|
11
|
+
# Run category-specific examples
|
|
12
|
+
node examples/semantic/01-vocabulary.js
|
|
13
|
+
node examples/crypto/01-password-hash.js
|
|
14
|
+
node examples/scientific/01-single-qubit.js
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Demo Site
|
|
18
|
+
|
|
19
|
+
Demo site with examples is available at [https://tinyaleph.com](https://tinyaleph.com)
|
|
20
|
+
|
|
21
|
+
## Example Categories
|
|
22
|
+
|
|
23
|
+
### 🚀 Quickstart (3 examples)
|
|
24
|
+
Basic examples to get started immediately.
|
|
25
|
+
|
|
26
|
+
| File | Description |
|
|
27
|
+
|------|-------------|
|
|
28
|
+
| [01-hello-world.js](./01-hello-world.js) | Your first TinyAleph embedding |
|
|
29
|
+
| [02-basic-hash.js](./02-basic-hash.js) | Basic cryptographic hashing |
|
|
30
|
+
| [03-quantum-coin.js](./03-quantum-coin.js) | Quantum coin flip simulation |
|
|
31
|
+
|
|
32
|
+
### 🤖 AI & Machine Learning (12 examples)
|
|
33
|
+
AI applications using semantic embeddings.
|
|
34
|
+
|
|
35
|
+
| File | Description |
|
|
36
|
+
|------|-------------|
|
|
37
|
+
| [ai/01-embeddings.js](./ai/01-embeddings.js) | Text embeddings for ML |
|
|
38
|
+
| [ai/02-semantic-memory.js](./ai/02-semantic-memory.js) | Semantic memory systems |
|
|
39
|
+
| [ai/03-reasoning.js](./ai/03-reasoning.js) | Symbolic reasoning chains |
|
|
40
|
+
| [ai/04-knowledge-graph.js](./ai/04-knowledge-graph.js) | Knowledge graph construction |
|
|
41
|
+
| [ai/05-llm-integration.js](./ai/05-llm-integration.js) | LLM integration patterns |
|
|
42
|
+
| [ai/06-agent.js](./ai/06-agent.js) | AI agent implementation |
|
|
43
|
+
| [ai/07-hybrid-ai.js](./ai/07-hybrid-ai.js) | Hybrid neural-symbolic AI |
|
|
44
|
+
| [ai/08-entropy-reasoning.js](./ai/08-entropy-reasoning.js) | Entropy-guided reasoning |
|
|
45
|
+
| [ai/09-concept-learning.js](./ai/09-concept-learning.js) | Concept learning systems |
|
|
46
|
+
| [ai/10-prompt-primes.js](./ai/10-prompt-primes.js) | Prime-based prompt engineering |
|
|
47
|
+
| [ai/11-rag.js](./ai/11-rag.js) | Retrieval-augmented generation |
|
|
48
|
+
| [ai/12-neuro-symbolic.js](./ai/12-neuro-symbolic.js) | Neural-symbolic bridge |
|
|
49
|
+
|
|
50
|
+
### 📝 Semantic Processing (8 examples)
|
|
51
|
+
Text analysis and NLP applications.
|
|
52
|
+
|
|
53
|
+
| File | Description |
|
|
54
|
+
|------|-------------|
|
|
55
|
+
| [semantic/01-vocabulary.js](./semantic/01-vocabulary.js) | Word-to-prime mapping |
|
|
56
|
+
| [semantic/02-similarity.js](./semantic/02-similarity.js) | Semantic similarity metrics |
|
|
57
|
+
| [semantic/03-word-algebra.js](./semantic/03-word-algebra.js) | Word vector algebra |
|
|
58
|
+
| [semantic/04-clustering.js](./semantic/04-clustering.js) | Text clustering |
|
|
59
|
+
| [semantic/05-classification.js](./semantic/05-classification.js) | Text classification |
|
|
60
|
+
| [semantic/06-dna-encoding.js](./semantic/06-dna-encoding.js) | DNA-inspired encoding |
|
|
61
|
+
| [semantic/07-search.js](./semantic/07-search.js) | Semantic search engine |
|
|
62
|
+
| [semantic/08-qa-system.js](./semantic/08-qa-system.js) | Question answering |
|
|
63
|
+
|
|
64
|
+
### 🔐 Cryptography (5 examples)
|
|
65
|
+
Cryptographic operations and security.
|
|
66
|
+
|
|
67
|
+
| File | Description |
|
|
68
|
+
|------|-------------|
|
|
69
|
+
| [crypto/01-password-hash.js](./crypto/01-password-hash.js) | Password hashing |
|
|
70
|
+
| [crypto/02-key-derivation.js](./crypto/02-key-derivation.js) | Key derivation (PBKDF) |
|
|
71
|
+
| [crypto/03-hmac.js](./crypto/03-hmac.js) | Message authentication |
|
|
72
|
+
| [crypto/04-file-integrity.js](./crypto/04-file-integrity.js) | File integrity verification |
|
|
73
|
+
| [crypto/05-content-hash.js](./crypto/05-content-hash.js) | Content-addressable storage |
|
|
74
|
+
|
|
75
|
+
### ⚛️ Scientific Computing (7 examples)
|
|
76
|
+
Quantum computing simulation.
|
|
77
|
+
|
|
78
|
+
| File | Description |
|
|
79
|
+
|------|-------------|
|
|
80
|
+
| [scientific/01-single-qubit.js](./scientific/01-single-qubit.js) | Single qubit operations |
|
|
81
|
+
| [scientific/02-two-qubit.js](./scientific/02-two-qubit.js) | Two-qubit systems |
|
|
82
|
+
| [scientific/03-quantum-circuits.js](./scientific/03-quantum-circuits.js) | Quantum circuits |
|
|
83
|
+
| [scientific/04-measurement.js](./scientific/04-measurement.js) | Quantum measurement |
|
|
84
|
+
| [scientific/05-algorithms.js](./scientific/05-algorithms.js) | Quantum algorithms |
|
|
85
|
+
| [scientific/06-random.js](./scientific/06-random.js) | Quantum random numbers |
|
|
86
|
+
| [scientific/07-wavefunction.js](./scientific/07-wavefunction.js) | Wavefunction simulation |
|
|
87
|
+
|
|
88
|
+
### ➗ Mathematics (5 examples)
|
|
89
|
+
Mathematical foundations.
|
|
90
|
+
|
|
91
|
+
| File | Description |
|
|
92
|
+
|------|-------------|
|
|
93
|
+
| [math/01-quaternions.js](./math/01-quaternions.js) | Quaternion algebra |
|
|
94
|
+
| [math/02-octonions.js](./math/02-octonions.js) | Octonion algebra |
|
|
95
|
+
| [math/03-prime-factorization.js](./math/03-prime-factorization.js) | Prime factorization |
|
|
96
|
+
| [math/04-vector-spaces.js](./math/04-vector-spaces.js) | Vector space operations |
|
|
97
|
+
| [math/05-gaussian-primes.js](./math/05-gaussian-primes.js) | Gaussian primes |
|
|
98
|
+
|
|
99
|
+
### 🌊 Physics Simulation (6 examples)
|
|
100
|
+
Physics and dynamics.
|
|
101
|
+
|
|
102
|
+
| File | Description |
|
|
103
|
+
|------|-------------|
|
|
104
|
+
| [physics/01-oscillator.js](./physics/01-oscillator.js) | Coupled oscillators |
|
|
105
|
+
| [physics/02-lyapunov.js](./physics/02-lyapunov.js) | Lyapunov exponents |
|
|
106
|
+
| [physics/03-collapse.js](./physics/03-collapse.js) | State collapse |
|
|
107
|
+
| [physics/04-kuramoto.js](./physics/04-kuramoto.js) | Kuramoto synchronization |
|
|
108
|
+
| [physics/05-entropy.js](./physics/05-entropy.js) | Entropy analysis |
|
|
109
|
+
| [physics/06-primeon-ladder.js](./physics/06-primeon-ladder.js) | Primeon Z-ladder dynamics |
|
|
110
|
+
|
|
111
|
+
## Running Examples
|
|
112
|
+
|
|
113
|
+
### Prerequisites
|
|
114
|
+
```bash
|
|
115
|
+
npm install
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Run Individual Examples
|
|
119
|
+
```bash
|
|
120
|
+
node examples/ai/01-embeddings.js
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Run All Examples in a Category
|
|
124
|
+
```bash
|
|
125
|
+
for f in examples/ai/*.js; do node "$f"; done
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Example Structure
|
|
129
|
+
|
|
130
|
+
Each example follows a consistent structure:
|
|
131
|
+
1. **Header comment** - Description and use cases
|
|
132
|
+
2. **Setup** - Import and initialization
|
|
133
|
+
3. **Core demonstration** - Main functionality
|
|
134
|
+
4. **Key takeaways** - Summary of concepts
|
|
135
|
+
|
|
136
|
+
## Common Patterns
|
|
137
|
+
|
|
138
|
+
### Semantic Backend
|
|
139
|
+
```javascript
|
|
140
|
+
const { SemanticBackend } = require('../modular');
|
|
141
|
+
const backend = new SemanticBackend({ dimension: 16 });
|
|
142
|
+
const state = backend.textToOrderedState('hello world');
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Cryptographic Backend
|
|
146
|
+
```javascript
|
|
147
|
+
const { CryptographicBackend } = require('../modular');
|
|
148
|
+
const backend = new CryptographicBackend({ dimension: 32 });
|
|
149
|
+
const hash = backend.hash('input', 32);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Scientific Backend
|
|
153
|
+
```javascript
|
|
154
|
+
const { ScientificBackend } = require('../modular');
|
|
155
|
+
const backend = new ScientificBackend({ dimension: 2 });
|
|
156
|
+
const primes = backend.applyGate(ket0, 'H');
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Contributing Examples
|
|
160
|
+
|
|
161
|
+
1. Create new example in appropriate category directory
|
|
162
|
+
2. Follow existing naming convention: `XX-name.js`
|
|
163
|
+
3. Include comprehensive header comment
|
|
164
|
+
4. Demonstrate real-world use cases
|
|
165
|
+
5. Add key takeaways section
|
|
166
|
+
6. Update this README
|
|
167
|
+
|
|
168
|
+
## Documentation
|
|
169
|
+
|
|
170
|
+
For complete documentation, see [../docs/README.md](../docs/README.md)
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example Prime Embeddings
|
|
3
|
+
* @description Generate embeddings for text and concepts using prime resonance
|
|
4
|
+
*
|
|
5
|
+
* TinyAleph generates unique embeddings based on prime factorization and
|
|
6
|
+
* hypercomplex algebra. Unlike neural embeddings, these are:
|
|
7
|
+
* - Deterministic (same input = same embedding)
|
|
8
|
+
* - Interpretable (based on prime structure)
|
|
9
|
+
* - Order-preserving (word order affects the result)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { SemanticBackend, Hypercomplex } = require('../../modular');
|
|
13
|
+
|
|
14
|
+
// ===========================================
|
|
15
|
+
// SETUP
|
|
16
|
+
// ===========================================
|
|
17
|
+
|
|
18
|
+
const backend = new SemanticBackend({ dimension: 16 });
|
|
19
|
+
|
|
20
|
+
// ===========================================
|
|
21
|
+
// BASIC EMBEDDINGS
|
|
22
|
+
// ===========================================
|
|
23
|
+
|
|
24
|
+
console.log('TinyAleph Prime Embeddings Example');
|
|
25
|
+
console.log('===================================\n');
|
|
26
|
+
|
|
27
|
+
// Generate embeddings for words
|
|
28
|
+
const words = ['cat', 'dog', 'animal', 'tree', 'forest'];
|
|
29
|
+
const embeddings = {};
|
|
30
|
+
|
|
31
|
+
console.log('Word Embeddings:');
|
|
32
|
+
console.log('-----------------');
|
|
33
|
+
for (const word of words) {
|
|
34
|
+
embeddings[word] = backend.textToOrderedState(word);
|
|
35
|
+
console.log(`${word.padEnd(10)}: [${embeddings[word].c.slice(0, 4).map(c => c.toFixed(3)).join(', ')}, ...]`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ===========================================
|
|
39
|
+
// EMBEDDING SIMILARITY
|
|
40
|
+
// ===========================================
|
|
41
|
+
|
|
42
|
+
console.log('\n===================================');
|
|
43
|
+
console.log('Embedding Similarity (Cosine):');
|
|
44
|
+
console.log('===================================\n');
|
|
45
|
+
|
|
46
|
+
function cosineSimilarity(a, b) {
|
|
47
|
+
let dot = 0, magA = 0, magB = 0;
|
|
48
|
+
for (let i = 0; i < a.c.length; i++) {
|
|
49
|
+
dot += a.c[i] * b.c[i];
|
|
50
|
+
magA += a.c[i] * a.c[i];
|
|
51
|
+
magB += b.c[i] * b.c[i];
|
|
52
|
+
}
|
|
53
|
+
return dot / (Math.sqrt(magA) * Math.sqrt(magB));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Compare embeddings
|
|
57
|
+
const pairs = [
|
|
58
|
+
['cat', 'dog'],
|
|
59
|
+
['cat', 'animal'],
|
|
60
|
+
['tree', 'forest'],
|
|
61
|
+
['cat', 'tree'],
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
for (const [w1, w2] of pairs) {
|
|
65
|
+
const sim = cosineSimilarity(embeddings[w1], embeddings[w2]);
|
|
66
|
+
console.log(`${w1} <-> ${w2}: ${sim.toFixed(4)}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ===========================================
|
|
70
|
+
// SENTENCE EMBEDDINGS
|
|
71
|
+
// ===========================================
|
|
72
|
+
|
|
73
|
+
console.log('\n===================================');
|
|
74
|
+
console.log('Sentence Embeddings:');
|
|
75
|
+
console.log('===================================\n');
|
|
76
|
+
|
|
77
|
+
const sentences = [
|
|
78
|
+
'The cat sat on the mat',
|
|
79
|
+
'The dog sat on the mat',
|
|
80
|
+
'The mat sat on the cat', // Word order matters!
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const sentenceEmbeddings = sentences.map(s => ({
|
|
84
|
+
text: s,
|
|
85
|
+
embedding: backend.textToOrderedState(s)
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
console.log('Sentence similarities:');
|
|
89
|
+
for (let i = 0; i < sentences.length; i++) {
|
|
90
|
+
for (let j = i + 1; j < sentences.length; j++) {
|
|
91
|
+
const sim = cosineSimilarity(
|
|
92
|
+
sentenceEmbeddings[i].embedding,
|
|
93
|
+
sentenceEmbeddings[j].embedding
|
|
94
|
+
);
|
|
95
|
+
console.log(`"${sentences[i].substring(0, 20)}..." <-> "${sentences[j].substring(0, 20)}...": ${sim.toFixed(4)}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ===========================================
|
|
100
|
+
// EMBEDDING ARITHMETIC
|
|
101
|
+
// ===========================================
|
|
102
|
+
|
|
103
|
+
console.log('\n===================================');
|
|
104
|
+
console.log('Embedding Arithmetic:');
|
|
105
|
+
console.log('===================================\n');
|
|
106
|
+
|
|
107
|
+
// king - man + woman ≈ queen (classic word2vec analogy)
|
|
108
|
+
const king = backend.textToOrderedState('king');
|
|
109
|
+
const man = backend.textToOrderedState('man');
|
|
110
|
+
const woman = backend.textToOrderedState('woman');
|
|
111
|
+
const queen = backend.textToOrderedState('queen');
|
|
112
|
+
|
|
113
|
+
// Compute: king - man + woman
|
|
114
|
+
const result = Hypercomplex.zero(16);
|
|
115
|
+
for (let i = 0; i < 16; i++) {
|
|
116
|
+
result.c[i] = king.c[i] - man.c[i] + woman.c[i];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log('king - man + woman = ?');
|
|
120
|
+
console.log(`Similarity to "queen": ${cosineSimilarity(result, queen).toFixed(4)}`);
|
|
121
|
+
console.log(`Similarity to "king": ${cosineSimilarity(result, king).toFixed(4)}`);
|
|
122
|
+
console.log(`Similarity to "man": ${cosineSimilarity(result, man).toFixed(4)}`);
|
|
123
|
+
|
|
124
|
+
// ===========================================
|
|
125
|
+
// EMBEDDING STORAGE FORMAT
|
|
126
|
+
// ===========================================
|
|
127
|
+
|
|
128
|
+
console.log('\n===================================');
|
|
129
|
+
console.log('Embedding Storage:');
|
|
130
|
+
console.log('===================================\n');
|
|
131
|
+
|
|
132
|
+
// Convert to JSON for storage
|
|
133
|
+
const embedding = backend.textToOrderedState('machine learning');
|
|
134
|
+
const json = JSON.stringify(Array.from(embedding.c));
|
|
135
|
+
console.log('JSON format (for storage):');
|
|
136
|
+
console.log(json.substring(0, 80) + '...');
|
|
137
|
+
console.log(`Size: ${json.length} bytes`);
|
|
138
|
+
|
|
139
|
+
// Restore from JSON
|
|
140
|
+
const restored = Hypercomplex.zero(16);
|
|
141
|
+
restored.c = new Float64Array(JSON.parse(json));
|
|
142
|
+
console.log(`\nRestored successfully: ${cosineSimilarity(embedding, restored) === 1 ? 'YES ✓' : 'NO'}`);
|
|
143
|
+
|
|
144
|
+
// ===========================================
|
|
145
|
+
// KEY TAKEAWAYS
|
|
146
|
+
// ===========================================
|
|
147
|
+
|
|
148
|
+
console.log('\n===================================');
|
|
149
|
+
console.log('KEY TAKEAWAYS:');
|
|
150
|
+
console.log('1. textToOrderedState() generates 16-dimensional hypercomplex embeddings');
|
|
151
|
+
console.log('2. Embeddings are deterministic and reproducible');
|
|
152
|
+
console.log('3. Cosine similarity measures semantic closeness');
|
|
153
|
+
console.log('4. Word order affects embeddings (non-commutative)');
|
|
154
|
+
console.log('5. Embedding arithmetic works for analogies');
|
|
155
|
+
console.log('6. Embeddings serialize to JSON for storage');
|