@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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +278 -0
  3. package/backends/cryptographic/index.js +196 -0
  4. package/backends/index.js +15 -0
  5. package/backends/interface.js +89 -0
  6. package/backends/scientific/index.js +272 -0
  7. package/backends/semantic/index.js +527 -0
  8. package/backends/semantic/surface.js +393 -0
  9. package/backends/semantic/two-layer.js +375 -0
  10. package/core/fano.js +127 -0
  11. package/core/hilbert.js +564 -0
  12. package/core/hypercomplex.js +141 -0
  13. package/core/index.js +133 -0
  14. package/core/llm.js +132 -0
  15. package/core/prime.js +184 -0
  16. package/core/resonance.js +695 -0
  17. package/core/rformer-tf.js +1086 -0
  18. package/core/rformer.js +806 -0
  19. package/core/sieve.js +350 -0
  20. package/data.json +8163 -0
  21. package/docs/EXAMPLES_PLAN.md +293 -0
  22. package/docs/README.md +159 -0
  23. package/docs/design/ALEPH_CHAT_ARCHITECTURE.md +499 -0
  24. package/docs/guide/01-quickstart.md +298 -0
  25. package/docs/guide/02-semantic-computing.md +409 -0
  26. package/docs/guide/03-cryptographic.md +420 -0
  27. package/docs/guide/04-scientific.md +494 -0
  28. package/docs/guide/05-llm-integration.md +568 -0
  29. package/docs/guide/06-advanced.md +996 -0
  30. package/docs/guide/README.md +188 -0
  31. package/docs/reference/01-core.md +695 -0
  32. package/docs/reference/02-physics.md +601 -0
  33. package/docs/reference/03-backends.md +892 -0
  34. package/docs/reference/04-engine.md +632 -0
  35. package/docs/reference/README.md +252 -0
  36. package/docs/theory/01-prime-semantics.md +327 -0
  37. package/docs/theory/02-hypercomplex-algebra.md +421 -0
  38. package/docs/theory/03-phase-synchronization.md +364 -0
  39. package/docs/theory/04-entropy-reasoning.md +348 -0
  40. package/docs/theory/05-non-commutativity.md +402 -0
  41. package/docs/theory/06-two-layer-meaning.md +414 -0
  42. package/docs/theory/07-resonant-field-interface.md +419 -0
  43. package/docs/theory/08-semantic-sieve.md +520 -0
  44. package/docs/theory/09-temporal-emergence.md +298 -0
  45. package/docs/theory/10-quaternionic-memory.md +415 -0
  46. package/docs/theory/README.md +162 -0
  47. package/engine/aleph.js +418 -0
  48. package/engine/index.js +7 -0
  49. package/index.js +23 -0
  50. package/modular.js +254 -0
  51. package/package.json +99 -0
  52. package/physics/collapse.js +95 -0
  53. package/physics/entropy.js +88 -0
  54. package/physics/index.js +65 -0
  55. package/physics/kuramoto.js +91 -0
  56. package/physics/lyapunov.js +80 -0
  57. package/physics/oscillator.js +95 -0
  58. package/types/index.d.ts +575 -0
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Scientific Backend - Quantum simulation, particle physics, molecular dynamics
3
+ */
4
+ const { Backend } = require('../interface');
5
+ const { Hypercomplex } = require('../../core/hypercomplex');
6
+ const { primeToFrequency, factorize, firstNPrimes, DEFAULT_PRIMES } = require('../../core/prime');
7
+
8
+ class ScientificBackend extends Backend {
9
+ constructor(config) {
10
+ super(config);
11
+ this.dimension = config.dimension || 16;
12
+ this.config.primes = config.primes || DEFAULT_PRIMES;
13
+
14
+ // Physical particle/force mappings
15
+ this.physicalConstants = config.physicalConstants || {
16
+ 2: 'electromagnetic', 3: 'weak', 5: 'strong', 7: 'gravitational',
17
+ 11: 'electron', 13: 'positron', 17: 'photon', 19: 'neutrino',
18
+ 23: 'muon', 29: 'tau', 31: 'up_quark', 37: 'down_quark',
19
+ 41: 'charm_quark', 43: 'strange_quark', 47: 'top_quark', 53: 'bottom_quark',
20
+ 59: 'W_boson', 61: 'Z_boson', 67: 'Higgs', 71: 'gluon'
21
+ };
22
+
23
+ // Quantum gate transforms
24
+ this.quantumGates = config.quantumGates || {
25
+ X: { q: [2], r: [3], name: 'Pauli-X' },
26
+ Y: { q: [3], r: [5], name: 'Pauli-Y' },
27
+ Z: { q: [5], r: [7], name: 'Pauli-Z' },
28
+ H: { q: [2, 3], r: [2, 3, 5], name: 'Hadamard' },
29
+ CNOT: { q: [2, 11], r: [3, 13], name: 'CNOT' },
30
+ T: { q: [7], r: [11], name: 'T-gate' },
31
+ S: { q: [11], r: [13], name: 'S-gate' },
32
+ SWAP: { q: [2, 3], r: [3, 2], name: 'SWAP' }
33
+ };
34
+
35
+ this.transforms = Object.values(this.quantumGates);
36
+ }
37
+
38
+ encode(input) {
39
+ // Handle various input types
40
+ if (Array.isArray(input)) {
41
+ return input.flatMap(q => this.qubitToPrimes(q));
42
+ }
43
+
44
+ // Parse ket notation |n⟩
45
+ const match = String(input).match(/\|(\d+)⟩/);
46
+ if (match) {
47
+ return this.integerToPrimes(parseInt(match[1]));
48
+ }
49
+
50
+ // Parse qubit string
51
+ if (typeof input === 'string' && input.startsWith('|')) {
52
+ return this.qubitToPrimes(input);
53
+ }
54
+
55
+ // Numeric input
56
+ if (typeof input === 'number') {
57
+ return this.integerToPrimes(input);
58
+ }
59
+
60
+ return [2]; // Default to |0⟩
61
+ }
62
+
63
+ qubitToPrimes(qubit) {
64
+ const map = {
65
+ '|0⟩': [2],
66
+ '|1⟩': [3],
67
+ '|+⟩': [2, 3],
68
+ '|-⟩': [2, 5],
69
+ '|i⟩': [3, 5],
70
+ '|-i⟩': [3, 7],
71
+ '|00⟩': [2, 2],
72
+ '|01⟩': [2, 3],
73
+ '|10⟩': [3, 2],
74
+ '|11⟩': [3, 3],
75
+ '|Φ+⟩': [2, 3, 5, 7], // Bell state
76
+ '|Φ-⟩': [2, 3, 5, 11], // Bell state
77
+ '|Ψ+⟩': [2, 5, 7, 11], // Bell state
78
+ '|Ψ-⟩': [3, 5, 7, 11] // Bell state
79
+ };
80
+ return map[qubit] || [2];
81
+ }
82
+
83
+ integerToPrimes(n) {
84
+ if (n <= 1) return [n + 2];
85
+ const factors = factorize(n);
86
+ return Object.entries(factors).flatMap(([p, exp]) =>
87
+ Array(exp).fill(parseInt(p))
88
+ );
89
+ }
90
+
91
+ decode(primes) {
92
+ const has2 = primes.includes(2);
93
+ const has3 = primes.includes(3);
94
+ const has5 = primes.includes(5);
95
+ const has7 = primes.includes(7);
96
+
97
+ // Bell states
98
+ if (primes.length >= 4 && has2 && has3 && has5) {
99
+ if (has7) return '|Φ+⟩';
100
+ if (primes.includes(11)) return '|Φ-⟩';
101
+ }
102
+
103
+ // Superposition states
104
+ if (has2 && has3 && !has5) return '|+⟩';
105
+ if (has2 && has5 && !has3) return '|-⟩';
106
+
107
+ // Basis states
108
+ if (has2 && !has3) return '|0⟩';
109
+ if (!has2 && has3) return '|1⟩';
110
+
111
+ // Default based on majority
112
+ const count2 = primes.filter(p => p === 2).length;
113
+ const count3 = primes.filter(p => p === 3).length;
114
+ return count2 > count3 ? '|0⟩' : '|1⟩';
115
+ }
116
+
117
+ primesToState(primes) {
118
+ const state = Hypercomplex.zero(this.dimension);
119
+
120
+ // Count prime occurrences
121
+ const primeCount = {};
122
+ for (const p of primes) {
123
+ primeCount[p] = (primeCount[p] || 0) + 1;
124
+ }
125
+
126
+ // Compute Bloch sphere angles
127
+ let theta = 0, phi = 0;
128
+ for (const [p, count] of Object.entries(primeCount)) {
129
+ theta += (parseInt(p) * count) % 180 * Math.PI / 180;
130
+ phi += (parseInt(p) * count * 2) % 360 * Math.PI / 180;
131
+ }
132
+
133
+ // Set qubit components
134
+ state.c[0] = Math.cos(theta / 2);
135
+ state.c[1] = Math.sin(theta / 2) * Math.cos(phi);
136
+ state.c[2] = Math.sin(theta / 2) * Math.sin(phi);
137
+
138
+ // Higher dimensions for multi-qubit systems
139
+ for (let i = 3; i < this.dimension; i++) {
140
+ const p = primes[i % primes.length] || 2;
141
+ state.c[i] = Math.cos(2 * Math.PI * i / p) / Math.sqrt(this.dimension);
142
+ }
143
+
144
+ return state.normalize();
145
+ }
146
+
147
+ primesToFrequencies(primes) {
148
+ // Hydrogen-like energy level spacing
149
+ return primes.map((p, n) => primeToFrequency(p) * ((n + 1) ** 2));
150
+ }
151
+
152
+ applyTransform(inputPrimes, transform) {
153
+ const inputSet = new Set(inputPrimes);
154
+
155
+ // Check if all query primes are present
156
+ if (!transform.q || !transform.q.every(p => inputSet.has(p))) {
157
+ return inputPrimes;
158
+ }
159
+
160
+ // Remove query primes and add result primes
161
+ const output = inputPrimes.filter(p => !transform.q.includes(p));
162
+ return [...output, ...(transform.r || [])];
163
+ }
164
+
165
+ /**
166
+ * Apply a quantum gate by name
167
+ */
168
+ applyGate(inputPrimes, gateName) {
169
+ const gate = this.quantumGates[gateName];
170
+ if (!gate) throw new Error(`Unknown gate: ${gateName}`);
171
+ return this.applyTransform(inputPrimes, gate);
172
+ }
173
+
174
+ /**
175
+ * Measure quantum state (probabilistic collapse)
176
+ */
177
+ measure(state) {
178
+ const p0 = state.c[0] ** 2 + (state.c[1] || 0) ** 2;
179
+ const outcome = Math.random() < p0 ? 0 : 1;
180
+ return {
181
+ outcome,
182
+ state: outcome === 0 ? '|0⟩' : '|1⟩',
183
+ probability: outcome === 0 ? p0 : 1 - p0
184
+ };
185
+ }
186
+
187
+ /**
188
+ * Simulate particle interaction
189
+ */
190
+ interact(particle1Primes, particle2Primes, interactionType = 'electromagnetic') {
191
+ // Find the interaction force prime
192
+ const interactionPrime = Object.entries(this.physicalConstants)
193
+ .find(([p, name]) => name === interactionType)?.[0] || 2;
194
+
195
+ // Combine particles with interaction
196
+ const combined = [...particle1Primes, ...particle2Primes, parseInt(interactionPrime)];
197
+
198
+ return {
199
+ inputParticles: [particle1Primes, particle2Primes],
200
+ interaction: interactionType,
201
+ outputState: this.primesToState(combined),
202
+ // Product of primes represents conserved quantity
203
+ conserved: combined.reduce((a, b) => a * b, 1)
204
+ };
205
+ }
206
+
207
+ /**
208
+ * Get particle name from primes
209
+ */
210
+ identifyParticle(primes) {
211
+ for (const p of primes) {
212
+ if (this.physicalConstants[p]) {
213
+ return this.physicalConstants[p];
214
+ }
215
+ }
216
+ return 'unknown';
217
+ }
218
+
219
+ /**
220
+ * Create entangled pair (Bell state)
221
+ */
222
+ createEntangledPair(type = 'Φ+') {
223
+ const bellStates = {
224
+ 'Φ+': [2, 3, 5, 7],
225
+ 'Φ-': [2, 3, 5, 11],
226
+ 'Ψ+': [2, 5, 7, 11],
227
+ 'Ψ-': [3, 5, 7, 11]
228
+ };
229
+ return bellStates[type] || bellStates['Φ+'];
230
+ }
231
+
232
+ /**
233
+ * Tensor product of two qubit states
234
+ */
235
+ tensorProduct(state1Primes, state2Primes) {
236
+ // Interleave and combine primes
237
+ const result = [];
238
+ const maxLen = Math.max(state1Primes.length, state2Primes.length);
239
+ for (let i = 0; i < maxLen; i++) {
240
+ if (i < state1Primes.length) result.push(state1Primes[i]);
241
+ if (i < state2Primes.length) result.push(state2Primes[i]);
242
+ }
243
+ return result;
244
+ }
245
+
246
+ /**
247
+ * Apply rotation gate with angle
248
+ */
249
+ rotate(inputPrimes, axis, angle) {
250
+ const state = this.primesToState(inputPrimes);
251
+ const result = Hypercomplex.zero(this.dimension);
252
+
253
+ const cos = Math.cos(angle / 2);
254
+ const sin = Math.sin(angle / 2);
255
+
256
+ if (axis === 'x') {
257
+ result.c[0] = cos * state.c[0] - sin * state.c[1];
258
+ result.c[1] = -sin * state.c[0] + cos * state.c[1];
259
+ } else if (axis === 'y') {
260
+ result.c[0] = cos * state.c[0] - sin * state.c[2];
261
+ result.c[2] = sin * state.c[0] + cos * state.c[2];
262
+ } else if (axis === 'z') {
263
+ result.c[0] = cos * state.c[0];
264
+ result.c[1] = cos * state.c[1] - sin * state.c[2];
265
+ result.c[2] = sin * state.c[1] + cos * state.c[2];
266
+ }
267
+
268
+ return result.normalize();
269
+ }
270
+ }
271
+
272
+ module.exports = { ScientificBackend };