@cortex-js/compute-engine 0.55.0 → 0.55.3
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 +2498 -2108
- package/dist/compile.min.esm.js +48 -48
- package/dist/compile.min.umd.cjs +49 -49
- package/dist/compile.umd.cjs +2498 -2108
- package/dist/compute-engine.esm.js +1219 -719
- package/dist/compute-engine.min.esm.js +73 -73
- package/dist/compute-engine.min.umd.cjs +73 -73
- package/dist/compute-engine.umd.cjs +1219 -719
- package/dist/core.esm.js +1223 -715
- package/dist/core.min.esm.js +72 -72
- package/dist/core.min.umd.cjs +72 -72
- package/dist/core.umd.cjs +1223 -715
- package/dist/interval.esm.js +1564 -1412
- package/dist/interval.min.esm.js +6 -6
- package/dist/interval.min.umd.cjs +6 -6
- package/dist/interval.umd.cjs +1564 -1412
- package/dist/latex-syntax.esm.js +673 -492
- package/dist/latex-syntax.min.esm.js +6 -6
- package/dist/latex-syntax.min.umd.cjs +6 -6
- package/dist/latex-syntax.umd.cjs +673 -492
- 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 +1 -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/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/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/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 +8 -7
- package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
- package/dist/types/compute-engine/compilation/constant-folding.d.ts +50 -0
- package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +23 -1
- package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/types.d.ts +1 -1
- 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-utils.d.ts +1 -1
- package/dist/types/compute-engine/global-types.d.ts +1 -1
- package/dist/types/compute-engine/index.d.ts +1 -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-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 +3 -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 +11 -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/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/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/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/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/numerics/unit-data.d.ts +1 -1
- package/dist/types/compute-engine/oeis.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/logic-utils.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 +1 -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/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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 0.55.
|
|
1
|
+
/** Compute Engine 0.55.3 */
|
|
2
2
|
|
|
3
3
|
// node_modules/complex-esm/dist/src/complex.js
|
|
4
4
|
var cosh = Math.cosh || function(x) {
|
|
@@ -9526,6 +9526,452 @@ function expressionToDictionaryValue(expr2) {
|
|
|
9526
9526
|
return expr2;
|
|
9527
9527
|
}
|
|
9528
9528
|
|
|
9529
|
+
// src/compute-engine/latex-syntax/dictionary/definitions-logic.ts
|
|
9530
|
+
var DEFINITIONS_LOGIC = [
|
|
9531
|
+
// Constants
|
|
9532
|
+
{
|
|
9533
|
+
name: "True",
|
|
9534
|
+
kind: "symbol",
|
|
9535
|
+
latexTrigger: ["\\top"]
|
|
9536
|
+
// ⊤ U+22A4
|
|
9537
|
+
},
|
|
9538
|
+
{
|
|
9539
|
+
kind: "symbol",
|
|
9540
|
+
latexTrigger: "\\mathrm{True}",
|
|
9541
|
+
parse: "True"
|
|
9542
|
+
},
|
|
9543
|
+
{
|
|
9544
|
+
kind: "symbol",
|
|
9545
|
+
latexTrigger: "\\operatorname{True}",
|
|
9546
|
+
parse: "True"
|
|
9547
|
+
},
|
|
9548
|
+
{
|
|
9549
|
+
kind: "symbol",
|
|
9550
|
+
latexTrigger: "\\mathsf{T}",
|
|
9551
|
+
parse: "True"
|
|
9552
|
+
},
|
|
9553
|
+
{
|
|
9554
|
+
name: "False",
|
|
9555
|
+
kind: "symbol",
|
|
9556
|
+
latexTrigger: ["\\bot"]
|
|
9557
|
+
// ⊥ U+22A5
|
|
9558
|
+
},
|
|
9559
|
+
{
|
|
9560
|
+
kind: "symbol",
|
|
9561
|
+
latexTrigger: "\\operatorname{False}",
|
|
9562
|
+
parse: "False"
|
|
9563
|
+
},
|
|
9564
|
+
{
|
|
9565
|
+
kind: "symbol",
|
|
9566
|
+
latexTrigger: "\\mathsf{F}",
|
|
9567
|
+
parse: "False"
|
|
9568
|
+
},
|
|
9569
|
+
// Operators
|
|
9570
|
+
// Logic operators have lower precedence than comparisons (245)
|
|
9571
|
+
// so that `x = 1 \lor x = 2` parses as `(x = 1) \lor (x = 2)`
|
|
9572
|
+
// See https://github.com/cortex-js/compute-engine/issues/243
|
|
9573
|
+
{
|
|
9574
|
+
name: "And",
|
|
9575
|
+
kind: "infix",
|
|
9576
|
+
latexTrigger: ["\\land"],
|
|
9577
|
+
precedence: 235
|
|
9578
|
+
// serialize: '\\land',
|
|
9579
|
+
},
|
|
9580
|
+
{ kind: "infix", latexTrigger: ["\\wedge"], parse: "And", precedence: 235 },
|
|
9581
|
+
{ kind: "infix", latexTrigger: "\\&", parse: "And", precedence: 235 },
|
|
9582
|
+
{
|
|
9583
|
+
kind: "infix",
|
|
9584
|
+
latexTrigger: "\\operatorname{and}",
|
|
9585
|
+
parse: "And",
|
|
9586
|
+
precedence: 235
|
|
9587
|
+
},
|
|
9588
|
+
{
|
|
9589
|
+
name: "Or",
|
|
9590
|
+
kind: "infix",
|
|
9591
|
+
latexTrigger: ["\\lor"],
|
|
9592
|
+
precedence: 230
|
|
9593
|
+
},
|
|
9594
|
+
{ kind: "infix", latexTrigger: ["\\vee"], parse: "Or", precedence: 230 },
|
|
9595
|
+
{ kind: "infix", latexTrigger: "\\parallel", parse: "Or", precedence: 230 },
|
|
9596
|
+
{
|
|
9597
|
+
kind: "infix",
|
|
9598
|
+
latexTrigger: "\\operatorname{or}",
|
|
9599
|
+
parse: "Or",
|
|
9600
|
+
precedence: 230
|
|
9601
|
+
},
|
|
9602
|
+
{
|
|
9603
|
+
name: "Xor",
|
|
9604
|
+
kind: "infix",
|
|
9605
|
+
latexTrigger: ["\\veebar"],
|
|
9606
|
+
precedence: 232
|
|
9607
|
+
},
|
|
9608
|
+
// Possible alt: \oplus ⊕ U+2295
|
|
9609
|
+
{
|
|
9610
|
+
name: "Not",
|
|
9611
|
+
kind: "prefix",
|
|
9612
|
+
latexTrigger: ["\\lnot"],
|
|
9613
|
+
precedence: 880
|
|
9614
|
+
},
|
|
9615
|
+
{
|
|
9616
|
+
kind: "prefix",
|
|
9617
|
+
latexTrigger: ["\\neg"],
|
|
9618
|
+
parse: "Not",
|
|
9619
|
+
precedence: 880
|
|
9620
|
+
},
|
|
9621
|
+
{
|
|
9622
|
+
name: "Nand",
|
|
9623
|
+
kind: "infix",
|
|
9624
|
+
latexTrigger: ["\\barwedge"],
|
|
9625
|
+
precedence: 232
|
|
9626
|
+
// serialize: '\\mid',
|
|
9627
|
+
},
|
|
9628
|
+
{
|
|
9629
|
+
name: "Nor",
|
|
9630
|
+
kind: "infix",
|
|
9631
|
+
latexTrigger: ["\u22BD"],
|
|
9632
|
+
// bar vee
|
|
9633
|
+
precedence: 232
|
|
9634
|
+
// serialize: '\\downarrow',
|
|
9635
|
+
},
|
|
9636
|
+
// Functions
|
|
9637
|
+
{
|
|
9638
|
+
kind: "function",
|
|
9639
|
+
symbolTrigger: "and",
|
|
9640
|
+
parse: "And"
|
|
9641
|
+
},
|
|
9642
|
+
{
|
|
9643
|
+
kind: "function",
|
|
9644
|
+
symbolTrigger: "or",
|
|
9645
|
+
parse: "Or"
|
|
9646
|
+
},
|
|
9647
|
+
{
|
|
9648
|
+
kind: "function",
|
|
9649
|
+
symbolTrigger: "not",
|
|
9650
|
+
parse: "Not"
|
|
9651
|
+
},
|
|
9652
|
+
// Relations
|
|
9653
|
+
{
|
|
9654
|
+
name: "Implies",
|
|
9655
|
+
kind: "infix",
|
|
9656
|
+
precedence: 220,
|
|
9657
|
+
associativity: "right",
|
|
9658
|
+
latexTrigger: ["\\implies"],
|
|
9659
|
+
serialize: "\\implies"
|
|
9660
|
+
},
|
|
9661
|
+
{
|
|
9662
|
+
latexTrigger: ["\\Rightarrow"],
|
|
9663
|
+
kind: "infix",
|
|
9664
|
+
precedence: 220,
|
|
9665
|
+
associativity: "right",
|
|
9666
|
+
parse: "Implies"
|
|
9667
|
+
},
|
|
9668
|
+
{
|
|
9669
|
+
latexTrigger: ["\\rightarrow"],
|
|
9670
|
+
kind: "infix",
|
|
9671
|
+
precedence: 220,
|
|
9672
|
+
associativity: "right",
|
|
9673
|
+
parse: "Implies"
|
|
9674
|
+
},
|
|
9675
|
+
{
|
|
9676
|
+
latexTrigger: ["\\Longrightarrow"],
|
|
9677
|
+
kind: "infix",
|
|
9678
|
+
precedence: 220,
|
|
9679
|
+
associativity: "right",
|
|
9680
|
+
parse: "Implies"
|
|
9681
|
+
},
|
|
9682
|
+
{
|
|
9683
|
+
latexTrigger: ["\\longrightarrow"],
|
|
9684
|
+
kind: "infix",
|
|
9685
|
+
precedence: 220,
|
|
9686
|
+
associativity: "right",
|
|
9687
|
+
parse: "Implies"
|
|
9688
|
+
},
|
|
9689
|
+
{
|
|
9690
|
+
// Non-strict mode: => for implies
|
|
9691
|
+
latexTrigger: ["=", ">"],
|
|
9692
|
+
kind: "infix",
|
|
9693
|
+
precedence: 220,
|
|
9694
|
+
associativity: "right",
|
|
9695
|
+
parse: (parser, lhs, until) => {
|
|
9696
|
+
if (parser.options.strict !== false) return null;
|
|
9697
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 220 });
|
|
9698
|
+
if (rhs === null) return null;
|
|
9699
|
+
return ["Implies", lhs, rhs];
|
|
9700
|
+
}
|
|
9701
|
+
},
|
|
9702
|
+
{
|
|
9703
|
+
name: "Equivalent",
|
|
9704
|
+
// MathML: identical to, Mathematica: Congruent
|
|
9705
|
+
latexTrigger: ["\\iff"],
|
|
9706
|
+
kind: "infix",
|
|
9707
|
+
associativity: "right",
|
|
9708
|
+
precedence: 219
|
|
9709
|
+
},
|
|
9710
|
+
{
|
|
9711
|
+
latexTrigger: ["\\Leftrightarrow"],
|
|
9712
|
+
kind: "infix",
|
|
9713
|
+
associativity: "right",
|
|
9714
|
+
precedence: 219,
|
|
9715
|
+
parse: "Equivalent"
|
|
9716
|
+
},
|
|
9717
|
+
{
|
|
9718
|
+
latexTrigger: ["\\leftrightarrow"],
|
|
9719
|
+
kind: "infix",
|
|
9720
|
+
associativity: "right",
|
|
9721
|
+
precedence: 219,
|
|
9722
|
+
parse: "Equivalent"
|
|
9723
|
+
},
|
|
9724
|
+
{
|
|
9725
|
+
latexTrigger: ["\\Longleftrightarrow"],
|
|
9726
|
+
kind: "infix",
|
|
9727
|
+
associativity: "right",
|
|
9728
|
+
precedence: 219,
|
|
9729
|
+
parse: "Equivalent"
|
|
9730
|
+
},
|
|
9731
|
+
{
|
|
9732
|
+
latexTrigger: ["\\longleftrightarrow"],
|
|
9733
|
+
kind: "infix",
|
|
9734
|
+
associativity: "right",
|
|
9735
|
+
precedence: 219,
|
|
9736
|
+
parse: "Equivalent"
|
|
9737
|
+
},
|
|
9738
|
+
{
|
|
9739
|
+
// Non-strict mode: <=> for equivalence
|
|
9740
|
+
latexTrigger: ["<", "=", ">"],
|
|
9741
|
+
kind: "infix",
|
|
9742
|
+
precedence: 219,
|
|
9743
|
+
associativity: "right",
|
|
9744
|
+
parse: (parser, lhs, until) => {
|
|
9745
|
+
if (parser.options.strict !== false) return null;
|
|
9746
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 219 });
|
|
9747
|
+
if (rhs === null) return null;
|
|
9748
|
+
return ["Equivalent", lhs, rhs];
|
|
9749
|
+
}
|
|
9750
|
+
},
|
|
9751
|
+
{
|
|
9752
|
+
latexTrigger: ["\\equiv"],
|
|
9753
|
+
kind: "infix",
|
|
9754
|
+
associativity: "right",
|
|
9755
|
+
precedence: 219,
|
|
9756
|
+
parse: (parser, lhs, terminator) => {
|
|
9757
|
+
const rhs = parser.parseExpression({ ...terminator, minPrec: 219 });
|
|
9758
|
+
const index = parser.index;
|
|
9759
|
+
const modulus = parser.parseExpression({ ...terminator, minPrec: 219 });
|
|
9760
|
+
if (modulus !== null && operator(modulus) === "Mod")
|
|
9761
|
+
return ["Congruent", lhs, rhs, missingIfEmpty(operand(modulus, 1))];
|
|
9762
|
+
parser.index = index;
|
|
9763
|
+
return ["Equivalent", lhs, missingIfEmpty(rhs)];
|
|
9764
|
+
}
|
|
9765
|
+
},
|
|
9766
|
+
{
|
|
9767
|
+
name: "Proves",
|
|
9768
|
+
kind: "infix",
|
|
9769
|
+
latexTrigger: ["\\vdash"],
|
|
9770
|
+
precedence: 220,
|
|
9771
|
+
associativity: "right",
|
|
9772
|
+
serialize: "\\vdash"
|
|
9773
|
+
},
|
|
9774
|
+
{
|
|
9775
|
+
name: "Entails",
|
|
9776
|
+
kind: "infix",
|
|
9777
|
+
latexTrigger: ["\\vDash"],
|
|
9778
|
+
precedence: 220,
|
|
9779
|
+
associativity: "right",
|
|
9780
|
+
serialize: "\\vDash"
|
|
9781
|
+
},
|
|
9782
|
+
{
|
|
9783
|
+
name: "Satisfies",
|
|
9784
|
+
kind: "infix",
|
|
9785
|
+
latexTrigger: ["\\models"],
|
|
9786
|
+
precedence: 220,
|
|
9787
|
+
associativity: "right",
|
|
9788
|
+
serialize: "\\models"
|
|
9789
|
+
},
|
|
9790
|
+
// Quantifiers: for all, exists
|
|
9791
|
+
{
|
|
9792
|
+
name: "ForAll",
|
|
9793
|
+
kind: "prefix",
|
|
9794
|
+
latexTrigger: ["\\forall"],
|
|
9795
|
+
precedence: 200,
|
|
9796
|
+
// Has to be lower than COMPARISON_PRECEDENCE
|
|
9797
|
+
serialize: serializeQuantifier("\\forall"),
|
|
9798
|
+
parse: parseQuantifier("ForAll")
|
|
9799
|
+
},
|
|
9800
|
+
{
|
|
9801
|
+
name: "Exists",
|
|
9802
|
+
kind: "prefix",
|
|
9803
|
+
latexTrigger: ["\\exists"],
|
|
9804
|
+
precedence: 200,
|
|
9805
|
+
// Has to be lower than COMPARISON_PRECEDENCE,
|
|
9806
|
+
serialize: serializeQuantifier("\\exists"),
|
|
9807
|
+
parse: parseQuantifier("Exists")
|
|
9808
|
+
},
|
|
9809
|
+
{
|
|
9810
|
+
name: "ExistsUnique",
|
|
9811
|
+
kind: "prefix",
|
|
9812
|
+
latexTrigger: ["\\exists", "!"],
|
|
9813
|
+
precedence: 200,
|
|
9814
|
+
// Has to be lower than COMPARISON_PRECEDENCE,
|
|
9815
|
+
serialize: serializeQuantifier("\\exists!"),
|
|
9816
|
+
parse: parseQuantifier("ExistsUnique")
|
|
9817
|
+
},
|
|
9818
|
+
{
|
|
9819
|
+
name: "NotForAll",
|
|
9820
|
+
kind: "prefix",
|
|
9821
|
+
latexTrigger: ["\\lnot", "\\forall"],
|
|
9822
|
+
precedence: 200,
|
|
9823
|
+
// Has to be lower than COMPARISON_PRECEDENCE
|
|
9824
|
+
serialize: serializeQuantifier("\\lnot\\forall"),
|
|
9825
|
+
parse: parseQuantifier("NotForAll")
|
|
9826
|
+
},
|
|
9827
|
+
{
|
|
9828
|
+
name: "NotExists",
|
|
9829
|
+
kind: "prefix",
|
|
9830
|
+
latexTrigger: ["\\lnot", "\\exists"],
|
|
9831
|
+
precedence: 200,
|
|
9832
|
+
// Has to be lower than COMPARISON_PRECEDENCE,
|
|
9833
|
+
serialize: serializeQuantifier("\\lnot\\exists"),
|
|
9834
|
+
parse: parseQuantifier("NotExists")
|
|
9835
|
+
},
|
|
9836
|
+
{
|
|
9837
|
+
name: "KroneckerDelta",
|
|
9838
|
+
kind: "prefix",
|
|
9839
|
+
latexTrigger: ["\\delta", "_"],
|
|
9840
|
+
precedence: 200,
|
|
9841
|
+
serialize: (serializer, expr2) => {
|
|
9842
|
+
const args = operands(expr2);
|
|
9843
|
+
if (args.length === 0) return "\\delta";
|
|
9844
|
+
if (args.every((x) => symbol(x)))
|
|
9845
|
+
return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join("")}}`;
|
|
9846
|
+
return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join(", ")}}`;
|
|
9847
|
+
},
|
|
9848
|
+
parse: (parser) => {
|
|
9849
|
+
const group = parser.parseGroup();
|
|
9850
|
+
if (group === null) {
|
|
9851
|
+
const token = parser.parseToken();
|
|
9852
|
+
if (!token) return null;
|
|
9853
|
+
return ["KroneckerDelta", token];
|
|
9854
|
+
}
|
|
9855
|
+
const seq = getSequence(group);
|
|
9856
|
+
if (seq && seq.length <= 2) return ["KroneckerDelta", ...seq];
|
|
9857
|
+
if (operator(group) === "InvisibleOperator")
|
|
9858
|
+
return ["KroneckerDelta", ...operands(group)];
|
|
9859
|
+
if (group !== null) return ["KroneckerDelta", group];
|
|
9860
|
+
return null;
|
|
9861
|
+
}
|
|
9862
|
+
},
|
|
9863
|
+
// Iverson brackets. Also called the "indicator function"
|
|
9864
|
+
// Must have a single argument, a relational expression, i.e.
|
|
9865
|
+
// `[ a = b ]` or `[ x \leq 0 ]`
|
|
9866
|
+
// Otherwise, it gets rejected, it could be something else, like a list or
|
|
9867
|
+
// tuple.
|
|
9868
|
+
{
|
|
9869
|
+
name: "Boole",
|
|
9870
|
+
kind: "matchfix",
|
|
9871
|
+
openTrigger: "[",
|
|
9872
|
+
closeTrigger: "]",
|
|
9873
|
+
// serialize: (serializer: Serializer, expr: MathJsonExpression) => {
|
|
9874
|
+
// const args = ops(expr);
|
|
9875
|
+
// return `[${serializer.serialize(arg)}]`;
|
|
9876
|
+
// },
|
|
9877
|
+
parse: (_parser, body) => {
|
|
9878
|
+
const h = operator(body);
|
|
9879
|
+
if (!h) return null;
|
|
9880
|
+
if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
|
|
9881
|
+
return ["Boole", body];
|
|
9882
|
+
}
|
|
9883
|
+
},
|
|
9884
|
+
{
|
|
9885
|
+
kind: "matchfix",
|
|
9886
|
+
openTrigger: "\\llbracket",
|
|
9887
|
+
closeTrigger: "\\rrbracket",
|
|
9888
|
+
parse: (_parser, body) => {
|
|
9889
|
+
const h = operator(body);
|
|
9890
|
+
if (!h) return null;
|
|
9891
|
+
if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
|
|
9892
|
+
return ["Boole", body];
|
|
9893
|
+
}
|
|
9894
|
+
},
|
|
9895
|
+
// Predicate application in First-Order Logic.
|
|
9896
|
+
// ["Predicate", "P", "x", "y"] serializes to "P(x, y)"
|
|
9897
|
+
{
|
|
9898
|
+
name: "Predicate",
|
|
9899
|
+
serialize: (serializer, expr2) => {
|
|
9900
|
+
const args = operands(expr2);
|
|
9901
|
+
if (args.length === 0) return "";
|
|
9902
|
+
const pred = args[0];
|
|
9903
|
+
const predStr = typeof pred === "string" ? pred : serializer.serialize(pred);
|
|
9904
|
+
if (args.length === 1) return predStr;
|
|
9905
|
+
const argStrs = args.slice(1).map((arg) => serializer.serialize(arg));
|
|
9906
|
+
return `${predStr}(${argStrs.join(", ")})`;
|
|
9907
|
+
}
|
|
9908
|
+
}
|
|
9909
|
+
];
|
|
9910
|
+
function serializeQuantifier(quantifierSymbol) {
|
|
9911
|
+
return (serializer, expr2) => {
|
|
9912
|
+
const args = operands(expr2);
|
|
9913
|
+
if (args.length === 0) return quantifierSymbol;
|
|
9914
|
+
if (args.length === 1)
|
|
9915
|
+
return `${quantifierSymbol} ${serializer.serialize(args[0])}`;
|
|
9916
|
+
const boundVar = serializer.serialize(args[0]);
|
|
9917
|
+
const body = serializer.serialize(args[1]);
|
|
9918
|
+
return `${quantifierSymbol} ${boundVar}, ${body}`;
|
|
9919
|
+
};
|
|
9920
|
+
}
|
|
9921
|
+
function tightBindingCondition(p, terminator) {
|
|
9922
|
+
return p.peek === "\\to" || p.peek === "\\rightarrow" || p.peek === "\\implies" || p.peek === "\\Rightarrow" || p.peek === "\\iff" || p.peek === "\\Leftrightarrow" || p.peek === "\\land" || p.peek === "\\wedge" || p.peek === "\\lor" || p.peek === "\\vee" || (terminator.condition?.(p) ?? false);
|
|
9923
|
+
}
|
|
9924
|
+
function parseQuantifier(kind) {
|
|
9925
|
+
return (parser, terminator) => {
|
|
9926
|
+
const index = parser.index;
|
|
9927
|
+
const useTightBinding = parser.options.quantifierScope !== "loose";
|
|
9928
|
+
const symbol2 = parser.parseSymbol(terminator);
|
|
9929
|
+
if (symbol2) {
|
|
9930
|
+
parser.skipSpace();
|
|
9931
|
+
if (parser.match(",") || parser.match("\\mid") || parser.match(".") || parser.match(":") || parser.match("\\colon")) {
|
|
9932
|
+
const bodyTerminator = useTightBinding ? {
|
|
9933
|
+
...terminator,
|
|
9934
|
+
condition: (p) => tightBindingCondition(p, terminator)
|
|
9935
|
+
} : terminator;
|
|
9936
|
+
parser.enterQuantifierScope();
|
|
9937
|
+
const body2 = parser.parseExpression(bodyTerminator);
|
|
9938
|
+
parser.exitQuantifierScope();
|
|
9939
|
+
return [kind, symbol2, missingIfEmpty(body2)];
|
|
9940
|
+
}
|
|
9941
|
+
parser.enterQuantifierScope();
|
|
9942
|
+
const body = parser.parseEnclosure();
|
|
9943
|
+
parser.exitQuantifierScope();
|
|
9944
|
+
if (body) return [kind, symbol2, missingIfEmpty(body)];
|
|
9945
|
+
}
|
|
9946
|
+
parser.index = index;
|
|
9947
|
+
const condTerminator = {
|
|
9948
|
+
...terminator,
|
|
9949
|
+
condition: (p) => p.peek === ":" || p.peek === "\\colon" || (terminator.condition?.(p) ?? false)
|
|
9950
|
+
};
|
|
9951
|
+
const condition = parser.parseExpression(condTerminator);
|
|
9952
|
+
if (condition === null) return null;
|
|
9953
|
+
parser.skipSpace();
|
|
9954
|
+
if (parser.matchAny([",", "\\mid", ":", "\\colon"])) {
|
|
9955
|
+
const bodyTerminator = useTightBinding ? {
|
|
9956
|
+
...terminator,
|
|
9957
|
+
condition: (p) => tightBindingCondition(p, terminator)
|
|
9958
|
+
} : terminator;
|
|
9959
|
+
parser.enterQuantifierScope();
|
|
9960
|
+
const body = parser.parseExpression(bodyTerminator);
|
|
9961
|
+
parser.exitQuantifierScope();
|
|
9962
|
+
return [kind, condition, missingIfEmpty(body)];
|
|
9963
|
+
}
|
|
9964
|
+
if (parser.match("(")) {
|
|
9965
|
+
parser.enterQuantifierScope();
|
|
9966
|
+
const body = parser.parseExpression(terminator);
|
|
9967
|
+
parser.exitQuantifierScope();
|
|
9968
|
+
if (!parser.match(")")) return null;
|
|
9969
|
+
return [kind, condition, missingIfEmpty(body)];
|
|
9970
|
+
}
|
|
9971
|
+
return null;
|
|
9972
|
+
};
|
|
9973
|
+
}
|
|
9974
|
+
|
|
9529
9975
|
// src/compute-engine/latex-syntax/dictionary/definitions-core.ts
|
|
9530
9976
|
function parseSequence(parser, terminator, lhs, prec, sep) {
|
|
9531
9977
|
if (terminator && terminator.minPrec >= prec) return null;
|
|
@@ -10136,6 +10582,120 @@ var DEFINITIONS_CORE = [
|
|
|
10136
10582
|
precedence: 21,
|
|
10137
10583
|
parse: (parser, lhs, until) => parseWhereExpression(parser, lhs, until)
|
|
10138
10584
|
},
|
|
10585
|
+
// \text{and} — logical conjunction infix
|
|
10586
|
+
{
|
|
10587
|
+
latexTrigger: ["\\text"],
|
|
10588
|
+
kind: "infix",
|
|
10589
|
+
associativity: "right",
|
|
10590
|
+
precedence: 235,
|
|
10591
|
+
// Same as \land
|
|
10592
|
+
parse: (parser, lhs, until) => {
|
|
10593
|
+
const start = parser.index;
|
|
10594
|
+
if (!matchTextKeyword(parser, "and")) {
|
|
10595
|
+
parser.index = start;
|
|
10596
|
+
return null;
|
|
10597
|
+
}
|
|
10598
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 235 });
|
|
10599
|
+
return ["And", lhs, rhs ?? "Nothing"];
|
|
10600
|
+
}
|
|
10601
|
+
},
|
|
10602
|
+
// \text{or} — logical disjunction infix
|
|
10603
|
+
{
|
|
10604
|
+
latexTrigger: ["\\text"],
|
|
10605
|
+
kind: "infix",
|
|
10606
|
+
associativity: "right",
|
|
10607
|
+
precedence: 230,
|
|
10608
|
+
// Same as \lor
|
|
10609
|
+
parse: (parser, lhs, until) => {
|
|
10610
|
+
const start = parser.index;
|
|
10611
|
+
if (!matchTextKeyword(parser, "or")) {
|
|
10612
|
+
parser.index = start;
|
|
10613
|
+
return null;
|
|
10614
|
+
}
|
|
10615
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 230 });
|
|
10616
|
+
return ["Or", lhs, rhs ?? "Nothing"];
|
|
10617
|
+
}
|
|
10618
|
+
},
|
|
10619
|
+
// \text{iff} — biconditional (if and only if)
|
|
10620
|
+
{
|
|
10621
|
+
latexTrigger: ["\\text"],
|
|
10622
|
+
kind: "infix",
|
|
10623
|
+
associativity: "right",
|
|
10624
|
+
precedence: 219,
|
|
10625
|
+
// Same as \iff
|
|
10626
|
+
parse: (parser, lhs, until) => {
|
|
10627
|
+
const start = parser.index;
|
|
10628
|
+
if (!matchTextKeyword(parser, "iff")) {
|
|
10629
|
+
parser.index = start;
|
|
10630
|
+
return null;
|
|
10631
|
+
}
|
|
10632
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 219 });
|
|
10633
|
+
return ["Equivalent", lhs, rhs ?? "Nothing"];
|
|
10634
|
+
}
|
|
10635
|
+
},
|
|
10636
|
+
// \text{if and only if} — verbose biconditional
|
|
10637
|
+
{
|
|
10638
|
+
latexTrigger: ["\\text"],
|
|
10639
|
+
kind: "infix",
|
|
10640
|
+
associativity: "right",
|
|
10641
|
+
precedence: 219,
|
|
10642
|
+
parse: (parser, lhs, until) => {
|
|
10643
|
+
const start = parser.index;
|
|
10644
|
+
if (!matchTextKeyword(parser, "if and only if")) {
|
|
10645
|
+
parser.index = start;
|
|
10646
|
+
return null;
|
|
10647
|
+
}
|
|
10648
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 219 });
|
|
10649
|
+
return ["Equivalent", lhs, rhs ?? "Nothing"];
|
|
10650
|
+
}
|
|
10651
|
+
},
|
|
10652
|
+
// \text{such that} — constraint separator (like : in set-builder notation)
|
|
10653
|
+
{
|
|
10654
|
+
latexTrigger: ["\\text"],
|
|
10655
|
+
kind: "infix",
|
|
10656
|
+
associativity: "right",
|
|
10657
|
+
precedence: 21,
|
|
10658
|
+
// Low precedence to capture full condition (same as 'where')
|
|
10659
|
+
parse: (parser, lhs, until) => {
|
|
10660
|
+
const start = parser.index;
|
|
10661
|
+
if (!matchTextKeyword(parser, "such that")) {
|
|
10662
|
+
parser.index = start;
|
|
10663
|
+
return null;
|
|
10664
|
+
}
|
|
10665
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 21 });
|
|
10666
|
+
return ["Colon", lhs, rhs ?? "Nothing"];
|
|
10667
|
+
}
|
|
10668
|
+
},
|
|
10669
|
+
// \text{for all} — universal quantifier
|
|
10670
|
+
{
|
|
10671
|
+
latexTrigger: ["\\text"],
|
|
10672
|
+
kind: "prefix",
|
|
10673
|
+
precedence: 200,
|
|
10674
|
+
// Same as \forall
|
|
10675
|
+
parse: (parser, until) => {
|
|
10676
|
+
const start = parser.index;
|
|
10677
|
+
if (!matchTextKeyword(parser, "for all")) {
|
|
10678
|
+
parser.index = start;
|
|
10679
|
+
return null;
|
|
10680
|
+
}
|
|
10681
|
+
return parseQuantifier("ForAll")(parser, until);
|
|
10682
|
+
}
|
|
10683
|
+
},
|
|
10684
|
+
// \text{there exists} — existential quantifier
|
|
10685
|
+
{
|
|
10686
|
+
latexTrigger: ["\\text"],
|
|
10687
|
+
kind: "prefix",
|
|
10688
|
+
precedence: 200,
|
|
10689
|
+
// Same as \exists
|
|
10690
|
+
parse: (parser, until) => {
|
|
10691
|
+
const start = parser.index;
|
|
10692
|
+
if (!matchTextKeyword(parser, "there exists")) {
|
|
10693
|
+
parser.index = start;
|
|
10694
|
+
return null;
|
|
10695
|
+
}
|
|
10696
|
+
return parseQuantifier("Exists")(parser, until);
|
|
10697
|
+
}
|
|
10698
|
+
},
|
|
10139
10699
|
// Block serializer — used by both `where` and semicolon blocks
|
|
10140
10700
|
{
|
|
10141
10701
|
name: "Block",
|
|
@@ -10251,6 +10811,39 @@ var DEFINITIONS_CORE = [
|
|
|
10251
10811
|
parser.parseExpression(until) ?? "Nothing"
|
|
10252
10812
|
]
|
|
10253
10813
|
},
|
|
10814
|
+
// Text serializer — reconstructs \text{...} with inline $...$ for math
|
|
10815
|
+
{
|
|
10816
|
+
name: "Text",
|
|
10817
|
+
serialize: (serializer, expr2) => {
|
|
10818
|
+
const args = operands(expr2);
|
|
10819
|
+
if (args.length === 0) return "";
|
|
10820
|
+
let firstStr = -1;
|
|
10821
|
+
let lastStr = -1;
|
|
10822
|
+
for (let i = 0; i < args.length; i++) {
|
|
10823
|
+
if (stringValue(args[i]) !== null) {
|
|
10824
|
+
if (firstStr < 0) firstStr = i;
|
|
10825
|
+
lastStr = i;
|
|
10826
|
+
}
|
|
10827
|
+
}
|
|
10828
|
+
if (firstStr < 0)
|
|
10829
|
+
return joinLatex(args.map((a) => serializer.serialize(a)));
|
|
10830
|
+
const parts = [];
|
|
10831
|
+
for (let i = 0; i < firstStr; i++)
|
|
10832
|
+
parts.push(serializer.serialize(args[i]));
|
|
10833
|
+
let textContent = "";
|
|
10834
|
+
for (let i = firstStr; i <= lastStr; i++) {
|
|
10835
|
+
const s = stringValue(args[i]);
|
|
10836
|
+
if (s !== null) textContent += sanitizeLatex(s);
|
|
10837
|
+
else if (operator(args[i]) === "Annotated" || operator(args[i]) === "Text")
|
|
10838
|
+
textContent += serializer.serialize(args[i]);
|
|
10839
|
+
else textContent += "$" + serializer.serialize(args[i]) + "$";
|
|
10840
|
+
}
|
|
10841
|
+
parts.push("\\text{" + textContent + "}");
|
|
10842
|
+
for (let i = lastStr + 1; i < args.length; i++)
|
|
10843
|
+
parts.push(serializer.serialize(args[i]));
|
|
10844
|
+
return joinLatex(parts);
|
|
10845
|
+
}
|
|
10846
|
+
},
|
|
10254
10847
|
{
|
|
10255
10848
|
name: "String",
|
|
10256
10849
|
latexTrigger: ["\\text"],
|
|
@@ -10641,9 +11234,10 @@ function parseTextRun(parser, style) {
|
|
|
10641
11234
|
} else if (parser.match("\\textcolor")) {
|
|
10642
11235
|
const pos = parser.index;
|
|
10643
11236
|
const color = parser.parseStringGroup();
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
11237
|
+
if (color !== null) {
|
|
11238
|
+
flush();
|
|
11239
|
+
const body2 = parseTextRun(parser);
|
|
11240
|
+
runs.push(["Annotated", body2, dictionaryFromEntries({ color })]);
|
|
10647
11241
|
} else {
|
|
10648
11242
|
parser.index = pos;
|
|
10649
11243
|
text += "\\textcolor";
|
|
@@ -10661,6 +11255,7 @@ function parseTextRun(parser, style) {
|
|
|
10661
11255
|
const expr2 = parser.parseExpression() ?? "Nothing";
|
|
10662
11256
|
parser.skipSpace();
|
|
10663
11257
|
if (parser.match("<$>")) {
|
|
11258
|
+
flush();
|
|
10664
11259
|
runs.push(expr2);
|
|
10665
11260
|
} else {
|
|
10666
11261
|
text += "$";
|
|
@@ -10671,6 +11266,7 @@ function parseTextRun(parser, style) {
|
|
|
10671
11266
|
const expr2 = parser.parseExpression() ?? "Nothing";
|
|
10672
11267
|
parser.skipSpace();
|
|
10673
11268
|
if (parser.match("<$$>")) {
|
|
11269
|
+
flush();
|
|
10674
11270
|
runs.push(expr2);
|
|
10675
11271
|
} else {
|
|
10676
11272
|
text += "$$";
|
|
@@ -11021,14 +11617,20 @@ function matchTextKeyword(parser, keyword) {
|
|
|
11021
11617
|
}
|
|
11022
11618
|
while (parser.match("<space>")) {
|
|
11023
11619
|
}
|
|
11024
|
-
let
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11620
|
+
for (let i = 0; i < keyword.length; i++) {
|
|
11621
|
+
if (keyword[i] === " ") {
|
|
11622
|
+
if (!parser.match("<space>")) {
|
|
11623
|
+
parser.index = start;
|
|
11624
|
+
return false;
|
|
11625
|
+
}
|
|
11626
|
+
while (parser.match("<space>")) {
|
|
11627
|
+
}
|
|
11030
11628
|
} else {
|
|
11031
|
-
|
|
11629
|
+
if (parser.peek !== keyword[i]) {
|
|
11630
|
+
parser.index = start;
|
|
11631
|
+
return false;
|
|
11632
|
+
}
|
|
11633
|
+
parser.nextToken();
|
|
11032
11634
|
}
|
|
11033
11635
|
}
|
|
11034
11636
|
while (parser.match("<space>")) {
|
|
@@ -11037,10 +11639,6 @@ function matchTextKeyword(parser, keyword) {
|
|
|
11037
11639
|
parser.index = start;
|
|
11038
11640
|
return false;
|
|
11039
11641
|
}
|
|
11040
|
-
if (text !== keyword) {
|
|
11041
|
-
parser.index = start;
|
|
11042
|
-
return false;
|
|
11043
|
-
}
|
|
11044
11642
|
return true;
|
|
11045
11643
|
}
|
|
11046
11644
|
function matchKeyword(parser, keyword) {
|
|
@@ -11215,554 +11813,108 @@ var SYMBOLS2 = [
|
|
|
11215
11813
|
//GREEK SMALL LETTER FINAL SIGMA
|
|
11216
11814
|
["tau", "\\tau", 964],
|
|
11217
11815
|
["phi", "\\phi", 981],
|
|
11218
|
-
// Note GREEK PHI SYMBOL, but common usage in math
|
|
11219
|
-
["phiLetter", "\\varphi", 966],
|
|
11220
|
-
["upsilon", "\\upsilon", 965],
|
|
11221
|
-
["chi", "\\chi", 967],
|
|
11222
|
-
["psi", "\\psi", 968],
|
|
11223
|
-
["omega", "\\omega", 969],
|
|
11224
|
-
["Alpha", "\\Alpha", 913],
|
|
11225
|
-
["Beta", "\\Beta", 914],
|
|
11226
|
-
["Gamma", "\\Gamma", 915],
|
|
11227
|
-
["Delta", "\\Delta", 916],
|
|
11228
|
-
["Epsilon", "\\Epsilon", 917],
|
|
11229
|
-
["Zeta", "\\Zeta", 918],
|
|
11230
|
-
["Eta", "\\Eta", 919],
|
|
11231
|
-
["Theta", "\\Theta", 920],
|
|
11232
|
-
["Iota", "\\Iota", 921],
|
|
11233
|
-
["Kappa", "\\Kappa", 922],
|
|
11234
|
-
["Lambda", "\\Lambda", 923],
|
|
11235
|
-
["Mu", "\\Mu", 924],
|
|
11236
|
-
["Nu", "\\Nu", 925],
|
|
11237
|
-
["Xi", "\\Xi", 926],
|
|
11238
|
-
["Omicron", "\\Omicron", 927],
|
|
11239
|
-
// ['Pi', '\\Pi', 0x03a0],
|
|
11240
|
-
["Rho", "\\Rho", 929],
|
|
11241
|
-
["Sigma", "\\Sigma", 931],
|
|
11242
|
-
["Tau", "\\Tau", 932],
|
|
11243
|
-
["Phi", "\\Phi", 934],
|
|
11244
|
-
["Upsilon", "\\Upsilon", 933],
|
|
11245
|
-
["Chi", "\\Chi", 935],
|
|
11246
|
-
["Psi", "\\Psi", 936],
|
|
11247
|
-
["Omega", "\\Omega", 937],
|
|
11248
|
-
["digamma", "\\digamma", 989],
|
|
11249
|
-
// Hebrew
|
|
11250
|
-
["aleph", "\\aleph", 8501],
|
|
11251
|
-
// Unicode ALEF SYMBOL
|
|
11252
|
-
["bet", "\\beth", 8502],
|
|
11253
|
-
["gimel", "\\gimel", 8503],
|
|
11254
|
-
["dalet", "\\daleth", 8504],
|
|
11255
|
-
// Letter-like
|
|
11256
|
-
["ell", "\\ell", 8499],
|
|
11257
|
-
// Unicode SCRIPT SMALL L
|
|
11258
|
-
["turnedCapitalF", "\\Finv", 8498],
|
|
11259
|
-
// Unicode TURNED CAPITAL F'
|
|
11260
|
-
["turnedCapitalG", "\\Game", 8513],
|
|
11261
|
-
// TURNED SANS-SERIF CAPITAL G
|
|
11262
|
-
["weierstrass", "\\wp", 8472],
|
|
11263
|
-
// Unicode SCRIPT CAPITAL P
|
|
11264
|
-
["eth", "\\eth", 240],
|
|
11265
|
-
["invertedOhm", "\\mho", 8487],
|
|
11266
|
-
// Unicode INVERTED OHM SIGN
|
|
11267
|
-
["hBar", "\\hbar", 295],
|
|
11268
|
-
// Unicode LATIN SMALL LETTER H WITH STROKE
|
|
11269
|
-
["hSlash", "\\hslash", 8463],
|
|
11270
|
-
// Unicode PLANCK CONSTANT OVER TWO PI
|
|
11271
|
-
// Symbols
|
|
11272
|
-
["blackClubSuit", "\\clubsuit", 9827],
|
|
11273
|
-
["whiteHeartSuit", "\\heartsuit", 9825],
|
|
11274
|
-
["blackSpadeSuit", "\\spadesuit", 9824],
|
|
11275
|
-
["whiteDiamondSuit", "\\diamondsuit", 9826],
|
|
11276
|
-
["sharp", "\\sharp", 9839],
|
|
11277
|
-
["flat", "\\flat", 9837],
|
|
11278
|
-
["natural", "\\natural", 9838]
|
|
11279
|
-
];
|
|
11280
|
-
var DEFINITIONS_SYMBOLS = [
|
|
11281
|
-
...SYMBOLS2.map(([symbol2, latex, _codepoint]) => {
|
|
11282
|
-
return {
|
|
11283
|
-
kind: "symbol",
|
|
11284
|
-
name: symbol2,
|
|
11285
|
-
latexTrigger: [latex],
|
|
11286
|
-
parse: symbol2
|
|
11287
|
-
};
|
|
11288
|
-
}),
|
|
11289
|
-
...SYMBOLS2.map(([symbol2, _latex, codepoint]) => {
|
|
11290
|
-
return {
|
|
11291
|
-
kind: "symbol",
|
|
11292
|
-
latexTrigger: [String.fromCodePoint(codepoint)],
|
|
11293
|
-
parse: symbol2
|
|
11294
|
-
};
|
|
11295
|
-
})
|
|
11296
|
-
];
|
|
11297
|
-
|
|
11298
|
-
// src/compute-engine/latex-syntax/dictionary/definitions-algebra.ts
|
|
11299
|
-
var DEFINITIONS_ALGEBRA = [
|
|
11300
|
-
{
|
|
11301
|
-
name: "To",
|
|
11302
|
-
latexTrigger: ["\\to"],
|
|
11303
|
-
kind: "infix",
|
|
11304
|
-
precedence: 270
|
|
11305
|
-
// MathML rightwards arrow
|
|
11306
|
-
},
|
|
11307
|
-
{
|
|
11308
|
-
// Non-strict mode: -> for maps-to arrow
|
|
11309
|
-
latexTrigger: ["-", ">"],
|
|
11310
|
-
kind: "infix",
|
|
11311
|
-
precedence: 270,
|
|
11312
|
-
parse: (parser, lhs, until) => {
|
|
11313
|
-
if (parser.options.strict !== false) return null;
|
|
11314
|
-
const rhs = parser.parseExpression({ ...until, minPrec: 270 });
|
|
11315
|
-
if (rhs === null) return null;
|
|
11316
|
-
return ["To", lhs, rhs];
|
|
11317
|
-
}
|
|
11318
|
-
}
|
|
11319
|
-
];
|
|
11320
|
-
|
|
11321
|
-
// src/compute-engine/latex-syntax/dictionary/definitions-logic.ts
|
|
11322
|
-
var DEFINITIONS_LOGIC = [
|
|
11323
|
-
// Constants
|
|
11324
|
-
{
|
|
11325
|
-
name: "True",
|
|
11326
|
-
kind: "symbol",
|
|
11327
|
-
latexTrigger: ["\\top"]
|
|
11328
|
-
// ⊤ U+22A4
|
|
11329
|
-
},
|
|
11330
|
-
{
|
|
11331
|
-
kind: "symbol",
|
|
11332
|
-
latexTrigger: "\\mathrm{True}",
|
|
11333
|
-
parse: "True"
|
|
11334
|
-
},
|
|
11335
|
-
{
|
|
11336
|
-
kind: "symbol",
|
|
11337
|
-
latexTrigger: "\\operatorname{True}",
|
|
11338
|
-
parse: "True"
|
|
11339
|
-
},
|
|
11340
|
-
{
|
|
11341
|
-
kind: "symbol",
|
|
11342
|
-
latexTrigger: "\\mathsf{T}",
|
|
11343
|
-
parse: "True"
|
|
11344
|
-
},
|
|
11345
|
-
{
|
|
11346
|
-
name: "False",
|
|
11347
|
-
kind: "symbol",
|
|
11348
|
-
latexTrigger: ["\\bot"]
|
|
11349
|
-
// ⊥ U+22A5
|
|
11350
|
-
},
|
|
11351
|
-
{
|
|
11352
|
-
kind: "symbol",
|
|
11353
|
-
latexTrigger: "\\operatorname{False}",
|
|
11354
|
-
parse: "False"
|
|
11355
|
-
},
|
|
11356
|
-
{
|
|
11357
|
-
kind: "symbol",
|
|
11358
|
-
latexTrigger: "\\mathsf{F}",
|
|
11359
|
-
parse: "False"
|
|
11360
|
-
},
|
|
11361
|
-
// Operators
|
|
11362
|
-
// Logic operators have lower precedence than comparisons (245)
|
|
11363
|
-
// so that `x = 1 \lor x = 2` parses as `(x = 1) \lor (x = 2)`
|
|
11364
|
-
// See https://github.com/cortex-js/compute-engine/issues/243
|
|
11365
|
-
{
|
|
11366
|
-
name: "And",
|
|
11367
|
-
kind: "infix",
|
|
11368
|
-
latexTrigger: ["\\land"],
|
|
11369
|
-
precedence: 235
|
|
11370
|
-
// serialize: '\\land',
|
|
11371
|
-
},
|
|
11372
|
-
{ kind: "infix", latexTrigger: ["\\wedge"], parse: "And", precedence: 235 },
|
|
11373
|
-
{ kind: "infix", latexTrigger: "\\&", parse: "And", precedence: 235 },
|
|
11374
|
-
{
|
|
11375
|
-
kind: "infix",
|
|
11376
|
-
latexTrigger: "\\operatorname{and}",
|
|
11377
|
-
parse: "And",
|
|
11378
|
-
precedence: 235
|
|
11379
|
-
},
|
|
11380
|
-
{
|
|
11381
|
-
name: "Or",
|
|
11382
|
-
kind: "infix",
|
|
11383
|
-
latexTrigger: ["\\lor"],
|
|
11384
|
-
precedence: 230
|
|
11385
|
-
},
|
|
11386
|
-
{ kind: "infix", latexTrigger: ["\\vee"], parse: "Or", precedence: 230 },
|
|
11387
|
-
{ kind: "infix", latexTrigger: "\\parallel", parse: "Or", precedence: 230 },
|
|
11388
|
-
{
|
|
11389
|
-
kind: "infix",
|
|
11390
|
-
latexTrigger: "\\operatorname{or}",
|
|
11391
|
-
parse: "Or",
|
|
11392
|
-
precedence: 230
|
|
11393
|
-
},
|
|
11394
|
-
{
|
|
11395
|
-
name: "Xor",
|
|
11396
|
-
kind: "infix",
|
|
11397
|
-
latexTrigger: ["\\veebar"],
|
|
11398
|
-
precedence: 232
|
|
11399
|
-
},
|
|
11400
|
-
// Possible alt: \oplus ⊕ U+2295
|
|
11401
|
-
{
|
|
11402
|
-
name: "Not",
|
|
11403
|
-
kind: "prefix",
|
|
11404
|
-
latexTrigger: ["\\lnot"],
|
|
11405
|
-
precedence: 880
|
|
11406
|
-
},
|
|
11407
|
-
{
|
|
11408
|
-
kind: "prefix",
|
|
11409
|
-
latexTrigger: ["\\neg"],
|
|
11410
|
-
parse: "Not",
|
|
11411
|
-
precedence: 880
|
|
11412
|
-
},
|
|
11413
|
-
{
|
|
11414
|
-
name: "Nand",
|
|
11415
|
-
kind: "infix",
|
|
11416
|
-
latexTrigger: ["\\barwedge"],
|
|
11417
|
-
precedence: 232
|
|
11418
|
-
// serialize: '\\mid',
|
|
11419
|
-
},
|
|
11420
|
-
{
|
|
11421
|
-
name: "Nor",
|
|
11422
|
-
kind: "infix",
|
|
11423
|
-
latexTrigger: ["\u22BD"],
|
|
11424
|
-
// bar vee
|
|
11425
|
-
precedence: 232
|
|
11426
|
-
// serialize: '\\downarrow',
|
|
11427
|
-
},
|
|
11428
|
-
// Functions
|
|
11429
|
-
{
|
|
11430
|
-
kind: "function",
|
|
11431
|
-
symbolTrigger: "and",
|
|
11432
|
-
parse: "And"
|
|
11433
|
-
},
|
|
11434
|
-
{
|
|
11435
|
-
kind: "function",
|
|
11436
|
-
symbolTrigger: "or",
|
|
11437
|
-
parse: "Or"
|
|
11438
|
-
},
|
|
11439
|
-
{
|
|
11440
|
-
kind: "function",
|
|
11441
|
-
symbolTrigger: "not",
|
|
11442
|
-
parse: "Not"
|
|
11443
|
-
},
|
|
11444
|
-
// Relations
|
|
11445
|
-
{
|
|
11446
|
-
name: "Implies",
|
|
11447
|
-
kind: "infix",
|
|
11448
|
-
precedence: 220,
|
|
11449
|
-
associativity: "right",
|
|
11450
|
-
latexTrigger: ["\\implies"],
|
|
11451
|
-
serialize: "\\implies"
|
|
11452
|
-
},
|
|
11453
|
-
{
|
|
11454
|
-
latexTrigger: ["\\Rightarrow"],
|
|
11455
|
-
kind: "infix",
|
|
11456
|
-
precedence: 220,
|
|
11457
|
-
associativity: "right",
|
|
11458
|
-
parse: "Implies"
|
|
11459
|
-
},
|
|
11460
|
-
{
|
|
11461
|
-
latexTrigger: ["\\rightarrow"],
|
|
11462
|
-
kind: "infix",
|
|
11463
|
-
precedence: 220,
|
|
11464
|
-
associativity: "right",
|
|
11465
|
-
parse: "Implies"
|
|
11466
|
-
},
|
|
11467
|
-
{
|
|
11468
|
-
latexTrigger: ["\\Longrightarrow"],
|
|
11469
|
-
kind: "infix",
|
|
11470
|
-
precedence: 220,
|
|
11471
|
-
associativity: "right",
|
|
11472
|
-
parse: "Implies"
|
|
11473
|
-
},
|
|
11474
|
-
{
|
|
11475
|
-
latexTrigger: ["\\longrightarrow"],
|
|
11476
|
-
kind: "infix",
|
|
11477
|
-
precedence: 220,
|
|
11478
|
-
associativity: "right",
|
|
11479
|
-
parse: "Implies"
|
|
11480
|
-
},
|
|
11481
|
-
{
|
|
11482
|
-
// Non-strict mode: => for implies
|
|
11483
|
-
latexTrigger: ["=", ">"],
|
|
11484
|
-
kind: "infix",
|
|
11485
|
-
precedence: 220,
|
|
11486
|
-
associativity: "right",
|
|
11487
|
-
parse: (parser, lhs, until) => {
|
|
11488
|
-
if (parser.options.strict !== false) return null;
|
|
11489
|
-
const rhs = parser.parseExpression({ ...until, minPrec: 220 });
|
|
11490
|
-
if (rhs === null) return null;
|
|
11491
|
-
return ["Implies", lhs, rhs];
|
|
11492
|
-
}
|
|
11493
|
-
},
|
|
11494
|
-
{
|
|
11495
|
-
name: "Equivalent",
|
|
11496
|
-
// MathML: identical to, Mathematica: Congruent
|
|
11497
|
-
latexTrigger: ["\\iff"],
|
|
11498
|
-
kind: "infix",
|
|
11499
|
-
associativity: "right",
|
|
11500
|
-
precedence: 219
|
|
11501
|
-
},
|
|
11502
|
-
{
|
|
11503
|
-
latexTrigger: ["\\Leftrightarrow"],
|
|
11504
|
-
kind: "infix",
|
|
11505
|
-
associativity: "right",
|
|
11506
|
-
precedence: 219,
|
|
11507
|
-
parse: "Equivalent"
|
|
11508
|
-
},
|
|
11509
|
-
{
|
|
11510
|
-
latexTrigger: ["\\leftrightarrow"],
|
|
11511
|
-
kind: "infix",
|
|
11512
|
-
associativity: "right",
|
|
11513
|
-
precedence: 219,
|
|
11514
|
-
parse: "Equivalent"
|
|
11515
|
-
},
|
|
11516
|
-
{
|
|
11517
|
-
latexTrigger: ["\\Longleftrightarrow"],
|
|
11518
|
-
kind: "infix",
|
|
11519
|
-
associativity: "right",
|
|
11520
|
-
precedence: 219,
|
|
11521
|
-
parse: "Equivalent"
|
|
11522
|
-
},
|
|
11816
|
+
// Note GREEK PHI SYMBOL, but common usage in math
|
|
11817
|
+
["phiLetter", "\\varphi", 966],
|
|
11818
|
+
["upsilon", "\\upsilon", 965],
|
|
11819
|
+
["chi", "\\chi", 967],
|
|
11820
|
+
["psi", "\\psi", 968],
|
|
11821
|
+
["omega", "\\omega", 969],
|
|
11822
|
+
["Alpha", "\\Alpha", 913],
|
|
11823
|
+
["Beta", "\\Beta", 914],
|
|
11824
|
+
["Gamma", "\\Gamma", 915],
|
|
11825
|
+
["Delta", "\\Delta", 916],
|
|
11826
|
+
["Epsilon", "\\Epsilon", 917],
|
|
11827
|
+
["Zeta", "\\Zeta", 918],
|
|
11828
|
+
["Eta", "\\Eta", 919],
|
|
11829
|
+
["Theta", "\\Theta", 920],
|
|
11830
|
+
["Iota", "\\Iota", 921],
|
|
11831
|
+
["Kappa", "\\Kappa", 922],
|
|
11832
|
+
["Lambda", "\\Lambda", 923],
|
|
11833
|
+
["Mu", "\\Mu", 924],
|
|
11834
|
+
["Nu", "\\Nu", 925],
|
|
11835
|
+
["Xi", "\\Xi", 926],
|
|
11836
|
+
["Omicron", "\\Omicron", 927],
|
|
11837
|
+
// ['Pi', '\\Pi', 0x03a0],
|
|
11838
|
+
["Rho", "\\Rho", 929],
|
|
11839
|
+
["Sigma", "\\Sigma", 931],
|
|
11840
|
+
["Tau", "\\Tau", 932],
|
|
11841
|
+
["Phi", "\\Phi", 934],
|
|
11842
|
+
["Upsilon", "\\Upsilon", 933],
|
|
11843
|
+
["Chi", "\\Chi", 935],
|
|
11844
|
+
["Psi", "\\Psi", 936],
|
|
11845
|
+
["Omega", "\\Omega", 937],
|
|
11846
|
+
["digamma", "\\digamma", 989],
|
|
11847
|
+
// Hebrew
|
|
11848
|
+
["aleph", "\\aleph", 8501],
|
|
11849
|
+
// Unicode ALEF SYMBOL
|
|
11850
|
+
["bet", "\\beth", 8502],
|
|
11851
|
+
["gimel", "\\gimel", 8503],
|
|
11852
|
+
["dalet", "\\daleth", 8504],
|
|
11853
|
+
// Letter-like
|
|
11854
|
+
["ell", "\\ell", 8499],
|
|
11855
|
+
// Unicode SCRIPT SMALL L
|
|
11856
|
+
["turnedCapitalF", "\\Finv", 8498],
|
|
11857
|
+
// Unicode TURNED CAPITAL F'
|
|
11858
|
+
["turnedCapitalG", "\\Game", 8513],
|
|
11859
|
+
// TURNED SANS-SERIF CAPITAL G
|
|
11860
|
+
["weierstrass", "\\wp", 8472],
|
|
11861
|
+
// Unicode SCRIPT CAPITAL P
|
|
11862
|
+
["eth", "\\eth", 240],
|
|
11863
|
+
["invertedOhm", "\\mho", 8487],
|
|
11864
|
+
// Unicode INVERTED OHM SIGN
|
|
11865
|
+
["hBar", "\\hbar", 295],
|
|
11866
|
+
// Unicode LATIN SMALL LETTER H WITH STROKE
|
|
11867
|
+
["hSlash", "\\hslash", 8463],
|
|
11868
|
+
// Unicode PLANCK CONSTANT OVER TWO PI
|
|
11869
|
+
// Symbols
|
|
11870
|
+
["blackClubSuit", "\\clubsuit", 9827],
|
|
11871
|
+
["whiteHeartSuit", "\\heartsuit", 9825],
|
|
11872
|
+
["blackSpadeSuit", "\\spadesuit", 9824],
|
|
11873
|
+
["whiteDiamondSuit", "\\diamondsuit", 9826],
|
|
11874
|
+
["sharp", "\\sharp", 9839],
|
|
11875
|
+
["flat", "\\flat", 9837],
|
|
11876
|
+
["natural", "\\natural", 9838]
|
|
11877
|
+
];
|
|
11878
|
+
var DEFINITIONS_SYMBOLS = [
|
|
11879
|
+
...SYMBOLS2.map(([symbol2, latex, _codepoint]) => {
|
|
11880
|
+
return {
|
|
11881
|
+
kind: "symbol",
|
|
11882
|
+
name: symbol2,
|
|
11883
|
+
latexTrigger: [latex],
|
|
11884
|
+
parse: symbol2
|
|
11885
|
+
};
|
|
11886
|
+
}),
|
|
11887
|
+
...SYMBOLS2.map(([symbol2, _latex, codepoint]) => {
|
|
11888
|
+
return {
|
|
11889
|
+
kind: "symbol",
|
|
11890
|
+
latexTrigger: [String.fromCodePoint(codepoint)],
|
|
11891
|
+
parse: symbol2
|
|
11892
|
+
};
|
|
11893
|
+
})
|
|
11894
|
+
];
|
|
11895
|
+
|
|
11896
|
+
// src/compute-engine/latex-syntax/dictionary/definitions-algebra.ts
|
|
11897
|
+
var DEFINITIONS_ALGEBRA = [
|
|
11523
11898
|
{
|
|
11524
|
-
|
|
11899
|
+
name: "To",
|
|
11900
|
+
latexTrigger: ["\\to"],
|
|
11525
11901
|
kind: "infix",
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
parse: "Equivalent"
|
|
11902
|
+
precedence: 270
|
|
11903
|
+
// MathML rightwards arrow
|
|
11529
11904
|
},
|
|
11530
11905
|
{
|
|
11531
|
-
// Non-strict mode:
|
|
11532
|
-
latexTrigger: ["
|
|
11906
|
+
// Non-strict mode: -> for maps-to arrow
|
|
11907
|
+
latexTrigger: ["-", ">"],
|
|
11533
11908
|
kind: "infix",
|
|
11534
|
-
precedence:
|
|
11535
|
-
associativity: "right",
|
|
11909
|
+
precedence: 270,
|
|
11536
11910
|
parse: (parser, lhs, until) => {
|
|
11537
11911
|
if (parser.options.strict !== false) return null;
|
|
11538
|
-
const rhs = parser.parseExpression({ ...until, minPrec:
|
|
11912
|
+
const rhs = parser.parseExpression({ ...until, minPrec: 270 });
|
|
11539
11913
|
if (rhs === null) return null;
|
|
11540
|
-
return ["
|
|
11541
|
-
}
|
|
11542
|
-
},
|
|
11543
|
-
{
|
|
11544
|
-
latexTrigger: ["\\equiv"],
|
|
11545
|
-
kind: "infix",
|
|
11546
|
-
associativity: "right",
|
|
11547
|
-
precedence: 219,
|
|
11548
|
-
parse: (parser, lhs, terminator) => {
|
|
11549
|
-
const rhs = parser.parseExpression({ ...terminator, minPrec: 219 });
|
|
11550
|
-
const index = parser.index;
|
|
11551
|
-
const modulus = parser.parseExpression({ ...terminator, minPrec: 219 });
|
|
11552
|
-
if (modulus !== null && operator(modulus) === "Mod")
|
|
11553
|
-
return ["Congruent", lhs, rhs, missingIfEmpty(operand(modulus, 1))];
|
|
11554
|
-
parser.index = index;
|
|
11555
|
-
return ["Equivalent", lhs, missingIfEmpty(rhs)];
|
|
11556
|
-
}
|
|
11557
|
-
},
|
|
11558
|
-
{
|
|
11559
|
-
name: "Proves",
|
|
11560
|
-
kind: "infix",
|
|
11561
|
-
latexTrigger: ["\\vdash"],
|
|
11562
|
-
precedence: 220,
|
|
11563
|
-
associativity: "right",
|
|
11564
|
-
serialize: "\\vdash"
|
|
11565
|
-
},
|
|
11566
|
-
{
|
|
11567
|
-
name: "Entails",
|
|
11568
|
-
kind: "infix",
|
|
11569
|
-
latexTrigger: ["\\vDash"],
|
|
11570
|
-
precedence: 220,
|
|
11571
|
-
associativity: "right",
|
|
11572
|
-
serialize: "\\vDash"
|
|
11573
|
-
},
|
|
11574
|
-
{
|
|
11575
|
-
name: "Satisfies",
|
|
11576
|
-
kind: "infix",
|
|
11577
|
-
latexTrigger: ["\\models"],
|
|
11578
|
-
precedence: 220,
|
|
11579
|
-
associativity: "right",
|
|
11580
|
-
serialize: "\\models"
|
|
11581
|
-
},
|
|
11582
|
-
// Quantifiers: for all, exists
|
|
11583
|
-
{
|
|
11584
|
-
name: "ForAll",
|
|
11585
|
-
kind: "prefix",
|
|
11586
|
-
latexTrigger: ["\\forall"],
|
|
11587
|
-
precedence: 200,
|
|
11588
|
-
// Has to be lower than COMPARISON_PRECEDENCE
|
|
11589
|
-
serialize: serializeQuantifier("\\forall"),
|
|
11590
|
-
parse: parseQuantifier("ForAll")
|
|
11591
|
-
},
|
|
11592
|
-
{
|
|
11593
|
-
name: "Exists",
|
|
11594
|
-
kind: "prefix",
|
|
11595
|
-
latexTrigger: ["\\exists"],
|
|
11596
|
-
precedence: 200,
|
|
11597
|
-
// Has to be lower than COMPARISON_PRECEDENCE,
|
|
11598
|
-
serialize: serializeQuantifier("\\exists"),
|
|
11599
|
-
parse: parseQuantifier("Exists")
|
|
11600
|
-
},
|
|
11601
|
-
{
|
|
11602
|
-
name: "ExistsUnique",
|
|
11603
|
-
kind: "prefix",
|
|
11604
|
-
latexTrigger: ["\\exists", "!"],
|
|
11605
|
-
precedence: 200,
|
|
11606
|
-
// Has to be lower than COMPARISON_PRECEDENCE,
|
|
11607
|
-
serialize: serializeQuantifier("\\exists!"),
|
|
11608
|
-
parse: parseQuantifier("ExistsUnique")
|
|
11609
|
-
},
|
|
11610
|
-
{
|
|
11611
|
-
name: "NotForAll",
|
|
11612
|
-
kind: "prefix",
|
|
11613
|
-
latexTrigger: ["\\lnot", "\\forall"],
|
|
11614
|
-
precedence: 200,
|
|
11615
|
-
// Has to be lower than COMPARISON_PRECEDENCE
|
|
11616
|
-
serialize: serializeQuantifier("\\lnot\\forall"),
|
|
11617
|
-
parse: parseQuantifier("NotForAll")
|
|
11618
|
-
},
|
|
11619
|
-
{
|
|
11620
|
-
name: "NotExists",
|
|
11621
|
-
kind: "prefix",
|
|
11622
|
-
latexTrigger: ["\\lnot", "\\exists"],
|
|
11623
|
-
precedence: 200,
|
|
11624
|
-
// Has to be lower than COMPARISON_PRECEDENCE,
|
|
11625
|
-
serialize: serializeQuantifier("\\lnot\\exists"),
|
|
11626
|
-
parse: parseQuantifier("NotExists")
|
|
11627
|
-
},
|
|
11628
|
-
{
|
|
11629
|
-
name: "KroneckerDelta",
|
|
11630
|
-
kind: "prefix",
|
|
11631
|
-
latexTrigger: ["\\delta", "_"],
|
|
11632
|
-
precedence: 200,
|
|
11633
|
-
serialize: (serializer, expr2) => {
|
|
11634
|
-
const args = operands(expr2);
|
|
11635
|
-
if (args.length === 0) return "\\delta";
|
|
11636
|
-
if (args.every((x) => symbol(x)))
|
|
11637
|
-
return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join("")}}`;
|
|
11638
|
-
return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join(", ")}}`;
|
|
11639
|
-
},
|
|
11640
|
-
parse: (parser) => {
|
|
11641
|
-
const group = parser.parseGroup();
|
|
11642
|
-
if (group === null) {
|
|
11643
|
-
const token = parser.parseToken();
|
|
11644
|
-
if (!token) return null;
|
|
11645
|
-
return ["KroneckerDelta", token];
|
|
11646
|
-
}
|
|
11647
|
-
const seq = getSequence(group);
|
|
11648
|
-
if (seq && seq.length <= 2) return ["KroneckerDelta", ...seq];
|
|
11649
|
-
if (operator(group) === "InvisibleOperator")
|
|
11650
|
-
return ["KroneckerDelta", ...operands(group)];
|
|
11651
|
-
if (group !== null) return ["KroneckerDelta", group];
|
|
11652
|
-
return null;
|
|
11653
|
-
}
|
|
11654
|
-
},
|
|
11655
|
-
// Iverson brackets. Also called the "indicator function"
|
|
11656
|
-
// Must have a single argument, a relational expression, i.e.
|
|
11657
|
-
// `[ a = b ]` or `[ x \leq 0 ]`
|
|
11658
|
-
// Otherwise, it gets rejected, it could be something else, like a list or
|
|
11659
|
-
// tuple.
|
|
11660
|
-
{
|
|
11661
|
-
name: "Boole",
|
|
11662
|
-
kind: "matchfix",
|
|
11663
|
-
openTrigger: "[",
|
|
11664
|
-
closeTrigger: "]",
|
|
11665
|
-
// serialize: (serializer: Serializer, expr: MathJsonExpression) => {
|
|
11666
|
-
// const args = ops(expr);
|
|
11667
|
-
// return `[${serializer.serialize(arg)}]`;
|
|
11668
|
-
// },
|
|
11669
|
-
parse: (_parser, body) => {
|
|
11670
|
-
const h = operator(body);
|
|
11671
|
-
if (!h) return null;
|
|
11672
|
-
if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
|
|
11673
|
-
return ["Boole", body];
|
|
11674
|
-
}
|
|
11675
|
-
},
|
|
11676
|
-
{
|
|
11677
|
-
kind: "matchfix",
|
|
11678
|
-
openTrigger: "\\llbracket",
|
|
11679
|
-
closeTrigger: "\\rrbracket",
|
|
11680
|
-
parse: (_parser, body) => {
|
|
11681
|
-
const h = operator(body);
|
|
11682
|
-
if (!h) return null;
|
|
11683
|
-
if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
|
|
11684
|
-
return ["Boole", body];
|
|
11685
|
-
}
|
|
11686
|
-
},
|
|
11687
|
-
// Predicate application in First-Order Logic.
|
|
11688
|
-
// ["Predicate", "P", "x", "y"] serializes to "P(x, y)"
|
|
11689
|
-
{
|
|
11690
|
-
name: "Predicate",
|
|
11691
|
-
serialize: (serializer, expr2) => {
|
|
11692
|
-
const args = operands(expr2);
|
|
11693
|
-
if (args.length === 0) return "";
|
|
11694
|
-
const pred = args[0];
|
|
11695
|
-
const predStr = typeof pred === "string" ? pred : serializer.serialize(pred);
|
|
11696
|
-
if (args.length === 1) return predStr;
|
|
11697
|
-
const argStrs = args.slice(1).map((arg) => serializer.serialize(arg));
|
|
11698
|
-
return `${predStr}(${argStrs.join(", ")})`;
|
|
11914
|
+
return ["To", lhs, rhs];
|
|
11699
11915
|
}
|
|
11700
11916
|
}
|
|
11701
11917
|
];
|
|
11702
|
-
function serializeQuantifier(quantifierSymbol) {
|
|
11703
|
-
return (serializer, expr2) => {
|
|
11704
|
-
const args = operands(expr2);
|
|
11705
|
-
if (args.length === 0) return quantifierSymbol;
|
|
11706
|
-
if (args.length === 1)
|
|
11707
|
-
return `${quantifierSymbol} ${serializer.serialize(args[0])}`;
|
|
11708
|
-
const boundVar = serializer.serialize(args[0]);
|
|
11709
|
-
const body = serializer.serialize(args[1]);
|
|
11710
|
-
return `${quantifierSymbol} ${boundVar}, ${body}`;
|
|
11711
|
-
};
|
|
11712
|
-
}
|
|
11713
|
-
function tightBindingCondition(p, terminator) {
|
|
11714
|
-
return p.peek === "\\to" || p.peek === "\\rightarrow" || p.peek === "\\implies" || p.peek === "\\Rightarrow" || p.peek === "\\iff" || p.peek === "\\Leftrightarrow" || p.peek === "\\land" || p.peek === "\\wedge" || p.peek === "\\lor" || p.peek === "\\vee" || (terminator.condition?.(p) ?? false);
|
|
11715
|
-
}
|
|
11716
|
-
function parseQuantifier(kind) {
|
|
11717
|
-
return (parser, terminator) => {
|
|
11718
|
-
const index = parser.index;
|
|
11719
|
-
const useTightBinding = parser.options.quantifierScope !== "loose";
|
|
11720
|
-
const symbol2 = parser.parseSymbol(terminator);
|
|
11721
|
-
if (symbol2) {
|
|
11722
|
-
parser.skipSpace();
|
|
11723
|
-
if (parser.match(",") || parser.match("\\mid") || parser.match(".") || parser.match(":") || parser.match("\\colon")) {
|
|
11724
|
-
const bodyTerminator = useTightBinding ? {
|
|
11725
|
-
...terminator,
|
|
11726
|
-
condition: (p) => tightBindingCondition(p, terminator)
|
|
11727
|
-
} : terminator;
|
|
11728
|
-
parser.enterQuantifierScope();
|
|
11729
|
-
const body2 = parser.parseExpression(bodyTerminator);
|
|
11730
|
-
parser.exitQuantifierScope();
|
|
11731
|
-
return [kind, symbol2, missingIfEmpty(body2)];
|
|
11732
|
-
}
|
|
11733
|
-
parser.enterQuantifierScope();
|
|
11734
|
-
const body = parser.parseEnclosure();
|
|
11735
|
-
parser.exitQuantifierScope();
|
|
11736
|
-
if (body) return [kind, symbol2, missingIfEmpty(body)];
|
|
11737
|
-
}
|
|
11738
|
-
parser.index = index;
|
|
11739
|
-
const condTerminator = {
|
|
11740
|
-
...terminator,
|
|
11741
|
-
condition: (p) => p.peek === ":" || p.peek === "\\colon" || (terminator.condition?.(p) ?? false)
|
|
11742
|
-
};
|
|
11743
|
-
const condition = parser.parseExpression(condTerminator);
|
|
11744
|
-
if (condition === null) return null;
|
|
11745
|
-
parser.skipSpace();
|
|
11746
|
-
if (parser.matchAny([",", "\\mid", ":", "\\colon"])) {
|
|
11747
|
-
const bodyTerminator = useTightBinding ? {
|
|
11748
|
-
...terminator,
|
|
11749
|
-
condition: (p) => tightBindingCondition(p, terminator)
|
|
11750
|
-
} : terminator;
|
|
11751
|
-
parser.enterQuantifierScope();
|
|
11752
|
-
const body = parser.parseExpression(bodyTerminator);
|
|
11753
|
-
parser.exitQuantifierScope();
|
|
11754
|
-
return [kind, condition, missingIfEmpty(body)];
|
|
11755
|
-
}
|
|
11756
|
-
if (parser.match("(")) {
|
|
11757
|
-
parser.enterQuantifierScope();
|
|
11758
|
-
const body = parser.parseExpression(terminator);
|
|
11759
|
-
parser.exitQuantifierScope();
|
|
11760
|
-
if (!parser.match(")")) return null;
|
|
11761
|
-
return [kind, condition, missingIfEmpty(body)];
|
|
11762
|
-
}
|
|
11763
|
-
return null;
|
|
11764
|
-
};
|
|
11765
|
-
}
|
|
11766
11918
|
|
|
11767
11919
|
// src/compute-engine/latex-syntax/dictionary/definitions-sets.ts
|
|
11768
11920
|
function parseIntervalBody(body, openLeft, openRight) {
|
|
@@ -16268,7 +16420,7 @@ var ZWJ2 = "\\u{200D}";
|
|
|
16268
16420
|
var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
|
|
16269
16421
|
var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
|
|
16270
16422
|
var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
|
|
16271
|
-
var EMOJI_NOT_SYMBOL = `(?:(?=\\P{XIDC})\\p{Emoji})`;
|
|
16423
|
+
var EMOJI_NOT_SYMBOL = `(?:(?=\\P{XIDC})(?=[^\\x23\\x2a\\x30-\\x39])\\p{Emoji})`;
|
|
16272
16424
|
var ZWJ_ELEMENT = `(?:${EMOJI_NOT_SYMBOL}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
|
|
16273
16425
|
var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ2}${ZWJ_ELEMENT})*`;
|
|
16274
16426
|
var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
|
|
@@ -16977,7 +17129,9 @@ function parseSymbolToken(parser, options) {
|
|
|
16977
17129
|
}
|
|
16978
17130
|
return c;
|
|
16979
17131
|
}
|
|
16980
|
-
|
|
17132
|
+
const raw = parser.peek;
|
|
17133
|
+
if (raw && /^[\p{XIDC}\p{M}]/u.test(raw)) return parser.nextToken();
|
|
17134
|
+
return null;
|
|
16981
17135
|
}
|
|
16982
17136
|
function parseSymbolBody(parser) {
|
|
16983
17137
|
let id = matchPrefixedSymbol(parser);
|
|
@@ -18267,6 +18421,29 @@ var _Parser = class __Parser {
|
|
|
18267
18421
|
this.index = start;
|
|
18268
18422
|
return null;
|
|
18269
18423
|
}
|
|
18424
|
+
/**
|
|
18425
|
+
* Speculatively check if any \text infix entry (e.g. "and", "or", "where")
|
|
18426
|
+
* would match the upcoming tokens. This is used to prevent InvisibleOperator
|
|
18427
|
+
* from consuming \text{keyword} as a text run when the keyword is actually
|
|
18428
|
+
* an infix operator that was skipped due to precedence constraints.
|
|
18429
|
+
*
|
|
18430
|
+
* Returns true if any entry's parse function would succeed (non-null result).
|
|
18431
|
+
* The parser index is always restored to its original position.
|
|
18432
|
+
*/
|
|
18433
|
+
wouldMatchTextInfix(opDefs) {
|
|
18434
|
+
const start = this.index;
|
|
18435
|
+
for (const [def, n] of opDefs) {
|
|
18436
|
+
if (def.kind !== "infix") continue;
|
|
18437
|
+
this.index = start + n;
|
|
18438
|
+
const result = def.parse(this, "Nothing", { minPrec: 0 });
|
|
18439
|
+
if (result !== null) {
|
|
18440
|
+
this.index = start;
|
|
18441
|
+
return true;
|
|
18442
|
+
}
|
|
18443
|
+
}
|
|
18444
|
+
this.index = start;
|
|
18445
|
+
return false;
|
|
18446
|
+
}
|
|
18270
18447
|
/**
|
|
18271
18448
|
* This returns an array of arguments (as in a function application),
|
|
18272
18449
|
* or null if there is no match.
|
|
@@ -18892,6 +19069,7 @@ var _Parser = class __Parser {
|
|
|
18892
19069
|
if (isDelimiterCommand(this))
|
|
18893
19070
|
return this.error("unexpected-delimiter", start);
|
|
18894
19071
|
if (command[0] !== "\\") {
|
|
19072
|
+
this.nextToken();
|
|
18895
19073
|
return this.error(
|
|
18896
19074
|
["unexpected-token", { str: tokensToString(command) }],
|
|
18897
19075
|
start
|
|
@@ -19020,25 +19198,28 @@ var _Parser = class __Parser {
|
|
|
19020
19198
|
if (result === null && until.minPrec <= INVISIBLE_OP_PRECEDENCE) {
|
|
19021
19199
|
const opDefs = this.peekDefinitions("operator");
|
|
19022
19200
|
if (opDefs.length === 0 || opDefs.every(([def]) => def.latexTrigger === "\\text")) {
|
|
19023
|
-
|
|
19024
|
-
...until,
|
|
19025
|
-
minPrec: INVISIBLE_OP_PRECEDENCE + 1
|
|
19026
|
-
});
|
|
19027
|
-
if (rhs !== null) {
|
|
19028
|
-
if (operator(lhs) === "InvisibleOperator") {
|
|
19029
|
-
if (operator(rhs) === "InvisibleOperator")
|
|
19030
|
-
result = [
|
|
19031
|
-
"InvisibleOperator",
|
|
19032
|
-
...operands(lhs),
|
|
19033
|
-
...operands(rhs)
|
|
19034
|
-
];
|
|
19035
|
-
else result = ["InvisibleOperator", ...operands(lhs), rhs];
|
|
19036
|
-
} else if (operator(rhs) === "InvisibleOperator") {
|
|
19037
|
-
result = ["InvisibleOperator", lhs, ...operands(rhs)];
|
|
19038
|
-
} else result = ["InvisibleOperator", lhs, rhs];
|
|
19201
|
+
if (opDefs.length > 0 && this.wouldMatchTextInfix(opDefs)) {
|
|
19039
19202
|
} else {
|
|
19040
|
-
|
|
19041
|
-
|
|
19203
|
+
const rhs = this.parseExpression({
|
|
19204
|
+
...until,
|
|
19205
|
+
minPrec: INVISIBLE_OP_PRECEDENCE + 1
|
|
19206
|
+
});
|
|
19207
|
+
if (rhs !== null) {
|
|
19208
|
+
if (operator(lhs) === "InvisibleOperator") {
|
|
19209
|
+
if (operator(rhs) === "InvisibleOperator")
|
|
19210
|
+
result = [
|
|
19211
|
+
"InvisibleOperator",
|
|
19212
|
+
...operands(lhs),
|
|
19213
|
+
...operands(rhs)
|
|
19214
|
+
];
|
|
19215
|
+
else result = ["InvisibleOperator", ...operands(lhs), rhs];
|
|
19216
|
+
} else if (operator(rhs) === "InvisibleOperator") {
|
|
19217
|
+
result = ["InvisibleOperator", lhs, ...operands(rhs)];
|
|
19218
|
+
} else result = ["InvisibleOperator", lhs, rhs];
|
|
19219
|
+
} else {
|
|
19220
|
+
if (result === null) {
|
|
19221
|
+
result = this.options.parseUnexpectedToken?.(lhs, this) ?? null;
|
|
19222
|
+
}
|
|
19042
19223
|
}
|
|
19043
19224
|
}
|
|
19044
19225
|
}
|
|
@@ -30503,8 +30684,7 @@ var ARITHMETIC_LIBRARY = [
|
|
|
30503
30684
|
broadcastable: true,
|
|
30504
30685
|
idempotent: true,
|
|
30505
30686
|
complexity: 1200,
|
|
30506
|
-
signature: "(number) ->
|
|
30507
|
-
type: ([x]) => x.type,
|
|
30687
|
+
signature: "(number) -> real",
|
|
30508
30688
|
sgn: ([x]) => {
|
|
30509
30689
|
if (x.isSame(0)) return "zero";
|
|
30510
30690
|
if (isNumber(x)) return "positive";
|
|
@@ -37863,6 +38043,10 @@ var CALCULUS_LIBRARY = [
|
|
|
37863
38043
|
scoped: true,
|
|
37864
38044
|
lazy: true,
|
|
37865
38045
|
signature: "(expression, variable:symbol, variables:symbol+) -> expression",
|
|
38046
|
+
type: ([body]) => {
|
|
38047
|
+
if (body && body.type.matches("number")) return body.type;
|
|
38048
|
+
return void 0;
|
|
38049
|
+
},
|
|
37866
38050
|
canonical: (ops, { engine: ce, scope }) => {
|
|
37867
38051
|
if (isSymbol2(ops[0]) && ops[0].canonical.operatorDefinition) {
|
|
37868
38052
|
const vars = ops.slice(1);
|
|
@@ -42434,6 +42618,18 @@ function canonicalInvisibleOperator(ops, { engine: ce }) {
|
|
|
42434
42618
|
}
|
|
42435
42619
|
}
|
|
42436
42620
|
ops = flattenInvisibleOperator(ops);
|
|
42621
|
+
if (ops.some((op) => isFunction2(op, "Text") || isString(op))) {
|
|
42622
|
+
const runs = [];
|
|
42623
|
+
for (const op of ops) {
|
|
42624
|
+
if (isFunction2(op, "Text")) {
|
|
42625
|
+
runs.push(...op.ops);
|
|
42626
|
+
} else if (op.operator !== "HorizontalSpacing") {
|
|
42627
|
+
runs.push(op.canonical);
|
|
42628
|
+
}
|
|
42629
|
+
}
|
|
42630
|
+
return ce._fn("Text", runs);
|
|
42631
|
+
}
|
|
42632
|
+
ops = combineFunctionApplications(ce, ops);
|
|
42437
42633
|
{
|
|
42438
42634
|
const significant = ops.filter((x) => x.operator !== "HorizontalSpacing");
|
|
42439
42635
|
if (significant.length === 2) {
|
|
@@ -42448,7 +42644,7 @@ function canonicalInvisibleOperator(ops, { engine: ce }) {
|
|
|
42448
42644
|
}
|
|
42449
42645
|
ops = flatten(ops);
|
|
42450
42646
|
if (ops.every(
|
|
42451
|
-
(x) => x.isValid && (x.type.isUnknown || x.type.matches("number") || x.isIndexedCollection && !isString(x))
|
|
42647
|
+
(x) => x.isValid && (x.type.isUnknown || x.type.type === "any" || x.type.type === "expression" || x.type.matches("number") || x.isIndexedCollection && !isString(x))
|
|
42452
42648
|
)) {
|
|
42453
42649
|
return ce._fn("Multiply", ops);
|
|
42454
42650
|
}
|
|
@@ -42463,6 +42659,40 @@ function flattenInvisibleOperator(ops) {
|
|
|
42463
42659
|
}
|
|
42464
42660
|
return ys;
|
|
42465
42661
|
}
|
|
42662
|
+
function combineFunctionApplications(ce, ops) {
|
|
42663
|
+
const result = [];
|
|
42664
|
+
let i = 0;
|
|
42665
|
+
while (i < ops.length) {
|
|
42666
|
+
const op = ops[i];
|
|
42667
|
+
if (i < ops.length - 1 && isSymbol2(op) && isFunction2(ops[i + 1], "Delimiter")) {
|
|
42668
|
+
const symName = op.symbol;
|
|
42669
|
+
const def = ce.lookupDefinition(symName);
|
|
42670
|
+
const delim = ops[i + 1];
|
|
42671
|
+
if (def && (isOperatorDef(def) || def.value?.type?.matches("function"))) {
|
|
42672
|
+
let args = delim.op1 ? isFunction2(delim.op1, "Sequence") ? delim.op1.ops : [delim.op1] : [];
|
|
42673
|
+
args = flatten(args);
|
|
42674
|
+
result.push(ce.function(symName, args));
|
|
42675
|
+
i += 2;
|
|
42676
|
+
continue;
|
|
42677
|
+
}
|
|
42678
|
+
if (delim.op1 && isFunction2(delim.op1, "Sequence")) {
|
|
42679
|
+
let args = delim.op1.ops;
|
|
42680
|
+
args = flatten(args);
|
|
42681
|
+
if (args.length > 1) {
|
|
42682
|
+
if (!def) ce.declare(symName, "function");
|
|
42683
|
+
else if (!isOperatorDef(def) && def.value?.type?.isUnknown)
|
|
42684
|
+
op.canonical.infer("function");
|
|
42685
|
+
result.push(ce.function(symName, args));
|
|
42686
|
+
i += 2;
|
|
42687
|
+
continue;
|
|
42688
|
+
}
|
|
42689
|
+
}
|
|
42690
|
+
}
|
|
42691
|
+
result.push(ops[i]);
|
|
42692
|
+
i++;
|
|
42693
|
+
}
|
|
42694
|
+
return result;
|
|
42695
|
+
}
|
|
42466
42696
|
function asInteger(expr2) {
|
|
42467
42697
|
if (isNumber(expr2)) {
|
|
42468
42698
|
const n = expr2.re;
|
|
@@ -43466,7 +43696,21 @@ var CORE_LIBRARY = [
|
|
|
43466
43696
|
},
|
|
43467
43697
|
Text: {
|
|
43468
43698
|
description: "A sequence of strings, annotated expressions and other Text expressions",
|
|
43469
|
-
signature: "(any*) ->
|
|
43699
|
+
signature: "(any*) -> string",
|
|
43700
|
+
evaluate: (ops, { engine: ce }) => {
|
|
43701
|
+
if (ops.length === 0) return ce.string("");
|
|
43702
|
+
const parts = [];
|
|
43703
|
+
for (const op of ops) {
|
|
43704
|
+
const unwrapped = op.operator === "Annotated" ? op.op1 : op;
|
|
43705
|
+
if (isString(unwrapped)) parts.push(unwrapped.string);
|
|
43706
|
+
else {
|
|
43707
|
+
const evaluated = unwrapped.evaluate();
|
|
43708
|
+
if (isString(evaluated)) parts.push(evaluated.string);
|
|
43709
|
+
else parts.push(evaluated.toString());
|
|
43710
|
+
}
|
|
43711
|
+
}
|
|
43712
|
+
return ce.string(parts.join(""));
|
|
43713
|
+
}
|
|
43470
43714
|
}
|
|
43471
43715
|
},
|
|
43472
43716
|
{
|
|
@@ -43561,7 +43805,16 @@ var CORE_LIBRARY = [
|
|
|
43561
43805
|
if (!isSymbol2(symbol2)) {
|
|
43562
43806
|
symbol2 = checkType(ce, lhs, "symbol");
|
|
43563
43807
|
}
|
|
43564
|
-
|
|
43808
|
+
const canonRhs = args[1].canonical;
|
|
43809
|
+
const result = ce._fn("Assign", [symbol2, canonRhs]);
|
|
43810
|
+
const symbolName2 = sym(symbol2);
|
|
43811
|
+
if (symbolName2 && isFunction2(canonRhs, "Function")) {
|
|
43812
|
+
if (!ce.lookupDefinition(symbolName2)) ce.symbol(symbolName2);
|
|
43813
|
+
const def = ce.lookupDefinition(symbolName2);
|
|
43814
|
+
if (def && isValueDef(def) && def.value.inferredType)
|
|
43815
|
+
def.value.type = ce.type("function");
|
|
43816
|
+
}
|
|
43817
|
+
return result;
|
|
43565
43818
|
},
|
|
43566
43819
|
evaluate: ([op1, op2], { engine: ce }) => {
|
|
43567
43820
|
if (isFunction2(op1, "Subscript") && sym(op1.op1)) {
|
|
@@ -43758,6 +44011,7 @@ var CORE_LIBRARY = [
|
|
|
43758
44011
|
description: "Simplify an expression.",
|
|
43759
44012
|
lazy: true,
|
|
43760
44013
|
signature: "(any) -> expression",
|
|
44014
|
+
type: ([x]) => x?.type ?? void 0,
|
|
43761
44015
|
canonical: (ops, { engine: ce }) => ce._fn("Simplify", checkArity(ce, ops, 1)),
|
|
43762
44016
|
evaluate: ([x]) => x.simplify() ?? void 0
|
|
43763
44017
|
},
|
|
@@ -53981,8 +54235,11 @@ var BaseCompiler = class _BaseCompiler {
|
|
|
53981
54235
|
for (const local of locals) {
|
|
53982
54236
|
for (const arg of args) {
|
|
53983
54237
|
if (isFunction2(arg, "Assign") && isSymbol2(arg.ops[0], local)) {
|
|
53984
|
-
|
|
54238
|
+
const rhs = arg.ops[1];
|
|
54239
|
+
if (_BaseCompiler.isComplexValued(rhs)) {
|
|
53985
54240
|
typeHints[local] = isWGSL ? "vec2f" : "vec2";
|
|
54241
|
+
} else if (_BaseCompiler.isIntegerValued(rhs)) {
|
|
54242
|
+
typeHints[local] = isWGSL ? "i32" : "int";
|
|
53986
54243
|
}
|
|
53987
54244
|
break;
|
|
53988
54245
|
}
|
|
@@ -54187,12 +54444,9 @@ var BaseCompiler = class _BaseCompiler {
|
|
|
54187
54444
|
/**
|
|
54188
54445
|
* Determine at compile time whether an expression produces a complex value.
|
|
54189
54446
|
*
|
|
54190
|
-
*
|
|
54191
|
-
*
|
|
54192
|
-
*
|
|
54193
|
-
* (undefined is treated as real -- assume-real policy)
|
|
54194
|
-
* - Functions: Abs, Arg, Re, Im always return real.
|
|
54195
|
-
* All others: complex if any operand is complex.
|
|
54447
|
+
* Uses the expression's declared type (from operator signatures) when
|
|
54448
|
+
* available. Falls back to operand inspection for functions whose
|
|
54449
|
+
* return type is unknown.
|
|
54196
54450
|
*/
|
|
54197
54451
|
static isComplexValued(expr2) {
|
|
54198
54452
|
if (isNumber(expr2)) return expr2.im !== 0;
|
|
@@ -54203,13 +54457,24 @@ var BaseCompiler = class _BaseCompiler {
|
|
|
54203
54457
|
return t.matches("complex") && !t.matches("real");
|
|
54204
54458
|
}
|
|
54205
54459
|
if (isFunction2(expr2)) {
|
|
54206
|
-
const
|
|
54207
|
-
if (
|
|
54208
|
-
|
|
54460
|
+
const t = expr2.type;
|
|
54461
|
+
if (t.matches("complex") && !t.matches("real")) return true;
|
|
54462
|
+
if (t.matches("real")) return false;
|
|
54209
54463
|
return expr2.ops.some((arg) => _BaseCompiler.isComplexValued(arg));
|
|
54210
54464
|
}
|
|
54211
54465
|
return false;
|
|
54212
54466
|
}
|
|
54467
|
+
/** True if the expression is provably integer-typed. */
|
|
54468
|
+
static isIntegerValued(expr2) {
|
|
54469
|
+
if (isNumber(expr2)) return expr2.im === 0 && Number.isInteger(expr2.re);
|
|
54470
|
+
const t = expr2.type;
|
|
54471
|
+
return t ? t.matches("integer") : false;
|
|
54472
|
+
}
|
|
54473
|
+
/** True if the expression is provably non-negative (sign ≥ 0). */
|
|
54474
|
+
static isNonNegative(expr2) {
|
|
54475
|
+
if (isNumber(expr2)) return expr2.im === 0 && expr2.re >= 0;
|
|
54476
|
+
return expr2.isNonNegative === true;
|
|
54477
|
+
}
|
|
54213
54478
|
/**
|
|
54214
54479
|
* Generate a temporary variable name
|
|
54215
54480
|
*/
|
|
@@ -54463,14 +54728,27 @@ function compile(expr2, options) {
|
|
|
54463
54728
|
} catch (e) {
|
|
54464
54729
|
if (options?.fallback ?? true) {
|
|
54465
54730
|
console.warn(
|
|
54466
|
-
`Compilation fallback for "${expr2.operator}": ${e.message}`
|
|
54731
|
+
`Compilation fallback for "${expr2.operator}" (target: ${options?.to ?? "javascript"}): ${e.message}`
|
|
54467
54732
|
);
|
|
54733
|
+
const ce = expr2.engine;
|
|
54734
|
+
const fallbackRun = ((vars) => {
|
|
54735
|
+
ce.pushScope();
|
|
54736
|
+
try {
|
|
54737
|
+
if (vars && typeof vars === "object") {
|
|
54738
|
+
for (const [k, v] of Object.entries(vars))
|
|
54739
|
+
ce.assign(k, v);
|
|
54740
|
+
}
|
|
54741
|
+
return expr2.evaluate().re;
|
|
54742
|
+
} finally {
|
|
54743
|
+
ce.popScope();
|
|
54744
|
+
}
|
|
54745
|
+
});
|
|
54468
54746
|
return {
|
|
54469
54747
|
target: options?.to ?? "javascript",
|
|
54470
54748
|
success: false,
|
|
54471
54749
|
code: "",
|
|
54472
54750
|
calling: "expression",
|
|
54473
|
-
run:
|
|
54751
|
+
run: fallbackRun
|
|
54474
54752
|
};
|
|
54475
54753
|
}
|
|
54476
54754
|
throw e;
|
|
@@ -59620,6 +59898,86 @@ function resetCommonSymbols(commonSymbols) {
|
|
|
59620
59898
|
for (const symbol2 of Object.values(commonSymbols)) symbol2?.reset();
|
|
59621
59899
|
}
|
|
59622
59900
|
|
|
59901
|
+
// src/compute-engine/compilation/constant-folding.ts
|
|
59902
|
+
function formatFloat(n) {
|
|
59903
|
+
const str = n.toString();
|
|
59904
|
+
if (!str.includes(".") && !str.includes("e") && !str.includes("E")) {
|
|
59905
|
+
return `${str}.0`;
|
|
59906
|
+
}
|
|
59907
|
+
return str;
|
|
59908
|
+
}
|
|
59909
|
+
function tryGetConstant(expr2) {
|
|
59910
|
+
if (!isNumber(expr2)) return void 0;
|
|
59911
|
+
if (expr2.im !== 0) return void 0;
|
|
59912
|
+
const re = expr2.re;
|
|
59913
|
+
if (!isFinite(re)) return void 0;
|
|
59914
|
+
return re;
|
|
59915
|
+
}
|
|
59916
|
+
var NUMERIC_LITERAL_RE = /^-?\d+(\.\d+)?$/;
|
|
59917
|
+
function foldTerms(terms, identity, op) {
|
|
59918
|
+
const identityValue = op === "+" ? 0 : 1;
|
|
59919
|
+
let numericAcc = null;
|
|
59920
|
+
const symbolic = [];
|
|
59921
|
+
for (const term of terms) {
|
|
59922
|
+
if (NUMERIC_LITERAL_RE.test(term)) {
|
|
59923
|
+
const val = parseFloat(term);
|
|
59924
|
+
if (op === "*" && val === 0) return "0.0";
|
|
59925
|
+
if (numericAcc === null) {
|
|
59926
|
+
numericAcc = val;
|
|
59927
|
+
} else {
|
|
59928
|
+
numericAcc = op === "+" ? numericAcc + val : numericAcc * val;
|
|
59929
|
+
}
|
|
59930
|
+
} else {
|
|
59931
|
+
symbolic.push(term);
|
|
59932
|
+
}
|
|
59933
|
+
}
|
|
59934
|
+
if (numericAcc !== null && numericAcc !== identityValue) {
|
|
59935
|
+
symbolic.unshift(formatFloat(numericAcc));
|
|
59936
|
+
}
|
|
59937
|
+
if (symbolic.length === 0) {
|
|
59938
|
+
if (numericAcc !== null) return formatFloat(numericAcc);
|
|
59939
|
+
return identity;
|
|
59940
|
+
}
|
|
59941
|
+
if (symbolic.length === 1) return symbolic[0];
|
|
59942
|
+
return symbolic.join(op === "+" ? " + " : " * ");
|
|
59943
|
+
}
|
|
59944
|
+
function tryGetComplexParts(expr2, compile3) {
|
|
59945
|
+
if (isSymbol2(expr2, "ImaginaryUnit")) {
|
|
59946
|
+
return { re: null, im: "1.0" };
|
|
59947
|
+
}
|
|
59948
|
+
if (isNumber(expr2) && expr2.im !== 0) {
|
|
59949
|
+
const re = expr2.re;
|
|
59950
|
+
const im = expr2.im;
|
|
59951
|
+
return {
|
|
59952
|
+
re: re !== 0 ? formatFloat(re) : null,
|
|
59953
|
+
im: formatFloat(im)
|
|
59954
|
+
};
|
|
59955
|
+
}
|
|
59956
|
+
if (isFunction2(expr2, "Multiply")) {
|
|
59957
|
+
const ops = expr2.ops;
|
|
59958
|
+
const iIndex = ops.findIndex(
|
|
59959
|
+
(op) => isSymbol2(op, "ImaginaryUnit") || isNumber(op) && op.re === 0 && op.im !== 0
|
|
59960
|
+
);
|
|
59961
|
+
if (iIndex >= 0) {
|
|
59962
|
+
const iFactor = ops[iIndex];
|
|
59963
|
+
const iScale = isSymbol2(iFactor, "ImaginaryUnit") ? 1 : iFactor.im;
|
|
59964
|
+
const remaining = ops.filter((_, idx) => idx !== iIndex);
|
|
59965
|
+
if (remaining.length === 0) {
|
|
59966
|
+
return { re: null, im: formatFloat(iScale) };
|
|
59967
|
+
}
|
|
59968
|
+
const compiledFactors = remaining.map((r) => compile3(r));
|
|
59969
|
+
if (iScale !== 1)
|
|
59970
|
+
compiledFactors.unshift(formatFloat(iScale));
|
|
59971
|
+
const imCode = foldTerms(compiledFactors, "1.0", "*");
|
|
59972
|
+
return { re: null, im: imCode };
|
|
59973
|
+
}
|
|
59974
|
+
}
|
|
59975
|
+
if (BaseCompiler.isComplexValued(expr2)) {
|
|
59976
|
+
return null;
|
|
59977
|
+
}
|
|
59978
|
+
return { re: compile3(expr2), im: null };
|
|
59979
|
+
}
|
|
59980
|
+
|
|
59623
59981
|
// src/compute-engine/compilation/javascript-target.ts
|
|
59624
59982
|
var JAVASCRIPT_OPERATORS = {
|
|
59625
59983
|
Add: ["+", 11],
|
|
@@ -59643,12 +60001,21 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59643
60001
|
Abs: (args, compile3) => {
|
|
59644
60002
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
59645
60003
|
return `_SYS.cabs(${compile3(args[0])})`;
|
|
60004
|
+
if (BaseCompiler.isNonNegative(args[0])) return compile3(args[0]);
|
|
59646
60005
|
return `Math.abs(${compile3(args[0])})`;
|
|
59647
60006
|
},
|
|
59648
60007
|
Add: (args, compile3) => {
|
|
59649
60008
|
if (args.length === 1) return compile3(args[0]);
|
|
59650
60009
|
const anyComplex = args.some((a) => BaseCompiler.isComplexValued(a));
|
|
59651
|
-
if (!anyComplex)
|
|
60010
|
+
if (!anyComplex) {
|
|
60011
|
+
const constants = args.map(tryGetConstant);
|
|
60012
|
+
if (constants.every((c) => c !== void 0))
|
|
60013
|
+
return String(constants.reduce((a, b) => a + b, 0));
|
|
60014
|
+
const nonZero = args.filter((a) => tryGetConstant(a) !== 0);
|
|
60015
|
+
if (nonZero.length === 0) return "0";
|
|
60016
|
+
if (nonZero.length === 1) return compile3(nonZero[0]);
|
|
60017
|
+
return `(${nonZero.map((x) => compile3(x)).join(" + ")})`;
|
|
60018
|
+
}
|
|
59652
60019
|
const parts = args.map((a) => {
|
|
59653
60020
|
const code = compile3(a);
|
|
59654
60021
|
return { code, isComplex: BaseCompiler.isComplexValued(a) };
|
|
@@ -59705,7 +60072,10 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59705
60072
|
return `Math.atan(${compile3(args[0])})`;
|
|
59706
60073
|
},
|
|
59707
60074
|
Artanh: "Math.atanh",
|
|
59708
|
-
Ceil:
|
|
60075
|
+
Ceil: (args, compile3) => {
|
|
60076
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
60077
|
+
return `Math.ceil(${compile3(args[0])})`;
|
|
60078
|
+
},
|
|
59709
60079
|
Chop: "_SYS.chop",
|
|
59710
60080
|
Cos: (args, compile3) => {
|
|
59711
60081
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
@@ -59748,7 +60118,10 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59748
60118
|
return `_SYS.cexp(${compile3(args[0])})`;
|
|
59749
60119
|
return `Math.exp(${compile3(args[0])})`;
|
|
59750
60120
|
},
|
|
59751
|
-
Floor:
|
|
60121
|
+
Floor: (args, compile3) => {
|
|
60122
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
60123
|
+
return `Math.floor(${compile3(args[0])})`;
|
|
60124
|
+
},
|
|
59752
60125
|
Fract: ([x], compile3) => {
|
|
59753
60126
|
if (x === null) throw new Error("Fract: no argument");
|
|
59754
60127
|
return BaseCompiler.inlineExpression("${x} - Math.floor(${x})", compile3(x));
|
|
@@ -59844,12 +60217,20 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59844
60217
|
if (BaseCompiler.isComplexValued(base) || BaseCompiler.isComplexValued(exp3)) {
|
|
59845
60218
|
return `_SYS.cpow(${compile3(base)}, ${compile3(exp3)})`;
|
|
59846
60219
|
}
|
|
59847
|
-
const
|
|
59848
|
-
|
|
59849
|
-
if (
|
|
59850
|
-
|
|
59851
|
-
if (
|
|
59852
|
-
if (
|
|
60220
|
+
const bConst = tryGetConstant(base);
|
|
60221
|
+
const eConst = tryGetConstant(exp3);
|
|
60222
|
+
if (bConst !== void 0 && eConst !== void 0)
|
|
60223
|
+
return String(Math.pow(bConst, eConst));
|
|
60224
|
+
if (eConst === 0) return "1";
|
|
60225
|
+
if (eConst === 1) return compile3(base);
|
|
60226
|
+
if (eConst === 2 && (isSymbol2(base) || isNumber(base))) {
|
|
60227
|
+
const code = compile3(base);
|
|
60228
|
+
return `(${code} * ${code})`;
|
|
60229
|
+
}
|
|
60230
|
+
if (eConst === -1) return `(1 / (${compile3(base)}))`;
|
|
60231
|
+
if (eConst === 0.5) return `Math.sqrt(${compile3(base)})`;
|
|
60232
|
+
if (eConst === 1 / 3) return `Math.cbrt(${compile3(base)})`;
|
|
60233
|
+
if (eConst === -0.5) return `(1 / Math.sqrt(${compile3(base)}))`;
|
|
59853
60234
|
return `Math.pow(${compile3(base)}, ${compile3(exp3)})`;
|
|
59854
60235
|
},
|
|
59855
60236
|
Range: (args, compile3) => {
|
|
@@ -59886,16 +60267,29 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59886
60267
|
Root: ([arg, exp3], compile3) => {
|
|
59887
60268
|
if (arg === null) throw new Error("Root: no argument");
|
|
59888
60269
|
if (exp3 === null) return `Math.sqrt(${compile3(arg)})`;
|
|
59889
|
-
|
|
59890
|
-
|
|
59891
|
-
if (
|
|
60270
|
+
const aConst = tryGetConstant(arg);
|
|
60271
|
+
const nConst = tryGetConstant(exp3);
|
|
60272
|
+
if (aConst !== void 0 && nConst !== void 0 && nConst !== 0)
|
|
60273
|
+
return String(Math.pow(aConst, 1 / nConst));
|
|
60274
|
+
if (nConst === 2) return `Math.sqrt(${compile3(arg)})`;
|
|
60275
|
+
if (nConst === 3) return `Math.cbrt(${compile3(arg)})`;
|
|
60276
|
+
if (nConst !== void 0) return `Math.pow(${compile3(arg)}, ${1 / nConst})`;
|
|
59892
60277
|
return `Math.pow(${compile3(arg)}, 1 / (${compile3(exp3)}))`;
|
|
59893
60278
|
},
|
|
59894
60279
|
Random: "Math.random",
|
|
59895
|
-
Round:
|
|
60280
|
+
Round: (args, compile3) => {
|
|
60281
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
60282
|
+
return `Math.round(${compile3(args[0])})`;
|
|
60283
|
+
},
|
|
59896
60284
|
Square: (args, compile3) => {
|
|
59897
60285
|
const arg = args[0];
|
|
59898
60286
|
if (arg === null) throw new Error("Square: no argument");
|
|
60287
|
+
const c = tryGetConstant(arg);
|
|
60288
|
+
if (c !== void 0) return String(c * c);
|
|
60289
|
+
if (isSymbol2(arg)) {
|
|
60290
|
+
const code = compile3(arg);
|
|
60291
|
+
return `(${code} * ${code})`;
|
|
60292
|
+
}
|
|
59899
60293
|
return `Math.pow(${compile3(arg)}, 2)`;
|
|
59900
60294
|
},
|
|
59901
60295
|
Sec: (args, compile3) => {
|
|
@@ -59928,6 +60322,8 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59928
60322
|
Sqrt: (args, compile3) => {
|
|
59929
60323
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
59930
60324
|
return `_SYS.csqrt(${compile3(args[0])})`;
|
|
60325
|
+
const c = tryGetConstant(args[0]);
|
|
60326
|
+
if (c !== void 0) return String(Math.sqrt(c));
|
|
59931
60327
|
return `Math.sqrt(${compile3(args[0])})`;
|
|
59932
60328
|
},
|
|
59933
60329
|
Tan: (args, compile3) => {
|
|
@@ -59944,9 +60340,14 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59944
60340
|
if (a === null || b === null) throw new Error("Mod: missing argument");
|
|
59945
60341
|
const ca = compile3(a);
|
|
59946
60342
|
const cb = compile3(b);
|
|
60343
|
+
if (BaseCompiler.isIntegerValued(a) && BaseCompiler.isIntegerValued(b) && BaseCompiler.isNonNegative(a))
|
|
60344
|
+
return `(${ca} % ${cb})`;
|
|
59947
60345
|
return `((${ca} % ${cb}) + ${cb}) % ${cb}`;
|
|
59948
60346
|
},
|
|
59949
|
-
Truncate:
|
|
60347
|
+
Truncate: (args, compile3) => {
|
|
60348
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
60349
|
+
return `Math.trunc(${compile3(args[0])})`;
|
|
60350
|
+
},
|
|
59950
60351
|
Remainder: ([a, b], compile3) => {
|
|
59951
60352
|
if (a === null || b === null)
|
|
59952
60353
|
throw new Error("Remainder: missing argument");
|
|
@@ -59954,25 +60355,20 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59954
60355
|
a
|
|
59955
60356
|
)} / ${compile3(b)}))`;
|
|
59956
60357
|
},
|
|
59957
|
-
//
|
|
59958
|
-
|
|
59959
|
-
if (a === null || b === null) throw new Error("Subtract: missing argument");
|
|
59960
|
-
const ac = BaseCompiler.isComplexValued(a);
|
|
59961
|
-
const bc = BaseCompiler.isComplexValued(b);
|
|
59962
|
-
if (!ac && !bc) return `(${compile3(a)} - ${compile3(b)})`;
|
|
59963
|
-
const ca = compile3(a);
|
|
59964
|
-
const cb = compile3(b);
|
|
59965
|
-
const reA = ac ? `(${ca}).re` : ca;
|
|
59966
|
-
const imA = ac ? `(${ca}).im` : "0";
|
|
59967
|
-
const reB = bc ? `(${cb}).re` : cb;
|
|
59968
|
-
const imB = bc ? `(${cb}).im` : "0";
|
|
59969
|
-
return `({ re: ${reA} - ${reB}, im: ${imA} - ${imB} })`;
|
|
59970
|
-
},
|
|
60358
|
+
// No Subtract function handler — Subtract canonicalizes to Add+Negate.
|
|
60359
|
+
// The operator entry in JAVASCRIPT_OPERATORS handles any edge cases.
|
|
59971
60360
|
Divide: ([a, b], compile3) => {
|
|
59972
60361
|
if (a === null || b === null) throw new Error("Divide: missing argument");
|
|
59973
60362
|
const ac = BaseCompiler.isComplexValued(a);
|
|
59974
60363
|
const bc = BaseCompiler.isComplexValued(b);
|
|
59975
|
-
if (!ac && !bc)
|
|
60364
|
+
if (!ac && !bc) {
|
|
60365
|
+
const ca = tryGetConstant(a);
|
|
60366
|
+
const cb = tryGetConstant(b);
|
|
60367
|
+
if (ca !== void 0 && cb !== void 0 && cb !== 0)
|
|
60368
|
+
return String(ca / cb);
|
|
60369
|
+
if (cb === 1) return compile3(a);
|
|
60370
|
+
return `(${compile3(a)} / ${compile3(b)})`;
|
|
60371
|
+
}
|
|
59976
60372
|
if (ac && bc) {
|
|
59977
60373
|
return `(() => { const _a = ${compile3(a)}, _b = ${compile3(
|
|
59978
60374
|
b
|
|
@@ -59989,13 +60385,26 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
59989
60385
|
},
|
|
59990
60386
|
Negate: ([x], compile3) => {
|
|
59991
60387
|
if (x === null) throw new Error("Negate: no argument");
|
|
59992
|
-
if (!BaseCompiler.isComplexValued(x))
|
|
60388
|
+
if (!BaseCompiler.isComplexValued(x)) {
|
|
60389
|
+
const c = tryGetConstant(x);
|
|
60390
|
+
if (c !== void 0) return String(-c);
|
|
60391
|
+
return `(-${compile3(x)})`;
|
|
60392
|
+
}
|
|
59993
60393
|
return `_SYS.cneg(${compile3(x)})`;
|
|
59994
60394
|
},
|
|
59995
60395
|
Multiply: (args, compile3) => {
|
|
59996
60396
|
if (args.length === 1) return compile3(args[0]);
|
|
59997
60397
|
const anyComplex = args.some((a) => BaseCompiler.isComplexValued(a));
|
|
59998
|
-
if (!anyComplex)
|
|
60398
|
+
if (!anyComplex) {
|
|
60399
|
+
if (args.some((a) => tryGetConstant(a) === 0)) return "0";
|
|
60400
|
+
const constants = args.map(tryGetConstant);
|
|
60401
|
+
if (constants.every((c) => c !== void 0))
|
|
60402
|
+
return String(constants.reduce((a, b) => a * b, 1));
|
|
60403
|
+
const nonOne = args.filter((a) => tryGetConstant(a) !== 1);
|
|
60404
|
+
if (nonOne.length === 0) return "1";
|
|
60405
|
+
if (nonOne.length === 1) return compile3(nonOne[0]);
|
|
60406
|
+
return `(${nonOne.map((x) => compile3(x)).join(" * ")})`;
|
|
60407
|
+
}
|
|
59999
60408
|
if (args.length === 2) {
|
|
60000
60409
|
const ac = BaseCompiler.isComplexValued(args[0]);
|
|
60001
60410
|
const bc = BaseCompiler.isComplexValued(args[1]);
|
|
@@ -60080,20 +60489,30 @@ var JAVASCRIPT_FUNCTIONS = {
|
|
|
60080
60489
|
AiryAi: "_SYS.airyAi",
|
|
60081
60490
|
AiryBi: "_SYS.airyBi",
|
|
60082
60491
|
// Combinatorics
|
|
60492
|
+
Mandelbrot: ([c, maxIter], compile3) => {
|
|
60493
|
+
if (c === null || maxIter === null)
|
|
60494
|
+
throw new Error("Mandelbrot: missing arguments");
|
|
60495
|
+
return `_SYS.mandelbrot(${compile3(c)}, ${compile3(maxIter)})`;
|
|
60496
|
+
},
|
|
60497
|
+
Julia: ([z, c, maxIter], compile3) => {
|
|
60498
|
+
if (z === null || c === null || maxIter === null)
|
|
60499
|
+
throw new Error("Julia: missing arguments");
|
|
60500
|
+
return `_SYS.julia(${compile3(z)}, ${compile3(c)}, ${compile3(maxIter)})`;
|
|
60501
|
+
},
|
|
60083
60502
|
Binomial: (args, compile3) => `_SYS.binomial(${compile3(args[0])}, ${compile3(args[1])})`,
|
|
60084
60503
|
Fibonacci: "_SYS.fibonacci",
|
|
60085
60504
|
// Complex-specific functions
|
|
60086
|
-
|
|
60505
|
+
Real: (args, compile3) => {
|
|
60087
60506
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
60088
60507
|
return `(${compile3(args[0])}).re`;
|
|
60089
60508
|
return compile3(args[0]);
|
|
60090
60509
|
},
|
|
60091
|
-
|
|
60510
|
+
Imaginary: (args, compile3) => {
|
|
60092
60511
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
60093
60512
|
return `(${compile3(args[0])}).im`;
|
|
60094
60513
|
return "0";
|
|
60095
60514
|
},
|
|
60096
|
-
|
|
60515
|
+
Argument: (args, compile3) => {
|
|
60097
60516
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
60098
60517
|
return `_SYS.carg(${compile3(args[0])})`;
|
|
60099
60518
|
return `(${compile3(args[0])} >= 0 ? 0 : Math.PI)`;
|
|
@@ -60429,6 +60848,41 @@ var SYS_HELPERS = {
|
|
|
60429
60848
|
sinc,
|
|
60430
60849
|
fresnelS,
|
|
60431
60850
|
fresnelC,
|
|
60851
|
+
mandelbrot: (c, maxIter) => {
|
|
60852
|
+
let zx = 0, zy = 0;
|
|
60853
|
+
const cx = typeof c === "number" ? c : c.re;
|
|
60854
|
+
const cy = typeof c === "number" ? 0 : c.im;
|
|
60855
|
+
const n = Math.round(maxIter);
|
|
60856
|
+
for (let i = 0; i < n; i++) {
|
|
60857
|
+
const newZx = zx * zx - zy * zy + cx;
|
|
60858
|
+
zy = 2 * zx * zy + cy;
|
|
60859
|
+
zx = newZx;
|
|
60860
|
+
const mag2 = zx * zx + zy * zy;
|
|
60861
|
+
if (mag2 > 4) {
|
|
60862
|
+
const smooth = (i - Math.log2(Math.log2(mag2)) + 4) / n;
|
|
60863
|
+
return Math.max(0, Math.min(1, smooth));
|
|
60864
|
+
}
|
|
60865
|
+
}
|
|
60866
|
+
return 1;
|
|
60867
|
+
},
|
|
60868
|
+
julia: (z, c, maxIter) => {
|
|
60869
|
+
let zx = typeof z === "number" ? z : z.re;
|
|
60870
|
+
let zy = typeof z === "number" ? 0 : z.im;
|
|
60871
|
+
const cx = typeof c === "number" ? c : c.re;
|
|
60872
|
+
const cy = typeof c === "number" ? 0 : c.im;
|
|
60873
|
+
const n = Math.round(maxIter);
|
|
60874
|
+
for (let i = 0; i < n; i++) {
|
|
60875
|
+
const newZx = zx * zx - zy * zy + cx;
|
|
60876
|
+
zy = 2 * zx * zy + cy;
|
|
60877
|
+
zx = newZx;
|
|
60878
|
+
const mag2 = zx * zx + zy * zy;
|
|
60879
|
+
if (mag2 > 4) {
|
|
60880
|
+
const smooth = (i - Math.log2(Math.log2(mag2)) + 4) / n;
|
|
60881
|
+
return Math.max(0, Math.min(1, smooth));
|
|
60882
|
+
}
|
|
60883
|
+
}
|
|
60884
|
+
return 1;
|
|
60885
|
+
},
|
|
60432
60886
|
binomial: choose,
|
|
60433
60887
|
fibonacci,
|
|
60434
60888
|
// Complex helpers
|
|
@@ -60774,6 +61228,7 @@ var GPU_OPERATORS = {
|
|
|
60774
61228
|
Add: ["+", 11],
|
|
60775
61229
|
Negate: ["-", 14],
|
|
60776
61230
|
Subtract: ["-", 11],
|
|
61231
|
+
// Subtract canonicalizes to Add+Negate; kept as fallback
|
|
60777
61232
|
Multiply: ["*", 12],
|
|
60778
61233
|
Divide: ["/", 13],
|
|
60779
61234
|
Equal: ["==", 8],
|
|
@@ -60789,6 +61244,12 @@ var GPU_OPERATORS = {
|
|
|
60789
61244
|
function gpuVec2(target) {
|
|
60790
61245
|
return target?.language === "wgsl" ? "vec2f" : "vec2";
|
|
60791
61246
|
}
|
|
61247
|
+
function compileIntArg(expr2, compile3, target) {
|
|
61248
|
+
const c = tryGetConstant(expr2);
|
|
61249
|
+
if (c !== void 0 && Number.isInteger(c)) return c.toString();
|
|
61250
|
+
const intCast = target?.language === "wgsl" ? "i32" : "int";
|
|
61251
|
+
return `${intCast}(${compile3(expr2)})`;
|
|
61252
|
+
}
|
|
60792
61253
|
var GPU_UNROLL_LIMIT = 100;
|
|
60793
61254
|
function compileGPUSumProduct(kind, args, _compile2, target) {
|
|
60794
61255
|
if (!args[0]) throw new Error(`${kind}: no body`);
|
|
@@ -60851,88 +61312,113 @@ var GPU_FUNCTIONS = {
|
|
|
60851
61312
|
if (args.length === 0) return "0.0";
|
|
60852
61313
|
if (args.length === 1) return compile3(args[0]);
|
|
60853
61314
|
const anyComplex = args.some((a) => BaseCompiler.isComplexValued(a));
|
|
60854
|
-
if (!anyComplex)
|
|
60855
|
-
|
|
60856
|
-
|
|
60857
|
-
|
|
60858
|
-
|
|
60859
|
-
|
|
60860
|
-
},
|
|
60861
|
-
Multiply: (args, compile3, _target) => {
|
|
60862
|
-
if (args.length === 0) return "1.0";
|
|
60863
|
-
if (args.length === 1) return compile3(args[0]);
|
|
60864
|
-
const anyComplex = args.some((a) => BaseCompiler.isComplexValued(a));
|
|
60865
|
-
if (!anyComplex) return args.map((x) => compile3(x)).join(" * ");
|
|
60866
|
-
let result = compile3(args[0]);
|
|
60867
|
-
let resultIsComplex = BaseCompiler.isComplexValued(args[0]);
|
|
60868
|
-
for (let i = 1; i < args.length; i++) {
|
|
60869
|
-
const code = compile3(args[i]);
|
|
60870
|
-
const argIsComplex = BaseCompiler.isComplexValued(args[i]);
|
|
60871
|
-
if (!resultIsComplex && !argIsComplex) {
|
|
60872
|
-
result = `(${result} * ${code})`;
|
|
60873
|
-
} else if (resultIsComplex && !argIsComplex) {
|
|
60874
|
-
result = `(${code} * ${result})`;
|
|
60875
|
-
} else if (!resultIsComplex && argIsComplex) {
|
|
60876
|
-
result = `(${result} * ${code})`;
|
|
60877
|
-
resultIsComplex = true;
|
|
60878
|
-
} else {
|
|
60879
|
-
result = `_gpu_cmul(${result}, ${code})`;
|
|
60880
|
-
}
|
|
61315
|
+
if (!anyComplex) {
|
|
61316
|
+
return foldTerms(
|
|
61317
|
+
args.map((x) => compile3(x)),
|
|
61318
|
+
"0.0",
|
|
61319
|
+
"+"
|
|
61320
|
+
);
|
|
60881
61321
|
}
|
|
60882
|
-
|
|
60883
|
-
|
|
60884
|
-
|
|
60885
|
-
|
|
61322
|
+
const parts = args.map((a) => tryGetComplexParts(a, compile3));
|
|
61323
|
+
if (parts.some((p) => p === null)) {
|
|
61324
|
+
const v2 = gpuVec2(target);
|
|
61325
|
+
return args.map((a) => {
|
|
61326
|
+
const code = compile3(a);
|
|
61327
|
+
return BaseCompiler.isComplexValued(a) ? code : `${v2}(${code}, 0.0)`;
|
|
61328
|
+
}).join(" + ");
|
|
61329
|
+
}
|
|
61330
|
+
const reParts = [];
|
|
61331
|
+
const imParts = [];
|
|
61332
|
+
for (const p of parts) {
|
|
61333
|
+
if (p.re !== null) reParts.push(p.re);
|
|
61334
|
+
if (p.im !== null) imParts.push(p.im);
|
|
61335
|
+
}
|
|
61336
|
+
const reSum = foldTerms(reParts, "0.0", "+");
|
|
61337
|
+
const imSum = foldTerms(imParts, "0.0", "+");
|
|
61338
|
+
return `${gpuVec2(target)}(${reSum}, ${imSum})`;
|
|
61339
|
+
},
|
|
61340
|
+
Multiply: (args, compile3, target) => {
|
|
61341
|
+
if (args.length === 0) return "1.0";
|
|
60886
61342
|
if (args.length === 1) return compile3(args[0]);
|
|
60887
61343
|
const anyComplex = args.some((a) => BaseCompiler.isComplexValued(a));
|
|
60888
61344
|
if (!anyComplex) {
|
|
60889
|
-
|
|
60890
|
-
|
|
60891
|
-
|
|
60892
|
-
|
|
60893
|
-
|
|
60894
|
-
return result2;
|
|
60895
|
-
}
|
|
60896
|
-
const v2 = gpuVec2(target);
|
|
60897
|
-
const promote = (a) => {
|
|
60898
|
-
const code = compile3(a);
|
|
60899
|
-
return BaseCompiler.isComplexValued(a) ? code : `${v2}(${code}, 0.0)`;
|
|
60900
|
-
};
|
|
60901
|
-
if (args.length === 2) return `${promote(args[0])} - ${promote(args[1])}`;
|
|
60902
|
-
let result = promote(args[0]);
|
|
60903
|
-
for (let i = 1; i < args.length; i++) {
|
|
60904
|
-
result = `${result} - ${promote(args[i])}`;
|
|
61345
|
+
return foldTerms(
|
|
61346
|
+
args.map((x) => compile3(x)),
|
|
61347
|
+
"1.0",
|
|
61348
|
+
"*"
|
|
61349
|
+
);
|
|
60905
61350
|
}
|
|
61351
|
+
const iIndex = args.findIndex(
|
|
61352
|
+
(op) => isSymbol2(op, "ImaginaryUnit") || isNumber(op) && op.re === 0 && op.im !== 0
|
|
61353
|
+
);
|
|
61354
|
+
if (iIndex >= 0) {
|
|
61355
|
+
const iFactor = args[iIndex];
|
|
61356
|
+
const iScale = isSymbol2(iFactor, "ImaginaryUnit") ? 1 : iFactor.im;
|
|
61357
|
+
const realFactors = args.filter((_, i) => i !== iIndex);
|
|
61358
|
+
const v2 = gpuVec2(target);
|
|
61359
|
+
if (realFactors.length === 0)
|
|
61360
|
+
return `${v2}(0.0, ${formatFloat(iScale)})`;
|
|
61361
|
+
const factors = realFactors.map((f) => compile3(f));
|
|
61362
|
+
if (iScale !== 1) factors.unshift(formatFloat(iScale));
|
|
61363
|
+
const imCode = foldTerms(factors, "1.0", "*");
|
|
61364
|
+
return `${v2}(0.0, ${imCode})`;
|
|
61365
|
+
}
|
|
61366
|
+
const realCodes = [];
|
|
61367
|
+
const complexCodes = [];
|
|
61368
|
+
for (const a of args) {
|
|
61369
|
+
if (BaseCompiler.isComplexValued(a)) complexCodes.push(compile3(a));
|
|
61370
|
+
else realCodes.push(compile3(a));
|
|
61371
|
+
}
|
|
61372
|
+
const scalarCode = foldTerms(realCodes, "1.0", "*");
|
|
61373
|
+
let result = complexCodes[0];
|
|
61374
|
+
for (let i = 1; i < complexCodes.length; i++) {
|
|
61375
|
+
result = `_gpu_cmul(${result}, ${complexCodes[i]})`;
|
|
61376
|
+
}
|
|
61377
|
+
if (scalarCode !== "1.0") result = `(${scalarCode} * ${result})`;
|
|
60906
61378
|
return result;
|
|
60907
61379
|
},
|
|
61380
|
+
// No Subtract function handler — Subtract canonicalizes to Add+Negate.
|
|
61381
|
+
// The operator entry in GPU_OPERATORS handles any edge cases.
|
|
60908
61382
|
Divide: (args, compile3, target) => {
|
|
60909
61383
|
if (args.length === 0) return "1.0";
|
|
60910
61384
|
if (args.length === 1) return compile3(args[0]);
|
|
60911
61385
|
const ac = BaseCompiler.isComplexValued(args[0]);
|
|
60912
61386
|
const bc = args.length >= 2 && BaseCompiler.isComplexValued(args[1]);
|
|
60913
61387
|
if (!ac && !bc) {
|
|
60914
|
-
if (args.length === 2)
|
|
61388
|
+
if (args.length === 2) {
|
|
61389
|
+
const a = tryGetConstant(args[0]);
|
|
61390
|
+
const b = tryGetConstant(args[1]);
|
|
61391
|
+
if (a !== void 0 && b !== void 0 && b !== 0)
|
|
61392
|
+
return formatFloat(a / b);
|
|
61393
|
+
if (b === 1) return compile3(args[0]);
|
|
61394
|
+
return `${compile3(args[0])} / ${compile3(args[1])}`;
|
|
61395
|
+
}
|
|
60915
61396
|
let result = compile3(args[0]);
|
|
60916
|
-
for (let i = 1; i < args.length; i++)
|
|
61397
|
+
for (let i = 1; i < args.length; i++)
|
|
60917
61398
|
result = `${result} / ${compile3(args[i])}`;
|
|
60918
|
-
}
|
|
60919
61399
|
return result;
|
|
60920
61400
|
}
|
|
60921
61401
|
if (ac && bc) return `_gpu_cdiv(${compile3(args[0])}, ${compile3(args[1])})`;
|
|
60922
|
-
if (ac && !bc) {
|
|
60923
|
-
return `(${compile3(args[0])} / ${compile3(args[1])})`;
|
|
60924
|
-
}
|
|
61402
|
+
if (ac && !bc) return `(${compile3(args[0])} / ${compile3(args[1])})`;
|
|
60925
61403
|
const v2 = gpuVec2(target);
|
|
60926
61404
|
return `_gpu_cdiv(${v2}(${compile3(args[0])}, 0.0), ${compile3(args[1])})`;
|
|
60927
61405
|
},
|
|
60928
|
-
Negate: ([x], compile3) => {
|
|
61406
|
+
Negate: ([x], compile3, target) => {
|
|
60929
61407
|
if (x === null) throw new Error("Negate: no argument");
|
|
61408
|
+
const c = tryGetConstant(x);
|
|
61409
|
+
if (c !== void 0) return formatFloat(-c);
|
|
61410
|
+
if (isNumber(x) && x.im !== 0) {
|
|
61411
|
+
return `${gpuVec2(target)}(${formatFloat(-x.re)}, ${formatFloat(-x.im)})`;
|
|
61412
|
+
}
|
|
61413
|
+
if (isSymbol2(x, "ImaginaryUnit"))
|
|
61414
|
+
return `${gpuVec2(target)}(0.0, -1.0)`;
|
|
60930
61415
|
return `(-${compile3(x)})`;
|
|
60931
61416
|
},
|
|
60932
61417
|
// Standard math functions with complex dispatch
|
|
60933
61418
|
Abs: (args, compile3) => {
|
|
60934
61419
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
60935
61420
|
return `length(${compile3(args[0])})`;
|
|
61421
|
+
if (BaseCompiler.isNonNegative(args[0])) return compile3(args[0]);
|
|
60936
61422
|
return `abs(${compile3(args[0])})`;
|
|
60937
61423
|
},
|
|
60938
61424
|
Arccos: (args, compile3) => {
|
|
@@ -60950,7 +61436,10 @@ var GPU_FUNCTIONS = {
|
|
|
60950
61436
|
return `_gpu_catan(${compile3(args[0])})`;
|
|
60951
61437
|
return `atan(${compile3(args[0])})`;
|
|
60952
61438
|
},
|
|
60953
|
-
Ceil:
|
|
61439
|
+
Ceil: (args, compile3) => {
|
|
61440
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
61441
|
+
return `ceil(${compile3(args[0])})`;
|
|
61442
|
+
},
|
|
60954
61443
|
Clamp: "clamp",
|
|
60955
61444
|
Cos: (args, compile3) => {
|
|
60956
61445
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
@@ -60964,7 +61453,10 @@ var GPU_FUNCTIONS = {
|
|
|
60964
61453
|
return `exp(${compile3(args[0])})`;
|
|
60965
61454
|
},
|
|
60966
61455
|
Exp2: "exp2",
|
|
60967
|
-
Floor:
|
|
61456
|
+
Floor: (args, compile3) => {
|
|
61457
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
61458
|
+
return `floor(${compile3(args[0])})`;
|
|
61459
|
+
},
|
|
60968
61460
|
Fract: "fract",
|
|
60969
61461
|
Ln: (args, compile3) => {
|
|
60970
61462
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
@@ -60986,10 +61478,25 @@ var GPU_FUNCTIONS = {
|
|
|
60986
61478
|
const eCode = BaseCompiler.isComplexValued(exp3) ? compile3(exp3) : `${v2}(${compile3(exp3)}, 0.0)`;
|
|
60987
61479
|
return `_gpu_cpow(${bCode}, ${eCode})`;
|
|
60988
61480
|
}
|
|
61481
|
+
const bConst = tryGetConstant(base);
|
|
61482
|
+
const eConst = tryGetConstant(exp3);
|
|
61483
|
+
if (bConst !== void 0 && eConst !== void 0)
|
|
61484
|
+
return formatFloat(Math.pow(bConst, eConst));
|
|
61485
|
+
if (eConst === 0) return "1.0";
|
|
61486
|
+
if (eConst === 1) return compile3(base);
|
|
61487
|
+
if (eConst === 2 && (isSymbol2(base) || isNumber(base))) {
|
|
61488
|
+
const code = compile3(base);
|
|
61489
|
+
return `(${code} * ${code})`;
|
|
61490
|
+
}
|
|
61491
|
+
if (eConst === -1) return `(1.0 / ${compile3(base)})`;
|
|
61492
|
+
if (eConst === 0.5) return `sqrt(${compile3(base)})`;
|
|
60989
61493
|
return `pow(${compile3(base)}, ${compile3(exp3)})`;
|
|
60990
61494
|
},
|
|
60991
61495
|
Radians: "radians",
|
|
60992
|
-
Round:
|
|
61496
|
+
Round: (args, compile3) => {
|
|
61497
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
61498
|
+
return `round(${compile3(args[0])})`;
|
|
61499
|
+
},
|
|
60993
61500
|
Sign: "sign",
|
|
60994
61501
|
Sin: (args, compile3) => {
|
|
60995
61502
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
@@ -61000,6 +61507,8 @@ var GPU_FUNCTIONS = {
|
|
|
61000
61507
|
Sqrt: (args, compile3) => {
|
|
61001
61508
|
if (BaseCompiler.isComplexValued(args[0]))
|
|
61002
61509
|
return `_gpu_csqrt(${compile3(args[0])})`;
|
|
61510
|
+
const c = tryGetConstant(args[0]);
|
|
61511
|
+
if (c !== void 0) return formatFloat(Math.sqrt(c));
|
|
61003
61512
|
return `sqrt(${compile3(args[0])})`;
|
|
61004
61513
|
},
|
|
61005
61514
|
Step: "step",
|
|
@@ -61008,17 +61517,20 @@ var GPU_FUNCTIONS = {
|
|
|
61008
61517
|
return `_gpu_ctan(${compile3(args[0])})`;
|
|
61009
61518
|
return `tan(${compile3(args[0])})`;
|
|
61010
61519
|
},
|
|
61011
|
-
Truncate:
|
|
61520
|
+
Truncate: (args, compile3) => {
|
|
61521
|
+
if (BaseCompiler.isIntegerValued(args[0])) return compile3(args[0]);
|
|
61522
|
+
return `trunc(${compile3(args[0])})`;
|
|
61523
|
+
},
|
|
61012
61524
|
// Complex-specific functions
|
|
61013
|
-
|
|
61525
|
+
Real: (args, compile3) => {
|
|
61014
61526
|
if (BaseCompiler.isComplexValued(args[0])) return `(${compile3(args[0])}).x`;
|
|
61015
61527
|
return compile3(args[0]);
|
|
61016
61528
|
},
|
|
61017
|
-
|
|
61529
|
+
Imaginary: (args, compile3) => {
|
|
61018
61530
|
if (BaseCompiler.isComplexValued(args[0])) return `(${compile3(args[0])}).y`;
|
|
61019
61531
|
return "0.0";
|
|
61020
61532
|
},
|
|
61021
|
-
|
|
61533
|
+
Argument: (args, compile3) => {
|
|
61022
61534
|
if (BaseCompiler.isComplexValued(args[0])) {
|
|
61023
61535
|
const code = compile3(args[0]);
|
|
61024
61536
|
return `atan(${code}.y, ${code}.x)`;
|
|
@@ -61233,13 +61745,20 @@ var GPU_FUNCTIONS = {
|
|
|
61233
61745
|
},
|
|
61234
61746
|
Square: ([x], compile3) => {
|
|
61235
61747
|
if (x === null) throw new Error("Square: no argument");
|
|
61236
|
-
|
|
61237
|
-
|
|
61748
|
+
if (isSymbol2(x) || isNumber(x)) {
|
|
61749
|
+
const arg = compile3(x);
|
|
61750
|
+
return `(${arg} * ${arg})`;
|
|
61751
|
+
}
|
|
61752
|
+
return `pow(${compile3(x)}, 2.0)`;
|
|
61238
61753
|
},
|
|
61239
61754
|
Root: ([x, n], compile3) => {
|
|
61240
61755
|
if (x === null) throw new Error("Root: no argument");
|
|
61241
61756
|
if (n === null || n === void 0) return `sqrt(${compile3(x)})`;
|
|
61242
|
-
|
|
61757
|
+
const nConst = tryGetConstant(n);
|
|
61758
|
+
if (nConst === 2) return `sqrt(${compile3(x)})`;
|
|
61759
|
+
const xConst = tryGetConstant(x);
|
|
61760
|
+
if (xConst !== void 0 && nConst !== void 0)
|
|
61761
|
+
return formatFloat(Math.pow(xConst, 1 / nConst));
|
|
61243
61762
|
return `pow(${compile3(x)}, 1.0 / ${compile3(n)})`;
|
|
61244
61763
|
},
|
|
61245
61764
|
// Color functions (pure-math, GPU-compilable)
|
|
@@ -61281,18 +61800,14 @@ var GPU_FUNCTIONS = {
|
|
|
61281
61800
|
Mandelbrot: ([c, maxIter], compile3, target) => {
|
|
61282
61801
|
if (c === null || maxIter === null)
|
|
61283
61802
|
throw new Error("Mandelbrot: missing arguments");
|
|
61284
|
-
const
|
|
61285
|
-
return `_fractal_mandelbrot(${compile3(c)}, ${
|
|
61286
|
-
maxIter
|
|
61287
|
-
)}))`;
|
|
61803
|
+
const iterCode = compileIntArg(maxIter, compile3, target);
|
|
61804
|
+
return `_fractal_mandelbrot(${compile3(c)}, ${iterCode})`;
|
|
61288
61805
|
},
|
|
61289
61806
|
Julia: ([z, c, maxIter], compile3, target) => {
|
|
61290
61807
|
if (z === null || c === null || maxIter === null)
|
|
61291
61808
|
throw new Error("Julia: missing arguments");
|
|
61292
|
-
const
|
|
61293
|
-
return `_fractal_julia(${compile3(z)}, ${compile3(c)}, ${
|
|
61294
|
-
maxIter
|
|
61295
|
-
)}))`;
|
|
61809
|
+
const iterCode = compileIntArg(maxIter, compile3, target);
|
|
61810
|
+
return `_fractal_julia(${compile3(z)}, ${compile3(c)}, ${iterCode})`;
|
|
61296
61811
|
},
|
|
61297
61812
|
// Vector/Matrix operations
|
|
61298
61813
|
Cross: "cross",
|
|
@@ -63924,6 +64439,7 @@ var INTERVAL_JAVASCRIPT_OPERATORS = {
|
|
|
63924
64439
|
Add: ["_IA.add", 20],
|
|
63925
64440
|
Negate: ["_IA.negate", 20],
|
|
63926
64441
|
Subtract: ["_IA.sub", 20],
|
|
64442
|
+
// Subtract canonicalizes to Add+Negate; kept as fallback
|
|
63927
64443
|
Multiply: ["_IA.mul", 20],
|
|
63928
64444
|
Divide: ["_IA.div", 20],
|
|
63929
64445
|
// Comparisons return BoolInterval
|
|
@@ -63948,17 +64464,7 @@ var INTERVAL_JAVASCRIPT_FUNCTIONS = {
|
|
|
63948
64464
|
}
|
|
63949
64465
|
return result;
|
|
63950
64466
|
},
|
|
63951
|
-
Subtract
|
|
63952
|
-
if (args.length === 0) return "_IA.point(0)";
|
|
63953
|
-
if (args.length === 1) return `_IA.negate(${compile3(args[0])})`;
|
|
63954
|
-
if (args.length === 2)
|
|
63955
|
-
return `_IA.sub(${compile3(args[0])}, ${compile3(args[1])})`;
|
|
63956
|
-
let result = compile3(args[0]);
|
|
63957
|
-
for (let i = 1; i < args.length; i++) {
|
|
63958
|
-
result = `_IA.sub(${result}, ${compile3(args[i])})`;
|
|
63959
|
-
}
|
|
63960
|
-
return result;
|
|
63961
|
-
},
|
|
64467
|
+
// No Subtract handler — canonicalizes to Add+Negate before compilation.
|
|
63962
64468
|
Multiply: (args, compile3) => {
|
|
63963
64469
|
if (args.length === 0) return "_IA.point(1)";
|
|
63964
64470
|
if (args.length === 1) return compile3(args[0]);
|
|
@@ -64894,6 +65400,7 @@ var PYTHON_OPERATORS = {
|
|
|
64894
65400
|
Negate: ["-", 14],
|
|
64895
65401
|
// Unary operator
|
|
64896
65402
|
Subtract: ["-", 11],
|
|
65403
|
+
// Subtract canonicalizes to Add+Negate; kept as fallback
|
|
64897
65404
|
Multiply: ["*", 12],
|
|
64898
65405
|
Divide: ["/", 13],
|
|
64899
65406
|
Power: ["**", 15],
|
|
@@ -64921,16 +65428,7 @@ var PYTHON_FUNCTIONS = {
|
|
|
64921
65428
|
if (args.length === 1) return compile3(args[0]);
|
|
64922
65429
|
return args.map((x) => compile3(x)).join(" * ");
|
|
64923
65430
|
},
|
|
64924
|
-
Subtract
|
|
64925
|
-
if (args.length === 0) return "0";
|
|
64926
|
-
if (args.length === 1) return compile3(args[0]);
|
|
64927
|
-
if (args.length === 2) return `${compile3(args[0])} - ${compile3(args[1])}`;
|
|
64928
|
-
let result = compile3(args[0]);
|
|
64929
|
-
for (let i = 1; i < args.length; i++) {
|
|
64930
|
-
result = `${result} - ${compile3(args[i])}`;
|
|
64931
|
-
}
|
|
64932
|
-
return result;
|
|
64933
|
-
},
|
|
65431
|
+
// No Subtract handler — canonicalizes to Add+Negate before compilation.
|
|
64934
65432
|
Divide: (args, compile3) => {
|
|
64935
65433
|
if (args.length === 0) return "1";
|
|
64936
65434
|
if (args.length === 1) return compile3(args[0]);
|
|
@@ -67362,7 +67860,9 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
67362
67860
|
}
|
|
67363
67861
|
return new ExactNumericValue(value, makeNumericValue);
|
|
67364
67862
|
}
|
|
67365
|
-
throw Error(
|
|
67863
|
+
throw Error(
|
|
67864
|
+
`Unexpected value: ${typeof value === "object" ? JSON.stringify(value) : String(value)}`
|
|
67865
|
+
);
|
|
67366
67866
|
}
|
|
67367
67867
|
/**
|
|
67368
67868
|
* The cost function is used to determine the "cost" of an expression. For example, when simplifying an expression, the simplification that results in the lowest cost is chosen.
|
|
@@ -67833,14 +68333,14 @@ var ComputeEngine = class _ComputeEngine {
|
|
|
67833
68333
|
_setDefaultEngineFactory(() => new ComputeEngine());
|
|
67834
68334
|
|
|
67835
68335
|
// src/compute-engine.ts
|
|
67836
|
-
var version = "0.55.
|
|
68336
|
+
var version = "0.55.3";
|
|
67837
68337
|
ComputeEngine._latexSyntaxFactory = () => new LatexSyntax();
|
|
67838
68338
|
_setDefaultEngineFactory(
|
|
67839
68339
|
() => new ComputeEngine({ latexSyntax: new LatexSyntax() })
|
|
67840
68340
|
);
|
|
67841
68341
|
globalThis[/* @__PURE__ */ Symbol.for("io.cortexjs.compute-engine")] = {
|
|
67842
68342
|
ComputeEngine: ComputeEngine.prototype.constructor,
|
|
67843
|
-
version: "0.55.
|
|
68343
|
+
version: "0.55.3"
|
|
67844
68344
|
};
|
|
67845
68345
|
export {
|
|
67846
68346
|
DEFINITIONS_ALGEBRA as ALGEBRA_DICTIONARY,
|