@hviana/sema 0.1.5 → 0.1.6
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/AGENTS.md +6 -5
- package/CITATION.cff +49 -0
- package/HOW_IT_WORKS.md +11 -12
- package/README.md +7 -5
- package/dist/example/demo.js +25 -25
- package/dist/example/train_base.d.ts +19 -21
- package/dist/example/train_base.js +1687 -1952
- package/dist/src/alphabet.d.ts +3 -3
- package/dist/src/alphabet.js +24 -27
- package/dist/src/alu/src/alu.d.ts +169 -194
- package/dist/src/alu/src/alu.js +374 -414
- package/dist/src/alu/src/expr.d.ts +36 -43
- package/dist/src/alu/src/expr.js +252 -278
- package/dist/src/alu/src/index.d.ts +9 -98
- package/dist/src/alu/src/index.js +10 -64
- package/dist/src/alu/src/kernel-arith.d.ts +1 -5
- package/dist/src/alu/src/kernel-arith.js +195 -285
- package/dist/src/alu/src/kernel-bits.d.ts +1 -5
- package/dist/src/alu/src/kernel-bits.js +81 -115
- package/dist/src/alu/src/kernel-logic.js +33 -63
- package/dist/src/alu/src/kernel-nd.js +155 -195
- package/dist/src/alu/src/kernel-numeric.d.ts +16 -80
- package/dist/src/alu/src/kernel-numeric.js +259 -331
- package/dist/src/alu/src/operation.d.ts +112 -132
- package/dist/src/alu/src/operation.js +149 -163
- package/dist/src/alu/src/parser.d.ts +168 -175
- package/dist/src/alu/src/parser.js +382 -421
- package/dist/src/alu/src/resonance.d.ts +16 -25
- package/dist/src/alu/src/resonance.js +49 -56
- package/dist/src/alu/src/text.d.ts +3 -7
- package/dist/src/alu/src/text.js +31 -37
- package/dist/src/alu/src/value.d.ts +14 -14
- package/dist/src/alu/src/value.js +150 -160
- package/dist/src/alu/test/alu.test.js +543 -656
- package/dist/src/bytes.d.ts +1 -5
- package/dist/src/bytes.js +33 -40
- package/dist/src/config.d.ts +99 -102
- package/dist/src/config.js +78 -83
- package/dist/src/derive/src/deduction.d.ts +60 -62
- package/dist/src/derive/src/deduction.js +103 -109
- package/dist/src/derive/src/index.d.ts +1 -7
- package/dist/src/derive/src/priority-queue.d.ts +8 -8
- package/dist/src/derive/src/priority-queue.js +57 -61
- package/dist/src/derive/src/rewrite.d.ts +15 -18
- package/dist/src/derive/src/rewrite.js +59 -67
- package/dist/src/derive/src/trie.d.ts +56 -56
- package/dist/src/derive/src/trie.js +175 -179
- package/dist/src/derive/test/derive.test.js +96 -100
- package/dist/src/extension.d.ts +13 -16
- package/dist/src/geometry.d.ts +17 -42
- package/dist/src/geometry.js +235 -266
- package/dist/src/index.d.ts +2 -17
- package/dist/src/index.js +2 -12
- package/dist/src/ingest-cache.d.ts +25 -30
- package/dist/src/ingest-cache.js +108 -127
- package/dist/src/mind/articulation.d.ts +1 -5
- package/dist/src/mind/articulation.js +77 -112
- package/dist/src/mind/attention.d.ts +40 -108
- package/dist/src/mind/attention.js +749 -871
- package/dist/src/mind/canonical.d.ts +4 -19
- package/dist/src/mind/canonical.js +27 -31
- package/dist/src/mind/graph-search.d.ts +201 -225
- package/dist/src/mind/graph-search.js +742 -821
- package/dist/src/mind/index.d.ts +2 -10
- package/dist/src/mind/junction.d.ts +31 -58
- package/dist/src/mind/junction.js +172 -237
- package/dist/src/mind/learning.d.ts +16 -52
- package/dist/src/mind/learning.js +143 -165
- package/dist/src/mind/match.d.ts +20 -69
- package/dist/src/mind/match.js +259 -318
- package/dist/src/mind/mechanisms/alu.js +16 -16
- package/dist/src/mind/mechanisms/cast.d.ts +9 -13
- package/dist/src/mind/mechanisms/cast.js +363 -456
- package/dist/src/mind/mechanisms/confluence.d.ts +8 -12
- package/dist/src/mind/mechanisms/confluence.js +152 -183
- package/dist/src/mind/mechanisms/cover.d.ts +2 -8
- package/dist/src/mind/mechanisms/cover.js +148 -210
- package/dist/src/mind/mechanisms/extraction.d.ts +8 -34
- package/dist/src/mind/mechanisms/extraction.js +234 -288
- package/dist/src/mind/mechanisms/recall.d.ts +6 -10
- package/dist/src/mind/mechanisms/recall.js +126 -185
- package/dist/src/mind/mind.d.ts +129 -154
- package/dist/src/mind/mind.js +258 -288
- package/dist/src/mind/pipeline-mechanism.d.ts +112 -124
- package/dist/src/mind/pipeline-mechanism.js +161 -172
- package/dist/src/mind/pipeline.d.ts +4 -14
- package/dist/src/mind/pipeline.js +125 -189
- package/dist/src/mind/primitives.d.ts +8 -32
- package/dist/src/mind/primitives.js +99 -117
- package/dist/src/mind/rationale.d.ts +86 -98
- package/dist/src/mind/rationale.js +113 -121
- package/dist/src/mind/reasoning.d.ts +2 -13
- package/dist/src/mind/reasoning.js +129 -166
- package/dist/src/mind/recognition.d.ts +1 -4
- package/dist/src/mind/recognition.js +183 -208
- package/dist/src/mind/resonance.d.ts +5 -22
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +6 -25
- package/dist/src/mind/trace.js +50 -58
- package/dist/src/mind/traverse.d.ts +16 -58
- package/dist/src/mind/traverse.js +304 -357
- package/dist/src/mind/types.d.ts +120 -127
- package/dist/src/mind/types.js +60 -69
- package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
- package/dist/src/rabitq-ivf/src/database.js +201 -0
- package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
- package/dist/src/{rabitq-hnsw → rabitq-ivf}/src/index.js +1 -3
- package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
- package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
- package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
- package/dist/src/rabitq-ivf/src/prng.js +36 -0
- package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
- package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
- package/dist/src/sema.d.ts +9 -13
- package/dist/src/sema.js +26 -40
- package/dist/src/store-sqlite.d.ts +169 -166
- package/dist/src/store-sqlite.js +762 -662
- package/dist/src/store.d.ts +586 -630
- package/dist/src/store.js +1423 -1581
- package/dist/src/vec.d.ts +5 -9
- package/dist/src/vec.js +61 -73
- package/example/train_base.ts +13 -10
- package/package.json +1 -1
- package/src/alu/README.md +1 -1
- package/src/alu/src/index.ts +1 -1
- package/src/config.ts +19 -27
- package/src/index.ts +6 -11
- package/src/rabitq-ivf/README.md +56 -0
- package/src/rabitq-ivf/src/database.ts +276 -0
- package/src/{rabitq-hnsw → rabitq-ivf}/src/index.ts +2 -5
- package/src/rabitq-ivf/src/ivf.ts +1330 -0
- package/src/{rabitq-hnsw → rabitq-ivf}/src/prng.ts +1 -1
- package/src/store-sqlite.ts +196 -9
- package/src/store.ts +8 -32
- package/test/08-storage.test.mjs +3 -3
- package/test/14-scaling.test.mjs +2 -2
- package/test/35-ivf.test.mjs +263 -0
- package/test/36-bloom.test.mjs +123 -0
- package/dist/src/rabitq-hnsw/src/database.d.ts +0 -202
- package/dist/src/rabitq-hnsw/src/database.js +0 -405
- package/dist/src/rabitq-hnsw/src/heap.d.ts +0 -22
- package/dist/src/rabitq-hnsw/src/heap.js +0 -94
- package/dist/src/rabitq-hnsw/src/hnsw.d.ts +0 -125
- package/dist/src/rabitq-hnsw/src/hnsw.js +0 -500
- package/dist/src/rabitq-hnsw/src/index.d.ts +0 -15
- package/dist/src/rabitq-hnsw/src/prng.d.ts +0 -19
- package/dist/src/rabitq-hnsw/src/prng.js +0 -38
- package/dist/src/rabitq-hnsw/src/rabitq.d.ts +0 -95
- package/dist/src/rabitq-hnsw/src/rabitq.js +0 -299
- package/dist/src/rabitq-hnsw/src/store.d.ts +0 -162
- package/dist/src/rabitq-hnsw/src/store.js +0 -916
- package/dist/src/rabitq-hnsw/test/hnsw.test.d.ts +0 -1
- package/dist/src/rabitq-hnsw/test/hnsw.test.js +0 -1197
- package/src/rabitq-hnsw/README.md +0 -303
- package/src/rabitq-hnsw/src/database.ts +0 -492
- package/src/rabitq-hnsw/src/heap.ts +0 -90
- package/src/rabitq-hnsw/src/hnsw.ts +0 -514
- package/src/rabitq-hnsw/src/store.ts +0 -994
- package/src/rabitq-hnsw/test/hnsw.test.ts +0 -1213
- /package/src/{rabitq-hnsw → rabitq-ivf}/src/rabitq.ts +0 -0
package/dist/src/alphabet.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vec } from "./vec.js";
|
|
2
2
|
import type { AlphabetConfig } from "./config.js";
|
|
3
3
|
export declare class Alphabet {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
readonly vecs: Vec[];
|
|
5
|
+
readonly config: AlphabetConfig;
|
|
6
|
+
constructor(seed: number, D: number, config?: Partial<AlphabetConfig>);
|
|
7
7
|
}
|
package/dist/src/alphabet.js
CHANGED
|
@@ -5,32 +5,29 @@
|
|
|
5
5
|
// resonate; far-apart values are quasi-orthogonal.
|
|
6
6
|
import { addInto, copy, normalize, randomUnit, rng } from "./vec.js";
|
|
7
7
|
export class Alphabet {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
vecs = [];
|
|
9
|
+
config;
|
|
10
|
+
constructor(seed, D, config) {
|
|
11
|
+
this.config = {
|
|
12
|
+
roughness: config?.roughness ?? 0.65,
|
|
13
|
+
seedMask: config?.seedMask ?? 0xa1fa17,
|
|
14
|
+
};
|
|
15
|
+
const rand = rng((seed ^ this.config.seedMask) >>> 0);
|
|
16
|
+
const refine = (parent) => {
|
|
17
|
+
const v = copy(parent);
|
|
18
|
+
for (let i = 0; i < v.length; i++) {
|
|
19
|
+
v[i] *= Math.sqrt(1 - this.config.roughness);
|
|
20
|
+
}
|
|
21
|
+
addInto(v, randomUnit(D, rand), Math.sqrt(this.config.roughness));
|
|
22
|
+
return normalize(v);
|
|
23
|
+
};
|
|
24
|
+
const coarse = [];
|
|
25
|
+
for (let i = 0; i < 16; i++)
|
|
26
|
+
coarse.push(randomUnit(D, rand));
|
|
27
|
+
const mid = [];
|
|
28
|
+
for (let i = 0; i < 64; i++)
|
|
29
|
+
mid.push(refine(coarse[i >> 2]));
|
|
30
|
+
for (let b = 0; b < 256; b++)
|
|
31
|
+
this.vecs.push(refine(mid[b >> 2]));
|
|
27
32
|
}
|
|
28
|
-
const mid = [];
|
|
29
|
-
for (let i = 0; i < 64; i++) {
|
|
30
|
-
mid.push(refine(coarse[i >> 2]));
|
|
31
|
-
}
|
|
32
|
-
for (let b = 0; b < 256; b++) {
|
|
33
|
-
this.vecs.push(refine(mid[b >> 2]));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
33
|
}
|
|
@@ -5,206 +5,181 @@ import type { ConceptAnchor } from "./resonance.js";
|
|
|
5
5
|
import { type AluHost, type ComputedSpan } from "./parser.js";
|
|
6
6
|
/** A numeric literal found in the byte stream, with its parsed value. */
|
|
7
7
|
export interface OperandSpan {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
i: number;
|
|
9
|
+
j: number;
|
|
10
|
+
value: Value;
|
|
11
11
|
}
|
|
12
12
|
/** A recognised operator span: the byte range and the canonical op it names. */
|
|
13
13
|
export interface OperatorSpan {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
i: number;
|
|
15
|
+
j: number;
|
|
16
|
+
name: string;
|
|
17
|
+
/** Operand count for INFIX use — a fixed arity as registered, or 2 for a
|
|
18
|
+
* variadic op used as a binary infix operator. */
|
|
19
|
+
arity: number;
|
|
20
20
|
}
|
|
21
21
|
/** Options for assembling an {@link Alu}. */
|
|
22
22
|
export interface AluOptions {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/** Decimal places a real result is rounded to before encoding (determinism). */
|
|
24
|
+
precision?: number;
|
|
25
|
+
/** Numerical convergence tolerance and iteration ceiling. */
|
|
26
|
+
tol?: number;
|
|
27
|
+
maxIter?: number;
|
|
28
28
|
}
|
|
29
29
|
export declare class Alu {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
resonance?: ResonanceSync
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
name: string,
|
|
185
|
-
operandBytes: Uint8Array[],
|
|
186
|
-
resonance?: ResonanceSync,
|
|
187
|
-
): Uint8Array | null;
|
|
188
|
-
/** Apply `name` to operand VALUES (a scalar, or an `nd` recognised by {@link
|
|
189
|
-
* recogniseValue}), and encode the result canonically. This is the entry
|
|
190
|
-
* point for computation over STRUCTURE: the scalar kernel and the nd kernel
|
|
191
|
-
* both consume Values, so once a span is recognised the computation is the
|
|
192
|
-
* same whether the operand came in as a number or a list. Returns null on any
|
|
193
|
-
* failure (unknown op, thrown computation), the same "this rule does not fire"
|
|
194
|
-
* contract as {@link applyBytes}. */
|
|
195
|
-
applyValues(
|
|
196
|
-
name: string,
|
|
197
|
-
operands: Value[],
|
|
198
|
-
resonance?: ResonanceSync,
|
|
199
|
-
): Uint8Array | null;
|
|
200
|
-
/** Like {@link applyBytes}, but `asSymbol(idx)` marks operand positions that
|
|
201
|
-
* must be kept as an opaque SYMBOL (not parsed as a number) — the convention
|
|
202
|
-
* the numerical layer needs, where operand 0 is an EXPRESSION (a function's
|
|
203
|
-
* bytes) the kernel samples via the expression evaluator, not a numeral. */
|
|
204
|
-
applyBytesTyped(
|
|
205
|
-
name: string,
|
|
206
|
-
operandBytes: Uint8Array[],
|
|
207
|
-
asSymbol: (idx: number) => boolean,
|
|
208
|
-
resonance?: ResonanceSync,
|
|
209
|
-
): Uint8Array | null;
|
|
30
|
+
readonly registry: OperationRegistry;
|
|
31
|
+
readonly codec: ValueCodec;
|
|
32
|
+
private readonly rt;
|
|
33
|
+
/** Symbolic operator forms (no ASCII letter/digit), as byte patterns, sorted
|
|
34
|
+
* longest-first so the scanner matches "<=" before "<". */
|
|
35
|
+
private readonly symbolicForms;
|
|
36
|
+
private _grammar?;
|
|
37
|
+
private _anchors?;
|
|
38
|
+
/** How many {@link apply} calls ended in a caught throw this session, and
|
|
39
|
+
* the most recent caught error. A caught throw is USUALLY a routine
|
|
40
|
+
* decline (a symbol fed to arithmetic — the "rule does not fire"
|
|
41
|
+
* contract), but the same catch would also swallow a genuine kernel bug;
|
|
42
|
+
* these two fields make that observable instead of silent. Zero cost when
|
|
43
|
+
* nothing throws. */
|
|
44
|
+
applyCaught: number;
|
|
45
|
+
lastApplyError: unknown;
|
|
46
|
+
private readonly decoder;
|
|
47
|
+
/** The query parser, wired to the host port — internal; hosts reach it only
|
|
48
|
+
* through {@link parse} and {@link compute}. */
|
|
49
|
+
private readonly parser;
|
|
50
|
+
constructor(opts?: AluOptions, host?: AluHost);
|
|
51
|
+
/** Recognise and evaluate every computation `query` invokes — infix
|
|
52
|
+
* arithmetic runs, and operations named literally or by meaning (through the
|
|
53
|
+
* host port). All async resonance is resolved inside, so the caller
|
|
54
|
+
* receives finished spans it can fold synchronously into its search. See
|
|
55
|
+
* {@link "./parser.js".QueryParser.parse}. */
|
|
56
|
+
parse(query: Uint8Array): Promise<ComputedSpan[]>;
|
|
57
|
+
/** Apply an operation to operand byte spans — operand STRUCTURE recognised
|
|
58
|
+
* into Values, every reachable symbol's resonance pre-resolved through the
|
|
59
|
+
* host port — and encode the result canonically; null when the computation
|
|
60
|
+
* declines. See {@link "./parser.js".QueryParser.compute}. */
|
|
61
|
+
compute(name: string, operandBytes: Uint8Array[], asSymbol?: (idx: number) => boolean): Promise<Uint8Array | null>;
|
|
62
|
+
/** Infix arity of an op: its fixed arity, or 2 for a variadic op (an infix
|
|
63
|
+
* operator binds two operands; the registry's variadic fold still accepts
|
|
64
|
+
* the pair). */
|
|
65
|
+
private infixArity;
|
|
66
|
+
/** Collect the symbolic surface forms (punctuation, no letters/digits) as
|
|
67
|
+
* UTF-8 byte patterns. Each maps to the binary claimant when one exists, so
|
|
68
|
+
* an infix scan resolves a shared symbol to its two-operand reading. */
|
|
69
|
+
private buildSymbolicForms;
|
|
70
|
+
/** The canonical op name(s) a literal surface form names (exact lookup). */
|
|
71
|
+
lookupOperator(form: string): readonly string[];
|
|
72
|
+
/** The operation CONCEPT anchors: the (canonical name, form bytes) pairs a
|
|
73
|
+
* span's MEANING is resonated against, so an operation the bytes do not
|
|
74
|
+
* literally spell (an integral, a derivative, a limit, …, in any modality)
|
|
75
|
+
* is recognised by gist nearness to one of these forms. This is what makes
|
|
76
|
+
* operation recognition generic and modality-agnostic rather than a fixed
|
|
77
|
+
* symbol table — and the ALU, not the host, decides which of its surface
|
|
78
|
+
* forms are anchors, using its own machinery:
|
|
79
|
+
*
|
|
80
|
+
* • a form the SCANNER already reads in full (a pure operator symbol like
|
|
81
|
+
* "<=", a numeral like "0") is excluded — the literal path owns it, and
|
|
82
|
+
* its meaning-space image would only add noise;
|
|
83
|
+
* • a form must be COMPOUND (≥ 2 runes): a single atom's gist is a
|
|
84
|
+
* coordinate of the alphabet, not a distributional meaning, so there is
|
|
85
|
+
* nothing for resonance to read.
|
|
86
|
+
*
|
|
87
|
+
* Cached once; the stable array identity lets the host memoise whatever
|
|
88
|
+
* representation (gists, indices) it derives from it. */
|
|
89
|
+
conceptAnchors(): ReadonlyArray<ConceptAnchor>;
|
|
90
|
+
/** The registry-derived expression grammar, built once: infix binding and
|
|
91
|
+
* prefix/function/constant resolution all read off the registered ops, and
|
|
92
|
+
* every evaluation step routes back through this registry's own arithmetic —
|
|
93
|
+
* recursion all the way down (see expr.ts). */
|
|
94
|
+
get grammar(): ExprGrammar;
|
|
95
|
+
/** Evaluate an expression's bytes at a variable binding, through this
|
|
96
|
+
* registry's own arithmetic (see {@link grammar}). */
|
|
97
|
+
evalExpression(bytes: Uint8Array, variable: string, at: number): number | null;
|
|
98
|
+
/** Whether a name is a registered operation. */
|
|
99
|
+
has(name: string): boolean;
|
|
100
|
+
/** The infix arity of a registered op (for the host to size a rule), or 0. */
|
|
101
|
+
arityOf(name: string): number;
|
|
102
|
+
/** Whether an op acts on an EXPRESSION (a function) rather than plain numbers
|
|
103
|
+
* — declared by the op itself at registration (the `expression` trait), so
|
|
104
|
+
* there is no side table of names here. */
|
|
105
|
+
isExpressionOp(name: string): boolean;
|
|
106
|
+
/** Scan a byte span for operand (numeric) and operator (symbolic) spans. A
|
|
107
|
+
* pure, deterministic left-to-right lexer: at each position take a numeral if
|
|
108
|
+
* one starts there, else the longest symbolic operator form, else skip one
|
|
109
|
+
* byte. Numerals and operator symbols are disjoint character classes, so the
|
|
110
|
+
* two never overlap. */
|
|
111
|
+
scan(bytes: Uint8Array): {
|
|
112
|
+
operands: OperandSpan[];
|
|
113
|
+
operators: OperatorSpan[];
|
|
114
|
+
};
|
|
115
|
+
private matchSymbolic;
|
|
116
|
+
/** Read a byte span into a {@link Value} by recognising its STRUCTURE — the
|
|
117
|
+
* byte⇄Value boundary the host computes across. The kernel itself only knows
|
|
118
|
+
* the irreducible scalar floor (a numeral's digits → a quantity, via {@link
|
|
119
|
+
* parseValue}); recognising whether a span is one quantity or a LIST of them is
|
|
120
|
+
* layered here, over {@link scan}, so no caller re-implements it.
|
|
121
|
+
*
|
|
122
|
+
* A LIST is a run of element values joined by a CONSISTENT separator. No
|
|
123
|
+
* spelling is privileged: two complementary readings cover the forms a list
|
|
124
|
+
* takes —
|
|
125
|
+
*
|
|
126
|
+
* • CONTAINER — an explicit `[ … ]` group delimits a list whose elements may
|
|
127
|
+
* be anything (symbols, nested groups, mixed): split its interior at the TOP
|
|
128
|
+
* level (bracket-depth aware) on separator runs, each element recognised in
|
|
129
|
+
* turn (so nesting and heterogeneity recurse for free). This is also the
|
|
130
|
+
* codec's canonical OUTPUT spelling, so a computed list feeds straight back
|
|
131
|
+
* in as an operand.
|
|
132
|
+
* • SEQUENCE — a bare run of ≥2 numeric operands with a consistent connective
|
|
133
|
+
* between them (`1 2 3`, `1, 2, 3`, `1 and 2 and 3`): the operands {@link
|
|
134
|
+
* scan} finds are the elements, and whatever sits between them — a space, a
|
|
135
|
+
* comma, " and " — is the separator, accepted as long as it is the same
|
|
136
|
+
* throughout and the run has no leftover edges.
|
|
137
|
+
*
|
|
138
|
+
* Anything else is a SCALAR ({@link parseValue}): a numeral, or an opaque
|
|
139
|
+
* symbol of any modality (a learnt form, an operator name a higher-order op
|
|
140
|
+
* will resolve, a single word). */
|
|
141
|
+
recogniseValue(bytes: Uint8Array): Value;
|
|
142
|
+
/** Split a CONTAINER's interior into its element values — top-level (bracket-
|
|
143
|
+
* depth aware) spans divided by separator RUNS (maximal runs of {@link
|
|
144
|
+
* isSepByte}). The brackets are the explicit delimiter, so the divider's
|
|
145
|
+
* spelling is not privileged (`[1,2,3]`, `[1, 2, 3]`, `[1 2 3]` are the same
|
|
146
|
+
* list). Each element is recognised in turn, so a nested `[ … ]` element
|
|
147
|
+
* recurses and a symbol element stays opaque. An empty interior is `[]`. */
|
|
148
|
+
private recogniseContainer;
|
|
149
|
+
/** Recognise a bare SEQUENCE — ≥2 numeric operands separated by a consistent
|
|
150
|
+
* connective, with no leftover material at the edges — or null when the span
|
|
151
|
+
* is not such a sequence. The operands are exactly the ones {@link scan}
|
|
152
|
+
* finds; the bytes between consecutive operands are the separator, which need
|
|
153
|
+
* only be the SAME throughout (a space, a comma, " and ", …) — its spelling is
|
|
154
|
+
* not constrained, so no separator is privileged. */
|
|
155
|
+
private recogniseSequence;
|
|
156
|
+
/** Apply an op to operand values, with the given pre-resolved resonance.
|
|
157
|
+
* Returns the result value, or null if the op is unknown or the computation
|
|
158
|
+
* throws (e.g. a symbol fed to arithmetic) — the caller treats null as "this
|
|
159
|
+
* rule does not fire", never as a wrong answer. */
|
|
160
|
+
apply(name: string, operands: Value[], resonance?: ResonanceSync): Value | null;
|
|
161
|
+
/** The expression evaluator handed to op contexts, bound to the cached {@link
|
|
162
|
+
* grammar}: the numerical layer's integrand is evaluated by a recursive
|
|
163
|
+
* application of the same derived-from-nand arithmetic. */
|
|
164
|
+
private makeEvalExpr;
|
|
165
|
+
/** Decode operand byte spans, apply `name`, and encode the result — the pure
|
|
166
|
+
* computation the graph rule materialises into an output span. Returns null
|
|
167
|
+
* on any failure (unknown op, undecodable operand, thrown computation), so a
|
|
168
|
+
* rule that cannot compute simply does not fire. The result bytes are
|
|
169
|
+
* canonical (see {@link decimalCodec}), so two derivations of the same value
|
|
170
|
+
* agree byte-for-byte — required for the search's chart memoization. */
|
|
171
|
+
applyBytes(name: string, operandBytes: Uint8Array[], resonance?: ResonanceSync): Uint8Array | null;
|
|
172
|
+
/** Apply `name` to operand VALUES (a scalar, or an `nd` recognised by {@link
|
|
173
|
+
* recogniseValue}), and encode the result canonically. This is the entry
|
|
174
|
+
* point for computation over STRUCTURE: the scalar kernel and the nd kernel
|
|
175
|
+
* both consume Values, so once a span is recognised the computation is the
|
|
176
|
+
* same whether the operand came in as a number or a list. Returns null on any
|
|
177
|
+
* failure (unknown op, thrown computation), the same "this rule does not fire"
|
|
178
|
+
* contract as {@link applyBytes}. */
|
|
179
|
+
applyValues(name: string, operands: Value[], resonance?: ResonanceSync): Uint8Array | null;
|
|
180
|
+
/** Like {@link applyBytes}, but `asSymbol(idx)` marks operand positions that
|
|
181
|
+
* must be kept as an opaque SYMBOL (not parsed as a number) — the convention
|
|
182
|
+
* the numerical layer needs, where operand 0 is an EXPRESSION (a function's
|
|
183
|
+
* bytes) the kernel samples via the expression evaluator, not a numeral. */
|
|
184
|
+
applyBytesTyped(name: string, operandBytes: Uint8Array[], asSymbol: (idx: number) => boolean, resonance?: ResonanceSync): Uint8Array | null;
|
|
210
185
|
}
|