@cortex-js/compute-engine 0.4.4 → 0.5.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 +7057 -7037
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +3 -6142
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
- 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 +3 -1
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
- 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 +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +87 -43
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/core.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/dictionary.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
- package/dist/types/compute-engine/dictionary/trigonometry.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 -1
- 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 +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/public.d.ts +46 -20
- 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 +2 -4
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +2 -2
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +432 -138
- 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 +1 -1
- 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 +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +3 -4
- package/package.json +16 -16
|
@@ -1,33 +1,62 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
import { DictionaryCategory, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
3
|
-
import { Decimal } from 'decimal.js';
|
|
1
|
+
/* 0.5.0 */
|
|
4
2
|
import { Complex } from 'complex.js';
|
|
3
|
+
import { Expression, MathJsonNumber } from '../math-json/math-json-format';
|
|
5
4
|
import { SignalMessage, WarningSignal } from '../common/signals';
|
|
5
|
+
import type { DictionaryCategory, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
6
6
|
import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, Dictionary, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, Substitution, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata } from './public';
|
|
7
7
|
/**
|
|
8
|
-
* Create a `CustomEngine` instance to customize its behavior and the syntax
|
|
9
|
-
* and operation dictionaries it uses.
|
|
10
8
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
|
|
10
|
+
*
|
|
11
|
+
* Use the instance to create expressions with `ce.parse()` and `ce.box()`.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const ce = new ComputeEngine();
|
|
16
|
+
* let expr = ce.parse("e^{i\\pi}");
|
|
17
|
+
* console.log(expr.N().latex);
|
|
18
|
+
* // ➔ "-1"
|
|
19
|
+
*
|
|
20
|
+
* expr = ce.box(["Expand", ["Power", ["Add", "a", "b"], 2]]);
|
|
21
|
+
* console.log(expr.evaluate().latex);
|
|
22
|
+
* // ➔ "a^2 + 2ab + b^2"
|
|
23
|
+
*
|
|
24
|
+
* ```
|
|
13
25
|
*/
|
|
14
26
|
export declare class ComputeEngine implements IComputeEngine {
|
|
27
|
+
/** @internal */
|
|
15
28
|
readonly ZERO: BoxedExpression;
|
|
29
|
+
/** @internal */
|
|
16
30
|
readonly ONE: BoxedExpression;
|
|
31
|
+
/** @internal */
|
|
17
32
|
readonly TWO: BoxedExpression;
|
|
33
|
+
/** @internal */
|
|
18
34
|
readonly HALF: BoxedExpression;
|
|
35
|
+
/** @internal */
|
|
19
36
|
readonly NEGATIVE_ONE: BoxedExpression;
|
|
37
|
+
/** @internal */
|
|
20
38
|
readonly I: BoxedExpression;
|
|
39
|
+
/** @internal */
|
|
21
40
|
readonly NAN: BoxedExpression;
|
|
41
|
+
/** @internal */
|
|
22
42
|
readonly POSITIVE_INFINITY: BoxedExpression;
|
|
43
|
+
/** @internal */
|
|
23
44
|
readonly NEGATIVE_INFINITY: BoxedExpression;
|
|
45
|
+
/** @internal */
|
|
24
46
|
readonly COMPLEX_INFINITY: BoxedExpression;
|
|
47
|
+
/** @internal */
|
|
25
48
|
DECIMAL_NAN: Decimal;
|
|
49
|
+
/** @internal */
|
|
26
50
|
DECIMAL_ZERO: Decimal;
|
|
51
|
+
/** @internal */
|
|
27
52
|
DECIMAL_ONE: Decimal;
|
|
53
|
+
/** @internal */
|
|
28
54
|
DECIMAL_TWO: Decimal;
|
|
55
|
+
/** @internal */
|
|
29
56
|
DECIMAL_HALF: Decimal;
|
|
57
|
+
/** @internal */
|
|
30
58
|
DECIMAL_PI: Decimal;
|
|
59
|
+
/** @internal */
|
|
31
60
|
DECIMAL_NEGATIVE_ONE: Decimal;
|
|
32
61
|
private _precision;
|
|
33
62
|
private _numericMode;
|
|
@@ -49,14 +78,18 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
49
78
|
/**
|
|
50
79
|
* The current scope.
|
|
51
80
|
*
|
|
52
|
-
* A scope
|
|
81
|
+
* A **scope** stores the definition of symbols and assumptions.
|
|
53
82
|
*
|
|
54
83
|
* Scopes form a stack, and definitions in more recent
|
|
55
84
|
* scopes can obscure definitions from older scopes.
|
|
56
85
|
*
|
|
86
|
+
* The `ce.context` property represents the current scope.
|
|
87
|
+
*
|
|
57
88
|
*/
|
|
58
89
|
context: RuntimeScope;
|
|
59
|
-
/** Absolute time beyond which evaluation should not proceed
|
|
90
|
+
/** Absolute time beyond which evaluation should not proceed.
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
60
93
|
deadline?: number;
|
|
61
94
|
/**
|
|
62
95
|
* Return dictionaries suitable for the specified categories, or `"all"`
|
|
@@ -68,18 +101,29 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
68
101
|
*/
|
|
69
102
|
static getDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
|
|
70
103
|
/**
|
|
71
|
-
* Construct a new `ComputeEngine`
|
|
72
|
-
*
|
|
73
|
-
* If no `options.dictionaries` is provided a default set of dictionaries
|
|
74
|
-
* is used.
|
|
104
|
+
* Construct a new `ComputeEngine` instance.
|
|
75
105
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
106
|
+
* Dictionaries define functions and symbols (in `options.dictionaries`) and
|
|
107
|
+
* the LaTeX syntax (in `options.latexDictionaries`). If no dictionaries
|
|
108
|
+
* are provided, the default ones are used.
|
|
78
109
|
*
|
|
79
110
|
* The order of the dictionaries matter: the definitions from the later ones
|
|
80
111
|
* override the definitions from earlier ones. The first dictionary should
|
|
81
112
|
* be the `'core'` dictionary which include some basic definitions such
|
|
82
113
|
* as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
|
|
114
|
+
*
|
|
115
|
+
* @param options.numericMode The default mode is `auto`. Use `machine` to only
|
|
116
|
+
* use 64-bit float, use `decimal` to always use arbitrary precision floating
|
|
117
|
+
* point numbers or `complex` for complex numbers.
|
|
118
|
+
*
|
|
119
|
+
* @param options.numericPrecision Specific how many digits of precision for the
|
|
120
|
+
* numeric calculations. Default is 100.
|
|
121
|
+
*
|
|
122
|
+
* @param options.tolerance If the absolute value of the difference of two numbers
|
|
123
|
+
* is less than `toleranc`, they are considered equal. Used by `chop()` as well.
|
|
124
|
+
*
|
|
125
|
+
* @param options.defaultDomain If an unknown symbol is encountered, assume it should
|
|
126
|
+
* be a variable in this domain. **Default** `ExtendedRealNumber`
|
|
83
127
|
*/
|
|
84
128
|
constructor(options?: {
|
|
85
129
|
dictionaries?: Readonly<Dictionary>[];
|
|
@@ -95,15 +139,21 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
95
139
|
*
|
|
96
140
|
* This needs to happen for example when the numeric precision changes.
|
|
97
141
|
*
|
|
142
|
+
* @internal
|
|
98
143
|
*/
|
|
99
144
|
purge(): void;
|
|
145
|
+
/** @internal */
|
|
100
146
|
_register(expr: BoxedExpression): void;
|
|
147
|
+
/** @internal */
|
|
101
148
|
_unregister(expr: BoxedExpression): void;
|
|
102
149
|
get stats(): ComputeEngineStats;
|
|
150
|
+
/** @internal */
|
|
103
151
|
_decimal: Decimal.Constructor;
|
|
152
|
+
/** @internal */
|
|
104
153
|
decimal: (a: Decimal.Value) => Decimal;
|
|
154
|
+
/** @internal */
|
|
105
155
|
complex: (a: number | Complex, b?: number) => Complex;
|
|
106
|
-
/** The precision, or number of significant digits, for
|
|
156
|
+
/** The precision, or number of significant digits, for numeric calculations
|
|
107
157
|
* such as when calling `ce.N()`.
|
|
108
158
|
*
|
|
109
159
|
* To make calculations using more digits, at the cost of expended memory
|
|
@@ -114,24 +164,22 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
114
164
|
*/
|
|
115
165
|
get precision(): number;
|
|
116
166
|
set precision(p: number | 'machine');
|
|
117
|
-
/**
|
|
118
|
-
* Mode to use for numerical calculations:
|
|
119
|
-
*
|
|
120
|
-
* - `auto`: use machine number if the precision is 15 or less, Decimal
|
|
121
|
-
* otherwise. Complex numbers are allowed.
|
|
122
|
-
* - `number`: use the machine format (64-bit float, 52-bit mantissa, about
|
|
123
|
-
* 15 digits of precision).
|
|
124
|
-
* - `decimal`: arbitrary precision floating-point numbers, as provided by the
|
|
125
|
-
* "decimal.js" library
|
|
126
|
-
* - `complex`: machine and complex numbers: two 64-bit float, as provided by the
|
|
127
|
-
* "complex.js" library
|
|
128
|
-
*
|
|
129
|
-
*/
|
|
130
167
|
get numericMode(): NumericMode;
|
|
131
168
|
set numericMode(f: NumericMode);
|
|
169
|
+
/** @experimental */
|
|
132
170
|
get timeLimit(): number;
|
|
171
|
+
/** @experimental */
|
|
133
172
|
get iterationLimit(): number;
|
|
173
|
+
/** @experimental */
|
|
134
174
|
get recursionLimit(): number;
|
|
175
|
+
/**
|
|
176
|
+
* If an unknown symbol is encountered, assume it should
|
|
177
|
+
* be a variable in this domain.
|
|
178
|
+
*
|
|
179
|
+
* If set to `null`, unknown symbols will trigger an error.
|
|
180
|
+
*
|
|
181
|
+
* **Default:** `"ExtendedRealNumber"`
|
|
182
|
+
*/
|
|
135
183
|
get defaultDomain(): BoxedExpression | null;
|
|
136
184
|
set defaultDomain(domain: BoxedExpression | string | null);
|
|
137
185
|
/**
|
|
@@ -141,6 +189,10 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
141
189
|
*/
|
|
142
190
|
get tolerance(): number;
|
|
143
191
|
set tolerance(val: number);
|
|
192
|
+
/** Replace a number that is close to 0 with the exact integer 0.
|
|
193
|
+
*
|
|
194
|
+
* How close to 0 the number has to be to be considered 0 is determined by {@link tolerance}.
|
|
195
|
+
*/
|
|
144
196
|
chop(n: number): number;
|
|
145
197
|
chop(n: Decimal): Decimal | 0;
|
|
146
198
|
chop(n: Complex): Complex | 0;
|
|
@@ -185,8 +237,11 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
185
237
|
* This can occur if:
|
|
186
238
|
* - an error has been signaled
|
|
187
239
|
* - the time limit or memory limit has been exceeded
|
|
240
|
+
*
|
|
241
|
+
* @internal
|
|
188
242
|
*/
|
|
189
243
|
shouldContinueExecution(): boolean;
|
|
244
|
+
/** @internal */
|
|
190
245
|
checkContinueExecution(): void;
|
|
191
246
|
assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
192
247
|
/**
|
|
@@ -201,9 +256,11 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
201
256
|
*/
|
|
202
257
|
signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
|
|
203
258
|
signal(sig: WarningSignal): void;
|
|
259
|
+
/** @internal */
|
|
204
260
|
cache<T>(cacheName: string, build: () => T, purge: (T: any) => T | undefined): T;
|
|
205
261
|
box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
|
|
206
262
|
fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
263
|
+
/** @internal */
|
|
207
264
|
_fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
208
265
|
error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): BoxedExpression;
|
|
209
266
|
add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
|
|
@@ -220,8 +277,8 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
220
277
|
number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
|
|
221
278
|
rules(rules: Rule[]): BoxedRuleSet;
|
|
222
279
|
pattern(expr: LatexString | SemiBoxedExpression): Pattern;
|
|
223
|
-
parse(s: null): null;
|
|
224
280
|
parse(s: LatexString | string): BoxedExpression;
|
|
281
|
+
parse(s: null): null;
|
|
225
282
|
parse(s: LatexString | string | null): null | BoxedExpression;
|
|
226
283
|
serialize(x: Expression | BoxedExpression): string;
|
|
227
284
|
get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
@@ -238,19 +295,6 @@ export declare class ComputeEngine implements IComputeEngine {
|
|
|
238
295
|
* ```
|
|
239
296
|
*/
|
|
240
297
|
ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
|
|
241
|
-
/**
|
|
242
|
-
* Add an assumption.
|
|
243
|
-
*
|
|
244
|
-
* Return `contradiction` if the new assumption is incompatible with previous
|
|
245
|
-
* ones.
|
|
246
|
-
*
|
|
247
|
-
* Return `tautology` if the new assumption is redundant with previous ones.
|
|
248
|
-
*
|
|
249
|
-
* Return `ok` if the assumption was successfully added to the assumption set.
|
|
250
|
-
*
|
|
251
|
-
* Note that the assumption is put into canonical form before being added.
|
|
252
|
-
*
|
|
253
|
-
*/
|
|
254
298
|
assume(symbol: LatexString | SemiBoxedExpression, domain: string | BoxedExpression): AssumeResult;
|
|
255
299
|
assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
|
|
256
300
|
forget(symbol: undefined | string | string[]): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const ARITHMETIC_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const COLLECTIONS_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const CORE_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const LOGIC_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const POLYNOMIALS_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const RELOP_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const SETS_DICTIONARY: Dictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const TRIGONOMETRY_DICTIONARY: Dictionary[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_CALCULUS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_LOGIC: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_OTHERS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_SETS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
import { ParseLatexOptions, LatexToken, NumberFormattingOptions, Delimiter, Terminator, Parser } from './public';
|
|
3
3
|
import { IndexedLatexDictionary, InfixEntry, PostfixEntry, PrefixEntry, SymbolEntry } from './dictionary/definitions';
|
|
4
4
|
import { WarningSignalHandler } from '../../common/signals';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
import { Expression } from '../../math-json/math-json-format';
|
|
3
3
|
import type { IComputeEngine } from '../public';
|
|
4
4
|
/**
|
|
@@ -13,7 +13,11 @@ export declare type LatexToken = string | '<{>' | '<}>' | '<space>' | '<$>' | '<
|
|
|
13
13
|
* `\frac{\pi}{2}`
|
|
14
14
|
*/
|
|
15
15
|
export declare type LatexString = string;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Open and close delimiters that can be used with {@link MatchfixEntry}
|
|
18
|
+
* record to define new LaTeX dictionary entries.
|
|
19
|
+
*/
|
|
20
|
+
export declare type Delimiter = ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor';
|
|
17
21
|
export declare type DictionaryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'combinatorics' | 'core' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'symbols' | 'trigonometry' | 'units';
|
|
18
22
|
/**
|
|
19
23
|
* This indicates a condition under which parsing should stop:
|
|
@@ -108,11 +112,11 @@ export declare type InfixEntry = BaseEntry & {
|
|
|
108
112
|
/**
|
|
109
113
|
* Infix position, with an operand before and an operand after: `a ⊛ b`.
|
|
110
114
|
*
|
|
111
|
-
*
|
|
115
|
+
* Example: `+`, `\times`.
|
|
112
116
|
*/
|
|
113
117
|
kind: 'infix';
|
|
114
118
|
/**
|
|
115
|
-
* - **`both`**: a + b + c
|
|
119
|
+
* - **`both`**: a + b + c +(a, b, c)
|
|
116
120
|
* - **`left`**: a / b / c -> /(/(a, b), c)
|
|
117
121
|
* - **`right`**: a = b = c -> =(a, =(b, c))
|
|
118
122
|
* - **`non`**: a < b < c -> syntax error
|
|
@@ -131,7 +135,7 @@ export declare type PostfixEntry = BaseEntry & {
|
|
|
131
135
|
/**
|
|
132
136
|
* Postfix position, with an operand before: `a ⊛`
|
|
133
137
|
*
|
|
134
|
-
*
|
|
138
|
+
* Example: `!`.
|
|
135
139
|
*/
|
|
136
140
|
kind: 'postfix';
|
|
137
141
|
precedence?: number;
|
|
@@ -141,22 +145,23 @@ export declare type PrefixEntry = BaseEntry & {
|
|
|
141
145
|
/**
|
|
142
146
|
* Prefix position, with an operand after: `⊛ a`
|
|
143
147
|
*
|
|
144
|
-
*
|
|
148
|
+
* Example: `-`, `\not`.
|
|
145
149
|
*/
|
|
146
150
|
kind: 'prefix';
|
|
147
151
|
precedence: number;
|
|
148
152
|
parse: PrefixParseHandler;
|
|
149
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* A LaTeX dictionary entry for an environment, that is a LaTeX
|
|
156
|
+
* construct using `\begin{...}...\end{...}`.
|
|
157
|
+
*/
|
|
150
158
|
export declare type EnvironmentEntry = BaseEntry & {
|
|
151
|
-
/**
|
|
152
|
-
* The name of an environment, as used in `\begin{matrix}` where
|
|
153
|
-
* `"matrix"` is the name of the environment.
|
|
154
|
-
*/
|
|
155
159
|
kind: 'environment';
|
|
156
160
|
parse: EnvironmentParseHandler;
|
|
157
161
|
};
|
|
158
162
|
export declare type SymbolEntry = BaseEntry & {
|
|
159
163
|
kind: 'symbol';
|
|
164
|
+
/** Used for appropriate wrapping (i.e. when to surround it with parens) */
|
|
160
165
|
precedence?: number;
|
|
161
166
|
/**
|
|
162
167
|
* Indicate if this symbol can be followed by arguments.
|
|
@@ -207,6 +212,9 @@ export declare type SymbolEntry = BaseEntry & {
|
|
|
207
212
|
requiredLatexArg?: number;
|
|
208
213
|
parse: Expression | SymbolParseHandler;
|
|
209
214
|
};
|
|
215
|
+
/**
|
|
216
|
+
* A simple LaTeX dictionary entry, for example for a command like `\pi`.
|
|
217
|
+
*/
|
|
210
218
|
export declare type DefaultEntry = BaseEntry & {
|
|
211
219
|
precedence?: number;
|
|
212
220
|
arguments?: 'group' | 'implicit' | '';
|
|
@@ -215,11 +223,17 @@ export declare type DefaultEntry = BaseEntry & {
|
|
|
215
223
|
parse?: Expression | SymbolParseHandler;
|
|
216
224
|
};
|
|
217
225
|
export declare type LatexDictionaryEntry = DefaultEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | SymbolEntry | EnvironmentEntry;
|
|
226
|
+
/** @internal */
|
|
218
227
|
export declare function isSymbolEntry(entry: LatexDictionaryEntry): entry is SymbolEntry;
|
|
228
|
+
/** @internal */
|
|
219
229
|
export declare function isMatchfixEntry(entry: LatexDictionaryEntry): entry is MatchfixEntry;
|
|
230
|
+
/** @internal */
|
|
220
231
|
export declare function isInfixEntry(entry: LatexDictionaryEntry): entry is InfixEntry;
|
|
232
|
+
/** @internal */
|
|
221
233
|
export declare function isPrefixEntry(entry: LatexDictionaryEntry): entry is PrefixEntry;
|
|
234
|
+
/** @internal */
|
|
222
235
|
export declare function isPostfixEntry(entry: LatexDictionaryEntry): entry is PostfixEntry;
|
|
236
|
+
/** @internal */
|
|
223
237
|
export declare function isEnvironmentEntry(entry: LatexDictionaryEntry): entry is EnvironmentEntry;
|
|
224
238
|
export declare type LatexDictionary = LatexDictionaryEntry[];
|
|
225
239
|
export declare type ParseLatexOptions = {
|
|
@@ -284,7 +298,13 @@ export declare type ParseLatexOptions = {
|
|
|
284
298
|
parseUnknownToken: (token: LatexToken, parser: Parser) => 'symbol' | 'function' | 'skip' | 'error';
|
|
285
299
|
/**
|
|
286
300
|
* If true, the expression will be decorated with the LaTeX
|
|
287
|
-
* fragments corresponding to each elements of the expression
|
|
301
|
+
* fragments corresponding to each elements of the expression.
|
|
302
|
+
*
|
|
303
|
+
* The top-level expression, that is the one returned by `parse()`, will
|
|
304
|
+
* include the verbatim LaTeX input that was parsed. The sub-expressions
|
|
305
|
+
* may contain a slightly different LaTeX, for example with consecutive spaces
|
|
306
|
+
* replaced by one, with comments removed and with some low-level LaTeX
|
|
307
|
+
* commands replaced, for example `\egroup` and `\bgroup`.
|
|
288
308
|
*/
|
|
289
309
|
preserveLatex: boolean;
|
|
290
310
|
};
|
|
@@ -447,7 +467,7 @@ export interface Parser {
|
|
|
447
467
|
readonly atEnd: boolean;
|
|
448
468
|
/** Return the next token, without advancing the index */
|
|
449
469
|
readonly peek: LatexToken;
|
|
450
|
-
/** Return true if the terminator
|
|
470
|
+
/** Return true if the terminator condition is met */
|
|
451
471
|
atTerminator(t: Terminator): boolean;
|
|
452
472
|
/** Return an array of string corresponding to tokens ahead.
|
|
453
473
|
* The index is unchanged.
|
|
@@ -516,16 +536,22 @@ export interface Parser {
|
|
|
516
536
|
matchMiddleDelimiter(delimiter: '|' | ':' | LatexToken): boolean;
|
|
517
537
|
matchSupsub(lhs: Expression | null): Expression | null;
|
|
518
538
|
/**
|
|
519
|
-
* <primary> :=
|
|
520
|
-
* (<number> | <symbol> | <latex-command> | <function-call> | <matchfix-expr>)
|
|
521
|
-
* (<subsup> | <postfix-operator>)*
|
|
522
|
-
*
|
|
523
|
-
* <matchfix-expr> :=
|
|
524
|
-
* <matchfix-op-open> <expression> <matchfix-op-close>
|
|
525
539
|
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
540
|
+
* ```
|
|
541
|
+
* <primary> :=
|
|
542
|
+
* (<number> | <symbol> | <latex-command> | <function-call> | <matchfix-expr>)
|
|
543
|
+
* (<subsup> | <postfix-operator>)*
|
|
544
|
+
* ```
|
|
528
545
|
*
|
|
546
|
+
* ```
|
|
547
|
+
* <matchfix-expr> :=
|
|
548
|
+
* <matchfix-op-open> <expression> <matchfix-op-close>
|
|
549
|
+
*```
|
|
550
|
+
*
|
|
551
|
+
*```
|
|
552
|
+
* <function-call> ::=
|
|
553
|
+
* | <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
|
|
554
|
+
*```
|
|
529
555
|
* If not a primary, return `null` and do not advance the index.
|
|
530
556
|
*/
|
|
531
557
|
matchPrimary(): Expression | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
import { NumberFormattingOptions } from './public';
|
|
3
3
|
export declare function serializeNumber(expr: Expression | null, options: NumberFormattingOptions): string;
|
|
4
4
|
export declare function serializeEngineeringNotationNumber(value: number, options: NumberFormattingOptions): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
export declare function getApplyFunctionStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
|
|
3
3
|
export declare function getGroupStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
|
|
4
4
|
export declare function getRootStyle(_expr: Expression | null, level: number): 'radical' | 'quotient' | 'solidus';
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.5.0 */
|
|
2
2
|
import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
|
|
3
3
|
import { IndexedLatexDictionary, SymbolEntry } from './dictionary/definitions';
|
|
4
4
|
import { WarningSignalHandler } from '../../common/signals';
|
|
5
|
-
import { IComputeEngine } from '../public';
|
|
6
5
|
export declare class Serializer {
|
|
7
6
|
readonly onError: WarningSignalHandler;
|
|
8
7
|
options: NumberFormattingOptions & SerializeLatexOptions;
|
|
9
|
-
readonly computeEngine?: IComputeEngine;
|
|
10
8
|
readonly dictionary: IndexedLatexDictionary;
|
|
11
9
|
level: number;
|
|
12
|
-
constructor(options: NumberFormattingOptions & SerializeLatexOptions, dictionary: IndexedLatexDictionary,
|
|
10
|
+
constructor(options: NumberFormattingOptions & SerializeLatexOptions, dictionary: IndexedLatexDictionary, onError: WarningSignalHandler);
|
|
13
11
|
updateOptions(opt: Partial<NumberFormattingOptions> & Partial<SerializeLatexOptions>): void;
|
|
14
12
|
/**
|
|
15
13
|
* Serialize the expression, and if the expression is an operator
|