@cortex-js/compute-engine 0.12.0 → 0.12.1

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 (86) hide show
  1. package/dist/compute-engine.esm.js +70 -60
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +2 -2
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -1
  9. package/dist/types/common/utils.d.ts +1 -1
  10. package/dist/types/compute-engine/assume.d.ts +1 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  27. package/dist/types/compute-engine/compute-engine.d.ts +1 -1
  28. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  29. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/public.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  48. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  49. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  51. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  52. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  53. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  54. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  55. package/dist/types/compute-engine/library/core.d.ts +1 -1
  56. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  57. package/dist/types/compute-engine/library/library.d.ts +1 -1
  58. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  59. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  60. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  61. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  62. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  63. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  64. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  65. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  66. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  67. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  68. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  69. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  70. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  71. package/dist/types/compute-engine/public.d.ts +1 -1
  72. package/dist/types/compute-engine/rules.d.ts +1 -1
  73. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  74. package/dist/types/compute-engine/solve.d.ts +1 -1
  75. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  76. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  77. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  78. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  79. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  80. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  81. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  82. package/dist/types/compute-engine.d.ts +2 -2
  83. package/dist/types/math-json/math-json-format.d.ts +1 -1
  84. package/dist/types/math-json/utils.d.ts +1 -1
  85. package/dist/types/math-json.d.ts +2 -2
  86. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.12.0 */
1
+ /** CortexJS Compute Engine 0.12.1 */
2
2
  /** @internal */
3
3
  function isSymbolEntry(entry) {
4
4
  return !('kind' in entry) || entry.kind === 'symbol';
@@ -14267,12 +14267,21 @@ function bigint(a) {
14267
14267
  return BigInt(s);
14268
14268
  }
14269
14269
  function gcd(a, b) {
14270
- while (b !== 0n)
14270
+ while (b !== BigInt(0))
14271
14271
  [a, b] = [b, a % b];
14272
- return a < 0n ? -a : a;
14272
+ return a < 0 ? -a : a;
14273
14273
  }
14274
14274
  // Difference between primes from 7 to 31
14275
- const PRIME_WHEEL_INC = [4n, 2n, 4n, 2n, 4n, 6n, 2n, 6n];
14275
+ const PRIME_WHEEL_INC = [
14276
+ BigInt(4),
14277
+ BigInt(2),
14278
+ BigInt(4),
14279
+ BigInt(2),
14280
+ BigInt(4),
14281
+ BigInt(6),
14282
+ BigInt(2),
14283
+ BigInt(6),
14284
+ ];
14276
14285
  function primeFactors(d) {
14277
14286
  if (d < Number.MAX_SAFE_INTEGER) {
14278
14287
  const factors = primeFactors$1(Number(d));
@@ -14289,24 +14298,24 @@ function primeFactors(d) {
14289
14298
  let count2 = 0;
14290
14299
  let count3 = 0;
14291
14300
  let count5 = 0;
14292
- let k = 10n;
14293
- while (n % k === 0n) {
14301
+ let k = BigInt(10);
14302
+ while (n % k === BigInt(0)) {
14294
14303
  count2 += 1;
14295
14304
  count5 += 1;
14296
14305
  n = n / k;
14297
14306
  }
14298
- k = 5n;
14299
- while (n % k === 0n) {
14307
+ k = BigInt(5);
14308
+ while (n % k === BigInt(0)) {
14300
14309
  count5 += 1;
14301
14310
  n = n / k;
14302
14311
  }
14303
- k = 3n;
14304
- while (n % k === 0n) {
14312
+ k = BigInt(3);
14313
+ while (n % k === BigInt(0)) {
14305
14314
  count3 += 1;
14306
14315
  n = n / k;
14307
14316
  }
14308
- k = 2n;
14309
- while (n % k === 0n) {
14317
+ k = BigInt(2);
14318
+ while (n % k === BigInt(0)) {
14310
14319
  count2 += 1;
14311
14320
  n = n / k;
14312
14321
  }
@@ -14316,11 +14325,11 @@ function primeFactors(d) {
14316
14325
  result.set('3', count3);
14317
14326
  if (count5 > 0)
14318
14327
  result.set('5', count5);
14319
- k = 7n;
14328
+ k = BigInt(7);
14320
14329
  let kIndex = '';
14321
14330
  let i = 0;
14322
14331
  while (k * k < n) {
14323
- if (n % k === 0n) {
14332
+ if (n % k === BigInt(0)) {
14324
14333
  if (!kIndex)
14325
14334
  kIndex = k.toString();
14326
14335
  result.set(kIndex, (result.get(kIndex) ?? 0) + 1);
@@ -14332,7 +14341,7 @@ function primeFactors(d) {
14332
14341
  i = i < 7 ? i + 1 : 0;
14333
14342
  }
14334
14343
  }
14335
- if (n !== 1n)
14344
+ if (n !== BigInt(1))
14336
14345
  result.set(n.toString(), (result.get(n.toString()) ?? 0) + 1);
14337
14346
  const r = new Map();
14338
14347
  for (const [k, v] of result)
@@ -14348,8 +14357,8 @@ function primeFactors(d) {
14348
14357
  function factorPower(n, exponent) {
14349
14358
  // @todo: handle negative n
14350
14359
  const factors = primeFactors(n);
14351
- let f = 1n;
14352
- let r = 1n;
14360
+ let f = BigInt(1);
14361
+ let r = BigInt(1);
14353
14362
  const exp = bigint(exponent);
14354
14363
  for (const [k, v] of factors) {
14355
14364
  const v2 = bigint(v);
@@ -14703,7 +14712,7 @@ function asRational(expr) {
14703
14712
  if (typeof num === 'number' && Number.isInteger(num))
14704
14713
  return [num, 1];
14705
14714
  if (num instanceof Decimal && num.isInteger())
14706
- return [bigint(num), 1n];
14715
+ return [bigint(num), BigInt(1)];
14707
14716
  return undefined;
14708
14717
  }
14709
14718
  function asMachineRational(r) {
@@ -14815,7 +14824,7 @@ function reducedRational(r) {
14815
14824
  // If the gcd is 0, return the rational unchanged
14816
14825
  return g <= 1 ? r : [r[0] / g, r[1] / g];
14817
14826
  }
14818
- if (r[0] === 1n || r[1] === 1n)
14827
+ if (r[0] === BigInt(1) || r[1] === BigInt(1))
14819
14828
  return r;
14820
14829
  if (r[1] < 0)
14821
14830
  r = [-r[0], -r[1]];
@@ -14977,7 +14986,7 @@ function asCoefficient(expr) {
14977
14986
  if (n !== null) {
14978
14987
  if (n instanceof Decimal) {
14979
14988
  if (n.isInteger())
14980
- return [[bigint(n.toString()), 1n], ce._ONE];
14989
+ return [[bigint(n.toString()), BigInt(1)], ce._ONE];
14981
14990
  if (n.isNegative())
14982
14991
  return [[-1, 1], ce.number(n.neg())];
14983
14992
  }
@@ -16414,7 +16423,7 @@ class Product {
16414
16423
  this._isCanonical = options.canonical;
16415
16424
  this.engine = ce;
16416
16425
  this._sign = 1;
16417
- this._rational = bignumPreferred(ce) ? [1n, 1n] : [1, 1];
16426
+ this._rational = bignumPreferred(ce) ? [BigInt(1), BigInt(1)] : [1, 1];
16418
16427
  // this._squareRootRational = this._rational;
16419
16428
  this._complex = Complex.ONE;
16420
16429
  this._bignum = ce._BIGNUM_ONE;
@@ -16492,7 +16501,7 @@ class Product {
16492
16501
  num = num.neg();
16493
16502
  }
16494
16503
  if (num.isInteger())
16495
- this._rational = mul(this._rational, [bigint(num), 1n]);
16504
+ this._rational = mul(this._rational, [bigint(num), BigInt(1)]);
16496
16505
  else if (bignumPreferred(this.engine))
16497
16506
  this._bignum = this._bignum.mul(num);
16498
16507
  else
@@ -18958,7 +18967,7 @@ class BoxedNumber extends AbstractBoxedExpression {
18958
18967
  console.assert(typeof n !== 'number' ||
18959
18968
  (Number.isInteger(n) && Number.isInteger(d) && d !== n && d !== 1));
18960
18969
  console.assert(!(typeof n === 'bigint' && typeof d == 'bigint') ||
18961
- (d !== n && d !== 1n));
18970
+ (d !== n && d !== BigInt(1)));
18962
18971
  if (options?.canonical ?? true) {
18963
18972
  this._value = canonicalNumber(ce, value);
18964
18973
  this._isCanonical = true;
@@ -19378,10 +19387,10 @@ function canonicalNumber(ce, value) {
19378
19387
  else {
19379
19388
  if (d < 0)
19380
19389
  [n, d] = [-n, -d];
19381
- if (d === 1n)
19390
+ if (d === BigInt(1))
19382
19391
  return ce.bignum(n);
19383
- if (d === 0n) {
19384
- if (n === 0n)
19392
+ if (d === BigInt(0)) {
19393
+ if (n === d)
19385
19394
  return NaN;
19386
19395
  return n < 0 ? -Infinity : +Infinity;
19387
19396
  }
@@ -19539,12 +19548,12 @@ function boxNumber(ce, num, options) {
19539
19548
  const [n, d] = num;
19540
19549
  if (typeof n === 'bigint' && typeof d === 'bigint') {
19541
19550
  if (n === d)
19542
- return d === 0n ? ce._NAN : ce._ONE;
19543
- if (d === 1n)
19551
+ return d === BigInt(0) ? ce._NAN : ce._ONE;
19552
+ if (d === BigInt(1))
19544
19553
  return ce.number(n, options);
19545
- if (d === -1n)
19554
+ if (d === BigInt(-1))
19546
19555
  return ce.number(-n, options);
19547
- if (n === 1n && d === 2n)
19556
+ if (n === BigInt(1) && d === BigInt(2))
19548
19557
  return ce._HALF;
19549
19558
  return new BoxedNumber(ce, [n, d], options);
19550
19559
  }
@@ -19935,7 +19944,7 @@ class Sum {
19935
19944
  options.canonical = true;
19936
19945
  this._isCanonical = options.canonical;
19937
19946
  this.engine = ce;
19938
- this._rational = bignumPreferred(ce) ? [0n, 1n] : [0, 1];
19947
+ this._rational = bignumPreferred(ce) ? [BigInt(0), BigInt(1)] : [0, 1];
19939
19948
  this._bignum = ce._BIGNUM_ZERO;
19940
19949
  this._number = 0;
19941
19950
  if (xs)
@@ -21257,7 +21266,7 @@ function evalSummation(ce, expr, range, mode) {
21257
21266
  ce.context = savedContext;
21258
21267
  return ce.add(terms).evaluate();
21259
21268
  }
21260
- let sum = bignumPreferred(ce) ? [1n, 1n] : [0, 1];
21269
+ let sum = bignumPreferred(ce) ? [BigInt(1), BigInt(1)] : [0, 1];
21261
21270
  if (!fn.scope)
21262
21271
  for (let i = lower; i <= upper; i++) {
21263
21272
  const term = fn.N();
@@ -21585,7 +21594,7 @@ function numEvalPower(ce, base, exponent) {
21585
21594
  }
21586
21595
  function processPower(ce, base, exponent, mode) {
21587
21596
  if (base.head === 'Multiply') {
21588
- let c = bignumPreferred(ce) ? [1n, 1n] : [1, 1];
21597
+ let c = bignumPreferred(ce) ? [BigInt(1), BigInt(1)] : [1, 1];
21589
21598
  const xs = [];
21590
21599
  for (const op of base.ops) {
21591
21600
  const r = asRational(op);
@@ -21645,12 +21654,15 @@ function processPower(ce, base, exponent, mode) {
21645
21654
  return ce._NAN;
21646
21655
  const sign = bigBase < 0 ? (d % 2 === 0 ? ce._I : ce._NEGATIVE_ONE) : ce._ONE;
21647
21656
  const [factor, root] = factorPower(bigBase > 0 ? bigBase : -bigBase, d);
21648
- if (root === 1n && factor === 1n)
21657
+ if (root === BigInt(1) && factor === BigInt(1))
21649
21658
  return sign;
21650
21659
  // If factor === 1, nothing special to do, fall through
21651
- if (factor !== 1n) {
21652
- if (root === 1n)
21653
- return ce.mul([sign, ce.number(n >= 0 ? factor : [1n, factor])]);
21660
+ if (factor !== BigInt(1)) {
21661
+ if (root === BigInt(1))
21662
+ return ce.mul([
21663
+ sign,
21664
+ ce.number(n >= 0 ? factor : [BigInt(1), factor]),
21665
+ ]);
21654
21666
  return ce.mul([
21655
21667
  sign,
21656
21668
  ce.number(factor),
@@ -21823,25 +21835,20 @@ function simplifyMultiply(ce, ops) {
21823
21835
  }
21824
21836
  return product.asExpression();
21825
21837
  }
21826
- function fastEvalMultiply(ops) {
21827
- let prod = 1;
21828
- for (const op of ops) {
21829
- if (typeof op.numericValue !== 'number')
21830
- return null;
21831
- prod *= op.numericValue;
21832
- }
21833
- return prod;
21834
- }
21835
21838
  function evalMultiply(ce, ops, mode = 'evaluate') {
21836
21839
  console.assert(ops.length > 1, 'evalMultiply(): no arguments');
21837
21840
  //
21838
21841
  // @fastpath
21839
21842
  //
21840
- if (mode === 'N' && ce.numericMode === 'machine') {
21843
+ if (mode === 'N') {
21841
21844
  ops = ops.map((x) => x.N());
21842
- const result = fastEvalMultiply(ops);
21843
- if (result !== null)
21844
- return ce.number(result);
21845
+ if (ce.numericMode === 'machine' &&
21846
+ ops.every((x) => typeof x.numericValue === 'number')) {
21847
+ let prod = 1;
21848
+ for (const op of ops)
21849
+ prod *= op.numericValue;
21850
+ return ce.number(prod);
21851
+ }
21845
21852
  }
21846
21853
  //
21847
21854
  // First pass: looking for early exits
@@ -21931,9 +21938,8 @@ function multiply2(op1, op2, metadata) {
21931
21938
  return ce._fn('Multiply', [c, t], metadata);
21932
21939
  }
21933
21940
  }
21934
- if (c.hash === t.hash && c.isSame(t)) {
21941
+ if (c.hash === t.hash && c.isSame(t))
21935
21942
  return square(ce, c);
21936
- }
21937
21943
  const product = new Product(ce, [c, t]);
21938
21944
  if (sign > 0)
21939
21945
  return product.asExpression();
@@ -22009,7 +22015,7 @@ function evalMultiplication(ce, expr, range, mode) {
22009
22015
  const product = ce.mul(terms);
22010
22016
  return mode === 'simplify' ? product.simplify() : product.evaluate();
22011
22017
  }
22012
- let product = bignumPreferred(ce) ? [1n, 1n] : [1, 1];
22018
+ let product = bignumPreferred(ce) ? [BigInt(1), BigInt(1)] : [1, 1];
22013
22019
  for (let i = lower; i <= upper; i++) {
22014
22020
  const n = ce.number(i);
22015
22021
  const r = fn.subs({ _1: n, _: n });
@@ -27990,7 +27996,7 @@ class ComputeEngine {
27990
27996
  // Is the denominator 1?
27991
27997
  if (isMachineRational(exponent) && exponent[1] === 1)
27992
27998
  e = exponent[0];
27993
- else if (isBigRational(exponent) && exponent[1] === 1n)
27999
+ else if (isBigRational(exponent) && exponent[1] === BigInt(1))
27994
28000
  e = Number(exponent[0]);
27995
28001
  }
27996
28002
  // x^1
@@ -28002,7 +28008,7 @@ class ComputeEngine {
28002
28008
  if (typeof r === 'number' && Number.isInteger(r))
28003
28009
  return this.number([1, r]);
28004
28010
  else if (r instanceof Decimal && r.isInteger())
28005
- return this.number([1n, bigint(r)]);
28011
+ return this.number([BigInt(1), bigint(r)]);
28006
28012
  else if (isRational(r))
28007
28013
  return this.number([r[1], r[0]]);
28008
28014
  }
@@ -28025,7 +28031,7 @@ class ComputeEngine {
28025
28031
  if (typeof n === 'number' && Number.isInteger(n))
28026
28032
  return this.number([1, n], { metadata });
28027
28033
  if (n instanceof Decimal && n.isInteger())
28028
- return this.number([1n, bigint(n)], { metadata });
28034
+ return this.number([BigInt(1), bigint(n)], { metadata });
28029
28035
  return this._fn('Divide', [this._ONE, expr], metadata);
28030
28036
  }
28031
28037
  if (expr.head === 'Sqrt')
@@ -28136,11 +28142,11 @@ class ComputeEngine {
28136
28142
  //
28137
28143
  if (options.metadata === undefined) {
28138
28144
  if (typeof value === 'bigint') {
28139
- if (value === 1n)
28145
+ if (value === BigInt(1))
28140
28146
  return this._ONE;
28141
- if (value === 0n)
28147
+ if (value === BigInt(0))
28142
28148
  return this._ZERO;
28143
- if (value === -1n)
28149
+ if (value === BigInt(-1))
28144
28150
  return this._NEGATIVE_ONE;
28145
28151
  }
28146
28152
  if (typeof value === 'number') {
@@ -28343,6 +28349,10 @@ class ComputeEngine {
28343
28349
  }
28344
28350
 
28345
28351
  // This file is the root of the `compute-engine` package
28346
- const version = '0.12.0';
28352
+ const version = '0.12.1';
28353
+ globalThis[Symbol.for('io.cortexjs.compute-engine')] = {
28354
+ ComputeEngine: ComputeEngine.constructor,
28355
+ version: '0.12.1',
28356
+ };
28347
28357
 
28348
28358
  export { ComputeEngine, isEnvironmentEntry, isFunctionEntry, isInfixEntry, isMatchfixEntry, isPostfixEntry, isPrefixEntry, isSymbolEntry, version };