@cortex-js/compute-engine 0.7.0 → 0.9.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.
- package/dist/compute-engine.esm.js +8291 -7307
- package/dist/compute-engine.min.esm.js +2 -2
- package/dist/compute-engine.min.js +2 -2
- package/dist/math-json.esm.js +41 -88
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -5
- package/dist/types/common/utils.d.ts +1 -0
- package/dist/types/compute-engine/assume.d.ts +6 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +67 -68
- package/dist/types/compute-engine/boxed-expression/box.d.ts +74 -16
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +10 -5
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -4
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +45 -36
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +22 -19
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +8 -7
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +6 -6
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +21 -15
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +9 -9
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +18 -0
- package/dist/types/compute-engine/compute-engine.d.ts +65 -35
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +2 -8
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -9
- package/dist/types/compute-engine/latex-syntax/public.d.ts +14 -6
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -3
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +5 -6
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +3 -2
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/domains.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/numerics/{numeric-decimal.d.ts → numeric-bignum.d.ts} +10 -6
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +10 -6
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +56 -0
- package/dist/types/compute-engine/public.d.ts +622 -506
- package/dist/types/compute-engine/rules.d.ts +7 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +17 -0
- package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/flatten.d.ts +2 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +30 -12
- package/dist/types/compute-engine/symbolic/sum.d.ts +13 -7
- package/dist/types/compute-engine/symbolic/utils.d.ts +7 -29
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +2 -2
- package/dist/types/math-json/utils.d.ts +11 -41
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.9.0 */
|
|
2
2
|
* The most important classes are {@link ComputeEngine} and
|
|
3
3
|
* {@link BoxedExpression}.
|
|
4
4
|
*
|
|
@@ -13,6 +13,7 @@ import type { SignalMessage, WarningSignal, WarningSignalHandler } from '../comm
|
|
|
13
13
|
import type { Expression, MathJsonDictionary, MathJsonFunction, MathJsonNumber, MathJsonString, MathJsonSymbol } from '../math-json/math-json-format';
|
|
14
14
|
import type { NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
|
|
15
15
|
export * from './latex-syntax/public';
|
|
16
|
+
export declare type Rational = [number, number] | [Decimal, Decimal];
|
|
16
17
|
/**
|
|
17
18
|
* Metadata that can be associated with a `BoxedExpression`
|
|
18
19
|
*/
|
|
@@ -23,18 +24,19 @@ export declare type Metadata = {
|
|
|
23
24
|
/**
|
|
24
25
|
* The numeric evaluation mode:
|
|
25
26
|
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
27
|
+
<div class=symbols-table>
|
|
28
|
+
|
|
29
|
+
| Mode | |
|
|
30
|
+
| :--- | :----- |
|
|
31
|
+
| `"auto"`| Use bignum or complex numbers. |
|
|
32
|
+
| `"machine"` | **IEEE 754-2008**, 64-bit floating point numbers: 52-bit mantissa, about 15 digits of precision |
|
|
33
|
+
| `"bignum"` | Arbitrary precision floating point numbers, as provided by the "decimal.js" library |
|
|
34
|
+
| `"complex"` | Complex number represented by two machine numbers, a real and an imaginary part, as provided by the "complex.js" library |
|
|
35
|
+
|
|
36
|
+
</div>
|
|
37
37
|
*/
|
|
38
|
+
export declare type NumericMode = 'auto' | 'machine' | 'bignum' | 'complex';
|
|
39
|
+
/** Options for `BoxedExpression.simplify()` */
|
|
38
40
|
export declare type SimplifyOptions = EvaluateOptions & {
|
|
39
41
|
recursive?: boolean;
|
|
40
42
|
rules?: BoxedRuleSet;
|
|
@@ -207,7 +209,14 @@ export declare type JsonSerializationOptions = {
|
|
|
207
209
|
*
|
|
208
210
|
* **Default**: `true`
|
|
209
211
|
*/
|
|
210
|
-
|
|
212
|
+
repeatingDecimals: boolean;
|
|
213
|
+
/** Number literals are serialized with this precision.
|
|
214
|
+
* If `"auto"`, the same precision as the compute engine calculations is used
|
|
215
|
+
* If `"max"`, all available digits are serialized
|
|
216
|
+
*
|
|
217
|
+
* **Default**: `"auto"`
|
|
218
|
+
*/
|
|
219
|
+
precision: 'auto' | 'max' | number;
|
|
211
220
|
};
|
|
212
221
|
/**
|
|
213
222
|
* **Theory of Operations**
|
|
@@ -231,584 +240,582 @@ export interface BoxedExpression {
|
|
|
231
240
|
readonly engine: IComputeEngine;
|
|
232
241
|
/** From `Object.valueOf()`, return a primitive value for the expression.
|
|
233
242
|
*
|
|
234
|
-
* If the expression is a machine number, or
|
|
243
|
+
* If the expression is a machine number, or bignum or rational that can be
|
|
235
244
|
* converted to a machine number, return a `number`.
|
|
236
245
|
*
|
|
237
|
-
* If the expression is a rational number, return `[number, number]`.
|
|
238
|
-
*
|
|
239
246
|
* If the expression is a symbol, return the name of the symbol as a `string`.
|
|
240
247
|
*
|
|
241
248
|
* Otherwise return a LaTeX representation of the expression.
|
|
242
249
|
*
|
|
243
|
-
* @category
|
|
250
|
+
* @category Primitive Methods
|
|
244
251
|
*/
|
|
245
|
-
valueOf(): number | string |
|
|
252
|
+
valueOf(): number | string | boolean;
|
|
246
253
|
/** From `Object.toString()`, return a LaTeX representation of the expression.
|
|
247
254
|
*
|
|
248
|
-
*
|
|
255
|
+
* Used when coercing a `BoxedExpression` to a `String`.
|
|
256
|
+
*
|
|
257
|
+
* @category Primitive Methods
|
|
249
258
|
*/
|
|
250
259
|
toString(): string;
|
|
251
|
-
/**
|
|
252
|
-
*
|
|
253
|
-
* @category Object Methods
|
|
260
|
+
/** Similar to`expr.valueOf()` but includes a hint.
|
|
261
|
+
* @category Primitive Methods
|
|
254
262
|
*/
|
|
255
|
-
|
|
256
|
-
/**
|
|
263
|
+
[Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
|
|
264
|
+
/** Used by `JSON.stringify()` to serialize this object to JSON.
|
|
257
265
|
*
|
|
258
|
-
*
|
|
266
|
+
* Method version of `expr.json`.
|
|
259
267
|
*
|
|
268
|
+
* @category Primitive Methods
|
|
260
269
|
*/
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
get hash(): number;
|
|
264
|
-
/** An optional short description of the symbol or function head.
|
|
265
|
-
*
|
|
266
|
-
* May include markdown. Each string is a paragraph. */
|
|
267
|
-
readonly description: string[];
|
|
268
|
-
/** An optional URL pointing to more information about the symbol or function head */
|
|
269
|
-
readonly url: string;
|
|
270
|
-
/** All boxed expressions have a head.
|
|
270
|
+
toJSON(): Expression;
|
|
271
|
+
/** If `true`, this expression is in a canonical form.
|
|
271
272
|
*
|
|
272
|
-
*
|
|
273
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
273
274
|
*
|
|
274
|
-
* If the head expression can be represented as a string, it is returned
|
|
275
|
-
* as a string.
|
|
276
|
-
*/
|
|
277
|
-
get head(): BoxedExpression | string;
|
|
278
|
-
/**
|
|
279
|
-
* If `this.isPure` is `true`, this is a synonym for `this.evaluate()`.
|
|
280
|
-
* Otherwise, it returns `undefined`.
|
|
281
|
-
*/
|
|
282
|
-
get value(): BoxedExpression | undefined;
|
|
283
|
-
/** Only the value of variables can be changed (symbols that are not constants) */
|
|
284
|
-
set value(value: BoxedExpression | number | undefined);
|
|
285
|
-
/** An approximation of the value of this expression. Floating-point
|
|
286
|
-
* operations may be performed.
|
|
287
|
-
*
|
|
288
|
-
* Just like `this.value`, it returns `undefined` for impure expressions.
|
|
289
|
-
*/
|
|
290
|
-
get numericValue(): BoxedExpression | undefined;
|
|
291
|
-
/** If true, the value of the expression never changes and evaluating it has
|
|
292
|
-
* no side-effects.
|
|
293
|
-
* If false, the value of the expression may change, if the
|
|
294
|
-
* value of other expression changes or for other reasons.
|
|
295
|
-
*
|
|
296
|
-
* If `this.isPure` is `false`, `this.value` is undefined. Call
|
|
297
|
-
* `this.evaluate()` to determine the value of the expression instead.
|
|
298
|
-
*
|
|
299
|
-
* As an example, the `Random` function is not pure.
|
|
300
275
|
*/
|
|
301
|
-
get isPure(): boolean;
|
|
302
|
-
/** True if the expression is a free variable, that is a symbol with no value */
|
|
303
|
-
get isFree(): boolean;
|
|
304
|
-
/** True if the expression is a constant, that is a symbol with an immutable value */
|
|
305
|
-
get isConstant(): boolean;
|
|
306
|
-
/**
|
|
307
|
-
* If `true`, this expression represents a value that was not calculated
|
|
308
|
-
* or that does not reference another expression.
|
|
309
|
-
* This means the expression is either a number, a string or a dictionary.
|
|
310
|
-
* Functions and symbols are not literals.
|
|
311
|
-
*/
|
|
312
|
-
get isLiteral(): boolean;
|
|
313
|
-
/** If `true`, this expression is in a canonical form */
|
|
314
276
|
get isCanonical(): boolean;
|
|
315
277
|
/** For internal use only, set when a canonical expression is created.
|
|
316
278
|
* @internal
|
|
317
279
|
*/
|
|
318
280
|
set isCanonical(val: boolean);
|
|
319
|
-
/**
|
|
320
|
-
getSubexpressions(head: string): BoxedExpression[];
|
|
321
|
-
/** All the subexpressions in this expression, recursively */
|
|
322
|
-
get subexpressions(): BoxedExpression[];
|
|
323
|
-
/** All the symbols in the expression, recursively */
|
|
324
|
-
get symbols(): BoxedExpression[];
|
|
325
|
-
/** All the `["Error"]` subexpressions */
|
|
326
|
-
get errors(): BoxedExpression[];
|
|
327
|
-
/** `ops` is the list of arguments of the function, its "tail"
|
|
281
|
+
/** MathJSON representation of this expression.
|
|
328
282
|
*
|
|
329
|
-
*
|
|
283
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
330
284
|
*
|
|
331
285
|
*/
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* is a function, check if `this.ops !== null` instead.
|
|
337
|
-
*
|
|
338
|
-
* @category Function Expression
|
|
339
|
-
*
|
|
286
|
+
readonly json: Expression;
|
|
287
|
+
/**
|
|
288
|
+
* The scope in which this expression has been defined.
|
|
289
|
+
* Is null when the expression is not canonical.
|
|
340
290
|
*/
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
* @category Function Expression
|
|
291
|
+
readonly scope: RuntimeScope | null;
|
|
292
|
+
/** From `Object.is()`. Equivalent to `BoxedExpression.isSame()`
|
|
346
293
|
*
|
|
294
|
+
* @category Primitive Methods
|
|
347
295
|
*
|
|
348
296
|
*/
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
|
|
297
|
+
is(rhs: unknown): boolean;
|
|
298
|
+
/** @internal */
|
|
299
|
+
readonly hash: number;
|
|
300
|
+
/** LaTeX representation of this expression.
|
|
352
301
|
*
|
|
353
|
-
*
|
|
302
|
+
* The serialization can be customized with `ComputeEngine.latexOptions`
|
|
354
303
|
*
|
|
304
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
355
305
|
*
|
|
356
306
|
*/
|
|
357
|
-
get
|
|
358
|
-
/**
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* @category Function Expression
|
|
362
|
-
*
|
|
307
|
+
get latex(): LatexString;
|
|
308
|
+
/**
|
|
363
309
|
*
|
|
310
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
311
|
+
* @internal
|
|
364
312
|
*/
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
*
|
|
368
|
-
* If this expression not a dictionary, return `null`
|
|
313
|
+
set latex(val: string);
|
|
314
|
+
/** If this expression is a symbol, return the name of the symbol as a string.
|
|
315
|
+
* Otherwise, return `null`.
|
|
369
316
|
*
|
|
370
|
-
*
|
|
317
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
318
|
+
|
|
319
|
+
* @category Symbol Expression
|
|
371
320
|
*
|
|
372
321
|
*/
|
|
373
|
-
|
|
322
|
+
readonly symbol: string | null;
|
|
374
323
|
/**
|
|
324
|
+
* If this is the `Nothing` symbol, return `true`.
|
|
375
325
|
*
|
|
376
|
-
*
|
|
326
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
377
327
|
*/
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
*
|
|
328
|
+
readonly isNothing: boolean;
|
|
329
|
+
/** If this expression is a string, return the value of the string.
|
|
330
|
+
* Otherwise, return `null`.
|
|
381
331
|
*
|
|
382
|
-
*
|
|
332
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
333
|
+
|
|
334
|
+
* @category String Expression
|
|
383
335
|
*
|
|
384
336
|
*/
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* If this expression is a dictionary, return true if the dictionary has a
|
|
388
|
-
* `key` entry.
|
|
337
|
+
readonly string: string | null;
|
|
338
|
+
/** All the subexpressions matching the head
|
|
389
339
|
*
|
|
390
|
-
*
|
|
340
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
391
341
|
*
|
|
392
342
|
*/
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Return the value of this number or symbol, if stored as a machine number.
|
|
343
|
+
getSubexpressions(head: string): BoxedExpression[];
|
|
344
|
+
/** All the subexpressions in this expression, recursively
|
|
396
345
|
*
|
|
397
|
-
* Note
|
|
398
|
-
* For example, when a symbol has been defined with an assumption.
|
|
346
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
399
347
|
*
|
|
400
|
-
|
|
401
|
-
|
|
348
|
+
*/
|
|
349
|
+
readonly subexpressions: BoxedExpression[];
|
|
350
|
+
/** All the symbols in the expression, recursively
|
|
402
351
|
*
|
|
403
|
-
*
|
|
352
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
404
353
|
*
|
|
405
354
|
*/
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Otherwise, return `[null, null]`.
|
|
409
|
-
*
|
|
410
|
-
* If `rationalValue` is not `[null, null]`, then `machineValue`, `decimalValue`
|
|
411
|
-
* and `complexValue` are `null.
|
|
355
|
+
readonly symbols: BoxedExpression[];
|
|
356
|
+
/** All the `["Error"]` subexpressions
|
|
412
357
|
*
|
|
413
|
-
*
|
|
358
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
414
359
|
*
|
|
415
360
|
*/
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Otherwise, return `null`.
|
|
419
|
-
*
|
|
420
|
-
* A `Decimal` number is an arbitrarily long floating point number.
|
|
361
|
+
readonly errors: BoxedExpression[];
|
|
362
|
+
/** All boxed expressions have a head.
|
|
421
363
|
*
|
|
422
|
-
* If
|
|
423
|
-
* and `complexValue` are `null` and `rationalValue` is `[null, null]`.
|
|
364
|
+
* If not a function this can be `Symbol`, `String`, `Number` or `Dictionary`.
|
|
424
365
|
*
|
|
425
|
-
*
|
|
366
|
+
* If the head expression can be represented as a string, it is returned
|
|
367
|
+
* as a string.
|
|
426
368
|
*
|
|
369
|
+
* **Note** applicable to canonical and non-canonical expressions. The head
|
|
370
|
+
* of a non-canonical expression may be different than the head of its
|
|
371
|
+
* canonical counterpart. For example the canonical counterpart of `["Divide", 5, 7]` is `["Rational", 5, 5]`.
|
|
427
372
|
*/
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Otherwise, return `null`.
|
|
373
|
+
readonly head: BoxedExpression | string;
|
|
374
|
+
/** The list of arguments of the function, its "tail".
|
|
431
375
|
*
|
|
432
|
-
* If
|
|
433
|
-
* and `decimalValue` are `null.
|
|
376
|
+
* If the expression is not a function, return `null`.
|
|
434
377
|
*
|
|
435
|
-
*
|
|
378
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
436
379
|
*
|
|
380
|
+
* @category Function Expression
|
|
437
381
|
*
|
|
438
382
|
*/
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* a 64-bit floating point number.
|
|
383
|
+
readonly ops: null | BoxedExpression[];
|
|
384
|
+
/** If this expression is a function, the number of operands, otherwise 0.
|
|
442
385
|
*
|
|
443
|
-
*
|
|
386
|
+
* Note that a function can have 0 operands, so to check if this expression
|
|
387
|
+
* is a function, check if `this.ops !== null` instead.
|
|
444
388
|
*
|
|
445
|
-
*
|
|
446
|
-
* denominator.
|
|
389
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
447
390
|
*
|
|
448
|
-
*
|
|
449
|
-
* number, return this value. There might be a small loss of precision due
|
|
450
|
-
* to the limitations of the binary representation of numbers as machine
|
|
451
|
-
* numbers.
|
|
391
|
+
* @category Function Expression
|
|
452
392
|
*
|
|
453
|
-
|
|
454
|
-
|
|
393
|
+
*/
|
|
394
|
+
readonly nops: number;
|
|
395
|
+
/** First operand, i.e.`this.ops[0]`
|
|
455
396
|
*
|
|
456
|
-
*
|
|
397
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
398
|
+
*
|
|
399
|
+
* @category Function Expression
|
|
457
400
|
*
|
|
458
401
|
*
|
|
459
402
|
*/
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* If the value of this expression is an integer with a 'small' absolute value,
|
|
463
|
-
* return this value. Otherwise, return `null`.
|
|
403
|
+
readonly op1: BoxedExpression;
|
|
404
|
+
/** Second operand, i.e.`this.ops[1]`
|
|
464
405
|
*
|
|
465
|
-
*
|
|
466
|
-
* performed if they are safe from overflow. This method makes it easy
|
|
467
|
-
* to check for this, whether the value is a Decimal or a number.
|
|
406
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
468
407
|
*
|
|
469
|
-
*
|
|
408
|
+
* @category Function Expression
|
|
470
409
|
*
|
|
471
|
-
* @category Numeric Expression
|
|
472
410
|
*
|
|
473
411
|
*/
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* If the value of this an expression is a small integer or a rational,
|
|
477
|
-
* return this value. Otherwise, return `[null, null`].
|
|
412
|
+
readonly op2: BoxedExpression;
|
|
413
|
+
/** Third operand, i.e. `this.ops[2]`
|
|
478
414
|
*
|
|
479
|
-
*
|
|
415
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
480
416
|
*
|
|
481
|
-
|
|
482
|
-
get asRational(): [number, number] | [null, null];
|
|
483
|
-
/**
|
|
484
|
-
* Return the following, depending on the value of this expression:
|
|
417
|
+
* @category Function Expression
|
|
485
418
|
*
|
|
486
|
-
* * `-1` if it is < 0
|
|
487
|
-
* * `0` if it is = 0
|
|
488
|
-
* * `+1` if it is > 0
|
|
489
|
-
* * `undefined` this value may be positive, negative or zero. We don't know
|
|
490
|
-
* right now (a symbol with an Integer domain, but no currently assigned
|
|
491
|
-
* value, for example)
|
|
492
|
-
* * `null` this value will never be positive, negative or zero (`NaN`,
|
|
493
|
-
* a string or a complex number for example)
|
|
494
419
|
*
|
|
495
|
-
|
|
496
|
-
|
|
420
|
+
*/
|
|
421
|
+
readonly op3: BoxedExpression;
|
|
422
|
+
/** `true` if this expression or any of its subexpressions is an `["Error"]`
|
|
423
|
+
* expression.
|
|
497
424
|
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
425
|
+
* **Note** applicable to canonical and non-canonical expressions. For
|
|
426
|
+
* non-canonical expression, this may indicate a syntax error while parsing
|
|
427
|
+
* LaTeX. For canonical expression, this may indicate argument domain
|
|
428
|
+
* mismatch, or missing or unexpected arguments.
|
|
501
429
|
*
|
|
502
|
-
* @category
|
|
430
|
+
* @category Symbol Expression
|
|
503
431
|
*
|
|
504
432
|
*/
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
*
|
|
433
|
+
readonly isValid: boolean;
|
|
434
|
+
/**
|
|
435
|
+
* If `true`, this expression represents a value that was not calculated
|
|
436
|
+
* and that does not reference another expression.
|
|
508
437
|
*
|
|
509
|
-
*
|
|
438
|
+
* This means the expression is either a number, a string or a dictionary.
|
|
439
|
+
* Functions and symbols are not literals.
|
|
510
440
|
*
|
|
441
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
511
442
|
*/
|
|
512
|
-
|
|
443
|
+
readonly isLiteral: boolean;
|
|
513
444
|
/**
|
|
514
|
-
*
|
|
515
|
-
|
|
516
|
-
get isNothing(): boolean;
|
|
517
|
-
/** `true` if this expression or any subexpression is an `["Error"]`
|
|
518
|
-
* expression.
|
|
445
|
+
* An exact value is not further transformed when evaluated. To get an
|
|
446
|
+
* approximate evaluation of an exact value, use `.N()`.
|
|
519
447
|
*
|
|
520
|
-
*
|
|
448
|
+
* Non-exact values includes:
|
|
449
|
+
* - numbers with a fractional part
|
|
450
|
+
* - complex numbers with a real or imaginary fractional part
|
|
521
451
|
*
|
|
522
452
|
*/
|
|
523
|
-
|
|
524
|
-
/** If
|
|
525
|
-
*
|
|
453
|
+
readonly isExact: boolean;
|
|
454
|
+
/** If true, the value of the expression never changes and evaluating it has
|
|
455
|
+
* no side-effects.
|
|
456
|
+
* If false, the value of the expression may change, if the
|
|
457
|
+
* value of other expression changes or for other reasons.
|
|
526
458
|
*
|
|
527
|
-
*
|
|
459
|
+
* If `this.isPure` is `false`, `this.value` is undefined. Call
|
|
460
|
+
* `this.evaluate()` to determine the value of the expression instead.
|
|
528
461
|
*
|
|
462
|
+
* As an example, the `Random` function is not pure.
|
|
463
|
+
*
|
|
464
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
529
465
|
*/
|
|
530
|
-
|
|
531
|
-
/**
|
|
466
|
+
readonly isPure: boolean;
|
|
467
|
+
/** True if the expression is a free variable, that is a symbol with no value */
|
|
468
|
+
readonly isFree: boolean;
|
|
469
|
+
/** True if the expression is a constant, that is a symbol with an immutable value */
|
|
470
|
+
readonly isConstant: boolean;
|
|
471
|
+
/**
|
|
472
|
+
* Return the canonical form of this expression.
|
|
532
473
|
*
|
|
533
|
-
*
|
|
474
|
+
* If this is a function expressin, a definition is associated with the
|
|
475
|
+
* canonical expression.
|
|
534
476
|
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
477
|
+
* When determining the canonical form the following function definition
|
|
478
|
+
* flags are applied:
|
|
479
|
+
* - `associative`: \\( f(a, f(b), c) \longrightarrow f(a, b, c) \\)
|
|
480
|
+
* - `idempotent`: \\( f(f(a)) \longrightarrow f(a) \\)
|
|
481
|
+
* - `involution`: \\( f(f(a)) \longrightarrow a \\)
|
|
482
|
+
* - `commutative`: sort the arguments.
|
|
483
|
+
*
|
|
484
|
+
* If his expression is already canonical, the value of canonical is
|
|
485
|
+
* `this`.
|
|
537
486
|
*
|
|
538
|
-
* @category Expression Properties
|
|
539
487
|
*/
|
|
540
|
-
get
|
|
541
|
-
/**
|
|
488
|
+
get canonical(): BoxedExpression;
|
|
489
|
+
/**
|
|
490
|
+
* If this expression is a function, apply the function `fn` to all its operands.
|
|
542
491
|
*
|
|
492
|
+
* Replace the head of this expression with `head`, if defined.
|
|
543
493
|
*
|
|
544
|
-
*
|
|
494
|
+
* If this expression is a dictionary, return a new dictionary with the values
|
|
495
|
+
* modified by `fn`.
|
|
545
496
|
*
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
/** The value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
|
|
497
|
+
* If `head` is provided, return a function expression with the modified
|
|
498
|
+
* dictionary as operand, otherwise return the modified dictionary.
|
|
549
499
|
*
|
|
550
|
-
* Note
|
|
500
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
551
501
|
*
|
|
502
|
+
* */
|
|
503
|
+
apply(fn: (x: BoxedExpression) => SemiBoxedExpression, head?: string): BoxedExpression;
|
|
504
|
+
/**
|
|
505
|
+
* Replace all the symbols in the expression as indicated.
|
|
552
506
|
*
|
|
553
|
-
*
|
|
507
|
+
* Note the same effect can be achieved with `this.replace()`, but
|
|
508
|
+
* using `this.subs()` is more efficient, and simpler.
|
|
509
|
+
*
|
|
510
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
554
511
|
*
|
|
555
512
|
*/
|
|
556
|
-
|
|
513
|
+
subs(sub: Substitution, options?: {
|
|
514
|
+
canonical?: boolean;
|
|
515
|
+
}): BoxedExpression;
|
|
557
516
|
/**
|
|
558
|
-
*
|
|
559
|
-
*
|
|
517
|
+
* Transform the expression by applying the rules:
|
|
518
|
+
* if the `lhs` of a rule matches, it is replaced by its `rhs`.
|
|
560
519
|
*
|
|
561
|
-
*
|
|
520
|
+
* If no rules apply, return `null`.
|
|
562
521
|
*
|
|
563
|
-
*
|
|
522
|
+
* See also `subs` for a simple substitution.
|
|
564
523
|
*
|
|
565
524
|
*
|
|
566
|
-
*
|
|
525
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
567
526
|
*
|
|
568
527
|
*/
|
|
569
|
-
|
|
528
|
+
replace(rules: BoxedRuleSet, options?: ReplaceOptions): null | BoxedExpression;
|
|
570
529
|
/**
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
* `isFinite && !isImaginary`
|
|
574
|
-
*
|
|
530
|
+
* True if the expression includes a symbol `v` or a function head `v`.
|
|
575
531
|
*
|
|
576
|
-
*
|
|
532
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
577
533
|
*/
|
|
578
|
-
|
|
579
|
-
/**
|
|
534
|
+
has(v: string | string[]): boolean;
|
|
535
|
+
/** Structural/symbolic equality (weak equality).
|
|
580
536
|
*
|
|
581
|
-
* `
|
|
537
|
+
* `ce.parse('1+x').isSame(ce.parse('x+1'))` is `false`
|
|
582
538
|
*
|
|
539
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
583
540
|
*
|
|
584
|
-
* @category
|
|
541
|
+
* @category Relational Operator
|
|
585
542
|
*/
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* The value of this expression is a number, but not `NaN` or any Infinity
|
|
543
|
+
isSame(rhs: BoxedExpression): boolean;
|
|
544
|
+
/** Attempt to match this expression to the `rhs` expression.
|
|
589
545
|
*
|
|
590
|
-
* `
|
|
546
|
+
* If `rhs` does not match, return `null`.
|
|
591
547
|
*
|
|
548
|
+
* Otherwise return an object literal.
|
|
592
549
|
*
|
|
593
|
-
*
|
|
550
|
+
* If this expression includes wildcards (symbols with a name that starts
|
|
551
|
+
* with `_`), the object literal will include a prop for each matching named
|
|
552
|
+
* wildcard.
|
|
594
553
|
*
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
/** `isReal || isImaginary || isInfinity`
|
|
554
|
+
* If `rhs` matches this pattern but there are no named wildcards, return
|
|
555
|
+
* the empty object literal, `{}`.
|
|
598
556
|
*
|
|
557
|
+
* **Note** applicable to canonical and non-canonical expressions.
|
|
599
558
|
*
|
|
600
|
-
* @category Expression Properties
|
|
601
559
|
*/
|
|
602
|
-
|
|
603
|
-
/**
|
|
560
|
+
match(rhs: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
|
|
561
|
+
/**
|
|
562
|
+
* "Not a Number".
|
|
563
|
+
*
|
|
564
|
+
* A value representing undefined result of computations, such as `0/0`,
|
|
565
|
+
* as per the floating point format standard IEEE-754.
|
|
604
566
|
*
|
|
567
|
+
* Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
|
|
568
|
+
* number).
|
|
605
569
|
*
|
|
606
570
|
* @category Expression Properties
|
|
571
|
+
*
|
|
607
572
|
*/
|
|
608
|
-
|
|
573
|
+
readonly isNaN: boolean | undefined;
|
|
609
574
|
/**
|
|
575
|
+
* The numeric value of this expression is 0.
|
|
576
|
+
*
|
|
610
577
|
* @category Expression Properties
|
|
611
578
|
*/
|
|
612
|
-
|
|
579
|
+
readonly isZero: boolean | undefined;
|
|
613
580
|
/**
|
|
581
|
+
* The numeric value of this expression is not 0.
|
|
614
582
|
* @category Expression Properties
|
|
615
583
|
*/
|
|
616
|
-
|
|
584
|
+
readonly isNotZero: boolean | undefined;
|
|
617
585
|
/**
|
|
586
|
+
* The numeric value of this expression is not 1.
|
|
618
587
|
* @category Expression Properties
|
|
619
588
|
*/
|
|
620
|
-
|
|
589
|
+
readonly isOne: boolean | undefined;
|
|
621
590
|
/**
|
|
591
|
+
* The numeric value of this expression is not -1.
|
|
622
592
|
* @category Expression Properties
|
|
623
593
|
*/
|
|
624
|
-
|
|
625
|
-
/** ±Infinity or Complex Infinity
|
|
626
|
-
*
|
|
627
|
-
* @category Expression Properties
|
|
628
|
-
*/
|
|
629
|
-
get isInfinity(): boolean | undefined;
|
|
630
|
-
/**
|
|
631
|
-
* "Not a Number".
|
|
632
|
-
*
|
|
633
|
-
* A value representing undefined result of computations, such as `0/0`,
|
|
634
|
-
* as per the floating point format standard IEEE-754.
|
|
635
|
-
*
|
|
636
|
-
* Note that if `isNaN` is true, `isNumber` is also true (yes, `NaN` is a
|
|
637
|
-
* number).
|
|
594
|
+
readonly isNegativeOne: boolean | undefined;
|
|
595
|
+
/** The numeric value of this expression is ±Infinity or Complex Infinity
|
|
638
596
|
*
|
|
639
597
|
* @category Expression Properties
|
|
640
|
-
*
|
|
641
598
|
*/
|
|
642
|
-
|
|
599
|
+
readonly isInfinity: boolean | undefined;
|
|
643
600
|
/** This expression is a number, but not ±Infinity and not `NaN`
|
|
644
601
|
*
|
|
645
602
|
* @category Expression Properties
|
|
646
603
|
*/
|
|
647
|
-
|
|
604
|
+
readonly isFinite: boolean | undefined;
|
|
648
605
|
/**
|
|
649
606
|
* @category Expression Properties
|
|
650
607
|
*/
|
|
651
|
-
|
|
608
|
+
readonly isEven: boolean | undefined;
|
|
652
609
|
/**
|
|
653
610
|
* @category Expression Properties
|
|
654
611
|
*/
|
|
655
|
-
|
|
612
|
+
readonly isOdd: boolean | undefined;
|
|
656
613
|
/**
|
|
657
614
|
* @category Expression Properties
|
|
658
615
|
*/
|
|
659
|
-
|
|
616
|
+
readonly isPrime: boolean | undefined;
|
|
660
617
|
/**
|
|
661
618
|
* @category Expression Properties
|
|
662
619
|
*/
|
|
663
|
-
|
|
664
|
-
/**
|
|
620
|
+
readonly isComposite: boolean | undefined;
|
|
621
|
+
/**
|
|
622
|
+
* Return the value of this expression, if a number literal.
|
|
665
623
|
*
|
|
666
|
-
* `
|
|
624
|
+
* Note it is possible for `numericValue` to be `null`, and for `isNotZero`
|
|
625
|
+
* to be true. For example, when a symbol has been defined with an assumption.
|
|
626
|
+
*
|
|
627
|
+
* @category Numeric Expression
|
|
667
628
|
*
|
|
668
|
-
* @category Relational Operator
|
|
669
629
|
*/
|
|
670
|
-
|
|
630
|
+
readonly numericValue: number | Decimal | Complex | Rational | null;
|
|
671
631
|
/**
|
|
672
|
-
*
|
|
673
|
-
*/
|
|
674
|
-
has(v: string | string[]): boolean;
|
|
675
|
-
/** Attempt to match this expression to the `rhs` expression.
|
|
676
|
-
*
|
|
677
|
-
* If `rhs` does not match, return `null`.
|
|
678
|
-
*
|
|
679
|
-
* Otherwise return an object literal.
|
|
632
|
+
* Return the following, depending on the value of this expression:
|
|
680
633
|
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
634
|
+
* * `-1` if it is < 0
|
|
635
|
+
* * `0` if it is = 0
|
|
636
|
+
* * `+1` if it is > 0
|
|
637
|
+
* * `undefined` this value may be positive, negative or zero. We don't know
|
|
638
|
+
* right now (a symbol with an Integer domain, but no currently assigned
|
|
639
|
+
* value, for example)
|
|
640
|
+
* * `null` this value will never be positive, negative or zero (`NaN`,
|
|
641
|
+
* a string or a complex number for example)
|
|
684
642
|
*
|
|
685
|
-
*
|
|
686
|
-
* the
|
|
687
|
-
*/
|
|
688
|
-
match(rhs: BoxedExpression, options?: PatternMatchOption): Substitution | null;
|
|
689
|
-
/** Mathematical equality (strong equality), that is the value
|
|
690
|
-
* of this expression and of `rhs` are numerically equal.
|
|
643
|
+
* Note that complex numbers have no natural ordering,
|
|
644
|
+
* so if the value is a complex number, `sgn` is either 0, or `null`
|
|
691
645
|
*
|
|
692
|
-
*
|
|
646
|
+
* If a symbol, this does take assumptions into account, that is `this.sgn`
|
|
647
|
+
* will return `1` if `isPositive` is `true`, even if this expression has
|
|
648
|
+
* no value
|
|
693
649
|
*
|
|
694
|
-
*
|
|
695
|
-
* considered equal. This tolerance is set when the `engine.precision` is
|
|
696
|
-
* changed to be such that the last two digits are ignored.
|
|
650
|
+
* @category Numeric Expression
|
|
697
651
|
*
|
|
698
|
-
* @category Relational Operator
|
|
699
652
|
*/
|
|
700
|
-
|
|
653
|
+
readonly sgn: -1 | 0 | 1 | undefined | null;
|
|
701
654
|
/** If the expressions cannot be compared, return `undefined`
|
|
655
|
+
*
|
|
656
|
+
* The numeric value of both expressions are compared.
|
|
702
657
|
*
|
|
703
658
|
* @category Relational Operator
|
|
704
659
|
*/
|
|
705
660
|
isLess(rhs: BoxedExpression): boolean | undefined;
|
|
706
661
|
/**
|
|
662
|
+
* The numeric value of both expressions are compared.
|
|
707
663
|
* @category Relational Operator
|
|
708
664
|
*/
|
|
709
665
|
isLessEqual(rhs: BoxedExpression): boolean | undefined;
|
|
710
666
|
/**
|
|
667
|
+
* The numeric value of both expressions are compared.
|
|
711
668
|
* @category Relational Operator
|
|
712
669
|
*/
|
|
713
670
|
isGreater(rhs: BoxedExpression): boolean | undefined;
|
|
714
671
|
/**
|
|
672
|
+
* The numeric value of both expressions are compared.
|
|
715
673
|
* @category Relational Operator
|
|
716
674
|
*/
|
|
717
675
|
isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
|
|
718
|
-
/** The value of this expression is > 0, same as `isGreater(0)`
|
|
676
|
+
/** The numeric value of this expression is > 0, same as `isGreater(0)`
|
|
719
677
|
*
|
|
720
678
|
* @category Expression Properties
|
|
721
679
|
*/
|
|
722
|
-
|
|
723
|
-
/** The value of this expression is >= 0, same as `isGreaterEqual(0)`
|
|
680
|
+
readonly isPositive: boolean | undefined;
|
|
681
|
+
/** The numeric value of this expression is >= 0, same as `isGreaterEqual(0)`
|
|
724
682
|
*
|
|
725
683
|
* @category Expression Properties
|
|
726
684
|
*/
|
|
727
|
-
|
|
728
|
-
/** The value of this expression is < 0, same as `isLess(0)`
|
|
685
|
+
readonly isNonNegative: boolean | undefined;
|
|
686
|
+
/** The numeric value of this expression is < 0, same as `isLess(0)`
|
|
729
687
|
*
|
|
730
688
|
* @category Expression Properties
|
|
731
689
|
*/
|
|
732
|
-
|
|
733
|
-
/** The value of this expression is <= 0, same as `isLessEqual(0)`
|
|
690
|
+
readonly isNegative: boolean | undefined;
|
|
691
|
+
/** The numeric value of this expression is <= 0, same as `isLessEqual(0)`
|
|
734
692
|
*
|
|
735
693
|
* @category Expression Properties
|
|
736
694
|
*/
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
695
|
+
readonly isNonPositive: boolean | undefined;
|
|
696
|
+
/** The keys of the dictionary.
|
|
697
|
+
*
|
|
698
|
+
* If this expression not a dictionary, return `null`
|
|
699
|
+
*
|
|
700
|
+
* @category Dictionary Expression
|
|
701
|
+
*
|
|
702
|
+
*/
|
|
703
|
+
readonly keys: IterableIterator<string> | null;
|
|
704
|
+
/**
|
|
705
|
+
*
|
|
706
|
+
* @category Dictionary Expression
|
|
707
|
+
*/
|
|
708
|
+
readonly keysCount: number;
|
|
709
|
+
/**
|
|
710
|
+
* If this expression is a dictionary, return the value of the `key` entry.
|
|
711
|
+
*
|
|
712
|
+
* @category Dictionary Expression
|
|
713
|
+
*
|
|
714
|
+
*/
|
|
715
|
+
getKey(key: string): BoxedExpression | undefined;
|
|
716
|
+
/**
|
|
717
|
+
* If this expression is a dictionary, return true if the
|
|
718
|
+
* dictionary has a `key` entry.
|
|
719
|
+
*
|
|
720
|
+
* @category Dictionary Expression
|
|
721
|
+
*
|
|
722
|
+
*/
|
|
723
|
+
hasKey(key: string): boolean;
|
|
724
|
+
/** Wikidata identifier.
|
|
725
|
+
*
|
|
726
|
+
* **Note** `undefined` if not a canonical expression.
|
|
727
|
+
*
|
|
728
|
+
*
|
|
729
|
+
*/
|
|
730
|
+
get wikidata(): string | undefined;
|
|
731
|
+
set wikidata(val: string | undefined);
|
|
732
|
+
/** An optional short description if the symbol or function head.
|
|
733
|
+
*
|
|
734
|
+
* May include markdown. Each string is a paragraph.
|
|
735
|
+
*
|
|
736
|
+
* **Note** `undefined` if not a canonical expression.
|
|
737
|
+
*
|
|
738
|
+
*/
|
|
739
|
+
readonly description: undefined | string[];
|
|
740
|
+
/** An optional URL pointing to more information about the symbol or
|
|
741
|
+
* function head
|
|
742
|
+
*
|
|
743
|
+
* **Note** `undefined` if not a canonical expression.
|
|
744
|
+
*
|
|
745
|
+
*/
|
|
746
|
+
readonly url: string | undefined;
|
|
746
747
|
/** Expressions with a higher complexity score are sorted
|
|
747
748
|
* first in commutative functions
|
|
749
|
+
*
|
|
750
|
+
* **Note** `undefined` if not a canonical expression.
|
|
748
751
|
*/
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
*
|
|
752
|
-
*
|
|
752
|
+
readonly complexity: number | undefined;
|
|
753
|
+
/**
|
|
754
|
+
* For symbols and functions, a possible definition associated with the
|
|
755
|
+
* expression. `basedDefinition` is the base class of symbol and function
|
|
756
|
+
* definition.
|
|
757
|
+
*
|
|
758
|
+
* **Note** `undefined` if not a canonical expression.
|
|
759
|
+
*
|
|
753
760
|
*/
|
|
754
|
-
|
|
755
|
-
/** Symbols that represent a variable (or a function name), can have their
|
|
756
|
-
* domain modified */
|
|
757
|
-
set domain(domain: BoxedDomain | string);
|
|
761
|
+
readonly basedDefinition: BoxedBaseDefinition | undefined;
|
|
758
762
|
/**
|
|
759
|
-
*
|
|
760
|
-
* or `defaultDomain`. If no domain has been explicitly set via assignment
|
|
761
|
-
* or via an `.assume()` directive, the `expr.explicitDomain` is `null.
|
|
763
|
+
* For functions, a possible definition associated with the expression.
|
|
762
764
|
*
|
|
763
|
-
*
|
|
765
|
+
* **Note** `undefined` if not a canonical expression or not a function.
|
|
764
766
|
*
|
|
765
|
-
* In most cases you'll want to use `.domain` instead.
|
|
766
767
|
*/
|
|
767
|
-
|
|
768
|
-
/** For symbols and functions, a possible definition associated with the
|
|
769
|
-
* expression. `basedDefinition` is the base class of symbol and function
|
|
770
|
-
* definition. */
|
|
771
|
-
get basedDefinition(): BoxedBaseDefinition | undefined;
|
|
772
|
-
get functionDefinition(): BoxedFunctionDefinition | undefined;
|
|
773
|
-
get symbolDefinition(): BoxedSymbolDefinition | undefined;
|
|
768
|
+
readonly functionDefinition: BoxedFunctionDefinition | undefined;
|
|
774
769
|
/**
|
|
775
|
-
*
|
|
770
|
+
* For symbols, a possible definition associated with the expression.
|
|
776
771
|
*
|
|
777
|
-
*
|
|
778
|
-
* - `associative`: \\( f(a, f(b), c) \longrightarrow f(a, b, c) \\)
|
|
779
|
-
* - `idempotent`: \\( f(f(a)) \longrightarrow f(a) \\)
|
|
780
|
-
* - `involution`: \\( f(f(a)) \longrightarrow a \\)
|
|
781
|
-
* - `commutative`: sort the arguments.
|
|
772
|
+
* **Note** `undefined` if not a symbol
|
|
782
773
|
*
|
|
783
|
-
|
|
784
|
-
|
|
774
|
+
*/
|
|
775
|
+
readonly symbolDefinition: BoxedSymbolDefinition | undefined;
|
|
776
|
+
/**
|
|
777
|
+
* The domain of this expression, without accounting for any inferred domain
|
|
778
|
+
* or `ce.defaultDomain`. If no domain has been explicitly set via assignment
|
|
779
|
+
* or via an `.assume()` directive, the `expr.explicitDomain` is `undefined`.
|
|
785
780
|
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
* - \\(\frac{4}{10} \longrightarrow \frac{2}{5} \\).
|
|
781
|
+
* This is useful to determine if the domain of an expression is inferred.
|
|
782
|
+
*
|
|
783
|
+
* In most cases you'll want to use `expr.domain` instead.
|
|
790
784
|
*
|
|
791
|
-
*
|
|
792
|
-
* \\( \sqrt(2) \longrightarrow \sqrt(2) \\).
|
|
785
|
+
* **Note** `undefined` if not a canonical expression or not a function.
|
|
793
786
|
*
|
|
794
|
-
* Determining the canonical form does not depend on the values assigned to,
|
|
795
|
-
* or assumptions about, symbols.
|
|
796
787
|
*/
|
|
797
|
-
|
|
788
|
+
readonly explicitDomain: BoxedDomain | undefined;
|
|
789
|
+
/**
|
|
790
|
+
* Update the definition associated with this expression, taking
|
|
791
|
+
* into account the specified scope.
|
|
792
|
+
*
|
|
793
|
+
* **Note**: applicable only to canonical expressions
|
|
794
|
+
*
|
|
795
|
+
* @internal
|
|
796
|
+
*/
|
|
797
|
+
bind(scope: RuntimeScope | null): void;
|
|
798
798
|
/**
|
|
799
|
-
* Return a simpler form of this expression.
|
|
800
799
|
*
|
|
801
|
-
*
|
|
802
|
-
|
|
800
|
+
* @internal
|
|
801
|
+
*/
|
|
802
|
+
unbind(): void;
|
|
803
|
+
/**
|
|
804
|
+
* Return a simpler form of the canonical form of this expression.
|
|
803
805
|
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
+
* A series of rewriting rules are applied repeatedly, until no more rules
|
|
807
|
+
* apply.
|
|
808
|
+
*
|
|
809
|
+
* If a custom `simplify` handler is associated with this function
|
|
810
|
+
* definition, it is invoked.
|
|
806
811
|
*
|
|
807
812
|
* The values assigned to symbols and the assumptions about symbols may be
|
|
808
813
|
* used, for example `arg.isInteger` or `arg.isPositive`.
|
|
809
814
|
*
|
|
810
|
-
* No calculations involving
|
|
811
|
-
* calculations may be performed,
|
|
815
|
+
* No calculations involving decimal numbers (numbers that are not
|
|
816
|
+
* integers) are performed but exact calculations may be performed,
|
|
817
|
+
* for example:
|
|
818
|
+
*
|
|
812
819
|
* \\( \sin(\frac{\pi}{4}) \longrightarrow \frac{\sqrt{2}}{2} \\).
|
|
813
820
|
*
|
|
814
821
|
* The result is in canonical form.
|
|
@@ -816,33 +823,37 @@ export interface BoxedExpression {
|
|
|
816
823
|
*/
|
|
817
824
|
simplify(options?: SimplifyOptions): BoxedExpression;
|
|
818
825
|
/**
|
|
819
|
-
* Return the value of this expression.
|
|
820
|
-
*
|
|
821
|
-
* The expression is first converted to canonical form.
|
|
826
|
+
* Return the value of the canonical form of this expression.
|
|
822
827
|
*
|
|
823
828
|
* A pure expression always return the same value and has no side effects.
|
|
824
|
-
* If `
|
|
825
|
-
*
|
|
829
|
+
* If `expr.isPure` is `true`, `expr.value` and `expr.evaluate()` are
|
|
830
|
+
* synonyms.
|
|
831
|
+
*
|
|
832
|
+
* For an impure expression, `expr.value` is undefined.
|
|
826
833
|
*
|
|
827
834
|
* Evaluating an impure expression may have some side effects, for
|
|
828
|
-
* example modifying the `ComputeEngine` environment, such as its set of
|
|
835
|
+
* example modifying the `ComputeEngine` environment, such as its set of
|
|
836
|
+
* assumptions.
|
|
829
837
|
*
|
|
830
|
-
* Only exact calculations are performed, no
|
|
831
|
-
*
|
|
838
|
+
* Only exact calculations are performed, no approximate calculations on
|
|
839
|
+
* decimal numbers (non-integer numbers). Constants, rational numbers and
|
|
840
|
+
* square root of rational numbers are preserved.
|
|
832
841
|
*
|
|
833
|
-
*
|
|
842
|
+
* To perform approximate calculations, use `expr.N()` instead.
|
|
843
|
+
*
|
|
844
|
+
* The result of `expr.evaluate()` may be the same as `expr.simplify()`.
|
|
834
845
|
*
|
|
835
846
|
* The result is in canonical form.
|
|
836
847
|
*
|
|
837
848
|
*/
|
|
838
849
|
evaluate(options?: EvaluateOptions): BoxedExpression;
|
|
839
|
-
/** Return a numeric approximation of this expression.
|
|
850
|
+
/** Return a numeric approximation of the canonical form of this expression.
|
|
840
851
|
*
|
|
841
|
-
*
|
|
852
|
+
* Any necessary calculations, including on decimal numbers (non-integers),
|
|
853
|
+
* are performed.
|
|
842
854
|
*
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
* to the `numericMode` and `precision` properties of the `ComputeEngine`.
|
|
855
|
+
* The calculations are performed according to the `numericMode` and
|
|
856
|
+
* `precision` properties of the `ComputeEngine`.
|
|
846
857
|
*
|
|
847
858
|
* To only perform exact calculations, use `this.evaluate()` instead.
|
|
848
859
|
*
|
|
@@ -854,46 +865,131 @@ export interface BoxedExpression {
|
|
|
854
865
|
N(options?: NOptions): BoxedExpression;
|
|
855
866
|
solve(vars: Iterable<string>): null | BoxedExpression[];
|
|
856
867
|
/**
|
|
857
|
-
* If
|
|
868
|
+
* Synonym for `evaluate()`. If the expression is pure, the value may be
|
|
869
|
+
* cached.
|
|
858
870
|
*
|
|
859
|
-
*
|
|
871
|
+
* It returns `undefined` for expressions that are not pure or that may
|
|
872
|
+
* not be evaluated.
|
|
860
873
|
*
|
|
861
|
-
* If
|
|
862
|
-
|
|
874
|
+
* **Note**: If non-canonical, return the value of its canonical counterpart
|
|
875
|
+
*/
|
|
876
|
+
get value(): BoxedExpression | undefined;
|
|
877
|
+
/** Only the value of variables can be changed (symbols that are not
|
|
878
|
+
* constants).
|
|
863
879
|
*
|
|
864
|
-
* If
|
|
865
|
-
*
|
|
866
|
-
|
|
867
|
-
|
|
880
|
+
* **Note**: If non-canonical, does nothing.
|
|
881
|
+
*
|
|
882
|
+
*/
|
|
883
|
+
set value(value: BoxedExpression | number | undefined);
|
|
884
|
+
/** The domain of the value of this expression.
|
|
885
|
+
*
|
|
886
|
+
* If a function expression, the domain of the value of the function (the codomain of the function).
|
|
887
|
+
*
|
|
888
|
+
* If a symbol the domain of the value of the symbol.
|
|
889
|
+
*
|
|
890
|
+
* Use `expr.head` to determine if an expression is a symbol or function.
|
|
891
|
+
*
|
|
892
|
+
* **Note**: If non-canonical, return the domain of its canonical
|
|
893
|
+
* counterpart
|
|
894
|
+
*/
|
|
895
|
+
get domain(): BoxedDomain;
|
|
896
|
+
/** Modify the domain of a symbol that represent a variable
|
|
897
|
+
* (or a function name).
|
|
898
|
+
*
|
|
899
|
+
* **Note**: If non-canonical, does nothing.
|
|
900
|
+
*
|
|
901
|
+
*/
|
|
902
|
+
set domain(domain: BoxedExpression | DomainExpression | BoxedDomain);
|
|
903
|
+
/** `true` if the value of this expression is a number.
|
|
904
|
+
*
|
|
905
|
+
* `isExtendedComplex || isNaN` = `isReal || isImaginary || isInfinity || isNaN`
|
|
906
|
+
*
|
|
907
|
+
* Note that in a fateful twist of cosmic irony, `NaN` ("Not a Number")
|
|
908
|
+
* **is** a number.
|
|
909
|
+
*
|
|
910
|
+
* @category Domain Properties
|
|
911
|
+
*/
|
|
912
|
+
readonly isNumber: boolean | undefined;
|
|
913
|
+
/** The value of this expression is an element of the set ℤ: ...,-2, -1, 0, 1, 2...
|
|
914
|
+
*
|
|
915
|
+
*
|
|
916
|
+
* @category Domain Properties
|
|
917
|
+
*
|
|
918
|
+
*/
|
|
919
|
+
readonly isInteger: boolean | undefined;
|
|
920
|
+
/** The value of this expression is an element of the set ℚ, p/q with p ∈ ℕ, q ∈ ℤ ⃰ q >= 1
|
|
921
|
+
*
|
|
922
|
+
* Note that every integer is also a rational.
|
|
923
|
+
*
|
|
924
|
+
*
|
|
925
|
+
* @category Domain Properties
|
|
926
|
+
*
|
|
927
|
+
*/
|
|
928
|
+
readonly isRational: boolean | undefined;
|
|
868
929
|
/**
|
|
869
|
-
*
|
|
870
|
-
*
|
|
930
|
+
* The value of this expression is a number that is the root of a non-zero
|
|
931
|
+
* univariate polynomial with rational coefficients.
|
|
871
932
|
*
|
|
872
|
-
*
|
|
933
|
+
* All integers and rational numbers are algebraic.
|
|
934
|
+
*
|
|
935
|
+
* Transcendental numbers, such as \\( \pi \\) or \\( e \\) are not algebraic.
|
|
936
|
+
*
|
|
937
|
+
*
|
|
938
|
+
* @category Domain Properties
|
|
873
939
|
*
|
|
874
|
-
* See also `subs` for a simple substitution.
|
|
875
940
|
*/
|
|
876
|
-
|
|
941
|
+
readonly isAlgebraic: boolean | undefined;
|
|
877
942
|
/**
|
|
878
|
-
*
|
|
943
|
+
* The value of this expression is real number: finite and not imaginary.
|
|
879
944
|
*
|
|
880
|
-
*
|
|
881
|
-
* using `this.subs()` is more efficient, and simpler.
|
|
945
|
+
* `isFinite && !isImaginary`
|
|
882
946
|
*
|
|
947
|
+
*
|
|
948
|
+
* @category Domain Properties
|
|
883
949
|
*/
|
|
884
|
-
|
|
950
|
+
readonly isReal: boolean | undefined;
|
|
951
|
+
/** Real or ±Infinity
|
|
952
|
+
*
|
|
953
|
+
* `isReal || isInfinity`
|
|
954
|
+
*
|
|
955
|
+
*
|
|
956
|
+
* @category Domain Properties
|
|
957
|
+
*/
|
|
958
|
+
readonly isExtendedReal: boolean | undefined;
|
|
885
959
|
/**
|
|
886
|
-
*
|
|
887
|
-
*
|
|
960
|
+
* The value of this expression is a number, but not `NaN` or any Infinity
|
|
961
|
+
*
|
|
962
|
+
* `isReal || isImaginary`
|
|
963
|
+
*
|
|
964
|
+
*
|
|
965
|
+
* @category Domain Properties
|
|
888
966
|
*
|
|
889
|
-
* @internal
|
|
890
967
|
*/
|
|
891
|
-
|
|
892
|
-
/**
|
|
968
|
+
readonly isComplex: boolean | undefined;
|
|
969
|
+
/** `isReal || isImaginary || isInfinity`
|
|
893
970
|
*
|
|
894
|
-
*
|
|
971
|
+
*
|
|
972
|
+
* @category Domain Properties
|
|
895
973
|
*/
|
|
896
|
-
|
|
974
|
+
readonly isExtendedComplex: boolean | undefined;
|
|
975
|
+
/** The value of this expression is a number with a imaginary part
|
|
976
|
+
*
|
|
977
|
+
*
|
|
978
|
+
* @category Domain Properties
|
|
979
|
+
*/
|
|
980
|
+
readonly isImaginary: boolean | undefined;
|
|
981
|
+
/** Mathematical equality (strong equality), that is the value
|
|
982
|
+
* of this expression and of `rhs` are numerically equal.
|
|
983
|
+
*
|
|
984
|
+
* The numeric value of both expressions are compared.
|
|
985
|
+
*
|
|
986
|
+
* Numbers whose difference is less than `engine.tolerance` are
|
|
987
|
+
* considered equal. This tolerance is set when the `engine.precision` is
|
|
988
|
+
* changed to be such that the last two digits are ignored.
|
|
989
|
+
*
|
|
990
|
+
* @category Relational Operator
|
|
991
|
+
*/
|
|
992
|
+
isEqual(rhs: BoxedExpression): boolean;
|
|
897
993
|
}
|
|
898
994
|
/** A semi boxed expression is an MathJSON expression which can include some
|
|
899
995
|
* boxed terms.
|
|
@@ -901,29 +997,18 @@ export interface BoxedExpression {
|
|
|
901
997
|
* This is convenient when creating new expressions from portions
|
|
902
998
|
* of an existing `BoxedExpression` while avoiding unboxing and reboxing.
|
|
903
999
|
*/
|
|
904
|
-
export declare type SemiBoxedExpression =
|
|
905
|
-
export declare type
|
|
906
|
-
|
|
907
|
-
export declare type PatternMatchOption = {
|
|
1000
|
+
export declare type SemiBoxedExpression = number | string | Decimal | Complex | MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction | MathJsonDictionary | SemiBoxedExpression[] | BoxedExpression;
|
|
1001
|
+
export declare type PatternMatchOptions = {
|
|
1002
|
+
substitution?: BoxedSubstitution;
|
|
908
1003
|
recursive?: boolean;
|
|
909
1004
|
numericTolerance?: number;
|
|
910
1005
|
exact?: boolean;
|
|
911
1006
|
};
|
|
912
1007
|
export interface Pattern extends BoxedExpression {
|
|
913
|
-
/**
|
|
914
|
-
* If `expr` does not match the pattern, return `null`.
|
|
915
|
-
*
|
|
916
|
-
* Otherwise, return a substitution describing the values that the named
|
|
917
|
-
* wildcard in the pattern should be changed to in order for the pattern to be
|
|
918
|
-
* equal to the expression. If there are no named wildcards and the expression
|
|
919
|
-
* matches the pattern, and empty object literal `{}` is returned.
|
|
920
|
-
*/
|
|
921
|
-
match(expr: BoxedExpression, options?: PatternMatchOption): BoxedSubstitution | null;
|
|
922
1008
|
/** If `expr` matches the pattern, return `true`, otherwise `false` */
|
|
923
|
-
test(expr: BoxedExpression, options?:
|
|
1009
|
+
test(expr: BoxedExpression, options?: PatternMatchOptions): boolean;
|
|
924
1010
|
/** Return the number of exprs that matched the pattern */
|
|
925
|
-
count(exprs: Iterable<BoxedExpression>, options?:
|
|
926
|
-
subs(sub: Substitution): Pattern;
|
|
1011
|
+
count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOptions): number;
|
|
927
1012
|
}
|
|
928
1013
|
export interface ExpressionMapInterface<U> {
|
|
929
1014
|
has(expr: BoxedExpression): boolean;
|
|
@@ -1000,7 +1085,7 @@ export declare type Scope = {
|
|
|
1000
1085
|
iterationLimit?: number;
|
|
1001
1086
|
};
|
|
1002
1087
|
export declare type RuntimeScope = Scope & {
|
|
1003
|
-
parentScope
|
|
1088
|
+
parentScope?: RuntimeScope;
|
|
1004
1089
|
symbolTable?: RuntimeSymbolTable;
|
|
1005
1090
|
assumptions: undefined | ExpressionMapInterface<boolean>;
|
|
1006
1091
|
/** The location of the call site that created this scope */
|
|
@@ -1141,12 +1226,6 @@ export declare type FunctionDefinitionFlags = {
|
|
|
1141
1226
|
* and its value is numeric.
|
|
1142
1227
|
*/
|
|
1143
1228
|
numeric: boolean;
|
|
1144
|
-
/**
|
|
1145
|
-
* When true, evaluating the function create a temporary scope.
|
|
1146
|
-
* This is used for example by the `Lambda` function to keep track of the
|
|
1147
|
-
* inferred domain of its wildcard `_` arguments
|
|
1148
|
-
*/
|
|
1149
|
-
scoped: boolean;
|
|
1150
1229
|
};
|
|
1151
1230
|
/**
|
|
1152
1231
|
*
|
|
@@ -1163,76 +1242,89 @@ export declare type FunctionSignature = {
|
|
|
1163
1242
|
/**
|
|
1164
1243
|
* Return the canonical form of the expression with the arguments `args`.
|
|
1165
1244
|
*
|
|
1166
|
-
*
|
|
1167
|
-
*
|
|
1245
|
+
* The arguments (`args`) may not be in canonical form. If necessary, they
|
|
1246
|
+
* can be put in canonical form.
|
|
1168
1247
|
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1248
|
+
* This handler should validate the domain and number of the arguments.
|
|
1249
|
+
* If a required argument is missing, it should be indicated with a
|
|
1250
|
+
* `["Error", "'missing"]` expression. If more arguments than expected
|
|
1251
|
+
* are present, this should be indicated with a `unexpected-argument` error.
|
|
1252
|
+
* If the domain of an argument is not compatible, it should be indicated with
|
|
1253
|
+
* a `incompatible-domain` error.
|
|
1172
1254
|
*
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1175
|
-
* `arg.isLiteral && arg.isRational`) or integers (i.e.
|
|
1176
|
-
* `isLiteral && arg.isInteger`).
|
|
1255
|
+
* `["Sequence"]` expressions are not folded and need to be handled
|
|
1256
|
+
* explicitly.
|
|
1177
1257
|
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1258
|
+
* If the function is associative, idempotent or an involution,
|
|
1259
|
+
* this handler should account for it. Notably, if it is commutative, the
|
|
1260
|
+
* arguments should be sorted in canonical order.
|
|
1180
1261
|
*
|
|
1181
|
-
* The handler
|
|
1182
|
-
*
|
|
1183
|
-
* `arg.isInteger`, etc...
|
|
1262
|
+
* The handler can make transformations based on the value of the arguments
|
|
1263
|
+
* that are exact (i.e. `arg.isExact`).
|
|
1184
1264
|
*
|
|
1185
|
-
* The handler should not
|
|
1186
|
-
*
|
|
1265
|
+
* The handler should not consider the value or any assumptions about any
|
|
1266
|
+
* of the arguments that are symbols or functions (i.e. `arg.isZero`,
|
|
1267
|
+
* `arg.isInteger`, etc...) since those may change over time.
|
|
1187
1268
|
*
|
|
1188
1269
|
* The result of the handler should be a canonical expression.
|
|
1189
1270
|
*
|
|
1271
|
+
* If the arguments do not match, they should be replaced with an appropriate
|
|
1272
|
+
* `["Error"]` expression. If the expression cannot be put in canonical form,
|
|
1273
|
+
* the handler should return `null`.
|
|
1274
|
+
*
|
|
1190
1275
|
*/
|
|
1191
|
-
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1276
|
+
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
|
|
1192
1277
|
/**
|
|
1193
1278
|
* Rewrite an expression into a simpler form.
|
|
1194
1279
|
*
|
|
1195
1280
|
* The arguments are in canonical form and have been simplified.
|
|
1196
1281
|
*
|
|
1197
|
-
* The handler can use the values assigned to symbols and the assumptions
|
|
1198
|
-
* symbols, for example with `arg.
|
|
1282
|
+
* The handler can use the values assigned to symbols and the assumptions
|
|
1283
|
+
* about symbols, for example with `arg.numericValue`, `arg.isInteger` or
|
|
1199
1284
|
* `arg.isPositive`.
|
|
1200
1285
|
*
|
|
1201
1286
|
* Even though a symbol may not have a value, there may be some information
|
|
1202
1287
|
* about it reflected for example in `this.isZero` or `this.isPrime`.
|
|
1203
1288
|
*
|
|
1204
1289
|
* The handler should not perform approximate numeric calculations, such
|
|
1205
|
-
* as calculations involving
|
|
1206
|
-
* calculations on integers or rationals is OK.
|
|
1207
|
-
* required, that the calculations be limited to `this.smallIntegerValue`
|
|
1208
|
-
* (i.e. numeric representations of the expression as an integer of small
|
|
1209
|
-
* magnitude).
|
|
1290
|
+
* as calculations involving decimal numbers (non-integers). Making exact
|
|
1291
|
+
* calculations on integers or rationals is OK.
|
|
1210
1292
|
*
|
|
1211
1293
|
* This handler should not have any side-effects: do not modify
|
|
1212
1294
|
* the environment of the `ComputeEngine` instance, do not perform I/O,
|
|
1213
1295
|
* do not do calculations that depend on random values.
|
|
1214
1296
|
*
|
|
1215
|
-
* If no simplification can be performed due to the values, domains or
|
|
1216
|
-
* about its arguments, for example, return `undefined`.
|
|
1297
|
+
* If no simplification can be performed due to the values, domains or
|
|
1298
|
+
* assumptions about its arguments, for example, return `undefined`.
|
|
1217
1299
|
*
|
|
1218
1300
|
*/
|
|
1219
1301
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1220
1302
|
/**
|
|
1221
|
-
* Evaluate symbolically
|
|
1303
|
+
* Evaluate symbolically a function expression.
|
|
1222
1304
|
*
|
|
1223
1305
|
* The arguments have been symbolically evaluated, except the arguments to
|
|
1224
1306
|
* which a `hold` apply.
|
|
1225
1307
|
*
|
|
1226
1308
|
* It is not necessary to further simplify or evaluate the arguments.
|
|
1227
1309
|
*
|
|
1228
|
-
* If
|
|
1229
|
-
*
|
|
1310
|
+
* If performing numerical calculations, if all the arguments are exact,
|
|
1311
|
+
* return an exact expression. If any of the arguments is not exact, that is
|
|
1312
|
+
* if it is a literal decimal (non-integer) number, return an approximation.
|
|
1313
|
+
* In this case, the value may be the same as `expr.N()`.
|
|
1230
1314
|
*
|
|
1315
|
+
* When doing an exact calculation:
|
|
1316
|
+
* - do not reduce rational numbers to decimal (floating point approximation)
|
|
1317
|
+
* - do not down convert bignums to machine numbers
|
|
1318
|
+
* - do not reduce square roots of rational numbers
|
|
1319
|
+
* - do not reduce constants with a `hold` attribute
|
|
1231
1320
|
*
|
|
1321
|
+
* If the expression cannot be evaluated, due to the values, domains, or
|
|
1322
|
+
* assumptions about its arguments, for example, return `undefined` or
|
|
1323
|
+
* an `["Error"]` expression.
|
|
1232
1324
|
*/
|
|
1233
|
-
evaluate?:
|
|
1325
|
+
evaluate?: SemiBoxedExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
|
|
1234
1326
|
/**
|
|
1235
|
-
* Evaluate numerically
|
|
1327
|
+
* Evaluate numerically a function expression.
|
|
1236
1328
|
*
|
|
1237
1329
|
* The arguments `args` have been simplified and evaluated, numerically
|
|
1238
1330
|
* if possible, except the arguments to which a `hold` apply.
|
|
@@ -1251,19 +1343,22 @@ export declare type FunctionSignature = {
|
|
|
1251
1343
|
* evaluation, but a literal argument is out of range or
|
|
1252
1344
|
* not of the expected type.
|
|
1253
1345
|
*
|
|
1254
|
-
*
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1346
|
+
* Note that regardless of the current value of `ce.numericMode`, the
|
|
1347
|
+
* arguments may be boxed numbers representing machine numbers, bignum
|
|
1348
|
+
* numbers, complex numbers, rationals or big rationals.
|
|
1349
|
+
*
|
|
1350
|
+
* Use the value of `ce.numericMode` to determine how to perform
|
|
1351
|
+
* the numeric evaluation.
|
|
1257
1352
|
*
|
|
1258
|
-
* If the
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1261
|
-
* will be complex literals.
|
|
1353
|
+
* If the numeric mode does not allow complex numbers (the
|
|
1354
|
+
* `engine.numericMode` is not `"complex"` or `"auto"`) and the result of
|
|
1355
|
+
* the evaluation would be a complex number, return `NaN` instead.
|
|
1262
1356
|
*
|
|
1263
|
-
* If
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1266
|
-
*
|
|
1357
|
+
* If `ce.numericMode` is `"bignum"` or `"auto"` the evaluation should be done
|
|
1358
|
+
* using bignums.
|
|
1359
|
+
*
|
|
1360
|
+
* Otherwise, `ce.numericMode` is `"machine", the evaluation should be
|
|
1361
|
+
* performed using machine numbers.
|
|
1267
1362
|
*
|
|
1268
1363
|
* You may perform any necessary computations, including approximate
|
|
1269
1364
|
* calculations on floating point numbers.
|
|
@@ -1274,17 +1369,17 @@ export declare type FunctionSignature = {
|
|
|
1274
1369
|
* @experimental
|
|
1275
1370
|
*/
|
|
1276
1371
|
evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1277
|
-
/** Return the sign of the function
|
|
1372
|
+
/** Return the sign of the function expression. */
|
|
1278
1373
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
1279
1374
|
/** Return a compiled (optimized) expression. */
|
|
1280
1375
|
compile?: (expr: BoxedExpression) => CompiledExpression;
|
|
1281
1376
|
};
|
|
1282
1377
|
export declare type BoxedFunctionSignature = {
|
|
1283
1378
|
domain: BoxedDomain;
|
|
1284
|
-
codomain?: BoxedDomain | ((ce: IComputeEngine, args:
|
|
1285
|
-
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1379
|
+
codomain?: BoxedDomain | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedDomain | null);
|
|
1380
|
+
canonical?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | null;
|
|
1286
1381
|
simplify?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1287
|
-
evaluate?:
|
|
1382
|
+
evaluate?: BoxedExpression | ((ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined);
|
|
1288
1383
|
N?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression | undefined;
|
|
1289
1384
|
evalDimension?: (ce: IComputeEngine, args: BoxedExpression[]) => BoxedExpression;
|
|
1290
1385
|
sgn?: (ce: IComputeEngine, args: BoxedExpression[]) => -1 | 0 | 1 | undefined;
|
|
@@ -1377,7 +1472,7 @@ export declare type SymbolDefinitionFlags = {
|
|
|
1377
1472
|
*/
|
|
1378
1473
|
constant: boolean;
|
|
1379
1474
|
/**
|
|
1380
|
-
* If false
|
|
1475
|
+
* If `false`, the value of the symbol is substituted during canonicalization
|
|
1381
1476
|
* or simplification.
|
|
1382
1477
|
*
|
|
1383
1478
|
* If true, the value is only replaced during a `ce.N()` or `ce.evaluate()`.
|
|
@@ -1421,8 +1516,6 @@ export interface IComputeEngine {
|
|
|
1421
1516
|
/** @internal */
|
|
1422
1517
|
readonly _ONE: BoxedExpression;
|
|
1423
1518
|
/** @internal */
|
|
1424
|
-
readonly _TWO: BoxedExpression;
|
|
1425
|
-
/** @internal */
|
|
1426
1519
|
readonly _HALF: BoxedExpression;
|
|
1427
1520
|
/** @internal */
|
|
1428
1521
|
readonly _NEGATIVE_ONE: BoxedExpression;
|
|
@@ -1437,19 +1530,19 @@ export interface IComputeEngine {
|
|
|
1437
1530
|
/** @internal */
|
|
1438
1531
|
readonly _COMPLEX_INFINITY: BoxedExpression;
|
|
1439
1532
|
/** @internal */
|
|
1440
|
-
readonly
|
|
1533
|
+
readonly _BIGNUM_NAN: Decimal;
|
|
1441
1534
|
/** @internal */
|
|
1442
|
-
readonly
|
|
1535
|
+
readonly _BIGNUM_ZERO: Decimal;
|
|
1443
1536
|
/** @internal */
|
|
1444
|
-
readonly
|
|
1537
|
+
readonly _BIGNUM_ONE: Decimal;
|
|
1445
1538
|
/** @internal */
|
|
1446
|
-
readonly
|
|
1539
|
+
readonly _BIGNUM_TWO: Decimal;
|
|
1447
1540
|
/** @internal */
|
|
1448
|
-
readonly
|
|
1541
|
+
readonly _BIGNUM_HALF: Decimal;
|
|
1449
1542
|
/** @internal */
|
|
1450
|
-
readonly
|
|
1543
|
+
readonly _BIGNUM_PI: Decimal;
|
|
1451
1544
|
/** @internal */
|
|
1452
|
-
readonly
|
|
1545
|
+
readonly _BIGNUM_NEGATIVE_ONE: Decimal;
|
|
1453
1546
|
/** The current scope */
|
|
1454
1547
|
context: RuntimeScope | null;
|
|
1455
1548
|
/** Absolute time beyond which evaluation should not proceed
|
|
@@ -1471,7 +1564,7 @@ export interface IComputeEngine {
|
|
|
1471
1564
|
chop(n: Complex): Complex | 0;
|
|
1472
1565
|
chop(n: number | Decimal | Complex): number | Decimal | Complex;
|
|
1473
1566
|
/** @internal */
|
|
1474
|
-
|
|
1567
|
+
bignum: (a: Decimal.Value) => Decimal;
|
|
1475
1568
|
/** @internal */
|
|
1476
1569
|
complex: (a: number | Complex, b?: number) => Complex;
|
|
1477
1570
|
set precision(p: number | 'machine');
|
|
@@ -1491,17 +1584,23 @@ export interface IComputeEngine {
|
|
|
1491
1584
|
defineFunction(def: FunctionDefinition): BoxedFunctionDefinition;
|
|
1492
1585
|
lookupSymbol(name: string, wikidata?: string, scope?: RuntimeScope): undefined | BoxedSymbolDefinition;
|
|
1493
1586
|
/** Return `undefined` if no definition exist for this `head` */
|
|
1494
|
-
lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
|
|
1587
|
+
lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
|
|
1495
1588
|
/**
|
|
1496
1589
|
* Return a boxed expression from the input.
|
|
1497
|
-
*
|
|
1498
|
-
* The result may not be canonical.
|
|
1499
1590
|
*/
|
|
1500
|
-
box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression
|
|
1501
|
-
|
|
1502
|
-
|
|
1591
|
+
box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
|
|
1592
|
+
canonical?: boolean;
|
|
1593
|
+
}): BoxedExpression;
|
|
1594
|
+
/** Return a boxed number */
|
|
1595
|
+
number(value: number | string | MathJsonNumber | Decimal | Complex | [num: number, denom: number] | [num: Decimal, denom: Decimal], options?: {
|
|
1596
|
+
metadata?: Metadata;
|
|
1597
|
+
canonical?: boolean;
|
|
1598
|
+
}): BoxedExpression;
|
|
1503
1599
|
/** Return a canonical boxed symbol */
|
|
1504
|
-
symbol(sym: string,
|
|
1600
|
+
symbol(sym: string, options?: {
|
|
1601
|
+
metadata?: Metadata;
|
|
1602
|
+
canonical?: boolean;
|
|
1603
|
+
}): BoxedExpression;
|
|
1505
1604
|
/** Return a canonical boxed string */
|
|
1506
1605
|
string(s: string, metadata?: Metadata): BoxedExpression;
|
|
1507
1606
|
/** Return a canonical boxed domain.
|
|
@@ -1510,8 +1609,6 @@ export interface IComputeEngine {
|
|
|
1510
1609
|
*
|
|
1511
1610
|
*/
|
|
1512
1611
|
domain(domain: SemiBoxedExpression | BoxedDomain | string, metadata?: Metadata): BoxedDomain;
|
|
1513
|
-
/** Return a canonical lambda expression */
|
|
1514
|
-
lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
|
|
1515
1612
|
/**
|
|
1516
1613
|
* Return a canonical expression.
|
|
1517
1614
|
*
|
|
@@ -1527,7 +1624,7 @@ export interface IComputeEngine {
|
|
|
1527
1624
|
* This is a primitive to create a boxed function. It doesn't perform
|
|
1528
1625
|
* any checks or normalization on its arguments.
|
|
1529
1626
|
*
|
|
1530
|
-
* In general, consider using `fn()` or `box()` instead.
|
|
1627
|
+
* In general, consider using `ce.fn()` or `ce.box()` instead.
|
|
1531
1628
|
*
|
|
1532
1629
|
* The result is canonical, but the caller has to ensure that all the
|
|
1533
1630
|
* conditions are met (i.e. `ops` properly normalized and sorted, all
|
|
@@ -1539,6 +1636,10 @@ export interface IComputeEngine {
|
|
|
1539
1636
|
* The result is canonical.
|
|
1540
1637
|
*/
|
|
1541
1638
|
error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
|
|
1639
|
+
/**
|
|
1640
|
+
* Add a`["Hold"]` wrapper to `expr.
|
|
1641
|
+
*/
|
|
1642
|
+
hold(expr: SemiBoxedExpression): BoxedExpression;
|
|
1542
1643
|
/** Shortcut for `this.fn("Add"...)`.
|
|
1543
1644
|
*
|
|
1544
1645
|
* The result is canonical.
|
|
@@ -1553,7 +1654,8 @@ export interface IComputeEngine {
|
|
|
1553
1654
|
*
|
|
1554
1655
|
* The result is canonical.
|
|
1555
1656
|
*/
|
|
1556
|
-
power(base: BoxedExpression, exponent: number |
|
|
1657
|
+
power(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
|
|
1658
|
+
sqrt(base: BoxedExpression, metadata?: Metadata): any;
|
|
1557
1659
|
/** Shortcut for `this.fn("Divide", [1, expr])`
|
|
1558
1660
|
*
|
|
1559
1661
|
* The result is canonical.
|
|
@@ -1587,9 +1689,15 @@ export interface IComputeEngine {
|
|
|
1587
1689
|
* The result may not be canonical.
|
|
1588
1690
|
*
|
|
1589
1691
|
*/
|
|
1590
|
-
parse(s: LatexString | string
|
|
1591
|
-
|
|
1592
|
-
|
|
1692
|
+
parse(s: LatexString | string, options?: {
|
|
1693
|
+
canonical?: boolean;
|
|
1694
|
+
}): BoxedExpression;
|
|
1695
|
+
parse(s: null, options?: {
|
|
1696
|
+
canonical?: boolean;
|
|
1697
|
+
}): null;
|
|
1698
|
+
parse(s: LatexString | string | null, options?: {
|
|
1699
|
+
canonical?: boolean;
|
|
1700
|
+
}): null | BoxedExpression;
|
|
1593
1701
|
/** Serialize a `BoxedExpression` or a `MathJSON` expression to
|
|
1594
1702
|
* a LaTeX string
|
|
1595
1703
|
*/
|
|
@@ -1607,8 +1715,22 @@ export interface IComputeEngine {
|
|
|
1607
1715
|
get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
|
|
1608
1716
|
set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
|
|
1609
1717
|
/** {@inheritDoc JsonSerializationOptions} */
|
|
1610
|
-
get jsonSerializationOptions(): JsonSerializationOptions
|
|
1718
|
+
get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
|
|
1611
1719
|
set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
|
|
1720
|
+
pushScope(options?: {
|
|
1721
|
+
symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
|
|
1722
|
+
assumptions?: (LatexString | Expression | BoxedExpression)[];
|
|
1723
|
+
scope?: Partial<Scope>;
|
|
1724
|
+
}): void;
|
|
1725
|
+
popScope(): void;
|
|
1726
|
+
/** Assign a value to an identifier in the current scope */
|
|
1727
|
+
set(identifiers: {
|
|
1728
|
+
[identifier: string]: SemiBoxedExpression;
|
|
1729
|
+
}): void;
|
|
1730
|
+
/** Declare identifiers (specify their domain without necessarily assigning them a value in the current scope*/
|
|
1731
|
+
let(identifiers: {
|
|
1732
|
+
[identifier: string]: SymbolDefinition | FunctionDefinition;
|
|
1733
|
+
}): void;
|
|
1612
1734
|
/**
|
|
1613
1735
|
* Add an assumption.
|
|
1614
1736
|
*
|
|
@@ -1630,13 +1752,7 @@ export interface IComputeEngine {
|
|
|
1630
1752
|
/** Remove all assumptions about one or more symbols */
|
|
1631
1753
|
forget(symbol?: string | string[]): void;
|
|
1632
1754
|
get assumptions(): ExpressionMapInterface<boolean>;
|
|
1633
|
-
ask(pattern: LatexString | SemiBoxedExpression):
|
|
1634
|
-
pushScope(options?: {
|
|
1635
|
-
symbolTable?: Readonly<SymbolTable> | Readonly<SymbolTable>[];
|
|
1636
|
-
assumptions?: (LatexString | Expression | BoxedExpression)[];
|
|
1637
|
-
scope?: Partial<Scope>;
|
|
1638
|
-
}): void;
|
|
1639
|
-
popScope(): void;
|
|
1755
|
+
ask(pattern: LatexString | SemiBoxedExpression): BoxedSubstitution[];
|
|
1640
1756
|
/**
|
|
1641
1757
|
* When `condition` is false, signal.
|
|
1642
1758
|
*
|