@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
|
@@ -2,13 +2,13 @@ import type { Alu } from "./alu.js";
|
|
|
2
2
|
import { type ConceptAnchor } from "./resonance.js";
|
|
3
3
|
/** A half-open byte range. */
|
|
4
4
|
export interface Span {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
i: number;
|
|
6
|
+
j: number;
|
|
7
7
|
}
|
|
8
8
|
/** A computation the parser recognised and evaluated: the query span [i, j) it
|
|
9
9
|
* is authoritative for, and the canonical result bytes. */
|
|
10
10
|
export interface ComputedSpan extends Span {
|
|
11
|
-
|
|
11
|
+
bytes: Uint8Array;
|
|
12
12
|
}
|
|
13
13
|
/** The port through which the parser reaches its host. This interface is the
|
|
14
14
|
* ENTIRE coupling surface between the ALU and any host: the ALU imports
|
|
@@ -37,13 +37,10 @@ export interface ComputedSpan extends Span {
|
|
|
37
37
|
* host's own grouping capacity, so adjacency is judged by the same
|
|
38
38
|
* geometry that groups the host's perception. */
|
|
39
39
|
export interface AluHost {
|
|
40
|
-
|
|
41
|
-
bytes: Uint8Array
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
continuation(bytes: Uint8Array): Promise<Uint8Array | null>;
|
|
45
|
-
segment(bytes: Uint8Array): Span[];
|
|
46
|
-
reach: number;
|
|
40
|
+
meaningOf(bytes: Uint8Array, anchors: ReadonlyArray<ConceptAnchor>): Promise<string | null>;
|
|
41
|
+
continuation(bytes: Uint8Array): Promise<Uint8Array | null>;
|
|
42
|
+
segment(bytes: Uint8Array): Span[];
|
|
43
|
+
reach: number;
|
|
47
44
|
}
|
|
48
45
|
/** A host that knows nothing beyond structure: no resonance, whitespace-run
|
|
49
46
|
* segmentation, unbounded reach. This is what "the ALU runs fully decoupled"
|
|
@@ -51,169 +48,165 @@ export interface AluHost {
|
|
|
51
48
|
* paths stay silent. */
|
|
52
49
|
export declare const STRUCTURAL_HOST: AluHost;
|
|
53
50
|
export declare class QueryParser {
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
* or filler — "of", "at", "the"), while a bare atom carries none and can
|
|
216
|
-
* only be the expression's free variable. Dropping the filler leaves the
|
|
217
|
-
* evaluator clean notation. */
|
|
218
|
-
private cleanExprText;
|
|
51
|
+
private readonly alu;
|
|
52
|
+
private readonly host;
|
|
53
|
+
/** The host's generic capabilities, specialised once into the {@link
|
|
54
|
+
* AluResonance} the prefetch bridges consume — the ONE place the ALU gives
|
|
55
|
+
* the host's neutral answers their computational reading: op recognition is
|
|
56
|
+
* meaningOf over the ALU's own concept anchors, and the polymorphic INVERSE
|
|
57
|
+
* of a symbol is the corpus's grounded continuation of it (a learnt
|
|
58
|
+
* opposition relation leads from a form to its opposite; the host never
|
|
59
|
+
* needs to know that is what it grounded). */
|
|
60
|
+
private readonly resonance;
|
|
61
|
+
/** Session memo of a term's meaning-based op reading, keyed by its bytes.
|
|
62
|
+
* `meaningOf` is a full river fold of the span — measured at ~a third of
|
|
63
|
+
* a plain-English respond's latency, paid per WORD per query — and it is
|
|
64
|
+
* a pure function of the bytes (perception is pure; the concept anchors
|
|
65
|
+
* are fixed for the Alu's lifetime), so the reading never changes.
|
|
66
|
+
* Bounded: cleared wholesale when full (words recur; a rare clear only
|
|
67
|
+
* re-pays folds, never changes a reading). */
|
|
68
|
+
private readonly meaningMemo;
|
|
69
|
+
private static readonly MEANING_MEMO_MAX;
|
|
70
|
+
constructor(alu: Alu, host?: AluHost);
|
|
71
|
+
/** Recognise and evaluate every computation `query` invokes. All async
|
|
72
|
+
* resonance is resolved in here, so the caller receives finished spans it
|
|
73
|
+
* can fold synchronously into its search. Results are deduplicated; a span
|
|
74
|
+
* that fails to compute is simply absent (the "rule does not fire"
|
|
75
|
+
* contract).
|
|
76
|
+
*
|
|
77
|
+
* The pipeline is one composition ladder, iterated to a FIXPOINT:
|
|
78
|
+
*
|
|
79
|
+
* 1. infix arithmetic RUNS are found and evaluated through the
|
|
80
|
+
* registry-derived grammar;
|
|
81
|
+
* 2. every computed span — a run, or a fired operation — is COLLAPSED
|
|
82
|
+
* into a single virtual operand, so the next round consumes it as one
|
|
83
|
+
* finished value: "sum 1*3 4" is add(3, 4), and "sqrt sum 9 16" is
|
|
84
|
+
* sqrt(25) — nesting by iteration, exactly as the grammar nests
|
|
85
|
+
* expressions, with no recursion machinery of its own;
|
|
86
|
+
* 3. rounds repeat while operations still fire (each round consumes at
|
|
87
|
+
* least one term, so the ladder is bounded by the term count).
|
|
88
|
+
*
|
|
89
|
+
* One AUTHORITY law then reconciles the readings: a span strictly
|
|
90
|
+
* contained in a larger computed span is that computation's MATERIAL (the
|
|
91
|
+
* "2-4" inside a solve's "x^2-4", the inner sum under a sqrt), not a rival
|
|
92
|
+
* result — the same rule by which the host's search lets a computed span
|
|
93
|
+
* override colliding learned facts. */
|
|
94
|
+
parse(query: Uint8Array): Promise<ComputedSpan[]>;
|
|
95
|
+
/** Apply an ALU operation to operand byte spans, with the host's resonance
|
|
96
|
+
* wired in — the entry point for computation over n-dimensional values.
|
|
97
|
+
*
|
|
98
|
+
* Unlike the in-query arithmetic rule (which hands the facade scalar operand
|
|
99
|
+
* bytes), this recognises each operand's STRUCTURE into a Value first and
|
|
100
|
+
* runs the kernel on the finished Values, with the full resonance snapshot
|
|
101
|
+
* pre-resolved — because an nd computation needs meaning in two places the
|
|
102
|
+
* bare facade cannot reach on its own:
|
|
103
|
+
*
|
|
104
|
+
* • the polymorphic INVERSE inside a broadcast — `inverse [large, 3, tall]`
|
|
105
|
+
* lifts element-wise (operation.ts), and each symbol element's opposite
|
|
106
|
+
* is a resonant lookup, grounded in the host's corpus exactly as a scalar
|
|
107
|
+
* inverse is;
|
|
108
|
+
* • the FUNCTION ARGUMENT of a higher-order op — `reduce(xs, ‹+›)`,
|
|
109
|
+
* `map(xs, ‹negate›)`: the operator value is resolved by
|
|
110
|
+
* {@link "./operation.js".OpContext.resolveOp}, which falls through to
|
|
111
|
+
* resonance when the bytes are not a literal surface form.
|
|
112
|
+
*
|
|
113
|
+
* Both are async, so every SYMBOL span reachable in the operands (recursing
|
|
114
|
+
* through nd nesting, see {@link "./value.js".symbolSpans}) is resolved ONCE
|
|
115
|
+
* up front into a synchronous snapshot, and the synchronous kernel computes
|
|
116
|
+
* against it. Returns null when the op is unknown or the computation
|
|
117
|
+
* declines — the "this rule does not fire" contract.
|
|
118
|
+
*
|
|
119
|
+
* `asSymbol(idx)` keeps an operand opaque (not read as structure or a
|
|
120
|
+
* number) — the numerical-layer convention where operand 0 is an
|
|
121
|
+
* expression's bytes; it defaults to "recognise everything", which is what
|
|
122
|
+
* an nd computation wants. */
|
|
123
|
+
compute(name: string, operandBytes: Uint8Array[], asSymbol?: (idx: number) => boolean): Promise<Uint8Array | null>;
|
|
124
|
+
/** Lex the query ONCE into a single ascending token stream: the facade's
|
|
125
|
+
* scanner claims numeric OPERANDS and symbolic OPERATORS, and every maximal
|
|
126
|
+
* unclaimed run between spacing bytes is a TERM — a word, glyph, or opaque
|
|
127
|
+
* fragment that may name an operation. Terms are deliberately bounded by
|
|
128
|
+
* the spacing floor, not the host's geometric segmentation: perception may
|
|
129
|
+
* cut mid-word (its segments are grouping capacity, not word boundaries),
|
|
130
|
+
* while an operation NAME is a notation-level token. Geometry still
|
|
131
|
+
* governs what happens BETWEEN tokens (gap bridging, operand reach).
|
|
132
|
+
*
|
|
133
|
+
* Tokens are disjoint, ascending, and cover every non-spacing byte — so
|
|
134
|
+
* the gap between consecutive tokens is pure spacing BY CONSTRUCTION, a
|
|
135
|
+
* structural fact the run recogniser leans on. */
|
|
136
|
+
private lex;
|
|
137
|
+
/** The maximal infix-arithmetic runs in the query: an alternation of numeric
|
|
138
|
+
* operands and SYMBOLIC operators (e.g. "2+3*4"), returned as [start, end)
|
|
139
|
+
* ranges that begin and end on an operand.
|
|
140
|
+
*
|
|
141
|
+
* Consecutive tokens may be SEPARATED — "3 + 3" is the same run as "3+3".
|
|
142
|
+
* The gap between two tokens is a bridgeable separator exactly when the
|
|
143
|
+
* host's geometric segmenter reads it as at most one coherent run — the
|
|
144
|
+
* same judgement the perception tree makes about spacing — so no character
|
|
145
|
+
* is privileged as "the" separator. */
|
|
146
|
+
private arithmeticRuns;
|
|
147
|
+
/** Evaluate an infix-arithmetic run to its canonical result bytes, through
|
|
148
|
+
* the kernel's recursive expression evaluator, or null if it does not
|
|
149
|
+
* evaluate. A whole result stays an exact int; otherwise the canonical
|
|
150
|
+
* rounded real — deterministic, so the search's chart memoises identical
|
|
151
|
+
* results identically. */
|
|
152
|
+
private evalRun;
|
|
153
|
+
/** Recognise and apply the operations the query's TERMS name — the generic,
|
|
154
|
+
* multimodal path. A term may name an operation literally (its bytes are a
|
|
155
|
+
* registered surface form — no resonance cost) or by RESONANCE (its gist
|
|
156
|
+
* lands on an operation's concept, any modality).
|
|
157
|
+
*
|
|
158
|
+
* Recognition PROPOSES, application DISPOSES: a surface form may be shared
|
|
159
|
+
* by several operations ("zero" is both the constant and solve's
|
|
160
|
+
* root-finding), so every literal claimant is kept, in registration order,
|
|
161
|
+
* and the first whose application actually fires wins — disambiguation by
|
|
162
|
+
* what the query supplies, not by a precedence table. Recognition runs
|
|
163
|
+
* CONCURRENTLY — each term's reading is independent — and is memoised in
|
|
164
|
+
* `readings` across fixpoint rounds (a surviving term is the same token
|
|
165
|
+
* object), so each term resonates at most once per parse. Application is
|
|
166
|
+
* then ordered and deterministic: an EXPRESSION op takes the function that
|
|
167
|
+
* follows it ({@link applyToExpression}), any other op takes its arity's
|
|
168
|
+
* worth of operands from the stream ({@link applyToStream}). Both read
|
|
169
|
+
* the same composed stream — an expression's TEXT comes from the raw query
|
|
170
|
+
* bytes by position, so composition never disturbs it, while a composed
|
|
171
|
+
* operand serves as a finished point/bound or argument. */
|
|
172
|
+
private operations;
|
|
173
|
+
/** Apply a NUMERICAL-LAYER op — one whose first operand is an EXPRESSION (a
|
|
174
|
+
* function), declared by the op's own `expression` trait. The registry's
|
|
175
|
+
* arity says how many trailing numeric operands are its points/bounds
|
|
176
|
+
* (arity − 1); the bytes between the operator and those points — with
|
|
177
|
+
* non-math filler stripped by {@link cleanExprText} — are the expression,
|
|
178
|
+
* evaluated by a recursive application of the kernel. */
|
|
179
|
+
private applyToExpression;
|
|
180
|
+
/** Apply any other op to the OPERAND STREAM after the operator: the numeric
|
|
181
|
+
* operands and symbol terms that follow it, merged nearest-first, each
|
|
182
|
+
* within the host's reach of the token before it — so "sqrt 144",
|
|
183
|
+
* "gcd 12 18", and "opposite large" are one rule, and the NEAREST token is
|
|
184
|
+
* the operand ("opposite large 5" inverts "large", not the 5).
|
|
185
|
+
*
|
|
186
|
+
* Two structural refinements make this read like notation rather than a
|
|
187
|
+
* special case:
|
|
188
|
+
*
|
|
189
|
+
* • WORD-INFIX — an under-supplied operator borrows the numeric operand
|
|
190
|
+
* immediately BEFORE it (within reach), so "7 minus 2" applies
|
|
191
|
+
* subtract(7, 2) exactly as "7 - 2" would: a synonym is notation too.
|
|
192
|
+
* • GROUNDED-ONLY SYMBOLS — when every operand is a symbol, a result that
|
|
193
|
+
* merely echoes an operand means resonance grounded nothing (an inverse
|
|
194
|
+
* with no learnt opposition), and the rule stays silent rather than
|
|
195
|
+
* invent meaning. Numeric identities ("max 3 7" → "7") are real
|
|
196
|
+
* results and pass.
|
|
197
|
+
*
|
|
198
|
+
* A NULLARY op never fires from a bare term: a computation must consume
|
|
199
|
+
* something, or any prose word that happens to name a constant would be
|
|
200
|
+
* rewritten. Symbol operands get their resonance (the opposite each may
|
|
201
|
+
* need) pre-resolved in one prefetch. */
|
|
202
|
+
private applyToStream;
|
|
203
|
+
/** Strip non-math filler tokens from a raw expression string — keep numbers,
|
|
204
|
+
* operators, parens, names the GRAMMAR resolves (unary functions,
|
|
205
|
+
* registered constants), and single-RUNE identifiers. The rune rule is the
|
|
206
|
+
* mirror of {@link "./alu.js".Alu.conceptAnchors}' compound rule: a compound
|
|
207
|
+
* name carries distributional meaning (it is either a resolvable operation
|
|
208
|
+
* or filler — "of", "at", "the"), while a bare atom carries none and can
|
|
209
|
+
* only be the expression's free variable. Dropping the filler leaves the
|
|
210
|
+
* evaluator clean notation. */
|
|
211
|
+
private cleanExprText;
|
|
219
212
|
}
|