@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,105 @@
1
+ /* 0.32.1 */
2
+ /**
3
+ * Coefficient of a univariate (single variable) polynomial.
4
+ *
5
+ * The first element is a constant.
6
+ * The second element is the coefficient of the variable.
7
+ * The third element is the coefficient of the variable squared.
8
+ * ...etc
9
+ *
10
+ * `3x^3 + 5x + √5 + 2` -> ['√5 + 2', 5, null, 3]
11
+ *
12
+ * If a coefficient does not apply (there are no corresponding term), it is `null`.
13
+ *
14
+ */
15
+ export type UnivariateCoefficients = (null | BoxedExpression)[];
16
+ export type MultivariateCoefficients = (null | (null | BoxedExpression)[])[];
17
+ /**
18
+ * Return a list of coefficient of powers of `vars` in `poly`,
19
+ * starting with power 0.
20
+ *
21
+ * If `poly` is not a polynomial, return `null`.
22
+ */
23
+ export declare function coefficients(poly: BoxedExpression, vars: string): UnivariateCoefficients | null;
24
+ export declare function coefficients(poly: BoxedExpression, vars: string[]): MultivariateCoefficients | null;
25
+ /**
26
+ * The total degree of an expression is the sum of the
27
+ * positive integer degrees of the factors in the expression:
28
+ *
29
+ * `3√2x^5y^3` -> 5 + 3 = 8
30
+ */
31
+ export declare function totalDegree(expr: BoxedExpression): number;
32
+ /**
33
+ * The max degree of a polynomial is the largest positive integer degree
34
+ * in the factors (monomials) of the expression
35
+ *
36
+ * `3√2x^5y^3` -> 5
37
+ *
38
+ */
39
+ export declare function maxDegree(expr: BoxedExpression): number;
40
+ /**
41
+ * Return a lexicographic key of the expression, for example
42
+ * `xy^2` -> `x y`
43
+ * `x\frac{1}{y}` -> `x y`
44
+ * `2xy + y^2` -> `x y y`
45
+ *
46
+ */
47
+ export declare function lex(expr: BoxedExpression): string;
48
+ export declare function revlex(expr: BoxedExpression): string;
49
+ /**
50
+ * Get the degree of a polynomial in a specific variable.
51
+ * Returns -1 if the expression is not a polynomial in the variable.
52
+ *
53
+ * Examples:
54
+ * - `polynomialDegree(x^3 + 2x + 1, 'x')` → 3
55
+ * - `polynomialDegree(x*y + y^2, 'x')` → 1
56
+ * - `polynomialDegree(sin(x), 'x')` → -1 (not a polynomial)
57
+ */
58
+ export declare function polynomialDegree(expr: BoxedExpression, variable: string): number;
59
+ /**
60
+ * Extract coefficients of a univariate polynomial.
61
+ * Returns an array where index i contains the coefficient of x^i.
62
+ * Returns null if the expression is not a polynomial in the variable.
63
+ *
64
+ * Examples:
65
+ * - `getPolynomialCoefficients(x^3 + 2x + 1, 'x')` → [1, 2, 0, 1]
66
+ * - `getPolynomialCoefficients(3x^2 - x + 5, 'x')` → [5, -1, 3]
67
+ */
68
+ export declare function getPolynomialCoefficients(expr: BoxedExpression, variable: string): BoxedExpression[] | null;
69
+ /**
70
+ * Construct a polynomial expression from its coefficients.
71
+ * coeffs[i] is the coefficient of x^i.
72
+ *
73
+ * Examples:
74
+ * - `fromCoefficients([1, 2, 0, 1], 'x')` → x^3 + 2x + 1
75
+ * - `fromCoefficients([5, -1, 3], 'x')` → 3x^2 - x + 5
76
+ */
77
+ export declare function fromCoefficients(coeffs: BoxedExpression[], variable: string): BoxedExpression;
78
+ /**
79
+ * Polynomial long division.
80
+ * Returns [quotient, remainder] such that dividend = divisor * quotient + remainder.
81
+ * Returns null if inputs are not valid polynomials or divisor is zero.
82
+ *
83
+ * Examples:
84
+ * - `polynomialDivide(x^3-1, x-1, 'x')` → [x^2+x+1, 0]
85
+ * - `polynomialDivide(x^3+2x+1, x+1, 'x')` → [x^2-x+3, -2]
86
+ */
87
+ export declare function polynomialDivide(dividend: BoxedExpression, divisor: BoxedExpression, variable: string): [BoxedExpression, BoxedExpression] | null;
88
+ /**
89
+ * Compute the GCD of two polynomials using the Euclidean algorithm.
90
+ * Returns a monic polynomial (leading coefficient = 1).
91
+ *
92
+ * Examples:
93
+ * - `polynomialGCD(x^2-1, x-1, 'x')` → x-1
94
+ * - `polynomialGCD(x^3-1, x^2-1, 'x')` → x-1
95
+ */
96
+ export declare function polynomialGCD(a: BoxedExpression, b: BoxedExpression, variable: string): BoxedExpression;
97
+ /**
98
+ * Cancel common polynomial factors in a rational expression (Divide).
99
+ * Returns the simplified expression.
100
+ *
101
+ * Examples:
102
+ * - `cancelCommonFactors((x^2-1)/(x-1), 'x')` → x+1
103
+ * - `cancelCommonFactors((x+1)/(x^2+3x+2), 'x')` → 1/(x+2)
104
+ */
105
+ export declare function cancelCommonFactors(expr: BoxedExpression, variable: string): BoxedExpression;
@@ -0,0 +1,66 @@
1
+ /* 0.32.1 */
2
+ import { NumericValue } from '../numeric-value/types';
3
+ import type { Rational } from '../numerics/types';
4
+ /**
5
+ * Group terms in a product by common term.
6
+ *
7
+ * All the terms should be canonical.
8
+ * - the arguments should have been flattened for `Multiply`
9
+ *
10
+ * - any argument of power been distributed, i.e.
11
+ * (ab)^2 -> a^2 b^2
12
+ * *
13
+ * 3 + √5 + √(x+1) + x^2 + (a+b)^2 + d
14
+ * -> [ [[3, "d"], [1, 1]],
15
+ * [[5, "x+1"], [1, 2]],
16
+ * [[1, "a+b"], [2, 1]]
17
+ * ]
18
+ *
19
+ */
20
+ export declare class Product {
21
+ readonly options?: {
22
+ canonical?: boolean;
23
+ };
24
+ engine: ComputeEngine;
25
+ coefficient: NumericValue;
26
+ terms: {
27
+ term: BoxedExpression;
28
+ exponent: Rational;
29
+ }[];
30
+ private _isCanonical;
31
+ static from(expr: BoxedExpression): Product;
32
+ constructor(ce: ComputeEngine, xs?: ReadonlyArray<BoxedExpression>, options?: {
33
+ canonical?: boolean;
34
+ });
35
+ /**
36
+ * Add a term to the product.
37
+ *
38
+ * If `this._isCanonical` a running product of exact terms is kept.
39
+ * Otherwise, terms and their exponent are tallied.
40
+ */
41
+ mul(term: BoxedExpression, exp?: Rational): void;
42
+ /** Divide the product by a term of coefficient */
43
+ div(term: NumericValue | BoxedExpression): void;
44
+ /** The terms of the product, grouped by degrees.
45
+ *
46
+ * If `mode` is `rational`, rationals are split into separate numerator and
47
+ * denominator, so that a rational expression can be created later
48
+ * If `mode` is `expression`, a boxed expression is returned, without
49
+ * splitting rationals
50
+ * If `mode` is `numeric`, the literals are combined into one expression
51
+ *
52
+ */
53
+ groupedByDegrees(options?: {
54
+ mode?: 'rational' | 'expression' | 'numeric';
55
+ }): {
56
+ exponent: Rational;
57
+ terms: BoxedExpression[];
58
+ }[] | null;
59
+ asExpression(options?: {
60
+ numericApproximation: boolean;
61
+ }): BoxedExpression;
62
+ /** The product, expressed as a numerator and denominator */
63
+ asNumeratorDenominator(): [BoxedExpression, BoxedExpression];
64
+ asRationalExpression(): BoxedExpression;
65
+ }
66
+ export declare function commonTerms(lhs: Product, rhs: Product): [NumericValue, BoxedExpression];
@@ -0,0 +1,129 @@
1
+ /* 0.32.1 */
2
+ export declare const ConditionParent: {
3
+ boolean: string;
4
+ string: string;
5
+ expression: string;
6
+ numeric: string;
7
+ number: string;
8
+ symbol: string;
9
+ complex: string;
10
+ imaginary: string;
11
+ real: string;
12
+ notreal: string;
13
+ integer: string;
14
+ rational: string;
15
+ irrational: string;
16
+ notzero: string;
17
+ notone: string;
18
+ finite: string;
19
+ infinite: string;
20
+ positive: string;
21
+ negative: string;
22
+ nonnegative: string;
23
+ nonpositive: string;
24
+ even: string;
25
+ odd: string;
26
+ prime: string;
27
+ composite: string;
28
+ constant: string;
29
+ variable: string;
30
+ function: string;
31
+ operator: string;
32
+ relation: string;
33
+ equation: string;
34
+ inequality: string;
35
+ collection: string;
36
+ list: string;
37
+ set: string;
38
+ tuple: string;
39
+ single: string;
40
+ pair: string;
41
+ triple: string;
42
+ tensor: string;
43
+ vector: string;
44
+ matrix: string;
45
+ scalar: string;
46
+ unit: string;
47
+ dimension: string;
48
+ angle: string;
49
+ polynomial: string;
50
+ };
51
+ export declare const CONDITIONS: {
52
+ boolean: (x: BoxedExpression) => boolean;
53
+ string: (x: BoxedExpression) => boolean;
54
+ number: (x: BoxedExpression) => boolean;
55
+ symbol: (x: BoxedExpression) => boolean;
56
+ expression: (x: BoxedExpression) => boolean;
57
+ numeric: (x: BoxedExpression) => boolean;
58
+ integer: (x: BoxedExpression) => boolean;
59
+ rational: (x: BoxedExpression) => boolean;
60
+ irrational: (x: BoxedExpression) => boolean;
61
+ real: (x: BoxedExpression) => boolean;
62
+ notreal: (x: BoxedExpression) => boolean;
63
+ complex: (x: BoxedExpression) => boolean;
64
+ imaginary: (x: BoxedExpression) => boolean;
65
+ positive: (x: BoxedExpression) => boolean;
66
+ negative: (x: BoxedExpression) => boolean;
67
+ nonnegative: (x: BoxedExpression) => boolean;
68
+ nonpositive: (x: BoxedExpression) => boolean;
69
+ even: (x: BoxedExpression) => boolean;
70
+ odd: (x: BoxedExpression) => boolean;
71
+ prime: (x: BoxedExpression) => boolean;
72
+ composite: (x: BoxedExpression) => boolean;
73
+ notzero: (x: BoxedExpression) => boolean;
74
+ notone: (x: BoxedExpression) => boolean;
75
+ finite: (x: BoxedExpression) => boolean;
76
+ infinite: (x: BoxedExpression) => boolean;
77
+ constant: (x: BoxedExpression) => boolean;
78
+ variable: (x: BoxedExpression) => boolean;
79
+ function: (x: BoxedExpression) => boolean;
80
+ relation: (x: BoxedExpression) => boolean;
81
+ equation: (x: BoxedExpression) => boolean;
82
+ inequality: (x: BoxedExpression) => boolean;
83
+ collection: (x: BoxedExpression) => boolean;
84
+ list: (x: BoxedExpression) => boolean;
85
+ set: (x: BoxedExpression) => boolean;
86
+ tuple: (x: BoxedExpression) => boolean;
87
+ single: (x: BoxedExpression) => boolean;
88
+ pair: (x: BoxedExpression) => boolean;
89
+ triple: (x: BoxedExpression) => boolean;
90
+ scalar: (x: BoxedExpression) => boolean;
91
+ tensor: (x: BoxedExpression) => boolean;
92
+ vector: (x: BoxedExpression) => boolean;
93
+ matrix: (x: BoxedExpression) => boolean;
94
+ unit: (x: BoxedExpression) => boolean;
95
+ dimension: (x: BoxedExpression) => boolean;
96
+ angle: (x: BoxedExpression) => boolean;
97
+ polynomial: (x: BoxedExpression) => boolean;
98
+ };
99
+ export declare function checkConditions(x: BoxedExpression, conditions: string[]): boolean;
100
+ /**
101
+ * Create a boxed rule set from a collection of non-boxed rules
102
+ */
103
+ export declare function boxRules(ce: ComputeEngine, rs: Rule | ReadonlyArray<Rule | BoxedRule> | BoxedRuleSet | undefined | null, options?: {
104
+ canonical?: boolean;
105
+ }): BoxedRuleSet;
106
+ /**
107
+ * Apply a rule to an expression, assuming an incoming substitution
108
+ * @param rule the rule to apply
109
+ * @param expr the expression to apply the rule to
110
+ * @param substitution an incoming substitution
111
+ * @param options
112
+ * @returns A transformed expression, if the rule matched. `null` otherwise.
113
+ */
114
+ export declare function applyRule(rule: Readonly<BoxedRule>, expr: BoxedExpression, substitution: BoxedSubstitution, options?: Readonly<Partial<ReplaceOptions>>): RuleStep | null;
115
+ /**
116
+ * Apply the rules in the ruleset and return a modified expression
117
+ * and the set of rules that were applied.
118
+ *
119
+ * The `replace` function can be used to apply a rule to a non-canonical
120
+ * expression.
121
+ *
122
+ */
123
+ export declare function replace(expr: BoxedExpression, rules: Rule | (Rule | BoxedRule)[] | BoxedRuleSet, options?: Partial<ReplaceOptions>): RuleSteps;
124
+ /**
125
+ * For each rules in the rule set that match, return the `replace` of the rule
126
+ *
127
+ * @param rules
128
+ */
129
+ export declare function matchAnyRules(expr: BoxedExpression, rules: BoxedRuleSet, sub: BoxedSubstitution, options?: Partial<ReplaceOptions>): BoxedExpression[];
@@ -0,0 +1,3 @@
1
+ /* 0.32.1 */
2
+ import type { ComputeEngine, BoxedExpression, JsonSerializationOptions } from '../global-types';
3
+ export declare function serializeJson(ce: ComputeEngine, expr: BoxedExpression, options: Readonly<JsonSerializationOptions>): Expression;
@@ -0,0 +1,46 @@
1
+ /* 0.32.1 */
2
+ export declare function sgn(expr: BoxedExpression): Sign | undefined;
3
+ /**
4
+ * Sign `s` is > 0.
5
+ *
6
+ * :::info[Note]
7
+ * Returns `undefined` for cases where the given sign is either non-applicable to real numbers
8
+ * ('nan', 'unsigned', 'complex-infinity') or does not convey enough information (e.g. 'real',
9
+ * 'not-zero', 'real-not-zero', 'non-negative').
10
+ * :::
11
+ *
12
+ * @param s
13
+ */
14
+ export declare function positiveSign(s: Sign | undefined): boolean | undefined;
15
+ /**
16
+ * Sign `s` is >= 0.
17
+ *
18
+ *
19
+ * **note**: returns *undefined* where sign does not apply to the field of reals, or does not convey
20
+ * enough information.
21
+ *
22
+ * @param s
23
+ */
24
+ export declare function nonNegativeSign(s: Sign | undefined): boolean | undefined;
25
+ /**
26
+ * Sign `s` is < 0.
27
+ *
28
+ * :::info[Note]
29
+ * Returns `undefined` for cases where the given sign is either non-applicable to real numbers
30
+ * ('nan', 'unsigned', 'complex-infinity') or does not convey enough information (e.g. 'real',
31
+ * 'not-zero', 'real-not-zero', 'non-positive').
32
+ * :::
33
+ *
34
+ * @param s
35
+ */
36
+ export declare function negativeSign(s: Sign | undefined): boolean | undefined;
37
+ /**
38
+ * Sign `s` is <= 0.
39
+ *
40
+ *
41
+ * **note**: returns *undefined* where sign does not apply to the field of reals, or does not convey
42
+ * enough information.
43
+ *
44
+ * @param s
45
+ */
46
+ export declare function nonPositiveSign(s: Sign | undefined): boolean | undefined;
@@ -0,0 +1,6 @@
1
+ /* 0.32.1 */
2
+ type InternalSimplifyOptions = SimplifyOptions & {
3
+ useVariations: boolean;
4
+ };
5
+ export declare function simplify(expr: BoxedExpression, options?: Partial<InternalSimplifyOptions>, steps?: RuleSteps): RuleSteps;
6
+ export {};
@@ -0,0 +1,20 @@
1
+ /* 0.32.1 */
2
+ export declare const UNIVARIATE_ROOTS: Rule[];
3
+ /**
4
+ * Expression is a function of a single variable (`x`) or an Equality
5
+ *
6
+ * Return the roots of that variable
7
+ *
8
+ */
9
+ export declare function findUnivariateRoots(expr: BoxedExpression, x: string): ReadonlyArray<BoxedExpression>;
10
+ /** Expr is an equation with an operator of
11
+ * - `Equal`, `Less`, `Greater`, `LessEqual`, `GreaterEqual`
12
+ *
13
+ * Return an expression with the same operator, but with the first argument
14
+ * a variable, if possible:
15
+ * `2x < 4` => `x < 2`
16
+ */
17
+ export declare function univariateSolve(expr: BoxedExpression, x: string): ReadonlyArray<BoxedExpression> | null;
18
+ /** Harmonization rules transform an expr into one or more equivalent
19
+ * expressions that are easier to solve */
20
+ export declare const HARMONIZATION_RULES: Rule[];
@@ -0,0 +1,10 @@
1
+ /* 0.32.1 */
2
+ export declare class Terms {
3
+ private engine;
4
+ private terms;
5
+ constructor(ce: ComputeEngine, terms: ReadonlyArray<BoxedExpression>);
6
+ private add;
7
+ private find;
8
+ N(): BoxedExpression;
9
+ asExpression(): BoxedExpression;
10
+ }
@@ -0,0 +1,9 @@
1
+ /* 0.32.1 */
2
+ export declare function Fu(exp: BoxedExpression): RuleStep | undefined;
3
+ /** Assuming x in an expression in radians, convert to current angular unit. */
4
+ export declare function radiansToAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
5
+ export declare function evalTrig(name: string, op: BoxedExpression | undefined): BoxedExpression | undefined;
6
+ export declare function processInverseFunction(ce: ComputeEngine, xs: ReadonlyArray<BoxedExpression>): BoxedExpression | undefined;
7
+ export declare function trigSign(operator: string, x: BoxedExpression): Sign | undefined;
8
+ export declare function isConstructible(x: string | BoxedExpression): boolean;
9
+ export declare function constructibleValues(operator: string, x: BoxedExpression | undefined): undefined | BoxedExpression;
@@ -0,0 +1,64 @@
1
+ /* 0.32.1 */
2
+ import { Type } from '../../common/type/types';
3
+ import { NumericValue } from '../numeric-value/types';
4
+ /**
5
+ * Check if an expression contains symbolic transcendental functions of constants
6
+ * (like ln(2), sin(1), etc.) that should not be evaluated numerically.
7
+ *
8
+ * This excludes transcendentals that simplify to exact values, such as:
9
+ * - ln(e) -> 1
10
+ * - sin(0) -> 0
11
+ * - cos(0) -> 1
12
+ */
13
+ export declare function hasSymbolicTranscendental(expr: BoxedExpression): boolean;
14
+ export declare function isDictionary(expr: any | null | undefined): expr is DictionaryInterface;
15
+ export declare function isBoxedExpression(x: unknown): x is BoxedExpression;
16
+ /**
17
+ * For any numeric result, if `bignumPreferred()` is true, calculate using
18
+ * bignums. If `bignumPreferred()` is false, calculate using machine numbers
19
+ */
20
+ export declare function bignumPreferred(ce: ComputeEngine): boolean;
21
+ export declare function hashCode(s: string): number;
22
+ export declare function normalizedUnknownsForSolve(syms: string | Iterable<string> | BoxedExpression | Iterable<BoxedExpression> | null | undefined): string[];
23
+ /** Return the local variables in the expression.
24
+ *
25
+ * A local variable is a symbol that is declared with a `Declare`
26
+ * expression in a `Block` expression.
27
+ *
28
+ */
29
+ export declare function getLocalVariables(expr: BoxedExpression): string[];
30
+ export declare function domainToType(expr: BoxedExpression): Type;
31
+ /**
32
+ * Return the angle in the range [0, 2π) that is equivalent to the given angle.
33
+ *
34
+ * @param x
35
+ * @returns
36
+ */
37
+ export declare function canonicalAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
38
+ /**
39
+ * Return a multiple of the imaginary unit, e.g.
40
+ * - 'ImaginaryUnit' -> 1
41
+ * - ['Negate', 'ImaginaryUnit'] -> -1
42
+ * - ['Negate', ['Multiply', 3, 'ImaginaryUnit']] -> -3
43
+ * - ['Multiply', 5, 'ImaginaryUnit'] -> 5
44
+ * - ['Multiply', 'ImaginaryUnit', 5] -> 5
45
+ * - ['Divide', 'ImaginaryUnit', 2] -> 0.5
46
+ *
47
+ */
48
+ export declare function getImaginaryFactor(expr: number | BoxedExpression): BoxedExpression | undefined;
49
+ /**
50
+ * `true` if expr is a number with imaginary part 1 and real part 0, or a symbol with a definition
51
+ * matching this. Does not bind expr if a symbol.
52
+ *
53
+ * @export
54
+ * @param expr
55
+ * @returns
56
+ */
57
+ export declare function isImaginaryUnit(expr: BoxedExpression): boolean;
58
+ export declare function getPiTerm(expr: BoxedExpression): [k: NumericValue, t: NumericValue];
59
+ export declare function isValidOperatorDef(def: any): def is Partial<OperatorDefinition>;
60
+ export declare function isValidValueDef(def: any): def is Partial<ValueDefinition>;
61
+ export declare function isValueDef(def: BoxedDefinition | undefined): def is TaggedValueDefinition;
62
+ export declare function isOperatorDef(def: BoxedDefinition | undefined): def is TaggedOperatorDefinition;
63
+ export declare function updateDef(ce: ComputeEngine, name: string, def: BoxedDefinition, newDef: Partial<OperatorDefinition> | BoxedOperatorDefinition | Partial<ValueDefinition> | BoxedValueDefinition): void;
64
+ export declare function placeholderDef(ce: ComputeEngine, name: string): BoxedDefinition;
@@ -0,0 +1,58 @@
1
+ /* 0.32.1 */
2
+ import type { BoxedExpression, ComputeEngine } from '../global-types';
3
+ /**
4
+ * Check that the number of arguments is as expected.
5
+ *
6
+ * Converts the arguments to canonical, and flattens the sequence.
7
+ */
8
+ export declare function checkArity(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, count: number): ReadonlyArray<BoxedExpression>;
9
+ /**
10
+ * Validation of arguments is normally done by checking the signature of the
11
+ * function vs the arguments of the expression. However, we have a fastpath
12
+ * for some common operations (add, multiply, power, neg, etc...) that bypasses
13
+ * the regular checks. This is its replacements.
14
+ *
15
+ * Since all those fastpath functions are numeric (i.e. have numeric arguments
16
+ * and a numeric result), we do a simple numeric check of all arguments, and
17
+ * verify we have the number of expected arguments.
18
+ *
19
+ * We also assume that the function is threadable.
20
+ *
21
+ * The arguments are made canonical.
22
+ *
23
+ * Flattens sequence expressions.
24
+ */
25
+ export declare function checkNumericArgs(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, options?: number | {
26
+ count?: number;
27
+ flatten?: string;
28
+ }): ReadonlyArray<BoxedExpression>;
29
+ /**
30
+ * Check that an argument is of the expected type.
31
+ *
32
+ * Converts the arguments to canonical
33
+ */
34
+ export declare function checkType(ce: ComputeEngine, arg: BoxedExpression | undefined | null, type: Type | undefined): BoxedExpression;
35
+ export declare function checkTypes(ce: ComputeEngine, args: ReadonlyArray<BoxedExpression>, types: Type[]): ReadonlyArray<BoxedExpression>;
36
+ /**
37
+ * Check that the argument is pure.
38
+ */
39
+ export declare function checkPure(ce: ComputeEngine, arg: BoxedExpression | BoxedExpression | undefined | null): BoxedExpression;
40
+ /**
41
+ *
42
+ * If the arguments match the parameters, return null.
43
+ *
44
+ * Otherwise return a list of expressions indicating the mismatched
45
+ * arguments.
46
+ *
47
+ * <!--
48
+ * @todo?:
49
+ * - Some permutations of operands should perhaps always be treated as invalid. Consider:
50
+ * - A sequence wildcard (non-optional, i.e. '__') followed by either a universal wildcard ('_'),
51
+ * or another non-optional sequence wildcard. (note that an optional sequence wildcard is
52
+ * unproblematic here.)
53
+ *
54
+ * -->
55
+ *
56
+ */
57
+ export declare function validateArguments(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, signature: Type, lazy?: boolean, threadable?: boolean): ReadonlyArray<BoxedExpression> | null;
58
+ export declare function spellCheckMessage(expr: BoxedExpression): string;
@@ -0,0 +1,35 @@
1
+ /* 0.32.1 */
2
+ /** If a collection has fewer than this many elements, eagerly evaluate it.
3
+ *
4
+ * For example, evaluate the Union of two sets with 10 elements each will
5
+ * result in a set with 20 elements.
6
+ *
7
+ * If the sum of the sizes of the two sets is greater than
8
+ * `MAX_SIZE_EAGER_COLLECTION`, the result is a Union expression
9
+ *
10
+ */
11
+ export declare const MAX_SIZE_EAGER_COLLECTION = 100;
12
+ export declare function isFiniteIndexedCollection(col: BoxedExpression): boolean;
13
+ export declare function repeat(value: BoxedExpression, count?: number): Iterator<BoxedExpression>;
14
+ /**
15
+ * Zips together multiple collections into a single iterator.
16
+ *
17
+ * Example:
18
+ * ```typescript
19
+ * const a = ce.box(['List', 1, 2, 3]);
20
+ * const b = ce.box(['List', 4, 5, 6]);
21
+ * const zipped = zip([a, b]);
22
+ * for (const [x, y] of zipped) {
23
+ * console.log(x, y); // 1 4, 2 5, 3 6
24
+ * }
25
+ * ```
26
+ */
27
+ export declare function zip(items: ReadonlyArray<BoxedExpression>): Iterator<BoxedExpression[]>;
28
+ /**
29
+ * Default collection handlers suitable for collections that store their
30
+ * elements as operands.
31
+ *
32
+ * This is the case for List, Tuple, etc.
33
+ */
34
+ export declare function basicIndexedCollectionHandlers(): CollectionHandlers;
35
+ export declare function defaultCollectionHandlers(def: undefined | CollectionHandlers): CollectionHandlers | undefined;
@@ -0,0 +1,31 @@
1
+ /* 0.32.1 */
2
+ import type { CompileTarget, TargetSource } from './types';
3
+ /**
4
+ * Base compiler class containing language-agnostic compilation logic
5
+ */
6
+ export declare class BaseCompiler {
7
+ /**
8
+ * Compile an expression to target language source code
9
+ */
10
+ static compile(expr: BoxedExpression | undefined, target: CompileTarget, prec?: number): TargetSource;
11
+ /**
12
+ * Compile a function expression
13
+ */
14
+ static compileExpr(engine: ComputeEngine, h: string, args: ReadonlyArray<BoxedExpression>, prec: number, target: CompileTarget): TargetSource;
15
+ /**
16
+ * Compile a block expression
17
+ */
18
+ private static compileBlock;
19
+ /**
20
+ * Compile loop constructs (Sum/Product)
21
+ */
22
+ private static compileLoop;
23
+ /**
24
+ * Generate a temporary variable name
25
+ */
26
+ static tempVar(): string;
27
+ /**
28
+ * Inline or wrap expression in IIFE based on complexity
29
+ */
30
+ static inlineExpression(body: string, x: string): string;
31
+ }
@@ -0,0 +1,68 @@
1
+ /* 0.32.1 */
2
+ import { chop, factorial, gcd, lcm, limit } from '../numerics/numeric';
3
+ import { gamma, gammaln } from '../numerics/special-functions';
4
+ import { interquartileRange, kurtosis, mean, median, mode, populationStandardDeviation, populationVariance, quartiles, skewness, standardDeviation, variance } from '../numerics/statistics';
5
+ import type { CompileTarget, CompiledOperators, CompiledFunctions, LanguageTarget, CompilationOptions, CompiledExecutable } from './types';
6
+ /**
7
+ * JavaScript-specific function extension that provides system functions
8
+ */
9
+ export declare class ComputeEngineFunction extends Function {
10
+ SYS: {
11
+ chop: typeof chop;
12
+ factorial: typeof factorial;
13
+ gamma: typeof gamma;
14
+ gcd: typeof gcd;
15
+ integrate: (f: any, a: any, b: any) => number;
16
+ lcm: typeof lcm;
17
+ lngamma: typeof gammaln;
18
+ limit: typeof limit;
19
+ mean: typeof mean;
20
+ median: typeof median;
21
+ variance: typeof variance;
22
+ populationVariance: typeof populationVariance;
23
+ standardDeviation: typeof standardDeviation;
24
+ populationStandardDeviation: typeof populationStandardDeviation;
25
+ kurtosis: typeof kurtosis;
26
+ skewness: typeof skewness;
27
+ mode: typeof mode;
28
+ quartiles: typeof quartiles;
29
+ interquartileRange: typeof interquartileRange;
30
+ };
31
+ constructor(body: string, preamble?: string);
32
+ }
33
+ /**
34
+ * JavaScript function literal with parameters
35
+ */
36
+ export declare class ComputeEngineFunctionLiteral extends Function {
37
+ SYS: {
38
+ chop: typeof chop;
39
+ factorial: typeof factorial;
40
+ gamma: typeof gamma;
41
+ gcd: typeof gcd;
42
+ integrate: (f: any, a: any, b: any) => number;
43
+ lcm: typeof lcm;
44
+ lngamma: typeof gammaln;
45
+ limit: typeof limit;
46
+ mean: typeof mean;
47
+ median: typeof median;
48
+ variance: typeof variance;
49
+ populationVariance: typeof populationVariance;
50
+ standardDeviation: typeof standardDeviation;
51
+ populationStandardDeviation: typeof populationStandardDeviation;
52
+ kurtosis: typeof kurtosis;
53
+ skewness: typeof skewness;
54
+ mode: typeof mode;
55
+ quartiles: typeof quartiles;
56
+ interquartileRange: typeof interquartileRange;
57
+ };
58
+ constructor(body: string, args: string[]);
59
+ }
60
+ /**
61
+ * JavaScript language target implementation
62
+ */
63
+ export declare class JavaScriptTarget implements LanguageTarget {
64
+ getOperators(): CompiledOperators;
65
+ getFunctions(): CompiledFunctions;
66
+ createTarget(options?: Partial<CompileTarget>): CompileTarget;
67
+ compileToExecutable(expr: BoxedExpression, options?: CompilationOptions): CompiledExecutable;
68
+ }