@cortex-js/compute-engine 0.29.1 → 0.30.1

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 +28319 -24614
  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} +29615 -25910
  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 +1 -4
  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 +13 -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,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export declare class ExpressionMap<U> implements ExpressionMapInterface<U> {
3
3
  readonly _items: Map<BoxedExpression, U>;
4
4
  constructor(source?: ExpressionMapInterface<U> | readonly (readonly [BoxedExpression, U])[]);
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  /** Combine rational expressions into a single fraction */
3
3
  export declare function together(op: BoxedExpression): BoxedExpression;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  /**
3
3
  *
4
4
  * Make all the arguments canonical.
@@ -1,6 +1,6 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  /** Apply the function `f` to each operand of the expression `expr`,
3
- * account for the 'lazy' property of the function definition:
3
+ * account for the 'lazy' property of the operator definition:
4
4
  *
5
5
  * Account for `Hold`, `ReleaseHold`, `Sequence`, `Symbol` and `Nothing`.
6
6
  *
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  /**
3
3
  * The function attempts to match a subject expression to a
4
4
  * [pattern](/compute-engine/guides/patterns-and-rules/).
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export declare function canonicalNegate(expr: BoxedExpression): BoxedExpression;
3
3
  /**
4
4
  * Distribute `Negate` (multiply by -1) if expr is a number literal, an
@@ -1,7 +1,34 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
+ import { Decimal } from 'decimal.js';
2
3
  import type { Rational } from '../numerics/types';
3
- import type { BoxedExpression } from '../global-types';
4
+ import type { BoxedExpression, SemiBoxedExpression } from '../global-types';
4
5
  export declare function asRational(expr: BoxedExpression): Rational | undefined;
5
- export declare function asBigint(expr: BoxedExpression | undefined): bigint | null;
6
+ export declare function asBigint(x: Complex | Decimal | SemiBoxedExpression | undefined): bigint | null;
6
7
  export declare function asBignum(expr: BoxedExpression | undefined): Decimal | null;
8
+ /**
9
+ * Validate if the expression is a small integer.
10
+ * A small integer is an integer between -SMALL_INTEGER and SMALL_INTEGER (inclusive).
11
+ * Returns null if the expression is not a small integer.
12
+ *
13
+ * Unlike `toInteger()` this functions fails if the expression is not an
14
+ * integer. `toInteger()` will round the value to the nearest integer.
15
+ */
7
16
  export declare function asSmallInteger(expr: number | BoxedExpression | undefined): number | null;
17
+ /**
18
+ * Convert a boxed expression to an integer.
19
+ * Returns null if the expression cannot be converted to an integer.
20
+ * If the expression is a complex number, only the real part is considered.
21
+ * If the real part is not an integer, it is rounded to the nearest integer.
22
+ *
23
+ * Unlike `asSmallInteger()`, this function does not check if the integer is
24
+ * within the range of -SMALL_INTEGER to SMALL_INTEGER, and it rounds the
25
+ * value to the nearest integer if it is a number.
26
+ *
27
+ */
28
+ export declare function toInteger(expr: BoxedExpression | undefined): number | null;
29
+ /** Convert a boxed expression to a bigint.
30
+ * Returns null if the expression cannot be converted to a bigint.
31
+ * If the expression is a complex number, only the real part is considered.
32
+ * If the real part is not an integer, it is rounded to the nearest integer.
33
+ */
34
+ export declare function toBigint(expr: BoxedExpression | undefined): bigint | null;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export type Order = 'lex' | 'dexlex' | 'grevlex' | 'elim';
3
3
  export declare const DEFAULT_COMPLEXITY = 100000;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  /**
3
3
  * Coefficient of a univariate (single variable) polynomial.
4
4
  *
@@ -1,6 +1,6 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  import { NumericValue } from '../numeric-value/types';
3
- import type { BoxedExpression, ComputeEngine } from '../global-types';
3
+ import type { Rational } from '../numerics/types';
4
4
  /**
5
5
  * Group terms in a product by common term.
6
6
  *
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export declare const ConditionParent: {
3
3
  boolean: string;
4
4
  string: string;
@@ -1,3 +1,3 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  import type { ComputeEngine, BoxedExpression, JsonSerializationOptions } from '../global-types';
3
3
  export declare function serializeJson(ce: ComputeEngine, expr: BoxedExpression, options: Readonly<JsonSerializationOptions>): Expression;
@@ -1,6 +1,46 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export declare function sgn(expr: BoxedExpression): Sign | undefined;
3
+ /**
4
+ * Sign `s` is > 0.
5
+ *
6
+ * :::info[Note]
7
+ * Returns `undefined` for cases where the given sign is either non-applicable to real numbers
8
+ * ('nan', 'unsigned', 'complex-infinity') or does not convey enough information (e.g. 'real',
9
+ * 'not-zero', 'real-not-zero', 'non-negative').
10
+ * :::
11
+ *
12
+ * @param s
13
+ */
3
14
  export declare function positiveSign(s: Sign | undefined): boolean | undefined;
15
+ /**
16
+ * Sign `s` is >= 0.
17
+ *
18
+ *
19
+ * **note**: returns *undefined* where sign does not apply to the field of reals, or does not convey
20
+ * enough information.
21
+ *
22
+ * @param s
23
+ */
4
24
  export declare function nonNegativeSign(s: Sign | undefined): boolean | undefined;
25
+ /**
26
+ * Sign `s` is < 0.
27
+ *
28
+ * :::info[Note]
29
+ * Returns `undefined` for cases where the given sign is either non-applicable to real numbers
30
+ * ('nan', 'unsigned', 'complex-infinity') or does not convey enough information (e.g. 'real',
31
+ * 'not-zero', 'real-not-zero', 'non-positive').
32
+ * :::
33
+ *
34
+ * @param s
35
+ */
5
36
  export declare function negativeSign(s: Sign | undefined): boolean | undefined;
37
+ /**
38
+ * Sign `s` is <= 0.
39
+ *
40
+ *
41
+ * **note**: returns *undefined* where sign does not apply to the field of reals, or does not convey
42
+ * enough information.
43
+ *
44
+ * @param s
45
+ */
6
46
  export declare function nonPositiveSign(s: Sign | undefined): boolean | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  type InternalSimplifyOptions = SimplifyOptions & {
3
3
  useVariations: boolean;
4
4
  };
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export declare const UNIVARIATE_ROOTS: Rule[];
3
3
  /**
4
4
  * Expression is a function of a single variable (`x`) or an Equality
@@ -15,4 +15,6 @@ export declare function findUnivariateRoots(expr: BoxedExpression, x: string): R
15
15
  * `2x < 4` => `x < 2`
16
16
  */
17
17
  export declare function univariateSolve(expr: BoxedExpression, x: string): ReadonlyArray<BoxedExpression> | null;
18
+ /** Harmonization rules transform an expr into one or more equivalent
19
+ * expressions that are easier to solve */
18
20
  export declare const HARMONIZATION_RULES: Rule[];
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export declare class Terms {
3
3
  private engine;
4
4
  private terms;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  export declare function Fu(exp: BoxedExpression): RuleStep | undefined;
3
3
  /** Assuming x in an expression in radians, convert to current angular unit. */
4
4
  export declare function radiansToAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
@@ -1,32 +1,30 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  import { Type } from '../../common/type/types';
3
- import { NumericValue } from '../types';
3
+ import { NumericValue } from '../numeric-value/types';
4
+ export declare function isDictionary(expr: any | null | undefined): expr is DictionaryInterface;
4
5
  export declare function isBoxedExpression(x: unknown): x is BoxedExpression;
5
6
  /**
6
7
  * For any numeric result, if `bignumPreferred()` is true, calculate using
7
8
  * bignums. If `bignumPreferred()` is false, calculate using machine numbers
8
9
  */
9
10
  export declare function bignumPreferred(ce: ComputeEngine): boolean;
10
- export declare function isLatexString(s: unknown): s is string;
11
- export declare function asLatexString(s: unknown): string | null;
12
11
  export declare function hashCode(s: string): number;
13
12
  export declare function normalizedUnknownsForSolve(syms: string | Iterable<string> | BoxedExpression | Iterable<BoxedExpression> | null | undefined): string[];
14
13
  /** Return the local variables in the expression.
15
14
  *
16
- * A local variable is an identifier that is declared with a `Declare`
15
+ * A local variable is a symbol that is declared with a `Declare`
17
16
  * expression in a `Block` expression.
18
17
  *
19
- * Note that the canonical form of a `Block` expression will hoist all
20
- * `Declare` expressions to the top of the block. `Assign` expressions
21
- * of undeclared variables will also have a matching `Declare` expressions
22
- * hoisted.
18
+ */
19
+ export declare function getLocalVariables(expr: BoxedExpression): string[];
20
+ export declare function domainToType(expr: BoxedExpression): Type;
21
+ /**
22
+ * Return the angle in the range [0, 2π) that is equivalent to the given angle.
23
23
  *
24
+ * @param x
25
+ * @returns
24
26
  */
25
- export declare function isRelationalOperator(name: BoxedExpression | string): boolean;
26
- export declare function isInequalityOperator(operator: string): boolean;
27
- export declare function isEquationOperator(operator: string): boolean;
28
- export declare function isInequality(expr: BoxedExpression): boolean;
29
- export declare function isEquation(expr: BoxedExpression): boolean;
27
+ export declare function canonicalAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
30
28
  /**
31
29
  * Return a multiple of the imaginary unit, e.g.
32
30
  * - 'ImaginaryUnit' -> 1
@@ -38,17 +36,19 @@ export declare function isEquation(expr: BoxedExpression): boolean;
38
36
  *
39
37
  */
40
38
  export declare function getImaginaryFactor(expr: number | BoxedExpression): BoxedExpression | undefined;
41
- export declare function normalizeFlags(flags: Partial<NumericFlags> | undefined): NumericFlags | undefined;
42
- export declare function isSymbolDefinition(def: any): def is SymbolDefinition;
43
- export declare function isFunctionDefinition(def: any): def is FunctionDefinition;
44
- export declare function semiCanonical(ce: ComputeEngine, xs: ReadonlyArray<SemiBoxedExpression>): ReadonlyArray<BoxedExpression>;
45
- export declare function canonical(ce: ComputeEngine, xs: ReadonlyArray<SemiBoxedExpression>): ReadonlyArray<BoxedExpression>;
46
- export declare function domainToType(expr: BoxedExpression): Type;
47
39
  /**
48
- * Return the angle in the range [0, 2π) that is equivalent to the given angle.
40
+ * `true` if expr is a number with imaginary part 1 and real part 0, or a symbol with a definition
41
+ * matching this. Does not bind expr if a symbol.
49
42
  *
50
- * @param x
43
+ * @export
44
+ * @param expr
51
45
  * @returns
52
46
  */
53
- export declare function canonicalAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
47
+ export declare function isImaginaryUnit(expr: BoxedExpression): boolean;
54
48
  export declare function getPiTerm(expr: BoxedExpression): [k: NumericValue, t: NumericValue];
49
+ export declare function isValidOperatorDef(def: any): def is Partial<OperatorDefinition>;
50
+ export declare function isValidValueDef(def: any): def is Partial<ValueDefinition>;
51
+ export declare function isValueDef(def: BoxedDefinition | undefined): def is TaggedValueDefinition;
52
+ export declare function isOperatorDef(def: BoxedDefinition | undefined): def is TaggedOperatorDefinition;
53
+ export declare function updateDef(ce: ComputeEngine, name: string, def: BoxedDefinition, newDef: Partial<OperatorDefinition> | BoxedOperatorDefinition | Partial<ValueDefinition> | BoxedValueDefinition): void;
54
+ export declare function placeholderDef(ce: ComputeEngine, name: string): BoxedDefinition;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  import type { BoxedExpression, ComputeEngine } from '../global-types';
3
3
  /**
4
4
  * Check that the number of arguments is as expected.
@@ -46,3 +46,4 @@ export declare function checkPure(ce: ComputeEngine, arg: BoxedExpression | Boxe
46
46
  *
47
47
  */
48
48
  export declare function validateArguments(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, signature: Type, lazy?: boolean, threadable?: boolean): ReadonlyArray<BoxedExpression> | null;
49
+ export declare function spellCheckMessage(expr: BoxedExpression): string;
@@ -1,70 +1,35 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  /** If a collection has fewer than this many elements, eagerly evaluate it.
3
3
  *
4
4
  * For example, evaluate the Union of two sets with 10 elements each will
5
5
  * result in a set with 20 elements.
6
6
  *
7
- * If the sum of the sizes of the two sets is greater than `MAX_SIZE_EAGER_COLLECTION`, the result is a Union expression
7
+ * If the sum of the sizes of the two sets is greater than
8
+ * `MAX_SIZE_EAGER_COLLECTION`, the result is a Union expression
8
9
  *
9
10
  */
10
11
  export declare const MAX_SIZE_EAGER_COLLECTION = 100;
11
- export declare function isFiniteCollection(col: BoxedExpression): boolean;
12
- export declare function isIndexableCollection(col: BoxedExpression): boolean;
13
- export declare function isFiniteIndexableCollection(col: BoxedExpression): boolean;
14
- /**
15
- *
16
- * Iterate over all the elements of a collection. If not a collection,
17
- * return the expression.
18
- *
19
- * The `col` argument is either a collection literal, or a symbol
20
- * whose value is a collection literal.
21
- *
22
- * Even infinite collections are iterable. Use `isFiniteCollection()`
23
- * to check if the collection is finite.
24
- *
25
- * The collection can have one of the following forms:
26
- * - `["Range"]`, `["Interval"]`, `["Linspace"]` expressions
27
- * - `["List"]` and `["Set"]` expressions
28
- * - `["Tuple"]`, `["Pair"]`, `["Pair"]`, `["Triple"]` expressions
29
- * - `["Sequence"]` expressions
30
- * ... and more
31
- *
32
- * In general, `each` is easier to use than `iterator`, but they do the same
33
- * thing.
34
- *
35
- * @param col - A potential collection
36
- *
37
- * @returns
38
- */
39
- export declare function each(col: BoxedExpression): Generator<BoxedExpression>;
40
- /**
41
- *
42
- * The `col` argument is either a collection literal, or a symbol
43
- * whose value is a collection literal.
44
- *
45
- * @returns
46
- */
47
- export declare function length(col: BoxedExpression): number | undefined;
12
+ export declare function isFiniteIndexedCollection(col: BoxedExpression): boolean;
13
+ export declare function repeat(value: BoxedExpression, count?: number): Iterator<BoxedExpression>;
48
14
  /**
49
- * From an expression, create an iterator that can be used
50
- * to enumerate values.
51
- *
52
- * `expr` should be a collection expression, or a string, or a symbol whose
53
- * value is a collection expression or a string.
54
- *
55
- * - ["Range", 5]
56
- * - ["List", 1, 2, 3]
57
- * - "'hello world'"
58
- *
15
+ * Zips together multiple collections into a single iterator.
16
+ *
17
+ * Example:
18
+ * ```typescript
19
+ * const a = ce.box(['List', 1, 2, 3]);
20
+ * const b = ce.box(['List', 4, 5, 6]);
21
+ * const zipped = zip([a, b]);
22
+ * for (const [x, y] of zipped) {
23
+ * console.log(x, y); // 1 4, 2 5, 3 6
24
+ * }
25
+ * ```
59
26
  */
60
- export declare function iterator(expr: BoxedExpression): Iterator<BoxedExpression> | undefined;
61
- export declare function repeat(value: BoxedExpression, count?: number): Iterator<BoxedExpression>;
27
+ export declare function zip(items: ReadonlyArray<BoxedExpression>): Iterator<BoxedExpression[]>;
62
28
  /**
29
+ * Default collection handlers suitable for collections that store their
30
+ * elements as operands.
63
31
  *
64
- * @param expr
65
- * @param index 1-based index
66
- * @returns
32
+ * This is the case for List, Tuple, etc.
67
33
  */
68
- export declare function at(expr: BoxedExpression, index: number): BoxedExpression | undefined;
69
- export declare function defaultCollectionHandlers(def: undefined | Partial<CollectionHandlers>): Partial<CollectionHandlers> | undefined;
70
- export declare function zip(items: ReadonlyArray<BoxedExpression>): Iterator<BoxedExpression[]>;
34
+ export declare function basicIndexedCollectionHandlers(): CollectionHandlers;
35
+ export declare function defaultCollectionHandlers(def: undefined | CollectionHandlers): CollectionHandlers | undefined;
@@ -1,17 +1,20 @@
1
- /* 0.29.1 */
2
- import { BoxedExpression, CompiledType, JSSource } from './global-types';
3
- export type CompiledOperators = Record<MathJsonIdentifier, [
1
+ /* 0.30.1 */
2
+ import { BoxedExpression, JSSource } from './global-types';
3
+ import { chop, factorial, gcd, lcm, limit } from './numerics/numeric';
4
+ import { gamma, gammaln } from './numerics/special-functions';
5
+ import { interquartileRange, kurtosis, mean, median, mode, populationStandardDeviation, populationVariance, quartiles, skewness, standardDeviation, variance } from './numerics/statistics';
6
+ export type CompiledOperators = Record<MathJsonSymbol, [
4
7
  op: string,
5
8
  prec: number
6
9
  ]>;
7
10
  export type CompiledFunction = string | ((args: ReadonlyArray<BoxedExpression>, compile: (expr: BoxedExpression) => JSSource, target: CompileTarget) => JSSource);
8
11
  export type CompiledFunctions = {
9
- [id: MathJsonIdentifier]: CompiledFunction;
12
+ [id: MathJsonSymbol]: CompiledFunction;
10
13
  };
11
14
  export type CompileTarget = {
12
- operators?: (op: MathJsonIdentifier) => [op: string, prec: number];
13
- functions?: (id: MathJsonIdentifier) => CompiledFunction | undefined;
14
- var: (id: MathJsonIdentifier) => string | undefined;
15
+ operators?: (op: MathJsonSymbol) => [op: string, prec: number] | undefined;
16
+ functions?: (id: MathJsonSymbol) => CompiledFunction | undefined;
17
+ var: (id: MathJsonSymbol) => string | undefined;
15
18
  string: (str: string) => string;
16
19
  number: (n: number) => string;
17
20
  ws: (s?: string) => string;
@@ -21,9 +24,57 @@ export type CompileTarget = {
21
24
  /** This is an extension of the Function class that allows us to pass
22
25
  * a custom scope for "global" functions. */
23
26
  export declare class ComputeEngineFunction extends Function {
24
- private sys;
27
+ SYS: {
28
+ chop: typeof chop;
29
+ factorial: typeof factorial;
30
+ gamma: typeof gamma;
31
+ gcd: typeof gcd;
32
+ integrate: (f: any, a: any, b: any) => number;
33
+ lcm: typeof lcm;
34
+ lngamma: typeof gammaln;
35
+ limit: typeof limit;
36
+ mean: typeof mean;
37
+ median: typeof median;
38
+ variance: typeof variance;
39
+ populationVariance: typeof populationVariance;
40
+ standardDeviation: typeof standardDeviation;
41
+ populationStandardDeviation: typeof populationStandardDeviation;
42
+ kurtosis: typeof kurtosis;
43
+ skewness: typeof skewness;
44
+ mode: typeof mode;
45
+ quartiles: typeof quartiles;
46
+ interquartileRange: typeof interquartileRange;
47
+ };
25
48
  constructor(body: string, preamble?: string);
26
49
  }
27
- export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): (_?: Record<string, CompiledType>) => CompiledType;
28
- export declare function compileToJavascript(expr: BoxedExpression, functions?: Record<MathJsonIdentifier, JSSource | Function>, vars?: Record<MathJsonIdentifier, JSSource>, imports?: unknown[], preamble?: string): (_?: Record<string, CompiledType>) => CompiledType;
50
+ export declare class ComputeEngineFunctionLiteral extends Function {
51
+ SYS: {
52
+ chop: typeof chop;
53
+ factorial: typeof factorial;
54
+ gamma: typeof gamma;
55
+ gcd: typeof gcd;
56
+ integrate: (f: any, a: any, b: any) => number;
57
+ lcm: typeof lcm;
58
+ lngamma: typeof gammaln;
59
+ limit: typeof limit;
60
+ mean: typeof mean;
61
+ median: typeof median;
62
+ variance: typeof variance;
63
+ populationVariance: typeof populationVariance;
64
+ standardDeviation: typeof standardDeviation;
65
+ populationStandardDeviation: typeof populationStandardDeviation;
66
+ kurtosis: typeof kurtosis;
67
+ skewness: typeof skewness;
68
+ mode: typeof mode;
69
+ quartiles: typeof quartiles;
70
+ interquartileRange: typeof interquartileRange;
71
+ };
72
+ constructor(body: string, args: string[]);
73
+ }
74
+ export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): ((...args: any[]) => any) & {
75
+ isCompiled: true;
76
+ };
77
+ export declare function compileToJavaScript(expr: BoxedExpression, functions?: Record<MathJsonSymbol, JSSource | Function>, vars?: Record<MathJsonSymbol, JSSource>, imports?: unknown[], preamble?: string): ((...args: any[]) => any) & {
78
+ isCompiled: true;
79
+ };
29
80
  export declare function compile(expr: BoxedExpression | undefined, target: CompileTarget, prec?: number): JSSource;
@@ -1,4 +1,4 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
2
  /**
3
3
  * The default cost function, used to determine if a new expression is simpler
4
4
  * than the old one.
@@ -1,18 +1,14 @@
1
- /* 0.29.1 */
1
+ /* 0.30.1 */
2
+ import type { BoxedDefinition, BoxedExpression, ComputeEngine, Scope } from './global-types';
2
3
  /***
3
4
  * ### THEORY OF OPERATIONS
4
5
  *
5
- * A `["Function"]` expression has its own scope.
6
- * This scope includes the parameters and local variables.
6
+ * The body of a `["Function"]` expression is a `["Block"]` expression,
7
+ * which is scoped. The function arguments are declared in that scope as well.
7
8
  *
8
9
  * Some expressions with anonymous parameters (e.g. `["Add", "_", 1]`)
9
10
  * are rewritten to a `["Function"]` expression with anonymous parameters
10
- * (e.g. `["Function", ["Add", "_", 1], "_"]`).
11
- *
12
- * The **body** of a `["Function"]` expression may have its own scope
13
- * (for example if it's a `["Block"]` expression) or may not have a scope
14
- * at all (if it's a number, i.e. `["Function", 1]`). the function body may
15
- * be a number, a symbol or (more commonly) an function expression.
11
+ * (e.g. `["Function", ["Block", ["Add", "_", 1]], "_"]`).
16
12
  *
17
13
  *
18
14
  * #### DURING BOXING (in makeLambda())
@@ -32,11 +28,10 @@
32
28
  *
33
29
  * 1/ The arguments are evaluated in the current scope
34
30
  * 2/ The context is swapped to the function scope
35
- * 3/ The values of all the ids in this scope are reset
36
- * 4/ The parameters are set to the value of the arguments
37
- * 5/ The function body is evaluated in the context of the function scope
38
- * 6/ The context is swapped back to the current scope
39
- * 7/ The result of the function body is returned
31
+ * 3/ The function parameters are set to the value of the arguments
32
+ * 4/ The function body is evaluated in the context of the function scope
33
+ * 5/ The context is swapped back to the current scope
34
+ * 6/ The result of the function body is returned
40
35
  *
41
36
  */
42
37
  /**
@@ -48,28 +43,48 @@ export declare function predicate(_expr: BoxedExpression): (...args: BoxedExpres
48
43
  */
49
44
  export declare function order(_expr: BoxedExpression): (a: BoxedExpression, b: BoxedExpression) => -1 | 0 | 1;
50
45
  /**
51
- * Given an expression, rewrite it to a canonical Function form.
46
+ * Given an expression, rewrite it to a symbol or canonical Function form.
47
+ *
48
+ * - symbol (no change):
49
+ * "Sin"
50
+ * -> "Sin"
51
+ *
52
+ * - built-in function:
53
+ * ["BuiltinFunction", "Sin"]
54
+ * -> "Sin"
55
+ *
56
+ * - parenthesized expression:
57
+ * ["Delimiter", ["Add", "_", 1], "'()'"]
58
+ * -> ["Function", ["Block", ["Add", "_", 1]], "_"]
59
+ *
60
+ * - explicit parameters (adding a block to serve as a scope for the arguments):
61
+ * ["Function", ["Add", "x", 1], "x"]
62
+ * -> ["Function", ["Block", ["Add", "x", 1]], "x"]
52
63
  *
53
- * - explicit parameters (no change)
54
- * ["Function", ["Add, "x", 1], "x"]
55
- * -> ["Function", ["Add, "x", 1], "x"]
56
64
  *
57
65
  * - single anonymous parameters:
58
66
  * ["Add", "_", 1]
59
- * -> ["Function", ["Add", "_", 1], "_"]
67
+ * -> ["Function", ["Block", ["Add", "_", 1]], "_"]
60
68
  *
61
69
  * - multiple anonymous parameters:
62
70
  * ["Add", "_1", "_2"]
63
- * -> ["Function", ["Add", "_1", "_2"], "_1", "_2"]
71
+ * -> ["Function", ["Block", ["Add", "_1", "_2"]], "_1", "_2"]
64
72
  *
65
73
  *
66
74
  */
67
- export declare function canonicalFunctionExpression(body: BoxedExpression, args?: BoxedExpression[]): [body: BoxedExpression, ...params: string[]];
75
+ export declare function canonicalFunctionLiteral(expr: BoxedExpression | undefined): BoxedExpression | undefined;
76
+ /** Assuming that ops has the following form:
77
+ * - body
78
+ * - ...params
79
+ * return a canonical function literal (["Function", body, ...params]) where
80
+ * body is potentially wrapped in a Block expression and the arguments are
81
+ * declared in the scope of the body.
82
+ */
83
+ export declare function canonicalFunctionLiteralArguments(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>): BoxedExpression | undefined;
68
84
  /**
69
- * Apply arguments to an expression which is either
70
- * - a '["Function"]' expression
71
- * - an expression with anonymous parameters, e.g. ["Add", "_", 1]
72
- * - the identifier for a function, e.g. "Sin".
85
+ * Apply arguments to an expression which is either:
86
+ * - a `["Function"]` expression
87
+ * - the symbol for a function, e.g. `Sin`.
73
88
  */
74
89
  export declare function apply(fn: BoxedExpression, args: ReadonlyArray<BoxedExpression>): BoxedExpression;
75
90
  /**
@@ -89,15 +104,17 @@ export declare function makeLambdaN1(expr: BoxedExpression): ((arg: number) => n
89
104
  */
90
105
  export declare function applicable(fn: BoxedExpression): (xs: ReadonlyArray<BoxedExpression>) => BoxedExpression | undefined;
91
106
  /**
92
- * Use applicableN when the function is known to be a function of a single
93
- * variable and the argument is a number.
107
+ * Use `applicableN1()` when the function is known to be a function with a
108
+ * single real argument that returns a real value.
94
109
  *
95
- * Unlike "apply", applicable returns a function that can be called
110
+ * Unlike `apply()`, `applicableN1()` returns a function that can be called
96
111
  * with an argument.
97
112
  *
98
113
  */
99
114
  export declare function applicableN1(fn: BoxedExpression): (x: number) => number;
100
115
  /**
101
- * Give a string like "f(x,y)" return, ["f", ["x", "y"]]
116
+ * Given a string like "f(x,y)" return, ["f", ["x", "y"]]
102
117
  */
103
118
  export declare function parseFunctionSignature(s: string): [id: string, args: string[] | undefined];
119
+ /** Lookup a definition matching a symbol in a lexical scope chain */
120
+ export declare function lookup(id: MathJsonSymbol, scope: Scope): undefined | BoxedDefinition;