@cortex-js/compute-engine 0.12.4 → 0.12.6

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 +916 -782
  2. package/dist/compute-engine.js +916 -782
  3. package/dist/compute-engine.min.esm.js +916 -782
  4. package/dist/compute-engine.min.js +916 -782
  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 +8 -6
  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 +14 -9
  43. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +2 -2
  44. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
  45. package/dist/types/compute-engine/latex-syntax/parse.d.ts +102 -75
  46. package/dist/types/compute-engine/latex-syntax/public.d.ts +138 -136
  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 +4 -4
  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 +2 -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 +102 -5
  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 +2 -1
  88. package/dist/types/math-json.d.ts +2 -2
  89. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- /* 0.12.4 */
2
- import { IndexedLatexDictionary, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedIdentifierEntry } from './dictionary/definitions';
1
+ /* 0.12.6 */
2
+ import { IndexedLatexDictionary, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry } from './dictionary/definitions';
3
3
  import { IComputeEngine } from '../public';
4
4
  import { Expression } from '../../math-json/math-json-format';
5
5
  export declare const DEFAULT_LATEX_NUMBER_OPTIONS: NumberFormattingOptions;
@@ -8,7 +8,7 @@ export declare class _Parser implements Parser {
8
8
  readonly computeEngine: IComputeEngine;
9
9
  readonly options: NumberFormattingOptions & ParseLatexOptions;
10
10
  index: number;
11
- private readonly _tokens;
11
+ private _tokens;
12
12
  private _positiveInfinityTokens;
13
13
  private _negativeInfinityTokens;
14
14
  private _notANumberTokens;
@@ -29,7 +29,7 @@ export declare class _Parser implements Parser {
29
29
  updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions>): void;
30
30
  get atEnd(): boolean;
31
31
  get peek(): LatexToken;
32
- next(): LatexToken;
32
+ nextToken(): LatexToken;
33
33
  /**
34
34
  * Return true if
35
35
  * - at end of the token stream
@@ -44,12 +44,9 @@ export declare class _Parser implements Parser {
44
44
  matchBoundary(): boolean;
45
45
  boundaryError(msg: string | [string, ...Expression[]]): Expression;
46
46
  latex(start: number, end?: number): string;
47
- latexAhead(n: number): string;
48
- latexBefore(): string;
49
- latexAfter(): string;
47
+ private latexAhead;
50
48
  /**
51
- * Return at most `this._dictionary.lookahead` strings made from the tokens
52
- * ahead.
49
+ * Return at most `this._dictionary.lookahead` LaTeX tokens.
53
50
  *
54
51
  * The index in the returned array correspond to the number of tokens.
55
52
  * Note that since a token can be longer than one char ('\\pi', but also
@@ -57,11 +54,16 @@ export declare class _Parser implements Parser {
57
54
  * does not match that index. However, knowing the index is important
58
55
  * to know by how many tokens to advance.
59
56
  *
57
+ * For example:
58
+ *
59
+ * `[empty, '\\sqrt', '\\sqrt{', '\\sqrt{2', '\\sqrt{2}']`
60
+ *
60
61
  */
61
62
  lookAhead(): string[];
62
63
  /** Return all the definitions that potentially match the tokens ahead */
64
+ peekDefinitions(kind: 'expression'): [IndexedExpressionEntry, number][] | null;
63
65
  peekDefinitions(kind: 'function'): [FunctionEntry, number][] | null;
64
- peekDefinitions(kind: 'identifier'): [IndexedIdentifierEntry, number][] | null;
66
+ peekDefinitions(kind: 'symbol'): [IndexedSymbolEntry, number][] | null;
65
67
  peekDefinitions(kind: 'postfix'): [IndexedPostfixEntry, number][] | null;
66
68
  peekDefinitions(kind: 'infix'): [IndexedInfixEntry, number][] | null;
67
69
  peekDefinitions(kind: 'prefix'): [IndexedPrefixEntry, number][] | null;
@@ -77,23 +79,38 @@ export declare class _Parser implements Parser {
77
79
  */
78
80
  skipSpace(): boolean;
79
81
  skipVisualSpace(): void;
80
- matchChar(): string | null;
81
- matchColor(_background?: boolean): string | null;
82
- matchLatexDimension(): string | null;
83
82
  match(token: LatexToken): boolean;
84
- matchAll(tokens: LatexToken | LatexToken[]): boolean;
83
+ matchAll(tokens: LatexToken[]): boolean;
85
84
  matchAny(tokens: LatexToken[]): LatexToken;
86
- matchSequence(tokens: LatexToken[]): LatexToken[];
87
- matchOptionalSign(): string;
88
- matchDecimalDigits(options?: {
89
- withGrouping?: boolean;
90
- }): string;
91
- matchSignedInteger(options?: {
92
- withGrouping?: boolean;
93
- }): string;
94
- matchExponent(): string;
95
- matchRepeatingDecimal(): string;
96
- matchNumber(): string;
85
+ matchChar(): string | null;
86
+ parseGroup(): Expression | null;
87
+ parseToken(): Expression | null;
88
+ parseOptionalGroup(): Expression | null;
89
+ /**
90
+ * Parse an expression in a tabular format, where rows are separated by `\\`
91
+ * and columns by `&`.
92
+ *
93
+ * Return rows of sparse columns: empty rows are indicated with `Nothing`,
94
+ * and empty cells are also indicated with `Nothing`.
95
+ */
96
+ parseTabular(): null | Expression[][];
97
+ /** Parse a group as a a string, for example for `\operatorname` or `\begin` */
98
+ parseStringGroup(): string | null;
99
+ /** Parse an environment: `\begin{env}...\end{end}`
100
+ */
101
+ private parseEnvironment;
102
+ /** If the next token matches a `+` or `-` sign, return it and advance the index.
103
+ * Otherwise return `''` and do not advance */
104
+ private parseOptionalSign;
105
+ private parseDecimalDigits;
106
+ private parseSignedInteger;
107
+ private parseExponent;
108
+ parseRepeatingDecimal(): string;
109
+ /**
110
+ * Parse a number, with an optional sign, exponent, decimal marker,
111
+ * repeating decimals, etc...
112
+ */
113
+ private parseNumber;
97
114
  /**
98
115
  * A Latex number can be a decimal, hex or octal number.
99
116
  * It is used in some Latex commands, such as `\char`
@@ -106,25 +123,22 @@ export declare class _Parser implements Parser {
106
123
  * > an internal variable.
107
124
  */
108
125
  matchLatexNumber(isInteger?: boolean): null | number;
109
- matchPrefixOperator(until?: Terminator): Expression | null;
110
- matchInfixOperator(lhs: Expression, until?: Terminator): Expression | null;
126
+ private parsePrefixOperator;
127
+ private parseInfixOperator;
111
128
  /**
112
- * - 'enclosure' : will look for an argument inside an enclosure (open/close fence)
129
+ * This returns an array of arguments (as in a function application),
130
+ * or null if there is no match.
131
+ *
132
+ * - 'enclosure' : will look for an argument inside an enclosure
133
+ * (open/close fence)
113
134
  * - 'implicit': either an expression inside a pair of `()`, or just a product
114
135
  * (i.e. we interpret `\cos 2x + 1` as `\cos(2x) + 1`)
136
+ *
115
137
  */
116
- matchArguments(kind: undefined | '' | 'enclosure' | 'implicit', until?: Terminator): Expression[] | null;
117
- /**
118
- * A function can be followed by the following suffixes:
119
- * - a `\prime`, `\doubleprime`, `'`, `(n)` to indicate a derivative
120
- * - a subscript to indicate an argument
121
- * - an argument, optionally inside an enclosure
122
- */
123
- matchFunctionSuffix(id: string): Expression;
138
+ parseArguments(kind?: 'enclosure' | 'implicit', until?: Terminator): Expression[] | null;
124
139
  /** A prime suffix is a sequence of `'`, `\prime` or `\doubleprime`
125
140
  * after a function or in a superscript.
126
141
  */
127
- matchPrimeSuffix(): number;
128
142
  /** If matches the normalized open delimiter, return the
129
143
  * expected closing delimiter.
130
144
  *
@@ -133,55 +147,55 @@ export declare class _Parser implements Parser {
133
147
  *
134
148
  * If you need to match several tokens, use `matchAll()`
135
149
  */
136
- matchOpenDelimiter(openDelim: Delimiter, closeDelim: Delimiter): LatexToken[] | null;
137
- matchMiddleDelimiter(delimiter: '|' | ':' | LatexToken): boolean;
150
+ private matchOpenDelimiter;
138
151
  /** For error handling, when there is potentially a mismatched delimiter.
139
152
  * Return a LaTeX fragment of the expected closing delimiter
153
+ *
154
+ * @internal
140
155
  */
141
156
  matchEnclosureOpen(): string | null;
157
+ /**
158
+ * Used for error handling
159
+ * @internal */
142
160
  matchEnclosureClose(): string | null;
143
161
  /**
144
162
  * An enclosure is an opening matchfix operator, an optional expression,
145
163
  * optionally followed multiple times by a separator and another expression,
146
164
  * and finally a closing matching operator.
147
165
  */
148
- matchEnclosure(): Expression | null;
149
- matchIdentifier(): string | null;
166
+ private parseEnclosure;
150
167
  /**
151
- * A function is an identifier followed by arguments
152
- * - a single letter identifier with explicit arguments `f(x)`
153
- * - a multiletter identifier with explicit arguments `\mathrm{floor}(x)`
154
- * - an identifier: `\mathrm{floor}`
155
- * - a command with implicit arguments: `\cos x` (via a custom parser)
156
- *
168
+ * A generic expression is used for dictionary entries that take do
169
+ * some complex (non-standard) parsing. This includes trig functions (to
170
+ * parse implicit arguments), and integrals (to parse the integrand and
171
+ * limits and the "dx" terminator).
172
+ */
173
+ private parseGenericExpression;
174
+ /**
175
+ * A function is an identifier followed by postfix operators
176
+ * (`\prime`...) and some arguments.
157
177
  */
158
- matchFunction(until?: Partial<Terminator>): Expression | null;
178
+ private parseFunction;
179
+ parseSymbol(until?: Partial<Terminator>): Expression | null;
159
180
  /**
160
- * A symbol is an identifier or a custom definition
181
+ * Parse a sequence superfix/subfix operator, e.g. `^{*}`
182
+ *
183
+ * Superfix and subfix need special handling:
184
+ *
185
+ * - they act mostly like an infix operator, but they are commutative, i.e.
186
+ * `x_a^b` should be parsed identically to `x^b_a`.
187
+ *
188
+ * - furthermore, in LaTeX `x^a^b` parses the same as `x^a{}^b`.
189
+ *
161
190
  */
162
- matchSymbol(until?: Partial<Terminator>): Expression | null;
163
- matchLatexOptionalGroup(): Expression | null;
164
- matchSingleAtomArgument(): Expression | null;
165
- matchLatexGroup(): Expression | null;
166
- matchSupsub(lhs: Expression | null): Expression | null;
167
- matchPostfix(lhs: Expression | null): Expression | null;
191
+ private parseSupsub;
192
+ parsePostfixOperator(lhs: Expression | null, until?: Partial<Terminator>): Expression | null;
168
193
  /** Match a string used as a LaTeX identifier, for example an environment
169
194
  * name.
170
195
  * Not suitable for general purpose text, e.g. argument of a `\text{}
171
196
  * command. See `matchChar()` instead.
172
197
  */
173
- matchString(): string;
174
- /** Match a string as an argument (in a `{}` pair) */
175
- matchStringArgument(): string | null;
176
- /**
177
- * Match an expression in a tabular format, where rows are separated by `\\`
178
- * and columns by `&`.
179
- *
180
- * Return rows of sparse columns: empty rows are indicated with `Nothing`,
181
- * and empty cells are also indicated with `Nothing`.
182
- */
183
- matchTabular(): null | Expression[][];
184
- matchEnvironment(): Expression | null;
198
+ private parseStringGroupContent;
185
199
  /**
186
200
  * Apply an invisible operator between two expressions.
187
201
  *
@@ -203,19 +217,30 @@ export declare class _Parser implements Parser {
203
217
  * - x2 -> no
204
218
  * => lhs is a number, rhs is a number, but not a literal
205
219
  */
206
- applyInvisibleOperator(until: Terminator, lhs: Expression | null): Expression | null;
207
- matchUnexpectedLatexCommand(): Expression | null;
220
+ private applyInvisibleOperator;
221
+ /**
222
+ * This is an error handling method. We've encountered a LaTeX command
223
+ * but were not able to match it to any entry in the LaTeX dictionary,
224
+ * or ran into it in an unexpected context (postfix operator lacking an
225
+ * argument, for example)
226
+ */
227
+ private parseUnexpectedLatexCommand;
208
228
  /**
209
229
  * <primary> :=
210
- * (<number> | <symbol> | <environment> | <matchfix-expr>) <subsup>* <postfix-operator>*
230
+ * (<number> | <symbol> | <environment> | <matchfix-expr>)
231
+ * <subsup>* <postfix-operator>*
211
232
  *
212
- * <symbol> ::= (<symbol-id> | (<latex-command><latex-arguments>)) <arguments>
233
+ * <symbol> ::=
234
+ * (<symbol-id> | (<latex-command><latex-arguments>)) <arguments>
213
235
  *
214
236
  * <matchfix-expr> :=
215
- * <matchfix-op-open> <expression> [<matchfix-op-separator> <expression>] <matchfix-op-close>
237
+ * <matchfix-op-open>
238
+ * <expression>
239
+ * (<matchfix-op-separator> <expression>)*
240
+ * <matchfix-op-close>
216
241
  *
217
242
  */
218
- matchPrimary(until?: Partial<Terminator>): Expression | null;
243
+ private parsePrimary;
219
244
  /**
220
245
  * Parse an expression:
221
246
  *
@@ -224,12 +249,14 @@ export declare class _Parser implements Parser {
224
249
  * | <prefix-op> <primary>
225
250
  * | <primary> <infix-op> <expression>
226
251
  *
227
- * Stop when an operator of precedence less than `until.minPrec` is encountered
252
+ * Stop when an operator of precedence less than `until.minPrec`
253
+ * is encountered
228
254
  */
229
- matchExpression(until?: Partial<Terminator>): Expression | null;
255
+ parseExpression(until?: Partial<Terminator>): Expression | null;
230
256
  /**
231
257
  * Add LaTeX or other requested metadata to the expression
232
258
  */
233
259
  decorate(expr: Expression | null, start: number): Expression | null;
234
260
  error(code: string | [string, ...Expression[]], fromToken: number): Expression;
261
+ private isFunctionHead;
235
262
  }