@cortex-js/compute-engine 0.32.0 → 0.32.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 (153) hide show
  1. package/dist/compute-engine.esm.js +42905 -0
  2. package/dist/compute-engine.min.esm.js +125 -0
  3. package/dist/compute-engine.min.umd.js +127 -0
  4. package/dist/compute-engine.umd.js +42930 -0
  5. package/dist/math-json.esm.js +130 -0
  6. package/dist/math-json.min.esm.js +130 -0
  7. package/dist/math-json.min.umd.js +4 -0
  8. package/dist/math-json.umd.js +155 -0
  9. package/dist/types/common/ansi-codes.d.ts +41 -0
  10. package/dist/types/common/configuration-change.d.ts +28 -0
  11. package/dist/types/common/fuzzy-string-match.d.ts +2 -0
  12. package/dist/types/common/grapheme-splitter.d.ts +15 -0
  13. package/dist/types/common/interruptible.d.ts +20 -0
  14. package/dist/types/common/one-of.d.ts +10 -0
  15. package/dist/types/common/signals.d.ts +96 -0
  16. package/dist/types/common/type/ast-nodes.d.ts +146 -0
  17. package/dist/types/common/type/boxed-type.d.ts +30 -0
  18. package/dist/types/common/type/lexer.d.ts +51 -0
  19. package/dist/types/common/type/parse.d.ts +211 -0
  20. package/dist/types/common/type/parser.d.ts +45 -0
  21. package/dist/types/common/type/primitive.d.ts +10 -0
  22. package/dist/types/common/type/serialize.d.ts +2 -0
  23. package/dist/types/common/type/subtype.d.ts +6 -0
  24. package/dist/types/common/type/type-builder.d.ts +32 -0
  25. package/dist/types/common/type/types.d.ts +300 -0
  26. package/dist/types/common/type/utils.d.ts +36 -0
  27. package/dist/types/common/utils.d.ts +23 -0
  28. package/dist/types/compute-engine/assume.d.ts +26 -0
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +165 -0
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +16 -0
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +27 -0
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +38 -0
  34. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  35. package/dist/types/compute-engine/boxed-expression/box.d.ts +47 -0
  36. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +44 -0
  37. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +136 -0
  38. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +103 -0
  39. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +53 -0
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +107 -0
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +27 -0
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +170 -0
  43. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +83 -0
  44. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +7 -0
  46. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
  47. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -0
  48. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  49. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  50. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  51. package/dist/types/compute-engine/boxed-expression/factor.d.ts +10 -0
  52. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  53. package/dist/types/compute-engine/boxed-expression/hold.d.ts +10 -0
  54. package/dist/types/compute-engine/boxed-expression/match.d.ts +41 -0
  55. package/dist/types/compute-engine/boxed-expression/negate.d.ts +11 -0
  56. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +34 -0
  57. package/dist/types/compute-engine/boxed-expression/order.d.ts +71 -0
  58. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +105 -0
  59. package/dist/types/compute-engine/boxed-expression/product.d.ts +66 -0
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -0
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +46 -0
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +20 -0
  65. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  66. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +9 -0
  67. package/dist/types/compute-engine/boxed-expression/utils.d.ts +64 -0
  68. package/dist/types/compute-engine/boxed-expression/validate.d.ts +58 -0
  69. package/dist/types/compute-engine/collection-utils.d.ts +35 -0
  70. package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
  71. package/dist/types/compute-engine/compilation/javascript-target.d.ts +68 -0
  72. package/dist/types/compute-engine/compilation/types.d.ts +83 -0
  73. package/dist/types/compute-engine/cost-function.d.ts +13 -0
  74. package/dist/types/compute-engine/function-utils.d.ts +120 -0
  75. package/dist/types/compute-engine/global-types.d.ts +2930 -0
  76. package/dist/types/compute-engine/index.d.ts +660 -0
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +2 -0
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +27 -0
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +2 -0
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +2 -0
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
  88. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +3 -0
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  90. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +88 -0
  91. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  92. package/dist/types/compute-engine/latex-syntax/parse.d.ts +316 -0
  93. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +29 -0
  94. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +10 -0
  95. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +37 -0
  96. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +18 -0
  97. package/dist/types/compute-engine/latex-syntax/types.d.ts +896 -0
  98. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  99. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -0
  100. package/dist/types/compute-engine/library/calculus.d.ts +2 -0
  101. package/dist/types/compute-engine/library/collections.d.ts +27 -0
  102. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  103. package/dist/types/compute-engine/library/complex.d.ts +2 -0
  104. package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
  105. package/dist/types/compute-engine/library/core.d.ts +2 -0
  106. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  107. package/dist/types/compute-engine/library/library.d.ts +17 -0
  108. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
  109. package/dist/types/compute-engine/library/logic-analysis.d.ts +64 -0
  110. package/dist/types/compute-engine/library/logic-utils.d.ts +58 -0
  111. package/dist/types/compute-engine/library/logic.d.ts +7 -0
  112. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  113. package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
  114. package/dist/types/compute-engine/library/random-expression.d.ts +2 -0
  115. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
  116. package/dist/types/compute-engine/library/sets.d.ts +2 -0
  117. package/dist/types/compute-engine/library/statistics.d.ts +2 -0
  118. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
  119. package/dist/types/compute-engine/library/utils.d.ts +77 -0
  120. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +57 -0
  121. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +75 -0
  122. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +56 -0
  123. package/dist/types/compute-engine/numeric-value/types.d.ts +116 -0
  124. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  125. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  126. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  127. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -0
  128. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +18 -0
  129. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +9 -0
  130. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  131. package/dist/types/compute-engine/numerics/numeric.d.ts +60 -0
  132. package/dist/types/compute-engine/numerics/primes.d.ts +7 -0
  133. package/dist/types/compute-engine/numerics/rationals.d.ts +43 -0
  134. package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
  135. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  136. package/dist/types/compute-engine/numerics/statistics.d.ts +24 -0
  137. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  138. package/dist/types/compute-engine/numerics/types.d.ts +30 -0
  139. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  140. package/dist/types/compute-engine/symbolic/derivative.d.ts +18 -0
  141. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  142. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +6 -0
  143. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +27 -0
  144. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +6 -0
  145. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +128 -0
  146. package/dist/types/compute-engine/tensor/tensors.d.ts +93 -0
  147. package/dist/types/compute-engine/types.d.ts +8 -0
  148. package/dist/types/compute-engine.d.ts +3 -0
  149. package/dist/types/math-json/symbols.d.ts +11 -0
  150. package/dist/types/math-json/types.d.ts +122 -0
  151. package/dist/types/math-json/utils.d.ts +87 -0
  152. package/dist/types/math-json.d.ts +3 -0
  153. package/package.json +1 -1
@@ -0,0 +1,83 @@
1
+ /* 0.32.1 */
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
+ }
@@ -0,0 +1,13 @@
1
+ /* 0.32.1 */
2
+ /**
3
+ * The default cost function, used to determine if a new expression is simpler
4
+ * than the old one.
5
+ *
6
+ * To change the cost function used by the engine, set the
7
+ * `ce.costFunction` property of the engine or pass a custom cost function
8
+ * to the `simplify` function.
9
+ *
10
+ */
11
+ export declare function costFunction(expr: BoxedExpression): number;
12
+ export declare function leafCount(expr: BoxedExpression): number;
13
+ export declare const DEFAULT_COST_FUNCTION: typeof costFunction;
@@ -0,0 +1,120 @@
1
+ /* 0.32.1 */
2
+ import type { BoxedDefinition, BoxedExpression, ComputeEngine, Scope } from './global-types';
3
+ /***
4
+ * ### THEORY OF OPERATIONS
5
+ *
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.
8
+ *
9
+ * Some expressions with anonymous parameters (e.g. `["Add", "_", 1]`)
10
+ * are rewritten to a `["Function"]` expression with anonymous parameters
11
+ * (e.g. `["Function", ["Block", ["Add", "_", 1]], "_"]`).
12
+ *
13
+ *
14
+ * #### DURING BOXING (in makeLambda())
15
+ *
16
+ * During the boxing/canonicalization phase of a function
17
+ * (`["Function"]` expression or operator of expression):
18
+ *
19
+ * 1/ If not a `["Function"]` expression, the expression is rewritten
20
+ * to a `["Function"]` expression with anonymous parameters
21
+ * 2/ A new scope is created
22
+ * 3/ The function parameters are declared in the scope
23
+ * 4/ The function body is boxed in the context of the scope and the scope
24
+ * is associated with the function
25
+ *
26
+ *
27
+ * #### DURING EVALUATION (executing the result of makeLambda())
28
+ *
29
+ * 1/ The arguments are evaluated in the current scope
30
+ * 2/ The context is swapped to the function scope
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
35
+ *
36
+ */
37
+ /**
38
+ * From an expression, return a predicate function, which can be used to filter.
39
+ */
40
+ export declare function predicate(_expr: BoxedExpression): (...args: BoxedExpression[]) => boolean;
41
+ /**
42
+ * From an expression, create an ordering function, which can be used to sort.
43
+ */
44
+ export declare function order(_expr: BoxedExpression): (a: BoxedExpression, b: BoxedExpression) => -1 | 0 | 1;
45
+ /**
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"]
63
+ *
64
+ *
65
+ * - single anonymous parameters:
66
+ * ["Add", "_", 1]
67
+ * -> ["Function", ["Block", ["Add", "_", 1]], "_"]
68
+ *
69
+ * - multiple anonymous parameters:
70
+ * ["Add", "_1", "_2"]
71
+ * -> ["Function", ["Block", ["Add", "_1", "_2"]], "_1", "_2"]
72
+ *
73
+ *
74
+ */
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;
84
+ /**
85
+ * Apply arguments to an expression which is either:
86
+ * - a `["Function"]` expression
87
+ * - the symbol for a function, e.g. `Sin`.
88
+ */
89
+ export declare function apply(fn: BoxedExpression, args: ReadonlyArray<BoxedExpression>): BoxedExpression;
90
+ /**
91
+ * Return a lambda function, assuming a scoped environment has been
92
+ * created and there is a single numeric argument
93
+ */
94
+ export declare function makeLambdaN1(expr: BoxedExpression): ((arg: number) => number) | undefined;
95
+ /**
96
+ * Given an expression such as:
97
+ * - ["Function", ["Add", 1, "x"], "x"]
98
+ * - ["Function", ["Divide", "_", 2]]
99
+ * - ["Multiply, "_", 3]
100
+ * - ["Add, "_1", "_2"]
101
+ * - "Sin"
102
+ *
103
+ * return a JS function that can be called with arguments.
104
+ */
105
+ export declare function applicable(fn: BoxedExpression): (xs: ReadonlyArray<BoxedExpression>) => BoxedExpression | undefined;
106
+ /**
107
+ * Use `applicableN1()` when the function is known to be a function with a
108
+ * single real argument that returns a real value.
109
+ *
110
+ * Unlike `apply()`, `applicableN1()` returns a function that can be called
111
+ * with an argument.
112
+ *
113
+ */
114
+ export declare function applicableN1(fn: BoxedExpression): (x: number) => number;
115
+ /**
116
+ * Given a string like "f(x,y)" return, ["f", ["x", "y"]]
117
+ */
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;