@cortex-js/compute-engine 0.25.0 → 0.26.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 (152) hide show
  1. package/dist/compute-engine.esm.js +27153 -25341
  2. package/dist/compute-engine.js +27124 -25300
  3. package/dist/compute-engine.min.esm.js +88 -23
  4. package/dist/compute-engine.min.js +88 -23
  5. package/dist/math-json.esm.js +42 -196
  6. package/dist/math-json.js +42 -196
  7. package/dist/math-json.min.esm.js +42 -196
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +30 -4
  10. package/dist/types/common/buffer.d.ts +9 -0
  11. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  12. package/dist/types/common/one-of.d.ts +9 -0
  13. package/dist/types/common/signals.d.ts +1 -1
  14. package/dist/types/common/styled-text.d.ts +28 -0
  15. package/dist/types/common/suggest.d.ts +1 -0
  16. package/dist/types/common/syntax-highlighter.d.ts +40 -0
  17. package/dist/types/common/terminal.d.ts +19 -0
  18. package/dist/types/common/type/parse.d.ts +4 -0
  19. package/dist/types/common/type/primitive.d.ts +8 -0
  20. package/dist/types/common/type/serialize.d.ts +2 -0
  21. package/dist/types/common/type/subtype.d.ts +6 -0
  22. package/dist/types/common/type/types.d.ts +249 -0
  23. package/dist/types/common/type/utils.d.ts +39 -0
  24. package/dist/types/common/utils.d.ts +2 -1
  25. package/dist/types/compute-engine/assume.d.ts +13 -13
  26. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +71 -47
  27. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  28. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -0
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +12 -0
  30. package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +16 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +20 -0
  32. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  33. package/dist/types/compute-engine/boxed-expression/box.d.ts +13 -71
  34. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +31 -13
  35. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +66 -45
  36. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +41 -37
  37. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
  38. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +13 -9
  39. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +34 -66
  40. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +63 -41
  41. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +44 -27
  42. package/dist/types/compute-engine/boxed-expression/cache.d.ts +6 -0
  43. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  45. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  46. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -6
  48. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  49. package/dist/types/compute-engine/boxed-expression/hold.d.ts +9 -0
  50. package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -4
  51. package/dist/types/compute-engine/boxed-expression/negate.d.ts +10 -0
  52. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +5 -39
  53. package/dist/types/compute-engine/boxed-expression/order.d.ts +26 -14
  54. package/dist/types/compute-engine/{symbolic → boxed-expression}/polynomials.d.ts +11 -15
  55. package/dist/types/compute-engine/{symbolic → boxed-expression}/product.d.ts +18 -24
  56. package/dist/types/compute-engine/boxed-expression/public.d.ts +947 -656
  57. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  58. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
  59. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +6 -0
  60. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  61. package/dist/types/compute-engine/{solve.d.ts → boxed-expression/solve.d.ts} +5 -5
  62. package/dist/types/compute-engine/{symbolic → boxed-expression}/tensor-fields.d.ts +3 -3
  63. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  64. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +10 -0
  65. package/dist/types/compute-engine/boxed-expression/utils.d.ts +22 -16
  66. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -7
  67. package/dist/types/compute-engine/collection-utils.d.ts +24 -2
  68. package/dist/types/compute-engine/compile.d.ts +3 -3
  69. package/dist/types/compute-engine/compute-engine.d.ts +133 -165
  70. package/dist/types/compute-engine/cost-function.d.ts +11 -1
  71. package/dist/types/compute-engine/function-utils.d.ts +5 -5
  72. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
  87. package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -30
  88. package/dist/types/compute-engine/latex-syntax/public.d.ts +22 -18
  89. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
  90. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -8
  92. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  93. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -2
  94. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  95. package/dist/types/compute-engine/library/collections.d.ts +24 -1
  96. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  97. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  98. package/dist/types/compute-engine/library/core.d.ts +1 -3
  99. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  100. package/dist/types/compute-engine/library/library.d.ts +2 -4
  101. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  102. package/dist/types/compute-engine/library/logic.d.ts +5 -1
  103. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  104. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  105. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  106. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  107. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  108. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  109. package/dist/types/compute-engine/library/utils.d.ts +46 -40
  110. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +59 -0
  111. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +77 -0
  112. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +58 -0
  113. package/dist/types/compute-engine/numeric-value/public.d.ts +110 -0
  114. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  115. package/dist/types/compute-engine/numerics/bignum.d.ts +12 -0
  116. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  117. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  118. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +19 -0
  119. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +4 -14
  120. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +6 -9
  121. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -59
  123. package/dist/types/compute-engine/numerics/primes.d.ts +3 -3
  124. package/dist/types/compute-engine/numerics/rationals.d.ts +29 -13
  125. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  127. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  128. package/dist/types/compute-engine/public.d.ts +8 -4
  129. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -2
  130. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  131. package/dist/types/compute-engine/{simplify-rules.d.ts → symbolic/simplify-rules.d.ts} +1 -1
  132. package/dist/types/compute-engine/{symbolic → tensor}/tensors.d.ts +3 -3
  133. package/dist/types/compute-engine.d.ts +4 -2
  134. package/dist/types/math-json/identifiers.d.ts +11 -0
  135. package/dist/types/math-json/{math-json-format.d.ts → types.d.ts} +4 -9
  136. package/dist/types/math-json/utils.d.ts +15 -23
  137. package/dist/types/math-json.d.ts +3 -3
  138. package/package.json +11 -11
  139. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -48
  140. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +0 -40
  141. package/dist/types/compute-engine/domain-utils.d.ts +0 -19
  142. package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
  143. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -17
  144. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
  145. package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
  146. package/dist/types/compute-engine/library/domains.d.ts +0 -16
  147. package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
  148. package/dist/types/compute-engine/rules.d.ts +0 -20
  149. package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
  150. package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
  151. package/dist/types/compute-engine/symbolic/negate.d.ts +0 -11
  152. package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
@@ -0,0 +1,77 @@
1
+ /* 0.26.0 */
2
+ import { SmallInteger } from '../numerics/numeric';
3
+ import { Rational } from '../numerics/rationals';
4
+ import { ExactNumericValueData, NumericValue, NumericValueFactory } from './public';
5
+ import { Expression } from '../../math-json/types';
6
+ import { BigNumFactory } from './big-numeric-value';
7
+ import { NumericType } from '../../common/type/types';
8
+ /**
9
+ * An ExactNumericValue is the sum of a Gaussian imaginary and the product of
10
+ * a rational number and a square root:
11
+ *
12
+ * a/b * sqrt(c) + ki where a, b, c and k are integers
13
+ *
14
+ * Note that ExactNumericValue does not "know" about BigNumericValue, but
15
+ * BigNumericValue "knows" about ExactNumericValue.
16
+ *
17
+ */
18
+ export declare class ExactNumericValue extends NumericValue {
19
+ __brand: 'ExactNumericValue';
20
+ rational: Rational;
21
+ radical: number;
22
+ im: number;
23
+ factory: NumericValueFactory;
24
+ bignum: BigNumFactory;
25
+ /** The caller is responsible to make sure the input is valid, i.e.
26
+ * - rational is a fraction of integers (but it may not be reduced)
27
+ * - radical is an integer
28
+ */
29
+ constructor(value: number | bigint | ExactNumericValueData, factory: NumericValueFactory, bignum: BigNumFactory);
30
+ get type(): NumericType;
31
+ get isExact(): boolean;
32
+ get asExact(): NumericValue | undefined;
33
+ toJSON(): Expression;
34
+ clone(value: number | ExactNumericValueData): ExactNumericValue;
35
+ /** Object.toString() */
36
+ toString(): string;
37
+ get sign(): -1 | 0 | 1;
38
+ get re(): number;
39
+ get bignumRe(): Decimal;
40
+ get numerator(): ExactNumericValue;
41
+ get denominator(): ExactNumericValue;
42
+ normalize(): void;
43
+ get isNaN(): boolean;
44
+ get isPositiveInfinity(): boolean;
45
+ get isNegativeInfinity(): boolean;
46
+ get isComplexInfinity(): boolean;
47
+ get isZero(): boolean;
48
+ get isOne(): boolean;
49
+ get isNegativeOne(): boolean;
50
+ sgn(): -1 | 0 | 1 | undefined;
51
+ N(): NumericValue;
52
+ neg(): ExactNumericValue;
53
+ inv(): NumericValue;
54
+ add(other: number | NumericValue): NumericValue;
55
+ sub(other: NumericValue): NumericValue;
56
+ mul(other: number | Decimal | NumericValue): NumericValue;
57
+ div(other: SmallInteger | NumericValue): NumericValue;
58
+ pow(exponent: number | NumericValue | {
59
+ re: number;
60
+ im: number;
61
+ }): NumericValue;
62
+ root(exponent: number): NumericValue;
63
+ sqrt(): NumericValue;
64
+ gcd(other: NumericValue): NumericValue;
65
+ abs(): NumericValue;
66
+ ln(base?: number): NumericValue;
67
+ exp(): NumericValue;
68
+ floor(): NumericValue;
69
+ ceil(): NumericValue;
70
+ round(): NumericValue;
71
+ eq(other: number | NumericValue): boolean;
72
+ lt(other: number | NumericValue): boolean | undefined;
73
+ lte(other: number | NumericValue): boolean | undefined;
74
+ gt(other: number | NumericValue): boolean | undefined;
75
+ gte(other: number | NumericValue): boolean | undefined;
76
+ static sum(values: NumericValue[], factory: NumericValueFactory, bignumFactory: BigNumFactory): NumericValue[];
77
+ }
@@ -0,0 +1,58 @@
1
+ /* 0.26.0 */
2
+ import { NumericValue, NumericValueData } from './public';
3
+ import type { Expression } from '../../math-json/types';
4
+ import { SmallInteger } from '../numerics/numeric';
5
+ import { NumericType } from '../../common/type/types';
6
+ import { BigNumFactory } from './big-numeric-value';
7
+ export declare class MachineNumericValue extends NumericValue {
8
+ __brand: 'MachineNumericValue';
9
+ decimal: number;
10
+ im: number;
11
+ bignum: BigNumFactory;
12
+ constructor(value: number | Decimal | NumericValueData, bignum: BigNumFactory);
13
+ private _makeExact;
14
+ get type(): NumericType;
15
+ get isExact(): boolean;
16
+ get asExact(): NumericValue | undefined;
17
+ toJSON(): Expression;
18
+ toString(): string;
19
+ clone(value: number | Decimal | NumericValueData): MachineNumericValue;
20
+ get re(): number;
21
+ get bignumRe(): Decimal | undefined;
22
+ get numerator(): MachineNumericValue;
23
+ get denominator(): NumericValue;
24
+ get isNaN(): boolean;
25
+ get isPositiveInfinity(): boolean;
26
+ get isNegativeInfinity(): boolean;
27
+ get isComplexInfinity(): boolean;
28
+ get isZero(): boolean;
29
+ isZeroWithTolerance(tolerance: number | Decimal): boolean;
30
+ get isOne(): boolean;
31
+ get isNegativeOne(): boolean;
32
+ sgn(): -1 | 0 | 1 | undefined;
33
+ N(): NumericValue;
34
+ neg(): NumericValue;
35
+ inv(): NumericValue;
36
+ add(other: number | NumericValue): NumericValue;
37
+ sub(other: NumericValue): NumericValue;
38
+ mul(other: number | Decimal | NumericValue): NumericValue;
39
+ div(other: SmallInteger | NumericValue): NumericValue;
40
+ pow(exponent: number | {
41
+ re: number;
42
+ im: number;
43
+ }): NumericValue;
44
+ root(exponent: number): NumericValue;
45
+ sqrt(): NumericValue;
46
+ gcd(other: NumericValue): NumericValue;
47
+ abs(): NumericValue;
48
+ ln(base?: number): NumericValue;
49
+ exp(): NumericValue;
50
+ floor(): NumericValue;
51
+ ceil(): NumericValue;
52
+ round(): NumericValue;
53
+ eq(other: number | NumericValue): boolean;
54
+ lt(other: number | NumericValue): boolean | undefined;
55
+ lte(other: number | NumericValue): boolean | undefined;
56
+ gt(other: number | NumericValue): boolean | undefined;
57
+ gte(other: number | NumericValue): boolean | undefined;
58
+ }
@@ -0,0 +1,110 @@
1
+ /* 0.26.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 { SmallInteger } from '../numerics/numeric';
28
+ import { Rational } from '../numerics/rationals';
29
+ import { NumericType } from '../../common/type/types';
30
+ /** The value is equal to `(decimal * rational * sqrt(radical)) + im * i` */
31
+ export type ExactNumericValueData = {
32
+ rational?: Rational;
33
+ radical?: number;
34
+ };
35
+ export type NumericValueData = {
36
+ re?: Decimal | number;
37
+ im?: number;
38
+ };
39
+ export type NumericValueFactory = (data: number | Decimal | NumericValueData) => NumericValue;
40
+ export declare abstract class NumericValue {
41
+ abstract get type(): NumericType;
42
+ /** True if numeric value is the product of a rational and the square root of an integer.
43
+ *
44
+ * This includes: 3/4√5, -2, √2, etc...
45
+ *
46
+ * But it doesn't include 0.5, 3.141592, etc...
47
+ *
48
+ */
49
+ abstract get isExact(): boolean;
50
+ /** If `isExact()`, returns an ExactNumericValue, otherwise returns undefined.
51
+ */
52
+ abstract get asExact(): NumericValue | undefined;
53
+ /** The real part of this numeric value.
54
+ *
55
+ * Can be negative, 0 or positive.
56
+ */
57
+ abstract get re(): number;
58
+ /** bignum version of .re, if available */
59
+ get bignumRe(): Decimal | undefined;
60
+ /** The imaginary part of this numeric value.
61
+ *
62
+ * Can be negative, zero or positive.
63
+ */
64
+ readonly im: number;
65
+ get bignumIm(): Decimal | undefined;
66
+ abstract get numerator(): NumericValue;
67
+ abstract get denominator(): NumericValue;
68
+ abstract get isNaN(): boolean;
69
+ abstract get isPositiveInfinity(): boolean;
70
+ abstract get isNegativeInfinity(): boolean;
71
+ abstract get isComplexInfinity(): boolean;
72
+ abstract get isZero(): boolean;
73
+ isZeroWithTolerance(_tolerance: number | Decimal): boolean;
74
+ abstract get isOne(): boolean;
75
+ abstract get isNegativeOne(): boolean;
76
+ /** The sign of complex numbers is undefined */
77
+ abstract sgn(): -1 | 0 | 1 | undefined;
78
+ abstract N(): NumericValue;
79
+ abstract neg(): NumericValue;
80
+ abstract inv(): NumericValue;
81
+ abstract add(other: number | NumericValue): NumericValue;
82
+ abstract sub(other: NumericValue): NumericValue;
83
+ abstract mul(other: number | Decimal | NumericValue): NumericValue;
84
+ abstract div(other: SmallInteger | NumericValue): NumericValue;
85
+ abstract pow(n: number | NumericValue | {
86
+ re: number;
87
+ im: number;
88
+ }): NumericValue;
89
+ abstract root(n: number): NumericValue;
90
+ abstract sqrt(): NumericValue;
91
+ abstract gcd(other: NumericValue): NumericValue;
92
+ abstract abs(): NumericValue;
93
+ abstract ln(base?: number): NumericValue;
94
+ abstract exp(): NumericValue;
95
+ abstract floor(): NumericValue;
96
+ abstract ceil(): NumericValue;
97
+ abstract round(): NumericValue;
98
+ abstract eq(other: number | NumericValue): boolean;
99
+ abstract lt(other: number | NumericValue): boolean | undefined;
100
+ abstract lte(other: number | NumericValue): boolean | undefined;
101
+ abstract gt(other: number | NumericValue): boolean | undefined;
102
+ abstract gte(other: number | NumericValue): boolean | undefined;
103
+ /** Object.valueOf(): returns a primitive value */
104
+ valueOf(): number | string;
105
+ /** Object.toPrimitive() */
106
+ [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): number | string | null;
107
+ /** Object.toJSON */
108
+ toJSON(): any;
109
+ print(): void;
110
+ }
@@ -0,0 +1,2 @@
1
+ /* 0.26.0 */
2
+ export declare function bigint(a: Decimal | number | bigint | string): bigint | null;
@@ -0,0 +1,12 @@
1
+ /* 0.26.0 */
2
+ export type BigNum = Decimal;
3
+ export interface IBigNum {
4
+ readonly _BIGNUM_NAN: BigNum;
5
+ readonly _BIGNUM_ZERO: BigNum;
6
+ readonly _BIGNUM_ONE: BigNum;
7
+ readonly _BIGNUM_TWO: BigNum;
8
+ readonly _BIGNUM_HALF: BigNum;
9
+ readonly _BIGNUM_PI: BigNum;
10
+ readonly _BIGNUM_NEGATIVE_ONE: BigNum;
11
+ bignum(value: string | number | bigint | BigNum): BigNum;
12
+ }
@@ -0,0 +1,4 @@
1
+ /* 0.26.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): Expression;
@@ -0,0 +1,12 @@
1
+ /* 0.26.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,19 @@
1
+ /* 0.26.0 */
2
+ * Return a numerical approximation of the integral
3
+ * of the function `f` from `a` to `b` using Monte Carlo integration.
4
+ *
5
+ * Thoughts for future improvements:
6
+ * - use a MISER algorithm to improve the accuracy
7
+ * - use a stratified sampling to improve the accuracy
8
+ * - use a quasi-Monte Carlo method to improve the accuracy
9
+ * - use a Markov Chain Monte Carlo method to improve the accuracy
10
+ * - use a Metropolis-Hastings algorithm to improve the accuracy
11
+ * - use a Hamiltonian Monte Carlo algorithm to improve the accuracy
12
+ * - use a Gibbs sampling algorithm to improve the accuracy
13
+ *
14
+ *
15
+ * See:
16
+ * - https://64.github.io/monte-carlo/
17
+ *
18
+ */
19
+ export declare function monteCarloEstimate(f: (x: number) => number, a: number, b: number, n?: number): number;
@@ -1,20 +1,10 @@
1
- /* 0.25.0 */
2
- import { Expression } from '../../math-json';
3
- export declare function bigintValue(expr: Expression | null | undefined): bigint | null;
4
- export declare function bigint(a: Decimal | number | bigint | string): bigint;
5
- export declare function gcd(a: bigint, b: bigint): bigint;
1
+ /* 0.26.0 */
6
2
  export declare function lcm(a: bigint, b: bigint): bigint;
7
- export declare function primeFactors(d: bigint): Map<bigint, number>;
8
3
  /** Return `[factor, root]` such that
9
4
  * pow(n, 1/exponent) = factor * pow(root, 1/exponent)
10
5
  *
11
- * factorPower(75, 2) -> [5, 3] = 5^2 * 3
6
+ * canonicalInteger(75, 2) -> [5, 3] = 5^2 * 3
12
7
  *
13
8
  */
14
- export declare function factorPower(n: bigint, exponent: number): [factor: bigint, root: bigint];
15
- /**
16
- * Return a, b, c such that n = a * b^c
17
- * @param n
18
- *
19
- */
20
- export declare function canonicalInteger(n: bigint): [a: bigint, b: bigint, c: bigint];
9
+ export declare function canonicalInteger(n: bigint, exponent: number): [factor: bigint, root: bigint];
10
+ export declare function reducedInteger(n: bigint): bigint | number;
@@ -1,13 +1,10 @@
1
- /* 0.25.0 */
2
- import { IComputeEngine } from '../public';
3
- export declare function gcd(a: Decimal, b: Decimal): Decimal;
4
- export declare function lcm(a: Decimal, b: Decimal): Decimal;
5
- export declare function factorial(ce: IComputeEngine, n: Decimal): Decimal;
6
- export declare function factorial2(ce: IComputeEngine, n: Decimal): Decimal;
7
- export declare function gammaln(ce: IComputeEngine, z: Decimal): Decimal;
8
- export declare function gamma(ce: IComputeEngine, z: Decimal): Decimal;
1
+ /* 0.26.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 factorial(ce: IBigNum, n: BigNum): BigNum;
5
+ export declare function factorial2(ce: IBigNum, n: BigNum): BigNum;
9
6
  /**
10
7
  * If the exponent of the bignum is in the range of the exponents
11
8
  * for machine numbers,return true.
12
9
  */
13
- export declare function isInMachineRange(d: Decimal): boolean;
10
+ export declare function isInMachineRange(d: BigNum): boolean;
@@ -1,3 +1,3 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  export declare function gamma(c: Complex): Complex;
3
3
  export declare function gammaln(c: Complex): Complex;
@@ -1,11 +1,13 @@
1
- /* 0.25.0 */
2
- import { Decimal } from 'decimal.js';
1
+ /* 0.26.0 */
3
2
  export declare const MACHINE_PRECISION_BITS = 53;
4
3
  export declare const MACHINE_PRECISION: number;
5
4
  export declare const MACHINE_TOLERANCE_BITS = 7;
6
5
  export declare const MACHINE_TOLERANCE: number;
7
- export declare const NUMERIC_TOLERANCE: number;
8
6
  export declare const SMALL_INTEGER = 1000000;
7
+ type IsInteger<N extends number> = `${N}` extends `${string}.${string}` ? never : `${N}` extends `-${string}.${string}` ? never : number;
8
+ export type SmallInteger = IsInteger<number>;
9
+ /** The largest number of digits of a bigint */
10
+ export declare const MAX_BIGINT_DIGITS = 1024;
9
11
  export declare const MAX_ITERATION = 1000000;
10
12
  export declare const MAX_SYMBOLIC_TERMS = 200;
11
13
  /**
@@ -14,50 +16,18 @@ export declare const MAX_SYMBOLIC_TERMS = 200;
14
16
  */
15
17
  export declare function nextUp(x: number): number;
16
18
  export declare function nextDown(x: number): number;
17
- /**
18
- * Return a, b, c such that n = a * b^c
19
- * @param n
20
- *
21
- */
22
- export declare function canonicalInteger(n: number): [a: number, b: number, c: number];
23
19
  /** Return `[factor, root]` such that
24
20
  * pow(n, 1/exponent) = factor * pow(root, 1/exponent)
25
21
  *
26
- * factorPower(75, 2) -> [5, 3] = 5^2 * 3
22
+ * canonicalInteger(75, 2) -> [5, 3] = 5^2 * 3
27
23
  *
28
24
  */
29
- export declare function factorPower(n: number, exponent: number): [factor: number, root: number];
25
+ export declare function canonicalInteger(n: number, exponent: number): readonly [factor: number, root: number];
30
26
  export declare function gcd(a: number, b: number): number;
31
27
  export declare function lcm(a: number, b: number): number;
32
28
  export declare function factorial(n: number): number;
33
29
  export declare function factorial2(n: number): number;
34
- export declare function gammaln(z: number): number;
35
- export declare function gamma(z: number): number;
36
- export declare function chop(n: number, tolerance: number): number;
37
- export declare function chop(n: Decimal, tolerance: number): 0 | Decimal;
38
- export declare function chop(n: Complex, tolerance: number): 0 | Complex;
39
- /**
40
- * An approximation of the gaussian error function, Erf(), using
41
- * Abramowitz and Stegun approximation.
42
- *
43
- * Thoughts for future improvements:
44
- * - https://math.stackexchange.com/questions/321569/approximating-the-error-function-erf-by-analytical-functions
45
- * - https://en.wikipedia.org/wiki/Error_function#Approximation_with_elementary_functions
46
-
47
- *
48
- * References:
49
- * - NIST: https://dlmf.nist.gov/7.24#i
50
- */
51
- export declare function erf(x: number): number;
52
- /**
53
- * Trivial function, used when compiling.
54
- */
55
- export declare function erfc(x: number): number;
56
- /**
57
- * Inverse Error Function.
58
- *
59
- */
60
- export declare function erfInv(x: number): number;
30
+ export declare function chop(n: number, tolerance?: number): 0 | number;
61
31
  /**
62
32
  * An 8th-order centered difference approximation can be used to get a highly
63
33
  * accurate approximation of the first derivative of a function.
@@ -77,25 +47,6 @@ export declare function erfInv(x: number): number;
77
47
  * See https://en.wikipedia.org/wiki/Finite_difference_coefficient
78
48
  */
79
49
  export declare function centeredDiff8thOrder(f: (number: any) => number, x: number, h?: number): number;
80
- /**
81
- * Return a numerical approximation of the integral
82
- * of the function `f` from `a` to `b` using Monte Carlo integration.
83
- *
84
- * Thoughts for future improvements:
85
- * - use a MISER algorithm to improve the accuracy
86
- * - use a stratified sampling to improve the accuracy
87
- * - use a quasi-Monte Carlo method to improve the accuracy
88
- * - use a Markov Chain Monte Carlo method to improve the accuracy
89
- * - use a Metropolis-Hastings algorithm to improve the accuracy
90
- * - use a Hamiltonian Monte Carlo algorithm to improve the accuracy
91
- * - use a Gibbs sampling algorithm to improve the accuracy
92
- *
93
- *
94
- * See:
95
- * - https://64.github.io/monte-carlo/
96
- *
97
- */
98
- export declare function monteCarloEstimate(f: (x: number) => number, a: number, b: number, n?: number): number;
99
50
  /**
100
51
  *
101
52
  * @param f
@@ -104,5 +55,4 @@ export declare function monteCarloEstimate(f: (x: number) => number, a: number,
104
55
  * @returns
105
56
  */
106
57
  export declare function limit(f: (x: number) => number, x: number, dir?: number): number;
107
- export declare function fromRoman(roman: string): [result: number, rest: string];
108
- export declare function fromDigits(s: string, baseInput?: string | number): [result: number, rest: string];
58
+ export {};
@@ -1,7 +1,7 @@
1
- /* 0.25.0 */
2
- export declare const SMALL_PRIMES: Set<number>;
3
- export declare const LARGEST_SMALL_PRIME = 7919;
1
+ /* 0.26.0 */
4
2
  export declare function primeFactors(n: number): {
5
3
  [factor: number]: number;
6
4
  };
7
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>;
@@ -1,31 +1,47 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
+ /**
2
3
  * @category Boxed Expression
3
4
  */
4
- export type Rational = [number, number] | [bigint, bigint];
5
+ export type Rational = [SmallInteger, SmallInteger] | [bigint, bigint];
5
6
  export declare function isRational(x: any | null): x is Rational;
6
- export declare function isMachineRational(x: any | null): x is [number, number];
7
+ export declare function isMachineRational(x: any | null): x is [SmallInteger, SmallInteger];
7
8
  export declare function isBigRational(x: any | null): x is [bigint, bigint];
8
- export declare function isRationalZero(x: Rational): boolean;
9
- export declare function isRationalOne(x: Rational): boolean;
10
- export declare function isRationalInteger(x: Rational): boolean;
11
- export declare function isRationalNegativeOne(x: Rational): boolean;
9
+ export declare function isZero(x: Rational): boolean;
10
+ export declare function isPositive(x: Rational): boolean;
11
+ export declare function isOne(x: Rational): boolean;
12
+ export declare function isNegativeOne(x: Rational): boolean;
13
+ export declare function isInteger(x: Rational): boolean;
12
14
  export declare function machineNumerator(x: Rational): number;
13
15
  export declare function machineDenominator(x: Rational): number;
16
+ export declare function rationalAsFloat(x: Rational): number;
14
17
  export declare function isNeg(x: Rational): boolean;
15
- export declare function neg(x: [number, number]): [number, number];
18
+ export declare function div(lhs: Rational, rhs: Rational): Rational;
19
+ /**
20
+ * Add a literal numeric value to a rational.
21
+ * If the rational is a bigint, this is a hint to do the calculation in bigint
22
+ * (no need to check `bignumPreferred()`).
23
+ * @param lhs
24
+ * @param rhs
25
+ * @returns
26
+ */
27
+ export declare function add(lhs: Rational, rhs: Rational): Rational;
28
+ export declare function mul(lhs: Rational, rhs: Rational): Rational;
29
+ export declare function neg(x: [SmallInteger, SmallInteger]): [SmallInteger, SmallInteger];
16
30
  export declare function neg(x: [bigint, bigint]): [bigint, bigint];
17
31
  export declare function neg(x: Rational): Rational;
18
- export declare function inverse(x: [number, number]): [number, number];
32
+ export declare function inverse(x: [SmallInteger, SmallInteger]): [SmallInteger, SmallInteger];
19
33
  export declare function inverse(x: [bigint, bigint]): [bigint, bigint];
20
34
  export declare function inverse(x: Rational): Rational;
21
- export declare function pow(r: Rational, exp: number): Rational;
35
+ export declare function asMachineRational(r: Rational): [SmallInteger, SmallInteger];
36
+ export declare function pow(r: Rational, exp: SmallInteger): Rational;
22
37
  export declare function sqrt(r: Rational): Rational | undefined;
23
- export declare function reducedRational(r: [number, number]): [number, number];
38
+ export declare function rationalGcd(lhs: Rational, rhs: Rational): Rational;
39
+ export declare function reducedRational(r: [SmallInteger, SmallInteger]): [SmallInteger, SmallInteger];
24
40
  export declare function reducedRational(r: [bigint, bigint]): [bigint, bigint];
25
41
  export declare function reducedRational(r: Rational): Rational;
26
42
  /** Return a rational approximation of x */
27
43
  export declare function rationalize(x: number): [n: number, d: number] | number;
28
- /** Return [factor, root] such that factor * sqrt(root) = n
44
+ /** Return [factor, root] such that factor * sqrt(root) = sqrt(n)
29
45
  * when factor and root are rationals
30
46
  */
31
- export declare function reduceRationalSquareRoot(n: Rational): [factor: Rational, root: Rational];
47
+ export declare function reduceRationalSquareRoot(n: Rational): [factor: Rational, root: number | bigint];
@@ -1,4 +1,4 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
 
3
3
  Translated from https://github.com/JuliaMath/Richardson.jl/blob/master/src/Richardson.jl
4
4
 
@@ -0,0 +1,28 @@
1
+ /* 0.26.0 */
2
+ import { BigNum } from './bignum';
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: IComputeEngine, z: BigNum): BigNum;
28
+ export declare function bigGamma(ce: IComputeEngine, z: BigNum): BigNum;
@@ -0,0 +1,2 @@
1
+ /* 0.26.0 */
2
+ export declare function numberToString(num: number | bigint): string;
@@ -1,4 +1,4 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  *
3
3
  * The Compute Engine is a symbolic computation engine that can be used to
4
4
  * manipulate and evaluate mathematical expressions.
@@ -12,7 +12,8 @@
12
12
  * @module "compute-engine"
13
13
  *
14
14
  */
15
- import { FunctionDefinition, SemiBoxedExpression, SymbolDefinition } from './boxed-expression/public';
15
+ import type { OneOf } from '../common/one-of';
16
+ import type { FunctionDefinition, SemiBoxedExpression, SymbolDefinition } from './boxed-expression/public';
16
17
  export * from './boxed-expression/public';
17
18
  /**
18
19
  * A table mapping identifiers to their definition.
@@ -24,11 +25,14 @@ export * from './boxed-expression/public';
24
25
  * - The first character should be a letter: `/^[a-zA-Z]/`
25
26
  * - Functions and symbols exported from a library should start with an uppercase letter `/^[A-Z]/`
26
27
  *
27
- * If a semi boxed expression
28
28
  * @category Definitions
29
29
  *
30
30
  */
31
- export type IdentifierDefinition = SymbolDefinition | FunctionDefinition | SemiBoxedExpression;
31
+ export type IdentifierDefinition = OneOf<[
32
+ SymbolDefinition,
33
+ FunctionDefinition,
34
+ SemiBoxedExpression
35
+ ]>;
32
36
  /**
33
37
  * @category Definitions
34
38
  *
@@ -1,4 +1,4 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  /**
3
3
  *
4
4
  * @param fn The function to differentiate, a `["Function"]` expression or
@@ -8,7 +8,7 @@
8
8
  * @returns a function expression representing the derivative of `fn` with
9
9
  * respect to the variables in `degrees`.
10
10
  */
11
- export declare function differentiateFunction(fn: BoxedExpression, degrees: number[]): BoxedExpression | undefined;
11
+ export declare function derivative(fn: BoxedExpression, order: number): BoxedExpression | undefined;
12
12
  /**
13
13
  * Calculate the partial derivative of an expression with respect to a
14
14
  * variable, `v`.
@@ -0,0 +1,5 @@
1
+ /* 0.26.0 */
2
+ /**
3
+ *
4
+ */
5
+ export declare function distribute(expr: BoxedExpression, g?: string, f?: string): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.25.0 */
1
+ /* 0.26.0 */
2
2
  /**
3
3
  * @todo: a set to "tidy" an expression. Different from a canonical form, but
4
4
  * inline with the user's expectations.
@@ -1,5 +1,5 @@
1
- /* 0.25.0 */
2
- import { DataTypeMap, TensorDataType, TensorField } from './tensor-fields';
1
+ /* 0.26.0 */
2
+ import { DataTypeMap, TensorDataType, TensorField } from '../boxed-expression/tensor-fields';
3
3
  /**
4
4
  * @noInheritDoc
5
5
  */
@@ -99,7 +99,7 @@ export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> imple
99
99
  equals(rhs: AbstractTensor<DT>): boolean;
100
100
  }
101
101
  export declare function makeTensor<T extends TensorDataType>(ce: IComputeEngine, data: TensorData<T> | {
102
- head: string;
102
+ operator: string;
103
103
  ops: BoxedExpression[];
104
104
  dtype: T;
105
105
  shape: number[];