@aleph-ai/tinyaleph 1.5.7 → 1.6.1
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/emotion.js +565 -0
- package/core/gravity.js +714 -0
- package/core/hilbert.js +506 -3
- package/core/index.js +132 -4
- package/core/nonlocal.js +744 -0
- package/core/oracle.js +662 -0
- 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/book-operators-demo.js +155 -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/emotion-demo.js +200 -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/gravity-demo.js +190 -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/nonlocal-demo.js +237 -0
- package/examples/oracle-demo.js +204 -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/quantum/01-prime-hunter.js +79 -0
- package/examples/quantum/02-entanglement-demo.js +79 -0
- package/examples/quantum/03-wave-analysis.js +63 -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 +427 -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/package.json +8 -3
- package/physics/alk-kuramoto.js +817 -0
- package/physics/index.js +23 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example DNA Encoding
|
|
3
|
+
* @description Encode DNA sequences as prime-resonant semantic states
|
|
4
|
+
*
|
|
5
|
+
* This example shows how TinyAleph encodes DNA sequences using prime numbers.
|
|
6
|
+
* Each nucleotide maps to a specific prime:
|
|
7
|
+
* A (Adenine) → 7 (purines get higher primes)
|
|
8
|
+
* T (Thymine) → 2 (lowest energy, pairs with A)
|
|
9
|
+
* G (Guanine) → 11 (highest prime, strongest purine)
|
|
10
|
+
* C (Cytosine) → 3 (pairs with G)
|
|
11
|
+
* U (Uracil) → 5 (RNA only, replaces T)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { BioinformaticsBackend } = require('../../modular');
|
|
15
|
+
|
|
16
|
+
// Nucleotide prime mapping
|
|
17
|
+
const NUCLEOTIDE_PRIMES = { A: 7, T: 2, G: 11, C: 3, U: 5 };
|
|
18
|
+
|
|
19
|
+
// ===========================================
|
|
20
|
+
// SETUP
|
|
21
|
+
// ===========================================
|
|
22
|
+
|
|
23
|
+
// Create a bioinformatics backend
|
|
24
|
+
const backend = new BioinformaticsBackend();
|
|
25
|
+
|
|
26
|
+
// ===========================================
|
|
27
|
+
// EXAMPLE CODE
|
|
28
|
+
// ===========================================
|
|
29
|
+
|
|
30
|
+
// A sample DNA sequence (start codon + some bases)
|
|
31
|
+
const dnaSequence = 'ATGCGATCGATCG';
|
|
32
|
+
|
|
33
|
+
// Encode the DNA sequence - returns prime array
|
|
34
|
+
const primes = backend.encode(dnaSequence);
|
|
35
|
+
|
|
36
|
+
// Convert primes to hypercomplex state
|
|
37
|
+
const state = backend.primesToState(primes);
|
|
38
|
+
|
|
39
|
+
// ===========================================
|
|
40
|
+
// OUTPUT
|
|
41
|
+
// ===========================================
|
|
42
|
+
|
|
43
|
+
console.log('TinyAleph DNA Encoding Example');
|
|
44
|
+
console.log('==============================\n');
|
|
45
|
+
|
|
46
|
+
console.log('DNA Sequence:', dnaSequence);
|
|
47
|
+
console.log('Sequence Length:', dnaSequence.length, 'nucleotides');
|
|
48
|
+
|
|
49
|
+
console.log('\nNucleotide → Prime Mapping:');
|
|
50
|
+
console.log(' A (Adenine) → 7');
|
|
51
|
+
console.log(' T (Thymine) → 2');
|
|
52
|
+
console.log(' G (Guanine) → 11');
|
|
53
|
+
console.log(' C (Cytosine) → 3');
|
|
54
|
+
|
|
55
|
+
console.log('\nPrime Encoding:');
|
|
56
|
+
for (let i = 0; i < dnaSequence.length; i++) {
|
|
57
|
+
console.log(` ${dnaSequence[i]} → ${primes[i]}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log('\nHypercomplex State (sedenion components):');
|
|
61
|
+
const components = state.c; // Hypercomplex uses .c for components
|
|
62
|
+
console.log(' Real part:', components[0].toFixed(6));
|
|
63
|
+
console.log(' i:', components[1].toFixed(6));
|
|
64
|
+
console.log(' j:', components[2].toFixed(6));
|
|
65
|
+
console.log(' k:', components[3].toFixed(6));
|
|
66
|
+
console.log(' (remaining 12 dimensions...)\n');
|
|
67
|
+
|
|
68
|
+
// Verify decoding works
|
|
69
|
+
const decoded = backend.decode(primes);
|
|
70
|
+
console.log('Decoded sequence:', decoded);
|
|
71
|
+
console.log('Round-trip match:', decoded === dnaSequence ? 'YES ✓' : 'NO ✗');
|
|
72
|
+
|
|
73
|
+
// ===========================================
|
|
74
|
+
// COMPLEMENTARY STRAND
|
|
75
|
+
// ===========================================
|
|
76
|
+
|
|
77
|
+
console.log('\n==============================');
|
|
78
|
+
console.log('COMPLEMENTARY BASE PAIRING:');
|
|
79
|
+
console.log('==============================\n');
|
|
80
|
+
|
|
81
|
+
// Compute complement manually (A↔T, G↔C)
|
|
82
|
+
const COMPLEMENT = { 'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G' };
|
|
83
|
+
const complement = dnaSequence.split('').map(b => COMPLEMENT[b] || b).join('');
|
|
84
|
+
|
|
85
|
+
console.log('Original: 5\'-' + dnaSequence + '-3\'');
|
|
86
|
+
console.log('Complement: 3\'-' + complement + '-5\'');
|
|
87
|
+
|
|
88
|
+
// In DNA, A pairs with T, G pairs with C
|
|
89
|
+
console.log('\nBase pairing (prime products):');
|
|
90
|
+
for (let i = 0; i < Math.min(5, dnaSequence.length); i++) {
|
|
91
|
+
const base1 = dnaSequence[i];
|
|
92
|
+
const base2 = complement[i];
|
|
93
|
+
const p1 = NUCLEOTIDE_PRIMES[base1];
|
|
94
|
+
const p2 = NUCLEOTIDE_PRIMES[base2];
|
|
95
|
+
console.log(` ${base1}-${base2}: ${p1} × ${p2} = ${p1 * p2}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ===========================================
|
|
99
|
+
// KEY TAKEAWAYS
|
|
100
|
+
// ===========================================
|
|
101
|
+
|
|
102
|
+
console.log('\n==============================');
|
|
103
|
+
console.log('KEY TAKEAWAYS:');
|
|
104
|
+
console.log('1. DNA nucleotides map to prime numbers (2, 3, 5, 7, 11)');
|
|
105
|
+
console.log('2. Prime encoding preserves sequence structure');
|
|
106
|
+
console.log('3. Hypercomplex states enable mathematical operations');
|
|
107
|
+
console.log('4. Complementary bases have related prime products');
|
|
108
|
+
console.log('5. Round-trip encoding/decoding is lossless');
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example Central Dogma
|
|
3
|
+
* @description DNA → RNA → Protein: The molecular biology central dogma
|
|
4
|
+
*
|
|
5
|
+
* This example demonstrates how TinyAleph models the central dogma
|
|
6
|
+
* of molecular biology as entropy-reducing transforms:
|
|
7
|
+
* 1. Transcription: DNA → mRNA (T→U substitution)
|
|
8
|
+
* 2. Translation: mRNA → Protein (codon→amino acid)
|
|
9
|
+
*
|
|
10
|
+
* Each step reduces entropy by collapsing possibility space.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { BioinformaticsBackend } = require('../../modular');
|
|
14
|
+
|
|
15
|
+
// ===========================================
|
|
16
|
+
// SETUP
|
|
17
|
+
// ===========================================
|
|
18
|
+
|
|
19
|
+
const backend = new BioinformaticsBackend();
|
|
20
|
+
|
|
21
|
+
// A sample gene: Start codon (ATG) + coding sequence + Stop codon (TAA)
|
|
22
|
+
const gene = 'ATGCATGCATACTAA';
|
|
23
|
+
|
|
24
|
+
// ===========================================
|
|
25
|
+
// TRANSCRIPTION: DNA → mRNA
|
|
26
|
+
// ===========================================
|
|
27
|
+
|
|
28
|
+
console.log('TinyAleph Central Dogma Example');
|
|
29
|
+
console.log('================================\n');
|
|
30
|
+
|
|
31
|
+
console.log('STEP 1: TRANSCRIPTION (DNA → mRNA)');
|
|
32
|
+
console.log('----------------------------------\n');
|
|
33
|
+
|
|
34
|
+
console.log('DNA Template: 5\'-' + gene + '-3\'');
|
|
35
|
+
|
|
36
|
+
// Encode DNA to primes
|
|
37
|
+
const dnaPrimes = backend.encode(gene);
|
|
38
|
+
|
|
39
|
+
// Transcribe using the backend's transcription operator
|
|
40
|
+
const transcribeResult = backend.transcribe(dnaPrimes, { force: true });
|
|
41
|
+
const mRNAPrimes = transcribeResult.success ? transcribeResult.rna : dnaPrimes;
|
|
42
|
+
|
|
43
|
+
// Decode mRNA back to sequence
|
|
44
|
+
const mRNA = backend.decode(mRNAPrimes);
|
|
45
|
+
|
|
46
|
+
console.log('mRNA Strand: 5\'-' + mRNA + '-3\'');
|
|
47
|
+
console.log('\nTransform: T (Thymine) → U (Uracil)');
|
|
48
|
+
|
|
49
|
+
// Show the substitution
|
|
50
|
+
let changes = [];
|
|
51
|
+
for (let i = 0; i < gene.length; i++) {
|
|
52
|
+
if (gene[i] === 'T' && mRNA[i] === 'U') {
|
|
53
|
+
changes.push(i);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
console.log('Substitutions at positions:', changes.join(', '));
|
|
57
|
+
|
|
58
|
+
// ===========================================
|
|
59
|
+
// TRANSLATION: mRNA → Protein
|
|
60
|
+
// ===========================================
|
|
61
|
+
|
|
62
|
+
console.log('\n\nSTEP 2: TRANSLATION (mRNA → Protein)');
|
|
63
|
+
console.log('-------------------------------------\n');
|
|
64
|
+
|
|
65
|
+
// Extract codons from mRNA
|
|
66
|
+
const codons = [];
|
|
67
|
+
for (let i = 0; i < mRNA.length - 2; i += 3) {
|
|
68
|
+
codons.push(mRNA.slice(i, i + 3));
|
|
69
|
+
}
|
|
70
|
+
console.log('Codons:', codons.join(' | '));
|
|
71
|
+
|
|
72
|
+
// Translate mRNA to protein using the backend
|
|
73
|
+
const translateResult = backend.translate(mRNAPrimes);
|
|
74
|
+
const proteinPrimes = translateResult.success ? translateResult.protein : [];
|
|
75
|
+
const protein = backend.decode(proteinPrimes);
|
|
76
|
+
|
|
77
|
+
console.log('Amino Acids:', protein.split('').join(' | '));
|
|
78
|
+
|
|
79
|
+
console.log('\nCodon → Amino Acid mapping:');
|
|
80
|
+
for (let i = 0; i < codons.length; i++) {
|
|
81
|
+
const aa = protein[i] || '*';
|
|
82
|
+
const aaName = {
|
|
83
|
+
'M': 'Methionine (Start)',
|
|
84
|
+
'H': 'Histidine',
|
|
85
|
+
'A': 'Alanine',
|
|
86
|
+
'Y': 'Tyrosine',
|
|
87
|
+
'*': 'Stop'
|
|
88
|
+
}[aa] || aa;
|
|
89
|
+
console.log(` ${codons[i]} → ${aa} (${aaName})`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ===========================================
|
|
93
|
+
// GENE EXPRESSION: Full Pipeline
|
|
94
|
+
// ===========================================
|
|
95
|
+
|
|
96
|
+
console.log('\n\nFULL GENE EXPRESSION');
|
|
97
|
+
console.log('--------------------\n');
|
|
98
|
+
|
|
99
|
+
// Use the express() function to go from DNA directly to protein
|
|
100
|
+
const expressResult = backend.express(dnaPrimes);
|
|
101
|
+
const expressedProtein = expressResult.success ? expressResult.sequence : '';
|
|
102
|
+
|
|
103
|
+
console.log('DNA:', gene);
|
|
104
|
+
console.log(' ↓ (transcription)');
|
|
105
|
+
console.log('mRNA:', mRNA);
|
|
106
|
+
console.log(' ↓ (translation)');
|
|
107
|
+
console.log('Protein:', expressedProtein || '[No protein - no start codon found]');
|
|
108
|
+
|
|
109
|
+
// ===========================================
|
|
110
|
+
// ENTROPY ANALYSIS
|
|
111
|
+
// ===========================================
|
|
112
|
+
|
|
113
|
+
console.log('\n\nENTROPY REDUCTION ANALYSIS');
|
|
114
|
+
console.log('--------------------------\n');
|
|
115
|
+
|
|
116
|
+
// Calculate effective entropy at each step
|
|
117
|
+
const dnaEntropy = gene.length * Math.log2(4); // 4 possible nucleotides
|
|
118
|
+
const rnaEntropy = mRNA.length * Math.log2(4); // 4 possible nucleotides
|
|
119
|
+
const proteinLength = expressedProtein ? expressedProtein.length : 0;
|
|
120
|
+
const proteinEntropy = proteinLength * Math.log2(20); // 20 amino acids
|
|
121
|
+
|
|
122
|
+
console.log('Information content:');
|
|
123
|
+
console.log(` DNA: ${gene.length} nucleotides × 2 bits = ${dnaEntropy.toFixed(1)} bits`);
|
|
124
|
+
console.log(` mRNA: ${mRNA.length} nucleotides × 2 bits = ${rnaEntropy.toFixed(1)} bits`);
|
|
125
|
+
console.log(` Protein: ${proteinLength} amino acids × 4.32 bits = ${proteinEntropy.toFixed(1)} bits`);
|
|
126
|
+
|
|
127
|
+
if (proteinLength > 0) {
|
|
128
|
+
const compression = (1 - proteinEntropy / dnaEntropy) * 100;
|
|
129
|
+
console.log(`\nEffective compression: ${compression.toFixed(1)}%`);
|
|
130
|
+
console.log('Translation reduces entropy by mapping 64 codons → 20 amino acids');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ===========================================
|
|
134
|
+
// PRIME ENCODING VIEW
|
|
135
|
+
// ===========================================
|
|
136
|
+
|
|
137
|
+
console.log('\n\nPRIME ENCODING VIEW');
|
|
138
|
+
console.log('-------------------\n');
|
|
139
|
+
|
|
140
|
+
const dnaState = backend.primesToState(dnaPrimes);
|
|
141
|
+
const rnaState = backend.primesToState(mRNAPrimes);
|
|
142
|
+
|
|
143
|
+
console.log('Hypercomplex state norms:');
|
|
144
|
+
console.log(` DNA: ${dnaState.norm().toFixed(4)}`);
|
|
145
|
+
console.log(` mRNA: ${rnaState.norm().toFixed(4)}`);
|
|
146
|
+
|
|
147
|
+
if (proteinPrimes.length > 0) {
|
|
148
|
+
const proteinState = backend.primesToState(proteinPrimes);
|
|
149
|
+
console.log(` Protein: ${proteinState.norm().toFixed(4)}`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ===========================================
|
|
153
|
+
// KEY TAKEAWAYS
|
|
154
|
+
// ===========================================
|
|
155
|
+
|
|
156
|
+
console.log('\n================================');
|
|
157
|
+
console.log('KEY TAKEAWAYS:');
|
|
158
|
+
console.log('1. Transcription: DNA→mRNA is a T→U substitution transform');
|
|
159
|
+
console.log('2. Translation: mRNA→Protein is codon→amino acid mapping');
|
|
160
|
+
console.log('3. Each step is entropy-reducing (collapses possibility space)');
|
|
161
|
+
console.log('4. 64 codons encode 20 amino acids + stop (redundancy)');
|
|
162
|
+
console.log('5. Prime encoding preserves information through transforms');
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example Protein Folding
|
|
3
|
+
* @description Simulate protein folding using Kuramoto oscillator synchronization
|
|
4
|
+
*
|
|
5
|
+
* This example demonstrates how TinyAleph models protein folding as a
|
|
6
|
+
* synchronization problem. Each amino acid is treated as an oscillator,
|
|
7
|
+
* and folding emerges from oscillator coupling based on:
|
|
8
|
+
* - Hydrophobic interactions (drives core formation)
|
|
9
|
+
* - Electrostatic attraction/repulsion
|
|
10
|
+
* - Prime resonance (hypercomplex coupling)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { BioinformaticsBackend } = require('../../modular');
|
|
14
|
+
|
|
15
|
+
// ===========================================
|
|
16
|
+
// SETUP
|
|
17
|
+
// ===========================================
|
|
18
|
+
|
|
19
|
+
const backend = new BioinformaticsBackend();
|
|
20
|
+
|
|
21
|
+
// A short protein sequence with various amino acid types
|
|
22
|
+
// W, L, I, F, V = hydrophobic (want to be in core)
|
|
23
|
+
// K, R, D, E = charged (on surface)
|
|
24
|
+
// M = start codon amino acid
|
|
25
|
+
const proteinSeq = 'MWLKFVEIRLLQ';
|
|
26
|
+
|
|
27
|
+
// ===========================================
|
|
28
|
+
// AMINO ACID PROPERTIES
|
|
29
|
+
// ===========================================
|
|
30
|
+
|
|
31
|
+
console.log('TinyAleph Protein Folding Example');
|
|
32
|
+
console.log('==================================\n');
|
|
33
|
+
|
|
34
|
+
console.log('Protein Sequence:', proteinSeq.split('').join('-'));
|
|
35
|
+
console.log('Length:', proteinSeq.length, 'amino acids\n');
|
|
36
|
+
|
|
37
|
+
// Classify amino acids
|
|
38
|
+
const hydrophobic = ['L', 'I', 'V', 'F', 'W', 'M', 'A'];
|
|
39
|
+
const positiveCharge = ['K', 'R', 'H'];
|
|
40
|
+
const negativeCharge = ['D', 'E'];
|
|
41
|
+
|
|
42
|
+
console.log('Amino Acid Properties:');
|
|
43
|
+
console.log('----------------------');
|
|
44
|
+
for (let i = 0; i < proteinSeq.length; i++) {
|
|
45
|
+
const aa = proteinSeq[i];
|
|
46
|
+
let type = 'polar';
|
|
47
|
+
if (hydrophobic.includes(aa)) type = 'hydrophobic';
|
|
48
|
+
else if (positiveCharge.includes(aa)) type = 'positive (+)';
|
|
49
|
+
else if (negativeCharge.includes(aa)) type = 'negative (-)';
|
|
50
|
+
console.log(` ${i}: ${aa} - ${type}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ===========================================
|
|
54
|
+
// FOLD PROTEIN
|
|
55
|
+
// ===========================================
|
|
56
|
+
|
|
57
|
+
console.log('\n\nFOLDING SIMULATION (Kuramoto Model)');
|
|
58
|
+
console.log('------------------------------------\n');
|
|
59
|
+
|
|
60
|
+
// Encode protein and fold
|
|
61
|
+
const proteinPrimes = backend.encode(proteinSeq);
|
|
62
|
+
const foldResult = backend.foldProtein(proteinPrimes);
|
|
63
|
+
|
|
64
|
+
console.log('Folding result:');
|
|
65
|
+
console.log(` Success: ${foldResult.success}`);
|
|
66
|
+
console.log(` Final synchronization: ${(foldResult.orderParameter || 0).toFixed(4)}`);
|
|
67
|
+
console.log(` Steps: ${foldResult.steps || 0}`);
|
|
68
|
+
|
|
69
|
+
// ===========================================
|
|
70
|
+
// PHASE ANALYSIS
|
|
71
|
+
// ===========================================
|
|
72
|
+
|
|
73
|
+
console.log('\n\nPHASE ANALYSIS');
|
|
74
|
+
console.log('--------------\n');
|
|
75
|
+
|
|
76
|
+
if (foldResult.phases && foldResult.phases.length > 0) {
|
|
77
|
+
console.log('Final oscillator phases:');
|
|
78
|
+
for (let i = 0; i < Math.min(foldResult.phases.length, proteinSeq.length); i++) {
|
|
79
|
+
const phase = foldResult.phases[i];
|
|
80
|
+
const phaseDegrees = ((phase % (2 * Math.PI)) * 180 / Math.PI).toFixed(1);
|
|
81
|
+
console.log(` ${proteinSeq[i]}: ${phaseDegrees}°`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ===========================================
|
|
86
|
+
// CONTACT ANALYSIS
|
|
87
|
+
// ===========================================
|
|
88
|
+
|
|
89
|
+
console.log('\n\nCONTACT ANALYSIS');
|
|
90
|
+
console.log('----------------\n');
|
|
91
|
+
|
|
92
|
+
// Calculate contacts from prime similarity
|
|
93
|
+
console.log('Computing residue contacts based on prime resonance...');
|
|
94
|
+
|
|
95
|
+
const primes = backend.encode(proteinSeq);
|
|
96
|
+
const contacts = [];
|
|
97
|
+
|
|
98
|
+
// Simple contact prediction based on prime resonance
|
|
99
|
+
for (let i = 0; i < primes.length; i++) {
|
|
100
|
+
for (let j = i + 2; j < primes.length; j++) {
|
|
101
|
+
const p1 = primes[i];
|
|
102
|
+
const p2 = primes[j];
|
|
103
|
+
|
|
104
|
+
// Resonance strength based on GCD and frequency matching
|
|
105
|
+
const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
106
|
+
const resonance = gcd(p1, p2) / Math.sqrt(p1 * p2);
|
|
107
|
+
|
|
108
|
+
// Hydrophobic attraction
|
|
109
|
+
const aa1 = proteinSeq[i];
|
|
110
|
+
const aa2 = proteinSeq[j];
|
|
111
|
+
const h1 = hydrophobic.includes(aa1) ? 0.3 : 0;
|
|
112
|
+
const h2 = hydrophobic.includes(aa2) ? 0.3 : 0;
|
|
113
|
+
|
|
114
|
+
const strength = resonance + h1 + h2;
|
|
115
|
+
|
|
116
|
+
if (strength > 0.1) {
|
|
117
|
+
contacts.push([i, j, strength]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Sort by strength
|
|
123
|
+
contacts.sort((a, b) => b[2] - a[2]);
|
|
124
|
+
|
|
125
|
+
console.log('\nTop contacts (by strength):');
|
|
126
|
+
for (const [i, j, strength] of contacts.slice(0, 8)) {
|
|
127
|
+
console.log(` ${proteinSeq[i]}(${i}) ↔ ${proteinSeq[j]}(${j}): ${strength.toFixed(3)}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ===========================================
|
|
131
|
+
// CONTACT MAP VISUALIZATION
|
|
132
|
+
// ===========================================
|
|
133
|
+
|
|
134
|
+
console.log('\n\nCONTACT MAP (text visualization)');
|
|
135
|
+
console.log('----------------------------------\n');
|
|
136
|
+
|
|
137
|
+
// Build contact strength matrix
|
|
138
|
+
const matrix = Array(proteinSeq.length).fill(null).map(() =>
|
|
139
|
+
Array(proteinSeq.length).fill(0)
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
for (const [i, j, strength] of contacts) {
|
|
143
|
+
matrix[i][j] = strength;
|
|
144
|
+
matrix[j][i] = strength;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Print header
|
|
148
|
+
console.log(' ' + proteinSeq.split('').join(' '));
|
|
149
|
+
console.log(' ' + proteinSeq.split('').map(() => '─').join('─'));
|
|
150
|
+
|
|
151
|
+
for (let i = 0; i < proteinSeq.length; i++) {
|
|
152
|
+
let row = `${proteinSeq[i]} │ `;
|
|
153
|
+
for (let j = 0; j < proteinSeq.length; j++) {
|
|
154
|
+
if (i === j) {
|
|
155
|
+
row += '●';
|
|
156
|
+
} else if (matrix[i][j] > 0.5) {
|
|
157
|
+
row += '█';
|
|
158
|
+
} else if (matrix[i][j] > 0.3) {
|
|
159
|
+
row += '▓';
|
|
160
|
+
} else if (matrix[i][j] > 0.1) {
|
|
161
|
+
row += '░';
|
|
162
|
+
} else {
|
|
163
|
+
row += '·';
|
|
164
|
+
}
|
|
165
|
+
row += ' ';
|
|
166
|
+
}
|
|
167
|
+
console.log(row);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.log('\nLegend: ● self, █ strong, ▓ medium, ░ weak, · none');
|
|
171
|
+
|
|
172
|
+
// ===========================================
|
|
173
|
+
// PRIME RESONANCE VIEW
|
|
174
|
+
// ===========================================
|
|
175
|
+
|
|
176
|
+
console.log('\n\nPRIME RESONANCE VIEW');
|
|
177
|
+
console.log('--------------------\n');
|
|
178
|
+
|
|
179
|
+
const proteinState = backend.primesToState(proteinPrimes);
|
|
180
|
+
console.log('Protein hypercomplex state norm:', proteinState.norm().toFixed(4));
|
|
181
|
+
|
|
182
|
+
// Show prime assignment for each amino acid
|
|
183
|
+
console.log('\nAmino Acid → Prime Mapping:');
|
|
184
|
+
const AMINO_ACID_PRIMES = {
|
|
185
|
+
'L': 23, 'I': 29, 'V': 31, 'F': 37, 'W': 41, 'M': 43, 'A': 47,
|
|
186
|
+
'G': 53, 'C': 59, 'P': 61, 'Y': 67, 'S': 71, 'T': 73, 'N': 79, 'Q': 83,
|
|
187
|
+
'H': 89, 'K': 97, 'R': 101, 'D': 103, 'E': 107
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
for (const aa of proteinSeq.slice(0, 6).split('')) {
|
|
191
|
+
const prime = AMINO_ACID_PRIMES[aa] || '?';
|
|
192
|
+
console.log(` ${aa} → ${prime}`);
|
|
193
|
+
}
|
|
194
|
+
console.log(' ...');
|
|
195
|
+
|
|
196
|
+
// ===========================================
|
|
197
|
+
// KEY TAKEAWAYS
|
|
198
|
+
// ===========================================
|
|
199
|
+
|
|
200
|
+
console.log('\n==================================');
|
|
201
|
+
console.log('KEY TAKEAWAYS:');
|
|
202
|
+
console.log('1. Protein folding modeled as oscillator synchronization');
|
|
203
|
+
console.log('2. Hydrophobic residues cluster (form protein core)');
|
|
204
|
+
console.log('3. Charged residues prefer opposite charges or surface');
|
|
205
|
+
console.log('4. Prime encoding enables resonance-based coupling');
|
|
206
|
+
console.log('5. Contact maps emerge from Kuramoto dynamics');
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example DNA Computing
|
|
3
|
+
* @description Build logic gates and circuits using DNA strands
|
|
4
|
+
*
|
|
5
|
+
* This example demonstrates DNA computing - using DNA strands to perform
|
|
6
|
+
* logical computation. The key mechanisms are:
|
|
7
|
+
* - DNA hybridization (complementary strands bind)
|
|
8
|
+
* - Strand displacement (incoming strand displaces bound strand)
|
|
9
|
+
* - Toehold-mediated reactions (short overhangs enable displacement)
|
|
10
|
+
*
|
|
11
|
+
* TinyAleph models these as prime-encoded strand operations.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
BioinformaticsBackend,
|
|
16
|
+
DNACircuit,
|
|
17
|
+
ANDGate,
|
|
18
|
+
ORGate,
|
|
19
|
+
NOTGate
|
|
20
|
+
} = require('../../modular');
|
|
21
|
+
|
|
22
|
+
// ===========================================
|
|
23
|
+
// SETUP
|
|
24
|
+
// ===========================================
|
|
25
|
+
|
|
26
|
+
const backend = new BioinformaticsBackend();
|
|
27
|
+
|
|
28
|
+
// ===========================================
|
|
29
|
+
// DNA STRAND BASICS
|
|
30
|
+
// ===========================================
|
|
31
|
+
|
|
32
|
+
console.log('TinyAleph DNA Computing Example');
|
|
33
|
+
console.log('================================\n');
|
|
34
|
+
|
|
35
|
+
console.log('DNA STRAND REPRESENTATION');
|
|
36
|
+
console.log('-------------------------\n');
|
|
37
|
+
|
|
38
|
+
// Create DNA strands using the backend
|
|
39
|
+
const seq1 = 'ATGCGATC';
|
|
40
|
+
const seq2 = 'GATCGCAT';
|
|
41
|
+
|
|
42
|
+
const strand1Primes = backend.encode(seq1);
|
|
43
|
+
const strand2Primes = backend.encode(seq2);
|
|
44
|
+
|
|
45
|
+
console.log('Strand 1 (signal-A):');
|
|
46
|
+
console.log(` Sequence: 5'-${seq1}-3'`);
|
|
47
|
+
console.log(` Primes: [${strand1Primes.slice(0, 4).join(', ')}...]`);
|
|
48
|
+
console.log(` State norm: ${backend.primesToState(strand1Primes).norm().toFixed(4)}`);
|
|
49
|
+
|
|
50
|
+
console.log('\nStrand 2 (signal-B):');
|
|
51
|
+
console.log(` Sequence: 5'-${seq2}-3'`);
|
|
52
|
+
console.log(` Primes: [${strand2Primes.slice(0, 4).join(', ')}...]`);
|
|
53
|
+
|
|
54
|
+
// Check if strands are complementary
|
|
55
|
+
const COMPLEMENT = { 'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G' };
|
|
56
|
+
const comp1 = seq1.split('').map(b => COMPLEMENT[b]).join('');
|
|
57
|
+
const isComplementary = comp1 === seq2;
|
|
58
|
+
console.log(`\nAre strands complementary? ${isComplementary ? 'YES' : 'NO'}`);
|
|
59
|
+
console.log(` Complement of strand 1: ${comp1}`);
|
|
60
|
+
|
|
61
|
+
// ===========================================
|
|
62
|
+
// SIMPLE LOGIC GATES
|
|
63
|
+
// ===========================================
|
|
64
|
+
|
|
65
|
+
console.log('\n\nLOGIC GATES');
|
|
66
|
+
console.log('-----------\n');
|
|
67
|
+
|
|
68
|
+
// Create a simple AND gate
|
|
69
|
+
const andGate = new ANDGate({ name: 'AND-1' });
|
|
70
|
+
console.log('AND Gate:', andGate.name);
|
|
71
|
+
|
|
72
|
+
// Test all input combinations (using concentration values 0 or 1)
|
|
73
|
+
console.log('\n Truth Table:');
|
|
74
|
+
console.log(' A | B | A AND B');
|
|
75
|
+
console.log(' --|---|--------');
|
|
76
|
+
for (const [a, b] of [[0, 0], [0, 1], [1, 0], [1, 1]]) {
|
|
77
|
+
const result = andGate.evaluate(a, b);
|
|
78
|
+
console.log(` ${a} | ${b} | ${result.output ? 1 : 0}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Create an OR gate
|
|
82
|
+
const orGate = new ORGate({ name: 'OR-1' });
|
|
83
|
+
console.log('\nOR Gate:', orGate.name);
|
|
84
|
+
console.log('\n Truth Table:');
|
|
85
|
+
console.log(' A | B | A OR B');
|
|
86
|
+
console.log(' --|---|-------');
|
|
87
|
+
for (const [a, b] of [[0, 0], [0, 1], [1, 0], [1, 1]]) {
|
|
88
|
+
const result = orGate.evaluate(a, b);
|
|
89
|
+
console.log(` ${a} | ${b} | ${result.output ? 1 : 0}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Create a NOT gate
|
|
93
|
+
const notGate = new NOTGate({ name: 'NOT-1' });
|
|
94
|
+
console.log('\nNOT Gate:', notGate.name);
|
|
95
|
+
console.log('\n Truth Table:');
|
|
96
|
+
console.log(' A | NOT A');
|
|
97
|
+
console.log(' --|------');
|
|
98
|
+
for (const a of [0, 1]) {
|
|
99
|
+
const result = notGate.evaluate(a);
|
|
100
|
+
console.log(` ${a} | ${result.output ? 1 : 0}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ===========================================
|
|
104
|
+
// DNA CIRCUIT
|
|
105
|
+
// ===========================================
|
|
106
|
+
|
|
107
|
+
console.log('\n\nDNA CIRCUIT: (A AND B) OR (NOT C)');
|
|
108
|
+
console.log('----------------------------------\n');
|
|
109
|
+
|
|
110
|
+
const circuit = new DNACircuit('main-circuit');
|
|
111
|
+
|
|
112
|
+
// Add gates to create: (A AND B) OR (NOT C)
|
|
113
|
+
circuit.addGate('and1', new ANDGate({ name: 'and1' }));
|
|
114
|
+
circuit.addGate('not1', new NOTGate({ name: 'not1' }));
|
|
115
|
+
circuit.addGate('or1', new ORGate({ name: 'or1' }));
|
|
116
|
+
|
|
117
|
+
// Connect: and1 output → or1 input1, not1 output → or1 input2
|
|
118
|
+
circuit.connect('and1', 'or1', 1);
|
|
119
|
+
circuit.connect('not1', 'or1', 2);
|
|
120
|
+
|
|
121
|
+
console.log('Circuit structure:');
|
|
122
|
+
console.log(' A ──┐');
|
|
123
|
+
console.log(' ├──[AND]──┐');
|
|
124
|
+
console.log(' B ──┘ ├──[OR]── result');
|
|
125
|
+
console.log(' ┌──[NOT]──┘');
|
|
126
|
+
console.log(' C ──┘');
|
|
127
|
+
|
|
128
|
+
console.log('\nCircuit gates:', circuit.listGates ? circuit.listGates().map(g => g.name).join(', ') : [...circuit.gates.keys()].join(', '));
|
|
129
|
+
|
|
130
|
+
// Manual evaluation for all input combinations
|
|
131
|
+
console.log('\nTruth Table:');
|
|
132
|
+
console.log('A | B | C | (A∧B)∨(¬C)');
|
|
133
|
+
console.log('--|---|---|----------');
|
|
134
|
+
|
|
135
|
+
for (const a of [0, 1]) {
|
|
136
|
+
for (const b of [0, 1]) {
|
|
137
|
+
for (const c of [0, 1]) {
|
|
138
|
+
// Manually compute the logic
|
|
139
|
+
const andResult = a && b;
|
|
140
|
+
const notResult = !c;
|
|
141
|
+
const finalResult = andResult || notResult;
|
|
142
|
+
console.log(`${a} | ${b} | ${c} | ${finalResult ? 1 : 0}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ===========================================
|
|
148
|
+
// BINDING AFFINITY
|
|
149
|
+
// ===========================================
|
|
150
|
+
|
|
151
|
+
console.log('\n\nBINDING AFFINITY BETWEEN STRANDS');
|
|
152
|
+
console.log('---------------------------------\n');
|
|
153
|
+
|
|
154
|
+
// Test binding between different strands
|
|
155
|
+
const strandsToTest = [
|
|
156
|
+
{ name: 'Strand 1', seq: seq1 },
|
|
157
|
+
{ name: 'Complement', seq: comp1 },
|
|
158
|
+
{ name: 'Different', seq: 'GGGGCCCC' }
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
console.log('Binding affinities relative to Strand 1:');
|
|
162
|
+
|
|
163
|
+
for (const strand of strandsToTest) {
|
|
164
|
+
const primes = backend.encode(strand.seq);
|
|
165
|
+
const result = backend.bindingAffinity(strand1Primes, primes);
|
|
166
|
+
console.log(` ${strand.name} (${strand.seq}): ${result.affinity.toFixed(4)}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ===========================================
|
|
170
|
+
// DNA COMPUTING ADVANTAGES
|
|
171
|
+
// ===========================================
|
|
172
|
+
|
|
173
|
+
console.log('\n\nDNA COMPUTING ADVANTAGES');
|
|
174
|
+
console.log('------------------------\n');
|
|
175
|
+
|
|
176
|
+
console.log('1. Massive parallelism: billions of molecules compute simultaneously');
|
|
177
|
+
console.log('2. Energy efficient: reactions occur at room temperature');
|
|
178
|
+
console.log('3. Ultra-dense storage: 1 gram DNA ≈ 215 petabytes');
|
|
179
|
+
console.log('4. Biocompatibility: can interface with living systems');
|
|
180
|
+
console.log('5. Self-assembly: complex structures emerge from simple rules');
|
|
181
|
+
|
|
182
|
+
// ===========================================
|
|
183
|
+
// KEY TAKEAWAYS
|
|
184
|
+
// ===========================================
|
|
185
|
+
|
|
186
|
+
console.log('\n================================');
|
|
187
|
+
console.log('KEY TAKEAWAYS:');
|
|
188
|
+
console.log('1. DNA strands encode information as prime sequences');
|
|
189
|
+
console.log('2. Logic gates use strand displacement reactions');
|
|
190
|
+
console.log('3. Circuits compose gates for complex logic');
|
|
191
|
+
console.log('4. Binding affinity measured via prime resonance');
|
|
192
|
+
console.log('5. TinyAleph models DNA computing in hypercomplex space');
|