@cortex-js/compute-engine 0.29.0 → 0.30.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 (150) hide show
  1. package/dist/compute-engine.esm.js +28330 -24627
  2. package/dist/compute-engine.min.esm.js +70 -68
  3. package/dist/compute-engine.min.umd.js +131 -0
  4. package/dist/{compute-engine.cjs → compute-engine.umd.js} +28330 -24627
  5. package/dist/math-json.esm.js +22 -294
  6. package/dist/math-json.min.esm.js +22 -294
  7. package/dist/math-json.min.umd.js +4 -0
  8. package/dist/math-json.umd.js +141 -0
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +28 -0
  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 +1 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/boxed-type.d.ts +20 -4
  17. package/dist/types/common/type/parse.d.ts +4 -4
  18. package/dist/types/common/type/primitive.d.ts +3 -2
  19. package/dist/types/common/type/serialize.d.ts +1 -1
  20. package/dist/types/common/type/subtype.d.ts +1 -1
  21. package/dist/types/common/type/types.d.ts +91 -25
  22. package/dist/types/common/type/utils.d.ts +2 -1
  23. package/dist/types/common/utils.d.ts +1 -1
  24. package/dist/types/compute-engine/assume.d.ts +2 -2
  25. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +72 -73
  26. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +2 -2
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +19 -1
  30. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/box.d.ts +6 -6
  32. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +42 -0
  33. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +48 -27
  34. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +17 -5
  35. package/dist/types/compute-engine/boxed-expression/{boxed-function-definition.d.ts → boxed-operator-definition.d.ts} +12 -12
  36. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +7 -8
  38. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +91 -52
  39. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +22 -25
  40. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
  41. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
  43. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -2
  44. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  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 +1 -1
  48. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/hold.d.ts +2 -2
  50. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +30 -3
  53. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/product.d.ts +2 -2
  56. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +41 -1
  59. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/solve.d.ts +3 -1
  61. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/utils.d.ts +23 -23
  64. package/dist/types/compute-engine/boxed-expression/validate.d.ts +2 -1
  65. package/dist/types/compute-engine/collection-utils.d.ts +22 -57
  66. package/dist/types/compute-engine/compile.d.ts +61 -10
  67. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  68. package/dist/types/compute-engine/function-utils.d.ts +46 -29
  69. package/dist/types/compute-engine/global-types.d.ts +1432 -893
  70. package/dist/types/compute-engine/index.d.ts +154 -124
  71. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  72. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +3 -3
  85. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  86. package/dist/types/compute-engine/latex-syntax/parse.d.ts +14 -12
  87. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  88. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  89. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  90. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/types.d.ts +51 -39
  92. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  93. package/dist/types/compute-engine/library/arithmetic.d.ts +2 -2
  94. package/dist/types/compute-engine/library/calculus.d.ts +2 -2
  95. package/dist/types/compute-engine/library/collections.d.ts +3 -3
  96. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  97. package/dist/types/compute-engine/library/complex.d.ts +2 -2
  98. package/dist/types/compute-engine/library/control-structures.d.ts +2 -2
  99. package/dist/types/compute-engine/library/core.d.ts +2 -2
  100. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  101. package/dist/types/compute-engine/library/library.d.ts +5 -5
  102. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -2
  103. package/dist/types/compute-engine/library/logic.d.ts +2 -2
  104. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  105. package/dist/types/compute-engine/library/polynomials.d.ts +2 -2
  106. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  107. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -2
  108. package/dist/types/compute-engine/library/sets.d.ts +2 -2
  109. package/dist/types/compute-engine/library/statistics.d.ts +2 -2
  110. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -2
  111. package/dist/types/compute-engine/library/utils.d.ts +24 -2
  112. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +3 -4
  113. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +3 -3
  114. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +3 -4
  115. package/dist/types/compute-engine/numeric-value/types.d.ts +7 -5
  116. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  117. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  118. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  119. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -19
  120. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  121. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -1
  124. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  125. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  129. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  130. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  131. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  132. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -4
  133. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  134. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  135. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +5 -46
  136. package/dist/types/compute-engine/tensor/tensors.d.ts +4 -14
  137. package/dist/types/compute-engine/types.d.ts +2 -5
  138. package/dist/types/compute-engine.d.ts +1 -1
  139. package/dist/types/math-json/symbols.d.ts +11 -0
  140. package/dist/types/math-json/types.d.ts +19 -11
  141. package/dist/types/math-json/utils.d.ts +18 -9
  142. package/dist/types/math-json.d.ts +2 -2
  143. package/package.json +9 -11
  144. package/dist/compute-engine.min.cjs +0 -129
  145. package/dist/math-json.cjs +0 -413
  146. package/dist/math-json.min.cjs +0 -6
  147. package/dist/types/common/json5.d.ts +0 -3
  148. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +0 -64
  149. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +0 -21
  150. package/dist/types/math-json/identifiers.d.ts +0 -11
@@ -1,19 +1,4 @@
1
- /* 0.29.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
+ /* 0.30.0 */
2
+ estimate: number;
3
+ error: number;
4
+ };
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export declare function lcm(a: bigint, b: bigint): bigint;
3
3
  /** Return `[factor, root]` such that
4
4
  * pow(n, 1/exponent) = factor * pow(root, 1/exponent)
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.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.29.0 */
1
+ /* 0.30.0 */
2
2
  export declare function gamma(c: Complex): Complex;
3
3
  export declare function gammaln(c: Complex): Complex;
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.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;
@@ -50,3 +50,11 @@ export declare function centeredDiff8thOrder(f: (number: any) => number, x: numb
50
50
  * @returns
51
51
  */
52
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>;
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export declare function primeFactors(n: number): {
3
3
  [factor: number]: number;
4
4
  };
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.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.29.0 */
1
+ /* 0.30.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.29.0 */
1
+ /* 0.30.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.29.0 */
1
+ /* 0.30.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.29.0 */
1
+ /* 0.30.0 */
2
2
  export declare function numberToString(num: number | bigint, fractionalDigits?: number | string): string;
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  type IsInteger<N extends number> = `${N}` extends `${string}.${string}` ? never : `${N}` extends `-${string}.${string}` ? never : number;
3
3
  /** A `SmallInteger` is an integer < 1e6
4
4
  * @category Numerics
@@ -0,0 +1,3 @@
1
+ /* 0.30.0 */
2
+ /** Calculate the antiderivative of fn, as an expression (not a function) */
3
+ export declare function antiderivative(fn: BoxedExpression, index: string): BoxedExpression;
@@ -1,10 +1,8 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  /**
3
3
  *
4
- * @param fn The function to differentiate, a `["Function"]` expression or
5
- * an identifier for a function name.
4
+ * @param fn The function to differentiate, a function literal.
6
5
  *
7
- * @param degrees
8
6
  * @returns a function expression representing the derivative of `fn` with
9
7
  * respect to the variables in `degrees`.
10
8
  */
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  /**
3
3
  *
4
4
  */
@@ -1,4 +1,4 @@
1
- /* 0.29.0 */
1
+ /* 0.30.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,46 +1,8 @@
1
- /* 0.29.0 */
2
- import { BoxedExpression, ComputeEngine, DataTypeMap, TensorDataType } from '../global-types';
1
+ /* 0.30.0 */
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]>;
5
5
  /** @category Tensors */
6
- export interface TensorField<T extends number | Complex | BoxedExpression | boolean | string = number> {
7
- readonly one: T;
8
- readonly zero: T;
9
- readonly nan: T;
10
- cast(x: T, dtype: 'float64'): undefined | number;
11
- cast(x: T, dtype: 'float32'): undefined | number;
12
- cast(x: T, dtype: 'int32'): undefined | number;
13
- cast(x: T, dtype: 'uint8'): undefined | number;
14
- cast(x: T, dtype: 'complex128'): undefined | Complex;
15
- cast(x: T, dtype: 'complex64'): undefined | Complex;
16
- cast(x: T, dtype: 'bool'): undefined | boolean;
17
- cast(x: T, dtype: 'string'): undefined | string;
18
- cast(x: T, dtype: 'expression'): undefined | BoxedExpression;
19
- cast(x: T[], dtype: 'float64'): undefined | number[];
20
- cast(x: T[], dtype: 'float32'): undefined | number[];
21
- cast(x: T[], dtype: 'int32'): undefined | number[];
22
- cast(x: T[], dtype: 'uint8'): undefined | number[];
23
- cast(x: T[], dtype: 'complex128'): undefined | Complex[];
24
- cast(x: T[], dtype: 'complex64'): undefined | Complex[];
25
- cast(x: T[], dtype: 'bool'): undefined | boolean[];
26
- cast(x: T[], dtype: 'string'): undefined | string[];
27
- cast(x: T[], dtype: 'expression'): undefined | BoxedExpression[];
28
- cast(x: T | T[], dtype: TensorDataType): undefined | Complex | number | boolean | string | BoxedExpression | Complex[] | number[] | boolean[] | string[] | BoxedExpression[];
29
- expression(x: T): BoxedExpression;
30
- isZero(x: T): boolean;
31
- isOne(x: T): boolean;
32
- equals(lhs: T, rhs: T): boolean;
33
- add(lhs: T, rhs: T): T;
34
- addn(...xs: T[]): T;
35
- neg(x: T): T;
36
- sub(lhs: T, rhs: T): T;
37
- mul(lhs: T, rhs: T): T;
38
- muln(...xs: T[]): T;
39
- div(lhs: T, rhs: T): T;
40
- pow(rhs: T, n: number): T;
41
- conjugate(x: T): T;
42
- }
43
- /** @category Tensors */
44
6
  export declare class TensorFieldNumber implements TensorField<number> {
45
7
  private ce;
46
8
  one: number;
@@ -54,7 +16,6 @@ export declare class TensorFieldNumber implements TensorField<number> {
54
16
  cast(x: number, dtype: 'complex128'): undefined | Complex;
55
17
  cast(x: number, dtype: 'complex64'): undefined | Complex;
56
18
  cast(x: number, dtype: 'bool'): undefined | boolean;
57
- cast(x: number, dtype: 'string'): undefined | string;
58
19
  cast(x: number, dtype: 'expression'): undefined | BoxedExpression;
59
20
  cast(x: number[], dtype: 'float64'): undefined | number[];
60
21
  cast(x: number[], dtype: 'float32'): undefined | number[];
@@ -63,7 +24,6 @@ export declare class TensorFieldNumber implements TensorField<number> {
63
24
  cast(x: number[], dtype: 'complex128'): undefined | Complex[];
64
25
  cast(x: number[], dtype: 'complex64'): undefined | Complex[];
65
26
  cast(x: number[], dtype: 'bool'): undefined | boolean[];
66
- cast(x: number[], dtype: 'string'): undefined | string[];
67
27
  cast(x: number[], dtype: 'expression'): undefined | BoxedExpression[];
68
28
  expression(x: number): BoxedExpression;
69
29
  isZero(x: number): boolean;
@@ -93,7 +53,6 @@ export declare class TensorFieldExpression implements TensorField<BoxedExpressio
93
53
  cast(x: BoxedExpression, dtype: 'complex128'): undefined | Complex;
94
54
  cast(x: BoxedExpression, dtype: 'complex64'): undefined | Complex;
95
55
  cast(x: BoxedExpression, dtype: 'bool'): undefined | boolean;
96
- cast(x: BoxedExpression, dtype: 'string'): undefined | string;
97
56
  cast(x: BoxedExpression, dtype: 'expression'): undefined | BoxedExpression;
98
57
  cast(x: BoxedExpression[], dtype: 'float64'): undefined | number[];
99
58
  cast(x: BoxedExpression[], dtype: 'float32'): undefined | number[];
@@ -102,7 +61,6 @@ export declare class TensorFieldExpression implements TensorField<BoxedExpressio
102
61
  cast(x: BoxedExpression[], dtype: 'complex128'): undefined | Complex[];
103
62
  cast(x: BoxedExpression[], dtype: 'complex64'): undefined | Complex[];
104
63
  cast(x: BoxedExpression[], dtype: 'bool'): undefined | boolean[];
105
- cast(x: BoxedExpression[], dtype: 'string'): undefined | string[];
106
64
  cast(x: BoxedExpression[], dtype: 'expression'): undefined | BoxedExpression[];
107
65
  expression(x: BoxedExpression): BoxedExpression;
108
66
  isZero(x: BoxedExpression): boolean;
@@ -132,7 +90,6 @@ export declare class TensorFieldComplex implements TensorField<Complex> {
132
90
  cast(x: Complex, dtype: 'complex128'): undefined | Complex;
133
91
  cast(x: Complex, dtype: 'complex64'): undefined | Complex;
134
92
  cast(x: Complex, dtype: 'bool'): undefined | boolean;
135
- cast(x: Complex, dtype: 'string'): undefined | string;
136
93
  cast(x: Complex, dtype: 'expression'): undefined | BoxedExpression;
137
94
  cast(x: Complex[], dtype: 'float64'): undefined | number[];
138
95
  cast(x: Complex[], dtype: 'float32'): undefined | number[];
@@ -141,7 +98,6 @@ export declare class TensorFieldComplex implements TensorField<Complex> {
141
98
  cast(x: Complex[], dtype: 'complex128'): undefined | Complex[];
142
99
  cast(x: Complex[], dtype: 'complex64'): undefined | Complex[];
143
100
  cast(x: Complex[], dtype: 'bool'): undefined | boolean[];
144
- cast(x: Complex[], dtype: 'string'): undefined | string[];
145
101
  cast(x: Complex[], dtype: 'expression'): undefined | BoxedExpression[];
146
102
  expression(z: Complex): BoxedExpression;
147
103
  isZero(z: Complex): boolean;
@@ -163,6 +119,9 @@ export declare class TensorFieldComplex implements TensorField<Complex> {
163
119
  */
164
120
  export declare function getSupertype(t1: TensorDataType | undefined, t2: TensorDataType): TensorDataType;
165
121
  /**
122
+ * If the expression is a literal number, return the datatype of the
123
+ * number (or boolean). Otherwise, return the `expression`.
124
+ *
166
125
  * @category Tensors
167
126
  * @internal
168
127
  */
@@ -1,11 +1,6 @@
1
- /* 0.29.0 */
2
- import type { BoxedExpression, ComputeEngine, DataTypeMap, TensorData, TensorDataType } from '../global-types';
3
- /** @internal */
4
- export type NestedArray<T> = NestedArray_<T>[];
5
- /** @internal */
6
- export type NestedArray_<T> = T | NestedArray_<T>[];
1
+ /* 0.30.0 */
7
2
  /** @category Tensors */
8
- export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> implements TensorData<DT> {
3
+ export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> implements Tensor<DT> {
9
4
  private ce;
10
5
  /**
11
6
  * Return a tuple of tensors that have the same dtype.
@@ -72,6 +67,7 @@ export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> imple
72
67
  * The data is reused (and shared) between the two tensors.
73
68
  */
74
69
  reshape(...shape: number[]): AbstractTensor<DT>;
70
+ slice(index: number): AbstractTensor<DT>;
75
71
  flatten(): DataTypeMap[DT][];
76
72
  upcast<DT extends keyof DataTypeMap>(dtype: DT): AbstractTensor<DT>;
77
73
  /** Transpose the first and second axis */
@@ -94,10 +90,4 @@ export declare abstract class AbstractTensor<DT extends keyof DataTypeMap> imple
94
90
  equals(rhs: AbstractTensor<DT>): boolean;
95
91
  }
96
92
  /** @category Tensors */
97
- export declare function makeTensor<T extends TensorDataType>(ce: ComputeEngine, data: TensorData<T> | {
98
- operator: string;
99
- ops: BoxedExpression[];
100
- dtype: T;
101
- shape: number[];
102
- }): AbstractTensor<T>;
103
- export { TensorData };
93
+ export declare function makeTensor<T extends TensorDataType>(ce: ComputeEngine, data: TensorData<T>): AbstractTensor<T>;
@@ -1,11 +1,8 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export * from '../math-json/types';
3
3
  export * from '../common/type/boxed-type';
4
4
  export * from '../common/type/types';
5
- export type { LatexString, SerializeLatexOptions, NumberSerializationFormat, DelimiterScale, NumberFormat, } from './latex-syntax/types';
6
- export * from './latex-syntax/dictionary/definitions';
5
+ export type * from './latex-syntax/types';
7
6
  export * from './numerics/types';
8
7
  export * from './numeric-value/types';
9
- export * from './tensor/tensors';
10
- export * from './tensor/tensor-fields';
11
8
  export * from './global-types';
@@ -1,3 +1,3 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export { ComputeEngine } from './compute-engine/index';
3
3
  export * from './compute-engine/types';
@@ -0,0 +1,11 @@
1
+ /* 0.30.0 */
2
+ * Return true if the string is a valid symbol.
3
+ *
4
+ * Check for symbols matching a profile of [Unicode UAX31](https://unicode.org/reports/tr31/)
5
+ *
6
+ * See https://cortexjs.io/math-json/#symbols for a full definition of the
7
+ * profile.
8
+ */
9
+ export declare function isValidSymbol(s: string): boolean;
10
+ export declare const EMOJIS: RegExp;
11
+ export declare function validateSymbol(s: unknown): 'valid' | 'not-a-string' | 'empty-string' | 'expected-nfc' | 'unexpected-mixed-emoji' | 'unexpected-bidi-marker' | 'unexpected-script' | 'invalid-first-char' | 'invalid-char';
@@ -1,4 +1,8 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
+ * The following properties can be added to any MathJSON expression
3
+ * to provide additional information about the expression.
4
+ *
5
+ * @category MathJSON */
2
6
  export type MathJsonAttributes = {
3
7
  /** A human readable string to annotate this expression, since JSON does not
4
8
  * allow comments in its encoding */
@@ -56,7 +60,7 @@ export type MathJsonAttributes = {
56
60
  sourceOffsets?: [start: number, end: number];
57
61
  };
58
62
  /** @category MathJSON */
59
- export type MathJsonIdentifier = string;
63
+ export type MathJsonSymbol = string;
60
64
  /**
61
65
  * A MathJSON numeric quantity.
62
66
  *
@@ -69,7 +73,7 @@ export type MathJsonIdentifier = string;
69
73
  * - an optional exponent part (a `e` or `E` exponent marker followed by an
70
74
  * optional `-` minus sign, followed by a string of digits)
71
75
  *
72
- * It can also consist of the value `NaN`, `-Infinity` and `+Infinity` to
76
+ * It can also consist of the string `NaN`, `-Infinity` or `+Infinity` to
73
77
  * represent these respective values.
74
78
  *
75
79
  * A MathJSON number may contain more digits or an exponent with a greater
@@ -82,25 +86,29 @@ export type MathJsonIdentifier = string;
82
86
  * - `123456789123456789.123(4567)e999`
83
87
  * @category MathJSON
84
88
  */
85
- export type MathJsonNumber = {
89
+ export type MathJsonNumberObject = {
86
90
  num: 'NaN' | '-Infinity' | '+Infinity' | string;
87
91
  } & MathJsonAttributes;
88
92
  /** @category MathJSON */
89
- export type MathJsonSymbol = {
90
- sym: MathJsonIdentifier;
93
+ export type MathJsonSymbolObject = {
94
+ sym: MathJsonSymbol;
91
95
  } & MathJsonAttributes;
92
96
  /** @category MathJSON */
93
- export type MathJsonString = {
97
+ export type MathJsonStringObject = {
94
98
  str: string;
95
99
  } & MathJsonAttributes;
96
100
  /** @category MathJSON */
97
- export type MathJsonFunction = {
98
- fn: [MathJsonIdentifier, ...Expression[]];
101
+ export type MathJsonFunctionObject = {
102
+ fn: [MathJsonSymbol, ...Expression[]];
103
+ } & MathJsonAttributes;
104
+ /** @category MathJSON */
105
+ export type MathJsonDictionaryObject = {
106
+ dict: Record<string, Expression>;
99
107
  } & MathJsonAttributes;
100
108
  /**
101
109
  * @category MathJSON
102
110
  */
103
- export type ExpressionObject = MathJsonNumber | MathJsonString | MathJsonSymbol | MathJsonFunction;
111
+ export type ExpressionObject = MathJsonNumberObject | MathJsonStringObject | MathJsonSymbolObject | MathJsonFunctionObject | MathJsonDictionaryObject;
104
112
  /**
105
113
  * A MathJSON expression is a recursive data structure.
106
114
  *
@@ -109,4 +117,4 @@ export type ExpressionObject = MathJsonNumber | MathJsonString | MathJsonSymbol
109
117
  *
110
118
  * @category MathJSON
111
119
  */
112
- export type Expression = ExpressionObject | number | MathJsonIdentifier | string | readonly [MathJsonIdentifier, ...Expression[]];
120
+ export type Expression = ExpressionObject | number | MathJsonSymbol | string | readonly [MathJsonSymbol, ...Expression[]];
@@ -1,10 +1,11 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export declare const MISSING: Expression;
3
- export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumber;
4
- export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumber;
5
- export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbol;
6
- export declare function isStringObject(expr: Expression | null): expr is MathJsonString;
7
- export declare function isFunctionObject(expr: Expression | null): expr is MathJsonFunction;
3
+ export declare function isNumberExpression(expr: Expression | null): expr is number | string | MathJsonNumberObject;
4
+ export declare function isNumberObject(expr: Expression | null): expr is MathJsonNumberObject;
5
+ export declare function isSymbolObject(expr: Expression | null): expr is MathJsonSymbolObject;
6
+ export declare function isStringObject(expr: Expression | null): expr is MathJsonStringObject;
7
+ export declare function isDictionaryObject(expr: Expression | null): expr is MathJsonDictionaryObject;
8
+ export declare function isFunctionObject(expr: Expression | null): expr is MathJsonFunctionObject;
8
9
  /** If expr is a string literal, return it.
9
10
  *
10
11
  * A string literal is a JSON string that begins and ends with
@@ -13,14 +14,14 @@ export declare function isFunctionObject(expr: Expression | null): expr is MathJ
13
14
  export declare function stringValue(expr: Expression | null | undefined): string | null;
14
15
  export declare function stripText(expr: Expression | null | undefined): Expression | null;
15
16
  /**
16
- * The operator of a function is an identifier
17
+ * The operator of a function is symbol.
17
18
  *
18
19
  * Return an empty string if the expression is not a function.
19
20
  *
20
21
  * Examples:
21
22
  * * `["Negate", 5]` -> `"Negate"`
22
23
  */
23
- export declare function operator(expr: Expression | null | undefined): MathJsonIdentifier;
24
+ export declare function operator(expr: Expression | null | undefined): MathJsonSymbol;
24
25
  /**
25
26
  * Return the arguments of a function, or an empty array if not a function
26
27
  * or no arguments.
@@ -31,7 +32,7 @@ export declare function operand(expr: Expression | null, n: 1 | 2 | 3): Expressi
31
32
  export declare function nops(expr: Expression | null | undefined): number;
32
33
  export declare function unhold(expr: Expression | null): Expression | null;
33
34
  export declare function symbol(expr: Expression | null | undefined): string | null;
34
- export declare function dictionaryFromExpression(expr: Expression | null): null | Record<string, Expression>;
35
+ export declare function dictionaryFromExpression(expr: Expression | null): null | MathJsonDictionaryObject;
35
36
  export declare function dictionaryFromEntries(dict: Record<string, Expression>): Expression;
36
37
  /**
37
38
  * CAUTION: `machineValue()` will return a truncated value if the number
@@ -51,6 +52,9 @@ export declare function machineValue(expr: Expression | null | undefined): numbe
51
52
  * The denominator is always > 0.
52
53
  */
53
54
  export declare function rationalValue(expr: Expression | undefined | null): [number, number] | null;
55
+ /**
56
+ * Apply a substitution to an expression.
57
+ */
54
58
  export declare function subs(expr: Expression, s: {
55
59
  [symbol: string]: Expression;
56
60
  }): Expression;
@@ -70,3 +74,8 @@ export declare function isEmptySequence(expr: Expression | null | undefined): ex
70
74
  export declare function missingIfEmpty(expr: Expression | null | undefined): Expression;
71
75
  /** The number of leaves (atomic expressions) in the expression */
72
76
  export declare function countLeaves(expr: Expression | null): number;
77
+ /** True if the string matches the expected pattern for a number */
78
+ export declare function matchesNumber(s: string): boolean;
79
+ /** True if the string matches the expected pattern for a symbol */
80
+ export declare function matchesSymbol(s: string): boolean;
81
+ export declare function matchesString(s: string): boolean;
@@ -1,3 +1,3 @@
1
- /* 0.29.0 */
1
+ /* 0.30.0 */
2
2
  export { isSymbolObject, isStringObject, isFunctionObject, stringValue, operator, operand, symbol, mapArgs, dictionaryFromExpression, } from './math-json/utils';
3
- export declare const version = "0.29.0";
3
+ export declare const version = "0.30.0";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.29.0",
2
+ "version": "0.30.0",
3
3
  "scripts": {
4
4
  "doc": "bash ./scripts/doc.sh",
5
5
  "build": "bash ./scripts/build.sh",
@@ -43,12 +43,10 @@
43
43
  "exports": {
44
44
  ".": {
45
45
  "types": "./dist/types/compute-engine.d.ts",
46
- "require": "./dist/compute-engine.min.cjs",
47
46
  "import": "./dist/compute-engine.min.esm.js",
48
- "default": "./dist/compute-engine.min.cjs"
47
+ "default": "./dist/compute-engine.min.esm.js"
49
48
  }
50
49
  },
51
- "main": "./dist/compute-engine.min.cjs",
52
50
  "module": "./dist/compute-engine.min.esm.js",
53
51
  "types": "./dist/types/compute-engine.d.ts",
54
52
  "engines": {
@@ -59,14 +57,14 @@
59
57
  "@cortex-js/prettier-config": "^1.2.0",
60
58
  "@jest/console": "^29.7.0",
61
59
  "@types/jest": "^29.5.5",
62
- "@types/node": "^20.6.3",
60
+ "@types/node": "^24.0.13",
63
61
  "@typescript-eslint/eslint-plugin": "^7.14.1",
64
62
  "@typescript-eslint/parser": "^7.14.1",
65
63
  "@typescript-eslint/typescript-estree": "^7.14.1",
66
64
  "chalk": "^5.3.0",
67
65
  "check-node-version": "^4.2.1",
68
66
  "concat-md": "^0.5.1",
69
- "esbuild": "^0.24.0",
67
+ "esbuild": "^0.25.6",
70
68
  "eslint": "^8.56.0",
71
69
  "eslint-config-prettier": "^9.0.0",
72
70
  "eslint-plugin-import": "^2.28.1",
@@ -74,21 +72,21 @@
74
72
  "eslint-plugin-prettier": "^5.0.0",
75
73
  "jest": "^29.7.0",
76
74
  "jest-silent-reporter": "^0.6.0",
77
- "open": "^10.1.0",
78
- "prettier": "^3.0.3",
75
+ "open": "^10.1.2",
76
+ "prettier": "^3.6.2",
79
77
  "prettier-2": "npm:prettier@^2",
80
78
  "serve-http": "^1.0.7",
81
- "ts-jest": "^29.1.1",
79
+ "ts-jest": "^29.4.0",
82
80
  "ts-node": "^10.9.1",
83
81
  "typedoc": "^0.27.6",
84
82
  "typedoc-plugin-markdown": "^4.4.1",
85
83
  "typedoc-plugin-no-inherit": "^1.5.0",
86
- "typescript": "^5.2.2",
84
+ "typescript": "^5.8.3",
87
85
  "update-notifier": "^7.0.0"
88
86
  },
89
87
  "prettier": "@cortex-js/prettier-config",
90
88
  "dependencies": {
91
89
  "complex-esm": "^2.1.1-esm1",
92
- "decimal.js": "^10.4.3"
90
+ "decimal.js": "^10.6.0"
93
91
  }
94
92
  }