@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.
Files changed (91) hide show
  1. package/dist/compute-engine.esm.js +14942 -11619
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +62 -43
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -1
  9. package/dist/types/compute-engine/assume.d.ts +2 -2
  10. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +72 -57
  11. package/dist/types/compute-engine/boxed-expression/box.d.ts +2 -14
  12. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +4 -4
  13. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +36 -19
  14. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +46 -38
  16. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +6 -4
  17. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +5 -5
  18. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  19. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +13 -10
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +28 -14
  21. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/utils.d.ts +25 -8
  25. package/dist/types/compute-engine/compute-engine.d.ts +72 -49
  26. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  27. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  28. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  29. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -3
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +8 -7
  39. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +3 -3
  40. package/dist/types/compute-engine/latex-syntax/parse.d.ts +87 -62
  41. package/dist/types/compute-engine/latex-syntax/public.d.ts +65 -46
  42. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +6 -4
  45. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  46. package/dist/types/compute-engine/library/arithmetic-add.d.ts +11 -0
  47. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +15 -0
  48. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +19 -0
  49. package/dist/types/compute-engine/{dictionary → library}/arithmetic-power.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -0
  51. package/dist/types/compute-engine/library/calculus.d.ts +2 -0
  52. package/dist/types/compute-engine/library/collections.d.ts +2 -0
  53. package/dist/types/compute-engine/library/core.d.ts +2 -0
  54. package/dist/types/compute-engine/library/domains.d.ts +15 -0
  55. package/dist/types/compute-engine/library/library.d.ts +17 -0
  56. package/dist/types/compute-engine/library/logic.d.ts +2 -0
  57. package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
  58. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
  59. package/dist/types/compute-engine/library/sets.d.ts +2 -0
  60. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
  61. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  62. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +5 -1
  63. package/dist/types/compute-engine/numerics/numeric.d.ts +4 -2
  64. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  65. package/dist/types/compute-engine/public.d.ts +717 -504
  66. package/dist/types/compute-engine/rules.d.ts +1 -1
  67. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  68. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  69. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  70. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  71. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  72. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/sum.d.ts +2 -2
  74. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  75. package/dist/types/compute-engine.d.ts +2 -2
  76. package/dist/types/math-json/math-json-format.d.ts +27 -23
  77. package/dist/types/math-json/utils.d.ts +22 -16
  78. package/dist/types/math-json.d.ts +3 -3
  79. package/package.json +20 -20
  80. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +0 -11
  81. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +0 -9
  82. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +0 -17
  83. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +0 -2
  84. package/dist/types/compute-engine/dictionary/collections.d.ts +0 -2
  85. package/dist/types/compute-engine/dictionary/core.d.ts +0 -2
  86. package/dist/types/compute-engine/dictionary/dictionary.d.ts +0 -26
  87. package/dist/types/compute-engine/dictionary/logic.d.ts +0 -2
  88. package/dist/types/compute-engine/dictionary/polynomials.d.ts +0 -2
  89. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +0 -2
  90. package/dist/types/compute-engine/dictionary/sets.d.ts +0 -2
  91. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +0 -2
@@ -1,9 +1,9 @@
1
- /* 0.6.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 { DictionaryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
6
- import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, Dictionary, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, Substitution, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, Domain, DomainExpression } from './public';
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 ZERO: BoxedExpression;
28
+ readonly _ZERO: BoxedExpression;
29
29
  /** @internal */
30
- readonly ONE: BoxedExpression;
30
+ readonly _ONE: BoxedExpression;
31
31
  /** @internal */
32
- readonly TWO: BoxedExpression;
32
+ readonly _TWO: BoxedExpression;
33
33
  /** @internal */
34
- readonly HALF: BoxedExpression;
34
+ readonly _HALF: BoxedExpression;
35
35
  /** @internal */
36
- readonly NEGATIVE_ONE: BoxedExpression;
36
+ readonly _NEGATIVE_ONE: BoxedExpression;
37
37
  /** @internal */
38
- readonly I: BoxedExpression;
38
+ readonly _I: BoxedExpression;
39
39
  /** @internal */
40
- readonly NAN: BoxedExpression;
40
+ readonly _NAN: BoxedExpression;
41
41
  /** @internal */
42
- readonly POSITIVE_INFINITY: BoxedExpression;
42
+ readonly _POSITIVE_INFINITY: BoxedExpression;
43
43
  /** @internal */
44
- readonly NEGATIVE_INFINITY: BoxedExpression;
44
+ readonly _NEGATIVE_INFINITY: BoxedExpression;
45
45
  /** @internal */
46
- readonly COMPLEX_INFINITY: BoxedExpression;
46
+ readonly _COMPLEX_INFINITY: BoxedExpression;
47
47
  /** @internal */
48
- DECIMAL_NAN: Decimal;
48
+ _DECIMAL_NAN: Decimal;
49
49
  /** @internal */
50
- DECIMAL_ZERO: Decimal;
50
+ _DECIMAL_ZERO: Decimal;
51
51
  /** @internal */
52
- DECIMAL_ONE: Decimal;
52
+ _DECIMAL_ONE: Decimal;
53
53
  /** @internal */
54
- DECIMAL_TWO: Decimal;
54
+ _DECIMAL_TWO: Decimal;
55
55
  /** @internal */
56
- DECIMAL_HALF: Decimal;
56
+ _DECIMAL_HALF: Decimal;
57
57
  /** @internal */
58
- DECIMAL_PI: Decimal;
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 dictionaries suitable for the specified categories, or `"all"`
110
+ * Return symbol tables suitable for the specified categories, or `"all"`
96
111
  * for all categories (`"arithmetic"`, `"algebra"`, etc...).
97
112
  *
98
- * A symbol dictionary defines how the symbols and function names in a MathJSON
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 getDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
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 `toleranc`, they are considered equal. Used by `chop()` as well.
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
- dictionaries?: Readonly<Dictionary>[];
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
- purge(): void;
159
+ reset(): void;
145
160
  /** @internal */
146
- _register(expr: BoxedExpression): void;
161
+ _register(_expr: BoxedExpression): void;
147
162
  /** @internal */
148
- _unregister(expr: BoxedExpression): void;
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(): Domain | null;
184
- set defaultDomain(domain: Domain | string | null);
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?: DictionaryCategory | 'all'): Readonly<LatexDictionary>;
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
- getSymbolDefinition(symbol: string, wikidata?: string): undefined | BoxedSymbolDefinition;
223
+ lookupSymbol(symbol: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
208
224
  /**
209
- * Return the definition for a function matching this head and
210
- * these arguments.
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
- * Start looking in the current scope, than up the scope chain.
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
- getFunctionDefinition(head: string, args?: BoxedExpression[]): undefined | BoxedFunctionDefinition;
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
- dictionary?: Readonly<Dictionary> | Readonly<Dictionary>[];
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(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): BoxedExpression;
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(sym: string, metadata?: Metadata): BoxedExpression;
278
- domain(domain: BoxedExpression | DomainExpression | Domain, metadata?: Metadata): Domain;
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(s: LatexString | string): BoxedExpression;
304
+ parse(latex: LatexString | string): BoxedExpression;
283
305
  parse(s: null): null;
284
- parse(s: LatexString | string | null): null | BoxedExpression;
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
- assume(symbol: LatexString | SemiBoxedExpression, domain: string | BoxedExpression): AssumeResult;
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,3 +1,3 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,4 +1,4 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedExpression } from './public';
4
4
  /** Quickly determine the numeric domain of a number or constant
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,4 +1,2 @@
1
- /* 0.6.0 */
2
- import { LatexDictionary, Serializer } from '../public';
3
- export declare function serializeLatex(serializer: Serializer, expr: Expression | null): string;
1
+ /* 0.8.0 */
4
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.8.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.6.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 DictionaryCategory]?: LatexDictionary;
56
+ [category in LibraryCategory]?: LatexDictionary;
56
57
  };
@@ -1,4 +1,4 @@
1
- /* 0.6.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?: DictionaryCategory | 'all'): Readonly<LatexDictionary>;
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.6.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 onError: WarningSignalHandler;
8
+ readonly computeEngine: IComputeEngine;
10
9
  readonly options: NumberFormattingOptions & ParseLatexOptions;
11
- readonly engine: IComputeEngine;
12
- readonly _dictionary: IndexedLatexDictionary;
13
10
  index: number;
14
- _lastPeek: string;
15
- _peekCounter: number;
16
- readonly _tokens: LatexToken[];
17
- constructor(tokens: LatexToken[], options: NumberFormattingOptions & ParseLatexOptions, dictionary: IndexedLatexDictionary, computeEngine: IComputeEngine, onError: WarningSignalHandler);
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
- next(): LatexToken;
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
- matchWhile(tokens: LatexToken[]): LatexToken[];
62
- matchSign(): string;
63
- matchDecimalDigits(): string;
64
- matchSignedInteger(): string;
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 primary
84
- * (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
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' | 'group'): Expression[] | null;
89
- /** If matches the normalized open delimiter, returns the
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, optionally
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
- * A symbol can be:
107
- * - a constant: `\pi`
108
- * - a single-letter variable: `x`
109
- * - a multi-letter variable: `\mathit{speed}` or `\mathrm{speed}`
110
- * - a function with explicit arguments `f(x)`
111
- * - a function with implicit arguments: `\cos x`
112
- * - a command: `\frac{2}{3}`
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
- matchSymbol(): Expression | null;
115
- matchOptionalLatexArgument(): Expression | null;
137
+ matchIdentifier(): string | null;
116
138
  /**
117
- * Match a required LaTeX argument:
118
- * - either enclosed in `{}`
119
- * - or a single token.
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
- matchRequiredLatexArgument(): Expression | null;
146
+ matchFunction(): Expression | null;
125
147
  /**
126
- * Match a sequence superfix/subfix operator, e.g. `^{*}`
127
- *
128
- * Superfix and subfix need special handling:
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
- matchString(until: Partial<Terminator>): string;
140
- matchEnvironmentName(command: '\\begin' | '\\end', envName: string): boolean;
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
- * where row are separated by `\\` and columns by `&`
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 as a list: empty rows are indicated with NOTHING,
146
- * and empty cells are also indicated with NOTHING.
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(endName: string): null | Expression;
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, rawLhs: Expression | null): Expression | null;
172
- matchUnknownLatexCommand(): Expression | null;
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
  }