@cortex-js/compute-engine 0.17.0 → 0.18.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.
Files changed (100) hide show
  1. package/dist/compute-engine.esm.js +478 -145
  2. package/dist/compute-engine.js +478 -145
  3. package/dist/compute-engine.min.esm.js +11 -8
  4. package/dist/compute-engine.min.js +11 -8
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +1 -1
  12. package/dist/types/common/utils.d.ts +1 -1
  13. package/dist/types/compute-engine/assume.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  30. package/dist/types/compute-engine/compile.d.ts +8 -4
  31. package/dist/types/compute-engine/compute-engine.d.ts +1 -1
  32. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  33. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  34. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/public.d.ts +15 -6
  52. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  56. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  57. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  58. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  59. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  60. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  61. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  62. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  63. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  64. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  65. package/dist/types/compute-engine/library/core.d.ts +1 -1
  66. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  67. package/dist/types/compute-engine/library/library.d.ts +1 -1
  68. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  69. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  70. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  71. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  72. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  73. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  74. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  75. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  76. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  77. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  78. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  79. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  80. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -1
  81. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  82. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  83. package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
  84. package/dist/types/compute-engine/public.d.ts +1 -1
  85. package/dist/types/compute-engine/rules.d.ts +1 -1
  86. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  87. package/dist/types/compute-engine/solve.d.ts +1 -1
  88. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  89. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  90. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  91. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  92. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  93. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  96. package/dist/types/compute-engine.d.ts +2 -2
  97. package/dist/types/math-json/math-json-format.d.ts +1 -1
  98. package/dist/types/math-json/utils.d.ts +1 -1
  99. package/dist/types/math-json.d.ts +2 -2
  100. package/package.json +10 -3
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.17.0 */
1
+ /** CortexJS Compute Engine 0.18.0 */
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1063,7 +1063,7 @@ function isEnvironmentEntry(entry) {
1063
1063
  }
1064
1064
 
1065
1065
  // src/compute-engine/compute-engine.ts
1066
- var import_complex20 = __toESM(require_complex(), 1);
1066
+ var import_complex20 = __toESM(require_complex());
1067
1067
 
1068
1068
  // node_modules/decimal.js/decimal.mjs
1069
1069
  var EXP_LIMIT = 9e15;
@@ -4859,8 +4859,41 @@ var DEFINITIONS_ARITHMETIC = [
4859
4859
  identifierTrigger: "lcm",
4860
4860
  kind: "function"
4861
4861
  },
4862
- { name: "Max", identifierTrigger: "max", kind: "function" },
4863
- { name: "Min", identifierTrigger: "min", kind: "function" },
4862
+ { identifierTrigger: "max", kind: "function", parse: "Max" },
4863
+ { identifierTrigger: "min", kind: "function", parse: "Min" },
4864
+ { name: "Max", latexTrigger: "\\max", kind: "function" },
4865
+ { name: "Min", latexTrigger: "\\min", kind: "function" },
4866
+ { name: "Supremum", latexTrigger: "\\sup", kind: "function" },
4867
+ { name: "Infimum", latexTrigger: "\\inf", kind: "function" },
4868
+ {
4869
+ name: "Limit",
4870
+ latexTrigger: "\\lim",
4871
+ kind: "expression",
4872
+ parse: (parser) => {
4873
+ if (!parser.match("_"))
4874
+ return void 0;
4875
+ const base = parser.parseGroup();
4876
+ if (head(base) !== "To")
4877
+ return void 0;
4878
+ const expr = parser.parseArguments("implicit");
4879
+ if (!expr)
4880
+ return void 0;
4881
+ return ["Limit", ["Function", expr[0], op(base, 1)], op(base, 2)];
4882
+ },
4883
+ serialize: (serializer, expr) => {
4884
+ const fn = op(expr, 1);
4885
+ const fnVar = op(fn, 2);
4886
+ const to = op(expr, 2);
4887
+ return joinLatex([
4888
+ "\\lim_{",
4889
+ serializer.serialize(fnVar),
4890
+ "\\to",
4891
+ serializer.serialize(to),
4892
+ "}",
4893
+ serializer.serialize(op(fn, 1))
4894
+ ]);
4895
+ }
4896
+ },
4864
4897
  {
4865
4898
  name: "MinusPlus",
4866
4899
  latexTrigger: ["\\mp"],
@@ -5298,13 +5331,14 @@ var DEFINITIONS_CORE = [
5298
5331
  },
5299
5332
  {
5300
5333
  name: "Assign",
5301
- kind: "function",
5302
5334
  latexTrigger: "\\coloneqq",
5335
+ kind: "infix",
5336
+ associativity: "right",
5303
5337
  precedence: 260,
5304
- parse: (parser, lhs) => {
5305
- const rhs = parser.parseExpression({ minPrec: 260 }) ?? "Nothing";
5306
- return ["Assign", lhs, rhs];
5307
- },
5338
+ // parse: (parser: Parser, lhs: Expression) => {
5339
+ // const rhs = parser.parseExpression({ minPrec: 260 }) ?? 'Nothing';
5340
+ // return ['Assign', lhs, rhs];
5341
+ // },
5308
5342
  serialize: (serializer, expr) => {
5309
5343
  return joinLatex([
5310
5344
  serializer.serialize(op(expr, 1)),
@@ -5314,22 +5348,31 @@ var DEFINITIONS_CORE = [
5314
5348
  }
5315
5349
  },
5316
5350
  {
5317
- kind: "function",
5318
- latexTrigger: ":=",
5319
- // \coloneqq
5320
- parse: (parser, lhs) => {
5321
- const rhs = parser.parseExpression({ minPrec: 270 }) ?? "Nothing";
5322
- return ["Assign", lhs, rhs];
5323
- }
5351
+ latexTrigger: [":", "="],
5352
+ kind: "infix",
5353
+ associativity: "right",
5354
+ precedence: 260,
5355
+ parse: "Assign"
5324
5356
  },
5357
+ // {
5358
+ // kind: 'function',
5359
+ // latexTrigger: ':=', // \coloneqq
5360
+ // parse: (parser: Parser, lhs: Expression) => {
5361
+ // const rhs = parser.parseExpression({ minPrec: 270 }) ?? 'Nothing';
5362
+ // return ['Assign', lhs, rhs];
5363
+ // },
5364
+ // },
5325
5365
  {
5326
- kind: "function",
5327
5366
  latexTrigger: "\\colonequals",
5328
5367
  // \coloneqq
5329
- parse: (parser, lhs) => {
5330
- const rhs = parser.parseExpression({ minPrec: 270 }) ?? "Nothing";
5331
- return ["Assign", lhs, rhs];
5332
- }
5368
+ kind: "infix",
5369
+ associativity: "right",
5370
+ precedence: 260,
5371
+ parse: "Assign"
5372
+ // parse: (parser: Parser, lhs: Expression) => {
5373
+ // const rhs = parser.parseExpression({ minPrec: 270 }) ?? 'Nothing';
5374
+ // return ['Assign', lhs, rhs];
5375
+ // },
5333
5376
  },
5334
5377
  {
5335
5378
  name: "BaseForm",
@@ -6074,13 +6117,6 @@ var DEFINITIONS_INEQUALITIES = [
6074
6117
  associativity: "right",
6075
6118
  precedence: 260
6076
6119
  },
6077
- {
6078
- latexTrigger: [":", "="],
6079
- kind: "infix",
6080
- associativity: "right",
6081
- precedence: 260,
6082
- parse: "Assign"
6083
- },
6084
6120
  {
6085
6121
  name: "Approx",
6086
6122
  // Note: Mathematica TildeTilde
@@ -8672,7 +8708,7 @@ var DEFAULT_PARSE_LATEX_OPTIONS = {
8672
8708
  applyInvisibleOperator: "auto",
8673
8709
  skipSpace: true,
8674
8710
  parseArgumentsOfUnknownLatexCommands: true,
8675
- parseNumbers: true,
8711
+ parseNumbers: "auto",
8676
8712
  parseUnknownIdentifier: (id, parser) => parser.computeEngine?.lookupFunction(id) !== void 0 ? "function" : "symbol",
8677
8713
  preserveLatex: false
8678
8714
  };
@@ -9282,27 +9318,27 @@ var _Parser = class {
9282
9318
  if (this.matchAny(["e", "E"])) {
9283
9319
  const exponent = this.parseSignedInteger({ withGrouping: false });
9284
9320
  if (exponent)
9285
- return "e" + exponent;
9321
+ return exponent;
9286
9322
  }
9287
9323
  this.index = start;
9288
9324
  if (this.match("\\times")) {
9289
9325
  this.skipSpaceTokens();
9290
9326
  if (this.match("1") && this.match("0") && this.match("^")) {
9291
9327
  if (/^[0-9]$/.test(this.peek))
9292
- return "e" + this.nextToken();
9328
+ return this.nextToken();
9293
9329
  if (this.match("<{>")) {
9294
9330
  this.skipSpaceTokens();
9295
9331
  const exponent = this.parseSignedInteger();
9296
9332
  this.skipSpaceTokens();
9297
9333
  if (this.match("<}>") && exponent)
9298
- return "e" + exponent;
9334
+ return exponent;
9299
9335
  }
9300
9336
  }
9301
9337
  }
9302
9338
  this.index = start;
9303
9339
  this.skipSpaceTokens();
9304
9340
  if (this.match("\\%"))
9305
- return `e-2`;
9341
+ return `-2`;
9306
9342
  this.index = start;
9307
9343
  if (this.matchAll(this._exponentProductTokens)) {
9308
9344
  this.skipSpaceTokens();
@@ -9311,7 +9347,7 @@ var _Parser = class {
9311
9347
  const exponent = this.parseSignedInteger();
9312
9348
  this.skipSpaceTokens();
9313
9349
  if (this.matchAll(this._endExponentMarkerTokens) && exponent)
9314
- return "e" + exponent;
9350
+ return exponent;
9315
9351
  }
9316
9352
  }
9317
9353
  this.index = start;
@@ -9359,43 +9395,60 @@ var _Parser = class {
9359
9395
  * repeating decimals, etc...
9360
9396
  */
9361
9397
  parseNumber() {
9362
- if (!this.options.parseNumbers)
9398
+ if (this.options.parseNumbers === false || this.options.parseNumbers === "never")
9363
9399
  return null;
9364
9400
  const start = this.index;
9365
9401
  this.skipVisualSpace();
9366
9402
  this.match("+");
9367
- let result = "";
9368
- let dotPrefix = false;
9403
+ let wholePart = "";
9404
+ let fractionalPart = "";
9405
+ let startsWithDecimalMarker = false;
9369
9406
  if (this.match(".") || this.matchAll(this._decimalMarkerTokens)) {
9370
9407
  const peek = this.peek;
9371
- if (peek !== "\\overline" && peek !== this._beginRepeatingDigitsTokens[0] && !/[0-9\(]/.test(peek)) {
9372
- this.index = start;
9373
- return null;
9374
- }
9375
- dotPrefix = true;
9376
- } else {
9377
- result = this.parseDecimalDigits({ withGrouping: true });
9378
- if (!result) {
9379
- this.index = start;
9380
- return null;
9408
+ if (peek === "\\overline" || peek === this._beginRepeatingDigitsTokens[0] || /[0-9\(]/.test(peek)) {
9409
+ startsWithDecimalMarker = true;
9410
+ wholePart = "0";
9381
9411
  }
9412
+ } else
9413
+ wholePart = this.parseDecimalDigits({ withGrouping: true });
9414
+ if (!wholePart) {
9415
+ this.index = start;
9416
+ return null;
9382
9417
  }
9383
- let hasDecimal = true;
9384
- if (!dotPrefix && (this.match(".") || this.matchAll(this._decimalMarkerTokens)))
9385
- result += "." + this.parseDecimalDigits({ withGrouping: true });
9386
- else if (dotPrefix)
9387
- result = "0." + this.parseDecimalDigits({ withGrouping: true });
9418
+ let hasFractionalPart = true;
9419
+ if (startsWithDecimalMarker || this.match(".") || this.matchAll(this._decimalMarkerTokens))
9420
+ fractionalPart = this.parseDecimalDigits({ withGrouping: true });
9388
9421
  else
9389
- hasDecimal = false;
9390
- if (hasDecimal) {
9422
+ hasFractionalPart = false;
9423
+ let hasRepeatingPart = false;
9424
+ if (hasFractionalPart) {
9391
9425
  const repeat = this.parseRepeatingDecimal();
9392
- if (repeat)
9393
- result += repeat;
9394
- else if (this.match("\\ldots") || this.matchAll(this._truncationMarkerTokens)) {
9426
+ if (repeat) {
9427
+ fractionalPart += repeat;
9428
+ hasRepeatingPart = true;
9429
+ } else if (this.match("\\ldots") || this.matchAll(this._truncationMarkerTokens)) {
9395
9430
  }
9396
9431
  }
9397
9432
  this.skipVisualSpace();
9398
- return result + this.parseExponent();
9433
+ const exponent = this.parseExponent();
9434
+ if (!hasRepeatingPart && this.options.parseNumbers === "rational") {
9435
+ const whole = parseInt(wholePart, 10);
9436
+ const fraction = parseInt(fractionalPart, 10);
9437
+ const n = fractionalPart.length;
9438
+ const numerator = whole * Math.pow(10, n) + fraction;
9439
+ const denominator = Math.pow(10, n);
9440
+ if (exponent) {
9441
+ return [
9442
+ "Multiply",
9443
+ ["Rational", numerator, denominator],
9444
+ ["Power", 10, exponent]
9445
+ ];
9446
+ }
9447
+ return ["Rational", numerator, denominator];
9448
+ }
9449
+ return {
9450
+ num: wholePart + (hasFractionalPart ? "." + fractionalPart : "") + (exponent ? "e" + exponent : "")
9451
+ };
9399
9452
  }
9400
9453
  /**
9401
9454
  * A Latex number can be a decimal, hex or octal number.
@@ -9843,18 +9896,24 @@ var _Parser = class {
9843
9896
  (x) => x.latexTrigger === "^"
9844
9897
  );
9845
9898
  if (defs) {
9846
- const arg = [
9847
- "Superscript",
9848
- result,
9849
- superscripts.length === 1 ? superscripts[0] : ["List", ...superscripts]
9850
- ];
9851
- for (const def of defs) {
9852
- if (typeof def.parse === "function")
9853
- result = def.parse(this, arg, { minPrec: 0 });
9854
- else
9855
- result = arg;
9856
- if (result)
9857
- break;
9899
+ let nonEmptySuperscripts = superscripts.filter(
9900
+ (x) => head(x) !== "Sequence"
9901
+ );
9902
+ if (nonEmptySuperscripts.length !== 0) {
9903
+ const superscriptExpression = nonEmptySuperscripts.length === 1 ? nonEmptySuperscripts[0] : ["List", ...nonEmptySuperscripts];
9904
+ const arg = [
9905
+ "Superscript",
9906
+ result,
9907
+ superscriptExpression
9908
+ ];
9909
+ for (const def of defs) {
9910
+ if (typeof def.parse === "function")
9911
+ result = def.parse(this, arg, { minPrec: 0 });
9912
+ else
9913
+ result = arg;
9914
+ if (result)
9915
+ break;
9916
+ }
9858
9917
  }
9859
9918
  }
9860
9919
  }
@@ -10021,8 +10080,11 @@ var _Parser = class {
10021
10080
  const [def, n] = opDefs[0];
10022
10081
  if (this.peek === "^") {
10023
10082
  this.index += 1;
10024
- this.parseGroup();
10025
- this.error("unexpected-operator", start);
10083
+ return [
10084
+ "Superscript",
10085
+ this.error("missing", start),
10086
+ missingIfEmpty(this.parseGroup())
10087
+ ];
10026
10088
  }
10027
10089
  this.index += n;
10028
10090
  if (typeof def.parse === "function") {
@@ -10129,11 +10191,7 @@ var _Parser = class {
10129
10191
  );
10130
10192
  }
10131
10193
  }
10132
- if (result === null) {
10133
- const num = this.parseNumber();
10134
- if (num !== null)
10135
- result = { num };
10136
- }
10194
+ result ?? (result = this.parseNumber());
10137
10195
  result ?? (result = this.parseEnclosure());
10138
10196
  result ?? (result = this.parseEnvironment(until));
10139
10197
  if (result === null && this.matchAll(this._positiveInfinityTokens))
@@ -11061,10 +11119,65 @@ var LatexSyntax = class _LatexSyntax {
11061
11119
  };
11062
11120
 
11063
11121
  // src/compute-engine/boxed-expression/utils.ts
11064
- var import_complex2 = __toESM(require_complex(), 1);
11122
+ var import_complex2 = __toESM(require_complex());
11123
+
11124
+ // src/compute-engine/numerics/numeric.ts
11125
+ var import_complex = __toESM(require_complex());
11126
+
11127
+ // src/compute-engine/numerics/richardson.ts
11128
+ function extrapolate(f, x0, options = {}) {
11129
+ const {
11130
+ contract = 0.125,
11131
+ step = 1,
11132
+ power = 2,
11133
+ atol = 1e-16,
11134
+ rtol = atol > 0 ? 0 : Math.sqrt(Number.EPSILON),
11135
+ maxeval = 1e6,
11136
+ // Number.MAX_SAFE_INTEGER
11137
+ breaktol = 2
11138
+ } = options;
11139
+ if (!isFinite(x0)) {
11140
+ return extrapolate((u) => f(1 / u), 1 / x0, {
11141
+ rtol,
11142
+ atol,
11143
+ maxeval,
11144
+ contract: Math.abs(contract) > 1 ? 1 / contract : contract,
11145
+ step: 1 / step,
11146
+ power
11147
+ });
11148
+ }
11149
+ let h = step;
11150
+ let invcontract = Math.pow(1 / contract, power);
11151
+ let f0 = f(x0 + h);
11152
+ let neville = [f0];
11153
+ let err = Infinity;
11154
+ let numeval = 1;
11155
+ while (numeval < maxeval) {
11156
+ numeval += 1;
11157
+ h *= contract;
11158
+ neville.push(f(x0 + h));
11159
+ let c = invcontract;
11160
+ let minerr = Infinity;
11161
+ for (let i = neville.length - 2; i >= 0; i--) {
11162
+ const old = neville[i];
11163
+ neville[i] = neville[i + 1] + (neville[i + 1] - neville[i]) / (c - 1);
11164
+ const err_ = Math.abs(neville[i] - old);
11165
+ minerr = Math.min(minerr, err_);
11166
+ if (err_ < err) {
11167
+ f0 = neville[i];
11168
+ err = err_;
11169
+ }
11170
+ c *= invcontract;
11171
+ }
11172
+ if (minerr > breaktol * err || !isFinite(minerr))
11173
+ break;
11174
+ if (err <= Math.max(rtol * Math.abs(f0), atol))
11175
+ break;
11176
+ }
11177
+ return [f0, err];
11178
+ }
11065
11179
 
11066
11180
  // src/compute-engine/numerics/numeric.ts
11067
- var import_complex = __toESM(require_complex(), 1);
11068
11181
  var MACHINE_PRECISION_BITS = 53;
11069
11182
  var MACHINE_PRECISION = Math.log10(
11070
11183
  Math.pow(2, MACHINE_PRECISION_BITS)
@@ -12428,6 +12541,19 @@ function monteCarloEstimate(f, a, b, n = 1e4) {
12428
12541
  }
12429
12542
  return sum2 / n * (b - a);
12430
12543
  }
12544
+ function limit(f, x, dir = 1) {
12545
+ if (dir === 0) {
12546
+ const left = limit(f, x, -1);
12547
+ const right = limit(f, x, 1);
12548
+ if (left === void 0 || right === void 0)
12549
+ return NaN;
12550
+ if (Math.abs(left - right) > 1e-5)
12551
+ return NaN;
12552
+ return (left + right) / 2;
12553
+ }
12554
+ const [val, err] = extrapolate(f, x, { step: dir > 0 ? 1 : -1 });
12555
+ return val;
12556
+ }
12431
12557
 
12432
12558
  // src/compute-engine/numerics/numeric-bigint.ts
12433
12559
  function bigint(a) {
@@ -12748,7 +12874,7 @@ function getWildcardName(s) {
12748
12874
  }
12749
12875
 
12750
12876
  // src/compute-engine/boxed-expression/order.ts
12751
- var import_complex3 = __toESM(require_complex(), 1);
12877
+ var import_complex3 = __toESM(require_complex());
12752
12878
 
12753
12879
  // src/compute-engine/symbolic/polynomials.ts
12754
12880
  function totalDegree(expr) {
@@ -12958,7 +13084,7 @@ function flattenSequence(xs) {
12958
13084
  }
12959
13085
 
12960
13086
  // src/compute-engine/numerics/rationals.ts
12961
- var import_complex4 = __toESM(require_complex(), 1);
13087
+ var import_complex4 = __toESM(require_complex());
12962
13088
  function isRational(x) {
12963
13089
  return x !== null && Array.isArray(x);
12964
13090
  }
@@ -13268,7 +13394,7 @@ function signDiff(lhs, rhs, tolerance) {
13268
13394
  }
13269
13395
 
13270
13396
  // src/compute-engine/symbolic/sum.ts
13271
- var import_complex5 = __toESM(require_complex(), 1);
13397
+ var import_complex5 = __toESM(require_complex());
13272
13398
  var Sum = class {
13273
13399
  constructor(ce, xs, options) {
13274
13400
  // If `false`, the running sums are not calculated
@@ -13704,7 +13830,7 @@ function domainSetsLibrary() {
13704
13830
  }
13705
13831
 
13706
13832
  // src/compute-engine/boxed-expression/abstract-boxed-expression.ts
13707
- var import_complex6 = __toESM(require_complex(), 1);
13833
+ var import_complex6 = __toESM(require_complex());
13708
13834
 
13709
13835
  // src/compute-engine/library/utils.ts
13710
13836
  function normalizeLimits(range) {
@@ -13775,6 +13901,7 @@ var NATIVE_JS_FUNCTIONS = {
13775
13901
  Gcd: "_SYS.gcd",
13776
13902
  // Math.hypot
13777
13903
  Lcm: "_SYS.lcm",
13904
+ Limit: (args, compile2) => `_SYS.limit(${compile2(args[0])}, ${compile2(args[1])})`,
13778
13905
  Ln: "Math.log",
13779
13906
  Log: "Math.log10",
13780
13907
  LogGamma: "_SYS.lngamma",
@@ -13809,7 +13936,7 @@ var NATIVE_JS_FUNCTIONS = {
13809
13936
  },
13810
13937
  Random: "Math.random",
13811
13938
  Round: "Math.round",
13812
- Sqaure: (args, compile2) => {
13939
+ Square: (args, compile2) => {
13813
13940
  const arg = args[0];
13814
13941
  if (arg === null)
13815
13942
  throw new Error("Square: no argument");
@@ -13920,7 +14047,8 @@ var ComputeEngineFunction = class extends Function {
13920
14047
  lngamma: gammaln,
13921
14048
  gcd,
13922
14049
  lcm,
13923
- chop
14050
+ chop,
14051
+ limit
13924
14052
  };
13925
14053
  return new Proxy(this, {
13926
14054
  apply: (target, thisArg, argumentsList) => super.apply(thisArg, [this.sys, ...argumentsList]),
@@ -13967,7 +14095,9 @@ function compileToJavascript(expr) {
13967
14095
  return void 0;
13968
14096
  },
13969
14097
  string: (str) => JSON.stringify(str),
13970
- number: (n) => n.toString()
14098
+ number: (n) => n.toString(),
14099
+ indent: 0,
14100
+ ws: (s) => s ?? ""
13971
14101
  });
13972
14102
  }
13973
14103
  function compileExpr(h, args, prec, target) {
@@ -13992,6 +14122,50 @@ function compileExpr(h, args, prec, target) {
13992
14122
  }
13993
14123
  return op3[1] < prec ? `(${resultStr})` : resultStr;
13994
14124
  }
14125
+ if (h === "Function") {
14126
+ const params = args.slice(1).map((x) => x.symbol);
14127
+ return `((${params.join(", ")}) => ${compile(args[0], {
14128
+ ...target,
14129
+ var: (id) => params.includes(id) ? id : target.var(id)
14130
+ })})`;
14131
+ }
14132
+ if (h === "Declare")
14133
+ return `let ${args[0].symbol}`;
14134
+ if (h === "Assign")
14135
+ return `${args[0].symbol} = ${compile(args[1], target)}`;
14136
+ if (h === "Return")
14137
+ return `return ${compile(args[0], target)}`;
14138
+ if (h === "If") {
14139
+ if (args.length !== 3)
14140
+ throw new Error("If: wrong number of arguments");
14141
+ return `((${compile(args[0], target)}) ? (${compile(
14142
+ args[1],
14143
+ target
14144
+ )}) : (${compile(args[2], target)}))`;
14145
+ }
14146
+ if (h === "Block") {
14147
+ const locals = [];
14148
+ for (const arg of args) {
14149
+ if (arg.head === "Declare")
14150
+ locals.push(arg.ops[0].symbol);
14151
+ }
14152
+ if (args.length === 1 && locals.length === 0)
14153
+ return compile(args[0], target);
14154
+ const result = args.map(
14155
+ (arg) => compile(arg, {
14156
+ ...target,
14157
+ var: (id) => {
14158
+ if (locals.includes(id))
14159
+ return id;
14160
+ return target.var(id);
14161
+ }
14162
+ })
14163
+ );
14164
+ result[result.length - 1] = `return ${result[result.length - 1]}`;
14165
+ return `(() => {${target.ws("\n")}${result.join(
14166
+ `;${target.ws("\n")}`
14167
+ )}${target.ws("\n")}})()`;
14168
+ }
13995
14169
  const fn = target.functions?.(h);
13996
14170
  if (!fn)
13997
14171
  throw new Error(`Unknown function ${h}`);
@@ -14383,7 +14557,7 @@ var _BoxedExpression = class {
14383
14557
  compile(to = "javascript", options) {
14384
14558
  if (to !== "javascript")
14385
14559
  return void 0;
14386
- options ?? (options = { optimize: ["simplify", "evaluate"] });
14560
+ options ?? (options = { optimize: ["simplify"] });
14387
14561
  let expr = this;
14388
14562
  if (options.optimize.includes("simplify"))
14389
14563
  expr = expr.simplify();
@@ -14757,7 +14931,7 @@ function narrow(a, b) {
14757
14931
  }
14758
14932
 
14759
14933
  // src/compute-engine/symbolic/utils.ts
14760
- var import_complex7 = __toESM(require_complex(), 1);
14934
+ var import_complex7 = __toESM(require_complex());
14761
14935
  function makePositive(expr) {
14762
14936
  if (expr.head === "Negate")
14763
14937
  return [-1, expr.op1];
@@ -15312,7 +15486,7 @@ function evalSummation(ce, expr, range, mode) {
15312
15486
  }
15313
15487
 
15314
15488
  // src/compute-engine/symbolic/negate.ts
15315
- var import_complex8 = __toESM(require_complex(), 1);
15489
+ var import_complex8 = __toESM(require_complex());
15316
15490
  function negateLiteral(expr, metadata) {
15317
15491
  let n = expr.numericValue;
15318
15492
  if (n === null)
@@ -15844,10 +16018,10 @@ function isInequality(expr) {
15844
16018
  }
15845
16019
 
15846
16020
  // src/compute-engine/boxed-expression/box.ts
15847
- var import_complex14 = __toESM(require_complex(), 1);
16021
+ var import_complex14 = __toESM(require_complex());
15848
16022
 
15849
16023
  // src/compute-engine/boxed-expression/serialize.ts
15850
- var import_complex10 = __toESM(require_complex(), 1);
16024
+ var import_complex10 = __toESM(require_complex());
15851
16025
 
15852
16026
  // src/compute-engine/numerics/numeric-bignum.ts
15853
16027
  function factorial3(ce, n) {
@@ -15963,7 +16137,7 @@ function isInMachineRange(d) {
15963
16137
  }
15964
16138
 
15965
16139
  // src/compute-engine/symbolic/product.ts
15966
- var import_complex9 = __toESM(require_complex(), 1);
16140
+ var import_complex9 = __toESM(require_complex());
15967
16141
  var Product = class {
15968
16142
  constructor(ce, xs, options) {
15969
16143
  this.options = options;
@@ -16902,7 +17076,7 @@ var BoxedDictionary = class _BoxedDictionary extends _BoxedExpression {
16902
17076
  };
16903
17077
 
16904
17078
  // src/compute-engine/boxed-expression/boxed-function.ts
16905
- var import_complex11 = __toESM(require_complex(), 1);
17079
+ var import_complex11 = __toESM(require_complex());
16906
17080
 
16907
17081
  // src/compute-engine/simplify-rules.ts
16908
17082
  var SIMPLIFY_RULES = [];
@@ -17595,10 +17769,12 @@ var BoxedFunction = class _BoxedFunction extends _BoxedExpression {
17595
17769
  const sig = def?.signature;
17596
17770
  if (!result && sig) {
17597
17771
  const numericMode = options?.numericMode ?? false;
17772
+ const context = this.engine.swapScope(this.scope);
17598
17773
  if (numericMode && sig.N)
17599
17774
  result = sig.N(this.engine, tail);
17600
17775
  if (!result && sig.evaluate)
17601
17776
  result = sig.evaluate(this.engine, tail);
17777
+ this.engine.swapScope(context);
17602
17778
  }
17603
17779
  if (result) {
17604
17780
  const num = result.numericValue;
@@ -17791,10 +17967,10 @@ function cheapest(oldExpr, newExpr) {
17791
17967
  }
17792
17968
 
17793
17969
  // src/compute-engine/boxed-expression/boxed-number.ts
17794
- var import_complex13 = __toESM(require_complex(), 1);
17970
+ var import_complex13 = __toESM(require_complex());
17795
17971
 
17796
17972
  // src/compute-engine/domain-utils.ts
17797
- var import_complex12 = __toESM(require_complex(), 1);
17973
+ var import_complex12 = __toESM(require_complex());
17798
17974
  function inferNumericDomain(value) {
17799
17975
  if (typeof value === "number" && !isNaN(value)) {
17800
17976
  if (!isFinite(value))
@@ -18081,7 +18257,12 @@ var BoxedNumber = class _BoxedNumber extends _BoxedExpression {
18081
18257
  return false;
18082
18258
  }
18083
18259
  isEqual(rhs) {
18084
- return this.isSame(rhs);
18260
+ if (this === rhs)
18261
+ return true;
18262
+ if (!(rhs instanceof _BoxedNumber))
18263
+ return false;
18264
+ const s = signDiff(this, rhs);
18265
+ return s === 0;
18085
18266
  }
18086
18267
  match(rhs, options) {
18087
18268
  if (this.isEqualWithTolerance(rhs, options?.numericTolerance ?? 0))
@@ -18736,7 +18917,7 @@ function asString(expr) {
18736
18917
  }
18737
18918
 
18738
18919
  // src/compute-engine/library/arithmetic.ts
18739
- var import_complex16 = __toESM(require_complex(), 1);
18920
+ var import_complex16 = __toESM(require_complex());
18740
18921
 
18741
18922
  // src/compute-engine/numerics/numeric-complex.ts
18742
18923
  function gamma3(c) {
@@ -18747,7 +18928,7 @@ function gammaln3(c) {
18747
18928
  }
18748
18929
 
18749
18930
  // src/compute-engine/library/arithmetic-power.ts
18750
- var import_complex15 = __toESM(require_complex(), 1);
18931
+ var import_complex15 = __toESM(require_complex());
18751
18932
  function canonicalPower(ce, base, exponent, metadata) {
18752
18933
  if (exponent.symbol === "ComplexInfinity")
18753
18934
  return ce.NaN;
@@ -20162,21 +20343,7 @@ var ARITHMETIC_LIBRARY = [
20162
20343
  return ops2[0];
20163
20344
  return ce.fn("Max", ops2);
20164
20345
  },
20165
- evaluate: (ce, ops2) => {
20166
- if (ops2.length === 0)
20167
- return ce.NegativeInfinity;
20168
- let result = void 0;
20169
- const rest = [];
20170
- for (const op3 of ops2) {
20171
- if (!op3.isNumber || op3.numericValue === void 0)
20172
- rest.push(op3);
20173
- else if (!result || op3.isGreater(result))
20174
- result = op3;
20175
- }
20176
- if (rest.length > 0)
20177
- return ce.box(result ? ["Max", result, ...rest] : ["Max", ...rest]);
20178
- return result ?? ce.NaN;
20179
- }
20346
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Max")
20180
20347
  }
20181
20348
  },
20182
20349
  Min: {
@@ -20186,26 +20353,42 @@ var ARITHMETIC_LIBRARY = [
20186
20353
  domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
20187
20354
  simplify: (ce, ops2) => {
20188
20355
  if (ops2.length === 0)
20189
- return ce.NegativeInfinity;
20356
+ return ce.PositiveInfinity;
20190
20357
  if (ops2.length === 1)
20191
20358
  return ops2[0];
20192
20359
  return ce.fn("Min", ops2);
20193
20360
  },
20194
- evaluate: (ce, ops2) => {
20361
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Min")
20362
+ }
20363
+ },
20364
+ Supremum: {
20365
+ description: "Like Max, but defined for open sets",
20366
+ complexity: 1200,
20367
+ signature: {
20368
+ domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
20369
+ simplify: (ce, ops2) => {
20195
20370
  if (ops2.length === 0)
20196
20371
  return ce.NegativeInfinity;
20197
- let result = void 0;
20198
- const rest = [];
20199
- for (const op3 of ops2) {
20200
- if (!op3.isNumber || op3.numericValue === void 0)
20201
- rest.push(op3);
20202
- else if (!result || op3.isLess(result))
20203
- result = op3;
20204
- }
20205
- if (rest.length > 0)
20206
- return ce.box(result ? ["Min", result, ...rest] : ["Min", ...rest]);
20207
- return result ?? ce.NaN;
20208
- }
20372
+ if (ops2.length === 1)
20373
+ return ops2[0];
20374
+ return ce.fn("Min", ops2);
20375
+ },
20376
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Supremum")
20377
+ }
20378
+ },
20379
+ Infimum: {
20380
+ description: "Like Min, but defined for open sets",
20381
+ complexity: 1200,
20382
+ signature: {
20383
+ domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
20384
+ simplify: (ce, ops2) => {
20385
+ if (ops2.length === 0)
20386
+ return ce.PositiveInfinity;
20387
+ if (ops2.length === 1)
20388
+ return ops2[0];
20389
+ return ce.fn("Min", ops2);
20390
+ },
20391
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Infimum")
20209
20392
  }
20210
20393
  },
20211
20394
  Product: {
@@ -20251,6 +20434,69 @@ var ARITHMETIC_LIBRARY = [
20251
20434
  evaluate: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "evaluate"),
20252
20435
  N: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "N")
20253
20436
  }
20437
+ },
20438
+ // Limits
20439
+ Limit: {
20440
+ description: "Limit of a function",
20441
+ complexity: 5e3,
20442
+ hold: "all",
20443
+ signature: {
20444
+ domain: [
20445
+ "FunctionOf",
20446
+ "Anything",
20447
+ "Numbers",
20448
+ ["OptArg", "Numbers"],
20449
+ "Numbers"
20450
+ ],
20451
+ N: (ce, ops2) => {
20452
+ const [f, x, dir] = ops2;
20453
+ const target = asFloat(x.N());
20454
+ if (target === null)
20455
+ return void 0;
20456
+ const fn = applicable(f);
20457
+ return ce.number(
20458
+ limit(
20459
+ (x2) => {
20460
+ let y = fn([ce.number(x2)])?.valueOf();
20461
+ return typeof y === "number" ? y : Number.NaN;
20462
+ },
20463
+ target,
20464
+ dir ? asFloat(dir) ?? 1 : 1
20465
+ )
20466
+ );
20467
+ }
20468
+ }
20469
+ },
20470
+ NLimit: {
20471
+ description: "Numerical approximation of the limit of a function",
20472
+ complexity: 5e3,
20473
+ hold: "all",
20474
+ signature: {
20475
+ domain: [
20476
+ "FunctionOf",
20477
+ "Anything",
20478
+ "Numbers",
20479
+ ["OptArg", "Numbers"],
20480
+ "Numbers"
20481
+ ],
20482
+ evaluate: (ce, ops2) => {
20483
+ const [f, x, dir] = ops2;
20484
+ const target = asFloat(x.N());
20485
+ if (target === null)
20486
+ return void 0;
20487
+ const fn = applicable(f);
20488
+ return ce.number(
20489
+ limit(
20490
+ (x2) => {
20491
+ let y = fn([ce.number(x2)])?.valueOf();
20492
+ return typeof y === "number" ? y : Number.NaN;
20493
+ },
20494
+ target,
20495
+ dir ? asFloat(dir) ?? 1 : 1
20496
+ )
20497
+ );
20498
+ }
20499
+ }
20254
20500
  }
20255
20501
  },
20256
20502
  //
@@ -20357,6 +20603,24 @@ function processAbs(ce, arg, mode) {
20357
20603
  return ce.neg(arg);
20358
20604
  return void 0;
20359
20605
  }
20606
+ function processMinMax(ce, ops2, mode) {
20607
+ const upper = mode === "Max" || mode === "Supremum";
20608
+ if (ops2.length === 0)
20609
+ return upper ? ce.NegativeInfinity : ce.PositiveInfinity;
20610
+ let result = void 0;
20611
+ const rest = [];
20612
+ for (const op3 of ops2) {
20613
+ if (!op3.isNumber || op3.numericValue === void 0)
20614
+ rest.push(op3);
20615
+ else if (!result)
20616
+ result = op3;
20617
+ else if (upper && op3.isGreater(result) || !upper && op3.isLess(result))
20618
+ result = op3;
20619
+ }
20620
+ if (rest.length > 0)
20621
+ return ce.box(result ? [mode, result, ...rest] : [mode, ...rest]);
20622
+ return result ?? (upper ? ce.NegativeInfinity : ce.PositiveInfinity);
20623
+ }
20360
20624
 
20361
20625
  // src/compute-engine/symbolic/derivative.ts
20362
20626
  var DERIVATIVES_TABLE = {
@@ -20681,8 +20945,9 @@ var CALCULUS_LIBRARY = [
20681
20945
  const params = ops2.slice(1);
20682
20946
  f.bind();
20683
20947
  f = f.canonical;
20948
+ const result = ce._fn("D", [f, ...params]);
20684
20949
  ce.popScope();
20685
- return ce._fn("D", [f, ...params]);
20950
+ return result;
20686
20951
  },
20687
20952
  evaluate: (ce, ops2) => {
20688
20953
  let f = ops2[0].canonical;
@@ -21541,6 +21806,7 @@ function indexes(ranges) {
21541
21806
  var CONTROL_STRUCTURES_LIBRARY = [
21542
21807
  {
21543
21808
  Block: {
21809
+ hold: "all",
21544
21810
  signature: {
21545
21811
  domain: "Functions",
21546
21812
  canonical: canonicalBlock,
@@ -21642,33 +21908,37 @@ function whichEvaluate(ce, args, mode) {
21642
21908
  function evaluateBlock(ce, ops2) {
21643
21909
  if (ops2.length === 0)
21644
21910
  return ce.Nothing;
21911
+ ce.resetContext();
21645
21912
  let result = void 0;
21646
21913
  for (const op3 of ops2) {
21647
- result = op3.evaluate();
21648
- const h = result.head;
21649
- if (h === "Return" || h === "Break" || h === "Continue")
21914
+ const h = op3.head;
21915
+ if (h === "Return") {
21916
+ result = op3.op1.evaluate();
21650
21917
  break;
21918
+ }
21919
+ if (h === "Break" || h === "Continue") {
21920
+ result = ce.fn(h, [op3.op1.evaluate()]);
21921
+ break;
21922
+ }
21923
+ result = op3.evaluate();
21651
21924
  }
21652
21925
  return result ?? ce.Nothing;
21653
21926
  }
21654
21927
  function canonicalBlock(ce, ops2) {
21655
21928
  if (ops2.length === 0)
21656
21929
  return null;
21930
+ ce.pushScope();
21657
21931
  const declarations = [];
21658
21932
  const body = [];
21659
21933
  for (const op3 of ops2) {
21660
- if (op3.head === "Declare") {
21934
+ if (op3.head === "Declare")
21661
21935
  declarations.push(op3);
21662
- } else if (op3.head === "Assign") {
21663
- const id = op3.op1.symbol;
21664
- const def = ce.lookupSymbol(id) ?? ce.lookupFunction(id);
21665
- if (!def) {
21666
- declarations.push(ce._fn("Declare", [op3.op1, ce.symbol("Undefined")]));
21667
- }
21668
- } else
21936
+ else
21669
21937
  body.push(invalidateDeclare(op3));
21670
21938
  }
21671
- return ce._fn("Block", [...declarations, ...body]);
21939
+ const result = ce._fn("Block", [...declarations, ...body]);
21940
+ ce.popScope();
21941
+ return result;
21672
21942
  }
21673
21943
  function invalidateDeclare(expr) {
21674
21944
  if (expr.head === "Declare")
@@ -22033,7 +22303,8 @@ var CORE_LIBRARY = [
22033
22303
  },
22034
22304
  // By definition, for arguments of the canonical expression of
22035
22305
  // `Hold` are not canonicalized.
22036
- canonical: (ce, args) => args.length !== 1 ? null : ce._fn("Hold", args)
22306
+ canonical: (ce, args) => args.length !== 1 ? null : ce._fn("Hold", args),
22307
+ evaluate: (ce, ops2) => ops2[0]
22037
22308
  }
22038
22309
  },
22039
22310
  HorizontalSpacing: {
@@ -22073,6 +22344,32 @@ var CORE_LIBRARY = [
22073
22344
  evaluate: (_ce, ops2) => apply3(ops2[0], ops2.slice(1))
22074
22345
  }
22075
22346
  },
22347
+ Assign: {
22348
+ hold: "all",
22349
+ signature: {
22350
+ domain: ["FunctionOf", "Symbols", "Anything", "Anything"],
22351
+ canonical: (ce, args) => {
22352
+ if (args.length !== 2)
22353
+ return null;
22354
+ const op12 = args[0];
22355
+ const op22 = args[1];
22356
+ if (!op12.symbol)
22357
+ return null;
22358
+ if (op22.symbol)
22359
+ return ce._fn("Assign", args);
22360
+ return ce._fn("Assign", [op12, ce._fn("Hold", [op22])]);
22361
+ },
22362
+ evaluate: (ce, ops2) => {
22363
+ const op12 = ops2[0];
22364
+ const op22 = ops2[1];
22365
+ if (!op12.symbol)
22366
+ return ce.Nothing;
22367
+ const val = op22.evaluate();
22368
+ ce.assign(op12.symbol, val);
22369
+ return val;
22370
+ }
22371
+ }
22372
+ },
22076
22373
  Assume: {
22077
22374
  hold: "all",
22078
22375
  signature: {
@@ -22082,6 +22379,32 @@ var CORE_LIBRARY = [
22082
22379
  },
22083
22380
  // @todo
22084
22381
  About: { signature: { domain: "Functions" } },
22382
+ Declare: {
22383
+ hold: "all",
22384
+ signature: {
22385
+ domain: ["FunctionOf", "Symbols", "Anything"],
22386
+ canonical: (ce, args) => {
22387
+ if (args.length !== 2)
22388
+ return null;
22389
+ const op12 = args[0];
22390
+ const op22 = args[1];
22391
+ if (!op12.symbol)
22392
+ return null;
22393
+ if (op22.symbol)
22394
+ return ce._fn("Declare", args);
22395
+ return ce._fn("Declare", [op12, ce._fn("Hold", [op22])]);
22396
+ },
22397
+ evaluate: (ce, ops2) => {
22398
+ const op12 = ops2[0];
22399
+ const op22 = ops2[1];
22400
+ if (!op12.symbol)
22401
+ return ce.Nothing;
22402
+ const val = op22.evaluate();
22403
+ ce.declare(op12.symbol, val);
22404
+ return val;
22405
+ }
22406
+ }
22407
+ },
22085
22408
  Domain: {
22086
22409
  /** Return the domain of an expression */
22087
22410
  signature: {
@@ -24188,7 +24511,7 @@ function evalTrig(ce, mode, head2, op3) {
24188
24511
  }
24189
24512
 
24190
24513
  // src/compute-engine/boxed-expression/boxed-symbol-definition.ts
24191
- var import_complex17 = __toESM(require_complex(), 1);
24514
+ var import_complex17 = __toESM(require_complex());
24192
24515
  var _BoxedSymbolDefinition = class {
24193
24516
  // @todo
24194
24517
  constructor(ce, name, def) {
@@ -25138,7 +25461,7 @@ function isFunctionDefinition(def) {
25138
25461
  }
25139
25462
 
25140
25463
  // src/compute-engine/cost-function.ts
25141
- var import_complex19 = __toESM(require_complex(), 1);
25464
+ var import_complex19 = __toESM(require_complex());
25142
25465
  function numericCostFunction(n) {
25143
25466
  if (Number.isInteger(n) && n !== 0) {
25144
25467
  return Math.floor(Math.log2(Math.abs(n)) / Math.log2(10)) + (n > 0 ? 1 : 2);
@@ -25530,6 +25853,16 @@ function match(subject, pattern, options) {
25530
25853
  }
25531
25854
  if (!options.recursive)
25532
25855
  return null;
25856
+ if (subject.ops) {
25857
+ const ops2 = subject.ops;
25858
+ const result = {};
25859
+ for (let i = 0; i < ops2.length; i++) {
25860
+ const sub2 = match(ops2[i], pattern, options);
25861
+ if (sub2 !== null)
25862
+ return sub2;
25863
+ }
25864
+ return result;
25865
+ }
25533
25866
  return null;
25534
25867
  }
25535
25868
 
@@ -27295,10 +27628,10 @@ var ComputeEngine = class _ComputeEngine {
27295
27628
  };
27296
27629
 
27297
27630
  // src/compute-engine.ts
27298
- var version = "0.17.0";
27631
+ var version = "0.18.0";
27299
27632
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
27300
27633
  ComputeEngine: ComputeEngine.prototype.constructor,
27301
- version: "0.17.0"
27634
+ version: "0.18.0"
27302
27635
  };
27303
27636
  export {
27304
27637
  ADDITION_PRECEDENCE,