@cortex-js/compute-engine 0.26.2 → 0.26.4
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 +5 -3
- package/dist/compute-engine.esm.js +60 -28
- package/dist/compute-engine.js +60 -28
- package/dist/compute-engine.min.esm.js +23 -23
- package/dist/compute-engine.min.js +22 -22
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/buffer.d.ts +1 -1
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/styled-text.d.ts +1 -1
- package/dist/types/common/suggest.d.ts +1 -1
- package/dist/types/common/syntax-highlighter.d.ts +1 -1
- package/dist/types/common/terminal.d.ts +1 -1
- package/dist/types/common/type/parse.d.ts +1 -1
- package/dist/types/common/type/primitive.d.ts +1 -1
- package/dist/types/common/type/serialize.d.ts +1 -1
- package/dist/types/common/type/subtype.d.ts +1 -1
- package/dist/types/common/type/types.d.ts +1 -1
- package/dist/types/common/type/utils.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/public.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/tensor-fields.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +1 -1
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/public.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/public.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
- package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/identifiers.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,13 +27,15 @@ import { ComputeEngine } from "@cortex-js/compute-engine";
|
|
|
27
27
|
|
|
28
28
|
const ce = new ComputeEngine();
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
ce.parse("2^{11}-1 \\in \\Z").evaluate().print()
|
|
31
31
|
// ➔ "True"
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## FAQ
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
**Q** How do I build the project?
|
|
37
|
+
|
|
38
|
+
[Build](BUILD.md) instructions
|
|
37
39
|
|
|
38
40
|
## Related Projects
|
|
39
41
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 0.26.
|
|
1
|
+
/** Compute Engine 0.26.4 */
|
|
2
2
|
|
|
3
3
|
// src/compute-engine/boxed-expression/public.ts
|
|
4
4
|
function isRuleStep(x) {
|
|
@@ -9596,7 +9596,10 @@ function canonicalMultiply(ce, ops) {
|
|
|
9596
9596
|
if (next.operator === "Sqrt" && next.op1.isNumberLiteral && isSubtype(next.op1.type, "finite_integer")) {
|
|
9597
9597
|
let radical = next.op1.numericValue;
|
|
9598
9598
|
if (typeof radical !== "number") radical = radical.re;
|
|
9599
|
-
if (radical >= SMALL_INTEGER)
|
|
9599
|
+
if (radical >= SMALL_INTEGER) {
|
|
9600
|
+
ys.push(x);
|
|
9601
|
+
continue;
|
|
9602
|
+
}
|
|
9600
9603
|
if (isSubtype(x.type, "finite_rational")) {
|
|
9601
9604
|
const rational = x.numericValue;
|
|
9602
9605
|
const [num, den] = typeof rational === "number" ? [rational, 1] : [rational.numerator.re, rational.denominator.re];
|
|
@@ -9689,6 +9692,7 @@ function mulN(...xs) {
|
|
|
9689
9692
|
function canonicalDivide(op1, op2) {
|
|
9690
9693
|
const ce = op1.engine;
|
|
9691
9694
|
if (!op1.isValid || !op2.isValid) return ce._fn("Divide", [op1, op2]);
|
|
9695
|
+
if (op1.isNaN || op2.isNaN) return ce.NaN;
|
|
9692
9696
|
if (op2.is(0)) return op1.is(0) ? ce.NaN : ce.ComplexInfinity;
|
|
9693
9697
|
if (op1.is(0)) return ce.Zero;
|
|
9694
9698
|
if (op2.is(0) === false) {
|
|
@@ -9888,9 +9892,11 @@ var Product = class _Product {
|
|
|
9888
9892
|
return;
|
|
9889
9893
|
}
|
|
9890
9894
|
if (term.isInfinity) {
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
|
|
9895
|
+
if (isOne(exp2)) {
|
|
9896
|
+
this.coefficient = this.engine._numericValue(
|
|
9897
|
+
term.isNegative ? -Infinity : Infinity
|
|
9898
|
+
);
|
|
9899
|
+
} else this.terms.push({ term, exponent: exp2 });
|
|
9894
9900
|
return;
|
|
9895
9901
|
}
|
|
9896
9902
|
if (isOne(exp2)) {
|
|
@@ -10045,8 +10051,15 @@ var Product = class _Product {
|
|
|
10045
10051
|
const ce = this.engine;
|
|
10046
10052
|
const coef = this.coefficient;
|
|
10047
10053
|
if (coef.isZero) return [ce.Zero, ce.One];
|
|
10048
|
-
if (coef.isPositiveInfinity || coef.isNegativeInfinity)
|
|
10054
|
+
if (coef.isPositiveInfinity || coef.isNegativeInfinity) {
|
|
10055
|
+
if (this.terms.length === 0) {
|
|
10056
|
+
return [
|
|
10057
|
+
coef.isPositiveInfinity ? ce.PositiveInfinity : ce.NegativeInfinity,
|
|
10058
|
+
ce.One
|
|
10059
|
+
];
|
|
10060
|
+
}
|
|
10049
10061
|
return [ce.NaN, ce.NaN];
|
|
10062
|
+
}
|
|
10050
10063
|
const isNegativeOne2 = coef.isNegativeOne;
|
|
10051
10064
|
if (isNegativeOne2) this.coefficient = ce._numericValue(1);
|
|
10052
10065
|
const xs = this.groupedByDegrees({ mode: "rational" });
|
|
@@ -10613,13 +10626,23 @@ function evalTrig(name, op) {
|
|
|
10613
10626
|
(x) => x.sinh(),
|
|
10614
10627
|
(x) => x.sinh()
|
|
10615
10628
|
);
|
|
10616
|
-
case "Tan":
|
|
10617
|
-
|
|
10629
|
+
case "Tan": {
|
|
10630
|
+
const result = applyAngle(
|
|
10618
10631
|
op,
|
|
10619
|
-
|
|
10620
|
-
|
|
10632
|
+
(x) => {
|
|
10633
|
+
const y = Math.tan(x);
|
|
10634
|
+
if (y > 1e6 || y < -1e6) return ce.ComplexInfinity;
|
|
10635
|
+
return y;
|
|
10636
|
+
},
|
|
10637
|
+
(x) => {
|
|
10638
|
+
const y = x.tan();
|
|
10639
|
+
if (y.greaterThan(1e6) || y.lessThan(-1e6)) return ce.ComplexInfinity;
|
|
10640
|
+
return y;
|
|
10641
|
+
},
|
|
10621
10642
|
(x) => x.tan()
|
|
10622
10643
|
);
|
|
10644
|
+
return result;
|
|
10645
|
+
}
|
|
10623
10646
|
case "Tanh":
|
|
10624
10647
|
return applyAngle(
|
|
10625
10648
|
op,
|
|
@@ -10853,9 +10876,11 @@ function canonicalRoot(a, b) {
|
|
|
10853
10876
|
if (exp2 === 1) return a;
|
|
10854
10877
|
if (exp2 === 2) {
|
|
10855
10878
|
if (a.isNumberLiteral && isSubtype(a.type, "rational")) {
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10879
|
+
if (a.re < SMALL_INTEGER) {
|
|
10880
|
+
const v = a.sqrt();
|
|
10881
|
+
if (typeof v.numericValue === "number") return v;
|
|
10882
|
+
if (v.numericValue.isExact) return v;
|
|
10883
|
+
}
|
|
10859
10884
|
}
|
|
10860
10885
|
return ce._fn("Sqrt", [a]);
|
|
10861
10886
|
}
|
|
@@ -11623,10 +11648,9 @@ function makeLambda(expr) {
|
|
|
11623
11648
|
ce.resetContext();
|
|
11624
11649
|
let i = 0;
|
|
11625
11650
|
for (const param of params) ce.assign(param, args[i++]);
|
|
11626
|
-
const result = fn.
|
|
11651
|
+
const result = fn.evaluate();
|
|
11627
11652
|
ce.swapScope(context);
|
|
11628
|
-
|
|
11629
|
-
return result;
|
|
11653
|
+
return result.isValid ? result : void 0;
|
|
11630
11654
|
};
|
|
11631
11655
|
}
|
|
11632
11656
|
function apply3(fn, args) {
|
|
@@ -13423,7 +13447,7 @@ var ARITHMETIC_LIBRARY = [
|
|
|
13423
13447
|
const [base, exp2] = args;
|
|
13424
13448
|
return canonicalRoot(base, exp2);
|
|
13425
13449
|
},
|
|
13426
|
-
evaluate: ([x, n], { numericApproximation }) =>
|
|
13450
|
+
evaluate: ([x, n], { numericApproximation }) => root(x, n, { numericApproximation })
|
|
13427
13451
|
},
|
|
13428
13452
|
Round: {
|
|
13429
13453
|
complexity: 1250,
|
|
@@ -17138,6 +17162,7 @@ function parseAt(...close) {
|
|
|
17138
17162
|
rhs ?? (rhs = parser.parseExpression({ minPrec: 0 }));
|
|
17139
17163
|
if (rhs === null) return null;
|
|
17140
17164
|
if (close.length > 0 && !parser.matchAll(close)) return null;
|
|
17165
|
+
if (stringValue(rhs) !== null) return null;
|
|
17141
17166
|
if (operator(rhs) === "Delimiter") rhs = operand(rhs, 1) ?? "Nothing";
|
|
17142
17167
|
if (operator(rhs) === "Sequence") return ["At", lhs, ...operands(rhs)];
|
|
17143
17168
|
return ["At", lhs, rhs];
|
|
@@ -21743,8 +21768,15 @@ var DERIVATIVES_TABLE = {
|
|
|
21743
21768
|
Log: ["Power", ["Multiply", "_", ["Ln", "10"]], -1],
|
|
21744
21769
|
Sqrt: ["Multiply", ["Power", "_", ["Negate", "Half"]], "Half"],
|
|
21745
21770
|
Abs: [
|
|
21746
|
-
"
|
|
21747
|
-
["
|
|
21771
|
+
"Which",
|
|
21772
|
+
["Equal", "_", 0],
|
|
21773
|
+
NaN,
|
|
21774
|
+
["Less", "_", 0],
|
|
21775
|
+
-1,
|
|
21776
|
+
["Greater", "_", 0],
|
|
21777
|
+
1,
|
|
21778
|
+
"True",
|
|
21779
|
+
["D", ["Abs", "_"], "_"]
|
|
21748
21780
|
],
|
|
21749
21781
|
// https://proofwiki.org/wiki/Derivative_of_Error_Function
|
|
21750
21782
|
Erf: [
|
|
@@ -24601,9 +24633,9 @@ var TRIGONOMETRY_LIBRARY = [
|
|
|
24601
24633
|
}
|
|
24602
24634
|
return ce.number(fArg).div(180).mul(ce.Pi);
|
|
24603
24635
|
},
|
|
24604
|
-
evaluate: (ops,
|
|
24605
|
-
if (
|
|
24606
|
-
return ops[0].mul(
|
|
24636
|
+
evaluate: (ops, options) => {
|
|
24637
|
+
if (options.engine.angularUnit === "deg") return ops[0];
|
|
24638
|
+
return ops[0].mul(options.engine.Pi.div(180)).evaluate(options);
|
|
24607
24639
|
}
|
|
24608
24640
|
},
|
|
24609
24641
|
// Hypot: sqrt(x*x + y*y)
|
|
@@ -25417,7 +25449,7 @@ var BoxedNumber = class extends _BoxedExpression {
|
|
|
25417
25449
|
if (typeof this._value === "number") {
|
|
25418
25450
|
if (this._value === 0 || this._value === 1) return this;
|
|
25419
25451
|
if (this._value === -1) return this.engine.I;
|
|
25420
|
-
if (this._value > 0 && Number.isInteger(this._value))
|
|
25452
|
+
if (this._value > 0 && Number.isInteger(this._value) && this._value < SMALL_INTEGER)
|
|
25421
25453
|
return this.engine.number(
|
|
25422
25454
|
this.engine._numericValue({ radical: this._value })
|
|
25423
25455
|
);
|
|
@@ -27272,7 +27304,7 @@ function parseBigOp(name, prec) {
|
|
|
27272
27304
|
}
|
|
27273
27305
|
function serializeBigOp(command) {
|
|
27274
27306
|
return (serializer, expr) => {
|
|
27275
|
-
if (operand(expr, 1)
|
|
27307
|
+
if (!operand(expr, 1)) return command;
|
|
27276
27308
|
let arg = operand(expr, 2);
|
|
27277
27309
|
const h = operator(arg);
|
|
27278
27310
|
if (h !== "Tuple" && h !== "Triple" && h !== "Pair" && h !== "Single")
|
|
@@ -29093,7 +29125,7 @@ function parseIntegralBodyExpression(expr) {
|
|
|
29093
29125
|
}
|
|
29094
29126
|
function serializeIntegral(command) {
|
|
29095
29127
|
return (serializer, expr) => {
|
|
29096
|
-
if (operand(expr, 1)
|
|
29128
|
+
if (!operand(expr, 1)) return command;
|
|
29097
29129
|
let arg = operand(expr, 2);
|
|
29098
29130
|
const h = operator(arg);
|
|
29099
29131
|
let indexExpr = null;
|
|
@@ -32963,7 +32995,7 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
32963
32995
|
}
|
|
32964
32996
|
if ("radical" in value || "rational" in value) {
|
|
32965
32997
|
if (value.radical !== void 0 && (!Number.isInteger(value.radical) || value.radical >= SMALL_INTEGER)) {
|
|
32966
|
-
|
|
32998
|
+
throw Error("Unexpected value for radical part:" + value.radical);
|
|
32967
32999
|
}
|
|
32968
33000
|
if (value.rational) {
|
|
32969
33001
|
if (isMachineRational(value.rational)) {
|
|
@@ -34363,10 +34395,10 @@ function mark(line, mark2) {
|
|
|
34363
34395
|
}
|
|
34364
34396
|
|
|
34365
34397
|
// src/compute-engine.ts
|
|
34366
|
-
var version = "0.26.
|
|
34398
|
+
var version = "0.26.4";
|
|
34367
34399
|
globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
|
|
34368
34400
|
ComputeEngine: ComputeEngine.prototype.constructor,
|
|
34369
|
-
version: "0.26.
|
|
34401
|
+
version: "0.26.4"
|
|
34370
34402
|
};
|
|
34371
34403
|
export {
|
|
34372
34404
|
ComputeEngine,
|
package/dist/compute-engine.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 0.26.
|
|
1
|
+
/** Compute Engine 0.26.4 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngine = {}));})(this, (function (exports) { 'use strict';
|
|
3
3
|
var ComputeEngine = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -9627,7 +9627,10 @@ Invalid type
|
|
|
9627
9627
|
if (next.operator === "Sqrt" && next.op1.isNumberLiteral && isSubtype(next.op1.type, "finite_integer")) {
|
|
9628
9628
|
let radical = next.op1.numericValue;
|
|
9629
9629
|
if (typeof radical !== "number") radical = radical.re;
|
|
9630
|
-
if (radical >= SMALL_INTEGER)
|
|
9630
|
+
if (radical >= SMALL_INTEGER) {
|
|
9631
|
+
ys.push(x);
|
|
9632
|
+
continue;
|
|
9633
|
+
}
|
|
9631
9634
|
if (isSubtype(x.type, "finite_rational")) {
|
|
9632
9635
|
const rational = x.numericValue;
|
|
9633
9636
|
const [num, den] = typeof rational === "number" ? [rational, 1] : [rational.numerator.re, rational.denominator.re];
|
|
@@ -9720,6 +9723,7 @@ Invalid type
|
|
|
9720
9723
|
function canonicalDivide(op1, op2) {
|
|
9721
9724
|
const ce = op1.engine;
|
|
9722
9725
|
if (!op1.isValid || !op2.isValid) return ce._fn("Divide", [op1, op2]);
|
|
9726
|
+
if (op1.isNaN || op2.isNaN) return ce.NaN;
|
|
9723
9727
|
if (op2.is(0)) return op1.is(0) ? ce.NaN : ce.ComplexInfinity;
|
|
9724
9728
|
if (op1.is(0)) return ce.Zero;
|
|
9725
9729
|
if (op2.is(0) === false) {
|
|
@@ -9919,9 +9923,11 @@ Invalid type
|
|
|
9919
9923
|
return;
|
|
9920
9924
|
}
|
|
9921
9925
|
if (term.isInfinity) {
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
|
|
9926
|
+
if (isOne(exp2)) {
|
|
9927
|
+
this.coefficient = this.engine._numericValue(
|
|
9928
|
+
term.isNegative ? -Infinity : Infinity
|
|
9929
|
+
);
|
|
9930
|
+
} else this.terms.push({ term, exponent: exp2 });
|
|
9925
9931
|
return;
|
|
9926
9932
|
}
|
|
9927
9933
|
if (isOne(exp2)) {
|
|
@@ -10076,8 +10082,15 @@ Invalid type
|
|
|
10076
10082
|
const ce = this.engine;
|
|
10077
10083
|
const coef = this.coefficient;
|
|
10078
10084
|
if (coef.isZero) return [ce.Zero, ce.One];
|
|
10079
|
-
if (coef.isPositiveInfinity || coef.isNegativeInfinity)
|
|
10085
|
+
if (coef.isPositiveInfinity || coef.isNegativeInfinity) {
|
|
10086
|
+
if (this.terms.length === 0) {
|
|
10087
|
+
return [
|
|
10088
|
+
coef.isPositiveInfinity ? ce.PositiveInfinity : ce.NegativeInfinity,
|
|
10089
|
+
ce.One
|
|
10090
|
+
];
|
|
10091
|
+
}
|
|
10080
10092
|
return [ce.NaN, ce.NaN];
|
|
10093
|
+
}
|
|
10081
10094
|
const isNegativeOne2 = coef.isNegativeOne;
|
|
10082
10095
|
if (isNegativeOne2) this.coefficient = ce._numericValue(1);
|
|
10083
10096
|
const xs = this.groupedByDegrees({ mode: "rational" });
|
|
@@ -10644,13 +10657,23 @@ Invalid type
|
|
|
10644
10657
|
(x) => x.sinh(),
|
|
10645
10658
|
(x) => x.sinh()
|
|
10646
10659
|
);
|
|
10647
|
-
case "Tan":
|
|
10648
|
-
|
|
10660
|
+
case "Tan": {
|
|
10661
|
+
const result = applyAngle(
|
|
10649
10662
|
op,
|
|
10650
|
-
|
|
10651
|
-
|
|
10663
|
+
(x) => {
|
|
10664
|
+
const y = Math.tan(x);
|
|
10665
|
+
if (y > 1e6 || y < -1e6) return ce.ComplexInfinity;
|
|
10666
|
+
return y;
|
|
10667
|
+
},
|
|
10668
|
+
(x) => {
|
|
10669
|
+
const y = x.tan();
|
|
10670
|
+
if (y.greaterThan(1e6) || y.lessThan(-1e6)) return ce.ComplexInfinity;
|
|
10671
|
+
return y;
|
|
10672
|
+
},
|
|
10652
10673
|
(x) => x.tan()
|
|
10653
10674
|
);
|
|
10675
|
+
return result;
|
|
10676
|
+
}
|
|
10654
10677
|
case "Tanh":
|
|
10655
10678
|
return applyAngle(
|
|
10656
10679
|
op,
|
|
@@ -10884,9 +10907,11 @@ Invalid type
|
|
|
10884
10907
|
if (exp2 === 1) return a;
|
|
10885
10908
|
if (exp2 === 2) {
|
|
10886
10909
|
if (a.isNumberLiteral && isSubtype(a.type, "rational")) {
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10910
|
+
if (a.re < SMALL_INTEGER) {
|
|
10911
|
+
const v = a.sqrt();
|
|
10912
|
+
if (typeof v.numericValue === "number") return v;
|
|
10913
|
+
if (v.numericValue.isExact) return v;
|
|
10914
|
+
}
|
|
10890
10915
|
}
|
|
10891
10916
|
return ce._fn("Sqrt", [a]);
|
|
10892
10917
|
}
|
|
@@ -11654,10 +11679,9 @@ Invalid type
|
|
|
11654
11679
|
ce.resetContext();
|
|
11655
11680
|
let i = 0;
|
|
11656
11681
|
for (const param of params) ce.assign(param, args[i++]);
|
|
11657
|
-
const result = fn.
|
|
11682
|
+
const result = fn.evaluate();
|
|
11658
11683
|
ce.swapScope(context);
|
|
11659
|
-
|
|
11660
|
-
return result;
|
|
11684
|
+
return result.isValid ? result : void 0;
|
|
11661
11685
|
};
|
|
11662
11686
|
}
|
|
11663
11687
|
function apply3(fn, args) {
|
|
@@ -13454,7 +13478,7 @@ Invalid type
|
|
|
13454
13478
|
const [base, exp2] = args;
|
|
13455
13479
|
return canonicalRoot(base, exp2);
|
|
13456
13480
|
},
|
|
13457
|
-
evaluate: ([x, n], { numericApproximation }) =>
|
|
13481
|
+
evaluate: ([x, n], { numericApproximation }) => root(x, n, { numericApproximation })
|
|
13458
13482
|
},
|
|
13459
13483
|
Round: {
|
|
13460
13484
|
complexity: 1250,
|
|
@@ -17169,6 +17193,7 @@ ${e.message}`);
|
|
|
17169
17193
|
rhs ?? (rhs = parser.parseExpression({ minPrec: 0 }));
|
|
17170
17194
|
if (rhs === null) return null;
|
|
17171
17195
|
if (close.length > 0 && !parser.matchAll(close)) return null;
|
|
17196
|
+
if (stringValue(rhs) !== null) return null;
|
|
17172
17197
|
if (operator(rhs) === "Delimiter") rhs = operand(rhs, 1) ?? "Nothing";
|
|
17173
17198
|
if (operator(rhs) === "Sequence") return ["At", lhs, ...operands(rhs)];
|
|
17174
17199
|
return ["At", lhs, rhs];
|
|
@@ -21774,8 +21799,15 @@ ${e.message}`);
|
|
|
21774
21799
|
Log: ["Power", ["Multiply", "_", ["Ln", "10"]], -1],
|
|
21775
21800
|
Sqrt: ["Multiply", ["Power", "_", ["Negate", "Half"]], "Half"],
|
|
21776
21801
|
Abs: [
|
|
21777
|
-
"
|
|
21778
|
-
["
|
|
21802
|
+
"Which",
|
|
21803
|
+
["Equal", "_", 0],
|
|
21804
|
+
NaN,
|
|
21805
|
+
["Less", "_", 0],
|
|
21806
|
+
-1,
|
|
21807
|
+
["Greater", "_", 0],
|
|
21808
|
+
1,
|
|
21809
|
+
"True",
|
|
21810
|
+
["D", ["Abs", "_"], "_"]
|
|
21779
21811
|
],
|
|
21780
21812
|
// https://proofwiki.org/wiki/Derivative_of_Error_Function
|
|
21781
21813
|
Erf: [
|
|
@@ -24632,9 +24664,9 @@ ${e.message}`);
|
|
|
24632
24664
|
}
|
|
24633
24665
|
return ce.number(fArg).div(180).mul(ce.Pi);
|
|
24634
24666
|
},
|
|
24635
|
-
evaluate: (ops,
|
|
24636
|
-
if (
|
|
24637
|
-
return ops[0].mul(
|
|
24667
|
+
evaluate: (ops, options) => {
|
|
24668
|
+
if (options.engine.angularUnit === "deg") return ops[0];
|
|
24669
|
+
return ops[0].mul(options.engine.Pi.div(180)).evaluate(options);
|
|
24638
24670
|
}
|
|
24639
24671
|
},
|
|
24640
24672
|
// Hypot: sqrt(x*x + y*y)
|
|
@@ -25448,7 +25480,7 @@ Error in definition of "${name}"`,
|
|
|
25448
25480
|
if (typeof this._value === "number") {
|
|
25449
25481
|
if (this._value === 0 || this._value === 1) return this;
|
|
25450
25482
|
if (this._value === -1) return this.engine.I;
|
|
25451
|
-
if (this._value > 0 && Number.isInteger(this._value))
|
|
25483
|
+
if (this._value > 0 && Number.isInteger(this._value) && this._value < SMALL_INTEGER)
|
|
25452
25484
|
return this.engine.number(
|
|
25453
25485
|
this.engine._numericValue({ radical: this._value })
|
|
25454
25486
|
);
|
|
@@ -27303,7 +27335,7 @@ Error in definition of "${name}"`,
|
|
|
27303
27335
|
}
|
|
27304
27336
|
function serializeBigOp(command) {
|
|
27305
27337
|
return (serializer, expr) => {
|
|
27306
|
-
if (operand(expr, 1)
|
|
27338
|
+
if (!operand(expr, 1)) return command;
|
|
27307
27339
|
let arg = operand(expr, 2);
|
|
27308
27340
|
const h = operator(arg);
|
|
27309
27341
|
if (h !== "Tuple" && h !== "Triple" && h !== "Pair" && h !== "Single")
|
|
@@ -29124,7 +29156,7 @@ Error in definition of "${name}"`,
|
|
|
29124
29156
|
}
|
|
29125
29157
|
function serializeIntegral(command) {
|
|
29126
29158
|
return (serializer, expr) => {
|
|
29127
|
-
if (operand(expr, 1)
|
|
29159
|
+
if (!operand(expr, 1)) return command;
|
|
29128
29160
|
let arg = operand(expr, 2);
|
|
29129
29161
|
const h = operator(arg);
|
|
29130
29162
|
let indexExpr = null;
|
|
@@ -32994,7 +33026,7 @@ Error in definition of "${name}"`,
|
|
|
32994
33026
|
}
|
|
32995
33027
|
if ("radical" in value || "rational" in value) {
|
|
32996
33028
|
if (value.radical !== void 0 && (!Number.isInteger(value.radical) || value.radical >= SMALL_INTEGER)) {
|
|
32997
|
-
|
|
33029
|
+
throw Error("Unexpected value for radical part:" + value.radical);
|
|
32998
33030
|
}
|
|
32999
33031
|
if (value.rational) {
|
|
33000
33032
|
if (isMachineRational(value.rational)) {
|
|
@@ -34394,10 +34426,10 @@ ${lineNo.toString().padStart(maxDigits, " ")}`;
|
|
|
34394
34426
|
}
|
|
34395
34427
|
|
|
34396
34428
|
// src/compute-engine.ts
|
|
34397
|
-
var version = "0.26.
|
|
34429
|
+
var version = "0.26.4";
|
|
34398
34430
|
globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
|
|
34399
34431
|
ComputeEngine: ComputeEngine.prototype.constructor,
|
|
34400
|
-
version: "0.26.
|
|
34432
|
+
version: "0.26.4"
|
|
34401
34433
|
};
|
|
34402
34434
|
return __toCommonJS(compute_engine_exports);
|
|
34403
34435
|
})();
|