@cortex-js/compute-engine 0.25.0 → 0.26.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 (152) hide show
  1. package/dist/compute-engine.esm.js +27153 -25341
  2. package/dist/compute-engine.js +27124 -25300
  3. package/dist/compute-engine.min.esm.js +88 -23
  4. package/dist/compute-engine.min.js +88 -23
  5. package/dist/math-json.esm.js +42 -196
  6. package/dist/math-json.js +42 -196
  7. package/dist/math-json.min.esm.js +42 -196
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +30 -4
  10. package/dist/types/common/buffer.d.ts +9 -0
  11. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  12. package/dist/types/common/one-of.d.ts +9 -0
  13. package/dist/types/common/signals.d.ts +1 -1
  14. package/dist/types/common/styled-text.d.ts +28 -0
  15. package/dist/types/common/suggest.d.ts +1 -0
  16. package/dist/types/common/syntax-highlighter.d.ts +40 -0
  17. package/dist/types/common/terminal.d.ts +19 -0
  18. package/dist/types/common/type/parse.d.ts +4 -0
  19. package/dist/types/common/type/primitive.d.ts +8 -0
  20. package/dist/types/common/type/serialize.d.ts +2 -0
  21. package/dist/types/common/type/subtype.d.ts +6 -0
  22. package/dist/types/common/type/types.d.ts +249 -0
  23. package/dist/types/common/type/utils.d.ts +39 -0
  24. package/dist/types/common/utils.d.ts +2 -1
  25. package/dist/types/compute-engine/assume.d.ts +13 -13
  26. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +71 -47
  27. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  28. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -0
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +12 -0
  30. package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +16 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +20 -0
  32. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  33. package/dist/types/compute-engine/boxed-expression/box.d.ts +13 -71
  34. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +31 -13
  35. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +66 -45
  36. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +41 -37
  37. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
  38. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +13 -9
  39. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +34 -66
  40. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +63 -41
  41. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +44 -27
  42. package/dist/types/compute-engine/boxed-expression/cache.d.ts +6 -0
  43. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  45. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  46. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -6
  48. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  49. package/dist/types/compute-engine/boxed-expression/hold.d.ts +9 -0
  50. package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -4
  51. package/dist/types/compute-engine/boxed-expression/negate.d.ts +10 -0
  52. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +5 -39
  53. package/dist/types/compute-engine/boxed-expression/order.d.ts +26 -14
  54. package/dist/types/compute-engine/{symbolic → boxed-expression}/polynomials.d.ts +11 -15
  55. package/dist/types/compute-engine/{symbolic → boxed-expression}/product.d.ts +18 -24
  56. package/dist/types/compute-engine/boxed-expression/public.d.ts +947 -656
  57. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  58. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
  59. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +6 -0
  60. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  61. package/dist/types/compute-engine/{solve.d.ts → boxed-expression/solve.d.ts} +5 -5
  62. package/dist/types/compute-engine/{symbolic → boxed-expression}/tensor-fields.d.ts +3 -3
  63. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  64. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +10 -0
  65. package/dist/types/compute-engine/boxed-expression/utils.d.ts +22 -16
  66. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -7
  67. package/dist/types/compute-engine/collection-utils.d.ts +24 -2
  68. package/dist/types/compute-engine/compile.d.ts +3 -3
  69. package/dist/types/compute-engine/compute-engine.d.ts +133 -165
  70. package/dist/types/compute-engine/cost-function.d.ts +11 -1
  71. package/dist/types/compute-engine/function-utils.d.ts +5 -5
  72. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
  87. package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -30
  88. package/dist/types/compute-engine/latex-syntax/public.d.ts +22 -18
  89. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
  90. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -8
  92. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  93. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -2
  94. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  95. package/dist/types/compute-engine/library/collections.d.ts +24 -1
  96. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  97. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  98. package/dist/types/compute-engine/library/core.d.ts +1 -3
  99. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  100. package/dist/types/compute-engine/library/library.d.ts +2 -4
  101. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  102. package/dist/types/compute-engine/library/logic.d.ts +5 -1
  103. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  104. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  105. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  106. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  107. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  108. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  109. package/dist/types/compute-engine/library/utils.d.ts +46 -40
  110. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +59 -0
  111. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +77 -0
  112. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +58 -0
  113. package/dist/types/compute-engine/numeric-value/public.d.ts +110 -0
  114. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  115. package/dist/types/compute-engine/numerics/bignum.d.ts +12 -0
  116. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  117. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  118. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +19 -0
  119. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +4 -14
  120. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +6 -9
  121. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -59
  123. package/dist/types/compute-engine/numerics/primes.d.ts +3 -3
  124. package/dist/types/compute-engine/numerics/rationals.d.ts +29 -13
  125. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  127. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  128. package/dist/types/compute-engine/public.d.ts +8 -4
  129. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -2
  130. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  131. package/dist/types/compute-engine/{simplify-rules.d.ts → symbolic/simplify-rules.d.ts} +1 -1
  132. package/dist/types/compute-engine/{symbolic → tensor}/tensors.d.ts +3 -3
  133. package/dist/types/compute-engine.d.ts +4 -2
  134. package/dist/types/math-json/identifiers.d.ts +11 -0
  135. package/dist/types/math-json/{math-json-format.d.ts → types.d.ts} +4 -9
  136. package/dist/types/math-json/utils.d.ts +15 -23
  137. package/dist/types/math-json.d.ts +3 -3
  138. package/package.json +11 -11
  139. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -48
  140. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +0 -40
  141. package/dist/types/compute-engine/domain-utils.d.ts +0 -19
  142. package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
  143. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -17
  144. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
  145. package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
  146. package/dist/types/compute-engine/library/domains.d.ts +0 -16
  147. package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
  148. package/dist/types/compute-engine/rules.d.ts +0 -20
  149. package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
  150. package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
  151. package/dist/types/compute-engine/symbolic/negate.d.ts +0 -11
  152. package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
@@ -1,87 +1,27 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { IComputeEngine, SemiBoxedExpression, BoxedExpression, Metadata, CanonicalOptions } from './public';
4
- import { MathJsonNumber } from '../../math-json/math-json-format';
5
- import { Rational } from '../numerics/rationals';
4
+ import { MathJsonIdentifier } from '../../math-json/types';
5
+ import { NumericValue } from '../numeric-value/public';
6
6
  /**
7
- * ### THEORY OF OPERATIONS
8
- *
9
- * 1/ Boxing does not depend on the numeric mode. The numeric mode could be
10
- * changed later, but the previously boxed numbers could not be retroactively
11
- * upgraded.
12
- *
13
- * The `numericMode` is taken into account only during evaluation.
14
- *
15
- * Therefore, a boxed expression may contain a mix of number representations.
16
- *
17
- * 2/ The result of boxing is canonical by default.
18
- *
19
- * This is the most common need (i.e. as soon as you want to evaluate an
20
- * expression you need a canonical expression). Creating a boxed expression
21
- * which is canonical from the start avoid going through an intermediary step
22
- * with a non-canonical expression.
23
- *
24
- * 3/ When boxing (and canonicalizing), if the function is "scoped", a new
25
- * scope is created before the canonicalization, so that any declaration
26
- * are done within that scope. Example of scoped functions include `Block`
27
- * and `Sum`.
28
- *
29
- * 4/ When implementing an `evaluate()`:
30
- * - if `bignumPreferred()` all operations should be done in bignum and complex,
31
- * otherwise, they should all be done in machine numbers and complex.
32
- * - if not `complexAllowed()`, return `NaN` if a complex value is encountered
33
- * - if a `Sqrt` (of a rational) is encountered, preserve it
34
- * - if a `hold` constant is encountered, preserve it
35
- * - if a rational is encountered, preserve it
36
- * - if one of the arguments is not exact, return an approximation
37
- *
38
- * EXACT
39
- * - 2 + 5 -> 7
40
- * - 2 + 5/7 -> 19/7
41
- * - 2 + √2 -> 2 + √2
42
- * - 2 + √(5/7) -> 2 + √(5/7)
43
- * - 5/7 + 9/11 -> 118/77
44
- * - 5/7 + √2 -> 5/7 + √2
45
- * - 10/14 + √(18/9) -> 5/7 + √2
46
- * - √2 + √5 -> √2 + √5
47
- * - √2 + √2 -> 2√2
48
- * - sin(2) -> sin(2)
49
- * - sin(pi/3) -> √3/2
50
- *
51
- * APPROXIMATE
52
- * - 2 + 2.1 -> 4.1
53
- * - 2 + √2.1 -> 3.44914
54
- * - 5/7 + √2.1 -> 2.16342
55
- * - sin(2) + √2.1 -> 2.35844
56
- */
57
- /**
58
- * Return a boxed number representing `num`.
59
- *
60
- * Note: `boxNumber()` should only be called from `ce.number()` in order to
61
- * benefit from number expression caching.
62
- */
63
- export declare function boxNumber(ce: IComputeEngine, num: MathJsonNumber | number | string | Complex | Decimal | Rational | [Decimal, Decimal], options?: {
64
- metadata?: Metadata;
65
- canonical?: boolean;
66
- }): BoxedExpression | null;
67
- /**
68
- * Given a head and a set of arguments, return a boxed function expression.
7
+ * Given a name and a set of arguments, return a boxed function expression.
69
8
  *
70
9
  * If available, preserve LaTeX and wikidata metadata in the boxed expression.
71
10
  *
72
11
  * Note that `boxFunction()` should only be called from `ce.function()`
73
12
  */
74
- export declare function boxFunction(ce: IComputeEngine, head: string, ops: readonly SemiBoxedExpression[], options?: {
13
+ export declare function boxFunction(ce: IComputeEngine, name: MathJsonIdentifier, ops: readonly SemiBoxedExpression[], options?: {
75
14
  metadata?: Metadata;
76
15
  canonical?: CanonicalOptions;
16
+ structural?: boolean;
77
17
  }): BoxedExpression;
78
18
  /**
79
19
  * Notes about the boxed form:
80
20
  *
81
- * [1] Expression with a head of `Number`, `String`, `Symbol` and `Dictionary`
21
+ * [1] Expression with an operator of `Number`, `String`, `Symbol` and `Dictionary`
82
22
  * are converted to the corresponding atomic expression.
83
23
  *
84
- * [2] Expressions with a head of `Complex` are converted to a (complex) number
24
+ * [2] Expressions with an operator of `Complex` are converted to a (complex) number
85
25
  * or a `Add`/`Multiply` expression.
86
26
  *
87
27
  * The precedence of `Complex` (for serialization) is sometimes the
@@ -89,8 +29,8 @@ export declare function boxFunction(ce: IComputeEngine, head: string, ops: reado
89
29
  * `Multiply` (when im or re === 0). Using a number or an explicit
90
30
  * `Add`/`Multiply` expression avoids this ambiguity.
91
31
  *
92
- * [3] An expression with a `Rational` head is converted to a rational number.
93
- * if possible, to a `Divide` otherwise.
32
+ * [3] An expression with a `Rational` operator is converted to a rational
33
+ * number if possible, to a `Divide` otherwise.
94
34
  *
95
35
  * [4] A `Negate` function applied to a number literal is converted to a number.
96
36
  *
@@ -100,6 +40,8 @@ export declare function boxFunction(ce: IComputeEngine, head: string, ops: reado
100
40
  * Note that this function should only be called from `ce.box()`
101
41
  *
102
42
  */
103
- export declare function box(ce: IComputeEngine, expr: null | undefined | Decimal | Complex | Rational | SemiBoxedExpression, options?: {
43
+ export declare function box(ce: IComputeEngine, expr: null | undefined | NumericValue | SemiBoxedExpression, options?: {
104
44
  canonical?: CanonicalOptions;
45
+ structural?: boolean;
105
46
  }): BoxedExpression;
47
+ export declare function toBigint(x: Complex | Decimal | SemiBoxedExpression): bigint | null;
@@ -1,5 +1,7 @@
1
- /* 0.25.0 */
2
- import { BoxedExpression } from './public';
1
+ /* 0.26.0 */
2
+ import type { BoxedExpression, CollectionHandlers, CompiledExpression, EvaluateOptions, Sign } from './public';
3
+ import { Type } from '../../common/type/types';
4
+ import { OneOf } from '../../common/one-of';
3
5
  export declare class _BoxedFunctionDefinition implements BoxedFunctionDefinition {
4
6
  engine: IComputeEngine;
5
7
  scope: RuntimeScope;
@@ -9,21 +11,37 @@ export declare class _BoxedFunctionDefinition implements BoxedFunctionDefinition
9
11
  threadable: boolean;
10
12
  associative: boolean;
11
13
  commutative: boolean;
14
+ commutativeOrder: ((a: BoxedExpression, b: BoxedExpression) => number) | undefined;
12
15
  idempotent: boolean;
13
16
  involution: boolean;
14
17
  pure: boolean;
15
- inert: boolean;
16
- numeric: boolean;
17
18
  complexity: number;
18
- hold: Hold;
19
- dynamic: boolean;
20
- signature: BoxedFunctionSignature;
21
- iterator?: (expr: BoxedExpression, start?: number, count?: number) => Iterator<BoxedExpression>;
22
- at?: (expr: BoxedExpression, index: number | string) => undefined | BoxedExpression;
23
- size?: (expr: BoxedExpression) => number;
24
- keys?: (expr: BoxedExpression) => undefined | Iterator<string>;
25
- indexOf?: (expr: BoxedExpression, target: BoxedExpression, from?: number) => number | string | undefined;
19
+ hold: boolean;
20
+ signature: Type;
21
+ inferredSignature: boolean;
22
+ type?: (ops: ReadonlyArray<BoxedExpression>, options: {
23
+ engine: IComputeEngine;
24
+ }) => Type | undefined;
25
+ sgn?: (ops: ReadonlyArray<BoxedExpression>, options: {
26
+ engine: IComputeEngine;
27
+ }) => Sign | undefined;
28
+ eq?: (a: BoxedExpression, b: BoxedExpression) => boolean | undefined;
29
+ neq?: (a: BoxedExpression, b: BoxedExpression) => boolean | undefined;
30
+ even?: (ops: ReadonlyArray<BoxedExpression>, options: {
31
+ engine: IComputeEngine;
32
+ }) => boolean | undefined;
33
+ canonical?: (ops: ReadonlyArray<BoxedExpression>, options: {
34
+ engine: IComputeEngine;
35
+ }) => BoxedExpression | null;
36
+ evaluate?: (ops: ReadonlyArray<BoxedExpression>, options: EvaluateOptions & {
37
+ engine: IComputeEngine;
38
+ }) => BoxedExpression | undefined;
39
+ evalDimension?: (ops: ReadonlyArray<BoxedExpression>, options: {
40
+ engine: IComputeEngine;
41
+ }) => BoxedExpression;
42
+ compile?: (expr: BoxedExpression) => CompiledExpression;
43
+ collection?: Partial<CollectionHandlers>;
26
44
  constructor(ce: IComputeEngine, name: string, def: FunctionDefinition);
27
45
  reset(): void;
28
46
  }
29
- export declare function makeFunctionDefinition(engine: IComputeEngine, name: string, def: FunctionDefinition | BoxedFunctionDefinition): BoxedFunctionDefinition;
47
+ export declare function makeFunctionDefinition(engine: IComputeEngine, name: string, def: OneOf<[FunctionDefinition | BoxedFunctionDefinition]>): BoxedFunctionDefinition;
@@ -1,47 +1,55 @@
1
- /* 0.25.0 */
2
- import { Decimal } from 'decimal.js';
1
+ /* 0.26.0 */
2
+ import type { BoxedFunctionDefinition, IComputeEngine, BoxedRuleSet, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOptions, RuntimeScope, BoxedSubstitution, EvaluateOptions, BoxedBaseDefinition, Rule, CanonicalOptions } from '../public';
3
+ import type { BoxedExpression, Sign } from './public';
4
+ import { NumericValue } from '../numeric-value/public';
3
5
  import { _BoxedExpression } from './abstract-boxed-expression';
4
- import { Expression } from '../../math-json/math-json-format';
5
- import { BoxedFunctionDefinition, IComputeEngine, NOptions, BoxedRuleSet, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedSubstitution, EvaluateOptions, BoxedBaseDefinition, Hold, Rule, CanonicalOptions } from '../public';
6
- import { BoxedExpression, SemiBoxedExpression } from './public';
6
+ import { Type } from '../../common/type/types';
7
7
  /**
8
8
  * A boxed function represent an expression that can be
9
9
  * represented by a function call.
10
10
  *
11
- * It is composed of a head (the name of the function) and
11
+ * It is composed of an operator (the name of the function) and
12
12
  * a list of arguments.
13
13
  *
14
- * It has a definition associated with it, based
15
- * on the head. The definition contains the signature of the function,
16
- * and the implementation of the function.
14
+ * It has a definition associated with it, based on the operator.
15
+ * The definition contains the signature of the function, and the
16
+ * implementation of the function.
17
17
  *
18
18
  * @noInheritDoc
19
19
  *
20
20
  */
21
21
  export declare class BoxedFunction extends _BoxedExpression {
22
- private readonly _head;
22
+ private readonly _name;
23
23
  private readonly _ops;
24
24
  private _canonical;
25
25
  private _scope;
26
- private _def;
26
+ _def: BoxedFunctionDefinition | undefined;
27
27
  private _isPure;
28
- private _result;
28
+ private _isStructural;
29
29
  private _hash;
30
- constructor(ce: IComputeEngine, head: string | BoxedExpression, ops: ReadonlyArray<BoxedExpression>, options?: {
30
+ private _value;
31
+ private _valueN;
32
+ private _sgn;
33
+ private _type;
34
+ constructor(ce: IComputeEngine, name: string, ops: ReadonlyArray<BoxedExpression>, options?: {
31
35
  metadata?: Metadata;
32
36
  canonical?: boolean;
37
+ structural?: boolean;
33
38
  });
34
39
  get hash(): number;
35
- infer(domain: BoxedDomain): boolean;
40
+ infer(t: Type): boolean;
36
41
  bind(): void;
37
42
  reset(): void;
38
- get isExact(): boolean;
39
43
  get isCanonical(): boolean;
40
44
  set isCanonical(val: boolean);
41
45
  get isPure(): boolean;
46
+ /** The value of the function is constant if the function is
47
+ * pure, and all its arguments are constant.
48
+ */
49
+ get isConstant(): boolean;
42
50
  get json(): Expression;
43
51
  get scope(): RuntimeScope | null;
44
- get head(): string | BoxedExpression;
52
+ get operator(): string;
45
53
  get ops(): ReadonlyArray<BoxedExpression>;
46
54
  get nops(): number;
47
55
  get op1(): BoxedExpression;
@@ -49,45 +57,58 @@ export declare class BoxedFunction extends _BoxedExpression {
49
57
  get op3(): BoxedExpression;
50
58
  get isValid(): boolean;
51
59
  get canonical(): BoxedExpression;
60
+ get structural(): BoxedExpression;
61
+ get isStructural(): boolean;
62
+ toNumericValue(): [NumericValue, BoxedExpression];
52
63
  subs(sub: Substitution, options?: {
53
64
  canonical?: CanonicalOptions;
54
65
  }): BoxedExpression;
55
- replace(rules: BoxedRuleSet | Rule | Rule[], options?: ReplaceOptions): BoxedExpression | null;
56
- has(x: string | string[]): boolean;
57
- /** `isSame` is structural/symbolic equality */
58
- isSame(rhs: BoxedExpression): boolean;
59
- match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
66
+ replace(rules: BoxedRuleSet | Rule | Rule[], options?: Partial<ReplaceOptions>): BoxedExpression | null;
67
+ match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
68
+ has(v: string | string[]): boolean;
69
+ get sgn(): Sign | undefined;
70
+ get isNaN(): boolean | undefined;
71
+ get isInfinity(): boolean | undefined;
72
+ get isFinite(): boolean | undefined;
73
+ get isOne(): boolean | undefined;
74
+ get isNegativeOne(): boolean | undefined;
75
+ get isPositive(): boolean | undefined;
76
+ get isNonNegative(): boolean | undefined;
77
+ get isNegative(): boolean | undefined;
78
+ get isNonPositive(): boolean | undefined;
79
+ get numerator(): BoxedExpression;
80
+ get denominator(): BoxedExpression;
81
+ get numeratorDenominator(): [BoxedExpression, BoxedExpression];
82
+ neg(): BoxedExpression;
83
+ inv(): BoxedExpression;
84
+ abs(): BoxedExpression;
85
+ add(rhs: number | BoxedExpression): BoxedExpression;
86
+ mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
87
+ div(rhs: number | BoxedExpression): BoxedExpression;
88
+ pow(exp: number | BoxedExpression): BoxedExpression;
89
+ root(exp: number | BoxedExpression): BoxedExpression;
90
+ sqrt(): BoxedExpression;
91
+ ln(semiBase?: number | BoxedExpression): BoxedExpression;
60
92
  get complexity(): number | undefined;
61
93
  get baseDefinition(): BoxedBaseDefinition | undefined;
62
94
  get functionDefinition(): BoxedFunctionDefinition | undefined;
63
- /** `isEqual` is mathematical equality */
64
- isEqual(rhs: BoxedExpression): boolean;
65
95
  get isNumber(): boolean | undefined;
66
96
  get isInteger(): boolean | undefined;
67
97
  get isRational(): boolean | undefined;
68
- get isAlgebraic(): boolean | undefined;
69
98
  get isReal(): boolean | undefined;
70
- get isExtendedReal(): boolean | undefined;
71
- get isComplex(): boolean | undefined;
72
- get isImaginary(): boolean | undefined;
73
- get domain(): BoxedDomain | undefined;
74
- simplify(options?: SimplifyOptions): BoxedExpression;
99
+ get isFunctionExpression(): boolean;
100
+ /** The type of the value of the function */
101
+ get type(): Type;
102
+ simplify(options?: Partial<SimplifyOptions>): BoxedExpression;
75
103
  evaluate(options?: EvaluateOptions): BoxedExpression;
76
- N(options?: NOptions): BoxedExpression;
104
+ N(): BoxedExpression;
77
105
  solve(vars: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
106
+ get isCollection(): boolean;
107
+ contains(rhs: BoxedExpression): boolean;
108
+ get size(): number;
109
+ each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
110
+ at(index: number): BoxedExpression | undefined;
111
+ get(index: BoxedExpression | string): BoxedExpression | undefined;
112
+ indexOf(expr: BoxedExpression): number;
113
+ subsetOf(rhs: BoxedExpression, strict: boolean): boolean;
78
114
  }
79
- export declare function makeCanonicalFunction(ce: IComputeEngine, head: string | BoxedExpression, ops: ReadonlyArray<SemiBoxedExpression>, metadata?: Metadata): BoxedExpression;
80
- /** Apply the function `f` to elements of `xs`, except to the elements
81
- * described by `skip`:
82
- * - `all`: don't apply f to any elements
83
- * - `none`: apply `f` to all elements
84
- * - `first`: apply `f` to all elements except the first
85
- * - `rest`: apply `f` to the first element, skip the others
86
- * - 'last': apply `f` to all elements except the last
87
- * - 'most': apply `f` to the last elements, skip the others
88
- *
89
- * Account for `Hold`, `ReleaseHold`, `Sequence`, `Symbol` and `Nothing`.
90
- *
91
- * If `f` returns `null`, the element is not added to the result
92
- */
93
- export declare function holdMap(xs: ReadonlyArray<BoxedExpression>, skip: Hold, associativeHead: string, f: (x: BoxedExpression) => BoxedExpression | null): ReadonlyArray<BoxedExpression>;
@@ -1,19 +1,20 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  import { Decimal } from 'decimal.js';
3
- import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, NOptions, PatternMatchOptions, SimplifyOptions, BoxedSubstitution, EvaluateOptions, SemiBoxedExpression } from '../public';
3
+ import type { BoxedExpression, IComputeEngine, Metadata, PatternMatchOptions, BoxedSubstitution, EvaluateOptions, BoxedRuleSet, ReplaceOptions, Rule, Substitution, CanonicalOptions, SimplifyOptions, Sign } from '../public';
4
+ import type { Expression, MathJsonNumber } from '../../math-json';
5
+ import { SmallInteger } from '../numerics/numeric';
4
6
  import { Rational } from '../numerics/rationals';
7
+ import { ExactNumericValueData, NumericValue, NumericValueData } from '../numeric-value/public';
5
8
  import { _BoxedExpression } from './abstract-boxed-expression';
6
- import { Expression } from '../../math-json';
9
+ import { Type } from '../../common/type/types';
7
10
  /**
8
11
  * BoxedNumber
9
12
  *
10
13
  * @noInheritDoc
11
14
  */
12
15
  export declare class BoxedNumber extends _BoxedExpression {
13
- protected readonly _value: number | Decimal | Complex | Rational;
14
- private _domain;
16
+ protected readonly _value: SmallInteger | NumericValue;
15
17
  private _hash;
16
- protected _isCanonical: boolean;
17
18
  /**
18
19
  * By the time the constructor is called, the `value` should have been
19
20
  * screened for cases where it's a well-known value (0, NaN, +Infinity,
@@ -26,33 +27,42 @@ export declare class BoxedNumber extends _BoxedExpression {
26
27
  * We may store as a machine number if a Decimal is passed that is in machine
27
28
  * range
28
29
  */
29
- constructor(ce: IComputeEngine, value: number | Decimal | Complex | Rational, options?: {
30
+ constructor(ce: IComputeEngine, value: SmallInteger | NumericValueData | ExactNumericValueData | NumericValue, options?: {
30
31
  metadata?: Metadata;
31
32
  canonical?: boolean;
32
33
  });
33
34
  get hash(): number;
34
35
  get json(): Expression;
35
- get head(): string;
36
+ get operator(): string;
36
37
  get isPure(): boolean;
37
- get isExact(): boolean;
38
38
  get isCanonical(): boolean;
39
39
  set isCanonical(val: boolean);
40
40
  get complexity(): number;
41
- get numericValue(): number | Decimal | Complex | Rational;
42
- get domain(): BoxedDomain;
43
- get sgn(): -1 | 0 | 1 | undefined | null;
44
- isSame(rhs: BoxedExpression): boolean;
45
- isEqual(rhs: BoxedExpression): boolean;
46
- match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
47
- /** Compare this with another BoxedNumber.
48
- * `rhs` must be a BoxedNumber. Use `isEqualWithTolerance(rhs.N())`
49
- * if necessary.
50
- */
51
- isEqualWithTolerance(rhs: BoxedExpression, tolerance: number): boolean;
52
- isLess(rhs: BoxedExpression): boolean | undefined;
53
- isLessEqual(rhs: BoxedExpression): boolean | undefined;
54
- isGreater(rhs: BoxedExpression): boolean | undefined;
55
- isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
41
+ get numericValue(): number | NumericValue;
42
+ get re(): number;
43
+ get im(): number;
44
+ get bignumRe(): Decimal | undefined;
45
+ get bignumIm(): Decimal | undefined;
46
+ neg(): BoxedExpression;
47
+ inv(): BoxedExpression;
48
+ abs(): BoxedExpression;
49
+ add(rhs: number | BoxedExpression): BoxedExpression;
50
+ mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
51
+ div(rhs: number | BoxedExpression): BoxedExpression;
52
+ pow(exp: number | BoxedExpression): BoxedExpression;
53
+ root(exp: number | BoxedExpression): BoxedExpression;
54
+ sqrt(): BoxedExpression;
55
+ ln(semiBase?: number | BoxedExpression): BoxedExpression;
56
+ get type(): Type;
57
+ get sgn(): Sign | undefined;
58
+ get numerator(): BoxedExpression;
59
+ get denominator(): BoxedExpression;
60
+ get numeratorDenominator(): [BoxedExpression, BoxedExpression];
61
+ subs(sub: Substitution, options?: {
62
+ canonical?: CanonicalOptions;
63
+ }): BoxedExpression;
64
+ replace(rules: BoxedRuleSet | Rule | Rule[], options?: Partial<ReplaceOptions>): BoxedExpression | null;
65
+ match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
56
66
  /** x > 0, same as `isGreater(0)` */
57
67
  get isPositive(): boolean | undefined;
58
68
  /** x >= 0, same as `isGreaterEqual(0)` */
@@ -61,28 +71,22 @@ export declare class BoxedNumber extends _BoxedExpression {
61
71
  get isNegative(): boolean | undefined;
62
72
  /** x <= 0, same as `isLessEqual(0)` */
63
73
  get isNonPositive(): boolean | undefined;
64
- get isZero(): boolean;
65
- get isNotZero(): boolean;
66
- get isOne(): boolean;
67
- get isNegativeOne(): boolean;
68
74
  get isOdd(): boolean | undefined;
69
75
  get isEven(): boolean | undefined;
70
- get isPrime(): boolean | undefined;
71
- get isComposite(): boolean | undefined;
72
76
  get isInfinity(): boolean;
73
77
  get isNaN(): boolean;
74
78
  get isFinite(): boolean;
75
79
  get isNumber(): true;
76
80
  get isInteger(): boolean;
77
81
  get isRational(): boolean;
78
- get isAlgebraic(): boolean | undefined;
79
82
  get isReal(): boolean;
80
- get isExtendedReal(): boolean;
81
- get isComplex(): boolean | undefined;
82
- get isImaginary(): boolean | undefined;
83
- get isExtendedComplex(): boolean | undefined;
83
+ is(rhs: any): boolean;
84
84
  get canonical(): BoxedExpression;
85
- simplify(_options?: SimplifyOptions): BoxedExpression;
85
+ get isStructural(): boolean;
86
+ get structural(): BoxedExpression;
87
+ toNumericValue(): [NumericValue, BoxedExpression];
88
+ simplify(options?: Partial<SimplifyOptions>): BoxedExpression;
86
89
  evaluate(options?: EvaluateOptions): BoxedExpression;
87
- N(_options?: NOptions): BoxedExpression;
90
+ N(): BoxedExpression;
88
91
  }
92
+ export declare function canonicalNumber(ce: IComputeEngine, value: number | bigint | string | Decimal | Complex | Rational | NumericValue | MathJsonNumber): number | NumericValue;
@@ -1,4 +1,4 @@
1
- /* 0.25.0 */
2
- import { BoxedExpression } from './public';
1
+ /* 0.26.0 */
2
+ import type { BoxedExpression } from './public';
3
3
  export declare function isWildcard(expr: BoxedExpression): expr is BoxedSymbol;
4
4
  export declare function wildcardName(expr: BoxedExpression): string | null;
@@ -1,7 +1,6 @@
1
- /* 0.25.0 */
2
- import { BoxedExpression, BoxedDomain, IComputeEngine, Metadata, PatternMatchOptions, BoxedSubstitution, SemiBoxedExpression } from './public';
3
- import Complex from 'complex.js';
4
- import Decimal from 'decimal.js';
1
+ /* 0.26.0 */
2
+ import { _BoxedExpression } from './abstract-boxed-expression';
3
+ import { Type } from '../../common/type/types';
5
4
  /**
6
5
  * BoxedString
7
6
  *
@@ -12,14 +11,19 @@ export declare class BoxedString extends _BoxedExpression {
12
11
  constructor(ce: IComputeEngine, expr: string, metadata?: Metadata);
13
12
  get json(): string;
14
13
  get hash(): number;
15
- get head(): string;
14
+ get operator(): string;
16
15
  get isPure(): boolean;
17
16
  get isCanonical(): boolean;
18
17
  set isCanonical(_va: boolean);
19
- get domain(): BoxedDomain;
18
+ get type(): Type;
20
19
  get complexity(): number;
21
20
  get string(): string;
22
- isEqual(rhs: BoxedExpression): boolean;
23
- isSame(rhs: BoxedExpression): boolean;
24
- match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
21
+ match(pattern: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
22
+ get isCollection(): boolean;
23
+ contains(rhs: BoxedExpression): boolean;
24
+ get size(): number;
25
+ each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
26
+ at(index: number): BoxedExpression | undefined;
27
+ get(key: string | BoxedExpression): BoxedExpression | undefined;
28
+ indexOf(expr: BoxedExpression): number;
25
29
  }
@@ -1,21 +1,28 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
+ import { Type } from '../../common/type/types';
2
3
  /**
3
4
  * ### THEORY OF OPERATIONS
4
5
  *
5
- * - The value or domain of a constant cannot be changed.
6
+ * - The value or type of a constant cannot be changed.
7
+ *
6
8
  * - If set explicitly, the value is the source of truth: it overrides any
7
- * flags.
8
- * - Once the domain has been set, it can only be changed from a numeric domain
9
- * to another numeric domain (some expressions may have been validated with
10
- * assumptions that the domain was numeric).
11
- * - When the domain is changed, the value is preserved if it is compatible
12
- * with the new domain, otherwise it is reset to no value. Flags are adjusted
13
- * to match the domain (discarded if not a numeric domain).
14
- * - When the value is changed, the domain is unaffected. If the value is not
15
- * compatible with the domain (setting a def with a numeric domain to a value
16
- * of `True` for example), the value is discarded.
9
+ * flags.
10
+ *
11
+ * - Once the type has been set, it can only be changed from a numeric type
12
+ * to another numeric type (some expressions may have been validated with
13
+ * assumptions that the just a number).
14
+ *
15
+ * - When the type is changed, the value is preserved if it is compatible
16
+ * with the new type, otherwise it is reset to no value. Flags are adjusted
17
+ * to match the type (discarded if not a numeric type).
18
+ *
19
+ * - When the value is changed, the type is unaffected. If the value is not
20
+ * compatible with the type (setting a def with a numeric type to a value
21
+ * of `True` for example), the value is discarded.
22
+ *
17
23
  * - When getting a flag, if a value is available, it is the source of truth.
18
- * Otherwise, the stored flags are (the stored flags are also set when the domain is changed)
24
+ * Otherwise, the stored flags are (the stored flags are also set when the
25
+ * type is changed)
19
26
  *
20
27
  */
21
28
  export declare class _BoxedSymbolDefinition implements BoxedSymbolDefinition {
@@ -27,69 +34,30 @@ export declare class _BoxedSymbolDefinition implements BoxedSymbolDefinition {
27
34
  readonly scope: RuntimeScope | undefined;
28
35
  private _defValue?;
29
36
  private _value;
30
- private _domain;
31
- inferredDomain: boolean;
32
- private _flags;
37
+ private _type;
38
+ inferredType: boolean;
33
39
  constant: boolean;
34
- holdUntil: 'never' | 'simplify' | 'evaluate' | 'N';
35
- prototype?: BoxedFunctionDefinition;
36
- self?: unknown;
40
+ holdUntil: 'never' | 'evaluate' | 'N';
41
+ private _flags;
42
+ eq?: (a: BoxedExpression) => boolean | undefined;
43
+ neq?: (a: BoxedExpression) => boolean | undefined;
44
+ cmp?: (a: BoxedExpression) => '=' | '>' | '<' | undefined;
45
+ collection?: Partial<CollectionHandlers>;
37
46
  constructor(ce: IComputeEngine, name: string, def: SymbolDefinition);
47
+ get isFunction(): boolean;
48
+ get isConstant(): boolean;
38
49
  /** The symbol was previously inferred, but now it has a declaration. Update the def accordingly (we can't replace defs, as other expressions may be referencing them) */
39
50
  update(def: SymbolDefinition): void;
40
51
  reset(): void;
41
52
  get value(): BoxedExpression | undefined;
42
53
  set value(val: SemiBoxedExpression | number | undefined);
43
- get domain(): BoxedDomain | undefined;
44
- set domain(domain: BoxedDomain | DomainExpression | undefined);
45
- get number(): boolean | undefined;
46
- set number(val: boolean | undefined);
47
- get integer(): boolean | undefined;
48
- set integer(val: boolean | undefined);
49
- get rational(): boolean | undefined;
50
- set rational(val: boolean | undefined);
51
- get algebraic(): boolean | undefined;
52
- set algebraic(val: boolean | undefined);
53
- get real(): boolean | undefined;
54
- set real(val: boolean | undefined);
55
- get extendedReal(): boolean | undefined;
56
- set extendedReal(val: boolean | undefined);
57
- get complex(): boolean | undefined;
58
- set complex(val: boolean | undefined);
59
- get extendedComplex(): boolean | undefined;
60
- set extendedComplex(val: boolean | undefined);
61
- get imaginary(): boolean | undefined;
62
- set imaginary(val: boolean | undefined);
63
- get positive(): boolean | undefined;
64
- set positive(val: boolean | undefined);
65
- get nonPositive(): boolean | undefined;
66
- set nonPositive(val: boolean | undefined);
67
- get negative(): boolean | undefined;
68
- set negative(val: boolean | undefined);
69
- get nonNegative(): boolean | undefined;
70
- set nonNegative(val: boolean | undefined);
71
- get zero(): boolean | undefined;
72
- set zero(val: boolean | undefined);
73
- get notZero(): boolean | undefined;
74
- set notZero(val: boolean | undefined);
75
- get one(): boolean | undefined;
76
- set one(val: boolean | undefined);
77
- get negativeOne(): boolean | undefined;
78
- set negativeOne(val: boolean | undefined);
79
- get infinity(): boolean | undefined;
80
- set infinity(val: boolean | undefined);
81
- get finite(): boolean | undefined;
82
- set finite(val: boolean | undefined);
83
- get NaN(): boolean | undefined;
84
- set NaN(val: boolean | undefined);
54
+ get type(): Type;
55
+ set type(type: Type);
56
+ get sgn(): Sign | undefined;
57
+ set sgn(val: Sign | undefined);
85
58
  get even(): boolean | undefined;
86
59
  set even(val: boolean | undefined);
87
60
  get odd(): boolean | undefined;
88
61
  set odd(val: boolean | undefined);
89
- get prime(): boolean | undefined;
90
- set prime(val: boolean | undefined);
91
- get composite(): boolean | undefined;
92
- set composite(val: boolean | undefined);
93
62
  updateFlags(flags: Partial<NumericFlags>): void;
94
63
  }
95
- export declare function domainToFlags(dom: BoxedDomain | undefined | null): Partial<NumericFlags>;