@cortex-js/compute-engine 0.8.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.
Files changed (83) hide show
  1. package/dist/compute-engine.esm.js +7800 -6891
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +41 -88
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -5
  9. package/dist/types/common/utils.d.ts +1 -0
  10. package/dist/types/compute-engine/assume.d.ts +6 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +10 -14
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +74 -16
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +10 -5
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -4
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +16 -14
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +20 -19
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +8 -7
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +3 -3
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +18 -12
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -3
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +7 -7
  26. package/dist/types/compute-engine/boxed-expression/validate.d.ts +18 -0
  27. package/dist/types/compute-engine/compute-engine.d.ts +64 -33
  28. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  29. package/dist/types/compute-engine/domain-utils.d.ts +2 -8
  30. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  31. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -9
  43. package/dist/types/compute-engine/latex-syntax/public.d.ts +14 -6
  44. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
  46. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  47. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  48. package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -3
  49. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  50. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +5 -6
  51. package/dist/types/compute-engine/library/arithmetic-power.d.ts +3 -2
  52. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  53. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  54. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  55. package/dist/types/compute-engine/library/core.d.ts +1 -1
  56. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  57. package/dist/types/compute-engine/library/library.d.ts +1 -1
  58. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  59. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  60. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  61. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  62. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  63. package/dist/types/compute-engine/numerics/{numeric-decimal.d.ts → numeric-bignum.d.ts} +10 -6
  64. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  65. package/dist/types/compute-engine/numerics/numeric.d.ts +10 -6
  66. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  67. package/dist/types/compute-engine/numerics/rationals.d.ts +56 -0
  68. package/dist/types/compute-engine/public.d.ts +200 -247
  69. package/dist/types/compute-engine/rules.d.ts +7 -1
  70. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  71. package/dist/types/compute-engine/solve.d.ts +17 -0
  72. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/flatten.d.ts +2 -1
  74. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  75. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  76. package/dist/types/compute-engine/symbolic/product.d.ts +30 -12
  77. package/dist/types/compute-engine/symbolic/sum.d.ts +13 -7
  78. package/dist/types/compute-engine/symbolic/utils.d.ts +7 -29
  79. package/dist/types/compute-engine.d.ts +2 -2
  80. package/dist/types/math-json/math-json-format.d.ts +2 -2
  81. package/dist/types/math-json/utils.d.ts +11 -41
  82. package/dist/types/math-json.d.ts +3 -3
  83. package/package.json +1 -1
@@ -1,49 +1,50 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
- import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOption, SimplifyOptions, Substitution } from '../public';
4
+ import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOptions, Rational, SimplifyOptions, BoxedSubstitution } from '../public';
5
5
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
6
6
  /**
7
7
  * BoxedNumber
8
8
  */
9
9
  export declare class BoxedNumber extends AbstractBoxedExpression {
10
- protected readonly _value: number | Decimal | Complex | [numer: number, denom: number];
10
+ protected readonly _value: number | Decimal | Complex | Rational;
11
11
  private _domain;
12
- private _head;
13
12
  private _hash;
14
13
  protected _isCanonical: boolean;
15
14
  /**
16
15
  * By the time the constructor is called, the `value` should have been
17
- * screened for cases where it's a well-known value (0, NaN, +Infinity, etc...)
18
- * or non-normal (complex number with im = 0, rational with denom = 1, etc...)
19
- * This is done in `ce.boxNumber()`. In general, use `ce.boxNumber()` rather
20
- * than calling the constructor directly.
16
+ * screened for cases where it's a well-known value (0, NaN, +Infinity,
17
+ * etc...) or non-normal (complex number with im = 0, rational with
18
+ * denom = 1, etc...).
19
+ *
20
+ * This is done in `ce.number()`. In general, use `ce.number()` rather
21
+ * than calling this constructor directly.
22
+ *
23
+ * We may store as a machine number if a Decimal is passed that is in machine
24
+ * range
21
25
  */
22
- constructor(ce: IComputeEngine, value: string | number | Decimal | Complex | [numer: number, denom: number], metadata?: Metadata);
26
+ constructor(ce: IComputeEngine, value: number | Decimal | Complex | Rational, options?: {
27
+ metadata?: Metadata;
28
+ canonical?: boolean;
29
+ });
23
30
  get hash(): number;
24
31
  get head(): string;
25
32
  get isPure(): boolean;
26
33
  get isLiteral(): boolean;
34
+ get isExact(): boolean;
27
35
  get isCanonical(): boolean;
28
36
  set isCanonical(val: boolean);
29
37
  get complexity(): number;
30
38
  get value(): BoxedExpression;
31
- get numericValue(): BoxedExpression;
32
- get machineValue(): number | null;
33
- get decimalValue(): Decimal | null;
34
- get complexValue(): Complex | null;
35
- get rationalValue(): [numer: number, denom: number] | [null, null];
36
- get asFloat(): number | null;
37
- get asSmallInteger(): number | null;
38
- get asRational(): [number, number] | [null, null];
39
+ get numericValue(): number | Decimal | Complex | Rational | null;
39
40
  get domain(): BoxedDomain;
40
41
  get json(): Expression;
41
42
  get sgn(): -1 | 0 | 1 | undefined | null;
42
43
  isSame(rhs: BoxedExpression): boolean;
43
44
  isEqual(rhs: BoxedExpression): boolean;
44
- match(rhs: BoxedExpression, options?: PatternMatchOption): Substitution | null;
45
+ match(rhs: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
45
46
  /** Compare this with another BoxedNumber.
46
- * `rhs` must be a BoxedNumber. Use `isEqualWithTolerance(rhs.numericValue)`
47
+ * `rhs` must be a BoxedNumber. Use `isEqualWithTolerance(rhs.N())`
47
48
  * if necessary.
48
49
  */
49
50
  isEqualWithTolerance(rhs: BoxedExpression, tolerance: number): boolean;
@@ -1,9 +1,8 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
- import { BoxedExpression, BoxedSubstitution, BoxedDomain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOption, SemiBoxedExpression, Substitution } from '../public';
3
+ import { BoxedExpression, BoxedSubstitution, BoxedDomain, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOptions, SemiBoxedExpression, Substitution } from '../public';
4
4
  export declare class BoxedPattern extends AbstractBoxedExpression implements Pattern {
5
5
  _pattern: BoxedExpression;
6
- _canonicalPattern: BoxedExpression | undefined;
7
6
  constructor(ce: IComputeEngine, pattern: LatexString | SemiBoxedExpression, metadata?: Metadata);
8
7
  get hash(): number;
9
8
  unbind(): void;
@@ -14,8 +13,10 @@ export declare class BoxedPattern extends AbstractBoxedExpression implements Pat
14
13
  set isCanonical(_val: boolean);
15
14
  isSame(rhs: BoxedExpression): boolean;
16
15
  isEqual(rhs: BoxedExpression): boolean;
17
- match(expr: BoxedExpression, options?: PatternMatchOption): BoxedSubstitution | null;
18
- test(expr: BoxedExpression, options?: PatternMatchOption): boolean;
19
- count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOption): number;
20
- subs(sub: Substitution): BoxedPattern;
16
+ match(expr: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
17
+ test(expr: BoxedExpression, options?: PatternMatchOptions): boolean;
18
+ count(exprs: Iterable<BoxedExpression>, options?: PatternMatchOptions): number;
19
+ subs(sub: Substitution, options?: {
20
+ canonical: boolean;
21
+ }): BoxedExpression;
21
22
  }
@@ -1,6 +1,6 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
- import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOption, Substitution } from '../public';
3
+ import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOptions, BoxedSubstitution } from '../public';
4
4
  /**
5
5
  * BoxedString
6
6
  */
@@ -19,5 +19,5 @@ export declare class BoxedString extends AbstractBoxedExpression {
19
19
  get string(): string;
20
20
  isEqual(rhs: BoxedExpression): boolean;
21
21
  isSame(rhs: BoxedExpression): boolean;
22
- match(rhs: BoxedExpression, _options?: PatternMatchOption): Substitution | null;
22
+ match(rhs: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
23
23
  }
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare function domainToFlags(dom: BoxedDomain | undefined | null): Partial<SymbolFlags>;
3
3
  export declare class BoxedSymbolDefinitionImpl implements BoxedSymbolDefinition {
4
4
  readonly name: string;
@@ -1,6 +1,6 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
- import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOption, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition } from '../public';
3
+ import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, DomainExpression, BoxedSubstitution } from '../public';
4
4
  /**
5
5
  * BoxedSymbol
6
6
  *
@@ -19,15 +19,20 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
19
19
  protected _name: string;
20
20
  private _hash;
21
21
  private _def;
22
- constructor(ce: IComputeEngine, name: string, metadata?: Metadata);
22
+ constructor(ce: IComputeEngine, name: string, options?: {
23
+ metadata?: Metadata;
24
+ canonical?: boolean;
25
+ });
23
26
  get hash(): number;
24
- unbind(): undefined;
27
+ unbind(): void;
25
28
  get isPure(): boolean;
29
+ get json(): Expression;
30
+ get scope(): RuntimeScope | null;
26
31
  /** A free variable either has no definition, or it has a definition, but no value */
27
32
  get isFree(): boolean;
28
33
  get isConstant(): boolean;
29
34
  get isCanonical(): boolean;
30
- set isCanonical(_va: boolean);
35
+ set isCanonical(val: boolean);
31
36
  get canonical(): BoxedExpression;
32
37
  get wikidata(): string | undefined;
33
38
  get description(): string[] | undefined;
@@ -41,17 +46,15 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
41
46
  get symbolDefinition(): BoxedSymbolDefinition | undefined;
42
47
  get functionDefinition(): BoxedFunctionDefinition | undefined;
43
48
  bind(scope: RuntimeScope | null): void;
44
- get value(): BoxedExpression;
49
+ get value(): BoxedExpression | undefined;
45
50
  set value(value: BoxedExpression | number | undefined);
46
- get numericValue(): BoxedExpression | undefined;
47
51
  get domain(): BoxedDomain;
48
- set domain(d: BoxedDomain);
52
+ set domain(inDomain: BoxedExpression | DomainExpression | BoxedDomain);
49
53
  get explicitDomain(): BoxedDomain | undefined;
50
- get json(): Expression;
51
54
  get sgn(): -1 | 0 | 1 | undefined | null;
52
55
  has(x: string | string[]): boolean;
53
56
  isSame(rhs: BoxedExpression): boolean;
54
- match(rhs: BoxedExpression, _options?: PatternMatchOption): Substitution | null;
57
+ match(rhs: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
55
58
  isEqual(rhs: BoxedExpression): boolean;
56
59
  isLess(rhs: BoxedExpression): boolean | undefined;
57
60
  isLessEqual(rhs: BoxedExpression): boolean | undefined;
@@ -81,8 +84,11 @@ export declare class BoxedSymbol extends AbstractBoxedExpression {
81
84
  get isComplex(): boolean | undefined;
82
85
  get isImaginary(): boolean | undefined;
83
86
  simplify(options?: SimplifyOptions): BoxedExpression;
84
- evaluate(options?: EvaluateOptions): BoxedExpression;
87
+ evaluate(_options?: EvaluateOptions): BoxedExpression;
85
88
  N(options?: NOptions): BoxedExpression;
86
89
  replace(rules: BoxedRuleSet, options?: ReplaceOptions): BoxedExpression | null;
87
- subs(sub: Substitution): BoxedExpression;
90
+ subs(sub: Substitution, options?: {
91
+ canonical: boolean;
92
+ }): BoxedExpression;
88
93
  }
94
+ export declare function makeCanonicalSymbol(ce: IComputeEngine, name: string): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,7 +1,7 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
- import { BoxedExpression, IComputeEngine, Metadata } from '../public';
4
+ import { BoxedExpression, IComputeEngine, Metadata, Rational } from '../public';
5
5
  /**
6
6
  * The canonical version of `serializeJsonFunction()` applies
7
7
  * additional transformations to "reverse" some of the effects
@@ -12,4 +12,4 @@ export declare function serializeJsonCanonicalFunction(ce: IComputeEngine, head:
12
12
  export declare function serializeJsonFunction(ce: IComputeEngine, head: string | BoxedExpression, args: BoxedExpression[], metadata?: Metadata): Expression;
13
13
  export declare function serializeJsonString(ce: IComputeEngine, s: string): Expression;
14
14
  export declare function serializeJsonSymbol(ce: IComputeEngine, sym: string, metadata?: Metadata): Expression;
15
- export declare function serializeJsonNumber(ce: IComputeEngine, value: number | Decimal | Complex | [number, number], metadata?: Metadata): Expression;
15
+ export declare function serializeJsonNumber(ce: IComputeEngine, value: number | Decimal | Complex | Rational, metadata?: Metadata): Expression;
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, IComputeEngine } from '../public';
4
4
  export declare function isLatexString(s: unknown): s is string;
@@ -20,11 +20,10 @@ export declare function getVars(expr: BoxedExpression): string[];
20
20
  export declare function getSymbols(expr: BoxedExpression, set: Set<string>): Set<string>;
21
21
  export declare function getSubexpressions(expr: BoxedExpression, head: string): BoxedExpression[];
22
22
  /**
23
- * For any numeric result, or when boxing numbers,
24
- * if `preferDecimal` is true, create them as Decimal number
25
- * if `preferDecimal` is false, create them as machine number
23
+ * For any numeric result, if `bignumPreferred()` is true, calculate using
24
+ * bignums. If `bignumPreferred()` is false, calculate using machine numbers
26
25
  */
27
- export declare function preferDecimal(ce: IComputeEngine): boolean;
26
+ export declare function bignumPreferred(ce: IComputeEngine): boolean;
28
27
  /** When result of a numeric evaluation is a complex number,
29
28
  * return `NaN` if not `complexallowed()`
30
29
  */
@@ -49,6 +48,7 @@ export declare function getListLike(expr: BoxedExpression): BoxedExpression[];
49
48
  * If `expr` is a number, return it as a Decimal (it might be
50
49
  * in the machine value range or not). Use `isInMachineRange()` to check.
51
50
  *
52
- * Use this instead of `machineValue()` when possible, as `machineValue` will truncate decimal numbers to machine numbers
51
+ * Use this instead of `machineValue()` when possible, as `machineValue` will
52
+ * truncate bignums to machine numbers
53
53
  */
54
- export declare function decimalValue(ce: IComputeEngine, expr: Expression | null | undefined): Decimal | null;
54
+ export declare function bignumValue(ce: IComputeEngine, expr: Expression | null | undefined): Decimal | null;
@@ -0,0 +1,18 @@
1
+ /* 0.9.0 */
2
+ export declare function validateArgumentCount(ce: IComputeEngine, ops: BoxedExpression[], count: number): BoxedExpression[];
3
+ /**
4
+ * Validation of arguments is normally done by checking the signature of the
5
+ * function vs the arguments of the expression. However, we have a fastpath
6
+ * for some common operations (add, multiply, power, neg, etc...) that bypasses
7
+ * the regular checks. This is its replacements. Since all those fastpath
8
+ * functions are numeric (i.e. have numeric arguments and return a numeric
9
+ * value), we do a simple numeric check of all arguments, and verify we have
10
+ * the number of expected arguments.
11
+ */
12
+ export declare function validateNumericArgs(ce: IComputeEngine, ops: SemiBoxedExpression[], count?: number): BoxedExpression[];
13
+ /** Return `null` if the `ops` match the sig. Otherwise, return an array
14
+ * of expressions indicating the mismatched arguments.
15
+ *
16
+ */
17
+ export declare function validateSignature(sig: BoxedDomain, ops: BoxedExpression[], codomain?: BoxedExpression): BoxedExpression[] | null;
18
+ export declare function validateArgument(ce: IComputeEngine, arg: BoxedExpression | undefined, expect: DomainExpression<BoxedExpression> | undefined): BoxedExpression;
@@ -1,9 +1,9 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression, MathJsonNumber } from '../math-json/math-json-format';
4
4
  import { SignalMessage, WarningSignal } from '../common/signals';
5
5
  import type { LibraryCategory, LatexDictionary, LatexDictionaryEntry, LatexString, NumberFormattingOptions, ParseLatexOptions, SerializeLatexOptions } from './latex-syntax/public';
6
- import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, SymbolTable, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, Substitution, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, BoxedLambdaExpression, FunctionDefinition } from './public';
6
+ import { AssumeResult, BoxedExpression, BoxedFunctionDefinition, BoxedSymbolDefinition, IComputeEngine, SymbolTable, ExpressionMapInterface, NumericMode as NumericMode, Pattern, RuntimeScope, Scope, SemiBoxedExpression, SymbolDefinition, BoxedRuleSet, Rule, JsonSerializationOptions, ComputeEngineStats, Metadata, BoxedDomain, DomainExpression, FunctionDefinition, Rational, BoxedSubstitution } from './public';
7
7
  /**
8
8
  *
9
9
  * To use the CortexJS Compute Engine, create a `ComputeEngine` instance.
@@ -29,8 +29,6 @@ export declare class ComputeEngine implements IComputeEngine {
29
29
  /** @internal */
30
30
  readonly _ONE: BoxedExpression;
31
31
  /** @internal */
32
- readonly _TWO: BoxedExpression;
33
- /** @internal */
34
32
  readonly _HALF: BoxedExpression;
35
33
  /** @internal */
36
34
  readonly _NEGATIVE_ONE: BoxedExpression;
@@ -45,19 +43,19 @@ export declare class ComputeEngine implements IComputeEngine {
45
43
  /** @internal */
46
44
  readonly _COMPLEX_INFINITY: BoxedExpression;
47
45
  /** @internal */
48
- _DECIMAL_NAN: Decimal;
46
+ _BIGNUM_NAN: Decimal;
49
47
  /** @internal */
50
- _DECIMAL_ZERO: Decimal;
48
+ _BIGNUM_ZERO: Decimal;
51
49
  /** @internal */
52
- _DECIMAL_ONE: Decimal;
50
+ _BIGNUM_ONE: Decimal;
53
51
  /** @internal */
54
- _DECIMAL_TWO: Decimal;
52
+ _BIGNUM_TWO: Decimal;
55
53
  /** @internal */
56
- _DECIMAL_HALF: Decimal;
54
+ _BIGNUM_HALF: Decimal;
57
55
  /** @internal */
58
- _DECIMAL_PI: Decimal;
56
+ _BIGNUM_PI: Decimal;
59
57
  /** @internal */
60
- _DECIMAL_NEGATIVE_ONE: Decimal;
58
+ _BIGNUM_NEGATIVE_ONE: Decimal;
61
59
  /** @internal */
62
60
  private _precision;
63
61
  /** @internal */
@@ -67,7 +65,7 @@ export declare class ComputeEngine implements IComputeEngine {
67
65
  /** @internal */
68
66
  private _tolerance;
69
67
  /** @internal */
70
- private _decimalTolerance;
68
+ private _bignumTolerance;
71
69
  /** @internal */
72
70
  private _cache;
73
71
  /** @internal */
@@ -76,6 +74,14 @@ export declare class ComputeEngine implements IComputeEngine {
76
74
  private _cost?;
77
75
  /** @internal */
78
76
  private _jsonSerializationOptions;
77
+ /**
78
+ * During certain operations (serializing to LaTeX, constructing error
79
+ * messages) we need to use a "raw" JSON serialization without any customization. Setting the `_useRawJsonSerializationOptions` will bypass
80
+ * the `_jsonSerializationOptions` and use `_rawJsonSerializationOptions`
81
+ * instead
82
+ * @internal */
83
+ private _useRawJsonSerializationOptions;
84
+ private _rawJsonSerializationOptions;
79
85
  /** The domain of unknown symbols. If `null` unknown symbols do not have a
80
86
  * definition automatically associated with them.
81
87
  *
@@ -127,9 +133,10 @@ export declare class ComputeEngine implements IComputeEngine {
127
133
  * be the `'core'` dictionary which include some basic definitions such
128
134
  * as domains (`Boolean`, `Number`, etc...) that are used by later dictionaries.
129
135
  *
130
- * @param options.numericMode The default mode is `auto`. Use `machine` to only
131
- * use 64-bit float, use `decimal` to always use arbitrary precision floating
132
- * point numbers or `complex` for complex numbers.
136
+ * @param options.numericMode The default mode is `"auto"`. Use `"machine"`
137
+ * to perform numeric calculations using 64-bit floats. Use `"bignum"` to
138
+ * perform calculations using arbitrary precision floating point numbers.
139
+ * Use `"auto"` or `"complex"` to allow calculations on complex numbers.
133
140
  *
134
141
  * @param options.numericPrecision Specific how many digits of precision for the
135
142
  * numeric calculations. Default is 100.
@@ -163,13 +170,15 @@ export declare class ComputeEngine implements IComputeEngine {
163
170
  _unregister(_expr: BoxedExpression): void;
164
171
  get stats(): ComputeEngineStats;
165
172
  /** @internal */
166
- _decimal: Decimal.Constructor;
167
- /** The precision, or number of significant digits, for numeric calculations
168
- * such as when calling `ce.N()`.
173
+ _bignum: Decimal.Constructor;
174
+ /** The precision, or number of significant digits, of numeric
175
+ * calculations when the numeric mode is `"auto"` or `"bignum"`.
169
176
  *
170
- * To make calculations using more digits, at the cost of expended memory
177
+ * To make calculations using more digits, at the cost of expanded memory
171
178
  * usage and slower computations, set the `precision` higher.
172
179
  *
180
+ * If the numeric mode is not `"auto"` or `"bignum"`, it is set to `"auto"`.
181
+ *
173
182
  * Trigonometric operations are accurate for precision up to 1,000.
174
183
  *
175
184
  */
@@ -201,7 +210,7 @@ export declare class ComputeEngine implements IComputeEngine {
201
210
  get tolerance(): number;
202
211
  set tolerance(val: number);
203
212
  /** @internal */
204
- decimal(a: Decimal.Value): Decimal;
213
+ bignum(a: Decimal.Value): Decimal;
205
214
  /** @internal */
206
215
  complex(a: number | Complex, b?: number): Complex;
207
216
  /** Replace a number that is close to 0 with the exact integer 0.
@@ -230,7 +239,7 @@ export declare class ComputeEngine implements IComputeEngine {
230
239
  * of the argument or the codomain. However, it is useful during parsing
231
240
  * to differentiate between symbols that might represent a function application, e.g. `f` vs `x`.
232
241
  */
233
- lookupFunction(head: string, scope?: RuntimeScope): undefined | BoxedFunctionDefinition;
242
+ lookupFunction(head: string | BoxedExpression, scope?: RuntimeScope | null): undefined | BoxedFunctionDefinition;
234
243
  /**
235
244
  * Add (or replace) a definition for a symbol in the current scope.
236
245
  */
@@ -252,6 +261,12 @@ export declare class ComputeEngine implements IComputeEngine {
252
261
  /** Remove the topmost scope from the scope stack.
253
262
  */
254
263
  popScope(): void;
264
+ set(identifiers: {
265
+ [identifier: string]: SemiBoxedExpression;
266
+ }): void;
267
+ let(identifiers: {
268
+ [identifier: string]: SymbolDefinition | FunctionDefinition;
269
+ }): void;
255
270
  get assumptions(): ExpressionMapInterface<boolean>;
256
271
  /**
257
272
  * Return false if the execution should stop.
@@ -280,35 +295,51 @@ export declare class ComputeEngine implements IComputeEngine {
280
295
  signal(sig: WarningSignal): void;
281
296
  /** @internal */
282
297
  cache<T>(cacheName: string, build: () => T, purge: (T: any) => T | undefined): T;
283
- box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression): BoxedExpression;
298
+ box(expr: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression, options?: {
299
+ canonical?: boolean;
300
+ }): BoxedExpression;
284
301
  fn(head: string, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
285
302
  /** @internal */
286
303
  _fn(head: string | BoxedExpression, ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
287
304
  error(message: ['invalid-domain', ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedDomain;
288
305
  error(message: string | [string, ...SemiBoxedExpression[]], where?: SemiBoxedExpression): BoxedExpression;
306
+ hold(expr: SemiBoxedExpression): BoxedExpression;
289
307
  add(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
290
- mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
291
- power(base: BoxedExpression, exponent: number | [number, number] | BoxedExpression, metadata?: Metadata): BoxedExpression;
292
- inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
293
308
  negate(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
309
+ mul(ops: BoxedExpression[], metadata?: Metadata): BoxedExpression;
294
310
  divide(num: BoxedExpression, denom: BoxedExpression, metadata?: Metadata): BoxedExpression;
311
+ sqrt(base: BoxedExpression, metadata?: Metadata): BoxedExpression;
312
+ power(base: BoxedExpression, exponent: number | Rational | BoxedExpression, metadata?: Metadata): BoxedExpression;
313
+ inverse(expr: BoxedExpression, metadata?: Metadata): BoxedExpression;
295
314
  pair(first: BoxedExpression, second: BoxedExpression, metadata?: Metadata): BoxedExpression;
296
315
  tuple(elements: BoxedExpression[], metadata?: Metadata): BoxedExpression;
297
316
  string(s: string, metadata?: Metadata): BoxedExpression;
298
- symbol(name: string, metadata?: Metadata): BoxedExpression;
317
+ symbol(name: string, options?: {
318
+ metadata?: Metadata;
319
+ canonical?: boolean;
320
+ }): BoxedExpression;
299
321
  domain(domain: BoxedExpression | DomainExpression | BoxedDomain, metadata?: Metadata): BoxedDomain;
300
- lambda(expr: SemiBoxedExpression, sig: BoxedDomain): BoxedLambdaExpression;
301
- number(value: number | MathJsonNumber | Decimal | Complex | [num: number, denom: number], metadata?: Metadata): BoxedExpression;
322
+ number(value: number | string | MathJsonNumber | Decimal | Complex | Rational, options?: {
323
+ canonical?: boolean;
324
+ metadata?: Metadata;
325
+ }): BoxedExpression;
302
326
  rules(rules: Rule[]): BoxedRuleSet;
303
327
  pattern(expr: LatexString | SemiBoxedExpression): Pattern;
304
- parse(latex: LatexString | string): BoxedExpression;
305
- parse(s: null): null;
306
- parse(latex: LatexString | string | null): null | BoxedExpression;
328
+ parse(latex: LatexString | string, options?: {
329
+ canonical?: boolean;
330
+ }): BoxedExpression;
331
+ parse(s: null, options?: {
332
+ canonical?: boolean;
333
+ }): null;
334
+ parse(latex: LatexString | string | null, options?: {
335
+ canonical?: boolean;
336
+ }): null | BoxedExpression;
307
337
  serialize(x: Expression | BoxedExpression): string;
308
338
  get latexOptions(): NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions;
309
339
  set latexOptions(opts: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>);
310
- get jsonSerializationOptions(): JsonSerializationOptions;
340
+ get jsonSerializationOptions(): Readonly<JsonSerializationOptions>;
311
341
  set jsonSerializationOptions(val: Partial<JsonSerializationOptions>);
342
+ rawJson(expr: BoxedExpression): Expression;
312
343
  /**
313
344
  * Return a list of all the assumptions that match a pattern.
314
345
  *
@@ -318,7 +349,7 @@ export declare class ComputeEngine implements IComputeEngine {
318
349
  * // -> [{'val': 0}]
319
350
  * ```
320
351
  */
321
- ask(pattern: LatexString | SemiBoxedExpression): Substitution[];
352
+ ask(pattern: LatexString | SemiBoxedExpression): BoxedSubstitution[];
322
353
  infer(symbol: BoxedExpression | string, _domain: BoxedDomain | DomainExpression): AssumeResult;
323
354
  assume(symbol: LatexString | SemiBoxedExpression, domainValue: BoxedDomain | DomainExpression | Expression | BoxedExpression): AssumeResult;
324
355
  assume(predicate: LatexString | SemiBoxedExpression): AssumeResult;
@@ -1,3 +1,3 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare function costFunction(expr: BoxedExpression): number;
3
3
  export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -1,11 +1,11 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { BoxedExpression } from './public';
4
4
  /** Quickly determine the numeric domain of a number or constant
5
5
  * For the symbols, this is a hard-coded optimization that doesn't rely on the
6
6
  * dictionaries. The regular path is in `internalDomain()`
7
7
  */
8
- export declare function inferNumericDomain(value: number | Decimal | Complex | [numer: number, denom: number]): string;
8
+ export declare function inferNumericDomain(value: number | Decimal | Complex | [numer: number, denom: number] | [numer: Decimal, denom: Decimal]): string;
9
9
  /**
10
10
  * Simple description of a numeric domain as a base domain, a min and
11
11
  * max value, possibly open ends, and some excluded values.
@@ -22,9 +22,3 @@ export declare type NumericDomainInfo = {
22
22
  */
23
23
  multiple?: [period: number, domain: BoxedExpression, phase: number];
24
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;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { WarningSignal } from '../../../common/signals';
3
3
  export declare type CommonEntry = {
4
4
  name?: string;
@@ -1,4 +1,4 @@
1
- /* 0.8.0 */
1
+ /* 0.9.0 */
2
2
  import { Serializer } from './serializer';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { WarningSignalHandler } from '../../common/signals';