@cortex-js/compute-engine 0.60.0 → 0.61.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/compile.esm.js +1270 -25
- package/dist/compile.min.esm.js +324 -78
- package/dist/compile.min.umd.cjs +324 -78
- package/dist/compile.umd.cjs +1270 -25
- package/dist/compute-engine.esm.js +867 -26
- package/dist/compute-engine.min.esm.js +329 -83
- package/dist/compute-engine.min.umd.cjs +329 -83
- package/dist/compute-engine.umd.cjs +867 -26
- package/dist/core.esm.js +855 -24
- package/dist/core.min.esm.js +330 -84
- package/dist/core.min.umd.cjs +330 -84
- package/dist/core.umd.cjs +855 -24
- package/dist/identities.esm.js +2 -2
- package/dist/identities.min.esm.js +2 -2
- package/dist/identities.min.umd.cjs +2 -2
- package/dist/identities.umd.cjs +2 -2
- package/dist/integration-rules.esm.js +2 -2
- package/dist/integration-rules.min.esm.js +2 -2
- package/dist/integration-rules.min.umd.cjs +2 -2
- package/dist/integration-rules.umd.cjs +2 -2
- package/dist/interval.esm.js +2 -2
- package/dist/interval.min.esm.js +2 -2
- package/dist/interval.min.umd.cjs +2 -2
- package/dist/interval.umd.cjs +2 -2
- package/dist/latex-syntax.esm.js +2 -2
- package/dist/latex-syntax.min.esm.js +2 -2
- package/dist/latex-syntax.min.umd.cjs +2 -2
- package/dist/latex-syntax.umd.cjs +2 -2
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.umd.cjs +2 -2
- package/dist/math-json.umd.cjs +2 -2
- package/dist/numerics.esm.js +2 -2
- package/dist/numerics.min.esm.js +2 -2
- package/dist/numerics.min.umd.cjs +2 -2
- package/dist/numerics.umd.cjs +2 -2
- package/dist/types/big-decimal/big-decimal.d.ts +1 -1
- package/dist/types/big-decimal/index.d.ts +1 -1
- package/dist/types/big-decimal/transcendentals.d.ts +1 -1
- package/dist/types/big-decimal/utils.d.ts +1 -1
- 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 +1 -1
- 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/compile.d.ts +2 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -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/constants.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/exp-to-trig.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 +1 -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/inequality-bounds.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/multivariate-gcd.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/multivariate-poly.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/pattern-utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/rule-index.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 +1 -1
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/type-guards.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 +79 -1
- package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
- package/dist/types/compute-engine/compilation/constant-folding.d.ts +1 -1
- package/dist/types/compute-engine/compilation/glsl-target.d.ts +2 -2
- package/dist/types/compute-engine/compilation/gpu-target.d.ts +7 -1
- package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +49 -0
- package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +30 -2
- package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/types.d.ts +54 -2
- package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
- package/dist/types/compute-engine/engine-cache.d.ts +1 -1
- package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
- package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
- package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
- package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
- package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
- package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
- package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
- package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
- package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
- package/dist/types/compute-engine/engine-scope.d.ts +1 -1
- package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
- package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
- package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
- package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
- package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
- package/dist/types/compute-engine/free-functions.d.ts +1 -1
- package/dist/types/compute-engine/function-properties/index.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/fungrim/loader.d.ts +1 -1
- package/dist/types/compute-engine/fungrim/types.d.ts +1 -1
- package/dist/types/compute-engine/global-types.d.ts +1 -1
- package/dist/types/compute-engine/index.d.ts +10 -1
- package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
- package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
- package/dist/types/compute-engine/interval/index.d.ts +1 -1
- package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
- package/dist/types/compute-engine/interval/types.d.ts +1 -1
- package/dist/types/compute-engine/interval/util.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
- 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-colors.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-units.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -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 +1 -1
- 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/colors.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/fractals.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 +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/quantity-arithmetic.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/special-functions.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/type-handlers.d.ts +1 -1
- package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
- package/dist/types/compute-engine/library/units.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/bernoulli.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/complex-esm-augment.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/linear-algebra.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/oscillatory-quadrature.d.ts +1 -1
- package/dist/types/compute-engine/numerics/polynomial-roots.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/random.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/numerics/unit-data.d.ts +1 -1
- package/dist/types/compute-engine/oeis.d.ts +1 -1
- package/dist/types/compute-engine/rubi/compile.d.ts +1 -1
- package/dist/types/compute-engine/rubi/driver.d.ts +1 -1
- package/dist/types/compute-engine/rubi/loader.d.ts +1 -1
- package/dist/types/compute-engine/rubi/match.d.ts +1 -1
- package/dist/types/compute-engine/rubi/normal-form.d.ts +1 -1
- package/dist/types/compute-engine/rubi/rubi-utils.d.ts +1 -1
- package/dist/types/compute-engine/rubi/types.d.ts +1 -1
- package/dist/types/compute-engine/sequence.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- 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/limit.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/residue.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-factorial.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-logic.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-definitions.d.ts +1 -1
- package/dist/types/compute-engine/types-engine.d.ts +11 -1
- package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
- package/dist/types/compute-engine/types-expression.d.ts +1 -1
- package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
- package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
- package/dist/types/compute-engine/types-serialization.d.ts +1 -1
- package/dist/types/compute-engine/types.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +1 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/identities.d.ts +1 -1
- package/dist/types/integration-rules.d.ts +1 -1
- package/dist/types/interval.d.ts +1 -1
- package/dist/types/latex-syntax.d.ts +2 -2
- 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/dist/types/numerics.d.ts +1 -1
- package/package.json +1 -1
package/dist/compile.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 0.
|
|
1
|
+
/** Compute Engine 0.61.0 */
|
|
2
2
|
|
|
3
3
|
// src/common/interruptible.ts
|
|
4
4
|
var CancellationError = class extends Error {
|
|
@@ -4524,10 +4524,18 @@ function canonicalFunctionLiteral(expr) {
|
|
|
4524
4524
|
}
|
|
4525
4525
|
function canonicalFunctionLiteralArguments(ce, ops) {
|
|
4526
4526
|
if (ops.length === 0) return void 0;
|
|
4527
|
-
const block = ops[0].operator === "Block" ? ops[0].canonical : ce.function("Block", [ops[0]]);
|
|
4528
4527
|
const params = ops.slice(1).map(
|
|
4529
4528
|
(x) => isSymbol2(x) ? x : ce.error("expected-a-symbol", x.toString())
|
|
4530
4529
|
);
|
|
4530
|
+
ce._pushShadowedParameters(
|
|
4531
|
+
params.filter((p) => isSymbol2(p)).map((p) => p.symbol)
|
|
4532
|
+
);
|
|
4533
|
+
let block;
|
|
4534
|
+
try {
|
|
4535
|
+
block = ops[0].operator === "Block" ? ops[0].canonical : ce.function("Block", [ops[0]]);
|
|
4536
|
+
} finally {
|
|
4537
|
+
ce._popShadowedParameters();
|
|
4538
|
+
}
|
|
4531
4539
|
console.assert(block.isScoped);
|
|
4532
4540
|
for (const param of params) {
|
|
4533
4541
|
if (isSymbol2(param) && !block.localScope.bindings.has(param.symbol)) {
|
|
@@ -16721,6 +16729,13 @@ function normalizeIndexingSet(indexingSet) {
|
|
|
16721
16729
|
|
|
16722
16730
|
// src/compute-engine/compilation/base-compiler.ts
|
|
16723
16731
|
var BaseCompiler = class _BaseCompiler {
|
|
16732
|
+
/**
|
|
16733
|
+
* Precedence used when compiling a folded symbol value. Higher than any
|
|
16734
|
+
* target's infix operator precedence, so a compound value parenthesizes
|
|
16735
|
+
* itself when spliced into a surrounding expression. See
|
|
16736
|
+
* `tryFoldKnownSymbol`.
|
|
16737
|
+
*/
|
|
16738
|
+
static FOLD_OPERAND_PREC = 1e3;
|
|
16724
16739
|
/**
|
|
16725
16740
|
* Compile an expression to target language source code
|
|
16726
16741
|
*/
|
|
@@ -16737,7 +16752,9 @@ var BaseCompiler = class _BaseCompiler {
|
|
|
16737
16752
|
if (op !== void 0) {
|
|
16738
16753
|
return `(a,b) => a ${op[0]} b`;
|
|
16739
16754
|
}
|
|
16740
|
-
|
|
16755
|
+
const resolved = target.var?.(s);
|
|
16756
|
+
if (resolved !== void 0) return resolved;
|
|
16757
|
+
return _BaseCompiler.tryFoldKnownSymbol(expr.engine, s, target) ?? s;
|
|
16741
16758
|
}
|
|
16742
16759
|
if (isNumber(expr)) {
|
|
16743
16760
|
if (expr.im !== 0) {
|
|
@@ -17063,10 +17080,10 @@ var BaseCompiler = class _BaseCompiler {
|
|
|
17063
17080
|
)
|
|
17064
17081
|
);
|
|
17065
17082
|
const needsWrap2 = target.number(0) !== "0";
|
|
17066
|
-
const bodyTarget2 =
|
|
17083
|
+
const bodyTarget2 = {
|
|
17067
17084
|
...target,
|
|
17068
|
-
var: (id) => loopVarSet.has(id) ? target.number(0).replace("0", id) : target.var(id)
|
|
17069
|
-
}
|
|
17085
|
+
var: (id) => loopVarSet.has(id) ? needsWrap2 ? target.number(0).replace("0", id) : id : target.var(id)
|
|
17086
|
+
};
|
|
17070
17087
|
const bodyCode = _BaseCompiler.compile(body, bodyTarget2);
|
|
17071
17088
|
let inner = `result.push(${bodyCode});`;
|
|
17072
17089
|
for (let i = narrowedElements.length - 1; i >= 0; i--) {
|
|
@@ -17364,6 +17381,167 @@ var BaseCompiler = class _BaseCompiler {
|
|
|
17364
17381
|
if (isNumber(expr)) return expr.im === 0 && expr.re >= 0;
|
|
17365
17382
|
return expr.isNonNegative === true;
|
|
17366
17383
|
}
|
|
17384
|
+
/**
|
|
17385
|
+
* If `id` names a symbol that is *known* to the engine — it has an assigned
|
|
17386
|
+
* value (`ce.assign("a", 1.5)`) or is a declared constant — return the
|
|
17387
|
+
* compiled target code for that value, i.e. **fold** the value into the
|
|
17388
|
+
* generated code the way `evaluate()` does. Returns `undefined` for a
|
|
17389
|
+
* genuinely free symbol (no value), so the caller falls back to its
|
|
17390
|
+
* free-symbol plumbing (a `vars` mapping, a `_.id` argument lookup, or a
|
|
17391
|
+
* declarable identifier).
|
|
17392
|
+
*
|
|
17393
|
+
* This keeps the compiled output consistent with `expr.unknowns` and
|
|
17394
|
+
* `evaluate()`: a symbol they treat as known (folded / dropped) is also
|
|
17395
|
+
* folded by `compile()`, instead of being emitted as a bare, dangling
|
|
17396
|
+
* reference (an undeclared GLSL identifier, or a bare JS global that throws
|
|
17397
|
+
* `ReferenceError` at run time).
|
|
17398
|
+
*
|
|
17399
|
+
* Callers MUST resolve any `vars` mapping for `id` **before** calling this,
|
|
17400
|
+
* so an explicitly `vars`-mapped symbol is never folded — the GPU/JS live
|
|
17401
|
+
* path relies on a mapped symbol staying a per-frame uniform / argument.
|
|
17402
|
+
*
|
|
17403
|
+
* `target` is the in-flight target: nested symbols inside the value resolve
|
|
17404
|
+
* through the same `vars`/constant/fold rules as the top-level expression.
|
|
17405
|
+
*
|
|
17406
|
+
* The value is compiled at a high precedence so a compound (operator) value
|
|
17407
|
+
* self-parenthesizes: folding `b = c + 1` into `b * x` must yield
|
|
17408
|
+
* `(c + 1) * x`, not `c + 1 * x`, and must stay safe when a handler splices
|
|
17409
|
+
* the folded string into its own expression (e.g. `Power`'s `(code * code)`).
|
|
17410
|
+
* An atomic value (number, symbol, function call) ignores the precedence, so
|
|
17411
|
+
* no redundant parentheses are added in the common assigned-number case.
|
|
17412
|
+
*/
|
|
17413
|
+
static tryFoldKnownSymbol(engine, id, target) {
|
|
17414
|
+
const value = engine._getSymbolValue(id);
|
|
17415
|
+
if (value === void 0) return void 0;
|
|
17416
|
+
return _BaseCompiler.compile(value, target, _BaseCompiler.FOLD_OPERAND_PREC);
|
|
17417
|
+
}
|
|
17418
|
+
/**
|
|
17419
|
+
* Operator heads the compiler lowers directly in `compileExpr`, independent
|
|
17420
|
+
* of any target operator/function mapping (control-flow, binding, and
|
|
17421
|
+
* indexing-set forms). `analyzeReferences` never reports these as
|
|
17422
|
+
* "unsupported".
|
|
17423
|
+
*/
|
|
17424
|
+
static STRUCTURAL_HEADS = /* @__PURE__ */ new Set([
|
|
17425
|
+
"Sequence",
|
|
17426
|
+
"Sum",
|
|
17427
|
+
"Product",
|
|
17428
|
+
"Function",
|
|
17429
|
+
"Declare",
|
|
17430
|
+
"Assign",
|
|
17431
|
+
"Return",
|
|
17432
|
+
"Break",
|
|
17433
|
+
"Continue",
|
|
17434
|
+
"Loop",
|
|
17435
|
+
"If",
|
|
17436
|
+
"Which",
|
|
17437
|
+
"When",
|
|
17438
|
+
"Block",
|
|
17439
|
+
// Indexing-set wrappers consumed by Sum/Product/Loop — never compiled
|
|
17440
|
+
// standalone.
|
|
17441
|
+
"Limits",
|
|
17442
|
+
"Element"
|
|
17443
|
+
]);
|
|
17444
|
+
/**
|
|
17445
|
+
* Analyze — without compiling, and never throwing — which external references
|
|
17446
|
+
* the generated code for `expr` would have on `target`:
|
|
17447
|
+
*
|
|
17448
|
+
* - `freeSymbols`: identifiers the caller must supply at run time. These are
|
|
17449
|
+
* the free symbols *as codegen sees them*: symbols with no value in the
|
|
17450
|
+
* engine, after descending into the values of folded (assigned / constant)
|
|
17451
|
+
* symbols — so `a = b + 1` surfaces `b`, which `expr.unknowns` misses — and
|
|
17452
|
+
* after excluding bound variables (lambda parameters, indices of
|
|
17453
|
+
* `Sum`/`Product`/`Integrate`/`Loop`, `Block` locals). A `vars`-mapped
|
|
17454
|
+
* symbol is always included: the mapping makes it an external input even
|
|
17455
|
+
* when it also has an assigned value.
|
|
17456
|
+
*
|
|
17457
|
+
* - `unsupported`: operator heads with no operator/function mapping in the
|
|
17458
|
+
* target and not one of the structural forms above.
|
|
17459
|
+
*
|
|
17460
|
+
* Lets a caller validate that a compiled result is self-contained
|
|
17461
|
+
* (`freeSymbols` covered by its inputs, `unsupported` empty) declaratively,
|
|
17462
|
+
* instead of executing or GPU-compiling the code to discover a dangling
|
|
17463
|
+
* reference or an unlowerable operator.
|
|
17464
|
+
*/
|
|
17465
|
+
static analyzeReferences(expr, target, varsKeys) {
|
|
17466
|
+
const engine = expr.engine;
|
|
17467
|
+
const free = /* @__PURE__ */ new Set();
|
|
17468
|
+
const unsupported = /* @__PURE__ */ new Set();
|
|
17469
|
+
const foldedSeen = /* @__PURE__ */ new Set();
|
|
17470
|
+
const union = (a, more) => {
|
|
17471
|
+
const s = new Set(a);
|
|
17472
|
+
for (const m of more) s.add(m);
|
|
17473
|
+
return s;
|
|
17474
|
+
};
|
|
17475
|
+
const visit = (e, bound) => {
|
|
17476
|
+
if (isSymbol2(e)) {
|
|
17477
|
+
const s = e.symbol;
|
|
17478
|
+
if (bound.has(s)) return;
|
|
17479
|
+
if (target.operators?.(s) !== void 0) return;
|
|
17480
|
+
if (varsKeys?.has(s)) {
|
|
17481
|
+
free.add(s);
|
|
17482
|
+
return;
|
|
17483
|
+
}
|
|
17484
|
+
const value = engine._getSymbolValue(s);
|
|
17485
|
+
if (value !== void 0) {
|
|
17486
|
+
if (!foldedSeen.has(s)) {
|
|
17487
|
+
foldedSeen.add(s);
|
|
17488
|
+
visit(value, bound);
|
|
17489
|
+
}
|
|
17490
|
+
return;
|
|
17491
|
+
}
|
|
17492
|
+
free.add(s);
|
|
17493
|
+
return;
|
|
17494
|
+
}
|
|
17495
|
+
if (!isFunction2(e)) return;
|
|
17496
|
+
const h = e.operator;
|
|
17497
|
+
const ops = e.ops;
|
|
17498
|
+
if (h !== "Error" && !_BaseCompiler.STRUCTURAL_HEADS.has(h) && target.functions?.(h) === void 0 && target.operators?.(h) === void 0)
|
|
17499
|
+
unsupported.add(h);
|
|
17500
|
+
if (h === "Function") {
|
|
17501
|
+
const params = ops.slice(1).filter((p) => isSymbol2(p)).map((p) => p.symbol);
|
|
17502
|
+
visit(ops[0], params.length ? union(bound, params) : bound);
|
|
17503
|
+
return;
|
|
17504
|
+
}
|
|
17505
|
+
if (h === "Sum" || h === "Product" || h === "Integrate" || h === "Loop") {
|
|
17506
|
+
const indices = [];
|
|
17507
|
+
const limitExprs = [];
|
|
17508
|
+
for (const clause of ops.slice(1)) {
|
|
17509
|
+
if (isFunction2(clause)) {
|
|
17510
|
+
if (isSymbol2(clause.ops[0])) indices.push(clause.ops[0].symbol);
|
|
17511
|
+
for (const sub2 of clause.ops.slice(1)) limitExprs.push(sub2);
|
|
17512
|
+
} else {
|
|
17513
|
+
limitExprs.push(clause);
|
|
17514
|
+
}
|
|
17515
|
+
}
|
|
17516
|
+
visit(ops[0], indices.length ? union(bound, indices) : bound);
|
|
17517
|
+
for (const le of limitExprs) visit(le, bound);
|
|
17518
|
+
return;
|
|
17519
|
+
}
|
|
17520
|
+
if (h === "Block") {
|
|
17521
|
+
const locals = [];
|
|
17522
|
+
for (const stmt of ops)
|
|
17523
|
+
if (isFunction2(stmt, "Declare") && isSymbol2(stmt.ops[0]))
|
|
17524
|
+
locals.push(stmt.ops[0].symbol);
|
|
17525
|
+
const inner = locals.length ? union(bound, locals) : bound;
|
|
17526
|
+
for (const op of ops) visit(op, inner);
|
|
17527
|
+
return;
|
|
17528
|
+
}
|
|
17529
|
+
for (const op of ops) visit(op, bound);
|
|
17530
|
+
};
|
|
17531
|
+
visit(expr, /* @__PURE__ */ new Set());
|
|
17532
|
+
return { freeSymbols: [...free], unsupported: [...unsupported] };
|
|
17533
|
+
}
|
|
17534
|
+
/**
|
|
17535
|
+
* Attach `freeSymbols` / `unsupported` (from `analyzeReferences`) to a
|
|
17536
|
+
* compilation result, returning the same object. Used by the built-in
|
|
17537
|
+
* targets to make every result carry its declarative reference analysis.
|
|
17538
|
+
*/
|
|
17539
|
+
static withReferences(result, expr, target, varsKeys) {
|
|
17540
|
+
return Object.assign(
|
|
17541
|
+
result,
|
|
17542
|
+
_BaseCompiler.analyzeReferences(expr, target, varsKeys)
|
|
17543
|
+
);
|
|
17544
|
+
}
|
|
17367
17545
|
/**
|
|
17368
17546
|
* Generate a temporary variable name
|
|
17369
17547
|
*/
|
|
@@ -17511,11 +17689,16 @@ function compile(expr, options) {
|
|
|
17511
17689
|
try {
|
|
17512
17690
|
if (options?.target) {
|
|
17513
17691
|
const code = BaseCompiler.compile(expr, options.target);
|
|
17514
|
-
return
|
|
17515
|
-
|
|
17516
|
-
|
|
17517
|
-
|
|
17518
|
-
|
|
17692
|
+
return BaseCompiler.withReferences(
|
|
17693
|
+
{
|
|
17694
|
+
target: options.target.language ?? "custom",
|
|
17695
|
+
success: true,
|
|
17696
|
+
code
|
|
17697
|
+
},
|
|
17698
|
+
expr,
|
|
17699
|
+
options.target,
|
|
17700
|
+
options.vars ? new Set(Object.keys(options.vars)) : void 0
|
|
17701
|
+
);
|
|
17519
17702
|
}
|
|
17520
17703
|
const targetName = options?.to ?? "javascript";
|
|
17521
17704
|
const languageTarget = expr.engine.getCompilationTarget(targetName);
|
|
@@ -17534,11 +17717,26 @@ function compile(expr, options) {
|
|
|
17534
17717
|
});
|
|
17535
17718
|
} catch (e) {
|
|
17536
17719
|
if (options?.fallback ?? true) {
|
|
17720
|
+
const error = e.message;
|
|
17537
17721
|
console.warn(
|
|
17538
|
-
`Compilation fallback for "${expr.operator}" (target: ${options?.to ?? "javascript"}): ${
|
|
17722
|
+
`Compilation fallback for "${expr.operator}" (target: ${options?.to ?? "javascript"}): ${error}`
|
|
17539
17723
|
);
|
|
17540
17724
|
const ce = expr.engine;
|
|
17541
17725
|
const target = options?.to ?? "javascript";
|
|
17726
|
+
let refs = {
|
|
17727
|
+
freeSymbols: [],
|
|
17728
|
+
unsupported: []
|
|
17729
|
+
};
|
|
17730
|
+
try {
|
|
17731
|
+
const compileTarget = options?.target ?? expr.engine.getCompilationTarget(target)?.createTarget();
|
|
17732
|
+
if (compileTarget)
|
|
17733
|
+
refs = BaseCompiler.analyzeReferences(
|
|
17734
|
+
expr,
|
|
17735
|
+
compileTarget,
|
|
17736
|
+
options?.vars ? new Set(Object.keys(options.vars)) : void 0
|
|
17737
|
+
);
|
|
17738
|
+
} catch {
|
|
17739
|
+
}
|
|
17542
17740
|
if (isFunction2(expr, "Function")) {
|
|
17543
17741
|
const lambdaRun = ((...args) => ce.function("Apply", [expr, ...args.map((a) => ce.expr(a))]).evaluate().re);
|
|
17544
17742
|
return {
|
|
@@ -17546,7 +17744,9 @@ function compile(expr, options) {
|
|
|
17546
17744
|
success: false,
|
|
17547
17745
|
code: "",
|
|
17548
17746
|
calling: "lambda",
|
|
17549
|
-
run: lambdaRun
|
|
17747
|
+
run: lambdaRun,
|
|
17748
|
+
error,
|
|
17749
|
+
...refs
|
|
17550
17750
|
};
|
|
17551
17751
|
}
|
|
17552
17752
|
const fallbackRun = ((vars) => {
|
|
@@ -17565,7 +17765,9 @@ function compile(expr, options) {
|
|
|
17565
17765
|
success: false,
|
|
17566
17766
|
code: "",
|
|
17567
17767
|
calling: "expression",
|
|
17568
|
-
run: fallbackRun
|
|
17768
|
+
run: fallbackRun,
|
|
17769
|
+
error,
|
|
17770
|
+
...refs
|
|
17569
17771
|
};
|
|
17570
17772
|
}
|
|
17571
17773
|
throw e;
|
|
@@ -17574,6 +17776,10 @@ function compile(expr, options) {
|
|
|
17574
17776
|
|
|
17575
17777
|
// src/compute-engine/compilation/constant-folding.ts
|
|
17576
17778
|
function formatFloat(n) {
|
|
17779
|
+
if (!Number.isFinite(n))
|
|
17780
|
+
throw new Error(
|
|
17781
|
+
`Cannot compile the non-finite value \`${n}\` to a GPU shader: GLSL/WGSL have no infinity or NaN literals.`
|
|
17782
|
+
);
|
|
17577
17783
|
const str = n.toString();
|
|
17578
17784
|
if (!str.includes(".") && !str.includes("e") && !str.includes("E")) {
|
|
17579
17785
|
return `${str}.0`;
|
|
@@ -21863,6 +22069,442 @@ function fresnelC(x) {
|
|
|
21863
22069
|
function sinc(x) {
|
|
21864
22070
|
return x === 0 ? 1 : Math.sin(x) / x;
|
|
21865
22071
|
}
|
|
22072
|
+
function erfi(x) {
|
|
22073
|
+
if (Number.isNaN(x)) return NaN;
|
|
22074
|
+
if (x === 0) return 0;
|
|
22075
|
+
if (!Number.isFinite(x)) return x > 0 ? Infinity : -Infinity;
|
|
22076
|
+
const sign2 = x < 0 ? -1 : 1;
|
|
22077
|
+
const ax = Math.abs(x);
|
|
22078
|
+
const x2 = ax * ax;
|
|
22079
|
+
let term = ax;
|
|
22080
|
+
let sum = ax;
|
|
22081
|
+
for (let n = 1; n < 1e3; n++) {
|
|
22082
|
+
term *= x2 * (2 * n - 1) / (n * (2 * n + 1));
|
|
22083
|
+
sum += term;
|
|
22084
|
+
if (term < sum * 1e-18) break;
|
|
22085
|
+
}
|
|
22086
|
+
return sign2 * (2 / Math.sqrt(Math.PI)) * sum;
|
|
22087
|
+
}
|
|
22088
|
+
var EULER_GAMMA = 0.5772156649015329;
|
|
22089
|
+
function cisi(x) {
|
|
22090
|
+
const EPS = 1e-16;
|
|
22091
|
+
const TMIN = 2;
|
|
22092
|
+
const BIG = 1e30;
|
|
22093
|
+
const t = Math.abs(x);
|
|
22094
|
+
if (t === 0) return { si: 0, ci: -Infinity };
|
|
22095
|
+
if (!Number.isFinite(t))
|
|
22096
|
+
return { si: x > 0 ? Math.PI / 2 : -Math.PI / 2, ci: 0 };
|
|
22097
|
+
let si;
|
|
22098
|
+
let ci;
|
|
22099
|
+
if (t > TMIN) {
|
|
22100
|
+
let br = 1;
|
|
22101
|
+
const bi = t;
|
|
22102
|
+
let cr = BIG;
|
|
22103
|
+
let cim = 0;
|
|
22104
|
+
let denom = br * br + bi * bi;
|
|
22105
|
+
let dr = br / denom;
|
|
22106
|
+
let di = -bi / denom;
|
|
22107
|
+
let hr = dr;
|
|
22108
|
+
let hi = di;
|
|
22109
|
+
for (let i = 1; i < 100; i++) {
|
|
22110
|
+
const a = -i * i;
|
|
22111
|
+
br += 2;
|
|
22112
|
+
let tr = a * dr + br;
|
|
22113
|
+
let ti = a * di + bi;
|
|
22114
|
+
denom = tr * tr + ti * ti;
|
|
22115
|
+
dr = tr / denom;
|
|
22116
|
+
di = -ti / denom;
|
|
22117
|
+
denom = cr * cr + cim * cim;
|
|
22118
|
+
cr = br + a * cr / denom;
|
|
22119
|
+
cim = bi - a * cim / denom;
|
|
22120
|
+
const delr = cr * dr - cim * di;
|
|
22121
|
+
const deli = cr * di + cim * dr;
|
|
22122
|
+
tr = hr * delr - hi * deli;
|
|
22123
|
+
ti = hr * deli + hi * delr;
|
|
22124
|
+
hr = tr;
|
|
22125
|
+
hi = ti;
|
|
22126
|
+
if (Math.abs(delr - 1) + Math.abs(deli) <= EPS) break;
|
|
22127
|
+
}
|
|
22128
|
+
const ct = Math.cos(t);
|
|
22129
|
+
const st = Math.sin(t);
|
|
22130
|
+
const reH = ct * hr + st * hi;
|
|
22131
|
+
const imH = ct * hi - st * hr;
|
|
22132
|
+
ci = -reH;
|
|
22133
|
+
si = Math.PI / 2 + imH;
|
|
22134
|
+
} else {
|
|
22135
|
+
let sum = 0;
|
|
22136
|
+
let sums = 0;
|
|
22137
|
+
let sumc = 0;
|
|
22138
|
+
let sign2 = 1;
|
|
22139
|
+
let fact = 1;
|
|
22140
|
+
let odd = true;
|
|
22141
|
+
for (let k = 1; k <= 100; k++) {
|
|
22142
|
+
fact *= t / k;
|
|
22143
|
+
const term = fact / k;
|
|
22144
|
+
sum += sign2 * term;
|
|
22145
|
+
const err = term / Math.abs(sum);
|
|
22146
|
+
if (odd) {
|
|
22147
|
+
sign2 = -sign2;
|
|
22148
|
+
sums = sum;
|
|
22149
|
+
sum = sumc;
|
|
22150
|
+
} else {
|
|
22151
|
+
sumc = sum;
|
|
22152
|
+
sum = sums;
|
|
22153
|
+
}
|
|
22154
|
+
if (err < EPS) break;
|
|
22155
|
+
odd = !odd;
|
|
22156
|
+
}
|
|
22157
|
+
si = sums;
|
|
22158
|
+
ci = sumc + Math.log(t) + EULER_GAMMA;
|
|
22159
|
+
}
|
|
22160
|
+
if (x < 0) si = -si;
|
|
22161
|
+
return { si, ci };
|
|
22162
|
+
}
|
|
22163
|
+
function sinIntegral(x) {
|
|
22164
|
+
if (Number.isNaN(x)) return NaN;
|
|
22165
|
+
return cisi(x).si;
|
|
22166
|
+
}
|
|
22167
|
+
function cosIntegral(x) {
|
|
22168
|
+
if (Number.isNaN(x)) return NaN;
|
|
22169
|
+
return cisi(x).ci;
|
|
22170
|
+
}
|
|
22171
|
+
function expInt1(x) {
|
|
22172
|
+
const EPS = 1e-16;
|
|
22173
|
+
const MAXIT = 200;
|
|
22174
|
+
if (x <= 0) return NaN;
|
|
22175
|
+
if (x <= 1) {
|
|
22176
|
+
let sum = -Math.log(x) - EULER_GAMMA;
|
|
22177
|
+
let fact = 1;
|
|
22178
|
+
for (let n = 1; n <= MAXIT; n++) {
|
|
22179
|
+
fact *= -x / n;
|
|
22180
|
+
const del = -fact / n;
|
|
22181
|
+
sum += del;
|
|
22182
|
+
if (Math.abs(del) < Math.abs(sum) * EPS) break;
|
|
22183
|
+
}
|
|
22184
|
+
return sum;
|
|
22185
|
+
}
|
|
22186
|
+
const BIG = 1e30;
|
|
22187
|
+
let b = x + 1;
|
|
22188
|
+
let c = BIG;
|
|
22189
|
+
let d = 1 / b;
|
|
22190
|
+
let h = d;
|
|
22191
|
+
for (let i = 1; i <= MAXIT; i++) {
|
|
22192
|
+
const a = -i * i;
|
|
22193
|
+
b += 2;
|
|
22194
|
+
d = 1 / (a * d + b);
|
|
22195
|
+
c = b + a / c;
|
|
22196
|
+
const del = c * d;
|
|
22197
|
+
h *= del;
|
|
22198
|
+
if (Math.abs(del - 1) <= EPS) break;
|
|
22199
|
+
}
|
|
22200
|
+
return h * Math.exp(-x);
|
|
22201
|
+
}
|
|
22202
|
+
function expIntegralEi(x) {
|
|
22203
|
+
if (Number.isNaN(x)) return NaN;
|
|
22204
|
+
if (x === 0) return -Infinity;
|
|
22205
|
+
if (!Number.isFinite(x)) return x > 0 ? Infinity : 0;
|
|
22206
|
+
if (x < 0) return -expInt1(-x);
|
|
22207
|
+
const EPS = 1e-16;
|
|
22208
|
+
const MAXIT = 200;
|
|
22209
|
+
const SWITCH = -Math.log(EPS);
|
|
22210
|
+
if (x <= SWITCH) {
|
|
22211
|
+
let sum2 = 0;
|
|
22212
|
+
let fact = 1;
|
|
22213
|
+
for (let k = 1; k <= MAXIT; k++) {
|
|
22214
|
+
fact *= x / k;
|
|
22215
|
+
const term2 = fact / k;
|
|
22216
|
+
sum2 += term2;
|
|
22217
|
+
if (term2 < EPS * sum2) break;
|
|
22218
|
+
}
|
|
22219
|
+
return sum2 + Math.log(x) + EULER_GAMMA;
|
|
22220
|
+
}
|
|
22221
|
+
let sum = 0;
|
|
22222
|
+
let term = 1;
|
|
22223
|
+
for (let k = 1; k <= MAXIT; k++) {
|
|
22224
|
+
const prev = term;
|
|
22225
|
+
term *= k / x;
|
|
22226
|
+
if (term < EPS) break;
|
|
22227
|
+
if (term < prev) sum += term;
|
|
22228
|
+
else {
|
|
22229
|
+
sum -= prev;
|
|
22230
|
+
break;
|
|
22231
|
+
}
|
|
22232
|
+
}
|
|
22233
|
+
return Math.exp(x) * (1 + sum) / x;
|
|
22234
|
+
}
|
|
22235
|
+
function logIntegral(x) {
|
|
22236
|
+
if (Number.isNaN(x)) return NaN;
|
|
22237
|
+
if (x === 0) return 0;
|
|
22238
|
+
if (x === 1) return -Infinity;
|
|
22239
|
+
if (x < 0) return NaN;
|
|
22240
|
+
return expIntegralEi(Math.log(x));
|
|
22241
|
+
}
|
|
22242
|
+
function agm(a, b) {
|
|
22243
|
+
if (Number.isNaN(a) || Number.isNaN(b)) return NaN;
|
|
22244
|
+
if (a < 0 || b < 0) return NaN;
|
|
22245
|
+
if (a === 0 || b === 0) return 0;
|
|
22246
|
+
if (!isFinite(a) || !isFinite(b)) return Infinity;
|
|
22247
|
+
for (let i = 0; i < 64 && Math.abs(a - b) > 1e-17 * Math.abs(a); i++) {
|
|
22248
|
+
const an = 0.5 * (a + b);
|
|
22249
|
+
b = Math.sqrt(a * b);
|
|
22250
|
+
a = an;
|
|
22251
|
+
}
|
|
22252
|
+
return 0.5 * (a + b);
|
|
22253
|
+
}
|
|
22254
|
+
function ellipticK(m) {
|
|
22255
|
+
if (Number.isNaN(m)) return NaN;
|
|
22256
|
+
if (m === 1) return Infinity;
|
|
22257
|
+
if (m > 1) return NaN;
|
|
22258
|
+
return Math.PI / (2 * agm(1, Math.sqrt(1 - m)));
|
|
22259
|
+
}
|
|
22260
|
+
function ellipticE(m) {
|
|
22261
|
+
if (Number.isNaN(m)) return NaN;
|
|
22262
|
+
if (m === 1) return 1;
|
|
22263
|
+
if (m > 1) return NaN;
|
|
22264
|
+
let a = 1;
|
|
22265
|
+
let b = Math.sqrt(1 - m);
|
|
22266
|
+
let sum = 0.5 * m;
|
|
22267
|
+
let pow2 = 0.5;
|
|
22268
|
+
for (let i = 0; i < 64 && Math.abs(a - b) > 1e-17 * a; i++) {
|
|
22269
|
+
const c = 0.5 * (a - b);
|
|
22270
|
+
const an = 0.5 * (a + b);
|
|
22271
|
+
b = Math.sqrt(a * b);
|
|
22272
|
+
a = an;
|
|
22273
|
+
pow2 *= 2;
|
|
22274
|
+
sum += pow2 * c * c;
|
|
22275
|
+
}
|
|
22276
|
+
const K = Math.PI / (2 * a);
|
|
22277
|
+
return K * (1 - sum);
|
|
22278
|
+
}
|
|
22279
|
+
var CARLSON_TOL = 1e-24;
|
|
22280
|
+
function carlsonRC(x, y) {
|
|
22281
|
+
if (Number.isNaN(x) || Number.isNaN(y) || x < 0) return NaN;
|
|
22282
|
+
if (y === 0) return Infinity;
|
|
22283
|
+
if (x === 0) return Math.PI / (2 * Math.sqrt(y));
|
|
22284
|
+
if (y < 0) return Math.sqrt(x / (x - y)) * carlsonRC(x - y, -y);
|
|
22285
|
+
if (x === y) return 1 / Math.sqrt(x);
|
|
22286
|
+
const e = (y - x) / x;
|
|
22287
|
+
if (Math.abs(e) < 0.01) {
|
|
22288
|
+
let sum = 0;
|
|
22289
|
+
let term = 1;
|
|
22290
|
+
for (let k = 0; k < 10; k++) {
|
|
22291
|
+
sum += term / (2 * k + 1);
|
|
22292
|
+
term *= -e;
|
|
22293
|
+
}
|
|
22294
|
+
return sum / Math.sqrt(x);
|
|
22295
|
+
}
|
|
22296
|
+
const a = Math.sqrt(x / y);
|
|
22297
|
+
return x < y ? Math.acos(a) / Math.sqrt(y - x) : Math.acosh(a) / Math.sqrt(x - y);
|
|
22298
|
+
}
|
|
22299
|
+
function carlsonRF(x, y, z) {
|
|
22300
|
+
if (Number.isNaN(x) || Number.isNaN(y) || Number.isNaN(z)) return NaN;
|
|
22301
|
+
if (x < 0 || y < 0 || z < 0) return NaN;
|
|
22302
|
+
if ((x === 0 ? 1 : 0) + (y === 0 ? 1 : 0) + (z === 0 ? 1 : 0) > 1)
|
|
22303
|
+
return Infinity;
|
|
22304
|
+
if (y === z) return carlsonRC(x, y);
|
|
22305
|
+
if (x === z) return carlsonRC(y, x);
|
|
22306
|
+
if (x === y) return carlsonRC(z, x);
|
|
22307
|
+
const A0 = (x + y + z) / 3;
|
|
22308
|
+
const Q = Math.pow(3 * CARLSON_TOL, -1 / 6) * Math.max(Math.abs(A0 - x), Math.abs(A0 - y), Math.abs(A0 - z));
|
|
22309
|
+
let [xm, ym, zm] = [x, y, z];
|
|
22310
|
+
let A = A0;
|
|
22311
|
+
let pow4 = 1;
|
|
22312
|
+
for (let i = 0; i < 64 && pow4 * Q >= Math.abs(A); i++) {
|
|
22313
|
+
const sx = Math.sqrt(xm);
|
|
22314
|
+
const sy = Math.sqrt(ym);
|
|
22315
|
+
const sz = Math.sqrt(zm);
|
|
22316
|
+
const lm = sx * sy + sx * sz + sy * sz;
|
|
22317
|
+
A = (A + lm) / 4;
|
|
22318
|
+
xm = (xm + lm) / 4;
|
|
22319
|
+
ym = (ym + lm) / 4;
|
|
22320
|
+
zm = (zm + lm) / 4;
|
|
22321
|
+
pow4 /= 4;
|
|
22322
|
+
}
|
|
22323
|
+
const t = pow4 / A;
|
|
22324
|
+
const Xc = (A0 - x) * t;
|
|
22325
|
+
const Yc = (A0 - y) * t;
|
|
22326
|
+
const Zc = -Xc - Yc;
|
|
22327
|
+
const E2 = Xc * Yc - Zc * Zc;
|
|
22328
|
+
const E3 = Xc * Yc * Zc;
|
|
22329
|
+
return Math.pow(A, -0.5) * (9240 - 924 * E2 + 385 * E2 * E2 + 660 * E3 - 630 * E2 * E3) / 9240;
|
|
22330
|
+
}
|
|
22331
|
+
function carlsonRJ(x, y, z, p) {
|
|
22332
|
+
if (Number.isNaN(x) || Number.isNaN(y) || Number.isNaN(z) || Number.isNaN(p))
|
|
22333
|
+
return NaN;
|
|
22334
|
+
if (x < 0 || y < 0 || z < 0) return NaN;
|
|
22335
|
+
if (p === 0) return Infinity;
|
|
22336
|
+
if ((x === 0 ? 1 : 0) + (y === 0 ? 1 : 0) + (z === 0 ? 1 : 0) > 1)
|
|
22337
|
+
return Infinity;
|
|
22338
|
+
if (p < 0) {
|
|
22339
|
+
const [a, b, c] = [x, y, z].sort((u, v2) => u - v2);
|
|
22340
|
+
const q = -p;
|
|
22341
|
+
const pn = (c * (a + b + q) - a * b) / (c + q);
|
|
22342
|
+
let v = (pn - c) * carlsonRJ(a, b, c, pn);
|
|
22343
|
+
v -= 3 * carlsonRF(a, b, c);
|
|
22344
|
+
v += 3 * Math.sqrt(a * b * c / (a * b + pn * q)) * carlsonRC(a * b + pn * q, pn * q);
|
|
22345
|
+
return v / (c + q);
|
|
22346
|
+
}
|
|
22347
|
+
const A0 = (x + y + z + 2 * p) / 5;
|
|
22348
|
+
const delta = (p - x) * (p - y) * (p - z);
|
|
22349
|
+
const Q = Math.pow(0.25 * CARLSON_TOL, -1 / 6) * Math.max(
|
|
22350
|
+
Math.abs(A0 - x),
|
|
22351
|
+
Math.abs(A0 - y),
|
|
22352
|
+
Math.abs(A0 - z),
|
|
22353
|
+
Math.abs(A0 - p)
|
|
22354
|
+
);
|
|
22355
|
+
let [xm, ym, zm, pm] = [x, y, z, p];
|
|
22356
|
+
let A = A0;
|
|
22357
|
+
let pow4 = 1;
|
|
22358
|
+
let S = 0;
|
|
22359
|
+
for (let i = 0; i < 64; i++) {
|
|
22360
|
+
const sx = Math.sqrt(xm);
|
|
22361
|
+
const sy = Math.sqrt(ym);
|
|
22362
|
+
const sz = Math.sqrt(zm);
|
|
22363
|
+
const sp = Math.sqrt(pm);
|
|
22364
|
+
const lm = sx * sy + sx * sz + sy * sz;
|
|
22365
|
+
const A1 = (A + lm) / 4;
|
|
22366
|
+
xm = (xm + lm) / 4;
|
|
22367
|
+
ym = (ym + lm) / 4;
|
|
22368
|
+
zm = (zm + lm) / 4;
|
|
22369
|
+
pm = (pm + lm) / 4;
|
|
22370
|
+
const dm = (sp + sx) * (sp + sy) * (sp + sz);
|
|
22371
|
+
const em = delta * pow4 * pow4 * pow4 / (dm * dm);
|
|
22372
|
+
if (pow4 * Q < Math.abs(A)) break;
|
|
22373
|
+
S += carlsonRC(1, 1 + em) * pow4 / dm;
|
|
22374
|
+
pow4 /= 4;
|
|
22375
|
+
A = A1;
|
|
22376
|
+
}
|
|
22377
|
+
const t = pow4 / A;
|
|
22378
|
+
const X = (A0 - x) * t;
|
|
22379
|
+
const Y = (A0 - y) * t;
|
|
22380
|
+
const Z = (A0 - z) * t;
|
|
22381
|
+
const P = (-X - Y - Z) / 2;
|
|
22382
|
+
const E2 = X * Y + X * Z + Y * Z - 3 * P * P;
|
|
22383
|
+
const E3 = X * Y * Z + 2 * E2 * P + 4 * P * P * P;
|
|
22384
|
+
const E4 = (2 * X * Y * Z + E2 * P + 3 * P * P * P) * P;
|
|
22385
|
+
const E5 = X * Y * Z * P * P;
|
|
22386
|
+
const series = (24024 - 5148 * E2 + 2457 * E2 * E2 + 4004 * E3 - 4158 * E2 * E3 - 3276 * E4 + 2772 * E5) / 24024;
|
|
22387
|
+
return pow4 * Math.pow(A, -1.5) * series + 6 * S;
|
|
22388
|
+
}
|
|
22389
|
+
function carlsonRD(x, y, z) {
|
|
22390
|
+
return carlsonRJ(x, y, z, z);
|
|
22391
|
+
}
|
|
22392
|
+
function ellipticF(phi, m) {
|
|
22393
|
+
if (Number.isNaN(phi) || Number.isNaN(m)) return NaN;
|
|
22394
|
+
if (Math.abs(phi) > Math.PI / 2) {
|
|
22395
|
+
const k = Math.round(phi / Math.PI);
|
|
22396
|
+
const K = ellipticK(m);
|
|
22397
|
+
if (!Number.isFinite(K)) return NaN;
|
|
22398
|
+
return 2 * k * K + ellipticF(phi - k * Math.PI, m);
|
|
22399
|
+
}
|
|
22400
|
+
const s = Math.sin(phi);
|
|
22401
|
+
const y = 1 - m * s * s;
|
|
22402
|
+
if (y < 0) return NaN;
|
|
22403
|
+
const c = Math.cos(phi);
|
|
22404
|
+
return s * carlsonRF(c * c, y, 1);
|
|
22405
|
+
}
|
|
22406
|
+
function ellipticEIncomplete(phi, m) {
|
|
22407
|
+
if (Number.isNaN(phi) || Number.isNaN(m)) return NaN;
|
|
22408
|
+
if (Math.abs(phi) > Math.PI / 2) {
|
|
22409
|
+
const k = Math.round(phi / Math.PI);
|
|
22410
|
+
const E = ellipticE(m);
|
|
22411
|
+
if (!Number.isFinite(E)) return NaN;
|
|
22412
|
+
return 2 * k * E + ellipticEIncomplete(phi - k * Math.PI, m);
|
|
22413
|
+
}
|
|
22414
|
+
const s = Math.sin(phi);
|
|
22415
|
+
const y = 1 - m * s * s;
|
|
22416
|
+
if (y < 0) return NaN;
|
|
22417
|
+
const c = Math.cos(phi);
|
|
22418
|
+
const s3 = s * s * s;
|
|
22419
|
+
return s * carlsonRF(c * c, y, 1) - m / 3 * s3 * carlsonRD(c * c, y, 1);
|
|
22420
|
+
}
|
|
22421
|
+
function ellipticPiComplete(n, m) {
|
|
22422
|
+
if (Number.isNaN(n) || Number.isNaN(m)) return NaN;
|
|
22423
|
+
if (n === 1 || m === 1) return Infinity;
|
|
22424
|
+
if (m > 1) return NaN;
|
|
22425
|
+
return carlsonRF(0, 1 - m, 1) + n / 3 * carlsonRJ(0, 1 - m, 1, 1 - n);
|
|
22426
|
+
}
|
|
22427
|
+
function ellipticPiIncomplete(n, phi, m) {
|
|
22428
|
+
if (Number.isNaN(n) || Number.isNaN(phi) || Number.isNaN(m)) return NaN;
|
|
22429
|
+
if (Math.abs(phi) > Math.PI / 2) {
|
|
22430
|
+
const k = Math.round(phi / Math.PI);
|
|
22431
|
+
const P = ellipticPiComplete(n, m);
|
|
22432
|
+
if (!Number.isFinite(P)) return NaN;
|
|
22433
|
+
return 2 * k * P + ellipticPiIncomplete(n, phi - k * Math.PI, m);
|
|
22434
|
+
}
|
|
22435
|
+
const s = Math.sin(phi);
|
|
22436
|
+
const y = 1 - m * s * s;
|
|
22437
|
+
if (y < 0) return NaN;
|
|
22438
|
+
const c = Math.cos(phi);
|
|
22439
|
+
const s3 = s * s * s;
|
|
22440
|
+
const p = 1 - n * s * s;
|
|
22441
|
+
if (p === 0) return Infinity;
|
|
22442
|
+
return s * carlsonRF(c * c, y, 1) + n / 3 * s3 * carlsonRJ(c * c, y, 1, p);
|
|
22443
|
+
}
|
|
22444
|
+
function isNonPositiveInteger(x) {
|
|
22445
|
+
return Number.isInteger(x) && x <= 0;
|
|
22446
|
+
}
|
|
22447
|
+
function gauss2F1Series(a, b, c, z, maxTerms = 1e4) {
|
|
22448
|
+
let term = 1;
|
|
22449
|
+
let sum = 1;
|
|
22450
|
+
for (let n = 0; n < maxTerms; n++) {
|
|
22451
|
+
term *= (a + n) * (b + n) * z / ((c + n) * (n + 1));
|
|
22452
|
+
if (term === 0) return sum;
|
|
22453
|
+
sum += term;
|
|
22454
|
+
if (n > 2 && Math.abs(term) <= Number.EPSILON * Math.abs(sum)) return sum;
|
|
22455
|
+
}
|
|
22456
|
+
return sum;
|
|
22457
|
+
}
|
|
22458
|
+
function hypergeometric2F1(a, b, c, z) {
|
|
22459
|
+
if ([a, b, c, z].some(Number.isNaN)) return NaN;
|
|
22460
|
+
const aTerm = isNonPositiveInteger(a) ? -a : Infinity;
|
|
22461
|
+
const bTerm = isNonPositiveInteger(b) ? -b : Infinity;
|
|
22462
|
+
const nTerms = Math.min(aTerm, bTerm);
|
|
22463
|
+
if (isNonPositiveInteger(c)) {
|
|
22464
|
+
if (nTerms === Infinity || nTerms > -c) return NaN;
|
|
22465
|
+
}
|
|
22466
|
+
if (nTerms !== Infinity) return gauss2F1Series(a, b, c, z, nTerms + 1);
|
|
22467
|
+
if (z === 0) return 1;
|
|
22468
|
+
if (z === 1) {
|
|
22469
|
+
const s2 = c - a - b;
|
|
22470
|
+
if (s2 <= 0) return s2 === 0 ? Infinity : NaN;
|
|
22471
|
+
return gamma(c) * gamma(s2) / (gamma(c - a) * gamma(c - b));
|
|
22472
|
+
}
|
|
22473
|
+
if (z > 1) return NaN;
|
|
22474
|
+
if (z < 0) {
|
|
22475
|
+
return Math.pow(1 - z, -a) * hypergeometric2F1(a, c - b, c, z / (z - 1));
|
|
22476
|
+
}
|
|
22477
|
+
if (z <= 0.5) return gauss2F1Series(a, b, c, z);
|
|
22478
|
+
const s = c - a - b;
|
|
22479
|
+
if (Number.isInteger(s)) {
|
|
22480
|
+
if (z <= 0.95) return gauss2F1Series(a, b, c, z, 1e6);
|
|
22481
|
+
return NaN;
|
|
22482
|
+
}
|
|
22483
|
+
const t1 = gamma(c) * gamma(s) / (gamma(c - a) * gamma(c - b)) * gauss2F1Series(a, b, 1 - s, 1 - z);
|
|
22484
|
+
const t2 = gamma(c) * gamma(-s) / (gamma(a) * gamma(b)) * Math.pow(1 - z, s) * gauss2F1Series(c - a, c - b, 1 + s, 1 - z);
|
|
22485
|
+
return t1 + t2;
|
|
22486
|
+
}
|
|
22487
|
+
function kummer1F1Series(a, b, z, maxTerms = 2e4) {
|
|
22488
|
+
let term = 1;
|
|
22489
|
+
let sum = 1;
|
|
22490
|
+
for (let n = 0; n < maxTerms; n++) {
|
|
22491
|
+
term *= (a + n) * z / ((b + n) * (n + 1));
|
|
22492
|
+
if (term === 0) return sum;
|
|
22493
|
+
sum += term;
|
|
22494
|
+
if (n > 2 && Math.abs(term) <= Number.EPSILON * Math.abs(sum)) return sum;
|
|
22495
|
+
}
|
|
22496
|
+
return sum;
|
|
22497
|
+
}
|
|
22498
|
+
function hypergeometric1F1(a, b, z) {
|
|
22499
|
+
if ([a, b, z].some(Number.isNaN)) return NaN;
|
|
22500
|
+
const aTerm = isNonPositiveInteger(a) ? -a : Infinity;
|
|
22501
|
+
if (isNonPositiveInteger(b)) {
|
|
22502
|
+
if (aTerm === Infinity || aTerm > -b) return NaN;
|
|
22503
|
+
}
|
|
22504
|
+
if (aTerm !== Infinity) return kummer1F1Series(a, b, z, aTerm + 1);
|
|
22505
|
+
if (z < 0) return Math.exp(z) * hypergeometric1F1(b - a, b, -z);
|
|
22506
|
+
return kummer1F1Series(a, b, z);
|
|
22507
|
+
}
|
|
21866
22508
|
|
|
21867
22509
|
// src/compute-engine/boxed-expression/expand.ts
|
|
21868
22510
|
var binomials = [
|
|
@@ -22582,6 +23224,7 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
22582
23224
|
Erf: "_SYS.erf",
|
|
22583
23225
|
Erfc: "_SYS.erfc",
|
|
22584
23226
|
ErfInv: "_SYS.erfInv",
|
|
23227
|
+
Erfi: "_SYS.erfi",
|
|
22585
23228
|
// Special functions
|
|
22586
23229
|
Beta: "_SYS.beta",
|
|
22587
23230
|
Digamma: "_SYS.digamma",
|
|
@@ -22597,6 +23240,30 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
22597
23240
|
// Airy functions
|
|
22598
23241
|
AiryAi: "_SYS.airyAi",
|
|
22599
23242
|
AiryBi: "_SYS.airyBi",
|
|
23243
|
+
// Exponential / trigonometric / logarithmic integrals. These are the closed
|
|
23244
|
+
// forms the antiderivative engine emits (e.g. ∫sin x/x dx = SinIntegral(x)),
|
|
23245
|
+
// so an "evaluate then compile" pipeline must be able to lower them.
|
|
23246
|
+
SinIntegral: "_SYS.sinIntegral",
|
|
23247
|
+
CosIntegral: "_SYS.cosIntegral",
|
|
23248
|
+
ExpIntegralEi: "_SYS.expIntegralEi",
|
|
23249
|
+
LogIntegral: "_SYS.logIntegral",
|
|
23250
|
+
// Arithmetic-geometric mean and elliptic integrals (parameter convention
|
|
23251
|
+
// m = k², as in the library). `AGM`, `EllipticE`, and `EllipticPi` are
|
|
23252
|
+
// arity-overloaded — the handlers mirror the library's evaluate dispatch.
|
|
23253
|
+
AGM: (args, compile2) => args.length === 1 ? `_SYS.agm(1, ${compile2(args[0])})` : `_SYS.agm(${compile2(args[0])}, ${compile2(args[1])})`,
|
|
23254
|
+
EllipticK: "_SYS.ellipticK",
|
|
23255
|
+
EllipticE: (args, compile2) => args.length === 2 ? `_SYS.ellipticEIncomplete(${compile2(args[0])}, ${compile2(args[1])})` : `_SYS.ellipticE(${compile2(args[0])})`,
|
|
23256
|
+
EllipticF: (args, compile2) => `_SYS.ellipticF(${compile2(args[0])}, ${compile2(args[1])})`,
|
|
23257
|
+
EllipticPi: (args, compile2) => args.length === 3 ? `_SYS.ellipticPiIncomplete(${compile2(args[0])}, ${compile2(
|
|
23258
|
+
args[1]
|
|
23259
|
+
)}, ${compile2(args[2])})` : `_SYS.ellipticPiComplete(${compile2(args[0])}, ${compile2(args[1])})`,
|
|
23260
|
+
// Hypergeometric functions.
|
|
23261
|
+
Hypergeometric2F1: (args, compile2) => `_SYS.hypergeometric2F1(${compile2(args[0])}, ${compile2(args[1])}, ${compile2(
|
|
23262
|
+
args[2]
|
|
23263
|
+
)}, ${compile2(args[3])})`,
|
|
23264
|
+
Hypergeometric1F1: (args, compile2) => `_SYS.hypergeometric1F1(${compile2(args[0])}, ${compile2(args[1])}, ${compile2(
|
|
23265
|
+
args[2]
|
|
23266
|
+
)})`,
|
|
22600
23267
|
// Combinatorics
|
|
22601
23268
|
Mandelbrot: ([c, maxIter], compile2) => {
|
|
22602
23269
|
if (c === null || maxIter === null)
|
|
@@ -22609,6 +23276,8 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
22609
23276
|
return `_SYS.julia(${compile2(z)}, ${compile2(c)}, ${compile2(maxIter)})`;
|
|
22610
23277
|
},
|
|
22611
23278
|
Binomial: (args, compile2) => `_SYS.binomial(${compile2(args[0])}, ${compile2(args[1])})`,
|
|
23279
|
+
// Choose(n, k) is the binomial coefficient — same runtime helper.
|
|
23280
|
+
Choose: (args, compile2) => `_SYS.binomial(${compile2(args[0])}, ${compile2(args[1])})`,
|
|
22612
23281
|
Fibonacci: "_SYS.fibonacci",
|
|
22613
23282
|
// Complex-specific functions
|
|
22614
23283
|
Real: (args, compile2) => {
|
|
@@ -23114,6 +23783,20 @@ var SYS_HELPERS = {
|
|
|
23114
23783
|
sinc,
|
|
23115
23784
|
fresnelS,
|
|
23116
23785
|
fresnelC,
|
|
23786
|
+
sinIntegral,
|
|
23787
|
+
cosIntegral,
|
|
23788
|
+
expIntegralEi,
|
|
23789
|
+
logIntegral,
|
|
23790
|
+
erfi,
|
|
23791
|
+
agm,
|
|
23792
|
+
ellipticK,
|
|
23793
|
+
ellipticE,
|
|
23794
|
+
ellipticEIncomplete,
|
|
23795
|
+
ellipticF,
|
|
23796
|
+
ellipticPiComplete,
|
|
23797
|
+
ellipticPiIncomplete,
|
|
23798
|
+
hypergeometric2F1,
|
|
23799
|
+
hypergeometric1F1,
|
|
23117
23800
|
mandelbrot: (c, maxIter) => {
|
|
23118
23801
|
let zx = 0, zy = 0;
|
|
23119
23802
|
const cx = typeof c === "number" ? c : c.re;
|
|
@@ -23300,7 +23983,7 @@ var JavaScriptTarget = class {
|
|
|
23300
23983
|
functions: (id) => namedFunctions?.[id] ? namedFunctions[id] : JAVASCRIPT_FUNCTIONS[id],
|
|
23301
23984
|
var: (id) => {
|
|
23302
23985
|
if (vars && id in vars) return JSON.stringify(vars[id]);
|
|
23303
|
-
const
|
|
23986
|
+
const result2 = {
|
|
23304
23987
|
Pi: "Math.PI",
|
|
23305
23988
|
ExponentialE: "Math.E",
|
|
23306
23989
|
NaN: "Number.NaN",
|
|
@@ -23311,13 +23994,20 @@ var JavaScriptTarget = class {
|
|
|
23311
23994
|
CatalanConstant: "0.91596559417721901",
|
|
23312
23995
|
EulerGamma: "0.57721566490153286"
|
|
23313
23996
|
}[id];
|
|
23314
|
-
if (
|
|
23997
|
+
if (result2 !== void 0) return result2;
|
|
23315
23998
|
if (unknowns.includes(id)) return `_.${id}`;
|
|
23316
|
-
return void 0;
|
|
23999
|
+
if (expr.engine._getSymbolValue(id) !== void 0) return void 0;
|
|
24000
|
+
return `_.${id}`;
|
|
23317
24001
|
},
|
|
23318
24002
|
preamble: (preamble ?? "") + preambleImports
|
|
23319
24003
|
});
|
|
23320
|
-
|
|
24004
|
+
const result = compileToTarget(expr, target, realOnly);
|
|
24005
|
+
return BaseCompiler.withReferences(
|
|
24006
|
+
result,
|
|
24007
|
+
expr,
|
|
24008
|
+
target,
|
|
24009
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
24010
|
+
);
|
|
23321
24011
|
}
|
|
23322
24012
|
};
|
|
23323
24013
|
function wrapRealOnly(result) {
|
|
@@ -25888,6 +26578,10 @@ var GPU_CONSTANTS = {
|
|
|
25888
26578
|
EulerGamma: "0.57721566490"
|
|
25889
26579
|
};
|
|
25890
26580
|
function formatGPUNumber(n) {
|
|
26581
|
+
if (!Number.isFinite(n))
|
|
26582
|
+
throw new Error(
|
|
26583
|
+
`Cannot compile the non-finite value \`${n}\` to a GPU shader: GLSL/WGSL have no infinity or NaN literals.`
|
|
26584
|
+
);
|
|
25891
26585
|
const str = n.toString();
|
|
25892
26586
|
if (!str.includes(".") && !str.includes("e") && !str.includes("E")) {
|
|
25893
26587
|
return `${str}.0`;
|
|
@@ -25915,7 +26609,7 @@ var GPUShaderTarget = class {
|
|
|
25915
26609
|
var: (id) => {
|
|
25916
26610
|
if (id === "ImaginaryUnit") return `${v2}(0.0, 1.0)`;
|
|
25917
26611
|
if (id in constants) return constants[id];
|
|
25918
|
-
return
|
|
26612
|
+
return void 0;
|
|
25919
26613
|
},
|
|
25920
26614
|
string: (str) => JSON.stringify(str),
|
|
25921
26615
|
number: formatGPUNumber,
|
|
@@ -25954,7 +26648,7 @@ var GPUShaderTarget = class {
|
|
|
25954
26648
|
if (vars && id in vars) return vars[id];
|
|
25955
26649
|
if (id === "ImaginaryUnit") return `${v2}(0.0, 1.0)`;
|
|
25956
26650
|
if (id in constants) return constants[id];
|
|
25957
|
-
return
|
|
26651
|
+
return void 0;
|
|
25958
26652
|
}
|
|
25959
26653
|
});
|
|
25960
26654
|
const code = BaseCompiler.compile(expr, target);
|
|
@@ -25994,7 +26688,12 @@ var GPUShaderTarget = class {
|
|
|
25994
26688
|
preamble += this.languageId === "wgsl" ? GPU_COLOR_PREAMBLE_WGSL : GPU_COLOR_PREAMBLE_GLSL;
|
|
25995
26689
|
}
|
|
25996
26690
|
if (preamble) result.preamble = preamble;
|
|
25997
|
-
return
|
|
26691
|
+
return BaseCompiler.withReferences(
|
|
26692
|
+
result,
|
|
26693
|
+
expr,
|
|
26694
|
+
target,
|
|
26695
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
26696
|
+
);
|
|
25998
26697
|
}
|
|
25999
26698
|
compileToSource(expr, _options = {}) {
|
|
26000
26699
|
const target = this.createTarget();
|
|
@@ -26027,6 +26726,8 @@ var GLSL_FUNCTIONS = {
|
|
|
26027
26726
|
Tuple: compileGLSLList
|
|
26028
26727
|
};
|
|
26029
26728
|
var GLSLTarget = class extends GPUShaderTarget {
|
|
26729
|
+
// Annotated `string` (not the literal `'glsl'`) so subclasses such as
|
|
26730
|
+
// `IntervalGLSLTarget` can override it while reusing the GLSL shader assembly.
|
|
26030
26731
|
languageId = "glsl";
|
|
26031
26732
|
getLanguageSpecificFunctions() {
|
|
26032
26733
|
return GLSL_FUNCTIONS;
|
|
@@ -26547,7 +27248,17 @@ var PythonTarget = class {
|
|
|
26547
27248
|
*/
|
|
26548
27249
|
compile(expr, options = {}) {
|
|
26549
27250
|
const code = this.compileToSource(expr, options);
|
|
26550
|
-
|
|
27251
|
+
const result = {
|
|
27252
|
+
target: "python",
|
|
27253
|
+
success: true,
|
|
27254
|
+
code
|
|
27255
|
+
};
|
|
27256
|
+
return BaseCompiler.withReferences(
|
|
27257
|
+
result,
|
|
27258
|
+
expr,
|
|
27259
|
+
this.createTarget(),
|
|
27260
|
+
options.vars ? new Set(Object.keys(options.vars)) : void 0
|
|
27261
|
+
);
|
|
26551
27262
|
}
|
|
26552
27263
|
/**
|
|
26553
27264
|
* Compile an expression to Python source code
|
|
@@ -28404,11 +29115,18 @@ var IntervalJavaScriptTarget = class {
|
|
|
28404
29115
|
};
|
|
28405
29116
|
if (id in constants) return constants[id];
|
|
28406
29117
|
if (unknowns.includes(id)) return `_.${id}`;
|
|
28407
|
-
return void 0;
|
|
29118
|
+
if (expr.engine._getSymbolValue(id) !== void 0) return void 0;
|
|
29119
|
+
return `_.${id}`;
|
|
28408
29120
|
},
|
|
28409
29121
|
preamble: (preamble ?? "") + preambleImports
|
|
28410
29122
|
});
|
|
28411
|
-
|
|
29123
|
+
const result = compileToIntervalTarget(expr, target);
|
|
29124
|
+
return BaseCompiler.withReferences(
|
|
29125
|
+
result,
|
|
29126
|
+
expr,
|
|
29127
|
+
target,
|
|
29128
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
29129
|
+
);
|
|
28412
29130
|
}
|
|
28413
29131
|
};
|
|
28414
29132
|
function compileToIntervalTarget(expr, target) {
|
|
@@ -28432,12 +29150,539 @@ function compileToIntervalTarget(expr, target) {
|
|
|
28432
29150
|
};
|
|
28433
29151
|
}
|
|
28434
29152
|
|
|
29153
|
+
// src/compute-engine/compilation/interval-glsl-target.ts
|
|
29154
|
+
var IV_INF = "1e18";
|
|
29155
|
+
var INTERVAL_GLSL_PREAMBLE = `
|
|
29156
|
+
const float IV_INF = ${IV_INF};
|
|
29157
|
+
const vec2 IV_ENTIRE = vec2(-IV_INF, IV_INF);
|
|
29158
|
+
const vec2 IV_EMPTY = vec2(IV_INF, -IV_INF);
|
|
29159
|
+
|
|
29160
|
+
bool _iv_is_empty(vec2 a) { return a.x > a.y; }
|
|
29161
|
+
|
|
29162
|
+
// Clamp bounds to the finite sentinel range. Preserves IV_EMPTY (its components
|
|
29163
|
+
// already sit at the sentinels) and folds any overflowed intermediate back to
|
|
29164
|
+
// the sentinel (min(inf, IV_INF) = IV_INF), so a real \`inf\` never escapes an op.
|
|
29165
|
+
vec2 _iv_clamp(vec2 a) { return clamp(a, -IV_INF, IV_INF); }
|
|
29166
|
+
|
|
29167
|
+
// Exact empty propagation: force empty if any operand is empty.
|
|
29168
|
+
vec2 _iv_guard1(vec2 r, vec2 a) { return _iv_is_empty(a) ? IV_EMPTY : r; }
|
|
29169
|
+
vec2 _iv_guard2(vec2 r, vec2 a, vec2 b) {
|
|
29170
|
+
return (_iv_is_empty(a) || _iv_is_empty(b)) ? IV_EMPTY : r;
|
|
29171
|
+
}
|
|
29172
|
+
|
|
29173
|
+
vec2 _iv_negate(vec2 a) { return _iv_guard1(_iv_clamp(vec2(-a.y, -a.x)), a); }
|
|
29174
|
+
|
|
29175
|
+
vec2 _iv_add(vec2 a, vec2 b) {
|
|
29176
|
+
return _iv_guard2(_iv_clamp(vec2(a.x + b.x, a.y + b.y)), a, b);
|
|
29177
|
+
}
|
|
29178
|
+
|
|
29179
|
+
vec2 _iv_sub(vec2 a, vec2 b) {
|
|
29180
|
+
return _iv_guard2(_iv_clamp(vec2(a.x - b.y, a.y - b.x)), a, b);
|
|
29181
|
+
}
|
|
29182
|
+
|
|
29183
|
+
vec2 _iv_mul(vec2 a, vec2 b) {
|
|
29184
|
+
float p1 = a.x * b.x, p2 = a.x * b.y, p3 = a.y * b.x, p4 = a.y * b.y;
|
|
29185
|
+
vec2 r = vec2(min(min(p1, p2), min(p3, p4)), max(max(p1, p2), max(p3, p4)));
|
|
29186
|
+
return _iv_guard2(_iv_clamp(r), a, b);
|
|
29187
|
+
}
|
|
29188
|
+
|
|
29189
|
+
vec2 _iv_div(vec2 a, vec2 b) {
|
|
29190
|
+
// Denominator spanning 0 \u2192 entire (wide, never narrow): the CPU pass turns
|
|
29191
|
+
// the pole into a proper asymptote break.
|
|
29192
|
+
bool spansZero = (b.x <= 0.0 && b.y >= 0.0);
|
|
29193
|
+
float q1 = a.x / b.x, q2 = a.x / b.y, q3 = a.y / b.x, q4 = a.y / b.y;
|
|
29194
|
+
vec2 r = vec2(min(min(q1, q2), min(q3, q4)), max(max(q1, q2), max(q3, q4)));
|
|
29195
|
+
r = spansZero ? IV_ENTIRE : r;
|
|
29196
|
+
return _iv_guard2(_iv_clamp(r), a, b);
|
|
29197
|
+
}
|
|
29198
|
+
|
|
29199
|
+
vec2 _iv_square(vec2 a) {
|
|
29200
|
+
float lo2 = a.x * a.x, hi2 = a.y * a.y;
|
|
29201
|
+
// Straddles 0 \u21D2 min is 0; otherwise the smaller endpoint\xB2 is the min.
|
|
29202
|
+
float lo = (a.x <= 0.0 && a.y >= 0.0) ? 0.0 : min(lo2, hi2);
|
|
29203
|
+
return _iv_guard1(_iv_clamp(vec2(lo, max(lo2, hi2))), a);
|
|
29204
|
+
}
|
|
29205
|
+
|
|
29206
|
+
// Scalar integer power that is correct for negative bases (GLSL \`pow\` requires
|
|
29207
|
+
// a non-negative base): keep the sign for odd exponents, drop it for even.
|
|
29208
|
+
float _iv_powi_scalar(float x, float n) {
|
|
29209
|
+
float a = pow(abs(x), n);
|
|
29210
|
+
return (mod(n, 2.0) == 1.0 && x < 0.0) ? -a : a;
|
|
29211
|
+
}
|
|
29212
|
+
|
|
29213
|
+
vec2 _iv_powi(vec2 a, float n) {
|
|
29214
|
+
float pl = _iv_powi_scalar(a.x, n);
|
|
29215
|
+
float ph = _iv_powi_scalar(a.y, n);
|
|
29216
|
+
bool even = (mod(n, 2.0) == 0.0);
|
|
29217
|
+
bool straddle = (a.x <= 0.0 && a.y >= 0.0);
|
|
29218
|
+
float lo = even ? (straddle ? 0.0 : min(pl, ph)) : pl;
|
|
29219
|
+
float hi = even ? max(pl, ph) : ph;
|
|
29220
|
+
return _iv_guard1(_iv_clamp(vec2(lo, hi)), a);
|
|
29221
|
+
}
|
|
29222
|
+
|
|
29223
|
+
// \u2500\u2500 Phase 2: elementary functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
29224
|
+
|
|
29225
|
+
vec2 _iv_abs(vec2 a) {
|
|
29226
|
+
float al = abs(a.x), ah = abs(a.y);
|
|
29227
|
+
bool straddle = (a.x <= 0.0 && a.y >= 0.0);
|
|
29228
|
+
return _iv_guard1(_iv_clamp(vec2(straddle ? 0.0 : min(al, ah), max(al, ah))), a);
|
|
29229
|
+
}
|
|
29230
|
+
|
|
29231
|
+
// Domain x \u2265 0: fully-negative box \u2192 empty; a box straddling 0 clamps lo to 0.
|
|
29232
|
+
vec2 _iv_sqrt(vec2 a) {
|
|
29233
|
+
vec2 r = vec2(sqrt(max(a.x, 0.0)), sqrt(max(a.y, 0.0)));
|
|
29234
|
+
r = (a.y < 0.0) ? IV_EMPTY : r;
|
|
29235
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29236
|
+
}
|
|
29237
|
+
|
|
29238
|
+
vec2 _iv_exp(vec2 a) {
|
|
29239
|
+
return _iv_guard1(_iv_clamp(vec2(exp(a.x), exp(a.y))), a);
|
|
29240
|
+
}
|
|
29241
|
+
|
|
29242
|
+
// Domain x > 0: fully-\u22640 box \u2192 empty; straddling box \u2192 lo clamped to \u2212IV_INF
|
|
29243
|
+
// (ln \u2192 \u2212\u221E as x \u2192 0\u207A, never a real \u2212inf).
|
|
29244
|
+
vec2 _iv_ln(vec2 a) {
|
|
29245
|
+
vec2 r = vec2(a.x > 0.0 ? log(a.x) : -IV_INF, log(a.y));
|
|
29246
|
+
r = (a.y <= 0.0) ? IV_EMPTY : r;
|
|
29247
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29248
|
+
}
|
|
29249
|
+
|
|
29250
|
+
const float _IV_INV_LN10 = 0.43429448190325176;
|
|
29251
|
+
const float _IV_INV_LN2 = 1.4426950408889634;
|
|
29252
|
+
|
|
29253
|
+
vec2 _iv_log10(vec2 a) {
|
|
29254
|
+
vec2 r = vec2(a.x > 0.0 ? log(a.x) * _IV_INV_LN10 : -IV_INF, log(a.y) * _IV_INV_LN10);
|
|
29255
|
+
r = (a.y <= 0.0) ? IV_EMPTY : r;
|
|
29256
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29257
|
+
}
|
|
29258
|
+
|
|
29259
|
+
vec2 _iv_log2(vec2 a) {
|
|
29260
|
+
vec2 r = vec2(a.x > 0.0 ? log(a.x) * _IV_INV_LN2 : -IV_INF, log(a.y) * _IV_INV_LN2);
|
|
29261
|
+
r = (a.y <= 0.0) ? IV_EMPTY : r;
|
|
29262
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29263
|
+
}
|
|
29264
|
+
|
|
29265
|
+
// Non-integer power. Real only for base \u2265 0: fully-negative box \u2192 empty; a box
|
|
29266
|
+
// straddling 0 clamps the base low end to 0. \`p\` is a compile-time constant, so
|
|
29267
|
+
// the \`p >= 0\` test is a constant branch.
|
|
29268
|
+
vec2 _iv_powf(vec2 a, float p) {
|
|
29269
|
+
float lob = max(a.x, 0.0);
|
|
29270
|
+
float e0 = pow(lob, p), e1 = pow(a.y, p);
|
|
29271
|
+
vec2 r = (p >= 0.0) ? vec2(e0, e1) : vec2(e1, e0);
|
|
29272
|
+
r = (a.y < 0.0) ? IV_EMPTY : r;
|
|
29273
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29274
|
+
}
|
|
29275
|
+
|
|
29276
|
+
// \u2500\u2500 Phase 3: trigonometric & inverse-trigonometric functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
29277
|
+
// Mirrors interval-js (interval/trigonometric.ts): exact endpoints with
|
|
29278
|
+
// extremum snapping (no outward epsilon). Per the Option-A contract, a tan pole
|
|
29279
|
+
// yields \`entire\` (interval-js returns \`singular\`; entire \u2287 singular and the
|
|
29280
|
+
// CPU classifies the asymptote).
|
|
29281
|
+
|
|
29282
|
+
const float _IV_PI = 3.141592653589793;
|
|
29283
|
+
const float _IV_TWO_PI = 6.283185307179586;
|
|
29284
|
+
const float _IV_HALF_PI = 1.5707963267948966;
|
|
29285
|
+
const float _IV_THREE_HALF_PI = 4.71238898038469;
|
|
29286
|
+
|
|
29287
|
+
// True if [a] contains an extremum of the family { ext + n\xB7period }.
|
|
29288
|
+
bool _iv_has_ext(vec2 a, float ext, float period) {
|
|
29289
|
+
float n = ceil((a.x - ext) / period);
|
|
29290
|
+
float cand = ext + n * period;
|
|
29291
|
+
return cand >= a.x - 1e-15 && cand <= a.y + 1e-15;
|
|
29292
|
+
}
|
|
29293
|
+
|
|
29294
|
+
vec2 _iv_sin(vec2 a) {
|
|
29295
|
+
vec2 r;
|
|
29296
|
+
if (a.y - a.x >= _IV_TWO_PI) r = vec2(-1.0, 1.0);
|
|
29297
|
+
else {
|
|
29298
|
+
float sl = sin(a.x), sh = sin(a.y);
|
|
29299
|
+
float lo = min(sl, sh), hi = max(sl, sh);
|
|
29300
|
+
if (_iv_has_ext(a, _IV_HALF_PI, _IV_TWO_PI)) hi = 1.0;
|
|
29301
|
+
if (_iv_has_ext(a, _IV_THREE_HALF_PI, _IV_TWO_PI)) lo = -1.0;
|
|
29302
|
+
r = vec2(lo, hi);
|
|
29303
|
+
}
|
|
29304
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29305
|
+
}
|
|
29306
|
+
|
|
29307
|
+
vec2 _iv_cos(vec2 a) {
|
|
29308
|
+
vec2 r;
|
|
29309
|
+
if (a.y - a.x >= _IV_TWO_PI) r = vec2(-1.0, 1.0);
|
|
29310
|
+
else {
|
|
29311
|
+
float cl = cos(a.x), ch = cos(a.y);
|
|
29312
|
+
float lo = min(cl, ch), hi = max(cl, ch);
|
|
29313
|
+
if (_iv_has_ext(a, 0.0, _IV_TWO_PI)) hi = 1.0;
|
|
29314
|
+
if (_iv_has_ext(a, _IV_PI, _IV_TWO_PI)) lo = -1.0;
|
|
29315
|
+
r = vec2(lo, hi);
|
|
29316
|
+
}
|
|
29317
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29318
|
+
}
|
|
29319
|
+
|
|
29320
|
+
vec2 _iv_tan(vec2 a) {
|
|
29321
|
+
// A pole in the interval \u2192 entire (cannot exclude).
|
|
29322
|
+
bool pole =
|
|
29323
|
+
(a.y - a.x >= _IV_PI) || _iv_has_ext(a, _IV_HALF_PI, _IV_PI);
|
|
29324
|
+
float tl = tan(a.x), th = tan(a.y);
|
|
29325
|
+
// Floating-point branch-cross sanity (large opposite-sign endpoints).
|
|
29326
|
+
bool crossed = (tl > 1e10 && th < -1e10) || (tl < -1e10 && th > 1e10);
|
|
29327
|
+
vec2 r = (pole || crossed) ? IV_ENTIRE : vec2(tl, th);
|
|
29328
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29329
|
+
}
|
|
29330
|
+
|
|
29331
|
+
// asin: domain [\u22121, 1]. Fully outside \u2192 empty; straddling clamps to the valid
|
|
29332
|
+
// sub-range. Monotonic increasing.
|
|
29333
|
+
vec2 _iv_asin(vec2 a) {
|
|
29334
|
+
vec2 r = vec2(asin(max(a.x, -1.0)), asin(min(a.y, 1.0)));
|
|
29335
|
+
r = (a.x > 1.0 || a.y < -1.0) ? IV_EMPTY : r;
|
|
29336
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29337
|
+
}
|
|
29338
|
+
|
|
29339
|
+
// acos: domain [\u22121, 1], monotonic decreasing (bounds swap).
|
|
29340
|
+
vec2 _iv_acos(vec2 a) {
|
|
29341
|
+
vec2 r = vec2(acos(min(a.y, 1.0)), acos(max(a.x, -1.0)));
|
|
29342
|
+
r = (a.x > 1.0 || a.y < -1.0) ? IV_EMPTY : r;
|
|
29343
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29344
|
+
}
|
|
29345
|
+
|
|
29346
|
+
vec2 _iv_atan(vec2 a) {
|
|
29347
|
+
return _iv_guard1(_iv_clamp(vec2(atan(a.x), atan(a.y))), a);
|
|
29348
|
+
}
|
|
29349
|
+
|
|
29350
|
+
// \u2500\u2500 Discontinuous / step functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
29351
|
+
// Bounded jump-discontinuity functions return the TIGHT value-range enclosure
|
|
29352
|
+
// (sound, and excludable when the range misses 0) rather than \`entire\` \u2014 only
|
|
29353
|
+
// genuine poles are entire. Per the Option-A division of labor, the CPU still
|
|
29354
|
+
// classifies the discontinuity on the (kept) live cells; the GPU only needs a
|
|
29355
|
+
// sound bound for the exclusion test. These functions are monotone, so the
|
|
29356
|
+
// enclosure is just [f(lo), f(hi)] unless noted.
|
|
29357
|
+
|
|
29358
|
+
vec2 _iv_floor(vec2 a) { return _iv_guard1(_iv_clamp(vec2(floor(a.x), floor(a.y))), a); }
|
|
29359
|
+
vec2 _iv_ceil(vec2 a) { return _iv_guard1(_iv_clamp(vec2(ceil(a.x), ceil(a.y))), a); }
|
|
29360
|
+
vec2 _iv_round(vec2 a) { return _iv_guard1(_iv_clamp(vec2(floor(a.x + 0.5), floor(a.y + 0.5))), a); }
|
|
29361
|
+
vec2 _iv_trunc(vec2 a) { return _iv_guard1(_iv_clamp(vec2(trunc(a.x), trunc(a.y))), a); }
|
|
29362
|
+
vec2 _iv_sign(vec2 a) { return _iv_guard1(vec2(sign(a.x), sign(a.y)), a); }
|
|
29363
|
+
|
|
29364
|
+
vec2 _iv_heaviside(vec2 a) {
|
|
29365
|
+
float hl = a.x < 0.0 ? 0.0 : (a.x > 0.0 ? 1.0 : 0.5);
|
|
29366
|
+
float hh = a.y < 0.0 ? 0.0 : (a.y > 0.0 ? 1.0 : 0.5);
|
|
29367
|
+
return _iv_guard1(vec2(hl, hh), a);
|
|
29368
|
+
}
|
|
29369
|
+
|
|
29370
|
+
// fract(x) = x \u2212 floor(x): continuous within an integer cell, sawtooth across
|
|
29371
|
+
// one (\u2192 full [0, 1] range).
|
|
29372
|
+
vec2 _iv_fract(vec2 a) {
|
|
29373
|
+
float fl = floor(a.x);
|
|
29374
|
+
vec2 r = (fl == floor(a.y)) ? vec2(a.x - fl, a.y - fl) : vec2(0.0, 1.0);
|
|
29375
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
29376
|
+
}
|
|
29377
|
+
|
|
29378
|
+
vec2 _iv_min(vec2 a, vec2 b) {
|
|
29379
|
+
return _iv_guard2(_iv_clamp(vec2(min(a.x, b.x), min(a.y, b.y))), a, b);
|
|
29380
|
+
}
|
|
29381
|
+
vec2 _iv_max(vec2 a, vec2 b) {
|
|
29382
|
+
return _iv_guard2(_iv_clamp(vec2(max(a.x, b.x), max(a.y, b.y))), a, b);
|
|
29383
|
+
}
|
|
29384
|
+
|
|
29385
|
+
// mod(x, y) = x \u2212 y\xB7floor(x/y). A modulus straddling 0 is a pole \u2192 entire. For
|
|
29386
|
+
// a constant (point) modulus the fast path is exact; otherwise compose (the
|
|
29387
|
+
// tight floor keeps it sound).
|
|
29388
|
+
vec2 _iv_mod(vec2 a, vec2 b) {
|
|
29389
|
+
if (b.x <= 0.0 && b.y >= 0.0) return _iv_guard2(IV_ENTIRE, a, b);
|
|
29390
|
+
if (b.x == b.y) {
|
|
29391
|
+
float p = abs(b.x);
|
|
29392
|
+
float flo = floor(a.x / p);
|
|
29393
|
+
vec2 r = (flo == floor(a.y / p)) ? vec2(a.x - p * flo, a.y - p * flo)
|
|
29394
|
+
: vec2(0.0, p);
|
|
29395
|
+
return _iv_guard2(_iv_clamp(r), a, b);
|
|
29396
|
+
}
|
|
29397
|
+
return _iv_sub(a, _iv_mul(b, _iv_floor(_iv_div(a, b))));
|
|
29398
|
+
}
|
|
29399
|
+
`;
|
|
29400
|
+
var INTERVAL_GLSL_FUNCTIONS = {
|
|
29401
|
+
Add: (args, compile2) => {
|
|
29402
|
+
if (args.length === 0) return "vec2(0.0, 0.0)";
|
|
29403
|
+
let r = compile2(args[0]);
|
|
29404
|
+
for (let i = 1; i < args.length; i++)
|
|
29405
|
+
r = `_iv_add(${r}, ${compile2(args[i])})`;
|
|
29406
|
+
return r;
|
|
29407
|
+
},
|
|
29408
|
+
Subtract: ([a, b], compile2) => {
|
|
29409
|
+
if (a === null || b === null) throw new Error("Subtract: missing argument");
|
|
29410
|
+
return `_iv_sub(${compile2(a)}, ${compile2(b)})`;
|
|
29411
|
+
},
|
|
29412
|
+
Multiply: (args, compile2) => {
|
|
29413
|
+
if (args.length === 0) return "vec2(1.0, 1.0)";
|
|
29414
|
+
let r = compile2(args[0]);
|
|
29415
|
+
for (let i = 1; i < args.length; i++)
|
|
29416
|
+
r = `_iv_mul(${r}, ${compile2(args[i])})`;
|
|
29417
|
+
return r;
|
|
29418
|
+
},
|
|
29419
|
+
Divide: ([a, b], compile2) => {
|
|
29420
|
+
if (a === null || b === null) throw new Error("Divide: missing argument");
|
|
29421
|
+
return `_iv_div(${compile2(a)}, ${compile2(b)})`;
|
|
29422
|
+
},
|
|
29423
|
+
Negate: ([a], compile2) => {
|
|
29424
|
+
if (a === null) throw new Error("Negate: no argument");
|
|
29425
|
+
return `_iv_negate(${compile2(a)})`;
|
|
29426
|
+
},
|
|
29427
|
+
Square: ([a], compile2) => {
|
|
29428
|
+
if (a === null) throw new Error("Square: no argument");
|
|
29429
|
+
return `_iv_square(${compile2(a)})`;
|
|
29430
|
+
},
|
|
29431
|
+
Sqrt: ([a], compile2) => {
|
|
29432
|
+
if (a === null) throw new Error("Sqrt: no argument");
|
|
29433
|
+
return `_iv_sqrt(${compile2(a)})`;
|
|
29434
|
+
},
|
|
29435
|
+
Abs: ([a], compile2) => {
|
|
29436
|
+
if (a === null) throw new Error("Abs: no argument");
|
|
29437
|
+
return `_iv_abs(${compile2(a)})`;
|
|
29438
|
+
},
|
|
29439
|
+
Exp: ([a], compile2) => {
|
|
29440
|
+
if (a === null) throw new Error("Exp: no argument");
|
|
29441
|
+
return `_iv_exp(${compile2(a)})`;
|
|
29442
|
+
},
|
|
29443
|
+
Ln: ([a], compile2) => {
|
|
29444
|
+
if (a === null) throw new Error("Ln: no argument");
|
|
29445
|
+
return `_iv_ln(${compile2(a)})`;
|
|
29446
|
+
},
|
|
29447
|
+
Log: (args, compile2) => {
|
|
29448
|
+
if (args.length === 1) return `_iv_log10(${compile2(args[0])})`;
|
|
29449
|
+
return `_iv_div(_iv_ln(${compile2(args[0])}), _iv_ln(${compile2(args[1])}))`;
|
|
29450
|
+
},
|
|
29451
|
+
Lb: ([a], compile2) => {
|
|
29452
|
+
if (a === null) throw new Error("Lb: no argument");
|
|
29453
|
+
return `_iv_log2(${compile2(a)})`;
|
|
29454
|
+
},
|
|
29455
|
+
Sin: ([a], compile2) => {
|
|
29456
|
+
if (a === null) throw new Error("Sin: no argument");
|
|
29457
|
+
return `_iv_sin(${compile2(a)})`;
|
|
29458
|
+
},
|
|
29459
|
+
Cos: ([a], compile2) => {
|
|
29460
|
+
if (a === null) throw new Error("Cos: no argument");
|
|
29461
|
+
return `_iv_cos(${compile2(a)})`;
|
|
29462
|
+
},
|
|
29463
|
+
Tan: ([a], compile2) => {
|
|
29464
|
+
if (a === null) throw new Error("Tan: no argument");
|
|
29465
|
+
return `_iv_tan(${compile2(a)})`;
|
|
29466
|
+
},
|
|
29467
|
+
Arcsin: ([a], compile2) => {
|
|
29468
|
+
if (a === null) throw new Error("Arcsin: no argument");
|
|
29469
|
+
return `_iv_asin(${compile2(a)})`;
|
|
29470
|
+
},
|
|
29471
|
+
Arccos: ([a], compile2) => {
|
|
29472
|
+
if (a === null) throw new Error("Arccos: no argument");
|
|
29473
|
+
return `_iv_acos(${compile2(a)})`;
|
|
29474
|
+
},
|
|
29475
|
+
Arctan: ([a], compile2) => {
|
|
29476
|
+
if (a === null) throw new Error("Arctan: no argument");
|
|
29477
|
+
return `_iv_atan(${compile2(a)})`;
|
|
29478
|
+
},
|
|
29479
|
+
Floor: ([a], compile2) => {
|
|
29480
|
+
if (a === null) throw new Error("Floor: no argument");
|
|
29481
|
+
return `_iv_floor(${compile2(a)})`;
|
|
29482
|
+
},
|
|
29483
|
+
Ceil: ([a], compile2) => {
|
|
29484
|
+
if (a === null) throw new Error("Ceil: no argument");
|
|
29485
|
+
return `_iv_ceil(${compile2(a)})`;
|
|
29486
|
+
},
|
|
29487
|
+
Round: ([a], compile2) => {
|
|
29488
|
+
if (a === null) throw new Error("Round: no argument");
|
|
29489
|
+
return `_iv_round(${compile2(a)})`;
|
|
29490
|
+
},
|
|
29491
|
+
Truncate: ([a], compile2) => {
|
|
29492
|
+
if (a === null) throw new Error("Truncate: no argument");
|
|
29493
|
+
return `_iv_trunc(${compile2(a)})`;
|
|
29494
|
+
},
|
|
29495
|
+
Fract: ([a], compile2) => {
|
|
29496
|
+
if (a === null) throw new Error("Fract: no argument");
|
|
29497
|
+
return `_iv_fract(${compile2(a)})`;
|
|
29498
|
+
},
|
|
29499
|
+
Sign: ([a], compile2) => {
|
|
29500
|
+
if (a === null) throw new Error("Sign: no argument");
|
|
29501
|
+
return `_iv_sign(${compile2(a)})`;
|
|
29502
|
+
},
|
|
29503
|
+
Heaviside: ([a], compile2) => {
|
|
29504
|
+
if (a === null) throw new Error("Heaviside: no argument");
|
|
29505
|
+
return `_iv_heaviside(${compile2(a)})`;
|
|
29506
|
+
},
|
|
29507
|
+
Mod: ([a, b], compile2) => {
|
|
29508
|
+
if (a === null || b === null) throw new Error("Mod: missing argument");
|
|
29509
|
+
return `_iv_mod(${compile2(a)}, ${compile2(b)})`;
|
|
29510
|
+
},
|
|
29511
|
+
Min: (args, compile2) => {
|
|
29512
|
+
if (args.length === 0) throw new Error("Min: no argument");
|
|
29513
|
+
let r = compile2(args[0]);
|
|
29514
|
+
for (let i = 1; i < args.length; i++)
|
|
29515
|
+
r = `_iv_min(${r}, ${compile2(args[i])})`;
|
|
29516
|
+
return r;
|
|
29517
|
+
},
|
|
29518
|
+
Max: (args, compile2) => {
|
|
29519
|
+
if (args.length === 0) throw new Error("Max: no argument");
|
|
29520
|
+
let r = compile2(args[0]);
|
|
29521
|
+
for (let i = 1; i < args.length; i++)
|
|
29522
|
+
r = `_iv_max(${r}, ${compile2(args[i])})`;
|
|
29523
|
+
return r;
|
|
29524
|
+
},
|
|
29525
|
+
Power: ([base, exp3], compile2) => {
|
|
29526
|
+
if (base === null || exp3 === null)
|
|
29527
|
+
throw new Error("Power: missing argument");
|
|
29528
|
+
if (isSymbol2(base, "ExponentialE")) return `_iv_exp(${compile2(exp3)})`;
|
|
29529
|
+
if (isNumber(exp3) && exp3.im === 0) {
|
|
29530
|
+
const v = exp3.re;
|
|
29531
|
+
if (v === 0.5) return `_iv_sqrt(${compile2(base)})`;
|
|
29532
|
+
if (v === 2) return `_iv_square(${compile2(base)})`;
|
|
29533
|
+
if (Number.isInteger(v) && v >= 0)
|
|
29534
|
+
return `_iv_powi(${compile2(base)}, ${formatGPUNumber(v)})`;
|
|
29535
|
+
if (!Number.isInteger(v) && v > 0)
|
|
29536
|
+
return `_iv_powf(${compile2(base)}, ${formatGPUNumber(v)})`;
|
|
29537
|
+
throw new Error(
|
|
29538
|
+
`interval-glsl: Power with exponent \`${exp3.toString()}\` is not yet supported`
|
|
29539
|
+
);
|
|
29540
|
+
}
|
|
29541
|
+
throw new Error(
|
|
29542
|
+
"interval-glsl: Power with a variable exponent is not yet supported"
|
|
29543
|
+
);
|
|
29544
|
+
}
|
|
29545
|
+
};
|
|
29546
|
+
var INTERVAL_GLSL_CONSTANTS = {
|
|
29547
|
+
Pi: "vec2(3.14159265359, 3.14159265359)",
|
|
29548
|
+
ExponentialE: "vec2(2.71828182846, 2.71828182846)",
|
|
29549
|
+
GoldenRatio: "vec2(1.61803398875, 1.61803398875)",
|
|
29550
|
+
CatalanConstant: "vec2(0.91596559417, 0.91596559417)",
|
|
29551
|
+
EulerGamma: "vec2(0.57721566490, 0.57721566490)"
|
|
29552
|
+
};
|
|
29553
|
+
var IntervalGLSLTarget = class extends GLSLTarget {
|
|
29554
|
+
languageId = "interval-glsl";
|
|
29555
|
+
getOperators() {
|
|
29556
|
+
return {};
|
|
29557
|
+
}
|
|
29558
|
+
getFunctions() {
|
|
29559
|
+
return INTERVAL_GLSL_FUNCTIONS;
|
|
29560
|
+
}
|
|
29561
|
+
getConstants() {
|
|
29562
|
+
return INTERVAL_GLSL_CONSTANTS;
|
|
29563
|
+
}
|
|
29564
|
+
createTarget(options = {}) {
|
|
29565
|
+
return super.createTarget({
|
|
29566
|
+
operators: () => void 0,
|
|
29567
|
+
functions: (id) => INTERVAL_GLSL_FUNCTIONS[id],
|
|
29568
|
+
number: (n) => `vec2(${formatGPUNumber(n)}, ${formatGPUNumber(n)})`,
|
|
29569
|
+
complex: () => {
|
|
29570
|
+
throw new Error("interval-glsl: complex values are not supported");
|
|
29571
|
+
},
|
|
29572
|
+
var: (id) => INTERVAL_GLSL_CONSTANTS[id],
|
|
29573
|
+
...options
|
|
29574
|
+
});
|
|
29575
|
+
}
|
|
29576
|
+
compile(expr, options = {}) {
|
|
29577
|
+
const { vars } = options;
|
|
29578
|
+
const target = this.createTarget({
|
|
29579
|
+
var: (id) => {
|
|
29580
|
+
if (vars && id in vars) return vars[id];
|
|
29581
|
+
if (id in INTERVAL_GLSL_CONSTANTS) return INTERVAL_GLSL_CONSTANTS[id];
|
|
29582
|
+
return void 0;
|
|
29583
|
+
}
|
|
29584
|
+
});
|
|
29585
|
+
const code = BaseCompiler.compile(expr, target);
|
|
29586
|
+
const result = {
|
|
29587
|
+
target: "interval-glsl",
|
|
29588
|
+
success: true,
|
|
29589
|
+
code
|
|
29590
|
+
};
|
|
29591
|
+
if (code.includes("_iv_")) result.preamble = INTERVAL_GLSL_PREAMBLE;
|
|
29592
|
+
return BaseCompiler.withReferences(
|
|
29593
|
+
result,
|
|
29594
|
+
expr,
|
|
29595
|
+
target,
|
|
29596
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
29597
|
+
);
|
|
29598
|
+
}
|
|
29599
|
+
/**
|
|
29600
|
+
* Emit a complete, self-contained GLSL fragment shader implementing the
|
|
29601
|
+
* **interval exclusion oracle** for the implicit curve `f = 0` (Phase 4).
|
|
29602
|
+
*
|
|
29603
|
+
* The shader is structured so the core contract — the interval evaluator —
|
|
29604
|
+
* is cleanly separable from the render harness:
|
|
29605
|
+
*
|
|
29606
|
+
* - `vec2 _implicit(<vec2 per free variable>)` evaluates the interval of `f`
|
|
29607
|
+
* over a cell box (this is the part that matters; it is identical to
|
|
29608
|
+
* `compile(expr).code` wrapped in a function).
|
|
29609
|
+
* - `main()` is a **reference harness**: it derives each fragment's cell box
|
|
29610
|
+
* from `gl_FragCoord` and the viewport uniforms, evaluates `_implicit`, and
|
|
29611
|
+
* writes the exclusion result. The renderer is free to replace `main()` /
|
|
29612
|
+
* the uniforms with its own conventions and keep `_implicit`.
|
|
29613
|
+
*
|
|
29614
|
+
* The first free variable maps to `u_domainX`, the second to `u_domainY`
|
|
29615
|
+
* (≤ 2 free variables; a 2D implicit curve). The exclusion predicate is
|
|
29616
|
+
* `f.lo > 0 || f.hi < 0` — which also excludes the `empty` (domain-undefined)
|
|
29617
|
+
* interval, since its `lo` is the `+IV_INF` sentinel.
|
|
29618
|
+
*
|
|
29619
|
+
* @throws if the expression has more than two free variables, or cannot be
|
|
29620
|
+
* lowered (an unsupported head propagates from `BaseCompiler.compile`).
|
|
29621
|
+
*/
|
|
29622
|
+
compileExclusionShader(expr, options = {}) {
|
|
29623
|
+
const { version: version2 = "300 es", precision = "highp" } = options;
|
|
29624
|
+
const compiled = this.compile(expr);
|
|
29625
|
+
const vars = compiled.freeSymbols ?? [];
|
|
29626
|
+
if (vars.length > 2)
|
|
29627
|
+
throw new Error(
|
|
29628
|
+
`interval-glsl exclusion shader supports at most 2 free variables (got ${vars.length}: ${vars.join(", ")})`
|
|
29629
|
+
);
|
|
29630
|
+
const params = vars.map((v) => `vec2 ${v}`).join(", ");
|
|
29631
|
+
const [axisX, axisY] = vars;
|
|
29632
|
+
const main = ["void main() {"];
|
|
29633
|
+
main.push(" vec2 _cell = gl_FragCoord.xy / u_resolution;");
|
|
29634
|
+
main.push(" vec2 _step = 1.0 / u_resolution;");
|
|
29635
|
+
const callArgs = [];
|
|
29636
|
+
if (axisX !== void 0) {
|
|
29637
|
+
main.push(" float _xlo = mix(u_domainX.x, u_domainX.y, _cell.x);");
|
|
29638
|
+
main.push(
|
|
29639
|
+
" float _xhi = mix(u_domainX.x, u_domainX.y, _cell.x + _step.x);"
|
|
29640
|
+
);
|
|
29641
|
+
callArgs.push("vec2(_xlo, _xhi)");
|
|
29642
|
+
}
|
|
29643
|
+
if (axisY !== void 0) {
|
|
29644
|
+
main.push(" float _ylo = mix(u_domainY.x, u_domainY.y, _cell.y);");
|
|
29645
|
+
main.push(
|
|
29646
|
+
" float _yhi = mix(u_domainY.x, u_domainY.y, _cell.y + _step.y);"
|
|
29647
|
+
);
|
|
29648
|
+
callArgs.push("vec2(_ylo, _yhi)");
|
|
29649
|
+
}
|
|
29650
|
+
main.push(` vec2 _f = _implicit(${callArgs.join(", ")});`);
|
|
29651
|
+
main.push(" bool _excluded = (_f.x > 0.0 || _f.y < 0.0);");
|
|
29652
|
+
main.push(
|
|
29653
|
+
" fragColor = _excluded ? vec4(0.0, 0.0, 0.0, 1.0) : vec4(1.0);"
|
|
29654
|
+
);
|
|
29655
|
+
main.push("}");
|
|
29656
|
+
return [
|
|
29657
|
+
`#version ${version2}`,
|
|
29658
|
+
`precision ${precision} float;`,
|
|
29659
|
+
"",
|
|
29660
|
+
INTERVAL_GLSL_PREAMBLE.trim(),
|
|
29661
|
+
"",
|
|
29662
|
+
"uniform vec2 u_domainX; // [min, max] for the 1st free variable",
|
|
29663
|
+
"uniform vec2 u_domainY; // [min, max] for the 2nd free variable",
|
|
29664
|
+
"uniform vec2 u_resolution; // render target size, in pixels",
|
|
29665
|
+
"",
|
|
29666
|
+
"out vec4 fragColor;",
|
|
29667
|
+
"",
|
|
29668
|
+
"// Interval evaluation of the implicit field f over a cell box.",
|
|
29669
|
+
`vec2 _implicit(${params}) {`,
|
|
29670
|
+
` return ${compiled.code};`,
|
|
29671
|
+
"}",
|
|
29672
|
+
"",
|
|
29673
|
+
main.join("\n"),
|
|
29674
|
+
""
|
|
29675
|
+
].join("\n");
|
|
29676
|
+
}
|
|
29677
|
+
};
|
|
29678
|
+
|
|
28435
29679
|
// src/compile.ts
|
|
28436
|
-
var version = "0.
|
|
29680
|
+
var version = "0.61.0";
|
|
28437
29681
|
export {
|
|
28438
29682
|
BaseCompiler,
|
|
28439
29683
|
GLSLTarget,
|
|
28440
29684
|
GPUShaderTarget,
|
|
29685
|
+
IntervalGLSLTarget,
|
|
28441
29686
|
IntervalJavaScriptTarget,
|
|
28442
29687
|
JavaScriptTarget,
|
|
28443
29688
|
PythonTarget,
|