@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,48 @@
1
+ /* 0.33.0 */
2
+ * Fu Algorithm for Trigonometric Simplification
3
+ *
4
+ * Implementation of the algorithm by Fu, Zhong, and Zeng:
5
+ * "Automated and readable simplification of trigonometric expressions."
6
+ * Mathematical and Computer Modelling 44.11 (2006): 1169-1177.
7
+ *
8
+ * The algorithm uses a greedy approach with transformation rules (TR),
9
+ * combination transforms (CTR), and rule lists (RL) to simplify
10
+ * trigonometric expressions.
11
+ */
12
+ import type { BoxedExpression, RuleStep } from '../global-types';
13
+ import { TrigCostFunction } from './fu-cost';
14
+ export interface FuOptions {
15
+ /**
16
+ * Cost function to evaluate expression complexity.
17
+ * Default minimizes trig function count, then leaf count.
18
+ */
19
+ measure?: TrigCostFunction;
20
+ /**
21
+ * Maximum iterations to prevent infinite loops.
22
+ * Default: 100
23
+ */
24
+ maxIterations?: number;
25
+ }
26
+ /**
27
+ * Apply the Fu algorithm to simplify a trigonometric expression.
28
+ *
29
+ * The algorithm:
30
+ * 1. Converts sec/csc to reciprocal forms (TR1) if present
31
+ * 2. For tan/cot expressions, applies RL1
32
+ * 3. If tan/cot remain, converts to sin/cos ratios (TR2)
33
+ * 4. For sin/cos expressions, applies RL2
34
+ * 5. Tries to convert back to tan/cot (TR2i)
35
+ * 6. Selects the best result based on the cost function
36
+ *
37
+ * @param expr The expression to simplify
38
+ * @param options Configuration options
39
+ * @returns RuleStep with simplified expression, or undefined if no simplification
40
+ */
41
+ export declare function fu(expr: BoxedExpression, options?: FuOptions): RuleStep | undefined;
42
+ /**
43
+ * Simplified entry point that returns the expression directly.
44
+ */
45
+ export declare function fuSimplify(expr: BoxedExpression, options?: FuOptions): BoxedExpression;
46
+ export { hasTrigFunction, hasOperator } from './fu-transforms';
47
+ export { trigCost, countTrigFunctions, countLeaves } from './fu-cost';
48
+ export type { TrigCostFunction } from './fu-cost';
@@ -0,0 +1,12 @@
1
+ /* 0.33.0 */
2
+ export declare function simplifyAbs(x: BoxedExpression): RuleStep | undefined;
3
+ /**
4
+ * Simplify expressions where Abs appears as the base of a power.
5
+ * |x|^n -> x^n when n is even
6
+ */
7
+ export declare function simplifyAbsPower(x: BoxedExpression): RuleStep | undefined;
8
+ /**
9
+ * Even functions: f(|x|) -> f(x)
10
+ * This rule handles Cos, Sec, Cosh, Sech with Abs argument
11
+ */
12
+ export declare function simplifyEvenFunctionAbs(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,15 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * Division simplification rules consolidated from simplify-rules.ts.
4
+ * Handles ~5 patterns for simplifying Divide expressions.
5
+ *
6
+ * Patterns:
7
+ * - a/a -> 1 (when a ≠ 0)
8
+ * - 1/(1/a) -> a (when a ≠ 0)
9
+ * - a/(1/b) -> a*b (when b ≠ 0)
10
+ * - a/(b/c) -> a*c/b (when c ≠ 0)
11
+ * - 0/a -> 0 (when a ≠ 0)
12
+ *
13
+ * IMPORTANT: Do not call .simplify() on results to avoid infinite recursion.
14
+ */
15
+ export declare function simplifyDivide(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare function simplifyHyperbolic(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,14 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * Infinity simplification rules consolidated from simplify-rules.ts.
4
+ * Handles ~20 patterns for simplifying expressions involving infinity.
5
+ *
6
+ * Groups rules by operation type:
7
+ * - Multiply with infinity
8
+ * - Divide with infinity
9
+ * - Power with infinity
10
+ * - Indeterminate forms
11
+ *
12
+ * IMPORTANT: Do not call .simplify() on results to avoid infinite recursion.
13
+ */
14
+ export declare function simplifyInfinity(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,15 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * Logarithm simplification rules consolidated from simplify-rules.ts.
4
+ * Handles ~30 patterns for simplifying Ln and Log expressions.
5
+ *
6
+ * Categories:
7
+ * - Ln power rules: ln(x^n) -> n*ln(x)
8
+ * - Log power rules: log_c(x^n) -> n*log_c(x)
9
+ * - Logarithm combinations: ln(x) + ln(y) -> ln(xy)
10
+ * - Change of base rules
11
+ * - Logarithm with infinity
12
+ *
13
+ * IMPORTANT: Do not call .simplify() on results to avoid infinite recursion.
14
+ */
15
+ export declare function simplifyLog(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,15 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * Power simplification rules consolidated from simplify-rules.ts.
4
+ * Handles ~25 patterns for simplifying Power expressions.
5
+ *
6
+ * Categories:
7
+ * - Basic power rules: x^0, x^1, 0^x, 1^x
8
+ * - Power combination: x^n * x^m -> x^{n+m}
9
+ * - Nested powers: (x^n)^m -> x^{n*m}
10
+ * - Root simplifications: sqrt(x^2) -> |x|
11
+ * - Negative exponent in denominator
12
+ *
13
+ * IMPORTANT: Do not call .simplify() on results to avoid infinite recursion.
14
+ */
15
+ export declare function simplifyPower(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,6 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * Product simplification rules extracted from simplify-rules.ts.
4
+ * Handles 13 patterns for simplifying Product expressions.
5
+ */
6
+ export declare function simplifyProduct(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,17 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * A set of simplification rules.
4
+ *
5
+ * The rules are expressed as
6
+ *
7
+ * `[lhs, rhs, condition]`
8
+ *
9
+ * where `lhs` is rewritten as `rhs` if `condition` is true.
10
+ *
11
+ * `lhs` and `rhs` can be either an Expression or a LaTeX string.
12
+ *
13
+ * If using an Expression, the expression is *not* canonicalized before being
14
+ * used. Therefore in some cases using Expression, while more verbose,
15
+ * may be necessary as the expression could be simplified by the canonicalization.
16
+ */
17
+ export declare const SIMPLIFY_RULES: Rule[];
@@ -0,0 +1,6 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ * Sum simplification rules extracted from simplify-rules.ts.
4
+ * Handles 16 patterns for simplifying Sum expressions.
5
+ */
6
+ export declare function simplifySum(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare function simplifyTrig(x: BoxedExpression): RuleStep | undefined;
@@ -0,0 +1,128 @@
1
+ /* 0.33.0 */
2
+ import { BoxedExpression, ComputeEngine, DataTypeMap, TensorDataType, TensorField } from '../global-types';
3
+ /** @category Tensors */
4
+ export declare function makeTensorField<DT extends keyof DataTypeMap>(ce: ComputeEngine, dtype: DT): TensorField<DataTypeMap[DT]>;
5
+ /** @category Tensors */
6
+ export declare class TensorFieldNumber implements TensorField<number> {
7
+ private ce;
8
+ one: number;
9
+ zero: number;
10
+ nan: number;
11
+ constructor(ce: ComputeEngine);
12
+ cast(x: number, dtype: 'float64'): undefined | number;
13
+ cast(x: number, dtype: 'float32'): undefined | number;
14
+ cast(x: number, dtype: 'int32'): undefined | number;
15
+ cast(x: number, dtype: 'uint8'): undefined | number;
16
+ cast(x: number, dtype: 'complex128'): undefined | Complex;
17
+ cast(x: number, dtype: 'complex64'): undefined | Complex;
18
+ cast(x: number, dtype: 'bool'): undefined | boolean;
19
+ cast(x: number, dtype: 'expression'): undefined | BoxedExpression;
20
+ cast(x: number[], dtype: 'float64'): undefined | number[];
21
+ cast(x: number[], dtype: 'float32'): undefined | number[];
22
+ cast(x: number[], dtype: 'int32'): undefined | number[];
23
+ cast(x: number[], dtype: 'uint8'): undefined | number[];
24
+ cast(x: number[], dtype: 'complex128'): undefined | Complex[];
25
+ cast(x: number[], dtype: 'complex64'): undefined | Complex[];
26
+ cast(x: number[], dtype: 'bool'): undefined | boolean[];
27
+ cast(x: number[], dtype: 'expression'): undefined | BoxedExpression[];
28
+ expression(x: number): BoxedExpression;
29
+ isZero(x: number): boolean;
30
+ isOne(x: number): boolean;
31
+ equals(lhs: number, rhs: number): boolean;
32
+ add(lhs: number, rhs: number): number;
33
+ addn(...xs: number[]): number;
34
+ neg(x: number): number;
35
+ sub(lhs: number, rhs: number): number;
36
+ mul(lhs: number, rhs: number): number;
37
+ muln(...xs: number[]): number;
38
+ div(lhs: number, rhs: number): number;
39
+ pow(lhs: number, rhs: number): number;
40
+ conjugate(x: number): number;
41
+ }
42
+ /** @category Tensors */
43
+ export declare class TensorFieldExpression implements TensorField<BoxedExpression> {
44
+ one: BoxedExpression;
45
+ zero: BoxedExpression;
46
+ nan: BoxedExpression;
47
+ private ce;
48
+ constructor(ce: ComputeEngine);
49
+ cast(x: BoxedExpression, dtype: 'float64'): undefined | number;
50
+ cast(x: BoxedExpression, dtype: 'float32'): undefined | number;
51
+ cast(x: BoxedExpression, dtype: 'int32'): undefined | number;
52
+ cast(x: BoxedExpression, dtype: 'uint8'): undefined | number;
53
+ cast(x: BoxedExpression, dtype: 'complex128'): undefined | Complex;
54
+ cast(x: BoxedExpression, dtype: 'complex64'): undefined | Complex;
55
+ cast(x: BoxedExpression, dtype: 'bool'): undefined | boolean;
56
+ cast(x: BoxedExpression, dtype: 'expression'): undefined | BoxedExpression;
57
+ cast(x: BoxedExpression[], dtype: 'float64'): undefined | number[];
58
+ cast(x: BoxedExpression[], dtype: 'float32'): undefined | number[];
59
+ cast(x: BoxedExpression[], dtype: 'int32'): undefined | number[];
60
+ cast(x: BoxedExpression[], dtype: 'uint8'): undefined | number[];
61
+ cast(x: BoxedExpression[], dtype: 'complex128'): undefined | Complex[];
62
+ cast(x: BoxedExpression[], dtype: 'complex64'): undefined | Complex[];
63
+ cast(x: BoxedExpression[], dtype: 'bool'): undefined | boolean[];
64
+ cast(x: BoxedExpression[], dtype: 'expression'): undefined | BoxedExpression[];
65
+ expression(x: BoxedExpression): BoxedExpression;
66
+ isZero(x: BoxedExpression): boolean;
67
+ isOne(x: BoxedExpression): boolean;
68
+ equals(lhs: BoxedExpression, rhs: BoxedExpression): boolean;
69
+ add(lhs: BoxedExpression, rhs: BoxedExpression): BoxedExpression;
70
+ addn(...xs: BoxedExpression[]): BoxedExpression;
71
+ neg(x: BoxedExpression): BoxedExpression;
72
+ sub(lhs: BoxedExpression, rhs: BoxedExpression): BoxedExpression;
73
+ mul(lhs: BoxedExpression, rhs: BoxedExpression): BoxedExpression;
74
+ muln(...xs: BoxedExpression[]): BoxedExpression;
75
+ div(lhs: BoxedExpression, rhs: BoxedExpression): BoxedExpression;
76
+ pow(lhs: BoxedExpression, rhs: number): BoxedExpression;
77
+ conjugate(x: BoxedExpression): BoxedExpression;
78
+ }
79
+ /** @category Tensors */
80
+ export declare class TensorFieldComplex implements TensorField<Complex> {
81
+ one: Complex;
82
+ zero: Complex;
83
+ nan: Complex;
84
+ private ce;
85
+ constructor(ce: ComputeEngine);
86
+ cast(x: Complex, dtype: 'float64'): undefined | number;
87
+ cast(x: Complex, dtype: 'float32'): undefined | number;
88
+ cast(x: Complex, dtype: 'int32'): undefined | number;
89
+ cast(x: Complex, dtype: 'uint8'): undefined | number;
90
+ cast(x: Complex, dtype: 'complex128'): undefined | Complex;
91
+ cast(x: Complex, dtype: 'complex64'): undefined | Complex;
92
+ cast(x: Complex, dtype: 'bool'): undefined | boolean;
93
+ cast(x: Complex, dtype: 'expression'): undefined | BoxedExpression;
94
+ cast(x: Complex[], dtype: 'float64'): undefined | number[];
95
+ cast(x: Complex[], dtype: 'float32'): undefined | number[];
96
+ cast(x: Complex[], dtype: 'int32'): undefined | number[];
97
+ cast(x: Complex[], dtype: 'uint8'): undefined | number[];
98
+ cast(x: Complex[], dtype: 'complex128'): undefined | Complex[];
99
+ cast(x: Complex[], dtype: 'complex64'): undefined | Complex[];
100
+ cast(x: Complex[], dtype: 'bool'): undefined | boolean[];
101
+ cast(x: Complex[], dtype: 'expression'): undefined | BoxedExpression[];
102
+ expression(z: Complex): BoxedExpression;
103
+ isZero(z: Complex): boolean;
104
+ isOne(z: Complex): boolean;
105
+ equals(lhs: Complex, rhs: Complex): boolean;
106
+ add(lhs: Complex, rhs: Complex): Complex;
107
+ addn(...xs: Complex[]): Complex;
108
+ neg(z: Complex): Complex;
109
+ sub(lhs: Complex, rhs: Complex): Complex;
110
+ mul(lhs: Complex, rhs: Complex): Complex;
111
+ muln(...xs: Complex[]): Complex;
112
+ div(lhs: Complex, rhs: Complex): Complex;
113
+ pow(lhs: Complex, rhs: number): Complex;
114
+ conjugate(z: Complex): Complex;
115
+ }
116
+ /**
117
+ * @category Tensors
118
+ * @internal
119
+ */
120
+ export declare function getSupertype(t1: TensorDataType | undefined, t2: TensorDataType): TensorDataType;
121
+ /**
122
+ * If the expression is a literal number, return the datatype of the
123
+ * number (or boolean). Otherwise, return the `expression`.
124
+ *
125
+ * @category Tensors
126
+ * @internal
127
+ */
128
+ export declare function getExpressionDatatype(expr: BoxedExpression): TensorDataType;
@@ -0,0 +1,93 @@
1
+ /* 0.33.0 */
2
+ /** @category Tensors */
3
+ export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> implements Tensor<DT> {
4
+ private ce;
5
+ /**
6
+ * Return a tuple of tensors that have the same dtype.
7
+ * If necessary, one of the two input tensors is upcast.
8
+ *
9
+ * The shape of the tensors is reshaped to a compatible
10
+ * shape. If the shape is not compatible, `undefined` is returned.
11
+ *
12
+ * @param lhs
13
+ * @param rhs
14
+ */
15
+ static align<T1 extends TensorDataType, T2 extends TensorDataType>(lhs: AbstractTensor<T1>, rhs: AbstractTensor<T2>): [AbstractTensor<T1>, AbstractTensor<T1>];
16
+ static align<T1 extends TensorDataType, T2 extends TensorDataType>(lhs: AbstractTensor<T1>, rhs: AbstractTensor<T2>): [AbstractTensor<T2>, AbstractTensor<T2>];
17
+ /**
18
+ * Apply a function to the elements of two tensors, or to a tensor
19
+ * and a scalar.
20
+ *
21
+ * The tensors are aligned and broadcasted if necessary.
22
+ *
23
+ * @param fn
24
+ * @param lhs
25
+ * @param rhs
26
+ * @returns
27
+ */
28
+ static broadcast<T extends TensorDataType>(fn: (lhs: DataTypeMap[T], rhs: DataTypeMap[T]) => DataTypeMap[T], lhs: AbstractTensor<T>, rhs: AbstractTensor<T> | DataTypeMap[T]): AbstractTensor<T>;
29
+ readonly field: TensorField<DataTypeMap[DT]>;
30
+ readonly shape: number[];
31
+ readonly rank: number;
32
+ private readonly _strides;
33
+ constructor(ce: ComputeEngine, tensorData: TensorData<DT>);
34
+ abstract get dtype(): DT;
35
+ abstract get data(): DataTypeMap[DT][];
36
+ get expression(): BoxedExpression;
37
+ /**
38
+ * Like expression(), but return a nested JS array instead
39
+ * of a BoxedExpression
40
+ */
41
+ get array(): NestedArray<DataTypeMap[DT]>;
42
+ /** Indices are 1-based, return a 0-based index in the data */
43
+ private _index;
44
+ get isSquare(): boolean;
45
+ get isSymmetric(): boolean;
46
+ get isSkewSymmetric(): boolean;
47
+ get isUpperTriangular(): boolean;
48
+ get isLowerTriangular(): boolean;
49
+ get isTriangular(): boolean;
50
+ get isDiagonal(): boolean;
51
+ get isIdentity(): boolean;
52
+ get isZero(): boolean;
53
+ /**
54
+ * The number of indices should match the rank of the tensor.
55
+ *
56
+ * Note: the indices are 1-based
57
+ * Note: the data is broadcast (wraps around) if the indices are out of bounds
58
+ *
59
+ * LaTeX notation `A\lbracki, j\rbrack` or `A_{i, j}`
60
+ */
61
+ at(...indices: number[]): DataTypeMap[DT];
62
+ diagonal(axis1?: number, axis2?: number): undefined | DataTypeMap[DT][];
63
+ trace(axis1?: number, axis2?: number): undefined | DataTypeMap[DT] | AbstractTensor<DT>;
64
+ /**
65
+ * Change the shape of the tensor
66
+ *
67
+ * The data is reused (and shared) between the two tensors.
68
+ */
69
+ reshape(...shape: number[]): AbstractTensor<DT>;
70
+ slice(index: number): AbstractTensor<DT>;
71
+ flatten(): DataTypeMap[DT][];
72
+ upcast<DT extends keyof DataTypeMap>(dtype: DT): AbstractTensor<DT>;
73
+ /** Transpose the last two axes (default) */
74
+ transpose(): undefined | AbstractTensor<DT>;
75
+ /** Transpose two axes. */
76
+ transpose(axis1: number, axis2: number, fn?: (v: DataTypeMap[DT]) => DataTypeMap[DT]): undefined | AbstractTensor<DT>;
77
+ conjugateTranspose(axis1: number, axis2: number): undefined | AbstractTensor<DT>;
78
+ determinant(): undefined | DataTypeMap[DT];
79
+ inverse(): undefined | AbstractTensor<DT>;
80
+ pseudoInverse(): undefined | AbstractTensor<DT>;
81
+ adjugateMatrix(): undefined | AbstractTensor<DT>;
82
+ minor(i: number, j: number): undefined | DataTypeMap[DT];
83
+ map1(fn: (lhs: DataTypeMap[DT], rhs: DataTypeMap[DT]) => DataTypeMap[DT], scalar: DataTypeMap[DT]): AbstractTensor<DT>;
84
+ map2(fn: (lhs: DataTypeMap[DT], rhs: DataTypeMap[DT]) => DataTypeMap[DT], rhs: AbstractTensor<DT>): AbstractTensor<DT>;
85
+ add(rhs: AbstractTensor<DT> | DataTypeMap[DT]): AbstractTensor<DT>;
86
+ subtract(rhs: AbstractTensor<DT> | DataTypeMap[DT]): AbstractTensor<DT>;
87
+ multiply(rhs: AbstractTensor<DT> | DataTypeMap[DT]): AbstractTensor<DT>;
88
+ divide(rhs: AbstractTensor<DT> | DataTypeMap[DT]): AbstractTensor<DT>;
89
+ power(rhs: AbstractTensor<DT> | DataTypeMap[DT]): AbstractTensor<DT>;
90
+ equals(rhs: AbstractTensor<DT>): boolean;
91
+ }
92
+ /** @category Tensors */
93
+ export declare function makeTensor<T extends TensorDataType>(ce: ComputeEngine, data: TensorData<T>): AbstractTensor<T>;
@@ -0,0 +1,8 @@
1
+ /* 0.33.0 */
2
+ export * from '../math-json/types';
3
+ export * from '../common/type/boxed-type';
4
+ export * from '../common/type/types';
5
+ export type * from './latex-syntax/types';
6
+ export * from './numerics/types';
7
+ export * from './numeric-value/types';
8
+ export * from './global-types';
@@ -0,0 +1,3 @@
1
+ /* 0.33.0 */
2
+ export { ComputeEngine } from './compute-engine/index';
3
+ export * from './compute-engine/types';
@@ -0,0 +1,11 @@
1
+ /* 0.33.0 */
2
+ * Return true if the string is a valid symbol.
3
+ *
4
+ * Check for symbols matching a profile of [Unicode UAX31](https://unicode.org/reports/tr31/)
5
+ *
6
+ * See https://cortexjs.io/math-json/#symbols for a full definition of the
7
+ * profile.
8
+ */
9
+ export declare function isValidSymbol(s: string): boolean;
10
+ export declare const EMOJIS: RegExp;
11
+ export declare function validateSymbol(s: unknown): 'valid' | 'not-a-string' | 'empty-string' | 'expected-nfc' | 'unexpected-mixed-emoji' | 'unexpected-bidi-marker' | 'unexpected-script' | 'invalid-first-char' | 'invalid-char';
@@ -0,0 +1,122 @@
1
+ /* 0.33.0 */
2
+ * The following properties can be added to any MathJSON expression
3
+ * to provide additional information about the expression.
4
+ *
5
+ * @category MathJSON */
6
+ export type MathJsonAttributes = {
7
+ /** A human readable string to annotate this expression, since JSON does not
8
+ * allow comments in its encoding */
9
+ comment?: string;
10
+ /** A Markdown-encoded string providing documentation about this expression.
11
+ */
12
+ documentation?: string;
13
+ /** A visual representation of this expression as a LaTeX string.
14
+ *
15
+ * This can be useful to preserve non-semantic details, for example
16
+ * parentheses in an expression or styling attributes.
17
+ */
18
+ latex?: string;
19
+ /**
20
+ * A short string referencing an entry in a wikibase.
21
+ *
22
+ * For example:
23
+ *
24
+ * `"Q167"` is the [wikidata entry](https://www.wikidata.org/wiki/Q167)
25
+ * for the `Pi` constant.
26
+ */
27
+ wikidata?: string;
28
+ /** A base URL for the `wikidata` key.
29
+ *
30
+ * A full URL can be produced by concatenating this key with the `wikidata`
31
+ * key. This key applies to this node and all its children.
32
+ *
33
+ * The default value is "https://www.wikidata.org/wiki/"
34
+ */
35
+ wikibase?: string;
36
+ /** A short string indicating an entry in an OpenMath Content Dictionary.
37
+ *
38
+ * For example: `arith1/#abs`.
39
+ *
40
+ */
41
+ openmathSymbol?: string;
42
+ /** A base URL for an OpenMath content dictionary. This key applies to this
43
+ * node and all its children.
44
+ *
45
+ * The default value is "http://www.openmath.org/cd".
46
+ */
47
+ openmathCd?: string;
48
+ /** A URL to the source code from which this expression was generated.
49
+ */
50
+ sourceUrl?: string;
51
+ /** The source code from which this expression was generated.
52
+ *
53
+ * It could be a LaTeX expression, or some other source language.
54
+ */
55
+ sourceContent?: string;
56
+ /**
57
+ * A character offset in `sourceContent` or `sourceUrl` from which this
58
+ * expression was generated.
59
+ */
60
+ sourceOffsets?: [start: number, end: number];
61
+ };
62
+ /** @category MathJSON */
63
+ export type MathJsonSymbol = string;
64
+ /**
65
+ * A MathJSON numeric quantity.
66
+ *
67
+ * The `num` string is made of:
68
+ * - an optional `-` minus sign
69
+ * - a string of decimal digits
70
+ * - an optional fraction part (a `.` decimal marker followed by decimal digits)
71
+ * - an optional repeating decimal pattern: a string of digits enclosed in
72
+ * parentheses
73
+ * - an optional exponent part (a `e` or `E` exponent marker followed by an
74
+ * optional `-` minus sign, followed by a string of digits)
75
+ *
76
+ * It can also consist of the string `NaN`, `-Infinity` or `+Infinity` to
77
+ * represent these respective values.
78
+ *
79
+ * A MathJSON number may contain more digits or an exponent with a greater
80
+ * range than can be represented in an IEEE 64-bit floating-point.
81
+ *
82
+ * For example:
83
+ * - `-12.34`
84
+ * - `0.234e-56`
85
+ * - `1.(3)`
86
+ * - `123456789123456789.123(4567)e999`
87
+ * @category MathJSON
88
+ */
89
+ export type MathJsonNumberObject = {
90
+ num: 'NaN' | '-Infinity' | '+Infinity' | string;
91
+ } & MathJsonAttributes;
92
+ /** @category MathJSON */
93
+ export type MathJsonSymbolObject = {
94
+ sym: MathJsonSymbol;
95
+ } & MathJsonAttributes;
96
+ /** @category MathJSON */
97
+ export type MathJsonStringObject = {
98
+ str: string;
99
+ } & MathJsonAttributes;
100
+ /** @category MathJSON */
101
+ export type MathJsonFunctionObject = {
102
+ fn: [MathJsonSymbol, ...Expression[]];
103
+ } & MathJsonAttributes;
104
+ /** @category MathJSON */
105
+ export type DictionaryValue = boolean | number | string | ExpressionObject | ReadonlyArray<DictionaryValue>;
106
+ /** @category MathJSON */
107
+ export type MathJsonDictionaryObject = {
108
+ dict: Record<string, DictionaryValue>;
109
+ } & MathJsonAttributes;
110
+ /**
111
+ * @category MathJSON
112
+ */
113
+ export type ExpressionObject = MathJsonNumberObject | MathJsonStringObject | MathJsonSymbolObject | MathJsonFunctionObject | MathJsonDictionaryObject;
114
+ /**
115
+ * A MathJSON expression is a recursive data structure.
116
+ *
117
+ * The leaf nodes of an expression are numbers, strings and symbols.
118
+ * The dictionary and function nodes can contain expressions themselves.
119
+ *
120
+ * @category MathJSON
121
+ */
122
+ export type Expression = ExpressionObject | number | MathJsonSymbol | string | readonly [MathJsonSymbol, ...Expression[]];
@@ -0,0 +1,87 @@
1
+ /* 0.33.0 */
2
+ export declare const MISSING: Expression;
3
+ export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumberObject;
4
+ export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumberObject;
5
+ export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbolObject;
6
+ export declare function isStringObject(expr: Expression | null): expr is MathJsonStringObject;
7
+ export declare function isDictionaryObject(expr: Expression | null): expr is MathJsonDictionaryObject;
8
+ export declare function isFunctionObject(expr: Expression | null): expr is MathJsonFunctionObject;
9
+ export declare function isExpressionObject(expr: Expression | null): expr is ExpressionObject;
10
+ /**
11
+ * Returns true if `expr` has at least one recognized metadata property
12
+ * (`latex` or `wikidata`) with a non-undefined value.
13
+ */
14
+ export declare function hasMetaData(expr: Expression | null): expr is ExpressionObject & Partial<MathJsonAttributes>;
15
+ /** If expr is a string literal, return it.
16
+ *
17
+ * A string literal is a JSON string that begins and ends with
18
+ * **U+0027 APOSTROPHE** : **`'`** or an object literal with a `str` key.
19
+ */
20
+ export declare function stringValue(expr: Expression | null | undefined): string | null;
21
+ export declare function stripText(expr: Expression | null | undefined): Expression | null;
22
+ /**
23
+ * The operator of a function is symbol.
24
+ *
25
+ * Return an empty string if the expression is not a function.
26
+ *
27
+ * Examples:
28
+ * * `["Negate", 5]` -> `"Negate"`
29
+ */
30
+ export declare function operator(expr: Expression | null | undefined): MathJsonSymbol;
31
+ /**
32
+ * Return the arguments of a function, or an empty array if not a function
33
+ * or no arguments.
34
+ */
35
+ export declare function operands(expr: Expression | null | undefined): ReadonlyArray<Expression>;
36
+ /** Return the nth operand of a function expression */
37
+ export declare function operand(expr: Expression | null, n: 1 | 2 | 3): Expression | null;
38
+ export declare function nops(expr: Expression | null | undefined): number;
39
+ export declare function unhold(expr: Expression | null): Expression | null;
40
+ export declare function symbol(expr: Expression | null | undefined): string | null;
41
+ export declare function dictionaryFromExpression(expr: Expression | null): null | MathJsonDictionaryObject;
42
+ export declare function dictionaryFromEntries(dict: Record<string, Expression>): Expression;
43
+ /**
44
+ * CAUTION: `machineValue()` will return a truncated value if the number
45
+ * has a precision outside of the machine range.
46
+ */
47
+ export declare function machineValue(expr: Expression | null | undefined): number | null;
48
+ /**
49
+ * Return a rational (numer over denom) representation of the expression,
50
+ * if possible, `null` otherwise.
51
+ *
52
+ * The expression can be:
53
+ * - Some symbols: "Infinity", "Half"...
54
+ * - ["Power", d, -1]
55
+ * - ["Power", n, 1]
56
+ * - ["Divide", n, d]
57
+ *
58
+ * The denominator is always > 0.
59
+ */
60
+ export declare function rationalValue(expr: Expression | undefined | null): [number, number] | null;
61
+ /**
62
+ * Apply a substitution to an expression.
63
+ */
64
+ export declare function subs(expr: Expression, s: {
65
+ [symbol: string]: Expression;
66
+ }): Expression;
67
+ /**
68
+ * Apply a function to the arguments of a function and return an array of T
69
+ */
70
+ export declare function mapArgs<T>(expr: Expression, fn: (x: Expression) => T): T[];
71
+ /**
72
+ * Assuming that op is an associative operator, fold lhs or rhs
73
+ * if either are the same operator.
74
+ */
75
+ export declare function foldAssociativeOperator(op: string, lhs: Expression, rhs: Expression): Expression;
76
+ /** Return the elements of a sequence, or null if the expression is not a sequence. The sequence can be optionally enclosed by a`["Delimiter"]` expression */
77
+ export declare function getSequence(expr: Expression | null | undefined): ReadonlyArray<Expression> | null;
78
+ /** `Nothing` or the empty sequence (`["Sequence"]`) */
79
+ export declare function isEmptySequence(expr: Expression | null | undefined): expr is null | undefined;
80
+ export declare function missingIfEmpty(expr: Expression | null | undefined): Expression;
81
+ /** The number of leaves (atomic expressions) in the expression */
82
+ export declare function countLeaves(expr: Expression | null): number;
83
+ /** True if the string matches the expected pattern for a number */
84
+ export declare function matchesNumber(s: string): boolean;
85
+ /** True if the string matches the expected pattern for a symbol */
86
+ export declare function matchesSymbol(s: string): boolean;
87
+ export declare function matchesString(s: string): boolean;
@@ -0,0 +1,3 @@
1
+ /* 0.33.0 */
2
+ export { isSymbolObject, isStringObject, isFunctionObject, stringValue, operator, operand, symbol, mapArgs, dictionaryFromExpression, } from './math-json/utils';
3
+ export declare const version = "0.33.0";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.32.0",
2
+ "version": "0.33.0",
3
3
  "scripts": {
4
4
  "doc": "bash ./scripts/doc.sh",
5
5
  "build": "bash ./scripts/build.sh",