@cortex-js/compute-engine 0.35.6 → 0.50.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 (223) hide show
  1. package/README.md +121 -5
  2. package/dist/compute-engine.esm.js +55594 -51135
  3. package/dist/compute-engine.min.esm.js +1081 -78
  4. package/dist/compute-engine.min.umd.js +1081 -78
  5. package/dist/compute-engine.umd.js +53638 -49162
  6. package/dist/math-json.esm.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.umd.js +2 -2
  9. package/dist/math-json.umd.js +2 -2
  10. package/dist/types/common/ansi-codes.d.ts +1 -1
  11. package/dist/types/common/configuration-change.d.ts +1 -1
  12. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  13. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  14. package/dist/types/common/interruptible.d.ts +1 -1
  15. package/dist/types/common/one-of.d.ts +1 -1
  16. package/dist/types/common/signals.d.ts +1 -1
  17. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  18. package/dist/types/common/type/boxed-type.d.ts +1 -1
  19. package/dist/types/common/type/lexer.d.ts +1 -1
  20. package/dist/types/common/type/parse.d.ts +1 -1
  21. package/dist/types/common/type/parser.d.ts +8 -1
  22. package/dist/types/common/type/primitive.d.ts +2 -1
  23. package/dist/types/common/type/reduce.d.ts +1 -1
  24. package/dist/types/common/type/serialize.d.ts +1 -1
  25. package/dist/types/common/type/subtype.d.ts +1 -1
  26. package/dist/types/common/type/type-builder.d.ts +1 -1
  27. package/dist/types/common/type/types.d.ts +1 -1
  28. package/dist/types/common/type/utils.d.ts +3 -2
  29. package/dist/types/common/utils.d.ts +1 -1
  30. package/dist/types/compute-engine/assume.d.ts +4 -22
  31. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +66 -76
  32. package/dist/types/compute-engine/boxed-expression/apply.d.ts +4 -4
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -6
  34. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +72 -6
  35. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +8 -8
  36. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +5 -8
  37. package/dist/types/compute-engine/boxed-expression/box.d.ts +63 -8
  38. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +13 -12
  39. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +44 -43
  40. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +31 -30
  41. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +18 -18
  42. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +5 -37
  43. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +5 -4
  44. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +34 -33
  45. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +34 -33
  46. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +8 -8
  47. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +2 -2
  49. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -2
  50. package/dist/types/compute-engine/boxed-expression/compare.d.ts +7 -4
  51. package/dist/types/compute-engine/boxed-expression/constants.d.ts +6 -0
  52. package/dist/types/compute-engine/boxed-expression/expand.d.ts +4 -5
  53. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +9 -9
  54. package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -7
  55. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +4 -13
  56. package/dist/types/compute-engine/boxed-expression/hold.d.ts +3 -3
  57. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +21 -0
  58. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -0
  59. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +4 -0
  60. package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -2
  61. package/dist/types/compute-engine/boxed-expression/negate.d.ts +4 -4
  62. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +8 -8
  63. package/dist/types/compute-engine/boxed-expression/order.d.ts +14 -14
  64. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +41 -0
  65. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +18 -0
  66. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +12 -35
  67. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +2 -0
  68. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -66
  69. package/dist/types/compute-engine/boxed-expression/rules.d.ts +51 -51
  70. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +6 -3
  71. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +2 -2
  72. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +2 -2
  73. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +8 -8
  74. package/dist/types/compute-engine/boxed-expression/solve.d.ts +3 -11
  75. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +7 -7
  76. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +31 -0
  77. package/dist/types/compute-engine/boxed-expression/utils.d.ts +13 -13
  78. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -10
  79. package/dist/types/compute-engine/collection-utils.d.ts +4 -4
  80. package/dist/types/compute-engine/compilation/base-compiler.d.ts +3 -3
  81. package/dist/types/compute-engine/compilation/compile-expression.d.ts +25 -0
  82. package/dist/types/compute-engine/compilation/glsl-target.d.ts +12 -41
  83. package/dist/types/compute-engine/compilation/gpu-target.d.ts +50 -0
  84. package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +11 -11
  85. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +7 -7
  86. package/dist/types/compute-engine/compilation/interval-wgsl-target.d.ts +54 -0
  87. package/dist/types/compute-engine/compilation/javascript-target.d.ts +6 -6
  88. package/dist/types/compute-engine/compilation/python-target.d.ts +61 -0
  89. package/dist/types/compute-engine/compilation/types.d.ts +38 -22
  90. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +41 -0
  91. package/dist/types/compute-engine/cost-function.d.ts +3 -3
  92. package/dist/types/compute-engine/engine-assumptions.d.ts +6 -0
  93. package/dist/types/compute-engine/engine-cache.d.ts +6 -0
  94. package/dist/types/compute-engine/engine-common-symbols.d.ts +6 -0
  95. package/dist/types/compute-engine/engine-compilation-targets.d.ts +17 -0
  96. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +15 -0
  97. package/dist/types/compute-engine/engine-declarations.d.ts +19 -0
  98. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +44 -0
  99. package/dist/types/compute-engine/engine-extension-contracts.d.ts +9 -0
  100. package/dist/types/compute-engine/engine-latex-dictionary-state.d.ts +13 -0
  101. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +6 -0
  102. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +34 -0
  103. package/dist/types/compute-engine/engine-parse-entrypoint.d.ts +7 -0
  104. package/dist/types/compute-engine/engine-runtime-state.d.ts +19 -0
  105. package/dist/types/compute-engine/engine-scope.d.ts +13 -0
  106. package/dist/types/compute-engine/engine-sequences.d.ts +14 -0
  107. package/dist/types/compute-engine/engine-simplification-rules.d.ts +15 -0
  108. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +28 -0
  109. package/dist/types/compute-engine/engine-type-resolver.d.ts +12 -0
  110. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +13 -0
  111. package/dist/types/compute-engine/free-functions.d.ts +20 -0
  112. package/dist/types/compute-engine/function-utils.d.ts +10 -10
  113. package/dist/types/compute-engine/global-types.d.ts +5 -3301
  114. package/dist/types/compute-engine/index.d.ts +156 -112
  115. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  116. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  117. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  118. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  119. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  120. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  121. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  122. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  123. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  124. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  125. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  126. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  127. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  128. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  129. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  130. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  131. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  132. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  133. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  134. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  135. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +4 -80
  136. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +83 -0
  137. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +28 -0
  138. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +2 -2
  139. package/dist/types/compute-engine/latex-syntax/parse.d.ts +23 -33
  140. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
  141. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +8 -8
  142. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +15 -15
  143. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  144. package/dist/types/compute-engine/latex-syntax/types.d.ts +73 -53
  145. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  146. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -2
  147. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  148. package/dist/types/compute-engine/library/collections.d.ts +4 -4
  149. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  150. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  151. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  152. package/dist/types/compute-engine/library/core.d.ts +1 -1
  153. package/dist/types/compute-engine/library/library.d.ts +19 -6
  154. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  155. package/dist/types/compute-engine/library/logic-analysis.d.ts +19 -32
  156. package/dist/types/compute-engine/library/logic.d.ts +1 -5
  157. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  158. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  159. package/dist/types/compute-engine/library/random-expression.d.ts +2 -2
  160. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  161. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  162. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  163. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  164. package/dist/types/compute-engine/library/type-handlers.d.ts +4 -0
  165. package/dist/types/compute-engine/library/utils.d.ts +12 -12
  166. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +5 -5
  167. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +5 -5
  168. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +5 -5
  169. package/dist/types/compute-engine/numeric-value/types.d.ts +2 -3
  170. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  171. package/dist/types/compute-engine/numerics/expression.d.ts +3 -3
  172. package/dist/types/compute-engine/numerics/interval.d.ts +2 -2
  173. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  174. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  175. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  176. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  177. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  178. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  179. package/dist/types/compute-engine/numerics/rationals.d.ts +4 -4
  180. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  181. package/dist/types/compute-engine/numerics/special-functions.d.ts +120 -1
  182. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -2
  183. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  184. package/dist/types/compute-engine/numerics/types.d.ts +3 -1
  185. package/dist/types/compute-engine/oeis.d.ts +3 -3
  186. package/dist/types/compute-engine/sequence.d.ts +13 -13
  187. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +2 -2
  188. package/dist/types/compute-engine/symbolic/derivative.d.ts +3 -3
  189. package/dist/types/compute-engine/symbolic/distribute.d.ts +2 -2
  190. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +6 -6
  191. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +46 -46
  192. package/dist/types/compute-engine/symbolic/fu.d.ts +4 -4
  193. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +54 -0
  194. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +4 -4
  195. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +2 -2
  196. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +2 -2
  197. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +2 -2
  198. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +2 -2
  199. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +5 -0
  200. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +2 -2
  201. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +2 -2
  202. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +65 -4
  203. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +2 -2
  204. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +2 -2
  205. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +42 -42
  206. package/dist/types/compute-engine/tensor/tensors.d.ts +4 -4
  207. package/dist/types/compute-engine/types-definitions.d.ts +900 -0
  208. package/dist/types/compute-engine/types-engine.d.ts +375 -0
  209. package/dist/types/compute-engine/types-evaluation.d.ts +67 -0
  210. package/dist/types/compute-engine/types-expression.d.ts +1655 -0
  211. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +164 -0
  212. package/dist/types/compute-engine/types-kernel-serialization.d.ts +147 -0
  213. package/dist/types/compute-engine/types-serialization.d.ts +23 -0
  214. package/dist/types/compute-engine/types.d.ts +2 -2
  215. package/dist/types/compute-engine.d.ts +16 -3
  216. package/dist/types/math-json/symbols.d.ts +1 -1
  217. package/dist/types/math-json/types.d.ts +3 -3
  218. package/dist/types/math-json/utils.d.ts +31 -31
  219. package/dist/types/math-json.d.ts +2 -2
  220. package/package.json +8 -1
  221. package/dist/types/compute-engine/boxed-expression/terms.d.ts +0 -10
  222. package/dist/types/compute-engine/library/invisible-operator.d.ts +0 -4
  223. package/dist/types/compute-engine/library/logic-utils.d.ts +0 -54
@@ -0,0 +1,900 @@
1
+ /* 0.50.1 */
2
+ import type { Type, TypeString } from '../common/type/types';
3
+ import type { BoxedType } from '../common/type/boxed-type';
4
+ import type { LatexString, LatexDictionaryEntry } from './latex-syntax/types';
5
+ import type { Expression, ExpressionInput, CompiledExpression } from './types-expression';
6
+ import type { EvaluateOptions as KernelEvaluateOptions, Rule as KernelRule, BoxedRule as KernelBoxedRule, BoxedRuleSet as KernelBoxedRuleSet, Scope as KernelScope } from './types-kernel-evaluation';
7
+ /**
8
+ * Compute engine surface used by definition callbacks.
9
+ *
10
+ * This interface is augmented by `types-engine.ts` with the concrete
11
+ * `IComputeEngine` members to avoid type-layer circular dependencies.
12
+ *
13
+ * @category Compute Engine
14
+ */
15
+ export interface ComputeEngine {
16
+ }
17
+ type EvaluateOptions = KernelEvaluateOptions<Expression>;
18
+ type Rule = KernelRule<Expression, ExpressionInput, ComputeEngine>;
19
+ type BoxedRule = KernelBoxedRule<Expression, ComputeEngine>;
20
+ type BoxedRuleSet = KernelBoxedRuleSet<Expression, ComputeEngine>;
21
+ type Scope = KernelScope<BoxedDefinition>;
22
+ /**
23
+ * A bound symbol (i.e. one with an associated definition) has either a type
24
+ * (e.g. ∀ x ∈ ℝ), a value (x = 5) or both (π: value = 3.14... type = 'real').
25
+ *
26
+ * @category Definitions
27
+ */
28
+ export type ValueDefinition = BaseDefinition & {
29
+ holdUntil: 'never' | 'evaluate' | 'N';
30
+ type: Type | TypeString | BoxedType;
31
+ /** If true, the type is inferred, and could be adjusted later
32
+ * as more information becomes available or if the symbol is explicitly
33
+ * declared.
34
+ */
35
+ inferred: boolean;
36
+ /** `value` can be a JS function since for some constants, such as
37
+ * `Pi`, the actual value depends on the `precision` setting of the
38
+ * `ComputeEngine` and possible other environment settings */
39
+ value: LatexString | ExpressionInput | ((ce: ComputeEngine) => Expression | null);
40
+ eq: (a: Expression) => boolean | undefined;
41
+ neq: (a: Expression) => boolean | undefined;
42
+ cmp: (a: Expression) => '=' | '>' | '<' | undefined;
43
+ collection: CollectionHandlers;
44
+ /**
45
+ * Custom evaluation handler for subscripted expressions of this symbol.
46
+ * Called when evaluating `Subscript(symbol, index)`.
47
+ *
48
+ * @param subscript - The subscript expression (already evaluated)
49
+ * @param options - Contains the compute engine and evaluation options
50
+ * @returns The evaluated result, or `undefined` to fall back to symbolic form
51
+ */
52
+ subscriptEvaluate?: (subscript: Expression, options: {
53
+ engine: ComputeEngine;
54
+ numericApproximation?: boolean;
55
+ }) => Expression | undefined;
56
+ };
57
+ /**
58
+ * Definition for a sequence declared with `ce.declareSequence()`.
59
+ *
60
+ * A sequence is defined by base cases and a recurrence relation.
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * // Fibonacci sequence
65
+ * ce.declareSequence('F', {
66
+ * base: { 0: 0, 1: 1 },
67
+ * recurrence: 'F_{n-1} + F_{n-2}',
68
+ * });
69
+ * ce.parse('F_{10}').evaluate(); // → 55
70
+ * ```
71
+ *
72
+ * @category Definitions
73
+ */
74
+ export interface SequenceDefinition {
75
+ /**
76
+ * Index variable name for single-index sequences, default 'n'.
77
+ * For multi-index sequences, use `variables` instead.
78
+ */
79
+ variable?: string;
80
+ /**
81
+ * Index variable names for multi-index sequences.
82
+ * Example: `['n', 'k']` for Pascal's triangle `P\_{n,k}`
83
+ *
84
+ * If provided, this takes precedence over `variable`.
85
+ */
86
+ variables?: string[];
87
+ /**
88
+ * Base cases as index → value mapping.
89
+ *
90
+ * For single-index sequences, use numeric keys:
91
+ * ```typescript
92
+ * base: { 0: 0, 1: 1 } // F_0 = 0, F_1 = 1
93
+ * ```
94
+ *
95
+ * For multi-index sequences, use comma-separated string keys:
96
+ * ```typescript
97
+ * base: {
98
+ * '0,0': 1, // Exact: P_{0,0} = 1
99
+ * 'n,0': 1, // Pattern: P_{n,0} = 1 for all n
100
+ * 'n,n': 1, // Pattern: P_{n,n} = 1 (diagonal)
101
+ * }
102
+ * ```
103
+ *
104
+ * Pattern keys use variable names to match any value. When the same
105
+ * variable appears multiple times (e.g., 'n,n'), the indices must be equal.
106
+ */
107
+ base: Record<number | string, number | Expression>;
108
+ /** Recurrence relation as LaTeX string or Expression */
109
+ recurrence: string | Expression;
110
+ /** Whether to memoize computed values (default: true) */
111
+ memoize?: boolean;
112
+ /**
113
+ * Valid index domain constraints.
114
+ *
115
+ * For single-index sequences:
116
+ * ```typescript
117
+ * domain: { min: 0, max: 100 }
118
+ * ```
119
+ *
120
+ * For multi-index sequences, use per-variable constraints:
121
+ * ```typescript
122
+ * domain: { n: { min: 0 }, k: { min: 0 } }
123
+ * ```
124
+ */
125
+ domain?: {
126
+ min?: number;
127
+ max?: number;
128
+ } | Record<string, {
129
+ min?: number;
130
+ max?: number;
131
+ }>;
132
+ /**
133
+ * Constraint expression for multi-index sequences.
134
+ * The expression should evaluate to a boolean/numeric value.
135
+ * If it evaluates to false or 0, the subscript is considered out of domain.
136
+ *
137
+ * Example: `'k <= n'` for Pascal's triangle (only valid when k ≤ n)
138
+ */
139
+ constraints?: string | Expression;
140
+ }
141
+ /**
142
+ * Status of a sequence definition.
143
+ * @category Definitions
144
+ */
145
+ export interface SequenceStatus {
146
+ /**
147
+ * Status of the sequence:
148
+ * - 'complete': Both base case(s) and recurrence defined
149
+ * - 'pending': Waiting for base case(s) or recurrence
150
+ * - 'not-a-sequence': Symbol is not a sequence
151
+ */
152
+ status: 'complete' | 'pending' | 'not-a-sequence';
153
+ /** Whether at least one base case is defined */
154
+ hasBase: boolean;
155
+ /** Whether a recurrence relation is defined */
156
+ hasRecurrence: boolean;
157
+ /**
158
+ * Keys of defined base cases.
159
+ * For single-index: numeric indices (e.g., [0, 1])
160
+ * For multi-index: string keys including patterns (e.g., ['0,0', 'n,0', 'n,n'])
161
+ */
162
+ baseIndices: (number | string)[];
163
+ /** Index variable name if recurrence is defined (single-index) */
164
+ variable?: string;
165
+ /** Index variable names if recurrence is defined (multi-index) */
166
+ variables?: string[];
167
+ }
168
+ /**
169
+ * Information about a defined sequence for introspection.
170
+ * @category Definitions
171
+ */
172
+ export interface SequenceInfo {
173
+ /** The sequence name */
174
+ name: string;
175
+ /** Index variable name for single-index sequences (e.g., `"n"`) */
176
+ variable?: string;
177
+ /** Index variable names for multi-index sequences (e.g., `["n", "k"]`) */
178
+ variables?: string[];
179
+ /**
180
+ * Base case keys.
181
+ * For single-index: numeric indices
182
+ * For multi-index: string keys including patterns
183
+ */
184
+ baseIndices: (number | string)[];
185
+ /** Whether memoization is enabled */
186
+ memoize: boolean;
187
+ /**
188
+ * Domain constraints.
189
+ * For single-index: `{ min?, max? }`
190
+ * For multi-index: per-variable constraints
191
+ */
192
+ domain: {
193
+ min?: number;
194
+ max?: number;
195
+ } | Record<string, {
196
+ min?: number;
197
+ max?: number;
198
+ }>;
199
+ /** Number of cached values */
200
+ cacheSize: number;
201
+ /** Whether this is a multi-index sequence */
202
+ isMultiIndex: boolean;
203
+ }
204
+ /**
205
+ * Result from an OEIS lookup operation.
206
+ * @category OEIS
207
+ */
208
+ export interface OEISSequenceInfo {
209
+ /** OEIS sequence ID (e.g., 'A000045') */
210
+ id: string;
211
+ /** Sequence name/description */
212
+ name: string;
213
+ /** First several terms of the sequence */
214
+ terms: number[];
215
+ /** Formula or recurrence (if available) */
216
+ formula?: string;
217
+ /** Comments about the sequence */
218
+ comments?: string[];
219
+ /** URL to the OEIS page */
220
+ url: string;
221
+ }
222
+ /**
223
+ * Options for OEIS operations.
224
+ * @category OEIS
225
+ */
226
+ export interface OEISOptions {
227
+ /** Request timeout in milliseconds (default: 10000) */
228
+ timeout?: number;
229
+ /** Maximum number of results to return for lookups (default: 5) */
230
+ maxResults?: number;
231
+ }
232
+ /**
233
+ * Definition record for a function.
234
+ * @category Definitions
235
+ *
236
+ */
237
+ export type OperatorDefinition = Partial<BaseDefinition> & Partial<OperatorDefinitionFlags> & {
238
+ /**
239
+ * The function signature, describing the type of the arguments and the
240
+ * return type.
241
+ *
242
+ * If a `type` handler is provided, the return type of the function should
243
+ * be a subtype of the return type in the signature.
244
+ *
245
+ */
246
+ signature?: Type | TypeString | BoxedType;
247
+ /**
248
+ * The type of the result (return type) based on the type of
249
+ * the arguments.
250
+ *
251
+ * Should be a subtype of the type indicated by the signature.
252
+ *
253
+ * For example, if the signature is `(number) -> real`, the type of the
254
+ * result could be `real` or `integer`, but not `complex`.
255
+ *
256
+ * :::info[Note]
257
+ * Do not evaluate the arguments.
258
+ *
259
+ * However, the type of the arguments can be used to determine the type of
260
+ * the result.
261
+ * :::
262
+ *
263
+ */
264
+ type?: (ops: ReadonlyArray<Expression>, options: {
265
+ engine: ComputeEngine;
266
+ }) => Type | TypeString | BoxedType | undefined;
267
+ /** Return the sign of the function expression.
268
+ *
269
+ * If the sign cannot be determined, return `undefined`.
270
+ *
271
+ * When determining the sign, only literal values and the values of
272
+ * symbols, if they are literals, should be considered.
273
+ *
274
+ * Do not evaluate the arguments.
275
+ *
276
+ * However, the type and sign of the arguments can be used to determine the
277
+ * sign.
278
+ *
279
+ */
280
+ sgn?: (ops: ReadonlyArray<Expression>, options: {
281
+ engine: ComputeEngine;
282
+ }) => Sign | undefined;
283
+ /** The value of this expression is > 0, same as `isGreater(0)`
284
+ *
285
+ * @category Numeric Expression
286
+ */
287
+ readonly isPositive?: boolean | undefined;
288
+ /** The value of this expression is >= 0, same as `isGreaterEqual(0)`
289
+ *
290
+ * @category Numeric Expression
291
+ */
292
+ readonly isNonNegative?: boolean | undefined;
293
+ /** The value of this expression is &lt; 0, same as `isLess(0)`
294
+ *
295
+ * @category Numeric Expression
296
+ */
297
+ readonly isNegative?: boolean | undefined;
298
+ /** The value of this expression is &lt;= 0, same as `isLessEqual(0)`
299
+ *
300
+ * @category Numeric Expression
301
+ */
302
+ readonly isNonPositive?: boolean | undefined;
303
+ /** Return `true` if the function expression is even, `false` if it is odd
304
+ * and `undefined` if it is neither (for example if it is not a number,
305
+ * or if it is a complex number).
306
+ */
307
+ even?: (ops: ReadonlyArray<Expression>, options: {
308
+ engine: ComputeEngine;
309
+ }) => boolean | undefined;
310
+ /**
311
+ * A number used to order arguments.
312
+ *
313
+ * Argument with higher complexity are placed after arguments with
314
+ * lower complexity when ordered canonically in commutative functions.
315
+ *
316
+ * - Additive functions: 1000-1999
317
+ * - Multiplicative functions: 2000-2999
318
+ * - Root and power functions: 3000-3999
319
+ * - Log functions: 4000-4999
320
+ * - Trigonometric functions: 5000-5999
321
+ * - Hypertrigonometric functions: 6000-6999
322
+ * - Special functions (factorial, Gamma, ...): 7000-7999
323
+ * - Collections: 8000-8999
324
+ * - Inert and styling: 9000-9999
325
+ * - Logic: 10000-10999
326
+ * - Relational: 11000-11999
327
+ *
328
+ * **Default**: 100,000
329
+ */
330
+ complexity?: number;
331
+ /**
332
+ * Return the canonical form of the expression with the arguments `args`.
333
+ *
334
+ * The arguments (`args`) may not be in canonical form. If necessary, they
335
+ * can be put in canonical form.
336
+ *
337
+ * This handler should validate the type and number of the arguments
338
+ * (arity).
339
+ *
340
+ * If a required argument is missing, it should be indicated with a
341
+ * `["Error", "'missing"]` expression. If more arguments than expected
342
+ * are present, this should be indicated with an
343
+ * `["Error", "'unexpected-argument'"]` error expression
344
+ *
345
+ * If the type of an argument is not compatible, it should be indicated
346
+ * with an `incompatible-type` error.
347
+ *
348
+ * `["Sequence"]` expressions are not folded and need to be handled
349
+ * explicitly.
350
+ *
351
+ * If the function is associative, idempotent or an involution,
352
+ * this handler should account for it. Notably, if it is commutative, the
353
+ * arguments should be sorted in canonical order.
354
+ *
355
+ *
356
+ * Values of symbols should not be substituted, unless they have
357
+ * a `holdUntil` attribute of `"never"`.
358
+ *
359
+ * The handler should not consider the value or any assumptions about any
360
+ * of the arguments that are symbols or functions (i.e. `arg.isZero`,
361
+ * `arg.isInteger`, etc...) since those may change over time.
362
+ *
363
+ * The result of the handler should be a canonical expression.
364
+ *
365
+ * If the arguments do not match, they should be replaced with an
366
+ * appropriate `["Error"]` expression. If the expression cannot be put in
367
+ * canonical form, the handler should return `null`.
368
+ *
369
+ */
370
+ canonical?: (ops: ReadonlyArray<Expression>, options: {
371
+ engine: ComputeEngine;
372
+ scope: Scope | undefined;
373
+ }) => Expression | null;
374
+ /**
375
+ * Evaluate a function expression.
376
+ *
377
+ * When the handler is invoked, the arguments have been evaluated, except
378
+ * if the `lazy` option is set to `true`.
379
+ *
380
+ * It is not necessary to further simplify or evaluate the arguments.
381
+ *
382
+ * If performing numerical calculations and `options.numericalApproximation`
383
+ * is `false` return an exact numeric value, for example return a rational
384
+ * number or a square root, rather than a floating point approximation.
385
+ * Use `ce.number()` to create the numeric value.
386
+ *
387
+ * If the expression cannot be evaluated, due to the values, types, or
388
+ * assumptions about its arguments, return `undefined` or
389
+ * an `["Error"]` expression.
390
+ */
391
+ evaluate?: ((ops: ReadonlyArray<Expression>, options: EvaluateOptions & {
392
+ engine: ComputeEngine;
393
+ }) => Expression | undefined) | Expression;
394
+ /**
395
+ * An asynchronous version of `evaluate`.
396
+ *
397
+ */
398
+ evaluateAsync?: (ops: ReadonlyArray<Expression>, options: EvaluateOptions & {
399
+ engine: ComputeEngine;
400
+ }) => Promise<Expression | undefined>;
401
+ /** Dimensional analysis
402
+ * @experimental
403
+ */
404
+ evalDimension?: (args: ReadonlyArray<Expression>, options: EvaluateOptions & {
405
+ engine: ComputeEngine;
406
+ }) => Expression;
407
+ /** Return a compiled (optimized) expression. */
408
+ xcompile?: (expr: Expression) => CompiledExpression;
409
+ eq?: (a: Expression, b: Expression) => boolean | undefined;
410
+ neq?: (a: Expression, b: Expression) => boolean | undefined;
411
+ collection?: CollectionHandlers;
412
+ };
413
+ /**
414
+ * Metadata common to both symbols and functions.
415
+ *
416
+ * @category Definitions
417
+ *
418
+ */
419
+ export interface BaseDefinition {
420
+ /**
421
+ * If a string, a short description, about one line long.
422
+ *
423
+ * Otherwise, a list of strings, each string a paragraph.
424
+ *
425
+ * May contain Markdown.
426
+ */
427
+ description: string | string[];
428
+ /** A list of examples of how to use this symbol or operator.
429
+ *
430
+ * Each example is a string, which can be a MathJSON expression or LaTeX, bracketed by `$` signs.
431
+ * For example, `["Add", 1, 2]` or `$\\sin(\\pi/4)$`.
432
+ */
433
+ examples: string | string[];
434
+ /** A URL pointing to more information about this symbol or operator. */
435
+ url: string;
436
+ /**
437
+ * A short string representing an entry in a wikibase.
438
+ *
439
+ * For example `"Q167"` is the [wikidata entry](https://www.wikidata.org/wiki/Q167)
440
+ * for the `Pi` constant.
441
+ */
442
+ wikidata: string;
443
+ /** If true, the value or type of the definition cannot be changed */
444
+ readonly isConstant?: boolean;
445
+ }
446
+ /** Options for `Expression.simplify()`
447
+ *
448
+ * @category Boxed Expression
449
+ */
450
+ export type SimplifyOptions = {
451
+ /**
452
+ * The set of rules to apply. If `null`, use no rules. If not provided,
453
+ * use the default simplification rules.
454
+ */
455
+ rules?: null | Rule | ReadonlyArray<BoxedRule | Rule> | BoxedRuleSet;
456
+ /**
457
+ * Use this cost function to determine if a simplification is worth it.
458
+ *
459
+ * If not provided, `ce.costFunction`, the cost function of the engine is
460
+ * used.
461
+ */
462
+ costFunction?: (expr: Expression) => number;
463
+ /**
464
+ * The simplification strategy to use.
465
+ *
466
+ * - `'default'`: Use standard simplification rules (default)
467
+ * - `'fu'`: Use the Fu algorithm for trigonometric simplification.
468
+ * This is more aggressive for trig expressions and may produce
469
+ * different results than the default strategy.
470
+ *
471
+ * **Note:** When using the `'fu'` strategy, the `costFunction` and `rules`
472
+ * options are ignored. The Fu algorithm uses its own specialized cost
473
+ * function that prioritizes minimizing the number of trigonometric
474
+ * functions. Standard simplification is applied before and after the
475
+ * Fu transformations using the engine's default rules.
476
+ */
477
+ strategy?: 'default' | 'fu';
478
+ };
479
+ /**
480
+ * A table mapping symbols to their definition.
481
+ *
482
+ * Symbols should be valid MathJSON symbols. In addition, the
483
+ * following rules are recommended:
484
+ *
485
+ * - Use only latin letters, digits and `-`: `/[a-zA-Z0-9-]+/`
486
+ * - The first character should be a letter: `/^[a-zA-Z]/`
487
+ * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
488
+ *
489
+ * @category Definitions
490
+ *
491
+ */
492
+ export type SymbolDefinition = OneOf<[ValueDefinition, OperatorDefinition]>;
493
+ /**
494
+ * @category Definitions
495
+ *
496
+ */
497
+ export type SymbolDefinitions = Readonly<{
498
+ [id: string]: Partial<SymbolDefinition>;
499
+ }>;
500
+ /**
501
+ * A library bundles symbol/operator definitions with their LaTeX dictionary
502
+ * entries and declares dependencies on other libraries.
503
+ *
504
+ * Use with the `libraries` constructor option to load standard or custom
505
+ * libraries:
506
+ *
507
+ * ```ts
508
+ * const ce = new ComputeEngine({
509
+ * libraries: ['core', 'arithmetic', {
510
+ * name: 'custom',
511
+ * requires: ['arithmetic'],
512
+ * definitions: { G: { value: 6.674e-11, type: 'real', isConstant: true } },
513
+ * }],
514
+ * });
515
+ * ```
516
+ *
517
+ * @category Definitions
518
+ */
519
+ export interface LibraryDefinition {
520
+ /** Library identifier */
521
+ name: string;
522
+ /** Libraries that must be loaded before this one */
523
+ requires?: string[];
524
+ /** Symbol and operator definitions */
525
+ definitions?: SymbolDefinitions | SymbolDefinitions[];
526
+ /** LaTeX dictionary entries for parsing/serialization */
527
+ latexDictionary?: Readonly<Partial<LatexDictionaryEntry>[]>;
528
+ }
529
+ /**
530
+ * When a unitless value is passed to or returned from a trigonometric function,
531
+ * the angular unit of the value.
532
+ *
533
+ * | Angular Unit | Description |
534
+ * |:--------------|:-------------|
535
+ * | `rad` | radians, 2π radians is a full circle |
536
+ * | `deg` | degrees, 360 degrees is a full circle |
537
+ * | `grad` | gradians, 400 gradians is a full circle |
538
+ * | `turn` | turns, 1 turn is a full circle |
539
+ *
540
+ * To change the angular unit used by the Compute Engine, use:
541
+ *
542
+ * ```js
543
+ * ce.angularUnit = 'deg';
544
+ * ```
545
+ *
546
+ * @category Compute Engine
547
+ */
548
+ export type AngularUnit = 'rad' | 'deg' | 'grad' | 'turn';
549
+ /** @category Numerics */
550
+ export type Sign =
551
+ /** The expression is equal to 0 */
552
+ 'zero'
553
+ /** The expression is > 0 */
554
+ | 'positive'
555
+ /** The expression is < 0 */
556
+ | 'negative'
557
+ /** The expression is >= 0 and isPositive is either false or undefined*/
558
+ | 'non-negative'
559
+ /** The expression is <= 0 and isNegative is either false or undefined*/
560
+ | 'non-positive'
561
+ /** The expression is not equal to 0 (possibly with an imaginary part) and isPositive, isNegative, isUnsigned are all false or undefined */
562
+ | 'not-zero'
563
+ /** The expression has an imaginary part or is NaN */
564
+ | 'unsigned';
565
+ /**
566
+ * These handlers are the primitive operations that can be performed on
567
+ * all collections, indexed or not.
568
+ *
569
+ * @category Definitions
570
+ */
571
+ export interface BaseCollectionHandlers {
572
+ /**
573
+ * Return an iterator that iterates over the elements of the collection.
574
+ *
575
+ * The order in which the elements are returned is not defined. Requesting
576
+ * two iterators on the same collection may return the elements in a
577
+ * different order.
578
+ *
579
+ * @category Definitions
580
+ */
581
+ iterator: (collection: Expression) => Iterator<Expression, undefined> | undefined;
582
+ /** Return the number of elements in the collection.
583
+ *
584
+ * An empty collection has a count of 0.
585
+ */
586
+ count: (collection: Expression) => number | undefined;
587
+ /** Optional flag to quickly check if the collection is empty, without having to count exactly how may elements it has (useful for lazy evaluation). */
588
+ isEmpty?: (collection: Expression) => boolean | undefined;
589
+ /** Optional flag to quickly check if the collection is finite, without having to count exactly how many elements it has (useful for lazy evaluation). */
590
+ isFinite?: (collection: Expression) => boolean | undefined;
591
+ /** Return `true` if the collection is lazy, `false` otherwise.
592
+ * If the collection is lazy, it means that the elements are not
593
+ * computed until they are needed, for example when iterating over the
594
+ * collection.
595
+ *
596
+ * Default: `true`
597
+ */
598
+ isLazy?: (collection: Expression) => boolean;
599
+ /**
600
+ * Return `true` if the target expression is in the collection,
601
+ * `false` otherwise.
602
+ *
603
+ * Return `undefined` if the membership cannot be determined.
604
+ */
605
+ contains?: (collection: Expression, target: Expression) => boolean | undefined;
606
+ /**
607
+ * Return `true` if all the elements of `other` are in `collection`.
608
+ * Both `collection` and `other` are collections.
609
+ *
610
+ * If strict is `true`, the subset must be strict, that is, `collection` must
611
+ * have more elements than `other`.
612
+ *
613
+ * Return `undefined` if the subset relation cannot be determined.
614
+ */
615
+ subsetOf?: (collection: Expression, other: Expression, strict: boolean) => boolean | undefined;
616
+ /** Return the sign of all the elements of the collection. */
617
+ eltsgn?: (collection: Expression) => Sign | undefined;
618
+ /** Return the widest type of all the elements in the collection */
619
+ elttype?: (collection: Expression) => Type | undefined;
620
+ }
621
+ /**
622
+ * These additional collection handlers are applicable to indexed
623
+ * collections only.
624
+ *
625
+ * The elements of an indexed collection can be accessed by index, and
626
+ * the order of the elements is defined.
627
+ *
628
+ * @category Definitions
629
+ */
630
+ export interface IndexedCollectionHandlers {
631
+ /**
632
+ * Return the element at the specified index.
633
+ *
634
+ * The first element is `at(1)`, the last element is `at(-1)`.
635
+ *
636
+ * If the index is &lt;0, return the element at index `count() + index + 1`.
637
+ *
638
+ * The index can also be a string for example for records. The set of valid
639
+ * keys is returned by the `keys()` handler.
640
+ *
641
+ * If the index is invalid, return `undefined`.
642
+ */
643
+ at: (collection: Expression, index: number | string) => undefined | Expression;
644
+ /**
645
+ * Return the index of the first element that matches the predicate.
646
+ *
647
+ * If no element matches the predicate, return `undefined`.
648
+ */
649
+ indexWhere: (collection: Expression, predicate: (element: Expression) => boolean) => number | undefined;
650
+ }
651
+ /**
652
+ * The collection handlers are the primitive operations that can be
653
+ * performed on collections, such as lists, sets, tuples, etc...
654
+ *
655
+ * @category Definitions
656
+ */
657
+ export type CollectionHandlers = BaseCollectionHandlers & Partial<IndexedCollectionHandlers>;
658
+ /**
659
+ *
660
+ * The definition for a value, represented as a tagged object literal.
661
+ * @category Definitions
662
+ *
663
+ */
664
+ export type TaggedValueDefinition = {
665
+ value: BoxedValueDefinition;
666
+ };
667
+ /**
668
+ *
669
+ * The definition for an operator, represented as a tagged object literal.
670
+ *
671
+ * @category Definitions
672
+ *
673
+ */
674
+ export type TaggedOperatorDefinition = {
675
+ operator: BoxedOperatorDefinition;
676
+ };
677
+ /**
678
+ * A definition can be either a value or an operator.
679
+ *
680
+ * It is collected in a tagged object literal, instead of being a simple union
681
+ * type, so that the type of the definition can be changed while keeping
682
+ * references to the definition in bound expressions.
683
+ *
684
+ * @category Definitions
685
+ *
686
+ */
687
+ export type BoxedDefinition = TaggedValueDefinition | TaggedOperatorDefinition;
688
+ /**
689
+ * @category Definitions
690
+ *
691
+ */
692
+ export interface BoxedBaseDefinition extends Partial<BaseDefinition> {
693
+ /** If this is the definition of a collection, the set of primitive operations
694
+ * that can be performed on this collection (counting the number of elements,
695
+ * enumerating it, etc...).
696
+ */
697
+ collection?: CollectionHandlers;
698
+ }
699
+ /**
700
+ *
701
+ * @category Definitions
702
+ */
703
+ export interface BoxedValueDefinition extends BoxedBaseDefinition {
704
+ /**
705
+ * If the symbol has a value, it is held as indicated in the table below.
706
+ * A green checkmark indicate that the symbol is substituted.
707
+
708
+ <div className="symbols-table">
709
+
710
+ | Operation | `"never"` | `"evaluate"` | `"N"` |
711
+ | :--- | :-----: | :----: | :---: |
712
+ | `canonical()` | (X) | | |
713
+ | `evaluate()` | (X) | (X) | |
714
+ | `"N()"` | (X) | (X) | (X) |
715
+
716
+ </div>
717
+
718
+ * Some examples:
719
+ * - `ImaginaryUnit` has `holdUntil: 'never'`: it is substituted during canonicalization
720
+ * - `x` has `holdUntil: 'evaluate'` (variables)
721
+ * - `Pi` has `holdUntil: 'N'` (special numeric constant)
722
+ *
723
+ * **Default:** `evaluate`
724
+ */
725
+ holdUntil: 'never' | 'evaluate' | 'N';
726
+ /** This is either the initial value of the symbol (i.e. when a new
727
+ * evaluation context is created), or its constant value, if a constant.
728
+ * Otherwise, the current value is tracked in the evaluation context.
729
+ *
730
+ */
731
+ readonly value: Expression | undefined;
732
+ eq?: (a: Expression) => boolean | undefined;
733
+ neq?: (a: Expression) => boolean | undefined;
734
+ cmp?: (a: Expression) => '=' | '>' | '<' | undefined;
735
+ /**
736
+ * True if the type has been inferred. An inferred type can be updated as
737
+ * more information becomes available.
738
+ *
739
+ * A type that is not inferred, but has been set explicitly, cannot be updated.
740
+ */
741
+ inferredType: boolean;
742
+ type: BoxedType;
743
+ /**
744
+ * Custom evaluation handler for subscripted expressions of this symbol.
745
+ * Called when evaluating `Subscript(symbol, index)`.
746
+ */
747
+ subscriptEvaluate?: (subscript: Expression, options: {
748
+ engine: ComputeEngine;
749
+ numericApproximation?: boolean;
750
+ }) => Expression | undefined;
751
+ }
752
+ /**
753
+ * An operator definition can have some flags to indicate specific
754
+ * properties of the operator.
755
+ * @category Definitions
756
+ */
757
+ export type OperatorDefinitionFlags = {
758
+ /**
759
+ * If `true`, the arguments to this operator are not automatically
760
+ * evaluated. The default is `false` (the arguments are evaluated).
761
+ *
762
+ * This can be useful for example for operators that take symbolic
763
+ * expressions as arguments, such as `Declare` or `Integrate`.
764
+ *
765
+ * This is also useful for operators that take an argument that is
766
+ * potentially an infinite collection.
767
+ *
768
+ * It will be up to the `evaluate()` handler to evaluate the arguments as
769
+ * needed. This is convenient to pass symbolic expressions as arguments
770
+ * to operators without having to explicitly use a `Hold` expression.
771
+ *
772
+ * This also applies to the `canonical()` handler.
773
+ *
774
+ */
775
+ lazy: boolean;
776
+ /**
777
+ * If `true`, the operator requires a new lexical scope when canonicalized.
778
+ * This will allow it to declare variables that are not visible outside
779
+ * the function expression using the operator.
780
+ *
781
+ * **Default**: `false`
782
+ */
783
+ scoped: boolean;
784
+ /** If `true`, the operator is applied element by element to lists, matrices
785
+ * (`["List"]` or `["Tuple"]` expressions) and equations (relational
786
+ * operators).
787
+ *
788
+ * **Default**: `false`
789
+ */
790
+ broadcastable: boolean;
791
+ /** If `true`, `["f", ["f", a], b]` simplifies to `["f", a, b]`
792
+ *
793
+ * **Default**: `false`
794
+ */
795
+ associative: boolean;
796
+ /** If `true`, `["f", a, b]` equals `["f", b, a]`. The canonical
797
+ * version of the function will order the arguments.
798
+ *
799
+ * **Default**: `false`
800
+ */
801
+ commutative: boolean;
802
+ /**
803
+ * If `commutative` is `true`, the order of the arguments is determined by
804
+ * this function.
805
+ *
806
+ * If the function is not provided, the arguments are ordered by the
807
+ * default order of the arguments.
808
+ *
809
+ */
810
+ commutativeOrder: ((a: Expression, b: Expression) => number) | undefined;
811
+ /** If `true`, when the operator is univariate, `["f", ["Multiply", x, c]]`
812
+ * simplifies to `["Multiply", ["f", x], c]` where `c` is constant
813
+ *
814
+ * When the operator is multivariate, multiplicativity is considered only on
815
+ * the first argument: `["f", ["Multiply", x, y], z]` simplifies to
816
+ * `["Multiply", ["f", x, z], ["f", y, z]]`
817
+ *
818
+ * Default: `false`
819
+ */
820
+ /** If `true`, `["f", ["f", x]]` simplifies to `["f", x]`.
821
+ *
822
+ * **Default**: `false`
823
+ */
824
+ idempotent: boolean;
825
+ /** If `true`, `["f", ["f", x]]` simplifies to `x`.
826
+ *
827
+ * **Default**: `false`
828
+ */
829
+ involution: boolean;
830
+ /** If `true`, the value of this operator is always the same for a given
831
+ * set of arguments and it has no side effects.
832
+ *
833
+ * An expression using this operator is pure if the operator and all its
834
+ * arguments are pure.
835
+ *
836
+ * For example `Sin` is pure, `Random` isn't.
837
+ *
838
+ * This information may be used to cache the value of expressions.
839
+ *
840
+ * **Default:** `true`
841
+ */
842
+ pure: boolean;
843
+ };
844
+ /**
845
+ *
846
+ * The definition includes information specific about an operator, such as
847
+ * handlers to canonicalize or evaluate a function expression with this
848
+ * operator.
849
+ *
850
+ * @category Definitions
851
+ *
852
+ */
853
+ export interface BoxedOperatorDefinition extends BoxedBaseDefinition, OperatorDefinitionFlags {
854
+ complexity: number;
855
+ /** If true, the signature was inferred from usage and may be modified
856
+ * as more information becomes available.
857
+ */
858
+ inferredSignature: boolean;
859
+ /** The type of the arguments and return value of this function */
860
+ signature: BoxedType;
861
+ /** If present, this handler can be used to more precisely determine the
862
+ * return type based on the type of the arguments. The arguments themselves
863
+ * should *not* be evaluated, only their types should be used.
864
+ */
865
+ type?: (ops: ReadonlyArray<Expression>, options: {
866
+ engine: ComputeEngine;
867
+ }) => Type | TypeString | BoxedType | undefined;
868
+ /** If present, this handler can be used to determine the sign of the
869
+ * return value of the function, based on the sign and type of its
870
+ * arguments.
871
+ *
872
+ * The arguments themselves should *not* be evaluated, only their types and
873
+ * sign should be used.
874
+ *
875
+ * This can be used in some case for example to determine when certain
876
+ * simplifications are valid.
877
+ */
878
+ sgn?: (ops: ReadonlyArray<Expression>, options: {
879
+ engine: ComputeEngine;
880
+ }) => Sign | undefined;
881
+ eq?: (a: Expression, b: Expression) => boolean | undefined;
882
+ neq?: (a: Expression, b: Expression) => boolean | undefined;
883
+ canonical?: (ops: ReadonlyArray<Expression>, options: {
884
+ engine: ComputeEngine;
885
+ scope: Scope | undefined;
886
+ }) => Expression | null;
887
+ evaluate?: (ops: ReadonlyArray<Expression>, options: Partial<EvaluateOptions> & {
888
+ engine?: ComputeEngine;
889
+ }) => Expression | undefined;
890
+ evaluateAsync?: (ops: ReadonlyArray<Expression>, options?: Partial<EvaluateOptions> & {
891
+ engine?: ComputeEngine;
892
+ }) => Promise<Expression | undefined>;
893
+ evalDimension?: (ops: ReadonlyArray<Expression>, options: {
894
+ engine: ComputeEngine;
895
+ }) => Expression;
896
+ compile?: (expr: Expression) => CompiledExpression;
897
+ /** @internal */
898
+ update(def: OperatorDefinition): void;
899
+ }
900
+ export {};