@cortex-js/compute-engine 0.4.0 → 0.4.3

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 (104) hide show
  1. package/README.md +2 -2
  2. package/dist/compute-engine.esm.js +22846 -16608
  3. package/dist/compute-engine.js +23518 -17282
  4. package/dist/compute-engine.min.esm.js +2 -7
  5. package/dist/compute-engine.min.js +2 -7
  6. package/dist/math-json.esm.js +4337 -10529
  7. package/dist/math-json.js +4354 -10532
  8. package/dist/math-json.min.esm.js +2 -7
  9. package/dist/math-json.min.js +2 -7
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +90 -0
  12. package/dist/types/compute-engine/assume.d.ts +21 -0
  13. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
  14. package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
  15. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
  16. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
  17. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
  18. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +93 -0
  19. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
  20. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
  21. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
  22. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
  24. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  25. package/dist/types/compute-engine/boxed-expression/order.d.ts +52 -0
  26. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
  27. package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
  28. package/dist/types/compute-engine/compute-engine.d.ts +252 -0
  29. package/dist/types/compute-engine/cost-function.d.ts +3 -0
  30. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
  31. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
  32. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
  33. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
  34. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
  35. package/dist/types/compute-engine/dictionary/collections.d.ts +2 -0
  36. package/dist/types/compute-engine/dictionary/core.d.ts +2 -0
  37. package/dist/types/compute-engine/dictionary/dictionary.d.ts +26 -0
  38. package/dist/types/compute-engine/dictionary/logic.d.ts +2 -0
  39. package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
  40. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
  41. package/dist/types/compute-engine/dictionary/sets.d.ts +2 -0
  42. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -0
  43. package/dist/types/compute-engine/domain-utils.d.ts +30 -0
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
  53. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  54. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
  55. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
  56. package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
  57. package/dist/types/compute-engine/latex-syntax/public.d.ts +550 -0
  58. package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +2 -3
  59. package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
  60. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +43 -0
  61. package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
  62. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  63. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
  64. package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
  65. package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
  66. package/dist/types/compute-engine/public.d.ts +1076 -434
  67. package/dist/types/compute-engine/rules.d.ts +18 -0
  68. package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
  69. package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
  70. package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
  71. package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
  72. package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
  73. package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
  74. package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
  75. package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
  76. package/dist/types/compute-engine.d.ts +3 -0
  77. package/dist/types/math-json/math-json-format.d.ts +101 -0
  78. package/dist/types/math-json/utils.d.ts +97 -0
  79. package/dist/types/math-json.d.ts +5 -3
  80. package/package.json +39 -36
  81. package/dist/types/common/utils.d.ts +0 -153
  82. package/dist/types/compute-engine/expression-map.d.ts +0 -11
  83. package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
  84. package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
  85. package/dist/types/compute-engine/numeric.d.ts +0 -21
  86. package/dist/types/compute-engine/patterns.d.ts +0 -22
  87. package/dist/types/compute-engine/predicates.d.ts +0 -42
  88. package/dist/types/compute-engine/utils.d.ts +0 -15
  89. package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
  90. package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
  91. package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
  92. package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
  93. package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
  94. package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
  95. package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
  96. package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
  97. package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
  98. package/dist/types/latex-syntax/definitions.d.ts +0 -40
  99. package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
  100. package/dist/types/latex-syntax/parse.d.ts +0 -138
  101. package/dist/types/latex-syntax/public.d.ts +0 -455
  102. package/dist/types/latex-syntax/serializer.d.ts +0 -26
  103. package/dist/types/latex-syntax/utils.d.ts +0 -10
  104. package/dist/types/public.d.ts +0 -163
@@ -1,455 +0,0 @@
1
- /* 0.4.0 */
2
- export declare type LatexToken = string | '<{>' | '<}>' | '<space>' | '<$>' | '<$$>';
3
- export declare type LatexString = string;
4
- /**
5
- * Custom parser function.
6
- *
7
- * It is triggered by a latex fragment (the `latex` argument). When invoked,
8
- * the scanner points right after that latex fragment. The scanner should be
9
- * moved, by calling `scanner.next()` for every consumed token.
10
- *
11
- * If it was in an infix or postfix context, `lhs` will represent the
12
- * left-hand side argument. In a prefix or matchfix context, `lhs` is `null`.
13
- *
14
- * The function should return a tuple:
15
- *
16
- * - Its first element is an unprocessed left-hand side, if any. If the
17
- * left-hand-side has been consumed (for example if this was a valid infix
18
- * operator), the first element of the tuple should be `null`.
19
- *
20
- * - Its second element is the resulting expression.
21
- *
22
- */
23
- export declare type ParserFunction<T extends number = number> = (lhs: Expression<T> | null, scanner: Scanner<T>, minPrec: number) => [lhs: Expression<T> | null, result: Expression<T> | null];
24
- /**
25
- * Maps a string of Latex tokens to a function or symbol and vice-versa.
26
- *
27
- */
28
- export declare type LatexDictionaryEntry<T extends number = number> = {
29
- /**
30
- * Map a function or symbol name to this record.
31
- *
32
- * Each record should have at least a `name` or a `trigger`
33
- */
34
- name?: string;
35
- /**
36
- * Map one or more latex tokens to this record.
37
- *
38
- * As a shortcut, if the trigger is a LatexToken, it is assumed to be a symbol.
39
- *
40
- * There can be multiple entries (for example '+' is both an infix and a
41
- * prefix)
42
- */
43
- trigger?: LatexToken | {
44
- symbol?: LatexToken | LatexToken[];
45
- matchfix?: LatexToken | LatexToken[];
46
- /**
47
- * Infix position, with an operand before and an operand after: `a ⊛ b`.
48
- *
49
- * Example: `+`, `\times`
50
- */
51
- infix?: LatexToken | LatexToken[];
52
- /**
53
- * Prefix position, with an operand after: `⊛ a`
54
- *
55
- * Example: `-`, `\not`
56
- */
57
- prefix?: LatexToken | LatexToken[];
58
- /**
59
- * Postfix position, with an operand before: `a⊛`
60
- */
61
- postfix?: LatexToken | LatexToken[];
62
- /**
63
- * Superfix position (in a superscript), with the base of the
64
- * superscript as the operand: `a^{⊛}`
65
- */
66
- superfix?: LatexToken | LatexToken[];
67
- /**
68
- * Subfix position (in a subscript), with the base of the
69
- * subscript as the operand: `a_{⊛}`
70
- */
71
- subfix?: LatexToken | LatexToken[];
72
- /**
73
- * The name of an environment, as used in `\begin{matrix}` where
74
- * `"matrix"` is the name of the environment.
75
- *
76
- */
77
- environment?: string;
78
- };
79
- /**
80
- * A function that returns an expression, or an expression
81
- */
82
- parse?: Expression<T> | ParserFunction<T>;
83
- /**
84
- * The Latex to serialize.
85
- */
86
- serialize?: SerializerFunction<T> | LatexString;
87
- /**
88
- * If `trigger` is `'infix'``
89
- * - **`both`**: a + b + c -> +(a, b, c)
90
- * - **`left`**: a / b / c -> /(/(a, b), c)
91
- * - **`right`**: a = b = c -> =(a, =(b, c))
92
- * - **`non`**: a < b < c -> syntax error
93
- *
94
- * - a `both`-associative operator has an unlimited number of arguments
95
- * - a `left`, `right` or `non` associative operator has at most two arguments
96
- */
97
- associativity?: 'right' | 'left' | 'non' | 'both';
98
- /** If `trigger` is `'infix'`` */
99
- precedence?: number;
100
- /**
101
- * If `trigger` is `'symbol'``.
102
- * Indicate if this symbol can be followed by arguments.
103
- * The presence of arguments will indicate that the arguments should be
104
- * applied to the symbol. Otherwise, the invisible operator is applied
105
- * to the symbol and the arguments.
106
- *
107
- * If `arguments` is `"group"`:
108
- *
109
- * "f(x)" -> `["f", "x"]`
110
- * "f x" -> `["multiply", "f", "x"]`
111
- *
112
- * If `arguments` is `""`:
113
- *
114
- * "f(x)" -> `["multiply", "f", ["group", "x"]]`
115
- * "f x" -> `["multiply", "f", "x"]`
116
- *
117
- * If `arguments` is `"group/primary"` and the symbol is followed either
118
- * by a group or by a primary (prefix + symbol + subsupfix + postfix).
119
- * Used for trig functions. i.e. `\sin x` vs `\sin(x)`:
120
- *
121
- * "f(x)" -> `["f", "x"]`
122
- * "f x" -> `["f", "x"]`
123
- *
124
- */
125
- arguments?: 'group' | 'implicit' | '';
126
- /**
127
- * If `trigger` is `'symbol'``.
128
- *
129
- * If a Latex command (i.e. the trigger starts with `\`, e.g. `\sqrt`)
130
- * indicates the number of optional arguments expected (indicate with
131
- * square brackets).
132
- *
133
- * For example, for the `\sqrt` command, 1: `\sqrt[3]{x}`
134
- *
135
- */
136
- optionalLatexArg?: number;
137
- /**
138
- * If `trigger` is `'symbol'``.
139
- *
140
- * If a Latex command (i.e. the trigger starts with `\`, e.g. `\frac`)
141
- * indicates the number of required arguments expected (indicated with
142
- * curly braces).
143
- *
144
- * For example, for the `\frac` command, 2: `\frac{1}{n}`
145
- *
146
- */
147
- requiredLatexArg?: number;
148
- /**
149
- * If `trigger` is `'matchfix'``.
150
- */
151
- separator?: LatexString;
152
- closeFence?: LatexToken | LatexToken[];
153
- };
154
- export declare type LatexDictionary<T extends number = number> = LatexDictionaryEntry<T>[];
155
- export declare type ParseLatexOptions = {
156
- /**
157
- * If a symbol follows a number, consider them separated by this
158
- * invisible operator.
159
- *
160
- * Default: `"Multiply"`
161
- */
162
- invisibleOperator?: string;
163
- /**
164
- * If true, ignore space characters.
165
- *
166
- */
167
- skipSpace?: boolean;
168
- /**
169
- * When an unknown latex command is encountered, attempt to parse
170
- * any arguments it may have.
171
- *
172
- * For example, `\foo{x+1}` would produce `['\foo', ['Add', 'x', 1]]` if
173
- * this property is true, `['LatexSymbols', '\foo', '<{>', 'x', '+', 1, '<{>']`
174
- * otherwise.
175
- */
176
- parseArgumentsOfUnknownLatexCommands?: boolean;
177
- /**
178
- * When a number is encountered, parse it.
179
- *
180
- * Otherwise, return each token making up the number (minus sign, digits,
181
- * decimal separator, etc...)
182
- */
183
- parseNumbers?: boolean;
184
- /**
185
- * If this setting is not empty, when a number is immediately followed by a
186
- * fraction, assume that the fraction should be added to the number, that
187
- * is that there is an invisible plus operator between the two.
188
- *
189
- * For example with `2\frac{3}{4}`:
190
- * - when `invisiblePlusOperator` is `"add"` : `["add", 2, ["divide", 3, 4]]`
191
- * - when `invisiblePlusOperator` is `""`: `["multiply", 2, ["divide", 3, 4]]`
192
- */
193
- invisiblePlusOperator?: string;
194
- /**
195
- * When a token is encountered at a position where a symbol could be
196
- * parsed, if the token matches `promoteUnknownSymbols` it will be
197
- * accepted as a symbol (an `unknown-symbol` error will still be triggered
198
- * so that the caller can be notified). Otherwise, the symbol is rejected.
199
- */
200
- promoteUnknownSymbols?: RegExp;
201
- /**
202
- * When one of these commands is encountered, it is skipped.
203
- *
204
- * Useful for purely presentational commands such as `\displaystyle`
205
- */
206
- ignoreCommands?: LatexToken[];
207
- /**
208
- * When one these commands is encountered, its argument is parsed,
209
- * as if the command was not present.
210
- *
211
- * Useful for some presentational commands such as `\left`, `\bigl`, etc...
212
- */
213
- idempotentCommands?: LatexToken[];
214
- /**
215
- * When a token is encountered at a position that could match
216
- * a function call, and it is followed by an apply function operator
217
- * (typically, parentheses), consider them to a be a function if the
218
- * string of tokens match this regular expression.
219
- *
220
- * While this is a convenient shortcut, it is recommended to more explicitly
221
- * define custom functions by providing an entry for them in a function
222
- * dictionary (providing additional information about their arguments, etc...)
223
- * and in a Latex translation dictionary (indicating what Latex markup
224
- * corresponds to the function).
225
- *
226
- * Example:
227
- *
228
- * By default, `f(x)` is parsed as `["Multiply", "f", "x"]`.
229
- *
230
- * After...
231
- *
232
- * ```
233
- * promoteUnknownFunctions = /^[fg]$/
234
- * ```
235
- *
236
- * ... `f(x)` is parsed as `["f", "x"]`
237
- *
238
- *
239
- */
240
- promoteUnknownFunctions?: RegExp;
241
- /**
242
- * If true, the expression will be decorated with the Latex
243
- * fragments corresponding to each elements of the expression
244
- */
245
- preserveLatex?: boolean;
246
- };
247
- export declare type SerializeLatexOptions = {
248
- /**
249
- * Latex string used to render an invisible multiply, e.g. in '2x'.
250
- * Leave it empty to join the adjacent terms, or use `\cdot` to insert
251
- * a `\cdot` operator between them, i.e. `2\cdot x`.
252
- *
253
- * Empty by default.
254
- */
255
- invisibleMultiply?: LatexString;
256
- /**
257
- * Latex string used for an invisible plus, e.g. in '1 3/4'.
258
- * Leave it empty to join the main number and the fraction, i.e. render it
259
- * as `1\frac{3}{4}`, or use `+` to insert a `+` operator between them, i.e.
260
- * `1+\frac{3}{4}`
261
- *
262
- * Empty by default.
263
- */
264
- invisiblePlus?: LatexString;
265
- /**
266
- * Latex string used for an explicit multiply operator,
267
- *
268
- * Default: `\times`
269
- */
270
- multiply?: LatexString;
271
- };
272
- export declare type NumberFormattingOptions = {
273
- precision?: number;
274
- positiveInfinity?: string;
275
- negativeInfinity?: string;
276
- notANumber?: string;
277
- /**
278
- * A string representing the decimal marker, the string separating
279
- * the whole portion of a number from the fractional portion, i.e.
280
- * the '.' in '3.1415'.
281
- *
282
- * Default: `"."`
283
- */
284
- decimalMarker?: string;
285
- /**
286
- * A string representing the separator between groups of digits,
287
- * used to improve readability of numbers with lots of digits.
288
- *
289
- * Default: `","`
290
- */
291
- groupSeparator?: string;
292
- exponentProduct?: string;
293
- beginExponentMarker?: string;
294
- endExponentMarker?: string;
295
- notation?: 'engineering' | 'auto' | 'scientific';
296
- truncationMarker?: string;
297
- beginRepeatingDigits?: string;
298
- endRepeatingDigits?: string;
299
- imaginaryNumber?: string;
300
- };
301
- /**
302
- * To customize the parsing and serializing of Latex syntax, create a `LatexSyntax`
303
- * instance.
304
- */
305
- export declare class LatexSyntax<T extends number = number> {
306
- /**
307
- *
308
- * @param onError - Called when a non-fatal error is encountered. When parsing,
309
- * the parser will attempt to recover and continue.
310
- *
311
- */
312
- constructor(options?: NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions & {
313
- onError?: ErrorListener<ErrorCode>;
314
- });
315
- /**
316
- * Return a Latex dictionary suitable for the specified category, or `"all"`
317
- * for all categories (`"arithmetic"`, `"algebra"`, etc...).
318
- *
319
- * A Latex dictionary is needed to translate between Latex and MathJSON.
320
- *
321
- * Each entry in the dictionary indicate how a Latex token (or string of
322
- * tokens) should be parsed into a MathJSON expression.
323
- *
324
- * For example an entry can define that the `\pi` Latex token should map to the
325
- * symbol `"Pi"`, or that the token `-` should map to the function
326
- * `["Negate",...]` when in a prefix position and to the function
327
- * `["Subtract", ...]` when in an infix position.
328
- *
329
- * Furthermore, the information in each dictionary entry is used to serialize
330
- * the Latex string corresponding to a MathJSON expression.
331
- *
332
- * Use the value returned by this function to the `options` argument of the
333
- * constructor.
334
- */
335
- static getDictionary(domain?: DictionaryCategory | 'all'): Readonly<LatexDictionary<any>>;
336
- parse(latex: LatexString): Expression<T>;
337
- serialize(expr: Expression<T>): LatexString;
338
- }
339
- export interface Serializer<T extends number = number> {
340
- readonly onError: ErrorListener<ErrorCode>;
341
- readonly options: Required<SerializeLatexOptions>;
342
- /** "depth" of the expression:
343
- * - 0 for the root
344
- * - 1 for the arguments of the root
345
- * - 2 for the arguments of the arguments of the root
346
- * - etc...
347
- *
348
- * This allows for variation of the Latex serialized based
349
- * on the depth of the expression, for example using `\Bigl(`
350
- * for the top level, and `\bigl(` or `(` for others.
351
- */
352
- level: number;
353
- /** Output a Latex string representing the expression */
354
- serialize: (expr: Expression<T> | null) => string;
355
- wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none'): string;
356
- /** Add a group fence around the expression if it is
357
- * an operator of precedence less than or equal to `prec`.
358
- */
359
- wrap: (expr: Expression<T> | null, prec?: number) => string;
360
- /** Add a group fence around the expression if it is
361
- * short (not a function)
362
- */
363
- wrapShort(expr: Expression<T> | null): string;
364
- }
365
- export declare type SerializerFunction<T extends number = number> = (serializer: Serializer<T>, expr: T | Expression<T>) => string;
366
- export interface Scanner<T extends number = number> {
367
- readonly onError: ErrorListener<ErrorCode>;
368
- readonly options: Required<ParseLatexOptions>;
369
- index: number;
370
- readonly atEnd: boolean;
371
- /** Return the next token, without advancing the index */
372
- readonly peek: LatexToken;
373
- /** Return an array of string corresponding to tokens ahead.
374
- * The index is unchanged.
375
- */
376
- lookAhead(): string[];
377
- /** Return the next token and advance the index */
378
- next(): LatexToken;
379
- /** Return a latex string before the index */
380
- latexBefore(): string;
381
- /** Return a latex string after the index */
382
- latexAfter(): string;
383
- /** If there are any space, advance the index until a non-space is encountered */
384
- skipSpace(): boolean;
385
- /** If the next token matches the target advance and return true. Otherwise
386
- * return false */
387
- match(target: LatexToken): boolean;
388
- matchAny(targets: LatexToken[]): LatexToken;
389
- matchWhile(targets: LatexToken[]): LatexToken[];
390
- /** If the next token matches a `+` or `-` sign, return it and advance the index.
391
- * Otherwise return `''` and do not advance */
392
- matchSign(): string;
393
- matchDecimalDigits(): string;
394
- matchSignedInteger(): string;
395
- matchExponent(): string;
396
- matchNumber(): string;
397
- matchTabular(): null | Expression<T>;
398
- applyOperator(op: string, lhs: Expression<T> | null, rhs: Expression<T> | null): NonNullable<[Expression<T> | null, Expression<T> | null]>;
399
- applyInvisibleOperator(lhs: Expression<T> | null, rhs: Expression<T> | null): Expression<T> | null;
400
- /** If the next tokens correspond to an optional argument,
401
- * enclosed with `[` and `]` return the content of the argument
402
- * as an expression and advance the index past the closing `]`.
403
- * Otherwise, return null
404
- */
405
- matchOptionalLatexArgument(): Expression<T> | null;
406
- matchRequiredLatexArgument(): Expression<T> | null;
407
- matchArguments(kind: '' | 'group' | 'implicit'): Expression<T>[] | null;
408
- matchSupsub(lhs: Expression<T> | null): Expression<T> | null;
409
- /**
410
- * <primary> :=
411
- * (<number> | <symbol> | <latex-command> | <function-call> | <matchfix-expr>)
412
- * (<subsup> | <postfix-operator>)*
413
- *
414
- * <matchfix-expr> :=
415
- * <matchfix-op-open> <expression> <matchfix-op-close>
416
- *
417
- * <function-call> ::=
418
- * | <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
419
- *
420
- * If not a primary, return `null` and do not advance the index.
421
- */
422
- matchPrimary(minPrec?: number): Expression<T> | null;
423
- /**
424
- * Parse an expression:
425
- *
426
- * <expression> ::=
427
- * | <prefix-op> <expression>
428
- * | <primary>
429
- * | <primary> <infix-op> <expression>
430
- *
431
- * Stop when an operator of precedence less than `minPrec` is encountered
432
- *
433
- * `minPrec` is 0 by default.
434
- */
435
- matchExpression(minPrec?: number): Expression<T> | null;
436
- matchBalancedExpression(open: LatexToken, close: LatexToken, onError?: ErrorListener<ErrorCode>): Expression<T> | null;
437
- }
438
- /**
439
- * Parse a Latex string and return a corresponding MathJSON expression.
440
- *
441
- * @param onError - Called when a non-fatal error is encountered while parsing.
442
- * The parsing will attempt to recover and continue.
443
- *
444
- */
445
- export declare function parse<T extends number = number>(latex: LatexString, options?: NumberFormattingOptions & ParseLatexOptions & {
446
- onError?: ErrorListener<ErrorCode>;
447
- }): Expression<T>;
448
- /**
449
- * Serialize a MathJSON expression as a Latex string.
450
- *
451
- */
452
- export declare function serialize<T extends number = number>(expr: Expression<T>, options?: NumberFormattingOptions & SerializeLatexOptions & {
453
- dictionary?: Readonly<LatexDictionary<T>>;
454
- onError?: ErrorListener<ErrorCode>;
455
- }): LatexString;
@@ -1,26 +0,0 @@
1
- /* 0.4.0 */
2
- import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
3
- import { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './definitions';
4
- export declare class Serializer<T extends number = number> implements Serializer<T> {
5
- readonly dictionary: IndexedLatexDictionary<T>;
6
- readonly onError: ErrorListener<ErrorCode>;
7
- readonly options: Required<NumberFormattingOptions> & Required<SerializeLatexOptions>;
8
- level: number;
9
- constructor(options: Required<NumberFormattingOptions> & Required<SerializeLatexOptions>, dictionary: IndexedLatexDictionary<T>, onError: ErrorListener<ErrorCode>);
10
- /**
11
- * Serialize the expression, and if the expression is an operator
12
- * of precedence less than or equal to prec, wrap it in some paren.
13
- * @todo: don't wrap abs
14
- */
15
- wrap(expr: Expression<T> | null, prec?: number): string;
16
- /** If this is a "short" expression (atomic), wrap it.
17
- *
18
- */
19
- wrapShort(expr: Expression<T> | null): string;
20
- wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none'): string;
21
- serializeSymbol(expr: Expression<T>, def?: IndexedLatexDictionaryEntry<T>): string;
22
- serializeDictionary(dict: {
23
- [key: string]: Expression<T>;
24
- }): string;
25
- serialize(expr: T | Expression<T> | null): LatexString;
26
- }
@@ -1,10 +0,0 @@
1
- /* 0.4.0 */
2
- export declare const DEFAULT_LATEX_NUMBER_OPTIONS: Required<NumberFormattingOptions>;
3
- export declare const DEFAULT_PARSE_LATEX_OPTIONS: Required<ParseLatexOptions>;
4
- export declare const DEFAULT_SERIALIZE_LATEX_OPTIONS: Required<SerializeLatexOptions>;
5
- export declare function appendLatex(src: string, s: string): string;
6
- /**
7
- * Replace '#1', '#2' in the latex template stings with the corresponding
8
- * values from `replacement`, in a Latex syntax safe manner (i.e. inserting spaces when needed)
9
- */
10
- export declare function replaceLatex(template: string, replacement: string[]): string;
@@ -1,163 +0,0 @@
1
- /* 0.4.0 */
2
- export declare type SignalCode = RuntimeSignalCode | ('syntax-error' | 'invalid-name' | 'expected-predicate' | 'expected-symbol' | 'cyclic-definition' | 'invalid-supersets' | 'expected-supersets' | 'unknown-domain' | 'duplicate-wikidata' | 'invalid-dictionary-entry');
3
- export declare type SignalMessage = SignalCode | [SignalCode, ...any[]];
4
- export declare type SignalOrigin = {
5
- url?: string;
6
- source?: string;
7
- offset?: number;
8
- line?: number;
9
- column?: number;
10
- around?: string;
11
- };
12
- export declare type Signal = {
13
- severity?: 'warning' | 'error';
14
- message: SignalMessage;
15
- head?: string;
16
- origin?: SignalOrigin;
17
- };
18
- export declare type ErrorSignal = Signal & {
19
- severity: 'error';
20
- };
21
- export declare class CortexError extends Error {
22
- constructor(errorSignal: Signal);
23
- toString(): string;
24
- }
25
- export declare type WarningSignal = Signal & {
26
- severity: 'warning';
27
- };
28
- export declare type ErrorSignalHandler = (error: ErrorSignal) => void;
29
- export declare type WarningSignalHandler = (warnings: WarningSignal[]) => void;
30
- export declare type ErrorListener<T> = (err: {
31
- code: T;
32
- arg?: string;
33
- latex?: string;
34
- before?: string;
35
- after?: string;
36
- }) => void;
37
- /**
38
- * * `unknown-symbol`: a symbol was encountered which does not have a
39
- * definition.
40
- *
41
- * * `unknown-operator`: a presumed operator was encountered which does not
42
- * have a definition.
43
- *
44
- * * `unknown-function`: a Latex command was encountered which does not
45
- * have a definition.
46
- *
47
- * * `unexpected-command`: a Latex command was encountered when only a string
48
- * was expected
49
- *
50
- * * `unexpected-superscript`: a superscript was encountered in an unexpected
51
- * context, or no `powerFunction` was defined. By default, superscript can
52
- * be applied to numbers, symbols or expressions, but not to operators (e.g.
53
- * `2+^34`) or to punctuation.
54
- *
55
- * * `unexpected-subscript`: a subscript was encountered in an unexpected
56
- * context or no 'subscriptFunction` was defined. By default, subscripts
57
- * are not expected on numbers, operators or symbols. Some commands (e.g. `\sum`)
58
- * do expected a subscript.
59
- *
60
- * * `unexpected-sequence`: some adjacent elements were encountered (for
61
- * example `xy`), but no `invisibleOperator` is defined, therefore the elements
62
- * can't be combined. The default `invisibleOperator` is `multiply`, but you
63
- * can also use `list`.
64
- *
65
- * * `expected-argument`: a Latex command that requires one or more argument
66
- * was encountered without the required arguments.
67
- *
68
- * * `expected-operand`: an operator was encountered without its required
69
- * operands.
70
- *
71
- * * `non-associative-operator`: an operator which is not associative was
72
- * encountered in an associative context, for example: `a < b < c` (assuming
73
- * `<` is defined as non-associative)
74
- *
75
- * * `postfix-operator-requires-one-operand`: a postfix operator which requires
76
- * a single argument was encountered with no arguments or more than one argument
77
- *
78
- * * `prefix-operator-requires-one-operand`: a prefix operator which requires
79
- * a single argument was encountered with no arguments or more than one argument
80
- *
81
- * * `base-out-of-range`: The base is expected to be between 2 and 36.
82
- *
83
- */
84
- export declare type ErrorCode = 'expected-argument' | 'unexpected-argument' | 'expected-operator' | 'expected-operand' | 'invalid-name' | 'invalid-dictionary-entry' | 'unknown-symbol' | 'unknown-operator' | 'unknown-function' | 'unknown-command' | 'unexpected-command' | 'unbalanced-symbols' | 'unexpected-superscript' | 'unexpected-subscript' | 'unexpected-sequence' | 'non-associative-operator' | 'function-has-too-many-arguments' | 'function-has-too-few-arguments' | 'operator-requires-one-operand' | 'infix-operator-requires-two-operands' | 'prefix-operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'associative-function-has-too-few-arguments' | 'commutative-function-has-too-few-arguments' | 'threadable-function-has-too-few-arguments' | 'hold-first-function-has-too-few-arguments' | 'hold-rest-function-has-too-few-arguments' | 'base-out-of-range' | 'syntax-error';
85
- export declare type Attributes = {
86
- /** A human readable string to annotate an expression, since JSON does not
87
- * allow comments in its encoding */
88
- comment?: string;
89
- /** A Markdown-encoded string providing documentation about this expression.
90
- */
91
- documentation?: string;
92
- /** A human readable string to indicate a syntax error or
93
- * other problem when parsing or evaluating an expression.
94
- */
95
- error?: string;
96
- /** A visual representation in LaTeX of the expression.
97
- *
98
- * This can be useful to preserve non-semantic details, for example
99
- * parentheses in an expression or styling attributes
100
- */
101
- latex?: string;
102
- /**
103
- * A short string indicating an entry in a wikibase.
104
- *
105
- * For example
106
- * `"Q167"` is the [wikidata entry](https://www.wikidata.org/wiki/Q167)
107
- * for the Pi constant.
108
- */
109
- wikidata?: string;
110
- /** A base URL for the `wikidata` key.
111
- *
112
- * A full URL can be produced by concatenating this key with the `wikidata`
113
- * key. This key applies to this node and all its children.
114
- *
115
- * The default value is "https://www.wikidata.org/wiki/"
116
- */
117
- wikibase?: string;
118
- /** A short string indicating an entry in an OpenMath Content Dictionary.
119
- *
120
- * For example: `arith1/#abs`.
121
- *
122
- */
123
- openmathSymbol?: string;
124
- /** A base URL for an OpenMath content dictionary. This key applies to this
125
- * node and all its children.
126
- *
127
- * The default value is "http://www.openmath.org/cd".
128
- */
129
- openmathCd?: string;
130
- /** A url to the source of this expression.
131
- */
132
- sourceUrl?: string;
133
- /** The source from which this expression was generated.
134
- *
135
- * It could be a Latex expression, or some other source language
136
- */
137
- sourceContent?: string;
138
- /**
139
- * A character offset in `sourceContent` or `sourceUrl` from which this
140
- * expression was generated
141
- */
142
- sourceOffsets?: [start: number, end: number];
143
- };
144
- export declare type MathJsonBasicNumber = 'NaN' | '-Infinity' | '+Infinity' | string;
145
- export declare type MathJsonRealNumber = {
146
- num: MathJsonBasicNumber;
147
- } & Attributes;
148
- export declare type MathJsonSymbol = {
149
- sym: string;
150
- } & Attributes;
151
- export declare type MathJsonString = {
152
- str: string;
153
- } & Attributes;
154
- export declare type MathJsonFunction<T extends number = number> = {
155
- fn: Expression<T>[];
156
- } & Attributes;
157
- export declare type MathJsonDictionary<T extends number = number> = {
158
- dict: {
159
- [key: string]: Expression<T>;
160
- };
161
- } & Attributes;
162
- export declare type Expression<T extends number = number> = T | MathJsonRealNumber | MathJsonString | MathJsonSymbol | string | MathJsonFunction<T> | MathJsonDictionary<T> | Expression<T>[];
163
- export declare type DictionaryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'complex' | 'combinatorics' | 'core' | 'dimensions' | 'domains' | 'inequalities' | 'intervals' | 'linear-algebra' | 'logic' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relations' | 'rounding' | 'sets' | 'statistics' | 'symbols' | 'transcendentals' | 'trigonometry' | 'units';