@cortex-js/compute-engine 0.6.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 +15779 -12531
  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 +22 -10
  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 +14 -13
  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 +9 -6
  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 +23 -6
  25. package/dist/types/compute-engine/compute-engine.d.ts +74 -50
  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 +237 -187
  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,38 +1,52 @@
1
- /* 0.6.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, Domain } 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(): Domain;
35
- set domain(d: Domain);
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.6.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.6.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.6.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,4 +1,6 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
+ import { Expression } from '../../math-json/math-json-format';
3
+ import { BoxedExpression, IComputeEngine } from '../public';
2
4
  export declare function isLatexString(s: unknown): s is string;
3
5
  export declare function latexString(s: unknown): string | null;
4
6
  /**
@@ -9,18 +11,20 @@ export declare function latexString(s: unknown): 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.6.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, 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
+ 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(): Domain | null;
184
- set defaultDomain(domain: Domain | 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,25 +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();
200
- static getLatexDictionary(domain?: DictionaryCategory | 'all'): Readonly<LatexDictionary>;
216
+ static getLatexDictionary(domain?: LibraryCategory | 'all'): Readonly<LatexDictionary>;
201
217
  set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
202
218
  get costFunction(): (expr: BoxedExpression) => number;
203
219
  /**
204
220
  * Return a matching symbol definition, starting with the current
205
- * scope and going up the scope chain.
221
+ * scope and going up the scope chain. Prioritize finding a match by
222
+ * wikidata, if provided.
206
223
  */
207
- getSymbolDefinition(symbol: string, wikidata?: string): undefined | BoxedSymbolDefinition;
224
+ lookupSymbol(symbol: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
208
225
  /**
209
- * Return the definition for a function matching this head and
210
- * these arguments.
226
+ * Return the definition for a function matching this head.
227
+ *
228
+ * Start looking in the current context, than up the scope chain.
211
229
  *
212
- * Start looking in the current scope, than up the scope chain.
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`.
213
233
  */
214
- getFunctionDefinition(head: string, args?: BoxedExpression[]): undefined | BoxedFunctionDefinition;
234
+ lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
215
235
  /**
216
236
  * Add (or replace) a definition for a symbol in the current scope.
217
237
  */
218
238
  defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
239
+ defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
219
240
  /**
220
241
  *
221
242
  * Create a new scope and add it to the top of the scope stack
@@ -225,7 +246,7 @@ export declare class ComputeEngine implements IComputeEngine {
225
246
  *
226
247
  */
227
248
  pushScope(options?: {
228
- dictionary?: Readonly<Dictionary> | Readonly<Dictionary>[];
249
+ symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
229
250
  assumptions?: (LatexString | Expression)[];
230
251
  scope?: Partial<Scope>;
231
252
  }): void;
@@ -263,8 +284,9 @@ export declare class ComputeEngine implements IComputeEngine {
263
284
  box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
264
285
  fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
265
286
  /** @internal */
266
- _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
267
- 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;
268
290
  add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
269
291
  mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
270
292
  power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
@@ -274,14 +296,15 @@ export declare class ComputeEngine implements IComputeEngine {
274
296
  pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
275
297
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
276
298
  string(s: string, metadata?: Metadata): BoxedExpression;
277
- symbol(sym: string, metadata?: Metadata): BoxedExpression;
278
- domain(domain: BoxedExpression | DomainExpression | Domain, metadata?: Metadata): Domain;
299
+ symbol(name: string, metadata?: Metadata): BoxedExpression;
300
+ domain(domain: BoxedExpression | DomainExpression | BoxedDomain, metadata?: Metadata): BoxedDomain;
301
+ lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
279
302
  number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
280
303
  rules(rules: Rule[]): BoxedRuleSet;
281
304
  pattern(expr: LatexString | SemiBoxedExpression): Pattern;
282
- parse(s: LatexString | string): BoxedExpression;
305
+ parse(latex: LatexString | string): BoxedExpression;
283
306
  parse(s: null): null;
284
- parse(s: LatexString | string | null): null | BoxedExpression;
307
+ parse(latex: LatexString | string | null): null | BoxedExpression;
285
308
  serialize(x: Expression | BoxedExpression): string;
286
309
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
287
310
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
@@ -297,7 +320,8 @@ export declare class ComputeEngine implements IComputeEngine {
297
320
  * ```
298
321
  */
299
322
  ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
300
- 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;
301
325
  assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
302
326
  forget(symbol: undefined | string | string[]): void;
303
327
  }
@@ -1,3 +1,3 @@
1
- /* 0.6.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.6.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.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.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.7.0 */
4
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.6.0 */
1
+ /* 0.7.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.6.0 */
1
+ /* 0.7.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.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(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;