MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / solutions

Function solutions

test/compute-engine/solve-domain.test.ts:10–17  ·  view source on GitHub ↗

Evaluate a `Solve` expression and return its solution values as numbers, * sorted ascending. Throws if the result is not a decided `List`.

(expr: BoxedExpression)

Source from the content-addressed store, hash-verified

8
9/** Evaluate a `Solve` expression and return its solution values as numbers,
10 * sorted ascending. Throws if the result is not a decided `List`. */
11function solutions(expr: BoxedExpression): number[] {
12 const r = expr.evaluate();
13 if (r.operator !== 'List')
14 throw new Error(`Expected a List, got ${r.operator}: ${r.toString()}`);
15 // `.N().re` (not `.re`): a periodic-expansion result is an EXACT π-multiple,
16 // a symbolic value whose bare `.re` is `NaN` — numericize before comparing.
17 return r.ops!.map((o) => o.N().re).sort((a, b) => a - b);
18}
19
20/** True if the `Solve` expression stayed unevaluated (undecided). */

Callers 1

Calls 4

evaluateMethod · 0.65
toStringMethod · 0.65
mapMethod · 0.65
NMethod · 0.65

Tested by

no test coverage detected