@cortex-js/compute-engine 0.32.1 → 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 (163) hide show
  1. package/dist/compute-engine.esm.js +31665 -25881
  2. package/dist/compute-engine.min.esm.js +43 -46
  3. package/dist/compute-engine.min.umd.js +43 -46
  4. package/dist/compute-engine.umd.js +31692 -25925
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.min.esm.js +2 -130
  7. package/dist/math-json.min.umd.js +2 -2
  8. package/dist/math-json.umd.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +1 -1
  11. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +1 -1
  14. package/dist/types/common/one-of.d.ts +2 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  17. package/dist/types/common/type/boxed-type.d.ts +1 -1
  18. package/dist/types/common/type/lexer.d.ts +1 -1
  19. package/dist/types/common/type/parse.d.ts +1 -1
  20. package/dist/types/common/type/parser.d.ts +1 -1
  21. package/dist/types/common/type/primitive.d.ts +1 -1
  22. package/dist/types/common/type/serialize.d.ts +1 -1
  23. package/dist/types/common/type/subtype.d.ts +1 -1
  24. package/dist/types/common/type/type-builder.d.ts +1 -1
  25. package/dist/types/common/type/types.d.ts +1 -1
  26. package/dist/types/common/type/utils.d.ts +1 -1
  27. package/dist/types/common/utils.d.ts +1 -1
  28. package/dist/types/compute-engine/assume.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +2 -1
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  34. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  35. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  36. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +5 -1
  38. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  39. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +5 -1
  43. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -2
  67. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  69. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  70. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  71. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  72. package/dist/types/compute-engine/global-types.d.ts +42 -3
  73. package/dist/types/compute-engine/index.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +3 -1
  88. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  89. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  90. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  93. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  94. package/dist/types/compute-engine/latex-syntax/types.d.ts +11 -2
  95. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  96. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  97. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  98. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  99. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  100. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  101. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  102. package/dist/types/compute-engine/library/core.d.ts +1 -1
  103. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  104. package/dist/types/compute-engine/library/library.d.ts +1 -1
  105. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  106. package/dist/types/compute-engine/library/logic-analysis.d.ts +31 -1
  107. package/dist/types/compute-engine/library/logic-utils.d.ts +1 -5
  108. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  109. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  110. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  111. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  112. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  113. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  114. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  115. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  116. package/dist/types/compute-engine/library/utils.d.ts +60 -2
  117. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  118. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  119. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  120. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  121. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  124. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  125. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/numeric.d.ts +2 -2
  129. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  130. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  131. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  132. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  133. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  134. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  135. package/dist/types/compute-engine/numerics/types.d.ts +2 -1
  136. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  137. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  138. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  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 +1 -1
  149. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -11
  150. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  151. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +2 -0
  152. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  153. package/dist/types/compute-engine/tensor/tensors.d.ts +3 -3
  154. package/dist/types/compute-engine/types.d.ts +1 -1
  155. package/dist/types/compute-engine.d.ts +1 -1
  156. package/dist/types/math-json/symbols.d.ts +1 -1
  157. package/dist/types/math-json/types.d.ts +1 -1
  158. package/dist/types/math-json/utils.d.ts +1 -1
  159. package/dist/types/math-json.d.ts +2 -2
  160. package/package.json +1 -1
  161. package/dist/types/compute-engine/compilation/base-compiler.d.ts +0 -31
  162. package/dist/types/compute-engine/compilation/javascript-target.d.ts +0 -68
  163. package/dist/types/compute-engine/compilation/types.d.ts +0 -83
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export declare function gcd(a: BigNum, b: BigNum): BigNum;
3
3
  export declare function lcm(a: BigNum, b: BigNum): BigNum;
4
4
  export declare function factorial2(ce: IBigNum, n: BigNum): BigNum;
@@ -1,3 +1,3 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export declare function gamma(c: Complex): Complex;
3
3
  export declare function gammaln(c: Complex): Complex;
@@ -1,11 +1,11 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export declare const MACHINE_PRECISION_BITS = 53;
3
3
  export declare const MACHINE_PRECISION: number;
4
4
  export declare const DEFAULT_TOLERANCE = 1e-10;
5
5
  export declare const SMALL_INTEGER = 1000000;
6
6
  /** The largest number of digits of a bigint */
7
7
  export declare const MAX_BIGINT_DIGITS = 1024;
8
- export declare const MAX_ITERATION = 1000000;
8
+ export declare const MAX_ITERATION = 10000;
9
9
  export declare const MAX_SYMBOLIC_TERMS = 200;
10
10
  /**
11
11
  * Returns the smallest floating-point number greater than x.
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export declare function primeFactors(n: number): {
3
3
  [factor: number]: number;
4
4
  };
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export declare function isRational(x: any | null): x is Rational;
3
3
  export declare function isMachineRational(x: any | null): x is [SmallInteger, SmallInteger];
4
4
  export declare function isBigRational(x: any | null): x is [bigint, bigint];
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
 
3
3
  Translated from https://github.com/JuliaMath/Richardson.jl/blob/master/src/Richardson.jl
4
4
 
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  import type { BigNum } from './types';
3
3
  export declare function gammaln(z: number): number;
4
4
  export declare function gamma(z: number): number;
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  import type { BigNum } from './types';
3
3
  export declare function mean(values: Iterable<number>): number;
4
4
  export declare function bigMean(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
@@ -1,2 +1,2 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export declare function numberToString(num: number | bigint, fractionalDigits?: number | string): string;
@@ -1,4 +1,5 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
+ /** @internal */
2
3
  type IsInteger<N extends number> = `${N}` extends `${string}.${string}` ? never : `${N}` extends `-${string}.${string}` ? never : number;
3
4
  /** A `SmallInteger` is an integer < 1e6
4
5
  * @category Numerics
@@ -1,3 +1,3 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  /** Calculate the antiderivative of fn, as an expression (not a function) */
3
3
  export declare function antiderivative(fn: BoxedExpression, index: string): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  /**
3
3
  *
4
4
  * @param fn The function to differentiate, a function literal.
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  /**
3
3
  *
4
4
  */
@@ -0,0 +1,33 @@
1
+ /* 0.33.0 */
2
+ * Cost functions for the Fu trigonometric simplification algorithm.
3
+ *
4
+ * The primary objective is to minimize the number of trigonometric functions,
5
+ * with secondary consideration for overall expression complexity.
6
+ */
7
+ import type { BoxedExpression } from '../global-types';
8
+ /**
9
+ * Count the number of trigonometric function occurrences in an expression.
10
+ * This is the primary metric for the Fu algorithm.
11
+ */
12
+ export declare function countTrigFunctions(expr: BoxedExpression): number;
13
+ /**
14
+ * Count the number of leaves (atoms) in an expression.
15
+ * Includes symbols, numbers, and function names.
16
+ */
17
+ export declare function countLeaves(expr: BoxedExpression): number;
18
+ /**
19
+ * The default trig cost function for the Fu algorithm.
20
+ *
21
+ * Priority:
22
+ * 1. Minimize number of trig functions (weighted heavily)
23
+ * 2. Minimize leaf count (secondary)
24
+ *
25
+ * This ensures that expressions with fewer trig functions are always
26
+ * preferred, even if they have slightly more total operations.
27
+ */
28
+ export declare function trigCost(expr: BoxedExpression): number;
29
+ export type TrigCostFunction = (expr: BoxedExpression) => number;
30
+ /**
31
+ * Default cost function for the Fu algorithm
32
+ */
33
+ export declare const DEFAULT_TRIG_COST: TrigCostFunction;
@@ -0,0 +1,130 @@
1
+ /* 0.33.0 */
2
+ * Fu Algorithm Transformation Rules
3
+ *
4
+ * Programmatic implementations of TR1-TR22 from the Fu trigonometric
5
+ * simplification algorithm.
6
+ *
7
+ * Reference: Fu, Hongguang, Xiuqin Zhong, and Zhenbing Zeng.
8
+ * "Automated and readable simplification of trigonometric expressions."
9
+ * Mathematical and Computer Modelling 44.11 (2006): 1169-1177.
10
+ *
11
+ * Each TR function applies a specific transformation to an expression.
12
+ * Returns the transformed expression, or undefined if the rule doesn't apply.
13
+ *
14
+ * IMPORTANT: These functions should NOT call .simplify() on their results
15
+ * to avoid infinite recursion when called from the simplification pipeline.
16
+ */
17
+ import type { BoxedExpression } from '../global-types';
18
+ /**
19
+ * Check if an expression contains any trigonometric functions
20
+ */
21
+ export declare function hasTrigFunction(expr: BoxedExpression): boolean;
22
+ /**
23
+ * Check if expression contains specific operators anywhere in the tree
24
+ */
25
+ export declare function hasOperator(expr: BoxedExpression, ...ops: string[]): boolean;
26
+ export declare function TR1(expr: BoxedExpression): BoxedExpression | undefined;
27
+ /**
28
+ * Apply TR1 to all subexpressions
29
+ */
30
+ export declare function applyTR1(expr: BoxedExpression): BoxedExpression;
31
+ export declare function TR2(expr: BoxedExpression): BoxedExpression | undefined;
32
+ /**
33
+ * Apply TR2 to all subexpressions
34
+ */
35
+ export declare function applyTR2(expr: BoxedExpression): BoxedExpression;
36
+ export declare function TR2i(expr: BoxedExpression): BoxedExpression | undefined;
37
+ /**
38
+ * Apply TR2i to all subexpressions
39
+ */
40
+ export declare function applyTR2i(expr: BoxedExpression): BoxedExpression;
41
+ export declare function TR3(expr: BoxedExpression): BoxedExpression | undefined;
42
+ /**
43
+ * Apply TR3 to all subexpressions
44
+ */
45
+ export declare function applyTR3(expr: BoxedExpression): BoxedExpression;
46
+ export declare function TR5(expr: BoxedExpression): BoxedExpression | undefined;
47
+ /**
48
+ * Apply TR5 to all subexpressions
49
+ */
50
+ export declare function applyTR5(expr: BoxedExpression): BoxedExpression;
51
+ export declare function TR6(expr: BoxedExpression): BoxedExpression | undefined;
52
+ /**
53
+ * Apply TR6 to all subexpressions
54
+ */
55
+ export declare function applyTR6(expr: BoxedExpression): BoxedExpression;
56
+ export declare function TR7(expr: BoxedExpression): BoxedExpression | undefined;
57
+ /**
58
+ * Apply TR7 to all subexpressions
59
+ */
60
+ export declare function applyTR7(expr: BoxedExpression): BoxedExpression;
61
+ export declare function TR7i(expr: BoxedExpression): BoxedExpression | undefined;
62
+ /**
63
+ * Apply TR7i to all subexpressions
64
+ */
65
+ export declare function applyTR7i(expr: BoxedExpression): BoxedExpression;
66
+ export declare function TR8(expr: BoxedExpression): BoxedExpression | undefined;
67
+ /**
68
+ * Apply TR8 to all subexpressions
69
+ */
70
+ export declare function applyTR8(expr: BoxedExpression): BoxedExpression;
71
+ export declare function TR9(expr: BoxedExpression): BoxedExpression | undefined;
72
+ /**
73
+ * Apply TR9 to all subexpressions
74
+ */
75
+ export declare function applyTR9(expr: BoxedExpression): BoxedExpression;
76
+ export declare function TR10(expr: BoxedExpression): BoxedExpression | undefined;
77
+ /**
78
+ * Apply TR10 to all subexpressions
79
+ */
80
+ export declare function applyTR10(expr: BoxedExpression): BoxedExpression;
81
+ export declare function TR10i(expr: BoxedExpression): BoxedExpression | undefined;
82
+ /**
83
+ * Apply TR10i to all subexpressions
84
+ */
85
+ export declare function applyTR10i(expr: BoxedExpression): BoxedExpression;
86
+ export declare function TR11(expr: BoxedExpression): BoxedExpression | undefined;
87
+ /**
88
+ * Apply TR11 to all subexpressions
89
+ */
90
+ export declare function applyTR11(expr: BoxedExpression): BoxedExpression;
91
+ export declare function TR11i(expr: BoxedExpression): BoxedExpression | undefined;
92
+ /**
93
+ * Apply TR11i to all subexpressions
94
+ */
95
+ export declare function applyTR11i(expr: BoxedExpression): BoxedExpression;
96
+ export declare function TR12(expr: BoxedExpression): BoxedExpression | undefined;
97
+ /**
98
+ * Apply TR12 to all subexpressions
99
+ */
100
+ export declare function applyTR12(expr: BoxedExpression): BoxedExpression;
101
+ export declare function TR12i(expr: BoxedExpression): BoxedExpression | undefined;
102
+ /**
103
+ * Apply TR12i to all subexpressions
104
+ */
105
+ export declare function applyTR12i(expr: BoxedExpression): BoxedExpression;
106
+ export declare function TR13(expr: BoxedExpression): BoxedExpression | undefined;
107
+ /**
108
+ * Apply TR13 to all subexpressions
109
+ */
110
+ export declare function applyTR13(expr: BoxedExpression): BoxedExpression;
111
+ export declare function TR22(expr: BoxedExpression): BoxedExpression | undefined;
112
+ /**
113
+ * Apply TR22 to all subexpressions
114
+ */
115
+ export declare function applyTR22(expr: BoxedExpression): BoxedExpression;
116
+ export declare function TR22i(expr: BoxedExpression): BoxedExpression | undefined;
117
+ /**
118
+ * Apply TR22i to all subexpressions
119
+ */
120
+ export declare function applyTR22i(expr: BoxedExpression): BoxedExpression;
121
+ export declare function TRmorrie(expr: BoxedExpression): BoxedExpression | undefined;
122
+ /**
123
+ * Apply TRmorrie to all subexpressions
124
+ */
125
+ export declare function applyTRmorrie(expr: BoxedExpression): BoxedExpression;
126
+ export declare function TRpythagorean(expr: BoxedExpression): BoxedExpression | undefined;
127
+ /**
128
+ * Apply TRpythagorean to all subexpressions
129
+ */
130
+ export declare function applyTRpythagorean(expr: BoxedExpression): BoxedExpression;
@@ -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;
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  /**
3
3
  * Product simplification rules extracted from simplify-rules.ts.
4
4
  * Handles 13 patterns for simplifying Product expressions.
@@ -1,14 +1,4 @@
1
- /* 0.32.1 */
2
- /**
3
- * @todo: a set to "tidy" an expression. Different from a canonical form, but
4
- * inline with the user's expectations.
5
- *
6
- * Example:
7
- *
8
- * - a^n * a^m -> a^(n+m)
9
- * - a / √b -> (a * √b) / b
10
- *
11
- */
1
+ /* 0.33.0 */
12
2
  /**
13
3
  * A set of simplification rules.
14
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  /**
3
3
  * Sum simplification rules extracted from simplify-rules.ts.
4
4
  * Handles 16 patterns for simplifying Sum expressions.
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare function simplifyTrig(x: BoxedExpression): RuleStep | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  import { BoxedExpression, ComputeEngine, DataTypeMap, TensorDataType, TensorField } from '../global-types';
3
3
  /** @category Tensors */
4
4
  export declare function makeTensorField<DT extends keyof DataTypeMap>(ce: ComputeEngine, dtype: DT): TensorField<DataTypeMap[DT]>;
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  /** @category Tensors */
3
3
  export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> implements Tensor<DT> {
4
4
  private ce;
@@ -60,7 +60,7 @@ export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> imple
60
60
  */
61
61
  at(...indices: number[]): DataTypeMap[DT];
62
62
  diagonal(axis1?: number, axis2?: number): undefined | DataTypeMap[DT][];
63
- trace(axis1?: number, axis2?: number): undefined | DataTypeMap[DT];
63
+ trace(axis1?: number, axis2?: number): undefined | DataTypeMap[DT] | AbstractTensor<DT>;
64
64
  /**
65
65
  * Change the shape of the tensor
66
66
  *
@@ -70,7 +70,7 @@ export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> imple
70
70
  slice(index: number): AbstractTensor<DT>;
71
71
  flatten(): DataTypeMap[DT][];
72
72
  upcast<DT extends keyof DataTypeMap>(dtype: DT): AbstractTensor<DT>;
73
- /** Transpose the first and second axis */
73
+ /** Transpose the last two axes (default) */
74
74
  transpose(): undefined | AbstractTensor<DT>;
75
75
  /** Transpose two axes. */
76
76
  transpose(axis1: number, axis2: number, fn?: (v: DataTypeMap[DT]) => DataTypeMap[DT]): undefined | AbstractTensor<DT>;
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export * from '../math-json/types';
3
3
  export * from '../common/type/boxed-type';
4
4
  export * from '../common/type/types';
@@ -1,3 +1,3 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export { ComputeEngine } from './compute-engine/index';
3
3
  export * from './compute-engine/types';
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  * Return true if the string is a valid symbol.
3
3
  *
4
4
  * Check for symbols matching a profile of [Unicode UAX31](https://unicode.org/reports/tr31/)
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  * The following properties can be added to any MathJSON expression
3
3
  * to provide additional information about the expression.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export declare const MISSING: Expression;
3
3
  export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumberObject;
4
4
  export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumberObject;
@@ -1,3 +1,3 @@
1
- /* 0.32.1 */
1
+ /* 0.33.0 */
2
2
  export { isSymbolObject, isStringObject, isFunctionObject, stringValue, operator, operand, symbol, mapArgs, dictionaryFromExpression, } from './math-json/utils';
3
- export declare const version = "0.32.1";
3
+ export declare const version = "0.33.0";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.32.1",
2
+ "version": "0.33.0",
3
3
  "scripts": {
4
4
  "doc": "bash ./scripts/doc.sh",
5
5
  "build": "bash ./scripts/build.sh",
@@ -1,31 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- }