@cortex-js/compute-engine 0.32.0 → 0.33.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 (160) hide show
  1. package/dist/compute-engine.esm.js +48689 -0
  2. package/dist/compute-engine.min.esm.js +122 -0
  3. package/dist/compute-engine.min.umd.js +124 -0
  4. package/dist/compute-engine.umd.js +48697 -0
  5. package/dist/math-json.esm.js +130 -0
  6. package/dist/math-json.min.esm.js +2 -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 +11 -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 +166 -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 +140 -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 +174 -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 +8 -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/cost-function.d.ts +13 -0
  71. package/dist/types/compute-engine/function-utils.d.ts +120 -0
  72. package/dist/types/compute-engine/global-types.d.ts +2969 -0
  73. package/dist/types/compute-engine/index.d.ts +660 -0
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +2 -0
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +27 -0
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +2 -0
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +2 -0
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +3 -0
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +90 -0
  88. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  89. package/dist/types/compute-engine/latex-syntax/parse.d.ts +316 -0
  90. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +29 -0
  91. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +10 -0
  92. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +37 -0
  93. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +18 -0
  94. package/dist/types/compute-engine/latex-syntax/types.d.ts +905 -0
  95. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  96. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -0
  97. package/dist/types/compute-engine/library/calculus.d.ts +2 -0
  98. package/dist/types/compute-engine/library/collections.d.ts +27 -0
  99. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  100. package/dist/types/compute-engine/library/complex.d.ts +2 -0
  101. package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
  102. package/dist/types/compute-engine/library/core.d.ts +2 -0
  103. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  104. package/dist/types/compute-engine/library/library.d.ts +17 -0
  105. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
  106. package/dist/types/compute-engine/library/logic-analysis.d.ts +94 -0
  107. package/dist/types/compute-engine/library/logic-utils.d.ts +54 -0
  108. package/dist/types/compute-engine/library/logic.d.ts +7 -0
  109. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  110. package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
  111. package/dist/types/compute-engine/library/random-expression.d.ts +2 -0
  112. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
  113. package/dist/types/compute-engine/library/sets.d.ts +2 -0
  114. package/dist/types/compute-engine/library/statistics.d.ts +2 -0
  115. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
  116. package/dist/types/compute-engine/library/utils.d.ts +135 -0
  117. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +57 -0
  118. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +75 -0
  119. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +56 -0
  120. package/dist/types/compute-engine/numeric-value/types.d.ts +116 -0
  121. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  122. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  123. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  124. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -0
  125. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +18 -0
  126. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +9 -0
  127. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  128. package/dist/types/compute-engine/numerics/numeric.d.ts +60 -0
  129. package/dist/types/compute-engine/numerics/primes.d.ts +7 -0
  130. package/dist/types/compute-engine/numerics/rationals.d.ts +43 -0
  131. package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
  132. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  133. package/dist/types/compute-engine/numerics/statistics.d.ts +24 -0
  134. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  135. package/dist/types/compute-engine/numerics/types.d.ts +31 -0
  136. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  137. package/dist/types/compute-engine/symbolic/derivative.d.ts +18 -0
  138. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  139. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +33 -0
  140. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +130 -0
  141. package/dist/types/compute-engine/symbolic/fu.d.ts +48 -0
  142. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +12 -0
  143. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +15 -0
  144. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +2 -0
  145. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +14 -0
  146. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +15 -0
  147. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +15 -0
  148. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +6 -0
  149. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +17 -0
  150. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +6 -0
  151. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +2 -0
  152. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +128 -0
  153. package/dist/types/compute-engine/tensor/tensors.d.ts +93 -0
  154. package/dist/types/compute-engine/types.d.ts +8 -0
  155. package/dist/types/compute-engine.d.ts +3 -0
  156. package/dist/types/math-json/symbols.d.ts +11 -0
  157. package/dist/types/math-json/types.d.ts +122 -0
  158. package/dist/types/math-json/utils.d.ts +87 -0
  159. package/dist/types/math-json.d.ts +3 -0
  160. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ /* 0.33.0 */
2
+ export declare function asLatexString(s: unknown): string | null;
3
+ export declare function isRelationalOperator(name: string | undefined): boolean;
4
+ export declare function isInequalityOperator(operator: string | undefined): boolean;
5
+ export declare function isEquationOperator(operator: string | undefined): boolean;
@@ -0,0 +1,4 @@
1
+ /* 0.33.0 */
2
+ export type CanonicalArithmeticOperators = 'Add' | 'Negate' | 'Multiply' | 'Divide' | 'Power' | 'Sqrt' | 'Root' | 'Ln';
3
+ export declare const ARITHMETIC_LIBRARY: SymbolDefinitions[];
4
+ export declare function isPrime(expr: BoxedExpression): boolean | undefined;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const CALCULUS_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,27 @@
1
+ /* 0.33.0 */
2
+ export declare const DEFAULT_LINSPACE_COUNT = 50;
3
+ export declare const COLLECTIONS_LIBRARY: SymbolDefinitions;
4
+ /**
5
+ * Normalize the arguments of range:
6
+ * - [from, to] -> [from, to, 1] if to > from, or [from, to, -1] if to < from
7
+ * - [x] -> [1, x]
8
+ * - arguments rounded to integers
9
+ *
10
+ */
11
+ export declare function range(expr: BoxedExpression): [lower: number, upper: number, step: number];
12
+ /** Return the last value in the range
13
+ * - could be less that lower if step is negative
14
+ * - could be less than upper if step is positive, for
15
+ * example `rangeLast([1, 6, 2])` = 5
16
+ */
17
+ export declare function rangeLast(r: [lower: number, upper: number, step: number]): number;
18
+ /**
19
+ * This function is used to reduce a collection of expressions to a single value. It
20
+ * iterates over the collection, applying the given function to each element and the
21
+ * accumulator. If the function returns `null`, the iteration is stopped and `undefined`
22
+ * is returned. Otherwise, the result of the function is used as the new accumulator.
23
+ * If the iteration completes, the final accumulator is returned.
24
+ */
25
+ export declare function reduceCollection<T>(collection: BoxedExpression, fn: (acc: T, next: BoxedExpression) => T | null, initial: T): Generator<T | undefined>;
26
+ export declare function fromRange(start: number, end: number): number[];
27
+ export declare function sortedIndices(expr: BoxedExpression, fn?: BoxedExpression | undefined): number[] | undefined;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const COMBINATORICS_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const COMPLEX_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const CONTROL_STRUCTURES_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const CORE_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,4 @@
1
+ /* 0.33.0 */
2
+ export declare function canonicalInvisibleOperator(ops: ReadonlyArray<BoxedExpression>, { engine: ce }: {
3
+ engine: ComputeEngine;
4
+ }): BoxedExpression | null;
@@ -0,0 +1,17 @@
1
+ /* 0.33.0 */
2
+ import type { SymbolDefinitions, ComputeEngine } from '../global-types';
3
+ export declare function getStandardLibrary(categories: LibraryCategory[] | LibraryCategory | 'all'): readonly SymbolDefinitions[];
4
+ export declare const LIBRARIES: {
5
+ [category in LibraryCategory]?: SymbolDefinitions | SymbolDefinitions[];
6
+ };
7
+ /**
8
+ * Set the symbol table of the current context (`engine.context`) to `table`
9
+ *
10
+ * `table` can be an array of symbol tables, in order to deal with circular
11
+ * dependencies: it is possible to partition a library into multiple
12
+ * symbol tables, to control the order in which they are processed and
13
+ * avoid having expressions in the definition of an entry reference a symbol
14
+ * or function name that has not yet been added to the symbol table.
15
+ *
16
+ */
17
+ export declare function setSymbolDefinitions(engine: ComputeEngine, table: SymbolDefinitions): void;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const LINEAR_ALGEBRA_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,94 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * Quantifier domain helpers and boolean analysis functions.
4
+ * Extracted from logic.ts for better code organization.
5
+ */
6
+ /**
7
+ * Result of extracting a finite domain from an Element expression.
8
+ * - `status: 'success'` - Domain was successfully extracted
9
+ * - `status: 'non-enumerable'` - Domain exists but cannot be enumerated (e.g., infinite set, unknown symbol)
10
+ * - `status: 'error'` - Invalid Element expression (missing variable, malformed domain)
11
+ */
12
+ export type ExtractDomainResult = {
13
+ status: 'success';
14
+ variable: string;
15
+ values: BoxedExpression[];
16
+ } | {
17
+ status: 'non-enumerable';
18
+ variable: string;
19
+ domain: BoxedExpression;
20
+ reason: string;
21
+ } | {
22
+ status: 'error';
23
+ reason: string;
24
+ };
25
+ /**
26
+ * Extract the finite domain from a quantifier's condition.
27
+ * Supports:
28
+ * - ["Element", "x", ["Set", 1, 2, 3]] → [1, 2, 3]
29
+ * - ["Element", "x", ["Range", 1, 5]] → [1, 2, 3, 4, 5]
30
+ * - ["Element", "x", ["Interval", 1, 5]] → [1, 2, 3, 4, 5] (integers only)
31
+ * - ["Element", "x", ["Set", 1, 2, 3], condition] → filtered values (EL-3)
32
+ * Returns detailed result indicating success, non-enumerable domain, or error.
33
+ */
34
+ export declare function extractFiniteDomainWithReason(condition: BoxedExpression, ce: ComputeEngine): ExtractDomainResult;
35
+ /**
36
+ * Extract the finite domain from a quantifier's condition.
37
+ * Supports:
38
+ * - ["Element", "x", ["Set", 1, 2, 3]] → [1, 2, 3]
39
+ * - ["Element", "x", ["Range", 1, 5]] → [1, 2, 3, 4, 5]
40
+ * - ["Element", "x", ["Interval", 1, 5]] → [1, 2, 3, 4, 5] (integers only)
41
+ * Returns null if the domain is not finite or not recognized.
42
+ * @deprecated Use extractFiniteDomainWithReason for better error handling
43
+ */
44
+ export declare function extractFiniteDomain(condition: BoxedExpression, ce: ComputeEngine): {
45
+ variable: string;
46
+ values: BoxedExpression[];
47
+ } | null;
48
+ /**
49
+ * Check if an expression contains a reference to a specific variable.
50
+ */
51
+ export declare function bodyContainsVariable(expr: BoxedExpression, variable: string): boolean;
52
+ /**
53
+ * For nested quantifiers like ∀x∈S. ∀y∈T. P(x,y), collect the inner domains.
54
+ * Returns an array of {variable, values} for nested ForAll/Exists with finite domains.
55
+ */
56
+ export declare function collectNestedDomains(body: BoxedExpression, ce: ComputeEngine): {
57
+ variable: string;
58
+ values: BoxedExpression[];
59
+ }[];
60
+ /**
61
+ * Get the innermost body of nested quantifiers.
62
+ */
63
+ export declare function getInnermostBody(body: BoxedExpression): BoxedExpression;
64
+ /**
65
+ * Evaluate ForAll over a Cartesian product of domains.
66
+ * Returns True if the predicate holds for all combinations.
67
+ */
68
+ export declare function evaluateForAllCartesian(domains: {
69
+ variable: string;
70
+ values: BoxedExpression[];
71
+ }[], body: BoxedExpression, ce: ComputeEngine): BoxedExpression | undefined;
72
+ /**
73
+ * Evaluate Exists over a Cartesian product of domains.
74
+ * Returns True if the predicate holds for at least one combination.
75
+ */
76
+ export declare function evaluateExistsCartesian(domains: {
77
+ variable: string;
78
+ values: BoxedExpression[];
79
+ }[], body: BoxedExpression, ce: ComputeEngine): BoxedExpression | undefined;
80
+ /**
81
+ * Check if a boolean expression is satisfiable.
82
+ * Returns True if there exists an assignment that makes the expression true.
83
+ */
84
+ export declare function isSatisfiable(expr: BoxedExpression, ce: ComputeEngine): BoxedExpression;
85
+ /**
86
+ * Check if a boolean expression is a tautology.
87
+ * Returns True if the expression is true for all possible assignments.
88
+ */
89
+ export declare function isTautology(expr: BoxedExpression, ce: ComputeEngine): BoxedExpression;
90
+ /**
91
+ * Generate a truth table for a boolean expression.
92
+ * Returns a List of Lists with headers and rows.
93
+ */
94
+ export declare function generateTruthTable(expr: BoxedExpression, ce: ComputeEngine): BoxedExpression;
@@ -0,0 +1,54 @@
1
+ /* 0.33.0 */
2
+ export declare function evaluateAnd(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
3
+ engine: ComputeEngine;
4
+ }): BoxedExpression | undefined;
5
+ export declare function evaluateOr(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
6
+ engine: ComputeEngine;
7
+ }): BoxedExpression | undefined;
8
+ export declare function evaluateNot(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
9
+ engine: ComputeEngine;
10
+ }): BoxedExpression | undefined;
11
+ export declare function evaluateEquivalent(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
12
+ engine: ComputeEngine;
13
+ }): BoxedExpression | undefined;
14
+ export declare function evaluateImplies(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
15
+ engine: ComputeEngine;
16
+ }): BoxedExpression | undefined;
17
+ export declare function evaluateXor(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
18
+ engine: ComputeEngine;
19
+ }): BoxedExpression | undefined;
20
+ export declare function evaluateNand(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
21
+ engine: ComputeEngine;
22
+ }): BoxedExpression | undefined;
23
+ export declare function evaluateNor(args: ReadonlyArray<BoxedExpression>, { engine: ce }: {
24
+ engine: ComputeEngine;
25
+ }): BoxedExpression | undefined;
26
+ /**
27
+ * Convert a boolean expression to Negation Normal Form (NNF).
28
+ * In NNF, negations only appear directly before variables (literals).
29
+ * This is a prerequisite for CNF/DNF conversion.
30
+ */
31
+ export declare function toNNF(expr: BoxedExpression, ce: ComputeEngine): BoxedExpression;
32
+ /**
33
+ * Convert a boolean expression to Conjunctive Normal Form (CNF).
34
+ */
35
+ export declare function toCNF(expr: BoxedExpression, ce: ComputeEngine): BoxedExpression;
36
+ /**
37
+ * Convert a boolean expression to Disjunctive Normal Form (DNF).
38
+ */
39
+ export declare function toDNF(expr: BoxedExpression, ce: ComputeEngine): BoxedExpression;
40
+ /**
41
+ * Extract all propositional variables from a boolean expression.
42
+ * Returns a sorted array of unique variable names.
43
+ */
44
+ export declare function extractVariables(expr: BoxedExpression): string[];
45
+ /**
46
+ * Evaluate a boolean expression with a given truth assignment.
47
+ * Returns True, False, or undefined if the expression cannot be evaluated.
48
+ */
49
+ export declare function evaluateWithAssignment(expr: BoxedExpression, assignment: Record<string, boolean>, ce: ComputeEngine): BoxedExpression;
50
+ /**
51
+ * Generate all possible truth assignments for a list of variables.
52
+ * Each assignment is a Record mapping variable names to boolean values.
53
+ */
54
+ export declare function generateAssignments(variables: string[]): Generator<Record<string, boolean>>;
@@ -0,0 +1,7 @@
1
+ /* 0.33.0 */
2
+ export declare const LOGIC_LIBRARY: SymbolDefinitions;
3
+ export declare function simplifyLogicFunction(x: BoxedExpression): {
4
+ value: BoxedExpression;
5
+ because: string;
6
+ } | undefined;
7
+ export declare const LOGIC_FUNCTION_LIBRARY: SymbolDefinitions;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const NUMBER_THEORY_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const POLYNOMIALS_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare function randomExpression(level?: number): Expression;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const RELOP_LIBRARY: SymbolDefinitions;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const SETS_LIBRARY: SymbolDefinitions;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const STATISTICS_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare const TRIGONOMETRY_LIBRARY: SymbolDefinitions[];
@@ -0,0 +1,135 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * EL-4: Convert known infinite integer sets to their equivalent Limits bounds.
4
+ * Returns undefined if the set cannot be converted to a Limits form.
5
+ *
6
+ * Mappings:
7
+ * - NonNegativeIntegers (ℕ₀) → [0, ∞)
8
+ * - PositiveIntegers (ℤ⁺) → [1, ∞)
9
+ * - NegativeIntegers (ℤ⁻) → Not supported (would need negative direction)
10
+ * - Integers (ℤ) → Not supported (bidirectional)
11
+ * - Other sets (Reals, Complexes, etc.) → Not supported (non-integer)
12
+ */
13
+ export declare function convertInfiniteSetToLimits(domainSymbol: string): {
14
+ lower: number;
15
+ upper: number;
16
+ isFinite: false;
17
+ } | undefined;
18
+ export type IndexingSet = {
19
+ index: string | undefined;
20
+ lower: number;
21
+ upper: number;
22
+ isFinite: boolean;
23
+ };
24
+ /**
25
+ * IndexingSet is an expression describing an index variable
26
+ * and a range of values for that variable.
27
+ *
28
+ * Note that when this function is called the indexing set is assumed to be canonical: 'Hold' has been handled, the indexing set is a tuple, and the bounds are canonical.
29
+ *
30
+ * This can take several valid forms:
31
+ * - a symbol, e.g. `n`, the upper and lower bounds are assumed ot be infinity
32
+ * - a tuple, e.g. `["Pair", "n", 1]` or `["Tuple", "n", 1, 10]` with one
33
+ * or two bounds
34
+ *
35
+ * The result is a normalized version that includes the index, the lower and
36
+ * upper bounds of the range, and a flag indicating whether the range is finite.
37
+ * @param indexingSet
38
+ * @returns
39
+ */
40
+ export declare function normalizeIndexingSet(indexingSet: BoxedExpression): IndexingSet;
41
+ export declare function normalizeIndexingSets(ops: ReadonlyArray<BoxedExpression>): IndexingSet[];
42
+ export declare function indexingSetCartesianProduct(indexingSets: IndexingSet[]): number[][];
43
+ /**
44
+ * Calculates the cartesian product of two arrays.
45
+ * ```ts
46
+ * // Example usage
47
+ * const array1 = [1, 2, 3];
48
+ * const array2 = ['a', 'b', 'c'];
49
+ * const result = cartesianProduct(array1, array2);
50
+ * console.log(result);
51
+ * // Output: [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c'], [3, 'a'], [3, 'b'], [3, 'c']]
52
+ * ```
53
+ * @param array1 - The first array.
54
+ * @param array2 - The second array.
55
+ * @returns The cartesian product as a 2D array.
56
+ */
57
+ export declare function cartesianProduct(array1: number[], array2: number[]): number[][];
58
+ /** Given a sequence of arguments, return an array of Limits:
59
+ *
60
+ * - ["Range", 1, 10] -> ["Limits", "Unknown", 1, 10]
61
+ * - 1, 10 -> ["Limits", "Nothing", 1, 10]
62
+ * - [Tuple, "x", 1, 10] -> ["Limits", "x", 1, 10]
63
+ *
64
+ */
65
+ export declare function canonicalLimitsSequence(ops: ReadonlyArray<BoxedExpression>, options: {
66
+ engine: ComputeEngine;
67
+ }): BoxedExpression[];
68
+ export declare function canonicalLimits(ops: ReadonlyArray<BoxedExpression>, { engine: ce }: {
69
+ engine: ComputeEngine;
70
+ }): BoxedExpression | null;
71
+ /** Return a limit/indexing set in canonical form as a `Limits` expression
72
+ * with:
73
+ * - `index` (a symbol), `Nothing` if none is present
74
+ * - `lower` (a number), `Nothing` if none is present
75
+ * - `upper` (a number), `Nothing` if none is present
76
+ *
77
+ * Or, for Element expressions, preserve them in canonical form.
78
+ *
79
+ * Assume we are in the context of a big operator
80
+ * (i.e. `pushScope()` has been called)
81
+ */
82
+ export declare function canonicalIndexingSet(expr: BoxedExpression): BoxedExpression | undefined;
83
+ export declare function canonicalBigop(bigOp: string, body: BoxedExpression, indexingSets: BoxedExpression[], scope: Scope | undefined): BoxedExpression | null;
84
+ /**
85
+ * A special symbol used to signal that a BigOp could not be evaluated
86
+ * because the domain is non-enumerable (e.g., infinite set, unknown symbol).
87
+ * When this is returned, the Sum/Product should keep the expression symbolic
88
+ * rather than returning NaN.
89
+ */
90
+ export declare const NON_ENUMERABLE_DOMAIN: unique symbol;
91
+ /**
92
+ * Result type for reduceBigOp that includes reason for failure
93
+ */
94
+ export type BigOpResult<T> = {
95
+ status: 'success';
96
+ value: T;
97
+ } | {
98
+ status: 'non-enumerable';
99
+ reason: string;
100
+ domain?: BoxedExpression;
101
+ } | {
102
+ status: 'error';
103
+ reason: string;
104
+ };
105
+ /**
106
+ * Process an expression of the form
107
+ * - ['Operator', body, ['Tuple', index1, lower, upper]]
108
+ * - ['Operator', body, ['Tuple', index1, lower, upper], ['Tuple', index2, lower, upper], ...]
109
+ * - ['Operator', body, ['Element', index, collection]]
110
+ * - ['Operator', body]
111
+ * - ['Operator', collection]
112
+ *
113
+ * `fn()` is the processing done on each element
114
+ * Apply the function `fn` to the body of a big operator, according to the
115
+ * indexing sets.
116
+ *
117
+ * Returns either the reduced value, or `typeof NON_ENUMERABLE_DOMAIN` if the
118
+ * domain cannot be enumerated (in which case the expression should remain symbolic).
119
+ */
120
+ export declare function reduceBigOp<T>(body: BoxedExpression, indexes: ReadonlyArray<BoxedExpression>, fn: (acc: T, x: BoxedExpression) => T | null, initial: T): Generator<T | typeof NON_ENUMERABLE_DOMAIN | undefined>;
121
+ /**
122
+ * Result type for reduceElementIndexingSets to distinguish between
123
+ * successful evaluation, non-enumerable domains (keep symbolic), and errors.
124
+ */
125
+ export type ReduceElementResult<T> = {
126
+ status: 'success';
127
+ value: T;
128
+ } | {
129
+ status: 'non-enumerable';
130
+ reason: string;
131
+ domain?: BoxedExpression;
132
+ } | {
133
+ status: 'error';
134
+ reason: string;
135
+ };
@@ -0,0 +1,57 @@
1
+ /* 0.33.0 */
2
+ import { BigNumFactory, NumericValue, NumericValueData } from './types';
3
+ import { ExactNumericValue } from './exact-numeric-value';
4
+ import { Expression } from '../../math-json/types';
5
+ import { SmallInteger } from '../numerics/types';
6
+ import { NumericPrimitiveType } from '../../common/type/types';
7
+ export declare class BigNumericValue extends NumericValue {
8
+ __brand: 'BigNumericValue';
9
+ decimal: Decimal;
10
+ bignum: BigNumFactory;
11
+ constructor(value: number | Decimal | NumericValueData, bignum: BigNumFactory);
12
+ get type(): NumericPrimitiveType;
13
+ get isExact(): boolean;
14
+ get asExact(): ExactNumericValue | undefined;
15
+ toJSON(): Expression;
16
+ toString(): string;
17
+ clone(value: number | Decimal | NumericValueData): BigNumericValue;
18
+ private _makeExact;
19
+ get re(): number;
20
+ get bignumRe(): Decimal;
21
+ get numerator(): BigNumericValue;
22
+ get denominator(): ExactNumericValue;
23
+ get isNaN(): boolean;
24
+ get isPositiveInfinity(): boolean;
25
+ get isNegativeInfinity(): boolean;
26
+ get isComplexInfinity(): boolean;
27
+ get isZero(): boolean;
28
+ isZeroWithTolerance(tolerance: number | Decimal): boolean;
29
+ get isOne(): boolean;
30
+ get isNegativeOne(): boolean;
31
+ sgn(): -1 | 0 | 1 | undefined;
32
+ N(): NumericValue;
33
+ neg(): BigNumericValue;
34
+ inv(): BigNumericValue;
35
+ add(other: number | NumericValue): NumericValue;
36
+ sub(other: NumericValue): NumericValue;
37
+ mul(other: number | Decimal | NumericValue): NumericValue;
38
+ div(other: SmallInteger | NumericValue): NumericValue;
39
+ pow(exponent: number | NumericValue | {
40
+ re: number;
41
+ im: number;
42
+ }): NumericValue;
43
+ root(exp: number): NumericValue;
44
+ sqrt(): NumericValue;
45
+ gcd(other: NumericValue): NumericValue;
46
+ abs(): NumericValue;
47
+ ln(base?: number): NumericValue;
48
+ exp(): NumericValue;
49
+ floor(): NumericValue;
50
+ ceil(): NumericValue;
51
+ round(): NumericValue;
52
+ eq(other: number | NumericValue): boolean;
53
+ lt(other: number | NumericValue): boolean | undefined;
54
+ lte(other: number | NumericValue): boolean | undefined;
55
+ gt(other: number | NumericValue): boolean | undefined;
56
+ gte(other: number | NumericValue): boolean | undefined;
57
+ }
@@ -0,0 +1,75 @@
1
+ /* 0.33.0 */
2
+ import { Rational, SmallInteger } from '../numerics/types';
3
+ import { BigNumFactory, ExactNumericValueData, NumericValue, NumericValueFactory } from './types';
4
+ import { Expression } from '../../math-json/types';
5
+ import { NumericPrimitiveType } from '../../common/type/types';
6
+ /**
7
+ * An ExactNumericValue is the sum of a Gaussian imaginary and the product of
8
+ * a rational number and a square root:
9
+ *
10
+ * a/b * sqrt(c) + ki where a, b, c and k are integers
11
+ *
12
+ * Note that ExactNumericValue does not "know" about BigNumericValue, but
13
+ * BigNumericValue "knows" about ExactNumericValue.
14
+ *
15
+ */
16
+ export declare class ExactNumericValue extends NumericValue {
17
+ __brand: 'ExactNumericValue';
18
+ rational: Rational;
19
+ radical: number;
20
+ im: number;
21
+ factory: NumericValueFactory;
22
+ bignum: BigNumFactory;
23
+ /** The caller is responsible to make sure the input is valid, i.e.
24
+ * - rational is a fraction of integers (but it may not be reduced)
25
+ * - radical is an integer
26
+ */
27
+ constructor(value: number | bigint | ExactNumericValueData, factory: NumericValueFactory, bignum: BigNumFactory);
28
+ get type(): NumericPrimitiveType;
29
+ get isExact(): boolean;
30
+ get asExact(): NumericValue | undefined;
31
+ toJSON(): Expression;
32
+ clone(value: number | ExactNumericValueData): ExactNumericValue;
33
+ /** Object.toString() */
34
+ toString(): string;
35
+ get sign(): -1 | 0 | 1;
36
+ get re(): number;
37
+ get bignumRe(): Decimal;
38
+ get numerator(): ExactNumericValue;
39
+ get denominator(): ExactNumericValue;
40
+ normalize(): void;
41
+ get isNaN(): boolean;
42
+ get isPositiveInfinity(): boolean;
43
+ get isNegativeInfinity(): boolean;
44
+ get isComplexInfinity(): boolean;
45
+ get isZero(): boolean;
46
+ get isOne(): boolean;
47
+ get isNegativeOne(): boolean;
48
+ sgn(): -1 | 0 | 1 | undefined;
49
+ N(): NumericValue;
50
+ neg(): ExactNumericValue;
51
+ inv(): NumericValue;
52
+ add(other: number | NumericValue): NumericValue;
53
+ sub(other: NumericValue): NumericValue;
54
+ mul(other: number | Decimal | NumericValue): NumericValue;
55
+ div(other: SmallInteger | NumericValue): NumericValue;
56
+ pow(exponent: number | NumericValue | {
57
+ re: number;
58
+ im: number;
59
+ }): NumericValue;
60
+ root(exponent: number): NumericValue;
61
+ sqrt(): NumericValue;
62
+ gcd(other: NumericValue): NumericValue;
63
+ abs(): NumericValue;
64
+ ln(base?: number): NumericValue;
65
+ exp(): NumericValue;
66
+ floor(): NumericValue;
67
+ ceil(): NumericValue;
68
+ round(): NumericValue;
69
+ eq(other: number | NumericValue): boolean;
70
+ lt(other: number | NumericValue): boolean | undefined;
71
+ lte(other: number | NumericValue): boolean | undefined;
72
+ gt(other: number | NumericValue): boolean | undefined;
73
+ gte(other: number | NumericValue): boolean | undefined;
74
+ static sum(values: NumericValue[], factory: NumericValueFactory, bignumFactory: BigNumFactory): NumericValue[];
75
+ }
@@ -0,0 +1,56 @@
1
+ /* 0.33.0 */
2
+ import { BigNumFactory, NumericValue, NumericValueData } from './types';
3
+ import type { Expression } from '../../math-json/types';
4
+ import type { SmallInteger } from '../numerics/types';
5
+ import { NumericPrimitiveType } from '../../common/type/types';
6
+ export declare class MachineNumericValue extends NumericValue {
7
+ __brand: 'MachineNumericValue';
8
+ decimal: number;
9
+ bignum: BigNumFactory;
10
+ constructor(value: number | Decimal | NumericValueData, bignum: BigNumFactory);
11
+ private _makeExact;
12
+ get type(): NumericPrimitiveType;
13
+ get isExact(): boolean;
14
+ get asExact(): NumericValue | undefined;
15
+ toJSON(): Expression;
16
+ toString(): string;
17
+ clone(value: number | Decimal | NumericValueData): MachineNumericValue;
18
+ get re(): number;
19
+ get bignumRe(): Decimal | undefined;
20
+ get numerator(): MachineNumericValue;
21
+ get denominator(): NumericValue;
22
+ get isNaN(): boolean;
23
+ get isPositiveInfinity(): boolean;
24
+ get isNegativeInfinity(): boolean;
25
+ get isComplexInfinity(): boolean;
26
+ get isZero(): boolean;
27
+ isZeroWithTolerance(tolerance: number | Decimal): boolean;
28
+ get isOne(): boolean;
29
+ get isNegativeOne(): boolean;
30
+ sgn(): -1 | 0 | 1 | undefined;
31
+ N(): NumericValue;
32
+ neg(): NumericValue;
33
+ inv(): NumericValue;
34
+ add(other: number | NumericValue): NumericValue;
35
+ sub(other: NumericValue): NumericValue;
36
+ mul(other: number | Decimal | NumericValue): NumericValue;
37
+ div(other: SmallInteger | NumericValue): NumericValue;
38
+ pow(exponent: number | {
39
+ re: number;
40
+ im: number;
41
+ }): NumericValue;
42
+ root(exponent: number): NumericValue;
43
+ sqrt(): NumericValue;
44
+ gcd(other: NumericValue): NumericValue;
45
+ abs(): NumericValue;
46
+ ln(base?: number): NumericValue;
47
+ exp(): NumericValue;
48
+ floor(): NumericValue;
49
+ ceil(): NumericValue;
50
+ round(): NumericValue;
51
+ eq(other: number | NumericValue): boolean;
52
+ lt(other: number | NumericValue): boolean | undefined;
53
+ lte(other: number | NumericValue): boolean | undefined;
54
+ gt(other: number | NumericValue): boolean | undefined;
55
+ gte(other: number | NumericValue): boolean | undefined;
56
+ }