tla-ts 0.0.9 → 0.0.10-dev.094b9b512

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 (622) hide show
  1. package/README.md +30 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +40 -37
  5. package/dist/deciders.js +47 -44
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +106 -10
  8. package/dist/index.d.ts +106 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +2658 -410
  15. package/dist/prove.js +2657 -409
  16. package/dist/run.cjs +144 -31
  17. package/dist/run.js +144 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +129 -104
  21. package/dist/transfer.js +129 -104
  22. package/dist/worker.cjs +6 -6
  23. package/dist/worker.js +6 -6
  24. package/package.json +3 -1
  25. package/src/ast.ts +48 -62
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +28 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check-failure.ts +116 -0
  30. package/src/check-trace.ts +282 -0
  31. package/src/check.ts +599 -754
  32. package/src/cli/options.ts +12 -32
  33. package/src/cli/run.ts +0 -2
  34. package/src/cli/runtime-invariants.ts +136 -0
  35. package/src/cli/shared.ts +19 -12
  36. package/src/cli/tlapm.ts +208 -54
  37. package/src/cli/tlc-arguments.ts +652 -0
  38. package/src/cli/tlc-output.ts +687 -0
  39. package/src/cli/tlc-usage.ts +361 -0
  40. package/src/cli/tlc.ts +309 -658
  41. package/src/cli/typescript.ts +23 -0
  42. package/src/cli/xml-exporter.ts +27 -49
  43. package/src/cli.ts +0 -1
  44. package/src/codegen.ts +196 -74
  45. package/src/config.ts +140 -109
  46. package/src/coverage.ts +830 -0
  47. package/src/dependencies.ts +14 -53
  48. package/src/dfid.ts +618 -0
  49. package/src/environment-config.ts +315 -0
  50. package/src/environment.ts +169 -335
  51. package/src/errors.ts +100 -57
  52. package/src/evaluate.ts +598 -340
  53. package/src/exit-codes.ts +37 -3
  54. package/src/fingerprints.ts +75 -11
  55. package/src/index.ts +3 -0
  56. package/src/instances.ts +126 -21
  57. package/src/java-hash.ts +7 -0
  58. package/src/java-overrides.ts +4 -19
  59. package/src/json-reader.ts +455 -0
  60. package/src/json.ts +252 -139
  61. package/src/levels.ts +46 -58
  62. package/src/lexer.ts +83 -101
  63. package/src/liveness-checker.ts +103 -153
  64. package/src/liveness.ts +150 -109
  65. package/src/obligations/action.ts +18 -43
  66. package/src/obligations/anonymize.ts +119 -90
  67. package/src/obligations/enabled-axioms.ts +218 -0
  68. package/src/obligations/equality.ts +2 -2
  69. package/src/obligations/expression.ts +38 -25
  70. package/src/obligations/format.ts +1 -9
  71. package/src/obligations/generate.ts +67 -63
  72. package/src/obligations/index.ts +38 -20
  73. package/src/obligations/levels.ts +28 -17
  74. package/src/obligations/module.ts +29 -54
  75. package/src/obligations/normalize.ts +31 -36
  76. package/src/obligations/operators.ts +1 -2
  77. package/src/obligations/pragma.ts +53 -25
  78. package/src/obligations/printer.ts +90 -57
  79. package/src/obligations/proof.ts +4 -5
  80. package/src/obligations/regroup.ts +1 -4
  81. package/src/obligations/simplify.ts +58 -62
  82. package/src/obligations/source.ts +119 -95
  83. package/src/obligations/subexpression.ts +51 -27
  84. package/src/obligations/substitution.ts +2 -4
  85. package/src/obligations/temporal.ts +13 -19
  86. package/src/obligations/tuples.ts +3 -9
  87. package/src/parallel-worker.ts +30 -60
  88. package/src/parallel.ts +57 -71
  89. package/src/parser.ts +961 -387
  90. package/src/pcal/ast.ts +53 -86
  91. package/src/pcal/parse.ts +144 -219
  92. package/src/pcal/tokenize.ts +91 -131
  93. package/src/pcal/translate.ts +83 -130
  94. package/src/pcal/validate.ts +48 -68
  95. package/src/pretty-print.ts +7 -8
  96. package/src/prover/decide-pool.ts +8 -13
  97. package/src/prover/deciders.ts +19 -13
  98. package/src/prover/first-order.ts +0 -11
  99. package/src/prover/isabelle/decide.ts +3 -31
  100. package/src/prover/isabelle/encode.ts +82 -62
  101. package/src/prover/isabelle/isar/attrib.ts +219 -0
  102. package/src/prover/isabelle/isar/context.ts +336 -0
  103. package/src/prover/isabelle/isar/induct.ts +392 -0
  104. package/src/prover/isabelle/isar/inner-syntax.ts +262 -117
  105. package/src/prover/isabelle/isar/method.ts +513 -225
  106. package/src/prover/isabelle/isar/proof.ts +569 -23
  107. package/src/prover/isabelle/isar/rule-cases.ts +234 -0
  108. package/src/prover/isabelle/isar/theory.ts +490 -89
  109. package/src/prover/isabelle/isar/toplevel.ts +341 -0
  110. package/src/prover/isabelle/isar/type-check.ts +100 -37
  111. package/src/prover/isabelle/provers/blast/blast.ts +17 -104
  112. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  113. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  114. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  115. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  116. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  117. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  118. package/src/prover/isabelle/provers/classical.ts +59 -60
  119. package/src/prover/isabelle/provers/hypsubst.ts +28 -51
  120. package/src/prover/isabelle/pure/bicompose.ts +25 -38
  121. package/src/prover/isabelle/pure/consts.ts +1 -7
  122. package/src/prover/isabelle/pure/conv.ts +3 -17
  123. package/src/prover/isabelle/pure/drule.ts +96 -44
  124. package/src/prover/isabelle/pure/envir.ts +3 -52
  125. package/src/prover/isabelle/pure/goal.ts +2 -8
  126. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  127. package/src/prover/isabelle/pure/list.ts +0 -3
  128. package/src/prover/isabelle/pure/logic.ts +2 -15
  129. package/src/prover/isabelle/pure/name.ts +2 -9
  130. package/src/prover/isabelle/pure/net.ts +3 -59
  131. package/src/prover/isabelle/pure/object-logic.ts +16 -15
  132. package/src/prover/isabelle/pure/pattern.ts +2 -19
  133. package/src/prover/isabelle/pure/raw-simplifier.ts +17 -62
  134. package/src/prover/isabelle/pure/rewriter.ts +32 -73
  135. package/src/prover/isabelle/pure/search.ts +3 -10
  136. package/src/prover/isabelle/pure/seq.ts +1 -10
  137. package/src/prover/isabelle/pure/simplifier.ts +28 -15
  138. package/src/prover/isabelle/pure/table.ts +3 -32
  139. package/src/prover/isabelle/pure/tactic.ts +12 -22
  140. package/src/prover/isabelle/pure/tactical.ts +48 -47
  141. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  142. package/src/prover/isabelle/pure/term.ts +2 -43
  143. package/src/prover/isabelle/pure/thm.ts +27 -47
  144. package/src/prover/isabelle/pure/type.ts +2 -15
  145. package/src/prover/isabelle/pure/unify.ts +20 -30
  146. package/src/prover/isabelle/pure/variable.ts +3 -7
  147. package/src/prover/isabelle/tla/classical-setup.ts +18 -24
  148. package/src/prover/isabelle/tla/context.ts +65 -26
  149. package/src/prover/isabelle/tla/logic-data.ts +1 -1
  150. package/src/prover/isabelle/tla/logic.ts +53 -32
  151. package/src/prover/isabelle/tla/simpdata.ts +46 -43
  152. package/src/prover/isabelle/tools/intuitionistic.ts +29 -20
  153. package/src/prover/ocaml.ts +0 -6
  154. package/src/prover/prep/action.ts +32 -66
  155. package/src/prover/prep/enabled-axioms.ts +22 -20
  156. package/src/prover/prep/fingerprint.ts +2 -21
  157. package/src/prover/prep/level-comparison.ts +8 -12
  158. package/src/prover/prep/md5.ts +0 -2
  159. package/src/prover/prep/methods.ts +137 -83
  160. package/src/prover/prep/normalize.ts +38 -36
  161. package/src/prover/prove-worker.ts +0 -2
  162. package/src/prover/prove.ts +371 -132
  163. package/src/prover/ptl/decide.ts +104 -44
  164. package/src/prover/ptl/encode.ts +15 -38
  165. package/src/prover/ptl/sat.ts +24 -32
  166. package/src/prover/ptl/tableau.ts +40 -28
  167. package/src/prover/smt/arithmetic.ts +310 -0
  168. package/src/prover/smt/axioms.ts +12 -15
  169. package/src/prover/smt/context.ts +61 -29
  170. package/src/prover/smt/data.ts +497 -387
  171. package/src/prover/smt/encode.ts +156 -85
  172. package/src/prover/smt/extensionality.ts +5 -13
  173. package/src/prover/smt/flatten.ts +7 -28
  174. package/src/prover/smt/format.ts +33 -14
  175. package/src/prover/smt/instances.ts +7 -11
  176. package/src/prover/smt/layout.ts +91 -0
  177. package/src/prover/smt/rewrite.ts +1025 -658
  178. package/src/prover/smt/simplify.ts +441 -0
  179. package/src/prover/smt/solver/ackermannize-bv-tactic.ts +63 -0
  180. package/src/prover/smt/solver/ackr-helper.ts +182 -0
  181. package/src/prover/smt/solver/ackr-model-converter.ts +112 -0
  182. package/src/prover/smt/solver/act-cache.ts +0 -15
  183. package/src/prover/smt/solver/add-bounds-tactic.ts +60 -0
  184. package/src/prover/smt/solver/aig-tactic.ts +43 -0
  185. package/src/prover/smt/solver/aig.ts +890 -0
  186. package/src/prover/smt/solver/arith-rewriter.ts +613 -48
  187. package/src/prover/smt/solver/arith-terms.ts +123 -0
  188. package/src/prover/smt/solver/array-decl-plugin.ts +176 -0
  189. package/src/prover/smt/solver/array-rewriter.ts +312 -0
  190. package/src/prover/smt/solver/array.ts +1 -3
  191. package/src/prover/smt/solver/asserted-formulas.ts +87 -57
  192. package/src/prover/smt/solver/ast-lt.ts +166 -21
  193. package/src/prover/smt/solver/ast-util.ts +161 -7
  194. package/src/prover/smt/solver/ast.ts +1466 -178
  195. package/src/prover/smt/solver/auf-solver.ts +8 -44
  196. package/src/prover/smt/solver/bit-blast-tactic.ts +591 -0
  197. package/src/prover/smt/solver/bit-blaster.ts +874 -0
  198. package/src/prover/smt/solver/bound-manager.ts +186 -0
  199. package/src/prover/smt/solver/bound-simplifier.ts +602 -0
  200. package/src/prover/smt/solver/bv-bound-chk.ts +500 -0
  201. package/src/prover/smt/solver/bv-decl-plugin.ts +339 -0
  202. package/src/prover/smt/solver/bv-divrem-bounds.ts +97 -0
  203. package/src/prover/smt/solver/bv-rewriter.ts +1905 -0
  204. package/src/prover/smt/solver/bv1-blast.ts +224 -0
  205. package/src/prover/smt/solver/bv2fpa-converter.ts +175 -0
  206. package/src/prover/smt/solver/bv2int-rewriter.ts +545 -0
  207. package/src/prover/smt/solver/bv2real-rewriter.ts +534 -0
  208. package/src/prover/smt/solver/card2bv.ts +112 -0
  209. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  210. package/src/prover/smt/solver/cg-table.ts +28 -34
  211. package/src/prover/smt/solver/check-logic.ts +326 -0
  212. package/src/prover/smt/solver/clause.ts +1 -27
  213. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +280 -0
  214. package/src/prover/smt/solver/conflict-resolution.ts +79 -12
  215. package/src/prover/smt/solver/context.ts +510 -175
  216. package/src/prover/smt/solver/ctx-simplify.ts +34 -50
  217. package/src/prover/smt/solver/ctx-solver-simplify.ts +124 -0
  218. package/src/prover/smt/solver/datatype-decl-plugin.ts +575 -0
  219. package/src/prover/smt/solver/datatype-rewriter.ts +83 -0
  220. package/src/prover/smt/solver/demodulator.ts +789 -0
  221. package/src/prover/smt/solver/dependent-expr-state.ts +68 -0
  222. package/src/prover/smt/solver/der.ts +40 -30
  223. package/src/prover/smt/solver/diff-neq.ts +207 -0
  224. package/src/prover/smt/solver/distribute-forall.ts +67 -0
  225. package/src/prover/smt/solver/dom-simplify.ts +513 -0
  226. package/src/prover/smt/solver/dt2bv-tactic.ts +267 -0
  227. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  228. package/src/prover/smt/solver/e-matching.ts +4 -35
  229. package/src/prover/smt/solver/elim-small-bv-tactic.ts +130 -0
  230. package/src/prover/smt/solver/elim-uncnstr.ts +558 -0
  231. package/src/prover/smt/solver/enode.ts +93 -22
  232. package/src/prover/smt/solver/eq2bv-tactic.ts +219 -0
  233. package/src/prover/smt/solver/euf/arith-axioms.ts +404 -0
  234. package/src/prover/smt/solver/euf/arith-internalize.ts +659 -0
  235. package/src/prover/smt/solver/euf/arith-solver.ts +895 -0
  236. package/src/prover/smt/solver/euf/array-axioms.ts +528 -0
  237. package/src/prover/smt/solver/euf/array-internalize.ts +419 -0
  238. package/src/prover/smt/solver/euf/array-solver.ts +308 -0
  239. package/src/prover/smt/solver/euf/bv-ackerman.ts +164 -0
  240. package/src/prover/smt/solver/euf/bv-internalize.ts +750 -0
  241. package/src/prover/smt/solver/euf/bv-solver.ts +451 -0
  242. package/src/prover/smt/solver/euf/dt-solver.ts +620 -0
  243. package/src/prover/smt/solver/euf/egraph.ts +885 -0
  244. package/src/prover/smt/solver/euf/euf-solver.ts +1203 -0
  245. package/src/prover/smt/solver/euf/fpa-solver.ts +333 -0
  246. package/src/prover/smt/solver/euf/mam.ts +1094 -0
  247. package/src/prover/smt/solver/euf/q-ematch.ts +900 -0
  248. package/src/prover/smt/solver/euf/q-mbi.ts +587 -0
  249. package/src/prover/smt/solver/euf/q-model-fixer.ts +299 -0
  250. package/src/prover/smt/solver/euf/q-solver.ts +361 -0
  251. package/src/prover/smt/solver/euf/th-solver.ts +343 -0
  252. package/src/prover/smt/solver/euf/th-solvers.ts +31 -0
  253. package/src/prover/smt/solver/expr-ref.ts +1 -5
  254. package/src/prover/smt/solver/expr-safe-replace.ts +26 -6
  255. package/src/prover/smt/solver/expr2polynomial.ts +147 -0
  256. package/src/prover/smt/solver/factor.ts +152 -0
  257. package/src/prover/smt/solver/fd-solver.ts +269 -0
  258. package/src/prover/smt/solver/fingerprints.ts +16 -26
  259. package/src/prover/smt/solver/fix-dl-var.ts +149 -0
  260. package/src/prover/smt/solver/flat-literals.ts +1 -9
  261. package/src/prover/smt/solver/fm-tactic.ts +873 -0
  262. package/src/prover/smt/solver/fpa-decl-plugin.ts +619 -0
  263. package/src/prover/smt/solver/fpa-rewriter.ts +641 -0
  264. package/src/prover/smt/solver/fpa2bv-converter.ts +2246 -0
  265. package/src/prover/smt/solver/fpa2bv-rewriter.ts +349 -0
  266. package/src/prover/smt/solver/fpa2bv-tactic.ts +75 -0
  267. package/src/prover/smt/solver/goal.ts +177 -28
  268. package/src/prover/smt/solver/goal2nlsat.ts +191 -0
  269. package/src/prover/smt/solver/guard-set.ts +220 -0
  270. package/src/prover/smt/solver/hash.ts +0 -8
  271. package/src/prover/smt/solver/hashtable.ts +27 -23
  272. package/src/prover/smt/solver/inf-eps.ts +64 -0
  273. package/src/prover/smt/solver/inj-axiom.ts +102 -0
  274. package/src/prover/smt/solver/internalizer.ts +72 -130
  275. package/src/prover/smt/solver/lackr.ts +383 -0
  276. package/src/prover/smt/solver/lbool.ts +1 -2
  277. package/src/prover/smt/solver/lia2card.ts +269 -0
  278. package/src/prover/smt/solver/lia2pb.ts +141 -0
  279. package/src/prover/smt/solver/literal.ts +0 -3
  280. package/src/prover/smt/solver/logic-tactics.ts +349 -0
  281. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  282. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  283. package/src/prover/smt/solver/lp/containers.ts +12 -30
  284. package/src/prover/smt/solver/lp/core-solver.ts +24 -27
  285. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  286. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  287. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  288. package/src/prover/smt/solver/lp/dioph-eq.ts +9 -102
  289. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  290. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  291. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  292. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  293. package/src/prover/smt/solver/lp/int-cube.ts +18 -39
  294. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  295. package/src/prover/smt/solver/lp/lar-solver.ts +70 -82
  296. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  297. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  298. package/src/prover/smt/solver/lp/maximize-term.ts +79 -52
  299. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  300. package/src/prover/smt/solver/lp/nex.ts +1 -6
  301. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  302. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  303. package/src/prover/smt/solver/lp/nla-core.ts +69 -132
  304. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  305. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  306. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  307. package/src/prover/smt/solver/lp/nla-grobner.ts +24 -72
  308. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  309. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  310. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  311. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  312. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  313. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  314. package/src/prover/smt/solver/lp/nla-powers.ts +184 -0
  315. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  316. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  317. package/src/prover/smt/solver/lp/nla-transcendentals.ts +293 -0
  318. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  319. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  320. package/src/prover/smt/solver/lp/nra-solver.ts +30 -54
  321. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  322. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  323. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  324. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  325. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  326. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  327. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  328. package/src/prover/smt/solver/lp/union-find.ts +6 -5
  329. package/src/prover/smt/solver/macro-finder.ts +533 -0
  330. package/src/prover/smt/solver/mam-compiler.ts +117 -126
  331. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  332. package/src/prover/smt/solver/max-bv-sharing-tactic.ts +29 -0
  333. package/src/prover/smt/solver/max-cliques.ts +107 -0
  334. package/src/prover/smt/solver/maxcore.ts +318 -0
  335. package/src/prover/smt/solver/maximize-ac-sharing.ts +9 -20
  336. package/src/prover/smt/solver/maxlex.ts +123 -0
  337. package/src/prover/smt/solver/maxsmt-base.ts +99 -0
  338. package/src/prover/smt/solver/maxsmt.ts +93 -0
  339. package/src/prover/smt/solver/mbp/mbp-arith.ts +477 -0
  340. package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +102 -0
  341. package/src/prover/smt/solver/mbp/mbp-plugin.ts +280 -0
  342. package/src/prover/smt/solver/mbp/mbp-qel.ts +49 -0
  343. package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +280 -0
  344. package/src/prover/smt/solver/mbp/mbp-term-graph.ts +624 -0
  345. package/src/prover/smt/solver/model-based-opt.ts +845 -0
  346. package/src/prover/smt/solver/model-checker.ts +20 -62
  347. package/src/prover/smt/solver/model-evaluator.ts +186 -39
  348. package/src/prover/smt/solver/model-finder.ts +15 -32
  349. package/src/prover/smt/solver/model-generator.ts +57 -40
  350. package/src/prover/smt/solver/model-macro-solver.ts +58 -111
  351. package/src/prover/smt/solver/model-printer.ts +215 -0
  352. package/src/prover/smt/solver/mpf.ts +712 -0
  353. package/src/prover/smt/solver/mus.ts +52 -0
  354. package/src/prover/smt/solver/muz/dl-context.ts +362 -0
  355. package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +98 -0
  356. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +121 -0
  357. package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +121 -0
  358. package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +305 -0
  359. package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +427 -0
  360. package/src/prover/smt/solver/muz/dl-mk-slice.ts +278 -0
  361. package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +158 -0
  362. package/src/prover/smt/solver/muz/dl-rule-set.ts +303 -0
  363. package/src/prover/smt/solver/muz/dl-rule-transformer.ts +127 -0
  364. package/src/prover/smt/solver/muz/dl-rule.ts +460 -0
  365. package/src/prover/smt/solver/muz/hnf.ts +201 -0
  366. package/src/prover/smt/solver/muz/horn-tactic.ts +192 -0
  367. package/src/prover/smt/solver/muz/rule-properties.ts +179 -0
  368. package/src/prover/smt/solver/muz/spacer-context.ts +1395 -0
  369. package/src/prover/smt/solver/muz/spacer-dl-interface.ts +41 -0
  370. package/src/prover/smt/solver/muz/spacer-generalizers.ts +244 -0
  371. package/src/prover/smt/solver/muz/spacer-manager.ts +133 -0
  372. package/src/prover/smt/solver/muz/spacer-pdr.ts +219 -0
  373. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +344 -0
  374. package/src/prover/smt/solver/muz/spacer-util.ts +309 -0
  375. package/src/prover/smt/solver/muz/substitution.ts +154 -0
  376. package/src/prover/smt/solver/nla2bv-tactic.ts +286 -0
  377. package/src/prover/smt/solver/nlqsat.ts +484 -0
  378. package/src/prover/smt/solver/nlsat/algebraic.ts +179 -159
  379. package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
  380. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  381. package/src/prover/smt/solver/nlsat/explain.ts +61 -69
  382. package/src/prover/smt/solver/nlsat/interval-set.ts +10 -51
  383. package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
  384. package/src/prover/smt/solver/nlsat/mpbq.ts +48 -14
  385. package/src/prover/smt/solver/nlsat/polynomial.ts +30 -160
  386. package/src/prover/smt/solver/nlsat/solver.ts +227 -99
  387. package/src/prover/smt/solver/nlsat/transcendental-eval.ts +311 -0
  388. package/src/prover/smt/solver/nlsat/transcendentals.ts +369 -0
  389. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  390. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
  391. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  392. package/src/prover/smt/solver/nlsat-tactic.ts +83 -0
  393. package/src/prover/smt/solver/nnf.ts +108 -60
  394. package/src/prover/smt/solver/normalize-bounds.ts +54 -0
  395. package/src/prover/smt/solver/occf.ts +98 -0
  396. package/src/prover/smt/solver/opt-context.ts +787 -0
  397. package/src/prover/smt/solver/opt-nlsat.ts +366 -0
  398. package/src/prover/smt/solver/opt-pareto.ts +284 -0
  399. package/src/prover/smt/solver/opt-preprocess.ts +102 -0
  400. package/src/prover/smt/solver/opt-solver.ts +300 -0
  401. package/src/prover/smt/solver/opt-value.ts +56 -0
  402. package/src/prover/smt/solver/optsmt.ts +691 -0
  403. package/src/prover/smt/solver/parallel-tactic.ts +301 -0
  404. package/src/prover/smt/solver/pattern-inference.ts +19 -23
  405. package/src/prover/smt/solver/pb-rewriter.ts +296 -0
  406. package/src/prover/smt/solver/pb2bv-tactic.ts +542 -0
  407. package/src/prover/smt/solver/poly-rewriter.ts +203 -77
  408. package/src/prover/smt/solver/probes.ts +514 -0
  409. package/src/prover/smt/solver/propagate-values.ts +34 -30
  410. package/src/prover/smt/solver/proto-model.ts +648 -63
  411. package/src/prover/smt/solver/pull-quant.ts +29 -23
  412. package/src/prover/smt/solver/purify-arith.ts +598 -0
  413. package/src/prover/smt/solver/qe-arith-plugin.ts +1099 -0
  414. package/src/prover/smt/solver/qe-lite-der.ts +3 -31
  415. package/src/prover/smt/solver/qe-lite-fm.ts +5 -28
  416. package/src/prover/smt/solver/qe-lite.ts +40 -49
  417. package/src/prover/smt/solver/qe-mbp.ts +281 -0
  418. package/src/prover/smt/solver/qe.ts +1508 -0
  419. package/src/prover/smt/solver/qel.ts +26 -0
  420. package/src/prover/smt/solver/qi-queue.ts +1 -16
  421. package/src/prover/smt/solver/qsat.ts +840 -0
  422. package/src/prover/smt/solver/quant-hoist.ts +195 -0
  423. package/src/prover/smt/solver/quant-tactics.ts +18 -74
  424. package/src/prover/smt/solver/quantifier-analyzer.ts +27 -47
  425. package/src/prover/smt/solver/quantifier-manager.ts +9 -23
  426. package/src/prover/smt/solver/quasi-macros.ts +254 -0
  427. package/src/prover/smt/solver/random-gen.ts +1 -2
  428. package/src/prover/smt/solver/rational.ts +29 -8
  429. package/src/prover/smt/solver/recfun-decl-plugin.ts +248 -0
  430. package/src/prover/smt/solver/recfun-rewriter.ts +108 -0
  431. package/src/prover/smt/solver/reduce-args.ts +226 -0
  432. package/src/prover/smt/solver/reduce-bv-size.ts +120 -0
  433. package/src/prover/smt/solver/ref-vector.ts +1 -6
  434. package/src/prover/smt/solver/relevancy.ts +3 -16
  435. package/src/prover/smt/solver/rewriter-tpl.ts +49 -129
  436. package/src/prover/smt/solver/rewriter.ts +478 -120
  437. package/src/prover/smt/solver/rlimit.ts +27 -21
  438. package/src/prover/smt/solver/sat/asymm-branch.ts +314 -0
  439. package/src/prover/smt/solver/sat/big.ts +178 -0
  440. package/src/prover/smt/solver/sat/clause-use-list.ts +79 -0
  441. package/src/prover/smt/solver/sat/clause.ts +221 -0
  442. package/src/prover/smt/solver/sat/cleaner.ts +96 -0
  443. package/src/prover/smt/solver/sat/config.ts +125 -0
  444. package/src/prover/smt/solver/sat/consequences.ts +204 -0
  445. package/src/prover/smt/solver/sat/elim-eqs.ts +144 -0
  446. package/src/prover/smt/solver/sat/goal2sat.ts +528 -0
  447. package/src/prover/smt/solver/sat/inc-sat-solver.ts +388 -0
  448. package/src/prover/smt/solver/sat/model-converter.ts +156 -0
  449. package/src/prover/smt/solver/sat/pb-constraint.ts +264 -0
  450. package/src/prover/smt/solver/sat/pb-solver.ts +1553 -0
  451. package/src/prover/smt/solver/sat/probing.ts +169 -0
  452. package/src/prover/smt/solver/sat/sat-tactic.ts +44 -0
  453. package/src/prover/smt/solver/sat/sat2goal.ts +171 -0
  454. package/src/prover/smt/solver/sat/scc.ts +143 -0
  455. package/src/prover/smt/solver/sat/simplifier.ts +1662 -0
  456. package/src/prover/smt/solver/sat/solver.ts +2128 -0
  457. package/src/prover/smt/solver/sat/var-queue.ts +119 -0
  458. package/src/prover/smt/solver/sat/watch-list.ts +136 -0
  459. package/src/prover/smt/solver/search-tree.ts +285 -0
  460. package/src/prover/smt/solver/seq-axioms.ts +1013 -0
  461. package/src/prover/smt/solver/seq-decl-plugin.ts +823 -0
  462. package/src/prover/smt/solver/seq-derive.ts +1303 -0
  463. package/src/prover/smt/solver/seq-eq-approx.ts +238 -0
  464. package/src/prover/smt/solver/seq-eq-solver.ts +440 -0
  465. package/src/prover/smt/solver/seq-factory.ts +91 -0
  466. package/src/prover/smt/solver/seq-monadic.ts +730 -0
  467. package/src/prover/smt/solver/seq-range-predicate.ts +225 -0
  468. package/src/prover/smt/solver/seq-re-rewriter.ts +1296 -0
  469. package/src/prover/smt/solver/seq-re-util.ts +777 -0
  470. package/src/prover/smt/solver/seq-regex-bisim.ts +145 -0
  471. package/src/prover/smt/solver/seq-regex-live.ts +202 -0
  472. package/src/prover/smt/solver/seq-regex-witness.ts +100 -0
  473. package/src/prover/smt/solver/seq-rewriter.ts +2407 -0
  474. package/src/prover/smt/solver/seq-skolem.ts +318 -0
  475. package/src/prover/smt/solver/seq-subset.ts +166 -0
  476. package/src/prover/smt/solver/seq-view-witness.ts +355 -0
  477. package/src/prover/smt/solver/smt-consequences.ts +299 -0
  478. package/src/prover/smt/solver/smt-kernel.ts +85 -0
  479. package/src/prover/smt/solver/smt-logics.ts +67 -0
  480. package/src/prover/smt/solver/smt-setup.ts +492 -0
  481. package/src/prover/smt/solver/smt2-printer.ts +767 -0
  482. package/src/prover/smt/solver/smtlib-parser.ts +2423 -270
  483. package/src/prover/smt/solver/smtlib-script.ts +1493 -0
  484. package/src/prover/smt/solver/solve-eqs.ts +931 -0
  485. package/src/prover/smt/solver/solver.ts +120 -39
  486. package/src/prover/smt/solver/sort.ts +1 -5
  487. package/src/prover/smt/solver/static-features.ts +319 -0
  488. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  489. package/src/prover/smt/solver/tactic.ts +1936 -0
  490. package/src/prover/smt/solver/term-enumeration.ts +206 -0
  491. package/src/prover/smt/solver/theory-array.ts +1275 -0
  492. package/src/prover/smt/solver/theory-bv.ts +1239 -0
  493. package/src/prover/smt/solver/theory-char.ts +356 -0
  494. package/src/prover/smt/solver/theory-datatype.ts +599 -0
  495. package/src/prover/smt/solver/theory-finite-set.ts +30 -0
  496. package/src/prover/smt/solver/theory-fpa.ts +422 -0
  497. package/src/prover/smt/solver/theory-lra-axioms.ts +56 -25
  498. package/src/prover/smt/solver/theory-lra-bounds.ts +31 -10
  499. package/src/prover/smt/solver/theory-lra-final-check.ts +60 -91
  500. package/src/prover/smt/solver/theory-lra-internalize.ts +87 -53
  501. package/src/prover/smt/solver/theory-lra-model.ts +24 -53
  502. package/src/prover/smt/solver/theory-lra-propagate.ts +25 -40
  503. package/src/prover/smt/solver/theory-lra-state.ts +7 -27
  504. package/src/prover/smt/solver/theory-lra.ts +194 -8
  505. package/src/prover/smt/solver/theory-pb.ts +932 -0
  506. package/src/prover/smt/solver/theory-polymorphism.ts +59 -0
  507. package/src/prover/smt/solver/theory-recfun.ts +308 -0
  508. package/src/prover/smt/solver/theory-seq-regex.ts +871 -0
  509. package/src/prover/smt/solver/theory-seq-solve.ts +1375 -0
  510. package/src/prover/smt/solver/theory-seq-state.ts +880 -0
  511. package/src/prover/smt/solver/theory-seq.ts +984 -0
  512. package/src/prover/smt/solver/theory.ts +175 -0
  513. package/src/prover/smt/solver/tseitin-cnf.ts +487 -0
  514. package/src/prover/smt/solver/var-subst.ts +33 -35
  515. package/src/prover/smt/table.ts +1 -9
  516. package/src/prover/smt/types.ts +146 -0
  517. package/src/prover/tlapm/cache.ts +67 -41
  518. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  519. package/src/prover/tlapm/tlapm.ts +21 -20
  520. package/src/prover/tlapm-library.ts +3208 -0
  521. package/src/prover/verdict.ts +9 -2
  522. package/src/prover/zenon/check/check.ts +1 -11
  523. package/src/prover/zenon/check/definitions.ts +5 -15
  524. package/src/prover/zenon/check/equality.ts +0 -8
  525. package/src/prover/zenon/check/functions.ts +0 -4
  526. package/src/prover/zenon/check/keys.ts +0 -7
  527. package/src/prover/zenon/check/propositional.ts +0 -3
  528. package/src/prover/zenon/check/records.ts +1 -6
  529. package/src/prover/zenon/check/relations.ts +2 -14
  530. package/src/prover/zenon/check/rewrites.ts +2 -21
  531. package/src/prover/zenon/check/sets.ts +40 -61
  532. package/src/prover/zenon/check/terms.ts +1 -19
  533. package/src/prover/zenon/check/tla.ts +0 -6
  534. package/src/prover/zenon/decide.ts +10 -15
  535. package/src/prover/zenon/encode.ts +1 -8
  536. package/src/prover/zenon/eqrel.ts +2 -13
  537. package/src/prover/zenon/equality-rules.ts +0 -4
  538. package/src/prover/zenon/expr.ts +8 -26
  539. package/src/prover/zenon/index-table.ts +26 -57
  540. package/src/prover/zenon/isar-case.ts +9 -19
  541. package/src/prover/zenon/isar.ts +36 -64
  542. package/src/prover/zenon/limits.ts +0 -4
  543. package/src/prover/zenon/llproof.ts +2 -20
  544. package/src/prover/zenon/mltoll.ts +66 -104
  545. package/src/prover/zenon/node.ts +20 -14
  546. package/src/prover/zenon/ocaml.ts +1 -17
  547. package/src/prover/zenon/parse.ts +10 -12
  548. package/src/prover/zenon/phrase.ts +1 -11
  549. package/src/prover/zenon/proof.ts +0 -9
  550. package/src/prover/zenon/propositional-rules.ts +0 -5
  551. package/src/prover/zenon/rules.ts +2 -6
  552. package/src/prover/zenon/search.ts +11 -33
  553. package/src/prover/zenon/tla/functions.ts +59 -31
  554. package/src/prover/zenon/tla/llproof.ts +67 -76
  555. package/src/prover/zenon/tla/records.ts +57 -33
  556. package/src/prover/zenon/tla/rewrites.ts +12 -19
  557. package/src/prover/zenon/tla/sets.ts +88 -57
  558. package/src/prover/zenon/tla/terms.ts +0 -6
  559. package/src/prover/zenon/tla/tla.ts +66 -64
  560. package/src/randomization.ts +81 -35
  561. package/src/resolve.ts +67 -184
  562. package/src/runtime.ts +22 -22
  563. package/src/sany/builtins.ts +2 -5
  564. package/src/sany/generation.ts +394 -0
  565. package/src/sany/generator-def-entries.ts +210 -0
  566. package/src/sany/generator-definitions.ts +686 -0
  567. package/src/sany/generator-expressions.ts +1100 -0
  568. package/src/sany/generator-proofs.ts +662 -0
  569. package/src/sany/generator.ts +191 -2764
  570. package/src/sany/levels.ts +6 -34
  571. package/src/sany/lexer.ts +58 -77
  572. package/src/sany/linter.ts +1 -9
  573. package/src/sany/modules.ts +1 -5
  574. package/src/sany/nodes.ts +5 -43
  575. package/src/sany/parse-error.ts +39 -117
  576. package/src/sany/report.ts +32 -69
  577. package/src/sany/selectors.ts +49 -76
  578. package/src/sany/source.ts +1 -17
  579. package/src/sany/xml.ts +35 -117
  580. package/src/search.ts +541 -163
  581. package/src/simulate.ts +709 -0
  582. package/src/spec-description.ts +192 -100
  583. package/src/standard-definitions.ts +0 -4
  584. package/src/standard-modules.ts +264 -95
  585. package/src/state-graph.ts +52 -31
  586. package/src/subexpressions.ts +69 -52
  587. package/src/substitution-levels.ts +7 -7
  588. package/src/successors.ts +266 -99
  589. package/src/symmetry.ts +33 -25
  590. package/src/tableau.ts +27 -24
  591. package/src/tlc/fingerprint.ts +183 -67
  592. package/src/tlc/jar-data.ts +112 -6
  593. package/src/tlc/messages.ts +125 -54
  594. package/src/tlc/order.ts +39 -69
  595. package/src/tlc/random.ts +37 -49
  596. package/src/tlc/replay.ts +553 -228
  597. package/src/tlc/summary.ts +36 -47
  598. package/src/tlc/tlc-operators.ts +78 -44
  599. package/src/tlc/tlcext-operators.ts +139 -122
  600. package/src/tlc/trace-spec.ts +249 -0
  601. package/src/tlc/value-stream.ts +139 -0
  602. package/src/tlc/version.ts +1 -4
  603. package/src/transfer.ts +22 -25
  604. package/src/typescript/actions.ts +479 -0
  605. package/src/typescript/collections.ts +614 -0
  606. package/src/typescript/compile.ts +63 -0
  607. package/src/typescript/context.ts +94 -0
  608. package/src/typescript/emit.ts +121 -0
  609. package/src/typescript/expressions.ts +496 -0
  610. package/src/typescript/formula.ts +154 -0
  611. package/src/typescript/functions.ts +284 -0
  612. package/src/typescript/model.ts +162 -0
  613. package/src/typescript/names.ts +114 -0
  614. package/src/typescript/program.ts +48 -0
  615. package/src/typescript/properties.ts +139 -0
  616. package/src/typescript/scope.ts +112 -0
  617. package/src/typescript/steps.ts +167 -0
  618. package/src/typescript/types.ts +171 -0
  619. package/src/values.ts +832 -484
  620. package/src/worker.ts +7 -8
  621. package/src/prover/isabelle/isar/statement.ts +0 -57
  622. package/src/prover/tlaps-module.ts +0 -510
package/dist/prove.cjs CHANGED
@@ -6,44 +6,145 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- const e=require("./worker.cjs"),t=require("./transfer.cjs"),n=require("./deciders.cjs"),r=[`CONSTANT`,`CONSTANTS`,`INIT`,`NEXT`,`SPECIFICATION`,`INVARIANT`,`INVARIANTS`,`PROPERTY`,`PROPERTIES`,`CONSTRAINT`,`CONSTRAINTS`,`ACTION_CONSTRAINT`,`ACTION_CONSTRAINTS`,`SYMMETRY`,`VIEW`,`CHECK_DEADLOCK`],i=/* @__PURE__ */ new Set([...r,`ALIAS`,`POSTCONDITION`,`POSTCONDITIONS`,`_POSSIBLE`,`_PERIODIC`,`_RL_REWARD`]),a=[`TYPE`,`TYPE_CONSTRAINT`],o=/* @__PURE__ */ new Set([...r,...a]),s=[`<-`,`<<`,`>>`,`=`,`{`,`}`,`,`,`[`,`]`,`(`,`)`,`!`],c=e=>{let n=[],r={index:0,line:1,lineStart:0},i=(i,a)=>{n.push({kind:`Error`,text:t.Gt(r.line,i-r.lineStart+1,e[i],a),line:r.line})},a=e=>{n.push({kind:`Error`,text:t.Gt(r.line+1,0,void 0,e),line:r.line})},o=e=>{let t=e.split(`
10
- `);t.length>1&&(r.line+=t.length-1,r.lineStart=r.index+e.length-t[t.length-1].length),r.index+=e.length};for(;r.index<e.length;){let c=e.slice(r.index),l=/^\s+/.exec(c)?.[0];if(l){o(l);continue}if(c.startsWith(`\\*`)){let e=c.indexOf(`
11
- `);o(e===-1?c:c.slice(0,e));continue}if(c.startsWith(`(*`)){let e=c.indexOf(`*)`);if(e===-1)return o(c),a(``),n;o(c.slice(0,e+2));continue}let u=r.line,d=/^\d+(?![A-Za-z_])/.exec(c)?.[0];if(d){n.push({kind:`Number`,text:d,line:u}),o(d);continue}let f=/^[A-Za-z0-9_]+/.exec(c)?.[0];if(f){n.push({kind:`Word`,text:f,line:u}),o(f);continue}if(c.startsWith(`"`)){let t=/^"((?:[^"\\\n]|\\[^\n])*)("?)/.exec(c),s=t?.[0]??`"`;if(t?.[2]!==`"`)return o(s),r.index===e.length?a(`${s}\n`):i(r.index,s),n;n.push({kind:`String`,text:t[1],line:u}),o(s);continue}let p=s.find(e=>c.startsWith(e));if(p){n.push({kind:`Symbol`,text:p,line:u}),o(p);continue}let m=t.Yt(e,r.index)??t.Jt(e,r.index);if(!m)return i(r.index,``),n;n.push({kind:`Word`,text:m.text,line:u}),o(e.slice(r.index,r.index+m.length))}return n.push({kind:`End`,text:``,line:r.line}),n},l=(t,n)=>new e.h(`TLC found an error in the configuration file at line ${t}\n${n}`),u=(e,t)=>l(e,`The keyword ${t} appeared twice.`),d=/* @__PURE__ */ new Map([[`INIT`,`init`],[`NEXT`,`next`],[`SPECIFICATION`,`specification`],[`VIEW`,`view`],[`SYMMETRY`,`symmetry`],[`ALIAS`,`alias`],[`_PERIODIC`,`periodic`],[`_RL_REWARD`,`rlReward`]]),f=/* @__PURE__ */ new Map([[`INVARIANT`,`invariants`],[`INVARIANTS`,`invariants`],[`PROPERTY`,`properties`],[`PROPERTIES`,`properties`],[`CONSTRAINT`,`constraints`],[`CONSTRAINTS`,`constraints`],[`ACTION_CONSTRAINT`,`actionConstraints`],[`ACTION_CONSTRAINTS`,`actionConstraints`],[`POSTCONDITION`,`postconditions`],[`POSTCONDITIONS`,`postconditions`],[`_POSSIBLE`,`possible`]]),p=(t,n=`master`)=>{let r=n===`1.7.4`?o:i,s=c(t),p={index:0},m={init:void 0,next:void 0,specification:void 0,invariants:[],properties:[],constraints:[],actionConstraints:[],constants:[],substitutions:[],checkDeadlock:!0,symmetry:void 0,view:void 0,alias:void 0,postconditions:[],possible:[],periodic:void 0,rlReward:void 0},h={isSet:!1},g=/* @__PURE__ */ new Set,_=()=>{let t=s[Math.min(p.index++,s.length-1)];if(t.kind===`Error`)throw new e.h(`TLC found an error in the configuration file:\n${t.text}`);return t},v=e=>{if(e.kind===`Number`)return{kind:`Number`,value:Number(e.text)};if(e.kind===`String`)return{kind:`String`,value:e.text};if(e.text===`TRUE`||e.text===`FALSE`)return{kind:`Boolean`,value:e.text===`TRUE`};if(e.text===`{`){let e=[],t={token:_()};if(t.token.text!==`}`)for(;e.push(v(t.token)),t.token=_(),t.token.text===`,`;)t.token=_();if(t.token.text!==`}`)throw l(t.token.line,`It was expecting }, but did not find it.`);return{kind:`Set`,elements:e}}if(e.kind!==`End`)return{kind:`ModelValue`,name:e.text};throw l(e.line,`It was expecting a value, but did not find it.`)},y=e=>{let t=_();if(t.kind===`End`)throw l(t.line,`Expected an identifier after ${e}[.`);let n=_();if(n.text!==`]`)throw l(n.line,`It was expecting ], but did not find it.`);return t.text},b=e=>{for(;;){let t=_();if(t.kind===`End`||r.has(t.text))return t;let n={token:_(),name:t.text};for(;n.token.text===`!`;)n.name=`${n.name}!${_().text}`,n.token=_();let i=n.name;if(n.token.text===`<-`){if(n.token=_(),n.token.text===`[`){let e=y(`<-`),t=_();if(t.kind===`End`)throw l(t.line,`Expected an identifier after <-[mod].`);m.substitutions.push({name:i,target:t.text,module:e});continue}if(n.token.kind===`End`)throw l(n.token.line,`Expected an identifier after <-.`);m.substitutions.push({name:i,target:n.token.text});continue}let a=[],o=n.token.text===`(`;if(o){for(;a.push(v(_())),n.token=_(),n.token.text===`,`;);if(n.token.text!==`)`)throw l(e,``);n.token=_()}if(n.token.text!==`=`)throw l(n.token.line,`It was expecting = or <-, but did not find it.`);n.token=_();let s=n.token.text===`[`?y(`=`):void 0,c=v(s===void 0?n.token:_());m.constants.push({name:i,value:c,...o&&{args:a},...s!==void 0&&{module:s}})}},ee=e=>{for(;;){let t=_();if(t.kind===`End`||r.has(t.text))return t;e.push(t.text)}},x={token:_()};for(;x.token.kind!==`End`;){let e=x.token.text,t=x.token.line,n=r.has(e)?d.get(e):void 0,i=r.has(e)?f.get(e):void 0,o=()=>{let n=_();if(n.kind===`End`)throw l(t,`The keyword ${e} was not followed by an identifier.`);return n};if(n!==void 0){let r=o();if(m[n]!==void 0)throw u(t,e);m[n]=r.text,x.token=_()}else if(i!==void 0)x.token=ee(m[i]);else if(e===`CONSTANT`||e===`CONSTANTS`)x.token=b(t);else if(e===`CHECK_DEADLOCK`){let n=o();if(n.text!==`TRUE`&&n.text!==`FALSE`)throw l(n.line,`It was expecting TRUE or FALSE, but did not find it.`);if(h.isSet)throw u(t,e);h.isSet=!0,m.checkDeadlock=n.text===`TRUE`,x.token=_()}else{if(!r.has(e)||!a.includes(e))throw l(t,`It was expecting a keyword, but did not find it.`);if(o(),g.has(e))throw u(t,e);g.add(e),x.token=_()}}return m},m=e=>{switch(e.kind){case`Always`:return!0;case`Eventually`:case`Not`:case`Next`:return m(e.body);case`And`:case`Or`:return e.operands.some(m);default:return!1}},h=e=>e.promises.some(e=>m(e.body))||e.models.some(e=>e.eventuallyAlways.length>0||e.infinitelyOftenStates.length>0||e.infinitelyOftenActions.length>0),g=(e,n)=>e.every((e,r)=>t.Rt(e,n[r])),_=e=>e.filter((t,n)=>n===0||e[n-1]!==t),v=e=>({data:e(1024),length:0,create:e}),y=(e,t,n)=>{let r=t+n.length;if(r>e.data.length){let t=e.create(Math.max(2*e.data.length,r));t.set(e.data),e.data=t}e.data.set(n,t),e.length=Math.max(e.length,r)},b=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},ee=e=>new Int32Array(e).fill(-1),x=(e,t)=>(e.edgeStarts[t]??-1)!==-1,te=(e,t)=>{let n=e.edgeStarts[t];return e.edgeTargets.data.subarray(n,n+e.edgeCounts[t])},ne=(e,t,n)=>e.stateResults.data[e.nodeStates[t]*e.solution.stateChecks.length+n]===1,S=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.edgeStarts.push(-1),e.edgeCounts.push(0),e.nextSiblings.push(-1),e.nodeStates.length-1),re=(e,t)=>{let n=[];for(let r=e.firstNodes.data[t]??-1;r!==-1;r=e.nextSiblings[r])n.push(r);return n},ie=2**53-1,ae=(n,r,i,a)=>{if(n.length===0)return;let o=r.map(e=>t.E(e.expression,e.scope,i)),s=n.map(e=>t.O(`Not`,t.E(e.expression,e.scope,i))),c=s.length===1?s[0]:t.D(`Or`,s),l=o.length===0?c:t.D(`And`,[...o,c]),u=t.k(l);if(u.length===0)throw t.S();let d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let n=t.A(e),r=d.get(n)??d.size;return d.set(n,r),r}),nodeStates:[],nodeTableaux:[],edgeStarts:[],edgeCounts:[],edgeTargets:v(e=>new Int32Array(e)),edgeActions:v(e=>new Uint8Array(e)),stateResults:v(e=>new Uint8Array(e)),initial:[],firstNodes:v(ee),lastNodes:v(ee),nextSiblings:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),p={multiplier:1},m=!t.et(i),ae={environment:i},C={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},oe=e=>{let t=C.states.get(e)??/* @__PURE__ */ new Map;return C.states.set(e,t),t},se=(e,t)=>{i.runtime.setLivenessSource(e);let n=t();return i.runtime.setLivenessSource(void 0),n},ce=(e,n)=>t.C(e,n,void 0,ae.environment,m?oe(n):/* @__PURE__ */ new Map),le=(e,t,n)=>se(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!ce(e,n))),w=(e,n,r,i)=>se(n,()=>{let n=e.solution.actionChecks;if(!m)return Uint8Array.from(n,e=>+!!t.C(e,r,i,ae.environment,/* @__PURE__ */ new Map));let a=oe(r),o=C.actions.get(r)??/* @__PURE__ */ new Map;C.actions.set(r,o);let s=o.get(i)??new Int8Array(d.size).fill(-1);return o.set(i,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!t.C(n[o],r,i,ae.environment,a)),s[e]))}),ue=(e,t,n,r)=>se(n,()=>e.nodes[t].statePredicates.every(e=>ce(e,r))),de=(e,t)=>{if(i.runtime.version===`1.7.4`)return!1;let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},fe=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),pe=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=b(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},me=(e,t,n)=>{let r=S(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),b(i,e[t]-1,e[t+1]))}i.slots.set([t+1,n,r],b(i,t,n));let a=e.lastNodes.data[t]??-1;return a===-1?y(e.firstNodes,t,[r]):e.nextSiblings[a]=r,y(e.lastNodes,t,[r]),r},he=(e,t,n,r,i)=>{let a=e.edgeTargets.length,o=e.solution.actionChecks.length;y(e.edgeTargets,a,n),r.forEach((t,n)=>y(e.edgeActions,(a+n)*o,t)),y(e.stateResults,e.nodeStates[t]*i.length,i),e.edgeStarts[t]=a,e.edgeCounts[t]=n.length},ge=(e,t,n)=>{let r={slots:Array.from({length:16*p.multiplier}),count:0},i=(e,t)=>{for(let n=(a.getFingerprint(t)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&g(r.state,t.state))return!1}},o=e=>{if(r.count>=r.slots.length>>1){let e=r.slots;r.slots=Array.from({length:2*e.length+1});for(let t of e)t&&i(r.slots,t)}i(r.slots,e)&&r.count++};return n.forEach(o),o({index:e,state:t}),r.slots.length>16*p.multiplier&&p.multiplier++,r.slots.filter(e=>e!==void 0)},_e=(e,t,n,r,i)=>{let o=le(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=[],u=s.successors.length>0?w(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!ue(t,a,r,n))continue;if(de(t,a)&&e.errorNode===void 0&&fe(e)){e.errorNode=i;return}let o=pe(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??me(e,r,a);l.push(s),c.push(u),o===void 0&&_e(e,t,n,r,s)}for(let i of a.getSuccessors(r,n)){let a=w(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!ue(t,n,r,i.state)||i.index===-1)continue;let s=pe(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??me(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&_e(e,t,i.state,i.index,u)}}l.length>0&&he(e,i,l,c,o)},ve=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>ue(t,r,a,e.state)));e.isDone[a]=!0;for(let s of re(e,a)){let a=[],c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=pe(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??me(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&_e(e,t,n.state,n.index,d)}}),he(e,s,a,c,i)}if(e.errorNode!==void 0)return _(be(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},ye=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)S(e,e.nodeStates.length,-1);let a=[],o=[];t.forEach((t,r)=>{x(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),he(e,i,a,o,r)},be=(t,n)=>{if(t.initial.includes(n))return[n];let r=/* @__PURE__ */ new Map,i=[];for(let e of t.initial)x(t,e)&&(i.push(e),r.set(e,-1));for(let e=0;e<i.length;e++){let a=i[e];for(let e of te(t,a))if(!(e===a&&t.solution.tableau)){if(e===n){let e=[n];for(let t=a;t!==-1;t=r.get(t)??-1)e.push(t);return e}x(t,e)&&!r.has(e)&&(r.set(e,a),i.push(e))}}throw new e._(`Couldn't re-create liveness trace (path) starting at: ${n}`)},xe=(n,r)=>{let i=n.solution,a=i.actionChecks.length,o=(e,t,r)=>n.edgeActions.data[(n.edgeStarts[e]+t)*a+r]===1,s=(e,t)=>r.eventuallyAlways.every(n=>o(e,t,n)),c=new Float64Array(n.nodeStates.length).fill(-1),l=n.initial.filter(e=>x(n,e)),u=[],d=e=>{let t=te(n,e).indexOf(e);return t!==-1&&s(e,t)},f=(e,r)=>i.tableau!==void 0&&t.j(i.tableau.nodes[n.nodeTableaux[e]].particle,r),p=e=>{let t=u.pop()??e;if(t===e&&!d(t)){c[t]=ie;return}let a=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Map;for(let r=t;;r=u.pop()??e){a.add(r);let t=l.get(n.nodeStates[r]);if(t?t.push(r):l.set(n.nodeStates[r],[r]),c[r]=ie,r===e)break}let p=r.infinitelyOftenStates.every(e=>[...a].some(t=>ne(n,t,e))),h=r.infinitelyOftenActions.every(e=>[...a].some(t=>te(n,t).some((n,r)=>a.has(n)&&s(t,r)&&o(t,r,e)))),g=i.promises.every(e=>[...a].some(t=>f(t,e)));if(p&&h&&g)return m(e,a,l)},m=(t,a,c)=>{let l=_(be(n,t).reverse().map(e=>n.nodeStates[e])),u=[],d=/* @__PURE__ */ new Set([t]),p=r.infinitelyOftenStates.map(()=>!1),m=r.infinitelyOftenActions.map(()=>!1),v=i.promises.map(()=>!1),y={count:p.length+m.length+v.length},b={node:t},ee=e=>a.has(e),x=e=>{u.push(b.node),b.node=e};for(;y.count>0;){let t=y.count;for(;r.infinitelyOftenStates.forEach((e,t)=>{!p[t]&&ne(n,b.node,e)&&(p[t]=!0,y.count--)}),i.promises.forEach((e,t)=>{!v[t]&&f(b.node,e)&&(v[t]=!0,y.count--)}),!(y.count<=0);){let i={last:-1,unvisited:-1},a=y.count;if(te(n,b.node).some((e,t)=>{if(c.has(n.nodeStates[e])){if(!ee(e)||!s(b.node,t))return!1;i.last=e,r.infinitelyOftenActions.forEach((e,n)=>{!m[n]&&o(b.node,t,e)&&(m[n]=!0,y.count--)})}return y.count<a?(x(e),d.clear(),!0):(ee(e)&&!d.has(e)&&(i.unvisited=e),!1)}))break;if(y.count<t){x(i.last),d.clear();break}for(;i.unvisited===-1;){let t=u.pop();if(t===void 0)throw new e._(`TLC failed to build the counterexample of a liveness property`);b.node=t,i.unvisited=te(n,t).find(e=>ee(e)&&!d.has(e))??-1}x(i.unvisited),d.add(i.unvisited)}}let S=g(t,b.node,c,s);for(let e=u.length-1;e>=0;e--){let t=n.nodeStates[u[e]];S[S.length-1]!==t&&S.push(t)}let re=l[l.length-1];return S[S.length-1]===re&&S.pop(),{prefix:l.slice(0,-1),cycle:[re,...S.reverse()],isCycleConstrained:h(i)}},g=(t,r,i,a)=>{if(r===t)return[];let o=n.nodeStates[r],s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set([o]),l=[];for(let r=o,u=-1,d=0;;d++){for(let e of i.get(r)??[])for(let[d,f]of te(n,e).entries()){if(f===e||!a(e,d))continue;if(f===t){let e=[];for(let t=r,n=u;t!==o;)e.push(t),t=n,n=s.get(t)??-1;return e.push(o),e}let p=n.nodeStates[f];i.has(p)&&!c.has(p)&&(c.add(p),l.push([p,r]))}s.set(r,u);let f=l[d];if(f===void 0)throw new e._(`TLC failed to build the counterexample of a liveness property`);r=f[0],u=f[1]}};for(let e=0;e<l.length;e++){let t=[l[e],-1,0],r={link:0};for(;t.length>=3;){let e=t.pop()??0,i=t.pop(),a=t.pop()??0;if(i===-42){if(c[a]===e){let e=p(a);if(e)return e}t.push(Math.min(t.pop()??e,e));continue}if(c[a]!==-1){t.push(Math.min(e,c[a]));continue}c[a]=r.link,t.push(e,a,-42),u.push(a);let o={value:r.link++};te(n,a).forEach((e,r)=>{x(n,e)&&(s(a,r)?c[e]===-1?t.push(e,-1):o.value=Math.min(o.value,c[e]):c[e]===-1&&l.push(e))}),t.push(o.value)}}};return{branches:f.length,addInitialState:(e,t,n)=>{ae.environment=n??i,C.states.clear(),C.actions.clear();try{for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)ue(r,i,void 0,t)&&n.initial.push(pe(n,e,i)??me(n,e,i))}}finally{ae.environment=i}},addState:(e,t,n,r)=>{ae.environment=r??i,C.states.clear(),C.actions.clear();try{let r=ge(e,t,n);for(let n of f){let i=r.map(r=>w(n,e,t,r.state)),a=le(n,e,t),o=n.solution.tableau;if(!o){ye(n,r,i,a,e);continue}let s=ve(n,o,r,i,a,e);if(s)return s}return}finally{ae.environment=i}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=xe(e,t);if(n)return n}},getViolatedProperties:(e,r)=>[...new Set(n.filter((n,a)=>!t.w(s[a].body,e,r,0,i)).map(e=>e.name))]}},C=`UnnamedAction`,oe={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},se=e=>{let n=e.range??oe;return t.Dt([[`beginLine`,n.start.line],[`beginColumn`,n.start.column],[`endLine`,n.end.line],[`endColumn`,n.end.column],[`module`,n.module]])},ce=e=>{let n=[[`name`,e.name],[`location`,se(e.location)]];return e.parameters.length===0?t.Dt(n):t.Dt([...n,[`context`,t.Dt(e.parameters)],[`parameters`,t.kt(e.parameters.map(e=>e[0]))]])},le=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),w=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),ue=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,de=e=>e.kind===`Apply`?e.args:[],fe=(e,n,r)=>{let i=ue(e);if(i===void 0)return;if(t.Wt(e)){let e=t.nt(n,i);return e?.kind===`Operator`&&e.operator.kind===`Closure`?e.operator:void 0}if(r.constants.has(i)||r.variableIndex.has(i))return;let a=t.rt(i,r);return a?.kind===`Closure`?a:void 0},pe=(n,r)=>{try{return t.X(n,w(r,void 0)),!0}catch(t){if(t instanceof e.g)return!1;throw t}},me=(e,n)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&t.ut(e,n)&&pe(e.body,n),he=(e,n)=>{let r=t.$(e.name,n);return r?.body===e.body&&me(r,n)},ge=(e,n)=>{if(e.kind!==`Identifier`||!t.Wt(e))return;let r=t.nt(n,e.name);return r?.kind===`Thunk`?r:void 0},_e=(e,n)=>(e?.params??[]).flatMap(e=>{let r=t.nt(n,e.name);return r?.kind===`Value`?[[e.name,r.value]]:[]}),ve=(t,n)=>{try{return t()}catch(t){if(t instanceof e.g)return n();throw t}},ye=(e,n,r,i,a)=>{let o=de(n),s=()=>[{name:e.name,location:n.location,parameters:[],expression:n,scope:r}];return!i||o.length===0?[{...e,parameters:[],expression:n,scope:r}]:o.some(e=>t.T(e,r,a)!==0)?s():ve(()=>[{...e,parameters:o.map((e,n)=>[i.params[n].name.replace(/#\d+$/,``),t.X(e,w(a,r))]),expression:n,scope:r}],s)},be=(e,n,r,i,a)=>{let o=()=>({name:r?.name??C,location:e.location,parameters:_e(r,n),expression:e,scope:n});switch(e.kind){case`Let`:return be(e.body,t.K(e.definitions,w(i,n)),r,i,a);case`Label`:return be(e.body,n,r,i,a);case`Or`:return e.operands.flatMap(e=>be(e,n,r,i,a));case`Exists`:return ve(()=>{let s=[];return t.Z(e.bounds,w(i,n),t=>(s.push(...be(e.body,t,r,i,a)),!1)),s.length===0?[o()]:s},()=>[o()])}let s=t.Wt(e)?void 0:a.get(ue(e)??``),c=fe(e,n,i);if(s)return ye(s,e,n,c,i);if(!c)return[o()];let l=de(e),u=t.Wt(e)?c.name:i.instanceNames.get(ue(e)??``)??c.name,d=()=>[{name:u,location:e.location,parameters:[],expression:e,scope:n}];return he(c,i)||l.some(e=>t.T(e,n,i)!==0)?d():ve(()=>{let e=l.reduce((e,r,a)=>({name:c.params[a].name,binding:{kind:`Value`,value:t.X(r,w(i,n))},parent:e}),c.scope);return be(c.body,e,{...c,name:u},i,a)},d)},xe=(e,n,r,i,a)=>{let o=(e,t)=>xe(e,t,r,i,a);if(e.kind===`Let`){o(e.body,t.K(e.definitions,w(r,n)));return}let s=ge(e,n);if(s){o(s.expression,s.scope);return}let c=fe(e,n,r);if(c&&he(c,r))return;if(c&&c.params.length===0){if(t.T(c.body,c.scope,r)===1){i.inits.push(le(c.name,c.body));return}o(c.body,c.scope);return}if(c&&e.kind===`Apply`&&c.params.length===e.args.length){o(c.body,t.q(c,e.args,w(r,n)));return}if(e.kind===`And`){e.operands.forEach(e=>o(e,n));return}if(e.kind===`Always`){if(e.expression.kind===`BoxAction`){a.push({expression:e.expression.action,scope:n});return}i.temporals.push(le(C,e));return}let l=t.T(e,n,r);l<=1?i.inits.push(le(C,e)):l===3&&i.temporals.push(le(C,e))},Se=(e,n,r,i,a)=>{let o=(t,n)=>Se(e,t,n,i,a);if(n.kind===`Let`){o(n.body,t.K(n.definitions,w(i,r)));return}let s=ge(n,r);if(s){o(s.expression,s.scope);return}let c=fe(n,r,i);if(c&&he(c,i))return;if(c&&c.params.length===de(n).length){o(c.body,n.kind===`Apply`?t.q(c,n.args,w(i,r)):c.scope);return}if(n.kind===`Forall`&&ve(()=>(t.Z(n.bounds,w(i,r),e=>(o(n.body,e),!1)),!0),()=>!1))return;if(n.kind===`And`){n.operands.forEach(e=>o(e,r));return}if(n.kind===`Always`){let o=n.expression;o.kind===`BoxAction`?a.impliedActions.push(le(e,o)):t.T(o,r,i)<2?a.invariants.push(le(e,o)):a.impliedTemporals.push(le(e,n));return}let l=t.T(n,r,i);l<=1?a.impliedInits.push(le(e,n)):l===3&&a.impliedTemporals.push(le(e,n))},T=(e,n)=>{let r=t.$(e,n);return r?.kind===`Operator`&&!me(r,n)?r:void 0},Ce=(e,n,r)=>{let i={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},a=[],o=e.specification===void 0?void 0:T(e.specification,n);o&&(xe(o.body,void 0,n,i,a),a.forEach(e=>i.actions.push(...be(e.expression,e.scope,void 0,n,r))));let s=e.init===void 0?void 0:t.rt(e.init,n);s?.kind===`Closure`&&i.inits.push(le(e.init??``,s.body));let c=e.next===void 0?void 0:t.rt(e.next,n);return c?.kind===`Closure`&&i.actions.push(...be(c.body,c.scope,c,n,r)),e.invariants.forEach(e=>{let t=T(e,n);t&&i.invariants.push(le(e,t.body))}),e.properties.forEach(e=>{let t=T(e,n);t&&Se(e,t.body,void 0,n,i)}),i},we=(e,t,n)=>Ce(e,t,n).inits,Te=(e,t,n)=>Ce(e,t,n).actions,E=e=>e.parameters.length===0?``:`(${e.parameters.map(e=>t.jt(e[1])).join(`,`)})`,Ee=(t,n)=>`${t.name===C?`Action`:t.name}${n===`1.7.4`?``:E(t)} ${e.z(t.location.range??oe)}`,De=e=>`${e.name}${E(e)}`,Oe=(e,n,r,i)=>{let a=Ce(e,n,i),o=e=>t.Ot(e.map(ce)),s=e=>t.Ot(e.flatMap(e=>{let r=T(e,n);return r?[t.Dt([[`name`,r.name],[`location`,se(r.location)]])]:[]}));return t.Dt([[`inits`,o(a.inits)],[`actions`,o(a.actions)],[`temporals`,o(a.temporals)],[`invariants`,o(a.invariants)],[`impliedinits`,o(a.impliedInits)],[`impliedactions`,o(a.impliedActions)],[`impliedtemporals`,o(a.impliedTemporals)],[`variables`,t.Ot(n.variables.map((e,n)=>t.Dt([[`name`,e],[`location`,se(r[n])]])))],[`actionconstraints`,s(e.actionConstraints)],[`constraints`,s(e.constraints)]])},ke=`paired12`,Ae=(e,t=16)=>e<=t*.75?t:Ae(e,t*2),je=(e,t)=>{let n=Ae(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},Me=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),Ne=e=>[...Array(e.length).keys()].reduce((t,n)=>Math.imul(31,t)+e.charCodeAt(n)|0,0),Pe=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),Fe=e=>Pe(e).replaceAll(`
12
- `,`\\n`),Ie=(e,t)=>{let n=[],r=e=>n.push(`State ${n.length+1}:\n${e.getText()}\n`);return{writeInitialState:r,writeSuccessor:(e,t,n)=>{n||r(t)},writeStuttering:r,close:()=>t?.(e.path,n.join(``))}},Le=(e,t,n)=>{let r=n===`1.7.4`,i=[`strict digraph DiskGraph {
13
- `,r?``:`node [shape=box,style=rounded]
14
- `,e.colorize?`edge [colorscheme="${ke}"]\n`:``,`nodesep=0.35;
9
+ const e=require("./worker.cjs"),t=require("./transfer.cjs"),n=require("./deciders.cjs"),r=n=>{let r=t.Wt(n.message);return r&&!r.isEvalException&&e.it(r.code)===e.nt.configParseError?e.nt.configParseError:e.Q(n)},i=t=>{let n=t.cause;return n instanceof e.b?i(n):t instanceof e.k?t.exitCode:e.nt.specEvaluationFailure},a=(t,n,a)=>{let o=n.callStack!==void 0;switch(n.phase){case`initial`:return o?e.nt.specEvaluationFailure:a?e.nt.success:r(t);case`behavior-graph`:return e.rt(t)??(t instanceof e.k?t.exitCode:e.nt.error);case`liveness`:return e.Q(t);default:return o?n.fingerprint?e.nt.specEvaluationFailure:i(n.replayError??t):e.Q(t)}},o=(n,r)=>{let i=t.J(n),a=i.callStack;try{r(i);return}catch(t){return e.tt(t)?{callStack:[],fingerprint:void 0}:!(t instanceof e.b)||!a?void 0:{callStack:a.expressions,fingerprint:a.fingerprint,replayError:t}}},s=(e,n)=>{if(typeof e!=`object`)return[];let r=n.get(e),i=t.jt(e).find(e=>t.At(e)!==void 0);return[...r?[r]:[],...i===void 0?[]:s(i,n)]},c=(e,n,r)=>{for(let e of n){let n=t.At(e);if(!n)continue;let i=r?s(e,r.sources):[];throw r&&i.length>0&&(r.expressions.length=0,r.isFrozen=!0,r.fingerprint={sources:i,reason:n.message}),n}e.forEach(t.It)},l=`Failed to recover the initial state from its fingerprint.`,u=`Failed to recover the next state from its fingerprint.`,d=n=>{let r=n.config,i=n.options,a=n.environment,o=a.runtime,s=n.search,c=n.current,d=n.states,f=n.depths,p=n.captureOutput,m=o.version===`1.7.4`,h=r.view!==void 0||r.symmetry!==void 0,g=s.getFingerprintState,_=s.toRecord,v=(e,t,n,r)=>{let a=o.getLevel,c=o.getBehavior;o.getLevel=()=>n+1,o.getBehavior=()=>t.slice(0,n+1).map(e=>e.state);try{return s.evaluateAlias(e,t[n].state,(t[n+1]??t[r??n]).state,i.isTool??!1)}finally{o.getLevel=a,o.getBehavior=c}},y=(e,r,i,a)=>{let o={...c};Object.assign(c,{index:e,isExpanding:!0,candidate:void 0,rebuilt:{state:r,level:f[e]}});let s=a?e=>e:g,l=s(i);try{return n.findSuccessorAction(r,e=>t.W(s(e.state),l))}finally{Object.assign(c,o)}},b=(e,o,s={})=>{let c=r.alias,l=s.known??1,u=e.length>1?p(n.getInitialStates).lines:[],d=e.map((t,n)=>n===0||t.action===`Stuttering`?{result:void 0,lines:[]}:p(()=>y(o[n-1],e[n-1].state,t.state,l===2&&n===e.length-1))),f=d.map(e=>e.lines),h=s.loopStart,g=m&&h!==void 0?h+1:e.length-l;if(a.coverage&&e.length>1){let t=l>0&&!m;g>0&&t&&p(n.getInitialStates),t&&e.slice(1).forEach((t,n)=>{t.action!==`Stuttering`&&p(()=>y(o[n],e[n].state,t.state,l===2&&n===e.length-2))})}let b=g>0?[u,...f.slice(1,g)].flat():[];return{trace:e.map((r,a)=>{let o=d[a].result,s={action:r.action,label:o&&t.C(o,i.version),state:c===void 0?_(r.state):v(c,e,a,h),output:a===0?b:a<g?[]:f[a]};return(c!==void 0||o)&&n.tracedSteps.set(s,{state:_(r.state),action:o}),s}),traceOutput:l>0&&!m?[u,...f].flat():[]}},x=(e,r)=>p(()=>{for(let i of n.nextActions){let n=t.nt(i.expression,e,a,i.scope).find(r);if(n)return{...n,action:n.action??i.name}}}).result,S=(e,r)=>t.W(g(e),n.fingerprintStates[r]),C=(e,t)=>x(e,e=>S(e.state,t)),w=(r,i)=>{let o=p(()=>h||t.Q(a)?n.getInitialStates().find(e=>S(e,r[0])):d[r[0]]).result;if(!o)throw new e.b(l);let s=[{state:o,action:void 0}];for(let t=1;t<r.length;t++){let n=s[t-1].state;if(r[t-1]===r[t]){s.push({state:n,action:`Stuttering`});continue}let a=c.rebuilt;c.rebuilt={state:n,level:f[r[t-1]]};let o=C(n,r[t]);if(c.rebuilt=a,!o)throw new e.b(i);s.push(o)}return s},T=(e,r)=>{let i=[];for(let t=e;t!==-1;t=n.parents[t])i.unshift(t);let a=h&&i.length>1?w(i,l):i.map(e=>({state:d[e],action:n.actions[e]}));if(!r)return b(a,i);let o=h?x(d[e],e=>t.W(e.state,r.state))?.action:r.action;return b([...a,{state:r.state,action:o}],i,{known:2})};return{toTrace:b,findStepAction:y,findSuccessorWithFingerprint:C,getTrace:T,getStateTrace:e=>n.parents[e]===-1?{trace:[{action:void 0,label:void 0,state:r.alias===void 0?_(d[e]):v(r.alias,[{state:d[e],action:void 0}],0,void 0)}],traceOutput:m?[]:p(n.getInitialStates).lines}:T(e),getFailedTrace:(e,t)=>({trace:T(e,t).trace}),getPathSteps:(t,n)=>{let r=w(t,u),i=r[r.length-1].state;if(h&&n!==void 0&&n!==t.length-1&&C(i,t[n])===void 0)throw new e.b(u);return r}}},f=e=>{switch(e.kind){case`Always`:return!0;case`Eventually`:case`Not`:case`Next`:return f(e.body);case`And`:case`Or`:return e.operands.some(f);default:return!1}},p=e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0,m=e=>e.promises.some(e=>f(e.body))||e.models.some(e=>!p(e)),h=(e,n)=>e.every((e,r)=>t.Ft(e,n[r])),g=e=>e.filter((t,n)=>n===0||e[n-1]!==t),_=e=>({data:e(1024),length:0,create:e}),v=(e,t,n)=>{let r=t+n.length;if(r>e.data.length){let t=e.create(Math.max(2*e.data.length,r));t.set(e.data),e.data=t}e.data.set(n,t),e.length=Math.max(e.length,r)},y=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},b=e=>new Int32Array(e).fill(-1),x=(e,t)=>(e.edgeStarts[t]??-1)!==-1,S=(e,t)=>{let n=e.edgeStarts[t];return e.edgeTargets.data.subarray(n,n+e.edgeCounts[t])},C=(e,t,n)=>e.stateResults.data[e.nodeStates[t]*e.solution.stateChecks.length+n]===1,w=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.edgeStarts.push(-1),e.edgeCounts.push(0),e.nextSiblings.push(-1),e.nodeStates.length-1),T=(e,t)=>{let n=[];for(let r=e.firstNodes.data[t]??-1;r!==-1;r=e.nextSiblings[r])n.push(r);return n},ee=2**53-1,te=(n,r,i,a)=>{if(n.length===0)return;let o=r.map(e=>t.j(e.expression,e.scope,i)),s=n.map(e=>t.N(`Not`,t.j(e.expression,e.scope,i))),c=s.length===1?s[0]:t.M(`Or`,s),l=o.length===0?c:t.M(`And`,[...o,c]),u=t.P(l),d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let n=t.F(e),r=d.get(n)??d.size;return d.set(n,r),r}),nodeStates:[],nodeTableaux:[],edgeStarts:[],edgeCounts:[],edgeTargets:_(e=>new Int32Array(e)),edgeActions:_(e=>new Uint8Array(e)),stateResults:_(e=>new Uint8Array(e)),initial:[],firstNodes:_(b),lastNodes:_(b),nextSiblings:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),te=1,ne=!t.Z(i),re=i,ie=/* @__PURE__ */ new Map,ae=/* @__PURE__ */ new Map,oe=e=>{let t=ie.get(e)??/* @__PURE__ */ new Map;return ie.set(e,t),t},se=(e,t)=>{i.runtime.setLivenessSource(e);try{return t()}finally{i.runtime.setLivenessSource(void 0)}},E=(e,n)=>t.k(e,n,void 0,re,ne?oe(n):/* @__PURE__ */ new Map),ce=(e,t,n)=>se(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!E(e,n))),le=(e,n,r,i)=>se(n,()=>{let n=e.solution.actionChecks;if(!ne)return Uint8Array.from(n,e=>+!!t.k(e,r,i,re,/* @__PURE__ */ new Map));let a=oe(r),o=ae.get(r)??/* @__PURE__ */ new Map;ae.set(r,o);let s=o.get(i)??new Int8Array(d.size).fill(-1);return o.set(i,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!t.k(n[o],r,i,re,a)),s[e]))}),ue=(e,t,n,r)=>se(n,()=>e.nodes[t].statePredicates.every(e=>E(e,r))),de=(e,t)=>{if(i.runtime.version===`1.7.4`)return!1;let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},fe=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=y(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},pe=(e,t,n)=>{let r=w(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),y(i,e[t]-1,e[t+1]))}i.slots.set([t+1,n,r],y(i,t,n));let a=e.lastNodes.data[t]??-1;return a===-1?v(e.firstNodes,t,[r]):e.nextSiblings[a]=r,v(e.lastNodes,t,[r]),r},me=(e,t,n,r,i)=>{let a=e.edgeTargets.length,o=e.solution.actionChecks.length;v(e.edgeTargets,a,n),r.forEach((t,n)=>v(e.edgeActions,(a+n)*o,t)),v(e.stateResults,e.nodeStates[t]*i.length,i),e.edgeStarts[t]=a,e.edgeCounts[t]=n.length},he=(e,t,n)=>{let r=Array.from({length:16*te}),i=0,o=(e,t)=>{for(let n=(a.getFingerprint(t)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&h(r.state,t.state))return!1}},s=e=>{if(i>=r.length>>1){let e=r;r=Array.from({length:2*e.length+1});for(let t of e)t&&o(r,t)}o(r,e)&&i++};return n.forEach(s),s({index:e,state:t}),r.length>16*te&&te++,r.filter(e=>e!==void 0)},ge=(e,t,n,r,i)=>{let o=ce(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=[],u=s.successors.length>0?le(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!ue(t,a,r,n))continue;if(de(t,a)&&e.errorNode===void 0&&e.solution.models.some(p)){e.errorNode=i;return}let o=fe(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??pe(e,r,a);l.push(s),c.push(u),o===void 0&&ge(e,t,n,r,s)}for(let i of a.getSuccessors(r,n)){let a=le(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!ue(t,n,r,i.state)||i.index===-1)continue;let s=fe(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??pe(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&ge(e,t,i.state,i.index,u)}}l.length>0&&me(e,i,l,c,o)},_e=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>ue(t,r,a,e.state)));e.isDone[a]=!0;for(let s of T(e,a)){let a=[],c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=fe(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??pe(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&ge(e,t,n.state,n.index,d)}}),me(e,s,a,c,i)}return e.errorNode===void 0?void 0:be(e,e.errorNode)},ve=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)w(e,e.nodeStates.length,-1);let a=[],o=[];t.forEach((t,r)=>{x(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),me(e,i,a,o,r)},ye=(t,n)=>{if(t.initial.includes(n))return[n];let r=/* @__PURE__ */ new Map,i=[];for(let e of t.initial)x(t,e)&&(i.push(e),r.set(e,-1));for(let e=0;e<i.length;e++){let a=i[e];for(let e of S(t,a))if(!(e===a&&t.solution.tableau)){if(e===n){let e=[n];for(let t=a;t!==-1;t=r.get(t)??-1)e.push(t);return e}x(t,e)&&!r.has(e)&&(r.set(e,a),i.push(e))}}throw new e.b(`Couldn't re-create liveness trace (path) starting at: ${n}`)},be=(e,t)=>g(ye(e,t).reverse().map(t=>e.nodeStates[t])),xe=(n,r)=>{let i=n.solution,a=i.actionChecks.length,o=(e,t,r)=>n.edgeActions.data[(n.edgeStarts[e]+t)*a+r]===1,s=(e,t)=>r.eventuallyAlways.every(n=>o(e,t,n)),c=new Float64Array(n.nodeStates.length).fill(-1),l=n.initial.filter(e=>x(n,e)),u=[],d=e=>{let t=S(n,e).indexOf(e);return t!==-1&&s(e,t)},f=(e,r)=>i.tableau!==void 0&&t.I(i.tableau.nodes[n.nodeTableaux[e]].particle,r),p=e=>{let t=u.pop()??e;if(t===e&&!d(t)){c[t]=ee;return}let a=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Map;for(let r=t;;r=u.pop()??e){a.add(r);let t=l.get(n.nodeStates[r]);if(t?t.push(r):l.set(n.nodeStates[r],[r]),c[r]=ee,r===e)break}let p=r.infinitelyOftenStates.every(e=>[...a].some(t=>C(n,t,e))),m=r.infinitelyOftenActions.every(e=>[...a].some(t=>S(n,t).some((n,r)=>a.has(n)&&s(t,r)&&o(t,r,e)))),g=i.promises.every(e=>[...a].some(t=>f(t,e)));if(p&&m&&g)return h(e,a,l)},h=(t,a,c)=>{let l=be(n,t),u=[],d=/* @__PURE__ */ new Set([t]),p=r.infinitelyOftenStates.map(()=>!1),h=r.infinitelyOftenActions.map(()=>!1),_=i.promises.map(()=>!1),v=p.length+h.length+_.length,y=t,b=e=>{u.push(y),y=e};for(;v>0;){let t=v;for(;r.infinitelyOftenStates.forEach((e,t)=>{!p[t]&&C(n,y,e)&&(p[t]=!0,v--)}),i.promises.forEach((e,t)=>{!_[t]&&f(y,e)&&(_[t]=!0,v--)}),!(v<=0);){let i=-1,l=-1,f=v;if(S(n,y).some((e,t)=>{if(c.has(n.nodeStates[e])){if(!a.has(e)||!s(y,t))return!1;i=e,r.infinitelyOftenActions.forEach((e,n)=>{!h[n]&&o(y,t,e)&&(h[n]=!0,v--)})}return v<f?(b(e),d.clear(),!0):(a.has(e)&&!d.has(e)&&(l=e),!1)}))break;if(v<t){b(i),d.clear();break}for(;l===-1;){let t=u.pop();if(t===void 0)throw new e.b(`TLC failed to build the counterexample of a liveness property`);y=t,l=S(n,t).find(e=>a.has(e)&&!d.has(e))??-1}b(l),d.add(l)}}let x=g(t,y,c);for(let e=u.length-1;e>=0;e--){let t=n.nodeStates[u[e]];x[x.length-1]!==t&&x.push(t)}let w=l[l.length-1];return x[x.length-1]===w&&x.pop(),{prefix:l.slice(0,-1),cycle:[w,...x.reverse()],isCycleConstrained:m(i)}},g=(t,r,i)=>{if(r===t)return[];let a=n.nodeStates[r],o=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set([a]),l=[];for(let r=a,u=-1,d=0;;d++){for(let e of i.get(r)??[])for(let[d,f]of S(n,e).entries()){if(f===e||!s(e,d))continue;if(f===t){let e=[];for(let t=r,n=u;t!==a;)e.push(t),t=n,n=o.get(t)??-1;return e.push(a),e}let p=n.nodeStates[f];i.has(p)&&!c.has(p)&&(c.add(p),l.push([p,r]))}o.set(r,u);let f=l[d];if(f===void 0)throw new e.b(`TLC failed to build the counterexample of a liveness property`);r=f[0],u=f[1]}};for(let e=0;e<l.length;e++){let t=[l[e],-1,0],r=0;for(;t.length>=3;){let e=t.pop()??0,i=t.pop(),a=t.pop()??0;if(i===-42){if(c[a]===e){let e=p(a);if(e)return e}t.push(Math.min(t.pop()??e,e));continue}if(c[a]!==-1){t.push(Math.min(e,c[a]));continue}c[a]=r,t.push(e,a,-42),u.push(a);let o=r++;S(n,a).forEach((e,r)=>{x(n,e)&&(s(a,r)?c[e]===-1?t.push(e,-1):o=Math.min(o,c[e]):c[e]===-1&&l.push(e))}),t.push(o)}}};return{branches:f.length,addInitialState:(e,t,n)=>{re=n??i,ie.clear(),ae.clear();try{for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)ue(r,i,void 0,t)&&n.initial.push(fe(n,e,i)??pe(n,e,i))}}finally{re=i}},addState:(e,t,n,r)=>{re=r??i,ie.clear(),ae.clear();try{let r=he(e,t,n);for(let n of f){let i=r.map(r=>le(n,e,t,r.state)),a=ce(n,e,t),o=n.solution.tableau;if(!o){ve(n,r,i,a,e);continue}let s=_e(n,o,r,i,a,e);if(s)return s}return}finally{re=i}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=xe(e,t);if(n)return n}},getViolatedProperties:(e,r)=>[...new Set(n.filter((n,a)=>!t.A(s[a].body,e,r,0,i)).map(e=>e.name))]}},ne=`paired12`,re=(e,t=16)=>e<=t*.75?t:re(e,t*2),ie=(e,t)=>{let n=re(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},ae=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),oe=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),se=e=>oe(e).replaceAll(`
10
+ `,`\\n`),E=(e,t)=>{let n=[],r=e=>n.push(`State ${n.length+1}:\n${e.getText()}\n`);return{writeInitialState:r,writeSuccessor:(e,t,n)=>{n||r(t)},writeConstrained:()=>{},writeStuttering:r,close:()=>t?.(e.path,n.join(``))}},ce=(e,n,r)=>{let i=r===`1.7.4`,a=[`strict digraph DiskGraph {
11
+ `,i?``:`node [shape=box,style=rounded]
12
+ `,e.colorize?`edge [colorscheme="${ne}"]\n`:``,`nodesep=0.35;
15
13
  `,`subgraph cluster_graph {
16
14
  `,`color="white";
17
- `],a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=e=>{let t=a.get(e.level)??/* @__PURE__ */ new Set;a.set(e.level,t.add(e.fingerprint))},c=e=>{if(!e)return 1;let t=o.get(e.name)??o.size+2;return o.set(e.name,t),t},l=()=>[`subgraph cluster_legend {graph[style=bold];label = "Next State Actions" style="solid"
18
- `,`node [ labeljust="l",colorscheme="${ke}",style=filled,shape=record ]\n`,...je([...o.keys()],Ne).map(e=>`${e.replaceAll(`!`,`:`)} [label="${e}",fillcolor=${o.get(e)}]\n`),`}`].join(``),u=()=>[...je([...a],e=>e[0]).map(e=>`{rank = same; ${je([...e[1]],Me).map(e=>`${e};`).join(``)}}\n`),`}
19
- `,e.colorize&&o.size>1?l():``,`}`].join(``),d=()=>{e.snapshot&&t?.(e.path.replaceAll(`.dot`,`_snapshot.dot`),i.join(``)+u())};return{writeInitialState:e=>{i.push(`${e.fingerprint} [label="${Fe(e.getLabel())}",style = filled]\n`),s(e),d()},writeSuccessor:(t,n,a,o)=>{let l=e.colorize?String(c(o)):`black`,u=e.actionLabels&&o?Pe(r?o.name:o.signature):``;if(i.push(`${t.fingerprint} -> ${n.fingerprint} [label="${u}",color="${l}",fontcolor="${l}"];\n`),!a){let e=r?``:`,tooltip="${Fe(n.getText())}"`;i.push(`${n.fingerprint} [label="${Fe(n.getLabel())}"${e}];\n`)}s(t),d()},writeStuttering:e=>{i.push(`${e.fingerprint} -> ${e.fingerprint} [style="dashed"];\n`),s(e),d()},close:()=>t?.(e.path,i.join(``)+u())}},Re=(e,t,n)=>e.dot?Le(e,t,n):Ie(e,t),ze=(e,t)=>({...e,traceOutput:[...e.traceOutput??[],...t]}),Be=`Failed to recover the initial state from its fingerprint.`,Ve=`Failed to recover the next state from its fingerprint.`,He=(e,n)=>{if(!t.Lt(e))return;let r=t.Ht(e);if(!r.domain.every(e=>typeof e==`string`))return;let i=r.domain.map((e,t)=>[String(e),r.range[t]]);return Object.fromEntries(i.sort((e,t)=>n.indexOf(e[0])-n.indexOf(t[0])))},Ue=/* @__PURE__ */ Error(`The replay stopped`),We=/* @__PURE__ */ new Set([...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281]),Ge=n=>{let r=t.vt(n.message);return r&&!r.isEvalException&&We.has(r.code)?e.W.configParseError:e.V(n)},Ke=t=>{let n=t.cause;return n instanceof e._?Ke(n):t instanceof e.C?t.exitCode:e.W.specEvaluationFailure},qe=t=>{let n=t.dump&&Re(t.dump,t.writeFile,t.version);try{return Je(t,n)}catch(t){throw e.U(t)?e.R():t}finally{n?.close()}},Je=(n,r)=>{let i=typeof n.config==`string`?p(n.config,n.version):n.config,a=n.onPrint??console.log,o={lines:void 0},s=e=>{o.lines?o.lines.push(e):a(e)},c=e=>{let t=o.lines,n=[];o.lines=n;try{return{result:e(),lines:n}}finally{o.lines=t}},l=t.N(n.source,n.loadModule);t.Bt(l.getStringOrder(i)),t.Vt(n.version);let u=t.M(i,{source:n.source,loadModule:n.loadModule,order:l,loadClass:n.loadClass,print:s,files:{readFile:n.readFile,writeFile:n.writeFile},seed:n.seed,isTool:n.isTool,isTraceRecorded:n.isTraceRecorded,isSanyReported:n.isSanyReported,isWarningEnabled:n.isWarningEnabled,version:n.version});t.b(u,i,n.onProgress);let d=u.environment,f=d.runtime,m=f.version===`1.7.4`;f.pause=n.onPause??(()=>{}),f.getSpecification=()=>Oe(i,d,u.variableLocations,u.instanceActions);let h={depth:0,initialStates:void 0},g=(e,t,n)=>({status:e,violation:t&&{...t,loopStart:t.loopStart},failure:n,generatedStates:f.generatedStates,distinctStates:f.distinctStates,queuedStates:f.queueSize,depth:f.generatedStates===0?0:Math.max(h.depth,1),initialStates:h.initialStates,outDegrees:void 0,fingerprintDistance:void 0}),_=Array.from({length:32},()=>0),v={newStates:0},y=()=>Math.min(v.newStates,31),b=()=>_.map((e,t)=>t===y()?e+1:e),ee=()=>m?[..._]:b(),x=(e,t,n)=>m?[]:e.getViolatedProperties(t,n),te=(e,t=[..._])=>({...e,violationOutDegrees:t}),ne=()=>({...g(`success`),outDegrees:[..._],fingerprintDistance:t.d(f.distinctStates,f.generatedStates,()=>S?S.getStoredFingerprints(E,ke):BigInt64Array.from(E,f.getFingerprint))}),S=t.h(i,d,()=>l.getDeclarationOrder(`variable`),n.onProgress),re=()=>t.g(u.assumptions,d);if(!S){f.isStarted=!0;let e=re();return e?g(`assumption-violation`,e):(h.initialStates={generated:0,distinct:0},n.onProgress?.({kind:`initial-states-started`}),n.onProgress?.({kind:`initial-states-computed`,initialStates:h.initialStates}),ne())}let ie=i.postconditions.length>0||i.possible.length>0,C=/* @__PURE__ */ new WeakMap,oe=e=>C.get(e)?.state??e.state,se=e=>{let n=C.get(e)?.action;return n?ce(n):t.P(e.action)},le=(e,n)=>{ie&&(f.counterExample=t.F(e.map(oe),e.slice(1).map(se),n));let r=S.findUnwitnessedPossible(),i=r?{result:void 0,lines:[]}:c(()=>S.findPostconditionViolation(!0));return{unwitnessed:r,postcondition:i.result,lines:i.lines}},w=(e,t,n)=>{let r=t.loopStart,i=le(t.trace,r===void 0||!n?void 0:{start:r,action:n()}),a=[...t.traceOutput??[],...i.lines];return g(e,{...t,...a.length>0&&{traceOutput:a},...i.unwitnessed&&{unwitnessed:i.unwitnessed},...i.postcondition&&{postcondition:i.postcondition}})},ue=(e,t)=>n.onProgress?.({kind:`violation`,status:e,violation:{...t,loopStart:void 0}}),de=S.spec,fe=S.getFingerprintState,pe={value:void 0},me=()=>pe.value??=Te(i,d,u.instanceActions),he=n=>{let r=t.J(d),i=r.callStack;try{n(r);return}catch(t){return e.U(t)?{callStack:[],fingerprint:void 0}:!(t instanceof e._)||!i?void 0:{callStack:i.expressions,fingerprint:i.fingerprint}}},ge=(e,n)=>{if(typeof e!=`object`)return[];let r=n.get(e),i=t.Nt(e).find(e=>t.Mt(e)!==void 0);return[...r?[r]:[],...i===void 0?[]:ge(i,n)]},_e=(e,n)=>{for(let r of fe(e)){let e=t.Mt(r);if(!e)continue;let i=n?ge(r,n.sources):[];throw n&&i.length>0&&(n.expressions.length=0,n.isFrozen=!0,n.fingerprint={sources:i,reason:e.message}),e}e.forEach(t.zt)},ve=()=>{let e=st.fingerprint?[st.fingerprint]:[];return(t,n)=>{_e(t,n);let r=fe(t);return it(k(r),r)!==-1||e.some(e=>A(e,r))?!1:(e.push(r),f.distinctStates++,!0)}},ye=()=>{let n={count:0},r=[],a=ve();return he(s=>{if(t.ct(we(i,d,u.instanceActions),s,i=>{if(t.y(n.count,e=>o.lines?.push(e)),n.count++,f.generatedStates=n.count,!(r.length>0))try{let e=S.checkReplayedInitialState(i,s,()=>{a(i,s.callStack)&&(f.queueSize++,T?.addInitialState(E.length,i,s))});if(e){let t=We([{action:void 0,state:i}],[]).trace[0].state;throw o.lines?.push({kind:`initial-state-violation`,...e,state:t}),Ue}}catch(t){if(!(t instanceof e._)||!s.callStack?.fingerprint)throw t;r.push(t)}}),r.length>0)throw r[0]})},be=e=>he(n=>{let i=E[e],a=r&&dt(i,Me[e]),o=ve();t.lt(me(),i,n,(t,s)=>{if(!S.checkReplayedSuccessor(i,t,n,()=>{let i=o(t,n.callStack);return a&&r?.writeSuccessor(a,dt(t,Me[e]+1),!i,_t?{name:s.name,signature:De(s)}:void 0),i}))throw Ue})}),xe=i.view!==void 0||i.symmetry!==void 0,Se=[];S.properties.liveness.length>0&&n.onProgress?.({kind:`liveness-initializing`,isSymmetric:S.isSymmetric,isConstrained:S.isConstrained});let T=e.q(()=>t.Ct(()=>ae(S.properties.liveness,de.temporals,d,{getFingerprint:({index:e,state:t})=>Se[e]??=Number(BigInt.asIntN(32,f.getFingerprint(t))),getSuccessors:(e,n)=>{let r=[];if(de.next===void 0)return r;let i=M.livenessSource;return M.livenessSource=e,t.at(de.next,n,d,e=>{if(Pe(e.state),!(S.satisfiesConstraints(e.state,n)&&S.satisfiesActionConstraints(n,e.state)))return!1;let t=fe(e.state),i=it(k(t),t);return r.push({index:i,state:e.state}),!1},de.scope),M.livenessSource=i,r}})));f.isStarted=!0;let Ce=S.isSymmetric||T!==void 0,E=[],ke=[],Ae=[],je=[],Me=[],Ne={slots:new Int32Array(1<<17),size:0,shift:16},Pe=t.Tt(),Fe=e=>Object.fromEntries(S.getTlcOrder().map(t=>[d.variables[t],e[t]])),Ie=(e,t,n,r)=>(f.getLevel=()=>n+1,f.getBehavior=()=>t.slice(0,n+1).map(e=>e.state),Le(e,t[n].state,(t[n+1]??t[r??n]).state)),Le=(r,i,a)=>{try{let e=t._(`alias`,r,d).body,n=t.X(t.m(r),t.v(d,i,a)),o=e.kind===`Record`?e.fields.map(e=>e.name):[];return He(n,o)??Fe(i)}catch(r){if(!(r instanceof e.h||r instanceof e._))throw r;return{...Fe(i),_ALIASEvalError:t.ht(r.message,n.isTool??!1)}}},Re=(e,n,r,i)=>{let a=me(),o={...M};Object.assign(M,{index:e,isExpanding:!0,candidate:void 0});let s=i?e=>e:fe,c=s(r),l=a.find(e=>t.st(e.expression,n,d,e.scope).some(e=>A(s(e.state),c)));return Object.assign(M,o),l},We=(e,t,r={})=>{let a=i.alias,o=r.known??1,s=e.length>1?c(qe).lines:[],l=e.map((n,r)=>r===0||n.action===`Stuttering`?{result:void 0,lines:[]}:c(()=>Re(t[r-1],e[r-1].state,n.state,o===2&&r===e.length-1))),u=l.map(e=>e.lines),d=r.loopStart,f=m&&d!==void 0?d+1:e.length-o,p=f>0?[s,...u.slice(1,f)].flat():[];return{trace:e.map((t,r)=>{let i=l[r].result,o={action:t.action,label:i&&Ee(i,n.version),state:a===void 0?Fe(t.state):Ie(a,e,r,d),output:r===0?p:r<f?[]:u[r]};return(a!==void 0||i)&&C.set(o,{state:Fe(t.state),action:i}),o}),traceOutput:o>0&&!m?[s,...u].flat():[]}},qe=()=>de.init===void 0?[]:t.ot(de.init,d,de.scope),Je=(e,n)=>c(()=>{for(let r of me()){let i=t.st(r.expression,e,d,r.scope).find(n);if(i)return{...i,action:i.action??r.name}}}).result,Ye=(e,t)=>A(fe(e),ke[t]),Xe=(e,t)=>Je(e,e=>Ye(e.state,t)),Ze=(n,r)=>{let i=c(()=>xe||t.tt(d)?qe().find(e=>Ye(e,n[0])):E[n[0]]).result;if(!i)throw new e._(Be);let a=[{state:i,action:void 0}];for(let t=1;t<n.length;t++){let i=a[t-1].state;if(n[t-1]===n[t]){a.push({state:i,action:`Stuttering`});continue}let o=Xe(i,n[t]);if(!o)throw new e._(r);a.push(o)}return a},Qe=(e,t)=>{let n=[];for(let t=e;t!==-1;t=Ae[t])n.unshift(t);let r=xe&&n.length>1?Ze(n,Be):n.map(e=>({state:E[e],action:je[e]}));if(!t)return We(r,n);let i=xe?Je(E[e],e=>A(e.state,t.state))?.action:t.action;return We([...r,{state:t.state,action:i}],n,{known:2})},$e=e=>Ae[e]===-1?{trace:[{action:void 0,label:void 0,state:Fe(E[e])}],traceOutput:m?[]:c(qe).lines}:Qe(e),D=(e,t)=>({trace:Qe(e,t).trace}),et=(t,n)=>n.isInitial&&!n.callStack&&!n.fingerprint&&m?e.W.success:n.callStack?n.isCallStackFirst?e.V(t):n.isLiveCallStack?e.G(t)??(t instanceof e.C?t.exitCode:e.W.error):n.isInitial||n.fingerprint?e.W.specEvaluationFailure:Ke(t):n.isInitial?Ge(t):e.V(t),O=(n,r,i={})=>{let a=e.U(n)?new e.D:n;if(!(a instanceof e._))throw a;let o=r.trace.length>0&&!i.traceFailure?le(r.trace,void 0):void 0,s=o?.unwitnessed??o?.postcondition,c=[...r.traceOutput??[],...o?.lines??[]];return{...g(`error`,void 0,{...t.yt(a,i.isNextState??!1),...r,...c.length>0&&{traceOutput:c},...s&&{postcondition:s},initialState:i.initialState&&!(a instanceof e.C)?Fe(i.initialState):void 0,exitCode:et(a,i),callStack:i.callStack,...i.isCallStackFirst&&{isCallStackFirst:!0},...i.fingerprint&&{fingerprint:i.fingerprint},...i.traceFailure&&{traceFailure:i.traceFailure}}),outDegrees:i.outDegrees}},tt=(r,i)=>{f.generatedStates++;let a=me(),o=a.length===1?a[0]:a.find(e=>e.name===i.action),s=i.variables,c=a.length===1?`the next-state action`:`action ${i.action} of the next-state relation`,l=m?`assigned`:`defined`,u=`Successor state is not completely specified by ${c}. The following variable${s.length>1?`s are`:` is`} not ${l}: ${s.join(`, `)}.\n`,d=t.Et(`null`),p=i.state.map(e=>e??d),h=O(i,$e(r));return te({...h,failure:h.failure&&{...h.failure,code:t.dt.incompleteSuccessor,message:u,toolMessage:u,exitCode:e.W.specEvaluationFailure,trace:[...h.failure.trace,{action:i.action,label:o&&Ee(o,n.version),state:Fe(p)}]}})},nt=(t,n)=>{let r=Ze(t,Ve),i=r[r.length-1].state;if(xe&&n!==void 0&&n!==t.length-1&&Xe(i,t[n])===void 0)throw new e._(Ve);return r},k=e=>{let n=2166136261;for(let r=0;r<e.length;r++)n=t.wt(n,t.It(e[r]));return n&1073741823},rt=e=>{for(let n of e){let e=t.Mt(n);if(e)throw e}},A=(e,n)=>{for(let r=0;r<n.length;r++)if(!t.Rt(e[r],n[r]))return!1;return!0},j=e=>Math.imul(e,2654435761)>>>Ne.shift<<1,it=(e,t)=>{let n=Ne.slots.length-1;for(let r=j(e);;r=r+2&n){let n=Ne.slots[r+1];if(n===0)return-1;if(Ne.slots[r]===e&&A(ke[n-1],t))return n-1}},at=(e,t)=>{let n=Ne.slots.length-1,r=j(e);for(;Ne.slots[r+1]!==0;)r=r+2&n;Ne.slots[r]=e,Ne.slots[r+1]=t},ot=(e,t)=>{if(Ne.size++,Ne.size*4>Ne.slots.length){let e=Ne.slots;Ne.slots=new Int32Array(e.length*2),Ne.shift--;for(let t=0;t<e.length;t+=2)e[t+1]!==0&&at(e[t],e[t+1])}at(e,t+1)},st={fingerprint:void 0},ct=e=>{f.distinctStates=E.length+1,h.depth=Math.max(h.depth,e),f.diameter=Math.max(f.diameter,e)},lt=(e,t,n,r)=>{let i=n===-1?1:Me[n]+1;E.push(e),ke.push(t),Ae.push(n),je.push(r),Me.push(i)},M={index:-1,isExpanding:!1,candidate:void 0,candidateLevel:0,livenessSource:-1},ut=e=>e===-1?[]:[...ut(Ae[e]),E[e]];f.isSeen=e=>{let t=fe(e);return it(k(t),t)!==-1},f.getBehavior=e=>{let t=e===M.candidate?-1:E.indexOf(e);return t===-1?[...ut(M.index),e]:ut(t)},f.getCurrentState=()=>M.index===-1?void 0:E[M.index],f.setLivenessSource=e=>{M.livenessSource=e??-1},f.getLevel=e=>{let t=M.livenessSource;if(m){let e=t===-1?M.isExpanding?M.index:-1:t;return e===-1?0:Me[e]}return t===-1?e===M.candidate?M.candidateLevel:M.index===-1?0:e===E[M.index]?Me[M.index]:M.isExpanding?Me[M.index]+1:0:e===E[t]?Me[t]:Me[t]+1};let dt=(e,n)=>({fingerprint:BigInt.asIntN(64,f.getFingerprint(e)),level:n,getLabel:()=>t.At(i.alias===void 0?Fe(e):Le(i.alias,e,void 0)),getText:()=>t.At(Fe(e))}),ft=e=>{Pe(e),f.generatedStates++,f.initialStates++,M.candidate=e,M.candidateLevel=1;let i=fe(e),a=k(i),o=S.satisfiesConstraints(e);if(o&&(S.trackStatePossible(e),rt(i),e.forEach(t.zt)),o&&it(a,i)!==-1)return;st.fingerprint=o?i:void 0,o&&(ct(1),f.queueSize++,T?.addInitialState(E.length,e),r?.writeInitialState(dt(e,1))),n.isContinued&&S.getViolatedInvariants(e).forEach(t=>ue(`invariant-violation`,{name:t.name,...We([{action:void 0,state:e}],[])}));let s=n.isContinued?void 0:S.findViolatedInvariant(e);if(s)return w(`invariant-violation`,{name:s.name,...We([{action:void 0,state:e}],[])});let c=S.findFailedInitialPredicate(e);if(c)return w(`liveness-violation`,{name:c.name,...We([{action:void 0,state:e}],[])});o&&(ot(a,E.length),lt(e,i,-1,void 0))},pt=(i,a,o,s,l)=>{let u=E[i];f.generatedStates++,M.candidate=a.state,M.candidateLevel=Me[i]+1,Ce&&Pe(a.state);let d=fe(a.state),p=k(d),m=it(p,d),h=S.satisfiesConstraints(a.state,u);h&&S.trackStatePossible(a.state);let g=h&&S.satisfiesActionConstraints(u,a.state);g&&(S.trackActionPossible(u,a.state),rt(d),a.state.forEach(t.zt));let _=g?m:-1;if(s&&g&&r?.writeSuccessor(s,dt(a.state,Me[i]+1),_!==-1,l&&{name:l.name,signature:De(l)}),_!==-1&&T){let e=E[_],t=e.every((e,t)=>e===a.state[t]);o.push({index:_,state:t?e:a.state})}let y=g&&_===-1;if(y&&T&&o.push({index:E.length,state:a.state}),st.fingerprint=y?d:void 0,y&&(ct(Me[i]+1),v.newStates++),_===-1)try{let e=S.findViolatedInvariant(a.state,u),t=e&&{name:e.name,...Qe(i,a)};if(t&&!n.isContinued)return te(w(`invariant-violation`,t));t&&ue(`invariant-violation`,t)}catch(t){if(e.U(t))throw t;let n=c(()=>be(i));return O(t,ze(D(i,a),n.lines),n.result??{outDegrees:ee()})}let b=S.findViolatedActionProperty(u,a.state),x=b&&{name:b.name,...Qe(i,a)};if(x&&!n.isContinued)return te(w(`liveness-violation`,x));x&&ue(`liveness-violation`,x),y&&(Ce||Pe(a.state),ot(p,E.length),lt(a.state,d,i,a.action),f.queueSize++)},mt={result:void 0};T&&n.onProgress?.({kind:`liveness-prepared`,branches:T.branches});let ht=re();if(ht)return g(`assumption-violation`,ht);if(n.onProgress?.({kind:`initial-states-started`}),de.init!==void 0)try{t.it(de.init,d,e=>{t.y(f.initialStates,n.onProgress);try{mt.result=ft(e)}catch(t){let n=c(ye);mt.result=O(t,{trace:[],traceOutput:n.lines},{initialState:e,...n.result,isInitial:!0})}return mt.result!==void 0},de.scope)}catch(n){if(n instanceof e.v){let e=O(n,{trace:[]},{initialState:n.state.map(e=>e??t.Et(`null`))});return{...e,failure:e.failure&&{...e.failure,isWithoutStatistics:!0}}}let r=c(ye);return O(n,{trace:[],traceOutput:r.lines},{...r.result,isInitial:!0})}if(mt.result)return mt.result;h.initialStates={generated:f.initialStates,distinct:f.distinctStates},n.onProgress?.({kind:`initial-states-computed`,initialStates:h.initialStates});let gt=de.next;if(gt===void 0){if(E.length>0)throw new e._(`No next state actions defined to generate successor states from.`);return ne()}let _t=!!(n.dump?.dot&&(n.dump.actionLabels||n.dump.colorize)),vt=(e,n)=>{if(!_t)return t.at(gt,e,d,e=>n(e,void 0),de.scope);let r={isStopped:!1};return me().reduce((i,a)=>r.isStopped?i:i+t.at(a.expression,e,d,e=>(r.isStopped=n(e,a),r.isStopped),a.scope),0)},yt=(e,t)=>{if(!T||m)return;let n=he(n=>T.addState(e,E[e],t,n));return n?.callStack.length&&!n.fingerprint?n.callStack:void 0},N=(t,n)=>{try{T?.addState(t,E[t],n);return}catch(r){if(!(r instanceof e._))throw r;return yt(t,n)}},bt=(e,t)=>{let n=c(()=>N(e,t));if(n.result)return{result:{callStack:n.result,fingerprint:void 0,isLiveCallStack:!0},lines:n.lines};let r=c(()=>be(e));return{result:r.result,lines:[...n.lines,...r.lines]}},xt=t=>O(e.R(),$e(t)),P=(n,r,i)=>{if(e.U(n))return xt(r);let a=bt(r,i);return O(t.x(n),ze($e(r),a.lines),{isNextState:!0,...a.result})},St=(n,a)=>{let o=E[n],s=r&&dt(o,Me[n]),l=vt(o,(r,i)=>{try{mt.result=pt(n,r,a,s,i)}catch(i){if(e.U(i))return mt.result=xt(n),!0;let o=m?c(()=>be(n)):bt(n,a);if(m&&i instanceof e._&&!t.St(i))return mt.result=O(new e._(`${t.bt(i)}${i.message}`,i),ze({trace:[]},o.lines),{isNextState:!0,...o.result}),!0;let s=fe(r.state).some(e=>t.Mt(e)!==void 0)&&i instanceof e._?t.yt(t.xt(i)?new e._(`${e.N}${i.message}`):i,!0):void 0;mt.result=O(i,ze(s?$e(n):D(n,r),o.lines),{isNextState:!0,...o.result,traceFailure:s})}return mt.result!==void 0});M.isExpanding=!1;let u=mt.result;if(u?.violation&&!m){let e=c(()=>N(n,a));return{...u,violation:ze(u.violation,e.lines),...e.result&&{liveCallStack:e.result}}}if(u)return u;let d=()=>{T&&s&&m&&r?.writeStuttering(s);let e=T?.addState(n,o,a);if(!T||!e)return;let t=nt(e),i=x(T,t.map(e=>e.state),t.length-1);return w(`property-violation`,{name:i[0],properties:i,...We(t,e,{known:0})})};if(l===0&&i.checkDeadlock){let t=w(`deadlock`,{name:`deadlock`,...$e(n)}),r=c(()=>{try{return{additional:d()?.violation}}catch(t){if(!(t instanceof e._))throw t;return{isFailed:!0,callStack:yt(n,a)}}}),i=t.violation?{...t,violation:ze(t.violation,r.lines)}:t,o=te(i,r.result.isFailed?ee():b());return r.result.additional?{...o,additionalViolation:r.result.additional}:r.result.callStack?{...o,liveCallStack:r.result.callStack}:o}try{return d()}catch(r){if(m&&r instanceof e._){let n=new e._(`${t.xt(r)?e.N:e.P}${r.message}`);return O(e.K(n,e.W.error),{trace:[]},{outDegrees:ee()})}let i=he(e=>T?.addState(n,o,a,e));return O(r,$e(n),{outDegrees:ee(),callStack:i?.callStack.length?i.callStack:void 0,isNextState:!0,isCallStackFirst:!0})}},Ct=()=>{let e=i.specification,n=`(compare Chapter 8, page 87ff of Specifying Systems at https://lamport.azurewebsites.net/tla/book.html).`;if(e===void 0)return{code:t.dt.noSpecificationButProperty,text:`The stuttering counterexample above may be caused by the absence of a behavior specification (SPECIFICATION). Only INIT and NEXT have been provided, so TLC permits infinite stuttering. To rule out such counterexamples, use SPECIFICATION Spec, with Spec asserting a suitable fairness constraint ${n}`};let r=t.$(e,d)?.location.range;if(!(de.temporals.length>0||!r))return{code:t.dt.noFairnessButProperty,text:`The stuttering counterexample above may be caused by the absence of a fairness constraint in the behavior specification ${e} defined at ${t.Q(r)}. To rule out such counterexamples, conjoin a suitable fairness constraint to ${e} ${n}`}},F=(e,r)=>{let i=[...r.prefix,...r.cycle],a=r.prefix.length,o=nt(i,a),s=We(o,i,{loopStart:a,known:0}).trace,l=x(e,o.map(e=>e.state),a),u=i[a],d=i[i.length-1],f=o[o.length-1].state,p=u===d?{result:void 0,lines:[]}:c(()=>Re(d,f,E[u],!1)),m=u===d&&r.isCycleConstrained;return w(`liveness-violation`,{name:l[0],properties:l,trace:s,traceOutput:p.lines,loopStart:a,loopLabel:p.result&&Ee(p.result,n.version),warning:m?Ct():void 0},()=>u===d?se(s[s.length-1]):p.result?ce(p.result):t.P(Xe(f,u)?.action))},wt=T!==void 0&&n.livenessCheck!==`final`,Tt=performance.now(),Et={at:Tt+3e3,size:1,time:0},Dt=e=>{let t=performance.now();if(!((e-Et.size)/Et.size>.1)||Et.time>(t-Tt)*.2||(Et.size=e,!T))return;n.onProgress?.({kind:`liveness-started`,branches:T.branches,isComplete:!1,states:e,statistics:g(`success`)});let r=T.findViolation();return r||n.onProgress?.({kind:`liveness-finished`}),Et.time+=performance.now()-t,r};for(let t=0;t<E.length&&!f.isStopped;t++){M.index=t,M.candidate=void 0,f.queueSize=E.length-t-1,M.isExpanding=!0;let r=[];try{mt.result=St(t,r)}catch(n){mt.result=n instanceof e.y?tt(t,n):P(n,t,r)}if(mt.result)return mt.result;if(_[y()]++,v.newStates=0,(wt||n.onProgress)&&performance.now()>=Et.at){Et.at=performance.now()+6e4;let e=wt?Dt(t+1):void 0;if(T&&e)return F(T,e);n.onProgress?.({kind:`progress`,statistics:g(`success`)})}}M.index=-1,M.candidate=void 0,T&&n.onProgress?.({kind:`liveness-started`,branches:T.branches,isComplete:!0,states:f.distinctStates,statistics:g(`success`)});let Ot=T?.findViolation();if(T&&Ot)return F(T,Ot);T&&n.onProgress?.({kind:`liveness-finished`});try{let e=S.findPostconditionViolation();if(e)return g(`postcondition-violation`,{name:e.name,message:e.message,counts:e.counts,trace:[],postcondition:e})}catch(e){return O(e,{trace:[]})}return ne()},Ye=async n=>{let r=typeof n.config==`string`?p(n.config,n.version):n.config,i=n.onPrint??console.log,a={count:0},o=e=>[e.kind,`name`in e?e.name:``,`count`in e?e.count:``,`text`in e?e.text:``].join(` `),s=/* @__PURE__ */ new Set,c=e=>{s.add(o(e)),n.onProgress?.(e)},l=e=>{e!==void 0&&n.onProgress?.({kind:`sequential-fallback`,string:e});let t={count:a.count};return qe({...n,config:r,onPrint:e=>t.count-->0?void 0:i(e),onProgress:e=>{s.has(o(e))||n.onProgress?.(e)}})},u=n.workers??1;if(u<2||typeof SharedArrayBuffer!=`function`||n.dump!==void 0||n.isContinued===!0||r.view!==void 0||r.postconditions.length>0||r.possible.length>0)return l();let d=/* @__PURE__ */ new Map,f=e=>{let t=n.loadModule?.(e);return d.set(e,t),t},m=/* @__PURE__ */ new Map,h=e=>{let t=n.loadClass?.(e);return m.set(e,t),t},g=t.N(n.source,f);t.Bt(g.getStringOrder(r)),t.Vt(n.version);let _=t.Ft(),v=t.M(r,{source:n.source,loadModule:f,order:g,loadClass:h,print:e=>{a.count++,i(e)},files:{readFile:n.readFile,writeFile:n.writeFile},isTool:n.isTool,isTraceRecorded:n.isTraceRecorded,isSanyReported:n.isSanyReported,isWarningEnabled:n.isWarningEnabled,version:n.version});t.b(v,r,c);let y=v.environment,b=t.h(r,y,()=>g.getDeclarationOrder(`variable`),c);if(t.g(v.assumptions,y)||!b||b.spec.init===void 0||b.spec.next===void 0||b.properties.liveness.length>0||t.tt(y))return l();let ee=t.Tt(),x={fingerprints:t.i()},te=/* @__PURE__ */ new Int32Array(2),ne=Array.from({length:u},t.n),S={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,initialStates:void 0,outDegrees:Array.from({length:32},()=>0)},re=[],ie=()=>({status:`success`,violation:void 0,failure:void 0,...S,fingerprintDistance:t.d(S.distinctStates,S.generatedStates,()=>{let e=new BigInt64Array(S.distinctStates);return re.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),ae=e=>{let n=[];for(let r of t.ot(e,y,b.spec.scope))if(t.y(S.generatedStates,c),ee(r),S.generatedStates++,t.c(b.getFingerprintState(r),te),t.s(x.fingerprints)&&(x.fingerprints=t.a(x.fingerprints)),t.o(x.fingerprints,te[0],te[1])){if(b.findViolatedInvariant(r)||b.findFailedInitialPredicate(r))return!1;if(b.satisfiesConstraints(r)){if(!ne[n.length%u].encode(r))return!1;n.push(r),S.distinctStates++}}return re.push(BigInt64Array.from(n,e=>y.runtime.getFingerprint(e))),!0};c({kind:`initial-states-started`});try{if(!ae(b.spec.init))return l()}catch(t){if(!(t instanceof e._))throw t;return l()}if(t.Ft()!==_)return l(t.Pt(_));if(S.depth=S.generatedStates===0?0:1,S.initialStates={generated:S.generatedStates,distinct:S.distinctStates},c({kind:`initial-states-computed`,initialStates:S.initialStates}),S.distinctStates===0)return ie();let C=[],oe={count:u,resolve:e=>{}},se=e=>{C.push(e),(e.type===`abort`||C.length===oe.count)&&oe.resolve(C.splice(0))},ce=e=>new Promise(t=>{oe.count=e,oe.resolve=t}),le=ce(u),w=new Int32Array(new SharedArrayBuffer(u*4)),ue=new Int32Array(new SharedArrayBuffer(u*4)),de=await Promise.all(Array.from({length:u},()=>e.i(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href),e=>se(e),()=>se({type:`abort`})))),fe=()=>de.forEach(e=>e.terminate()),pe=/* @__PURE__ */ new Map,me=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=pe.get(n)??new MessageChannel;return pe.set(n,r),e<t?r.port1:r.port2};de.forEach((e,t)=>{let i=Array.from({length:u},(e,n)=>n===t?void 0:me(t,n)),a=ne[t].finish(),o={type:`start`,source:n.source,config:r,modules:[...d],classes:[...m],index:t,ports:i,seed:a,isTool:n.isTool,isTraceRecorded:n.isTraceRecorded,isWarningEnabled:n.isWarningEnabled,version:n.version,fingerprints:x.fingerprints,requests:w,remaining:ue};e.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let he=e=>e.some(e=>e.type===`abort`),ge=e=>de.forEach(t=>t.postMessage(e)),_e=async e=>{let n=e.filter(e=>e.type===`paused`).length;if(n===0||he(e))return e;x.fingerprints=t.a(x.fingerprints);let r=ce(n);return ge({type:`resize`,fingerprints:x.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await _e(await r)]};if(he(await le))return fe(),l();for(;;){let e=ce(u);w.forEach((e,t)=>Atomics.store(w,t,0)),ge({type:`level`});let t=await _e(await e);if(he(t)){fe();let e=t.find(e=>e.type===`abort`&&e.string!==void 0);return l(e?.type===`abort`?e.string:void 0)}let n=t.flatMap(e=>e.type===`level`?[e]:[]),r=n.reduce((e,t)=>e+t.added,0);if(S.generatedStates+=n.reduce((e,t)=>e+t.generated,0),S.distinctStates+=r,n.forEach(e=>{e.outDegrees.forEach((e,t)=>S.outDegrees[t]+=e),re.push(e.fingerprints)}),r===0)return fe(),ie();S.depth++}},Xe=e=>{let t=e.endColumn-1;return e.startLine===e.endLine?e.startColumn>=t?`line ${e.startLine}, character ${e.startColumn}`:`line ${e.startLine}, characters ${e.startColumn}-${t}`:`line ${e.startLine}, character ${e.startColumn} to line ${e.endLine}, character ${t}`},Ze=e=>`File ${JSON.stringify(e.file)}, ${Xe(e)}`,Qe=e=>e?Ze(e):`<unknown location>`,$e=e=>`${Qe(e)}:\n`,D=(e,t)=>({text:`${$e(e)}Error: ${t}`,channel:`stderr`}),et=e=>e?`${Ze(e)} :\n`:``,O=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},tt=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},nt=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t,k=(e,t,n)=>O({kind:`Apply`,operator:O({kind:`Internal`,builtin:e},n),args:t},n),rt=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},A=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),j=(e,t)=>t.reduce(A,e),it=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},at=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(tt(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},ot=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},st=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},ct=(e,t)=>{let n={state:e,hyp:void 0,parent:void 0,next:/* @__PURE__ */ new WeakMap};return(e,r=e)=>{let i=e.reduce((e,n,i)=>{let a=e.next.get(n);if(a)return a;let[o,s]=t(e.state,r[i],n),c={state:o,hyp:s,parent:e,next:/* @__PURE__ */ new WeakMap};return e.next.set(n,c),c},n),a=[];for(let e=i;e;e=e.parent)e.hyp&&a.push(e.hyp);return{state:i.state,context:a.reverse()}}},lt=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),M=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),ut=(e,t,n,r)=>({kind:`Fact`,expression:e,visibility:t,time:n,location:r}),dt=e=>lt(e.name,e.level),ft=e=>lt(e.name,`Unknown`,e.shape),pt=e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),mt=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},ht=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),gt=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,_t=(e,t)=>e.map(e=>{let n=t(e.value);return{trail:e.trail.map(e=>e.kind===`Apply`?{kind:`Apply`,expression:t(e.expression)}:e),value:n}}),vt=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,yt=(e,t,n)=>e.kind===`Fresh`?e.domain?{...e,domain:t(e.domain)}:e:e.kind===`Flex`||n===`visible`&&e.visibility===`Hidden`?e:e.kind===`Defn`?{...e,definition:vt(e.definition,t)}:{...e,expression:t(e.expression)},N=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,dt(t)),e);switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Lambda`:{let i=t.params.reduce((e,t)=>{let n=ft(t);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=st(e,t.sequent.context,(e,t)=>{let a=yt(t,t=>n(e,t),i);return[r(e,a),a]});return{...t,sequent:{context:o,active:n(a,t.sequent.active)}}}case`Let`:{let[i,a]=st(e,t.definitions,(e,t)=>{let i=vt(t,t=>n(e,t));return[r(e,pt(i)),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=ht(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=ht(t.bounds,a);return{...t,bounds:e,element:n(o(e),t.element)}}case`Tquant`:{let i=t.names.reduce((e,t)=>r(e,{kind:`Flex`,name:t}),e);return{...t,body:n(i,t.body)}}case`Choose`:{let i=t.domain&&a(t.domain),o=i?M(t.name,i):lt(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=M(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>gt(e,a));return{...t,expression:a(t.expression),selectors:e}}case`Apply`:{let e=t.args.map(a);return{...t,operator:a(t.operator),args:e}}case`With`:case`Dot`:case`Parens`:return{...t,expression:a(t.expression)};case`If`:{let e=a(t.alternative),n=a(t.consequent);return{...t,condition:a(t.condition),consequent:n,alternative:e}}case`List`:return{...t,items:t.items.map(a)};case`SetEnum`:case`Tuple`:return{...t,elements:t.elements.map(a)};case`Product`:return{...t,factors:t.factors.map(a)};case`FcnApp`:{let e=t.args.map(a);return{...t,function:a(t.function),args:e}}case`Arrow`:{let e=a(t.range);return{...t,domain:a(t.domain),range:e}}case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:a(e.value)}))};case`Except`:{let e=_t(t.specs,a);return{...t,function:a(t.function),specs:e}}case`Sub`:case`Tsub`:case`Fair`:return{...t,subscript:a(t.subscript),action:a(t.action)};case`Case`:{let e=t.other&&a(t.other),n=t.arms.map(e=>{let t=a(e.body);return{condition:a(e.condition),body:t}});return{...t,arms:n,other:e}}}},bt=(e,t)=>N(void 0,e,(e,n)=>t(n),()=>void 0,`all`),xt=e=>{let t=[];return bt(e,e=>(t.push(e),e)),t},P=e=>({kind:`Shift`,amount:e}),St=(e,t)=>({kind:`Cons`,expression:e,rest:t}),Ct=(e,t)=>e.reduce((e,t)=>St(t,e),t),F=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},wt=(e,t,n)=>{switch(e.kind){case`Shift`:return O({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?O(mt(e.expression),n):wt(e.rest,t-1,n);case`Compose`:return I(e.outer,wt(e.inner,t,n));case`Bump`:return t<=e.amount?O({kind:`Ix`,index:t},n):I(P(e.amount),wt(e.rest,t-e.amount,n))}},Tt=(e,t)=>t.map(t=>I(e,t)),Et=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e.w(`Arity mismatch`);return mt(I(Ct(n,P(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?mt(t):{kind:`Apply`,operator:t,args:n}},Dt=(e,t)=>[F(t.length,e),ht(t,t=>I(e,t))],Ot=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return vt(t,t=>I(e,t));case`Instance`:{let n=F(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:I(n,e.expression)}))}}}}},kt=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:I(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:Ot(e,t.definition)};case`Fact`:return{...t,expression:I(e,t.expression)}}},At=(e,t)=>{let[n,r]=st(e,t.context,(e,t)=>[F(1,e),kt(e,t)]);return{context:r,active:I(n,t.active)}},I=(e,t)=>{let n=t=>I(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return wt(e,t.index,t);case`Apply`:return O(Et(n(t.operator),Tt(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>gt(e,n))};case`Lambda`:return{...t,body:I(F(t.params.length,e),t.body)};case`Let`:{let[n,r]=st(e,t.definitions,(e,t)=>[F(1,e),Ot(e,t)]);return{...t,definitions:r,body:I(n,t.body)}}case`Sequent`:return{...t,sequent:At(e,t.sequent)};case`With`:case`Dot`:case`Parens`:return{...t,expression:n(t.expression)};case`If`:return{...t,condition:n(t.condition),consequent:n(t.consequent),alternative:n(t.alternative)};case`List`:return{...t,items:Tt(e,t.items)};case`Quant`:case`Fcn`:{let[n,r]=Dt(e,t.bounds);return{...t,bounds:r,body:I(n,t.body)}}case`Tquant`:return{...t,body:I(F(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:I(F(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:I(F(1,e),t.body)};case`SetOf`:{let[n,r]=Dt(e,t.bounds);return{...t,bounds:r,element:I(n,t.element)}}case`SetEnum`:case`Tuple`:return{...t,elements:Tt(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`FcnApp`:return{...t,function:n(t.function),args:Tt(e,t.args)};case`Product`:return{...t,factors:Tt(e,t.factors)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:_t(t.specs,n)};case`Sub`:case`Tsub`:case`Fair`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)}}},L=(e,t)=>e===0?t:I(P(e),t),jt=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),Mt=(e,t)=>e&&t?R(e,t):!e&&!t,Nt=(e,t)=>{let n=new Map(e.map(e=>[e.name,e.value])),r=new Map(t.map(e=>[e.name,e.value]));if(n.size!==r.size)return!1;for(let[e,t]of n){let n=r.get(e);if(!n||!R(t,n))return!1}return!0},Pt=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&R(e.domain.expression,t.domain.expression)),Ft=(e,t)=>{if(e.kind!==t.kind)return!1;switch(e.kind){case`Number`:return t.kind===`Number`&&e.value===t.value;case`Instance`:return t.kind===`Instance`&&jt(e.args,t.args,R);case`Label`:return t.kind===`Label`&&e.label===t.label&&jt(e.args,t.args,R);default:return!0}},It=(e,t)=>{if((e.kind===`Operator`||e.kind===`Bpragma`)&&t.kind===e.kind)return R(e.body,t.body);if(e.kind===`Instance`&&t.kind===`Instance`){let n=e.instance.substitutions.map(e=>({name:e.name,value:e.expression})),r=t.instance.substitutions.map(e=>({name:e.name,value:e.expression}));return jt(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&Nt(n,r)}return!1},Lt=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level===t.level&&e.shape===t.shape&&Mt(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?It(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&R(e.expression,t.expression),Rt=(e,t)=>jt(e.context,t.context,Lt)&&R(e.active,t.active),R=(e,t)=>{if(e.kind===`Parens`)return R(e.expression,t);if(t.kind===`Parens`)return R(e,t.expression);switch(e.kind){case`Ix`:return t.kind===`Ix`&&e.index===t.index;case`Opaque`:return t.kind===`Opaque`&&e.name===t.name;case`Internal`:return t.kind===`Internal`&&e.builtin===t.builtin;case`Lambda`:return t.kind===`Lambda`&&e.params.length===t.params.length&&R(e.body,t.body);case`Apply`:return t.kind===`Apply`&&R(e.operator,t.operator)&&jt(e.args,t.args,R);case`Sequent`:return t.kind===`Sequent`&&Rt(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&R(e.expression,t.expression)&&jt(e.selectors,t.selectors,Ft);case`With`:return t.kind===`With`&&R(e.expression,t.expression);case`Let`:return t.kind===`Let`&&jt(e.definitions,t.definitions,It)&&R(e.body,t.body);case`If`:return t.kind===`If`&&R(e.condition,t.condition)&&R(e.consequent,t.consequent)&&R(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&jt(e.items,t.items,R);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&jt(e.bounds,t.bounds,Pt)&&R(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&jt(e.names,t.names,(e,t)=>e===t)&&R(e.body,t.body);case`Choose`:return t.kind===`Choose`&&Mt(e.domain,t.domain)&&R(e.body,t.body);case`SetSt`:return t.kind===`SetSt`&&R(e.domain,t.domain)&&R(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&R(e.element,t.element)&&jt(e.bounds,t.bounds,Pt);case`SetEnum`:case`Tuple`:return t.kind===e.kind&&jt(e.elements,t.elements,R);case`Arrow`:return t.kind===`Arrow`&&R(e.domain,t.domain)&&R(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&jt(e.bounds,t.bounds,Pt)&&R(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&jt([e.function,...e.args],[t.function,...t.args],R);case`Product`:return t.kind===`Product`&&jt(e.factors,t.factors,R);case`Rect`:case`Record`:return t.kind===e.kind&&Nt(e.fields,t.fields);case`Except`:return t.kind===`Except`&&R(e.function,t.function)&&jt(e.specs,t.specs,(e,t)=>jt(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&R(e.expression,t.expression))&&R(e.value,t.value));case`Dot`:return t.kind===`Dot`&&R(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&R(e.action,t.action)&&R(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&R(e.subscript,t.subscript)&&R(e.action,t.action);case`Case`:return t.kind===`Case`&&(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:R(e.arms[0].condition,t.arms[0].condition)&&R(e.arms[0].body,t.arms[0].body))&&Mt(e.other,t.other);case`String`:return t.kind===`String`&&e.value===t.value;case`Num`:return t.kind===`Num`&&e.integer===t.integer&&e.fraction===t.fraction;case`At`:return t.kind===`At`&&e.isExcept===t.isExcept}},zt={kind:`Opaque`,name:`$Bad`},Bt=e=>e.kind===`Opaque`&&e.name===zt.name,Vt=e=>{let t=e.kind===`Parens`?Vt(e.expression):bt(e,Vt);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},Ht=e=>e.kind===`Let`?O({kind:`Let`,definitions:e.definitions,body:Ht(e.body)},e.body):e.kind===`Parens`?Ht(e.expression):bt(e,Ht),Ut=e=>e.kind===`Ix`?e.index<=0:xt(e).some(Ut),Wt=(e,t,n)=>{let r=(e,r=n)=>Wt(e,t,r),i=(e,t)=>e.reduce((e,t)=>e??(t.domain.kind===`Domain`?r(t.domain.expression):void 0),void 0)??r(t,[...n,...e.map(dt)]);switch(e.kind){case`Parens`:return e.form.kind===`Xlabel`?e.form.label===t?{context:n,expression:e.expression,indices:e.form.indices}:void 0:r(e.expression);case`Lambda`:return r(e.body,[...n,...e.params.map(ft)]);case`Let`:{let t=[...n];for(let n of e.definitions){let e=n.kind===`Operator`||n.kind===`Bpragma`?r(n.body,[...t]):void 0;if(e)return e;t.push({kind:`Defn`,definition:n,whereDefined:`Builtin`,visibility:`Visible`,isLocal:!0})}return r(e.body,t)}case`Quant`:case`Fcn`:return i(e.bounds,e.body);case`SetOf`:return i(e.bounds,e.element);case`Tquant`:return r(e.body,[...n,...e.names.map(e=>({kind:`Flex`,name:e}))]);case`Choose`:case`SetSt`:return(e.domain&&r(e.domain))??r(e.body,[...n,lt(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of xt(e)){let e=r(t);if(e)return e}return}},Gt=(e,t)=>Ct(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),P(e+t)),Kt=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),qt=(t,n,r)=>{switch(n.kind){case`Quant`:case`Fcn`:case`SetOf`:{if(n.bounds.length!==r.length){let i=n.bounds.length,a=`Arity mismatch in subexpression instance.\nExpected ${i} argument${i===1?``:`s`}, but found${r.length<i?` only`:``} ${r.length}.`;throw t(D(n.location,a)),new e.w(a,{failure:`Expr.Deref.deref_inst`})}let i=n.kind===`SetOf`?n.element:n.body;return I(Ct(r,P(0)),i)}case`Tquant`:return qt(t,O({kind:`Quant`,quantifier:n.quantifier,bounds:n.names.map(e=>({name:e,level:`State`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`Lambda`:return qt(t,O({kind:`Quant`,quantifier:`Forall`,bounds:n.params.map(e=>({name:e.name,level:`Unknown`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`SetSt`:case`Choose`:if(r.length!==1){let i=`Arity mismatch in subexpression instance.\nExpected 1 argument, but found ${r.length}.`;throw t(D(n.location,i)),new e.w(i,{failure:`Expr.Deref.deref_inst`})}return I(Ct(r,P(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw t(D(n.location,r)),new e.w(r,{failure:`Expr.Deref.deref_inst`})}}},Jt=(t,n,r)=>{let i=(()=>{switch(r.kind){case`Quant`:case`Fcn`:case`SetOf`:return r.bounds.map(e=>({name:e.name,shape:0}));case`Tquant`:return r.names.map(e=>({name:e,shape:0}));case`Lambda`:return r.params;case`SetSt`:case`Choose`:return[{name:r.name,shape:0}];default:{let n=`Cannot abstract over bound variables in a non-binding expression`;throw t(D(r.location,n)),new e.w(n,{failure:`Expr.Deref.deref_at`})}}})(),a=I(Gt(n,i.length),r);return[i,qt(t,a,Kt(i.length))]},Yt=(t,n,r,i,a)=>{let o=n=>{if(!(r<=n))throw t(D(i.location,a)),new e.w(a,{failure:`Expr.Deref.deref_num`})},s=e=>(o(e.length),e[r-1]);if(n.kind===`With`)return Yt(t,n.expression,r,i,a);let c=(()=>{switch(n.kind){case`Sequent`:{let i=n.sequent;o(i.context.length+1);let a=i.context[r-1];if(a&&a.kind!==`Fact`){let r=`subexpression reference does not resolve to an expression`;throw t(D(n.location,r)),new e.w(r,{failure:`Expr.Deref.deref_num`})}let s=I(P(-(r-1)),a?a.expression:i.active);if(Ut(s))throw t(D(n.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
20
- Tlapm does not handle yet such subexpression namings.`)),new e.w(`Subexpression of ASSUME/PROVE uses identifiers declared therein
21
-
22
- Tlapm does not handle yet such subexpression namings.`,{failure:`Expr.Deref.deref_num`});return s}case`Apply`:return s(n.args);case`If`:return s([n.condition,n.consequent,n.alternative]);case`List`:return s(n.items);case`SetEnum`:case`Tuple`:return s(n.elements);case`Product`:return s(n.factors);case`Let`:return o(1),n.body;case`Quant`:case`SetOf`:case`Fcn`:return s(n.bounds.flatMap(e=>e.domain.kind===`Domain`?[e.domain.expression]:[]));case`Choose`:case`SetSt`:if(!n.domain)break;return s([n.domain]);case`Arrow`:return s([n.domain,n.range]);case`FcnApp`:{let e=n.args.length===1?n.args[0]:O({kind:`Tuple`,elements:n.args},n);return s([n.function,e])}case`Rect`:case`Record`:return s(n.fields.map(e=>e.value));case`Dot`:return s([n.expression,O({kind:`String`,value:n.field},n)]);case`Except`:return s([n.function,...n.specs.map(e=>e.value)]);case`Sub`:case`Tsub`:return s([n.action,n.subscript]);case`Fair`:return s([n.subscript,n.action]);case`Case`:return s([...n.arms.map(e=>O({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...n.other?[O({kind:`Tuple`,elements:[zt,n.other]},n.other)]:[]])}let i=`Expression has no subexpressions`;throw t(D(n.location,i)),new e.w(i,{failure:`Expr.Deref.deref_num`})})();if(Bt(c)){let i=`Cannot resolve subexpression reference !${r}`;throw t(D(n.location,i)),new e.w(i,{failure:`Expr.Deref.deref_num`})}return[n.kind===`Let`?n.definitions:[],c]},Xt=(e,t)=>{let n=e.length,r=e;for(let e=n-1;e>=0;e--)r.includes(n-e)||(r=r.map(t=>t+e<n?t:t-1));return r.map(e=>t[n-e])},Zt=(t,n,r,i,a)=>{let o=Wt(r,i,[]);if(!o)return t(D(r.location,`Could not find label ${i}`)),{params:[],definitions:[],expression:zt};let s=o.indices;if(s.length!==a.length&&a.length>0){let n=s.length===1?``:`s`,r=`Expected ${s.length} argument${n} for labelled reference !${i}, but found ${a.length}`;throw t(D(o.expression.location,r)),new e.w(r,{failure:`Expr.Deref.deref_lsub`})}let c=a.length===0?s.map(e=>({name:e.name,shape:0})):[],l=a.length===0?Kt(s.length):a,u=o.context.reduceRight((e,t)=>t.kind===`Defn`?O({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?O({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):I(P(-1),e),o.expression),d=I(Gt(n,c.length),u),f=[],p=d,m=Xt(s.map(e=>e.index),l);for(;m.length>0;)if(p.kind===`Let`&&p.definitions.length===1)f.push(p.definitions[0]),p=p.body,m=m.map(e=>I(P(1),e));else{if(p.kind!==`Quant`||p.bounds.length!==1)throw new e.M(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);p=I(St(m[0],P(0)),p.body),m=m.slice(1)}return{params:c,definitions:f,expression:p}},Qt=(t,n,r,i,a)=>{if(r.kind!==`Let`)throw t(D(r.location,`not a LET expression`)),new e.w(`not a LET expression`,{failure:`Expr.Deref.deref_letop`});let o=r.definitions.findIndex(e=>e.kind===`Operator`&&e.name===i),s=r.definitions[o];if(!s||s.kind!==`Operator`){let n=`no definition of operator ${i}`;throw t(D(r.location,n)),new e.w(n,{failure:`Expr.Deref.deref_letop`})}let c=s.body,l=c.kind===`Lambda`?O({...c,body:O({kind:`Parens`,expression:c.body,form:{kind:`Xlabel`,label:i,indices:c.params.map((e,t)=>({name:e.name,index:c.params.length-t}))}},c.body)},c):O({kind:`Parens`,expression:c,form:{kind:`Xlabel`,label:i,indices:[]}},c);return Zt(t,n,O({kind:`Let`,definitions:r.definitions.slice(0,o),body:l},c),i,a)},$t=(t,n,r,i)=>{let[a,...o]=i;if(!a){let e=r.definitions.length===0?r.expression:O({kind:`Let`,definitions:r.definitions,body:r.expression},r.expression),t=r.params.length===0?e:O({kind:`Lambda`,params:r.params,body:e},e);return{...Vt(t),isAtomic:!0}}if(r.expression.isAtomic)return t(D(r.expression.location,`Expression has no subexpressions`)),zt;let s=n?r.expression:Ht(r.expression),c=r.definitions.length,l=(()=>{let i=(e,n)=>{let[i,a]=Yt(t,s,e,r.expression,n);return{params:[],definitions:i,expression:a,rest:o,isLabel:!1}};switch(a.kind){case`Down`:{let[r,...i]=o;if(s.kind===`Let`&&r?.kind===`Label`&&n)return{...Qt(t,c,s,r.label,r.args),rest:i,isLabel:!0};if(n)return{params:[],definitions:[],expression:s,rest:o,isLabel:!1};throw new e.w(`!: is forbidden for this expression.
23
- `,{failure:`Expr.Deref.deref: !:`})}case`Number`:return i(a.value,`Cannot resolve !${a.value}`);case`Left`:return i(1,`Cannot resolve !<<`);case`Right`:return i(2,`Cannot resolve !>>`);case`Instance`:return{params:[],definitions:[],expression:qt(t,s,a.args),rest:o,isLabel:!1};case`Label`:return{...s.kind===`Let`&&!n?Qt(t,c,s,a.label,a.args):Zt(t,c,s,a.label,a.args),rest:o,isLabel:!0};case`At`:{let[e,n]=Jt(t,c,s);return{params:e,definitions:[],expression:n,rest:o,isLabel:!1}}}})();return $t(t,l.isLabel,{params:[...r.params,...l.params],definitions:[...r.definitions,...l.definitions],expression:l.expression},l.rest.map(e=>gt(e,e=>I(P(l.definitions.length),e))))},en=(e,t,n)=>{if(n.length>0)return{params:[],definitions:[],expression:qt(e,t,n)};if(t.kind!==`Lambda`)return{params:[],definitions:[],expression:t};let[r,i]=Jt(e,0,t);return{params:r,definitions:[],expression:i}},tn=(t,n,r,i)=>{let a=$t(t,!0,en(t,n,r),i);if(Bt(a)){let r=`Could not resolve subexpression reference`;throw t(D(n.location,r)),new e.w(r,{failure:`Expr.Anon: 2`})}return a},nn=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),rn=e=>k(`UNCHANGED`,[e],e),an=e=>k(`Eq`,[k(`Prime`,[e],e),e],e),on=e=>{let t=e=>e.kind===`Tuple`?e.elements.flatMap(t):[e],n=t(e);return n.length===0?O({kind:`Internal`,builtin:`TRUE`},e):n.length===1?an(n[0]):O({kind:`List`,bullet:`And`,items:n.map(an)},e)},sn=e=>t=>{let n=sn(e);return e(t,n)??bt(t,n)},cn=sn((e,t)=>e.kind===`Apply`&&nn(e,[`Leadsto`])?k(`BoxTrue`,[k(`Implies`,[t(e.args[0]),k(`Diamond`,[t(e.args[1])],e)],e)],e):void 0),ln=sn(e=>{if(e.kind!==`Fair`)return;let t=e.action,n=e.subscript,r=k(`ENABLED`,[O({kind:`Sub`,modal:`Dia`,action:t,subscript:n},t)],t),i=e.fairness===`Weak`?`Diamond`:`BoxTrue`,a=e.fairness===`Weak`?`BoxTrue`:`Diamond`;return k(`Implies`,[k(i,[k(a,[r],t)],t),k(`BoxTrue`,[O({kind:`Tsub`,modal:`Dia`,action:t,subscript:n},t)],t)],t)}),un=sn((e,t)=>{if(e.kind!==`Sub`&&e.kind!==`Tsub`)return;let n=t(e.action),r=t(e.subscript),i=e.modal===`Box`?k(`Disj`,[n,rn(r)],e):k(`Conj`,[n,k(`Neg`,[rn(r)],e)],e);return e.kind===`Sub`?i:k(e.modal===`Box`?`BoxTrue`:`Diamond`,[i],e)}),dn=sn(e=>e.kind===`Apply`&&nn(e,[`UNCHANGED`])?on(e.args[0]):void 0),fn=[`Prime`,`StrongPrime`,`Leadsto`,`ENABLED`,`UNCHANGED`,`Cdot`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`],pn=/* @__PURE__ */ new WeakMap,mn=(e,t)=>{switch(t.kind){case`Fresh`:return t.level===`Constant`;case`Defn`:return t.definition.kind===`Operator`&&gn(e,t.definition.body);case`Fact`:return gn(e,t.expression);case`Flex`:return!1}},hn=(e,t)=>j(e,t.map(e=>lt(e,`Constant`))),gn=(e,t)=>{let n=t=>gn(e,t);switch(t.kind){case`Ix`:{let n=ot(e,t.index-1),r=n?.hyp;if(r?.kind===`Fresh`)return r.level===`Constant`;if(r?.kind!==`Defn`||r.definition.kind!==`Operator`||r.isConstnessUnset)return!1;let i=r.definition.body,a=pn.get(i);if(a!==void 0)return a;let o=gn(n?.rest,i);return pn.set(i,o),o}case`Opaque`:case`String`:case`Num`:case`At`:return!0;case`Internal`:return!fn.includes(t.builtin);case`Tquant`:case`Sub`:case`Tsub`:case`Fair`:return!1;case`Lambda`:return gn(hn(e,t.params.map(e=>e.name)),t.body);case`Sequent`:{let n=t.sequent.context.reduce((e,t)=>({scope:A(e.scope,t),isGood:e.isGood&&mn(e.scope,t)}),{scope:e,isGood:!0});return n.isGood&&gn(n.scope,t.sequent.active)}case`Bang`:case`With`:case`Dot`:case`Parens`:return n(t.expression);case`Apply`:return n(t.operator)&&t.args.every(n);case`Let`:{let n=t.definitions.reduce((e,t)=>({scope:A(e.scope,pt(t)),isGood:e.isGood&&t.kind===`Operator`&&gn(e.scope,t.body)}),{scope:e,isGood:!0});return n.isGood&&gn(n.scope,t.body)}case`Quant`:case`Fcn`:case`SetOf`:{let r=t.kind===`SetOf`?t.element:t.body;return t.bounds.every(e=>e.domain.kind!==`Domain`||n(e.domain.expression))&&gn(hn(e,t.bounds.map(e=>e.name)),r)}case`Choose`:case`SetSt`:return(t.domain===void 0||n(t.domain))&&gn(hn(e,[t.name]),t.body);case`If`:return n(t.condition)&&n(t.consequent)&&n(t.alternative);case`List`:return t.items.every(n);case`Tuple`:case`SetEnum`:return t.elements.every(n);case`Product`:return t.factors.every(n);case`FcnApp`:return n(t.function)&&t.args.every(n);case`Rect`:case`Record`:return t.fields.every(e=>n(e.value));case`Arrow`:return n(t.domain)&&n(t.range);case`Except`:return n(t.function)&&t.specs.every(e=>e.trail.every(e=>e.kind===`Dot`||n(e.expression))&&n(e.value));case`Case`:return t.arms.every(e=>n(e.condition)&&n(e.body))&&(t.other===void 0||n(t.other))}},_n=(e,t,n)=>{if(gn(e,t))return!0;if(t.kind===`Internal`)return[`Eq`,`Neq`,`UNCHANGED`,`TRUE`,`FALSE`].includes(t.builtin);if(t.kind===`List`)return t.items.every(t=>_n(e,t,n));if(t.kind===`Sequent`)return _n(j(e,t.sequent.context),t.sequent.active,n);if(t.kind!==`Apply`)return!1;let r=t.args;return nn(t,[`BoxTrue`,`BoxFalse`])&&n||nn(t,[`Diamond`])&&!n?!0:r.length===1&&nn(t,[`BoxTrue`,`BoxFalse`,`Diamond`,`Prime`])?_n(e,r[0],n):r.length===1&&nn(t,[`Neg`])?_n(e,r[0],!n):r.length===2&&nn(t,[`Conj`,`Disj`])?_n(e,r[0],n)&&_n(e,r[1],n):r.length===2&&nn(t,[`Implies`])?_n(e,r[0],!n)&&_n(e,r[1],n):r.length===2&&nn(t,[`Equiv`])?[!0,!1].every(t=>_n(e,r[0],n!==t)&&_n(e,r[1],n===t)):_n(e,t.operator,n)&&r.every(t=>_n(e,t,n))},vn=(e,t)=>_n(e,cn(ln(un(dn(t)))),!0)?`Always`:`Now`,yn=(e,t)=>t===`Always`&&e.some(e=>e.kind===`Fact`&&e.time===`Now`)?`Now`:t,bn=e=>e.kind===`Named`?`<${e.level}>${e.label}`:`<${e.level}>`,xn=e=>++e.value,Sn={kind:`Fact`,expression:{kind:`At`,isExcept:!1},visibility:`Visible`,time:`Always`},Cn={Number:`1NUM`,Down:`1DOWN`,At:`1AT`,Instance:`1INST`,Left:`1`,Right:`1`},wn={kind:`Opaque`,name:`$badexp`},Tn=(e,t)=>t.location?{...e,location:t.location}:e,En=(t,n,r)=>{let i,a=e=>({warnedSteps:[],scope:e}),o=e=>e.scope?.size??0,s=(e,t)=>{if(t.kind===`At`&&t.isExcept)return i?L(o(e)-i.size,i.expression):t;if(t.kind!==`Except`)return f(e,t);let n=s(e,t.function);return t.specs.reduce((n,r)=>{let[a,c]=st(n,r.trail,(t,n)=>{if(n.kind===`Dot`)return[O({kind:`Dot`,expression:t,field:n.field},t),n];let r=s(e,n.expression);return[O({kind:`FcnApp`,function:t,args:[r]},t),{kind:`Apply`,expression:r}]}),l=i;i={expression:a,size:o(e)};let u=s(e,r.value);return i=l,O({kind:`Except`,function:n,specs:[{trail:c,value:u}]},t)},n)},c=(e,t,n)=>{let r=O({kind:`Ix`,index:e},n);return t.length===0?r:O({kind:`Apply`,operator:r,args:t},n)},l=(e,t,n,r,i)=>{if(t!==`Builtin`)return c(e,r,i);let a=L(e,n);return O(r.length===0?a:Et(a,r),i)},u=(t,n,i,a)=>{let o=at(t.scope,n);if(!o){let t=`Operator "${n}" not found`;throw r(D(a.location,t)),new e.w(t,{failure:`Expr.Anon: 4`})}let s=o.depth+1,u=o.hyp;switch(u.kind){case`Defn`:{let t=u.definition;if(t.kind===`Operator`)return l(s,u.whereDefined,t.body,i,a);if(t.kind===`Recursive`)throw new e.w(`Recursive operators not supported by TLAPS`,{failure:`Expr.Anon: Recursive`});return c(s,i,a)}case`Fresh`:return c(s,i,a);case`Flex`:return O({kind:`Ix`,index:s},a);case`Fact`:throw new e.M(`File "src/expr/e_anon.ml", line 230, characters 24-36: Assertion failed`)}},d=(t,n,i,a,o,c)=>{let u=at(t.scope,n);if(!u){let[o,...l]=a;if(o?.kind===`Label`){let e=o.args.map(e=>s(t,e));return d(t,`${n}!${o.label}`,[...i,...e],l,!0,c)}let u=`Operator "${n}" not found`;throw o&&r(D(c.location,u)),new e.w(u,{failure:`Expr.Anon: ${o?Cn[o.kind]:`1EMPTY`}`})}let f=u.hyp;if(f.kind!==`Defn`||f.definition.kind!==`Operator`&&f.definition.kind!==`Bpragma`)throw new e.w(`invalid subexpression reference`);let p=u.depth+1;if(a.length===0&&o)return i.length===0?O({kind:`Ix`,index:p},c):l(p,f.whereDefined,f.definition.body,i,c);let m=Tn(L(p,f.definition.body),c);return Tn(tn(r,m,i,a),c)},f=(e,t)=>{switch(t.kind){case`Bang`:{let n=t.expression;if(n.kind===`Apply`&&n.operator.kind===`Opaque`){let r=t.selectors.map(t=>gt(t,t=>s(e,t))),i=n.args.map(t=>s(e,t)),o=a(e.scope);return d(o,n.operator.name,i,r,!1,t)}return s(e,{...t,expression:O({kind:`Apply`,operator:n,args:[]},n)})}case`Apply`:{if(t.operator.kind!==`Opaque`)return v(e,t);let n=t.operator.name;if(e.warnedSteps.includes(n))return r({text:`${et(t.location)}Warning: ${n} does not introduce any assumptions. It does not make sense to use it here.\n`,channel:`toolbox`}),O({kind:`Internal`,builtin:`TRUE`},t);let i=t.args.map(t=>s(e,t));return u(e,n,i,t)}case`Opaque`:return s(e,O({kind:`Apply`,operator:t,args:[]},t));case`Parens`:return t.form.kind===`Syntax`?s(e,t.expression):{...t,expression:s(e,t.expression),form:p(e,t.form)};default:return v(e,t)}},p=(t,n)=>n.kind===`Nlabel`?{kind:`Xlabel`,label:n.label,indices:n.names.map(n=>{let r=at(t.scope,n);if(!r)throw new e.w(`Identifier "${n}" in label parameters not found`);return{name:n,index:r.depth+1}})}:n,m=(e,t)=>({warnedSteps:e.warnedSteps,scope:t}),h=(e,t)=>m(e,A(e.scope,t)),g=(e,t)=>m(e,j(e.scope,t.map(dt))),_=(e,t)=>{let n=ht(t,t=>s(e,t));return[g(e,n),n]},v=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:x(e,t.sequent)[1]};if(t.kind===`Let`){let[n,r]=b(e,t.definitions);return{...t,definitions:r,body:s(n,t.body)}}return N(e,t,s,h)},y=(e,t)=>{if(t.kind!==`Operator`)return t;let n=t.body;if(n.kind!==`Fcn`)return{...t,body:s(e,n)};let r=s(h(e,lt(t.name,`Constant`)),n);if(R(I(St({kind:`Opaque`,name:`%%%`},P(1)),r),r))return{...t,body:L(-1,r)};let i=k(`Eq`,[O({kind:`Ix`,index:1},r),r],r);return{...t,body:O({kind:`Choose`,name:t.name,domain:void 0,body:i},r)}},b=(e,t)=>{let r=e,i=[...t],a=[];for(let e=0;e<i.length;e++){let t=i[e];if(t.kind===`Instance`){i.splice(e+1,0,...n(r.scope,t));continue}let o=y(r,t);r=h(r,{...pt(o),isConstnessUnset:!0}),a.push(o)}return[r,a]},ee=(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:s(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:y(e,t.definition)};case`Fact`:{let n=s(e,t.expression);return{...t,expression:n,time:vn(e.scope,n)}}}})();return[h(e,n),n]},x=(e,t)=>{let[n,r]=st(e,t.context,ee);return[n,{context:r,active:s(n,t.active)}]},te=(e,t)=>({warnedSteps:[bn(t),...e.warnedSteps],scope:e.scope}),ne=(e,t,n,r)=>h(e,{kind:`Defn`,definition:{kind:`Operator`,name:bn(t),body:n,location:r.location},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!0,isConstnessUnset:!0,location:r.location}),S=(e,t)=>m(e,j(e.scope,Array.from({length:t},()=>Sn))),re=e=>{let t=[...e.context.map((t,n)=>{let r=e.context.length-n+1;if(t.kind===`Fact`)return L(r,t.expression);if(t.kind!==`Fresh`||!t.domain)return wn;let i=k(`Mem`,[O({kind:`Ix`,index:0},t.domain),t.domain],t.domain);return L(r,i)}),L(1,e.active)];return t.length===1?t[0]:{kind:`Tuple`,elements:t}},ie=e=>e.kind!==`Use`&&e.kind!==`Hide`&&e.kind!==`Define`,ae=(e,t)=>({facts:t.facts.map(t=>s(e,t)),defs:t.defs.flatMap(t=>{if(t.kind===`Dx`)return[t];let n=s(e,O({kind:`Opaque`,name:t.name},t));return n.kind===`Ix`?ot(e.scope,n.index-1)?.hyp.kind===`Defn`?[{kind:`Dx`,index:n.index,location:t.location}]:(r({text:`${et(t.location)}${JSON.stringify(t.name)} is not a definition and cannot be used in a DEF clause.`,channel:`toolbox`}),[]):(r({text:`${et(t.location)}Ignored unexpandable identifier ${JSON.stringify(t.name)} in BY DEF.`,channel:`stderr`}),[])})}),C=(e,t)=>{switch(t.kind){case`Steps`:{let[n,r]=st(e,t.steps,oe),i=C(t.step?te(n,t.step):n,t.qed.proof);return{...t,steps:r,qed:{...t.qed,proof:i}}}case`By`:return{...t,usable:ae(e,t.usable)};default:return t}},oe=(n,r)=>{let i=r.step?.kind===`Unnamed`&&ie(r)?{kind:`Named`,level:r.step.level,label:`_a${xn(t)}`,isAnonymous:!0}:r.step;if(!i)throw new e.M;let a={...r,step:i};switch(a.kind){case`Assert`:{let[,e]=x(n,a.sequent),t=e.context.reduce(h,n),r=S(ne(S(t,1),i,O(re(e),a),a),1),o=e.context.length===0?te(r,i):r,s={...a,sequent:e,proof:C(o,a.proof)};return[S(ne(n,i,O(rt(e),a),a),1),s]}case`Pcase`:{let e=s(n,a.expression),t=O({kind:`Tuple`,elements:[L(2,e)]},a),r=S(ne(S(n,2),i,t,a),1),o={...a,expression:e,proof:C(r,a.proof)},c=ne(n,i,O({kind:`Tuple`,elements:[e]},a),a);return[S(c,1),o]}case`Suffices`:{let[,e]=x(n,a.sequent),t=O({kind:`Tuple`,elements:[O(rt(e),a)]},a),r=S(ne(n,i,t,a),1),o={...a,sequent:e,proof:C(r,a.proof)},s=e.context.reduce(h,n),c=O({kind:`Tuple`,elements:[O(re(e),a)]},a);return[S(ne(S(s,1),i,c,a),1),o]}case`Have`:{let e=s(n,a.expression),t=O({kind:`Tuple`,elements:[L(2,e)]},a);return[S(ne(S(n,2),i,t,a),1),{...a,expression:e}]}case`Take`:{let[e,t]=_(n,a.bounds),r=O({kind:`Quant`,quantifier:`Forall`,bounds:t,body:wn},a);return[S(ne(S(e,1),i,r,a),1),{...a,bounds:t}]}case`Witness`:{let e=a.expressions.map(e=>s(n,e)),t=O({kind:`Tuple`,elements:e},a);return[S(ne(S(n,1),i,t,a),1),{...a,expressions:e}]}case`Pick`:{let[e,t]=_(n,a.bounds),r=s(e,a.expression),o=O({kind:`Quant`,quantifier:`Exists`,bounds:t,body:r},a),c=te(S(ne(S(n,1),i,o,a),1),i),l={...a,bounds:t,expression:r,proof:C(c,a.proof)},u=g(S(n,2),t),d=L(4+t.length,o);return[S(ne(S(u,2),i,d,a),1),l]}case`Use`:{let e=ae(n,a.usable);return[S(n,e.facts.length),{...a,usable:e}]}case`Hide`:return[n,{...a,usable:ae(n,a.usable)}];case`Define`:{let[e,t]=b(n,a.definitions);return[e,{...a,definitions:t}]}case`Forget`:return[n,a]}};return{expr:(e,t)=>s(a(e),t),defn:(e,t)=>y(a(e),t),sequent:(e,t)=>x(a(e),t)[1],usable:(e,t)=>ae(a(e),t),proof:(e,t)=>C(a(e),t)}},z=(e,t,n)=>({kind:`Definition`,definition:{kind:`Operator`,name:t,body:e===0?{kind:`Internal`,builtin:n}:{kind:`Lambda`,params:Array.from({length:e},(e,t)=>({name:`x${t+1}`,shape:0})),body:{kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n}))}}},whereDefined:`Builtin`,visibility:`Visible`,isLocal:!1}),Dn=[z(0,`Nat`,`Nat`),z(2,`+`,`Plus`),z(2,`-`,`Minus`),z(2,`*`,`Times`),z(2,`^`,`Exp`),z(2,`<`,`Lt`),z(2,`>`,`Gt`),z(2,`=<`,`Lteq`),z(2,`>=`,`Gteq`),z(2,`%`,`Remainder`),z(2,`\\div`,`Quotient`),z(2,`..`,`Range`)],On=[...Dn,z(0,`Int`,`Int`),z(1,`-.`,`Uminus`)],kn=[...On,z(0,`Real`,`Real`),z(2,`/`,`Ratio`),z(0,`Infinity`,`Infinity`)],An=[z(1,`Seq`,`Seq`),z(1,`Len`,`Len`),z(2,`BSeq`,`BSeq`),z(2,`\\o`,`Cat`),z(2,`Append`,`Append`),z(1,`Head`,`Head`),z(1,`Tail`,`Tail`),z(3,`SubSeq`,`SubSeq`),z(2,`SelectSeq`,`SelectSeq`)],jn=[z(2,`Print`,`Print`),z(1,`PrintT`,`PrintT`),z(2,`Assert`,`Assert`),z(0,`JavaTime`,`JavaTime`),z(1,`TLCGet`,`TLCGet`),z(2,`TLCSet`,`TLCSet`),z(2,`:>`,`OneArg`),z(2,`@@`,`Extend`),z(1,`Permutations`,`Permutations`),z(2,`SortSeq`,`SortSeq`),z(1,`RandomElement`,`RandomElement`),z(0,`Any`,`Any`),z(1,`ToString`,`ToString`)],Mn=(e,t)=>({name:e,extendees:[],body:t,isImportant:!1,isStandard:!0}),Nn=new Map([Mn(`Naturals`,Dn),Mn(`Integers`,On),Mn(`Reals`,kn),Mn(`Sequences`,An),Mn(`TLC`,jn)].map(e=>[e.name,e])),Pn=e=>{let t=e.location;switch(e.kind){case`Constants`:return e.declarations.map(e=>({...lt(e.name,`Constant`,e.shape),location:t}));case`Recursives`:return e.declarations.map(e=>({kind:`Defn`,definition:{kind:`Recursive`,name:e.name,shape:e.shape,location:t},whereDefined:`User`,visibility:`Hidden`,isLocal:!1,location:t}));case`Variables`:return e.names.map(e=>({kind:`Flex`,name:e,location:t}));case`Definition`:return[{kind:`Defn`,definition:e.definition,whereDefined:e.whereDefined,visibility:e.visibility,isLocal:e.isLocal,location:t}];case`Axiom`:case`Theorem`:{let n=e.kind===`Axiom`?e.expression:O(rt(At(P(-e.axiomCount),{...e.sequent,context:e.sequent.context.slice(e.axiomCount)})),e);return e.name===void 0?[ut(n,`Hidden`,`Always`,t)]:In(e.name,n,t)}case`Mutate`:return e.mode===`Use`?e.usable.facts.map((e,n)=>ut(L(n,e),`Visible`,`Always`,t)):[];case`Submod`:case`Anoninst`:return[]}},Fn=e=>e.kind===`Axiom`||e.kind===`Theorem`?e.name===void 0?1:2:Pn(e).length,In=(e,t,n)=>[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:t,location:n},whereDefined:`User`,visibility:`Visible`,isLocal:!1,location:n},ut({kind:`Ix`,index:1,location:n},`Hidden`,`Always`,n)],Ln=e=>e.body.flatMap(e=>{switch(e.kind){case`Definition`:return[{...e,whereDefined:e.isLocal?`Builtin`:e.whereDefined}];case`Mutate`:return[];case`Theorem`:return[{...e,proof:{kind:`Omitted`,omission:`Elsewhere`,location:e.location}}];case`Submod`:return[{...e,module:{...e.module,body:Ln(e.module)}}];default:return[e]}}),Rn=(t,n,r,i=/* @__PURE__ */ new Set([n.name]))=>{let a=[];for(let o of n.extendees){if(r.has(o))continue;if(i.has(o))throw new e.M(`Stack overflow`);let n=t.get(o);if(!n)throw new e.w(`Module "${o}" unknown`);a.push(...Ln(Rn(t,n,r,/* @__PURE__ */ new Set([...i,o])))),r.add(o)}return{...n,body:[...a,...n.body].map(e=>e.kind===`Submod`?{...e,module:Rn(t,e.module,/* @__PURE__ */ new Set)}:e)}},zn=e=>{let t=/* @__PURE__ */ new Map,n=(e,n)=>{t.has(e)||t.set(e,n)},r=e=>e.extendees.forEach((t,r)=>n(t,e.extendeeLocations?.[r])),i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Map,o=e=>{typeof e==`object`&&e&&(`instance`in e&&Bn(e.instance)&&n(e.instance.module,e.instance.location),Object.values(e).forEach(o))},s=e=>{e.kind===`Submod`?(i.add(e.module.name),a.set(e.module.name,e.module),r(e.module),e.module.body.forEach(s)):o(e.kind===`Theorem`?e.sequent:e)};return e.body.forEach(s),i.forEach(e=>t.delete(e)),r(e),{dependencies:[...t.keys()].sort(Vn),locations:t,submodules:a}},Bn=e=>typeof e==`object`&&!!e&&`module`in e&&typeof e.module==`string`&&`substitutions`in e,Vn=(e,t)=>e<t?-1:+(e>t),Hn=(t,n)=>({facts:Tt(t,n.facts),defs:n.defs.map(n=>{if(n.kind===`Dvar`)return n;let r=I(t,{kind:`Ix`,index:n.index});if(r.kind!==`Ix`)throw new e.w(`substitution produced bad definition`);return{...n,index:r.index}})}),Un=(e,t)=>{switch(t.kind){case`Constants`:case`Recursives`:return[F(t.declarations.length,e),t];case`Variables`:return[F(t.names.length,e),t];case`Definition`:return[F(1,e),{...t,definition:Ot(e,t.definition)}];case`Axiom`:return[F(Fn(t),e),{...t,expression:I(e,t.expression)}];case`Theorem`:return[F(Fn(t),e),{...t,sequent:At(e,t.sequent)}];case`Submod`:return[e,{...t,module:{...t.module,body:Wn(e,t.module.body)}}];case`Mutate`:return[t.mode===`Hide`?e:F(t.usable.facts.length,e),{...t,usable:Hn(e,t.usable)}];case`Anoninst`:return[e,{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(t=>({name:t.name,expression:I(e,t.expression)}))}}]}},Wn=(e,t)=>st(e,t,Un)[1],Gn=(e,t,n)=>e===void 0?{hyps:[],sequent:t}:{hyps:[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:O(rt(t),{location:n}),location:n},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:n}],sequent:At(P(1),t)},Kn={kind:`At`,isExcept:!1},qn=e=>e?.kind===`Named`&&e.isAnonymous,Jn=e=>O({kind:`Internal`,builtin:`TRUE`},e),Yn=(e,t)=>t.context.flatMap((n,r)=>n.kind===`Fact`&&n.visibility===`Visible`?[L(e+t.context.length-1-r,n.expression)]:[]),Xn=(t,n,r)=>{if(!t.step)throw new e.M;return{kind:`Defn`,definition:{kind:`Operator`,name:bn(t.step),body:n,location:t.location},whereDefined:{kind:`Proof`,time:r},visibility:`Visible`,isLocal:!0,location:t.location}},Zn=(e,t,n,r)=>{let i=qn(n.step)?`Visible`:`Hidden`,a=t.context.map(e=>e.kind===`Fact`?{...e,visibility:i}:e),o=O({kind:`List`,bullet:`Refs`,items:Yn(2,t)},n),s=yn(t.context,r);return{context:[...e,...a,ut(Jn(n),`Hidden`,r,n.location),Xn(n,o,s),ut(O({kind:`Ix`,index:1},n),`Hidden`,s,n.location)],active:L(3,t.active),time:s}},Qn=(e,t,n,r,i,a)=>{let o=e||qn(i.step)?`Visible`:`Hidden`;return{context:[...t,Xn(i,O(rt(r),i),a),ut(O({kind:`Ix`,index:1},i),o,a,i.location)],active:L(2,n)}},$n=(e,t,n)=>{if(t.kind!==`Ix`)return n;let r=e[e.length-t.index];return r?.kind===`Fact`?r.time:r?.kind===`Defn`&&typeof r.whereDefined==`object`?r.whereDefined.time:`Always`},er=(t,n,r)=>{if(r.kind!==`Dx`)throw new e.w(`Unknown definition ${r.name}`);let i=n.length-r.index,a=n[i];if(!a)return n;if(a.kind!==`Defn`)throw new e.w(`Indicated point is not a definition`);return n.map((e,n)=>n===i?{...a,visibility:t}:e)},tr=(e,t)=>nt(e,`Mem`)&&e.args[0]?.kind===`Ix`&&e.args[0].index===0&&R(t,e.args[1]),nr=(t,n,r,i)=>{let a=!1,o=r,s=[...i];for(let e=i.length-1;e>=0;e--){o=L(-1,o);let t=i[e];t.kind===`Fact`&&R(t.expression,o)?(a=!0,s[e]={...t,visibility:n}):t.kind===`Fresh`&&t.domain&&tr(o,t.domain)&&(a=!0,s[e]={...t,domainVisibility:n})}if(!a){let n=`This expression does not appear in the context and cannot be hidden.`;throw t(D(r.location,`${n}\n`)),new e.w(n,{failure:`proof.Gen.set_expr`})}return s},rr=(e,t,n)=>({sequent:e,location:t.location,kind:n,method:t.method}),ir={total:0,absent:[],omitted:[]},ar=(e,t)=>({total:e.total+t.total,absent:[...e.absent,...t.absent],omitted:[...e.omitted,...t.omitted]}),or=e=>e.kind===`Use`?{...ir,total:e.obligations?.length??0}:`proof`in e?sr(e.proof):ir,sr=e=>e.kind===`Steps`?[...e.steps.map(or),sr(e.qed.proof)].reduce(ar):e.kind!==`Omitted`||!e.obligations||!e.location?{...ir,total:e.obligations?.length??0}:{total:e.obligations.length,absent:e.omission===`Implicit`?[e.location]:[],omitted:e.omission===`Explicit`?[e.location]:[]},cr=(t,n,r)=>{let i=(r,o,s)=>{let c=o.location;if(!c||!t.has(c.file)||c.endLine<n.start||c.startLine>n.end)return o;switch(o.kind){case`Obvious`:return{...o,obligations:[rr(r,o,{kind:`Main`})]};case`Omitted`:return{...o,obligations:[rr(r,o,{kind:`Omitted`,omission:o.omission})]};case`Error`:return{...o,obligations:[rr(r,o,{kind:`Error`,message:o.message})]};case`By`:throw new e.w(`Proof.Gen.generate`);case`Steps`:{let[e,t]=st({sequent:r,time:s},o.steps,(e,t)=>{let[n,r,i]=a(e.sequent,t,e.time);return[{sequent:n,time:i},r]}),n=i(e.sequent,o.qed.proof,e.time);return{...o,steps:t,qed:{...o.qed,proof:n}}}}},a=(t,n,a)=>{switch(n.kind){case`Forget`:{let e=t.context.length,r=t.context.map((t,r)=>t.kind===`Fact`&&t.visibility===`Visible`&&n.count+r<e?{...t,visibility:`Hidden`}:t);return[{...t,context:r},n,a]}case`Use`:{let r=n.usable;if(r.defs.length===0&&r.facts.length===1){let e=r.facts[0],i=rr({...t,active:e},n,{kind:`Support`});return[{context:[...t.context,{...ut(e,`Visible`,$n(t.context,e,a),e.location),useLocation:n.useLocation}],active:L(1,t.active)},{...n,obligations:[i]},a]}if(r.facts.length>0)throw new e.w(`Proof.Gen.gen_step: USE with facts and definitions`);let i=r.defs.reduce((e,t)=>er(`Visible`,e,t),t.context);return[{...t,context:i},n,a]}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>er(`Hidden`,e,t),t.context),i=n.usable.facts.reduceRight((e,t)=>nr(r,`Hidden`,t,e),e);return[{...t,context:i},n,a]}case`Define`:return[{context:[...t.context,...n.definitions.map(e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0,location:e.location}))],active:L(n.definitions.length,t.active)},n,a];case`Assert`:{let e=Zn(t.context,n.sequent,n,a),r=i(e,n.proof,e.time),o={...n,proof:r};return[Qn(!1,t.context,t.active,n.sequent,o,a),o,a]}case`Suffices`:{let e=i(Qn(!0,t.context,t.active,n.sequent,n,a),n.proof,a),r={...n,proof:e},o=Zn(t.context,n.sequent,r,a);return[o,r,o.time]}default:throw new e.w(`Proof.Gen.gen_step`)}},o=(e,t,n,r)=>{let i={kind:`Unnamed`,level:0,id:0},[o,s]=a({context:e,active:{...Kn,location:r}},t===`Use`?{kind:`Use`,usable:n,isOnly:!1,location:r,step:i,useLocation:r}:{kind:`Hide`,usable:n,location:r,step:i},`Always`);return[o.context,s.obligations??[]]},s=(e,t,n,r)=>{if(n.defs.length===0&&n.facts.length===0)return[e,[]];let i=n.defs.length>0,[a,...c]=n.facts,[l,u]=o(e,t,i?{defs:n.defs,facts:[]}:{defs:[],facts:[a]},r),d=i?n.facts:c.map(e=>L(1,e)),[f,p]=s(l,t,{defs:[],facts:d},r);return[f,[...u,...p]]},c=e=>{let t=[],n=e=>{e.kind===`Steps`?(n(e.qed.proof),e.steps.forEach(r)):e.obligations&&t.push(...e.obligations)},r=e=>{e.kind===`Use`&&e.obligations&&t.push(...e.obligations),`proof`in e&&n(e.proof)};return n(e),t},l=(e,t)=>{let n=[],r=[],a=ir,o=e;for(let e of t.body)switch(e.kind){case`Theorem`:{let t=Gn(e.name,e.sequent,e.location),s=[...o,...t.hyps],l=[...s,...t.sequent.context],u=i({context:l,active:t.sequent.active},e.proof,yn(l,`Always`));n.push(...c(u));let d=sr(u);r.push({...d,location:e.location}),a=ar(a,d);let f=e.name===void 0?O(rt(e.sequent),e):{kind:`Ix`,index:1,location:e.location};o=[...s,ut(f,`Hidden`,`Always`,e.location)];continue}case`Submod`:{let t=l(o,e.module);n.push(...t.obligations),a=ar(a,t.summary);continue}case`Mutate`:{let[t,r]=s(o,e.mode,e.usable,e.location);n.push(...r),o=t;continue}default:o=[...o,...Pn(e)]}return{obligations:n,summary:{...a,theorems:r}}};return l},lr=(e,t=0)=>({level:e,weights:Array.from({length:t},()=>!0),params:/* @__PURE__ */ new Set}),ur={TRUE:[0,0],FALSE:[0,0],Implies:[0,2],Equiv:[0,2],Conj:[0,2],Disj:[0,2],Neg:[0,1],Eq:[0,2],Neq:[0,2],STRING:[0,0],BOOLEAN:[0,0],SUBSET:[0,1],UNION:[0,1],DOMAIN:[0,1],Subseteq:[0,2],Mem:[0,2],Notmem:[0,2],Setminus:[0,2],Cap:[0,2],Cup:[0,2],Actplus:[3,2],BoxTrue:[3,1],BoxFalse:[3,1],Diamond:[3,1],Prime:[2,1],StrongPrime:[2,1],ENABLED:[1,1],UNCHANGED:[2,1],Leadsto:[3,2],Cdot:[2,2],Nat:[0,0],Int:[0,0],Real:[0,0],Infinity:[0,0],Plus:[0,2],Minus:[0,2],Times:[0,2],Ratio:[0,2],Quotient:[0,2],Remainder:[0,2],Exp:[0,2],Divides:[0,2],Lteq:[0,2],Lt:[0,2],Gteq:[0,2],Gt:[0,2],Range:[0,2],Uminus:[0,1],Seq:[0,1],Len:[0,1],BSeq:[0,2],Cat:[0,2],Append:[0,2],Head:[0,1],Tail:[0,1],SubSeq:[0,3],SelectSeq:[0,2],OneArg:[0,2],Extend:[0,2],Print:[0,2],PrintT:[0,1],Assert:[0,2],JavaTime:[0,0],TLCGet:[0,1],TLCSet:[0,2],Permutations:[0,1],SortSeq:[0,2],RandomElement:[0,1],Any:[0,0],ToString:[0,1],Unprimable:[0,1]},dr={Constant:0,State:1,Action:2,Temporal:3,Unknown:0},fr=e=>new Set(e.flatMap(e=>[...e])),pr=e=>({level:Math.max(0,...e.map(e=>e.level)),weights:[],params:fr(e.map(e=>e.params))}),mr=/* @__PURE__ */ new WeakMap,hr=t=>{let n=t.hyp;switch(n.kind){case`Flex`:return lr(1);case`Fresh`:return{...lr(dr[n.level],n.shape),params:/* @__PURE__ */ new Set([n.name])};case`Defn`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e.M;return yr(t.rest,r.body)}case`Fact`:return yr(t.rest,n.expression)}},gr=e=>{let t=mr.get(e);if(t)return t;let n=hr(e);return mr.set(e,n),n},_r=(e,t,n)=>{let r=t.flatMap(t=>t.domain.kind===`Domain`?[yr(e,t.domain.expression)]:[]);return pr([yr(j(e,t.map(dt)),n),...r])},vr=(t,n)=>{if(t.weights.length!==n.length)throw new e.w(`Invalid number of arguments`);let r=n.filter((e,n)=>t.weights[n]);return{level:Math.max(t.level,...r.map(e=>e.level)),weights:[],params:fr([t.params,...r.map(e=>e.params)])}},yr=(t,n)=>{let r=e=>yr(t,e);switch(n.kind){case`Ix`:{let r=ot(t,n.index-1);if(!r)throw new e.M;return gr(r)}case`Internal`:{let t=ur[n.builtin];if(!t)throw new e.M;return lr(t[0],t[1])}case`Opaque`:case`String`:case`Num`:return lr(0);case`Lambda`:{let e=yr(j(t,n.params.map(ft)),n.body),r=new Set(n.params.map(e=>e.name));return{level:e.level,weights:n.params.map(t=>e.params.has(t.name)),params:new Set([...e.params].filter(e=>!r.has(e)))}}case`Apply`:{let t=n.operator;if(nt(t,`Prime`)&&t.args.length===1)return r({...n,operator:t.args[0]});if(t.kind===`Opaque`)return vr(lr(0,n.args.length),n.args.map(r));if(t.kind===`Internal`&&n.args.length===1){let i=n.args[0];switch(t.builtin){case`Prime`:case`StrongPrime`:if(r(i).level>1)throw new e.M;return lr(2,1);case`ENABLED`:{let t=r(i);if(t.level>2)throw new e.M;return{level:1,weights:[],params:t.params}}case`UNCHANGED`:{let t=r(i);if(t.level>1)throw new e.M;return{level:2,weights:[],params:t.params}}}}return t.kind===`Internal`&&t.builtin===`Cdot`?(n.args.forEach(r),lr(2)):t.kind===`Internal`&&t.builtin===`Leadsto`?(n.args.forEach(r),lr(3,2)):vr(r(t),n.args.map(r))}case`Sequent`:{let[e,r]=st(t,n.sequent.context,(e,t)=>{let n=A(e,t);return[n,gr(n).level]});return lr(Math.max(0,...r,yr(e,n.sequent.active).level))}case`With`:case`Dot`:case`Parens`:return r(n.expression);case`Let`:return yr(j(t,n.definitions.map(pt)),n.body);case`If`:return pr([n.condition,n.consequent,n.alternative].map(r));case`List`:return pr(n.items.map(r));case`Quant`:case`Fcn`:return _r(t,n.bounds,n.body);case`SetOf`:return _r(t,n.bounds,n.element);case`Tquant`:return yr(j(t,n.names.map(e=>({kind:`Flex`,name:e}))),n.body),lr(3);case`Choose`:case`SetSt`:{let e=n.domain&&r(n.domain),i=n.domain?M(n.name,n.domain):lt(n.name,`Constant`);return pr([yr(A(t,i),n.body),...e?[e]:[]])}case`SetEnum`:case`Tuple`:return pr(n.elements.map(r));case`Product`:return pr(n.factors.map(r));case`FcnApp`:return pr([n.function,...n.args].map(r));case`Arrow`:return pr([r(n.domain),r(n.range)]);case`Rect`:case`Record`:return pr(n.fields.map(e=>r(e.value)));case`Except`:return pr([r(n.function),...n.specs.flatMap(e=>[...e.trail.flatMap(e=>e.kind===`Apply`?[r(e.expression)]:[]),r(e.value)])]);case`Sub`:return{...pr([r(n.action),r(n.subscript)]),level:2};case`Tsub`:case`Fair`:return r(n.action),r(n.subscript),lr(3);case`Case`:return pr([...n.arms.flatMap(e=>[r(e.condition),r(e.body)]),...n.other?[r(n.other)]:[]]);case`Bang`:case`At`:throw new e.M}},br=`EnabledWrapper`,xr=`CdotWrapper`,Sr="Nested occurrence of the operator `ENABLED` found in scope of `\\cdot` when expanding `\\cdot`. Using the proof directive `ExpandENABLED` from the module `TLAPS` is expected to avoid this error.For example, writing `BY ExpandENABLED`.",Cr="Nested occurrence of the operator `\\cdot` found in scope of `ENABLED` when expanding `ENABLED`. Using the proof directive `ExpandCdot` from the module `TLAPS` is expected to avoid this error.",wr=`${Cr} For example, writing \`BY ExpandCdot\`.`,Tr=(e,t)=>N(void 0,e,(e,n)=>t(n),()=>void 0),Er=(t,n)=>{let r=ot(t,n-1)?.hyp;if(!r)throw new e.M;return r},Dr=e=>e.kind===`Internal`&&(e.builtin===`ENABLED`||e.builtin===`Cdot`),Or=e=>e.kind===`Opaque`&&(e.name===br||e.name===xr),kr=e=>e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`Lambda`&&(Dr(e.operator)||Or(e.operator)),Ar=e=>e===void 0?2:Math.min(2,e),jr=e=>e===void 0?void 0:Math.max(1,e-1),Mr=(t,n,r,i,a)=>{let o=(e,i=a)=>Mr(t,n,r,e,i);if(kr(i))return i;if(i.kind===`Sub`)return{...i,action:o(i.action),subscript:o(i.subscript,jr(a))};if(i.kind===`Apply`&&i.operator.kind===`Internal`){let r=i.operator.builtin,[s,c]=i.args;if(r===`Cdot`&&i.args.length===2){if(a!==void 0&&!t.isCdot)throw n(D(i.location,`${Cr}For example, writing \`BY ExpandCdot\`.`)),new e.T(`Expr.Action`);return{...i,args:t.isCdot?[o(s,Ar(a)),o(c,1)]:[o(s),o(c)]}}if(r===`ENABLED`&&i.args.length===1){if(a!==void 0&&!t.isEnabled)throw n(D(i.location,Sr)),new e.T(`Expr.Action`);return{...i,args:[t.isEnabled?o(s,Ar(a)):o(s)]}}if((r===`Prime`||r===`UNCHANGED`)&&i.args.length===1)return{...i,args:[o(s,jr(a))]}}let s=i.kind===`Apply`&&i.operator.kind===`Ix`?i.operator:i;if(s.kind!==`Ix`)return N(r,i,(e,r)=>Mr(t,n,e,r,a),A);if(a===void 0)return i;let c=yr(r,i).level,l=Er(r,s.index),u=e=>`The operator \`${e}\` is declared at:\n${Qe(l.location)}`;if(l.kind===`Fresh`&&l.level===`Unknown`)throw n(D(i.location,`Declared operator \`${l.name}\` has unknown level and occurs within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${a}.\nIf a constant operator is substituted for this operator, then the expression that results from applying this declared operator has expression level ${c}.\n May need expansion. A declared operator cannot be expanded.\n${u(l.name)}\n and has arity: ${l.shape}`)),new e.M(`File "src/expr/e_action.ml", line 367, characters 20-26: Assertion failed`);if(c<a)return i;if(c>2||l.kind===`Fact`)throw new e.M;if(l.kind===`Flex`){if(i.kind!==`Ix`)throw new e.M;return i}if(l.kind===`Fresh`){let t=`The expression that results from applying the declared operator \`${l.name}\` has expression level ${c} within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${a}. A declared operator cannot be expanded.\n${u(l.name)}\n and has level: ${dr[l.level]}\n and arity: ${l.shape}`;throw n(D(i.location,t)),new e.w(t)}let d=l.definition;if(d.kind!==`Operator`&&d.kind!==`Bpragma`)throw new e.M;if(!t.isAutoUse){let r=t.isEnabled&&t.isCdot?["the operators `ENABLED` and `\\cdot`","the proof directives `ExpandENABLED` and `ExpandCdot`"]:t.isEnabled?["the operator `ENABLED`","`ExpandENABLED` proof directive"]:["the operator `\\cdot`","`ExpandCdot` proof directive"],a=d.body.kind===`Lambda`?d.body.body:d.body,o=`Hidden definition of operator \`${d.name}\` needs expansion for soundly expanding ${r[0]} (using rigid quantification).\nThe expansion of ${r[0]} has been activated with the ${r[1]} from the module \`TLAPS\`.\nThe operator \`${d.name}\` is defined at: \n\t${Qe(a.location)}\nand the operator \`${d.name}\` occurs at: \n\t${Qe(i.location)}\nUsing the proof directive \`AutoUSE\` from the module \`TLAPS\`, or \`BY DEF ${d.name}\` is expected to avoid this error.\n`;throw n(D(i.location,o)),new e.T(o)}n({text:`${$e(i.location)}[INFO]: Auto-expanding the definition of operator: ${d.name}\n`,channel:`stdout`});let f=I(P(s.index),d.body);return o(mt(i.kind===`Apply`?Et(f,i.args):f))},Nr=t=>{if(t.kind===`Apply`&&t.args.length===1)return on(t.args[0]);if(t.kind!==`Sub`)throw new e.M;let n=on(t.subscript),r=t.modal===`Box`?n:k(`Neg`,[n],t);return k(t.modal===`Box`?`Disj`:`Conj`,[t.action,r],t)},Pr=e=>{let t=(e,t)=>e<<t|e>>>32-t,n=(e,n)=>{let r=Math.imul(t(Math.imul(n,3432918353),15),461845907);return Math.imul(t(e^r,13),5)+3864292196|0},r=new TextEncoder().encode(e),i=r.length-r.length%4,a=0;for(let e=0;e<i;e+=4)a=n(a,r[e]|r[e+1]<<8|r[e+2]<<16|r[e+3]<<24);let o=r.subarray(i).reduceRight((e,t)=>e<<8|t,0);return r.length>i&&(a=n(a,o)),a^=r.length,a=Math.imul(a^a>>>16,2246822507),a=Math.imul(a^a>>>13,3266489909),(a^a>>>16)&1073741823},Fr=e=>{let t=Array.from({length:16},()=>[]);return e.forEach((e,n)=>{if(t[Pr(e)&t.length-1].unshift(e),n+1<=t.length*2)return;let r=Array.from({length:t.length*2},()=>[]);t.flat().forEach(e=>r[Pr(e)&r.length-1].push(e)),t=r}),t.flat()},Ir=(t,n,r,i,a,o)=>{let s=e=>Ir(t,n,r,i,a,e),c=r!==void 0||i!==void 0,l=(e,s)=>{let c={names:[],depth:Math.max(r?.depth??0,i?.depth??0)+1},[l,u]=s,d=[Ir(t,n,r,c,a,l),...u?[Ir(t,n,c,i,a,u)]:[]],f=c.names.length===0?[`r#0`]:Fr(c.names);return O({kind:`Apply`,operator:e,args:[{kind:`Lambda`,params:[`_`,...f].map(e=>({name:e,shape:0})),body:d.length===1?d[0]:{kind:`List`,bullet:`And`,items:d}}]},o)};if(kr(o))return o;if(o.kind===`Apply`&&o.operator.kind===`Internal`){let r=o.operator.builtin;if(t.isEnabled&&r===`ENABLED`&&o.args.length===1||t.isCdot&&r===`Cdot`&&o.args.length===2)return l(o.operator,o.args);if(r===`ENABLED`&&c)throw n(D(o.location,Sr)),new e.T(`Expr.Action`);if(r===`Cdot`&&c)throw n(D(o.location,wr)),new e.T(`Expr.Action`);if(r===`Prime`&&o.args.length===1){let e=Ir(t,n,i,void 0,a,o.args[0]);return i?e:{...o,args:[e]}}if(r===`UNCHANGED`&&c)return s(Nr(o))}if(o.kind===`Sub`&&c)return s(Nr(o));if(o.kind===`Ix`){if(!r)return o;let t=Er(a,o.index);if(t.kind===`Fact`)throw new e.M;if(t.kind!==`Flex`)return o;let n=`${t.name}#enabled#prime${r.depth}`;return r.names.includes(n)||r.names.push(n),O({kind:`Opaque`,name:n},o)}if(o.kind===`Apply`&&o.operator.kind===`Opaque`)throw n(D(o.location,`Named operator \`${o.operator.name}\` unexpected after anonymization.`)),new e.M(`File "src/expr/e_action.ml", line 1048, characters 12-18: Assertion failed`);return N(a,o,(e,a)=>Ir(t,n,r,i,e,a),A)},Lr=(t,n)=>{if(n.kind===`Apply`&&Dr(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`)throw new e.M;let[i,...a]=r.params;if(i.name!==`_`)return n;let o=Lr({kind:`Compose`,outer:t,inner:P(a.length)},r.body);return{kind:`Apply`,operator:n.operator,args:[{kind:`Lambda`,params:a,body:o}]}}return n.kind===`Ix`?I(t,n):n.kind===`Apply`?O(Et(Lr(t,n.operator),n.args.map(e=>Lr(t,e))),n):N(t,n,Lr,e=>F(1,e))},Rr=(t,n)=>{if(n.kind===`Apply`&&Dr(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`||r.params[0].name===`_`)throw new e.M;let i=n.operator.builtin===`Cdot`?xr:br;return{kind:`Apply`,operator:O({kind:`Opaque`,name:i},n.operator),args:[{kind:`Lambda`,params:r.params.map((e,n)=>({name:t?e.name:`r#${n}`,shape:0})),body:Rr(t,r.body)}]}}return Tr(n,e=>Rr(t,e))},zr=t=>{if(nt(t,`Cdot`)&&t.args.length===1&&t.args[0].kind!==`Lambda`)throw new e.M;return Tr(t,zr)},Br=(e,t,n,r,i,a)=>{let o=Ir(i,t,void 0,void 0,n,r);return Rr(a,e.expr(n,Lr(P(0),o)))},Vr={isEnabled:!0,isCdot:!0,isAutoUse:!0},Hr=(e,t,n,r,i=Vr)=>{let a=Mr(i,t,n,r,void 0);return zr(Br(e,t,n,a,i,!1))},Ur=(t,n,r,i,a)=>{let o=(e,i)=>({kind:`Quant`,quantifier:`Exists`,bounds:e.map(e=>({name:e.name,level:`Constant`,domain:{kind:`NoDomain`}})),body:Ur(t,n,j(r,e.map(ft)),i,!0)}),s=e=>e===`ENABLED`?t.isEnabled:t.isCdot;if(i.kind===`Apply`&&i.args.length===1){let e=i.operator,[a]=i.args;if(a.kind===`Lambda`){if(e.kind===`Opaque`&&(t.isEnabled&&e.name===br||t.isCdot&&e.name===xr))return o(a.params,a.body);if(e.kind===`Ix`&&(t.isEnabled||t.isCdot)){let t=Er(r,e.index);if(t.kind===`Defn`&&t.definition.kind===`Operator`&&(t.definition.name===br||t.definition.name===xr))return o(a.params,a.body)}if(Dr(e)&&s(e.builtin))return o(a.params,a.body)}if(Dr(e)&&s(e.builtin))return Ur(t,n,r,a,!0)}if(nt(i,`ENABLED`)&&a)throw n(D(i.location,Sr)),new e.T(`Expr.Action`);if(nt(i,`Cdot`)&&a)throw n(D(i.location,wr)),new e.T(`Expr.Action`);return N(r,i,(e,r)=>Ur(t,n,e,r,a),A)},Wr=t=>{if(t.kind===`Quant`&&t.quantifier===`Exists`){let n=t.body;if(n.kind===`List`&&n.bullet===`Or`)return Wr({...n,items:n.items.map(e=>({...t,body:e}))});if(nt(n,`Disj`)){if(n.args.length!==2)throw new e.M;return Wr({...n,args:n.args.map(e=>({...t,body:e}))})}}return Tr(t,Wr)},Gr=(e,t,n,r,i)=>{let a=Mr(i,t,n,r,void 0),o=Br(e,t,n,a,i,!0);return Wr(Ur(i,t,n,o,!1))},Kr=(t,n,r,i)=>{try{let r=Hr(t.anonymizer,t.onWarning,n,{kind:`Sequent`,sequent:i});if(r.kind!==`Sequent`)throw new e.M;return r.sequent}catch(n){if(!(n instanceof e.w)||n.failure===void 0)throw n;let a=i.active.location,o=`${n.failure}\nCould not instantiate the theorem ${r===void 0?``:`named: ${r}, `}at: ${Qe(a)}`;return t.onWarning({text:`${$e(a)}[ERROR]${o}`,channel:`stdout`}),t.onWarning({text:o,channel:`toolboxOnly`}),{context:[],active:O({kind:`Internal`,builtin:`TRUE`},i.active)}}},qr=(e,t,n)=>{if(n.kind===`Theorem`)return{...n,sequent:Kr(e,t,n.name,n.sequent)};if(n.kind!==`Definition`)return n;let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)return n;let i=Hr(e.anonymizer,e.onWarning,t,r.body);return{...n,definition:{...r,body:i}}},Jr=(e,t,n)=>st(t,n,(t,n)=>{if(n.kind===`Submod`){let[r,i]=Jr(e,t,n.module.body);return[r,{...n,module:{...n.module,body:i}}]}let r=qr(e,t,n);return[j(t,Pn(r)),r]}),Yr=(t,n)=>{let r=[],i=0,a=t;for(;a.length>0;){let[t,...o]=a,s=t.kind===`Constants`?{name:t.declarations[0].name,remaining:{...t,declarations:t.declarations.slice(1)}}:t.kind===`Variables`?{name:t.names[0],remaining:{...t,names:t.names.slice(1)}}:void 0;if(s){let t=n.get(s.name);if(!t)throw new e.w(`Parameter ${s.name} has no substitute`);let r=Fn(s.remaining)===0;a=Wn(St(L(i,t),P(0)),r?o:[s.remaining,...o])}else r.push(t),i+=Fn(t),a=o}return r},Xr=(e,t,n)=>{let r=Array.from({length:t},(e,r)=>O({kind:`Ix`,index:t-r},{location:n})),i=Array.from({length:t},(e,t)=>O({kind:`Ix`,index:t+1},{location:n})),a=Array.from({length:e},(e,i)=>{let a=O({kind:`Ix`,index:i+t+1},{location:n});return t>0?O({kind:`Apply`,operator:a,args:r},{location:n}):a});return Ct([...a,...i].reverse(),P(e+t))},Zr=(e,t)=>{let n=t.map(e=>({name:e,shape:0}));return e.kind===`Lambda`?{...e,params:[...n,...e.params]}:t.length===0?e:O({kind:`Lambda`,params:n,body:e},e)},Qr=(t,n,r,i,a,o)=>{let s=e=>r===``?e:`${r}!${e}`,c=i.args.length,l=[],u=0,d=n,f=c===0,p=e=>{f||(f=!0,t.onWarning({text:e,channel:`stderr`}))};for(;d.length>0;){let[n,...r]=d;d=r;let f=e=>Zr(I(Xr(u,c,o),e),i.args);switch(n.kind){case`Definition`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e.w(`Module.Elab.localize`);let i=n.isLocal?`${r.name}$${xn(t.salts)}`:r.name;l.push({...n,definition:{...r,name:s(i),body:f(r.body)},whereDefined:n.isLocal?`Builtin`:n.whereDefined,isLocal:n.isLocal||a}),u+=1;continue}case`Axiom`:{p(`${et(o)}Instancing produces parametric axioms.\nSuch axioms will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`);let e={...n,name:n.name===void 0?void 0:s(n.name),expression:f(n.expression)};l.push(e),u+=Fn(e);continue}case`Theorem`:{p(`${$e(o)}Warning: Instancing produces parametric theorems.\nSuch theorems will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`);let e=f(O(rt(n.sequent),n));l.push({...n,name:n.name===void 0?void 0:s(n.name),sequent:e.kind===`Sequent`?e.sequent:{context:[],active:e},proof:{kind:`Omitted`,omission:`Elsewhere`,location:n.location}}),u+=1;continue}case`Mutate`:n.mode===`Use`&&(d=Wn(P(-n.usable.facts.length),d));continue;case`Submod`:continue;default:throw new e.w(`Module.Elab.localize`)}}return l},$r=e=>{let t=[],n=e;for(;n.length>0;){let[e,...r]=n;if(e.kind!==`Axiom`){t.push(e),n=r;continue}let i=e.location;e.name!==void 0&&t.push({kind:`Definition`,definition:{kind:`Operator`,name:e.name,body:e.expression,location:i},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:i});let a=ut(e.name===void 0?L(1,e.expression):O({kind:`Ix`,index:2},e),`Visible`,`Always`,i),o=0,s=r.map(e=>{let t=o;if(o+=Fn(e),e.kind!==`Theorem`)return e;let n=At(P(1),e.sequent);return{...e,sequent:{...n,context:[kt(P(t),a),...n.context]},axiomCount:e.axiomCount+1}});n=Wn(P(-1),s)}return t},ei=e=>new Set(e.body.flatMap(e=>e.kind===`Constants`?e.declarations.map(e=>e.name):e.kind===`Variables`?e.names:[])),ti=(t,n,r,i,a,o,s)=>{let c=n.get(i.module);if(!c)throw new e.w(`Module "${i.module}" unknown`);let l=ei(c);for(let t of i.substitutions)if(!l.has(t.name))throw new e.w(`Parameter ${t.name} occurs in the statement \`INSTANCE ${i.module} WITH\`, and is not declared in the module ${i.module}`);let u=j(r,i.args.map(e=>lt(e,`Unknown`))),d=new Map(i.substitutions.map(e=>[e.name,e.expression]));for(let t of[...l].sort(Vn))if(!d.has(t)){if(!at(u,t))throw new e.w(`Required parameter ${t} for module ${i.module} could not be inferred.`);d.set(t,O({kind:`Opaque`,name:t},{location:s}))}let f=new Map([...d].map(([e,n])=>[e,t.anonymizer.expr(u,n)])),p=Wn(P((u?.size??0)-(c.depth??0)),c.body.map(e=>e.kind===`Theorem`?{...e,proof:{kind:`Omitted`,omission:`Implicit`,location:e.proof.location}}:e)),[,m]=Jr(t,u,p);return $r(Qr(t,Yr(m,f),o,i,a,s))},ni=(t,n,r)=>{let i=r.instance.module;if(!t.latestModules.has(i))throw t.onWarning({text:`${et(r.instance.location)}Module ${JSON.stringify(i)} unknown\n`,channel:`toolbox`}),new e.w(`Module ${JSON.stringify(i)} unknown`,{failure:`Module.Elab.anon#defns`});let a=ti(t,t.latestModules,n,r.instance,!0,r.name,r.location),o=[],s=a;for(;s.length>0;){let[e,...t]=s;e.kind===`Definition`?(o.push(e.definition),s=t):s=Wn(P(-Fn(e)),t)}return o},ri=(e,t,n,r)=>{let i=[],a=n,o=e=>{i.push(e),a=j(a,Pn(e))},s=e=>e!==void 0&&at(a,e)!==void 0,c=r.body.map(e=>({unit:e,isAnonymized:!1}));for(let n=0;n<c.length;n++){let i=c[n].unit,l=(r,o,s)=>{let l=ti(e,t,a,r,o,s,i.location);c.splice(n+1,0,...l.map(e=>({unit:e,isAnonymized:!0})))};switch(i.kind){case`Anoninst`:l(i.instance,i.isLocal,``);continue;case`Definition`:{let t=i.definition;if(t.kind===`Instance`){l(t.instance,i.isLocal,t.name);continue}let r=t.kind===`Recursive`||c[n].isAnonymized?t:e.anonymizer.defn(a,t),s={...i,definition:r};if(t.kind===`Recursive`){o(s);continue}let u=Pn(s)[0],d=at(a,t.name);if(d?.hyp.kind===`Defn`&&(d.hyp.definition.kind===`Recursive`||Lt(kt(P(d.depth+1),d.hyp),u))){let e=c.slice(n+1),t=Wn(St(O({kind:`Ix`,index:d.depth+1},i),P(0)),e.map(e=>e.unit));c.splice(n+1,e.length,...e.map((e,n)=>({...e,unit:t[n]})));continue}o(s);continue}case`Recursives`:case`Constants`:case`Variables`:o(i);continue;case`Axiom`:if(s(i.name))continue;e.latestModules=new Map(t),o({...i,expression:e.anonymizer.expr(a,i.expression)});continue;case`Theorem`:{let n=s(i.name),c=n?`(redundant)${i.name}`:i.name,l=n?{kind:`Obvious`,location:i.proof.location}:i.proof;e.latestModules=new Map(t);let u=e.anonymizer.sequent(a,i.sequent),d=Gn(c,u,i.location),f=j(j(a,d.hyps.map(e=>({...e,isConstnessUnset:!0}))),d.sequent.context),p=e.anonymizer.proof(f,l),m=r.isImportant?e.simplify(it(f),d.sequent.active,p,yn(d.sequent.context,`Always`)):p;o({...i,name:c,sequent:u,proof:m});continue}case`Mutate`:e.latestModules=new Map(t),o({...i,usable:e.anonymizer.usable(a,i.usable)});continue;case`Submod`:o({...i,module:ri(e,t,a,i.module)});continue}}let l={...r,body:i,depth:n?.size??0};return t.set(r.name,l),l},ii=1000000010,ai=new TextEncoder,oi=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return ai.encode(e).length;return e.length},si=()=>({leftTotal:-1,element:{size:-1,token:{kind:`Text`,text:``},length:0}}),ci=e=>{let t={size:-1,token:{kind:`Begin`,indent:0,box:`hov`},length:0};return{queue:[t],queueStart:0,scanStack:[si(),{leftTotal:1,element:t}],formatStack:[],margin:78,maxIndent:e,spaceLeft:78,currentIndent:0,isNewLine:!0,leftTotal:1,rightTotal:1,depth:1,output:[]}},li=(e,t)=>{e.rightTotal+=t.length,e.queue.push(t)},ui=(e,t,n)=>{e.output.push(`
24
- `),e.isNewLine=!0,e.currentIndent=Math.min(e.maxIndent,e.margin-n+t),e.spaceLeft=e.margin-e.currentIndent,e.output.push(` `.repeat(e.currentIndent))},di=(e,t)=>{e.spaceLeft-=t,e.output.push(` `.repeat(t))},fi=e=>{let t=e.formatStack.at(-1);t?t.width>e.spaceLeft&&t.box!==`fits`&&t.box!==`h`&&ui(e,0,t.width):e.output.push(`
25
- `)},pi=(e,t,n)=>{switch(n.kind){case`Text`:e.spaceLeft-=t,e.output.push(n.text),e.isNewLine=!1;return;case`Begin`:{e.margin-e.spaceLeft>e.maxIndent&&fi(e);let r=e.spaceLeft-n.indent,i=n.box===`v`||t>e.spaceLeft?n.box:`fits`;e.formatStack.push({box:i,width:r});return}case`End`:e.formatStack.pop();return;case`Newline`:{let t=e.formatStack.at(-1);t?ui(e,0,t.width):e.output.push(`
26
- `);return}case`Break`:{let r=e.formatStack.at(-1);if(!r)return;let i=r.width;switch(r.box){case`hov`:t>e.spaceLeft?ui(e,n.offset,i):di(e,n.width);return;case`b`:e.isNewLine?di(e,n.width):t>e.spaceLeft||e.currentIndent>e.margin-i+n.offset?ui(e,n.offset,i):di(e,n.width);return;case`hv`:case`v`:ui(e,n.offset,i);return;case`fits`:case`h`:di(e,n.width);return}}}},mi=e=>{for(;e.queueStart<e.queue.length;){let t=e.queue[e.queueStart],n=t.size>=0;if(!n&&e.rightTotal-e.leftTotal<e.spaceLeft)return;e.queueStart++,pi(e,n?t.size:ii,t.token),e.leftTotal+=t.length}e.queue.length=0,e.queueStart=0},hi=(e,t)=>{li(e,t),mi(e)},gi=(e,t)=>{let n=e.scanStack.at(-1);n&&(n.leftTotal<e.leftTotal?e.scanStack=[si()]:n.element.token.kind===(t?`Break`:`Begin`)&&(n.element.size=e.rightTotal+n.element.size,e.scanStack.pop()))},_i=(e,t,n)=>{li(e,n),t&&gi(e,!0),e.scanStack.push({leftTotal:e.rightTotal,element:n})},vi=(e,t,n)=>{e.depth++,_i(e,!1,{size:-e.rightTotal,token:{kind:`Begin`,indent:n,box:t},length:0})},yi=e=>{e.depth<=1||(li(e,{size:0,token:{kind:`End`},length:0}),gi(e,!0),gi(e,!1),e.depth--)},bi=(e,t,n)=>hi(e,{size:t,token:{kind:`Text`,text:n},length:t}),xi=(e,t,n)=>_i(e,!0,{size:-e.rightTotal,token:{kind:`Break`,width:t,offset:n},length:t}),Si=e=>hi(e,{size:0,token:{kind:`Newline`},length:0}),Ci=e=>{for(;e.depth>1;)yi(e);return e.rightTotal=ii,mi(e),e.output.join(``)},wi=e=>{Ci(e);let t=[...e.output,`
27
- `];Object.assign(e,ci(e.maxIndent)),e.output=t},Ti={h:`h`,v:`v`,hv:`hv`,hov:`hov`,b:`b`},Ei=e=>({kind:`Text`,text:e,size:oi(e)}),B=e=>e===``?[]:[Ei(e)],Di={kind:`Break`,width:1,offset:0},Oi={kind:`Break`,width:0,offset:0},ki=e=>{let t=e.search(/\d|$/);return{kind:`Open`,box:Ti[e.slice(0,t)],indent:Number(e.slice(t)||0)}},V=(e,...t)=>{let n=[],r=0,i=``,a=()=>{i!==``&&(n.push(Ei(i)),i=``)};for(let o=0;o<e.length;o++){let s=e[o];if(s===`%`){a();let e=t[r++];typeof e==`string`?e!==``&&n.push(Ei(e)):n.push(e),o++}else if(s!==`@`)i+=s;else switch(a(),e[o+1]){case`[`:{if(e[o+2]!==`<`){n.push({kind:`Open`,box:`b`,indent:0}),o++;break}let t=e.indexOf(`>`,o);n.push(ki(e.slice(o+3,t))),o=t;break}case`]`:n.push({kind:`Close`}),o++;break;case` `:n.push(Di),o++;break;case`,`:n.push(Oi),o++;break;case`
28
- `:n.push({kind:`Newline`}),o++;break;case`.`:n.push({kind:`Flush`}),o++;break;case`;`:{let t=e.indexOf(`>`,o),r=e.slice(o+3,t).split(` `);n.push({kind:`Break`,width:Number(r[0]),offset:Number(r[1])}),o=t;break}case`<`:{let i=e.indexOf(`>`,o);n.push({kind:`Text`,text:String(t[r++]),size:Number(e.slice(o+2,i))}),o=i+2;break}}}return a(),n},H=(e,t,n=[Ei(`,`),Di])=>e.flatMap((e,r)=>r===0?[t(e)]:[n,t(e)]),Ai=(e,t)=>{for(let n of t)if(Array.isArray(n))Ai(e,n);else switch(n.kind){case`Open`:vi(e,n.box,n.indent);break;case`Close`:yi(e);break;case`Text`:bi(e,n.size,n.text);break;case`Break`:xi(e,n.width,n.offset);break;case`Newline`:Si(e);break;case`Flush`:wi(e)}},ji=(e,t=68)=>{let n=ci(t);return Ai(n,e),Ci(n)},Mi=[[`=>`,1,1,`InfixNon`,[]],[`<=>`,2,2,`InfixNon`,[`\\equiv`]],[`/\\`,3,3,`InfixLeft`,[`\\land`]],[`\\/`,3,3,`InfixLeft`,[`\\lor`]],[`~`,4,4,`Prefix`,[`\\neg`,`\\lnot`]],[`=`,5,5,`InfixNon`,[]],[`#`,5,5,`InfixNon`,[`/=`]],[`SUBSET`,8,8,`Prefix`,[]],[`UNION`,8,8,`Prefix`,[]],[`DOMAIN`,9,9,`Prefix`,[]],[`\\subseteq`,5,5,`InfixNon`,[]],[`\\in`,5,5,`InfixNon`,[]],[`\\notin`,5,5,`InfixNon`,[]],[`\\`,8,8,`InfixNon`,[]],[`\\cap`,8,8,`InfixLeft`,[`\\intersect`]],[`\\cup`,8,8,`InfixLeft`,[`\\union`]],[`\\X`,10,13,`Prefix`,[`\\times`]],[`'`,15,15,`Postfix`,[]],[`~>`,2,2,`InfixNon`,[`\\leadsto`]],[`ENABLED`,4,15,`Prefix`,[]],[`UNCHANGED`,4,15,`Prefix`,[]],[`\\cdot`,5,14,`InfixLeft`,[]],[`-+->`,2,2,`InfixNon`,[]],[`[]`,4,15,`Prefix`,[]],[`<>`,4,15,`Prefix`,[]],[`^`,14,14,`InfixNon`,[]],[`/`,13,13,`InfixNon`,[]],[`*`,13,13,`InfixLeft`,[]],[`-.`,12,12,`Prefix`,[`-`]],[`-`,11,11,`InfixLeft`,[]],[`+`,10,10,`InfixLeft`,[]],[`^+`,15,15,`Postfix`,[]],[`^*`,15,15,`Postfix`,[]],[`^#`,15,15,`Postfix`,[]],[`<`,5,5,`InfixNon`,[]],[`=<`,5,5,`InfixNon`,[`<=`,`\\leq`]],[`>`,5,5,`InfixNon`,[]],[`>=`,5,5,`InfixNon`,[`\\geq`]],[`...`,9,9,`InfixNon`,[]],[`..`,9,9,`InfixNon`,[]],[`|`,10,11,`InfixLeft`,[]],[`||`,10,11,`InfixLeft`,[]],[`&&`,13,13,`InfixLeft`,[]],[`&`,13,13,`InfixLeft`,[]],[`$$`,9,13,`InfixLeft`,[]],[`$`,9,13,`InfixLeft`,[]],[`??`,9,13,`InfixLeft`,[]],[`%%`,10,11,`InfixLeft`,[]],[`%`,10,11,`InfixLeft`,[`\\mod`]],[`##`,9,13,`InfixLeft`,[]],[`++`,10,10,`InfixLeft`,[]],[`--`,11,11,`InfixLeft`,[]],[`**`,13,13,`InfixLeft`,[]],[`//`,13,13,`InfixNon`,[]],[`^^`,14,14,`InfixNon`,[]],[`@@`,6,6,`InfixLeft`,[]],[`!!`,9,13,`InfixNon`,[]],[`|-`,5,5,`InfixNon`,[]],[`|=`,5,5,`InfixNon`,[]],[`-|`,5,5,`InfixNon`,[]],[`=|`,5,5,`InfixNon`,[]],[`<:`,7,7,`InfixNon`,[]],[`:>`,7,7,`InfixNon`,[]],[`:=`,5,5,`InfixNon`,[]],[`::=`,5,5,`InfixNon`,[]],[`(+)`,10,10,`InfixLeft`,[`\\oplus`]],[`(-)`,11,11,`InfixLeft`,[`\\ominus`]],[`(.)`,13,13,`InfixLeft`,[`\\odot`]],[`(/)`,13,13,`InfixNon`,[`\\oslash`]],[`(\\X)`,13,13,`InfixLeft`,[`\\otimes`]],[`\\uplus`,9,13,`InfixLeft`,[]],[`\\sqcap`,9,13,`InfixLeft`,[]],[`\\sqcup`,9,13,`InfixLeft`,[]],[`\\div`,13,13,`InfixNon`,[]],[`\\wr`,9,14,`InfixNon`,[]],[`\\star`,13,13,`InfixLeft`,[]],[`\\o`,13,13,`InfixLeft`,[`\\circ`]],[`\\bigcirc`,13,13,`InfixLeft`,[]],[`\\bullet`,13,13,`InfixLeft`,[]],[`\\prec`,5,5,`InfixNon`,[]],[`\\succ`,5,5,`InfixNon`,[]],[`\\preceq`,5,5,`InfixNon`,[]],[`\\succeq`,5,5,`InfixNon`,[]],[`\\sim`,5,5,`InfixNon`,[]],[`\\simeq`,5,5,`InfixNon`,[]],[`\\ll`,5,5,`InfixNon`,[]],[`\\gg`,5,5,`InfixNon`,[]],[`\\asymp`,5,5,`InfixNon`,[]],[`\\subset`,5,5,`InfixNon`,[]],[`\\supset`,5,5,`InfixNon`,[]],[`\\supseteq`,5,5,`InfixNon`,[]],[`\\approx`,5,5,`InfixNon`,[]],[`\\cong`,5,5,`InfixNon`,[]],[`\\sqsubset`,5,5,`InfixNon`,[]],[`\\sqsubseteq`,5,5,`InfixNon`,[]],[`\\sqsupset`,5,5,`InfixNon`,[]],[`\\sqsupseteq`,5,5,`InfixNon`,[]],[`\\doteq`,5,5,`InfixNon`,[]],[`\\propto`,5,5,`InfixNon`,[]]],Ni=/* @__PURE__ */ new Map;for(let[e,t,n,r,i]of Mi){let a={name:e,low:t,high:n,fixity:r};for(let t of[e,...i])Ni.set(t,a)}const Pi=e=>({name:e,low:-1,high:-1,fixity:`Nonfix`}),Fi=e=>Ni.get(e)??Pi(e),Ii={Implies:`=>`,Equiv:`<=>`,Conj:`/\\`,Disj:`\\/`,Neg:`~`,Eq:`=`,Neq:`#`,SUBSET:`SUBSET`,UNION:`UNION`,DOMAIN:`DOMAIN`,Subseteq:`\\subseteq`,Mem:`\\in`,Notmem:`\\notin`,Setminus:`\\`,Cap:`\\cap`,Cup:`\\cup`,Prime:`'`,StrongPrime:`'`,Leadsto:`~>`,ENABLED:`ENABLED`,UNCHANGED:`UNCHANGED`,Cdot:`\\cdot`,Actplus:`-+->`,BoxTrue:`[]`,BoxFalse:`[]`,Diamond:`<>`,Plus:`+`,Minus:`-`,Times:`*`,Ratio:`/`,Quotient:`\\div`,Remainder:`%`,Exp:`^`,Lteq:`=<`,Lt:`<`,Gteq:`>=`,Gt:`>`,Range:`..`,Cat:`\\o`,OneArg:`:>`,Extend:`@@`},Li=e=>{if(e===`Divides`)return{name:`?|`,low:10,high:11,fixity:`InfixNon`};if(e===`Uminus`)return{...Fi(`-.`),name:`-`};let t=Ii[e];return t?Fi(t):Pi(e)},Ri=e=>e.salt===0?e.rep:`${e.rep}_${e.salt}`,zi=()=>({stack:[],idents:/* @__PURE__ */ new Map,defined:/* @__PURE__ */ new Map}),Bi=(e,t)=>{let n=e.stack[e.stack.length-t];return n&&Ri(n)},Vi=(e,t)=>{let n=e.idents.get(t)?.at(-1),r=n?{rep:t,salt:n.salt+1}:{rep:t,salt:0};for(;e.defined.has(Ri(r));)r={rep:t,salt:r.salt+1};e.stack.push(r);let i=e.idents.get(t);i?i.push(r):e.idents.set(t,[r]);let a=Ri(r);return e.defined.set(a,(e.defined.get(a)??0)+1),a},Hi=(e,t)=>{for(let n=0;n<t;n++){let t=e.stack.pop();if(!t)return;e.idents.get(t.rep)?.pop();let n=Ri(t),r=(e.defined.get(n)??1)-1;r===0?e.defined.delete(n):e.defined.set(n,r)}},Ui=(e,t,n)=>{let r=n(t.map(t=>Vi(e,t)));return Hi(e,t.length),r},Wi=(e,t)=>t.kind===`Atm`||t.kind===`Op`&&e<t.low,Gi=e=>[V(`(`),e,V(`)`)],Ki=(e,t)=>t?qi(e):Gi(qi(e)),qi=e=>{if(e.kind!==`Op`)return e.doc;let t=e.skeleton,n=t=>Wi(e.high,t);switch(t.kind){case`Prefix`:case`Postfix`:{let r=t.operand,i=Ki(r,n(r)||r.kind===`Op`&&r.skeleton.kind===t.kind),a=t.kind===`Prefix`?[e.doc,i]:[i,e.doc];return[V(`@[<h>`),...a,V(`@]`)]}case`Infix`:{let r=t.left,i=t.right,a=n(r)||r.kind===`Op`&&r.name===e.name&&t.assoc===`Left`,o=n(i)||t.assoc===`Right`&&i.kind===`Op`&&i.skeleton.kind===`Infix`&&i.skeleton.assoc===`Right`;return[V(`@[<b0>`),Ki(r,a),e.doc,Ki(i,o),V(`@]`)]}}},U=e=>({kind:`Atm`,doc:e}),Ji=e=>({kind:`Big`,doc:e}),Yi=e=>e.kind===`Lambda`?Yi(e.body):e.kind===`Sequent`?Yi(e.sequent.active):e.kind===`With`,Xi=e=>{if(e.kind===`Defn`){let t=e.definition,n=t.kind===`Operator`&&Yi(t.body);return e.visibility===`Hidden`||n||e.whereDefined!==`User`}return e.kind===`Fact`?e.visibility===`Hidden`||Yi(e.expression):!1},Zi=e=>e===0?[]:V(`@[<hov1>(%a)@]`,H(Array.from({length:e},()=>`_`),B)),Qi=e=>V(`%s%a`,e.name,Zi(e.shape)),$i={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`UNKNOWN`},ea=(t=[])=>{let n=zi(),r=e=>qi(u(e)),i=(e,t)=>Ui(n,e.map(e=>e.name),()=>V(`@[<b2>LAMBDA @[<hv0>%a@] :@ %a@]`,H(e,Qi),r(t))),a=(e,t)=>{let i=e.map(e=>e.domain.kind===`Domain`?r(e.domain.expression):void 0);return Ui(n,e.map(e=>e.name),n=>{let r=[];return e.forEach((e,t)=>{t>0&&e.domain.kind===`Ditto`?r.at(-1)?.names.push(n[t]):r.push({names:[n[t]],index:t})}),t(H(r,t=>{let n=H(t.names,B),r=e[t.index].domain;return r.kind===`NoDomain`?n:r.kind===`Ditto`?V(`@[<hov0>%a@ \\in ??????@]`,n):V(`@[<hov0>%a@ \\in %a@]`,n,i[t.index]??[])}))})},o=e=>{switch(e.kind){case`Down`:return V(`:`);case`Left`:return V(`<<`);case`Right`:return V(`>>`);case`At`:return B(`@`);case`Number`:return B(String(e.value));case`Instance`:return V(`@[<b1>(%a)@]`,H(e.args,r));case`Label`:return e.args.length===0?B(e.label):V(`@[<b2>%s@,@[<b1>(%a)@]@]`,e.label,H(e.args,r))}},s=e=>e.length===0?[]:[V(`!`),H(e,o,V(`!`))],c=e=>{if(e<0)return`#$$${Math.abs(e)}`;if(e===0)return`#$0`;if(e<=n.stack.length)return Bi(n,e);let r=t[t.length-(e-n.stack.length)];return r?tt(r)??`??? FACT ???`:`#$${e}`},l=(t,n)=>{if(t.kind===`Lambda`)return{kind:`Op`,name:` `,doc:V(`@ `),low:20,high:20,skeleton:{kind:`Infix`,assoc:`Left`,left:Ji(i(t.params,t.body)),right:U(V(`(%a)`,H(n,r)))}};if(t.kind===`Bang`)return n.length===0?u(t):U(V(`@[<b2>%a@[<b1>(%a)@]@]`,r(t),H(n,r)));if(t.kind===`Internal`&&n.length===1){if(t.builtin===`BoxFalse`||t.builtin===`Unprimable`)return u(n[0]);if(t.builtin===`Irregular`)return U(V(`@[<h>@<1>%s%a@<1>%s@]`,`<[`,r(n[0]),`]>`))}let a=(()=>{switch(t.kind){case`Ix`:return Fi(c(t.index));case`Opaque`:{let e=Fi(t.name);return{...e,name:`?${e.name}`}}case`Internal`:return Li(t.builtin);default:throw new e.w(`Cannot print this operator`)}})(),o=(e,t)=>({kind:`Op`,name:a.name,doc:e,low:a.low,high:a.high,skeleton:t});if(n.length===0)return U(B(a.name));if(a.fixity===`Nonfix`)return U(V(`@[<b2>%s@[<b1>(%a)@]@]`,a.name,H(n,r)));if(a.fixity===`Prefix`&&n.length===1)return o(/[A-Za-z]$/.test(a.name)?V(`%s@ `,a.name):B(a.name),{kind:`Prefix`,operand:u(n[0])});if(a.fixity===`Postfix`&&n.length===1)return o(B(a.name),{kind:`Postfix`,operand:u(n[0])});if(a.fixity.startsWith(`Infix`)&&n.length===2){let e=a.fixity===`InfixLeft`?`Left`:a.fixity===`InfixRight`?`Right`:`Non`;return o(a.name===`..`?B(a.name):V(`@ %s `,a.name),{kind:`Infix`,assoc:e,left:u(n[0]),right:u(n[1])})}throw new e.w(`Arity mismatch for operator ${a.name}`)},u=t=>{switch(t.kind){case`Ix`:case`Opaque`:case`Internal`:return l(t,[]);case`Lambda`:return Ji(i(t.params,t.body));case`Bang`:return U([r(t.expression),s(t.selectors)]);case`Apply`:return l(t.operator,t.args);case`Sequent`:return Ji(p(t.sequent));case`With`:return u(t.expression);case`If`:return Ji(V(`@[<hv2>@[<b2>IF@ %a@]@ @[<b2>THEN %a@]@ @[<b2>ELSE %a@]@]`,r(t.condition),r(t.consequent),r(t.alternative)));case`List`:{if(t.bullet===`Refs`&&t.items.length===0)return U(V(`TRUE`));if(t.bullet===`Refs`&&t.items.length===1)return u(t.items[0]);let e=t.bullet===`Or`?`\\/`:`/\\`;return Ji(V(`@[<v0>%a@]`,H(t.items,t=>V(`@[<h>%s %a@]`,e,r(t)),V(`@,`))))}case`Let`:{let e=H(t.definitions,d,V(`@,`)),i=r(t.body);return Hi(n,t.definitions.length),Ji([V(`@[<hv0>LET @[<v0>`),e,V(`@]@
29
- IN %a@]`,i)])}case`Quant`:return a(t.bounds,e=>Ji(V(`@[<b3>%s @[<b0>%a@] :@ %a@]`,t.quantifier===`Forall`?`\\A`:`\\E`,e,r(t.body))));case`Tquant`:return Ui(n,t.names,e=>Ji(V(`@[<b4>%s @[<b0>%a@] : %a@]`,t.quantifier===`Forall`?`\\AA`:`\\EE`,H(e,B),r(t.body))));case`Choose`:{let e=t.domain&&r(t.domain);return Ui(n,[t.name],([n])=>Ji(e?V(`@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]`,n,e,r(t.body)):V(`@[<b2>CHOOSE %s :@ %a@]`,n,r(t.body))))}case`SetSt`:{let e=r(t.domain);return Ui(n,[t.name],([n])=>U(V(`@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]`,n,e,r(t.body))))}case`SetOf`:return a(t.bounds,e=>U(V(`@[<b3>{%a :@ %a}@]`,r(t.element),e)));case`SetEnum`:return U(V(`@[<h>{@[<b0>%a@]}@]`,H(t.elements,r)));case`Arrow`:return U(V(`@[<b3>[%a ->@ %a]@]`,r(t.domain),r(t.range)));case`Fcn`:return a(t.bounds,e=>U(V(`@[<b3>[%a |->@ %a]@]`,e,r(t.body))));case`FcnApp`:{let e=u(t.function),n=e.kind===`Atm`;return U(V(`@[<h>%s%a%s@[<b1>[%a]@]@]`,n?``:`(`,qi(e),n?``:`)`,H(t.args,r)))}case`Product`:if(t.factors.length===1)return u(t.factors[0]);if(t.factors.length===0)throw new e.w(`Expr.Fmt.fmt_expr: PRODUCT []`);return{kind:`Op`,name:`\\X`,doc:V(`@ \\X `),low:10,high:13,skeleton:{kind:`Infix`,assoc:`Right`,left:u(t.factors[0]),right:u({...t,factors:t.factors.slice(1)})}};case`Tuple`:return U(V(`@[<b2><<%a>>@]`,H(t.elements,r)));case`Rect`:case`Record`:{let e=t.kind===`Rect`?`:`:`|->`;return U(V(`@[<b1>[%a]@]`,H(t.fields,t=>V(`@[<h>%s ${e} %a@]`,t.name,r(t.value)))))}case`Except`:return U(V(`@[<b3>[%a EXCEPT@ @[<v0>%a@]]@]`,r(t.function),H(t.specs,e=>V(`!@[<h>%a = %a@]`,e.trail.map(e=>e.kind===`Dot`?V(`.%s`,e.field):V(`[%a]`,r(e.expression))),r(e.value)))));case`Dot`:return{kind:`Op`,name:`.`,doc:V(`.`),low:16,high:16,skeleton:{kind:`Infix`,assoc:`Left`,left:u(t.expression),right:U(B(t.field))}};case`Sub`:case`Tsub`:{let e=t.modal===`Box`,n=t.kind===`Sub`?e?`[`:`<<`:e?`[][`:`<><<`;return U(V(`@[<h>%s@[<b2>%a@]%s%a@]`,n,r(t.action),e?`]_`:`>>_`,r(t.subscript)))}case`Fair`:return Ji(V(`@[<h>%s_%a (%a)@]`,t.fairness===`Weak`?`WF`:`SF`,Gi(r(t.subscript)),r(t.action)));case`Case`:return Ji(V(`@[<v2>CASE %a%a@]`,H(t.arms,e=>V(`@[<b2>%a ->@ %a@]`,r(e.condition),r(e.body)),V(`@,[] `)),t.other?V(`@,[] @[<b2>OTHER ->@ %a@]`,r(t.other)):[]));case`String`:return U(V(`"%s"`,t.value));case`Num`:return U(B(t.fraction===``?t.integer:`${t.integer}.${t.fraction}`));case`At`:return U(B(`@`));case`Parens`:{let e=t.form;if(e.kind===`Syntax`)return u(t.expression);let r=e.kind===`Nlabel`?e.names:e.indices.map(e=>e.index>=1&&e.index<=n.stack.length?c(e.index):`¶${e.index}`),i=u(t.expression);if(r.length===0){let t=i.kind===`Op`?`%s::(%a)`:`%s::%a`;return U(V(t,e.label,qi(i)))}let a=H(r,B),o=i.kind===`Atm`?`%s(%a)::%a`:i.kind===`Big`?`%s(%a)::(%a)`:`(%s(%a):: %a)`;return U(V(o,e.label,a,qi(i)))}}},d=e=>{switch(e.kind){case`Operator`:case`Bpragma`:{let t=e.body;if(t.kind===`Lambda`){let i=Ui(n,t.params.map(e=>e.name),()=>r(t.body)),a=Vi(n,e.name);return V(`@[<b2>%s@[<b1>(%a)@] ==@ %a@]`,a,H(t.params,Qi),i)}let i=r(t);return V(`@[<b2>%s ==@ %a@]`,Vi(n,e.name),i)}case`Instance`:{let t=e.instance,i=Ui(n,t.args,e=>({doc:V(`@[<b2>INSTANCE %s%a@]`,t.module,t.substitutions.length===0?[]:V(`@ WITH@ %a`,H(t.substitutions,e=>V(`@[<b2>%s <- %a@]`,e.name,r(e.expression))))),args:e})),a=Vi(n,e.name),o=t.args.length===0?B(a):V(`%s (@[<b0>%a@])`,a,H(i.args,B));return V(`@[<b2>%a == %a@]`,o,i.doc)}case`Recursive`:{let t=Vi(n,e.name);return V(`@[<b2>NEW CONSTANT %s%a@]`,t,Zi(e.shape))}}},f=e=>{switch(e.kind){case`Fresh`:{let t=e.domain&&e.domainVisibility===`Visible`?r(e.domain):void 0,i=Vi(n,e.name);return[V(`NEW %s %s%a`,$i[e.level],i,Zi(e.shape)),t?V(` \\in %a`,t):[]]}case`Flex`:return V(`NEW VARIABLE %s`,Vi(n,e.name));case`Defn`:return d(e.definition);case`Fact`:{let t=V(`@[<h>%a @]`,r(e.expression));return Vi(n,``),t}}},p=e=>{if(e.context.length===0)return r(e.active);let t=[];for(let r of e.context)Xi(r)?Vi(n,tt(r)??``):t.push(f(r));let i=r(e.active);return Hi(n,e.context.length),t.length===0?i:[V(`@[<v0>ASSUME @[<v0>`),H(t,e=>e),V(`@]@
30
- PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},ta=(e,t)=>ea(e).printExpr(t),na=e=>ea().printSequent(e),ra=e=>ji(V(`@[<b0>%a@]`,na(e))).trimEnd(),ia=e=>({location:e.location,step:e.step,method:e.method}),aa=e=>e?.level??0,oa=(e,t)=>nt(e,t)&&e.args.length===2,sa=(e,...t)=>ji(V(e,...t)),ca=e=>la(e).map((e,t)=>{let n=e.domain.kind===`Domain`?L(t,e.domain.expression):void 0;return{kind:`Fresh`,name:e.name,shape:0,level:n?`Constant`:e.level,domain:n,domainVisibility:`Visible`}}),la=e=>{let t={kind:`NoDomain`};return e.map(e=>e.domain.kind===`Ditto`?{...e,domain:t}:(t=e.domain,e))},ua=(e,t)=>{let n=Dt(P(1),t)[1];return n[0].domain.kind===`Ditto`&&e.domain.kind===`Domain`?[{...n[0],domain:{kind:`Domain`,expression:L(1,e.domain.expression)}},...n.slice(1)]:n},da=(e,t)=>{if(t.length===0)return{kind:`Obvious`,...ia(e)};let n=t.map((t,n)=>{let r=L(2*n+2,t);return{kind:`Assert`,sequent:{context:[],active:r},proof:{kind:`By`,usable:{facts:[L(3,r)],defs:[]},isOnly:!1,location:t.location,method:e.method},location:t.location}}),r={kind:`By`,usable:{facts:[O({kind:`Ix`,index:2*t.length+2},e),...t.map((n,r)=>O({kind:`Ix`,index:2*(t.length-r)},e))],defs:[]},isOnly:!0,...ia(e),method:void 0};return{kind:`Steps`,steps:n,qed:{proof:r,location:r.location},...ia(e)}},fa=(e,t)=>e.kind===`At`&&!e.isExcept?O(mt(t),e):bt(e,e=>fa(e,t)),pa=t=>{let n=e=>({kind:`Named`,level:e,label:`_a${xn(t)}`,isAnonymous:!0}),r=(e,t)=>t?.kind===`Named`?{...t,level:e}:n(e),i=(e,t)=>{let n={...t,step:r(e,t.step)};if(n.kind!==`Steps`)return n;let o=n.steps.map(t=>a(e,t));return{...n,steps:o,qed:{...n.qed,proof:i(e+1,n.qed.proof)}}},a=(e,t)=>{let n={...t,step:r(e,t.step)};return`proof`in n?{...n,proof:i(e+1,n.proof)}:n},o=(t,n)=>{let r=n.kind===`Apply`?n.operator:n;if(r.kind===`Ix`){let i=t[t.length-r.index];if(!i)throw new e.w(`expose_connective`);if(i.kind!==`Defn`||i.definition.kind!==`Operator`)return n;let a=L(r.index,i.definition.body);if(n.kind!==`Apply`)return o(t,a);let s={...a,location:n.location};return o(t,O(Et(s,n.args),s))}if(nt(n,`Prime`)){let e=o(t,n.args[0]),r=e=>k(`Prime`,[e],e);return e.kind===`Quant`?O({kind:`Quant`,quantifier:e.quantifier,bounds:ht(e.bounds,r),body:r(e.body)},n):oa(e,`Implies`)||oa(e,`Mem`)?O({kind:`Apply`,operator:e.operator,args:[r(e.args[0]),r(e.args[1])]},n):r(e)}return n.kind===`Parens`?o(t,n.expression):n},s=e=>{if(e.kind!==`Assert`)return;let t=e.sequent.active;return t.kind===`Apply`&&t.args.length===2?t.args[1]:void 0},c=e=>{if(e.kind!==`Steps`)return e;let t=[];return e.steps.forEach(e=>{let n=t.at(-1),r=n&&s(n);if(e.kind!==`Assert`||!r){t.push(e);return}let i=fa(e.sequent.active,L(2,r));t.push({...e,sequent:{...e.sequent,active:i}})}),{...e,steps:t}},l=(e,t,r,i)=>{let a=c(r);switch(a.kind){case`Obvious`:case`Omitted`:case`Error`:return a;case`By`:{let e=a.usable,t=e.defs.length===0?[]:[{kind:`Use`,usable:{facts:[],defs:e.defs},isOnly:!1,location:a.location}],r=e.facts.map((e,t)=>({kind:`Use`,usable:{facts:[L(t,e)],defs:[]},isOnly:!1,location:e.location,useLocation:a.location})),i=a.isOnly?[{kind:`Forget`,count:e.facts.length,location:a.location}]:[],o=aa(a.step),s=[...t,...r,...i].map(e=>({...e,step:n(o)})),c={kind:`Obvious`,location:a.location,step:n(o),method:a.method};return{kind:`Steps`,steps:s,qed:{proof:c,location:c.location,step:c.step},location:a.location,step:a.step}}case`Steps`:{let[n,r]=st({context:e,goal:t,time:i},a.steps,(e,t)=>{let[n,r,i,a]=u(e.context,e.goal,t,e.time);return[{context:n,goal:r,time:a},i]}),o=l(n.context,n.goal,a.qed.proof,n.time);return{...a,steps:r.flat(),qed:{...a.qed,proof:o}}}}},u=(t,n,r,i)=>{let s=aa(r.step);switch(r.kind){case`Forget`:return[t,n,[r],i];case`Assert`:{let e=Zn(t,r.sequent,r,i),a={...r,proof:l(e.context,e.active,r.proof,e.time)},o=Qn(!1,t,n,r.sequent,a,i);return[o.context,o.active,[a],i]}case`Suffices`:{let e=Qn(!0,t,n,r.sequent,r,i),a={...r,proof:l(e.context,e.active,r.proof,i)},o=Zn(t,r.sequent,a,i);return[o.context,o.active,[a],o.time]}case`Use`:{let a={kind:`By`,usable:r.usable,isOnly:r.isOnly,location:r.location,step:r.step,method:r.method},o=l(t,n,a,i);if(o.kind!==`Steps`)throw new e.w(`simplifying BY does not produce a non-leaf proof!`);let s=r.usable.facts.map(()=>ut(Kn,`Visible`,i,r.location));return[[...t,...s],L(r.usable.facts.length,n),o.steps,i]}case`Hide`:return[r.usable.defs.reduce((t,n)=>{if(n.kind!==`Dx`)throw new e.w(`set_vis`);let i=t.length-n.index,a=t[i];if(a?.kind!==`Defn`){let t=a?a.kind===`Fact`?`??? FACT ???`:a.name:``;throw new e.w(`USE DEF ${t} invalid because ${t} is not a defined operator`)}return t.map((e,t)=>t===i?{...a,visibility:`Hidden`,location:r.location}:e)},t),n,[r],i];case`Define`:return[[...t,...r.definitions.map(e=>({kind:`Defn`,definition:e,whereDefined:{kind:`Proof`,time:i},visibility:`Visible`,isLocal:!0,location:r.location}))],L(r.definitions.length,n),[r],i];case`Have`:{let e=o(t,n),c=oa(e,`Implies`),l={context:[ut(r.expression,`Visible`,i,r.location)],active:c?L(1,e.args[1]):e},d=c?{kind:`By`,usable:{facts:[O({kind:`Ix`,index:2},r)],defs:[]},isOnly:!0,...ia(r)}:{kind:`Error`,message:sa(`@.@[<v2>@[%s@ %s@]@,%a@]@.`,`Error: this HAVE step is applied to the following goal,`,`which is not an implication:`,ta(t,n)),...ia(r)},f=a(s,{kind:`Suffices`,sequent:l,proof:d,location:r.location,step:r.step});return u(t,n,f,i)}case`Take`:return u(t,n,a(s,f(t,n,r)),i);case`Witness`:return u(t,n,a(s,p(t,n,r)),i);case`Pcase`:{let e={kind:`Assert`,sequent:{context:[ut(r.expression,`Visible`,i,r.location)],active:L(1,n)},proof:r.proof,...ia(r)};return u(t,n,a(s,e),i)}case`Pick`:{let a=O({kind:`Quant`,quantifier:`Exists`,bounds:r.bounds,body:r.expression},r),o=d(r.step,`ex`),[s,c,l,f]=u(t,n,{kind:`Assert`,sequent:{context:[],active:a},proof:r.proof,...ia(r),step:o},i),p=L(2,a);if(p.kind!==`Quant`)throw new e.w(`Proof.Simplify.simplify_step/PICK`);let m=[...ca(p.bounds),ut(p.body,`Visible`,f,p.body.location)],[h,g,_,v]=u(s,c,{kind:`Suffices`,sequent:{context:m,active:L(m.length,c)},proof:{kind:`Omitted`,omission:`Elsewhere`,...ia(r)},...ia(r)},f);return[h,g,[...l,..._],v]}}},d=(e,n)=>({kind:`Named`,level:aa(e),label:`${e?.kind===`Named`?e.label:`_a`}${n}${xn(t)}`,isAnonymous:!1}),f=(e,t,n)=>{let r=la(n.bounds),i=(t,n,r,a)=>{let s=a[0];if(!s)return{sideFacts:n,goal:r};let c=o(e,r);if(c.kind!==`Quant`||c.quantifier!==`Forall`||c.bounds.length===0)return sa(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this TAKE step is applied to the following goal,`,`which is not a universal formula:`,ta(e,r));let l=c.bounds[0],u=la(c.bounds).slice(1),d=s.domain,f=l.domain;if(d.kind===`NoDomain`&&f.kind===`Domain`)return sa(`@.@[<b0>%s (%s)@ %s (%s \\in %a)@]@.`,`Error: the TAKE argument`,s.name,`does not match the pattern`,l.name,ta(e,f.expression));if(d.kind===`Domain`&&f.kind===`NoDomain`)return sa(`@.@[<b0>%s (%s \\in %a)@ %s (%s)@]@.`,`Error: the TAKE argument`,s.name,ta(e,d.expression),`does not match the pattern`,l.name);let p=d.kind===`Domain`&&f.kind===`Domain`&&!R(d.expression,f.expression)?[{kind:`Apply`,operator:{kind:`Internal`,builtin:`Subseteq`},args:[f.expression,d.expression]},...n]:n;if(u.length===0)return i(1,p,c.body,a.slice(1));let m=a.length===1?u.map(e=>Dt(P(t),[e])[1][0]):u;return i(t+1,p,O({kind:`Quant`,quantifier:`Forall`,bounds:m,body:c.body},c),a.slice(1))},a=i(1,[],t,r);if(typeof a==`string`)return{kind:`Suffices`,sequent:{context:[ut(Jn(t),`Visible`,`Now`,n.location)],active:t},proof:{kind:`Error`,message:a,...ia(n)},...ia(n)};let s=a.sideFacts.filter((e,t)=>a.sideFacts.findIndex(t=>R(e,t))===t),c=[O({kind:`Ix`,index:2},n),...s.map(e=>L(2,e))];return{kind:`Suffices`,sequent:{context:ca(r),active:a.goal},proof:{kind:`By`,usable:{facts:c,defs:[]},isOnly:!0,...ia(n)},...ia(n)}},p=(e,t,n)=>{let r=[],i=``,a=t;for(let t of n.expressions){let n=o(e,a);if(n.kind!==`Quant`||n.quantifier!==`Exists`||n.bounds.length===0){i||=sa(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this WITNESS step is applied to the following goal,`,`which is not an existential formula:`,ta(e,n)),a=n;break}let[s,...c]=n.bounds,l=c.length===0?n.body:O({kind:`Quant`,quantifier:`Exists`,bounds:ua(s,c),body:n.body},n),u=t;if(s.domain.kind===`Domain`){let n=s.domain.expression,a=o(e,t);if(oa(a,`Mem`)){let[e,t]=a.args,i=R(t,n)?[]:[k(`Subseteq`,[t,n],t)];r.push(...i,a),u=e}else i||=sa(`@.@[<b0>%s (%a)@ %s (%s \\in %a)@]@.`,`Error: the WITNESS argument`,ta(e,a),`does not match the pattern`,s.name,ta(e,n)),u=a}let d=k(`Unprimable`,[u],u);a=I(St(d,P(0)),l)}let s=i===``?da(n,r):{kind:`Error`,message:i,...ia(n)};return{kind:`Suffices`,sequent:{context:[],active:a},proof:s,...ia(n)}};return l},ma=[`(`,`)`,`;`,`:`,`@`,`,`],ha=e=>e===` `||e===`\r`||e===` `,ga=(e,t)=>{for(;t.line<e.length;){let n=e[t.line];for(;ha(n[t.column]);)t.column++;if(t.column<n.length)return;t.line++,t.column=0}},_a=(e,t)=>{let n={...t};return ga(e,n),(e[n.line]??``).startsWith(`(*{`,n.column)?n:void 0},va=(e,t)=>{let n=_a(e,t);if(!n)return;let r={line:n.line,column:n.column+3},i=[];for(ga(e,r);r.line<e.length;ga(e,r)){let t=e[r.line].slice(r.column);if(t.startsWith(`}*)`))return i;let n=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t)??/^\d+(\.\d+)?/.exec(t)??/^"(\\.|[^"\\])*"/.exec(t);if(n){let e=n[0];i.push(e.startsWith(`"`)?{kind:`String`,text:JSON.parse(e)}:/^\d/.test(e)?{kind:`Number`,text:e}:{kind:`Ident`,text:e}),r.column+=e.length}else{if(!ma.includes(t[0]))return;i.push({kind:`Punct`,text:t[0]}),r.column++}}},ya=(e,t)=>e?.kind===`Punct`&&e.text===t,ba=e=>e?.kind===`String`?{kind:`String`,value:e.text}:e?.kind===`Number`?{kind:`Float`,value:Number.parseFloat(e.text)}:ya(e,`@`)?{kind:`Default`}:void 0,xa=/* @__PURE__ */ new Map([[`smt`,`smt`],[`cvc3`,`cvc4`],[`yices`,`yices`],[`z3`,`z3`],[`cooper`,`cooper`],[`presburger`,`cooper`],[`fail`,`fail`],[`smt2lib`,`smt`],[`smt2z3`,`z3`],[`smt3`,`smt`],[`z33`,`z3`],[`cvc33`,`cvc4`],[`yices3`,`yices`],[`verit`,`verit`],[`zipper`,`zipper`],[`spass`,`spass`],[`tptp`,`tptp`],[`ls4`,`ls4`],[`expandenabled`,`expandenabled`],[`expandcdot`,`expandcdot`],[`autouse`,`autouse`],[`lambdify`,`lambdify`],[`enabledaxioms`,`enabledaxioms`],[`levelcomparison`,`levelcomparison`],[`trivial`,`trivial`]]),Sa=(e,t)=>{let n=va(e,t);if(!n)return;let r=0,i=()=>{let e=n[r];return e?.kind===`Number`?(r++,{timeout:Number.parseFloat(e.text)}):{}},a=()=>{if(!ya(n[r],`(`))return;r++;let e=n[r++];if(e?.kind!==`Ident`)return;let t=(()=>{if(e.text===`isabelle`){let t=n[r];return t?.kind===`String`?(r++,{name:e.text,tactic:t.text,...i()}):void 0}if(e.text===`zenon`){let t=i();return ya(n[r],`(`)&&!a()?void 0:{name:e.text,...t}}let t=xa.get(e.text);return t===void 0?void 0:{name:t}})();if(t&&ya(n[r],`)`))return r++,t};if(n[r]?.kind!==`Ident`||n[r++].text!==`by`)return;let o=a();return r===n.length?o:void 0},Ca=(e,t)=>{let n=va(e,t);if(!n)return;let r=0,i=[];for(;r<n.length;){let e=n[r++];if(e.kind!==`Ident`||e.text!==`by`&&e.text!==`set`||!ya(n[r],`(`))return;r++;let t=[];for(;;){let e=n[r++];if(e?.kind!==`Ident`||!ya(n[r],`:`))return;r++;let i=ba(n[r++]);if(!i)return;if(t.push({hint:e.text,value:i}),ya(n[r],`)`))break;if(!ya(n[r],`;`))return;r++}r++,i.push(t)}return i},wa=e=>({kind:`Opaque`,name:e}),Ta=e=>({kind:`Tuple`,elements:e.map(wa)}),Ea=(e,t)=>({kind:`Apply`,operator:{kind:`Internal`,builtin:`Eq`},args:[e,t]}),Da=e=>e.map(e=>({name:e,level:`Constant`,domain:{kind:`NoDomain`}})),Oa=(e,t)=>e?.kind===`Product`&&e.factors.length===t.length?e.factors:void 0,ka=(e,t)=>t.map((t,n)=>({kind:`Operator`,name:t,body:{kind:`FcnApp`,function:wa(e),args:[{kind:`Num`,integer:String(n+1),fraction:``}]}})),Aa=(e,t)=>e.map((e,n)=>({name:e,level:`Constant`,domain:{kind:`Domain`,expression:t[n]}})),ja=e=>({name:e.name,level:`Constant`,domain:e.domain}),Ma=(e,t,n)=>{let r=[];return t.forEach(e=>{e.kind===`Name`&&e.domain.kind===`Ditto`?r.at(-1)?.push(e):r.push([e])}),r.reduceRight((t,n)=>{let r=(n,r=t)=>({kind:`Quant`,quantifier:e,bounds:n,body:r,location:t.location}),i=n[0];if(i.kind===`Name`)return r(n.flatMap(e=>e.kind===`Name`?[ja(e)]:[]));let a=Oa(i.domain,i.names);if(a)return r(Aa(i.names,a));let o={kind:`Apply`,operator:{kind:`Internal`,builtin:e===`Exists`?`Mem`:`Notmem`},args:[Ta(i.names),i.domain]};return r(Da(i.names),{kind:`List`,bullet:e===`Exists`?`And`:`Or`,items:[o,t]})},n)},Na=(e,t,n)=>{let r=`${e.kind.toLowerCase()}#${t[0]}`;return{...e,name:r,body:Oa(e.domain,t)?{kind:`Let`,definitions:ka(r,t),body:n}:{kind:`Quant`,quantifier:`Exists`,bounds:Da(t),body:{kind:`List`,bullet:`And`,items:[Ea(wa(r),Ta(t)),n]}}}},Pa=(e,t,n)=>{let r=e.map(e=>{if(e.kind===`Name`)return{bounds:[ja(e)],definitions:[]};let t=Oa(e.domain,e.names);if(t&&n)return{bounds:Aa(e.names,t),definitions:[]};let r=`fcn#${e.names[0]}`,i={name:r,level:`Constant`,domain:{kind:`Domain`,expression:e.domain}};if(t)return{bounds:[i],definitions:ka(r,e.names)};let a=`choose#${r}`;return{bounds:[i],definitions:[{kind:`Operator`,name:a,body:Na({kind:`Choose`,domain:void 0},e.names,Ea(wa(r),Ta(e.names)))},...ka(a,e.names)]}}),i=r.flatMap(e=>e.definitions);return{bounds:r.flatMap(e=>e.bounds),value:i.length===0?t:{kind:`Let`,definitions:i,body:t}}},Fa=(e,t)=>{let n=Pa(t,e,!0);return{kind:`SetOf`,element:n.value,bounds:n.bounds}},Ia=(e,t)=>{let n=Pa(e,t,!1);return{kind:`Fcn`,bounds:n.bounds,body:n.value}},La={Always:`[]`,Eventually:`<>`,Enabled:`ENABLED`,Unchanged:`UNCHANGED`},Ra=(e,t)=>e!==void 0&&t!==void 0&&e.line===t.line&&e.column===t.column,za=e=>e.location.range?.start,Ba=e=>e.location.range?.end,Va=(e,t)=>{let n=e.location.range;return n&&t?{...e,location:{...e.location,range:{...n,end:t}}}:e},Ha=e=>{if(e.kind===`Apply`){let t=Fi(e.operator),n=e.args.length===2&&t.fixity.startsWith(`Infix`),r=e.args.length===1&&t.fixity===`Prefix`;if(!n&&!r)return;let i=e.args.length-1;return{operator:t,isInfix:n,operand:e.args[i],replace:t=>({...e,args:[...e.args.slice(0,i),t]})}}let t=La[e.kind];if(t!==void 0&&`expression`in e)return{operator:Fi(t),isInfix:!1,operand:e.expression,replace:t=>({...e,expression:t})}},Ua=(e,t)=>e.high<t.low,Wa=e=>{let t=Fi(e.operator),[n,r]=e.args,i=Ba(e),a=t=>{let n=e.location.range,i=za(t);return{...e,args:[t,r],location:n&&i?{...e.location,range:{...n,start:i}}:e.location}},o=(e,n)=>{let r=n?Ha(e):void 0;if(!r)return{kind:`Reduced`,isFinal:!1};let s=o(r.operand,Ra(Ba(r.operand),Ba(e)));return s.kind===`Attached`?{kind:`Attached`,expression:Va(r.replace(s.expression),i)}:!s.isFinal&&(Ua(t,r.operator)||r.isInfix&&t.fixity===`InfixLeft`&&r.operator.fixity===`InfixLeft`&&!Ua(r.operator,t))?{kind:`Reduced`,isFinal:!Ua(t,r.operator)}:{kind:`Attached`,expression:Va(r.replace(a(r.operand)),i)}},s=o(n,Ra(za(n),za(e)));return s.kind===`Attached`?s.expression:e},Ga={"=>":`Implies`,"<=>":`Equiv`,"/\\":`Conj`,"\\/":`Disj`,"~":`Neg`,"=":`Eq`,"#":`Neq`,SUBSET:`SUBSET`,UNION:`UNION`,DOMAIN:`DOMAIN`,"\\subseteq":`Subseteq`,"\\in":`Mem`,"\\notin":`Notmem`,"\\":`Setminus`,"\\cap":`Cap`,"\\cup":`Cup`,"'":`Prime`,"~>":`Leadsto`,ENABLED:`ENABLED`,UNCHANGED:`UNCHANGED`,"\\cdot":`Cdot`,"-+->":`Actplus`,"[]":`BoxTrue`,"<>":`Diamond`,TRUE:`TRUE`,FALSE:`FALSE`,BOOLEAN:`BOOLEAN`,STRING:`STRING`},Ka=e=>Fi(e).name,qa=/^<(\d+|\*|\+)>([A-Za-z0-9_]*)\.*$/,Ja=(e,t)=>{if(!e||!t)return e??t;let n=e.startLine<t.startLine||e.startLine===t.startLine&&e.startColumn<=t.startColumn,r=e.endLine>t.endLine||e.endLine===t.endLine&&e.endColumn>=t.endColumn;return{file:e.file,startLine:n?e.startLine:t.startLine,startColumn:n?e.startColumn:t.startColumn,endLine:r?e.endLine:t.endLine,endColumn:r?e.endColumn:t.endColumn}},Ya="use instead the class`E_visit.iter_concrete`",Xa=(e,t)=>t>0&&e[t-1].set===e[t].set,Za=(t,n,r,i)=>{let a=n.split(`
31
- `),o=e=>({file:t,startLine:e.start.line,startColumn:e.start.column,endLine:e.end.line,endColumn:e.end.column+1}),s=e=>{let t=_a(a,{line:e.endLine-1,column:e.endColumn-1});if(!t)return e;for(let n=t.line;n<a.length;n++){let r=a[n].indexOf(`}*)`,n===t.line?t.column:0);if(r!==-1)return{...e,endLine:n+1,endColumn:r+4}}return e},c=e=>e&&Sa(a,{line:e.end.line-1,column:e.end.column}),l=e=>{let t=c(e),n=o(e);return t?{location:s(n),method:t}:{location:n}},u=(e,t)=>{let n=c(t);return n?O({kind:`With`,expression:e,method:n},e):e},d=(e,n)=>({file:t,startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+n}),f=e=>e.range?o(e.range):d(e,1),p=(e,t)=>{let n=Ka(e),r=Ga[n];return O(r?{kind:`Internal`,builtin:r}:{kind:`Opaque`,name:n},{location:t})},m=(e,t,n,r)=>{if(e.startsWith(`<`)){let t=O({kind:`Opaque`,name:e},{location:n});return O({kind:`Bang`,expression:t,selectors:[]},{location:n})}let i=Ga[e];if(i&&t.length===0)return O({kind:`Internal`,builtin:i},{location:n});let a=e.split(`!`);if(a.length===1){let r=O({kind:`Opaque`,name:e},{location:n});return t.length===0?r:O({kind:`Apply`,operator:r,args:t},{location:n})}let o=r??a.map((e,n)=>n===a.length-1?t.length:0),s=o.map((e,t)=>o.slice(0,t).reduce((e,t)=>e+t,0)),c=e=>t.slice(s[e],s[e]+o[e]),l=O({kind:`Opaque`,name:a[0]},{location:n});return O({kind:`Bang`,expression:o[0]===0?l:O({kind:`Apply`,operator:l,args:c(0)},{location:n}),selectors:a.slice(1).map((e,t)=>({kind:`Label`,label:Ka(e),args:c(t+1)}))},{location:n})},h=(t,n)=>t.map((r,i)=>{if(r.pattern.kind===`Tuple`)throw new e.w(`Unexpected tuple declaration`,{failure:Ya});return{name:r.pattern.name,level:`Constant`,domain:Xa(t,i)?{kind:`Ditto`}:{kind:`Domain`,expression:y(r.set,n)}}}),g=(e,t)=>e.map((n,r)=>{let i=y(n.set,t);return n.pattern.kind===`Tuple`?{kind:`Tuple`,names:n.pattern.names,domain:i}:{kind:`Name`,name:n.pattern.name,domain:Xa(e,r)?{kind:`Ditto`}:{kind:`Domain`,expression:i}}}),_=(t,n)=>{if(!i)throw new e.w(`Unexpected tuple declaration`,{failure:Ya});return O(t,{location:n})},v=e=>e.some(e=>e.pattern.kind===`Tuple`),y=(t,n)=>{let r=f(t.location),i=e=>y(e,n),o=(e,t)=>e.length===2?Ja(e[0].location,e[1].location):e.length!==1||!e[0].location?r:t===`Prefix`?Ja({...r,endLine:r.startLine,endColumn:r.startColumn+1},e[0].location):t===`Postfix`?Ja({...r,startLine:r.endLine,startColumn:r.endColumn-1},e[0].location):r,s=(e,t)=>O({kind:`Apply`,operator:{kind:`Internal`,builtin:e},args:[t]},{location:o([t],`Prefix`)});switch(t.kind){case`Number`:return O({kind:`Num`,integer:t.text??String(t.value),fraction:``},{location:r});case`Decimal`:{let[e,n]=t.text.split(`.`);return O({kind:`Num`,integer:e,fraction:n},{location:r})}case`String`:{let e=/"((?:[^"\\]|\\.)*)"$/.exec((a[r.endLine-1]??``).slice(0,r.endColumn-1));return O({kind:`String`,value:e?.[1]??t.value},{location:r})}case`Identifier`:return m(t.name,[],r);case`Apply`:{if(t.args.length===2){let e=Wa(t);if(e!==t)return i(e)}let e=t.args.map(i),n=Fi(t.operator);return n.fixity===`Nonfix`?m(t.operator,e,r,t.argumentCounts):O({kind:`Apply`,operator:p(t.operator,void 0),args:e},{location:o(e,n.fixity)})}case`OperatorReference`:return p(t.operator,r);case`Lambda`:return O({kind:`Lambda`,params:t.params.map(e=>({name:e,shape:0})),body:i(t.body)},{location:r});case`And`:case`Or`:{let e=t.operands.map(i);if(t.isBulleted)return O({kind:`List`,bullet:t.kind,items:e},{location:r});let n=t.kind===`And`?`Conj`:`Disj`;return e.reduce((e,t)=>O({kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:[e,t]},{location:Ja(e.location,t.location)}))}case`Prime`:{let e=i(t.expression);return O({kind:`Apply`,operator:{kind:`Internal`,builtin:`Prime`},args:[e]},{location:o([e],`Postfix`)})}case`Unchanged`:return s(`UNCHANGED`,i(t.expression));case`Enabled`:return s(`ENABLED`,i(t.expression));case`If`:return O({kind:`If`,condition:i(t.condition),consequent:i(t.consequent),alternative:i(t.alternative)},{location:r});case`Case`:return O({kind:`Case`,arms:t.arms.map(e=>({condition:i(e.condition),body:i(e.body)})),other:t.other&&i(t.other)},{location:r});case`Let`:return O({kind:`Let`,definitions:[...t.definitions,...t.instances??[]].sort((e,t)=>e.location.line-t.location.line||e.location.column-t.location.column).map(e=>ee(e,n)),body:i(t.body)},{location:r});case`Forall`:case`Exists`:return v(t.bounds)?_(Ma(t.kind,g(t.bounds,n),i(t.body)),r):O({kind:`Quant`,quantifier:t.kind,bounds:h(t.bounds,n),body:i(t.body)},{location:r});case`UnboundedQuantifier`:{let e=i(t.body),n=t.quantifier;return t.isTemporal?O({kind:`Tquant`,quantifier:n,names:t.names,body:e},{location:r}):O({kind:`Quant`,quantifier:n,bounds:Da(t.names),body:e},{location:r})}case`Choose`:return t.pattern.kind===`Tuple`?_(Na({kind:`Choose`,domain:t.set&&i(t.set)},t.pattern.names,i(t.body)),r):O({kind:`Choose`,name:t.pattern.name,domain:t.set&&i(t.set),body:i(t.body)},{location:r});case`SetEnumeration`:return O({kind:`SetEnum`,elements:t.elements.map(i)},{location:r});case`SetFilter`:return t.bound.pattern.kind===`Tuple`?_(Na({kind:`SetSt`,domain:i(t.bound.set)},t.bound.pattern.names,i(t.predicate)),r):O({kind:`SetSt`,name:t.bound.pattern.name,domain:i(t.bound.set),body:i(t.predicate)},{location:r});case`SetMap`:return v(t.bounds)?_(Fa(i(t.expression),g(t.bounds,n)),r):O({kind:`SetOf`,element:i(t.expression),bounds:h(t.bounds,n)},{location:r});case`Tuple`:return O({kind:`Tuple`,elements:t.elements.map(i)},{location:{...r,startLine:r.endLine,startColumn:r.endColumn-2}});case`FunctionConstruction`:return v(t.bounds)?_(Ia(g(t.bounds,n),i(t.body)),r):O({kind:`Fcn`,bounds:h(t.bounds,n),body:i(t.body)},{location:r});case`FunctionSet`:return O({kind:`Arrow`,domain:i(t.domain),range:i(t.range)},{location:r});case`Record`:case`RecordSet`:return O({kind:t.kind===`Record`?`Record`:`Rect`,fields:t.fields.map(e=>({name:e.name,value:i(e.value)}))},{location:r});case`Except`:return O({kind:`Except`,function:i(t.function),specs:t.updates.map(e=>({trail:e.path.map(e=>e.kind===`Field`?{kind:`Dot`,field:e.name}:{kind:`Apply`,expression:e.args.length===1?i(e.args[0]):{kind:`Tuple`,elements:e.args.map(i)}}),value:y(e.value,!0)}))},{location:r});case`ExceptAt`:return O({kind:`At`,isExcept:n},{location:r});case`Bracket`:throw new e.w(`Unexpected [ without a function or subscript`);case`FunctionApplication`:return O({kind:`FcnApp`,function:i(t.function),args:t.args.map(i)},{location:r});case`FieldAccess`:return O({kind:`Dot`,expression:i(t.record),field:t.field},{location:r});case`Product`:return O({kind:`Product`,factors:t.factors.map(i)},{location:r});case`Always`:case`Eventually`:{let e=t.expression;return t.kind===`Always`&&e.kind===`BoxAction`?O({kind:`Tsub`,modal:`Box`,action:i(e.action),subscript:i(e.subscript)},{location:r}):t.kind===`Eventually`&&e.kind===`AngleAction`?O({kind:`Tsub`,modal:`Dia`,action:i(e.action),subscript:i(e.subscript)},{location:r}):s(t.kind===`Always`?`BoxTrue`:`Diamond`,i(e))}case`BoxAction`:case`AngleAction`:return O({kind:`Sub`,modal:t.kind===`BoxAction`?`Box`:`Dia`,action:i(t.action),subscript:i(t.subscript)},{location:r});case`WeakFairness`:case`StrongFairness`:return O({kind:`Fair`,fairness:t.kind===`WeakFairness`?`Weak`:`Strong`,subscript:i(t.subscript),action:i(t.action)},{location:r});case`Label`:return O({kind:`Parens`,expression:i(t.body),form:{kind:`Nlabel`,label:t.name,names:t.params}},{location:r});case`Subexpression`:{let[n,...a]=t.selectors;if(n.kind!==`Name`)throw new e.w(`Unexpected subexpression reference`);let o=O({kind:`Opaque`,name:n.name},{location:r}),s=n.args.length===0?o:O({kind:`Apply`,operator:o,args:n.args.map(i)},{location:r});return O({kind:`Bang`,expression:s,selectors:a.map(e=>{switch(e.kind){case`Name`:return{kind:`Label`,label:Ka(e.name),args:e.args.map(i)};case`Operand`:return e.operand===`<<`?{kind:`Left`}:e.operand===`>>`?{kind:`Right`}:{kind:`Number`,value:e.operand};case`Bound`:return{kind:`Instance`,args:e.args.map(i)};case`At`:return{kind:`At`};case`Colon`:return{kind:`Down`}}})},{location:r})}}},b=e=>({location:o(e.definitionRange??e.instanceRange),args:e.params.map(e=>e.name),module:e.module,substitutions:e.substitutions.map(e=>({name:Ka(e.name),expression:y(e.expression,!1)}))}),ee=(t,n=!1)=>{let r=f(t.location);if(t.kind===`Instance`){if(t.name===void 0)throw new e.w(`Unexpected keyword INSTANCE`);return{kind:`Instance`,name:t.name,instance:b(t),location:r}}let i=t.kind===`Operator`&&t.params.length===1&&t.name===`-`?`-.`:Ka(t.name),o=y(t.body,n);if(t.kind===`Function`&&v(t.bounds))return{kind:`Operator`,name:i,body:_(Ia(g(t.bounds,n),o),r),location:r};if(t.kind===`Function`){let e=h(t.bounds,n);return{kind:`Operator`,name:i,body:O({kind:`Fcn`,bounds:e,body:o},{location:r}),location:r}}let s=t.params.length===0?o:O({kind:`Lambda`,params:t.params.map(e=>({name:Ka(e.name),shape:e.arity,...e.location&&{location:d(e.location,e.name.length)}})),body:o},{location:r}),c=t.location.range?.end,l=c&&Ca(a,{line:c.line-1,column:c.column});return l?{kind:`Bpragma`,name:i,body:s,methods:l,location:r}:{kind:`Operator`,name:i,body:s,location:r}},x=e=>{let t=f(e.location);return e.level===`Variable`?{kind:`Flex`,name:e.name,location:t}:{kind:`Fresh`,name:e.name,shape:e.arity,level:e.level,domain:e.set&&y(e.set,!1),domainVisibility:`Visible`,location:t}},te=e=>e.kind===`AssumeProve`?{context:e.assumptions.map(e=>{if(e.kind===`NewSymbol`)return x(e);let t=e.kind===`AssumeProve`?O({kind:`Sequent`,sequent:te(e)},{location:f(e.location)}):ne(e);return ut(t,`Visible`,`Now`,t.location)}),active:y(e.conclusion,!1)}:{context:[],active:y(e,!1)},ne=e=>{if(e.kind!==`Label`||e.params.length>0)return y(e,!1);let t=f(e.location);return O({kind:`Parens`,expression:y(e.body,!1),form:{kind:`Xlabel`,label:e.name,indices:[]}},{location:t})},S=t=>{if(t.kind===`ModuleFact`)throw new e.A(`MODULE facts in proof obligations are not supported`);let n=y(t,!1);return n.kind===`Bang`&&n.selectors.length===0?n.expression:n},re=t=>{let n=f(t.location);if(t.kind===`ModuleFact`)return{kind:`Dvar`,name:t.name,location:n};if(t.kind===`Identifier`)return{kind:`Dvar`,name:Ka(t.name),location:n};if(t.kind===`OperatorReference`)return{kind:`Dvar`,name:Ka(t.operator),location:n};throw new e.A(`This DEF clause in proof obligations is not supported`)},ie=e=>({facts:e.facts.map(S),defs:e.defs.map(re)}),ae=(e,t)=>e?.[2]?{kind:`Named`,level:t,label:e[2],isAnonymous:!1}:{kind:`Unnamed`,level:t,id:xn(r)},C=(e,t,n)=>{if(!e)return{kind:`Omitted`,omission:`Implicit`,location:n};switch(e.kind){case`Obvious`:return{kind:`Obvious`,...l(e.keyword)};case`Omitted`:return{kind:`Omitted`,omission:`Explicit`,location:o(e.keyword)};case`By`:return{kind:`By`,usable:ie(e),isOnly:e.isOnly,location:o(e.keyword),step:{kind:`Unnamed`,level:t,id:0},method:c(e.location.range)};case`Steps`:{let n=e.steps.map(e=>qa.exec(e.token)),r=n[0],i=r&&r[1]!==`*`&&r[1]!==`+`?Number(r[1]):t,a=e.steps.slice(0,-1).map((e,t)=>se(e,ae(n[t],i),i)),s=e.steps[e.steps.length-1],c=ae(n[n.length-1],i),l=o(s.head),u=C(s.proof,i+1,l),d={proof:u,location:Ja(l,u.location),step:c};return{kind:`Steps`,steps:a,qed:d,location:a.reduce((e,t)=>Ja(e,t.location),d.location),step:d.step}}}},oe=e=>Ja(o(e.keyword),e.defs.length>0?f(e.defs[e.defs.length-1].location):void 0),se=(t,n,r)=>{let i=o(t.head),a=t.body,s=e=>{let a=C(t.proof,r+1,i);return{...e(a),location:Ja(i,a.location),step:n}},u=e=>({...e,...l(t.head),step:n});switch(a.kind){case`Use`:case`Hide`:{let e=Ja(o({...t.head,end:t.head.start}),oe(a)),r=ie(a);return a.kind===`Use`?{kind:`Use`,usable:r,isOnly:a.isOnly,location:e,step:n,method:c(a.location.range)}:{kind:`Hide`,usable:r,location:e,step:n}}case`Instance`:throw new e.w(`Unexpected keyword INSTANCE`);case`Define`:return{kind:`Define`,definitions:a.definitions.map(e=>ee(e)),location:i,step:n};case`Have`:return u({kind:`Have`,expression:y(a.expression,!1)});case`Take`:return u({kind:`Take`,bounds:a.names.length>0?Da(a.names):h(a.bounds,!1)});case`Witness`:return u({kind:`Witness`,expressions:a.expressions.map(e=>y(e,!1))});case`Pick`:{let e=a.names.length>0?Da(a.names):h(a.bounds,!1),t=y(a.body,!1);return s(n=>({kind:`Pick`,bounds:e,expression:t,proof:n}))}case`Case`:{let e=y(a.expression,!1);return s(t=>({kind:`Pcase`,expression:e,proof:t}))}case`Assert`:{let e=te(a.statement);return s(t=>a.isSuffices?{kind:`Suffices`,sequent:e,proof:t}:{kind:`Assert`,sequent:e,proof:t})}case`Qed`:throw new e.A(`QED in the middle of a proof`)}},ce=e=>({name:e.name,extendees:e.extends,extendeeLocations:e.extendsRanges.map(o),isImportant:!1,location:f(e.location),body:e.units.map(e=>{switch(e.kind){case`Constants`:case`Recursive`:return{kind:e.kind===`Constants`?`Constants`:`Recursives`,declarations:e.declarations.map(e=>({name:Ka(e.name),shape:e.arity})),location:f(e.declarations[0].location)};case`Variables`:return{kind:`Variables`,names:e.declarations.map(e=>e.name),location:f(e.declarations[0].location)};case`Definition`:return{kind:`Definition`,definition:ee(e.definition),whereDefined:`User`,visibility:`Hidden`,isLocal:e.definition.isLocal,location:f(e.definition.location)};case`Instance`:{let t=e.instance,n=f(t.location);return t.name===void 0?{kind:`Anoninst`,instance:b(t),isLocal:t.isLocal,location:n}:{kind:`Definition`,definition:ee(t),whereDefined:`User`,visibility:`Hidden`,isLocal:t.isLocal,location:o(t.instanceRange)}}case`Assumption`:return{kind:`Axiom`,name:e.assumption.name,expression:u(y(e.assumption.expression,!1),e.assumption.location.range),location:f(e.assumption.location)};case`Theorem`:{let t=e.theorem,n=f(t.location),r=s(n),i=te(t.statement);return{kind:`Theorem`,name:t.name,sequent:{...i,active:u(i.active,t.statement.location.range)},axiomCount:0,proof:C(t.proof,0,{...r,startLine:r.endLine,startColumn:r.endColumn}),location:n}}case`Use`:return{kind:`Mutate`,mode:e.use.kind,usable:ie(e.use),location:oe(e.use)};case`Module`:return{kind:`Submod`,module:{...ce(e.module),isImportant:!0}}}})});return{convertModule:ce}},Qa={start:0,end:1/0},$a=/-{4,} *MODULE/,eo=`Unexpected EOF`,to=e=>e?`${e.startLine}:${e.startColumn}:${e.endLine}:${e.endColumn}`:``,no=e=>{let n=t.Zt(e),r=e.split(`
32
- `),i=n.at(-1)?.line??r.length,a=r.slice(0,i-1).reduce((e,t)=>e+t.length+1,0)+r[i-1].indexOf(`====`),o=e.indexOf(` `,e.search($a));if(o===-1||o>=a)return;let s=e.slice(0,o).split(`
15
+ `],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set,l=(t,n)=>{if(!e.strict)return!1;let r=`${t.fingerprint} ${n.fingerprint}`;return c.has(r)?!0:(c.add(r),!1)},u=e=>{let t=o.get(e.level)??/* @__PURE__ */ new Set;o.set(e.level,t.add(e.fingerprint))},d=e=>{if(!e)return 1;let t=s.get(e.name)??s.size+2;return s.set(e.name,t),t},f=()=>[`subgraph cluster_legend {graph[style=bold];label = "Next State Actions" style="solid"
16
+ `,`node [ labeljust="l",colorscheme="${ne}",style=filled,shape=record ]\n`,...ie([...s.keys()],t.Zt).map(e=>`${e.replaceAll(`!`,`:`)} [label="${e}",fillcolor=${s.get(e)}]\n`),`}`].join(``),p=()=>[...ie([...o],e=>e[0]).map(e=>`{rank = same; ${ie([...e[1]],ae).map(e=>`${e};`).join(``)}}\n`),`}
17
+ `,e.colorize&&s.size>1?f():``,`}`].join(``),m=()=>{e.snapshot&&n?.(e.path.replaceAll(`.dot`,`_snapshot.dot`),a.join(``)+p())},h=(t,n,r,o,s)=>{if(l(t,n))return;let c=e.colorize?String(d(o)):`black`,f=e.actionLabels&&o?oe(i?o.name:o.signature):``,p=s===void 0?f:`${f}\n${s}`;if(a.push(`${t.fingerprint} -> ${n.fingerprint} [label="${p}",color="${c}",fontcolor="${c}"];\n`),!r){let e=i?``:`,tooltip="${se(n.getText())}"`,t=s===void 0?``:`,style = filled, fillcolor=lightyellow`;a.push(`${n.fingerprint} [label="${se(n.getLabel())}"${e}${t}];\n`)}u(t),m()};return{writeInitialState:e=>{a.push(`${e.fingerprint} [label="${se(e.getLabel())}",style = filled]\n`),u(e),m()},writeSuccessor:h,writeConstrained:(e,t,n,r)=>h(e,t,!1,n,r),writeStuttering:e=>{l(e,e)||(a.push(`${e.fingerprint} -> ${e.fingerprint} [style="dashed"${i?``:`,color="lightgray"`}];\n`),u(e),m())},close:()=>n?.(e.path,a.join(``)+p())}},le=(e,t,n)=>e.dot?ce(e,t,n):E(e,t),ue=` `,de=`
18
+ ----
19
+ `,fe=`${`=`.repeat(77)}\n`,pe=`_TTraceLassoStart`,me=`_TTraceLassoEnd`,he=e=>{let n=t.Zt(e);return n^n>>>16},ge=e=>{let t=[...new Set(e)],n=2**Math.max(4,Math.ceil(Math.log2(t.length/.75)));return t.map((e,t)=>({name:e,index:t,bucket:he(e)&n-1})).sort((e,t)=>e.bucket-t.bucket||e.index-t.index).map(e=>e.name)},_e=e=>{let n=(t,n)=>new Intl.DateTimeFormat(`en-US`,t).formatToParts(e).find(e=>e.type===n)?.value;return`${n({weekday:`short`},`weekday`)} ${n({month:`short`},`month`)} ${t.Xt(e.getDate())} ${t.Xt(e.getHours())}:${t.Xt(e.getMinutes())}:${t.Xt(e.getSeconds())} ${n({timeZoneName:`short`},`timeZoneName`)} ${e.getFullYear()}`},ve=e=>{let t=e.split(`
20
+ `);for(;t.length>1&&t[t.length-1]===``;)t.pop();return t},ye=(e,t)=>{let n=ue.repeat(t);return n+ve(e).join(`\n${n}`)},be=(e,t)=>`---- MODULE ${e} ----\nEXTENDS ${t.join(`, `)}\n\n`,xe=(e,t)=>ye([...t===void 0?[]:[t],...e.map(([e,t])=>`${e} = (${t})`)].join(`
21
+ /\\
22
+ `),2),Se=(e,t,n)=>`${e} ==\n${ue}LET ${t} == INSTANCE ${t}\n${ue}IN ${t}!${n}\n----\n`,Ce=(e,t)=>{let n=t[0],r=n===void 0?``:`\\* ,_${n}Unchanged |-> ${n} = ${n}'
23
+
24
+ \\* Format the \`${n}\` variable as Json value.
25
+ \\* ,_${n}Json |->
26
+ \\* LET J == INSTANCE Json
27
+ \\* IN J!ToJson(${n})
28
+
29
+ \\* Lastly, you may build expressions over arbitrary sets of states by
30
+ \\* leveraging the _TETrace operator. For example, this is how to
31
+ \\* count the number of times a spec variable changed up to the current
32
+ \\* state in the trace.
33
+ \\* ,_${n}ModCount |->
34
+ \\* LET F[s \\in DOMAIN _TETrace] ==
35
+ \\* IF s = 1 THEN 0
36
+ \\* ELSE IF _TETrace[s].${n} # _TETrace[s-1].${n}
37
+ \\* THEN 1 + F[s-1] ELSE F[s-1]
38
+ \\* IN F[_TEPosition - 1]
39
+ `,i=`\\* To hide variables of the \`${e}\` spec from the error trace,
40
+ \\* remove the variables below. The trace will be written in the order
41
+ \\* of the fields of this record.
42
+ ${t.map(e=>`${e} |-> ${e}`).join(`
43
+ ,`)}
44
+
45
+ \\* Put additional constant-, state-, and action-level expressions here:
46
+ \\* ,_stateNumber |-> _TEPosition
47
+ ${r}`;return`expression == \n${ue}[\n${ye(i,2)}\n${ue}]\n\n`},we=e=>{let n=e.loopStart,r=e.states.map(e=>ge(Object.keys(e)).map(n=>[n,t.kt(e[n])]));if(r.length+(n===void 0?0:1)<=1)return;let i=Object.keys(e.states[0]),a=e.specName,o=r[r.length-1],s=n===r.length-1,c=n!==void 0&&!s,l=new Set(e.rawConstants.map(e=>e.split(` = `)[0])),u=[...e.rawConstants.map(e=>ye(e,1)),...e.modelValues.filter(e=>!l.has(e)).map(e=>ye(`${e} = ${e}`,1)),...c?[`${pe} = ${n+1}`,`${me} = ${r.length}`]:[]],d=[...e.modelValues.filter(t=>!e.isDefined(t)),...c?[pe,me]:[]],f=`${a}_TEConstants`,p=ge([`TLC`,...d.length>0?[f]:[]]),m=ge([`Toolbox`,`TLCExt`,`Naturals`,`Sequences`,...p,a]),h=`${a}_TEExpression`,g=`${a}_TETrace`,_=s?{config:`
48
+ PROPERTY
49
+ _prop
50
+ `,definition:`\n_prop ==\n${ue}~<>[](\n${xe(o)}\n${ue})`}:c?{config:`
51
+ PROPERTY
52
+ _prop
53
+ `,definition:`\n_prop ==\n${ye(`~(([]<>(\n${xe(o)}\n))/\\([]<>(\n${xe(r[n])}\n)))`,1)}`}:{config:`
54
+ INVARIANT
55
+ _inv
56
+ `,definition:`\n_inv ==\n${ue}~(\n${xe(o,`TLCGet("level") = Len(_TETrace)`)}\n${ue})`},v=`_next ==
57
+ /\\ \\E i,j \\in DOMAIN _TETrace:
58
+ /\\ \\/ /\\ j = i + 1
59
+ /\\ i = TLCGet("level")
60
+ ${c?`${ue}${ue} \\/ /\\ i = ${me}\n${ue}${ue} /\\ j = ${pe}\n`:``}${i.map(e=>` /\\ ${e} = _TETrace[i].${e}\n /\\ ${e}' = _TETrace[j].${e}\n`).join(``)}
61
+ \\* Uncomment the ASSUME below to write the states of the error trace
62
+ \\* to the given file in Json format. Note that you can pass any tuple
63
+ \\* to \`JsonSerialize\`. For example, a sub-sequence of _TETrace.
64
+ \\* ASSUME
65
+ \\* LET J == INSTANCE Json
66
+ \\* IN J!JsonSerialize("${e.module}.json", _TETrace)
67
+
68
+ `,y=c&&new Set(r.map(e=>JSON.stringify(e))).size<r.length?{config:`
69
+ VIEW
70
+ _view
71
+ `,definition:`\n_view ==\n${ue}<<${i.join(`, `)}, IF TLCGet("level") = ${me} + 1 THEN ${pe} ELSE TLCGet("level")>>\n`}:{config:``,definition:``},b=`\n${be(g,ge([`IOUtils`,...p,a]))}trace == IODeserialize("${e.module}.bin", TRUE)\n\n${fe}`,x=`${ue}<<\n${r.map(e=>`${ue}([${e.map(([e,t])=>`${e} |-> ${t}`).join(`,`)}])`).join(`,
72
+ `)}\n${ue}>>${de}\n`;return[be(e.module,m),`${Se(`_expression`,h,`expression`)}\n`,Se(`_trace`,g,`trace`),_.definition,`${de}\n`,`_init ==
73
+ `,i.map(e=>`${ue}/\\ ${e} = _TETrace[1].${e}\n`).join(``),`----
74
+
75
+ `,v,y.definition,fe,`
76
+ `,` Note that you can extract this module \`${h}\`\n`," to a dedicated file to reuse `expression` (the module in the \n",` dedicated \`${h}.tla\` file takes precedence \n`,` over the module \`${h}\` below).`,`\n\n${be(h,m)}${Ce(a,i)}${fe}\n\n`,`
77
+ `,`Parsing and semantic processing can take forever if the trace below is long.
78
+ `,` In this case, it is advised to uncomment the module below to deserialize the
79
+ `,` trace from a generated binary file.
80
+ `,`\n\\*${b.replaceAll(`
81
+ `,`
82
+ \\*`)}\n\n`,be(g,ge([...p,a])),`trace == \n${x}\n`,...d.length>0?[fe,`
83
+ `,be(f,[a]),`CONSTANTS ${d.join(`, `)}\n\n`]:[],fe].join(``)+[`\n---- CONFIG ${e.module} ----\n`,u.length>0?`CONSTANTS\n${u.map(e=>`${e}\n`).join(``)}`:``,_.config,`
84
+ CHECK_DEADLOCK
85
+ \\* CHECK_DEADLOCK off because of PROPERTY or INVARIANT above.
86
+ FALSE`,`
87
+
88
+ INIT
89
+ _init
90
+ `,`
91
+ NEXT
92
+ _next
93
+ `,y.config,`
94
+ CONSTANT
95
+ _TETrace <- _trace
96
+ `,`
97
+ ALIAS
98
+ _expression
99
+ `,fe,`\\* Generated on ${_e(/* @__PURE__ */ new Date)}`].join(``)},Te=(e,t)=>({...e,traceOutput:[...e.traceOutput??[],...t]}),Ee=/* @__PURE__ */ Error(`The replay stopped`),De=/* @__PURE__ */ Error(`The walk stopped`),Oe=t=>{let n=t.dump&&le(t.dump,t.writeFile,t.version);try{return ke(t,n)}catch(t){throw e.tt(t)?e.Y():t}finally{n?.close()}},ke=(n,r)=>{let i=typeof n.config==`string`?t.$t(n.config,n.version):n.config,s=n.onPrint??console.log,l,u=e=>{l?l.push(e):s(e)},f=e=>{let t=l,n=[];l=n;try{return{result:e(),lines:n}}finally{l=t}},p=t.c(i,n,u),m=p.specification;t.g(m,i,n.onProgress);let h=n.coverage===void 0?void 0:t.bt(m.environment.variables.length),g=h?{...m.environment,evaluators:/* @__PURE__ */ new WeakMap,entryEvaluators:/* @__PURE__ */ new WeakMap,definitionEvaluators:/* @__PURE__ */ new WeakMap,coverage:h}:m.environment,_=g.runtime,v=_.version===`1.7.4`;_.pause=n.onPause??(()=>{});let y,b=()=>y??=t.T(i,g,m.instanceActions);_.getSpecification=()=>t.E(b(),i,g,m.variableLocations);let x=0,S,C=(e,r)=>n.traceSpec&&we({module:n.traceSpec.module,specName:m.rootName,rawConstants:i.rawConstants,states:e.map(e=>de(e)),loopStart:r,modelValues:t.Mt().map(e=>e.name),isDefined:e=>g.definitions.has(e)||g.constants.has(e)||[...g.definitions.keys()].some(t=>t.startsWith(`${e}@`))}),w=(e,n,r)=>{let i=C(n?.trace??r?.trace??[],e===`property-violation`?void 0:n?.loopStart);return{status:e,violation:n&&{...n,loopStart:n.loopStart},failure:r,generatedStates:_.generatedStates,distinctStates:_.distinctStates,queuedStates:_.queueSize,depth:_.generatedStates===0?0:Math.max(x,1),initialStates:S,outDegrees:void 0,fingerprintDistance:void 0,coverage:h?.relations.some(e=>e.kind===`next`)?t.St(h,g,m.variableLocations,E?.getTlcOrder()??[]):void 0,...i!==void 0&&{traceSpec:i}}},T=Array.from({length:32},()=>0),ee=0,ne=()=>Math.min(ee,31),re=()=>T.map((e,t)=>t===ne()?e+1:e),ie=()=>v?[...T]:re(),ae=(e,t,n)=>v?[]:e.getViolatedProperties(t,n),oe=(e,t=[...T])=>({...e,violationOutDegrees:t}),se=()=>({...w(`success`),outDegrees:[...T],fingerprintDistance:t.a(_.distinctStates,_.generatedStates,()=>E?E.getStoredFingerprints(O,Ie):BigInt64Array.from(O,_.getFingerprint))}),E=t.u(i,g,m.variableLocations,()=>p.order.getDeclarationOrder(`variable`),n.onProgress,m.moduleOperators),ce=()=>t.d(m.assumptions,g);if(!E){_.isStarted=!0;let e=ce();return e?w(`assumption-violation`,e):(S={generated:0,distinct:0},n.onProgress?.({kind:`initial-states-started`}),n.onProgress?.({kind:`initial-states-computed`,initialStates:S}),se())}let le=i.postconditions.length>0||i.possible.length>0||m.moduleOperators.some(e=>e.kind===`postcondition`),ue=/* @__PURE__ */ new WeakMap,de=e=>ue.get(e)?.state??e.state,fe=e=>{let n=ue.get(e)?.action;return n?t.D(n):t.ft(e.action)},pe=(e,n)=>{le&&(_.counterExample=t.pt(e.map(de),e.slice(1).map(fe),n));let r=E.findUnwitnessedPossible(),i=r?{result:void 0,lines:[]}:f(()=>E.findPostconditionViolation(!0));return{unwitnessed:r,postcondition:i.result,lines:i.lines}},me=(e,t,n)=>{let r=t.loopStart,i=pe(t.trace,r===void 0||!n?void 0:{start:r,action:n()});return w(e,{...t,...i.lines.length>0&&{postconditionOutput:i.lines},...i.unwitnessed&&{unwitnessed:i.unwitnessed},...i.postcondition&&{postcondition:i.postcondition}})},he,ge=(e,t)=>{he??=e,n.onProgress?.({kind:`violation`,status:e,violation:{...t,loopStart:void 0}})},_e=E.spec,ve=E.getFingerprintState,ye=b().actions;_.getSuccessorAction=(e,n)=>ye.find(r=>t.nt(r.expression,e,g,r.scope).some(e=>e.state.every((e,r)=>t.Ft(e,n[r]))));let be=(e,n)=>n.map(n=>({...n,node:h?t._t(h,e,t.xt(n.name,n.expression,g),n.expression,n.scope):-1})),xe=be(`init`,h?b().inits:[]),Se=be(`next`,h?ye:[]);h&&t.vt(h,g,t.it(Se,g));let Ce=(n,r,i)=>t.st(n,n.node,r,g,e=>{h&&h.primary[n.node]++,i(e)},t=>{let r=g.variables.filter((e,n)=>t[n]===void 0);throw new e.C(`Successor state is not completely specified by action ${n.name}. The following variables are not assigned: ${r.join(`, `)}`,t,n.name,r)}),Oe=(e,t)=>{let n=[];return Ce(e,t,t=>n.push({state:t,action:e.name})),n},ke=t=>{throw e.at(new e.S([...t]),e.nt.error)},Ae=()=>{let e=[];return t.at(xe,g,t=>e.push(t),ke),e},je=()=>{let e=We?[We]:[];return(n,r)=>{c(n,ve(n),r);let i=ve(n);return t.B(ze,t.V(i),i)!==-1||e.some(e=>t.W(e,i))?!1:(e.push(i),_.distinctStates++,!0)}},Me=()=>{let n=0,r=[],i=je();return o(g,a=>{if(t.at(b().inits,a,o=>{if(t.h(n,e=>l?.push(e)),n++,_.generatedStates=n,!(r.length>0))try{let e=E.checkReplayedInitialState(o,a,()=>{i(o,a.callStack)&&(_.queueSize++,D?.addInitialState(O.length,o,a))});if(e){let t=qe.toTrace([{action:void 0,state:o}],[]).trace[0].state;throw l?.push({kind:`initial-state-violation`,...e,state:t}),Ee}}catch(t){if(!(t instanceof e.b&&a.callStack?.fingerprint!==void 0)&&!e.tt(t))throw t;r.push(t)}}),r.length>0)throw r[0]})},Ne=e=>o(g,n=>{let i=O[e],a=r&&Xe(i,Re[e]),o=je();t.ot(ye,i,n,(t,s)=>{if(!E.checkReplayedSuccessor(i,t,n,()=>{let i=o(t,n.callStack);return a&&r?.writeSuccessor(a,Xe(t,Re[e]+1),!i,rt?Ye(s):void 0),i}))throw Ee})}),Pe=[];E.properties.liveness.length>0&&n.onProgress?.({kind:`liveness-initializing`,isSymmetric:E.isSymmetric,isConstrained:E.isConstrained});let D=e.ot(()=>t.Yt(()=>te(E.properties.liveness,_e.temporals,g,{getFingerprint:e=>Pe[e.index]??=Number(BigInt.asIntN(32,_.getFingerprint(e.state))),getSuccessors:(e,n)=>{let r=[];if(_e.next===void 0)return r;let i=N.livenessSource;N.livenessSource=e;try{t.et(_e.next,n,g,e=>{if(Be(e.state),!(E.satisfiesConstraints(e.state,n)&&E.satisfiesActionConstraints(n,e.state)))return!1;let i=ve(e.state),a=t.B(ze,t.V(i),i);return r.push({index:a,state:e.state}),!1},_e.scope)}finally{N.livenessSource=i}return r}})));if(D?.branches===0)throw t.O();_.isStarted=!0;let Fe=E.isSymmetric||D!==void 0,O=[],Ie=[],k=[],Le=[],Re=[],ze=t.z(Ie),Be=t.Tt(),A=E.toRecord,Ve=()=>h?Ae():_e.init===void 0?[]:t.tt(_e.init,g,_e.scope),j=n=>{try{return ve(n).some(e=>t.At(e)!==void 0)}catch(t){if(!(t instanceof e.b))throw t;return!0}},M=(n,r,i={})=>{let o=e.tt(n)?new e.P:n;if(!(o instanceof e.b))throw o;let s=r.trace.length>0&&!i.traceFailure?pe(r.trace,void 0):void 0,c=s?.unwitnessed??s?.postcondition,l=[...r.traceOutput??[],...s?.lines??[]];return{...w(`error`,void 0,{...t.Gt(o,i.phase!==void 0&&i.phase!==`initial`),...r,...l.length>0&&{traceOutput:l},...c&&{postcondition:c},initialState:i.initialState&&!(o instanceof e.k)?A(i.initialState):void 0,exitCode:a(o,i,v),callStack:i.callStack,...i.phase===`liveness`&&{isCallStackFirst:!0},...i.fingerprint&&{fingerprint:i.fingerprint},...i.traceFailure&&{traceFailure:i.traceFailure}}),outDegrees:i.outDegrees}},He=(r,i)=>{_.generatedStates++;let a=ye.length===1?ye:ye.filter(e=>e.name===i.action),o=a.length===1?a[0]:f(()=>a.find(e=>t.rt(e.expression,O[r],g,e.scope))).result,s=t.f(i.variables,i.action,ye.length,n.version),c=t.Et(`null`),l=i.state.map(e=>e??c),u=M(i,qe.getStateTrace(r));return oe({...u,failure:u.failure&&{...u.failure,code:t.Lt.incompleteSuccessor,message:s,toolMessage:s,exitCode:e.nt.specEvaluationFailure,trace:[...u.failure.trace,{action:i.action,label:o&&t.C(o,n.version),state:A(l)}]}})},Ue=e=>{for(let n of e){let e=t.At(n);if(e)throw e}},We,Ge=e=>{_.distinctStates=O.length+1,x=Math.max(x,e),_.diameter=Math.max(_.diameter,e)},Ke=(e,t,n,r)=>{let i=n===-1?1:Re[n]+1;O.push(e),Ie.push(t),k.push(n),Le.push(r),Re.push(i)},N={index:-1,isExpanding:!1,candidate:void 0,candidateLevel:0,livenessSource:-1,rebuilt:void 0},qe=d({config:i,options:n,environment:g,search:E,nextActions:ye,current:N,states:O,fingerprintStates:Ie,parents:k,actions:Le,depths:Re,tracedSteps:ue,captureOutput:f,getInitialStates:Ve,findSuccessorAction:(e,n)=>h?Se.find(t=>Oe(t,e).some(n)):ye.find(r=>t.nt(r.expression,e,g,r.scope).some(n))}),Je=e=>e===-1?[]:[...Je(k[e]),O[e]];_.isSeen=e=>{let n=ve(e);return t.B(ze,t.V(n),n)!==-1},_.getBehavior=e=>{let t=e===N.candidate?-1:O.indexOf(e);return t===-1?[...Je(N.index),e]:Je(t)},_.getCurrentState=()=>N.index===-1?void 0:O[N.index],_.setLivenessSource=e=>{N.livenessSource=e??-1},_.getLevel=e=>{let t=N.livenessSource;if(v){let e=t===-1?N.isExpanding?N.index:-1:t;return e===-1?0:Re[e]}let n=N.rebuilt;return n?e===n.state?n.level:n.level+1:t===-1?e===N.candidate?N.candidateLevel:N.index===-1?0:e===O[N.index]?Re[N.index]:N.isExpanding?Re[N.index]+1:0:e===O[t]?Re[t]:Re[t]+1};let Ye=e=>({name:e.name,signature:t.w(e)}),Xe=(e,r)=>({fingerprint:BigInt.asIntN(64,_.getFingerprint(e)),level:r,getLabel:()=>t.Ot(i.alias===void 0?A(e):E.evaluateAlias(i.alias,e,void 0,n.isTool??!1)),getText:()=>t.Ot(A(e))}),Ze=e=>{Be(e),_.generatedStates++,_.initialStates++,N.candidate=e,N.candidateLevel=1;let i=ve(e),a=t.V(i),o=E.satisfiesConstraints(e);if(o&&(E.trackStatePossible(e),Ue(i),e.forEach(t.It)),o&&t.B(ze,a,i)!==-1)return;We=o?i:void 0,o&&(Ge(1),_.queueSize++,D?.addInitialState(O.length,e),r?.writeInitialState(Xe(e,1))),n.isContinued&&E.getViolatedInvariants(e).forEach(t=>ge(`invariant-violation`,{name:t.name,...qe.toTrace([{action:void 0,state:e}],[])}));let s=n.isContinued?void 0:E.findViolatedInvariant(e);if(s)return me(`invariant-violation`,{name:s.name,...qe.toTrace([{action:void 0,state:e}],[])});let c=E.findFailedInitialPredicate(e);if(c)return me(`liveness-violation`,{name:c.name,...qe.toTrace([{action:void 0,state:e}],[])});o&&(t.K(ze,a,O.length),Ke(e,i,-1,void 0))},Qe=(i,a,o,s,c)=>{let l=O[i];_.generatedStates++,N.candidate=a.state,N.candidateLevel=Re[i]+1,Fe&&Be(a.state);let u=ve(a.state),d=t.V(u),p=t.B(ze,d,u),m=E.satisfiesConstraints(a.state,l);m&&E.trackStatePossible(a.state);let g=m&&E.satisfiesActionConstraints(l,a.state);g&&(E.trackActionPossible(l,a.state),Ue(u),a.state.forEach(t.It));let v=g?p:-1;if(s&&g&&r?.writeSuccessor(s,Xe(a.state,Re[i]+1),v!==-1,c&&Ye(c)),s&&!g&&n.dump?.constrained){let e=Xe(a.state,Re[i]+1);E.getExcludingConstraints(l,a.state).forEach(t=>r?.writeConstrained(s,e,c&&Ye(c),t))}if(v!==-1&&D){let e=O[v],t=e.every((e,t)=>e===a.state[t]);o.push({index:v,state:t?e:a.state})}let y=g&&v===-1;if(y&&D&&o.push({index:O.length,state:a.state}),We=y?u:void 0,y&&(Ge(Re[i]+1),ee++,h&&h.secondary[et]++),v===-1)try{let e=E.findViolatedInvariant(a.state,l),t=e&&{name:e.name,...qe.getTrace(i,a)};if(t&&!n.isContinued)return oe(me(`invariant-violation`,t));t&&ge(`invariant-violation`,t)}catch(t){if(e.tt(t))throw t;let n=f(()=>Ne(i));return M(t,Te(qe.getFailedTrace(i,a),n.lines),n.result??{outDegrees:ie()})}let b=E.findViolatedActionProperty(l,a.state),x=b&&{name:b.name,...qe.getTrace(i,a)};if(x&&!n.isContinued)return oe(me(`liveness-violation`,x));x&&ge(`liveness-violation`,x),y&&(h&&t.yt(h,a.state),Fe||Be(a.state),t.K(ze,d,O.length),Ke(a.state,u,i,a.action),_.queueSize++)},$e,et=-1;D&&n.onProgress?.({kind:`liveness-prepared`,branches:D.branches});let tt=ce();if(tt)return w(`assumption-violation`,tt);if(n.onProgress?.({kind:`initial-states-started`}),_e.init!==void 0){let r,i=(e,t)=>{let n=f(Me);return M(e,{trace:[],traceOutput:n.lines},{initialState:t,...n.result,phase:`initial`})};try{let a=a=>{if(t.h(_.initialStates,n.onProgress),r)return _.generatedStates++,_.initialStates++,!1;try{$e=Ze(a)}catch(t){e.tt(t)?r=a:$e=i(t,a)}return $e!==void 0};if(h)try{t.at(xe,g,e=>{if(a(e))throw De},ke)}catch(e){if(e!==De)throw e}else t.$(_e.init,g,a,_e.scope);r&&($e=i(e.Y(),r))}catch(n){if(n instanceof e.S){let e=M(n,{trace:[]},{initialState:n.state.map(e=>e??t.Et(`null`))});return{...e,failure:e.failure&&{...e.failure,isWithoutStatistics:!0}}}let r=f(Me);return M(n,{trace:[],traceOutput:r.lines},{...r.result,phase:`initial`})}}if($e)return $e;S={generated:_.initialStates,distinct:_.distinctStates},n.onProgress?.({kind:`initial-states-computed`,initialStates:S});let nt=_e.next;if(nt===void 0){if(O.length>0)throw new e.b(`No next state actions defined to generate successor states from.`);return se()}let rt=!!(n.dump?.dot&&(n.dump.actionLabels||n.dump.colorize)),it=(e,n,r)=>{if(h){let t=0;try{Se.forEach(n=>{et=n.node,Ce(n,e,e=>{if(t++,r({state:e,action:n.name},n))throw De})})}catch(e){if(e!==De)throw e}return t}if(!rt)return t.et(nt,e,g,e=>r(e,void 0),_e.scope,void 0,n);let i=!1;return ye.reduce((a,o)=>i?a:a+t.et(o.expression,e,g,e=>(i=r(e,o),i),o.scope,void 0,n&&((e,t)=>n(e,t,o))),0)},at=(e,t)=>{if(!D||v)return;let n=o(g,n=>D.addState(e,O[e],t,n));return n?.callStack.length&&!n.fingerprint?n.callStack:void 0},ot=(t,n)=>{try{D?.addState(t,O[t],n);return}catch(r){if(!(r instanceof e.b))throw r;return at(t,n)}},st=(e,t)=>{let n=f(()=>ot(e,t));if(n.result)return{result:{phase:`behavior-graph`,callStack:n.result},lines:n.lines};let r=f(()=>Ne(e));return{result:r.result,lines:[...n.lines,...r.lines]}},P=t=>M(e.Y(),qe.getStateTrace(t),{phase:`next`}),ct=(n,r,i)=>{if(e.tt(n))return P(r);let a=st(r,i);return M(t._(n),Te(qe.getStateTrace(r),a.lines),{phase:`next`,...a.result})},lt=(a,s)=>{let c=O[a],l=r&&Xe(c,Re[a]),u=l&&n.dump?.constrained?(e,n,i)=>r?.writeConstrained(l,Xe(e,Re[a]+1),i&&Ye(i),t.Y(n)):void 0,d=it(c,u,(n,r)=>{try{$e=Qe(a,n,s,l,r)}catch(r){if(e.tt(r))return $e=P(a),!0;let i=v?f(()=>Ne(a)):st(a,s);if(v&&r instanceof e.b&&!t.Jt(r))return $e=M(new e.b(`${t.Kt(r)}${r.message}`,r),Te({trace:[]},i.lines),{phase:`next`,...i.result}),!0;let o=j(n.state)&&r instanceof e.b?t.Gt(t.qt(r)?new e.b(`${e.W}${r.message}`):r,!0):void 0;$e=M(r,Te(o?qe.getStateTrace(a):qe.getFailedTrace(a,n),i.lines),{phase:`next`,...i.result,traceFailure:o})}return $e!==void 0});N.isExpanding=!1;let p=$e;if(p?.violation&&!v){let e=f(()=>ot(a,s));return{...p,violation:Te(p.violation,e.lines),...e.result&&{liveCallStack:e.result}}}if(p)return p;let m=()=>{D&&l&&(v||n.dump?.stuttering)&&r?.writeStuttering(l);let e=D?.addState(a,c,s);if(!D||!e)return;let t=qe.getPathSteps(e),i=ae(D,t.map(e=>e.state),t.length-1);return me(`property-violation`,{name:i[0],properties:i,...qe.toTrace(t,e,{known:0})})};if(d===0&&i.checkDeadlock){let t=me(`deadlock`,{name:`deadlock`,...qe.getStateTrace(a)}),n=f(()=>{try{return{additional:m()?.violation}}catch(t){if(!(t instanceof e.b))throw t;return{isFailed:!0,callStack:at(a,s)}}}),r=t.violation?{...t,violation:Te(t.violation,n.lines)}:t,i=oe(r,n.result.isFailed?ie():re());return n.result.additional?{...i,additionalViolation:n.result.additional}:n.result.callStack?{...i,liveCallStack:n.result.callStack}:i}try{return m()}catch(n){if(v&&n instanceof e.b){let r=new e.b(`${t.qt(n)?e.W:e.G}${n.message}`);return M(e.at(r,e.nt.error),{trace:[]},{outDegrees:ie()})}let r=o(g,e=>D?.addState(a,c,s,e));return M(n,qe.getStateTrace(a),{outDegrees:ie(),callStack:r?.callStack.length?r.callStack:void 0,phase:`liveness`})}},ut=()=>{let n=i.specification,r=`(compare Chapter 8, page 87ff of Specifying Systems at https://lamport.azurewebsites.net/tla/book.html).`;if(n===void 0)return{code:t.Lt.noSpecificationButProperty,text:`The stuttering counterexample above may be caused by the absence of a behavior specification (SPECIFICATION). Only INIT and NEXT have been provided, so TLC permits infinite stuttering. To rule out such counterexamples, use SPECIFICATION Spec, with Spec asserting a suitable fairness constraint ${r}`};let a=t.X(n,g)?.location.range;if(!(_e.temporals.length>0||!a))return{code:t.Lt.noFairnessButProperty,text:`The stuttering counterexample above may be caused by the absence of a fairness constraint in the behavior specification ${n} defined at ${e.X(a)}. To rule out such counterexamples, conjoin a suitable fairness constraint to ${n} ${r}`}},dt=(e,r)=>{let i=[...r.prefix,...r.cycle],a=r.prefix.length,o=qe.getPathSteps(i,a),s=qe.toTrace(o,i,{loopStart:a,known:0}).trace,c=ae(e,o.map(e=>e.state),a),l=i[a],u=i[i.length-1],d=o[o.length-1].state,p=l===u?{result:void 0,lines:[]}:f(()=>qe.findStepAction(u,d,O[l],!1)),m=l===u&&r.isCycleConstrained;return me(`liveness-violation`,{name:c[0],properties:c,trace:s,traceOutput:p.lines,loopStart:a,loopLabel:p.result&&t.C(p.result,n.version),warning:m?ut():void 0},()=>l===u?fe(s[s.length-1]):p.result?t.D(p.result):t.ft(qe.findSuccessorWithFingerprint(d,l)?.action))},ft=D!==void 0&&(n.livenessCheck??`default`)==="default",pt=performance.now(),mt={at:pt+3e3,size:1,time:0,coverageCount:Math.trunc(n.coverage??0)},ht=e=>{let t=performance.now();if(!((e-mt.size)/mt.size>.1)||mt.time>(t-pt)*.2||(mt.size=e,!D))return;n.onProgress?.({kind:`liveness-started`,branches:D.branches,isComplete:!1,states:e,statistics:w(`success`)});let r=D.findViolation();return r||n.onProgress?.({kind:`liveness-finished`}),mt.time+=performance.now()-t,r};for(let t=0;t<O.length&&!_.isStopped;t++){N.index=t,N.candidate=void 0,_.queueSize=O.length-t-1,N.isExpanding=!0;let r=[];try{$e=lt(t,r)}catch(n){$e=n instanceof e.C?He(t,n):ct(n,t,r)}if($e)return $e;if(T[ne()]++,ee=0,(ft||n.onProgress)&&performance.now()>=mt.at){mt.at=performance.now()+6e4;let e=ft?ht(t+1):void 0;if(D&&e)return dt(D,e);let r=n.coverage!==void 0&&mt.coverageCount===0;mt.coverageCount=r?Math.trunc(n.coverage??0):mt.coverageCount-1;let i=w(`success`);n.onProgress?.({kind:`progress`,statistics:{...i,coverage:r?i.coverage:void 0}})}}N.index=-1,N.candidate=void 0;let gt=n.livenessCheck===`off`?void 0:D;gt&&n.onProgress?.({kind:`liveness-started`,branches:gt.branches,isComplete:!0,states:_.distinctStates,statistics:w(`success`)});let _t=gt?.findViolation();if(gt&&_t)return dt(gt,_t);gt&&n.onProgress?.({kind:`liveness-finished`});let F=m.moduleOperators.find(e=>e.kind===`postcondition`&&e.key===void 0);if(F)return M(t.l(F),{trace:[]});let I=E.findPostconditionViolation();return I?w(`postcondition-violation`,{name:I.name,message:I.message,counts:I.counts,trace:[],postcondition:I}):he?w(he):se()},Ae=async n=>{let r=typeof n.config==`string`?t.$t(n.config,n.version):n.config,i=n.onPrint??console.log,a=0,o=e=>[e.kind,`name`in e?e.name:``,`count`in e?e.count:``,`text`in e?e.text:``].join(` `),s=/* @__PURE__ */ new Set,c=e=>{s.add(o(e)),n.onProgress?.(e)},l=e=>{e!==void 0&&n.onProgress?.({kind:`sequential-fallback`,string:e});let t=a;return Oe({...n,config:r,onPrint:e=>t-->0?void 0:i(e),onProgress:e=>{s.has(o(e))||n.onProgress?.(e)}})},u=n.workers??1;if(u<2||typeof SharedArrayBuffer!=`function`||n.dump!==void 0||n.coverage!==void 0||n.isContinued===!0||r.view!==void 0||r.postconditions.length>0||r.possible.length>0||(n.moduleOperators?.length??0)>0)return l();let d=/* @__PURE__ */ new Map,f=e=>{let t=n.loadModule?.(e);return d.set(e,t),t},p=/* @__PURE__ */ new Map,m=e=>{let t=n.loadClass?.(e);return p.set(e,t),t},h=t.c(r,{...n,loadModule:f,loadClass:m,seed:void 0,moduleOperators:void 0},e=>{a++,i(e)},!0),g=h.specification;t.g(g,r,c);let _=g.environment,v=t.u(r,_,g.variableLocations,()=>h.order.getDeclarationOrder(`variable`),c);if(t.d(g.assumptions,_)||!v||v.spec.init===void 0||v.spec.next===void 0||v.properties.liveness.length>0||t.Q(_))return l();let y=t.Tt(),b=t.R(),x=/* @__PURE__ */ new Int32Array(2),S=Array.from({length:u},t.n),C={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,initialStates:void 0,outDegrees:Array.from({length:32},()=>0)},w=[],T=()=>({status:`success`,violation:void 0,failure:void 0,...C,fingerprintDistance:t.a(C.distinctStates,C.generatedStates,()=>{let e=new BigInt64Array(C.distinctStates);return w.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),ee=e=>{let n=[];for(let r of t.tt(e,_,v.spec.scope))if(t.h(C.generatedStates,c),y(r),C.generatedStates++,t.q(v.getFingerprintState(r),x),t.G(b)&&(b=t.H(b)),t.U(b,x[0],x[1])){if(v.findViolatedInvariant(r)||v.findFailedInitialPredicate(r))return!1;if(v.satisfiesConstraints(r)){if(!S[n.length%u].encode(r))return!1;n.push(r),C.distinctStates++}}return w.push(BigInt64Array.from(n,e=>_.runtime.getFingerprint(e))),!0};c({kind:`initial-states-started`});try{if(!ee(v.spec.init))return l()}catch(t){if(!(t instanceof e.b))throw t;return l()}let te=t.Pt();if(te!==void 0)return l(te);if(C.depth=C.generatedStates===0?0:1,C.initialStates={generated:C.generatedStates,distinct:C.distinctStates},c({kind:`initial-states-computed`,initialStates:C.initialStates}),C.distinctStates===0)return T();let ne=[],re=u,ie=e=>{},ae=e=>{ne.push(e),(e.type===`abort`||ne.length===re)&&ie(ne.splice(0))},oe=e=>new Promise(t=>{re=e,ie=t}),se=oe(u),E=new Int32Array(new SharedArrayBuffer(u*4)),ce=new Int32Array(new SharedArrayBuffer(u*4)),le=await Promise.all(Array.from({length:u},()=>e.i(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href),e=>ae(e),()=>ae({type:`abort`})))),ue=()=>le.forEach(e=>e.terminate()),de=/* @__PURE__ */ new Map,fe=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=de.get(n)??new MessageChannel;return de.set(n,r),e<t?r.port1:r.port2};le.forEach((e,t)=>{let i=Array.from({length:u},(e,n)=>n===t?void 0:fe(t,n)),a=S[t].finish(),o={type:`start`,source:n.source,config:r,modules:[...d],classes:[...p],index:t,ports:i,seed:a,isTool:n.isTool,traceSpec:n.traceSpec,isWarningEnabled:n.isWarningEnabled,version:n.version,fingerprintPolynomial:n.fingerprintPolynomial,maxSetSize:n.maxSetSize,isLazyValueExpanded:n.isLazyValueExpanded,fingerprints:b,requests:E,remaining:ce};e.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let pe=e=>e.some(e=>e.type===`abort`),me=e=>le.forEach(t=>t.postMessage(e)),he=async e=>{let n=e.filter(e=>e.type===`paused`).length;if(n===0||pe(e))return e;b=t.H(b);let r=oe(n);return me({type:`resize`,fingerprints:b}),[...e.filter(e=>e.type!==`paused`),...await he(await r)]};if(pe(await se))return ue(),l();for(;;){let e=oe(u);E.forEach((e,t)=>Atomics.store(E,t,0)),me({type:`level`});let t=await he(await e);if(pe(t)){ue();let e=t.find(e=>e.type===`abort`&&e.string!==void 0);return l(e?.type===`abort`?e.string:void 0)}let n=t.flatMap(e=>e.type===`level`?[e]:[]),r=n.reduce((e,t)=>e+t.added,0);if(C.generatedStates+=n.reduce((e,t)=>e+t.generated,0),C.distinctStates+=r,n.forEach(e=>{e.outDegrees.forEach((e,t)=>C.outDegrees[t]+=e),w.push(e.fingerprints)}),r===0)return ue(),T();C.depth++}},je=e=>{let t=e.endColumn-1;return e.startLine===e.endLine?e.startColumn>=t?`line ${e.startLine}, character ${e.startColumn}`:`line ${e.startLine}, characters ${e.startColumn}-${t}`:`line ${e.startLine}, character ${e.startColumn} to line ${e.endLine}, character ${t}`},Me=e=>`File ${JSON.stringify(e.file)}, ${je(e)}`,Ne=e=>e?Me(e):`<unknown location>`,Pe=e=>`${Ne(e)}:\n`,D=(e,t)=>({text:`${Pe(e)}Error: ${t}`,channel:`stderr`}),Fe=(e,t)=>({text:t,channel:`error`,locus:e}),O=(e,t,n)=>{e(D(t,n)),e(Fe(t,n))},Ie=e=>e?`${Me(e)} :\n`:``,k=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},Le={kind:`At`,isExcept:!1},Re=e=>k({kind:`Internal`,builtin:`TRUE`},e),ze=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},Be=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t,A=(e,t,n)=>k({kind:`Apply`,operator:k({kind:`Internal`,builtin:e},n),args:t},n),Ve=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},j=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),M=(e,t)=>t.reduce(j,e),He=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},Ue=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(ze(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},We=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},Ge=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},Ke=(e,t)=>{let n={state:e,hyp:void 0,parent:void 0,next:/* @__PURE__ */ new WeakMap};return(e,r=e)=>{let i=e.reduce((e,n,i)=>{let a=e.next.get(n);if(a)return a;let[o,s]=t(e.state,r[i],n),c={state:o,hyp:s,parent:e,next:/* @__PURE__ */ new WeakMap};return e.next.set(n,c),c},n),a=[];for(let e=i;e;e=e.parent)e.hyp&&a.push(e.hyp);return{state:i.state,context:a.reverse()}}},N=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),qe=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),Je=(e,t,n,r)=>({kind:`Fact`,expression:e,visibility:t,time:n,location:r}),Ye=(e,t,n,r,i)=>({kind:`Defn`,definition:e,whereDefined:t,visibility:n,isLocal:r,location:i}),Xe=e=>N(e.name,e.level),Ze=e=>N(e.name,`Unknown`,e.shape),Qe=e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),$e=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},et=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),tt=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,nt=(e,t)=>e.map(e=>{let n=t(e.value);return{trail:e.trail.map(e=>e.kind===`Apply`?{kind:`Apply`,expression:t(e.expression)}:e),value:n}}),rt=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,it=(e,t,n)=>e.kind===`Fresh`?e.domain?{...e,domain:t(e.domain)}:e:e.kind===`Flex`||n===`visible`&&e.visibility===`Hidden`?e:e.kind===`Defn`?{...e,definition:rt(e.definition,t)}:{...e,expression:t(e.expression)},at=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,Xe(t)),e);switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Lambda`:{let i=t.params.reduce((e,t)=>{let n=Ze(t);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=Ge(e,t.sequent.context,(e,t)=>{let a=it(t,t=>n(e,t),i);return[r(e,a),a]});return{...t,sequent:{context:o,active:n(a,t.sequent.active)}}}case`Let`:{let[i,a]=Ge(e,t.definitions,(e,t)=>{let i=rt(t,t=>n(e,t));return[r(e,Qe(i)),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=et(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=et(t.bounds,a);return{...t,bounds:e,element:n(o(e),t.element)}}case`Tquant`:{let i=t.names.reduce((e,t)=>r(e,{kind:`Flex`,name:t}),e);return{...t,body:n(i,t.body)}}case`Choose`:{let i=t.domain&&a(t.domain),o=i?qe(t.name,i):N(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=qe(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>tt(e,a));return{...t,expression:a(t.expression),selectors:e}}case`Apply`:{let e=t.args.map(a);return{...t,operator:a(t.operator),args:e}}case`With`:case`Dot`:case`Parens`:return{...t,expression:a(t.expression)};case`If`:{let e=a(t.alternative),n=a(t.consequent);return{...t,condition:a(t.condition),consequent:n,alternative:e}}case`List`:return{...t,items:t.items.map(a)};case`SetEnum`:case`Tuple`:return{...t,elements:t.elements.map(a)};case`Product`:return{...t,factors:t.factors.map(a)};case`FcnApp`:{let e=t.args.map(a);return{...t,function:a(t.function),args:e}}case`Arrow`:{let e=a(t.range);return{...t,domain:a(t.domain),range:e}}case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:a(e.value)}))};case`Except`:{let e=nt(t.specs,a);return{...t,function:a(t.function),specs:e}}case`Sub`:case`Tsub`:case`Fair`:return{...t,subscript:a(t.subscript),action:a(t.action)};case`Case`:{let e=t.other&&a(t.other),n=t.arms.map(e=>{let t=a(e.body);return{condition:a(e.condition),body:t}});return{...t,arms:n,other:e}}}},ot=(e,t,n=`all`)=>at(void 0,e,(e,n)=>t(n),()=>void 0,n),st=e=>{let t=[];return ot(e,e=>(t.push(e),e)),t},P=e=>({kind:`Shift`,amount:e}),ct=(e,t)=>({kind:`Cons`,expression:e,rest:t}),lt=(e,t)=>e.reduce((e,t)=>ct(t,e),t),ut=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},dt=(e,t,n)=>{switch(e.kind){case`Shift`:return k({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?k($e(e.expression),n):dt(e.rest,t-1,n);case`Compose`:return F(e.outer,dt(e.inner,t,n));case`Bump`:return t<=e.amount?k({kind:`Ix`,index:t},n):F(P(e.amount),dt(e.rest,t-e.amount,n))}},ft=(e,t)=>t.map(t=>F(e,t)),pt=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e.A(`Arity mismatch`);return $e(F(lt(n,P(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?$e(t):{kind:`Apply`,operator:t,args:n}},mt=(e,t)=>[ut(t.length,e),et(t,t=>F(e,t))],ht=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return rt(t,t=>F(e,t));case`Instance`:{let n=ut(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({...e,expression:F(n,e.expression)}))}}}}},gt=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:F(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ht(e,t.definition)};case`Fact`:return{...t,expression:F(e,t.expression)}}},_t=(e,t)=>{let[n,r]=Ge(e,t.context,(e,t)=>[ut(1,e),gt(e,t)]);return{context:r,active:F(n,t.active)}},F=(e,t)=>{let n=t=>F(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return dt(e,t.index,t);case`Apply`:return k(pt(n(t.operator),ft(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>tt(e,n))};case`Lambda`:return{...t,body:F(ut(t.params.length,e),t.body)};case`Let`:{let[n,r]=Ge(e,t.definitions,(e,t)=>[ut(1,e),ht(e,t)]);return{...t,definitions:r,body:F(n,t.body)}}case`Sequent`:return{...t,sequent:_t(e,t.sequent)};case`With`:case`Dot`:case`Parens`:return{...t,expression:n(t.expression)};case`If`:return{...t,condition:n(t.condition),consequent:n(t.consequent),alternative:n(t.alternative)};case`List`:return{...t,items:ft(e,t.items)};case`Quant`:case`Fcn`:{let[n,r]=mt(e,t.bounds);return{...t,bounds:r,body:F(n,t.body)}}case`Tquant`:return{...t,body:F(ut(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:F(ut(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:F(ut(1,e),t.body)};case`SetOf`:{let[n,r]=mt(e,t.bounds);return{...t,bounds:r,element:F(n,t.element)}}case`SetEnum`:case`Tuple`:return{...t,elements:ft(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`FcnApp`:return{...t,function:n(t.function),args:ft(e,t.args)};case`Product`:return{...t,factors:ft(e,t.factors)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:nt(t.specs,n)};case`Sub`:case`Tsub`:case`Fair`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)}}},I=(e,t)=>e===0?t:F(P(e),t),vt=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),yt=(e,t)=>e&&t?L(e,t):!e&&!t,bt=(e,t)=>{let n=new Map(e.map(e=>[e.name,e.value])),r=new Map(t.map(e=>[e.name,e.value]));if(n.size!==r.size)return!1;for(let[e,t]of n){let n=r.get(e);if(!n||!L(t,n))return!1}return!0},xt=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&L(e.domain.expression,t.domain.expression)),St=(e,t)=>{if(e.kind!==t.kind)return!1;switch(e.kind){case`Number`:return t.kind===`Number`&&e.value===t.value;case`Instance`:return t.kind===`Instance`&&vt(e.args,t.args,L);case`Label`:return t.kind===`Label`&&e.label===t.label&&vt(e.args,t.args,L);default:return!0}},Ct=(e,t)=>{if((e.kind===`Operator`||e.kind===`Bpragma`)&&t.kind===e.kind)return L(e.body,t.body);if(e.kind===`Instance`&&t.kind===`Instance`){let n=e.instance.substitutions.map(e=>({name:e.name,value:e.expression})),r=t.instance.substitutions.map(e=>({name:e.name,value:e.expression}));return vt(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&bt(n,r)}return!1},wt=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level===t.level&&e.shape===t.shape&&yt(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?Ct(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&L(e.expression,t.expression),Tt=(e,t)=>vt(e.context,t.context,wt)&&L(e.active,t.active),L=(e,t)=>{if(e.kind===`Parens`)return L(e.expression,t);if(t.kind===`Parens`)return L(e,t.expression);switch(e.kind){case`Ix`:return t.kind===`Ix`&&e.index===t.index;case`Opaque`:return t.kind===`Opaque`&&e.name===t.name;case`Internal`:return t.kind===`Internal`&&e.builtin===t.builtin;case`Lambda`:return t.kind===`Lambda`&&e.params.length===t.params.length&&L(e.body,t.body);case`Apply`:return t.kind===`Apply`&&L(e.operator,t.operator)&&vt(e.args,t.args,L);case`Sequent`:return t.kind===`Sequent`&&Tt(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&L(e.expression,t.expression)&&vt(e.selectors,t.selectors,St);case`With`:return t.kind===`With`&&L(e.expression,t.expression);case`Let`:return t.kind===`Let`&&vt(e.definitions,t.definitions,Ct)&&L(e.body,t.body);case`If`:return t.kind===`If`&&L(e.condition,t.condition)&&L(e.consequent,t.consequent)&&L(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&vt(e.items,t.items,L);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&vt(e.bounds,t.bounds,xt)&&L(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&vt(e.names,t.names,(e,t)=>e===t)&&L(e.body,t.body);case`Choose`:return t.kind===`Choose`&&yt(e.domain,t.domain)&&L(e.body,t.body);case`SetSt`:return t.kind===`SetSt`&&L(e.domain,t.domain)&&L(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&L(e.element,t.element)&&vt(e.bounds,t.bounds,xt);case`SetEnum`:case`Tuple`:return t.kind===e.kind&&vt(e.elements,t.elements,L);case`Arrow`:return t.kind===`Arrow`&&L(e.domain,t.domain)&&L(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&vt(e.bounds,t.bounds,xt)&&L(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&vt([e.function,...e.args],[t.function,...t.args],L);case`Product`:return t.kind===`Product`&&vt(e.factors,t.factors,L);case`Rect`:case`Record`:return t.kind===e.kind&&bt(e.fields,t.fields);case`Except`:return t.kind===`Except`&&L(e.function,t.function)&&vt(e.specs,t.specs,(e,t)=>vt(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&L(e.expression,t.expression))&&L(e.value,t.value));case`Dot`:return t.kind===`Dot`&&L(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&L(e.action,t.action)&&L(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&L(e.subscript,t.subscript)&&L(e.action,t.action);case`Case`:return t.kind===`Case`&&(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:L(e.arms[0].condition,t.arms[0].condition)&&L(e.arms[0].body,t.arms[0].body))&&yt(e.other,t.other);case`String`:return t.kind===`String`&&e.value===t.value;case`Num`:return t.kind===`Num`&&e.integer===t.integer&&e.fraction===t.fraction;case`At`:return t.kind===`At`&&e.isExcept===t.isExcept}},Et=1000000010,Dt=new TextEncoder,Ot=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return Dt.encode(e).length;return e.length},kt=()=>({leftTotal:-1,element:{size:-1,token:{kind:`Text`,text:``},length:0}}),At=e=>{let t={size:-1,token:{kind:`Begin`,indent:0,box:`hov`},length:0};return{queue:[t],queueStart:0,scanStack:[kt(),{leftTotal:1,element:t}],formatStack:[],margin:78,maxIndent:e,spaceLeft:78,currentIndent:0,isNewLine:!0,leftTotal:1,rightTotal:1,depth:1,output:[]}},jt=(e,t)=>{e.rightTotal+=t.length,e.queue.push(t)},Mt=(e,t,n)=>{e.output.push(`
100
+ `),e.isNewLine=!0,e.currentIndent=Math.min(e.maxIndent,e.margin-n+t),e.spaceLeft=e.margin-e.currentIndent,e.output.push(` `.repeat(e.currentIndent))},Nt=(e,t)=>{e.spaceLeft-=t,e.output.push(` `.repeat(t))},Pt=e=>{let t=e.formatStack.at(-1);t?t.width>e.spaceLeft&&t.box!==`fits`&&t.box!==`h`&&Mt(e,0,t.width):e.output.push(`
101
+ `)},Ft=(e,t,n)=>{switch(n.kind){case`Text`:e.spaceLeft-=t,e.output.push(n.text),e.isNewLine=!1;return;case`Begin`:{e.margin-e.spaceLeft>e.maxIndent&&Pt(e);let r=e.spaceLeft-n.indent,i=n.box===`v`||t>e.spaceLeft?n.box:`fits`;e.formatStack.push({box:i,width:r});return}case`End`:e.formatStack.pop();return;case`Newline`:{let t=e.formatStack.at(-1);t?Mt(e,0,t.width):e.output.push(`
102
+ `);return}case`Break`:{let r=e.formatStack.at(-1);if(!r)return;let i=r.width;switch(r.box){case`hov`:t>e.spaceLeft?Mt(e,n.offset,i):Nt(e,n.width);return;case`b`:e.isNewLine?Nt(e,n.width):t>e.spaceLeft||e.currentIndent>e.margin-i+n.offset?Mt(e,n.offset,i):Nt(e,n.width);return;case`hv`:case`v`:Mt(e,n.offset,i);return;case`fits`:case`h`:Nt(e,n.width);return}}}},It=e=>{for(;e.queueStart<e.queue.length;){let t=e.queue[e.queueStart],n=t.size>=0;if(!n&&e.rightTotal-e.leftTotal<e.spaceLeft)return;e.queueStart++,Ft(e,n?t.size:Et,t.token),e.leftTotal+=t.length}e.queue.length=0,e.queueStart=0},Lt=(e,t)=>{jt(e,t),It(e)},Rt=(e,t)=>{let n=e.scanStack.at(-1);n&&(n.leftTotal<e.leftTotal?e.scanStack=[kt()]:n.element.token.kind===(t?`Break`:`Begin`)&&(n.element.size=e.rightTotal+n.element.size,e.scanStack.pop()))},zt=(e,t,n)=>{jt(e,n),t&&Rt(e,!0),e.scanStack.push({leftTotal:e.rightTotal,element:n})},Bt=(e,t,n)=>{e.depth++,zt(e,!1,{size:-e.rightTotal,token:{kind:`Begin`,indent:n,box:t},length:0})},Vt=e=>{e.depth<=1||(jt(e,{size:0,token:{kind:`End`},length:0}),Rt(e,!0),Rt(e,!1),e.depth--)},Ht=(e,t,n)=>Lt(e,{size:t,token:{kind:`Text`,text:n},length:t}),Ut=(e,t,n)=>zt(e,!0,{size:-e.rightTotal,token:{kind:`Break`,width:t,offset:n},length:t}),Wt=e=>Lt(e,{size:0,token:{kind:`Newline`},length:0}),Gt=e=>{for(;e.depth>1;)Vt(e);return e.rightTotal=Et,It(e),e.output.join(``)},Kt=e=>{Gt(e);let t=[...e.output,`
103
+ `];Object.assign(e,At(e.maxIndent)),e.output=t},qt={h:`h`,v:`v`,hv:`hv`,hov:`hov`,b:`b`},Jt=e=>({kind:`Text`,text:e,size:Ot(e)}),R=e=>e===``?[]:[Jt(e)],Yt={kind:`Break`,width:1,offset:0},Xt={kind:`Break`,width:0,offset:0},Zt=e=>{let t=e.search(/\d|$/);return{kind:`Open`,box:qt[e.slice(0,t)],indent:Number(e.slice(t)||0)}},z=(e,...t)=>{let n=[],r=0,i=``,a=()=>{i!==``&&(n.push(Jt(i)),i=``)};for(let o=0;o<e.length;o++){let s=e[o];if(s===`%`){a();let e=t[r++];typeof e==`string`?e!==``&&n.push(Jt(e)):n.push(e),o++}else if(s!==`@`)i+=s;else switch(a(),e[o+1]){case`[`:{if(e[o+2]!==`<`){n.push({kind:`Open`,box:`b`,indent:0}),o++;break}let t=e.indexOf(`>`,o);n.push(Zt(e.slice(o+3,t))),o=t;break}case`]`:n.push({kind:`Close`}),o++;break;case` `:n.push(Yt),o++;break;case`,`:n.push(Xt),o++;break;case`
104
+ `:n.push({kind:`Newline`}),o++;break;case`.`:n.push({kind:`Flush`}),o++;break;case`;`:{let t=e.indexOf(`>`,o),r=e.slice(o+3,t).split(` `);n.push({kind:`Break`,width:Number(r[0]),offset:Number(r[1])}),o=t;break}case`<`:{let i=e.indexOf(`>`,o);n.push({kind:`Text`,text:String(t[r++]),size:Number(e.slice(o+2,i))}),o=i+2;break}}}return a(),n},Qt=(e,t,n=[Jt(`,`),Yt])=>e.flatMap((e,r)=>r===0?[t(e)]:[n,t(e)]),$t=(e,t)=>{for(let n of t)if(Array.isArray(n))$t(e,n);else switch(n.kind){case`Open`:Bt(e,n.box,n.indent);break;case`Close`:Vt(e);break;case`Text`:Ht(e,n.size,n.text);break;case`Break`:Ut(e,n.width,n.offset);break;case`Newline`:Wt(e);break;case`Flush`:Kt(e)}},en=(e,t=68)=>{let n=At(t);return $t(n,e),Gt(n)},tn=[[`=>`,1,1,`InfixNon`,[]],[`<=>`,2,2,`InfixNon`,[`\\equiv`]],[`/\\`,3,3,`InfixLeft`,[`\\land`]],[`\\/`,3,3,`InfixLeft`,[`\\lor`]],[`~`,4,4,`Prefix`,[`\\neg`,`\\lnot`]],[`=`,5,5,`InfixNon`,[]],[`#`,5,5,`InfixNon`,[`/=`]],[`SUBSET`,8,8,`Prefix`,[]],[`UNION`,8,8,`Prefix`,[]],[`DOMAIN`,9,9,`Prefix`,[]],[`\\subseteq`,5,5,`InfixNon`,[]],[`\\in`,5,5,`InfixNon`,[]],[`\\notin`,5,5,`InfixNon`,[]],[`\\`,8,8,`InfixNon`,[]],[`\\cap`,8,8,`InfixLeft`,[`\\intersect`]],[`\\cup`,8,8,`InfixLeft`,[`\\union`]],[`\\X`,10,13,`Prefix`,[`\\times`]],[`'`,15,15,`Postfix`,[]],[`~>`,2,2,`InfixNon`,[`\\leadsto`]],[`ENABLED`,4,15,`Prefix`,[]],[`UNCHANGED`,4,15,`Prefix`,[]],[`\\cdot`,5,14,`InfixLeft`,[]],[`-+->`,2,2,`InfixNon`,[]],[`[]`,4,15,`Prefix`,[]],[`<>`,4,15,`Prefix`,[]],[`^`,14,14,`InfixNon`,[]],[`/`,13,13,`InfixNon`,[]],[`*`,13,13,`InfixLeft`,[]],[`-.`,12,12,`Prefix`,[`-`]],[`-`,11,11,`InfixLeft`,[]],[`+`,10,10,`InfixLeft`,[]],[`^+`,15,15,`Postfix`,[]],[`^*`,15,15,`Postfix`,[]],[`^#`,15,15,`Postfix`,[]],[`<`,5,5,`InfixNon`,[]],[`=<`,5,5,`InfixNon`,[`<=`,`\\leq`]],[`>`,5,5,`InfixNon`,[]],[`>=`,5,5,`InfixNon`,[`\\geq`]],[`...`,9,9,`InfixNon`,[]],[`..`,9,9,`InfixNon`,[]],[`|`,10,11,`InfixLeft`,[]],[`||`,10,11,`InfixLeft`,[]],[`&&`,13,13,`InfixLeft`,[]],[`&`,13,13,`InfixLeft`,[]],[`$$`,9,13,`InfixLeft`,[]],[`$`,9,13,`InfixLeft`,[]],[`??`,9,13,`InfixLeft`,[]],[`%%`,10,11,`InfixLeft`,[]],[`%`,10,11,`InfixLeft`,[`\\mod`]],[`##`,9,13,`InfixLeft`,[]],[`++`,10,10,`InfixLeft`,[]],[`--`,11,11,`InfixLeft`,[]],[`**`,13,13,`InfixLeft`,[]],[`//`,13,13,`InfixNon`,[]],[`^^`,14,14,`InfixNon`,[]],[`@@`,6,6,`InfixLeft`,[]],[`!!`,9,13,`InfixNon`,[]],[`|-`,5,5,`InfixNon`,[]],[`|=`,5,5,`InfixNon`,[]],[`-|`,5,5,`InfixNon`,[]],[`=|`,5,5,`InfixNon`,[]],[`<:`,7,7,`InfixNon`,[]],[`:>`,7,7,`InfixNon`,[]],[`:=`,5,5,`InfixNon`,[]],[`::=`,5,5,`InfixNon`,[]],[`(+)`,10,10,`InfixLeft`,[`\\oplus`]],[`(-)`,11,11,`InfixLeft`,[`\\ominus`]],[`(.)`,13,13,`InfixLeft`,[`\\odot`]],[`(/)`,13,13,`InfixNon`,[`\\oslash`]],[`(\\X)`,13,13,`InfixLeft`,[`\\otimes`]],[`\\uplus`,9,13,`InfixLeft`,[]],[`\\sqcap`,9,13,`InfixLeft`,[]],[`\\sqcup`,9,13,`InfixLeft`,[]],[`\\div`,13,13,`InfixNon`,[]],[`\\wr`,9,14,`InfixNon`,[]],[`\\star`,13,13,`InfixLeft`,[]],[`\\o`,13,13,`InfixLeft`,[`\\circ`]],[`\\bigcirc`,13,13,`InfixLeft`,[]],[`\\bullet`,13,13,`InfixLeft`,[]],[`\\prec`,5,5,`InfixNon`,[]],[`\\succ`,5,5,`InfixNon`,[]],[`\\preceq`,5,5,`InfixNon`,[]],[`\\succeq`,5,5,`InfixNon`,[]],[`\\sim`,5,5,`InfixNon`,[]],[`\\simeq`,5,5,`InfixNon`,[]],[`\\ll`,5,5,`InfixNon`,[]],[`\\gg`,5,5,`InfixNon`,[]],[`\\asymp`,5,5,`InfixNon`,[]],[`\\subset`,5,5,`InfixNon`,[]],[`\\supset`,5,5,`InfixNon`,[]],[`\\supseteq`,5,5,`InfixNon`,[]],[`\\approx`,5,5,`InfixNon`,[]],[`\\cong`,5,5,`InfixNon`,[]],[`\\sqsubset`,5,5,`InfixNon`,[]],[`\\sqsubseteq`,5,5,`InfixNon`,[]],[`\\sqsupset`,5,5,`InfixNon`,[]],[`\\sqsupseteq`,5,5,`InfixNon`,[]],[`\\doteq`,5,5,`InfixNon`,[]],[`\\propto`,5,5,`InfixNon`,[]]],nn=/* @__PURE__ */ new Map;for(let[e,t,n,r,i]of tn){let a={name:e,low:t,high:n,fixity:r};for(let t of[e,...i])nn.set(t,a)}const rn=e=>({name:e,low:-1,high:-1,fixity:`Nonfix`}),an=e=>nn.get(e)??rn(e),on={Implies:`=>`,Equiv:`<=>`,Conj:`/\\`,Disj:`\\/`,Neg:`~`,Eq:`=`,Neq:`#`,SUBSET:`SUBSET`,UNION:`UNION`,DOMAIN:`DOMAIN`,Subseteq:`\\subseteq`,Mem:`\\in`,Notmem:`\\notin`,Setminus:`\\`,Cap:`\\cap`,Cup:`\\cup`,Prime:`'`,StrongPrime:`'`,Leadsto:`~>`,ENABLED:`ENABLED`,UNCHANGED:`UNCHANGED`,Cdot:`\\cdot`,Actplus:`-+->`,BoxTrue:`[]`,BoxFalse:`[]`,Diamond:`<>`,Plus:`+`,Minus:`-`,Times:`*`,Ratio:`/`,Quotient:`\\div`,Remainder:`%`,Exp:`^`,Lteq:`=<`,Lt:`<`,Gteq:`>=`,Gt:`>`,Range:`..`,Cat:`\\o`,OneArg:`:>`,Extend:`@@`},sn=e=>{if(e===`Divides`)return{name:`?|`,low:10,high:11,fixity:`InfixNon`};if(e===`Uminus`)return{...an(`-.`),name:`-`};let t=on[e];return t?an(t):rn(e)},cn=e=>e.salt===0?e.rep:`${e.rep}_${e.salt}`,ln=()=>({stack:[],idents:/* @__PURE__ */ new Map,defined:/* @__PURE__ */ new Map}),un=(e,t)=>{let n=e.stack[e.stack.length-t];return n&&cn(n)},dn=(e,t)=>{let n=e.idents.get(t)?.at(-1),r=n?{rep:t,salt:n.salt+1}:{rep:t,salt:0};for(;e.defined.has(cn(r));)r={rep:t,salt:r.salt+1};e.stack.push(r);let i=e.idents.get(t);i?i.push(r):e.idents.set(t,[r]);let a=cn(r);return e.defined.set(a,(e.defined.get(a)??0)+1),a},fn=(e,t)=>{for(let n=0;n<t;n++){let t=e.stack.pop();if(!t)return;e.idents.get(t.rep)?.pop();let n=cn(t),r=(e.defined.get(n)??1)-1;r===0?e.defined.delete(n):e.defined.set(n,r)}},pn=(e,t,n)=>{let r=n(t.map(t=>dn(e,t)));return fn(e,t.length),r},mn=(e,t)=>t.kind===`Atm`||t.kind===`Op`&&e<t.low,hn=e=>[z(`(`),e,z(`)`)],gn=(e,t)=>t?_n(e):hn(_n(e)),_n=e=>{if(e.kind!==`Op`)return e.doc;let t=e.skeleton,n=t=>mn(e.high,t);switch(t.kind){case`Prefix`:case`Postfix`:{let r=t.operand,i=gn(r,n(r)||r.kind===`Op`&&r.skeleton.kind===t.kind),a=t.kind===`Prefix`?[e.doc,i]:[i,e.doc];return[z(`@[<h>`),...a,z(`@]`)]}case`Infix`:{let r=t.left,i=t.right,a=n(r)||r.kind===`Op`&&r.name===e.name&&t.assoc===`Left`,o=n(i)||t.assoc===`Right`&&i.kind===`Op`&&i.skeleton.kind===`Infix`&&i.skeleton.assoc===`Right`;return[z(`@[<b0>`),gn(r,a),e.doc,gn(i,o),z(`@]`)]}}},vn=e=>({kind:`Atm`,doc:e}),yn=e=>({kind:`Big`,doc:e}),bn=e=>e.kind===`Lambda`?bn(e.body):e.kind===`Sequent`?bn(e.sequent.active):e.kind===`With`,xn=(e,t)=>{if(t.isShowingHidden)return!1;if(e.kind===`Defn`){let n=e.definition,r=n.kind===`Operator`&&bn(n.body);return!t.isShowingAllDefinitions&&(e.visibility===`Hidden`||r||e.whereDefined!==`User`)}return e.kind===`Fact`?e.visibility===`Hidden`||bn(e.expression):!1},Sn=e=>e===0?[]:z(`@[<hov1>(%a)@]`,Qt(Array.from({length:e},()=>`_`),R)),Cn=e=>z(`%s%a`,e.name,Sn(e.shape)),wn={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`UNKNOWN`},Tn=(t=[],n={})=>{let r=ln(),i=e=>_n(d(e)),a=(e,t)=>pn(r,e.map(e=>e.name),()=>z(`@[<b2>LAMBDA @[<hv0>%a@] :@ %a@]`,Qt(e,Cn),i(t))),o=(e,t)=>{let n=e.map(e=>e.domain.kind===`Domain`?i(e.domain.expression):void 0);return pn(r,e.map(e=>e.name),r=>{let i=[];return e.forEach((e,t)=>{t>0&&e.domain.kind===`Ditto`?i.at(-1)?.names.push(r[t]):i.push({names:[r[t]],index:t})}),t(Qt(i,t=>{let r=Qt(t.names,R),i=e[t.index].domain;return i.kind===`NoDomain`?r:i.kind===`Ditto`?z(`@[<hov0>%a@ \\in ??????@]`,r):z(`@[<hov0>%a@ \\in %a@]`,r,n[t.index]??[])}))})},s=e=>{switch(e.kind){case`Down`:return z(`:`);case`Left`:return z(`<<`);case`Right`:return z(`>>`);case`At`:return R(`@`);case`Number`:return R(String(e.value));case`Instance`:return z(`@[<b1>(%a)@]`,Qt(e.args,i));case`Label`:return e.args.length===0?R(e.label):z(`@[<b2>%s@,@[<b1>(%a)@]@]`,e.label,Qt(e.args,i))}},c=e=>e.length===0?[]:[z(`!`),Qt(e,s,z(`!`))],l=e=>{if(e<0)return`#$$${Math.abs(e)}`;if(e===0)return`#$0`;if(e<=r.stack.length)return un(r,e);let n=t[t.length-(e-r.stack.length)];return n?ze(n)??`??? FACT ???`:`#$${e}`},u=(t,n)=>{if(t.kind===`Lambda`)return{kind:`Op`,name:` `,doc:z(`@ `),low:20,high:20,skeleton:{kind:`Infix`,assoc:`Left`,left:yn(a(t.params,t.body)),right:vn(z(`(%a)`,Qt(n,i)))}};if(t.kind===`Bang`)return n.length===0?d(t):vn(z(`@[<b2>%a@[<b1>(%a)@]@]`,i(t),Qt(n,i)));if(t.kind===`Internal`&&n.length===1){if(t.builtin===`BoxFalse`||t.builtin===`Unprimable`)return d(n[0]);if(t.builtin===`Irregular`)return vn(z(`@[<h>@<1>%s%a@<1>%s@]`,`<[`,i(n[0]),`]>`))}let r=(()=>{switch(t.kind){case`Ix`:return an(l(t.index));case`Opaque`:{let e=an(t.name);return{...e,name:`?${e.name}`}}case`Internal`:return sn(t.builtin);default:throw new e.A(`Cannot print this operator`)}})(),o=(e,t)=>({kind:`Op`,name:r.name,doc:e,low:r.low,high:r.high,skeleton:t});if(n.length===0)return vn(R(r.name));if(r.fixity===`Nonfix`)return vn(z(`@[<b2>%s@[<b1>(%a)@]@]`,r.name,Qt(n,i)));if(r.fixity===`Prefix`&&n.length===1)return o(/[A-Za-z]$/.test(r.name)?z(`%s@ `,r.name):R(r.name),{kind:`Prefix`,operand:d(n[0])});if(r.fixity===`Postfix`&&n.length===1)return o(R(r.name),{kind:`Postfix`,operand:d(n[0])});if(r.fixity.startsWith(`Infix`)&&n.length===2){let e=r.fixity===`InfixLeft`?`Left`:r.fixity===`InfixRight`?`Right`:`Non`;return o(r.name===`..`?R(r.name):z(`@ %s `,r.name),{kind:`Infix`,assoc:e,left:d(n[0]),right:d(n[1])})}throw new e.A(`Arity mismatch for operator ${r.name}`)},d=t=>{switch(t.kind){case`Ix`:case`Opaque`:case`Internal`:return u(t,[]);case`Lambda`:return yn(a(t.params,t.body));case`Bang`:return vn([i(t.expression),c(t.selectors)]);case`Apply`:return u(t.operator,t.args);case`Sequent`:return yn(m(t.sequent));case`With`:return d(t.expression);case`If`:return yn(z(`@[<hv2>@[<b2>IF@ %a@]@ @[<b2>THEN %a@]@ @[<b2>ELSE %a@]@]`,i(t.condition),i(t.consequent),i(t.alternative)));case`List`:{if(t.bullet===`Refs`&&t.items.length===0)return vn(z(`TRUE`));if(t.bullet===`Refs`&&t.items.length===1)return d(t.items[0]);let e=t.bullet===`Or`?`\\/`:`/\\`;return yn(z(`@[<v0>%a@]`,Qt(t.items,t=>z(`@[<h>%s %a@]`,e,i(t)),z(`@,`))))}case`Let`:{let e=Qt(t.definitions,f,z(`@,`)),n=i(t.body);return fn(r,t.definitions.length),yn([z(`@[<hv0>LET @[<v0>`),e,z(`@]@
105
+ IN %a@]`,n)])}case`Quant`:return o(t.bounds,e=>yn(z(`@[<b3>%s @[<b0>%a@] :@ %a@]`,t.quantifier===`Forall`?`\\A`:`\\E`,e,i(t.body))));case`Tquant`:return pn(r,t.names,e=>yn(z(`@[<b4>%s @[<b0>%a@] : %a@]`,t.quantifier===`Forall`?`\\AA`:`\\EE`,Qt(e,R),i(t.body))));case`Choose`:{let e=t.domain&&i(t.domain);return pn(r,[t.name],([n])=>yn(e?z(`@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]`,n,e,i(t.body)):z(`@[<b2>CHOOSE %s :@ %a@]`,n,i(t.body))))}case`SetSt`:{let e=i(t.domain);return pn(r,[t.name],([n])=>vn(z(`@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]`,n,e,i(t.body))))}case`SetOf`:return o(t.bounds,e=>vn(z(`@[<b3>{%a :@ %a}@]`,i(t.element),e)));case`SetEnum`:return vn(z(`@[<h>{@[<b0>%a@]}@]`,Qt(t.elements,i)));case`Arrow`:return vn(z(`@[<b3>[%a ->@ %a]@]`,i(t.domain),i(t.range)));case`Fcn`:return o(t.bounds,e=>vn(z(`@[<b3>[%a |->@ %a]@]`,e,i(t.body))));case`FcnApp`:{let e=d(t.function),n=e.kind===`Atm`;return vn(z(`@[<h>%s%a%s@[<b1>[%a]@]@]`,n?``:`(`,_n(e),n?``:`)`,Qt(t.args,i)))}case`Product`:if(t.factors.length===1)return d(t.factors[0]);if(t.factors.length===0)throw new e.A(`Expr.Fmt.fmt_expr: PRODUCT []`);return{kind:`Op`,name:`\\X`,doc:z(`@ \\X `),low:10,high:13,skeleton:{kind:`Infix`,assoc:`Right`,left:d(t.factors[0]),right:d({...t,factors:t.factors.slice(1)})}};case`Tuple`:return vn(z(`@[<b2><<%a>>@]`,Qt(t.elements,i)));case`Rect`:case`Record`:{let e=t.kind===`Rect`?`:`:`|->`;return vn(z(`@[<b1>[%a]@]`,Qt(t.fields,t=>z(`@[<h>%s ${e} %a@]`,t.name,i(t.value)))))}case`Except`:return vn(z(`@[<b3>[%a EXCEPT@ @[<v0>%a@]]@]`,i(t.function),Qt(t.specs,e=>z(`!@[<h>%a = %a@]`,e.trail.map(e=>e.kind===`Dot`?z(`.%s`,e.field):z(`[%a]`,i(e.expression))),i(e.value)))));case`Dot`:return{kind:`Op`,name:`.`,doc:z(`.`),low:16,high:16,skeleton:{kind:`Infix`,assoc:`Left`,left:d(t.expression),right:vn(R(t.field))}};case`Sub`:case`Tsub`:{let e=t.modal===`Box`,n=t.kind===`Sub`?e?`[`:`<<`:e?`[][`:`<><<`;return vn(z(`@[<h>%s@[<b2>%a@]%s%a@]`,n,i(t.action),e?`]_`:`>>_`,i(t.subscript)))}case`Fair`:return yn(z(`@[<h>%s_%a (%a)@]`,t.fairness===`Weak`?`WF`:`SF`,hn(i(t.subscript)),i(t.action)));case`Case`:return yn(z(`@[<v2>CASE %a%a@]`,Qt(t.arms,e=>z(`@[<b2>%a ->@ %a@]`,i(e.condition),i(e.body)),z(`@,[] `)),t.other?z(`@,[] @[<b2>OTHER ->@ %a@]`,i(t.other)):[]));case`String`:return vn(z(`"%s"`,t.value));case`Num`:return vn(R(t.fraction===``?t.integer:`${t.integer}.${t.fraction}`));case`At`:return vn(R(`@`));case`Parens`:{let e=t.form;if(e.kind===`Syntax`)return d(t.expression);let n=e.kind===`Nlabel`?e.names:e.indices.map(e=>e.index>=1&&e.index<=r.stack.length?l(e.index):`¶${e.index}`),i=d(t.expression);if(n.length===0){let t=i.kind===`Op`?`%s::(%a)`:`%s::%a`;return vn(z(t,e.label,_n(i)))}let a=Qt(n,R),o=i.kind===`Atm`?`%s(%a)::%a`:i.kind===`Big`?`%s(%a)::(%a)`:`(%s(%a):: %a)`;return vn(z(o,e.label,a,_n(i)))}}},f=e=>{switch(e.kind){case`Operator`:case`Bpragma`:{let t=e.body;if(t.kind===`Lambda`){let n=pn(r,t.params.map(e=>e.name),()=>i(t.body)),a=dn(r,e.name);return z(`@[<b2>%s@[<b1>(%a)@] ==@ %a@]`,a,Qt(t.params,Cn),n)}let n=i(t);return z(`@[<b2>%s ==@ %a@]`,dn(r,e.name),n)}case`Instance`:{let t=e.instance,n=pn(r,t.args,e=>({doc:z(`@[<b2>INSTANCE %s%a@]`,t.module,t.substitutions.length===0?[]:z(`@ WITH@ %a`,Qt(t.substitutions,e=>z(`@[<b2>%s <- %a@]`,e.name,i(e.expression))))),args:e})),a=dn(r,e.name),o=t.args.length===0?R(a):z(`%s (@[<b0>%a@])`,a,Qt(n.args,R));return z(`@[<b2>%a == %a@]`,o,n.doc)}case`Recursive`:{let t=dn(r,e.name);return z(`@[<b2>NEW CONSTANT %s%a@]`,t,Sn(e.shape))}}},p=e=>{switch(e.kind){case`Fresh`:{let t=e.domain&&e.domainVisibility===`Visible`?i(e.domain):void 0,n=dn(r,e.name);return[z(`NEW %s %s%a`,wn[e.level],n,Sn(e.shape)),t?z(` \\in %a`,t):[]]}case`Flex`:return z(`NEW VARIABLE %s`,dn(r,e.name));case`Defn`:{let t=e.whereDefined===`Builtin`?`(* builtin *)@
106
+ `:typeof e.whereDefined==`object`?`(* from proof *)@
107
+ `:``;return[n.isShowingAllDefinitions?z(t):[],f(e.definition)]}case`Fact`:{let t=z(`@[<h>%a %s@]`,i(e.expression),n.isTemporal&&e.time===`Now`?`(* non-[] *)`:``);return dn(r,``),t}}},m=e=>{if(e.context.length===0)return i(e.active);let t=[];for(let i of e.context){if(xn(i,n)){dn(r,ze(i)??``);continue}let e=(i.kind===`Defn`||i.kind===`Fact`)&&i.visibility===`Hidden`;t.push([n.isShowingHidden&&e?z(`(* hidden *)@
108
+ `):[],p(i)])}let a=i(e.active);return fn(r,e.context.length),t.length===0?a:[z(`@[<v0>ASSUME @[<v0>`),Qt(t,e=>e),z(`@]@
109
+ PROVE %a@]`,a)]};return{printSequent:m,printExpr:i}},En=(e,t)=>Tn(e).printExpr(t),Dn=(e,t={})=>Tn([],t).printSequent(e),On=(e,t={})=>en(z(`@[<b0>%a@]`,Dn(e,t))).trimEnd(),kn={kind:`Opaque`,name:`$Bad`},An=e=>e.kind===`Opaque`&&e.name===kn.name,jn=e=>{let t=e.kind===`Parens`?jn(e.expression):ot(e,jn);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},Mn=e=>e.kind===`Let`?k({kind:`Let`,definitions:e.definitions,body:Mn(e.body)},e.body):e.kind===`Parens`?Mn(e.expression):ot(e,Mn),Nn=e=>e.kind===`Ix`?e.index<=0:st(e).some(Nn),Pn=(e,t,n)=>{let r=(e,r=n)=>Pn(e,t,r),i=(e,t)=>e.reduce((e,t)=>e??(t.domain.kind===`Domain`?r(t.domain.expression):void 0),void 0)??r(t,[...n,...e.map(Xe)]);switch(e.kind){case`Parens`:return e.form.kind===`Xlabel`?e.form.label===t?{context:n,expression:e.expression,indices:e.form.indices}:void 0:r(e.expression);case`Lambda`:return r(e.body,[...n,...e.params.map(Ze)]);case`Let`:{let t=[...n];for(let n of e.definitions){let e=n.kind===`Operator`||n.kind===`Bpragma`?r(n.body,[...t]):void 0;if(e)return e;t.push({kind:`Defn`,definition:n,whereDefined:`Builtin`,visibility:`Visible`,isLocal:!0})}return r(e.body,t)}case`Quant`:case`Fcn`:return i(e.bounds,e.body);case`SetOf`:return i(e.bounds,e.element);case`Tquant`:return r(e.body,[...n,...e.names.map(e=>({kind:`Flex`,name:e}))]);case`Choose`:case`SetSt`:return(e.domain&&r(e.domain))??r(e.body,[...n,N(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of st(e)){let e=r(t);if(e)return e}return}},Fn=(e,t)=>lt(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),P(e+t)),In=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),Ln=(t,n,r)=>{switch(n.kind){case`Quant`:case`Fcn`:case`SetOf`:{if(n.bounds.length!==r.length){let i=n.bounds.length,a=`Arity mismatch in subexpression instance.\nExpected ${i} argument${i===1?``:`s`}, but found${r.length<i?` only`:``} ${r.length}.`;throw t(D(n.location,a)),t(Fe(n.location,a.replace(`
110
+ `,`@
111
+ `))),new e.A(a,{failure:`Expr.Deref.deref_inst`})}let i=n.kind===`SetOf`?n.element:n.body;return F(lt(r,P(0)),i)}case`Tquant`:return Ln(t,k({kind:`Quant`,quantifier:n.quantifier,bounds:n.names.map(e=>({name:e,level:`State`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`Lambda`:return Ln(t,k({kind:`Quant`,quantifier:`Forall`,bounds:n.params.map(e=>({name:e.name,level:`Unknown`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`SetSt`:case`Choose`:if(r.length!==1){let i=`Arity mismatch in subexpression instance.\nExpected 1 argument, but found ${r.length}.`;throw t(D(n.location,i)),t(Fe(n.location,i.replace(`
112
+ `,`@
113
+ `))),new e.A(i,{failure:`Expr.Deref.deref_inst`})}return F(lt(r,P(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw O(t,n.location,r),new e.A(r,{failure:`Expr.Deref.deref_inst`})}}},Rn=(t,n,r)=>{let i=(()=>{switch(r.kind){case`Quant`:case`Fcn`:case`SetOf`:return r.bounds.map(e=>({name:e.name,shape:0}));case`Tquant`:return r.names.map(e=>({name:e,shape:0}));case`Lambda`:return r.params;case`SetSt`:case`Choose`:return[{name:r.name,shape:0}];default:{let n=`Cannot abstract over bound variables in a non-binding expression`;throw O(t,r.location,n),new e.A(n,{failure:`Expr.Deref.deref_at`})}}})(),a=F(Fn(n,i.length),r);return[i,Ln(t,a,In(i.length))]},zn=(t,n,r,i,a)=>{let o=n=>{if(!(r<=n))throw O(t,i.location,a),new e.A(a,{failure:`Expr.Deref.deref_num`})},s=e=>(o(e.length),e[r-1]);if(n.kind===`With`)return zn(t,n.expression,r,i,a);let c=(()=>{switch(n.kind){case`Sequent`:{let i=n.sequent;o(i.context.length+1);let a=i.context[r-1];if(a&&a.kind!==`Fact`){let r=`subexpression reference does not resolve to an expression`;throw O(t,n.location,r),new e.A(r,{failure:`Expr.Deref.deref_num`})}let s=F(P(-(r-1)),a?a.expression:i.active);if(Nn(s)){t(D(n.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
114
+ Tlapm does not handle yet such subexpression namings.`));let r=`Subexpression of ASSUME/PROVE uses identifiers declared therein
115
+
116
+ Tlapm does not handle yet such subexpression namings.`;throw t(Fe(n.location,r)),new e.A(r,{failure:`Expr.Deref.deref_num`})}return s}case`Apply`:return s(n.args);case`If`:return s([n.condition,n.consequent,n.alternative]);case`List`:return s(n.items);case`SetEnum`:case`Tuple`:return s(n.elements);case`Product`:return s(n.factors);case`Let`:return o(1),n.body;case`Quant`:case`SetOf`:case`Fcn`:return s(n.bounds.flatMap(e=>e.domain.kind===`Domain`?[e.domain.expression]:[]));case`Choose`:case`SetSt`:if(!n.domain)break;return s([n.domain]);case`Arrow`:return s([n.domain,n.range]);case`FcnApp`:{let e=n.args.length===1?n.args[0]:k({kind:`Tuple`,elements:n.args},n);return s([n.function,e])}case`Rect`:case`Record`:return s(n.fields.map(e=>e.value));case`Dot`:return s([n.expression,k({kind:`String`,value:n.field},n)]);case`Except`:return s([n.function,...n.specs.map(e=>e.value)]);case`Sub`:case`Tsub`:return s([n.action,n.subscript]);case`Fair`:return s([n.subscript,n.action]);case`Case`:return s([...n.arms.map(e=>k({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...n.other?[k({kind:`Tuple`,elements:[kn,n.other]},n.other)]:[]])}let i=`Expression has no subexpressions`;throw O(t,n.location,i),new e.A(i,{failure:`Expr.Deref.deref_num`})})();if(An(c)){let i=`Cannot resolve subexpression reference !${r}`;throw O(t,n.location,i),new e.A(i,{failure:`Expr.Deref.deref_num`})}return[n.kind===`Let`?n.definitions:[],c]},Bn=(e,t)=>{let n=e.length,r=e;for(let e=n-1;e>=0;e--)r.includes(n-e)||(r=r.map(t=>t+e<n?t:t-1));return r.map(e=>t[n-e])},Vn=(t,n,r,i,a)=>{let o=Pn(r,i,[]);if(!o)return t(D(r.location,`Could not find label ${i}`)),{params:[],definitions:[],expression:kn};let s=o.indices;if(s.length!==a.length&&a.length>0){let n=s.length===1?``:`s`,r=`Expected ${s.length} argument${n} for labelled reference !${i}, but found ${a.length}`;throw O(t,o.expression.location,r),new e.A(r,{failure:`Expr.Deref.deref_lsub`})}let c=a.length===0?s.map(e=>({name:e.name,shape:0})):[],l=a.length===0?In(s.length):a,u=o.context.reduceRight((e,t)=>t.kind===`Defn`?k({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?k({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):F(P(-1),e),o.expression),d=F(Fn(n,c.length),u),f=[],p=d,m=Bn(s.map(e=>e.index),l);for(;m.length>0;)if(p.kind===`Let`&&p.definitions.length===1)f.push(p.definitions[0]),p=p.body,m=m.map(e=>F(P(1),e));else{if(p.kind!==`Quant`||p.bounds.length!==1)throw new e.U(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);p=F(ct(m[0],P(0)),p.body),m=m.slice(1)}return{params:c,definitions:f,expression:p}},Hn=(t,n,r,i,a)=>{if(r.kind!==`Let`){let n=`not a LET expression`;throw O(t,r.location,n),new e.A(n,{failure:`Expr.Deref.deref_letop`})}let o=r.definitions.findIndex(e=>e.kind===`Operator`&&e.name===i),s=r.definitions[o];if(!s||s.kind!==`Operator`){let n=`no definition of operator ${i}`;throw O(t,r.location,n),new e.A(n,{failure:`Expr.Deref.deref_letop`})}let c=s.body,l=c.kind===`Lambda`?k({...c,body:k({kind:`Parens`,expression:c.body,form:{kind:`Xlabel`,label:i,indices:c.params.map((e,t)=>({name:e.name,index:c.params.length-t}))}},c.body)},c):k({kind:`Parens`,expression:c,form:{kind:`Xlabel`,label:i,indices:[]}},c);return Vn(t,n,k({kind:`Let`,definitions:r.definitions.slice(0,o),body:l},c),i,a)},Un=(t,n,r,i,a)=>{let[o,...s]=a;if(!o){let e=i.definitions.length===0?i.expression:k({kind:`Let`,definitions:i.definitions,body:i.expression},i.expression),t=i.params.length===0?e:k({kind:`Lambda`,params:i.params,body:e},e);return{...jn(t),isAtomic:!0}}if(i.expression.isAtomic)return O(t,i.expression.location,`Expression has no subexpressions`),kn;let c=r?i.expression:Mn(i.expression),l=i.definitions.length,u=(()=>{let a=(e,n)=>{let[r,a]=zn(t,c,e,i.expression,n);return{params:[],definitions:r,expression:a,rest:s,isLabel:!1}};switch(o.kind){case`Down`:{let[a,...o]=s;if(c.kind===`Let`&&a?.kind===`Label`&&r)return{...Hn(t,l,c,a.label,a.args),rest:o,isLabel:!0};if(r)return{params:[],definitions:[],expression:c,rest:s,isLabel:!1};t(Fe(c.location,`!: is forbidden for this expression.
117
+ `));let u=[...n,...i.definitions.map(e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0}))];throw t(D(c.location,`!: is forbidden for this expression:\n${en(En(u,c))}`)),new e.A(`!: is forbidden for this expression.
118
+ `,{failure:`Expr.Deref.deref: !:`})}case`Number`:return a(o.value,`Cannot resolve !${o.value}`);case`Left`:return a(1,`Cannot resolve !<<`);case`Right`:return a(2,`Cannot resolve !>>`);case`Instance`:return{params:[],definitions:[],expression:Ln(t,c,o.args),rest:s,isLabel:!1};case`Label`:return{...c.kind===`Let`&&!r?Hn(t,l,c,o.label,o.args):Vn(t,l,c,o.label,o.args),rest:s,isLabel:!0};case`At`:{let[e,n]=Rn(t,l,c);return{params:e,definitions:[],expression:n,rest:s,isLabel:!1}}}})();return Un(t,n,u.isLabel,{params:[...i.params,...u.params],definitions:[...i.definitions,...u.definitions],expression:u.expression},u.rest.map(e=>tt(e,e=>F(P(u.definitions.length),e))))},Wn=(e,t,n)=>{if(n.length>0)return{params:[],definitions:[],expression:Ln(e,t,n)};if(t.kind!==`Lambda`)return{params:[],definitions:[],expression:t};let[r,i]=Rn(e,0,t);return{params:r,definitions:[],expression:i}},Gn=(t,n,r,i,a)=>{let o=Un(t,n,!0,Wn(t,r,i),a);if(An(o)){let n=`Could not resolve subexpression reference`;throw O(t,r.location,n),new e.A(n,{failure:`Expr.Anon: 2`})}return o},Kn=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),qn=e=>A(`UNCHANGED`,[e],e),Jn=e=>A(`Eq`,[A(`Prime`,[e],e),e],e),Yn=e=>{let t=e=>e.kind===`Tuple`?e.elements.flatMap(t):[e],n=t(e);return n.length===0?Re(e):n.length===1?Jn(n[0]):k({kind:`List`,bullet:`And`,items:n.map(Jn)},e)},Xn=e=>t=>{let n=Xn(e);return e(t,n)??ot(t,n)},Zn=Xn((e,t)=>Be(e,`Leadsto`)?A(`BoxTrue`,[A(`Implies`,[t(e.args[0]),A(`Diamond`,[t(e.args[1])],e)],e)],e):void 0),Qn=Xn(e=>{if(e.kind!==`Fair`)return;let t=e.action,n=e.subscript,r=A(`ENABLED`,[k({kind:`Sub`,modal:`Dia`,action:t,subscript:n},t)],t),i=e.fairness===`Weak`?`Diamond`:`BoxTrue`,a=e.fairness===`Weak`?`BoxTrue`:`Diamond`;return A(`Implies`,[A(i,[A(a,[r],t)],t),A(`BoxTrue`,[k({kind:`Tsub`,modal:`Dia`,action:t,subscript:n},t)],t)],t)}),$n=Xn((e,t)=>{if(e.kind!==`Sub`&&e.kind!==`Tsub`)return;let n=t(e.action),r=t(e.subscript),i=e.modal===`Box`?A(`Disj`,[n,qn(r)],e):A(`Conj`,[n,A(`Neg`,[qn(r)],e)],e);return e.kind===`Sub`?i:A(e.modal===`Box`?`BoxTrue`:`Diamond`,[i],e)}),er=Xn(e=>Be(e,`UNCHANGED`)?Yn(e.args[0]):void 0),tr=[`Prime`,`StrongPrime`,`Leadsto`,`ENABLED`,`UNCHANGED`,`Cdot`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`],nr=/* @__PURE__ */ new WeakMap,rr=(e,t)=>{switch(t.kind){case`Fresh`:return t.level===`Constant`;case`Defn`:return t.definition.kind===`Operator`&&ar(e,t.definition.body);case`Fact`:return ar(e,t.expression);case`Flex`:return!1}},ir=(e,t)=>M(e,t.map(e=>N(e,`Constant`))),ar=(e,t)=>{let n=t=>ar(e,t);switch(t.kind){case`Ix`:{let n=We(e,t.index-1),r=n?.hyp;if(r?.kind===`Fresh`)return r.level===`Constant`;if(r?.kind!==`Defn`||r.definition.kind!==`Operator`||r.isConstnessUnset)return!1;let i=r.definition.body,a=nr.get(i);if(a!==void 0)return a;let o=ar(n?.rest,i);return nr.set(i,o),o}case`Opaque`:case`String`:case`Num`:case`At`:return!0;case`Internal`:return!tr.includes(t.builtin);case`Tquant`:case`Sub`:case`Tsub`:case`Fair`:return!1;case`Lambda`:return ar(ir(e,t.params.map(e=>e.name)),t.body);case`Sequent`:{let n=t.sequent.context.reduce((e,t)=>({scope:j(e.scope,t),isGood:e.isGood&&rr(e.scope,t)}),{scope:e,isGood:!0});return n.isGood&&ar(n.scope,t.sequent.active)}case`Bang`:case`With`:case`Dot`:case`Parens`:return n(t.expression);case`Apply`:return n(t.operator)&&t.args.every(n);case`Let`:{let n=t.definitions.reduce((e,t)=>({scope:j(e.scope,Qe(t)),isGood:e.isGood&&t.kind===`Operator`&&ar(e.scope,t.body)}),{scope:e,isGood:!0});return n.isGood&&ar(n.scope,t.body)}case`Quant`:case`Fcn`:case`SetOf`:{let r=t.kind===`SetOf`?t.element:t.body;return t.bounds.every(e=>e.domain.kind!==`Domain`||n(e.domain.expression))&&ar(ir(e,t.bounds.map(e=>e.name)),r)}case`Choose`:case`SetSt`:return(t.domain===void 0||n(t.domain))&&ar(ir(e,[t.name]),t.body);case`If`:return n(t.condition)&&n(t.consequent)&&n(t.alternative);case`List`:return t.items.every(n);case`Tuple`:case`SetEnum`:return t.elements.every(n);case`Product`:return t.factors.every(n);case`FcnApp`:return n(t.function)&&t.args.every(n);case`Rect`:case`Record`:return t.fields.every(e=>n(e.value));case`Arrow`:return n(t.domain)&&n(t.range);case`Except`:return n(t.function)&&t.specs.every(e=>e.trail.every(e=>e.kind===`Dot`||n(e.expression))&&n(e.value));case`Case`:return t.arms.every(e=>n(e.condition)&&n(e.body))&&(t.other===void 0||n(t.other))}},or=(e,t,n)=>{if(ar(e,t))return!0;if(t.kind===`Internal`)return[`Eq`,`Neq`,`UNCHANGED`,`TRUE`,`FALSE`].includes(t.builtin);if(t.kind===`List`)return t.items.every(t=>or(e,t,n));if(t.kind===`Sequent`)return or(M(e,t.sequent.context),t.sequent.active,n);if(t.kind!==`Apply`)return!1;let r=t.args;return Kn(t,[`BoxTrue`,`BoxFalse`])&&n||Kn(t,[`Diamond`])&&!n?!0:r.length===1&&Kn(t,[`BoxTrue`,`BoxFalse`,`Diamond`,`Prime`])?or(e,r[0],n):r.length===1&&Kn(t,[`Neg`])?or(e,r[0],!n):r.length===2&&Kn(t,[`Conj`,`Disj`])?or(e,r[0],n)&&or(e,r[1],n):r.length===2&&Kn(t,[`Implies`])?or(e,r[0],!n)&&or(e,r[1],n):r.length===2&&Kn(t,[`Equiv`])?[!0,!1].every(t=>or(e,r[0],n!==t)&&or(e,r[1],n===t)):or(e,t.operator,n)&&r.every(t=>or(e,t,n))},sr=(e,t)=>or(e,Zn(Qn($n(er(t)))),!0)?`Always`:`Now`,cr=(e,t)=>t===`Always`&&e.some(e=>e.kind===`Fact`&&e.time===`Now`)?`Now`:t,lr=e=>e.kind===`Named`?`<${e.level}>${e.label}`:`<${e.level}>`,ur=e=>++e.value,dr={kind:`Fact`,expression:Le,visibility:`Visible`,time:`Always`},fr={Number:`1NUM`,Down:`1DOWN`,At:`1AT`,Instance:`1INST`,Left:`1`,Right:`1`},pr={kind:`Opaque`,name:`$badexp`},mr=(e,t)=>t.location?{...e,location:t.location}:e,hr=(t,n,r)=>{let i,a=e=>({warnedSteps:[],scope:e}),o=e=>e.scope?.size??0,s=(e,t)=>{if(t.kind===`At`&&t.isExcept)return i?I(o(e)-i.size,i.expression):t;if(t.kind!==`Except`)return f(e,t);let n=s(e,t.function);return t.specs.reduce((n,r)=>{let[a,c]=Ge(n,r.trail,(t,n)=>{if(n.kind===`Dot`)return[k({kind:`Dot`,expression:t,field:n.field},t),n];let r=s(e,n.expression);return[k({kind:`FcnApp`,function:t,args:[r]},t),{kind:`Apply`,expression:r}]}),l=i;i={expression:a,size:o(e)};let u=s(e,r.value);return i=l,k({kind:`Except`,function:n,specs:[{trail:c,value:u}]},t)},n)},c=(e,t,n)=>{let r=k({kind:`Ix`,index:e},n);return t.length===0?r:k({kind:`Apply`,operator:r,args:t},n)},l=(e,t,n,r,i)=>{if(t!==`Builtin`)return c(e,r,i);let a=I(e,n);return k(r.length===0?a:pt(a,r),i)},u=(t,n,i,a)=>{let o=Ue(t.scope,n);if(!o){let t=`Operator "${n}" not found`;throw O(r,a.location,t),new e.A(t,{failure:`Expr.Anon: 4`})}let s=o.depth+1,u=o.hyp;switch(u.kind){case`Defn`:{let t=u.definition;if(t.kind===`Operator`)return l(s,u.whereDefined,t.body,i,a);if(t.kind===`Recursive`){let t=`Recursive operators not supported by TLAPS`;throw r(Fe(u.location,t)),new e.A(t,{failure:`Expr.Anon: Recursive`})}return c(s,i,a)}case`Fresh`:return c(s,i,a);case`Flex`:if(i.length>0)throw new e.U(`File "src/expr/e_anon.ml", line 224, characters 24-30: Assertion failed`);return k({kind:`Ix`,index:s},a);case`Fact`:throw new e.U(`File "src/expr/e_anon.ml", line 230, characters 24-36: Assertion failed`)}},d=(t,n,i,a,o,c)=>{let u=Ue(t.scope,n);if(!u){let[o,...l]=a;if(o?.kind===`Label`){let e=o.args.map(e=>s(t,e));return d(t,`${n}!${o.label}`,[...i,...e],l,!0,c)}let u=`Operator "${n}" not found`;throw o&&r(D(c.location,u)),r(Fe(c.location,u)),new e.A(u,{failure:`Expr.Anon: ${o?fr[o.kind]:`1EMPTY`}`})}let f=u.hyp;if(f.kind!==`Defn`||f.definition.kind!==`Operator`&&f.definition.kind!==`Bpragma`)throw r(D(c.location,`invalid subexpression reference in: ${en(En([],c))}`)),r(Fe(c.location,`invalid subexpression reference`)),new e.A(`invalid subexpression reference`,{failure:`Expr.Anon: 3`});let p=u.depth+1;if(a.length===0&&o)return i.length===0?k({kind:`Ix`,index:p},c):l(p,f.whereDefined,f.definition.body,i,c);let m=mr(I(p,f.definition.body),c),h=He(t.scope);return mr(Gn(r,h,m,i,a),c)},f=(e,t)=>{switch(t.kind){case`Bang`:{let n=t.expression;if(n.kind===`Apply`&&n.operator.kind===`Opaque`){let r=t.selectors.map(t=>tt(t,t=>s(e,t))),i=n.args.map(t=>s(e,t)),o=a(e.scope);return d(o,n.operator.name,i,r,!1,t)}return s(e,{...t,expression:k({kind:`Apply`,operator:n,args:[]},n)})}case`Apply`:{if(t.operator.kind!==`Opaque`)return v(e,t);let n=t.operator.name;if(e.warnedSteps.includes(n))return r({text:`${Ie(t.location)}Warning: ${n} does not introduce any assumptions. It does not make sense to use it here.\n`,channel:`toolbox`}),Re(t);let i=t.args.map(t=>s(e,t));return u(e,n,i,t)}case`Opaque`:return s(e,k({kind:`Apply`,operator:t,args:[]},t));case`Parens`:return t.form.kind===`Syntax`?s(e,t.expression):{...t,expression:s(e,t.expression),form:p(e,t.form)};default:return v(e,t)}},p=(t,n)=>n.kind===`Nlabel`?{kind:`Xlabel`,label:n.label,indices:n.names.map(i=>{let a=Ue(t.scope,i);if(!a){let t=`Identifier "${i}" in label parameters not found`;throw O(r,n.location,t),new e.A(t,{failure:`Expr.Anon`})}return{name:i,index:a.depth+1}})}:n,m=(e,t)=>({warnedSteps:e.warnedSteps,scope:t}),h=(e,t)=>m(e,j(e.scope,t)),g=(e,t)=>m(e,M(e.scope,t.map(Xe))),_=(e,t)=>{let n=et(t,t=>s(e,t));return[g(e,n),n]},v=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:S(e,t.sequent)[1]};if(t.kind===`Let`){let[n,r]=b(e,t.definitions);return{...t,definitions:r,body:s(n,t.body)}}return at(e,t,s,h)},y=(e,t)=>{if(t.kind!==`Operator`)return t;let n=t.body;if(n.kind!==`Fcn`)return{...t,body:s(e,n)};let r=s(h(e,N(t.name,`Constant`)),n);if(L(F(ct({kind:`Opaque`,name:`%%%`},P(1)),r),r))return{...t,body:I(-1,r)};let i=A(`Eq`,[k({kind:`Ix`,index:1},r),r],r);return{...t,body:k({kind:`Choose`,name:t.name,domain:void 0,body:i},r)}},b=(e,t)=>{let r=e,i=[...t],a=[];for(let e=0;e<i.length;e++){let t=i[e];if(t.kind===`Instance`){i.splice(e+1,0,...n(r.scope,t));continue}let o=y(r,t);r=h(r,{...Qe(o),isConstnessUnset:!0}),a.push(o)}return[r,a]},x=(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:s(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:y(e,t.definition)};case`Fact`:{let n=s(e,t.expression);return{...t,expression:n,time:sr(e.scope,n)}}}})();return[h(e,n),n]},S=(e,t)=>{let[n,r]=Ge(e,t.context,x);return[n,{context:r,active:s(n,t.active)}]},C=(e,t)=>({warnedSteps:[lr(t),...e.warnedSteps],scope:e.scope}),w=(e,t,n,r)=>h(e,{kind:`Defn`,definition:{kind:`Operator`,name:lr(t),body:n,location:r.location},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!0,isConstnessUnset:!0,location:r.location}),T=(e,t)=>m(e,M(e.scope,Array.from({length:t},()=>dr))),ee=e=>{let t=[...e.context.map((t,n)=>{let r=e.context.length-n+1;if(t.kind===`Fact`)return I(r,t.expression);if(t.kind!==`Fresh`||!t.domain)return pr;let i=A(`Mem`,[k({kind:`Ix`,index:0},t.domain),t.domain],t.domain);return I(r,i)}),I(1,e.active)];return t.length===1?t[0]:{kind:`Tuple`,elements:t}},te=e=>e.kind!==`Use`&&e.kind!==`Hide`&&e.kind!==`Define`,ne=(e,t)=>({facts:t.facts.map(t=>s(e,t)),defs:t.defs.flatMap(t=>{if(t.kind===`Dx`)return[t];let n=s(e,k({kind:`Opaque`,name:t.name},t));return n.kind===`Ix`?We(e.scope,n.index-1)?.hyp.kind===`Defn`?[{kind:`Dx`,index:n.index,location:t.location}]:(r({text:`${Ie(t.location)}${JSON.stringify(t.name)} is not a definition and cannot be used in a DEF clause.`,channel:`toolbox`}),[]):(r({text:`${Ie(t.location)}Ignored unexpandable identifier ${JSON.stringify(t.name)} in BY DEF.`,channel:`stderr`}),[])})}),re=(e,t)=>{switch(t.kind){case`Steps`:{let[n,r]=Ge(e,t.steps,ie),i=re(t.step?C(n,t.step):n,t.qed.proof);return{...t,steps:r,qed:{...t.qed,proof:i}}}case`By`:return{...t,usable:ne(e,t.usable)};default:return t}},ie=(n,r)=>{let i=r.step?.kind===`Unnamed`&&te(r)?{kind:`Named`,level:r.step.level,label:`_a${ur(t)}`,isAnonymous:!0}:r.step;if(!i)throw new e.U;let a={...r,step:i};switch(a.kind){case`Assert`:{let[,e]=S(n,a.sequent),t=e.context.reduce(h,n),r=T(w(T(t,1),i,k(ee(e),a),a),1),o=e.context.length===0?C(r,i):r,s={...a,sequent:e,proof:re(o,a.proof)};return[T(w(n,i,k(Ve(e),a),a),1),s]}case`Pcase`:{let e=s(n,a.expression),t=k({kind:`Tuple`,elements:[I(2,e)]},a),r=T(w(T(n,2),i,t,a),1),o={...a,expression:e,proof:re(r,a.proof)},c=w(n,i,k({kind:`Tuple`,elements:[e]},a),a);return[T(c,1),o]}case`Suffices`:{let[,e]=S(n,a.sequent),t=k({kind:`Tuple`,elements:[k(Ve(e),a)]},a),r=T(w(n,i,t,a),1),o={...a,sequent:e,proof:re(r,a.proof)},s=e.context.reduce(h,n),c=k({kind:`Tuple`,elements:[k(ee(e),a)]},a);return[T(w(T(s,1),i,c,a),1),o]}case`Have`:{let e=s(n,a.expression),t=k({kind:`Tuple`,elements:[I(2,e)]},a);return[T(w(T(n,2),i,t,a),1),{...a,expression:e}]}case`Take`:{let[e,t]=_(n,a.bounds),r=k({kind:`Quant`,quantifier:`Forall`,bounds:t,body:pr},a);return[T(w(T(e,1),i,r,a),1),{...a,bounds:t}]}case`Witness`:{let e=a.expressions.map(e=>s(n,e)),t=k({kind:`Tuple`,elements:e},a);return[T(w(T(n,1),i,t,a),1),{...a,expressions:e}]}case`Pick`:{let[e,t]=_(n,a.bounds),r=s(e,a.expression),o=k({kind:`Quant`,quantifier:`Exists`,bounds:t,body:r},a),c=C(T(w(T(n,1),i,o,a),1),i),l={...a,bounds:t,expression:r,proof:re(c,a.proof)},u=g(T(n,2),t),d=I(4+t.length,o);return[T(w(T(u,2),i,d,a),1),l]}case`Use`:{let e=ne(n,a.usable);return[T(n,e.facts.length),{...a,usable:e}]}case`Hide`:return[n,{...a,usable:ne(n,a.usable)}];case`Define`:{let[e,t]=b(n,a.definitions);return[e,{...a,definitions:t}]}case`Forget`:return[n,a]}};return{expr:(e,t)=>s(a(e),t),defn:(e,t)=>y(a(e),t),sequent:(e,t)=>S(a(e),t)[1],usable:(e,t)=>ne(a(e),t),proof:(e,t)=>re(a(e),t)}},B=(e,t,n)=>({kind:`Definition`,definition:{kind:`Operator`,name:t,body:e===0?{kind:`Internal`,builtin:n}:{kind:`Lambda`,params:Array.from({length:e},(e,t)=>({name:`x${t+1}`,shape:0})),body:{kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n}))}}},whereDefined:`Builtin`,visibility:`Visible`,isLocal:!1}),gr=[B(0,`Nat`,`Nat`),B(2,`+`,`Plus`),B(2,`-`,`Minus`),B(2,`*`,`Times`),B(2,`^`,`Exp`),B(2,`<`,`Lt`),B(2,`>`,`Gt`),B(2,`=<`,`Lteq`),B(2,`>=`,`Gteq`),B(2,`%`,`Remainder`),B(2,`\\div`,`Quotient`),B(2,`..`,`Range`)],_r=[...gr,B(0,`Int`,`Int`),B(1,`-.`,`Uminus`)],vr=[..._r,B(0,`Real`,`Real`),B(2,`/`,`Ratio`),B(0,`Infinity`,`Infinity`)],yr=[B(1,`Seq`,`Seq`),B(1,`Len`,`Len`),B(2,`BSeq`,`BSeq`),B(2,`\\o`,`Cat`),B(2,`Append`,`Append`),B(1,`Head`,`Head`),B(1,`Tail`,`Tail`),B(3,`SubSeq`,`SubSeq`),B(2,`SelectSeq`,`SelectSeq`)],br=[B(2,`Print`,`Print`),B(1,`PrintT`,`PrintT`),B(2,`Assert`,`Assert`),B(0,`JavaTime`,`JavaTime`),B(1,`TLCGet`,`TLCGet`),B(2,`TLCSet`,`TLCSet`),B(2,`:>`,`OneArg`),B(2,`@@`,`Extend`),B(1,`Permutations`,`Permutations`),B(2,`SortSeq`,`SortSeq`),B(1,`RandomElement`,`RandomElement`),B(0,`Any`,`Any`),B(1,`ToString`,`ToString`)],xr=(e,t)=>({name:e,extendees:[],body:t,isImportant:!1,isStandard:!0}),Sr=new Map([xr(`Naturals`,gr),xr(`Integers`,_r),xr(`Reals`,vr),xr(`Sequences`,yr),xr(`TLC`,br)].map(e=>[e.name,e])),Cr=e=>{let t=e.location;switch(e.kind){case`Constants`:return e.declarations.map(e=>({...N(e.name,`Constant`,e.shape),location:t}));case`Recursives`:return e.declarations.map(e=>Ye({kind:`Recursive`,name:e.name,shape:e.shape,location:t},`User`,`Hidden`,!1,t));case`Variables`:return e.names.map(e=>({kind:`Flex`,name:e,location:t}));case`Definition`:return[Ye(e.definition,e.whereDefined,e.visibility,e.isLocal,t)];case`Axiom`:case`Theorem`:{let n=e.kind===`Axiom`?e.expression:k(Ve(_t(P(-e.axiomCount),{...e.sequent,context:e.sequent.context.slice(e.axiomCount)})),e);return e.name===void 0?[Je(n,`Hidden`,`Always`,t)]:Tr(e.name,n,t)}case`Mutate`:return e.mode===`Use`?e.usable.facts.map((e,n)=>Je(I(n,e),`Visible`,`Always`,t)):[];case`Submod`:case`Anoninst`:return[]}},wr=e=>e.kind===`Axiom`||e.kind===`Theorem`?e.name===void 0?1:2:Cr(e).length,Tr=(e,t,n)=>[Ye({kind:`Operator`,name:e,body:t,location:n},`User`,`Visible`,!1,n),Je({kind:`Ix`,index:1,location:n},`Hidden`,`Always`,n)],Er=e=>e.body.flatMap(e=>{switch(e.kind){case`Definition`:return[{...e,whereDefined:e.isLocal?`Builtin`:e.whereDefined}];case`Mutate`:return[];case`Theorem`:return[{...e,proof:{kind:`Omitted`,omission:`Elsewhere`,location:e.location}}];case`Submod`:return[{...e,module:{...e.module,body:Er(e.module)}}];default:return[e]}}),Dr=(t,n,r,i=/* @__PURE__ */ new Set([n.name]))=>{let a=[];for(let o of n.extendees){if(r.has(o))continue;if(i.has(o))throw new e.U(`Stack overflow`);let n=t.get(o);if(!n)throw new e.A(`Module "${o}" unknown`);a.push(...Er(Dr(t,n,r,/* @__PURE__ */ new Set([...i,o])))),r.add(o)}return{...n,body:[...a,...n.body].map(e=>e.kind===`Submod`?{...e,module:Dr(t,e.module,/* @__PURE__ */ new Set)}:e)}},Or=e=>{let t=/* @__PURE__ */ new Map,n=(e,n)=>{t.has(e)||t.set(e,n)},r=e=>e.extendees.forEach((t,r)=>n(t,e.extendeeLocations?.[r])),i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Map,o=e=>{typeof e==`object`&&e&&(`instance`in e&&kr(e.instance)&&n(e.instance.module,e.instance.location),Object.values(e).forEach(o))},s=e=>{e.kind===`Submod`?(i.add(e.module.name),a.set(e.module.name,e.module),r(e.module),e.module.body.forEach(s)):o(e.kind===`Theorem`?e.sequent:e)};return e.body.forEach(s),i.forEach(e=>t.delete(e)),r(e),{dependencies:[...t.keys()].sort(Ar),locations:t,submodules:a}},kr=e=>typeof e==`object`&&!!e&&`module`in e&&typeof e.module==`string`&&`substitutions`in e,Ar=(e,t)=>e<t?-1:+(e>t),jr=(t,n)=>({facts:ft(t,n.facts),defs:n.defs.map(n=>{if(n.kind===`Dvar`)return n;let r=F(t,{kind:`Ix`,index:n.index});if(r.kind!==`Ix`)throw new e.A(`substitution produced bad definition`);return{...n,index:r.index}})}),Mr=(e,t)=>{switch(t.kind){case`Constants`:case`Recursives`:return[ut(t.declarations.length,e),t];case`Variables`:return[ut(t.names.length,e),t];case`Definition`:return[ut(1,e),{...t,definition:ht(e,t.definition)}];case`Axiom`:return[ut(wr(t),e),{...t,expression:F(e,t.expression)}];case`Theorem`:return[ut(wr(t),e),{...t,sequent:_t(e,t.sequent)}];case`Submod`:return[e,{...t,module:{...t.module,body:Nr(e,t.module.body)}}];case`Mutate`:return[t.mode===`Hide`?e:ut(t.usable.facts.length,e),{...t,usable:jr(e,t.usable)}];case`Anoninst`:return[e,{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(t=>({...t,expression:F(e,t.expression)}))}}]}},Nr=(e,t)=>Ge(e,t,Mr)[1],Pr=(e,t,n)=>e===void 0?{hyps:[],sequent:t}:{hyps:[Ye({kind:`Operator`,name:e,body:k(Ve(t),{location:n}),location:n},{kind:`Proof`,time:`Always`},`Visible`,!1,n)],sequent:_t(P(1),t)},Fr=e=>e?.kind===`Named`&&e.isAnonymous,Ir=(e,t)=>t.context.flatMap((n,r)=>n.kind===`Fact`&&n.visibility===`Visible`?[I(e+t.context.length-1-r,n.expression)]:[]),Lr=(t,n,r)=>{if(!t.step)throw new e.U;return Ye({kind:`Operator`,name:lr(t.step),body:n,location:t.location},{kind:`Proof`,time:r},`Visible`,!0,t.location)},Rr=e=>({...Qe(e),location:e.location}),zr=(e,t,n,r)=>{let i=Fr(n.step)?`Visible`:`Hidden`,a=t.context.map(e=>e.kind===`Fact`?{...e,visibility:i}:e),o=k({kind:`List`,bullet:`Refs`,items:Ir(2,t)},n),s=cr(t.context,r);return{context:[...e,...a,Je(Re(n),`Hidden`,r,n.location),Lr(n,o,s),Je(k({kind:`Ix`,index:1},n),`Hidden`,s,n.location)],active:I(3,t.active),time:s}},Br=(e,t,n,r,i,a)=>{let o=e||Fr(i.step)?`Visible`:`Hidden`;return{context:[...t,Lr(i,k(Ve(r),i),a),Je(k({kind:`Ix`,index:1},i),o,a,i.location)],active:I(2,n)}},Vr=(e,t,n)=>{if(t.kind!==`Ix`)return n;let r=e[e.length-t.index];return r?.kind===`Fact`?r.time:r?.kind===`Defn`&&typeof r.whereDefined==`object`?r.whereDefined.time:n},Hr=(t,n,r)=>{if(r.kind!==`Dx`)throw new e.A(`Unknown definition ${r.name}`);let i=n.length-r.index,a=n[i];if(!a)return n;if(a.kind!==`Defn`)throw new e.A(`Indicated point is not a definition`);return n.map((e,n)=>n===i?{...a,visibility:t}:e)},Ur=(e,t)=>Be(e,`Mem`)&&e.args[0]?.kind===`Ix`&&e.args[0].index===0&&L(t,e.args[1]),Wr=(t,n,r,i)=>{let a=!1,o=r,s=[...i];for(let e=i.length-1;e>=0;e--){o=I(-1,o);let t=i[e];t.kind===`Fact`&&L(t.expression,o)?(a=!0,s[e]={...t,visibility:n}):t.kind===`Fresh`&&t.domain&&Ur(o,t.domain)&&(a=!0,s[e]={...t,domainVisibility:n})}if(!a){let n=`This expression does not appear in the context and cannot be hidden.`;throw t(D(r.location,`${n}\n`)),new e.A(n,{failure:`proof.Gen.set_expr`})}return s},Gr=(e,t,n)=>({sequent:e,location:t.location,kind:n,method:t.method,isEnabledAxiomsSound:t.isEnabledAxiomsSound}),Kr={total:0,absent:[],omitted:[]},qr=(e,t)=>({total:e.total+t.total,absent:[...e.absent,...t.absent],omitted:[...e.omitted,...t.omitted]}),Jr=e=>e.kind===`Use`?{...Kr,total:e.obligations?.length??0}:`proof`in e?Yr(e.proof):Kr,Yr=e=>e.kind===`Steps`?[...e.steps.map(Jr),Yr(e.qed.proof)].reduce(qr):e.kind!==`Omitted`||!e.obligations||!e.location?{...Kr,total:e.obligations?.length??0}:{total:e.obligations.length,absent:e.omission===`Implicit`?[e.location]:[],omitted:e.omission===`Explicit`?[e.location]:[]},Xr=(t,n,r)=>{let i=(r,o,s)=>{let c=o.location;if(!c||!t.has(c.file)||c.endLine<n.start||c.startLine>n.end)return o;switch(o.kind){case`Obvious`:return{...o,obligations:[Gr(r,o,{kind:`Main`})]};case`Omitted`:return{...o,obligations:[Gr(r,o,{kind:`Omitted`,omission:o.omission})]};case`Error`:return{...o,obligations:[Gr(r,o,{kind:`Error`,message:o.message})]};case`By`:throw new e.A(`Proof.Gen.generate`);case`Steps`:{let[e,t]=Ge({sequent:r,time:s},o.steps,(e,t)=>{let n=a(e.sequent,t,e.time);return[n,n.step]}),n=i(e.sequent,o.qed.proof,e.time);return{...o,steps:t,qed:{...o.qed,proof:n}}}}},a=(t,n,a)=>{switch(n.kind){case`Forget`:{let e=t.context.length,r=t.context.map((t,r)=>t.kind===`Fact`&&t.visibility===`Visible`&&n.count+r<e?{...t,visibility:`Hidden`}:t);return{sequent:{...t,context:r},step:n,time:a}}case`Use`:{let r=n.usable;if(r.defs.length===0&&r.facts.length===1){let e=r.facts[0],i=Gr({...t,active:e},n,{kind:`Support`});return{sequent:{context:[...t.context,{...Je(e,`Visible`,Vr(t.context,e,a),e.location),useLocation:n.useLocation}],active:I(1,t.active)},step:{...n,obligations:[i]},time:a}}if(r.facts.length>0)throw new e.A(`Proof.Gen.gen_step: USE with facts and definitions`);let i=r.defs.reduce((e,t)=>Hr(`Visible`,e,t),t.context);return{sequent:{...t,context:i},step:n,time:a}}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>Hr(`Hidden`,e,t),t.context),i=n.usable.facts.reduceRight((e,t)=>Wr(r,`Hidden`,t,e),e);return{sequent:{...t,context:i},step:n,time:a}}case`Define`:return{sequent:{context:[...t.context,...n.definitions.map(Rr)],active:I(n.definitions.length,t.active)},step:n,time:a};case`Assert`:{let e=zr(t.context,n.sequent,n,a),r=i(e,n.proof,e.time),o={...n,proof:r};return{sequent:Br(!1,t.context,t.active,n.sequent,o,a),step:o,time:a}}case`Suffices`:{let e=i(Br(!0,t.context,t.active,n.sequent,n,a),n.proof,a),r={...n,proof:e},o=zr(t.context,n.sequent,r,a);return{sequent:o,step:r,time:o.time}}default:throw new e.A(`Proof.Gen.gen_step`)}},o=(e,t,n,r)=>{let i={kind:`Unnamed`,level:0,id:0},o=a({context:e,active:{...Le,location:r}},t===`Use`?{kind:`Use`,usable:n,isOnly:!1,location:r,step:i,useLocation:r}:{kind:`Hide`,usable:n,location:r,step:i},`Always`);return[o.sequent.context,o.step.obligations??[]]},s=(e,t,n,r)=>{if(n.defs.length===0&&n.facts.length===0)return[e,[]];let i=n.defs.length>0,[a,...c]=n.facts,[l,u]=o(e,t,i?{defs:n.defs,facts:[]}:{defs:[],facts:[a]},r),d=i?n.facts:c.map(e=>I(1,e)),[f,p]=s(l,t,{defs:[],facts:d},r);return[f,[...u,...p]]},c=e=>{let t=[],n=e=>{e.kind===`Steps`?(n(e.qed.proof),e.steps.forEach(r)):e.obligations&&!e.isSuppressed&&t.push(...e.obligations)},r=e=>{e.kind===`Use`&&e.obligations&&!e.isSuppressed&&t.push(...e.obligations),`proof`in e&&n(e.proof)};return n(e),t},l=(e,t)=>{let n=[],r=[],a=Kr,o=e;for(let e of t.body)switch(e.kind){case`Theorem`:{let t=Pr(e.name,e.sequent,e.location),s=[...o,...t.hyps],l=[...s,...t.sequent.context],u=i({context:l,active:t.sequent.active},e.proof,cr(l,`Always`));n.push(...c(u));let d=Yr(u);r.push({...d,location:e.location}),a=qr(a,d);let f=e.name===void 0?k(Ve(e.sequent),e):{kind:`Ix`,index:1,location:e.location};o=[...s,Je(f,`Hidden`,`Always`,e.location)];continue}case`Submod`:{let t=l(o,e.module);n.push(...t.obligations),a=qr(a,t.summary);continue}case`Mutate`:{let[t,r]=s(o,e.mode,e.usable,e.location);n.push(...r),o=t;continue}default:o=[...o,...Cr(e)]}return{obligations:n,summary:{...a,theorems:r}}};return l},Zr=(e,t=0)=>({level:e,weights:Array.from({length:t},()=>!0),params:/* @__PURE__ */ new Set}),Qr={TRUE:[0,0],FALSE:[0,0],Implies:[0,2],Equiv:[0,2],Conj:[0,2],Disj:[0,2],Neg:[0,1],Eq:[0,2],Neq:[0,2],STRING:[0,0],BOOLEAN:[0,0],SUBSET:[0,1],UNION:[0,1],DOMAIN:[0,1],Subseteq:[0,2],Mem:[0,2],Notmem:[0,2],Setminus:[0,2],Cap:[0,2],Cup:[0,2],Actplus:[3,2],BoxTrue:[3,1],BoxFalse:[3,1],Diamond:[3,1],Prime:[2,1],StrongPrime:[2,1],ENABLED:[1,1],UNCHANGED:[2,1],Leadsto:[3,2],Cdot:[2,2],Nat:[0,0],Int:[0,0],Real:[0,0],Infinity:[0,0],Plus:[0,2],Minus:[0,2],Times:[0,2],Ratio:[0,2],Quotient:[0,2],Remainder:[0,2],Exp:[0,2],Divides:[0,2],Lteq:[0,2],Lt:[0,2],Gteq:[0,2],Gt:[0,2],Range:[0,2],Uminus:[0,1],Seq:[0,1],Len:[0,1],BSeq:[0,2],Cat:[0,2],Append:[0,2],Head:[0,1],Tail:[0,1],SubSeq:[0,3],SelectSeq:[0,2],OneArg:[0,2],Extend:[0,2],Print:[0,2],PrintT:[0,1],Assert:[0,2],JavaTime:[0,0],TLCGet:[0,1],TLCSet:[0,2],Permutations:[0,1],SortSeq:[0,2],RandomElement:[0,1],Any:[0,0],ToString:[0,1],Unprimable:[0,1]},$r={Constant:0,State:1,Action:2,Temporal:3,Unknown:0},ei=e=>new Set(e.flatMap(e=>[...e])),ti=e=>({level:Math.max(0,...e.map(e=>e.level)),weights:[],params:ei(e.map(e=>e.params))}),ni=/* @__PURE__ */ new WeakMap,ri=t=>{let n=t.hyp;switch(n.kind){case`Flex`:return Zr(1);case`Fresh`:return{...Zr($r[n.level],n.shape),params:/* @__PURE__ */ new Set([n.name])};case`Defn`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e.U;return ci(t.rest,r.body)}case`Fact`:return ci(t.rest,n.expression)}},ii=e=>{let t=ni.get(e);if(t)return t;let n=ri(e);return ni.set(e,n),n},ai=(e,t,n)=>{let r=t.flatMap(t=>t.domain.kind===`Domain`?[ci(e,t.domain.expression)]:[]);return ti([ci(M(e,t.map(Xe)),n),...r])},oi=(t,n,r)=>{if(t.weights.length!==n.length)throw new e.A(`Invalid number of arguments`,{failure:`Expr.Levels: ARITY`,locus:r.location});let i=n.filter((e,n)=>t.weights[n]);return{level:Math.max(t.level,...i.map(e=>e.level)),weights:[],params:ei([t.params,...i.map(e=>e.params)])}},si=(e,t)=>{let[n,r]=Ge(e,t,(e,t)=>{let n=j(e,t);return[n,ii(n).level]});return{scope:n,level:Math.max(0,...r)}},ci=(t,n)=>{let r=e=>ci(t,e);switch(n.kind){case`Ix`:{let r=We(t,n.index-1);if(!r)throw new e.U;return ii(r)}case`Internal`:{let t=Qr[n.builtin];if(!t)throw new e.U;return Zr(t[0],t[1])}case`Opaque`:case`String`:case`Num`:return Zr(0);case`Lambda`:{let e=ci(M(t,n.params.map(Ze)),n.body),r=new Set(n.params.map(e=>e.name));return{level:e.level,weights:n.params.map(t=>e.params.has(t.name)),params:new Set([...e.params].filter(e=>!r.has(e)))}}case`Apply`:{let t=n.operator;if(Be(t,`Prime`)&&t.args.length===1)return r({...n,operator:t.args[0]});if(t.kind===`Opaque`)return oi(Zr(0,n.args.length),n.args.map(r),n);if(t.kind===`Internal`&&n.args.length===1){let i=n.args[0];switch(t.builtin){case`Prime`:case`StrongPrime`:if(r(i).level>1)throw new e.U;return Zr(2,1);case`ENABLED`:{let t=r(i);if(t.level>2)throw new e.U;return{level:1,weights:[],params:t.params}}case`UNCHANGED`:{let t=r(i);if(t.level>1)throw new e.U;return{level:2,weights:[],params:t.params}}}}return t.kind===`Internal`&&t.builtin===`Cdot`?(n.args.forEach(r),Zr(2)):t.kind===`Internal`&&t.builtin===`Leadsto`?(n.args.forEach(r),Zr(3,2)):oi(r(t),n.args.map(r),n)}case`Sequent`:{let e=si(t,n.sequent.context);return Zr(Math.max(e.level,ci(e.scope,n.sequent.active).level))}case`With`:case`Dot`:case`Parens`:return r(n.expression);case`Let`:return ci(M(t,n.definitions.map(Qe)),n.body);case`If`:return ti([n.condition,n.consequent,n.alternative].map(r));case`List`:return ti(n.items.map(r));case`Quant`:case`Fcn`:return ai(t,n.bounds,n.body);case`SetOf`:return ai(t,n.bounds,n.element);case`Tquant`:return ci(M(t,n.names.map(e=>({kind:`Flex`,name:e}))),n.body),Zr(3);case`Choose`:case`SetSt`:{let e=n.domain&&r(n.domain),i=n.domain?qe(n.name,n.domain):N(n.name,`Constant`);return ti([ci(j(t,i),n.body),...e?[e]:[]])}case`SetEnum`:case`Tuple`:return ti(n.elements.map(r));case`Product`:return ti(n.factors.map(r));case`FcnApp`:return ti([n.function,...n.args].map(r));case`Arrow`:return ti([r(n.domain),r(n.range)]);case`Rect`:case`Record`:return ti(n.fields.map(e=>r(e.value)));case`Except`:return ti([r(n.function),...n.specs.flatMap(e=>[...e.trail.flatMap(e=>e.kind===`Apply`?[r(e.expression)]:[]),r(e.value)])]);case`Sub`:return{...ti([r(n.action),r(n.subscript)]),level:2};case`Tsub`:case`Fair`:return r(n.action),r(n.subscript),Zr(3);case`Case`:return ti([...n.arms.flatMap(e=>[r(e.condition),r(e.body)]),...n.other?[r(n.other)]:[]]);case`Bang`:case`At`:throw new e.U}},li=`EnabledWrapper`,ui=`CdotWrapper`,di="Nested occurrence of the operator `ENABLED` found in scope of `\\cdot` when expanding `\\cdot`. Using the proof directive `ExpandENABLED` from the module `TLAPS` is expected to avoid this error.For example, writing `BY ExpandENABLED`.",fi="Nested occurrence of the operator `\\cdot` found in scope of `ENABLED` when expanding `ENABLED`. Using the proof directive `ExpandCdot` from the module `TLAPS` is expected to avoid this error.",pi=`${fi} For example, writing \`BY ExpandCdot\`.`,mi=(t,n)=>{let r=We(t,n-1)?.hyp;if(!r)throw new e.U;return r},hi=e=>e.kind===`Internal`&&(e.builtin===`ENABLED`||e.builtin===`Cdot`),gi=e=>e.kind===`Opaque`&&(e.name===li||e.name===ui),_i=e=>e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`Lambda`&&(hi(e.operator)||gi(e.operator)),vi=e=>e===void 0?2:Math.min(2,e),yi=e=>e===void 0?void 0:Math.max(1,e-1),bi=(t,n,r,i,a)=>{let o=(e,i=a)=>bi(t,n,r,e,i);if(_i(i))return i;if(i.kind===`Sub`)return{...i,action:o(i.action),subscript:o(i.subscript,yi(a))};if(i.kind===`Apply`&&i.operator.kind===`Internal`){let r=i.operator.builtin,[s,c]=i.args;if(r===`Cdot`&&i.args.length===2){if(a!==void 0&&!t.isCdot)throw n(D(i.location,`${fi}For example, writing \`BY ExpandCdot\`.`)),new e.j(`Expr.Action`);return{...i,args:t.isCdot?[o(s,vi(a)),o(c,1)]:[o(s),o(c)]}}if(r===`ENABLED`&&i.args.length===1){if(a!==void 0&&!t.isEnabled)throw n(D(i.location,di)),new e.j(`Expr.Action`);return{...i,args:[t.isEnabled?o(s,vi(a)):o(s)]}}if((r===`Prime`||r===`UNCHANGED`)&&i.args.length===1)return{...i,args:[o(s,yi(a))]}}let s=i.kind===`Apply`&&i.operator.kind===`Ix`?i.operator:i;if(s.kind!==`Ix`)return at(r,i,(e,r)=>bi(t,n,e,r,a),j);if(a===void 0)return i;let c=ci(r,i).level,l=mi(r,s.index),u=e=>`The operator \`${e}\` is declared at:\n${Ne(l.location)}`;if(l.kind===`Fresh`&&l.level===`Unknown`)throw n(D(i.location,`Declared operator \`${l.name}\` has unknown level and occurs within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${a}.\nIf a constant operator is substituted for this operator, then the expression that results from applying this declared operator has expression level ${c}.\n May need expansion. A declared operator cannot be expanded.\n${u(l.name)}\n and has arity: ${l.shape}`)),new e.U(`File "src/expr/e_action.ml", line 367, characters 20-26: Assertion failed`);if(c<a)return i;if(c>2||l.kind===`Fact`)throw new e.U;if(l.kind===`Flex`){if(i.kind!==`Ix`)throw new e.U;return i}if(l.kind===`Fresh`){let t=`The expression that results from applying the declared operator \`${l.name}\` has expression level ${c} within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${a}. A declared operator cannot be expanded.\n${u(l.name)}\n and has level: ${$r[l.level]}\n and arity: ${l.shape}`;throw n(D(i.location,t)),new e.j(t)}let d=l.definition;if(d.kind!==`Operator`&&d.kind!==`Bpragma`)throw new e.U;if(!t.isAutoUse){let r=t.isEnabled&&t.isCdot?["the operators `ENABLED` and `\\cdot`","the proof directives `ExpandENABLED` and `ExpandCdot`"]:t.isEnabled?["the operator `ENABLED`","`ExpandENABLED` proof directive"]:["the operator `\\cdot`","`ExpandCdot` proof directive"],a=d.body.kind===`Lambda`?d.body.body:d.body,o=`Hidden definition of operator \`${d.name}\` needs expansion for soundly expanding ${r[0]} (using rigid quantification).\nThe expansion of ${r[0]} has been activated with the ${r[1]} from the module \`TLAPS\`.\nThe operator \`${d.name}\` is defined at: \n\t${Ne(a.location)}\nand the operator \`${d.name}\` occurs at: \n\t${Ne(i.location)}\nUsing the proof directive \`AutoUSE\` from the module \`TLAPS\`, or \`BY DEF ${d.name}\` is expected to avoid this error.\n`;throw n(D(i.location,o)),new e.j(o)}n({text:`${Pe(i.location)}[INFO]: Auto-expanding the definition of operator: ${d.name}\n`,channel:`stdout`});let f=F(P(s.index),d.body);return o($e(i.kind===`Apply`?pt(f,i.args):f))},xi=t=>{if(t.kind===`Apply`&&t.args.length===1)return Yn(t.args[0]);if(t.kind!==`Sub`)throw new e.U;let n=Yn(t.subscript),r=t.modal===`Box`?n:A(`Neg`,[n],t);return A(t.modal===`Box`?`Disj`:`Conj`,[t.action,r],t)},Si=e=>{let t=(e,t)=>e<<t|e>>>32-t,n=(e,n)=>{let r=Math.imul(t(Math.imul(n,3432918353),15),461845907);return Math.imul(t(e^r,13),5)+3864292196|0},r=new TextEncoder().encode(e),i=r.length-r.length%4,a=0;for(let e=0;e<i;e+=4)a=n(a,r[e]|r[e+1]<<8|r[e+2]<<16|r[e+3]<<24);let o=r.subarray(i).reduceRight((e,t)=>e<<8|t,0);return r.length>i&&(a=n(a,o)),a^=r.length,a=Math.imul(a^a>>>16,2246822507),a=Math.imul(a^a>>>13,3266489909),(a^a>>>16)&1073741823},Ci=e=>{let t=Array.from({length:16},()=>[]);return e.forEach((e,n)=>{if(t[Si(e)&t.length-1].unshift(e),n+1<=t.length*2)return;let r=Array.from({length:t.length*2},()=>[]);t.flat().forEach(e=>r[Si(e)&r.length-1].push(e)),t=r}),t.flat()},wi=(t,n,r,i,a,o)=>{let s=e=>wi(t,n,r,i,a,e),c=r!==void 0||i!==void 0,l=(e,s)=>{let c={names:[],depth:Math.max(r?.depth??0,i?.depth??0)+1},[l,u]=s,d=[wi(t,n,r,c,a,l),...u?[wi(t,n,c,i,a,u)]:[]],f=c.names.length===0?[`r#0`]:Ci(c.names);return k({kind:`Apply`,operator:e,args:[{kind:`Lambda`,params:[`_`,...f].map(e=>({name:e,shape:0})),body:d.length===1?d[0]:{kind:`List`,bullet:`And`,items:d}}]},o)};if(_i(o))return o;if(o.kind===`Apply`&&o.operator.kind===`Internal`){let r=o.operator.builtin;if(t.isEnabled&&r===`ENABLED`&&o.args.length===1||t.isCdot&&r===`Cdot`&&o.args.length===2)return l(o.operator,o.args);if(r===`ENABLED`&&c)throw n(D(o.location,di)),new e.j(`Expr.Action`);if(r===`Cdot`&&c)throw n(D(o.location,pi)),new e.j(`Expr.Action`);if(r===`Prime`&&o.args.length===1){let e=wi(t,n,i,void 0,a,o.args[0]);return i?e:{...o,args:[e]}}if(r===`UNCHANGED`&&c)return s(xi(o))}if(o.kind===`Sub`&&c)return s(xi(o));if(o.kind===`Ix`){if(!r)return o;let t=mi(a,o.index);if(t.kind===`Fact`)throw new e.U;if(t.kind!==`Flex`)return o;let n=`${t.name}#enabled#prime${r.depth}`;return r.names.includes(n)||r.names.push(n),k({kind:`Opaque`,name:n},o)}if(o.kind===`Apply`&&o.operator.kind===`Opaque`)throw n(D(o.location,`Named operator \`${o.operator.name}\` unexpected after anonymization.`)),new e.U(`File "src/expr/e_action.ml", line 1048, characters 12-18: Assertion failed`);return at(a,o,(e,a)=>wi(t,n,r,i,e,a),j)},Ti=(t,n)=>{if(n.kind===`Apply`&&hi(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`)throw new e.U;let[i,...a]=r.params;if(i.name!==`_`)return n;let o=Ti({kind:`Compose`,outer:t,inner:P(a.length)},r.body);return{kind:`Apply`,operator:n.operator,args:[{kind:`Lambda`,params:a,body:o}]}}return n.kind===`Ix`?F(t,n):n.kind===`Apply`?k(pt(Ti(t,n.operator),n.args.map(e=>Ti(t,e))),n):at(t,n,Ti,e=>ut(1,e))},Ei=(t,n)=>{if(n.kind===`Apply`&&hi(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`||r.params[0].name===`_`)throw new e.U;let i=n.operator.builtin===`Cdot`?ui:li;return{kind:`Apply`,operator:k({kind:`Opaque`,name:i},n.operator),args:[{kind:`Lambda`,params:r.params.map((e,n)=>({name:t?e.name:`r#${n}`,shape:0})),body:Ei(t,r.body)}]}}return ot(n,e=>Ei(t,e),`visible`)},Di=t=>{if(Be(t,`Cdot`)&&t.args.length===1&&t.args[0].kind!==`Lambda`)throw new e.U;return ot(t,Di,`visible`)},Oi=(e,t,n,r,i,a)=>{let o=wi(i,t,void 0,void 0,n,r);return Ei(a,e.expr(n,Ti(P(0),o)))},ki={isEnabled:!0,isCdot:!0,isAutoUse:!0},Ai=(e,t,n,r,i=ki)=>{let a=bi(i,t,n,i.isEnabled?Qn(r):r,void 0);return Di(Oi(e,t,n,a,i,!1))},ji=(t,n,r,i,a)=>{let o=(e,i)=>({kind:`Quant`,quantifier:`Exists`,bounds:e.map(e=>({name:e.name,level:`Constant`,domain:{kind:`NoDomain`}})),body:ji(t,n,M(r,e.map(Ze)),i,!0)}),s=e=>e===`ENABLED`?t.isEnabled:t.isCdot;if(i.kind===`Apply`&&i.args.length===1){let e=i.operator,[a]=i.args;if(a.kind===`Lambda`){if(e.kind===`Opaque`&&(t.isEnabled&&e.name===li||t.isCdot&&e.name===ui))return o(a.params,a.body);if(e.kind===`Ix`&&(t.isEnabled||t.isCdot)){let t=mi(r,e.index);if(t.kind===`Defn`&&t.definition.kind===`Operator`&&(t.definition.name===li||t.definition.name===ui))return o(a.params,a.body)}if(hi(e)&&s(e.builtin))return o(a.params,a.body)}if(hi(e)&&s(e.builtin))return ji(t,n,r,a,!0)}if(Be(i,`ENABLED`)&&a)throw n(D(i.location,di)),new e.j(`Expr.Action`);if(Be(i,`Cdot`)&&a)throw n(D(i.location,pi)),new e.j(`Expr.Action`);return at(r,i,(e,r)=>ji(t,n,e,r,a),j)},Mi=t=>{if(t.kind===`Quant`&&t.quantifier===`Exists`){let n=t.body;if(n.kind===`List`&&n.bullet===`Or`)return Mi({...n,items:n.items.map(e=>({...t,body:e}))});if(Be(n,`Disj`)){if(n.args.length!==2)throw new e.U;return Mi({...n,args:n.args.map(e=>({...t,body:e}))})}}return ot(t,Mi,`visible`)},Ni=(e,t,n,r,i)=>{let a=bi(i,t,n,r,void 0),o=Oi(e,t,n,a,i,!0);return Mi(ji(i,t,n,o,!1))},Pi=Je(Le,`Visible`,`Always`,void 0),Fi=(e,t,n)=>n.kind===`Ix`?e[t-n.index]:void 0,Ii=e=>e?.kind===`Defn`&&e.definition.kind===`Bpragma`&&e.definition.name===`ENABLEDaxioms`,Li=(t,n,r,i)=>{let a={isUsed:!1},o=(e,t)=>{if(!i)return{hyps:0,sequent:0};let n=si(M(void 0,e),t.sequent.context);return{hyps:n.level,sequent:Math.max(n.level,ci(n.scope,t.sequent.active).level)}},s=(t,n,o)=>{let s=t.context;if(!i)return a.isUsed||=s.some((e,t)=>e.kind===`Fact`&&Ii(Fi(s,t,e.expression))),n;let c=Ge(void 0,s,(e,t)=>[j(e,t),e])[1],l=s.flatMap((e,t)=>e.kind===`Fact`&&e.visibility===`Visible`&&e.expression.kind!==`At`?[{expression:e.expression,index:t}]:[]),u=l.some(e=>Ii(Fi(s,e.index,e.expression)));if(o&&!u)return{...n,isEnabledAxiomsSound:!0};let d=Math.max(0,...l.map(n=>{let r=Fi(s,n.index,n.expression);if(!r)return ci(c[n.index],n.expression).level;if(!o&&r.kind===`Fact`&&r.visibility===`Visible`)throw new e.U;return r.kind===`Defn`&&r.definition.kind===`Operator`&&r.visibility===`Visible`?t.stepLevels.get(r.definition.name)??0:0}));return o||(t.level.value=Math.max(t.level.value,d)),!u||d<=1?{...n,isEnabledAxiomsSound:!0}:(r(D(n.location,`ENABLEDaxioms depends on assumption of expression level > 1`)),{...n,isEnabledAxiomsSound:!1})},c=(t,n)=>{if(!n.step)throw new e.U;let i=lr(n.step),a=new Map(t.stepLevels);a.delete(i);let s=Lr(n,Le,`Always`);switch(n.kind){case`Forget`:{let e=t.context.length,r=t.context.map((t,r)=>t.kind===`Fact`&&t.visibility===`Visible`&&n.count+r<e?{...t,visibility:`Hidden`}:t);return[{...t,stepLevels:a,context:r},n]}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>Hr(`Hidden`,e,t),t.context),i=n.usable.facts.reduceRight((e,t)=>Wr(r,`Hidden`,t,e),e);return[{...t,stepLevels:a,context:i},n]}case`Assert`:{let e=o(t.context,n),r={value:0},c=l({context:[...t.context,...n.sequent.context,Pi,s,Pi],level:r,stepLevels:new Map(a).set(i,e.hyps)},n.proof);return t.level.value=r.value<2?r.value:Math.min(e.sequent,r.value),[{context:[...t.context,s,Pi],level:t.level,stepLevels:a.set(i,t.level.value)},{...n,proof:c}]}case`Suffices`:{let e=o(t.context,n);t.level.value=e.sequent;let r={value:0},c=l({context:[...t.context,s,Pi],level:r,stepLevels:new Map(a).set(i,e.sequent)},n.proof);return[{context:[...t.context,...n.sequent.context,Pi,s,Pi],level:r,stepLevels:a.set(i,e.hyps)},{...n,proof:c}]}case`Use`:{let e=n.usable.facts;if(n.usable.defs.length===0&&e.length===1){let r=Je(e[0],`Visible`,`Always`,e[0].location);return[{...t,stepLevels:a,context:[...t.context,r]},n]}let r=[...t.context,...e.map(()=>Pi)];return[{...t,stepLevels:a.set(i,1),context:r},n]}case`Define`:{let e=[...t.context,...n.definitions.map(Rr)];return[{...t,stepLevels:a.set(i,1),context:e},n]}default:throw new e.U}},l=(e,t)=>{switch(t.kind){case`Omitted`:case`Error`:return t;case`Obvious`:return s(e,t,!1);case`By`:return s(e,t,t.isOnly);case`Steps`:{let[n,r]=Ge(e,t.steps,c),i={...t.qed,proof:l(n,t.qed.proof)};return{...t,steps:r,qed:i}}}},u=l({context:t,level:{value:0},stepLevels:/* @__PURE__ */ new Map},n);return{isUsed:a.isUsed,proof:u}},Ri=(e,t,n)=>Li(e,t,n,!1).isUsed?Li(e,t,n,!0).proof:t,zi=(t,n,r,i)=>{try{let r=Ai(t.anonymizer,t.onWarning,n,{kind:`Sequent`,sequent:i});if(r.kind!==`Sequent`)throw new e.U;return r.sequent}catch(n){if(!(n instanceof e.A)||n.failure===void 0)throw n;let a=i.active.location,o=`${n.failure}\nCould not instantiate the theorem ${r===void 0?``:`named: ${r}, `}at: ${Ne(a)}`;return t.onWarning({text:`${Pe(a)}[ERROR]${o}`,channel:`stdout`}),t.onWarning({text:o,channel:`toolboxOnly`}),{context:[],active:Re(i.active)}}},Bi=(e,t,n)=>{if(n.kind===`Theorem`)return{...n,sequent:zi(e,t,n.name,n.sequent)};if(n.kind!==`Definition`)return n;let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)return n;let i=Ai(e.anonymizer,e.onWarning,t,r.body);return{...n,definition:{...r,body:i}}},Vi=(e,t,n)=>Ge(t,n,(t,n)=>{if(n.kind===`Submod`){let[r,i]=Vi(e,t,n.module.body);return[r,{...n,module:{...n.module,body:i}}]}let r=Bi(e,t,n);return[M(t,Cr(r)),r]}),Hi=(t,n)=>{let r=[],i=0,a=t;for(;a.length>0;){let[t,...o]=a,s=t.kind===`Constants`?{name:t.declarations[0].name,remaining:{...t,declarations:t.declarations.slice(1)}}:t.kind===`Variables`?{name:t.names[0],remaining:{...t,names:t.names.slice(1)}}:void 0;if(s){let t=n.get(s.name);if(!t)throw new e.A(`Parameter ${s.name} has no substitute`);let r=wr(s.remaining)===0;a=Nr(ct(I(i,t),P(0)),r?o:[s.remaining,...o])}else r.push(t),i+=wr(t),a=o}return r},Ui=(e,t,n)=>{let r=Array.from({length:t},(e,r)=>k({kind:`Ix`,index:t-r},{location:n})),i=Array.from({length:t},(e,t)=>k({kind:`Ix`,index:t+1},{location:n})),a=Array.from({length:e},(e,i)=>{let a=k({kind:`Ix`,index:i+t+1},{location:n});return t>0?k({kind:`Apply`,operator:a,args:r},{location:n}):a});return lt([...a,...i].reverse(),P(e+t))},Wi=(e,t)=>{let n=t.map(e=>({name:e,shape:0}));return e.kind===`Lambda`?{...e,params:[...n,...e.params]}:t.length===0?e:k({kind:`Lambda`,params:n,body:e},e)},Gi=(t,n,r,i,a,o)=>{let s=e=>r===``?e:`${r}!${e}`,c=i.args.length,l=[],u=0,d=n,f=c===0,p=e=>{f||(f=!0,t.onWarning({text:e,channel:`stderr`}))};for(;d.length>0;){let[n,...r]=d;d=r;let f=e=>Wi(F(Ui(u,c,o),e),i.args);switch(n.kind){case`Definition`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e.A(`Module.Elab.localize`);let i=n.isLocal?`${r.name}$${ur(t.salts)}`:r.name;l.push({...n,definition:{...r,name:s(i),body:f(r.body)},whereDefined:n.isLocal?`Builtin`:n.whereDefined,isLocal:n.isLocal||a}),u+=1;continue}case`Axiom`:{p(`${Ie(o)}Instancing produces parametric axioms.\nSuch axioms will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`);let e={...n,name:n.name===void 0?void 0:s(n.name),expression:f(n.expression)};l.push(e),u+=wr(e);continue}case`Theorem`:{p(`${Pe(o)}Warning: Instancing produces parametric theorems.\nSuch theorems will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`);let e=f(k(Ve(n.sequent),n));l.push({...n,name:n.name===void 0?void 0:s(n.name),sequent:e.kind===`Sequent`?e.sequent:{context:[],active:e},proof:{kind:`Omitted`,omission:`Elsewhere`,location:n.location}}),u+=1;continue}case`Mutate`:n.mode===`Use`&&(d=Nr(P(-n.usable.facts.length),d));continue;case`Submod`:continue;default:throw new e.A(`Module.Elab.localize`)}}return l},Ki=e=>{let t=[],n=e;for(;n.length>0;){let[e,...r]=n;if(e.kind!==`Axiom`){t.push(e),n=r;continue}let i=e.location;e.name!==void 0&&t.push({kind:`Definition`,definition:{kind:`Operator`,name:e.name,body:e.expression,location:i},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:i});let a=Je(e.name===void 0?I(1,e.expression):k({kind:`Ix`,index:2},e),`Visible`,`Always`,i),o=0,s=r.map(e=>{let t=o;if(o+=wr(e),e.kind!==`Theorem`)return e;let n=_t(P(1),e.sequent);return{...e,sequent:{...n,context:[gt(P(t),a),...n.context]},axiomCount:e.axiomCount+1}});n=Nr(P(-1),s)}return t},qi=e=>new Set(e.body.flatMap(e=>e.kind===`Constants`?e.declarations.map(e=>e.name):e.kind===`Variables`?e.names:[])),Ji=(t,n,r,i,a,o,s)=>{let c=n.get(i.module);if(!c)throw new e.A(`Module "${i.module}" unknown`);let l=qi(c);for(let n of i.substitutions)if(!l.has(n.name))throw t.onWarning({text:`${Ie(n.location)}Parameter ${n.name} occurs in the statement \`INSTANCE ${i.module} WITH\`, and is not declared in the module ${i.module}\n`,channel:`toolbox`}),new e.A(`Module.Elab.instance_substitutes_declared_identifiers`,{failure:`Module.Elab.instance_substitutes_declared_identifiers`});let u=M(r,i.args.map(e=>N(e,`Unknown`))),d=new Map(i.substitutions.map(e=>[e.name,e.expression]));for(let n of[...l].sort(Ar))if(!d.has(n)){if(!Ue(u,n)){let r=`Required parameter ${n} for module ${i.module} could not be inferred.`;throw t.onWarning({text:`${Ie(i.instanceLocation)}${r}\n`,channel:`toolbox`}),new e.A(r,{failure:`Module.Elab.complete_with_statement_params`})}d.set(n,k({kind:`Opaque`,name:n},{location:s}))}let f=new Map([...d].map(([e,n])=>[e,t.anonymizer.expr(u,n)])),p=Nr(P((u?.size??0)-(c.depth??0)),c.body.map(e=>e.kind===`Theorem`?{...e,proof:{kind:`Omitted`,omission:`Implicit`,location:e.proof.location}}:e)),[,m]=Vi(t,u,p);return Ki(Gi(t,Hi(m,f),o,i,a,s))},Yi=(t,n,r)=>{let i=r.instance.module;if(!t.latestModules.has(i))throw t.onWarning({text:`${Ie(r.instance.location)}Module ${JSON.stringify(i)} unknown\n`,channel:`toolbox`}),new e.A(`Module ${JSON.stringify(i)} unknown`,{failure:`Module.Elab.anon#defns`});let a=Ji(t,t.latestModules,n,r.instance,!0,r.name,r.location),o=[],s=a;for(;s.length>0;){let[e,...t]=s;e.kind===`Definition`?(o.push(e.definition),s=t):s=Nr(P(-wr(e)),t)}return o},Xi=(e,t,n,r)=>{let i=[],a=n,o=e=>{i.push(e),a=M(a,Cr(e))},s=e=>e!==void 0&&Ue(a,e)!==void 0,c=r.body.map(e=>({unit:e,isAnonymized:!1}));for(let n=0;n<c.length;n++){let i=c[n].unit,l=(r,o,s)=>{let l=Ji(e,t,a,r,o,s,i.location);c.splice(n+1,0,...l.map(e=>({unit:e,isAnonymized:!0})))};switch(i.kind){case`Anoninst`:l(i.instance,i.isLocal,``);continue;case`Definition`:{let t=i.definition;if(t.kind===`Instance`){l(t.instance,i.isLocal,t.name);continue}let r=t.kind===`Recursive`||c[n].isAnonymized?t:e.anonymizer.defn(a,t),s={...i,definition:r};if(t.kind===`Recursive`){o(s);continue}let u=Cr(s)[0],d=Ue(a,t.name);if(d?.hyp.kind===`Defn`&&(d.hyp.definition.kind===`Recursive`||wt(gt(P(d.depth+1),d.hyp),u))){let e=c.slice(n+1),t=Nr(ct(k({kind:`Ix`,index:d.depth+1},i),P(0)),e.map(e=>e.unit));c.splice(n+1,e.length,...e.map((e,n)=>({...e,unit:t[n]})));continue}o(s);continue}case`Recursives`:case`Constants`:case`Variables`:o(i);continue;case`Axiom`:if(s(i.name))continue;e.latestModules=new Map(t),o({...i,expression:e.anonymizer.expr(a,i.expression)});continue;case`Theorem`:{let n=s(i.name),c=n?`(redundant)${i.name}`:i.name,l=n?{kind:`Obvious`,location:i.proof.location}:i.proof;e.latestModules=new Map(t);let u=e.anonymizer.sequent(a,i.sequent),d=Pr(c,u,i.location),f=M(M(a,d.hyps.map(e=>({...e,isConstnessUnset:!0}))),d.sequent.context),p=e.anonymizer.proof(f,l),m=He(f),h=r.isImportant?Ri(m,e.simplify(m,d.sequent.active,p,cr(d.sequent.context,`Always`)),e.onWarning):p;o({...i,name:c,sequent:u,proof:h});continue}case`Mutate`:e.latestModules=new Map(t),o({...i,usable:e.anonymizer.usable(a,i.usable)});continue;case`Submod`:o({...i,module:Xi(e,t,a,i.module)});continue}}let l={...r,body:i,depth:n?.size??0};return t.set(r.name,l),l},Zi=e=>({location:e.location,step:e.step,method:e.method,isSuppressed:e.isSuppressed}),Qi=e=>e?.level??0,$i=(e,t,n)=>Je(t,`Visible`,sr(M(void 0,e),t),n),ea=(e,t)=>Be(e,t)&&e.args.length===2,ta=(e,...t)=>en(z(e,...t)),na=e=>ra(e).map((e,t)=>{let n=e.domain.kind===`Domain`?I(t,e.domain.expression):void 0;return{kind:`Fresh`,name:e.name,shape:0,level:n?`Constant`:e.level,domain:n,domainVisibility:`Visible`}}),ra=e=>{let t={kind:`NoDomain`};return e.map(e=>e.domain.kind===`Ditto`?{...e,domain:t}:(t=e.domain,e))},ia=(e,t)=>{let n=mt(P(1),t)[1];return n[0].domain.kind===`Ditto`&&e.domain.kind===`Domain`?[{...n[0],domain:{kind:`Domain`,expression:I(1,e.domain.expression)}},...n.slice(1)]:n},aa=(e,t)=>{if(t.length===0||e.isSuppressed)return{kind:`Obvious`,...Zi(e)};let n=t.map((t,n)=>{let r=I(2*n+2,t);return{kind:`Assert`,sequent:{context:[],active:r},proof:{kind:`By`,usable:{facts:[I(3,r)],defs:[]},isOnly:!1,location:t.location,method:e.method},location:t.location}}),r={kind:`By`,usable:{facts:[k({kind:`Ix`,index:2*t.length+2},e),...t.map((n,r)=>k({kind:`Ix`,index:2*(t.length-r)},e))],defs:[]},isOnly:!0,...Zi(e),method:void 0};return{kind:`Steps`,steps:n,qed:{proof:r,location:r.location},...Zi(e)}},oa=(e,t)=>e.kind===`At`&&!e.isExcept?k($e(t),e):ot(e,e=>oa(e,t)),sa=t=>{let n=e=>({kind:`Named`,level:e,label:`_a${ur(t)}`,isAnonymous:!0}),r=(e,t)=>t?.kind===`Named`?{...t,level:e}:n(e),i=(e,t)=>{let n={...t,step:r(e,t.step)};if(n.kind!==`Steps`)return n;let o=n.steps.map(t=>a(e,t));return{...n,steps:o,qed:{...n.qed,proof:i(e+1,n.qed.proof)}}},a=(e,t)=>{let n={...t,step:r(e,t.step)};return`proof`in n?{...n,proof:i(e+1,n.proof)}:n},o=(t,n)=>{let r=n.kind===`Apply`?n.operator:n;if(r.kind===`Ix`){let i=t[t.length-r.index];if(!i)throw new e.A(`expose_connective`);if(i.kind!==`Defn`||i.definition.kind!==`Operator`)return n;let a=I(r.index,i.definition.body);if(n.kind!==`Apply`)return o(t,a);let s={...a,location:n.location};return o(t,k(pt(s,n.args),s))}if(Be(n,`Prime`)){let e=o(t,n.args[0]),r=e=>A(`Prime`,[e],e);return e.kind===`Quant`?k({kind:`Quant`,quantifier:e.quantifier,bounds:et(e.bounds,r),body:r(e.body)},n):ea(e,`Implies`)||ea(e,`Mem`)?k({kind:`Apply`,operator:e.operator,args:[r(e.args[0]),r(e.args[1])]},n):r(e)}return n.kind===`Parens`?o(t,n.expression):n},s=e=>{if(e.kind!==`Assert`)return;let t=e.sequent.active;return t.kind===`Apply`&&t.args.length===2?t.args[1]:void 0},c=e=>{if(e.kind!==`Steps`)return e;let t=[];return e.steps.forEach(e=>{let n=t.at(-1),r=n&&s(n);if(e.kind!==`Assert`||!r){t.push(e);return}let i=oa(e.sequent.active,I(2,r));t.push({...e,sequent:{...e.sequent,active:i}})}),{...e,steps:t}},l=(e,t,r,i)=>{let a=c(r);switch(a.kind){case`Obvious`:case`Omitted`:case`Error`:return a;case`By`:{let e=a.usable,t=e.defs.length===0?[]:[{kind:`Use`,usable:{facts:[],defs:e.defs},isOnly:!1,location:a.location}],r=e.facts.map((e,t)=>({kind:`Use`,usable:{facts:[I(t,e)],defs:[]},isOnly:!1,location:e.location,useLocation:a.location,isSuppressed:a.isSuppressed})),i=a.isOnly?[{kind:`Forget`,count:e.facts.length,location:a.location}]:[],o=Qi(a.step),s=[...t,...r,...i].map(e=>({...e,step:n(o)})),c={kind:`Obvious`,location:a.location,step:n(o),method:a.method,isSuppressed:a.isSuppressed};return{kind:`Steps`,steps:s,qed:{proof:c,location:c.location,step:c.step},location:a.location,step:a.step}}case`Steps`:{let[n,r]=Ge({context:e,goal:t,time:i},a.steps,(e,t)=>{let n=u(e.context,e.goal,t,e.time);return[n,n.steps]}),o=l(n.context,n.goal,a.qed.proof,n.time);return{...a,steps:r.flat(),qed:{...a.qed,proof:o}}}}},u=(t,n,r,i)=>{let s=Qi(r.step);switch(r.kind){case`Forget`:return{context:t,goal:n,steps:[r],time:i};case`Assert`:{let e=zr(t,r.sequent,r,i),a={...r,proof:l(e.context,e.active,r.proof,e.time)},o=Br(!1,t,n,r.sequent,a,i);return{context:o.context,goal:o.active,steps:[a],time:i}}case`Suffices`:{let e=Br(!0,t,n,r.sequent,r,i),a={...r,proof:l(e.context,e.active,r.proof,i)},o=zr(t,r.sequent,a,i);return{context:o.context,goal:o.active,steps:[a],time:o.time}}case`Use`:{let a={kind:`By`,usable:r.usable,isOnly:r.isOnly,location:r.location,step:r.step,method:r.method,isSuppressed:r.isSuppressed},o=l(t,n,a,i);if(o.kind!==`Steps`)throw new e.A(`simplifying BY does not produce a non-leaf proof!`);let s=r.usable.facts.map(()=>Je(Le,`Visible`,i,r.location));return{context:[...t,...s],goal:I(r.usable.facts.length,n),steps:o.steps,time:i}}case`Hide`:return{context:r.usable.defs.reduce((t,n)=>{if(n.kind!==`Dx`)throw new e.A(`set_vis`);let i=t.length-n.index,a=t[i];if(a?.kind!==`Defn`){let t=a?a.kind===`Fact`?`??? FACT ???`:a.name:``;throw new e.A(`USE DEF ${t} invalid because ${t} is not a defined operator`)}return t.map((e,t)=>t===i?{...a,visibility:`Hidden`,location:r.location}:e)},t),goal:n,steps:[r],time:i};case`Define`:return{context:[...t,...r.definitions.map(e=>Ye(e,{kind:`Proof`,time:i},`Visible`,!0,r.location))],goal:I(r.definitions.length,n),steps:[r],time:i};case`Have`:{let e=o(t,n),c=ea(e,`Implies`),l={context:[$i(t,r.expression,r.location)],active:c?I(1,e.args[1]):e},d=c?{kind:`By`,usable:{facts:[k({kind:`Ix`,index:2},r)],defs:[]},isOnly:!0,...Zi(r)}:{kind:`Error`,message:ta(`@.@[<v2>@[%s@ %s@]@,%a@]@.`,`Error: this HAVE step is applied to the following goal,`,`which is not an implication:`,En(t,n)),...Zi(r)},f=a(s,{kind:`Suffices`,sequent:l,proof:d,location:r.location,step:r.step});return u(t,n,f,i)}case`Take`:return u(t,n,a(s,f(t,n,r)),i);case`Witness`:return u(t,n,a(s,p(t,n,r)),i);case`Pcase`:{let e={kind:`Assert`,sequent:{context:[$i(t,r.expression,r.location)],active:I(1,n)},proof:r.proof,...Zi(r)};return u(t,n,a(s,e),i)}case`Pick`:{let a=k({kind:`Quant`,quantifier:`Exists`,bounds:r.bounds,body:r.expression},r),o=d(r.step,`ex`),s=u(t,n,{kind:`Assert`,sequent:{context:[],active:a},proof:r.proof,...Zi(r),step:o},i),c=I(2,a);if(c.kind!==`Quant`)throw new e.A(`Proof.Simplify.simplify_step/PICK`);let l=na(c.bounds),f=[...l,$i([...s.context,...l],c.body,c.body.location)],p=u(s.context,s.goal,{kind:`Suffices`,sequent:{context:f,active:I(f.length,s.goal)},proof:{kind:`Omitted`,omission:`Elsewhere`,...Zi(r)},...Zi(r)},s.time);return{...p,steps:[...s.steps,...p.steps]}}}},d=(e,n)=>({kind:`Named`,level:Qi(e),label:`${e?.kind===`Named`?e.label:`_a`}${n}${ur(t)}`,isAnonymous:!1}),f=(e,t,n)=>{let r=ra(n.bounds),i=(t,n,r,a)=>{let s=a[0];if(!s)return{sideFacts:n,goal:r};let c=o(e,r);if(c.kind!==`Quant`||c.quantifier!==`Forall`||c.bounds.length===0)return ta(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this TAKE step is applied to the following goal,`,`which is not a universal formula:`,En(e,r));let l=c.bounds[0],u=ra(c.bounds).slice(1),d=s.domain,f=l.domain;if(d.kind===`NoDomain`&&f.kind===`Domain`)return ta(`@.@[<b0>%s (%s)@ %s (%s \\in %a)@]@.`,`Error: the TAKE argument`,s.name,`does not match the pattern`,l.name,En(e,f.expression));if(d.kind===`Domain`&&f.kind===`NoDomain`)return ta(`@.@[<b0>%s (%s \\in %a)@ %s (%s)@]@.`,`Error: the TAKE argument`,s.name,En(e,d.expression),`does not match the pattern`,l.name);let p=d.kind===`Domain`&&f.kind===`Domain`&&!L(d.expression,f.expression)?[{kind:`Apply`,operator:{kind:`Internal`,builtin:`Subseteq`},args:[f.expression,d.expression],location:s.location},...n]:n;if(u.length===0)return i(1,p,c.body,a.slice(1));let m=a.length===1?u.map(e=>mt(P(t),[e])[1][0]):u;return i(t+1,p,k({kind:`Quant`,quantifier:`Forall`,bounds:m,body:c.body},c),a.slice(1))},a=i(1,[],t,r);if(typeof a==`string`)return{kind:`Suffices`,sequent:{context:[Je(Re(t),`Visible`,`Now`,n.location)],active:t},proof:{kind:`Error`,message:a,...Zi(n)},...Zi(n)};let s=a.sideFacts.filter((e,t)=>a.sideFacts.findIndex(t=>L(e,t))===t),c=[k({kind:`Ix`,index:2},n),...s.map(e=>I(2,e))];return{kind:`Suffices`,sequent:{context:na(r),active:a.goal},proof:{kind:`By`,usable:{facts:c,defs:[]},isOnly:!0,...Zi(n)},...Zi(n)}},p=(e,t,n)=>{let r=[],i=``,a=t;for(let t of n.expressions){let n=o(e,a);if(n.kind!==`Quant`||n.quantifier!==`Exists`||n.bounds.length===0){i||=ta(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this WITNESS step is applied to the following goal,`,`which is not an existential formula:`,En(e,n)),a=n;break}let[s,...c]=n.bounds,l=c.length===0?n.body:k({kind:`Quant`,quantifier:`Exists`,bounds:ia(s,c),body:n.body},n),u=t;if(s.domain.kind===`Domain`){let n=s.domain.expression,a=o(e,t);if(ea(a,`Mem`)){let[e,t]=a.args,i=L(t,n)?[]:[A(`Subseteq`,[t,n],t)];r.push(...i,a),u=e}else i||=ta(`@.@[<b0>%s (%a)@ %s (%s \\in %a)@]@.`,`Error: the WITNESS argument`,En(e,a),`does not match the pattern`,s.name,En(e,n)),u=a}let d=A(`Unprimable`,[u],u);a=F(ct(d,P(0)),l)}let s=i===``?aa(n,r):{kind:`Error`,message:i,...Zi(n)};return{kind:`Suffices`,sequent:{context:[],active:a},proof:s,...Zi(n)}};return l},ca=[`(`,`)`,`;`,`:`,`@`,`,`],la=e=>e===` `||e===`\r`||e===` `,ua=(e,t)=>{for(;t.line<e.length;){let n=e[t.line];for(;la(n[t.column]);)t.column++;if(t.column<n.length)return;t.line++,t.column=0}},da=(e,t)=>{let n={...t};return ua(e,n),(e[n.line]??``).startsWith(`(*{`,n.column)?n:void 0},fa=(e,t)=>{let n=da(e,t);if(!n)return;let r={line:n.line,column:n.column+3},i=[];for(ua(e,r);r.line<e.length;ua(e,r)){let t=e[r.line].slice(r.column);if(t.startsWith(`}*)`))return i;let n=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t)??/^\d+(\.\d+)?/.exec(t)??/^"(\\.|[^"\\])*"/.exec(t);if(n){let e=n[0],t=e.startsWith(`"`);i.push({kind:t?`String`:/^\d/.test(e)?`Number`:`Ident`,text:t?JSON.parse(e):e,start:{...r},length:e.length}),r.column+=e.length}else{if(!ca.includes(t[0]))return;i.push({kind:`Punct`,text:t[0],start:{...r},length:1}),r.column++}}},pa=(e,t)=>e?.kind===`Punct`&&e.text===t,ma=e=>e?.kind===`String`?{kind:`String`,value:e.text}:e?.kind===`Number`?{kind:`Float`,value:Number.parseFloat(e.text)}:pa(e,`@`)?{kind:`Default`}:void 0,ha=/* @__PURE__ */ new Map([[`smt`,`smt`],[`cvc3`,`cvc4`],[`yices`,`yices`],[`z3`,`z3`],[`cooper`,`cooper`],[`presburger`,`cooper`],[`fail`,`fail`],[`smt2lib`,`smt`],[`smt2z3`,`z3`],[`smt3`,`smt`],[`z33`,`z3`],[`cvc33`,`cvc4`],[`yices3`,`yices`],[`verit`,`verit`],[`zipper`,`zipper`],[`spass`,`spass`],[`tptp`,`tptp`],[`ls4`,`ls4`],[`expandenabled`,`expandenabled`],[`expandcdot`,`expandcdot`],[`autouse`,`autouse`],[`lambdify`,`lambdify`],[`enabledaxioms`,`enabledaxioms`],[`levelcomparison`,`levelcomparison`],[`trivial`,`trivial`]]),ga=(e,t)=>{let n=fa(e,t);if(!n)return;let r=0,i=()=>{let e=n[r];return e?.kind===`Number`?(r++,{timeout:Number.parseFloat(e.text)}):{}},a=()=>{if(!pa(n[r],`(`))return;r++;let e=n[r++];if(e?.kind!==`Ident`)return;let t=(()=>{if(e.text===`isabelle`){let t=n[r];return t?.kind===`String`?(r++,{name:e.text,tactic:t.text,...i()}):void 0}if(e.text===`zenon`){let t=i();return pa(n[r],`(`)&&!a()?void 0:{name:e.text,...t}}let t=ha.get(e.text);return t===void 0?void 0:{name:t}})();if(t&&pa(n[r],`)`))return r++,t};if(n[r]?.kind!==`Ident`||n[r++].text!==`by`)return;let o=a();return r===n.length?o:void 0},_a=(e,t,n)=>{let r=fa(e,t);if(!r)return;let i=0,a=[];for(;i<r.length;){let e=r[i++];if(e.kind!==`Ident`||e.text!==`by`&&e.text!==`set`||!pa(r[i],`(`))return;i++;let t=[];for(;;){let e=r[i++];if(e?.kind!==`Ident`||!pa(r[i],`:`))return;i++;let a=ma(r[i++]);if(!a)return;if(t.push({hint:e.text,value:a,location:{file:n,startLine:e.start.line+1,startColumn:e.start.column+1,endLine:e.start.line+1,endColumn:e.start.column+1+e.length}}),pa(r[i],`)`))break;if(!pa(r[i],`;`))return;i++}i++,a.push(t)}return a},va=(e,t)=>{let n={...t};for(;e[n.line].slice(0,n.column).trimEnd()===``;){if(n.line===0)return;n.line--,n.column=e[n.line].length}if(e[n.line].slice(0,n.column).trimEnd().endsWith(`}*)`))for(let t=n.line;t>=0;t--){let r=e[t].lastIndexOf(`(*{`,t===n.line?n.column:void 0);if(r===-1)continue;let i=fa(e,{line:t,column:r});return i?.length===1&&i[0].kind===`Ident`&&(i[0].text===`_`||i[0].text===`suppress`)?{line:t,column:r}:void 0}},ya=e=>({kind:`Opaque`,name:e}),ba=e=>({kind:`Tuple`,elements:e.map(ya)}),xa=(e,t)=>({kind:`Apply`,operator:{kind:`Internal`,builtin:`Eq`},args:[e,t]}),Sa=e=>e.map(e=>({name:e,level:`Constant`,domain:{kind:`NoDomain`}})),Ca=(e,t)=>e?.kind===`Product`&&e.factors.length===t.length?e.factors:void 0,wa=(e,t)=>t.map((t,n)=>({kind:`Operator`,name:t,body:{kind:`FcnApp`,function:ya(e),args:[{kind:`Num`,integer:String(n+1),fraction:``}]}})),Ta=(e,t)=>e.map((e,n)=>({name:e,level:`Constant`,domain:{kind:`Domain`,expression:t[n]}})),Ea=e=>({name:e.name,level:`Constant`,domain:e.domain}),Da=(e,t,n)=>{let r=[];return t.forEach(e=>{e.kind===`Name`&&e.domain.kind===`Ditto`?r.at(-1)?.push(e):r.push([e])}),r.reduceRight((t,n)=>{let r=(n,r=t)=>({kind:`Quant`,quantifier:e,bounds:n,body:r,location:t.location}),i=n[0];if(i.kind===`Name`)return r(n.flatMap(e=>e.kind===`Name`?[Ea(e)]:[]));let a=Ca(i.domain,i.names);if(a)return r(Ta(i.names,a));let o={kind:`Apply`,operator:{kind:`Internal`,builtin:e===`Exists`?`Mem`:`Notmem`},args:[ba(i.names),i.domain]};return r(Sa(i.names),{kind:`List`,bullet:e===`Exists`?`And`:`Or`,items:[o,t]})},n)},Oa=(e,t,n)=>{let r=`${e.kind.toLowerCase()}#${t[0]}`;return{...e,name:r,body:Ca(e.domain,t)?{kind:`Let`,definitions:wa(r,t),body:n}:{kind:`Quant`,quantifier:`Exists`,bounds:Sa(t),body:{kind:`List`,bullet:`And`,items:[xa(ya(r),ba(t)),n]}}}},ka=(e,t,n)=>{let r=e.map(e=>{if(e.kind===`Name`)return{bounds:[Ea(e)],definitions:[]};let t=Ca(e.domain,e.names);if(t&&n)return{bounds:Ta(e.names,t),definitions:[]};let r=`fcn#${e.names[0]}`,i={name:r,level:`Constant`,domain:{kind:`Domain`,expression:e.domain}};if(t)return{bounds:[i],definitions:wa(r,e.names)};let a=`choose#${r}`;return{bounds:[i],definitions:[{kind:`Operator`,name:a,body:Oa({kind:`Choose`,domain:void 0},e.names,xa(ya(r),ba(e.names)))},...wa(a,e.names)]}}),i=r.flatMap(e=>e.definitions);return{bounds:r.flatMap(e=>e.bounds),value:i.length===0?t:{kind:`Let`,definitions:i,body:t}}},Aa=(e,t)=>{let n=ka(t,e,!0);return{kind:`SetOf`,element:n.value,bounds:n.bounds}},ja=(e,t)=>{let n=ka(e,t,!1);return{kind:`Fcn`,bounds:n.bounds,body:n.value}},Ma={Always:`[]`,Eventually:`<>`,Enabled:`ENABLED`,Unchanged:`UNCHANGED`},Na=(e,t)=>e!==void 0&&t!==void 0&&e.line===t.line&&e.column===t.column,Pa=e=>e.location.range?.start,Fa=e=>e.location.range?.end,Ia=(e,t)=>{let n=e.location.range;return n&&t?{...e,location:{...e.location,range:{...n,end:t}}}:e},La=e=>{if(e.kind===`Apply`){let t=an(e.operator),n=e.args.length===2&&t.fixity.startsWith(`Infix`),r=e.args.length===1&&t.fixity===`Prefix`;if(!n&&!r)return;let i=e.args.length-1;return{operator:t,isInfix:n,operand:e.args[i],replace:t=>({...e,args:[...e.args.slice(0,i),t]})}}let t=Ma[e.kind];if(t!==void 0&&`expression`in e)return{operator:an(t),isInfix:!1,operand:e.expression,replace:t=>({...e,expression:t})}},Ra=(e,t)=>e.high<t.low,za=e=>{let t=an(e.operator),[n,r]=e.args,i=Fa(e),a=t=>{let n=e.location.range,i=Pa(t);return{...e,args:[t,r],location:n&&i?{...e.location,range:{...n,start:i}}:e.location}},o=(e,n)=>{let r=n?La(e):void 0;if(!r)return{kind:`Reduced`,isFinal:!1};let s=o(r.operand,Na(Fa(r.operand),Fa(e)));return s.kind===`Attached`?{kind:`Attached`,expression:Ia(r.replace(s.expression),i)}:!s.isFinal&&(Ra(t,r.operator)||r.isInfix&&t.fixity===`InfixLeft`&&r.operator.fixity===`InfixLeft`&&!Ra(r.operator,t))?{kind:`Reduced`,isFinal:!Ra(t,r.operator)}:{kind:`Attached`,expression:Ia(r.replace(a(r.operand)),i)}},s=o(n,Na(Pa(n),Pa(e)));return s.kind===`Attached`?s.expression:e},Ba=new Map(Object.entries({"=>":`Implies`,"<=>":`Equiv`,"/\\":`Conj`,"\\/":`Disj`,"~":`Neg`,"=":`Eq`,"#":`Neq`,SUBSET:`SUBSET`,UNION:`UNION`,DOMAIN:`DOMAIN`,"\\subseteq":`Subseteq`,"\\in":`Mem`,"\\notin":`Notmem`,"\\":`Setminus`,"\\cap":`Cap`,"\\cup":`Cup`,"'":`Prime`,"~>":`Leadsto`,ENABLED:`ENABLED`,UNCHANGED:`UNCHANGED`,"\\cdot":`Cdot`,"-+->":`Actplus`,"[]":`BoxTrue`,"<>":`Diamond`,TRUE:`TRUE`,FALSE:`FALSE`,BOOLEAN:`BOOLEAN`,STRING:`STRING`})),Va=e=>an(e).name,Ha=/^<(\d+|\*|\+)>([A-Za-z0-9_]*)\.*$/,Ua=(e,t)=>{if(!e||!t)return e??t;let n=e.startLine<t.startLine||e.startLine===t.startLine&&e.startColumn<=t.startColumn,r=e.endLine>t.endLine||e.endLine===t.endLine&&e.endColumn>=t.endColumn;return{file:e.file,startLine:n?e.startLine:t.startLine,startColumn:n?e.startColumn:t.startColumn,endLine:r?e.endLine:t.endLine,endColumn:r?e.endColumn:t.endColumn}},Wa="use instead the class`E_visit.iter_concrete`",Ga=(e,t)=>t>0&&e[t-1].set===e[t].set,Ka=(t,n,r,i)=>{let a=n.split(`
119
+ `),o=e=>({file:t,startLine:e.start.line,startColumn:e.start.column,endLine:e.end.line,endColumn:e.end.column+1}),s=e=>{let t=da(a,{line:e.endLine-1,column:e.endColumn-1});if(!t)return e;for(let n=t.line;n<a.length;n++){let r=a[n].indexOf(`}*)`,n===t.line?t.column:0);if(r!==-1)return{...e,endLine:n+1,endColumn:r+4}}return e},c=e=>e&&ga(a,{line:e.end.line-1,column:e.end.column}),l=e=>va(a,{line:e.start.line-1,column:e.start.column-1}),u=e=>l(e)!==void 0,d=e=>{let t=c(e),n=o(e);return t?{location:s(n),method:t}:{location:n}},f=(e,t)=>{let n=c(t);return n?k({kind:`With`,expression:e,method:n},e):e},p=(e,n)=>({file:t,startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+n}),m=e=>e.range?o(e.range):p(e,1),h=(e,t)=>{let n=Va(e),r=Ba.get(n);return k(r?{kind:`Internal`,builtin:r}:{kind:`Opaque`,name:n},{location:t})},g=(e,t,n,r)=>{if(e.startsWith(`<`)){let t=k({kind:`Opaque`,name:e},{location:n});return k({kind:`Bang`,expression:t,selectors:[]},{location:n})}let i=Ba.get(e);if(i&&t.length===0)return k({kind:`Internal`,builtin:i},{location:n});let a=e.split(`!`);if(a.length===1){let r=k({kind:`Opaque`,name:e},{location:n});return t.length===0?r:k({kind:`Apply`,operator:r,args:t},{location:n})}let o=r??a.map((e,n)=>n===a.length-1?t.length:0),s=o.map((e,t)=>o.slice(0,t).reduce((e,t)=>e+t,0)),c=e=>t.slice(s[e],s[e]+o[e]),l=k({kind:`Opaque`,name:a[0]},{location:n});return k({kind:`Bang`,expression:o[0]===0?l:k({kind:`Apply`,operator:l,args:c(0)},{location:n}),selectors:a.slice(1).map((e,t)=>({kind:`Label`,label:Va(e),args:c(t+1)}))},{location:n})},_=(t,n)=>t.map((r,i)=>{if(r.pattern.kind===`Tuple`)throw new e.A(`Unexpected tuple declaration`,{failure:Wa});let a=r.pattern.ranges?.[0];return{name:r.pattern.name,level:`Constant`,domain:Ga(t,i)?{kind:`Ditto`}:{kind:`Domain`,expression:S(r.set,n)},...a&&{location:o(a)}}}),v=(e,t)=>e.map((n,r)=>{let i=S(n.set,t);return n.pattern.kind===`Tuple`?{kind:`Tuple`,names:n.pattern.names,domain:i}:{kind:`Name`,name:n.pattern.name,domain:Ga(e,r)?{kind:`Ditto`}:{kind:`Domain`,expression:i}}}),y=t=>{if(t.bounds.some(e=>e.pattern.kind===`Tuple`))throw new e.A(`Unexpected tuple declaration`,{failure:"use instead the class `P_visit.map_concrete`"});return t.names.length>0?Sa(t.names):_(t.bounds,!1)},b=(t,n)=>{if(!i)throw new e.A(`Unexpected tuple declaration`,{failure:Wa});return k(t,{location:n})},x=e=>e.some(e=>e.pattern.kind===`Tuple`),S=(t,n)=>{let r=m(t.location),i=e=>S(e,n),s=(e,t)=>e.length===2?Ua(e[0].location,e[1].location):e.length!==1||!e[0].location?r:t===`Prefix`?Ua({...r,endLine:r.startLine,endColumn:r.startColumn+1},e[0].location):t===`Postfix`?Ua({...r,startLine:r.endLine,startColumn:r.endColumn-1},e[0].location):r,c=(e,t)=>k({kind:`Apply`,operator:{kind:`Internal`,builtin:e},args:[t]},{location:s([t],`Prefix`)});switch(t.kind){case`Number`:return k({kind:`Num`,integer:t.text??String(t.value),fraction:``},{location:r});case`Decimal`:{let[e,n]=t.text.split(`.`);return k({kind:`Num`,integer:e,fraction:n},{location:r})}case`String`:{let e=/"((?:[^"\\]|\\.)*)"$/.exec((a[r.endLine-1]??``).slice(0,r.endColumn-1));return k({kind:`String`,value:e?.[1]??t.value},{location:r})}case`Identifier`:return g(t.name,[],r);case`Apply`:{if(t.args.length===2){let e=za(t);if(e!==t)return i(e)}let e=t.args.map(i),n=an(t.operator);if(n.fixity!==`Nonfix`){let r=p(t.location,1),i=e[0]?.location,a=e.length===2&&i!==void 0&&(r.startLine<i.startLine||r.startLine===i.startLine&&r.startColumn<i.startColumn),o=s(e,n.fixity);return k({kind:`Apply`,operator:h(t.operator,void 0),args:e},{location:a?Ua(r,o):o})}return g(t.operator,e,r,t.argumentCounts)}case`OperatorReference`:return h(t.operator,r);case`Lambda`:return k({kind:`Lambda`,params:t.params.map(e=>({name:e,shape:0})),body:i(t.body)},{location:r});case`And`:case`Or`:{let e=t.operands.map(i);if(t.isBulleted)return k({kind:`List`,bullet:t.kind,items:e},{location:r});let n=t.kind===`And`?`Conj`:`Disj`;return e.reduce((e,t)=>k({kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:[e,t]},{location:Ua(e.location,t.location)}))}case`Prime`:{let e=i(t.expression);return k({kind:`Apply`,operator:{kind:`Internal`,builtin:`Prime`},args:[e]},{location:s([e],`Postfix`)})}case`Unchanged`:return c(`UNCHANGED`,i(t.expression));case`Enabled`:return c(`ENABLED`,i(t.expression));case`If`:return k({kind:`If`,condition:i(t.condition),consequent:i(t.consequent),alternative:i(t.alternative)},{location:r});case`Case`:return k({kind:`Case`,arms:t.arms.map(e=>({condition:i(e.condition),body:i(e.body)})),other:t.other&&i(t.other)},{location:r});case`Let`:return k({kind:`Let`,definitions:[...t.definitions,...t.instances??[]].sort((e,t)=>e.location.line-t.location.line||e.location.column-t.location.column).map(e=>w(e,n)),body:i(t.body)},{location:r});case`Forall`:case`Exists`:return x(t.bounds)?b(Da(t.kind,v(t.bounds,n),i(t.body)),r):k({kind:`Quant`,quantifier:t.kind,bounds:_(t.bounds,n),body:i(t.body)},{location:r});case`UnboundedQuantifier`:{let e=i(t.body),n=t.quantifier;return t.isTemporal?k({kind:`Tquant`,quantifier:n,names:t.names,body:e},{location:r}):k({kind:`Quant`,quantifier:n,bounds:Sa(t.names),body:e},{location:r})}case`Choose`:return t.pattern.kind===`Tuple`?b(Oa({kind:`Choose`,domain:t.set&&i(t.set)},t.pattern.names,i(t.body)),r):k({kind:`Choose`,name:t.pattern.name,domain:t.set&&i(t.set),body:i(t.body)},{location:r});case`SetEnumeration`:return k({kind:`SetEnum`,elements:t.elements.map(i)},{location:r});case`SetFilter`:return t.bound.pattern.kind===`Tuple`?b(Oa({kind:`SetSt`,domain:i(t.bound.set)},t.bound.pattern.names,i(t.predicate)),r):k({kind:`SetSt`,name:t.bound.pattern.name,domain:i(t.bound.set),body:i(t.predicate)},{location:r});case`SetMap`:return x(t.bounds)?b(Aa(i(t.expression),v(t.bounds,n)),r):k({kind:`SetOf`,element:i(t.expression),bounds:_(t.bounds,n)},{location:r});case`Tuple`:return k({kind:`Tuple`,elements:t.elements.map(i)},{location:{...r,startLine:r.endLine,startColumn:r.endColumn-2}});case`FunctionConstruction`:return x(t.bounds)?b(ja(v(t.bounds,n),i(t.body)),r):k({kind:`Fcn`,bounds:_(t.bounds,n),body:i(t.body)},{location:r});case`FunctionSet`:return k({kind:`Arrow`,domain:i(t.domain),range:i(t.range)},{location:r});case`Record`:case`RecordSet`:return k({kind:t.kind===`Record`?`Record`:`Rect`,fields:t.fields.map(e=>({name:e.name,value:i(e.value)}))},{location:r});case`Except`:return k({kind:`Except`,function:i(t.function),specs:t.updates.map(e=>({trail:e.path.map(e=>e.kind===`Field`?{kind:`Dot`,field:e.name}:{kind:`Apply`,expression:e.args.length===1?i(e.args[0]):{kind:`Tuple`,elements:e.args.map(i)}}),value:S(e.value,!0)}))},{location:r});case`ExceptAt`:return k({kind:`At`,isExcept:n},{location:r});case`Bracket`:throw new e.A(`Unexpected [ without a function or subscript`);case`FunctionApplication`:return k({kind:`FcnApp`,function:i(t.function),args:t.args.map(i)},{location:r});case`FieldAccess`:return k({kind:`Dot`,expression:i(t.record),field:t.field},{location:r});case`Product`:return k({kind:`Product`,factors:t.factors.map(i)},{location:r});case`Always`:case`Eventually`:{let e=t.expression;return t.kind===`Always`&&e.kind===`BoxAction`||t.kind===`Eventually`&&e.kind===`AngleAction`?k({kind:`Tsub`,modal:t.kind===`Always`?`Box`:`Dia`,action:i(e.action),subscript:i(e.subscript)},{location:r}):c(t.kind===`Always`?`BoxTrue`:`Diamond`,i(e))}case`BoxAction`:case`AngleAction`:return k({kind:`Sub`,modal:t.kind===`BoxAction`?`Box`:`Dia`,action:i(t.action),subscript:i(t.subscript)},{location:r});case`WeakFairness`:case`StrongFairness`:{let e=/\w/.test(a[r.startLine-1]?.[r.startColumn+2]??``),n=t=>e&&t.location?.startLine===r.startLine&&t.location.startColumn===r.startColumn+3?ot({...t,location:{...t.location,startColumn:r.startColumn}},n):t;return k({kind:`Fair`,fairness:t.kind===`WeakFairness`?`Weak`:`Strong`,subscript:n(i(t.subscript)),action:i(t.action)},{location:r})}case`Label`:return k({kind:`Parens`,expression:i(t.body),form:{kind:`Nlabel`,label:t.name,names:t.params,location:t.head&&o(t.head)}},{location:r});case`Subexpression`:{let[n,...a]=t.selectors;if(n.kind!==`Name`)throw new e.A(`Unexpected subexpression reference`);let o=k({kind:`Opaque`,name:n.name},{location:r}),s=n.args.length===0?o:k({kind:`Apply`,operator:o,args:n.args.map(i)},{location:r});return k({kind:`Bang`,expression:s,selectors:a.map(e=>{switch(e.kind){case`Name`:return{kind:`Label`,label:Va(e.name),args:e.args.map(i)};case`Operand`:return e.operand===`<<`?{kind:`Left`}:e.operand===`>>`?{kind:`Right`}:{kind:`Number`,value:e.operand};case`Bound`:return{kind:`Instance`,args:e.args.map(i)};case`At`:return{kind:`At`};case`Colon`:return{kind:`Down`}}})},{location:r})}}},C=e=>({location:o(e.definitionRange??e.instanceRange),instanceLocation:o(e.instanceRange),args:e.params.map(e=>e.name),module:e.module,substitutions:e.substitutions.map(e=>({name:Va(e.name),expression:S(e.expression,!1),location:o(e.nameRange)}))}),w=(n,r=!1)=>{let i=m(n.location);if(n.kind===`Instance`){if(n.name===void 0)throw new e.A(`Unexpected keyword INSTANCE`);return{kind:`Instance`,name:n.name,instance:C(n),location:i}}let o=n.kind===`Operator`&&n.params.length===1&&n.name===`-`?`-.`:Va(n.name),s=S(n.body,r);if(n.kind===`Function`)return{kind:`Operator`,name:o,body:x(n.bounds)?b(ja(v(n.bounds,r),s),i):k({kind:`Fcn`,bounds:_(n.bounds,r),body:s},{location:i}),location:i};let c=n.params.length===0?s:k({kind:`Lambda`,params:n.params.map(e=>({name:Va(e.name),shape:e.arity,...e.location&&{location:p(e.location,e.name.length)}})),body:s},{location:i}),l=n.location.range?.end,u=l&&_a(a,{line:l.line-1,column:l.column},t);return u?{kind:`Bpragma`,name:o,body:c,methods:u,location:i}:{kind:`Operator`,name:o,body:c,location:i}},T=e=>{let t=m(e.location);return e.level===`Variable`?{kind:`Flex`,name:e.name,location:t}:{kind:`Fresh`,name:e.name,shape:e.arity,level:e.level,domain:e.set&&S(e.set,!1),domainVisibility:`Visible`,location:t}},ee=e=>e.kind===`AssumeProve`?{context:e.assumptions.map(e=>{if(e.kind===`NewSymbol`)return T(e);let t=e.kind===`AssumeProve`?k({kind:`Sequent`,sequent:ee(e)},{location:m(e.location)}):te(e);return Je(t,`Visible`,`Now`,t.location)}),active:S(e.conclusion,!1)}:{context:[],active:S(e,!1)},te=e=>{if(e.kind!==`Label`||e.params.length>0)return S(e,!1);let t=m(e.location);return k({kind:`Parens`,expression:S(e.body,!1),form:{kind:`Xlabel`,label:e.name,indices:[]}},{location:t})},ne=t=>{if(t.kind===`ModuleFact`)throw new e.B(`MODULE facts in proof obligations are not supported`);let n=S(t,!1);return n.kind===`Bang`&&n.selectors.length===0?n.expression:n},re=t=>{let n=m(t.location);if(t.kind===`ModuleFact`)return{kind:`Dvar`,name:t.name,location:n};if(t.kind===`Identifier`)return{kind:`Dvar`,name:Va(t.name),location:n};if(t.kind===`OperatorReference`)return{kind:`Dvar`,name:Va(t.operator),location:n};throw new e.B(`This DEF clause in proof obligations is not supported`)},ie=e=>({facts:e.facts.map(ne),defs:e.defs.map(re)}),ae=(e,t)=>e?.[2]?{kind:`Named`,level:t,label:e[2],isAnonymous:!1}:{kind:`Unnamed`,level:t,id:ur(r)},oe=(e,t,n)=>{if(!e)return{kind:`Omitted`,omission:`Implicit`,location:n};switch(e.kind){case`Obvious`:return{kind:`Obvious`,...d(e.keyword),isSuppressed:u(e.keyword)};case`Omitted`:return{kind:`Omitted`,omission:`Explicit`,location:o(e.keyword)};case`By`:return{kind:`By`,usable:ie(e),isOnly:e.isOnly,location:o(e.keyword),step:{kind:`Unnamed`,level:t,id:0},method:c(e.location.range),isSuppressed:u(e.keyword)};case`Steps`:{let n=e.steps.map(e=>Ha.exec(e.token)),r=n[0],i=r&&r[1]!==`*`&&r[1]!==`+`?Number(r[1]):t,a=e.steps.slice(0,-1).map((e,t)=>E(e,ae(n[t],i),i)),s=e.steps[e.steps.length-1],c=ae(n[n.length-1],i),l=o(s.head),u=oe(s.proof,i+1,l),d={proof:u,location:Ua(l,u.location),step:c};return{kind:`Steps`,steps:a,qed:d,location:a.reduce((e,t)=>Ua(e,t.location),d.location),step:d.step}}}},se=e=>Ua(o(e.keyword),e.defs.length>0?m(e.defs[e.defs.length-1].location):void 0),E=(t,n,r)=>{let i=o(t.head),a=t.body,s=e=>{let a=oe(t.proof,r+1,i);return{...e(a),location:Ua(i,a.location),step:n}},l=e=>({...e,...d(t.head),step:n,isSuppressed:u(t.statement)});switch(a.kind){case`Use`:case`Hide`:{let e=Ua(o({...t.head,end:t.head.start}),se(a)),r=ie(a);return a.kind===`Use`?{kind:`Use`,usable:r,isOnly:a.isOnly,location:e,step:n,method:c(a.location.range),isSuppressed:u(a.keyword)}:{kind:`Hide`,usable:r,location:e,step:n}}case`Instance`:throw new e.A(`Unexpected keyword INSTANCE`);case`Define`:return{kind:`Define`,definitions:a.definitions.map(e=>w(e)),location:i,step:n};case`Have`:return l({kind:`Have`,expression:S(a.expression,!1)});case`Take`:return l({kind:`Take`,bounds:y(a)});case`Witness`:return l({kind:`Witness`,expressions:a.expressions.map(e=>S(e,!1))});case`Pick`:{let e=y(a),t=S(a.body,!1);return s(n=>({kind:`Pick`,bounds:e,expression:t,proof:n}))}case`Case`:{let e=S(a.expression,!1);return s(t=>({kind:`Pcase`,expression:e,proof:t}))}case`Assert`:{let e=ee(a.statement);return s(t=>a.isSuffices?{kind:`Suffices`,sequent:e,proof:t}:{kind:`Assert`,sequent:e,proof:t})}case`Qed`:throw new e.B(`QED in the middle of a proof`)}},ce=e=>({name:e.name,extendees:e.extends,extendeeLocations:e.extendsRanges.map(o),isImportant:!1,location:m(e.location),body:e.units.map(e=>{switch(e.kind){case`Constants`:case`Recursive`:return{kind:e.kind===`Constants`?`Constants`:`Recursives`,declarations:e.declarations.map(e=>({name:Va(e.name),shape:e.arity})),location:m(e.kind===`Constants`?e.declarations[0].location:e.location)};case`Variables`:return{kind:`Variables`,names:e.declarations.map(e=>e.name),location:m(e.declarations[0].location)};case`Definition`:return{kind:`Definition`,definition:w(e.definition),whereDefined:`User`,visibility:`Hidden`,isLocal:e.definition.isLocal,location:m(e.definition.location)};case`Instance`:{let t=e.instance,n=m(t.location);return t.name===void 0?{kind:`Anoninst`,instance:C(t),isLocal:t.isLocal,location:n}:{kind:`Definition`,definition:w(t),whereDefined:`User`,visibility:`Hidden`,isLocal:t.isLocal,location:o(t.instanceRange)}}case`Assumption`:return{kind:`Axiom`,name:e.assumption.name,expression:f(S(e.assumption.expression,!1),e.assumption.location.range),location:m(e.assumption.location)};case`Theorem`:{let t=e.theorem,n=m(t.location),r=s(n),i=ee(t.statement);return{kind:`Theorem`,name:t.name,sequent:{...i,active:f(i.active,t.statement.location.range)},axiomCount:0,proof:oe(t.proof,0,{...r,startLine:r.endLine,startColumn:r.endColumn}),location:n}}case`Use`:{let t=l(e.use.keyword);return{kind:`Mutate`,mode:e.use.kind,usable:ie(e.use),location:Ua(t&&p({line:t.line+1,column:t.column+1},0),se(e.use))}}case`Module`:return{kind:`Submod`,module:{...ce(e.module),isImportant:!0}}}})});return ce},qa={start:0,end:1/0},Ja=/-{4,} *MODULE/,Ya=`Unexpected EOF`,Xa=e=>e?`${e.startLine}:${e.startColumn}:${e.endLine}:${e.endColumn}`:``,Za=e=>{let n=t.rn(e,!0),r=e.split(`
120
+ `),i=n.at(-1)?.line??r.length,a=r.slice(0,i-1).reduce((e,t)=>e+t.length+1,0)+r[i-1].indexOf(`====`),o=e.indexOf(` `,e.search(Ja));if(o===-1||o>=a)return;let s=e.slice(0,o).split(`
33
121
  `).length,c=o-e.lastIndexOf(`
34
- `,o-1),l=n.findLast(e=>e.kind!==`End`&&(e.line<s||e.line===s&&e.column<c));return{offset:o,line:s,column:c,end:{reason:eo,line:l?.line??s,column:l?l.endColumn+1:c,isEnd:!0}}},ro=t=>{try{return t()}catch(t){if(!(t instanceof e.O)||!t.failure)throw t;return t.failure}},io=e=>typeof e==`object`&&!!e&&`reason`in e,ao=e=>{let n=ro(()=>no(e));if(io(n))return[n];let r=ro(()=>t.U(n?e.slice(0,n.offset):e));return n&&(!io(r)||r.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:n.line,column:n.column,isEnd:!1},io(r)&&r.reason===eo?r:n.end]:io(r)?[r]:r},oo=(t,n,r,i,a)=>{if(!$a.test(t.source))throw new e.w(`No tokens in file`);let o=ao(t.source);if(Array.isArray(o)){o.forEach(e=>{let n=`File ${JSON.stringify(t.file)}, line ${e.line}, character ${e.column}\n${e.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`})});let n=`Could not parse ${JSON.stringify(t.file)} successfully.`;throw i({text:`${a}Error: ${n}`,channel:`stderr`}),new e.w(n,{failure:`Module.Parser.parse_file`})}let s=Za(t.file,t.source,n,r).convertModule(o),c=t.file.slice(t.file.lastIndexOf(`/`)+1),l=c.replace(/\.tla$/,``);return s.name===l?s:(i({text:`${et(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},so=t=>{let n=new Map([...t].map(([e,t])=>[e,zn(t).dependencies])),r=/* @__PURE__ */ new Set,i=[],a=o=>{if(r.has(o))return;r.add(o);let s=t.get(o);if(!s)throw new e.w(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(Vn).forEach(a),i},co=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${Xe(t)}`)],lo=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?Xe({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...co(`missing`,e.absent,t),...co(`omitted`,e.omitted,n),` ====`]},uo=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...lo(t,e.missing,e.omitted)],missing:e.missing+t.absent.length,omitted:e.omitted+t.omitted.length},{lines:[],missing:0,omitted:0});return[`---- summary of module ${JSON.stringify(e.name)} ----`,` obligations_count = ${t.total}`,...t.absent.length>0?[` missing_proofs_count = ${t.absent.length}`]:[],...t.omitted.length>0?[` omitted_proofs_count = ${t.omitted.length}`]:[],...n.lines,`====`].join(`
35
- `)},fo=(t,n,r={})=>{let i=r.lines??Qa,a=r.onWarning??(()=>{}),o={value:0},s=new Map(Nn);t.forEach(e=>{let t={...oo(e,o,!0,a,`File "<unknown>":
36
- `),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Vn(e.name,t.name)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=zn(c[e]);t.submodules.forEach((e,t)=>{u.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!Nn.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=oo(r,o,!1,a,$e(t.locations.get(e)));s.set(e,i),c.push(i)}}let d=[...l.keys()].filter(e=>!u.has(e)).sort(Vn);if(d.forEach(e=>a(D(l.get(e),`Unknown module ${JSON.stringify(e)}`))),d.length>0)throw new e.w(`Unknown module ${JSON.stringify(d[0])}`,{failure:`Module.Parser.load_module`});let f={anonymizer:En(o,(e,t)=>ni(f,e,t),a),simplify:pa(o),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},p=so(s).map(e=>e.isStandard?e:Rn(s,e,/* @__PURE__ */ new Set)),m=cr(new Set(t.map(e=>e.file)),i,a),h=new Map(p.map(e=>[e.name,e]));return p.flatMap(e=>{if(e.isStandard)return[];let t=ri(f,h,void 0,e);if(!e.isImportant)return[];let n=m([],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${ra(e.sequent)}\n`;return[{id:t+1,location:to(n),locus:n,text:r,kind:e.kind,sequent:e.sequent,method:e.method}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},po=async t=>{let n=[],r=[],i=/* @__PURE__ */ new Map,a=[],o={failure:void 0},s=()=>{for(;a.length>0&&r.length>0;){let e=r.reduce((e,t,n)=>t.priority<r[e].priority?n:e,0),[t]=r.splice(e,1),o=a.pop()??0;i.set(o,t),n[o].postMessage(t.request)}},c=(t,n)=>{let r=n,o=i.get(t);i.delete(t),a.push(t),`verdict`in r&&o?.resolve(r),`error`in r&&o?.reject(new e.T(r.error)),s()},l=e=>{o.failure||(o.failure={reason:e},[...r.splice(0),...i.values()].forEach(t=>t.reject(e)),i.clear(),n.forEach(e=>e.terminate()))};return n.push(...await Promise.all(Array.from({length:t},(t,n)=>e.i(new URL(`./prove-worker.js`,require("url").pathToFileURL(__filename).href),e=>c(n,e),l)))),a.push(...n.keys()),{decide:(e,t,n,i)=>new Promise((a,c)=>{if(o.failure)return c(o.failure.reason);r.push({request:{prover:e,text:t,timeLimitMs:n.timeLimitMs},priority:i,resolve:a,reject:c}),s()}),terminate:l}},mo={"!":`excl_`,"#":`hash_`,$:`doll_`,"%":`perc_`,"&":`ampe_`,"'":`quot_`,"(":`lpar_`,")":`rpar_`,"*":`star_`,"+":`plus_`,"-":`dash_`,".":`peri_`,"/":`slas_`,":":`colo_`,"<":`less_`,"=":`equa_`,">":`more_`,"?":`ques_`,"@":`atsi_`,"[":`lbrk_`,"\\":`bksl_`,"]":`rbrk_`,"^":`care_`,_:`unde_`,"|":`vert_`,"~":`tild_`},ho=new Set((/* @__PURE__ */ `All Append Bijections Case CaseArm CaseOther Char Choice EnumFuncSet Ex Fcn FuncSet INTER Id.Image Injections Injective InjectiveOn Int Inverse Len Let Monotonic Nat Nibble Not PeanoAxioms.Pred Product Range Seq String Succ Surjections Surjective TYPE Trueprop Zero abs addElt addnat.all antisymmetric any aprop arbitrary args arith_add asms bAll bChoice bEx boolify c cap cargs.case_arm case_arms cases_conj cases_equal cases_forall cases_implies char cidts classes cond.conj conjunction converse cs cup default diff diffnat disj div divmodNat divmod_rel domrng.domrngs dummy dummy_pattern dvd emptySeq eq equivalence except extend fapply float_const.float_token fun geq gfp greater id idt idts iff imp in index infinity irreflexive isAFcn isASeq.isBool isNeg isPos itself leq less letbind letbinds lfp logic longid minus mod mult multnat.natInterval num num_const oneArg prod prop psubset psupset pttrn pttrns reflexive rel_comp.rel_domain rel_image rel_range setOfAll setOfPairs setminus sgn sort sort_constraint struct.subsetOf subseteq symmetric term tid tpl transitive tvar type types upair upto var xcpt xnum.xstr.ML ML_command ML_export ML_file ML_file_debug ML_file_no_debug ML_prf ML_val ROOTS_file.SML_export SML_file SML_file_debug SML_file_no_debug SML_import abbreviation abbrevs alias also.and apply apply_end assume assumes attribute_setup axiomatization back begin bibtex_file binder.bundle by case chapter class class_deps code_datatype compile_generated_files consider.constrains consts context corollary declaration declare default_sort defer define defines.definition done end experiment export_files export_generated_files export_prefix external_file.external_files extract extract_type finally find_consts find_theorems fix fixes for from.full_prf generate_file global_interpretation guess have help hence hide_class hide_const.hide_fact hide_type if imports in include includes including infix infixl infixr instance.instantiation interpret interpretation is judgment keywords lemma lemmas let local_setup locale.locale_deps method_setup moreover named_theorems next no_notation no_syntax no_translations.no_type_notation nonterminal notation note notepad notes obtain obtains oops open opening oracle.output overloaded overloading paragraph parse_ast_translation parse_translation pervasive prefer.premises presume prf print_ML_antiquotations print_abbrevs print_antiquotations.print_ast_translation print_attributes print_bundles print_cases print_classes print_codesetup.print_commands print_context print_definitions print_defn_rules print_facts print_interps.print_locale print_locales print_methods print_options print_rules print_simpset print_state.print_statement print_syntax print_term_bindings print_theorems print_theory print_trans_rules.print_translation private proof prop proposition qed qualified realizability realizers rewrites.schematic_goal section setup show shows simproc_setup sorry structure subclass subgoal sublocale.subparagraph subsection subsubsection supply syntax syntax_declaration term text text_raw then.theorem theory thm thm_deps thm_oracles thus thy_deps translations txt typ type_alias.type_notation type_synonym typed_print_translation typedecl ultimately unbundle unchecked.unfolding unused_thms using welcome when where with write.O max status`.split(`.`)).join(` `).split(` `)),go=e=>/^[A-Za-z]$/.test(e),_o=t=>{if(/^[A-Za-z0-9]$/.test(t))return;let n=mo[t];if(n===void 0)throw new e.M;return n},vo=e=>{let t=[...e];return go(t[0]??``)&&go(t.at(-1)??``)&&t.every(e=>_o(e)===void 0)&&!ho.has(e)?e:`a_${t.map(e=>_o(e)??e).join(``)}a`},yo={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},bo=(t,n,r)=>{if((t===`Prime`||t===`StrongPrime`||t===`UNCHANGED`)&&n===1)return new e.M;let i=yo[t];return i&&i[1]===n?new e.T(`Unsupported operator \`${i[0]}\`.\n`):new e.T(r)},xo=(e,t,n)=>{let r=t[0],i=t.slice(1),a=i[0]?.domain.kind===`Ditto`?[{...i[0],domain:r.domain},...i.slice(1)]:i;return a.length===0?{first:r,inner:n}:{first:r,inner:{kind:`Quant`,quantifier:e,bounds:a.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:L(1,e.domain.expression)}}:e),body:n,location:n.location}}},So=(t,n)=>{let r=t.stack.length;try{return n()}catch(n){if(!(n instanceof e.A))throw n;return Hi(t,t.stack.length-r),n}},Co=e=>`is${vo(e)}`,wo={TRUE:`TRUE`,FALSE:`FALSE`,STRING:`STRING`,BOOLEAN:`BOOLEAN`,Nat:`Nat`,Int:`Int`,Real:Co(`Real`),Infinity:Co(`Infinity`),Any:`Any`},To={Neg:`~`,DOMAIN:`DOMAIN`,SUBSET:`SUBSET`,UNION:`UNION`},Eo={Implies:`\\<Rightarrow>`,Equiv:`\\<Leftrightarrow>`,Conj:`\\<and>`,Disj:`\\<or>`,Eq:`=`,Neq:`\\<noteq>`,Subseteq:`\\<subseteq>`,Mem:`\\<in>`,Notmem:`\\<notin>`,Setminus:`\\\\`,Cap:`\\<inter>`,Cup:`\\<union>`,OneArg:`:>`,Extend:`@@`},Do={Plus:[`addint`,2],Minus:[`subint`,2],Uminus:[`minus`,1],Times:[`mult`,2],Ratio:[Co(`/`),2],Quotient:[Co(`\\div`),2],Remainder:[Co(`%`),2],Exp:[Co(`^`),2],Lteq:[`leq`,2],Lt:[`less`,2],Gteq:[`geq`,2],Gt:[`greater`,2],Range:[`intvl`,2],Seq:[`Seq`,1],Len:[`Len`,1],BSeq:[`BSeq`,1],Cat:[Co(`\\circ`),2],Append:[`Append`,2],Head:[`Head`,1],Tail:[`Tail`,1],SubSeq:[`SubSeq`,3],SelectSeq:[`SelectSeq`,2],Print:[`Print`,2],PrintT:[`PrintT`,1],Assert:[`Assert`,2],JavaTime:[`JavaTime`,0],TLCGet:[`TLCGet`,1],TLCSet:[`TLCSet`,2],Permutations:[`Permutations`,1],SortSeq:[`SortSeq`,2],RandomElement:[`RandomElement`,1],ToString:[`ToString`,1]},Oo=[`consts`,...[[`Real`,0],[`/`,2],[`\\div`,2],[`%`,2],[`..`,2],[`Infinity`,0],[`[]`,1],[`<>`,1]].map(e=>` "${Co(e[0])}" :: ${e[1]===0?`c`:`"[${Array(e[1]).fill(`c`).join(`,`)}] => c"`}`),``].join(`
37
- `),ko=e=>{let t=Number.parseInt(e,10);return`${`succ[`.repeat(t)}0${`]`.repeat(t)}`},Ao=(e,t)=>[`(* automatically generated -- do not edit manually *)`,`theory ${e} imports Constant Zenon begin`,...t?[`ML_command \\<open> writeln ("*** TLAPS PARSED\\n"); \\<close>`]:[],Oo],jo=t=>{let n=zi(),r=e=>Vi(n,vo(e)),i=()=>Vi(n,``),a=(e,t)=>{let i=t(r(e));return Hi(n,1),i},o=e=>`(${p(e)})`,s=e=>e.map(o).join(`, `),c=(e,t)=>`(${e} (${s(t)}))`,l=(t,n)=>{let r=wo[t];if(r!==void 0&&n.length===0)return r;let i=To[t];if(i!==void 0&&n.length===1)return`(${i} ${o(n[0])})`;let a=Eo[t];if(a!==void 0&&n.length===2)return`(${o(n[0])} ${a} ${o(n[1])})`;let s=Do[t];if(s&&s[1]===n.length)return c(s[0],n);if(t===`Unprimable`&&n.length===1)return o(n[0]);throw t===`Irregular`&&n.length===1?new e.A(`Irregular`):bo(t,n.length,`Backend.Isabelle.pp_apply`)},u=(t,i)=>{switch(t.kind){case`Ix`:{let r=Bi(n,t.index);if(t.index<=0||r===void 0)throw new e.M;return i.length===0?r:`(${r} (${s(i)}))`}case`Opaque`:{let e=vo(t.name);return i.length===0?`(${e} :: c)`:`(${e} (${s(i)}) :: c)`}case`Internal`:return l(t.builtin,i);case`Lambda`:{let e=`\\<lambda> ${t.params.map(e=>`${r(e.name)} `).join(``)}. ${o(t.body)}`;return Hi(n,t.params.length),e}default:throw new e.M}},d=(t,n,r)=>{if(n.length===0)return p(r);let i=xo(t,n,r),s=t===`Forall`?`\\<forall>`:`\\<exists>`;if(i.first.domain.kind===`NoDomain`)return a(i.first.name,e=>`${s}${e} : ${o(i.inner)}`);if(i.first.domain.kind!==`Domain`)throw new e.M;let c=o(i.first.domain.expression);return a(i.first.name,e=>`${s} ${e} \\<in> ${c} : ${o(i.inner)}`)},f=t=>{if(t.context.length===0)return o(t.active);let r=t.context[0],s=()=>f({context:t.context.slice(1),active:t.active});switch(r.kind){case`Flex`:return a(r.name,e=>`(\\<And> ${e} ${e}'.${s()})`);case`Fresh`:{if(r.domain&&r.domainVisibility===`Visible`){let e=o(r.domain);return a(r.name,t=>`(\\<And> ${t} :: c. ${t} \\<in> ${e} \\<Longrightarrow> ${s()})`)}let e=`${`c => `.repeat(r.shape)}c`;return a(r.name,t=>`(\\<And> ${t} :: ${e}. ${s()})`)}case`Fact`:{let e=r.visibility===`Visible`?o(r.expression):void 0;i();let t=e?`(${e} \\<Longrightarrow> ${s()})`:s();return Hi(n,1),t}case`Defn`:throw new e.A(`Inner definition`)}},p=t=>{switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return u(t,[]);case`Apply`:return u(t.operator,t.args);case`Bang`:throw new e.T(`Backend.Isabelle.module`);case`Sequent`:return f(t.sequent);case`With`:case`Parens`:return p(t.expression);case`Let`:throw new e.A(`LET`);case`List`:return t.bullet===`Refs`&&t.items.length===0?`TRUE`:t.bullet===`Refs`&&t.items.length===1?p(t.items[0]):t.items.map(o).join(t.bullet===`Or`?` | `:` & `);case`If`:return`cond(${o(t.condition)}, ${o(t.consequent)}, ${o(t.alternative)})`;case`Quant`:return d(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.A(t.quantifier===`Forall`?`\\\\AA`:`\\\\EE`);case`Choose`:{if(!t.domain)return a(t.name,e=>`Choice(%${e}. ${o(t.body)})`);let e=o(t.domain);return a(t.name,n=>`bChoice(${e}, %${n}. ${o(t.body)})`)}case`SetSt`:{let e=o(t.domain);return a(t.name,n=>`subsetOf(${e}, %${n}. ${o(t.body)})`)}case`SetOf`:{if(t.bounds.length===0)throw new e.M;let n=t.bounds[0];if(t.bounds.length!==1||n.domain.kind!==`Domain`)throw new e.A(`SetOf (multiple declared constants)`);let r=o(n.domain.expression);return a(n.name,e=>`setOfAll(${r}, %${e}. ${o(t.element)})`)}case`SetEnum`:return`{${s(t.elements)}}`;case`Fcn`:{let n=t.bounds[0];if(t.bounds.length!==1)throw new e.A(`function (multiple declared constants)`);if(n.domain.kind===`Ditto`)throw new e.M;let r=n.domain.kind===`Domain`?o(n.domain.expression):void 0;return a(n.name,e=>`[${r===void 0?e:` ${e} \\<in> ${r} `} \\<mapsto> ${o(t.body)}]`)}case`FcnApp`:{let e=o(t.function);return t.args.length===1?`fapply (${e}, ${o(t.args[0])})`:`fapply (${e}, <<${s(t.args)}>>)`}case`Arrow`:return`[${o(t.domain)} \\<rightarrow> ${o(t.range)}]`;case`Rect`:return`[${t.fields.map(e=>`''${e.name}'' : ${o(e.value)}`).join(`, `)}]`;case`Record`:return`(${t.fields.map(e=>`(''${e.name}'' :> ${o(e.value)})`).join(` @@ `)})`;case`Except`:{let e=t.specs.map(e=>`!${e.trail.map(e=>e.kind===`Dot`?`[''${e.field}'']`:`[${o(e.expression)}]`).join(``)} = ${o(e.value)}`);return`[${o(t.function)} EXCEPT ${e.join(`, `)}]`}case`Dot`:return`fapply (${o(t.expression)}, (''${t.field}''))`;case`Tuple`:return`<<${s(t.elements)}>>`;case`Product`:return t.factors.length===2?`(${o(t.factors[0])} \\<times> ${o(t.factors[1])})`:`Product(\\<langle>${s(t.factors)}\\<rangle>)`;case`Sub`:case`Tsub`:{let e=t.kind===`Sub`?`sub`:`tsub`;return`${t.modal===`Box`?Co(`a'box'${e}`):`a'dia'${e}`}(${o(t.action)},${o(t.subscript)})`}case`Fair`:return`${Co(t.fairness===`Weak`?`a'wf`:`a'sf`)}(${o(t.subscript)},${o(t.action)})`;case`Case`:{let e=s(t.arms.map(e=>e.condition)),n=s(t.arms.map(e=>e.body));return t.other?`CaseOther(<<${e}>>,<<${n}>>,${o(t.other)})`:`Case(<<${e}>>,<<${n}>>)`}case`String`:return`''${t.value}''`;case`Num`:if(t.fraction!==``)throw new e.A(`real constants`);return`(${ko(t.integer)})`;case`At`:throw new e.M}},m=t=>{let a=[];for(let s of t.context)switch(s.kind){case`Flex`:{let e=r(s.name);a.push(`fixes ${e} ${e}'`);break}case`Fresh`:{let e=s.domain&&s.domainVisibility===`Visible`?o(s.domain):void 0,t=r(s.name);if(a.push(`fixes ${t}`),e===void 0)break;a.push(`assumes ${t}_in : "(${t} \\<in> ${e})"`);break}case`Fact`:{let t=n.stack.length,r=s.visibility===`Visible`?So(n,()=>o(s.expression)):void 0;if(i(),r instanceof e.A){a.push(`(* omitted temporal assumption : ${r.message} *)`);break}if(r===void 0)break;a.push(`assumes v'${t}: "${r}"`);break}case`Defn`:if(s.definition.kind===`Bpragma`)return[...a,``];a.push(`(* usable definition ${s.definition.name} suppressed *)`),r(s.definition.name)}return[...a,`shows "${o(t.active)}"`]};try{let e=m(t);return{text:e.join(`
38
- `),isAssumed:e.some(e=>e.startsWith(`assumes `))}}catch(t){throw t instanceof e.A?new e.T(`isabelle : unsupported operator ${t.message}`):t}},Mo=(e,t,n)=>{let r=jo(t);return[...Ao(`tlapm_${e}`,!1),`lemma ob'${e}:`,`${r.text}(is "PROP ?ob'${e}")`,`proof -`,`show "PROP ?ob'${e}"`,`${r.isAssumed?`using assms `:``}by ${n}`,`qed`,`end`,``].join(`
39
- `)},No=(e,t)=>[...Ao(e,!0),...t.flatMap(e=>[`lemma ob'${e.id}:`,`${jo(e.sequent).text}(is "PROP ?ob'${e.id}")`,`proof -`,`ML_command \\<open> writeln "*** TLAPS ENTER ${e.id}"; \\<close>`,`show "PROP ?ob'${e.id}"`,`using assms by ${e.tactic}`,`ML_command \\<open> writeln "*** TLAPS EXIT ${e.id}"; \\<close> qed`]),`end`,``].join(`
40
- `),Po=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],Fo=Array.from({length:64},(e,t)=>Math.floor(Math.abs(Math.sin(t+1))*2**32)),Io=(e,t)=>e<<t|e>>>32-t,Lo=e=>{let t=new TextEncoder().encode(e),n=Math.ceil((t.length+9)/64)*64,r=new Uint8Array(n);r.set(t),r[t.length]=128;let i=new DataView(r.buffer);i.setUint32(n-8,t.length*8>>>0,!0),i.setUint32(n-4,Math.floor(t.length/2**29),!0);let a=[1732584193,4023233417,2562383102,271733878];for(let e=0;e<n;e+=64){let t=Array.from({length:16},(t,n)=>i.getUint32(e+n*4,!0)),n=Array.from({length:64}).reduce(([e,n,r,i],a,o)=>{let s=Math.floor(o/16),c=s===0?n&r|~n&i:s===1?i&n|~i&r:s===2?n^r^i:r^(n|~i),l=s===0?o:s===1?(5*o+1)%16:s===2?(3*o+5)%16:7*o%16,u=e+c+Fo[o]+t[l]|0;return[i,n+Io(u,Po[s*4+o%4])|0,n,r]},a);a.splice(0,4,...a.map((e,t)=>e+n[t]|0))}return a.flatMap(e=>[e,e>>>8,e>>>16,e>>>24]).map(e=>(e&255).toString(16).padStart(2,`0`)).join(``)},Ro=(t,n)=>{let r=ot(t,n-1)?.hyp;if(!r)throw new e.M;return r},zo=(e,t)=>yr(e,t).level,Bo=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),Vo=(e,t)=>{let n=ct(void 0,(n,r)=>{let i=yt(r,t=>e(n,t),t);return[A(n,i),i]});return(t,r)=>{let i=n(t,r.context);return{context:i.context,active:e(i.state,r.active)}}},Ho=(e,t)=>{if(t.kind===`Sub`||t.kind===`Tsub`){let n=Ho(e,t.action),r=Ho(e,t.subscript),i=k(`UNCHANGED`,[r],t),a=t.modal===`Box`?k(`Disj`,[n,i],t):k(`Conj`,[n,k(`Neg`,[i],t)],t);return t.kind===`Sub`?a:k(t.modal===`Box`?`BoxTrue`:`Diamond`,[a],t)}return N(e,t,Ho,A,`all`)},Uo=(e,t)=>t.kind===`Apply`&&Bo(t,[`UNCHANGED`])&&t.args.length===1?on(t.args[0]):N(e,t,Uo,A,`all`),Wo=(e,t)=>k(e,[t],t),Go=(t,n)=>{if(n.kind===`Ix`){let e=Ro(t,n.index);return e.kind===`Fresh`&&e.level===`Constant`||e.kind===`Defn`&&e.definition.kind===`Operator`&&zo(ot(t,n.index),e.definition.body)===0?n:Wo(`Prime`,n)}if(Bo(n,[`ENABLED`])||n.kind===`Opaque`||n.kind===`Sequent`||n.kind===`Let`)return Wo(`Prime`,n);if(Bo(n,[`UNCHANGED`,`Cdot`,`Leadsto`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`])||n.kind===`Tquant`||n.kind===`Sub`||n.kind===`Tsub`||n.kind===`Fair`)throw new e.M;return N(t,n,Go,A)},Ko=e=>{let t=e===`BoxTrue`?`Conj`:`Disj`,n=e===`BoxTrue`?`Forall`:`Exists`,r=(i,a)=>zo(i,a)===0?a:Bo(a,[t])||(a.kind===`Quant`||a.kind===`Tquant`)&&a.quantifier===n?N(i,a,r,A):Wo(e,a);return r},qo={Prime:Go,BoxTrue:Ko(`BoxTrue`),Diamond:Ko(`Diamond`)},Jo=(t,n)=>{if(n.kind===`Apply`&&n.operator.kind===`Internal`){let r=qo[n.operator.builtin];if(r){if(n.args.length!==1)throw new e.M;return r(t,n.args[0])}}return N(t,n,Jo,A,`all`)},Yo={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},Xo=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],Zo=(e,t)=>`${e}_${t}_`,Qo=(t,n,r)=>{if(n.kind!==`Operator`)return n.kind===`Bpragma`?{...n,body:is(t,n.body)}:n;let i=is(t,n.body),a=Xo[r??zo(t,i)];if(a===void 0)throw new e.M;return{...n,name:Zo(a,n.name),body:i}},$o=(e,t,n)=>{switch(t.kind){case`Fresh`:return{...t,name:Zo(Yo[t.level],t.name),domain:t.domain&&is(e,t.domain)};case`Flex`:return{...t,name:Zo(`VARIABLE`,t.name)};case`Defn`:return{...t,definition:Qo(e,t.definition,n)};case`Fact`:return{...t,expression:is(e,t.expression)}}},es=(e,t)=>{if(t.kind!==`Defn`||t.definition.kind!==`Operator`)return;let n=t=>{if(!Bo(t,[`UNCHANGED`])||t.kind!==`Apply`)return zo(e,t);let n=e=>e.kind===`Tuple`?e.elements.flatMap(n):[e],r=n(t.args[0]);return zo(e,r.length===1?r[0]:t.args[0])},r=t.definition.body;return n(Bo(r,[`Prime`,`BoxTrue`,`Diamond`])&&r.kind===`Apply`&&r.args.length===1&&r.kind===`Apply`?r.args[0]:r)},ts=ct({scope:void 0,original:void 0},(e,t,n)=>{let r=$o(e.scope,t,es(e.original,n));return[{scope:A(e.scope,r),original:A(e.original,n)},r]}),ns=(e,t)=>{let n=ts(t.context,e.context);return{context:n.context,active:is(n.state.scope,e.active)}},rs=(e,t)=>{let[n,r]=st(e,t.context,(e,t)=>{let n=$o(e,t);return[A(e,n),n]});return{context:r,active:is(n,t.active)}},is=(e,t)=>{switch(t.kind){case`Lambda`:{let n=t.params.map(e=>({...e,name:Zo(`Unknown`,e.name)})),r=j(e,n.map(ft));return{...t,params:n,body:is(r,t.body)}}case`Tquant`:{let n=j(e,t.names.map(e=>({kind:`Flex`,name:Zo(`VARIABLE`,e)})));return{...t,body:is(n,t.body)}}case`Choose`:{let n=t.domain&&is(e,t.domain),r=Zo(`CONSTANT`,t.name),i=n?M(r,n):lt(r,`Constant`);return{...t,name:r,domain:n,body:is(A(e,i),t.body)}}case`SetSt`:{let n=is(e,t.domain),r=Zo(`CONSTANT`,t.name),i=is(A(e,M(r,n)),t.body);return{...t,name:r,domain:n,body:i}}case`Quant`:case`Fcn`:case`SetOf`:{let n=t.bounds.map(t=>({...t,name:Zo(Yo[t.level],t.name),domain:t.domain.kind===`Domain`?{kind:`Domain`,expression:is(e,t.domain.expression)}:t.domain})),r=j(e,n.map(dt));return t.kind===`SetOf`?{...t,bounds:n,element:is(r,t.element)}:{...t,bounds:n,body:is(r,t.body)}}case`Let`:{let[n,r]=st(e,t.definitions,(e,t)=>{let n=Qo(e,t);return[A(e,pt(n)),n]});return{...t,definitions:r,body:is(n,t.body)}}case`Sequent`:return{...t,sequent:rs(e,t.sequent)};default:return N(e,t,is,A,`all`)}},as=/* @__PURE__ */ new WeakMap,os=(e,t)=>{let n=as.get(t);if(n)return n;let r=t.kind===`Operator`?t.body:void 0;if(r?.kind!==`Lambda`)return[];let i=j(e,r.params.map(ft)),a=r.params.map((e,t)=>ls(i,r.body,t+1,!0));return as.set(t,a),a},ss=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`ENABLED`,`UNCHANGED`],cs=[`Leadsto`,`Actplus`,`Cdot`],ls=(t,n,r,i)=>{if(n.kind===`Ix`)return i||n.index!==r;if(n.kind===`Apply`&&n.operator.kind===`Internal`){let e=n.operator.builtin;if(ss.includes(e)&&n.args.length===1||cs.includes(e)&&n.args.length===2)return n.args.every(e=>ls(t,e,r,!1))}if(n.kind===`Sub`)return[n.action,n.subscript].every(e=>ls(t,e,r,!1));if(n.kind===`Apply`&&n.operator.kind===`Ix`){let i=ot(t,n.operator.index-1),a=i?.hyp;if(i&&a?.kind===`Defn`&&a.definition.kind===`Operator`){let o=os(i.rest,a.definition);return n.args.every((n,i)=>{let a=o[i];if(a===void 0)throw new e.M;return ls(t,n,r,a)})}}let a={isSubstitutive:!0};return N({scope:t,index:r},n,(e,t)=>(a.isSubstitutive&&=ls(e.scope,t,e.index,i),t),(e,t)=>({scope:A(e.scope,t),index:e.index+1}),`all`),a.isSubstitutive},us=(e,t)=>`h${Lo(ji(ta(e,t))).slice(0,5)}`,ds=(e,t)=>O({kind:`Opaque`,name:us(it(e),t)},t),fs=(e,t,n,r,i)=>{let a=i.map((t,r)=>zo(e,t)===0||n[i.length-r-1]?O({kind:`Opaque`,name:`*`},t):t);return ds(e,O({kind:`Apply`,operator:{kind:`Opaque`,name:t},args:a},r))},ps=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`Leadsto`,`ENABLED`,`Cdot`,`UNCHANGED`],ms=(t,n)=>{if(n.kind!==`Apply`)return N(t,n,ms,A);let r=n.operator,[i]=n.args;if(Bo(n,[`Prime`,`StrongPrime`])&&n.args.length===1&&i.kind===`Ix`){let e=Ro(t,i.index);if(e.kind===`Fresh`||e.kind===`Flex`)return O({kind:`Opaque`,name:`${e.name}#prime`},n)}if(Bo(n,ps))return ds(t,n);if(r.kind!==`Ix`)return N(t,n,ms,A);let a=ot(t,r.index-1),o=a?.hyp;if(!o)throw new e.M;let s=n.args;if(o.kind===`Defn`&&o.definition.kind===`Operator`){let e=os(a.rest,o.definition);if(s.every((n,r)=>zo(t,n)===0||e[s.length-r-1]))return N(t,n,ms,A);let i=fs(t,o.definition.name,e,r,s);return O({kind:`Apply`,operator:i,args:s.map(e=>ms(t,e))},n)}if(o.kind===`Flex`)return N(t,n,ms,A);if(o.kind===`Fresh`){if(o.level===`Constant`)return O({kind:`Apply`,operator:r,args:s.map(e=>ms(t,e))},n);let e=s.map(()=>!1);return fs(t,o.name,e,r,s)}throw new e.M},hs=Vo(Ho,`all`),gs=Vo(Uo,`all`),_s=Vo(Jo,`all`),vs=Vo(ms,`visible`),ys=e=>{let t=e.context,n=gs(t,hs(t,e)),r=_s(t,n);return vs(t,ns(r,e))},bs=/* @__PURE__ */ `TRUE.FALSE.Implies.Equiv.Conj.Disj.Neg.Eq.Neq.STRING.BOOLEAN.SUBSET.UNION.DOMAIN.Subseteq.Mem.Notmem.Setminus.Cap.Cup.Prime.StrongPrime.Leadsto.ENABLED.UNCHANGED.Cdot.Actplus.Diamond.Nat.Int.Real.Plus.Minus.Uminus.Times.Ratio.Quotient.Remainder.Exp.Infinity.Lteq.Lt.Gteq.Gt.Divides.Range.Seq.Len.BSeq.Cat.Append.Head.Tail.SubSeq.SelectSeq.OneArg.Extend.Print.PrintT.Assert.JavaTime.TLCGet.TLCSet.Permutations.SortSeq.RandomElement.Any.ToString.Unprimable.Irregular`.split(`.`),xs={And:0,Or:1,Refs:2},Ss={Forall:0,Exists:1},Cs={Box:0,Dia:1},ws={Weak:0,Strong:1},Ts={34:`\\"`,92:`\\\\`,10:`\\n`,9:`\\t`,13:`\\r`,8:`\\b`},Es=e=>`"${[...new TextEncoder().encode(e)].map(e=>Ts[e]??(e<32||e>126?`\\${String(e).padStart(3,`0`)}`:String.fromCharCode(e))).join(``)}"`,Ds=e=>e===`BoxTrue`?`$Box`:e===`BoxFalse`?`$FakeBox`:`$${bs.indexOf(e)}`,Os=e=>e.level===`Unknown`?`Unknown`:e.level.toUpperCase(),ks=t=>{let n=[],r=t=>{let r=n[n.length-t];if(!r)throw new e.M;return r},i=e=>n.push({ident:e,isUsed:!1}),a=()=>{let t=n.pop();if(!t)throw new e.M;return t},o=e=>Array.from({length:e}).forEach(()=>i({kind:`Var`})),s=e=>Array.from({length:e},a),c=t=>{if(t.ident.kind===`VarIndex`)return t.ident.index;if(t.ident.kind===`Var`)return 0;throw new e.M},l=t=>{if(t.ident.kind!==`HypIndex`)throw new e.M;return t.ident.index},u=(t,n)=>{let a=e=>u(t,e),l=e=>e.map(a).join(`,`),f=(e,t)=>t.map((t,n)=>t.domain.kind===`Domain`?`${c(e[n])}:${a(t.domain.expression)},`:``).join(``),p=(e,t)=>(o(e),{text:a(t),entries:s(e)}),m=e=>e.map(e=>`${c(e)}.`).join(``);switch(n.kind){case`Ix`:{let i=r(n.index);i.isUsed=!0;let a=i.ident;switch(a.kind){case`None`:return`$V(${n.index}SHOULD_NOT_APPEAR)`;case`Hyp`:{let e=t.hyp++;return i.ident={kind:`HypIndex`,index:e},`$${a.label}(${e})`}case`Var`:{let e=t.variable++;return i.ident={kind:`VarIndex`,index:e},`$PRM(${e})`}case`HypIndex`:return`$HYP(${a.index})`;case`VarIndex`:return`$PRM(${a.index})`;case`Pragma`:return``}throw new e.M}case`Opaque`:return n.name;case`Internal`:return Ds(n.builtin);case`Lambda`:{let e=p(n.params.length,n.body);return`$Lam(${m(e.entries.toReversed())}${e.text})`}case`Sequent`:return d(n.sequent);case`Apply`:{let e=n.operator;return e.kind===`Ix`&&r(e.index).ident.kind===`Pragma`?``:`$OpApp(${a(e)};${l(n.args)})`}case`With`:case`Parens`:return a(n.expression);case`If`:return`$If(${a(n.condition)},${a(n.consequent)},${a(n.alternative)})`;case`List`:return`$List(${xs[n.bullet]};${l(n.items)})`;case`Let`:{let t=n.definitions.map(t=>{if(t.kind!==`Operator`&&t.kind!==`Bpragma`)throw new e.M;let n=`${a(t.body)}.`;return i({kind:`Var`}),n}),r=a(n.body);return s(t.length),`${t.join(``)}${r}`}case`Quant`:{let e=p(n.bounds.length,n.body);return`$Quant(${Ss[n.quantifier]};${f(e.entries,n.bounds)}.${e.text})`}case`Tquant`:{let e=p(n.names.length,n.body);return`$Tquant(${Ss[n.quantifier]}${m(e.entries.toReversed())}${e.text})`}case`Choose`:{let e=p(1,n.body),t=c(e.entries[0]);return n.domain?`$Bch(${t}:${a(n.domain)};${e.text})`:`$Ch(${t}:${e.text})`}case`SetSt`:{let e=p(1,n.body);return`$SSt(${c(e.entries[0])}:${a(n.domain)};${e.text})`}case`SetOf`:{let e=p(n.bounds.length,n.element);return`$Sof(${f(e.entries.toReversed(),n.bounds)}.${e.text})`}case`Fcn`:{let e=p(n.bounds.length,n.body);return`$Fcn(${f(e.entries.toReversed(),n.bounds)}.${e.text})`}case`SetEnum`:return`$Set(${l(n.elements)})`;case`Tuple`:return`$Tup(${l(n.elements)})`;case`Product`:return`$Prod(${l(n.factors)})`;case`FcnApp`:return`$FcnApp(${a(n.function)};${l(n.args)})`;case`Arrow`:return`$Arrow(${a(n.domain)},${a(n.range)})`;case`Rect`:case`Record`:return`$${n.kind}(${n.fields.map(e=>`(${e.name},${a(e.value)})`).join(`,`)})`;case`Except`:return`$Except(${a(n.function)},${n.specs.map(e=>`(${e.trail.map(e=>e.kind===`Dot`?`.${e.field}`:`.${a(e.expression)}`).join(``)}=${a(e.value)})`).join(`,`)})`;case`Dot`:return`$Dot(${a(n.expression)},${n.field})`;case`Sub`:case`Tsub`:return`$${n.kind}(${Cs[n.modal]},${a(n.action)},${a(n.subscript)})`;case`Fair`:return`$Fair(${ws[n.fairness]},${a(n.subscript)},${a(n.action)})`;case`Case`:return`$Case(${n.arms.map(e=>`(${a(e.condition)},${a(e.body)})`).join(`,`)},${n.other?a(n.other):``})`;case`String`:return Es(n.value);case`Num`:return`$Num(${n.integer},${n.fraction})`;case`At`:return`$At`;case`Bang`:throw new e.M}},d=t=>{let n={hyp:1,variable:1},r=(o,s)=>{let c=t.context[o];if(!c)return`$Goal(${u(n,t.active)})`;let d=e=>(i(e),{rest:r(o+1,A(s,c)),entry:a()});switch(c.kind){case`Fresh`:{if(!c.domain){let e=Os(c),t=d({kind:`Hyp`,label:e});return t.entry.isUsed?`${t.rest}${e}${c.name}`:t.rest}let e=d({kind:`Hyp`,label:`CON`});if(c.domainVisibility===`Hidden`)return e.rest;let t=e.entry.isUsed?String(l(e.entry)):`_`;return`${e.rest}$Dom(${t};${u(n,c.domain)})`}case`Flex`:return d({kind:`Hyp`,label:`VAR`}).rest;case`Defn`:{let t=c.definition;if(t.kind===`Recursive`)return d({kind:`Hyp`,label:`CON`}).rest;if(t.kind===`Bpragma`)return d({kind:`Pragma`}).rest;if(t.kind===`Instance`)throw new e.M;let r=d({kind:`Hyp`,label:`HYP`});if(!r.entry.isUsed)return r.rest;let i=l(r.entry);return c.visibility===`Hidden`?`${r.rest}$Def(${i},${gn(s,t.body)?0:3})`:`${r.rest}$Def(${i};${u(n,t.body)})`}case`Fact`:return c.visibility===`Hidden`?d({kind:`None`}).rest:`${d({kind:`Hyp`,label:`HYP`}).rest}$Fact(${u(n,c.expression)},${c.time.toLowerCase()})`}};return r(0,void 0)};return d(t)},As=e=>Lo(ks(e)),js={kind:`Internal`,builtin:`TRUE`},Ms=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2?e.args:void 0,Ns=e=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`ENABLED`&&e.args.length===1?e.args[0]:void 0,Ps=(e,t)=>{let n=Ms(e,t),r=n&&Ns(n[0]),i=n&&Ns(n[1]);return r&&i?[r,i]:void 0},Fs=(t,n)=>{let r=/* @__PURE__ */ new Set,i=(t,n)=>{let a={...t,isPrimed:!0},o=n.kind===`Apply`&&n.operator.kind===`Internal`&&n.operator,s=o&&o.builtin,c=n.kind===`Apply`?n.args:[];if((s===`Prime`&&c.length===1||s===`ENABLED`||s===`Cdot`&&c.length===2||s===`UNCHANGED`&&c.length===1||n.kind===`Sub`)&&t.isPrimed)throw new e.M;if(s===`Prime`&&c.length===1)i(a,c[0]);else if(s===`Cdot`&&c.length===2)i(t,c[1]);else if(s===`UNCHANGED`&&c.length===1)i(a,c[0]);else if(n.kind===`Sub`)i(t,n.action),i(a,n.subscript);else if(n.kind===`Ix`){let i=ot(t.scope,n.index-1)?.hyp;if(!i)throw new e.M;i.kind===`Flex`&&t.isPrimed&&r.add(i.name)}else s!==`ENABLED`&&N(t,n,i,(e,t)=>({...e,scope:A(e.scope,t)}));return n};return i({scope:t,isPrimed:!1},n),r},Is=(e,t,n)=>{let r=Fs(e,t);return[...Fs(e,n)].every(e=>!r.has(e))},Ls=(t,n)=>{let r=e=>yr(t,e).level,i=(t,n)=>{if(r(t)>2||r(n)>2)throw new e.M},a=Ns(n),o=a&&Ms(a,`Disj`);if(o)return i(o[0],o[1]),{name:`abdisj_inverse`,left:o[0],right:o[1]};let s=Ps(n,`Disj`);if(s)return i(s[0],s[1]),{name:`abdisj`,left:s[0],right:s[1]};let c=a&&Ms(a,`Conj`);if(c){let e=c[0],n=c[1],a=Is(t,e,n);return i(e,n),a?{name:r(e)===2?`abconj_inverse`:`pconj_inverse`,left:e,right:n}:void 0}let l=Ps(n,`Conj`);if(l)return Is(t,l[0],l[1])?{name:`abconj`,left:l[0],right:l[1]}:void 0;let u=Ms(n,`Conj`),d=u&&Ns(u[1]);if(u&&d)return r(u[0])<=1&&r(d)<=2?{name:`pconj`,left:u[0],right:d}:void 0;let f=Ps(n,`Equiv`)??Ps(n,`Eq`);if(f)return{name:`equiv`,left:f[0],right:f[1]};let p=Ps(n,`Implies`);return p&&{name:`implies`,left:p[0],right:p[1]}},Rs=t=>{let n=j(void 0,t.context),r=Ls(n,t.active),i={isPremise:!1,isLeftBoolean:!1,isRightBoolean:!1};if(t.context.forEach((e,n)=>{if(!r||e.kind!==`Fact`||e.visibility!==`Visible`)return;let a=t.context.length-n,o=e.expression,s=e=>R(L(a,e),r.left),c=e=>R(L(a,e),r.right),l=(e,t)=>e!==void 0&&s(e[0])&&c(e[1])&&t.includes(r.name),u=Ns(o),d=u&&Ms(u,`Conj`),f=Ms(o,`Conj`),p=f&&Ns(f[1]),m=Ms(o,`Mem`),h=m?.[1].kind===`Internal`&&m[1].builtin===`BOOLEAN`;l(d,[`pconj`])||l(u&&Ms(u,`Disj`),[`abdisj`])||l(Ps(o,`Disj`),[`abdisj_inverse`])||l(d,[`abconj`])||l(Ps(o,`Conj`),[`abconj_inverse`,`pconj_inverse`])||l(f&&p&&[f[0],p],[`pconj_inverse`])?i.isPremise=!0:l(Ms(o,`Equiv`),[`equiv`])?(i.isPremise=!0,i.isLeftBoolean=!0,i.isRightBoolean=!0):l(Ms(o,`Eq`),[`equiv`])?i.isPremise=!0:m&&h&&s(m[0])?i.isLeftBoolean=!0:m&&h&&c(m[0])?i.isRightBoolean=!0:l(Ms(o,`Implies`),[`implies`])&&(i.isPremise=!0)}),!i.isPremise||!i.isLeftBoolean||!i.isRightBoolean)throw new e.T(`ENABLEDaxioms proof directive did not succeed.
41
- `);return{...t,active:js}},zs={Constant:0,State:1,Action:2,Temporal:3},Bs=(e,t,n)=>e.every((e,r)=>r<t.length&&n(e,t[r]))&&e.length===t.length,Vs=e=>[...new Map(e.toReversed().map(e=>[e.name,e.value]))].toSorted((e,t)=>e[0]<t[0]?-1:1),Hs=(t,n)=>{let r=ot(t,n-1);if(!r)throw new e.M;let i=r.hyp;if(i.kind===`Fresh`)return{name:i.name,kind:i.level,level:zs[i.level]??-1};if(i.kind===`Flex`)return{name:i.name,kind:`Variable`,level:1};if(i.kind===`Defn`&&i.definition.kind===`Operator`){let e=yr(r.rest,i.definition.body).level;return{name:i.definition.name,kind:`Definition`,level:e}}throw new e.M},Us=(e,t)=>j(e,t.map(dt)),Ws=(e,t)=>j(e,t.map(ft)),Gs=(e,t)=>j(e,t.map(pt)),Ks=(e,t)=>j(e,t.map(e=>({kind:`Flex`,name:e}))),qs=(t,n,r,i)=>{let a=/* @__PURE__ */ new Map,o=(e,t,n,r)=>{let i=Hs(e,n),o=Hs(t,r);if(i.kind===`Unknown`)return n===r;if(i.kind===`Variable`||i.kind===`Definition`)return i.name===o.name&&o.kind===i.kind;let s=zs[o.kind];if(!(s!==void 0&&s<=i.level||o.kind===`Definition`&&o.level<=i.level))return!1;let c=a.get(i.name);return c===void 0?(a.set(i.name,o.name),!0):c===o.name},s=(e,t,n,r)=>{if(n.kind===`Operator`&&r.kind===`Operator`||n.kind===`Bpragma`&&r.kind===`Bpragma`)return p(e,t,n.body,r.body);if(n.kind!==`Instance`||r.kind!==`Instance`)return!1;let i=n.instance.args,a=r.instance.args,o=(e,t)=>j(e,t.map(e=>lt(e,`Unknown`))),s=e=>Vs(e.substitutions.map(e=>({name:e.name,value:e.expression})));return Bs(i,a,(e,t)=>e===t)&&n.instance.module===r.instance.module&&c(o(e,i),o(t,a),s(n.instance),s(r.instance))},c=(e,t,n,r)=>Bs(n,r,(n,r)=>n[0]===r[0]&&p(e,t,n[1],r[1])),l=(e,t,n,r)=>Bs(n,r,(n,r)=>{if(n.level!==r.level)return!1;let i=n.domain,a=r.domain;return i.kind===`Domain`&&a.kind===`Domain`?p(e,t,i.expression,a.expression):i.kind===a.kind&&i.kind!==`Domain`}),u=(e,t,n,r)=>n.kind===`Fresh`&&r.kind===`Fresh`?n.level!==r.level||n.shape!==r.shape?!1:n.domain&&r.domain?p(e,t,n.domain,r.domain):!n.domain&&!r.domain:n.kind===`Flex`&&r.kind===`Flex`?!0:n.kind===`Defn`&&r.kind===`Defn`?s(e,t,n.definition,r.definition)&&n.isLocal===r.isLocal:n.kind===`Fact`&&r.kind===`Fact`&&p(e,t,n.expression,r.expression),d=(e,t,n,r)=>n.length===0||r.length===0?n.length===r.length:u(e,t,n[0],r[0])&&d(A(e,n[0]),A(t,r[0]),n.slice(1),r.slice(1)),f=(e,t,n,r)=>!n.domain||!r.domain?!n.domain&&!r.domain&&p(A(e,lt(n.name,`Constant`)),A(t,lt(r.name,`Constant`)),n.body,r.body):p(e,t,n.domain,r.domain)&&p(A(e,M(n.name,n.domain)),A(t,M(r.name,r.domain)),n.body,r.body),p=(t,n,r,i)=>{if(r.kind===`Parens`)return p(t,n,r.expression,i);if(i.kind===`Parens`)return p(t,n,r,i.expression);let a=(e,r)=>p(t,n,e,r),u=(e,t)=>Bs(e,t,a);switch(r.kind){case`Ix`:return i.kind===`Ix`&&o(t,n,r.index,i.index);case`Opaque`:return i.kind===`Opaque`&&r.name===i.name;case`Internal`:return i.kind===`Internal`&&r.builtin===i.builtin;case`Lambda`:return i.kind===`Lambda`&&r.params.length===i.params.length&&p(Ws(t,r.params),Ws(n,i.params),r.body,i.body);case`Apply`:return i.kind===`Apply`&&a(r.operator,i.operator)&&u(r.args,i.args);case`Sequent`:return i.kind===`Sequent`&&d(t,n,r.sequent.context,i.sequent.context)&&p(j(t,r.sequent.context),j(n,i.sequent.context),r.sequent.active,i.sequent.active);case`Bang`:{if(i.kind!==`Bang`||!a(r.expression,i.expression))return!1;let t=i.selectors,n=r.selectors.every((e,n)=>{let r=t[n];return r?e.kind===`Number`&&r.kind===`Number`?e.value===r.value:e.kind===`Instance`&&r.kind===`Instance`?u(e.args,r.args):e.kind===`Label`&&r.kind===`Label`?e.label===r.label&&u(e.args,r.args):e.kind===r.kind:!0});if(n&&r.selectors.length!==t.length)throw new e.M(`Invalid_argument`);return n}case`With`:return i.kind===`With`&&a(r.expression,i.expression);case`Let`:return i.kind===`Let`&&Bs(r.definitions,i.definitions,(e,r)=>s(t,n,e,r))&&p(Gs(t,r.definitions),Gs(n,i.definitions),r.body,i.body);case`If`:return i.kind===`If`&&a(r.condition,i.condition)&&a(r.consequent,i.consequent)&&a(r.alternative,i.alternative);case`List`:return i.kind===`List`&&r.bullet===i.bullet&&u(r.items,i.items);case`Quant`:return i.kind===`Quant`&&r.quantifier===i.quantifier&&l(t,n,r.bounds,i.bounds)&&p(Us(t,r.bounds),Us(n,r.bounds),r.body,i.body);case`Tquant`:return i.kind===`Tquant`&&r.quantifier===i.quantifier&&Bs(r.names,i.names,(e,t)=>e===t)&&p(Ks(t,r.names),Ks(n,i.names),r.body,i.body);case`Choose`:case`SetSt`:return i.kind===r.kind&&f(t,n,r,i);case`SetOf`:return i.kind===`SetOf`&&p(Us(t,r.bounds),Us(n,i.bounds),r.element,i.element)&&l(t,n,r.bounds,i.bounds);case`SetEnum`:return i.kind===`SetEnum`&&u(r.elements,i.elements);case`Arrow`:return i.kind===`Arrow`&&a(r.domain,i.domain)&&a(r.range,i.range);case`Fcn`:return i.kind===`Fcn`&&l(t,n,r.bounds,i.bounds)&&p(Us(t,r.bounds),Us(n,i.bounds),r.body,i.body);case`FcnApp`:return i.kind===`FcnApp`&&u([r.function,...r.args],[i.function,...i.args]);case`Tuple`:return i.kind===`Tuple`&&u(r.elements,i.elements);case`Product`:return i.kind===`Product`&&u(r.factors,i.factors);case`Rect`:case`Record`:return i.kind===r.kind&&c(t,n,Vs(r.fields),Vs(i.fields));case`Except`:return i.kind===`Except`&&a(r.function,i.function)&&Bs(r.specs,i.specs,(e,t)=>Bs(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&a(e.expression,t.expression))&&a(e.value,t.value));case`Dot`:return i.kind===`Dot`&&a(r.expression,i.expression)&&r.field===i.field;case`Sub`:case`Tsub`:return i.kind===r.kind&&r.modal===i.modal&&a(r.action,i.action)&&a(r.subscript,i.subscript);case`Fair`:return i.kind===`Fair`&&r.fairness===i.fairness&&a(r.subscript,i.subscript)&&a(r.action,i.action);case`Case`:{if(i.kind!==`Case`)return!1;let e=r.arms[0],t=i.arms[0];return(e&&t?a(e.condition,t.condition)&&a(e.body,t.body):!e&&!t)?r.other&&i.other?a(r.other,i.other):!r.other&&!i.other:!1}case`String`:return i.kind===`String`&&r.value===i.value;case`Num`:return i.kind===`Num`&&r.integer===i.integer&&r.fraction===i.fraction;case`At`:return i.kind===`At`&&r.isExcept===i.isExcept}},m=p(t,n,r,i),h=it(t),g=[...a].map(t=>t[0]===t[1]||h.reduce((n,r)=>{if(r.kind===`Fact`)return n;if(r.kind===`Defn`&&r.definition.kind!==`Operator`)throw new e.M;return n||(r.kind===`Defn`?r.definition.name:r.name)===t[0]},!1));return m&&g.every(Boolean)},Js=t=>{let n=j(void 0,t.context);if(!t.context.some((e,r)=>{if(e.kind!==`Fact`||e.visibility!==`Visible`)return!1;let i=ot(n,t.context.length-r),a=e.expression;return a.kind===`Sequent`?qs(j(i,a.sequent.context),n,a.sequent.active,t.active):qs(i,n,a,t.active)}))throw new e.T(`LevelComparison proof directive did not succeed.
42
- `);return{...t,active:{kind:`Internal`,builtin:`TRUE`}}},Ys=/* @__PURE__ */ new Set([`expandenabled`,`expandcdot`,`autouse`,`lambdify`,`enabledaxioms`,`levelcomparison`]),Xs=[{prover:`smt`,timeLimitMs:5e3},{prover:`zenon`,timeLimitMs:1e4},{prover:`isabelle`,timeLimitMs:3e4,tactic:`auto`}],Zs={zenon:{prover:`zenon`,seconds:10},isabelle:{prover:`isabelle`,seconds:30},yices:{prover:`yices`,seconds:30},ls4:{prover:`ls4`,seconds:10},z3:{prover:`z3`,seconds:5,isBudgeted:!0},smt:{prover:`smt`,seconds:5,isBudgeted:!0},cvc3:{prover:`cvc3`,seconds:5},cooper:{prover:`cooper`,seconds:0},fail:{prover:`fail`,seconds:0},smt2lib:{prover:`smt`,seconds:5,isBudgeted:!0},smt2z3:{prover:`z3`,seconds:5,isBudgeted:!0},smt3:{prover:`smt`,seconds:5,isBudgeted:!0},z33:{prover:`z3`,seconds:5,isBudgeted:!0},cvc33:{prover:`cvc3`,seconds:5},yices3:{prover:`yices`,seconds:5},verit:{prover:`verit`,seconds:5},zipper:{prover:`zipper`,seconds:30},spass:{prover:`spass`,seconds:5},tptp:{prover:`tptp`,seconds:5},trivial:{prover:`trivial`,seconds:0},...Object.fromEntries([...Ys].map(e=>[e,{prover:e,seconds:0}]))},Qs=(t,n,r,i)=>{let a=Zs[t];if(!a)throw new e.T(`Unknown prover: ${t}`);if(r!==void 0&&!a.isBudgeted)throw new e.T(`A Z3 rlimit budget ("rN") is only supported by the SMT and Z3 backends.`);return{prover:a.prover,timeLimitMs:r===void 0?(n??a.seconds)*1e3:1/0,...r!==void 0&&{rlimit:r},...a.prover===`isabelle`&&{tactic:i??`auto`}}},$s=t=>{let n=Number.parseFloat(t.slice(1));if(!/^[rR]./.test(t)||!Number.isFinite(n)||n<=0)throw new e.T(`Invalid SMT budget "${t}"`);return Math.max(1,Math.trunc(Math.min(n*3e6,4294967295)))},ec=(t,n)=>{let r=t.reduce((t,n)=>{let r=n.value,i=r.kind===`Default`?t.args[0]:void 0,a=r.kind===`Default`?t.args.slice(1):t.args;if(r.kind===`Default`&&!i)throw new e.T(`Some arguments are missing`);let o=r.kind===`String`?r.value:i?.kind===`String`?i.value:void 0;switch(n.hint){case`prover`:case`tactic`:if(o===void 0)throw new e.T(`This argument should be a string`);return{...t,args:a,[n.hint]:o};case`timeout`:if(r.kind===`Float`)return{...t,args:a,timeout:r.value};if(o!==void 0)return{...t,args:a,rlimit:$s(o)};if(i?.kind!==`Num`)throw new e.T(`This argument should be a number of seconds`);return{...t,args:a,timeout:Number(`${i.integer}.${i.fraction}`)};default:throw new e.T(`Unknown keyword in proof method definition: ${n.hint}`)}},{args:n});if(r.args.length>0)throw new e.T(`Too many arguments`);if(r.prover===void 0)throw new e.T(`Missing prover name`);return Qs(r.prover,r.timeout,r.rlimit,r.tactic)},tc=e=>Qs(e.name,e.timeout,void 0,e.tactic),nc=t=>{let n=[],r={methods:[],useLocation:null};return t.context.forEach((t,i)=>{let a=t.kind===`Fact`&&t.visibility===`Visible`&&t.expression;if(a&&a.kind===`With`){r.methods.push(tc(a.method)),n.push(void 0);return}if(t.kind===`Defn`&&t.definition.kind===`Bpragma`){n.push({kind:`Premeth`,groups:t.definition.methods});return}if(t.kind===`Defn`&&t.definition.kind===`Operator`&&t.visibility===`Visible`){let e=t.definition.body;n.push(e.kind===`With`?{kind:`Meth`,method:e.method}:void 0);return}if(n.push(void 0),!a||t.kind!==`Fact`)return;let o=a.kind===`Apply`?a.operator:a;if(o.kind!==`Ix`)return;let s=n[i-o.index];if(s?.kind===`Premeth`){t.useLocation!==r.useLocation&&(r.methods=[],r.useLocation=t.useLocation);let e=a.kind===`Apply`?a.args:[];r.methods.push(...s.groups.map(t=>ec(t,e)))}else if(s?.kind===`Meth`){if(a.kind===`Apply`)throw new e.M;r.methods.push(tc(s.method))}}),r.methods},rc=e=>{let t=e.method===void 0?nc(e.sequent):[tc(e.method)],n=t.filter(e=>!Ys.has(e.prover));return{frontends:new Set(t.flatMap(e=>Ys.has(e.prover)?[e.prover]:[])),provers:n.length>0?n:Xs}},ic=e=>ct(P(0),(t,n)=>n.kind===`Defn`&&(e&&n.definition.kind===`Bpragma`||n.definition.kind===`Operator`&&n.visibility===`Visible`)?[St(I(t,n.definition.body),t),void 0]:[F(1,t),kt(t,n)]),ac=ic(!0),oc=ic(!1),sc=(e,t=!0)=>{let n=(t?ac:oc)(e.context);return{context:n.context,active:I(n.state,e.active)}},cc=/* @__PURE__ */ new Set([`BoxTrue`,`BoxFalse`,`Diamond`,`Actplus`,`Leadsto`,`Cdot`]),lc=e=>{switch(e.kind){case`Fresh`:return e.domain?[e.domain]:[];case`Flex`:return[];case`Defn`:return e.visibility===`Hidden`||e.definition.kind!==`Operator`&&e.definition.kind!==`Bpragma`?[]:[e.definition.body];case`Fact`:return e.visibility===`Hidden`?[]:[e.expression]}},uc=e=>{if(e.kind===`Tsub`||e.kind===`Fair`||e.kind===`Apply`&&e.operator.kind===`Internal`&&cc.has(e.operator.builtin))return!1;if(e.kind===`Sequent`){let t=e.sequent;return[...t.context.flatMap(lc),t.active].every(uc)}return xt(e).every(uc)},dc=t=>{if(t.kind!==`Let`)return bt(t,dc);let[n,...r]=t.definitions;if(!n)return dc(t.body);if(n.kind!==`Operator`&&n.kind!==`Bpragma`)throw new e.w(n.kind===`Instance`?`Found INSTANCE in Expr.Elab.let_normalize, all INSTANCE statements have been replaced with definitions in Module.Elab `:`Expr.Elab.let_normalize`);let i=dc(n.body),a={...t,definitions:r};return dc(I(St(i,P(0)),a))},fc=(e,t)=>t.kind===`Dot`?O({kind:`Dot`,expression:e,field:t.field},e):O({kind:`FcnApp`,function:e,args:[t.expression]},e),pc=(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&R(e.expression,t.expression),mc=(e,t)=>{let n=t.kind===`Dot`?t.field:t.expression.kind===`String`?t.expression.value:void 0;return e.kind===`Record`&&n!==void 0?e.fields.find(e=>e.name===n):void 0},hc=e=>{if(e.kind!==`Except`)return bt(e,hc);let t=e,n=(e,t)=>mc(e,t)?.value??fc(e,t),r=(e,n,r)=>{let i=mc(e,n);if(e.kind!==`Record`||!i)return O({kind:`Except`,function:e,specs:[{trail:[n],value:r}]},t);let a=e.fields.map(e=>e.name===i.name?{name:e.name,value:r}:e);return O({kind:`Record`,fields:a},e)},i=(e,t)=>{let[a,...o]=t;if(!a)return e;if(a.trail.length===0)return i(a.value,o);let s=a.trail[0],c=t.findIndex(e=>e.trail.length===0||!pc(e.trail[0],s)),l=c===-1?t.length:c,u=t.slice(0,l).map(e=>({trail:e.trail.slice(1),value:e.value}));return i(r(e,s,i(n(e,s),u)),t.slice(l))};return i(hc(t.function),_t(t.specs,hc))},gc=ct(!0,(e,t)=>[e&&lc(t).every(uc),yt(t,dc,`all`)]),_c=ct(void 0,(e,t)=>[void 0,yt(t,hc,`all`)]),vc=e=>{let t=gc(e.context),n=dc(e.active);return t.state&&uc(e.active)?{context:_c(e.context,t.context).context,active:hc(n)}:{context:t.context,active:n}},yc=(t,n)=>{let r=n.has(`expandenabled`),i=n.has(`expandcdot`),a=n.has(`autouse`),o=n.has(`lambdify`);if(!r&&!i&&!o)return n.has(`levelcomparison`)?Js(t):n.has(`enabledaxioms`)?Rs(t):t;let s=En({value:0},()=>{throw new e.M},()=>{}),c={kind:`Sequent`,sequent:t},l=r||i?Gr(s,()=>{},void 0,c,{isEnabled:r,isCdot:i,isAutoUse:a}):Hr(s,()=>{},void 0,c,{isEnabled:!0,isCdot:!0,isAutoUse:a});if(l.kind!==`Sequent`)throw new e.M;return l.sequent},bc=(e,t=rc(e))=>yc(vc(sc(e.sequent)),t.frontends),xc=e=>e.active.kind===`Internal`&&e.active.builtin===`TRUE`||e.context.some((t,n)=>t.kind===`Fact`?R(t.expression,L(n-e.context.length,e.active)):t.kind!==`Fresh`||!t.domain?!1:R(k(`Mem`,[{kind:`Ix`,index:1},L(1,t.domain)],{}),L(n+1-e.context.length,e.active))),Sc=e=>e.domain.kind===`NoDomain`,Cc=e=>{if(e.kind===`List`&&(e.bullet===`And`||e.bullet===`Refs`)){let t=e.items.map(Cc),n=t.flatMap(e=>e[0]),r=t.flatMap(e=>e[1]?[e[1]]:[]);return r.length<=1?[n,r[0]]:[n,{...e,bullet:`And`,items:r}]}if(e.kind===`Apply`&&e.operator.kind===`Internal`){let t=e.operator.builtin;if(t===`Conj`&&e.args.length===2){let t=Cc(e.args[0]),n=Cc(e.args[1]),r=[...t[0],...n[0]];return t[1]&&n[1]?[r,{...e,args:[t[1],n[1]]}]:[r,t[1]??n[1]]}if(t===`Eq`)return[[e],void 0]}if(e.kind===`Internal`&&e.builtin===`TRUE`)return[[],void 0];if(e.kind===`Quant`&&e.quantifier===`Forall`&&e.bounds.every(Sc)){let t=Cc(e.body),n=(t,n)=>O({kind:`Quant`,quantifier:`Forall`,bounds:e.bounds,body:t},n);return[t[0].map(e=>n(e,e)),t[1]&&n(t[1],e)]}return[[],e]},wc=e=>{let t=[],n=e.context.reduce((e,n)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return t.push(kt(e,n)),F(1,e);let r=Cc(n.expression),i=[...r[1]?[r[1]]:[],...r[0]];return i.forEach((r,i)=>t.push({...n,expression:L(i,I(e,r))})),{kind:`Compose`,outer:P(i.length-1),inner:F(1,e)}},P(0));return{context:t,active:I(n,e.active)}},Tc=(e,t)=>{let[n,r]=st(e,t.context,(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return{...t,name:`${Yo[t.level]}_${t.name}_`,domain:t.domain&&Ec(e,t.domain)};case`Flex`:return{...t,name:`VARIABLE_${t.name}_`};case`Defn`:{let n=t.definition;if(n.kind!==`Operator`)return t;let r=Ec(e,n.body),i=Xo[yr(e,r).level];return{...t,definition:{...n,name:`${i}_${n.name}_`,body:r}}}case`Fact`:return{...t,expression:Ec(e,t.expression)}}})();return[A(e,n),n]});return{context:r,active:Ec(n,t.active)}},Ec=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:Tc(e,t.sequent)};let n=N(e,t,Ec,A,`all`);switch(n.kind){case`Lambda`:return{...n,params:n.params.map(e=>({...e,name:`Unknown_${e.name}_`}))};case`Quant`:case`Fcn`:case`SetOf`:return{...n,bounds:n.bounds.map(e=>({...e,name:`${Yo[e.level]}_${e.name}_`}))};case`Choose`:case`SetSt`:return{...n,name:`CONSTANT_${n.name}_`};default:return n}},Dc=(e,t)=>{if(t.kind!==`Sequent`)return N(e,t,Dc,A,`all`);let n={scope:e,substitution:P(0),context:[]},r=e=>{let t=e.kind===`Fact`&&e.visibility===`Visible`&&e.time===`Always`?{...e,expression:k(`BoxTrue`,[e.expression],e.expression)}:e;n.context.push(t),n.scope=A(n.scope,t)};for(let e of t.sequent.context){let t=kt(n.substitution,e);if(t.kind!==`Fresh`||!t.domain||e.kind!==`Fresh`||!e.domain){r(t.kind===`Fact`?{...t,expression:Dc(n.scope,t.expression)}:t),n.substitution=F(1,n.substitution);continue}let i=Dc(n.scope,t.domain);r({...t,domain:void 0}),r({kind:`Fact`,expression:k(`Mem`,[O({kind:`Ix`,index:1},i),L(1,i)],i),visibility:t.domainVisibility,time:t.level===`Constant`?vn(n.scope,e.domain):`Now`,location:t.location}),n.substitution={kind:`Compose`,outer:P(1),inner:F(1,n.substitution)}}let i=I(n.substitution,t.sequent.active);return{...t,sequent:{context:n.context,active:Dc(n.scope,i)}}},Oc={Conj:`&`,Disj:`|`,Implies:`->`,Equiv:`<->`},kc={Neg:`~`,BoxTrue:`always`,BoxFalse:`always`,Diamond:`sometime`,Prime:`next`},Ac=e=>{if(e.kind===`Internal`&&e.builtin===`TRUE`)return;if(e.kind===`List`&&e.bullet!==`Or`){let t=e.items.flatMap(e=>Ac(e)??[]);return t.length<=1?t[0]:{...e,bullet:`And`,items:t}}if(e.kind!==`Apply`||e.operator.kind!==`Internal`||e.operator.builtin!==`Conj`||e.args.length!==2)return e;let t=Ac(e.args[0]),n=Ac(e.args[1]);return t&&n?{...e,args:[t,n]}:t??n},jc=`(cc | ~ cc)`,Mc=e=>{let t=(e,n,r=!1)=>{let i=n=>t(e,n);switch(n.kind){case`Internal`:if(n.builtin===`TRUE`)return jc;if(n.builtin===`FALSE`)return`(cc & ~ cc)`;break;case`Apply`:{let e=n.operator,t=n.args;if(e.kind!==`Internal`)break;let r=Oc[e.builtin];if(r&&t.length===2)return`(${i(t[0])} ${r} ${i(t[1])})`;let a=kc[e.builtin];if(a&&t.length===1)return`(${a} ${i(t[0])})`;break}case`List`:{if(n.items.length===0)return jc;let e=n.bullet===`Or`?`|`:`&`;return n.items.map(i).reduceRight((t,n)=>`(${n} ${e} ${t})`)}case`Sequent`:{let i=[...e],a=[];for(let e of n.sequent.context){let n=e.kind!==`Fact`||e.visibility!==`Visible`?void 0:r?Ac(e.expression):e.expression;n&&a.push(t(i,n)),i.push(e)}let o=t(i,n.sequent.active);return a.length===0?o:`(${a.join(` & `)} -> ${o})`}}return us(e,n)},n=Ec(void 0,{kind:`Sequent`,sequent:e});return`not (${t([],Dc(void 0,un(cn(ln(n)))),!0)})`},Nc=(e,t)=>e<t?-1:+(e>t),Pc=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Nc(e,t);if(!Array.isArray(e)||!Array.isArray(t))return 0;let n=e.findIndex((e,n)=>n>=t.length||Pc(e,t[n])!==0);return n===-1?e.length-t.length:n>=t.length?1:Pc(e[n],t[n])},Fc={"\\":`backslash_`,"+":`plussign_`,"-":`hyphen_`,"*":`asterisk_`,"/":`slash_`,"%":`percentsign_`,"^":`circumflexaccent_`,"&":`ampersand_`,"@":`atsign_`,"#":`pound_`,$:`dollarsign_`,"(":`leftparenthesis_`,")":`rightparenthesis_`,"|":`verticalbar_`,".":`period_`,":":`colon_`,"?":`questionmark_`,"!":`exclamationmark_`,"<":`lessthansign_`,">":`greaterthansign_`,"=":`equalsign_`," ":`space_`},Ic=e=>`smt__${e.replace(/[\\+\-*/%^&@#$()|.:?!<>= ]/g,e=>Fc[e]).replaceAll(`_`,`__`)}`,Lc=Ic(`TLA__`),Rc=new Map(Object.entries(Fc).map(e=>[e[1],e[0]])),zc=RegExp(`(${[...Rc.keys()].join(`|`)})`,`g`),W=e=>Ic(`TLA__${e}`),Bc=e=>e.startsWith(Lc)?e.slice(Lc.length).replaceAll(`__`,`_`).replace(zc,e=>Rc.get(e)??e):void 0,G=W(`Mem`),Vc=W(`SetExtTrigger`),Hc=W(`SubsetEq`),Uc=W(`Cup`),Wc=W(`Cap`),Gc=W(`SetMinus`),Kc=W(`Subset`),qc=W(`Union`),Jc=W(`Tt_Idv`),Yc=W(`Cast_Bool`),Xc=W(`BoolSet`),Zc=W(`StrSet`),Qc=W(`IntSet`),$c=W(`NatSet`),K=W(`Cast_Int`),q=W(`Proj_Int`),el=W(`IntLteq`),tl=W(`IntRange`),J=W(`FunApp`),nl=W(`FunDom`),rl=W(`FunIsafcn`),il=W(`FunSet`),al=W(`FunExcept`),ol=W(`TrigEq_Set$Idv$`),sl=W(`IsSetOf`),Y=W(`Seq`),X=W(`Len`),cl=W(`Cat`),ll=W(`Append`),ul=W(`Head`),dl=W(`Tail`),fl=W(`SubSeq`),pl=W(`Tuple_0`),ml={Cup:Uc,Cap:Wc,Setminus:Gc,SUBSET:Kc,UNION:qc,DOMAIN:nl,Plus:W(`IntPlus`),Minus:W(`IntMinus`),Times:W(`IntTimes`),Exp:W(`IntExp`),Quotient:W(`IntQuotient`),Remainder:W(`IntRemainder`),Uminus:W(`IntUminus`),Range:tl,Seq:Y,Len:X,BSeq:W(`BSeq`),Cat:cl,Append:ll,Head:ul,Tail:dl,SubSeq:fl},hl=(e,t)=>Array.from({length:t},(t,n)=>`${e}${n+1}`),gl=(e,t=`Idv`)=>e.map(e=>`(${e} ${t})`).join(` `),Z=(e,t,n=[],r=`Idv`)=>e.length===0?t:`(forall (${gl(e,r)}) ${n.length===0?t:`(! ${t} ${n.map(e=>`:pattern (${e.join(` `)})`).join(` `)})`})`,_l=e=>e.length===0?`true`:e.length===1?e[0]:`(and ${e.join(` `)})`,vl=e=>e.length===0?`false`:e.length===1?e[0]:`(or ${e.join(` `)})`,Q=(e,t)=>t.length===0?e:`(${e} ${t.join(` `)})`,yl=(e,t,n=`Idv`,r=`Idv`)=>`(declare-fun ${e} (${Array.from({length:t},()=>r).join(` `)}) ${n})`,bl=(e,t)=>{let n={depth:0,index:t};for(;n.index<e.length;n.index++)if(e[n.index]===`(`&&n.depth++,e[n.index]===`)`&&n.depth--,n.depth===0)return n.index;return e.length},xl=(e,t,n)=>e.replace(/[^\s()]+/g,e=>e===t?n:e),Sl=(e,t)=>t===0?e:`${e}_${t}`,Cl=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Set;return{names:t,adjoin:n=>{let r=Ic(n),i=(e.get(r)??-1)+1,a=Array.from({length:t.size+1},(e,t)=>i+t).find(e=>!t.has(Sl(r,e)))??i;return{base:r,salt:a,name:Sl(r,a)}},enter:n=>{let r=e.get(n.base);return e.set(n.base,n.salt),t.add(n.name),()=>{t.delete(n.name),r===void 0?e.delete(n.base):e.set(n.base,r)}}}},wl=e=>{let t=Cl();return{resolve:n=>{let r=/^\(declare-fun (\S+)/.exec(n)?.[1];if(r!==void 0){let i=e.get(r);return i?t.enter(i):t.names.add(r),n}let i=[...n.matchAll(/\|[^|]*\||[()]|[^\s()|]+/g)],a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=[],c={index:0,depth:0};for(;c.index<i.length;){let e=i[c.index][0];if(e===`(`&&(i[c.index+1]?.[0]===`forall`||i[c.index+1]?.[0]===`exists`)&&i[c.index+2]?.[0]===`(`){c.depth++;let e={depth:c.depth,exits:[]};for(s.push(e),c.index+=3;i[c.index]?.[0]===`(`;){let n=i[c.index+1][0],r=t.adjoin(n.replace(/#\d+$/,``)),s=o.get(n)??[];o.set(n,[...s,r.name]),e.exits.push(t.enter(r),()=>o.set(n,s)),a.set(c.index+1,r.name),c.index+=4}c.index++;continue}e===`(`&&c.depth++,e===`)`&&(s.at(-1)?.depth===c.depth&&s.pop()?.exits.toReversed().forEach(e=>e()),c.depth--);let n=o.get(e)?.at(-1);n!==void 0&&a.set(c.index,n),c.index++}return i.map((e,t)=>{let r=i[t+1]?.index??n.length;return`${a.get(t)??e[0]}${n.slice(e.index+e[0].length,r)}`}).join(``)}}},Tl=/* @__PURE__ */ `ChooseDef.ChooseExt.SetExt.SubsetEqDef.SubsetEqIntro.SubsetEqElim.UnionDef.UnionIntro.UnionElim.SubsetDef.SubsetDefAlt.SubsetIntro.SubsetElim.CupDef.CapDef.SetMinusDef.SetStDef.NatSetDef.IntPlusTyping.IntUminusTyping.IntMinusTyping.IntTimesTyping.IntQuotientTyping.IntRemainderTyping.IntExpTyping.NatPlusTyping.NatTimesTyping.IntRangeDef.NonNegIsPos.LteqReflexive.LteqTransitive.LteqAntisym.FunExt.FunConstrIsafcn.FunSetDef.FunSetIntro.FunSetElim1.FunSetElim2.FunSetImIntro.FunSetSubs.FunDomDef.FunAppDef.FunTyping.FunExceptIsafcn.FunExceptDomDef.FunExceptAppDef1.FunExceptAppDef2.FunExceptTyping.FunImDef.FunImIntro.FunImElim.SeqSetIntro.SeqSetElim1.SeqSetElim2.SeqLenDef.SeqCatTyping.SeqCatLen.SeqCatApp1.SeqCatApp2.SeqAppendTyping.SeqAppendLen.SeqAppendApp1.SeqAppendApp2.SeqHeadDef.SeqTailTyping.SeqTailLen.SeqTailApp.SeqSubseqTyping.SeqSubseqLen.SeqSubseqApp.SeqSelectseqTyping.SeqSelectseqLen.SeqSelectseqNil.SeqSelectseqApp.SeqSelectseqAppend.DisjointTrigger.EmptyComprehensionTrigger.CompareSetOfTrigger`.split(`.`),El=/* @__PURE__ */ `EnumDef.EnumDefIntro.EnumDefElim.SetOfDef.SetOfIntro.SetOfElim.StrLitIsstr.StrLitDistinct.IntLitIsint.IntLitDistinct.IntLitZeroCmp.TupIsafcn.TupDomDef.TupAppDef.TupExcept.ProductDef.ProductIntro.ProductElim.RecIsafcn.RecDomDef.RecAppDef.RecExcept.RecSetDef.RecSetIntro.RecSetElim.SeqTupTyping.SeqTupLen.CastInj.CastInjAlt.TypeGuard.TypeGuardIntro.TypeGuardElim.Typing.ExtTrigEqDef.ExtTrigEqTrigger.AssertIsSetOf`.split(`.`),Dl=[`TIntPlus`,`TIntUminus`,`TIntMinus`,`TIntTimes`,`TIntQuotient`,`TIntRemainder`,`TIntLteq`],$=(e,t,n,r)=>({name:e,args:t,label:r??[e,...t.flat()].join(` `),formula:n}),Ol=e=>`${e.name} ${JSON.stringify(e.args)}`,kl=e=>{let t=Tl.indexOf(e.name);return t===-1?Tl.length+El.indexOf(e.name):t},Al=(e,t)=>kl(e)-kl(t)||Pc(e.args,t.args),jl={IntPlus:[`+`,2],IntMinus:[`-`,2],IntTimes:[`*`,2],IntUminus:[`-`,1],IntQuotient:[`div`,2],IntRemainder:[`mod`,2],IntLteq:[`<=`,2]},Ml=e=>{let t=jl[e][0],n=t===`div`||t===`mod`,r=jl[e][1]===1?[`x1`]:n?[`x`,`y`]:[`x1`,`x2`],i=Q(W(e),r.map(e=>`(${K} ${e})`)),a=`(= ${i} ${t===`<=`?`(<= ${r.join(` `)})`:`(${K} (${t} ${r.join(` `)}))`})`;return $(`Typing`,[Dl.indexOf(`T${e}`)],Z(r,n?`(=> (> y 0) ${a})`:a,[[i]],`Int`),`Typing T${e}`)},Nl=e=>{let t=W(`SetEnum_${e}`),n=hl(`a`,e),r=Q(t,n),i=$(`EnumDefElim`,[e],Z([...n,`x`],e===0?`(not (${G} x ${r}))`:`(=> (${G} x ${r}) ${vl(n.map(e=>`(= x ${e})`))})`,[[`(${G} x ${r})`]]));return e===0?[i]:[$(`EnumDefIntro`,[e],Z(n,_l(n.map(e=>`(${G} ${e} ${r})`)),[[r]])),i]},Pl=e=>Array.from({length:e},(e,t)=>`(${K} ${t+1})`),Fl=e=>e.map(e=>W(`StrLit_${e}`)),Il=(e,t,n,r)=>{let i=hl(`x`,r.length);return r.map((r,a)=>{let o=`(${al} ${Q(n,i)} ${r} x)`,s=i.map((e,t)=>t===a?`x`:e);return $(`${e}Except`,[...t,a+1],Z([...i,`x`],`(= ${o} ${Q(n,s)})`,[[o]]))})},Ll=e=>Il(`Tup`,[e],W(`Tuple_${e}`),Pl(e)),Rl=e=>Il(`Rec`,[e],W(`Record_${e.join(`_`)}`),Fl(e)),zl=(e,t,n,r)=>{let i=hl(`x`,r.length),a=Q(n,i),o=$(`${e}Isafcn`,t,Z(i,`(${rl} ${a})`,[[a]]));return r.length===0?[o]:[o,$(`${e}DomDef`,t,Z(i,`(= (${nl} ${a}) ${Q(W(`SetEnum_${r.length}`),r)})`,[[a]])),$(`${e}AppDef`,t,Z(i,_l(r.map((e,t)=>`(= (${J} ${a} ${e}) ${i[t]})`)),[[a]]))]},Bl=(e,t)=>{let n=W(`Tuple_${e}`),r=hl(`x`,e),i=Q(n,r);return[...zl(`Tup`,[e],n,Pl(e)),$(`SeqTupTyping`,[e],Z([`a`,...r],e===0?`(${G} ${i} (${Y} a))`:`(=> ${_l(r.map(e=>`(${G} ${e} a)`))} (${G} ${i} (${Y} a)))`,[[...r.map(e=>`(${G} ${e} a)`),i]])),$(`SeqTupLen`,[e],Z(r,`(= (${X} ${i}) (${K} ${e}))`,[[i]])),...t?Ll(e):[]]},Vl=(e,t)=>[...zl(`Rec`,[e],W(`Record_${e.join(`_`)}`),Fl(e)),...t?Rl(e):[]],Hl=(e,t,n,r,i,a)=>{let o=hl(`s`,i.length),s=hl(`x`,i.length),c=Q(n,o),l=Q(r,s),u=i.map(e=>`(${J} ${a} ${e})`);return[$(`${e}Intro`,t,Z([...o,...s],`(=> ${_l(s.map((e,t)=>`(${G} ${e} ${o[t]})`))} (${G} ${l} ${c}))`,[[l,c]])),$(`${e}Elim`,t,Z([...o,a],`(=> (${G} ${a} ${c}) ${_l([`(= ${a} ${Q(r,u)})`,...u.map((e,t)=>`(${G} ${e} ${o[t]})`)])})`,[[`(${G} ${a} ${c})`]]))]},Ul=[`Mem`,`Seq`,`Len`,`FunApp`,`NatSet`,`Cast_Int`,`Proj_Int`],Wl=(t,n)=>{let r=(e,t,n)=>({declaration:e,deps:t,axioms:n}),i=W(t),a=(e,t,n,a=`Idv`)=>r(yl(i,e,a),t,n),o=/^SetEnum_(\d+)$/.exec(t);if(o)return a(Number(o[1]),[`Mem`],Nl(Number(o[1])));let s=/^SetOf_(\d+)$/.exec(t);if(s){let e=Number(s[1]);return r(void 0,[`Mem`,`IsSetOf`],[$(`SetOfIntro`,[e],void 0),$(`SetOfElim`,[e],void 0),$(`AssertIsSetOf`,[e],void 0),$(`CompareSetOfTrigger`,[],Z([`a`,`b`],`(${Vc} a b)`,[[`(${sl} a)`,`(${sl} b)`]]))])}if(t.startsWith(`StrLit_`)){let e=t.slice(7),r=n.strings.map(t=>$(`StrLitDistinct`,[e,t],`(distinct ${i} ${W(`StrLit_${t}`)})`));return n.strings.push(e),a(0,[`Mem`,`StrSet`],[$(`StrLitIsstr`,[e],`(${G} ${i} ${Zc})`),...r])}let c=/^Tuple_(\d+)$/.exec(t);if(c){let e=Number(c[1]);return n.tuples.push(e),a(e,e===0?[`FunIsafcn`,`Cast_Int`,`Seq`,`Len`]:[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${e}`,`Cast_Int`,`Mem`,`Seq`,`Len`],Bl(e,n.isExcept))}let l=/^Product_(\d+)$/.exec(t);if(l){let e=Number(l[1]);return a(e,[`Mem`,`Tuple_${e}`,`FunApp`,`Cast_Int`,`Proj_Int`],Hl(`Product`,[e],i,W(`Tuple_${e}`),Pl(e),`t`))}let u=n.recordFields.get(t);if(u&&t.startsWith(`Record_`))return n.records.push(u),a(u.length,[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${u.length}`,...u.map(e=>`StrLit_${e}`)],Vl(u,n.isExcept));if(u&&t.startsWith(`RecordSet_`)){let e=`Record_${u.join(`_`)}`;return a(u.length,[`Mem`,e,`FunApp`,...u.map(e=>`StrLit_${e}`)],Hl(`RecSet`,[u],i,W(e),Fl(u),`r`))}let d=n.anonymous.get(t);if(d!==void 0)return a(d,[],[]);let f=jl[t];if(f)return a(f[1],[`Cast_Int`],[Ml(t)],t===`IntLteq`?`Bool`:`Idv`);switch(t){case`IntExp`:return a(2,[`Mem`,`IntSet`,`Cast_Int`,`TIntLteq`,`TIntLit_0`,`TIntLit_1`],[$(`IntExpTyping`,[],`(forall ((x Idv) (y Idv)) (! (=> (and (${G} x ${Qc}) (${G} y ${Qc}) (or (distinct x (${K} 0)) (${el} (${K} 1) y))) (${G} (${i} x y) ${Qc})) :pattern ((${i} x y))))`)]);case`SelectSeq`:return r(void 0,[`Mem`,`Seq`,`Len`,`Append`,`FunApp`,`FunDom`,`IntSet`,`NatSet`,`Tuple_0`,`Proj_Int`],[$(`SeqSelectseqTyping`,[],void 0),$(`SeqSelectseqLen`,[],void 0),$(`SeqSelectseqNil`,[],void 0),$(`SeqSelectseqApp`,[],void 0),$(`SeqSelectseqAppend`,[],void 0)]);case`Choose`:return r(void 0,[],[$(`ChooseDef`,[],void 0)]);case`Mem`:return a(2,[`SetExtTrigger`],[$(`SetExt`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (= (${G} z x) (${G} z y))) (= x y)) :pattern ((${Vc} x y))))`)],`Bool`);case`SubsetEq`:return a(2,[`Mem`],[$(`SubsetEqIntro`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${G} z x) (${G} z y))) (${Hc} x y)) :pattern ((${Hc} x y))))`),$(`SubsetEqElim`,[],`(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${Hc} x y) (${G} z x)) (${G} z y)) :pattern ((${Hc} x y) (${G} z x))))`)],`Bool`);case`Union`:return a(1,[`Mem`],[$(`UnionIntro`,[],`(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${G} y a) (${G} x y)) (${G} x (${qc} a))) :pattern ((${G} y a) (${G} x (${qc} a))) :pattern ((${G} x y) (${G} x (${qc} a))) :pattern ((${G} y a) (${G} x y) (${qc} a))))`),$(`UnionElim`,[],`(forall ((a Idv) (x Idv)) (! (=> (${G} x (${qc} a)) (exists ((y Idv)) (and (${G} y a) (${G} x y)))) :pattern ((${G} x (${qc} a)))))`)]);case`Subset`:return a(1,[`Mem`,`SubsetEq`],[$(`SubsetDefAlt`,[],`(forall ((a Idv) (x Idv)) (! (= (${G} x (${Kc} a)) (${Hc} x a)) :pattern ((${G} x (${Kc} a))) :pattern ((${Hc} x a) (${Kc} a))))`)]);case`Cup`:case`Cap`:case`SetMinus`:{let e=t===`Cup`?`(or (MEM x a) (MEM x b))`:t===`Cap`?`(and (MEM x a) (MEM x b))`:`(and (MEM x a) (not (MEM x b)))`,n=$(`${t}Def`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${G} x (${i} a b)) ${e.replaceAll(`MEM`,G)}) :pattern ((${G} x (${i} a b))) :pattern ((${G} x a) (${i} a b)) :pattern ((${G} x b) (${i} a b))))`);return t===`Cap`?a(2,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[n,$(`DisjointTrigger`,[],`(forall ((x Idv) (y Idv)) (! (${Vc} (${Wc} x y) ${W(`SetEnum_0`)}) :pattern ((${Wc} x y))))`)]):a(2,[`Mem`],[n])}case`SetSt`:return r(void 0,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[$(`SetStDef`,[],void 0),$(`EmptyComprehensionTrigger`,[],void 0)]);case`NatSet`:return a(0,[`IntSet`,`TIntLit_0`,`Cast_Int`,`IntLteq`],[$(`NatSetDef`,[],`(forall ((x Idv)) (! (= (${G} x ${$c}) (and (${G} x ${Qc}) (${el} (${K} 0) x))) :pattern ((${G} x ${$c}))))`)]);case`IntRange`:return a(2,[`Mem`,`IntSet`,`IntLteq`],[$(`IntRangeDef`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${G} x (${tl} a b)) (and (${G} x ${Qc}) (${el} a x) (${el} x b))) :pattern ((${G} x (${tl} a b)))))`)]);case`FunIsafcn`:return a(1,[`Mem`,`FunDom`,`FunFcn`,`FunApp`],[$(`FunExt`,[],`(forall ((f Idv) (g Idv)) (! (=> (and (${rl} f) (${rl} g) (= (${nl} f) (${nl} g)) (forall ((x Idv)) (=> (${G} x (${nl} f)) (= (${J} f x) (${J} g x))))) (= f g)) :pattern ((${rl} f) (${rl} g))))`)],`Bool`);case`FunSet`:return n.isFunSet=!0,a(2,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunSetIntro`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (and (${rl} f) (= (${nl} f) a) (forall ((x Idv)) (=> (${G} x a) (${G} (${J} f x) b)))) (${G} f (${il} a b))) :pattern ((${G} f (${il} a b)))))`),$(`FunSetElim1`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (${G} f (${il} a b)) (and (${rl} f) (= (${nl} f) a))) :pattern ((${G} f (${il} a b)))))`),$(`FunSetElim2`,[],`(forall ((a Idv) (b Idv) (f Idv) (x Idv)) (! (=> (and (${G} f (${il} a b)) (${G} x a)) (${G} (${J} f x) b)) :pattern ((${G} f (${il} a b)) (${G} x a)) :pattern ((${G} f (${il} a b)) (${J} f x))))`),...n.isFunConstr?[$(`FunTyping`,[],void 0)]:[]]);case`FunFcn`:return n.isFunConstr=!0,r(void 0,[`FunIsafcn`],[$(`FunConstrIsafcn`,[],void 0),...n.isFunSet?[$(`FunTyping`,[],void 0)]:[]]);case`FunDom`:return a(1,[`FunFcn`],[$(`FunDomDef`,[],void 0)]);case`FunApp`:return a(2,[`Mem`,`FunFcn`],[$(`FunAppDef`,[],void 0)]);case`FunExcept`:{n.isExcept=!0;let e=`(${al} f x y)`;return a(3,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunExceptIsafcn`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (${rl} ${e}) :pattern (${e})))`),$(`FunExceptDomDef`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (= (${nl} ${e}) (${nl} f)) :pattern (${e})))`),$(`FunExceptAppDef1`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (=> (${G} x (${nl} f)) (= (${J} ${e} x) y)) :pattern (${e})))`),$(`FunExceptAppDef2`,[],`(forall ((f Idv) (x Idv) (y Idv) (z Idv)) (! (=> (${G} z (${nl} f)) (and (=> (= z x) (= (${J} ${e} z) y)) (=> (distinct z x) (= (${J} ${e} z) (${J} f z))))) :pattern ((${J} ${e} z)) :pattern (${e} (${J} f z))))`),...n.tuples.flatMap(Ll),...n.records.flatMap(Rl)])}case`Seq`:return a(1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`Cast_Int`,`Proj_Int`],[$(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${rl} s) (>= (${q} (${X} s)) 0) (forall ((i Idv)) (= (${G} i (${nl} s)) (and (${G} i ${Qc}) (<= 1 (${q} i)) (<= (${q} i) (${q} (${X} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${q} (${X} s)))) (${G} (${J} s (${K} i)) a)))) (${G} s (${Y} a))) :pattern ((${G} s (${Y} a)))))`),$(`SeqSetElim1`,[],`(forall ((a Idv) (s Idv)) (! (=> (${G} s (${Y} a)) (and (${rl} s) (${G} (${X} s) ${$c}) (= (${nl} s) (${tl} (${K} 1) (${X} s))))) :pattern ((${G} s (${Y} a)))))`,`SetSetElim1`),$(`SeqSetElim2`,[],`(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${G} s (${Y} a)) (<= 1 i) (<= i (${q} (${X} s)))) (${G} (${J} s (${K} i)) a)) :pattern ((${G} s (${Y} a)) (${J} s (${K} i)))))`,`SetSetElim2`)]);case`Len`:return a(1,[`FunDom`,`IntRange`,`Cast_Int`],[$(`SeqLenDef`,[],`(forall ((s Idv) (z Int)) (=> (and (>= z 0) (= (${nl} s) (${tl} (${K} 1) (${K} z)))) (= (${X} s) (${K} z))))`)]);case`BSeq`:return a(1,[],[]);case`Cat`:return a(2,Ul,[$(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${G} s (${Y} a)) (${G} t (${Y} a))) (${G} (${cl} s t) (${Y} a))) :pattern ((${G} s (${Y} a)) (${cl} s t)) :pattern ((${G} t (${Y} a)) (${cl} s t))))`),$(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${G} (${X} s) ${$c}) (${G} (${X} t) ${$c})) (= (${X} (${cl} s t)) (${K} (+ (${q} (${X} s)) (${q} (${X} t)))))) :pattern ((${cl} s t))))`),$(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${G} (${X} s) ${$c}) (${G} (${X} t) ${$c}) (<= 1 i) (<= i (${q} (${X} s)))) (= (${J} (${cl} s t) (${K} i)) (${J} s (${K} i)))) :pattern ((${J} (${cl} s t) (${K} i))) :pattern ((${cl} s t) (${J} s (${K} i)))))`),$(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${G} (${X} s) ${$c}) (${G} (${X} t) ${$c}) (<= i (+ (${q} (${X} s)) (${q} (${X} t)))) (< (${q} (${X} s)) i)) (= (${J} (${cl} s t) (${K} i)) (${J} t (${K} (- i (${q} (${X} s))))))) :pattern ((${J} (${cl} s t) (${K} i)))))`)]);case`Append`:return a(2,Ul,[$(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${G} s (${Y} a)) (${G} x a)) (${G} (${ll} s x) (${Y} a))) :pattern ((${G} s (${Y} a)) (${ll} s x))))`),$(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${G} (${X} s) ${$c}) (= (${X} (${ll} s x)) (${K} (+ (${q} (${X} s)) 1)))) :pattern ((${ll} s x))))`),$(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${G} (${X} s) ${$c}) (<= 1 i) (<= i (${q} (${X} s)))) (= (${J} (${ll} s x) (${K} i)) (${J} s (${K} i)))) :pattern ((${J} (${ll} s x) (${K} i))) :pattern ((${ll} s x) (${J} s (${K} i)))))`),$(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${G} (${X} s) ${$c}) (= (${J} (${ll} s x) (${K} (+ (${q} (${X} s)) 1))) x)) :pattern ((${ll} s x))))`)]);case`Head`:return a(1,[`FunApp`,`Cast_Int`],[$(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${ul} s) (${J} s (${K} 1))) :pattern ((${ul} s))))`)]);case`Tail`:return a(1,Ul,[$(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${G} s (${Y} a)) (distinct (${q} (${X} s)) 0)) (${G} (${dl} s) (${Y} a))) :pattern ((${G} s (${Y} a)) (${dl} s))))`),$(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${G} (${X} s) ${$c}) (distinct (${q} (${X} s)) 0)) (= (${X} (${dl} s)) (${K} (- (${q} (${X} s)) 1)))) :pattern ((${dl} s))))`),$(`SeqTailApp`,[],`(forall ((s Idv) (i Int)) (! (=> (and (${G} (${X} s) ${$c}) (distinct (${q} (${X} s)) 0) (<= 1 i) (<= i (- (${q} (${X} s)) 1))) (= (${J} (${dl} s) (${K} i)) (${J} s (${K} (+ i 1))))) :pattern ((${J} (${dl} s) (${K} i)))))`)]);case`SubSeq`:{let e=`(${fl} s (${K} x) (${K} y))`;return a(3,[`Mem`,`Seq`,`Len`,`FunApp`,`IntSet`,`Cast_Int`,`Proj_Int`],[$(`SeqSubseqTyping`,[],`(forall ((a Idv) (s Idv) (x Int) (y Int)) (! (=> (or (< y x) (and (${G} s (${Y} a)) (<= 1 x) (<= y (${q} (${X} s))))) (${G} ${e} (${Y} a))) :pattern ((${G} s (${Y} a)) ${e})))`),$(`SeqSubseqLen`,[],`(forall ((s Idv) (x Int) (y Int)) (! (and (=> (<= x (+ y 1)) (= (${X} ${e}) (${K} (- (+ y 1) x)))) (=> (> x (+ y 1)) (= (${X} ${e}) (${K} 0)))) :pattern (${e})))`),$(`SeqSubseqApp`,[],`(forall ((s Idv) (x Int) (y Int) (z Int)) (! (=> (and (<= 1 x) (<= 1 z) (<= z (- (+ y 1) x))) (= (${J} ${e} (${K} z)) (${J} s (${K} (- (+ z x) 1))))) :pattern ((${J} ${e} (${K} z)))))`)])}case`Cast_Int`:return r(yl(i,1,`Idv`,`Int`),[`Mem`,`IntSet`,`Proj_Int`],[$(`CastInjAlt`,[`Int`],`(forall ((x Int)) (! (= x (${q} (${K} x))) :pattern ((${K} x))))`),$(`TypeGuardIntro`,[`Int`],`(forall ((z Int)) (! (${G} (${K} z) ${Qc}) :pattern ((${K} z))))`),$(`TypeGuardElim`,[`Int`],`(forall ((x Idv)) (! (=> (${G} x ${Qc}) (= x (${K} (${q} x)))) :pattern ((${G} x ${Qc}))))`)]);case`Cast_Bool`:return r(yl(i,1,`Idv`,`Bool`),[`Mem`,`BoolSet`,`Tt_Idv`],[$(`CastInjAlt`,[`Bool`],`(and (= (${Yc} true) ${Jc}) (distinct (${Yc} false) ${Jc}))`),$(`TypeGuardIntro`,[`Bool`],`(forall ((z Bool)) (! (${G} (${Yc} z) ${Xc}) :pattern ((${Yc} z))))`),$(`TypeGuardElim`,[`Bool`],`(forall ((x Idv)) (! (=> (${G} x ${Xc}) (or (= x (${Yc} true)) (= x (${Yc} false)))) :pattern ((${G} x ${Xc}))))`)]);case`Proj_Int`:return r(yl(i,1,`Int`),[],[]);case`TrigEq_Set$Idv$`:return a(2,[`SetExtTrigger`],[$(`ExtTrigEqDef`,[`Set$Idv$`],`(forall ((x Idv) (y Idv)) (! (= (${ol} x y) (= x y)) :pattern ((${ol} x y))))`),$(`ExtTrigEqTrigger`,[`Idv`],`(forall ((x Idv) (y Idv)) (! (${Vc} x y) :pattern ((${ol} x y))))`)],`Bool`);case`SetExtTrigger`:case`IsSetOf`:return a(t===`IsSetOf`?1:2,[],[],`Bool`);case`BoolSet`:case`StrSet`:case`IntSet`:case`Tt_Idv`:return a(0,[],[]);case`TIntLteq`:return r(void 0,[`IntLteq`],[Ml(`IntLteq`)]);default:if(t.startsWith(`TIntLit_`))return r(void 0,[],[]);throw new e.A(`the symbol ${t}`)}},Gl=(e,t)=>`${e}#${t}`,Kl=e=>Number(e.slice(e.lastIndexOf(`#`)+1)),ql=`?unprimable`,Jl=e=>{let t=e.indexOf(`(${ql} `);if(t===-1)return e;let n=bl(e,t);return e.slice(0,t)+Jl(e.slice(t+11+2,n))+Jl(e.slice(n+1))},Yl=(e,t)=>/\((forall|exists|ite) /.test(e)?void 0:e.replace(/[^\s()]+#(\d+)/g,(e,n)=>Number(n)<t?`#`:`#${Number(n)-t}`),Xl=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n={blueprints:0},r=[];return{flattened:e,flatten:(i,a,o,s,c,l=`TLA__${i}`)=>{if(o.isOmitted){let t=Ic(`${l}_omitted_${e.size}`);return e.set(t,{symbol:t,kind:i,visit:Jl(a),getLines:()=>[]}),t}let u=Yl(`${l} ${a}`,o.depth);n.blueprints++;let d=u===void 0?void 0:t.get(u);if(d)return d.symbol;let f=`${l}_flatnd_${n.blueprints}`,p=Ic(f),m={symbol:p,kind:i,visit:Jl(a),getLines:e=>[yl(p,c),...s(p,e).map(e=>`(assert (! ${Jl(e.formula??``)} :named |${e.label} ${f}|))`)]};return u!==void 0&&t.set(u,m),e.set(p,m),r.push(m),p},takeIntroduced:()=>r.splice(0)}},Zl=`?trigger`,Ql=/* @__PURE__ */ new Set([qc,Kc,Uc,Wc,Gc,tl,il,Y]),$l=e=>{let t=/^\(?([^\s()]+)/.exec(e)?.[1]??``;return Ql.has(t)||/^smt__TLA____(SetEnum__\d+|SetSt__flatnd__\d+|SetOf__\d+__flatnd__\d+|Product__\d+|RecordSet__)/.test(t)},eu=(e,t)=>{let n=e.indexOf(`(${Zl} `);if(n===-1)return e;let r=n+8+2,i=bl(e,r)+1,a=bl(e,i+1)+1,o=t?e.slice(r,i):e.slice(i+1,a);return e.slice(0,n)+o+eu(e.slice(a+1),t)},tu=(e,t,n,r)=>{let i=`(${ol} ${e} ${t})`,a=r?`(distinct ${e} ${t})`:`(= ${e} ${t})`;if(!$l(e)&&!$l(t))return a;let o=r?`(not ${i})`:i;return n===(r?`Positive`:`Negative`)?`(${Zl} ${o} ${a})`:o},nu=(e,t,n,r)=>{let i=Q(e,[`a`,...t]);return[$(`SetStDef`,[],Z([...t,`a`,`x`],`(= (${G} x ${i}) (and (${G} x a) ${xl(n,r,`x`)}))`,[[`(${G} x ${i})`],[`(${G} x a)`,i]]))]},ru=(e,t,n,r)=>{let i=r.length,a=hl(`a`,i),o=hl(`y`,i),s=r.reduce((e,t,n)=>xl(e,t,o[n]),n),c=Q(e,[...a,...t]),l=o.map((e,t)=>`(${G} ${e} ${a[t]})`),u=i===1?[`a`]:a,d=Q(e,[...u,...t]);return[$(`SetOfIntro`,[i],Z([...t,...a,...o],`(=> ${_l(l)} (${G} ${s} ${c}))`,[[s,c],[c,...l]])),$(`SetOfElim`,[i],Z([...t,...a,`x`],`(=> (${G} x ${c}) (exists (${gl(o)}) ${_l([...l,`(= x ${s})`])}))`,[[`(${G} x ${c})`]])),$(`AssertIsSetOf`,[i],Z([...t,...u],`(${sl} ${d})`,[[d]]))]},iu=(e,t,n,r,i)=>{let a=Q(e,[`a`,...t]),o=xl(n,r,`x`),s=i.has(Ol($(`FunTyping`,[],void 0)))?[$(`FunTyping`,[],Z([...t,`a`,`b`],`(=> (forall ((x Idv)) (=> (${G} x a) (${G} ${o} b))) (${G} ${a} (${il} a b)))`,[[a,`(${il} a b)`]]))]:[];return[$(`FunConstrIsafcn`,[],Z([...t,`a`],`(${rl} ${a})`,[[a]])),$(`FunDomDef`,[],Z([...t,`a`],`(= (${nl} ${a}) a)`,[[a]])),$(`FunAppDef`,[],Z([...t,`a`,`x`],`(=> (${G} x a) (= (${J} ${a} x) ${o}))`,[[`(${J} ${a} x)`],[`(${G} x a)`,a]])),...s]},au=(e,t,n,r)=>[$(`ChooseDef`,[],Z([...t,`x`],`(=> ${xl(n,r,`x`)} ${xl(n,r,Q(e,t))})`))],ou=(e,t,n,r)=>{let i=n=>Q(e,[n,...t]),a=e=>xl(n,r,e),o=i(`(${ll} s x)`);return[$(`SeqSelectseqTyping`,[],Z([...t,`a`,`s`],`(=> (${G} s (${Y} a)) (${G} ${i(`s`)} (${Y} a)))`,[[`(${G} s (${Y} a))`,i(`s`)]])),$(`SeqSelectseqLen`,[],Z([...t,`s`],`(=> (${G} (${X} s) ${$c}) (<= (${q} (${X} ${i(`s`)})) (${q} (${X} s))))`,[[i(`s`)]])),$(`SeqSelectseqNil`,[],Z(t,`(= ${i(pl)} ${pl})`)),$(`SeqSelectseqApp`,[],Z([...t,`s`,`x`],`(=> (${G} x (${nl} ${i(`s`)})) ${a(`(${J} ${i(`s`)} x)`)})`,[[`(${J} ${i(`s`)} x)`]])),$(`SeqSelectseqAppend`,[],Z([...t,`s`,`x`],`(and (=> ${a(`x`)} (= ${o} (${ll} ${i(`s`)} x))) (=> (not ${a(`x`)}) (= ${o} ${i(`s`)})))`,[[o]]))]},su=t=>{let n=Xl(),r=n.flatten,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=Cl(),s=/* @__PURE__ */ new Map,c=e=>e.isBool?e.text:`(= ${eu(e.text,!0)} ${Jc})`,l=e=>e.isBool?`(${Yc} ${eu(e.text,!0)})`:e.text,u=e=>({isBool:!0,text:e}),d=e=>({isBool:!1,text:e}),f=(t,n)=>{let r=Array.from({length:n-1}).reduce(e=>e?.rest,t);if(!r)throw new e.A(`a reference outside the obligation`);return r.binding},p=(e,t)=>({binding:t,rest:e}),m=(e,t)=>[...new Set(e.match(/[^\s()]+#\d+/g))].filter(e=>Kl(e)<t).toSorted((e,t)=>Kl(e)-Kl(t)),h=e=>{let t=o.adjoin(e);return o.enter(t),s.set(t.name,t),t.name},g=e=>({...e,polarity:`Neither`}),_=e=>({...e,polarity:e.polarity===`Positive`?`Negative`:e.polarity===`Negative`?`Positive`:`Neither`}),v=(e,t,n)=>l(pe(e,t,g(n))),y=(e,t,n)=>c(pe(e,t,n)),b=(e,t,n)=>e.reduce((e,t)=>t.domain.kind===`Ditto`?[...e,e.at(-1)]:t.domain.kind===`NoDomain`?[...e,void 0]:[...e,t.domain.expression],[]).map(e=>e===void 0?void 0:v(e,t,n)),ee=(t,n,r,i)=>b(t,n,r).map(t=>{if(t===void 0)throw new e.A(`${i} without a domain`);return t}),x=(e,t,n)=>{let r=e.map((e,t)=>Gl(e,n.depth+t));return{variables:r,env:r.reduce((e,t)=>p(e,{kind:`constant`,symbol:t}),t),mode:{...n,depth:n.depth+e.length}}},te=(e,t,n)=>{let r=b(e.bounds,t,n),i=x(e.bounds.map(e=>e.name),t,n),a=y(e.body,i.env,i.mode),o=i.variables.flatMap((e,t)=>r[t]===void 0?[]:[`(${G} ${e} ${r[t]})`]);return e.quantifier===`Forall`?`(forall (${gl(i.variables)}) ${o.length===0?a:`(=> ${_l(o)} ${a})`})`:`(exists (${gl(i.variables)}) ${_l([...o,a])})`},ne=(e,t,n)=>{let i=v(e.domain,t,n),a=x([e.name],t,g(n)),o=y(e.body,a.env,a.mode),s=m(o,n.depth),c=r(`SetSt`,o,n,e=>nu(e,s,o,a.variables[0]),s.length+1);return d(Q(c,[i,...s]))},S=(e,t,n)=>{let i=ee(e.bounds,t,n,`a set of values`),a=x(e.bounds.map(e=>e.name),t,g(n)),o=v(e.element,a.env,a.mode),s=m(o,n.depth),c=i.length,l=r(`SetOf_${c}`,o,n,e=>ru(e,s,o,a.variables),c+s.length);return d(Q(l,[...i,...s]))},re=(e,t,n)=>{let i=ee(e.bounds,t,n,`a function`),a=i.length===1?i[0]:Q(W(`Product_${i.length}`),i),o=Gl(i.length===1?e.bounds[0].name:`x`,n.depth),s={...g(n),depth:n.depth+1},c=i.length===1?p(t,{kind:`constant`,symbol:o}):Pl(i.length).reduce((e,t)=>p(e,{kind:`constant`,symbol:`(${J} ${o} ${t})`}),t),l=v(e.body,c,s),u=m(l,n.depth),f=r(`FunFcn`,l,n,(e,t)=>iu(e,u,l,o,t),u.length+1);return d(Q(f,[a,...u]))},ie=(e,t,n)=>{let i=x([e.name],t,g(n)),a=i.variables[0],o=e.domain&&`(${G} ${a} ${v(e.domain,t,n)})`,s=y(e.body,i.env,i.mode),c=o===void 0?s:_l([o,s]),l=m(c,n.depth),u=r(`Choose`,c,n,e=>au(e,l,c,a),l.length);return d(Q(u,l))},ae=(e,t,n,r)=>tu(v(e[0],t,n),v(e[1],t,n),n.polarity,r),C=(e,t,n)=>{let r=e.kind===`Lambda`&&e.params.length===1?e:void 0,i=x([r?.params[0].name??`x1`],t,g(n));return{body:y(r?.body??{kind:`Apply`,operator:L(1,e),args:[{kind:`Ix`,index:1}]},i.env,i.mode),variable:i.variables[0]}},oe=(t,n,i,a)=>{let o=()=>n.map(e=>v(e,i,a));switch(t){case`Conj`:return u(_l(n.map(e=>y(e,i,a))));case`Disj`:return u(vl(n.map(e=>y(e,i,a))));case`Implies`:return u(`(=> ${y(n[0],i,_(a))} ${y(n[1],i,a)})`);case`Equiv`:return u(`(= ${n.map(e=>y(e,i,g(a))).join(` `)})`);case`Neg`:return u(`(not ${y(n[0],i,_(a))})`);case`Eq`:return u(ae(n,i,a,!1));case`Neq`:return u(ae(n,i,a,!0));case`Mem`:return u(Q(G,o()));case`Notmem`:return u(`(not ${Q(G,o())})`);case`Subseteq`:return u(Q(Hc,o()));case`Lteq`:return u(Q(el,o()));case`Gteq`:return u(Q(el,o().toReversed()));case`Lt`:case`Gt`:{let e=()=>t===`Lt`?o():o().toReversed();return u(`(and ${Q(el,e())} (distinct ${e().join(` `)}))`)}case`SelectSeq`:{let e=C(n[1],i,a),t=m(e.body,a.depth),o=r(`SelectSeq`,e.body,a,n=>ou(n,t,e.body,e.variable),t.length+1);return d(Q(o,[v(n[0],i,a),...t]))}case`Unprimable`:{let e=pe(n[0],i,g(a));return{...e,text:`(${ql} ${e.text})`}}default:{let n=ml[t];if(n===void 0)throw new e.A(`the operator ${t}`);return d(Q(n,o()))}}},se=(t,n,i,a)=>{switch(t.kind){case`constant`:case`variable`:if(n.length>0)throw new e.A(`an applied ${t.kind}`);return d(t.symbol);case`operator`:if(n.length!==t.arity)throw new e.A(`an operator applied to the wrong number of arguments`);return d(Q(t.symbol,n.map(e=>v(e,i,a))));case`secondOrder`:{if(n.length!==t.shapes.length)throw new e.A(`an operator applied to the wrong number of arguments`);let o=n.map((n,r)=>{if(t.shapes[r]===0)return{isFirstOrder:!0,text:v(n,i,a)};if(n.kind===`Ix`){let t=f(i,n.index);if(t.kind!==`operator`)throw new e.A(`an operator argument that isn't a LAMBDA`);return{isFirstOrder:!1,text:t.symbol}}if(n.kind!==`Lambda`)throw new e.A(`an operator argument that isn't a LAMBDA`);let o=x(n.params.map(e=>e.name),i,g(a));return{isFirstOrder:!1,text:v(n.body,o.env,o.mode)}}),s=o.flatMap(e=>e.isFirstOrder?[e.text]:[]),c=o.flatMap(e=>e.isFirstOrder?[]:[e.text]),l=m(c.join(` `),a.depth),u=r(``,c.join(` `),a,()=>[],s.length+l.length,t.name);return d(Q(u,[...s,...l]))}case`unsupported`:throw new e.A(t.reason)}},ce=(t,n)=>{if(!t)throw new e.A(`a primed declaration that isn't a variable`);let r=t.binding;return r.kind===`variable`&&r.name===n?r.primed:ce(t.rest,n)},le=(e,t,n,r)=>{if(t.length===0&&e.endsWith(`#prime`))return d(ce(n,e.slice(0,-6)));let a=t.length===0?`Anon_OPAQUE_${e}`:`Anon_${e}`;return i.set(a,t.length),d(Q(W(a),t.map(e=>v(e,n,r))))},w=(e,t,n)=>e.specs.reduce((e,r)=>{let i=(e,a)=>{if(a.length===0)return v(r.value,t,{...n,at:e});let o=a[0],s=()=>o.kind===`Dot`?W(`StrLit_${o.field}`):v(o.expression,t,n),c=s(),l=i(`(${J} ${e} ${a.length>1?s():c})`,a.slice(1));return`(${al} ${e} ${c} ${l})`};return i(e,r.trail)},v(e.function,t,n)),ue=()=>{t.caseErrors++;let e=`Anon_incomplete_case_error_${t.caseErrors}`;return i.set(e,0),W(e)},de=(e,t,n)=>{let r=e.arms.map(e=>pe(e.body,t,n)),i=e.other?pe(e.other,t,n):d(ue()),a=i.isBool&&r.every(e=>e.isBool);if(i.integer!==void 0&&r.every(e=>e.integer!==void 0)){let a=e.arms.reduceRight((e,i,a)=>`(ite ${y(i.condition,t,g(n))} ${r[a].integer} ${e})`,i.integer??``);return{isBool:!1,text:`(${K} ${a})`,integer:a}}let o=e=>a?e.text:l(e);return{isBool:a,text:e.arms.reduceRight((e,i,a)=>`(ite ${y(i.condition,t,n)} ${o(r[a])} ${e})`,o(i))}},fe=(t,n,r)=>{let i=t.context.reduce((t,n)=>{switch(n.kind){case`Fresh`:{if(n.shape>0){if(!t.mode.isOmitted)throw new e.A(`a second-order ASSUME`);let r=Gl(n.name,t.mode.depth);return{env:p(t.env,{kind:`operator`,symbol:r,arity:n.shape}),mode:{...t.mode,depth:t.mode.depth+1},wrappers:[...t.wrappers,e=>`(forall ((${r} Idv)) ${e})`]}}if(n.level!==`Constant`)throw new e.A(`a NEW declaration that isn't constant`);let r=n.domain&&v(n.domain,t.env,t.mode),i=x([n.name],t.env,t.mode),a=i.variables[0],o=r&&`(${G} ${a} ${r})`;return{env:i.env,mode:i.mode,wrappers:[...t.wrappers,e=>`(forall ((${a} Idv)) ${o?`(=> ${o} ${e})`:e})`]}}case`Fact`:{let e=n.visibility===`Visible`?y(n.expression,t.env,_(t.mode)):void 0;return{env:p(t.env,{kind:`unsupported`,reason:`a reference to a fact`}),mode:t.mode,wrappers:e?[...t.wrappers,t=>`(=> ${e} ${t})`]:t.wrappers}}default:throw new e.A(`a ${n.kind} in a nested ASSUME`)}},{env:n,mode:r,wrappers:[]});return i.wrappers.reduceRight((e,t)=>t(e),y(t.active,i.env,i.mode))},pe=(t,n,r)=>{switch(t.kind){case`Ix`:return se(f(n,t.index),[],n,r);case`Internal`:switch(t.builtin){case`TRUE`:return u(`true`);case`FALSE`:return u(`false`);case`BOOLEAN`:return d(Xc);case`STRING`:return d(Zc);case`Nat`:return d($c);case`Int`:return d(Qc);default:throw new e.A(`the operator ${t.builtin}`)}case`Apply`:{let i=t.operator;if(i.kind===`Internal`)return oe(i.builtin,t.args,n,r);if(i.kind===`Ix`)return se(f(n,i.index),t.args,n,r);if(i.kind===`Opaque`)return le(i.name,t.args,n,r);if(i.kind===`Lambda`)return pe(Et(i,t.args),n,r);throw new e.A(`an application of ${i.kind}`)}case`Sequent`:return u(fe(t.sequent,n,r));case`With`:case`Parens`:return pe(t.expression,n,r);case`If`:{let e=y(t.condition,n,r),i=pe(t.consequent,n,r),a=pe(t.alternative,n,r);if(i.integer!==void 0&&a.integer!==void 0){let t=`(ite ${eu(e,!0)} ${i.integer} ${a.integer})`;return{isBool:!1,text:`(${K} ${t})`,integer:t}}return i.isBool&&a.isBool?u(`(ite ${e} ${i.text} ${a.text})`):d(`(ite ${e} ${l(i)} ${l(a)})`)}case`List`:{let e=t.items.map(e=>y(e,n,r));return u(t.bullet===`Or`?vl(e):_l(e))}case`Opaque`:return le(t.name,[],n,r);case`Quant`:return u(te(t,n,r));case`Choose`:return ie(t,n,r);case`SetSt`:return ne(t,n,r);case`SetOf`:return S(t,n,r);case`SetEnum`:return d(Q(W(`SetEnum_${t.elements.length}`),t.elements.map(e=>v(e,n,r))));case`Product`:return d(Q(W(`Product_${t.factors.length}`),t.factors.map(e=>v(e,n,r))));case`Tuple`:return d(Q(W(`Tuple_${t.elements.length}`),t.elements.map(e=>v(e,n,r))));case`Fcn`:return re(t,n,r);case`FcnApp`:{let e=v(t.function,n,r),i=t.args.map(e=>v(e,n,r)),a=i.length===1?i[0]:Q(W(`Tuple_${i.length}`),i);return d(`(${J} ${e} ${a})`)}case`Arrow`:return d(Q(il,[v(t.domain,n,r),v(t.range,n,r)]));case`Record`:case`Rect`:{let e=t.fields.map(e=>e.name),i=e.join(`_`);return a.set(`Record_${i}`,e),a.set(`RecordSet_${i}`,e),d(Q(W(`${t.kind===`Record`?`Record`:`RecordSet`}_${i}`),t.fields.map(e=>v(e.value,n,r))))}case`Except`:return d(w(t,n,r));case`Dot`:return d(`(${J} ${v(t.expression,n,r)} ${W(`StrLit_${t.field}`)})`);case`Case`:return de(t,n,r);case`String`:return d(W(`StrLit_${t.value}`));case`Num`:if(t.fraction!==``)throw new e.A(`a real number`);return{isBool:!1,text:`(${K} ${BigInt(t.integer)})`,integer:String(BigInt(t.integer))};case`At`:if(r.at===void 0)throw new e.A(`@ outside EXCEPT`);return d(r.at);case`Tquant`:case`Tsub`:case`Fair`:throw new e.A(`a temporal formula`);default:throw new e.A(`the expression ${t.kind}`)}};return{encodeIdv:v,encodeBool:y,push:p,getEntries:e=>[...n.takeIntroduced(),Jl(eu(e,!1))],getUniqueName:h,flattened:n.flattened,anonymous:i,recordFields:a,declared:s}},cu=(e,t)=>e.fields.length===t.fields.length&&e.fields.every(e=>t.fields.some(t=>t.name===e.name))&&t.fields.every(t=>e.fields.some(e=>e.name===t.name)),lu=e=>e.length===1?e[0]:k(`Conj`,[e[0],lu(e.slice(1))],e[0]),uu=(e,t,n)=>e.kind!==`Record`||t.kind!==`Record`||!cu(e,t)?k(`Eq`,[e,t],n):lu(e.fields.map(e=>uu(e.value,t.fields.find(t=>t.name===e.name)?.value??e.value,n))),du=e=>{let t=bt(e,du);return t.kind!==`Apply`||t.operator.kind!==`Internal`||t.operator.builtin!==`Eq`||t.args.length!==2||t.args[0].kind!==`Record`||t.args[1].kind!==`Record`?t:O(uu(t.args[0],t.args[1],t),t)},fu=e=>e.kind===`Record`||e.kind===`Rect`?{...e,fields:e.fields.toSorted((e,t)=>Nc(e.name,t.name))}:bt(e,fu),pu=(e,t)=>{let n={recordFields:t.recordFields,strings:[],isFunConstr:!1,isFunSet:!1,isExcept:!1,tuples:[],records:[],anonymous:t.anonymous},r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=e=>{let t=/* @__PURE__ */ new Set([e]);for(;t.size>0;){let e=[...t].toSorted(Nc)[0];if(t.delete(e),r.has(e))continue;let a=Wl(e,n);r.set(e,a),a.deps.forEach(e=>t.add(e)),a.axioms.forEach(e=>i.set(Ol(e),e))}},o=e=>{let n=e.match(/[()]|[^\s()]+/g)??[],r=[];n.reduce((e,i,s)=>{if(i===`(`)return e+1;if(i===`)`)return r.at(-1)?.depth===e&&o(r.pop()?.text??``),e-1;let c=t.flattened.get(i);if(!c){let t=Bc(i);return t!==void 0&&a(t),e}return c.kind!==``&&a(c.kind),n[s-1]===`(`?r.push({depth:e,text:c.visit}):o(c.visit),e},0)};return e.forEach(e=>{typeof e==`string`?o(e):`omitted`in e&&o(e.omitted)}),{symbols:r,axioms:i}},mu={isOmitted:!1,polarity:`Negative`,at:void 0,depth:0},hu=e=>e.definition.kind===`Bpragma`||e.definition.kind===`Operator`&&e.visibility===`Visible`,gu=e=>e.kind===`Sequent`&&e.sequent.context.some(e=>e.kind===`Fresh`&&e.shape>0),_u=(e,t)=>e.reduce((e,n)=>{let r=(n,r=[])=>({env:t.push(e.env,n),entries:[...e.entries,...r]});switch(n.kind){case`Fresh`:{let i=t.getUniqueName(n.name),a=n.shape===0?{kind:`constant`,symbol:i}:{kind:`operator`,symbol:i,arity:n.shape},o=yl(i,n.shape);if(!n.domain||n.domainVisibility===`Hidden`)return r(a,[o]);let s=`(assert (${G} ${i} ${t.encodeIdv(n.domain,e.env,mu)}))`;return r(a,[o,...t.getEntries(s)])}case`Flex`:{let e=t.getUniqueName(n.name),i=t.getUniqueName(`${n.name}_prime`);return r({kind:`variable`,name:n.name,symbol:e,primed:i},[yl(e,0),yl(i,0)])}case`Defn`:{let e=n.definition;if(hu(n))return r({kind:`unsupported`,reason:`an expanded definition`});if(e.kind===`Instance`)return r({kind:`unsupported`,reason:`an instance`});if(e.kind===`Recursive`){let n=t.getUniqueName(`CONSTANT_${e.name}_`);return r({kind:`operator`,symbol:n,arity:e.shape},[yl(n,e.shape)])}if(e.kind!==`Operator`)return r({kind:`unsupported`,reason:`a definition`});let i=e.body,a=i.kind===`Lambda`?i.params:[];if(a.some(e=>e.shape>0))return r({kind:`secondOrder`,name:e.name,shapes:a.map(e=>e.shape)});let o=t.getUniqueName(e.name);return r({kind:`operator`,symbol:o,arity:a.length},[yl(o,a.length)])}case`Fact`:{let i={kind:`unsupported`,reason:`a reference to a fact`};if(n.visibility===`Hidden`)return r(i);let a=gu(n.expression),o=t.getEntries(`(assert ${t.encodeBool(n.expression,e.env,{...mu,isOmitted:a})})`);return r(i,a?o.map(e=>typeof e==`string`?{omitted:e}:e):o)}}},{env:void 0,entries:[]}),vu=(e,t)=>{let n=fu(du({kind:`Sequent`,sequent:e})),r=n.kind===`Sequent`?n.sequent:e,i=su(t),a=_u(r.context,i),o=gu(r.active)?[]:i.getEntries(`(assert (! (not ${i.encodeBool(r.active,a.env,{...mu,polarity:`Positive`})}) :named |Goal|))`),s=[...a.entries,...o],c=wl(i.declared),l=pu(s,i),u=[...l.symbols].toSorted((e,t)=>Nc(e[0],t[0])).flatMap(e=>e[1].declaration===void 0?[]:[e[1].declaration]),d=[...l.axioms.values()].toSorted(Al).flatMap(e=>e.formula===void 0?[]:[`(assert (! ${e.formula} :named |${e.label}|))`]),f=new Set(l.axioms.keys()),p=[...u,...d,...s.flatMap(e=>typeof e==`string`?[e]:`omitted`in e?[]:e.getLines(f))];return[`(set-logic UFNIA)`,...p.some(e=>/\bIdv\b/.test(e))||r.context.some(e=>e.kind===`Defn`&&(e.definition.kind===`Operator`||e.definition.kind===`Recursive`)&&!hu(e))?[`(declare-sort Idv 0)`]:[],...p].map(c.resolve).concat(`(check-sat)`,`(exit)`).join(`
43
- `)},yu=V(`@ `),bu={TRUE:`T.`,FALSE:`F.`,STRING:`TLA.STRING`,BOOLEAN:`(TLA.set T. F.)`,Nat:`arith.N`,Int:`arith.Z`,Real:`arith.R`,Infinity:`arith.Infinity`,Any:`TLA.Any`},xu={Implies:[`=>`,2],Equiv:[`<=>`,2],Conj:[`/\\`,2],Disj:[`\\/`,2],Neg:[`-.`,1],Eq:[`=`,2],DOMAIN:[`TLA.DOMAIN`,1],SUBSET:[`TLA.SUBSET`,1],UNION:[`TLA.UNION`,1],Subseteq:[`TLA.subseteq`,2],Mem:[`TLA.in`,2],Setminus:[`TLA.setminus`,2],Cap:[`TLA.cap`,2],Cup:[`TLA.cup`,2],Plus:[`arith.add`,2],Uminus:[`arith.minus`,1],Times:[`arith.mul`,2],Ratio:[`arith.div`,2],Quotient:[`arith.euclidiv`,2],Remainder:[`arith.mod`,2],Exp:[`arith.power`,2],Lteq:[`arith.le`,2],Lt:[`arith.lt`,2],Range:[`arith.intrange`,2],Seq:[`TLA.Seq`,1],Len:[`TLA.Len`,1],BSeq:[`TLA.BSeq`,1],Cat:[`TLA.concat`,2],Append:[`TLA.Append`,2],Head:[`TLA.Head`,1],Tail:[`TLA.Tail`,1],SubSeq:[`TLA.SubSeq`,3],SelectSeq:[`TLA.SelectSeq`,2],OneArg:[`TLA.oneArg`,2],Extend:[`TLA.extend`,2],Print:[`TLA.Print`,2],PrintT:[`TLA.PrintT`,1],Assert:[`TLA.Assert`,2],JavaTime:[`TLA.JavaTime`,0],TLCGet:[`TLA.TLCGet`,1],TLCSet:[`TLA.TLCSet`,2],Permutations:[`TLA.Permutations`,1],SortSeq:[`TLA.SortSeq`,2],RandomElement:[`TLA.RandomElement`,1],ToString:[`TLA.ToString`,1]},Su=e=>{let t=Number.parseInt(e,10);return`${`(TLA.fapply TLA.Succ `.repeat(t)}0${`)`.repeat(t)}`},Cu=(t,n)=>{let r=zi(),i=e=>Vi(r,vo(e)),a=()=>Vi(r,``),o=e=>H(e,m,yu),s=(e,t)=>V(`(%s %a)`,e,o(t)),c=(e,t,n)=>{let a=i(e),o=V(`%a((%s) %a))`,t,a,m(n));return Hi(r,1),o},l=(e,t)=>{let n=bu[e];if(n!==void 0&&t.length===0)return B(n);let r=xu[e];if(r&&r[1]===t.length)return s(r[0],t);if(t.length===2)switch(e){case`Neq`:return V(`(-. %a)`,s(`=`,t));case`Notmem`:return V(`(-. %a)`,s(`TLA.in`,t));case`Minus`:return s(`arith.add`,[t[0],{kind:`Apply`,operator:{kind:`Internal`,builtin:`Uminus`,location:t[1].location},args:[t[1]],location:t[1].location}]);case`Gteq`:return s(`arith.le`,t.toReversed());case`Gt`:return s(`arith.lt`,t.toReversed())}if(e===`Unprimable`&&t.length===1)return m(t[0]);throw bo(e,t.length,`Backend.Zenon.fmt_apply`)},u=(t,n)=>{switch(t.kind){case`Ix`:{let i=Bi(r,t.index);if(t.index<=0||i===void 0)throw new e.M;return n.length===0?B(i):s(i,n)}case`Opaque`:{let e=vo(t.name);return n.length===0?B(e):s(e,n)}case`Internal`:return l(t.builtin,n);case`Lambda`:{let e=t.params.map(e=>V(`%s `,i(e.name))),n=V(`((%a) %a)`,e,m(t.body));return Hi(r,t.params.length),n}default:throw new e.M}},d=(t,n,r)=>{if(n.length===0)return m(r);let i=xo(t,n,r),a=t===`Forall`;if(i.first.domain.kind===`NoDomain`)return c(i.first.name,B(a?`(A. `:`(E. `),i.inner);if(i.first.domain.kind!==`Domain`)throw new e.M;let o=m(i.first.domain.expression);return c(i.first.name,V(`(%s %a `,a?`TLA.bAll`:`TLA.bEx`,o),i.inner)},f=(t,n,r,i)=>{if(n.length!==1)throw new e.A(`${i} (multiple declared constants)`);let a=n[0];if(a.domain.kind!==`Domain`)throw new e.M;return c(a.name,V(`(%s %a `,t,m(a.domain.expression)),r)},p=t=>{if(t.context.length===0)return m(t.active);let n=t.context[0],o=()=>p({context:t.context.slice(1),active:t.active});if(n.kind===`Fact`){let e=n.visibility===`Visible`?m(n.expression):void 0;a();let t=e?V(`(=> %a %a)`,e,o()):o();return Hi(r,1),t}if(n.kind===`Defn`)throw new e.M;let s=n.kind===`Fresh`&&n.domain&&n.domainVisibility===`Visible`?m(n.domain):void 0,c=i(n.name),l=n.kind===`Flex`?V(`(A. ((%s) (A. ((%s') %a))))`,c,c,o()):s?V(`(TLA.bAll %a ((%s) %a))`,s,c,o()):V(`(A. ((%s) %a))`,c,o());return Hi(r,1),l},m=t=>{switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return u(t,[]);case`Apply`:return u(t.operator,t.args);case`Sequent`:return p(t.sequent);case`With`:case`Parens`:return m(t.expression);case`If`:return V(`(TLA.cond %a %a %a)`,m(t.condition),m(t.consequent),m(t.alternative));case`List`:if(t.bullet===`Refs`&&t.items.length===0)throw new e.M;return t.bullet===`Refs`&&t.items.length===1?m(t.items[0]):V(`(%s %a)`,t.bullet===`Or`?`\\/`:`/\\`,o(t.items));case`Quant`:return d(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.A(`\\AA or \\EE`);case`Choose`:return t.domain?c(t.name,V(`(TLA.bChoice %a `,m(t.domain)),t.body):c(t.name,B(`(t. `),t.body);case`SetSt`:return c(t.name,V(`(TLA.subsetOf %a `,m(t.domain)),t.body);case`SetOf`:return f(`TLA.setOfAll`,t.bounds,t.element,`Setof`);case`Fcn`:return f(`TLA.Fcn`,t.bounds,t.body,`Fcn`);case`SetEnum`:return t.elements.length===0?B(`TLA.emptyset`):[B(`(TLA.set`),t.elements.map(e=>V(` %a`,m(e))),B(`)`)];case`FcnApp`:{let e=m(t.function);return t.args.length===1?V(`(TLA.fapply %a %a)`,e,m(t.args[0])):V(`(TLA.fapply %a (TLA.tuple %a))`,e,o(t.args))}case`Arrow`:return V(`(TLA.FuncSet %a %a)`,m(t.domain),m(t.range));case`Rect`:case`Record`:return[B(t.kind===`Rect`?`(TLA.recordset`:`(TLA.record`),t.fields.map(e=>V(` "%s" %a`,e.name,m(e.value))),B(`)`)];case`Except`:{let n=t.specs[0];if(t.specs.length!==1||n.trail.length!==1)throw new e.A(`complex EXCEPT`);let r=n.trail[0],i=r.kind===`Dot`?B(`"${r.field}"`):m(r.expression);return V(`(TLA.except %a %a %a)`,m(t.function),i,m(n.value))}case`Dot`:return V(`(TLA.fapply %a "%s")`,m(t.expression),t.field);case`Tuple`:return V(`(TLA.tuple %a)`,o(t.elements));case`Product`:return t.factors.length===2?V(`(TLA.prod %a %a)`,m(t.factors[0]),m(t.factors[1])):V(`(TLA.Product (TLA.tuple %a))`,o(t.factors));case`Sub`:case`Tsub`:case`Fair`:throw new e.A(t.kind);case`Case`:{let e=H(t.arms,e=>V(`%a %a`,m(e.condition),m(e.body)),yu);return t.other?V(`(TLA.CASE %a %a)@]`,e,m(t.other)):V(`(TLA.CASE %a )`,e)}case`String`:return V(`"%s"`,t.value);case`Num`:if(t.fraction!==``)throw new e.A(`Real number constants`);return B(Su(t.integer));case`Bang`:case`Let`:case`At`:throw new e.M}},h=t=>{switch(t.kind){case`Fresh`:{let e=t.domain&&t.domainVisibility===`Visible`?m(t.domain):void 0,n=i(t.name);return e?V(`$hyp "%s_in" (TLA.in %s %a)@
44
- `,n,n,e):[]}case`Flex`:return i(t.name),[];case`Defn`:{let e=i(t.definition.name);return t.visibility===`Visible`?V(`; usable definition %s suppressed@.`,e):[]}case`Fact`:{let n=String(r.stack.length),i=t.visibility===`Visible`?So(r,()=>m(t.expression)):void 0;return a(),i instanceof e.A?V(`; omitted temporal assumption : %s @.`,i.message):i?V(`$hyp "v'%s" %a@
45
- `,n,i):[]}}},g=(()=>{try{return[n.context.map(h),V(`$goal %a`,m(n.active))]}catch(t){throw t instanceof e.A?new e.T(`Zenon: unsupported operator ${t.message}`):t}})();return ji([V(`;; obligation #%s@
46
- `,String(t)),g])},wu=e=>wc(ys(e)),Tu=(e,t,n,r)=>(n.rlimit===void 0?``:`(set-option :rlimit ${n.rlimit})\n`)+vu(wu(t),r),Eu={smt:Tu,z3:Tu,zenon:(e,t)=>Cu(e,wu(t)),isabelle:(e,t,n)=>Mo(e,wu(t),n.tactic??`auto`),ls4:(e,t)=>Mc(t)},Du=e=>e.kind===`Case`&&e.other===void 0||xt(e).some(Du),Ou=/* @__PURE__ */ new WeakMap,ku=e=>{let t=Ou.get(e);if(t!==void 0)return t;let n=[];yt(e,e=>(n.push(e),e),`all`);let r=n.some(Du);return Ou.set(e,r),r},Au=e=>/-{4,}\s*MODULE\s+(\w+)/.exec(e)?.[1]??`Main`,ju=e=>({id:e.id,location:e.location,text:e.text}),Mu=(e,t,n,r=[])=>({obligation:{...ju(e),status:t,reason:n},attempts:r}),Nu=(e,t)=>`${ra(t?vc(sc(e.sequent,!1)):bc(e))}\n`,Pu=(e,t,n)=>No(e,t.flatMap((e,t)=>e.attempts.filter(e=>e.method.prover===`isabelle`&&e.isProved&&!e.isReused).map(r=>({id:e.obligation.id,sequent:wu(bc(n[t])),tactic:r.method.tactic??`auto`})))),Fu=async(e,t)=>{let n=e.tasks[t];if(n.session)return n.session.current;let r=e.tasks.slice(0,t);await Promise.all(r.map(e=>e.done));let i=r.reduce((e,t)=>e+(t.session?t.session.current.caseErrors-t.session.initial:0),0);return n.session={initial:i,current:{caseErrors:i}},n.session.current},Iu=async(t,n,r,i)=>{if(t.kind.kind===`Error`)return Mu(t,`failed`,t.kind.message);let a=rc(t),o=As(t.sequent),s=r.lastByFingerprint.get(o);r.lastByFingerprint.set(o,r.tasks[n].done),await s;let c=[],l=[],u=e=>({obligation:{...ju(t),status:`proved`,prover:e},attempts:c}),d=e=>{r.isFingerprinted(t)||r.results.delete(o);let n=r.results.get(o)?.get(e.prover);return n?.method.tactic===e.tactic?n:void 0},f=e=>e.rlimit??e.timeLimitMs/1e3,p=e=>c.push({...e,isReused:!0,timeUsedMs:void 0}),m=e=>{c.push(e),r.results.set(o,(r.results.get(o)??/* @__PURE__ */ new Map).set(e.method.prover,e))},h=(e,t)=>{c.push({method:e,isProved:!1,isReused:!1,reason:t}),l.push({reason:t,isDecided:!1})},g=d(a.provers[0]);if(g?.isProved)return p(g),u(g.method.prover);let _=bc(t,a);if(t.kind.kind===`Support`&&xc(_))return r.results.set(o,r.results.get(o)??/* @__PURE__ */ new Map),{obligation:{...ju(t),status:`trivial`},attempts:c};for(let o of a.provers){let a=d(o);if(a?.isProved)return p(a),u(o.prover);if(a&&f(a.method)>=f(o)){p(a),l.push({reason:`${o.prover} failed on an obligation with the same fingerprint`,isDecided:!0});continue}if(!r.isProving)continue;if(o.prover===`trivial`)return u(o.prover);let s=Eu[o.prover];if(!s)h(o,`tla-ts has no ${o.prover} backend`);else try{let e=s===Tu&&(_.context.some(ku)||Du(_.active))?await Fu(r,n):{caseErrors:0},a=s(t.id,_,o,e),c=await r.decide(o.prover,a,{timeLimitMs:o.timeLimitMs,signal:i},n),d=c.verdict===`unsat`;if(m({method:o,isProved:d,isReused:!1,...!d&&{reason:c.timeUsedMs>=o.timeLimitMs?`timeout`:`false`},verdict:c.verdict,timeUsedMs:c.timeUsedMs}),d)return u(o.prover);l.push({reason:`${o.prover} answered ${c.verdict}`,isDecided:!0})}catch(t){if(t instanceof e.T){m({method:o,isProved:!1,isReused:!1,reason:`false`}),l.push({reason:`${o.prover} failed: ${t.message}`,isDecided:!0});continue}if(!(t instanceof e.A))throw t;h(o,`${o.prover} can't encode ${t.message}`)}}return Mu(t,l.some(e=>e.isDecided)?`failed`:`unsupported`,l.map(e=>e.reason).join(`, `),c)},Lu=(t,n)=>{if(n instanceof e.A)return Mu(t,`unsupported`,n.message);if(n instanceof e.T)return Mu(t,`failed`,n.message);throw n},Ru=async(t,r)=>{let i=r.workers??1,a=i>1&&e.r()?await po(i):void 0,o=()=>a?.terminate(r.signal?.reason);r.signal?.addEventListener(`abort`,o);let s={tasks:[],results:r.results??/* @__PURE__ */ new Map,isFingerprinted:r.isFingerprinted??(()=>!0),isProving:r.isProving??!0,lastByFingerprint:/* @__PURE__ */ new Map,decide:a?.decide??(async(e,t,r)=>n.t(e,t,r))},c=a?i*4:1,l=[],u=[],d=/* @__PURE__ */ new Set,f=[],p=async()=>{for(;u[f.length];){r.signal?.throwIfAborted();let e=await l[f.length];f.push(e),r.onReport?.(e,t[f.length-1]),await new Promise(e=>setTimeout(e))}};try{for(let[e,n]of t.entries()){r.signal?.throwIfAborted();let t=Promise.withResolvers();s.tasks.push({done:t.promise,session:void 0});let i=Iu(n,e,s,r.signal).catch(e=>Lu(n,e));l.push(i),d.add(t.promise);let a=()=>{u[e]=!0,d.delete(t.promise),t.resolve()};i.then(a,a),d.size>=c&&await Promise.race(d),await p()}await Promise.all(d),await p()}finally{r.signal?.removeEventListener(`abort`,o),a?.terminate(new e.T(`prove stopped`))}return f},zu=(e,t)=>({...ju(e),...t??{status:`unsupported`,reason:`tlapm reported no result`}}),Bu=async t=>{let n=Au(t.source),r=/* @__PURE__ */ new Map,i=fo([{file:`${n}.tla`,source:t.source}],e=>{let n=t.loadModule?.(e);n!==void 0&&r.set(e,n);let i=n??(e===`TLAPS`?`------------------------------- MODULE TLAPS --------------------------------
122
+ `,o-1),l=n.findLast(e=>e.kind!==`End`&&(e.line<s||e.line===s&&e.column<c));return{offset:o,line:s,column:c,end:{reason:Ya,line:l?.line??s,column:l?l.endColumn+1:c,isEnd:!0}}},Qa=t=>{try{return t()}catch(t){if(!(t instanceof e.F)||!t.failure)throw t;return t.failure}},$a=e=>typeof e==`object`&&!!e&&`reason`in e,eo=e=>{let n=Qa(()=>Za(e));if($a(n))return[n];let r=Qa(()=>t.x(n?e.slice(0,n.offset):e));return n&&(!$a(r)||r.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:n.line,column:n.column,isEnd:!1},$a(r)&&r.reason===Ya?r:n.end]:$a(r)?[r]:r},to=(t,n,r,i,a)=>{if(!Ja.test(t.source))throw new e.A(`No tokens in file`);let o=eo(t.source),s=Array.isArray(o)?o[0].proof:void 0;if(Array.isArray(o)&&s){let n={file:t.file,startLine:o[0].line,startColumn:o[0].column,endLine:s.stop.line,endColumn:s.stop.column};throw O(i,n,o[0].reason),new e.A(o[0].reason,{failure:s.exception})}if(Array.isArray(o)){o.forEach(e=>{let n=`File ${JSON.stringify(t.file)}, line ${e.line}, character ${e.column}\n${e.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`}),i(Fe({file:t.file,startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+1},`${e.reason}\n`))});let n=`Could not parse ${JSON.stringify(t.file)} successfully.`;throw i({text:`${a}Error: ${n}`,channel:`stderr`}),new e.A(n,{failure:`Module.Parser.parse_file`})}let c=Ka(t.file,t.source,n,r)(o),l=t.file.slice(t.file.lastIndexOf(`/`)+1),u=l.replace(/\.tla$/,``);return c.name===u?c:(i({text:`${Ie(c.location)}Warning: module name ${JSON.stringify(c.name)} does not match file name ${JSON.stringify(l)}.`,channel:`toolbox`}),{...c,name:u})},no=t=>{let n=new Map([...t].map(([e,t])=>[e,Or(t).dependencies])),r=/* @__PURE__ */ new Set,i=[],a=o=>{if(r.has(o))return;r.add(o);let s=t.get(o);if(!s)throw new e.A(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(Ar).forEach(a),i},ro=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${je(t)}`)],io=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?je({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...ro(`missing`,e.absent,t),...ro(`omitted`,e.omitted,n),` ====`]},ao=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...io(t,e.missing,e.omitted)],missing:e.missing+t.absent.length,omitted:e.omitted+t.omitted.length},{lines:[],missing:0,omitted:0});return[`---- summary of module ${JSON.stringify(e.name)} ----`,` obligations_count = ${t.total}`,...t.absent.length>0?[` missing_proofs_count = ${t.absent.length}`]:[],...t.omitted.length>0?[` omitted_proofs_count = ${t.omitted.length}`]:[],...n.lines,`====`].join(`
123
+ `)},oo=(t,n,r={})=>{let i=r.lines??qa,a=r.onWarning??(()=>{}),o={value:0},s=new Map(Sr);t.forEach(e=>{let t={...to(e,o,!0,a,`File "<unknown>":
124
+ `),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Ar(e.name,t.name)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=Or(c[e]);t.submodules.forEach((e,t)=>{u.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!Sr.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=to(r,o,!1,a,Pe(t.locations.get(e)));s.set(e,i),c.push(i)}}let d=[...l.keys()].filter(e=>!u.has(e)).sort(Ar);if(d.forEach(e=>{let t=`Unknown module ${JSON.stringify(e)}`;O(a,l.get(e),t)}),d.length>0)throw new e.A(`Unknown module ${JSON.stringify(d[0])}`,{failure:`Module.Parser.load_module`});let f={anonymizer:hr(o,(e,t)=>Yi(f,e,t),a),simplify:sa(o),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},p=no(s).map(e=>e.isStandard?e:Dr(s,e,/* @__PURE__ */ new Set)),m=Xr(new Set(t.map(e=>e.file)),i,a),h=new Map(p.map(e=>[e.name,e]));return p.flatMap(e=>{if(e.isStandard)return[];let t=Xi(f,h,void 0,e);if(!e.isImportant)return[];let n=m([],t),a=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let a=e.kind.kind===`Error`?e.kind.message:`${On(e.sequent,r.printing)}\n`;return[{id:t+1,location:Xa(n),locus:n,text:a,kind:e.kind,sequent:e.sequent,method:e.method,isEnabledAxiomsSound:e.isEnabledAxiomsSound}]});return[{name:e.name,location:e.location,obligations:a,summary:n.summary}]})},so=async t=>{let n=[],r=[],i=/* @__PURE__ */ new Map,a=[],o,s=()=>{for(;a.length>0&&r.length>0;){let e=r.reduce((e,t,n)=>t.priority<r[e].priority?n:e,0),[t]=r.splice(e,1),o=a.pop()??0;i.set(o,t),n[o].postMessage(t.request)}},c=(t,n)=>{let r=n,o=i.get(t);i.delete(t),a.push(t),`verdict`in r&&o?.resolve(r),`error`in r&&o?.reject(new e.j(r.error)),s()},l=e=>{o||(o={reason:e},[...r.splice(0),...i.values()].forEach(t=>t.reject(e)),i.clear(),n.forEach(e=>e.terminate()))};return n.push(...await Promise.all(Array.from({length:t},(t,n)=>e.i(new URL(`./prove-worker.js`,require("url").pathToFileURL(__filename).href),e=>c(n,e),l)))),a.push(...n.keys()),{decide:(e,t,n,i)=>new Promise((a,c)=>{if(o)return c(o.reason);r.push({request:{prover:e,text:t,timeLimitMs:n.timeLimitMs},priority:i,resolve:a,reject:c}),s()}),terminate:l}},co={"!":`excl_`,"#":`hash_`,$:`doll_`,"%":`perc_`,"&":`ampe_`,"'":`quot_`,"(":`lpar_`,")":`rpar_`,"*":`star_`,"+":`plus_`,"-":`dash_`,".":`peri_`,"/":`slas_`,":":`colo_`,"<":`less_`,"=":`equa_`,">":`more_`,"?":`ques_`,"@":`atsi_`,"[":`lbrk_`,"\\":`bksl_`,"]":`rbrk_`,"^":`care_`,_:`unde_`,"|":`vert_`,"~":`tild_`},lo=new Set((/* @__PURE__ */ `All Append Bijections Case CaseArm CaseOther Char Choice EnumFuncSet Ex Fcn FuncSet INTER Id.Image Injections Injective InjectiveOn Int Inverse Len Let Monotonic Nat Nibble Not PeanoAxioms.Pred Product Range Seq String Succ Surjections Surjective TYPE Trueprop Zero abs addElt addnat.all antisymmetric any aprop arbitrary args arith_add asms bAll bChoice bEx boolify c cap cargs.case_arm case_arms cases_conj cases_equal cases_forall cases_implies char cidts classes cond.conj conjunction converse cs cup default diff diffnat disj div divmodNat divmod_rel domrng.domrngs dummy dummy_pattern dvd emptySeq eq equivalence except extend fapply float_const.float_token fun geq gfp greater id idt idts iff imp in index infinity irreflexive isAFcn isASeq.isBool isNeg isPos itself leq less letbind letbinds lfp logic longid minus mod mult multnat.natInterval num num_const oneArg prod prop psubset psupset pttrn pttrns reflexive rel_comp.rel_domain rel_image rel_range setOfAll setOfPairs setminus sgn sort sort_constraint struct.subsetOf subseteq symmetric term tid tpl transitive tvar type types upair upto var xcpt xnum.xstr.ML ML_command ML_export ML_file ML_file_debug ML_file_no_debug ML_prf ML_val ROOTS_file.SML_export SML_file SML_file_debug SML_file_no_debug SML_import abbreviation abbrevs alias also.and apply apply_end assume assumes attribute_setup axiomatization back begin bibtex_file binder.bundle by case chapter class class_deps code_datatype compile_generated_files consider.constrains consts context corollary declaration declare default_sort defer define defines.definition done end experiment export_files export_generated_files export_prefix external_file.external_files extract extract_type finally find_consts find_theorems fix fixes for from.full_prf generate_file global_interpretation guess have help hence hide_class hide_const.hide_fact hide_type if imports in include includes including infix infixl infixr instance.instantiation interpret interpretation is judgment keywords lemma lemmas let local_setup locale.locale_deps method_setup moreover named_theorems next no_notation no_syntax no_translations.no_type_notation nonterminal notation note notepad notes obtain obtains oops open opening oracle.output overloaded overloading paragraph parse_ast_translation parse_translation pervasive prefer.premises presume prf print_ML_antiquotations print_abbrevs print_antiquotations.print_ast_translation print_attributes print_bundles print_cases print_classes print_codesetup.print_commands print_context print_definitions print_defn_rules print_facts print_interps.print_locale print_locales print_methods print_options print_rules print_simpset print_state.print_statement print_syntax print_term_bindings print_theorems print_theory print_trans_rules.print_translation private proof prop proposition qed qualified realizability realizers rewrites.schematic_goal section setup show shows simproc_setup sorry structure subclass subgoal sublocale.subparagraph subsection subsubsection supply syntax syntax_declaration term text text_raw then.theorem theory thm thm_deps thm_oracles thus thy_deps translations txt typ type_alias.type_notation type_synonym typed_print_translation typedecl ultimately unbundle unchecked.unfolding unused_thms using welcome when where with write.O max status`.split(`.`)).join(` `).split(` `)),uo=e=>/^[A-Za-z]$/.test(e),fo=t=>{if(/^[A-Za-z0-9]$/.test(t))return;let n=co[t];if(n===void 0)throw new e.U;return n},po=e=>{let t=[...e];return uo(t[0]??``)&&uo(t.at(-1)??``)&&t.every(e=>fo(e)===void 0)&&!lo.has(e)?e:`a_${t.map(e=>fo(e)??e).join(``)}a`},mo={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},ho=(t,n,r)=>{if((t===`Prime`||t===`StrongPrime`||t===`UNCHANGED`)&&n===1)return new e.U;let i=mo[t];return i&&i[1]===n?new e.j(`Unsupported operator \`${i[0]}\`.\n`):new e.j(r)},go=(e,t,n)=>{let r=t[0],i=t.slice(1),a=i[0]?.domain.kind===`Ditto`?[{...i[0],domain:r.domain},...i.slice(1)]:i;return a.length===0?{first:r,inner:n}:{first:r,inner:{kind:`Quant`,quantifier:e,bounds:a.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:I(1,e.domain.expression)}}:e),body:n,location:n.location}}},_o=(t,n)=>{let r=t.stack.length;try{return n()}catch(n){if(!(n instanceof e.B))throw n;return fn(t,t.stack.length-r),n}},vo=e=>`is${po(e)}`,yo={TRUE:`TRUE`,FALSE:`FALSE`,STRING:`STRING`,BOOLEAN:`BOOLEAN`,Nat:`Nat`,Int:`Int`,Real:vo(`Real`),Infinity:vo(`Infinity`),Any:`Any`},bo={Neg:`~`,DOMAIN:`DOMAIN`,SUBSET:`SUBSET`,UNION:`UNION`},xo={Implies:`\\<Rightarrow>`,Equiv:`\\<Leftrightarrow>`,Conj:`\\<and>`,Disj:`\\<or>`,Eq:`=`,Neq:`\\<noteq>`,Subseteq:`\\<subseteq>`,Mem:`\\<in>`,Notmem:`\\<notin>`,Setminus:`\\\\`,Cap:`\\<inter>`,Cup:`\\<union>`,OneArg:`:>`,Extend:`@@`},So={Plus:[`addint`,2],Minus:[`subint`,2],Uminus:[`minus`,1],Times:[`mult`,2],Ratio:[vo(`/`),2],Quotient:[vo(`\\div`),2],Remainder:[vo(`%`),2],Exp:[vo(`^`),2],Lteq:[`leq`,2],Lt:[`less`,2],Gteq:[`geq`,2],Gt:[`greater`,2],Range:[`intvl`,2],Seq:[`Seq`,1],Len:[`Len`,1],BSeq:[`BSeq`,1],Cat:[vo(`\\circ`),2],Append:[`Append`,2],Head:[`Head`,1],Tail:[`Tail`,1],SubSeq:[`SubSeq`,3],SelectSeq:[`SelectSeq`,2],Print:[`Print`,2],PrintT:[`PrintT`,1],Assert:[`Assert`,2],JavaTime:[`JavaTime`,0],TLCGet:[`TLCGet`,1],TLCSet:[`TLCSet`,2],Permutations:[`Permutations`,1],SortSeq:[`SortSeq`,2],RandomElement:[`RandomElement`,1],ToString:[`ToString`,1]},Co=[`consts`,...[[`Real`,0],[`/`,2],[`\\div`,2],[`%`,2],[`..`,2],[`Infinity`,0],[`[]`,1],[`<>`,1]].map(e=>` "${vo(e[0])}" :: ${e[1]===0?`c`:`"[${Array(e[1]).fill(`c`).join(`,`)}] => c"`}`),``].join(`
125
+ `),wo=e=>{let t=Number.parseInt(e,10);return`${`succ[`.repeat(t)}0${`]`.repeat(t)}`},To=(e,t)=>[`(* automatically generated -- do not edit manually *)`,`theory ${e} imports Constant Zenon begin`,...t?[`ML_command \\<open> writeln ("*** TLAPS PARSED\\n"); \\<close>`]:[],Co],Eo=t=>{let n=ln(),r=e=>dn(n,po(e)),i=()=>dn(n,``),a=(e,t)=>{let i=t(r(e));return fn(n,1),i},o=e=>`(${p(e)})`,s=e=>e.map(o).join(`, `),c=(e,t)=>`(${e} (${s(t)}))`,l=(t,n)=>{let r=yo[t];if(r!==void 0&&n.length===0)return r;let i=bo[t];if(i!==void 0&&n.length===1)return`(${i} ${o(n[0])})`;let a=xo[t];if(a!==void 0&&n.length===2)return`(${o(n[0])} ${a} ${o(n[1])})`;let s=So[t];if(s&&s[1]===n.length)return c(s[0],n);if(t===`Unprimable`&&n.length===1)return o(n[0]);throw t===`Irregular`&&n.length===1?new e.B(`Irregular`):ho(t,n.length,`Backend.Isabelle.pp_apply`)},u=(t,i)=>{switch(t.kind){case`Ix`:{let r=un(n,t.index);if(t.index<=0||r===void 0)throw new e.U;return i.length===0?r:c(r,i)}case`Opaque`:{let e=po(t.name);return i.length===0?`(${e} :: c)`:`(${e} (${s(i)}) :: c)`}case`Internal`:return l(t.builtin,i);case`Lambda`:{let e=`\\<lambda> ${t.params.map(e=>`${r(e.name)} `).join(``)}. ${o(t.body)}`;return fn(n,t.params.length),e}default:throw new e.U}},d=(t,n,r)=>{if(n.length===0)return p(r);let i=go(t,n,r),s=t===`Forall`?`\\<forall>`:`\\<exists>`;if(i.first.domain.kind===`NoDomain`)return a(i.first.name,e=>`${s}${e} : ${o(i.inner)}`);if(i.first.domain.kind!==`Domain`)throw new e.U;let c=o(i.first.domain.expression);return a(i.first.name,e=>`${s} ${e} \\<in> ${c} : ${o(i.inner)}`)},f=t=>{if(t.context.length===0)return o(t.active);let r=t.context[0],s=()=>f({context:t.context.slice(1),active:t.active});switch(r.kind){case`Flex`:return a(r.name,e=>`(\\<And> ${e} ${e}'.${s()})`);case`Fresh`:{if(r.domain&&r.domainVisibility===`Visible`){let e=o(r.domain);return a(r.name,t=>`(\\<And> ${t} :: c. ${t} \\<in> ${e} \\<Longrightarrow> ${s()})`)}let e=`${`c => `.repeat(r.shape)}c`;return a(r.name,t=>`(\\<And> ${t} :: ${e}. ${s()})`)}case`Fact`:{let e=r.visibility===`Visible`?o(r.expression):void 0;i();let t=e?`(${e} \\<Longrightarrow> ${s()})`:s();return fn(n,1),t}case`Defn`:throw new e.B(`Inner definition`)}},p=t=>{switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return u(t,[]);case`Apply`:return u(t.operator,t.args);case`Bang`:throw new e.j(`Backend.Isabelle.module`);case`Sequent`:return f(t.sequent);case`With`:case`Parens`:return p(t.expression);case`Let`:throw new e.B(`LET`);case`List`:return t.bullet===`Refs`&&t.items.length===0?`TRUE`:t.bullet===`Refs`&&t.items.length===1?p(t.items[0]):t.items.map(o).join(t.bullet===`Or`?` | `:` & `);case`If`:return`cond(${o(t.condition)}, ${o(t.consequent)}, ${o(t.alternative)})`;case`Quant`:return d(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.B(t.quantifier===`Forall`?`\\\\AA`:`\\\\EE`);case`Choose`:{if(!t.domain)return a(t.name,e=>`Choice(%${e}. ${o(t.body)})`);let e=o(t.domain);return a(t.name,n=>`bChoice(${e}, %${n}. ${o(t.body)})`)}case`SetSt`:{let e=o(t.domain);return a(t.name,n=>`subsetOf(${e}, %${n}. ${o(t.body)})`)}case`SetOf`:{if(t.bounds.length===0)throw new e.U;let n=t.bounds[0];if(t.bounds.length!==1||n.domain.kind!==`Domain`)throw new e.B(`SetOf (multiple declared constants)`);let r=o(n.domain.expression);return a(n.name,e=>`setOfAll(${r}, %${e}. ${o(t.element)})`)}case`SetEnum`:return`{${s(t.elements)}}`;case`Fcn`:{let n=t.bounds[0];if(t.bounds.length!==1)throw new e.B(`function (multiple declared constants)`);if(n.domain.kind===`Ditto`)throw new e.U;let r=n.domain.kind===`Domain`?o(n.domain.expression):void 0;return a(n.name,e=>`[${r===void 0?e:` ${e} \\<in> ${r} `} \\<mapsto> ${o(t.body)}]`)}case`FcnApp`:{let e=o(t.function);return t.args.length===1?`fapply (${e}, ${o(t.args[0])})`:`fapply (${e}, <<${s(t.args)}>>)`}case`Arrow`:return`[${o(t.domain)} \\<rightarrow> ${o(t.range)}]`;case`Rect`:return`[${t.fields.map(e=>`''${e.name}'' : ${o(e.value)}`).join(`, `)}]`;case`Record`:return`(${t.fields.map(e=>`(''${e.name}'' :> ${o(e.value)})`).join(` @@ `)})`;case`Except`:{let e=t.specs.map(e=>`!${e.trail.map(e=>e.kind===`Dot`?`[''${e.field}'']`:`[${o(e.expression)}]`).join(``)} = ${o(e.value)}`);return`[${o(t.function)} EXCEPT ${e.join(`, `)}]`}case`Dot`:return`fapply (${o(t.expression)}, (''${t.field}''))`;case`Tuple`:return`<<${s(t.elements)}>>`;case`Product`:return t.factors.length===2?`(${o(t.factors[0])} \\<times> ${o(t.factors[1])})`:`Product(\\<langle>${s(t.factors)}\\<rangle>)`;case`Sub`:case`Tsub`:{let e=t.kind===`Sub`?`sub`:`tsub`;return`${t.modal===`Box`?vo(`a'box'${e}`):`a'dia'${e}`}(${o(t.action)},${o(t.subscript)})`}case`Fair`:return`${vo(t.fairness===`Weak`?`a'wf`:`a'sf`)}(${o(t.subscript)},${o(t.action)})`;case`Case`:{let e=s(t.arms.map(e=>e.condition)),n=s(t.arms.map(e=>e.body));return t.other?`CaseOther(<<${e}>>,<<${n}>>,${o(t.other)})`:`Case(<<${e}>>,<<${n}>>)`}case`String`:return`''${t.value}''`;case`Num`:if(t.fraction!==``)throw new e.B(`real constants`);return`(${wo(t.integer)})`;case`At`:throw new e.U}},m=[],h=t=>{for(let a of t.context)switch(a.kind){case`Flex`:{let e=r(a.name);m.push(`fixes ${e} ${e}'`);break}case`Fresh`:{let e=a.domain&&a.domainVisibility===`Visible`?o(a.domain):void 0,t=r(a.name);if(m.push(`fixes ${t}`),e===void 0)break;m.push(`assumes ${t}_in : "(${t} \\<in> ${e})"`);break}case`Fact`:{let t=n.stack.length,r=a.visibility===`Visible`?_o(n,()=>o(a.expression)):void 0;if(i(),r instanceof e.B){m.push(`(* omitted temporal assumption : ${r.message} *)`);break}if(r===void 0)break;m.push(`assumes v'${t}: "${r}"`);break}case`Defn`:if(a.definition.kind===`Bpragma`){m.push(``);return}m.push(`(* usable definition ${a.definition.name} suppressed *)`),r(a.definition.name)}m.push(`shows "${o(t.active)}"`)},g=(()=>{try{h(t);return}catch(t){if(t instanceof e.j)return t;if(!(t instanceof e.B))throw t;return new e.j(`isabelle : unsupported operator ${t.message}`)}})();return{text:m.join(`
126
+ `),isAssumed:m.some(e=>e.startsWith(`assumes `)),failure:g}},Do=(e,t,n,r,i,a)=>{let o=Eo(t);if(a([...To(r,!1),`(* Generated from ${i.location} *)`,`lemma ob'${e}: (* ${i.fingerprint} *)`,o.text].join(`
127
+ `)),o.failure)throw o.failure;a([`(is "PROP ?ob'${e}")`,`proof -`,`show "PROP ?ob'${e}"`,`${o.isAssumed?`using assms `:``}by ${n}`,`qed`,`end`,``].join(`
128
+ `))},Oo=(e,t)=>[`${To(e,!0).join(`
129
+ `)}\n`,...t.flatMap(e=>{let t=Eo(e.sequent);return t.failure?[]:[`lemma ob'${e.id}:`,`${t.text}(is "PROP ?ob'${e.id}")`,`proof -`,`ML_command \\<open> writeln "*** TLAPS ENTER ${e.id}"; \\<close>`,`show "PROP ?ob'${e.id}"`,`${e.proof}ML_command \\<open> writeln "*** TLAPS EXIT ${e.id}"; \\<close> qed\n`].join(`
130
+ `)}),`end
131
+ `].join(``),ko=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],Ao=Array.from({length:64},(e,t)=>Math.floor(Math.abs(Math.sin(t+1))*2**32)),jo=(e,t)=>e<<t|e>>>32-t,Mo=e=>{let t=new TextEncoder().encode(e),n=Math.ceil((t.length+9)/64)*64,r=new Uint8Array(n);r.set(t),r[t.length]=128;let i=new DataView(r.buffer);i.setUint32(n-8,t.length*8>>>0,!0),i.setUint32(n-4,Math.floor(t.length/2**29),!0);let a=[1732584193,4023233417,2562383102,271733878];for(let e=0;e<n;e+=64){let t=Array.from({length:16},(t,n)=>i.getUint32(e+n*4,!0)),n=Array.from({length:64}).reduce(([e,n,r,i],a,o)=>{let s=Math.floor(o/16),c=s===0?n&r|~n&i:s===1?i&n|~i&r:s===2?n^r^i:r^(n|~i),l=s===0?o:s===1?(5*o+1)%16:s===2?(3*o+5)%16:7*o%16,u=e+c+Ao[o]+t[l]|0;return[i,n+jo(u,ko[s*4+o%4])|0,n,r]},a);a.splice(0,4,...a.map((e,t)=>e+n[t]|0))}return a.flatMap(e=>[e,e>>>8,e>>>16,e>>>24]).map(e=>(e&255).toString(16).padStart(2,`0`)).join(``)},No=(t,n)=>{let r=We(t,n-1)?.hyp;if(!r)throw new e.U;return r},Po=(e,t)=>ci(e,t).level,Fo=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),Io=(e,t)=>{let n=Ke(void 0,(n,r)=>{let i=it(r,t=>e(n,t),t);return[j(n,i),i]});return(t,r)=>{let i=n(t,r.context);return{context:i.context,active:e(i.state,r.active)}}},Lo=(e,t)=>{if(t.kind===`Sub`||t.kind===`Tsub`){let n=Lo(e,t.action),r=Lo(e,t.subscript),i=A(`UNCHANGED`,[r],t),a=t.modal===`Box`?A(`Disj`,[n,i],t):A(`Conj`,[n,A(`Neg`,[i],t)],t);return t.kind===`Sub`?a:A(t.modal===`Box`?`BoxTrue`:`Diamond`,[a],t)}return at(e,t,Lo,j,`all`)},Ro=(e,t)=>Fo(t,[`UNCHANGED`])&&t.args.length===1?Yn(t.args[0]):at(e,t,Ro,j,`all`),zo=(e,t)=>A(e,[t],t),Bo=(t,n)=>{if(n.kind===`Ix`){let e=No(t,n.index);return e.kind===`Fresh`&&e.level===`Constant`||e.kind===`Defn`&&e.definition.kind===`Operator`&&Po(We(t,n.index),e.definition.body)===0?n:zo(`Prime`,n)}if(Fo(n,[`ENABLED`])||n.kind===`Opaque`||n.kind===`Sequent`||n.kind===`Let`)return zo(`Prime`,n);if(Fo(n,[`UNCHANGED`,`Cdot`,`Leadsto`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`])||n.kind===`Tquant`||n.kind===`Sub`||n.kind===`Tsub`||n.kind===`Fair`)throw new e.U;return at(t,n,Bo,j)},Vo=e=>{let t=e===`BoxTrue`?`Conj`:`Disj`,n=e===`BoxTrue`?`Forall`:`Exists`,r=(i,a)=>Po(i,a)===0?a:Fo(a,[t])||(a.kind===`Quant`||a.kind===`Tquant`)&&a.quantifier===n?at(i,a,r,j):zo(e,a);return r},Ho={Prime:Bo,BoxTrue:Vo(`BoxTrue`),Diamond:Vo(`Diamond`)},Uo=(t,n)=>{if(n.kind===`Apply`&&n.operator.kind===`Internal`){let r=Ho[n.operator.builtin];if(r){if(n.args.length!==1)throw new e.U;return r(t,n.args[0])}}return at(t,n,Uo,j,`all`)},Wo={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},Go=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],Ko=(e,t)=>`${e}_${t}_`,qo=(t,n,r)=>{if(n.kind!==`Operator`)return n.kind===`Bpragma`?{...n,body:$o(t,n.body)}:n;let i=$o(t,n.body),a=Go[r??Po(t,i)];if(a===void 0)throw new e.U;return{...n,name:Ko(a,n.name),body:i}},Jo=(e,t,n)=>{switch(t.kind){case`Fresh`:return{...t,name:Ko(Wo[t.level],t.name),domain:t.domain&&$o(e,t.domain)};case`Flex`:return{...t,name:Ko(`VARIABLE`,t.name)};case`Defn`:return{...t,definition:qo(e,t.definition,n)};case`Fact`:return{...t,expression:$o(e,t.expression)}}},Yo=(e,t)=>{if(t.kind!==`Defn`||t.definition.kind!==`Operator`)return;let n=t=>{if(!Fo(t,[`UNCHANGED`]))return Po(e,t);let n=e=>e.kind===`Tuple`?e.elements.flatMap(n):[e],r=n(t.args[0]);return Po(e,r.length===1?r[0]:t.args[0])},r=t.definition.body;return n(Fo(r,[`Prime`,`BoxTrue`,`Diamond`])&&r.args.length===1?r.args[0]:r)},Xo=Ke({scope:void 0,original:void 0},(e,t,n)=>{let r=Jo(e.scope,t,Yo(e.original,n));return[{scope:j(e.scope,r),original:j(e.original,n)},r]}),Zo=(e,t)=>{let n=Xo(t.context,e.context);return{context:n.context,active:$o(n.state.scope,e.active)}},Qo=(e,t)=>{let[n,r]=Ge(e,t.context,(e,t)=>{let n=Jo(e,t);return[j(e,n),n]});return{context:r,active:$o(n,t.active)}},$o=(e,t)=>{switch(t.kind){case`Lambda`:{let n=t.params.map(e=>({...e,name:Ko(`Unknown`,e.name)})),r=M(e,n.map(Ze));return{...t,params:n,body:$o(r,t.body)}}case`Tquant`:{let n=M(e,t.names.map(e=>({kind:`Flex`,name:Ko(`VARIABLE`,e)})));return{...t,body:$o(n,t.body)}}case`Choose`:{let n=t.domain&&$o(e,t.domain),r=Ko(`CONSTANT`,t.name),i=n?qe(r,n):N(r,`Constant`);return{...t,name:r,domain:n,body:$o(j(e,i),t.body)}}case`SetSt`:{let n=$o(e,t.domain),r=Ko(`CONSTANT`,t.name),i=$o(j(e,qe(r,n)),t.body);return{...t,name:r,domain:n,body:i}}case`Quant`:case`Fcn`:case`SetOf`:{let n=t.bounds.map(t=>({...t,name:Ko(Wo[t.level],t.name),domain:t.domain.kind===`Domain`?{kind:`Domain`,expression:$o(e,t.domain.expression)}:t.domain})),r=M(e,n.map(Xe));return t.kind===`SetOf`?{...t,bounds:n,element:$o(r,t.element)}:{...t,bounds:n,body:$o(r,t.body)}}case`Let`:{let[n,r]=Ge(e,t.definitions,(e,t)=>{let n=qo(e,t);return[j(e,Qe(n)),n]});return{...t,definitions:r,body:$o(n,t.body)}}case`Sequent`:return{...t,sequent:Qo(e,t.sequent)};default:return at(e,t,$o,j,`all`)}},es=/* @__PURE__ */ new WeakMap,ts=(e,t)=>{let n=es.get(t);if(n)return n;let r=t.kind===`Operator`?t.body:void 0;if(r?.kind!==`Lambda`)return[];let i=M(e,r.params.map(Ze)),a=r.params.map((e,t)=>is(i,r.body,t+1,!0));return es.set(t,a),a},ns=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`ENABLED`,`UNCHANGED`],rs=[`Leadsto`,`Actplus`,`Cdot`],is=(t,n,r,i)=>{if(n.kind===`Ix`)return i||n.index!==r;if(n.kind===`Apply`&&n.operator.kind===`Internal`){let e=n.operator.builtin;if(ns.includes(e)&&n.args.length===1||rs.includes(e)&&n.args.length===2)return n.args.every(e=>is(t,e,r,!1))}if(n.kind===`Sub`)return[n.action,n.subscript].every(e=>is(t,e,r,!1));if(n.kind===`Apply`&&n.operator.kind===`Ix`){let i=We(t,n.operator.index-1),a=i?.hyp;if(i&&a?.kind===`Defn`&&a.definition.kind===`Operator`){let o=ts(i.rest,a.definition);return n.args.every((n,i)=>{let a=o[i];if(a===void 0)throw new e.U;return is(t,n,r,a)})}}let a=!0;return at({scope:t,index:r},n,(e,t)=>(a&&=is(e.scope,t,e.index,i),t),(e,t)=>({scope:j(e.scope,t),index:e.index+1}),`all`),a},as=(e,t)=>`h${Mo(en(En(e,t))).slice(0,5)}`,os=(e,t)=>k({kind:`Opaque`,name:as(He(e),t)},t),ss=(e,t,n,r,i)=>{let a=i.map((t,r)=>Po(e,t)===0||n[i.length-r-1]?k({kind:`Opaque`,name:`*`},t):t);return os(e,k({kind:`Apply`,operator:{kind:`Opaque`,name:t},args:a},r))},cs=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`Leadsto`,`ENABLED`,`Cdot`,`UNCHANGED`],ls=(t,n)=>{if(n.kind!==`Apply`)return at(t,n,ls,j);let r=n.operator,i=n.args,a=i[0];if(Fo(n,[`Prime`,`StrongPrime`])&&i.length===1&&a.kind===`Ix`){let e=No(t,a.index);if(e.kind===`Fresh`||e.kind===`Flex`)return k({kind:`Opaque`,name:`${e.name}#prime`},n)}if(Fo(n,cs))return os(t,n);if(r.kind!==`Ix`)return at(t,n,ls,j);let o=We(t,r.index-1),s=o?.hyp;if(!s)throw new e.U;let c=e=>k({kind:`Apply`,operator:e,args:i.map(e=>ls(t,e))},n);if(s.kind===`Defn`&&s.definition.kind===`Operator`){let e=ts(o.rest,s.definition);return i.every((n,r)=>Po(t,n)===0||e[i.length-r-1])?at(t,n,ls,j):c(ss(t,s.definition.name,e,r,i))}if(s.kind===`Flex`)return at(t,n,ls,j);if(s.kind===`Fresh`)return s.level===`Constant`?c(r):c(ss(t,s.name,i.map(()=>!1),r,i));throw new e.U},us=Io(Lo,`all`),ds=Io(Ro,`all`),fs=Io(Uo,`all`),ps=Io(ls,`visible`),ms=e=>{ci(void 0,{kind:`Sequent`,sequent:e});let t=e.context,n=ds(t,us(t,e)),r=fs(t,n);return ps(t,Zo(r,e))},hs=/* @__PURE__ */ `TRUE.FALSE.Implies.Equiv.Conj.Disj.Neg.Eq.Neq.STRING.BOOLEAN.SUBSET.UNION.DOMAIN.Subseteq.Mem.Notmem.Setminus.Cap.Cup.Prime.StrongPrime.Leadsto.ENABLED.UNCHANGED.Cdot.Actplus.Diamond.Nat.Int.Real.Plus.Minus.Uminus.Times.Ratio.Quotient.Remainder.Exp.Infinity.Lteq.Lt.Gteq.Gt.Divides.Range.Seq.Len.BSeq.Cat.Append.Head.Tail.SubSeq.SelectSeq.OneArg.Extend.Print.PrintT.Assert.JavaTime.TLCGet.TLCSet.Permutations.SortSeq.RandomElement.Any.ToString.Unprimable.Irregular`.split(`.`),gs={And:0,Or:1,Refs:2},_s={Forall:0,Exists:1},vs={Box:0,Dia:1},ys={Weak:0,Strong:1},bs={34:`\\"`,92:`\\\\`,10:`\\n`,9:`\\t`,13:`\\r`,8:`\\b`},xs=e=>`"${[...new TextEncoder().encode(e)].map(e=>bs[e]??(e<32||e>126?`\\${String(e).padStart(3,`0`)}`:String.fromCharCode(e))).join(``)}"`,Ss=e=>e===`BoxTrue`?`$Box`:e===`BoxFalse`?`$FakeBox`:`$${hs.indexOf(e)}`,Cs=t=>{let n=[],r=t=>{let r=n[n.length-t];if(!r)throw new e.U;return r},i=e=>n.push({ident:e,isUsed:!1}),a=()=>{let t=n.pop();if(!t)throw new e.U;return t},o=e=>Array.from({length:e}).forEach(()=>i({kind:`Var`})),s=e=>Array.from({length:e},a),c=t=>{if(t.ident.kind===`VarIndex`)return t.ident.index;if(t.ident.kind===`Var`)return 0;throw new e.U},l=t=>{if(t.ident.kind!==`HypIndex`)throw new e.U;return t.ident.index},u=(t,n)=>{let a=e=>u(t,e),l=e=>e.map(a).join(`,`),f=(e,t)=>t.map((t,n)=>t.domain.kind===`Domain`?`${c(e[n])}:${a(t.domain.expression)},`:``).join(``),p=(e,t)=>(o(e),{text:a(t),entries:s(e)}),m=e=>e.map(e=>`${c(e)}.`).join(``);switch(n.kind){case`Ix`:{let e=r(n.index);e.isUsed=!0;let i=e.ident;switch(i.kind){case`None`:return`$V(${n.index}SHOULD_NOT_APPEAR)`;case`Hyp`:{let n=t.hyp++;return e.ident={kind:`HypIndex`,index:n},`$${i.label}(${n})`}case`Var`:{let n=t.variable++;return e.ident={kind:`VarIndex`,index:n},`$PRM(${n})`}case`HypIndex`:return`$HYP(${i.index})`;case`VarIndex`:return`$PRM(${i.index})`;case`Pragma`:return``}}case`Opaque`:return n.name;case`Internal`:return Ss(n.builtin);case`Lambda`:{let e=p(n.params.length,n.body);return`$Lam(${m(e.entries.toReversed())}${e.text})`}case`Sequent`:return d(n.sequent);case`Apply`:{let e=n.operator;return e.kind===`Ix`&&r(e.index).ident.kind===`Pragma`?``:`$OpApp(${a(e)};${l(n.args)})`}case`With`:case`Parens`:return a(n.expression);case`If`:return`$If(${a(n.condition)},${a(n.consequent)},${a(n.alternative)})`;case`List`:return`$List(${gs[n.bullet]};${l(n.items)})`;case`Let`:{let t=n.definitions.map(t=>{if(t.kind!==`Operator`&&t.kind!==`Bpragma`)throw new e.U;let n=`${a(t.body)}.`;return i({kind:`Var`}),n}),r=a(n.body);return s(t.length),`${t.join(``)}${r}`}case`Quant`:{let e=p(n.bounds.length,n.body);return`$Quant(${_s[n.quantifier]};${f(e.entries,n.bounds)}.${e.text})`}case`Tquant`:{let e=p(n.names.length,n.body);return`$Tquant(${_s[n.quantifier]}${m(e.entries.toReversed())}${e.text})`}case`Choose`:{let e=p(1,n.body),t=c(e.entries[0]);return n.domain?`$Bch(${t}:${a(n.domain)};${e.text})`:`$Ch(${t}:${e.text})`}case`SetSt`:{let e=p(1,n.body);return`$SSt(${c(e.entries[0])}:${a(n.domain)};${e.text})`}case`SetOf`:{let e=p(n.bounds.length,n.element);return`$Sof(${f(e.entries.toReversed(),n.bounds)}.${e.text})`}case`Fcn`:{let e=p(n.bounds.length,n.body);return`$Fcn(${f(e.entries.toReversed(),n.bounds)}.${e.text})`}case`SetEnum`:return`$Set(${l(n.elements)})`;case`Tuple`:return`$Tup(${l(n.elements)})`;case`Product`:return`$Prod(${l(n.factors)})`;case`FcnApp`:return`$FcnApp(${a(n.function)};${l(n.args)})`;case`Arrow`:return`$Arrow(${a(n.domain)},${a(n.range)})`;case`Rect`:case`Record`:return`$${n.kind}(${n.fields.map(e=>`(${e.name},${a(e.value)})`).join(`,`)})`;case`Except`:return`$Except(${a(n.function)},${n.specs.map(e=>`(${e.trail.map(e=>e.kind===`Dot`?`.${e.field}`:`.${a(e.expression)}`).join(``)}=${a(e.value)})`).join(`,`)})`;case`Dot`:return`$Dot(${a(n.expression)},${n.field})`;case`Sub`:case`Tsub`:return`$${n.kind}(${vs[n.modal]},${a(n.action)},${a(n.subscript)})`;case`Fair`:return`$Fair(${ys[n.fairness]},${a(n.subscript)},${a(n.action)})`;case`Case`:return`$Case(${n.arms.map(e=>`(${a(e.condition)},${a(e.body)})`).join(`,`)},${n.other?a(n.other):``})`;case`String`:return xs(n.value);case`Num`:return`$Num(${n.integer},${n.fraction})`;case`At`:return`$At`;case`Bang`:throw new e.U}},d=t=>{let n={hyp:1,variable:1},r=(o,s)=>{let c=t.context[o];if(!c)return`$Goal(${u(n,t.active)})`;let d=e=>(i(e),{rest:r(o+1,j(s,c)),entry:a()});switch(c.kind){case`Fresh`:{if(!c.domain){let e=Wo[c.level],t=d({kind:`Hyp`,label:e});return t.entry.isUsed?`${t.rest}${e}${c.name}`:t.rest}let e=d({kind:`Hyp`,label:`CON`});if(c.domainVisibility===`Hidden`)return e.rest;let t=e.entry.isUsed?String(l(e.entry)):`_`;return`${e.rest}$Dom(${t};${u(n,c.domain)})`}case`Flex`:return d({kind:`Hyp`,label:`VAR`}).rest;case`Defn`:{let t=c.definition;if(t.kind===`Recursive`)return d({kind:`Hyp`,label:`CON`}).rest;if(t.kind===`Bpragma`)return d({kind:`Pragma`}).rest;if(t.kind===`Instance`)throw new e.U;let r=d({kind:`Hyp`,label:`HYP`});if(!r.entry.isUsed)return r.rest;let i=l(r.entry);return c.visibility===`Hidden`?`${r.rest}$Def(${i},${ar(s,t.body)?0:3})`:`${r.rest}$Def(${i};${u(n,t.body)})`}case`Fact`:return c.visibility===`Hidden`?d({kind:`None`}).rest:`${d({kind:`Hyp`,label:`HYP`}).rest}$Fact(${u(n,c.expression)},${c.time.toLowerCase()})`}};return r(0,void 0)};return d(t)},ws=e=>Mo(Cs(e)),Ts={kind:`Internal`,builtin:`TRUE`},Es=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2?e.args:void 0,Ds=e=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`ENABLED`&&e.args.length===1?e.args[0]:void 0,Os=(e,t)=>{let n=Es(e,t),r=n&&Ds(n[0]),i=n&&Ds(n[1]);return r&&i?[r,i]:void 0},ks=(t,n)=>{let r=/* @__PURE__ */ new Set,i=(t,n)=>{let a={...t,isPrimed:!0},o=n.kind===`Apply`&&n.operator.kind===`Internal`&&n.operator,s=o&&o.builtin,c=n.kind===`Apply`?n.args:[];if((s===`Prime`&&c.length===1||s===`ENABLED`||s===`Cdot`&&c.length===2||s===`UNCHANGED`&&c.length===1||n.kind===`Sub`)&&t.isPrimed)throw new e.U;if(s===`Prime`&&c.length===1)i(a,c[0]);else if(s===`Cdot`&&c.length===2)i(t,c[1]);else if(s===`UNCHANGED`&&c.length===1)i(a,c[0]);else if(n.kind===`Sub`)i(t,n.action),i(a,n.subscript);else if(n.kind===`Ix`){let i=We(t.scope,n.index-1)?.hyp;if(!i)throw new e.U;i.kind===`Flex`&&t.isPrimed&&r.add(i.name)}else s!==`ENABLED`&&at(t,n,i,(e,t)=>({...e,scope:j(e.scope,t)}));return n};return i({scope:t,isPrimed:!1},n),r},As=(e,t,n)=>{let r=ks(e,t);return[...ks(e,n)].every(e=>!r.has(e))},js=(t,n)=>{let r=e=>ci(t,e).level,i=(t,n)=>{if(r(t)>2||r(n)>2)throw new e.U},a=Ds(n),o=a&&Es(a,`Disj`);if(o)return i(o[0],o[1]),{name:`abdisj_inverse`,left:o[0],right:o[1]};let s=Os(n,`Disj`);if(s)return i(s[0],s[1]),{name:`abdisj`,left:s[0],right:s[1]};let c=a&&Es(a,`Conj`);if(c){let e=c[0],n=c[1],a=As(t,e,n);return i(e,n),a?{name:r(e)===2?`abconj_inverse`:`pconj_inverse`,left:e,right:n}:void 0}let l=Os(n,`Conj`);if(l)return As(t,l[0],l[1])?{name:`abconj`,left:l[0],right:l[1]}:void 0;let u=Es(n,`Conj`),d=u&&Ds(u[1]);if(u&&d)return r(u[0])<=1&&r(d)<=2?{name:`pconj`,left:u[0],right:d}:void 0;let f=Os(n,`Equiv`)??Os(n,`Eq`);if(f)return{name:`equiv`,left:f[0],right:f[1]};let p=Os(n,`Implies`);return p&&{name:`implies`,left:p[0],right:p[1]}},Ms=(t,n,r)=>{let i=M(void 0,t.context),a=js(i,t.active),o=!1,s=!1,c=!1;if(t.context.forEach((e,n)=>{if(!a||e.kind!==`Fact`||e.visibility!==`Visible`)return;let r=t.context.length-n,i=e.expression,l=e=>L(I(r,e),a.left),u=e=>L(I(r,e),a.right),d=(e,t)=>e!==void 0&&l(e[0])&&u(e[1])&&t.includes(a.name),f=Ds(i),p=f&&Es(f,`Conj`),m=Es(i,`Conj`),h=m&&Ds(m[1]),g=Es(i,`Mem`),_=g?.[1].kind===`Internal`&&g[1].builtin===`BOOLEAN`;d(p,[`pconj`])||d(f&&Es(f,`Disj`),[`abdisj`])||d(Os(i,`Disj`),[`abdisj_inverse`])||d(p,[`abconj`])||d(Os(i,`Conj`),[`abconj_inverse`,`pconj_inverse`])||d(m&&h&&[m[0],h],[`pconj_inverse`])?o=!0:d(Es(i,`Equiv`),[`equiv`])?(o=!0,s=!0,c=!0):d(Es(i,`Eq`),[`equiv`])?o=!0:g&&_&&l(g[0])?s=!0:g&&_&&u(g[0])?c=!0:d(Es(i,`Implies`),[`implies`])&&(o=!0)}),!a||!o||!s||!c)throw new e.j(`ENABLEDaxioms proof directive did not succeed.
132
+ `);return r({text:`${Pe(n)}[INFO]\nProved ${a.name}\n`,channel:`stdout`}),{...t,active:Ts}},Ns={Constant:0,State:1,Action:2,Temporal:3},Ps=(e,t,n)=>e.every((e,r)=>r<t.length&&n(e,t[r]))&&e.length===t.length,Fs=e=>[...new Map(e.toReversed().map(e=>[e.name,e.value]))].toSorted((e,t)=>e[0]<t[0]?-1:1),Is=(t,n)=>{let r=We(t,n-1);if(!r)throw new e.U;let i=r.hyp;if(i.kind===`Fresh`)return{name:i.name,kind:i.level,level:Ns[i.level]??-1};if(i.kind===`Flex`)return{name:i.name,kind:`Variable`,level:1};if(i.kind===`Defn`&&i.definition.kind===`Operator`){let e=ci(r.rest,i.definition.body).level;return{name:i.definition.name,kind:`Definition`,level:e}}throw new e.U},Ls=(e,t)=>M(e,t.map(Xe)),Rs=(e,t)=>M(e,t.map(Ze)),zs=(e,t)=>M(e,t.map(Qe)),Bs=(e,t)=>M(e,t.map(e=>({kind:`Flex`,name:e}))),Vs=(t,n,r,i)=>{let a=/* @__PURE__ */ new Map,o=(e,t,n,r)=>{let i=Is(e,n),o=Is(t,r);if(i.kind===`Unknown`)return n===r;if(i.kind===`Variable`||i.kind===`Definition`)return i.name===o.name&&o.kind===i.kind;let s=Ns[o.kind];if(!(s!==void 0&&s<=i.level||o.kind===`Definition`&&o.level<=i.level))return!1;let c=a.get(i.name);return c===void 0?(a.set(i.name,o.name),!0):c===o.name},s=(e,t,n,r)=>{if(n.kind===`Operator`&&r.kind===`Operator`||n.kind===`Bpragma`&&r.kind===`Bpragma`)return p(e,t,n.body,r.body);if(n.kind!==`Instance`||r.kind!==`Instance`)return!1;let i=n.instance.args,a=r.instance.args,o=(e,t)=>M(e,t.map(e=>N(e,`Unknown`))),s=e=>Fs(e.substitutions.map(e=>({name:e.name,value:e.expression})));return Ps(i,a,(e,t)=>e===t)&&n.instance.module===r.instance.module&&c(o(e,i),o(t,a),s(n.instance),s(r.instance))},c=(e,t,n,r)=>Ps(n,r,(n,r)=>n[0]===r[0]&&p(e,t,n[1],r[1])),l=(e,t,n,r)=>Ps(n,r,(n,r)=>{if(n.level!==r.level)return!1;let i=n.domain,a=r.domain;return i.kind===`Domain`&&a.kind===`Domain`?p(e,t,i.expression,a.expression):i.kind===a.kind&&i.kind!==`Domain`}),u=(e,t,n,r)=>n.kind===`Fresh`&&r.kind===`Fresh`?n.level!==r.level||n.shape!==r.shape?!1:n.domain&&r.domain?p(e,t,n.domain,r.domain):!n.domain&&!r.domain:n.kind===`Flex`&&r.kind===`Flex`?!0:n.kind===`Defn`&&r.kind===`Defn`?s(e,t,n.definition,r.definition)&&n.isLocal===r.isLocal:n.kind===`Fact`&&r.kind===`Fact`&&p(e,t,n.expression,r.expression),d=(e,t,n,r)=>n.length===0||r.length===0?n.length===r.length:u(e,t,n[0],r[0])&&d(j(e,n[0]),j(t,r[0]),n.slice(1),r.slice(1)),f=(e,t,n,r)=>!n.domain||!r.domain?!n.domain&&!r.domain&&p(j(e,N(n.name,`Constant`)),j(t,N(r.name,`Constant`)),n.body,r.body):p(e,t,n.domain,r.domain)&&p(j(e,qe(n.name,n.domain)),j(t,qe(r.name,r.domain)),n.body,r.body),p=(t,n,r,i)=>{if(r.kind===`Parens`)return p(t,n,r.expression,i);if(i.kind===`Parens`)return p(t,n,r,i.expression);let a=(e,r)=>p(t,n,e,r),u=(e,t)=>Ps(e,t,a);switch(r.kind){case`Ix`:return i.kind===`Ix`&&o(t,n,r.index,i.index);case`Opaque`:return i.kind===`Opaque`&&r.name===i.name;case`Internal`:return i.kind===`Internal`&&r.builtin===i.builtin;case`Lambda`:return i.kind===`Lambda`&&r.params.length===i.params.length&&p(Rs(t,r.params),Rs(n,i.params),r.body,i.body);case`Apply`:return i.kind===`Apply`&&a(r.operator,i.operator)&&u(r.args,i.args);case`Sequent`:return i.kind===`Sequent`&&d(t,n,r.sequent.context,i.sequent.context)&&p(M(t,r.sequent.context),M(n,i.sequent.context),r.sequent.active,i.sequent.active);case`Bang`:{if(i.kind!==`Bang`||!a(r.expression,i.expression))return!1;let t=i.selectors,n=r.selectors.every((e,n)=>{let r=t[n];return r?e.kind===`Number`&&r.kind===`Number`?e.value===r.value:e.kind===`Instance`&&r.kind===`Instance`?u(e.args,r.args):e.kind===`Label`&&r.kind===`Label`?e.label===r.label&&u(e.args,r.args):e.kind===r.kind:!0});if(n&&r.selectors.length!==t.length)throw new e.U(`Invalid_argument`);return n}case`With`:return i.kind===`With`&&a(r.expression,i.expression);case`Let`:return i.kind===`Let`&&Ps(r.definitions,i.definitions,(e,r)=>s(t,n,e,r))&&p(zs(t,r.definitions),zs(n,i.definitions),r.body,i.body);case`If`:return i.kind===`If`&&a(r.condition,i.condition)&&a(r.consequent,i.consequent)&&a(r.alternative,i.alternative);case`List`:return i.kind===`List`&&r.bullet===i.bullet&&u(r.items,i.items);case`Quant`:return i.kind===`Quant`&&r.quantifier===i.quantifier&&l(t,n,r.bounds,i.bounds)&&p(Ls(t,r.bounds),Ls(n,r.bounds),r.body,i.body);case`Tquant`:return i.kind===`Tquant`&&r.quantifier===i.quantifier&&Ps(r.names,i.names,(e,t)=>e===t)&&p(Bs(t,r.names),Bs(n,i.names),r.body,i.body);case`Choose`:case`SetSt`:return i.kind===r.kind&&f(t,n,r,i);case`SetOf`:return i.kind===`SetOf`&&p(Ls(t,r.bounds),Ls(n,i.bounds),r.element,i.element)&&l(t,n,r.bounds,i.bounds);case`SetEnum`:return i.kind===`SetEnum`&&u(r.elements,i.elements);case`Arrow`:return i.kind===`Arrow`&&a(r.domain,i.domain)&&a(r.range,i.range);case`Fcn`:return i.kind===`Fcn`&&l(t,n,r.bounds,i.bounds)&&p(Ls(t,r.bounds),Ls(n,i.bounds),r.body,i.body);case`FcnApp`:return i.kind===`FcnApp`&&u([r.function,...r.args],[i.function,...i.args]);case`Tuple`:return i.kind===`Tuple`&&u(r.elements,i.elements);case`Product`:return i.kind===`Product`&&u(r.factors,i.factors);case`Rect`:case`Record`:return i.kind===r.kind&&c(t,n,Fs(r.fields),Fs(i.fields));case`Except`:return i.kind===`Except`&&a(r.function,i.function)&&Ps(r.specs,i.specs,(e,t)=>Ps(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&a(e.expression,t.expression))&&a(e.value,t.value));case`Dot`:return i.kind===`Dot`&&a(r.expression,i.expression)&&r.field===i.field;case`Sub`:case`Tsub`:return i.kind===r.kind&&r.modal===i.modal&&a(r.action,i.action)&&a(r.subscript,i.subscript);case`Fair`:return i.kind===`Fair`&&r.fairness===i.fairness&&a(r.subscript,i.subscript)&&a(r.action,i.action);case`Case`:{if(i.kind!==`Case`)return!1;let e=r.arms[0],t=i.arms[0];return(e&&t?a(e.condition,t.condition)&&a(e.body,t.body):!e&&!t)?r.other&&i.other?a(r.other,i.other):!r.other&&!i.other:!1}case`String`:return i.kind===`String`&&r.value===i.value;case`Num`:return i.kind===`Num`&&r.integer===i.integer&&r.fraction===i.fraction;case`At`:return i.kind===`At`&&r.isExcept===i.isExcept}},m=p(t,n,r,i),h=He(t),g=[...a].map(t=>t[0]===t[1]||h.reduce((n,r)=>{if(r.kind===`Fact`)return n;if(r.kind===`Defn`&&r.definition.kind!==`Operator`)throw new e.U;return n||(r.kind===`Defn`?r.definition.name:r.name)===t[0]},!1));return m&&g.every(Boolean)},Hs=t=>{let n=M(void 0,t.context);if(!t.context.some((e,r)=>{if(e.kind!==`Fact`||e.visibility!==`Visible`)return!1;let i=We(n,t.context.length-r),a=e.expression;return a.kind===`Sequent`?Vs(M(i,a.sequent.context),n,a.sequent.active,t.active):Vs(i,n,a,t.active)}))throw new e.j(`LevelComparison proof directive did not succeed.
133
+ `);return{...t,active:{kind:`Internal`,builtin:`TRUE`}}},Us=e=>e.rlimit??e.timeLimitMs/1e3,Ws=/* @__PURE__ */ new Set([`expandenabled`,`expandcdot`,`autouse`,`lambdify`,`enabledaxioms`,`levelcomparison`]),Gs=[{prover:`smt`,timeLimitMs:5e3},{prover:`zenon`,timeLimitMs:1e4},{prover:`isabelle`,timeLimitMs:3e4,tactic:`auto`}],Ks={zenon:{prover:`zenon`,seconds:10},isabelle:{prover:`isabelle`,seconds:30},yices:{prover:`yices`,seconds:30},ls4:{prover:`ls4`,seconds:10},z3:{prover:`z3`,seconds:5,isBudgeted:!0},smt:{prover:`smt`,seconds:5,isBudgeted:!0},cvc3:{prover:`cvc4`,seconds:5},cooper:{prover:`cooper`,seconds:1/0},fail:{prover:`fail`,seconds:1/0},smt2lib:{prover:`smt`,seconds:5,isBudgeted:!0},smt2z3:{prover:`z3`,seconds:5,isBudgeted:!0},smt3:{prover:`smt`,seconds:5,isBudgeted:!0},z33:{prover:`z3`,seconds:5,isBudgeted:!0},cvc33:{prover:`cvc4`,seconds:5},yices3:{prover:`yices`,seconds:5},verit:{prover:`verit`,seconds:5},zipper:{prover:`zipper`,seconds:30},spass:{prover:`spass`,seconds:5},tptp:{prover:`tptp`,seconds:5},trivial:{prover:`trivial`,seconds:0},...Object.fromEntries([...Ws].map(e=>[e,{prover:e,seconds:0}]))},qs=(t,n,r,i)=>{let a=Ks[t];if(!a)throw new e.j(`Unknown prover: ${t}`);return{prover:a.prover,timeLimitMs:r===void 0?(n??a.seconds)*1e3:1/0,...r!==void 0&&{rlimit:r},...a.prover===`isabelle`&&{tactic:i??`auto`}}},Js=`a number of seconds (wall-clock timeout), or a deterministic Z3 rlimit budget of the form "rN" (e.g. "r5")`,Ys=(t,n)=>{let r=Number(t.slice(1));if(!/^[rR]./.test(t)||!Number.isFinite(r)||r<=0)throw new e.E(`Invalid SMT budget ${JSON.stringify(t)}: expected ${Js}.`,n);return Math.max(1,Math.trunc(Math.min(r*3e6,4294967295)))},Xs=(t,n,r)=>{let i=t.reduce((t,n)=>{let i=n.value,a=i.kind===`Default`?t.args[0]:void 0,o=i.kind===`Default`?t.args.slice(1):t.args;if(n.hint!==`prover`&&n.hint!==`tactic`&&n.hint!==`timeout`)throw new e.E(`Unknown keyword in proof method definition: ${n.hint}`,n.location);if(i.kind===`Default`&&!a)throw new e.E(`Some arguments are missing`,r);if(n.hint===`timeout`){if(i.kind===`Float`)return{...t,timeout:i.value};if(i.kind===`String`)return{...t,rlimit:Ys(i.value,n.location)};if(a?.kind===`Num`)return{...t,args:o,timeout:Number(`${a.integer}.${a.fraction}`)};if(a?.kind===`String`)return{...t,args:o,rlimit:Ys(a.value,a.location)};throw new e.E(`This argument should be ${Js}`,a?.location)}if(i.kind===`Float`)throw new e.E(`Argument should be a string or @`,n.location);let s=i.kind===`String`?i.value:a?.kind===`String`?a.value:void 0;if(s===void 0)throw new e.E(`This argument should be a string (${n.hint===`prover`?`prover name`:`proof tactic`})`,a?.location);return n.hint===`tactic`?{...t,args:o,tactic:s}:{...t,args:o,prover:s,proverLocus:i.kind===`Default`?r:n.location}},{args:n});if(i.args.length>0)throw new e.E(`Too many arguments`,r);if(i.prover===void 0)throw new e.E(`Missing prover name`,t[0].location);let a=Ks[i.prover];if(!a)throw new e.E(`Unknown prover: ${i.prover}`,i.proverLocus);if(i.rlimit!==void 0&&!a.isBudgeted)throw new e.E(`A Z3 rlimit budget ("rN") is only supported by the SMT and Z3 backends.`,r);return qs(i.prover,i.timeout,i.rlimit,i.tactic)},Zs=e=>qs(e.name,e.timeout,void 0,e.tactic),Qs=t=>{let n=[],r=[],i=null;return t.context.forEach((t,a)=>{let o=t.kind===`Fact`&&t.visibility===`Visible`&&t.expression;if(o&&o.kind===`With`){r.push(Zs(o.method)),n.push(void 0);return}if(t.kind===`Defn`&&t.definition.kind===`Bpragma`){n.push({kind:`Premeth`,groups:t.definition.methods});return}if(t.kind===`Defn`&&t.definition.kind===`Operator`&&t.visibility===`Visible`){let e=t.definition.body;n.push(e.kind===`With`?{kind:`Meth`,method:e.method}:void 0);return}if(n.push(void 0),!o||t.kind!==`Fact`)return;let s=o.kind===`Apply`?o.operator:o;if(s.kind!==`Ix`)return;let c=n[a-s.index];if(c?.kind===`Premeth`){t.useLocation!==i&&(r=[],i=t.useLocation);let e=o.kind===`Apply`?o.args:[];r.push(...c.groups.map(t=>Xs(t,e,o.location)))}else if(c?.kind===`Meth`){if(o.kind===`Apply`)throw new e.U;r.push(Zs(c.method))}}),r},$s=(e,t=Gs)=>{let n=e.method===void 0?Qs(e.sequent):[Zs(e.method)],r=n.filter(e=>!Ws.has(e.prover));return{frontends:new Set(n.flatMap(e=>Ws.has(e.prover)?[e.prover]:[])),provers:r.length>0?r:t}},ec={zenon:`zenon`,smt:`smt`,z3:`z3`,cvc4:`cvc33`,yices:`yices3`,verit:`verit`,zipper:`zipper`,spass:`spass`,tptp:`tptp`,ls4:`ls4`},tc=t=>t.split(`,`).map(t=>{let n=t.indexOf(`:`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:Number.parseFloat(t.slice(n+1));if(Number.isNaN(i))throw new e.j(`--method: bad timeout specification: not a number`);if(r===`auto`||r===`blast`||r===`force`)return qs(`isabelle`,i,void 0,r);if(r===`fail`)return{prover:`fail`,timeLimitMs:1/0};let a=ec[r];if(a===void 0)throw new e.j(`--method: unknown method ${JSON.stringify(r)}`);return qs(a,i,void 0,void 0)}),nc=e=>Ke(P(0),(t,n)=>n.kind===`Defn`&&(e&&n.definition.kind===`Bpragma`||n.definition.kind===`Operator`&&n.visibility===`Visible`)?[ct(F(t,n.definition.body),t),void 0]:[ut(1,t),gt(t,n)]),rc=nc(!0),ic=nc(!1),ac=(e,t=!0)=>{let n=(t?rc:ic)(e.context);return{context:n.context,active:F(n.state,e.active)}},oc=/* @__PURE__ */ new Set([`BoxTrue`,`BoxFalse`,`Diamond`,`Actplus`,`Leadsto`,`Cdot`]),sc=e=>{switch(e.kind){case`Fresh`:return e.domain?[e.domain]:[];case`Flex`:return[];case`Defn`:return e.visibility===`Hidden`||e.definition.kind!==`Operator`&&e.definition.kind!==`Bpragma`?[]:[e.definition.body];case`Fact`:return e.visibility===`Hidden`?[]:[e.expression]}},cc=e=>{if(e.kind===`Tsub`||e.kind===`Fair`||e.kind===`Apply`&&e.operator.kind===`Internal`&&oc.has(e.operator.builtin))return!1;if(e.kind===`Sequent`){let t=e.sequent;return[...t.context.flatMap(sc),t.active].every(cc)}return st(e).every(cc)},lc=t=>{if(t.kind!==`Let`)return ot(t,lc);let n=t.definitions[0];if(!n)return lc(t.body);if(n.kind!==`Operator`&&n.kind!==`Bpragma`)throw new e.A(n.kind===`Instance`?`Found INSTANCE in Expr.Elab.let_normalize, all INSTANCE statements have been replaced with definitions in Module.Elab `:`Expr.Elab.let_normalize`);let r=lc(n.body),i={...t,definitions:t.definitions.slice(1)};return lc(F(ct(r,P(0)),i))},uc=(e,t)=>t.kind===`Dot`?k({kind:`Dot`,expression:e,field:t.field},e):k({kind:`FcnApp`,function:e,args:[t.expression]},e),dc=(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&L(e.expression,t.expression),fc=(e,t)=>{let n=t.kind===`Dot`?t.field:t.expression.kind===`String`?t.expression.value:void 0;return e.kind===`Record`&&n!==void 0?e.fields.find(e=>e.name===n):void 0},pc=e=>{if(e.kind!==`Except`)return ot(e,pc);let t=e,n=(e,t)=>fc(e,t)?.value??uc(e,t),r=(e,n,r)=>{let i=fc(e,n);if(e.kind!==`Record`||!i)return k({kind:`Except`,function:e,specs:[{trail:[n],value:r}]},t);let a=e.fields.map(e=>e.name===i.name?{name:e.name,value:r}:e);return k({kind:`Record`,fields:a},e)},i=(e,t)=>{let a=t[0];if(!a)return e;if(a.trail.length===0)return i(a.value,t.slice(1));let o=a.trail[0],s=t.findIndex(e=>e.trail.length===0||!dc(e.trail[0],o)),c=s===-1?t.length:s,l=t.slice(0,c).map(e=>({trail:e.trail.slice(1),value:e.value}));return i(r(e,o,i(n(e,o),l)),t.slice(c))};return i(pc(t.function),nt(t.specs,pc))},mc=Ke(!0,(e,t)=>[e&&sc(t).every(cc),it(t,lc,`all`)]),hc=Ke(void 0,(e,t)=>[void 0,it(t,pc,`all`)]),gc=e=>{let t=mc(e.context),n=lc(e.active);return t.state&&cc(e.active)?{context:hc(e.context,t.context).context,active:pc(n)}:{context:t.context,active:n}},_c=(t,n,r,i,a)=>{let o=i.has(`expandenabled`),s=i.has(`expandcdot`),c=i.has(`autouse`),l=i.has(`lambdify`);if(!o&&!s&&!l){if(i.has(`levelcomparison`))return Hs(t);if(!i.has(`enabledaxioms`))return t;if(r!==void 0&&a({text:`expr has ENABLEDaxioms property ===`,channel:`stdout`}),r===!1)throw new e.j(`ENABLEDaxioms depends on assumptions of level > 1
134
+
135
+ `);return Ms(t,n,a)}let u=hr({value:0},()=>{throw new e.U},()=>{}),d={kind:`Sequent`,sequent:t},f=o||s?Ni(u,a,void 0,d,{isEnabled:o,isCdot:s,isAutoUse:c}):Ai(u,a,void 0,d,{isEnabled:!0,isCdot:!0,isAutoUse:c});if(f.kind!==`Sequent`)throw new e.U;return f.sequent},vc=(e,t=$s(e),n=()=>{})=>_c(gc(ac(e.sequent)),e.locus,e.isEnabledAxiomsSound,t.frontends,n),yc=e=>e.active.kind===`Internal`&&e.active.builtin===`TRUE`||e.context.some((t,n)=>t.kind===`Fact`?L(t.expression,I(n-e.context.length,e.active)):t.kind!==`Fresh`||!t.domain?!1:L(A(`Mem`,[{kind:`Ix`,index:1},I(1,t.domain)],{}),I(n+1-e.context.length,e.active))),bc=e=>e.domain.kind===`NoDomain`,xc=e=>{if(e.kind===`List`&&(e.bullet===`And`||e.bullet===`Refs`)){let t=e.items.map(xc),n=t.flatMap(e=>e[0]),r=t.flatMap(e=>e[1]?[e[1]]:[]);return r.length<=1?[n,r[0]]:[n,{...e,bullet:`And`,items:r}]}if(e.kind===`Apply`&&e.operator.kind===`Internal`){let t=e.operator.builtin;if(t===`Conj`&&e.args.length===2){let t=xc(e.args[0]),n=xc(e.args[1]),r=[...t[0],...n[0]];return t[1]&&n[1]?[r,{...e,args:[t[1],n[1]]}]:[r,t[1]??n[1]]}if(t===`Eq`)return[[e],void 0]}if(e.kind===`Internal`&&e.builtin===`TRUE`)return[[],void 0];if(e.kind===`Quant`&&e.quantifier===`Forall`&&e.bounds.every(bc)){let t=xc(e.body),n=(t,n)=>k({kind:`Quant`,quantifier:`Forall`,bounds:e.bounds,body:t},n);return[t[0].map(e=>n(e,e)),t[1]&&n(t[1],e)]}return[[],e]},Sc=e=>{let t=[],n=e.context.reduce((e,n)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return t.push(gt(e,n)),ut(1,e);let r=xc(n.expression),i=[...r[1]?[r[1]]:[],...r[0]];return i.forEach((r,i)=>t.push({...n,expression:I(i,F(e,r))})),{kind:`Compose`,outer:P(i.length-1),inner:ut(1,e)}},P(0));return{context:t,active:F(n,e.active)}},Cc=(e,t)=>{let[n,r]=Ge(e,t.context,(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return{...t,name:`${Wo[t.level]}_${t.name}_`,domain:t.domain&&wc(e,t.domain)};case`Flex`:return{...t,name:`VARIABLE_${t.name}_`};case`Defn`:{let n=t.definition;if(n.kind!==`Operator`)return t;let r=wc(e,n.body),i=Go[ci(e,r).level];return{...t,definition:{...n,name:`${i}_${n.name}_`,body:r}}}case`Fact`:return{...t,expression:wc(e,t.expression)}}})();return[j(e,n),n]});return{context:r,active:wc(n,t.active)}},wc=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:Cc(e,t.sequent)};let n=at(e,t,wc,j,`all`);switch(n.kind){case`Lambda`:return{...n,params:n.params.map(e=>({...e,name:`Unknown_${e.name}_`}))};case`Quant`:case`Fcn`:case`SetOf`:return{...n,bounds:n.bounds.map(e=>({...e,name:`${Wo[e.level]}_${e.name}_`}))};case`Choose`:case`SetSt`:return{...n,name:`CONSTANT_${n.name}_`};default:return n}},Tc=(e,t)=>{if(t.kind!==`Sequent`)return at(e,t,Tc,j,`all`);let n=e,r=P(0),i=[],a=e=>{let t=e.kind===`Fact`&&e.visibility===`Visible`&&e.time===`Always`?{...e,expression:A(`BoxTrue`,[e.expression],e.expression)}:e;i.push(t),n=j(n,t)};for(let e of t.sequent.context){let t=gt(r,e);if(t.kind!==`Fresh`||!t.domain){a(t.kind===`Fact`?{...t,expression:Tc(n,t.expression)}:t),r=ut(1,r);continue}let i=Tc(n,t.domain);a({...t,domain:void 0}),a({kind:`Fact`,expression:A(`Mem`,[k({kind:`Ix`,index:1},i),I(1,i)],i),visibility:t.domainVisibility,time:t.level===`Constant`?sr(n,I(1,i)):`Now`,location:t.location}),r={kind:`Compose`,outer:P(1),inner:ut(1,r)}}let o=F(r,t.sequent.active);return{...t,sequent:{context:i,active:Tc(n,o)}}},Ec={Conj:`&`,Disj:`|`,Implies:`->`,Equiv:`<->`},Dc={Neg:`~`,BoxTrue:`always`,BoxFalse:`always`,Diamond:`sometime`,Prime:`next`},Oc=e=>{if(e.kind===`Internal`&&e.builtin===`TRUE`)return;if(e.kind===`List`&&e.bullet!==`Or`){let t=e.items.flatMap(e=>Oc(e)??[]);return t.length<=1?t[0]:{...e,bullet:`And`,items:t}}if(e.kind!==`Apply`||e.operator.kind!==`Internal`||e.operator.builtin!==`Conj`||e.args.length!==2)return e;let t=Oc(e.args[0]),n=Oc(e.args[1]);return t&&n?{...e,args:[t,n]}:t??n},kc=`(cc | ~ cc)`,Ac=e=>{let t=(e,n,r=!1)=>{let i=n=>t(e,n);switch(n.kind){case`Internal`:if(n.builtin===`TRUE`)return kc;if(n.builtin===`FALSE`)return`(cc & ~ cc)`;break;case`Apply`:{let e=n.operator,t=n.args;if(e.kind!==`Internal`)break;let r=Ec[e.builtin];if(r&&t.length===2)return`(${i(t[0])} ${r} ${i(t[1])})`;let a=Dc[e.builtin];if(a&&t.length===1)return`(${a} ${i(t[0])})`;break}case`List`:{if(n.items.length===0)return kc;let e=n.bullet===`Or`?`|`:`&`;return n.items.map(i).reduceRight((t,n)=>`(${n} ${e} ${t})`)}case`Sequent`:{let i=[...e],a=[];for(let e of n.sequent.context){let n=e.kind!==`Fact`||e.visibility!==`Visible`?void 0:r?Oc(e.expression):e.expression;n&&a.push(t(i,n)),i.push(e)}let o=t(i,n.sequent.active);return a.length===0?o:`(${a.join(` & `)} -> ${o})`}}return as(e,n)},n=wc(void 0,{kind:`Sequent`,sequent:e});return`not (${t([],Tc(void 0,$n(Zn(Qn(n)))),!0)})`},jc=(e,t)=>e<t?-1:+(e>t),Mc=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return jc(e,t);if(!Array.isArray(e)||!Array.isArray(t))return 0;let n=e.findIndex((e,n)=>n>=t.length||Mc(e,t[n])!==0);return n===-1?e.length-t.length:n>=t.length?1:Mc(e[n],t[n])},Nc={"\\":`backslash_`,"+":`plussign_`,"-":`hyphen_`,"*":`asterisk_`,"/":`slash_`,"%":`percentsign_`,"^":`circumflexaccent_`,"&":`ampersand_`,"@":`atsign_`,"#":`pound_`,$:`dollarsign_`,"(":`leftparenthesis_`,")":`rightparenthesis_`,"|":`verticalbar_`,".":`period_`,":":`colon_`,"?":`questionmark_`,"!":`exclamationmark_`,"<":`lessthansign_`,">":`greaterthansign_`,"=":`equalsign_`," ":`space_`},Pc=e=>`smt__${e.replace(/[\\+\-*/%^&@#$()|.:?!<>= ]/g,e=>Nc[e]).replaceAll(`_`,`__`)}`,Fc=Pc(`TLA__`),Ic=new Map(Object.entries(Nc).map(e=>[e[1],e[0]])),Lc=RegExp(`(${[...Ic.keys()].join(`|`)})`,`g`),V=e=>Pc(`TLA__${e}`),Rc=e=>e.startsWith(Fc)?e.slice(Fc.length).replaceAll(`__`,`_`).replace(Lc,e=>Ic.get(e)??e):void 0,H=V(`Mem`),zc=V(`SetExtTrigger`),Bc=V(`SubsetEq`),Vc=V(`Cup`),Hc=V(`Cap`),Uc=V(`SetMinus`),Wc=V(`Subset`),Gc=V(`Union`),Kc=V(`Tt_Idv`),qc=V(`Cast_Bool`),Jc=V(`BoolSet`),Yc=V(`StrSet`),U=V(`IntSet`),W=V(`NatSet`),G=V(`Cast_Int`),Xc=V(`Proj_Int`),K=V(`IntLteq`),Zc=V(`IntPlus`),Qc=V(`IntMinus`),$c=V(`IntRange`),q=V(`FunApp`),el=V(`FunDom`),tl=V(`FunIsafcn`),nl=V(`FunSet`),rl=V(`FunExcept`),il=V(`TrigEq_Set$Idv$`),al=V(`IsSetOf`),J=V(`Seq`),Y=V(`Len`),ol=V(`Cat`),sl=V(`Append`),cl=V(`Head`),ll=V(`Tail`),ul=V(`SubSeq`),dl=V(`Tuple_0`),fl=new Map([[`TIntPlus`,`+`],[`TIntMinus`,`-`],[`TIntTimes`,`*`],[`TIntUminus`,`-`],[`TIntLteq`,`<=`],[`TIntLt`,`<`],[`TIntGteq`,`>=`],[`TIntGt`,`>`]].map(e=>[V(e[0]),e[1]])),pl={Cup:Vc,Cap:Hc,Setminus:Uc,SUBSET:Wc,UNION:Gc,DOMAIN:el,Plus:Zc,Minus:Qc,Times:V(`IntTimes`),Exp:V(`IntExp`),Quotient:V(`IntQuotient`),Remainder:V(`IntRemainder`),Uminus:V(`IntUminus`),Range:$c,Seq:J,Len:Y,BSeq:V(`BSeq`),Cat:ol,Append:sl,Head:cl,Tail:ll,SubSeq:ul},ml=(e,t)=>Array.from({length:t},(t,n)=>`${e}${n+1}`),hl=(e,t,n=`Idv`)=>`${e}${n===`Idv`?``:`:${n}`}#${t}`,gl=e=>/:(\w+)#\d+$/.exec(e)?.[1],_l=(e,t=`Idv`)=>e.map(e=>`(${e} ${gl(e)??t})`).join(` `),vl=(e,t,n=[],r=`Idv`)=>e.length===0?t:`(forall (${_l(e,r)}) ${n.length===0?t:`(! ${t} ${n.map(e=>`:pattern (${e.join(` `)})`).join(` `)})`})`,yl=e=>e.length===0?`true`:e.length===1?e[0]:`(and ${e.join(` `)})`,bl=e=>e.length===0?`false`:e.length===1?e[0]:`(or ${e.join(` `)})`,X=(e,t)=>t.length===0?e:`(${e} ${t.join(` `)})`,xl=(e,t,n=`Idv`,r=`Idv`)=>`(declare-fun ${e} (${Array.from({length:t},()=>r).join(` `)}) ${n})`,Sl=(e,t)=>{let n=0;for(let r=t;r<e.length;r++)if(e[r]===`(`&&n++,e[r]===`)`&&n--,n===0)return r;return e.length},Cl=(e,t)=>e.replace(/[^\s()]+/g,e=>t.get(e)??e),wl=(e,t,n)=>Cl(e,/* @__PURE__ */ new Map([[t,n]])),Tl=(e,t)=>{let n=[],r=t,i=0;do{let t=e[r][0];t===`(`&&i++,t===`)`&&i--,t===`(`&&i===2&&n.push(r+1),r++}while(i>0);return{names:n,end:r-1}},El=(e,t)=>t===0?e:`${e}_${t}`,Dl=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Set;return{names:t,adjoin:n=>{let r=Pc(n),i=(e.get(r)??-1)+1,a=Array.from({length:t.size+1},(e,t)=>i+t).find(e=>!t.has(El(r,e)))??i;return{base:r,salt:a,name:El(r,a)}},enter:n=>{let r=e.get(n.base);return e.set(n.base,n.salt),t.add(n.name),()=>{t.delete(n.name),r===void 0?e.delete(n.base):e.set(n.base,r)}}}},Ol=e=>{let t=Dl();return n=>{let r=/^\(declare-fun (\S+)/.exec(n)?.[1];if(r!==void 0){let i=e.get(r);return i?t.enter(i):t.names.add(r),n}let i=[...n.matchAll(/\|[^|]*\||[()]|[^\s()|]+/g)],a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=[],c=/* @__PURE__ */ new Map,l=0,u=0;for(;l<i.length;){let e=i[l][0];if(e===`(`&&i[l+1]?.[0]===`let`){let e=Tl(i,l+2);c.set(e.end,{depth:u+1,names:e.names})}if(e===`(`&&(i[l+1]?.[0]===`forall`||i[l+1]?.[0]===`exists`)&&i[l+2]?.[0]===`(`){u++;let e={depth:u,exits:[]};for(s.push(e),l+=3;i[l]?.[0]===`(`;){let n=i[l+1][0],r=t.adjoin(n.replace(/(:\w+)?#\d+$/,``)),s=o.get(n)??[];o.set(n,[...s,r.name]),e.exits.push(t.enter(r),()=>o.set(n,s)),a.set(l+1,r.name),l+=4}l++;continue}e===`(`&&u++,e===`)`&&(s.at(-1)?.depth===u&&s.pop()?.exits.toReversed().forEach(e=>e()),u--);let n=o.get(e)?.at(-1);n!==void 0&&a.set(l,n);let r=c.get(l);if(r!==void 0){let e={depth:r.depth,exits:[]};r.names.toReversed().forEach(n=>{let r=i[n][0],s=t.adjoin(r.replace(/(:\w+)?#\d+$/,``)),c=o.get(r)??[];o.set(r,[...c,s.name]),e.exits.push(t.enter(s),()=>o.set(r,c)),a.set(n,s.name)}),s.push(e)}l++}return i.map((e,t)=>{let r=i[t+1]?.index??n.length;return`${a.get(t)??e[0]}${n.slice(e.index+e[0].length,r)}`}).join(``)}},kl=e=>e.kind===`Apply`&&e.operator.kind===`Internal`?e.operator.builtin:void 0,Z=(e,t)=>A(e,t,{}),Al=e=>({kind:`Ix`,index:e}),jl={kind:`NoDomain`},Ml=e=>({name:e,level:`Constant`,domain:jl}),Nl=(e,t)=>it(e,t,`all`),Pl=e=>{let t=ot(e,Pl);return t.kind!==`Apply`||kl(t)!==`Notmem`?t:k(Z(`Neg`,[Z(`Mem`,t.args)]),t)},Fl=e=>{let t=e.bounds.length,n=e.bounds.reduce((e,n)=>n.domain.kind===`Domain`?[...e,I(t,Ll(n.domain.expression))]:[...e,n.domain.kind===`Ditto`?e.at(-1):void 0],[]).flatMap((e,n)=>e===void 0?[]:[Z(`Mem`,[Al(t-n),e])]),r=Ll(e.body),i=e.bounds.map(e=>({...e,domain:jl}));if(n.length===0)return{...e,bounds:i,body:r};let a=e.quantifier===`Exists`?{kind:`List`,bullet:`And`,items:[...n,r]}:Z(`Implies`,[n.length===1?n[0]:{kind:`List`,bullet:`And`,items:n},r]);return{...e,bounds:i,body:a}},Il=e=>{let t=e.context.reduce((e,t)=>{if(t.kind!==`Fresh`||t.domain===void 0){let n=gt(e.substitution,t);return{substitution:ut(1,e.substitution),context:[...e.context,Nl(n,Ll)]}}let n=Ll(F(e.substitution,t.domain)),r={kind:`Fact`,expression:Z(`Mem`,[Al(1),I(1,n)]),visibility:t.domainVisibility,time:`Now`};return{substitution:{kind:`Compose`,outer:P(1),inner:ut(1,e.substitution)},context:[...e.context,{...t,domain:void 0},r]}},{substitution:P(0),context:[]});return{context:t.context,active:Ll(F(t.substitution,e.active))}},Ll=e=>{if(e.kind===`Quant`)return Fl(e);if(e.kind===`Sequent`)return{...e,sequent:Il(e.sequent)};if(e.kind===`Choose`&&e.domain!==void 0){let t=Z(`Mem`,[Al(1),I(1,Ll(e.domain))]);return{...e,domain:void 0,body:Z(`Conj`,[t,Ll(e.body)])}}return ot(e,Ll)},Rl=e=>{switch(e.kind){case`SetEnum`:case`SetSt`:case`SetOf`:case`Product`:case`Arrow`:case`Rect`:return!0;case`Internal`:return[`STRING`,`BOOLEAN`,`Nat`,`Int`].includes(e.builtin);case`Apply`:return e.args.length===2&&[`Cap`,`Cup`,`Setminus`,`Range`].includes(kl(e)??``);default:return!1}},zl=e=>e===`Positive`?`Negative`:e===`Negative`?`Positive`:`Neither`,Bl=(e,t,n)=>({kind:`Quant`,quantifier:`Forall`,bounds:[Ml(`x`)],body:Z(e,[Z(`Mem`,[Al(1),I(1,t)]),Z(`Mem`,[Al(1),I(1,n)])])}),Vl=(e,t,n)=>{if(n.kind===`Sequent`){let r=n.sequent,i=r.context.map(n=>Nl(n,n=>e(zl(t),n)));return{...n,sequent:{context:i,active:e(t,r.active)}}}if(n.kind!==`Apply`)return ot(n,n=>e(t,n));let r=n.args;switch(kl(n)){case`Implies`:return{...n,args:[e(zl(t),r[0]),e(t,r[1])]};case`Equiv`:return k(Z(`Conj`,[Z(`Implies`,[e(zl(t),r[0]),e(t,r[1])]),Z(`Implies`,[e(zl(t),r[1]),e(t,r[0])])]),n);case`Neg`:return{...n,args:[e(zl(t),r[0])]};default:return{...n,args:r.map(t=>e(`Neither`,t))}}},Hl=(e,t)=>{if(t.kind===`Apply`&&t.args.length===2){let n=t.args[0],r=t.args[1],i=Rl(n)||Rl(r),a=kl(t);if(a===`Eq`&&e===`Positive`&&i)return k(Bl(`Equiv`,Hl(e,n),Hl(e,r)),t);if(a===`Neq`&&e===`Negative`&&i)return k(Z(`Neg`,[Bl(`Equiv`,Hl(e,n),Hl(e,r))]),t);if(a===`Subseteq`&&e===`Positive`)return k(Bl(`Implies`,Hl(e,n),Hl(e,r)),t);if(a===`Conj`||a===`Disj`)return{...t,args:[Hl(e,n),Hl(e,r)]}}return Vl(Hl,e,t)},Ul=(e,t,n)=>{let r=t=>Wl(e,t),i=(e,t)=>Z(`Mem`,[e,t]);switch(n.kind){case`SetEnum`:{if(n.elements.length===0)return{kind:`Internal`,builtin:`FALSE`};let e=r(t),i=n.elements.map(t=>Z(`Eq`,[e,r(t)]));return i.length===1?i[0]:{kind:`List`,bullet:`Or`,items:i}}case`SetSt`:{let e=r(t),a=r(n.domain),o=r(n.body);return Z(`Conj`,[i(e,a),F(ct(e,P(0)),o)])}case`SetOf`:{let e=r(t),a=n.bounds.map(e=>e.domain.kind===`Domain`?r(e.domain.expression):void 0).reduce((e,t)=>[...e,t??e[e.length-1]],[]),o=n.bounds.length;return{kind:`Quant`,quantifier:`Exists`,bounds:n.bounds.map(e=>Ml(e.name)),body:{kind:`List`,bullet:`And`,items:[Z(`Eq`,[I(o,e),r(n.element)]),...a.map((e,t)=>i(Al(o-t),I(o,e)))]}}}case`Arrow`:{let e=r(t),a=r(n.domain),o=r(n.range);return{kind:`List`,bullet:`And`,items:[{kind:`Apply`,operator:{kind:`Opaque`,name:`IsAFcn`},args:[e]},Z(`Eq`,[Z(`DOMAIN`,[e]),a]),{kind:`Quant`,quantifier:`Forall`,bounds:[Ml(`x`)],body:Z(`Implies`,[i(Al(1),I(1,a)),i({kind:`FcnApp`,function:I(1,e),args:[Al(1)]},I(1,o))])}]}}case`Product`:{let e=r(t),a=n.factors.map(r),o=t=>({kind:`FcnApp`,function:e,args:[{kind:`Num`,integer:String(t+1),fraction:``}]});return{kind:`List`,bullet:`And`,items:[Z(`Eq`,[e,{kind:`Tuple`,elements:a.map((e,t)=>o(t))}]),...a.map((e,t)=>i(o(t),e))]}}case`Rect`:{let e=r(t),a=n.fields.map(e=>({name:e.name,value:r(e.value)})),o=t=>({kind:`Dot`,expression:e,field:t});return{kind:`List`,bullet:`And`,items:[Z(`Eq`,[e,{kind:`Record`,fields:a.map(e=>({name:e.name,value:o(e.name)}))}]),...a.map(e=>i(o(e.name),e.value))]}}case`Internal`:return n.builtin===`Nat`?Z(`Conj`,[i(r(t),{kind:`Internal`,builtin:`Int`}),Z(`Lteq`,[{kind:`Num`,integer:`0`,fraction:``},r(t)])]):void 0;case`Apply`:{let e=n.args,a=kl(n);if(a===`SUBSET`&&e.length===1)return{kind:`Quant`,quantifier:`Forall`,bounds:[Ml(`v`)],body:Z(`Implies`,[i(Al(1),I(1,r(t))),i(Al(1),I(1,r(e[0])))])};if(a===`UNION`&&e.length===1)return{kind:`Quant`,quantifier:`Exists`,bounds:[Ml(`v`)],body:Z(`Conj`,[i(Al(1),I(1,r(e[0]))),i(I(1,r(t)),Al(1))])};if(e.length!==2)return;let o=r(t);return a===`Cup`?Z(`Disj`,[i(o,r(e[0])),i(o,r(e[1]))]):a===`Cap`?Z(`Conj`,[i(o,r(e[0])),i(o,r(e[1]))]):a===`Setminus`?Z(`Conj`,[i(o,r(e[0])),Z(`Neg`,[i(o,r(e[1]))])]):a===`Range`?{kind:`List`,bullet:`And`,items:[i(o,{kind:`Internal`,builtin:`Int`}),Z(`Lteq`,[r(e[0]),o]),Z(`Lteq`,[o,r(e[1])])]}:void 0}default:return}},Wl=(e,t)=>{if(t.kind===`Apply`&&t.args.length===2){let n=t.args[0],r=t.args[1],i=kl(t),a=i===`Mem`?Ul(e,n,r):void 0;if(a!==void 0)return k(a,t);let o=Rl(n)||Rl(r);if(i===`Eq`&&e===`Positive`&&o)return k(Bl(`Equiv`,Wl(e,n),Wl(e,r)),t);if(i===`Neq`&&e===`Negative`&&o)return k(Z(`Neg`,[Bl(`Equiv`,Wl(e,n),Wl(e,r))]),t);if(i===`Subseteq`&&e===`Positive`)return k(Bl(`Implies`,Wl(e,n),Wl(e,r)),t)}return Vl(Wl,e,t)},Gl=(e,t)=>{if(t===0)return e;let n=Il({context:e.context.map(e=>Nl(e,Pl)),active:Pl(e.active)}),r={kind:`Sequent`,sequent:n},i=t===1?Hl(`Positive`,r):Array.from({length:10}).reduce(e=>Wl(`Positive`,e),r);return i.kind===`Sequent`?i.sequent:n},Kl=e=>{let t=e.match(/\|[^|]*\||[()]|[^\s()|]+/g)??[],n=[[]];return t.forEach(e=>{if(e===`(`)n.push([]);else if(e===`)`){let e=n.pop()??[];n.at(-1)?.push(e)}else n.at(-1)?.push(e)}),n[0][0]},ql=e=>typeof e==`string`?e:`(${e.map(ql).join(` `)})`,Jl=(...e)=>[z(`@[<hov2>(`),e,z(`@])`)],Yl=e=>z(`@[<hov0>%a@]`,e),Xl=e=>e.flatMap((e,t)=>t===0?[e]:[z(`@ `),e]),Zl=e=>Array.isArray(e)?e:[],Ql=e=>e.flatMap((t,n)=>{if(n%2==1)return[];let r=e[n+1]??``;return t===`:pattern`?[[R(`:pattern `),Jl(Xl(Zl(r).map($l)))]]:[R(`${ql(t)} ${ql(r)}`)]}),$l=e=>Yl(eu(e)),eu=e=>{if(typeof e==`string`)return R(e);let t=ql(e[0]),n=e.slice(1);return t===`forall`||t===`exists`?Jl(R(t),z(`@ `),Jl(Xl(Zl(n[0]).map(e=>R(ql(e))))),z(`@ `),$l(n[1])):t===`let`?Jl(R(`let `),Jl(Xl(Zl(n[0]).map(e=>{let t=Zl(e);return[R(`(${ql(t[0])} `),eu(t[1]),R(`)`)]}))),z(`@ `),$l(n[1])):t===`!`?Jl(R(`!`),z(`@ `),$l(n[0]),z(`@ `),Xl(Ql(n.slice(1)))):Jl(R(t),z(`@ `),Xl(n.map($l)))},tu=e=>{let t=Zl(Kl(e)),n=t[0];return n===`declare-fun`?en(Jl(R(`declare-fun ${ql(t[1])} (`),Xl(Zl(t[2]).map(e=>R(ql(e)))),R(`) ${ql(t[3])}`))):n===`assert`?en(Jl(R(`assert`),z(`@ `),$l(t[1]))):e},nu=/* @__PURE__ */ `ChooseDef.ChooseExt.SetExt.SubsetEqDef.SubsetEqIntro.SubsetEqElim.UnionDef.UnionIntro.UnionElim.SubsetDef.SubsetDefAlt.SubsetIntro.SubsetElim.CupDef.CapDef.SetMinusDef.SetStDef.NatSetDef.IntPlusTyping.IntUminusTyping.IntMinusTyping.IntTimesTyping.IntQuotientTyping.IntRemainderTyping.IntExpTyping.NatPlusTyping.NatTimesTyping.IntRangeDef.NonNegIsPos.LteqReflexive.LteqTransitive.LteqAntisym.FunExt.FunConstrIsafcn.FunSetDef.FunSetIntro.FunSetElim1.FunSetElim2.FunSetImIntro.FunSetSubs.FunDomDef.FunAppDef.FunTyping.FunExceptIsafcn.FunExceptDomDef.FunExceptAppDef1.FunExceptAppDef2.FunExceptTyping.FunImDef.FunImIntro.FunImElim.SeqSetIntro.SeqSetElim1.SeqSetElim2.SeqLenDef.SeqCatTyping.SeqCatLen.SeqCatApp1.SeqCatApp2.SeqAppendTyping.SeqAppendLen.SeqAppendApp1.SeqAppendApp2.SeqHeadDef.SeqTailTyping.SeqTailLen.SeqTailApp.SeqSubseqTyping.SeqSubseqLen.SeqSubseqApp.SeqSelectseqTyping.SeqSelectseqLen.SeqSelectseqNil.SeqSelectseqApp.SeqSelectseqAppend.DisjointTrigger.EmptyComprehensionTrigger.CompareSetOfTrigger`.split(`.`),ru=/* @__PURE__ */ `EnumDef.EnumDefIntro.EnumDefElim.SetOfDef.SetOfIntro.SetOfElim.StrLitIsstr.StrLitDistinct.IntLitIsint.IntLitDistinct.IntLitZeroCmp.TupIsafcn.TupDomDef.TupAppDef.TupExcept.ProductDef.ProductIntro.ProductElim.RecIsafcn.RecDomDef.RecAppDef.RecExcept.RecSetDef.RecSetIntro.RecSetElim.SeqTupTyping.SeqTupLen.CastInj.CastInjAlt.TypeGuard.TypeGuardIntro.TypeGuardElim.Typing.ExtTrigEqDef.ExtTrigEqTrigger.AssertIsSetOf`.split(`.`),iu=[`TIntPlus`,`TIntUminus`,`TIntMinus`,`TIntTimes`,`TIntQuotient`,`TIntRemainder`,`TIntLteq`],Q=(e,t,n,r)=>({name:e,args:t,label:r??[e,...t.flat()].join(` `),formula:n}),au=e=>`${e.name} ${JSON.stringify(e.args)}`,ou=e=>{let t=nu.indexOf(e.name);return t===-1?nu.length+ru.indexOf(e.name):t},su=(e,t)=>ou(e)-ou(t)||Mc(e.args,t.args),cu={IntPlus:[`+`,2],IntMinus:[`-`,2],IntTimes:[`*`,2],IntUminus:[`-`,1],IntQuotient:[`div`,2],IntRemainder:[`mod`,2],IntLteq:[`<=`,2]},lu=e=>{let t=cu[e][0],n=t===`div`||t===`mod`,r=cu[e][1]===1?[`x1`]:n?[`x`,`y`]:[`x1`,`x2`],i=X(V(e),r.map(e=>`(${G} ${e})`)),a=`(= ${i} ${t===`<=`?`(<= ${r.join(` `)})`:`(${G} (${t} ${r.join(` `)}))`})`;return Q(`Typing`,[iu.indexOf(`T${e}`)],vl(r,n?`(=> (> y 0) ${a})`:a,[[i]],`Int`),`Typing T${e}`)},uu=e=>{let t=V(`SetEnum_${e}`),n=ml(`a`,e),r=X(t,n),i=Q(`EnumDefElim`,[e],vl([...n,`x`],e===0?`(not (${H} x ${r}))`:`(=> (${H} x ${r}) ${bl(n.map(e=>`(= x ${e})`))})`,[[`(${H} x ${r})`]]));return e===0?[i]:[Q(`EnumDefIntro`,[e],vl(n,yl(n.map(e=>`(${H} ${e} ${r})`)),[[r]])),i]},du=(e,t)=>t?`(${G} ${e})`:V(`IntLit_${e}`),fu=(e,t)=>Array.from({length:e},(e,n)=>du(n+1,t)),pu=e=>e.map(e=>V(`StrLit_${e}`)),mu=(e,t,n,r)=>{let i=ml(`x`,r.length);return r.map((r,a)=>{let o=`(${rl} ${X(n,i)} ${r} x)`,s=i.map((e,t)=>t===a?`x`:e);return Q(`${e}Except`,[...t,a+1],vl([...i,`x`],`(= ${o} ${X(n,s)})`,[[o]]))})},hu=(e,t)=>mu(`Tup`,[e],V(`Tuple_${e}`),fu(e,t)),gu=e=>mu(`Rec`,[e],V(`Record_${e.join(`_`)}`),pu(e)),_u=(e,t,n,r)=>{let i=ml(`x`,r.length),a=X(n,i),o=Q(`${e}Isafcn`,t,vl(i,`(${tl} ${a})`,[[a]]));return r.length===0?[o]:[o,Q(`${e}DomDef`,t,vl(i,`(= (${el} ${a}) ${X(V(`SetEnum_${r.length}`),r)})`,[[a]])),Q(`${e}AppDef`,t,vl(i,yl(r.map((e,t)=>`(= (${q} ${a} ${e}) ${i[t]})`)),[[a]]))]},vu=(e,t,n)=>{let r=V(`Tuple_${e}`),i=ml(`x`,e),a=X(r,i);return[..._u(`Tup`,[e],r,fu(e,n)),Q(`SeqTupTyping`,[e],vl([`a`,...i],e===0?`(${H} ${a} (${J} a))`:`(=> ${yl(i.map(e=>`(${H} ${e} a)`))} (${H} ${a} (${J} a)))`,[[...i.map(e=>`(${H} ${e} a)`),a]])),Q(`SeqTupLen`,[e],vl(i,`(= (${Y} ${a}) ${du(e,n)})`,[[a]])),...t?hu(e,n):[]]},yu=(e,t)=>[..._u(`Rec`,[e],V(`Record_${e.join(`_`)}`),pu(e)),...t?gu(e):[]],bu=(e,t,n,r,i,a)=>{let o=ml(`s`,i.length),s=ml(`x`,i.length),c=X(n,o),l=X(r,s),u=i.map(e=>`(${q} ${a} ${e})`);return[Q(`${e}Intro`,t,vl([...o,...s],`(=> ${yl(s.map((e,t)=>`(${H} ${e} ${o[t]})`))} (${H} ${l} ${c}))`,[[l,c]])),Q(`${e}Elim`,t,vl([...o,a],`(=> (${H} ${a} ${c}) ${yl([`(= ${a} ${X(r,u)})`,...u.map((e,t)=>`(${H} ${e} ${o[t]})`)])})`,[[`(${H} ${a} ${c})`]]))]},xu=V(`IntLit_0`),Su=V(`IntLit_1`),Cu=[`Mem`,`Seq`,`Len`,`FunApp`,`IntSet`,`NatSet`,`IntPlus`,`IntLteq`],wu=(e,t,n)=>Q(e,[],`(forall ((x Idv) (y Idv)) (! (=> (and (${H} x ${n}) (${H} y ${n})) (${H} (${t} x y) ${n})) :pattern ((${t} x y))))`),Tu=e=>{let t=V(e),n=(e,n,r,i=`Idv`)=>({declaration:xl(t,e,i),deps:n,axioms:r});switch(e){case`NatSet`:return n(0,[`IntSet`,`IntLit_0`,`IntLteq`],[Q(`NatSetDef`,[],`(forall ((x Idv)) (! (= (${H} x ${W}) (and (${H} x ${U}) (${K} ${xu} x))) :pattern ((${H} x ${W}))))`)]);case`IntPlus`:case`IntTimes`:{let r=e===`IntPlus`?`Plus`:`Times`;return n(2,[`Mem`,`IntSet`,`NatSet`],[wu(`Int${r}Typing`,t,U),wu(`Nat${r}Typing`,t,W)])}case`IntMinus`:return n(2,[`Mem`,`IntSet`],[wu(`IntMinusTyping`,t,U)]);case`IntUminus`:return n(1,[`Mem`,`IntSet`],[Q(`IntUminusTyping`,[],`(forall ((x Idv)) (! (=> (${H} x ${U}) (${H} (${t} x) ${U})) :pattern ((${t} x))))`)]);case`IntQuotient`:case`IntRemainder`:{let r=e===`IntQuotient`;return n(2,r?[`Mem`,`IntSet`,`NatSet`,`IntLteq`,`IntLit_0`]:[`Mem`,`IntSet`,`NatSet`,`IntLteq`,`IntLit_0`,`IntLit_1`,`IntRange`,`IntMinus`],[Q(`${e}Typing`,[],`(forall ((x Idv) (y Idv)) (! (=> (and (${H} x ${U}) (${H} y ${W}) (${K} ${xu} y)) (${H} (${t} x y) ${r?W:`(${$c} ${xu} (${Qc} y ${Su}))`})) :pattern ((${t} x y))))`)])}case`IntExp`:return n(2,[`Mem`,`IntSet`,`IntLteq`,`IntLit_0`,`IntLit_1`],[Q(`IntExpTyping`,[],`(forall ((x Idv) (y Idv)) (! (=> (and (${H} x ${U}) (${H} y ${U}) (${K} ${xu} y) (or (distinct x ${xu}) (${K} ${Su} y))) (${H} (${t} x y) ${U})) :pattern ((${t} x y))))`)]);case`IntLteq`:return n(2,[`Mem`,`IntSet`],[Q(`LteqReflexive`,[],`(forall ((x Idv)) (=> (${H} x ${U}) (${K} x x)))`),Q(`LteqTransitive`,[],`(forall ((x Idv) (y Idv) (z Idv)) (=> (and (${H} x ${U}) (${H} y ${U}) (${H} z ${U}) (${K} x y) (${K} y z)) (${K} x z)))`),Q(`LteqAntisym`,[],`(forall ((x Idv) (y Idv)) (=> (and (${H} x ${U}) (${H} y ${U}) (${K} x y) (${K} y x)) (= x y)))`)],`Bool`);case`Seq`:return n(1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`IntLteq`,`IntLit_1`],[Q(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${tl} s) (${H} (${Y} s) ${W}) (forall ((i Idv)) (= (${H} i (${el} s)) (and (${H} i ${U}) (${K} ${Su} i) (${K} i (${Y} s))))) (forall ((i Idv)) (=> (and (${H} i ${U}) (${K} ${Su} i) (${K} i (${Y} s))) (${H} (${q} s i) a)))) (${H} s (${J} a))) :pattern ((${H} s (${J} a)))))`),Q(`SeqSetElim1`,[],`(forall ((a Idv) (s Idv)) (! (=> (${H} s (${J} a)) (and (${tl} s) (${H} (${Y} s) ${W}) (= (${el} s) (${$c} ${Su} (${Y} s))))) :pattern ((${H} s (${J} a)))))`,`SetSetElim1`),Q(`SeqSetElim2`,[],`(forall ((a Idv) (s Idv) (i Idv)) (! (=> (and (${H} s (${J} a)) (${H} i ${U}) (${K} ${Su} i) (${K} i (${Y} s))) (${H} (${q} s i) a)) :pattern ((${H} s (${J} a)) (${q} s i))))`,`SetSetElim2`)]);case`Len`:return n(1,[`Mem`,`FunDom`,`IntRange`,`NatSet`,`IntLit_1`],[Q(`SeqLenDef`,[],`(forall ((s Idv) (z Idv)) (=> (and (${H} z ${W}) (= (${el} s) (${$c} ${Su} z))) (= (${Y} s) z)))`)]);case`Cat`:return n(2,[...Cu,`IntLit_1`],[Q(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${H} s (${J} a)) (${H} t (${J} a))) (${H} (${ol} s t) (${J} a))) :pattern ((${H} s (${J} a)) (${ol} s t)) :pattern ((${H} t (${J} a)) (${ol} s t))))`),Q(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${H} (${Y} s) ${W}) (${H} (${Y} t) ${W})) (= (${Y} (${ol} s t)) (${Zc} (${Y} s) (${Y} t)))) :pattern ((${ol} s t))))`),Q(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Idv)) (! (=> (and (${H} (${Y} s) ${W}) (${H} (${Y} t) ${W}) (${H} i ${U}) (${K} ${Su} i) (${K} i (${Y} s))) (= (${q} (${ol} s t) i) (${q} s i))) :pattern ((${q} (${ol} s t) i)) :pattern ((${ol} s t) (${q} s i))))`),Q(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Idv)) (! (=> (and (${H} (${Y} s) ${W}) (${H} (${Y} t) ${W}) (${H} i ${U}) (${K} i (${Zc} (${Y} s) (${Y} t))) (${K} (${Y} s) i) (distinct (${Y} s) i)) (= (${q} (${ol} s t) i) (${q} t (${Qc} i (${Y} s))))) :pattern ((${q} (${ol} s t) i))))`)]);case`Append`:return n(2,[...Cu,`IntLit_1`],[Q(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${H} s (${J} a)) (${H} x a)) (${H} (${sl} s x) (${J} a))) :pattern ((${H} s (${J} a)) (${sl} s x))))`),Q(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${H} (${Y} s) ${W}) (= (${Y} (${sl} s x)) (${Zc} (${Y} s) ${Su}))) :pattern ((${sl} s x))))`),Q(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Idv)) (! (=> (and (${H} (${Y} s) ${W}) (${H} i ${U}) (${K} ${Su} i) (${K} i (${Y} s))) (= (${q} (${sl} s x) i) (${q} s i))) :pattern ((${q} (${sl} s x) i)) :pattern ((${sl} s x) (${q} s i))))`),Q(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${H} (${Y} s) ${W}) (= (${q} (${sl} s x) (${Zc} (${Y} s) ${Su})) x)) :pattern ((${sl} s x))))`)]);case`Head`:return n(1,[`FunApp`,`IntLit_1`],[Q(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${cl} s) (${q} s ${Su})) :pattern ((${cl} s))))`)]);case`Tail`:return n(1,[...Cu,`IntMinus`,`IntLit_0`,`IntLit_1`],[Q(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${H} s (${J} a)) (distinct (${Y} s) ${xu})) (${H} (${ll} s) (${J} a))) :pattern ((${H} s (${J} a)) (${ll} s))))`),Q(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${H} (${Y} s) ${W}) (distinct (${Y} s) ${xu})) (= (${Y} (${ll} s)) (${Qc} (${Y} s) ${Su}))) :pattern ((${ll} s))))`),Q(`SeqTailApp`,[],`(forall ((s Idv) (i Idv)) (! (=> (and (${H} (${Y} s) ${W}) (distinct (${Y} s) ${xu}) (${H} i ${U}) (${K} ${Su} i) (${K} i (${Qc} (${Y} s) ${Su}))) (= (${q} (${ll} s) i) (${q} s (${Zc} i ${Su})))) :pattern ((${q} (${ll} s) i))))`)]);case`SubSeq`:return n(3,[`Mem`,`Seq`,`Len`,`FunApp`,`IntSet`,`IntPlus`,`IntMinus`,`IntLteq`,`IntLit_0`,`IntLit_1`],[Q(`SeqSubseqTyping`,[],`(forall ((a Idv) (s Idv) (x Idv) (y Idv)) (! (=> (or (and (${H} x ${U}) (${H} y ${U}) (${K} y x) (distinct y x)) (and (${H} s (${J} a)) (${H} x ${U}) (${H} y ${U}) (${K} ${Su} x) (${K} y (${Y} s)))) (${H} (${ul} s x y) (${J} a))) :pattern ((${H} s (${J} a)) (${ul} s x y))))`),Q(`SeqSubseqLen`,[],`(forall ((s Idv) (x Idv) (y Idv)) (! (=> (and (${H} x ${U}) (${H} y ${U})) (and (=> (${K} x (${Zc} y ${Su})) (= (${Y} (${ul} s x y)) (${Qc} (${Zc} y ${Su}) x))) (=> (not (${K} x (${Zc} y ${Su}))) (= (${Y} (${ul} s x y)) ${xu})))) :pattern ((${ul} s x y))))`),Q(`SeqSubseqApp`,[],`(forall ((s Idv) (x Idv) (y Idv) (z Idv)) (! (=> (and (${H} x ${U}) (${H} y ${U}) (${H} z ${U}) (${K} ${Su} x) (${K} ${Su} z) (${K} z (${Qc} (${Zc} y ${Su}) x))) (= (${q} (${ul} s x y) z) (${q} s (${Qc} (${Zc} z x) ${Su})))) :pattern ((${q} (${ul} s x y) z))))`)]);default:return}},Eu={kind:`Idv`},Du={kind:`Bool`},Ou={kind:`Int`},ku={kind:`String`},Au=[`Idv`,`Bool`,`Int`,`Real`,`String`],ju=e=>{switch(e.kind){case`Set`:return`Set$${ju(e.element)}$`;case`Fun`:return`Fun$${ju(e.domain)}${ju(e.range)}$`;case`Product`:return`Prd$${e.items.map(ju).join(``)}$`;case`Record`:return`Rec${e.fields.map(e=>`!${e.name}${ju(e.type)}`).join(``)}$`;default:return e.kind}},Mu=(e,t)=>ju(e)===ju(t),Nu=e=>{switch(e.kind){case`Set`:return[2,Nu(e.element)];case`Fun`:return[4,Nu(e.domain),Nu(e.range)];case`Product`:return[5,e.items.map(Nu)];case`Record`:return[6,e.fields.map(e=>[e.name,Nu(e.type)])];default:return[1,Au.indexOf(e.kind)]}},Pu=e=>e?.kind===`Int`||e?.kind===`Bool`?e.kind:`Idv`,Fu=e=>e.kind===`Apply`&&e.operator.kind===`Internal`?e.operator.builtin:void 0,Iu=e=>e.reduce((e,t)=>e??t(),void 0),Lu=(e,t)=>{let n=e();if(n===void 0)return;let r=t();return r!==void 0&&Mu(n,r)?r:void 0},Ru=(e,t,n,r)=>{let i=Fu(r),a=r.kind===`Apply`?r.args:[],o=(r,i=t)=>Ru(e,i,n,r);switch(i){case`Mem`:case`Notmem`:if(a.length===2&&e.isTarget(a[0],n)&&i===`Notmem`===t){let t=e.infer(a[1],n);return t?.kind===`Set`?t.element:void 0}return;case`Eq`:case`Neq`:return a.length!==2||i===`Neq`!==t?void 0:e.isTarget(a[0],n)?e.infer(a[1],n):e.isTarget(a[1],n)?e.infer(a[0],n):void 0;case`Conj`:case`Disj`:return i===`Disj`===t?Iu(a.map(e=>()=>o(e))):Lu(()=>o(a[0]),()=>o(a[1]));case`Neg`:return o(a[0],!t);case`Implies`:return Iu([()=>o(a[0],!t),()=>o(a[1])])}switch(r.kind){case`List`:return r.bullet!==`Refs`&&r.bullet===`Or`===t?Iu(r.items.map(e=>()=>o(e))):void 0;case`Quant`:return r.quantifier===`Forall`===t?Ru(e,t,n+r.bounds.length,r.body):void 0;case`Sequent`:return t?zu(e,n,r.sequent):void 0;default:return}},zu=(e,t,n)=>Iu([...n.context.map((n,r)=>()=>n.kind===`Fact`&&n.visibility===`Visible`?Ru(e,!1,t+r,n.expression):void 0),()=>Ru(e,!0,t+n.context.length,n.active)]),Bu=(e,t,n)=>Ru(e,t,0,n),Vu={kind:`Set`,element:Eu},Hu=e=>`; omitted declaration of 'TLA__${e}' (second-order)`,Uu=e=>Array.from({length:e},(e,t)=>`IntLit_${t+1}`),Wu=[`Mem`,`Seq`,`Len`,`FunApp`,`NatSet`,`Cast_Int`,`Proj_Int`],Gu=V(`IntExp`),Ku=`(${ul} s (${G} x) (${G} y))`,qu=(e,t,n)=>({declaration:e,deps:t,axioms:n}),$=(e,t,n,r,i=`Idv`)=>qu(xl(V(e),t,i),n,r),Ju=(e,t)=>Q(`${e}Def`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${H} x (${V(e)} a b)) ${t}) :pattern ((${H} x (${V(e)} a b))) :pattern ((${H} x a) (${V(e)} a b)) :pattern ((${H} x b) (${V(e)} a b))))`),Yu=new Map(Object.entries({IntExp:$(`IntExp`,2,[`Mem`,`IntSet`,`Cast_Int`,`TIntLteq`,`TIntLit_0`,`TIntLit_1`],[Q(`IntExpTyping`,[],`(forall ((x Idv) (y Idv)) (! (=> (and (${H} x ${U}) (${H} y ${U}) (${K} (${G} 0) y) (or (distinct x (${G} 0)) (${K} (${G} 1) y))) (${H} (${Gu} x y) ${U})) :pattern ((${Gu} x y))))`)]),Choose:qu(Hu(`Choose`),[],[Q(`ChooseDef`,[],void 0)]),SubsetEq:$(`SubsetEq`,2,[`Mem`],[Q(`SubsetEqIntro`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${H} z x) (${H} z y))) (${Bc} x y)) :pattern ((${Bc} x y))))`),Q(`SubsetEqElim`,[],`(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${Bc} x y) (${H} z x)) (${H} z y)) :pattern ((${Bc} x y) (${H} z x))))`)],`Bool`),Union:$(`Union`,1,[`Mem`],[Q(`UnionIntro`,[],`(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${H} y a) (${H} x y)) (${H} x (${Gc} a))) :pattern ((${H} y a) (${H} x (${Gc} a))) :pattern ((${H} x y) (${H} x (${Gc} a))) :pattern ((${H} y a) (${H} x y) (${Gc} a))))`),Q(`UnionElim`,[],`(forall ((a Idv) (x Idv)) (! (=> (${H} x (${Gc} a)) (exists ((y Idv)) (and (${H} y a) (${H} x y)))) :pattern ((${H} x (${Gc} a)))))`)]),Subset:$(`Subset`,1,[`Mem`,`SubsetEq`],[Q(`SubsetDefAlt`,[],`(forall ((a Idv) (x Idv)) (! (= (${H} x (${Wc} a)) (${Bc} x a)) :pattern ((${H} x (${Wc} a))) :pattern ((${Bc} x a) (${Wc} a))))`)]),Cup:$(`Cup`,2,[`Mem`],[Ju(`Cup`,`(or (${H} x a) (${H} x b))`)]),SetMinus:$(`SetMinus`,2,[`Mem`],[Ju(`SetMinus`,`(and (${H} x a) (not (${H} x b)))`)]),NatSet:$(`NatSet`,0,[`IntSet`,`TIntLit_0`,`Cast_Int`,`IntLteq`],[Q(`NatSetDef`,[],`(forall ((x Idv)) (! (= (${H} x ${W}) (and (${H} x ${U}) (${K} (${G} 0) x))) :pattern ((${H} x ${W}))))`)]),IntRange:$(`IntRange`,2,[`Mem`,`IntSet`,`IntLteq`],[Q(`IntRangeDef`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${H} x (${$c} a b)) (and (${H} x ${U}) (${K} a x) (${K} x b))) :pattern ((${H} x (${$c} a b)))))`)]),FunIsafcn:$(`FunIsafcn`,1,[`Mem`,`FunDom`,`FunFcn`,`FunApp`],[Q(`FunExt`,[],`(forall ((f Idv) (g Idv)) (! (=> (and (${tl} f) (${tl} g) (= (${el} f) (${el} g)) (forall ((x Idv)) (=> (${H} x (${el} f)) (= (${q} f x) (${q} g x))))) (= f g)) :pattern ((${tl} f) (${tl} g))))`)],`Bool`),FunDom:$(`FunDom`,1,[`FunFcn`],[Q(`FunDomDef`,[],void 0)]),FunApp:$(`FunApp`,2,[`Mem`,`FunFcn`],[Q(`FunAppDef`,[],void 0)]),Seq:$(`Seq`,1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`Cast_Int`,`Proj_Int`],[Q(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${tl} s) (>= (${Xc} (${Y} s)) 0) (forall ((i Idv)) (= (${H} i (${el} s)) (and (${H} i ${U}) (<= 1 (${Xc} i)) (<= (${Xc} i) (${Xc} (${Y} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${Xc} (${Y} s)))) (${H} (${q} s (${G} i)) a)))) (${H} s (${J} a))) :pattern ((${H} s (${J} a)))))`),Q(`SeqSetElim1`,[],`(forall ((a Idv) (s Idv)) (! (=> (${H} s (${J} a)) (and (${tl} s) (${H} (${Y} s) ${W}) (= (${el} s) (${$c} (${G} 1) (${Y} s))))) :pattern ((${H} s (${J} a)))))`,`SetSetElim1`),Q(`SeqSetElim2`,[],`(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${H} s (${J} a)) (<= 1 i) (<= i (${Xc} (${Y} s)))) (${H} (${q} s (${G} i)) a)) :pattern ((${H} s (${J} a)) (${q} s (${G} i)))))`,`SetSetElim2`)]),Len:$(`Len`,1,[`FunDom`,`IntRange`,`Cast_Int`],[Q(`SeqLenDef`,[],`(forall ((s Idv) (z Int)) (=> (and (>= z 0) (= (${el} s) (${$c} (${G} 1) (${G} z)))) (= (${Y} s) (${G} z))))`)]),BSeq:$(`BSeq`,1,[],[]),Cat:$(`Cat`,2,Wu,[Q(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${H} s (${J} a)) (${H} t (${J} a))) (${H} (${ol} s t) (${J} a))) :pattern ((${H} s (${J} a)) (${ol} s t)) :pattern ((${H} t (${J} a)) (${ol} s t))))`),Q(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${H} (${Y} s) ${W}) (${H} (${Y} t) ${W})) (= (${Y} (${ol} s t)) (${G} (+ (${Xc} (${Y} s)) (${Xc} (${Y} t)))))) :pattern ((${ol} s t))))`),Q(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${H} (${Y} s) ${W}) (${H} (${Y} t) ${W}) (<= 1 i) (<= i (${Xc} (${Y} s)))) (= (${q} (${ol} s t) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${ol} s t) (${G} i))) :pattern ((${ol} s t) (${q} s (${G} i)))))`),Q(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${H} (${Y} s) ${W}) (${H} (${Y} t) ${W}) (<= i (+ (${Xc} (${Y} s)) (${Xc} (${Y} t)))) (< (${Xc} (${Y} s)) i)) (= (${q} (${ol} s t) (${G} i)) (${q} t (${G} (- i (${Xc} (${Y} s))))))) :pattern ((${q} (${ol} s t) (${G} i)))))`)]),Append:$(`Append`,2,Wu,[Q(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${H} s (${J} a)) (${H} x a)) (${H} (${sl} s x) (${J} a))) :pattern ((${H} s (${J} a)) (${sl} s x))))`),Q(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${H} (${Y} s) ${W}) (= (${Y} (${sl} s x)) (${G} (+ (${Xc} (${Y} s)) 1)))) :pattern ((${sl} s x))))`),Q(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${H} (${Y} s) ${W}) (<= 1 i) (<= i (${Xc} (${Y} s)))) (= (${q} (${sl} s x) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${sl} s x) (${G} i))) :pattern ((${sl} s x) (${q} s (${G} i)))))`),Q(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${H} (${Y} s) ${W}) (= (${q} (${sl} s x) (${G} (+ (${Xc} (${Y} s)) 1))) x)) :pattern ((${sl} s x))))`)]),Head:$(`Head`,1,[`FunApp`,`Cast_Int`],[Q(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${cl} s) (${q} s (${G} 1))) :pattern ((${cl} s))))`)]),Tail:$(`Tail`,1,Wu,[Q(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${H} s (${J} a)) (distinct (${Xc} (${Y} s)) 0)) (${H} (${ll} s) (${J} a))) :pattern ((${H} s (${J} a)) (${ll} s))))`),Q(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${H} (${Y} s) ${W}) (distinct (${Xc} (${Y} s)) 0)) (= (${Y} (${ll} s)) (${G} (- (${Xc} (${Y} s)) 1)))) :pattern ((${ll} s))))`),Q(`SeqTailApp`,[],`(forall ((s Idv) (i Int)) (! (=> (and (${H} (${Y} s) ${W}) (distinct (${Xc} (${Y} s)) 0) (<= 1 i) (<= i (- (${Xc} (${Y} s)) 1))) (= (${q} (${ll} s) (${G} i)) (${q} s (${G} (+ i 1))))) :pattern ((${q} (${ll} s) (${G} i)))))`)]),SubSeq:$(`SubSeq`,3,[`Mem`,`Seq`,`Len`,`FunApp`,`IntSet`,`Cast_Int`,`Proj_Int`],[Q(`SeqSubseqTyping`,[],`(forall ((a Idv) (s Idv) (x Int) (y Int)) (! (=> (or (< y x) (and (${H} s (${J} a)) (<= 1 x) (<= y (${Xc} (${Y} s))))) (${H} ${Ku} (${J} a))) :pattern ((${H} s (${J} a)) ${Ku})))`),Q(`SeqSubseqLen`,[],`(forall ((s Idv) (x Int) (y Int)) (! (and (=> (<= x (+ y 1)) (= (${Y} ${Ku}) (${G} (- (+ y 1) x)))) (=> (> x (+ y 1)) (= (${Y} ${Ku}) (${G} 0)))) :pattern (${Ku})))`),Q(`SeqSubseqApp`,[],`(forall ((s Idv) (x Int) (y Int) (z Int)) (! (=> (and (<= 1 x) (<= 1 z) (<= z (- (+ y 1) x))) (= (${q} ${Ku} (${G} z)) (${q} s (${G} (- (+ z x) 1))))) :pattern ((${q} ${Ku} (${G} z)))))`)]),Cast_Int:qu(xl(V(`Cast_Int`),1,`Idv`,`Int`),[`Mem`,`IntSet`,`Proj_Int`],[Q(`CastInjAlt`,[`Int`],`(forall ((x Int)) (! (= x (${Xc} (${G} x))) :pattern ((${G} x))))`),Q(`TypeGuardIntro`,[`Int`],`(forall ((z Int)) (! (${H} (${G} z) ${U}) :pattern ((${G} z))))`),Q(`TypeGuardElim`,[`Int`],`(forall ((x Idv)) (! (=> (${H} x ${U}) (= x (${G} (${Xc} x)))) :pattern ((${H} x ${U}))))`)]),Cast_Bool:qu(xl(V(`Cast_Bool`),1,`Idv`,`Bool`),[`Mem`,`BoolSet`,`Tt_Idv`],[Q(`CastInjAlt`,[`Bool`],`(and (= (${qc} true) ${Kc}) (distinct (${qc} false) ${Kc}))`),Q(`TypeGuardIntro`,[`Bool`],`(forall ((z Bool)) (! (${H} (${qc} z) ${Jc}) :pattern ((${qc} z))))`),Q(`TypeGuardElim`,[`Bool`],`(forall ((x Idv)) (! (=> (${H} x ${Jc}) (or (= x (${qc} true)) (= x (${qc} false)))) :pattern ((${H} x ${Jc}))))`)]),Proj_Int:qu(xl(V(`Proj_Int`),1,`Int`),[],[]),SetExtTrigger:$(`SetExtTrigger`,2,[],[],`Bool`),IsSetOf:$(`IsSetOf`,1,[],[],`Bool`),BoolSet:$(`BoolSet`,0,[],[]),StrSet:$(`StrSet`,0,[],[]),IntSet:$(`IntSet`,0,[],[]),Tt_Idv:$(`Tt_Idv`,0,[],[]),TIntLteq:qu(void 0,[`IntLteq`],[lu(`IntLteq`)]),TIntLt:qu(void 0,[`IntLteq`],[lu(`IntLteq`)]),TIntGteq:qu(void 0,[`IntLteq`],[lu(`IntLteq`)]),TIntGt:qu(void 0,[`IntLteq`],[lu(`IntLteq`)]),TIntPlus:qu(void 0,[`IntPlus`],[]),TIntMinus:qu(void 0,[`IntMinus`],[]),TIntTimes:qu(void 0,[`IntTimes`],[]),TIntUminus:qu(void 0,[`IntUminus`],[])})),Xu=(t,n)=>{let r=V(t),i=/^SetEnum_(\d+)$/.exec(t);if(i)return $(t,Number(i[1]),[`Mem`],uu(Number(i[1])));let a=/^SetOf_(\d+)$/.exec(t);if(a){let e=Number(a[1]),r=[Q(`SetOfIntro`,[e],void 0),Q(`SetOfElim`,[e],void 0)];return n.isSetExtensional?qu(Hu(t),[`Mem`,`IsSetOf`],[...r,Q(`AssertIsSetOf`,[e],void 0),Q(`CompareSetOfTrigger`,[],vl([`a`,`b`],`(${zc} a b)`,[[`(${al} a)`,`(${al} b)`]]))]):qu(Hu(t),[`Mem`],r)}if(t.startsWith(`StrLit_`)){let e=t.slice(7),i=n.strings.map(t=>Q(`StrLitDistinct`,[e,t],`(distinct ${r} ${V(`StrLit_${t}`)})`));return n.strings.push(e),$(t,0,[`Mem`,`StrSet`],[Q(`StrLitIsstr`,[e],`(${H} ${r} ${Yc})`),...i])}let o=/^IntLit_(\d+)$/.exec(t);if(o){let e=Number(o[1]),i=n.integers.map(t=>Q(`IntLitDistinct`,[t,e],`(distinct ${V(`IntLit_${t}`)} ${r})`));n.integers.push(e);let a=V(`IntLit_0`),s=e===0&&!n.isArithmetic;return $(t,0,[`Mem`,`IntSet`,`IntLit_0`,`IntLteq`,...s?[`IntLit_1`]:[]],[Q(`IntLitIsint`,[e],`(${H} ${r} ${U})`),Q(`IntLitZeroCmp`,[e],e===0?`(${K} ${r} ${a})`:`(${K} ${a} ${r})`),...i,...s?[Q(`NonNegIsPos`,[],`(forall ((x Idv)) (! (=> (and (${K} ${a} x) (distinct ${a} x)) (${K} ${V(`IntLit_1`)} x)) :pattern ((${K} ${a} x))))`)]:[]])}let s=/^Tuple_(\d+)$/.exec(t);if(s){let e=Number(s[1]);n.tuples.push(e);let r=n.isArithmetic?[`Cast_Int`]:e===0?[`IntLit_0`]:Uu(e),i=e===0?[`FunIsafcn`,...r,`Seq`,`Len`]:[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${e}`,...r,`Mem`,`Seq`,`Len`];return $(t,e,i,vu(e,n.isExcept,n.isArithmetic))}let c=/^Product_(\d+)$/.exec(t);if(c){let e=Number(c[1]);return $(t,e,[`Mem`,`Tuple_${e}`,`FunApp`,...n.isArithmetic?[`Cast_Int`,`Proj_Int`]:Uu(e)],bu(`Product`,[e],r,V(`Tuple_${e}`),fu(e,n.isArithmetic),`t`))}if(t.startsWith(`TrigEq_`)){let e=n.setTypes.get(t)??Vu,i=e.kind===`Set`?e.element:Eu;return $(t,2,[`SetExtTrigger`],[Q(`ExtTrigEqDef`,[Nu(e)],`(forall ((x Idv) (y Idv)) (! (= (${r} x y) (= x y)) :pattern ((${r} x y))))`,`ExtTrigEqDef ${ju(e)}`),Q(`ExtTrigEqTrigger`,[Nu(i)],`(forall ((x Idv) (y Idv)) (! (${zc} x y) :pattern ((${r} x y))))`,`ExtTrigEqTrigger ${ju(i)}`)],`Bool`)}let l=n.recordFields.get(t);if(l&&t.startsWith(`Record_`))return n.records.push(l),$(t,l.length,[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${l.length}`,...l.map(e=>`StrLit_${e}`)],yu(l,n.isExcept));if(l&&t.startsWith(`RecordSet_`)){let e=`Record_${l.join(`_`)}`;return $(t,l.length,[`Mem`,e,`FunApp`,...l.map(e=>`StrLit_${e}`)],bu(`RecSet`,[l],r,V(e),pu(l),`r`))}let u=n.anonymous.get(t);if(u!==void 0)return $(t,u,[],[]);let d=n.isArithmetic?void 0:Tu(t);if(d)return d;let f=Yu.get(t);if(f)return f;let p=cu[t];if(p)return $(t,p[1],[`Cast_Int`],[lu(t)],t===`IntLteq`?`Bool`:`Idv`);switch(t){case`SelectSeq`:return qu(Hu(t),[`Mem`,`Seq`,`Len`,`Append`,`FunApp`,`FunDom`,`IntSet`,`NatSet`,`Tuple_0`,n.isArithmetic?`Proj_Int`:`IntLteq`],[Q(`SeqSelectseqTyping`,[],void 0),Q(`SeqSelectseqLen`,[],void 0),Q(`SeqSelectseqNil`,[],void 0),Q(`SeqSelectseqApp`,[],void 0),Q(`SeqSelectseqAppend`,[],void 0)]);case`Mem`:return n.isSetExtensional?$(`Mem`,2,[`SetExtTrigger`],[Q(`SetExt`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (= (${H} z x) (${H} z y))) (= x y)) :pattern ((${zc} x y))))`)],`Bool`):$(t,2,[],[],`Bool`);case`Cap`:return n.isSetExtensional?$(`Cap`,2,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[Ju(`Cap`,`(and (${H} x a) (${H} x b))`),Q(`DisjointTrigger`,[],`(forall ((x Idv) (y Idv)) (! (${zc} (${Hc} x y) ${V(`SetEnum_0`)}) :pattern ((${Hc} x y))))`)]):$(t,2,[`Mem`],[Ju(`Cap`,`(and (${H} x a) (${H} x b))`)]);case`SetSt`:return n.isSetExtensional?qu(Hu(t),[`Mem`,`SetEnum_0`,`SetExtTrigger`],[Q(`SetStDef`,[],void 0),Q(`EmptyComprehensionTrigger`,[],void 0)]):qu(Hu(t),[`Mem`],[Q(`SetStDef`,[],void 0)]);case`FunSet`:return n.isFunSet=!0,$(t,2,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[Q(`FunSetIntro`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (and (${tl} f) (= (${el} f) a) (forall ((x Idv)) (=> (${H} x a) (${H} (${q} f x) b)))) (${H} f (${nl} a b))) :pattern ((${H} f (${nl} a b)))))`),Q(`FunSetElim1`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (${H} f (${nl} a b)) (and (${tl} f) (= (${el} f) a))) :pattern ((${H} f (${nl} a b)))))`),Q(`FunSetElim2`,[],`(forall ((a Idv) (b Idv) (f Idv) (x Idv)) (! (=> (and (${H} f (${nl} a b)) (${H} x a)) (${H} (${q} f x) b)) :pattern ((${H} f (${nl} a b)) (${H} x a)) :pattern ((${H} f (${nl} a b)) (${q} f x))))`),...n.isFunConstr?[Q(`FunTyping`,[],void 0)]:[]]);case`FunFcn`:return n.isFunConstr=!0,qu(Hu(t),[`FunIsafcn`],[Q(`FunConstrIsafcn`,[],void 0),...n.isFunSet?[Q(`FunTyping`,[],void 0)]:[]]);case`FunExcept`:{n.isExcept=!0;let e=`(${rl} f x y)`;return $(t,3,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[Q(`FunExceptIsafcn`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (${tl} ${e}) :pattern (${e})))`),Q(`FunExceptDomDef`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (= (${el} ${e}) (${el} f)) :pattern (${e})))`),Q(`FunExceptAppDef1`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (=> (${H} x (${el} f)) (= (${q} ${e} x) y)) :pattern (${e})))`),Q(`FunExceptAppDef2`,[],`(forall ((f Idv) (x Idv) (y Idv) (z Idv)) (! (=> (${H} z (${el} f)) (and (=> (= z x) (= (${q} ${e} z) y)) (=> (distinct z x) (= (${q} ${e} z) (${q} f z))))) :pattern ((${q} ${e} z)) :pattern (${e} (${q} f z))))`),...n.tuples.flatMap(e=>hu(e,n.isArithmetic)),...n.records.flatMap(gu)])}default:if(t.startsWith(`TIntLit_`))return qu(void 0,[],[]);throw new e.B(`the symbol ${t}`)}},Zu=e=>Number(e.slice(e.lastIndexOf(`#`)+1)),Qu=`?unprimable`,$u=e=>{let t=e.indexOf(`(${Qu} `);if(t===-1)return e;let n=Sl(e,t);return e.slice(0,t)+$u(e.slice(t+11+2,n))+$u(e.slice(n+1))},ed=(e,t)=>/\((forall|exists|ite|let) /.test(e)?void 0:e.replace(/[^\s()]+#(\d+)/g,(e,n)=>Number(n)<t?`#`:`#${Number(n)-t}`),td=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n=0,r=[];return{flattened:e,flatten:(i,a,o,s,c,l=`TLA__${i}`)=>{if(o.isOmitted){let t=Pc(`${l}_omitted_${e.size}`);return e.set(t,{symbol:t,kind:i,visit:$u(a),getLines:()=>[]}),t}let u=ed(`${l} ${a}`,o.depth);n++;let d=u===void 0?void 0:t.get(u);if(d)return d.symbol;let f=`${l}_flatnd_${n}`,p=Pc(f),m={symbol:p,kind:i,visit:$u(a),getLines:e=>[`(declare-fun ${p} (${c.join(` `)}) Idv)`,...s(p,e).map(e=>`(assert (! ${$u(e.formula??``)} :named |${e.label} ${f}|))`)]};return u!==void 0&&t.set(u,m),e.set(p,m),r.push(m),p},takeIntroduced:()=>r.splice(0)}},nd=`?trigger`,rd=/* @__PURE__ */ new Set([Gc,Wc,Vc,Hc,Uc,$c,nl,J]),id=e=>{let t=/^\(?([^\s()]+)/.exec(e)?.[1]??``;return rd.has(t)||/^smt__TLA____(SetEnum__\d+|SetSt__flatnd__\d+|SetOf__\d+__flatnd__\d+|Product__\d+|RecordSet__)/.test(t)},ad=(e,t)=>{let n=e.indexOf(`(${nd} `);if(n===-1)return e;let r=n+8+2,i=Sl(e,r)+1,a=Sl(e,i+1)+1,o=t?e.slice(r,i):e.slice(i+1,a);return e.slice(0,n)+o+ad(e.slice(a+1),t)},od=(e,t,n,r,i)=>{let a=`(${i??il} ${e} ${t})`,o=r?`(distinct ${e} ${t})`:`(= ${e} ${t})`;if(n===void 0||i===void 0&&!id(e)&&!id(t))return o;let s=r?`(not ${a})`:a;return n===(r?`Positive`:`Negative`)?`(${nd} ${s} ${o})`:s},sd=(e,t,n,r)=>{let i=X(e,[`a`,...t]);return[Q(`SetStDef`,[],vl([...t,`a`,`x`],`(= (${H} x ${i}) (and (${H} x a) ${wl(n,r,`x`)}))`,[[`(${H} x ${i})`],[`(${H} x a)`,i]]))]},cd=(e,t,n,r)=>{let i=r.length,a=ml(`a`,i),o=ml(`y`,i),s=r.reduce((e,t,n)=>wl(e,t,o[n]),n),c=X(e,[...a,...t]),l=o.map((e,t)=>`(${H} ${e} ${a[t]})`),u=i===1?[`a`]:a,d=X(e,[...u,...t]);return[Q(`SetOfIntro`,[i],vl([...t,...a,...o],`(=> ${yl(l)} (${H} ${s} ${c}))`,[[s,c],[c,...l]])),Q(`SetOfElim`,[i],vl([...t,...a,`x`],`(=> (${H} x ${c}) (exists (${_l(o)}) ${yl([...l,`(= x ${s})`])}))`,[[`(${H} x ${c})`]])),Q(`AssertIsSetOf`,[i],vl([...t,...u],`(${al} ${d})`,[[d]]))]},ld=(e,t,n,r,i)=>{let a=X(e,[`a`,...t]),o=wl(n,r,`x`),s=i.has(au(Q(`FunTyping`,[],void 0)))?[Q(`FunTyping`,[],vl([...t,`a`,`b`],`(=> (forall ((x Idv)) (=> (${H} x a) (${H} ${o} b))) (${H} ${a} (${nl} a b)))`,[[a,`(${nl} a b)`]]))]:[];return[Q(`FunConstrIsafcn`,[],vl([...t,`a`],`(${tl} ${a})`,[[a]])),Q(`FunDomDef`,[],vl([...t,`a`],`(= (${el} ${a}) a)`,[[a]])),Q(`FunAppDef`,[],vl([...t,`a`,`x`],`(=> (${H} x a) (= (${q} ${a} x) ${o}))`,[[`(${q} ${a} x)`],[`(${H} x a)`,a]])),...s]},ud=(e,t,n,r)=>[Q(`ChooseDef`,[],vl([...t,`x`],`(=> ${wl(n,r,`x`)} ${wl(n,r,X(e,t))})`))],dd=(e,t,n,r,i)=>{let a=n=>X(e,[n,...t]),o=e=>wl(n,r,e),s=a(`(${sl} s x)`);return[Q(`SeqSelectseqTyping`,[],vl([...t,`a`,`s`],`(=> (${H} s (${J} a)) (${H} ${a(`s`)} (${J} a)))`,[[`(${H} s (${J} a))`,a(`s`)]])),Q(`SeqSelectseqLen`,[],vl([...t,`s`],`(=> (${H} (${Y} s) ${W}) ${i?`(<= (${Xc} (${Y} ${a(`s`)})) (${Xc} (${Y} s)))`:`(${K} (${Y} ${a(`s`)}) (${Y} s))`})`,[[a(`s`)]])),Q(`SeqSelectseqNil`,[],vl(t,`(= ${a(dl)} ${dl})`)),Q(`SeqSelectseqApp`,[],vl([...t,`s`,`x`],`(=> (${H} x (${el} ${a(`s`)})) ${o(`(${q} ${a(`s`)} x)`)})`,[[`(${q} ${a(`s`)} x)`]])),Q(`SeqSelectseqAppend`,[],vl([...t,`s`,`x`],`(and (=> ${o(`x`)} (= ${s} (${sl} ${a(`s`)} x))) (=> (not ${o(`x`)}) (= ${s} ${a(`s`)})))`,[[s]]))]},fd=/* @__PURE__ */ new Set([`Prime`,`StrongPrime`,`Leadsto`,`ENABLED`,`UNCHANGED`,`Cdot`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`,`Divides`,`Irregular`]),pd=/* @__PURE__ */ new Set([`Plus`,`Minus`,`Times`,`Uminus`]),md=e=>({kind:`Set`,element:e}),hd=(e,t)=>e.kind===`Record`?e.fields.find(e=>e.name===t)?.type:void 0,gd=(e,t)=>e.kind===`Fun`&&e.domain.kind===`String`?e.range:hd(e,t),_d=(e,t)=>{if(t.length!==1)return;let n=t[0];return n.kind===`String`?hd(e,n.value):n.kind===`Num`&&n.fraction===``&&e.kind===`Product`?e.items[Number(n.integer)-1]:void 0},vd=(e,t)=>{let n=t[0];switch(e){case`Range`:return md(Ou);case`Cup`:case`Cap`:case`Setminus`:return n.kind===`Set`&&Mu(n,t[1])?n:void 0;case`UNION`:return n.kind===`Set`&&n.element.kind===`Set`?n.element:void 0;case`SUBSET`:return n.kind===`Set`?md(n):void 0;case`DOMAIN`:return n.kind===`Fun`?md(n.domain):n.kind===`Product`?md(Ou):n.kind===`Record`?md(ku):void 0;default:return}},yd=e=>e.isBool?e.text:`(= ${ad(e.text,!0)} ${Kc})`,bd=e=>e.isBool?`(${qc} ${ad(e.text,!0)})`:e.text,xd=e=>({isBool:!0,text:e}),Sd=(e,t)=>({isBool:!1,text:e,type:t}),Cd=e=>({isBool:!1,text:`(${G} ${e})`,integer:e}),wd=(e,t)=>e.encoding.isTyped?t:void 0,Td=e=>e.isBool?Du:e.integer===void 0?e.type??Eu:Ou,Ed=(e,t)=>t?.kind===`Int`?Cd(e):t?.kind===`Bool`?xd(e):Sd(e,t),Dd=(e,t)=>t.kind===`Int`?{isBool:!1,text:e,integer:`(${Xc} ${e})`}:Sd(e,t.kind===`Bool`?void 0:t),Od=e=>{let t=Td(e);return t.kind===`Set`?t.element:void 0},kd=(t,n)=>{let r=Array.from({length:n-1}).reduce(e=>e?.rest,t);if(!r)throw new e.B(`a reference outside the obligation`);return r.binding},Ad=(e,t)=>({binding:t,rest:e}),jd=(t,n,r,i,a)=>{let o=Array.from({length:a}).reduce(e=>Ad(e,{kind:`unsupported`,reason:`a declaration without a type`}),r);try{return Td(cf(uf({caseErrors:t.session.caseErrors},t.encoding),n,o,i))}catch(t){if(t instanceof e.y)return;throw t}},Md=(e,t,n,r,i,a)=>e.encoding.isTyped?Bu({infer:(t,n)=>jd(e,t,r,i,a===void 0?n+1:n),isTarget:(e,t)=>a===void 0?e.kind===`Ix`&&e.index===t+1:e.kind===`Opaque`&&e.name===a},n,t):void 0,Nd=(e,t)=>[...new Set(e.match(/[^\s()]+#\d+/g))].filter(e=>Zu(e)<t).toSorted((e,t)=>Zu(e)-Zu(t)),Pd=(e,t)=>{let n=e.context.adjoin(t);return e.context.enter(n),e.declared.set(n.name,n),n.name},Fd=e=>({...e,polarity:`Neither`}),Id=e=>({...e,polarity:e.polarity===`Positive`?`Negative`:e.polarity===`Negative`?`Positive`:`Neither`}),Ld=(e,t,n,r)=>bd(cf(e,t,n,Fd(r))),Rd=(e,t,n,r)=>yd(cf(e,t,n,r)),zd=(e,t,n,r)=>t.reduce((e,t)=>t.domain.kind===`Ditto`?[...e,e.at(-1)]:t.domain.kind===`NoDomain`?[...e,void 0]:[...e,t.domain.expression],[]).map(t=>t===void 0?void 0:cf(e,t,n,Fd(r))),Bd=(t,n,r,i,a)=>zd(t,n,r,i).map(t=>{if(t===void 0)throw new e.B(`${a} without a domain`);return t}),Vd=(e,t,n)=>{let r=t.map(Od);return e.encoding.isTyped&&r.every(e=>e!==void 0)?n(r.filter(e=>e!==void 0)):void 0},Hd=(e,t,n,r=[])=>{let i=e.map((e,t)=>hl(e,n.depth+t,Pu(r[t])));return{variables:i,env:i.reduce((e,t,n)=>Ad(e,{kind:`constant`,symbol:t,type:r[n]}),t),mode:{...n,depth:n.depth+e.length}}},Ud=(e,t,n,r,i)=>t.bounds.reduce((a,o,s)=>{let c=n[s],l=e=>({types:[...a.types,e],last:e});if(o.domain.kind===`Domain`&&c!==void 0)return l(Od(c));if(o.domain.kind===`Ditto`&&a.last!==void 0)return l(a.last);let u=t.bounds.slice(s+1),d=u.length===0?t.body:{...t,bounds:u},f=t.bounds.slice(0,s).map(e=>e.name),p=Hd(f,r,i,a.types);return l(Md(e,d,t.quantifier===`Forall`,p.env,p.mode))},{types:[],last:void 0}).types,Wd=(e,t,n,r)=>{let i=zd(e,t.bounds,n,r),a=e.encoding.isTyped?Ud(e,t,i,n,r):[],o=Hd(t.bounds.map(e=>e.name),n,r,a),s=Rd(e,t.body,o.env,o.mode),c=o.variables.flatMap((e,t)=>{let n=i[t];return n===void 0?[]:[`(${H} ${bd(Ed(e,a[t]))} ${bd(n)})`]});return t.quantifier===`Forall`?`(forall (${_l(o.variables)}) ${c.length===0?s:`(=> ${yl(c)} ${s})`})`:`(exists (${_l(o.variables)}) ${yl([...c,s])})`},Gd=(e,t)=>[...Array.from({length:e},()=>`Idv`),...t.map(e=>gl(e)??`Idv`)],Kd=(e,t,n,r)=>{let i=cf(e,t.domain,n,Fd(r)),a=Hd([t.name],n,Fd(r)),o=Rd(e,t.body,a.env,a.mode),s=Nd(o,r.depth),c=e.flattener.flatten(`SetSt`,o,r,e=>sd(e,s,o,a.variables[0]),Gd(1,s));return Sd(X(c,[bd(i),...s]),Vd(e,[i],e=>md(e[0])))},qd=(e,t,n,r)=>{let i=Bd(e,t.bounds,n,r,`a set of values`),a=Hd(t.bounds.map(e=>e.name),n,Fd(r)),o=cf(e,t.element,a.env,Fd(a.mode)),s=bd(o),c=Nd(s,r.depth),l=i.length,u=e.flattener.flatten(`SetOf_${l}`,s,r,e=>cd(e,c,s,a.variables),Gd(l,c));return Sd(X(u,[...i.map(bd),...c]),Vd(e,i,()=>md(Td(o))))},Jd=(e,t,n,r)=>{let i=Bd(e,t.bounds,n,r,`a function`),a=i.map(bd),o=a.length===1?a[0]:X(V(`Product_${a.length}`),a),s=hl(a.length===1?t.bounds[0].name:`x`,r.depth),c={...Fd(r),depth:r.depth+1},l=Hd(a.length===1?[]:t.bounds.map(e=>e.name),n,c),u=cf(e,t.body,a.length===1?Ad(n,{kind:`constant`,symbol:s}):l.env,Fd(l.mode)),d=bd(u),f=l.variables.map((t,n)=>`(${t} (${q} ${s} ${du(n+1,e.encoding.isArithmetic)}))`),p=a.length===1?d:`(let (${f.toReversed().join(` `)}) ${d})`,m=Nd(p,r.depth),h=e.flattener.flatten(`FunFcn`,a.length===1?d:`(let (${f.join(` `)}) ${d})`,r,(e,t)=>ld(e,m,p,s,t),Gd(1,m));return Sd(X(h,[o,...m]),Vd(e,i,e=>({kind:`Fun`,domain:e.length===1?e[0]:{kind:`Product`,items:e},range:Td(u)})))},Yd=(e,t,n,r)=>{let i=Hd([t.name],n,Fd(r)),a=i.variables[0],o=t.domain&&`(${H} ${a} ${Ld(e,t.domain,n,r)})`,s=Rd(e,t.body,i.env,i.mode),c=o===void 0?s:yl([o,s]),l=Nd(c,r.depth),u=e.flattener.flatten(`Choose`,c,r,e=>ud(e,l,c,a),Gd(0,l));return Sd(X(u,l))},Xd=(e,t,n,r,i)=>{let a=cf(e,t[0],n,Fd(r)),o=cf(e,t[1],n,Fd(r)),s=Td(a),c=e.encoding.isSetExtensional?r.polarity:void 0;if(!e.encoding.isTyped||!Mu(s,Td(o)))return od(bd(a),bd(o),c,i);if(s.kind===`Int`||s.kind===`Bool`){let e=[a,o].map(e=>e.integer??e.text).join(` `);return i?`(distinct ${e})`:`(= ${e})`}if(s.kind!==`Set`)return od(a.text,o.text,c,i);let l=`TrigEq_${ju(s)}`;return e.setTypes.set(l,s),od(a.text,o.text,c,i,V(l))},Zd=(e,t,n,r)=>{let i=t.kind===`Lambda`&&t.params.length===1?t:void 0,a=Hd([i?.params[0].name??`x1`],n,Fd(r));return{body:Rd(e,i?.body??{kind:`Apply`,operator:I(1,t),args:[{kind:`Ix`,index:1}]},a.env,a.mode),variable:a.variables[0]}},Qd=(t,n,r,i,a)=>{let o=()=>r.map(e=>cf(t,e,i,Fd(a))),s=()=>o().map(bd);switch(n){case`Conj`:return xd(yl(r.map(e=>Rd(t,e,i,a))));case`Disj`:return xd(bl(r.map(e=>Rd(t,e,i,a))));case`Implies`:return xd(`(=> ${Rd(t,r[0],i,Id(a))} ${Rd(t,r[1],i,a)})`);case`Equiv`:return xd(`(= ${r.map(e=>Rd(t,e,i,Fd(a))).join(` `)})`);case`Neg`:return xd(`(not ${Rd(t,r[0],i,Id(a))})`);case`Eq`:return xd(Xd(t,r,i,a,!1));case`Neq`:return xd(Xd(t,r,i,a,!0));case`Mem`:return xd(X(H,s()));case`Notmem`:return xd(`(not ${X(H,s())})`);case`Subseteq`:return xd(X(Bc,s()));case`Lteq`:case`Gteq`:case`Lt`:case`Gt`:{let e=o(),r=e.flatMap(e=>e.integer===void 0?[]:[e.integer]);if(t.encoding.isTyped&&r.length===2)return xd(X(V(`TInt${n}`),r));let i=e=>n===`Lteq`||n===`Lt`?e:e.toReversed(),a=i(e.map(bd));return xd(n===`Lteq`||n===`Gteq`?X(K,a):`(and ${X(K,a)} (distinct ${i(s()).join(` `)}))`)}case`SelectSeq`:{let e=Zd(t,r[1],i,a),n=Nd(e.body,a.depth),o=t.flattener.flatten(`SelectSeq`,e.body,a,r=>dd(r,n,e.body,e.variable,t.encoding.isArithmetic),Gd(1,n));return Sd(X(o,[Ld(t,r[0],i,a),...n]))}case`Unprimable`:{let e=cf(t,r[0],i,Fd(a));return{...e,text:`(${Qu} ${e.text})`}}default:{let r=pl[n];if(r===void 0)throw new e.j(fd.has(n)?`Type.Synthesize: Unsupported builtin ${n.startsWith(`Box`)?`Box`:n}`:`Type.Synthesize: Unexpected left operand`);let i=o();if(!t.encoding.isTyped)return Sd(X(r,i.map(bd)));let a=i.flatMap(e=>e.integer===void 0?[]:[e.integer]);return pd.has(n)&&a.length===i.length?Cd(X(V(`TInt${n}`),a)):Sd(X(r,i.map(bd)),vd(n,i.map(Td)))}}},$d=(t,n,r,i,a)=>{switch(n.kind){case`constant`:case`variable`:if(r.length>0)throw new e.B(`an applied ${n.kind}`);return Ed(n.symbol,n.type);case`operator`:if(r.length===0&&n.arity>0)throw new e.j(`Type.Synthesize: Impossible operator conversion`);if(r.length!==n.arity)throw new e.B(`an operator applied to the wrong number of arguments`);return Sd(X(n.symbol,r.map(e=>Ld(t,e,i,a))));case`secondOrder`:{if(r.length!==n.shapes.length)throw new e.B(`an operator applied to the wrong number of arguments`);let o=r.map((r,o)=>{if(n.shapes[o]===0)return{isFirstOrder:!0,text:Ld(t,r,i,a)};if(r.kind===`Ix`){let t=kd(i,r.index);if(t.kind!==`operator`)throw new e.B(`an operator argument that isn't a LAMBDA`);return{isFirstOrder:!1,text:t.symbol}}if(r.kind!==`Lambda`)throw new e.B(`an operator argument that isn't a LAMBDA`);let s=Hd(r.params.map(e=>e.name),i,Fd(a));return{isFirstOrder:!1,text:Ld(t,r.body,s.env,s.mode)}}),s=o.flatMap(e=>e.isFirstOrder?[e.text]:[]),c=o.flatMap(e=>e.isFirstOrder?[]:[e.text]),l=Nd(c.join(` `),a.depth),u=t.flattener.flatten(``,c.join(` `),a,()=>[],Gd(s.length,l),n.name);return Sd(X(u,[...s,...l]))}case`unsupported`:throw new e.B(n.reason)}},ef=(t,n)=>{if(!t)throw new e.B(`a primed declaration that isn't a variable`);let r=t.binding;return r.kind===`variable`&&r.name===n?Ed(r.primed,r.primedType):ef(t.rest,n)},tf=(e,t,n,r,i)=>{if(t===`IsAFcn`&&n.length===1)return xd(`(${tl} ${Ld(e,n[0],r,i)})`);if(n.length===0&&t.endsWith(`#prime`))return ef(r,t.slice(0,-6));let a=n.length===0?`Anon_OPAQUE_${t}`:`Anon_${t}`;return e.anonymous.set(a,n.length),Sd(X(V(a),n.map(t=>Ld(e,t,r,i))))},nf=(e,t,n,r)=>t.specs.reduce((t,i)=>{let a=(t,o)=>{if(o.length===0)return Ld(e,i.value,n,{...r,at:t});let s=o[0],c=()=>s.kind===`Dot`?V(`StrLit_${s.field}`):Ld(e,s.expression,n,r),l=c(),u=a(`(${q} ${t} ${o.length>1?c():l})`,o.slice(1));return`(${rl} ${t} ${l} ${u})`};return a(t,i.trail)},Ld(e,t.function,n,r)),rf=e=>{e.session.caseErrors++;let t=`Anon_incomplete_case_error_${e.session.caseErrors}`;return e.anonymous.set(t,0),V(t)},af=(e,t,n,r)=>{let i=t.arms.map(t=>cf(e,t.body,n,r)),a=t.other?cf(e,t.other,n,r):Sd(rf(e)),o=Td(a),s=i.every(e=>Mu(Td(e),o)),c=s&&o.kind===`Bool`;if(s&&o.kind===`Int`){let o=t.arms.reduceRight((t,a,o)=>`(ite ${Rd(e,a.condition,n,Fd(r))} ${i[o].integer} ${t})`,a.integer??``);return{isBool:!1,text:`(${G} ${o})`,integer:o}}let l=e=>c?e.text:bd(e);return{isBool:c,text:t.arms.reduceRight((t,a,o)=>`(ite ${Rd(e,a.condition,n,r)} ${l(i[o])} ${t})`,l(a)),type:s?a.type:void 0}},of=(e,t,n,r,i,a)=>{let o=n&&cf(e,n,i,Fd(a)),s=o!==void 0&&t.domainVisibility===`Visible`?Od(o):Md(e,{kind:`Sequent`,sequent:r},!0,i,a);return{type:s,getGuard:e=>o&&`(${H} ${bd(Ed(e,s))} ${bd(o)})`}},sf=(t,n,r,i)=>{let a=n.context.reduce((r,i,a)=>{switch(i.kind){case`Fresh`:{if(i.shape>0){if(!r.mode.isOmitted)throw new e.B(`a second-order ASSUME`);let t=hl(i.name,r.mode.depth);return{env:Ad(r.env,{kind:`operator`,symbol:t,arity:i.shape}),mode:{...r.mode,depth:r.mode.depth+1},wrappers:[...r.wrappers,e=>`(forall ((${t} Idv)) ${e})`]}}if(i.level!==`Constant`)throw new e.B(`a NEW declaration that isn't constant`);let o={context:n.context.slice(a+1),active:n.active},s=of(t,i,i.domain,o,r.env,r.mode),c=Hd([i.name],r.env,r.mode,[s.type]),l=c.variables[0],u=s.getGuard(l);return{env:c.env,mode:c.mode,wrappers:[...r.wrappers,e=>`(forall (${_l([l])}) ${u?`(=> ${u} ${e})`:e})`]}}case`Fact`:{let e=i.visibility===`Visible`?Rd(t,i.expression,r.env,Id(r.mode)):void 0;return{env:Ad(r.env,{kind:`unsupported`,reason:`a reference to a fact`}),mode:r.mode,wrappers:e?[...r.wrappers,t=>`(=> ${e} ${t})`]:r.wrappers}}default:throw new e.B(`a ${i.kind} in a nested ASSUME`)}},{env:r,mode:i,wrappers:[]});return a.wrappers.reduceRight((e,t)=>t(e),Rd(t,n.active,a.env,a.mode))},cf=(t,n,r,i)=>{switch(n.kind){case`Ix`:return $d(t,kd(r,n.index),[],r,i);case`Internal`:switch(n.builtin){case`TRUE`:return xd(`true`);case`FALSE`:return xd(`false`);case`BOOLEAN`:return Sd(Jc,wd(t,md(Du)));case`STRING`:return Sd(Yc,wd(t,md(ku)));case`Nat`:return Sd(W,wd(t,md(Ou)));case`Int`:return Sd(U,wd(t,md(Ou)));case`Real`:case`Infinity`:throw new e.j(`Encode.Standardize: Unexpected builtin '${n.builtin}'`);default:throw new e.j(`Type.Synthesize: Unexpected builtin`)}case`Apply`:{let a=n.operator;if(a.kind===`Internal`)return Qd(t,a.builtin,n.args,r,i);if(a.kind===`Ix`)return $d(t,kd(r,a.index),n.args,r,i);if(a.kind===`Opaque`)return tf(t,a.name,n.args,r,i);if(a.kind===`Lambda`)return cf(t,pt(a,n.args),r,i);throw new e.B(`an application of ${a.kind}`)}case`Sequent`:return xd(sf(t,n.sequent,r,i));case`With`:case`Parens`:return cf(t,n.expression,r,i);case`If`:{let e=Rd(t,n.condition,r,i),a=cf(t,n.consequent,r,i),o=cf(t,n.alternative,r,i);if(a.integer!==void 0&&o.integer!==void 0){let t=`(ite ${ad(e,!0)} ${a.integer} ${o.integer})`;return{isBool:!1,text:`(${G} ${t})`,integer:t}}return a.isBool&&o.isBool?xd(`(ite ${e} ${a.text} ${o.text})`):Sd(`(ite ${e} ${bd(a)} ${bd(o)})`,Mu(Td(a),Td(o))?a.type:void 0)}case`List`:{let e=n.items.map(e=>Rd(t,e,r,i));return xd(n.bullet===`Or`?bl(e):yl(e))}case`Opaque`:return tf(t,n.name,[],r,i);case`Quant`:return xd(Wd(t,n,r,i));case`Choose`:return Yd(t,n,r,i);case`SetSt`:return Kd(t,n,r,i);case`SetOf`:return qd(t,n,r,i);case`SetEnum`:{let e=n.elements.map(e=>cf(t,e,r,Fd(i))),a=e.map(Td);return Sd(X(V(`SetEnum_${e.length}`),e.map(bd)),wd(t,a.every(e=>Mu(e,a[0]??Eu))?md(a[0]??Eu):void 0))}case`Product`:{let e=n.factors.map(e=>cf(t,e,r,Fd(i)));return Sd(X(V(`Product_${e.length}`),e.map(bd)),Vd(t,e,e=>md({kind:`Product`,items:e})))}case`Tuple`:{let e=n.elements.map(e=>cf(t,e,r,Fd(i)));return Sd(X(V(`Tuple_${e.length}`),e.map(bd)),wd(t,{kind:`Product`,items:e.map(Td)}))}case`Fcn`:return Jd(t,n,r,i);case`FcnApp`:{let e=cf(t,n.function,r,Fd(i)),a=n.args.map(e=>Ld(t,e,r,i)),o=a.length===1?a[0]:X(V(`Tuple_${a.length}`),a),s=`(${q} ${bd(e)} ${o})`,c=wd(t,_d(Td(e),n.args));return c===void 0?Sd(s):Dd(s,c)}case`Arrow`:{let e=[n.domain,n.range].map(e=>cf(t,e,r,Fd(i)));return Sd(X(nl,e.map(bd)),Vd(t,e,e=>md({kind:`Fun`,domain:e[0],range:e[1]})))}case`Record`:case`Rect`:{let e=n.fields.map(e=>e.name),a=e.join(`_`);t.recordFields.set(`Record_${a}`,e),t.recordFields.set(`RecordSet_${a}`,e);let o=n.fields.map(e=>cf(t,e.value,r,Fd(i))),s={kind:`Record`,fields:e.map((e,t)=>({name:e,type:Td(o[t])}))};return Sd(X(V(`${n.kind===`Record`?`Record`:`RecordSet`}_${a}`),o.map(bd)),n.kind===`Record`?wd(t,s):void 0)}case`Except`:return Sd(nf(t,n,r,i));case`Dot`:{let e=cf(t,n.expression,r,Fd(i)),a=`(${q} ${bd(e)} ${V(`StrLit_${n.field}`)})`,o=wd(t,gd(Td(e),n.field));return o===void 0?Sd(a):Dd(a,o)}case`Case`:return af(t,n,r,i);case`String`:return Sd(V(`StrLit_${n.value}`),wd(t,ku));case`Num`:if(n.fraction!==``)throw new e.B(`a real number`);return t.encoding.isArithmetic?{isBool:!1,text:`(${G} ${BigInt(n.integer)})`,integer:String(BigInt(n.integer))}:Sd(V(`IntLit_${BigInt(n.integer)}`));case`At`:if(i.at===void 0)throw new e.B(`@ outside EXCEPT`);return Sd(i.at);case`Tquant`:case`Tsub`:case`Fair`:throw new e.j(`Backend.Smtlib: Unsupported expression`);case`Lambda`:case`Bang`:throw new e.j(`Type.Synthesize: Unexpected ${n.kind} constructor`);default:throw new e.B(`the expression ${n.kind}`)}},lf=(e,t)=>[...e.flattener.takeIntroduced(),$u(ad(t,!1))],uf=(e,t)=>({session:e,encoding:t,flattener:td(),anonymous:/* @__PURE__ */ new Map,recordFields:/* @__PURE__ */ new Map,setTypes:/* @__PURE__ */ new Map,context:Dl(),declared:/* @__PURE__ */ new Map}),df=(e,t)=>e.fields.length===t.fields.length&&e.fields.every(e=>t.fields.some(t=>t.name===e.name))&&t.fields.every(t=>e.fields.some(e=>e.name===t.name)),ff=e=>e.length===1?e[0]:A(`Conj`,[e[0],ff(e.slice(1))],e[0]),pf=(e,t,n)=>e.kind!==`Record`||t.kind!==`Record`||!df(e,t)?A(`Eq`,[e,t],n):ff(e.fields.map(e=>pf(e.value,t.fields.find(t=>t.name===e.name)?.value??e.value,n))),mf=e=>{let t=ot(e,mf);return t.kind!==`Apply`||t.operator.kind!==`Internal`||t.operator.builtin!==`Eq`||t.args.length!==2||t.args[0].kind!==`Record`||t.args[1].kind!==`Record`?t:k(pf(t.args[0],t.args[1],t),t)},hf=e=>e.kind===`Record`||e.kind===`Rect`?{...e,fields:e.fields.toSorted((e,t)=>jc(e.name,t.name))}:ot(e,hf),gf=(e,t)=>{let n={isArithmetic:t.encoding.isArithmetic,isSetExtensional:t.encoding.isSetExtensional,recordFields:t.recordFields,setTypes:t.setTypes,strings:[],integers:[],isFunConstr:!1,isFunSet:!1,isExcept:!1,tuples:[],records:[],anonymous:t.anonymous},r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=e=>{let t=/* @__PURE__ */ new Set([e]);for(;t.size>0;){let e=[...t].toSorted(jc)[0];if(t.delete(e),r.has(e))continue;let a=Xu(e,n);r.set(e,a),a.deps.forEach(e=>t.add(e)),a.axioms.forEach(e=>i.set(au(e),e))}},o=e=>{let n=e.match(/[()]|[^\s()]+/g)??[],r=[];n.reduce((e,i,s)=>{if(i===`(`)return e+1;if(i===`)`)return r.at(-1)?.depth===e&&o(r.pop()?.text??``),e-1;let c=t.flattener.flattened.get(i);if(!c){let t=Rc(i);return t!==void 0&&a(t),e}return c.kind!==``&&a(c.kind),n[s-1]===`(`?r.push({depth:e,text:c.visit}):o(c.visit),e},0)};return e.forEach(e=>{typeof e==`string`?o(e):`omitted`in e&&o(e.omitted)}),{symbols:r,axioms:i}},_f={isOmitted:!1,polarity:`Negative`,at:void 0,depth:0},vf=e=>e.definition.kind===`Bpragma`||e.definition.kind===`Operator`&&e.visibility===`Visible`,yf=e=>e.kind===`Sequent`&&e.sequent.context.some(e=>e.kind===`Fresh`&&e.shape>0),bf=(e,t)=>e.context.reduce((n,r,i)=>{let a=(e,t=[])=>({env:Ad(n.env,e),entries:[...n.entries,...t]}),o={kind:`Sequent`,sequent:{context:e.context.slice(i+1),active:e.active}};switch(r.kind){case`Fresh`:{let e=Pd(t,r.name);if(r.shape>0)return a({kind:`operator`,symbol:e,arity:r.shape},[xl(e,r.shape)]);let i=of(t,r,r.domainVisibility===`Visible`?r.domain:void 0,o.sequent,n.env,_f),s={kind:`constant`,symbol:e,type:i.type},c=xl(e,0,Pu(i.type)),l=i.getGuard(e);return l===void 0?a(s,[c]):a(s,[c,...lf(t,`(assert ${l})`)])}case`Flex`:{let e=Pd(t,r.name),i=Pd(t,`${r.name}_prime`),s=Md(t,o,!0,n.env,_f),c={kind:`variable`,name:r.name,symbol:e,primed:i,type:s},l=Md(t,o,!0,Ad(n.env,c),_f,`${r.name}#prime`);return a({...c,primedType:l},[xl(e,0,Pu(s)),xl(i,0,Pu(l))])}case`Defn`:{let e=r.definition;if(vf(r))return a({kind:`unsupported`,reason:`an expanded definition`});if(e.kind===`Instance`)return a({kind:`unsupported`,reason:`an instance`},[`; omitted declaration of '${e.name}' (missing type)`]);if(e.kind===`Recursive`){let n=Pd(t,`CONSTANT_${e.name}_`);return a({kind:`operator`,symbol:n,arity:e.shape},[xl(n,e.shape)])}if(e.kind!==`Operator`)return a({kind:`unsupported`,reason:`a definition`});let i=e.body,s=i.kind===`Lambda`?i.params:[];if(s.some(e=>e.shape>0))return a({kind:`secondOrder`,name:e.name,shapes:s.map(e=>e.shape)},[`; omitted declaration of '${e.name}' (second-order)`]);let c=Pd(t,e.name),l=r.visibility===`Hidden`&&i.kind!==`Lambda`?Md(t,o,!0,n.env,_f):void 0;return l===void 0?a({kind:`operator`,symbol:c,arity:s.length},[xl(c,s.length)]):a({kind:`constant`,symbol:c,type:l},[xl(c,0,Pu(l))])}case`Fact`:{let e={kind:`unsupported`,reason:`a reference to a fact`};if(r.visibility===`Hidden`)return a(e,[`; hidden fact`]);let i=yf(r.expression),o=lf(t,`(assert ${Rd(t,r.expression,n.env,{..._f,isOmitted:i})})`);return a(e,i?[...o.map(e=>typeof e==`string`?{omitted:e}:e),`; omitted fact (second-order)`]:o)}}},{env:void 0,entries:[]}),xf=(e,t,n,r)=>{let i=hf(mf({kind:`Sequent`,sequent:e})),a=Gl(i.kind===`Sequent`?i.sequent:e,r.rewriteLevel),o=uf(t,r),s=bf(a,o),c=yf(a.active)?[]:lf(o,`(assert (! (not ${Rd(o,a.active,s.env,{..._f,polarity:`Positive`})}) :named |Goal|))`),l=Ol(o.declared),u=gf([...s.entries,...c],o),d=[...u.symbols].toSorted((e,t)=>jc(e[0],t[0])).flatMap(e=>e[1].declaration===void 0?[]:[e[1].declaration]),f=[...u.axioms.values()].toSorted(su).map(e=>e.formula===void 0?`; omitted fact (second-order)`:`(assert (! ${e.formula} :named |${e.label}|))`),p=new Set(u.axioms.keys()),m=e=>e.flatMap(e=>typeof e==`string`?[e]:`omitted`in e?[]:e.getLines(p)),h=[...d,...f,...m(s.entries)],g=[...h,...m(c)],_=g.some(e=>/\bIdv\b/.test(e))||a.context.some(e=>e.kind===`Defn`&&(e.definition.kind===`Operator`||e.definition.kind===`Recursive`)&&!vf(e)),v=e=>{if(e.startsWith(`;`))return e;let t=tu(Cl(l(e),fl)),n=/:named \|([^|]*)\|\)\)$/.exec(e)?.[1];return n===void 0?t:`;; ${n===`Goal`?n:`Axiom: ${n}`}\n${t}`};return[`;; TLA+ Proof Manager ${n.version}\n`,`;; Proof obligation #${n.id}\n`,`;; Generated from ${n.location}\n\n`,`(set-logic ${n.logic})\n\n`,`;; Sorts
136
+
137
+ `,_?`(declare-sort Idv 0)
138
+ `:``,`
139
+ ;; Hypotheses
140
+
141
+ `,h.length===0?`
142
+ `:``,...g.map(e=>`${v(e)}\n\n`),`(check-sat)
143
+ (exit)
144
+ `].join(``)},Sf=z(`@ `),Cf={TRUE:`T.`,FALSE:`F.`,STRING:`TLA.STRING`,BOOLEAN:`(TLA.set T. F.)`,Nat:`arith.N`,Int:`arith.Z`,Real:`arith.R`,Infinity:`arith.Infinity`,Any:`TLA.Any`},wf={Implies:[`=>`,2],Equiv:[`<=>`,2],Conj:[`/\\`,2],Disj:[`\\/`,2],Neg:[`-.`,1],Eq:[`=`,2],DOMAIN:[`TLA.DOMAIN`,1],SUBSET:[`TLA.SUBSET`,1],UNION:[`TLA.UNION`,1],Subseteq:[`TLA.subseteq`,2],Mem:[`TLA.in`,2],Setminus:[`TLA.setminus`,2],Cap:[`TLA.cap`,2],Cup:[`TLA.cup`,2],Plus:[`arith.add`,2],Uminus:[`arith.minus`,1],Times:[`arith.mul`,2],Ratio:[`arith.div`,2],Quotient:[`arith.euclidiv`,2],Remainder:[`arith.mod`,2],Exp:[`arith.power`,2],Lteq:[`arith.le`,2],Lt:[`arith.lt`,2],Range:[`arith.intrange`,2],Seq:[`TLA.Seq`,1],Len:[`TLA.Len`,1],BSeq:[`TLA.BSeq`,1],Cat:[`TLA.concat`,2],Append:[`TLA.Append`,2],Head:[`TLA.Head`,1],Tail:[`TLA.Tail`,1],SubSeq:[`TLA.SubSeq`,3],SelectSeq:[`TLA.SelectSeq`,2],OneArg:[`TLA.oneArg`,2],Extend:[`TLA.extend`,2],Print:[`TLA.Print`,2],PrintT:[`TLA.PrintT`,1],Assert:[`TLA.Assert`,2],JavaTime:[`TLA.JavaTime`,0],TLCGet:[`TLA.TLCGet`,1],TLCSet:[`TLA.TLCSet`,2],Permutations:[`TLA.Permutations`,1],SortSeq:[`TLA.SortSeq`,2],RandomElement:[`TLA.RandomElement`,1],ToString:[`TLA.ToString`,1]},Tf=e=>{let t=Number.parseInt(e,10);return`${`(TLA.fapply TLA.Succ `.repeat(t)}0${`)`.repeat(t)}`},Ef=(t,n)=>{let r=ln(),i=e=>dn(r,po(e)),a=()=>dn(r,``),o=e=>Qt(e,m,Sf),s=(e,t)=>z(`(%s %a)`,e,o(t)),c=(e,t,n)=>{let a=i(e),o=z(`%a((%s) %a))`,t,a,m(n));return fn(r,1),o},l=(e,t)=>{let n=Cf[e];if(n!==void 0&&t.length===0)return R(n);let r=wf[e];if(r&&r[1]===t.length)return s(r[0],t);if(t.length===2)switch(e){case`Neq`:return z(`(-. %a)`,s(`=`,t));case`Notmem`:return z(`(-. %a)`,s(`TLA.in`,t));case`Minus`:return s(`arith.add`,[t[0],{kind:`Apply`,operator:{kind:`Internal`,builtin:`Uminus`,location:t[1].location},args:[t[1]],location:t[1].location}]);case`Gteq`:return s(`arith.le`,t.toReversed());case`Gt`:return s(`arith.lt`,t.toReversed())}if(e===`Unprimable`&&t.length===1)return m(t[0]);throw ho(e,t.length,`Backend.Zenon.fmt_apply`)},u=(t,n)=>{switch(t.kind){case`Ix`:{let i=un(r,t.index);if(t.index<=0||i===void 0)throw new e.U;return n.length===0?R(i):s(i,n)}case`Opaque`:{let e=po(t.name);return n.length===0?R(e):s(e,n)}case`Internal`:return l(t.builtin,n);case`Lambda`:{let e=t.params.map(e=>z(`%s `,i(e.name))),n=z(`((%a) %a)`,e,m(t.body));return fn(r,t.params.length),n}default:throw new e.U}},d=(t,n,r)=>{if(n.length===0)return m(r);let i=go(t,n,r),a=t===`Forall`;if(i.first.domain.kind===`NoDomain`)return c(i.first.name,R(a?`(A. `:`(E. `),i.inner);if(i.first.domain.kind!==`Domain`)throw new e.U;let o=m(i.first.domain.expression);return c(i.first.name,z(`(%s %a `,a?`TLA.bAll`:`TLA.bEx`,o),i.inner)},f=(t,n,r,i)=>{if(n.length!==1)throw new e.B(`${i} (multiple declared constants)`);let a=n[0];if(a.domain.kind!==`Domain`)throw new e.U;return c(a.name,z(`(%s %a `,t,m(a.domain.expression)),r)},p=t=>{if(t.context.length===0)return m(t.active);let n=t.context[0],o=()=>p({context:t.context.slice(1),active:t.active});if(n.kind===`Fact`){let e=n.visibility===`Visible`?m(n.expression):void 0;a();let t=e?z(`(=> %a %a)`,e,o()):o();return fn(r,1),t}if(n.kind===`Defn`)throw new e.U;let s=n.kind===`Fresh`&&n.domain&&n.domainVisibility===`Visible`?m(n.domain):void 0,c=i(n.name),l=n.kind===`Flex`?z(`(A. ((%s) (A. ((%s') %a))))`,c,c,o()):s?z(`(TLA.bAll %a ((%s) %a))`,s,c,o()):z(`(A. ((%s) %a))`,c,o());return fn(r,1),l},m=t=>{switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return u(t,[]);case`Apply`:return u(t.operator,t.args);case`Sequent`:return p(t.sequent);case`With`:case`Parens`:return m(t.expression);case`If`:return z(`(TLA.cond %a %a %a)`,m(t.condition),m(t.consequent),m(t.alternative));case`List`:if(t.bullet===`Refs`&&t.items.length===0)throw new e.U;return t.bullet===`Refs`&&t.items.length===1?m(t.items[0]):z(`(%s %a)`,t.bullet===`Or`?`\\/`:`/\\`,o(t.items));case`Quant`:return d(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.B(`\\AA or \\EE`);case`Choose`:return t.domain?c(t.name,z(`(TLA.bChoice %a `,m(t.domain)),t.body):c(t.name,R(`(t. `),t.body);case`SetSt`:return c(t.name,z(`(TLA.subsetOf %a `,m(t.domain)),t.body);case`SetOf`:return f(`TLA.setOfAll`,t.bounds,t.element,`Setof`);case`Fcn`:return f(`TLA.Fcn`,t.bounds,t.body,`Fcn`);case`SetEnum`:return t.elements.length===0?R(`TLA.emptyset`):[R(`(TLA.set`),t.elements.map(e=>z(` %a`,m(e))),R(`)`)];case`FcnApp`:{let e=m(t.function);return t.args.length===1?z(`(TLA.fapply %a %a)`,e,m(t.args[0])):z(`(TLA.fapply %a (TLA.tuple %a))`,e,o(t.args))}case`Arrow`:return z(`(TLA.FuncSet %a %a)`,m(t.domain),m(t.range));case`Rect`:case`Record`:return[R(t.kind===`Rect`?`(TLA.recordset`:`(TLA.record`),t.fields.map(e=>z(` "%s" %a`,e.name,m(e.value))),R(`)`)];case`Except`:{let n=t.specs[0];if(t.specs.length!==1||n.trail.length!==1)throw new e.B(`complex EXCEPT`);let r=n.trail[0],i=r.kind===`Dot`?R(`"${r.field}"`):m(r.expression);return z(`(TLA.except %a %a %a)`,m(t.function),i,m(n.value))}case`Dot`:return z(`(TLA.fapply %a "%s")`,m(t.expression),t.field);case`Tuple`:return z(`(TLA.tuple %a)`,o(t.elements));case`Product`:return t.factors.length===2?z(`(TLA.prod %a %a)`,m(t.factors[0]),m(t.factors[1])):z(`(TLA.Product (TLA.tuple %a))`,o(t.factors));case`Sub`:case`Tsub`:case`Fair`:throw new e.B(t.kind);case`Case`:{let e=Qt(t.arms,e=>z(`%a %a`,m(e.condition),m(e.body)),Sf);return t.other?z(`(TLA.CASE %a %a)@]`,e,m(t.other)):z(`(TLA.CASE %a )`,e)}case`String`:return z(`"%s"`,t.value);case`Num`:if(t.fraction!==``)throw new e.B(`Real number constants`);return R(Tf(t.integer));case`Bang`:case`Let`:case`At`:throw new e.U}},h=t=>{switch(t.kind){case`Fresh`:{let e=t.domain&&t.domainVisibility===`Visible`?m(t.domain):void 0,n=i(t.name);return e?z(`$hyp "%s_in" (TLA.in %s %a)@
145
+ `,n,n,e):[]}case`Flex`:return i(t.name),[];case`Defn`:{let e=i(t.definition.name);return t.visibility===`Visible`?z(`; usable definition %s suppressed@.`,e):[]}case`Fact`:{let n=String(r.stack.length),i=t.visibility===`Visible`?_o(r,()=>m(t.expression)):void 0;return a(),i instanceof e.B?z(`; omitted temporal assumption : %s @.`,i.message):i?z(`$hyp "v'%s" %a@
146
+ `,n,i):[]}}},g=(()=>{try{return[n.context.map(h),z(`$goal %a`,m(n.active))]}catch(t){throw t instanceof e.B?new e.j(`Zenon: unsupported operator ${t.message}`):t}})();return en([z(`;; obligation #%s@
147
+ `,String(t)),g])},Df=/* @__PURE__ */ new Map([[`TLAPS`,`------------------------------- MODULE TLAPS --------------------------------
47
148
 
48
149
  (* Backend pragmas. *)
49
150
 
@@ -523,484 +624,2631 @@ PROOF OMITTED
523
624
  (***************************************************************************)
524
625
  PropositionalTemporalLogic == TRUE
525
626
  =============================================================================
526
- `:void 0);return i===void 0?void 0:{file:`${e}.tla`,source:i}}),a=i.flatMap(e=>e.obligations),o={missingProofCount:i.reduce((e,t)=>e+t.summary.absent.length,0),omittedProofCount:i.reduce((e,t)=>e+t.summary.omitted.length,0)};if(t.backend===`tlapm`){if(typeof process>`u`||process.versions?.node===void 0)throw new e.A(`The tlapm backend runs only in Node and Bun.`);let i=await Promise.resolve().then(()=>require("./tlapm.cjs")).then(e=>e.n),s=new Map(a.map(e=>[e.id,e])),c=await i.proveWithTlapm(n,new Map([[n,t.source],...r]),{signal:t.signal,onResult:(e,n)=>{let r=s.get(e);r&&t.onObligation?.(zu(r,n))}});return{obligations:a.map(e=>zu(e,c.get(e.id))),...o}}return{obligations:(await Ru(a,{workers:t.workers,signal:t.signal,onReport:e=>t.onObligation?.(e.obligation)})).map(e=>e.obligation),...o}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return`------------------------------- MODULE TLAPS --------------------------------
627
+ `],[`Bags`,`----------------------------- MODULE Bags --------------------------------
628
+ (**************************************************************************)
629
+ (* A bag, also called a multiset, is a set that can contain multiple *)
630
+ (* copies of the same element. A bag can have infinitely many elements, *)
631
+ (* but only finitely many copies of any single element. *)
632
+ (* *)
633
+ (* We represent a bag in the usual way as a function whose range is a *)
634
+ (* subset of the positive integers. An element e belongs to bag B iff e *)
635
+ (* is in the domain of B, in which case bag B contains B[e] copies of e. *)
636
+ (**************************************************************************)
637
+ LOCAL INSTANCE Naturals
638
+
639
+ IsABag(B) ==
640
+ (************************************************************************)
641
+ (* True iff B is a bag. *)
642
+ (************************************************************************)
643
+ B \\in [DOMAIN B -> {n \\in Nat : n > 0}]
644
+
645
+ BagToSet(B) == DOMAIN B
646
+ (************************************************************************)
647
+ (* The set of elements at least one copy of which is in B. *)
648
+ (************************************************************************)
649
+
650
+ SetToBag(S) == [e \\in S |-> 1]
651
+ (************************************************************************)
652
+ (* The bag that contains one copy of every element of the set S. *)
653
+ (************************************************************************)
654
+
655
+ BagIn(e,B) == e \\in BagToSet(B)
656
+ (************************************************************************)
657
+ (* The \\in operator for bags. *)
658
+ (************************************************************************)
659
+
660
+ EmptyBag == SetToBag({})
661
+
662
+ B1 (+) B2 ==
663
+ (************************************************************************)
664
+ (* The union of bags B1 and B2. *)
665
+ (************************************************************************)
666
+ [e \\in (DOMAIN B1) \\cup (DOMAIN B2) |->
667
+ (IF e \\in DOMAIN B1 THEN B1[e] ELSE 0)
668
+ + (IF e \\in DOMAIN B2 THEN B2[e] ELSE 0) ]
669
+
670
+ B1 (-) B2 ==
671
+ (************************************************************************)
672
+ (* The bag B1 with the elements of B2 removed--that is, with one copy *)
673
+ (* of an element removed from B1 for each copy of the same element in *)
674
+ (* B2. If B2 has at least as many copies of e as B1, then B1 (-) B2 *)
675
+ (* has no copies of e. *)
676
+ (************************************************************************)
677
+ LET B == [e \\in DOMAIN B1 |-> IF e \\in DOMAIN B2 THEN B1[e] - B2[e]
678
+ ELSE B1[e]]
679
+ IN [e \\in {d \\in DOMAIN B : B[d] > 0} |-> B[e]]
680
+
681
+ LOCAL Sum(f) ==
682
+ (******************************************************************)
683
+ (* The sum of f[x] for all x in DOMAIN f. The definition assumes *)
684
+ (* that f is a Nat-valued function and that f[x] equals 0 for all *)
685
+ (* but a finite number of elements x in DOMAIN f. *)
686
+ (******************************************************************)
687
+ LET DSum[S \\in SUBSET DOMAIN f] ==
688
+ LET elt == CHOOSE e \\in S : TRUE
689
+ IN IF S = {} THEN 0
690
+ ELSE f[elt] + DSum[S \\ {elt}]
691
+ IN DSum[DOMAIN f]
692
+
693
+ BagUnion(S) ==
694
+ (************************************************************************)
695
+ (* The bag union of all elements of the set S of bags. *)
696
+ (************************************************************************)
697
+ [e \\in UNION {BagToSet(B) : B \\in S} |->
698
+ Sum( [B \\in S |-> IF BagIn(e, B) THEN B[e] ELSE 0] ) ]
699
+
700
+ B1 \\sqsubseteq B2 ==
701
+ (************************************************************************)
702
+ (* The subset operator for bags. B1 \\sqsubseteq B2 iff, for all e, bag *)
703
+ (* B2 has at least as many copies of e as bag B1 does. *)
704
+ (************************************************************************)
705
+ /\\ (DOMAIN B1) \\subseteq (DOMAIN B2)
706
+ /\\ \\A e \\in DOMAIN B1 : B1[e] \\leq B2[e]
707
+
708
+ SubBag(B) ==
709
+ (************************************************************************)
710
+ (* The set of all subbags of bag B. *)
711
+ (* *)
712
+ (* The following definition is not the one described in the TLA+ book, *)
713
+ (* but rather one that TLC can evaluate. *)
714
+ (************************************************************************)
715
+
716
+ LET RemoveFromDom(x, f) == [y \\in (DOMAIN f) \\ {x} |-> f[y]]
717
+ Combine(x, BagSet) ==
718
+ BagSet \\cup
719
+ {[y \\in (DOMAIN f) \\cup {x} |-> IF y = x THEN i ELSE f[y]] :
720
+ f \\in BagSet, i \\in 1..B[x]}
721
+ Biggest == LET Range1 == {B[x] : x \\in DOMAIN B}
722
+ IN IF Range1 = {} THEN 0
723
+ ELSE CHOOSE r \\in Range1 :
724
+ \\A s \\in Range1 : r \\geq s
725
+ RSB[BB \\in UNION {[S -> 1..Biggest] : S \\in SUBSET DOMAIN B}] ==
726
+ IF BB = << >> THEN {<< >>}
727
+ ELSE LET x == CHOOSE x \\in DOMAIN BB : TRUE
728
+ IN Combine(x, RSB[RemoveFromDom(x, BB)])
729
+ IN RSB[B]
730
+
731
+ (******************* Here is the definition from the TLA+ book. ********
732
+ LET AllBagsOfSubset ==
733
+ (******************************************************************)
734
+ (* The set of all bags SB such that BagToSet(SB) \\subseteq *)
735
+ (* BagToSet(B). *)
736
+ (******************************************************************)
737
+ UNION {[SB -> {n \\in Nat : n > 0}] : SB \\in SUBSET BagToSet(B)}
738
+ IN {SB \\in AllBagsOfSubset : \\A e \\in DOMAIN SB : SB[e] \\leq B[e]}
739
+ ***************************************************************************)
740
+
741
+ BagOfAll(F(_), B) ==
742
+ (************************************************************************)
743
+ (* The bag analog of the set {F(x) : x \\in B} for a set B. It's the bag *)
744
+ (* that contains, for each element e of B, one copy of F(e) for every *)
745
+ (* copy of e in B. This defines a bag iff, for any value v, the set of *)
746
+ (* e in B such that F(e) = v is finite. *)
747
+ (************************************************************************)
748
+ [e \\in {F(d) : d \\in BagToSet(B)} |->
749
+ Sum( [d \\in BagToSet(B) |-> IF F(d) = e THEN B[d] ELSE 0] ) ]
750
+
751
+ BagCardinality(B) ==
752
+ (************************************************************************)
753
+ (* If B is a finite bag (one such that BagToSet(B) is a finite set), *)
754
+ (* then this is its cardinality (the total number of copies of elements *)
755
+ (* in B). Its value is unspecified if B is infinite. *)
756
+ (************************************************************************)
757
+ Sum(B)
527
758
 
528
- (* Backend pragmas. *)
759
+
760
+ =============================================================================
761
+
762
+ (* Last modified on Fri 26 Jan 2007 at 8:45:03 PST by lamport *)
763
+
764
+ 6 Apr 99 : Modified version for standard module set
765
+ 7 Dec 98 : Corrected error found by Stephan Merz.
766
+ 6 Dec 98 : Modified comments based on suggestions by Lyle Ramshaw.
767
+ 5 Dec 98 : Initial version.
768
+ `],[`BagsTheorems`,`---------------------------- MODULE BagsTheorems ---------------------------
769
+ (**************************************************************************)
770
+ (* A bag, also called a multiset, is a set that can contain multiple *)
771
+ (* copies of the same element. A bag can have infinitely many elements, *)
772
+ (* but only finitely many copies of any single element. *)
773
+ (* *)
774
+ (* We represent a bag in the usual way as a function whose range is a *)
775
+ (* subset of the positive integers. An element e belongs to bag B iff e *)
776
+ (* is in the domain of B, in which case bag B contains B[e] copies of e. *)
777
+ (**************************************************************************)
778
+ EXTENDS Bags
779
+
780
+ LOCAL INSTANCE Naturals
781
+
782
+ CopiesIn(e, B) ==
783
+ (************************************************************************)
784
+ (* If B is a bag, then CopiesIn(e, B) is the number of copies of e in *)
785
+ (* B. If ~BagIn(e, B), then CopiesIn(e, B) = 0. *)
786
+ (************************************************************************)
787
+ IF BagIn(e, B) THEN B[e] ELSE 0
788
+
789
+ Scaling(n, B) ==
790
+ (************************************************************************)
791
+ (* If B is a bag, then Scaling(e, B) is the Bag containing the same *)
792
+ (* elements of B with n times their copies *)
793
+ (************************************************************************)
794
+ IF n>0 THEN [i \\in DOMAIN B |-> n*B[i] ] ELSE EmptyBag
529
795
 
530
796
 
531
797
  (***************************************************************************)
532
- (* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
533
- (* is added to the context of an obligation most recently is the one whose *)
534
- (* effects are triggered. *)
798
+ (* Converts a sequence into a bag *)
535
799
  (***************************************************************************)
536
800
 
801
+ SeqToBag(seq) == [ x \\in Range(seq) |-> Cardinality({i \\in DOMAIN seq: seq[i]=x}) ]
802
+
803
+
537
804
  (***************************************************************************)
538
- (* The following pragmas should be used only as a last resource. They are *)
539
- (* dependent upon the particular backend provers, and are unlikely to have *)
540
- (* any effect if the set of backend provers changes. Moreover, they are *)
541
- (* meaningless to a reader of the proof. *)
805
+ (* \\sqsubseteq is a PARTIAL ORDER relattion *)
542
806
  (***************************************************************************)
543
807
 
808
+ (*Reflexivity*)
809
+ THEOREM Bags_SqsubsetPO_Reflexivity ==
810
+ ASSUME NEW B, IsABag(B)
811
+ PROVE B \\sqsubseteq B
544
812
 
545
- (**************************************************************************)
546
- (* Backend pragma: use the SMT solver for arithmetic. *)
547
- (* *)
548
- (* This method exists under this name for historical reasons. *)
549
- (**************************************************************************)
813
+ (*Antisymmetry*)
814
+ THEOREM Bags_SqsubseteqPO_AntiSymmetry ==
815
+ ASSUME NEW A, NEW B, IsABag(A), IsABag(B),
816
+ A \\sqsubseteq B, B \\sqsubseteq A
817
+ PROVE A = B
550
818
 
551
- SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
819
+ (*Transitivity*)
820
+ THEOREM Bags_SqsubseteqPO_Transitivity ==
821
+ ASSUME NEW A, NEW B, NEW C, IsABag(A), IsABag(B), IsABag(C),
822
+ A \\sqsubseteq B, B \\sqsubseteq C
823
+ PROVE A \\sqsubseteq C
552
824
 
825
+ (***************************************************************************)
826
+ (* Lemmas on EmptyBags *)
827
+ (***************************************************************************)
553
828
 
554
- (**************************************************************************)
555
- (* Backend pragma: SMT solver *)
556
- (* *)
557
- (* This method translates the proof obligation to SMTLIB2. The supported *)
558
- (* fragment includes first-order logic, set theory, functions and *)
559
- (* records. *)
560
- (* SMT calls the smt-solver with the default timeout of 5 seconds *)
561
- (* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
562
- (* *)
563
- (* SMTT also accepts a string argument of the form "rN" to bound the *)
564
- (* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
565
- (* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
566
- (* resource count, so a small readable budget like "r5" is meaningful. *)
567
- (* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
568
- (* speed or load, so the proof's pass/fail outcome reproduces on any *)
569
- (* machine and every rerun (for a fixed Z3 build); how long it takes to *)
570
- (* consume the budget still varies by machine. This is Z3-specific. *)
571
- (**************************************************************************)
829
+ THEOREM Bags_EmptyBag ==
830
+ ASSUME NEW B, IsABag(B)
831
+ PROVE /\\ IsABag(EmptyBag)
832
+ /\\ B=EmptyBag <=> DOMAIN B ={}
833
+ /\\ DOMAIN EmptyBag ={}
834
+ /\\ EmptyBag \\sqsubseteq B
835
+ /\\ \\A e: ~BagIn(e, EmptyBag)
572
836
 
573
- SMT == TRUE (*{ by (prover:"smt3") }*)
574
- SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
837
+ (***************************************************************************)
838
+ (* Lemmas on Scaling Operator for Bags *)
839
+ (***************************************************************************)
575
840
 
841
+ THEOREM Bags_Scaling ==
842
+ ASSUME NEW B, IsABag(B), NEW n \\in Nat, NEW m \\in Nat
843
+ PROVE /\\ IsABag(Scaling(n, B))
844
+ /\\ Scaling(n, EmptyBag)=EmptyBag
845
+ /\\ Scaling(0, B)=EmptyBag
846
+ /\\ Scaling(1, B)= B
847
+ /\\ Scaling(n*m, B) = Scaling(n, Scaling(m, B))
848
+ /\\ n>0 => DOMAIN(Scaling(n, B)) = DOMAIN B
576
849
 
577
- (**************************************************************************)
578
- (* Backend pragma: CVC4 SMT solver *)
579
- (* *)
580
- (* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
581
- (**************************************************************************)
850
+ (***************************************************************************)
851
+ (* SetToBag and BagToSet are inverse of each other *)
852
+ (***************************************************************************)
582
853
 
583
- (* The CVC3* methods are here for backward compatibility. They call CVC4. *)
584
- CVC3 == TRUE (*{ by (prover: "cvc33") }*)
585
- CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
854
+ THEOREM Bags_Inverse ==
855
+ ASSUME NEW S
856
+ PROVE BagToSet(SetToBag(S))=S
586
857
 
587
- CVC4 == TRUE (*{ by (prover: "cvc33") }*)
588
- CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
858
+ THEOREM Bags_Inverse1 ==
859
+ ASSUME NEW B, IsABag(B)
860
+ PROVE SetToBag(BagToSet(B)) \\sqsubseteq B
589
861
 
862
+ (***************************************************************************)
863
+ (* SetToBag Preserves Equality *)
864
+ (***************************************************************************)
590
865
 
591
- (**************************************************************************)
592
- (* Backend pragma: Yices SMT solver *)
593
- (* *)
594
- (* This method translates the proof obligation to Yices native language. *)
595
- (**************************************************************************)
866
+ THEOREM Bags_SetToBagEquality ==
867
+ ASSUME NEW A, NEW B
868
+ PROVE A=B <=> SetToBag(A)=SetToBag(B)
596
869
 
597
- Yices == TRUE (*{ by (prover: "yices3") }*)
598
- YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
870
+ (***************************************************************************)
871
+ (* Union of Bags *)
872
+ (***************************************************************************)
599
873
 
600
- (**************************************************************************)
601
- (* Backend pragma: veriT SMT solver *)
602
- (* *)
603
- (* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
604
- (**************************************************************************)
874
+ THEOREM Bags_Union ==
875
+ ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
876
+ PROVE /\\ IsABag(B1 (+) B2)
877
+ /\\ DOMAIN(B1 (+) B2) = DOMAIN B1 \\cup DOMAIN B2
878
+ /\\ \\A e : CopiesIn(e, B1(+)B2) = CopiesIn(e,B1) + CopiesIn(e,B2)
605
879
 
606
- veriT == TRUE (*{ by (prover: "verit") }*)
607
- veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
880
+ (***************************************************************************)
881
+ (* Difference of Bags *)
882
+ (***************************************************************************)
608
883
 
609
- (**************************************************************************)
610
- (* Backend pragma: Zipperposition solver *)
611
- (* *)
612
- (* This method translates the proof obligation to TPTP and *)
613
- (* calls Zipperposition. *)
614
- (**************************************************************************)
884
+ THEOREM Bags_Difference ==
885
+ ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
886
+ PROVE /\\ IsABag(B1 (-) B2)
887
+ /\\ DOMAIN (B1 (-) B2) =
888
+ {e \\in DOMAIN B1 : e \\notin DOMAIN B2 \\/ B1[e] > B2[e]}
889
+ /\\ \\A e : CopiesIn(e, B1 (-) B2) =
890
+ IF BagIn(e, B1(-)B2) THEN CopiesIn(e,B1) - CopiesIn(e,B2)
891
+ ELSE 0
615
892
 
616
- Zipper == TRUE (*{ by (prover: "zipper") }*)
617
- ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
893
+ (***************************************************************************)
894
+ (* Union is commutative. *)
895
+ (***************************************************************************)
618
896
 
619
- (**************************************************************************)
620
- (* Backend pragma: Z3 SMT solver *)
621
- (* *)
622
- (* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
623
- (* Z3 is used by default but you can also explicitly call it. *)
624
- (* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
625
- (* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
626
- (* reproduces the same outcome on any machine (see SMTT). *)
627
- (**************************************************************************)
897
+ THEOREM Bags_UnionCommutative ==
898
+ ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
899
+ PROVE B1(+)B2 = B2(+)B1
628
900
 
629
- Z3 == TRUE (*{ by (prover: "z33") }*)
630
- Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
901
+ (***************************************************************************)
902
+ (* Unon is associative. *)
903
+ (***************************************************************************)
904
+ THEOREM Bags_UnionAssociative ==
905
+ ASSUME NEW B1, NEW B2, NEW B3, IsABag(B1), IsABag(B2), IsABag(B3)
906
+ PROVE (B1(+)B2) (+) B3 = B1 (+) (B2(+)B3)
631
907
 
632
- (**************************************************************************)
633
- (* Backend pragma: SPASS superposition prover *)
634
- (* *)
635
- (* This method translates the proof obligation to the DFG format language *)
636
- (* supported by the ATP SPASS. The translation is based on the SMT one. *)
637
- (**************************************************************************)
908
+ (***************************************************************************)
909
+ (* Given Bags B1, B2 then B1 \\sqsubseteq B1(+)B2 *)
910
+ (***************************************************************************)
638
911
 
639
- Spass == TRUE (*{ by (prover: "spass") }*)
640
- SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
912
+ THEOREM Bags_UnionSqSubset ==
913
+ ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
914
+ PROVE B1 \\sqsubseteq B1(+)B2
641
915
 
642
- (**************************************************************************)
643
- (* Backend pragma: The PTL propositional linear time temporal logic *)
644
- (* prover. It currently is the LS4 backend. *)
645
- (* *)
646
- (* This method translates the negetation of the proof obligation to *)
647
- (* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
648
- (**************************************************************************)
916
+ (***************************************************************************)
917
+ (* Scaling is monotonic in the scaling factor. *)
918
+ (***************************************************************************)
649
919
 
650
- LS4 == TRUE (*{ by (prover: "ls4") }*)
651
- LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
652
- PTL == TRUE (*{ by (prover: "ls4") }*)
920
+ THEOREM Bags_ScalingMonotonic ==
921
+ ASSUME NEW B, IsABag(B), NEW n \\in Nat, NEW m \\in Nat, m <= n
922
+ PROVE Scaling(m, B) \\sqsubseteq Scaling(n, B)
653
923
 
654
- (**************************************************************************)
655
- (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
656
- (* *)
657
- (**************************************************************************)
924
+ (***************************************************************************)
925
+ (* Given Bags A and B, A(-)B \\sqsubseteq A *)
926
+ (***************************************************************************)
658
927
 
659
- Zenon == TRUE (*{ by (prover:"zenon") }*)
660
- ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
928
+ THEOREM Bags_DifferenceSqsubset ==
929
+ ASSUME NEW A, NEW B, IsABag(A), IsABag(B)
930
+ PROVE A(-)B \\sqsubseteq A
661
931
 
662
- (********************************************************************)
663
- (* Backend pragma: Isabelle with different timeouts and tactics *)
664
- (* (default is 30 seconds/auto) *)
665
- (********************************************************************)
932
+ (***************************************************************************)
933
+ (* EmptyBag is the additive identity. *)
934
+ (***************************************************************************)
666
935
 
667
- Isa == TRUE (*{ by (prover:"isabelle") }*)
668
- IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
669
- IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
670
- IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
936
+ THEOREM Bags_EmptyBagOperations ==
937
+ ASSUME NEW B, IsABag(B)
938
+ PROVE /\\ B (+) EmptyBag = B
939
+ /\\ B (-) EmptyBag = B
671
940
 
672
941
  (***************************************************************************)
673
- (* The following theorem expresses the (useful implication of the) law of *)
674
- (* set extensionality, which can be written as *)
942
+ (* SetToBag of a set is a bag. *)
943
+ (***************************************************************************)
944
+
945
+ THEOREM Bags_SetToBagIsABag ==
946
+ ASSUME NEW S
947
+ PROVE IsABag(SetToBag(S))
948
+
949
+ (***************************************************************************)
950
+ (* CopiesIn is monotone w.r.t \\sqsubseteq *)
951
+ (***************************************************************************)
952
+
953
+ THEOREM Bags_CopiesInBagsInMonotone ==
954
+ ASSUME NEW B1, NEW B2, NEW e, IsABag(B1), IsABag(B2), B1 \\sqsubseteq B2
955
+ PROVE /\\ BagIn(e, B1) => BagIn(e, B2)
956
+ /\\ CopiesIn(e, B1) <= CopiesIn(e, B2)
957
+
958
+ (***************************************************************************)
959
+ (* Given Bag B and Natural n, CopiesIn(e, Scaling(n, B))=n*CopiesIn(e, B) *)
960
+ (***************************************************************************)
961
+
962
+ THEOREM Bags_CopiesInScaling ==
963
+ ASSUME NEW B, IsABag(B), NEW n \\in Nat, NEW e
964
+ PROVE CopiesIn(e, Scaling(n, B)) = n*CopiesIn(e, B)
965
+
966
+ (***************************************************************************)
967
+ (* Given set S, CopiesIn(e, SetToBag(S))=IF e \\in B THEN 1 ELSE 0 *)
968
+ (***************************************************************************)
969
+
970
+ THEOREM Bags_CopiesInSetToBag ==
971
+ ASSUME NEW B, NEW e
972
+ PROVE CopiesIn(e, SetToBag(B))=IF e \\in B THEN 1 ELSE 0
973
+
974
+ (***************************************************************************)
975
+ (* Given sequence seq, SeqToBag(seq) is a Bag *)
976
+ (***************************************************************************)
977
+
978
+ THEOREM Bags_IsABagSeqToBag ==
979
+ ASSUME NEW S, NEW seq \\in Seq(S)
980
+ PROVE IsABag(SeqToBag(seq))
981
+
982
+ =============================================================================
983
+ `],[`FiniteSets`,`---------------------------- MODULE FiniteSets -----------------------------
984
+ LOCAL INSTANCE Naturals
985
+ LOCAL INSTANCE Sequences
986
+ (*************************************************************************)
987
+ (* Imports the definitions from Naturals and Sequences, but doesn't *)
988
+ (* export them. *)
989
+ (*************************************************************************)
990
+
991
+ IsFiniteSet(S) ==
992
+ (*************************************************************************)
993
+ (* A set S is finite iff there is a finite sequence containing all its *)
994
+ (* elements. *)
995
+ (*************************************************************************)
996
+ \\E seq \\in Seq(S) : \\A s \\in S : \\E n \\in 1..Len(seq) : seq[n] = s
997
+
998
+ Cardinality(S) ==
999
+ (*************************************************************************)
1000
+ (* Cardinality is defined only for finite sets. *)
1001
+ (*************************************************************************)
1002
+ LET CS[T \\in SUBSET S] == IF T = {} THEN 0
1003
+ ELSE 1 + CS[T \\ {CHOOSE x : x \\in T}]
1004
+ IN CS[S]
1005
+ =============================================================================
1006
+ `],[`FiniteSetTheorems`,`------------------------- MODULE FiniteSetTheorems --------------------------
1007
+ (***************************************************************************)
1008
+ (* \`^{\\large\\bf \\vspace{12pt} *)
1009
+ (* Facts about finite sets and their cardinality. *)
1010
+ (* Originally contributed by Tom Rodeheffer, MSR. *)
1011
+ (* \\vspace{12pt}}^' *)
1012
+ (***************************************************************************)
1013
+
1014
+ EXTENDS FiniteSets, Integers, Functions, WellFoundedInduction
1015
+
1016
+ (***************************************************************************)
1017
+ (* \`. .' *)
675
1018
  (* *)
676
- (* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
1019
+ (* A set S is finite iff there exists a natural number n such that there *)
1020
+ (* exist a surjection (or a bijection) from 1..n to S. *)
677
1021
  (* *)
678
- (* Theorem SetExtensionality is sometimes required by the SMT backend for *)
679
- (* reasoning about sets. It is usually counterproductive to include *)
680
- (* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
681
- (* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
682
- (* the Isabelle backend to use the rule of set extensionality. *)
1022
+ (* \`. .' *)
683
1023
  (***************************************************************************)
684
- IsaWithSetExtensionality == TRUE
685
- (*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
686
1024
 
687
- THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
688
- OBVIOUS
1025
+ LEMMA FS_NatSurjection ==
1026
+ ASSUME NEW S
1027
+ PROVE IsFiniteSet(S) <=> \\E n \\in Nat : ExistsSurjection(1..n,S)
1028
+
1029
+ LEMMA FS_NatBijection ==
1030
+ ASSUME NEW S
1031
+ PROVE IsFiniteSet(S) <=> \\E n \\in Nat : ExistsBijection(1..n,S)
1032
+
689
1033
 
690
1034
  (***************************************************************************)
691
- (* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
692
- (* the definition *)
1035
+ (* \`. .' *)
693
1036
  (* *)
694
- (* NotInSetS == CHOOSE v : v \\notin SetS *)
1037
+ (* If there exists n \\in Nat such that a bijection exists from 1..n to S, *)
1038
+ (* then Cardinality(S) = n. *)
1039
+ (* *)
1040
+ (* \`. .' *)
695
1041
  (***************************************************************************)
696
- THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
697
- OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
698
- -----------------------------------------------------------------------------
699
1042
 
1043
+ LEMMA FS_CountingElements ==
1044
+ ASSUME NEW S, NEW n \\in Nat, ExistsBijection(1..n,S)
1045
+ PROVE Cardinality(S) = n
700
1046
 
701
1047
 
702
- (********************************************************************)
703
- (********************************************************************)
704
- (********************************************************************)
1048
+ (***************************************************************************)
1049
+ (* Corollary: a surjection from 1..n to S provides a cardinality bound. *)
1050
+ (***************************************************************************)
1051
+ THEOREM FS_SurjCardinalityBound ==
1052
+ ASSUME NEW S, NEW n \\in Nat, ExistsSurjection(1..n, S)
1053
+ PROVE Cardinality(S) <= n
705
1054
 
706
1055
 
707
- (********************************************************************)
708
- (* Old versions of Zenon and Isabelle pragmas below *)
709
- (* (kept for compatibility) *)
710
- (********************************************************************)
1056
+ (***************************************************************************)
1057
+ (* \`. .' *)
1058
+ (* *)
1059
+ (* For any finite set S, Cardinality(S) \\in Nat. Moreover, there is a *)
1060
+ (* bijection from 1 .. Cardinality(S) to S. *)
1061
+ (* *)
1062
+ (* \`. .' *)
1063
+ (***************************************************************************)
1064
+ THEOREM FS_CardinalityType ==
1065
+ ASSUME NEW S, IsFiniteSet(S)
1066
+ PROVE /\\ Cardinality(S) \\in Nat
1067
+ /\\ ExistsBijection(1..Cardinality(S), S)
711
1068
 
712
1069
 
713
- (**************************************************************************)
714
- (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
715
- (* *)
716
- (**************************************************************************)
1070
+ (***************************************************************************)
1071
+ (* \`. .' *)
1072
+ (* *)
1073
+ (* The image of a finite set under a bijection is finite. *)
1074
+ (* *)
1075
+ (* \`. .' *)
1076
+ (***************************************************************************)
1077
+ THEOREM FS_Bijection ==
1078
+ ASSUME NEW S, NEW T, IsFiniteSet(S), ExistsBijection(S,T)
1079
+ PROVE /\\ IsFiniteSet(T)
1080
+ /\\ Cardinality(T) = Cardinality(S)
717
1081
 
718
- SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
719
- SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
720
- VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
721
- SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
1082
+ THEOREM FS_SameCardinalityBij ==
1083
+ ASSUME NEW S, NEW T, IsFiniteSet(S), IsFiniteSet(T),
1084
+ Cardinality(S) = Cardinality(T)
1085
+ PROVE ExistsBijection(S,T)
722
1086
 
723
1087
 
1088
+ (***************************************************************************)
1089
+ (* \`. .' *)
1090
+ (* *)
1091
+ (* Any surjection between two finite sets of equal cardinality is *)
1092
+ (* an injection. *)
1093
+ (* *)
1094
+ (* \`. .' *)
1095
+ (***************************************************************************)
1096
+ THEOREM FS_SurjSameCardinalityImpliesInj ==
1097
+ ASSUME NEW S, NEW T, IsFiniteSet(S), Cardinality(S) = Cardinality(T),
1098
+ NEW f \\in Surjection(S,T)
1099
+ PROVE f \\in Injection(S,T)
724
1100
 
725
- (********************************************************************)
726
- (* Backend pragma: Isabelle's automatic search ("auto") *)
727
- (* *)
728
- (* This pragma bypasses Zenon. It is useful in situations involving *)
729
- (* essentially simplification and equational reasoning. *)
730
- (* Default imeout for all isabelle tactics is 30 seconds. *)
731
- (********************************************************************)
732
- Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
733
- SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
734
- SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
735
- SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
736
1101
 
737
- (********************************************************************)
738
- (* Backend pragma: Isabelle's "force" tactic *)
739
- (* *)
740
- (* This pragma bypasses Zenon. It is useful in situations involving *)
741
- (* quantifier reasoning. *)
742
- (********************************************************************)
743
- Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
744
- SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
745
- SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
746
- SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
1102
+ (***************************************************************************)
1103
+ (* \`. .' *)
1104
+ (* *)
1105
+ (* The image of a finite set is finite. *)
1106
+ (* NB: Note that any function is a surjection on its range by theorem *)
1107
+ (* Fun_RangeProperties. *)
1108
+ (* *)
1109
+ (* \`. .' *)
1110
+ (***************************************************************************)
1111
+ THEOREM FS_Surjection ==
1112
+ ASSUME NEW S, NEW T, NEW f \\in Surjection(S,T), IsFiniteSet(S)
1113
+ PROVE /\\ IsFiniteSet(T)
1114
+ /\\ Cardinality(T) <= Cardinality(S)
1115
+ /\\ Cardinality(T) = Cardinality(S) <=> f \\in Injection(S,T)
1116
+
1117
+ THEOREM FS_Image ==
1118
+ ASSUME NEW S, IsFiniteSet(S), NEW Op(_)
1119
+ PROVE LET T == {Op(x) : x \\in S}
1120
+ IN /\\ IsFiniteSet(T)
1121
+ /\\ Cardinality(T) <= Cardinality(S)
747
1122
 
748
- (***********************************************************************)
749
- (* Backend pragma: Isabelle's "simplification" tactics *)
750
- (* *)
751
- (* These tactics simplify the goal before running one of the automated *)
752
- (* tactics. They are often necessary for obligations involving record *)
753
- (* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
754
- (* sure you can get away with just Simplification *)
755
- (***********************************************************************)
756
- SimplifyAndSolve == TRUE
757
- (*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
758
- SlowSimplifyAndSolve == TRUE
759
- (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
760
- SlowerSimplifyAndSolve == TRUE
761
- (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
762
- SlowestSimplifyAndSolve == TRUE
763
- (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
1123
+ (***************************************************************************)
1124
+ (* \`. .' *)
1125
+ (* *)
1126
+ (* Symmetric theorem for injections and the pigeonhole principle. *)
1127
+ (* *)
1128
+ (* \`. .' *)
1129
+ (***************************************************************************)
1130
+ THEOREM FS_Injection ==
1131
+ ASSUME NEW S, NEW T, NEW f \\in Injection(S,T), IsFiniteSet(T)
1132
+ PROVE /\\ IsFiniteSet(S)
1133
+ /\\ Cardinality(S) <= Cardinality(T)
1134
+ /\\ Cardinality(S) = Cardinality(T) <=> f \\in Surjection(S,T)
764
1135
 
765
- Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
766
- SlowSimplification == TRUE
767
- (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
768
- SlowerSimplification == TRUE
769
- (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
770
- SlowestSimplification == TRUE
771
- (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
1136
+ THEOREM FS_PigeonHole ==
1137
+ ASSUME NEW S, IsFiniteSet(S),
1138
+ NEW T, IsFiniteSet(T), Cardinality(T) < Cardinality(S),
1139
+ NEW f \\in [S -> T]
1140
+ PROVE \\E x,y \\in S : x # y /\\ f[x] = f[y]
772
1141
 
773
- (**************************************************************************)
774
- (* Backend pragma: Isabelle's tableau prover ("blast") *)
775
- (* *)
776
- (* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
777
- (* prover, Blast. It is almost never better than Zenon by itself, but *)
778
- (* becomes very useful in combination with the Auto pragma above. The *)
779
- (* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
780
- (* Auto could not prove. (There is currently no way to use Zenon on the *)
781
- (* results left over from Auto.) *)
782
- (**************************************************************************)
783
- Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
784
- SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
785
- SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
786
- SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
787
1142
 
788
- AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
1143
+ (***************************************************************************)
1144
+ (* \`. .' *)
1145
+ (* *)
1146
+ (* The cardinality of a finite set S is 0 iff S is empty. *)
1147
+ (* *)
1148
+ (* \`. .' *)
1149
+ (***************************************************************************)
1150
+ THEOREM FS_EmptySet ==
1151
+ /\\ IsFiniteSet({})
1152
+ /\\ Cardinality({}) = 0
1153
+ /\\ \\A S : IsFiniteSet(S) => (Cardinality(S) = 0 <=> S = {})
1154
+
1155
+
1156
+ (***************************************************************************)
1157
+ (* \`. .' *)
1158
+ (* *)
1159
+ (* If S is finite, so are S \\cup {x} and S \\ {x}. *)
1160
+ (* *)
1161
+ (* \`. .' *)
1162
+ (***************************************************************************)
1163
+ THEOREM FS_AddElement ==
1164
+ ASSUME NEW S, NEW x, IsFiniteSet(S)
1165
+ PROVE /\\ IsFiniteSet(S \\cup {x})
1166
+ /\\ Cardinality(S \\cup {x}) =
1167
+ IF x \\in S THEN Cardinality(S) ELSE Cardinality(S)+1
1168
+
1169
+ THEOREM FS_RemoveElement ==
1170
+ ASSUME NEW S, NEW x, IsFiniteSet(S)
1171
+ PROVE /\\ IsFiniteSet(S \\ {x})
1172
+ /\\ Cardinality(S \\ {x}) =
1173
+ IF x \\in S THEN Cardinality(S)-1 ELSE Cardinality(S)
1174
+
1175
+
1176
+ (***************************************************************************)
1177
+ (* \`. .' *)
1178
+ (* *)
1179
+ (* In particular, a singleton set is finite. *)
1180
+ (* *)
1181
+ (* \`. .' *)
1182
+ (***************************************************************************)
1183
+ THEOREM FS_Singleton ==
1184
+ /\\ \\A x : IsFiniteSet({x}) /\\ Cardinality({x}) = 1
1185
+ /\\ \\A S : IsFiniteSet(S) => (Cardinality(S) = 1 <=> \\E x: S = {x})
1186
+
1187
+
1188
+ (***************************************************************************)
1189
+ (* \`. .' *)
1190
+ (* *)
1191
+ (* Any subset of a finite set is finite. *)
1192
+ (* *)
1193
+ (* \`. .' *)
1194
+ (***************************************************************************)
1195
+ THEOREM FS_Subset ==
1196
+ ASSUME NEW S, IsFiniteSet(S), NEW T \\in SUBSET S
1197
+ PROVE /\\ IsFiniteSet(T)
1198
+ /\\ Cardinality(T) <= Cardinality(S)
1199
+ /\\ Cardinality(S) = Cardinality(T) => S = T
1200
+
1201
+
1202
+ (***************************************************************************)
1203
+ (* \`. .' *)
1204
+ (* *)
1205
+ (* a..b is a finite set for any a,b \\in Int. *)
1206
+ (* *)
1207
+ (* \`. .' *)
1208
+ (***************************************************************************)
1209
+ THEOREM FS_Interval ==
1210
+ ASSUME NEW a \\in Int, NEW b \\in Int
1211
+ PROVE /\\ IsFiniteSet(a..b)
1212
+ /\\ Cardinality(a..b) = IF a > b THEN 0 ELSE b-a+1
1213
+
1214
+ THEOREM FS_BoundedSetOfNaturals ==
1215
+ ASSUME NEW S \\in SUBSET Nat, NEW n \\in Nat,
1216
+ \\A s \\in S : s <= n
1217
+ PROVE /\\ IsFiniteSet(S)
1218
+ /\\ Cardinality(S) \\leq n+1
1219
+
1220
+
1221
+ (***************************************************************************)
1222
+ (* \`. .' *)
1223
+ (* *)
1224
+ (* Induction for finite sets. *)
1225
+ (* *)
1226
+ (* \`. .' *)
1227
+ (***************************************************************************)
1228
+
1229
+ THEOREM FS_Induction ==
1230
+ ASSUME NEW S, IsFiniteSet(S),
1231
+ NEW P(_), P({}),
1232
+ ASSUME NEW T \\in SUBSET S, IsFiniteSet(T), P(T), NEW x \\in S \\ T
1233
+ PROVE P(T \\cup {x})
1234
+ PROVE P(S)
1235
+
1236
+
1237
+ (***************************************************************************)
1238
+ (* \`. .' *)
1239
+ (* *)
1240
+ (* The finite subsets form a well-founded ordering with respect to strict *)
1241
+ (* set inclusion. *)
1242
+ (* *)
1243
+ (* \`. .' *)
1244
+ (***************************************************************************)
1245
+
1246
+ FiniteSubsetsOf(S) == { T \\in SUBSET S : IsFiniteSet(T) }
1247
+ StrictSubsetOrdering(S) == { ss \\in (SUBSET S) \\X (SUBSET S) :
1248
+ ss[1] \\subseteq ss[2] /\\ ss[1] # ss[2] }
1249
+
1250
+ LEMMA FS_FiniteSubsetsOfFinite ==
1251
+ ASSUME NEW S, IsFiniteSet(S)
1252
+ PROVE FiniteSubsetsOf(S) = SUBSET S
1253
+
1254
+
1255
+ (*****************************************************************************)
1256
+ (* The formulation of the following theorem doesn't require S being finite. *)
1257
+ (* If S is finite, it implies *)
1258
+ (* IsWellFoundedOn(StrictSubsetOrdering(S), SUBSET S) *)
1259
+ (* using lemma FS_FiniteSubsetsOfFinite. *)
1260
+ (*****************************************************************************)
1261
+ THEOREM FS_StrictSubsetOrderingWellFounded ==
1262
+ ASSUME NEW S
1263
+ PROVE IsWellFoundedOn(StrictSubsetOrdering(S), FiniteSubsetsOf(S))
1264
+
1265
+
1266
+ (***************************************************************************)
1267
+ (* \`. .' *)
1268
+ (* *)
1269
+ (* Well-founded induction for finite subsets. *)
1270
+ (* *)
1271
+ (* \`. .' *)
1272
+ (***************************************************************************)
1273
+
1274
+ THEOREM FS_WFInduction ==
1275
+ ASSUME NEW P(_), NEW S, IsFiniteSet(S),
1276
+ ASSUME NEW T \\in SUBSET S,
1277
+ \\A U \\in (SUBSET T) \\ {T} : P(U)
1278
+ PROVE P(T)
1279
+ PROVE P(S)
1280
+
1281
+
1282
+ (***************************************************************************)
1283
+ (* \`. .' *)
1284
+ (* *)
1285
+ (* The union of two finite sets is finite. *)
1286
+ (* *)
1287
+ (* \`. .' *)
1288
+ (***************************************************************************)
1289
+ THEOREM FS_Union ==
1290
+ ASSUME NEW S, IsFiniteSet(S),
1291
+ NEW T, IsFiniteSet(T)
1292
+ PROVE /\\ IsFiniteSet(S \\cup T)
1293
+ /\\ Cardinality(S \\cup T) =
1294
+ Cardinality(S) + Cardinality(T) - Cardinality(S \\cap T)
1295
+
1296
+
1297
+ (***************************************************************************)
1298
+ (* \`. .' *)
1299
+ (* *)
1300
+ (* Corollary: two majorities intersect. More precisely, any two subsets *)
1301
+ (* of a finite set U such that the sum of cardinalities of the subsets *)
1302
+ (* exceeds that of U must have non-empty intersection. *)
1303
+ (* *)
1304
+ (* \`. .' *)
1305
+ (***************************************************************************)
1306
+ THEOREM FS_MajoritiesIntersect ==
1307
+ ASSUME NEW U, NEW S, NEW T, IsFiniteSet(U),
1308
+ S \\subseteq U, T \\subseteq U,
1309
+ Cardinality(S) + Cardinality(T) > Cardinality(U)
1310
+ PROVE S \\cap T # {}
1311
+
1312
+
1313
+ (***************************************************************************)
1314
+ (* \`. .' *)
1315
+ (* *)
1316
+ (* The intersection of a finite set with an arbitrary set is finite. *)
1317
+ (* *)
1318
+ (* \`. .' *)
1319
+ (***************************************************************************)
1320
+
1321
+
1322
+ THEOREM FS_Intersection ==
1323
+ ASSUME NEW S, IsFiniteSet(S), NEW T
1324
+ PROVE /\\ IsFiniteSet(S \\cap T)
1325
+ /\\ IsFiniteSet(T \\cap S)
1326
+ /\\ Cardinality(S \\cap T) <= Cardinality(S)
1327
+ /\\ Cardinality(T \\cap S) <= Cardinality(S)
1328
+
1329
+
1330
+ (***************************************************************************)
1331
+ (* \`. .' *)
1332
+ (* *)
1333
+ (* The difference between a finite set and an arbitrary set is finite. *)
1334
+ (* *)
1335
+ (* \`. .' *)
1336
+ (***************************************************************************)
1337
+ THEOREM FS_Difference ==
1338
+ ASSUME NEW S, NEW T, IsFiniteSet(S)
1339
+ PROVE /\\ IsFiniteSet(S \\ T)
1340
+ /\\ Cardinality(S \\ T) = Cardinality(S) - Cardinality(S \\cap T)
1341
+
1342
+
1343
+ (***************************************************************************)
1344
+ (* \`. .' *)
1345
+ (* *)
1346
+ (* The union of a finite number of finite sets is finite. *)
1347
+ (* *)
1348
+ (* \`. .' *)
1349
+ (***************************************************************************)
1350
+ THEOREM FS_UNION ==
1351
+ ASSUME NEW S, IsFiniteSet(S), \\A T \\in S : IsFiniteSet(T)
1352
+ PROVE IsFiniteSet(UNION S)
1353
+
1354
+
1355
+ (***************************************************************************)
1356
+ (* \`. .' *)
1357
+ (* *)
1358
+ (* The product of two finite sets is finite. *)
1359
+ (* *)
1360
+ (* \`. .' *)
1361
+ (***************************************************************************)
1362
+ THEOREM FS_Product ==
1363
+ ASSUME NEW S, IsFiniteSet(S),
1364
+ NEW T, IsFiniteSet(T)
1365
+ PROVE /\\ IsFiniteSet(S \\X T)
1366
+ /\\ Cardinality(S \\X T) = Cardinality(S) * Cardinality(T)
1367
+
1368
+
1369
+ (***************************************************************************)
1370
+ (* \`. .' *)
1371
+ (* *)
1372
+ (* The powerset of a finite set is finite. *)
1373
+ (* *)
1374
+ (* \`. .' *)
1375
+ (***************************************************************************)
1376
+ THEOREM FS_SUBSET ==
1377
+ ASSUME NEW S, IsFiniteSet(S)
1378
+ PROVE /\\ IsFiniteSet(SUBSET S)
1379
+ /\\ Cardinality(SUBSET S) = 2^Cardinality(S)
1380
+
1381
+ =============================================================================
1382
+ \\* Modification History
1383
+ \\* Last modified Wed Jan 08 17:43:30 CET 2020 by merz
1384
+ \\* Last modified Thu Jul 04 15:15:07 CEST 2013 by bhargav
1385
+ \\* Last modified Tue Jun 04 11:44:51 CEST 2013 by bhargav
1386
+ \\* Last modified Fri May 03 12:02:51 PDT 2013 by tomr
1387
+ \\* Created Fri Oct 05 15:04:18 PDT 2012 by tomr
1388
+ `],[`Folds`,`------------------------------- MODULE Folds -------------------------------
1389
+ (***************************************************************************)
1390
+ (* This module provides a general framework for folding operations over *)
1391
+ (* sets with flexible element selection and transformation. *)
1392
+ (* *)
1393
+ (* The main operator MapThenFoldSet is the foundation for many other *)
1394
+ (* folding operations found in: *)
1395
+ (* - FiniteSetsExt.FoldSet (simplified for sets) *)
1396
+ (* - Functions.FoldFunction (specialized for functions) *)
1397
+ (* - SequencesExt.FoldSeq (specialized for sequences) *)
1398
+ (* *)
1399
+ (***************************************************************************)
1400
+
1401
+ MapThenFoldSet(op(_,_), base, f(_), choose(_), S) ==
1402
+ (******************************************************************************)
1403
+ (* Starting from base, apply op to f(x), for all x \\in S, by choosing the set *)
1404
+ (* elements with \`choose\`. If there are multiple ways for choosing an element,*)
1405
+ (* op should be associative and commutative. Otherwise, the result may depend *)
1406
+ (* on the concrete implementation of \`choose\`. *)
1407
+ (* *)
1408
+ (* FoldSet, a simpler version for sets is contained in FiniteSetsEx. *)
1409
+ (* FoldFunction, a simpler version for functions is contained in Functions. *)
1410
+ (* FoldSequence, a simpler version for sequences is contained in SequencesExt.*)
1411
+ (* *)
1412
+ (* Example: *)
1413
+ (* *)
1414
+ (* MapThenFoldSet(LAMBDA x,y: x \\cup y, *)
1415
+ (* {}, *)
1416
+ (* LAMBDA x: {{x}}, *)
1417
+ (* LAMBDA set: CHOOSE x \\in set: TRUE, *)
1418
+ (* {1,2}) *)
1419
+ (* = {{1},{2}} *)
1420
+ (******************************************************************************)
1421
+ LET iter[s \\in SUBSET S] ==
1422
+ IF s = {} THEN base
1423
+ ELSE LET x == choose(s)
1424
+ IN op(f(x), iter[s \\ {x}])
1425
+ IN iter[S]
1426
+
1427
+
1428
+ =============================================================================
1429
+ `],[`Functions`,`------------------------------ MODULE Functions -----------------------------
1430
+ (***************************************************************************)
1431
+ (* \`^{\\large\\bf \\vspace{12pt} *)
1432
+ (* Notions about functions including injection, surjection, and bijection.*)
1433
+ (* Originally contributed by Tom Rodeheffer, MSR. *)
1434
+ (* \\vspace{12pt}}^' *)
1435
+ (***************************************************************************)
1436
+
1437
+ EXTENDS Integers, Folds
1438
+
1439
+ (***************************************************************************)
1440
+ (* Restriction of a function to a set (should be a subset of the domain). *)
1441
+ (***************************************************************************)
1442
+ Restrict(f,S) == [ x \\in S |-> f[x] ]
1443
+
1444
+ (***************************************************************************)
1445
+ (* Restriction of a function to the subset of its domain satisfying a *)
1446
+ (* test predicate. *)
1447
+ (* *)
1448
+ (* Example: *)
1449
+ (* (LET f == (0 :> "a" @@ 1 :> "b" @@ 2 :> "c") *)
1450
+ (* IN RestrictDomain(f, LAMBDA x : x \\in {0,2})) *)
1451
+ (* = (0 :> "a" @@ 2 :> "c") *)
1452
+ (***************************************************************************)
1453
+ RestrictDomain(f, Test(_)) == Restrict(f, {x \\in DOMAIN f : Test(x)})
1454
+
1455
+ (***************************************************************************)
1456
+ (* Restriction of a function to the subset of its domain for which the *)
1457
+ (* function values satisfy a test predicate. *)
1458
+ (* *)
1459
+ (* Example: *)
1460
+ (* (LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
1461
+ (* IN RestrictValues(f, LAMBDA y : y \\in {0,2})) *)
1462
+ (* = ("a" :> 0 @@ "b" :> 2) *)
1463
+ (* *)
1464
+ (* This is similar to the operator SelectSeq from the standard Sequences *)
1465
+ (* module and related to standard "filter" functions in functional *)
1466
+ (* programming. However, SelectSeq produces sequences, whereas *)
1467
+ (* RestrictValues will in general not. For example, *)
1468
+ (* *)
1469
+ (* RestrictValues([0,1,2], LAMBDA y : y \\in {0,2}) *)
1470
+ (* = (1 :> 0 @@ 3 :> 2) *)
1471
+ (***************************************************************************)
1472
+ RestrictValues(f, Test(_)) ==
1473
+ LET S == {x \\in DOMAIN f : Test(f[x])}
1474
+ IN Restrict(f, S)
1475
+
1476
+ (***************************************************************************)
1477
+ (* Check if a function narrow is a restriction of a function wide, i.e. *)
1478
+ (* Is the domain of narrow a subset of that of wide, and does the *)
1479
+ (* projection of wide on the domain of narrow have the same image as *)
1480
+ (* narrow does. *)
1481
+ (* *)
1482
+ (* Examples: *)
1483
+ (* IsRestriction([one |-> 1], [one |-> 1, two |-> 2]) *)
1484
+ (* IsRestriction([one |-> 1], [one |-> 1]) *)
1485
+ (* ~IsRestriction([one |-> 1, two |-> 2], [one |-> 1, two |-> 3]) *)
1486
+ (* ~IsRestriction([one |-> 1], [2 |-> two]) *)
1487
+ (* ~IsRestriction([one |-> 1, two |-> 2], [two |-> 2]) *)
1488
+ (***************************************************************************)
1489
+ IsRestriction(narrow, wide) ==
1490
+ /\\ DOMAIN narrow \\subseteq DOMAIN wide
1491
+ /\\ \\A x \\in DOMAIN narrow \\intersect DOMAIN wide: narrow[x] = wide[x]
1492
+
1493
+ (***************************************************************************)
1494
+ (* Range of a function. *)
1495
+ (* Note: The image of a set under function f can be defined as *)
1496
+ (* Range(Restrict(f,S)). *)
1497
+ (***************************************************************************)
1498
+ Range(f) == { f[x] : x \\in DOMAIN f }
1499
+
1500
+ (***************************************************************************)
1501
+ (* Assuming DOMAIN f \\subseteq DOMAIN g, apply the binary operation T to *)
1502
+ (* the corresponding elements of the two functions f and g. *)
1503
+ (* *)
1504
+ (* Example: *)
1505
+ (* LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
1506
+ (* g == ("a" :> 1 @@ "b" :> 1 @@ "c" :> 3) *)
1507
+ (* IN Pointwise(f,g,+) = ("a" :> 1 @@ "b" :> 2 @@ "c" :> 5 ) *)
1508
+ (***************************************************************************)
1509
+ Pointwise(f, g, T(_,_)) == [ e \\in DOMAIN f |-> T(f[e], g[e]) ]
1510
+
1511
+ (***************************************************************************)
1512
+ (* The inverse of a function. *)
1513
+ (* Example: *)
1514
+ (* LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
1515
+ (* IN Inverse(f, DOMAIN f, Range(f)) = *)
1516
+ (* (0 :> "a" @@ 1 :> "b" @@ 2 :> "c") *)
1517
+ (* Example: *)
1518
+ (* LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
1519
+ (* IN Inverse(f, DOMAIN f, {1,3}) = *)
1520
+ (* 1 :> "b" @@ 3 :> "a") *)
1521
+ (***************************************************************************)
1522
+ Inverse(f,S,T) == [t \\in T |-> CHOOSE s \\in S : t \\in Range(f) => f[s] = t]
1523
+
1524
+ (***************************************************************************)
1525
+ (* The inverse of a function. *)
1526
+ (***************************************************************************)
1527
+ AntiFunction(f) == Inverse(f, DOMAIN f, Range(f))
1528
+
1529
+ (***************************************************************************)
1530
+ (* A function is injective iff it maps each element in its domain to a *)
1531
+ (* distinct element. *)
1532
+ (* *)
1533
+ (* This definition is overridden by TLC in the Java class Functions.java *)
1534
+ (* The operator is overridden by the Java method with the same name. *)
1535
+ (***************************************************************************)
1536
+ IsInjective(f) == \\A a,b \\in DOMAIN f : f[a] = f[b] => a = b
1537
+
1538
+ (***************************************************************************)
1539
+ (* Set of injections between two sets. *)
1540
+ (***************************************************************************)
1541
+ Injection(S,T) == { M \\in [S -> T] : IsInjective(M) }
1542
+
1543
+
1544
+ (***************************************************************************)
1545
+ (* A map is a surjection iff for each element in the range there is some *)
1546
+ (* element in the domain that maps to it. *)
1547
+ (***************************************************************************)
1548
+ Surjection(S,T) == { M \\in [S -> T] : \\A t \\in T : \\E s \\in S : M[s] = t }
1549
+
1550
+
1551
+ (***************************************************************************)
1552
+ (* A map is a bijection iff it is both an injection and a surjection. *)
1553
+ (***************************************************************************)
1554
+ Bijection(S,T) == Injection(S,T) \\cap Surjection(S,T)
1555
+
1556
+
1557
+ (***************************************************************************)
1558
+ (* An injection, surjection, or bijection exists if the corresponding set *)
1559
+ (* is nonempty. *)
1560
+ (***************************************************************************)
1561
+ ExistsInjection(S,T) == Injection(S,T) # {}
1562
+ ExistsSurjection(S,T) == Surjection(S,T) # {}
1563
+ ExistsBijection(S,T) == Bijection(S,T) # {}
1564
+
1565
+ --------------------------------------------------------------------------------
1566
+
1567
+ (***************************************************************************)
1568
+ (* Applies the binary operator op on the elements f[i] for i \\in indices, *)
1569
+ (* a subset of DOMAIN f, in an unspecified order, starting from value *)
1570
+ (* base. The result is *)
1571
+ (* op(f[i],op(f[j], ..., op(f[k],base) ...)) *)
1572
+ (* where i,j,k range over the sets indices. *)
1573
+ (* *)
1574
+ (* op should be associative and commutative, because we can not assume a *)
1575
+ (* particular ordering of i, j, and k *)
1576
+ (* *)
1577
+ (* Example: *)
1578
+ (* FoldFunctionOnSet(LAMBDA x,y: {x} \\cup y, {}, <<1,2>>, {}) = {} *)
1579
+ (***************************************************************************)
1580
+ FoldFunctionOnSet(op(_,_), base, fun, indices) ==
1581
+ MapThenFoldSet(op, base, LAMBDA i : fun[i], LAMBDA s: CHOOSE x \\in s : TRUE, indices)
1582
+
1583
+ (***************************************************************************)
1584
+ (* Special case of the above where indices = DOMAIN fun. In other words, *)
1585
+ (* the values f[i] for all i \\in DOMAIN fun, are combined using the binary *)
1586
+ (* operator op, in an unspecified order. *)
1587
+ (* *)
1588
+ (* Example: *)
1589
+ (* FoldFunction(LAMBDA x,y: {x} \\cup y, {}, <<1,2,1>>) = {1,2} *)
1590
+ (***************************************************************************)
1591
+ FoldFunction(op(_,_), base, fun) ==
1592
+ FoldFunctionOnSet(op, base, fun, DOMAIN fun)
1593
+
1594
+ (***************************************************************************)
1595
+ (* Sum the values f[i] for i \\in indices, a subset of DOMAIN f. *)
1596
+ (* *)
1597
+ (* Example: *)
1598
+ (* SumFunctionOnSet(<<4,5,6>>, {1,2}) = 9 *)
1599
+ (* SumFunction(<<4,5,6>>) = 15 *)
1600
+ (***************************************************************************)
1601
+ SumFunctionOnSet(fun, indices) == FoldFunctionOnSet(+, 0, fun, indices)
1602
+ SumFunction(fun) == SumFunctionOnSet(fun, DOMAIN fun)
1603
+
1604
+ =============================================================================
1605
+ \\* Created Thu Apr 11 10:30:48 PDT 2013 by tomr
1606
+ `],[`FunctionTheorems`,`------------------------ MODULE FunctionTheorems ----------------------------
1607
+ (***************************************************************************)
1608
+ (* \`^{\\large \\vspace{12pt} *)
1609
+ (* Proofs of facts about functions. *)
1610
+ (* Originally contributed by Tom Rodeheffer, MSR. *)
1611
+ (* \\vspace{12pt}}^' *)
1612
+ (***************************************************************************)
1613
+
1614
+ EXTENDS Functions, Integers, FiniteSets
1615
+
1616
+ (***************************************************************************)
1617
+ (* \`. .' *)
1618
+ (* *)
1619
+ (* Function restriction. *)
1620
+ (* *)
1621
+ (* \`. .' *)
1622
+ (***************************************************************************)
1623
+ THEOREM Fun_RestrictProperties ==
1624
+ ASSUME NEW S, NEW T, NEW f \\in [S -> T], NEW A \\in SUBSET S
1625
+ PROVE /\\ Restrict(f,A) \\in [A -> T]
1626
+ /\\ \\A x \\in A : Restrict(f,A)[x] = f[x]
1627
+
1628
+ (***************************************************************************)
1629
+ (* \`. .' *)
1630
+ (* *)
1631
+ (* Range of a function. *)
1632
+ (* *)
1633
+ (* \`. .' *)
1634
+ (***************************************************************************)
1635
+ THEOREM Fun_RangeProperties ==
1636
+ ASSUME NEW S, NEW T, NEW f \\in [S -> T]
1637
+ PROVE /\\ Range(f) \\subseteq T
1638
+ /\\ \\A y \\in Range(f) : \\E x \\in S : f[x] = y
1639
+ /\\ f \\in Surjection(S, Range(f))
1640
+
1641
+
1642
+ (***************************************************************************)
1643
+ (* \`. .' *)
1644
+ (* *)
1645
+ (* Inverse of a function. *)
1646
+ (* *)
1647
+ (* \`. .' *)
1648
+ (***************************************************************************)
1649
+ THEOREM Fun_InverseProperties ==
1650
+ ASSUME NEW S, NEW T, NEW f \\in [S -> T]
1651
+ PROVE /\\ (S = {} => T = {}) => Inverse(f,S,T) \\in [T -> S]
1652
+ /\\ \\A y \\in Range(f) : f[Inverse(f,S,T)[y]] = y
1653
+
1654
+
1655
+ (***************************************************************************)
1656
+ (* \`. .' *)
1657
+ (* *)
1658
+ (* Introduction rules for injections, surjections, bijections. *)
1659
+ (* *)
1660
+ (* \`. .' *)
1661
+ (***************************************************************************)
1662
+ THEOREM Fun_IsInj ==
1663
+ ASSUME NEW S, NEW T, NEW F \\in [S -> T],
1664
+ \\A a,b \\in S : F[a] = F[b] => a = b
1665
+ PROVE F \\in Injection(S,T)
1666
+
1667
+ THEOREM Fun_IsSurj ==
1668
+ ASSUME NEW S, NEW T, NEW F \\in [S -> T],
1669
+ \\A t \\in T : \\E s \\in S : F[s] = t
1670
+ PROVE F \\in Surjection(S,T)
1671
+
1672
+ THEOREM Fun_IsBij ==
1673
+ ASSUME NEW S, NEW T, NEW F,
1674
+ \\/ F \\in Injection(S,T)
1675
+ \\/ (F \\in [S -> T] /\\ \\A a,b \\in S : F[a] = F[b] => a = b),
1676
+
1677
+ \\/ F \\in Surjection(S,T)
1678
+ \\/ (F \\in [S -> T] /\\ \\A t \\in T : \\E s \\in S : F[s] = t)
1679
+ PROVE F \\in Bijection(S,T)
1680
+
1681
+
1682
+
1683
+ (***************************************************************************)
1684
+ (* \`. .' *)
1685
+ (* *)
1686
+ (* Properties of injections, surjections, and bijections. *)
1687
+ (* *)
1688
+ (* \`. .' *)
1689
+ (***************************************************************************)
1690
+ THEOREM Fun_InjectionProperties ==
1691
+ ASSUME NEW S, NEW T, NEW F \\in Injection(S,T)
1692
+ PROVE /\\ F \\in [S -> T]
1693
+ /\\ \\A a,b \\in S : F[a] = F[b] => a = b
1694
+
1695
+ THEOREM Fun_SurjectionProperties ==
1696
+ ASSUME NEW S, NEW T, NEW F \\in Surjection(S,T)
1697
+ PROVE /\\ F \\in [S -> T]
1698
+ /\\ \\A t \\in T : \\E s \\in S : F[s] = t
1699
+ /\\ Range(F) = T
1700
+
1701
+ THEOREM Fun_BijectionProperties ==
1702
+ ASSUME NEW S, NEW T, NEW F \\in Bijection(S,T)
1703
+ PROVE /\\ F \\in [S -> T]
1704
+ /\\ F \\in Injection(S,T)
1705
+ /\\ F \\in Surjection(S,T)
1706
+ /\\ \\A a,b \\in S : F[a] = F[b] => a = b
1707
+ /\\ \\A t \\in T : \\E s \\in S : F[s] = t
1708
+
1709
+
1710
+ (***************************************************************************)
1711
+ (* \`. .' *)
1712
+ (* *)
1713
+ (* A surjection in [S -> T] such that there is no surjection from any *)
1714
+ (* subset of S to T is a bijection. *)
1715
+ (* *)
1716
+ (* \`. .' *)
1717
+ (***************************************************************************)
1718
+ THEOREM Fun_SmallestSurjectionIsBijection ==
1719
+ ASSUME NEW S, NEW T, NEW f \\in Surjection(S,T),
1720
+ \\A U \\in SUBSET S : U # S => Surjection(U,T) = {}
1721
+ PROVE f \\in Bijection(S,T)
1722
+
1723
+
1724
+ (***************************************************************************)
1725
+ (* \`. .' *)
1726
+ (* *)
1727
+ (* Transitivity of injections, surjections, bijections. *)
1728
+ (* *)
1729
+ (* \`. .' *)
1730
+ (***************************************************************************)
1731
+ THEOREM Fun_InjTransitive ==
1732
+ ASSUME NEW S, NEW T, NEW U,
1733
+ NEW F \\in Injection(S,T),
1734
+ NEW G \\in Injection(T,U)
1735
+ PROVE [s \\in S |-> G[F[s]]] \\in Injection(S,U)
1736
+
1737
+ THEOREM Fun_SurjTransitive ==
1738
+ ASSUME NEW S, NEW T, NEW U,
1739
+ NEW F \\in Surjection(S,T),
1740
+ NEW G \\in Surjection(T,U)
1741
+ PROVE [s \\in S |-> G[F[s]]] \\in Surjection(S,U)
1742
+
1743
+ THEOREM Fun_BijTransitive ==
1744
+ ASSUME NEW S, NEW T, NEW U,
1745
+ NEW F \\in Bijection(S,T),
1746
+ NEW G \\in Bijection(T,U)
1747
+ PROVE [s \\in S |-> G[F[s]]] \\in Bijection(S,U)
1748
+
1749
+
1750
+ (***************************************************************************)
1751
+ (* \`. .' *)
1752
+ (* *)
1753
+ (* The inverse of a surjection is an injection and vice versa. *)
1754
+ (* *)
1755
+ (* \`. .' *)
1756
+ (***************************************************************************)
1757
+ THEOREM Fun_SurjInverse ==
1758
+ ASSUME NEW S, NEW T, NEW f \\in Surjection(S,T)
1759
+ PROVE Inverse(f,S,T) \\in Injection(T,S)
1760
+
1761
+ THEOREM Fun_InjInverse ==
1762
+ ASSUME NEW S, NEW T, NEW f \\in Injection(S,T), S = {} => T = {}
1763
+ PROVE Inverse(f,S,T) \\in Surjection(T,S)
1764
+
1765
+
1766
+ (***************************************************************************)
1767
+ (* \`. .' *)
1768
+ (* *)
1769
+ (* Properties of the inverse of a bijection. *)
1770
+ (* *)
1771
+ (* \`. .' *)
1772
+ (***************************************************************************)
1773
+ THEOREM Fun_BijInverse ==
1774
+ ASSUME NEW S, NEW T, NEW f \\in Bijection(S,T)
1775
+ PROVE /\\ Inverse(f,S,T) \\in Bijection(T,S)
1776
+ /\\ \\A s \\in S : Inverse(f,S,T)[f[s]] = s
1777
+ /\\ Inverse(Inverse(f,S,T), T,S) = f
1778
+
1779
+ (***************************************************************************)
1780
+ (* We cannot conclude that a function f is a bijection if its inverse is *)
1781
+ (* a bijection, and the following is a counter-example. *)
1782
+ (* *)
1783
+ (* S = {1,2} T = {3,4} *)
1784
+ (* f = [x \\in S |-> 3] *)
1785
+ (* *)
1786
+ (* Then, Inverse(f,S,T) can very well be (3 :> 1) @@ (4 :> 2), which is a *)
1787
+ (* bijection although f is not. *)
1788
+ (***************************************************************************)
1789
+
1790
+ (***************************************************************************)
1791
+ (* \`. .' *)
1792
+ (* *)
1793
+ (* The restriction of a bijection is a bijection. *)
1794
+ (* *)
1795
+ (* \`. .' *)
1796
+ (***************************************************************************)
1797
+ THEOREM Fun_BijRestrict ==
1798
+ ASSUME NEW S, NEW T, NEW F \\in Bijection(S,T),
1799
+ NEW R \\in SUBSET S
1800
+ PROVE Restrict(F, R) \\in Bijection(R, Range(Restrict(F, R)))
1801
+
1802
+
1803
+ (***************************************************************************)
1804
+ (* \`. .' *)
1805
+ (* *)
1806
+ (* Given F an injection from S to T, then F is a bijection from S to F(S). *)
1807
+ (* *)
1808
+ (* \`. .' *)
1809
+ (***************************************************************************)
1810
+ THEOREM Fun_InjMeansBijImage ==
1811
+ ASSUME NEW S, NEW T, NEW F \\in Injection(S,T)
1812
+ PROVE F \\in Bijection(S, Range(F))
1813
+
1814
+
1815
+ -----------------------------------------------------------------------------
1816
+ (***************************************************************************)
1817
+ (* \`^{\\large \\vspace{12pt} *)
1818
+ (* Facts about exists jections. *)
1819
+ (* \\vspace{12pt}}^' *)
1820
+ (***************************************************************************)
1821
+
1822
+
1823
+
1824
+ (***************************************************************************)
1825
+ (* \`. .' *)
1826
+ (* *)
1827
+ (* Definitions restated as facts. *)
1828
+ (* *)
1829
+ (* \`. .' *)
1830
+ (***************************************************************************)
1831
+ THEOREM Fun_ExistsInj ==
1832
+ \\A S,T : ExistsInjection(S,T) <=> Injection(S,T) # {}
1833
+
1834
+ THEOREM Fun_ExistsSurj ==
1835
+ \\A S,T : ExistsSurjection(S,T) <=> Surjection(S,T) # {}
1836
+
1837
+ THEOREM Fun_ExistsBij ==
1838
+ \\A S,T : ExistsBijection(S,T) <=> Bijection(S,T) # {}
1839
+
1840
+
1841
+ (***************************************************************************)
1842
+ (* \`. .' *)
1843
+ (* *)
1844
+ (* There is a surjection from any set S to any non-empty subset T of S. *)
1845
+ (* (Note that there cannot be a surjection to {} except if S is empty.) *)
1846
+ (* *)
1847
+ (* \`. .' *)
1848
+ (***************************************************************************)
1849
+ THEOREM Fun_ExistsSurjSubset ==
1850
+ ASSUME NEW S, NEW T \\in SUBSET S, T # {}
1851
+ PROVE ExistsSurjection(S,T)
1852
+
1853
+
1854
+ (***************************************************************************)
1855
+ (* \`. .' *)
1856
+ (* *)
1857
+ (* If there is a surjection from S to T, then there is an injection from T *)
1858
+ (* to S. *)
1859
+ (* *)
1860
+ (* \`. .' *)
1861
+ (***************************************************************************)
1862
+ THEOREM Fun_ExistsSurjMeansExistsRevInj ==
1863
+ ASSUME NEW S, NEW T, ExistsSurjection(S,T)
1864
+ PROVE ExistsInjection(T,S)
1865
+
1866
+
1867
+ (***************************************************************************)
1868
+ (* \`. .' *)
1869
+ (* *)
1870
+ (* ExistsBijection is reflexive, symmetric, and transitive. *)
1871
+ (* *)
1872
+ (* \`. .' *)
1873
+ (***************************************************************************)
1874
+ THEOREM Fun_ExistsBijReflexive ==
1875
+ ASSUME NEW S
1876
+ PROVE ExistsBijection(S,S)
1877
+
1878
+ THEOREM Fun_ExistsBijSymmetric ==
1879
+ ASSUME NEW S, NEW T, ExistsBijection(S,T)
1880
+ PROVE ExistsBijection(T,S)
1881
+
1882
+ THEOREM Fun_ExistsBijTransitive ==
1883
+ ASSUME NEW S, NEW T, NEW U, ExistsBijection(S,T), ExistsBijection(T,U)
1884
+ PROVE ExistsBijection(S,U)
1885
+
1886
+
1887
+ (***************************************************************************)
1888
+ (* \`. .' *)
1889
+ (* *)
1890
+ (* Existence of injections and surjections is reflexive and transitive. *)
1891
+ (* *)
1892
+ (* \`. .' *)
1893
+ (***************************************************************************)
1894
+ THEOREM Fun_ExistsInjReflexive ==
1895
+ ASSUME NEW S
1896
+ PROVE ExistsInjection(S,S)
1897
+
1898
+ THEOREM Fun_ExistsSurjReflexive ==
1899
+ ASSUME NEW S
1900
+ PROVE ExistsSurjection(S,S)
1901
+
1902
+ THEOREM Fun_ExistsInjTransitive ==
1903
+ ASSUME NEW S, NEW T, NEW U,
1904
+ ExistsInjection(S,T), ExistsInjection(T,U)
1905
+ PROVE ExistsInjection(S,U)
1906
+
1907
+ THEOREM Fun_ExistsSurjTransitive ==
1908
+ ASSUME NEW S, NEW T, NEW U,
1909
+ ExistsSurjection(S,T), ExistsSurjection(T,U)
1910
+ PROVE ExistsSurjection(S,U)
1911
+
1912
+
1913
+ -----------------------------------------------------------------------------
1914
+ (***************************************************************************)
1915
+ (* \`^{\\large \\vspace{12pt} *)
1916
+ (* The Cantor-Bernstein-Schroeder theorem. *)
1917
+ (* \\vspace{12pt}}^' *)
1918
+ (***************************************************************************)
1919
+
1920
+
1921
+ (***************************************************************************)
1922
+ (* \`. .' *)
1923
+ (* *)
1924
+ (* If there exists an injection from S to T, where T is a subset of S, *)
1925
+ (* then there exists a bijection from S to T. *)
1926
+ (* *)
1927
+ (* A lemma for the Cantor-Bernstein-Schroeder theorem. *)
1928
+ (* *)
1929
+ (* This proof is formalized from *)
1930
+ (* \`^\\url{http://www.proofwiki.org/wiki/Cantor-Bernstein-Schroeder\\_Theorem/Lemma}^' *)
1931
+ (* retrieved April 29, 2013. *)
1932
+ (* *)
1933
+ (* \`. .' *)
1934
+ (***************************************************************************)
1935
+ THEOREM Fun_CantorBernsteinSchroeder_Lemma ==
1936
+ ASSUME NEW S, NEW T, T \\subseteq S, ExistsInjection(S,T)
1937
+ PROVE ExistsBijection(S,T)
1938
+
1939
+
1940
+ (***************************************************************************)
1941
+ (* \`. .' *)
1942
+ (* *)
1943
+ (* If an injection exists from S to T and an injection exists from T to S, *)
1944
+ (* then there is a bijection from S to T. *)
1945
+ (* *)
1946
+ (* This is the Cantor-Bernstein-Schroeder theorem. *)
1947
+ (* *)
1948
+ (* This proof is formalized from *)
1949
+ (* \`^\\url{http://www.proofwiki.org/wiki/Cantor-Bernstein-Schroeder_Theorem/Proof_5}^' *)
1950
+ (* retrieved April 29, 2013. *)
1951
+ (* *)
1952
+ (* \`. .' *)
1953
+ (***************************************************************************)
1954
+ THEOREM Fun_CantorBernsteinSchroeder ==
1955
+ ASSUME NEW S, NEW T,
1956
+ ExistsInjection(S,T), ExistsInjection(T,S)
1957
+ PROVE ExistsBijection(S,T)
1958
+
1959
+
1960
+ (***************************************************************************)
1961
+ (* \`. .' *)
1962
+ (* *)
1963
+ (* Applications of the Cantor-Bernstein-Schroeder Theorem. *)
1964
+ (* If there exists an injection f: A->B and a surjection g: A->B, then *)
1965
+ (* there exists a bijection between A and B. *)
1966
+ (* Also, if there are surjections between A and B, then there is a *)
1967
+ (* bijection. *)
1968
+ (* *)
1969
+ (* \`. .' *)
1970
+ (***************************************************************************)
1971
+
1972
+ THEOREM Fun_ExistInjAndSurjThenBij ==
1973
+ ASSUME NEW S, NEW T,
1974
+ ExistsInjection(S,T), ExistsSurjection(S,T)
1975
+ PROVE ExistsBijection(S,T)
1976
+
1977
+ THEOREM Fun_ExistSurjAndSurjThenBij ==
1978
+ ASSUME NEW S, NEW T,
1979
+ ExistsSurjection(S,T), ExistsSurjection(T,S)
1980
+ PROVE ExistsBijection(S,T)
1981
+
1982
+
1983
+ (***************************************************************************)
1984
+ (* \`. .' *)
1985
+ (* *)
1986
+ (* Equivalences for ExistsBijection. *)
1987
+ (* *)
1988
+ (* \`. .' *)
1989
+ (***************************************************************************)
1990
+ THEOREM Fun_ExistsBijEquiv ==
1991
+ ASSUME NEW S, NEW T
1992
+ PROVE /\\ ExistsBijection(S,T) <=> ExistsBijection(T,S)
1993
+ /\\ ExistsBijection(S,T) <=> ExistsInjection(S,T) /\\ ExistsInjection(T,S)
1994
+ /\\ ExistsBijection(S,T) <=> ExistsInjection(S,T) /\\ ExistsSurjection(S,T)
1995
+ /\\ ExistsBijection(S,T) <=> ExistsInjection(T,S) /\\ ExistsSurjection(T,S)
1996
+ /\\ ExistsBijection(S,T) <=> ExistsSurjection(S,T) /\\ ExistsSurjection(T,S)
1997
+
1998
+
1999
+ -----------------------------------------------------------------------------
2000
+ (***************************************************************************)
2001
+ (* \`^{\\large \\vspace{12pt} *)
2002
+ (* Facts about jections involving 1..n. *)
2003
+ (* \\vspace{12pt}}^' *)
2004
+ (***************************************************************************)
2005
+
2006
+
2007
+ (***************************************************************************)
2008
+ (* \`. .' *)
2009
+ (* *)
2010
+ (* There is a bijection from 1..b-a+1 to a..b for integers a,b with a <= b.*)
2011
+ (* *)
2012
+ (* \`. .' *)
2013
+ (***************************************************************************)
2014
+ THEOREM Fun_ExistsBijInterval ==
2015
+ ASSUME NEW a \\in Int, NEW b \\in Int, a <= b
2016
+ PROVE ExistsBijection(1 .. b-a+1, a .. b)
2017
+
2018
+
2019
+ (***************************************************************************)
2020
+ (* \`. .' *)
2021
+ (* *)
2022
+ (* There is an injection from 1..n to 1..m iff n \\leq m. *)
2023
+ (* *)
2024
+ (* \`. .' *)
2025
+ (***************************************************************************)
2026
+ THEOREM Fun_NatInjLeq ==
2027
+ ASSUME NEW n \\in Nat, NEW m \\in Nat
2028
+ PROVE ExistsInjection(1..n,1..m) <=> n \\leq m
2029
+
2030
+
2031
+ (***************************************************************************)
2032
+ (* \`. .' *)
2033
+ (* *)
2034
+ (* If a surjection from 1..n to S exists (for some n \\in Nat) then a *)
2035
+ (* bijection from 1..m to S exists (for some m \\in Nat) and m \\leq n. *)
2036
+ (* *)
2037
+ (* \`. .' *)
2038
+ (***************************************************************************)
2039
+ THEOREM Fun_NatSurjImpliesNatBij ==
2040
+ ASSUME NEW S, NEW n \\in Nat, ExistsSurjection(1..n,S)
2041
+ PROVE \\E m \\in Nat : ExistsBijection(1..m,S) /\\ m \\leq n
2042
+
2043
+
2044
+ (***************************************************************************)
2045
+ (* Simple corollary. *)
2046
+ (***************************************************************************)
2047
+ THEOREM Fun_NatSurjEquivNatBij ==
2048
+ ASSUME NEW S
2049
+ PROVE (\\E n \\in Nat : ExistsSurjection(1..n,S))
2050
+ <=> (\\E m \\in Nat : ExistsBijection(1..m,S))
2051
+
2052
+
2053
+ (***************************************************************************)
2054
+ (* \`. .' *)
2055
+ (* *)
2056
+ (* For any set S, given n, m \\in Nat such that bijections exist from 1..n *)
2057
+ (* to S and from 1..m to S, then it must be the case that n = m. *)
2058
+ (* *)
2059
+ (* \`. .' *)
2060
+ (***************************************************************************)
2061
+ THEOREM Fun_NatBijSame ==
2062
+ ASSUME NEW S,
2063
+ NEW n \\in Nat, ExistsBijection(1..n,S),
2064
+ NEW m \\in Nat, ExistsBijection(1..m,S)
2065
+ PROVE n = m
2066
+
2067
+
2068
+ (***************************************************************************)
2069
+ (* \`. .' *)
2070
+ (* *)
2071
+ (* S is empty iff there exists a bijection from 1..0 to S. *)
2072
+ (* *)
2073
+ (* \`. .' *)
2074
+ (***************************************************************************)
2075
+ THEOREM Fun_NatBijEmpty ==
2076
+ ASSUME NEW S
2077
+ PROVE ExistsBijection(1..0,S) <=> S = {}
2078
+
2079
+
2080
+ (***************************************************************************)
2081
+ (* \`. .' *)
2082
+ (* *)
2083
+ (* S is a singleton iff there exists a bijection from 1..1 to S. *)
2084
+ (* *)
2085
+ (* \`. .' *)
2086
+ (***************************************************************************)
2087
+ THEOREM Fun_NatBijSingleton ==
2088
+ ASSUME NEW S
2089
+ PROVE ExistsBijection(1..1,S) <=> \\E s : S = {s}
2090
+
2091
+
2092
+ (***************************************************************************)
2093
+ (* \`. .' *)
2094
+ (* *)
2095
+ (* If there exists a bijection from 1..m to S (for some m \\in Nat), then *)
2096
+ (* there exists a bijection from 1..n to T (for some n \\in Nat), where T *)
2097
+ (* is a subset of S. Furthermore n \\leq m. *)
2098
+ (* *)
2099
+ (* \`. .' *)
2100
+ (***************************************************************************)
2101
+ THEOREM Fun_NatBijSubset ==
2102
+ ASSUME NEW S, NEW m \\in Nat, ExistsBijection(1..m,S),
2103
+ NEW T \\in SUBSET S
2104
+ PROVE \\E n \\in Nat : ExistsBijection(1..n,T) /\\ n \\leq m
2105
+
2106
+
2107
+ (***************************************************************************)
2108
+ (* \`. .' *)
2109
+ (* *)
2110
+ (* If there exists a bijection from 1..m to S (for some m \\in Nat), then *)
2111
+ (* there exists a bijection from 1..(m+1) to S \\cup {x}, where x \\notin S. *)
2112
+ (* *)
2113
+ (* *)
2114
+ (* \`. .' *)
2115
+ (***************************************************************************)
2116
+ THEOREM Fun_NatBijAddElem ==
2117
+ ASSUME NEW S, NEW m \\in Nat, ExistsBijection(1..m,S),
2118
+ NEW x, x \\notin S
2119
+ PROVE ExistsBijection(1..(m+1), S \\cup {x})
2120
+
2121
+
2122
+ (***************************************************************************)
2123
+ (* \`. .' *)
2124
+ (* *)
2125
+ (* If there exists a bijection from 1..m to S (for some m \\in Nat), then *)
2126
+ (* there exists a bijection from 1..(m-1) to S \\ {x}, where x \\in S. *)
2127
+ (* *)
2128
+ (* *)
2129
+ (* \`. .' *)
2130
+ (***************************************************************************)
2131
+ THEOREM Fun_NatBijSubElem ==
2132
+ ASSUME NEW S, NEW m \\in Nat, ExistsBijection(1..m,S),
2133
+ NEW x, x \\in S
2134
+ PROVE ExistsBijection(1..(m-1), S \\ {x})
2135
+
2136
+ -----------------------------------------------------------------------------
2137
+
2138
+ (***************************************************************************)
2139
+ (* Folding a function for an empty set of indices yields the base value. *)
2140
+ (***************************************************************************)
2141
+ THEOREM FoldFunctionOnSetEmpty ==
2142
+ ASSUME NEW op(_,_), NEW base, NEW fun
2143
+ PROVE FoldFunctionOnSet(op, base, fun, {}) = base
2144
+
2145
+ (***************************************************************************)
2146
+ (* Folding a function for a non-empty set of indices corresponds to *)
2147
+ (* applying the binary operator to f[i], for some i \\in indices, and the *)
2148
+ (* result of recursing for the set indices \\ {i}. *)
2149
+ (***************************************************************************)
2150
+ THEOREM FoldFunctionOnSetNonempty ==
2151
+ ASSUME NEW op(_,_), NEW base, NEW fun,
2152
+ NEW indices, indices # {}, IsFiniteSet(indices)
2153
+ PROVE \\E i \\in indices : FoldFunctionOnSet(op, base, fun, indices) =
2154
+ op(fun[i], FoldFunctionOnSet(op, base, fun, indices \\ {i}))
2155
+
2156
+ (***************************************************************************)
2157
+ (* The type of folding a function corresponds to the type associated with *)
2158
+ (* the binary operator that underlies the fold. *)
2159
+ (***************************************************************************)
2160
+ THEOREM FoldFunctionOnSetType ==
2161
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2162
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2163
+ NEW indices, IsFiniteSet(indices), NEW fun,
2164
+ \\A i \\in indices : fun[i] \\in Typ
2165
+ PROVE FoldFunctionOnSet(op, base, fun, indices) \\in Typ
2166
+
2167
+ (***************************************************************************)
2168
+ (* Folding two functions that agree on every element of the set of indices *)
2169
+ (* yields the same value. *)
2170
+ (***************************************************************************)
2171
+ THEOREM FoldFunctionOnSetEqual ==
2172
+ ASSUME NEW op(_,_), NEW base, NEW f, NEW g,
2173
+ NEW indices, IsFiniteSet(indices),
2174
+ \\A i \\in indices : f[i] = g[i]
2175
+ PROVE FoldFunctionOnSet(op, base, f, indices) =
2176
+ FoldFunctionOnSet(op, base, g, indices)
2177
+
2178
+ (***************************************************************************)
2179
+ (* If the binary operator is associative and commutative, the result of *)
2180
+ (* folding a function over a non-empty set corresponds to applying the *)
2181
+ (* operator to an arbitrary element of the set and the result of folding *)
2182
+ (* the function over the remainder of the set. *)
2183
+ (***************************************************************************)
2184
+ THEOREM FoldFunctionOnSetAC ==
2185
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2186
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2187
+ \\A t,u \\in Typ : op(t,u) = op(u,t),
2188
+ \\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
2189
+ NEW indices, IsFiniteSet(indices), NEW i \\in indices, NEW fun,
2190
+ \\A j \\in indices : fun[j] \\in Typ
2191
+ PROVE FoldFunctionOnSet(op, base, fun, indices) =
2192
+ op(fun[i], FoldFunctionOnSet(op, base, fun, indices \\ {i}))
2193
+
2194
+ \\* reformulation in terms of adding an index to the set
2195
+ THEOREM FoldFunctionOnSetACAddIndex ==
2196
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2197
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2198
+ \\A t,u \\in Typ : op(t,u) = op(u,t),
2199
+ \\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
2200
+ NEW indices, IsFiniteSet(indices), NEW i, i \\notin indices,
2201
+ NEW fun, \\A j \\in indices \\union {i} : fun[j] \\in Typ
2202
+ PROVE FoldFunctionOnSet(op, base, fun, indices \\union {i}) =
2203
+ op(fun[i], FoldFunctionOnSet(op, base, fun, indices))
2204
+
2205
+ (*************************************************************************)
2206
+ (* For an AC operator, folding an EXCEPT construction can be reduced to *)
2207
+ (* folding the original function. *)
2208
+ (*************************************************************************)
2209
+ THEOREM FoldFunctionOnSetACExcept ==
2210
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2211
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2212
+ \\A t,u \\in Typ : op(t,u) = op(u,t),
2213
+ \\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
2214
+ NEW fun, NEW i, NEW y \\in Typ,
2215
+ NEW indices \\in SUBSET (DOMAIN fun), IsFiniteSet(indices),
2216
+ \\A j \\in indices : fun[j] \\in Typ
2217
+ PROVE FoldFunctionOnSet(op, base, [fun EXCEPT ![i] = y], indices) =
2218
+ IF i \\in indices
2219
+ THEN op(y, FoldFunctionOnSet(op, base, fun, indices \\ {i}))
2220
+ ELSE FoldFunctionOnSet(op, base, fun, indices)
2221
+
2222
+ (*************************************************************************)
2223
+ (* For an AC operator \`op\` for which \`base\` is the neutral element, *)
2224
+ (* folding a function commutes with set union, for disjoint sets. *)
2225
+ (*************************************************************************)
2226
+ THEOREM FoldFunctionOnSetDisjointUnion ==
2227
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2228
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2229
+ \\A t,u \\in Typ : op(t,u) = op(u,t),
2230
+ \\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
2231
+ \\A t \\in Typ : op(base, t) = t,
2232
+ NEW S, IsFiniteSet(S), NEW T, IsFiniteSet(T), S \\cap T = {},
2233
+ NEW fun, \\A i \\in S \\union T : fun[i] \\in Typ
2234
+ PROVE FoldFunctionOnSet(op, base, fun, S \\union T) =
2235
+ op(FoldFunctionOnSet(op, base, fun, S), FoldFunctionOnSet(op, base, fun, T))
2236
+
2237
+ (*************************************************************************)
2238
+ (* Analogous theorems for FoldFunction. Note that the theorems about *)
2239
+ (* adding an index and about disjoint union do not make sense here. *)
2240
+ (*************************************************************************)
2241
+ THEOREM FoldFunctionEmpty ==
2242
+ ASSUME NEW op(_,_), NEW base, NEW fun, DOMAIN fun = {}
2243
+ PROVE FoldFunction(op, base, fun) = base
2244
+
2245
+ THEOREM FoldFunctionNonempty ==
2246
+ ASSUME NEW op(_,_), NEW base, NEW fun,
2247
+ DOMAIN fun # {}, IsFiniteSet(DOMAIN fun)
2248
+ PROVE \\E i \\in DOMAIN fun : FoldFunction(op, base, fun) =
2249
+ op(fun[i], FoldFunctionOnSet(op, base, fun, DOMAIN fun \\ {i}))
2250
+
2251
+ THEOREM FoldFunctionType ==
2252
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2253
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2254
+ NEW fun, IsFiniteSet(DOMAIN fun),
2255
+ \\A i \\in DOMAIN fun : fun[i] \\in Typ
2256
+ PROVE FoldFunction(op, base, fun) \\in Typ
2257
+
2258
+ THEOREM FoldFunctionAC ==
2259
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2260
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2261
+ \\A t,u \\in Typ : op(t,u) = op(u,t),
2262
+ \\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
2263
+ NEW fun, IsFiniteSet(DOMAIN fun), NEW i \\in DOMAIN fun,
2264
+ \\A j \\in DOMAIN fun : fun[j] \\in Typ
2265
+ PROVE FoldFunction(op, base, fun) =
2266
+ op(fun[i], FoldFunctionOnSet(op, base, fun, (DOMAIN fun) \\ {i}))
2267
+
2268
+ THEOREM FoldFunctionACExcept ==
2269
+ ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
2270
+ \\A t,u \\in Typ : op(t,u) \\in Typ,
2271
+ \\A t,u \\in Typ : op(t,u) = op(u,t),
2272
+ \\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
2273
+ NEW fun, NEW i, NEW y \\in Typ,
2274
+ IsFiniteSet(DOMAIN fun),
2275
+ \\A j \\in DOMAIN fun : fun[j] \\in Typ
2276
+ PROVE FoldFunction(op, base, [fun EXCEPT ![i] = y]) =
2277
+ IF i \\in DOMAIN fun
2278
+ THEN op(y, FoldFunctionOnSet(op, base, fun, (DOMAIN fun) \\ {i}))
2279
+ ELSE FoldFunction(op, base, fun)
2280
+
2281
+ (*************************************************************************)
2282
+ (* Summing a function that returns natural numbers, resp. integers, *)
2283
+ (* yields a natural number, resp. an integer. *)
2284
+ (*************************************************************************)
2285
+ THEOREM SumFunctionOnSetNat ==
2286
+ ASSUME NEW fun, NEW indices, IsFiniteSet(indices),
2287
+ \\A i \\in indices : fun[i] \\in Nat
2288
+ PROVE SumFunctionOnSet(fun, indices) \\in Nat
2289
+
2290
+ THEOREM SumFunctionOnSetInt ==
2291
+ ASSUME NEW fun, NEW indices, IsFiniteSet(indices),
2292
+ \\A i \\in indices : fun[i] \\in Int
2293
+ PROVE SumFunctionOnSet(fun, indices) \\in Int
2294
+
2295
+ (*************************************************************************)
2296
+ (* Summing two functions that agree on all relevant indices yields the *)
2297
+ (* same result. *)
2298
+ (*************************************************************************)
2299
+ THEOREM SumFunctionOnSetEqual ==
2300
+ ASSUME NEW f, NEW g, NEW indices, IsFiniteSet(indices),
2301
+ \\A i \\in indices : f[i] = g[i]
2302
+ PROVE SumFunctionOnSet(f, indices) = SumFunctionOnSet(g, indices)
2303
+
2304
+ (*************************************************************************)
2305
+ (* Summing a function over the empty set is 0. *)
2306
+ (*************************************************************************)
2307
+ THEOREM SumFunctionOnSetEmpty ==
2308
+ ASSUME NEW fun
2309
+ PROVE SumFunctionOnSet(fun, {}) = 0
2310
+
2311
+ (*************************************************************************)
2312
+ (* Summing a function over a non-empty set corresponds to the sum of *)
2313
+ (* element of the set and the sum of the function over the remainder. *)
2314
+ (*************************************************************************)
2315
+ THEOREM SumFunctionOnSetNonempty ==
2316
+ ASSUME NEW fun, NEW indices, IsFiniteSet(indices), NEW i \\in indices,
2317
+ \\A j \\in indices : fun[j] \\in Int
2318
+ PROVE SumFunctionOnSet(fun, indices) =
2319
+ fun[i] + SumFunctionOnSet(fun, indices \\ {i})
2320
+
2321
+ \\* reformulation in terms of adding an index
2322
+ THEOREM SumFunctionOnSetAddIndex ==
2323
+ ASSUME NEW fun, NEW indices, IsFiniteSet(indices),
2324
+ NEW i, i \\notin indices,
2325
+ \\A j \\in indices \\union {i} : fun[j] \\in Int
2326
+ PROVE SumFunctionOnSet(fun, indices \\union {i}) =
2327
+ fun[i] + SumFunctionOnSet(fun, indices)
2328
+
2329
+ \\* corresponding lemma for removing an index
2330
+ THEOREM SumFunctionOnSetRemoveIndex ==
2331
+ ASSUME NEW fun, NEW indices, IsFiniteSet(indices), NEW i \\in indices,
2332
+ \\A j \\in indices : fun[j] \\in Int
2333
+ PROVE SumFunctionOnSet(fun, indices \\ {i}) =
2334
+ SumFunctionOnSet(fun, indices) - fun[i]
2335
+
2336
+ (*************************************************************************)
2337
+ (* Reduce the sum of an EXCEPT to the sum of the original function. *)
2338
+ (*************************************************************************)
2339
+ THEOREM SumFunctionOnSetExcept ==
2340
+ ASSUME NEW fun, NEW i, NEW y \\in Int,
2341
+ NEW indices \\in SUBSET (DOMAIN fun), IsFiniteSet(indices),
2342
+ \\A j \\in indices : fun[j] \\in Int
2343
+ PROVE SumFunctionOnSet([fun EXCEPT ![i] = y], indices) =
2344
+ IF i \\in indices
2345
+ THEN SumFunctionOnSet(fun, indices) + y - fun[i]
2346
+ ELSE SumFunctionOnSet(fun, indices)
2347
+
2348
+ (*************************************************************************)
2349
+ (* Summing a function distributes over disjoint union. *)
2350
+ (*************************************************************************)
2351
+ THEOREM SumFunctionOnSetDisjointUnion ==
2352
+ ASSUME NEW S, IsFiniteSet(S),
2353
+ NEW T, IsFiniteSet(T), S \\cap T = {},
2354
+ NEW fun, \\A x \\in S \\union T : fun[x] \\in Int
2355
+ PROVE SumFunctionOnSet(fun, S \\union T) =
2356
+ SumFunctionOnSet(fun, S) + SumFunctionOnSet(fun, T)
2357
+
2358
+ (*************************************************************************)
2359
+ (* Summing a Nat-valued function is monotonic in the subset relation. *)
2360
+ (*************************************************************************)
2361
+ THEOREM SumFunctionNatOnSubset ==
2362
+ ASSUME NEW S, IsFiniteSet(S), NEW T \\in SUBSET S,
2363
+ NEW fun, \\A s \\in S : fun[s] \\in Nat
2364
+ PROVE SumFunctionOnSet(fun, T) <= SumFunctionOnSet(fun, S)
2365
+
2366
+ (*************************************************************************)
2367
+ (* The sum of a Nat-valued function is zero iff all relevant function *)
2368
+ (* values are zero. *)
2369
+ (*************************************************************************)
2370
+ THEOREM SumFunctionOnSetZero ==
2371
+ ASSUME NEW S, IsFiniteSet(S),
2372
+ NEW fun, \\A x \\in S : fun[x] \\in Nat
2373
+ PROVE SumFunctionOnSet(fun, S) = 0 <=> \\A x \\in S : fun[x] = 0
2374
+
2375
+ (*************************************************************************)
2376
+ (* Given any Int-valued function f and finite set S such that f[s] = c *)
2377
+ (* for all s \\in S, summing f over S yields c multiplied by the *)
2378
+ (* cardinality of S. For example, for *)
2379
+ (* f == [s \\in {"a", "b", "c"} |-> IF s = "c" THEN 42 ELSE 5], *)
2380
+ (* SumFunctionOnSet(f, {"a","b"}) = 10. *)
2381
+ (*************************************************************************)
2382
+ THEOREM SumFunctionOnSetConst ==
2383
+ ASSUME NEW D, NEW S \\in SUBSET D, IsFiniteSet(S),
2384
+ NEW f \\in [D -> Int], NEW c \\in Int, \\A x \\in S : f[x] = c
2385
+ PROVE SumFunctionOnSet(f, S) = c * Cardinality(S)
2386
+
2387
+ (*************************************************************************)
2388
+ (* Summing a function is monotonic in the function argument. *)
2389
+ (*************************************************************************)
2390
+ THEOREM SumFunctionOnSetMonotonic ==
2391
+ ASSUME NEW S, IsFiniteSet(S),
2392
+ NEW f, \\A s \\in S : f[s] \\in Int,
2393
+ NEW g, \\A s \\in S : g[s] \\in Int,
2394
+ \\A s \\in S : f[s] <= g[s]
2395
+ PROVE SumFunctionOnSet(f, S) <= SumFunctionOnSet(g, S)
2396
+
2397
+ (*************************************************************************)
2398
+ (* The sum over function f is strictly smaller than the sum over g if *)
2399
+ (* f[x] <= g[x] for all x \\in S and f[x] < g[s] holds for at least some *)
2400
+ (* element s \\in S. *)
2401
+ (*************************************************************************)
2402
+ THEOREM SumFunctionOnSetStrictlyMonotonic ==
2403
+ ASSUME NEW S, IsFiniteSet(S),
2404
+ NEW f, \\A s \\in S : f[s] \\in Int,
2405
+ NEW g, \\A s \\in S : g[s] \\in Int,
2406
+ \\A x \\in S : f[x] <= g[x],
2407
+ NEW s \\in S, f[s] < g[s]
2408
+ PROVE SumFunctionOnSet(f, S) < SumFunctionOnSet(g, S)
2409
+
2410
+ (*************************************************************************)
2411
+ (* Similar theorems for SumFunction. *)
2412
+ (*************************************************************************)
2413
+ THEOREM SumFunctionNat ==
2414
+ ASSUME NEW fun, IsFiniteSet(DOMAIN fun),
2415
+ \\A x \\in DOMAIN fun : fun[x] \\in Nat
2416
+ PROVE SumFunction(fun) \\in Nat
2417
+
2418
+ THEOREM SumFunctionInt ==
2419
+ ASSUME NEW fun, IsFiniteSet(DOMAIN fun),
2420
+ \\A x \\in DOMAIN fun : fun[x] \\in Int
2421
+ PROVE SumFunction(fun) \\in Int
2422
+
2423
+ THEOREM SumFunctionEmpty ==
2424
+ ASSUME NEW fun, DOMAIN fun = {}
2425
+ PROVE SumFunction(fun) = 0
2426
+
2427
+ THEOREM SumFunctionNonempty ==
2428
+ ASSUME NEW fun, IsFiniteSet(DOMAIN fun), NEW x \\in DOMAIN fun,
2429
+ \\A i \\in DOMAIN fun : fun[i] \\in Int
2430
+ PROVE SumFunction(fun) = fun[x] + SumFunctionOnSet(fun, (DOMAIN fun) \\ {x})
2431
+
2432
+ THEOREM SumFunctionExcept ==
2433
+ ASSUME NEW fun, NEW i, NEW y \\in Int, IsFiniteSet(DOMAIN fun),
2434
+ \\A x \\in DOMAIN fun : fun[x] \\in Int
2435
+ PROVE SumFunction([fun EXCEPT ![i] = y]) =
2436
+ IF i \\in DOMAIN fun
2437
+ THEN SumFunction(fun) + y - fun[i]
2438
+ ELSE SumFunction(fun)
2439
+
2440
+ THEOREM SumFunctionZero ==
2441
+ ASSUME NEW fun, IsFiniteSet(DOMAIN fun),
2442
+ \\A x \\in DOMAIN fun : fun[x] \\in Nat
2443
+ PROVE SumFunction(fun) = 0 <=> \\A x \\in DOMAIN fun : fun[x] = 0
2444
+
2445
+ (*************************************************************************)
2446
+ (* Summing a constant function yields the constant multiplied by the *)
2447
+ (* cardinality of its domain. For example, *)
2448
+ (* SumFunction([s \\in {"a","b","c"} |-> 5]) = 15. *)
2449
+ (*************************************************************************)
2450
+ THEOREM SumFunctionConst ==
2451
+ ASSUME NEW S, IsFiniteSet(S), NEW c \\in Int
2452
+ PROVE SumFunction([s \\in S |-> c]) = c * Cardinality(S)
2453
+
2454
+ THEOREM SumFunctionMonotonic ==
2455
+ ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
2456
+ \\A x \\in DOMAIN f : f[x] \\in Int,
2457
+ \\A x \\in DOMAIN f : g[x] \\in Int,
2458
+ \\A x \\in DOMAIN f : f[x] <= g[x]
2459
+ PROVE SumFunction(f) <= SumFunction(g)
2460
+
2461
+ THEOREM SumFunctionStrictlyMonotonic ==
2462
+ ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
2463
+ \\A x \\in DOMAIN f : f[x] \\in Int,
2464
+ \\A x \\in DOMAIN f : g[x] \\in Int,
2465
+ \\A x \\in DOMAIN f : f[x] <= g[x],
2466
+ NEW s \\in DOMAIN f, f[s] < g[s]
2467
+ PROVE SumFunction(f) < SumFunction(g)
2468
+
2469
+ =============================================================================
2470
+ \\* Created Thu Apr 11 10:36:10 PDT 2013 by tomr
2471
+ `],[`NaturalsInduction`,`------------------------- MODULE NaturalsInduction --------------------------
2472
+ (***************************************************************************)
2473
+ (* This module contains useful theorems for inductive proofs and recursive *)
2474
+ (* definitions over the naturals. *)
2475
+ (* *)
2476
+ (* Some of the statements of the theorems are decomposed in terms of *)
2477
+ (* definitions. This is done for two reasons: *)
2478
+ (* *)
2479
+ (* - It makes it easier for the backends to instantiate the theorems *)
2480
+ (* when those definitions are not expanded. *)
2481
+ (* *)
2482
+ (* - It can be convenient when writing proofs to use those definitions *)
2483
+ (* rather than having to write out their expansions. *)
2484
+ (***************************************************************************)
2485
+ EXTENDS Integers
2486
+
2487
+ (***************************************************************************)
2488
+ (* The following is the simple statement of inductions over the naturals. *)
2489
+ (* For predicates P defined by a moderately complex operator, it is often *)
2490
+ (* useful to hide the operator definition before using this theorem. That *)
2491
+ (* is, you first define a suitable operator P (not necessarily by that *)
2492
+ (* name), prove the two hypotheses of the theorem, and then hide the *)
2493
+ (* definition of P when using the theorem. *)
2494
+ (***************************************************************************)
2495
+ THEOREM NatInduction ==
2496
+ ASSUME NEW P(_),
2497
+ P(0),
2498
+ \\A n \\in Nat : P(n) => P(n+1)
2499
+ PROVE \\A n \\in Nat : P(n)
2500
+
2501
+ (***************************************************************************)
2502
+ (* A useful corollary of NatInduction *)
2503
+ (***************************************************************************)
2504
+ THEOREM DownwardNatInduction ==
2505
+ ASSUME NEW P(_), NEW m \\in Nat, P(m),
2506
+ \\A n \\in 1 .. m : P(n) => P(n-1)
2507
+ PROVE P(0)
2508
+
2509
+ (***************************************************************************)
2510
+ (* The following theorem expresses a stronger induction principle, *)
2511
+ (* also known as course-of-values induction, where the induction *)
2512
+ (* hypothesis is available for all strictly smaller natural numbers. *)
2513
+ (***************************************************************************)
2514
+ THEOREM GeneralNatInduction ==
2515
+ ASSUME NEW P(_),
2516
+ \\A n \\in Nat : (\\A m \\in 0..(n-1) : P(m)) => P(n)
2517
+ PROVE \\A n \\in Nat : P(n)
2518
+
2519
+ (***************************************************************************)
2520
+ (* The following theorem expresses the \`\`least-number principle'': *)
2521
+ (* if P(n) is true for some natural number n then there is a *)
2522
+ (* smallest natural number for which P is true. It could be derived in *)
2523
+ (* module WellFoundedInduction as a corollary of the fact that the natural *)
2524
+ (* numbers are well ordered, but we give a direct proof. *)
2525
+ (***************************************************************************)
2526
+ THEOREM SmallestNatural ==
2527
+ ASSUME NEW P(_), NEW n \\in Nat, P(n)
2528
+ PROVE \\E m \\in Nat : /\\ P(m)
2529
+ /\\ \\A k \\in 0 .. m-1 : ~ P(k)
2530
+
2531
+ (***************************************************************************)
2532
+ (* The following theorem says that a recursively defined function f over *)
2533
+ (* the natural numbers is well-defined if for every n \\in Nat the *)
2534
+ (* definition of f[n] depends only on arguments smaller than n. *)
2535
+ (***************************************************************************)
2536
+ THEOREM RecursiveFcnOfNat ==
2537
+ ASSUME NEW Def(_,_),
2538
+ ASSUME NEW n \\in Nat, NEW g, NEW h,
2539
+ \\A i \\in 0..(n-1) : g[i] = h[i]
2540
+ PROVE Def(g, n) = Def(h, n)
2541
+ PROVE LET f[n \\in Nat] == Def(f, n)
2542
+ IN f = [n \\in Nat |-> Def(f, n)]
2543
+
2544
+ (***************************************************************************)
2545
+ (* The following theorem NatInductiveDef is what you use to justify a *)
2546
+ (* function defined by primitive recursion over the naturals. *)
2547
+ (***************************************************************************)
2548
+ NatInductiveDefHypothesis(f, f0, Def(_,_)) ==
2549
+ (f = CHOOSE g : g = [i \\in Nat |-> IF i = 0 THEN f0 ELSE Def(g[i-1], i)])
2550
+ NatInductiveDefConclusion(f, f0, Def(_,_)) ==
2551
+ f = [i \\in Nat |-> IF i = 0 THEN f0 ELSE Def(f[i-1], i)]
2552
+
2553
+ THEOREM NatInductiveDef ==
2554
+ ASSUME NEW Def(_,_), NEW f, NEW f0,
2555
+ NatInductiveDefHypothesis(f, f0, Def)
2556
+ PROVE NatInductiveDefConclusion(f, f0, Def)
2557
+
2558
+ (***************************************************************************)
2559
+ (* The following two theorems allow you to prove the type of a recursively *)
2560
+ (* defined function over the natural numbers. *)
2561
+ (***************************************************************************)
2562
+ THEOREM RecursiveFcnOfNatType ==
2563
+ ASSUME NEW f, NEW S, NEW Def(_,_), f = [n \\in Nat |-> Def(f,n)],
2564
+ ASSUME NEW n \\in Nat, NEW g, \\A i \\in 0 .. n-1 : g[i] \\in S
2565
+ PROVE Def(g,n) \\in S
2566
+ PROVE f \\in [Nat -> S]
2567
+
2568
+ THEOREM NatInductiveDefType ==
2569
+ ASSUME NEW Def(_,_), NEW S, NEW f, NEW f0 \\in S,
2570
+ NatInductiveDefConclusion(f, f0, Def),
2571
+ f0 \\in S,
2572
+ \\A v \\in S, n \\in Nat \\ {0} : Def(v, n) \\in S
2573
+ PROVE f \\in [Nat -> S]
2574
+
2575
+ (***************************************************************************)
2576
+ (* The following theorems show uniqueness of functions recursively defined *)
2577
+ (* over Nat. *)
2578
+ (***************************************************************************)
2579
+ THEOREM RecursiveFcnOfNatUnique ==
2580
+ ASSUME NEW Def(_,_), NEW f, NEW g,
2581
+ f = [n \\in Nat |-> Def(f,n)],
2582
+ g = [n \\in Nat |-> Def(g,n)],
2583
+ ASSUME NEW n \\in Nat, NEW ff, NEW gg,
2584
+ \\A i \\in 0..(n-1) : ff[i] = gg[i]
2585
+ PROVE Def(ff, n) = Def(gg, n)
2586
+ PROVE f = g
2587
+
2588
+ THEOREM NatInductiveUnique ==
2589
+ ASSUME NEW Def(_,_), NEW f, NEW g, NEW f0,
2590
+ NatInductiveDefConclusion(f, f0, Def),
2591
+ NatInductiveDefConclusion(g, f0, Def)
2592
+ PROVE f = g
2593
+
2594
+ (***************************************************************************)
2595
+ (* The following theorems are analogous to the preceding ones but for *)
2596
+ (* functions defined over intervals of natural numbers. *)
2597
+ (***************************************************************************)
2598
+
2599
+ FiniteNatInductiveDefHypothesis(f, c, Def(_,_), m, n) ==
2600
+ (f = CHOOSE g : g = [i \\in m..n |-> IF i = m THEN c ELSE Def(g[i-1], i)])
2601
+ FiniteNatInductiveDefConclusion(f, c, Def(_,_), m, n) ==
2602
+ f = [i \\in m..n |-> IF i = m THEN c ELSE Def(f[i-1], i)]
2603
+
2604
+ THEOREM FiniteNatInductiveDef ==
2605
+ ASSUME NEW Def(_,_), NEW f, NEW c, NEW m \\in Nat, NEW n \\in Nat,
2606
+ FiniteNatInductiveDefHypothesis(f, c, Def, m, n)
2607
+ PROVE FiniteNatInductiveDefConclusion(f, c, Def, m, n)
2608
+
2609
+ THEOREM FiniteNatInductiveDefType ==
2610
+ ASSUME NEW S, NEW Def(_,_), NEW f, NEW c \\in S, NEW m \\in Nat, NEW n \\in Nat,
2611
+ FiniteNatInductiveDefConclusion(f, c, Def, m, n),
2612
+ \\A v \\in S, i \\in (m+1) .. n : Def(v,i) \\in S
2613
+ PROVE f \\in [m..n -> S]
2614
+
2615
+ THEOREM FiniteNatInductiveUnique ==
2616
+ ASSUME NEW Def(_,_), NEW f, NEW g, NEW c, NEW m \\in Nat, NEW n \\in Nat,
2617
+ FiniteNatInductiveDefConclusion(f, c, Def, m, n),
2618
+ FiniteNatInductiveDefConclusion(g, c, Def, m, n)
2619
+ PROVE f = g
2620
+
2621
+ =============================================================================
2622
+
2623
+ (***************************************************************************)
2624
+ (* The following example shows how this module is used. *)
2625
+ (***************************************************************************)
2626
+
2627
+ factorial[n \\in Nat] == IF n = 0 THEN 1 ELSE n * factorial[n-1]
2628
+
2629
+ THEOREM FactorialDefConclusion == NatInductiveDefConclusion(factorial, 1, LAMBDA v,n : n*v)
2630
+ <1>1. NatInductiveDefHypothesis(factorial, 1, LAMBDA v,n : n*v)
2631
+ BY DEF NatInductiveDefHypothesis, factorial
2632
+ <1>2. QED
2633
+ BY <1>1, NatInductiveDef
2634
+
2635
+ THEOREM FactorialDef == \\A n \\in Nat : factorial[n] = IF n = 0 THEN 1 ELSE n * factorial[n-1]
2636
+ BY FactorialDefConclusion DEF NatInductiveDefConclusion
2637
+
2638
+ THEOREM FactorialType == factorial \\in [Nat -> Nat]
2639
+ <1>1. \\A v \\in Nat, n \\in Nat \\ {0} : n * v \\in Nat
2640
+ OBVIOUS
2641
+ <1>2. QED
2642
+ BY <1>1, NatInductiveDefType, FactorialDefConclusion, Isa
2643
+
2644
+
2645
+ \\* Modification History
2646
+ \\* Last modified Thu Aug 22 15:29:20 CEST 2019 by merz
2647
+ \\* Last modified Tue Oct 15 12:06:48 CEST 2013 by shaolin
2648
+ \\* Last modified Sat Nov 26 08:49:59 CET 2011 by merz
2649
+ \\* Last modified Mon Nov 07 08:58:05 PST 2011 by lamport
2650
+ \\* Created Mon Oct 31 02:52:05 PDT 2011 by lamport
2651
+ `],[`RealTime`,`----------------------------- MODULE RealTime -------------------------------
2652
+ EXTENDS Reals
2653
+ VARIABLE now
2654
+
2655
+ RTBound(A, v, D, E) ==
2656
+ LET TNext(t) == t' = IF <<A>>_v \\/ ~(ENABLED <<A>>_v)'
2657
+ THEN 0
2658
+ ELSE t + (now'-now)
2659
+
2660
+ Timer(t) == (t=0) /\\ [][TNext(t)]_<<t, v, now>>
2661
+
2662
+ MaxTime(t) == [](t \\leq E)
2663
+
2664
+ MinTime(t) == [][A => t \\geq D]_v
2665
+ IN \\EE t : Timer(t) /\\ MaxTime(t) /\\ MinTime(t)
2666
+ -----------------------------------------------------------------------------
2667
+ RTnow(v) == LET NowNext == /\\ now' \\in {r \\in Real : r > now}
2668
+ /\\ UNCHANGED v
2669
+ IN /\\ now \\in Real
2670
+ /\\ [][NowNext]_now
2671
+ /\\ \\A r \\in Real : WF_now(NowNext /\\ (now'>r))
2672
+ =============================================================================
2673
+ `],[`SequenceTheorems`,`-------------------------- MODULE SequenceTheorems --------------------------
2674
+ (***************************************************************************)
2675
+ (* This module contains theorems about operations on sequences. *)
2676
+ (***************************************************************************)
2677
+ EXTENDS Sequences, Functions
2678
+ LOCAL INSTANCE NaturalsInduction
2679
+ LOCAL INSTANCE TLAPS
2680
+
2681
+
2682
+ (***************************************************************************)
2683
+ (* Elementary properties about Seq(S) *)
2684
+ (***************************************************************************)
789
2685
 
2686
+ LEMMA SeqDef == \\A S : Seq(S) = UNION {[1..n -> S] : n \\in Nat}
2687
+
2688
+ THEOREM SeqMonotonic ==
2689
+ ASSUME NEW S, NEW T, NEW seq \\in Seq(S),
2690
+ S \\subseteq T
2691
+ PROVE seq \\in Seq(T)
2692
+
2693
+ THEOREM ElementOfSeq ==
2694
+ ASSUME NEW S, NEW seq \\in Seq(S),
2695
+ NEW n \\in 1..Len(seq)
2696
+ PROVE seq[n] \\in S
2697
+
2698
+ THEOREM EmptySeq ==
2699
+ ASSUME NEW S
2700
+ PROVE /\\ << >> \\in Seq(S)
2701
+ /\\ Len(<< >>) = 0
2702
+ /\\ \\A seq \\in Seq(S) : (seq # << >>) => (Len(seq) \\in Nat \\ {0})
2703
+
2704
+ THEOREM LenProperties ==
2705
+ ASSUME NEW S, NEW seq \\in Seq(S)
2706
+ PROVE /\\ Len(seq) \\in Nat
2707
+ /\\ seq \\in [1..Len(seq) -> S]
2708
+ /\\ DOMAIN seq = 1 .. Len(seq)
2709
+
2710
+ THEOREM IsASeq ==
2711
+ ASSUME NEW n \\in Nat, NEW e(_), NEW S,
2712
+ \\A i \\in 1..n : e(i) \\in S
2713
+ PROVE [i \\in 1..n |-> e(i)] \\in Seq(S)
2714
+
2715
+ THEOREM ExceptSeq ==
2716
+ ASSUME NEW S, NEW seq \\in Seq(S), NEW i \\in 1 .. Len(seq), NEW e \\in S
2717
+ PROVE /\\ [seq EXCEPT ![i] = e] \\in Seq(S)
2718
+ /\\ Len([seq EXCEPT ![i] = e]) = Len(seq)
2719
+ /\\ \\A j \\in 1 .. Len(seq) : [seq EXCEPT ![i] = e][j] = IF j=i THEN e ELSE seq[j]
2720
+
2721
+ THEOREM SeqEqual ==
2722
+ ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
2723
+ Len(s) = Len(t), \\A i \\in 1 .. Len(s) : s[i] = t[i]
2724
+ PROVE s = t
790
2725
 
791
2726
  (**************************************************************************)
792
- (* Backend pragmas: multi-back-ends *)
793
- (* *)
794
- (* These pragmas just run a bunch of back-ends one after the other in the *)
795
- (* hope that one will succeed. This saves time and effort for the user at *)
796
- (* the expense of computation time. *)
2727
+ (* Properties of concatenation (\\o) *)
797
2728
  (**************************************************************************)
798
2729
 
799
- (* CVC3 goes first because it's bundled with TLAPS, then the other SMT
800
- solvers are unlikely to succeed if CVC3 fails, so we run zenon and
801
- Isabelle before them. *)
802
- AllProvers == TRUE (*{
803
- by (prover:"cvc33")
804
- by (prover:"zenon")
805
- by (prover:"isabelle"; tactic:"auto")
806
- by (prover:"spass")
807
- by (prover:"smt3")
808
- by (prover:"yices3")
809
- by (prover:"verit")
810
- by (prover:"z33")
811
- by (prover:"isabelle"; tactic:"force")
812
- by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
813
- by (prover:"isabelle"; tactic:"clarsimp auto?")
814
- by (prover:"isabelle"; tactic:"clarsimp")
815
- by (prover:"isabelle"; tactic:"auto, blast")
816
- }*)
817
- AllProversT(X) == TRUE (*{
818
- by (prover:"cvc33"; timeout:@)
819
- by (prover:"zenon"; timeout:@)
820
- by (prover:"isabelle"; tactic:"auto"; timeout:@)
821
- by (prover:"spass"; timeout:@)
822
- by (prover:"smt3"; timeout:@)
823
- by (prover:"yices3"; timeout:@)
824
- by (prover:"verit"; timeout:@)
825
- by (prover:"z33"; timeout:@)
826
- by (prover:"isabelle"; tactic:"force"; timeout:@)
827
- by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
828
- by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
829
- by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
830
- by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
831
- }*)
2730
+ THEOREM ConcatProperties ==
2731
+ ASSUME NEW S, NEW s1 \\in Seq(S), NEW s2 \\in Seq(S)
2732
+ PROVE /\\ s1 \\o s2 \\in Seq(S)
2733
+ /\\ Len(s1 \\o s2) = Len(s1) + Len(s2)
2734
+ /\\ \\A i \\in 1 .. Len(s1) + Len(s2) : (s1 \\o s2)[i] =
2735
+ IF i <= Len(s1) THEN s1[i] ELSE s2[i - Len(s1)]
2736
+
2737
+ THEOREM ConcatEmptySeq ==
2738
+ ASSUME NEW S, NEW seq \\in Seq(S)
2739
+ PROVE /\\ seq \\o << >> = seq
2740
+ /\\ << >> \\o seq = seq
2741
+
2742
+ THEOREM ConcatEqualIffEmpty ==
2743
+ ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S)
2744
+ PROVE /\\ s \\o t = s <=> t = << >>
2745
+ /\\ s \\o t = t <=> s = << >>
2746
+ /\\ s \\o t = << >> <=> s = << >> /\\ t = << >>
2747
+
2748
+ THEOREM ConcatAssociative ==
2749
+ ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S), NEW u \\in Seq(S)
2750
+ PROVE (s \\o t) \\o u = s \\o (t \\o u)
2751
+
2752
+ (****************************************************************************)
2753
+ (* Intentionally not written as an ASSUME ... PROVE such that the conjuncts *)
2754
+ (* can be named individually. *)
2755
+ (****************************************************************************)
2756
+ THEOREM ConcatSimplifications ==
2757
+ /\\ idRight:: \\A S : \\A s,t \\in Seq(S) : s \\o t = s => t = <<>>
2758
+ /\\ idLeft:: \\A S : \\A s,t \\in Seq(S) : s \\o t = t => s = <<>>
2759
+ /\\ concIsEmpty:: \\A S : \\A s,t \\in Seq(S) : s \\o t = <<>> => s = <<>> /\\ t = <<>>
2760
+ /\\ cancelLeft:: \\A S : \\A s,t,v \\in Seq(S) : s \\o t = s \\o v => t = v
2761
+ /\\ cancelRight:: \\A S : \\A s,t,v \\in Seq(S) : s \\o v = t \\o v => s = t
832
2762
 
833
- AllSMT == TRUE (*{
834
- by (prover:"cvc33")
835
- by (prover:"smt3")
836
- by (prover:"yices3")
837
- by (prover:"verit")
838
- by (prover:"z33")
839
- }*)
840
- AllSMTT(X) == TRUE (*{
841
- by (prover:"cvc33"; timeout:@)
842
- by (prover:"smt3"; timeout:@)
843
- by (prover:"yices3"; timeout:@)
844
- by (prover:"verit"; timeout:@)
845
- by (prover:"z33"; timeout:@)
846
- }*)
2763
+ (***************************************************************************)
2764
+ (* SubSeq, Head and Tail *)
2765
+ (***************************************************************************)
847
2766
 
848
- AllIsa == TRUE (*{
849
- by (prover:"isabelle"; tactic:"auto")
850
- by (prover:"isabelle"; tactic:"force")
851
- by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
852
- by (prover:"isabelle"; tactic:"clarsimp auto?")
853
- by (prover:"isabelle"; tactic:"clarsimp")
854
- by (prover:"isabelle"; tactic:"auto, blast")
855
- }*)
856
- AllIsaT(X) == TRUE (*{
857
- by (prover:"isabelle"; tactic:"auto"; timeout:@)
858
- by (prover:"isabelle"; tactic:"force"; timeout:@)
859
- by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
860
- by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
861
- by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
862
- by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
863
- }*)
2767
+ THEOREM SubSeqProperties ==
2768
+ ASSUME NEW S, NEW s, NEW m \\in Int, NEW n \\in Int,
2769
+ \\A i \\in m .. n : s[i] \\in S
2770
+ PROVE /\\ SubSeq(s,m,n) \\in Seq(S)
2771
+ /\\ Len(SubSeq(s,m,n)) = IF m<=n THEN n-m+1 ELSE 0
2772
+ /\\ \\A i \\in 1 .. n-m+1 : SubSeq(s,m,n)[i] = s[m+i-1]
2773
+
2774
+ THEOREM SubSeqEmpty ==
2775
+ ASSUME NEW s, NEW m \\in Int, NEW n \\in Int, n < m
2776
+ PROVE SubSeq(s,m,n) = << >>
2777
+
2778
+ THEOREM SubSeqRange ==
2779
+ ASSUME NEW S, NEW s \\in Seq(S), NEW m \\in 1 .. Len(s), NEW n \\in 1 .. Len(s)
2780
+ PROVE Range(SubSeq(s,m,n)) \\subseteq Range(s)
2781
+
2782
+ THEOREM HeadTailProperties ==
2783
+ ASSUME NEW S,
2784
+ NEW s \\in Seq(S), s # << >>
2785
+ PROVE /\\ Head(s) \\in S
2786
+ /\\ Head(s) \\in Range(s)
2787
+ /\\ Tail(s) \\in Seq(S)
2788
+ /\\ Len(Tail(s)) = Len(s)-1
2789
+ /\\ \\A i \\in 1 .. Len(Tail(s)) : Tail(s)[i] = s[i+1]
2790
+ /\\ Range(Tail(s)) \\subseteq Range(s)
2791
+
2792
+ THEOREM TailIsSubSeq ==
2793
+ ASSUME NEW S,
2794
+ NEW s \\in Seq(S), s # << >>
2795
+ PROVE Tail(s) = SubSeq(s, 2, Len(s))
2796
+
2797
+ THEOREM SubSeqRestrict ==
2798
+ ASSUME NEW S, NEW seq \\in Seq(S), NEW n \\in 0 .. Len(seq)
2799
+ PROVE SubSeq(seq, 1, n) = Restrict(seq, 1 .. n)
2800
+
2801
+ THEOREM HeadTailOfSubSeq ==
2802
+ ASSUME NEW S, NEW seq \\in Seq(S),
2803
+ NEW m \\in 1 .. Len(seq), NEW n \\in m .. Len(seq)
2804
+ PROVE /\\ Head(SubSeq(seq,m,n)) = seq[m]
2805
+ /\\ Tail(SubSeq(seq,m,n)) = SubSeq(seq, m+1, n)
2806
+
2807
+ THEOREM SubSeqRecursive ==
2808
+ ASSUME NEW S, NEW seq \\in Seq(S),
2809
+ NEW m \\in 1 .. Len(seq), NEW n \\in m .. Len(seq)
2810
+ PROVE /\\ SubSeq(seq, m, n) = << seq[m] >> \\o SubSeq(seq, m+1, n)
2811
+ /\\ SubSeq(seq, m, n) = SubSeq(seq, m, n-1) \\o << seq[n] >>
864
2812
 
2813
+ (***************************************************************************)
2814
+ (* Subsequences of subsequences. *)
2815
+ (***************************************************************************)
2816
+ THEOREM SubSeqOfSubSeq ==
2817
+ ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
2818
+ NEW i \\in 1 .. Len(s), NEW j \\in 1 .. Len(s),
2819
+ NEW m \\in 1 .. j-i+1, NEW n \\in 1 .. j-i+1
2820
+ PROVE SubSeq(SubSeq(s,i,j),m,n) = SubSeq(s, i+m-1, i+n-1)
2821
+
2822
+ (*****************************************************************************)
2823
+ (* Adjacent subsequences can be concatenated to obtain a longer subsequence. *)
2824
+ (*****************************************************************************)
2825
+ THEOREM ConcatAdjacentSubSeq ==
2826
+ ASSUME NEW S, NEW seq \\in Seq(S),
2827
+ NEW m \\in 1 .. Len(seq)+1,
2828
+ NEW k \\in m-1 .. Len(seq),
2829
+ NEW n \\in k .. Len(seq)
2830
+ PROVE SubSeq(seq, m, k) \\o SubSeq(seq, k+1, n) = SubSeq(seq, m, n)
865
2831
 
866
- (**************************************************************************)
867
- (* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
868
- (* *)
869
- (* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
870
- (* *)
871
- (* The pragma AutoUSE invokes automated expansion of definitions, *)
872
- (* for both of ExpandEnabled and ExpandCdot, when each is present. *)
873
- (* *)
874
- (* The pragma Lambdify invokes expansion of the operators *)
875
- (* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
876
- (* which is a form before introducing rigid quantifiers. *)
877
- (* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
878
- (* that are not nested. *)
879
- (**************************************************************************)
880
- ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
881
- ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
882
- AutoUSE == TRUE (*{ by (prover:"autouse") }*)
883
- Lambdify == TRUE (*{ by (prover:"lambdify") }*)
884
- ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
885
- LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
2832
+ (***************************************************************************)
2833
+ (* Special cases of subsequences of concatenations. *)
2834
+ (***************************************************************************)
2835
+ THEOREM SubSeqOfConcat1 ==
2836
+ ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
2837
+ NEW m \\in 1 .. Len(s), NEW n \\in 1 .. Len(s)
2838
+ PROVE SubSeq(s \\o t, m, n) = SubSeq(s, m, n)
886
2839
 
887
- (* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
888
- (* representation within TLAPM. *)
889
- EnabledWrapper(Op(_)) == FALSE
890
- CdotWrapper(Op(_)) == FALSE
2840
+ THEOREM SubSeqOfConcat2 ==
2841
+ ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
2842
+ NEW m \\in Len(s)+1 .. Len(s)+Len(t), NEW n \\in Len(s)+1 .. Len(s)+Len(t)
2843
+ PROVE SubSeq(s \\o t, m, n) = SubSeq(t, m - Len(s), n - Len(s))
891
2844
 
892
2845
  (***************************************************************************)
893
- (* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
894
- (* triviality checks in TLAPM. *)
2846
+ (* Theorems about Append *)
2847
+ (***************************************************************************)
2848
+
2849
+ THEOREM AppendProperties ==
2850
+ ASSUME NEW S, NEW seq \\in Seq(S), NEW elt \\in S
2851
+ PROVE /\\ Append(seq, elt) \\in Seq(S)
2852
+ /\\ Append(seq, elt) # << >>
2853
+ /\\ Len(Append(seq, elt)) = Len(seq)+1
2854
+ /\\ \\A i \\in 1.. Len(seq) : Append(seq, elt)[i] = seq[i]
2855
+ /\\ Append(seq, elt)[Len(seq)+1] = elt
2856
+ /\\ Range(Append(seq, elt)) = Range(seq) \\cup {elt}
2857
+
2858
+ THEOREM AppendIsConcat ==
2859
+ ASSUME NEW S, NEW seq \\in Seq(S), NEW elt \\in S
2860
+ PROVE Append(seq, elt) = seq \\o <<elt>>
2861
+
2862
+ THEOREM HeadTailAppend ==
2863
+ ASSUME NEW S, NEW seq \\in Seq(S), NEW elt
2864
+ PROVE /\\ Head(Append(seq, elt)) = IF seq = <<>> THEN elt ELSE Head(seq)
2865
+ /\\ Tail(Append(seq, elt)) = IF seq = <<>> THEN <<>> ELSE Append(Tail(seq), elt)
2866
+
2867
+ THEOREM AppendInjective ==
2868
+ ASSUME NEW S, NEW e \\in S, NEW s \\in Seq(S), NEW f \\in S, NEW t \\in Seq(S)
2869
+ PROVE Append(s,e) = Append(t,f) <=> s = t /\\ e = f
2870
+
2871
+ THEOREM SequenceEmptyOrAppend ==
2872
+ ASSUME NEW S, NEW seq \\in Seq(S), seq # << >>
2873
+ PROVE \\E s \\in Seq(S), elt \\in S : seq = Append(s, elt)
2874
+
2875
+ (***************************************************************************)
2876
+ (* Inductive reasoning for sequences *)
2877
+ (***************************************************************************)
2878
+
2879
+ THEOREM SequencesInductionAppend ==
2880
+ ASSUME NEW P(_), NEW S,
2881
+ P(<< >>),
2882
+ \\A s \\in Seq(S), e \\in S : P(s) => P(Append(s,e))
2883
+ PROVE \\A seq \\in Seq(S) : P(seq)
2884
+
2885
+ THEOREM SequencesInductionTail ==
2886
+ ASSUME NEW S, NEW P(_),
2887
+ P(<< >>),
2888
+ \\A s \\in Seq(S) : (s # << >>) /\\ P(Tail(s)) => P(s)
2889
+ PROVE \\A s \\in Seq(S) : P(s)
2890
+
2891
+
2892
+ (***************************************************************************)
2893
+ (* RANGE OF SEQUENCE *)
2894
+ (***************************************************************************)
2895
+
2896
+ THEOREM RangeOfSeq ==
2897
+ ASSUME NEW S, NEW seq \\in Seq(S)
2898
+ PROVE Range(seq) \\in SUBSET S
2899
+
2900
+ THEOREM RangeEquality ==
2901
+ ASSUME NEW S, NEW seq \\in Seq(S)
2902
+ PROVE Range(seq) = { seq[i] : i \\in 1 .. Len(seq) }
2903
+
2904
+ THEOREM SeqOfRange ==
2905
+ ASSUME NEW S, NEW seq \\in Seq(S)
2906
+ PROVE seq \\in Seq(Range(seq))
2907
+
2908
+ (* The range of the concatenation of two sequences is the union of the ranges *)
2909
+ THEOREM RangeConcatenation ==
2910
+ ASSUME NEW S, NEW s1 \\in Seq(S), NEW s2 \\in Seq(S)
2911
+ PROVE Range(s1 \\o s2) = Range(s1) \\cup Range(s2)
2912
+
2913
+ (***************************************************************************)
2914
+ (* Theorems about injective sequences, i.e. sequences without duplicates. *)
895
2915
  (***************************************************************************)
896
- Trivial == TRUE (*{ by (prover:"trivial") }*)
897
2916
 
2917
+ LEMMA EmptySingletonIsInjective ==
2918
+ /\\ IsInjective(<< >>)
2919
+ /\\ \\A e : IsInjective(<< e >>)
2920
+
2921
+ LEMMA ConcatInjectiveSeq ==
2922
+ ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S)
2923
+ PROVE IsInjective(s \\o t) <=>
2924
+ IsInjective(s) /\\ IsInjective(t) /\\ Range(s) \\cap Range(t) = {}
2925
+
2926
+ LEMMA AppendInjectiveSeq ==
2927
+ ASSUME NEW S, NEW seq \\in Seq(S), NEW e \\in S
2928
+ PROVE IsInjective(Append(seq,e)) <=> IsInjective(seq) /\\ e \\notin Range(seq)
2929
+
2930
+ LEMMA TailInjectiveSeq ==
2931
+ ASSUME NEW S, NEW seq \\in Seq(S), IsInjective(seq), seq # << >>
2932
+ PROVE /\\ IsInjective(Tail(seq))
2933
+ /\\ Range(Tail(seq)) = Range(seq) \\ {Head(seq)}
898
2934
 
899
2935
  =============================================================================
2936
+ `],[`WellFoundedInduction`,`------------------------ MODULE WellFoundedInduction ------------------------
2937
+ (***************************************************************************)
2938
+ (* This module contains useful theorems for inductive proofs and recursive *)
2939
+ (* definitions based on a well-founded ordering. *)
2940
+ (* *)
2941
+ (* Most of the statements of the theorems are decomposed in terms of *)
2942
+ (* definitions. This is done for two reasons: *)
2943
+ (* *)
2944
+ (* - It makes it easier for the backends to instantiate the theorems *)
2945
+ (* when those definitions are not expanded. In fact, at the moment *)
2946
+ (* the provers can't prove any of those theorems from the theorem *)
2947
+ (* itself if the definitions are made usable. *)
2948
+ (* *)
2949
+ (* - It can be convenient when writing proofs to use those definitions *)
2950
+ (* rather than having to write out their expansions. *)
2951
+ (* *)
2952
+ (* A relation is represented as a set of ordered pairs, where we write *)
2953
+ (* <<x, y>> \\in R instead of x R y. It is more convenient to represent *)
2954
+ (* relations this way rather than as operators such as < . *)
2955
+ (***************************************************************************)
2956
+ EXTENDS NaturalsInduction
900
2957
 
901
- The material below is obsolete: the TLA proof rules below are superseded by
902
- the PTL decision procedure, and their formulation is unsound for the semantics
903
- of temporal reasoning that TLAPS adopts.
2958
+ (***************************************************************************)
2959
+ (* The following defines what it means for a relation R to be transitively *)
2960
+ (* closed on a set S. In this and other definitions, we think of R as a *)
2961
+ (* relation on S, meaning that it is a subset of S \\X S. However, this is *)
2962
+ (* not necessary. Our results do not require this as a hypothesis, and it *)
2963
+ (* is often convenient to apply them when R is a relation on a set *)
2964
+ (* containing S as a subset. They're even true (though uninteresting) if *)
2965
+ (* R and S \\X S are disjoint sets. *)
2966
+ (***************************************************************************)
2967
+ IsTransitivelyClosedOn(R, S) ==
2968
+ \\A i, j, k \\in S : (<<i, j>> \\in R) /\\ (<<j, k>> \\in R)
2969
+ => (<<i, k>> \\in R)
2970
+ (***************************************************************************)
2971
+ (* If we think of R as a less-than relation, then R is well founded on S *)
2972
+ (* iff there is no "infinitely descending" sequence of elements of S. The *)
2973
+ (* canonical example of a well founded relation is the ordinary less-than *)
2974
+ (* relation on the natural numbers. *)
2975
+ (* *)
2976
+ (* A S with a well-founded ordering is often called well-ordered. *)
2977
+ (***************************************************************************)
2978
+ IsWellFoundedOn(R, S) ==
2979
+ ~ \\E f \\in [Nat -> S] : \\A n \\in Nat : <<f[n+1], f[n]>> \\in R
2980
+
2981
+ LEMMA EmptyIsWellFounded == \\A S : IsWellFoundedOn({}, S)
2982
+
2983
+
2984
+ LEMMA IsWellFoundedOnSubset ==
2985
+ ASSUME NEW R, NEW S, NEW T \\in SUBSET S,
2986
+ IsWellFoundedOn(R,S)
2987
+ PROVE IsWellFoundedOn(R,T)
2988
+
2989
+
2990
+ LEMMA IsWellFoundedOnSubrelation ==
2991
+ ASSUME NEW S, NEW R, NEW RR, RR \\cap (S \\X S) \\subseteq R,
2992
+ IsWellFoundedOn(R,S)
2993
+ PROVE IsWellFoundedOn(RR,S)
2994
+
2995
+ (***************************************************************************)
2996
+ (* If we think of R as a less-than relation on S, then the following is *)
2997
+ (* the set of elements of S that are less than x. *)
2998
+ (***************************************************************************)
2999
+ SetLessThan(x, R, S) == {y \\in S : <<y, x>> \\in R}
3000
+
3001
+ (***************************************************************************)
3002
+ (* If we think of R as a less-than relation on S, then R is well-founded *)
3003
+ (* iff every non-empty subset of S has a minimal element. *)
3004
+ (***************************************************************************)
3005
+
3006
+ THEOREM WFMin ==
3007
+ ASSUME NEW R, NEW S,
3008
+ IsWellFoundedOn(R, S),
3009
+ NEW T, T \\subseteq S, T # {}
3010
+ PROVE \\E x \\in T : \\A y \\in T : ~ (<<y, x>> \\in R)
3011
+
3012
+
3013
+ THEOREM MinWF ==
3014
+ ASSUME NEW R, NEW S,
3015
+ \\A T \\in SUBSET S : T # {} => \\E x \\in T : \\A y \\in T : ~ (<<y, x>> \\in R)
3016
+ PROVE IsWellFoundedOn(R,S)
3017
+
3018
+ (***************************************************************************)
3019
+ (* The two following lemmas are simple consequences of theorem WFMin. *)
3020
+ (***************************************************************************)
3021
+ LEMMA WellFoundedIsIrreflexive ==
3022
+ ASSUME NEW R, NEW S, NEW x \\in S,
3023
+ IsWellFoundedOn(R, S)
3024
+ PROVE <<x, x>> \\notin R
3025
+
3026
+ LEMMA WellFoundedIsAsymmetric ==
3027
+ ASSUME NEW R, NEW S, NEW x \\in S, NEW y \\in S,
3028
+ IsWellFoundedOn(R,S),
3029
+ <<x,y>> \\in R, <<y,x>> \\in R
3030
+ PROVE FALSE
3031
+
3032
+ (***************************************************************************)
3033
+ (* The following lemmas are simple facts about operator SetLessThan. *)
3034
+ (***************************************************************************)
3035
+ LEMMA WFSetLessThanIrreflexive ==
3036
+ ASSUME NEW R, NEW S, NEW x \\in S,
3037
+ IsWellFoundedOn(R,S)
3038
+ PROVE x \\notin SetLessThan(x,R,S)
3039
+
3040
+ LEMMA SetLessTransitive ==
3041
+ ASSUME NEW R, NEW S, NEW x \\in S, NEW y \\in SetLessThan(x,R,S),
3042
+ IsTransitivelyClosedOn(R, S)
3043
+ PROVE SetLessThan(y, R, S) \\subseteq SetLessThan(x, R, S)
904
3044
 
905
3045
  ----------------------------------------------------------------------------
906
3046
  (***************************************************************************)
907
- (* TEMPORAL LOGIC *)
908
- (* *)
909
- (* The following rules are intended to be used when TLAPS handles temporal *)
910
- (* logic. They will not work now. Moreover when temporal reasoning is *)
911
- (* implemented, these rules may be changed or omitted, and additional *)
912
- (* rules will probably be added. However, they are included mainly so *)
913
- (* their names will be defined, preventing the use of identifiers that are *)
914
- (* likely to produce name clashes with future versions of this module. *)
3047
+ (* The following theorem is the basis for proof by induction over a *)
3048
+ (* well-founded set. It generalizes theorem GeneralNatInduction of module *)
3049
+ (* NaturalsInduction. *)
915
3050
  (***************************************************************************)
3051
+ THEOREM WFInduction ==
3052
+ ASSUME NEW P(_), NEW R, NEW S,
3053
+ IsWellFoundedOn(R, S),
3054
+ \\A x \\in S : (\\A y \\in SetLessThan(x, R, S) : P(y))
3055
+ => P(x)
3056
+ PROVE \\A x \\in S : P(x)
916
3057
 
3058
+ (***************************************************************************)
3059
+ (* Theorem WFInductiveDef below justifies recursive definitions based on a *)
3060
+ (* well-founded ordering. We first prove it with the hypothesis that the *)
3061
+ (* ordering is transitively closed. We prove the theorem for an arbitrary *)
3062
+ (* well-founded relation by applying the special case to its transitive *)
3063
+ (* closure. *)
3064
+ (***************************************************************************)
3065
+ WFDefOn(R, S, Def(_,_)) ==
3066
+ \\A g, h :
3067
+ \\A x \\in S :
3068
+ (\\A y \\in SetLessThan(x, R, S) : g[y] = h[y])
3069
+ => (Def(g,x) = Def(h,x))
3070
+
3071
+ OpDefinesFcn(f, S, Def(_,_)) ==
3072
+ f = CHOOSE g : g = [x \\in S |-> Def(g, x)]
3073
+
3074
+ WFInductiveDefines(f, S, Def(_,_)) ==
3075
+ f = [x \\in S |-> Def(f, x)]
3076
+
3077
+ WFInductiveUnique(S, Def(_,_)) ==
3078
+ \\A g, h : /\\ WFInductiveDefines(g, S, Def)
3079
+ /\\ WFInductiveDefines(h, S, Def)
3080
+ => (g = h)
3081
+
3082
+ THEOREM WFDefOnUnique ==
3083
+ ASSUME NEW Def(_,_), NEW R, NEW S,
3084
+ IsWellFoundedOn(R, S), WFDefOn(R, S, Def)
3085
+ PROVE WFInductiveUnique(S, Def)
3086
+
3087
+ LEMMA WFInductiveDefLemma ==
3088
+ ASSUME NEW Def(_,_), NEW R, NEW S, NEW f,
3089
+ IsWellFoundedOn(R, S),
3090
+ IsTransitivelyClosedOn(R, S),
3091
+ WFDefOn(R, S, Def),
3092
+ OpDefinesFcn(f, S, Def)
3093
+ PROVE WFInductiveDefines(f, S, Def)
917
3094
 
918
3095
  (***************************************************************************)
919
- (* The following proof rules (and their names) are from the paper "The *)
920
- (* Temporal Logic of Actions". *)
3096
+ (* The following defines the transitive closure of the relation R on S. *)
3097
+ (* More precisely, it is the transitive closure of the restriction of R *)
3098
+ (* to S. We give an abstract definition of transitive closure as the *)
3099
+ (* smallest relation that contains R (restricted to S \\X S) and that is *)
3100
+ (* transitively closed, then prove some relevant properties. *)
921
3101
  (***************************************************************************)
922
- THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
923
- P /\\ (f' = f) => P'
924
- PROVE []P <=> P /\\ [][P => P']_f
3102
+ TransitiveClosureOn(R,S) ==
3103
+ { ss \\in S \\X S :
3104
+ \\A U \\in SUBSET (S \\X S) :
3105
+ /\\ R \\cap S \\X S \\subseteq U
3106
+ /\\ IsTransitivelyClosedOn(U, S)
3107
+ => ss \\in U }
3108
+
3109
+ LEMMA TransitiveClosureThm ==
3110
+ \\A R, S :
3111
+ /\\ R \\cap S \\X S \\subseteq TransitiveClosureOn(R, S)
3112
+ /\\ IsTransitivelyClosedOn(TransitiveClosureOn(R, S), S)
3113
+
3114
+ LEMMA TransitiveClosureMinimal ==
3115
+ ASSUME NEW R, NEW S, NEW U \\in SUBSET (S \\X S),
3116
+ R \\cap S \\X S \\subseteq U,
3117
+ IsTransitivelyClosedOn(U,S)
3118
+ PROVE TransitiveClosureOn(R,S) \\subseteq U
925
3119
 
926
- THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
927
- ACTION A, ACTION B,
928
- P /\\ [A]_f => Q /\\ [B]_g
929
- PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
3120
+ (***************************************************************************)
3121
+ (* The following lemmas are consequences of the two previous ones. The *)
3122
+ (* first three state closure properties of transitive closure, the fourth *)
3123
+ (* lemma allows one to chop off a step in the underlying relation for any *)
3124
+ (* pair in the transitive closure. *)
3125
+ (***************************************************************************)
930
3126
 
931
- THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
932
- I /\\ [N]_F => I'
933
- PROVE I /\\ [][N]_F => []I
3127
+ LEMMA TCTCTC ==
3128
+ ASSUME NEW R, NEW S, NEW i \\in S, NEW j \\in S, NEW k \\in S,
3129
+ <<i,j>> \\in TransitiveClosureOn(R,S),
3130
+ <<j,k>> \\in TransitiveClosureOn(R,S)
3131
+ PROVE <<i,k>> \\in TransitiveClosureOn(R,S)
934
3132
 
935
- THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
936
- PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
3133
+ LEMMA TCRTC ==
3134
+ ASSUME NEW R, NEW S, NEW i \\in S, NEW j \\in S, NEW k \\in S,
3135
+ <<i,j>> \\in TransitiveClosureOn(R,S), <<j,k>> \\in R
3136
+ PROVE <<i,k>> \\in TransitiveClosureOn(R,S)
937
3137
 
938
- THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
939
- P /\\ [N]_f => (P' \\/ Q'),
940
- P /\\ <<N /\\ A>>_f => Q',
941
- P => ENABLED <<A>>_f
942
- PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
3138
+ LEMMA RTCTC ==
3139
+ ASSUME NEW R, NEW S, NEW i \\in S, NEW j \\in S, NEW k \\in S,
3140
+ <<i,j>> \\in R, <<j,k>> \\in TransitiveClosureOn(R,S)
3141
+ PROVE <<i,k>> \\in TransitiveClosureOn(R,S)
943
3142
 
944
- THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
945
- ACTION N, ACTION A, TEMPORAL F,
946
- P /\\ [N]_f => (P' \\/ Q'),
947
- P /\\ <<N /\\ A>>_f => Q',
948
- []P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
949
- PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
3143
+ LEMMA TransitiveClosureChopLast ==
3144
+ ASSUME NEW R, NEW S, NEW i \\in S, NEW k \\in S, <<i,k>> \\in TransitiveClosureOn(R,S)
3145
+ PROVE \\E j \\in S : /\\ <<j,k>> \\in R
3146
+ /\\ i = j \\/ <<i,j>> \\in TransitiveClosureOn(R,S)
950
3147
 
951
3148
  (***************************************************************************)
952
- (* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
953
- (* from the following two rules by the following substitutions: \`. *)
954
- (* *)
955
- (* ___ ___ _______________ *)
956
- (* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
3149
+ (* NB: In a similar way to the preceding lemma, one could prove *)
3150
+ (* ASSUME NEW R, NEW S, NEW x \\in S, NEW y \\in S, *)
3151
+ (* <<x,y>> \\in TransitiveClosureOn(R,S) *)
3152
+ (* PROVE \\E n \\in Nat : \\E f \\in [0..(n+1) -> S] : *)
3153
+ (* /\\ \\A i \\in 0..n : <<f[i], f[i+1]>> \\in R *)
3154
+ (* /\\ x = f[0] /\\ y = f[n+1] *)
3155
+ (* which provides a more constructive characterization of transitive *)
3156
+ (* closure. The converse theorem would be proved by induction on n, *)
3157
+ (* using the above closure properties. *)
957
3158
  (***************************************************************************)
958
- THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
959
- ACTION A, ACTION B, ACTION N, ACTION M,
960
- TEMPORAL F,
961
- <<N /\\ B>>_f => <<M>>_g,
962
- P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
963
- P /\\ EM => ENABLED A,
964
- [][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
965
- PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
966
3159
 
967
- THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
968
- ACTION A, ACTION B, ACTION N, ACTION M,
969
- TEMPORAL F,
970
- <<N /\\ B>>_f => <<M>>_g,
971
- P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
972
- P /\\ EM => ENABLED A,
973
- [][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
974
- PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
3160
+ THEOREM TransitiveClosureWF ==
3161
+ ASSUME NEW R, NEW S, IsWellFoundedOn(R,S)
3162
+ PROVE IsWellFoundedOn(TransitiveClosureOn(R, S), S)
975
3163
 
3164
+ THEOREM WFInductiveDef ==
3165
+ ASSUME NEW Def(_,_), NEW R, NEW S, NEW f,
3166
+ IsWellFoundedOn(R, S),
3167
+ WFDefOn(R, S, Def),
3168
+ OpDefinesFcn(f, S, Def)
3169
+ PROVE WFInductiveDefines(f, S, Def)
976
3170
 
977
3171
  (***************************************************************************)
978
- (* The following rule is a special case of the general temporal logic *)
979
- (* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
980
- (* general rule is for arbitrary temporal formulas F and G, but it cannot *)
981
- (* yet be handled by TLAPS. *)
3172
+ (* Theorem WFInductiveDef allows us to conclude that a recursively defined *)
3173
+ (* function satisfies its recursion equation. The following result allows *)
3174
+ (* us to deduce the range of this function. *)
982
3175
  (***************************************************************************)
983
- THEOREM RuleInvImplication ==
984
- ASSUME STATE F, STATE G,
985
- F => G
986
- PROVE []F => []G
987
- PROOF OMITTED
3176
+ THEOREM WFInductiveDefType ==
3177
+ ASSUME NEW Def(_,_), NEW f, NEW R, NEW S, NEW T,
3178
+ T # {},
3179
+ IsWellFoundedOn(R, S),
3180
+ WFDefOn(R, S, Def),
3181
+ WFInductiveDefines(f, S, Def),
3182
+ \\A g \\in [S -> T], s \\in S : Def(g, s) \\in T
3183
+ PROVE f \\in [S -> T]
3184
+
3185
+ ----------------------------------------------------------------------------
3186
+ (***************************************************************************)
3187
+ (* Below are some theorems that allow us to derive some useful *)
3188
+ (* well-founded relations from a given well-founded relation. First, we *)
3189
+ (* define the operator OpToRel that constructs a relation (a set of *)
3190
+ (* ordered pairs) from a relation expressed as an operator. *)
3191
+ (***************************************************************************)
3192
+ OpToRel(_\\prec_, S) == {ss \\in S \\X S : ss[1] \\prec ss[2]}
988
3193
 
989
3194
  (***************************************************************************)
990
- (* The following rule is a special case of rule TLA2 from the paper "The *)
991
- (* Temporal Logic of Actions". *)
3195
+ (* To construct well-founded relations from the less-than relation on the *)
3196
+ (* natural numbers, we first prove that it is well-founded. *)
992
3197
  (***************************************************************************)
993
- THEOREM RuleStepSimulation ==
994
- ASSUME STATE I, STATE f, STATE g,
995
- ACTION M, ACTION N,
996
- I /\\ I' /\\ [M]_f => [N]_g
997
- PROVE []I /\\ [][M]_f => [][N]_g
998
- PROOF OMITTED
3198
+ THEOREM NatLessThanWellFounded == IsWellFoundedOn(OpToRel(<,Nat), Nat)
999
3199
 
1000
3200
  (***************************************************************************)
1001
- (* The following may be used to invoke a decision procedure for *)
1002
- (* propositional temporal logic. *)
3201
+ (* The next definition would be easier to read if we used the TLA+ *)
3202
+ (* construct {<<x, y>> \\in T : ... }. However, TLAPS does not suport *)
3203
+ (* that notation. (It's meaning is rather complicated in the general case *)
3204
+ (* when T is not a Cartesian product of sets.) *)
1003
3205
  (***************************************************************************)
1004
- PropositionalTemporalLogic == TRUE
3206
+ PreImage(f(_), S, R) == {ss \\in S \\X S : <<f(ss[1]), f(ss[2])>> \\in R}
3207
+
3208
+ THEOREM PreImageWellFounded ==
3209
+ ASSUME NEW S, NEW T, NEW R, NEW f(_),
3210
+ \\A s \\in S : f(s) \\in T,
3211
+ IsWellFoundedOn(R, T)
3212
+ PROVE IsWellFoundedOn(PreImage(f, S, R), S)
3213
+
3214
+ (***************************************************************************)
3215
+ (* We now prove that the lexicographical ordering on the Cartesian product *)
3216
+ (* of two well-ordered sets is well-ordered. *)
3217
+ (***************************************************************************)
3218
+ LexPairOrdering(R1, R2, S1, S2) ==
3219
+ {ss \\in (S1 \\X S2) \\X (S1 \\X S2) :
3220
+ \\/ <<ss[1][1], ss[2][1]>> \\in R1
3221
+ \\/ /\\ ss[1][1] = ss[2][1]
3222
+ /\\ <<ss[1][2], ss[2][2]>> \\in R2}
3223
+
3224
+ THEOREM WFLexPairOrdering ==
3225
+ ASSUME NEW R1, NEW R2, NEW S1, NEW S2,
3226
+ IsWellFoundedOn(R1, S1),
3227
+ IsWellFoundedOn(R2, S2)
3228
+ PROVE IsWellFoundedOn(LexPairOrdering(R1, R2, S1, S2), S1 \\X S2)
3229
+
3230
+ (***************************************************************************)
3231
+ (* The preceding theorem generalizes in the obvious way to the Cartesian *)
3232
+ (* product of a finite number of well-ordered sets. However, the *)
3233
+ (* statement of the general theorem is rather complicated, so we state it *)
3234
+ (* for the most useful case: the Cartesian product of n copies of the same *)
3235
+ (* set. *)
3236
+ (***************************************************************************)
3237
+ LexProductOrdering(R, S, n) ==
3238
+ { ff \\in [1..n -> S] \\X [1..n -> S] :
3239
+ \\E j \\in 1..n :
3240
+ /\\ \\A i \\in 1..(j-1) : ff[1][i] = ff[2][i]
3241
+ /\\ <<ff[1][j], ff[2][j]>> \\in R }
3242
+
3243
+ THEOREM WFLexProductOrdering ==
3244
+ ASSUME NEW R, NEW S, NEW n \\in Nat,
3245
+ IsWellFoundedOn(R, S)
3246
+ PROVE IsWellFoundedOn(LexProductOrdering(R, S, n), [1..n -> S])
3247
+
1005
3248
  =============================================================================
1006
- `}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return fo}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return ji}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Ru}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return na}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Ye}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Nu}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Qa}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Bu}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return uo}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Pu}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return V}});
3249
+ \\* Modification History
3250
+ \\* Last modified Thu Aug 22 18:31:26 CEST 2019 by merz
3251
+ \\* Last modified Sun Jan 01 18:39:23 CET 2012 by merz
3252
+ \\* Last modified Wed Nov 23 10:13:18 PST 2011 by lamport
3253
+ `]]),Of=[`zenon`,`isabelle`,`smt`,`z3`,`ls4`],kf=e=>Of.some(t=>t===e),Af=3e3,jf=[`expandenabled`,`expandcdot`,`lambdify`,`enabledaxioms`,`levelcomparison`],Mf=`b91fb6c`,Nf=(e,t=!0)=>{let n=ms(e);return t?Sc(n):n},Pf=e=>e.locus?`file ${JSON.stringify(e.locus.file)}, ${je(e.locus)}`:`<unknown location>`,Ff=e=>{let t=Nf(e.sequent,e.settings.isFlattened),n=xf(t,e.session,{version:Mf,id:e.obligation.id,location:Pf(e.obligation),logic:e.settings.smtLogic},e.settings.smtEncoding);e.write(`;; Proof obligation:\n${en(Dn(t)).replace(/^/gm,`;; `)}\n${e.method.rlimit===void 0?``:`(set-option :rlimit ${e.method.rlimit})\n`}${n}`)},If={smt:{encode:Ff,suffix:`.smt`,isCaseNumbered:!0},z3:{encode:Ff,suffix:`.smt2`,isCaseNumbered:!0},zenon:{encode:e=>e.write(Ef(e.obligation.id,Nf(e.sequent,e.settings.isFlattened))),suffix:`.znn`},isabelle:{encode:e=>Do(e.obligation.id,Nf(e.sequent,e.settings.isFlattened),e.method.tactic??`auto`,e.name,{location:Pf(e.obligation),fingerprint:e.fingerprint},e.write),suffix:`.thy`},ls4:{encode:e=>e.write(Ac(e.sequent)),suffix:`.ls4`}},Lf=()=>`tlapm_${Math.floor(Math.random()*16777216).toString(16).padStart(6,`0`)}`,Rf=(e,t,n)=>e.prover===`isabelle`?`using assms by ${e.tactic??`auto`}\n`:e.prover===`zenon`?`\n(* BEGIN ZENON INPUT\n;; zenon -p0 -x tla -oisar -max-time 1d\n${t}\nEND ZENON INPUT *)\n${n.output??``}`:``,zf=(e,t)=>(e.prover===`smt`||e.prover===`z3`)&&t.output!==void 0&&/^(sat|unknown)/.test(t.output)?`\n(* SMT failed with status = ${t.output} *)\n`:void 0,Bf=e=>e.kind===`Case`&&e.other===void 0||st(e).some(Bf),Vf=/* @__PURE__ */ new WeakMap,Hf=e=>{let t=Vf.get(e);if(t!==void 0)return t;let n=[];it(e,e=>(n.push(e),e),`all`);let r=n.some(Bf);return Vf.set(e,r),r},Uf=e=>/-{4,}\s*MODULE\s+(\w+)/.exec(e)?.[1]??`Main`,Wf=e=>({id:e.id,location:e.location,text:e.text}),Gf=(e,t,n,r=[])=>({obligation:{...Wf(e),status:t,reason:n},attempts:r}),Kf=e=>e.kind===`decided`?e.verdict===`unsat`:(e.kind===`stored`||e.kind===`reused`)&&e.isProved,qf=e=>{switch(e.kind){case`decided`:return e.verdict===`unsat`?void 0:e.timeUsedMs>=Math.max(e.method.timeLimitMs,Af)?`timeout`:`false`;case`error`:return`false`;default:return e.reason}},Jf=(e,t,n)=>`${On(t.kind===`reused`||Ws.has(t.method.prover)?gc(ac(e.sequent,t.kind!==`reused`)):vc(e),n)}\n`,Yf=(e,t,n)=>Oo(e,t.flatMap((e,t)=>e.attempts.flatMap(r=>r.kind===`decided`&&r.proof?[{id:e.obligation.id,sequent:Nf(vc(n[t])),proof:r.proof}]:[]))),Xf=async(e,t)=>{let n=e.tasks[t];if(n.session)return n.session.current;let r=e.tasks.slice(0,t);await Promise.all(r.map(e=>e.done));let i=r.reduce((e,t)=>e+(t.session?t.session.current.caseErrors-t.session.initial:0),0);return n.session={initial:i,current:{caseErrors:i}},n.session.current},Zf=async(t,n,r,i,a)=>{if(t.kind.kind===`Error`)return Gf(t,`failed`,t.kind.message);let o=$s(t,r.settings.defaultMethods),s={...o,provers:o.provers.map(e=>({...e,timeLimitMs:e.timeLimitMs*r.settings.stretch}))},c=ws(t.sequent),l=r.lastByFingerprint.get(c);r.lastByFingerprint.set(c,n),await(l===void 0?void 0:r.tasks[l].done);let u=[],d=[],f=e=>({obligation:{...Wf(t),status:`proved`,prover:e},attempts:u}),p=e=>{r.isFingerprinted(t)||r.results.delete(c);let n=r.results.get(c)?.get(e.prover);return n?.method.tactic===e.tactic?n:void 0},m=e=>u.push({kind:`reused`,method:e.method,isProved:Kf(e),reason:qf(e),shipped:`shipped`in e?e.shipped:void 0}),h=e=>{u.push(e),r.results.set(c,(r.results.get(c)??/* @__PURE__ */ new Map).set(e.method.prover,e))},g=(e,t)=>{u.push({kind:`skipped`,method:e,reason:t}),d.push({reason:t,isDecided:!1})},_=p(s.provers[0]);if(_&&Kf(_))return m(_),f(_.method.prover);let v=(()=>{try{return vc(t,s,a)}catch(t){if(!(t instanceof e.j))throw t;return t}})();if(v instanceof e.j){let e=jf.find(e=>s.frontends.has(e));if(e===void 0)throw v;return h({kind:`failed`,method:{prover:e,timeLimitMs:1/0},reason:v.message,note:`${v.message}\nObligation:\n\n`}),Gf(t,`failed`,`${e} failed: ${v.message}`,u)}let y=v;if(t.kind.kind===`Support`&&yc(y))return r.results.set(c,r.results.get(c)??/* @__PURE__ */ new Map),{obligation:{...Wf(t),status:`trivial`},attempts:u};for(let a of s.provers){let o=p(a);if(o&&Kf(o))return m(o),f(a.prover);if(o&&Us(o.method)>=Us(a))m(o),d.push({reason:`${a.prover} failed on an obligation with the same fingerprint`,isDecided:!0});else if(r.isProving){if(a.prover===`trivial`)return Gf(t,`failed`,`the trivial method`,u);if(a.prover===`fail`)d.push({reason:`the fail method`,isDecided:!0});else if(a.prover===`cooper`){let e=`Cooper's method is not available any more.
3254
+ `;h({kind:`failed`,method:a,warning:e,note:`\n\\* ${e}\n`,shipped:`${On(Nf(y,r.settings.isFlattened))}\n`}),d.push({reason:`Cooper's method is not available any more.`,isDecided:!0})}else if(!kf(a.prover))g(a,`tla-ts has no ${a.prover} backend`);else try{let o=If[a.prover],s=o.isCaseNumbered&&(y.context.some(Hf)||Bf(y.active))?await Xf(r,n):{caseErrors:0},l=Lf(),u=`${l}${o.suffix}`,p=[];try{o.encode({obligation:t,sequent:y,fingerprint:c,method:a,session:s,name:l,settings:r.settings,write:e=>p.push(e)})}catch(t){if(!(t instanceof e.j))throw t;h({kind:`failed`,method:a,reason:t.message}),d.push({reason:`${a.prover} failed: ${t.message}`,isDecided:!0});continue}finally{r.settings.onInput?.(u,p.join(``))}let m=p.join(``),g=Math.max(a.timeLimitMs,Af),_=a.prover===`smt`&&r.settings.solveSmt?await r.settings.solveSmt(u,m,g):await r.decide(a.prover,m,{timeLimitMs:g,signal:i},n),v=_.verdict===`unsat`;if(h({kind:`decided`,method:a,verdict:_.verdict,timeUsedMs:_.timeUsedMs,...v?{proof:Rf(a,m,_)}:_.timeUsedMs<g&&{note:zf(a,_)},..._.errorOutput!==void 0&&{errorOutput:_.errorOutput}}),v)return f(a.prover);d.push({reason:`${a.prover} answered ${_.verdict}`,isDecided:!0})}catch(t){if(t instanceof e.j){h({kind:`error`,method:a}),d.push({reason:`${a.prover} failed: ${t.message}`,isDecided:!0});continue}if(!(t instanceof e.B))throw t;g(a,`${a.prover} can't encode ${t.message}`)}}}return Gf(t,d.some(e=>e.isDecided)?`failed`:`unsupported`,d.map(e=>e.reason).join(`, `),u)},Qf=(t,n,r)=>{if(n instanceof e.E)return r({text:`${Ie(n.locus)}${n.message}`,channel:`toolbox`}),Gf(t,`failed`,n.message);if(n instanceof e.B)return Gf(t,`unsupported`,n.message);if(n instanceof e.j)return Gf(t,`failed`,n.message);throw n},$f={stretch:1,isFlattened:!0,smtLogic:`UFNIA`,smtEncoding:{isArithmetic:!0,rewriteLevel:0,isSetExtensional:!0,isTyped:!1}},ep=async(t,r)=>{let i=r.workers??1,a=i>1&&e.r()?await so(i):void 0,o=()=>a?.terminate(r.signal?.reason);r.signal?.addEventListener(`abort`,o);let s={tasks:[],results:r.results??/* @__PURE__ */ new Map,isFingerprinted:r.isFingerprinted??(()=>!0),isProving:r.isProving??!0,lastByFingerprint:/* @__PURE__ */ new Map,decide:a?.decide??(async(e,t,r)=>n.t(e,t,r)),settings:{defaultMethods:r.defaultMethods,stretch:r.stretch??$f.stretch,isFlattened:r.isFlattened??$f.isFlattened,smtLogic:r.smtLogic??$f.smtLogic,smtEncoding:r.smtEncoding??$f.smtEncoding,onInput:r.onInput,solveSmt:r.solveSmt}},c=a?i*4:1,l=/* @__PURE__ */ new Set,u=[],d=async()=>{for(;u.length<s.tasks.length&&s.tasks[u.length].isSettled;){r.signal?.throwIfAborted();let e=await s.tasks[u.length].report;u.push(e),r.onReport?.(e,t[u.length-1]),await new Promise(e=>setTimeout(e))}};try{for(let[e,n]of t.entries()){r.signal?.throwIfAborted();let t=[],i=e=>t.push(e),a=Zf(n,e,s,r.signal,i).catch(e=>Qf(n,e,i)).then(e=>({...e,warnings:t})),o=()=>{u.isSettled=!0,l.delete(u.done)},u={report:a,done:a.then(o,o),isSettled:!1,session:void 0};s.tasks.push(u),l.add(u.done),l.size>=c&&await Promise.race(l),await d()}await Promise.all(l),await d()}finally{r.signal?.removeEventListener(`abort`,o),a?.terminate(new e.j(`prove stopped`))}return u},tp=(e,t)=>({...Wf(e),...t??{status:`unsupported`,reason:`tlapm reported no result`}}),np=async t=>{let n=Uf(t.source),r=/* @__PURE__ */ new Map,i=oo([{file:`${n}.tla`,source:t.source}],e=>{let n=t.loadModule?.(e);n!==void 0&&r.set(e,n);let i=n??Df.get(e);return i===void 0?void 0:{file:`${e}.tla`,source:i}}),a=i.flatMap(e=>e.obligations),o={missingProofCount:i.reduce((e,t)=>e+t.summary.absent.length,0),omittedProofCount:i.reduce((e,t)=>e+t.summary.omitted.length,0)};if(t.backend===`tlapm`){if(typeof process>`u`||process.versions?.node===void 0)throw new e.B(`The tlapm backend runs only in Node and Bun.`);let i=await Promise.resolve().then(()=>require("./tlapm.cjs")).then(e=>e.n),s=new Map(a.map(e=>[e.id,e])),c=await i.proveWithTlapm(n,new Map([[n,t.source],...r]),{signal:t.signal,onResult:(e,n)=>{let r=s.get(e);r&&t.onObligation?.(tp(r,n))}});return{obligations:a.map(e=>tp(e,c.get(e.id))),...o}}return{obligations:(await ep(a,{workers:t.workers,signal:t.signal,onReport:e=>t.onObligation?.(e.obligation)})).map(e=>e.obligation),...o}};Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return en}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Kf}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Of}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return tc}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return qa}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Dn}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return qf}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Df}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return oo}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Yf}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return np}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return ao}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Jf}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return ep}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Mf}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Us}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Me}});