@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,116 @@
1
+ /* 0.33.0 */
2
+ *
3
+ * ## THEORY OF OPERATIONS
4
+ *
5
+ * A numeric value represents a number literal.
6
+ *
7
+ * It is defined as a functional field over the complex numbers.
8
+ *
9
+ * It includes basic arithmetic operations: addition, subtraction,
10
+ * multiplication, power, division, negation, inversion, square root.
11
+ *
12
+ * Several flavors of numeric values are available:
13
+ * - `NumericValue` is the base class for all numeric values.
14
+ * - `ExactNumericValue` is a numeric value that represents numbers as the
15
+ * sum of an imaginary number and the product of a rational and a radical
16
+ * (square root of a integer).
17
+ * - `BigNumericValue` is a numeric value that represents numbers as the
18
+ * sum of an imaginary number and a decimal (arbitrary precision) number.
19
+ *
20
+ * An exact numeric value may need to be converted to a float one, for
21
+ * example when calculating the square root of a square root.
22
+ *
23
+ * A float numeric value is never converted to an exact one.
24
+ *
25
+ */
26
+ import { Decimal } from 'decimal.js';
27
+ import type { Rational, SmallInteger } from '../numerics/types';
28
+ import { NumericPrimitiveType } from '../../common/type/types';
29
+ export type BigNumFactory = (value: Decimal.Value) => Decimal;
30
+ /** The value is equal to `(decimal * rational * sqrt(radical)) + im * i`
31
+ * @category Numerics */
32
+ export type ExactNumericValueData = {
33
+ rational?: Rational;
34
+ radical?: number;
35
+ };
36
+ /** @category Numerics */
37
+ export type NumericValueData = {
38
+ re?: Decimal | number;
39
+ im?: number;
40
+ };
41
+ /** @category Numerics */
42
+ export type NumericValueFactory = (data: number | Decimal | NumericValueData) => NumericValue;
43
+ /** @category Numerics */
44
+ export declare abstract class NumericValue {
45
+ abstract get type(): NumericPrimitiveType;
46
+ /** True if numeric value is the product of a rational and the square root of an integer.
47
+ *
48
+ * This includes: 3/4√5, -2, √2, etc...
49
+ *
50
+ * But it doesn't include 0.5, 3.141592, etc...
51
+ *
52
+ */
53
+ abstract get isExact(): boolean;
54
+ /** If `isExact()`, returns an ExactNumericValue, otherwise returns undefined.
55
+ */
56
+ abstract get asExact(): NumericValue | undefined;
57
+ /** The real part of this numeric value.
58
+ *
59
+ * Can be negative, 0 or positive.
60
+ */
61
+ abstract get re(): number;
62
+ /** bignum version of .re, if available */
63
+ get bignumRe(): Decimal | undefined;
64
+ /** The imaginary part of this numeric value.
65
+ *
66
+ * Can be negative, zero or positive.
67
+ */
68
+ im: number;
69
+ get bignumIm(): Decimal | undefined;
70
+ abstract get numerator(): NumericValue;
71
+ abstract get denominator(): NumericValue;
72
+ abstract get isNaN(): boolean;
73
+ abstract get isPositiveInfinity(): boolean;
74
+ abstract get isNegativeInfinity(): boolean;
75
+ abstract get isComplexInfinity(): boolean;
76
+ abstract get isZero(): boolean;
77
+ isZeroWithTolerance(_tolerance: number | Decimal): boolean;
78
+ abstract get isOne(): boolean;
79
+ abstract get isNegativeOne(): boolean;
80
+ /** The sign of complex numbers is undefined */
81
+ abstract sgn(): -1 | 0 | 1 | undefined;
82
+ /** Return a non-exact representation of the numeric value */
83
+ abstract N(): NumericValue;
84
+ abstract neg(): NumericValue;
85
+ abstract inv(): NumericValue;
86
+ abstract add(other: number | NumericValue): NumericValue;
87
+ abstract sub(other: NumericValue): NumericValue;
88
+ abstract mul(other: number | Decimal | NumericValue): NumericValue;
89
+ abstract div(other: SmallInteger | NumericValue): NumericValue;
90
+ abstract pow(n: number | NumericValue | {
91
+ re: number;
92
+ im: number;
93
+ }): NumericValue;
94
+ abstract root(n: number): NumericValue;
95
+ abstract sqrt(): NumericValue;
96
+ abstract gcd(other: NumericValue): NumericValue;
97
+ abstract abs(): NumericValue;
98
+ abstract ln(base?: number): NumericValue;
99
+ abstract exp(): NumericValue;
100
+ abstract floor(): NumericValue;
101
+ abstract ceil(): NumericValue;
102
+ abstract round(): NumericValue;
103
+ abstract eq(other: number | NumericValue): boolean;
104
+ abstract lt(other: number | NumericValue): boolean | undefined;
105
+ abstract lte(other: number | NumericValue): boolean | undefined;
106
+ abstract gt(other: number | NumericValue): boolean | undefined;
107
+ abstract gte(other: number | NumericValue): boolean | undefined;
108
+ /** Object.valueOf(): returns a primitive value, preferably a JavaScript
109
+ * number over a string, even if at the expense of precision */
110
+ valueOf(): number | string;
111
+ /** Object.toPrimitive() */
112
+ [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
113
+ /** Object.toJSON */
114
+ toJSON(): any;
115
+ print(): void;
116
+ }
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare function bigint(a: Decimal | number | bigint | string): bigint | null;
@@ -0,0 +1,4 @@
1
+ /* 0.33.0 */
2
+ export declare function bigintValue(expr: Expression | null | undefined): bigint | null;
3
+ /** Output a shorthand if possible */
4
+ export declare function numberToExpression(num: number | bigint, fractionalDigits?: string | number): Expression;
@@ -0,0 +1,12 @@
1
+ /* 0.33.0 */
2
+ /** An interval is a continuous set of real numbers */
3
+ export type Interval = {
4
+ start: number;
5
+ openStart: boolean;
6
+ end: number;
7
+ openEnd: boolean;
8
+ };
9
+ export declare function interval(expr: BoxedExpression): Interval | undefined;
10
+ export declare function intervalContains(int: Interval, val: number): boolean;
11
+ /** Return true if int1 is a subset of int2 */
12
+ export declare function intervalSubset(int1: Interval, int2: Interval): boolean;
@@ -0,0 +1,4 @@
1
+ /* 0.33.0 */
2
+ estimate: number;
3
+ error: number;
4
+ };
@@ -0,0 +1,18 @@
1
+ /* 0.33.0 */
2
+ export declare function lcm(a: bigint, b: bigint): bigint;
3
+ /** Return `[factor, root]` such that
4
+ * pow(n, 1/exponent) = factor * pow(root, 1/exponent)
5
+ *
6
+ * canonicalInteger(75, 2) -> [5, 3] = 5^2 * 3
7
+ *
8
+ */
9
+ export declare function canonicalInteger(n: bigint, exponent: number): [factor: bigint, root: bigint];
10
+ export declare function reducedInteger(n: bigint): bigint | number;
11
+ /**
12
+ * Computes the factorial of a number as a generator to allow interruptibility.
13
+ * Yields intermediate values periodically, but these are not intended to be the primary result.
14
+ *
15
+ * @param n - The number to compute the factorial of (as a BigInt).
16
+ * @returns A generator that can be iterated for intermediate values, with the final value returned when the computation completes.
17
+ */
18
+ export declare function factorial(n: bigint): Generator<bigint, bigint>;
@@ -0,0 +1,9 @@
1
+ /* 0.33.0 */
2
+ export declare function gcd(a: BigNum, b: BigNum): BigNum;
3
+ export declare function lcm(a: BigNum, b: BigNum): BigNum;
4
+ export declare function factorial2(ce: IBigNum, n: BigNum): BigNum;
5
+ /**
6
+ * If the exponent of the bignum is in the range of the exponents
7
+ * for machine numbers,return true.
8
+ */
9
+ export declare function isInMachineRange(d: BigNum): boolean;
@@ -0,0 +1,3 @@
1
+ /* 0.33.0 */
2
+ export declare function gamma(c: Complex): Complex;
3
+ export declare function gammaln(c: Complex): Complex;
@@ -0,0 +1,60 @@
1
+ /* 0.33.0 */
2
+ export declare const MACHINE_PRECISION_BITS = 53;
3
+ export declare const MACHINE_PRECISION: number;
4
+ export declare const DEFAULT_TOLERANCE = 1e-10;
5
+ export declare const SMALL_INTEGER = 1000000;
6
+ /** The largest number of digits of a bigint */
7
+ export declare const MAX_BIGINT_DIGITS = 1024;
8
+ export declare const MAX_ITERATION = 10000;
9
+ export declare const MAX_SYMBOLIC_TERMS = 200;
10
+ /**
11
+ * Returns the smallest floating-point number greater than x.
12
+ * Denormalized values may not be supported.
13
+ */
14
+ export declare function nextUp(x: number): number;
15
+ export declare function nextDown(x: number): number;
16
+ /** Return `[factor, root]` such that
17
+ * pow(n, 1/exponent) = factor * pow(root, 1/exponent)
18
+ *
19
+ * canonicalInteger(75, 2) -> [5, 3] = 5^2 * 3
20
+ *
21
+ */
22
+ export declare function canonicalInteger(n: number, exponent: number): readonly [factor: number, root: number];
23
+ export declare function gcd(a: number, b: number): number;
24
+ export declare function lcm(a: number, b: number): number;
25
+ export declare function factorial(n: number): number;
26
+ export declare function factorial2(n: number): number;
27
+ export declare function chop(n: number, tolerance?: number): 0 | number;
28
+ /**
29
+ * An 8th-order centered difference approximation can be used to get a highly
30
+ * accurate approximation of the first derivative of a function.
31
+ * The formula for the 8th-order centered difference approximation for the
32
+ * first derivative is given by:
33
+ *
34
+ * $$ f'(x) \approx \frac{1}{280h} \left[ -f(x-4h) + \frac{4}{3}f(x-3h) - \frac{1}{5}f(x-2h) + \frac{8}{5}f(x-h) - \frac{8}{5}f(x+h) + \frac{1}{5}f(x+2h) - \frac{4}{3}f(x+3h) + f(x+4h) \right]$$
35
+ *
36
+ * Note: Mathematica uses an 8th order approximation for the first derivative
37
+ *
38
+ * f: the function
39
+ * x: the point at which to approximate the derivative
40
+ * h: the step size
41
+ *
42
+ * See https://en.wikipedia.org/wiki/Finite_difference_coefficient
43
+ */
44
+ export declare function centeredDiff8thOrder(f: (number: any) => number, x: number, h?: number): number;
45
+ /**
46
+ *
47
+ * @param f
48
+ * @param x
49
+ * @param dir Direction of approach: > 0 for right, < 0 for left, 0 for both
50
+ * @returns
51
+ */
52
+ export declare function limit(f: (x: number) => number, x: number, dir?: number): number;
53
+ export declare function cantorEnumerateRationals(): Generator<[number, number]>;
54
+ export declare function cantorEnumeratePositiveRationals(): Generator<[
55
+ number,
56
+ number
57
+ ]>;
58
+ export declare function cantorEnumerateComplexNumbers(): Generator<[number, number]>;
59
+ export declare function cantorEnumerateIntegers(): Generator<number>;
60
+ export declare function cantorEnumerateNaturalNumbers(): Generator<number>;
@@ -0,0 +1,7 @@
1
+ /* 0.33.0 */
2
+ export declare function primeFactors(n: number): {
3
+ [factor: number]: number;
4
+ };
5
+ export declare function isPrime(n: number): boolean | undefined;
6
+ export declare function isPrimeBigint(n: bigint): boolean | undefined;
7
+ export declare function bigPrimeFactors(d: bigint): Map<bigint, number>;
@@ -0,0 +1,43 @@
1
+ /* 0.33.0 */
2
+ export declare function isRational(x: any | null): x is Rational;
3
+ export declare function isMachineRational(x: any | null): x is [SmallInteger, SmallInteger];
4
+ export declare function isBigRational(x: any | null): x is [bigint, bigint];
5
+ export declare function isZero(x: Rational): boolean;
6
+ export declare function isPositive(x: Rational): boolean;
7
+ export declare function isOne(x: Rational): boolean;
8
+ export declare function isNegativeOne(x: Rational): boolean;
9
+ export declare function isInteger(x: Rational): boolean;
10
+ export declare function machineNumerator(x: Rational): number;
11
+ export declare function machineDenominator(x: Rational): number;
12
+ export declare function rationalAsFloat(x: Rational): number;
13
+ export declare function isNeg(x: Rational): boolean;
14
+ export declare function div(lhs: Rational, rhs: Rational): Rational;
15
+ /**
16
+ * Add a literal numeric value to a rational.
17
+ * If the rational is a bigint, this is a hint to do the calculation in bigint
18
+ * (no need to check `bignumPreferred()`).
19
+ * @param lhs
20
+ * @param rhs
21
+ * @returns
22
+ */
23
+ export declare function add(lhs: Rational, rhs: Rational): Rational;
24
+ export declare function mul(lhs: Rational, rhs: Rational): Rational;
25
+ export declare function neg(x: [SmallInteger, SmallInteger]): [SmallInteger, SmallInteger];
26
+ export declare function neg(x: [bigint, bigint]): [bigint, bigint];
27
+ export declare function neg(x: Rational): Rational;
28
+ export declare function inverse(x: [SmallInteger, SmallInteger]): [SmallInteger, SmallInteger];
29
+ export declare function inverse(x: [bigint, bigint]): [bigint, bigint];
30
+ export declare function inverse(x: Rational): Rational;
31
+ export declare function asMachineRational(r: Rational): [SmallInteger, SmallInteger];
32
+ export declare function pow(r: Rational, exp: SmallInteger): Rational;
33
+ export declare function sqrt(r: Rational): Rational | undefined;
34
+ export declare function rationalGcd(lhs: Rational, rhs: Rational): Rational;
35
+ export declare function reducedRational(r: [SmallInteger, SmallInteger]): [SmallInteger, SmallInteger];
36
+ export declare function reducedRational(r: [bigint, bigint]): [bigint, bigint];
37
+ export declare function reducedRational(r: Rational): Rational;
38
+ /** Return a rational approximation of x */
39
+ export declare function rationalize(x: number): [n: number, d: number] | number;
40
+ /** Return [factor, root] such that factor * sqrt(root) = sqrt(n)
41
+ * when factor and root are rationals
42
+ */
43
+ export declare function reduceRationalSquareRoot(n: Rational): [factor: Rational, root: number | bigint];
@@ -0,0 +1,80 @@
1
+ /* 0.33.0 */
2
+
3
+ Translated from https://github.com/JuliaMath/Richardson.jl/blob/master/src/Richardson.jl
4
+
5
+
6
+ The `Richardson` module provides a function `extrapolate` that
7
+ extrapolates a given function `f(x)` to `f(x0)`, evaluating
8
+ `f` only at a geometric sequence of points `> x0`
9
+ (or optionally `< x0`).
10
+
11
+ The key algorithm is Richardson extrapolation using a Neville—Aitken
12
+ tableau, which adaptively increases the degree of an extrapolation
13
+ polynomial until convergence is achieved to a desired tolerance
14
+ (or convergence stalls due to e.g. floating-point errors). This
15
+ allows one to obtain `f(x0)` to high-order accuracy, assuming
16
+ that `f(x0+h)` has a Taylor series or some other power
17
+ series in `h`.
18
+ */
19
+ export interface ExtrapolateOptions {
20
+ contract?: number;
21
+ step?: number;
22
+ power?: number;
23
+ atol?: number;
24
+ rtol?: number;
25
+ maxeval?: number;
26
+ breaktol?: number;
27
+ }
28
+ /**
29
+ *
30
+ * Extrapolate `f(x)` to `f₀ ≈ f(x0)`, evaluating `f` only at `x > x0` points
31
+ (or `x < x0` if `h < 0`) using Richardson extrapolation starting at
32
+ `x=x₀+h`. It returns a tuple `(f₀, err)` of the estimated `f(x0)`
33
+ and an error estimate.
34
+
35
+ The return value of `f` can be any type supporting `±` and `norm`
36
+ operations (i.e. a normed vector space).
37
+ Similarly, `h` and `x0` can be in any normed vector space,
38
+ in which case `extrapolate` performs Richardson extrapolation
39
+ of `f(x0+s*h)` to `s=0⁺` (i.e. it takes the limit as `x` goes
40
+ to `x0` along the `h` direction).
41
+
42
+ On each step of Richardson extrapolation, it shrinks `x-x0` by
43
+ a factor of `contract`, stopping when the estimated error is
44
+ `< max(rtol*norm(f₀), atol)`, when the estimated error
45
+ increases by more than `breaktol` (e.g. due to numerical errors in the
46
+ computation of `f`), when `f` returns a non-finite value (`NaN` or `Inf`),
47
+ or when `f` has been evaluated `maxeval` times. Note that
48
+ if the function may converge to zero, you may want
49
+ specify a nonzero `atol` (which cannot be set by default
50
+ because it depends on the scale/units of `f`); alternatively,
51
+ in such cases `extrapolate` will halt when it becomes
52
+ limited by the floating-point precision. (Passing `breaktol=Inf`
53
+ can be useful to force `extrapolate` to continue shrinking `h` even
54
+ if polynomial extrapolation is initially failing to converge,
55
+ possibly at the cost of extraneous function evaluations.)
56
+
57
+
58
+ If `x0 = ±∞` (`±Inf`), then `extrapolate` computes the limit of
59
+ `f(x)` as `x ⟶ ±∞` using geometrically *increasing* values
60
+ of `h` (by factors of `1/contract`).
61
+
62
+ In general, the starting `h` should be large enough that `f(x0+h)`
63
+ can be computed accurately and efficiently (e.g. without
64
+ severe cancellation errors), but small enough that `f` does not
65
+ oscillate much between `x0` and `h`. i.e. `h` should be a typical
66
+ scale over which the function `f` varies significantly.
67
+
68
+ Technically, Richardson extrapolation assumes that `f(x0+h)` can
69
+ be expanded in a power series in `h^power`, where the default
70
+ `power=1` corresponds to an ordinary Taylor series (i.e. assuming
71
+ `f` is analytic at `x0`). If this is not true, you may obtain
72
+ slow convergence from `extrapolate`, but you can pass a different
73
+ value of `power` (e.g. `power=0.5`) if your `f` has some different
74
+ (Puiseux) power-series expansion. Conversely, if `f` is
75
+ an *even* function around `x0`, i.e. `f(x0+h) == f(x0-h)`,
76
+ so that its Taylor series contains only *even* powers of `h`,
77
+ you can accelerate convergence by passing `power=2`.
78
+
79
+ */
80
+ export declare function extrapolate(f: (x: number) => number, x0: number, options?: ExtrapolateOptions): [val: number, err: number];
@@ -0,0 +1,28 @@
1
+ /* 0.33.0 */
2
+ import type { BigNum } from './types';
3
+ export declare function gammaln(z: number): number;
4
+ export declare function gamma(z: number): number;
5
+ /**
6
+ * Inverse Error Function.
7
+ *
8
+ */
9
+ export declare function erfInv(x: number): number;
10
+ /**
11
+ * Trivial function, used when compiling.
12
+ */
13
+ export declare function erfc(x: number): number;
14
+ /**
15
+ * An approximation of the gaussian error function, Erf(), using
16
+ * Abramowitz and Stegun approximation.
17
+ *
18
+ * Thoughts for future improvements:
19
+ * - https://math.stackexchange.com/questions/321569/approximating-the-error-function-erf-by-analytical-functions
20
+ * - https://en.wikipedia.org/wiki/Error_function#Approximation_with_elementary_functions
21
+
22
+ *
23
+ * References:
24
+ * - NIST: https://dlmf.nist.gov/7.24#i
25
+ */
26
+ export declare function erf(x: number): number;
27
+ export declare function bigGammaln(ce: ComputeEngine, z: BigNum): BigNum;
28
+ export declare function bigGamma(ce: ComputeEngine, z: BigNum): BigNum;
@@ -0,0 +1,24 @@
1
+ /* 0.33.0 */
2
+ import type { BigNum } from './types';
3
+ export declare function mean(values: Iterable<number>): number;
4
+ export declare function bigMean(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
5
+ export declare function median(values: Iterable<number>): number;
6
+ export declare function bigMedian(values: Iterable<BigNum>): BigNum;
7
+ export declare function variance(values: Iterable<number>): number;
8
+ export declare function bigVariance(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
9
+ export declare function populationVariance(values: Iterable<number>): number;
10
+ export declare function bigPopulationVariance(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
11
+ export declare function standardDeviation(values: Iterable<number>): number;
12
+ export declare function bigStandardDeviation(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
13
+ export declare function populationStandardDeviation(values: Iterable<number>): number;
14
+ export declare function bigPopulationStandardDeviation(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
15
+ export declare function kurtosis(values: Iterable<number>): number;
16
+ export declare function bigKurtosis(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
17
+ export declare function skewness(values: Iterable<number>): number;
18
+ export declare function bigSkewness(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
19
+ export declare function mode(values: Iterable<number>): number;
20
+ export declare function bigMode(bignum: BigNumFactory, values: Iterable<BigNum>): BigNum;
21
+ export declare function quartiles(values: Iterable<number>): [number, number, number];
22
+ export declare function bigQuartiles(values: Iterable<BigNum>): [BigNum, BigNum, BigNum];
23
+ export declare function interquartileRange(values: Iterable<number>): number;
24
+ export declare function bigInterquartileRange(values: Iterable<BigNum>): BigNum;
@@ -0,0 +1,2 @@
1
+ /* 0.33.0 */
2
+ export declare function numberToString(num: number | bigint, fractionalDigits?: number | string): string;
@@ -0,0 +1,31 @@
1
+ /* 0.33.0 */
2
+ /** @internal */
3
+ type IsInteger<N extends number> = `${N}` extends `${string}.${string}` ? never : `${N}` extends `-${string}.${string}` ? never : number;
4
+ /** A `SmallInteger` is an integer < 1e6
5
+ * @category Numerics
6
+ */
7
+ export type SmallInteger = IsInteger<number>;
8
+ /**
9
+ * A rational number is a number that can be expressed as the quotient or fraction p/q of two integers,
10
+ * a numerator p and a non-zero denominator q.
11
+ *
12
+ * A rational can either be represented as a pair of small integers or
13
+ * a pair of big integers.
14
+ *
15
+ * @category Numerics
16
+ */
17
+ export type Rational = [SmallInteger, SmallInteger] | [bigint, bigint];
18
+ /** @category Numerics */
19
+ export type BigNum = Decimal;
20
+ /** @category Numerics */
21
+ export interface IBigNum {
22
+ readonly _BIGNUM_NAN: BigNum;
23
+ readonly _BIGNUM_ZERO: BigNum;
24
+ readonly _BIGNUM_ONE: BigNum;
25
+ readonly _BIGNUM_TWO: BigNum;
26
+ readonly _BIGNUM_HALF: BigNum;
27
+ readonly _BIGNUM_PI: BigNum;
28
+ readonly _BIGNUM_NEGATIVE_ONE: BigNum;
29
+ bignum(value: string | number | bigint | BigNum): BigNum;
30
+ }
31
+ export {};
@@ -0,0 +1,3 @@
1
+ /* 0.33.0 */
2
+ /** Calculate the antiderivative of fn, as an expression (not a function) */
3
+ export declare function antiderivative(fn: BoxedExpression, index: string): BoxedExpression;
@@ -0,0 +1,18 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ *
4
+ * @param fn The function to differentiate, a function literal.
5
+ *
6
+ * @returns a function expression representing the derivative of `fn` with
7
+ * respect to the variables in `degrees`.
8
+ */
9
+ export declare function derivative(fn: BoxedExpression, order: number): BoxedExpression | undefined;
10
+ /**
11
+ * Calculate the partial derivative of an expression with respect to a
12
+ * variable, `v`.
13
+ *
14
+ * All expressions that do not explicitly depend on `v` are taken to have zero
15
+ * partial derivative.
16
+ *
17
+ */
18
+ export declare function differentiate(expr: BoxedExpression, v: string): BoxedExpression | undefined;
@@ -0,0 +1,5 @@
1
+ /* 0.33.0 */
2
+ /**
3
+ *
4
+ */
5
+ export declare function distribute(expr: BoxedExpression, g?: string, f?: string): BoxedExpression;
@@ -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;