@cortex-js/compute-engine 0.25.1 → 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 (153) hide show
  1. package/dist/compute-engine.esm.js +26832 -23014
  2. package/dist/compute-engine.js +26836 -23006
  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 +22 -139
  6. package/dist/math-json.js +22 -139
  7. package/dist/math-json.min.esm.js +22 -139
  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 +70 -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 +906 -634
  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 +132 -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 +3 -3
  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/boxed-expression/coefficient-field.d.ts +0 -56
  142. package/dist/types/compute-engine/domain-utils.d.ts +0 -19
  143. package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
  144. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -16
  145. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
  146. package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
  147. package/dist/types/compute-engine/library/domains.d.ts +0 -16
  148. package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
  149. package/dist/types/compute-engine/rules.d.ts +0 -20
  150. package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
  151. package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
  152. package/dist/types/compute-engine/symbolic/negate.d.ts +0 -11
  153. package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
@@ -1,28 +1,35 @@
1
- /* 0.25.1 */
2
- import { Decimal } from 'decimal.js';
3
- import { Expression } from '../../math-json/math-json-format';
4
- import { LatexString } from '../public';
5
- import { Rational } from '../numerics/rationals';
6
- import { BoxedBaseDefinition, BoxedDomain, BoxedExpression, BoxedFunctionDefinition, BoxedRuleSet, BoxedSubstitution, BoxedSymbolDefinition, CanonicalOptions, DomainCompatibility, DomainLiteral, EvaluateOptions, IComputeEngine, JsonSerializationOptions, Metadata, NOptions, PatternMatchOptions, Rule, RuntimeScope, SemiBoxedExpression, SimplifyOptions, Substitution } from './public';
7
- import { SerializeLatexOptions } from '../latex-syntax/public';
1
+ /* 0.26.0 */
2
+ import { Expression, MathJsonIdentifier } from '../../math-json/types';
3
+ import type { BoxedBaseDefinition, BoxedExpression, BoxedFunctionDefinition, BoxedRuleSet, BoxedSubstitution, BoxedSymbolDefinition, CanonicalOptions, EvaluateOptions, IComputeEngine, JsonSerializationOptions, Metadata, PatternMatchOptions, Rule, RuntimeScope, Sign, SimplifyOptions, Substitution } from './public';
4
+ import type { LatexString } from '../public';
5
+ import type { NumericValue } from '../numeric-value/public';
6
+ import type { SmallInteger } from '../numerics/numeric';
7
+ import type { SerializeLatexOptions } from '../latex-syntax/public';
8
+ import { AsciiMathOptions } from './ascii-math';
8
9
  /**
9
10
  * _BoxedExpression
10
11
  */
11
12
  export declare abstract class _BoxedExpression implements BoxedExpression {
12
13
  abstract readonly hash: number;
13
14
  abstract readonly json: Expression;
14
- abstract readonly head: BoxedExpression | string;
15
+ abstract readonly operator: string;
16
+ /** @deprecated */
17
+ get head(): string;
15
18
  abstract get isCanonical(): boolean;
16
19
  abstract set isCanonical(_val: boolean);
17
- abstract isSame(rhs: BoxedExpression): boolean;
18
- abstract isEqual(rhs: BoxedExpression): boolean;
19
- abstract match(pattern: Decimal | Complex | [num: number, denom: number] | SemiBoxedExpression | BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
20
+ abstract match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
20
21
  readonly engine: IComputeEngine;
21
22
  /** Verbatim LaTeX, obtained from a source, i.e. from parsing,
22
23
  * not generated synthetically
23
24
  */
24
25
  verbatimLatex?: string;
25
26
  constructor(ce: IComputeEngine, metadata?: Metadata);
27
+ isSame(rhs: BoxedExpression): boolean;
28
+ isEqual(rhs: number | BoxedExpression): boolean | undefined;
29
+ isLess(_rhs: number | BoxedExpression): boolean | undefined;
30
+ isLessEqual(_rhs: number | BoxedExpression): boolean | undefined;
31
+ isGreater(_rhs: number | BoxedExpression): boolean | undefined;
32
+ isGreaterEqual(_rhs: number | BoxedExpression): boolean | undefined;
26
33
  /**
27
34
  *
28
35
  * `Object.valueOf()`: return a JavaScript primitive value for the expression
@@ -30,7 +37,8 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
30
37
  * Primitive values are: boolean, number, bigint, string, null, undefined
31
38
  *
32
39
  */
33
- valueOf(): number | Object | string | boolean;
40
+ valueOf(): number | object | string | boolean;
41
+ toAsciiMath(options?: Partial<AsciiMathOptions>): string;
34
42
  /** Object.toString() */
35
43
  toString(): string;
36
44
  print(): void;
@@ -43,43 +51,62 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
43
51
  toJSON(): Expression;
44
52
  toMathJson(options?: Readonly<Partial<JsonSerializationOptions>>): Expression;
45
53
  toLatex(options?: Partial<SerializeLatexOptions>): LatexString;
54
+ toNumericValue(): [NumericValue, BoxedExpression];
46
55
  get scope(): RuntimeScope | null;
47
- /** Object.is() */
48
56
  is(rhs: any): boolean;
49
57
  get canonical(): BoxedExpression;
58
+ get structural(): BoxedExpression;
59
+ get isStructural(): boolean;
50
60
  get latex(): LatexString;
51
61
  set latex(val: LatexString);
52
62
  get symbol(): string | null;
63
+ get tensor(): null | AbstractTensor<'expression'>;
53
64
  get string(): string | null;
54
- getSubexpressions(head: string): ReadonlyArray<BoxedExpression>;
65
+ getSubexpressions(operator: MathJsonIdentifier): ReadonlyArray<BoxedExpression>;
55
66
  get subexpressions(): ReadonlyArray<BoxedExpression>;
56
67
  get symbols(): ReadonlyArray<string>;
57
68
  get unknowns(): ReadonlyArray<string>;
58
69
  get freeVariables(): ReadonlyArray<string>;
59
70
  get errors(): ReadonlyArray<BoxedExpression>;
60
71
  get ops(): null | ReadonlyArray<BoxedExpression>;
61
- get nops(): number;
72
+ get nops(): SmallInteger;
62
73
  get op1(): BoxedExpression;
63
74
  get op2(): BoxedExpression;
64
75
  get op3(): BoxedExpression;
65
76
  get isValid(): boolean;
66
77
  get isPure(): boolean;
67
- get isExact(): boolean;
68
- /** For a symbol, true if the symbol is a constant (unchangeable value) */
78
+ /** Literals (number, string, boolean) are constants. Some symbols
79
+ * may also be constants (e.g. Pi, E, True, False). Expressions of constant
80
+ * symbols are also constants (if the function is pure).
81
+ */
69
82
  get isConstant(): boolean;
70
83
  get isNaN(): boolean | undefined;
71
- get isZero(): boolean | undefined;
72
- get isNotZero(): boolean | undefined;
73
- get isOne(): boolean | undefined;
74
- get isNegativeOne(): boolean | undefined;
75
84
  get isInfinity(): boolean | undefined;
76
85
  get isFinite(): boolean | undefined;
77
86
  get isEven(): boolean | undefined;
78
87
  get isOdd(): boolean | undefined;
79
- get isPrime(): boolean | undefined;
80
- get isComposite(): boolean | undefined;
81
- get numericValue(): number | Decimal | Complex | Rational | null;
82
- get sgn(): -1 | 0 | 1 | undefined | null;
88
+ get numericValue(): number | NumericValue | null;
89
+ get isNumberLiteral(): boolean;
90
+ get isFunctionExpression(): boolean;
91
+ get re(): number;
92
+ get im(): number;
93
+ get bignumRe(): Decimal | undefined;
94
+ get bignumIm(): Decimal | undefined;
95
+ get numerator(): BoxedExpression;
96
+ get denominator(): BoxedExpression;
97
+ get numeratorDenominator(): [BoxedExpression, BoxedExpression];
98
+ neg(): BoxedExpression;
99
+ inv(): BoxedExpression;
100
+ abs(): BoxedExpression;
101
+ add(rhs: number | BoxedExpression): BoxedExpression;
102
+ sub(rhs: BoxedExpression): BoxedExpression;
103
+ mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
104
+ div(rhs: number | BoxedExpression): BoxedExpression;
105
+ pow(exp: number | BoxedExpression): BoxedExpression;
106
+ root(exp: number | BoxedExpression): BoxedExpression;
107
+ sqrt(): BoxedExpression;
108
+ ln(base?: number | BoxedExpression): BoxedExpression;
109
+ get sgn(): Sign | undefined;
83
110
  get shape(): number[];
84
111
  get rank(): number;
85
112
  subs(_sub: Substitution, options?: {
@@ -92,15 +119,10 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
92
119
  solve(_vars: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
93
120
  replace(_rules: BoxedRuleSet | Rule | Rule[]): null | BoxedExpression;
94
121
  has(_v: string | string[]): boolean;
95
- isLess(_rhs: BoxedExpression): boolean | undefined;
96
- isLessEqual(_rhs: BoxedExpression): boolean | undefined;
97
- isGreater(_rhs: BoxedExpression): boolean | undefined;
98
- isGreaterEqual(_rhs: BoxedExpression): boolean | undefined;
99
122
  get isPositive(): boolean | undefined;
100
123
  get isNonNegative(): boolean | undefined;
101
124
  get isNegative(): boolean | undefined;
102
125
  get isNonPositive(): boolean | undefined;
103
- isCompatible(_dom: BoxedDomain | DomainLiteral, _kind?: DomainCompatibility): boolean;
104
126
  get description(): string[] | undefined;
105
127
  get url(): string | undefined;
106
128
  get wikidata(): string | undefined;
@@ -108,31 +130,32 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
108
130
  get baseDefinition(): BoxedBaseDefinition | undefined;
109
131
  get symbolDefinition(): BoxedSymbolDefinition | undefined;
110
132
  get functionDefinition(): BoxedFunctionDefinition | undefined;
111
- infer(_domain: BoxedDomain): boolean;
133
+ infer(t: Type): boolean;
112
134
  bind(): void;
113
135
  reset(): void;
114
- get keys(): IterableIterator<string> | null;
115
- get keysCount(): number;
116
- getKey(_key: string): BoxedExpression | undefined;
117
- hasKey(_key: string): boolean;
118
- get value(): number | boolean | string | Object | undefined;
136
+ get value(): number | boolean | string | object | undefined;
119
137
  set value(_value: BoxedExpression | number | boolean | string | number[] | undefined);
120
- get domain(): BoxedDomain | undefined;
121
- set domain(_domain: BoxedDomain);
138
+ get type(): Type;
139
+ set type(_type: Type);
122
140
  get isNumber(): boolean | undefined;
123
141
  get isInteger(): boolean | undefined;
124
142
  get isRational(): boolean | undefined;
125
- get isAlgebraic(): boolean | undefined;
126
143
  get isReal(): boolean | undefined;
127
- get isExtendedReal(): boolean | undefined;
128
- get isComplex(): boolean | undefined;
129
- get isImaginary(): boolean | undefined;
130
- get isExtendedComplex(): boolean | undefined;
131
- simplify(_options?: SimplifyOptions): BoxedExpression;
132
- evaluate(_options?: EvaluateOptions): BoxedExpression;
133
- N(_options?: NOptions): BoxedExpression;
144
+ simplify(_options?: Partial<SimplifyOptions>): BoxedExpression;
145
+ evaluate(_options?: Partial<EvaluateOptions>): BoxedExpression;
146
+ N(): BoxedExpression;
134
147
  compile(to?: string, options?: {
135
148
  optimize: ('simplify' | 'evaluate')[];
136
149
  }): ((args: Record<string, any>) => any | undefined) | undefined;
150
+ get isCollection(): boolean;
151
+ contains(_rhs: BoxedExpression): boolean;
152
+ subsetOf(_target: BoxedExpression, _strict: boolean): boolean;
153
+ get size(): number;
154
+ each(_start?: number, _count?: number): Iterator<BoxedExpression, undefined>;
155
+ at(_index: number): BoxedExpression | undefined;
156
+ get(_key: string | BoxedExpression): BoxedExpression | undefined;
157
+ indexOf(_expr: BoxedExpression): number;
137
158
  }
138
- export declare function getSubexpressions(expr: BoxedExpression, head: string): ReadonlyArray<BoxedExpression>;
159
+ export declare function getSubexpressions(expr: BoxedExpression, name: MathJsonIdentifier): ReadonlyArray<BoxedExpression>;
160
+ import { Type } from '../../common/type/types';
161
+ import { AbstractTensor } from '../tensor/tensors';
@@ -0,0 +1,5 @@
1
+ /* 0.26.0 */
2
+ import { Decimal } from 'decimal.js';
3
+ import type { BoxedExpression } from '../public';
4
+ export declare function apply(expr: BoxedExpression, fn: (x: number) => number | Complex, bigFn?: (x: Decimal) => Decimal | Complex | number, complexFn?: (x: Complex) => number | Complex): BoxedExpression | undefined;
5
+ export declare function apply2(expr1: BoxedExpression, expr2: BoxedExpression, fn: (x1: number, x2: number) => number | Complex, bigFn?: (x1: Decimal, x2: Decimal) => Decimal | Complex | number, complexFn?: (x1: Complex, x2: number | Complex) => Complex | number): BoxedExpression | undefined;
@@ -0,0 +1,15 @@
1
+ /* 0.26.0 */
2
+ import { Type } from '../../common/type/types';
3
+ /**
4
+ *
5
+ * The canonical form of `Add`:
6
+ * - canonicalize the arguments
7
+ * - remove `0`
8
+ * - capture complex numbers (`a + ib` or `ai + b`)
9
+ * - sort the terms
10
+ *
11
+ */
12
+ export declare function canonicalAdd(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
13
+ export declare function addType(args: ReadonlyArray<BoxedExpression>): Type;
14
+ export declare function add(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
15
+ export declare function addN(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
@@ -0,0 +1,12 @@
1
+ /* 0.26.0 */
2
+ /**
3
+ * Canonical form of 'Divide' (and 'Rational')
4
+ * - remove denominator of 1
5
+ * - simplify the signs
6
+ * - factor out negate (make the numerator and denominator positive)
7
+ * - if numerator and denominator are integer literals, return a rational number
8
+ * or Rational expression
9
+ * - evaluate number literals
10
+ */
11
+ export declare function canonicalDivide(op1: BoxedExpression, op2: BoxedExpression): BoxedExpression;
12
+ export declare function div(num: BoxedExpression, denom: number | BoxedExpression): BoxedExpression;
@@ -0,0 +1,16 @@
1
+ /* 0.26.0 */
2
+ /**
3
+ * The canonical form of `Multiply`:
4
+ * - removes `1` anb `-1`
5
+ * - simplifies the signs:
6
+ * - i.e. `-y \times -x` -> `x \times y`
7
+ * - `2 \times -x` -> `-2 \times x`
8
+ * - arguments are sorted
9
+ * - complex numbers promoted (['Multiply', 2, 'ImaginaryUnit'] -> 2i)
10
+ * - Numeric values are promoted (['Multiply', 2, 'Sqrt', 3] -> 2√3)
11
+ *
12
+ * The input ops may not be canonical, the result is canonical.
13
+ */
14
+ export declare function canonicalMultiply(ce: IComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
15
+ export declare function mul(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
16
+ export declare function mulN(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
@@ -0,0 +1,20 @@
1
+ /* 0.26.0 */
2
+ import type { Rational } from '../numerics/rationals';
3
+ export declare function asRadical(expr: BoxedExpression): Rational | null;
4
+ export declare function canonicalPower(a: BoxedExpression, b: BoxedExpression): BoxedExpression;
5
+ export declare function canonicalRoot(a: BoxedExpression, b: BoxedExpression | number): BoxedExpression;
6
+ /**
7
+ * The power function.
8
+ *
9
+ * It follows the same conventions as SymPy, which do not always
10
+ * conform to IEEE 754 floating point arithmetic.
11
+ *
12
+ * See https://docs.sympy.org/latest/modules/core.html#sympy.core.power.Pow
13
+ *
14
+ */
15
+ export declare function pow(x: BoxedExpression, exp: number | BoxedExpression, { numericApproximation }: {
16
+ numericApproximation: boolean;
17
+ }): BoxedExpression;
18
+ export declare function root(a: BoxedExpression, b: BoxedExpression, { numericApproximation }: {
19
+ numericApproximation: boolean;
20
+ }): BoxedExpression;
@@ -0,0 +1,11 @@
1
+ /* 0.26.0 */
2
+ export type AsciiMathSerializer = (expr: BoxedExpression, precedence?: number) => string;
3
+ export type AsciiMathOptions = {
4
+ symbols: Record<string, string>;
5
+ operators: Record<string, [
6
+ string | ((expr: BoxedExpression) => string),
7
+ number
8
+ ]>;
9
+ functions: Record<string, string | ((expr: BoxedExpression, serialize: AsciiMathSerializer) => string)>;
10
+ };
11
+ export declare function toAsciiMath(expr: BoxedExpression, options?: Partial<AsciiMathOptions>, precedence?: number): string;
@@ -1,87 +1,27 @@
1
- /* 0.25.1 */
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.1 */
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.1 */
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>;