@cortex-js/compute-engine 0.12.4 → 0.12.5

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 (89) hide show
  1. package/dist/compute-engine.esm.js +94 -60
  2. package/dist/compute-engine.js +94 -60
  3. package/dist/compute-engine.min.esm.js +94 -60
  4. package/dist/compute-engine.min.js +94 -60
  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/grapheme-splitter.d.ts +1 -1
  10. package/dist/types/common/signals.d.ts +1 -1
  11. package/dist/types/common/utils.d.ts +1 -1
  12. package/dist/types/compute-engine/assume.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +2 -2
  19. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  29. package/dist/types/compute-engine/compute-engine.d.ts +4 -2
  30. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  31. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/parse.d.ts +4 -2
  46. package/dist/types/compute-engine/latex-syntax/public.d.ts +2 -2
  47. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  51. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  52. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  53. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  54. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  55. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  56. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  57. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  58. package/dist/types/compute-engine/library/core.d.ts +1 -1
  59. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  60. package/dist/types/compute-engine/library/library.d.ts +1 -1
  61. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  62. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  63. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  64. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  65. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  66. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  67. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  68. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  69. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  70. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  71. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  72. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  73. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  74. package/dist/types/compute-engine/public.d.ts +5 -3
  75. package/dist/types/compute-engine/rules.d.ts +1 -1
  76. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  77. package/dist/types/compute-engine/solve.d.ts +1 -1
  78. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  79. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  80. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  81. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  82. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  83. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  84. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  85. package/dist/types/compute-engine.d.ts +2 -2
  86. package/dist/types/math-json/math-json-format.d.ts +1 -1
  87. package/dist/types/math-json/utils.d.ts +1 -1
  88. package/dist/types/math-json.d.ts +2 -2
  89. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.12.4 */
1
+ /** CortexJS Compute Engine 0.12.5 */
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;
@@ -4608,6 +4608,15 @@ var ComputeEngine = (() => {
4608
4608
  parse: "ExponentialE",
4609
4609
  serialize: "\\exponentialE"
4610
4610
  },
4611
+ {
4612
+ kind: "function",
4613
+ trigger: "exp",
4614
+ parse: (parser) => ["Exp", ...parser.matchArguments("enclosure") ?? []]
4615
+ },
4616
+ {
4617
+ trigger: "\\exp",
4618
+ parse: (parser) => ["Exp", ...parser.matchArguments("enclosure") ?? []]
4619
+ },
4611
4620
  {
4612
4621
  name: "ImaginaryUnit",
4613
4622
  trigger: ["\\imaginaryI"]
@@ -4731,11 +4740,12 @@ var ComputeEngine = (() => {
4731
4740
  },
4732
4741
  {
4733
4742
  name: "Exp",
4734
- serialize: (serializer, expr) => joinLatex([
4735
- "\\exponentialE^{",
4736
- serializer.serialize(missingIfEmpty(op(expr, 1))),
4737
- "}"
4738
- ])
4743
+ serialize: (serializer, expr) => {
4744
+ const op12 = op(expr, 1);
4745
+ if (symbol(op12) || machineValue(op12) !== null)
4746
+ return joinLatex(["\\exponentialE^{", serializer.serialize(op12)]);
4747
+ return joinLatex(["\\exp", serializer.wrap(missingIfEmpty(op12))]);
4748
+ }
4739
4749
  },
4740
4750
  {
4741
4751
  name: "Factorial",
@@ -4912,7 +4922,31 @@ var ComputeEngine = (() => {
4912
4922
  trigger: ["\\pm"],
4913
4923
  kind: "infix",
4914
4924
  associativity: "both",
4915
- precedence: 270
4925
+ precedence: 270,
4926
+ serialize: (serializer, expr) => {
4927
+ const op12 = op(expr, 1);
4928
+ if (op12 === null)
4929
+ return "\\pm";
4930
+ if (nops(expr) === 1)
4931
+ return joinLatex(["\\pm", serializer.serialize(op12)]);
4932
+ const op22 = op(expr, 2);
4933
+ return joinLatex([
4934
+ serializer.serialize(op12),
4935
+ "\\pm",
4936
+ serializer.serialize(op22)
4937
+ ]);
4938
+ }
4939
+ },
4940
+ {
4941
+ trigger: ["\\pm"],
4942
+ kind: "prefix",
4943
+ precedence: 270,
4944
+ parse: (parser, terminator) => {
4945
+ if (270 < terminator.minPrec)
4946
+ return null;
4947
+ const rhs = parser.matchExpression({ ...terminator, minPrec: 400 });
4948
+ return ["PlusMinus", missingIfEmpty(rhs)];
4949
+ }
4916
4950
  },
4917
4951
  {
4918
4952
  name: "Power",
@@ -5641,7 +5675,7 @@ var ComputeEngine = (() => {
5641
5675
  kind: "infix",
5642
5676
  associativity: "right",
5643
5677
  precedence: 241,
5644
- parse: "Equal"
5678
+ parse: "LessEqual"
5645
5679
  },
5646
5680
  {
5647
5681
  trigger: ["\\leqslant"],
@@ -7425,7 +7459,7 @@ var ComputeEngine = (() => {
7425
7459
  message: [
7426
7460
  "invalid-dictionary-entry",
7427
7461
  indexedEntry.name,
7428
- "Duplicate definition"
7462
+ "Duplicate definition. The name must be unique, but a trigger can be used by multiple definitions."
7429
7463
  ]
7430
7464
  });
7431
7465
  }
@@ -8722,6 +8756,8 @@ var ComputeEngine = (() => {
8722
8756
  * - 'enclosure' : will look for an argument inside an enclosure (open/close fence)
8723
8757
  * - 'implicit': either an expression inside a pair of `()`, or just a product
8724
8758
  * (i.e. we interpret `\cos 2x + 1` as `\cos(2x) + 1`)
8759
+ *
8760
+ * This returns an array of arguments, or null if there is no match.
8725
8761
  */
8726
8762
  matchArguments(kind, until) {
8727
8763
  if (!kind)
@@ -8730,23 +8766,15 @@ var ComputeEngine = (() => {
8730
8766
  return null;
8731
8767
  const savedIndex = this.index;
8732
8768
  const group = this.matchEnclosure();
8733
- if (kind === "enclosure" && head(group) === "Delimiter") {
8734
- if (op(group, 1) === "Sequence")
8735
- return ops(op(group, 1)) ?? [];
8736
- return [op(group, 1) ?? ["Sequence"]];
8737
- }
8769
+ if (kind === "enclosure")
8770
+ return getSequence(group) ?? [];
8738
8771
  if (kind === "implicit") {
8739
- if (head(group) === "Delimiter") {
8740
- if (head(op(group, 1)) === "Sequence")
8741
- return getSequence(group) ?? [];
8742
- return [op(group, 1) ?? ["Sequence"]];
8743
- }
8772
+ if (head(group) === "Delimiter")
8773
+ return getSequence(group) ?? [];
8744
8774
  if (group !== null)
8745
8775
  return [group];
8746
8776
  const primary = this.matchExpression({ ...until, minPrec: 390 });
8747
- if (primary !== null)
8748
- return [primary];
8749
- return null;
8777
+ return primary === null ? null : [primary];
8750
8778
  }
8751
8779
  this.index = savedIndex;
8752
8780
  return null;
@@ -8766,7 +8794,7 @@ var ComputeEngine = (() => {
8766
8794
  fn = pf;
8767
8795
  } while (true);
8768
8796
  const seq = this.matchArguments("enclosure");
8769
- return seq ? [fn, ...seq] : id;
8797
+ return seq ? [fn, ...seq] : fn;
8770
8798
  }
8771
8799
  /** A prime suffix is a sequence of `'`, `\prime` or `\doubleprime`
8772
8800
  * after a function or in a superscript.
@@ -9175,7 +9203,7 @@ var ComputeEngine = (() => {
9175
9203
  this.index = index;
9176
9204
  return result;
9177
9205
  }
9178
- matchPostfix(lhs) {
9206
+ matchPostfix(lhs, until) {
9179
9207
  /* @__PURE__ */ console.assert(lhs !== null);
9180
9208
  if (lhs === null)
9181
9209
  return null;
@@ -9185,7 +9213,7 @@ var ComputeEngine = (() => {
9185
9213
  const start = this.index;
9186
9214
  for (const [def, n] of defs) {
9187
9215
  this.index = start + n;
9188
- const result = def.parse(this, lhs);
9216
+ const result = def.parse(this, lhs, until);
9189
9217
  if (result !== null)
9190
9218
  return result;
9191
9219
  }
@@ -9531,7 +9559,7 @@ var ComputeEngine = (() => {
9531
9559
  let postfix = null;
9532
9560
  let index = this.index;
9533
9561
  do {
9534
- postfix = this.matchPostfix(result);
9562
+ postfix = this.matchPostfix(result, until);
9535
9563
  result = postfix ?? result;
9536
9564
  if (this.index === index && postfix !== null) {
9537
9565
  /* @__PURE__ */ console.assert(this.index !== index, "No token consumed");
@@ -15391,7 +15419,7 @@ var ComputeEngine = (() => {
15391
15419
  const ce = expr.engine;
15392
15420
  if (expr.op1.head === "Negate") {
15393
15421
  const sign2 = exp2 % 2 === 0 ? 1 : -1;
15394
- const result2 = expandMultinomial(ce.box(["Power", expr.op1.op1, expr.op2]));
15422
+ const result2 = expandMultinomial(ce.pow(expr.op1.op1, expr.op2));
15395
15423
  if (result2 === null)
15396
15424
  return null;
15397
15425
  if (sign2 > 0)
@@ -15616,15 +15644,14 @@ var ComputeEngine = (() => {
15616
15644
  const sols = findUnivariateRoots(proposition, lhs2);
15617
15645
  if (sols.length === 0) {
15618
15646
  ce.assumptions.set(
15619
- ce.box([
15620
- "Equal",
15647
+ ce.fn("Equal", [
15621
15648
  ce.add([proposition.op1.canonical, ce.neg(proposition.op2.canonical)]).simplify(),
15622
15649
  0
15623
15650
  ]),
15624
15651
  true
15625
15652
  );
15626
15653
  }
15627
- const val = sols.length === 1 ? sols[0] : ce.box(["List", ...sols]);
15654
+ const val = sols.length === 1 ? sols[0] : ce.fn("List", sols);
15628
15655
  const def = ce.lookupSymbol(lhs2);
15629
15656
  if (!def) {
15630
15657
  ce.defineSymbol(lhs2, { value: val });
@@ -16605,7 +16632,6 @@ var ComputeEngine = (() => {
16605
16632
  return result;
16606
16633
  }
16607
16634
  solve(vars) {
16608
- /* @__PURE__ */ console.log("solve this:", this.toString());
16609
16635
  if (vars.length !== 1)
16610
16636
  return null;
16611
16637
  const roots = findUnivariateRoots(this.simplify(), vars[0]);
@@ -16684,6 +16710,8 @@ var ComputeEngine = (() => {
16684
16710
  xs.push(y);
16685
16711
  }
16686
16712
  }
16713
+ if (!xs.every((x) => x.isValid))
16714
+ return new BoxedFunction(ce, head2, xs, { metadata, canonical: false });
16687
16715
  const sig = def.signature;
16688
16716
  if (sig.canonical) {
16689
16717
  try {
@@ -16714,21 +16742,22 @@ var ComputeEngine = (() => {
16714
16742
  return new BoxedFunction(ce, head2, xs, { metadata, def, canonical: true });
16715
16743
  }
16716
16744
  function apply(fn, args) {
16745
+ const ce = fn.engine;
16717
16746
  if (fn.head !== "Lambda")
16718
- return fn.engine._fn(fn.evaluate(), args);
16747
+ return ce._fn(fn.evaluate(), args);
16719
16748
  const subs2 = {
16720
- "__": fn.engine.tuple(args),
16721
- "_#": fn.engine.number(args.length)
16749
+ "__": ce.tuple(args),
16750
+ "_#": ce.number(args.length)
16722
16751
  };
16723
16752
  let n = 1;
16724
16753
  for (const op3 of args)
16725
16754
  subs2[`_${n++}`] = op3;
16726
16755
  subs2["_"] = subs2["_1"];
16727
- const savedContext = this.context;
16728
- this.context = fn.scope ?? null;
16729
- const result = fn.subs(subs2).evaluate();
16730
- this.context = savedContext;
16731
- return result;
16756
+ const savedContext = ce.context;
16757
+ ce.context = fn.scope ?? null;
16758
+ const result = fn.subs(subs2);
16759
+ ce.context = savedContext;
16760
+ return result.op1.evaluate();
16732
16761
  }
16733
16762
  function holdMap(xs, skip, associativeHead, f) {
16734
16763
  if (xs.length === 0)
@@ -18841,7 +18870,7 @@ var ComputeEngine = (() => {
18841
18870
  return ce._NEGATIVE_INFINITY;
18842
18871
  if (ops2.length === 1)
18843
18872
  return ops2[0];
18844
- return ce.box(["Max", ...ops2]);
18873
+ return ce.fn("Max", ops2);
18845
18874
  },
18846
18875
  evaluate: (ce, ops2) => {
18847
18876
  if (ops2.length === 0)
@@ -18870,7 +18899,7 @@ var ComputeEngine = (() => {
18870
18899
  return ce._NEGATIVE_INFINITY;
18871
18900
  if (ops2.length === 1)
18872
18901
  return ops2[0];
18873
- return ce.box(["Min", ...ops2]);
18902
+ return ce.fn("Min", ops2);
18874
18903
  },
18875
18904
  evaluate: (ce, ops2) => {
18876
18905
  if (ops2.length === 0)
@@ -19211,7 +19240,7 @@ var ComputeEngine = (() => {
19211
19240
  e: {
19212
19241
  domain: "TranscendentalNumber",
19213
19242
  constant: true,
19214
- holdUntil: "never",
19243
+ holdUntil: "N",
19215
19244
  value: "ExponentialE"
19216
19245
  },
19217
19246
  i: {
@@ -19237,14 +19266,13 @@ var ComputeEngine = (() => {
19237
19266
  },
19238
19267
  Half: {
19239
19268
  constant: true,
19240
- holdUntil: "never",
19269
+ holdUntil: "evaluate",
19241
19270
  value: ["Rational", 1, 2]
19242
19271
  },
19243
19272
  ImaginaryUnit: {
19244
19273
  domain: "ImaginaryNumber",
19245
19274
  constant: true,
19246
- holdUntil: "evaluate",
19247
- // @todo maybe?
19275
+ holdUntil: "never",
19248
19276
  wikidata: "Q193796",
19249
19277
  flags: { imaginary: true },
19250
19278
  value: ["Complex", 0, 1]
@@ -20072,8 +20100,7 @@ var ComputeEngine = (() => {
20072
20100
  signature: {
20073
20101
  domain: ["Function", ["Maybe", ["Sequence", "Anything"]], "String"],
20074
20102
  evaluate: (ce, ops2) => {
20075
- return ce.box([
20076
- "Latex",
20103
+ return ce.fn("Latex", [
20077
20104
  ce.string(tokensToString(ops2.map((x) => x.string ?? x.latex)))
20078
20105
  ]);
20079
20106
  }
@@ -20096,7 +20123,7 @@ var ComputeEngine = (() => {
20096
20123
  hold: "all",
20097
20124
  signature: {
20098
20125
  domain: ["Function", ["Maybe", ["Sequence", "Anything"]], "String"],
20099
- evaluate: (ce, ops2) => ce.box(["Latex", ce.string(joinLatex(ops2.map((x) => x.latex)))])
20126
+ evaluate: (ce, ops2) => ce.fn("Latex", [ce.string(joinLatex(ops2.map((x) => x.latex)))])
20100
20127
  }
20101
20128
  },
20102
20129
  SplitAsLatexTokens: {
@@ -20933,13 +20960,13 @@ var ComputeEngine = (() => {
20933
20960
  "Number"
20934
20961
  ]);
20935
20962
  if (ops2.length !== 1)
20936
- return ce.box(["Degrees", ops2]);
20963
+ return ce.fn("Degrees", ops2, { canonical: false });
20937
20964
  const arg = ops2[0];
20938
20965
  if (arg.numericValue === null || !arg.isValid)
20939
- return ce.box(["Degrees", arg]);
20966
+ return ce.fn("Degrees", ops2, { canonical: false });
20940
20967
  return ce.div(ce.mul([arg, ce.symbol("Pi")]), ce.number(180));
20941
20968
  },
20942
- evaluate: (ce, ops2) => ce.mul([ops2[0], ce.box(["Divide", "Pi", 180])])
20969
+ evaluate: (ce, ops2) => ce.mul([ops2[0], ce.div(ce.symbol("Pi"), ce.number(180))])
20943
20970
  }
20944
20971
  },
20945
20972
  Hypot: {
@@ -21459,6 +21486,8 @@ var ComputeEngine = (() => {
21459
21486
  ]
21460
21487
  };
21461
21488
  function constructibleValues(ce, head2, x) {
21489
+ if (!x)
21490
+ return void 0;
21462
21491
  const specialValues = ce.cache(
21463
21492
  "constructible-trigonometric-values",
21464
21493
  () => {
@@ -21535,6 +21564,8 @@ var ComputeEngine = (() => {
21535
21564
  return newHead ? ce.symbol(newHead) : void 0;
21536
21565
  }
21537
21566
  function evalTrig(ce, mode, head2, op3) {
21567
+ if (!op3)
21568
+ return void 0;
21538
21569
  if (mode === "evaluate") {
21539
21570
  const result = constructibleValues(ce, head2, op3)?.evaluate();
21540
21571
  if (result)
@@ -21732,7 +21763,7 @@ var ComputeEngine = (() => {
21732
21763
  this._flags = def.flags ? normalizeFlags(def.flags) : void 0;
21733
21764
  this._domain = def.domain ? ce.domain(def.domain) : void 0;
21734
21765
  this.constant = def.constant ?? false;
21735
- this.holdUntil = def.holdUntil ?? "simplify";
21766
+ this.holdUntil = def.holdUntil ?? "evaluate";
21736
21767
  if (this.constant) {
21737
21768
  this._defValue = def.value;
21738
21769
  this._value = null;
@@ -23388,17 +23419,20 @@ ${JSON.stringify(entry)}`
23388
23419
  }
23389
23420
  simplify(options) {
23390
23421
  const def = this.symbolDefinition;
23391
- if ((def?.holdUntil === "never" || def?.holdUntil === "simplify") && def.value)
23422
+ if (def?.holdUntil === "simplify" && def.value)
23392
23423
  return def.value.simplify(options);
23393
23424
  return options?.rules ? this.replace(options.rules) ?? this : this;
23394
23425
  }
23395
23426
  evaluate(options) {
23396
23427
  const def = this.symbolDefinition;
23397
- if (def?.holdUntil !== "N")
23398
- return def?.value?.evaluate(options) ?? this;
23428
+ if (def && (def.holdUntil === "simplify" || def.holdUntil === "evaluate"))
23429
+ return def.value?.evaluate(options) ?? this;
23399
23430
  return this;
23400
23431
  }
23401
23432
  N(options) {
23433
+ const def = this.symbolDefinition;
23434
+ if (def && def.holdUntil === "never")
23435
+ return this;
23402
23436
  return this.symbolDefinition?.value?.N(options) ?? this;
23403
23437
  }
23404
23438
  replace(rules, options) {
@@ -23811,7 +23845,7 @@ ${JSON.stringify(entry)}`
23811
23845
  precision: this.precision,
23812
23846
  avoidExponentsInRange: [-6, this.precision],
23813
23847
  onError: (err) => {
23814
- throw new Error(err[0].message.toString());
23848
+ throw new Error(JSON.stringify(err[0].message));
23815
23849
  }
23816
23850
  });
23817
23851
  return this._latexSyntax;
@@ -24075,8 +24109,8 @@ ${JSON.stringify(entry)}`
24075
24109
  const bxs = xs;
24076
24110
  return bxs.every((x) => x.isCanonical) ? bxs : bxs.map((x) => x.canonical);
24077
24111
  }
24078
- fn(head2, ops2, metadata) {
24079
- return boxFunction(this, head2, ops2, { metadata, canonical: true });
24112
+ fn(head2, ops2, options) {
24113
+ return boxFunction(this, head2, ops2, options ?? { canonical: true });
24080
24114
  }
24081
24115
  /** @internal */
24082
24116
  _fn(head2, ops2, metadata) {
@@ -24490,10 +24524,10 @@ ${JSON.stringify(entry)}`
24490
24524
  };
24491
24525
 
24492
24526
  // src/compute-engine.ts
24493
- var version = "0.12.4";
24527
+ var version = "0.12.5";
24494
24528
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
24495
24529
  ComputeEngine: ComputeEngine.prototype.constructor,
24496
- version: "0.12.4"
24530
+ version: "0.12.5"
24497
24531
  };
24498
24532
  return __toCommonJS(compute_engine_exports);
24499
24533
  })();
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.12.4 */
1
+ /** CortexJS Compute Engine 0.12.5 */
2
2
 
3
3
  // src/math-json/utils.ts
4
4
  function isSymbolObject(expr) {
@@ -239,7 +239,7 @@ function mapArgs(expr, fn) {
239
239
  }
240
240
 
241
241
  // src/math-json.ts
242
- var version = "0.12.4";
242
+ var version = "0.12.5";
243
243
  export {
244
244
  applyRecursively,
245
245
  dictionary as getDictionary,
package/dist/math-json.js CHANGED
@@ -1,4 +1,4 @@
1
- /** CortexJS MathJSON 0.12.4 */
1
+ /** CortexJS MathJSON 0.12.5 */
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.MathJson = {}));})(this, (function (exports) { 'use strict';
3
3
  var MathJson = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -277,7 +277,7 @@ var MathJson = (() => {
277
277
  }
278
278
 
279
279
  // src/math-json.ts
280
- var version = "0.12.4";
280
+ var version = "0.12.5";
281
281
  return __toCommonJS(math_json_exports);
282
282
  })();
283
283
  Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,4 +1,4 @@
1
- /** CortexJS Compute Engine 0.12.4 */
1
+ /** CortexJS Compute Engine 0.12.5 */
2
2
 
3
3
  // src/math-json/utils.ts
4
4
  function isSymbolObject(expr) {
@@ -239,7 +239,7 @@ function mapArgs(expr, fn) {
239
239
  }
240
240
 
241
241
  // src/math-json.ts
242
- var version = "0.12.4";
242
+ var version = "0.12.5";
243
243
  export {
244
244
  applyRecursively,
245
245
  dictionary as getDictionary,
@@ -1,4 +1,4 @@
1
- /** CortexJS MathJSON 0.12.4 */
1
+ /** CortexJS MathJSON 0.12.5 */
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.MathJson = {}));})(this, (function (exports) { 'use strict';
3
3
  var MathJson = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -277,7 +277,7 @@ var MathJson = (() => {
277
277
  }
278
278
 
279
279
  // src/math-json.ts
280
- var version = "0.12.4";
280
+ var version = "0.12.5";
281
281
  return __toCommonJS(math_json_exports);
282
282
  })();
283
283
  Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  /**
3
3
  * Return a string or an array of graphemes.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export type SignalCode = RuntimeSignalCode | ('invalid-name' | 'expected-predicate' | 'expected-symbol' | 'operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'prefix-operator-requires-one-operand' | 'unbalanced-symbols' | 'expected-argument' | 'unexpected-command' | 'cyclic-definition' | 'invalid-supersets' | 'expected-supersets' | 'unknown-domain' | 'duplicate-wikidata' | 'invalid-dictionary-entry' | 'syntax-error');
3
3
  export type SignalMessage = SignalCode | [SignalCode, ...any[]];
4
4
  export type SignalOrigin = {
@@ -1 +1 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  /**
3
3
  * Add an assumption, in the form of a predicate, for example:
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, BoxedFunctionDefinition, BoxedRuleSet, BoxedSymbolDefinition, BoxedDomain, EvaluateOptions, IComputeEngine, LatexString, Metadata, NOptions, PatternMatchOptions, SemiBoxedExpression, SimplifyOptions, Substitution, RuntimeScope, DomainCompatibility, DomainLiteral, BoxedBaseDefinition, Rational, BoxedSubstitution } from '../public';
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { IComputeEngine, SemiBoxedExpression, BoxedExpression, Metadata, Rational } from '../public';
4
4
  import { MathJsonNumber } from '../../math-json/math-json-format';
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { BoxedExpression, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, ReplaceOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, BoxedSubstitution } from '../public';
3
3
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { BoxedDomain, BoxedExpression, BoxedSubstitution, DomainCompatibility, DomainConstructor, DomainExpression, DomainLiteral, IComputeEngine, Metadata, PatternMatchOptions } from '../public';
3
3
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
4
4
  /**
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export declare function makeFunctionDefinition(engine: IComputeEngine, name: string, def: FunctionDefinition | BoxedFunctionDefinition): BoxedFunctionDefinition;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedSubstitution, EvaluateOptions } from '../public';
4
4
  /**
@@ -87,7 +87,7 @@ export declare class BoxedFunction extends AbstractBoxedExpression {
87
87
  }
88
88
  export declare function makeCanonicalFunction(ce: IComputeEngine, head: string | BoxedExpression, ops: SemiBoxedExpression[], metadata?: Metadata): BoxedExpression;
89
89
  /** Apply arguments to an expression. If the expression is a lambda expression
90
- * it's wildcard arguments are substituted before being evaluated. Otherwise
90
+ * its wildcard arguments are substituted before being evaluated. Otherwise
91
91
  * the expression is just evaluated.
92
92
  */
93
93
  export declare function apply(fn: BoxedExpression, args: BoxedExpression[]): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOptions, Rational, SimplifyOptions, BoxedSubstitution } from '../public';
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, BoxedSubstitution, BoxedDomain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOptions, SemiBoxedExpression, Substitution } from '../public';
4
4
  export declare class BoxedPattern extends AbstractBoxedExpression implements Pattern {
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOptions, BoxedSubstitution } from '../public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  /**
3
3
  * THEORY OF OPERATIONS
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, DomainExpression, BoxedSubstitution } from '../public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, IComputeEngine, Metadata, Rational } from '../public';
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, IComputeEngine } from '../public';
4
4
  export declare function isLatexString(s: unknown): s is string;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export declare function validateArgumentCount(ce: IComputeEngine, ops: BoxedExpression[], count: number): BoxedExpression[];
3
3
  /**
4
4
  * Validation of arguments is normally done by checking the signature of the
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression, MathJsonNumber } from '../math-json/math-json-format';
4
4
  import type { LibraryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
@@ -279,7 +279,9 @@ export declare class ComputeEngine implements IComputeEngine {
279
279
  canonical?: boolean;
280
280
  }): BoxedExpression;
281
281
  canonical(xs: SemiBoxedExpression[]): BoxedExpression[];
282
- fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
282
+ fn(head: string, ops: BoxedExpression[], options?: {
283
+ canonical: boolean;
284
+ }): BoxedExpression;
283
285
  /** @internal */
284
286
  _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
285
287
  error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
@@ -1,3 +1,3 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedExpression, Rational } from './public';
4
4
  /** Quickly determine the numeric domain of a number or constant
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.5 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;