@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
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  notation interchange format based on JSON.
10
10
 
11
11
  The Cortex Compute Engine can parse LaTeX to MathJSON, serialize MathJSON to
12
- LaTeX, format, simplify and evaluate MathJSON expressions.
12
+ LaTeX or MathASCII, format, simplify and evaluate MathJSON expressions.
13
13
 
14
14
  Reference documentation and guides at
15
15
  [cortexjs.io/compute-engine](https://cortexjs.io/compute-engine/).
@@ -23,15 +23,12 @@ $ npm install --save @cortex-js/compute-engine
23
23
  ```
24
24
 
25
25
  ```js
26
- import { parse, evaluate } from "@cortex-js/compute-engine";
26
+ import { ComputeEngine } from "@cortex-js/compute-engine";
27
27
 
28
- const expr = parse("2^{11}-1 \\in \\P");
28
+ const ce = new ComputeEngine();
29
29
 
30
- console.log(expr);
31
- // ➔ ["Element", ["Subtract", ["Power", 2, 11] , 1], "PrimeNumber"]
32
-
33
- console.log(evaluate(expr));
34
- // ➔ "False"
30
+ engine.parse("2^{11}-1 \\in \\Z").evaluate().print()
31
+ // ➔ "True"
35
32
  ```
36
33
 
37
34
  ## More
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.26.0 */
1
+ /** Compute Engine 0.26.2 */
2
2
 
3
3
  // src/compute-engine/boxed-expression/public.ts
4
4
  function isRuleStep(x) {
@@ -4022,6 +4022,7 @@ Invalid type
4022
4022
  function parseType(s) {
4023
4023
  if (s === void 0) return void 0;
4024
4024
  if (isValidType(s)) return s;
4025
+ if (typeof s !== "string") return void 0;
4025
4026
  if (PRIMITIVE_TYPES.includes(s)) return s;
4026
4027
  const parser = new TypeParser(s);
4027
4028
  return parser.parse();
@@ -4597,6 +4598,7 @@ var ARROW_PRECEDENCE = 270;
4597
4598
  var ADDITION_PRECEDENCE = 275;
4598
4599
  var MULTIPLICATION_PRECEDENCE = 390;
4599
4600
  var DIVISION_PRECEDENCE = 600;
4601
+ var EXPONENTIATION_PRECEDENCE = 700;
4600
4602
  var POSTFIX_PRECEDENCE = 810;
4601
4603
  function isExpressionEntry(entry) {
4602
4604
  return !("kind" in entry) || entry.kind === "expression";
@@ -6458,20 +6460,20 @@ function isSymbolDefinition(def) {
6458
6460
  if (def === void 0 || def === null || typeof def !== "object")
6459
6461
  return false;
6460
6462
  if (isBoxedExpression(def)) return false;
6461
- if ("type" in def || "value" in def || "constant" in def) {
6462
- if (typeof def.type === "function") {
6463
+ if ("value" in def || "constant" in def || "inferred" in def) {
6464
+ if ("type" in def && typeof def.type === "function") {
6463
6465
  throw new Error(
6464
- "The type field of a symbol definition should be a type string"
6466
+ "The `type` field of a symbol definition should be of type `string`"
6465
6467
  );
6466
6468
  }
6467
6469
  if ("signature" in def) {
6468
6470
  throw new Error(
6469
- "Symbol definition cannot have a signature field. Use a type field instead."
6471
+ "Symbol definition cannot have a `signature` field. Use a `type` field instead."
6470
6472
  );
6471
6473
  }
6472
6474
  if ("sgn" in def) {
6473
6475
  throw new Error(
6474
- "Symbol definition cannot have a sgn field. Use a flags field instead."
6476
+ "Symbol definition cannot have a `sgn` field. Use a `flags.sgn` field instead."
6475
6477
  );
6476
6478
  }
6477
6479
  return true;
@@ -6485,22 +6487,23 @@ function isFunctionDefinition(def) {
6485
6487
  if ("signature" in def || "complexity" in def) {
6486
6488
  if ("constant" in def) {
6487
6489
  throw new Error(
6488
- "Function definition cannot have a constant field and symbol definition cannot have a signature field."
6490
+ "Function definition cannot have a `constant` field and symbol definition cannot have a `signature` field."
6489
6491
  );
6490
6492
  }
6491
- if ("type" in def && typeof def.type !== "function") {
6492
- throw new Error(
6493
- "The type field of a function definition should be a function"
6494
- );
6495
- }
6496
- if ("sgn" in def && typeof def.sgn !== "function") {
6497
- throw new Error(
6498
- "The sgn field of a function definition should be a function"
6499
- );
6500
- }
6501
- return true;
6502
6493
  }
6503
- return false;
6494
+ if (!("evaluate" in def) && !("signature" in def) && !("sgn" in def) && !("complexity" in def) && !("canonical" in def))
6495
+ return false;
6496
+ if ("type" in def && typeof def.type !== "function") {
6497
+ throw new Error(
6498
+ "The `type` field of a function definition should be a function"
6499
+ );
6500
+ }
6501
+ if ("sgn" in def && typeof def.sgn !== "function") {
6502
+ throw new Error(
6503
+ "The `sgn` field of a function definition should be a function"
6504
+ );
6505
+ }
6506
+ return true;
6504
6507
  }
6505
6508
  function semiCanonical(ce, xs) {
6506
6509
  if (!xs.every((x) => isBoxedExpression(x))) return xs.map((x) => ce.box(x));
@@ -7502,7 +7505,9 @@ function fromDigits(s, baseInput) {
7502
7505
  }
7503
7506
  return [value, ""];
7504
7507
  }
7505
- function numberToString(num) {
7508
+ function numberToString(num, fractionalDigits) {
7509
+ if (typeof fractionalDigits === "number" && typeof num === "number")
7510
+ return num.toFixed(fractionalDigits);
7506
7511
  const numStr = num.toString();
7507
7512
  if (typeof num === "number" && Number.isInteger(num) && numStr.includes("e")) {
7508
7513
  const fixedStr = BigInt(num).toString();
@@ -7534,11 +7539,13 @@ function bigintValue(expr) {
7534
7539
  if (s === "-infinity") return null;
7535
7540
  return bigint(s);
7536
7541
  }
7537
- function numberToExpression(num) {
7542
+ function numberToExpression(num, fractionalDigits) {
7538
7543
  if (typeof num === "number") {
7539
7544
  if (isNaN(num)) return "NaN";
7540
7545
  if (!Number.isFinite(num))
7541
7546
  return num < 0 ? "NegativeInfinity" : "PositiveInfinity";
7547
+ if (typeof fractionalDigits === "number")
7548
+ return { num: num.toFixed(fractionalDigits) };
7542
7549
  return num;
7543
7550
  }
7544
7551
  if (num >= Number.MIN_SAFE_INTEGER && num <= Number.MAX_SAFE_INTEGER)
@@ -7672,7 +7679,7 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
7672
7679
  return result.mul(this.bignum(this.radical).sqrt());
7673
7680
  }
7674
7681
  get numerator() {
7675
- if (this.rational[1] === 1) return this;
7682
+ if (this.rational[1] == 1) return this;
7676
7683
  return this.clone({
7677
7684
  rational: isMachineRational(this.rational) ? [this.rational[0], 1] : [this.rational[0], BigInt(1)],
7678
7685
  radical: this.radical
@@ -7714,10 +7721,10 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
7714
7721
  return Number.isNaN(this.rational[0]);
7715
7722
  }
7716
7723
  get isPositiveInfinity() {
7717
- return this.rational[0] === Infinity;
7724
+ return this.rational[0] == Infinity;
7718
7725
  }
7719
7726
  get isNegativeInfinity() {
7720
- return this.rational[0] === -Infinity;
7727
+ return this.rational[0] == -Infinity;
7721
7728
  }
7722
7729
  get isComplexInfinity() {
7723
7730
  return false;
@@ -7859,7 +7866,7 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
7859
7866
  exponent = { re: exponent.re, im: exponent.im };
7860
7867
  } else {
7861
7868
  if (exponent instanceof _ExactNumericValue) {
7862
- if (exponent.radical === 1 && exponent.rational[0] === 1)
7869
+ if (exponent.radical === 1 && exponent.rational[0] == 1)
7863
7870
  return this.root(exponent.rational[0]);
7864
7871
  }
7865
7872
  exponent = exponent.re;
@@ -7941,7 +7948,7 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
7941
7948
  return this.factory({ im: Math.pow(-this.re, 1 / exponent) });
7942
7949
  if (this.radical > SMALL_INTEGER || this.rational[0] > SMALL_INTEGER || this.rational[0] < -SMALL_INTEGER || this.rational[1] > SMALL_INTEGER)
7943
7950
  return this.factory(this.bignumRe).root(exponent);
7944
- if (this.rational[1] === 1) {
7951
+ if (this.rational[1] == 1) {
7945
7952
  const root2 = Math.pow(this.rational[0], 1 / exponent);
7946
7953
  if (Number.isInteger(root2)) return this.clone(root2);
7947
7954
  }
@@ -8007,7 +8014,7 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
8007
8014
  }
8008
8015
  eq(other) {
8009
8016
  if (typeof other === "number")
8010
- return this.radical === 1 && isInteger(this.rational) && this.rational[0] === other;
8017
+ return this.radical === 1 && isInteger(this.rational) && this.rational[0] == other;
8011
8018
  if (other instanceof _ExactNumericValue) {
8012
8019
  return this.radical === other.radical && this.rational[0] == other.rational[0] && this.rational[1] == other.rational[1];
8013
8020
  }
@@ -8171,7 +8178,7 @@ function asSmallInteger(expr) {
8171
8178
  // src/compute-engine/boxed-expression/polynomials.ts
8172
8179
  function totalDegree(expr) {
8173
8180
  if (expr.symbol && !expr.isConstant) return 1;
8174
- if (expr.operator === "Power" && expr.op2.numericValue !== null) {
8181
+ if (expr.operator === "Power" && expr.op2.isNumberLiteral) {
8175
8182
  if (totalDegree(expr.op1) === 0) return 0;
8176
8183
  const deg = asSmallInteger(expr.op2);
8177
8184
  if (deg !== null && deg > 0) return deg;
@@ -8196,7 +8203,7 @@ function totalDegree(expr) {
8196
8203
  }
8197
8204
  function maxDegree(expr) {
8198
8205
  if (expr.symbol && !expr.isConstant) return 1;
8199
- if (expr.operator === "Power" && expr.op2.numericValue !== null) {
8206
+ if (expr.operator === "Power" && expr.op2.isNumberLiteral) {
8200
8207
  if (maxDegree(expr.op1) === 0) return 0;
8201
8208
  const deg = asSmallInteger(expr.op2);
8202
8209
  if (deg !== null && deg > 0) return deg;
@@ -9505,6 +9512,16 @@ function expandAll(expr) {
9505
9512
  }
9506
9513
 
9507
9514
  // src/compute-engine/boxed-expression/negate.ts
9515
+ function canonicalNegate(expr) {
9516
+ let sign2 = -1;
9517
+ while (expr.operator === "Negate") {
9518
+ expr = expr.op1;
9519
+ sign2 = -sign2;
9520
+ }
9521
+ if (sign2 === 1) return expr;
9522
+ if (expr.isNumberLiteral) return expr.neg();
9523
+ return expr.engine._fn("Negate", [expr]);
9524
+ }
9508
9525
  function negate(expr) {
9509
9526
  let sign2 = -1;
9510
9527
  while (expr.operator === "Negate") {
@@ -9517,9 +9534,7 @@ function negate(expr) {
9517
9534
  if (expr.operator === "Subtract") return expr.op2.sub(expr.op1);
9518
9535
  if (expr.operator === "Add") return add3(...expr.ops.map((x) => negate(x)));
9519
9536
  if (expr.operator === "Multiply") return negateProduct(ce, expr.ops);
9520
- if (expr.operator === "Divide") {
9521
- return negate(expr.op1).div(expr.op2);
9522
- }
9537
+ if (expr.operator === "Divide") return negate(expr.op1).div(expr.op2);
9523
9538
  return ce._fn("Negate", [expr]);
9524
9539
  }
9525
9540
  function negateProduct(ce, args) {
@@ -13041,7 +13056,7 @@ var ARITHMETIC_LIBRARY = [
13041
13056
  sgn: ([x]) => x.isNonNegative ? "positive" : x.isNegative || x.isReal === false ? "unsigned" : void 0,
13042
13057
  canonical: (args, { engine }) => {
13043
13058
  const x = args[0];
13044
- if (x.numericValue !== null && x.isNegative)
13059
+ if (x.isNumberLiteral && x.isNegative)
13045
13060
  return engine._fn("Factorial", [x.neg()]).neg();
13046
13061
  return engine._fn("Factorial", [x]);
13047
13062
  },
@@ -18124,6 +18139,9 @@ function serializeRepeatingDecimals(s, options) {
18124
18139
  fractionalPart += lastDigit;
18125
18140
  while (fractionalPart.endsWith("0"))
18126
18141
  fractionalPart = fractionalPart.slice(0, -1);
18142
+ if (typeof options.fractionalDigits === "number") {
18143
+ fractionalPart = fractionalPart.slice(0, options.fractionalDigits);
18144
+ }
18127
18145
  if (exponent)
18128
18146
  return `${wholepart}.${fractionalPart}${exponent.toLowerCase()}`;
18129
18147
  return `${wholepart}.${fractionalPart}`;
@@ -18278,7 +18296,7 @@ function serializeJsonNumber(ce, value, options, metadata) {
18278
18296
  metadata.latex = metadata.latex ?? ce.box({ num: value.toString() }).latex;
18279
18297
  if (metadata.latex !== void 0)
18280
18298
  return { num: value.toString(), latex: metadata.latex };
18281
- return shorthandAllowed ? numberToExpression(value) : { num: numberToString(value) };
18299
+ return shorthandAllowed ? numberToExpression(value, options.fractionalDigits) : { num: numberToString(value, options.fractionalDigits) };
18282
18300
  }
18283
18301
  }
18284
18302
  let result;
@@ -18440,6 +18458,8 @@ var _BoxedExpression = class {
18440
18458
  }
18441
18459
  if (options.fractionalDigits === "auto")
18442
18460
  defaultOptions.fractionalDigits = -this.engine.precision;
18461
+ if (typeof options.fractionalDigits === "number")
18462
+ defaultOptions.fractionalDigits = options.fractionalDigits;
18443
18463
  }
18444
18464
  const opts = {
18445
18465
  ...defaultOptions,
@@ -18496,6 +18516,7 @@ var _BoxedExpression = class {
18496
18516
  };
18497
18517
  if (options?.fractionalDigits === "auto")
18498
18518
  effectiveOptions.fractionalDigits = -this.engine.precision;
18519
+ else effectiveOptions.fractionalDigits = options?.fractionalDigits ?? "max";
18499
18520
  if (typeof effectiveOptions.fractionalDigits === "number" && effectiveOptions.fractionalDigits > this.engine.precision)
18500
18521
  effectiveOptions.fractionalDigits = this.engine.precision;
18501
18522
  effectiveOptions = {
@@ -18624,7 +18645,7 @@ var _BoxedExpression = class {
18624
18645
  return null;
18625
18646
  }
18626
18647
  get isNumberLiteral() {
18627
- return this.numericValue !== null;
18648
+ return false;
18628
18649
  }
18629
18650
  get isFunctionExpression() {
18630
18651
  return false;
@@ -18797,6 +18818,9 @@ var _BoxedExpression = class {
18797
18818
  simplify(_options) {
18798
18819
  return this;
18799
18820
  }
18821
+ expand() {
18822
+ return expand2(this) ?? this;
18823
+ }
18800
18824
  evaluate(_options) {
18801
18825
  return this.simplify();
18802
18826
  }
@@ -21293,7 +21317,7 @@ function invisibleOperatorForm(expr) {
21293
21317
  return expr.engine._fn(expr.operator, expr.ops.map(invisibleOperatorForm));
21294
21318
  }
21295
21319
  function numberForm(expr) {
21296
- if (expr.numericValue !== null) return expr.canonical;
21320
+ if (expr.isNumberLiteral) return expr.canonical;
21297
21321
  if (expr.ops) return expr.engine._fn(expr.operator, expr.ops.map(numberForm));
21298
21322
  return expr;
21299
21323
  }
@@ -21424,10 +21448,10 @@ function boxFunction(ce, name, ops, options) {
21424
21448
  if (typeof op1 === "number") return ce.number(-op1, options);
21425
21449
  if (op1 instanceof Decimal) return ce.number(op1.neg(), options);
21426
21450
  const boxedop1 = ce.box(op1, options);
21427
- ops = [boxedop1];
21428
21451
  const num = boxedop1.numericValue;
21429
21452
  if (num !== null)
21430
21453
  return ce.number(typeof num === "number" ? -num : num.neg(), options);
21454
+ ops = [boxedop1];
21431
21455
  }
21432
21456
  }
21433
21457
  if (options.canonical === true)
@@ -21576,7 +21600,7 @@ function makeNumericFunction(ce, name, semiOps, metadata) {
21576
21600
  } else return null;
21577
21601
  if (!ops.every((x) => x.isValid)) return ce._fn(name, ops, metadata);
21578
21602
  if (name === "Add") return canonicalAdd(ce, ops);
21579
- if (name === "Negate") return ops[0].neg();
21603
+ if (name === "Negate") return canonicalNegate(ops[0]);
21580
21604
  if (name === "Multiply") return canonicalMultiply(ce, ops);
21581
21605
  if (name === "Divide") {
21582
21606
  if (ops.length === 2)
@@ -21794,7 +21818,7 @@ function derivative(fn, order2) {
21794
21818
  function differentiate(expr, v) {
21795
21819
  const ce = expr.engine;
21796
21820
  if (expr.string) return void 0;
21797
- if (expr.numericValue !== null) return expr.engine.Zero;
21821
+ if (expr.isNumberLiteral) return expr.engine.Zero;
21798
21822
  if (expr.symbol === v) return expr.engine.One;
21799
21823
  if (expr.symbol) return expr.engine.Zero;
21800
21824
  if (!expr.operator) return void 0;
@@ -23404,8 +23428,10 @@ var LOGIC_LIBRARY = {
23404
23428
  evaluate: evaluateImplies
23405
23429
  },
23406
23430
  Exists: { signature: "function", hold: true },
23431
+ NotExists: { signature: "function", hold: true },
23407
23432
  ExistsUnique: { signature: "function", hold: true },
23408
23433
  ForAll: { signature: "function", hold: true },
23434
+ NotForAll: { signature: "function", hold: true },
23409
23435
  KroneckerDelta: {
23410
23436
  description: "Return 1 if the arguments are equal, 0 otherwise",
23411
23437
  signature: "(value, ...value) -> integer",
@@ -25265,6 +25291,9 @@ var BoxedNumber = class extends _BoxedExpression {
25265
25291
  get numericValue() {
25266
25292
  return this._value;
25267
25293
  }
25294
+ get isNumberLiteral() {
25295
+ return true;
25296
+ }
25268
25297
  get re() {
25269
25298
  if (typeof this._value === "number") return this._value;
25270
25299
  return this._value.re;
@@ -25644,12 +25673,10 @@ function canonicalNumberString(ce, s) {
25644
25673
  }
25645
25674
  const n = bigint(s);
25646
25675
  if (n !== null) {
25647
- if (n >= Number.MIN_SAFE_INTEGER && n <= Number.MAX_SAFE_INTEGER)
25648
- return Number(n);
25676
+ if (n >= -SMALL_INTEGER && n <= SMALL_INTEGER) return Number(n);
25649
25677
  return ce._numericValue(n);
25650
25678
  }
25651
- const b = ce.bignum(s);
25652
- return isInMachineRange(b) ? b.toNumber() : ce._numericValue(b);
25679
+ return ce._numericValue(ce.bignum(s));
25653
25680
  }
25654
25681
 
25655
25682
  // src/compute-engine/boxed-expression/boxed-symbol.ts
@@ -27008,14 +27035,12 @@ var DEFINITIONS_ARITHMETIC = [
27008
27035
  name: "Negate",
27009
27036
  latexTrigger: ["-"],
27010
27037
  kind: "prefix",
27011
- precedence: ADDITION_PRECEDENCE + 2,
27038
+ precedence: EXPONENTIATION_PRECEDENCE + 1,
27012
27039
  parse: (parser, terminator) => {
27013
27040
  parser.skipSpace();
27014
- if (/\d/.test(parser.peek)) return null;
27015
- if (parser.parseNumber() !== null) return null;
27016
27041
  const rhs = parser.parseExpression({
27017
27042
  ...terminator,
27018
- minPrec: ADDITION_PRECEDENCE + 3
27043
+ minPrec: EXPONENTIATION_PRECEDENCE + 3
27019
27044
  });
27020
27045
  if (rhs === null) return null;
27021
27046
  return ["Negate", rhs];
@@ -27106,7 +27131,7 @@ var DEFINITIONS_ARITHMETIC = [
27106
27131
  latexTrigger: ["^"],
27107
27132
  kind: "infix",
27108
27133
  serialize: serializePower
27109
- // Parsing is done as a special case in `parseExpression`
27134
+ // Parsing is done as a special case in `parseSupsub`
27110
27135
  },
27111
27136
  {
27112
27137
  latexTrigger: "\\prod",
@@ -27830,6 +27855,24 @@ var DEFINITIONS_LOGIC = [
27830
27855
  serialize: "\\exists!",
27831
27856
  parse: parseQuantifier("ExistsUnique")
27832
27857
  },
27858
+ {
27859
+ name: "NotForAll",
27860
+ kind: "prefix",
27861
+ latexTrigger: ["\\lnot", "\\forall"],
27862
+ precedence: 200,
27863
+ // Has to be lower than COMPARISON_PRECEDENCE
27864
+ serialize: "\\lnot\\forall",
27865
+ parse: parseQuantifier("NotForAll")
27866
+ },
27867
+ {
27868
+ name: "NotExists",
27869
+ kind: "prefix",
27870
+ latexTrigger: ["\\lnot", "\\exists"],
27871
+ precedence: 200,
27872
+ // Has to be lower than COMPARISON_PRECEDENCE,
27873
+ serialize: "\\lnot\\exists",
27874
+ parse: parseQuantifier("NotExists")
27875
+ },
27833
27876
  {
27834
27877
  name: "KroneckerDelta",
27835
27878
  kind: "prefix",
@@ -27897,14 +27940,11 @@ function parseQuantifier(kind) {
27897
27940
  if (id) {
27898
27941
  parser.skipSpace();
27899
27942
  if (parser.match(",") || parser.match("\\mid") || parser.match(".") || parser.match(":") || parser.match("\\colon")) {
27900
- const body = parser.parseExpression(terminator);
27901
- return [kind, id, missingIfEmpty(body)];
27902
- }
27903
- if (parser.match("(")) {
27904
- const body = parser.parseExpression(terminator);
27905
- if (!parser.match(")")) return null;
27906
- return [kind, id, missingIfEmpty(body)];
27943
+ const body2 = parser.parseExpression(terminator);
27944
+ return [kind, id, missingIfEmpty(body2)];
27907
27945
  }
27946
+ const body = parser.parseEnclosure();
27947
+ if (body) return [kind, id, missingIfEmpty(body)];
27908
27948
  }
27909
27949
  parser.index = index;
27910
27950
  const condition = parser.parseExpression(terminator);
@@ -33220,11 +33260,19 @@ Invalid definition for ${id}`, err.message].join("\n| ") + "\n"
33220
33260
  {
33221
33261
  const type2 = parseType(def);
33222
33262
  if (!isValidType(type2)) {
33263
+ if (typeof def === "object" && "N" in def) {
33264
+ throw Error(
33265
+ [
33266
+ `Invalid argument for "${id}"`,
33267
+ "Use `evaluate` handler instead of `N`"
33268
+ ].join("\n| ")
33269
+ );
33270
+ }
33223
33271
  throw Error(
33224
33272
  [
33225
33273
  `Invalid argument for "${id}"`,
33226
33274
  def.toString(),
33227
- `Use a type, a FunctionDefinition or a SymbolDefinition`
33275
+ `Use a type, a \`FunctionDefinition\` or a \`SymbolDefinition\``
33228
33276
  ].join("\n| ")
33229
33277
  );
33230
33278
  }
@@ -34315,10 +34363,10 @@ function mark(line, mark2) {
34315
34363
  }
34316
34364
 
34317
34365
  // src/compute-engine.ts
34318
- var version = "0.26.0";
34366
+ var version = "0.26.2";
34319
34367
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
34320
34368
  ComputeEngine: ComputeEngine.prototype.constructor,
34321
- version: "0.26.0"
34369
+ version: "0.26.2"
34322
34370
  };
34323
34371
  export {
34324
34372
  ComputeEngine,