@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
  (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(), 1);
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
- { name: "Max", identifierTrigger: "max", kind: "function" },
4893
- { name: "Min", identifierTrigger: "min", kind: "function" },
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
- const rhs = parser.parseExpression({ minPrec: 260 }) ?? "Nothing";
5336
- return ["Assign", lhs, rhs];
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
- kind: "function",
5348
- latexTrigger: ":=",
5349
- // \coloneqq
5350
- parse: (parser, lhs) => {
5351
- const rhs = parser.parseExpression({ minPrec: 270 }) ?? "Nothing";
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
- parse: (parser, lhs) => {
5360
- const rhs = parser.parseExpression({ minPrec: 270 }) ?? "Nothing";
5361
- return ["Assign", lhs, rhs];
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: true,
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 "e" + exponent;
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 "e" + this.nextToken();
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 "e" + exponent;
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 `e-2`;
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 "e" + exponent;
9380
+ return exponent;
9345
9381
  }
9346
9382
  }
9347
9383
  this.index = start;
@@ -9389,43 +9425,60 @@ var ComputeEngine = (() => {
9389
9425
  * repeating decimals, etc...
9390
9426
  */
9391
9427
  parseNumber() {
9392
- if (!this.options.parseNumbers)
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 result = "";
9398
- let dotPrefix = false;
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 !== "\\overline" && peek !== this._beginRepeatingDigitsTokens[0] && !/[0-9\(]/.test(peek)) {
9402
- this.index = start;
9403
- return null;
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 hasDecimal = true;
9414
- if (!dotPrefix && (this.match(".") || this.matchAll(this._decimalMarkerTokens)))
9415
- result += "." + this.parseDecimalDigits({ withGrouping: true });
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
- hasDecimal = false;
9420
- if (hasDecimal) {
9452
+ hasFractionalPart = false;
9453
+ let hasRepeatingPart = false;
9454
+ if (hasFractionalPart) {
9421
9455
  const repeat = this.parseRepeatingDecimal();
9422
- if (repeat)
9423
- result += repeat;
9424
- else if (this.match("\\ldots") || this.matchAll(this._truncationMarkerTokens)) {
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
- return result + this.parseExponent();
9463
+ const exponent = this.parseExponent();
9464
+ if (!hasRepeatingPart && this.options.parseNumbers === "rational") {
9465
+ const whole = parseInt(wholePart, 10);
9466
+ const fraction = parseInt(fractionalPart, 10);
9467
+ const n = fractionalPart.length;
9468
+ const numerator = whole * Math.pow(10, n) + fraction;
9469
+ const denominator = Math.pow(10, n);
9470
+ if (exponent) {
9471
+ return [
9472
+ "Multiply",
9473
+ ["Rational", numerator, denominator],
9474
+ ["Power", 10, exponent]
9475
+ ];
9476
+ }
9477
+ return ["Rational", numerator, denominator];
9478
+ }
9479
+ return {
9480
+ num: wholePart + (hasFractionalPart ? "." + fractionalPart : "") + (exponent ? "e" + exponent : "")
9481
+ };
9429
9482
  }
9430
9483
  /**
9431
9484
  * A Latex number can be a decimal, hex or octal number.
@@ -9873,18 +9926,24 @@ var ComputeEngine = (() => {
9873
9926
  (x) => x.latexTrigger === "^"
9874
9927
  );
9875
9928
  if (defs) {
9876
- const arg = [
9877
- "Superscript",
9878
- result,
9879
- superscripts.length === 1 ? superscripts[0] : ["List", ...superscripts]
9880
- ];
9881
- for (const def of defs) {
9882
- if (typeof def.parse === "function")
9883
- result = def.parse(this, arg, { minPrec: 0 });
9884
- else
9885
- result = arg;
9886
- if (result)
9887
- break;
9929
+ let nonEmptySuperscripts = superscripts.filter(
9930
+ (x) => head(x) !== "Sequence"
9931
+ );
9932
+ if (nonEmptySuperscripts.length !== 0) {
9933
+ const superscriptExpression = nonEmptySuperscripts.length === 1 ? nonEmptySuperscripts[0] : ["List", ...nonEmptySuperscripts];
9934
+ const arg = [
9935
+ "Superscript",
9936
+ result,
9937
+ superscriptExpression
9938
+ ];
9939
+ for (const def of defs) {
9940
+ if (typeof def.parse === "function")
9941
+ result = def.parse(this, arg, { minPrec: 0 });
9942
+ else
9943
+ result = arg;
9944
+ if (result)
9945
+ break;
9946
+ }
9888
9947
  }
9889
9948
  }
9890
9949
  }
@@ -10051,8 +10110,11 @@ var ComputeEngine = (() => {
10051
10110
  const [def, n] = opDefs[0];
10052
10111
  if (this.peek === "^") {
10053
10112
  this.index += 1;
10054
- this.parseGroup();
10055
- this.error("unexpected-operator", start);
10113
+ return [
10114
+ "Superscript",
10115
+ this.error("missing", start),
10116
+ missingIfEmpty(this.parseGroup())
10117
+ ];
10056
10118
  }
10057
10119
  this.index += n;
10058
10120
  if (typeof def.parse === "function") {
@@ -10159,11 +10221,7 @@ var ComputeEngine = (() => {
10159
10221
  );
10160
10222
  }
10161
10223
  }
10162
- if (result === null) {
10163
- const num = this.parseNumber();
10164
- if (num !== null)
10165
- result = { num };
10166
- }
10224
+ result ?? (result = this.parseNumber());
10167
10225
  result ?? (result = this.parseEnclosure());
10168
10226
  result ?? (result = this.parseEnvironment(until));
10169
10227
  if (result === null && this.matchAll(this._positiveInfinityTokens))
@@ -11091,10 +11149,65 @@ var ComputeEngine = (() => {
11091
11149
  };
11092
11150
 
11093
11151
  // src/compute-engine/boxed-expression/utils.ts
11094
- var import_complex2 = __toESM(require_complex(), 1);
11152
+ var import_complex2 = __toESM(require_complex());
11153
+
11154
+ // src/compute-engine/numerics/numeric.ts
11155
+ var import_complex = __toESM(require_complex());
11156
+
11157
+ // src/compute-engine/numerics/richardson.ts
11158
+ function extrapolate(f, x0, options = {}) {
11159
+ const {
11160
+ contract = 0.125,
11161
+ step = 1,
11162
+ power = 2,
11163
+ atol = 1e-16,
11164
+ rtol = atol > 0 ? 0 : Math.sqrt(Number.EPSILON),
11165
+ maxeval = 1e6,
11166
+ // Number.MAX_SAFE_INTEGER
11167
+ breaktol = 2
11168
+ } = options;
11169
+ if (!isFinite(x0)) {
11170
+ return extrapolate((u) => f(1 / u), 1 / x0, {
11171
+ rtol,
11172
+ atol,
11173
+ maxeval,
11174
+ contract: Math.abs(contract) > 1 ? 1 / contract : contract,
11175
+ step: 1 / step,
11176
+ power
11177
+ });
11178
+ }
11179
+ let h = step;
11180
+ let invcontract = Math.pow(1 / contract, power);
11181
+ let f0 = f(x0 + h);
11182
+ let neville = [f0];
11183
+ let err = Infinity;
11184
+ let numeval = 1;
11185
+ while (numeval < maxeval) {
11186
+ numeval += 1;
11187
+ h *= contract;
11188
+ neville.push(f(x0 + h));
11189
+ let c = invcontract;
11190
+ let minerr = Infinity;
11191
+ for (let i = neville.length - 2; i >= 0; i--) {
11192
+ const old = neville[i];
11193
+ neville[i] = neville[i + 1] + (neville[i + 1] - neville[i]) / (c - 1);
11194
+ const err_ = Math.abs(neville[i] - old);
11195
+ minerr = Math.min(minerr, err_);
11196
+ if (err_ < err) {
11197
+ f0 = neville[i];
11198
+ err = err_;
11199
+ }
11200
+ c *= invcontract;
11201
+ }
11202
+ if (minerr > breaktol * err || !isFinite(minerr))
11203
+ break;
11204
+ if (err <= Math.max(rtol * Math.abs(f0), atol))
11205
+ break;
11206
+ }
11207
+ return [f0, err];
11208
+ }
11095
11209
 
11096
11210
  // src/compute-engine/numerics/numeric.ts
11097
- var import_complex = __toESM(require_complex(), 1);
11098
11211
  var MACHINE_PRECISION_BITS = 53;
11099
11212
  var MACHINE_PRECISION = Math.log10(
11100
11213
  Math.pow(2, MACHINE_PRECISION_BITS)
@@ -12458,6 +12571,19 @@ var ComputeEngine = (() => {
12458
12571
  }
12459
12572
  return sum2 / n * (b - a);
12460
12573
  }
12574
+ function limit(f, x, dir = 1) {
12575
+ if (dir === 0) {
12576
+ const left = limit(f, x, -1);
12577
+ const right = limit(f, x, 1);
12578
+ if (left === void 0 || right === void 0)
12579
+ return NaN;
12580
+ if (Math.abs(left - right) > 1e-5)
12581
+ return NaN;
12582
+ return (left + right) / 2;
12583
+ }
12584
+ const [val, err] = extrapolate(f, x, { step: dir > 0 ? 1 : -1 });
12585
+ return val;
12586
+ }
12461
12587
 
12462
12588
  // src/compute-engine/numerics/numeric-bigint.ts
12463
12589
  function bigint(a) {
@@ -12778,7 +12904,7 @@ var ComputeEngine = (() => {
12778
12904
  }
12779
12905
 
12780
12906
  // src/compute-engine/boxed-expression/order.ts
12781
- var import_complex3 = __toESM(require_complex(), 1);
12907
+ var import_complex3 = __toESM(require_complex());
12782
12908
 
12783
12909
  // src/compute-engine/symbolic/polynomials.ts
12784
12910
  function totalDegree(expr) {
@@ -12988,7 +13114,7 @@ var ComputeEngine = (() => {
12988
13114
  }
12989
13115
 
12990
13116
  // src/compute-engine/numerics/rationals.ts
12991
- var import_complex4 = __toESM(require_complex(), 1);
13117
+ var import_complex4 = __toESM(require_complex());
12992
13118
  function isRational(x) {
12993
13119
  return x !== null && Array.isArray(x);
12994
13120
  }
@@ -13298,7 +13424,7 @@ var ComputeEngine = (() => {
13298
13424
  }
13299
13425
 
13300
13426
  // src/compute-engine/symbolic/sum.ts
13301
- var import_complex5 = __toESM(require_complex(), 1);
13427
+ var import_complex5 = __toESM(require_complex());
13302
13428
  var Sum = class {
13303
13429
  constructor(ce, xs, options) {
13304
13430
  // If `false`, the running sums are not calculated
@@ -13734,7 +13860,7 @@ var ComputeEngine = (() => {
13734
13860
  }
13735
13861
 
13736
13862
  // src/compute-engine/boxed-expression/abstract-boxed-expression.ts
13737
- var import_complex6 = __toESM(require_complex(), 1);
13863
+ var import_complex6 = __toESM(require_complex());
13738
13864
 
13739
13865
  // src/compute-engine/library/utils.ts
13740
13866
  function normalizeLimits(range) {
@@ -13805,6 +13931,7 @@ var ComputeEngine = (() => {
13805
13931
  Gcd: "_SYS.gcd",
13806
13932
  // Math.hypot
13807
13933
  Lcm: "_SYS.lcm",
13934
+ Limit: (args, compile2) => `_SYS.limit(${compile2(args[0])}, ${compile2(args[1])})`,
13808
13935
  Ln: "Math.log",
13809
13936
  Log: "Math.log10",
13810
13937
  LogGamma: "_SYS.lngamma",
@@ -13839,7 +13966,7 @@ var ComputeEngine = (() => {
13839
13966
  },
13840
13967
  Random: "Math.random",
13841
13968
  Round: "Math.round",
13842
- Sqaure: (args, compile2) => {
13969
+ Square: (args, compile2) => {
13843
13970
  const arg = args[0];
13844
13971
  if (arg === null)
13845
13972
  throw new Error("Square: no argument");
@@ -13950,7 +14077,8 @@ var ComputeEngine = (() => {
13950
14077
  lngamma: gammaln,
13951
14078
  gcd,
13952
14079
  lcm,
13953
- chop
14080
+ chop,
14081
+ limit
13954
14082
  };
13955
14083
  return new Proxy(this, {
13956
14084
  apply: (target, thisArg, argumentsList) => super.apply(thisArg, [this.sys, ...argumentsList]),
@@ -13997,7 +14125,9 @@ ${js}`);
13997
14125
  return void 0;
13998
14126
  },
13999
14127
  string: (str) => JSON.stringify(str),
14000
- number: (n) => n.toString()
14128
+ number: (n) => n.toString(),
14129
+ indent: 0,
14130
+ ws: (s) => s ?? ""
14001
14131
  });
14002
14132
  }
14003
14133
  function compileExpr(h, args, prec, target) {
@@ -14022,6 +14152,50 @@ ${js}`);
14022
14152
  }
14023
14153
  return op3[1] < prec ? `(${resultStr})` : resultStr;
14024
14154
  }
14155
+ if (h === "Function") {
14156
+ const params = args.slice(1).map((x) => x.symbol);
14157
+ return `((${params.join(", ")}) => ${compile(args[0], {
14158
+ ...target,
14159
+ var: (id) => params.includes(id) ? id : target.var(id)
14160
+ })})`;
14161
+ }
14162
+ if (h === "Declare")
14163
+ return `let ${args[0].symbol}`;
14164
+ if (h === "Assign")
14165
+ return `${args[0].symbol} = ${compile(args[1], target)}`;
14166
+ if (h === "Return")
14167
+ return `return ${compile(args[0], target)}`;
14168
+ if (h === "If") {
14169
+ if (args.length !== 3)
14170
+ throw new Error("If: wrong number of arguments");
14171
+ return `((${compile(args[0], target)}) ? (${compile(
14172
+ args[1],
14173
+ target
14174
+ )}) : (${compile(args[2], target)}))`;
14175
+ }
14176
+ if (h === "Block") {
14177
+ const locals = [];
14178
+ for (const arg of args) {
14179
+ if (arg.head === "Declare")
14180
+ locals.push(arg.ops[0].symbol);
14181
+ }
14182
+ if (args.length === 1 && locals.length === 0)
14183
+ return compile(args[0], target);
14184
+ const result = args.map(
14185
+ (arg) => compile(arg, {
14186
+ ...target,
14187
+ var: (id) => {
14188
+ if (locals.includes(id))
14189
+ return id;
14190
+ return target.var(id);
14191
+ }
14192
+ })
14193
+ );
14194
+ result[result.length - 1] = `return ${result[result.length - 1]}`;
14195
+ return `(() => {${target.ws("\n")}${result.join(
14196
+ `;${target.ws("\n")}`
14197
+ )}${target.ws("\n")}})()`;
14198
+ }
14025
14199
  const fn = target.functions?.(h);
14026
14200
  if (!fn)
14027
14201
  throw new Error(`Unknown function ${h}`);
@@ -14413,7 +14587,7 @@ ${js}`);
14413
14587
  compile(to = "javascript", options) {
14414
14588
  if (to !== "javascript")
14415
14589
  return void 0;
14416
- options ?? (options = { optimize: ["simplify", "evaluate"] });
14590
+ options ?? (options = { optimize: ["simplify"] });
14417
14591
  let expr = this;
14418
14592
  if (options.optimize.includes("simplify"))
14419
14593
  expr = expr.simplify();
@@ -14787,7 +14961,7 @@ ${js}`);
14787
14961
  }
14788
14962
 
14789
14963
  // src/compute-engine/symbolic/utils.ts
14790
- var import_complex7 = __toESM(require_complex(), 1);
14964
+ var import_complex7 = __toESM(require_complex());
14791
14965
  function makePositive(expr) {
14792
14966
  if (expr.head === "Negate")
14793
14967
  return [-1, expr.op1];
@@ -15342,7 +15516,7 @@ ${js}`);
15342
15516
  }
15343
15517
 
15344
15518
  // src/compute-engine/symbolic/negate.ts
15345
- var import_complex8 = __toESM(require_complex(), 1);
15519
+ var import_complex8 = __toESM(require_complex());
15346
15520
  function negateLiteral(expr, metadata) {
15347
15521
  let n = expr.numericValue;
15348
15522
  if (n === null)
@@ -15874,10 +16048,10 @@ ${js}`);
15874
16048
  }
15875
16049
 
15876
16050
  // src/compute-engine/boxed-expression/box.ts
15877
- var import_complex14 = __toESM(require_complex(), 1);
16051
+ var import_complex14 = __toESM(require_complex());
15878
16052
 
15879
16053
  // src/compute-engine/boxed-expression/serialize.ts
15880
- var import_complex10 = __toESM(require_complex(), 1);
16054
+ var import_complex10 = __toESM(require_complex());
15881
16055
 
15882
16056
  // src/compute-engine/numerics/numeric-bignum.ts
15883
16057
  function factorial3(ce, n) {
@@ -15993,7 +16167,7 @@ ${js}`);
15993
16167
  }
15994
16168
 
15995
16169
  // src/compute-engine/symbolic/product.ts
15996
- var import_complex9 = __toESM(require_complex(), 1);
16170
+ var import_complex9 = __toESM(require_complex());
15997
16171
  var Product = class {
15998
16172
  constructor(ce, xs, options) {
15999
16173
  this.options = options;
@@ -16932,7 +17106,7 @@ ${js}`);
16932
17106
  };
16933
17107
 
16934
17108
  // src/compute-engine/boxed-expression/boxed-function.ts
16935
- var import_complex11 = __toESM(require_complex(), 1);
17109
+ var import_complex11 = __toESM(require_complex());
16936
17110
 
16937
17111
  // src/compute-engine/simplify-rules.ts
16938
17112
  var SIMPLIFY_RULES = [];
@@ -17625,10 +17799,12 @@ ${js}`);
17625
17799
  const sig = def?.signature;
17626
17800
  if (!result && sig) {
17627
17801
  const numericMode = options?.numericMode ?? false;
17802
+ const context = this.engine.swapScope(this.scope);
17628
17803
  if (numericMode && sig.N)
17629
17804
  result = sig.N(this.engine, tail);
17630
17805
  if (!result && sig.evaluate)
17631
17806
  result = sig.evaluate(this.engine, tail);
17807
+ this.engine.swapScope(context);
17632
17808
  }
17633
17809
  if (result) {
17634
17810
  const num = result.numericValue;
@@ -17821,10 +17997,10 @@ ${js}`);
17821
17997
  }
17822
17998
 
17823
17999
  // src/compute-engine/boxed-expression/boxed-number.ts
17824
- var import_complex13 = __toESM(require_complex(), 1);
18000
+ var import_complex13 = __toESM(require_complex());
17825
18001
 
17826
18002
  // src/compute-engine/domain-utils.ts
17827
- var import_complex12 = __toESM(require_complex(), 1);
18003
+ var import_complex12 = __toESM(require_complex());
17828
18004
  function inferNumericDomain(value) {
17829
18005
  if (typeof value === "number" && !isNaN(value)) {
17830
18006
  if (!isFinite(value))
@@ -18111,7 +18287,12 @@ ${js}`);
18111
18287
  return false;
18112
18288
  }
18113
18289
  isEqual(rhs) {
18114
- return this.isSame(rhs);
18290
+ if (this === rhs)
18291
+ return true;
18292
+ if (!(rhs instanceof _BoxedNumber))
18293
+ return false;
18294
+ const s = signDiff(this, rhs);
18295
+ return s === 0;
18115
18296
  }
18116
18297
  match(rhs, options) {
18117
18298
  if (this.isEqualWithTolerance(rhs, options?.numericTolerance ?? 0))
@@ -18766,7 +18947,7 @@ ${js}`);
18766
18947
  }
18767
18948
 
18768
18949
  // src/compute-engine/library/arithmetic.ts
18769
- var import_complex16 = __toESM(require_complex(), 1);
18950
+ var import_complex16 = __toESM(require_complex());
18770
18951
 
18771
18952
  // src/compute-engine/numerics/numeric-complex.ts
18772
18953
  function gamma3(c) {
@@ -18777,7 +18958,7 @@ ${js}`);
18777
18958
  }
18778
18959
 
18779
18960
  // src/compute-engine/library/arithmetic-power.ts
18780
- var import_complex15 = __toESM(require_complex(), 1);
18961
+ var import_complex15 = __toESM(require_complex());
18781
18962
  function canonicalPower(ce, base, exponent, metadata) {
18782
18963
  if (exponent.symbol === "ComplexInfinity")
18783
18964
  return ce.NaN;
@@ -20192,21 +20373,7 @@ ${js}`);
20192
20373
  return ops2[0];
20193
20374
  return ce.fn("Max", ops2);
20194
20375
  },
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
- }
20376
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Max")
20210
20377
  }
20211
20378
  },
20212
20379
  Min: {
@@ -20216,26 +20383,42 @@ ${js}`);
20216
20383
  domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
20217
20384
  simplify: (ce, ops2) => {
20218
20385
  if (ops2.length === 0)
20219
- return ce.NegativeInfinity;
20386
+ return ce.PositiveInfinity;
20220
20387
  if (ops2.length === 1)
20221
20388
  return ops2[0];
20222
20389
  return ce.fn("Min", ops2);
20223
20390
  },
20224
- evaluate: (ce, ops2) => {
20391
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Min")
20392
+ }
20393
+ },
20394
+ Supremum: {
20395
+ description: "Like Max, but defined for open sets",
20396
+ complexity: 1200,
20397
+ signature: {
20398
+ domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
20399
+ simplify: (ce, ops2) => {
20225
20400
  if (ops2.length === 0)
20226
20401
  return ce.NegativeInfinity;
20227
- let result = void 0;
20228
- const rest = [];
20229
- for (const op3 of ops2) {
20230
- if (!op3.isNumber || op3.numericValue === void 0)
20231
- rest.push(op3);
20232
- else if (!result || op3.isLess(result))
20233
- result = op3;
20234
- }
20235
- if (rest.length > 0)
20236
- return ce.box(result ? ["Min", result, ...rest] : ["Min", ...rest]);
20237
- return result ?? ce.NaN;
20238
- }
20402
+ if (ops2.length === 1)
20403
+ return ops2[0];
20404
+ return ce.fn("Min", ops2);
20405
+ },
20406
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Supremum")
20407
+ }
20408
+ },
20409
+ Infimum: {
20410
+ description: "Like Min, but defined for open sets",
20411
+ complexity: 1200,
20412
+ signature: {
20413
+ domain: ["FunctionOf", ["VarArg", "Values"], "Numbers"],
20414
+ simplify: (ce, ops2) => {
20415
+ if (ops2.length === 0)
20416
+ return ce.PositiveInfinity;
20417
+ if (ops2.length === 1)
20418
+ return ops2[0];
20419
+ return ce.fn("Min", ops2);
20420
+ },
20421
+ evaluate: (ce, ops2) => processMinMax(ce, ops2, "Infimum")
20239
20422
  }
20240
20423
  },
20241
20424
  Product: {
@@ -20281,6 +20464,69 @@ ${js}`);
20281
20464
  evaluate: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "evaluate"),
20282
20465
  N: (ce, ops2) => evalSummation(ce, ops2[0], ops2[1], "N")
20283
20466
  }
20467
+ },
20468
+ // Limits
20469
+ Limit: {
20470
+ description: "Limit of a function",
20471
+ complexity: 5e3,
20472
+ hold: "all",
20473
+ signature: {
20474
+ domain: [
20475
+ "FunctionOf",
20476
+ "Anything",
20477
+ "Numbers",
20478
+ ["OptArg", "Numbers"],
20479
+ "Numbers"
20480
+ ],
20481
+ N: (ce, ops2) => {
20482
+ const [f, x, dir] = ops2;
20483
+ const target = asFloat(x.N());
20484
+ if (target === null)
20485
+ return void 0;
20486
+ const fn = applicable(f);
20487
+ return ce.number(
20488
+ limit(
20489
+ (x2) => {
20490
+ let y = fn([ce.number(x2)])?.valueOf();
20491
+ return typeof y === "number" ? y : Number.NaN;
20492
+ },
20493
+ target,
20494
+ dir ? asFloat(dir) ?? 1 : 1
20495
+ )
20496
+ );
20497
+ }
20498
+ }
20499
+ },
20500
+ NLimit: {
20501
+ description: "Numerical approximation of the limit of a function",
20502
+ complexity: 5e3,
20503
+ hold: "all",
20504
+ signature: {
20505
+ domain: [
20506
+ "FunctionOf",
20507
+ "Anything",
20508
+ "Numbers",
20509
+ ["OptArg", "Numbers"],
20510
+ "Numbers"
20511
+ ],
20512
+ evaluate: (ce, ops2) => {
20513
+ const [f, x, dir] = ops2;
20514
+ const target = asFloat(x.N());
20515
+ if (target === null)
20516
+ return void 0;
20517
+ const fn = applicable(f);
20518
+ return ce.number(
20519
+ limit(
20520
+ (x2) => {
20521
+ let y = fn([ce.number(x2)])?.valueOf();
20522
+ return typeof y === "number" ? y : Number.NaN;
20523
+ },
20524
+ target,
20525
+ dir ? asFloat(dir) ?? 1 : 1
20526
+ )
20527
+ );
20528
+ }
20529
+ }
20284
20530
  }
20285
20531
  },
20286
20532
  //
@@ -20387,6 +20633,24 @@ ${js}`);
20387
20633
  return ce.neg(arg);
20388
20634
  return void 0;
20389
20635
  }
20636
+ function processMinMax(ce, ops2, mode) {
20637
+ const upper = mode === "Max" || mode === "Supremum";
20638
+ if (ops2.length === 0)
20639
+ return upper ? ce.NegativeInfinity : ce.PositiveInfinity;
20640
+ let result = void 0;
20641
+ const rest = [];
20642
+ for (const op3 of ops2) {
20643
+ if (!op3.isNumber || op3.numericValue === void 0)
20644
+ rest.push(op3);
20645
+ else if (!result)
20646
+ result = op3;
20647
+ else if (upper && op3.isGreater(result) || !upper && op3.isLess(result))
20648
+ result = op3;
20649
+ }
20650
+ if (rest.length > 0)
20651
+ return ce.box(result ? [mode, result, ...rest] : [mode, ...rest]);
20652
+ return result ?? (upper ? ce.NegativeInfinity : ce.PositiveInfinity);
20653
+ }
20390
20654
 
20391
20655
  // src/compute-engine/symbolic/derivative.ts
20392
20656
  var DERIVATIVES_TABLE = {
@@ -20711,8 +20975,9 @@ ${js}`);
20711
20975
  const params = ops2.slice(1);
20712
20976
  f.bind();
20713
20977
  f = f.canonical;
20978
+ const result = ce._fn("D", [f, ...params]);
20714
20979
  ce.popScope();
20715
- return ce._fn("D", [f, ...params]);
20980
+ return result;
20716
20981
  },
20717
20982
  evaluate: (ce, ops2) => {
20718
20983
  let f = ops2[0].canonical;
@@ -21571,6 +21836,7 @@ ${js}`);
21571
21836
  var CONTROL_STRUCTURES_LIBRARY = [
21572
21837
  {
21573
21838
  Block: {
21839
+ hold: "all",
21574
21840
  signature: {
21575
21841
  domain: "Functions",
21576
21842
  canonical: canonicalBlock,
@@ -21672,33 +21938,37 @@ ${js}`);
21672
21938
  function evaluateBlock(ce, ops2) {
21673
21939
  if (ops2.length === 0)
21674
21940
  return ce.Nothing;
21941
+ ce.resetContext();
21675
21942
  let result = void 0;
21676
21943
  for (const op3 of ops2) {
21677
- result = op3.evaluate();
21678
- const h = result.head;
21679
- if (h === "Return" || h === "Break" || h === "Continue")
21944
+ const h = op3.head;
21945
+ if (h === "Return") {
21946
+ result = op3.op1.evaluate();
21680
21947
  break;
21948
+ }
21949
+ if (h === "Break" || h === "Continue") {
21950
+ result = ce.fn(h, [op3.op1.evaluate()]);
21951
+ break;
21952
+ }
21953
+ result = op3.evaluate();
21681
21954
  }
21682
21955
  return result ?? ce.Nothing;
21683
21956
  }
21684
21957
  function canonicalBlock(ce, ops2) {
21685
21958
  if (ops2.length === 0)
21686
21959
  return null;
21960
+ ce.pushScope();
21687
21961
  const declarations = [];
21688
21962
  const body = [];
21689
21963
  for (const op3 of ops2) {
21690
- if (op3.head === "Declare") {
21964
+ if (op3.head === "Declare")
21691
21965
  declarations.push(op3);
21692
- } else if (op3.head === "Assign") {
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
21966
+ else
21699
21967
  body.push(invalidateDeclare(op3));
21700
21968
  }
21701
- return ce._fn("Block", [...declarations, ...body]);
21969
+ const result = ce._fn("Block", [...declarations, ...body]);
21970
+ ce.popScope();
21971
+ return result;
21702
21972
  }
21703
21973
  function invalidateDeclare(expr) {
21704
21974
  if (expr.head === "Declare")
@@ -22063,7 +22333,8 @@ ${js}`);
22063
22333
  },
22064
22334
  // By definition, for arguments of the canonical expression of
22065
22335
  // `Hold` are not canonicalized.
22066
- canonical: (ce, args) => args.length !== 1 ? null : ce._fn("Hold", args)
22336
+ canonical: (ce, args) => args.length !== 1 ? null : ce._fn("Hold", args),
22337
+ evaluate: (ce, ops2) => ops2[0]
22067
22338
  }
22068
22339
  },
22069
22340
  HorizontalSpacing: {
@@ -22103,6 +22374,32 @@ ${js}`);
22103
22374
  evaluate: (_ce, ops2) => apply3(ops2[0], ops2.slice(1))
22104
22375
  }
22105
22376
  },
22377
+ Assign: {
22378
+ hold: "all",
22379
+ signature: {
22380
+ domain: ["FunctionOf", "Symbols", "Anything", "Anything"],
22381
+ canonical: (ce, args) => {
22382
+ if (args.length !== 2)
22383
+ return null;
22384
+ const op12 = args[0];
22385
+ const op22 = args[1];
22386
+ if (!op12.symbol)
22387
+ return null;
22388
+ if (op22.symbol)
22389
+ return ce._fn("Assign", args);
22390
+ return ce._fn("Assign", [op12, ce._fn("Hold", [op22])]);
22391
+ },
22392
+ evaluate: (ce, ops2) => {
22393
+ const op12 = ops2[0];
22394
+ const op22 = ops2[1];
22395
+ if (!op12.symbol)
22396
+ return ce.Nothing;
22397
+ const val = op22.evaluate();
22398
+ ce.assign(op12.symbol, val);
22399
+ return val;
22400
+ }
22401
+ }
22402
+ },
22106
22403
  Assume: {
22107
22404
  hold: "all",
22108
22405
  signature: {
@@ -22112,6 +22409,32 @@ ${js}`);
22112
22409
  },
22113
22410
  // @todo
22114
22411
  About: { signature: { domain: "Functions" } },
22412
+ Declare: {
22413
+ hold: "all",
22414
+ signature: {
22415
+ domain: ["FunctionOf", "Symbols", "Anything"],
22416
+ canonical: (ce, args) => {
22417
+ if (args.length !== 2)
22418
+ return null;
22419
+ const op12 = args[0];
22420
+ const op22 = args[1];
22421
+ if (!op12.symbol)
22422
+ return null;
22423
+ if (op22.symbol)
22424
+ return ce._fn("Declare", args);
22425
+ return ce._fn("Declare", [op12, ce._fn("Hold", [op22])]);
22426
+ },
22427
+ evaluate: (ce, ops2) => {
22428
+ const op12 = ops2[0];
22429
+ const op22 = ops2[1];
22430
+ if (!op12.symbol)
22431
+ return ce.Nothing;
22432
+ const val = op22.evaluate();
22433
+ ce.declare(op12.symbol, val);
22434
+ return val;
22435
+ }
22436
+ }
22437
+ },
22115
22438
  Domain: {
22116
22439
  /** Return the domain of an expression */
22117
22440
  signature: {
@@ -24218,7 +24541,7 @@ ${js}`);
24218
24541
  }
24219
24542
 
24220
24543
  // src/compute-engine/boxed-expression/boxed-symbol-definition.ts
24221
- var import_complex17 = __toESM(require_complex(), 1);
24544
+ var import_complex17 = __toESM(require_complex());
24222
24545
  var _BoxedSymbolDefinition = class {
24223
24546
  // @todo
24224
24547
  constructor(ce, name, def) {
@@ -25168,7 +25491,7 @@ ${JSON.stringify(entry)}`
25168
25491
  }
25169
25492
 
25170
25493
  // src/compute-engine/cost-function.ts
25171
- var import_complex19 = __toESM(require_complex(), 1);
25494
+ var import_complex19 = __toESM(require_complex());
25172
25495
  function numericCostFunction(n) {
25173
25496
  if (Number.isInteger(n) && n !== 0) {
25174
25497
  return Math.floor(Math.log2(Math.abs(n)) / Math.log2(10)) + (n > 0 ? 1 : 2);
@@ -25560,6 +25883,16 @@ ${JSON.stringify(entry)}`
25560
25883
  }
25561
25884
  if (!options.recursive)
25562
25885
  return null;
25886
+ if (subject.ops) {
25887
+ const ops2 = subject.ops;
25888
+ const result = {};
25889
+ for (let i = 0; i < ops2.length; i++) {
25890
+ const sub2 = match(ops2[i], pattern, options);
25891
+ if (sub2 !== null)
25892
+ return sub2;
25893
+ }
25894
+ return result;
25895
+ }
25563
25896
  return null;
25564
25897
  }
25565
25898
 
@@ -27325,10 +27658,10 @@ ${JSON.stringify(entry)}`
27325
27658
  };
27326
27659
 
27327
27660
  // src/compute-engine.ts
27328
- var version = "0.17.0";
27661
+ var version = "0.18.0";
27329
27662
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
27330
27663
  ComputeEngine: ComputeEngine.prototype.constructor,
27331
- version: "0.17.0"
27664
+ version: "0.18.0"
27332
27665
  };
27333
27666
  return __toCommonJS(compute_engine_exports);
27334
27667
  })();