@cortex-js/compute-engine 0.29.0 → 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 +28330 -24627
  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} +28330 -24627
  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 +2 -5
  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,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  * A primitive type is a simple type that represents a concrete value.
3
3
  *
4
4
  * - `any`: the top type
@@ -12,7 +12,7 @@
12
12
  * - a symbolic expression, such as `["Add", "x", 1]`
13
13
  * - `<value>`
14
14
  * - `symbol`: a symbol, such as `x`.
15
- * - `function`: a function expression
15
+ * - `function`: a function literal
16
16
  * such as `["Function", ["Add", "x", 1], "x"]`.
17
17
  *
18
18
  * - `value`
@@ -21,19 +21,24 @@
21
21
  * - `boolean`: a boolean value: `True` or `False`.
22
22
  * - `string`: a string of characters.
23
23
  * - `collection`
24
- * - `list`: a collection of expressions, possibly recursive,
25
- * with optional dimensions, e.g. `[number]`, `[boolean^32]`,
26
- * `[number^(2x3)]`. Used to represent a vector, a matrix or a
27
- * tensor when the type of its elements is a number
28
24
  * - `set`: a collection of unique expressions, e.g. `set<string>`.
29
- * - `tuple`: a fixed-size collection of named or unnamed elements, e.g.
30
- * `tuple<number, boolean>`, `tuple<x: number, y: boolean>`.
31
- * - `map`: a set key-value pairs, e.g. `map<x: number, y: boolean>`.
25
+ * - `record`: a collection of specific key-value pairs,
26
+ * e.g. `record<x: number, y: boolean>`.
27
+ * - `dictionary`: a collection of arbitrary key-value pairs
28
+ * e.g. `dictionary<string, number>`.
29
+ * - `indexed_collection`: collections whose elements can be accessed
30
+ * by a numeric index
31
+ * - `list`: a collection of expressions, possibly recursive,
32
+ * with optional dimensions, e.g. `[number]`, `[boolean^32]`,
33
+ * `[number^(2x3)]`. Used to represent a vector, a matrix or a
34
+ * tensor when the type of its elements is a number
35
+ * - `tuple`: a fixed-size collection of named or unnamed elements,
36
+ * e.g. `tuple<number, boolean>`, `tuple<x: number, y: boolean>`.
32
37
  *
33
38
  *
34
39
  *
35
40
  */
36
- export type PrimitiveType = NumericType | 'collection' | 'list' | 'set' | 'map' | 'tuple' | 'value' | 'scalar' | 'function' | 'symbol' | 'boolean' | 'string' | 'expression' | 'unknown' | 'error' | 'nothing' | 'never' | 'any';
41
+ export type PrimitiveType = NumericPrimitiveType | 'collection' | 'indexed_collection' | 'list' | 'set' | 'dictionary' | 'record' | 'dictionary' | 'tuple' | 'value' | 'scalar' | 'function' | 'symbol' | 'boolean' | 'string' | 'expression' | 'unknown' | 'error' | 'nothing' | 'never' | 'any';
37
42
  /**
38
43
  * - `number`: any numeric value = `complex` + `real` plus `NaN`
39
44
  * - `complex`: a number with non-zero real and imaginary parts = `finite_complex` plus `ComplexInfinity`
@@ -49,7 +54,7 @@ export type PrimitiveType = NumericType | 'collection' | 'list' | 'set' | 'map'
49
54
  * - `rational`: a pure rational number (not an integer) = `finite_rational` + `non_finite_number`
50
55
  *
51
56
  */
52
- export type NumericType = 'number' | 'finite_number' | 'complex' | 'finite_complex' | 'imaginary' | 'real' | 'finite_real' | 'rational' | 'finite_rational' | 'integer' | 'finite_integer' | 'non_finite_number';
57
+ export type NumericPrimitiveType = 'number' | 'finite_number' | 'complex' | 'finite_complex' | 'imaginary' | 'real' | 'finite_real' | 'rational' | 'finite_rational' | 'integer' | 'finite_integer' | 'non_finite_number';
53
58
  export type NamedElement = {
54
59
  name?: string;
55
60
  type: Type;
@@ -58,7 +63,8 @@ export type FunctionSignature = {
58
63
  kind: 'signature';
59
64
  args?: NamedElement[];
60
65
  optArgs?: NamedElement[];
61
- restArg?: NamedElement;
66
+ variadicArg?: NamedElement;
67
+ variadicMin?: 0 | 1;
62
68
  result: Type;
63
69
  };
64
70
  export type AlgebraicType = {
@@ -73,24 +79,42 @@ export type ValueType = {
73
79
  kind: 'value';
74
80
  value: any;
75
81
  };
76
- /** Map is a non-indexable collection of key/value pairs.
77
- * An element of a map whose type is a subtype of `nothing` is optional.
78
- * For example, in `{x: number, y: boolean | nothing}` the element `y` is optional.
82
+ /** A record is a collection of key-value pairs.
83
+ *
84
+ * The keys are strings. The set of keys is fixed.
85
+ *
86
+ * For a record type to be a subtype of another record type, it must have a
87
+ * subset of the keys, and all their types must match (width subtyping).
88
+ *
79
89
  */
80
- export type MapType = {
81
- kind: 'map';
90
+ export type RecordType = {
91
+ kind: 'record';
82
92
  elements: Record<string, Type>;
83
93
  };
84
- /** Collection, List, Set, Tuple and Map are collections.
94
+ /** A dictionary is a collection of key-value pairs.
85
95
  *
96
+ * The keys are strings. The set of keys is also not defined as part of the
97
+ * type and can be modified at runtime.
98
+ *
99
+ * A dictionary is suitable for use as cache or data storage.
100
+ */
101
+ export type DictionaryType = {
102
+ kind: 'dictionary';
103
+ values: Type;
104
+ };
105
+ /**
86
106
  * `CollectionType` is a generic collection of elements of a certain type.
107
+ *
108
+ * - Indexed collections: List, Tuple
109
+ * - Non-indexed: Set, Record, Dictionary
110
+ *
87
111
  */
88
112
  export type CollectionType = {
89
- kind: 'collection';
113
+ kind: 'collection' | 'indexed_collection';
90
114
  elements: Type;
91
115
  };
92
116
  /**
93
- * The elements of a list are ordered.
117
+ * The elements of a list can be accessed by their one-based index.
94
118
  *
95
119
  * All elements of a list have the same type, but it can be a broad type,
96
120
  * up to `any`.
@@ -106,13 +130,30 @@ export type ListType = {
106
130
  elements: Type;
107
131
  dimensions?: number[];
108
132
  };
133
+ export type SymbolType = {
134
+ kind: 'symbol';
135
+ name: string;
136
+ };
137
+ export type ExpressionType = {
138
+ kind: 'expression';
139
+ operator: string;
140
+ };
141
+ export type NumericType = {
142
+ kind: 'numeric';
143
+ type: NumericPrimitiveType;
144
+ lower?: number;
145
+ upper?: number;
146
+ };
109
147
  /** Each element of a set is unique (is not present in the set more than once).
110
- * The elements of a set are not ordered.
148
+ * The elements of a set are not indexed.
111
149
  */
112
150
  export type SetType = {
113
151
  kind: 'set';
114
152
  elements: Type;
115
153
  };
154
+ /** The elements of a tuple are indexed and may be named or unnamed.
155
+ * If one element is named, all elements must be named.
156
+ */
116
157
  export type TupleType = {
117
158
  kind: 'tuple';
118
159
  elements: NamedElement[];
@@ -120,9 +161,11 @@ export type TupleType = {
120
161
  /** Nominal typing */
121
162
  export type TypeReference = {
122
163
  kind: 'reference';
123
- ref: string;
164
+ name: string;
165
+ alias: boolean;
166
+ def: Type | undefined;
124
167
  };
125
- export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType | ListType | SetType | MapType | TupleType | FunctionSignature | ValueType | TypeReference;
168
+ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType | ListType | SetType | RecordType | DictionaryType | TupleType | SymbolType | ExpressionType | NumericType | NumericPrimitiveType | FunctionSignature | ValueType | TypeReference;
126
169
  /**
127
170
  * The type of a boxed expression indicates the kind of expression it is and
128
171
  * the value it represents.
@@ -222,7 +265,7 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
222
265
  * - `"number -> number"` -- a signature with a single argument
223
266
  * - `"(x: number, number) -> number"` -- a signature with a named argument
224
267
  * - `"(number, y:number?) -> number"` -- a signature with an optional named argument (can have several optional arguments, at the end)
225
- * - `"(number, ...number) -> number"` -- a signature with a rest argument (can have only one, and no optional arguments if there is a rest argument).
268
+ * - `"(number, number+) -> number"` -- a signature with a rest argument (can have only one, and no optional arguments if there is a rest argument).
226
269
  * - `"() -> number"` -- a signature with an empty argument list
227
270
  * - `"number | boolean"` -- a union type
228
271
  * - `"(x: number) & (y: number)"` -- an intersection type
@@ -231,4 +274,27 @@ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType
231
274
  */
232
275
  export type TypeString = string;
233
276
  export type TypeCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
234
- export type TypeResolver = (name: string) => Type | undefined;
277
+ /** A type resolver should return a definition for a given type name.
278
+ */
279
+ export type TypeResolver = {
280
+ /** Return a list of all type names that are defined in the resolver. This is
281
+ * used to display error messages when a type is not found. */
282
+ get names(): string[];
283
+ forward: (name: string) => TypeReference | undefined;
284
+ resolve: (name: string) => TypeReference | undefined;
285
+ };
286
+ /**
287
+ * ### Future considerations:
288
+ * - Add support for generics (e.g. `list<T>`), i.e. parametric polymorphism,
289
+ * - Add support for type constraints (e.g. `list<T: number>` or list<T> where T: number),
290
+ * - Add support for type variants (e.g. a la Rust enums)
291
+ * Maybe something like
292
+ * `variant<Square, Circle>` or
293
+ * `variant<Square(side: integer), Circle(radius: integer)>`
294
+ * `variant<Square: {side: integer}, Circle: {radius: integer}>`
295
+ * - Add support for dependent types, with type-level computations
296
+ * - Add support for integers, booleans, symbols and strings, i.e. "T = "red" | "green" | "blue""
297
+ * - Add support for conditional types (e.g. `T extends U ? X : Y`)
298
+ *
299
+ *
300
+ */
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  /** Convert two or more types into a more specific type that is a subtype of
3
3
  * all the input types. The resulting type is usually more constrained and
4
4
  * only encompasses values that belong to both input types.
@@ -32,4 +32,5 @@ export declare function isSignatureType(type: Readonly<Type> | TypeString): type
32
32
  export declare function functionSignature(type: Readonly<Type>): Type | undefined;
33
33
  export declare function functionResult(type: Readonly<Type> | undefined): Type | undefined;
34
34
  export declare function collectionElementType(type: Readonly<Type>): Type | undefined;
35
+ export declare function isValidTypeName(name: string): boolean;
35
36
  export declare function isValidType(t: any): t is Readonly<Type>;
@@ -1,2 +1,2 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export declare function hidePrivateProperties(obj: any): void;
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  /**
3
3
  * Add an assumption, in the form of a predicate, for example:
4
4
  *
@@ -7,7 +7,7 @@
7
7
  * - `x > 3`
8
8
  * - `x + y = 5`
9
9
  *
10
- * Assumptions that represent a symbol definition (equality to an expression,
10
+ * Assumptions that represent a value definition (equality to an expression,
11
11
  * membership to a type, >0, <=0, etc...) are stored directly in the current
12
12
  * scope's symbols dictionary, and an entry for the symbol is created if
13
13
  * necessary.
@@ -1,36 +1,27 @@
1
- /* 0.29.0 */
2
- import { Expression, MathJsonIdentifier } from '../../math-json/types';
1
+ /* 0.30.0 */
2
+ import type { Expression, MathJsonSymbol } from '../../math-json/types';
3
3
  import type { Type, TypeString } from '../../common/type/types';
4
4
  import { BoxedType } from '../../common/type/boxed-type';
5
- import type { BoxedSubstitution, Metadata, RuntimeScope, Substitution, CanonicalOptions, BoxedRuleSet, Rule, BoxedBaseDefinition, BoxedSymbolDefinition, BoxedFunctionDefinition, EvaluateOptions, CompiledType, Sign, BoxedExpression, JsonSerializationOptions, PatternMatchOptions, SimplifyOptions, TensorData, ComputeEngine } from '../global-types';
5
+ import type { BoxedSubstitution, Metadata, Substitution, CanonicalOptions, BoxedRuleSet, Rule, BoxedBaseDefinition, BoxedValueDefinition, BoxedOperatorDefinition, EvaluateOptions, Sign, BoxedExpression, JsonSerializationOptions, PatternMatchOptions, SimplifyOptions, ComputeEngine, Scope, Tensor } from '../global-types';
6
6
  import type { NumericValue } from '../numeric-value/types';
7
7
  import type { SmallInteger } from '../numerics/types';
8
8
  import type { LatexString, SerializeLatexOptions } from '../latex-syntax/types';
9
- import { AsciiMathOptions } from './ascii-math';
10
9
  /**
11
10
  * _BoxedExpression
11
+ *
12
+ * @internal
12
13
  */
13
14
  export declare abstract class _BoxedExpression implements BoxedExpression {
14
15
  abstract readonly hash: number;
15
16
  abstract readonly json: Expression;
16
- abstract readonly operator: string;
17
- /** @deprecated */
18
- get head(): string;
19
- abstract get isCanonical(): boolean;
20
- abstract set isCanonical(_val: boolean);
17
+ abstract isCanonical: boolean;
21
18
  abstract match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
22
19
  readonly engine: ComputeEngine;
23
20
  /** Verbatim LaTeX, obtained from a source, i.e. from parsing,
24
21
  * not generated synthetically
25
22
  */
26
- verbatimLatex?: string;
23
+ readonly verbatimLatex?: string;
27
24
  constructor(ce: ComputeEngine, metadata?: Metadata);
28
- isSame(rhs: BoxedExpression): boolean;
29
- isEqual(rhs: number | BoxedExpression): boolean | undefined;
30
- isLess(_rhs: number | BoxedExpression): boolean | undefined;
31
- isLessEqual(_rhs: number | BoxedExpression): boolean | undefined;
32
- isGreater(_rhs: number | BoxedExpression): boolean | undefined;
33
- isGreaterEqual(_rhs: number | BoxedExpression): boolean | undefined;
34
25
  /**
35
26
  *
36
27
  * `Object.valueOf()`: return a JavaScript primitive value for the expression
@@ -38,12 +29,12 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
38
29
  * Primitive values are: boolean, number, bigint, string, null, undefined
39
30
  *
40
31
  */
41
- valueOf(): number | object | string | boolean;
42
- toAsciiMath(options?: Partial<AsciiMathOptions>): string;
32
+ valueOf(): number | number[] | number[][] | number[][][] | string | boolean;
33
+ [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
43
34
  /** Object.toString() */
44
35
  toString(): string;
45
- print(): void;
46
- [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
36
+ toLatex(options?: Partial<SerializeLatexOptions>): LatexString;
37
+ get latex(): LatexString;
47
38
  /** Called by `JSON.stringify()` when serializing to json.
48
39
  *
49
40
  * Note: this is a standard method of JavaScript objects.
@@ -51,51 +42,27 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
51
42
  */
52
43
  toJSON(): Expression;
53
44
  toMathJson(options?: Readonly<Partial<JsonSerializationOptions>>): Expression;
54
- toLatex(options?: Partial<SerializeLatexOptions>): LatexString;
55
- toNumericValue(): [NumericValue, BoxedExpression];
56
- get scope(): RuntimeScope | null;
57
- is(rhs: any): boolean;
45
+ print(): void;
46
+ get isStructural(): boolean;
58
47
  get canonical(): BoxedExpression;
59
48
  get structural(): BoxedExpression;
60
- get isStructural(): boolean;
61
- get latex(): LatexString;
62
- set latex(val: LatexString);
63
- get symbol(): string | null;
64
- get tensor(): null | TensorData<'expression'>;
65
- get string(): string | null;
66
- getSubexpressions(operator: MathJsonIdentifier): ReadonlyArray<BoxedExpression>;
67
- get subexpressions(): ReadonlyArray<BoxedExpression>;
68
- get symbols(): ReadonlyArray<string>;
69
- get unknowns(): ReadonlyArray<string>;
70
- get freeVariables(): ReadonlyArray<string>;
71
- get errors(): ReadonlyArray<BoxedExpression>;
72
- get ops(): null | ReadonlyArray<BoxedExpression>;
73
- get nops(): SmallInteger;
74
- get op1(): BoxedExpression;
75
- get op2(): BoxedExpression;
76
- get op3(): BoxedExpression;
77
49
  get isValid(): boolean;
78
50
  get isPure(): boolean;
79
- /** Literals (number, string, boolean) are constants. Some symbols
80
- * may also be constants (e.g. Pi, E, True, False). Expressions of constant
81
- * symbols are also constants (if the function is pure).
82
- */
83
51
  get isConstant(): boolean;
84
- get isNaN(): boolean | undefined;
85
- get isInfinity(): boolean | undefined;
86
- get isFinite(): boolean | undefined;
52
+ get isNumberLiteral(): boolean;
53
+ get numericValue(): number | NumericValue | null;
54
+ toNumericValue(): [NumericValue, BoxedExpression];
87
55
  get isEven(): boolean | undefined;
88
56
  get isOdd(): boolean | undefined;
89
- get numericValue(): number | NumericValue | null;
90
- get isNumberLiteral(): boolean;
91
- get isFunctionExpression(): boolean;
92
57
  get re(): number;
93
58
  get im(): number;
94
59
  get bignumRe(): Decimal | undefined;
95
60
  get bignumIm(): Decimal | undefined;
96
- get numerator(): BoxedExpression;
97
- get denominator(): BoxedExpression;
98
- get numeratorDenominator(): [BoxedExpression, BoxedExpression];
61
+ get sgn(): Sign | undefined;
62
+ get isPositive(): boolean | undefined;
63
+ get isNonNegative(): boolean | undefined;
64
+ get isNegative(): boolean | undefined;
65
+ get isNonPositive(): boolean | undefined;
99
66
  neg(): BoxedExpression;
100
67
  inv(): BoxedExpression;
101
68
  abs(): BoxedExpression;
@@ -107,7 +74,36 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
107
74
  root(exp: number | BoxedExpression): BoxedExpression;
108
75
  sqrt(): BoxedExpression;
109
76
  ln(base?: number | BoxedExpression): BoxedExpression;
110
- get sgn(): Sign | undefined;
77
+ get numerator(): BoxedExpression;
78
+ get denominator(): BoxedExpression;
79
+ get numeratorDenominator(): [BoxedExpression, BoxedExpression];
80
+ is(other: BoxedExpression | number | bigint | boolean | string): boolean;
81
+ isSame(other: BoxedExpression): boolean;
82
+ isEqual(other: number | BoxedExpression): boolean | undefined;
83
+ isLess(other: number | BoxedExpression): boolean | undefined;
84
+ isLessEqual(other: number | BoxedExpression): boolean | undefined;
85
+ isGreater(other: number | BoxedExpression): boolean | undefined;
86
+ isGreaterEqual(other: number | BoxedExpression): boolean | undefined;
87
+ get symbol(): string | null;
88
+ get tensor(): null | Tensor<any>;
89
+ get string(): string | null;
90
+ getSubexpressions(operator: MathJsonSymbol): ReadonlyArray<BoxedExpression>;
91
+ get subexpressions(): ReadonlyArray<BoxedExpression>;
92
+ get symbols(): ReadonlyArray<string>;
93
+ get unknowns(): ReadonlyArray<string>;
94
+ get errors(): ReadonlyArray<BoxedExpression>;
95
+ get isFunctionExpression(): boolean;
96
+ get ops(): null | ReadonlyArray<BoxedExpression>;
97
+ get isScoped(): boolean;
98
+ get localScope(): Scope | undefined;
99
+ abstract readonly operator: string;
100
+ get nops(): SmallInteger;
101
+ get op1(): BoxedExpression;
102
+ get op2(): BoxedExpression;
103
+ get op3(): BoxedExpression;
104
+ get isNaN(): boolean | undefined;
105
+ get isInfinity(): boolean | undefined;
106
+ get isFinite(): boolean | undefined;
111
107
  get shape(): number[];
112
108
  get rank(): number;
113
109
  subs(_sub: Substitution, options?: {
@@ -120,22 +116,18 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
120
116
  solve(_vars?: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
121
117
  replace(_rules: BoxedRuleSet | Rule | Rule[]): null | BoxedExpression;
122
118
  has(_v: string | string[]): boolean;
123
- get isPositive(): boolean | undefined;
124
- get isNonNegative(): boolean | undefined;
125
- get isNegative(): boolean | undefined;
126
- get isNonPositive(): boolean | undefined;
127
119
  get description(): string[] | undefined;
128
120
  get url(): string | undefined;
129
121
  get wikidata(): string | undefined;
130
122
  get complexity(): number | undefined;
131
123
  get baseDefinition(): BoxedBaseDefinition | undefined;
132
- get symbolDefinition(): BoxedSymbolDefinition | undefined;
133
- get functionDefinition(): BoxedFunctionDefinition | undefined;
134
- infer(_t: Type): boolean;
124
+ get valueDefinition(): BoxedValueDefinition | undefined;
125
+ get operatorDefinition(): BoxedOperatorDefinition | undefined;
126
+ infer(t: Type, inferenceMode?: 'narrow' | 'widen'): boolean;
135
127
  bind(): void;
136
128
  reset(): void;
137
- get value(): number | boolean | string | object | undefined;
138
- set value(_value: BoxedExpression | number | boolean | string | number[] | undefined);
129
+ get value(): BoxedExpression | undefined;
130
+ set value(_value: any);
139
131
  get type(): BoxedType;
140
132
  set type(_type: Type | TypeString | BoxedType);
141
133
  get isNumber(): boolean | undefined;
@@ -149,18 +141,25 @@ export declare abstract class _BoxedExpression implements BoxedExpression {
149
141
  N(): BoxedExpression;
150
142
  compile(options?: {
151
143
  to?: 'javascript';
152
- functions?: Record<MathJsonIdentifier, string | ((...any: any[]) => any)>;
153
- vars?: Record<MathJsonIdentifier, string>;
144
+ functions?: Record<MathJsonSymbol, string | ((...any: any[]) => any)>;
145
+ vars?: Record<MathJsonSymbol, string>;
154
146
  imports?: ((...any: any[]) => any)[];
155
147
  preamble?: string;
156
- }): (args: Record<string, any>) => CompiledType;
148
+ fallback?: boolean;
149
+ }): ((...args: any[]) => any) & {
150
+ isCompiled?: boolean;
151
+ };
157
152
  get isCollection(): boolean;
158
- contains(_rhs: BoxedExpression): boolean;
159
- subsetOf(_target: BoxedExpression, _strict: boolean): boolean;
160
- get size(): number;
161
- each(_start?: number, _count?: number): Iterator<BoxedExpression, undefined>;
153
+ get isIndexedCollection(): boolean;
154
+ get isLazyCollection(): boolean;
155
+ xcontains(_rhs: BoxedExpression): boolean | undefined;
156
+ subsetOf(_target: BoxedExpression, _strict: boolean): boolean | undefined;
157
+ get xsize(): number | undefined;
158
+ get isEmptyCollection(): boolean | undefined;
159
+ get isFiniteCollection(): boolean | undefined;
160
+ each(): Generator<BoxedExpression>;
162
161
  at(_index: number): BoxedExpression | undefined;
163
162
  get(_key: string | BoxedExpression): BoxedExpression | undefined;
164
- indexOf(_expr: BoxedExpression): number;
163
+ indexWhere(_predicate: (element: BoxedExpression) => boolean): number | undefined;
165
164
  }
166
- export declare function getSubexpressions(expr: BoxedExpression, name: MathJsonIdentifier): ReadonlyArray<BoxedExpression>;
165
+ export declare function getSubexpressions(expr: BoxedExpression, name: MathJsonSymbol): ReadonlyArray<BoxedExpression>;
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import type { BoxedExpression } from '../global-types';
4
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;
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  import { BoxedType } from '../../common/type/boxed-type';
3
3
  import type { BoxedExpression, ComputeEngine } from '../global-types';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  /**
3
3
  * Canonical form of 'Divide' (and 'Rational')
4
4
  * - remove denominator of 1
@@ -12,7 +12,7 @@ export declare function canonicalDivide(op1: BoxedExpression, op2: BoxedExpressi
12
12
  export declare function div(num: BoxedExpression, denom: number | BoxedExpression): BoxedExpression;
13
13
  /**
14
14
  * The canonical form of `Multiply`:
15
- * - removes `1` anb `-1`
15
+ * - removes `1` and `-1`
16
16
  * - simplifies the signs:
17
17
  * - i.e. `-y \times -x` -> `x \times y`
18
18
  * - `2 \times -x` -> `-2 \times x`
@@ -1,6 +1,24 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  import type { Rational } from '../numerics/types';
3
3
  export declare function asRadical(expr: BoxedExpression): Rational | null;
4
+ /**
5
+ *
6
+ * Produce the canonical form of the operands of a Power expression, returning either the operation
7
+ * result (e.g. 'a^1 -> a'), an alternate expr. representation ('a^{1/2} -> Sqrt(a)'), or an
8
+ * unchanged 'Power' expression. Operations include:
9
+ *
10
+ * - @todo
11
+ *
12
+ * Both the given base and exponent can either be canonical or non-canonical: with fully
13
+ * canonicalized args. lending to more simplifications.
14
+ *
15
+ * Returns a canonical expr. is both operands are canonical.
16
+
17
+ * @export
18
+ * @param a
19
+ * @param b
20
+ * @returns
21
+ */
4
22
  export declare function canonicalPower(a: BoxedExpression, b: BoxedExpression): BoxedExpression;
5
23
  export declare function canonicalRoot(a: BoxedExpression, b: BoxedExpression | number): BoxedExpression;
6
24
  /**
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export type AsciiMathSerializer = (expr: BoxedExpression, precedence?: number) => string;
3
3
  export type AsciiMathOptions = {
4
4
  symbols: Record<string, string>;
@@ -1,7 +1,5 @@
1
- /* 0.29.0 */
2
- import { Decimal } from 'decimal.js';
3
- import type { SemiBoxedExpression, BoxedExpression, CanonicalOptions, ComputeEngine, Metadata } from '../global-types';
4
- import { MathJsonIdentifier } from '../../math-json/types';
1
+ /* 0.30.0 */
2
+ import { MathJsonSymbol } from '../../math-json/types';
5
3
  import { NumericValue } from '../numeric-value/types';
6
4
  /**
7
5
  * Given a name and a set of arguments, return a boxed function expression.
@@ -10,10 +8,11 @@ import { NumericValue } from '../numeric-value/types';
10
8
  *
11
9
  * Note that `boxFunction()` should only be called from `ce.function()`
12
10
  */
13
- export declare function boxFunction(ce: ComputeEngine, name: MathJsonIdentifier, ops: readonly SemiBoxedExpression[], options?: {
11
+ export declare function boxFunction(ce: ComputeEngine, name: MathJsonSymbol, ops: readonly SemiBoxedExpression[], options?: {
14
12
  metadata?: Metadata;
15
13
  canonical?: CanonicalOptions;
16
14
  structural?: boolean;
15
+ scope?: Scope;
17
16
  }): BoxedExpression;
18
17
  /**
19
18
  * Notes about the boxed form:
@@ -43,5 +42,6 @@ export declare function boxFunction(ce: ComputeEngine, name: MathJsonIdentifier,
43
42
  export declare function box(ce: ComputeEngine, expr: null | undefined | NumericValue | SemiBoxedExpression, options?: {
44
43
  canonical?: CanonicalOptions;
45
44
  structural?: boolean;
45
+ scope?: Scope;
46
46
  }): BoxedExpression;
47
- export declare function toBigint(x: Complex | Decimal | SemiBoxedExpression): bigint | null;
47
+ export declare function semiCanonical(ce: ComputeEngine, xs: ReadonlyArray<SemiBoxedExpression>, scope?: Scope): ReadonlyArray<BoxedExpression>;
@@ -0,0 +1,42 @@
1
+ /* 0.30.0 */
2
+ import { _BoxedExpression } from './abstract-boxed-expression';
3
+ import { BoxedType } from '../../common/type/boxed-type';
4
+ import { Expression } from '../../math-json/types';
5
+ /**
6
+ * BoxedDictionary
7
+ *
8
+ */
9
+ export declare class BoxedDictionary extends _BoxedExpression implements DictionaryInterface {
10
+ [Symbol.toStringTag]: string;
11
+ private readonly _keyValues;
12
+ private _type;
13
+ constructor(ce: ComputeEngine, keyValues: Record<string, SemiBoxedExpression> | BoxedExpression, options?: {
14
+ metadata?: Metadata;
15
+ canonical?: boolean;
16
+ });
17
+ private _initFromRecord;
18
+ private _initFromExpression;
19
+ get json(): Expression;
20
+ get hash(): number;
21
+ get operator(): string;
22
+ get type(): BoxedType;
23
+ get isPure(): boolean;
24
+ get isCanonical(): boolean;
25
+ set isCanonical(_va: boolean);
26
+ get value(): BoxedExpression | undefined;
27
+ get complexity(): number;
28
+ get isCollection(): boolean;
29
+ get isIndexedCollection(): boolean;
30
+ get isLazyCollection(): boolean;
31
+ xcontains(_rhs: BoxedExpression): boolean | undefined;
32
+ get xsize(): number | undefined;
33
+ get isEmptyCollection(): boolean;
34
+ get isFiniteCollection(): boolean;
35
+ each(): Generator<BoxedExpression>;
36
+ get(key: string): BoxedExpression | undefined;
37
+ has(key: string): boolean;
38
+ get keys(): string[];
39
+ get entries(): [string, BoxedExpression][];
40
+ get values(): BoxedExpression[];
41
+ match(pattern: BoxedExpression, _options?: PatternMatchOptions): BoxedSubstitution | null;
42
+ }