@cortex-js/compute-engine 0.6.0 → 0.8.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.
- package/dist/compute-engine.esm.js +14942 -11619
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +62 -43
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +72 -57
- package/dist/types/compute-engine/boxed-expression/box.d.ts +2 -14
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +4 -4
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +36 -19
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +46 -38
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +6 -4
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +5 -5
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +13 -10
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +28 -14
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +25 -8
- package/dist/types/compute-engine/compute-engine.d.ts +72 -49
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -3
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +8 -7
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +3 -3
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +87 -62
- package/dist/types/compute-engine/latex-syntax/public.d.ts +65 -46
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +6 -4
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +11 -0
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +15 -0
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +19 -0
- package/dist/types/compute-engine/{dictionary → library}/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +2 -0
- package/dist/types/compute-engine/library/calculus.d.ts +2 -0
- package/dist/types/compute-engine/library/collections.d.ts +2 -0
- package/dist/types/compute-engine/library/core.d.ts +2 -0
- package/dist/types/compute-engine/library/domains.d.ts +15 -0
- package/dist/types/compute-engine/library/library.d.ts +17 -0
- package/dist/types/compute-engine/library/logic.d.ts +2 -0
- package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
- package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
- package/dist/types/compute-engine/library/sets.d.ts +2 -0
- package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +5 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +4 -2
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +717 -504
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +2 -2
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +27 -23
- package/dist/types/math-json/utils.d.ts +22 -16
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +20 -20
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +0 -11
- package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +0 -9
- package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +0 -17
- package/dist/types/compute-engine/dictionary/arithmetic.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/collections.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/core.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/dictionary.d.ts +0 -26
- package/dist/types/compute-engine/dictionary/logic.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/polynomials.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/relational-operator.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/sets.d.ts +0 -2
- package/dist/types/compute-engine/dictionary/trigonometry.d.ts +0 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
import { Complex } from 'complex.js';
|
|
3
3
|
import { Expression, MathJsonNumber } from '../math-json/math-json-format';
|
|
4
4
|
import { SignalMessage, WarningSignal } from '../common/signals';
|
|
5
|
-
import type {
|
|
6
|
-
import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine,
|
|
5
|
+
import type { LibraryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
6
|
+
import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, SymbolTable, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, Substitution, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, BoxedLambdaExpression, FunctionDefinition } from './public';
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
* To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
|
|
@@ -25,55 +25,70 @@ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefi
|
|
|
25
25
|
*/
|
|
26
26
|
export declare class ComputeEngine implements IComputeEngine {
|
|
27
27
|
/** @internal */
|
|
28
|
-
readonly
|
|
28
|
+
readonly _ZERO: BoxedExpression;
|
|
29
29
|
/** @internal */
|
|
30
|
-
readonly
|
|
30
|
+
readonly _ONE: BoxedExpression;
|
|
31
31
|
/** @internal */
|
|
32
|
-
readonly
|
|
32
|
+
readonly _TWO: BoxedExpression;
|
|
33
33
|
/** @internal */
|
|
34
|
-
readonly
|
|
34
|
+
readonly _HALF: BoxedExpression;
|
|
35
35
|
/** @internal */
|
|
36
|
-
readonly
|
|
36
|
+
readonly _NEGATIVE_ONE: BoxedExpression;
|
|
37
37
|
/** @internal */
|
|
38
|
-
readonly
|
|
38
|
+
readonly _I: BoxedExpression;
|
|
39
39
|
/** @internal */
|
|
40
|
-
readonly
|
|
40
|
+
readonly _NAN: BoxedExpression;
|
|
41
41
|
/** @internal */
|
|
42
|
-
readonly
|
|
42
|
+
readonly _POSITIVE_INFINITY: BoxedExpression;
|
|
43
43
|
/** @internal */
|
|
44
|
-
readonly
|
|
44
|
+
readonly _NEGATIVE_INFINITY: BoxedExpression;
|
|
45
45
|
/** @internal */
|
|
46
|
-
readonly
|
|
46
|
+
readonly _COMPLEX_INFINITY: BoxedExpression;
|
|
47
47
|
/** @internal */
|
|
48
|
-
|
|
48
|
+
_DECIMAL_NAN: Decimal;
|
|
49
49
|
/** @internal */
|
|
50
|
-
|
|
50
|
+
_DECIMAL_ZERO: Decimal;
|
|
51
51
|
/** @internal */
|
|
52
|
-
|
|
52
|
+
_DECIMAL_ONE: Decimal;
|
|
53
53
|
/** @internal */
|
|
54
|
-
|
|
54
|
+
_DECIMAL_TWO: Decimal;
|
|
55
55
|
/** @internal */
|
|
56
|
-
|
|
56
|
+
_DECIMAL_HALF: Decimal;
|
|
57
57
|
/** @internal */
|
|
58
|
-
|
|
58
|
+
_DECIMAL_PI: Decimal;
|
|
59
|
+
/** @internal */
|
|
60
|
+
_DECIMAL_NEGATIVE_ONE: Decimal;
|
|
59
61
|
/** @internal */
|
|
60
|
-
DECIMAL_NEGATIVE_ONE: Decimal;
|
|
61
62
|
private _precision;
|
|
63
|
+
/** @internal */
|
|
62
64
|
private _numericMode;
|
|
65
|
+
/** @internal */
|
|
63
66
|
private _latexSyntax?;
|
|
67
|
+
/** @internal */
|
|
64
68
|
private _tolerance;
|
|
69
|
+
/** @internal */
|
|
65
70
|
private _decimalTolerance;
|
|
71
|
+
/** @internal */
|
|
66
72
|
private _cache;
|
|
73
|
+
/** @internal */
|
|
67
74
|
private _stats;
|
|
75
|
+
/** @internal */
|
|
68
76
|
private _cost?;
|
|
77
|
+
/** @internal */
|
|
69
78
|
private _jsonSerializationOptions;
|
|
70
79
|
/** The domain of unknown symbols. If `null` unknown symbols do not have a
|
|
71
80
|
* definition automatically associated with them.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
72
83
|
*/
|
|
73
84
|
private _defaultDomain;
|
|
85
|
+
/** @internal */
|
|
74
86
|
private _commonSymbols;
|
|
87
|
+
/** @internal */
|
|
75
88
|
private _commonNumbers;
|
|
89
|
+
/** @internal */
|
|
76
90
|
private _commonDomains;
|
|
91
|
+
/** @internal */
|
|
77
92
|
private _latexDictionary?;
|
|
78
93
|
/**
|
|
79
94
|
* The current scope.
|
|
@@ -86,20 +101,20 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
86
101
|
* The `ce.context` property represents the current scope.
|
|
87
102
|
*
|
|
88
103
|
*/
|
|
89
|
-
context: RuntimeScope;
|
|
104
|
+
context: RuntimeScope | null;
|
|
90
105
|
/** Absolute time beyond which evaluation should not proceed.
|
|
91
106
|
* @internal
|
|
92
107
|
*/
|
|
93
108
|
deadline?: number;
|
|
94
109
|
/**
|
|
95
|
-
* Return
|
|
110
|
+
* Return symbol tables suitable for the specified categories, or `"all"`
|
|
96
111
|
* for all categories (`"arithmetic"`, `"algebra"`, etc...).
|
|
97
112
|
*
|
|
98
|
-
* A symbol
|
|
113
|
+
* A symbol table defines how the symbols and function names in a MathJSON
|
|
99
114
|
* expression should be interpreted, i.e. how to evaluate and manipulate them.
|
|
100
115
|
*
|
|
101
116
|
*/
|
|
102
|
-
static
|
|
117
|
+
static getSymbolTables(categories?: LibraryCategory[] | LibraryCategory | 'all'): Readonly<SymbolTable>[];
|
|
103
118
|
/**
|
|
104
119
|
* Construct a new `ComputeEngine` instance.
|
|
105
120
|
*
|
|
@@ -120,13 +135,13 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
120
135
|
* numeric calculations. Default is 100.
|
|
121
136
|
*
|
|
122
137
|
* @param options.tolerance If the absolute value of the difference of two numbers
|
|
123
|
-
* is less than `
|
|
138
|
+
* is less than `tolerance`, they are considered equal. Used by `chop()` as well.
|
|
124
139
|
*
|
|
125
140
|
* @param options.defaultDomain If an unknown symbol is encountered, assume it should
|
|
126
141
|
* be a variable in this domain. **Default** `ExtendedRealNumber`
|
|
127
142
|
*/
|
|
128
143
|
constructor(options?: {
|
|
129
|
-
|
|
144
|
+
symbolTables?: Readonly<SymbolTable>[];
|
|
130
145
|
latexDictionary?: readonly LatexDictionaryEntry[];
|
|
131
146
|
numericMode?: NumericMode;
|
|
132
147
|
numericPrecision?: number;
|
|
@@ -141,18 +156,14 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
141
156
|
*
|
|
142
157
|
* @internal
|
|
143
158
|
*/
|
|
144
|
-
|
|
159
|
+
reset(): void;
|
|
145
160
|
/** @internal */
|
|
146
|
-
_register(
|
|
161
|
+
_register(_expr: BoxedExpression): void;
|
|
147
162
|
/** @internal */
|
|
148
|
-
_unregister(
|
|
163
|
+
_unregister(_expr: BoxedExpression): void;
|
|
149
164
|
get stats(): ComputeEngineStats;
|
|
150
165
|
/** @internal */
|
|
151
166
|
_decimal: Decimal.Constructor;
|
|
152
|
-
/** @internal */
|
|
153
|
-
decimal: (a: Decimal.Value) => Decimal;
|
|
154
|
-
/** @internal */
|
|
155
|
-
complex: (a: number | Complex, b?: number) => Complex;
|
|
156
167
|
/** The precision, or number of significant digits, for numeric calculations
|
|
157
168
|
* such as when calling `ce.N()`.
|
|
158
169
|
*
|
|
@@ -180,8 +191,8 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
180
191
|
*
|
|
181
192
|
* **Default:** `"ExtendedRealNumber"`
|
|
182
193
|
*/
|
|
183
|
-
get defaultDomain():
|
|
184
|
-
set defaultDomain(domain:
|
|
194
|
+
get defaultDomain(): BoxedDomain | null;
|
|
195
|
+
set defaultDomain(domain: BoxedDomain | string | null);
|
|
185
196
|
/**
|
|
186
197
|
* Values smaller than the tolerance are considered to be zero for the
|
|
187
198
|
* purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
|
|
@@ -189,6 +200,10 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
189
200
|
*/
|
|
190
201
|
get tolerance(): number;
|
|
191
202
|
set tolerance(val: number);
|
|
203
|
+
/** @internal */
|
|
204
|
+
decimal(a: Decimal.Value): Decimal;
|
|
205
|
+
/** @internal */
|
|
206
|
+
complex(a: number | Complex, b?: number): Complex;
|
|
192
207
|
/** Replace a number that is close to 0 with the exact integer 0.
|
|
193
208
|
*
|
|
194
209
|
* How close to 0 the number has to be to be considered 0 is determined by {@link tolerance}.
|
|
@@ -197,25 +212,30 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
197
212
|
chop(n: Decimal): Decimal | 0;
|
|
198
213
|
chop(n: Complex): Complex | 0;
|
|
199
214
|
private get latexSyntax();
|
|
200
|
-
static getLatexDictionary(domain?:
|
|
215
|
+
static getLatexDictionary(domain?: LibraryCategory | 'all'): Readonly<LatexDictionary>;
|
|
201
216
|
set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
|
|
202
217
|
get costFunction(): (expr: BoxedExpression) => number;
|
|
203
218
|
/**
|
|
204
219
|
* Return a matching symbol definition, starting with the current
|
|
205
|
-
* scope and going up the scope chain.
|
|
220
|
+
* scope and going up the scope chain. Prioritize finding a match by
|
|
221
|
+
* wikidata, if provided.
|
|
206
222
|
*/
|
|
207
|
-
|
|
223
|
+
lookupSymbol(symbol: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
|
|
208
224
|
/**
|
|
209
|
-
* Return the definition for a function matching this head
|
|
210
|
-
*
|
|
225
|
+
* Return the definition for a function matching this head.
|
|
226
|
+
*
|
|
227
|
+
* Start looking in the current context, than up the scope chain.
|
|
211
228
|
*
|
|
212
|
-
*
|
|
229
|
+
* This is a very rough lookup, since it doesn't account for the domain
|
|
230
|
+
* of the argument or the codomain. However, it is useful during parsing
|
|
231
|
+
* to differentiate between symbols that might represent a function application, e.g. `f` vs `x`.
|
|
213
232
|
*/
|
|
214
|
-
|
|
233
|
+
lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
|
|
215
234
|
/**
|
|
216
235
|
* Add (or replace) a definition for a symbol in the current scope.
|
|
217
236
|
*/
|
|
218
237
|
defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
|
|
238
|
+
defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
|
|
219
239
|
/**
|
|
220
240
|
*
|
|
221
241
|
* Create a new scope and add it to the top of the scope stack
|
|
@@ -225,7 +245,7 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
225
245
|
*
|
|
226
246
|
*/
|
|
227
247
|
pushScope(options?: {
|
|
228
|
-
|
|
248
|
+
symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
|
|
229
249
|
assumptions?: (LatexString | Expression)[];
|
|
230
250
|
scope?: Partial<Scope>;
|
|
231
251
|
}): void;
|
|
@@ -264,7 +284,8 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
264
284
|
fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
265
285
|
/** @internal */
|
|
266
286
|
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
267
|
-
error(
|
|
287
|
+
error(message: ['invalid-domain', ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedDomain;
|
|
288
|
+
error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
|
|
268
289
|
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
269
290
|
mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
270
291
|
power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
@@ -274,14 +295,15 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
274
295
|
pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
275
296
|
tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
276
297
|
string(s: string, metadata?: Metadata): BoxedExpression;
|
|
277
|
-
symbol(
|
|
278
|
-
domain(domain: BoxedExpression | DomainExpression |
|
|
298
|
+
symbol(name: string, metadata?: Metadata): BoxedExpression;
|
|
299
|
+
domain(domain: BoxedExpression | DomainExpression | BoxedDomain, metadata?: Metadata): BoxedDomain;
|
|
300
|
+
lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
|
|
279
301
|
number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
|
|
280
302
|
rules(rules: Rule[]): BoxedRuleSet;
|
|
281
303
|
pattern(expr: LatexString | SemiBoxedExpression): Pattern;
|
|
282
|
-
parse(
|
|
304
|
+
parse(latex: LatexString | string): BoxedExpression;
|
|
283
305
|
parse(s: null): null;
|
|
284
|
-
parse(
|
|
306
|
+
parse(latex: LatexString | string | null): null | BoxedExpression;
|
|
285
307
|
serialize(x: Expression | BoxedExpression): string;
|
|
286
308
|
get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
287
309
|
set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
|
|
@@ -297,7 +319,8 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
297
319
|
* ```
|
|
298
320
|
*/
|
|
299
321
|
ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
|
|
300
|
-
|
|
322
|
+
infer(symbol: BoxedExpression | string, _domain: BoxedDomain | DomainExpression): AssumeResult;
|
|
323
|
+
assume(symbol: LatexString | SemiBoxedExpression, domainValue: BoxedDomain | DomainExpression | Expression | BoxedExpression): AssumeResult;
|
|
301
324
|
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
302
325
|
forget(symbol: undefined | string | string[]): void;
|
|
303
326
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_CALCULUS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_LOGIC: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_OTHERS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_SETS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
import { WarningSignal } from '../../../common/signals';
|
|
3
3
|
export declare type CommonEntry = {
|
|
4
4
|
name?: string;
|
|
@@ -7,10 +7,12 @@ export declare type CommonEntry = {
|
|
|
7
7
|
export declare type SymbolEntry = CommonEntry & {
|
|
8
8
|
kind: 'symbol';
|
|
9
9
|
precedence: number;
|
|
10
|
-
optionalLatexArg: number;
|
|
11
|
-
requiredLatexArg: number;
|
|
12
10
|
parse: SymbolParseHandler;
|
|
13
11
|
};
|
|
12
|
+
export declare type FunctionEntry = CommonEntry & {
|
|
13
|
+
kind: 'function';
|
|
14
|
+
parse: FunctionParseHandler;
|
|
15
|
+
};
|
|
14
16
|
export declare type MatchfixEntry = CommonEntry & {
|
|
15
17
|
kind: 'matchfix';
|
|
16
18
|
openDelimiter: Delimiter | LatexToken[];
|
|
@@ -35,14 +37,13 @@ export declare type PostfixEntry = CommonEntry & {
|
|
|
35
37
|
};
|
|
36
38
|
export declare type EnvironmentEntry = CommonEntry & {
|
|
37
39
|
kind: 'environment';
|
|
38
|
-
optionalLatexArg: number;
|
|
39
|
-
requiredLatexArg: number;
|
|
40
40
|
parse: EnvironmentParseHandler;
|
|
41
41
|
};
|
|
42
|
-
export declare type IndexedLatexDictionaryEntry = SymbolEntry | MatchfixEntry | InfixEntry | PrefixEntry | PostfixEntry | EnvironmentEntry;
|
|
42
|
+
export declare type IndexedLatexDictionaryEntry = FunctionEntry | SymbolEntry | MatchfixEntry | InfixEntry | PrefixEntry | PostfixEntry | EnvironmentEntry;
|
|
43
43
|
export declare type IndexedLatexDictionary = {
|
|
44
44
|
lookahead: number;
|
|
45
45
|
name: Map<string, IndexedLatexDictionaryEntry>;
|
|
46
|
+
function: Map<string, FunctionEntry[]>;
|
|
46
47
|
symbol: (Map<LatexString, SymbolEntry[]> | null)[];
|
|
47
48
|
prefix: (Map<LatexString, PrefixEntry[]> | null)[];
|
|
48
49
|
infix: (Map<LatexString, InfixEntry[]> | null)[];
|
|
@@ -52,5 +53,5 @@ export declare type IndexedLatexDictionary = {
|
|
|
52
53
|
};
|
|
53
54
|
export declare function indexLatexDictionary(dic: readonly LatexDictionaryEntry[], onError: (sig: WarningSignal) => void): IndexedLatexDictionary;
|
|
54
55
|
export declare const DEFAULT_LATEX_DICTIONARY: {
|
|
55
|
-
[category in
|
|
56
|
+
[category in LibraryCategory]?: LatexDictionary;
|
|
56
57
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.8.0 */
|
|
2
2
|
import { Serializer } from './serializer';
|
|
3
3
|
import { Expression } from '../../math-json/math-json-format';
|
|
4
4
|
import { WarningSignalHandler } from '../../common/signals';
|
|
@@ -6,7 +6,7 @@ import { IComputeEngine } from '../public';
|
|
|
6
6
|
export declare const DEFAULT_SERIALIZE_LATEX_OPTIONS: Required<SerializeLatexOptions>;
|
|
7
7
|
export declare class LatexSyntax {
|
|
8
8
|
onError: WarningSignalHandler;
|
|
9
|
-
options: NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
9
|
+
readonly options: NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
10
10
|
readonly computeEngine: IComputeEngine;
|
|
11
11
|
private dictionary;
|
|
12
12
|
private _serializer?;
|
|
@@ -16,7 +16,7 @@ export declare class LatexSyntax {
|
|
|
16
16
|
onError?: WarningSignalHandler;
|
|
17
17
|
});
|
|
18
18
|
updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>): void;
|
|
19
|
-
static getDictionary(category?:
|
|
19
|
+
static getDictionary(category?: LibraryCategory | 'all'): Readonly<LatexDictionary>;
|
|
20
20
|
parse(latex: LatexString): Expression;
|
|
21
21
|
serialize(expr: Expression): LatexString;
|
|
22
22
|
get serializer(): Serializer;
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import { ParseLatexOptions, LatexToken, NumberFormattingOptions, Delimiter, Terminator, Parser } from './public';
|
|
1
|
+
/* 0.8.0 */
|
|
3
2
|
import { IndexedLatexDictionary, InfixEntry, PostfixEntry, PrefixEntry, SymbolEntry } from './dictionary/definitions';
|
|
4
|
-
import { WarningSignalHandler } from '../../common/signals';
|
|
5
3
|
import { IComputeEngine } from '../public';
|
|
4
|
+
import { Expression } from '../../math-json/math-json-format';
|
|
6
5
|
export declare const DEFAULT_LATEX_NUMBER_OPTIONS: NumberFormattingOptions;
|
|
7
6
|
export declare const DEFAULT_PARSE_LATEX_OPTIONS: ParseLatexOptions;
|
|
8
7
|
export declare class _Parser implements Parser {
|
|
9
|
-
readonly
|
|
8
|
+
readonly computeEngine: IComputeEngine;
|
|
10
9
|
readonly options: NumberFormattingOptions & ParseLatexOptions;
|
|
11
|
-
readonly engine: IComputeEngine;
|
|
12
|
-
readonly _dictionary: IndexedLatexDictionary;
|
|
13
10
|
index: number;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
private readonly _tokens;
|
|
12
|
+
private _positiveInfinityTokens;
|
|
13
|
+
private _negativeInfinityTokens;
|
|
14
|
+
private _notANumberTokens;
|
|
15
|
+
private _decimalMarkerTokens;
|
|
16
|
+
private _groupSeparatorTokens;
|
|
17
|
+
private _exponentProductTokens;
|
|
18
|
+
private _beginExponentMarkerTokens;
|
|
19
|
+
private _endExponentMarkerTokens;
|
|
20
|
+
private _truncationMarkerTokens;
|
|
21
|
+
private _beginRepeatingDigitsTokens;
|
|
22
|
+
private _endRepeatingDigitsTokens;
|
|
23
|
+
private _imaginaryNumberTokens;
|
|
24
|
+
private readonly _dictionary;
|
|
25
|
+
private _boundaries;
|
|
26
|
+
private _lastPeek;
|
|
27
|
+
private _peekCounter;
|
|
28
|
+
constructor(tokens: LatexToken[], options: NumberFormattingOptions & ParseLatexOptions, dictionary: IndexedLatexDictionary, computeEngine: IComputeEngine);
|
|
18
29
|
updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions>): void;
|
|
19
|
-
clone(start: number, end: number): Parser;
|
|
20
30
|
get atEnd(): boolean;
|
|
21
31
|
get peek(): LatexToken;
|
|
32
|
+
next(): LatexToken;
|
|
22
33
|
/**
|
|
23
34
|
* Return true if
|
|
24
35
|
* - at end of the token stream
|
|
@@ -27,12 +38,18 @@ export declare class _Parser implements Parser {
|
|
|
27
38
|
* Note: the `minPrec` condition is not checked. It should be checked separately.
|
|
28
39
|
*/
|
|
29
40
|
atTerminator(t?: Terminator): boolean;
|
|
41
|
+
/** True if the current token matches any of the boundaries we are waiting for */
|
|
42
|
+
get atBoundary(): boolean;
|
|
43
|
+
addBoundary(boundary: LatexToken[]): void;
|
|
44
|
+
removeBoundary(): void;
|
|
45
|
+
matchBoundary(): boolean;
|
|
46
|
+
boundaryError(msg: string | [string, ...Expression[]]): Expression;
|
|
30
47
|
latex(start: number, end?: number): string;
|
|
31
48
|
latexAhead(n: number): string;
|
|
32
49
|
latexBefore(): string;
|
|
33
50
|
latexAfter(): string;
|
|
34
51
|
/**
|
|
35
|
-
* Return at most `lookahead` strings made from the tokens
|
|
52
|
+
* Return at most `this._dictionary.lookahead` strings made from the tokens
|
|
36
53
|
* ahead.
|
|
37
54
|
*
|
|
38
55
|
* The index in the returned array correspond to the number of tokens.
|
|
@@ -44,13 +61,16 @@ export declare class _Parser implements Parser {
|
|
|
44
61
|
*/
|
|
45
62
|
lookAhead(): string[];
|
|
46
63
|
/** Return all the definitions that potentially match the tokens ahead */
|
|
64
|
+
peekDefinitions(kind: 'function'): [FunctionEntry, number][] | null;
|
|
47
65
|
peekDefinitions(kind: 'symbol'): [SymbolEntry, number][] | null;
|
|
48
66
|
peekDefinitions(kind: 'postfix'): [PostfixEntry, number][] | null;
|
|
49
|
-
peekDefinitions(kind: 'postfix'): [PostfixEntry, number][] | null;
|
|
50
|
-
peekDefinitions(kind: 'operator'): [InfixEntry | PrefixEntry | PostfixEntry, number][] | null;
|
|
51
67
|
peekDefinitions(kind: 'infix'): [InfixEntry, number][] | null;
|
|
52
68
|
peekDefinitions(kind: 'prefix'): [PrefixEntry, number][] | null;
|
|
53
|
-
|
|
69
|
+
peekDefinitions(kind: 'operator'): [InfixEntry | PrefixEntry | PostfixEntry, number][] | null;
|
|
70
|
+
skipSpaceTokens(): void;
|
|
71
|
+
/** While parsing in math mode, skip applicable spaces.
|
|
72
|
+
* Do not use to skip spaces e.g. while parsing a string. See `skipSpaceTokens()` instead.
|
|
73
|
+
*/
|
|
54
74
|
skipSpace(): boolean;
|
|
55
75
|
matchChar(): string | null;
|
|
56
76
|
matchColor(_background?: boolean): string | null;
|
|
@@ -58,11 +78,16 @@ export declare class _Parser implements Parser {
|
|
|
58
78
|
match(token: LatexToken): boolean;
|
|
59
79
|
matchAll(tokens: LatexToken | LatexToken[]): boolean;
|
|
60
80
|
matchAny(tokens: LatexToken[]): LatexToken;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
matchDecimalDigits(
|
|
64
|
-
|
|
81
|
+
matchSequence(tokens: LatexToken[]): LatexToken[];
|
|
82
|
+
matchOptionalSign(): string;
|
|
83
|
+
matchDecimalDigits(options?: {
|
|
84
|
+
withGrouping?: boolean;
|
|
85
|
+
}): string;
|
|
86
|
+
matchSignedInteger(options?: {
|
|
87
|
+
withGrouping?: boolean;
|
|
88
|
+
}): string;
|
|
65
89
|
matchExponent(): string;
|
|
90
|
+
matchRepeatingDecimal(): string;
|
|
66
91
|
matchNumber(): string;
|
|
67
92
|
/**
|
|
68
93
|
* A Latex number can be a decimal, hex or octal number.
|
|
@@ -80,13 +105,11 @@ export declare class _Parser implements Parser {
|
|
|
80
105
|
matchInfixOperator(lhs: Expression, until?: Terminator): Expression | null;
|
|
81
106
|
/**
|
|
82
107
|
* - 'enclosure' : will look for an argument inside an enclosure (open/close fence)
|
|
83
|
-
* - 'implicit': either an expression inside a pair of `()`, or just a
|
|
84
|
-
* (i.e. we interpret `\cos
|
|
85
|
-
* - 'group': the arguments follow until an end of group, `<}>`. This is the
|
|
86
|
-
* case for example for `\displaystyle`
|
|
108
|
+
* - 'implicit': either an expression inside a pair of `()`, or just a product
|
|
109
|
+
* (i.e. we interpret `\cos 2x + 1` as `\cos(2x) + 1`)
|
|
87
110
|
*/
|
|
88
|
-
matchArguments(kind: undefined | '' | 'enclosure' | 'implicit'
|
|
89
|
-
/** If matches the normalized open delimiter,
|
|
111
|
+
matchArguments(kind: undefined | '' | 'enclosure' | 'implicit'): Expression[] | null;
|
|
112
|
+
/** If matches the normalized open delimiter, return the
|
|
90
113
|
* expected closing delimiter.
|
|
91
114
|
*
|
|
92
115
|
* For example, if `delimiter` is `(`, it would match `\left\lparen` and
|
|
@@ -97,55 +120,56 @@ export declare class _Parser implements Parser {
|
|
|
97
120
|
matchOpenDelimiter(openDelim: Delimiter, closeDelim: Delimiter): LatexToken[] | null;
|
|
98
121
|
matchMiddleDelimiter(delimiter: '|' | ':' | LatexToken): boolean;
|
|
99
122
|
/**
|
|
100
|
-
* An enclosure is an opening matchfix operator, an expression,
|
|
101
|
-
* followed multiple times by a separator and another expression,
|
|
123
|
+
* An enclosure is an opening matchfix operator, an optional expression,
|
|
124
|
+
* optionally followed multiple times by a separator and another expression,
|
|
102
125
|
* and finally a closing matching operator.
|
|
103
126
|
*/
|
|
104
127
|
matchEnclosure(): Expression | null;
|
|
105
128
|
/**
|
|
106
|
-
*
|
|
107
|
-
* - a
|
|
108
|
-
* - a
|
|
109
|
-
* - a multi-letter
|
|
110
|
-
* - a
|
|
111
|
-
* - a
|
|
112
|
-
*
|
|
129
|
+
* Match a single variable name. It can be:
|
|
130
|
+
* - a symbol
|
|
131
|
+
* - a simple multi-letter identifier: `\mathrm{speed}`
|
|
132
|
+
* - a complex multi-letter identifier: `\alpha_12` or `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}`
|
|
133
|
+
* - a command: `\alpha` @todo
|
|
134
|
+
* - a complex name such as `\alpha_12` or `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}` (see serializer.ts) @todo:
|
|
135
|
+
* @todo: matchSymbol should use matchIdentifier
|
|
113
136
|
*/
|
|
114
|
-
|
|
115
|
-
matchOptionalLatexArgument(): Expression | null;
|
|
137
|
+
matchIdentifier(): string | null;
|
|
116
138
|
/**
|
|
117
|
-
*
|
|
118
|
-
* -
|
|
119
|
-
* -
|
|
139
|
+
* A function is a function identifier followed by arguments
|
|
140
|
+
* - a function with explicit arguments `f(x)`
|
|
141
|
+
* - a function with explicit arguments `\mathrm{floor}(x)`
|
|
142
|
+
* - a function name: `\mathrm{floor}`
|
|
143
|
+
* - a function with implicit arguments: `\cos x` (via a custom parser)
|
|
120
144
|
*
|
|
121
|
-
* Return null if an argument was not found
|
|
122
|
-
* Return 'Nothing' if an empty argument `{}` was found
|
|
123
145
|
*/
|
|
124
|
-
|
|
146
|
+
matchFunction(): Expression | null;
|
|
125
147
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* - they act mostly like an infix operator, but they are commutative, i.e.
|
|
131
|
-
* `x_a^b` should be parsed identically to `x^b_a`.
|
|
132
|
-
*
|
|
133
|
-
* - furthermore, in LaTeX, consecutive `^` or `_` are treated as concatenated,
|
|
134
|
-
* that is `x^a^b` parses the same as `x^{ab}`.
|
|
135
|
-
*
|
|
148
|
+
* A symbol can be:
|
|
149
|
+
* - a single-letter variable: `x`
|
|
150
|
+
* - a single LaTeX command: `\pi`
|
|
136
151
|
*/
|
|
152
|
+
matchSymbol(): Expression | null;
|
|
153
|
+
matchOptionalLatexArgument(): Expression | null;
|
|
154
|
+
matchRequiredLatexArgument(): Expression | null;
|
|
137
155
|
matchSupsub(lhs: Expression | null): Expression | null;
|
|
138
156
|
matchPostfix(lhs: Expression | null): Expression | null;
|
|
139
|
-
|
|
140
|
-
|
|
157
|
+
/** Match a string used as a LaTeX identifier, for example an environment
|
|
158
|
+
* name.
|
|
159
|
+
* Not suitable for general purpose text, e.g. argument of a `\text{}
|
|
160
|
+
* command. See `matchChar()` instead.
|
|
161
|
+
*/
|
|
162
|
+
matchString(): string;
|
|
163
|
+
/** Match a string as an argument (in a `{}` pair) */
|
|
164
|
+
matchStringArgument(): string | null;
|
|
141
165
|
/**
|
|
142
|
-
* Match an expression in a tabular format,
|
|
143
|
-
*
|
|
166
|
+
* Match an expression in a tabular format, where rows are separated by `\\`
|
|
167
|
+
* and columns by `&`.
|
|
144
168
|
*
|
|
145
|
-
* Return rows of sparse columns
|
|
146
|
-
* and empty cells are also indicated with
|
|
169
|
+
* Return rows of sparse columns: empty rows are indicated with `Nothing`,
|
|
170
|
+
* and empty cells are also indicated with `Nothing`.
|
|
147
171
|
*/
|
|
148
|
-
matchTabular(
|
|
172
|
+
matchTabular(): null | Expression[][];
|
|
149
173
|
matchEnvironment(): Expression | null;
|
|
150
174
|
/**
|
|
151
175
|
* Apply an invisible operator between two expressions.
|
|
@@ -168,8 +192,8 @@ export declare class _Parser implements Parser {
|
|
|
168
192
|
* - x2 -> no
|
|
169
193
|
* => lhs is a number, rhs is a number, but not a literal
|
|
170
194
|
*/
|
|
171
|
-
applyInvisibleOperator(terminator: Terminator,
|
|
172
|
-
|
|
195
|
+
applyInvisibleOperator(terminator: Terminator, lhs: Expression | null): Expression | null;
|
|
196
|
+
matchUnexpectedLatexCommand(): Expression | null;
|
|
173
197
|
/**
|
|
174
198
|
* <primary> :=
|
|
175
199
|
* (<number> | <symbol> | <environment> | <matchfix-expr>) <subsup>* <postfix-operator>*
|
|
@@ -189,11 +213,12 @@ export declare class _Parser implements Parser {
|
|
|
189
213
|
* | <prefix-op> <primary>
|
|
190
214
|
* | <primary> <infix-op> <expression>
|
|
191
215
|
*
|
|
192
|
-
* Stop when an operator of precedence less than `minPrec` is encountered
|
|
216
|
+
* Stop when an operator of precedence less than `until.minPrec` is encountered
|
|
193
217
|
*/
|
|
194
218
|
matchExpression(until?: Partial<Terminator>): Expression | null;
|
|
195
219
|
/**
|
|
196
220
|
* Add LaTeX or other requested metadata to the expression
|
|
197
221
|
*/
|
|
198
222
|
decorate(expr: Expression | null, start: number): Expression | null;
|
|
223
|
+
error(code: string | [string, ...Expression[]], fromToken: number): Expression;
|
|
199
224
|
}
|