@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.
Files changed (35) hide show
  1. package/README.md +187 -2
  2. package/backends/bioinformatics/binding.js +503 -0
  3. package/backends/bioinformatics/dna-computing.js +664 -0
  4. package/backends/bioinformatics/encoding.js +339 -0
  5. package/backends/bioinformatics/folding.js +454 -0
  6. package/backends/bioinformatics/genetic-code.js +269 -0
  7. package/backends/bioinformatics/index.js +522 -0
  8. package/backends/bioinformatics/transcription.js +221 -0
  9. package/backends/bioinformatics/translation.js +264 -0
  10. package/backends/index.js +25 -1
  11. package/core/compound.js +532 -0
  12. package/core/hilbert.js +454 -1
  13. package/core/index.js +106 -12
  14. package/core/inference.js +605 -0
  15. package/core/resonance.js +245 -616
  16. package/core/symbols/archetypes.js +478 -0
  17. package/core/symbols/base.js +302 -0
  18. package/core/symbols/elements.js +487 -0
  19. package/core/symbols/hieroglyphs.js +303 -0
  20. package/core/symbols/iching.js +471 -0
  21. package/core/symbols/index.js +77 -0
  22. package/core/symbols/tarot.js +211 -0
  23. package/core/symbols.js +22 -0
  24. package/docs/design/BIOINFORMATICS_BACKEND_DESIGN.md +493 -0
  25. package/docs/guide/06-symbolic-ai.md +370 -0
  26. package/docs/guide/README.md +2 -1
  27. package/docs/reference/05-symbolic-ai.md +570 -0
  28. package/docs/reference/06-bioinformatics.md +546 -0
  29. package/docs/reference/README.md +32 -2
  30. package/docs/theory/11-prgraph-memory.md +559 -0
  31. package/docs/theory/12-resonant-attention.md +661 -0
  32. package/modular.js +33 -1
  33. package/package.json +1 -1
  34. package/physics/index.js +16 -0
  35. package/physics/kuramoto-coupled-ladder.js +603 -0
@@ -0,0 +1,493 @@
1
+ # Bioinformatics Backend Design for TinyAleph
2
+
3
+ ## Executive Summary
4
+
5
+ This document specifies a bioinformatics computation backend for tinyaleph that leverages the library's prime-resonance architecture to model biological systems. The design treats DNA as a prime-encoded information channel, molecular processes as entropy-minimizing transforms, and protein dynamics as coupled oscillator systems.
6
+
7
+ **Core Thesis**: Biological computation follows the same prime-resonance principles as the tinyaleph framework:
8
+ - Genetic information encodes as prime signatures (4 nucleotides, 20 amino acids → prime basis)
9
+ - Central Dogma (DNA → RNA → Protein) maps to prime-preserving transform operators
10
+ - Molecular dynamics (folding, binding) emerge from Kuramoto-like oscillator synchronization
11
+ - Biological fitness maximization equals entropy minimization in the prime Hilbert space
12
+
13
+ ---
14
+
15
+ ## 1. Architecture Overview
16
+
17
+ ```
18
+ ┌─────────────────────────────────────────────────────────────────────┐
19
+ │ BioinformaticsBackend │
20
+ │ ┌──────────────┐ ┌──────────────┐ ┌────────────────────────────┐ │
21
+ │ │ DNA Encoder │ │ Transform │ │ Molecular Dynamics │ │
22
+ │ │ (4 primes) │◄─┤ Pipeline │◄─┤ (Kuramoto Coupling) │ │
23
+ │ └──────────────┘ └──────────────┘ └────────────────────────────┘ │
24
+ │ │ │ │ │
25
+ │ ┌──────────────┐ ┌──────────────┐ ┌────────────────────────────┐ │
26
+ │ │ RNA Encoder │ │ Codon Table │ │ Folding Energy Landscape │ │
27
+ │ │ (4 primes) │ │ (64 primes) │ │ (Entropy Surface) │ │
28
+ │ └──────────────┘ └──────────────┘ └────────────────────────────┘ │
29
+ │ │ │ │ │
30
+ │ ┌──────────────┐ ┌──────────────┐ ┌────────────────────────────┐ │
31
+ │ │ Protein │ │ Mutation │ │ Binding Affinity │ │
32
+ │ │ Encoder │ │ Operators │ │ (Resonance Scoring) │ │
33
+ │ │ (20 primes) │ │ │ │ │ │
34
+ │ └──────────────┘ └──────────────┘ └────────────────────────────┘ │
35
+ └─────────────────────────────────────────────────────────────────────┘
36
+
37
+ ┌────────────────────┼────────────────────┐
38
+ ▼ ▼ ▼
39
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
40
+ │ core/prime.js │ │ physics/kuramoto│ │ core/hilbert.js │
41
+ │ │ │ │ │ │
42
+ │ • Prime encoding│ │ • Oscillator │ │ • PrimeState │
43
+ │ • Factorization │ │ dynamics │ │ • Complex amps │
44
+ │ • Resonance │ │ • Coupling │ │ • Entropy │
45
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
46
+ ```
47
+
48
+ ### Integration with Existing Modules
49
+
50
+ | TinyAleph Module | Bioinformatics Use |
51
+ |------------------|-------------------|
52
+ | `core/prime.js` | Nucleotide/amino acid prime mapping |
53
+ | `core/hilbert.js` | Sequence states in prime Hilbert space |
54
+ | `core/resonance.js` | Binding affinity via golden ratio |
55
+ | `physics/kuramoto.js` | Protein folding dynamics |
56
+ | `physics/entropy.js` | Fitness/stability metrics |
57
+ | `physics/sync-models.js` | Multi-domain protein coupling |
58
+
59
+ ---
60
+
61
+ ## 2. Prime Encoding Schemes
62
+
63
+ ### 2.1 Nucleotide Prime Basis
64
+
65
+ ```javascript
66
+ const NUCLEOTIDE_PRIMES = {
67
+ 'A': 7, // Adenine (purine)
68
+ 'T': 2, // Thymine (pyrimidine)
69
+ 'G': 11, // Guanine (purine)
70
+ 'C': 3, // Cytosine (pyrimidine)
71
+ 'U': 5, // Uracil (RNA)
72
+ };
73
+
74
+ // Watson-Crick pairing: complementary bases have same prime product
75
+ // A-T: 7*2 = 14, G-C: 11*3 = 33
76
+ ```
77
+
78
+ ### 2.2 Amino Acid Prime Basis
79
+
80
+ ```javascript
81
+ const AMINO_ACID_PRIMES = {
82
+ // Hydrophobic (small primes)
83
+ 'G': 23, 'A': 29, 'V': 31, 'L': 37, 'I': 41, 'M': 43,
84
+ // Aromatic
85
+ 'F': 47, 'W': 53, 'Y': 59,
86
+ // Polar
87
+ 'S': 61, 'T': 67, 'C': 71, 'N': 73, 'Q': 79,
88
+ // Charged
89
+ 'K': 83, 'R': 89, 'H': 97, 'D': 101, 'E': 103,
90
+ // Special
91
+ 'P': 107, '*': 109
92
+ };
93
+ ```
94
+
95
+ ---
96
+
97
+ ## 3. Biological Transform Operators
98
+
99
+ ### 3.1 Central Dogma Pipeline
100
+
101
+ ```
102
+ DNA ──[Transcription]──► RNA ──[Translation]──► Protein ──[Folding]──► Structure
103
+ │ │ │ │
104
+ ▼ ▼ ▼ ▼
105
+ [2,3,7,11] [3,5,7,11] [23-109 range] [Phase array]
106
+ ```
107
+
108
+ ### 3.2 Transform Summary
109
+
110
+ | Transform | Input | Output | Entropy Change |
111
+ |-----------|-------|--------|----------------|
112
+ | Transcription | DNA primes | RNA primes | +0.01×len |
113
+ | Translation | RNA primes | Protein primes | -codons×log₂(3) |
114
+ | Folding | Protein primes | Phase array | →0 (minimized) |
115
+ | Binding | 2 molecules | Affinity score | -ΔG/RT |
116
+
117
+ ---
118
+
119
+ ## 4. Molecular Dynamics via Oscillator Coupling
120
+
121
+ ### 4.1 Protein Folding as Kuramoto Synchronization
122
+
123
+ Each amino acid residue becomes an oscillator with:
124
+ - **Natural frequency**: `f(p) = 1 + log(p)/10` (from prime value)
125
+ - **Coupling**: Contact propensity matrix based on:
126
+ - Prime resonance (golden ratio proximity)
127
+ - Hydrophobicity (smaller primes attract)
128
+ - Electrostatics (charged primes repel/attract)
129
+
130
+ **Folded state** = High order parameter (synchronized oscillators)
131
+
132
+ ### 4.2 Binding as Multi-System Coupling
133
+
134
+ Protein-ligand binding uses `MultiSystemCoupling`:
135
+ - Receptor and ligand as separate oscillator banks
136
+ - Cross-coupling from pairwise prime resonance
137
+ - Docking score from inter-system coherence
138
+
139
+ ---
140
+
141
+ ## 5. BioinformaticsBackend Class
142
+
143
+ ### 5.1 Interface Implementation
144
+
145
+ ```javascript
146
+ class BioinformaticsBackend extends Backend {
147
+ // Required by Backend interface
148
+ encode(input) // Sequence string → prime array
149
+ decode(primes) // Prime array → sequence string
150
+ primesToState(primes) // Primes → Hypercomplex state
151
+ primesToFrequencies(primes)// Primes → oscillator frequencies
152
+ applyTransform(primes, t) // Apply biological transform
153
+ getTransforms() // List available transforms
154
+ getPrimes() // Get biological prime set
155
+
156
+ // Bioinformatics-specific methods
157
+ transcribe(dna) // DNA → RNA
158
+ translate(rna) // RNA → Protein
159
+ express(dna) // DNA → Protein (full pipeline)
160
+ fold(protein) // Protein → 3D structure
161
+ mutate(seq, mutation) // Apply mutation
162
+ align(seq1, seq2) // Sequence alignment
163
+ bindingAffinity(mol1, mol2)// Compute binding score
164
+ }
165
+ ```
166
+
167
+ ### 5.2 Transform Registry
168
+
169
+ ```javascript
170
+ const BIOINFORMATICS_TRANSFORMS = [
171
+ { type: 'transcription', name: 'DNA→RNA' },
172
+ { type: 'translation', name: 'RNA→Protein' },
173
+ { type: 'complement', name: 'DNA complement' },
174
+ { type: 'reverse_complement', name: 'Reverse complement' },
175
+ { type: 'fold', name: 'Protein folding' },
176
+ { type: 'mutation', mutationType: 'point', name: 'Point mutation' },
177
+ { type: 'mutation', mutationType: 'insertion', name: 'Insertion' },
178
+ { type: 'mutation', mutationType: 'deletion', name: 'Deletion' },
179
+ ];
180
+ ```
181
+
182
+ ---
183
+
184
+ ## 6. Usage Examples
185
+
186
+ ### 6.1 Basic Usage
187
+
188
+ ```javascript
189
+ const { createEngine, BioinformaticsBackend } = require('@aleph-ai/tinyaleph');
190
+
191
+ // Create bioinformatics engine
192
+ const config = { dimension: 32 };
193
+ const engine = createEngine('bioinformatics', config);
194
+
195
+ // Encode and process DNA sequence
196
+ const result = engine.run('ATGCGATCGATCG');
197
+
198
+ console.log('Input primes:', result.inputPrimes);
199
+ console.log('Entropy:', result.entropy);
200
+ console.log('Coherence:', result.coherence);
201
+ ```
202
+
203
+ ### 6.2 Gene Expression
204
+
205
+ ```javascript
206
+ const backend = new BioinformaticsBackend();
207
+
208
+ // DNA sequence
209
+ const dna = backend.encode('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGA');
210
+
211
+ // Express gene
212
+ const rna = backend.transcribe(dna);
213
+ const protein = backend.translate(rna);
214
+
215
+ console.log('DNA primes:', dna);
216
+ console.log('RNA primes:', rna);
217
+ console.log('Protein primes:', protein);
218
+ console.log('Protein sequence:', backend.decode(protein));
219
+ ```
220
+
221
+ ### 6.3 Protein Folding
222
+
223
+ ```javascript
224
+ const backend = new BioinformaticsBackend();
225
+
226
+ // Encode protein
227
+ const proteinPrimes = backend.encode('MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSH');
228
+
229
+ // Fold protein
230
+ const foldResult = backend.fold(proteinPrimes);
231
+
232
+ console.log('Order parameter:', foldResult.orderParameter);
233
+ console.log('Secondary structure:', foldResult.structure.map(s => s.secondaryStructure));
234
+ console.log('Contacts:', foldResult.contacts.length);
235
+ console.log('Free energy:', foldResult.foldingFreeEnergy);
236
+ ```
237
+
238
+ ### 6.4 Binding Affinity Screening
239
+
240
+ ```javascript
241
+ const backend = new BioinformaticsBackend();
242
+ const calculator = new BindingAffinityCalculator();
243
+
244
+ // Target protein
245
+ const target = backend.encode('MKTAYIAKQRQISFVKSHFSRQLEERLGLIEVQAPILSRVGDGTQDNLSGAEKAVQVKVKALPDAQFEVVHSLAKWKRQQIA');
246
+
247
+ // Ligand library
248
+ const ligands = [
249
+ { id: 'aspirin', primes: backend.encode('CCOC1=CC=CC=C1OC') },
250
+ { id: 'caffeine', primes: backend.encode('CN1C=NC2=C1C=NC=N2') },
251
+ { id: 'glucose', primes: backend.encode('OC1OC(CO)C(O)C(O)C1O') }
252
+ ];
253
+
254
+ // Screen
255
+ const results = calculator.screenLibrary(target, ligands);
256
+ console.log('Top binder:', results[0].id, 'affinity:', results[0].affinity);
257
+ ```
258
+
259
+ ### 6.5 Mutation Analysis
260
+
261
+ ```javascript
262
+ const backend = new BioinformaticsBackend();
263
+ const mutator = new PointMutationOperator();
264
+
265
+ // Original sequence
266
+ const original = backend.encode('ATGGCCATTGTAATG');
267
+
268
+ // Apply mutation at position 3
269
+ const mutated = mutator.apply(original, 3, NUCLEOTIDE_PRIMES['T']);
270
+
271
+ // Classify effect
272
+ const effect = mutator.classify(original, mutated, 3);
273
+ console.log('Mutation effect:', effect); // 'synonymous', 'missense', or 'nonsense'
274
+ ```
275
+
276
+ ### 6.6 Sequence Alignment via Oscillator Sync
277
+
278
+ ```javascript
279
+ const backend = new BioinformaticsBackend();
280
+
281
+ const seq1 = backend.encode('MVLSPADKTNVKAAW');
282
+ const seq2 = backend.encode('MVHLTPEEKSAVTAL');
283
+
284
+ const alignment = backend.align(seq1, seq2);
285
+
286
+ console.log('Alignment coherence:', alignment.coherence);
287
+ console.log('Phase alignment:', alignment.alignment);
288
+ ```
289
+
290
+ ---
291
+
292
+ ## 7. Integration with AlephEngine
293
+
294
+ ### 7.1 Engine Configuration
295
+
296
+ ```javascript
297
+ function createEngine(backendType, config = {}) {
298
+ let backend;
299
+
300
+ switch (backendType.toLowerCase()) {
301
+ case 'bioinformatics':
302
+ case 'bio':
303
+ case 'dna':
304
+ backend = new BioinformaticsBackend(config);
305
+ break;
306
+ // ... existing backends
307
+ }
308
+
309
+ return new AlephEngine(backend, config.engineOptions || {});
310
+ }
311
+ ```
312
+
313
+ ### 7.2 Field-Based Biological Computation
314
+
315
+ The AlephEngine's field-based computation naturally models biological processes:
316
+
317
+ 1. **Excitation**: Input sequence excites oscillators (encode)
318
+ 2. **Evolution**: Kuramoto dynamics simulate molecular behavior
319
+ 3. **Sampling**: Coherent frames capture stable conformations
320
+ 4. **Decoding**: Convert oscillator state back to biological output
321
+
322
+ This parallels how biological systems:
323
+ - Store information in molecular structure
324
+ - Evolve through thermodynamic processes
325
+ - Settle into stable energy minima
326
+ - Express functional outputs
327
+
328
+ ---
329
+
330
+ ## 8. Advanced Features
331
+
332
+ ### 8.1 Phylogenetic Analysis via Entanglement Graph
333
+
334
+ ```javascript
335
+ // Use PrimeEntanglementGraph for sequence relationships
336
+ const graph = new PrimeEntanglementGraph(allSequencePrimes);
337
+
338
+ // Record co-evolution
339
+ for (const [seq1, seq2] of sequencePairs) {
340
+ const primes1 = backend.encode(seq1);
341
+ const primes2 = backend.encode(seq2);
342
+ const similarity = backend.similarity(primes1, primes2);
343
+ graph.observe(primes1, primes2, similarity);
344
+ }
345
+
346
+ // Build phylogenetic tree
347
+ const tree = graph.toAdjacencyMatrix(sequencePrimes);
348
+ ```
349
+
350
+ ### 8.2 Evolutionary Dynamics
351
+
352
+ ```javascript
353
+ // Model evolution as entropy-driven process
354
+ const evolution = new EntropyDrivenEvolution(
355
+ PrimeState.fromPrimes(genomePrimes),
356
+ {
357
+ lambda: 0.01, // Mutation rate
358
+ rStable: 0.9 // Fitness threshold
359
+ }
360
+ );
361
+
362
+ // Evolve population
363
+ const result = evolution.evolveUntilCollapse(10000);
364
+ console.log('Generations:', result.steps);
365
+ console.log('Final fitness:', result.probability);
366
+ ```
367
+
368
+ ### 8.3 Multi-Domain Protein Dynamics
369
+
370
+ ```javascript
371
+ // Use SmallWorldKuramoto for allosteric effects
372
+ const domain1 = proteinPrimes.slice(0, 100);
373
+ const domain2 = proteinPrimes.slice(100, 200);
374
+ const linker = proteinPrimes.slice(200, 220);
375
+
376
+ const multiDomain = new SmallWorldKuramoto(
377
+ [...domain1, ...linker, ...domain2].map(p => primeToFrequency(p)),
378
+ 4, // neighbors
379
+ 0.1, // rewiring probability
380
+ 0.3 // coupling
381
+ );
382
+
383
+ // Simulate allostery
384
+ multiDomain.evolve(1000, 0.01);
385
+ const allostericCoupling = multiDomain.smallWorldCoefficient();
386
+ ```
387
+
388
+ ---
389
+
390
+ ## 9. File Structure
391
+
392
+ ```
393
+ backends/
394
+ └── bioinformatics/
395
+ ├── index.js # Main BioinformaticsBackend class
396
+ ├── encoding.js # Nucleotide/AA prime mappings
397
+ ├── transcription.js # DNA → RNA operator
398
+ ├── translation.js # RNA → Protein operator
399
+ ├── mutation.js # Mutation operators
400
+ ├── folding.js # Kuramoto-based folding
401
+ ├── binding.js # Affinity calculator
402
+ ├── alignment.js # Sequence alignment
403
+ └── genetic-code.js # Codon tables
404
+ ```
405
+
406
+ ---
407
+
408
+ ## 10. Testing Strategy
409
+
410
+ ```javascript
411
+ // Unit tests for encoding
412
+ test('nucleotide encoding', () => {
413
+ const backend = new BioinformaticsBackend();
414
+ expect(backend.encode('ATGC')).toEqual([7, 2, 11, 3]);
415
+ });
416
+
417
+ // Integration tests for expression
418
+ test('gene expression pipeline', () => {
419
+ const backend = new BioinformaticsBackend();
420
+ const dna = backend.encode('ATGTTT'); // Met-Phe
421
+ const protein = backend.express(dna);
422
+ expect(backend.decode(protein)).toBe('MF');
423
+ });
424
+
425
+ // Folding convergence test
426
+ test('folding converges', () => {
427
+ const backend = new BioinformaticsBackend();
428
+ const protein = backend.encode('MVLSPADKTNVKAAW');
429
+ const result = backend.fold(protein);
430
+ expect(result.orderParameter).toBeGreaterThan(0.8);
431
+ });
432
+ ```
433
+
434
+ ---
435
+
436
+ ## 11. Performance Considerations
437
+
438
+ | Operation | Complexity | Notes |
439
+ |-----------|------------|-------|
440
+ | Encoding | O(n) | Linear in sequence length |
441
+ | Transcription | O(n) | Simple substitution |
442
+ | Translation | O(n) | Codon lookup |
443
+ | Folding | O(n²×s) | n residues, s steps |
444
+ | Binding | O(m×n) | m×n pairwise interactions |
445
+ | Alignment | O(m×n×s) | Multi-system coupling |
446
+
447
+ For long sequences (>1000 residues), consider:
448
+ - Sparse contact matrices
449
+ - Hierarchical folding (domains first)
450
+ - GPU acceleration for Kuramoto integration
451
+
452
+ ---
453
+
454
+ ## 12. Future Extensions
455
+
456
+ ### 12.1 CRISPR Editing Simulation
457
+ Model guide RNA binding and Cas9 cleavage using resonance scoring.
458
+
459
+ ### 12.2 Metabolic Networks
460
+ Extend to metabolic pathways as coupled reaction oscillators.
461
+
462
+ ### 12.3 Epigenetics
463
+ Add methylation states as phase modifications to nucleotide oscillators.
464
+
465
+ ### 12.4 Drug Design
466
+ Use inverse folding to design sequences with target binding properties.
467
+
468
+ ---
469
+
470
+ ## 13. Summary
471
+
472
+ The BioinformaticsBackend provides a novel computational model for biological systems based on tinyaleph's prime-resonance framework:
473
+
474
+ | Biological Concept | Prime-Resonance Analog |
475
+ |--------------------|------------------------|
476
+ | Genetic information | Prime signatures |
477
+ | Base pairing | Prime product symmetry |
478
+ | Gene expression | Entropy-reducing transforms |
479
+ | Protein folding | Oscillator synchronization |
480
+ | Molecular binding | Golden ratio resonance |
481
+ | Evolution | Entropy-driven dynamics |
482
+
483
+ This approach offers:
484
+ 1. **Unified framework** for sequence, structure, and dynamics
485
+ 2. **Physical grounding** via oscillator physics
486
+ 3. **Information-theoretic** metrics for biological function
487
+ 4. **Seamless integration** with existing tinyaleph infrastructure
488
+
489
+ ---
490
+
491
+ *Design document version 1.0*
492
+ *Author: TinyAleph Architecture Team*
493
+ *Date: 2026-01-08*