@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** LatexSyntax 0.
|
|
1
|
+
/** LatexSyntax 0.58.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.LatexSyntax = {}));})(this, (function (exports) { 'use strict';
|
|
3
3
|
var LatexSyntax = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -3170,7 +3170,42 @@ var LatexSyntax = (() => {
|
|
|
3170
3170
|
if (b === "nothing") return a;
|
|
3171
3171
|
if (isSubtype(a, b)) return b;
|
|
3172
3172
|
if (isSubtype(b, a)) return a;
|
|
3173
|
-
|
|
3173
|
+
const sup = superType(a, b);
|
|
3174
|
+
if (LOSSY_SUPERTYPE.has(sup)) return unionTypes(a, b);
|
|
3175
|
+
return sup;
|
|
3176
|
+
}
|
|
3177
|
+
var LOSSY_SUPERTYPE = /* @__PURE__ */ new Set([
|
|
3178
|
+
"scalar",
|
|
3179
|
+
"value",
|
|
3180
|
+
"function",
|
|
3181
|
+
"expression",
|
|
3182
|
+
"collection",
|
|
3183
|
+
"indexed_collection",
|
|
3184
|
+
"list",
|
|
3185
|
+
"set",
|
|
3186
|
+
"tuple",
|
|
3187
|
+
"record",
|
|
3188
|
+
"dictionary",
|
|
3189
|
+
"map",
|
|
3190
|
+
"any"
|
|
3191
|
+
]);
|
|
3192
|
+
function unionTypes(a, b) {
|
|
3193
|
+
const members = [];
|
|
3194
|
+
const push = (t) => {
|
|
3195
|
+
if (typeof t === "object" && t.kind === "union") {
|
|
3196
|
+
for (const m of t.types) push(m);
|
|
3197
|
+
return;
|
|
3198
|
+
}
|
|
3199
|
+
const key = typeof t === "string" ? t : JSON.stringify(t);
|
|
3200
|
+
if (!members.some(
|
|
3201
|
+
(m) => (typeof m === "string" ? m : JSON.stringify(m)) === key
|
|
3202
|
+
))
|
|
3203
|
+
members.push(t);
|
|
3204
|
+
};
|
|
3205
|
+
push(a);
|
|
3206
|
+
push(b);
|
|
3207
|
+
if (members.length === 1) return members[0];
|
|
3208
|
+
return { kind: "union", types: members };
|
|
3174
3209
|
}
|
|
3175
3210
|
function narrow(...types) {
|
|
3176
3211
|
if (types.length === 0) return "nothing";
|
|
@@ -3725,6 +3760,64 @@ var LatexSyntax = (() => {
|
|
|
3725
3760
|
}
|
|
3726
3761
|
|
|
3727
3762
|
// src/compute-engine/latex-syntax/dictionary/definitions-core.ts
|
|
3763
|
+
var COMPONENT_ACCESS_HEADS = {
|
|
3764
|
+
x: "First",
|
|
3765
|
+
y: "Second",
|
|
3766
|
+
z: "Third",
|
|
3767
|
+
real: "Real",
|
|
3768
|
+
re: "Real",
|
|
3769
|
+
imag: "Imaginary",
|
|
3770
|
+
im: "Imaginary",
|
|
3771
|
+
count: "Length",
|
|
3772
|
+
total: "Sum",
|
|
3773
|
+
max: "Max",
|
|
3774
|
+
min: "Min"
|
|
3775
|
+
};
|
|
3776
|
+
function memberHead(name) {
|
|
3777
|
+
return COMPONENT_ACCESS_HEADS[name] ?? null;
|
|
3778
|
+
}
|
|
3779
|
+
function parseComponentAccess(parser, lhs) {
|
|
3780
|
+
parser.skipVisualSpace();
|
|
3781
|
+
if (parser.match("\\operatorname")) {
|
|
3782
|
+
const name = parser.parseStringGroup();
|
|
3783
|
+
if (name === null) return null;
|
|
3784
|
+
const head = memberHead(name.trim());
|
|
3785
|
+
if (head === null) return null;
|
|
3786
|
+
return [head, lhs];
|
|
3787
|
+
}
|
|
3788
|
+
const tok = parser.peek;
|
|
3789
|
+
if (typeof tok === "string" && tok.startsWith("\\")) {
|
|
3790
|
+
const bare = tok.slice(1);
|
|
3791
|
+
const head = memberHead(bare);
|
|
3792
|
+
if (head !== null) {
|
|
3793
|
+
parser.nextToken();
|
|
3794
|
+
return [head, lhs];
|
|
3795
|
+
}
|
|
3796
|
+
return null;
|
|
3797
|
+
}
|
|
3798
|
+
if (typeof tok === "string" && /^[a-zA-Z]$/.test(tok)) {
|
|
3799
|
+
const head = memberHead(tok);
|
|
3800
|
+
if (head === null) return null;
|
|
3801
|
+
parser.nextToken();
|
|
3802
|
+
return [head, lhs];
|
|
3803
|
+
}
|
|
3804
|
+
return null;
|
|
3805
|
+
}
|
|
3806
|
+
function parseWhenRestriction(parser, lhs, close) {
|
|
3807
|
+
parser.addBoundary(close);
|
|
3808
|
+
parser.skipVisualSpace();
|
|
3809
|
+
const cond = parser.parseExpression({ minPrec: 0 });
|
|
3810
|
+
if (cond === null) {
|
|
3811
|
+
parser.removeBoundary();
|
|
3812
|
+
return null;
|
|
3813
|
+
}
|
|
3814
|
+
parser.skipVisualSpace();
|
|
3815
|
+
if (!parser.matchBoundary()) {
|
|
3816
|
+
parser.removeBoundary();
|
|
3817
|
+
return null;
|
|
3818
|
+
}
|
|
3819
|
+
return ["When", lhs, cond];
|
|
3820
|
+
}
|
|
3728
3821
|
function parseSequence(parser, terminator, lhs, prec, sep) {
|
|
3729
3822
|
if (terminator && terminator.minPrec >= prec) return null;
|
|
3730
3823
|
const result = lhs ? [lhs] : ["Nothing"];
|
|
@@ -4000,15 +4093,16 @@ var LatexSyntax = (() => {
|
|
|
4000
4093
|
precedence: ASSIGNMENT_PRECEDENCE,
|
|
4001
4094
|
parse: parseAssign
|
|
4002
4095
|
},
|
|
4003
|
-
// General colon operator (type annotation, mapping notation)
|
|
4004
|
-
// Precedence below
|
|
4005
|
-
// and below arrows (270) so
|
|
4096
|
+
// General colon operator (type annotation, mapping notation, Desmos piecewise)
|
|
4097
|
+
// Precedence below comparisons (245) so `cond : val` (Desmos compact piecewise)
|
|
4098
|
+
// parses as `Colon(cond, val)`, and below arrows (270) so
|
|
4099
|
+
// `f: A \to B` parses as `Colon(f, To(A, B))`.
|
|
4006
4100
|
{
|
|
4007
4101
|
name: "Colon",
|
|
4008
4102
|
latexTrigger: ":",
|
|
4009
4103
|
kind: "infix",
|
|
4010
4104
|
associativity: "right",
|
|
4011
|
-
precedence:
|
|
4105
|
+
precedence: 240,
|
|
4012
4106
|
serialize: (serializer, expr) => joinLatex([
|
|
4013
4107
|
serializer.serialize(operand(expr, 1)),
|
|
4014
4108
|
"\\colon",
|
|
@@ -4019,7 +4113,7 @@ var LatexSyntax = (() => {
|
|
|
4019
4113
|
latexTrigger: "\\colon",
|
|
4020
4114
|
kind: "infix",
|
|
4021
4115
|
associativity: "right",
|
|
4022
|
-
precedence:
|
|
4116
|
+
precedence: 240,
|
|
4023
4117
|
parse: "Colon"
|
|
4024
4118
|
},
|
|
4025
4119
|
{
|
|
@@ -4196,6 +4290,15 @@ var LatexSyntax = (() => {
|
|
|
4196
4290
|
}
|
|
4197
4291
|
},
|
|
4198
4292
|
{ name: "LatexTokens", serialize: serializeLatexTokens },
|
|
4293
|
+
// Component-access postfix: expr.member (C3)
|
|
4294
|
+
// The '.' trigger is consumed before the parse function is called.
|
|
4295
|
+
// Precedence 850 > 810 (At/indexing) so .x chains tightly.
|
|
4296
|
+
{
|
|
4297
|
+
kind: "postfix",
|
|
4298
|
+
precedence: 850,
|
|
4299
|
+
latexTrigger: ["."],
|
|
4300
|
+
parse: parseComponentAccess
|
|
4301
|
+
},
|
|
4199
4302
|
{
|
|
4200
4303
|
name: "At",
|
|
4201
4304
|
kind: "postfix",
|
|
@@ -4216,6 +4319,29 @@ var LatexSyntax = (() => {
|
|
|
4216
4319
|
latexTrigger: ["\\left", "\\lbrack"],
|
|
4217
4320
|
parse: parseAt("\\right", "\\rbrack")
|
|
4218
4321
|
},
|
|
4322
|
+
// When-restriction: `expr\left\{cond\right\}` → `When(expr, cond)` (D3)
|
|
4323
|
+
{
|
|
4324
|
+
name: "When",
|
|
4325
|
+
kind: "postfix",
|
|
4326
|
+
precedence: 800,
|
|
4327
|
+
latexTrigger: ["\\left", "\\{"],
|
|
4328
|
+
parse: (parser, lhs) => parseWhenRestriction(parser, lhs, ["\\right", "\\}"]),
|
|
4329
|
+
serialize: (serializer, expr) => {
|
|
4330
|
+
const e = operand(expr, 1);
|
|
4331
|
+
const cond = operand(expr, 2);
|
|
4332
|
+
if (!e || !cond) return "";
|
|
4333
|
+
const clauses = operator(cond) === "And" ? operands(cond) ?? [] : [cond];
|
|
4334
|
+
const inner = clauses.map((c) => `\\left\\{${serializer.serialize(c)}\\right\\}`).join("");
|
|
4335
|
+
return `${serializer.serialize(e)}${inner}`;
|
|
4336
|
+
}
|
|
4337
|
+
},
|
|
4338
|
+
// When-restriction: bare `expr\{cond\}` → `When(expr, cond)`
|
|
4339
|
+
{
|
|
4340
|
+
kind: "postfix",
|
|
4341
|
+
precedence: 800,
|
|
4342
|
+
latexTrigger: ["\\{"],
|
|
4343
|
+
parse: (parser, lhs) => parseWhenRestriction(parser, lhs, ["\\}"])
|
|
4344
|
+
},
|
|
4219
4345
|
{
|
|
4220
4346
|
kind: "postfix",
|
|
4221
4347
|
latexTrigger: ["_"],
|
|
@@ -4298,6 +4424,29 @@ var LatexSyntax = (() => {
|
|
|
4298
4424
|
return "";
|
|
4299
4425
|
}
|
|
4300
4426
|
},
|
|
4427
|
+
// Additional triggers for Range: `...`, `\ldots`, and `\dots` are
|
|
4428
|
+
// equivalent to `..` when used as infix operators (e.g. `[1...9]`).
|
|
4429
|
+
// No `name` field here — names must be unique per the dictionary rules;
|
|
4430
|
+
// the first Range entry owns the name. When there is no LHS the symbol
|
|
4431
|
+
// entries near the top of the file still fire (ContinuationPlaceholder).
|
|
4432
|
+
{
|
|
4433
|
+
latexTrigger: [".", ".", "."],
|
|
4434
|
+
kind: "infix",
|
|
4435
|
+
precedence: 800,
|
|
4436
|
+
parse: parseRange
|
|
4437
|
+
},
|
|
4438
|
+
{
|
|
4439
|
+
latexTrigger: ["\\ldots"],
|
|
4440
|
+
kind: "infix",
|
|
4441
|
+
precedence: 800,
|
|
4442
|
+
parse: parseRange
|
|
4443
|
+
},
|
|
4444
|
+
{
|
|
4445
|
+
latexTrigger: ["\\dots"],
|
|
4446
|
+
kind: "infix",
|
|
4447
|
+
precedence: 800,
|
|
4448
|
+
parse: parseRange
|
|
4449
|
+
},
|
|
4301
4450
|
{
|
|
4302
4451
|
latexTrigger: [";"],
|
|
4303
4452
|
kind: "infix",
|
|
@@ -4482,13 +4631,24 @@ var LatexSyntax = (() => {
|
|
|
4482
4631
|
const args = operands(expr);
|
|
4483
4632
|
if (!args || args.length < 2) return "";
|
|
4484
4633
|
const body = args[0];
|
|
4485
|
-
const
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4634
|
+
const elements = args.slice(1);
|
|
4635
|
+
const allElements = elements.every((e) => operator(e) === "Element");
|
|
4636
|
+
if (!allElements) {
|
|
4637
|
+
return joinLatex([
|
|
4638
|
+
"\\operatorname{Loop}(",
|
|
4639
|
+
serializer.serialize(body),
|
|
4640
|
+
", ",
|
|
4641
|
+
serializer.serialize(elements[0]),
|
|
4642
|
+
")"
|
|
4643
|
+
]);
|
|
4644
|
+
}
|
|
4645
|
+
if (elements.length === 1) {
|
|
4646
|
+
const elem = elements[0];
|
|
4647
|
+
const index = operand(elem, 1);
|
|
4648
|
+
const coll = operand(elem, 2);
|
|
4649
|
+
if (operator(coll) === "Range") {
|
|
4650
|
+
const lo = operand(coll, 1);
|
|
4651
|
+
const hi = operand(coll, 2);
|
|
4492
4652
|
return joinLatex([
|
|
4493
4653
|
"\\text{for }",
|
|
4494
4654
|
serializer.serialize(index),
|
|
@@ -4500,13 +4660,27 @@ var LatexSyntax = (() => {
|
|
|
4500
4660
|
serializer.serialize(body)
|
|
4501
4661
|
]);
|
|
4502
4662
|
}
|
|
4663
|
+
return joinLatex([
|
|
4664
|
+
serializer.serialize(body),
|
|
4665
|
+
" \\operatorname{for} ",
|
|
4666
|
+
serializer.serialize(index),
|
|
4667
|
+
" = ",
|
|
4668
|
+
serializer.serialize(coll)
|
|
4669
|
+
]);
|
|
4503
4670
|
}
|
|
4671
|
+
const bindings = elements.map((elem) => {
|
|
4672
|
+
const name = operand(elem, 1);
|
|
4673
|
+
const coll = operand(elem, 2);
|
|
4674
|
+
return joinLatex([
|
|
4675
|
+
serializer.serialize(name),
|
|
4676
|
+
" = ",
|
|
4677
|
+
serializer.serialize(coll)
|
|
4678
|
+
]);
|
|
4679
|
+
}).join(", ");
|
|
4504
4680
|
return joinLatex([
|
|
4505
|
-
"\\operatorname{Loop}(",
|
|
4506
4681
|
serializer.serialize(body),
|
|
4507
|
-
"
|
|
4508
|
-
|
|
4509
|
-
")"
|
|
4682
|
+
" \\operatorname{for} ",
|
|
4683
|
+
bindings
|
|
4510
4684
|
]);
|
|
4511
4685
|
}
|
|
4512
4686
|
},
|
|
@@ -4539,6 +4713,18 @@ var LatexSyntax = (() => {
|
|
|
4539
4713
|
precedence: 245,
|
|
4540
4714
|
parse: (parser, until) => parseForExpression(parser, until)
|
|
4541
4715
|
},
|
|
4716
|
+
// \operatorname{for} as postfix infix (list comprehension):
|
|
4717
|
+
// `body \operatorname{for} x = L_1, y = L_2`
|
|
4718
|
+
// Precedence 19 — just below comma (20) so the body is allowed to use
|
|
4719
|
+
// any operator (including comma sequencing) up to the keyword, and the
|
|
4720
|
+
// bindings can be comma-separated below us.
|
|
4721
|
+
{
|
|
4722
|
+
symbolTrigger: "for",
|
|
4723
|
+
kind: "infix",
|
|
4724
|
+
associativity: "none",
|
|
4725
|
+
precedence: 19,
|
|
4726
|
+
parse: (parser, lhs, until) => parseForComprehension(parser, lhs, until)
|
|
4727
|
+
},
|
|
4542
4728
|
// \operatorname{break}
|
|
4543
4729
|
{
|
|
4544
4730
|
symbolTrigger: "break",
|
|
@@ -4743,7 +4929,10 @@ var LatexSyntax = (() => {
|
|
|
4743
4929
|
if (!sym || !parser.getSymbolType(sym).matches("function")) return null;
|
|
4744
4930
|
parser.addBoundary([")"]);
|
|
4745
4931
|
const expr = parser.parseExpression(until);
|
|
4746
|
-
if (!parser.matchBoundary())
|
|
4932
|
+
if (!parser.matchBoundary()) {
|
|
4933
|
+
parser.removeBoundary();
|
|
4934
|
+
return null;
|
|
4935
|
+
}
|
|
4747
4936
|
if (!parser.match("<}>")) return null;
|
|
4748
4937
|
return ["Derivative", lhs, expr];
|
|
4749
4938
|
}
|
|
@@ -5184,7 +5373,12 @@ var LatexSyntax = (() => {
|
|
|
5184
5373
|
if (isEmptySequence(body)) return ["List"];
|
|
5185
5374
|
const h = operator(body);
|
|
5186
5375
|
if (h === "Range" || h === "Linspace") return body;
|
|
5187
|
-
if (h === "Sequence")
|
|
5376
|
+
if (h === "Sequence") {
|
|
5377
|
+
const elems = operands(body);
|
|
5378
|
+
const inferred = tryInferRangeFromElements(elems, parser);
|
|
5379
|
+
if (inferred) return inferred;
|
|
5380
|
+
return ["List", ...elems];
|
|
5381
|
+
}
|
|
5188
5382
|
if (h === "Delimiter") {
|
|
5189
5383
|
const delim = stringValue(operand(body, 2)) ?? "...";
|
|
5190
5384
|
if (delim === ";" || delim === ".;.") {
|
|
@@ -5197,12 +5391,37 @@ var LatexSyntax = (() => {
|
|
|
5197
5391
|
}
|
|
5198
5392
|
if (delim === "," || delim === ".,.") {
|
|
5199
5393
|
body = operand(body, 1);
|
|
5200
|
-
if (operator(body) === "Sequence")
|
|
5394
|
+
if (operator(body) === "Sequence") {
|
|
5395
|
+
const elems = operands(body);
|
|
5396
|
+
const inferred = tryInferRangeFromElements(elems, parser);
|
|
5397
|
+
if (inferred) return inferred;
|
|
5398
|
+
return ["List", ...elems];
|
|
5399
|
+
}
|
|
5201
5400
|
return ["List", body ?? "Nothing"];
|
|
5202
5401
|
}
|
|
5203
5402
|
}
|
|
5204
5403
|
return ["List", body];
|
|
5205
5404
|
}
|
|
5405
|
+
function tryInferRangeFromElements(elems, parser) {
|
|
5406
|
+
if (elems.length < 4) return null;
|
|
5407
|
+
const penultimate = elems[elems.length - 2];
|
|
5408
|
+
if (symbol(penultimate) !== "ContinuationPlaceholder") return null;
|
|
5409
|
+
const samples = elems.slice(0, -2);
|
|
5410
|
+
const endExpr = elems[elems.length - 1];
|
|
5411
|
+
if (samples.length < 2) return null;
|
|
5412
|
+
const sampleNums = samples.map(machineValue);
|
|
5413
|
+
if (sampleNums.some((n) => n === null)) return null;
|
|
5414
|
+
const nums = sampleNums;
|
|
5415
|
+
const step = nums[nums.length - 1] - nums[nums.length - 2];
|
|
5416
|
+
const tol = parser.options.tolerance;
|
|
5417
|
+
if (Math.abs(step) < tol)
|
|
5418
|
+
return parser.error("degenerate-range-step", parser.index);
|
|
5419
|
+
for (let i = 1; i < nums.length; i++) {
|
|
5420
|
+
if (Math.abs(nums[i] - nums[i - 1] - step) > tol)
|
|
5421
|
+
return parser.error("inconsistent-range-samples", parser.index);
|
|
5422
|
+
}
|
|
5423
|
+
return ["Range", nums[0], endExpr, step];
|
|
5424
|
+
}
|
|
5206
5425
|
function serializeList(serializer, expr) {
|
|
5207
5426
|
if (nops(expr) > 1 && operands(expr).every((x) => {
|
|
5208
5427
|
const op = operator(x);
|
|
@@ -5454,6 +5673,38 @@ var LatexSyntax = (() => {
|
|
|
5454
5673
|
["Element", index, ["Range", lower, upper]]
|
|
5455
5674
|
];
|
|
5456
5675
|
}
|
|
5676
|
+
function parseForComprehension(parser, lhs, until) {
|
|
5677
|
+
const bindingTerminator = {
|
|
5678
|
+
minPrec: 21,
|
|
5679
|
+
// Above comma (20) and ; (19), so `x = L_1` is captured whole
|
|
5680
|
+
condition: (p) => {
|
|
5681
|
+
if (until?.condition?.(p)) return true;
|
|
5682
|
+
const saved = p.index;
|
|
5683
|
+
p.skipVisualSpace();
|
|
5684
|
+
const isComma = p.peek === ",";
|
|
5685
|
+
p.index = saved;
|
|
5686
|
+
if (isComma) return true;
|
|
5687
|
+
if (peekKeyword(p, "where")) return true;
|
|
5688
|
+
if (peekKeyword(p, "with")) return true;
|
|
5689
|
+
return false;
|
|
5690
|
+
}
|
|
5691
|
+
};
|
|
5692
|
+
const elements = [];
|
|
5693
|
+
do {
|
|
5694
|
+
parser.skipVisualSpace();
|
|
5695
|
+
const binding = parser.parseExpression(bindingTerminator);
|
|
5696
|
+
if (binding === null) break;
|
|
5697
|
+
const op = operator(binding);
|
|
5698
|
+
if (op !== "Equal" && op !== "Assign") return null;
|
|
5699
|
+
const name = operand(binding, 1);
|
|
5700
|
+
const list = operand(binding, 2);
|
|
5701
|
+
if (!name || !list) return null;
|
|
5702
|
+
elements.push(["Element", name, list]);
|
|
5703
|
+
parser.skipVisualSpace();
|
|
5704
|
+
} while (parser.match(","));
|
|
5705
|
+
if (elements.length === 0) return null;
|
|
5706
|
+
return ["Loop", lhs, ...elements];
|
|
5707
|
+
}
|
|
5457
5708
|
function parseWhereExpression(parser, lhs, until) {
|
|
5458
5709
|
const bindingTerminator = {
|
|
5459
5710
|
minPrec: 21,
|
|
@@ -5476,6 +5727,25 @@ var LatexSyntax = (() => {
|
|
|
5476
5727
|
parser.skipVisualSpace();
|
|
5477
5728
|
} while (parser.match(","));
|
|
5478
5729
|
if (bindings.length === 0) return null;
|
|
5730
|
+
const forStart = parser.index;
|
|
5731
|
+
if (matchKeyword(parser, "for")) {
|
|
5732
|
+
const loop = parseForComprehension(parser, lhs, until);
|
|
5733
|
+
if (loop) {
|
|
5734
|
+
const block2 = [];
|
|
5735
|
+
for (const b of bindings) {
|
|
5736
|
+
const normalized = normalizeLocalAssign(b);
|
|
5737
|
+
if (operator(normalized) === "Assign") {
|
|
5738
|
+
block2.push(["Declare", operand(normalized, 1)]);
|
|
5739
|
+
block2.push(normalized);
|
|
5740
|
+
} else {
|
|
5741
|
+
block2.push(normalized);
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
block2.push(loop);
|
|
5745
|
+
return ["Block", ...block2];
|
|
5746
|
+
}
|
|
5747
|
+
parser.index = forStart;
|
|
5748
|
+
}
|
|
5479
5749
|
const block = [];
|
|
5480
5750
|
for (const b of bindings) {
|
|
5481
5751
|
const normalized = normalizeLocalAssign(b);
|
|
@@ -5689,6 +5959,17 @@ var LatexSyntax = (() => {
|
|
|
5689
5959
|
const upperExpr = openRight ? ["Open", upper] : upper;
|
|
5690
5960
|
return ["Interval", lowerExpr, upperExpr];
|
|
5691
5961
|
}
|
|
5962
|
+
var COMPARISON_HEADS = /* @__PURE__ */ new Set([
|
|
5963
|
+
"Less",
|
|
5964
|
+
"LessEqual",
|
|
5965
|
+
"Greater",
|
|
5966
|
+
"GreaterEqual",
|
|
5967
|
+
"Equal",
|
|
5968
|
+
"NotEqual",
|
|
5969
|
+
"And",
|
|
5970
|
+
"Or",
|
|
5971
|
+
"Not"
|
|
5972
|
+
]);
|
|
5692
5973
|
var DEFINITIONS_SETS = [
|
|
5693
5974
|
//
|
|
5694
5975
|
// Constants
|
|
@@ -5947,18 +6228,58 @@ var LatexSyntax = (() => {
|
|
|
5947
6228
|
closeTrigger: "}",
|
|
5948
6229
|
parse: (_parser, body) => {
|
|
5949
6230
|
if (isEmptySequence(body)) return "EmptySet";
|
|
6231
|
+
if (operator(body) == "Delimiter" && stringValue(operand(body, 2)) === ",") {
|
|
6232
|
+
body = operand(body, 1);
|
|
6233
|
+
}
|
|
5950
6234
|
const h = operator(body);
|
|
5951
|
-
if (h === "Divides"
|
|
6235
|
+
if (h === "Divides") {
|
|
5952
6236
|
const expr = operand(body, 1);
|
|
5953
6237
|
const condition = operand(body, 2);
|
|
5954
6238
|
if (expr !== null && condition !== null)
|
|
5955
6239
|
return ["Set", expr, ["Condition", condition]];
|
|
5956
6240
|
}
|
|
5957
|
-
if (
|
|
5958
|
-
|
|
6241
|
+
if (h === "Colon") {
|
|
6242
|
+
const lhs = operand(body, 1);
|
|
6243
|
+
const rhs = operand(body, 2);
|
|
6244
|
+
if (lhs !== null && rhs !== null) {
|
|
6245
|
+
const lhsOp = operator(lhs);
|
|
6246
|
+
if (lhsOp !== null && COMPARISON_HEADS.has(lhsOp)) {
|
|
6247
|
+
return ["Which", lhs, rhs];
|
|
6248
|
+
}
|
|
6249
|
+
return ["Set", lhs, ["Condition", rhs]];
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
if (h === "Sequence") {
|
|
6253
|
+
const elements = operands(body);
|
|
6254
|
+
const colonElements = elements.filter((el) => operator(el) === "Colon");
|
|
6255
|
+
const allPiecewise = colonElements.length > 0 && colonElements.every((el) => {
|
|
6256
|
+
const lhs = operand(el, 1);
|
|
6257
|
+
const lhsOp = lhs !== null ? operator(lhs) : null;
|
|
6258
|
+
return lhsOp !== null && COMPARISON_HEADS.has(lhsOp);
|
|
6259
|
+
});
|
|
6260
|
+
if (allPiecewise) {
|
|
6261
|
+
const whichOps = [];
|
|
6262
|
+
for (let i = 0; i < elements.length; i++) {
|
|
6263
|
+
const el = elements[i];
|
|
6264
|
+
if (operator(el) === "Colon") {
|
|
6265
|
+
const cond = operand(el, 1);
|
|
6266
|
+
const val = operand(el, 2);
|
|
6267
|
+
if (cond === null || val === null) {
|
|
6268
|
+
return ["Set", ...elements];
|
|
6269
|
+
}
|
|
6270
|
+
whichOps.push(cond, val);
|
|
6271
|
+
} else {
|
|
6272
|
+
if (i !== elements.length - 1) {
|
|
6273
|
+
return ["Set", ...elements];
|
|
6274
|
+
}
|
|
6275
|
+
whichOps.push("True", el);
|
|
6276
|
+
}
|
|
6277
|
+
}
|
|
6278
|
+
return ["Which", ...whichOps];
|
|
6279
|
+
}
|
|
6280
|
+
return ["Set", ...elements];
|
|
5959
6281
|
}
|
|
5960
|
-
|
|
5961
|
-
return ["Set", ...operands(body)];
|
|
6282
|
+
return ["Set", body];
|
|
5962
6283
|
},
|
|
5963
6284
|
serialize: (serializer, expr) => {
|
|
5964
6285
|
if (nops(expr) === 2 && operator(operand(expr, 2)) === "Condition") {
|
|
@@ -7962,7 +8283,8 @@ var LatexSyntax = (() => {
|
|
|
7962
8283
|
minPrec: MULTIPLICATION_PRECEDENCE,
|
|
7963
8284
|
condition: (parser2) => trigCommands[parser2.peek] || (until?.condition?.(parser2) ?? false)
|
|
7964
8285
|
});
|
|
7965
|
-
const
|
|
8286
|
+
const head = fn === "Arctan" && args?.length === 2 ? "Arctan2" : fn;
|
|
8287
|
+
const appliedFn = args === null ? fn : typeof head === "string" ? [head, ...args] : ["Apply", head, ...args];
|
|
7966
8288
|
return sup === null ? appliedFn : ["Power", appliedFn, sup];
|
|
7967
8289
|
};
|
|
7968
8290
|
}
|
|
@@ -10085,10 +10407,17 @@ var LatexSyntax = (() => {
|
|
|
10085
10407
|
// The capitalized library entries already exist; these are pure parse
|
|
10086
10408
|
// aliases so the lowercase names don't land in `unsupported-operator`.
|
|
10087
10409
|
// ---------------------------------------------------------------------------
|
|
10410
|
+
{ latexTrigger: "\\operatorname{count}", parse: "Length" },
|
|
10088
10411
|
{ latexTrigger: "\\operatorname{random}", parse: "Random" },
|
|
10089
10412
|
{ latexTrigger: "\\operatorname{shuffle}", parse: "Shuffle" },
|
|
10090
10413
|
{ latexTrigger: "\\operatorname{repeat}", parse: "Repeat" },
|
|
10091
10414
|
{ latexTrigger: "\\operatorname{join}", parse: "Join" },
|
|
10415
|
+
{ latexTrigger: "\\operatorname{range}", parse: "Range" },
|
|
10416
|
+
// Note: `\operatorname{with}` (Desmos's local-binding clause) is intentionally
|
|
10417
|
+
// NOT registered here. Use the math-notation equivalent `\operatorname{where}`
|
|
10418
|
+
// (with `\coloneq` for bindings), or register `with` as a custom dictionary
|
|
10419
|
+
// entry at the integration layer — see the "Desmos-Specific Syntax — Prefer
|
|
10420
|
+
// Custom LaTeX Dictionary" section in COMPUTE_ENGINE.md for a worked example.
|
|
10092
10421
|
// ---------------------------------------------------------------------------
|
|
10093
10422
|
// Geometric primitive heads. Registered as known typed heads so consumers
|
|
10094
10423
|
// can branch on the operator name; CE itself doesn't render them. The
|
|
@@ -14510,6 +14839,19 @@ var LatexSyntax = (() => {
|
|
|
14510
14839
|
} while (postfix !== null);
|
|
14511
14840
|
}
|
|
14512
14841
|
if (result !== null) result = this.parseSupsub(result);
|
|
14842
|
+
if (result !== null) {
|
|
14843
|
+
let postfix = null;
|
|
14844
|
+
let index = this.index;
|
|
14845
|
+
do {
|
|
14846
|
+
postfix = this.parsePostfixOperator(result, until);
|
|
14847
|
+
result = postfix ?? result;
|
|
14848
|
+
if (this.index === index && postfix !== null) {
|
|
14849
|
+
console.assert(this.index !== index, "No token consumed");
|
|
14850
|
+
break;
|
|
14851
|
+
}
|
|
14852
|
+
index = this.index;
|
|
14853
|
+
} while (postfix !== null);
|
|
14854
|
+
}
|
|
14513
14855
|
if (result === null) {
|
|
14514
14856
|
result = this.options.parseUnexpectedToken?.(null, this) ?? null;
|
|
14515
14857
|
if (result === null && this.peek.startsWith("\\")) {
|
|
@@ -15018,6 +15360,28 @@ var LatexSyntax = (() => {
|
|
|
15018
15360
|
}
|
|
15019
15361
|
|
|
15020
15362
|
// src/compute-engine/latex-syntax/serializer.ts
|
|
15363
|
+
var DOT_NOTATION_MAP = {
|
|
15364
|
+
First: ".x",
|
|
15365
|
+
Second: ".y",
|
|
15366
|
+
Third: ".z",
|
|
15367
|
+
Real: ".\\operatorname{real}",
|
|
15368
|
+
Imaginary: ".\\operatorname{imag}",
|
|
15369
|
+
Length: ".\\operatorname{count}",
|
|
15370
|
+
Sum: ".\\operatorname{total}",
|
|
15371
|
+
Max: ".\\max",
|
|
15372
|
+
Min: ".\\min"
|
|
15373
|
+
};
|
|
15374
|
+
function trySerializeDotNotation(serializer, expr) {
|
|
15375
|
+
if (!serializer.options.dotNotation) return null;
|
|
15376
|
+
const ops = operands(expr);
|
|
15377
|
+
if (!ops || ops.length !== 1) return null;
|
|
15378
|
+
const head = operator(expr);
|
|
15379
|
+
if (!head) return null;
|
|
15380
|
+
const suffix = DOT_NOTATION_MAP[head];
|
|
15381
|
+
if (suffix === void 0) return null;
|
|
15382
|
+
const lhs = serializer.wrap(ops[0], 810);
|
|
15383
|
+
return `${lhs}${suffix}`;
|
|
15384
|
+
}
|
|
15021
15385
|
var ACCENT_MODIFIERS = {
|
|
15022
15386
|
deg: (s) => `${s}\\degree`,
|
|
15023
15387
|
prime: (s) => `${s}^{\\prime}`,
|
|
@@ -15061,6 +15425,7 @@ var LatexSyntax = (() => {
|
|
|
15061
15425
|
constructor(dictionary, options) {
|
|
15062
15426
|
this.dictionary = dictionary;
|
|
15063
15427
|
this.options = {
|
|
15428
|
+
dotNotation: false,
|
|
15064
15429
|
dmsFormat: false,
|
|
15065
15430
|
angleNormalization: "none",
|
|
15066
15431
|
...options
|
|
@@ -15159,6 +15524,8 @@ var LatexSyntax = (() => {
|
|
|
15159
15524
|
return def?.serialize?.(this, expr) ?? serializeSymbol(symbol(expr)) ?? "";
|
|
15160
15525
|
}
|
|
15161
15526
|
serializeFunction(expr, def) {
|
|
15527
|
+
const dotResult = trySerializeDotNotation(this, expr);
|
|
15528
|
+
if (dotResult !== null) return dotResult;
|
|
15162
15529
|
if (def?.serialize) return def.serialize(this, expr);
|
|
15163
15530
|
const h = operator(expr);
|
|
15164
15531
|
return serializeSymbol(h, "auto") + this.wrapArguments(expr);
|
|
@@ -15401,6 +15768,8 @@ var LatexSyntax = (() => {
|
|
|
15401
15768
|
preserveLatex: opts.preserveLatex ?? false,
|
|
15402
15769
|
quantifierScope: opts.quantifierScope ?? "tight",
|
|
15403
15770
|
timeDerivativeVariable: opts.timeDerivativeVariable ?? "t",
|
|
15771
|
+
// Standalone mode has no engine; use the same default as ComputeEngine
|
|
15772
|
+
tolerance: 1e-7,
|
|
15404
15773
|
// Callbacks -- standalone mode has no engine, so these are stubs
|
|
15405
15774
|
getSymbolType: (_id) => BoxedType.unknown,
|
|
15406
15775
|
hasSubscriptEvaluate: (_id) => false,
|
|
@@ -15433,6 +15802,7 @@ var LatexSyntax = (() => {
|
|
|
15433
15802
|
invisiblePlus: "",
|
|
15434
15803
|
multiply: "\\times",
|
|
15435
15804
|
missingSymbol: "\\blacksquare",
|
|
15805
|
+
dotNotation: false,
|
|
15436
15806
|
dmsFormat: false,
|
|
15437
15807
|
angleNormalization: "none",
|
|
15438
15808
|
// Style callbacks -- use same defaults as the engine
|
|
@@ -15501,7 +15871,7 @@ var LatexSyntax = (() => {
|
|
|
15501
15871
|
}
|
|
15502
15872
|
|
|
15503
15873
|
// src/latex-syntax.ts
|
|
15504
|
-
var version = "0.
|
|
15874
|
+
var version = "0.58.0";
|
|
15505
15875
|
return __toCommonJS(latex_syntax_exports);
|
|
15506
15876
|
})();
|
|
15507
15877
|
Object.assign(exports, LatexSyntax); Object.defineProperty(exports, '__esModule', { value: true });}));
|
package/dist/math-json.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
|
function isNumberObject(expr) {
|
|
@@ -115,7 +115,7 @@ function expressionToDictionaryValue(expr) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
// src/math-json.ts
|
|
118
|
-
var version = "0.
|
|
118
|
+
var version = "0.58.0";
|
|
119
119
|
export {
|
|
120
120
|
dictionaryFromExpression,
|
|
121
121
|
isFunctionObject,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** Compute Engine 0.
|
|
2
|
-
function b(n){return n!==null&&typeof n=="object"&&"num"in n}function s(n){return n!==null&&typeof n=="object"&&"sym"in n}function f(n){return n!==null&&typeof n=="object"&&"str"in n}function M(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function r(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):j(n)||y(n)?null:n}function l(n){return Array.isArray(n)?n[0]:n==null?"":r(n)?n.fn[0]:""}function h(n){return Array.isArray(n)?n.slice(1):n!==void 0&&r(n)?n.fn.slice(1):[]}function d(n,t){return Array.isArray(n)?n[t]??null:n===null||!r(n)?null:n.fn[t]??null}function J(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):r(n)?Math.max(0,n.fn.length-1):0}function m(n){return typeof n=="string"&&y(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:s(n)?n.sym:null}function a(n){let t=l(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,o]=h(n),e=c(i);return e?[e,o??"Nothing"]:null}return null}function E(n){if(n===null)return null;if(M(n))return n;let t=a(n);if(t)return{[t[0]]:t[1]};if(l(n)==="Dictionary"){let i={},o=h(n);for(let e=1;e<J(n);e++){let u=a(o[e]);u&&(i[u[0]]=O(u[1])??"Nothing")}return{dict:i}}return null}function g(n,t){let i=null;if(Array.isArray(n)&&(i=n),r(n)&&(i=n.fn),i===null)return[];let o=1,e=[];for(;o<i.length;)e.push(t(i[o])),o+=1;return e}function j(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function y(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}function O(n){return n==null?null:f(n)?n.str:b(n)?parseFloat(n.num):s(n)?n.sym:typeof n=="string"||typeof n=="number"?n:Array.isArray(n)?{fn:n}:n}var S="0.
|
|
1
|
+
/** Compute Engine 0.58.0 */
|
|
2
|
+
function b(n){return n!==null&&typeof n=="object"&&"num"in n}function s(n){return n!==null&&typeof n=="object"&&"sym"in n}function f(n){return n!==null&&typeof n=="object"&&"str"in n}function M(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function r(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):j(n)||y(n)?null:n}function l(n){return Array.isArray(n)?n[0]:n==null?"":r(n)?n.fn[0]:""}function h(n){return Array.isArray(n)?n.slice(1):n!==void 0&&r(n)?n.fn.slice(1):[]}function d(n,t){return Array.isArray(n)?n[t]??null:n===null||!r(n)?null:n.fn[t]??null}function J(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):r(n)?Math.max(0,n.fn.length-1):0}function m(n){return typeof n=="string"&&y(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:s(n)?n.sym:null}function a(n){let t=l(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,o]=h(n),e=c(i);return e?[e,o??"Nothing"]:null}return null}function E(n){if(n===null)return null;if(M(n))return n;let t=a(n);if(t)return{[t[0]]:t[1]};if(l(n)==="Dictionary"){let i={},o=h(n);for(let e=1;e<J(n);e++){let u=a(o[e]);u&&(i[u[0]]=O(u[1])??"Nothing")}return{dict:i}}return null}function g(n,t){let i=null;if(Array.isArray(n)&&(i=n),r(n)&&(i=n.fn),i===null)return[];let o=1,e=[];for(;o<i.length;)e.push(t(i[o])),o+=1;return e}function j(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function y(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}function O(n){return n==null?null:f(n)?n.str:b(n)?parseFloat(n.num):s(n)?n.sym:typeof n=="string"||typeof n=="number"?n:Array.isArray(n)?{fn:n}:n}var S="0.58.0";export{E as dictionaryFromExpression,r as isFunctionObject,f as isStringObject,s as isSymbolObject,g as mapArgs,d as operand,l as operator,c as stringValue,m as symbol,S as version};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** MathJSON 0.
|
|
1
|
+
/** MathJSON 0.58.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
|
|
3
|
-
var MathJson=(()=>{var a=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var O=(n,t)=>{for(var i in t)a(n,i,{get:t[i],enumerable:!0})},A=(n,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of g(t))!j.call(n,e)&&e!==i&&a(n,e,{get:()=>t[e],enumerable:!(o=E(t,e))||o.enumerable});return n};var S=n=>A(a({},"__esModule",{value:!0}),n);var T={};O(T,{dictionaryFromExpression:()=>d,isFunctionObject:()=>r,isStringObject:()=>f,isSymbolObject:()=>u,mapArgs:()=>J,operand:()=>b,operator:()=>s,stringValue:()=>c,symbol:()=>M,version:()=>V});function N(n){return n!==null&&typeof n=="object"&&"num"in n}function u(n){return n!==null&&typeof n=="object"&&"sym"in n}function f(n){return n!==null&&typeof n=="object"&&"str"in n}function p(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function r(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):k(n)||m(n)?null:n}function s(n){return Array.isArray(n)?n[0]:n==null?"":r(n)?n.fn[0]:""}function y(n){return Array.isArray(n)?n.slice(1):n!==void 0&&r(n)?n.fn.slice(1):[]}function b(n,t){return Array.isArray(n)?n[t]??null:n===null||!r(n)?null:n.fn[t]??null}function D(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):r(n)?Math.max(0,n.fn.length-1):0}function M(n){return typeof n=="string"&&m(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:u(n)?n.sym:null}function h(n){let t=s(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,o]=y(n),e=c(i);return e?[e,o??"Nothing"]:null}return null}function d(n){if(n===null)return null;if(p(n))return n;let t=h(n);if(t)return{[t[0]]:t[1]};if(s(n)==="Dictionary"){let i={},o=y(n);for(let e=1;e<D(n);e++){let l=h(o[e]);l&&(i[l[0]]=F(l[1])??"Nothing")}return{dict:i}}return null}function J(n,t){let i=null;if(Array.isArray(n)&&(i=n),r(n)&&(i=n.fn),i===null)return[];let o=1,e=[];for(;o<i.length;)e.push(t(i[o])),o+=1;return e}function k(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function m(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}function F(n){return n==null?null:f(n)?n.str:N(n)?parseFloat(n.num):u(n)?n.sym:typeof n=="string"||typeof n=="number"?n:Array.isArray(n)?{fn:n}:n}var V="0.
|
|
3
|
+
var MathJson=(()=>{var a=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var O=(n,t)=>{for(var i in t)a(n,i,{get:t[i],enumerable:!0})},A=(n,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of g(t))!j.call(n,e)&&e!==i&&a(n,e,{get:()=>t[e],enumerable:!(o=E(t,e))||o.enumerable});return n};var S=n=>A(a({},"__esModule",{value:!0}),n);var T={};O(T,{dictionaryFromExpression:()=>d,isFunctionObject:()=>r,isStringObject:()=>f,isSymbolObject:()=>u,mapArgs:()=>J,operand:()=>b,operator:()=>s,stringValue:()=>c,symbol:()=>M,version:()=>V});function N(n){return n!==null&&typeof n=="object"&&"num"in n}function u(n){return n!==null&&typeof n=="object"&&"sym"in n}function f(n){return n!==null&&typeof n=="object"&&"str"in n}function p(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function r(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):k(n)||m(n)?null:n}function s(n){return Array.isArray(n)?n[0]:n==null?"":r(n)?n.fn[0]:""}function y(n){return Array.isArray(n)?n.slice(1):n!==void 0&&r(n)?n.fn.slice(1):[]}function b(n,t){return Array.isArray(n)?n[t]??null:n===null||!r(n)?null:n.fn[t]??null}function D(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):r(n)?Math.max(0,n.fn.length-1):0}function M(n){return typeof n=="string"&&m(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:u(n)?n.sym:null}function h(n){let t=s(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,o]=y(n),e=c(i);return e?[e,o??"Nothing"]:null}return null}function d(n){if(n===null)return null;if(p(n))return n;let t=h(n);if(t)return{[t[0]]:t[1]};if(s(n)==="Dictionary"){let i={},o=y(n);for(let e=1;e<D(n);e++){let l=h(o[e]);l&&(i[l[0]]=F(l[1])??"Nothing")}return{dict:i}}return null}function J(n,t){let i=null;if(Array.isArray(n)&&(i=n),r(n)&&(i=n.fn),i===null)return[];let o=1,e=[];for(;o<i.length;)e.push(t(i[o])),o+=1;return e}function k(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function m(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}function F(n){return n==null?null:f(n)?n.str:N(n)?parseFloat(n.num):u(n)?n.sym:typeof n=="string"||typeof n=="number"?n:Array.isArray(n)?{fn:n}:n}var V="0.58.0";return S(T);})();
|
|
4
4
|
Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
|