@cortex-js/compute-engine 0.14.0 → 0.16.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 (99) hide show
  1. package/dist/compute-engine.esm.js +3939 -1797
  2. package/dist/compute-engine.js +3939 -1797
  3. package/dist/compute-engine.min.esm.js +3952 -1812
  4. package/dist/compute-engine.min.js +3952 -1812
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +15 -0
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +1 -1
  12. package/dist/types/common/utils.d.ts +1 -1
  13. package/dist/types/compute-engine/assume.d.ts +2 -2
  14. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +9 -12
  15. package/dist/types/compute-engine/boxed-expression/box.d.ts +8 -3
  16. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +3 -3
  17. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +6 -6
  18. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +27 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +7 -19
  20. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
  21. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +3 -3
  22. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +11 -10
  24. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +17 -11
  25. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/utils.d.ts +30 -9
  29. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  30. package/dist/types/compute-engine/compile.d.ts +1 -1
  31. package/dist/types/compute-engine/compute-engine.d.ts +58 -24
  32. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  33. package/dist/types/compute-engine/domain-utils.d.ts +4 -19
  34. package/dist/types/compute-engine/function-utils.d.ts +84 -0
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +2 -0
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +5 -3
  49. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/parse.d.ts +37 -1
  51. package/dist/types/compute-engine/latex-syntax/public.d.ts +24 -6
  52. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -2
  55. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  56. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  57. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  58. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  59. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  60. package/dist/types/compute-engine/library/arithmetic.d.ts +3 -2
  61. package/dist/types/compute-engine/library/calculus.d.ts +2 -2
  62. package/dist/types/compute-engine/library/collections.d.ts +2 -2
  63. package/dist/types/compute-engine/library/complex.d.ts +2 -0
  64. package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
  65. package/dist/types/compute-engine/library/core.d.ts +2 -2
  66. package/dist/types/compute-engine/library/domains.d.ts +7 -8
  67. package/dist/types/compute-engine/library/library.d.ts +5 -5
  68. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
  69. package/dist/types/compute-engine/library/logic.d.ts +2 -2
  70. package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
  71. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  72. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
  73. package/dist/types/compute-engine/library/sets.d.ts +2 -2
  74. package/dist/types/compute-engine/library/statistics.d.ts +2 -0
  75. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
  76. package/dist/types/compute-engine/library/utils.d.ts +3 -3
  77. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  78. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +3 -2
  79. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +2 -2
  80. package/dist/types/compute-engine/numerics/numeric.d.ts +61 -2
  81. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  82. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  83. package/dist/types/compute-engine/public.d.ts +205 -91
  84. package/dist/types/compute-engine/rules.d.ts +1 -1
  85. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  86. package/dist/types/compute-engine/solve.d.ts +1 -1
  87. package/dist/types/compute-engine/symbolic/derivative.d.ts +6 -0
  88. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  89. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  90. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  91. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  92. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  93. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  94. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  95. package/dist/types/compute-engine.d.ts +2 -2
  96. package/dist/types/math-json/math-json-format.d.ts +1 -1
  97. package/dist/types/math-json/utils.d.ts +2 -1
  98. package/dist/types/math-json.d.ts +2 -2
  99. package/package.json +23 -21
@@ -1,8 +1,8 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression, MathJsonNumber } from '../math-json/math-json-format';
4
- import type { LibraryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
5
- import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdTable, ExpressionMapInterface, NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution, Substitution } from './public';
4
+ import type { LibraryCategory, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
5
+ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, IdentifierDefinitions, ExpressionMapInterface, NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution, AssignValue } from './public';
6
6
  /**
7
7
  *
8
8
  * To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
@@ -93,8 +93,6 @@ export declare class ComputeEngine implements IComputeEngine {
93
93
  private _commonNumbers;
94
94
  /** @internal */
95
95
  private _commonDomains;
96
- /** @internal */
97
- private _latexDictionary?;
98
96
  /**
99
97
  * The current scope.
100
98
  *
@@ -121,19 +119,20 @@ export declare class ComputeEngine implements IComputeEngine {
121
119
  * manipulate them.
122
120
  *
123
121
  */
124
- static getStandardLibrary(categories?: LibraryCategory[] | LibraryCategory | 'all'): Readonly<IdTable>[];
122
+ static getStandardLibrary(categories?: LibraryCategory[] | LibraryCategory | 'all'): readonly IdentifierDefinitions[];
125
123
  /**
126
124
  * Construct a new `ComputeEngine` instance.
127
125
  *
128
126
  * Identifier tables define functions and symbols (in `options.ids`).
129
- * If no table is provided the standard library is used (`ComputeEngine.getStandardLibrary()`)
127
+ * If no table is provided the MathJSON Standard Library is used (`ComputeEngine.getStandardLibrary()`)
130
128
  *
131
129
  * The LaTeX syntax dictionary is defined in `options.latexDictionary`.
132
130
  *
133
131
  * The order of the dictionaries matter: the definitions from the later ones
134
132
  * override the definitions from earlier ones. The first dictionary should
135
133
  * be the `'core'` dictionary which include some basic definitions such
136
- * as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
134
+ * as domains (`Booleans`, `Numbers`, etc...) that are used by later
135
+ * dictionaries.
137
136
  *
138
137
  * @param options.numericMode The default mode is `"auto"`. Use `"machine"`
139
138
  * to perform numeric calculations using 64-bit floats. Use `"bignum"` to
@@ -148,13 +147,12 @@ export declare class ComputeEngine implements IComputeEngine {
148
147
  * `chop()` as well.
149
148
  *
150
149
  * @param options.defaultDomain If an unknown symbol is encountered, assume
151
- * this is its domain. **Default** `ExtendedRealNumber`
150
+ * this is its domain. **Default** `ExtendedRealNumbers`
152
151
  */
153
152
  constructor(options?: {
154
153
  numericMode?: NumericMode;
155
154
  numericPrecision?: number;
156
- ids?: Readonly<IdTable>[];
157
- latexDictionary?: readonly LatexDictionaryEntry[];
155
+ ids?: readonly IdentifierDefinitions[];
158
156
  tolerance?: number;
159
157
  defaultDomain?: string;
160
158
  });
@@ -202,7 +200,7 @@ export declare class ComputeEngine implements IComputeEngine {
202
200
  *
203
201
  * If set to `null`, unknown symbols will trigger an error.
204
202
  *
205
- * **Default:** `"ExtendedRealNumber"`
203
+ * **Default:** `"ExtendedRealNumbers"`
206
204
  */
207
205
  get defaultDomain(): BoxedDomain | null;
208
206
  set defaultDomain(domain: BoxedDomain | string | null);
@@ -225,7 +223,7 @@ export declare class ComputeEngine implements IComputeEngine {
225
223
  isBignum(a: unknown): a is Decimal;
226
224
  isComplex(a: unknown): a is Complex;
227
225
  private get latexSyntax();
228
- static getLatexDictionary(domain?: LibraryCategory | 'all'): Readonly<LatexDictionary>;
226
+ static getLatexDictionary(domain?: LibraryCategory | 'all'): readonly Readonly<object>[];
229
227
  set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
230
228
  get costFunction(): (expr: BoxedExpression) => number;
231
229
  /**
@@ -248,21 +246,57 @@ export declare class ComputeEngine implements IComputeEngine {
248
246
  * Add (or replace) a definition for a symbol in the current scope.
249
247
  */
250
248
  defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
249
+ _defineSymbol(name: string, def: SymbolDefinition): BoxedSymbolDefinition;
251
250
  defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
251
+ _defineFunction(name: string, def: FunctionDefinition): BoxedFunctionDefinition;
252
252
  /**
253
253
  *
254
254
  * Create a new scope and add it to the top of the scope stack
255
255
  *
256
- * The `options.scope` property can be used to specify custom precision,
256
+ * The `scope` argument can be used to specify custom precision,
257
257
  * etc... for this scope
258
258
  *
259
+ *
259
260
  */
260
- pushScope(ids?: Readonly<IdTable> | Readonly<IdTable>[], scope?: Partial<Scope>): void;
261
+ pushScope(scope?: Partial<Scope>): IComputeEngine;
261
262
  /** Remove the topmost scope from the scope stack.
262
263
  */
263
- popScope(): void;
264
- set(identifiers: Substitution<SemiBoxedExpression | null | undefined>): void;
265
- let(identifiers: IdTable): void;
264
+ popScope(): IComputeEngine;
265
+ swapScope(scope: RuntimeScope | null): RuntimeScope | null;
266
+ _printScope(options?: {
267
+ details?: boolean;
268
+ }, scope?: RuntimeScope | null, depth?: number): RuntimeScope | null;
269
+ /**
270
+ * Declare one or more identifiers:
271
+ *
272
+ * associate an identifier with a definition, at minimum a domain, optionally
273
+ * a value and some other flags.
274
+ */
275
+ declare(id: string, def: DomainExpression | SymbolDefinition | FunctionDefinition): IComputeEngine;
276
+ declare(identifiers: {
277
+ [id: string]: DomainExpression | SymbolDefinition | FunctionDefinition;
278
+ }): IComputeEngine;
279
+ /**
280
+ * Assign a value to one or more identifiers.
281
+ *
282
+ * Domain of value must be compatible with existing domain.
283
+ *
284
+ * Declare identifier if it hasn't been declared yet.
285
+ *
286
+ */
287
+ assign(id: string, value: AssignValue): IComputeEngine;
288
+ assign(ids: {
289
+ [id: string]: AssignValue;
290
+ }): IComputeEngine;
291
+ /**
292
+ * Same as assign(), but for internal use:
293
+ * - skips validity checks
294
+ * - does not auto-declare
295
+ * - if assigning to a function, must pass a JS function
296
+ *
297
+ * @internal
298
+ */
299
+ _assign(id: string, value: AssignValue): IComputeEngine;
266
300
  get assumptions(): ExpressionMapInterface<boolean>;
267
301
  /**
268
302
  * Return false if the execution should stop.
@@ -319,7 +353,9 @@ export declare class ComputeEngine implements IComputeEngine {
319
353
  parse(latex: LatexString | string | null, options?: {
320
354
  canonical?: boolean;
321
355
  }): null | BoxedExpression;
322
- serialize(x: Expression | BoxedExpression): string;
356
+ serialize(x: Expression | BoxedExpression, options?: {
357
+ canonical?: boolean;
358
+ }): string;
323
359
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
324
360
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
325
361
  get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
@@ -329,14 +365,12 @@ export declare class ComputeEngine implements IComputeEngine {
329
365
  * Return a list of all the assumptions that match a pattern.
330
366
  *
331
367
  * ```js
332
- * ce.assume(x, 'PositiveInteger');
368
+ * ce.assume(['Element', 'x', 'PositiveIntegers');
333
369
  * ce.ask(['Greater', 'x', '_val'])
334
370
  * // -> [{'val': 0}]
335
371
  * ```
336
372
  */
337
- ask(pattern: LatexString | SemiBoxedExpression): BoxedSubstitution[];
338
- infer(symbol: BoxedExpression | string, _domain: BoxedDomain | DomainExpression): AssumeResult;
339
- assume(symbol: LatexString | SemiBoxedExpression, domainValue: BoxedDomain | Expression | BoxedExpression): AssumeResult;
340
- assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
373
+ ask(pattern: SemiBoxedExpression): BoxedSubstitution[];
374
+ assume(predicate: SemiBoxedExpression): AssumeResult;
341
375
  forget(symbol: undefined | string | string[]): void;
342
376
  }
@@ -1,3 +1,3 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,24 +1,9 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { Decimal } from 'decimal.js';
3
- import { BoxedExpression, Rational } from './public';
3
+ import { DomainLiteral, Rational, SemiBoxedExpression } from './public';
4
4
  /** Quickly determine the numeric domain of a number or constant
5
5
  * For the symbols, this is a hard-coded optimization that doesn't rely on the
6
6
  * dictionaries. The regular path is in `internalDomain()`
7
7
  */
8
- export declare function inferNumericDomain(value: number | Decimal | Complex | Rational): string;
9
- /**
10
- * Simple description of a numeric domain as a base domain, a min and
11
- * max value, possibly open ends, and some excluded values.
12
- */
13
- export type NumericDomainInfo = {
14
- domain?: string;
15
- min?: number;
16
- max?: number;
17
- open?: 'left' | 'right' | 'both';
18
- /** Values from _excludedValues_ are considered not in this domain */
19
- excludedValues?: number[];
20
- /** If defined, the values in this domain must follow the relation
21
- * _period_ * _n_ + _phase_ when _n_ is in _domain_.
22
- */
23
- multiple?: [period: number, domain: BoxedExpression, phase: number];
24
- };
8
+ export declare function inferNumericDomain(value: number | Decimal | Complex | Rational): DomainLiteral;
9
+ export declare function inferDomain(expr: SemiBoxedExpression): DomainLiteral;
@@ -0,0 +1,84 @@
1
+ /* 0.16.0 */
2
+ /**
3
+ * From an expression, create an iterator that can be used
4
+ * to enumerate values.
5
+ *
6
+ * `expr` can be a collection, a function, an expression, a string.
7
+ *
8
+ * - ["Range", 5]
9
+ * - ["List", 1, 2, 3]
10
+ * - "'hello world'"
11
+ *
12
+ */
13
+ export declare function iterable(expr: BoxedExpression): Iterator<BoxedExpression> | undefined;
14
+ /**
15
+ * indexable(expr) return a JS function with one argument.
16
+ *
17
+ * Evaluate expr.
18
+ * If expr is indexable function (def with at handler), return handler.
19
+ * Otherwise, call makeLambda, then return function that set scope
20
+ * with one arg, then evaluate result of makeLambda.
21
+ */
22
+ export declare function indexable(expr: BoxedExpression): ((index: number) => BoxedExpression | undefined) | undefined;
23
+ /**
24
+ * From an expression, return a predicate function, which can be used to filter.
25
+ */
26
+ export declare function predicate(_expr: BoxedExpression): (...args: BoxedExpression[]) => boolean;
27
+ /**
28
+ * From an expression, create an ordering function, which can be used to sort.
29
+ */
30
+ export declare function order(_expr: BoxedExpression): (a: BoxedExpression, b: BoxedExpression) => -1 | 0 | 1;
31
+ /**
32
+ * Given an expression, rewrite it to a canonical Function form.
33
+ *
34
+ *
35
+ * - explicit parameters (no change)
36
+ * ["Function", ["Add, "x", 1], "x"]
37
+ * -> ["Function", ["Add, "x", 1], "x"]
38
+ *
39
+ * - single anonymous parameters:
40
+ * ["Add", "_", 1]
41
+ * -> ["Function", ["Add", "_", 1], "_"]
42
+ *
43
+ * - multiple anonymous parameters:
44
+ * ["Add", "_1", "_2"]
45
+ * -> ["Function", ["Add", "_1", "_2"], "_1", "_2"]
46
+ *
47
+ */
48
+ export declare function canonicalFunctionExpression(expr: BoxedExpression): BoxedExpression | undefined;
49
+ /**
50
+ * Apply arguments to an expression which is either
51
+ * - a '["Function"]' expression
52
+ * - an expression with anonymous parameters, e.g. ["Add", "_", 1]
53
+ * - the identifier for a function, e.g. "Sin".
54
+ */
55
+ export declare function apply(fn: BoxedExpression, args: BoxedExpression[]): BoxedExpression;
56
+ /**
57
+ * Return a lambda function, assuming a scoped environment has been
58
+ * created and there is a single numeric argument
59
+ */
60
+ export declare function makeLambdaN1(expr: BoxedExpression): ((arg: number) => number) | undefined;
61
+ /**
62
+ * Given an expression such as:
63
+ * - ["Function", ["Add", 1, "x"], "x"]
64
+ * - ["Function", ["Divide", "_", 2]]
65
+ * - ["Multiply, "_", 3]
66
+ * - ["Add, "_1", "_2"]
67
+ * - "Sin"
68
+ *
69
+ * return a JS function that can be called with arguments.
70
+ */
71
+ export declare function applicable(fn: BoxedExpression): (args: BoxedExpression[]) => BoxedExpression | undefined;
72
+ /**
73
+ * Use applicableN when the function is known to be a function of a single
74
+ * variable and the argument is a number.
75
+ *
76
+ * Unlike "apply", applicable returns a function that can be called
77
+ * with an argument.
78
+ *
79
+ */
80
+ export declare function applicableN1(fn: BoxedExpression): (x: number) => number;
81
+ /**
82
+ * Give a string like "f(x,y)" return, ["f", ["x", "y"]]
83
+ */
84
+ export declare function parseFunctionSignature(s: string): [id: string, args: string[] | undefined];
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.16.0 */
2
+ export declare const DEFINITIONS_COMPLEX: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.16.0 */
2
+ export declare const DEFINITIONS_STATISTICS: LatexDictionary;
@@ -1,3 +1,3 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const SYMBOLS: [string, string, number][];
3
3
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { WarningSignal } from '../../../common/signals';
3
3
  export type CommonEntry = {
4
4
  /** Note: a name is required if a serialize handler is provided */
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { Serializer } from './serializer';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { WarningSignalHandler } from '../../common/signals';
@@ -19,8 +19,10 @@ export declare class LatexSyntax {
19
19
  get dictionary(): readonly LatexDictionaryEntry[];
20
20
  set dictionary(val: readonly LatexDictionaryEntry[]);
21
21
  updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>): void;
22
- static getDictionary(category?: LibraryCategory | 'all'): Readonly<LatexDictionary>;
22
+ static getDictionary(category?: LibraryCategory | 'all'): readonly Readonly<object>[];
23
23
  parse(latex: LatexString): Expression;
24
- serialize(expr: Expression): LatexString;
24
+ serialize(expr: Expression, options?: {
25
+ canonical?: boolean;
26
+ }): LatexString;
25
27
  get serializer(): Serializer;
26
28
  }
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { Parser } from './public';
3
3
  /** For error handling, if we have a identifier prefix, assume
4
4
  * the identifier is invalid (it would have been captured by
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
3
3
  import { IComputeEngine } from '../public';
4
4
  import { Expression } from '../../math-json/math-json-format';
@@ -94,6 +94,40 @@ export declare class _Parser implements Parser {
94
94
  matchAll(tokens: LatexToken[]): boolean;
95
95
  matchAny(tokens: LatexToken[]): LatexToken;
96
96
  matchChar(): string | null;
97
+ /** If the next token matches the open delimiter, set a boundary with
98
+ * the close token and return true.
99
+ *
100
+ * Note this method handles generic delimiters, i.e. '(' will math both
101
+ * '(', '\left(', '\bigl(', etc...
102
+ *
103
+ * Note that the definitions for matchfix may need to include synonyms
104
+ * for example:
105
+ *
106
+ * {
107
+ * openDelimiter: '(',
108
+ * closeDelimiter: ')'
109
+ * }
110
+ *
111
+ * and
112
+ *
113
+ * {
114
+ * openDelimiter: '\\lparen',
115
+ * closeDelimiter: '\\rparen'
116
+ * }
117
+ *
118
+ * For:
119
+ * - '[': '\\lbrack' and '\\['
120
+ * - ']': '\\rbrack' and '\\]'
121
+ * - '{': '\\lbrace' and '\\}'
122
+ * - '}': '\\rbrace' and '\\}'
123
+ * - '<': '\\langle'
124
+ * - '>': '\\rangle'
125
+ * - '|': '\\vert'
126
+ * - '||': '\\Vert'
127
+ * - '|': '\\lvert' and '\\rvert'
128
+ * - '||': '\\lVert' and '\\rVert'
129
+ */
130
+ private matchDelimiter;
97
131
  parseGroup(): Expression | null;
98
132
  parseToken(): Expression | null;
99
133
  parseOptionalGroup(): Expression | null;
@@ -154,6 +188,8 @@ export declare class _Parser implements Parser {
154
188
  * return `['\right', '\rparen']`, which can be matched with `matchAll()`
155
189
  *
156
190
  * If you need to match several tokens, use `matchAll()`
191
+ *
192
+ * @internal
157
193
  */
158
194
  private matchOpenDelimiter;
159
195
  /** For error handling, when there is potentially a mismatched delimiter.
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import type { IComputeEngine } from '../public';
4
4
  /**
@@ -18,14 +18,18 @@ export type LatexString = string;
18
18
  * record to define new LaTeX dictionary entries.
19
19
  */
20
20
  export type Delimiter = ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor';
21
- export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'control-structures' | 'combinatorics' | 'core' | 'data-structures' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'styling' | 'symbols' | 'trigonometry' | 'units';
22
- /** Theory of operations:
21
+ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'control-structures' | 'combinatorics' | 'complex' | 'core' | 'data-structures' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'styling' | 'symbols' | 'trigonometry' | 'units';
22
+ /**
23
+ *
24
+ * ## THEORY OF OPERATIONS
23
25
  *
24
26
  * The precedence of an operator is a number that indicates the order in which
25
- * operators are applied. For example, in `1 + 2 * 3`, the `*` operator has
26
- * a higher precedence than the `+` operator, so it is applied first.
27
+ * operators are applied.
27
28
  *
28
- * The precendence range from 0 to 1000. The higher the number, the higher the
29
+ * For example, in `1 + 2 * 3`, the `*` operator has a **higher** precedence
30
+ * than the `+` operator, so it is applied first.
31
+ *
32
+ * The precendence range from 0 to 1000. The larger the number, the higher the
29
33
  * precedence, the more "binding" the operator is.
30
34
  *
31
35
  * Here are some rough ranges for the precedence:
@@ -46,6 +50,8 @@ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collectio
46
50
  * - 100: not used
47
51
  * - 0: `,`, `;`, etc...
48
52
  *
53
+ * Some constants are defined below for common precedence values.
54
+ *
49
55
  *
50
56
  * Note: MathML defines some operator precendence, but it has some
51
57
  * issues and inconsistencies. However, whenever possible we adopted the
@@ -55,6 +61,14 @@ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collectio
55
61
  * here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence
56
62
  */
57
63
  export type Precedence = number;
64
+ export declare const COMPARISON_PRECEDENCE = 245;
65
+ export declare const ASSIGNMENT_PRECEDENCE = 260;
66
+ export declare const ARROW_PRECEDENCE = 270;
67
+ export declare const ADDITION_PRECEDENCE = 275;
68
+ export declare const MULTIPLICATION_PRECEDENCE = 390;
69
+ export declare const DIVISION_PRECEDENCE = 600;
70
+ export declare const EXPONENTIATION_PRECEDENCE = 700;
71
+ export declare const POSTFIX_PRECEDENCE = 810;
58
72
  /**
59
73
  * This indicates a condition under which parsing should stop:
60
74
  * - an operator of a precedence higher than specified has been encountered
@@ -453,6 +467,10 @@ export interface Serializer {
453
467
  * for the top level, and `\bigl(` or `(` for others.
454
468
  */
455
469
  level: number;
470
+ /** If true, apply transformations to the expression so the output
471
+ * doesn't necesarily match the raw MathJSON, but is more visually pleasing
472
+ * and easier to read. If false, output the raw MathJSON. */
473
+ canonical?: boolean;
456
474
  /** Output a LaTeX string representing the expression */
457
475
  serialize: (expr: Expression | null) => string;
458
476
  wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none', fence?: string): string;
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { NumberFormattingOptions } from './public';
3
3
  export declare function serializeNumber(expr: Expression | null, options: NumberFormattingOptions): string;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.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,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  import { WarningSignalHandler } from '../../common/signals';
3
3
  import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
4
4
  import { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
@@ -7,6 +7,7 @@ export declare class Serializer {
7
7
  options: NumberFormattingOptions & SerializeLatexOptions;
8
8
  readonly dictionary: IndexedLatexDictionary;
9
9
  level: number;
10
+ canonical: undefined | boolean;
10
11
  constructor(options: NumberFormattingOptions & SerializeLatexOptions, dictionary: IndexedLatexDictionary, onError: WarningSignalHandler);
11
12
  updateOptions(opt: Partial<NumberFormattingOptions> & Partial<SerializeLatexOptions>): void;
12
13
  /**
@@ -30,7 +31,9 @@ export declare class Serializer {
30
31
  serializeDictionary(dict: {
31
32
  [key: string]: Expression;
32
33
  }): string;
33
- serialize(expr: Expression | null): LatexString;
34
+ serialize(expr: Expression | null, options?: {
35
+ canonical?: boolean;
36
+ }): LatexString;
34
37
  applyFunctionStyle(expr: Expression, level: number): 'paren' | 'leftright' | 'big' | 'none';
35
38
  groupStyle(expr: Expression, level: number): 'paren' | 'leftright' | 'big' | 'none';
36
39
  rootStyle(expr: Expression, level: number): 'radical' | 'quotient' | 'solidus';
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  * ## Reference
3
3
  * TeX source code:
4
4
  * {@link http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web | Tex.web}
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  /** The canonical form of `Add`:
3
3
  * - removes `0`
4
4
  * - capture complex numbers (a + ib or ai +b)
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  /**
3
3
  * Canonical form of 'Divide' (and 'Rational')
4
4
  * - remove denominator of 1
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  /** The canonical form of `Multiply`:
3
3
  * - remove `1`
4
4
  * - combine literal integers and rationals
@@ -1,4 +1,4 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  /**
3
3
  *
4
4
  */
@@ -1,2 +1,3 @@
1
- /* 0.14.0 */
2
- export declare const ARITHMETIC_LIBRARY: IdTable[];
1
+ /* 0.16.0 */
2
+ export type CanonicalArithmeticFunctions = 'Add' | 'Negate' | 'Multiply' | 'Divide' | 'Power' | 'Ln';
3
+ export declare const ARITHMETIC_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
2
- export declare const CALCULUS_LIBRARY: IdTable[];
1
+ /* 0.16.0 */
2
+ export declare const CALCULUS_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
2
- export declare const COLLECTIONS_LIBRARY: IdTable;
1
+ /* 0.16.0 */
2
+ export declare const COLLECTIONS_LIBRARY: IdentifierDefinitions;
@@ -0,0 +1,2 @@
1
+ /* 0.16.0 */
2
+ export declare const COMPLEX_LIBRARY: IdentifierDefinitions[];
@@ -0,0 +1,2 @@
1
+ /* 0.16.0 */
2
+ export declare const CONTROL_STRUCTURES_LIBRARY: IdentifierDefinitions[];
@@ -1,2 +1,2 @@
1
- /* 0.14.0 */
2
- export declare const CORE_LIBRARY: IdTable[];
1
+ /* 0.16.0 */
2
+ export declare const CORE_LIBRARY: IdentifierDefinitions[];
@@ -1,16 +1,15 @@
1
- /* 0.14.0 */
1
+ /* 0.16.0 */
2
2
  export declare const DOMAIN_CONSTRUCTORS: string[];
3
3
  export declare const DOMAIN_ALIAS: {
4
- NumericFunction: (string | string[])[];
5
- RealFunction: (string | string[])[];
6
- TrigonometricFunction: string[];
7
- LogicOperator: (string | string[])[];
8
- Predicate: (string | string[])[];
9
- RelationalOperator: string[];
4
+ NumericFunctions: (string | string[])[];
5
+ RealFunctions: (string | string[])[];
6
+ LogicOperators: (string | string[])[];
7
+ Predicates: (string | string[])[];
8
+ RelationalOperators: string[];
10
9
  };
11
10
  export declare function isDomainLiteral(s: string | null): s is DomainLiteral;
12
11
  export declare function isSubdomainLiteral(lhs: string, rhs: string): boolean;
13
12
  /** Return all the domain literals that are an ancestor of `dom`
14
13
  */
15
14
  export declare function ancestors(dom: string): string[];
16
- export declare function domainSetsLibrary(): IdTable;
15
+ export declare function domainSetsLibrary(): IdentifierDefinitions;