@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,8 +1,11 @@
1
- /* 0.25.0 */
2
- import { Decimal } from 'decimal.js';
3
- import { Expression } from '../../math-json/math-json-format';
1
+ /* 0.26.0 */
2
+ import type { Expression } from '../../math-json/types';
3
+ import type { Type, TypeString } from '../../common/type/types';
4
+ import type { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, BoxedSubstitution, Rule, CanonicalOptions, BoxedRule, Sign } from './public';
5
+ import { NumericValue } from '../numeric-value/public';
4
6
  import { _BoxedExpression } from './abstract-boxed-expression';
5
- import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOptions, BoxedDomain, RuntimeScope, BoxedFunctionDefinition, BoxedBaseDefinition, DomainExpression, BoxedSubstitution, Rule, SemiBoxedExpression, CanonicalOptions } from './public';
7
+ import { BigNum } from '../numerics/bignum';
8
+ import type { OneOf } from '../../common/one-of';
6
9
  /**
7
10
  * BoxedSymbol
8
11
  *
@@ -24,16 +27,23 @@ export declare class BoxedSymbol extends _BoxedExpression {
24
27
  protected _id: string;
25
28
  private _hash;
26
29
  private _def;
30
+ private _isStructural;
27
31
  constructor(ce: IComputeEngine, name: string, options?: {
28
32
  metadata?: Metadata;
29
33
  canonical?: CanonicalOptions;
30
- def?: BoxedSymbolDefinition | BoxedFunctionDefinition;
34
+ structural?: boolean;
35
+ def?: OneOf<[BoxedSymbolDefinition, BoxedFunctionDefinition]>;
31
36
  });
32
37
  get json(): Expression;
33
38
  get hash(): number;
34
39
  get isPure(): boolean;
40
+ get isStructural(): boolean;
41
+ get structural(): BoxedExpression;
35
42
  get scope(): RuntimeScope | null;
36
43
  get isConstant(): boolean;
44
+ private _lookupDef;
45
+ /** This method returns the definition associated with the value of this symbol, or associated with the symbol if it has no value. This is the definition to use with most operations on the symbol. Indeed, "x[2]" is accessing the second element of **the value** of "x".*/
46
+ private _getDef;
37
47
  /**
38
48
  * Associate a definition with this symbol
39
49
  */
@@ -41,49 +51,53 @@ export declare class BoxedSymbol extends _BoxedExpression {
41
51
  reset(): void;
42
52
  get isCanonical(): boolean;
43
53
  set isCanonical(val: boolean);
54
+ is(rhs: any): boolean;
44
55
  get canonical(): BoxedExpression;
56
+ toNumericValue(): [NumericValue, BoxedExpression];
57
+ neg(): BoxedExpression;
58
+ inv(): BoxedExpression;
59
+ abs(): BoxedExpression;
60
+ add(rhs: number | BoxedExpression): BoxedExpression;
61
+ mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
62
+ div(rhs: number | BoxedExpression): BoxedExpression;
63
+ pow(exp: number | BoxedExpression): BoxedExpression;
64
+ root(n: number | BoxedExpression): BoxedExpression;
65
+ sqrt(): BoxedExpression;
66
+ ln(semiBase?: number | BoxedExpression): BoxedExpression;
45
67
  solve(vars: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
46
68
  get complexity(): number;
47
- get head(): string;
69
+ get operator(): string;
48
70
  get symbol(): string;
49
71
  get baseDefinition(): BoxedBaseDefinition | undefined;
50
72
  get symbolDefinition(): BoxedSymbolDefinition | undefined;
51
73
  get functionDefinition(): BoxedFunctionDefinition | undefined;
52
74
  /**
53
75
  * Subsequence inferences will narrow the domain of the symbol.
54
- * f(:integer), g(:real)
55
- * g(x) => x:real
56
- * f(x) => x:integer narrowed from integer to real
76
+ * f: integer -> real, g: real -> real
77
+ * g(x) => x: real
78
+ * f(x) => x: integer narrowed from integer to real
57
79
  */
58
- infer(domain: BoxedDomain): boolean;
59
- get value(): number | boolean | string | Object | undefined;
60
- set value(value: boolean | string | Decimal | Complex | {
61
- re: number;
62
- im: number;
63
- } | {
64
- num: number;
65
- denom: number;
66
- } | number[] | BoxedExpression | number | undefined);
67
- get domain(): BoxedDomain | undefined;
68
- set domain(inDomain: DomainExpression | BoxedDomain);
69
- get sgn(): -1 | 0 | 1 | undefined | null;
80
+ infer(t: Type): boolean;
81
+ get value(): number | boolean | string | object | undefined;
82
+ set value(value: boolean | string | Decimal | number[] | OneOf<[
83
+ {
84
+ re: number;
85
+ im: number;
86
+ },
87
+ {
88
+ num: number;
89
+ denom: number;
90
+ },
91
+ BoxedExpression
92
+ ]> | number | object | undefined);
93
+ get type(): Type;
94
+ set type(t: Type | TypeString);
95
+ get sgn(): Sign | undefined;
70
96
  has(x: string | string[]): boolean;
71
- isSame(rhs: BoxedExpression): boolean;
72
- match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
73
- isEqual(rhs: BoxedExpression): boolean;
74
- isLess(rhs: BoxedExpression): boolean | undefined;
75
- isLessEqual(rhs: BoxedExpression): boolean | undefined;
76
- isGreater(rhs: BoxedExpression): boolean | undefined;
77
- isGreaterEqual(rhs: BoxedExpression): boolean | undefined;
97
+ match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
78
98
  get isFunction(): boolean | undefined;
79
- get isZero(): boolean | undefined;
80
- get isNotZero(): boolean | undefined;
81
- get isOne(): boolean | undefined;
82
- get isNegativeOne(): boolean | undefined;
83
99
  get isOdd(): boolean | undefined;
84
100
  get isEven(): boolean | undefined;
85
- get isPrime(): boolean | undefined;
86
- get isComposite(): boolean | undefined;
87
101
  get isInfinity(): boolean | undefined;
88
102
  get isNaN(): boolean | undefined;
89
103
  get isPositive(): boolean | undefined;
@@ -93,17 +107,25 @@ export declare class BoxedSymbol extends _BoxedExpression {
93
107
  get isNumber(): boolean | undefined;
94
108
  get isInteger(): boolean | undefined;
95
109
  get isRational(): boolean | undefined;
96
- get isAlgebraic(): boolean | undefined;
97
110
  get isReal(): boolean | undefined;
98
- get isExtendedReal(): boolean | undefined;
99
- get isComplex(): boolean | undefined;
100
- get isImaginary(): boolean | undefined;
101
- simplify(options?: SimplifyOptions): BoxedExpression;
111
+ get re(): number;
112
+ get im(): number;
113
+ get bignumRe(): BigNum | undefined;
114
+ get bignumIm(): BigNum | undefined;
115
+ simplify(options?: Partial<SimplifyOptions>): BoxedExpression;
102
116
  evaluate(options?: EvaluateOptions): BoxedExpression;
103
- N(options?: NOptions): BoxedExpression;
104
- replace(rules: BoxedRuleSet | Rule | Rule[], options?: ReplaceOptions): BoxedExpression | null;
117
+ N(): BoxedExpression;
118
+ replace(rules: Rule | (Rule | BoxedRule)[] | BoxedRuleSet, options?: Partial<ReplaceOptions>): BoxedExpression | null;
105
119
  subs(sub: Substitution, options?: {
106
120
  canonical?: CanonicalOptions;
107
121
  }): BoxedExpression;
122
+ get isCollection(): boolean;
123
+ contains(rhs: BoxedExpression): boolean;
124
+ get size(): number;
125
+ each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
126
+ at(index: number): BoxedExpression | undefined;
127
+ get(index: BoxedExpression | string): BoxedExpression | undefined;
128
+ indexOf(expr: BoxedExpression): number;
129
+ subsetOf(rhs: BoxedExpression, strict: boolean): boolean;
108
130
  }
109
131
  export declare function makeCanonicalSymbol(ce: IComputeEngine, name: string): BoxedExpression;
@@ -1,37 +1,40 @@
1
- /* 0.25.0 */
2
- import Decimal from 'decimal.js';
3
- import { Expression } from '../../math-json/math-json-format';
4
- import { BoxedExpression, IComputeEngine, EvaluateOptions, NOptions, SimplifyOptions, Metadata, BoxedDomain, BoxedSubstitution, PatternMatchOptions, BoxedBaseDefinition, BoxedFunctionDefinition, SemiBoxedExpression } from '../public';
5
- import { DataTypeMap, TensorDataType } from '../symbolic/tensor-fields';
6
- import { AbstractTensor, TensorData } from '../symbolic/tensors';
1
+ /* 0.26.0 */
2
+ import type { BoxedExpression, IComputeEngine, EvaluateOptions, SimplifyOptions, Metadata, BoxedSubstitution, PatternMatchOptions, BoxedBaseDefinition, BoxedFunctionDefinition } from '../public';
3
+ import { TensorDataType } from './tensor-fields';
4
+ import { NumericValue } from '../numeric-value/public';
7
5
  import { _BoxedExpression } from './abstract-boxed-expression';
6
+ import { AbstractTensor, TensorData } from '../tensor/tensors';
7
+ import { Type } from '../../common/type/types';
8
8
  /**
9
- * A boxed tensor represents an expression that can be
10
- * represented by a tensor. This could be a vector, matrix
11
- * or multi-dimensional array.
9
+ * A boxed tensor represents an expression that can be represented by a tensor.
10
+ * This could be a vector, matrix or multi-dimensional array.
12
11
  *
13
- * The object can be created either from a tensor or from
14
- * an expression that can be represented as a tensor.
12
+ * The object can be created either from a tensor or from an expression that
13
+ * can be represented as a tensor.
15
14
  *
16
- * The counterpart (expression if input is tensor, or tensor
15
+ * The structural counterpart (expression if input is tensor, or tensor
17
16
  * if input is expression) is created lazily.
18
17
  *
19
18
  * @noInheritDoc
20
19
  *
21
20
  */
22
21
  export declare class BoxedTensor extends _BoxedExpression {
22
+ readonly options?: {
23
+ metadata?: Metadata;
24
+ canonical?: boolean;
25
+ };
23
26
  private _tensor;
24
- private readonly _head?;
27
+ private readonly _operator?;
25
28
  private readonly _ops?;
26
29
  private _expression;
27
30
  constructor(ce: IComputeEngine, input: {
28
- head?: string;
31
+ op?: string;
29
32
  ops: ReadonlyArray<BoxedExpression>;
30
33
  } | AbstractTensor<'expression'>, options?: {
31
34
  metadata?: Metadata;
32
35
  canonical?: boolean;
33
36
  });
34
- get expression(): BoxedExpression;
37
+ get structural(): BoxedExpression;
35
38
  /** Create the tensor on demand */
36
39
  get tensor(): AbstractTensor<'expression'>;
37
40
  get baseDefinition(): BoxedBaseDefinition | undefined;
@@ -45,28 +48,42 @@ export declare class BoxedTensor extends _BoxedExpression {
45
48
  get isPure(): boolean;
46
49
  get isValid(): boolean;
47
50
  get complexity(): number;
48
- get head(): string;
51
+ get operator(): string;
49
52
  get nops(): number;
50
53
  get ops(): ReadonlyArray<BoxedExpression>;
51
54
  get op1(): BoxedExpression;
52
55
  get op2(): BoxedExpression;
53
56
  get op3(): BoxedExpression;
57
+ neg(): BoxedExpression;
58
+ inv(): BoxedExpression;
59
+ abs(): BoxedExpression;
60
+ add(rhs: number | BoxedExpression): BoxedExpression;
61
+ sub(rhs: BoxedExpression): BoxedExpression;
62
+ mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
63
+ div(rhs: number | BoxedExpression): BoxedExpression;
64
+ pow(exp: number | BoxedExpression): BoxedExpression;
65
+ root(exp: number | BoxedExpression): BoxedExpression;
66
+ sqrt(): BoxedExpression;
54
67
  get shape(): number[];
55
68
  get rank(): number;
56
- get domain(): BoxedDomain | undefined;
69
+ get type(): Type;
57
70
  get json(): Expression;
58
- /** Structural equality */
59
- isSame(rhs: BoxedExpression): boolean;
60
71
  /** Mathematical equality */
61
- isEqual(rhs: BoxedExpression): boolean;
62
- match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
72
+ isEqual(rhs: number | BoxedExpression): boolean | undefined;
73
+ get isCollection(): boolean;
74
+ contains(rhs: BoxedExpression): boolean;
75
+ get size(): number;
76
+ each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
77
+ at(_index: number): BoxedExpression | undefined;
78
+ indexOf(_expr: BoxedExpression): number;
79
+ match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
63
80
  evaluate(options?: EvaluateOptions): BoxedExpression;
64
- simplify(options?: SimplifyOptions): BoxedExpression;
65
- N(options?: NOptions): BoxedExpression;
81
+ simplify(options?: Partial<SimplifyOptions>): BoxedExpression;
82
+ N(): BoxedExpression;
66
83
  }
67
84
  export declare function isBoxedTensor(val: unknown): val is BoxedTensor;
68
- export declare function expressionTensorInfo(head: string, rows: ReadonlyArray<BoxedExpression>): {
85
+ export declare function expressionTensorInfo(operator: string, rows: ReadonlyArray<BoxedExpression>): {
69
86
  shape: number[];
70
- dtype: keyof DataTypeMap;
71
- };
72
- export declare function expressionAsTensor<T extends TensorDataType>(head: string, rows: ReadonlyArray<BoxedExpression>): TensorData<T> | undefined;
87
+ dtype: TensorDataType | undefined;
88
+ } | undefined;
89
+ export declare function expressionAsTensor<T extends TensorDataType = 'expression'>(operator: string, rows: ReadonlyArray<BoxedExpression>): TensorData<T> | undefined;
@@ -0,0 +1,6 @@
1
+ /* 0.26.0 */
2
+ value: T | null;
3
+ generation: number | undefined;
4
+ };
5
+ /** The cache v will get updated if necessary */
6
+ export declare function cachedValue<T>(v: CachedValue<T>, generation: number | undefined, fn: () => T): T;
@@ -1,2 +1,2 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  export declare function canonicalForm(expr: BoxedExpression, forms: CanonicalOptions): BoxedExpression;
@@ -0,0 +1,13 @@
1
+ /* 0.26.0 */
2
+ /**
3
+ * Structural equality of boxed expressions.
4
+ */
5
+ export declare function same(a: BoxedExpression, b: BoxedExpression): boolean;
6
+ /**
7
+ * Mathematically equality of two boxed expressions.
8
+ *
9
+ * In general, it is impossible to always prove equality
10
+ * ([Richardson's theorem](https://en.wikipedia.org/wiki/Richardson%27s_theorem)) but this works often...
11
+ */
12
+ export declare function eq(a: BoxedExpression, b: number | BoxedExpression): boolean | undefined;
13
+ export declare function cmp(a: BoxedExpression, b: number | BoxedExpression): '<' | '=' | '>' | '>=' | '<=' | undefined;
@@ -0,0 +1,20 @@
1
+ /* 0.26.0 */
2
+ export declare function expandProducts(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression | null;
3
+ export declare function choose(n: number, k: number): number;
4
+ /** Attempt to transform the expression (h, ops) into a sum */
5
+ export declare function expandFunction(ce: IComputeEngine, h: string, ops: ReadonlyArray<BoxedExpression>): BoxedExpression | null;
6
+ /** Apply the distributive law if the expression is a product of sums.
7
+ * For example, a(b + c) = ab + ac
8
+ * Expand the expression if it is a power of a sum.
9
+ * Expand the terms of the expression if it is a sum or negate.
10
+ * If the expression is a fraction, expand the numerator.
11
+ * If the exression is a relational operator, expand the operands.
12
+ * Return null if the expression cannot be expanded.
13
+ */
14
+ export declare function expand(expr: BoxedExpression | undefined): BoxedExpression | null;
15
+ /**
16
+ * Recursive expand of all terms in the expression.
17
+ *
18
+ * `expand()` only expands the top level of the expression.
19
+ */
20
+ export declare function expandAll(expr: BoxedExpression): BoxedExpression | null;
@@ -1,4 +1,4 @@
1
- /* 0.25.0 */
1
+ /* 0.26.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,11 +1,12 @@
1
- /* 0.25.0 */
2
- import Decimal from 'decimal.js';
3
- import { Rational } from '../numerics/rationals';
4
- import { BoxedExpression } from './public';
5
- export declare function applyCoefficient(value: number | Decimal | Complex | Rational | null, coef: Rational): number | Decimal | Complex | Rational | null;
1
+ /* 0.26.0 */
2
+ import { NumericValue } from '../numeric-value/public';
6
3
  /** Combine rational expressions into a single fraction */
7
4
  export declare function together(op: BoxedExpression): BoxedExpression;
8
5
  /**
9
- * Return a list of expressions that multiply together to form `expr`.
6
+ * Return an expression factored as a product.
7
+ * - 2x + 4 -> 2(x + 2)
8
+ * - 2x < 4 -> x < 2
9
+ * - (2x) * (2y) -> 4xy
10
10
  */
11
11
  export declare function factor(expr: BoxedExpression): BoxedExpression;
12
+ export declare function getPiTerm(expr: BoxedExpression): [k: NumericValue, t: NumericValue];
@@ -0,0 +1,25 @@
1
+ /* 0.26.0 */
2
+ /**
3
+ *
4
+ * Make all the arguments canonical.
5
+ *
6
+ * "Lift" Sequence expressions to the top level.
7
+ * e.g. `["Add", 1, ["Sequence", 2, 3]]` -> `["Add", 1, 2, 3]`
8
+ *
9
+ * Additionally, if an operator is provided, also lift nested expressions
10
+ * with the same operator.
11
+ * e.g. `["f", a, ["f", b, c]]` -> `["f", a, b, c]`
12
+ *
13
+ * Note: *not* recursive
14
+ */
15
+ export declare function flatten<T extends ReadonlyArray<BoxedExpression> | BoxedExpression[]>(ops: T, operator?: string): T;
16
+ /**
17
+ * Flatten the arguments.
18
+ * @fixme replace with just flatten.
19
+ * @fixme consider adding flatternSort()
20
+ */
21
+ export declare function flattenOps<T extends ReadonlyArray<BoxedExpression> | BoxedExpression[]>(ops: T, operator: string): T;
22
+ /**
23
+ * @todo: this function should probably not be recursive. As it, it is semi-recursive.
24
+ */
25
+ export declare function flattenSequence(xs: ReadonlyArray<BoxedExpression>): ReadonlyArray<BoxedExpression>;
@@ -0,0 +1,9 @@
1
+ /* 0.26.0 */
2
+ /** Apply the function `f` to each operand of the expression `expr`,
3
+ * account for the 'hold' property of the function definition:
4
+ *
5
+ * Account for `Hold`, `ReleaseHold`, `Sequence`, `Symbol` and `Nothing`.
6
+ *
7
+ * If `f` returns `null`, the element is not added to the result
8
+ */
9
+ export declare function holdMap(expr: BoxedExpression, f: (x: BoxedExpression) => BoxedExpression | null): ReadonlyArray<BoxedExpression>;
@@ -1,6 +1,4 @@
1
- /* 0.25.0 */
2
- import Decimal from 'decimal.js';
3
- import { BoxedSubstitution, PatternMatchOptions, BoxedExpression, SemiBoxedExpression } from './public';
1
+ /* 0.26.0 */
4
2
  /**
5
3
  * The function attempts to match a subject expression to a
6
4
  * [pattern](/compute-engine/guides/patterns-and-rules/).
@@ -11,4 +9,4 @@ import { BoxedSubstitution, PatternMatchOptions, BoxedExpression, SemiBoxedExpre
11
9
  * If the expression does not match the pattern, it returns `null`.
12
10
  *
13
11
  */
14
- export declare function match(subject: BoxedExpression, pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
12
+ export declare function match(subject: BoxedExpression, pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
@@ -0,0 +1,10 @@
1
+ /* 0.26.0 */
2
+ /**
3
+ * Distribute `Negate` (multiply by -1) if expr is a number literal, an
4
+ * addition or multiplication or another `Negate`.
5
+ *
6
+ * It is important to do all these to handle cases like
7
+ * `-3x` -> ["Negate, ["Multiply", 3, "x"]] -> ["Multiply, -3, x]
8
+ */
9
+ export declare function negate(expr: BoxedExpression): BoxedExpression;
10
+ export declare function negateProduct(ce: IComputeEngine, args: ReadonlyArray<BoxedExpression>): BoxedExpression;
@@ -1,41 +1,7 @@
1
- /* 0.25.0 */
2
- import { Rational } from '../numerics/rationals';
3
- import { BoxedExpression } from './public';
4
- /**
5
- * Attempt to factor a numeric coefficient `c` and a `rest` out of a
6
- * canonical expression `expr` such that `ce.mul(c, rest)` is equal to `expr`.
7
- *
8
- * Attempts to make `rest` a positive value (i.e. pulls out negative sign).
9
- *
10
- * For example:
11
- *
12
- * ['Multiply', 2, 'x', 3, 'a']
13
- * -> [6, ['Multiply', 'x', 'a']]
14
- *
15
- * ['Divide', ['Multiply', 2, 'x'], ['Multiply', 3, 'y', 'a']]
16
- * -> [['Rational', 2, 3], ['Divide', 'x', ['Multiply, 'y', 'a']]]
17
- */
18
- export declare function asCoefficient(expr: BoxedExpression): [coef: Rational, rest: BoxedExpression];
1
+ /* 0.26.0 */
2
+ import type { Rational } from '../numerics/rationals';
3
+ import type { BoxedExpression } from './public';
19
4
  export declare function asRational(expr: BoxedExpression): Rational | undefined;
20
- export declare function asApproximateRational(expr: BoxedExpression): Rational | undefined;
21
- export declare function div(lhs: Rational, rhs: Rational): Rational;
22
- /**
23
- * Add a literal numeric value to a rational.
24
- * If the rational is a bigint, this is a hint to do the calculation in bigint
25
- * (no need to check `bignumPreferred()`).
26
- * @param lhs
27
- * @param rhs
28
- * @returns
29
- */
30
- export declare function add(lhs: Rational, rhs: BoxedExpression | Rational): Rational;
31
- export declare function mul(lhs: Rational, rhs: BoxedExpression | Rational): Rational;
32
- export declare function asFloat(expr: BoxedExpression | undefined): number | null;
5
+ export declare function asBigint(expr: BoxedExpression | undefined): bigint | null;
33
6
  export declare function asBignum(expr: BoxedExpression | undefined): Decimal | null;
34
- export declare function asMachineInteger(expr: BoxedExpression | undefined): number | null;
35
- /**
36
- *
37
- * @param lhs
38
- * @param rhs
39
- * @returns the sign (-1, 0, 1) of the difference between `lhs` and `rhs`
40
- */
41
- export declare function signDiff(lhs: BoxedExpression, rhs: BoxedExpression, tolerance?: number): -1 | 0 | 1 | undefined;
7
+ export declare function asSmallInteger(expr: number | BoxedExpression | undefined): number | null;
@@ -1,11 +1,22 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  export type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
5
- * Sort by higher total degree (sum of degree), if tied, sort by max degree,
6
- * if tied,
5
+ * The sorting order of arguments of the Add function uses a modified degrevlex:
6
+ * - Sort by total degree (sum of degree)
7
+ * - Sort by max degree.
8
+ * - Sort reverse lexicographically
9
+ * - Sort by rank
10
+ *
11
+ *
12
+ * E.g.
13
+ * - 2x^2 + 3x + 1
14
+ * - 2x^2y^3 + 5x^3y
7
15
  */
8
- export declare function sortAdd(ops: ReadonlyArray<BoxedExpression>): ReadonlyArray<BoxedExpression>;
16
+ export declare function addOrder(a: BoxedExpression, b: BoxedExpression): number;
17
+ export declare function equalOrder(a: BoxedExpression, b: BoxedExpression): number;
18
+ declare const RANKS: readonly ["integer", "rational", "radical", "real", "complex", "constant", "symbol", "multiply", "divide", "add", "trig", "fn", "power", "string", "other"];
19
+ export type Rank = (typeof RANKS)[number];
9
20
  /**
10
21
  * Given two expressions `a` and `b`, return:
11
22
  * - `-1` if `a` should be ordered before `b`
@@ -15,7 +26,7 @@ export declare function sortAdd(ops: ReadonlyArray<BoxedExpression>): ReadonlyAr
15
26
  * The default order is as follow:
16
27
  *
17
28
  * 1/ Literal numeric values (rational, machine numbers and Decimal numbers),
18
- * ordered by they numeric value (smaller numbers before larger numbers)
29
+ * ordered by their numeric value (smaller numbers before larger numbers)
19
30
  *
20
31
  * 2/ Literal complex numbers, ordered by their real parts. In case of a tie,
21
32
  * ordered by the absolute value of their imaginary parts. In case of a tie,
@@ -26,7 +37,7 @@ export declare function sortAdd(ops: ReadonlyArray<BoxedExpression>): ReadonlyAr
26
37
  * 4/ Addition, ordered as a polynom, with higher degree terms first
27
38
  *
28
39
  * 5/ Other functions, ordered by their `complexity` property. In case
29
- * of a tie, ordered by the head of the expression as a string. In case of a
40
+ * of a tie, ordered by the operator of the expression as a string. In case of a
30
41
  * tie, by the leaf count of each expression. In case of a tie, by the order
31
42
  * of each argument, left to right.
32
43
  *
@@ -35,9 +46,8 @@ export declare function sortAdd(ops: ReadonlyArray<BoxedExpression>): ReadonlyAr
35
46
  * example "E" < "e" < "È" and "11" < "2". This ordering is not suitable to
36
47
  * collate natural language strings.
37
48
  *
38
- * 7/ Dictionaries, ordered by the number of keys. If there is a tie, by the
39
- * sum of the complexities of the values of the dictionary
40
- *
49
+ * See https://reference.wolfram.com/language/ref/Sort.html for a
50
+ * description of the ordering of expressions in Mathematica.
41
51
  *
42
52
  */
43
53
  export declare function order(a: BoxedExpression, b: BoxedExpression): number;
@@ -47,13 +57,15 @@ export declare function order(a: BoxedExpression, b: BoxedExpression): number;
47
57
  export declare function canonicalOrder(expr: BoxedExpression, { recursive }: {
48
58
  recursive?: boolean;
49
59
  }): BoxedExpression;
60
+ export declare function sortOperands(operator: string, xs: ReadonlyArray<BoxedExpression>): ReadonlyArray<BoxedExpression>;
50
61
  /**
51
62
  * Sort the terms of a polynomial expression (`Add` expression) according
52
63
  * to the deglex polynomial ordering
53
64
  *
54
65
  */
55
- export declare function polynomialOrder(expr: BoxedExpression): SemiBoxedExpression;
56
- export declare function lexicographicOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): SemiBoxedExpression;
57
- export declare function degreeLexicographicOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): SemiBoxedExpression;
58
- export declare function degreeReverseLexicographicOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): SemiBoxedExpression;
59
- export declare function eliminationOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): SemiBoxedExpression;
66
+ export declare function polynomialOrder(expr: BoxedExpression): BoxedExpression;
67
+ export declare function lexicographicOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): BoxedExpression;
68
+ export declare function degreeLexicographicOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): BoxedExpression;
69
+ export declare function degreeReverseLexicographicOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): BoxedExpression;
70
+ export declare function eliminationOrder(expr: BoxedExpression, vars?: ReadonlyArray<string>): BoxedExpression;
71
+ export {};
@@ -1,4 +1,4 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -22,31 +22,27 @@ export type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
22
22
  */
23
23
  export declare function coefficients(poly: BoxedExpression, vars: string): UnivariateCoefficients | null;
24
24
  export declare function coefficients(poly: BoxedExpression, vars: string[]): MultivariateCoefficients | null;
25
- /**
26
- * Return a polynomial expression of `vars` with coefficient
27
- * of powers `coefs`.
28
- *
29
- * `poly === polynomial(coefficients(poly), getVars(poly))`
30
- *
31
- */
32
- export declare function polynomial(coefs: UnivariateCoefficients, vars: string): SemiBoxedExpression;
33
- export declare function polynomial(coefs: MultivariateCoefficients, vars: string[]): SemiBoxedExpression;
34
25
  /**
35
26
  * The total degree of an expression is the sum of the
36
- * of the positive integer degrees of the factors in the expression:
27
+ * positive integer degrees of the factors in the expression:
37
28
  *
38
- * `3√2x^5y^3` -> 8 (5 + 3)
29
+ * `3√2x^5y^3` -> 5 + 3 = 8
39
30
  */
40
31
  export declare function totalDegree(expr: BoxedExpression): number;
41
32
  /**
42
- * The max degree of an expression is the largest positive integer degree
43
- * in the factors of the expression
33
+ * The max degree of a polynomial is the largest positive integer degree
34
+ * in the factors (monomials) of the expression
44
35
  *
45
36
  * `3√2x^5y^3` -> 5
46
37
  *
47
38
  */
48
39
  export declare function maxDegree(expr: BoxedExpression): number;
49
40
  /**
50
- * Return a lexicographic key of the expression
41
+ * Return a lexicographic key of the expression, for example
42
+ * `xy^2` -> `x y`
43
+ * `x\frac{1}{y}` -> `x y`
44
+ * `2xy + y^2` -> `x y y`
45
+ *
51
46
  */
52
47
  export declare function lex(expr: BoxedExpression): string;
48
+ export declare function revlex(expr: BoxedExpression): string;