@cortex-js/compute-engine 0.29.1 → 0.30.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 (150) hide show
  1. package/dist/compute-engine.esm.js +28319 -24614
  2. package/dist/compute-engine.min.esm.js +70 -68
  3. package/dist/compute-engine.min.umd.js +131 -0
  4. package/dist/{compute-engine.cjs → compute-engine.umd.js} +29615 -25910
  5. package/dist/math-json.esm.js +22 -294
  6. package/dist/math-json.min.esm.js +22 -294
  7. package/dist/math-json.min.umd.js +4 -0
  8. package/dist/math-json.umd.js +141 -0
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +28 -0
  11. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +1 -1
  14. package/dist/types/common/one-of.d.ts +1 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/boxed-type.d.ts +20 -4
  17. package/dist/types/common/type/parse.d.ts +4 -4
  18. package/dist/types/common/type/primitive.d.ts +3 -2
  19. package/dist/types/common/type/serialize.d.ts +1 -1
  20. package/dist/types/common/type/subtype.d.ts +1 -1
  21. package/dist/types/common/type/types.d.ts +91 -25
  22. package/dist/types/common/type/utils.d.ts +2 -1
  23. package/dist/types/common/utils.d.ts +1 -1
  24. package/dist/types/compute-engine/assume.d.ts +2 -2
  25. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +72 -73
  26. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +2 -2
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +19 -1
  30. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/box.d.ts +6 -6
  32. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +42 -0
  33. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +48 -27
  34. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +17 -5
  35. package/dist/types/compute-engine/boxed-expression/{boxed-function-definition.d.ts → boxed-operator-definition.d.ts} +12 -12
  36. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +7 -8
  38. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +91 -52
  39. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +22 -25
  40. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
  41. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
  43. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -2
  44. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  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 +1 -1
  48. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/hold.d.ts +2 -2
  50. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +30 -3
  53. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/product.d.ts +2 -2
  56. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +41 -1
  59. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/solve.d.ts +3 -1
  61. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/utils.d.ts +23 -23
  64. package/dist/types/compute-engine/boxed-expression/validate.d.ts +2 -1
  65. package/dist/types/compute-engine/collection-utils.d.ts +22 -57
  66. package/dist/types/compute-engine/compile.d.ts +61 -10
  67. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  68. package/dist/types/compute-engine/function-utils.d.ts +46 -29
  69. package/dist/types/compute-engine/global-types.d.ts +1432 -893
  70. package/dist/types/compute-engine/index.d.ts +154 -124
  71. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  72. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +3 -3
  85. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  86. package/dist/types/compute-engine/latex-syntax/parse.d.ts +14 -12
  87. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  88. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  89. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  90. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/types.d.ts +51 -39
  92. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  93. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
  94. package/dist/types/compute-engine/library/calculus.d.ts +2 -2
  95. package/dist/types/compute-engine/library/collections.d.ts +3 -3
  96. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  97. package/dist/types/compute-engine/library/complex.d.ts +2 -2
  98. package/dist/types/compute-engine/library/control-structures.d.ts +2 -2
  99. package/dist/types/compute-engine/library/core.d.ts +2 -2
  100. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  101. package/dist/types/compute-engine/library/library.d.ts +5 -5
  102. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -2
  103. package/dist/types/compute-engine/library/logic.d.ts +2 -2
  104. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  105. package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
  106. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  107. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
  108. package/dist/types/compute-engine/library/sets.d.ts +2 -2
  109. package/dist/types/compute-engine/library/statistics.d.ts +2 -2
  110. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
  111. package/dist/types/compute-engine/library/utils.d.ts +24 -2
  112. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +3 -4
  113. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +3 -3
  114. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +3 -4
  115. package/dist/types/compute-engine/numeric-value/types.d.ts +7 -5
  116. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  117. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  118. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  119. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -19
  120. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  121. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -1
  124. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  125. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  129. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  130. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  131. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  132. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -4
  133. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  134. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  135. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +5 -46
  136. package/dist/types/compute-engine/tensor/tensors.d.ts +4 -14
  137. package/dist/types/compute-engine/types.d.ts +1 -4
  138. package/dist/types/compute-engine.d.ts +1 -1
  139. package/dist/types/math-json/symbols.d.ts +11 -0
  140. package/dist/types/math-json/types.d.ts +19 -11
  141. package/dist/types/math-json/utils.d.ts +18 -9
  142. package/dist/types/math-json.d.ts +2 -2
  143. package/package.json +9 -11
  144. package/dist/compute-engine.min.cjs +0 -129
  145. package/dist/math-json.cjs +0 -413
  146. package/dist/math-json.min.cjs +0 -6
  147. package/dist/types/common/json5.d.ts +0 -3
  148. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +0 -64
  149. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +0 -21
  150. package/dist/types/math-json/identifiers.d.ts +0 -11
@@ -1,27 +1,31 @@
1
- /* 0.29.1 */
2
- import type { SimplifyOptions, ReplaceOptions, PatternMatchOptions, BoxedExpression, BoxedBaseDefinition, BoxedFunctionDefinition, BoxedRuleSet, BoxedSubstitution, CanonicalOptions, EvaluateOptions, ComputeEngine, Metadata, Rule, RuntimeScope, Sign, Substitution } from '../global-types';
3
- import { NumericValue } from '../numeric-value/types';
4
- import { _BoxedExpression } from './abstract-boxed-expression';
1
+ /* 0.30.0 */
2
+ import type { SimplifyOptions, ReplaceOptions, PatternMatchOptions, BoxedExpression, BoxedBaseDefinition, BoxedOperatorDefinition, BoxedRuleSet, BoxedSubstitution, CanonicalOptions, EvaluateOptions, ComputeEngine, Metadata, Rule, Sign, Substitution, Scope, BoxedValueDefinition } from '../global-types';
5
3
  import { Type } from '../../common/type/types';
6
4
  import { BoxedType } from '../../common/type/boxed-type';
5
+ import { NumericValue } from '../numeric-value/types';
6
+ import { _BoxedExpression } from './abstract-boxed-expression';
7
7
  /**
8
- * A boxed function represent an expression that can be represented by a
9
- * function call.
8
+ * A boxed function expression represent an expression composed of an operator
9
+ * (the name of the function) and a list of arguments. For example:
10
+ * `["Add", 1, 2]` is a function expression with the operator "Add" and two
11
+ * arguments 1 and 2.
10
12
  *
11
- * It is composed of an operator (the name of the function) and a list of
12
- * arguments.
13
+ * If canonical, it has a definition associated with it, based on the operator.
13
14
  *
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.
15
+ * The definition contains its signature and its evaluation handler.
17
16
  *
18
17
  */
19
18
  export declare class BoxedFunction extends _BoxedExpression {
20
- private readonly _name;
19
+ private readonly _operator;
21
20
  private readonly _ops;
22
- private _canonical;
23
- private _scope;
24
- _def: BoxedFunctionDefinition | undefined;
21
+ private _def;
22
+ /** @todo: wrong. If the function is scoped (has its own lexical scope), the captured eval context. This includes the lexical scope for this expression
23
+ */
24
+ private _capturedContext;
25
+ /** If the operator is scoped, the local scope associated with
26
+ * the function expression
27
+ */
28
+ private _localScope;
25
29
  private _isPure;
26
30
  private _isStructural;
27
31
  private _hash;
@@ -29,35 +33,47 @@ export declare class BoxedFunction extends _BoxedExpression {
29
33
  private _valueN;
30
34
  private _sgn;
31
35
  private _type;
32
- constructor(ce: ComputeEngine, name: string, ops: ReadonlyArray<BoxedExpression>, options?: {
36
+ constructor(ce: ComputeEngine, operator: string, ops: ReadonlyArray<BoxedExpression>, options?: {
33
37
  metadata?: Metadata;
34
38
  canonical?: boolean;
35
39
  structural?: boolean;
40
+ scope?: Scope;
36
41
  });
37
42
  get hash(): number;
38
- infer(t: Type): boolean;
43
+ /**
44
+ * For function expressions, `infer()` infers the result type of the function
45
+ * based on the provided type and inference mode.
46
+ */
47
+ infer(t: Type, inferenceMode?: 'narrow' | 'widen'): boolean;
39
48
  bind(): void;
40
49
  reset(): void;
50
+ get value(): BoxedExpression | undefined;
41
51
  get isCanonical(): boolean;
42
- set isCanonical(val: boolean);
43
52
  get isPure(): boolean;
44
- /** The value of the function is constant if the function is
45
- * pure, and all its arguments are constant.
46
- */
47
53
  get isConstant(): boolean;
54
+ get constantValue(): number | boolean | string | object | undefined;
48
55
  get json(): Expression;
49
- get scope(): RuntimeScope | null;
50
56
  get operator(): string;
51
57
  get ops(): ReadonlyArray<BoxedExpression>;
52
58
  get nops(): number;
53
59
  get op1(): BoxedExpression;
54
60
  get op2(): BoxedExpression;
55
61
  get op3(): BoxedExpression;
62
+ get isScoped(): boolean;
63
+ get localScope(): Scope | undefined;
56
64
  get isValid(): boolean;
65
+ /** Note: if the expression is not canonical, this will return a canonical
66
+ * version of the expression in the current lexical scope.
67
+ */
57
68
  get canonical(): BoxedExpression;
58
69
  get structural(): BoxedExpression;
59
70
  get isStructural(): boolean;
60
71
  toNumericValue(): [NumericValue, BoxedExpression];
72
+ /**
73
+ * Note: the result is bound to the current scope, not the scope of the
74
+ * original expression.
75
+ * <!-- This may or may not be desirable -->
76
+ */
61
77
  subs(sub: Substitution, options?: {
62
78
  canonical?: CanonicalOptions;
63
79
  }): BoxedExpression;
@@ -89,7 +105,8 @@ export declare class BoxedFunction extends _BoxedExpression {
89
105
  ln(semiBase?: number | BoxedExpression): BoxedExpression;
90
106
  get complexity(): number | undefined;
91
107
  get baseDefinition(): BoxedBaseDefinition | undefined;
92
- get functionDefinition(): BoxedFunctionDefinition | undefined;
108
+ get operatorDefinition(): BoxedOperatorDefinition | undefined;
109
+ get valueDefinition(): BoxedValueDefinition | undefined;
93
110
  get isNumber(): boolean | undefined;
94
111
  get isInteger(): boolean | undefined;
95
112
  get isRational(): boolean | undefined;
@@ -103,12 +120,16 @@ export declare class BoxedFunction extends _BoxedExpression {
103
120
  N(): BoxedExpression;
104
121
  solve(vars?: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
105
122
  get isCollection(): boolean;
106
- contains(rhs: BoxedExpression): boolean;
107
- get size(): number;
108
- each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
123
+ get isIndexedCollection(): boolean;
124
+ get isLazyCollection(): boolean;
125
+ xcontains(rhs: BoxedExpression): boolean | undefined;
126
+ get xsize(): number | undefined;
127
+ get isEmptyCollection(): boolean | undefined;
128
+ get isFiniteCollection(): boolean | undefined;
129
+ each(): Generator<BoxedExpression>;
109
130
  at(index: number): BoxedExpression | undefined;
110
131
  get(index: BoxedExpression | string): BoxedExpression | undefined;
111
- indexOf(expr: BoxedExpression): number;
132
+ indexWhere(predicate: (element: BoxedExpression) => boolean): number | undefined;
112
133
  subsetOf(rhs: BoxedExpression, strict: boolean): boolean;
113
134
  _computeValue(options?: Partial<EvaluateOptions>): () => BoxedExpression;
114
135
  _computeValueAsync(options?: Partial<EvaluateOptions>): () => Promise<BoxedExpression>;
@@ -1,6 +1,6 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { Decimal } from 'decimal.js';
3
- import type { Expression, MathJsonNumber } from '../../math-json';
3
+ import type { Expression, MathJsonNumberObject } from '../../math-json';
4
4
  import type { Rational, SmallInteger } from '../numerics/types';
5
5
  import { ExactNumericValueData, NumericValue, NumericValueData } from '../numeric-value/types';
6
6
  import { _BoxedExpression } from './abstract-boxed-expression';
@@ -27,7 +27,6 @@ export declare class BoxedNumber extends _BoxedExpression {
27
27
  */
28
28
  constructor(ce: ComputeEngine, value: SmallInteger | NumericValueData | ExactNumericValueData | NumericValue, options?: {
29
29
  metadata?: Metadata;
30
- canonical?: boolean;
31
30
  });
32
31
  get hash(): number;
33
32
  get json(): Expression;
@@ -36,6 +35,18 @@ export declare class BoxedNumber extends _BoxedExpression {
36
35
  get isCanonical(): boolean;
37
36
  set isCanonical(val: boolean);
38
37
  get complexity(): number;
38
+ /**
39
+ *
40
+ * Return a JavaScript number when possible (most cases); else return a
41
+ * string representation of the number (ComplexInfinity and complex numbers
42
+ * for example).
43
+ *
44
+ * When a JavaScript number is returned, it may have fewer digits than the
45
+ * original number, but it will be a close approximation.
46
+ *
47
+ * @returns {number | string} The value of the number.
48
+ */
49
+ valueOf(): number | string;
39
50
  get numericValue(): number | NumericValue;
40
51
  get isNumberLiteral(): boolean;
41
52
  get re(): number;
@@ -52,6 +63,7 @@ export declare class BoxedNumber extends _BoxedExpression {
52
63
  root(exp: number | BoxedExpression): BoxedExpression;
53
64
  sqrt(): BoxedExpression;
54
65
  ln(semiBase?: number | BoxedExpression): BoxedExpression;
66
+ get value(): BoxedExpression;
55
67
  get type(): BoxedType;
56
68
  get sgn(): Sign | undefined;
57
69
  get numerator(): BoxedExpression;
@@ -79,7 +91,7 @@ export declare class BoxedNumber extends _BoxedExpression {
79
91
  get isInteger(): boolean;
80
92
  get isRational(): boolean;
81
93
  get isReal(): boolean;
82
- is(rhs: any): boolean;
94
+ is(other: BoxedExpression | number | bigint | boolean): boolean;
83
95
  get canonical(): BoxedExpression;
84
96
  get isStructural(): boolean;
85
97
  get structural(): BoxedExpression;
@@ -88,4 +100,4 @@ export declare class BoxedNumber extends _BoxedExpression {
88
100
  evaluate(options?: Partial<EvaluateOptions>): BoxedExpression;
89
101
  N(): BoxedExpression;
90
102
  }
91
- export declare function canonicalNumber(ce: ComputeEngine, value: number | bigint | string | Decimal | Complex | Rational | NumericValue | MathJsonNumber): number | NumericValue;
103
+ export declare function canonicalNumber(ce: ComputeEngine, value: number | bigint | string | Decimal | Complex | Rational | NumericValue | MathJsonNumberObject): number | NumericValue;
@@ -1,14 +1,13 @@
1
- /* 0.29.1 */
2
- import { OneOf } from '../../common/one-of';
1
+ /* 0.30.0 */
3
2
  import { BoxedType } from '../../common/type/boxed-type';
4
- import type { FunctionDefinition, BoxedExpression, BoxedFunctionDefinition, CollectionHandlers, CompiledExpression, EvaluateOptions, ComputeEngine, RuntimeScope, Sign } from '../global-types';
5
- export declare class _BoxedFunctionDefinition implements BoxedFunctionDefinition {
3
+ import type { OperatorDefinition, BoxedExpression, BoxedOperatorDefinition, CollectionHandlers, CompiledExpression, EvaluateOptions, ComputeEngine, Sign } from '../global-types';
4
+ export declare class _BoxedOperatorDefinition implements BoxedOperatorDefinition {
6
5
  engine: ComputeEngine;
7
- scope: RuntimeScope;
8
6
  name: string;
9
7
  description?: string | string[];
8
+ url?: string;
10
9
  wikidata?: string;
11
- threadable: boolean;
10
+ broadcastable: boolean;
12
11
  associative: boolean;
13
12
  commutative: boolean;
14
13
  commutativeOrder: ((a: BoxedExpression, b: BoxedExpression) => number) | undefined;
@@ -17,6 +16,7 @@ export declare class _BoxedFunctionDefinition implements BoxedFunctionDefinition
17
16
  pure: boolean;
18
17
  complexity: number;
19
18
  lazy: boolean;
19
+ scoped: boolean;
20
20
  signature: BoxedType;
21
21
  inferredSignature: boolean;
22
22
  type?: (ops: ReadonlyArray<BoxedExpression>, options: {
@@ -43,11 +43,11 @@ export declare class _BoxedFunctionDefinition implements BoxedFunctionDefinition
43
43
  engine: ComputeEngine;
44
44
  }) => BoxedExpression;
45
45
  compile?: (expr: BoxedExpression) => CompiledExpression;
46
- collection?: Partial<CollectionHandlers>;
47
- constructor(ce: ComputeEngine, name: string, def: FunctionDefinition);
46
+ collection?: CollectionHandlers;
47
+ constructor(ce: ComputeEngine, name: string, def: OperatorDefinition);
48
+ /** For debugging */
49
+ toJSON(): any;
48
50
  infer(sig: Type): void;
49
- update(def: FunctionDefinition): void;
50
- reset(): void;
51
+ update(def: OperatorDefinition): void;
52
+ onConfigurationChange(): void;
51
53
  }
52
- export declare function makeFunctionDefinition(engine: ComputeEngine, name: string, def: OneOf<[FunctionDefinition | BoxedFunctionDefinition]>): BoxedFunctionDefinition;
53
- export declare function isBoxedFunctionDefinition(x: any): x is BoxedFunctionDefinition;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import type { BoxedExpression } from '../global-types';
3
3
  export declare function isWildcard(expr: BoxedExpression): expr is BoxedSymbol;
4
4
  export declare function wildcardName(expr: BoxedExpression): string | null;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  import { _BoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedType } from '../../common/type/boxed-type';
4
4
  /**
@@ -6,7 +6,10 @@ import { BoxedType } from '../../common/type/boxed-type';
6
6
  *
7
7
  */
8
8
  export declare class BoxedString extends _BoxedExpression {
9
+ [Symbol.toStringTag]: string;
9
10
  private readonly _string;
11
+ private _utf8Buffer?;
12
+ private _unicodeScalarValues?;
10
13
  constructor(ce: ComputeEngine, expr: string, metadata?: Metadata);
11
14
  get json(): string;
12
15
  get hash(): number;
@@ -14,15 +17,11 @@ export declare class BoxedString extends _BoxedExpression {
14
17
  get isPure(): boolean;
15
18
  get isCanonical(): boolean;
16
19
  set isCanonical(_va: boolean);
20
+ get value(): BoxedExpression;
17
21
  get type(): BoxedType;
18
22
  get complexity(): number;
19
23
  get string(): string;
24
+ get buffer(): Uint8Array;
25
+ get unicodeScalars(): number[];
20
26
  match(pattern: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
21
- get isCollection(): boolean;
22
- contains(rhs: BoxedExpression): boolean;
23
- get size(): number;
24
- each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
25
- at(index: number): BoxedExpression | undefined;
26
- get(key: string | BoxedExpression): BoxedExpression | undefined;
27
- indexOf(expr: BoxedExpression): number;
28
27
  }
@@ -1,58 +1,62 @@
1
- /* 0.29.1 */
2
- import type { Expression } from '../../math-json/types';
1
+ /* 0.30.0 */
3
2
  import type { Type, TypeString } from '../../common/type/types';
4
- import type { BoxedExpression, SimplifyOptions, PatternMatchOptions, ReplaceOptions, RuntimeScope, BoxedSymbolDefinition, BoxedFunctionDefinition, ComputeEngine, Metadata, CanonicalOptions, BoxedBaseDefinition, BoxedSubstitution, EvaluateOptions, Rule, BoxedRule, BoxedRuleSet, Substitution, Sign } from '../global-types';
5
- import { NumericValue } from '../numeric-value/types';
6
- import { _BoxedExpression } from './abstract-boxed-expression';
7
- import type { BigNum } from '../numerics/types';
8
3
  import type { OneOf } from '../../common/one-of';
9
4
  import { BoxedType } from '../../common/type/boxed-type';
5
+ import type { BigNum } from '../numerics/types';
6
+ import { NumericValue } from '../numeric-value/types';
7
+ import type { BoxedExpression, SimplifyOptions, PatternMatchOptions, ReplaceOptions, BoxedValueDefinition, BoxedOperatorDefinition, ComputeEngine, Metadata, CanonicalOptions, BoxedBaseDefinition, BoxedSubstitution, EvaluateOptions, Rule, BoxedRule, BoxedRuleSet, Substitution, Sign, BoxedDefinition, CollectionHandlers } from '../global-types';
8
+ import { _BoxedExpression } from './abstract-boxed-expression';
10
9
  /**
11
- * BoxedSymbol
10
+ * ### BoxedSymbol
11
+ *
12
+ * A boxed symbol is a reference to a `BoxedDefinition`.
13
+ *
14
+ * A `BoxedDefinition` "owns" all the information about a symbol, its
15
+ * type and various attributes (is it a constant?, etc...).
12
16
  *
13
- * A boxed symbol is a reference to a `BoxedSymbolDefinition` or a
14
- * `BoxedFunctionDefinition`.
17
+ * Boxed symbols are bound to a definition during construction if they
18
+ * are canonical.
15
19
  *
16
- * If a `BoxedSymbolDefinition`, it "owns" all the information
17
- * about the symbol, its value, domain and various attributes.
20
+ * If a symbol is not canonical (and thus not bound to a definition),
21
+ * some properties and methods will return `undefined`, for example
22
+ * `isInteger`, `isRational`, `isReal`, etc...
18
23
  *
19
- * If a `BoxedFunctionDefinition`, it it a reference to a function name,
20
- * not a function expression, i.e. `Sin`, not `["Sin", "Pi"]`. This is used
21
- * for example in `["InverseFunction", "Sin"]`
24
+ * There is a single value definition for each symbol but the value of a
25
+ * symbol can be different in different evaluation contexts, for example
26
+ * a local variable during a recursion.
22
27
  *
28
+ * The value of a symbol is tracked in the evaluation context and
29
+ * not in the value definition.
30
+ *
31
+ * The `value` property of a boxed symbol is the value of the symbol
32
+ * in the current evaluation context. It is `undefined` if the symbol
33
+ * is not bound to a definition or if the value is not known (a bound
34
+ * symbol may have no value).
23
35
  *
24
36
  */
25
37
  export declare class BoxedSymbol extends _BoxedExpression {
26
- private _scope;
27
- protected _id: string;
28
38
  private _hash;
29
- private _def;
30
- private _isStructural;
31
- constructor(ce: ComputeEngine, name: string, options?: {
39
+ /** The name of the symbol */
40
+ protected _id: MathJsonSymbol;
41
+ /**
42
+ * The definition of the symbol, if the symbol is bound/canonical.
43
+ */
44
+ private readonly _def;
45
+ /** Note: to indicate that the symbol should be canonical, pass a def. */
46
+ constructor(ce: ComputeEngine, name: MathJsonSymbol, options?: {
32
47
  metadata?: Metadata;
33
- canonical?: CanonicalOptions;
34
- structural?: boolean;
35
- def?: OneOf<[BoxedSymbolDefinition, BoxedFunctionDefinition]>;
48
+ def?: BoxedDefinition;
36
49
  });
37
50
  get json(): Expression;
38
51
  get hash(): number;
39
52
  get isPure(): boolean;
40
- get isStructural(): boolean;
41
- get structural(): BoxedExpression;
42
- get scope(): RuntimeScope | null;
43
53
  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;
47
- /**
48
- * Associate a definition with this symbol
49
- */
50
54
  bind(): void;
51
55
  reset(): void;
52
56
  get isCanonical(): boolean;
53
57
  set isCanonical(val: boolean);
54
- is(rhs: any): boolean;
55
58
  get canonical(): BoxedExpression;
59
+ is(other: any): boolean;
56
60
  toNumericValue(): [NumericValue, BoxedExpression];
57
61
  neg(): BoxedExpression;
58
62
  inv(): BoxedExpression;
@@ -66,20 +70,40 @@ export declare class BoxedSymbol extends _BoxedExpression {
66
70
  ln(semiBase?: number | BoxedExpression): BoxedExpression;
67
71
  solve(vars?: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
68
72
  get complexity(): number;
69
- get operator(): string;
70
- get symbol(): string;
73
+ get operator(): MathJsonSymbol;
74
+ get symbol(): MathJsonSymbol;
71
75
  get baseDefinition(): BoxedBaseDefinition | undefined;
72
- get symbolDefinition(): BoxedSymbolDefinition | undefined;
73
- get functionDefinition(): BoxedFunctionDefinition | undefined;
76
+ get valueDefinition(): BoxedValueDefinition | undefined;
77
+ get operatorDefinition(): BoxedOperatorDefinition | undefined;
74
78
  /**
75
- * Subsequent inferences will narrow the domain of the symbol.
76
- * f: integer -> real, g: real -> real
77
- * g(x) => x: real
78
- * f(x) => x: integer narrowed from integer to real
79
+ *
80
+ * Assuming the symbol is used as an argument, subsequent inferences will
81
+ * narrow the domain of the symbol:
82
+ *
83
+ * ```
84
+ * f: real -> number, g: integer -> number
85
+ * f(x) => x: inferred to real
86
+ * g(x) => x: narrowed to integer
87
+ * ```
88
+ *
89
+ * If the symbol is used as a return value, its domain should be widened:
90
+ *
91
+ * ```
92
+ * f: number -> integer, g: number -> real
93
+ * x = f(2) => x: inferred to integer
94
+ * x = g(2) => x: widened to real
95
+ * ```
96
+ *
97
+ * Arguments accumulate constraints and narrow.
98
+ * Return values accumulate possibilities and widen.
99
+ *
100
+ * @inheritdoc
79
101
  */
80
- infer(t: Type): boolean;
81
- get value(): number | boolean | string | object | undefined;
82
- set value(value: boolean | string | Decimal | number[] | OneOf<[
102
+ infer(t: Type, inferenceMode?: 'narrow' | 'widen'): boolean;
103
+ /** Return the value of the symbol, undefined if an operator or not bound */
104
+ get _value(): BoxedExpression | undefined;
105
+ get value(): BoxedExpression | undefined;
106
+ set value(value: boolean | string | BigNum | number[] | OneOf<[
83
107
  {
84
108
  re: number;
85
109
  im: number;
@@ -89,21 +113,32 @@ export declare class BoxedSymbol extends _BoxedExpression {
89
113
  denom: number;
90
114
  },
91
115
  BoxedExpression
92
- ]> | number | object | undefined);
116
+ ]> | number | undefined);
117
+ /**
118
+ * The type of the symbol.
119
+ *
120
+ * Note that the type of the value of the symbol may be more specific.'
121
+ * For example, a symbol could have a type of 'number' but the value
122
+ * could be 'integer'.
123
+ *
124
+ * If the symbol is not canonical (not bound to a definition), the type is
125
+ * 'unknown'
126
+ */
93
127
  get type(): BoxedType;
94
128
  set type(t: Type | TypeString | BoxedType);
95
- get sgn(): Sign | undefined;
96
- has(x: string | string[]): boolean;
129
+ has(x: MathJsonSymbol | MathJsonSymbol[]): boolean;
97
130
  match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
98
- get isFunction(): boolean | undefined;
131
+ get sgn(): Sign | undefined;
99
132
  get isOdd(): boolean | undefined;
100
133
  get isEven(): boolean | undefined;
134
+ get isFinite(): boolean | undefined;
101
135
  get isInfinity(): boolean | undefined;
102
136
  get isNaN(): boolean | undefined;
103
137
  get isPositive(): boolean | undefined;
104
138
  get isNonPositive(): boolean | undefined;
105
139
  get isNegative(): boolean | undefined;
106
140
  get isNonNegative(): boolean | undefined;
141
+ get isFunction(): boolean | undefined;
107
142
  get isNumber(): boolean | undefined;
108
143
  get isInteger(): boolean | undefined;
109
144
  get isRational(): boolean | undefined;
@@ -119,13 +154,17 @@ export declare class BoxedSymbol extends _BoxedExpression {
119
154
  subs(sub: Substitution, options?: {
120
155
  canonical?: CanonicalOptions;
121
156
  }): BoxedExpression;
157
+ get _asCollection(): CollectionHandlers | undefined;
122
158
  get isCollection(): boolean;
123
- contains(rhs: BoxedExpression): boolean;
124
- get size(): number;
125
- each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
159
+ get isIndexedCollection(): boolean;
160
+ get isLazyCollection(): boolean;
161
+ xcontains(rhs: BoxedExpression): boolean | undefined;
162
+ get xsize(): number;
163
+ get isEmptyCollection(): boolean;
164
+ get isFiniteCollection(): boolean | undefined;
165
+ each(): Generator<BoxedExpression>;
126
166
  at(index: number): BoxedExpression | undefined;
127
167
  get(index: BoxedExpression | string): BoxedExpression | undefined;
128
- indexOf(expr: BoxedExpression): number;
168
+ indexWhere(predicate: (element: BoxedExpression) => boolean): number | undefined;
129
169
  subsetOf(rhs: BoxedExpression, strict: boolean): boolean;
130
170
  }
131
- export declare function makeCanonicalSymbol(ce: ComputeEngine, name: string): BoxedExpression;
@@ -1,9 +1,8 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
+ import type { ComputeEngine, TensorDataType, Metadata, BoxedBaseDefinition, BoxedOperatorDefinition, BoxedSubstitution, EvaluateOptions, BoxedExpression, SimplifyOptions, PatternMatchOptions, Tensor } from '../global-types';
3
+ import { BoxedType } from '../../common/type/boxed-type';
2
4
  import { NumericValue } from '../numeric-value/types';
3
5
  import { _BoxedExpression } from './abstract-boxed-expression';
4
- import { AbstractTensor } from '../tensor/tensors';
5
- import { BoxedType } from '../../common/type/boxed-type';
6
- import type { ComputeEngine, TensorDataType, Metadata, BoxedBaseDefinition, BoxedFunctionDefinition, BoxedSubstitution, EvaluateOptions, TensorData, BoxedExpression, SimplifyOptions, PatternMatchOptions } from '../global-types';
7
6
  /**
8
7
  * A boxed tensor represents an expression that can be represented by a tensor.
9
8
  * This could be a vector, matrix or multi-dimensional array.
@@ -15,33 +14,32 @@ import type { ComputeEngine, TensorDataType, Metadata, BoxedBaseDefinition, Boxe
15
14
  * if input is expression) is created lazily.
16
15
  *
17
16
  */
18
- export declare class BoxedTensor extends _BoxedExpression {
17
+ export declare class BoxedTensor<T extends TensorDataType> extends _BoxedExpression {
18
+ readonly input: {
19
+ ops: ReadonlyArray<BoxedExpression>;
20
+ shape: number[];
21
+ dtype: T;
22
+ };
19
23
  readonly options?: {
20
24
  metadata?: Metadata;
21
- canonical?: boolean;
22
25
  };
23
26
  private _tensor;
24
- private readonly _operator?;
25
- private readonly _ops?;
26
- private _expression;
27
+ private _expression?;
27
28
  constructor(ce: ComputeEngine, input: {
28
- op?: string;
29
29
  ops: ReadonlyArray<BoxedExpression>;
30
- } | AbstractTensor<'expression'>, options?: {
30
+ shape: number[];
31
+ dtype: T;
32
+ }, options?: {
31
33
  metadata?: Metadata;
32
- canonical?: boolean;
33
34
  });
34
35
  get structural(): BoxedExpression;
35
36
  /** Create the tensor on demand */
36
- get tensor(): AbstractTensor<'expression'>;
37
+ get tensor(): Tensor<T>;
37
38
  get baseDefinition(): BoxedBaseDefinition | undefined;
38
- get functionDefinition(): BoxedFunctionDefinition | undefined;
39
- bind(): void;
40
- reset(): void;
39
+ get operatorDefinition(): BoxedOperatorDefinition | undefined;
41
40
  get hash(): number;
42
41
  get canonical(): BoxedExpression;
43
42
  get isCanonical(): boolean;
44
- set isCanonical(val: boolean);
45
43
  get isPure(): boolean;
46
44
  get isValid(): boolean;
47
45
  get complexity(): number;
@@ -68,19 +66,18 @@ export declare class BoxedTensor extends _BoxedExpression {
68
66
  /** Mathematical equality */
69
67
  isEqual(rhs: number | BoxedExpression): boolean | undefined;
70
68
  get isCollection(): boolean;
71
- contains(rhs: BoxedExpression): boolean;
72
- get size(): number;
73
- each(start?: number, count?: number): Iterator<BoxedExpression, undefined>;
74
- at(_index: number): BoxedExpression | undefined;
75
- indexOf(_expr: BoxedExpression): number;
69
+ get isIndexedCollection(): boolean;
70
+ xcontains(other: BoxedExpression): boolean | undefined;
71
+ get xsize(): number;
72
+ each(): Generator<BoxedExpression>;
73
+ at(index: number): BoxedExpression | undefined;
76
74
  match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
77
75
  evaluate(options?: Partial<EvaluateOptions>): BoxedExpression;
78
76
  simplify(options?: Partial<SimplifyOptions>): BoxedExpression;
79
77
  N(): BoxedExpression;
80
78
  }
81
- export declare function isBoxedTensor(val: unknown): val is BoxedTensor;
79
+ export declare function isBoxedTensor(val: unknown): val is BoxedTensor<any>;
82
80
  export declare function expressionTensorInfo(operator: string, rows: ReadonlyArray<BoxedExpression>): {
83
81
  shape: number[];
84
- dtype: TensorDataType | undefined;
82
+ dtype: TensorDataType;
85
83
  } | undefined;
86
- export declare function expressionAsTensor<T extends TensorDataType = 'expression'>(operator: string, rows: ReadonlyArray<BoxedExpression>): TensorData<T> | undefined;
@@ -0,0 +1,46 @@
1
+ /* 0.30.0 */
2
+ import type { Type, TypeString } from '../../common/type/types';
3
+ import { BoxedType } from '../../common/type/boxed-type';
4
+ import { ConfigurationChangeListener } from '../../common/configuration-change';
5
+ /**
6
+ * ### THEORY OF OPERATIONS
7
+ *
8
+ * - The value in the definition is the initial value of the symbol when
9
+ * entering an evaluation context. Unless it is a constant, it is not the
10
+ * value of the symbol itself, which is stored in the evaluation context.
11
+ *
12
+ * - The value or type of a constant cannot be changed.
13
+ *
14
+ * - When the type is changed, the value is preserved if it is compatible
15
+ * with the new type, otherwise it is reset to no value.
16
+ *
17
+ * - When the value is changed, the type is unaffected. If the value is not
18
+ * compatible with the type (setting a def with a numeric type to a value
19
+ * of `True` for example), the value is discarded.
20
+ *
21
+ */
22
+ export declare class _BoxedValueDefinition implements BoxedValueDefinition, ConfigurationChangeListener {
23
+ readonly name: string; /** Used for debugging and error messages */
24
+ wikidata?: string;
25
+ description?: string | string[];
26
+ url?: string;
27
+ private _engine;
28
+ private _defValue?;
29
+ private _value;
30
+ private _type;
31
+ inferredType: boolean;
32
+ _isConstant: boolean;
33
+ holdUntil: 'never' | 'evaluate' | 'N';
34
+ eq?: (a: BoxedExpression) => boolean | undefined;
35
+ neq?: (a: BoxedExpression) => boolean | undefined;
36
+ cmp?: (a: BoxedExpression) => '=' | '>' | '<' | undefined;
37
+ collection?: CollectionHandlers;
38
+ constructor(ce: ComputeEngine, name: string, def: Partial<ValueDefinition>);
39
+ /** For debugging */
40
+ toJSON(): any;
41
+ get isConstant(): boolean;
42
+ get value(): BoxedExpression | undefined;
43
+ get type(): BoxedType;
44
+ set type(t: Type | TypeString | BoxedType);
45
+ onConfigurationChange(): void;
46
+ }
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  value: T | null;
3
3
  generation: number | undefined;
4
4
  };
@@ -0,0 +1,5 @@
1
+ /* 0.30.0 */
2
+ /**
3
+ * Ensure all expressions in the array are in canonical form
4
+ */
5
+ export declare function canonical(ce: ComputeEngine, xs: ReadonlyArray<BoxedExpression>, scope?: Scope): ReadonlyArray<BoxedExpression>;
@@ -1,2 +1,2 @@
1
- /* 0.29.1 */
2
- export declare function canonicalForm(expr: BoxedExpression, forms: CanonicalOptions): BoxedExpression;
1
+ /* 0.30.0 */
2
+ export declare function canonicalForm(expr: BoxedExpression, forms: CanonicalOptions, scope?: Scope): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  /**
3
3
  * Structural equality of boxed expressions.
4
4
  */
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.0 */
2
2
  export declare function expandProducts(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression | null;
3
3
  export declare function choose(n: number, k: number): number;
4
4
  /** Attempt to transform the expression (h, ops) into a sum */