@cortex-js/compute-engine 0.30.1 → 0.31.0

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 (149) hide show
  1. package/dist/compute-engine.esm.js +9837 -7504
  2. package/dist/compute-engine.min.esm.js +49 -53
  3. package/dist/compute-engine.min.umd.js +49 -53
  4. package/dist/compute-engine.umd.js +9837 -7504
  5. package/dist/math-json.esm.js +19 -5
  6. package/dist/math-json.min.esm.js +19 -5
  7. package/dist/math-json.min.umd.js +2 -2
  8. package/dist/math-json.umd.js +19 -5
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +1 -1
  11. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +1 -1
  14. package/dist/types/common/one-of.d.ts +1 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/ast-nodes.d.ts +146 -0
  17. package/dist/types/common/type/boxed-type.d.ts +1 -1
  18. package/dist/types/common/type/lexer.d.ts +51 -0
  19. package/dist/types/common/type/parse.d.ts +208 -1
  20. package/dist/types/common/type/parser.d.ts +45 -0
  21. package/dist/types/common/type/primitive.d.ts +1 -1
  22. package/dist/types/common/type/serialize.d.ts +1 -1
  23. package/dist/types/common/type/subtype.d.ts +1 -1
  24. package/dist/types/common/type/type-builder.d.ts +32 -0
  25. package/dist/types/common/type/types.d.ts +1 -1
  26. package/dist/types/common/type/utils.d.ts +1 -1
  27. package/dist/types/common/utils.d.ts +22 -1
  28. package/dist/types/compute-engine/assume.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +4 -4
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  34. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  35. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  36. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +7 -5
  37. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +3 -3
  38. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  39. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +104 -1
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -3
  43. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +3 -3
  44. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/match.d.ts +8 -1
  55. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +58 -1
  59. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +2 -2
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/utils.d.ts +11 -1
  68. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -1
  69. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  70. package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
  71. package/dist/types/compute-engine/{compile.d.ts → compilation/javascript-target.d.ts} +20 -32
  72. package/dist/types/compute-engine/compilation/types.d.ts +83 -0
  73. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  74. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  75. package/dist/types/compute-engine/global-types.d.ts +75 -17
  76. package/dist/types/compute-engine/index.d.ts +4 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  88. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  90. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  93. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  94. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  95. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  96. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  97. package/dist/types/compute-engine/latex-syntax/types.d.ts +2 -2
  98. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  99. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  100. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  101. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  102. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  103. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  104. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  105. package/dist/types/compute-engine/library/core.d.ts +1 -1
  106. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  107. package/dist/types/compute-engine/library/library.d.ts +1 -1
  108. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  109. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  110. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  111. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  112. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  113. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  114. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  115. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  116. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  117. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  118. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  119. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  120. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  121. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  124. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  125. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  129. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  130. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  131. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  132. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  133. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  134. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  135. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  136. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  137. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  138. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  139. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  140. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  141. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  142. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  143. package/dist/types/compute-engine/types.d.ts +1 -1
  144. package/dist/types/compute-engine.d.ts +1 -1
  145. package/dist/types/math-json/symbols.d.ts +1 -1
  146. package/dist/types/math-json/types.d.ts +4 -2
  147. package/dist/types/math-json/utils.d.ts +7 -1
  148. package/dist/types/math-json.d.ts +2 -2
  149. package/package.json +11 -10
@@ -1,6 +1,9 @@
1
- /** Compute Engine 0.30.1 */
1
+ /** Compute Engine 0.31.0 */
2
2
 
3
3
  // src/math-json/utils.ts
4
+ function isNumberObject(expr) {
5
+ return expr !== null && typeof expr === "object" && "num" in expr;
6
+ }
4
7
  function isSymbolObject(expr) {
5
8
  return expr !== null && typeof expr === "object" && "sym" in expr;
6
9
  }
@@ -70,13 +73,15 @@ function dictionaryFromExpression(expr) {
70
73
  const kv = keyValuePair(expr);
71
74
  if (kv) return { [kv[0]]: kv[1] };
72
75
  if (operator(expr) === "Dictionary") {
73
- const result = {};
76
+ const dict = {};
74
77
  const ops = operands(expr);
75
78
  for (let i = 1; i < nops(expr); i++) {
76
79
  const kv2 = keyValuePair(ops[i]);
77
- if (kv2) result[kv2[0]] = kv2[1];
80
+ if (kv2) {
81
+ dict[kv2[0]] = expressionToDictionaryValue(kv2[1]) ?? "Nothing";
82
+ }
78
83
  }
79
- return result;
84
+ return { dict };
80
85
  }
81
86
  return null;
82
87
  }
@@ -99,9 +104,18 @@ function matchesNumber(s) {
99
104
  function matchesSymbol(s) {
100
105
  return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
101
106
  }
107
+ function expressionToDictionaryValue(expr) {
108
+ if (expr === null || expr === void 0) return null;
109
+ if (isStringObject(expr)) return expr.str;
110
+ if (isNumberObject(expr)) return parseFloat(expr.num);
111
+ if (isSymbolObject(expr)) return expr.sym;
112
+ if (typeof expr === "string" || typeof expr === "number") return expr;
113
+ if (Array.isArray(expr)) return { fn: expr };
114
+ return expr;
115
+ }
102
116
 
103
117
  // src/math-json.ts
104
- var version = "0.30.1";
118
+ var version = "0.31.0";
105
119
  export {
106
120
  dictionaryFromExpression,
107
121
  isFunctionObject,
@@ -1,6 +1,9 @@
1
- /** Compute Engine 0.30.1 */
1
+ /** Compute Engine 0.31.0 */
2
2
 
3
3
  // src/math-json/utils.ts
4
+ function isNumberObject(expr) {
5
+ return expr !== null && typeof expr === "object" && "num" in expr;
6
+ }
4
7
  function isSymbolObject(expr) {
5
8
  return expr !== null && typeof expr === "object" && "sym" in expr;
6
9
  }
@@ -70,13 +73,15 @@ function dictionaryFromExpression(expr) {
70
73
  const kv = keyValuePair(expr);
71
74
  if (kv) return { [kv[0]]: kv[1] };
72
75
  if (operator(expr) === "Dictionary") {
73
- const result = {};
76
+ const dict = {};
74
77
  const ops = operands(expr);
75
78
  for (let i = 1; i < nops(expr); i++) {
76
79
  const kv2 = keyValuePair(ops[i]);
77
- if (kv2) result[kv2[0]] = kv2[1];
80
+ if (kv2) {
81
+ dict[kv2[0]] = expressionToDictionaryValue(kv2[1]) ?? "Nothing";
82
+ }
78
83
  }
79
- return result;
84
+ return { dict };
80
85
  }
81
86
  return null;
82
87
  }
@@ -99,9 +104,18 @@ function matchesNumber(s) {
99
104
  function matchesSymbol(s) {
100
105
  return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
101
106
  }
107
+ function expressionToDictionaryValue(expr) {
108
+ if (expr === null || expr === void 0) return null;
109
+ if (isStringObject(expr)) return expr.str;
110
+ if (isNumberObject(expr)) return parseFloat(expr.num);
111
+ if (isSymbolObject(expr)) return expr.sym;
112
+ if (typeof expr === "string" || typeof expr === "number") return expr;
113
+ if (Array.isArray(expr)) return { fn: expr };
114
+ return expr;
115
+ }
102
116
 
103
117
  // src/math-json.ts
104
- var version = "0.30.1";
118
+ var version = "0.31.0";
105
119
  export {
106
120
  dictionaryFromExpression,
107
121
  isFunctionObject,
@@ -1,4 +1,4 @@
1
- /** MathJSON 0.30.1 */
1
+ /** MathJSON 0.31.0 */
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
- var MathJson=(()=>{var s=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var S=(n,t)=>{for(var i in t)s(n,i,{get:t[i],enumerable:!0})},J=(n,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of O(t))!M.call(n,e)&&e!==i&&s(n,e,{get:()=>t[e],enumerable:!(r=j(t,e))||r.enumerable});return n};var A=n=>J(s({},"__esModule",{value:!0}),n);var F={};S(F,{dictionaryFromExpression:()=>E,isFunctionObject:()=>u,isStringObject:()=>y,isSymbolObject:()=>f,mapArgs:()=>h,operand:()=>d,operator:()=>o,stringValue:()=>c,symbol:()=>m,version:()=>k});function f(n){return n!==null&&typeof n=="object"&&"sym"in n}function y(n){return n!==null&&typeof n=="object"&&"str"in n}function N(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function u(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):p(n)||g(n)?null:n}function o(n){return Array.isArray(n)?n[0]:n==null?"":u(n)?n.fn[0]:""}function b(n){return Array.isArray(n)?n.slice(1):n!==void 0&&u(n)?n.fn.slice(1):[]}function d(n,t){return Array.isArray(n)?n[t]??null:n===null||!u(n)?null:n.fn[t]??null}function D(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):u(n)?Math.max(0,n.fn.length-1):0}function m(n){return typeof n=="string"&&g(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:f(n)?n.sym:null}function a(n){let t=o(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,r]=b(n),e=c(i);return e?[e,r??"Nothing"]:null}return null}function E(n){if(n===null)return null;if(N(n))return n;let t=a(n);if(t)return{[t[0]]:t[1]};if(o(n)==="Dictionary"){let i={},r=b(n);for(let e=1;e<D(n);e++){let l=a(r[e]);l&&(i[l[0]]=l[1])}return i}return null}function h(n,t){let i=null;if(Array.isArray(n)&&(i=n),u(n)&&(i=n.fn),i===null)return[];let r=1,e=[];for(;r<i.length;)e.push(t(i[r])),r+=1;return e}function p(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function g(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}var k="0.30.1";return A(F);})();
3
+ var MathJson=(()=>{var f=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var A=(n,t)=>{for(var i in t)f(n,i,{get:t[i],enumerable:!0})},J=(n,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of O(t))!M.call(n,e)&&e!==i&&f(n,e,{get:()=>t[e],enumerable:!(r=j(t,e))||r.enumerable});return n};var S=n=>J(f({},"__esModule",{value:!0}),n);var T={};A(T,{dictionaryFromExpression:()=>E,isFunctionObject:()=>u,isStringObject:()=>a,isSymbolObject:()=>o,mapArgs:()=>h,operand:()=>d,operator:()=>s,stringValue:()=>c,symbol:()=>m,version:()=>V});function N(n){return n!==null&&typeof n=="object"&&"num"in n}function o(n){return n!==null&&typeof n=="object"&&"sym"in n}function a(n){return n!==null&&typeof n=="object"&&"str"in n}function p(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function u(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):k(n)||g(n)?null:n}function s(n){return Array.isArray(n)?n[0]:n==null?"":u(n)?n.fn[0]:""}function b(n){return Array.isArray(n)?n.slice(1):n!==void 0&&u(n)?n.fn.slice(1):[]}function d(n,t){return Array.isArray(n)?n[t]??null:n===null||!u(n)?null:n.fn[t]??null}function D(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):u(n)?Math.max(0,n.fn.length-1):0}function m(n){return typeof n=="string"&&g(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:o(n)?n.sym:null}function y(n){let t=s(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,r]=b(n),e=c(i);return e?[e,r??"Nothing"]:null}return null}function E(n){if(n===null)return null;if(p(n))return n;let t=y(n);if(t)return{[t[0]]:t[1]};if(s(n)==="Dictionary"){let i={},r=b(n);for(let e=1;e<D(n);e++){let l=y(r[e]);l&&(i[l[0]]=F(l[1])??"Nothing")}return{dict:i}}return null}function h(n,t){let i=null;if(Array.isArray(n)&&(i=n),u(n)&&(i=n.fn),i===null)return[];let r=1,e=[];for(;r<i.length;)e.push(t(i[r])),r+=1;return e}function k(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function g(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}function F(n){return n==null?null:a(n)?n.str:N(n)?parseFloat(n.num):o(n)?n.sym:typeof n=="string"||typeof n=="number"?n:Array.isArray(n)?{fn:n}:n}var V="0.31.0";return S(T);})();
4
4
  Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,4 +1,4 @@
1
- /** MathJSON 0.30.1 */
1
+ /** MathJSON 0.31.0 */
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;
@@ -35,6 +35,9 @@ var MathJson = (() => {
35
35
  });
36
36
 
37
37
  // src/math-json/utils.ts
38
+ function isNumberObject(expr) {
39
+ return expr !== null && typeof expr === "object" && "num" in expr;
40
+ }
38
41
  function isSymbolObject(expr) {
39
42
  return expr !== null && typeof expr === "object" && "sym" in expr;
40
43
  }
@@ -104,13 +107,15 @@ var MathJson = (() => {
104
107
  const kv = keyValuePair(expr);
105
108
  if (kv) return { [kv[0]]: kv[1] };
106
109
  if (operator(expr) === "Dictionary") {
107
- const result = {};
110
+ const dict = {};
108
111
  const ops = operands(expr);
109
112
  for (let i = 1; i < nops(expr); i++) {
110
113
  const kv2 = keyValuePair(ops[i]);
111
- if (kv2) result[kv2[0]] = kv2[1];
114
+ if (kv2) {
115
+ dict[kv2[0]] = expressionToDictionaryValue(kv2[1]) ?? "Nothing";
116
+ }
112
117
  }
113
- return result;
118
+ return { dict };
114
119
  }
115
120
  return null;
116
121
  }
@@ -133,9 +138,18 @@ var MathJson = (() => {
133
138
  function matchesSymbol(s) {
134
139
  return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
135
140
  }
141
+ function expressionToDictionaryValue(expr) {
142
+ if (expr === null || expr === void 0) return null;
143
+ if (isStringObject(expr)) return expr.str;
144
+ if (isNumberObject(expr)) return parseFloat(expr.num);
145
+ if (isSymbolObject(expr)) return expr.sym;
146
+ if (typeof expr === "string" || typeof expr === "number") return expr;
147
+ if (Array.isArray(expr)) return { fn: expr };
148
+ return expr;
149
+ }
136
150
 
137
151
  // src/math-json.ts
138
- var version = "0.30.1";
152
+ var version = "0.31.0";
139
153
  return __toCommonJS(math_json_exports);
140
154
  })();
141
155
  Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFAULT_COLOR = "\u001B[39m";
3
3
  export declare const DEFAULT_BG = "\u001B[49m";
4
4
  export declare const WHITE_BG = "\u001B[47m";
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  private _listeners;
3
3
  private _pending;
4
4
  private _version;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare function fuzzyStringMatch(invalidWord: string, validWords: string[]): string | null;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  /**
3
3
  * Return a string or an array of graphemes.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  cause: unknown;
3
3
  value: T;
4
4
  constructor({ message, value, cause, }?: {
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  infer Head,
3
3
  ...infer Rem
4
4
  ] ? MergeTypes<Rem, Res & Head> : Res;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export type RuntimeSignalCode = 'timeout' | 'out-of-memory' | 'recursion-depth-exceeded' | 'iteration-limit-exceeded';
3
3
  /** @category Error Handling */
4
4
  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');
@@ -0,0 +1,146 @@
1
+ /* 0.31.0 */
2
+ kind: string;
3
+ position: number;
4
+ line: number;
5
+ column: number;
6
+ }
7
+ export interface NamedElementNode extends ASTNode {
8
+ kind: 'named_element';
9
+ name?: string;
10
+ type: TypeNode;
11
+ }
12
+ export interface ArgumentNode extends ASTNode {
13
+ kind: 'argument';
14
+ element: NamedElementNode;
15
+ modifier?: 'optional' | 'variadic_zero' | 'variadic_one';
16
+ }
17
+ export interface FunctionSignatureNode extends ASTNode {
18
+ kind: 'function_signature';
19
+ arguments: ArgumentNode[];
20
+ returnType: TypeNode;
21
+ }
22
+ export interface UnionTypeNode extends ASTNode {
23
+ kind: 'union';
24
+ types: TypeNode[];
25
+ }
26
+ export interface IntersectionTypeNode extends ASTNode {
27
+ kind: 'intersection';
28
+ types: TypeNode[];
29
+ }
30
+ export interface NegationTypeNode extends ASTNode {
31
+ kind: 'negation';
32
+ type: TypeNode;
33
+ }
34
+ export interface GroupTypeNode extends ASTNode {
35
+ kind: 'group';
36
+ type: TypeNode;
37
+ }
38
+ export interface ListTypeNode extends ASTNode {
39
+ kind: 'list';
40
+ elementType: TypeNode;
41
+ dimensions?: DimensionNode[];
42
+ }
43
+ export interface VectorTypeNode extends ASTNode {
44
+ kind: 'vector';
45
+ elementType: TypeNode;
46
+ size?: number;
47
+ }
48
+ export interface MatrixTypeNode extends ASTNode {
49
+ kind: 'matrix';
50
+ elementType: TypeNode;
51
+ dimensions?: DimensionNode[];
52
+ }
53
+ export interface TensorTypeNode extends ASTNode {
54
+ kind: 'tensor';
55
+ elementType: TypeNode;
56
+ }
57
+ export interface TupleTypeNode extends ASTNode {
58
+ kind: 'tuple';
59
+ elements: NamedElementNode[];
60
+ }
61
+ export interface RecordTypeNode extends ASTNode {
62
+ kind: 'record';
63
+ entries: RecordEntryNode[];
64
+ }
65
+ export interface RecordEntryNode extends ASTNode {
66
+ kind: 'record_entry';
67
+ key: string;
68
+ valueType: TypeNode;
69
+ }
70
+ export interface DictionaryTypeNode extends ASTNode {
71
+ kind: 'dictionary';
72
+ valueType: TypeNode;
73
+ }
74
+ export interface SetTypeNode extends ASTNode {
75
+ kind: 'set';
76
+ elementType: TypeNode;
77
+ }
78
+ export interface CollectionTypeNode extends ASTNode {
79
+ kind: 'collection';
80
+ elementType: TypeNode;
81
+ indexed?: boolean;
82
+ }
83
+ export interface ExpressionTypeNode extends ASTNode {
84
+ kind: 'expression';
85
+ operator: string;
86
+ }
87
+ export interface SymbolTypeNode extends ASTNode {
88
+ kind: 'symbol';
89
+ name: string;
90
+ }
91
+ export interface NumericTypeNode extends ASTNode {
92
+ kind: 'numeric';
93
+ baseType: string;
94
+ lowerBound?: ValueNode;
95
+ upperBound?: ValueNode;
96
+ }
97
+ export interface PrimitiveTypeNode extends ASTNode {
98
+ kind: 'primitive';
99
+ name: string;
100
+ }
101
+ export interface TypeReferenceNode extends ASTNode {
102
+ kind: 'type_reference';
103
+ name: string;
104
+ isForward?: boolean;
105
+ }
106
+ export interface ValueNode extends ASTNode {
107
+ kind: 'value';
108
+ value: any;
109
+ valueType: 'string' | 'number' | 'boolean' | 'infinity' | 'nan';
110
+ }
111
+ export interface DimensionNode extends ASTNode {
112
+ kind: 'dimension';
113
+ size: number | null;
114
+ }
115
+ export interface IdentifierNode extends ASTNode {
116
+ kind: 'identifier';
117
+ name: string;
118
+ }
119
+ export interface VerbatimStringNode extends ASTNode {
120
+ kind: 'verbatim_string';
121
+ value: string;
122
+ }
123
+ export type TypeNode = FunctionSignatureNode | UnionTypeNode | IntersectionTypeNode | NegationTypeNode | GroupTypeNode | ListTypeNode | VectorTypeNode | MatrixTypeNode | TensorTypeNode | TupleTypeNode | RecordTypeNode | DictionaryTypeNode | SetTypeNode | CollectionTypeNode | ExpressionTypeNode | SymbolTypeNode | NumericTypeNode | PrimitiveTypeNode | TypeReferenceNode | ValueNode;
124
+ export interface ASTVisitor<T> {
125
+ visitFunctionSignature(node: FunctionSignatureNode): T;
126
+ visitUnionType(node: UnionTypeNode): T;
127
+ visitIntersectionType(node: IntersectionTypeNode): T;
128
+ visitNegationType(node: NegationTypeNode): T;
129
+ visitGroupType(node: GroupTypeNode): T;
130
+ visitListType(node: ListTypeNode): T;
131
+ visitVectorType(node: VectorTypeNode): T;
132
+ visitMatrixType(node: MatrixTypeNode): T;
133
+ visitTensorType(node: TensorTypeNode): T;
134
+ visitTupleType(node: TupleTypeNode): T;
135
+ visitRecordType(node: RecordTypeNode): T;
136
+ visitDictionaryType(node: DictionaryTypeNode): T;
137
+ visitSetType(node: SetTypeNode): T;
138
+ visitCollectionType(node: CollectionTypeNode): T;
139
+ visitExpressionType(node: ExpressionTypeNode): T;
140
+ visitSymbolType(node: SymbolTypeNode): T;
141
+ visitNumericType(node: NumericTypeNode): T;
142
+ visitPrimitiveType(node: PrimitiveTypeNode): T;
143
+ visitTypeReference(node: TypeReferenceNode): T;
144
+ visitValue(node: ValueNode): T;
145
+ }
146
+ export declare function visitNode<T>(node: TypeNode, visitor: ASTVisitor<T>): T;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  /** @category Type */
3
3
  export declare class BoxedType {
4
4
  static unknown: BoxedType;
@@ -0,0 +1,51 @@
1
+ /* 0.31.0 */
2
+ export interface Token {
3
+ type: TokenType;
4
+ value: string;
5
+ position: number;
6
+ line: number;
7
+ column: number;
8
+ }
9
+ export interface LexerError {
10
+ message: string;
11
+ position: number;
12
+ line: number;
13
+ column: number;
14
+ }
15
+ export declare class Lexer {
16
+ input: string;
17
+ private pos;
18
+ private line;
19
+ private column;
20
+ private tokens;
21
+ constructor(input: string);
22
+ saveState(): {
23
+ pos: number;
24
+ line: number;
25
+ column: number;
26
+ tokens: Token[];
27
+ };
28
+ restoreState(state: {
29
+ pos: number;
30
+ line: number;
31
+ column: number;
32
+ tokens: Token[];
33
+ }): void;
34
+ error(message: string): never;
35
+ private peek;
36
+ private advance;
37
+ private match;
38
+ private isEOF;
39
+ private skipWhitespace;
40
+ private readIdentifier;
41
+ private readVerbatimString;
42
+ private readStringLiteral;
43
+ private readNumber;
44
+ private createToken;
45
+ private nextToken;
46
+ tokenize(): Token[];
47
+ peekToken(): Token;
48
+ consumeToken(): Token;
49
+ matchToken(type: TokenType): boolean;
50
+ expectToken(type: TokenType): Token;
51
+ }
@@ -1,4 +1,211 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
+ /**
3
+ * BNF grammar for the type parser:
4
+ *
5
+ <type> ::= <union_type>
6
+ | <function_signature>
7
+
8
+ <union_type> ::= <intersection_type> ( " | " <intersection_type> )*
9
+
10
+ <intersection_type> ::= <primary_type_with_negation> ( " & " <primary_type_with_negation> )*
11
+
12
+ <primary_type_with_negation> ::= ( "!" )? <primary_type>
13
+
14
+ <primary_type> ::= <group>
15
+ | <list_type>
16
+ | <tuple_type>
17
+ | <record_type>
18
+ | <dictionary_type>
19
+ | <set_type>
20
+ | <collection_type>
21
+ | <expression_type>
22
+ | <symbol_type>
23
+ | <numeric_type>
24
+ | <primitive_type>
25
+ | <value>
26
+ | <type_reference>
27
+
28
+ <group> ::= "(" <type> ")"
29
+
30
+ (* --- Function Signatures --- *)
31
+
32
+ <function_signature> ::= <arguments> " -> " <type>
33
+
34
+ <arguments> ::= "()"
35
+ | "(" <argument_list>? ")"
36
+
37
+ (* Note: The parser enforces a semantic rule: required arguments must come before optional and variadic arguments. *)
38
+ <argument_list> ::= <argument_specifier> ( "," <argument_specifier> )*
39
+
40
+ <argument_specifier> ::= <named_element> ( "?" | "*" | "+" )?
41
+
42
+ <named_element> ::= ( <name> ":" )? <type>
43
+
44
+ <name> ::= <identifier> | <verbatim_string>
45
+
46
+
47
+ (* --- Collection-like Types --- *)
48
+
49
+ <list_type> ::= "list" ( "<" <type> ( "^" <dimensions> )? ">" )?
50
+ | "vector" ( "<" ( <type> ("^" <dimension_specifier>)? | <dimensions> ) ">" )?
51
+ | "matrix" ( "<" ( <type> ("^" <dimensions>)? | <dimensions> ) ">" )?
52
+ | "tensor" ( "<" <type> ">" )?
53
+
54
+ <dimensions> ::= <dimension_specifier> ( "x" <dimension_specifier> )*
55
+ | "(" <dimension_specifier> ( "x" <dimension_specifier> )* ")"
56
+
57
+ <dimension_specifier> ::= <positive_integer_literal> | "?"
58
+
59
+ <tuple_type> ::= "tuple<" ( <named_element> ( "," <named_element> )* )? ">"
60
+
61
+ <record_type> ::= "record"
62
+ | "record<" <record_element> ( "," <record_element> )* ">"
63
+
64
+ <record_element> ::= <key> ":" <type>
65
+
66
+ <key> ::= <identifier> | <verbatim_string>
67
+
68
+ <dictionary_type> ::= "dictionary"
69
+ | "dictionary<" <type> ">"
70
+
71
+ <set_type> ::= "set"
72
+ | "set<" <type> ">"
73
+
74
+ <collection_type> ::= ( "collection" | "indexed_collection" ) ( "<" <type> ">" )?
75
+
76
+
77
+ (* --- Other Constructed Types --- *)
78
+
79
+ <expression_type> ::= "expression<" <identifier> ">"
80
+
81
+ <symbol_type> ::= "symbol<" <identifier> ">"
82
+
83
+ <numeric_type> ::= <numeric_primitive> "<" <bound> ".." <bound> ">"
84
+
85
+ <bound> ::= <number_literal> | "-oo" | "oo" | ""
86
+
87
+
88
+ (* --- Atomic and Primitive Types --- *)
89
+
90
+ <type_reference> ::= ( "type" )? <identifier>
91
+
92
+ <value> ::= <string_literal>
93
+ | <number_literal>
94
+ | "true" | "false"
95
+ | "nan" | "infinity" | "+infinity" | "oo" | "∞" | "+oo" | "+∞"
96
+ | "-infinity" | "-oo" | "-∞"
97
+
98
+ <primitive_type> ::= <numeric_primitive>
99
+ | "any" | "unknown" | "nothing" | "never" | "error"
100
+ | "expression" | "symbol" | "function" | "value"
101
+ | "scalar" | "boolean" | "string"
102
+ | "collection" | "indexed_collection" | "list" | "tuple"
103
+ | "set" | "record" | "dictionary"
104
+
105
+ <numeric_primitive> ::= "number" | "finite_number" | "complex" | "finite_complex"
106
+ | "imaginary" | "real" | "finite_real" | "rational"
107
+ | "finite_rational" | "integer" | "finite_integer"
108
+ | "non_finite_number"
109
+
110
+
111
+ (* --- Terminals (Lexical Tokens) --- *)
112
+
113
+ <identifier> ::= [a-zA-Z_][a-zA-Z0-9_]*
114
+
115
+ <verbatim_string> ::= "`" ( [^`] | "\`" | "\\" )* "`"
116
+
117
+ <positive_integer_literal> ::= [1-9][0-9]*
118
+
119
+ <number_literal> ::= (* As parsed by the valueParser, including integers, decimals, and scientific notation *)
120
+
121
+ <string_literal> ::= '"' ( [^"] | '\"' )* '"'
122
+ *
123
+ */
124
+ declare class TypeParser {
125
+ buffer: string;
126
+ pos: number;
127
+ _valueParser: (parser: TypeParser) => any;
128
+ _typeResolver: TypeResolver;
129
+ constructor(buffer: string, options?: {
130
+ valueParser?: (parser: TypeParser) => any;
131
+ typeResolver?: TypeResolver;
132
+ });
133
+ error(...messages: (string | undefined)[]): never;
134
+ peek(): string;
135
+ consume(): string;
136
+ /** Check if the upcoming tokens match s, return false if not, consume otherwise */
137
+ match(s: string): boolean;
138
+ /** If the next token don't match `>`, error */
139
+ expectClosingBracket(): void;
140
+ /** If a white space is allowed, call before `consume()` or `match()` */
141
+ skipWhitespace(): void;
142
+ isEOF(): boolean;
143
+ parseValue(): Type | null;
144
+ parseTypeReference(): TypeReference | null;
145
+ parsePrimitiveType(): Type | null;
146
+ /**
147
+ * Arguments are `name: type` or `type` separated by commas.
148
+ * Arguments can be optional, i.e. `name: type?` or `type?`.
149
+ * Variadic arguments are `name: type+`, `type+`, `name: type*` or `type*`.
150
+ */
151
+ parseArguments(): [
152
+ required: NamedElement[],
153
+ optional: NamedElement[],
154
+ variadic: NamedElement | undefined,
155
+ variadicMin: 0 | 1 | undefined
156
+ ];
157
+ parseFunctionSignature(): Type | null;
158
+ parsePositiveIntegerLiteral(): number | null;
159
+ parseOptionalDimension(): number | null;
160
+ parseDimensions(): number[] | undefined;
161
+ parseList(): Type | null;
162
+ /**
163
+ * Parse the name of a named element, i.e. an identifier followed by a colon.
164
+ * Does special error handling for optional qualifiers.
165
+ * */
166
+ parseName(): string | null;
167
+ parseVerbatimString(): string | null;
168
+ /**
169
+ * A general purpose identifier, used for expresion<>, symbol<>, type references, record keys, etc.
170
+ *
171
+ * Not used for arguments (they have special error handling with `parseName()`).
172
+ */
173
+ parseIdentifier(): string | null;
174
+ /** Parse:
175
+ * - "<identifier>: <type>"
176
+ * - "<type>"
177
+ *
178
+ * Does not parse variadic arguments, i.e. `type+` or `name: type+`.
179
+ */
180
+ parseNamedElement(): NamedElement | null;
181
+ parseTupleElements(): NamedElement[];
182
+ parseTuple(): Type | null;
183
+ /** Parse a non-optional group, i.e. "(" <type> ")" */
184
+ parseGroup(): Type | null;
185
+ parseSet(): Type | null;
186
+ parseRecordKeyValue(): [string, Type][];
187
+ parseRecord(): Type | null;
188
+ parseDictionary(): Type | null;
189
+ parseCollection(): Type | null;
190
+ parseExpression(): Type | null;
191
+ parseSymbol(): Type | null;
192
+ /** Parse a constructed numeric type with a range */
193
+ parseNumericType(): Type | null;
194
+ parseStringType(): Type | null;
195
+ parsePrimary(): Type;
196
+ parseUnexpectedToken(): string | undefined;
197
+ parseMaybePrimary(): Type | null;
198
+ parseNegationType(): Type | null;
199
+ parseIntersectionType(): Type | null;
200
+ parseUnionType(): Type | null;
201
+ parseType(): Readonly<Type> | null;
202
+ /** Parse a type, but return null if there's a problem instead
203
+ * of throwing.
204
+ */
205
+ parseTypeMaybe(): Readonly<Type> | null;
206
+ parse(): Readonly<Type>;
207
+ }
2
208
  export declare function parseType(s: undefined, typeResolver?: TypeResolver): undefined;
3
209
  export declare function parseType(s: TypeString | Type, typeResolver?: TypeResolver): Type;
4
210
  export declare function parseType(s: TypeString | Type | undefined, typeResolver?: TypeResolver): Type | undefined;
211
+ export { TypeParser };