@hviana/sema 0.1.3 → 0.1.5

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 (123) hide show
  1. package/dist/example/demo.js +25 -25
  2. package/dist/example/train_base.d.ts +21 -19
  3. package/dist/example/train_base.js +1952 -1684
  4. package/dist/src/alphabet.d.ts +3 -3
  5. package/dist/src/alphabet.js +27 -24
  6. package/dist/src/alu/src/alu.d.ts +194 -169
  7. package/dist/src/alu/src/alu.js +414 -374
  8. package/dist/src/alu/src/expr.d.ts +43 -36
  9. package/dist/src/alu/src/expr.js +278 -252
  10. package/dist/src/alu/src/index.d.ts +98 -9
  11. package/dist/src/alu/src/index.js +63 -9
  12. package/dist/src/alu/src/kernel-arith.d.ts +5 -1
  13. package/dist/src/alu/src/kernel-arith.js +285 -195
  14. package/dist/src/alu/src/kernel-bits.d.ts +5 -1
  15. package/dist/src/alu/src/kernel-bits.js +115 -81
  16. package/dist/src/alu/src/kernel-logic.js +63 -33
  17. package/dist/src/alu/src/kernel-nd.js +195 -155
  18. package/dist/src/alu/src/kernel-numeric.d.ts +80 -16
  19. package/dist/src/alu/src/kernel-numeric.js +331 -259
  20. package/dist/src/alu/src/operation.d.ts +132 -112
  21. package/dist/src/alu/src/operation.js +163 -149
  22. package/dist/src/alu/src/parser.d.ts +175 -168
  23. package/dist/src/alu/src/parser.js +421 -382
  24. package/dist/src/alu/src/resonance.d.ts +25 -16
  25. package/dist/src/alu/src/resonance.js +56 -49
  26. package/dist/src/alu/src/text.d.ts +7 -3
  27. package/dist/src/alu/src/text.js +37 -31
  28. package/dist/src/alu/src/value.d.ts +14 -14
  29. package/dist/src/alu/src/value.js +160 -150
  30. package/dist/src/alu/test/alu.test.js +656 -543
  31. package/dist/src/bytes.d.ts +5 -1
  32. package/dist/src/bytes.js +40 -33
  33. package/dist/src/config.d.ts +102 -102
  34. package/dist/src/config.js +83 -83
  35. package/dist/src/derive/src/deduction.d.ts +62 -60
  36. package/dist/src/derive/src/deduction.js +109 -103
  37. package/dist/src/derive/src/index.d.ts +7 -1
  38. package/dist/src/derive/src/priority-queue.d.ts +8 -8
  39. package/dist/src/derive/src/priority-queue.js +61 -57
  40. package/dist/src/derive/src/rewrite.d.ts +18 -15
  41. package/dist/src/derive/src/rewrite.js +67 -59
  42. package/dist/src/derive/src/trie.d.ts +56 -56
  43. package/dist/src/derive/src/trie.js +179 -175
  44. package/dist/src/derive/test/derive.test.js +100 -96
  45. package/dist/src/extension.d.ts +16 -13
  46. package/dist/src/geometry.d.ts +42 -17
  47. package/dist/src/geometry.js +266 -235
  48. package/dist/src/index.d.ts +17 -2
  49. package/dist/src/index.js +7 -1
  50. package/dist/src/ingest-cache.d.ts +30 -25
  51. package/dist/src/ingest-cache.js +127 -108
  52. package/dist/src/mind/articulation.d.ts +5 -1
  53. package/dist/src/mind/articulation.js +112 -77
  54. package/dist/src/mind/attention.d.ts +108 -40
  55. package/dist/src/mind/attention.js +871 -749
  56. package/dist/src/mind/canonical.d.ts +19 -4
  57. package/dist/src/mind/canonical.js +31 -27
  58. package/dist/src/mind/graph-search.d.ts +225 -201
  59. package/dist/src/mind/graph-search.js +821 -742
  60. package/dist/src/mind/index.d.ts +10 -2
  61. package/dist/src/mind/junction.d.ts +58 -31
  62. package/dist/src/mind/junction.js +237 -172
  63. package/dist/src/mind/learning.d.ts +52 -16
  64. package/dist/src/mind/learning.js +165 -143
  65. package/dist/src/mind/match.d.ts +69 -20
  66. package/dist/src/mind/match.js +318 -259
  67. package/dist/src/mind/mechanisms/alu.js +16 -16
  68. package/dist/src/mind/mechanisms/cast.d.ts +13 -9
  69. package/dist/src/mind/mechanisms/cast.js +456 -363
  70. package/dist/src/mind/mechanisms/confluence.d.ts +12 -8
  71. package/dist/src/mind/mechanisms/confluence.js +183 -152
  72. package/dist/src/mind/mechanisms/cover.d.ts +8 -2
  73. package/dist/src/mind/mechanisms/cover.js +210 -148
  74. package/dist/src/mind/mechanisms/extraction.d.ts +34 -8
  75. package/dist/src/mind/mechanisms/extraction.js +288 -234
  76. package/dist/src/mind/mechanisms/recall.d.ts +10 -6
  77. package/dist/src/mind/mechanisms/recall.js +185 -126
  78. package/dist/src/mind/mind.d.ts +154 -129
  79. package/dist/src/mind/mind.js +288 -258
  80. package/dist/src/mind/pipeline-mechanism.d.ts +124 -112
  81. package/dist/src/mind/pipeline-mechanism.js +172 -161
  82. package/dist/src/mind/pipeline.d.ts +14 -4
  83. package/dist/src/mind/pipeline.js +189 -125
  84. package/dist/src/mind/primitives.d.ts +32 -8
  85. package/dist/src/mind/primitives.js +117 -99
  86. package/dist/src/mind/rationale.d.ts +98 -86
  87. package/dist/src/mind/rationale.js +121 -113
  88. package/dist/src/mind/reasoning.d.ts +13 -2
  89. package/dist/src/mind/reasoning.js +166 -129
  90. package/dist/src/mind/recognition.d.ts +4 -1
  91. package/dist/src/mind/recognition.js +208 -183
  92. package/dist/src/mind/resonance.d.ts +22 -5
  93. package/dist/src/mind/resonance.js +0 -0
  94. package/dist/src/mind/trace.d.ts +25 -6
  95. package/dist/src/mind/trace.js +58 -50
  96. package/dist/src/mind/traverse.d.ts +58 -16
  97. package/dist/src/mind/traverse.js +357 -304
  98. package/dist/src/mind/types.d.ts +127 -120
  99. package/dist/src/mind/types.js +69 -60
  100. package/dist/src/rabitq-hnsw/src/database.d.ts +179 -177
  101. package/dist/src/rabitq-hnsw/src/database.js +359 -342
  102. package/dist/src/rabitq-hnsw/src/heap.d.ts +12 -12
  103. package/dist/src/rabitq-hnsw/src/heap.js +80 -75
  104. package/dist/src/rabitq-hnsw/src/hnsw.d.ts +103 -103
  105. package/dist/src/rabitq-hnsw/src/hnsw.js +454 -428
  106. package/dist/src/rabitq-hnsw/src/index.d.ts +6 -1
  107. package/dist/src/rabitq-hnsw/src/prng.d.ts +10 -10
  108. package/dist/src/rabitq-hnsw/src/prng.js +27 -25
  109. package/dist/src/rabitq-hnsw/src/rabitq.d.ts +69 -69
  110. package/dist/src/rabitq-hnsw/src/rabitq.js +262 -246
  111. package/dist/src/rabitq-hnsw/src/store.d.ts +132 -132
  112. package/dist/src/rabitq-hnsw/src/store.js +843 -752
  113. package/dist/src/rabitq-hnsw/test/hnsw.test.js +1054 -805
  114. package/dist/src/sema.d.ts +35 -0
  115. package/dist/src/sema.js +77 -0
  116. package/dist/src/store-sqlite.d.ts +166 -144
  117. package/dist/src/store-sqlite.js +660 -578
  118. package/dist/src/store.d.ts +630 -593
  119. package/dist/src/store.js +1581 -1440
  120. package/dist/src/vec.d.ts +9 -5
  121. package/dist/src/vec.js +73 -61
  122. package/package.json +2 -2
  123. package/src/sema.ts +102 -0
@@ -6,9 +6,9 @@ export type ApplyScalar = (name: string, args: number[]) => number;
6
6
  /** Whether a name is a registered unary function the evaluator may call. */
7
7
  export type IsUnaryFn = (name: string) => boolean;
8
8
  export interface Token {
9
- kind: "num" | "name" | "op" | "lparen" | "rparen";
10
- text: string;
11
- value?: number;
9
+ kind: "num" | "name" | "op" | "lparen" | "rparen";
10
+ text: string;
11
+ value?: number;
12
12
  }
13
13
  /** Tokenize an expression string: numerals (the irreducible floor), operator
14
14
  * tokens (matched longest-first against `operators` — the registry's own
@@ -16,46 +16,53 @@ export interface Token {
16
16
  * vocabulary is given, each symbolic character stands alone (enough for name
17
17
  * extraction). Returns null when a character fits none of these — the span is
18
18
  * not a clean expression. */
19
- export declare function tokenize(s: string, operators?: readonly string[]): Token[] | null;
19
+ export declare function tokenize(
20
+ s: string,
21
+ operators?: readonly string[],
22
+ ): Token[] | null;
20
23
  /** The identifiers in `s` that are NOT known unary functions and NOT registered
21
24
  * constants — the free-variable candidates. Used to auto-detect the variable
22
25
  * when the caller did not name one. */
23
- export declare function freeVariables(s: string, isUnaryFn: IsUnaryFn, isConstant?: (name: string) => boolean): string[];
26
+ export declare function freeVariables(
27
+ s: string,
28
+ isUnaryFn: IsUnaryFn,
29
+ isConstant?: (name: string) => boolean,
30
+ ): string[];
24
31
  /** The expression grammar, read off an operation registry once and reused for
25
32
  * every evaluation. It resolves each token through the registry's own form
26
33
  * index — infix binding from the `infix` trait, a prefix operator as the
27
34
  * arity-1 claimant of a shared symbol, functions as arity-1 ops, constants as
28
35
  * arity-0 ops — so the grammar and the kernel can never drift apart. */
29
36
  export declare class ExprGrammar {
30
- private readonly registry;
31
- private readonly applyScalar;
32
- /** Symbolic operator tokens, longest first (so "<=" wins over "<"). */
33
- private readonly operatorTokens;
34
- /** token → the infix op it names and its declared binding. */
35
- private readonly infixTable;
36
- /** token → the arity-1 (prefix) op it names. */
37
- private readonly prefixTable;
38
- /** The tightest infix tier — a prefix operator binds its operand up through
39
- * it, so "-x^2" reads -(x^2) without a hardcoded rule. */
40
- private readonly maxPrecedence;
41
- constructor(registry: OperationRegistry, applyScalar: ApplyScalar);
42
- /** Resolve an identifier to a registered op of the given arity: a surface
43
- * form claimant of that arity first, else the canonical name itself. */
44
- private resolveName;
45
- /** Whether an identifier names a unary function. */
46
- isFunction(name: string): boolean;
47
- /** Whether an identifier names a nullary constant (an arity-0 op). */
48
- isConstant(name: string): boolean;
49
- /** Tokenize with this grammar's operator vocabulary. */
50
- tokenize(s: string): Token[] | null;
51
- /** The free-variable candidates of `s` under this grammar. */
52
- freeVariables(s: string): string[];
53
- /** Evaluate expression `s` with `variable` bound to `at`. Returns a number,
54
- * or null if `s` is not a well-formed expression. Every binary/function/
55
- * constant step is applied through the kernel, so the arithmetic is the
56
- * kernel's own. When `variable` is empty, the single free variable is
57
- * auto-detected; if there is more than one and none was named, evaluation
58
- * declines (null) — a genuinely multivariate expression needs an explicit
59
- * binding. */
60
- eval(s: string, variable: string, at: number): number | null;
37
+ private readonly registry;
38
+ private readonly applyScalar;
39
+ /** Symbolic operator tokens, longest first (so "<=" wins over "<"). */
40
+ private readonly operatorTokens;
41
+ /** token → the infix op it names and its declared binding. */
42
+ private readonly infixTable;
43
+ /** token → the arity-1 (prefix) op it names. */
44
+ private readonly prefixTable;
45
+ /** The tightest infix tier — a prefix operator binds its operand up through
46
+ * it, so "-x^2" reads -(x^2) without a hardcoded rule. */
47
+ private readonly maxPrecedence;
48
+ constructor(registry: OperationRegistry, applyScalar: ApplyScalar);
49
+ /** Resolve an identifier to a registered op of the given arity: a surface
50
+ * form claimant of that arity first, else the canonical name itself. */
51
+ private resolveName;
52
+ /** Whether an identifier names a unary function. */
53
+ isFunction(name: string): boolean;
54
+ /** Whether an identifier names a nullary constant (an arity-0 op). */
55
+ isConstant(name: string): boolean;
56
+ /** Tokenize with this grammar's operator vocabulary. */
57
+ tokenize(s: string): Token[] | null;
58
+ /** The free-variable candidates of `s` under this grammar. */
59
+ freeVariables(s: string): string[];
60
+ /** Evaluate expression `s` with `variable` bound to `at`. Returns a number,
61
+ * or null if `s` is not a well-formed expression. Every binary/function/
62
+ * constant step is applied through the kernel, so the arithmetic is the
63
+ * kernel's own. When `variable` is empty, the single free variable is
64
+ * auto-detected; if there is more than one and none was named, evaluation
65
+ * declines (null) — a genuinely multivariate expression needs an explicit
66
+ * binding. */
67
+ eval(s: string, variable: string, at: number): number | null;
61
68
  }