@cortex-js/compute-engine 0.55.0 → 0.55.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/dist/compile.esm.js +2498 -2108
  2. package/dist/compile.min.esm.js +48 -48
  3. package/dist/compile.min.umd.cjs +49 -49
  4. package/dist/compile.umd.cjs +2498 -2108
  5. package/dist/compute-engine.esm.js +1219 -719
  6. package/dist/compute-engine.min.esm.js +73 -73
  7. package/dist/compute-engine.min.umd.cjs +73 -73
  8. package/dist/compute-engine.umd.cjs +1219 -719
  9. package/dist/core.esm.js +1223 -715
  10. package/dist/core.min.esm.js +72 -72
  11. package/dist/core.min.umd.cjs +72 -72
  12. package/dist/core.umd.cjs +1223 -715
  13. package/dist/interval.esm.js +1564 -1412
  14. package/dist/interval.min.esm.js +6 -6
  15. package/dist/interval.min.umd.cjs +6 -6
  16. package/dist/interval.umd.cjs +1564 -1412
  17. package/dist/latex-syntax.esm.js +673 -492
  18. package/dist/latex-syntax.min.esm.js +6 -6
  19. package/dist/latex-syntax.min.umd.cjs +6 -6
  20. package/dist/latex-syntax.umd.cjs +673 -492
  21. package/dist/math-json.esm.js +2 -2
  22. package/dist/math-json.min.esm.js +2 -2
  23. package/dist/math-json.min.umd.cjs +2 -2
  24. package/dist/math-json.umd.cjs +2 -2
  25. package/dist/numerics.esm.js +2 -2
  26. package/dist/numerics.min.esm.js +2 -2
  27. package/dist/numerics.min.umd.cjs +2 -2
  28. package/dist/numerics.umd.cjs +2 -2
  29. package/dist/types/big-decimal/big-decimal.d.ts +1 -1
  30. package/dist/types/big-decimal/index.d.ts +1 -1
  31. package/dist/types/big-decimal/transcendentals.d.ts +1 -1
  32. package/dist/types/big-decimal/utils.d.ts +1 -1
  33. package/dist/types/common/ansi-codes.d.ts +1 -1
  34. package/dist/types/common/configuration-change.d.ts +1 -1
  35. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  36. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  37. package/dist/types/common/interruptible.d.ts +1 -1
  38. package/dist/types/common/one-of.d.ts +1 -1
  39. package/dist/types/common/signals.d.ts +1 -1
  40. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  41. package/dist/types/common/type/boxed-type.d.ts +1 -1
  42. package/dist/types/common/type/lexer.d.ts +1 -1
  43. package/dist/types/common/type/parse.d.ts +1 -1
  44. package/dist/types/common/type/parser.d.ts +1 -1
  45. package/dist/types/common/type/primitive.d.ts +1 -1
  46. package/dist/types/common/type/reduce.d.ts +1 -1
  47. package/dist/types/common/type/serialize.d.ts +1 -1
  48. package/dist/types/common/type/subtype.d.ts +1 -1
  49. package/dist/types/common/type/type-builder.d.ts +1 -1
  50. package/dist/types/common/type/types.d.ts +1 -1
  51. package/dist/types/common/type/utils.d.ts +1 -1
  52. package/dist/types/common/utils.d.ts +1 -1
  53. package/dist/types/compile.d.ts +1 -1
  54. package/dist/types/compute-engine/assume.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  82. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  87. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  88. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  89. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  90. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  91. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  92. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  93. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  94. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  95. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  96. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  97. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  98. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  99. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  100. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  101. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  102. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  103. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  104. package/dist/types/compute-engine/compilation/base-compiler.d.ts +8 -7
  105. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  106. package/dist/types/compute-engine/compilation/constant-folding.d.ts +50 -0
  107. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  108. package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -1
  109. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  110. package/dist/types/compute-engine/compilation/javascript-target.d.ts +23 -1
  111. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  112. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  113. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  114. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  115. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  116. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  117. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  118. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  119. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  120. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  121. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  122. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  123. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  124. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  125. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  126. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  127. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  128. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  129. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  130. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  131. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  132. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  133. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  134. package/dist/types/compute-engine/global-types.d.ts +1 -1
  135. package/dist/types/compute-engine/index.d.ts +1 -1
  136. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  137. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  138. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  139. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  140. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  141. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  142. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  143. package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
  144. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  145. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  146. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  147. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  148. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  149. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  150. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +3 -1
  151. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  152. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  153. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  154. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  155. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  156. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  157. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  158. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  159. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  160. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  161. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  162. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  163. package/dist/types/compute-engine/latex-syntax/parse.d.ts +11 -1
  164. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
  165. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  166. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  167. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  168. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  169. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  170. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  171. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  172. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  173. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  174. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  175. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  176. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  177. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  178. package/dist/types/compute-engine/library/core.d.ts +1 -1
  179. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  180. package/dist/types/compute-engine/library/library.d.ts +1 -1
  181. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  182. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  183. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  184. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  185. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  186. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  187. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  188. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  189. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  190. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  191. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  192. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  193. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  194. package/dist/types/compute-engine/library/units.d.ts +1 -1
  195. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  196. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  197. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  198. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  199. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  200. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  201. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  202. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  203. package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
  204. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  205. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  206. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  207. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  208. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  209. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  210. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  211. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  212. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  213. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  214. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  215. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  216. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  217. package/dist/types/compute-engine/oeis.d.ts +1 -1
  218. package/dist/types/compute-engine/sequence.d.ts +1 -1
  219. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  220. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  221. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  222. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  223. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  224. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  225. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  226. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  227. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  228. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  229. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  230. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  231. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  232. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  233. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  234. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  235. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  236. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  237. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  238. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  239. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  240. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  241. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  242. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  243. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  244. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  245. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  246. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  247. package/dist/types/compute-engine/types.d.ts +1 -1
  248. package/dist/types/compute-engine.d.ts +1 -1
  249. package/dist/types/core.d.ts +1 -1
  250. package/dist/types/interval.d.ts +1 -1
  251. package/dist/types/latex-syntax.d.ts +2 -2
  252. package/dist/types/math-json/symbols.d.ts +1 -1
  253. package/dist/types/math-json/types.d.ts +1 -1
  254. package/dist/types/math-json/utils.d.ts +1 -1
  255. package/dist/types/math-json.d.ts +2 -2
  256. package/dist/types/numerics.d.ts +1 -1
  257. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.55.0 */
1
+ /** Compute Engine 0.55.3 */
2
2
 
3
3
  // src/math-json/utils.ts
4
4
  var MISSING = ["Error", "'missing'"];
@@ -3232,6 +3232,452 @@ var BoxedType = class _BoxedType {
3232
3232
  }
3233
3233
  };
3234
3234
 
3235
+ // src/compute-engine/latex-syntax/dictionary/definitions-logic.ts
3236
+ var DEFINITIONS_LOGIC = [
3237
+ // Constants
3238
+ {
3239
+ name: "True",
3240
+ kind: "symbol",
3241
+ latexTrigger: ["\\top"]
3242
+ // ⊤ U+22A4
3243
+ },
3244
+ {
3245
+ kind: "symbol",
3246
+ latexTrigger: "\\mathrm{True}",
3247
+ parse: "True"
3248
+ },
3249
+ {
3250
+ kind: "symbol",
3251
+ latexTrigger: "\\operatorname{True}",
3252
+ parse: "True"
3253
+ },
3254
+ {
3255
+ kind: "symbol",
3256
+ latexTrigger: "\\mathsf{T}",
3257
+ parse: "True"
3258
+ },
3259
+ {
3260
+ name: "False",
3261
+ kind: "symbol",
3262
+ latexTrigger: ["\\bot"]
3263
+ // ⊥ U+22A5
3264
+ },
3265
+ {
3266
+ kind: "symbol",
3267
+ latexTrigger: "\\operatorname{False}",
3268
+ parse: "False"
3269
+ },
3270
+ {
3271
+ kind: "symbol",
3272
+ latexTrigger: "\\mathsf{F}",
3273
+ parse: "False"
3274
+ },
3275
+ // Operators
3276
+ // Logic operators have lower precedence than comparisons (245)
3277
+ // so that `x = 1 \lor x = 2` parses as `(x = 1) \lor (x = 2)`
3278
+ // See https://github.com/cortex-js/compute-engine/issues/243
3279
+ {
3280
+ name: "And",
3281
+ kind: "infix",
3282
+ latexTrigger: ["\\land"],
3283
+ precedence: 235
3284
+ // serialize: '\\land',
3285
+ },
3286
+ { kind: "infix", latexTrigger: ["\\wedge"], parse: "And", precedence: 235 },
3287
+ { kind: "infix", latexTrigger: "\\&", parse: "And", precedence: 235 },
3288
+ {
3289
+ kind: "infix",
3290
+ latexTrigger: "\\operatorname{and}",
3291
+ parse: "And",
3292
+ precedence: 235
3293
+ },
3294
+ {
3295
+ name: "Or",
3296
+ kind: "infix",
3297
+ latexTrigger: ["\\lor"],
3298
+ precedence: 230
3299
+ },
3300
+ { kind: "infix", latexTrigger: ["\\vee"], parse: "Or", precedence: 230 },
3301
+ { kind: "infix", latexTrigger: "\\parallel", parse: "Or", precedence: 230 },
3302
+ {
3303
+ kind: "infix",
3304
+ latexTrigger: "\\operatorname{or}",
3305
+ parse: "Or",
3306
+ precedence: 230
3307
+ },
3308
+ {
3309
+ name: "Xor",
3310
+ kind: "infix",
3311
+ latexTrigger: ["\\veebar"],
3312
+ precedence: 232
3313
+ },
3314
+ // Possible alt: \oplus ⊕ U+2295
3315
+ {
3316
+ name: "Not",
3317
+ kind: "prefix",
3318
+ latexTrigger: ["\\lnot"],
3319
+ precedence: 880
3320
+ },
3321
+ {
3322
+ kind: "prefix",
3323
+ latexTrigger: ["\\neg"],
3324
+ parse: "Not",
3325
+ precedence: 880
3326
+ },
3327
+ {
3328
+ name: "Nand",
3329
+ kind: "infix",
3330
+ latexTrigger: ["\\barwedge"],
3331
+ precedence: 232
3332
+ // serialize: '\\mid',
3333
+ },
3334
+ {
3335
+ name: "Nor",
3336
+ kind: "infix",
3337
+ latexTrigger: ["\u22BD"],
3338
+ // bar vee
3339
+ precedence: 232
3340
+ // serialize: '\\downarrow',
3341
+ },
3342
+ // Functions
3343
+ {
3344
+ kind: "function",
3345
+ symbolTrigger: "and",
3346
+ parse: "And"
3347
+ },
3348
+ {
3349
+ kind: "function",
3350
+ symbolTrigger: "or",
3351
+ parse: "Or"
3352
+ },
3353
+ {
3354
+ kind: "function",
3355
+ symbolTrigger: "not",
3356
+ parse: "Not"
3357
+ },
3358
+ // Relations
3359
+ {
3360
+ name: "Implies",
3361
+ kind: "infix",
3362
+ precedence: 220,
3363
+ associativity: "right",
3364
+ latexTrigger: ["\\implies"],
3365
+ serialize: "\\implies"
3366
+ },
3367
+ {
3368
+ latexTrigger: ["\\Rightarrow"],
3369
+ kind: "infix",
3370
+ precedence: 220,
3371
+ associativity: "right",
3372
+ parse: "Implies"
3373
+ },
3374
+ {
3375
+ latexTrigger: ["\\rightarrow"],
3376
+ kind: "infix",
3377
+ precedence: 220,
3378
+ associativity: "right",
3379
+ parse: "Implies"
3380
+ },
3381
+ {
3382
+ latexTrigger: ["\\Longrightarrow"],
3383
+ kind: "infix",
3384
+ precedence: 220,
3385
+ associativity: "right",
3386
+ parse: "Implies"
3387
+ },
3388
+ {
3389
+ latexTrigger: ["\\longrightarrow"],
3390
+ kind: "infix",
3391
+ precedence: 220,
3392
+ associativity: "right",
3393
+ parse: "Implies"
3394
+ },
3395
+ {
3396
+ // Non-strict mode: => for implies
3397
+ latexTrigger: ["=", ">"],
3398
+ kind: "infix",
3399
+ precedence: 220,
3400
+ associativity: "right",
3401
+ parse: (parser, lhs, until) => {
3402
+ if (parser.options.strict !== false) return null;
3403
+ const rhs = parser.parseExpression({ ...until, minPrec: 220 });
3404
+ if (rhs === null) return null;
3405
+ return ["Implies", lhs, rhs];
3406
+ }
3407
+ },
3408
+ {
3409
+ name: "Equivalent",
3410
+ // MathML: identical to, Mathematica: Congruent
3411
+ latexTrigger: ["\\iff"],
3412
+ kind: "infix",
3413
+ associativity: "right",
3414
+ precedence: 219
3415
+ },
3416
+ {
3417
+ latexTrigger: ["\\Leftrightarrow"],
3418
+ kind: "infix",
3419
+ associativity: "right",
3420
+ precedence: 219,
3421
+ parse: "Equivalent"
3422
+ },
3423
+ {
3424
+ latexTrigger: ["\\leftrightarrow"],
3425
+ kind: "infix",
3426
+ associativity: "right",
3427
+ precedence: 219,
3428
+ parse: "Equivalent"
3429
+ },
3430
+ {
3431
+ latexTrigger: ["\\Longleftrightarrow"],
3432
+ kind: "infix",
3433
+ associativity: "right",
3434
+ precedence: 219,
3435
+ parse: "Equivalent"
3436
+ },
3437
+ {
3438
+ latexTrigger: ["\\longleftrightarrow"],
3439
+ kind: "infix",
3440
+ associativity: "right",
3441
+ precedence: 219,
3442
+ parse: "Equivalent"
3443
+ },
3444
+ {
3445
+ // Non-strict mode: <=> for equivalence
3446
+ latexTrigger: ["<", "=", ">"],
3447
+ kind: "infix",
3448
+ precedence: 219,
3449
+ associativity: "right",
3450
+ parse: (parser, lhs, until) => {
3451
+ if (parser.options.strict !== false) return null;
3452
+ const rhs = parser.parseExpression({ ...until, minPrec: 219 });
3453
+ if (rhs === null) return null;
3454
+ return ["Equivalent", lhs, rhs];
3455
+ }
3456
+ },
3457
+ {
3458
+ latexTrigger: ["\\equiv"],
3459
+ kind: "infix",
3460
+ associativity: "right",
3461
+ precedence: 219,
3462
+ parse: (parser, lhs, terminator) => {
3463
+ const rhs = parser.parseExpression({ ...terminator, minPrec: 219 });
3464
+ const index = parser.index;
3465
+ const modulus = parser.parseExpression({ ...terminator, minPrec: 219 });
3466
+ if (modulus !== null && operator(modulus) === "Mod")
3467
+ return ["Congruent", lhs, rhs, missingIfEmpty(operand(modulus, 1))];
3468
+ parser.index = index;
3469
+ return ["Equivalent", lhs, missingIfEmpty(rhs)];
3470
+ }
3471
+ },
3472
+ {
3473
+ name: "Proves",
3474
+ kind: "infix",
3475
+ latexTrigger: ["\\vdash"],
3476
+ precedence: 220,
3477
+ associativity: "right",
3478
+ serialize: "\\vdash"
3479
+ },
3480
+ {
3481
+ name: "Entails",
3482
+ kind: "infix",
3483
+ latexTrigger: ["\\vDash"],
3484
+ precedence: 220,
3485
+ associativity: "right",
3486
+ serialize: "\\vDash"
3487
+ },
3488
+ {
3489
+ name: "Satisfies",
3490
+ kind: "infix",
3491
+ latexTrigger: ["\\models"],
3492
+ precedence: 220,
3493
+ associativity: "right",
3494
+ serialize: "\\models"
3495
+ },
3496
+ // Quantifiers: for all, exists
3497
+ {
3498
+ name: "ForAll",
3499
+ kind: "prefix",
3500
+ latexTrigger: ["\\forall"],
3501
+ precedence: 200,
3502
+ // Has to be lower than COMPARISON_PRECEDENCE
3503
+ serialize: serializeQuantifier("\\forall"),
3504
+ parse: parseQuantifier("ForAll")
3505
+ },
3506
+ {
3507
+ name: "Exists",
3508
+ kind: "prefix",
3509
+ latexTrigger: ["\\exists"],
3510
+ precedence: 200,
3511
+ // Has to be lower than COMPARISON_PRECEDENCE,
3512
+ serialize: serializeQuantifier("\\exists"),
3513
+ parse: parseQuantifier("Exists")
3514
+ },
3515
+ {
3516
+ name: "ExistsUnique",
3517
+ kind: "prefix",
3518
+ latexTrigger: ["\\exists", "!"],
3519
+ precedence: 200,
3520
+ // Has to be lower than COMPARISON_PRECEDENCE,
3521
+ serialize: serializeQuantifier("\\exists!"),
3522
+ parse: parseQuantifier("ExistsUnique")
3523
+ },
3524
+ {
3525
+ name: "NotForAll",
3526
+ kind: "prefix",
3527
+ latexTrigger: ["\\lnot", "\\forall"],
3528
+ precedence: 200,
3529
+ // Has to be lower than COMPARISON_PRECEDENCE
3530
+ serialize: serializeQuantifier("\\lnot\\forall"),
3531
+ parse: parseQuantifier("NotForAll")
3532
+ },
3533
+ {
3534
+ name: "NotExists",
3535
+ kind: "prefix",
3536
+ latexTrigger: ["\\lnot", "\\exists"],
3537
+ precedence: 200,
3538
+ // Has to be lower than COMPARISON_PRECEDENCE,
3539
+ serialize: serializeQuantifier("\\lnot\\exists"),
3540
+ parse: parseQuantifier("NotExists")
3541
+ },
3542
+ {
3543
+ name: "KroneckerDelta",
3544
+ kind: "prefix",
3545
+ latexTrigger: ["\\delta", "_"],
3546
+ precedence: 200,
3547
+ serialize: (serializer, expr) => {
3548
+ const args = operands(expr);
3549
+ if (args.length === 0) return "\\delta";
3550
+ if (args.every((x) => symbol(x)))
3551
+ return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join("")}}`;
3552
+ return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join(", ")}}`;
3553
+ },
3554
+ parse: (parser) => {
3555
+ const group = parser.parseGroup();
3556
+ if (group === null) {
3557
+ const token = parser.parseToken();
3558
+ if (!token) return null;
3559
+ return ["KroneckerDelta", token];
3560
+ }
3561
+ const seq = getSequence(group);
3562
+ if (seq && seq.length <= 2) return ["KroneckerDelta", ...seq];
3563
+ if (operator(group) === "InvisibleOperator")
3564
+ return ["KroneckerDelta", ...operands(group)];
3565
+ if (group !== null) return ["KroneckerDelta", group];
3566
+ return null;
3567
+ }
3568
+ },
3569
+ // Iverson brackets. Also called the "indicator function"
3570
+ // Must have a single argument, a relational expression, i.e.
3571
+ // `[ a = b ]` or `[ x \leq 0 ]`
3572
+ // Otherwise, it gets rejected, it could be something else, like a list or
3573
+ // tuple.
3574
+ {
3575
+ name: "Boole",
3576
+ kind: "matchfix",
3577
+ openTrigger: "[",
3578
+ closeTrigger: "]",
3579
+ // serialize: (serializer: Serializer, expr: MathJsonExpression) => {
3580
+ // const args = ops(expr);
3581
+ // return `[${serializer.serialize(arg)}]`;
3582
+ // },
3583
+ parse: (_parser, body) => {
3584
+ const h = operator(body);
3585
+ if (!h) return null;
3586
+ if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
3587
+ return ["Boole", body];
3588
+ }
3589
+ },
3590
+ {
3591
+ kind: "matchfix",
3592
+ openTrigger: "\\llbracket",
3593
+ closeTrigger: "\\rrbracket",
3594
+ parse: (_parser, body) => {
3595
+ const h = operator(body);
3596
+ if (!h) return null;
3597
+ if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
3598
+ return ["Boole", body];
3599
+ }
3600
+ },
3601
+ // Predicate application in First-Order Logic.
3602
+ // ["Predicate", "P", "x", "y"] serializes to "P(x, y)"
3603
+ {
3604
+ name: "Predicate",
3605
+ serialize: (serializer, expr) => {
3606
+ const args = operands(expr);
3607
+ if (args.length === 0) return "";
3608
+ const pred = args[0];
3609
+ const predStr = typeof pred === "string" ? pred : serializer.serialize(pred);
3610
+ if (args.length === 1) return predStr;
3611
+ const argStrs = args.slice(1).map((arg) => serializer.serialize(arg));
3612
+ return `${predStr}(${argStrs.join(", ")})`;
3613
+ }
3614
+ }
3615
+ ];
3616
+ function serializeQuantifier(quantifierSymbol) {
3617
+ return (serializer, expr) => {
3618
+ const args = operands(expr);
3619
+ if (args.length === 0) return quantifierSymbol;
3620
+ if (args.length === 1)
3621
+ return `${quantifierSymbol} ${serializer.serialize(args[0])}`;
3622
+ const boundVar = serializer.serialize(args[0]);
3623
+ const body = serializer.serialize(args[1]);
3624
+ return `${quantifierSymbol} ${boundVar}, ${body}`;
3625
+ };
3626
+ }
3627
+ function tightBindingCondition(p, terminator) {
3628
+ return p.peek === "\\to" || p.peek === "\\rightarrow" || p.peek === "\\implies" || p.peek === "\\Rightarrow" || p.peek === "\\iff" || p.peek === "\\Leftrightarrow" || p.peek === "\\land" || p.peek === "\\wedge" || p.peek === "\\lor" || p.peek === "\\vee" || (terminator.condition?.(p) ?? false);
3629
+ }
3630
+ function parseQuantifier(kind) {
3631
+ return (parser, terminator) => {
3632
+ const index = parser.index;
3633
+ const useTightBinding = parser.options.quantifierScope !== "loose";
3634
+ const symbol2 = parser.parseSymbol(terminator);
3635
+ if (symbol2) {
3636
+ parser.skipSpace();
3637
+ if (parser.match(",") || parser.match("\\mid") || parser.match(".") || parser.match(":") || parser.match("\\colon")) {
3638
+ const bodyTerminator = useTightBinding ? {
3639
+ ...terminator,
3640
+ condition: (p) => tightBindingCondition(p, terminator)
3641
+ } : terminator;
3642
+ parser.enterQuantifierScope();
3643
+ const body2 = parser.parseExpression(bodyTerminator);
3644
+ parser.exitQuantifierScope();
3645
+ return [kind, symbol2, missingIfEmpty(body2)];
3646
+ }
3647
+ parser.enterQuantifierScope();
3648
+ const body = parser.parseEnclosure();
3649
+ parser.exitQuantifierScope();
3650
+ if (body) return [kind, symbol2, missingIfEmpty(body)];
3651
+ }
3652
+ parser.index = index;
3653
+ const condTerminator = {
3654
+ ...terminator,
3655
+ condition: (p) => p.peek === ":" || p.peek === "\\colon" || (terminator.condition?.(p) ?? false)
3656
+ };
3657
+ const condition = parser.parseExpression(condTerminator);
3658
+ if (condition === null) return null;
3659
+ parser.skipSpace();
3660
+ if (parser.matchAny([",", "\\mid", ":", "\\colon"])) {
3661
+ const bodyTerminator = useTightBinding ? {
3662
+ ...terminator,
3663
+ condition: (p) => tightBindingCondition(p, terminator)
3664
+ } : terminator;
3665
+ parser.enterQuantifierScope();
3666
+ const body = parser.parseExpression(bodyTerminator);
3667
+ parser.exitQuantifierScope();
3668
+ return [kind, condition, missingIfEmpty(body)];
3669
+ }
3670
+ if (parser.match("(")) {
3671
+ parser.enterQuantifierScope();
3672
+ const body = parser.parseExpression(terminator);
3673
+ parser.exitQuantifierScope();
3674
+ if (!parser.match(")")) return null;
3675
+ return [kind, condition, missingIfEmpty(body)];
3676
+ }
3677
+ return null;
3678
+ };
3679
+ }
3680
+
3235
3681
  // src/compute-engine/latex-syntax/dictionary/definitions-core.ts
3236
3682
  function parseSequence(parser, terminator, lhs, prec, sep) {
3237
3683
  if (terminator && terminator.minPrec >= prec) return null;
@@ -3842,6 +4288,120 @@ var DEFINITIONS_CORE = [
3842
4288
  precedence: 21,
3843
4289
  parse: (parser, lhs, until) => parseWhereExpression(parser, lhs, until)
3844
4290
  },
4291
+ // \text{and} — logical conjunction infix
4292
+ {
4293
+ latexTrigger: ["\\text"],
4294
+ kind: "infix",
4295
+ associativity: "right",
4296
+ precedence: 235,
4297
+ // Same as \land
4298
+ parse: (parser, lhs, until) => {
4299
+ const start = parser.index;
4300
+ if (!matchTextKeyword(parser, "and")) {
4301
+ parser.index = start;
4302
+ return null;
4303
+ }
4304
+ const rhs = parser.parseExpression({ ...until, minPrec: 235 });
4305
+ return ["And", lhs, rhs ?? "Nothing"];
4306
+ }
4307
+ },
4308
+ // \text{or} — logical disjunction infix
4309
+ {
4310
+ latexTrigger: ["\\text"],
4311
+ kind: "infix",
4312
+ associativity: "right",
4313
+ precedence: 230,
4314
+ // Same as \lor
4315
+ parse: (parser, lhs, until) => {
4316
+ const start = parser.index;
4317
+ if (!matchTextKeyword(parser, "or")) {
4318
+ parser.index = start;
4319
+ return null;
4320
+ }
4321
+ const rhs = parser.parseExpression({ ...until, minPrec: 230 });
4322
+ return ["Or", lhs, rhs ?? "Nothing"];
4323
+ }
4324
+ },
4325
+ // \text{iff} — biconditional (if and only if)
4326
+ {
4327
+ latexTrigger: ["\\text"],
4328
+ kind: "infix",
4329
+ associativity: "right",
4330
+ precedence: 219,
4331
+ // Same as \iff
4332
+ parse: (parser, lhs, until) => {
4333
+ const start = parser.index;
4334
+ if (!matchTextKeyword(parser, "iff")) {
4335
+ parser.index = start;
4336
+ return null;
4337
+ }
4338
+ const rhs = parser.parseExpression({ ...until, minPrec: 219 });
4339
+ return ["Equivalent", lhs, rhs ?? "Nothing"];
4340
+ }
4341
+ },
4342
+ // \text{if and only if} — verbose biconditional
4343
+ {
4344
+ latexTrigger: ["\\text"],
4345
+ kind: "infix",
4346
+ associativity: "right",
4347
+ precedence: 219,
4348
+ parse: (parser, lhs, until) => {
4349
+ const start = parser.index;
4350
+ if (!matchTextKeyword(parser, "if and only if")) {
4351
+ parser.index = start;
4352
+ return null;
4353
+ }
4354
+ const rhs = parser.parseExpression({ ...until, minPrec: 219 });
4355
+ return ["Equivalent", lhs, rhs ?? "Nothing"];
4356
+ }
4357
+ },
4358
+ // \text{such that} — constraint separator (like : in set-builder notation)
4359
+ {
4360
+ latexTrigger: ["\\text"],
4361
+ kind: "infix",
4362
+ associativity: "right",
4363
+ precedence: 21,
4364
+ // Low precedence to capture full condition (same as 'where')
4365
+ parse: (parser, lhs, until) => {
4366
+ const start = parser.index;
4367
+ if (!matchTextKeyword(parser, "such that")) {
4368
+ parser.index = start;
4369
+ return null;
4370
+ }
4371
+ const rhs = parser.parseExpression({ ...until, minPrec: 21 });
4372
+ return ["Colon", lhs, rhs ?? "Nothing"];
4373
+ }
4374
+ },
4375
+ // \text{for all} — universal quantifier
4376
+ {
4377
+ latexTrigger: ["\\text"],
4378
+ kind: "prefix",
4379
+ precedence: 200,
4380
+ // Same as \forall
4381
+ parse: (parser, until) => {
4382
+ const start = parser.index;
4383
+ if (!matchTextKeyword(parser, "for all")) {
4384
+ parser.index = start;
4385
+ return null;
4386
+ }
4387
+ return parseQuantifier("ForAll")(parser, until);
4388
+ }
4389
+ },
4390
+ // \text{there exists} — existential quantifier
4391
+ {
4392
+ latexTrigger: ["\\text"],
4393
+ kind: "prefix",
4394
+ precedence: 200,
4395
+ // Same as \exists
4396
+ parse: (parser, until) => {
4397
+ const start = parser.index;
4398
+ if (!matchTextKeyword(parser, "there exists")) {
4399
+ parser.index = start;
4400
+ return null;
4401
+ }
4402
+ return parseQuantifier("Exists")(parser, until);
4403
+ }
4404
+ },
3845
4405
  // Block serializer — used by both `where` and semicolon blocks
3846
4406
  {
3847
4407
  name: "Block",
@@ -3957,6 +4517,39 @@ var DEFINITIONS_CORE = [
3957
4517
  parser.parseExpression(until) ?? "Nothing"
3958
4518
  ]
3959
4519
  },
4520
+ // Text serializer — reconstructs \text{...} with inline $...$ for math
4521
+ {
4522
+ name: "Text",
4523
+ serialize: (serializer, expr) => {
4524
+ const args = operands(expr);
4525
+ if (args.length === 0) return "";
4526
+ let firstStr = -1;
4527
+ let lastStr = -1;
4528
+ for (let i = 0; i < args.length; i++) {
4529
+ if (stringValue(args[i]) !== null) {
4530
+ if (firstStr < 0) firstStr = i;
4531
+ lastStr = i;
4532
+ }
4533
+ }
4534
+ if (firstStr < 0)
4535
+ return joinLatex(args.map((a) => serializer.serialize(a)));
4536
+ const parts = [];
4537
+ for (let i = 0; i < firstStr; i++)
4538
+ parts.push(serializer.serialize(args[i]));
4539
+ let textContent = "";
4540
+ for (let i = firstStr; i <= lastStr; i++) {
4541
+ const s = stringValue(args[i]);
4542
+ if (s !== null) textContent += sanitizeLatex(s);
4543
+ else if (operator(args[i]) === "Annotated" || operator(args[i]) === "Text")
4544
+ textContent += serializer.serialize(args[i]);
4545
+ else textContent += "$" + serializer.serialize(args[i]) + "$";
4546
+ }
4547
+ parts.push("\\text{" + textContent + "}");
4548
+ for (let i = lastStr + 1; i < args.length; i++)
4549
+ parts.push(serializer.serialize(args[i]));
4550
+ return joinLatex(parts);
4551
+ }
4552
+ },
3960
4553
  {
3961
4554
  name: "String",
3962
4555
  latexTrigger: ["\\text"],
@@ -4347,9 +4940,10 @@ function parseTextRun(parser, style) {
4347
4940
  } else if (parser.match("\\textcolor")) {
4348
4941
  const pos = parser.index;
4349
4942
  const color = parser.parseStringGroup();
4350
- const body2 = parser.parseExpression();
4351
- if (color !== null && body2 !== null) {
4352
- runs.push(["Annotated", body2, { dict: { color } }]);
4943
+ if (color !== null) {
4944
+ flush();
4945
+ const body2 = parseTextRun(parser);
4946
+ runs.push(["Annotated", body2, dictionaryFromEntries({ color })]);
4353
4947
  } else {
4354
4948
  parser.index = pos;
4355
4949
  text += "\\textcolor";
@@ -4367,6 +4961,7 @@ function parseTextRun(parser, style) {
4367
4961
  const expr = parser.parseExpression() ?? "Nothing";
4368
4962
  parser.skipSpace();
4369
4963
  if (parser.match("<$>")) {
4964
+ flush();
4370
4965
  runs.push(expr);
4371
4966
  } else {
4372
4967
  text += "$";
@@ -4377,6 +4972,7 @@ function parseTextRun(parser, style) {
4377
4972
  const expr = parser.parseExpression() ?? "Nothing";
4378
4973
  parser.skipSpace();
4379
4974
  if (parser.match("<$$>")) {
4975
+ flush();
4380
4976
  runs.push(expr);
4381
4977
  } else {
4382
4978
  text += "$$";
@@ -4727,14 +5323,20 @@ function matchTextKeyword(parser, keyword) {
4727
5323
  }
4728
5324
  while (parser.match("<space>")) {
4729
5325
  }
4730
- let text = "";
4731
- while (!parser.atEnd && parser.peek !== "<}>" && parser.peek !== "<space>") {
4732
- const tok = parser.peek;
4733
- if (/^[a-zA-Z]$/.test(tok)) {
4734
- text += tok;
4735
- parser.nextToken();
5326
+ for (let i = 0; i < keyword.length; i++) {
5327
+ if (keyword[i] === " ") {
5328
+ if (!parser.match("<space>")) {
5329
+ parser.index = start;
5330
+ return false;
5331
+ }
5332
+ while (parser.match("<space>")) {
5333
+ }
4736
5334
  } else {
4737
- break;
5335
+ if (parser.peek !== keyword[i]) {
5336
+ parser.index = start;
5337
+ return false;
5338
+ }
5339
+ parser.nextToken();
4738
5340
  }
4739
5341
  }
4740
5342
  while (parser.match("<space>")) {
@@ -4743,10 +5345,6 @@ function matchTextKeyword(parser, keyword) {
4743
5345
  parser.index = start;
4744
5346
  return false;
4745
5347
  }
4746
- if (text !== keyword) {
4747
- parser.index = start;
4748
- return false;
4749
- }
4750
5348
  return true;
4751
5349
  }
4752
5350
  function matchKeyword(parser, keyword) {
@@ -5002,473 +5600,27 @@ var DEFINITIONS_SYMBOLS = [
5002
5600
  ];
5003
5601
 
5004
5602
  // src/compute-engine/latex-syntax/dictionary/definitions-algebra.ts
5005
- var DEFINITIONS_ALGEBRA = [
5006
- {
5007
- name: "To",
5008
- latexTrigger: ["\\to"],
5009
- kind: "infix",
5010
- precedence: 270
5011
- // MathML rightwards arrow
5012
- },
5013
- {
5014
- // Non-strict mode: -> for maps-to arrow
5015
- latexTrigger: ["-", ">"],
5016
- kind: "infix",
5017
- precedence: 270,
5018
- parse: (parser, lhs, until) => {
5019
- if (parser.options.strict !== false) return null;
5020
- const rhs = parser.parseExpression({ ...until, minPrec: 270 });
5021
- if (rhs === null) return null;
5022
- return ["To", lhs, rhs];
5023
- }
5024
- }
5025
- ];
5026
-
5027
- // src/compute-engine/latex-syntax/dictionary/definitions-logic.ts
5028
- var DEFINITIONS_LOGIC = [
5029
- // Constants
5030
- {
5031
- name: "True",
5032
- kind: "symbol",
5033
- latexTrigger: ["\\top"]
5034
- // ⊤ U+22A4
5035
- },
5036
- {
5037
- kind: "symbol",
5038
- latexTrigger: "\\mathrm{True}",
5039
- parse: "True"
5040
- },
5041
- {
5042
- kind: "symbol",
5043
- latexTrigger: "\\operatorname{True}",
5044
- parse: "True"
5045
- },
5046
- {
5047
- kind: "symbol",
5048
- latexTrigger: "\\mathsf{T}",
5049
- parse: "True"
5050
- },
5051
- {
5052
- name: "False",
5053
- kind: "symbol",
5054
- latexTrigger: ["\\bot"]
5055
- // ⊥ U+22A5
5056
- },
5057
- {
5058
- kind: "symbol",
5059
- latexTrigger: "\\operatorname{False}",
5060
- parse: "False"
5061
- },
5062
- {
5063
- kind: "symbol",
5064
- latexTrigger: "\\mathsf{F}",
5065
- parse: "False"
5066
- },
5067
- // Operators
5068
- // Logic operators have lower precedence than comparisons (245)
5069
- // so that `x = 1 \lor x = 2` parses as `(x = 1) \lor (x = 2)`
5070
- // See https://github.com/cortex-js/compute-engine/issues/243
5071
- {
5072
- name: "And",
5073
- kind: "infix",
5074
- latexTrigger: ["\\land"],
5075
- precedence: 235
5076
- // serialize: '\\land',
5077
- },
5078
- { kind: "infix", latexTrigger: ["\\wedge"], parse: "And", precedence: 235 },
5079
- { kind: "infix", latexTrigger: "\\&", parse: "And", precedence: 235 },
5080
- {
5081
- kind: "infix",
5082
- latexTrigger: "\\operatorname{and}",
5083
- parse: "And",
5084
- precedence: 235
5085
- },
5086
- {
5087
- name: "Or",
5088
- kind: "infix",
5089
- latexTrigger: ["\\lor"],
5090
- precedence: 230
5091
- },
5092
- { kind: "infix", latexTrigger: ["\\vee"], parse: "Or", precedence: 230 },
5093
- { kind: "infix", latexTrigger: "\\parallel", parse: "Or", precedence: 230 },
5094
- {
5095
- kind: "infix",
5096
- latexTrigger: "\\operatorname{or}",
5097
- parse: "Or",
5098
- precedence: 230
5099
- },
5100
- {
5101
- name: "Xor",
5102
- kind: "infix",
5103
- latexTrigger: ["\\veebar"],
5104
- precedence: 232
5105
- },
5106
- // Possible alt: \oplus ⊕ U+2295
5107
- {
5108
- name: "Not",
5109
- kind: "prefix",
5110
- latexTrigger: ["\\lnot"],
5111
- precedence: 880
5112
- },
5113
- {
5114
- kind: "prefix",
5115
- latexTrigger: ["\\neg"],
5116
- parse: "Not",
5117
- precedence: 880
5118
- },
5119
- {
5120
- name: "Nand",
5121
- kind: "infix",
5122
- latexTrigger: ["\\barwedge"],
5123
- precedence: 232
5124
- // serialize: '\\mid',
5125
- },
5126
- {
5127
- name: "Nor",
5128
- kind: "infix",
5129
- latexTrigger: ["\u22BD"],
5130
- // bar vee
5131
- precedence: 232
5132
- // serialize: '\\downarrow',
5133
- },
5134
- // Functions
5135
- {
5136
- kind: "function",
5137
- symbolTrigger: "and",
5138
- parse: "And"
5139
- },
5140
- {
5141
- kind: "function",
5142
- symbolTrigger: "or",
5143
- parse: "Or"
5144
- },
5145
- {
5146
- kind: "function",
5147
- symbolTrigger: "not",
5148
- parse: "Not"
5149
- },
5150
- // Relations
5151
- {
5152
- name: "Implies",
5153
- kind: "infix",
5154
- precedence: 220,
5155
- associativity: "right",
5156
- latexTrigger: ["\\implies"],
5157
- serialize: "\\implies"
5158
- },
5159
- {
5160
- latexTrigger: ["\\Rightarrow"],
5161
- kind: "infix",
5162
- precedence: 220,
5163
- associativity: "right",
5164
- parse: "Implies"
5165
- },
5166
- {
5167
- latexTrigger: ["\\rightarrow"],
5168
- kind: "infix",
5169
- precedence: 220,
5170
- associativity: "right",
5171
- parse: "Implies"
5172
- },
5173
- {
5174
- latexTrigger: ["\\Longrightarrow"],
5175
- kind: "infix",
5176
- precedence: 220,
5177
- associativity: "right",
5178
- parse: "Implies"
5179
- },
5180
- {
5181
- latexTrigger: ["\\longrightarrow"],
5182
- kind: "infix",
5183
- precedence: 220,
5184
- associativity: "right",
5185
- parse: "Implies"
5186
- },
5187
- {
5188
- // Non-strict mode: => for implies
5189
- latexTrigger: ["=", ">"],
5190
- kind: "infix",
5191
- precedence: 220,
5192
- associativity: "right",
5193
- parse: (parser, lhs, until) => {
5194
- if (parser.options.strict !== false) return null;
5195
- const rhs = parser.parseExpression({ ...until, minPrec: 220 });
5196
- if (rhs === null) return null;
5197
- return ["Implies", lhs, rhs];
5198
- }
5199
- },
5200
- {
5201
- name: "Equivalent",
5202
- // MathML: identical to, Mathematica: Congruent
5203
- latexTrigger: ["\\iff"],
5204
- kind: "infix",
5205
- associativity: "right",
5206
- precedence: 219
5207
- },
5208
- {
5209
- latexTrigger: ["\\Leftrightarrow"],
5210
- kind: "infix",
5211
- associativity: "right",
5212
- precedence: 219,
5213
- parse: "Equivalent"
5214
- },
5215
- {
5216
- latexTrigger: ["\\leftrightarrow"],
5217
- kind: "infix",
5218
- associativity: "right",
5219
- precedence: 219,
5220
- parse: "Equivalent"
5221
- },
5222
- {
5223
- latexTrigger: ["\\Longleftrightarrow"],
5224
- kind: "infix",
5225
- associativity: "right",
5226
- precedence: 219,
5227
- parse: "Equivalent"
5228
- },
5603
+ var DEFINITIONS_ALGEBRA = [
5229
5604
  {
5230
- latexTrigger: ["\\longleftrightarrow"],
5605
+ name: "To",
5606
+ latexTrigger: ["\\to"],
5231
5607
  kind: "infix",
5232
- associativity: "right",
5233
- precedence: 219,
5234
- parse: "Equivalent"
5608
+ precedence: 270
5609
+ // MathML rightwards arrow
5235
5610
  },
5236
5611
  {
5237
- // Non-strict mode: <=> for equivalence
5238
- latexTrigger: ["<", "=", ">"],
5612
+ // Non-strict mode: -> for maps-to arrow
5613
+ latexTrigger: ["-", ">"],
5239
5614
  kind: "infix",
5240
- precedence: 219,
5241
- associativity: "right",
5615
+ precedence: 270,
5242
5616
  parse: (parser, lhs, until) => {
5243
5617
  if (parser.options.strict !== false) return null;
5244
- const rhs = parser.parseExpression({ ...until, minPrec: 219 });
5618
+ const rhs = parser.parseExpression({ ...until, minPrec: 270 });
5245
5619
  if (rhs === null) return null;
5246
- return ["Equivalent", lhs, rhs];
5247
- }
5248
- },
5249
- {
5250
- latexTrigger: ["\\equiv"],
5251
- kind: "infix",
5252
- associativity: "right",
5253
- precedence: 219,
5254
- parse: (parser, lhs, terminator) => {
5255
- const rhs = parser.parseExpression({ ...terminator, minPrec: 219 });
5256
- const index = parser.index;
5257
- const modulus = parser.parseExpression({ ...terminator, minPrec: 219 });
5258
- if (modulus !== null && operator(modulus) === "Mod")
5259
- return ["Congruent", lhs, rhs, missingIfEmpty(operand(modulus, 1))];
5260
- parser.index = index;
5261
- return ["Equivalent", lhs, missingIfEmpty(rhs)];
5262
- }
5263
- },
5264
- {
5265
- name: "Proves",
5266
- kind: "infix",
5267
- latexTrigger: ["\\vdash"],
5268
- precedence: 220,
5269
- associativity: "right",
5270
- serialize: "\\vdash"
5271
- },
5272
- {
5273
- name: "Entails",
5274
- kind: "infix",
5275
- latexTrigger: ["\\vDash"],
5276
- precedence: 220,
5277
- associativity: "right",
5278
- serialize: "\\vDash"
5279
- },
5280
- {
5281
- name: "Satisfies",
5282
- kind: "infix",
5283
- latexTrigger: ["\\models"],
5284
- precedence: 220,
5285
- associativity: "right",
5286
- serialize: "\\models"
5287
- },
5288
- // Quantifiers: for all, exists
5289
- {
5290
- name: "ForAll",
5291
- kind: "prefix",
5292
- latexTrigger: ["\\forall"],
5293
- precedence: 200,
5294
- // Has to be lower than COMPARISON_PRECEDENCE
5295
- serialize: serializeQuantifier("\\forall"),
5296
- parse: parseQuantifier("ForAll")
5297
- },
5298
- {
5299
- name: "Exists",
5300
- kind: "prefix",
5301
- latexTrigger: ["\\exists"],
5302
- precedence: 200,
5303
- // Has to be lower than COMPARISON_PRECEDENCE,
5304
- serialize: serializeQuantifier("\\exists"),
5305
- parse: parseQuantifier("Exists")
5306
- },
5307
- {
5308
- name: "ExistsUnique",
5309
- kind: "prefix",
5310
- latexTrigger: ["\\exists", "!"],
5311
- precedence: 200,
5312
- // Has to be lower than COMPARISON_PRECEDENCE,
5313
- serialize: serializeQuantifier("\\exists!"),
5314
- parse: parseQuantifier("ExistsUnique")
5315
- },
5316
- {
5317
- name: "NotForAll",
5318
- kind: "prefix",
5319
- latexTrigger: ["\\lnot", "\\forall"],
5320
- precedence: 200,
5321
- // Has to be lower than COMPARISON_PRECEDENCE
5322
- serialize: serializeQuantifier("\\lnot\\forall"),
5323
- parse: parseQuantifier("NotForAll")
5324
- },
5325
- {
5326
- name: "NotExists",
5327
- kind: "prefix",
5328
- latexTrigger: ["\\lnot", "\\exists"],
5329
- precedence: 200,
5330
- // Has to be lower than COMPARISON_PRECEDENCE,
5331
- serialize: serializeQuantifier("\\lnot\\exists"),
5332
- parse: parseQuantifier("NotExists")
5333
- },
5334
- {
5335
- name: "KroneckerDelta",
5336
- kind: "prefix",
5337
- latexTrigger: ["\\delta", "_"],
5338
- precedence: 200,
5339
- serialize: (serializer, expr) => {
5340
- const args = operands(expr);
5341
- if (args.length === 0) return "\\delta";
5342
- if (args.every((x) => symbol(x)))
5343
- return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join("")}}`;
5344
- return `\\delta_{${args.map((arg) => serializer.serialize(arg)).join(", ")}}`;
5345
- },
5346
- parse: (parser) => {
5347
- const group = parser.parseGroup();
5348
- if (group === null) {
5349
- const token = parser.parseToken();
5350
- if (!token) return null;
5351
- return ["KroneckerDelta", token];
5352
- }
5353
- const seq = getSequence(group);
5354
- if (seq && seq.length <= 2) return ["KroneckerDelta", ...seq];
5355
- if (operator(group) === "InvisibleOperator")
5356
- return ["KroneckerDelta", ...operands(group)];
5357
- if (group !== null) return ["KroneckerDelta", group];
5358
- return null;
5359
- }
5360
- },
5361
- // Iverson brackets. Also called the "indicator function"
5362
- // Must have a single argument, a relational expression, i.e.
5363
- // `[ a = b ]` or `[ x \leq 0 ]`
5364
- // Otherwise, it gets rejected, it could be something else, like a list or
5365
- // tuple.
5366
- {
5367
- name: "Boole",
5368
- kind: "matchfix",
5369
- openTrigger: "[",
5370
- closeTrigger: "]",
5371
- // serialize: (serializer: Serializer, expr: MathJsonExpression) => {
5372
- // const args = ops(expr);
5373
- // return `[${serializer.serialize(arg)}]`;
5374
- // },
5375
- parse: (_parser, body) => {
5376
- const h = operator(body);
5377
- if (!h) return null;
5378
- if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
5379
- return ["Boole", body];
5380
- }
5381
- },
5382
- {
5383
- kind: "matchfix",
5384
- openTrigger: "\\llbracket",
5385
- closeTrigger: "\\rrbracket",
5386
- parse: (_parser, body) => {
5387
- const h = operator(body);
5388
- if (!h) return null;
5389
- if (!DEFINITIONS_INEQUALITIES.some((x) => x.name === h)) return null;
5390
- return ["Boole", body];
5391
- }
5392
- },
5393
- // Predicate application in First-Order Logic.
5394
- // ["Predicate", "P", "x", "y"] serializes to "P(x, y)"
5395
- {
5396
- name: "Predicate",
5397
- serialize: (serializer, expr) => {
5398
- const args = operands(expr);
5399
- if (args.length === 0) return "";
5400
- const pred = args[0];
5401
- const predStr = typeof pred === "string" ? pred : serializer.serialize(pred);
5402
- if (args.length === 1) return predStr;
5403
- const argStrs = args.slice(1).map((arg) => serializer.serialize(arg));
5404
- return `${predStr}(${argStrs.join(", ")})`;
5620
+ return ["To", lhs, rhs];
5405
5621
  }
5406
5622
  }
5407
5623
  ];
5408
- function serializeQuantifier(quantifierSymbol) {
5409
- return (serializer, expr) => {
5410
- const args = operands(expr);
5411
- if (args.length === 0) return quantifierSymbol;
5412
- if (args.length === 1)
5413
- return `${quantifierSymbol} ${serializer.serialize(args[0])}`;
5414
- const boundVar = serializer.serialize(args[0]);
5415
- const body = serializer.serialize(args[1]);
5416
- return `${quantifierSymbol} ${boundVar}, ${body}`;
5417
- };
5418
- }
5419
- function tightBindingCondition(p, terminator) {
5420
- return p.peek === "\\to" || p.peek === "\\rightarrow" || p.peek === "\\implies" || p.peek === "\\Rightarrow" || p.peek === "\\iff" || p.peek === "\\Leftrightarrow" || p.peek === "\\land" || p.peek === "\\wedge" || p.peek === "\\lor" || p.peek === "\\vee" || (terminator.condition?.(p) ?? false);
5421
- }
5422
- function parseQuantifier(kind) {
5423
- return (parser, terminator) => {
5424
- const index = parser.index;
5425
- const useTightBinding = parser.options.quantifierScope !== "loose";
5426
- const symbol2 = parser.parseSymbol(terminator);
5427
- if (symbol2) {
5428
- parser.skipSpace();
5429
- if (parser.match(",") || parser.match("\\mid") || parser.match(".") || parser.match(":") || parser.match("\\colon")) {
5430
- const bodyTerminator = useTightBinding ? {
5431
- ...terminator,
5432
- condition: (p) => tightBindingCondition(p, terminator)
5433
- } : terminator;
5434
- parser.enterQuantifierScope();
5435
- const body2 = parser.parseExpression(bodyTerminator);
5436
- parser.exitQuantifierScope();
5437
- return [kind, symbol2, missingIfEmpty(body2)];
5438
- }
5439
- parser.enterQuantifierScope();
5440
- const body = parser.parseEnclosure();
5441
- parser.exitQuantifierScope();
5442
- if (body) return [kind, symbol2, missingIfEmpty(body)];
5443
- }
5444
- parser.index = index;
5445
- const condTerminator = {
5446
- ...terminator,
5447
- condition: (p) => p.peek === ":" || p.peek === "\\colon" || (terminator.condition?.(p) ?? false)
5448
- };
5449
- const condition = parser.parseExpression(condTerminator);
5450
- if (condition === null) return null;
5451
- parser.skipSpace();
5452
- if (parser.matchAny([",", "\\mid", ":", "\\colon"])) {
5453
- const bodyTerminator = useTightBinding ? {
5454
- ...terminator,
5455
- condition: (p) => tightBindingCondition(p, terminator)
5456
- } : terminator;
5457
- parser.enterQuantifierScope();
5458
- const body = parser.parseExpression(bodyTerminator);
5459
- parser.exitQuantifierScope();
5460
- return [kind, condition, missingIfEmpty(body)];
5461
- }
5462
- if (parser.match("(")) {
5463
- parser.enterQuantifierScope();
5464
- const body = parser.parseExpression(terminator);
5465
- parser.exitQuantifierScope();
5466
- if (!parser.match(")")) return null;
5467
- return [kind, condition, missingIfEmpty(body)];
5468
- }
5469
- return null;
5470
- };
5471
- }
5472
5624
 
5473
5625
  // src/compute-engine/latex-syntax/dictionary/definitions-sets.ts
5474
5626
  function parseIntervalBody(body, openLeft, openRight) {
@@ -9881,7 +10033,7 @@ var ZWJ2 = "\\u{200D}";
9881
10033
  var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
9882
10034
  var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
9883
10035
  var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
9884
- var EMOJI_NOT_SYMBOL = `(?:(?=\\P{XIDC})\\p{Emoji})`;
10036
+ var EMOJI_NOT_SYMBOL = `(?:(?=\\P{XIDC})(?=[^\\x23\\x2a\\x30-\\x39])\\p{Emoji})`;
9885
10037
  var ZWJ_ELEMENT = `(?:${EMOJI_NOT_SYMBOL}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
9886
10038
  var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ2}${ZWJ_ELEMENT})*`;
9887
10039
  var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
@@ -10590,7 +10742,9 @@ function parseSymbolToken(parser, options) {
10590
10742
  }
10591
10743
  return c;
10592
10744
  }
10593
- return parser.nextToken();
10745
+ const raw = parser.peek;
10746
+ if (raw && /^[\p{XIDC}\p{M}]/u.test(raw)) return parser.nextToken();
10747
+ return null;
10594
10748
  }
10595
10749
  function parseSymbolBody(parser) {
10596
10750
  let id = matchPrefixedSymbol(parser);
@@ -13258,6 +13412,29 @@ var _Parser = class __Parser {
13258
13412
  this.index = start;
13259
13413
  return null;
13260
13414
  }
13415
+ /**
13416
+ * Speculatively check if any \text infix entry (e.g. "and", "or", "where")
13417
+ * would match the upcoming tokens. This is used to prevent InvisibleOperator
13418
+ * from consuming \text{keyword} as a text run when the keyword is actually
13419
+ * an infix operator that was skipped due to precedence constraints.
13420
+ *
13421
+ * Returns true if any entry's parse function would succeed (non-null result).
13422
+ * The parser index is always restored to its original position.
13423
+ */
13424
+ wouldMatchTextInfix(opDefs) {
13425
+ const start = this.index;
13426
+ for (const [def, n] of opDefs) {
13427
+ if (def.kind !== "infix") continue;
13428
+ this.index = start + n;
13429
+ const result = def.parse(this, "Nothing", { minPrec: 0 });
13430
+ if (result !== null) {
13431
+ this.index = start;
13432
+ return true;
13433
+ }
13434
+ }
13435
+ this.index = start;
13436
+ return false;
13437
+ }
13261
13438
  /**
13262
13439
  * This returns an array of arguments (as in a function application),
13263
13440
  * or null if there is no match.
@@ -13883,6 +14060,7 @@ var _Parser = class __Parser {
13883
14060
  if (isDelimiterCommand(this))
13884
14061
  return this.error("unexpected-delimiter", start);
13885
14062
  if (command[0] !== "\\") {
14063
+ this.nextToken();
13886
14064
  return this.error(
13887
14065
  ["unexpected-token", { str: tokensToString(command) }],
13888
14066
  start
@@ -14011,25 +14189,28 @@ var _Parser = class __Parser {
14011
14189
  if (result === null && until.minPrec <= INVISIBLE_OP_PRECEDENCE) {
14012
14190
  const opDefs = this.peekDefinitions("operator");
14013
14191
  if (opDefs.length === 0 || opDefs.every(([def]) => def.latexTrigger === "\\text")) {
14014
- const rhs = this.parseExpression({
14015
- ...until,
14016
- minPrec: INVISIBLE_OP_PRECEDENCE + 1
14017
- });
14018
- if (rhs !== null) {
14019
- if (operator(lhs) === "InvisibleOperator") {
14020
- if (operator(rhs) === "InvisibleOperator")
14021
- result = [
14022
- "InvisibleOperator",
14023
- ...operands(lhs),
14024
- ...operands(rhs)
14025
- ];
14026
- else result = ["InvisibleOperator", ...operands(lhs), rhs];
14027
- } else if (operator(rhs) === "InvisibleOperator") {
14028
- result = ["InvisibleOperator", lhs, ...operands(rhs)];
14029
- } else result = ["InvisibleOperator", lhs, rhs];
14192
+ if (opDefs.length > 0 && this.wouldMatchTextInfix(opDefs)) {
14030
14193
  } else {
14031
- if (result === null) {
14032
- result = this.options.parseUnexpectedToken?.(lhs, this) ?? null;
14194
+ const rhs = this.parseExpression({
14195
+ ...until,
14196
+ minPrec: INVISIBLE_OP_PRECEDENCE + 1
14197
+ });
14198
+ if (rhs !== null) {
14199
+ if (operator(lhs) === "InvisibleOperator") {
14200
+ if (operator(rhs) === "InvisibleOperator")
14201
+ result = [
14202
+ "InvisibleOperator",
14203
+ ...operands(lhs),
14204
+ ...operands(rhs)
14205
+ ];
14206
+ else result = ["InvisibleOperator", ...operands(lhs), rhs];
14207
+ } else if (operator(rhs) === "InvisibleOperator") {
14208
+ result = ["InvisibleOperator", lhs, ...operands(rhs)];
14209
+ } else result = ["InvisibleOperator", lhs, rhs];
14210
+ } else {
14211
+ if (result === null) {
14212
+ result = this.options.parseUnexpectedToken?.(lhs, this) ?? null;
14213
+ }
14033
14214
  }
14034
14215
  }
14035
14216
  }
@@ -14952,7 +15133,7 @@ function serialize(expr) {
14952
15133
  }
14953
15134
 
14954
15135
  // src/latex-syntax.ts
14955
- var version = "0.55.0";
15136
+ var version = "0.55.3";
14956
15137
  export {
14957
15138
  DEFINITIONS_ALGEBRA as ALGEBRA_DICTIONARY,
14958
15139
  DEFINITIONS_ARITHMETIC as ARITHMETIC_DICTIONARY,