@cortex-js/compute-engine 0.30.1 → 0.31.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 (149) hide show
  1. package/dist/compute-engine.esm.js +9837 -7504
  2. package/dist/compute-engine.min.esm.js +49 -53
  3. package/dist/compute-engine.min.umd.js +49 -53
  4. package/dist/compute-engine.umd.js +9837 -7504
  5. package/dist/math-json.esm.js +19 -5
  6. package/dist/math-json.min.esm.js +19 -5
  7. package/dist/math-json.min.umd.js +2 -2
  8. package/dist/math-json.umd.js +19 -5
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +1 -1
  11. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +1 -1
  14. package/dist/types/common/one-of.d.ts +1 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/ast-nodes.d.ts +146 -0
  17. package/dist/types/common/type/boxed-type.d.ts +1 -1
  18. package/dist/types/common/type/lexer.d.ts +51 -0
  19. package/dist/types/common/type/parse.d.ts +208 -1
  20. package/dist/types/common/type/parser.d.ts +45 -0
  21. package/dist/types/common/type/primitive.d.ts +1 -1
  22. package/dist/types/common/type/serialize.d.ts +1 -1
  23. package/dist/types/common/type/subtype.d.ts +1 -1
  24. package/dist/types/common/type/type-builder.d.ts +32 -0
  25. package/dist/types/common/type/types.d.ts +1 -1
  26. package/dist/types/common/type/utils.d.ts +1 -1
  27. package/dist/types/common/utils.d.ts +22 -1
  28. package/dist/types/compute-engine/assume.d.ts +1 -1
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +4 -4
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  34. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  35. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  36. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +7 -5
  37. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +3 -3
  38. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  39. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +104 -1
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -3
  43. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +3 -3
  44. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/match.d.ts +8 -1
  55. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +58 -1
  59. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +2 -2
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/utils.d.ts +11 -1
  68. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -1
  69. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  70. package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
  71. package/dist/types/compute-engine/{compile.d.ts → compilation/javascript-target.d.ts} +20 -32
  72. package/dist/types/compute-engine/compilation/types.d.ts +83 -0
  73. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  74. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  75. package/dist/types/compute-engine/global-types.d.ts +75 -17
  76. package/dist/types/compute-engine/index.d.ts +4 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  88. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  90. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  93. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  94. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  95. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  96. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  97. package/dist/types/compute-engine/latex-syntax/types.d.ts +2 -2
  98. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  99. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  100. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  101. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  102. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  103. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  104. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  105. package/dist/types/compute-engine/library/core.d.ts +1 -1
  106. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  107. package/dist/types/compute-engine/library/library.d.ts +1 -1
  108. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  109. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  110. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  111. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  112. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  113. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  114. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  115. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  116. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  117. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  118. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  119. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  120. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  121. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  123. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  124. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  125. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  127. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  128. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  129. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  130. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  131. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  132. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  133. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  134. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  135. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  136. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  137. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  138. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  139. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  140. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  141. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  142. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  143. package/dist/types/compute-engine/types.d.ts +1 -1
  144. package/dist/types/compute-engine.d.ts +1 -1
  145. package/dist/types/math-json/symbols.d.ts +1 -1
  146. package/dist/types/math-json/types.d.ts +4 -2
  147. package/dist/types/math-json/utils.d.ts +7 -1
  148. package/dist/types/math-json.d.ts +2 -2
  149. package/package.json +11 -10
@@ -1,3 +1,3 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
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,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare function sgn(expr: BoxedExpression): Sign | undefined;
3
3
  /**
4
4
  * Sign `s` is > 0.
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  type InternalSimplifyOptions = SimplifyOptions & {
3
3
  useVariations: boolean;
4
4
  };
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const UNIVARIATE_ROOTS: Rule[];
3
3
  /**
4
4
  * Expression is a function of a single variable (`x`) or an Equality
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare class Terms {
3
3
  private engine;
4
4
  private terms;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
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,6 +1,16 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { Type } from '../../common/type/types';
3
3
  import { NumericValue } from '../numeric-value/types';
4
+ /**
5
+ * Check if an expression contains symbolic transcendental functions of constants
6
+ * (like ln(2), sin(1), etc.) that should not be evaluated numerically.
7
+ *
8
+ * This excludes transcendentals that simplify to exact values, such as:
9
+ * - ln(e) -> 1
10
+ * - sin(0) -> 0
11
+ * - cos(0) -> 1
12
+ */
13
+ export declare function hasSymbolicTranscendental(expr: BoxedExpression): boolean;
4
14
  export declare function isDictionary(expr: any | null | undefined): expr is DictionaryInterface;
5
15
  export declare function isBoxedExpression(x: unknown): x is BoxedExpression;
6
16
  /**
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import type { BoxedExpression, ComputeEngine } from '../global-types';
3
3
  /**
4
4
  * Check that the number of arguments is as expected.
@@ -44,6 +44,15 @@ export declare function checkPure(ce: ComputeEngine, arg: BoxedExpression | Boxe
44
44
  * Otherwise return a list of expressions indicating the mismatched
45
45
  * arguments.
46
46
  *
47
+ * <!--
48
+ * @todo?:
49
+ * - Some permutations of operands should perhaps always be treated as invalid. Consider:
50
+ * - A sequence wildcard (non-optional, i.e. '__') followed by either a universal wildcard ('_'),
51
+ * or another non-optional sequence wildcard. (note that an optional sequence wildcard is
52
+ * unproblematic here.)
53
+ *
54
+ * -->
55
+ *
47
56
  */
48
57
  export declare function validateArguments(ce: ComputeEngine, ops: ReadonlyArray<BoxedExpression>, signature: Type, lazy?: boolean, threadable?: boolean): ReadonlyArray<BoxedExpression> | null;
49
58
  export declare function spellCheckMessage(expr: BoxedExpression): string;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
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
@@ -0,0 +1,31 @@
1
+ /* 0.31.0 */
2
+ import type { CompileTarget, TargetSource } from './types';
3
+ /**
4
+ * Base compiler class containing language-agnostic compilation logic
5
+ */
6
+ export declare class BaseCompiler {
7
+ /**
8
+ * Compile an expression to target language source code
9
+ */
10
+ static compile(expr: BoxedExpression | undefined, target: CompileTarget, prec?: number): TargetSource;
11
+ /**
12
+ * Compile a function expression
13
+ */
14
+ static compileExpr(engine: ComputeEngine, h: string, args: ReadonlyArray<BoxedExpression>, prec: number, target: CompileTarget): TargetSource;
15
+ /**
16
+ * Compile a block expression
17
+ */
18
+ private static compileBlock;
19
+ /**
20
+ * Compile loop constructs (Sum/Product)
21
+ */
22
+ private static compileLoop;
23
+ /**
24
+ * Generate a temporary variable name
25
+ */
26
+ static tempVar(): string;
27
+ /**
28
+ * Inline or wrap expression in IIFE based on complexity
29
+ */
30
+ static inlineExpression(body: string, x: string): string;
31
+ }
@@ -1,28 +1,11 @@
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, [
7
- op: string,
8
- prec: number
9
- ]>;
10
- export type CompiledFunction = string | ((args: ReadonlyArray<BoxedExpression>, compile: (expr: BoxedExpression) => JSSource, target: CompileTarget) => JSSource);
11
- export type CompiledFunctions = {
12
- [id: MathJsonSymbol]: CompiledFunction;
13
- };
14
- export type CompileTarget = {
15
- operators?: (op: MathJsonSymbol) => [op: string, prec: number] | undefined;
16
- functions?: (id: MathJsonSymbol) => CompiledFunction | undefined;
17
- var: (id: MathJsonSymbol) => string | undefined;
18
- string: (str: string) => string;
19
- number: (n: number) => string;
20
- ws: (s?: string) => string;
21
- preamble: string;
22
- indent: number;
23
- };
24
- /** This is an extension of the Function class that allows us to pass
25
- * a custom scope for "global" functions. */
1
+ /* 0.31.0 */
2
+ import { chop, factorial, gcd, lcm, limit } from '../numerics/numeric';
3
+ import { gamma, gammaln } from '../numerics/special-functions';
4
+ import { interquartileRange, kurtosis, mean, median, mode, populationStandardDeviation, populationVariance, quartiles, skewness, standardDeviation, variance } from '../numerics/statistics';
5
+ import type { CompileTarget, CompiledOperators, CompiledFunctions, LanguageTarget, CompilationOptions, CompiledExecutable } from './types';
6
+ /**
7
+ * JavaScript-specific function extension that provides system functions
8
+ */
26
9
  export declare class ComputeEngineFunction extends Function {
27
10
  SYS: {
28
11
  chop: typeof chop;
@@ -47,6 +30,9 @@ export declare class ComputeEngineFunction extends Function {
47
30
  };
48
31
  constructor(body: string, preamble?: string);
49
32
  }
33
+ /**
34
+ * JavaScript function literal with parameters
35
+ */
50
36
  export declare class ComputeEngineFunctionLiteral extends Function {
51
37
  SYS: {
52
38
  chop: typeof chop;
@@ -71,10 +57,12 @@ export declare class ComputeEngineFunctionLiteral extends Function {
71
57
  };
72
58
  constructor(body: string, args: string[]);
73
59
  }
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
- };
80
- export declare function compile(expr: BoxedExpression | undefined, target: CompileTarget, prec?: number): JSSource;
60
+ /**
61
+ * JavaScript language target implementation
62
+ */
63
+ export declare class JavaScriptTarget implements LanguageTarget {
64
+ getOperators(): CompiledOperators;
65
+ getFunctions(): CompiledFunctions;
66
+ createTarget(options?: Partial<CompileTarget>): CompileTarget;
67
+ compileToExecutable(expr: BoxedExpression, options?: CompilationOptions): CompiledExecutable;
68
+ }
@@ -0,0 +1,83 @@
1
+ /* 0.31.0 */
2
+ import type { BoxedExpression } from '../global-types';
3
+ /**
4
+ * Source code in the target language
5
+ */
6
+ export type TargetSource = string;
7
+ /**
8
+ * A compiled function that can be executed
9
+ */
10
+ export type CompiledFunction = string | ((args: ReadonlyArray<BoxedExpression>, compile: (expr: BoxedExpression) => TargetSource, target: CompileTarget) => TargetSource);
11
+ /**
12
+ * Mapping of operators to their target language representation and precedence
13
+ */
14
+ export type CompiledOperators = Record<MathJsonSymbol, [
15
+ op: string,
16
+ prec: number
17
+ ]>;
18
+ /**
19
+ * Mapping of function names to their target language implementation
20
+ */
21
+ export type CompiledFunctions = {
22
+ [id: MathJsonSymbol]: CompiledFunction;
23
+ };
24
+ /**
25
+ * Target language compilation configuration
26
+ */
27
+ export interface CompileTarget {
28
+ /** Get operator representation for the target language */
29
+ operators?: (op: MathJsonSymbol) => [op: string, prec: number] | undefined;
30
+ /** Get function implementation for the target language */
31
+ functions?: (id: MathJsonSymbol) => CompiledFunction | undefined;
32
+ /** Get variable representation for the target language */
33
+ var: (id: MathJsonSymbol) => string | undefined;
34
+ /** Format string literals for the target language */
35
+ string: (str: string) => string;
36
+ /** Format numeric literals for the target language */
37
+ number: (n: number) => string;
38
+ /** Format whitespace for the target language */
39
+ ws: (s?: string) => string;
40
+ /** Code to be inserted at the beginning of the compiled output */
41
+ preamble: string;
42
+ /** Current indentation level */
43
+ indent: number;
44
+ /** Target language identifier (for debugging/logging) */
45
+ language?: string;
46
+ }
47
+ /**
48
+ * Base interface for language-specific compilation targets
49
+ */
50
+ export interface LanguageTarget {
51
+ /** Get the default operators for this language */
52
+ getOperators(): CompiledOperators;
53
+ /** Get the default functions for this language */
54
+ getFunctions(): CompiledFunctions;
55
+ /** Create a CompileTarget for this language */
56
+ createTarget(options?: Partial<CompileTarget>): CompileTarget;
57
+ /** Compile an expression to executable code in this language */
58
+ compileToExecutable(expr: BoxedExpression, options?: CompilationOptions): CompiledExecutable;
59
+ }
60
+ /**
61
+ * Options for compilation
62
+ */
63
+ export interface CompilationOptions {
64
+ /** Custom function implementations */
65
+ functions?: Record<MathJsonSymbol, TargetSource | Function>;
66
+ /** Variable bindings */
67
+ vars?: Record<MathJsonSymbol, TargetSource>;
68
+ /** Additional imports/libraries to include */
69
+ imports?: unknown[];
70
+ /** Additional preamble code */
71
+ preamble?: string;
72
+ }
73
+ /**
74
+ * A compiled expression that can be executed
75
+ */
76
+ export interface CompiledExecutable {
77
+ /** Execute the compiled code */
78
+ (...args: any[]): any;
79
+ /** Get the source code */
80
+ toString(): string;
81
+ /** Flag indicating this is a compiled expression */
82
+ isCompiled: true;
83
+ }
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  /**
3
3
  * The default cost function, used to determine if a new expression is simpler
4
4
  * than the old one.
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import type { BoxedDefinition, BoxedExpression, ComputeEngine, Scope } from './global-types';
3
3
  /***
4
4
  * ### THEORY OF OPERATIONS
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import type { OneOf } from '../common/one-of';
3
3
  import type { Expression, MathJsonNumberObject, MathJsonStringObject, MathJsonFunctionObject, MathJsonSymbolObject, MathJsonSymbol, MathJsonDictionaryObject } from '../math-json';
4
4
  import type { Type, TypeReference, TypeResolver, TypeString } from '../common/type/types';
@@ -912,6 +912,10 @@ export interface BoxedExpression {
912
912
  *
913
913
  * :::info[Note]
914
914
  * Applicable to canonical and non-canonical expressions.
915
+ *
916
+ * If this is a function, an empty substitution is given, and the computed value of `canonical`
917
+ * does not differ from that of this expr.: then a call this method is analagous to requesting a
918
+ * *clone*.
915
919
  * :::
916
920
  *
917
921
  */
@@ -949,11 +953,25 @@ export interface BoxedExpression {
949
953
  *
950
954
  * See also `expr.subs()` for a simple substitution of symbols.
951
955
  *
952
- * If `options.canonical` is not set, the result is canonical if `this`
953
- * is canonical.
956
+ * Procedure for the determining the canonical-status of the input expression and replacements:
957
+ *
958
+ * - If `options.canonical` is set, the *entire expr.* is canonicalized to this degree: whether
959
+ * the replacement occurs at the top-level, or within/recursively.
960
+ *
961
+ * - If otherwise, the *direct replacement will be canonical* if either the 'replaced' expression
962
+ * is canonical, or the given replacement (- is a BoxedExpression and -) is canonical.
963
+ * Notably also, if this replacement takes place recursively (not at the top-level), then exprs.
964
+ * containing the replaced expr. will still however have their (previous) canonical-status
965
+ * *preserved*... unless this expr. was previously non-canonical, and *replacements have resulted
966
+ * in canonical operands*. In this case, an expr. meeting this criteria will be updated to
967
+ * canonical status. (Canonicalization is opportunistic here, in other words).
954
968
  *
955
969
  * :::info[Note]
956
970
  * Applicable to canonical and non-canonical expressions.
971
+ *
972
+ * To match a specific symbol (not a wildcard pattern), the `match` must be
973
+ * a `BoxedExpression` (e.g., `{ match: ce.box('x'), replace: ... }`).
974
+ * For simple symbol substitution, consider using `subs()` instead.
957
975
  * :::
958
976
  */
959
977
  replace(rules: BoxedRuleSet | Rule | Rule[], options?: Partial<ReplaceOptions>): null | BoxedExpression;
@@ -1304,9 +1322,9 @@ export interface BoxedExpression {
1304
1322
  *
1305
1323
  */
1306
1324
  compile(options?: {
1307
- to?: 'javascript';
1325
+ to?: 'javascript' | 'wgsl' | 'python' | 'webassembly';
1308
1326
  functions?: Record<MathJsonSymbol, JSSource | ((...any: any[]) => any)>;
1309
- vars?: Record<MathJsonSymbol, CompiledType>;
1327
+ vars?: Record<MathJsonSymbol, JSSource>;
1310
1328
  imports?: ((...any: any[]) => any)[];
1311
1329
  preamble?: string;
1312
1330
  fallback?: boolean;
@@ -1523,7 +1541,7 @@ export interface BoxedExpression {
1523
1541
  * Return `undefined` if the membership cannot be determined without
1524
1542
  * iterating over the collection.
1525
1543
  */
1526
- xcontains(rhs: BoxedExpression): boolean | undefined;
1544
+ contains(rhs: BoxedExpression): boolean | undefined;
1527
1545
  /**
1528
1546
  * Check if this collection is a subset of another collection.
1529
1547
  *
@@ -1541,7 +1559,7 @@ export interface BoxedExpression {
1541
1559
  * be determined without iterating over the collection.
1542
1560
  *
1543
1561
  */
1544
- get xsize(): number | undefined;
1562
+ get count(): number | undefined;
1545
1563
  /** If this is a finite collection, return true. */
1546
1564
  isFiniteCollection: boolean | undefined;
1547
1565
  /** If this is an empty collection, return true.
@@ -1635,7 +1653,7 @@ export type JsonSerializationOptions = {
1635
1653
  *
1636
1654
  * **Default**: `["all"]`
1637
1655
  */
1638
- shorthands: ('all' | 'number' | 'symbol' | 'function' | 'string')[];
1656
+ shorthands: ('all' | 'number' | 'symbol' | 'function' | 'string' | 'dictionary')[];
1639
1657
  /** A list of space separated keywords indicating which metadata should be
1640
1658
  * included in the MathJSON. If metadata is included, shorthand notation
1641
1659
  * is not used.
@@ -1663,16 +1681,31 @@ export type JsonSerializationOptions = {
1663
1681
  /**
1664
1682
  * Control how a pattern is matched to an expression.
1665
1683
  *
1666
- * - `substitution`: if present, assumes these values for the named wildcards,
1667
- * and ensure that subsequent occurrence of the same wildcard have the same
1668
- * value.
1684
+ * ## Wildcards
1685
+ *
1686
+ * Patterns can include wildcards to match parts of expressions:
1687
+ *
1688
+ * - **Universal (`_` or `_name`)**: Matches exactly one element
1689
+ * - **Sequence (`__` or `__name`)**: Matches one or more elements
1690
+ * - **Optional Sequence (`___` or `___name`)**: Matches zero or more elements
1691
+ *
1692
+ * Named wildcards capture values in the returned substitution:
1693
+ * - `['Add', '_a', 1].match(['Add', 'x', 1])` → `{_a: 'x'}`
1694
+ * - `['Add', '__a'].match(['Add', 1, 2, 3])` → `{__a: [1, 2, 3]}`
1695
+ *
1696
+ * ## Options
1697
+ *
1698
+ * - `substitution`: if present, assumes these values for a subset of
1699
+ * named wildcards, and ensure that subsequent occurrence of the same
1700
+ * wildcard have the same value.
1669
1701
  * - `recursive`: if true, match recursively, otherwise match only the top
1670
1702
  * level.
1671
1703
  * - `useVariations`: if false, only match expressions that are structurally identical.
1672
1704
  * If true, match expressions that are structurally identical or equivalent.
1673
- *
1674
- * For example, when true, `["Add", '_a', 2]` matches `2`, with a value of
1675
- * `_a` of `0`. If false, the expression does not match. **Default**: `false`
1705
+ * For example, when true, `["Add", '_a', 2]` matches `2`, with `_a = 0`.
1706
+ * **Default**: `false`
1707
+ * - `matchPermutations`: if true (default), for commutative operators, try all
1708
+ * permutations of pattern operands. If false, match exact order only.
1676
1709
  *
1677
1710
  * @category Pattern Matching
1678
1711
  *
@@ -1681,6 +1714,15 @@ export type PatternMatchOptions = {
1681
1714
  substitution?: BoxedSubstitution;
1682
1715
  recursive?: boolean;
1683
1716
  useVariations?: boolean;
1717
+ /**
1718
+ * If `true` (default), for commutative operators, try all permutations of
1719
+ * the pattern operands to find a match.
1720
+ *
1721
+ * If `false`, only match in the exact order given. This can be useful
1722
+ * when the pattern order is significant or for performance optimization
1723
+ * with large patterns.
1724
+ */
1725
+ matchPermutations?: boolean;
1684
1726
  };
1685
1727
  /**
1686
1728
  * @category Boxed Expression
@@ -1718,6 +1760,17 @@ export type ReplaceOptions = {
1718
1760
  *
1719
1761
  */
1720
1762
  useVariations: boolean;
1763
+ /**
1764
+ * If `true` (default), for commutative operators, try all permutations of
1765
+ * the pattern operands to find a match.
1766
+ *
1767
+ * If `false`, only match in the exact order given. This can be useful
1768
+ * when the pattern order is significant or for performance optimization
1769
+ * with large patterns.
1770
+ *
1771
+ * **Default**: `true`
1772
+ */
1773
+ matchPermutations: boolean;
1721
1774
  /**
1722
1775
  * If `iterationLimit` > 1, the rules will be repeatedly applied
1723
1776
  * until no rules apply, up to `iterationLimit` times.
@@ -2520,18 +2573,22 @@ export type RuleStep = {
2520
2573
  /** @category Rules */
2521
2574
  export type RuleSteps = RuleStep[];
2522
2575
  /**
2523
- * A rule describes how to modify an expressions that matches a pattern `match`
2576
+ * A rule describes how to modify an expression that matches a pattern `match`
2524
2577
  * into a new expression `replace`.
2525
2578
  *
2526
2579
  * - `x-1` \( \to \) `1-x`
2527
2580
  * - `(x+1)(x-1)` \( \to \) `x^2-1
2528
2581
  *
2529
- * The patterns can be expressed as LaTeX strings or a MathJSON expressions.
2582
+ * The patterns can be expressed as LaTeX strings or `SemiBoxedExpression`'s.
2583
+ * Alternatively, match/replace logic may be specified by a `RuleFunction`, allowing both custom
2584
+ * logic/conditions for the match, and either a *BoxedExpression* (or `RuleStep` if being
2585
+ * descriptive) for the replacement.
2530
2586
  *
2531
2587
  * As a shortcut, a rule can be defined as a LaTeX string: `x-1 -> 1-x`.
2532
2588
  * The expression to the left of `->` is the `match` and the expression to the
2533
2589
  * right is the `replace`. When using LaTeX strings, single character variables
2534
- * are assumed to be wildcards.
2590
+ * are assumed to be wildcards. The rule LHS ('match') and RHS ('replace') may also be supplied
2591
+ * separately: in this case following the same rules.
2535
2592
  *
2536
2593
  * When using MathJSON expressions, anonymous wildcards (`_`) will match any
2537
2594
  * expression. Named wildcards (`_x`, `_a`, etc...) will match any expression
@@ -2762,6 +2819,7 @@ export interface ComputeEngine extends IBigNum {
2762
2819
  }): BoxedExpression;
2763
2820
  symbol(sym: string, options?: {
2764
2821
  canonical?: CanonicalOptions;
2822
+ metadata?: Metadata;
2765
2823
  }): BoxedExpression;
2766
2824
  string(s: string, metadata?: Metadata): BoxedExpression;
2767
2825
  error(message: string | string[], where?: string): BoxedExpression;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { Type, TypeResolver, TypeString } from '../common/type/types';
4
4
  import { BoxedType } from '../common/type/boxed-type';
@@ -10,8 +10,10 @@ import type { LatexDictionaryEntry, LatexString, LibraryCategory, ParseLatexOpti
10
10
  import { type IndexedLatexDictionary } from './latex-syntax/dictionary/definitions';
11
11
  import type { BigNum, Rational } from './numerics/types';
12
12
  import { ExactNumericValueData, NumericValue, NumericValueData } from './numeric-value/types';
13
+ import { validatePattern } from './boxed-expression/boxed-patterns';
13
14
  import './boxed-expression/serialize';
14
15
  export * from './global-types';
16
+ export { validatePattern };
15
17
  /**
16
18
  *
17
19
  * To use the Compute Engine, create a `ComputeEngine` instance:
@@ -566,6 +568,7 @@ export declare class ComputeEngine implements IComputeEngine {
566
568
  /** Create a boxed symbol */
567
569
  symbol(name: string, options?: {
568
570
  canonical?: CanonicalOptions;
571
+ metadata?: Metadata;
569
572
  }): BoxedExpression;
570
573
  /**
571
574
  * This function tries to avoid creating a boxed number if `num` corresponds
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_COMPLEX: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_CORE: LatexDictionary;
3
3
  export declare const DELIMITERS_SHORTHAND: {
4
4
  '(': string;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_LINEAR_ALGEBRA: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_INEQUALITIES: LatexDictionaryEntry[];
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_STATISTICS: LatexDictionary;
@@ -1,3 +1,3 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const SYMBOLS: [string, string, number][];
3
3
  export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -1,2 +1,2 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { Delimiter, EnvironmentParseHandler, ExpressionParseHandler, InfixParseHandler, LatexDictionary, LatexDictionaryEntry, LatexString, LatexToken, LibraryCategory, MatchfixParseHandler, PostfixParseHandler, Precedence, SerializeHandler } from '../types';
3
3
  export type CommonEntry = {
4
4
  /** Note: a name is required if a serialize handler is provided */
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { Parser } from './types';
3
3
  /** For error handling, if we have a symbol prefix, assume
4
4
  * the symbol is invalid (it would have been captured by
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { ParseLatexOptions, LatexToken, Terminator, Parser, SymbolTable } from './types';
3
3
  import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedSymbolEntry, IndexedExpressionEntry, IndexedFunctionEntry } from './dictionary/definitions';
4
4
  import { BoxedType } from '../../common/type/boxed-type';
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { NumberSerializationFormat } from './types';
3
3
  /**
4
4
  * @param expr - A number, can be represented as a string
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { DelimiterScale } from './types';
3
3
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): DelimiterScale;
4
4
  export declare function getGroupStyle(_expr: Expression, _level: number): DelimiterScale;
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import { LatexString, SerializeLatexOptions, DelimiterScale } from './types';
3
3
  import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
4
4
  export declare class Serializer {
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  * ## Reference
3
3
  * TeX source code:
4
4
  * {@link http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web | Tex.web}
@@ -1,4 +1,4 @@
1
- /* 0.30.1 */
1
+ /* 0.31.0 */
2
2
  import type { Expression, MathJsonSymbol } from '../../math-json/types';
3
3
  import { BoxedType, TypeString } from '../types';
4
4
  import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
@@ -450,7 +450,7 @@ export type NumberSerializationFormat = NumberFormat & {
450
450
  * Default: `"auto"`
451
451
  */
452
452
  fractionalDigits: 'auto' | 'max' | number;
453
- notation: 'auto' | 'engineering' | 'scientific';
453
+ notation: 'auto' | 'engineering' | 'scientific' | 'adaptiveScientific';
454
454
  avoidExponentsInRange: undefined | null | [negativeExponent: number, positiveExponent: number];
455
455
  };
456
456
  /**