@cortex-js/compute-engine 0.26.0 → 0.26.2

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 (139) hide show
  1. package/README.md +5 -8
  2. package/dist/compute-engine.esm.js +106 -58
  3. package/dist/compute-engine.js +106 -58
  4. package/dist/compute-engine.min.esm.js +37 -36
  5. package/dist/compute-engine.min.js +37 -36
  6. package/dist/math-json.esm.js +2 -2
  7. package/dist/math-json.js +2 -2
  8. package/dist/math-json.min.esm.js +2 -2
  9. package/dist/math-json.min.js +2 -2
  10. package/dist/types/common/ansi-codes.d.ts +1 -1
  11. package/dist/types/common/buffer.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/one-of.d.ts +1 -1
  14. package/dist/types/common/signals.d.ts +1 -1
  15. package/dist/types/common/styled-text.d.ts +1 -1
  16. package/dist/types/common/suggest.d.ts +1 -1
  17. package/dist/types/common/syntax-highlighter.d.ts +1 -1
  18. package/dist/types/common/terminal.d.ts +1 -1
  19. package/dist/types/common/type/parse.d.ts +1 -1
  20. package/dist/types/common/type/primitive.d.ts +1 -1
  21. package/dist/types/common/type/serialize.d.ts +1 -1
  22. package/dist/types/common/type/subtype.d.ts +1 -1
  23. package/dist/types/common/type/types.d.ts +1 -1
  24. package/dist/types/common/type/utils.d.ts +1 -1
  25. package/dist/types/common/utils.d.ts +1 -1
  26. package/dist/types/compute-engine/assume.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +2 -1
  28. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  30. package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +1 -1
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  33. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  34. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  35. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  36. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +2 -1
  38. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  39. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  40. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  41. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  43. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/negate.d.ts +2 -1
  53. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/public.d.ts +7 -2
  58. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/tensor-fields.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  68. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  69. package/dist/types/compute-engine/compile.d.ts +1 -1
  70. package/dist/types/compute-engine/compute-engine.d.ts +2 -2
  71. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  72. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  87. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  88. package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
  89. package/dist/types/compute-engine/latex-syntax/public.d.ts +3 -1
  90. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  93. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  94. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  95. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  96. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  97. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  98. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  99. package/dist/types/compute-engine/library/core.d.ts +1 -1
  100. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  101. package/dist/types/compute-engine/library/library.d.ts +1 -1
  102. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  103. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  104. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  105. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  106. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  107. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  108. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  109. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  110. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  111. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  112. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  113. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  114. package/dist/types/compute-engine/numeric-value/public.d.ts +1 -1
  115. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  116. package/dist/types/compute-engine/numerics/bignum.d.ts +1 -1
  117. package/dist/types/compute-engine/numerics/expression.d.ts +2 -2
  118. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  119. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  120. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  121. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  124. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  125. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/strings.d.ts +2 -2
  129. package/dist/types/compute-engine/public.d.ts +1 -1
  130. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  131. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  132. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  133. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  134. package/dist/types/compute-engine.d.ts +2 -2
  135. package/dist/types/math-json/identifiers.d.ts +1 -1
  136. package/dist/types/math-json/types.d.ts +1 -1
  137. package/dist/types/math-json/utils.d.ts +1 -1
  138. package/dist/types/math-json.d.ts +2 -2
  139. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.26.0 */
1
+ /** Compute Engine 0.26.2 */
2
2
  (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngine = {}));})(this, (function (exports) { 'use strict';
3
3
  var ComputeEngine = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -4053,6 +4053,7 @@ Invalid type
4053
4053
  function parseType(s) {
4054
4054
  if (s === void 0) return void 0;
4055
4055
  if (isValidType(s)) return s;
4056
+ if (typeof s !== "string") return void 0;
4056
4057
  if (PRIMITIVE_TYPES.includes(s)) return s;
4057
4058
  const parser = new TypeParser(s);
4058
4059
  return parser.parse();
@@ -4628,6 +4629,7 @@ Invalid type
4628
4629
  var ADDITION_PRECEDENCE = 275;
4629
4630
  var MULTIPLICATION_PRECEDENCE = 390;
4630
4631
  var DIVISION_PRECEDENCE = 600;
4632
+ var EXPONENTIATION_PRECEDENCE = 700;
4631
4633
  var POSTFIX_PRECEDENCE = 810;
4632
4634
  function isExpressionEntry(entry) {
4633
4635
  return !("kind" in entry) || entry.kind === "expression";
@@ -6489,20 +6491,20 @@ Invalid type
6489
6491
  if (def === void 0 || def === null || typeof def !== "object")
6490
6492
  return false;
6491
6493
  if (isBoxedExpression(def)) return false;
6492
- if ("type" in def || "value" in def || "constant" in def) {
6493
- if (typeof def.type === "function") {
6494
+ if ("value" in def || "constant" in def || "inferred" in def) {
6495
+ if ("type" in def && typeof def.type === "function") {
6494
6496
  throw new Error(
6495
- "The type field of a symbol definition should be a type string"
6497
+ "The `type` field of a symbol definition should be of type `string`"
6496
6498
  );
6497
6499
  }
6498
6500
  if ("signature" in def) {
6499
6501
  throw new Error(
6500
- "Symbol definition cannot have a signature field. Use a type field instead."
6502
+ "Symbol definition cannot have a `signature` field. Use a `type` field instead."
6501
6503
  );
6502
6504
  }
6503
6505
  if ("sgn" in def) {
6504
6506
  throw new Error(
6505
- "Symbol definition cannot have a sgn field. Use a flags field instead."
6507
+ "Symbol definition cannot have a `sgn` field. Use a `flags.sgn` field instead."
6506
6508
  );
6507
6509
  }
6508
6510
  return true;
@@ -6516,22 +6518,23 @@ Invalid type
6516
6518
  if ("signature" in def || "complexity" in def) {
6517
6519
  if ("constant" in def) {
6518
6520
  throw new Error(
6519
- "Function definition cannot have a constant field and symbol definition cannot have a signature field."
6521
+ "Function definition cannot have a `constant` field and symbol definition cannot have a `signature` field."
6520
6522
  );
6521
6523
  }
6522
- if ("type" in def && typeof def.type !== "function") {
6523
- throw new Error(
6524
- "The type field of a function definition should be a function"
6525
- );
6526
- }
6527
- if ("sgn" in def && typeof def.sgn !== "function") {
6528
- throw new Error(
6529
- "The sgn field of a function definition should be a function"
6530
- );
6531
- }
6532
- return true;
6533
6524
  }
6534
- return false;
6525
+ if (!("evaluate" in def) && !("signature" in def) && !("sgn" in def) && !("complexity" in def) && !("canonical" in def))
6526
+ return false;
6527
+ if ("type" in def && typeof def.type !== "function") {
6528
+ throw new Error(
6529
+ "The `type` field of a function definition should be a function"
6530
+ );
6531
+ }
6532
+ if ("sgn" in def && typeof def.sgn !== "function") {
6533
+ throw new Error(
6534
+ "The `sgn` field of a function definition should be a function"
6535
+ );
6536
+ }
6537
+ return true;
6535
6538
  }
6536
6539
  function semiCanonical(ce, xs) {
6537
6540
  if (!xs.every((x) => isBoxedExpression(x))) return xs.map((x) => ce.box(x));
@@ -7533,7 +7536,9 @@ Invalid type
7533
7536
  }
7534
7537
  return [value, ""];
7535
7538
  }
7536
- function numberToString(num) {
7539
+ function numberToString(num, fractionalDigits) {
7540
+ if (typeof fractionalDigits === "number" && typeof num === "number")
7541
+ return num.toFixed(fractionalDigits);
7537
7542
  const numStr = num.toString();
7538
7543
  if (typeof num === "number" && Number.isInteger(num) && numStr.includes("e")) {
7539
7544
  const fixedStr = BigInt(num).toString();
@@ -7565,11 +7570,13 @@ Invalid type
7565
7570
  if (s === "-infinity") return null;
7566
7571
  return bigint(s);
7567
7572
  }
7568
- function numberToExpression(num) {
7573
+ function numberToExpression(num, fractionalDigits) {
7569
7574
  if (typeof num === "number") {
7570
7575
  if (isNaN(num)) return "NaN";
7571
7576
  if (!Number.isFinite(num))
7572
7577
  return num < 0 ? "NegativeInfinity" : "PositiveInfinity";
7578
+ if (typeof fractionalDigits === "number")
7579
+ return { num: num.toFixed(fractionalDigits) };
7573
7580
  return num;
7574
7581
  }
7575
7582
  if (num >= Number.MIN_SAFE_INTEGER && num <= Number.MAX_SAFE_INTEGER)
@@ -7703,7 +7710,7 @@ Invalid type
7703
7710
  return result.mul(this.bignum(this.radical).sqrt());
7704
7711
  }
7705
7712
  get numerator() {
7706
- if (this.rational[1] === 1) return this;
7713
+ if (this.rational[1] == 1) return this;
7707
7714
  return this.clone({
7708
7715
  rational: isMachineRational(this.rational) ? [this.rational[0], 1] : [this.rational[0], BigInt(1)],
7709
7716
  radical: this.radical
@@ -7745,10 +7752,10 @@ Invalid type
7745
7752
  return Number.isNaN(this.rational[0]);
7746
7753
  }
7747
7754
  get isPositiveInfinity() {
7748
- return this.rational[0] === Infinity;
7755
+ return this.rational[0] == Infinity;
7749
7756
  }
7750
7757
  get isNegativeInfinity() {
7751
- return this.rational[0] === -Infinity;
7758
+ return this.rational[0] == -Infinity;
7752
7759
  }
7753
7760
  get isComplexInfinity() {
7754
7761
  return false;
@@ -7890,7 +7897,7 @@ Invalid type
7890
7897
  exponent = { re: exponent.re, im: exponent.im };
7891
7898
  } else {
7892
7899
  if (exponent instanceof _ExactNumericValue) {
7893
- if (exponent.radical === 1 && exponent.rational[0] === 1)
7900
+ if (exponent.radical === 1 && exponent.rational[0] == 1)
7894
7901
  return this.root(exponent.rational[0]);
7895
7902
  }
7896
7903
  exponent = exponent.re;
@@ -7972,7 +7979,7 @@ Invalid type
7972
7979
  return this.factory({ im: Math.pow(-this.re, 1 / exponent) });
7973
7980
  if (this.radical > SMALL_INTEGER || this.rational[0] > SMALL_INTEGER || this.rational[0] < -SMALL_INTEGER || this.rational[1] > SMALL_INTEGER)
7974
7981
  return this.factory(this.bignumRe).root(exponent);
7975
- if (this.rational[1] === 1) {
7982
+ if (this.rational[1] == 1) {
7976
7983
  const root2 = Math.pow(this.rational[0], 1 / exponent);
7977
7984
  if (Number.isInteger(root2)) return this.clone(root2);
7978
7985
  }
@@ -8038,7 +8045,7 @@ Invalid type
8038
8045
  }
8039
8046
  eq(other) {
8040
8047
  if (typeof other === "number")
8041
- return this.radical === 1 && isInteger(this.rational) && this.rational[0] === other;
8048
+ return this.radical === 1 && isInteger(this.rational) && this.rational[0] == other;
8042
8049
  if (other instanceof _ExactNumericValue) {
8043
8050
  return this.radical === other.radical && this.rational[0] == other.rational[0] && this.rational[1] == other.rational[1];
8044
8051
  }
@@ -8202,7 +8209,7 @@ Invalid type
8202
8209
  // src/compute-engine/boxed-expression/polynomials.ts
8203
8210
  function totalDegree(expr) {
8204
8211
  if (expr.symbol && !expr.isConstant) return 1;
8205
- if (expr.operator === "Power" && expr.op2.numericValue !== null) {
8212
+ if (expr.operator === "Power" && expr.op2.isNumberLiteral) {
8206
8213
  if (totalDegree(expr.op1) === 0) return 0;
8207
8214
  const deg = asSmallInteger(expr.op2);
8208
8215
  if (deg !== null && deg > 0) return deg;
@@ -8227,7 +8234,7 @@ Invalid type
8227
8234
  }
8228
8235
  function maxDegree(expr) {
8229
8236
  if (expr.symbol && !expr.isConstant) return 1;
8230
- if (expr.operator === "Power" && expr.op2.numericValue !== null) {
8237
+ if (expr.operator === "Power" && expr.op2.isNumberLiteral) {
8231
8238
  if (maxDegree(expr.op1) === 0) return 0;
8232
8239
  const deg = asSmallInteger(expr.op2);
8233
8240
  if (deg !== null && deg > 0) return deg;
@@ -9536,6 +9543,16 @@ Invalid type
9536
9543
  }
9537
9544
 
9538
9545
  // src/compute-engine/boxed-expression/negate.ts
9546
+ function canonicalNegate(expr) {
9547
+ let sign2 = -1;
9548
+ while (expr.operator === "Negate") {
9549
+ expr = expr.op1;
9550
+ sign2 = -sign2;
9551
+ }
9552
+ if (sign2 === 1) return expr;
9553
+ if (expr.isNumberLiteral) return expr.neg();
9554
+ return expr.engine._fn("Negate", [expr]);
9555
+ }
9539
9556
  function negate(expr) {
9540
9557
  let sign2 = -1;
9541
9558
  while (expr.operator === "Negate") {
@@ -9548,9 +9565,7 @@ Invalid type
9548
9565
  if (expr.operator === "Subtract") return expr.op2.sub(expr.op1);
9549
9566
  if (expr.operator === "Add") return add3(...expr.ops.map((x) => negate(x)));
9550
9567
  if (expr.operator === "Multiply") return negateProduct(ce, expr.ops);
9551
- if (expr.operator === "Divide") {
9552
- return negate(expr.op1).div(expr.op2);
9553
- }
9568
+ if (expr.operator === "Divide") return negate(expr.op1).div(expr.op2);
9554
9569
  return ce._fn("Negate", [expr]);
9555
9570
  }
9556
9571
  function negateProduct(ce, args) {
@@ -13072,7 +13087,7 @@ Invalid type
13072
13087
  sgn: ([x]) => x.isNonNegative ? "positive" : x.isNegative || x.isReal === false ? "unsigned" : void 0,
13073
13088
  canonical: (args, { engine }) => {
13074
13089
  const x = args[0];
13075
- if (x.numericValue !== null && x.isNegative)
13090
+ if (x.isNumberLiteral && x.isNegative)
13076
13091
  return engine._fn("Factorial", [x.neg()]).neg();
13077
13092
  return engine._fn("Factorial", [x]);
13078
13093
  },
@@ -18155,6 +18170,9 @@ ${e.message}`);
18155
18170
  fractionalPart += lastDigit;
18156
18171
  while (fractionalPart.endsWith("0"))
18157
18172
  fractionalPart = fractionalPart.slice(0, -1);
18173
+ if (typeof options.fractionalDigits === "number") {
18174
+ fractionalPart = fractionalPart.slice(0, options.fractionalDigits);
18175
+ }
18158
18176
  if (exponent)
18159
18177
  return `${wholepart}.${fractionalPart}${exponent.toLowerCase()}`;
18160
18178
  return `${wholepart}.${fractionalPart}`;
@@ -18309,7 +18327,7 @@ ${e.message}`);
18309
18327
  metadata.latex = metadata.latex ?? ce.box({ num: value.toString() }).latex;
18310
18328
  if (metadata.latex !== void 0)
18311
18329
  return { num: value.toString(), latex: metadata.latex };
18312
- return shorthandAllowed ? numberToExpression(value) : { num: numberToString(value) };
18330
+ return shorthandAllowed ? numberToExpression(value, options.fractionalDigits) : { num: numberToString(value, options.fractionalDigits) };
18313
18331
  }
18314
18332
  }
18315
18333
  let result;
@@ -18471,6 +18489,8 @@ ${e.message}`);
18471
18489
  }
18472
18490
  if (options.fractionalDigits === "auto")
18473
18491
  defaultOptions.fractionalDigits = -this.engine.precision;
18492
+ if (typeof options.fractionalDigits === "number")
18493
+ defaultOptions.fractionalDigits = options.fractionalDigits;
18474
18494
  }
18475
18495
  const opts = {
18476
18496
  ...defaultOptions,
@@ -18527,6 +18547,7 @@ ${e.message}`);
18527
18547
  };
18528
18548
  if (options?.fractionalDigits === "auto")
18529
18549
  effectiveOptions.fractionalDigits = -this.engine.precision;
18550
+ else effectiveOptions.fractionalDigits = options?.fractionalDigits ?? "max";
18530
18551
  if (typeof effectiveOptions.fractionalDigits === "number" && effectiveOptions.fractionalDigits > this.engine.precision)
18531
18552
  effectiveOptions.fractionalDigits = this.engine.precision;
18532
18553
  effectiveOptions = {
@@ -18655,7 +18676,7 @@ ${e.message}`);
18655
18676
  return null;
18656
18677
  }
18657
18678
  get isNumberLiteral() {
18658
- return this.numericValue !== null;
18679
+ return false;
18659
18680
  }
18660
18681
  get isFunctionExpression() {
18661
18682
  return false;
@@ -18828,6 +18849,9 @@ ${e.message}`);
18828
18849
  simplify(_options) {
18829
18850
  return this;
18830
18851
  }
18852
+ expand() {
18853
+ return expand2(this) ?? this;
18854
+ }
18831
18855
  evaluate(_options) {
18832
18856
  return this.simplify();
18833
18857
  }
@@ -21324,7 +21348,7 @@ ${e.message}`);
21324
21348
  return expr.engine._fn(expr.operator, expr.ops.map(invisibleOperatorForm));
21325
21349
  }
21326
21350
  function numberForm(expr) {
21327
- if (expr.numericValue !== null) return expr.canonical;
21351
+ if (expr.isNumberLiteral) return expr.canonical;
21328
21352
  if (expr.ops) return expr.engine._fn(expr.operator, expr.ops.map(numberForm));
21329
21353
  return expr;
21330
21354
  }
@@ -21455,10 +21479,10 @@ ${e.message}`);
21455
21479
  if (typeof op1 === "number") return ce.number(-op1, options);
21456
21480
  if (op1 instanceof Decimal) return ce.number(op1.neg(), options);
21457
21481
  const boxedop1 = ce.box(op1, options);
21458
- ops = [boxedop1];
21459
21482
  const num = boxedop1.numericValue;
21460
21483
  if (num !== null)
21461
21484
  return ce.number(typeof num === "number" ? -num : num.neg(), options);
21485
+ ops = [boxedop1];
21462
21486
  }
21463
21487
  }
21464
21488
  if (options.canonical === true)
@@ -21607,7 +21631,7 @@ ${e.message}`);
21607
21631
  } else return null;
21608
21632
  if (!ops.every((x) => x.isValid)) return ce._fn(name, ops, metadata);
21609
21633
  if (name === "Add") return canonicalAdd(ce, ops);
21610
- if (name === "Negate") return ops[0].neg();
21634
+ if (name === "Negate") return canonicalNegate(ops[0]);
21611
21635
  if (name === "Multiply") return canonicalMultiply(ce, ops);
21612
21636
  if (name === "Divide") {
21613
21637
  if (ops.length === 2)
@@ -21825,7 +21849,7 @@ ${e.message}`);
21825
21849
  function differentiate(expr, v) {
21826
21850
  const ce = expr.engine;
21827
21851
  if (expr.string) return void 0;
21828
- if (expr.numericValue !== null) return expr.engine.Zero;
21852
+ if (expr.isNumberLiteral) return expr.engine.Zero;
21829
21853
  if (expr.symbol === v) return expr.engine.One;
21830
21854
  if (expr.symbol) return expr.engine.Zero;
21831
21855
  if (!expr.operator) return void 0;
@@ -23435,8 +23459,10 @@ ${e.message}`);
23435
23459
  evaluate: evaluateImplies
23436
23460
  },
23437
23461
  Exists: { signature: "function", hold: true },
23462
+ NotExists: { signature: "function", hold: true },
23438
23463
  ExistsUnique: { signature: "function", hold: true },
23439
23464
  ForAll: { signature: "function", hold: true },
23465
+ NotForAll: { signature: "function", hold: true },
23440
23466
  KroneckerDelta: {
23441
23467
  description: "Return 1 if the arguments are equal, 0 otherwise",
23442
23468
  signature: "(value, ...value) -> integer",
@@ -25296,6 +25322,9 @@ Error in definition of "${name}"`,
25296
25322
  get numericValue() {
25297
25323
  return this._value;
25298
25324
  }
25325
+ get isNumberLiteral() {
25326
+ return true;
25327
+ }
25299
25328
  get re() {
25300
25329
  if (typeof this._value === "number") return this._value;
25301
25330
  return this._value.re;
@@ -25675,12 +25704,10 @@ Error in definition of "${name}"`,
25675
25704
  }
25676
25705
  const n = bigint(s);
25677
25706
  if (n !== null) {
25678
- if (n >= Number.MIN_SAFE_INTEGER && n <= Number.MAX_SAFE_INTEGER)
25679
- return Number(n);
25707
+ if (n >= -SMALL_INTEGER && n <= SMALL_INTEGER) return Number(n);
25680
25708
  return ce._numericValue(n);
25681
25709
  }
25682
- const b = ce.bignum(s);
25683
- return isInMachineRange(b) ? b.toNumber() : ce._numericValue(b);
25710
+ return ce._numericValue(ce.bignum(s));
25684
25711
  }
25685
25712
 
25686
25713
  // src/compute-engine/boxed-expression/boxed-symbol.ts
@@ -27039,14 +27066,12 @@ Error in definition of "${name}"`,
27039
27066
  name: "Negate",
27040
27067
  latexTrigger: ["-"],
27041
27068
  kind: "prefix",
27042
- precedence: ADDITION_PRECEDENCE + 2,
27069
+ precedence: EXPONENTIATION_PRECEDENCE + 1,
27043
27070
  parse: (parser, terminator) => {
27044
27071
  parser.skipSpace();
27045
- if (/\d/.test(parser.peek)) return null;
27046
- if (parser.parseNumber() !== null) return null;
27047
27072
  const rhs = parser.parseExpression({
27048
27073
  ...terminator,
27049
- minPrec: ADDITION_PRECEDENCE + 3
27074
+ minPrec: EXPONENTIATION_PRECEDENCE + 3
27050
27075
  });
27051
27076
  if (rhs === null) return null;
27052
27077
  return ["Negate", rhs];
@@ -27137,7 +27162,7 @@ Error in definition of "${name}"`,
27137
27162
  latexTrigger: ["^"],
27138
27163
  kind: "infix",
27139
27164
  serialize: serializePower
27140
- // Parsing is done as a special case in `parseExpression`
27165
+ // Parsing is done as a special case in `parseSupsub`
27141
27166
  },
27142
27167
  {
27143
27168
  latexTrigger: "\\prod",
@@ -27861,6 +27886,24 @@ Error in definition of "${name}"`,
27861
27886
  serialize: "\\exists!",
27862
27887
  parse: parseQuantifier("ExistsUnique")
27863
27888
  },
27889
+ {
27890
+ name: "NotForAll",
27891
+ kind: "prefix",
27892
+ latexTrigger: ["\\lnot", "\\forall"],
27893
+ precedence: 200,
27894
+ // Has to be lower than COMPARISON_PRECEDENCE
27895
+ serialize: "\\lnot\\forall",
27896
+ parse: parseQuantifier("NotForAll")
27897
+ },
27898
+ {
27899
+ name: "NotExists",
27900
+ kind: "prefix",
27901
+ latexTrigger: ["\\lnot", "\\exists"],
27902
+ precedence: 200,
27903
+ // Has to be lower than COMPARISON_PRECEDENCE,
27904
+ serialize: "\\lnot\\exists",
27905
+ parse: parseQuantifier("NotExists")
27906
+ },
27864
27907
  {
27865
27908
  name: "KroneckerDelta",
27866
27909
  kind: "prefix",
@@ -27928,14 +27971,11 @@ Error in definition of "${name}"`,
27928
27971
  if (id) {
27929
27972
  parser.skipSpace();
27930
27973
  if (parser.match(",") || parser.match("\\mid") || parser.match(".") || parser.match(":") || parser.match("\\colon")) {
27931
- const body = parser.parseExpression(terminator);
27932
- return [kind, id, missingIfEmpty(body)];
27933
- }
27934
- if (parser.match("(")) {
27935
- const body = parser.parseExpression(terminator);
27936
- if (!parser.match(")")) return null;
27937
- return [kind, id, missingIfEmpty(body)];
27974
+ const body2 = parser.parseExpression(terminator);
27975
+ return [kind, id, missingIfEmpty(body2)];
27938
27976
  }
27977
+ const body = parser.parseEnclosure();
27978
+ if (body) return [kind, id, missingIfEmpty(body)];
27939
27979
  }
27940
27980
  parser.index = index;
27941
27981
  const condition = parser.parseExpression(terminator);
@@ -33251,11 +33291,19 @@ Invalid definition for ${id}`, err.message].join("\n| ") + "\n"
33251
33291
  {
33252
33292
  const type2 = parseType(def);
33253
33293
  if (!isValidType(type2)) {
33294
+ if (typeof def === "object" && "N" in def) {
33295
+ throw Error(
33296
+ [
33297
+ `Invalid argument for "${id}"`,
33298
+ "Use `evaluate` handler instead of `N`"
33299
+ ].join("\n| ")
33300
+ );
33301
+ }
33254
33302
  throw Error(
33255
33303
  [
33256
33304
  `Invalid argument for "${id}"`,
33257
33305
  def.toString(),
33258
- `Use a type, a FunctionDefinition or a SymbolDefinition`
33306
+ `Use a type, a \`FunctionDefinition\` or a \`SymbolDefinition\``
33259
33307
  ].join("\n| ")
33260
33308
  );
33261
33309
  }
@@ -34346,10 +34394,10 @@ ${lineNo.toString().padStart(maxDigits, " ")}`;
34346
34394
  }
34347
34395
 
34348
34396
  // src/compute-engine.ts
34349
- var version = "0.26.0";
34397
+ var version = "0.26.2";
34350
34398
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
34351
34399
  ComputeEngine: ComputeEngine.prototype.constructor,
34352
- version: "0.26.0"
34400
+ version: "0.26.2"
34353
34401
  };
34354
34402
  return __toCommonJS(compute_engine_exports);
34355
34403
  })();