@cortex-js/compute-engine 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +4 -5
  2. package/dist/compute-engine.esm.js +16755 -10484
  3. package/dist/compute-engine.min.esm.js +2 -7
  4. package/dist/compute-engine.min.js +2 -7
  5. package/dist/math-json.esm.js +148 -12472
  6. package/dist/math-json.min.esm.js +2 -7
  7. package/dist/math-json.min.js +2 -7
  8. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  9. package/dist/types/common/signals.d.ts +90 -0
  10. package/dist/types/compute-engine/assume.d.ts +21 -6
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +95 -0
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +53 -0
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
  26. package/dist/types/compute-engine/compute-engine.d.ts +284 -99
  27. package/dist/types/compute-engine/cost-function.d.ts +3 -0
  28. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
  29. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
  30. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
  31. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
  32. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
  33. package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
  34. package/dist/types/compute-engine/dictionary/core.d.ts +2 -2
  35. package/dist/types/compute-engine/dictionary/dictionary.d.ts +18 -11
  36. package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
  37. package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
  38. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
  39. package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
  40. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -2
  41. package/dist/types/compute-engine/domain-utils.d.ts +30 -0
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
  53. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
  54. package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
  55. package/dist/types/compute-engine/latex-syntax/public.d.ts +576 -0
  56. package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +4 -5
  57. package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
  58. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +41 -0
  59. package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
  60. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  61. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
  62. package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
  63. package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
  64. package/dist/types/compute-engine/public.d.ts +1416 -447
  65. package/dist/types/compute-engine/rules.d.ts +16 -6
  66. package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
  67. package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
  68. package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
  69. package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
  70. package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
  71. package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
  72. package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
  73. package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
  74. package/dist/types/compute-engine.d.ts +3 -5
  75. package/dist/types/math-json/math-json-format.d.ts +101 -0
  76. package/dist/types/math-json/utils.d.ts +97 -0
  77. package/dist/types/math-json.d.ts +4 -3
  78. package/package.json +29 -28
  79. package/dist/compute-engine.js +0 -17296
  80. package/dist/cortex.esm.js +0 -20989
  81. package/dist/cortex.js +0 -21011
  82. package/dist/cortex.min.esm.js +0 -7
  83. package/dist/cortex.min.js +0 -7
  84. package/dist/math-json.js +0 -12517
  85. package/dist/types/common/debug.d.ts +0 -28
  86. package/dist/types/common/utils.d.ts +0 -153
  87. package/dist/types/compute-engine/canonical-forms.d.ts +0 -74
  88. package/dist/types/compute-engine/dictionary/domains.d.ts +0 -26
  89. package/dist/types/compute-engine/dictionary/utils.d.ts +0 -5
  90. package/dist/types/compute-engine/domains.d.ts +0 -4
  91. package/dist/types/compute-engine/evaluate.d.ts +0 -13
  92. package/dist/types/compute-engine/expression-map.d.ts +0 -11
  93. package/dist/types/compute-engine/internal-compute-engine.d.ts +0 -108
  94. package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
  95. package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
  96. package/dist/types/compute-engine/numeric.d.ts +0 -21
  97. package/dist/types/compute-engine/numerical-eval.d.ts +0 -5
  98. package/dist/types/compute-engine/order.d.ts +0 -18
  99. package/dist/types/compute-engine/patterns.d.ts +0 -22
  100. package/dist/types/compute-engine/predicates.d.ts +0 -42
  101. package/dist/types/compute-engine/simplify.d.ts +0 -6
  102. package/dist/types/compute-engine/utils.d.ts +0 -15
  103. package/dist/types/cortex/formatter.d.ts +0 -165
  104. package/dist/types/cortex/parse-cortex.d.ts +0 -5
  105. package/dist/types/cortex/reserved-words.d.ts +0 -1
  106. package/dist/types/cortex/serialize-cortex.d.ts +0 -14
  107. package/dist/types/cortex.d.ts +0 -8
  108. package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
  109. package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
  110. package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
  111. package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
  112. package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
  113. package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
  114. package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
  115. package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
  116. package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
  117. package/dist/types/latex-syntax/definitions.d.ts +0 -40
  118. package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
  119. package/dist/types/latex-syntax/parse.d.ts +0 -138
  120. package/dist/types/latex-syntax/public.d.ts +0 -456
  121. package/dist/types/latex-syntax/serializer.d.ts +0 -26
  122. package/dist/types/latex-syntax/utils.d.ts +0 -10
  123. package/dist/types/point-free-parser/characters.d.ts +0 -25
  124. package/dist/types/point-free-parser/combinators.d.ts +0 -46
  125. package/dist/types/point-free-parser/core-combinators.d.ts +0 -78
  126. package/dist/types/point-free-parser/grammar.d.ts +0 -12
  127. package/dist/types/point-free-parser/identifier-parsers.d.ts +0 -7
  128. package/dist/types/point-free-parser/numeric-parsers.d.ts +0 -8
  129. package/dist/types/point-free-parser/parsers.d.ts +0 -130
  130. package/dist/types/point-free-parser/string-parsers.d.ts +0 -29
  131. package/dist/types/point-free-parser/whitespace-parsers.d.ts +0 -17
  132. package/dist/types/public.d.ts +0 -163
@@ -1,116 +1,301 @@
1
- /* 0.4.2 */
2
- import { CollectionDefinition, ComputeEngine as ComputeEngineInterface, Definition, Dictionary, Domain, Form, FunctionDefinition, Numeric, NumericFormat, RuleSet, RuntimeScope, Scope, SetDefinition, Simplification, SymbolDefinition } from './public';
3
- import { InternalComputeEngine } from './internal-compute-engine';
4
- import { ExpressionMap } from './expression-map';
5
- export declare class ComputeEngine<T extends number = number> implements ComputeEngineInterface {
6
- readonly internal: InternalComputeEngine;
7
- static getDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary<Numeric>>[];
1
+ /* 0.5.0 */
2
+ import { Complex } from 'complex.js';
3
+ import { Expression, MathJsonNumber } from '../math-json/math-json-format';
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';
7
+ /**
8
+ *
9
+ * To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
10
+ *
11
+ * Use the instance to create expressions with `ce.parse()` and `ce.box()`.
12
+ *
13
+ *
14
+ * ```ts
15
+ * const ce = new ComputeEngine();
16
+ * let expr = ce.parse("e^{i\\pi}");
17
+ * console.log(expr.N().latex);
18
+ * // ➔ "-1"
19
+ *
20
+ * expr = ce.box(["Expand", ["Power", ["Add", "a", "b"], 2]]);
21
+ * console.log(expr.evaluate().latex);
22
+ * // ➔ "a^2 + 2ab + b^2"
23
+ *
24
+ * ```
25
+ */
26
+ export declare class ComputeEngine implements IComputeEngine {
27
+ /** @internal */
28
+ readonly ZERO: BoxedExpression;
29
+ /** @internal */
30
+ readonly ONE: BoxedExpression;
31
+ /** @internal */
32
+ readonly TWO: BoxedExpression;
33
+ /** @internal */
34
+ readonly HALF: BoxedExpression;
35
+ /** @internal */
36
+ readonly NEGATIVE_ONE: BoxedExpression;
37
+ /** @internal */
38
+ readonly I: BoxedExpression;
39
+ /** @internal */
40
+ readonly NAN: BoxedExpression;
41
+ /** @internal */
42
+ readonly POSITIVE_INFINITY: BoxedExpression;
43
+ /** @internal */
44
+ readonly NEGATIVE_INFINITY: BoxedExpression;
45
+ /** @internal */
46
+ readonly COMPLEX_INFINITY: BoxedExpression;
47
+ /** @internal */
48
+ DECIMAL_NAN: Decimal;
49
+ /** @internal */
50
+ DECIMAL_ZERO: Decimal;
51
+ /** @internal */
52
+ DECIMAL_ONE: Decimal;
53
+ /** @internal */
54
+ DECIMAL_TWO: Decimal;
55
+ /** @internal */
56
+ DECIMAL_HALF: Decimal;
57
+ /** @internal */
58
+ DECIMAL_PI: Decimal;
59
+ /** @internal */
60
+ DECIMAL_NEGATIVE_ONE: Decimal;
61
+ private _precision;
62
+ private _numericMode;
63
+ private _latexSyntax?;
64
+ private _tolerance;
65
+ private _decimalTolerance;
66
+ private _cache;
67
+ private _stats;
68
+ private _cost?;
69
+ private _jsonSerializationOptions;
70
+ /** The domain of unknown symbols. If `null` unknown symbols do not have a
71
+ * definition automatically associated with them.
72
+ */
73
+ private _defaultDomain;
74
+ private _commonSymbols;
75
+ private _commonNumbers;
76
+ private _commonDomains;
77
+ private _latexDictionary?;
78
+ /**
79
+ * The current scope.
80
+ *
81
+ * A **scope** stores the definition of symbols and assumptions.
82
+ *
83
+ * Scopes form a stack, and definitions in more recent
84
+ * scopes can obscure definitions from older scopes.
85
+ *
86
+ * The `ce.context` property represents the current scope.
87
+ *
88
+ */
89
+ context: RuntimeScope;
90
+ /** Absolute time beyond which evaluation should not proceed.
91
+ * @internal
92
+ */
93
+ deadline?: number;
94
+ /**
95
+ * Return dictionaries suitable for the specified categories, or `"all"`
96
+ * for all categories (`"arithmetic"`, `"algebra"`, etc...).
97
+ *
98
+ * A symbol dictionary defines how the symbols and function names in a MathJSON
99
+ * expression should be interpreted, i.e. how to evaluate and manipulate them.
100
+ *
101
+ */
102
+ static getDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
103
+ /**
104
+ * Construct a new `ComputeEngine` instance.
105
+ *
106
+ * Dictionaries define functions and symbols (in `options.dictionaries`) and
107
+ * the LaTeX syntax (in `options.latexDictionaries`). If no dictionaries
108
+ * are provided, the default ones are used.
109
+ *
110
+ * The order of the dictionaries matter: the definitions from the later ones
111
+ * override the definitions from earlier ones. The first dictionary should
112
+ * be the `'core'` dictionary which include some basic definitions such
113
+ * as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
114
+ *
115
+ * @param options.numericMode The default mode is `auto`. Use `machine` to only
116
+ * use 64-bit float, use `decimal` to always use arbitrary precision floating
117
+ * point numbers or `complex` for complex numbers.
118
+ *
119
+ * @param options.numericPrecision Specific how many digits of precision for the
120
+ * numeric calculations. Default is 100.
121
+ *
122
+ * @param options.tolerance If the absolute value of the difference of two numbers
123
+ * is less than `toleranc`, they are considered equal. Used by `chop()` as well.
124
+ *
125
+ * @param options.defaultDomain If an unknown symbol is encountered, assume it should
126
+ * be a variable in this domain. **Default** `ExtendedRealNumber`
127
+ */
8
128
  constructor(options?: {
9
- dictionaries?: Readonly<Dictionary<Numeric>>[];
129
+ dictionaries?: Readonly<Dictionary>[];
130
+ latexDictionary?: readonly LatexDictionaryEntry[];
131
+ numericMode?: NumericMode;
132
+ numericPrecision?: number;
133
+ tolerance?: number;
134
+ assumptions?: (LatexString | Expression)[];
135
+ defaultDomain?: string;
10
136
  });
137
+ /** After the configuration of the engine has changed, clear the caches
138
+ * so that new values can be recalculated.
139
+ *
140
+ * This needs to happen for example when the numeric precision changes.
141
+ *
142
+ * @internal
143
+ */
144
+ purge(): void;
145
+ /** @internal */
146
+ _register(expr: BoxedExpression): void;
147
+ /** @internal */
148
+ _unregister(expr: BoxedExpression): void;
149
+ get stats(): ComputeEngineStats;
150
+ /** @internal */
151
+ _decimal: Decimal.Constructor;
152
+ /** @internal */
153
+ decimal: (a: Decimal.Value) => Decimal;
154
+ /** @internal */
155
+ complex: (a: number | Complex, b?: number) => Complex;
156
+ /** The precision, or number of significant digits, for numeric calculations
157
+ * such as when calling `ce.N()`.
158
+ *
159
+ * To make calculations using more digits, at the cost of expended memory
160
+ * usage and slower computations, set the `precision` higher.
161
+ *
162
+ * Trigonometric operations are accurate for precision up to 1,000.
163
+ *
164
+ */
11
165
  get precision(): number;
12
166
  set precision(p: number | 'machine');
13
- get numericFormat(): NumericFormat;
14
- set numericFormat(f: NumericFormat);
167
+ get numericMode(): NumericMode;
168
+ set numericMode(f: NumericMode);
169
+ /** @experimental */
170
+ get timeLimit(): number;
171
+ /** @experimental */
172
+ get iterationLimit(): number;
173
+ /** @experimental */
174
+ get recursionLimit(): number;
175
+ /**
176
+ * If an unknown symbol is encountered, assume it should
177
+ * be a variable in this domain.
178
+ *
179
+ * If set to `null`, unknown symbols will trigger an error.
180
+ *
181
+ * **Default:** `"ExtendedRealNumber"`
182
+ */
183
+ get defaultDomain(): BoxedExpression | null;
184
+ set defaultDomain(domain: BoxedExpression | string | null);
185
+ /**
186
+ * Values smaller than the tolerance are considered to be zero for the
187
+ * purpose of comparison, i.e. if `|b - a| <= tolerance`, `b` is considered
188
+ * equal to `a`.
189
+ */
15
190
  get tolerance(): number;
16
191
  set tolerance(val: number);
17
- get context(): RuntimeScope<Numeric>;
18
- pushScope(dictionary: Readonly<Dictionary<Numeric>>, scope?: Partial<Scope>): void;
19
- popScope(): void;
20
- get assumptions(): ExpressionMap<T, boolean>;
21
- shouldContinueExecution(): boolean;
22
- checkContinueExecution(): void;
23
- signal(sig: ErrorSignal | WarningSignal): void;
24
- getFunctionDefinition(name: string): FunctionDefinition | null;
25
- getSymbolDefinition(name: string): SymbolDefinition<Numeric> | null;
26
- getSetDefinition(name: string): SetDefinition<Numeric> | null;
27
- getCollectionDefinition(name: string): CollectionDefinition<Numeric> | null;
28
- getDefinition(name: string): Definition<Numeric> | null;
29
- getRules(topic: string | string[]): RuleSet;
30
- format(expr: Expression | null, forms?: Form | Form[]): Expression | null;
192
+ /** Replace a number that is close to 0 with the exact integer 0.
193
+ *
194
+ * How close to 0 the number has to be to be considered 0 is determined by {@link tolerance}.
195
+ */
196
+ chop(n: number): number;
197
+ chop(n: Decimal): Decimal | 0;
198
+ chop(n: Complex): Complex | 0;
199
+ private get latexSyntax();
200
+ set costFunction(fn: ((expr: BoxedExpression) => number) | undefined);
201
+ get costFunction(): (expr: BoxedExpression) => number;
202
+ /**
203
+ * Return a matching symbol definition, starting with the current
204
+ * scope and going up the scope chain.
205
+ */
206
+ getSymbolDefinition(symbol: string, wikidata?: string): undefined | BoxedSymbolDefinition;
207
+ /**
208
+ * Return the definition for a function matching this head.
209
+ *
210
+ * Start looking in the current scope, than up the scope chain.
211
+ */
212
+ getFunctionDefinition(head: string): undefined | BoxedFunctionDefinition;
213
+ /**
214
+ * Add (or replace) a definition for a symbol in the current scope.
215
+ */
216
+ defineSymbol(def: SymbolDefinition): BoxedSymbolDefinition;
31
217
  /**
32
- * Return the canonical form of an expression.
218
+ *
219
+ * Create a new scope and add it to the top of the scope stack
220
+ *
221
+ * The `options.scope` property can be used to specify custom precision,
222
+ * etc... for this scope
223
+ *
224
+ */
225
+ pushScope(options?: {
226
+ dictionary?: Readonly<Dictionary> | Readonly<Dictionary>[];
227
+ assumptions?: (LatexString | Expression)[];
228
+ scope?: Partial<Scope>;
229
+ }): void;
230
+ /** Remove the topmost scope from the scope stack.
33
231
  */
34
- canonical(expr: Expression | null): Expression | null;
232
+ popScope(): void;
233
+ get assumptions(): ExpressionMapInterface<boolean>;
35
234
  /**
36
- * Return a numerical approximation of an expression.
235
+ * Return false if the execution should stop.
236
+ *
237
+ * This can occur if:
238
+ * - an error has been signaled
239
+ * - the time limit or memory limit has been exceeded
240
+ *
241
+ * @internal
37
242
  */
38
- N(expr: Expression): Expression | null;
243
+ shouldContinueExecution(): boolean;
244
+ /** @internal */
245
+ checkContinueExecution(): void;
246
+ assert(condition: boolean, expr: BoxedExpression, msg: string, code?: SignalMessage): void;
39
247
  /**
40
- * Attempt to simplify an expression, that is rewrite it in a simpler form,
41
- * making use of the available assumptions.
248
+ * Call this function if an unexpected condition occurs during execution of a
249
+ * function in the engine.
42
250
  *
43
- * The simplification steps will proceed multiple times until either:
44
- * 1/ the expression stop changing
45
- * 2/ the number of iteration exceeds `iterationLimit`
46
- * 3/ the time to compute exceeds `timeLimit`, expressed in seconds
251
+ * An `ErrorSignal` is a problem that cannot be recovered from.
47
252
  *
48
- * If no `timeLimit` or `iterationLimit` are provided, the values
49
- * from the current ComputeEngine context are used. By default those
50
- * values are an infinite amount of iterations and a 2s time limit.
253
+ * A `WarningSignal` indicates a minor problem that does not prevent the
254
+ * execution to continue.
51
255
  *
52
256
  */
53
- simplify(expr: Expression, options?: {
54
- timeLimit?: number;
55
- iterationLimit?: number;
56
- simplifications?: Simplification[];
57
- }): Expression | null;
257
+ signal(expr: BoxedExpression, msg: string, code?: SignalMessage): void;
258
+ signal(sig: WarningSignal): void;
259
+ /** @internal */
260
+ cache<T>(cacheName: string, build: () => T, purge: (T: any) => T | undefined): T;
261
+ box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
262
+ fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
263
+ /** @internal */
264
+ _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
265
+ error(val: BoxedExpression, message: string, messageArg: SemiBoxedExpression): BoxedExpression;
266
+ add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
267
+ mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
268
+ power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
269
+ inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
270
+ negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
271
+ divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
272
+ pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
273
+ tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
274
+ string(s: string, metadata?: Metadata): BoxedExpression;
275
+ symbol(sym: string, metadata?: Metadata): BoxedExpression;
276
+ domain(domain: BoxedExpression | string, metadata?: Metadata): BoxedExpression;
277
+ number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
278
+ rules(rules: Rule[]): BoxedRuleSet;
279
+ pattern(expr: LatexString | SemiBoxedExpression): Pattern;
280
+ parse(s: LatexString | string): BoxedExpression;
281
+ parse(s: null): null;
282
+ parse(s: LatexString | string | null): null | BoxedExpression;
283
+ serialize(x: Expression | BoxedExpression): string;
284
+ get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
285
+ set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
286
+ get jsonSerializationOptions(): JsonSerializationOptions;
287
+ set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
58
288
  /**
59
- * Return a simplified and numerically approximation of an expression
60
- * in canonical form.
61
- *
62
- * The simplification steps will proceed multiple times until either:
63
- * 1/ the expression stop changing
64
- * 2/ the number of iteration exceeds `iterationLimit`
65
- * 3/ the time to compute exceeds `timeLimit`, expressed in seconds
66
- *
67
- * If no `timeLimit` or `iterationLimit` are provided, the values
68
- * from the current ComputeEngine context are used. By default those
69
- * values are an infinite amount of iterations and a 2s time limit.
70
- */
71
- evaluate(expr: Expression, options?: {
72
- timeLimit?: number;
73
- iterationLimit?: number;
74
- }): Promise<Expression | null>;
75
- parse(s: string): Expression;
76
- serialize(x: Expression): string;
77
- domain(expr: Expression): Expression | null;
78
- /** Query the assumption database
79
- */
80
- is(symbol: Expression, domain: Domain): boolean | undefined;
81
- is(predicate: Expression): boolean | undefined;
82
- ask(pattern: Expression): {
83
- [symbol: string]: Expression;
84
- }[];
85
- assume(symbol: Expression, domain: Domain): 'contradiction' | 'tautology' | 'ok';
86
- assume(predicate: Expression): 'contradiction' | 'tautology' | 'ok';
87
- replace(rules: RuleSet<T>, expr: Expression<T>): Expression<T>;
88
- getVars(expr: Expression): Set<string>;
89
- chop(n: Numeric): Numeric;
90
- isZero(x: Expression<T>): boolean | undefined;
91
- isNotZero(x: Expression<T>): boolean | undefined;
92
- isNumeric(x: Expression<T>): boolean | undefined;
93
- isInfinity(x: Expression<T>): boolean | undefined;
94
- isFinite(x: Expression<T>): boolean | undefined;
95
- isNonNegative(x: Expression<T>): boolean | undefined;
96
- isPositive(x: Expression<T>): boolean | undefined;
97
- isNegative(x: Expression<T>): boolean | undefined;
98
- isNonPositive(x: Expression<T>): boolean | undefined;
99
- isInteger(x: Expression<T>): boolean | undefined;
100
- isRational(x: Expression<T>): boolean | undefined;
101
- isAlgebraic(x: Expression<T>): boolean | undefined;
102
- isReal(x: Expression<T>): boolean | undefined;
103
- isExtendedReal(x: Expression<T>): boolean | undefined;
104
- isComplex(x: Expression<T>): boolean | undefined;
105
- isOne(x: Expression<T>): boolean | undefined;
106
- isNegativeOne(x: Expression<T>): boolean | undefined;
107
- isElement(x: Expression<T>, set: Expression<T>): boolean | undefined;
108
- isSubsetOf(lhs: Domain | null, rhs: Domain | null): boolean;
109
- isEqual(lhs: Expression, rhs: Expression): boolean | undefined;
110
- isLess(lhs: Expression, rhs: Expression): boolean | undefined;
111
- isLessEqual(lhs: Expression, rhs: Expression): boolean | undefined;
112
- isGreater(lhs: Expression, rhs: Expression): boolean | undefined;
113
- isGreaterEqual(lhs: Expression, rhs: Expression): boolean | undefined;
289
+ * Return a list of all the assumptions that match a pattern.
290
+ *
291
+ * ```js
292
+ * ce.assume(x, 'PositiveInteger');
293
+ * ce.ask(['Greater', 'x', '_val'])
294
+ * // -> [{'val': 0}]
295
+ * ```
296
+ */
297
+ ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
298
+ assume(symbol: LatexString | SemiBoxedExpression, domain: string | BoxedExpression): AssumeResult;
299
+ assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
300
+ forget(symbol: undefined | string | string[]): void;
114
301
  }
115
- export declare function format(expr: Expression, forms: Form | Form[]): Expression | null;
116
- export declare function evaluate(expr: Expression): Promise<Expression | null>;
@@ -0,0 +1,3 @@
1
+ /* 0.5.0 */
2
+ export declare function costFunction(expr: BoxedExpression): number;
3
+ export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -0,0 +1,11 @@
1
+ /* 0.5.0 */
2
+ /** The canonical form of `Add`:
3
+ * - removes `0`
4
+ * - adds up small integers and rational numbers
5
+ * - capture complex numbers (a + ib or ai +b)
6
+ * - groups repeated terms (a + a -> 2a)
7
+ * */
8
+ export declare function canonicalAdd(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
9
+ export declare function domainAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression | string;
10
+ export declare function numEvalAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression;
11
+ export declare function processAdd(ce: IComputeEngine, args: BoxedExpression[], _mode: 'simplify' | 'evaluate'): BoxedExpression | undefined;
@@ -0,0 +1,9 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ * Canonical form of 'Divide' (and 'Rational')
4
+ * - remove denominator of 1
5
+ * - simplify the signs
6
+ * - factor out negate (make the numerator and denominator positive)
7
+ * - if Divide, transform into Multiply/Power
8
+ */
9
+ export declare function canonicalDivide(ce: IComputeEngine, op1: BoxedExpression, op2: BoxedExpression): BoxedExpression;
@@ -0,0 +1,17 @@
1
+ /* 0.5.0 */
2
+ /** The canonical form of `Multiply`:
3
+ * - remove `1`
4
+ * - combine literal small integers and rationals
5
+ * - any arg is literal 0 -> return 0
6
+ * - simplify signs
7
+ * - combine terms with same base
8
+ * `a a^3` -> `a^4`
9
+ * - simplify the signs:
10
+ * - i.e. `-2 \times -3` -> `2 \times 3`
11
+ * - `2 \times -x` -> `-2 \times x`
12
+ *
13
+ * The ops must be canonical, the result is canonical.
14
+ */
15
+ export declare function canonicalMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
16
+ export declare function processMultiply(ce: IComputeEngine, ops: BoxedExpression[], _mode: 'simplify' | 'evaluate'): BoxedExpression | undefined;
17
+ export declare function numEvalMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression | undefined;
@@ -0,0 +1,9 @@
1
+ /* 0.5.0 */
2
+ /**
3
+ *
4
+ * Return `null` if there is no canonicalization necessary and the result is
5
+ * simply `ce._fn('Power', [base, exponent])`
6
+ */
7
+ export declare function canonicalPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, metadata?: Metadata): BoxedExpression | null;
8
+ export declare function square(ce: IComputeEngine, base: BoxedExpression): BoxedExpression;
9
+ export declare function processPower(ce: IComputeEngine, base: BoxedExpression, exponent: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
@@ -1,12 +1,2 @@
1
- /* 0.4.2 */
2
- import type { ComputeEngine, Dictionary, Numeric } from '../public';
3
- export declare const ARITHMETIC_DICTIONARY: Dictionary<Numeric>;
4
- /** Apply some simplifications for `Negate`.
5
- * Used by `canonical-negate` and `simplify`
6
- */
7
- export declare function applyNegate(expr: Expression): Expression;
8
- export declare function ungroup(expr: Expression | null): Expression;
9
- export declare function applyPower(engine: ComputeEngine, expr: Expression): Expression;
10
- /** Used by `simplify` and `canonical` to simplify some arithmetic
11
- * and trigonometric constants */
12
- export declare function applyConstants(expr: Expression): Expression;
1
+ /* 0.5.0 */
2
+ export declare const ARITHMETIC_DICTIONARY: Dictionary[];
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
1
+ /* 0.5.0 */
2
2
  export declare const COLLECTIONS_DICTIONARY: Dictionary;
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
2
- export declare const CORE_DICTIONARY: Dictionary;
1
+ /* 0.5.0 */
2
+ export declare const CORE_DICTIONARY: Dictionary[];
@@ -1,19 +1,26 @@
1
- /* 0.4.2 */
2
- import type { Dictionary, CompiledDictionary, ComputeEngine, Numeric } from '../public';
3
- export declare function getDefaultDictionaries<T extends number = number>(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary<T>>[];
4
- export declare const DICTIONARY: {
5
- [category in DictionaryCategory]?: Dictionary<Numeric>;
1
+ /* 0.5.0 */
2
+ import { IComputeEngine, Dictionary } from '../public';
3
+ export declare function getDefaultDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
4
+ export declare const DICTIONARIES: {
5
+ [category in DictionaryCategory]?: Readonly<Dictionary> | Readonly<Dictionary>[];
6
6
  };
7
7
  /**
8
- * Return a compiled and validated version of the dictionary.
8
+ * Set the dictionary of the current context (`engine.context`) to `dicts`
9
+ *
10
+ * `dicts` can be an array of dictionaries, in order to deal with circular
11
+ * dependencies: it is possible to partition a dictionary into multiple
12
+ * sub-dictionary, to control the order in which they are processe and
13
+ * avoid having expressions in the definition of an entry reference a symbol
14
+ * or function name that has not yet been added to the dictionary.
9
15
  *
10
16
  * Specifically:
11
- * - Expressions (for values, evaluate, domain, isElementOf, etc..) are compiled
12
- * when possible, put in canonical form otherwise
17
+ * - Expressions (for values, evaluate, domain, isElementOf, etc..) are boxed
13
18
  * - The domain of entries is inferred and validated:
14
19
  * - check that domains are in canonical form
15
- * - check that domains are consistent with declarations (for example that
16
- * the signature of predicate have a "MaybeBoolean" codomain)
20
+ * - check that domains are consistent with declarations
17
21
  *
18
22
  */
19
- export declare function compileDictionary<T extends number = Numeric>(dict: Dictionary<T>, engine: ComputeEngine<T>): CompiledDictionary<T>;
23
+ export declare function setCurrentContextDictionary(engine: IComputeEngine, dicts: Dictionary | Dictionary[] | undefined): void;
24
+ /**
25
+ * For debugging: a textual representation of the inheritance chain of sets.
26
+ */
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
1
+ /* 0.5.0 */
2
2
  export declare const LOGIC_DICTIONARY: Dictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const POLYNOMIALS_DICTIONARY: Dictionary[];
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const RELOP_DICTIONARY: Dictionary;
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
1
+ /* 0.5.0 */
2
2
  export declare const SETS_DICTIONARY: Dictionary;
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
2
- export declare const TRIGONOMETRY_DICTIONARY: Dictionary;
1
+ /* 0.5.0 */
2
+ export declare const TRIGONOMETRY_DICTIONARY: Dictionary[];
@@ -0,0 +1,30 @@
1
+ /* 0.5.0 */
2
+ import { Decimal } from 'decimal.js';
3
+ import { BoxedExpression } from './public';
4
+ /** Quickly determine the numeric domain of a number or constant
5
+ * For the symbols, this is a hard-coded optimization that doesn't rely on the
6
+ * dictionaries. The regular path is in `internalDomain()`
7
+ */
8
+ export declare function inferNumericDomain(value: number | Decimal | Complex | [numer: number, denom: number]): 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 declare 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
+ };
25
+ /**
26
+ * Return an efficient data structure describing a numeric domain,
27
+ * an `Interval` or `Range`
28
+ * @todo could also check for `Multiple`
29
+ */
30
+ export declare function inferNumericDomainInfo(expr: BoxedExpression): NumericDomainInfo | null;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -0,0 +1,4 @@
1
+ /* 0.5.0 */
2
+ import { LatexDictionary, Serializer } from '../public';
3
+ export declare function serializeLatex(serializer: Serializer, expr: Expression | null): string;
4
+ export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.5.0 */
2
+ export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;