@cortex-js/compute-engine 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compute-engine.esm.js +496 -152
- package/dist/compute-engine.js +496 -152
- package/dist/compute-engine.min.esm.js +11 -8
- package/dist/compute-engine.min.js +11 -8
- 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/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.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/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-domain.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/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.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/compile.d.ts +8 -4
- 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/domain-utils.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-inequalities.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-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/latex-syntax.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 +15 -6
- 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-add.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-power.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/domains.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/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 +12 -2
- 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 +80 -0
- package/dist/types/compute-engine/public.d.ts +1 -1
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.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 +10 -3
package/dist/compute-engine.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** CortexJS Compute Engine 0.
|
|
1
|
+
/** CortexJS Compute Engine 0.18.1 */
|
|
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 __create = Object.create;
|
|
@@ -1093,7 +1093,7 @@ var ComputeEngine = (() => {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
|
|
1095
1095
|
// src/compute-engine/compute-engine.ts
|
|
1096
|
-
var import_complex20 = __toESM(require_complex()
|
|
1096
|
+
var import_complex20 = __toESM(require_complex());
|
|
1097
1097
|
|
|
1098
1098
|
// node_modules/decimal.js/decimal.mjs
|
|
1099
1099
|
var EXP_LIMIT = 9e15;
|
|
@@ -4889,8 +4889,41 @@ var ComputeEngine = (() => {
|
|
|
4889
4889
|
identifierTrigger: "lcm",
|
|
4890
4890
|
kind: "function"
|
|
4891
4891
|
},
|
|
4892
|
-
{
|
|
4893
|
-
{
|
|
4892
|
+
{ identifierTrigger: "max", kind: "function", parse: "Max" },
|
|
4893
|
+
{ identifierTrigger: "min", kind: "function", parse: "Min" },
|
|
4894
|
+
{ name: "Max", latexTrigger: "\\max", kind: "function" },
|
|
4895
|
+
{ name: "Min", latexTrigger: "\\min", kind: "function" },
|
|
4896
|
+
{ name: "Supremum", latexTrigger: "\\sup", kind: "function" },
|
|
4897
|
+
{ name: "Infimum", latexTrigger: "\\inf", kind: "function" },
|
|
4898
|
+
{
|
|
4899
|
+
name: "Limit",
|
|
4900
|
+
latexTrigger: "\\lim",
|
|
4901
|
+
kind: "expression",
|
|
4902
|
+
parse: (parser) => {
|
|
4903
|
+
if (!parser.match("_"))
|
|
4904
|
+
return void 0;
|
|
4905
|
+
const base = parser.parseGroup();
|
|
4906
|
+
if (head(base) !== "To")
|
|
4907
|
+
return void 0;
|
|
4908
|
+
const expr = parser.parseArguments("implicit");
|
|
4909
|
+
if (!expr)
|
|
4910
|
+
return void 0;
|
|
4911
|
+
return ["Limit", ["Function", expr[0], op(base, 1)], op(base, 2)];
|
|
4912
|
+
},
|
|
4913
|
+
serialize: (serializer, expr) => {
|
|
4914
|
+
const fn = op(expr, 1);
|
|
4915
|
+
const fnVar = op(fn, 2);
|
|
4916
|
+
const to = op(expr, 2);
|
|
4917
|
+
return joinLatex([
|
|
4918
|
+
"\\lim_{",
|
|
4919
|
+
serializer.serialize(fnVar),
|
|
4920
|
+
"\\to",
|
|
4921
|
+
serializer.serialize(to),
|
|
4922
|
+
"}",
|
|
4923
|
+
serializer.serialize(op(fn, 1))
|
|
4924
|
+
]);
|
|
4925
|
+
}
|
|
4926
|
+
},
|
|
4894
4927
|
{
|
|
4895
4928
|
name: "MinusPlus",
|
|
4896
4929
|
latexTrigger: ["\\mp"],
|
|
@@ -5328,13 +5361,14 @@ var ComputeEngine = (() => {
|
|
|
5328
5361
|
},
|
|
5329
5362
|
{
|
|
5330
5363
|
name: "Assign",
|
|
5331
|
-
kind: "function",
|
|
5332
5364
|
latexTrigger: "\\coloneqq",
|
|
5365
|
+
kind: "infix",
|
|
5366
|
+
associativity: "right",
|
|
5333
5367
|
precedence: 260,
|
|
5334
|
-
parse: (parser, lhs) => {
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
},
|
|
5368
|
+
// parse: (parser: Parser, lhs: Expression) => {
|
|
5369
|
+
// const rhs = parser.parseExpression({ minPrec: 260 }) ?? 'Nothing';
|
|
5370
|
+
// return ['Assign', lhs, rhs];
|
|
5371
|
+
// },
|
|
5338
5372
|
serialize: (serializer, expr) => {
|
|
5339
5373
|
return joinLatex([
|
|
5340
5374
|
serializer.serialize(op(expr, 1)),
|
|
@@ -5344,22 +5378,31 @@ var ComputeEngine = (() => {
|
|
|
5344
5378
|
}
|
|
5345
5379
|
},
|
|
5346
5380
|
{
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
return ["Assign", lhs, rhs];
|
|
5353
|
-
}
|
|
5381
|
+
latexTrigger: [":", "="],
|
|
5382
|
+
kind: "infix",
|
|
5383
|
+
associativity: "right",
|
|
5384
|
+
precedence: 260,
|
|
5385
|
+
parse: "Assign"
|
|
5354
5386
|
},
|
|
5387
|
+
// {
|
|
5388
|
+
// kind: 'function',
|
|
5389
|
+
// latexTrigger: ':=', // \coloneqq
|
|
5390
|
+
// parse: (parser: Parser, lhs: Expression) => {
|
|
5391
|
+
// const rhs = parser.parseExpression({ minPrec: 270 }) ?? 'Nothing';
|
|
5392
|
+
// return ['Assign', lhs, rhs];
|
|
5393
|
+
// },
|
|
5394
|
+
// },
|
|
5355
5395
|
{
|
|
5356
|
-
kind: "function",
|
|
5357
5396
|
latexTrigger: "\\colonequals",
|
|
5358
5397
|
// \coloneqq
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5398
|
+
kind: "infix",
|
|
5399
|
+
associativity: "right",
|
|
5400
|
+
precedence: 260,
|
|
5401
|
+
parse: "Assign"
|
|
5402
|
+
// parse: (parser: Parser, lhs: Expression) => {
|
|
5403
|
+
// const rhs = parser.parseExpression({ minPrec: 270 }) ?? 'Nothing';
|
|
5404
|
+
// return ['Assign', lhs, rhs];
|
|
5405
|
+
// },
|
|
5363
5406
|
},
|
|
5364
5407
|
{
|
|
5365
5408
|
name: "BaseForm",
|
|
@@ -6104,13 +6147,6 @@ var ComputeEngine = (() => {
|
|
|
6104
6147
|
associativity: "right",
|
|
6105
6148
|
precedence: 260
|
|
6106
6149
|
},
|
|
6107
|
-
{
|
|
6108
|
-
latexTrigger: [":", "="],
|
|
6109
|
-
kind: "infix",
|
|
6110
|
-
associativity: "right",
|
|
6111
|
-
precedence: 260,
|
|
6112
|
-
parse: "Assign"
|
|
6113
|
-
},
|
|
6114
6150
|
{
|
|
6115
6151
|
name: "Approx",
|
|
6116
6152
|
// Note: Mathematica TildeTilde
|
|
@@ -8702,7 +8738,7 @@ var ComputeEngine = (() => {
|
|
|
8702
8738
|
applyInvisibleOperator: "auto",
|
|
8703
8739
|
skipSpace: true,
|
|
8704
8740
|
parseArgumentsOfUnknownLatexCommands: true,
|
|
8705
|
-
parseNumbers:
|
|
8741
|
+
parseNumbers: "auto",
|
|
8706
8742
|
parseUnknownIdentifier: (id, parser) => parser.computeEngine?.lookupFunction(id) !== void 0 ? "function" : "symbol",
|
|
8707
8743
|
preserveLatex: false
|
|
8708
8744
|
};
|
|
@@ -9312,27 +9348,27 @@ var ComputeEngine = (() => {
|
|
|
9312
9348
|
if (this.matchAny(["e", "E"])) {
|
|
9313
9349
|
const exponent = this.parseSignedInteger({ withGrouping: false });
|
|
9314
9350
|
if (exponent)
|
|
9315
|
-
return
|
|
9351
|
+
return exponent;
|
|
9316
9352
|
}
|
|
9317
9353
|
this.index = start;
|
|
9318
9354
|
if (this.match("\\times")) {
|
|
9319
9355
|
this.skipSpaceTokens();
|
|
9320
9356
|
if (this.match("1") && this.match("0") && this.match("^")) {
|
|
9321
9357
|
if (/^[0-9]$/.test(this.peek))
|
|
9322
|
-
return
|
|
9358
|
+
return this.nextToken();
|
|
9323
9359
|
if (this.match("<{>")) {
|
|
9324
9360
|
this.skipSpaceTokens();
|
|
9325
9361
|
const exponent = this.parseSignedInteger();
|
|
9326
9362
|
this.skipSpaceTokens();
|
|
9327
9363
|
if (this.match("<}>") && exponent)
|
|
9328
|
-
return
|
|
9364
|
+
return exponent;
|
|
9329
9365
|
}
|
|
9330
9366
|
}
|
|
9331
9367
|
}
|
|
9332
9368
|
this.index = start;
|
|
9333
9369
|
this.skipSpaceTokens();
|
|
9334
9370
|
if (this.match("\\%"))
|
|
9335
|
-
return
|
|
9371
|
+
return `-2`;
|
|
9336
9372
|
this.index = start;
|
|
9337
9373
|
if (this.matchAll(this._exponentProductTokens)) {
|
|
9338
9374
|
this.skipSpaceTokens();
|
|
@@ -9341,7 +9377,7 @@ var ComputeEngine = (() => {
|
|
|
9341
9377
|
const exponent = this.parseSignedInteger();
|
|
9342
9378
|
this.skipSpaceTokens();
|
|
9343
9379
|
if (this.matchAll(this._endExponentMarkerTokens) && exponent)
|
|
9344
|
-
return
|
|
9380
|
+
return exponent;
|
|
9345
9381
|
}
|
|
9346
9382
|
}
|
|
9347
9383
|
this.index = start;
|
|
@@ -9389,43 +9425,65 @@ var ComputeEngine = (() => {
|
|
|
9389
9425
|
* repeating decimals, etc...
|
|
9390
9426
|
*/
|
|
9391
9427
|
parseNumber() {
|
|
9392
|
-
if (
|
|
9428
|
+
if (this.options.parseNumbers === false || this.options.parseNumbers === "never")
|
|
9393
9429
|
return null;
|
|
9394
9430
|
const start = this.index;
|
|
9395
9431
|
this.skipVisualSpace();
|
|
9396
9432
|
this.match("+");
|
|
9397
|
-
let
|
|
9398
|
-
let
|
|
9433
|
+
let wholePart = "";
|
|
9434
|
+
let fractionalPart = "";
|
|
9435
|
+
let startsWithDecimalMarker = false;
|
|
9399
9436
|
if (this.match(".") || this.matchAll(this._decimalMarkerTokens)) {
|
|
9400
9437
|
const peek = this.peek;
|
|
9401
|
-
if (peek
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
}
|
|
9405
|
-
dotPrefix = true;
|
|
9406
|
-
} else {
|
|
9407
|
-
result = this.parseDecimalDigits({ withGrouping: true });
|
|
9408
|
-
if (!result) {
|
|
9409
|
-
this.index = start;
|
|
9410
|
-
return null;
|
|
9438
|
+
if (peek === "\\overline" || peek === this._beginRepeatingDigitsTokens[0] || /[0-9\(]/.test(peek)) {
|
|
9439
|
+
startsWithDecimalMarker = true;
|
|
9440
|
+
wholePart = "0";
|
|
9411
9441
|
}
|
|
9442
|
+
} else
|
|
9443
|
+
wholePart = this.parseDecimalDigits({ withGrouping: true });
|
|
9444
|
+
if (!wholePart) {
|
|
9445
|
+
this.index = start;
|
|
9446
|
+
return null;
|
|
9412
9447
|
}
|
|
9413
|
-
let
|
|
9414
|
-
if (
|
|
9415
|
-
|
|
9416
|
-
else if (dotPrefix)
|
|
9417
|
-
result = "0." + this.parseDecimalDigits({ withGrouping: true });
|
|
9448
|
+
let hasFractionalPart = true;
|
|
9449
|
+
if (startsWithDecimalMarker || this.match(".") || this.matchAll(this._decimalMarkerTokens))
|
|
9450
|
+
fractionalPart = this.parseDecimalDigits({ withGrouping: true });
|
|
9418
9451
|
else
|
|
9419
|
-
|
|
9420
|
-
|
|
9452
|
+
hasFractionalPart = false;
|
|
9453
|
+
let hasRepeatingPart = false;
|
|
9454
|
+
if (hasFractionalPart) {
|
|
9421
9455
|
const repeat = this.parseRepeatingDecimal();
|
|
9422
|
-
if (repeat)
|
|
9423
|
-
|
|
9424
|
-
|
|
9456
|
+
if (repeat) {
|
|
9457
|
+
fractionalPart += repeat;
|
|
9458
|
+
hasRepeatingPart = true;
|
|
9459
|
+
} else if (this.match("\\ldots") || this.matchAll(this._truncationMarkerTokens)) {
|
|
9425
9460
|
}
|
|
9426
9461
|
}
|
|
9427
9462
|
this.skipVisualSpace();
|
|
9428
|
-
|
|
9463
|
+
const exponent = this.parseExponent();
|
|
9464
|
+
if (!hasRepeatingPart && this.options.parseNumbers === "rational") {
|
|
9465
|
+
const whole = parseInt(wholePart, 10);
|
|
9466
|
+
if (!fractionalPart) {
|
|
9467
|
+
if (exponent)
|
|
9468
|
+
return ["Multiply", whole, ["Power", 10, exponent]];
|
|
9469
|
+
return whole;
|
|
9470
|
+
}
|
|
9471
|
+
const fraction = parseInt(fractionalPart, 10);
|
|
9472
|
+
const n = fractionalPart.length;
|
|
9473
|
+
const numerator = whole * Math.pow(10, n) + fraction;
|
|
9474
|
+
const denominator = Math.pow(10, n);
|
|
9475
|
+
if (exponent) {
|
|
9476
|
+
return [
|
|
9477
|
+
"Multiply",
|
|
9478
|
+
["Rational", numerator, denominator],
|
|
9479
|
+
["Power", 10, exponent]
|
|
9480
|
+
];
|
|
9481
|
+
}
|
|
9482
|
+
return ["Rational", numerator, denominator];
|
|
9483
|
+
}
|
|
9484
|
+
return {
|
|
9485
|
+
num: wholePart + (hasFractionalPart ? "." + fractionalPart : "") + (exponent ? "e" + exponent : "")
|
|
9486
|
+
};
|
|
9429
9487
|
}
|
|
9430
9488
|
/**
|
|
9431
9489
|
* A Latex number can be a decimal, hex or octal number.
|
|
@@ -9873,18 +9931,24 @@ var ComputeEngine = (() => {
|
|
|
9873
9931
|
(x) => x.latexTrigger === "^"
|
|
9874
9932
|
);
|
|
9875
9933
|
if (defs) {
|
|
9876
|
-
|
|
9877
|
-
"
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
result
|
|
9884
|
-
|
|
9885
|
-
|
|
9886
|
-
|
|
9887
|
-
|
|
9934
|
+
let nonEmptySuperscripts = superscripts.filter(
|
|
9935
|
+
(x) => head(x) !== "Sequence"
|
|
9936
|
+
);
|
|
9937
|
+
if (nonEmptySuperscripts.length !== 0) {
|
|
9938
|
+
const superscriptExpression = nonEmptySuperscripts.length === 1 ? nonEmptySuperscripts[0] : ["List", ...nonEmptySuperscripts];
|
|
9939
|
+
const arg = [
|
|
9940
|
+
"Superscript",
|
|
9941
|
+
result,
|
|
9942
|
+
superscriptExpression
|
|
9943
|
+
];
|
|
9944
|
+
for (const def of defs) {
|
|
9945
|
+
if (typeof def.parse === "function")
|
|
9946
|
+
result = def.parse(this, arg, { minPrec: 0 });
|
|
9947
|
+
else
|
|
9948
|
+
result = arg;
|
|
9949
|
+
if (result)
|
|
9950
|
+
break;
|
|
9951
|
+
}
|
|
9888
9952
|
}
|
|
9889
9953
|
}
|
|
9890
9954
|
}
|
|
@@ -10051,8 +10115,11 @@ var ComputeEngine = (() => {
|
|
|
10051
10115
|
const [def, n] = opDefs[0];
|
|
10052
10116
|
if (this.peek === "^") {
|
|
10053
10117
|
this.index += 1;
|
|
10054
|
-
|
|
10055
|
-
|
|
10118
|
+
return [
|
|
10119
|
+
"Superscript",
|
|
10120
|
+
this.error("missing", start),
|
|
10121
|
+
missingIfEmpty(this.parseGroup())
|
|
10122
|
+
];
|
|
10056
10123
|
}
|
|
10057
10124
|
this.index += n;
|
|
10058
10125
|
if (typeof def.parse === "function") {
|
|
@@ -10159,11 +10226,7 @@ var ComputeEngine = (() => {
|
|
|
10159
10226
|
);
|
|
10160
10227
|
}
|
|
10161
10228
|
}
|
|
10162
|
-
|
|
10163
|
-
const num = this.parseNumber();
|
|
10164
|
-
if (num !== null)
|
|
10165
|
-
result = { num };
|
|
10166
|
-
}
|
|
10229
|
+
result ?? (result = this.parseNumber());
|
|
10167
10230
|
result ?? (result = this.parseEnclosure());
|
|
10168
10231
|
result ?? (result = this.parseEnvironment(until));
|
|
10169
10232
|
if (result === null && this.matchAll(this._positiveInfinityTokens))
|
|
@@ -11091,10 +11154,65 @@ var ComputeEngine = (() => {
|
|
|
11091
11154
|
};
|
|
11092
11155
|
|
|
11093
11156
|
// src/compute-engine/boxed-expression/utils.ts
|
|
11094
|
-
var import_complex2 = __toESM(require_complex()
|
|
11157
|
+
var import_complex2 = __toESM(require_complex());
|
|
11158
|
+
|
|
11159
|
+
// src/compute-engine/numerics/numeric.ts
|
|
11160
|
+
var import_complex = __toESM(require_complex());
|
|
11161
|
+
|
|
11162
|
+
// src/compute-engine/numerics/richardson.ts
|
|
11163
|
+
function extrapolate(f, x0, options = {}) {
|
|
11164
|
+
const {
|
|
11165
|
+
contract = 0.125,
|
|
11166
|
+
step = 1,
|
|
11167
|
+
power = 2,
|
|
11168
|
+
atol = 1e-16,
|
|
11169
|
+
rtol = atol > 0 ? 0 : Math.sqrt(Number.EPSILON),
|
|
11170
|
+
maxeval = 1e6,
|
|
11171
|
+
// Number.MAX_SAFE_INTEGER
|
|
11172
|
+
breaktol = 2
|
|
11173
|
+
} = options;
|
|
11174
|
+
if (!isFinite(x0)) {
|
|
11175
|
+
return extrapolate((u) => f(1 / u), 1 / x0, {
|
|
11176
|
+
rtol,
|
|
11177
|
+
atol,
|
|
11178
|
+
maxeval,
|
|
11179
|
+
contract: Math.abs(contract) > 1 ? 1 / contract : contract,
|
|
11180
|
+
step: 1 / step,
|
|
11181
|
+
power
|
|
11182
|
+
});
|
|
11183
|
+
}
|
|
11184
|
+
let h = step;
|
|
11185
|
+
let invcontract = Math.pow(1 / contract, power);
|
|
11186
|
+
let f0 = f(x0 + h);
|
|
11187
|
+
let neville = [f0];
|
|
11188
|
+
let err = Infinity;
|
|
11189
|
+
let numeval = 1;
|
|
11190
|
+
while (numeval < maxeval) {
|
|
11191
|
+
numeval += 1;
|
|
11192
|
+
h *= contract;
|
|
11193
|
+
neville.push(f(x0 + h));
|
|
11194
|
+
let c = invcontract;
|
|
11195
|
+
let minerr = Infinity;
|
|
11196
|
+
for (let i = neville.length - 2; i >= 0; i--) {
|
|
11197
|
+
const old = neville[i];
|
|
11198
|
+
neville[i] = neville[i + 1] + (neville[i + 1] - neville[i]) / (c - 1);
|
|
11199
|
+
const err_ = Math.abs(neville[i] - old);
|
|
11200
|
+
minerr = Math.min(minerr, err_);
|
|
11201
|
+
if (err_ < err) {
|
|
11202
|
+
f0 = neville[i];
|
|
11203
|
+
err = err_;
|
|
11204
|
+
}
|
|
11205
|
+
c *= invcontract;
|
|
11206
|
+
}
|
|
11207
|
+
if (minerr > breaktol * err || !isFinite(minerr))
|
|
11208
|
+
break;
|
|
11209
|
+
if (err <= Math.max(rtol * Math.abs(f0), atol))
|
|
11210
|
+
break;
|
|
11211
|
+
}
|
|
11212
|
+
return [f0, err];
|
|
11213
|
+
}
|
|
11095
11214
|
|
|
11096
11215
|
// src/compute-engine/numerics/numeric.ts
|
|
11097
|
-
var import_complex = __toESM(require_complex(), 1);
|
|
11098
11216
|
var MACHINE_PRECISION_BITS = 53;
|
|
11099
11217
|
var MACHINE_PRECISION = Math.log10(
|
|
11100
11218
|
Math.pow(2, MACHINE_PRECISION_BITS)
|
|
@@ -12426,10 +12544,10 @@ var ComputeEngine = (() => {
|
|
|
12426
12544
|
const x7 = x5 * x2;
|
|
12427
12545
|
return Math.sqrt(pi) / 2 * (x + pi / 12 * x3 + 7 * pi2 / 480 * x5 + 127 * pi3 / 40320 * x7 + 4369 * pi2 * pi2 / 5806080 * x7 * x2 + 34807 * pi3 * pi2 / 182476800 * x7 * x2 * x2);
|
|
12428
12546
|
}
|
|
12429
|
-
function centeredDiff8thOrder(f, x, h =
|
|
12430
|
-
return (
|
|
12547
|
+
function centeredDiff8thOrder(f, x, h = 0.1) {
|
|
12548
|
+
return (f(x - 4 * h) / 280 - 4 * f(x - 3 * h) / 105 + f(x - 2 * h) / 5 - 4 * f(x - h) / 5 + 4 * f(x + h) / 5 - f(x + 2 * h) / 5 + 4 * f(x + 3 * h) / 105 - f(x + 4 * h) / 280) / h;
|
|
12431
12549
|
}
|
|
12432
|
-
function monteCarloEstimate(f, a, b, n =
|
|
12550
|
+
function monteCarloEstimate(f, a, b, n = 1e5) {
|
|
12433
12551
|
let sum2 = 0;
|
|
12434
12552
|
if (a === -Infinity && b === Infinity) {
|
|
12435
12553
|
for (let i = 0; i < n; i++) {
|
|
@@ -12458,6 +12576,19 @@ var ComputeEngine = (() => {
|
|
|
12458
12576
|
}
|
|
12459
12577
|
return sum2 / n * (b - a);
|
|
12460
12578
|
}
|
|
12579
|
+
function limit(f, x, dir = 1) {
|
|
12580
|
+
if (dir === 0) {
|
|
12581
|
+
const left = limit(f, x, -1);
|
|
12582
|
+
const right = limit(f, x, 1);
|
|
12583
|
+
if (left === void 0 || right === void 0)
|
|
12584
|
+
return NaN;
|
|
12585
|
+
if (Math.abs(left - right) > 1e-5)
|
|
12586
|
+
return NaN;
|
|
12587
|
+
return (left + right) / 2;
|
|
12588
|
+
}
|
|
12589
|
+
const [val, err] = extrapolate(f, x, { step: dir > 0 ? 1 : -1 });
|
|
12590
|
+
return val;
|
|
12591
|
+
}
|
|
12461
12592
|
|
|
12462
12593
|
// src/compute-engine/numerics/numeric-bigint.ts
|
|
12463
12594
|
function bigint(a) {
|
|
@@ -12778,7 +12909,7 @@ var ComputeEngine = (() => {
|
|
|
12778
12909
|
}
|
|
12779
12910
|
|
|
12780
12911
|
// src/compute-engine/boxed-expression/order.ts
|
|
12781
|
-
var import_complex3 = __toESM(require_complex()
|
|
12912
|
+
var import_complex3 = __toESM(require_complex());
|
|
12782
12913
|
|
|
12783
12914
|
// src/compute-engine/symbolic/polynomials.ts
|
|
12784
12915
|
function totalDegree(expr) {
|
|
@@ -12988,7 +13119,7 @@ var ComputeEngine = (() => {
|
|
|
12988
13119
|
}
|
|
12989
13120
|
|
|
12990
13121
|
// src/compute-engine/numerics/rationals.ts
|
|
12991
|
-
var import_complex4 = __toESM(require_complex()
|
|
13122
|
+
var import_complex4 = __toESM(require_complex());
|
|
12992
13123
|
function isRational(x) {
|
|
12993
13124
|
return x !== null && Array.isArray(x);
|
|
12994
13125
|
}
|
|
@@ -13298,7 +13429,7 @@ var ComputeEngine = (() => {
|
|
|
13298
13429
|
}
|
|
13299
13430
|
|
|
13300
13431
|
// src/compute-engine/symbolic/sum.ts
|
|
13301
|
-
var import_complex5 = __toESM(require_complex()
|
|
13432
|
+
var import_complex5 = __toESM(require_complex());
|
|
13302
13433
|
var Sum = class {
|
|
13303
13434
|
constructor(ce, xs, options) {
|
|
13304
13435
|
// If `false`, the running sums are not calculated
|
|
@@ -13734,7 +13865,7 @@ var ComputeEngine = (() => {
|
|
|
13734
13865
|
}
|
|
13735
13866
|
|
|
13736
13867
|
// src/compute-engine/boxed-expression/abstract-boxed-expression.ts
|
|
13737
|
-
var import_complex6 = __toESM(require_complex()
|
|
13868
|
+
var import_complex6 = __toESM(require_complex());
|
|
13738
13869
|
|
|
13739
13870
|
// src/compute-engine/library/utils.ts
|
|
13740
13871
|
function normalizeLimits(range) {
|
|
@@ -13805,6 +13936,7 @@ var ComputeEngine = (() => {
|
|
|
13805
13936
|
Gcd: "_SYS.gcd",
|
|
13806
13937
|
// Math.hypot
|
|
13807
13938
|
Lcm: "_SYS.lcm",
|
|
13939
|
+
Limit: (args, compile2) => `_SYS.limit(${compile2(args[0])}, ${compile2(args[1])})`,
|
|
13808
13940
|
Ln: "Math.log",
|
|
13809
13941
|
Log: "Math.log10",
|
|
13810
13942
|
LogGamma: "_SYS.lngamma",
|
|
@@ -13839,7 +13971,7 @@ var ComputeEngine = (() => {
|
|
|
13839
13971
|
},
|
|
13840
13972
|
Random: "Math.random",
|
|
13841
13973
|
Round: "Math.round",
|
|
13842
|
-
|
|
13974
|
+
Square: (args, compile2) => {
|
|
13843
13975
|
const arg = args[0];
|
|
13844
13976
|
if (arg === null)
|
|
13845
13977
|
throw new Error("Square: no argument");
|
|
@@ -13950,7 +14082,8 @@ var ComputeEngine = (() => {
|
|
|
13950
14082
|
lngamma: gammaln,
|
|
13951
14083
|
gcd,
|
|
13952
14084
|
lcm,
|
|
13953
|
-
chop
|
|
14085
|
+
chop,
|
|
14086
|
+
limit
|
|
13954
14087
|
};
|
|
13955
14088
|
return new Proxy(this, {
|
|
13956
14089
|
apply: (target, thisArg, argumentsList) => super.apply(thisArg, [this.sys, ...argumentsList]),
|
|
@@ -13997,7 +14130,9 @@ ${js}`);
|
|
|
13997
14130
|
return void 0;
|
|
13998
14131
|
},
|
|
13999
14132
|
string: (str) => JSON.stringify(str),
|
|
14000
|
-
number: (n) => n.toString()
|
|
14133
|
+
number: (n) => n.toString(),
|
|
14134
|
+
indent: 0,
|
|
14135
|
+
ws: (s) => s ?? ""
|
|
14001
14136
|
});
|
|
14002
14137
|
}
|
|
14003
14138
|
function compileExpr(h, args, prec, target) {
|
|
@@ -14022,6 +14157,50 @@ ${js}`);
|
|
|
14022
14157
|
}
|
|
14023
14158
|
return op3[1] < prec ? `(${resultStr})` : resultStr;
|
|
14024
14159
|
}
|
|
14160
|
+
if (h === "Function") {
|
|
14161
|
+
const params = args.slice(1).map((x) => x.symbol);
|
|
14162
|
+
return `((${params.join(", ")}) => ${compile(args[0], {
|
|
14163
|
+
...target,
|
|
14164
|
+
var: (id) => params.includes(id) ? id : target.var(id)
|
|
14165
|
+
})})`;
|
|
14166
|
+
}
|
|
14167
|
+
if (h === "Declare")
|
|
14168
|
+
return `let ${args[0].symbol}`;
|
|
14169
|
+
if (h === "Assign")
|
|
14170
|
+
return `${args[0].symbol} = ${compile(args[1], target)}`;
|
|
14171
|
+
if (h === "Return")
|
|
14172
|
+
return `return ${compile(args[0], target)}`;
|
|
14173
|
+
if (h === "If") {
|
|
14174
|
+
if (args.length !== 3)
|
|
14175
|
+
throw new Error("If: wrong number of arguments");
|
|
14176
|
+
return `((${compile(args[0], target)}) ? (${compile(
|
|
14177
|
+
args[1],
|
|
14178
|
+
target
|
|
14179
|
+
)}) : (${compile(args[2], target)}))`;
|
|
14180
|
+
}
|
|
14181
|
+
if (h === "Block") {
|
|
14182
|
+
const locals = [];
|
|
14183
|
+
for (const arg of args) {
|
|
14184
|
+
if (arg.head === "Declare")
|
|
14185
|
+
locals.push(arg.ops[0].symbol);
|
|
14186
|
+
}
|
|
14187
|
+
if (args.length === 1 && locals.length === 0)
|
|
14188
|
+
return compile(args[0], target);
|
|
14189
|
+
const result = args.map(
|
|
14190
|
+
(arg) => compile(arg, {
|
|
14191
|
+
...target,
|
|
14192
|
+
var: (id) => {
|
|
14193
|
+
if (locals.includes(id))
|
|
14194
|
+
return id;
|
|
14195
|
+
return target.var(id);
|
|
14196
|
+
}
|
|
14197
|
+
})
|
|
14198
|
+
);
|
|
14199
|
+
result[result.length - 1] = `return ${result[result.length - 1]}`;
|
|
14200
|
+
return `(() => {${target.ws("\n")}${result.join(
|
|
14201
|
+
`;${target.ws("\n")}`
|
|
14202
|
+
)}${target.ws("\n")}})()`;
|
|
14203
|
+
}
|
|
14025
14204
|
const fn = target.functions?.(h);
|
|
14026
14205
|
if (!fn)
|
|
14027
14206
|
throw new Error(`Unknown function ${h}`);
|
|
@@ -14413,7 +14592,7 @@ ${js}`);
|
|
|
14413
14592
|
compile(to = "javascript", options) {
|
|
14414
14593
|
if (to !== "javascript")
|
|
14415
14594
|
return void 0;
|
|
14416
|
-
options ?? (options = { optimize: ["simplify"
|
|
14595
|
+
options ?? (options = { optimize: ["simplify"] });
|
|
14417
14596
|
let expr = this;
|
|
14418
14597
|
if (options.optimize.includes("simplify"))
|
|
14419
14598
|
expr = expr.simplify();
|
|
@@ -14787,7 +14966,7 @@ ${js}`);
|
|
|
14787
14966
|
}
|
|
14788
14967
|
|
|
14789
14968
|
// src/compute-engine/symbolic/utils.ts
|
|
14790
|
-
var import_complex7 = __toESM(require_complex()
|
|
14969
|
+
var import_complex7 = __toESM(require_complex());
|
|
14791
14970
|
function makePositive(expr) {
|
|
14792
14971
|
if (expr.head === "Negate")
|
|
14793
14972
|
return [-1, expr.op1];
|
|
@@ -15342,7 +15521,7 @@ ${js}`);
|
|
|
15342
15521
|
}
|
|
15343
15522
|
|
|
15344
15523
|
// src/compute-engine/symbolic/negate.ts
|
|
15345
|
-
var import_complex8 = __toESM(require_complex()
|
|
15524
|
+
var import_complex8 = __toESM(require_complex());
|
|
15346
15525
|
function negateLiteral(expr, metadata) {
|
|
15347
15526
|
let n = expr.numericValue;
|
|
15348
15527
|
if (n === null)
|
|
@@ -15874,10 +16053,10 @@ ${js}`);
|
|
|
15874
16053
|
}
|
|
15875
16054
|
|
|
15876
16055
|
// src/compute-engine/boxed-expression/box.ts
|
|
15877
|
-
var import_complex14 = __toESM(require_complex()
|
|
16056
|
+
var import_complex14 = __toESM(require_complex());
|
|
15878
16057
|
|
|
15879
16058
|
// src/compute-engine/boxed-expression/serialize.ts
|
|
15880
|
-
var import_complex10 = __toESM(require_complex()
|
|
16059
|
+
var import_complex10 = __toESM(require_complex());
|
|
15881
16060
|
|
|
15882
16061
|
// src/compute-engine/numerics/numeric-bignum.ts
|
|
15883
16062
|
function factorial3(ce, n) {
|
|
@@ -15993,7 +16172,7 @@ ${js}`);
|
|
|
15993
16172
|
}
|
|
15994
16173
|
|
|
15995
16174
|
// src/compute-engine/symbolic/product.ts
|
|
15996
|
-
var import_complex9 = __toESM(require_complex()
|
|
16175
|
+
var import_complex9 = __toESM(require_complex());
|
|
15997
16176
|
var Product = class {
|
|
15998
16177
|
constructor(ce, xs, options) {
|
|
15999
16178
|
this.options = options;
|
|
@@ -16932,7 +17111,7 @@ ${js}`);
|
|
|
16932
17111
|
};
|
|
16933
17112
|
|
|
16934
17113
|
// src/compute-engine/boxed-expression/boxed-function.ts
|
|
16935
|
-
var import_complex11 = __toESM(require_complex()
|
|
17114
|
+
var import_complex11 = __toESM(require_complex());
|
|
16936
17115
|
|
|
16937
17116
|
// src/compute-engine/simplify-rules.ts
|
|
16938
17117
|
var SIMPLIFY_RULES = [];
|
|
@@ -17625,10 +17804,12 @@ ${js}`);
|
|
|
17625
17804
|
const sig = def?.signature;
|
|
17626
17805
|
if (!result && sig) {
|
|
17627
17806
|
const numericMode = options?.numericMode ?? false;
|
|
17807
|
+
const context = this.engine.swapScope(this.scope);
|
|
17628
17808
|
if (numericMode && sig.N)
|
|
17629
17809
|
result = sig.N(this.engine, tail);
|
|
17630
17810
|
if (!result && sig.evaluate)
|
|
17631
17811
|
result = sig.evaluate(this.engine, tail);
|
|
17812
|
+
this.engine.swapScope(context);
|
|
17632
17813
|
}
|
|
17633
17814
|
if (result) {
|
|
17634
17815
|
const num = result.numericValue;
|
|
@@ -17821,10 +18002,10 @@ ${js}`);
|
|
|
17821
18002
|
}
|
|
17822
18003
|
|
|
17823
18004
|
// src/compute-engine/boxed-expression/boxed-number.ts
|
|
17824
|
-
var import_complex13 = __toESM(require_complex()
|
|
18005
|
+
var import_complex13 = __toESM(require_complex());
|
|
17825
18006
|
|
|
17826
18007
|
// src/compute-engine/domain-utils.ts
|
|
17827
|
-
var import_complex12 = __toESM(require_complex()
|
|
18008
|
+
var import_complex12 = __toESM(require_complex());
|
|
17828
18009
|
function inferNumericDomain(value) {
|
|
17829
18010
|
if (typeof value === "number" && !isNaN(value)) {
|
|
17830
18011
|
if (!isFinite(value))
|
|
@@ -18111,7 +18292,12 @@ ${js}`);
|
|
|
18111
18292
|
return false;
|
|
18112
18293
|
}
|
|
18113
18294
|
isEqual(rhs) {
|
|
18114
|
-
|
|
18295
|
+
if (this === rhs)
|
|
18296
|
+
return true;
|
|
18297
|
+
if (!(rhs instanceof _BoxedNumber))
|
|
18298
|
+
return false;
|
|
18299
|
+
const s = signDiff(this, rhs);
|
|
18300
|
+
return s === 0;
|
|
18115
18301
|
}
|
|
18116
18302
|
match(rhs, options) {
|
|
18117
18303
|
if (this.isEqualWithTolerance(rhs, options?.numericTolerance ?? 0))
|
|
@@ -18766,7 +18952,7 @@ ${js}`);
|
|
|
18766
18952
|
}
|
|
18767
18953
|
|
|
18768
18954
|
// src/compute-engine/library/arithmetic.ts
|
|
18769
|
-
var import_complex16 = __toESM(require_complex()
|
|
18955
|
+
var import_complex16 = __toESM(require_complex());
|
|
18770
18956
|
|
|
18771
18957
|
// src/compute-engine/numerics/numeric-complex.ts
|
|
18772
18958
|
function gamma3(c) {
|
|
@@ -18777,7 +18963,7 @@ ${js}`);
|
|
|
18777
18963
|
}
|
|
18778
18964
|
|
|
18779
18965
|
// src/compute-engine/library/arithmetic-power.ts
|
|
18780
|
-
var import_complex15 = __toESM(require_complex()
|
|
18966
|
+
var import_complex15 = __toESM(require_complex());
|
|
18781
18967
|
function canonicalPower(ce, base, exponent, metadata) {
|
|
18782
18968
|
if (exponent.symbol === "ComplexInfinity")
|
|
18783
18969
|
return ce.NaN;
|
|
@@ -20192,21 +20378,7 @@ ${js}`);
|
|
|
20192
20378
|
return ops2[0];
|
|
20193
20379
|
return ce.fn("Max", ops2);
|
|
20194
20380
|
},
|
|
20195
|
-
evaluate: (ce, ops2) =>
|
|
20196
|
-
if (ops2.length === 0)
|
|
20197
|
-
return ce.NegativeInfinity;
|
|
20198
|
-
let result = void 0;
|
|
20199
|
-
const rest = [];
|
|
20200
|
-
for (const op3 of ops2) {
|
|
20201
|
-
if (!op3.isNumber || op3.numericValue === void 0)
|
|
20202
|
-
rest.push(op3);
|
|
20203
|
-
else if (!result || op3.isGreater(result))
|
|
20204
|
-
result = op3;
|
|
20205
|
-
}
|
|
20206
|
-
if (rest.length > 0)
|
|
20207
|
-
return ce.box(result ? ["Max", result, ...rest] : ["Max", ...rest]);
|
|
20208
|
-
return result ?? ce.NaN;
|
|
20209
|
-
}
|
|
20381
|
+
evaluate: (ce, ops2) => processMinMax(ce, ops2, "Max")
|
|
20210
20382
|
}
|
|
20211
20383
|
},
|
|
20212
20384
|
Min: {
|
|
@@ -20216,26 +20388,42 @@ ${js}`);
|
|
|
20216
20388
|
domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
|
|
20217
20389
|
simplify: (ce, ops2) => {
|
|
20218
20390
|
if (ops2.length === 0)
|
|
20219
|
-
return ce.
|
|
20391
|
+
return ce.PositiveInfinity;
|
|
20220
20392
|
if (ops2.length === 1)
|
|
20221
20393
|
return ops2[0];
|
|
20222
20394
|
return ce.fn("Min", ops2);
|
|
20223
20395
|
},
|
|
20224
|
-
evaluate: (ce, ops2) =>
|
|
20396
|
+
evaluate: (ce, ops2) => processMinMax(ce, ops2, "Min")
|
|
20397
|
+
}
|
|
20398
|
+
},
|
|
20399
|
+
Supremum: {
|
|
20400
|
+
description: "Like Max, but defined for open sets",
|
|
20401
|
+
complexity: 1200,
|
|
20402
|
+
signature: {
|
|
20403
|
+
domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
|
|
20404
|
+
simplify: (ce, ops2) => {
|
|
20225
20405
|
if (ops2.length === 0)
|
|
20226
20406
|
return ce.NegativeInfinity;
|
|
20227
|
-
|
|
20228
|
-
|
|
20229
|
-
|
|
20230
|
-
|
|
20231
|
-
|
|
20232
|
-
|
|
20233
|
-
|
|
20234
|
-
|
|
20235
|
-
|
|
20236
|
-
|
|
20237
|
-
|
|
20238
|
-
|
|
20407
|
+
if (ops2.length === 1)
|
|
20408
|
+
return ops2[0];
|
|
20409
|
+
return ce.fn("Min", ops2);
|
|
20410
|
+
},
|
|
20411
|
+
evaluate: (ce, ops2) => processMinMax(ce, ops2, "Supremum")
|
|
20412
|
+
}
|
|
20413
|
+
},
|
|
20414
|
+
Infimum: {
|
|
20415
|
+
description: "Like Min, but defined for open sets",
|
|
20416
|
+
complexity: 1200,
|
|
20417
|
+
signature: {
|
|
20418
|
+
domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
|
|
20419
|
+
simplify: (ce, ops2) => {
|
|
20420
|
+
if (ops2.length === 0)
|
|
20421
|
+
return ce.PositiveInfinity;
|
|
20422
|
+
if (ops2.length === 1)
|
|
20423
|
+
return ops2[0];
|
|
20424
|
+
return ce.fn("Min", ops2);
|
|
20425
|
+
},
|
|
20426
|
+
evaluate: (ce, ops2) => processMinMax(ce, ops2, "Infimum")
|
|
20239
20427
|
}
|
|
20240
20428
|
},
|
|
20241
20429
|
Product: {
|
|
@@ -20281,6 +20469,69 @@ ${js}`);
|
|
|
20281
20469
|
evaluate: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "evaluate"),
|
|
20282
20470
|
N: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "N")
|
|
20283
20471
|
}
|
|
20472
|
+
},
|
|
20473
|
+
// Limits
|
|
20474
|
+
Limit: {
|
|
20475
|
+
description: "Limit of a function",
|
|
20476
|
+
complexity: 5e3,
|
|
20477
|
+
hold: "all",
|
|
20478
|
+
signature: {
|
|
20479
|
+
domain: [
|
|
20480
|
+
"FunctionOf",
|
|
20481
|
+
"Anything",
|
|
20482
|
+
"Numbers",
|
|
20483
|
+
["OptArg", "Numbers"],
|
|
20484
|
+
"Numbers"
|
|
20485
|
+
],
|
|
20486
|
+
N: (ce, ops2) => {
|
|
20487
|
+
const [f, x, dir] = ops2;
|
|
20488
|
+
const target = asFloat(x.N());
|
|
20489
|
+
if (target === null)
|
|
20490
|
+
return void 0;
|
|
20491
|
+
const fn = applicable(f);
|
|
20492
|
+
return ce.number(
|
|
20493
|
+
limit(
|
|
20494
|
+
(x2) => {
|
|
20495
|
+
let y = fn([ce.number(x2)])?.valueOf();
|
|
20496
|
+
return typeof y === "number" ? y : Number.NaN;
|
|
20497
|
+
},
|
|
20498
|
+
target,
|
|
20499
|
+
dir ? asFloat(dir) ?? 1 : 1
|
|
20500
|
+
)
|
|
20501
|
+
);
|
|
20502
|
+
}
|
|
20503
|
+
}
|
|
20504
|
+
},
|
|
20505
|
+
NLimit: {
|
|
20506
|
+
description: "Numerical approximation of the limit of a function",
|
|
20507
|
+
complexity: 5e3,
|
|
20508
|
+
hold: "all",
|
|
20509
|
+
signature: {
|
|
20510
|
+
domain: [
|
|
20511
|
+
"FunctionOf",
|
|
20512
|
+
"Anything",
|
|
20513
|
+
"Numbers",
|
|
20514
|
+
["OptArg", "Numbers"],
|
|
20515
|
+
"Numbers"
|
|
20516
|
+
],
|
|
20517
|
+
evaluate: (ce, ops2) => {
|
|
20518
|
+
const [f, x, dir] = ops2;
|
|
20519
|
+
const target = asFloat(x.N());
|
|
20520
|
+
if (target === null)
|
|
20521
|
+
return void 0;
|
|
20522
|
+
const fn = applicable(f);
|
|
20523
|
+
return ce.number(
|
|
20524
|
+
limit(
|
|
20525
|
+
(x2) => {
|
|
20526
|
+
let y = fn([ce.number(x2)])?.valueOf();
|
|
20527
|
+
return typeof y === "number" ? y : Number.NaN;
|
|
20528
|
+
},
|
|
20529
|
+
target,
|
|
20530
|
+
dir ? asFloat(dir) ?? 1 : 1
|
|
20531
|
+
)
|
|
20532
|
+
);
|
|
20533
|
+
}
|
|
20534
|
+
}
|
|
20284
20535
|
}
|
|
20285
20536
|
},
|
|
20286
20537
|
//
|
|
@@ -20387,6 +20638,24 @@ ${js}`);
|
|
|
20387
20638
|
return ce.neg(arg);
|
|
20388
20639
|
return void 0;
|
|
20389
20640
|
}
|
|
20641
|
+
function processMinMax(ce, ops2, mode) {
|
|
20642
|
+
const upper = mode === "Max" || mode === "Supremum";
|
|
20643
|
+
if (ops2.length === 0)
|
|
20644
|
+
return upper ? ce.NegativeInfinity : ce.PositiveInfinity;
|
|
20645
|
+
let result = void 0;
|
|
20646
|
+
const rest = [];
|
|
20647
|
+
for (const op3 of ops2) {
|
|
20648
|
+
if (!op3.isNumber || op3.numericValue === void 0)
|
|
20649
|
+
rest.push(op3);
|
|
20650
|
+
else if (!result)
|
|
20651
|
+
result = op3;
|
|
20652
|
+
else if (upper && op3.isGreater(result) || !upper && op3.isLess(result))
|
|
20653
|
+
result = op3;
|
|
20654
|
+
}
|
|
20655
|
+
if (rest.length > 0)
|
|
20656
|
+
return ce.box(result ? [mode, result, ...rest] : [mode, ...rest]);
|
|
20657
|
+
return result ?? (upper ? ce.NegativeInfinity : ce.PositiveInfinity);
|
|
20658
|
+
}
|
|
20390
20659
|
|
|
20391
20660
|
// src/compute-engine/symbolic/derivative.ts
|
|
20392
20661
|
var DERIVATIVES_TABLE = {
|
|
@@ -20711,8 +20980,9 @@ ${js}`);
|
|
|
20711
20980
|
const params = ops2.slice(1);
|
|
20712
20981
|
f.bind();
|
|
20713
20982
|
f = f.canonical;
|
|
20983
|
+
const result = ce._fn("D", [f, ...params]);
|
|
20714
20984
|
ce.popScope();
|
|
20715
|
-
return
|
|
20985
|
+
return result;
|
|
20716
20986
|
},
|
|
20717
20987
|
evaluate: (ce, ops2) => {
|
|
20718
20988
|
let f = ops2[0].canonical;
|
|
@@ -20746,7 +21016,7 @@ ${js}`);
|
|
|
20746
21016
|
if (typeof x !== "number")
|
|
20747
21017
|
return void 0;
|
|
20748
21018
|
const f = applicableN1(ce.box(ops2[0]));
|
|
20749
|
-
return ce.number(centeredDiff8thOrder(f, x
|
|
21019
|
+
return ce.number(centeredDiff8thOrder(f, x));
|
|
20750
21020
|
}
|
|
20751
21021
|
}
|
|
20752
21022
|
},
|
|
@@ -20802,11 +21072,17 @@ ${js}`);
|
|
|
20802
21072
|
signature: {
|
|
20803
21073
|
domain: ["FunctionOf", "Functions", "Numbers", "Numbers", "Numbers"],
|
|
20804
21074
|
evaluate: (ce, ops2) => {
|
|
21075
|
+
const numericMode = ce.numericMode;
|
|
21076
|
+
const precision = ce.precision;
|
|
21077
|
+
ce.numericMode = "machine";
|
|
20805
21078
|
const f = applicableN1(ops2[0]);
|
|
20806
21079
|
const [a, b] = ops2.slice(1).map((op3) => op3.valueOf());
|
|
20807
|
-
|
|
20808
|
-
|
|
20809
|
-
|
|
21080
|
+
let result = void 0;
|
|
21081
|
+
if (typeof a === "number" && typeof b === "number")
|
|
21082
|
+
result = ce.number(monteCarloEstimate(f, a, b));
|
|
21083
|
+
ce.numericMode = numericMode;
|
|
21084
|
+
ce.precision = precision;
|
|
21085
|
+
return result;
|
|
20810
21086
|
}
|
|
20811
21087
|
}
|
|
20812
21088
|
}
|
|
@@ -21571,6 +21847,7 @@ ${js}`);
|
|
|
21571
21847
|
var CONTROL_STRUCTURES_LIBRARY = [
|
|
21572
21848
|
{
|
|
21573
21849
|
Block: {
|
|
21850
|
+
hold: "all",
|
|
21574
21851
|
signature: {
|
|
21575
21852
|
domain: "Functions",
|
|
21576
21853
|
canonical: canonicalBlock,
|
|
@@ -21672,33 +21949,37 @@ ${js}`);
|
|
|
21672
21949
|
function evaluateBlock(ce, ops2) {
|
|
21673
21950
|
if (ops2.length === 0)
|
|
21674
21951
|
return ce.Nothing;
|
|
21952
|
+
ce.resetContext();
|
|
21675
21953
|
let result = void 0;
|
|
21676
21954
|
for (const op3 of ops2) {
|
|
21677
|
-
|
|
21678
|
-
|
|
21679
|
-
|
|
21955
|
+
const h = op3.head;
|
|
21956
|
+
if (h === "Return") {
|
|
21957
|
+
result = op3.op1.evaluate();
|
|
21680
21958
|
break;
|
|
21959
|
+
}
|
|
21960
|
+
if (h === "Break" || h === "Continue") {
|
|
21961
|
+
result = ce.fn(h, [op3.op1.evaluate()]);
|
|
21962
|
+
break;
|
|
21963
|
+
}
|
|
21964
|
+
result = op3.evaluate();
|
|
21681
21965
|
}
|
|
21682
21966
|
return result ?? ce.Nothing;
|
|
21683
21967
|
}
|
|
21684
21968
|
function canonicalBlock(ce, ops2) {
|
|
21685
21969
|
if (ops2.length === 0)
|
|
21686
21970
|
return null;
|
|
21971
|
+
ce.pushScope();
|
|
21687
21972
|
const declarations = [];
|
|
21688
21973
|
const body = [];
|
|
21689
21974
|
for (const op3 of ops2) {
|
|
21690
|
-
if (op3.head === "Declare")
|
|
21975
|
+
if (op3.head === "Declare")
|
|
21691
21976
|
declarations.push(op3);
|
|
21692
|
-
|
|
21693
|
-
const id = op3.op1.symbol;
|
|
21694
|
-
const def = ce.lookupSymbol(id) ?? ce.lookupFunction(id);
|
|
21695
|
-
if (!def) {
|
|
21696
|
-
declarations.push(ce._fn("Declare", [op3.op1, ce.symbol("Undefined")]));
|
|
21697
|
-
}
|
|
21698
|
-
} else
|
|
21977
|
+
else
|
|
21699
21978
|
body.push(invalidateDeclare(op3));
|
|
21700
21979
|
}
|
|
21701
|
-
|
|
21980
|
+
const result = ce._fn("Block", [...declarations, ...body]);
|
|
21981
|
+
ce.popScope();
|
|
21982
|
+
return result;
|
|
21702
21983
|
}
|
|
21703
21984
|
function invalidateDeclare(expr) {
|
|
21704
21985
|
if (expr.head === "Declare")
|
|
@@ -22063,7 +22344,8 @@ ${js}`);
|
|
|
22063
22344
|
},
|
|
22064
22345
|
// By definition, for arguments of the canonical expression of
|
|
22065
22346
|
// `Hold` are not canonicalized.
|
|
22066
|
-
canonical: (ce, args) => args.length !== 1 ? null : ce._fn("Hold", args)
|
|
22347
|
+
canonical: (ce, args) => args.length !== 1 ? null : ce._fn("Hold", args),
|
|
22348
|
+
evaluate: (ce, ops2) => ops2[0]
|
|
22067
22349
|
}
|
|
22068
22350
|
},
|
|
22069
22351
|
HorizontalSpacing: {
|
|
@@ -22103,6 +22385,32 @@ ${js}`);
|
|
|
22103
22385
|
evaluate: (_ce, ops2) => apply3(ops2[0], ops2.slice(1))
|
|
22104
22386
|
}
|
|
22105
22387
|
},
|
|
22388
|
+
Assign: {
|
|
22389
|
+
hold: "all",
|
|
22390
|
+
signature: {
|
|
22391
|
+
domain: ["FunctionOf", "Symbols", "Anything", "Anything"],
|
|
22392
|
+
canonical: (ce, args) => {
|
|
22393
|
+
if (args.length !== 2)
|
|
22394
|
+
return null;
|
|
22395
|
+
const op12 = args[0];
|
|
22396
|
+
const op22 = args[1];
|
|
22397
|
+
if (!op12.symbol)
|
|
22398
|
+
return null;
|
|
22399
|
+
if (op22.symbol)
|
|
22400
|
+
return ce._fn("Assign", args);
|
|
22401
|
+
return ce._fn("Assign", [op12, ce._fn("Hold", [op22])]);
|
|
22402
|
+
},
|
|
22403
|
+
evaluate: (ce, ops2) => {
|
|
22404
|
+
const op12 = ops2[0];
|
|
22405
|
+
const op22 = ops2[1];
|
|
22406
|
+
if (!op12.symbol)
|
|
22407
|
+
return ce.Nothing;
|
|
22408
|
+
const val = op22.evaluate();
|
|
22409
|
+
ce.assign(op12.symbol, val);
|
|
22410
|
+
return val;
|
|
22411
|
+
}
|
|
22412
|
+
}
|
|
22413
|
+
},
|
|
22106
22414
|
Assume: {
|
|
22107
22415
|
hold: "all",
|
|
22108
22416
|
signature: {
|
|
@@ -22112,6 +22420,32 @@ ${js}`);
|
|
|
22112
22420
|
},
|
|
22113
22421
|
// @todo
|
|
22114
22422
|
About: { signature: { domain: "Functions" } },
|
|
22423
|
+
Declare: {
|
|
22424
|
+
hold: "all",
|
|
22425
|
+
signature: {
|
|
22426
|
+
domain: ["FunctionOf", "Symbols", "Anything"],
|
|
22427
|
+
canonical: (ce, args) => {
|
|
22428
|
+
if (args.length !== 2)
|
|
22429
|
+
return null;
|
|
22430
|
+
const op12 = args[0];
|
|
22431
|
+
const op22 = args[1];
|
|
22432
|
+
if (!op12.symbol)
|
|
22433
|
+
return null;
|
|
22434
|
+
if (op22.symbol)
|
|
22435
|
+
return ce._fn("Declare", args);
|
|
22436
|
+
return ce._fn("Declare", [op12, ce._fn("Hold", [op22])]);
|
|
22437
|
+
},
|
|
22438
|
+
evaluate: (ce, ops2) => {
|
|
22439
|
+
const op12 = ops2[0];
|
|
22440
|
+
const op22 = ops2[1];
|
|
22441
|
+
if (!op12.symbol)
|
|
22442
|
+
return ce.Nothing;
|
|
22443
|
+
const val = op22.evaluate();
|
|
22444
|
+
ce.declare(op12.symbol, val);
|
|
22445
|
+
return val;
|
|
22446
|
+
}
|
|
22447
|
+
}
|
|
22448
|
+
},
|
|
22115
22449
|
Domain: {
|
|
22116
22450
|
/** Return the domain of an expression */
|
|
22117
22451
|
signature: {
|
|
@@ -24218,7 +24552,7 @@ ${js}`);
|
|
|
24218
24552
|
}
|
|
24219
24553
|
|
|
24220
24554
|
// src/compute-engine/boxed-expression/boxed-symbol-definition.ts
|
|
24221
|
-
var import_complex17 = __toESM(require_complex()
|
|
24555
|
+
var import_complex17 = __toESM(require_complex());
|
|
24222
24556
|
var _BoxedSymbolDefinition = class {
|
|
24223
24557
|
// @todo
|
|
24224
24558
|
constructor(ce, name, def) {
|
|
@@ -25168,7 +25502,7 @@ ${JSON.stringify(entry)}`
|
|
|
25168
25502
|
}
|
|
25169
25503
|
|
|
25170
25504
|
// src/compute-engine/cost-function.ts
|
|
25171
|
-
var import_complex19 = __toESM(require_complex()
|
|
25505
|
+
var import_complex19 = __toESM(require_complex());
|
|
25172
25506
|
function numericCostFunction(n) {
|
|
25173
25507
|
if (Number.isInteger(n) && n !== 0) {
|
|
25174
25508
|
return Math.floor(Math.log2(Math.abs(n)) / Math.log2(10)) + (n > 0 ? 1 : 2);
|
|
@@ -25560,6 +25894,16 @@ ${JSON.stringify(entry)}`
|
|
|
25560
25894
|
}
|
|
25561
25895
|
if (!options.recursive)
|
|
25562
25896
|
return null;
|
|
25897
|
+
if (subject.ops) {
|
|
25898
|
+
const ops2 = subject.ops;
|
|
25899
|
+
const result = {};
|
|
25900
|
+
for (let i = 0; i < ops2.length; i++) {
|
|
25901
|
+
const sub2 = match(ops2[i], pattern, options);
|
|
25902
|
+
if (sub2 !== null)
|
|
25903
|
+
return sub2;
|
|
25904
|
+
}
|
|
25905
|
+
return result;
|
|
25906
|
+
}
|
|
25563
25907
|
return null;
|
|
25564
25908
|
}
|
|
25565
25909
|
|
|
@@ -27325,10 +27669,10 @@ ${JSON.stringify(entry)}`
|
|
|
27325
27669
|
};
|
|
27326
27670
|
|
|
27327
27671
|
// src/compute-engine.ts
|
|
27328
|
-
var version = "0.
|
|
27672
|
+
var version = "0.18.1";
|
|
27329
27673
|
globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
|
|
27330
27674
|
ComputeEngine: ComputeEngine.prototype.constructor,
|
|
27331
|
-
version: "0.
|
|
27675
|
+
version: "0.18.1"
|
|
27332
27676
|
};
|
|
27333
27677
|
return __toCommonJS(compute_engine_exports);
|
|
27334
27678
|
})();
|