@cortex-js/compute-engine 0.19.0 → 0.19.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 (101) hide show
  1. package/dist/compute-engine.esm.js +185 -119
  2. package/dist/compute-engine.js +185 -119
  3. package/dist/compute-engine.min.esm.js +9 -9
  4. package/dist/compute-engine.min.js +9 -9
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +1 -1
  12. package/dist/types/common/utils.d.ts +1 -1
  13. package/dist/types/compute-engine/assume.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  30. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  31. package/dist/types/compute-engine/compile.d.ts +1 -1
  32. package/dist/types/compute-engine/compute-engine.d.ts +1 -1
  33. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  34. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  35. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/public.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  56. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  57. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  58. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  59. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  60. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  61. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  62. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  63. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  64. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  65. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  66. package/dist/types/compute-engine/library/core.d.ts +1 -1
  67. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  68. package/dist/types/compute-engine/library/library.d.ts +1 -1
  69. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  70. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  71. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  72. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  73. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  74. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  75. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  76. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  77. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  78. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  79. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  80. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  81. package/dist/types/compute-engine/numerics/numeric.d.ts +3 -2
  82. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  83. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  84. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  85. package/dist/types/compute-engine/public.d.ts +1 -1
  86. package/dist/types/compute-engine/rules.d.ts +1 -1
  87. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  88. package/dist/types/compute-engine/solve.d.ts +1 -1
  89. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  90. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  91. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  92. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  93. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  95. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  96. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  97. package/dist/types/compute-engine.d.ts +2 -2
  98. package/dist/types/math-json/math-json-format.d.ts +1 -1
  99. package/dist/types/math-json/utils.d.ts +1 -1
  100. package/dist/types/math-json.d.ts +2 -2
  101. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.19.0 */
1
+ /** CortexJS Compute Engine 0.19.1 */
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 __create = Object.create;
@@ -12306,90 +12306,6 @@ var ComputeEngine = (() => {
12306
12306
  const t = z + gammaG + 0.5;
12307
12307
  return Math.sqrt(2 * Math.PI) * Math.pow(t, z + 0.5) * Math.exp(-t) * x;
12308
12308
  }
12309
- function fromDigits(s, base = 10) {
12310
- let value = 0;
12311
- for (let i = 0; i < s.length; i++) {
12312
- const k = {
12313
- " ": -1,
12314
- "\xA0": -1,
12315
- // NBS
12316
- "\u2000": -1,
12317
- // EN QUAD
12318
- "\u2001": -1,
12319
- // EM QUAD
12320
- "\u2002": -1,
12321
- // EN SPACE
12322
- "\u2003": -1,
12323
- // EM SPACE
12324
- "\u2004": -1,
12325
- // THREE-PER-EM SPACE
12326
- "\u2005": -1,
12327
- // FOUR-PER-EM SPACE
12328
- "\u2006": -1,
12329
- // SIX-PER-EM SPACE
12330
- "\u2007": -1,
12331
- // FIGURE SPACE
12332
- "\u2008": -1,
12333
- // PUNCTUATION SPACE
12334
- "\u2009": -1,
12335
- // THIN SPACE
12336
- "\u200A": -1,
12337
- // HAIR SPACE
12338
- "\u200B": -1,
12339
- // ZWS
12340
- "\u202F": -1,
12341
- // NARROW NBS
12342
- "\u205F": -1,
12343
- // MEDIUM MATHEMATICAL SPACE
12344
- "_": -1,
12345
- ",": -1,
12346
- "0": 0,
12347
- "1": 1,
12348
- "2": 2,
12349
- "3": 3,
12350
- "4": 4,
12351
- "5": 5,
12352
- "6": 6,
12353
- "7": 7,
12354
- "8": 8,
12355
- "9": 9,
12356
- "a": 10,
12357
- "b": 11,
12358
- "c": 12,
12359
- "d": 13,
12360
- "e": 14,
12361
- "f": 15,
12362
- "g": 16,
12363
- "h": 17,
12364
- "i": 18,
12365
- "j": 19,
12366
- "k": 20,
12367
- "l": 21,
12368
- "m": 22,
12369
- "n": 23,
12370
- "o": 24,
12371
- "p": 25,
12372
- "q": 26,
12373
- "r": 27,
12374
- "s": 28,
12375
- "t": 29,
12376
- "u": 30,
12377
- "v": 31,
12378
- "w": 32,
12379
- "x": 33,
12380
- "y": 34,
12381
- "z": 35
12382
- }[s[i]];
12383
- if (k !== -1) {
12384
- if (k === void 0)
12385
- return [value, s.substring(i)];
12386
- if (k >= base)
12387
- return [value, s.substring(i)];
12388
- value = value * base + k;
12389
- }
12390
- }
12391
- return [value, ""];
12392
- }
12393
12309
  function asFloat(expr) {
12394
12310
  if (expr === void 0 || expr === null)
12395
12311
  return null;
@@ -12540,6 +12456,148 @@ var ComputeEngine = (() => {
12540
12456
  const [val, err] = extrapolate(f, x, { step: dir > 0 ? 1 : -1 });
12541
12457
  return val;
12542
12458
  }
12459
+ function fromRoman(roman) {
12460
+ if (roman === "N")
12461
+ return [0, ""];
12462
+ const romanMap = {
12463
+ I: 1,
12464
+ V: 5,
12465
+ X: 10,
12466
+ L: 50,
12467
+ C: 100,
12468
+ D: 500,
12469
+ M: 1e3
12470
+ };
12471
+ let total = 0;
12472
+ let prevValue = 0;
12473
+ roman = roman.toUpperCase();
12474
+ for (let i = roman.length - 1; i >= 0; i--) {
12475
+ const currentValue = romanMap[roman[i]];
12476
+ if (currentValue === void 0)
12477
+ return [total, roman.slice(i)];
12478
+ if (currentValue < prevValue)
12479
+ total -= currentValue;
12480
+ else
12481
+ total += currentValue;
12482
+ prevValue = currentValue;
12483
+ }
12484
+ return [total, ""];
12485
+ }
12486
+ function fromDigits(s, baseInput) {
12487
+ s = s.trim();
12488
+ if (s.length === 0)
12489
+ return [NaN, ""];
12490
+ if (s.startsWith("+"))
12491
+ return fromDigits(s.slice(1), baseInput);
12492
+ if (s.startsWith("-")) {
12493
+ const [v, r] = fromDigits(s.slice(1), baseInput);
12494
+ return [-v, r];
12495
+ }
12496
+ let base = 10;
12497
+ if (typeof baseInput === "string")
12498
+ baseInput = baseInput.toLowerCase();
12499
+ if (s.startsWith("0x")) {
12500
+ base = 16;
12501
+ s = s.slice(2);
12502
+ } else if (s.startsWith("0b")) {
12503
+ base = 2;
12504
+ s = s.slice(2);
12505
+ } else if (baseInput === "roman") {
12506
+ return fromRoman(s);
12507
+ } else if (baseInput === "base64" || baseInput === "base-64") {
12508
+ try {
12509
+ return [parseInt(btoa(s)), ""];
12510
+ } catch (e) {
12511
+ return [NaN, ""];
12512
+ }
12513
+ } else if (typeof baseInput === "number") {
12514
+ base = baseInput;
12515
+ } else if (typeof baseInput === "string") {
12516
+ base = parseInt(baseInput);
12517
+ }
12518
+ let value = 0;
12519
+ for (let i = 0; i < s.length; i++) {
12520
+ const k = {
12521
+ " ": -1,
12522
+ "\xA0": -1,
12523
+ // NBS
12524
+ "\u2000": -1,
12525
+ // EN QUAD
12526
+ "\u2001": -1,
12527
+ // EM QUAD
12528
+ "\u2002": -1,
12529
+ // EN SPACE
12530
+ "\u2003": -1,
12531
+ // EM SPACE
12532
+ "\u2004": -1,
12533
+ // THREE-PER-EM SPACE
12534
+ "\u2005": -1,
12535
+ // FOUR-PER-EM SPACE
12536
+ "\u2006": -1,
12537
+ // SIX-PER-EM SPACE
12538
+ "\u2007": -1,
12539
+ // FIGURE SPACE
12540
+ "\u2008": -1,
12541
+ // PUNCTUATION SPACE
12542
+ "\u2009": -1,
12543
+ // THIN SPACE
12544
+ "\u200A": -1,
12545
+ // HAIR SPACE
12546
+ "\u200B": -1,
12547
+ // ZWS
12548
+ "\u202F": -1,
12549
+ // NARROW NBS
12550
+ "\u205F": -1,
12551
+ // MEDIUM MATHEMATICAL SPACE
12552
+ "_": -1,
12553
+ ",": -1,
12554
+ "0": 0,
12555
+ "1": 1,
12556
+ "2": 2,
12557
+ "3": 3,
12558
+ "4": 4,
12559
+ "5": 5,
12560
+ "6": 6,
12561
+ "7": 7,
12562
+ "8": 8,
12563
+ "9": 9,
12564
+ "a": 10,
12565
+ "b": 11,
12566
+ "c": 12,
12567
+ "d": 13,
12568
+ "e": 14,
12569
+ "f": 15,
12570
+ "g": 16,
12571
+ "h": 17,
12572
+ "i": 18,
12573
+ "j": 19,
12574
+ "k": 20,
12575
+ "l": 21,
12576
+ "m": 22,
12577
+ "n": 23,
12578
+ "o": 24,
12579
+ "p": 25,
12580
+ "q": 26,
12581
+ "r": 27,
12582
+ "s": 28,
12583
+ "t": 29,
12584
+ "u": 30,
12585
+ "v": 31,
12586
+ "w": 32,
12587
+ "x": 33,
12588
+ "y": 34,
12589
+ "z": 35
12590
+ }[s[i]];
12591
+ if (k !== -1) {
12592
+ if (k === void 0)
12593
+ return [value, s.substring(i)];
12594
+ if (k >= base)
12595
+ return [value, s.substring(i)];
12596
+ value = value * base + k;
12597
+ }
12598
+ }
12599
+ return [value, ""];
12600
+ }
12543
12601
 
12544
12602
  // src/compute-engine/numerics/numeric-bigint.ts
12545
12603
  function bigint(a) {
@@ -20726,23 +20784,24 @@ var ComputeEngine = (() => {
20726
20784
  // @todo could accept `0xcafe`, `0b01010` or `(deadbeef)_16` as string formats
20727
20785
  // @todo could accept "roman"... as base
20728
20786
  // @todo could accept optional third parameter as the (padded) length of the output
20729
- threadable: true,
20730
20787
  signature: {
20731
- domain: ["FunctionOf", "Strings", ["OptArg", "Integers"], "Integers"],
20788
+ domain: ["FunctionOf", "Strings", ["OptArg", "Anything"], "Integers"],
20732
20789
  evaluate: (ce, ops2) => {
20733
- const op12 = ops2[0];
20734
- if (!op12.string)
20735
- return ce.domainError("Strings", op12.domain, op12);
20736
- const op22 = ops2[1];
20790
+ let op12 = ops2[0]?.string;
20791
+ if (!op12)
20792
+ return ce.domainError("Strings", ops2[0]?.domain, ops2[0]);
20793
+ op12 = op12.trim();
20794
+ if (op12.startsWith("0x"))
20795
+ return ce.number(parseInt(op12.slice(2), 16));
20796
+ if (op12.startsWith("0b"))
20797
+ return ce.number(parseInt(op12.slice(2), 2));
20798
+ const op22 = ops2[1] ?? ce.Nothing;
20737
20799
  if (op22.isNothing)
20738
- return ce.number(Number.parseInt(op12.string, 10));
20739
- if (op22.numericValue === null) {
20740
- return ce.error(["unexpected-base", op22.latex], op22);
20741
- }
20800
+ return ce.number(Number.parseInt(op12, 10));
20742
20801
  const base = asFloat(op22);
20743
- if (!Number.isInteger(base) || base < 2 || base > 36)
20802
+ if (base && (!Number.isInteger(base) || base < 2 || base > 36))
20744
20803
  return ce.error(["unexpected-base", base], op22);
20745
- const [value, rest] = fromDigits(op12.string, base);
20804
+ const [value, rest] = fromDigits(op12, op22.string ?? op22.symbol ?? 10);
20746
20805
  if (rest)
20747
20806
  return ce.error(["unexpected-digit", { str: rest[0] }], {
20748
20807
  str: rest
@@ -20764,7 +20823,7 @@ var ComputeEngine = (() => {
20764
20823
  const val = asFloat(op12) ?? NaN;
20765
20824
  if (Number.isNaN(val) || !Number.isInteger(val))
20766
20825
  return ce.domainError("Integers", op12.domain, op12);
20767
- const op22 = ops2[1];
20826
+ const op22 = ops2[1] ?? ce.Nothing;
20768
20827
  if (op22.isNothing) {
20769
20828
  const op1Num = op12.numericValue;
20770
20829
  if (typeof op1Num === "number")
@@ -27443,19 +27502,19 @@ ${JSON.stringify(entry)}`
27443
27502
  if (symDef) {
27444
27503
  if (symDef.constant)
27445
27504
  throw Error(`Cannot assign a value to the constant "${id}"`);
27446
- if (args)
27447
- throw Error(`The symbol "${id}" is not a function`);
27448
- if (typeof value === "function")
27505
+ if (!symDef.inferredDomain && isFunctionValue(value))
27449
27506
  throw Error(`Cannot assign a function to symbol "${id}"`);
27450
- if (value === void 0 || value === null) {
27451
- symDef.value = void 0;
27452
- return this;
27453
- }
27454
27507
  const scope = symDef.scope;
27455
27508
  scope?.ids?.delete(symDef.name);
27456
- symDef.value = this.box(value);
27457
- scope?.ids?.set(symDef.name, symDef);
27458
- return this;
27509
+ if (!args && !isFunctionValue(value)) {
27510
+ if (value === void 0 || value === null) {
27511
+ symDef.value = void 0;
27512
+ return this;
27513
+ }
27514
+ symDef.value = this.box(value);
27515
+ scope?.ids?.set(symDef.name, symDef);
27516
+ return this;
27517
+ }
27459
27518
  }
27460
27519
  const fnDef = this.lookupFunction(id);
27461
27520
  if (fnDef) {
@@ -27465,17 +27524,15 @@ ${JSON.stringify(entry)}`
27465
27524
  return this;
27466
27525
  if (typeof value === "function") {
27467
27526
  const previousScope2 = this.swapScope(scope);
27468
- this.defineFunction(id, {
27469
- signature: { evaluate: value }
27470
- });
27527
+ this.defineFunction(id, { signature: { evaluate: value } });
27471
27528
  this.swapScope(previousScope2);
27472
27529
  return this;
27473
27530
  }
27531
+ if (args && isFunctionValue(value))
27532
+ throw Error(`Unexpected arguments for "${id}"`);
27474
27533
  const val = args ? this.box(["Function", value, ...args]) : this.box(value);
27475
27534
  const previousScope = this.swapScope(scope);
27476
- this.defineFunction(id, {
27477
- signature: { evaluate: val }
27478
- });
27535
+ this.defineFunction(id, { signature: { evaluate: val } });
27479
27536
  this.swapScope(previousScope);
27480
27537
  return this;
27481
27538
  }
@@ -27484,9 +27541,11 @@ ${JSON.stringify(entry)}`
27484
27541
  return this;
27485
27542
  }
27486
27543
  if (typeof value === "function") {
27487
- this.defineFunction(id, {
27488
- signature: { evaluate: value }
27489
- });
27544
+ this.defineFunction(id, { signature: { evaluate: value } });
27545
+ return this;
27546
+ }
27547
+ if (value instanceof _BoxedExpression && value.domain?.base === "Functions") {
27548
+ this.defineFunction(id, { signature: { evaluate: value } });
27490
27549
  return this;
27491
27550
  }
27492
27551
  if (Array.isArray(value) || value instanceof _BoxedExpression || args) {
@@ -28076,12 +28135,19 @@ ${JSON.stringify(entry)}`
28076
28135
  }
28077
28136
  }
28078
28137
  };
28138
+ function isFunctionValue(value) {
28139
+ if (typeof value === "function")
28140
+ return true;
28141
+ if (value instanceof _BoxedExpression && value.domain?.base === "Functions")
28142
+ return true;
28143
+ return false;
28144
+ }
28079
28145
 
28080
28146
  // src/compute-engine.ts
28081
- var version = "0.19.0";
28147
+ var version = "0.19.1";
28082
28148
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
28083
28149
  ComputeEngine: ComputeEngine.prototype.constructor,
28084
- version: "0.19.0"
28150
+ version: "0.19.1"
28085
28151
  };
28086
28152
  return __toCommonJS(compute_engine_exports);
28087
28153
  })();