trilean 1.9.1 → 1.10.0

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/README.md CHANGED
@@ -181,7 +181,9 @@ The inputs are validated in full before anything is evaluated, every element of
181
181
 
182
182
  The result is printed as JSON in the `Evaluation` shape, a `definite` value or an `indeterminate` reason (see [The evaluation model](#the-evaluation-model)). The exit status separates the three outcomes a script cares about: `0` for a definite result, `1` for an indeterminate one, `2` when no result was printed (bad usage, an unreadable file, JSON that is malformed, a tree or an input that fails validation, a tree that folds or quantifies over a list the inputs do not hold, or a result JSON cannot carry, which the built-in registry never produces). Everything that is not a result goes to standard error, the usage text included unless `--help` asked for it, and problems with the tree or an input are one `path: message` line each. A reader of standard output that closes early (`| true`) does not change the exit status or print an error.
183
183
 
184
- `call` nodes resolve against `builtinFunctions`, which the library also exports (frozen, so changing the export cannot change what the command resolves): `minimum` and `maximum` (one or more numbers sharing a unit), `absoluteValue`, `round` (halves away from zero, working on the decimal number as written, so `round(1.005, 2)` is `1.01`, with an optional count of decimal places, and a value too large to have a digit at that precision returned unchanged), `squareRoot`, `exponential`, and `logarithm` (natural, or to an optional base, exact for powers of 10 and 2), and the two projections of a complex value onto the reals: `magnitude` (the absolute value of a real number or the modulus of a complex one) and `phase` (the angle of a complex number in radians, in the range [-pi, pi]: a negative real number is +pi whatever the sign of its zero imaginary part, so a signed zero never gives -pi, though a tiny negative imaginary part can round to exactly -pi; zero is 0; a component that is not finite is a `domain-error`). Every function but those two takes real numbers only and refuses a complex value, `absoluteValue` included; `magnitude` takes a real or a complex number and `phase` a complex one. They follow the unit rules above: `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit, `phase` is dimensionless, `squareRoot` halves each dimension's exponent and refuses an odd one, and `exponential` and `logarithm` accept dimensionless numbers only. An argument a function cannot accept (the wrong kind or count, or mismatched units, as in `minimum(1 m, 2)`) is `wrong-type`; an argument of the right kind outside the function's domain, or a result that is not a finite number, is `domain-error`; and any other name is `wrong-type`.
184
+ `call` nodes resolve against `builtinFunctions`, which the library also exports (frozen, so changing the export cannot change what the command resolves): `minimum` and `maximum` (one or more numbers sharing a unit), `absoluteValue`, `round` (halves away from zero, working on the decimal number as written, so `round(1.005, 2)` is `1.01`, with an optional count of decimal places, and a value too large to have a digit at that precision returned unchanged), `squareRoot`, `exponential`, and `logarithm` (natural, or to an optional real base, exact for powers of 10 and 2), the two projections of a complex value onto the reals: `magnitude` (the absolute value of a real number or the modulus of a complex one) and `phase` (the angle of a complex number in radians, in the range [-pi, pi]: a negative real number is +pi whatever the sign of its zero imaginary part, so a signed zero never gives -pi, though a tiny negative imaginary part can round to exactly -pi; zero is 0; a component that is not finite is a `domain-error`), and the trigonometric functions `sine`, `cosine`, `tangent`, `arcSine`, `arcCosine`, `arcTangent` and `arcTangent2` (the angle of the point `(x, y)`, called as `arcTangent2(y, x)`: the `phase` of `x + yi`, so it shares that range and signed-zero handling).
185
+
186
+ `squareRoot`, `exponential`, `logarithm` and `magnitude` take a real or a complex number, `phase` a complex one only, and every other function takes real numbers only and refuses a complex value, `absoluteValue` and the trigonometric functions included. A real argument gives a real result exactly as it always has, so a negative `squareRoot` and a `logarithm` of zero or a negative number stay `domain-error` rather than turning complex. A complex argument gives a complex result, the principal value, even when its imaginary part comes out zero, as complex arithmetic does (see [Complex values](#complex-values)): the branch cut is the negative real axis with `phase`'s convention on it, so `logarithm` is `log|z| + i phase(z)` (divided through by the natural logarithm of a base when one is given), `logarithm(-1)` is `pi i`, `squareRoot` is the root whose real part is not negative (`squareRoot(-4 + 0i)` is `2i` exactly, whatever the sign of the zero), and `exponential(x + yi)` is `e^x (cos y + i sin y)`; a complex zero is a `domain-error` for `logarithm`. They follow the unit rules above: `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit, `phase` is dimensionless, `squareRoot` halves each dimension's exponent and refuses an odd one, and `exponential`, `logarithm` and the trigonometric functions accept dimensionless numbers only and return one, angles in radians. An argument a function cannot accept (the wrong kind or count, or mismatched units, as in `minimum(1 m, 2)`) is `wrong-type`; an argument of the right kind outside the function's domain (an `arcSine` or `arcCosine` outside -1 to 1 among them), or a result that is not a finite number in either component, is `domain-error`; and any other name is `wrong-type`. A `tangent` near a pole is large but finite, since no double is an odd multiple of pi/2 exactly.
185
187
 
186
188
  The command has no table, delegate or tree store to hand a `lookup`, `delegate` or `treeReference` node. A `lookup` is `not-found` and a `delegate` or `treeReference` is `wrong-type`. A tree that folds or quantifies over a list the inputs do not hold exits `2` rather than treating the missing list as empty. That holds even when another operand would settle the answer: `and(false, some(...))` still exits `2`, because the synchronous evaluator asks for the collection before it combines the two. For trees that need a table, a delegate or a tree store, embed the library and supply the [resolvers](#resolvers) yourself.
187
189
 
@@ -546,7 +548,7 @@ The magnitude-and-phase view stays reachable through four exported conversion he
546
548
 
547
549
  - `add`/`subtract` are component-wise, requiring **identical** dimensional-exponent maps exactly as real numbers do (see [Units](#units)).
548
550
  - `multiply`/`divide` are real complex multiplication and division — `(a + bi)(c + di) = (ac − bd) + (ad + bc)i`, and the corresponding quotient — never component-wise. The divisor and the dividend are each scaled by their own power of two, which brings the larger component of each to about a quarter, the quotient is computed on those scaled values, and the combined power of two is applied to the result once. Where the quotient is a normal number the error over the pair is a few units of 2^-53 (the measured worst case over a large exact-rational check is under 4); where it is subnormal the result is within a few spacings of the true value (under 5 measured), not correctly rounded. A quotient too large for a double is `domain-error`, and one below about half the smallest subnormal is zero; both thresholds are fuzzy by that error near the edge (measured, a true quotient up to about 2 ulps above the largest double came back finite, and a representable one a little over 1 ulp below it was refused). A zero dividend gives zero without preserving the signs of its zeros, which is visible only through `Object.is` on the library function, not through JSON, `compare` or `memberOf`. Units combine by the same dimensional analysis real numbers use. A zero divisor means both components zero; a divisor with only a zero real part divides perfectly well.
549
- - `power` is defined for a **real integer exponent** and evaluated as the repeated multiplication that integer exponentiation is, grouped by squaring so the work grows with the logarithm of the exponent. The price is accuracy: the error of squaring grows in proportion to |n|, so for large exponents the result is many times less accurate than a plain multiplication loop's. These are observations from samples, not bounds, and the figures move from sample to sample. Against a 140-digit reference on random unit-magnitude bases, the mean error of squaring was between 15 and 56 times a plain loop's for |n| from 1e3 to 1e7, growing by about a factor of ten per tenfold increase in |n| (roughly 0.23 |n| units of 2^-53). For |n| up to 24 the worst error was about 20 units of 2^-53: 18.5 for positive and 18.2 for negative exponents over 50,000 bases per exponent, and up to 19.7 in another sample of 40,000. A negative exponent is the reciprocal of the positive power, except where that power overflows or underflows, when the reciprocal is raised instead so a representable result is not lost. Like a real `power`, it requires dimensionless operands. An arbitrary complex exponent is a genuinely bigger question — it needs the complex logarithm, which is multivalued, so it needs a branch-cut convention this design has not chosen — and is deliberately out of scope for now: it is `wrong-type`, as is a non-integer real exponent, on the same reading of that code used throughout ("an answer exists, but this operator does not accept this operand" — compare `power`'s existing dimensionless-operands requirement, also `wrong-type`).
551
+ - `power` is defined for a **real integer exponent** and evaluated as the repeated multiplication that integer exponentiation is, grouped by squaring so the work grows with the logarithm of the exponent. The price is accuracy: the error of squaring grows in proportion to |n|, so for large exponents the result is many times less accurate than a plain multiplication loop's. These are observations from samples, not bounds, and the figures move from sample to sample. Against a 140-digit reference on random unit-magnitude bases, the mean error of squaring was between 15 and 56 times a plain loop's for |n| from 1e3 to 1e7, growing by about a factor of ten per tenfold increase in |n| (roughly 0.23 |n| units of 2^-53). For |n| up to 24 the worst error was about 20 units of 2^-53: 18.5 for positive and 18.2 for negative exponents over 50,000 bases per exponent, and up to 19.7 in another sample of 40,000. A negative exponent is the reciprocal of the positive power, except where that power overflows or underflows, when the reciprocal is raised instead so a representable result is not lost. Like a real `power`, it requires dimensionless operands. An arbitrary complex exponent is a genuinely bigger question, and deliberately out of scope for now: it needs the complex logarithm, which is multivalued, and although the command line's built-in `logarithm` returns its principal value, the evaluator's own operators carry no function set and have not adopted that branch cut. It is `wrong-type`, as is a non-integer real exponent, on the same reading of that code used throughout ("an answer exists, but this operator does not accept this operand" — compare `power`'s existing dimensionless-operands requirement, also `wrong-type`).
550
552
  - `modulo` is `domain-error`, not `wrong-type`: a remainder needs a canonical notion of how many whole divisors fit, and the complex plane has no ordering to supply one. There is no answer to accept, which is the same category as division by zero.
551
553
 
552
554
  **A real operand is promoted, never rejected.** Mixing a `number` with a `complex` in one `arithmetic` node works: every real number *is* a complex number with a zero imaginary part, so the promotion is exact, total, and canonical — unlike the temporal cross-kind combinations above, which had to be enumerated one by one precisely because no such embedding exists between an `instant` and a `duration`. Scaling a complex value by a real one, or offsetting it by a real constant, is the common case, and forcing every real literal in such a formula to be rewritten as a complex one would defeat the point. The result is `complex` whenever either operand is, even when the imaginary part comes out zero: a node's result kind follows its operand kinds, never the values that happen to flow through it.
@@ -35,6 +35,80 @@ function singleNumber(name, args) {
35
35
  if (args.length !== 1 || !isNumberValue(arg)) return { wrongType: `${name} requires exactly one number argument` };
36
36
  return arg;
37
37
  }
38
+ /** The one exit for every complex result, as `finiteNumber` is for real ones. A complex argument always gives a complex result, even when the imaginary part comes out zero, as the evaluator's own complex arithmetic does: the result kind follows the argument kind, never the value. */
39
+ function finiteComplex(name, { re, im }, unit) {
40
+ if (!Number.isFinite(re) || !Number.isFinite(im)) return { domainError: `${name} produced a result that is not a finite number` };
41
+ return unit === void 0 ? {
42
+ kind: "complex",
43
+ re,
44
+ im
45
+ } : {
46
+ kind: "complex",
47
+ re,
48
+ im,
49
+ unit
50
+ };
51
+ }
52
+ function singleNumberOrComplex(name, args) {
53
+ const [arg] = args;
54
+ if (args.length !== 1 || arg?.kind !== "number" && arg?.kind !== "complex") return { wrongType: `${name} requires exactly one number or complex number argument` };
55
+ return arg;
56
+ }
57
+ /** The value of a single dimensionless real argument, or the `wrongType` refusing anything else (a complex value included). */
58
+ function singleDimensionless(name, args) {
59
+ const arg = singleNumber(name, args);
60
+ if ("wrongType" in arg) return arg;
61
+ if (!isDimensionless(arg)) return { wrongType: `${name} requires a dimensionless number` };
62
+ return arg.value;
63
+ }
64
+ /** A real function of one dimensionless number, returning a dimensionless number. */
65
+ function dimensionlessFunction(name, apply) {
66
+ return (args) => {
67
+ const value = singleDimensionless(name, args);
68
+ if (typeof value !== "number") return value;
69
+ return finiteNumber(name, apply(value));
70
+ };
71
+ }
72
+ /** An inverse sine or cosine, whose real domain is the closed interval from -1 to 1; outside it the inverse is not a real number, which is a `domainError` rather than the `NaN` `Math.asin` and `Math.acos` return. */
73
+ function unitIntervalInverse(name, apply) {
74
+ return (args) => {
75
+ const value = singleDimensionless(name, args);
76
+ if (typeof value !== "number") return value;
77
+ if (!(Math.abs(value) <= 1)) return { domainError: `${name} requires a number from -1 to 1` };
78
+ return finiteNumber(name, apply(value));
79
+ };
80
+ }
81
+ /**
82
+ * The principal square root of a complex value: the root whose real part is not negative, with the branch cut along the negative real axis. On the cut the root lies on the positive imaginary axis whatever the sign of the zero imaginary part, matching `complexPhase`'s +pi for a negative real number, so `sqrt(z)` is `sqrt(|z|) * e^(i * phase(z) / 2)` everywhere.
83
+ *
84
+ * It is computed by the closed form rather than through that polar expression: with `t = sqrt((|re| + |z|) / 2)`, the root is `t + (im / 2t)i` when `re` is not negative and `|im| / 2t + t i` (with the sign of `im` on `t`) otherwise. Neither form subtracts two nearly equal quantities, and an exactly representable root comes out exact (`sqrt(-4)` is `2i`, where `cos(pi / 2)` would leave a stray real part of about 1e-16).
85
+ */
86
+ function principalSquareRoot(value) {
87
+ const modulus = require_complex.complexMagnitude(value).value;
88
+ if (modulus === 0) return {
89
+ re: 0,
90
+ im: 0
91
+ };
92
+ const sum = Math.abs(value.re) + modulus;
93
+ const half = Number.isFinite(sum) ? sum / 2 : Math.abs(value.re) / 2 + modulus / 2;
94
+ const t = Math.sqrt(half);
95
+ const { im } = value;
96
+ if (value.re >= 0) return {
97
+ re: t,
98
+ im: im / (2 * t)
99
+ };
100
+ return {
101
+ re: Math.abs(im) / (2 * t),
102
+ im: im < 0 ? -t : t
103
+ };
104
+ }
105
+ /** The logarithm of a positive real number, natural or to a base already checked to be above zero and not one. */
106
+ function realLogarithm(value, base) {
107
+ if (base === void 0) return Math.log(value);
108
+ if (base === DECIMAL_BASE) return Math.log10(value);
109
+ if (base === BINARY_BASE) return Math.log2(value);
110
+ return Math.log(value) / Math.log(base);
111
+ }
38
112
  /** Halves every dimension's exponent, or `false` when one is odd and the root would need a fractional exponent. */
39
113
  function halveUnit(unit) {
40
114
  if (unit === void 0) return void 0;
@@ -74,11 +148,13 @@ function roundHalfAwayFromZero(value, places) {
74
148
  return rounded === 0 ? 0 : Math.sign(value) * rounded;
75
149
  }
76
150
  /**
77
- * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional base), and the two projections of a complex value onto the reals, `magnitude` and `phase`. Every function but those two takes real numbers only, and refuses a complex value; `magnitude` takes a real or a complex number, and `phase` a complex one.
151
+ * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional real base), the two projections of a complex value onto the reals, `magnitude` and `phase`, and the trigonometric functions `sine`, `cosine`, `tangent`, `arcSine`, `arcCosine`, `arcTangent` and `arcTangent2` (the angle of the point `(x, y)`, called with `y` first).
78
152
  *
79
- * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places) or a result that is not a finite number is a `domainError`.
153
+ * Which take a complex value: `squareRoot`, `exponential`, `logarithm` and `magnitude` take a real or a complex number, and `phase` a complex one only. Every other function takes real numbers only and refuses a complex value. A real argument to `squareRoot`, `exponential` or `logarithm` gives a real result, so a negative `squareRoot` or a `logarithm` of zero or a negative number stays a `domainError` rather than becoming complex; a complex argument gives a complex result, the principal value, even when its imaginary part comes out zero, as the evaluator's own complex arithmetic does. The principal values take the branch cut along the negative real axis with `phase`'s convention on it: `logarithm` is `log|z| + i phase(z)` (divided through by the natural logarithm of a base when one is given), so its imaginary part lies in [-pi, pi], and `squareRoot` is the root with a real part that is not negative, on the positive imaginary axis for a negative real number whatever the sign of its zero imaginary part.
80
154
  *
81
- * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential` and `logarithm` accept only dimensionless numbers and return one.
155
+ * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative real `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places, an `arcSine` or `arcCosine` outside -1 to 1) or a result that is not a finite number (in either component of a complex one) is a `domainError`. A `tangent` near a pole is large but finite, since no double is an odd multiple of pi/2 exactly.
156
+ *
157
+ * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential`, `logarithm` and the trigonometric functions accept only dimensionless numbers and return one, angles in radians. `arcTangent2` is the `phase` of `x + yi`, so it shares that range and signed-zero handling, and its two arguments must be finite.
82
158
  *
83
159
  * Frozen, so mutating the export cannot change what `evaluateDocument` resolves.
84
160
  */
@@ -99,31 +175,35 @@ const builtinFunctions = Object.freeze({
99
175
  return finiteNumber("round", roundHalfAwayFromZero(value.value, places.value), value.unit);
100
176
  },
101
177
  squareRoot: (args) => {
102
- const arg = singleNumber("squareRoot", args);
178
+ const arg = singleNumberOrComplex("squareRoot", args);
103
179
  if ("wrongType" in arg) return arg;
104
180
  const unit = halveUnit(arg.unit);
105
181
  if (unit === false) return { wrongType: "squareRoot requires every unit exponent to be even" };
182
+ if (arg.kind === "complex") return finiteComplex("squareRoot", principalSquareRoot(arg), unit);
106
183
  if (arg.value < 0) return { domainError: "squareRoot of a negative number is not a real number" };
107
184
  return finiteNumber("squareRoot", Math.sqrt(arg.value), unit);
108
185
  },
109
186
  exponential: (args) => {
110
- const arg = singleNumber("exponential", args);
187
+ const arg = singleNumberOrComplex("exponential", args);
111
188
  if ("wrongType" in arg) return arg;
112
- if (!isDimensionless(arg)) return { wrongType: "exponential requires a dimensionless number" };
189
+ if (!require_computed_value.unitsEqual(arg.unit, void 0)) return { wrongType: "exponential requires a dimensionless number" };
190
+ if (arg.kind === "complex") return finiteComplex("exponential", require_complex.complexFromPolar(Math.exp(arg.re), arg.im));
113
191
  return finiteNumber("exponential", Math.exp(arg.value));
114
192
  },
115
193
  logarithm: (args) => {
116
194
  const [value, base, ...extra] = args;
117
- if (!isNumberValue(value) || extra.length > 0) return { wrongType: "logarithm requires a number and an optional base" };
118
- if (!isDimensionless(value)) return { wrongType: "logarithm requires a dimensionless number" };
195
+ if (value?.kind !== "number" && value?.kind !== "complex" || extra.length > 0) return { wrongType: "logarithm requires a number or a complex number and an optional base" };
196
+ if (!require_computed_value.unitsEqual(value.unit, void 0)) return { wrongType: "logarithm requires a dimensionless number" };
119
197
  const baseNumber = base === void 0 ? void 0 : dimensionlessNumber(base);
120
198
  if (base !== void 0 && baseNumber === void 0) return { wrongType: "logarithm requires its base to be a dimensionless number" };
121
- if (value.value <= 0) return { domainError: "logarithm requires a number above zero" };
122
- if (baseNumber === void 0) return finiteNumber("logarithm", Math.log(value.value));
123
- if (baseNumber <= 0 || baseNumber === 1) return { domainError: "logarithm requires its base to be above zero and not one" };
124
- if (baseNumber === DECIMAL_BASE) return finiteNumber("logarithm", Math.log10(value.value));
125
- if (baseNumber === BINARY_BASE) return finiteNumber("logarithm", Math.log2(value.value));
126
- return finiteNumber("logarithm", Math.log(value.value) / Math.log(baseNumber));
199
+ if (value.kind === "number" && value.value <= 0) return { domainError: "logarithm requires a number above zero" };
200
+ if (value.kind === "complex" && value.re === 0 && value.im === 0) return { domainError: "logarithm requires a complex number other than zero" };
201
+ if (baseNumber !== void 0 && (baseNumber <= 0 || baseNumber === 1)) return { domainError: "logarithm requires its base to be above zero and not one" };
202
+ if (value.kind === "number") return finiteNumber("logarithm", realLogarithm(value.value, baseNumber));
203
+ return finiteComplex("logarithm", {
204
+ re: realLogarithm(require_complex.complexMagnitude(value).value, baseNumber),
205
+ im: require_complex.complexPhase(value).value / (baseNumber === void 0 ? 1 : Math.log(baseNumber))
206
+ });
127
207
  },
128
208
  magnitude: (args) => {
129
209
  const [arg] = args;
@@ -140,6 +220,23 @@ const builtinFunctions = Object.freeze({
140
220
  if (args.length !== 1 || arg?.kind !== "complex") return { wrongType: "phase requires exactly one complex argument" };
141
221
  if (!Number.isFinite(arg.re) || !Number.isFinite(arg.im)) return { domainError: "phase requires finite components" };
142
222
  return require_complex.complexPhase(arg);
223
+ },
224
+ sine: dimensionlessFunction("sine", Math.sin),
225
+ cosine: dimensionlessFunction("cosine", Math.cos),
226
+ tangent: dimensionlessFunction("tangent", Math.tan),
227
+ arcSine: unitIntervalInverse("arcSine", Math.asin),
228
+ arcCosine: unitIntervalInverse("arcCosine", Math.acos),
229
+ arcTangent: dimensionlessFunction("arcTangent", Math.atan),
230
+ arcTangent2: (args) => {
231
+ const [y, x] = args;
232
+ if (args.length !== 2 || !isNumberValue(y) || !isNumberValue(x)) return { wrongType: "arcTangent2 requires exactly two number arguments" };
233
+ if (!isDimensionless(y) || !isDimensionless(x)) return { wrongType: "arcTangent2 requires dimensionless numbers" };
234
+ if (!Number.isFinite(y.value) || !Number.isFinite(x.value)) return { domainError: "arcTangent2 requires finite arguments" };
235
+ return require_complex.complexPhase({
236
+ kind: "complex",
237
+ re: x.value,
238
+ im: y.value
239
+ });
143
240
  }
144
241
  });
145
242
  //#endregion
@@ -1,11 +1,13 @@
1
1
  import { FunctionRegistry } from "./functions.cjs";
2
2
  //#region src/builtin-functions.d.ts
3
3
  /**
4
- * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional base), and the two projections of a complex value onto the reals, `magnitude` and `phase`. Every function but those two takes real numbers only, and refuses a complex value; `magnitude` takes a real or a complex number, and `phase` a complex one.
4
+ * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional real base), the two projections of a complex value onto the reals, `magnitude` and `phase`, and the trigonometric functions `sine`, `cosine`, `tangent`, `arcSine`, `arcCosine`, `arcTangent` and `arcTangent2` (the angle of the point `(x, y)`, called with `y` first).
5
5
  *
6
- * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places) or a result that is not a finite number is a `domainError`.
6
+ * Which take a complex value: `squareRoot`, `exponential`, `logarithm` and `magnitude` take a real or a complex number, and `phase` a complex one only. Every other function takes real numbers only and refuses a complex value. A real argument to `squareRoot`, `exponential` or `logarithm` gives a real result, so a negative `squareRoot` or a `logarithm` of zero or a negative number stays a `domainError` rather than becoming complex; a complex argument gives a complex result, the principal value, even when its imaginary part comes out zero, as the evaluator's own complex arithmetic does. The principal values take the branch cut along the negative real axis with `phase`'s convention on it: `logarithm` is `log|z| + i phase(z)` (divided through by the natural logarithm of a base when one is given), so its imaginary part lies in [-pi, pi], and `squareRoot` is the root with a real part that is not negative, on the positive imaginary axis for a negative real number whatever the sign of its zero imaginary part.
7
7
  *
8
- * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential` and `logarithm` accept only dimensionless numbers and return one.
8
+ * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative real `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places, an `arcSine` or `arcCosine` outside -1 to 1) or a result that is not a finite number (in either component of a complex one) is a `domainError`. A `tangent` near a pole is large but finite, since no double is an odd multiple of pi/2 exactly.
9
+ *
10
+ * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential`, `logarithm` and the trigonometric functions accept only dimensionless numbers and return one, angles in radians. `arcTangent2` is the `phase` of `x + yi`, so it shares that range and signed-zero handling, and its two arguments must be finite.
9
11
  *
10
12
  * Frozen, so mutating the export cannot change what `evaluateDocument` resolves.
11
13
  */
@@ -1,11 +1,13 @@
1
1
  import { FunctionRegistry } from "./functions.js";
2
2
  //#region src/builtin-functions.d.ts
3
3
  /**
4
- * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional base), and the two projections of a complex value onto the reals, `magnitude` and `phase`. Every function but those two takes real numbers only, and refuses a complex value; `magnitude` takes a real or a complex number, and `phase` a complex one.
4
+ * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional real base), the two projections of a complex value onto the reals, `magnitude` and `phase`, and the trigonometric functions `sine`, `cosine`, `tangent`, `arcSine`, `arcCosine`, `arcTangent` and `arcTangent2` (the angle of the point `(x, y)`, called with `y` first).
5
5
  *
6
- * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places) or a result that is not a finite number is a `domainError`.
6
+ * Which take a complex value: `squareRoot`, `exponential`, `logarithm` and `magnitude` take a real or a complex number, and `phase` a complex one only. Every other function takes real numbers only and refuses a complex value. A real argument to `squareRoot`, `exponential` or `logarithm` gives a real result, so a negative `squareRoot` or a `logarithm` of zero or a negative number stays a `domainError` rather than becoming complex; a complex argument gives a complex result, the principal value, even when its imaginary part comes out zero, as the evaluator's own complex arithmetic does. The principal values take the branch cut along the negative real axis with `phase`'s convention on it: `logarithm` is `log|z| + i phase(z)` (divided through by the natural logarithm of a base when one is given), so its imaginary part lies in [-pi, pi], and `squareRoot` is the root with a real part that is not negative, on the positive imaginary axis for a negative real number whatever the sign of its zero imaginary part.
7
7
  *
8
- * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential` and `logarithm` accept only dimensionless numbers and return one.
8
+ * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative real `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places, an `arcSine` or `arcCosine` outside -1 to 1) or a result that is not a finite number (in either component of a complex one) is a `domainError`. A `tangent` near a pole is large but finite, since no double is an odd multiple of pi/2 exactly.
9
+ *
10
+ * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential`, `logarithm` and the trigonometric functions accept only dimensionless numbers and return one, angles in radians. `arcTangent2` is the `phase` of `x + yi`, so it shares that range and signed-zero handling, and its two arguments must be finite.
9
11
  *
10
12
  * Frozen, so mutating the export cannot change what `evaluateDocument` resolves.
11
13
  */
@@ -1,5 +1,5 @@
1
1
  import { unitsEqual } from "./computed-value.js";
2
- import { complexMagnitude, complexPhase } from "./complex.js";
2
+ import { complexFromPolar, complexMagnitude, complexPhase } from "./complex.js";
3
3
  //#region src/builtin-functions.ts
4
4
  const DECIMAL_BASE = 10;
5
5
  const BINARY_BASE = 2;
@@ -34,6 +34,80 @@ function singleNumber(name, args) {
34
34
  if (args.length !== 1 || !isNumberValue(arg)) return { wrongType: `${name} requires exactly one number argument` };
35
35
  return arg;
36
36
  }
37
+ /** The one exit for every complex result, as `finiteNumber` is for real ones. A complex argument always gives a complex result, even when the imaginary part comes out zero, as the evaluator's own complex arithmetic does: the result kind follows the argument kind, never the value. */
38
+ function finiteComplex(name, { re, im }, unit) {
39
+ if (!Number.isFinite(re) || !Number.isFinite(im)) return { domainError: `${name} produced a result that is not a finite number` };
40
+ return unit === void 0 ? {
41
+ kind: "complex",
42
+ re,
43
+ im
44
+ } : {
45
+ kind: "complex",
46
+ re,
47
+ im,
48
+ unit
49
+ };
50
+ }
51
+ function singleNumberOrComplex(name, args) {
52
+ const [arg] = args;
53
+ if (args.length !== 1 || arg?.kind !== "number" && arg?.kind !== "complex") return { wrongType: `${name} requires exactly one number or complex number argument` };
54
+ return arg;
55
+ }
56
+ /** The value of a single dimensionless real argument, or the `wrongType` refusing anything else (a complex value included). */
57
+ function singleDimensionless(name, args) {
58
+ const arg = singleNumber(name, args);
59
+ if ("wrongType" in arg) return arg;
60
+ if (!isDimensionless(arg)) return { wrongType: `${name} requires a dimensionless number` };
61
+ return arg.value;
62
+ }
63
+ /** A real function of one dimensionless number, returning a dimensionless number. */
64
+ function dimensionlessFunction(name, apply) {
65
+ return (args) => {
66
+ const value = singleDimensionless(name, args);
67
+ if (typeof value !== "number") return value;
68
+ return finiteNumber(name, apply(value));
69
+ };
70
+ }
71
+ /** An inverse sine or cosine, whose real domain is the closed interval from -1 to 1; outside it the inverse is not a real number, which is a `domainError` rather than the `NaN` `Math.asin` and `Math.acos` return. */
72
+ function unitIntervalInverse(name, apply) {
73
+ return (args) => {
74
+ const value = singleDimensionless(name, args);
75
+ if (typeof value !== "number") return value;
76
+ if (!(Math.abs(value) <= 1)) return { domainError: `${name} requires a number from -1 to 1` };
77
+ return finiteNumber(name, apply(value));
78
+ };
79
+ }
80
+ /**
81
+ * The principal square root of a complex value: the root whose real part is not negative, with the branch cut along the negative real axis. On the cut the root lies on the positive imaginary axis whatever the sign of the zero imaginary part, matching `complexPhase`'s +pi for a negative real number, so `sqrt(z)` is `sqrt(|z|) * e^(i * phase(z) / 2)` everywhere.
82
+ *
83
+ * It is computed by the closed form rather than through that polar expression: with `t = sqrt((|re| + |z|) / 2)`, the root is `t + (im / 2t)i` when `re` is not negative and `|im| / 2t + t i` (with the sign of `im` on `t`) otherwise. Neither form subtracts two nearly equal quantities, and an exactly representable root comes out exact (`sqrt(-4)` is `2i`, where `cos(pi / 2)` would leave a stray real part of about 1e-16).
84
+ */
85
+ function principalSquareRoot(value) {
86
+ const modulus = complexMagnitude(value).value;
87
+ if (modulus === 0) return {
88
+ re: 0,
89
+ im: 0
90
+ };
91
+ const sum = Math.abs(value.re) + modulus;
92
+ const half = Number.isFinite(sum) ? sum / 2 : Math.abs(value.re) / 2 + modulus / 2;
93
+ const t = Math.sqrt(half);
94
+ const { im } = value;
95
+ if (value.re >= 0) return {
96
+ re: t,
97
+ im: im / (2 * t)
98
+ };
99
+ return {
100
+ re: Math.abs(im) / (2 * t),
101
+ im: im < 0 ? -t : t
102
+ };
103
+ }
104
+ /** The logarithm of a positive real number, natural or to a base already checked to be above zero and not one. */
105
+ function realLogarithm(value, base) {
106
+ if (base === void 0) return Math.log(value);
107
+ if (base === DECIMAL_BASE) return Math.log10(value);
108
+ if (base === BINARY_BASE) return Math.log2(value);
109
+ return Math.log(value) / Math.log(base);
110
+ }
37
111
  /** Halves every dimension's exponent, or `false` when one is odd and the root would need a fractional exponent. */
38
112
  function halveUnit(unit) {
39
113
  if (unit === void 0) return void 0;
@@ -73,11 +147,13 @@ function roundHalfAwayFromZero(value, places) {
73
147
  return rounded === 0 ? 0 : Math.sign(value) * rounded;
74
148
  }
75
149
  /**
76
- * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional base), and the two projections of a complex value onto the reals, `magnitude` and `phase`. Every function but those two takes real numbers only, and refuses a complex value; `magnitude` takes a real or a complex number, and `phase` a complex one.
150
+ * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional real base), the two projections of a complex value onto the reals, `magnitude` and `phase`, and the trigonometric functions `sine`, `cosine`, `tangent`, `arcSine`, `arcCosine`, `arcTangent` and `arcTangent2` (the angle of the point `(x, y)`, called with `y` first).
77
151
  *
78
- * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places) or a result that is not a finite number is a `domainError`.
152
+ * Which take a complex value: `squareRoot`, `exponential`, `logarithm` and `magnitude` take a real or a complex number, and `phase` a complex one only. Every other function takes real numbers only and refuses a complex value. A real argument to `squareRoot`, `exponential` or `logarithm` gives a real result, so a negative `squareRoot` or a `logarithm` of zero or a negative number stays a `domainError` rather than becoming complex; a complex argument gives a complex result, the principal value, even when its imaginary part comes out zero, as the evaluator's own complex arithmetic does. The principal values take the branch cut along the negative real axis with `phase`'s convention on it: `logarithm` is `log|z| + i phase(z)` (divided through by the natural logarithm of a base when one is given), so its imaginary part lies in [-pi, pi], and `squareRoot` is the root with a real part that is not negative, on the positive imaginary axis for a negative real number whatever the sign of its zero imaginary part.
79
153
  *
80
- * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential` and `logarithm` accept only dimensionless numbers and return one.
154
+ * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative real `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places, an `arcSine` or `arcCosine` outside -1 to 1) or a result that is not a finite number (in either component of a complex one) is a `domainError`. A `tangent` near a pole is large but finite, since no double is an odd multiple of pi/2 exactly.
155
+ *
156
+ * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential`, `logarithm` and the trigonometric functions accept only dimensionless numbers and return one, angles in radians. `arcTangent2` is the `phase` of `x + yi`, so it shares that range and signed-zero handling, and its two arguments must be finite.
81
157
  *
82
158
  * Frozen, so mutating the export cannot change what `evaluateDocument` resolves.
83
159
  */
@@ -98,31 +174,35 @@ const builtinFunctions = Object.freeze({
98
174
  return finiteNumber("round", roundHalfAwayFromZero(value.value, places.value), value.unit);
99
175
  },
100
176
  squareRoot: (args) => {
101
- const arg = singleNumber("squareRoot", args);
177
+ const arg = singleNumberOrComplex("squareRoot", args);
102
178
  if ("wrongType" in arg) return arg;
103
179
  const unit = halveUnit(arg.unit);
104
180
  if (unit === false) return { wrongType: "squareRoot requires every unit exponent to be even" };
181
+ if (arg.kind === "complex") return finiteComplex("squareRoot", principalSquareRoot(arg), unit);
105
182
  if (arg.value < 0) return { domainError: "squareRoot of a negative number is not a real number" };
106
183
  return finiteNumber("squareRoot", Math.sqrt(arg.value), unit);
107
184
  },
108
185
  exponential: (args) => {
109
- const arg = singleNumber("exponential", args);
186
+ const arg = singleNumberOrComplex("exponential", args);
110
187
  if ("wrongType" in arg) return arg;
111
- if (!isDimensionless(arg)) return { wrongType: "exponential requires a dimensionless number" };
188
+ if (!unitsEqual(arg.unit, void 0)) return { wrongType: "exponential requires a dimensionless number" };
189
+ if (arg.kind === "complex") return finiteComplex("exponential", complexFromPolar(Math.exp(arg.re), arg.im));
112
190
  return finiteNumber("exponential", Math.exp(arg.value));
113
191
  },
114
192
  logarithm: (args) => {
115
193
  const [value, base, ...extra] = args;
116
- if (!isNumberValue(value) || extra.length > 0) return { wrongType: "logarithm requires a number and an optional base" };
117
- if (!isDimensionless(value)) return { wrongType: "logarithm requires a dimensionless number" };
194
+ if (value?.kind !== "number" && value?.kind !== "complex" || extra.length > 0) return { wrongType: "logarithm requires a number or a complex number and an optional base" };
195
+ if (!unitsEqual(value.unit, void 0)) return { wrongType: "logarithm requires a dimensionless number" };
118
196
  const baseNumber = base === void 0 ? void 0 : dimensionlessNumber(base);
119
197
  if (base !== void 0 && baseNumber === void 0) return { wrongType: "logarithm requires its base to be a dimensionless number" };
120
- if (value.value <= 0) return { domainError: "logarithm requires a number above zero" };
121
- if (baseNumber === void 0) return finiteNumber("logarithm", Math.log(value.value));
122
- if (baseNumber <= 0 || baseNumber === 1) return { domainError: "logarithm requires its base to be above zero and not one" };
123
- if (baseNumber === DECIMAL_BASE) return finiteNumber("logarithm", Math.log10(value.value));
124
- if (baseNumber === BINARY_BASE) return finiteNumber("logarithm", Math.log2(value.value));
125
- return finiteNumber("logarithm", Math.log(value.value) / Math.log(baseNumber));
198
+ if (value.kind === "number" && value.value <= 0) return { domainError: "logarithm requires a number above zero" };
199
+ if (value.kind === "complex" && value.re === 0 && value.im === 0) return { domainError: "logarithm requires a complex number other than zero" };
200
+ if (baseNumber !== void 0 && (baseNumber <= 0 || baseNumber === 1)) return { domainError: "logarithm requires its base to be above zero and not one" };
201
+ if (value.kind === "number") return finiteNumber("logarithm", realLogarithm(value.value, baseNumber));
202
+ return finiteComplex("logarithm", {
203
+ re: realLogarithm(complexMagnitude(value).value, baseNumber),
204
+ im: complexPhase(value).value / (baseNumber === void 0 ? 1 : Math.log(baseNumber))
205
+ });
126
206
  },
127
207
  magnitude: (args) => {
128
208
  const [arg] = args;
@@ -139,6 +219,23 @@ const builtinFunctions = Object.freeze({
139
219
  if (args.length !== 1 || arg?.kind !== "complex") return { wrongType: "phase requires exactly one complex argument" };
140
220
  if (!Number.isFinite(arg.re) || !Number.isFinite(arg.im)) return { domainError: "phase requires finite components" };
141
221
  return complexPhase(arg);
222
+ },
223
+ sine: dimensionlessFunction("sine", Math.sin),
224
+ cosine: dimensionlessFunction("cosine", Math.cos),
225
+ tangent: dimensionlessFunction("tangent", Math.tan),
226
+ arcSine: unitIntervalInverse("arcSine", Math.asin),
227
+ arcCosine: unitIntervalInverse("arcCosine", Math.acos),
228
+ arcTangent: dimensionlessFunction("arcTangent", Math.atan),
229
+ arcTangent2: (args) => {
230
+ const [y, x] = args;
231
+ if (args.length !== 2 || !isNumberValue(y) || !isNumberValue(x)) return { wrongType: "arcTangent2 requires exactly two number arguments" };
232
+ if (!isDimensionless(y) || !isDimensionless(x)) return { wrongType: "arcTangent2 requires dimensionless numbers" };
233
+ if (!Number.isFinite(y.value) || !Number.isFinite(x.value)) return { domainError: "arcTangent2 requires finite arguments" };
234
+ return complexPhase({
235
+ kind: "complex",
236
+ re: x.value,
237
+ im: y.value
238
+ });
142
239
  }
143
240
  });
144
241
  //#endregion
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_index_C4tKZ0yW = require("./index.C4tKZ0yW-q5POG9-K.cjs");
2
+ const require_index_C4tKZ0yW = require("./index.C4tKZ0yW-BXgPC7yz.cjs");
3
3
  const require_evaluator_factory = require("./evaluator-factory.cjs");
4
4
  //#region src/evaluator-indeterminacy-helpers.ts
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { createEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.js";
2
- import { t as globalExpect } from "./index.C4tKZ0yW-ICJbIYnA.js";
2
+ import { t as globalExpect } from "./index.C4tKZ0yW-D6D25qxM.js";
3
3
  //#region src/evaluator-indeterminacy-helpers.ts
4
4
  /**
5
5
  * Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.unit.test.ts, evaluator.indeterminacy-cases.unit.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.unit.test.ts.
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_index_C4tKZ0yW = require("./index.C4tKZ0yW-q5POG9-K.cjs");
2
+ const require_index_C4tKZ0yW = require("./index.C4tKZ0yW-BXgPC7yz.cjs");
3
3
  //#region src/evaluator-test-helpers.ts
4
4
  /** A resolver reporting a fixed `{ kind: "number", value: 10, unit: { m: 1 } }` for key `"present"`, and not-found for anything else -- `resolveLookup`/`resolveCollection` are never exercised by expression-level nodes and are stubbed only to satisfy `Resolvers`. Shared across the split `evaluator.*.test.ts` files below; a test needing genuinely different resolver behaviour spreads over it (`{ ...resolvers, resolveValue: ... }`) locally rather than mutating this shared instance. */
5
5
  const resolvers = {
@@ -1,4 +1,4 @@
1
- import { t as globalExpect } from "./index.C4tKZ0yW-ICJbIYnA.js";
1
+ import { t as globalExpect } from "./index.C4tKZ0yW-D6D25qxM.js";
2
2
  //#region src/evaluator-test-helpers.ts
3
3
  /** A resolver reporting a fixed `{ kind: "number", value: 10, unit: { m: 1 } }` for key `"present"`, and not-found for anything else -- `resolveLookup`/`resolveCollection` are never exercised by expression-level nodes and are stubbed only to satisfy `Resolvers`. Shared across the split `evaluator.*.test.ts` files below; a test needing genuinely different resolver behaviour spreads over it (`{ ...resolvers, resolveValue: ... }`) locally rather than mutating this shared instance. */
4
4
  const resolvers = {
@@ -1,7 +1,7 @@
1
1
  //#region \0rolldown/runtime.js
2
2
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
3
3
  //#endregion
4
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/tinyrainbow.Ht9iggcq.js
4
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/tinyrainbow.Ht9iggcq.js
5
5
  var b$1 = {
6
6
  reset: [0, 0],
7
7
  bold: [
@@ -84,7 +84,7 @@ function C({ force: e } = {}) {
84
84
  }
85
85
  var y$1 = C();
86
86
  //#endregion
87
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/index.cx-_w29y.js
87
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/index.cx-_w29y.js
88
88
  function _mergeNamespaces(n, m) {
89
89
  m.forEach(function(e) {
90
90
  e && typeof e !== "string" && !Array.isArray(e) && Object.keys(e).forEach(function(k) {
@@ -1247,7 +1247,7 @@ const plugins = {
1247
1247
  Error: ErrorPlugin
1248
1248
  };
1249
1249
  //#endregion
1250
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/display.CXBnkt9a.js
1250
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/display.CXBnkt9a.js
1251
1251
  const { AsymmetricMatcher: AsymmetricMatcher$3, DOMCollection: DOMCollection$2, DOMElement: DOMElement$2, Immutable: Immutable$2, ReactElement: ReactElement$2, ReactTestComponent: ReactTestComponent$2 } = plugins;
1252
1252
  const PLUGINS$2 = [
1253
1253
  ReactTestComponent$2,
@@ -1708,7 +1708,7 @@ const isAbsolute = function(p) {
1708
1708
  return _IS_ABSOLUTE_RE.test(p);
1709
1709
  };
1710
1710
  //#endregion
1711
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/source-map.DUxvo12T.js
1711
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/source-map.DUxvo12T.js
1712
1712
  var build = {};
1713
1713
  var hasRequiredBuild;
1714
1714
  function requireBuild() {
@@ -2487,7 +2487,7 @@ function getOriginalPosition(map, needle) {
2487
2487
  return result;
2488
2488
  }
2489
2489
  //#endregion
2490
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/task-utils.js
2490
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/task-utils.js
2491
2491
  /* @__NO_SIDE_EFFECTS__ */
2492
2492
  function getNames(task) {
2493
2493
  const names = [task.name];
@@ -2504,7 +2504,7 @@ function createTaskName(names, separator = " > ") {
2504
2504
  return names.filter((name) => name !== void 0).join(separator);
2505
2505
  }
2506
2506
  //#endregion
2507
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/run.BTlFXlnv.js
2507
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/run.BTlFXlnv.js
2508
2508
  /**
2509
2509
  * Diff Match and Patch
2510
2510
  * Copyright 2018 The diff-match-patch Authors.
@@ -5072,7 +5072,7 @@ async function finishSendTasksUpdate(runner) {
5072
5072
  await Promise.all(pendingTasksUpdates);
5073
5073
  }
5074
5074
  //#endregion
5075
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/utils.DYj33du9.js
5075
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/utils.DYj33du9.js
5076
5076
  const NAME_WORKER_STATE = "__vitest_worker__";
5077
5077
  function getWorkerState() {
5078
5078
  const workerState = globalThis[NAME_WORKER_STATE];
@@ -5098,7 +5098,7 @@ function resetModules(modules, resetMocks = false) {
5098
5098
  });
5099
5099
  }
5100
5100
  //#endregion
5101
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/spy.DgMTfhrK.js
5101
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/spy.DgMTfhrK.js
5102
5102
  function isMockFunction(fn) {
5103
5103
  return typeof fn === "function" && "_isMockFunction" in fn && fn._isMockFunction === true;
5104
5104
  }
@@ -8495,7 +8495,7 @@ function use(fn) {
8495
8495
  }
8496
8496
  __name(use, "use");
8497
8497
  //#endregion
8498
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/plugins.D2ut1V9b.js
8498
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/plugins.D2ut1V9b.js
8499
8499
  const serialize$1 = (val, config, indentation, depth, refs, printer) => {
8500
8500
  const name = val.getMockName();
8501
8501
  const nameString = name === "vi.fn()" ? "" : ` ${name}`;
@@ -8528,7 +8528,7 @@ function getSerializers() {
8528
8528
  return PLUGINS;
8529
8529
  }
8530
8530
  //#endregion
8531
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/offset.Dy-5Fdfn.js
8531
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/offset.Dy-5Fdfn.js
8532
8532
  const lineSplitRE = /\r?\n/;
8533
8533
  function positionToOffset(source, lineNumber, columnNumber) {
8534
8534
  const lines = source.split(lineSplitRE);
@@ -1,5 +1,5 @@
1
1
  import "expect-type";
2
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/tinyrainbow.Ht9iggcq.js
2
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/tinyrainbow.Ht9iggcq.js
3
3
  var b$1 = {
4
4
  reset: [0, 0],
5
5
  bold: [
@@ -82,7 +82,7 @@ function C({ force: e } = {}) {
82
82
  }
83
83
  var y$1 = C();
84
84
  //#endregion
85
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/index.cx-_w29y.js
85
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/index.cx-_w29y.js
86
86
  function _mergeNamespaces(n, m) {
87
87
  m.forEach(function(e) {
88
88
  e && typeof e !== "string" && !Array.isArray(e) && Object.keys(e).forEach(function(k) {
@@ -1245,7 +1245,7 @@ const plugins = {
1245
1245
  Error: ErrorPlugin
1246
1246
  };
1247
1247
  //#endregion
1248
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/display.CXBnkt9a.js
1248
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/display.CXBnkt9a.js
1249
1249
  const { AsymmetricMatcher: AsymmetricMatcher$3, DOMCollection: DOMCollection$2, DOMElement: DOMElement$2, Immutable: Immutable$2, ReactElement: ReactElement$2, ReactTestComponent: ReactTestComponent$2 } = plugins;
1250
1250
  const PLUGINS$2 = [
1251
1251
  ReactTestComponent$2,
@@ -1706,7 +1706,7 @@ const isAbsolute = function(p) {
1706
1706
  return _IS_ABSOLUTE_RE.test(p);
1707
1707
  };
1708
1708
  //#endregion
1709
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/source-map.DUxvo12T.js
1709
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/source-map.DUxvo12T.js
1710
1710
  var build = {};
1711
1711
  var hasRequiredBuild;
1712
1712
  function requireBuild() {
@@ -2485,7 +2485,7 @@ function getOriginalPosition(map, needle) {
2485
2485
  return result;
2486
2486
  }
2487
2487
  //#endregion
2488
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/task-utils.js
2488
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/task-utils.js
2489
2489
  /* @__NO_SIDE_EFFECTS__ */
2490
2490
  function getNames(task) {
2491
2491
  const names = [task.name];
@@ -2502,7 +2502,7 @@ function createTaskName(names, separator = " > ") {
2502
2502
  return names.filter((name) => name !== void 0).join(separator);
2503
2503
  }
2504
2504
  //#endregion
2505
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/run.BTlFXlnv.js
2505
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/run.BTlFXlnv.js
2506
2506
  /**
2507
2507
  * Diff Match and Patch
2508
2508
  * Copyright 2018 The diff-match-patch Authors.
@@ -5070,7 +5070,7 @@ async function finishSendTasksUpdate(runner) {
5070
5070
  await Promise.all(pendingTasksUpdates);
5071
5071
  }
5072
5072
  //#endregion
5073
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/utils.DYj33du9.js
5073
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/utils.DYj33du9.js
5074
5074
  const NAME_WORKER_STATE = "__vitest_worker__";
5075
5075
  function getWorkerState() {
5076
5076
  const workerState = globalThis[NAME_WORKER_STATE];
@@ -5096,7 +5096,7 @@ function resetModules(modules, resetMocks = false) {
5096
5096
  });
5097
5097
  }
5098
5098
  //#endregion
5099
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/spy.DgMTfhrK.js
5099
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/spy.DgMTfhrK.js
5100
5100
  function isMockFunction(fn) {
5101
5101
  return typeof fn === "function" && "_isMockFunction" in fn && fn._isMockFunction === true;
5102
5102
  }
@@ -8493,7 +8493,7 @@ function use(fn) {
8493
8493
  }
8494
8494
  __name(use, "use");
8495
8495
  //#endregion
8496
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/plugins.D2ut1V9b.js
8496
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/plugins.D2ut1V9b.js
8497
8497
  const serialize$1 = (val, config, indentation, depth, refs, printer) => {
8498
8498
  const name = val.getMockName();
8499
8499
  const nameString = name === "vi.fn()" ? "" : ` ${name}`;
@@ -8526,7 +8526,7 @@ function getSerializers() {
8526
8526
  return PLUGINS;
8527
8527
  }
8528
8528
  //#endregion
8529
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/offset.Dy-5Fdfn.js
8529
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/offset.Dy-5Fdfn.js
8530
8530
  const lineSplitRE = /\r?\n/;
8531
8531
  function positionToOffset(source, lineNumber, columnNumber) {
8532
8532
  const lines = source.split(lineSplitRE);
@@ -8567,7 +8567,7 @@ globalThis.performance.now.bind(globalThis.performance);
8567
8567
  globalThis.process?.hrtime?.bigint.bind(globalThis.process?.hrtime);
8568
8568
  globalThis.Bun?.nanoseconds;
8569
8569
  //#endregion
8570
- //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.3_vite@8.2.2_@types+node@26.6.5_5333ae081f4122dbae688304e924e108/node_modules/vitest/dist/chunks/index.C4tKZ0yW.js
8570
+ //#region ../../node_modules/.pnpm/vitest@5.0.3_@types+node@26.6.5_@vitest+coverage-v8@5.0.4_vite@8.2.2_@types+node@26.6.5_220b0db820952837b535c2e83c4bd0a5/node_modules/vitest/dist/chunks/index.C4tKZ0yW.js
8571
8571
  var naturalCompare$1 = { exports: {} };
8572
8572
  var hasRequiredNaturalCompare;
8573
8573
  function requireNaturalCompare() {
@@ -4,7 +4,7 @@ import { parseArgs } from "node:util";
4
4
  import { z } from "zod";
5
5
  import { RegexParseError, compilePattern } from "trilean-regex";
6
6
  //#region package.json
7
- var version = "1.9.1";
7
+ var version = "1.10.0";
8
8
  //#endregion
9
9
  //#region src/computed-value.ts
10
10
  /** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
@@ -1384,6 +1384,80 @@ function singleNumber(name, args) {
1384
1384
  if (args.length !== 1 || !isNumberValue(arg)) return { wrongType: `${name} requires exactly one number argument` };
1385
1385
  return arg;
1386
1386
  }
1387
+ /** The one exit for every complex result, as `finiteNumber` is for real ones. A complex argument always gives a complex result, even when the imaginary part comes out zero, as the evaluator's own complex arithmetic does: the result kind follows the argument kind, never the value. */
1388
+ function finiteComplex(name, { re, im }, unit) {
1389
+ if (!Number.isFinite(re) || !Number.isFinite(im)) return { domainError: `${name} produced a result that is not a finite number` };
1390
+ return unit === void 0 ? {
1391
+ kind: "complex",
1392
+ re,
1393
+ im
1394
+ } : {
1395
+ kind: "complex",
1396
+ re,
1397
+ im,
1398
+ unit
1399
+ };
1400
+ }
1401
+ function singleNumberOrComplex(name, args) {
1402
+ const [arg] = args;
1403
+ if (args.length !== 1 || arg?.kind !== "number" && arg?.kind !== "complex") return { wrongType: `${name} requires exactly one number or complex number argument` };
1404
+ return arg;
1405
+ }
1406
+ /** The value of a single dimensionless real argument, or the `wrongType` refusing anything else (a complex value included). */
1407
+ function singleDimensionless(name, args) {
1408
+ const arg = singleNumber(name, args);
1409
+ if ("wrongType" in arg) return arg;
1410
+ if (!isDimensionless(arg)) return { wrongType: `${name} requires a dimensionless number` };
1411
+ return arg.value;
1412
+ }
1413
+ /** A real function of one dimensionless number, returning a dimensionless number. */
1414
+ function dimensionlessFunction(name, apply) {
1415
+ return (args) => {
1416
+ const value = singleDimensionless(name, args);
1417
+ if (typeof value !== "number") return value;
1418
+ return finiteNumber(name, apply(value));
1419
+ };
1420
+ }
1421
+ /** An inverse sine or cosine, whose real domain is the closed interval from -1 to 1; outside it the inverse is not a real number, which is a `domainError` rather than the `NaN` `Math.asin` and `Math.acos` return. */
1422
+ function unitIntervalInverse(name, apply) {
1423
+ return (args) => {
1424
+ const value = singleDimensionless(name, args);
1425
+ if (typeof value !== "number") return value;
1426
+ if (!(Math.abs(value) <= 1)) return { domainError: `${name} requires a number from -1 to 1` };
1427
+ return finiteNumber(name, apply(value));
1428
+ };
1429
+ }
1430
+ /**
1431
+ * The principal square root of a complex value: the root whose real part is not negative, with the branch cut along the negative real axis. On the cut the root lies on the positive imaginary axis whatever the sign of the zero imaginary part, matching `complexPhase`'s +pi for a negative real number, so `sqrt(z)` is `sqrt(|z|) * e^(i * phase(z) / 2)` everywhere.
1432
+ *
1433
+ * It is computed by the closed form rather than through that polar expression: with `t = sqrt((|re| + |z|) / 2)`, the root is `t + (im / 2t)i` when `re` is not negative and `|im| / 2t + t i` (with the sign of `im` on `t`) otherwise. Neither form subtracts two nearly equal quantities, and an exactly representable root comes out exact (`sqrt(-4)` is `2i`, where `cos(pi / 2)` would leave a stray real part of about 1e-16).
1434
+ */
1435
+ function principalSquareRoot(value) {
1436
+ const modulus = complexMagnitude(value).value;
1437
+ if (modulus === 0) return {
1438
+ re: 0,
1439
+ im: 0
1440
+ };
1441
+ const sum = Math.abs(value.re) + modulus;
1442
+ const half = Number.isFinite(sum) ? sum / 2 : Math.abs(value.re) / 2 + modulus / 2;
1443
+ const t = Math.sqrt(half);
1444
+ const { im } = value;
1445
+ if (value.re >= 0) return {
1446
+ re: t,
1447
+ im: im / (2 * t)
1448
+ };
1449
+ return {
1450
+ re: Math.abs(im) / (2 * t),
1451
+ im: im < 0 ? -t : t
1452
+ };
1453
+ }
1454
+ /** The logarithm of a positive real number, natural or to a base already checked to be above zero and not one. */
1455
+ function realLogarithm(value, base) {
1456
+ if (base === void 0) return Math.log(value);
1457
+ if (base === DECIMAL_BASE) return Math.log10(value);
1458
+ if (base === BINARY_BASE) return Math.log2(value);
1459
+ return Math.log(value) / Math.log(base);
1460
+ }
1387
1461
  /** Halves every dimension's exponent, or `false` when one is odd and the root would need a fractional exponent. */
1388
1462
  function halveUnit(unit) {
1389
1463
  if (unit === void 0) return void 0;
@@ -1423,11 +1497,13 @@ function roundHalfAwayFromZero(value, places) {
1423
1497
  return rounded === 0 ? 0 : Math.sign(value) * rounded;
1424
1498
  }
1425
1499
  /**
1426
- * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional base), and the two projections of a complex value onto the reals, `magnitude` and `phase`. Every function but those two takes real numbers only, and refuses a complex value; `magnitude` takes a real or a complex number, and `phase` a complex one.
1500
+ * The numeric functions a `call` node can name when an embedder has no registry of its own: `minimum` and `maximum` (one or more numbers in a shared unit), `absoluteValue`, `round` (half away from zero, with an optional count of decimal places), `squareRoot`, `exponential`, `logarithm` (natural, or to an optional real base), the two projections of a complex value onto the reals, `magnitude` and `phase`, and the trigonometric functions `sine`, `cosine`, `tangent`, `arcSine`, `arcCosine`, `arcTangent` and `arcTangent2` (the angle of the point `(x, y)`, called with `y` first).
1427
1501
  *
1428
- * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places) or a result that is not a finite number is a `domainError`.
1502
+ * Which take a complex value: `squareRoot`, `exponential`, `logarithm` and `magnitude` take a real or a complex number, and `phase` a complex one only. Every other function takes real numbers only and refuses a complex value. A real argument to `squareRoot`, `exponential` or `logarithm` gives a real result, so a negative `squareRoot` or a `logarithm` of zero or a negative number stays a `domainError` rather than becoming complex; a complex argument gives a complex result, the principal value, even when its imaginary part comes out zero, as the evaluator's own complex arithmetic does. The principal values take the branch cut along the negative real axis with `phase`'s convention on it: `logarithm` is `log|z| + i phase(z)` (divided through by the natural logarithm of a base when one is given), so its imaginary part lies in [-pi, pi], and `squareRoot` is the root with a real part that is not negative, on the positive imaginary axis for a negative real number whatever the sign of its zero imaginary part.
1429
1503
  *
1430
- * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential` and `logarithm` accept only dimensionless numbers and return one.
1504
+ * Failures split as the evaluator's own operators split. An argument a function cannot accept at all (the wrong kind, the wrong count, or units that do not fit) is a `wrongType`; an argument of the right kind outside the function's domain (a negative real `squareRoot`, a `logarithm` of zero, a base of one, a fractional count of decimal places, an `arcSine` or `arcCosine` outside -1 to 1) or a result that is not a finite number (in either component of a complex one) is a `domainError`. A `tangent` near a pole is large but finite, since no double is an odd multiple of pi/2 exactly.
1505
+ *
1506
+ * Units follow the evaluator's rule that dimensions are never silently converted. `minimum`, `maximum`, `absoluteValue`, `round` and `magnitude` keep the argument's unit (and the first two require all arguments to share one); `phase` returns a dimensionless angle in radians in the range [-pi, pi], whatever unit its argument carries, with a negative real number +pi whatever the sign of its zero imaginary part (a signed zero never gives -pi, though a tiny negative imaginary part can round to it) and zero 0 (a component that is not finite is a `domainError`); `squareRoot` halves each dimension's exponent and refuses a unit whose exponents are not all even; `exponential`, `logarithm` and the trigonometric functions accept only dimensionless numbers and return one, angles in radians. `arcTangent2` is the `phase` of `x + yi`, so it shares that range and signed-zero handling, and its two arguments must be finite.
1431
1507
  *
1432
1508
  * Frozen, so mutating the export cannot change what `evaluateDocument` resolves.
1433
1509
  */
@@ -1448,31 +1524,35 @@ const builtinFunctions = Object.freeze({
1448
1524
  return finiteNumber("round", roundHalfAwayFromZero(value.value, places.value), value.unit);
1449
1525
  },
1450
1526
  squareRoot: (args) => {
1451
- const arg = singleNumber("squareRoot", args);
1527
+ const arg = singleNumberOrComplex("squareRoot", args);
1452
1528
  if ("wrongType" in arg) return arg;
1453
1529
  const unit = halveUnit(arg.unit);
1454
1530
  if (unit === false) return { wrongType: "squareRoot requires every unit exponent to be even" };
1531
+ if (arg.kind === "complex") return finiteComplex("squareRoot", principalSquareRoot(arg), unit);
1455
1532
  if (arg.value < 0) return { domainError: "squareRoot of a negative number is not a real number" };
1456
1533
  return finiteNumber("squareRoot", Math.sqrt(arg.value), unit);
1457
1534
  },
1458
1535
  exponential: (args) => {
1459
- const arg = singleNumber("exponential", args);
1536
+ const arg = singleNumberOrComplex("exponential", args);
1460
1537
  if ("wrongType" in arg) return arg;
1461
- if (!isDimensionless(arg)) return { wrongType: "exponential requires a dimensionless number" };
1538
+ if (!unitsEqual(arg.unit, void 0)) return { wrongType: "exponential requires a dimensionless number" };
1539
+ if (arg.kind === "complex") return finiteComplex("exponential", complexFromPolar(Math.exp(arg.re), arg.im));
1462
1540
  return finiteNumber("exponential", Math.exp(arg.value));
1463
1541
  },
1464
1542
  logarithm: (args) => {
1465
1543
  const [value, base, ...extra] = args;
1466
- if (!isNumberValue(value) || extra.length > 0) return { wrongType: "logarithm requires a number and an optional base" };
1467
- if (!isDimensionless(value)) return { wrongType: "logarithm requires a dimensionless number" };
1544
+ if (value?.kind !== "number" && value?.kind !== "complex" || extra.length > 0) return { wrongType: "logarithm requires a number or a complex number and an optional base" };
1545
+ if (!unitsEqual(value.unit, void 0)) return { wrongType: "logarithm requires a dimensionless number" };
1468
1546
  const baseNumber = base === void 0 ? void 0 : dimensionlessNumber(base);
1469
1547
  if (base !== void 0 && baseNumber === void 0) return { wrongType: "logarithm requires its base to be a dimensionless number" };
1470
- if (value.value <= 0) return { domainError: "logarithm requires a number above zero" };
1471
- if (baseNumber === void 0) return finiteNumber("logarithm", Math.log(value.value));
1472
- if (baseNumber <= 0 || baseNumber === 1) return { domainError: "logarithm requires its base to be above zero and not one" };
1473
- if (baseNumber === DECIMAL_BASE) return finiteNumber("logarithm", Math.log10(value.value));
1474
- if (baseNumber === BINARY_BASE) return finiteNumber("logarithm", Math.log2(value.value));
1475
- return finiteNumber("logarithm", Math.log(value.value) / Math.log(baseNumber));
1548
+ if (value.kind === "number" && value.value <= 0) return { domainError: "logarithm requires a number above zero" };
1549
+ if (value.kind === "complex" && value.re === 0 && value.im === 0) return { domainError: "logarithm requires a complex number other than zero" };
1550
+ if (baseNumber !== void 0 && (baseNumber <= 0 || baseNumber === 1)) return { domainError: "logarithm requires its base to be above zero and not one" };
1551
+ if (value.kind === "number") return finiteNumber("logarithm", realLogarithm(value.value, baseNumber));
1552
+ return finiteComplex("logarithm", {
1553
+ re: realLogarithm(complexMagnitude(value).value, baseNumber),
1554
+ im: complexPhase(value).value / (baseNumber === void 0 ? 1 : Math.log(baseNumber))
1555
+ });
1476
1556
  },
1477
1557
  magnitude: (args) => {
1478
1558
  const [arg] = args;
@@ -1489,6 +1569,23 @@ const builtinFunctions = Object.freeze({
1489
1569
  if (args.length !== 1 || arg?.kind !== "complex") return { wrongType: "phase requires exactly one complex argument" };
1490
1570
  if (!Number.isFinite(arg.re) || !Number.isFinite(arg.im)) return { domainError: "phase requires finite components" };
1491
1571
  return complexPhase(arg);
1572
+ },
1573
+ sine: dimensionlessFunction("sine", Math.sin),
1574
+ cosine: dimensionlessFunction("cosine", Math.cos),
1575
+ tangent: dimensionlessFunction("tangent", Math.tan),
1576
+ arcSine: unitIntervalInverse("arcSine", Math.asin),
1577
+ arcCosine: unitIntervalInverse("arcCosine", Math.acos),
1578
+ arcTangent: dimensionlessFunction("arcTangent", Math.atan),
1579
+ arcTangent2: (args) => {
1580
+ const [y, x] = args;
1581
+ if (args.length !== 2 || !isNumberValue(y) || !isNumberValue(x)) return { wrongType: "arcTangent2 requires exactly two number arguments" };
1582
+ if (!isDimensionless(y) || !isDimensionless(x)) return { wrongType: "arcTangent2 requires dimensionless numbers" };
1583
+ if (!Number.isFinite(y.value) || !Number.isFinite(x.value)) return { domainError: "arcTangent2 requires finite arguments" };
1584
+ return complexPhase({
1585
+ kind: "complex",
1586
+ re: x.value,
1587
+ im: y.value
1588
+ });
1492
1589
  }
1493
1590
  });
1494
1591
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trilean",
3
3
  "description": "Three-valued predicate and expression evaluation trees, stored as JSON and evaluated against injected resolvers, for domain logic — business rules, eligibility checks, formulas, search filters, and more — that needs to be data instead of code.",
4
- "version": "1.9.1",
4
+ "version": "1.10.0",
5
5
  "bin": {
6
6
  "trilean": "./dist-cli/trilean.mjs"
7
7
  },
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/ExaDev/trilean/issues"
10
10
  },
11
11
  "dependencies": {
12
- "trilean-regex": "1.0.14",
12
+ "trilean-regex": "1.0.15",
13
13
  "zod": "^4.6.5"
14
14
  },
15
15
  "devDependencies": {
@@ -17,7 +17,7 @@
17
17
  "@cloudflare/vitest-plugin": "1.4.0",
18
18
  "@exadev/eslint-config": "3.0.0",
19
19
  "@types/node": "^26.6.5",
20
- "@vitest/coverage-v8": "^5.0.3",
20
+ "@vitest/coverage-v8": "^5.0.4",
21
21
  "canonicalize": "^5.1.0",
22
22
  "eslint": "^10.12.0",
23
23
  "eslint-config-prettier": "^10.1.8",
@@ -1 +1 @@
1
- {"$defs":{"ExpressionNode":{"anyOf":[{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"numberLiteral","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"},"value":{"type":"number"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"booleanLiteral","type":"string"},"value":{"type":"boolean"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"instantLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"durationLiteral","type":"string"},"unit":{"enum":["ms","s","min","h","d"],"type":"string"},"value":{"type":"number"}},"required":["kind","value","unit"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"reference","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","key"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"arithmetic","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["add","subtract","multiply","divide","power","modulo"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"negate","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"args":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"fn":{"type":"string"},"kind":{"const":"call","type":"string"}},"required":["kind","fn","args"],"type":"object"},{"additionalProperties":false,"properties":{"keys":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"lookup","type":"string"},"table":{"$ref":"#/$defs/schema0"}},"required":["kind","table","keys"],"type":"object"},{"additionalProperties":false,"properties":{"cases":{"items":{"additionalProperties":false,"properties":{"then":{"$ref":"#/$defs/ExpressionNode"},"when":{"$ref":"#/$defs/PredicateNode"}},"required":["when","then"],"type":"object"},"type":"array"},"fallback":{"$ref":"#/$defs/ExpressionNode"},"hitPolicy":{"enum":["first","unique"],"type":"string"},"kind":{"const":"conditional","type":"string"}},"required":["kind","cases","fallback"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"combiner":{"oneOf":[{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"max","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"min","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"combine":{"$ref":"#/$defs/ExpressionNode"},"initial":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"reduce","type":"string"}},"required":["mode","initial","combine"],"type":"object"}]},"filter":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"fold","type":"string"}},"required":["kind","collection","combiner"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"accumulator","type":"string"}},"required":["kind"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"delegate","type":"string"},"payload":{"$ref":"#/$defs/schema0"},"system":{"type":"string"}},"required":["kind","system","payload"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},{"anyOf":[{"additionalProperties":false,"properties":{"im":{"type":"number"},"kind":{"const":"complexLiteral","type":"string"},"re":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","re","im"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"complexLiteral","type":"string"},"magnitude":{"type":"number"},"phase":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","magnitude","phase"],"type":"object"}]}]},"PredicateNode":{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"not","type":"string"},"operand":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"and","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"or","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"allOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"anyOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"compare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["gt","gte","lt","lte","eq","neq"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textCompare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["equals","notEquals","matches","notMatches","portableMatches","portableNotMatches"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"candidates":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"memberOf","type":"string"},"op":{"enum":["in","notIn"],"type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","operand","candidates"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"exists","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"some","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"every","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},"schema0":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"items":{"$ref":"#/$defs/schema0"},"type":"array"},{"additionalProperties":{"$ref":"#/$defs/schema0"},"propertyNames":{"type":"string"},"type":"object"}]}},"$id":"https://cdn.jsdelivr.net/npm/trilean@1.9.1/schemas/trilean.schema.json","$schema":"https://json-schema.org/draft/2020-12/schema","oneOf":[{"$ref":"#/$defs/PredicateNode"},{"$ref":"#/$defs/ExpressionNode"}]}
1
+ {"$defs":{"ExpressionNode":{"anyOf":[{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"numberLiteral","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"},"value":{"type":"number"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"booleanLiteral","type":"string"},"value":{"type":"boolean"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"instantLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"durationLiteral","type":"string"},"unit":{"enum":["ms","s","min","h","d"],"type":"string"},"value":{"type":"number"}},"required":["kind","value","unit"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"reference","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","key"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"arithmetic","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["add","subtract","multiply","divide","power","modulo"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"negate","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"args":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"fn":{"type":"string"},"kind":{"const":"call","type":"string"}},"required":["kind","fn","args"],"type":"object"},{"additionalProperties":false,"properties":{"keys":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"lookup","type":"string"},"table":{"$ref":"#/$defs/schema0"}},"required":["kind","table","keys"],"type":"object"},{"additionalProperties":false,"properties":{"cases":{"items":{"additionalProperties":false,"properties":{"then":{"$ref":"#/$defs/ExpressionNode"},"when":{"$ref":"#/$defs/PredicateNode"}},"required":["when","then"],"type":"object"},"type":"array"},"fallback":{"$ref":"#/$defs/ExpressionNode"},"hitPolicy":{"enum":["first","unique"],"type":"string"},"kind":{"const":"conditional","type":"string"}},"required":["kind","cases","fallback"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"combiner":{"oneOf":[{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"max","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"min","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"combine":{"$ref":"#/$defs/ExpressionNode"},"initial":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"reduce","type":"string"}},"required":["mode","initial","combine"],"type":"object"}]},"filter":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"fold","type":"string"}},"required":["kind","collection","combiner"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"accumulator","type":"string"}},"required":["kind"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"delegate","type":"string"},"payload":{"$ref":"#/$defs/schema0"},"system":{"type":"string"}},"required":["kind","system","payload"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},{"anyOf":[{"additionalProperties":false,"properties":{"im":{"type":"number"},"kind":{"const":"complexLiteral","type":"string"},"re":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","re","im"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"complexLiteral","type":"string"},"magnitude":{"type":"number"},"phase":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","magnitude","phase"],"type":"object"}]}]},"PredicateNode":{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"not","type":"string"},"operand":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"and","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"or","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"allOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"anyOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"compare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["gt","gte","lt","lte","eq","neq"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textCompare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["equals","notEquals","matches","notMatches","portableMatches","portableNotMatches"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"candidates":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"memberOf","type":"string"},"op":{"enum":["in","notIn"],"type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","operand","candidates"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"exists","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"some","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"every","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},"schema0":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"items":{"$ref":"#/$defs/schema0"},"type":"array"},{"additionalProperties":{"$ref":"#/$defs/schema0"},"propertyNames":{"type":"string"},"type":"object"}]}},"$id":"https://cdn.jsdelivr.net/npm/trilean@1.10.0/schemas/trilean.schema.json","$schema":"https://json-schema.org/draft/2020-12/schema","oneOf":[{"$ref":"#/$defs/PredicateNode"},{"$ref":"#/$defs/ExpressionNode"}]}