@hviana/sema 0.1.5 → 0.1.7

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