solve-engine 1.0.0-beta.0 → 1.0.0-beta.2
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/dist/BytecodeBuilder-3egMyuDi.d.cts +274 -0
- package/dist/BytecodeBuilder-3egMyuDi.d.ts +274 -0
- package/dist/Configuration-fVpd-HC-.d.cts +228 -0
- package/dist/Configuration-fVpd-HC-.d.ts +228 -0
- package/dist/EngineError-DvPSnhZi.d.cts +304 -0
- package/dist/EngineError-DvPSnhZi.d.ts +304 -0
- package/dist/Lexer-BJdhlnej.d.cts +531 -0
- package/dist/Lexer-D9l4Yrk2.d.ts +531 -0
- package/dist/NormalizerRule-BrVoVjmP.d.cts +163 -0
- package/dist/NormalizerRule-CEjf1FyD.d.ts +163 -0
- package/dist/PackageRegistry-D-Tv_7ca.d.cts +2572 -0
- package/dist/PackageRegistry-DaH4aIKP.d.ts +2572 -0
- package/dist/Parselet-CK8cQu2a.d.cts +299 -0
- package/dist/Parselet-ConOIdRO.d.ts +299 -0
- package/dist/ScopeManager-B5k0nk05.d.ts +559 -0
- package/dist/ScopeManager-CKfQtl7l.d.cts +559 -0
- package/dist/Token-0jpvUdPY.d.cts +245 -0
- package/dist/Token-0jpvUdPY.d.ts +245 -0
- package/dist/VMCheckpoints-BmDwIXgK.d.ts +171 -0
- package/dist/VMCheckpoints-CqFuLwrT.d.cts +171 -0
- package/dist/Value-KtAQNHur.d.cts +295 -0
- package/dist/Value-KtAQNHur.d.ts +295 -0
- package/dist/chunk-2RWAXT6O.js +3 -0
- package/dist/chunk-2RWAXT6O.js.map +1 -0
- package/dist/chunk-34RRD7PC.js +1492 -0
- package/dist/chunk-34RRD7PC.js.map +1 -0
- package/dist/chunk-3PPFLFH4.js +5097 -0
- package/dist/chunk-3PPFLFH4.js.map +1 -0
- package/dist/chunk-3VGDNEE3.js +84 -0
- package/dist/chunk-3VGDNEE3.js.map +1 -0
- package/dist/chunk-3YNVWKR2.cjs +370 -0
- package/dist/chunk-3YNVWKR2.cjs.map +1 -0
- package/dist/chunk-47LRVGOT.cjs +316 -0
- package/dist/chunk-47LRVGOT.cjs.map +1 -0
- package/dist/chunk-4MG4XKO2.js +1644 -0
- package/dist/chunk-4MG4XKO2.js.map +1 -0
- package/dist/chunk-4QADQTWS.js +2392 -0
- package/dist/chunk-4QADQTWS.js.map +1 -0
- package/dist/chunk-53B6KDDJ.cjs +1651 -0
- package/dist/chunk-53B6KDDJ.cjs.map +1 -0
- package/dist/chunk-5X2PTP6F.cjs +104 -0
- package/dist/chunk-5X2PTP6F.cjs.map +1 -0
- package/dist/chunk-5YEMOYSE.js +264 -0
- package/dist/chunk-5YEMOYSE.js.map +1 -0
- package/dist/chunk-64W6GLLZ.js +481 -0
- package/dist/chunk-64W6GLLZ.js.map +1 -0
- package/dist/chunk-6BKTCEUP.cjs +233 -0
- package/dist/chunk-6BKTCEUP.cjs.map +1 -0
- package/dist/chunk-6NTVRDQV.cjs +1642 -0
- package/dist/chunk-6NTVRDQV.cjs.map +1 -0
- package/dist/chunk-6RDSQURE.js +290 -0
- package/dist/chunk-6RDSQURE.js.map +1 -0
- package/dist/chunk-75JP4BZX.js +93 -0
- package/dist/chunk-75JP4BZX.js.map +1 -0
- package/dist/chunk-B7LXJ6LC.cjs +36 -0
- package/dist/chunk-B7LXJ6LC.cjs.map +1 -0
- package/dist/chunk-BVAR5J2F.js +257 -0
- package/dist/chunk-BVAR5J2F.js.map +1 -0
- package/dist/chunk-C4XZV6E7.cjs +269 -0
- package/dist/chunk-C4XZV6E7.cjs.map +1 -0
- package/dist/chunk-CCJPSHGI.cjs +40 -0
- package/dist/chunk-CCJPSHGI.cjs.map +1 -0
- package/dist/chunk-CLL7RUQV.cjs +316 -0
- package/dist/chunk-CLL7RUQV.cjs.map +1 -0
- package/dist/chunk-DM3LMRBC.js +329 -0
- package/dist/chunk-DM3LMRBC.js.map +1 -0
- package/dist/chunk-DUEZFTK2.js +38 -0
- package/dist/chunk-DUEZFTK2.js.map +1 -0
- package/dist/chunk-EBSPLUW4.cjs +489 -0
- package/dist/chunk-EBSPLUW4.cjs.map +1 -0
- package/dist/chunk-EHAHVROS.cjs +261 -0
- package/dist/chunk-EHAHVROS.cjs.map +1 -0
- package/dist/chunk-EIGTWK5N.js +167 -0
- package/dist/chunk-EIGTWK5N.js.map +1 -0
- package/dist/chunk-EPOXXJBK.js +96 -0
- package/dist/chunk-EPOXXJBK.js.map +1 -0
- package/dist/chunk-FEAIOR7N.cjs +91 -0
- package/dist/chunk-FEAIOR7N.cjs.map +1 -0
- package/dist/chunk-G535KJEG.js +312 -0
- package/dist/chunk-G535KJEG.js.map +1 -0
- package/dist/chunk-GCM5JHMX.js +88 -0
- package/dist/chunk-GCM5JHMX.js.map +1 -0
- package/dist/chunk-GOLDJNMZ.js +368 -0
- package/dist/chunk-GOLDJNMZ.js.map +1 -0
- package/dist/chunk-GW32KPCU.cjs +360 -0
- package/dist/chunk-GW32KPCU.cjs.map +1 -0
- package/dist/chunk-HTXVVJRA.cjs +1549 -0
- package/dist/chunk-HTXVVJRA.cjs.map +1 -0
- package/dist/chunk-HWSZJQCI.js +311 -0
- package/dist/chunk-HWSZJQCI.js.map +1 -0
- package/dist/chunk-IF532O7C.js +101 -0
- package/dist/chunk-IF532O7C.js.map +1 -0
- package/dist/chunk-J73SJHR3.cjs +2415 -0
- package/dist/chunk-J73SJHR3.cjs.map +1 -0
- package/dist/chunk-JBSYC7BB.cjs +7473 -0
- package/dist/chunk-JBSYC7BB.cjs.map +1 -0
- package/dist/chunk-KVILKGMS.js +228 -0
- package/dist/chunk-KVILKGMS.js.map +1 -0
- package/dist/chunk-LIPPNDBE.js +258 -0
- package/dist/chunk-LIPPNDBE.js.map +1 -0
- package/dist/chunk-LR7YASZF.cjs +172 -0
- package/dist/chunk-LR7YASZF.cjs.map +1 -0
- package/dist/chunk-M4N5GA5Z.cjs +309 -0
- package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
- package/dist/chunk-M5LX5AOO.js +7459 -0
- package/dist/chunk-M5LX5AOO.js.map +1 -0
- package/dist/chunk-MZOVP3WI.cjs +96 -0
- package/dist/chunk-MZOVP3WI.cjs.map +1 -0
- package/dist/chunk-N5YFR4UP.cjs +10 -0
- package/dist/chunk-N5YFR4UP.cjs.map +1 -0
- package/dist/chunk-NGBBNL4K.cjs +4 -0
- package/dist/chunk-NGBBNL4K.cjs.map +1 -0
- package/dist/chunk-NH2O2AUR.js +146 -0
- package/dist/chunk-NH2O2AUR.js.map +1 -0
- package/dist/chunk-NLNDMWZC.js +31 -0
- package/dist/chunk-NLNDMWZC.js.map +1 -0
- package/dist/chunk-NMCRQP3Z.cjs +778 -0
- package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
- package/dist/chunk-NMD5VRN4.cjs +1327 -0
- package/dist/chunk-NMD5VRN4.cjs.map +1 -0
- package/dist/chunk-OC6LTXYS.cjs +286 -0
- package/dist/chunk-OC6LTXYS.cjs.map +1 -0
- package/dist/chunk-OT6OJY7C.cjs +114 -0
- package/dist/chunk-OT6OJY7C.cjs.map +1 -0
- package/dist/chunk-PFSDGGYL.js +8 -0
- package/dist/chunk-PFSDGGYL.js.map +1 -0
- package/dist/chunk-QNJ4ACRT.cjs +155 -0
- package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
- package/dist/chunk-QWY3VEZN.js +1637 -0
- package/dist/chunk-QWY3VEZN.js.map +1 -0
- package/dist/chunk-RFYD5TJE.js +111 -0
- package/dist/chunk-RFYD5TJE.js.map +1 -0
- package/dist/chunk-RIN643A3.js +354 -0
- package/dist/chunk-RIN643A3.js.map +1 -0
- package/dist/chunk-RZCWSXTA.cjs +5122 -0
- package/dist/chunk-RZCWSXTA.cjs.map +1 -0
- package/dist/chunk-SDGRK7EP.js +774 -0
- package/dist/chunk-SDGRK7EP.js.map +1 -0
- package/dist/chunk-VEKIWQ3F.cjs +39 -0
- package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
- package/dist/chunk-WQTTOGXC.cjs +99 -0
- package/dist/chunk-WQTTOGXC.cjs.map +1 -0
- package/dist/chunk-X6K3HUOY.cjs +86 -0
- package/dist/chunk-X6K3HUOY.cjs.map +1 -0
- package/dist/chunk-XJCMXB2E.cjs +333 -0
- package/dist/chunk-XJCMXB2E.cjs.map +1 -0
- package/dist/chunk-XVWCOTR6.js +1324 -0
- package/dist/chunk-XVWCOTR6.js.map +1 -0
- package/dist/chunk-YLJ4XMA6.js +33 -0
- package/dist/chunk-YLJ4XMA6.js.map +1 -0
- package/dist/chunk-Z2XP767T.cjs +35 -0
- package/dist/chunk-Z2XP767T.cjs.map +1 -0
- package/dist/chunk-Z4X2RWOF.js +37 -0
- package/dist/chunk-Z4X2RWOF.js.map +1 -0
- package/dist/constants.cjs +22 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +12 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/engine.cjs +79 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +587 -0
- package/dist/engine.d.ts +587 -0
- package/dist/engine.js +34 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.cjs +81 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +95 -0
- package/dist/errors.d.ts +95 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/format.cjs +171 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +51 -0
- package/dist/format.d.ts +51 -0
- package/dist/format.js +168 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +152 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/language.cjs +308 -0
- package/dist/language.cjs.map +1 -0
- package/dist/language.d.cts +110 -0
- package/dist/language.d.ts +110 -0
- package/dist/language.js +287 -0
- package/dist/language.js.map +1 -0
- package/dist/lexer.cjs +64 -0
- package/dist/lexer.cjs.map +1 -0
- package/dist/lexer.d.cts +56 -0
- package/dist/lexer.d.ts +56 -0
- package/dist/lexer.js +11 -0
- package/dist/lexer.js.map +1 -0
- package/dist/normalizer.cjs +40 -0
- package/dist/normalizer.cjs.map +1 -0
- package/dist/normalizer.d.cts +364 -0
- package/dist/normalizer.d.ts +364 -0
- package/dist/normalizer.js +11 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/packages.cjs +121 -0
- package/dist/packages.cjs.map +1 -0
- package/dist/packages.d.cts +691 -0
- package/dist/packages.d.ts +691 -0
- package/dist/packages.js +24 -0
- package/dist/packages.js.map +1 -0
- package/dist/parser.cjs +55 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +46 -0
- package/dist/parser.d.ts +46 -0
- package/dist/parser.js +10 -0
- package/dist/parser.js.map +1 -0
- package/dist/pipeline-CrsRPmsv.d.ts +285 -0
- package/dist/pipeline-DPUQt7yL.d.cts +285 -0
- package/dist/resolvers.cjs +13 -0
- package/dist/resolvers.cjs.map +1 -0
- package/dist/resolvers.d.cts +111 -0
- package/dist/resolvers.d.ts +111 -0
- package/dist/resolvers.js +4 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/services.cjs +21 -0
- package/dist/services.cjs.map +1 -0
- package/dist/services.d.cts +30 -0
- package/dist/services.d.ts +30 -0
- package/dist/services.js +4 -0
- package/dist/services.js.map +1 -0
- package/dist/uom.cjs +56 -0
- package/dist/uom.cjs.map +1 -0
- package/dist/uom.d.cts +224 -0
- package/dist/uom.d.ts +224 -0
- package/dist/uom.js +11 -0
- package/dist/uom.js.map +1 -0
- package/dist/utilities.cjs +32 -0
- package/dist/utilities.cjs.map +1 -0
- package/dist/utilities.d.cts +113 -0
- package/dist/utilities.d.ts +113 -0
- package/dist/utilities.js +7 -0
- package/dist/utilities.js.map +1 -0
- package/dist/variables.cjs +17 -0
- package/dist/variables.cjs.map +1 -0
- package/dist/variables.d.cts +87 -0
- package/dist/variables.d.ts +87 -0
- package/dist/variables.js +4 -0
- package/dist/variables.js.map +1 -0
- package/dist/vm.cjs +284 -0
- package/dist/vm.cjs.map +1 -0
- package/dist/vm.d.cts +68 -0
- package/dist/vm.d.ts +68 -0
- package/dist/vm.js +194 -0
- package/dist/vm.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact rational arithmetic over `bigint`, the coefficient type for every
|
|
3
|
+
* part of the symbolic algebra system.
|
|
4
|
+
*
|
|
5
|
+
* A computer-algebra system cannot work in IEEE doubles. Factoring
|
|
6
|
+
* `x^2 - x/3 - 2/3` needs `1/3` to stay `1/3` rather than becoming
|
|
7
|
+
* `0.3333333333333333`, and the rational-root theorem tests candidate roots
|
|
8
|
+
* by exact division, where a rounding error is indistinguishable from a
|
|
9
|
+
* genuine root. Every coefficient in `SymbolicNode`, `Polynomial`, `Factor`
|
|
10
|
+
* and `Solve` is a Rational for that reason.
|
|
11
|
+
*
|
|
12
|
+
* Values are always normalized on construction (`d > 0n`, `gcd(|n|, d) === 1n`,
|
|
13
|
+
* zero is exactly `0n/1n`), so structural equality on the `{n, d}` pair is
|
|
14
|
+
* mathematical equality, and the pair can be used directly as a cache key.
|
|
15
|
+
*
|
|
16
|
+
* A Rational holds two `bigint`s. Structured clone, which is what the
|
|
17
|
+
* playground's `postMessage` uses to ship a `SymbolicNode` to the VM trace
|
|
18
|
+
* view, handles bigint correctly. `JSON.stringify` does not: it throws
|
|
19
|
+
* `TypeError: Do not know how to serialize a BigInt`. Do not introduce a JSON
|
|
20
|
+
* round-trip anywhere a Rational can reach.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* An exact rational number.
|
|
24
|
+
*
|
|
25
|
+
* Always normalized, see this module's own doc comment for the invariant.
|
|
26
|
+
* Construct via {@link rational} or {@link rationalFromNumber} rather than as
|
|
27
|
+
* an object literal, which would bypass normalization.
|
|
28
|
+
*/
|
|
29
|
+
interface Rational {
|
|
30
|
+
/** Signed numerator. Carries the sign of the whole value. */
|
|
31
|
+
readonly n: bigint;
|
|
32
|
+
/** Denominator, always strictly positive. */
|
|
33
|
+
readonly d: bigint;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Exact complex arithmetic over the Gaussian rationals.
|
|
38
|
+
*
|
|
39
|
+
* Both components are {@link Rational}, so this is exact in the same sense the
|
|
40
|
+
* rest of the system is: `(1+2i)/(3-4i)` has an exact answer and gets it,
|
|
41
|
+
* rather than a pair of doubles that are nearly right. That matters most where
|
|
42
|
+
* a complex value has to be recognised as zero, which is how a cubic's
|
|
43
|
+
* *casus irreducibilis* is detected and how a conjugate pair cancels.
|
|
44
|
+
*
|
|
45
|
+
* ## Why the number tower stops here
|
|
46
|
+
*
|
|
47
|
+
* Real values stay {@link Rational} throughout. A complex value only appears
|
|
48
|
+
* when something genuinely produces one: a negative discriminant, a square root
|
|
49
|
+
* of a negative number, or an explicit `i`. That keeps every real-only path
|
|
50
|
+
* paying nothing for complex support, and it keeps `factor` and `solve` working
|
|
51
|
+
* over the rationals by default, which is what a CAS is expected to do.
|
|
52
|
+
*
|
|
53
|
+
* A complex whose imaginary part is zero is collapsed back to a real constant
|
|
54
|
+
* at the boundary, so `(1+i)*(1-i)` reads as `2` rather than `2+0i`.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* An exact complex number, `re + im * i`, with both parts rational.
|
|
59
|
+
*
|
|
60
|
+
* Construct through {@link complex} rather than as an object literal, so the
|
|
61
|
+
* real-collapse convention below stays consistent.
|
|
62
|
+
*/
|
|
63
|
+
interface Complex {
|
|
64
|
+
/** Real part. */
|
|
65
|
+
readonly re: Rational;
|
|
66
|
+
/** Imaginary part. Zero means this value is really a real number. */
|
|
67
|
+
readonly im: Rational;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The symbolic expression tree: an algebraic formula over free variables,
|
|
72
|
+
* rather than a concrete number.
|
|
73
|
+
*
|
|
74
|
+
* This is the data type the whole symbolic algebra system manipulates. It is
|
|
75
|
+
* deliberately a plain discriminated union of immutable object literals, not a
|
|
76
|
+
* class hierarchy, so a node can cross the worker boundary by structured clone
|
|
77
|
+
* (see `diagnostics/events.ts`, which carries these in its VM trace payload)
|
|
78
|
+
* and so pattern matching in the simplifier stays exhaustive under the
|
|
79
|
+
* compiler's own checking.
|
|
80
|
+
*
|
|
81
|
+
* Two variants exist here that the original bounded simplifier did not have,
|
|
82
|
+
* and they are what unlocks the rest of the system:
|
|
83
|
+
*
|
|
84
|
+
* - `pow` gives exponentiation a representation. Without it `x^2` had nowhere
|
|
85
|
+
* to go, and `OpCode.EXP` fell through to `Math.pow(0, 2)` because
|
|
86
|
+
* `Value.toNumber()` reports `0` for a symbolic operand, so `x^2 + 3x + 2`
|
|
87
|
+
* silently evaluated to `3x+2`. Polynomials, derivatives and roots all need it.
|
|
88
|
+
* - `call` gives function application a representation, so `sqrt(x)` and
|
|
89
|
+
* `sin(x)` carry through a symbolic expression instead of collapsing to
|
|
90
|
+
* `sqrt(0)`.
|
|
91
|
+
*
|
|
92
|
+
* Coefficients are exact rationals, never doubles. See `Rational.ts` for why.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A symbolic (algebraic) expression tree.
|
|
97
|
+
*
|
|
98
|
+
* Build nodes through the constructor functions in this module rather than as
|
|
99
|
+
* object literals, so constants normalize consistently.
|
|
100
|
+
*/
|
|
101
|
+
type SymbolicNode = {
|
|
102
|
+
kind: "const";
|
|
103
|
+
value: Rational;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "complex";
|
|
106
|
+
value: Complex;
|
|
107
|
+
} | {
|
|
108
|
+
kind: "var";
|
|
109
|
+
name: string;
|
|
110
|
+
} | {
|
|
111
|
+
kind: "add";
|
|
112
|
+
left: SymbolicNode;
|
|
113
|
+
right: SymbolicNode;
|
|
114
|
+
} | {
|
|
115
|
+
kind: "sub";
|
|
116
|
+
left: SymbolicNode;
|
|
117
|
+
right: SymbolicNode;
|
|
118
|
+
} | {
|
|
119
|
+
kind: "mul";
|
|
120
|
+
left: SymbolicNode;
|
|
121
|
+
right: SymbolicNode;
|
|
122
|
+
} | {
|
|
123
|
+
kind: "div";
|
|
124
|
+
left: SymbolicNode;
|
|
125
|
+
right: SymbolicNode;
|
|
126
|
+
} | {
|
|
127
|
+
kind: "neg";
|
|
128
|
+
operand: SymbolicNode;
|
|
129
|
+
} | {
|
|
130
|
+
kind: "pow";
|
|
131
|
+
base: SymbolicNode;
|
|
132
|
+
exponent: SymbolicNode;
|
|
133
|
+
} | {
|
|
134
|
+
kind: "call";
|
|
135
|
+
name: string;
|
|
136
|
+
args: readonly SymbolicNode[];
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A single matrix cell. `boolean` covers element-wise comparison results
|
|
141
|
+
* (`[1,6;3,8] < [5,2;7,4]` produces a Matrix of booleans, not numbers). A
|
|
142
|
+
* `SymbolicNode` cell is a free-variable algebraic entry, e.g. `s =
|
|
143
|
+
* [sx,0,0;0,sy,0;0,0,1]` where `sx`/`sy` are never assigned, so those
|
|
144
|
+
* cells store a real `SymbolicNode` (a bare `var` node initially) rather
|
|
145
|
+
* than degrading to `0`. See `MatrixOps.ts`'s `entryToSymbolic()`/
|
|
146
|
+
* `symbolicToEntry()` for the two-way conversion every symbolic-aware
|
|
147
|
+
* matrix op (multiply, inverse, determinant) uses.
|
|
148
|
+
*/
|
|
149
|
+
type MatrixEntry = number | boolean | SymbolicNode;
|
|
150
|
+
/**
|
|
151
|
+
* A general rows×cols matrix, a vector is just a 1×N (row) or N×1 (column)
|
|
152
|
+
* matrix. `data` is COLUMN-MAJOR (`data[row + col*rows]`), matching the
|
|
153
|
+
* spec's own `a[index]` column-major indexing semantics directly (no
|
|
154
|
+
* translation needed for single-index reads). `hasSymbolic` lets every
|
|
155
|
+
* numeric matrix op fast-path the all-numeric case with one boolean check,
|
|
156
|
+
* mirroring `binaryOp()`'s existing Number+Number fast path, computed by
|
|
157
|
+
* `matrixValue()` itself (true the moment any cell is a `SymbolicNode`
|
|
158
|
+
* object rather than a plain number/boolean), not something callers set
|
|
159
|
+
* by hand.
|
|
160
|
+
*/
|
|
161
|
+
interface MatrixData {
|
|
162
|
+
readonly rows: number;
|
|
163
|
+
readonly cols: number;
|
|
164
|
+
readonly data: readonly MatrixEntry[];
|
|
165
|
+
readonly hasSymbolic: boolean;
|
|
166
|
+
}
|
|
167
|
+
/** A first-class integer range `min:max`, both bounds inclusive. */
|
|
168
|
+
interface RangeData {
|
|
169
|
+
readonly min: number;
|
|
170
|
+
readonly max: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Discriminated union tag for {@link Value} objects.
|
|
174
|
+
*
|
|
175
|
+
* Determines the runtime type of a Value and how its `value` field should
|
|
176
|
+
* be interpreted. Used by the VM for type-aware dispatch in arithmetic,
|
|
177
|
+
* comparison, and conversion operations.
|
|
178
|
+
*/
|
|
179
|
+
declare enum ValueType {
|
|
180
|
+
/** Plain 64-bit floating point number (IEEE 754 double) */
|
|
181
|
+
Number = 0,
|
|
182
|
+
Hex = 1,
|
|
183
|
+
BigInt = 2,
|
|
184
|
+
String = 3,
|
|
185
|
+
Datetime = 4,
|
|
186
|
+
Percentage = 5,
|
|
187
|
+
Uom = 6,
|
|
188
|
+
/** General rows×cols matrix (a vector is a 1×N or N×1 matrix). Value is {@link MatrixData}. */
|
|
189
|
+
Matrix = 7,
|
|
190
|
+
/** A first-class integer range `min:max`, both inclusive. Value is {@link RangeData}. */
|
|
191
|
+
Range = 8,
|
|
192
|
+
/** A symbolic/algebraic expression tree (free-variable formula, not a concrete number). Value is a `SymbolicNode` (`@solve-js/symbolic`). */
|
|
193
|
+
Symbolic = 9,
|
|
194
|
+
/** Boolean true/false. Value is `boolean`. */
|
|
195
|
+
Boolean = 10,
|
|
196
|
+
/** Unit of measurement token (lexer only, not a runtime value). */
|
|
197
|
+
Unit = 11,
|
|
198
|
+
/** Async result pending resolution. Value stores the queryKey string. */
|
|
199
|
+
Pending = 12,
|
|
200
|
+
/** Plugin-raised error propagated through the DAG. Value stores error code, unit stores message. */
|
|
201
|
+
Error = 13
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Universal runtime value for the solve-js VM.
|
|
205
|
+
*
|
|
206
|
+
* Carries a {@link ValueType} discriminant, a polymorphic `value` payload,
|
|
207
|
+
* and an optional `unit` string (for UoM values). Treated as immutable after
|
|
208
|
+
* construction, the arena reuses objects internally via `recycle()`, but
|
|
209
|
+
* external code should never mutate Value fields.
|
|
210
|
+
*
|
|
211
|
+
* A cached `_cachedNumber` avoids repeated `toNumber()` computation on
|
|
212
|
+
* hot paths (ADD/SUB/MUL in the VM dispatch loop).
|
|
213
|
+
*/
|
|
214
|
+
declare class Value {
|
|
215
|
+
private _cachedNumber;
|
|
216
|
+
type: ValueType;
|
|
217
|
+
value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode;
|
|
218
|
+
unit?: string;
|
|
219
|
+
/** Set by async resolvers when a fetch timed out, the result is a fallback (typically 0). */
|
|
220
|
+
timedOut?: boolean;
|
|
221
|
+
constructor(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode, unit?: string);
|
|
222
|
+
/**
|
|
223
|
+
* Phase 5.3: Reset all fields for arena reuse.
|
|
224
|
+
* Called by ValueArena.acquire(), zero allocation, just field assignment.
|
|
225
|
+
*/
|
|
226
|
+
recycle(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode, unit?: string): void;
|
|
227
|
+
isNumber(): this is Value & {
|
|
228
|
+
value: number;
|
|
229
|
+
};
|
|
230
|
+
isHex(): this is Value & {
|
|
231
|
+
value: number;
|
|
232
|
+
};
|
|
233
|
+
isBigInt(): this is Value & {
|
|
234
|
+
value: bigint;
|
|
235
|
+
};
|
|
236
|
+
isString(): this is Value & {
|
|
237
|
+
value: string;
|
|
238
|
+
};
|
|
239
|
+
isMatrix(): this is Value & {
|
|
240
|
+
value: MatrixData;
|
|
241
|
+
};
|
|
242
|
+
/** A Matrix shaped like a vector, 1×N (row) or N×1 (column). */
|
|
243
|
+
isVectorShape(): boolean;
|
|
244
|
+
isRange(): this is Value & {
|
|
245
|
+
value: RangeData;
|
|
246
|
+
};
|
|
247
|
+
isSymbolic(): this is Value & {
|
|
248
|
+
value: SymbolicNode;
|
|
249
|
+
};
|
|
250
|
+
toNumber(): number;
|
|
251
|
+
isNaN(): boolean;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Create a Number-typed Value. Uses the arena when active for zero-allocation.
|
|
255
|
+
* This is the most common factory, over 90% of all Value creations.
|
|
256
|
+
*/
|
|
257
|
+
declare function numberValue(n: number): Value;
|
|
258
|
+
/** Which base a {@link ValueType.Hex} value is displayed in. */
|
|
259
|
+
type DisplayBase = "hex" | "bin" | "oct";
|
|
260
|
+
/**
|
|
261
|
+
* Create a Hex-typed Value: a **number** that displays in another base.
|
|
262
|
+
*
|
|
263
|
+
* The type is numeric on purpose, and that is the whole point of it. A base is
|
|
264
|
+
* a way of writing a quantity, not a different kind of quantity, so `0xFF + 1`
|
|
265
|
+
* has to be 256. Returning a string instead makes it 1, because a string reads
|
|
266
|
+
* as zero in arithmetic, and nothing about that failure is visible at the point
|
|
267
|
+
* of use.
|
|
268
|
+
*
|
|
269
|
+
* @param n - The number itself, in full precision.
|
|
270
|
+
* @param base - How to display it, defaulting to hexadecimal. Carried in the
|
|
271
|
+
* `unit` slot, which is free for this type.
|
|
272
|
+
*/
|
|
273
|
+
declare function hexValue(n: number, base?: DisplayBase): Value;
|
|
274
|
+
/** Create a BigInt-typed Value (arbitrary-precision integer). */
|
|
275
|
+
declare function bigIntValue(n: bigint): Value;
|
|
276
|
+
/** Create a String-typed Value. */
|
|
277
|
+
declare function stringValue(s: string): Value;
|
|
278
|
+
/** Create a Unit-of-Measurement Value (typed number with unit annotation). */
|
|
279
|
+
declare function uomValue(n: number, unit: string): Value;
|
|
280
|
+
/**
|
|
281
|
+
* Create a Matrix value from an explicit shape + column-major data array.
|
|
282
|
+
* `data.length` must equal `rows*cols`, callers building a matrix from
|
|
283
|
+
* row-major source syntax (e.g. the `[1,2;3,4]` literal) must transpose
|
|
284
|
+
* into column-major order before calling this; see `MatrixOps.ts`'s
|
|
285
|
+
* `rowMajorToColumnMajor()`.
|
|
286
|
+
*/
|
|
287
|
+
declare function matrixValue(rows: number, cols: number, data: readonly MatrixEntry[]): Value;
|
|
288
|
+
/** A 1×N row-vector Matrix, row-major and column-major storage are identical for a single row. */
|
|
289
|
+
declare function rowVectorValue(data: readonly number[]): Value;
|
|
290
|
+
/** An N×1 column-vector Matrix, row-major and column-major storage are identical for a single column. */
|
|
291
|
+
declare function colVectorValue(data: readonly number[]): Value;
|
|
292
|
+
/** Create a Range value, a first-class integer range `min:max`, both bounds inclusive. */
|
|
293
|
+
declare function rangeValue(min: number, max: number): Value;
|
|
294
|
+
|
|
295
|
+
export { type MatrixData as M, type RangeData as R, type SymbolicNode as S, Value as V, type MatrixEntry as a, ValueType as b, bigIntValue as c, colVectorValue as d, rowVectorValue as e, hexValue as h, matrixValue as m, numberValue as n, rangeValue as r, stringValue as s, uomValue as u };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-2RWAXT6O.js"}
|