@cortex-js/compute-engine 0.56.0 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compile.esm.js +1137 -92
- package/dist/compile.min.esm.js +261 -61
- package/dist/compile.min.umd.cjs +262 -62
- package/dist/compile.umd.cjs +1137 -92
- package/dist/compute-engine.esm.js +1751 -176
- package/dist/compute-engine.min.esm.js +273 -73
- package/dist/compute-engine.min.umd.cjs +272 -72
- package/dist/compute-engine.umd.cjs +1751 -176
- package/dist/core.esm.js +1750 -175
- package/dist/core.min.esm.js +271 -71
- package/dist/core.min.umd.cjs +271 -71
- package/dist/core.umd.cjs +1750 -175
- package/dist/interval.esm.js +357 -28
- package/dist/interval.min.esm.js +6 -6
- package/dist/interval.min.umd.cjs +6 -6
- package/dist/interval.umd.cjs +357 -28
- package/dist/latex-syntax.esm.js +398 -28
- package/dist/latex-syntax.min.esm.js +6 -6
- package/dist/latex-syntax.min.umd.cjs +6 -6
- package/dist/latex-syntax.umd.cjs +398 -28
- 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 +38 -3
- package/dist/numerics.min.esm.js +3 -3
- package/dist/numerics.min.umd.cjs +4 -4
- package/dist/numerics.umd.cjs +38 -3
- 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 +8 -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 +7 -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 +22 -10
- 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 +62 -6
- package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
- package/dist/types/compute-engine/compilation/constant-folding.d.ts +1 -1
- package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/gpu-target.d.ts +44 -1
- package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -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 +4 -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 +18 -2
- package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
- package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
- package/dist/types/compute-engine/interval/index.d.ts +1 -1
- package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
- package/dist/types/compute-engine/interval/types.d.ts +1 -1
- package/dist/types/compute-engine/interval/util.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-colors.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/types.d.ts +40 -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 +5 -3
- 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/random.d.ts +23 -0
- 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 +51 -1
- package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
- package/dist/types/compute-engine/types-expression.d.ts +69 -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
package/dist/latex-syntax.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 0.
|
|
1
|
+
/** Compute Engine 0.58.0 */
|
|
2
2
|
|
|
3
3
|
// src/math-json/utils.ts
|
|
4
4
|
var MISSING = ["Error", "'missing'"];
|
|
@@ -3126,7 +3126,42 @@ function widen2(a, b) {
|
|
|
3126
3126
|
if (b === "nothing") return a;
|
|
3127
3127
|
if (isSubtype(a, b)) return b;
|
|
3128
3128
|
if (isSubtype(b, a)) return a;
|
|
3129
|
-
|
|
3129
|
+
const sup = superType(a, b);
|
|
3130
|
+
if (LOSSY_SUPERTYPE.has(sup)) return unionTypes(a, b);
|
|
3131
|
+
return sup;
|
|
3132
|
+
}
|
|
3133
|
+
var LOSSY_SUPERTYPE = /* @__PURE__ */ new Set([
|
|
3134
|
+
"scalar",
|
|
3135
|
+
"value",
|
|
3136
|
+
"function",
|
|
3137
|
+
"expression",
|
|
3138
|
+
"collection",
|
|
3139
|
+
"indexed_collection",
|
|
3140
|
+
"list",
|
|
3141
|
+
"set",
|
|
3142
|
+
"tuple",
|
|
3143
|
+
"record",
|
|
3144
|
+
"dictionary",
|
|
3145
|
+
"map",
|
|
3146
|
+
"any"
|
|
3147
|
+
]);
|
|
3148
|
+
function unionTypes(a, b) {
|
|
3149
|
+
const members = [];
|
|
3150
|
+
const push = (t) => {
|
|
3151
|
+
if (typeof t === "object" && t.kind === "union") {
|
|
3152
|
+
for (const m of t.types) push(m);
|
|
3153
|
+
return;
|
|
3154
|
+
}
|
|
3155
|
+
const key = typeof t === "string" ? t : JSON.stringify(t);
|
|
3156
|
+
if (!members.some(
|
|
3157
|
+
(m) => (typeof m === "string" ? m : JSON.stringify(m)) === key
|
|
3158
|
+
))
|
|
3159
|
+
members.push(t);
|
|
3160
|
+
};
|
|
3161
|
+
push(a);
|
|
3162
|
+
push(b);
|
|
3163
|
+
if (members.length === 1) return members[0];
|
|
3164
|
+
return { kind: "union", types: members };
|
|
3130
3165
|
}
|
|
3131
3166
|
function narrow(...types) {
|
|
3132
3167
|
if (types.length === 0) return "nothing";
|
|
@@ -3681,6 +3716,64 @@ function parseQuantifier(kind) {
|
|
|
3681
3716
|
}
|
|
3682
3717
|
|
|
3683
3718
|
// src/compute-engine/latex-syntax/dictionary/definitions-core.ts
|
|
3719
|
+
var COMPONENT_ACCESS_HEADS = {
|
|
3720
|
+
x: "First",
|
|
3721
|
+
y: "Second",
|
|
3722
|
+
z: "Third",
|
|
3723
|
+
real: "Real",
|
|
3724
|
+
re: "Real",
|
|
3725
|
+
imag: "Imaginary",
|
|
3726
|
+
im: "Imaginary",
|
|
3727
|
+
count: "Length",
|
|
3728
|
+
total: "Sum",
|
|
3729
|
+
max: "Max",
|
|
3730
|
+
min: "Min"
|
|
3731
|
+
};
|
|
3732
|
+
function memberHead(name) {
|
|
3733
|
+
return COMPONENT_ACCESS_HEADS[name] ?? null;
|
|
3734
|
+
}
|
|
3735
|
+
function parseComponentAccess(parser, lhs) {
|
|
3736
|
+
parser.skipVisualSpace();
|
|
3737
|
+
if (parser.match("\\operatorname")) {
|
|
3738
|
+
const name = parser.parseStringGroup();
|
|
3739
|
+
if (name === null) return null;
|
|
3740
|
+
const head = memberHead(name.trim());
|
|
3741
|
+
if (head === null) return null;
|
|
3742
|
+
return [head, lhs];
|
|
3743
|
+
}
|
|
3744
|
+
const tok = parser.peek;
|
|
3745
|
+
if (typeof tok === "string" && tok.startsWith("\\")) {
|
|
3746
|
+
const bare = tok.slice(1);
|
|
3747
|
+
const head = memberHead(bare);
|
|
3748
|
+
if (head !== null) {
|
|
3749
|
+
parser.nextToken();
|
|
3750
|
+
return [head, lhs];
|
|
3751
|
+
}
|
|
3752
|
+
return null;
|
|
3753
|
+
}
|
|
3754
|
+
if (typeof tok === "string" && /^[a-zA-Z]$/.test(tok)) {
|
|
3755
|
+
const head = memberHead(tok);
|
|
3756
|
+
if (head === null) return null;
|
|
3757
|
+
parser.nextToken();
|
|
3758
|
+
return [head, lhs];
|
|
3759
|
+
}
|
|
3760
|
+
return null;
|
|
3761
|
+
}
|
|
3762
|
+
function parseWhenRestriction(parser, lhs, close) {
|
|
3763
|
+
parser.addBoundary(close);
|
|
3764
|
+
parser.skipVisualSpace();
|
|
3765
|
+
const cond = parser.parseExpression({ minPrec: 0 });
|
|
3766
|
+
if (cond === null) {
|
|
3767
|
+
parser.removeBoundary();
|
|
3768
|
+
return null;
|
|
3769
|
+
}
|
|
3770
|
+
parser.skipVisualSpace();
|
|
3771
|
+
if (!parser.matchBoundary()) {
|
|
3772
|
+
parser.removeBoundary();
|
|
3773
|
+
return null;
|
|
3774
|
+
}
|
|
3775
|
+
return ["When", lhs, cond];
|
|
3776
|
+
}
|
|
3684
3777
|
function parseSequence(parser, terminator, lhs, prec, sep) {
|
|
3685
3778
|
if (terminator && terminator.minPrec >= prec) return null;
|
|
3686
3779
|
const result = lhs ? [lhs] : ["Nothing"];
|
|
@@ -3956,15 +4049,16 @@ var DEFINITIONS_CORE = [
|
|
|
3956
4049
|
precedence: ASSIGNMENT_PRECEDENCE,
|
|
3957
4050
|
parse: parseAssign
|
|
3958
4051
|
},
|
|
3959
|
-
// General colon operator (type annotation, mapping notation)
|
|
3960
|
-
// Precedence below
|
|
3961
|
-
// and below arrows (270) so
|
|
4052
|
+
// General colon operator (type annotation, mapping notation, Desmos piecewise)
|
|
4053
|
+
// Precedence below comparisons (245) so `cond : val` (Desmos compact piecewise)
|
|
4054
|
+
// parses as `Colon(cond, val)`, and below arrows (270) so
|
|
4055
|
+
// `f: A \to B` parses as `Colon(f, To(A, B))`.
|
|
3962
4056
|
{
|
|
3963
4057
|
name: "Colon",
|
|
3964
4058
|
latexTrigger: ":",
|
|
3965
4059
|
kind: "infix",
|
|
3966
4060
|
associativity: "right",
|
|
3967
|
-
precedence:
|
|
4061
|
+
precedence: 240,
|
|
3968
4062
|
serialize: (serializer, expr) => joinLatex([
|
|
3969
4063
|
serializer.serialize(operand(expr, 1)),
|
|
3970
4064
|
"\\colon",
|
|
@@ -3975,7 +4069,7 @@ var DEFINITIONS_CORE = [
|
|
|
3975
4069
|
latexTrigger: "\\colon",
|
|
3976
4070
|
kind: "infix",
|
|
3977
4071
|
associativity: "right",
|
|
3978
|
-
precedence:
|
|
4072
|
+
precedence: 240,
|
|
3979
4073
|
parse: "Colon"
|
|
3980
4074
|
},
|
|
3981
4075
|
{
|
|
@@ -4152,6 +4246,15 @@ var DEFINITIONS_CORE = [
|
|
|
4152
4246
|
}
|
|
4153
4247
|
},
|
|
4154
4248
|
{ name: "LatexTokens", serialize: serializeLatexTokens },
|
|
4249
|
+
// Component-access postfix: expr.member (C3)
|
|
4250
|
+
// The '.' trigger is consumed before the parse function is called.
|
|
4251
|
+
// Precedence 850 > 810 (At/indexing) so .x chains tightly.
|
|
4252
|
+
{
|
|
4253
|
+
kind: "postfix",
|
|
4254
|
+
precedence: 850,
|
|
4255
|
+
latexTrigger: ["."],
|
|
4256
|
+
parse: parseComponentAccess
|
|
4257
|
+
},
|
|
4155
4258
|
{
|
|
4156
4259
|
name: "At",
|
|
4157
4260
|
kind: "postfix",
|
|
@@ -4172,6 +4275,29 @@ var DEFINITIONS_CORE = [
|
|
|
4172
4275
|
latexTrigger: ["\\left", "\\lbrack"],
|
|
4173
4276
|
parse: parseAt("\\right", "\\rbrack")
|
|
4174
4277
|
},
|
|
4278
|
+
// When-restriction: `expr\left\{cond\right\}` → `When(expr, cond)` (D3)
|
|
4279
|
+
{
|
|
4280
|
+
name: "When",
|
|
4281
|
+
kind: "postfix",
|
|
4282
|
+
precedence: 800,
|
|
4283
|
+
latexTrigger: ["\\left", "\\{"],
|
|
4284
|
+
parse: (parser, lhs) => parseWhenRestriction(parser, lhs, ["\\right", "\\}"]),
|
|
4285
|
+
serialize: (serializer, expr) => {
|
|
4286
|
+
const e = operand(expr, 1);
|
|
4287
|
+
const cond = operand(expr, 2);
|
|
4288
|
+
if (!e || !cond) return "";
|
|
4289
|
+
const clauses = operator(cond) === "And" ? operands(cond) ?? [] : [cond];
|
|
4290
|
+
const inner = clauses.map((c) => `\\left\\{${serializer.serialize(c)}\\right\\}`).join("");
|
|
4291
|
+
return `${serializer.serialize(e)}${inner}`;
|
|
4292
|
+
}
|
|
4293
|
+
},
|
|
4294
|
+
// When-restriction: bare `expr\{cond\}` → `When(expr, cond)`
|
|
4295
|
+
{
|
|
4296
|
+
kind: "postfix",
|
|
4297
|
+
precedence: 800,
|
|
4298
|
+
latexTrigger: ["\\{"],
|
|
4299
|
+
parse: (parser, lhs) => parseWhenRestriction(parser, lhs, ["\\}"])
|
|
4300
|
+
},
|
|
4175
4301
|
{
|
|
4176
4302
|
kind: "postfix",
|
|
4177
4303
|
latexTrigger: ["_"],
|
|
@@ -4254,6 +4380,29 @@ var DEFINITIONS_CORE = [
|
|
|
4254
4380
|
return "";
|
|
4255
4381
|
}
|
|
4256
4382
|
},
|
|
4383
|
+
// Additional triggers for Range: `...`, `\ldots`, and `\dots` are
|
|
4384
|
+
// equivalent to `..` when used as infix operators (e.g. `[1...9]`).
|
|
4385
|
+
// No `name` field here — names must be unique per the dictionary rules;
|
|
4386
|
+
// the first Range entry owns the name. When there is no LHS the symbol
|
|
4387
|
+
// entries near the top of the file still fire (ContinuationPlaceholder).
|
|
4388
|
+
{
|
|
4389
|
+
latexTrigger: [".", ".", "."],
|
|
4390
|
+
kind: "infix",
|
|
4391
|
+
precedence: 800,
|
|
4392
|
+
parse: parseRange
|
|
4393
|
+
},
|
|
4394
|
+
{
|
|
4395
|
+
latexTrigger: ["\\ldots"],
|
|
4396
|
+
kind: "infix",
|
|
4397
|
+
precedence: 800,
|
|
4398
|
+
parse: parseRange
|
|
4399
|
+
},
|
|
4400
|
+
{
|
|
4401
|
+
latexTrigger: ["\\dots"],
|
|
4402
|
+
kind: "infix",
|
|
4403
|
+
precedence: 800,
|
|
4404
|
+
parse: parseRange
|
|
4405
|
+
},
|
|
4257
4406
|
{
|
|
4258
4407
|
latexTrigger: [";"],
|
|
4259
4408
|
kind: "infix",
|
|
@@ -4438,13 +4587,24 @@ var DEFINITIONS_CORE = [
|
|
|
4438
4587
|
const args = operands(expr);
|
|
4439
4588
|
if (!args || args.length < 2) return "";
|
|
4440
4589
|
const body = args[0];
|
|
4441
|
-
const
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4590
|
+
const elements = args.slice(1);
|
|
4591
|
+
const allElements = elements.every((e) => operator(e) === "Element");
|
|
4592
|
+
if (!allElements) {
|
|
4593
|
+
return joinLatex([
|
|
4594
|
+
"\\operatorname{Loop}(",
|
|
4595
|
+
serializer.serialize(body),
|
|
4596
|
+
", ",
|
|
4597
|
+
serializer.serialize(elements[0]),
|
|
4598
|
+
")"
|
|
4599
|
+
]);
|
|
4600
|
+
}
|
|
4601
|
+
if (elements.length === 1) {
|
|
4602
|
+
const elem = elements[0];
|
|
4603
|
+
const index = operand(elem, 1);
|
|
4604
|
+
const coll = operand(elem, 2);
|
|
4605
|
+
if (operator(coll) === "Range") {
|
|
4606
|
+
const lo = operand(coll, 1);
|
|
4607
|
+
const hi = operand(coll, 2);
|
|
4448
4608
|
return joinLatex([
|
|
4449
4609
|
"\\text{for }",
|
|
4450
4610
|
serializer.serialize(index),
|
|
@@ -4456,13 +4616,27 @@ var DEFINITIONS_CORE = [
|
|
|
4456
4616
|
serializer.serialize(body)
|
|
4457
4617
|
]);
|
|
4458
4618
|
}
|
|
4619
|
+
return joinLatex([
|
|
4620
|
+
serializer.serialize(body),
|
|
4621
|
+
" \\operatorname{for} ",
|
|
4622
|
+
serializer.serialize(index),
|
|
4623
|
+
" = ",
|
|
4624
|
+
serializer.serialize(coll)
|
|
4625
|
+
]);
|
|
4459
4626
|
}
|
|
4627
|
+
const bindings = elements.map((elem) => {
|
|
4628
|
+
const name = operand(elem, 1);
|
|
4629
|
+
const coll = operand(elem, 2);
|
|
4630
|
+
return joinLatex([
|
|
4631
|
+
serializer.serialize(name),
|
|
4632
|
+
" = ",
|
|
4633
|
+
serializer.serialize(coll)
|
|
4634
|
+
]);
|
|
4635
|
+
}).join(", ");
|
|
4460
4636
|
return joinLatex([
|
|
4461
|
-
"\\operatorname{Loop}(",
|
|
4462
4637
|
serializer.serialize(body),
|
|
4463
|
-
"
|
|
4464
|
-
|
|
4465
|
-
")"
|
|
4638
|
+
" \\operatorname{for} ",
|
|
4639
|
+
bindings
|
|
4466
4640
|
]);
|
|
4467
4641
|
}
|
|
4468
4642
|
},
|
|
@@ -4495,6 +4669,18 @@ var DEFINITIONS_CORE = [
|
|
|
4495
4669
|
precedence: 245,
|
|
4496
4670
|
parse: (parser, until) => parseForExpression(parser, until)
|
|
4497
4671
|
},
|
|
4672
|
+
// \operatorname{for} as postfix infix (list comprehension):
|
|
4673
|
+
// `body \operatorname{for} x = L_1, y = L_2`
|
|
4674
|
+
// Precedence 19 — just below comma (20) so the body is allowed to use
|
|
4675
|
+
// any operator (including comma sequencing) up to the keyword, and the
|
|
4676
|
+
// bindings can be comma-separated below us.
|
|
4677
|
+
{
|
|
4678
|
+
symbolTrigger: "for",
|
|
4679
|
+
kind: "infix",
|
|
4680
|
+
associativity: "none",
|
|
4681
|
+
precedence: 19,
|
|
4682
|
+
parse: (parser, lhs, until) => parseForComprehension(parser, lhs, until)
|
|
4683
|
+
},
|
|
4498
4684
|
// \operatorname{break}
|
|
4499
4685
|
{
|
|
4500
4686
|
symbolTrigger: "break",
|
|
@@ -4699,7 +4885,10 @@ var DEFINITIONS_CORE = [
|
|
|
4699
4885
|
if (!sym || !parser.getSymbolType(sym).matches("function")) return null;
|
|
4700
4886
|
parser.addBoundary([")"]);
|
|
4701
4887
|
const expr = parser.parseExpression(until);
|
|
4702
|
-
if (!parser.matchBoundary())
|
|
4888
|
+
if (!parser.matchBoundary()) {
|
|
4889
|
+
parser.removeBoundary();
|
|
4890
|
+
return null;
|
|
4891
|
+
}
|
|
4703
4892
|
if (!parser.match("<}>")) return null;
|
|
4704
4893
|
return ["Derivative", lhs, expr];
|
|
4705
4894
|
}
|
|
@@ -5140,7 +5329,12 @@ function parseBrackets(parser, body) {
|
|
|
5140
5329
|
if (isEmptySequence(body)) return ["List"];
|
|
5141
5330
|
const h = operator(body);
|
|
5142
5331
|
if (h === "Range" || h === "Linspace") return body;
|
|
5143
|
-
if (h === "Sequence")
|
|
5332
|
+
if (h === "Sequence") {
|
|
5333
|
+
const elems = operands(body);
|
|
5334
|
+
const inferred = tryInferRangeFromElements(elems, parser);
|
|
5335
|
+
if (inferred) return inferred;
|
|
5336
|
+
return ["List", ...elems];
|
|
5337
|
+
}
|
|
5144
5338
|
if (h === "Delimiter") {
|
|
5145
5339
|
const delim = stringValue(operand(body, 2)) ?? "...";
|
|
5146
5340
|
if (delim === ";" || delim === ".;.") {
|
|
@@ -5153,12 +5347,37 @@ function parseBrackets(parser, body) {
|
|
|
5153
5347
|
}
|
|
5154
5348
|
if (delim === "," || delim === ".,.") {
|
|
5155
5349
|
body = operand(body, 1);
|
|
5156
|
-
if (operator(body) === "Sequence")
|
|
5350
|
+
if (operator(body) === "Sequence") {
|
|
5351
|
+
const elems = operands(body);
|
|
5352
|
+
const inferred = tryInferRangeFromElements(elems, parser);
|
|
5353
|
+
if (inferred) return inferred;
|
|
5354
|
+
return ["List", ...elems];
|
|
5355
|
+
}
|
|
5157
5356
|
return ["List", body ?? "Nothing"];
|
|
5158
5357
|
}
|
|
5159
5358
|
}
|
|
5160
5359
|
return ["List", body];
|
|
5161
5360
|
}
|
|
5361
|
+
function tryInferRangeFromElements(elems, parser) {
|
|
5362
|
+
if (elems.length < 4) return null;
|
|
5363
|
+
const penultimate = elems[elems.length - 2];
|
|
5364
|
+
if (symbol(penultimate) !== "ContinuationPlaceholder") return null;
|
|
5365
|
+
const samples = elems.slice(0, -2);
|
|
5366
|
+
const endExpr = elems[elems.length - 1];
|
|
5367
|
+
if (samples.length < 2) return null;
|
|
5368
|
+
const sampleNums = samples.map(machineValue);
|
|
5369
|
+
if (sampleNums.some((n) => n === null)) return null;
|
|
5370
|
+
const nums = sampleNums;
|
|
5371
|
+
const step = nums[nums.length - 1] - nums[nums.length - 2];
|
|
5372
|
+
const tol = parser.options.tolerance;
|
|
5373
|
+
if (Math.abs(step) < tol)
|
|
5374
|
+
return parser.error("degenerate-range-step", parser.index);
|
|
5375
|
+
for (let i = 1; i < nums.length; i++) {
|
|
5376
|
+
if (Math.abs(nums[i] - nums[i - 1] - step) > tol)
|
|
5377
|
+
return parser.error("inconsistent-range-samples", parser.index);
|
|
5378
|
+
}
|
|
5379
|
+
return ["Range", nums[0], endExpr, step];
|
|
5380
|
+
}
|
|
5162
5381
|
function serializeList(serializer, expr) {
|
|
5163
5382
|
if (nops(expr) > 1 && operands(expr).every((x) => {
|
|
5164
5383
|
const op = operator(x);
|
|
@@ -5410,6 +5629,38 @@ function parseForExpression(parser, until) {
|
|
|
5410
5629
|
["Element", index, ["Range", lower, upper]]
|
|
5411
5630
|
];
|
|
5412
5631
|
}
|
|
5632
|
+
function parseForComprehension(parser, lhs, until) {
|
|
5633
|
+
const bindingTerminator = {
|
|
5634
|
+
minPrec: 21,
|
|
5635
|
+
// Above comma (20) and ; (19), so `x = L_1` is captured whole
|
|
5636
|
+
condition: (p) => {
|
|
5637
|
+
if (until?.condition?.(p)) return true;
|
|
5638
|
+
const saved = p.index;
|
|
5639
|
+
p.skipVisualSpace();
|
|
5640
|
+
const isComma = p.peek === ",";
|
|
5641
|
+
p.index = saved;
|
|
5642
|
+
if (isComma) return true;
|
|
5643
|
+
if (peekKeyword(p, "where")) return true;
|
|
5644
|
+
if (peekKeyword(p, "with")) return true;
|
|
5645
|
+
return false;
|
|
5646
|
+
}
|
|
5647
|
+
};
|
|
5648
|
+
const elements = [];
|
|
5649
|
+
do {
|
|
5650
|
+
parser.skipVisualSpace();
|
|
5651
|
+
const binding = parser.parseExpression(bindingTerminator);
|
|
5652
|
+
if (binding === null) break;
|
|
5653
|
+
const op = operator(binding);
|
|
5654
|
+
if (op !== "Equal" && op !== "Assign") return null;
|
|
5655
|
+
const name = operand(binding, 1);
|
|
5656
|
+
const list = operand(binding, 2);
|
|
5657
|
+
if (!name || !list) return null;
|
|
5658
|
+
elements.push(["Element", name, list]);
|
|
5659
|
+
parser.skipVisualSpace();
|
|
5660
|
+
} while (parser.match(","));
|
|
5661
|
+
if (elements.length === 0) return null;
|
|
5662
|
+
return ["Loop", lhs, ...elements];
|
|
5663
|
+
}
|
|
5413
5664
|
function parseWhereExpression(parser, lhs, until) {
|
|
5414
5665
|
const bindingTerminator = {
|
|
5415
5666
|
minPrec: 21,
|
|
@@ -5432,6 +5683,25 @@ function parseWhereExpression(parser, lhs, until) {
|
|
|
5432
5683
|
parser.skipVisualSpace();
|
|
5433
5684
|
} while (parser.match(","));
|
|
5434
5685
|
if (bindings.length === 0) return null;
|
|
5686
|
+
const forStart = parser.index;
|
|
5687
|
+
if (matchKeyword(parser, "for")) {
|
|
5688
|
+
const loop = parseForComprehension(parser, lhs, until);
|
|
5689
|
+
if (loop) {
|
|
5690
|
+
const block2 = [];
|
|
5691
|
+
for (const b of bindings) {
|
|
5692
|
+
const normalized = normalizeLocalAssign(b);
|
|
5693
|
+
if (operator(normalized) === "Assign") {
|
|
5694
|
+
block2.push(["Declare", operand(normalized, 1)]);
|
|
5695
|
+
block2.push(normalized);
|
|
5696
|
+
} else {
|
|
5697
|
+
block2.push(normalized);
|
|
5698
|
+
}
|
|
5699
|
+
}
|
|
5700
|
+
block2.push(loop);
|
|
5701
|
+
return ["Block", ...block2];
|
|
5702
|
+
}
|
|
5703
|
+
parser.index = forStart;
|
|
5704
|
+
}
|
|
5435
5705
|
const block = [];
|
|
5436
5706
|
for (const b of bindings) {
|
|
5437
5707
|
const normalized = normalizeLocalAssign(b);
|
|
@@ -5645,6 +5915,17 @@ function parseIntervalBody(body, openLeft, openRight) {
|
|
|
5645
5915
|
const upperExpr = openRight ? ["Open", upper] : upper;
|
|
5646
5916
|
return ["Interval", lowerExpr, upperExpr];
|
|
5647
5917
|
}
|
|
5918
|
+
var COMPARISON_HEADS = /* @__PURE__ */ new Set([
|
|
5919
|
+
"Less",
|
|
5920
|
+
"LessEqual",
|
|
5921
|
+
"Greater",
|
|
5922
|
+
"GreaterEqual",
|
|
5923
|
+
"Equal",
|
|
5924
|
+
"NotEqual",
|
|
5925
|
+
"And",
|
|
5926
|
+
"Or",
|
|
5927
|
+
"Not"
|
|
5928
|
+
]);
|
|
5648
5929
|
var DEFINITIONS_SETS = [
|
|
5649
5930
|
//
|
|
5650
5931
|
// Constants
|
|
@@ -5903,18 +6184,58 @@ var DEFINITIONS_SETS = [
|
|
|
5903
6184
|
closeTrigger: "}",
|
|
5904
6185
|
parse: (_parser, body) => {
|
|
5905
6186
|
if (isEmptySequence(body)) return "EmptySet";
|
|
6187
|
+
if (operator(body) == "Delimiter" && stringValue(operand(body, 2)) === ",") {
|
|
6188
|
+
body = operand(body, 1);
|
|
6189
|
+
}
|
|
5906
6190
|
const h = operator(body);
|
|
5907
|
-
if (h === "Divides"
|
|
6191
|
+
if (h === "Divides") {
|
|
5908
6192
|
const expr = operand(body, 1);
|
|
5909
6193
|
const condition = operand(body, 2);
|
|
5910
6194
|
if (expr !== null && condition !== null)
|
|
5911
6195
|
return ["Set", expr, ["Condition", condition]];
|
|
5912
6196
|
}
|
|
5913
|
-
if (
|
|
5914
|
-
|
|
6197
|
+
if (h === "Colon") {
|
|
6198
|
+
const lhs = operand(body, 1);
|
|
6199
|
+
const rhs = operand(body, 2);
|
|
6200
|
+
if (lhs !== null && rhs !== null) {
|
|
6201
|
+
const lhsOp = operator(lhs);
|
|
6202
|
+
if (lhsOp !== null && COMPARISON_HEADS.has(lhsOp)) {
|
|
6203
|
+
return ["Which", lhs, rhs];
|
|
6204
|
+
}
|
|
6205
|
+
return ["Set", lhs, ["Condition", rhs]];
|
|
6206
|
+
}
|
|
6207
|
+
}
|
|
6208
|
+
if (h === "Sequence") {
|
|
6209
|
+
const elements = operands(body);
|
|
6210
|
+
const colonElements = elements.filter((el) => operator(el) === "Colon");
|
|
6211
|
+
const allPiecewise = colonElements.length > 0 && colonElements.every((el) => {
|
|
6212
|
+
const lhs = operand(el, 1);
|
|
6213
|
+
const lhsOp = lhs !== null ? operator(lhs) : null;
|
|
6214
|
+
return lhsOp !== null && COMPARISON_HEADS.has(lhsOp);
|
|
6215
|
+
});
|
|
6216
|
+
if (allPiecewise) {
|
|
6217
|
+
const whichOps = [];
|
|
6218
|
+
for (let i = 0; i < elements.length; i++) {
|
|
6219
|
+
const el = elements[i];
|
|
6220
|
+
if (operator(el) === "Colon") {
|
|
6221
|
+
const cond = operand(el, 1);
|
|
6222
|
+
const val = operand(el, 2);
|
|
6223
|
+
if (cond === null || val === null) {
|
|
6224
|
+
return ["Set", ...elements];
|
|
6225
|
+
}
|
|
6226
|
+
whichOps.push(cond, val);
|
|
6227
|
+
} else {
|
|
6228
|
+
if (i !== elements.length - 1) {
|
|
6229
|
+
return ["Set", ...elements];
|
|
6230
|
+
}
|
|
6231
|
+
whichOps.push("True", el);
|
|
6232
|
+
}
|
|
6233
|
+
}
|
|
6234
|
+
return ["Which", ...whichOps];
|
|
6235
|
+
}
|
|
6236
|
+
return ["Set", ...elements];
|
|
5915
6237
|
}
|
|
5916
|
-
|
|
5917
|
-
return ["Set", ...operands(body)];
|
|
6238
|
+
return ["Set", body];
|
|
5918
6239
|
},
|
|
5919
6240
|
serialize: (serializer, expr) => {
|
|
5920
6241
|
if (nops(expr) === 2 && operator(operand(expr, 2)) === "Condition") {
|
|
@@ -7918,7 +8239,8 @@ function parseTrig(op) {
|
|
|
7918
8239
|
minPrec: MULTIPLICATION_PRECEDENCE,
|
|
7919
8240
|
condition: (parser2) => trigCommands[parser2.peek] || (until?.condition?.(parser2) ?? false)
|
|
7920
8241
|
});
|
|
7921
|
-
const
|
|
8242
|
+
const head = fn === "Arctan" && args?.length === 2 ? "Arctan2" : fn;
|
|
8243
|
+
const appliedFn = args === null ? fn : typeof head === "string" ? [head, ...args] : ["Apply", head, ...args];
|
|
7922
8244
|
return sup === null ? appliedFn : ["Power", appliedFn, sup];
|
|
7923
8245
|
};
|
|
7924
8246
|
}
|
|
@@ -10041,10 +10363,17 @@ var DEFINITIONS_OTHERS = [
|
|
|
10041
10363
|
// The capitalized library entries already exist; these are pure parse
|
|
10042
10364
|
// aliases so the lowercase names don't land in `unsupported-operator`.
|
|
10043
10365
|
// ---------------------------------------------------------------------------
|
|
10366
|
+
{ latexTrigger: "\\operatorname{count}", parse: "Length" },
|
|
10044
10367
|
{ latexTrigger: "\\operatorname{random}", parse: "Random" },
|
|
10045
10368
|
{ latexTrigger: "\\operatorname{shuffle}", parse: "Shuffle" },
|
|
10046
10369
|
{ latexTrigger: "\\operatorname{repeat}", parse: "Repeat" },
|
|
10047
10370
|
{ latexTrigger: "\\operatorname{join}", parse: "Join" },
|
|
10371
|
+
{ latexTrigger: "\\operatorname{range}", parse: "Range" },
|
|
10372
|
+
// Note: `\operatorname{with}` (Desmos's local-binding clause) is intentionally
|
|
10373
|
+
// NOT registered here. Use the math-notation equivalent `\operatorname{where}`
|
|
10374
|
+
// (with `\coloneq` for bindings), or register `with` as a custom dictionary
|
|
10375
|
+
// entry at the integration layer — see the "Desmos-Specific Syntax — Prefer
|
|
10376
|
+
// Custom LaTeX Dictionary" section in COMPUTE_ENGINE.md for a worked example.
|
|
10048
10377
|
// ---------------------------------------------------------------------------
|
|
10049
10378
|
// Geometric primitive heads. Registered as known typed heads so consumers
|
|
10050
10379
|
// can branch on the operator name; CE itself doesn't render them. The
|
|
@@ -14466,6 +14795,19 @@ var _Parser = class __Parser {
|
|
|
14466
14795
|
} while (postfix !== null);
|
|
14467
14796
|
}
|
|
14468
14797
|
if (result !== null) result = this.parseSupsub(result);
|
|
14798
|
+
if (result !== null) {
|
|
14799
|
+
let postfix = null;
|
|
14800
|
+
let index = this.index;
|
|
14801
|
+
do {
|
|
14802
|
+
postfix = this.parsePostfixOperator(result, until);
|
|
14803
|
+
result = postfix ?? result;
|
|
14804
|
+
if (this.index === index && postfix !== null) {
|
|
14805
|
+
console.assert(this.index !== index, "No token consumed");
|
|
14806
|
+
break;
|
|
14807
|
+
}
|
|
14808
|
+
index = this.index;
|
|
14809
|
+
} while (postfix !== null);
|
|
14810
|
+
}
|
|
14469
14811
|
if (result === null) {
|
|
14470
14812
|
result = this.options.parseUnexpectedToken?.(null, this) ?? null;
|
|
14471
14813
|
if (result === null && this.peek.startsWith("\\")) {
|
|
@@ -14974,6 +15316,28 @@ function toDecimalNumber(wholePart, fractionalPart, exp) {
|
|
|
14974
15316
|
}
|
|
14975
15317
|
|
|
14976
15318
|
// src/compute-engine/latex-syntax/serializer.ts
|
|
15319
|
+
var DOT_NOTATION_MAP = {
|
|
15320
|
+
First: ".x",
|
|
15321
|
+
Second: ".y",
|
|
15322
|
+
Third: ".z",
|
|
15323
|
+
Real: ".\\operatorname{real}",
|
|
15324
|
+
Imaginary: ".\\operatorname{imag}",
|
|
15325
|
+
Length: ".\\operatorname{count}",
|
|
15326
|
+
Sum: ".\\operatorname{total}",
|
|
15327
|
+
Max: ".\\max",
|
|
15328
|
+
Min: ".\\min"
|
|
15329
|
+
};
|
|
15330
|
+
function trySerializeDotNotation(serializer, expr) {
|
|
15331
|
+
if (!serializer.options.dotNotation) return null;
|
|
15332
|
+
const ops = operands(expr);
|
|
15333
|
+
if (!ops || ops.length !== 1) return null;
|
|
15334
|
+
const head = operator(expr);
|
|
15335
|
+
if (!head) return null;
|
|
15336
|
+
const suffix = DOT_NOTATION_MAP[head];
|
|
15337
|
+
if (suffix === void 0) return null;
|
|
15338
|
+
const lhs = serializer.wrap(ops[0], 810);
|
|
15339
|
+
return `${lhs}${suffix}`;
|
|
15340
|
+
}
|
|
14977
15341
|
var ACCENT_MODIFIERS = {
|
|
14978
15342
|
deg: (s) => `${s}\\degree`,
|
|
14979
15343
|
prime: (s) => `${s}^{\\prime}`,
|
|
@@ -15017,6 +15381,7 @@ var Serializer5 = class {
|
|
|
15017
15381
|
constructor(dictionary, options) {
|
|
15018
15382
|
this.dictionary = dictionary;
|
|
15019
15383
|
this.options = {
|
|
15384
|
+
dotNotation: false,
|
|
15020
15385
|
dmsFormat: false,
|
|
15021
15386
|
angleNormalization: "none",
|
|
15022
15387
|
...options
|
|
@@ -15115,6 +15480,8 @@ var Serializer5 = class {
|
|
|
15115
15480
|
return def?.serialize?.(this, expr) ?? serializeSymbol(symbol(expr)) ?? "";
|
|
15116
15481
|
}
|
|
15117
15482
|
serializeFunction(expr, def) {
|
|
15483
|
+
const dotResult = trySerializeDotNotation(this, expr);
|
|
15484
|
+
if (dotResult !== null) return dotResult;
|
|
15118
15485
|
if (def?.serialize) return def.serialize(this, expr);
|
|
15119
15486
|
const h = operator(expr);
|
|
15120
15487
|
return serializeSymbol(h, "auto") + this.wrapArguments(expr);
|
|
@@ -15357,6 +15724,8 @@ function defaultParseOptions(opts) {
|
|
|
15357
15724
|
preserveLatex: opts.preserveLatex ?? false,
|
|
15358
15725
|
quantifierScope: opts.quantifierScope ?? "tight",
|
|
15359
15726
|
timeDerivativeVariable: opts.timeDerivativeVariable ?? "t",
|
|
15727
|
+
// Standalone mode has no engine; use the same default as ComputeEngine
|
|
15728
|
+
tolerance: 1e-7,
|
|
15360
15729
|
// Callbacks -- standalone mode has no engine, so these are stubs
|
|
15361
15730
|
getSymbolType: (_id) => BoxedType.unknown,
|
|
15362
15731
|
hasSubscriptEvaluate: (_id) => false,
|
|
@@ -15389,6 +15758,7 @@ function defaultSerializeOptions(opts) {
|
|
|
15389
15758
|
invisiblePlus: "",
|
|
15390
15759
|
multiply: "\\times",
|
|
15391
15760
|
missingSymbol: "\\blacksquare",
|
|
15761
|
+
dotNotation: false,
|
|
15392
15762
|
dmsFormat: false,
|
|
15393
15763
|
angleNormalization: "none",
|
|
15394
15764
|
// Style callbacks -- use same defaults as the engine
|
|
@@ -15457,7 +15827,7 @@ function serialize(expr) {
|
|
|
15457
15827
|
}
|
|
15458
15828
|
|
|
15459
15829
|
// src/latex-syntax.ts
|
|
15460
|
-
var version = "0.
|
|
15830
|
+
var version = "0.58.0";
|
|
15461
15831
|
export {
|
|
15462
15832
|
DEFINITIONS_ALGEBRA as ALGEBRA_DICTIONARY,
|
|
15463
15833
|
DEFINITIONS_ARITHMETIC as ARITHMETIC_DICTIONARY,
|