@cortex-js/compute-engine 0.32.0 → 0.32.1

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 +42905 -0
  2. package/dist/compute-engine.min.esm.js +125 -0
  3. package/dist/compute-engine.min.umd.js +127 -0
  4. package/dist/compute-engine.umd.js +42930 -0
  5. package/dist/math-json.esm.js +130 -0
  6. package/dist/math-json.min.esm.js +130 -0
  7. package/dist/math-json.min.umd.js +4 -0
  8. package/dist/math-json.umd.js +155 -0
  9. package/dist/types/common/ansi-codes.d.ts +41 -0
  10. package/dist/types/common/configuration-change.d.ts +28 -0
  11. package/dist/types/common/fuzzy-string-match.d.ts +2 -0
  12. package/dist/types/common/grapheme-splitter.d.ts +15 -0
  13. package/dist/types/common/interruptible.d.ts +20 -0
  14. package/dist/types/common/one-of.d.ts +10 -0
  15. package/dist/types/common/signals.d.ts +96 -0
  16. package/dist/types/common/type/ast-nodes.d.ts +146 -0
  17. package/dist/types/common/type/boxed-type.d.ts +30 -0
  18. package/dist/types/common/type/lexer.d.ts +51 -0
  19. package/dist/types/common/type/parse.d.ts +211 -0
  20. package/dist/types/common/type/parser.d.ts +45 -0
  21. package/dist/types/common/type/primitive.d.ts +10 -0
  22. package/dist/types/common/type/serialize.d.ts +2 -0
  23. package/dist/types/common/type/subtype.d.ts +6 -0
  24. package/dist/types/common/type/type-builder.d.ts +32 -0
  25. package/dist/types/common/type/types.d.ts +300 -0
  26. package/dist/types/common/type/utils.d.ts +36 -0
  27. package/dist/types/common/utils.d.ts +23 -0
  28. package/dist/types/compute-engine/assume.d.ts +26 -0
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +165 -0
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +16 -0
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +27 -0
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +38 -0
  34. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  35. package/dist/types/compute-engine/boxed-expression/box.d.ts +47 -0
  36. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +44 -0
  37. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +136 -0
  38. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +103 -0
  39. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +53 -0
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +107 -0
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +27 -0
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +170 -0
  43. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +83 -0
  44. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +7 -0
  46. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
  47. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -0
  48. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  49. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  50. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  51. package/dist/types/compute-engine/boxed-expression/factor.d.ts +10 -0
  52. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  53. package/dist/types/compute-engine/boxed-expression/hold.d.ts +10 -0
  54. package/dist/types/compute-engine/boxed-expression/match.d.ts +41 -0
  55. package/dist/types/compute-engine/boxed-expression/negate.d.ts +11 -0
  56. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +34 -0
  57. package/dist/types/compute-engine/boxed-expression/order.d.ts +71 -0
  58. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +105 -0
  59. package/dist/types/compute-engine/boxed-expression/product.d.ts +66 -0
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -0
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +46 -0
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +20 -0
  65. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  66. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +9 -0
  67. package/dist/types/compute-engine/boxed-expression/utils.d.ts +64 -0
  68. package/dist/types/compute-engine/boxed-expression/validate.d.ts +58 -0
  69. package/dist/types/compute-engine/collection-utils.d.ts +35 -0
  70. package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
  71. package/dist/types/compute-engine/compilation/javascript-target.d.ts +68 -0
  72. package/dist/types/compute-engine/compilation/types.d.ts +83 -0
  73. package/dist/types/compute-engine/cost-function.d.ts +13 -0
  74. package/dist/types/compute-engine/function-utils.d.ts +120 -0
  75. package/dist/types/compute-engine/global-types.d.ts +2930 -0
  76. package/dist/types/compute-engine/index.d.ts +660 -0
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +2 -0
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +27 -0
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +2 -0
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +2 -0
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
  88. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +3 -0
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  90. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +88 -0
  91. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  92. package/dist/types/compute-engine/latex-syntax/parse.d.ts +316 -0
  93. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +29 -0
  94. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +10 -0
  95. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +37 -0
  96. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +18 -0
  97. package/dist/types/compute-engine/latex-syntax/types.d.ts +896 -0
  98. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  99. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -0
  100. package/dist/types/compute-engine/library/calculus.d.ts +2 -0
  101. package/dist/types/compute-engine/library/collections.d.ts +27 -0
  102. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  103. package/dist/types/compute-engine/library/complex.d.ts +2 -0
  104. package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
  105. package/dist/types/compute-engine/library/core.d.ts +2 -0
  106. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  107. package/dist/types/compute-engine/library/library.d.ts +17 -0
  108. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
  109. package/dist/types/compute-engine/library/logic-analysis.d.ts +64 -0
  110. package/dist/types/compute-engine/library/logic-utils.d.ts +58 -0
  111. package/dist/types/compute-engine/library/logic.d.ts +7 -0
  112. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  113. package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
  114. package/dist/types/compute-engine/library/random-expression.d.ts +2 -0
  115. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
  116. package/dist/types/compute-engine/library/sets.d.ts +2 -0
  117. package/dist/types/compute-engine/library/statistics.d.ts +2 -0
  118. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
  119. package/dist/types/compute-engine/library/utils.d.ts +77 -0
  120. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +57 -0
  121. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +75 -0
  122. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +56 -0
  123. package/dist/types/compute-engine/numeric-value/types.d.ts +116 -0
  124. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  125. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  126. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  127. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -0
  128. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +18 -0
  129. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +9 -0
  130. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  131. package/dist/types/compute-engine/numerics/numeric.d.ts +60 -0
  132. package/dist/types/compute-engine/numerics/primes.d.ts +7 -0
  133. package/dist/types/compute-engine/numerics/rationals.d.ts +43 -0
  134. package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
  135. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  136. package/dist/types/compute-engine/numerics/statistics.d.ts +24 -0
  137. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  138. package/dist/types/compute-engine/numerics/types.d.ts +30 -0
  139. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  140. package/dist/types/compute-engine/symbolic/derivative.d.ts +18 -0
  141. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  142. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +6 -0
  143. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +27 -0
  144. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +6 -0
  145. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +128 -0
  146. package/dist/types/compute-engine/tensor/tensors.d.ts +93 -0
  147. package/dist/types/compute-engine/types.d.ts +8 -0
  148. package/dist/types/compute-engine.d.ts +3 -0
  149. package/dist/types/math-json/symbols.d.ts +11 -0
  150. package/dist/types/math-json/types.d.ts +122 -0
  151. package/dist/types/math-json/utils.d.ts +87 -0
  152. package/dist/types/math-json.d.ts +3 -0
  153. package/package.json +1 -1
@@ -0,0 +1,300 @@
1
+ /* 0.32.1 */
2
+ * A primitive type is a simple type that represents a concrete value.
3
+ *
4
+ * - `any`: the top type
5
+ * - `expression`
6
+ * - `error`: an invalid value, such as `["Error", "missing"]`
7
+ * - `nothing`: the type of the `Nothing` symbol, the unit type
8
+ * - `never`: the bottom type
9
+ * - `unknown`: a value whose type is not known
10
+ *
11
+ * - `expression`:
12
+ * - a symbolic expression, such as `["Add", "x", 1]`
13
+ * - `<value>`
14
+ * - `symbol`: a symbol, such as `x`.
15
+ * - `function`: a function literal
16
+ * such as `["Function", ["Add", "x", 1], "x"]`.
17
+ *
18
+ * - `value`
19
+ * - `scalar`
20
+ * - `<number>`
21
+ * - `boolean`: a boolean value: `True` or `False`.
22
+ * - `string`: a string of characters.
23
+ * - `collection`
24
+ * - `set`: a collection of unique expressions, e.g. `set<string>`.
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>`.
37
+ *
38
+ *
39
+ *
40
+ */
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';
42
+ /**
43
+ * - `number`: any numeric value = `complex` + `real` plus `NaN`
44
+ * - `complex`: a number with non-zero real and imaginary parts = `finite_complex` plus `ComplexInfinity`
45
+ * - `finite_complex`: a finite complex number = `imaginary` + `finite_real`
46
+ * - `imaginary`: a complex number with a real part of 0 (pure imaginary)
47
+ * - `finite_number`: a finite numeric value = `finite_complex`
48
+ * - `finite_real`: a finite real number = `finite_rational` + `finite_integer`
49
+ * - `finite_rational`: a pure rational number
50
+ * - `finite_integer`: a whole number
51
+ * - `real`: a complex number with an imaginary part of 0 = `finite_real` + `non_finite_number`
52
+ * - `non_finite_number`: `PositiveInfinity`, `NegativeInfinity`
53
+ * - `integer`: a whole number = `finite_integer` + `non_finite_number`
54
+ * - `rational`: a pure rational number (not an integer) = `finite_rational` + `non_finite_number`
55
+ *
56
+ */
57
+ export type NumericPrimitiveType = 'number' | 'finite_number' | 'complex' | 'finite_complex' | 'imaginary' | 'real' | 'finite_real' | 'rational' | 'finite_rational' | 'integer' | 'finite_integer' | 'non_finite_number';
58
+ export type NamedElement = {
59
+ name?: string;
60
+ type: Type;
61
+ };
62
+ export type FunctionSignature = {
63
+ kind: 'signature';
64
+ args?: NamedElement[];
65
+ optArgs?: NamedElement[];
66
+ variadicArg?: NamedElement;
67
+ variadicMin?: 0 | 1;
68
+ result: Type;
69
+ };
70
+ export type AlgebraicType = {
71
+ kind: 'union' | 'intersection';
72
+ types: Type[];
73
+ };
74
+ export type NegationType = {
75
+ kind: 'negation';
76
+ type: Type;
77
+ };
78
+ export type ValueType = {
79
+ kind: 'value';
80
+ value: any;
81
+ };
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
+ *
89
+ */
90
+ export type RecordType = {
91
+ kind: 'record';
92
+ elements: Record<string, Type>;
93
+ };
94
+ /** A dictionary is a collection of key-value pairs.
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
+ /**
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
+ *
111
+ */
112
+ export type CollectionType = {
113
+ kind: 'collection' | 'indexed_collection';
114
+ elements: Type;
115
+ };
116
+ /**
117
+ * The elements of a list can be accessed by their one-based index.
118
+ *
119
+ * All elements of a list have the same type, but it can be a broad type,
120
+ * up to `any`.
121
+ *
122
+ * The same element can be present in the list more than once.
123
+ *
124
+ * A list can be multi-dimensional. For example, a list of integers with
125
+ * dimensions 2x3x4 is a 3D tensor with 2 layers, 3 rows and 4 columns.
126
+ *
127
+ */
128
+ export type ListType = {
129
+ kind: 'list';
130
+ elements: Type;
131
+ dimensions?: number[];
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
+ };
147
+ /** Each element of a set is unique (is not present in the set more than once).
148
+ * The elements of a set are not indexed.
149
+ */
150
+ export type SetType = {
151
+ kind: 'set';
152
+ elements: Type;
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
+ */
157
+ export type TupleType = {
158
+ kind: 'tuple';
159
+ elements: NamedElement[];
160
+ };
161
+ /** Nominal typing */
162
+ export type TypeReference = {
163
+ kind: 'reference';
164
+ name: string;
165
+ alias: boolean;
166
+ def: Type | undefined;
167
+ };
168
+ export type Type = PrimitiveType | AlgebraicType | NegationType | CollectionType | ListType | SetType | RecordType | DictionaryType | TupleType | SymbolType | ExpressionType | NumericType | NumericPrimitiveType | FunctionSignature | ValueType | TypeReference;
169
+ /**
170
+ * The type of a boxed expression indicates the kind of expression it is and
171
+ * the value it represents.
172
+ *
173
+ * The type is represented either by a primitive type (e.g. number, complex, collection, etc.), or a compound type (e.g. tuple, function signature, etc.).
174
+ *
175
+ * Types are described using the following BNF grammar:
176
+ *
177
+ * ```bnf
178
+ * <type> ::= <union_type> | "(" <type> ")"
179
+ *
180
+ * <union_type> ::= <intersection_type> (" | " <intersection_type>)*
181
+ *
182
+ * <intersection_type> ::= <primary_type> (" & " <primary_type>)*
183
+ *
184
+ * <primary_type> ::= <primitive>
185
+ * | <tuple_type>
186
+ * | <signature>
187
+ * | <list_type>
188
+ *
189
+ * <primitive> ::= "any" | "unknown" | <value-type> | <symbolic-type> | <numeric-type>
190
+ *
191
+ * <numeric-type> ::= "number" | "complex" | "imaginary" | "real" | "rational" | "integer"
192
+ *
193
+ * <value-type> ::= "value" | <numeric-type> | "collection" | "boolean" | "string"
194
+ *
195
+ * <symbolic-type> ::= "expression" | "function" | "symbol"
196
+ *
197
+ * <tuple_type> ::= "tuple<" (<name> <type> "," <named_tuple_elements>*) ">"
198
+ * | "tuple<" (<type> "," <unnamed_tuple_elements>*) ">" |
199
+ * | "tuple<" <tuple_elements> ">"
200
+ *
201
+ * <tuple_elements> ::= <unnamed_tuple_elements> | <named_tuple_elements>
202
+ *
203
+ * <unnamed_tuple_elements> ::= <type> ("," <type>)*
204
+ *
205
+ * <named_tuple_elements> ::= <name> <type> ("," <name> <type>)*
206
+ *
207
+ * <signature> ::= <arguments> " -> " <type>
208
+ *
209
+ * <arguments> ::= "()"
210
+ * | <argument>
211
+ * | "(" <argument-list> ")"
212
+ *
213
+ * <argument> ::= <type>
214
+ * | <name> <type>
215
+ *
216
+ * <rest_argument> ::= "..." <type>
217
+ * | <name> "..." <type>
218
+ *
219
+ * <optional_argument> ::= <argument> "?"
220
+ *
221
+ * <optional_arguments> ::= <optional_argument> ("," <optional_argument>)*
222
+ *
223
+ * <required_arguments> ::= <argument> ("," <argument>)*
224
+ *
225
+ * <argument-list> ::= <required_arguments> ("," <rest_argument>)?
226
+ * | <required_arguments> <optional_arguments>?
227
+ * | <optional_arguments>?
228
+ * | <rest_argument>
229
+ *
230
+ * <list_type> ::= "list<" <type> <dimensions>? ">"
231
+ *
232
+ * <dimensions> ::= "^" <fixed_size>
233
+ * | "^(" <multi_dimensional_size> ")"
234
+ *
235
+ * <fixed_size> ::= <positive-integer_literal>
236
+ *
237
+ * <multi_dimensional_size> ::= <positive-integer_literal> "x" <positive-integer_literal> ("x" <positive-integer_literal>)*
238
+ *
239
+ * <map> ::= "map" | "map<" <map_elements> ">"
240
+ *
241
+ * <map_elements> ::= <name> <type> ("," <name> <type>)*
242
+ *
243
+ * <set> ::= "set<" <type> ">"
244
+ *
245
+ * <collection ::= "collection<" <type> ">"
246
+ *
247
+ * <name> ::= <identifier> ":"
248
+ *
249
+ * <identifier> ::= [a-zA-Z_][a-zA-Z0-9_]*
250
+ *
251
+ * <positive-integer_literal> ::= [1-9][0-9]*
252
+ *```
253
+ *
254
+ * Examples of types strings:
255
+ * - `"number"` -- a simple type primitive
256
+ * - `"(number, boolean)"` -- a tuple type
257
+ * - `"(x: number, y:boolean)"` -- a named tuple/record type. Either all arguments are named, or none are
258
+ * - `"collection<any>"` -- an arbitrary collection type, with no length or element type restrictions
259
+ * - `"collection<integer>"` -- a collection type where all the elements are integers
260
+ * - `"collection<(number, boolean)>"` -- a collection of tuples
261
+ * - `"collection<(value:number, seen:boolean)>"` -- a collection of named tuples
262
+ * - `"[boolean]^32"` -- a collection type with a fixed size of 32 elements
263
+ * - `"[integer]^(2x3)"` -- an integer matrix of 2 columns and 3 rows
264
+ * - `"[integer]^(2x3x4)"` -- a tensor of dimensions 2x3x4
265
+ * - `"number -> number"` -- a signature with a single argument
266
+ * - `"(x: number, number) -> number"` -- a signature with a named argument
267
+ * - `"(number, y:number?) -> number"` -- a signature with an optional named argument (can have several optional arguments, at the end)
268
+ * - `"(number, number+) -> number"` -- a signature with a rest argument (can have only one, and no optional arguments if there is a rest argument).
269
+ * - `"() -> number"` -- a signature with an empty argument list
270
+ * - `"number | boolean"` -- a union type
271
+ * - `"(x: number) & (y: number)"` -- an intersection type
272
+ * - `"number | ((x: number) & (y: number))"` -- a union type with an intersection type
273
+ * - `"(number -> number) | number"` -- a union type with a signature and a primitive type
274
+ */
275
+ export type TypeString = string;
276
+ export type TypeCompatibility = 'covariant' | 'contravariant' | 'bivariant' | 'invariant';
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
+ */
@@ -0,0 +1,36 @@
1
+ /* 0.32.1 */
2
+ /** Convert two or more types into a more specific type that is a subtype of
3
+ * all the input types. The resulting type is usually more constrained and
4
+ * only encompasses values that belong to both input types.
5
+ *
6
+ * Examples:
7
+ * narrow('integer', 'rational') => 'integer'
8
+ * narrow('number', 'complex') => 'complex'
9
+ * narrow('number', 'collection') => 'nothing'
10
+ * narrow('number', 'value') => 'value'
11
+ * narrow('number', 'expression') => 'expression'
12
+ * narrow('number', 'string') => 'nothing'
13
+ *
14
+ *
15
+ */
16
+ export declare function narrow(...types: Readonly<Type>[]): Type;
17
+ /**
18
+ * Convert two or more types into a broader, more general type that can
19
+ * accommodate all the input types. The resulting type is usually a supertype
20
+ * that encompasses the possible values of the input types
21
+ *
22
+ * Examples:
23
+ * widen('integer', 'rational') => 'rational'
24
+ * widen('number', 'complex') => 'complex'
25
+ * widen('number', 'collection') => 'collection'
26
+ * widen('number', 'value') => 'value'
27
+ * widen('number', 'expression') => 'expression'
28
+ * widen('number', 'string') => 'any'
29
+ */
30
+ export declare function widen(...types: Readonly<Type>[]): Readonly<Type>;
31
+ export declare function isSignatureType(type: Readonly<Type> | TypeString): type is FunctionSignature;
32
+ export declare function functionSignature(type: Readonly<Type>): Type | undefined;
33
+ export declare function functionResult(type: Readonly<Type> | undefined): Type | undefined;
34
+ export declare function collectionElementType(type: Readonly<Type>): Type | undefined;
35
+ export declare function isValidTypeName(name: string): boolean;
36
+ export declare function isValidType(t: any): t is Readonly<Type>;
@@ -0,0 +1,23 @@
1
+ /* 0.32.1 */
2
+ *
3
+ * <!--
4
+ * !@consider?
5
+ * - In terms of BoxedExpressions - optimizations which are always desirable to take place are
6
+ * possible...
7
+ * ^Perhaps then, a wrapper BoxedExpr. utility for specifying these permutations via 'condition'
8
+ * would be apt...?
9
+ *
10
+ * - ^If wishing to take adv. of this, the 'condition' callback would likely benefit from a second parameter typed as a collection
11
+ * ('Set' if enforcing unique) with all hitherto (arbitrary representations) of generated
12
+ * permutations.
13
+ * (See commented snippets within function signature below.)
14
+ * -->
15
+ *
16
+ * @export
17
+ * @template T
18
+ * @param xs
19
+ * @param [condition]
20
+ * @returns
21
+ */
22
+ export declare function permutations<T>(xs: ReadonlyArray<T>, condition?: (xs: ReadonlyArray<T>) => boolean): ReadonlyArray<ReadonlyArray<T>>;
23
+ export declare function hidePrivateProperties(obj: any): void;
@@ -0,0 +1,26 @@
1
+ /* 0.32.1 */
2
+ /**
3
+ * Add an assumption, in the form of a predicate, for example:
4
+ *
5
+ * - `x = 5`
6
+ * - `x ∈ ℕ`
7
+ * - `x > 3`
8
+ * - `x + y = 5`
9
+ *
10
+ * Assumptions that represent a value definition (equality to an expression,
11
+ * membership to a type, >0, <=0, etc...) are stored directly in the current
12
+ * scope's symbols dictionary, and an entry for the symbol is created if
13
+ * necessary.
14
+ *
15
+ * Predicates that involve multiple symbols are simplified (for example
16
+ * `x + y = 5` becomes `x + y - 5 = 0`), then stored in the `assumptions`
17
+ * record of the current context.
18
+ *
19
+ * New assumptions can 'refine' previous assumptions, if they don't contradict
20
+ * previous assumptions.
21
+ *
22
+ * To set new assumptions that contradict previous ones, you must first
23
+ * `forget` about any symbols in the new assumption.
24
+ *
25
+ */
26
+ export declare function assume(proposition: BoxedExpression): AssumeResult;
@@ -0,0 +1,165 @@
1
+ /* 0.32.1 */
2
+ import type { Expression, MathJsonSymbol } from '../../math-json/types';
3
+ import type { Type, TypeString } from '../../common/type/types';
4
+ import { BoxedType } from '../../common/type/boxed-type';
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
+ import type { NumericValue } from '../numeric-value/types';
7
+ import type { SmallInteger } from '../numerics/types';
8
+ import type { LatexString, SerializeLatexOptions } from '../latex-syntax/types';
9
+ /**
10
+ * _BoxedExpression
11
+ *
12
+ * @internal
13
+ */
14
+ export declare abstract class _BoxedExpression implements BoxedExpression {
15
+ abstract readonly hash: number;
16
+ abstract readonly json: Expression;
17
+ abstract isCanonical: boolean;
18
+ abstract match(pattern: BoxedExpression, options?: PatternMatchOptions): BoxedSubstitution | null;
19
+ readonly engine: ComputeEngine;
20
+ /** Verbatim LaTeX, obtained from a source, i.e. from parsing,
21
+ * not generated synthetically
22
+ */
23
+ readonly verbatimLatex?: string;
24
+ constructor(ce: ComputeEngine, metadata?: Metadata);
25
+ /**
26
+ *
27
+ * `Object.valueOf()`: return a JavaScript primitive value for the expression
28
+ *
29
+ * Primitive values are: boolean, number, bigint, string, null, undefined
30
+ *
31
+ */
32
+ valueOf(): number | number[] | number[][] | number[][][] | string | boolean;
33
+ [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
34
+ /** Object.toString() */
35
+ toString(): string;
36
+ toLatex(options?: Partial<SerializeLatexOptions>): LatexString;
37
+ get latex(): LatexString;
38
+ /** Called by `JSON.stringify()` when serializing to json.
39
+ *
40
+ * Note: this is a standard method of JavaScript objects.
41
+ *
42
+ */
43
+ toJSON(): Expression;
44
+ toMathJson(options?: Readonly<Partial<JsonSerializationOptions>>): Expression;
45
+ print(): void;
46
+ get isStructural(): boolean;
47
+ get canonical(): BoxedExpression;
48
+ get structural(): BoxedExpression;
49
+ get isValid(): boolean;
50
+ get isPure(): boolean;
51
+ get isConstant(): boolean;
52
+ get isNumberLiteral(): boolean;
53
+ get numericValue(): number | NumericValue | null;
54
+ toNumericValue(): [NumericValue, BoxedExpression];
55
+ get isEven(): boolean | undefined;
56
+ get isOdd(): boolean | undefined;
57
+ get re(): number;
58
+ get im(): number;
59
+ get bignumRe(): Decimal | undefined;
60
+ get bignumIm(): Decimal | undefined;
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;
66
+ neg(): BoxedExpression;
67
+ inv(): BoxedExpression;
68
+ abs(): BoxedExpression;
69
+ add(rhs: number | BoxedExpression): BoxedExpression;
70
+ sub(rhs: BoxedExpression): BoxedExpression;
71
+ mul(rhs: NumericValue | number | BoxedExpression): BoxedExpression;
72
+ div(rhs: number | BoxedExpression): BoxedExpression;
73
+ pow(exp: number | BoxedExpression): BoxedExpression;
74
+ root(exp: number | BoxedExpression): BoxedExpression;
75
+ sqrt(): BoxedExpression;
76
+ ln(base?: number | BoxedExpression): BoxedExpression;
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;
107
+ get shape(): number[];
108
+ get rank(): number;
109
+ subs(_sub: Substitution, options?: {
110
+ canonical?: CanonicalOptions;
111
+ }): BoxedExpression;
112
+ map(fn: (x: BoxedExpression) => BoxedExpression, options?: {
113
+ canonical: CanonicalOptions;
114
+ recursive?: boolean;
115
+ }): BoxedExpression;
116
+ solve(_vars?: Iterable<string> | string | BoxedExpression | Iterable<BoxedExpression>): null | ReadonlyArray<BoxedExpression>;
117
+ replace(_rules: BoxedRuleSet | Rule | Rule[]): null | BoxedExpression;
118
+ has(_v: string | string[]): boolean;
119
+ get description(): string[] | undefined;
120
+ get url(): string | undefined;
121
+ get wikidata(): string | undefined;
122
+ get complexity(): number | undefined;
123
+ get baseDefinition(): BoxedBaseDefinition | undefined;
124
+ get valueDefinition(): BoxedValueDefinition | undefined;
125
+ get operatorDefinition(): BoxedOperatorDefinition | undefined;
126
+ infer(t: Type, inferenceMode?: 'narrow' | 'widen'): boolean;
127
+ bind(): void;
128
+ reset(): void;
129
+ get value(): BoxedExpression | undefined;
130
+ set value(_value: any);
131
+ get type(): BoxedType;
132
+ set type(_type: Type | TypeString | BoxedType);
133
+ get isNumber(): boolean | undefined;
134
+ get isInteger(): boolean | undefined;
135
+ get isRational(): boolean | undefined;
136
+ get isReal(): boolean | undefined;
137
+ simplify(_options?: Partial<SimplifyOptions>): BoxedExpression;
138
+ expand(): BoxedExpression;
139
+ evaluate(_options?: Partial<EvaluateOptions>): BoxedExpression;
140
+ evaluateAsync(_options?: Partial<EvaluateOptions>): Promise<BoxedExpression>;
141
+ N(): BoxedExpression;
142
+ compile(options?: {
143
+ to?: 'javascript' | 'wgsl' | 'python' | 'webassembly';
144
+ functions?: Record<MathJsonSymbol, string | ((...any: any[]) => any)>;
145
+ vars?: Record<MathJsonSymbol, string>;
146
+ imports?: ((...any: any[]) => any)[];
147
+ preamble?: string;
148
+ fallback?: boolean;
149
+ }): ((...args: any[]) => any) & {
150
+ isCompiled?: boolean;
151
+ };
152
+ get isCollection(): boolean;
153
+ get isIndexedCollection(): boolean;
154
+ get isLazyCollection(): boolean;
155
+ contains(_rhs: BoxedExpression): boolean | undefined;
156
+ subsetOf(_target: BoxedExpression, _strict: boolean): boolean | undefined;
157
+ get count(): number | undefined;
158
+ get isEmptyCollection(): boolean | undefined;
159
+ get isFiniteCollection(): boolean | undefined;
160
+ each(): Generator<BoxedExpression>;
161
+ at(_index: number): BoxedExpression | undefined;
162
+ get(_key: string | BoxedExpression): BoxedExpression | undefined;
163
+ indexWhere(_predicate: (element: BoxedExpression) => boolean): number | undefined;
164
+ }
165
+ export declare function getSubexpressions(expr: BoxedExpression, name: MathJsonSymbol): ReadonlyArray<BoxedExpression>;
@@ -0,0 +1,5 @@
1
+ /* 0.32.1 */
2
+ import { Decimal } from 'decimal.js';
3
+ import type { BoxedExpression } from '../global-types';
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,16 @@
1
+ /* 0.32.1 */
2
+ import { BoxedType } from '../../common/type/boxed-type';
3
+ import type { BoxedExpression, ComputeEngine } from '../global-types';
4
+ /**
5
+ *
6
+ * The canonical form of `Add`:
7
+ * - canonicalize the arguments
8
+ * - remove `0`
9
+ * - capture complex numbers (`a + ib` or `ai + b`)
10
+ * - sort the terms
11
+ *
12
+ */
13
+ export declare function canonicalAdd(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
14
+ export declare function addType(args: ReadonlyArray<BoxedExpression>): Type | BoxedType;
15
+ export declare function add(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
16
+ export declare function addN(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
@@ -0,0 +1,27 @@
1
+ /* 0.32.1 */
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;
13
+ /**
14
+ * The canonical form of `Multiply`:
15
+ * - removes `1` and `-1`
16
+ * - simplifies the signs:
17
+ * - i.e. `-y \times -x` -> `x \times y`
18
+ * - `2 \times -x` -> `-2 \times x`
19
+ * - arguments are sorted
20
+ * - complex numbers promoted (['Multiply', 2, 'ImaginaryUnit'] -> 2i)
21
+ * - Numeric values are promoted (['Multiply', 2, 'Sqrt', 3] -> 2√3)
22
+ *
23
+ * The input ops may not be canonical, the result is canonical.
24
+ */
25
+ export declare function canonicalMultiply(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression;
26
+ export declare function mul(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
27
+ export declare function mulN(...xs: ReadonlyArray<BoxedExpression>): BoxedExpression;
@@ -0,0 +1,38 @@
1
+ /* 0.32.1 */
2
+ import type { Rational } from '../numerics/types';
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
+ */
22
+ export declare function canonicalPower(a: BoxedExpression, b: BoxedExpression): BoxedExpression;
23
+ export declare function canonicalRoot(a: BoxedExpression, b: BoxedExpression | number): BoxedExpression;
24
+ /**
25
+ * The power function.
26
+ *
27
+ * It follows the same conventions as SymPy, which do not always
28
+ * conform to IEEE 754 floating point arithmetic.
29
+ *
30
+ * See https://docs.sympy.org/latest/modules/core.html#sympy.core.power.Pow
31
+ *
32
+ */
33
+ export declare function pow(x: BoxedExpression, exp: number | BoxedExpression, { numericApproximation }: {
34
+ numericApproximation: boolean;
35
+ }): BoxedExpression;
36
+ export declare function root(a: BoxedExpression, b: BoxedExpression, { numericApproximation }: {
37
+ numericApproximation: boolean;
38
+ }): BoxedExpression;
@@ -0,0 +1,11 @@
1
+ /* 0.32.1 */
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;