@cortex-js/compute-engine 0.26.2 → 0.26.4

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 -3
  2. package/dist/compute-engine.esm.js +60 -28
  3. package/dist/compute-engine.js +60 -28
  4. package/dist/compute-engine.min.esm.js +23 -23
  5. package/dist/compute-engine.min.js +22 -22
  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 +1 -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 +1 -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 +1 -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 +1 -1
  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 +1 -1
  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 +1 -1
  89. package/dist/types/compute-engine/latex-syntax/public.d.ts +1 -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 +1 -1
  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 +1 -1
  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
@@ -27,13 +27,15 @@ import { ComputeEngine } from "@cortex-js/compute-engine";
27
27
 
28
28
  const ce = new ComputeEngine();
29
29
 
30
- engine.parse("2^{11}-1 \\in \\Z").evaluate().print()
30
+ ce.parse("2^{11}-1 \\in \\Z").evaluate().print()
31
31
  // ➔ "True"
32
32
  ```
33
33
 
34
- ## More
34
+ ## FAQ
35
35
 
36
- - [Build](BUILD.md) instructions
36
+ **Q** How do I build the project?
37
+
38
+ [Build](BUILD.md) instructions
37
39
 
38
40
  ## Related Projects
39
41
 
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.26.2 */
1
+ /** Compute Engine 0.26.4 */
2
2
 
3
3
  // src/compute-engine/boxed-expression/public.ts
4
4
  function isRuleStep(x) {
@@ -9596,7 +9596,10 @@ function canonicalMultiply(ce, ops) {
9596
9596
  if (next.operator === "Sqrt" && next.op1.isNumberLiteral && isSubtype(next.op1.type, "finite_integer")) {
9597
9597
  let radical = next.op1.numericValue;
9598
9598
  if (typeof radical !== "number") radical = radical.re;
9599
- if (radical >= SMALL_INTEGER) continue;
9599
+ if (radical >= SMALL_INTEGER) {
9600
+ ys.push(x);
9601
+ continue;
9602
+ }
9600
9603
  if (isSubtype(x.type, "finite_rational")) {
9601
9604
  const rational = x.numericValue;
9602
9605
  const [num, den] = typeof rational === "number" ? [rational, 1] : [rational.numerator.re, rational.denominator.re];
@@ -9689,6 +9692,7 @@ function mulN(...xs) {
9689
9692
  function canonicalDivide(op1, op2) {
9690
9693
  const ce = op1.engine;
9691
9694
  if (!op1.isValid || !op2.isValid) return ce._fn("Divide", [op1, op2]);
9695
+ if (op1.isNaN || op2.isNaN) return ce.NaN;
9692
9696
  if (op2.is(0)) return op1.is(0) ? ce.NaN : ce.ComplexInfinity;
9693
9697
  if (op1.is(0)) return ce.Zero;
9694
9698
  if (op2.is(0) === false) {
@@ -9888,9 +9892,11 @@ var Product = class _Product {
9888
9892
  return;
9889
9893
  }
9890
9894
  if (term.isInfinity) {
9891
- this.coefficient = this.engine._numericValue(
9892
- term.isNegative ? -Infinity : Infinity
9893
- );
9895
+ if (isOne(exp2)) {
9896
+ this.coefficient = this.engine._numericValue(
9897
+ term.isNegative ? -Infinity : Infinity
9898
+ );
9899
+ } else this.terms.push({ term, exponent: exp2 });
9894
9900
  return;
9895
9901
  }
9896
9902
  if (isOne(exp2)) {
@@ -10045,8 +10051,15 @@ var Product = class _Product {
10045
10051
  const ce = this.engine;
10046
10052
  const coef = this.coefficient;
10047
10053
  if (coef.isZero) return [ce.Zero, ce.One];
10048
- if (coef.isPositiveInfinity || coef.isNegativeInfinity)
10054
+ if (coef.isPositiveInfinity || coef.isNegativeInfinity) {
10055
+ if (this.terms.length === 0) {
10056
+ return [
10057
+ coef.isPositiveInfinity ? ce.PositiveInfinity : ce.NegativeInfinity,
10058
+ ce.One
10059
+ ];
10060
+ }
10049
10061
  return [ce.NaN, ce.NaN];
10062
+ }
10050
10063
  const isNegativeOne2 = coef.isNegativeOne;
10051
10064
  if (isNegativeOne2) this.coefficient = ce._numericValue(1);
10052
10065
  const xs = this.groupedByDegrees({ mode: "rational" });
@@ -10613,13 +10626,23 @@ function evalTrig(name, op) {
10613
10626
  (x) => x.sinh(),
10614
10627
  (x) => x.sinh()
10615
10628
  );
10616
- case "Tan":
10617
- return applyAngle(
10629
+ case "Tan": {
10630
+ const result = applyAngle(
10618
10631
  op,
10619
- Math.tan,
10620
- (x) => x.toSignificantDigits(ce.precision + 4).tan().toSignificantDigits(ce.precision),
10632
+ (x) => {
10633
+ const y = Math.tan(x);
10634
+ if (y > 1e6 || y < -1e6) return ce.ComplexInfinity;
10635
+ return y;
10636
+ },
10637
+ (x) => {
10638
+ const y = x.tan();
10639
+ if (y.greaterThan(1e6) || y.lessThan(-1e6)) return ce.ComplexInfinity;
10640
+ return y;
10641
+ },
10621
10642
  (x) => x.tan()
10622
10643
  );
10644
+ return result;
10645
+ }
10623
10646
  case "Tanh":
10624
10647
  return applyAngle(
10625
10648
  op,
@@ -10853,9 +10876,11 @@ function canonicalRoot(a, b) {
10853
10876
  if (exp2 === 1) return a;
10854
10877
  if (exp2 === 2) {
10855
10878
  if (a.isNumberLiteral && isSubtype(a.type, "rational")) {
10856
- const v = a.sqrt();
10857
- if (typeof v.numericValue === "number") return v;
10858
- if (v.numericValue.isExact) return v;
10879
+ if (a.re < SMALL_INTEGER) {
10880
+ const v = a.sqrt();
10881
+ if (typeof v.numericValue === "number") return v;
10882
+ if (v.numericValue.isExact) return v;
10883
+ }
10859
10884
  }
10860
10885
  return ce._fn("Sqrt", [a]);
10861
10886
  }
@@ -11623,10 +11648,9 @@ function makeLambda(expr) {
11623
11648
  ce.resetContext();
11624
11649
  let i = 0;
11625
11650
  for (const param of params) ce.assign(param, args[i++]);
11626
- const result = fn.N() ?? fn.evaluate();
11651
+ const result = fn.evaluate();
11627
11652
  ce.swapScope(context);
11628
- if (!result.isValid) return void 0;
11629
- return result;
11653
+ return result.isValid ? result : void 0;
11630
11654
  };
11631
11655
  }
11632
11656
  function apply3(fn, args) {
@@ -13423,7 +13447,7 @@ var ARITHMETIC_LIBRARY = [
13423
13447
  const [base, exp2] = args;
13424
13448
  return canonicalRoot(base, exp2);
13425
13449
  },
13426
- evaluate: ([x, n], { numericApproximation }) => x.root(n)
13450
+ evaluate: ([x, n], { numericApproximation }) => root(x, n, { numericApproximation })
13427
13451
  },
13428
13452
  Round: {
13429
13453
  complexity: 1250,
@@ -17138,6 +17162,7 @@ function parseAt(...close) {
17138
17162
  rhs ?? (rhs = parser.parseExpression({ minPrec: 0 }));
17139
17163
  if (rhs === null) return null;
17140
17164
  if (close.length > 0 && !parser.matchAll(close)) return null;
17165
+ if (stringValue(rhs) !== null) return null;
17141
17166
  if (operator(rhs) === "Delimiter") rhs = operand(rhs, 1) ?? "Nothing";
17142
17167
  if (operator(rhs) === "Sequence") return ["At", lhs, ...operands(rhs)];
17143
17168
  return ["At", lhs, rhs];
@@ -21743,8 +21768,15 @@ var DERIVATIVES_TABLE = {
21743
21768
  Log: ["Power", ["Multiply", "_", ["Ln", "10"]], -1],
21744
21769
  Sqrt: ["Multiply", ["Power", "_", ["Negate", "Half"]], "Half"],
21745
21770
  Abs: [
21746
- "Piecewise",
21747
- ["Tuple", ["Multiply", "_", ["Power", "_", -1]], ["Greater", "_", 0]]
21771
+ "Which",
21772
+ ["Equal", "_", 0],
21773
+ NaN,
21774
+ ["Less", "_", 0],
21775
+ -1,
21776
+ ["Greater", "_", 0],
21777
+ 1,
21778
+ "True",
21779
+ ["D", ["Abs", "_"], "_"]
21748
21780
  ],
21749
21781
  // https://proofwiki.org/wiki/Derivative_of_Error_Function
21750
21782
  Erf: [
@@ -24601,9 +24633,9 @@ var TRIGONOMETRY_LIBRARY = [
24601
24633
  }
24602
24634
  return ce.number(fArg).div(180).mul(ce.Pi);
24603
24635
  },
24604
- evaluate: (ops, { engine: ce }) => {
24605
- if (ce.angularUnit === "deg") return ops[0];
24606
- return ops[0].mul(ce.Pi.div(180)).evaluate();
24636
+ evaluate: (ops, options) => {
24637
+ if (options.engine.angularUnit === "deg") return ops[0];
24638
+ return ops[0].mul(options.engine.Pi.div(180)).evaluate(options);
24607
24639
  }
24608
24640
  },
24609
24641
  // Hypot: sqrt(x*x + y*y)
@@ -25417,7 +25449,7 @@ var BoxedNumber = class extends _BoxedExpression {
25417
25449
  if (typeof this._value === "number") {
25418
25450
  if (this._value === 0 || this._value === 1) return this;
25419
25451
  if (this._value === -1) return this.engine.I;
25420
- if (this._value > 0 && Number.isInteger(this._value))
25452
+ if (this._value > 0 && Number.isInteger(this._value) && this._value < SMALL_INTEGER)
25421
25453
  return this.engine.number(
25422
25454
  this.engine._numericValue({ radical: this._value })
25423
25455
  );
@@ -27272,7 +27304,7 @@ function parseBigOp(name, prec) {
27272
27304
  }
27273
27305
  function serializeBigOp(command) {
27274
27306
  return (serializer, expr) => {
27275
- if (operand(expr, 1) !== null) return command;
27307
+ if (!operand(expr, 1)) return command;
27276
27308
  let arg = operand(expr, 2);
27277
27309
  const h = operator(arg);
27278
27310
  if (h !== "Tuple" && h !== "Triple" && h !== "Pair" && h !== "Single")
@@ -29093,7 +29125,7 @@ function parseIntegralBodyExpression(expr) {
29093
29125
  }
29094
29126
  function serializeIntegral(command) {
29095
29127
  return (serializer, expr) => {
29096
- if (operand(expr, 1) !== null) return command;
29128
+ if (!operand(expr, 1)) return command;
29097
29129
  let arg = operand(expr, 2);
29098
29130
  const h = operator(arg);
29099
29131
  let indexExpr = null;
@@ -32963,7 +32995,7 @@ var ComputeEngine = class _ComputeEngine {
32963
32995
  }
32964
32996
  if ("radical" in value || "rational" in value) {
32965
32997
  if (value.radical !== void 0 && (!Number.isInteger(value.radical) || value.radical >= SMALL_INTEGER)) {
32966
- return makeNumericValue(value);
32998
+ throw Error("Unexpected value for radical part:" + value.radical);
32967
32999
  }
32968
33000
  if (value.rational) {
32969
33001
  if (isMachineRational(value.rational)) {
@@ -34363,10 +34395,10 @@ function mark(line, mark2) {
34363
34395
  }
34364
34396
 
34365
34397
  // src/compute-engine.ts
34366
- var version = "0.26.2";
34398
+ var version = "0.26.4";
34367
34399
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
34368
34400
  ComputeEngine: ComputeEngine.prototype.constructor,
34369
- version: "0.26.2"
34401
+ version: "0.26.4"
34370
34402
  };
34371
34403
  export {
34372
34404
  ComputeEngine,
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.26.2 */
1
+ /** Compute Engine 0.26.4 */
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;
@@ -9627,7 +9627,10 @@ Invalid type
9627
9627
  if (next.operator === "Sqrt" && next.op1.isNumberLiteral && isSubtype(next.op1.type, "finite_integer")) {
9628
9628
  let radical = next.op1.numericValue;
9629
9629
  if (typeof radical !== "number") radical = radical.re;
9630
- if (radical >= SMALL_INTEGER) continue;
9630
+ if (radical >= SMALL_INTEGER) {
9631
+ ys.push(x);
9632
+ continue;
9633
+ }
9631
9634
  if (isSubtype(x.type, "finite_rational")) {
9632
9635
  const rational = x.numericValue;
9633
9636
  const [num, den] = typeof rational === "number" ? [rational, 1] : [rational.numerator.re, rational.denominator.re];
@@ -9720,6 +9723,7 @@ Invalid type
9720
9723
  function canonicalDivide(op1, op2) {
9721
9724
  const ce = op1.engine;
9722
9725
  if (!op1.isValid || !op2.isValid) return ce._fn("Divide", [op1, op2]);
9726
+ if (op1.isNaN || op2.isNaN) return ce.NaN;
9723
9727
  if (op2.is(0)) return op1.is(0) ? ce.NaN : ce.ComplexInfinity;
9724
9728
  if (op1.is(0)) return ce.Zero;
9725
9729
  if (op2.is(0) === false) {
@@ -9919,9 +9923,11 @@ Invalid type
9919
9923
  return;
9920
9924
  }
9921
9925
  if (term.isInfinity) {
9922
- this.coefficient = this.engine._numericValue(
9923
- term.isNegative ? -Infinity : Infinity
9924
- );
9926
+ if (isOne(exp2)) {
9927
+ this.coefficient = this.engine._numericValue(
9928
+ term.isNegative ? -Infinity : Infinity
9929
+ );
9930
+ } else this.terms.push({ term, exponent: exp2 });
9925
9931
  return;
9926
9932
  }
9927
9933
  if (isOne(exp2)) {
@@ -10076,8 +10082,15 @@ Invalid type
10076
10082
  const ce = this.engine;
10077
10083
  const coef = this.coefficient;
10078
10084
  if (coef.isZero) return [ce.Zero, ce.One];
10079
- if (coef.isPositiveInfinity || coef.isNegativeInfinity)
10085
+ if (coef.isPositiveInfinity || coef.isNegativeInfinity) {
10086
+ if (this.terms.length === 0) {
10087
+ return [
10088
+ coef.isPositiveInfinity ? ce.PositiveInfinity : ce.NegativeInfinity,
10089
+ ce.One
10090
+ ];
10091
+ }
10080
10092
  return [ce.NaN, ce.NaN];
10093
+ }
10081
10094
  const isNegativeOne2 = coef.isNegativeOne;
10082
10095
  if (isNegativeOne2) this.coefficient = ce._numericValue(1);
10083
10096
  const xs = this.groupedByDegrees({ mode: "rational" });
@@ -10644,13 +10657,23 @@ Invalid type
10644
10657
  (x) => x.sinh(),
10645
10658
  (x) => x.sinh()
10646
10659
  );
10647
- case "Tan":
10648
- return applyAngle(
10660
+ case "Tan": {
10661
+ const result = applyAngle(
10649
10662
  op,
10650
- Math.tan,
10651
- (x) => x.toSignificantDigits(ce.precision + 4).tan().toSignificantDigits(ce.precision),
10663
+ (x) => {
10664
+ const y = Math.tan(x);
10665
+ if (y > 1e6 || y < -1e6) return ce.ComplexInfinity;
10666
+ return y;
10667
+ },
10668
+ (x) => {
10669
+ const y = x.tan();
10670
+ if (y.greaterThan(1e6) || y.lessThan(-1e6)) return ce.ComplexInfinity;
10671
+ return y;
10672
+ },
10652
10673
  (x) => x.tan()
10653
10674
  );
10675
+ return result;
10676
+ }
10654
10677
  case "Tanh":
10655
10678
  return applyAngle(
10656
10679
  op,
@@ -10884,9 +10907,11 @@ Invalid type
10884
10907
  if (exp2 === 1) return a;
10885
10908
  if (exp2 === 2) {
10886
10909
  if (a.isNumberLiteral && isSubtype(a.type, "rational")) {
10887
- const v = a.sqrt();
10888
- if (typeof v.numericValue === "number") return v;
10889
- if (v.numericValue.isExact) return v;
10910
+ if (a.re < SMALL_INTEGER) {
10911
+ const v = a.sqrt();
10912
+ if (typeof v.numericValue === "number") return v;
10913
+ if (v.numericValue.isExact) return v;
10914
+ }
10890
10915
  }
10891
10916
  return ce._fn("Sqrt", [a]);
10892
10917
  }
@@ -11654,10 +11679,9 @@ Invalid type
11654
11679
  ce.resetContext();
11655
11680
  let i = 0;
11656
11681
  for (const param of params) ce.assign(param, args[i++]);
11657
- const result = fn.N() ?? fn.evaluate();
11682
+ const result = fn.evaluate();
11658
11683
  ce.swapScope(context);
11659
- if (!result.isValid) return void 0;
11660
- return result;
11684
+ return result.isValid ? result : void 0;
11661
11685
  };
11662
11686
  }
11663
11687
  function apply3(fn, args) {
@@ -13454,7 +13478,7 @@ Invalid type
13454
13478
  const [base, exp2] = args;
13455
13479
  return canonicalRoot(base, exp2);
13456
13480
  },
13457
- evaluate: ([x, n], { numericApproximation }) => x.root(n)
13481
+ evaluate: ([x, n], { numericApproximation }) => root(x, n, { numericApproximation })
13458
13482
  },
13459
13483
  Round: {
13460
13484
  complexity: 1250,
@@ -17169,6 +17193,7 @@ ${e.message}`);
17169
17193
  rhs ?? (rhs = parser.parseExpression({ minPrec: 0 }));
17170
17194
  if (rhs === null) return null;
17171
17195
  if (close.length > 0 && !parser.matchAll(close)) return null;
17196
+ if (stringValue(rhs) !== null) return null;
17172
17197
  if (operator(rhs) === "Delimiter") rhs = operand(rhs, 1) ?? "Nothing";
17173
17198
  if (operator(rhs) === "Sequence") return ["At", lhs, ...operands(rhs)];
17174
17199
  return ["At", lhs, rhs];
@@ -21774,8 +21799,15 @@ ${e.message}`);
21774
21799
  Log: ["Power", ["Multiply", "_", ["Ln", "10"]], -1],
21775
21800
  Sqrt: ["Multiply", ["Power", "_", ["Negate", "Half"]], "Half"],
21776
21801
  Abs: [
21777
- "Piecewise",
21778
- ["Tuple", ["Multiply", "_", ["Power", "_", -1]], ["Greater", "_", 0]]
21802
+ "Which",
21803
+ ["Equal", "_", 0],
21804
+ NaN,
21805
+ ["Less", "_", 0],
21806
+ -1,
21807
+ ["Greater", "_", 0],
21808
+ 1,
21809
+ "True",
21810
+ ["D", ["Abs", "_"], "_"]
21779
21811
  ],
21780
21812
  // https://proofwiki.org/wiki/Derivative_of_Error_Function
21781
21813
  Erf: [
@@ -24632,9 +24664,9 @@ ${e.message}`);
24632
24664
  }
24633
24665
  return ce.number(fArg).div(180).mul(ce.Pi);
24634
24666
  },
24635
- evaluate: (ops, { engine: ce }) => {
24636
- if (ce.angularUnit === "deg") return ops[0];
24637
- return ops[0].mul(ce.Pi.div(180)).evaluate();
24667
+ evaluate: (ops, options) => {
24668
+ if (options.engine.angularUnit === "deg") return ops[0];
24669
+ return ops[0].mul(options.engine.Pi.div(180)).evaluate(options);
24638
24670
  }
24639
24671
  },
24640
24672
  // Hypot: sqrt(x*x + y*y)
@@ -25448,7 +25480,7 @@ Error in definition of "${name}"`,
25448
25480
  if (typeof this._value === "number") {
25449
25481
  if (this._value === 0 || this._value === 1) return this;
25450
25482
  if (this._value === -1) return this.engine.I;
25451
- if (this._value > 0 && Number.isInteger(this._value))
25483
+ if (this._value > 0 && Number.isInteger(this._value) && this._value < SMALL_INTEGER)
25452
25484
  return this.engine.number(
25453
25485
  this.engine._numericValue({ radical: this._value })
25454
25486
  );
@@ -27303,7 +27335,7 @@ Error in definition of "${name}"`,
27303
27335
  }
27304
27336
  function serializeBigOp(command) {
27305
27337
  return (serializer, expr) => {
27306
- if (operand(expr, 1) !== null) return command;
27338
+ if (!operand(expr, 1)) return command;
27307
27339
  let arg = operand(expr, 2);
27308
27340
  const h = operator(arg);
27309
27341
  if (h !== "Tuple" && h !== "Triple" && h !== "Pair" && h !== "Single")
@@ -29124,7 +29156,7 @@ Error in definition of "${name}"`,
29124
29156
  }
29125
29157
  function serializeIntegral(command) {
29126
29158
  return (serializer, expr) => {
29127
- if (operand(expr, 1) !== null) return command;
29159
+ if (!operand(expr, 1)) return command;
29128
29160
  let arg = operand(expr, 2);
29129
29161
  const h = operator(arg);
29130
29162
  let indexExpr = null;
@@ -32994,7 +33026,7 @@ Error in definition of "${name}"`,
32994
33026
  }
32995
33027
  if ("radical" in value || "rational" in value) {
32996
33028
  if (value.radical !== void 0 && (!Number.isInteger(value.radical) || value.radical >= SMALL_INTEGER)) {
32997
- return makeNumericValue(value);
33029
+ throw Error("Unexpected value for radical part:" + value.radical);
32998
33030
  }
32999
33031
  if (value.rational) {
33000
33032
  if (isMachineRational(value.rational)) {
@@ -34394,10 +34426,10 @@ ${lineNo.toString().padStart(maxDigits, " ")}`;
34394
34426
  }
34395
34427
 
34396
34428
  // src/compute-engine.ts
34397
- var version = "0.26.2";
34429
+ var version = "0.26.4";
34398
34430
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
34399
34431
  ComputeEngine: ComputeEngine.prototype.constructor,
34400
- version: "0.26.2"
34432
+ version: "0.26.4"
34401
34433
  };
34402
34434
  return __toCommonJS(compute_engine_exports);
34403
34435
  })();