@cortex-js/compute-engine 0.26.2 → 0.26.3

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 +57 -26
  3. package/dist/compute-engine.js +57 -26
  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.3 */
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,
@@ -21743,8 +21767,15 @@ var DERIVATIVES_TABLE = {
21743
21767
  Log: ["Power", ["Multiply", "_", ["Ln", "10"]], -1],
21744
21768
  Sqrt: ["Multiply", ["Power", "_", ["Negate", "Half"]], "Half"],
21745
21769
  Abs: [
21746
- "Piecewise",
21747
- ["Tuple", ["Multiply", "_", ["Power", "_", -1]], ["Greater", "_", 0]]
21770
+ "Which",
21771
+ ["Equal", "_", 0],
21772
+ NaN,
21773
+ ["Less", "_", 0],
21774
+ -1,
21775
+ ["Greater", "_", 0],
21776
+ 1,
21777
+ "True",
21778
+ ["D", ["Abs", "_"], "_"]
21748
21779
  ],
21749
21780
  // https://proofwiki.org/wiki/Derivative_of_Error_Function
21750
21781
  Erf: [
@@ -24601,9 +24632,9 @@ var TRIGONOMETRY_LIBRARY = [
24601
24632
  }
24602
24633
  return ce.number(fArg).div(180).mul(ce.Pi);
24603
24634
  },
24604
- evaluate: (ops, { engine: ce }) => {
24605
- if (ce.angularUnit === "deg") return ops[0];
24606
- return ops[0].mul(ce.Pi.div(180)).evaluate();
24635
+ evaluate: (ops, options) => {
24636
+ if (options.engine.angularUnit === "deg") return ops[0];
24637
+ return ops[0].mul(options.engine.Pi.div(180)).evaluate(options);
24607
24638
  }
24608
24639
  },
24609
24640
  // Hypot: sqrt(x*x + y*y)
@@ -25417,7 +25448,7 @@ var BoxedNumber = class extends _BoxedExpression {
25417
25448
  if (typeof this._value === "number") {
25418
25449
  if (this._value === 0 || this._value === 1) return this;
25419
25450
  if (this._value === -1) return this.engine.I;
25420
- if (this._value > 0 && Number.isInteger(this._value))
25451
+ if (this._value > 0 && Number.isInteger(this._value) && this._value < SMALL_INTEGER)
25421
25452
  return this.engine.number(
25422
25453
  this.engine._numericValue({ radical: this._value })
25423
25454
  );
@@ -32963,7 +32994,7 @@ var ComputeEngine = class _ComputeEngine {
32963
32994
  }
32964
32995
  if ("radical" in value || "rational" in value) {
32965
32996
  if (value.radical !== void 0 && (!Number.isInteger(value.radical) || value.radical >= SMALL_INTEGER)) {
32966
- return makeNumericValue(value);
32997
+ throw Error("Unexpected value for radical part:" + value.radical);
32967
32998
  }
32968
32999
  if (value.rational) {
32969
33000
  if (isMachineRational(value.rational)) {
@@ -34363,10 +34394,10 @@ function mark(line, mark2) {
34363
34394
  }
34364
34395
 
34365
34396
  // src/compute-engine.ts
34366
- var version = "0.26.2";
34397
+ var version = "0.26.3";
34367
34398
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
34368
34399
  ComputeEngine: ComputeEngine.prototype.constructor,
34369
- version: "0.26.2"
34400
+ version: "0.26.3"
34370
34401
  };
34371
34402
  export {
34372
34403
  ComputeEngine,
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.26.2 */
1
+ /** Compute Engine 0.26.3 */
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,
@@ -21774,8 +21798,15 @@ ${e.message}`);
21774
21798
  Log: ["Power", ["Multiply", "_", ["Ln", "10"]], -1],
21775
21799
  Sqrt: ["Multiply", ["Power", "_", ["Negate", "Half"]], "Half"],
21776
21800
  Abs: [
21777
- "Piecewise",
21778
- ["Tuple", ["Multiply", "_", ["Power", "_", -1]], ["Greater", "_", 0]]
21801
+ "Which",
21802
+ ["Equal", "_", 0],
21803
+ NaN,
21804
+ ["Less", "_", 0],
21805
+ -1,
21806
+ ["Greater", "_", 0],
21807
+ 1,
21808
+ "True",
21809
+ ["D", ["Abs", "_"], "_"]
21779
21810
  ],
21780
21811
  // https://proofwiki.org/wiki/Derivative_of_Error_Function
21781
21812
  Erf: [
@@ -24632,9 +24663,9 @@ ${e.message}`);
24632
24663
  }
24633
24664
  return ce.number(fArg).div(180).mul(ce.Pi);
24634
24665
  },
24635
- evaluate: (ops, { engine: ce }) => {
24636
- if (ce.angularUnit === "deg") return ops[0];
24637
- return ops[0].mul(ce.Pi.div(180)).evaluate();
24666
+ evaluate: (ops, options) => {
24667
+ if (options.engine.angularUnit === "deg") return ops[0];
24668
+ return ops[0].mul(options.engine.Pi.div(180)).evaluate(options);
24638
24669
  }
24639
24670
  },
24640
24671
  // Hypot: sqrt(x*x + y*y)
@@ -25448,7 +25479,7 @@ Error in definition of "${name}"`,
25448
25479
  if (typeof this._value === "number") {
25449
25480
  if (this._value === 0 || this._value === 1) return this;
25450
25481
  if (this._value === -1) return this.engine.I;
25451
- if (this._value > 0 && Number.isInteger(this._value))
25482
+ if (this._value > 0 && Number.isInteger(this._value) && this._value < SMALL_INTEGER)
25452
25483
  return this.engine.number(
25453
25484
  this.engine._numericValue({ radical: this._value })
25454
25485
  );
@@ -32994,7 +33025,7 @@ Error in definition of "${name}"`,
32994
33025
  }
32995
33026
  if ("radical" in value || "rational" in value) {
32996
33027
  if (value.radical !== void 0 && (!Number.isInteger(value.radical) || value.radical >= SMALL_INTEGER)) {
32997
- return makeNumericValue(value);
33028
+ throw Error("Unexpected value for radical part:" + value.radical);
32998
33029
  }
32999
33030
  if (value.rational) {
33000
33031
  if (isMachineRational(value.rational)) {
@@ -34394,10 +34425,10 @@ ${lineNo.toString().padStart(maxDigits, " ")}`;
34394
34425
  }
34395
34426
 
34396
34427
  // src/compute-engine.ts
34397
- var version = "0.26.2";
34428
+ var version = "0.26.3";
34398
34429
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
34399
34430
  ComputeEngine: ComputeEngine.prototype.constructor,
34400
- version: "0.26.2"
34431
+ version: "0.26.3"
34401
34432
  };
34402
34433
  return __toCommonJS(compute_engine_exports);
34403
34434
  })();