@cortex-js/compute-engine 0.33.0 → 0.35.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.
- package/dist/compute-engine.esm.js +16198 -9444
- package/dist/compute-engine.min.esm.js +457 -52
- package/dist/compute-engine.min.umd.js +457 -52
- package/dist/compute-engine.umd.js +16197 -9443
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.umd.js +2 -2
- package/dist/math-json.umd.js +2 -2
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/configuration-change.d.ts +1 -1
- package/dist/types/common/fuzzy-string-match.d.ts +1 -1
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/interruptible.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/type/ast-nodes.d.ts +1 -1
- package/dist/types/common/type/boxed-type.d.ts +1 -1
- package/dist/types/common/type/lexer.d.ts +1 -1
- package/dist/types/common/type/parse.d.ts +1 -1
- package/dist/types/common/type/parser.d.ts +1 -1
- package/dist/types/common/type/primitive.d.ts +1 -1
- package/dist/types/common/type/reduce.d.ts +12 -0
- package/dist/types/common/type/serialize.d.ts +1 -1
- package/dist/types/common/type/subtype.d.ts +1 -1
- package/dist/types/common/type/type-builder.d.ts +1 -1
- package/dist/types/common/type/types.d.ts +1 -1
- package/dist/types/common/type/utils.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +37 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +5 -3
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +2 -1
- package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +5 -1
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +47 -1
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +60 -0
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
- package/dist/types/compute-engine/compilation/glsl-target.d.ts +63 -0
- package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +51 -0
- package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +93 -0
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +68 -0
- package/dist/types/compute-engine/compilation/types.d.ts +140 -0
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/global-types.d.ts +340 -8
- package/dist/types/compute-engine/index.d.ts +188 -3
- package/dist/types/compute-engine/interval/arithmetic.d.ts +56 -0
- package/dist/types/compute-engine/interval/comparison.d.ts +70 -0
- package/dist/types/compute-engine/interval/elementary.d.ts +100 -0
- package/dist/types/compute-engine/interval/index.d.ts +93 -0
- package/dist/types/compute-engine/interval/trigonometric.d.ts +105 -0
- package/dist/types/compute-engine/interval/types.d.ts +50 -0
- package/dist/types/compute-engine/interval/util.d.ts +99 -0
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +8 -1
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +21 -1
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/types.d.ts +23 -2
- package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic-analysis.d.ts +159 -4
- package/dist/types/compute-engine/library/logic-utils.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
- package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
- package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/numerics/types.d.ts +1 -1
- package/dist/types/compute-engine/oeis.d.ts +85 -0
- package/dist/types/compute-engine/sequence.d.ts +120 -0
- package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +17 -2
- package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
- package/dist/types/compute-engine/types.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +5 -1
- package/dist/types/math-json/symbols.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* 0.35.0 */
|
|
2
|
+
/**
|
|
3
|
+
* Solve a system of linear equations.
|
|
4
|
+
*
|
|
5
|
+
* @param equations - Array of BoxedExpression representing equations (Equal expressions)
|
|
6
|
+
* @param variables - Array of variable names to solve for
|
|
7
|
+
* @returns Object mapping variable names to their solutions, or null if unsolvable
|
|
8
|
+
*
|
|
9
|
+
* For under-determined systems (fewer equations than variables), returns
|
|
10
|
+
* parametric solutions where free variables appear in the expressions.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Unique solution
|
|
15
|
+
* const e = ce.parse('\\begin{cases}x+y=70\\\\2x-4y=80\\end{cases}');
|
|
16
|
+
* const result = e.solve(['x', 'y']);
|
|
17
|
+
* // result = { x: BoxedExpression(60), y: BoxedExpression(10) }
|
|
18
|
+
*
|
|
19
|
+
* // Parametric solution (under-determined)
|
|
20
|
+
* const e2 = ce.parse('\\begin{cases}x+y=5\\end{cases}');
|
|
21
|
+
* const result2 = e2.solve(['x', 'y']);
|
|
22
|
+
* // result2 = { x: 5 - y, y: y }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function solveLinearSystem(equations: BoxedExpression[], variables: string[]): Record<string, BoxedExpression> | null;
|
|
26
|
+
/**
|
|
27
|
+
* Solve a system of polynomial equations that may be non-linear.
|
|
28
|
+
* Currently supports:
|
|
29
|
+
* 1. Product + sum pattern: xy = p, x + y = s (2 equations, 2 variables)
|
|
30
|
+
* 2. Substitution-reducible: one equation is linear in one variable
|
|
31
|
+
*
|
|
32
|
+
* @param equations - Array of BoxedExpression representing equations (Equal expressions)
|
|
33
|
+
* @param variables - Array of variable names to solve for
|
|
34
|
+
* @returns Array of solution objects, or null if unsolvable
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Product + sum pattern
|
|
39
|
+
* const e = ce.parse('\\begin{cases}xy=6\\\\x+y=5\\end{cases}');
|
|
40
|
+
* const result = e.solve(['x', 'y']);
|
|
41
|
+
* // result = [{ x: 2, y: 3 }, { x: 3, y: 2 }]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function solvePolynomialSystem(equations: BoxedExpression[], variables: string[]): Array<Record<string, BoxedExpression>> | null;
|
|
45
|
+
/**
|
|
46
|
+
* Solve a system of linear inequalities in 2 variables.
|
|
47
|
+
* Returns the vertices of the feasible region (convex polygon).
|
|
48
|
+
*
|
|
49
|
+
* @param inequalities - Array of BoxedExpression representing inequalities
|
|
50
|
+
* @param variables - Array of exactly 2 variable names
|
|
51
|
+
* @returns Array of vertex coordinate objects, or null if unsolvable/unbounded
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const e = ce.parse('\\begin{cases}x+y\\leq 10\\\\x\\geq 0\\\\y\\geq 0\\end{cases}');
|
|
56
|
+
* const result = e.solve(['x', 'y']);
|
|
57
|
+
* // result = [{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 0, y: 10 }]
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function solveLinearInequalitySystem(inequalities: BoxedExpression[], variables: string[]): Array<Record<string, BoxedExpression>> | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.
|
|
1
|
+
/* 0.35.0 */
|
|
2
2
|
/** Assuming x in an expression in radians, convert to current angular unit. */
|
|
3
3
|
export declare function radiansToAngle(x: BoxedExpression | undefined): BoxedExpression | undefined;
|
|
4
4
|
export declare function evalTrig(name: string, op: BoxedExpression | undefined): BoxedExpression | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* 0.35.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
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* 0.35.0 */
|
|
2
|
+
import type { CompileTarget, CompiledOperators, CompiledFunctions, LanguageTarget, CompilationOptions, CompiledExecutable } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* GLSL language target implementation
|
|
5
|
+
*/
|
|
6
|
+
export declare class GLSLTarget implements LanguageTarget {
|
|
7
|
+
getOperators(): CompiledOperators;
|
|
8
|
+
getFunctions(): CompiledFunctions;
|
|
9
|
+
createTarget(options?: Partial<CompileTarget>): CompileTarget;
|
|
10
|
+
/**
|
|
11
|
+
* Compile to GLSL source code (not executable)
|
|
12
|
+
*
|
|
13
|
+
* GLSL doesn't run in JavaScript, so this returns source code as a string
|
|
14
|
+
* rather than an executable function.
|
|
15
|
+
*/
|
|
16
|
+
compileToExecutable(expr: BoxedExpression, options?: CompilationOptions): CompiledExecutable;
|
|
17
|
+
/**
|
|
18
|
+
* Compile an expression to GLSL source code
|
|
19
|
+
*
|
|
20
|
+
* Returns the GLSL code as a string.
|
|
21
|
+
*/
|
|
22
|
+
compile(expr: BoxedExpression, options?: CompilationOptions): string;
|
|
23
|
+
/**
|
|
24
|
+
* Create a complete GLSL function from an expression
|
|
25
|
+
*
|
|
26
|
+
* @param expr - The expression to compile
|
|
27
|
+
* @param functionName - Name of the GLSL function
|
|
28
|
+
* @param returnType - GLSL return type (e.g., 'float', 'vec3')
|
|
29
|
+
* @param parameters - Parameter declarations (e.g., [['x', 'float'], ['y', 'vec3']])
|
|
30
|
+
*/
|
|
31
|
+
compileFunction(expr: BoxedExpression, functionName: string, returnType: string, parameters: Array<[name: string, type: string]>): string;
|
|
32
|
+
/**
|
|
33
|
+
* Create a complete GLSL shader from expressions
|
|
34
|
+
*
|
|
35
|
+
* @param options - Shader compilation options
|
|
36
|
+
*/
|
|
37
|
+
compileShader(options: {
|
|
38
|
+
/** Shader type: 'vertex' or 'fragment' */
|
|
39
|
+
type: 'vertex' | 'fragment';
|
|
40
|
+
/** GLSL version (e.g., '300 es', '330', '450') */
|
|
41
|
+
version?: string;
|
|
42
|
+
/** Input variables (attributes or varyings) */
|
|
43
|
+
inputs?: Array<{
|
|
44
|
+
name: string;
|
|
45
|
+
type: string;
|
|
46
|
+
}>;
|
|
47
|
+
/** Output variables */
|
|
48
|
+
outputs?: Array<{
|
|
49
|
+
name: string;
|
|
50
|
+
type: string;
|
|
51
|
+
}>;
|
|
52
|
+
/** Uniform variables */
|
|
53
|
+
uniforms?: Array<{
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
}>;
|
|
57
|
+
/** Main function body expressions */
|
|
58
|
+
body: Array<{
|
|
59
|
+
variable: string;
|
|
60
|
+
expression: BoxedExpression;
|
|
61
|
+
}>;
|
|
62
|
+
}): string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* 0.35.0 */
|
|
2
|
+
* GLSL interval arithmetic compilation target
|
|
3
|
+
*
|
|
4
|
+
* Compiles mathematical expressions to GLSL code using interval arithmetic
|
|
5
|
+
* for reliable function evaluation in shaders.
|
|
6
|
+
*
|
|
7
|
+
* Intervals are represented as vec2(lo, hi).
|
|
8
|
+
* Status flags use float constants for shader compatibility.
|
|
9
|
+
*
|
|
10
|
+
* @module compilation/interval-glsl-target
|
|
11
|
+
*/
|
|
12
|
+
import type { BoxedExpression } from '../global-types';
|
|
13
|
+
import type { CompileTarget, CompiledOperators, CompiledFunctions, LanguageTarget, CompilationOptions, CompiledExecutable } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* GLSL interval arithmetic target implementation.
|
|
16
|
+
*/
|
|
17
|
+
export declare class IntervalGLSLTarget implements LanguageTarget {
|
|
18
|
+
getOperators(): CompiledOperators;
|
|
19
|
+
getFunctions(): CompiledFunctions;
|
|
20
|
+
/**
|
|
21
|
+
* Get the GLSL interval library code.
|
|
22
|
+
*
|
|
23
|
+
* This should be included in shaders that use interval arithmetic.
|
|
24
|
+
*/
|
|
25
|
+
getLibrary(): string;
|
|
26
|
+
createTarget(options?: Partial<CompileTarget>): CompileTarget;
|
|
27
|
+
compileToExecutable(expr: BoxedExpression, options?: CompilationOptions): CompiledExecutable;
|
|
28
|
+
/**
|
|
29
|
+
* Compile an expression to GLSL interval code.
|
|
30
|
+
*/
|
|
31
|
+
compile(expr: BoxedExpression, options?: CompilationOptions): string;
|
|
32
|
+
/**
|
|
33
|
+
* Create a complete GLSL interval function from an expression.
|
|
34
|
+
*
|
|
35
|
+
* @param expr - The expression to compile
|
|
36
|
+
* @param functionName - Name of the GLSL function
|
|
37
|
+
* @param parameters - Parameter names (each becomes a vec2 interval input)
|
|
38
|
+
*/
|
|
39
|
+
compileFunction(expr: BoxedExpression, functionName: string, parameters: string[]): string;
|
|
40
|
+
/**
|
|
41
|
+
* Create a complete GLSL fragment shader for interval function plotting.
|
|
42
|
+
*
|
|
43
|
+
* @param expr - The expression to compile
|
|
44
|
+
* @param options - Shader options
|
|
45
|
+
*/
|
|
46
|
+
compileShaderFunction(expr: BoxedExpression, options?: {
|
|
47
|
+
functionName?: string;
|
|
48
|
+
version?: string;
|
|
49
|
+
parameters?: string[];
|
|
50
|
+
}): string;
|
|
51
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* 0.35.0 */
|
|
2
|
+
* JavaScript interval arithmetic compilation target
|
|
3
|
+
*
|
|
4
|
+
* Compiles mathematical expressions to JavaScript code using interval arithmetic
|
|
5
|
+
* for reliable function evaluation with singularity detection.
|
|
6
|
+
*
|
|
7
|
+
* @module compilation/interval-javascript-target
|
|
8
|
+
*/
|
|
9
|
+
import type { BoxedExpression } from '../global-types';
|
|
10
|
+
import type { CompileTarget, CompiledOperators, CompiledFunctions, LanguageTarget, CompilationOptions, CompiledExecutable } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* JavaScript function that wraps compiled interval arithmetic code.
|
|
13
|
+
*
|
|
14
|
+
* Injects the _IA library and provides input conversion from various formats.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ComputeEngineIntervalFunction extends Function {
|
|
17
|
+
IA: {
|
|
18
|
+
ok: typeof import("../interval").ok;
|
|
19
|
+
point: typeof import("../interval").point;
|
|
20
|
+
containsExtremum: typeof import("../interval").containsExtremum;
|
|
21
|
+
unionResults: typeof import("../interval").unionResults;
|
|
22
|
+
mergeDomainClip: typeof import("../interval").mergeDomainClip;
|
|
23
|
+
isPoint: typeof import("../interval").isPoint;
|
|
24
|
+
containsZero: typeof import("../interval").containsZero;
|
|
25
|
+
isPositive: typeof import("../interval").isPositive;
|
|
26
|
+
isNegative: typeof import("../interval").isNegative;
|
|
27
|
+
isNonNegative: typeof import("../interval").isNonNegative;
|
|
28
|
+
isNonPositive: typeof import("../interval").isNonPositive;
|
|
29
|
+
width: typeof import("../interval").width;
|
|
30
|
+
midpoint: typeof import("../interval").midpoint;
|
|
31
|
+
getValue: typeof import("../interval").getValue;
|
|
32
|
+
unwrap: typeof import("../interval").unwrap;
|
|
33
|
+
unwrapOrPropagate: typeof import("../interval").unwrapOrPropagate;
|
|
34
|
+
add: typeof import("../interval").add;
|
|
35
|
+
sub: typeof import("../interval").sub;
|
|
36
|
+
mul: typeof import("../interval").mul;
|
|
37
|
+
div: typeof import("../interval").div;
|
|
38
|
+
negate: typeof import("../interval").negate;
|
|
39
|
+
sqrt: typeof import("../interval").sqrt;
|
|
40
|
+
square: typeof import("../interval").square;
|
|
41
|
+
pow: typeof import("../interval").pow;
|
|
42
|
+
powInterval: typeof import("../interval").powInterval;
|
|
43
|
+
exp: typeof import("../interval").exp;
|
|
44
|
+
ln: typeof import("../interval").ln;
|
|
45
|
+
log10: typeof import("../interval").log10;
|
|
46
|
+
log2: typeof import("../interval").log2;
|
|
47
|
+
abs: typeof import("../interval").abs;
|
|
48
|
+
floor: typeof import("../interval").floor;
|
|
49
|
+
ceil: typeof import("../interval").ceil;
|
|
50
|
+
round: typeof import("../interval").round;
|
|
51
|
+
min: typeof import("../interval").min;
|
|
52
|
+
max: typeof import("../interval").max;
|
|
53
|
+
mod: typeof import("../interval").mod;
|
|
54
|
+
sign: typeof import("../interval").sign;
|
|
55
|
+
sin: typeof import("../interval").sin;
|
|
56
|
+
cos: typeof import("../interval").cos;
|
|
57
|
+
tan: typeof import("../interval").tan;
|
|
58
|
+
cot: typeof import("../interval").cot;
|
|
59
|
+
sec: typeof import("../interval").sec;
|
|
60
|
+
csc: typeof import("../interval").csc;
|
|
61
|
+
asin: typeof import("../interval").asin;
|
|
62
|
+
acos: typeof import("../interval").acos;
|
|
63
|
+
atan: typeof import("../interval").atan;
|
|
64
|
+
atan2: typeof import("../interval").atan2;
|
|
65
|
+
sinh: typeof import("../interval").sinh;
|
|
66
|
+
cosh: typeof import("../interval").cosh;
|
|
67
|
+
tanh: typeof import("../interval").tanh;
|
|
68
|
+
asinh: typeof import("../interval").asinh;
|
|
69
|
+
acosh: typeof import("../interval").acosh;
|
|
70
|
+
atanh: typeof import("../interval").atanh;
|
|
71
|
+
less: typeof import("../interval").less;
|
|
72
|
+
lessEqual: typeof import("../interval").lessEqual;
|
|
73
|
+
greater: typeof import("../interval").greater;
|
|
74
|
+
greaterEqual: typeof import("../interval").greaterEqual;
|
|
75
|
+
equal: typeof import("../interval").equal;
|
|
76
|
+
notEqual: typeof import("../interval").notEqual;
|
|
77
|
+
and: typeof import("../interval").and;
|
|
78
|
+
or: typeof import("../interval").or;
|
|
79
|
+
not: typeof import("../interval").not;
|
|
80
|
+
piecewise: typeof import("../interval").piecewise;
|
|
81
|
+
clamp: typeof import("../interval").clamp;
|
|
82
|
+
};
|
|
83
|
+
constructor(body: string, preamble?: string);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Interval arithmetic JavaScript target implementation.
|
|
87
|
+
*/
|
|
88
|
+
export declare class IntervalJavaScriptTarget implements LanguageTarget {
|
|
89
|
+
getOperators(): CompiledOperators;
|
|
90
|
+
getFunctions(): CompiledFunctions;
|
|
91
|
+
createTarget(options?: Partial<CompileTarget>): CompileTarget;
|
|
92
|
+
compileToExecutable(expr: BoxedExpression, options?: CompilationOptions): CompiledExecutable;
|
|
93
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* 0.35.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
|
+
*/
|
|
9
|
+
export declare class ComputeEngineFunction extends Function {
|
|
10
|
+
SYS: {
|
|
11
|
+
chop: typeof chop;
|
|
12
|
+
factorial: typeof factorial;
|
|
13
|
+
gamma: typeof gamma;
|
|
14
|
+
gcd: typeof gcd;
|
|
15
|
+
integrate: (f: any, a: any, b: any) => number;
|
|
16
|
+
lcm: typeof lcm;
|
|
17
|
+
lngamma: typeof gammaln;
|
|
18
|
+
limit: typeof limit;
|
|
19
|
+
mean: typeof mean;
|
|
20
|
+
median: typeof median;
|
|
21
|
+
variance: typeof variance;
|
|
22
|
+
populationVariance: typeof populationVariance;
|
|
23
|
+
standardDeviation: typeof standardDeviation;
|
|
24
|
+
populationStandardDeviation: typeof populationStandardDeviation;
|
|
25
|
+
kurtosis: typeof kurtosis;
|
|
26
|
+
skewness: typeof skewness;
|
|
27
|
+
mode: typeof mode;
|
|
28
|
+
quartiles: typeof quartiles;
|
|
29
|
+
interquartileRange: typeof interquartileRange;
|
|
30
|
+
};
|
|
31
|
+
constructor(body: string, preamble?: string);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* JavaScript function literal with parameters
|
|
35
|
+
*/
|
|
36
|
+
export declare class ComputeEngineFunctionLiteral extends Function {
|
|
37
|
+
SYS: {
|
|
38
|
+
chop: typeof chop;
|
|
39
|
+
factorial: typeof factorial;
|
|
40
|
+
gamma: typeof gamma;
|
|
41
|
+
gcd: typeof gcd;
|
|
42
|
+
integrate: (f: any, a: any, b: any) => number;
|
|
43
|
+
lcm: typeof lcm;
|
|
44
|
+
lngamma: typeof gammaln;
|
|
45
|
+
limit: typeof limit;
|
|
46
|
+
mean: typeof mean;
|
|
47
|
+
median: typeof median;
|
|
48
|
+
variance: typeof variance;
|
|
49
|
+
populationVariance: typeof populationVariance;
|
|
50
|
+
standardDeviation: typeof standardDeviation;
|
|
51
|
+
populationStandardDeviation: typeof populationStandardDeviation;
|
|
52
|
+
kurtosis: typeof kurtosis;
|
|
53
|
+
skewness: typeof skewness;
|
|
54
|
+
mode: typeof mode;
|
|
55
|
+
quartiles: typeof quartiles;
|
|
56
|
+
interquartileRange: typeof interquartileRange;
|
|
57
|
+
};
|
|
58
|
+
constructor(body: string, args: string[]);
|
|
59
|
+
}
|
|
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,140 @@
|
|
|
1
|
+
/* 0.35.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
|
+
/**
|
|
65
|
+
* Target language for compilation.
|
|
66
|
+
*
|
|
67
|
+
* Built-in targets:
|
|
68
|
+
* - `'javascript'` (default) - Compile to JavaScript
|
|
69
|
+
* - `'glsl'` - Compile to GLSL (OpenGL Shading Language)
|
|
70
|
+
*
|
|
71
|
+
* Custom targets can be registered using `ce.registerCompilationTarget()`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Compile to GLSL
|
|
76
|
+
* const glslCode = expr.compile({ to: 'glsl' });
|
|
77
|
+
*
|
|
78
|
+
* // Compile to custom target
|
|
79
|
+
* ce.registerCompilationTarget('python', new PythonTarget());
|
|
80
|
+
* const pythonCode = expr.compile({ to: 'python' });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
to?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Direct compilation target override.
|
|
86
|
+
*
|
|
87
|
+
* When provided, this takes precedence over the `to` option.
|
|
88
|
+
* Useful for one-off custom targets without registration.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const customTarget: CompileTarget = {
|
|
93
|
+
* language: 'custom',
|
|
94
|
+
* operators: (op) => ...,
|
|
95
|
+
* functions: (id) => ...,
|
|
96
|
+
* // ... other methods
|
|
97
|
+
* };
|
|
98
|
+
*
|
|
99
|
+
* const code = expr.compile({ target: customTarget });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
target?: CompileTarget;
|
|
103
|
+
/**
|
|
104
|
+
* Custom operator mappings. Can be:
|
|
105
|
+
* - A partial object mapping operator names to [operator, precedence] tuples
|
|
106
|
+
* - A function that returns the operator mapping for a given symbol
|
|
107
|
+
*
|
|
108
|
+
* When an operator is overridden, it will be compiled using the specified
|
|
109
|
+
* string and precedence instead of the default for the target language.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Override operators as object
|
|
114
|
+
* { operators: { Add: ['add', 11], Multiply: ['mul', 12] } }
|
|
115
|
+
*
|
|
116
|
+
* // Override operators as function
|
|
117
|
+
* { operators: (op) => op === 'Add' ? ['add', 11] : undefined }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
operators?: Partial<CompiledOperators> | ((op: MathJsonSymbol) => [op: string, prec: number] | undefined);
|
|
121
|
+
/** Custom function implementations */
|
|
122
|
+
functions?: Record<MathJsonSymbol, TargetSource | Function>;
|
|
123
|
+
/** Variable bindings */
|
|
124
|
+
vars?: Record<MathJsonSymbol, TargetSource>;
|
|
125
|
+
/** Additional imports/libraries to include */
|
|
126
|
+
imports?: unknown[];
|
|
127
|
+
/** Additional preamble code */
|
|
128
|
+
preamble?: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A compiled expression that can be executed
|
|
132
|
+
*/
|
|
133
|
+
export interface CompiledExecutable {
|
|
134
|
+
/** Execute the compiled code */
|
|
135
|
+
(...args: any[]): any;
|
|
136
|
+
/** Get the source code */
|
|
137
|
+
toString(): string;
|
|
138
|
+
/** Flag indicating this is a compiled expression */
|
|
139
|
+
isCompiled: true;
|
|
140
|
+
}
|