@cortex-js/compute-engine 0.24.1 → 0.25.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 (112) hide show
  1. package/dist/compute-engine.esm.js +24046 -25451
  2. package/dist/compute-engine.js +23987 -25392
  3. package/dist/compute-engine.min.esm.js +13 -13
  4. package/dist/compute-engine.min.js +13 -13
  5. package/dist/math-json.esm.js +43 -77
  6. package/dist/math-json.js +43 -77
  7. package/dist/math-json.min.esm.js +43 -77
  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 +31 -19
  15. package/dist/types/compute-engine/boxed-expression/box.d.ts +9 -9
  16. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +4 -4
  17. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -2
  18. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +9 -10
  20. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +5 -4
  21. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -15
  22. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -4
  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 +7 -8
  25. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +6 -7
  26. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -2
  27. package/dist/types/compute-engine/boxed-expression/coefficient-field.d.ts +56 -0
  28. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/factor.d.ts +11 -0
  30. package/dist/types/compute-engine/boxed-expression/match.d.ts +14 -0
  31. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +41 -0
  32. package/dist/types/compute-engine/boxed-expression/order.d.ts +6 -6
  33. package/dist/types/compute-engine/boxed-expression/public.d.ts +1983 -0
  34. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -15
  35. package/dist/types/compute-engine/boxed-expression/utils.d.ts +5 -2
  36. package/dist/types/compute-engine/boxed-expression/validate.d.ts +7 -6
  37. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  38. package/dist/types/compute-engine/compile.d.ts +2 -2
  39. package/dist/types/compute-engine/compute-engine.d.ts +86 -62
  40. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  41. package/dist/types/compute-engine/domain-utils.d.ts +3 -2
  42. package/dist/types/compute-engine/function-utils.d.ts +2 -2
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -3
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  55. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  56. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +5 -4
  57. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  58. package/dist/types/compute-engine/latex-syntax/parse.d.ts +71 -29
  59. package/dist/types/compute-engine/latex-syntax/public.d.ts +264 -252
  60. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +9 -3
  61. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  62. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +6 -11
  63. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +3 -2
  64. package/dist/types/compute-engine/library/arithmetic-add.d.ts +5 -5
  65. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +2 -2
  66. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +5 -5
  67. package/dist/types/compute-engine/library/arithmetic-power.d.ts +2 -1
  68. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  69. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  70. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  71. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  72. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  73. package/dist/types/compute-engine/library/core.d.ts +3 -2
  74. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  75. package/dist/types/compute-engine/library/library.d.ts +1 -1
  76. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  77. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  78. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  79. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  80. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -2
  81. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  82. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  83. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  84. package/dist/types/compute-engine/library/utils.d.ts +2 -2
  85. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +7 -1
  86. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  87. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  88. package/dist/types/compute-engine/numerics/numeric.d.ts +7 -17
  89. package/dist/types/compute-engine/numerics/primes.d.ts +6 -1
  90. package/dist/types/compute-engine/numerics/rationals.d.ts +4 -13
  91. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  92. package/dist/types/compute-engine/numerics/terms.d.ts +7 -4
  93. package/dist/types/compute-engine/public.d.ts +3 -1841
  94. package/dist/types/compute-engine/rules.d.ts +1 -1
  95. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  96. package/dist/types/compute-engine/solve.d.ts +4 -3
  97. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  98. package/dist/types/compute-engine/symbolic/expand.d.ts +2 -2
  99. package/dist/types/compute-engine/symbolic/flatten.d.ts +6 -4
  100. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  101. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  102. package/dist/types/compute-engine/symbolic/product.d.ts +4 -3
  103. package/dist/types/compute-engine/symbolic/tensor-fields.d.ts +1 -1
  104. package/dist/types/compute-engine/symbolic/tensors.d.ts +1 -1
  105. package/dist/types/compute-engine/symbolic/utils.d.ts +5 -10
  106. package/dist/types/compute-engine.d.ts +2 -2
  107. package/dist/types/math-json/math-json-format.d.ts +3 -3
  108. package/dist/types/math-json/utils.d.ts +4 -6
  109. package/dist/types/math-json.d.ts +2 -2
  110. package/package.json +10 -10
  111. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +0 -28
  112. package/dist/types/compute-engine/numerics/factor.d.ts +0 -27
@@ -1,37 +1,71 @@
1
- /* 0.24.1 */
2
- import { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
3
- import { IComputeEngine } from '../public';
4
- import { Expression } from '../../math-json/math-json-format';
5
- export declare const DEFAULT_LATEX_NUMBER_OPTIONS: NumberFormattingOptions;
6
- export declare const DEFAULT_PARSE_LATEX_OPTIONS: ParseLatexOptions;
1
+ /* 0.25.1 */
2
+ import { ParseLatexOptions, LatexToken, Terminator, Parser, SymbolTable, SymbolType } from './public';
3
+ import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
4
+ /**
5
+ * ## THEORY OF OPERATIONS
6
+ *
7
+ * The parser is a recursive descent parser that uses a dictionary of
8
+ * LaTeX commands to parse a LaTeX string into a MathJSON expression.
9
+ *
10
+ * The parser is a stateful object that keeps track of the current position
11
+ * in the token stream, and the boundaries of the current parsing operation.
12
+ *
13
+ * To parse correctly some constructs, the parser needs to know the context
14
+ * in which it is parsing. For example, parsing `k(2+x)` can be interpreted
15
+ * as a function `k` applied to the sum of `2` and `x`, or as the product
16
+ * of `k` and the sum of `2` and `x`. The parser needs to know that `k` is
17
+ * a function to interpret the expression as a function application.
18
+ *
19
+ * The parser uses the current state of the compute engine, and any
20
+ * identifier that may have been declared, to determine the correct
21
+ * interpretation.
22
+ *
23
+ * Some constructs declare variables or functions while parsing. For example,
24
+ * `\sum_{i=1}^n i` declares the variable `i` as the index of the sum.
25
+ *
26
+ * The parser keeps track of the parsing state with a stack of symbol tables.
27
+ *
28
+ * In addition, the handler `getIdentifierType()` is called when the parser
29
+ * encounters an unknown identifier. This handler can be used to declare the
30
+ * identifier, or to return `unknown` if the identifier is not known.
31
+ *
32
+ * Some functions affect the state of the parser:
33
+ * - `Declare`, `Assign` modify the symbol table
34
+ * - `Block` create a new symbol table (local scope)
35
+ * - `Function` create a new symbol table with named arguments
36
+ *
37
+ *
38
+ */
7
39
  export declare class _Parser implements Parser {
8
- readonly computeEngine: IComputeEngine;
9
- readonly options: NumberFormattingOptions & ParseLatexOptions;
40
+ readonly options: Readonly<ParseLatexOptions>;
10
41
  _index: number;
42
+ symbolTable: SymbolTable;
43
+ pushSymbolTable(): void;
44
+ popSymbolTable(): void;
45
+ addSymbol(id: string, type: SymbolType): void;
11
46
  get index(): number;
12
47
  set index(val: number);
13
48
  private _tokens;
14
49
  private _positiveInfinityTokens;
15
50
  private _negativeInfinityTokens;
16
51
  private _notANumberTokens;
17
- private _decimalMarkerTokens;
18
- private _groupSeparatorTokens;
52
+ private _decimalSeparatorTokens;
53
+ private _wholeDigitGroupSeparatorTokens;
54
+ private _fractionalDigitGroupSeparatorTokens;
19
55
  private _exponentProductTokens;
20
56
  private _beginExponentMarkerTokens;
21
57
  private _endExponentMarkerTokens;
22
58
  private _truncationMarkerTokens;
23
- private _beginRepeatingDigitsTokens;
24
- private _endRepeatingDigitsTokens;
25
- private _imaginaryNumberTokens;
59
+ private _imaginaryUnitTokens;
26
60
  private readonly _dictionary;
27
61
  private _boundaries;
28
62
  private _lastPeek;
29
63
  private _peekCounter;
30
- constructor(tokens: LatexToken[], options: NumberFormattingOptions & ParseLatexOptions, dictionary: IndexedLatexDictionary, computeEngine: IComputeEngine);
31
- updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions>): void;
32
- get atEnd(): boolean;
64
+ constructor(tokens: LatexToken[], dictionary: IndexedLatexDictionary, options: Readonly<ParseLatexOptions>);
65
+ getIdentifierType(id: string): SymbolType;
33
66
  get peek(): LatexToken;
34
67
  nextToken(): LatexToken;
68
+ get atEnd(): boolean;
35
69
  /**
36
70
  * Return true if
37
71
  * - at end of the token stream
@@ -111,8 +145,8 @@ export declare class _Parser implements Parser {
111
145
  */
112
146
  private matchDelimiter;
113
147
  parseGroup(): Expression | null;
114
- parseToken(): Expression | null;
115
148
  parseOptionalGroup(): Expression | null;
149
+ parseToken(): Expression | null;
116
150
  /**
117
151
  * Parse an expression in a tabular format, where rows are separated by `\\`
118
152
  * and columns by `&`.
@@ -121,15 +155,28 @@ export declare class _Parser implements Parser {
121
155
  * and empty cells are also indicated with `Nothing`.
122
156
  */
123
157
  parseTabular(): null | Expression[][];
158
+ /** Match a string used as a LaTeX identifier, for example an environment
159
+ * name.
160
+ * Not suitable for general purpose text, e.g. argument of a `\text{}
161
+ * command. See `matchChar()` instead.
162
+ */
163
+ private parseStringGroupContent;
124
164
  /** Parse a group as a a string, for example for `\operatorname` or `\begin` */
125
165
  parseStringGroup(optional?: boolean): string | null;
126
166
  /** Parse an environment: `\begin{env}...\end{end}`
127
167
  */
128
168
  private parseEnvironment;
129
- /** If the next token matches a `+` or `-` sign, return it and advance the index.
130
- * Otherwise return `''` and do not advance */
169
+ /** If the next token matches a `-` sign, return '-', otherwise return '+'
170
+ *
171
+ */
131
172
  private parseOptionalSign;
173
+ /** Parse a sequence of decimal digits. The part indicates which
174
+ * grouping separator should be expected.
175
+ */
132
176
  private parseDecimalDigits;
177
+ /** The 'part' argument is used to dermine what grouping separator
178
+ * should be expected.
179
+ */
133
180
  private parseSignedInteger;
134
181
  private parseExponent;
135
182
  parseRepeatingDecimal(): string;
@@ -173,7 +220,6 @@ export declare class _Parser implements Parser {
173
220
  *
174
221
  * @internal
175
222
  */
176
- private matchOpenDelimiter;
177
223
  /**
178
224
  * An enclosure is an opening matchfix operator, an optional expression,
179
225
  * optionally followed multiple times by a separator and another expression,
@@ -181,7 +227,7 @@ export declare class _Parser implements Parser {
181
227
  */
182
228
  private parseEnclosure;
183
229
  /**
184
- * A generic expression is used for dictionary entries that take do
230
+ * A generic expression is used for dictionary entries that do
185
231
  * some complex (non-standard) parsing. This includes trig functions (to
186
232
  * parse implicit arguments), and integrals (to parse the integrand and
187
233
  * limits and the "dx" terminator).
@@ -206,18 +252,13 @@ export declare class _Parser implements Parser {
206
252
  */
207
253
  private parseSupsub;
208
254
  parsePostfixOperator(lhs: Expression | null, until?: Readonly<Terminator>): Expression | null;
209
- /** Match a string used as a LaTeX identifier, for example an environment
210
- * name.
211
- * Not suitable for general purpose text, e.g. argument of a `\text{}
212
- * command. See `matchChar()` instead.
213
- */
214
- private parseStringGroupContent;
215
255
  /**
216
- * This method can be invoked when we know we're in an error situation.
256
+ * This method can be invoked when we know we're in an error situation,
257
+ * for example when there are tokens remaining after we've finished parsing.
217
258
  *
218
259
  * In general, if a context does not apply, we return `null` to give
219
260
  * the chance to some other option to be considered. However, in some cases
220
- * we know we've exhausted all posibilities, and in this case this method
261
+ * we know we've exhausted all possibilities, and in this case this method
221
262
  * will return an error expression as informative as possible.
222
263
  *
223
264
  * We've encountered a LaTeX command or symbol but were not able to match it
@@ -262,3 +303,4 @@ export declare class _Parser implements Parser {
262
303
  /** Return all defs of the specified kind */
263
304
  getDefs(kind: string): Iterable<IndexedLatexDictionaryEntry>;
264
305
  }
306
+ export declare function parse(latex: string, dictionary: IndexedLatexDictionary, options: Readonly<ParseLatexOptions>): Expression | null;