@aleph-ai/tinyaleph 1.2.1 → 1.4.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/README.md +609 -13
- package/backends/bioinformatics/binding.js +503 -0
- package/backends/bioinformatics/dna-computing.js +664 -0
- package/backends/bioinformatics/encoding.js +339 -0
- package/backends/bioinformatics/folding.js +454 -0
- package/backends/bioinformatics/genetic-code.js +269 -0
- package/backends/bioinformatics/index.js +522 -0
- package/backends/bioinformatics/transcription.js +221 -0
- package/backends/bioinformatics/translation.js +264 -0
- package/backends/cryptographic/index.js +455 -2
- package/backends/index.js +25 -1
- package/core/beacon.js +735 -0
- package/core/compound.js +532 -0
- package/core/crt-homology.js +1004 -0
- package/core/enochian-vocabulary.js +910 -0
- package/core/enochian.js +744 -0
- package/core/errors.js +587 -0
- package/core/hilbert.js +1105 -2
- package/core/index.js +192 -13
- package/core/inference.js +605 -0
- package/core/lambda.js +284 -33
- package/core/logger.js +350 -0
- package/core/prime.js +136 -1
- package/core/quaternion-semantics.js +623 -0
- package/core/reduction.js +391 -1
- package/core/resonance.js +245 -616
- package/core/rformer-crt.js +892 -0
- package/core/symbols/archetypes.js +478 -0
- package/core/symbols/base.js +302 -0
- package/core/symbols/elements.js +487 -0
- package/core/symbols/hieroglyphs.js +303 -0
- package/core/symbols/iching.js +471 -0
- package/core/symbols/index.js +77 -0
- package/core/symbols/tarot.js +211 -0
- package/core/symbols.js +22 -0
- package/core/topology.js +655 -0
- package/docs/README.md +54 -0
- package/docs/design/BIOINFORMATICS_BACKEND_DESIGN.md +493 -0
- package/docs/guide/06-symbolic-ai.md +370 -0
- package/docs/guide/README.md +2 -1
- package/docs/reference/05-symbolic-ai.md +570 -0
- package/docs/reference/06-bioinformatics.md +546 -0
- package/docs/reference/07-topology.md +257 -0
- package/docs/reference/08-observer.md +421 -0
- package/docs/reference/09-crt-homology.md +369 -0
- package/docs/reference/README.md +32 -2
- package/docs/theory/11-prgraph-memory.md +559 -0
- package/docs/theory/12-resonant-attention.md +661 -0
- package/modular.js +264 -4
- package/package.json +1 -1
package/core/enochian.js
ADDED
|
@@ -0,0 +1,744 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enochian Packet Layer (Section 7.4 of Whitepaper)
|
|
3
|
+
*
|
|
4
|
+
* Low-bandwidth prime-mode surface language for robust symbolic packets.
|
|
5
|
+
* Uses a geometric validity gate based on twist angles derived from primes.
|
|
6
|
+
*
|
|
7
|
+
* Key features:
|
|
8
|
+
* - Prime alphabet PE = {7, 11, 13, 17, 19, 23, 29}
|
|
9
|
+
* - Mode set M = {α, μ, ω} (alpha, mu, omega)
|
|
10
|
+
* - Twist angle κ(p) = 360/p degrees
|
|
11
|
+
* - Twist-closure validation: T(P) mod 360 ∈ [0,ε) ∪ (360-ε, 360]
|
|
12
|
+
*
|
|
13
|
+
* This layer provides fast structural validation before expensive
|
|
14
|
+
* decoding and network verification.
|
|
15
|
+
*
|
|
16
|
+
* Enhanced with enochian-vocabulary.js integration:
|
|
17
|
+
* - Full 21-letter Enochian alphabet
|
|
18
|
+
* - Core vocabulary (35+ words)
|
|
19
|
+
* - The 19 Calls
|
|
20
|
+
* - Sedenion operations (16D)
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// Import the comprehensive Enochian vocabulary system
|
|
24
|
+
const EnochianVocabulary = require('./enochian-vocabulary');
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Enochian prime alphabet (Section 7.4)
|
|
28
|
+
*/
|
|
29
|
+
const ENOCHIAN_PRIMES = [7, 11, 13, 17, 19, 23, 29];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Mode symbols (α = alpha, μ = mu, ω = omega)
|
|
33
|
+
*/
|
|
34
|
+
const MODES = ['α', 'μ', 'ω'];
|
|
35
|
+
const MODE_INDEX = { 'α': 0, 'μ': 1, 'ω': 2, 'alpha': 0, 'mu': 1, 'omega': 2 };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Twist angle for a prime (equation 16)
|
|
39
|
+
* κ(p) = 360/p degrees
|
|
40
|
+
* @param {number} p - Prime number
|
|
41
|
+
* @returns {number} Twist angle in degrees
|
|
42
|
+
*/
|
|
43
|
+
function twistAngle(p) {
|
|
44
|
+
return 360 / p;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Compute total twist for a sequence (equation 17)
|
|
49
|
+
* T(P) = Σ κ(pi)
|
|
50
|
+
* @param {Array<number>} primes - Sequence of primes
|
|
51
|
+
* @returns {number} Total twist in degrees
|
|
52
|
+
*/
|
|
53
|
+
function totalTwist(primes) {
|
|
54
|
+
return primes.reduce((sum, p) => sum + twistAngle(p), 0);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Check twist closure (equation 18)
|
|
59
|
+
* Accept packet as twist-closed when T(P) mod 360 ∈ [0,ε) ∪ (360-ε, 360]
|
|
60
|
+
* @param {Array<number>} primes - Sequence of primes
|
|
61
|
+
* @param {number} epsilon - Tolerance in degrees (default 1.0)
|
|
62
|
+
* @returns {boolean} True if twist-closed
|
|
63
|
+
*/
|
|
64
|
+
function isTwistClosed(primes, epsilon = 1.0) {
|
|
65
|
+
const twist = totalTwist(primes);
|
|
66
|
+
const mod = ((twist % 360) + 360) % 360;
|
|
67
|
+
return mod < epsilon || mod > (360 - epsilon);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Enochian Symbol
|
|
72
|
+
* Represents a single symbol (prime, mode) tuple
|
|
73
|
+
*/
|
|
74
|
+
class EnochianSymbol {
|
|
75
|
+
/**
|
|
76
|
+
* @param {number} prime - Prime from ENOCHIAN_PRIMES
|
|
77
|
+
* @param {string} mode - Mode from MODES (α, μ, ω)
|
|
78
|
+
*/
|
|
79
|
+
constructor(prime, mode = 'α') {
|
|
80
|
+
if (!ENOCHIAN_PRIMES.includes(prime)) {
|
|
81
|
+
throw new Error(`Invalid Enochian prime: ${prime}. Must be one of ${ENOCHIAN_PRIMES}`);
|
|
82
|
+
}
|
|
83
|
+
const modeIdx = MODE_INDEX[mode];
|
|
84
|
+
if (modeIdx === undefined) {
|
|
85
|
+
throw new Error(`Invalid mode: ${mode}. Must be one of ${MODES}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.prime = prime;
|
|
89
|
+
this.mode = MODES[modeIdx];
|
|
90
|
+
this.twist = twistAngle(prime);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the numeric encoding (prime * 3 + modeIdx)
|
|
95
|
+
*/
|
|
96
|
+
encode() {
|
|
97
|
+
const modeIdx = MODE_INDEX[this.mode];
|
|
98
|
+
return this.prime * 3 + modeIdx;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Decode from numeric encoding
|
|
103
|
+
*/
|
|
104
|
+
static decode(encoded) {
|
|
105
|
+
const modeIdx = encoded % 3;
|
|
106
|
+
const prime = (encoded - modeIdx) / 3;
|
|
107
|
+
return new EnochianSymbol(prime, MODES[modeIdx]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get string representation
|
|
112
|
+
*/
|
|
113
|
+
toString() {
|
|
114
|
+
return `${this.mode}${this.prime}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
toJSON() {
|
|
118
|
+
return { prime: this.prime, mode: this.mode, twist: this.twist };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Enochian Packet
|
|
124
|
+
* A sequence of symbols with twist-closure validation
|
|
125
|
+
*/
|
|
126
|
+
class EnochianPacket {
|
|
127
|
+
/**
|
|
128
|
+
* @param {Array<EnochianSymbol>} symbols - Sequence of symbols
|
|
129
|
+
*/
|
|
130
|
+
constructor(symbols = []) {
|
|
131
|
+
this.symbols = symbols;
|
|
132
|
+
this.timestamp = Date.now();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Add a symbol to the packet
|
|
137
|
+
*/
|
|
138
|
+
add(symbol) {
|
|
139
|
+
this.symbols.push(symbol);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get all primes in the packet
|
|
145
|
+
*/
|
|
146
|
+
primes() {
|
|
147
|
+
return this.symbols.map(s => s.prime);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get total twist
|
|
152
|
+
*/
|
|
153
|
+
totalTwist() {
|
|
154
|
+
return totalTwist(this.primes());
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Check if packet is twist-closed
|
|
159
|
+
*/
|
|
160
|
+
isTwistClosed(epsilon = 1.0) {
|
|
161
|
+
return isTwistClosed(this.primes(), epsilon);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get twist closure error (how far from closed)
|
|
166
|
+
*/
|
|
167
|
+
closureError() {
|
|
168
|
+
const twist = this.totalTwist();
|
|
169
|
+
const mod = ((twist % 360) + 360) % 360;
|
|
170
|
+
return Math.min(mod, 360 - mod);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Validate the packet
|
|
175
|
+
*/
|
|
176
|
+
validate(epsilon = 1.0) {
|
|
177
|
+
return {
|
|
178
|
+
valid: this.isTwistClosed(epsilon),
|
|
179
|
+
totalTwist: this.totalTwist(),
|
|
180
|
+
closureError: this.closureError(),
|
|
181
|
+
symbolCount: this.symbols.length
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Encode to binary buffer
|
|
187
|
+
*/
|
|
188
|
+
encode() {
|
|
189
|
+
const buffer = new Uint8Array(this.symbols.length);
|
|
190
|
+
for (let i = 0; i < this.symbols.length; i++) {
|
|
191
|
+
buffer[i] = this.symbols[i].encode();
|
|
192
|
+
}
|
|
193
|
+
return buffer;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Decode from binary buffer
|
|
198
|
+
*/
|
|
199
|
+
static decode(buffer) {
|
|
200
|
+
const symbols = [];
|
|
201
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
202
|
+
try {
|
|
203
|
+
symbols.push(EnochianSymbol.decode(buffer[i]));
|
|
204
|
+
} catch (e) {
|
|
205
|
+
// Skip invalid symbols
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return new EnochianPacket(symbols);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Encode to base64 string (browser-compatible)
|
|
213
|
+
*/
|
|
214
|
+
toBase64() {
|
|
215
|
+
const buffer = this.encode();
|
|
216
|
+
// Browser-compatible base64 encoding
|
|
217
|
+
if (typeof btoa === 'function') {
|
|
218
|
+
return btoa(String.fromCharCode.apply(null, buffer));
|
|
219
|
+
}
|
|
220
|
+
// Node.js
|
|
221
|
+
return Buffer.from(buffer).toString('base64');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Decode from base64 string (browser-compatible)
|
|
226
|
+
*/
|
|
227
|
+
static fromBase64(str) {
|
|
228
|
+
let buffer;
|
|
229
|
+
// Browser-compatible base64 decoding
|
|
230
|
+
if (typeof atob === 'function') {
|
|
231
|
+
const binary = atob(str);
|
|
232
|
+
buffer = new Uint8Array(binary.length);
|
|
233
|
+
for (let i = 0; i < binary.length; i++) {
|
|
234
|
+
buffer[i] = binary.charCodeAt(i);
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
// Node.js
|
|
238
|
+
buffer = new Uint8Array(Buffer.from(str, 'base64'));
|
|
239
|
+
}
|
|
240
|
+
return EnochianPacket.decode(buffer);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Get string representation
|
|
245
|
+
*/
|
|
246
|
+
toString() {
|
|
247
|
+
return this.symbols.map(s => s.toString()).join(' ');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
toJSON() {
|
|
251
|
+
return {
|
|
252
|
+
symbols: this.symbols.map(s => s.toJSON()),
|
|
253
|
+
totalTwist: this.totalTwist(),
|
|
254
|
+
isClosed: this.isTwistClosed(),
|
|
255
|
+
closureError: this.closureError(),
|
|
256
|
+
timestamp: this.timestamp
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Enochian Encoder
|
|
263
|
+
* Encodes semantic content into twist-closed Enochian packets
|
|
264
|
+
*/
|
|
265
|
+
class EnochianEncoder {
|
|
266
|
+
constructor(options = {}) {
|
|
267
|
+
this.epsilon = options.epsilon || 1.0;
|
|
268
|
+
this.maxIterations = options.maxIterations || 1000;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Encode a semantic hash into an Enochian packet
|
|
273
|
+
* Attempts to create a twist-closed packet
|
|
274
|
+
*
|
|
275
|
+
* @param {number} hash - Semantic hash value
|
|
276
|
+
* @param {number} minSymbols - Minimum symbols in packet
|
|
277
|
+
* @returns {EnochianPacket} Twist-closed packet
|
|
278
|
+
*/
|
|
279
|
+
encode(hash, minSymbols = 3) {
|
|
280
|
+
const symbols = [];
|
|
281
|
+
|
|
282
|
+
// Extract prime indices from hash
|
|
283
|
+
let remaining = Math.abs(hash);
|
|
284
|
+
while (remaining > 0 || symbols.length < minSymbols) {
|
|
285
|
+
const primeIdx = remaining % ENOCHIAN_PRIMES.length;
|
|
286
|
+
const modeIdx = (remaining / ENOCHIAN_PRIMES.length | 0) % 3;
|
|
287
|
+
|
|
288
|
+
symbols.push(new EnochianSymbol(
|
|
289
|
+
ENOCHIAN_PRIMES[primeIdx],
|
|
290
|
+
MODES[modeIdx]
|
|
291
|
+
));
|
|
292
|
+
|
|
293
|
+
remaining = (remaining / (ENOCHIAN_PRIMES.length * 3)) | 0;
|
|
294
|
+
|
|
295
|
+
if (remaining === 0 && symbols.length < minSymbols) {
|
|
296
|
+
remaining = symbols.length + hash;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Attempt to close the twist
|
|
301
|
+
return this.closeTwist(new EnochianPacket(symbols));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Attempt to make a packet twist-closed by adding symbols
|
|
306
|
+
*/
|
|
307
|
+
closeTwist(packet) {
|
|
308
|
+
if (packet.isTwistClosed(this.epsilon)) {
|
|
309
|
+
return packet;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Try adding symbols to close the twist
|
|
313
|
+
for (let iter = 0; iter < this.maxIterations; iter++) {
|
|
314
|
+
const currentTwist = packet.totalTwist();
|
|
315
|
+
const mod = ((currentTwist % 360) + 360) % 360;
|
|
316
|
+
|
|
317
|
+
// Find best prime to add
|
|
318
|
+
let bestPrime = ENOCHIAN_PRIMES[0];
|
|
319
|
+
let bestError = Infinity;
|
|
320
|
+
|
|
321
|
+
for (const p of ENOCHIAN_PRIMES) {
|
|
322
|
+
const newMod = ((mod + twistAngle(p)) % 360);
|
|
323
|
+
const error = Math.min(newMod, 360 - newMod);
|
|
324
|
+
if (error < bestError) {
|
|
325
|
+
bestError = error;
|
|
326
|
+
bestPrime = p;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
packet.add(new EnochianSymbol(bestPrime, MODES[iter % 3]));
|
|
331
|
+
|
|
332
|
+
if (packet.isTwistClosed(this.epsilon)) {
|
|
333
|
+
return packet;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Return best effort
|
|
338
|
+
return packet;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Encode text to Enochian packet
|
|
343
|
+
*/
|
|
344
|
+
encodeText(text) {
|
|
345
|
+
// Simple hash of text
|
|
346
|
+
let hash = 0;
|
|
347
|
+
for (let i = 0; i < text.length; i++) {
|
|
348
|
+
hash = ((hash << 5) - hash) + text.charCodeAt(i);
|
|
349
|
+
hash |= 0;
|
|
350
|
+
}
|
|
351
|
+
return this.encode(hash, Math.max(3, Math.ceil(text.length / 10)));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Encode a prime calculus term to Enochian
|
|
356
|
+
*/
|
|
357
|
+
encodeTerm(term) {
|
|
358
|
+
const sig = term.signature();
|
|
359
|
+
return this.encodeText(sig);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Enochian Decoder
|
|
365
|
+
* Decodes and validates Enochian packets
|
|
366
|
+
*/
|
|
367
|
+
class EnochianDecoder {
|
|
368
|
+
constructor(options = {}) {
|
|
369
|
+
this.epsilon = options.epsilon || 1.0;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Decode and validate a packet
|
|
374
|
+
* @param {EnochianPacket|Uint8Array|string} input
|
|
375
|
+
* @returns {Object} Decoded result with validation
|
|
376
|
+
*/
|
|
377
|
+
decode(input) {
|
|
378
|
+
let packet;
|
|
379
|
+
|
|
380
|
+
if (input instanceof EnochianPacket) {
|
|
381
|
+
packet = input;
|
|
382
|
+
} else if (input instanceof Uint8Array) {
|
|
383
|
+
packet = EnochianPacket.decode(input);
|
|
384
|
+
} else if (typeof input === 'string') {
|
|
385
|
+
packet = EnochianPacket.fromBase64(input);
|
|
386
|
+
} else {
|
|
387
|
+
return { valid: false, error: 'Invalid input type' };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const validation = packet.validate(this.epsilon);
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
valid: validation.valid,
|
|
394
|
+
packet: packet,
|
|
395
|
+
primes: packet.primes(),
|
|
396
|
+
modes: packet.symbols.map(s => s.mode),
|
|
397
|
+
totalTwist: validation.totalTwist,
|
|
398
|
+
closureError: validation.closureError,
|
|
399
|
+
symbolCount: validation.symbolCount
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Validate only (fast path for network filtering)
|
|
405
|
+
*/
|
|
406
|
+
validateOnly(input) {
|
|
407
|
+
try {
|
|
408
|
+
let packet;
|
|
409
|
+
|
|
410
|
+
if (input instanceof EnochianPacket) {
|
|
411
|
+
packet = input;
|
|
412
|
+
} else if (input instanceof Uint8Array) {
|
|
413
|
+
packet = EnochianPacket.decode(input);
|
|
414
|
+
} else if (typeof input === 'string') {
|
|
415
|
+
packet = EnochianPacket.fromBase64(input);
|
|
416
|
+
} else {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return packet.isTwistClosed(this.epsilon);
|
|
421
|
+
} catch (e) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Enochian Packet Builder
|
|
429
|
+
* Fluent API for building packets
|
|
430
|
+
*/
|
|
431
|
+
class EnochianPacketBuilder {
|
|
432
|
+
constructor() {
|
|
433
|
+
this.symbols = [];
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Add a symbol with shorthand
|
|
438
|
+
*/
|
|
439
|
+
add(prime, mode = 'α') {
|
|
440
|
+
this.symbols.push(new EnochianSymbol(prime, mode));
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Add alpha mode symbol
|
|
446
|
+
*/
|
|
447
|
+
alpha(prime) {
|
|
448
|
+
return this.add(prime, 'α');
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Add mu mode symbol
|
|
453
|
+
*/
|
|
454
|
+
mu(prime) {
|
|
455
|
+
return this.add(prime, 'μ');
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Add omega mode symbol
|
|
460
|
+
*/
|
|
461
|
+
omega(prime) {
|
|
462
|
+
return this.add(prime, 'ω');
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Build the packet
|
|
467
|
+
*/
|
|
468
|
+
build() {
|
|
469
|
+
return new EnochianPacket(this.symbols.slice());
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Get current twist
|
|
474
|
+
*/
|
|
475
|
+
currentTwist() {
|
|
476
|
+
return totalTwist(this.symbols.map(s => s.prime));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Check if current sequence is closed
|
|
481
|
+
*/
|
|
482
|
+
isClosed(epsilon = 1.0) {
|
|
483
|
+
return isTwistClosed(this.symbols.map(s => s.prime), epsilon);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Suggest next prime to close the twist
|
|
488
|
+
*/
|
|
489
|
+
suggestClosing() {
|
|
490
|
+
const current = this.currentTwist();
|
|
491
|
+
const mod = ((current % 360) + 360) % 360;
|
|
492
|
+
|
|
493
|
+
const suggestions = ENOCHIAN_PRIMES.map(p => ({
|
|
494
|
+
prime: p,
|
|
495
|
+
resultMod: ((mod + twistAngle(p)) % 360),
|
|
496
|
+
error: Math.min(
|
|
497
|
+
((mod + twistAngle(p)) % 360),
|
|
498
|
+
360 - ((mod + twistAngle(p)) % 360)
|
|
499
|
+
)
|
|
500
|
+
}));
|
|
501
|
+
|
|
502
|
+
return suggestions.sort((a, b) => a.error - b.error);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Reset builder
|
|
507
|
+
*/
|
|
508
|
+
reset() {
|
|
509
|
+
this.symbols = [];
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Precomputed twist-closed sequences
|
|
516
|
+
* Common short sequences that are twist-closed
|
|
517
|
+
*/
|
|
518
|
+
const CLOSED_SEQUENCES = [
|
|
519
|
+
// These are example closed sequences - actual values depend on epsilon
|
|
520
|
+
[7, 7, 7, 7, 7, 7, 7], // 7 sevens = 7 * 51.43 = 360
|
|
521
|
+
[11, 11, 11, 29, 29], // Approximate closure
|
|
522
|
+
[13, 13, 13, 13, 19], // Approximate closure
|
|
523
|
+
];
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Find twist-closed sequences of given length
|
|
527
|
+
*/
|
|
528
|
+
function findClosedSequences(length, epsilon = 1.0, maxResults = 10) {
|
|
529
|
+
const results = [];
|
|
530
|
+
|
|
531
|
+
function search(current, depth) {
|
|
532
|
+
if (depth === length) {
|
|
533
|
+
if (isTwistClosed(current, epsilon)) {
|
|
534
|
+
results.push(current.slice());
|
|
535
|
+
}
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (results.length >= maxResults) return;
|
|
539
|
+
|
|
540
|
+
for (const p of ENOCHIAN_PRIMES) {
|
|
541
|
+
current.push(p);
|
|
542
|
+
search(current, depth + 1);
|
|
543
|
+
current.pop();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
search([], 0);
|
|
548
|
+
return results;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* EnhancedEnochianEncoder - Extends EnochianEncoder with vocabulary support
|
|
553
|
+
*/
|
|
554
|
+
class EnhancedEnochianEncoder extends EnochianEncoder {
|
|
555
|
+
constructor(options = {}) {
|
|
556
|
+
super(options);
|
|
557
|
+
this.engine = new EnochianVocabulary.EnochianEngine();
|
|
558
|
+
this.vocabulary = EnochianVocabulary.wordLookup;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Encode an Enochian word from vocabulary
|
|
563
|
+
* @param {string} word - Enochian word (e.g., 'ZACAR', 'ZORGE')
|
|
564
|
+
*/
|
|
565
|
+
encodeWord(word) {
|
|
566
|
+
const enochianWord = this.vocabulary.get(word.toUpperCase());
|
|
567
|
+
if (enochianWord) {
|
|
568
|
+
// Use the word's primes directly
|
|
569
|
+
return this.encodeFromPrimes(enochianWord.primes);
|
|
570
|
+
}
|
|
571
|
+
// Fall back to parsing as text
|
|
572
|
+
return this.encodeText(word);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Encode from a sequence of primes
|
|
577
|
+
*/
|
|
578
|
+
encodeFromPrimes(primes) {
|
|
579
|
+
const symbols = [];
|
|
580
|
+
for (let i = 0; i < primes.length; i++) {
|
|
581
|
+
const prime = primes[i];
|
|
582
|
+
// Map to ENOCHIAN_PRIMES or use closest
|
|
583
|
+
const mappedPrime = this.findClosestEnochianPrime(prime);
|
|
584
|
+
const modeIdx = i % 3;
|
|
585
|
+
symbols.push(new EnochianSymbol(mappedPrime, MODES[modeIdx]));
|
|
586
|
+
}
|
|
587
|
+
return this.closeTwist(new EnochianPacket(symbols));
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Find closest prime in ENOCHIAN_PRIMES
|
|
592
|
+
*/
|
|
593
|
+
findClosestEnochianPrime(prime) {
|
|
594
|
+
let closest = ENOCHIAN_PRIMES[0];
|
|
595
|
+
let minDiff = Math.abs(prime - closest);
|
|
596
|
+
for (const p of ENOCHIAN_PRIMES) {
|
|
597
|
+
const diff = Math.abs(prime - p);
|
|
598
|
+
if (diff < minDiff) {
|
|
599
|
+
minDiff = diff;
|
|
600
|
+
closest = p;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return closest;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Encode a Call by number
|
|
608
|
+
*/
|
|
609
|
+
encodeCall(callNumber) {
|
|
610
|
+
const call = EnochianVocabulary.THE_NINETEEN_CALLS.find(c => c.number === callNumber);
|
|
611
|
+
if (!call) {
|
|
612
|
+
throw new Error(`Call ${callNumber} not found`);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const primes = call.getAllPrimes();
|
|
616
|
+
return this.encodeFromPrimes(primes);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Get vocabulary entry for a word
|
|
621
|
+
*/
|
|
622
|
+
getVocabularyEntry(word) {
|
|
623
|
+
return this.vocabulary.get(word.toUpperCase());
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Compute sedenion representation of encoded packet
|
|
628
|
+
*/
|
|
629
|
+
toSedenion(packet) {
|
|
630
|
+
const primes = packet.primes();
|
|
631
|
+
let result = new EnochianVocabulary.SedenionElement();
|
|
632
|
+
|
|
633
|
+
for (const p of primes) {
|
|
634
|
+
const elem = EnochianVocabulary.SedenionElement.fromBasis([p / 100]);
|
|
635
|
+
result = result.add(elem);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return result;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* EnhancedEnochianDecoder - Extends EnochianDecoder with vocabulary support
|
|
644
|
+
*/
|
|
645
|
+
class EnhancedEnochianDecoder extends EnochianDecoder {
|
|
646
|
+
constructor(options = {}) {
|
|
647
|
+
super(options);
|
|
648
|
+
this.engine = new EnochianVocabulary.EnochianEngine();
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Decode and attempt to match to vocabulary
|
|
653
|
+
*/
|
|
654
|
+
decodeWithVocabulary(input) {
|
|
655
|
+
const result = this.decode(input);
|
|
656
|
+
if (!result.valid) return result;
|
|
657
|
+
|
|
658
|
+
// Try to match primes to vocabulary words
|
|
659
|
+
const matchedWords = this.findMatchingWords(result.primes);
|
|
660
|
+
|
|
661
|
+
return {
|
|
662
|
+
...result,
|
|
663
|
+
vocabularyMatches: matchedWords,
|
|
664
|
+
sedenion: this.toSedenion(result.packet)
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Find vocabulary words that share primes with the packet
|
|
670
|
+
*/
|
|
671
|
+
findMatchingWords(primes) {
|
|
672
|
+
const primeSet = new Set(primes);
|
|
673
|
+
const matches = [];
|
|
674
|
+
|
|
675
|
+
for (const [word, wordObj] of EnochianVocabulary.wordLookup) {
|
|
676
|
+
const sharedPrimes = wordObj.primes.filter(p => primeSet.has(p));
|
|
677
|
+
if (sharedPrimes.length > 0) {
|
|
678
|
+
matches.push({
|
|
679
|
+
word: word,
|
|
680
|
+
meaning: wordObj.meaning,
|
|
681
|
+
sharedPrimes: sharedPrimes,
|
|
682
|
+
matchScore: sharedPrimes.length / wordObj.primes.length
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
return matches.sort((a, b) => b.matchScore - a.matchScore).slice(0, 5);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Convert packet to sedenion
|
|
692
|
+
*/
|
|
693
|
+
toSedenion(packet) {
|
|
694
|
+
const primes = packet.primes();
|
|
695
|
+
let result = new EnochianVocabulary.SedenionElement();
|
|
696
|
+
|
|
697
|
+
for (const p of primes) {
|
|
698
|
+
const elem = EnochianVocabulary.SedenionElement.fromBasis([p / 100]);
|
|
699
|
+
result = result.add(elem);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return result;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
module.exports = {
|
|
707
|
+
// Constants
|
|
708
|
+
ENOCHIAN_PRIMES,
|
|
709
|
+
MODES,
|
|
710
|
+
MODE_INDEX,
|
|
711
|
+
CLOSED_SEQUENCES,
|
|
712
|
+
|
|
713
|
+
// Functions
|
|
714
|
+
twistAngle,
|
|
715
|
+
totalTwist,
|
|
716
|
+
isTwistClosed,
|
|
717
|
+
findClosedSequences,
|
|
718
|
+
|
|
719
|
+
// Classes
|
|
720
|
+
EnochianSymbol,
|
|
721
|
+
EnochianPacket,
|
|
722
|
+
EnochianEncoder,
|
|
723
|
+
EnochianDecoder,
|
|
724
|
+
EnochianPacketBuilder,
|
|
725
|
+
|
|
726
|
+
// Enhanced classes with vocabulary support
|
|
727
|
+
EnhancedEnochianEncoder,
|
|
728
|
+
EnhancedEnochianDecoder,
|
|
729
|
+
|
|
730
|
+
// Re-export vocabulary module
|
|
731
|
+
EnochianVocabulary,
|
|
732
|
+
|
|
733
|
+
// Convenience re-exports from vocabulary
|
|
734
|
+
ENOCHIAN_ALPHABET: EnochianVocabulary.ENOCHIAN_ALPHABET,
|
|
735
|
+
PRIME_BASIS: EnochianVocabulary.PRIME_BASIS,
|
|
736
|
+
CORE_VOCABULARY: EnochianVocabulary.CORE_VOCABULARY,
|
|
737
|
+
THE_NINETEEN_CALLS: EnochianVocabulary.THE_NINETEEN_CALLS,
|
|
738
|
+
EnochianWord: EnochianVocabulary.EnochianWord,
|
|
739
|
+
EnochianCall: EnochianVocabulary.EnochianCall,
|
|
740
|
+
EnochianEngine: EnochianVocabulary.EnochianEngine,
|
|
741
|
+
SedenionElement: EnochianVocabulary.SedenionElement,
|
|
742
|
+
TwistOperator: EnochianVocabulary.TwistOperator,
|
|
743
|
+
validateTwistClosure: EnochianVocabulary.validateTwistClosure
|
|
744
|
+
};
|