@cortex-js/compute-engine 0.5.0 → 0.7.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 +16900 -13123
  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 +90 -36
  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 +23 -10
  11. package/dist/types/compute-engine/boxed-expression/box.d.ts +4 -18
  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 +49 -6
  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 +14 -11
  16. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +3 -3
  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 +10 -7
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +24 -10
  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 +73 -47
  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 -8
  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 +89 -63
  41. package/dist/types/compute-engine/latex-syntax/public.d.ts +85 -67
  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 +265 -219
  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 +3 -2
  76. package/dist/types/math-json/math-json-format.d.ts +27 -23
  77. package/dist/types/math-json/utils.d.ts +23 -18
  78. package/dist/types/math-json.d.ts +3 -3
  79. package/package.json +21 -22
  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,38 +1,52 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
- import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOption } from '../public';
3
+ import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOption, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition } from '../public';
4
4
  /**
5
5
  * BoxedSymbol
6
6
  *
7
- * A boxed symbol is a reference to a BoxedSymbolDefinition.
8
- * The BoxedSymbolDefinition "owns" all the information
7
+ * A boxed symbol is a reference to a `BoxedSymbolDefinition` or a
8
+ * `BoxedFunctionDefinition`.
9
+ *
10
+ * If a `BoxedSymbolDefinition`, it "owns" all the information
9
11
  * about the symbol, its value, domain and various attributes.
12
+ *
13
+ * If a `BoxedFunctionDefinition`, it it a reference to a function name,
14
+ * not a function expression, i.e. `Sin`, not `["Sin", "Pi"]`. This is used
15
+ * for example in `["InverseFunction", "Sin"]`
10
16
  */
11
17
  export declare class BoxedSymbol extends AbstractBoxedExpression {
18
+ private _scope;
12
19
  protected _name: string;
13
20
  private _hash;
14
21
  private _def;
15
22
  constructor(ce: IComputeEngine, name: string, metadata?: Metadata);
16
23
  get hash(): number;
17
- _purge(): undefined;
24
+ unbind(): undefined;
18
25
  get isPure(): boolean;
26
+ /** A free variable either has no definition, or it has a definition, but no value */
27
+ get isFree(): boolean;
28
+ get isConstant(): boolean;
19
29
  get isCanonical(): boolean;
20
30
  set isCanonical(_va: boolean);
31
+ get canonical(): BoxedExpression;
21
32
  get wikidata(): string;
22
33
  get description(): string[];
23
34
  get url(): string;
24
35
  get complexity(): number;
25
36
  get head(): string;
26
37
  get symbol(): string;
27
- get isMissing(): boolean;
38
+ get isNothing(): boolean;
28
39
  get isLiteral(): boolean;
40
+ get baseDefinition(): BoxedBaseDefinition | undefined;
29
41
  get symbolDefinition(): BoxedSymbolDefinition | undefined;
30
- _repairDefinition(): void;
42
+ get functionDefinition(): BoxedFunctionDefinition | undefined;
43
+ bind(scope: RuntimeScope | null): void;
31
44
  get value(): BoxedExpression | undefined;
32
45
  set value(value: BoxedExpression | number | undefined);
33
46
  get numericValue(): BoxedExpression | undefined;
34
- get domain(): BoxedExpression;
35
- set domain(d: BoxedExpression);
47
+ get domain(): BoxedDomain;
48
+ set domain(d: BoxedDomain);
49
+ get explicitDomain(): BoxedDomain | null;
36
50
  get json(): Expression;
37
51
  get sgn(): -1 | 0 | 1 | undefined | null;
38
52
  has(x: string | string[]): boolean;
@@ -43,6 +57,7 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
43
57
  isLessEqual(rhs: BoxedExpression): boolean | undefined;
44
58
  isGreater(rhs: BoxedExpression): boolean | undefined;
45
59
  isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
60
+ get isFunction(): boolean | undefined;
46
61
  get isZero(): boolean | undefined;
47
62
  get isNotZero(): boolean | undefined;
48
63
  get isOne(): boolean | undefined;
@@ -65,7 +80,6 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
65
80
  get isExtendedReal(): boolean | undefined;
66
81
  get isComplex(): boolean | undefined;
67
82
  get isImaginary(): boolean | undefined;
68
- get canonical(): BoxedExpression;
69
83
  simplify(options?: SimplifyOptions): BoxedExpression;
70
84
  evaluate(options?: EvaluateOptions): BoxedExpression;
71
85
  N(options?: NOptions): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, IComputeEngine, Metadata } from '../public';
@@ -1,6 +1,8 @@
1
- /* 0.5.0 */
2
- export declare function isLatexString(s: any): s is string;
3
- export declare function latexString(s: any): string | null;
1
+ /* 0.7.0 */
2
+ import { Expression } from '../../math-json/math-json-format';
3
+ import { BoxedExpression, IComputeEngine } from '../public';
4
+ export declare function isLatexString(s: unknown): s is string;
5
+ export declare function latexString(s: unknown): string | null;
4
6
  /**
5
7
  * Return a multiple of the imaginary unit, e.g.
6
8
  * - 'ImaginaryUnit'
@@ -9,18 +11,20 @@ export declare function latexString(s: any): string | null;
9
11
  * - ['Multiply', 5, 'ImaginaryUnit']
10
12
  * - ['Multiply', 'ImaginaryUnit', 5]
11
13
  */
12
- export declare function getImaginaryCoef(expr: BoxedExpression): number;
14
+ export declare function getImaginaryCoef(expr: BoxedExpression): number | null;
13
15
  /**
14
16
  * Return the free symbols in the expression, recursively.
15
- * A variable, or free symbol,is a symbol that is not bound to a value.
17
+ * A variable, or free symbol, is a symbol that is not bound to a value.
16
18
  */
17
19
  export declare function getVars(expr: BoxedExpression): string[];
20
+ export declare function getSymbols(expr: BoxedExpression, set: Set<string>): Set<string>;
21
+ export declare function getSubexpressions(expr: BoxedExpression, head: string): BoxedExpression[];
18
22
  /**
19
23
  * For any numeric result, or when boxing numbers,
20
- * if `ce.useDecimal` is true, create them as Decimal number
21
- * if `ce.useDecimal` is false, create them as machine number
24
+ * if `preferDecimal` is true, create them as Decimal number
25
+ * if `preferDecimal` is false, create them as machine number
22
26
  */
23
- export declare function useDecimal(ce: IComputeEngine): boolean;
27
+ export declare function preferDecimal(ce: IComputeEngine): boolean;
24
28
  /** If result of a numeric evaluation is a complex number,
25
29
  * return `NaN` if `ce.useComplex` is false
26
30
  */
@@ -35,3 +39,16 @@ export declare function complexAllowed(ce: IComputeEngine): boolean;
35
39
  */
36
40
  export declare function asCanonical(expr: BoxedExpression): BoxedExpression;
37
41
  export declare function hashCode(s: string): number;
42
+ export declare function isDictionaryLike(expr: BoxedExpression): boolean;
43
+ export declare function getDictionaryLike(expr: BoxedExpression): {
44
+ [key: string]: BoxedExpression;
45
+ };
46
+ export declare function isListLike(expr: BoxedExpression): boolean;
47
+ export declare function getListLike(expr: BoxedExpression): BoxedExpression[];
48
+ /**
49
+ * If `expr` is a number, return it as a Decimal (it might be
50
+ * in the machine value range or not). Use `isInMachineRange()` to check.
51
+ *
52
+ * Use this instead of `machineValue()` when possible, as `machineValue` will truncate decimal numbers to machine numbers
53
+ */
54
+ export declare function decimalValue(ce: IComputeEngine, expr: Expression | null | undefined): Decimal | null;
@@ -1,9 +1,10 @@
1
- /* 0.5.0 */
1
+ /* 0.7.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, 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 } 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
+ import { BoxedFunction } from './boxed-expression/boxed-function';
7
8
  /**
8
9
  *
9
10
  * To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
@@ -25,55 +26,70 @@ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefi
25
26
  */
26
27
  export declare class ComputeEngine implements IComputeEngine {
27
28
  /** @internal */
28
- readonly ZERO: BoxedExpression;
29
+ readonly _ZERO: BoxedExpression;
29
30
  /** @internal */
30
- readonly ONE: BoxedExpression;
31
+ readonly _ONE: BoxedExpression;
31
32
  /** @internal */
32
- readonly TWO: BoxedExpression;
33
+ readonly _TWO: BoxedExpression;
33
34
  /** @internal */
34
- readonly HALF: BoxedExpression;
35
+ readonly _HALF: BoxedExpression;
35
36
  /** @internal */
36
- readonly NEGATIVE_ONE: BoxedExpression;
37
+ readonly _NEGATIVE_ONE: BoxedExpression;
37
38
  /** @internal */
38
- readonly I: BoxedExpression;
39
+ readonly _I: BoxedExpression;
39
40
  /** @internal */
40
- readonly NAN: BoxedExpression;
41
+ readonly _NAN: BoxedExpression;
41
42
  /** @internal */
42
- readonly POSITIVE_INFINITY: BoxedExpression;
43
+ readonly _POSITIVE_INFINITY: BoxedExpression;
43
44
  /** @internal */
44
- readonly NEGATIVE_INFINITY: BoxedExpression;
45
+ readonly _NEGATIVE_INFINITY: BoxedExpression;
45
46
  /** @internal */
46
- readonly COMPLEX_INFINITY: BoxedExpression;
47
+ readonly _COMPLEX_INFINITY: BoxedExpression;
47
48
  /** @internal */
48
- DECIMAL_NAN: Decimal;
49
+ _DECIMAL_NAN: Decimal;
49
50
  /** @internal */
50
- DECIMAL_ZERO: Decimal;
51
+ _DECIMAL_ZERO: Decimal;
51
52
  /** @internal */
52
- DECIMAL_ONE: Decimal;
53
+ _DECIMAL_ONE: Decimal;
53
54
  /** @internal */
54
- DECIMAL_TWO: Decimal;
55
+ _DECIMAL_TWO: Decimal;
55
56
  /** @internal */
56
- DECIMAL_HALF: Decimal;
57
+ _DECIMAL_HALF: Decimal;
57
58
  /** @internal */
58
- DECIMAL_PI: Decimal;
59
+ _DECIMAL_PI: Decimal;
60
+ /** @internal */
61
+ _DECIMAL_NEGATIVE_ONE: Decimal;
59
62
  /** @internal */
60
- DECIMAL_NEGATIVE_ONE: Decimal;
61
63
  private _precision;
64
+ /** @internal */
62
65
  private _numericMode;
66
+ /** @internal */
63
67
  private _latexSyntax?;
68
+ /** @internal */
64
69
  private _tolerance;
70
+ /** @internal */
65
71
  private _decimalTolerance;
72
+ /** @internal */
66
73
  private _cache;
74
+ /** @internal */
67
75
  private _stats;
76
+ /** @internal */
68
77
  private _cost?;
78
+ /** @internal */
69
79
  private _jsonSerializationOptions;
70
80
  /** The domain of unknown symbols. If `null` unknown symbols do not have a
71
81
  * definition automatically associated with them.
82
+ *
83
+ * @internal
72
84
  */
73
85
  private _defaultDomain;
86
+ /** @internal */
74
87
  private _commonSymbols;
88
+ /** @internal */
75
89
  private _commonNumbers;
90
+ /** @internal */
76
91
  private _commonDomains;
92
+ /** @internal */
77
93
  private _latexDictionary?;
78
94
  /**
79
95
  * The current scope.
@@ -86,20 +102,20 @@ export declare class ComputeEngine implements IComputeEngine {
86
102
  * The `ce.context` property represents the current scope.
87
103
  *
88
104
  */
89
- context: RuntimeScope;
105
+ context: RuntimeScope | null;
90
106
  /** Absolute time beyond which evaluation should not proceed.
91
107
  * @internal
92
108
  */
93
109
  deadline?: number;
94
110
  /**
95
- * Return dictionaries suitable for the specified categories, or `"all"`
111
+ * Return symbol tables suitable for the specified categories, or `"all"`
96
112
  * for all categories (`"arithmetic"`, `"algebra"`, etc...).
97
113
  *
98
- * A symbol dictionary defines how the symbols and function names in a MathJSON
114
+ * A symbol table defines how the symbols and function names in a MathJSON
99
115
  * expression should be interpreted, i.e. how to evaluate and manipulate them.
100
116
  *
101
117
  */
102
- static getDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
118
+ static getSymbolTables(categories?: LibraryCategory[] | LibraryCategory | 'all'): Readonly<SymbolTable>[];
103
119
  /**
104
120
  * Construct a new `ComputeEngine` instance.
105
121
  *
@@ -120,13 +136,13 @@ export declare class ComputeEngine implements IComputeEngine {
120
136
  * numeric calculations. Default is 100.
121
137
  *
122
138
  * @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.
139
+ * is less than `tolerance`, they are considered equal. Used by `chop()` as well.
124
140
  *
125
141
  * @param options.defaultDomain If an unknown symbol is encountered, assume it should
126
142
  * be a variable in this domain. **Default** `ExtendedRealNumber`
127
143
  */
128
144
  constructor(options?: {
129
- dictionaries?: Readonly<Dictionary>[];
145
+ symbolTables?: Readonly<SymbolTable>[];
130
146
  latexDictionary?: readonly LatexDictionaryEntry[];
131
147
  numericMode?: NumericMode;
132
148
  numericPrecision?: number;
@@ -141,18 +157,14 @@ export declare class ComputeEngine implements IComputeEngine {
141
157
  *
142
158
  * @internal
143
159
  */
144
- purge(): void;
160
+ reset(): void;
145
161
  /** @internal */
146
- _register(expr: BoxedExpression): void;
162
+ _register(_expr: BoxedExpression): void;
147
163
  /** @internal */
148
- _unregister(expr: BoxedExpression): void;
164
+ _unregister(_expr: BoxedExpression): void;
149
165
  get stats(): ComputeEngineStats;
150
166
  /** @internal */
151
167
  _decimal: Decimal.Constructor;
152
- /** @internal */
153
- decimal: (a: Decimal.Value) => Decimal;
154
- /** @internal */
155
- complex: (a: number | Complex, b?: number) => Complex;
156
168
  /** The precision, or number of significant digits, for numeric calculations
157
169
  * such as when calling `ce.N()`.
158
170
  *
@@ -180,8 +192,8 @@ export declare class ComputeEngine implements IComputeEngine {
180
192
  *
181
193
  * **Default:** `"ExtendedRealNumber"`
182
194
  */
183
- get defaultDomain(): BoxedExpression | null;
184
- set defaultDomain(domain: BoxedExpression | string | null);
195
+ get defaultDomain(): BoxedDomain | null;
196
+ set defaultDomain(domain: BoxedDomain | string | null);
185
197
  /**
186
198
  * Values smaller than the tolerance are considered to be zero for the
187
199
  * purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
@@ -189,6 +201,10 @@ export declare class ComputeEngine implements IComputeEngine {
189
201
  */
190
202
  get tolerance(): number;
191
203
  set tolerance(val: number);
204
+ /** @internal */
205
+ decimal(a: Decimal.Value): Decimal;
206
+ /** @internal */
207
+ complex(a: number | Complex, b?: number): Complex;
192
208
  /** Replace a number that is close to 0 with the exact integer 0.
193
209
  *
194
210
  * How close to 0 the number has to be to be considered 0 is determined by {@link tolerance}.
@@ -197,23 +213,30 @@ export declare class ComputeEngine implements IComputeEngine {
197
213
  chop(n: Decimal): Decimal | 0;
198
214
  chop(n: Complex): Complex | 0;
199
215
  private get latexSyntax();
216
+ static getLatexDictionary(domain?: LibraryCategory | 'all'): Readonly<LatexDictionary>;
200
217
  set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
201
218
  get costFunction(): (expr: BoxedExpression) => number;
202
219
  /**
203
220
  * Return a matching symbol definition, starting with the current
204
- * scope and going up the scope chain.
221
+ * scope and going up the scope chain. Prioritize finding a match by
222
+ * wikidata, if provided.
205
223
  */
206
- getSymbolDefinition(symbol: string, wikidata?: string): undefined | BoxedSymbolDefinition;
224
+ lookupSymbol(symbol: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
207
225
  /**
208
226
  * Return the definition for a function matching this head.
209
227
  *
210
- * Start looking in the current scope, than up the scope chain.
228
+ * Start looking in the current context, than up the scope chain.
229
+ *
230
+ * This is a very rough lookup, since it doesn't account for the domain
231
+ * of the argument or the codomain. However, it is useful during parsing
232
+ * to differentiate between symbols that might represent a function application, e.g. `f` vs `x`.
211
233
  */
212
- getFunctionDefinition(head: string): undefined | BoxedFunctionDefinition;
234
+ lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
213
235
  /**
214
236
  * Add (or replace) a definition for a symbol in the current scope.
215
237
  */
216
238
  defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
239
+ defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
217
240
  /**
218
241
  *
219
242
  * Create a new scope and add it to the top of the scope stack
@@ -223,7 +246,7 @@ export declare class ComputeEngine implements IComputeEngine {
223
246
  *
224
247
  */
225
248
  pushScope(options?: {
226
- dictionary?: Readonly<Dictionary> | Readonly<Dictionary>[];
249
+ symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
227
250
  assumptions?: (LatexString | Expression)[];
228
251
  scope?: Partial<Scope>;
229
252
  }): void;
@@ -261,8 +284,9 @@ export declare class ComputeEngine implements IComputeEngine {
261
284
  box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
262
285
  fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
263
286
  /** @internal */
264
- _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
265
- error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): BoxedExpression;
287
+ _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedFunction;
288
+ error(message: ['invalid-domain', ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedDomain;
289
+ error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
266
290
  add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
267
291
  mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
268
292
  power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
@@ -272,14 +296,15 @@ export declare class ComputeEngine implements IComputeEngine {
272
296
  pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
273
297
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
274
298
  string(s: string, metadata?: Metadata): BoxedExpression;
275
- symbol(sym: string, metadata?: Metadata): BoxedExpression;
276
- domain(domain: BoxedExpression | string, metadata?: Metadata): BoxedExpression;
299
+ symbol(name: string, metadata?: Metadata): BoxedExpression;
300
+ domain(domain: BoxedExpression | DomainExpression | BoxedDomain, metadata?: Metadata): BoxedDomain;
301
+ lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
277
302
  number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
278
303
  rules(rules: Rule[]): BoxedRuleSet;
279
304
  pattern(expr: LatexString | SemiBoxedExpression): Pattern;
280
- parse(s: LatexString | string): BoxedExpression;
305
+ parse(latex: LatexString | string): BoxedExpression;
281
306
  parse(s: null): null;
282
- parse(s: LatexString | string | null): null | BoxedExpression;
307
+ parse(latex: LatexString | string | null): null | BoxedExpression;
283
308
  serialize(x: Expression | BoxedExpression): string;
284
309
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
285
310
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
@@ -295,7 +320,8 @@ export declare class ComputeEngine implements IComputeEngine {
295
320
  * ```
296
321
  */
297
322
  ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
298
- assume(symbol: LatexString | SemiBoxedExpression, domain: string | BoxedExpression): AssumeResult;
323
+ infer(symbol: BoxedExpression | string, _domain: BoxedDomain | DomainExpression): AssumeResult;
324
+ assume(symbol: LatexString | SemiBoxedExpression, domainValue: BoxedDomain | DomainExpression | Expression | BoxedExpression): AssumeResult;
299
325
  assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
300
326
  forget(symbol: undefined | string | string[]): void;
301
327
  }
@@ -1,3 +1,3 @@
1
- /* 0.5.0 */
1
+ /* 0.7.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.5.0 */
1
+ /* 0.7.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.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,4 +1,2 @@
1
- /* 0.5.0 */
2
- import { LatexDictionary, Serializer } from '../public';
3
- export declare function serializeLatex(serializer: Serializer, expr: Expression | null): string;
1
+ /* 0.7.0 */
4
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.5.0 */
1
+ /* 0.7.0 */
2
2
  import { WarningSignal } from '../../../common/signals';
3
3
  export declare type CommonEntry = {
4
4
  name?: string;
@@ -7,11 +7,12 @@ export declare type CommonEntry = {
7
7
  export declare type SymbolEntry = CommonEntry & {
8
8
  kind: 'symbol';
9
9
  precedence: number;
10
- arguments: 'group' | 'implicit' | '';
11
- optionalLatexArg: number;
12
- requiredLatexArg: number;
13
10
  parse: SymbolParseHandler;
14
11
  };
12
+ export declare type FunctionEntry = CommonEntry & {
13
+ kind: 'function';
14
+ parse: FunctionParseHandler;
15
+ };
15
16
  export declare type MatchfixEntry = CommonEntry & {
16
17
  kind: 'matchfix';
17
18
  openDelimiter: Delimiter | LatexToken[];
@@ -36,14 +37,13 @@ export declare type PostfixEntry = CommonEntry & {
36
37
  };
37
38
  export declare type EnvironmentEntry = CommonEntry & {
38
39
  kind: 'environment';
39
- optionalLatexArg: number;
40
- requiredLatexArg: number;
41
40
  parse: EnvironmentParseHandler;
42
41
  };
43
- export declare type IndexedLatexDictionaryEntry = SymbolEntry | MatchfixEntry | InfixEntry | PrefixEntry | PostfixEntry | EnvironmentEntry;
42
+ export declare type IndexedLatexDictionaryEntry = FunctionEntry | SymbolEntry | MatchfixEntry | InfixEntry | PrefixEntry | PostfixEntry | EnvironmentEntry;
44
43
  export declare type IndexedLatexDictionary = {
45
44
  lookahead: number;
46
45
  name: Map<string, IndexedLatexDictionaryEntry>;
46
+ function: Map<string, FunctionEntry[]>;
47
47
  symbol: (Map<LatexString, SymbolEntry[]> | null)[];
48
48
  prefix: (Map<LatexString, PrefixEntry[]> | null)[];
49
49
  infix: (Map<LatexString, InfixEntry[]> | null)[];
@@ -53,5 +53,5 @@ export declare type IndexedLatexDictionary = {
53
53
  };
54
54
  export declare function indexLatexDictionary(dic: readonly LatexDictionaryEntry[], onError: (sig: WarningSignal) => void): IndexedLatexDictionary;
55
55
  export declare const DEFAULT_LATEX_DICTIONARY: {
56
- [category in DictionaryCategory]?: LatexDictionary;
56
+ [category in LibraryCategory]?: LatexDictionary;
57
57
  };
@@ -1,4 +1,4 @@
1
- /* 0.5.0 */
1
+ /* 0.7.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(domain?: 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;