tla-ts 0.0.4-dev.a0009b7 → 0.0.4-dev.c4929d7

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 (313) hide show
  1. package/README.md +27 -141
  2. package/dist/deciders.cjs +366 -0
  3. package/dist/deciders.js +366 -0
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +37 -1
  6. package/dist/index.d.ts +37 -1
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +1 -4
  9. package/dist/parallel-worker.js +1 -4
  10. package/dist/prove-worker.cjs +9 -0
  11. package/dist/prove-worker.d.cts +9 -0
  12. package/dist/prove-worker.d.ts +9 -0
  13. package/dist/prove-worker.js +9 -0
  14. package/dist/prove.cjs +996 -0
  15. package/dist/prove.js +996 -0
  16. package/dist/run-cli.cjs +37 -47
  17. package/dist/run-cli.js +37 -47
  18. package/dist/tlapm.cjs +10 -0
  19. package/dist/tlapm.js +10 -0
  20. package/dist/transfer.cjs +38 -44
  21. package/dist/transfer.js +38 -44
  22. package/dist/worker.cjs +21 -0
  23. package/dist/worker.js +21 -0
  24. package/package.json +21 -12
  25. package/src/check.ts +1 -0
  26. package/src/codegen.ts +26 -7
  27. package/src/errors.ts +86 -0
  28. package/src/evaluate.ts +63 -20
  29. package/src/index.ts +10 -0
  30. package/src/{obligation-action.ts → obligations/action.ts} +265 -55
  31. package/src/{obligation-anon.ts → obligations/anon.ts} +47 -37
  32. package/src/obligations/ctx.ts +64 -0
  33. package/src/{obligation-deref.ts → obligations/deref.ts} +38 -61
  34. package/src/{obligation-expression.ts → obligations/expression.ts} +78 -45
  35. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  36. package/src/{obligation-generate.ts → obligations/generate.ts} +147 -74
  37. package/src/{obligations.ts → obligations/index.ts} +29 -13
  38. package/src/{obligation-levels.ts → obligations/levels.ts} +14 -5
  39. package/src/{obligation-module.ts → obligations/module.ts} +56 -33
  40. package/src/obligations/pickle.ts +98 -0
  41. package/src/obligations/pragma.ts +189 -0
  42. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  43. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
  44. package/src/{obligation-source.ts → obligations/source.ts} +159 -97
  45. package/src/obligations/temporal.ts +319 -0
  46. package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
  47. package/src/ocaml-marshal.ts +166 -0
  48. package/src/parallel-worker.ts +2 -18
  49. package/src/parallel.ts +10 -43
  50. package/src/prove/decide-pool.ts +100 -0
  51. package/src/prove/deciders.ts +33 -0
  52. package/src/prove/isabelle/LICENSE +36 -0
  53. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  54. package/src/prove/isabelle/decide.ts +47 -0
  55. package/src/prove/isabelle/encode.ts +503 -0
  56. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  57. package/src/prove/isabelle/isar/method.ts +367 -0
  58. package/src/prove/isabelle/isar/proof.ts +28 -0
  59. package/src/prove/isabelle/isar/statement.ts +57 -0
  60. package/src/prove/isabelle/isar/theory.ts +192 -0
  61. package/src/prove/isabelle/isar/type-check.ts +278 -0
  62. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  63. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  64. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  65. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  66. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  67. package/src/prove/isabelle/provers/blast/term.ts +547 -0
  68. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  69. package/src/prove/isabelle/provers/classical.ts +389 -0
  70. package/src/prove/isabelle/provers/hypsubst.ts +441 -0
  71. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  72. package/src/prove/isabelle/pure/consts.ts +32 -0
  73. package/src/prove/isabelle/pure/conv.ts +79 -0
  74. package/src/prove/isabelle/pure/drule.ts +264 -0
  75. package/src/prove/isabelle/pure/envir.ts +363 -0
  76. package/src/prove/isabelle/pure/goal.ts +53 -0
  77. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  78. package/src/prove/isabelle/pure/list.ts +12 -0
  79. package/src/prove/isabelle/pure/logic.ts +402 -0
  80. package/src/prove/isabelle/pure/name.ts +110 -0
  81. package/src/prove/isabelle/pure/net.ts +262 -0
  82. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  83. package/src/prove/isabelle/pure/pattern.ts +650 -0
  84. package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
  85. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  86. package/src/prove/isabelle/pure/search.ts +68 -0
  87. package/src/prove/isabelle/pure/seq.ts +156 -0
  88. package/src/prove/isabelle/pure/simplifier.ts +112 -0
  89. package/src/prove/isabelle/pure/table.ts +208 -0
  90. package/src/prove/isabelle/pure/tactic.ts +276 -0
  91. package/src/prove/isabelle/pure/tactical.ts +347 -0
  92. package/src/prove/isabelle/pure/term-ord.ts +159 -0
  93. package/src/prove/isabelle/pure/term.ts +808 -0
  94. package/src/prove/isabelle/pure/thm.ts +806 -0
  95. package/src/prove/isabelle/pure/type.ts +133 -0
  96. package/src/prove/isabelle/pure/unify.ts +753 -0
  97. package/src/prove/isabelle/pure/variable.ts +25 -0
  98. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  99. package/src/prove/isabelle/tla/context.ts +74 -0
  100. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  101. package/src/prove/isabelle/tla/logic.ts +215 -0
  102. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  103. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  104. package/src/prove/ocaml.ts +22 -0
  105. package/src/prove/prep/action.ts +521 -0
  106. package/src/prove/prep/defs.ts +33 -0
  107. package/src/prove/prep/elab.ts +156 -0
  108. package/src/prove/prep/enabled-axioms.ts +189 -0
  109. package/src/prove/prep/enabled.ts +43 -0
  110. package/src/prove/prep/fingerprint.ts +388 -0
  111. package/src/prove/prep/flatten.ts +70 -0
  112. package/src/prove/prep/level-comparison.ts +557 -0
  113. package/src/prove/prep/md5.ts +67 -0
  114. package/src/prove/prep/pragma.ts +221 -0
  115. package/src/prove/prep/trivial.ts +22 -0
  116. package/src/prove/prove-worker.ts +25 -0
  117. package/src/prove/prove.ts +505 -0
  118. package/src/prove/ptl/decide.ts +68 -0
  119. package/src/prove/ptl/encode.ts +256 -0
  120. package/src/prove/ptl/sat.ts +151 -0
  121. package/src/prove/ptl/tableau.ts +276 -0
  122. package/src/prove/smt/axiomatize.ts +69 -0
  123. package/src/prove/smt/axioms.ts +222 -0
  124. package/src/prove/smt/context.ts +108 -0
  125. package/src/prove/smt/data.ts +636 -0
  126. package/src/prove/smt/encode.ts +166 -0
  127. package/src/prove/smt/extensionality.ts +65 -0
  128. package/src/prove/smt/flatten.ts +112 -0
  129. package/src/prove/smt/format.ts +154 -0
  130. package/src/prove/smt/instances.ts +182 -0
  131. package/src/prove/smt/rewrite.ts +773 -0
  132. package/src/prove/smt/simplify.ts +57 -0
  133. package/src/prove/smt/solver/act-cache.ts +265 -0
  134. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  135. package/src/prove/smt/solver/array.ts +22 -0
  136. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  137. package/src/prove/smt/solver/ast-lt.ts +157 -0
  138. package/src/prove/smt/solver/ast-util.ts +147 -0
  139. package/src/prove/smt/solver/ast.ts +1315 -0
  140. package/src/prove/smt/solver/auf-solver.ts +572 -0
  141. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  142. package/src/prove/smt/solver/cg-table.ts +175 -0
  143. package/src/prove/smt/solver/clause.ts +276 -0
  144. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  145. package/src/prove/smt/solver/context.ts +1292 -0
  146. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  147. package/src/prove/smt/solver/der.ts +224 -0
  148. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  149. package/src/prove/smt/solver/e-matching.ts +659 -0
  150. package/src/prove/smt/solver/enode.ts +259 -0
  151. package/src/prove/smt/solver/expr-ref.ts +21 -0
  152. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  153. package/src/prove/smt/solver/fingerprints.ts +92 -0
  154. package/src/prove/smt/solver/flat-literals.ts +51 -0
  155. package/src/prove/smt/solver/goal.ts +138 -0
  156. package/src/prove/smt/solver/hash.ts +173 -0
  157. package/src/prove/smt/solver/hashtable.ts +166 -0
  158. package/src/prove/smt/solver/internalizer.ts +1381 -0
  159. package/src/prove/smt/solver/lbool.ts +5 -0
  160. package/src/prove/smt/solver/literal.ts +24 -0
  161. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  162. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  163. package/src/prove/smt/solver/lp/containers.ts +296 -0
  164. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  165. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  166. package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
  167. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  168. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  169. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  170. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  171. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  172. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  173. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  174. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  175. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  176. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  177. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  178. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  179. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  180. package/src/prove/smt/solver/lp/nex.ts +120 -0
  181. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  182. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  183. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  184. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  185. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  186. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  187. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  188. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  189. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  190. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  191. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  192. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  193. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  194. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  195. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  196. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  197. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  198. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  199. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  200. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  201. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  202. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  203. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  204. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  205. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  206. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  207. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  208. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  209. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  210. package/src/prove/smt/solver/model-checker.ts +347 -0
  211. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  212. package/src/prove/smt/solver/model-finder.ts +155 -0
  213. package/src/prove/smt/solver/model-generator.ts +97 -0
  214. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  215. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  216. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  217. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  218. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  219. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  220. package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
  221. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  222. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  223. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  224. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  225. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  226. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  227. package/src/prove/smt/solver/nnf.ts +469 -0
  228. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  229. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  230. package/src/prove/smt/solver/propagate-values.ts +83 -0
  231. package/src/prove/smt/solver/proto-model.ts +551 -0
  232. package/src/prove/smt/solver/pull-quant.ts +139 -0
  233. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  234. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  235. package/src/prove/smt/solver/qe-lite.ts +381 -0
  236. package/src/prove/smt/solver/qi-queue.ts +362 -0
  237. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  238. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  239. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  240. package/src/prove/smt/solver/random-gen.ts +10 -0
  241. package/src/prove/smt/solver/rational.ts +165 -0
  242. package/src/prove/smt/solver/ref-vector.ts +62 -0
  243. package/src/prove/smt/solver/relevancy.ts +247 -0
  244. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  245. package/src/prove/smt/solver/rewriter.ts +843 -0
  246. package/src/prove/smt/solver/rlimit.ts +79 -0
  247. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  248. package/src/prove/smt/solver/solver.ts +71 -0
  249. package/src/prove/smt/solver/sort.ts +35 -0
  250. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  251. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  252. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  253. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  254. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  255. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  256. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  257. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  258. package/src/prove/smt/solver/theory-lra.ts +56 -0
  259. package/src/prove/smt/solver/var-subst.ts +258 -0
  260. package/src/prove/smt/solver/z3-license.txt +10 -0
  261. package/src/prove/smt/table.ts +170 -0
  262. package/src/prove/tlapm/tlapm.ts +96 -0
  263. package/src/prove/tlaps-module.ts +510 -0
  264. package/src/prove/verdict.ts +18 -0
  265. package/src/prove/zenon/LICENSE +32 -0
  266. package/src/prove/zenon/check/check.ts +105 -0
  267. package/src/prove/zenon/check/definitions.ts +144 -0
  268. package/src/prove/zenon/check/equality.ts +182 -0
  269. package/src/prove/zenon/check/functions.ts +62 -0
  270. package/src/prove/zenon/check/keys.ts +125 -0
  271. package/src/prove/zenon/check/propositional.ts +104 -0
  272. package/src/prove/zenon/check/records.ts +188 -0
  273. package/src/prove/zenon/check/relations.ts +121 -0
  274. package/src/prove/zenon/check/rewrites.ts +224 -0
  275. package/src/prove/zenon/check/sets.ts +302 -0
  276. package/src/prove/zenon/check/terms.ts +127 -0
  277. package/src/prove/zenon/check/tla.ts +126 -0
  278. package/src/prove/zenon/decide.ts +113 -0
  279. package/src/prove/zenon/encode.ts +437 -0
  280. package/src/prove/zenon/eqrel.ts +300 -0
  281. package/src/prove/zenon/equality-rules.ts +435 -0
  282. package/src/prove/zenon/expr.ts +551 -0
  283. package/src/prove/zenon/index-table.ts +350 -0
  284. package/src/prove/zenon/isar-case.ts +513 -0
  285. package/src/prove/zenon/isar.ts +1249 -0
  286. package/src/prove/zenon/limits.ts +15 -0
  287. package/src/prove/zenon/llproof.ts +173 -0
  288. package/src/prove/zenon/mltoll.ts +1566 -0
  289. package/src/prove/zenon/node.ts +297 -0
  290. package/src/prove/zenon/ocaml.ts +169 -0
  291. package/src/prove/zenon/parse.ts +247 -0
  292. package/src/prove/zenon/phrase.ts +191 -0
  293. package/src/prove/zenon/proof.ts +198 -0
  294. package/src/prove/zenon/propositional-rules.ts +387 -0
  295. package/src/prove/zenon/rules.ts +94 -0
  296. package/src/prove/zenon/search.ts +288 -0
  297. package/src/prove/zenon/tla/functions.ts +151 -0
  298. package/src/prove/zenon/tla/llproof.ts +480 -0
  299. package/src/prove/zenon/tla/records.ts +225 -0
  300. package/src/prove/zenon/tla/rewrites.ts +447 -0
  301. package/src/prove/zenon/tla/sets.ts +304 -0
  302. package/src/prove/zenon/tla/terms.ts +181 -0
  303. package/src/prove/zenon/tla/tla.ts +506 -0
  304. package/src/run-cli.ts +334 -75
  305. package/src/standard-modules.ts +5 -2
  306. package/src/successors.ts +24 -5
  307. package/src/tlapm-cache.ts +236 -0
  308. package/src/tlc-random.ts +55 -32
  309. package/src/tlc-version.ts +8 -7
  310. package/src/values.ts +97 -47
  311. package/src/worker.ts +65 -0
  312. package/dist/parallel.cjs +0 -12
  313. package/dist/parallel.js +0 -12
package/dist/prove.cjs ADDED
@@ -0,0 +1,996 @@
1
+ /**
2
+ * @license tla-ts
3
+ *
4
+ * Copyright (c) Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const e=require("./worker.cjs"),t=require("./transfer.cjs"),n=require("./deciders.cjs"),r=async n=>{let r=typeof n.config==`string`?t.Q(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=()=>{let e={count:a.count};return t.l({...n,config:r,onPrint:t=>e.count-->0?void 0:i(t),onProgress:e=>{s.has(o(e))||n.onProgress?.(e)}})},u=n.workers??1;if(u<2||typeof SharedArrayBuffer!=`function`||n.dump!==void 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},p=/* @__PURE__ */ new Map,m=e=>{let t=n.loadClass?.(e);return p.set(e,t),t};t.X(t.x(n.source,r,f)),t.Z(n.version);let h=t.Y(),g=t.y(r,{source:n.source,loadModule:f,loadClass:m,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.p(g,r,c);let _=g.environment,v=t.u(r,_,()=>t.S(n.source,f),c);if(t.d(g.assumptions,_)||!v||v.spec.init===void 0||v.spec.next===void 0||v.properties.liveness.length>0||t.P(_))return l();let y=t.K(),b={fingerprints:t.i()},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=[],ee=()=>({status:`success`,violation:void 0,failure:void 0,...C,fingerprintDistance:t.g(C.distinctStates,C.generatedStates,()=>{let e=new BigInt64Array(C.distinctStates);return w.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),te=e=>{let n=[];for(let r of t.F(e,_,v.spec.scope))if(t.f(C.generatedStates,c),y(r),C.generatedStates++,t.c(v.getFingerprintState(r),x),t.s(b.fingerprints)&&(b.fingerprints=t.a(b.fingerprints)),t.o(b.fingerprints,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(!te(v.spec.init))return l()}catch(t){if(!(t instanceof e.g))throw t;return l()}if(t.Y()!==h)return l();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 ee();let ne=[],re={count:u,resolve:e=>{}},T=e=>{ne.push(e),(e.type===`abort`||ne.length===re.count)&&re.resolve(ne.splice(0))},ie=e=>new Promise(t=>{re.count=e,re.resolve=t}),ae=ie(u),E=new Int32Array(new SharedArrayBuffer(u*4)),oe=new Int32Array(new SharedArrayBuffer(u*4)),D=await Promise.all(Array.from({length:u},()=>e.r(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href),e=>T(e),()=>T({type:`abort`})))),O=()=>D.forEach(e=>e.terminate()),k=/* @__PURE__ */ new Map,se=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=k.get(n)??new MessageChannel;return k.set(n,r),e<t?r.port1:r.port2};D.forEach((e,t)=>{let i=Array.from({length:u},(e,n)=>n===t?void 0:se(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,isTraceRecorded:n.isTraceRecorded,isWarningEnabled:n.isWarningEnabled,version:n.version,fingerprints:b.fingerprints,requests:E,remaining:oe};e.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let ce=e=>e.some(e=>e.type===`abort`),le=e=>D.forEach(t=>t.postMessage(e)),A=async e=>{let n=e.filter(e=>e.type===`paused`).length;if(n===0||ce(e))return e;b.fingerprints=t.a(b.fingerprints);let r=ie(n);return le({type:`resize`,fingerprints:b.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await A(await r)]};if(ce(await ae))return O(),l();for(let e=1;;e++){let t=ie(u);E.forEach((e,t)=>Atomics.store(E,t,0)),le({type:`level`,level:e});let n=await A(await t);if(ce(n))return O(),l();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(C.generatedStates+=r.reduce((e,t)=>e+t.generated,0),C.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>C.outDegrees[t]+=e),w.push(e.fingerprints)}),i===0)return O(),ee();C.depth++}},i=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}`},a=e=>`File ${JSON.stringify(e.file)}, ${i(e)}`,o=e=>`${e?a(e):`<unknown location>`}:\n`,s=(e,t)=>({text:`${o(e)}Error: ${t}`,channel:`stderr`}),c=e=>e?`${a(e)} :\n`:``,l=e=>({kind:`Shift`,amount:e}),u=(e,t)=>({kind:`Cons`,expression:e,rest:t}),d=(e,t)=>e.reduce((e,t)=>u(t,e),t),f=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},p=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},m=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},h=(e,t,n)=>p({kind:`Apply`,operator:p({kind:`Internal`,builtin:e},n),args:t},n),g=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},_=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),v=(e,t)=>t.reduce(_,e),y=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},b=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(m(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},x=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},S=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},C=(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()}}},w=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),ee=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),te=(e,t,n)=>{switch(e.kind){case`Shift`:return p({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?p(T(e.expression),n):te(e.rest,t-1,n);case`Compose`:return D(e.outer,te(e.inner,t,n));case`Bump`:return t<=e.amount?p({kind:`Ix`,index:t},n):D(l(e.amount),te(e.rest,t-e.amount,n))}},ne=(e,t)=>t.map(t=>D(e,t)),re=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e.C(`Arity mismatch`);return T(D(d(n,l(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?T(t):{kind:`Apply`,operator:t,args:n}},T=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},ie=(e,t)=>[f(t.length,e),fe(t,t=>D(e,t))],ae=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return he(t,t=>D(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:D(n,e.expression)}))}}}}},E=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:D(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ae(e,t.definition)};case`Fact`:return{...t,expression:D(e,t.expression)}}},oe=(e,t)=>{let[n,r]=S(e,t.context,(e,t)=>[f(1,e),E(e,t)]);return{context:r,active:D(n,t.active)}},D=(e,t)=>{let n=t=>D(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return te(e,t.index,t);case`Apply`:return p(re(n(t.operator),ne(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>pe(e,n))};case`Lambda`:return{...t,body:D(f(t.params.length,e),t.body)};case`Let`:{let[n,r]=S(e,t.definitions,(e,t)=>[f(1,e),ae(e,t)]);return{...t,definitions:r,body:D(n,t.body)}}case`Sequent`:return{...t,sequent:oe(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:ne(e,t.items)};case`Quant`:case`Fcn`:{let[n,r]=ie(e,t.bounds);return{...t,bounds:r,body:D(n,t.body)}}case`Tquant`:return{...t,body:D(f(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:D(f(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:D(f(1,e),t.body)};case`SetOf`:{let[n,r]=ie(e,t.bounds);return{...t,bounds:r,element:D(n,t.element)}}case`SetEnum`:case`Tuple`:return{...t,elements:ne(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`FcnApp`:return{...t,function:n(t.function),args:ne(e,t.args)};case`Product`:return{...t,factors:ne(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:me(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)}}},O=(e,t)=>e===0?t:D(l(e),t),k=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),se=(e,t)=>e&&t?M(e,t):!e&&!t,ce=(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||!M(t,n))return!1}return!0},le=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&M(e.domain.expression,t.domain.expression)),A=(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`&&k(e.args,t.args,M);case`Label`:return t.kind===`Label`&&e.label===t.label&&k(e.args,t.args,M);default:return!0}},j=(e,t)=>{if((e.kind===`Operator`||e.kind===`Bpragma`)&&t.kind===e.kind)return M(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 k(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&ce(n,r)}return!1},ue=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level===t.level&&e.shape===t.shape&&se(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?j(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&M(e.expression,t.expression),de=(e,t)=>k(e.context,t.context,ue)&&M(e.active,t.active),M=(e,t)=>{if(e.kind===`Parens`)return M(e.expression,t);if(t.kind===`Parens`)return M(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&&M(e.body,t.body);case`Apply`:return t.kind===`Apply`&&M(e.operator,t.operator)&&k(e.args,t.args,M);case`Sequent`:return t.kind===`Sequent`&&de(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&M(e.expression,t.expression)&&k(e.selectors,t.selectors,A);case`With`:return t.kind===`With`&&M(e.expression,t.expression);case`Let`:return t.kind===`Let`&&k(e.definitions,t.definitions,j)&&M(e.body,t.body);case`If`:return t.kind===`If`&&M(e.condition,t.condition)&&M(e.consequent,t.consequent)&&M(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&k(e.items,t.items,M);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&k(e.bounds,t.bounds,le)&&M(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&k(e.names,t.names,(e,t)=>e===t)&&M(e.body,t.body);case`Choose`:return t.kind===`Choose`&&se(e.domain,t.domain)&&M(e.body,t.body);case`SetSt`:return t.kind===`SetSt`&&M(e.domain,t.domain)&&M(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&M(e.element,t.element)&&k(e.bounds,t.bounds,le);case`SetEnum`:case`Tuple`:return t.kind===e.kind&&k(e.elements,t.elements,M);case`Arrow`:return t.kind===`Arrow`&&M(e.domain,t.domain)&&M(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&k(e.bounds,t.bounds,le)&&M(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&k([e.function,...e.args],[t.function,...t.args],M);case`Product`:return t.kind===`Product`&&k(e.factors,t.factors,M);case`Rect`:case`Record`:return t.kind===e.kind&&ce(e.fields,t.fields);case`Except`:return t.kind===`Except`&&M(e.function,t.function)&&k(e.specs,t.specs,(e,t)=>k(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&M(e.expression,t.expression))&&M(e.value,t.value));case`Dot`:return t.kind===`Dot`&&M(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&M(e.action,t.action)&&M(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&M(e.subscript,t.subscript)&&M(e.action,t.action);case`Case`:return t.kind===`Case`&&(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:M(e.arms[0].condition,t.arms[0].condition)&&M(e.arms[0].body,t.arms[0].body))&&se(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}},fe=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),pe=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,me=(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}}),he=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,ge=(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:he(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,w(t.name,t.level)),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=w(t.name,`Unknown`,t.shape);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=S(e,t.sequent.context,(e,t)=>{let a=ge(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]=S(e,t.definitions,(e,t)=>{let i=he(t,t=>n(e,t));return[r(e,{kind:`Defn`,definition:i,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=fe(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=fe(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?ee(t.name,i):w(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=ee(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>pe(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=me(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}}}},_e=(e,t)=>N(void 0,e,(e,n)=>t(n),()=>void 0,`all`),ve=e=>{let t=[];return _e(e,e=>(t.push(e),e)),t},ye={kind:`Opaque`,name:`$Bad`},be=e=>e.kind===`Opaque`&&e.name===ye.name,xe=e=>{let t=e.kind===`Parens`?xe(e.expression):_e(e,xe);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},Se=e=>e.kind===`Let`?p({kind:`Let`,definitions:e.definitions,body:Se(e.body)},e.body):e.kind===`Parens`?Se(e.expression):_e(e,Se),Ce=e=>e.kind===`Ix`?e.index<=0:ve(e).some(Ce),we=(e,t,n)=>{let r=(e,r=n)=>we(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(e=>w(e.name,e.level))]);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(e=>w(e.name,`Unknown`,e.shape))]);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,w(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 ve(e)){let e=r(t);if(e)return e}return}},Te=(e,t)=>d(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),l(e+t)),Ee=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),De=(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(s(n.location,a)),new e.C(a,{failure:`Expr.Deref.deref_inst`})}let i=n.kind===`SetOf`?n.element:n.body;return D(d(r,l(0)),i)}case`Tquant`:return De(t,p({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 De(t,p({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(s(n.location,i)),new e.C(i,{failure:`Expr.Deref.deref_inst`})}return D(d(r,l(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw t(s(n.location,r)),new e.C(r,{failure:`Expr.Deref.deref_inst`})}}},Oe=(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(s(r.location,n)),new e.C(n,{failure:`Expr.Deref.deref_at`})}}})(),a=D(Te(n,i.length),r);return[i,De(t,a,Ee(i.length))]},ke=(t,n,r,i,a)=>{let o=n=>{if(!(r<=n))throw t(s(i.location,a)),new e.C(a,{failure:`Expr.Deref.deref_num`})},c=e=>(o(e.length),e[r-1]);if(n.kind===`With`)return ke(t,n.expression,r,i,a);let u=(()=>{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(s(n.location,r)),new e.C(r,{failure:`Expr.Deref.deref_num`})}let c=D(l(-(r-1)),a?a.expression:i.active);if(Ce(c))throw t(s(n.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
10
+ Tlapm does not handle yet such subexpression namings.`)),new e.C(`Subexpression of ASSUME/PROVE uses identifiers declared therein
11
+
12
+ Tlapm does not handle yet such subexpression namings.`,{failure:`Expr.Deref.deref_num`});return c}case`Apply`:return c(n.args);case`If`:return c([n.condition,n.consequent,n.alternative]);case`List`:return c(n.items);case`SetEnum`:case`Tuple`:return c(n.elements);case`Product`:return c(n.factors);case`Let`:return o(1),n.body;case`Quant`:case`SetOf`:case`Fcn`:return c(n.bounds.flatMap(e=>e.domain.kind===`Domain`?[e.domain.expression]:[]));case`Choose`:case`SetSt`:if(!n.domain)break;return c([n.domain]);case`Arrow`:return c([n.domain,n.range]);case`FcnApp`:{let e=n.args.length===1?n.args[0]:p({kind:`Tuple`,elements:n.args},n);return c([n.function,e])}case`Rect`:case`Record`:return c(n.fields.map(e=>e.value));case`Dot`:return c([n.expression,p({kind:`String`,value:n.field},n)]);case`Except`:return c([n.function,...n.specs.map(e=>e.value)]);case`Sub`:case`Tsub`:return c([n.action,n.subscript]);case`Fair`:return c([n.subscript,n.action]);case`Case`:return c([...n.arms.map(e=>p({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...n.other?[p({kind:`Tuple`,elements:[ye,n.other]},n.other)]:[]])}let i=`Expression has no subexpressions`;throw t(s(n.location,i)),new e.C(i,{failure:`Expr.Deref.deref_num`})})();if(be(u)){let i=`Cannot resolve subexpression reference !${r}`;throw t(s(n.location,i)),new e.C(i,{failure:`Expr.Deref.deref_num`})}return[n.kind===`Let`?n.definitions:[],u]},Ae=(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])},je=(t,n,r,i,a)=>{let o=we(r,i,[]);if(!o)return t(s(r.location,`Could not find label ${i}`)),{params:[],definitions:[],expression:ye};let c=o.indices;if(c.length!==a.length&&a.length>0){let n=c.length===1?``:`s`,r=`Expected ${c.length} argument${n} for labelled reference !${i}, but found ${a.length}`;throw t(s(o.expression.location,r)),new e.C(r,{failure:`Expr.Deref.deref_lsub`})}let d=a.length===0?c.map(e=>({name:e.name,shape:0})):[],f=a.length===0?Ee(c.length):a,m=o.context.reduceRight((e,t)=>t.kind===`Defn`?p({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?p({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):D(l(-1),e),o.expression),h=D(Te(n,d.length),m),g=[],_=h,v=Ae(c.map(e=>e.index),f);for(;v.length>0;)if(_.kind===`Let`&&_.definitions.length===1)g.push(_.definitions[0]),_=_.body,v=v.map(e=>D(l(1),e));else{if(_.kind!==`Quant`||_.bounds.length!==1)throw new e.j(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);_=D(u(v[0],l(0)),_.body),v=v.slice(1)}return{params:d,definitions:g,expression:_}},Me=(t,n,r,i,a)=>{if(r.kind!==`Let`)throw t(s(r.location,`not a LET expression`)),new e.C(`not a LET expression`,{failure:`Expr.Deref.deref_letop`});let o=r.definitions.findIndex(e=>e.kind===`Operator`&&e.name===i),c=r.definitions[o];if(!c||c.kind!==`Operator`){let n=`no definition of operator ${i}`;throw t(s(r.location,n)),new e.C(n,{failure:`Expr.Deref.deref_letop`})}let l=c.body,u=l.kind===`Lambda`?p({...l,body:p({kind:`Parens`,expression:l.body,form:{kind:`Xlabel`,label:i,indices:l.params.map((e,t)=>({name:e.name,index:l.params.length-t}))}},l.body)},l):p({kind:`Parens`,expression:l,form:{kind:`Xlabel`,label:i,indices:[]}},l);return je(t,n,p({kind:`Let`,definitions:r.definitions.slice(0,o),body:u},l),i,a)},Ne=(t,n,r,i)=>{let[a,...o]=i;if(!a){let e=r.definitions.length===0?r.expression:p({kind:`Let`,definitions:r.definitions,body:r.expression},r.expression),t=r.params.length===0?e:p({kind:`Lambda`,params:r.params,body:e},e);return{...xe(t),isAtomic:!0}}if(r.expression.isAtomic)return t(s(r.expression.location,`Expression has no subexpressions`)),ye;let c=n?r.expression:Se(r.expression),u=r.definitions.length,d=(()=>{let i=(e,n)=>{let[i,a]=ke(t,c,e,r.expression,n);return{params:[],definitions:i,expression:a,rest:o,isLabel:!1}};switch(a.kind){case`Down`:{let[r,...i]=o;if(c.kind===`Let`&&r?.kind===`Label`&&n)return{...Me(t,u,c,r.label,r.args),rest:i,isLabel:!0};if(n)return{params:[],definitions:[],expression:c,rest:o,isLabel:!1};throw new e.C(`!: is forbidden for this expression.
13
+ `,{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:De(t,c,a.args),rest:o,isLabel:!1};case`Label`:return{...c.kind===`Let`&&!n?Me(t,u,c,a.label,a.args):je(t,u,c,a.label,a.args),rest:o,isLabel:!0};case`At`:{let[e,n]=Oe(t,u,c);return{params:e,definitions:[],expression:n,rest:o,isLabel:!1}}}})();return Ne(t,d.isLabel,{params:[...r.params,...d.params],definitions:[...r.definitions,...d.definitions],expression:d.expression},d.rest.map(e=>pe(e,e=>D(l(d.definitions.length),e))))},Pe=(e,t,n)=>{if(n.length>0)return{params:[],definitions:[],expression:De(e,t,n)};if(t.kind!==`Lambda`)return{params:[],definitions:[],expression:t};let[r,i]=Oe(e,0,t);return{params:r,definitions:[],expression:i}},Fe=(t,n,r,i)=>{let a=Ne(t,!0,Pe(t,n,r),i);if(be(a)){let r=`Could not resolve subexpression reference`;throw t(s(n.location,r)),new e.C(r,{failure:`Expr.Anon: 2`})}return a},Ie=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),Le=e=>h(`UNCHANGED`,[e],e),Re=e=>t=>{let n=Re(e);return e(t,n)??_e(t,n)},ze=Re((e,t)=>e.kind===`Apply`&&Ie(e,[`Leadsto`])?h(`BoxTrue`,[h(`Implies`,[t(e.args[0]),h(`Diamond`,[t(e.args[1])],e)],e)],e):void 0),Be=Re(e=>{if(e.kind!==`Fair`)return;let t=e.action,n=e.subscript,r=h(`ENABLED`,[p({kind:`Sub`,modal:`Dia`,action:t,subscript:n},t)],t),i=e.fairness===`Weak`?`Diamond`:`BoxTrue`,a=e.fairness===`Weak`?`BoxTrue`:`Diamond`;return h(`Implies`,[h(i,[h(a,[r],t)],t),h(`BoxTrue`,[p({kind:`Tsub`,modal:`Dia`,action:t,subscript:n},t)],t)],t)}),Ve=Re((e,t)=>{if(e.kind!==`Sub`&&e.kind!==`Tsub`)return;let n=t(e.action),r=t(e.subscript),i=e.modal===`Box`?h(`Disj`,[n,Le(r)],e):h(`Conj`,[n,h(`Neg`,[Le(r)],e)],e);return e.kind===`Sub`?i:h(e.modal===`Box`?`BoxTrue`:`Diamond`,[i],e)}),He=e=>e.kind===`Tuple`?e.elements.flatMap(He):[e],Ue=Re(e=>{if(e.kind!==`Apply`||!Ie(e,[`UNCHANGED`]))return;let t=He(e.args[0]).map(e=>h(`Eq`,[h(`Prime`,[e],e),e],e));return t.length===0?p({kind:`Internal`,builtin:`TRUE`},e):t.length===1?t[0]:p({kind:`List`,bullet:`And`,items:t},e)}),We=[`Prime`,`StrongPrime`,`Leadsto`,`ENABLED`,`UNCHANGED`,`Cdot`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`],Ge=/* @__PURE__ */ new WeakMap,Ke=(e,t)=>{switch(t.kind){case`Fresh`:return t.level===`Constant`;case`Defn`:return t.definition.kind===`Operator`&&Je(e,t.definition.body);case`Fact`:return Je(e,t.expression);case`Flex`:return!1}},qe=(e,t)=>t.reduce((e,t)=>_(e,w(t,`Constant`)),e),Je=(e,t)=>{let n=t=>Je(e,t);switch(t.kind){case`Ix`:{let n=x(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=Ge.get(i);if(a!==void 0)return a;let o=Je(n?.rest,i);return Ge.set(i,o),o}case`Opaque`:case`String`:case`Num`:case`At`:return!0;case`Internal`:return!We.includes(t.builtin);case`Tquant`:case`Sub`:case`Tsub`:case`Fair`:return!1;case`Lambda`:return Je(qe(e,t.params.map(e=>e.name)),t.body);case`Sequent`:{let n=t.sequent.context.reduce((e,t)=>({scope:_(e.scope,t),isGood:e.isGood&&Ke(e.scope,t)}),{scope:e,isGood:!0});return n.isGood&&Je(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:_(e.scope,{kind:`Defn`,definition:t,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),isGood:e.isGood&&t.kind===`Operator`&&Je(e.scope,t.body)}),{scope:e,isGood:!0});return n.isGood&&Je(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))&&Je(qe(e,t.bounds.map(e=>e.name)),r)}case`Choose`:case`SetSt`:return(t.domain===void 0||n(t.domain))&&Je(qe(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))}},Ye=(e,t,n)=>{if(Je(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=>Ye(e,t,n));if(t.kind===`Sequent`){let r=t.sequent.context.reduce(_,e);return Ye(r,t.sequent.active,n)}if(t.kind!==`Apply`)return!1;let r=t.args;return Ie(t,[`BoxTrue`,`BoxFalse`])&&n||Ie(t,[`Diamond`])&&!n?!0:r.length===1&&Ie(t,[`BoxTrue`,`BoxFalse`,`Diamond`,`Prime`])?Ye(e,r[0],n):r.length===1&&Ie(t,[`Neg`])?Ye(e,r[0],!n):r.length===2&&Ie(t,[`Conj`,`Disj`])?Ye(e,r[0],n)&&Ye(e,r[1],n):r.length===2&&Ie(t,[`Implies`])?Ye(e,r[0],!n)&&Ye(e,r[1],n):r.length===2&&Ie(t,[`Equiv`])?[!0,!1].every(t=>Ye(e,r[0],n!==t)&&Ye(e,r[1],n===t)):Ye(e,t.operator,n)&&r.every(t=>Ye(e,t,n))},Xe=(e,t)=>Ye(e,ze(Be(Ve(Ue(t)))),!0)?`Always`:`Now`,Ze=(e,t)=>t===`Always`&&e.some(e=>e.kind===`Fact`&&e.time===`Now`)?`Now`:t,Qe=e=>e.kind===`Named`?`<${e.level}>${e.label}`:`<${e.level}>`,$e=e=>++e.value,et={kind:`Fact`,expression:{kind:`At`,isExcept:!1},visibility:`Visible`,time:`Always`},tt={Number:`1NUM`,Down:`1DOWN`,At:`1AT`,Instance:`1INST`,Left:`1`,Right:`1`},nt={kind:`Opaque`,name:`$badexp`},rt=(t,n,r)=>{let i,a=e=>({warnedSteps:[],scope:e}),o=e=>e.scope?.size??0,d=(e,t)=>{if(t.kind===`At`&&t.isExcept)return i?O(o(e)-i.size,i.expression):t;if(t.kind!==`Except`)return ee(e,t);let n=d(e,t.function);return t.specs.reduce((n,r)=>{let[a,s]=S(n,r.trail,(t,n)=>{if(n.kind===`Dot`)return[p({kind:`Dot`,expression:t,field:n.field},t),n];let r=d(e,n.expression);return[p({kind:`FcnApp`,function:t,args:[r]},t),{kind:`Apply`,expression:r}]}),c=i;i={expression:a,size:o(e)};let l=d(e,r.value);return i=c,p({kind:`Except`,function:n,specs:[{trail:s,value:l}]},t)},n)},f=(e,t,n)=>{let r=p({kind:`Ix`,index:e},n);return t.length===0?r:p({kind:`Apply`,operator:r,args:t},n)},m=(e,t,n,r,i)=>{if(t!==`Builtin`)return f(e,r,i);let a=O(e,n);return p(r.length===0?a:re(a,r),i)},y=(t,n,i,a)=>{let o=b(t.scope,n);if(!o){let t=`Operator "${n}" not found`;throw r(s(a.location,t)),new e.C(t,{failure:`Expr.Anon: 4`})}let c=o.depth+1,l=o.hyp;switch(l.kind){case`Defn`:{let t=l.definition;if(t.kind===`Operator`)return m(c,l.whereDefined,t.body,i,a);if(t.kind===`Recursive`)throw new e.C(`Recursive operators not supported by TLAPS`,{failure:`Expr.Anon: Recursive`});return f(c,i,a)}case`Fresh`:return f(c,i,a);case`Flex`:return p({kind:`Ix`,index:c},a);case`Fact`:throw new e.j(`File "src/expr/e_anon.ml", line 230, characters 24-36: Assertion failed`)}},C=(t,n,i,a,o,c)=>{let l=b(t.scope,n);if(!l){let[o,...l]=a;if(o?.kind===`Label`){let e=o.args.map(e=>d(t,e));return C(t,`${n}!${o.label}`,[...i,...e],l,!0,c)}let u=`Operator "${n}" not found`;throw o&&r(s(c.location,u)),new e.C(u,{failure:`Expr.Anon: ${o?tt[o.kind]:`1EMPTY`}`})}let u=l.hyp;if(u.kind!==`Defn`||u.definition.kind!==`Operator`&&u.definition.kind!==`Bpragma`)throw new e.C(`invalid subexpression reference`);let f=l.depth+1;if(a.length===0&&o)return i.length===0?p({kind:`Ix`,index:f},c):m(f,u.whereDefined,u.definition.body,i,c);let h=it(O(f,u.definition.body),c);return it(Fe(r,h,i,a),c)},ee=(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=>pe(t,t=>d(e,t))),i=n.args.map(t=>d(e,t)),o=a(e.scope);return C(o,n.operator.name,i,r,!1,t)}return d(e,{...t,expression:p({kind:`Apply`,operator:n,args:[]},n)})}case`Apply`:{if(t.operator.kind!==`Opaque`)return E(e,t);let n=t.operator.name;if(e.warnedSteps.includes(n))return r({text:`${c(t.location)}Warning: ${n} does not introduce any assumptions. It does not make sense to use it here.\n`,channel:`toolbox`}),p({kind:`Internal`,builtin:`TRUE`},t);let i=t.args.map(t=>d(e,t));return y(e,n,i,t)}case`Opaque`:return d(e,p({kind:`Apply`,operator:t,args:[]},t));case`Parens`:return t.form.kind===`Syntax`?d(e,t.expression):{...t,expression:d(e,t.expression),form:te(e,t.form)};default:return E(e,t)}},te=(t,n)=>n.kind===`Nlabel`?{kind:`Xlabel`,label:n.label,indices:n.names.map(n=>{let r=b(t.scope,n);if(!r)throw new e.C(`Identifier "${n}" in label parameters not found`);return{name:n,index:r.depth+1}})}:n,ne=(e,t)=>({warnedSteps:e.warnedSteps,scope:t}),T=(e,t)=>ne(e,_(e.scope,t)),ie=(e,t)=>t.reduce((e,t)=>T(e,w(t.name,t.level)),e),ae=(e,t)=>{let n=fe(t,t=>d(e,t));return[ie(e,n),n]},E=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:ce(e,t.sequent)[1]};if(t.kind===`Let`){let[n,r]=k(e,t.definitions);return{...t,definitions:r,body:d(n,t.body)}}return N(e,t,d,T)},oe=(e,t)=>{if(t.kind!==`Operator`)return t;let n=t.body;if(n.kind!==`Fcn`)return{...t,body:d(e,n)};let r=d(T(e,w(t.name,`Constant`)),n);if(M(D(u({kind:`Opaque`,name:`%%%`},l(1)),r),r))return{...t,body:O(-1,r)};let i=h(`Eq`,[p({kind:`Ix`,index:1},r),r],r);return{...t,body:p({kind:`Choose`,name:t.name,domain:void 0,body:i},r)}},k=(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=oe(r,t);r=T(r,{kind:`Defn`,definition:o,whereDefined:`User`,visibility:`Visible`,isLocal:!0,isConstnessUnset:!0}),a.push(o)}return[r,a]},se=(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:d(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:oe(e,t.definition)};case`Fact`:{let n=d(e,t.expression);return{...t,expression:n,time:Xe(e.scope,n)}}}})();return[T(e,n),n]},ce=(e,t)=>{let[n,r]=S(e,t.context,se);return[n,{context:r,active:d(n,t.active)}]},le=(e,t)=>({warnedSteps:[Qe(t),...e.warnedSteps],scope:e.scope}),A=(e,t,n,r)=>T(e,{kind:`Defn`,definition:{kind:`Operator`,name:Qe(t),body:n,location:r.location},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!0,isConstnessUnset:!0,location:r.location}),j=(e,t)=>ne(e,v(e.scope,Array.from({length:t},()=>et))),ue=e=>{let t=[...e.context.map((t,n)=>{let r=e.context.length-n+1;if(t.kind===`Fact`)return O(r,t.expression);if(t.kind!==`Fresh`||!t.domain)return nt;let i=h(`Mem`,[p({kind:`Ix`,index:0},t.domain),t.domain],t.domain);return O(r,i)}),O(1,e.active)];return t.length===1?t[0]:{kind:`Tuple`,elements:t}},de=e=>e.kind!==`Use`&&e.kind!==`Hide`&&e.kind!==`Define`,me=(e,t)=>({facts:t.facts.map(t=>d(e,t)),defs:t.defs.flatMap(t=>{if(t.kind===`Dx`)return[t];let n=d(e,p({kind:`Opaque`,name:t.name},t));return n.kind===`Ix`?x(e.scope,n.index-1)?.hyp.kind===`Defn`?[{kind:`Dx`,index:n.index,location:t.location}]:(r({text:`${c(t.location)}${JSON.stringify(t.name)} is not a definition and cannot be used in a DEF clause.`,channel:`toolbox`}),[]):(r({text:`${c(t.location)}Ignored unexpandable identifier ${JSON.stringify(t.name)} in BY DEF.`,channel:`stderr`}),[])})}),he=(e,t)=>{switch(t.kind){case`Steps`:{let[n,r]=S(e,t.steps,ge),i=he(t.step?le(n,t.step):n,t.qed.proof);return{...t,steps:r,qed:{...t.qed,proof:i}}}case`By`:return{...t,usable:me(e,t.usable)};default:return t}},ge=(n,r)=>{let i=r.step?.kind===`Unnamed`&&de(r)?{kind:`Named`,level:r.step.level,label:`_a${$e(t)}`,isAnonymous:!0}:r.step;if(!i)throw new e.j;let a={...r,step:i};switch(a.kind){case`Assert`:{let[,e]=ce(n,a.sequent),t=e.context.reduce(T,n),r=j(A(j(t,1),i,p(ue(e),a),a),1),o=e.context.length===0?le(r,i):r,s={...a,sequent:e,proof:he(o,a.proof)};return[j(A(n,i,p(g(e),a),a),1),s]}case`Pcase`:{let e=d(n,a.expression),t=p({kind:`Tuple`,elements:[O(2,e)]},a),r=j(A(j(n,2),i,t,a),1),o={...a,expression:e,proof:he(r,a.proof)},s=A(n,i,p({kind:`Tuple`,elements:[e]},a),a);return[j(s,1),o]}case`Suffices`:{let[,e]=ce(n,a.sequent),t=p({kind:`Tuple`,elements:[p(g(e),a)]},a),r=j(A(n,i,t,a),1),o={...a,sequent:e,proof:he(r,a.proof)},s=e.context.reduce(T,n),c=p({kind:`Tuple`,elements:[p(ue(e),a)]},a);return[j(A(j(s,1),i,c,a),1),o]}case`Have`:{let e=d(n,a.expression),t=p({kind:`Tuple`,elements:[O(2,e)]},a);return[j(A(j(n,2),i,t,a),1),{...a,expression:e}]}case`Take`:{let[e,t]=ae(n,a.bounds),r=p({kind:`Quant`,quantifier:`Forall`,bounds:t,body:nt},a);return[j(A(j(e,1),i,r,a),1),{...a,bounds:t}]}case`Witness`:{let e=a.expressions.map(e=>d(n,e)),t=p({kind:`Tuple`,elements:e},a);return[j(A(j(n,1),i,t,a),1),{...a,expressions:e}]}case`Pick`:{let[e,t]=ae(n,a.bounds),r=d(e,a.expression),o=p({kind:`Quant`,quantifier:`Exists`,bounds:t,body:r},a),s=le(j(A(j(n,1),i,o,a),1),i),c={...a,bounds:t,expression:r,proof:he(s,a.proof)},l=ie(j(n,2),t),u=O(4+t.length,o);return[j(A(j(l,2),i,u,a),1),c]}case`Use`:{let e=me(n,a.usable);return[j(n,e.facts.length),{...a,usable:e}]}case`Hide`:return[n,{...a,usable:me(n,a.usable)}];case`Define`:{let[e,t]=k(n,a.definitions);return[e,{...a,definitions:t}]}case`Forget`:return[n,a]}};return{expr:(e,t)=>d(a(e),t),defn:(e,t)=>oe(a(e),t),sequent:(e,t)=>ce(a(e),t)[1],usable:(e,t)=>me(a(e),t),proof:(e,t)=>he(a(e),t)}},it=(e,t)=>t.location?{...e,location:t.location}:e,at=1000000010,ot=new TextEncoder,st=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return ot.encode(e).length;return e.length},ct=()=>({leftTotal:-1,element:{size:-1,token:{kind:`Text`,text:``},length:0}}),lt=e=>{let t={size:-1,token:{kind:`Begin`,indent:0,box:`hov`},length:0};return{queue:[t],queueStart:0,scanStack:[ct(),{leftTotal:1,element:t}],formatStack:[],margin:78,maxIndent:e,spaceLeft:78,currentIndent:0,isNewLine:!0,leftTotal:1,rightTotal:1,depth:1,output:[]}},ut=(e,t)=>{e.rightTotal+=t.length,e.queue.push(t)},dt=(e,t,n)=>{e.output.push(`
14
+ `),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))},ft=(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`&&dt(e,0,t.width):e.output.push(`
15
+ `)},mt=(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?dt(e,0,t.width):e.output.push(`
16
+ `);return}case`Break`:{let r=e.formatStack.at(-1);if(!r)return;let i=r.width;switch(r.box){case`hov`:t>e.spaceLeft?dt(e,n.offset,i):ft(e,n.width);return;case`b`:e.isNewLine?ft(e,n.width):t>e.spaceLeft||e.currentIndent>e.margin-i+n.offset?dt(e,n.offset,i):ft(e,n.width);return;case`hv`:case`v`:dt(e,n.offset,i);return;case`fits`:case`h`:ft(e,n.width);return}}}},ht=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++,mt(e,n?t.size:at,t.token),e.leftTotal+=t.length}e.queue.length=0,e.queueStart=0},gt=(e,t)=>{ut(e,t),ht(e)},_t=(e,t)=>{let n=e.scanStack.at(-1);n&&(n.leftTotal<e.leftTotal?e.scanStack=[ct()]:n.element.token.kind===(t?`Break`:`Begin`)&&(n.element.size=e.rightTotal+n.element.size,e.scanStack.pop()))},vt=(e,t,n)=>{ut(e,n),t&&_t(e,!0),e.scanStack.push({leftTotal:e.rightTotal,element:n})},yt=(e,t,n)=>{e.depth++,vt(e,!1,{size:-e.rightTotal,token:{kind:`Begin`,indent:n,box:t},length:0})},bt=e=>{e.depth<=1||(ut(e,{size:0,token:{kind:`End`},length:0}),_t(e,!0),_t(e,!1),e.depth--)},xt=(e,t,n)=>gt(e,{size:t,token:{kind:`Text`,text:n},length:t}),St=(e,t,n)=>vt(e,!0,{size:-e.rightTotal,token:{kind:`Break`,width:t,offset:n},length:t}),Ct=e=>gt(e,{size:0,token:{kind:`Newline`},length:0}),wt=e=>{for(;e.depth>1;)bt(e);return e.rightTotal=at,ht(e),e.output.join(``)},Tt=e=>{wt(e);let t=[...e.output,`
17
+ `];Object.assign(e,lt(e.maxIndent)),e.output=t},Et={h:`h`,v:`v`,hv:`hv`,hov:`hov`,b:`b`},Dt=e=>({kind:`Text`,text:e,size:st(e)}),P=e=>e===``?[]:[Dt(e)],Ot={kind:`Break`,width:1,offset:0},kt={kind:`Break`,width:0,offset:0},At=e=>{let t=e.search(/\d|$/);return{kind:`Open`,box:Et[e.slice(0,t)],indent:Number(e.slice(t)||0)}},F=(e,...t)=>{let n=[],r=0,i=``,a=()=>{i!==``&&(n.push(Dt(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(Dt(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(At(e.slice(o+3,t))),o=t;break}case`]`:n.push({kind:`Close`}),o++;break;case` `:n.push(Ot),o++;break;case`,`:n.push(kt),o++;break;case`
18
+ `: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},I=(e,t,n=[Dt(`,`),Ot])=>e.flatMap((e,r)=>r===0?[t(e)]:[n,t(e)]),jt=(e,t)=>{for(let n of t)if(Array.isArray(n))jt(e,n);else switch(n.kind){case`Open`:yt(e,n.box,n.indent);break;case`Close`:bt(e);break;case`Text`:xt(e,n.size,n.text);break;case`Break`:St(e,n.width,n.offset);break;case`Newline`:Ct(e);break;case`Flush`:Tt(e)}},Mt=(e,t=68)=>{let n=lt(t);return jt(n,e),wt(n)},Nt=e=>e.salt===0?e.rep:`${e.rep}_${e.salt}`,Pt=()=>({stack:[],idents:/* @__PURE__ */ new Map,defined:/* @__PURE__ */ new Map}),Ft=(e,t)=>{let n=e.stack[e.stack.length-t];return n&&Nt(n)},It=(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(Nt(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=Nt(r);return e.defined.set(a,(e.defined.get(a)??0)+1),a},Lt=(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=Nt(t),r=(e.defined.get(n)??1)-1;r===0?e.defined.delete(n):e.defined.set(n,r)}},Rt=(e,t,n)=>{let r=n(t.map(t=>It(e,t)));return Lt(e,t.length),r},zt=[[`=>`,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`,[]]],Bt=/* @__PURE__ */ new Map;for(let[e,t,n,r,i]of zt){let a={name:e,low:t,high:n,fixity:r};for(let t of[e,...i])Bt.set(t,a)}const Vt=e=>({name:e,low:-1,high:-1,fixity:`Nonfix`}),Ht=e=>Bt.get(e)??Vt(e),Ut={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:`@@`},Wt=e=>{if(e===`Divides`)return{name:`?|`,low:10,high:11,fixity:`InfixNon`};if(e===`Uminus`)return{...Ht(`-.`),name:`-`};let t=Ut[e];return t?Ht(t):Vt(e)},Gt=(e,t)=>t.kind===`Atm`||t.kind===`Op`&&e<t.low,Kt=e=>[F(`(`),e,F(`)`)],qt=(e,t)=>t?Jt(e):Kt(Jt(e)),Jt=e=>{if(e.kind!==`Op`)return e.doc;let t=e.skeleton,n=t=>Gt(e.high,t);switch(t.kind){case`Prefix`:case`Postfix`:{let r=t.operand,i=qt(r,n(r)||r.kind===`Op`&&r.skeleton.kind===t.kind),a=t.kind===`Prefix`?[e.doc,i]:[i,e.doc];return[F(`@[<h>`),...a,F(`@]`)]}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[F(`@[<b0>`),qt(r,a),e.doc,qt(i,o),F(`@]`)]}}},L=e=>({kind:`Atm`,doc:e}),Yt=e=>({kind:`Big`,doc:e}),Xt=e=>e.kind===`Lambda`?Xt(e.body):e.kind===`Sequent`?Xt(e.sequent.active):e.kind===`With`,Zt=e=>{if(e.kind===`Defn`){let t=e.definition,n=t.kind===`Operator`&&Xt(t.body);return e.visibility===`Hidden`||n||e.whereDefined!==`User`}return e.kind===`Fact`?e.visibility===`Hidden`||Xt(e.expression):!1},Qt=e=>e===0?[]:F(`@[<hov1>(%a)@]`,I(Array.from({length:e},()=>`_`),P)),$t=e=>F(`%s%a`,e.name,Qt(e.shape)),en={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`UNKNOWN`},tn=(t=[])=>{let n=Pt(),r=e=>Jt(u(e)),i=(e,t)=>Rt(n,e.map(e=>e.name),()=>F(`@[<b2>LAMBDA @[<hv0>%a@] :@ %a@]`,I(e,$t),r(t))),a=(e,t)=>{let i=e.map(e=>e.domain.kind===`Domain`?r(e.domain.expression):void 0);return Rt(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(I(r,t=>{let n=I(t.names,P),r=e[t.index].domain;return r.kind===`NoDomain`?n:r.kind===`Ditto`?F(`@[<hov0>%a@ \\in ??????@]`,n):F(`@[<hov0>%a@ \\in %a@]`,n,i[t.index]??[])}))})},o=e=>{switch(e.kind){case`Down`:return F(`:`);case`Left`:return F(`<<`);case`Right`:return F(`>>`);case`At`:return P(`@`);case`Number`:return P(String(e.value));case`Instance`:return F(`@[<b1>(%a)@]`,I(e.args,r));case`Label`:return e.args.length===0?P(e.label):F(`@[<b2>%s@,@[<b1>(%a)@]@]`,e.label,I(e.args,r))}},s=e=>e.length===0?[]:[F(`!`),I(e,o,F(`!`))],c=e=>{if(e<0)return`#$$${Math.abs(e)}`;if(e===0)return`#$0`;if(e<=n.stack.length)return Ft(n,e);let r=t[t.length-(e-n.stack.length)];return r?m(r)??`??? FACT ???`:`#$${e}`},l=(t,n)=>{if(t.kind===`Lambda`)return{kind:`Op`,name:` `,doc:F(`@ `),low:20,high:20,skeleton:{kind:`Infix`,assoc:`Left`,left:Yt(i(t.params,t.body)),right:L(F(`(%a)`,I(n,r)))}};if(t.kind===`Bang`)return n.length===0?u(t):L(F(`@[<b2>%a@[<b1>(%a)@]@]`,r(t),I(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 L(F(`@[<h>@<1>%s%a@<1>%s@]`,`<[`,r(n[0]),`]>`))}let a=(()=>{switch(t.kind){case`Ix`:return Ht(c(t.index));case`Opaque`:{let e=Ht(t.name);return{...e,name:`?${e.name}`}}case`Internal`:return Wt(t.builtin);default:throw new e.C(`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 L(P(a.name));if(a.fixity===`Nonfix`)return L(F(`@[<b2>%s@[<b1>(%a)@]@]`,a.name,I(n,r)));if(a.fixity===`Prefix`&&n.length===1)return o(/[A-Za-z]$/.test(a.name)?F(`%s@ `,a.name):P(a.name),{kind:`Prefix`,operand:u(n[0])});if(a.fixity===`Postfix`&&n.length===1)return o(P(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===`..`?P(a.name):F(`@ %s `,a.name),{kind:`Infix`,assoc:e,left:u(n[0]),right:u(n[1])})}throw new e.C(`Arity mismatch for operator ${a.name}`)},u=t=>{switch(t.kind){case`Ix`:case`Opaque`:case`Internal`:return l(t,[]);case`Lambda`:return Yt(i(t.params,t.body));case`Bang`:return L([r(t.expression),s(t.selectors)]);case`Apply`:return l(t.operator,t.args);case`Sequent`:return Yt(p(t.sequent));case`With`:return u(t.expression);case`If`:return Yt(F(`@[<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 L(F(`TRUE`));if(t.bullet===`Refs`&&t.items.length===1)return u(t.items[0]);let e=t.bullet===`Or`?`\\/`:`/\\`;return Yt(F(`@[<v0>%a@]`,I(t.items,t=>F(`@[<h>%s %a@]`,e,r(t)),F(`@,`))))}case`Let`:{let e=I(t.definitions,d,F(`@,`)),i=r(t.body);return Lt(n,t.definitions.length),Yt([F(`@[<hv0>LET @[<v0>`),e,F(`@]@
19
+ IN %a@]`,i)])}case`Quant`:return a(t.bounds,e=>Yt(F(`@[<b3>%s @[<b0>%a@] :@ %a@]`,t.quantifier===`Forall`?`\\A`:`\\E`,e,r(t.body))));case`Tquant`:return Rt(n,t.names,e=>Yt(F(`@[<b4>%s @[<b0>%a@] : %a@]`,t.quantifier===`Forall`?`\\AA`:`\\EE`,I(e,P),r(t.body))));case`Choose`:{let e=t.domain&&r(t.domain);return Rt(n,[t.name],([n])=>Yt(e?F(`@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]`,n,e,r(t.body)):F(`@[<b2>CHOOSE %s :@ %a@]`,n,r(t.body))))}case`SetSt`:{let e=r(t.domain);return Rt(n,[t.name],([n])=>L(F(`@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]`,n,e,r(t.body))))}case`SetOf`:return a(t.bounds,e=>L(F(`@[<b3>{%a :@ %a}@]`,r(t.element),e)));case`SetEnum`:return L(F(`@[<h>{@[<b0>%a@]}@]`,I(t.elements,r)));case`Arrow`:return L(F(`@[<b3>[%a ->@ %a]@]`,r(t.domain),r(t.range)));case`Fcn`:return a(t.bounds,e=>L(F(`@[<b3>[%a |->@ %a]@]`,e,r(t.body))));case`FcnApp`:{let e=u(t.function),n=e.kind===`Atm`;return L(F(`@[<h>%s%a%s@[<b1>[%a]@]@]`,n?``:`(`,Jt(e),n?``:`)`,I(t.args,r)))}case`Product`:if(t.factors.length===1)return u(t.factors[0]);if(t.factors.length===0)throw new e.C(`Expr.Fmt.fmt_expr: PRODUCT []`);return{kind:`Op`,name:`\\X`,doc:F(`@ \\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 L(F(`@[<b2><<%a>>@]`,I(t.elements,r)));case`Rect`:case`Record`:{let e=t.kind===`Rect`?`:`:`|->`;return L(F(`@[<b1>[%a]@]`,I(t.fields,t=>F(`@[<h>%s ${e} %a@]`,t.name,r(t.value)))))}case`Except`:return L(F(`@[<b3>[%a EXCEPT@ @[<v0>%a@]]@]`,r(t.function),I(t.specs,e=>F(`!@[<h>%a = %a@]`,e.trail.map(e=>e.kind===`Dot`?F(`.%s`,e.field):F(`[%a]`,r(e.expression))),r(e.value)))));case`Dot`:return{kind:`Op`,name:`.`,doc:F(`.`),low:16,high:16,skeleton:{kind:`Infix`,assoc:`Left`,left:u(t.expression),right:L(P(t.field))}};case`Sub`:case`Tsub`:{let e=t.modal===`Box`,n=t.kind===`Sub`?e?`[`:`<<`:e?`[][`:`<><<`;return L(F(`@[<h>%s@[<b2>%a@]%s%a@]`,n,r(t.action),e?`]_`:`>>_`,r(t.subscript)))}case`Fair`:return Yt(F(`@[<h>%s_%a (%a)@]`,t.fairness===`Weak`?`WF`:`SF`,Kt(r(t.subscript)),r(t.action)));case`Case`:return Yt(F(`@[<v2>CASE %a%a@]`,I(t.arms,e=>F(`@[<b2>%a ->@ %a@]`,r(e.condition),r(e.body)),F(`@,[] `)),t.other?F(`@,[] @[<b2>OTHER ->@ %a@]`,r(t.other)):[]));case`String`:return L(F(`"%s"`,t.value));case`Num`:return L(P(t.fraction===``?t.integer:`${t.integer}.${t.fraction}`));case`At`:return L(P(`@`));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 L(F(t,e.label,Jt(i)))}let a=I(r,P),o=i.kind===`Atm`?`%s(%a)::%a`:i.kind===`Big`?`%s(%a)::(%a)`:`(%s(%a):: %a)`;return L(F(o,e.label,a,Jt(i)))}}},d=e=>{switch(e.kind){case`Operator`:case`Bpragma`:{let t=e.body;if(t.kind===`Lambda`){let i=Rt(n,t.params.map(e=>e.name),()=>r(t.body)),a=It(n,e.name);return F(`@[<b2>%s@[<b1>(%a)@] ==@ %a@]`,a,I(t.params,$t),i)}let i=r(t);return F(`@[<b2>%s ==@ %a@]`,It(n,e.name),i)}case`Instance`:{let t=e.instance,i=Rt(n,t.args,e=>({doc:F(`@[<b2>INSTANCE %s%a@]`,t.module,t.substitutions.length===0?[]:F(`@ WITH@ %a`,I(t.substitutions,e=>F(`@[<b2>%s <- %a@]`,e.name,r(e.expression))))),args:e})),a=It(n,e.name),o=t.args.length===0?P(a):F(`%s (@[<b0>%a@])`,a,I(i.args,P));return F(`@[<b2>%a == %a@]`,o,i.doc)}case`Recursive`:{let t=It(n,e.name);return F(`@[<b2>NEW CONSTANT %s%a@]`,t,Qt(e.shape))}}},f=e=>{switch(e.kind){case`Fresh`:{let t=e.domain&&e.domainVisibility===`Visible`?r(e.domain):void 0,i=It(n,e.name);return[F(`NEW %s %s%a`,en[e.level],i,Qt(e.shape)),t?F(` \\in %a`,t):[]]}case`Flex`:return F(`NEW VARIABLE %s`,It(n,e.name));case`Defn`:return d(e.definition);case`Fact`:{let t=F(`@[<h>%a @]`,r(e.expression));return It(n,``),t}}},p=e=>{if(e.context.length===0)return r(e.active);let t=[];for(let r of e.context)Zt(r)?It(n,m(r)??``):t.push(f(r));let i=r(e.active);return Lt(n,e.context.length),t.length===0?i:[F(`@[<v0>ASSUME @[<v0>`),I(t,e=>e),F(`@]@
20
+ PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},nn=(e,t)=>tn(e).printExpr(t),rn=e=>tn().printSequent(e),an=e=>Mt(F(`@[<b0>%a@]`,rn(e))).trimEnd(),on={kind:`At`,isExcept:!1},R=e=>({location:e.location,step:e.step,isSuppressed:e.isSuppressed,method:e.method}),sn=e=>e?.kind===`Named`&&e.isAnonymous,cn=e=>e?.level??0,ln=e=>p({kind:`Internal`,builtin:`TRUE`},e),un=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2,dn=(e,...t)=>Mt(F(e,...t)),fn=e=>pn(e).map((e,t)=>{let n=e.domain.kind===`Domain`?O(t,e.domain.expression):void 0;return{kind:`Fresh`,name:e.name,shape:0,level:n?`Constant`:e.level,domain:n,domainVisibility:`Visible`}}),pn=e=>{let t={kind:`NoDomain`};return e.map(e=>e.domain.kind===`Ditto`?{...e,domain:t}:(t=e.domain,e))},mn=(e,t)=>t.context.flatMap((n,r)=>n.kind===`Fact`&&n.visibility===`Visible`?[O(e+t.context.length-1-r,n.expression)]:[]),hn=(t,n,r)=>{if(!t.step)throw new e.j;return{kind:`Defn`,definition:{kind:`Operator`,name:Qe(t.step),body:n,location:t.location},whereDefined:{kind:`Proof`,time:r},visibility:`Visible`,isLocal:!0,location:t.location}},gn=(e,t,n,r)=>{let i=sn(n.step)?`Visible`:`Hidden`,a=t.context.map(e=>e.kind===`Fact`?{...e,visibility:i}:e),o=p({kind:`List`,bullet:`Refs`,items:mn(2,t)},n),s=Ze(t.context,r);return{context:[...e,...a,{kind:`Fact`,expression:ln(n),visibility:`Hidden`,time:r,location:n.location},hn(n,o,s),{kind:`Fact`,expression:p({kind:`Ix`,index:1},n),visibility:`Hidden`,time:s,location:n.location}],active:O(3,t.active),time:s}},_n=(e,t,n,r,i,a)=>{let o=e||sn(i.step)?`Visible`:`Hidden`;return{context:[...t,hn(i,p(g(r),i),a),{kind:`Fact`,expression:p({kind:`Ix`,index:1},i),visibility:o,time:a,location:i.location}],active:O(2,n)}},vn=(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`},yn=(t,n,r)=>{if(r.kind!==`Dx`)throw new e.C(`Unknown definition ${r.name}`);let i=n.length-r.index,a=n[i];if(!a)return n;if(a.kind!==`Defn`)throw new e.C(`Indicated point is not a definition`);return n.map((e,n)=>n===i?{...a,visibility:t}:e)},bn=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`Mem`&&e.args[0]?.kind===`Ix`&&e.args[0].index===0&&M(t,e.args[1]),xn=(t,n,r,i)=>{let a=!1,o=r,c=[...i];for(let e=i.length-1;e>=0;e--){o=O(-1,o);let t=i[e];t.kind===`Fact`&&M(t.expression,o)?(a=!0,c[e]={...t,visibility:n}):t.kind===`Fresh`&&t.domain&&bn(o,t.domain)&&(a=!0,c[e]={...t,domainVisibility:n})}if(!a){let n=`This expression does not appear in the context and cannot be hidden.`;throw t(s(r.location,`${n}\n`)),new e.C(n,{failure:`proof.Gen.set_expr`})}return c},Sn=(e,t)=>{let n=ie(l(1),t)[1];return n[0].domain.kind===`Ditto`&&e.domain.kind===`Domain`?[{...n[0],domain:{kind:`Domain`,expression:O(1,e.domain.expression)}},...n.slice(1)]:n},Cn=(e,t)=>{if(e.isSuppressed||t.length===0)return{kind:`Obvious`,...R(e)};let n=t.map((t,n)=>{let r=O(2*n+2,t);return{kind:`Assert`,sequent:{context:[],active:r},proof:{kind:`By`,usable:{facts:[O(3,r)],defs:[]},isOnly:!1,location:t.location,method:e.method},location:t.location}}),r={kind:`By`,usable:{facts:[p({kind:`Ix`,index:2*t.length+2},e),...t.map((n,r)=>p({kind:`Ix`,index:2*(t.length-r)},e))],defs:[]},isOnly:!0,...R(e),method:void 0};return{kind:`Steps`,steps:n,qed:{proof:r,location:r.location},...R(e)}},wn=(e,t,n)=>({sequent:e,location:t.location,kind:n,method:t.method}),Tn={total:0,absent:[],omitted:[]},En=(e,t)=>({total:e.total+t.total,absent:[...e.absent,...t.absent],omitted:[...e.omitted,...t.omitted]}),Dn=e=>{switch(e.kind){case`Use`:return{...Tn,total:e.obligations?.length??0};case`Assert`:case`Suffices`:case`Pcase`:case`Pick`:return On(e.proof);default:return Tn}},On=e=>e.kind===`Steps`?[...e.steps.map(Dn),On(e.qed.proof)].reduce(En):e.kind!==`Omitted`||!e.obligations||!e.location?{...Tn,total:e.obligations?.length??0}:{total:e.obligations.length,absent:e.omission===`Implicit`?[e.location]:[],omitted:e.omission===`Explicit`?[e.location]:[]},kn=(e,t)=>e.kind===`At`&&!e.isExcept?p(T(t),e):_e(e,e=>kn(e,t)),An=(t,n,r,i)=>{let a=(t,i,s)=>{let c=i.location;if(!c||!n.has(c.file)||c.endLine<r.start||c.startLine>r.end)return i;switch(i.kind){case`Obvious`:return{...i,obligations:[wn(t,i,{kind:`Main`})]};case`Omitted`:return{...i,obligations:[wn(t,i,{kind:`Omitted`,omission:i.omission})]};case`Error`:return{...i,obligations:[wn(t,i,{kind:`Error`,message:i.message})]};case`By`:throw new e.C(`Proof.Gen.generate`);case`Steps`:{let[e,n]=S({sequent:t,time:s},i.steps,(e,t)=>{let[n,r,i]=o(e.sequent,t,e.time);return[{sequent:n,time:i},r]}),r=a(e.sequent,i.qed.proof,e.time);return{...i,steps:n,qed:{...i.qed,proof:r}}}}},o=(t,n,r)=>{switch(n.kind){case`Forget`:{let e=t.context.length,i=t.context.map((t,r)=>t.kind===`Fact`&&t.visibility===`Visible`&&n.count+r<e?{...t,visibility:`Hidden`}:t);return[{...t,context:i},n,r]}case`Use`:{let i=n.usable;if(i.defs.length===0&&i.facts.length===1){let e=i.facts[0],a=wn({...t,active:e},n,{kind:`Support`});return[{context:[...t.context,{kind:`Fact`,expression:e,visibility:`Visible`,time:vn(t.context,e,r),location:e.location,useLocation:n.useLocation}],active:O(1,t.active)},{...n,obligations:[a]},r]}if(i.facts.length>0)throw new e.C(`Proof.Gen.gen_step: USE with facts and definitions`);let a=i.defs.reduce((e,t)=>yn(`Visible`,e,t),t.context);return[{...t,context:a},n,r]}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>yn(`Hidden`,e,t),t.context),a=n.usable.facts.reduceRight((e,t)=>xn(i,`Hidden`,t,e),e);return[{...t,context:a},n,r]}case`Define`:return[{context:[...t.context,...n.definitions.map(e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0,location:e.location}))],active:O(n.definitions.length,t.active)},n,r];case`Assert`:{let e=gn(t.context,n.sequent,n,r),i=a(e,n.proof,e.time),o={...n,proof:i};return[_n(!1,t.context,t.active,n.sequent,o,r),o,r]}case`Suffices`:{let e=a(_n(!0,t.context,t.active,n.sequent,n,r),n.proof,r),i={...n,proof:e},o=gn(t.context,n.sequent,i,r);return[o,i,o.time]}default:throw new e.C(`Proof.Gen.gen_step`)}},s=(e,t,n,r)=>{let i={kind:`Unnamed`,level:0,id:0},[a,s]=o({context:e,active:{...on,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[a.context,s.obligations??[]]},c=(e,t,n,r)=>{if(n.defs.length===0&&n.facts.length===0)return[e,[]];let i=n.defs.length>0,[a,...o]=n.facts,[l,u]=s(e,t,i?{defs:n.defs,facts:[]}:{defs:[],facts:[a]},r),d=i?n.facts:o.map(e=>O(1,e)),[f,p]=c(l,t,{defs:[],facts:d},r);return[f,[...u,...p]]},d=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),(e.kind===`Assert`||e.kind===`Suffices`||e.kind===`Pcase`||e.kind===`Pick`)&&n(e.proof)};return n(e),t},f=e=>({kind:`Named`,level:e,label:`_a${$e(t)}`,isAnonymous:!0}),m=(e,t)=>t?.kind===`Named`?{...t,level:e}:f(e),g=(e,t)=>{let n={...t,step:m(e,t.step)};if(n.kind!==`Steps`)return n;let r=n.steps.map(t=>_(e,t));return{...n,steps:r,qed:{...n.qed,proof:g(e+1,n.qed.proof)}}},_=(e,t)=>{let n={...t,step:m(e,t.step)};switch(n.kind){case`Assert`:case`Suffices`:case`Pcase`:case`Pick`:return{...n,proof:g(e+1,n.proof)};default:return n}},v=(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.C(`expose_connective`);if(i.kind!==`Defn`||i.definition.kind!==`Operator`)return n;let a=O(r.index,i.definition.body);if(n.kind!==`Apply`)return v(t,a);let o={...a,location:n.location};return v(t,p(re(o,n.args),o))}if(n.kind===`Apply`&&n.operator.kind===`Internal`&&n.operator.builtin===`Prime`){let e=v(t,n.args[0]),r=e=>h(`Prime`,[e],e);return e.kind===`Quant`?p({kind:`Quant`,quantifier:e.quantifier,bounds:e.bounds.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:r(e.domain.expression)}}:e),body:r(e.body)},n):un(e,`Implies`)||un(e,`Mem`)?p({kind:`Apply`,operator:e.operator,args:[r(e.args[0]),r(e.args[1])]},n):r(e)}return n.kind===`Parens`?v(t,n.expression):n},y=e=>{if(e.kind!==`Assert`)return;let t=e.sequent.active;return t.kind===`Apply`&&t.args.length===2?t.args[1]:void 0},b=e=>{if(e.kind!==`Steps`)return e;let t=[];return e.steps.forEach(e=>{let n=t.at(-1),r=n&&y(n);if(e.kind!==`Assert`||!r){t.push(e);return}let i=kn(e.sequent.active,O(2,r));t.push({...e,sequent:{...e.sequent,active:i}})}),{...e,steps:t}},x=(e,t,n,r)=>{let i=b(n);switch(i.kind){case`Obvious`:case`Omitted`:case`Error`:return i;case`By`:{let e=i.usable,t=e.defs.length===0?[]:[{kind:`Use`,usable:{facts:[],defs:e.defs},isOnly:!1,location:i.location}],n=e.facts.map((e,t)=>({kind:`Use`,usable:{facts:[O(t,e)],defs:[]},isOnly:!1,location:e.location,isSuppressed:i.isSuppressed,useLocation:i.location})),r=i.isOnly?[{kind:`Forget`,count:e.facts.length,location:i.location}]:[],a=cn(i.step),o=[...t,...n,...r].map(e=>({...e,step:f(a)})),s={kind:`Obvious`,location:i.location,step:f(a),isSuppressed:i.isSuppressed,method:i.method};return{kind:`Steps`,steps:o,qed:{proof:s,location:s.location,step:s.step},location:i.location,step:i.step,isSuppressed:i.isSuppressed}}case`Steps`:{let[n,a]=S({context:e,goal:t,time:r},i.steps,(e,t)=>{let[n,r,i,a]=C(e.context,e.goal,t,e.time);return[{context:n,goal:r,time:a},i]}),o=x(n.context,n.goal,i.qed.proof,n.time);return{...i,steps:a.flat(),qed:{...i.qed,proof:o}}}}},C=(t,n,r,i)=>{let a=cn(r.step);switch(r.kind){case`Forget`:return[t,n,[r],i];case`Assert`:{let e=gn(t,r.sequent,r,i),a={...r,proof:x(e.context,e.active,r.proof,e.time)},o=_n(!1,t,n,r.sequent,a,i);return[o.context,o.active,[a],i]}case`Suffices`:{let e=_n(!0,t,n,r.sequent,r,i),a={...r,proof:x(e.context,e.active,r.proof,i)},o=gn(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,isSuppressed:r.isSuppressed,method:r.method},o=x(t,n,a,i);if(o.kind!==`Steps`)throw new e.C(`simplifying BY does not produce a non-leaf proof!`);let s=r.usable.facts.map(()=>({kind:`Fact`,expression:on,visibility:`Visible`,time:i,location:r.location}));return[[...t,...s],O(r.usable.facts.length,n),o.steps,i]}case`Hide`:return[r.usable.defs.reduce((t,n)=>{if(n.kind!==`Dx`)throw new e.C(`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.C(`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}))],O(r.definitions.length,n),[r],i];case`Have`:{let e=v(t,n),o={kind:`Fact`,expression:r.expression,visibility:`Visible`,time:i,location:r.location},s=un(e,`Implies`),c={context:[o],active:s?O(1,e.args[1]):e},l=s?{kind:`By`,usable:{facts:[p({kind:`Ix`,index:2},r)],defs:[]},isOnly:!0,...R(r)}:{kind:`Error`,message:dn(`@.@[<v2>@[%s@ %s@]@,%a@]@.`,`Error: this HAVE step is applied to the following goal,`,`which is not an implication:`,nn(t,n)),...R(r)},u=_(a,{kind:`Suffices`,sequent:c,proof:l,location:r.location,step:r.step});return C(t,n,u,i)}case`Take`:return C(t,n,_(a,ee(t,n,r)),i);case`Witness`:return C(t,n,_(a,te(t,n,r)),i);case`Pcase`:{let e={kind:`Assert`,sequent:{context:[{kind:`Fact`,expression:r.expression,visibility:`Visible`,time:i,location:r.location}],active:O(1,n)},proof:r.proof,...R(r)};return C(t,n,_(a,e),i)}case`Pick`:{let a=p({kind:`Quant`,quantifier:`Exists`,bounds:r.bounds,body:r.expression},r),o=w(r.step,`ex`),[s,c,l,u]=C(t,n,{kind:`Assert`,sequent:{context:[],active:a},proof:r.proof,...R(r),step:o},i),d=O(2,a);if(d.kind!==`Quant`)throw new e.C(`Proof.Simplify.simplify_step/PICK`);let f=[...fn(d.bounds),{kind:`Fact`,expression:d.body,visibility:`Visible`,time:u,location:d.body.location}],[m,h,g,_]=C(s,c,{kind:`Suffices`,sequent:{context:f,active:O(f.length,c)},proof:{kind:`Omitted`,omission:`Elsewhere`,...R(r)},...R(r)},u);return[m,h,[...l,...g],_]}}},w=(e,n)=>({kind:`Named`,level:cn(e),label:`${e?.kind===`Named`?e.label:`_a`}${n}${$e(t)}`,isAnonymous:!1}),ee=(e,t,n)=>{let r=pn(n.bounds),i=(t,n,r,a)=>{let o=a[0];if(!o)return{aux:n,goal:r};let s=v(e,r);if(s.kind!==`Quant`||s.quantifier!==`Forall`||s.bounds.length===0)return dn(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this TAKE step is applied to the following goal,`,`which is not a universal formula:`,nn(e,r));let c=s.bounds[0],u=pn(s.bounds).slice(1),d=o.domain,f=c.domain;if(d.kind===`NoDomain`&&f.kind===`Domain`)return dn(`@.@[<b0>%s (%s)@ %s (%s \\in %a)@]@.`,`Error: the TAKE argument`,o.name,`does not match the pattern`,c.name,nn(e,f.expression));if(d.kind===`Domain`&&f.kind===`NoDomain`)return dn(`@.@[<b0>%s (%s \\in %a)@ %s (%s)@]@.`,`Error: the TAKE argument`,o.name,nn(e,d.expression),`does not match the pattern`,c.name);let m=d.kind===`Domain`&&f.kind===`Domain`&&!M(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,m,s.body,a.slice(1));let h=a.length===1?u.map(e=>ie(l(t),[e])[1][0]):u;return i(t+1,m,p({kind:`Quant`,quantifier:`Forall`,bounds:h,body:s.body},s),a.slice(1))},a=i(1,[],t,r);if(typeof a==`string`)return{kind:`Suffices`,sequent:{context:[{kind:`Fact`,expression:ln(t),visibility:`Visible`,time:`Now`,location:n.location}],active:t},proof:{kind:`Error`,message:a,...R(n)},...R(n)};let o=a.aux.filter((e,t)=>a.aux.findIndex(t=>M(e,t))===t),s=[p({kind:`Ix`,index:2},n),...o.map(e=>O(2,e))];return{kind:`Suffices`,sequent:{context:fn(r),active:a.goal},proof:{kind:`By`,usable:{facts:s,defs:[]},isOnly:!0,...R(n)},...R(n)}},te=(e,t,n)=>{let r=[],i=``,a=t;for(let t of n.expressions){let n=v(e,a);if(n.kind!==`Quant`||n.quantifier!==`Exists`||n.bounds.length===0){i||=dn(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this WITNESS step is applied to the following goal,`,`which is not an existential formula:`,nn(e,n)),a=n;break}let[o,...s]=n.bounds,c=s.length===0?n.body:p({kind:`Quant`,quantifier:`Exists`,bounds:Sn(o,s),body:n.body},n),d=t;if(o.domain.kind===`Domain`){let n=o.domain.expression,a=v(e,t);if(un(a,`Mem`)){let[e,t]=a.args,i=M(t,n)?[]:[h(`Subseteq`,[t,n],t)];r.push(...i,a),d=e}else i||=dn(`@.@[<b0>%s (%a)@ %s (%s \\in %a)@]@.`,`Error: the WITNESS argument`,nn(e,a),`does not match the pattern`,o.name,nn(e,n)),d=a}let f=h(`Unprimable`,[d],d);a=D(u(f,l(0)),c)}let o=i===``?Cn(n,r):{kind:`Error`,message:i,...R(n)};return{kind:`Suffices`,sequent:{context:[],active:a},proof:o,...R(n)}};return{generate:a,collect:d,mutate:c,simplify:x}},jn=(e,t=0)=>({level:e,weights:Array.from({length:t},()=>!0),params:/* @__PURE__ */ new Set}),Mn={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]},Nn={Constant:0,State:1,Action:2,Temporal:3,Unknown:0},Pn=e=>new Set(e.flatMap(e=>[...e])),Fn=e=>({level:Math.max(0,...e.map(e=>e.level)),weights:[],params:Pn(e.map(e=>e.params))}),In=/* @__PURE__ */ new WeakMap,Ln=t=>{let n=t.hyp;switch(n.kind){case`Flex`:return jn(1);case`Fresh`:return{...jn(Nn[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.j;return z(t.rest,r.body)}case`Fact`:return z(t.rest,n.expression)}},Rn=e=>{let t=In.get(e);if(t)return t;let n=Ln(e);return In.set(e,n),n},zn=(e,t,n)=>{let r=t.flatMap(t=>t.domain.kind===`Domain`?[z(e,t.domain.expression)]:[]),i=t.reduce((e,t)=>_(e,w(t.name,t.level)),e);return Fn([z(i,n),...r])},Bn=(t,n)=>{if(t.weights.length!==n.length)throw new e.C(`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:Pn([t.params,...r.map(e=>e.params)])}},z=(t,n)=>{let r=e=>z(t,e);switch(n.kind){case`Ix`:{let r=x(t,n.index-1);if(!r)throw new e.j;return Rn(r)}case`Internal`:{let t=Mn[n.builtin];if(!t)throw new e.j;return jn(t[0],t[1])}case`Opaque`:case`String`:case`Num`:return jn(0);case`Lambda`:{let e=n.params.reduce((e,t)=>_(e,w(t.name,`Unknown`,t.shape)),t),r=z(e,n.body),i=new Set(n.params.map(e=>e.name));return{level:r.level,weights:n.params.map(e=>r.params.has(e.name)),params:new Set([...r.params].filter(e=>!i.has(e)))}}case`Apply`:{let t=n.operator;if(t.kind===`Apply`&&t.operator.kind===`Internal`&&t.operator.builtin===`Prime`&&t.args.length===1)return r({...n,operator:t.args[0]});if(t.kind===`Opaque`)return Bn(jn(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.j;return jn(2,1);case`ENABLED`:{let t=r(i);if(t.level>2)throw new e.j;return{level:1,weights:[],params:t.params}}case`UNCHANGED`:{let t=r(i);if(t.level>1)throw new e.j;return{level:2,weights:[],params:t.params}}}}return t.kind===`Internal`&&t.builtin===`Cdot`?(n.args.forEach(r),jn(2)):t.kind===`Internal`&&t.builtin===`Leadsto`?(n.args.forEach(r),jn(3,2)):Bn(r(t),n.args.map(r))}case`Sequent`:{let[e,r]=S(t,n.sequent.context,(e,t)=>{let n=_(e,t);return[n,Rn(n).level]});return jn(Math.max(0,...r,z(e,n.sequent.active).level))}case`With`:case`Dot`:case`Parens`:return r(n.expression);case`Let`:{let e=n.definitions.reduce((e,t)=>_(e,{kind:`Defn`,definition:t,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),t);return z(e,n.body)}case`If`:return Fn([n.condition,n.consequent,n.alternative].map(r));case`List`:return Fn(n.items.map(r));case`Quant`:case`Fcn`:return zn(t,n.bounds,n.body);case`SetOf`:return zn(t,n.bounds,n.element);case`Tquant`:return z(n.names.reduce((e,t)=>_(e,{kind:`Flex`,name:t}),t),n.body),jn(3);case`Choose`:case`SetSt`:{let e=n.domain&&r(n.domain),i=n.domain?ee(n.name,n.domain):w(n.name,`Constant`);return Fn([z(_(t,i),n.body),...e?[e]:[]])}case`SetEnum`:case`Tuple`:return Fn(n.elements.map(r));case`Product`:return Fn(n.factors.map(r));case`FcnApp`:return Fn([n.function,...n.args].map(r));case`Arrow`:return Fn([r(n.domain),r(n.range)]);case`Rect`:case`Record`:return Fn(n.fields.map(e=>r(e.value)));case`Except`:return Fn([r(n.function),...n.specs.flatMap(e=>[...e.trail.flatMap(e=>e.kind===`Apply`?[r(e.expression)]:[]),r(e.value)])]);case`Sub`:return{...Fn([r(n.action),r(n.subscript)]),level:2};case`Tsub`:case`Fair`:return r(n.action),r(n.subscript),jn(3);case`Case`:return Fn([...n.arms.flatMap(e=>[r(e.condition),r(e.body)]),...n.other?[r(n.other)]:[]]);case`Bang`:case`At`:throw new e.j}},Vn=`EnabledWrapper`,Hn=`CdotWrapper`,Un="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`.",Wn="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.",Gn=`${Wn} For example, writing \`BY ExpandCdot\`.`,Kn=e=>e?a(e):`<unknown location>`,qn=(e,t)=>N(void 0,e,(e,n)=>t(n),()=>void 0),Jn=(t,n)=>{let r=x(t,n-1)?.hyp;if(!r)throw new e.j;return r},Yn=e=>e.kind===`Internal`&&(e.builtin===`ENABLED`||e.builtin===`Cdot`),Xn=e=>e.kind===`Opaque`&&(e.name===Vn||e.name===Hn),Zn=e=>e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`Lambda`&&(Yn(e.operator)||Xn(e.operator)),Qn=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t,$n=e=>e===void 0?2:Math.min(2,e),er=e=>e===void 0?void 0:Math.max(1,e-1),tr=(t,n,r,i,a)=>{let c=(e,i=a)=>tr(t,n,r,e,i);if(Zn(i))return i;if(i.kind===`Sub`)return{...i,action:c(i.action),subscript:c(i.subscript,er(a))};if(i.kind===`Apply`&&i.operator.kind===`Internal`){let r=i.operator.builtin,[o,l]=i.args;if(r===`Cdot`&&i.args.length===2){if(a!==void 0&&!t.isCdot)throw n(s(i.location,`${Wn}For example, writing \`BY ExpandCdot\`.`)),new e.w(`Expr.Action`);return{...i,args:t.isCdot?[c(o,$n(a)),c(l,1)]:[c(o),c(l)]}}if(r===`ENABLED`&&i.args.length===1){if(a!==void 0&&!t.isEnabled)throw n(s(i.location,Un)),new e.w(`Expr.Action`);return{...i,args:[t.isEnabled?c(o,$n(a)):c(o)]}}if((r===`Prime`||r===`UNCHANGED`)&&i.args.length===1)return{...i,args:[c(o,er(a))]}}let u=i.kind===`Apply`&&i.operator.kind===`Ix`?i.operator:i;if(u.kind!==`Ix`)return N(r,i,(e,r)=>tr(t,n,e,r,a),_);if(a===void 0)return i;let d=z(r,i).level,f=Jn(r,u.index),p=e=>`The operator \`${e}\` is declared at:\n${Kn(f.location)}`;if(f.kind===`Fresh`&&f.level===`Unknown`)throw n(s(i.location,`Declared operator \`${f.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 ${d}.\n May need expansion. A declared operator cannot be expanded.\n${p(f.name)}\n and has arity: ${f.shape}`)),new e.j(`File "src/expr/e_action.ml", line 367, characters 20-26: Assertion failed`);if(d<a)return i;if(d>2||f.kind===`Fact`)throw new e.j;if(f.kind===`Flex`){if(i.kind!==`Ix`)throw new e.j;return i}if(f.kind===`Fresh`){let t=`The expression that results from applying the declared operator \`${f.name}\` has expression level ${d} within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${a}. A declared operator cannot be expanded.\n${p(f.name)}\n and has level: ${Nn[f.level]}\n and arity: ${f.shape}`;throw n(s(i.location,t)),new e.C(t)}let m=f.definition;if(m.kind!==`Operator`&&m.kind!==`Bpragma`)throw new e.j;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=m.body.kind===`Lambda`?m.body.body:m.body,o=`Hidden definition of operator \`${m.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 \`${m.name}\` is defined at: \n\t${Kn(a.location)}\nand the operator \`${m.name}\` occurs at: \n\t${Kn(i.location)}\nUsing the proof directive \`AutoUSE\` from the module \`TLAPS\`, or \`BY DEF ${m.name}\` is expected to avoid this error.\n`;throw n(s(i.location,o)),new e.w(o)}n({text:`${o(i.location)}[INFO]: Auto-expanding the definition of operator: ${m.name}\n`,channel:`stdout`});let h=D(l(u.index),m.body);return c(T(i.kind===`Apply`?re(h,i.args):h))},nr=e=>h(`Eq`,[h(`Prime`,[e],e),e],e),rr=e=>{let t=e=>e.kind===`Tuple`?e.elements.flatMap(t):[e],n=t(e);return n.length===0?p({kind:`Internal`,builtin:`TRUE`},e):n.length===1?nr(n[0]):p({kind:`List`,bullet:`And`,items:n.map(nr)},e)},ir=t=>{if(t.kind===`Apply`&&t.args.length===1)return rr(t.args[0]);if(t.kind!==`Sub`)throw new e.j;let n=rr(t.subscript),r=t.modal===`Box`?n:h(`Neg`,[n],t);return h(t.modal===`Box`?`Disj`:`Conj`,[t.action,r],t)},ar=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},or=e=>{let t=Array.from({length:16},()=>[]);return e.forEach((e,n)=>{if(t[ar(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[ar(e)&r.length-1].push(e)),t=r}),t.flat()},sr=(t,n,r,i,a,o)=>{let c=e=>sr(t,n,r,i,a,e),l=r!==void 0||i!==void 0,u=(e,s)=>{let c={names:[],depth:Math.max(r?.depth??0,i?.depth??0)+1},[l,u]=s,d=[sr(t,n,r,c,a,l),...u?[sr(t,n,c,i,a,u)]:[]],f=c.names.length===0?[`r#0`]:or(c.names);return p({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(Zn(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 u(o.operator,o.args);if(r===`ENABLED`&&l)throw n(s(o.location,Un)),new e.w(`Expr.Action`);if(r===`Cdot`&&l)throw n(s(o.location,Gn)),new e.w(`Expr.Action`);if(r===`Prime`&&o.args.length===1){let e=sr(t,n,i,void 0,a,o.args[0]);return i?e:{...o,args:[e]}}if(r===`UNCHANGED`&&l)return c(ir(o))}if(o.kind===`Sub`&&l)return c(ir(o));if(o.kind===`Ix`){if(!r)return o;let t=Jn(a,o.index);if(t.kind===`Fact`)throw new e.j;if(t.kind!==`Flex`)return o;let n=`${t.name}#enabled#prime${r.depth}`;return r.names.includes(n)||r.names.push(n),p({kind:`Opaque`,name:n},o)}if(o.kind===`Apply`&&o.operator.kind===`Opaque`)throw n(s(o.location,`Named operator \`${o.operator.name}\` unexpected after anonymization.`)),new e.j(`File "src/expr/e_action.ml", line 1048, characters 12-18: Assertion failed`);return N(a,o,(e,a)=>sr(t,n,r,i,e,a),_)},cr=(t,n)=>{if(n.kind===`Apply`&&Yn(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`)throw new e.j;let[i,...a]=r.params;if(i.name!==`_`)return n;let o=cr({kind:`Compose`,outer:t,inner:l(a.length)},r.body);return{kind:`Apply`,operator:n.operator,args:[{kind:`Lambda`,params:a,body:o}]}}return n.kind===`Ix`?D(t,n):n.kind===`Apply`?p(re(cr(t,n.operator),n.args.map(e=>cr(t,e))),n):N(t,n,cr,e=>f(1,e))},lr=(t,n)=>{if(n.kind===`Apply`&&Yn(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`||r.params[0].name===`_`)throw new e.j;let i=n.operator.builtin===`Cdot`?Hn:Vn;return{kind:`Apply`,operator:p({kind:`Opaque`,name:i},n.operator),args:[{kind:`Lambda`,params:r.params.map((e,n)=>({name:t?e.name:`r#${n}`,shape:0})),body:lr(t,r.body)}]}}return qn(n,e=>lr(t,e))},ur=t=>{if(Qn(t,`Cdot`)&&t.args.length===1&&t.args[0].kind!==`Lambda`)throw new e.j;return qn(t,ur)},dr=(e,t,n,r,i,a)=>{let o=sr(i,t,void 0,void 0,n,r);return lr(a,e.expr(n,cr(l(0),o)))},fr={isEnabled:!0,isCdot:!0,isAutoUse:!0},pr=(e,t,n,r,i=fr)=>{let a=tr(i,t,n,r,void 0);return ur(dr(e,t,n,a,i,!1))},mr=(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:mr(t,n,v(r,e.map(e=>w(e.name,`Unknown`,e.shape))),i,!0)}),c=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===Vn||t.isCdot&&e.name===Hn))return o(a.params,a.body);if(e.kind===`Ix`&&(t.isEnabled||t.isCdot)){let t=Jn(r,e.index);if(t.kind===`Defn`&&t.definition.kind===`Operator`&&(t.definition.name===Vn||t.definition.name===Hn))return o(a.params,a.body)}if(Yn(e)&&c(e.builtin))return o(a.params,a.body)}if(Yn(e)&&c(e.builtin))return mr(t,n,r,a,!0)}if(Qn(i,`ENABLED`)&&a)throw n(s(i.location,Un)),new e.w(`Expr.Action`);if(Qn(i,`Cdot`)&&a)throw n(s(i.location,Gn)),new e.w(`Expr.Action`);return N(r,i,(e,r)=>mr(t,n,e,r,a),_)},hr=t=>{if(t.kind===`Quant`&&t.quantifier===`Exists`){let n=t.body;if(n.kind===`List`&&n.bullet===`Or`)return hr({...n,items:n.items.map(e=>({...t,body:e}))});if(n.kind===`Apply`&&n.operator.kind===`Internal`&&n.operator.builtin===`Disj`){if(n.args.length!==2)throw new e.j;return hr({...n,args:n.args.map(e=>({...t,body:e}))})}}return qn(t,hr)},gr=(e,t,n,r,i)=>{let a=tr(i,t,n,r,void 0),o=dr(e,t,n,a,i,!0);return hr(mr(i,t,n,o,!1))},_r=(e,t)=>({kind:`Definition`,definition:{kind:`Operator`,name:e,body:{kind:`Internal`,builtin:t}},whereDefined:`Builtin`,visibility:`Visible`,isLocal:!1}),B=(e,t,n)=>({kind:`Definition`,definition:{kind:`Operator`,name:t,body:{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}),vr=[_r(`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`)],yr=[...vr,_r(`Int`,`Int`),B(1,`-.`,`Uminus`)],br=[...yr,_r(`Real`,`Real`),B(2,`/`,`Ratio`),_r(`Infinity`,`Infinity`)],xr=[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`)],Sr=[B(2,`Print`,`Print`),B(1,`PrintT`,`PrintT`),B(2,`Assert`,`Assert`),_r(`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`),_r(`Any`,`Any`),B(1,`ToString`,`ToString`)],Cr=(e,t)=>({name:e,extendees:[],body:t,isImportant:!1,isStandard:!0}),wr=new Map([Cr(`Naturals`,vr),Cr(`Integers`,yr),Cr(`Reals`,br),Cr(`Sequences`,xr),Cr(`TLC`,Sr)].map(e=>[e.name,e])),Tr=e=>{let t=e.location;switch(e.kind){case`Constants`:return e.declarations.map(e=>({kind:`Fresh`,name:e.name,shape:e.shape,level:`Constant`,domain:void 0,domainVisibility:`Visible`,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:p(g(oe(l(-e.axiomCount),{...e.sequent,context:e.sequent.context.slice(e.axiomCount)})),e);return e.name===void 0?[{kind:`Fact`,expression:n,visibility:`Hidden`,time:`Always`,location:t}]:Dr(e.name,n,t)}case`Mutate`:return e.mode===`Use`?e.usable.facts.map((e,n)=>({kind:`Fact`,expression:O(n,e),visibility:`Visible`,time:`Always`,location:t})):[];case`Submod`:case`Anoninst`:return[]}},Er=e=>e.kind===`Axiom`||e.kind===`Theorem`?e.name===void 0?1:2:Tr(e).length,Dr=(e,t,n)=>[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:t,location:n},whereDefined:`User`,visibility:`Visible`,isLocal:!1,location:n},{kind:`Fact`,expression:{kind:`Ix`,index:1,location:n},visibility:`Hidden`,time:`Always`,location:n}],Or=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:Or(e.module)}}];default:return[e]}}),kr=(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.j(`Stack overflow`);let n=t.get(o);if(!n)throw new e.C(`Module "${o}" unknown`);a.push(...Or(kr(t,n,r,/* @__PURE__ */ new Set([...i,o])))),r.add(o)}return{...n,body:[...a,...n.body].map(e=>e.kind===`Submod`?{...e,module:kr(t,e.module,/* @__PURE__ */ new Set)}:e)}},Ar=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&&jr(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(Mr),locations:t,submodules:a}},jr=e=>typeof e==`object`&&!!e&&`module`in e&&typeof e.module==`string`&&`substitutions`in e,Mr=(e,t)=>e<t?-1:+(e>t),Nr=(t,n)=>({facts:ne(t,n.facts),defs:n.defs.map(n=>{if(n.kind===`Dvar`)return n;let r=D(t,{kind:`Ix`,index:n.index});if(r.kind!==`Ix`)throw new e.C(`substitution produced bad definition`);return{...n,index:r.index}})}),Pr=(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:ae(e,t.definition)}];case`Axiom`:return[f(Er(t),e),{...t,expression:D(e,t.expression)}];case`Theorem`:return[f(Er(t),e),{...t,sequent:oe(e,t.sequent)}];case`Submod`:return[e,{...t,module:{...t.module,body:Fr(e,t.module.body)}}];case`Mutate`:return[t.mode===`Hide`?e:f(t.usable.facts.length,e),{...t,usable:Nr(e,t.usable)}];case`Anoninst`:return[e,{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(t=>({name:t.name,expression:D(e,t.expression)}))}}]}},Fr=(e,t)=>S(e,t,Pr)[1],Ir=(t,n,r,i)=>{try{let r=pr(t.anonymizer,t.onWarning,n,{kind:`Sequent`,sequent:i});if(r.kind!==`Sequent`)throw new e.j;return r.sequent}catch(n){if(!(n instanceof e.C)||n.failure===void 0)throw n;let s=i.active.location,c=`${n.failure}\nCould not instantiate the theorem ${r===void 0?``:`named: ${r}, `}at: ${s?a(s):`<unknown location>`}`;return t.onWarning({text:`${o(s)}[ERROR]${c}`,channel:`stdout`}),t.onWarning({text:c,channel:`toolboxOnly`}),{context:[],active:p({kind:`Internal`,builtin:`TRUE`},i.active)}}},Lr=(e,t,n)=>{if(n.kind===`Theorem`)return{...n,sequent:Ir(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=pr(e.anonymizer,e.onWarning,t,r.body);return{...n,definition:{...r,body:i}}},Rr=(e,t,n)=>S(t,n,(t,n)=>{if(n.kind===`Submod`){let[r,i]=Rr(e,t,n.module.body);return[r,{...n,module:{...n.module,body:i}}]}let r=Lr(e,t,n);return[v(t,Tr(r)),r]}),zr=(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.C(`Parameter ${s.name} has no substitute`);let r=Er(s.remaining)===0;a=Fr(u(O(i,t),l(0)),r?o:[s.remaining,...o])}else r.push(t),i+=Er(t),a=o}return r},Br=(e,t,n)=>{let r=Array.from({length:t},(e,r)=>p({kind:`Ix`,index:t-r},{location:n})),i=Array.from({length:t},(e,t)=>p({kind:`Ix`,index:t+1},{location:n})),a=Array.from({length:e},(e,i)=>{let a=p({kind:`Ix`,index:i+t+1},{location:n});return t>0?p({kind:`Apply`,operator:a,args:r},{location:n}):a});return d([...a,...i].reverse(),l(e+t))},Vr=(e,t)=>{let n=t.map(e=>({name:e,shape:0}));return e.kind===`Lambda`?{...e,params:[...n,...e.params]}:t.length===0?e:p({kind:`Lambda`,params:n,body:e},e)},Hr=(t,n,r,i,a,s)=>{let u=e=>r===``?e:`${r}!${e}`,d=i.args.length,f=[],m=0,h=n,_=d===0,v=e=>{_||(_=!0,t.onWarning({text:e,channel:`stderr`}))};for(;h.length>0;){let[n,...r]=h;h=r;let _=e=>Vr(D(Br(m,d,s),e),i.args);switch(n.kind){case`Definition`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e.C(`Module.Elab.localize`);let i=n.isLocal?`${r.name}$${$e(t.salts)}`:r.name;f.push({...n,definition:{...r,name:u(i),body:_(r.body)},whereDefined:n.isLocal?`Builtin`:n.whereDefined,isLocal:n.isLocal||a}),m+=1;continue}case`Axiom`:{v(`${c(s)}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:u(n.name),expression:_(n.expression)};f.push(e),m+=Er(e);continue}case`Theorem`:{v(`${o(s)}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=_(p(g(n.sequent),n));f.push({...n,name:n.name===void 0?void 0:u(n.name),sequent:e.kind===`Sequent`?e.sequent:{context:[],active:e},proof:{kind:`Omitted`,omission:`Elsewhere`,location:n.location}}),m+=1;continue}case`Mutate`:n.mode===`Use`&&(h=Fr(l(-n.usable.facts.length),h));continue;case`Submod`:continue;default:throw new e.C(`Module.Elab.localize`)}}return f},Ur=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={kind:`Fact`,expression:e.name===void 0?O(1,e.expression):p({kind:`Ix`,index:2},e),visibility:`Visible`,time:`Always`,location:i},o=0,s=r.map(e=>{let t=o;if(o+=Er(e),e.kind!==`Theorem`)return e;let n=oe(l(1),e.sequent);return{...e,sequent:{...n,context:[E(l(t),a),...n.context]},axiomCount:e.axiomCount+1}});n=Fr(l(-1),s)}return t},Wr=e=>new Set(e.body.flatMap(e=>e.kind===`Constants`?e.declarations.map(e=>e.name):e.kind===`Variables`?e.names:[])),Gr=(t,n,r,i,a,o,s)=>{let c=n.get(i.module);if(!c)throw new e.C(`Module "${i.module}" unknown`);let u=Wr(c);for(let t of i.substitutions)if(!u.has(t.name))throw new e.C(`Parameter ${t.name} occurs in the statement \`INSTANCE ${i.module} WITH\`, and is not declared in the module ${i.module}`);let d=v(r,i.args.map(e=>w(e,`Unknown`))),f=new Map(i.substitutions.map(e=>[e.name,e.expression]));for(let t of[...u].sort(Mr))if(!f.has(t)){if(!b(d,t))throw new e.C(`Required parameter ${t} for module ${i.module} could not be inferred.`);f.set(t,p({kind:`Opaque`,name:t},{location:s}))}let m=new Map([...f].map(([e,n])=>[e,t.anonymizer.expr(d,n)])),h=Fr(l((d?.size??0)-(c.depth??0)),c.body.map(e=>e.kind===`Theorem`?{...e,proof:{kind:`Omitted`,omission:`Implicit`,location:e.proof.location}}:e)),[,g]=Rr(t,d,h);return Ur(Hr(t,zr(g,m),o,i,a,s))},Kr=(e,t,n)=>e===void 0?{hyps:[],sequent:t}:{hyps:[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:p(g(t),{location:n}),location:n},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:n}],sequent:oe(l(1),t)},qr=(t,n,r)=>{let i=r.instance.module;if(!t.latestModules.has(i))throw t.onWarning({text:`${c(r.instance.location)}Module ${JSON.stringify(i)} unknown\n`,channel:`toolbox`}),new e.C(`Module ${JSON.stringify(i)} unknown`,{failure:`Module.Elab.anon#defns`});let a=Gr(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=Fr(l(-Er(e)),t)}return o},Jr=(e,t,n,r)=>{let i=[],a=n,o=e=>{i.push(e),a=v(a,Tr(e))},s=e=>e!==void 0&&b(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,d=(r,o,s)=>{let l=Gr(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`:d(i.instance,i.isLocal,``);continue;case`Definition`:{let t=i.definition;if(t.kind===`Instance`){d(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 f=Tr(s)[0],m=b(a,t.name);if(m?.hyp.kind===`Defn`&&(m.hyp.definition.kind===`Recursive`||ue(E(l(m.depth+1),m.hyp),f))){let e=c.slice(n+1),t=Fr(u(p({kind:`Ix`,index:m.depth+1},i),l(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=Kr(c,u,i.location),f=v(v(a,d.hyps.map(e=>({...e,isConstnessUnset:!0}))),d.sequent.context),p=e.anonymizer.proof(f,l),m=r.isImportant?e.generator.simplify(y(f),d.sequent.active,p,Ze(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:Jr(e,t,a,i.module)});continue}}let d={...r,body:i,depth:n?.size??0};return t.set(r.name,d),d},Yr=(e,t,n)=>{let r=[],i=[],a=Tn,o=t;for(let t of n.body)switch(t.kind){case`Theorem`:{let n=Kr(t.name,t.sequent,t.location),s=[...o,...n.hyps],c=[...s,...n.sequent.context],l=e.generator.generate({context:c,active:n.sequent.active},t.proof,Ze(c,`Always`));r.push(...e.generator.collect(l));let u=On(l);i.push({...u,location:t.location}),a=En(a,u);let d=t.name===void 0?p(g(t.sequent),t):{kind:`Ix`,index:1,location:t.location};o=[...s,{kind:`Fact`,expression:d,visibility:`Hidden`,time:`Always`,location:t.location}];continue}case`Submod`:{let n=Yr(e,o,t.module);r.push(...n.obligations),a=En(a,n.summary);continue}case`Mutate`:{let[n,i]=e.generator.mutate(o,t.mode,t.usable,t.location);r.push(...i),o=n;continue}default:o=[...o,...Tr(t)]}return{obligations:r,summary:{...a,theorems:i}}},Xr=[`(`,`)`,`;`,`:`,`@`,`,`],Zr=e=>e===` `||e===`\r`||e===` `,Qr=(e,t)=>{let n={...t},r=()=>{for(;n.line<e.length;){let t=e[n.line];for(;Zr(t[n.column]);)n.column++;if(n.column<t.length)return;n.line++,n.column=0}};if(r(),!(e[n.line]??``).startsWith(`(*{`,n.column))return;n.column+=3;let i=[];for(r();n.line<e.length;r()){let t=e[n.line].slice(n.column);if(t.startsWith(`}*)`))return i;let r=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t)??/^\d+(\.\d+)?/.exec(t)??/^"(\\.|[^"\\])*"/.exec(t);if(r){let e=r[0];i.push(e.startsWith(`"`)?{kind:`String`,text:JSON.parse(e)}:/^\d/.test(e)?{kind:`Number`,text:e}:{kind:`Ident`,text:e}),n.column+=e.length}else{if(!Xr.includes(t[0]))return;i.push({kind:`Punct`,text:t[0]}),n.column++}}},$r=(e,t)=>e?.kind===`Punct`&&e.text===t,ei=e=>e?.kind===`String`?{kind:`String`,value:e.text}:e?.kind===`Number`?{kind:`Float`,value:Number.parseFloat(e.text)}:$r(e,`@`)?{kind:`Default`}:void 0,ti=/* @__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`]]),ni=(e,t)=>{let n=Qr(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(!$r(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 $r(n[r],`(`)&&!a()?void 0:{name:e.text,...t}}let t=ti.get(e.text);return t===void 0?void 0:{name:t}})();if(t&&$r(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},ri=(e,t)=>{let n=Qr(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`||!$r(n[r],`(`))return;r++;let t=[];for(;;){let e=n[r++];if(e?.kind!==`Ident`||!$r(n[r],`:`))return;r++;let i=ei(n[r++]);if(!i)return;if(t.push({hint:e.text,value:i}),$r(n[r],`)`))break;if(!$r(n[r],`;`))return;r++}r++,i.push(t)}return i},ii=e=>({kind:`Opaque`,name:e}),ai=e=>({kind:`Tuple`,elements:e.map(ii)}),oi=(e,t)=>({kind:`Apply`,operator:{kind:`Internal`,builtin:`Eq`},args:[e,t]}),si=e=>e.map(e=>({name:e,level:`Constant`,domain:{kind:`NoDomain`}})),ci=(e,t)=>e?.kind===`Product`&&e.factors.length===t.length?e.factors:void 0,li=(e,t)=>t.map((t,n)=>({kind:`Operator`,name:t,body:{kind:`FcnApp`,function:ii(e),args:[{kind:`Num`,integer:String(n+1),fraction:``}]}})),ui=(e,t)=>e.map((e,n)=>({name:e,level:`Constant`,domain:{kind:`Domain`,expression:t[n]}})),di=e=>({name:e.name,level:`Constant`,domain:e.domain}),fi=(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[0];if(r.kind===`Name`)return{kind:`Quant`,quantifier:e,bounds:n.flatMap(e=>e.kind===`Name`?[di(e)]:[]),body:t,location:t.location};let i=ci(r.domain,r.names);if(i)return{kind:`Quant`,quantifier:e,bounds:ui(r.names,i),body:t,location:t.location};let a={kind:`Apply`,operator:{kind:`Internal`,builtin:e===`Exists`?`Mem`:`Notmem`},args:[ai(r.names),r.domain]};return{kind:`Quant`,quantifier:e,bounds:si(r.names),body:{kind:`List`,bullet:e===`Exists`?`And`:`Or`,items:[a,t]},location:t.location}},n)},pi=(e,t,n,r)=>ci(n,t)?{kind:`Let`,definitions:li(e,t),body:r}:{kind:`Quant`,quantifier:`Exists`,bounds:si(t),body:{kind:`List`,bullet:`And`,items:[oi(ii(e),ai(t)),r]}},mi=(e,t,n)=>{let r=`choose#${e[0]}`;return{kind:`Choose`,name:r,domain:t,body:pi(r,e,t,n)}},hi=(e,t,n)=>{let r=`setst#${e[0]}`;return{kind:`SetSt`,name:r,domain:t,body:pi(r,e,t,n)}},gi=(e,t,n)=>{let r=e.map(e=>{if(e.kind===`Name`)return{bounds:[di(e)],definitions:[]};let t=ci(e.domain,e.names);if(t&&n)return{bounds:ui(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:li(r,e.names)};let a=`choose#${r}`;return{bounds:[i],definitions:[{kind:`Operator`,name:a,body:mi(e.names,void 0,oi(ii(r),ai(e.names)))},...li(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}}},_i=(e,t)=>{let n=gi(t,e,!0);return{kind:`SetOf`,element:n.value,bounds:n.bounds}},vi=(e,t)=>{let n=gi(e,t,!1);return{kind:`Fcn`,bounds:n.bounds,body:n.value}},yi={"=>":`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`},bi=e=>Ht(e).name,xi=/^<(\d+|\*|\+)>([A-Za-z0-9_]*)\.*$/,Si=(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}},Ci={Always:`[]`,Eventually:`<>`,Enabled:`ENABLED`,Unchanged:`UNCHANGED`},wi=(e,t)=>e!==void 0&&t!==void 0&&e.line===t.line&&e.column===t.column,Ti=e=>e.location.range?.start,Ei=e=>e.location.range?.end,Di=(e,t)=>{let n=e.location.range;return n&&t?{...e,location:{...e.location,range:{...n,end:t}}}:e},Oi=e=>{if(e.kind===`Apply`){let t=Ht(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=Ci[e.kind];if(t!==void 0&&`expression`in e)return{operator:Ht(t),isInfix:!1,operand:e.expression,replace:t=>({...e,expression:t})}},ki=(e,t)=>e.high<t.low,Ai=e=>{let t=Ht(e.operator),[n,r]=e.args,i=Ei(e),a=t=>{let n=e.location.range,i=Ti(t);return{...e,args:[t,r],location:n&&i?{...e.location,range:{...n,start:i}}:e.location}},o=(e,n)=>{let r=n?Oi(e):void 0;if(!r)return{kind:`Reduced`,isFinal:!1};let s=o(r.operand,wi(Ei(r.operand),Ei(e)));return s.kind===`Attached`?{kind:`Attached`,expression:Di(r.replace(s.expression),i)}:!s.isFinal&&(ki(t,r.operator)||r.isInfix&&t.fixity===`InfixLeft`&&r.operator.fixity===`InfixLeft`&&!ki(r.operator,t))?{kind:`Reduced`,isFinal:!ki(t,r.operator)}:{kind:`Attached`,expression:Di(r.replace(a(r.operand)),i)}},s=o(n,wi(Ti(n),Ti(e)));return s.kind===`Attached`?s.expression:e},ji="use instead the class`E_visit.iter_concrete`",Mi=(e,t)=>t>0&&e[t-1].set===e[t].set,Ni=(t,n,r,i)=>{let a=n.split(`
21
+ `),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={line:e.endLine-1,column:e.endColumn-1},n=e=>e===` `||e===`\r`;for(;t.line<a.length;){let e=a[t.line];for(;n(e[t.column]);)t.column++;if(t.column<e.length)break;t.line++,t.column=0}if(!(a[t.line]??``).startsWith(`(*{`,t.column))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&&ni(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?p({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),m=(e,t)=>{let n=bi(e),r=yi[n];return p(r?{kind:`Internal`,builtin:r}:{kind:`Opaque`,name:n},{location:t})},h=(e,t,n,r)=>{if(e.startsWith(`<`)){let t=p({kind:`Opaque`,name:e},{location:n});return p({kind:`Bang`,expression:t,selectors:[]},{location:n})}let i=yi[e];if(i&&t.length===0)return p({kind:`Internal`,builtin:i},{location:n});let a=e.split(`!`);if(a.length===1){let r=p({kind:`Opaque`,name:e},{location:n});return t.length===0?r:p({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=p({kind:`Opaque`,name:a[0]},{location:n});return p({kind:`Bang`,expression:o[0]===0?l:p({kind:`Apply`,operator:l,args:c(0)},{location:n}),selectors:a.slice(1).map((e,t)=>({kind:`Label`,label:bi(e),args:c(t+1)}))},{location:n})},g=(t,n)=>t.map((r,i)=>{if(r.pattern.kind===`Tuple`)throw new e.C(`Unexpected tuple declaration`,{failure:ji});return{name:r.pattern.name,level:`Constant`,domain:Mi(t,i)?{kind:`Ditto`}:{kind:`Domain`,expression:b(r.set,n)}}}),_=(e,t)=>e.map((n,r)=>{let i=b(n.set,t);return n.pattern.kind===`Tuple`?{kind:`Tuple`,names:n.pattern.names,domain:i}:{kind:`Name`,name:n.pattern.name,domain:Mi(e,r)?{kind:`Ditto`}:{kind:`Domain`,expression:i}}}),v=(t,n)=>{if(!i)throw new e.C(`Unexpected tuple declaration`,{failure:ji});return p(t,{location:n})},y=e=>e.some(e=>e.pattern.kind===`Tuple`),b=(t,n)=>{let r=f(t.location),i=e=>b(e,n),o=(e,t)=>e.length===2?Si(e[0].location,e[1].location):e.length!==1||!e[0].location?r:t===`Prefix`?Si({...r,endLine:r.startLine,endColumn:r.startColumn+1},e[0].location):t===`Postfix`?Si({...r,startLine:r.endLine,startColumn:r.endColumn-1},e[0].location):r,s=(e,t)=>p({kind:`Apply`,operator:{kind:`Internal`,builtin:e},args:[t]},{location:o([t],`Prefix`)});switch(t.kind){case`Number`:return p({kind:`Num`,integer:t.text??String(t.value),fraction:``},{location:r});case`Decimal`:{let[e,n]=t.text.split(`.`);return p({kind:`Num`,integer:e,fraction:n},{location:r})}case`String`:{let e=/"((?:[^"\\]|\\.)*)"$/.exec((a[r.endLine-1]??``).slice(0,r.endColumn-1));return p({kind:`String`,value:e?.[1]??t.value},{location:r})}case`Identifier`:return h(t.name,[],r);case`Apply`:{if(t.args.length===2){let e=Ai(t);if(e!==t)return i(e)}let e=t.args.map(i),n=Ht(t.operator);return n.fixity===`Nonfix`?h(t.operator,e,r,t.argumentCounts):p({kind:`Apply`,operator:m(t.operator,void 0),args:e},{location:o(e,n.fixity)})}case`OperatorReference`:return m(t.operator,r);case`Lambda`:return p({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 p({kind:`List`,bullet:t.kind,items:e},{location:r});let n=t.kind===`And`?`Conj`:`Disj`;return e.reduce((e,t)=>p({kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:[e,t]},{location:Si(e.location,t.location)}))}case`Prime`:{let e=i(t.expression);return p({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 p({kind:`If`,condition:i(t.condition),consequent:i(t.consequent),alternative:i(t.alternative)},{location:r});case`Case`:return p({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 p({kind:`Let`,definitions:[...t.definitions,...t.instances??[]].sort((e,t)=>e.location.line-t.location.line||e.location.column-t.location.column).map(e=>S(e,n)),body:i(t.body)},{location:r});case`Forall`:case`Exists`:return y(t.bounds)?v(fi(t.kind,_(t.bounds,n),i(t.body)),r):p({kind:`Quant`,quantifier:t.kind,bounds:g(t.bounds,n),body:i(t.body)},{location:r});case`UnboundedQuantifier`:{let e=i(t.body),n=t.quantifier;return t.isTemporal?p({kind:`Tquant`,quantifier:n,names:t.names,body:e},{location:r}):p({kind:`Quant`,quantifier:n,bounds:si(t.names),body:e},{location:r})}case`Choose`:return t.pattern.kind===`Tuple`?v(mi(t.pattern.names,t.set&&i(t.set),i(t.body)),r):p({kind:`Choose`,name:t.pattern.name,domain:t.set&&i(t.set),body:i(t.body)},{location:r});case`SetEnumeration`:return p({kind:`SetEnum`,elements:t.elements.map(i)},{location:r});case`SetFilter`:return t.bound.pattern.kind===`Tuple`?v(hi(t.bound.pattern.names,i(t.bound.set),i(t.predicate)),r):p({kind:`SetSt`,name:t.bound.pattern.name,domain:i(t.bound.set),body:i(t.predicate)},{location:r});case`SetMap`:return y(t.bounds)?v(_i(i(t.expression),_(t.bounds,n)),r):p({kind:`SetOf`,element:i(t.expression),bounds:g(t.bounds,n)},{location:r});case`Tuple`:return p({kind:`Tuple`,elements:t.elements.map(i)},{location:{...r,startLine:r.endLine,startColumn:r.endColumn-2}});case`FunctionConstruction`:return y(t.bounds)?v(vi(_(t.bounds,n),i(t.body)),r):p({kind:`Fcn`,bounds:g(t.bounds,n),body:i(t.body)},{location:r});case`FunctionSet`:return p({kind:`Arrow`,domain:i(t.domain),range:i(t.range)},{location:r});case`Record`:case`RecordSet`:return p({kind:t.kind===`Record`?`Record`:`Rect`,fields:t.fields.map(e=>({name:e.name,value:i(e.value)}))},{location:r});case`Except`:return p({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:b(e.value,!0)}))},{location:r});case`ExceptAt`:return p({kind:`At`,isExcept:n},{location:r});case`Bracket`:throw new e.C(`Unexpected [ without a function or subscript`);case`FunctionApplication`:return p({kind:`FcnApp`,function:i(t.function),args:t.args.map(i)},{location:r});case`FieldAccess`:return p({kind:`Dot`,expression:i(t.record),field:t.field},{location:r});case`Product`:return p({kind:`Product`,factors:t.factors.map(i)},{location:r});case`Always`:case`Eventually`:{let e=t.expression;return t.kind===`Always`&&e.kind===`BoxAction`?p({kind:`Tsub`,modal:`Box`,action:i(e.action),subscript:i(e.subscript)},{location:r}):t.kind===`Eventually`&&e.kind===`AngleAction`?p({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 p({kind:`Sub`,modal:t.kind===`BoxAction`?`Box`:`Dia`,action:i(t.action),subscript:i(t.subscript)},{location:r});case`WeakFairness`:case`StrongFairness`:return p({kind:`Fair`,fairness:t.kind===`WeakFairness`?`Weak`:`Strong`,subscript:i(t.subscript),action:i(t.action)},{location:r});case`Label`:return p({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.C(`Unexpected subexpression reference`);let o=p({kind:`Opaque`,name:n.name},{location:r}),s=n.args.length===0?o:p({kind:`Apply`,operator:o,args:n.args.map(i)},{location:r});return p({kind:`Bang`,expression:s,selectors:a.map(e=>{switch(e.kind){case`Name`:return{kind:`Label`,label:bi(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})}}},x=e=>({location:o(e.definitionRange??e.instanceRange),args:e.params.map(e=>e.name),module:e.module,substitutions:e.substitutions.map(e=>({name:bi(e.name),expression:b(e.expression,!1)}))}),S=(t,n=!1)=>{let r=f(t.location);if(t.kind===`Instance`){if(t.name===void 0)throw new e.C(`Unexpected keyword INSTANCE`);return{kind:`Instance`,name:t.name,instance:x(t),location:r}}let i=t.kind===`Operator`&&t.params.length===1&&t.name===`-`?`-.`:bi(t.name),o=b(t.body,n);if(t.kind===`Function`&&y(t.bounds))return{kind:`Operator`,name:i,body:v(vi(_(t.bounds,n),o),r),location:r};if(t.kind===`Function`){let e=g(t.bounds,n);return{kind:`Operator`,name:i,body:p({kind:`Fcn`,bounds:e,body:o},{location:r}),location:r}}let s=t.params.length===0?o:p({kind:`Lambda`,params:t.params.map(e=>({name:bi(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&&ri(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}},C=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&&b(e.set,!1),domainVisibility:`Visible`,location:t}},w=e=>e.kind===`AssumeProve`?{context:e.assumptions.map(e=>{if(e.kind===`NewSymbol`)return C(e);let t=e.kind===`AssumeProve`?p({kind:`Sequent`,sequent:w(e)},{location:f(e.location)}):ee(e);return{kind:`Fact`,expression:t,visibility:`Visible`,time:`Now`,location:t.location}}),active:b(e.conclusion,!1)}:{context:[],active:b(e,!1)},ee=e=>{if(e.kind!==`Label`||e.params.length>0)return b(e,!1);let t=f(e.location);return p({kind:`Parens`,expression:b(e.body,!1),form:{kind:`Xlabel`,label:e.name,indices:[]}},{location:t})},te=t=>{if(t.kind===`ModuleFact`)throw new e.k(`MODULE facts in proof obligations are not supported`);let n=b(t,!1);return n.kind===`Bang`&&n.selectors.length===0?n.expression:n},ne=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:bi(t.name),location:n};if(t.kind===`OperatorReference`)return{kind:`Dvar`,name:bi(t.operator),location:n};throw new e.k(`This DEF clause in proof obligations is not supported`)},re=e=>({facts:e.facts.map(te),defs:e.defs.map(ne)}),T=(e,t)=>e?.[2]?{kind:`Named`,level:t,label:e[2],isAnonymous:!1}:{kind:`Unnamed`,level:t,id:$e(r)},ie=(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:re(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=>xi.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,T(n[t],i),i)),s=e.steps[e.steps.length-1],c=T(n[n.length-1],i),l=o(s.head),u=ie(s.proof,i+1,l),d={proof:u,location:Si(l,u.location),step:c};return{kind:`Steps`,steps:a,qed:d,location:a.reduce((e,t)=>Si(e,t.location),d.location),step:d.step}}}},ae=e=>Si(o(e.keyword),e.defs.length>0?f(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=ie(t.proof,r+1,i);return{...e(a),location:Si(i,a.location),step:n}},u=e=>({...e,...l(t.head),step:n});switch(a.kind){case`Use`:case`Hide`:{let e=Si(o({...t.head,end:t.head.start}),ae(a)),r=re(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.C(`Unexpected keyword INSTANCE`);case`Define`:return{kind:`Define`,definitions:a.definitions.map(e=>S(e)),location:i,step:n};case`Have`:return u({kind:`Have`,expression:b(a.expression,!1)});case`Take`:return u({kind:`Take`,bounds:a.names.length>0?si(a.names):g(a.bounds,!1)});case`Witness`:return u({kind:`Witness`,expressions:a.expressions.map(e=>b(e,!1))});case`Pick`:{let e=a.names.length>0?si(a.names):g(a.bounds,!1),t=b(a.body,!1);return s(n=>({kind:`Pick`,bounds:e,expression:t,proof:n}))}case`Case`:{let e=b(a.expression,!1);return s(t=>({kind:`Pcase`,expression:e,proof:t}))}case`Assert`:{let e=w(a.statement);return s(t=>a.isSuffices?{kind:`Suffices`,sequent:e,proof:t}:{kind:`Assert`,sequent:e,proof:t})}case`Qed`:throw new e.k(`QED in the middle of a proof`)}},oe=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:bi(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:S(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:x(t),isLocal:t.isLocal,location:n}:{kind:`Definition`,definition:S(t),whereDefined:`User`,visibility:`Hidden`,isLocal:t.isLocal,location:o(t.instanceRange)}}case`Assumption`:return{kind:`Axiom`,name:e.assumption.name,expression:u(b(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=w(t.statement);return{kind:`Theorem`,name:t.name,sequent:{...i,active:u(i.active,t.statement.location.range)},axiomCount:0,proof:ie(t.proof,0,{...r,startLine:r.endLine,startColumn:r.endColumn}),location:n}}case`Use`:return{kind:`Mutate`,mode:e.use.kind,isSuppressed:!1,usable:re(e.use),location:ae(e.use)};case`Module`:return{kind:`Submod`,module:{...oe(e.module),isImportant:!0}}}})});return{convertModule:oe}},Pi={start:0,end:1/0},Fi=/-{4,} *MODULE/,Ii=`Unexpected EOF`,Li=e=>e?`${e.startLine}:${e.startColumn}:${e.endLine}:${e.endColumn}`:``,Ri=e=>{let n=t.nt(e),r=e.split(`
22
+ `),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(Fi));if(o===-1||o>=a)return;let s=e.slice(0,o).split(`
23
+ `).length,c=o-e.lastIndexOf(`
24
+ `,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:Ii,line:l?.line??s,column:l?l.endColumn+1:c,isEnd:!0}}},zi=t=>{try{return t()}catch(t){if(!(t instanceof e.D)||!t.failure)throw t;return t.failure}},Bi=e=>typeof e==`object`&&!!e&&`reason`in e,Vi=e=>{let n=zi(()=>Ri(e));if(Bi(n))return[n];let r=zi(()=>t.A(n?e.slice(0,n.offset):e));return n&&(!Bi(r)||r.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:n.line,column:n.column,isEnd:!1},Bi(r)&&r.reason===Ii?r:n.end]:Bi(r)?[r]:r},Hi=(t,n,r,i,a)=>{if(!Fi.test(t.source))throw new e.C(`No tokens in file`);let o=Vi(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.C(n,{failure:`Module.Parser.parse_file`})}let s=Ni(t.file,t.source,n,r).convertModule(o),l=t.file.slice(t.file.lastIndexOf(`/`)+1),u=l.replace(/\.tla$/,``);return s.name===u?s:(i({text:`${c(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(l)}.`,channel:`toolbox`}),{...s,name:u})},Ui=t=>{let n=new Map([...t].map(([e,t])=>[e,Ar(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.C(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(Mr).forEach(a),i},Wi=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${i(t)}`)],Gi=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?i({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...Wi(`missing`,e.absent,t),...Wi(`omitted`,e.omitted,n),` ====`]},Ki=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...Gi(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(`
25
+ `)},qi=(t,n,r={})=>{let i=r.lines??Pi,a=r.onWarning??(()=>{}),c={value:0},l=new Map(wr);t.forEach(e=>{let t={...Hi(e,c,!0,a,`File "<unknown>":
26
+ `),isImportant:!0};l.set(t.name,t)});let u=[...l.values()].sort((e,t)=>Mr(e.name,t.name)),d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<u.length;e++){let t=Ar(u[e]);t.submodules.forEach((e,t)=>{f.add(t),l.has(t)||l.set(t,e)});for(let e of t.dependencies){if(l.has(e)&&!wr.has(e))continue;let r=n(e);if(!r){!l.has(e)&&!d.has(e)&&d.set(e,t.locations.get(e));continue}let i=Hi(r,c,!1,a,o(t.locations.get(e)));l.set(e,i),u.push(i)}}let p=[...d.keys()].filter(e=>!f.has(e)).sort(Mr);if(p.forEach(e=>a(s(d.get(e),`Unknown module ${JSON.stringify(e)}`))),p.length>0)throw new e.C(`Unknown module ${JSON.stringify(p[0])}`,{failure:`Module.Parser.load_module`});let m={anonymizer:rt(c,(e,t)=>qr(m,e,t),a),generator:An(c,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},h=Ui(l).map(e=>e.isStandard?e:kr(l,e,/* @__PURE__ */ new Set)),g=new Map(h.map(e=>[e.name,e]));return h.flatMap(e=>{if(e.isStandard)return[];let t=Jr(m,g,void 0,e);if(!e.isImportant)return[];let n=Yr(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:`${an(e.sequent)}\n`;return[{id:t+1,location:Li(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}]})},Ji=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);if(i.delete(t),a.push(t),`verdict`in r&&o?.resolve(r),`error`in r){let t=r.error.name===`TlaProverError`?e.w:e.k;o?.reject(new t(r.error.message))}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.r(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}},Yi={"!":`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_`},Xi=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(` `)),Zi=e=>/^[A-Za-z]$/.test(e),Qi=t=>{if(/^[A-Za-z0-9]$/.test(t))return;let n=Yi[t];if(n===void 0)throw new e.j;return n},$i=e=>{let t=[...e];return Zi(t[0]??``)&&Zi(t.at(-1)??``)&&t.every(e=>Qi(e)===void 0)&&!Xi.has(e)?e:`a_${t.map(e=>Qi(e)??e).join(``)}a`},ea=e=>`is${$i(e)}`,ta={TRUE:`TRUE`,FALSE:`FALSE`,STRING:`STRING`,BOOLEAN:`BOOLEAN`,Nat:`Nat`,Int:`Int`,Real:ea(`Real`),Infinity:ea(`Infinity`),Any:`Any`},na={Neg:`~`,DOMAIN:`DOMAIN`,SUBSET:`SUBSET`,UNION:`UNION`},ra={Implies:`\\<Rightarrow>`,Equiv:`\\<Leftrightarrow>`,Conj:`\\<and>`,Disj:`\\<or>`,Eq:`=`,Neq:`\\<noteq>`,Subseteq:`\\<subseteq>`,Mem:`\\<in>`,Notmem:`\\<notin>`,Setminus:`\\\\`,Cap:`\\<inter>`,Cup:`\\<union>`,OneArg:`:>`,Extend:`@@`},ia={Plus:[`addint`,2],Minus:[`subint`,2],Uminus:[`minus`,1],Times:[`mult`,2],Ratio:[ea(`/`),2],Quotient:[ea(`\\div`),2],Remainder:[ea(`%`),2],Exp:[ea(`^`),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:[ea(`\\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]},aa={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},oa=[`consts`,...[[`Real`,0],[`/`,2],[`\\div`,2],[`%`,2],[`..`,2],[`Infinity`,0],[`[]`,1],[`<>`,1]].map(e=>` "${ea(e[0])}" :: ${e[1]===0?`c`:`"[${Array(e[1]).fill(`c`).join(`,`)}] => c"`}`),``].join(`
27
+ `),sa=e=>{let t=Number.parseInt(e,10);return`${`succ[`.repeat(t)}0${`]`.repeat(t)}`},ca=(e,t)=>[`(* automatically generated -- do not edit manually *)`,`theory ${e} imports Constant Zenon begin`,...t?[`ML_command \\<open> writeln ("*** TLAPS PARSED\\n"); \\<close>`]:[],oa],la=t=>{let n=Pt(),r=e=>It(n,$i(e)),i=()=>It(n,``),a={isAssumed:!1},o=(e,t)=>{let i=t(r(e));return Lt(n,1),i},s=e=>`(${m(e)})`,c=e=>e.map(s).join(`, `),l=(e,t)=>`(${e} (${c(t)}))`,u=(t,n)=>{let r=ta[t];if(r!==void 0&&n.length===0)return r;let i=na[t];if(i!==void 0&&n.length===1)return`(${i} ${s(n[0])})`;let a=ra[t];if(a!==void 0&&n.length===2)return`(${s(n[0])} ${a} ${s(n[1])})`;let o=ia[t];if(o&&o[1]===n.length)return l(o[0],n);if(t===`Unprimable`&&n.length===1)return s(n[0]);if(t===`Irregular`&&n.length===1)throw new e.k(`Irregular`);if((t===`Prime`||t===`StrongPrime`||t===`UNCHANGED`)&&n.length===1)throw new e.j;let c=aa[t];throw c&&c[1]===n.length?new e.w(`Unsupported operator \`${c[0]}\`.\n`):new e.w(`Backend.Isabelle.pp_apply`)},d=(t,i)=>{switch(t.kind){case`Ix`:{let r=Ft(n,t.index);if(t.index<=0||r===void 0)throw new e.j;return i.length===0?r:`(${r} (${c(i)}))`}case`Opaque`:{let e=$i(t.name);return i.length===0?`(${e} :: c)`:`(${e} (${c(i)}) :: c)`}case`Internal`:return u(t.builtin,i);case`Lambda`:{let e=`\\<lambda> ${t.params.map(e=>`${r(e.name)} `).join(``)}. ${s(t.body)}`;return Lt(n,t.params.length),e}default:throw new e.j}},f=(t,n,r)=>{if(n.length===0)return m(r);let i=n[0],a=n.slice(1),c=a[0]?.domain.kind===`Ditto`?[{...a[0],domain:i.domain},...a.slice(1)]:a,l=c.length===0?r:{kind:`Quant`,quantifier:t,bounds:c.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:O(1,e.domain.expression)}}:e),body:r,location:r.location},u=t===`Forall`?`\\<forall>`:`\\<exists>`;if(i.domain.kind===`NoDomain`)return o(i.name,e=>`${u}${e} : ${s(l)}`);if(i.domain.kind!==`Domain`)throw new e.j;let d=s(i.domain.expression);return o(i.name,e=>`${u} ${e} \\<in> ${d} : ${s(l)}`)},p=t=>{if(t.context.length===0)return s(t.active);let r=t.context[0],a=()=>p({context:t.context.slice(1),active:t.active});switch(r.kind){case`Flex`:return o(r.name,e=>`(\\<And> ${e} ${e}'.${a()})`);case`Fresh`:{if(r.domain&&r.domainVisibility===`Visible`){let e=s(r.domain);return o(r.name,t=>`(\\<And> ${t} :: c. ${t} \\<in> ${e} \\<Longrightarrow> ${a()})`)}let e=`${`c => `.repeat(r.shape)}c`;return o(r.name,t=>`(\\<And> ${t} :: ${e}. ${a()})`)}case`Fact`:{let e=r.visibility===`Visible`?s(r.expression):void 0;i();let t=e?`(${e} \\<Longrightarrow> ${a()})`:a();return Lt(n,1),t}case`Defn`:throw new e.k(`Inner definition`)}},m=t=>{switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return d(t,[]);case`Apply`:return d(t.operator,t.args);case`Bang`:throw new e.w(`Backend.Isabelle.module`);case`Sequent`:return p(t.sequent);case`With`:case`Parens`:return m(t.expression);case`Let`:throw new e.k(`LET`);case`List`:return t.bullet===`Refs`&&t.items.length===0?`TRUE`:t.bullet===`Refs`&&t.items.length===1?m(t.items[0]):t.items.map(s).join(t.bullet===`Or`?` | `:` & `);case`If`:return`cond(${s(t.condition)}, ${s(t.consequent)}, ${s(t.alternative)})`;case`Quant`:return f(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.k(t.quantifier===`Forall`?`\\\\AA`:`\\\\EE`);case`Choose`:{if(!t.domain)return o(t.name,e=>`Choice(%${e}. ${s(t.body)})`);let e=s(t.domain);return o(t.name,n=>`bChoice(${e}, %${n}. ${s(t.body)})`)}case`SetSt`:{let e=s(t.domain);return o(t.name,n=>`subsetOf(${e}, %${n}. ${s(t.body)})`)}case`SetOf`:{if(t.bounds.length===0)throw new e.j;let n=t.bounds[0];if(t.bounds.length!==1||n.domain.kind!==`Domain`)throw new e.k(`SetOf (multiple declared constants)`);let r=s(n.domain.expression);return o(n.name,e=>`setOfAll(${r}, %${e}. ${s(t.element)})`)}case`SetEnum`:return`{${c(t.elements)}}`;case`Fcn`:{let n=t.bounds[0];if(t.bounds.length!==1)throw new e.k(`function (multiple declared constants)`);if(n.domain.kind===`Ditto`)throw new e.j;let r=n.domain.kind===`Domain`?s(n.domain.expression):void 0;return o(n.name,e=>`[${r===void 0?e:` ${e} \\<in> ${r} `} \\<mapsto> ${s(t.body)}]`)}case`FcnApp`:{let e=s(t.function);return t.args.length===1?`fapply (${e}, ${s(t.args[0])})`:`fapply (${e}, <<${c(t.args)}>>)`}case`Arrow`:return`[${s(t.domain)} \\<rightarrow> ${s(t.range)}]`;case`Rect`:return`[${t.fields.map(e=>`''${e.name}'' : ${s(e.value)}`).join(`, `)}]`;case`Record`:return`(${t.fields.map(e=>`(''${e.name}'' :> ${s(e.value)})`).join(` @@ `)})`;case`Except`:{let e=t.specs.map(e=>`!${e.trail.map(e=>e.kind===`Dot`?`[''${e.field}'']`:`[${s(e.expression)}]`).join(``)} = ${s(e.value)}`);return`[${s(t.function)} EXCEPT ${e.join(`, `)}]`}case`Dot`:return`fapply (${s(t.expression)}, (''${t.field}''))`;case`Tuple`:return`<<${c(t.elements)}>>`;case`Product`:return t.factors.length===2?`(${s(t.factors[0])} \\<times> ${s(t.factors[1])})`:`Product(\\<langle>${c(t.factors)}\\<rangle>)`;case`Sub`:case`Tsub`:{let e=t.kind===`Sub`?`sub`:`tsub`;return`${t.modal===`Box`?ea(`a'box'${e}`):`a'dia'${e}`}(${s(t.action)},${s(t.subscript)})`}case`Fair`:return`${ea(t.fairness===`Weak`?`a'wf`:`a'sf`)}(${s(t.subscript)},${s(t.action)})`;case`Case`:{let e=c(t.arms.map(e=>e.condition)),n=c(t.arms.map(e=>e.body));return t.other?`CaseOther(<<${e}>>,<<${n}>>,${s(t.other)})`:`Case(<<${e}>>,<<${n}>>)`}case`String`:return`''${t.value}''`;case`Num`:if(t.fraction!==``)throw new e.k(`real constants`);return`(${sa(t.integer)})`;case`At`:throw new e.j}},h=t=>{let r=n.stack.length;try{return s(t)}catch(t){if(!(t instanceof e.k))throw t;return Lt(n,n.stack.length-r),t}},g=t=>{let o=[];for(let c of t.context)switch(c.kind){case`Flex`:{let e=r(c.name);o.push(`fixes ${e} ${e}'`);break}case`Fresh`:{let e=c.domain&&c.domainVisibility===`Visible`?s(c.domain):void 0,t=r(c.name);if(o.push(`fixes ${t}`),e===void 0)break;a.isAssumed=!0,o.push(`assumes ${t}_in : "(${t} \\<in> ${e})"`);break}case`Fact`:{let t=n.stack.length,r=c.visibility===`Visible`?h(c.expression):void 0;if(i(),r instanceof e.k){o.push(`(* omitted temporal assumption : ${r.message} *)`);break}if(r===void 0)break;a.isAssumed=!0,o.push(`assumes v'${t}: "${r}"`);break}case`Defn`:if(c.definition.kind===`Bpragma`)return o.map(e=>`${e}\n`).join(``);o.push(`(* usable definition ${c.definition.name} suppressed *)`),r(c.definition.name)}return[...o,`shows "${s(t.active)}"`].join(`
28
+ `)};try{return{text:g(t),isAssumed:a.isAssumed}}catch(t){throw t instanceof e.k?new e.w(`isabelle : unsupported operator ${t.message}`):t}},ua=(e,t,n,r)=>{let i=la(t);return[...ca(r,!1),`lemma ob'${e}:`,`${i.text}(is "PROP ?ob'${e}")`,`proof -`,`show "PROP ?ob'${e}"`,`${i.isAssumed?`using assms `:``}by ${n}`,`qed`,`end`,``].join(`
29
+ `)},da=(e,t)=>[...ca(e,!0),...t.flatMap(e=>[`lemma ob'${e.id}:`,`${la(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(`
30
+ `),fa=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],pa=Array.from({length:64},(e,t)=>Math.floor(Math.abs(Math.sin(t+1))*2**32)),ma=(e,t)=>e<<t|e>>>32-t,ha=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,r,o,s]=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+pa[o]+t[l]|0;return[i,n+ma(u,fa[s*4+o%4])|0,n,r]},a);a.splice(0,4,a[0]+n|0,a[1]+r|0,a[2]+o|0,a[3]+s|0)}return a.flatMap(e=>[e,e>>>8,e>>>16,e>>>24]).map(e=>(e&255).toString(16).padStart(2,`0`)).join(``)},ga=(t,n)=>{let r=x(t,n-1)?.hyp;if(!r)throw new e.j;return r},_a=(e,t)=>z(e,t).level,va=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),ya=(e,t)=>{let n=C(void 0,(n,r)=>{let i=ge(r,t=>e(n,t),t);return[_(n,i),i]});return(t,r)=>{let i=n(t,r.context);return{context:i.context,active:e(i.state,r.active)}}},ba=(e,t)=>{if(t.kind===`Sub`||t.kind===`Tsub`){let n=ba(e,t.action),r=ba(e,t.subscript),i=h(`UNCHANGED`,[r],t),a=t.modal===`Box`?h(`Disj`,[n,i],t):h(`Conj`,[n,h(`Neg`,[i],t)],t);return t.kind===`Sub`?a:h(t.modal===`Box`?`BoxTrue`:`Diamond`,[a],t)}return N(e,t,ba,_,`all`)},xa=(e,t)=>t.kind===`Apply`&&va(t,[`UNCHANGED`])&&t.args.length===1?rr(t.args[0]):N(e,t,xa,_,`all`),Sa=(e,t)=>h(e,[t],t),Ca=(t,n)=>{if(n.kind===`Ix`){let e=ga(t,n.index);return e.kind===`Fresh`&&e.level===`Constant`||e.kind===`Defn`&&e.definition.kind===`Operator`&&_a(x(t,n.index),e.definition.body)===0?n:Sa(`Prime`,n)}if(va(n,[`ENABLED`])||n.kind===`Opaque`||n.kind===`Sequent`||n.kind===`Let`)return Sa(`Prime`,n);if(va(n,[`UNCHANGED`,`Cdot`,`Leadsto`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`])||n.kind===`Tquant`||n.kind===`Sub`||n.kind===`Tsub`||n.kind===`Fair`)throw new e.j;return N(t,n,Ca,_)},wa=e=>{let t=e===`BoxTrue`?`Conj`:`Disj`,n=e===`BoxTrue`?`Forall`:`Exists`,r=(i,a)=>_a(i,a)===0?a:va(a,[t])||(a.kind===`Quant`||a.kind===`Tquant`)&&a.quantifier===n?N(i,a,r,_):Sa(e,a);return r},Ta={Prime:Ca,BoxTrue:wa(`BoxTrue`),Diamond:wa(`Diamond`)},Ea=(t,n)=>{if(n.kind===`Apply`&&n.operator.kind===`Internal`){let r=Ta[n.operator.builtin];if(r){if(n.args.length!==1)throw new e.j;return r(t,n.args[0])}}return N(t,n,Ea,_,`all`)},Da=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],Oa={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},ka=(e,t)=>`${e}_${t}_`,Aa=(t,n,r)=>{if(n.kind!==`Operator`)return n.kind===`Bpragma`?{...n,body:V(t,n.body)}:n;let i=V(t,n.body),a=Da[r??_a(t,i)];if(a===void 0)throw new e.j;return{...n,name:ka(a,n.name),body:i}},ja=(e,t,n)=>{switch(t.kind){case`Fresh`:return{...t,name:ka(Oa[t.level],t.name),domain:t.domain&&V(e,t.domain)};case`Flex`:return{...t,name:ka(`VARIABLE`,t.name)};case`Defn`:return{...t,definition:Aa(e,t.definition,n)};case`Fact`:return{...t,expression:V(e,t.expression)}}},Ma=(e,t)=>{if(t.kind!==`Defn`||t.definition.kind!==`Operator`)return;let n=t=>{if(!va(t,[`UNCHANGED`])||t.kind!==`Apply`)return _a(e,t);let n=e=>e.kind===`Tuple`?e.elements.flatMap(n):[e],r=n(t.args[0]);return _a(e,r.length===1?r[0]:t.args[0])},r=t.definition.body;return n(va(r,[`Prime`,`BoxTrue`,`Diamond`])&&r.kind===`Apply`&&r.args.length===1&&r.kind===`Apply`?r.args[0]:r)},Na=C({scope:void 0,original:void 0},(e,t,n)=>{let r=ja(e.scope,t,Ma(e.original,n));return[{scope:_(e.scope,r),original:_(e.original,n)},r]}),Pa=(e,t)=>{let n=Na(t.context,e.context);return{context:n.context,active:V(n.state.scope,e.active)}},Fa=(e,t)=>{let[n,r]=S(e,t.context,(e,t)=>{let n=ja(e,t);return[_(e,n),n]});return{context:r,active:V(n,t.active)}},V=(e,t)=>{switch(t.kind){case`Lambda`:{let n=t.params.map(e=>({...e,name:ka(`Unknown`,e.name)})),r=v(e,n.map(e=>w(e.name,`Unknown`,e.shape)));return{...t,params:n,body:V(r,t.body)}}case`Tquant`:{let n=v(e,t.names.map(e=>({kind:`Flex`,name:ka(`VARIABLE`,e)})));return{...t,body:V(n,t.body)}}case`Choose`:{let n=t.domain&&V(e,t.domain),r=ka(`CONSTANT`,t.name),i=n?ee(r,n):w(r,`Constant`);return{...t,name:r,domain:n,body:V(_(e,i),t.body)}}case`SetSt`:{let n=V(e,t.domain),r=ka(`CONSTANT`,t.name),i=V(_(e,ee(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:ka(Oa[t.level],t.name),domain:t.domain.kind===`Domain`?{kind:`Domain`,expression:V(e,t.domain.expression)}:t.domain})),r=v(e,n.map(e=>w(e.name,e.level)));return t.kind===`SetOf`?{...t,bounds:n,element:V(r,t.element)}:{...t,bounds:n,body:V(r,t.body)}}case`Let`:{let[n,r]=S(e,t.definitions,(e,t)=>{let n=Aa(e,t);return[_(e,{kind:`Defn`,definition:n,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),n]});return{...t,definitions:r,body:V(n,t.body)}}case`Sequent`:return{...t,sequent:Fa(e,t.sequent)};default:return N(e,t,V,_,`all`)}},Ia=/* @__PURE__ */ new WeakMap,La=(e,t)=>{let n=Ia.get(t);if(n)return n;let r=t.kind===`Operator`?t.body:void 0;if(r?.kind!==`Lambda`)return[];let i=v(e,r.params.map(e=>w(e.name,`Unknown`,e.shape))),a=r.params.map((e,t)=>Ba(i,r.body,t+1,!0));return Ia.set(t,a),a},Ra=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`ENABLED`,`UNCHANGED`],za=[`Leadsto`,`Actplus`,`Cdot`],Ba=(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(Ra.includes(e)&&n.args.length===1||za.includes(e)&&n.args.length===2)return n.args.every(e=>Ba(t,e,r,!1))}if(n.kind===`Sub`)return[n.action,n.subscript].every(e=>Ba(t,e,r,!1));if(n.kind===`Apply`&&n.operator.kind===`Ix`){let i=x(t,n.operator.index-1),a=i?.hyp;if(i&&a?.kind===`Defn`&&a.definition.kind===`Operator`){let o=La(i.rest,a.definition);return n.args.every((n,i)=>{let a=o[i];if(a===void 0)throw new e.j;return Ba(t,n,r,a)})}}let a={isSubstitutive:!0};return N({scope:t,index:r},n,(e,t)=>(a.isSubstitutive&&=Ba(e.scope,t,e.index,i),t),(e,t)=>({scope:_(e.scope,t),index:e.index+1}),`all`),a.isSubstitutive},Va=(e,t)=>{let n=Mt(nn(y(e),t));return`h${ha(n).slice(0,5)}`},Ha=(e,t)=>p({kind:`Opaque`,name:Va(e,t)},t),Ua=(e,t,n,r,i)=>{let a=i.map((t,r)=>_a(e,t)===0||n[i.length-r-1]?p({kind:`Opaque`,name:`*`},t):t);return Ha(e,p({kind:`Apply`,operator:{kind:`Opaque`,name:t},args:a},r))},Wa=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`Leadsto`,`ENABLED`,`Cdot`,`UNCHANGED`],Ga=(t,n)=>{if(n.kind!==`Apply`)return N(t,n,Ga,_);let r=n.operator,[i]=n.args;if(va(n,[`Prime`,`StrongPrime`])&&n.args.length===1&&i.kind===`Ix`){let e=ga(t,i.index);if(e.kind===`Fresh`||e.kind===`Flex`)return p({kind:`Opaque`,name:`${e.name}#prime`},n)}if(va(n,Wa))return Ha(t,n);if(r.kind!==`Ix`)return N(t,n,Ga,_);let a=x(t,r.index-1),o=a?.hyp;if(!o)throw new e.j;let s=n.args;if(o.kind===`Defn`&&o.definition.kind===`Operator`){let e=La(a.rest,o.definition);if(s.every((n,r)=>_a(t,n)===0||e[s.length-r-1]))return N(t,n,Ga,_);let i=Ua(t,o.definition.name,e,r,s);return p({kind:`Apply`,operator:i,args:s.map(e=>Ga(t,e))},n)}if(o.kind===`Flex`)return N(t,n,Ga,_);if(o.kind===`Fresh`){if(o.level===`Constant`)return p({kind:`Apply`,operator:r,args:s.map(e=>Ga(t,e))},n);let e=s.map(()=>!1);return Ua(t,o.name,e,r,s)}throw new e.j},Ka=ya(ba,`all`),qa=ya(xa,`all`),Ja=ya(Ea,`all`),Ya=ya(Ga,`visible`),Xa=e=>{let t=e.context,n=qa(t,Ka(t,e)),r=Ja(t,n);return Ya(t,Pa(r,e))},Za=e=>C(l(0),(t,n)=>n.kind===`Defn`&&(e&&n.definition.kind===`Bpragma`||n.definition.kind===`Operator`&&n.visibility===`Visible`)?[u(D(t,n.definition.body),t),void 0]:[f(1,t),E(t,n)]),Qa=Za(!0),$a=Za(!1),eo=(e,t=!0)=>{let n=(t?Qa:$a)(e.context);return{context:n.context,active:D(n.state,e.active)}},to=/* @__PURE__ */ new Set([`BoxTrue`,`BoxFalse`,`Diamond`,`Actplus`,`Leadsto`,`Cdot`]),no=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]}},ro=e=>{if(e.kind===`Tsub`||e.kind===`Fair`||e.kind===`Apply`&&e.operator.kind===`Internal`&&to.has(e.operator.builtin))return!1;if(e.kind===`Sequent`){let t=e.sequent;return[...t.context.flatMap(no),t.active].every(ro)}return ve(e).every(ro)},io=t=>{if(t.kind!==`Let`)return _e(t,io);let[n,...r]=t.definitions;if(!n)return io(t.body);if(n.kind!==`Operator`&&n.kind!==`Bpragma`)throw new e.C(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=io(n.body),a={...t,definitions:r};return io(D(u(i,l(0)),a))},ao=(e,t)=>t.kind===`Dot`?p({kind:`Dot`,expression:e,field:t.field},e):p({kind:`FcnApp`,function:e,args:[t.expression]},e),oo=(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&M(e.expression,t.expression),so=(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},co=e=>{if(e.kind!==`Except`)return _e(e,co);let t=e,n=(e,t)=>so(e,t)?.value??ao(e,t),r=(e,n,r)=>{let i=so(e,n);if(e.kind!==`Record`||!i)return p({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 p({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||!oo(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(co(t.function),me(t.specs,co))},lo=C(!0,(e,t)=>[e&&no(t).every(ro),ge(t,io,`all`)]),uo=C(void 0,(e,t)=>[void 0,ge(t,co,`all`)]),fo=e=>{let t=lo(e.context),n=io(e.active);return t.state&&ro(e.active)?{context:uo(e.context,t.context).context,active:co(n)}:{context:t.context,active:n}},po={kind:`Internal`,builtin:`TRUE`},mo=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2?e.args:void 0,ho=e=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`ENABLED`&&e.args.length===1?e.args[0]:void 0,go=(e,t)=>{let n=mo(e,t),r=n&&ho(n[0]),i=n&&ho(n[1]);return r&&i?[r,i]:void 0},_o=(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.j;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=x(t.scope,n.index-1)?.hyp;if(!i)throw new e.j;i.kind===`Flex`&&t.isPrimed&&r.add(i.name)}else s!==`ENABLED`&&N(t,n,i,(e,t)=>({...e,scope:_(e.scope,t)}));return n};return i({scope:t,isPrimed:!1},n),r},vo=(e,t,n)=>{let r=_o(e,t);return[..._o(e,n)].every(e=>!r.has(e))},yo=(t,n)=>{let r=e=>z(t,e).level,i=(t,n)=>{if(r(t)>2||r(n)>2)throw new e.j},a=ho(n),o=a&&mo(a,`Disj`);if(o)return i(o[0],o[1]),{name:`abdisj_inverse`,left:o[0],right:o[1]};let s=go(n,`Disj`);if(s)return i(s[0],s[1]),{name:`abdisj`,left:s[0],right:s[1]};let c=a&&mo(a,`Conj`);if(c){let e=c[0],n=c[1],a=vo(t,e,n);return i(e,n),a?{name:r(e)===2?`abconj_inverse`:`pconj_inverse`,left:e,right:n}:void 0}let l=go(n,`Conj`);if(l)return vo(t,l[0],l[1])?{name:`abconj`,left:l[0],right:l[1]}:void 0;let u=mo(n,`Conj`),d=u&&ho(u[1]);if(u&&d)return r(u[0])<=1&&r(d)<=2?{name:`pconj`,left:u[0],right:d}:void 0;let f=go(n,`Equiv`)??go(n,`Eq`);if(f)return{name:`equiv`,left:f[0],right:f[1]};let p=go(n,`Implies`);return p&&{name:`implies`,left:p[0],right:p[1]}},bo=t=>{let n=v(void 0,t.context),r=yo(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=>M(O(a,e),r.left),c=e=>M(O(a,e),r.right),l=(e,t)=>e!==void 0&&s(e[0])&&c(e[1])&&t.includes(r.name),u=ho(o),d=u&&mo(u,`Conj`),f=mo(o,`Conj`),p=f&&ho(f[1]),m=mo(o,`Mem`),h=m?.[1].kind===`Internal`&&m[1].builtin===`BOOLEAN`;l(d,[`pconj`])||l(u&&mo(u,`Disj`),[`abdisj`])||l(go(o,`Disj`),[`abdisj_inverse`])||l(d,[`abconj`])||l(go(o,`Conj`),[`abconj_inverse`,`pconj_inverse`])||l(f&&p&&[f[0],p],[`pconj_inverse`])?i.isPremise=!0:l(mo(o,`Equiv`),[`equiv`])?(i.isPremise=!0,i.isLeftBoolean=!0,i.isRightBoolean=!0):l(mo(o,`Eq`),[`equiv`])?i.isPremise=!0:m&&h&&s(m[0])?i.isLeftBoolean=!0:m&&h&&c(m[0])?i.isRightBoolean=!0:l(mo(o,`Implies`),[`implies`])&&(i.isPremise=!0)}),!i.isPremise||!i.isLeftBoolean||!i.isRightBoolean)throw new e.w(`ENABLEDaxioms proof directive did not succeed.
31
+ `);return{...t,active:po}},xo={Constant:0,State:1,Action:2,Temporal:3},So=(e,t,n)=>e.every((e,r)=>r<t.length&&n(e,t[r]))&&e.length===t.length,Co=e=>[...new Map(e.toReversed().map(e=>[e.name,e.value]))].toSorted((e,t)=>e[0]<t[0]?-1:1),wo=(t,n)=>{let r=x(t,n-1);if(!r)throw new e.j;let i=r.hyp;if(i.kind===`Fresh`)return{name:i.name,kind:i.level,level:xo[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=z(r.rest,i.definition.body).level;return{name:i.definition.name,kind:`Definition`,level:e}}throw new e.j},To=(e,t)=>v(e,t.map(e=>w(e.name,e.level))),Eo=(e,t)=>v(e,t.map(e=>w(e.name,`Unknown`,e.shape))),Do=(e,t)=>v(e,t.map(e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0}))),Oo=(e,t)=>v(e,t.map(e=>({kind:`Flex`,name:e}))),ko=(t,n,r,i)=>{let a=/* @__PURE__ */ new Map,o=(e,t,n,r)=>{let i=wo(e,n),o=wo(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=xo[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)=>v(e,t.map(e=>w(e,`Unknown`))),s=e=>Co(e.substitutions.map(e=>({name:e.name,value:e.expression})));return So(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)=>So(n,r,(n,r)=>n[0]===r[0]&&p(e,t,n[1],r[1])),l=(e,t,n,r)=>So(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(_(e,n[0]),_(t,r[0]),n.slice(1),r.slice(1)),f=(e,t,n,r)=>!n.domain||!r.domain?!n.domain&&!r.domain&&p(_(e,w(n.name,`Constant`)),_(t,w(r.name,`Constant`)),n.body,r.body):p(e,t,n.domain,r.domain)&&p(_(e,ee(n.name,n.domain)),_(t,ee(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)=>So(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(Eo(t,r.params),Eo(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(v(t,r.sequent.context),v(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.j(`Invalid_argument`);return n}case`With`:return i.kind===`With`&&a(r.expression,i.expression);case`Let`:return i.kind===`Let`&&So(r.definitions,i.definitions,(e,r)=>s(t,n,e,r))&&p(Do(t,r.definitions),Do(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(To(t,r.bounds),To(n,r.bounds),r.body,i.body);case`Tquant`:return i.kind===`Tquant`&&r.quantifier===i.quantifier&&So(r.names,i.names,(e,t)=>e===t)&&p(Oo(t,r.names),Oo(n,i.names),r.body,i.body);case`Choose`:return i.kind===`Choose`&&f(t,n,r,i);case`SetSt`:return i.kind===`SetSt`&&f(t,n,r,i);case`SetOf`:return i.kind===`SetOf`&&p(To(t,r.bounds),To(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(To(t,r.bounds),To(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`:return i.kind===`Rect`&&c(t,n,Co(r.fields),Co(i.fields));case`Record`:return i.kind===`Record`&&c(t,n,Co(r.fields),Co(i.fields));case`Except`:return i.kind===`Except`&&a(r.function,i.function)&&So(r.specs,i.specs,(e,t)=>So(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`:return i.kind===`Sub`&&r.modal===i.modal&&a(r.action,i.action)&&a(r.subscript,i.subscript);case`Tsub`:return i.kind===`Tsub`&&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=y(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.j;return n||(r.kind===`Defn`?r.definition.name:r.name)===t[0]},!1));return m&&g.every(Boolean)},Ao=t=>{let n=v(void 0,t.context);if(!t.context.some((e,r)=>{if(e.kind!==`Fact`||e.visibility!==`Visible`)return!1;let i=x(n,t.context.length-r),a=e.expression;return a.kind===`Sequent`?ko(v(i,a.sequent.context),n,a.sequent.active,t.active):ko(i,n,a,t.active)}))throw new e.w(`LevelComparison proof directive did not succeed.
32
+ `);return{...t,active:{kind:`Internal`,builtin:`TRUE`}}},jo=(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`)?Ao(t):n.has(`enabledaxioms`)?bo(t):t;let s=rt({value:0},()=>{throw new e.j},()=>{}),c={kind:`Sequent`,sequent:t},l=r||i?gr(s,()=>{},void 0,c,{isEnabled:r,isCdot:i,isAutoUse:a}):pr(s,()=>{},void 0,c,{isEnabled:!0,isCdot:!0,isAutoUse:a});if(l.kind!==`Sequent`)throw new e.j;return l.sequent},Mo=/* @__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(`.`),No={And:0,Or:1,Refs:2},Po={Forall:0,Exists:1},Fo={Box:0,Dia:1},Io={Weak:0,Strong:1},Lo={34:`\\"`,92:`\\\\`,10:`\\n`,9:`\\t`,13:`\\r`,8:`\\b`},Ro=e=>`"${[...new TextEncoder().encode(e)].map(e=>Lo[e]??(e<32||e>126?`\\${String(e).padStart(3,`0`)}`:String.fromCharCode(e))).join(``)}"`,zo=e=>e===`BoxTrue`?`$Box`:e===`BoxFalse`?`$FakeBox`:`$${Mo.indexOf(e)}`,Bo=e=>e.level===`Unknown`?`Unknown`:e.level.toUpperCase(),Vo=t=>{let n=[],r=t=>{let r=n[n.length-t];if(!r)throw new e.j;return r},i=e=>n.push({ident:e,isUsed:!1}),a=()=>{let t=n.pop();if(!t)throw new e.j;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.j},l=t=>{if(t.ident.kind!==`HypIndex`)throw new e.j;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.j}case`Opaque`:return n.name;case`Internal`:return zo(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(${No[n.bullet]};${l(n.items)})`;case`Let`:{let t=n.definitions.map(t=>{if(t.kind!==`Operator`&&t.kind!==`Bpragma`)throw new e.j;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(${Po[n.quantifier]};${f(e.entries,n.bounds)}.${e.text})`}case`Tquant`:{let e=p(n.names.length,n.body);return`$Tquant(${Po[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}(${Fo[n.modal]},${a(n.action)},${a(n.subscript)})`;case`Fair`:return`$Fair(${Io[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 Ro(n.value);case`Num`:return`$Num(${n.integer},${n.fraction})`;case`At`:return`$At`;case`Bang`:throw new e.j}},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,_(s,c)),entry:a()});switch(c.kind){case`Fresh`:{if(!c.domain){let e=Bo(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.j;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},${Je(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)},Ho=e=>ha(Vo(e)),Uo=e=>e.domain.kind===`NoDomain`,Wo=e=>{if(e.kind===`List`&&(e.bullet===`And`||e.bullet===`Refs`)){let t=e.items.map(Wo),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=Wo(e.args[0]),n=Wo(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(Uo)){let t=Wo(e.body),n=(t,n)=>p({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]},Go=e=>{let t=[],n=e.context.reduce((e,n)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return t.push(E(e,n)),f(1,e);let r=Wo(n.expression),i=[...r[1]?[r[1]]:[],...r[0]];return i.forEach((r,i)=>t.push({...n,expression:O(i,D(e,r))})),{kind:`Compose`,outer:l(i.length-1),inner:f(1,e)}},l(0));return{context:t,active:D(n,e.active)}},Ko=/* @__PURE__ */ new Set([`expandenabled`,`expandcdot`,`autouse`,`lambdify`,`enabledaxioms`,`levelcomparison`]),qo=[{prover:`smt`,timeLimitMs:5e3},{prover:`zenon`,timeLimitMs:1e4},{prover:`isabelle`,timeLimitMs:3e4,tactic:`auto`}],Jo={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([...Ko].map(e=>[e,{prover:e,seconds:0}]))},Yo=(t,n,r,i)=>{let a=Jo[t];if(!a)throw new e.w(`Unknown prover: ${t}`);if(r!==void 0&&!a.isBudgeted)throw new e.w(`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`}}},Xo=t=>{let n=Number.parseFloat(t.slice(1));if(!/^[rR]./.test(t)||!Number.isFinite(n)||n<=0)throw new e.w(`Invalid SMT budget "${t}"`);return Math.max(1,Math.trunc(Math.min(n*3e6,4294967295)))},Zo=(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.w(`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.w(`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:Xo(o)};if(i?.kind!==`Num`)throw new e.w(`This argument should be a number of seconds`);return{...t,args:a,timeout:Number(`${i.integer}.${i.fraction}`)};default:throw new e.w(`Unknown keyword in proof method definition: ${n.hint}`)}},{args:n});if(r.args.length>0)throw new e.w(`Too many arguments`);if(r.prover===void 0)throw new e.w(`Missing prover name`);return Yo(r.prover,r.timeout,r.rlimit,r.tactic)},Qo=e=>Yo(e.name,e.timeout,void 0,e.tactic),$o=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(Qo(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=>Zo(t,e)))}else if(s?.kind===`Meth`){if(a.kind===`Apply`)throw new e.j;r.methods.push(Qo(s.method))}}),r.methods},es=e=>{let t=e.method===void 0?$o(e.sequent):[Qo(e.method)],n=t.filter(e=>!Ko.has(e.prover));return{frontends:new Set(t.flatMap(e=>Ko.has(e.prover)?[e.prover]:[])),provers:n.length>0?n:qo}},ts=e=>e.active.kind===`Internal`&&e.active.builtin===`TRUE`||e.context.some((t,n)=>t.kind===`Fact`?M(t.expression,O(n-e.context.length,e.active)):t.kind!==`Fresh`||!t.domain?!1:M(h(`Mem`,[{kind:`Ix`,index:1},O(1,t.domain)],{}),O(n+1-e.context.length,e.active))),ns={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},rs=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],is=(e,t)=>{let[n,r]=S(e,t.context,(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return{...t,name:`${ns[t.level]}_${t.name}_`,domain:t.domain&&as(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=as(e,n.body),i=rs[z(e,r).level];return{...t,definition:{...n,name:`${i}_${n.name}_`,body:r}}}case`Fact`:return{...t,expression:as(e,t.expression)}}})();return[_(e,n),n]});return{context:r,active:as(n,t.active)}},as=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:is(e,t.sequent)};let n=N(e,t,as,_,`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:`${ns[e.level]}_${e.name}_`}))};case`Choose`:case`SetSt`:return{...n,name:`CONSTANT_${n.name}_`};default:return n}},os=(e,t)=>{if(t.kind!==`Sequent`)return N(e,t,os,_,`all`);let n={scope:e,substitution:l(0),context:[]},r=e=>{let t=e.kind===`Fact`&&e.visibility===`Visible`&&e.time===`Always`?{...e,expression:h(`BoxTrue`,[e.expression],e.expression)}:e;n.context.push(t),n.scope=_(n.scope,t)};for(let e of t.sequent.context){let t=E(n.substitution,e);if(t.kind===`Fact`){r({...t,expression:os(n.scope,t.expression)}),n.substitution=f(1,n.substitution);continue}if(t.kind!==`Fresh`||!t.domain||e.kind!==`Fresh`||!e.domain){r(t),n.substitution=f(1,n.substitution);continue}let i=os(n.scope,t.domain);r({...t,domain:void 0}),r({kind:`Fact`,expression:h(`Mem`,[p({kind:`Ix`,index:1},i),O(1,i)],i),visibility:t.domainVisibility,time:t.level===`Constant`?Xe(n.scope,e.domain):`Now`,location:t.location}),n.substitution={kind:`Compose`,outer:l(1),inner:f(1,n.substitution)}}let i=D(n.substitution,t.sequent.active);return{...t,sequent:{context:n.context,active:os(n.scope,i)}}},ss={Conj:`&`,Disj:`|`,Implies:`->`,Equiv:`<->`},cs={Neg:`~`,BoxTrue:`always`,BoxFalse:`always`,Diamond:`sometime`,Prime:`next`},ls=e=>{if(e.kind===`Internal`&&e.builtin===`TRUE`)return;if(e.kind===`List`&&e.bullet!==`Or`){let t=e.items.flatMap(e=>ls(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=ls(e.args[0]),n=ls(e.args[1]);return t&&n?{...e,args:[t,n]}:t??n},us=`(cc | ~ cc)`,ds=e=>{let t=(e,n,r=!1)=>{let i=n=>t(e,n);switch(n.kind){case`Internal`:if(n.builtin===`TRUE`)return us;if(n.builtin===`FALSE`)return`(cc & ~ cc)`;break;case`Apply`:{let e=n.operator,t=n.args;if(e.kind!==`Internal`)break;let r=ss[e.builtin];if(r&&t.length===2)return`(${i(t[0])} ${r} ${i(t[1])})`;let a=cs[e.builtin];if(a&&t.length===1)return`(${a} ${i(t[0])})`;break}case`List`:{if(n.items.length===0)return us;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?ls(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`h${ha(Mt(nn(e,n))).slice(0,5)}`},n=as(void 0,{kind:`Sequent`,sequent:e});return`not (${t([],os(void 0,Ve(ze(Be(n)))),!0)})`},fs=(e,t)=>e<t?-1:+(e>t),ps=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return fs(e,t);if(!Array.isArray(e)||!Array.isArray(t))return 0;let n=e.findIndex((e,n)=>n>=t.length||ps(e,t[n])!==0);return n===-1?e.length-t.length:n>=t.length?1:ps(e[n],t[n])},ms={"\\":`backslash_`,"+":`plussign_`,"-":`hyphen_`,"*":`asterisk_`,"/":`slash_`,"%":`percentsign_`,"^":`circumflexaccent_`,"&":`ampersand_`,"@":`atsign_`,"#":`pound_`,$:`dollarsign_`,"(":`leftparenthesis_`,")":`rightparenthesis_`,"|":`verticalbar_`,".":`period_`,":":`colon_`,"?":`questionmark_`,"!":`exclamationmark_`,"<":`lessthansign_`,">":`greaterthansign_`,"=":`equalsign_`," ":`space_`},hs=e=>`smt__${e.replace(/[\\+\-*/%^&@#$()|.:?!<>= ]/g,e=>ms[e]).replaceAll(`_`,`__`)}`,gs=hs(`TLA__`),_s=new Map(Object.entries(ms).map(e=>[e[1],e[0]])),vs=RegExp(`(${[..._s.keys()].join(`|`)})`,`g`),H=e=>hs(`TLA__${e}`),ys=e=>e.startsWith(gs)?e.slice(gs.length).replaceAll(`__`,`_`).replace(vs,e=>_s.get(e)??e):void 0,U=H(`Mem`),bs=H(`SetExtTrigger`),xs=H(`SubsetEq`),Ss=H(`Cup`),Cs=H(`Cap`),ws=H(`SetMinus`),Ts=H(`Subset`),Es=H(`Union`),Ds=H(`Tt_Idv`),Os=H(`Cast_Bool`),ks=H(`BoolSet`),As=H(`StrSet`),js=H(`IntSet`),W=H(`NatSet`),G=H(`Cast_Int`),K=H(`Proj_Int`),Ms=H(`IntLteq`),Ns=H(`IntRange`),q=H(`FunApp`),J=H(`FunDom`),Ps=H(`FunIsafcn`),Fs=H(`FunSet`),Is=H(`FunExcept`),Ls=H(`TrigEq_Set$Idv$`),Rs=H(`IsSetOf`),Y=H(`Seq`),X=H(`Len`),zs=H(`Cat`),Bs=H(`Append`),Vs=H(`Head`),Hs=H(`Tail`),Us=H(`SubSeq`),Ws=H(`Tuple_0`),Gs={Cup:Ss,Cap:Cs,Setminus:ws,SUBSET:Ts,UNION:Es,DOMAIN:J,Plus:H(`IntPlus`),Minus:H(`IntMinus`),Times:H(`IntTimes`),Exp:H(`IntExp`),Quotient:H(`IntQuotient`),Remainder:H(`IntRemainder`),Uminus:H(`IntUminus`),Range:Ns,Seq:Y,Len:X,BSeq:H(`BSeq`),Cat:zs,Append:Bs,Head:Vs,Tail:Hs,SubSeq:Us},Ks=(e,t)=>Array.from({length:t},(t,n)=>`${e}${n+1}`),qs=(e,t=`Idv`)=>e.map(e=>`(${e} ${t})`).join(` `),Z=(e,t,n=[],r=`Idv`)=>e.length===0?t:`(forall (${qs(e,r)}) ${n.length===0?t:`(! ${t} ${n.map(e=>`:pattern (${e.join(` `)})`).join(` `)})`})`,Js=e=>e.length===0?`true`:e.length===1?e[0]:`(and ${e.join(` `)})`,Ys=e=>e.length===0?`false`:e.length===1?e[0]:`(or ${e.join(` `)})`,Q=(e,t)=>t.length===0?e:`(${e} ${t.join(` `)})`,Xs=(e,t,n=`Idv`,r=`Idv`)=>`(declare-fun ${e} (${Array.from({length:t},()=>r).join(` `)}) ${n})`,Zs=(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},Qs=(e,t,n)=>e.replace(/[^\s()]+/g,e=>e===t?n:e),$s=/* @__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(`.`),ec=/* @__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(`.`),tc=[`TIntPlus`,`TIntUminus`,`TIntMinus`,`TIntTimes`,`TIntQuotient`,`TIntRemainder`,`TIntLteq`],$=(e,t,n,r)=>({name:e,args:t,label:r??[e,...t.flat()].join(` `),formula:n}),nc=e=>`${e.name} ${JSON.stringify(e.args)}`,rc=e=>{let t=$s.indexOf(e.name);return t===-1?$s.length+ec.indexOf(e.name):t},ic=(e,t)=>rc(e)-rc(t)||ps(e.args,t.args),ac={IntPlus:[`+`,2],IntMinus:[`-`,2],IntTimes:[`*`,2],IntUminus:[`-`,1],IntQuotient:[`div`,2],IntRemainder:[`mod`,2],IntLteq:[`<=`,2]},oc=e=>{let t=ac[e][0],n=t===`div`||t===`mod`,r=ac[e][1]===1?[`x1`]:n?[`x`,`y`]:[`x1`,`x2`],i=Q(H(e),r.map(e=>`(${G} ${e})`)),a=`(= ${i} ${t===`<=`?`(<= ${r.join(` `)})`:`(${G} (${t} ${r.join(` `)}))`})`;return $(`Typing`,[tc.indexOf(`T${e}`)],Z(r,n?`(=> (> y 0) ${a})`:a,[[i]],`Int`),`Typing T${e}`)},sc=e=>{let t=H(`SetEnum_${e}`),n=Ks(`a`,e),r=Q(t,n),i=$(`EnumDefElim`,[e],Z([...n,`x`],e===0?`(not (${U} x ${r}))`:`(=> (${U} x ${r}) ${Ys(n.map(e=>`(= x ${e})`))})`,[[`(${U} x ${r})`]]));return e===0?[i]:[$(`EnumDefIntro`,[e],Z(n,Js(n.map(e=>`(${U} ${e} ${r})`)),[[r]])),i]},cc=e=>Array.from({length:e},(e,t)=>`(${G} ${t+1})`),lc=e=>e.map(e=>H(`StrLit_${e}`)),uc=(e,t,n,r)=>{let i=Ks(`x`,r.length);return r.map((r,a)=>{let o=`(${Is} ${Q(n,i)} ${r} x)`,s=i.map((e,t)=>t===a?`x`:e);return $(e,[...t,a+1],Z([...i,`x`],`(= ${o} ${Q(n,s)})`,[[o]]))})},dc=e=>uc(`TupExcept`,[e],H(`Tuple_${e}`),cc(e)),fc=e=>uc(`RecExcept`,[e],H(`Record_${e.join(`_`)}`),lc(e)),pc=(e,t)=>{let n=H(`Tuple_${e}`),r=Ks(`x`,e),i=Q(n,r),a=cc(e);return[$(`TupIsafcn`,[e],Z(r,`(${Ps} ${i})`,[[i]])),...e===0?[]:[$(`TupDomDef`,[e],Z(r,`(= (${J} ${i}) ${Q(H(`SetEnum_${e}`),a)})`,[[i]])),$(`TupAppDef`,[e],Z(r,Js(a.map((e,t)=>`(= (${q} ${i} ${e}) ${r[t]})`)),[[i]]))],$(`SeqTupTyping`,[e],Z([`a`,...r],e===0?`(${U} ${i} (${Y} a))`:`(=> ${Js(r.map(e=>`(${U} ${e} a)`))} (${U} ${i} (${Y} a)))`,[[...r.map(e=>`(${U} ${e} a)`),i]])),$(`SeqTupLen`,[e],Z(r,`(= (${X} ${i}) (${G} ${e}))`,[[i]])),...t?dc(e):[]]},mc=(e,t)=>{let n=H(`Record_${e.join(`_`)}`),r=lc(e),i=Ks(`x`,e.length),a=Q(n,i);return[$(`RecIsafcn`,[e],Z(i,`(${Ps} ${a})`,[[a]])),$(`RecDomDef`,[e],Z(i,`(= (${J} ${a}) ${Q(H(`SetEnum_${e.length}`),r)})`,[[a]])),$(`RecAppDef`,[e],Z(i,Js(r.map((e,t)=>`(= (${q} ${a} ${e}) ${i[t]})`)),[[a]])),...t?fc(e):[]]},hc=(e,t,n,r,i,a)=>{let o=Ks(`s`,i.length),s=Ks(`x`,i.length),c=Q(n,o),l=Q(r,s),u=i.map(e=>`(${q} ${a} ${e})`);return[$(`${e}Intro`,t,Z([...o,...s],`(=> ${Js(s.map((e,t)=>`(${U} ${e} ${o[t]})`))} (${U} ${l} ${c}))`,[[l,c]])),$(`${e}Elim`,t,Z([...o,a],`(=> (${U} ${a} ${c}) ${Js([`(= ${a} ${Q(r,u)})`,...u.map((e,t)=>`(${U} ${e} ${o[t]})`)])})`,[[`(${U} ${a} ${c})`]]))]},gc=[`Mem`,`Seq`,`Len`,`FunApp`,`NatSet`,`Cast_Int`,`Proj_Int`],_c=(t,n)=>{let r=(e,t,n)=>({declaration:e,deps:t,axioms:n}),i=H(t),a=(e,t,n,a=`Idv`)=>r(Xs(i,e,a),t,n),o=/^SetEnum_(\d+)$/.exec(t);if(o)return a(Number(o[1]),[`Mem`],sc(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`],`(${bs} a b)`,[[`(${Rs} a)`,`(${Rs} b)`]]))])}if(t.startsWith(`StrLit_`)){let e=t.slice(7),r=n.strings.map(t=>$(`StrLitDistinct`,[e,t],`(distinct ${i} ${H(`StrLit_${t}`)})`));return n.strings.push(e),a(0,[`Mem`,`StrSet`],[$(`StrLitIsstr`,[e],`(${U} ${i} ${As})`),...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`],pc(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`],hc(`Product`,[e],i,H(`Tuple_${e}`),cc(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}`)],mc(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}`)],hc(`RecSet`,[u],i,H(e),lc(u),`r`))}let d=n.anonymous.get(t);if(d!==void 0)return a(d,[],[]);let f=ac[t];if(f)return a(f[1],[`Cast_Int`],[oc(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 (${U} x ${js}) (${U} y ${js}) (or (distinct x (${G} 0)) (${Ms} (${G} 1) y))) (${U} (${i} x y) ${js})) :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)) (= (${U} z x) (${U} z y))) (= x y)) :pattern ((${bs} x y))))`)],`Bool`);case`SubsetEq`:return a(2,[`Mem`],[$(`SubsetEqIntro`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${U} z x) (${U} z y))) (${xs} x y)) :pattern ((${xs} x y))))`),$(`SubsetEqElim`,[],`(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${xs} x y) (${U} z x)) (${U} z y)) :pattern ((${xs} x y) (${U} z x))))`)],`Bool`);case`Union`:return a(1,[`Mem`],[$(`UnionIntro`,[],`(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${U} y a) (${U} x y)) (${U} x (${Es} a))) :pattern ((${U} y a) (${U} x (${Es} a))) :pattern ((${U} x y) (${U} x (${Es} a))) :pattern ((${U} y a) (${U} x y) (${Es} a))))`),$(`UnionElim`,[],`(forall ((a Idv) (x Idv)) (! (=> (${U} x (${Es} a)) (exists ((y Idv)) (and (${U} y a) (${U} x y)))) :pattern ((${U} x (${Es} a)))))`)]);case`Subset`:return a(1,[`Mem`,`SubsetEq`],[$(`SubsetDefAlt`,[],`(forall ((a Idv) (x Idv)) (! (= (${U} x (${Ts} a)) (${xs} x a)) :pattern ((${U} x (${Ts} a))) :pattern ((${xs} x a) (${Ts} 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)) (! (= (${U} x (${i} a b)) ${e.replaceAll(`MEM`,U)}) :pattern ((${U} x (${i} a b))) :pattern ((${U} x a) (${i} a b)) :pattern ((${U} x b) (${i} a b))))`);return t===`Cap`?a(2,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[n,$(`DisjointTrigger`,[],`(forall ((x Idv) (y Idv)) (! (${bs} (${Cs} x y) ${H(`SetEnum_0`)}) :pattern ((${Cs} 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)) (! (= (${U} x ${W}) (and (${U} x ${js}) (${Ms} (${G} 0) x))) :pattern ((${U} x ${W}))))`)]);case`IntRange`:return a(2,[`Mem`,`IntSet`,`IntLteq`],[$(`IntRangeDef`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${U} x (${Ns} a b)) (and (${U} x ${js}) (${Ms} a x) (${Ms} x b))) :pattern ((${U} x (${Ns} a b)))))`)]);case`FunIsafcn`:return a(1,[`Mem`,`FunDom`,`FunFcn`,`FunApp`],[$(`FunExt`,[],`(forall ((f Idv) (g Idv)) (! (=> (and (${Ps} f) (${Ps} g) (= (${J} f) (${J} g)) (forall ((x Idv)) (=> (${U} x (${J} f)) (= (${q} f x) (${q} g x))))) (= f g)) :pattern ((${Ps} f) (${Ps} g))))`)],`Bool`);case`FunSet`:return n.isFunSet=!0,a(2,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunSetIntro`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (and (${Ps} f) (= (${J} f) a) (forall ((x Idv)) (=> (${U} x a) (${U} (${q} f x) b)))) (${U} f (${Fs} a b))) :pattern ((${U} f (${Fs} a b)))))`),$(`FunSetElim1`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (${U} f (${Fs} a b)) (and (${Ps} f) (= (${J} f) a))) :pattern ((${U} f (${Fs} a b)))))`),$(`FunSetElim2`,[],`(forall ((a Idv) (b Idv) (f Idv) (x Idv)) (! (=> (and (${U} f (${Fs} a b)) (${U} x a)) (${U} (${q} f x) b)) :pattern ((${U} f (${Fs} a b)) (${U} x a)) :pattern ((${U} f (${Fs} a b)) (${q} 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=`(${Is} f x y)`;return a(3,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunExceptIsafcn`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (${Ps} ${e}) :pattern (${e})))`),$(`FunExceptDomDef`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (= (${J} ${e}) (${J} f)) :pattern (${e})))`),$(`FunExceptAppDef1`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (=> (${U} x (${J} f)) (= (${q} ${e} x) y)) :pattern (${e})))`),$(`FunExceptAppDef2`,[],`(forall ((f Idv) (x Idv) (y Idv) (z Idv)) (! (=> (${U} z (${J} 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(dc),...n.records.flatMap(fc)])}case`Seq`:return a(1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`Cast_Int`,`Proj_Int`],[$(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${Ps} s) (>= (${K} (${X} s)) 0) (forall ((i Idv)) (= (${U} i (${J} s)) (and (${U} i ${js}) (<= 1 (${K} i)) (<= (${K} i) (${K} (${X} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${K} (${X} s)))) (${U} (${q} s (${G} i)) a)))) (${U} s (${Y} a))) :pattern ((${U} s (${Y} a)))))`),$(`SeqSetElim1`,[],`(forall ((a Idv) (s Idv)) (! (=> (${U} s (${Y} a)) (and (${Ps} s) (${U} (${X} s) ${W}) (= (${J} s) (${Ns} (${G} 1) (${X} s))))) :pattern ((${U} s (${Y} a)))))`,`SetSetElim1`),$(`SeqSetElim2`,[],`(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${U} s (${Y} a)) (<= 1 i) (<= i (${K} (${X} s)))) (${U} (${q} s (${G} i)) a)) :pattern ((${U} s (${Y} a)) (${q} s (${G} i)))))`,`SetSetElim2`)]);case`Len`:return a(1,[`FunDom`,`IntRange`,`Cast_Int`],[$(`SeqLenDef`,[],`(forall ((s Idv) (z Int)) (=> (and (>= z 0) (= (${J} s) (${Ns} (${G} 1) (${G} z)))) (= (${X} s) (${G} z))))`)]);case`BSeq`:return a(1,[],[]);case`Cat`:return a(2,gc,[$(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${U} s (${Y} a)) (${U} t (${Y} a))) (${U} (${zs} s t) (${Y} a))) :pattern ((${U} s (${Y} a)) (${zs} s t)) :pattern ((${U} t (${Y} a)) (${zs} s t))))`),$(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${U} (${X} s) ${W}) (${U} (${X} t) ${W})) (= (${X} (${zs} s t)) (${G} (+ (${K} (${X} s)) (${K} (${X} t)))))) :pattern ((${zs} s t))))`),$(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (${U} (${X} t) ${W}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${zs} s t) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${zs} s t) (${G} i))) :pattern ((${zs} s t) (${q} s (${G} i)))))`),$(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (${U} (${X} t) ${W}) (<= i (+ (${K} (${X} s)) (${K} (${X} t)))) (< (${K} (${X} s)) i)) (= (${q} (${zs} s t) (${G} i)) (${q} t (${G} (- i (${K} (${X} s))))))) :pattern ((${q} (${zs} s t) (${G} i)))))`)]);case`Append`:return a(2,gc,[$(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${U} s (${Y} a)) (${U} x a)) (${U} (${Bs} s x) (${Y} a))) :pattern ((${U} s (${Y} a)) (${Bs} s x))))`),$(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${U} (${X} s) ${W}) (= (${X} (${Bs} s x)) (${G} (+ (${K} (${X} s)) 1)))) :pattern ((${Bs} s x))))`),$(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${Bs} s x) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${Bs} s x) (${G} i))) :pattern ((${Bs} s x) (${q} s (${G} i)))))`),$(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${U} (${X} s) ${W}) (= (${q} (${Bs} s x) (${G} (+ (${K} (${X} s)) 1))) x)) :pattern ((${Bs} s x))))`)]);case`Head`:return a(1,[`FunApp`,`Cast_Int`],[$(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${Vs} s) (${q} s (${G} 1))) :pattern ((${Vs} s))))`)]);case`Tail`:return a(1,gc,[$(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${U} s (${Y} a)) (distinct (${K} (${X} s)) 0)) (${U} (${Hs} s) (${Y} a))) :pattern ((${U} s (${Y} a)) (${Hs} s))))`),$(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${U} (${X} s) ${W}) (distinct (${K} (${X} s)) 0)) (= (${X} (${Hs} s)) (${G} (- (${K} (${X} s)) 1)))) :pattern ((${Hs} s))))`),$(`SeqTailApp`,[],`(forall ((s Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (distinct (${K} (${X} s)) 0) (<= 1 i) (<= i (- (${K} (${X} s)) 1))) (= (${q} (${Hs} s) (${G} i)) (${q} s (${G} (+ i 1))))) :pattern ((${q} (${Hs} s) (${G} i)))))`)]);case`SubSeq`:{let e=`(${Us} s (${G} x) (${G} 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 (${U} s (${Y} a)) (<= 1 x) (<= y (${K} (${X} s))))) (${U} ${e} (${Y} a))) :pattern ((${U} s (${Y} a)) ${e})))`),$(`SeqSubseqLen`,[],`(forall ((s Idv) (x Int) (y Int)) (! (and (=> (<= x (+ y 1)) (= (${X} ${e}) (${G} (- (+ y 1) x)))) (=> (> x (+ y 1)) (= (${X} ${e}) (${G} 0)))) :pattern (${e})))`),$(`SeqSubseqApp`,[],`(forall ((s Idv) (x Int) (y Int) (z Int)) (! (=> (and (<= 1 x) (<= 1 z) (<= z (- (+ y 1) x))) (= (${q} ${e} (${G} z)) (${q} s (${G} (- (+ z x) 1))))) :pattern ((${q} ${e} (${G} z)))))`)])}case`Cast_Int`:return r(Xs(i,1,`Idv`,`Int`),[`Mem`,`IntSet`,`Proj_Int`],[$(`CastInjAlt`,[`Int`],`(forall ((x Int)) (! (= x (${K} (${G} x))) :pattern ((${G} x))))`),$(`TypeGuardIntro`,[`Int`],`(forall ((z Int)) (! (${U} (${G} z) ${js}) :pattern ((${G} z))))`),$(`TypeGuardElim`,[`Int`],`(forall ((x Idv)) (! (=> (${U} x ${js}) (= x (${G} (${K} x)))) :pattern ((${U} x ${js}))))`)]);case`Cast_Bool`:return r(Xs(i,1,`Idv`,`Bool`),[`Mem`,`BoolSet`,`Tt_Idv`],[$(`CastInjAlt`,[`Bool`],`(and (= (${Os} true) ${Ds}) (distinct (${Os} false) ${Ds}))`),$(`TypeGuardIntro`,[`Bool`],`(forall ((z Bool)) (! (${U} (${Os} z) ${ks}) :pattern ((${Os} z))))`),$(`TypeGuardElim`,[`Bool`],`(forall ((x Idv)) (! (=> (${U} x ${ks}) (or (= x (${Os} true)) (= x (${Os} false)))) :pattern ((${U} x ${ks}))))`)]);case`Proj_Int`:return r(Xs(i,1,`Int`),[],[]);case`TrigEq_Set$Idv$`:return a(2,[`SetExtTrigger`],[$(`ExtTrigEqDef`,[`Set$Idv$`],`(forall ((x Idv) (y Idv)) (! (= (${Ls} x y) (= x y)) :pattern ((${Ls} x y))))`),$(`ExtTrigEqTrigger`,[`Idv`],`(forall ((x Idv) (y Idv)) (! (${bs} x y) :pattern ((${Ls} 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`],[oc(`IntLteq`)]);default:if(t.startsWith(`TIntLit_`))return r(void 0,[],[]);throw new e.k(`the symbol ${t}`)}},vc=(e,t,n,r)=>{let i={recordFields:r,strings:[],isFunConstr:!1,isFunSet:!1,isExcept:!1,tuples:[],records:[],anonymous:n},a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=e=>{let t=/* @__PURE__ */ new Set([e]);for(;t.size>0;){let e=[...t].toSorted(fs)[0];if(t.delete(e),a.has(e))continue;let n=_c(e,i);a.set(e,n),n.deps.forEach(e=>t.add(e)),n.axioms.forEach(e=>o.set(nc(e),e))}},c=e=>{let n=e.match(/[()]|[^\s()]+/g)??[],r=[];n.reduce((e,i,a)=>{if(i===`(`)return e+1;if(i===`)`)return r.at(-1)?.depth===e&&c(r.pop()?.text??``),e-1;let o=t.get(i);if(!o){let t=ys(i);return t!==void 0&&s(t),e}return o.kind!==``&&s(o.kind),n[a-1]===`(`?r.push({depth:e,text:o.visit}):c(o.visit),e},0)};return e.forEach(e=>{typeof e==`string`?c(e):`omitted`in e&&c(e.omitted)}),{symbols:a,axioms:o}},yc=(e,t)=>t===0?e:`${e}_${t}`,bc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Set;return{names:t,adjoin:n=>{let r=hs(n),i=(e.get(r)??-1)+1,a=Array.from({length:t.size+1},(e,t)=>i+t).find(e=>!t.has(yc(r,e)))??i;return{base:r,salt:a,name:yc(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)}}}},xc=e=>{let t=bc();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(``)}}},Sc=(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)),Cc=e=>e.length===1?e[0]:h(`Conj`,[e[0],Cc(e.slice(1))],e[0]),wc=(e,t,n)=>e.kind!==`Record`||t.kind!==`Record`||!Sc(e,t)?h(`Eq`,[e,t],n):Cc(e.fields.map(e=>wc(e.value,t.fields.find(t=>t.name===e.name)?.value??e.value,n))),Tc=e=>{let t=_e(e,Tc);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.kind===`Apply`?p(wc(t.args[0],t.args[1],t),t):t},Ec=e=>e.kind===`Record`||e.kind===`Rect`?{...e,fields:e.fields.toSorted((e,t)=>fs(e.name,t.name))}:_e(e,Ec),Dc=(e,t)=>`${e}#${t}`,Oc=e=>Number(e.slice(e.lastIndexOf(`#`)+1)),kc=`?unprimable`,Ac=e=>{let t=e.indexOf(`(${kc} `);if(t===-1)return e;let n=Zs(e,t);return e.slice(0,t)+Ac(e.slice(t+11+2,n))+Ac(e.slice(n+1))},jc=(e,t)=>/\((forall|exists|ite) /.test(e)?void 0:e.replace(/[^\s()]+#(\d+)/g,(e,n)=>Number(n)<t?`#`:`#${Number(n)-t}`),Mc=()=>{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=hs(`${l}_omitted_${e.size}`);return e.set(t,{symbol:t,kind:i,visit:Ac(a),getLines:()=>[]}),t}let u=jc(`${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=hs(f),m={symbol:p,kind:i,visit:Ac(a),getLines:e=>[Xs(p,c),...s(p,e).map(e=>`(assert (! ${Ac(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)}},Nc=`?trigger`,Pc=/* @__PURE__ */ new Set([Es,Ts,Ss,Cs,ws,Ns,Fs,Y]),Fc=e=>{let t=/^\(?([^\s()]+)/.exec(e)?.[1]??``;return Pc.has(t)||/^smt__TLA____(SetEnum__\d+|SetSt__flatnd__\d+|SetOf__\d+__flatnd__\d+|Product__\d+|RecordSet__)/.test(t)},Ic=(e,t)=>{let n=e.indexOf(`(${Nc} `);if(n===-1)return e;let r=n+8+2,i=Zs(e,r)+1,a=Zs(e,i+1)+1,o=t?e.slice(r,i):e.slice(i+1,a);return e.slice(0,n)+o+Ic(e.slice(a+1),t)},Lc=(e,t,n,r)=>{let i=`(${Ls} ${e} ${t})`,a=r?`(distinct ${e} ${t})`:`(= ${e} ${t})`;if(!Fc(e)&&!Fc(t))return a;let o=r?`(not ${i})`:i;return n===(r?`Positive`:`Negative`)?`(${Nc} ${o} ${a})`:o},Rc=(e,t,n,r)=>{let i=Q(e,[`a`,...t]);return[$(`SetStDef`,[],Z([...t,`a`,`x`],`(= (${U} x ${i}) (and (${U} x a) ${Qs(n,r,`x`)}))`,[[`(${U} x ${i})`],[`(${U} x a)`,i]]))]},zc=(e,t,n,r)=>{let i=r.length,a=Ks(`a`,i),o=Ks(`y`,i),s=r.reduce((e,t,n)=>Qs(e,t,o[n]),n),c=Q(e,[...a,...t]),l=o.map((e,t)=>`(${U} ${e} ${a[t]})`),u=i===1?[`a`]:a;return[$(`SetOfIntro`,[i],Z([...t,...a,...o],`(=> ${Js(l)} (${U} ${s} ${c}))`,[[s,c],[c,...l]])),$(`SetOfElim`,[i],Z([...t,...a,`x`],`(=> (${U} x ${c}) (exists (${qs(o)}) ${Js([...l,`(= x ${s})`])}))`,[[`(${U} x ${c})`]])),$(`AssertIsSetOf`,[i],Z([...t,...u],`(${Rs} ${Q(e,[...u,...t])})`,[[Q(e,[...u,...t])]]))]},Bc=(e,t,n,r,i)=>{let a=Q(e,[`a`,...t]),o=Qs(n,r,`x`),s=i.has(nc($(`FunTyping`,[],void 0)))?[$(`FunTyping`,[],Z([...t,`a`,`b`],`(=> (forall ((x Idv)) (=> (${U} x a) (${U} ${o} b))) (${U} ${a} (${Fs} a b)))`,[[a,`(${Fs} a b)`]]))]:[];return[$(`FunConstrIsafcn`,[],Z([...t,`a`],`(${Ps} ${a})`,[[a]])),$(`FunDomDef`,[],Z([...t,`a`],`(= (${J} ${a}) a)`,[[a]])),$(`FunAppDef`,[],Z([...t,`a`,`x`],`(=> (${U} x a) (= (${q} ${a} x) ${o}))`,[[`(${q} ${a} x)`],[`(${U} x a)`,a]])),...s]},Vc=(e,t,n,r)=>[$(`ChooseDef`,[],Z([...t,`x`],`(=> ${Qs(n,r,`x`)} ${Qs(n,r,Q(e,t))})`))],Hc=(e,t,n,r)=>{let i=n=>Q(e,[n,...t]),a=e=>Qs(n,r,e),o=i(`(${Bs} s x)`);return[$(`SeqSelectseqTyping`,[],Z([...t,`a`,`s`],`(=> (${U} s (${Y} a)) (${U} ${i(`s`)} (${Y} a)))`,[[`(${U} s (${Y} a))`,i(`s`)]])),$(`SeqSelectseqLen`,[],Z([...t,`s`],`(=> (${U} (${X} s) ${W}) (<= (${K} (${X} ${i(`s`)})) (${K} (${X} s))))`,[[i(`s`)]])),$(`SeqSelectseqNil`,[],Z(t,`(= ${i(Ws)} ${Ws})`)),$(`SeqSelectseqApp`,[],Z([...t,`s`,`x`],`(=> (${U} x (${J} ${i(`s`)})) ${a(`(${q} ${i(`s`)} x)`)})`,[[`(${q} ${i(`s`)} x)`]])),$(`SeqSelectseqAppend`,[],Z([...t,`s`,`x`],`(and (=> ${a(`x`)} (= ${o} (${Bs} ${i(`s`)} x))) (=> (not ${a(`x`)}) (= ${o} ${i(`s`)})))`,[[o]]))]},Uc=t=>{let n=Mc(),r=n.flatten,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=bc(),s=/* @__PURE__ */ new Map,c=e=>e.isBool?e.text:`(= ${Ic(e.text,!0)} ${Ds})`,l=e=>e.isBool?`(${Os} ${Ic(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.k(`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=>Oc(e)<t).toSorted((e,t)=>Oc(e)-Oc(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(A(e,t,g(n))),y=(e,t,n)=>c(A(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)),x=(t,n,r,i)=>b(t,n,r).map(t=>{if(t===void 0)throw new e.k(`${i} without a domain`);return t}),S=(e,t,n)=>{let r=e.map((e,t)=>Dc(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}}},C=(e,t,n)=>{let r=b(e.bounds,t,n),i=S(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?[]:[`(${U} ${e} ${r[t]})`]);return e.quantifier===`Forall`?`(forall (${qs(i.variables)}) ${o.length===0?a:`(=> ${Js(o)} ${a})`})`:`(exists (${qs(i.variables)}) ${Js([...o,a])})`},w=(e,t,n)=>{let i=v(e.domain,t,n),a=S([e.name],t,g(n)),o=y(e.body,a.env,a.mode),s=m(o,n.depth),c=r(`SetSt`,o,n,e=>Rc(e,s,o,a.variables[0]),s.length+1);return d(Q(c,[i,...s]))},ee=(e,t,n)=>{let i=x(e.bounds,t,n,`a set of values`),a=S(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=>zc(e,s,o,a.variables),c+s.length);return d(Q(l,[...i,...s]))},te=(e,t,n)=>{let i=x(e.bounds,t,n,`a function`),a=i.length===1?i[0]:Q(H(`Product_${i.length}`),i),o=Dc(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}):cc(i.length).reduce((e,t)=>p(e,{kind:`constant`,symbol:`(${q} ${o} ${t})`}),t),l=v(e.body,c,s),u=m(l,n.depth),f=r(`FunFcn`,l,n,(e,t)=>Bc(e,u,l,o,t),u.length+1);return d(Q(f,[a,...u]))},ne=(e,t,n)=>{let i=S([e.name],t,g(n)),a=i.variables[0],o=e.domain&&`(${U} ${a} ${v(e.domain,t,n)})`,s=y(e.body,i.env,i.mode),c=o===void 0?s:Js([o,s]),l=m(c,n.depth),u=r(`Choose`,c,n,e=>Vc(e,l,c,a),l.length);return d(Q(u,l))},T=(e,t,n,r)=>Lc(v(e[0],t,n),v(e[1],t,n),n.polarity,r),ie=(e,t,n)=>{let r=e.kind===`Lambda`&&e.params.length===1?e:void 0,i=S([r?.params[0].name??`x1`],t,g(n));return{body:y(r?.body??{kind:`Apply`,operator:O(1,e),args:[{kind:`Ix`,index:1}]},i.env,i.mode),variable:i.variables[0]}},ae=(t,n,i,a)=>{let o=()=>n.map(e=>v(e,i,a));switch(t){case`Conj`:return u(Js(n.map(e=>y(e,i,a))));case`Disj`:return u(Ys(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(T(n,i,a,!1));case`Neq`:return u(T(n,i,a,!0));case`Mem`:return u(Q(U,o()));case`Notmem`:return u(`(not ${Q(U,o())})`);case`Subseteq`:return u(Q(xs,o()));case`Lteq`:return u(Q(Ms,o()));case`Gteq`:return u(Q(Ms,o().toReversed()));case`Lt`:case`Gt`:{let e=()=>t===`Lt`?o():o().toReversed();return u(`(and ${Q(Ms,e())} (distinct ${e().join(` `)}))`)}case`SelectSeq`:{let e=ie(n[1],i,a),t=m(e.body,a.depth),o=r(`SelectSeq`,e.body,a,n=>Hc(n,t,e.body,e.variable),t.length+1);return d(Q(o,[v(n[0],i,a),...t]))}case`Unprimable`:{let e=A(n[0],i,g(a));return{...e,text:`(${kc} ${e.text})`}}default:{let n=Gs[t];if(n===void 0)throw new e.k(`the operator ${t}`);return d(Q(n,o()))}}},E=(t,n,i,a)=>{switch(t.kind){case`constant`:case`variable`:if(n.length>0)throw new e.k(`an applied ${t.kind}`);return d(t.symbol);case`operator`:if(n.length!==t.arity)throw new e.k(`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.k(`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.k(`an operator argument that isn't a LAMBDA`);return{isFirstOrder:!1,text:t.symbol}}if(n.kind!==`Lambda`)throw new e.k(`an operator argument that isn't a LAMBDA`);let o=S(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.k(t.reason)}},oe=(t,n)=>{if(!t)throw new e.k(`a primed declaration that isn't a variable`);let r=t.binding;return r.kind===`variable`&&r.name===n?r.primed:oe(t.rest,n)},D=(e,t,n,r)=>{if(t.length===0&&e.endsWith(`#prime`))return d(oe(n,e.slice(0,-6)));let a=t.length===0?`Anon_OPAQUE_${e}`:`Anon_${e}`;return i.set(a,t.length),d(Q(H(a),t.map(e=>v(e,n,r))))},k=(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`?H(`StrLit_${o.field}`):v(o.expression,t,n),c=s(),l=i(`(${q} ${e} ${a.length>1?s():c})`,a.slice(1));return`(${Is} ${e} ${c} ${l})`};return i(e,r.trail)},v(e.function,t,n)),se=()=>{t.caseErrors++;let e=`Anon_incomplete_case_error_${t.caseErrors}`;return i.set(e,0),H(e)},ce=(e,t,n)=>{let r=e.arms.map(e=>A(e.body,t,n)),i=e.other?A(e.other,t,n):d(se()),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:`(${G} ${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))}},le=(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.k(`a second-order ASSUME`);let r=Dc(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.k(`a NEW declaration that isn't constant`);let r=n.domain&&v(n.domain,t.env,t.mode),i=S([n.name],t.env,t.mode),a=i.variables[0],o=r&&`(${U} ${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.k(`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))},A=(t,n,r)=>{switch(t.kind){case`Ix`:return E(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(ks);case`STRING`:return d(As);case`Nat`:return d(W);case`Int`:return d(js);default:throw new e.k(`the operator ${t.builtin}`)}case`Apply`:{let i=t.operator;if(i.kind===`Internal`)return ae(i.builtin,t.args,n,r);if(i.kind===`Ix`)return E(f(n,i.index),t.args,n,r);if(i.kind===`Opaque`)return D(i.name,t.args,n,r);if(i.kind===`Lambda`)return A({...re(i,t.args)},n,r);throw new e.k(`an application of ${i.kind}`)}case`Sequent`:return u(le(t.sequent,n,r));case`With`:case`Parens`:return A(t.expression,n,r);case`If`:{let e=y(t.condition,n,r),i=A(t.consequent,n,r),a=A(t.alternative,n,r);if(i.integer!==void 0&&a.integer!==void 0){let t=`(ite ${Ic(e,!0)} ${i.integer} ${a.integer})`;return{isBool:!1,text:`(${G} ${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`?Ys(e):Js(e))}case`Opaque`:return D(t.name,[],n,r);case`Quant`:return u(C(t,n,r));case`Choose`:return ne(t,n,r);case`SetSt`:return w(t,n,r);case`SetOf`:return ee(t,n,r);case`SetEnum`:return d(Q(H(`SetEnum_${t.elements.length}`),t.elements.map(e=>v(e,n,r))));case`Product`:return d(Q(H(`Product_${t.factors.length}`),t.factors.map(e=>v(e,n,r))));case`Tuple`:return d(Q(H(`Tuple_${t.elements.length}`),t.elements.map(e=>v(e,n,r))));case`Fcn`:return te(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(H(`Tuple_${i.length}`),i);return d(`(${q} ${e} ${a})`)}case`Arrow`:return d(Q(Fs,[v(t.domain,n,r),v(t.range,n,r)]));case`Record`:case`Rect`:{let e=t.fields,i=e.map(e=>e.name);a.set(`Record_${i.join(`_`)}`,i),a.set(`RecordSet_${i.join(`_`)}`,i);let o=`${t.kind===`Record`?`Record`:`RecordSet`}_${i.join(`_`)}`;return d(Q(H(o),e.map(e=>v(e.value,n,r))))}case`Except`:return d(k(t,n,r));case`Dot`:return d(`(${q} ${v(t.expression,n,r)} ${H(`StrLit_${t.field}`)})`);case`Case`:return ce(t,n,r);case`String`:return d(H(`StrLit_${t.value}`));case`Num`:if(t.fraction!==``)throw new e.k(`a real number`);return{isBool:!1,text:`(${G} ${BigInt(t.integer)})`,integer:String(BigInt(t.integer))};case`At`:if(r.at===void 0)throw new e.k(`@ outside EXCEPT`);return d(r.at);case`Tquant`:case`Tsub`:case`Fair`:throw new e.k(`a temporal formula`);default:throw new e.k(`the expression ${t.kind}`)}};return{encodeIdv:v,encodeBool:y,push:p,getEntries:e=>[...n.takeIntroduced(),Ac(Ic(e,!1))],getUniqueName:h,flattened:n.flattened,anonymous:i,recordFields:a,declared:s}},Wc={isOmitted:!1,polarity:`Negative`,at:void 0,depth:0},Gc=e=>e.definition.kind===`Bpragma`||e.definition.kind===`Operator`&&e.visibility===`Visible`,Kc=e=>e.kind===`Sequent`&&e.sequent.context.some(e=>e.kind===`Fresh`&&e.shape>0),qc=(e,t)=>e.reduce((e,n)=>{let r=(r,i=[])=>({env:t.push(e.env,r),scope:_(e.scope,n),entries:[...e.entries,...i]});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=Xs(i,n.shape);if(!n.domain||n.domainVisibility===`Hidden`)return r(a,[o]);let s=`(assert (${U} ${i} ${t.encodeIdv(n.domain,e.env,Wc)}))`;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},[Xs(e,0),Xs(i,0)])}case`Defn`:{let e=n.definition;if(Gc(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},[Xs(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},[Xs(o,a.length)])}case`Fact`:{let i={kind:`unsupported`,reason:`a reference to a fact`};if(n.visibility===`Hidden`)return r(i);let a=Kc(n.expression),o=t.getEntries(`(assert ${t.encodeBool(n.expression,e.env,{...Wc,isOmitted:a})})`);return r(i,a?o.map(e=>typeof e==`string`?{omitted:e}:e):o)}}},{env:void 0,scope:void 0,entries:[]}),Jc=(e,t)=>{let n=Ec(Tc({kind:`Sequent`,sequent:e})),r=n.kind===`Sequent`?n.sequent:e,i=Uc(t),a=qc(r.context,i),o=Kc(r.active)?[]:i.getEntries(`(assert (! (not ${i.encodeBool(r.active,a.env,{...Wc,polarity:`Positive`})}) :named |Goal|))`),s=[...a.entries,...o],c=xc(i.declared),l=vc(s,i.flattened,i.anonymous,i.recordFields),u=[...l.symbols].toSorted((e,t)=>fs(e[0],t[0])).flatMap(e=>e[1].declaration===void 0?[]:[e[1].declaration]),d=[...l.axioms.values()].toSorted(ic).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`)&&!Gc(e))?[`(declare-sort Idv 0)`]:[],...p].map(c.resolve).concat(`(check-sat)`,`(exit)`).join(`
33
+ `)},Yc=F(`@ `),Xc={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`},Zc={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]},Qc={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},$c=e=>{let t=Number.parseInt(e,10);return`${`(TLA.fapply TLA.Succ `.repeat(t)}0${`)`.repeat(t)}`},el=(t,n)=>{let r=Pt(),i=e=>It(r,$i(e)),a=()=>It(r,``),o=e=>I(e,m,Yc),s=(e,t)=>F(`(%s %a)`,e,o(t)),c=(e,t,n,a)=>{let o=i(e),s=F(`%a((%s) %a)%s`,t,o,m(n),a);return Lt(r,1),s},l=(t,n)=>{let r=Xc[t];if(r!==void 0&&n.length===0)return P(r);let i=Zc[t];if(i&&i[1]===n.length)return s(i[0],n);if(n.length===2)switch(t){case`Neq`:return F(`(-. %a)`,s(`=`,n));case`Notmem`:return F(`(-. %a)`,s(`TLA.in`,n));case`Minus`:return s(`arith.add`,[n[0],{kind:`Apply`,operator:{kind:`Internal`,builtin:`Uminus`,location:n[1].location},args:[n[1]],location:n[1].location}]);case`Gteq`:return s(`arith.le`,n.toReversed());case`Gt`:return s(`arith.lt`,n.toReversed())}if(t===`Unprimable`&&n.length===1)return m(n[0]);if((t===`Prime`||t===`StrongPrime`||t===`UNCHANGED`)&&n.length===1)throw new e.j;let a=Qc[t];throw a&&a[1]===n.length?new e.w(`Unsupported operator \`${a[0]}\`.\n`):new e.w(`Backend.Zenon.fmt_apply`)},u=(t,n)=>{switch(t.kind){case`Ix`:{let i=Ft(r,t.index);if(t.index<=0||i===void 0)throw new e.j;return n.length===0?P(i):s(i,n)}case`Opaque`:{let e=$i(t.name);return n.length===0?P(e):s(e,n)}case`Internal`:return l(t.builtin,n);case`Lambda`:{let e=t.params.map(e=>F(`%s `,i(e.name))),n=F(`((%a) %a)`,e,m(t.body));return Lt(r,t.params.length),n}default:throw new e.j}},d=(t,n,r)=>{if(n.length===0)return m(r);let i=n[0],a=n.slice(1),o=a[0]?.domain.kind===`Ditto`?[{...a[0],domain:i.domain},...a.slice(1)]:a,s=o.length===0?r:{kind:`Quant`,quantifier:t,bounds:o.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:O(1,e.domain.expression)}}:e),body:r,location:r.location},l=t===`Forall`;if(i.domain.kind===`NoDomain`)return c(i.name,P(l?`(A. `:`(E. `),s,`)`);if(i.domain.kind!==`Domain`)throw new e.j;let u=m(i.domain.expression);return c(i.name,F(`(%s %a `,l?`TLA.bAll`:`TLA.bEx`,u),s,`)`)},f=(t,n,r,i)=>{if(n.length!==1)throw new e.k(`${i} (multiple declared constants)`);let a=n[0];if(a.domain.kind!==`Domain`)throw new e.j;return c(a.name,F(`(%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?F(`(=> %a %a)`,e,o()):o();return Lt(r,1),t}if(n.kind===`Defn`)throw new e.j;let s=n.kind===`Fresh`&&n.domain&&n.domainVisibility===`Visible`?m(n.domain):void 0,c=i(n.name),l=n.kind===`Flex`?F(`(A. ((%s) (A. ((%s') %a))))`,c,c,o()):s?F(`(TLA.bAll %a ((%s) %a))`,s,c,o()):F(`(A. ((%s) %a))`,c,o());return Lt(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 F(`(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.j;return t.bullet===`Refs`&&t.items.length===1?m(t.items[0]):F(`(%s %a)`,t.bullet===`Or`?`\\/`:`/\\`,o(t.items));case`Quant`:return d(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.k(`\\AA or \\EE`);case`Choose`:return t.domain?c(t.name,F(`(TLA.bChoice %a `,m(t.domain)),t.body,`)`):c(t.name,P(`(t. `),t.body,`)`);case`SetSt`:return c(t.name,F(`(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?P(`TLA.emptyset`):[P(`(TLA.set`),t.elements.map(e=>F(` %a`,m(e))),P(`)`)];case`FcnApp`:{let e=m(t.function);return t.args.length===1?F(`(TLA.fapply %a %a)`,e,m(t.args[0])):F(`(TLA.fapply %a (TLA.tuple %a))`,e,o(t.args))}case`Arrow`:return F(`(TLA.FuncSet %a %a)`,m(t.domain),m(t.range));case`Rect`:case`Record`:return[P(t.kind===`Rect`?`(TLA.recordset`:`(TLA.record`),t.fields.map(e=>F(` "%s" %a`,e.name,m(e.value))),P(`)`)];case`Except`:{let n=t.specs[0];if(t.specs.length!==1||n.trail.length!==1)throw new e.k(`complex EXCEPT`);let r=n.trail[0],i=r.kind===`Dot`?P(`"${r.field}"`):m(r.expression);return F(`(TLA.except %a %a %a)`,m(t.function),i,m(n.value))}case`Dot`:return F(`(TLA.fapply %a "%s")`,m(t.expression),t.field);case`Tuple`:return F(`(TLA.tuple %a)`,o(t.elements));case`Product`:return t.factors.length===2?F(`(TLA.prod %a %a)`,m(t.factors[0]),m(t.factors[1])):F(`(TLA.Product (TLA.tuple %a))`,o(t.factors));case`Sub`:case`Tsub`:case`Fair`:throw new e.k(t.kind);case`Case`:{let e=I(t.arms,e=>F(`%a %a`,m(e.condition),m(e.body)),Yc);return t.other?F(`(TLA.CASE %a %a)@]`,e,m(t.other)):F(`(TLA.CASE %a )`,e)}case`String`:return F(`"%s"`,t.value);case`Num`:if(t.fraction!==``)throw new e.k(`Real number constants`);return P($c(t.integer));case`Bang`:case`Let`:case`At`:throw new e.j}},h=t=>{let n=r.stack.length;try{return m(t)}catch(t){if(!(t instanceof e.k))throw t;return Lt(r,r.stack.length-n),t}},g=t=>{switch(t.kind){case`Fresh`:{let e=t.domain&&t.domainVisibility===`Visible`?m(t.domain):void 0,n=i(t.name);return e?F(`$hyp "%s_in" (TLA.in %s %a)@
34
+ `,n,n,e):[]}case`Flex`:return i(t.name),[];case`Defn`:{let e=i(t.definition.name);return t.visibility===`Visible`?F(`; usable definition %s suppressed@.`,e):[]}case`Fact`:{let n=String(r.stack.length),i=t.visibility===`Visible`?h(t.expression):void 0;return a(),i instanceof e.k?F(`; omitted temporal assumption : %s @.`,i.message):i?F(`$hyp "v'%s" %a@
35
+ `,n,i):[]}}},_=(()=>{try{return[n.context.map(g),F(`$goal %a`,m(n.active))]}catch(t){throw t instanceof e.k?new e.w(`Zenon: unsupported operator ${t.message}`):t}})();return Mt([F(`;; obligation #%s@
36
+ `,String(t)),_])},tl=[`tla-ts`,`tlapm`],nl=e=>tl.some(t=>t===e),rl=e=>Go(Xa(e)),il={encode:(e,t,n,r)=>(n.rlimit===void 0?``:`(set-option :rlimit ${n.rlimit})\n`)+Jc(rl(t),r)},al={smt:il,z3:il,zenon:{encode:(e,t)=>el(e,rl(t))},isabelle:{encode:(e,t,n)=>ua(e,rl(t),n.tactic??`auto`,`tlapm_${e}`)},ls4:{encode:(e,t)=>ds(t)}},ol=e=>e.kind===`Case`&&e.other===void 0||ve(e).some(ol),sl=/* @__PURE__ */ new WeakMap,cl=e=>{let t=sl.get(e);if(t!==void 0)return t;let n=[];ge(e,e=>(n.push(e),e),`all`);let r=n.some(ol);return sl.set(e,r),r},ll=e=>/-{4,}\s*MODULE\s+(\w+)/.exec(e)?.[1]??`Main`,ul=e=>({id:e.id,location:e.location,text:e.text}),dl=(e,t,n)=>({...ul(e),status:t,reason:n}),fl=(e,t=es(e))=>jo(fo(eo(e.sequent)),t.frontends),pl=(e,t)=>`${an(t?fo(eo(e.sequent,!1)):fl(e))}\n`,ml=(e,t,n)=>da(e,t.flatMap((e,t)=>e.attempts.filter(e=>e.method.prover===`isabelle`&&e.isProved&&!e.isReused).map(r=>({id:e.obligation.id,sequent:rl(fl(n[t])),tactic:r.method.tactic??`auto`})))),hl=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},gl=async(t,n,r,i)=>{if(t.kind.kind===`Error`)return{obligation:dl(t,`failed`,t.kind.message),attempts:[]};let a=es(t),o=Ho(t.sequent),s=r.lastByFingerprint.get(o);r.lastByFingerprint.set(o,r.tasks[n].done),await s;let c=[],l=e=>({obligation:{...ul(t),status:`proved`,prover:e},attempts:c}),u=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},d=e=>e.rlimit??e.timeLimitMs/1e3,f=e=>c.push({...e,isReused:!0,timeUsedMs:void 0}),p=u(a.provers[0]);if(p?.isProved)return f(p),l(p.method.prover);let m=fl(t,a);if(t.kind.kind===`Support`&&ts(m))return r.results.set(o,r.results.get(o)??/* @__PURE__ */ new Map),{obligation:{...ul(t),status:`trivial`},attempts:c};let h=[],g={isDecided:!1},_=e=>{c.push(e),r.results.set(o,(r.results.get(o)??/* @__PURE__ */ new Map).set(e.method.prover,e)),g.isDecided=!0};for(let o of a.provers){let a=u(o);if(a?.isProved)return f(a),l(o.prover);if(a&&d(a.method)>=d(o)){f(a),g.isDecided=!0,h.push(`${o.prover} failed on an obligation with the same fingerprint`);continue}if(!r.isProving)continue;if(o.prover===`trivial`)return l(o.prover);let s=al[o.prover];if(s)try{let e=s===il&&(m.context.some(cl)||ol(m.active))?await hl(r,n):{caseErrors:0},a=s.encode(t.id,m,o,e),c=await r.decide(o.prover,a,{timeLimitMs:o.timeLimitMs,signal:i},n),u=c.verdict===`unsat`;if(_({method:o,isProved:u,isReused:!1,...!u&&{reason:c.timeUsedMs>=o.timeLimitMs?`timeout`:`false`},verdict:c.verdict,timeUsedMs:c.timeUsedMs}),u)return l(o.prover);h.push(`${o.prover} answered ${c.verdict}`)}catch(t){if(t instanceof e.w){_({method:o,isProved:!1,isReused:!1,reason:`false`}),h.push(`${o.prover} failed: ${t.message}`);continue}if(!(t instanceof e.k))throw t;let n=`${o.prover} can't encode ${t.message}`;c.push({method:o,isProved:!1,isReused:!1,reason:n}),h.push(n)}else{let e=`tla-ts has no ${o.prover} backend`;c.push({method:o,isProved:!1,isReused:!1,reason:e}),h.push(e)}}return{obligation:dl(t,g.isDecided?`failed`:`unsupported`,h.join(`, `)),attempts:c}},_l=async(t,n)=>{try{return await n()}catch(n){if(n instanceof e.k)return{obligation:dl(t,`unsupported`,n.message),attempts:[]};if(n instanceof e.w)return{obligation:dl(t,`failed`,n.message),attempts:[]};throw n}},vl=async(t,r)=>{let i=r.workers??1,a=i>1&&e.n()?await Ji(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=_l(n,()=>gl(n,e,s,r.signal));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.w(`prove stopped`))}return f},yl=(e,t)=>t?{...ul(e),...t}:dl(e,`unsupported`,`tlapm reported no result`),bl=async t=>{let n=ll(t.source),r=/* @__PURE__ */ new Map,i=qi([{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 --------------------------------
37
+
38
+ (* Backend pragmas. *)
39
+
40
+
41
+ (***************************************************************************)
42
+ (* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
43
+ (* is added to the context of an obligation most recently is the one whose *)
44
+ (* effects are triggered. *)
45
+ (***************************************************************************)
46
+
47
+ (***************************************************************************)
48
+ (* The following pragmas should be used only as a last resource. They are *)
49
+ (* dependent upon the particular backend provers, and are unlikely to have *)
50
+ (* any effect if the set of backend provers changes. Moreover, they are *)
51
+ (* meaningless to a reader of the proof. *)
52
+ (***************************************************************************)
53
+
54
+
55
+ (**************************************************************************)
56
+ (* Backend pragma: use the SMT solver for arithmetic. *)
57
+ (* *)
58
+ (* This method exists under this name for historical reasons. *)
59
+ (**************************************************************************)
60
+
61
+ SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
62
+
63
+
64
+ (**************************************************************************)
65
+ (* Backend pragma: SMT solver *)
66
+ (* *)
67
+ (* This method translates the proof obligation to SMTLIB2. The supported *)
68
+ (* fragment includes first-order logic, set theory, functions and *)
69
+ (* records. *)
70
+ (* SMT calls the smt-solver with the default timeout of 5 seconds *)
71
+ (* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
72
+ (* *)
73
+ (* SMTT also accepts a string argument of the form "rN" to bound the *)
74
+ (* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
75
+ (* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
76
+ (* resource count, so a small readable budget like "r5" is meaningful. *)
77
+ (* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
78
+ (* speed or load, so the proof's pass/fail outcome reproduces on any *)
79
+ (* machine and every rerun (for a fixed Z3 build); how long it takes to *)
80
+ (* consume the budget still varies by machine. This is Z3-specific. *)
81
+ (**************************************************************************)
82
+
83
+ SMT == TRUE (*{ by (prover:"smt3") }*)
84
+ SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
85
+
86
+
87
+ (**************************************************************************)
88
+ (* Backend pragma: CVC4 SMT solver *)
89
+ (* *)
90
+ (* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
91
+ (**************************************************************************)
92
+
93
+ (* The CVC3* methods are here for backward compatibility. They call CVC4. *)
94
+ CVC3 == TRUE (*{ by (prover: "cvc33") }*)
95
+ CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
96
+
97
+ CVC4 == TRUE (*{ by (prover: "cvc33") }*)
98
+ CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
99
+
100
+
101
+ (**************************************************************************)
102
+ (* Backend pragma: Yices SMT solver *)
103
+ (* *)
104
+ (* This method translates the proof obligation to Yices native language. *)
105
+ (**************************************************************************)
106
+
107
+ Yices == TRUE (*{ by (prover: "yices3") }*)
108
+ YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
109
+
110
+ (**************************************************************************)
111
+ (* Backend pragma: veriT SMT solver *)
112
+ (* *)
113
+ (* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
114
+ (**************************************************************************)
115
+
116
+ veriT == TRUE (*{ by (prover: "verit") }*)
117
+ veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
118
+
119
+ (**************************************************************************)
120
+ (* Backend pragma: Zipperposition solver *)
121
+ (* *)
122
+ (* This method translates the proof obligation to TPTP and *)
123
+ (* calls Zipperposition. *)
124
+ (**************************************************************************)
125
+
126
+ Zipper == TRUE (*{ by (prover: "zipper") }*)
127
+ ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
128
+
129
+ (**************************************************************************)
130
+ (* Backend pragma: Z3 SMT solver *)
131
+ (* *)
132
+ (* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
133
+ (* Z3 is used by default but you can also explicitly call it. *)
134
+ (* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
135
+ (* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
136
+ (* reproduces the same outcome on any machine (see SMTT). *)
137
+ (**************************************************************************)
138
+
139
+ Z3 == TRUE (*{ by (prover: "z33") }*)
140
+ Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
141
+
142
+ (**************************************************************************)
143
+ (* Backend pragma: SPASS superposition prover *)
144
+ (* *)
145
+ (* This method translates the proof obligation to the DFG format language *)
146
+ (* supported by the ATP SPASS. The translation is based on the SMT one. *)
147
+ (**************************************************************************)
148
+
149
+ Spass == TRUE (*{ by (prover: "spass") }*)
150
+ SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
151
+
152
+ (**************************************************************************)
153
+ (* Backend pragma: The PTL propositional linear time temporal logic *)
154
+ (* prover. It currently is the LS4 backend. *)
155
+ (* *)
156
+ (* This method translates the negetation of the proof obligation to *)
157
+ (* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
158
+ (**************************************************************************)
159
+
160
+ LS4 == TRUE (*{ by (prover: "ls4") }*)
161
+ LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
162
+ PTL == TRUE (*{ by (prover: "ls4") }*)
163
+
164
+ (**************************************************************************)
165
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
166
+ (* *)
167
+ (**************************************************************************)
168
+
169
+ Zenon == TRUE (*{ by (prover:"zenon") }*)
170
+ ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
171
+
172
+ (********************************************************************)
173
+ (* Backend pragma: Isabelle with different timeouts and tactics *)
174
+ (* (default is 30 seconds/auto) *)
175
+ (********************************************************************)
176
+
177
+ Isa == TRUE (*{ by (prover:"isabelle") }*)
178
+ IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
179
+ IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
180
+ IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
181
+
182
+ (***************************************************************************)
183
+ (* The following theorem expresses the (useful implication of the) law of *)
184
+ (* set extensionality, which can be written as *)
185
+ (* *)
186
+ (* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
187
+ (* *)
188
+ (* Theorem SetExtensionality is sometimes required by the SMT backend for *)
189
+ (* reasoning about sets. It is usually counterproductive to include *)
190
+ (* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
191
+ (* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
192
+ (* the Isabelle backend to use the rule of set extensionality. *)
193
+ (***************************************************************************)
194
+ IsaWithSetExtensionality == TRUE
195
+ (*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
196
+
197
+ THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
198
+ OBVIOUS
199
+
200
+ (***************************************************************************)
201
+ (* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
202
+ (* the definition *)
203
+ (* *)
204
+ (* NotInSetS == CHOOSE v : v \\notin SetS *)
205
+ (***************************************************************************)
206
+ THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
207
+ OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
208
+ -----------------------------------------------------------------------------
209
+
210
+
211
+
212
+ (********************************************************************)
213
+ (********************************************************************)
214
+ (********************************************************************)
215
+
216
+
217
+ (********************************************************************)
218
+ (* Old versions of Zenon and Isabelle pragmas below *)
219
+ (* (kept for compatibility) *)
220
+ (********************************************************************)
221
+
222
+
223
+ (**************************************************************************)
224
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
225
+ (* *)
226
+ (**************************************************************************)
227
+
228
+ SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
229
+ SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
230
+ VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
231
+ SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
232
+
233
+
234
+
235
+ (********************************************************************)
236
+ (* Backend pragma: Isabelle's automatic search ("auto") *)
237
+ (* *)
238
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
239
+ (* essentially simplification and equational reasoning. *)
240
+ (* Default imeout for all isabelle tactics is 30 seconds. *)
241
+ (********************************************************************)
242
+ Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
243
+ SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
244
+ SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
245
+ SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
246
+
247
+ (********************************************************************)
248
+ (* Backend pragma: Isabelle's "force" tactic *)
249
+ (* *)
250
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
251
+ (* quantifier reasoning. *)
252
+ (********************************************************************)
253
+ Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
254
+ SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
255
+ SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
256
+ SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
257
+
258
+ (***********************************************************************)
259
+ (* Backend pragma: Isabelle's "simplification" tactics *)
260
+ (* *)
261
+ (* These tactics simplify the goal before running one of the automated *)
262
+ (* tactics. They are often necessary for obligations involving record *)
263
+ (* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
264
+ (* sure you can get away with just Simplification *)
265
+ (***********************************************************************)
266
+ SimplifyAndSolve == TRUE
267
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
268
+ SlowSimplifyAndSolve == TRUE
269
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
270
+ SlowerSimplifyAndSolve == TRUE
271
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
272
+ SlowestSimplifyAndSolve == TRUE
273
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
274
+
275
+ Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
276
+ SlowSimplification == TRUE
277
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
278
+ SlowerSimplification == TRUE
279
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
280
+ SlowestSimplification == TRUE
281
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
282
+
283
+ (**************************************************************************)
284
+ (* Backend pragma: Isabelle's tableau prover ("blast") *)
285
+ (* *)
286
+ (* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
287
+ (* prover, Blast. It is almost never better than Zenon by itself, but *)
288
+ (* becomes very useful in combination with the Auto pragma above. The *)
289
+ (* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
290
+ (* Auto could not prove. (There is currently no way to use Zenon on the *)
291
+ (* results left over from Auto.) *)
292
+ (**************************************************************************)
293
+ Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
294
+ SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
295
+ SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
296
+ SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
297
+
298
+ AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
299
+
300
+
301
+ (**************************************************************************)
302
+ (* Backend pragmas: multi-back-ends *)
303
+ (* *)
304
+ (* These pragmas just run a bunch of back-ends one after the other in the *)
305
+ (* hope that one will succeed. This saves time and effort for the user at *)
306
+ (* the expense of computation time. *)
307
+ (**************************************************************************)
308
+
309
+ (* CVC3 goes first because it's bundled with TLAPS, then the other SMT
310
+ solvers are unlikely to succeed if CVC3 fails, so we run zenon and
311
+ Isabelle before them. *)
312
+ AllProvers == TRUE (*{
313
+ by (prover:"cvc33")
314
+ by (prover:"zenon")
315
+ by (prover:"isabelle"; tactic:"auto")
316
+ by (prover:"spass")
317
+ by (prover:"smt3")
318
+ by (prover:"yices3")
319
+ by (prover:"verit")
320
+ by (prover:"z33")
321
+ by (prover:"isabelle"; tactic:"force")
322
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
323
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
324
+ by (prover:"isabelle"; tactic:"clarsimp")
325
+ by (prover:"isabelle"; tactic:"auto, blast")
326
+ }*)
327
+ AllProversT(X) == TRUE (*{
328
+ by (prover:"cvc33"; timeout:@)
329
+ by (prover:"zenon"; timeout:@)
330
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
331
+ by (prover:"spass"; timeout:@)
332
+ by (prover:"smt3"; timeout:@)
333
+ by (prover:"yices3"; timeout:@)
334
+ by (prover:"verit"; timeout:@)
335
+ by (prover:"z33"; timeout:@)
336
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
337
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
338
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
339
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
340
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
341
+ }*)
342
+
343
+ AllSMT == TRUE (*{
344
+ by (prover:"cvc33")
345
+ by (prover:"smt3")
346
+ by (prover:"yices3")
347
+ by (prover:"verit")
348
+ by (prover:"z33")
349
+ }*)
350
+ AllSMTT(X) == TRUE (*{
351
+ by (prover:"cvc33"; timeout:@)
352
+ by (prover:"smt3"; timeout:@)
353
+ by (prover:"yices3"; timeout:@)
354
+ by (prover:"verit"; timeout:@)
355
+ by (prover:"z33"; timeout:@)
356
+ }*)
357
+
358
+ AllIsa == TRUE (*{
359
+ by (prover:"isabelle"; tactic:"auto")
360
+ by (prover:"isabelle"; tactic:"force")
361
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
362
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
363
+ by (prover:"isabelle"; tactic:"clarsimp")
364
+ by (prover:"isabelle"; tactic:"auto, blast")
365
+ }*)
366
+ AllIsaT(X) == TRUE (*{
367
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
368
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
369
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
370
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
371
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
372
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
373
+ }*)
374
+
375
+
376
+ (**************************************************************************)
377
+ (* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
378
+ (* *)
379
+ (* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
380
+ (* *)
381
+ (* The pragma AutoUSE invokes automated expansion of definitions, *)
382
+ (* for both of ExpandEnabled and ExpandCdot, when each is present. *)
383
+ (* *)
384
+ (* The pragma Lambdify invokes expansion of the operators *)
385
+ (* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
386
+ (* which is a form before introducing rigid quantifiers. *)
387
+ (* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
388
+ (* that are not nested. *)
389
+ (**************************************************************************)
390
+ ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
391
+ ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
392
+ AutoUSE == TRUE (*{ by (prover:"autouse") }*)
393
+ Lambdify == TRUE (*{ by (prover:"lambdify") }*)
394
+ ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
395
+ LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
396
+
397
+ (* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
398
+ (* representation within TLAPM. *)
399
+ EnabledWrapper(Op(_)) == FALSE
400
+ CdotWrapper(Op(_)) == FALSE
401
+
402
+ (***************************************************************************)
403
+ (* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
404
+ (* triviality checks in TLAPM. *)
405
+ (***************************************************************************)
406
+ Trivial == TRUE (*{ by (prover:"trivial") }*)
407
+
408
+
409
+ =============================================================================
410
+
411
+ The material below is obsolete: the TLA proof rules below are superseded by
412
+ the PTL decision procedure, and their formulation is unsound for the semantics
413
+ of temporal reasoning that TLAPS adopts.
414
+
415
+ ----------------------------------------------------------------------------
416
+ (***************************************************************************)
417
+ (* TEMPORAL LOGIC *)
418
+ (* *)
419
+ (* The following rules are intended to be used when TLAPS handles temporal *)
420
+ (* logic. They will not work now. Moreover when temporal reasoning is *)
421
+ (* implemented, these rules may be changed or omitted, and additional *)
422
+ (* rules will probably be added. However, they are included mainly so *)
423
+ (* their names will be defined, preventing the use of identifiers that are *)
424
+ (* likely to produce name clashes with future versions of this module. *)
425
+ (***************************************************************************)
426
+
427
+
428
+ (***************************************************************************)
429
+ (* The following proof rules (and their names) are from the paper "The *)
430
+ (* Temporal Logic of Actions". *)
431
+ (***************************************************************************)
432
+ THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
433
+ P /\\ (f' = f) => P'
434
+ PROVE []P <=> P /\\ [][P => P']_f
435
+
436
+ THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
437
+ ACTION A, ACTION B,
438
+ P /\\ [A]_f => Q /\\ [B]_g
439
+ PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
440
+
441
+ THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
442
+ I /\\ [N]_F => I'
443
+ PROVE I /\\ [][N]_F => []I
444
+
445
+ THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
446
+ PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
447
+
448
+ THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
449
+ P /\\ [N]_f => (P' \\/ Q'),
450
+ P /\\ <<N /\\ A>>_f => Q',
451
+ P => ENABLED <<A>>_f
452
+ PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
453
+
454
+ THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
455
+ ACTION N, ACTION A, TEMPORAL F,
456
+ P /\\ [N]_f => (P' \\/ Q'),
457
+ P /\\ <<N /\\ A>>_f => Q',
458
+ []P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
459
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
460
+
461
+ (***************************************************************************)
462
+ (* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
463
+ (* from the following two rules by the following substitutions: \`. *)
464
+ (* *)
465
+ (* ___ ___ _______________ *)
466
+ (* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
467
+ (***************************************************************************)
468
+ THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
469
+ ACTION A, ACTION B, ACTION N, ACTION M,
470
+ TEMPORAL F,
471
+ <<N /\\ B>>_f => <<M>>_g,
472
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
473
+ P /\\ EM => ENABLED A,
474
+ [][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
475
+ PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
476
+
477
+ THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
478
+ ACTION A, ACTION B, ACTION N, ACTION M,
479
+ TEMPORAL F,
480
+ <<N /\\ B>>_f => <<M>>_g,
481
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
482
+ P /\\ EM => ENABLED A,
483
+ [][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
484
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
485
+
486
+
487
+ (***************************************************************************)
488
+ (* The following rule is a special case of the general temporal logic *)
489
+ (* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
490
+ (* general rule is for arbitrary temporal formulas F and G, but it cannot *)
491
+ (* yet be handled by TLAPS. *)
492
+ (***************************************************************************)
493
+ THEOREM RuleInvImplication ==
494
+ ASSUME STATE F, STATE G,
495
+ F => G
496
+ PROVE []F => []G
497
+ PROOF OMITTED
498
+
499
+ (***************************************************************************)
500
+ (* The following rule is a special case of rule TLA2 from the paper "The *)
501
+ (* Temporal Logic of Actions". *)
502
+ (***************************************************************************)
503
+ THEOREM RuleStepSimulation ==
504
+ ASSUME STATE I, STATE f, STATE g,
505
+ ACTION M, ACTION N,
506
+ I /\\ I' /\\ [M]_f => [N]_g
507
+ PROVE []I /\\ [][M]_f => [][N]_g
508
+ PROOF OMITTED
509
+
510
+ (***************************************************************************)
511
+ (* The following may be used to invoke a decision procedure for *)
512
+ (* propositional temporal logic. *)
513
+ (***************************************************************************)
514
+ PropositionalTemporalLogic == TRUE
515
+ =============================================================================
516
+ `: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.k(`The tlapm backend runs only in Node and Bun.`);let i=await Promise.resolve().then(()=>require("./tlapm.cjs")),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?.(yl(r,n))}});return{obligations:a.map(e=>yl(e,c.get(e.id))),...o}}return{obligations:(await vl(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 bl}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Pi}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return rn}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return nl}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Ki}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return ml}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return vl}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Mt}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return pl}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return`------------------------------- MODULE TLAPS --------------------------------
517
+
518
+ (* Backend pragmas. *)
519
+
520
+
521
+ (***************************************************************************)
522
+ (* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
523
+ (* is added to the context of an obligation most recently is the one whose *)
524
+ (* effects are triggered. *)
525
+ (***************************************************************************)
526
+
527
+ (***************************************************************************)
528
+ (* The following pragmas should be used only as a last resource. They are *)
529
+ (* dependent upon the particular backend provers, and are unlikely to have *)
530
+ (* any effect if the set of backend provers changes. Moreover, they are *)
531
+ (* meaningless to a reader of the proof. *)
532
+ (***************************************************************************)
533
+
534
+
535
+ (**************************************************************************)
536
+ (* Backend pragma: use the SMT solver for arithmetic. *)
537
+ (* *)
538
+ (* This method exists under this name for historical reasons. *)
539
+ (**************************************************************************)
540
+
541
+ SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
542
+
543
+
544
+ (**************************************************************************)
545
+ (* Backend pragma: SMT solver *)
546
+ (* *)
547
+ (* This method translates the proof obligation to SMTLIB2. The supported *)
548
+ (* fragment includes first-order logic, set theory, functions and *)
549
+ (* records. *)
550
+ (* SMT calls the smt-solver with the default timeout of 5 seconds *)
551
+ (* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
552
+ (* *)
553
+ (* SMTT also accepts a string argument of the form "rN" to bound the *)
554
+ (* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
555
+ (* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
556
+ (* resource count, so a small readable budget like "r5" is meaningful. *)
557
+ (* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
558
+ (* speed or load, so the proof's pass/fail outcome reproduces on any *)
559
+ (* machine and every rerun (for a fixed Z3 build); how long it takes to *)
560
+ (* consume the budget still varies by machine. This is Z3-specific. *)
561
+ (**************************************************************************)
562
+
563
+ SMT == TRUE (*{ by (prover:"smt3") }*)
564
+ SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
565
+
566
+
567
+ (**************************************************************************)
568
+ (* Backend pragma: CVC4 SMT solver *)
569
+ (* *)
570
+ (* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
571
+ (**************************************************************************)
572
+
573
+ (* The CVC3* methods are here for backward compatibility. They call CVC4. *)
574
+ CVC3 == TRUE (*{ by (prover: "cvc33") }*)
575
+ CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
576
+
577
+ CVC4 == TRUE (*{ by (prover: "cvc33") }*)
578
+ CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
579
+
580
+
581
+ (**************************************************************************)
582
+ (* Backend pragma: Yices SMT solver *)
583
+ (* *)
584
+ (* This method translates the proof obligation to Yices native language. *)
585
+ (**************************************************************************)
586
+
587
+ Yices == TRUE (*{ by (prover: "yices3") }*)
588
+ YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
589
+
590
+ (**************************************************************************)
591
+ (* Backend pragma: veriT SMT solver *)
592
+ (* *)
593
+ (* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
594
+ (**************************************************************************)
595
+
596
+ veriT == TRUE (*{ by (prover: "verit") }*)
597
+ veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
598
+
599
+ (**************************************************************************)
600
+ (* Backend pragma: Zipperposition solver *)
601
+ (* *)
602
+ (* This method translates the proof obligation to TPTP and *)
603
+ (* calls Zipperposition. *)
604
+ (**************************************************************************)
605
+
606
+ Zipper == TRUE (*{ by (prover: "zipper") }*)
607
+ ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
608
+
609
+ (**************************************************************************)
610
+ (* Backend pragma: Z3 SMT solver *)
611
+ (* *)
612
+ (* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
613
+ (* Z3 is used by default but you can also explicitly call it. *)
614
+ (* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
615
+ (* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
616
+ (* reproduces the same outcome on any machine (see SMTT). *)
617
+ (**************************************************************************)
618
+
619
+ Z3 == TRUE (*{ by (prover: "z33") }*)
620
+ Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
621
+
622
+ (**************************************************************************)
623
+ (* Backend pragma: SPASS superposition prover *)
624
+ (* *)
625
+ (* This method translates the proof obligation to the DFG format language *)
626
+ (* supported by the ATP SPASS. The translation is based on the SMT one. *)
627
+ (**************************************************************************)
628
+
629
+ Spass == TRUE (*{ by (prover: "spass") }*)
630
+ SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
631
+
632
+ (**************************************************************************)
633
+ (* Backend pragma: The PTL propositional linear time temporal logic *)
634
+ (* prover. It currently is the LS4 backend. *)
635
+ (* *)
636
+ (* This method translates the negetation of the proof obligation to *)
637
+ (* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
638
+ (**************************************************************************)
639
+
640
+ LS4 == TRUE (*{ by (prover: "ls4") }*)
641
+ LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
642
+ PTL == TRUE (*{ by (prover: "ls4") }*)
643
+
644
+ (**************************************************************************)
645
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
646
+ (* *)
647
+ (**************************************************************************)
648
+
649
+ Zenon == TRUE (*{ by (prover:"zenon") }*)
650
+ ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
651
+
652
+ (********************************************************************)
653
+ (* Backend pragma: Isabelle with different timeouts and tactics *)
654
+ (* (default is 30 seconds/auto) *)
655
+ (********************************************************************)
656
+
657
+ Isa == TRUE (*{ by (prover:"isabelle") }*)
658
+ IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
659
+ IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
660
+ IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
661
+
662
+ (***************************************************************************)
663
+ (* The following theorem expresses the (useful implication of the) law of *)
664
+ (* set extensionality, which can be written as *)
665
+ (* *)
666
+ (* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
667
+ (* *)
668
+ (* Theorem SetExtensionality is sometimes required by the SMT backend for *)
669
+ (* reasoning about sets. It is usually counterproductive to include *)
670
+ (* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
671
+ (* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
672
+ (* the Isabelle backend to use the rule of set extensionality. *)
673
+ (***************************************************************************)
674
+ IsaWithSetExtensionality == TRUE
675
+ (*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
676
+
677
+ THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
678
+ OBVIOUS
679
+
680
+ (***************************************************************************)
681
+ (* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
682
+ (* the definition *)
683
+ (* *)
684
+ (* NotInSetS == CHOOSE v : v \\notin SetS *)
685
+ (***************************************************************************)
686
+ THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
687
+ OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
688
+ -----------------------------------------------------------------------------
689
+
690
+
691
+
692
+ (********************************************************************)
693
+ (********************************************************************)
694
+ (********************************************************************)
695
+
696
+
697
+ (********************************************************************)
698
+ (* Old versions of Zenon and Isabelle pragmas below *)
699
+ (* (kept for compatibility) *)
700
+ (********************************************************************)
701
+
702
+
703
+ (**************************************************************************)
704
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
705
+ (* *)
706
+ (**************************************************************************)
707
+
708
+ SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
709
+ SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
710
+ VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
711
+ SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
712
+
713
+
714
+
715
+ (********************************************************************)
716
+ (* Backend pragma: Isabelle's automatic search ("auto") *)
717
+ (* *)
718
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
719
+ (* essentially simplification and equational reasoning. *)
720
+ (* Default imeout for all isabelle tactics is 30 seconds. *)
721
+ (********************************************************************)
722
+ Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
723
+ SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
724
+ SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
725
+ SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
726
+
727
+ (********************************************************************)
728
+ (* Backend pragma: Isabelle's "force" tactic *)
729
+ (* *)
730
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
731
+ (* quantifier reasoning. *)
732
+ (********************************************************************)
733
+ Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
734
+ SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
735
+ SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
736
+ SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
737
+
738
+ (***********************************************************************)
739
+ (* Backend pragma: Isabelle's "simplification" tactics *)
740
+ (* *)
741
+ (* These tactics simplify the goal before running one of the automated *)
742
+ (* tactics. They are often necessary for obligations involving record *)
743
+ (* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
744
+ (* sure you can get away with just Simplification *)
745
+ (***********************************************************************)
746
+ SimplifyAndSolve == TRUE
747
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
748
+ SlowSimplifyAndSolve == TRUE
749
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
750
+ SlowerSimplifyAndSolve == TRUE
751
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
752
+ SlowestSimplifyAndSolve == TRUE
753
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
754
+
755
+ Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
756
+ SlowSimplification == TRUE
757
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
758
+ SlowerSimplification == TRUE
759
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
760
+ SlowestSimplification == TRUE
761
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
762
+
763
+ (**************************************************************************)
764
+ (* Backend pragma: Isabelle's tableau prover ("blast") *)
765
+ (* *)
766
+ (* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
767
+ (* prover, Blast. It is almost never better than Zenon by itself, but *)
768
+ (* becomes very useful in combination with the Auto pragma above. The *)
769
+ (* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
770
+ (* Auto could not prove. (There is currently no way to use Zenon on the *)
771
+ (* results left over from Auto.) *)
772
+ (**************************************************************************)
773
+ Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
774
+ SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
775
+ SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
776
+ SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
777
+
778
+ AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
779
+
780
+
781
+ (**************************************************************************)
782
+ (* Backend pragmas: multi-back-ends *)
783
+ (* *)
784
+ (* These pragmas just run a bunch of back-ends one after the other in the *)
785
+ (* hope that one will succeed. This saves time and effort for the user at *)
786
+ (* the expense of computation time. *)
787
+ (**************************************************************************)
788
+
789
+ (* CVC3 goes first because it's bundled with TLAPS, then the other SMT
790
+ solvers are unlikely to succeed if CVC3 fails, so we run zenon and
791
+ Isabelle before them. *)
792
+ AllProvers == TRUE (*{
793
+ by (prover:"cvc33")
794
+ by (prover:"zenon")
795
+ by (prover:"isabelle"; tactic:"auto")
796
+ by (prover:"spass")
797
+ by (prover:"smt3")
798
+ by (prover:"yices3")
799
+ by (prover:"verit")
800
+ by (prover:"z33")
801
+ by (prover:"isabelle"; tactic:"force")
802
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
803
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
804
+ by (prover:"isabelle"; tactic:"clarsimp")
805
+ by (prover:"isabelle"; tactic:"auto, blast")
806
+ }*)
807
+ AllProversT(X) == TRUE (*{
808
+ by (prover:"cvc33"; timeout:@)
809
+ by (prover:"zenon"; timeout:@)
810
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
811
+ by (prover:"spass"; timeout:@)
812
+ by (prover:"smt3"; timeout:@)
813
+ by (prover:"yices3"; timeout:@)
814
+ by (prover:"verit"; timeout:@)
815
+ by (prover:"z33"; timeout:@)
816
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
817
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
818
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
819
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
820
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
821
+ }*)
822
+
823
+ AllSMT == TRUE (*{
824
+ by (prover:"cvc33")
825
+ by (prover:"smt3")
826
+ by (prover:"yices3")
827
+ by (prover:"verit")
828
+ by (prover:"z33")
829
+ }*)
830
+ AllSMTT(X) == TRUE (*{
831
+ by (prover:"cvc33"; timeout:@)
832
+ by (prover:"smt3"; timeout:@)
833
+ by (prover:"yices3"; timeout:@)
834
+ by (prover:"verit"; timeout:@)
835
+ by (prover:"z33"; timeout:@)
836
+ }*)
837
+
838
+ AllIsa == TRUE (*{
839
+ by (prover:"isabelle"; tactic:"auto")
840
+ by (prover:"isabelle"; tactic:"force")
841
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
842
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
843
+ by (prover:"isabelle"; tactic:"clarsimp")
844
+ by (prover:"isabelle"; tactic:"auto, blast")
845
+ }*)
846
+ AllIsaT(X) == TRUE (*{
847
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
848
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
849
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
850
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
851
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
852
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
853
+ }*)
854
+
855
+
856
+ (**************************************************************************)
857
+ (* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
858
+ (* *)
859
+ (* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
860
+ (* *)
861
+ (* The pragma AutoUSE invokes automated expansion of definitions, *)
862
+ (* for both of ExpandEnabled and ExpandCdot, when each is present. *)
863
+ (* *)
864
+ (* The pragma Lambdify invokes expansion of the operators *)
865
+ (* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
866
+ (* which is a form before introducing rigid quantifiers. *)
867
+ (* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
868
+ (* that are not nested. *)
869
+ (**************************************************************************)
870
+ ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
871
+ ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
872
+ AutoUSE == TRUE (*{ by (prover:"autouse") }*)
873
+ Lambdify == TRUE (*{ by (prover:"lambdify") }*)
874
+ ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
875
+ LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
876
+
877
+ (* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
878
+ (* representation within TLAPM. *)
879
+ EnabledWrapper(Op(_)) == FALSE
880
+ CdotWrapper(Op(_)) == FALSE
881
+
882
+ (***************************************************************************)
883
+ (* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
884
+ (* triviality checks in TLAPM. *)
885
+ (***************************************************************************)
886
+ Trivial == TRUE (*{ by (prover:"trivial") }*)
887
+
888
+
889
+ =============================================================================
890
+
891
+ The material below is obsolete: the TLA proof rules below are superseded by
892
+ the PTL decision procedure, and their formulation is unsound for the semantics
893
+ of temporal reasoning that TLAPS adopts.
894
+
895
+ ----------------------------------------------------------------------------
896
+ (***************************************************************************)
897
+ (* TEMPORAL LOGIC *)
898
+ (* *)
899
+ (* The following rules are intended to be used when TLAPS handles temporal *)
900
+ (* logic. They will not work now. Moreover when temporal reasoning is *)
901
+ (* implemented, these rules may be changed or omitted, and additional *)
902
+ (* rules will probably be added. However, they are included mainly so *)
903
+ (* their names will be defined, preventing the use of identifiers that are *)
904
+ (* likely to produce name clashes with future versions of this module. *)
905
+ (***************************************************************************)
906
+
907
+
908
+ (***************************************************************************)
909
+ (* The following proof rules (and their names) are from the paper "The *)
910
+ (* Temporal Logic of Actions". *)
911
+ (***************************************************************************)
912
+ THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
913
+ P /\\ (f' = f) => P'
914
+ PROVE []P <=> P /\\ [][P => P']_f
915
+
916
+ THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
917
+ ACTION A, ACTION B,
918
+ P /\\ [A]_f => Q /\\ [B]_g
919
+ PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
920
+
921
+ THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
922
+ I /\\ [N]_F => I'
923
+ PROVE I /\\ [][N]_F => []I
924
+
925
+ THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
926
+ PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
927
+
928
+ THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
929
+ P /\\ [N]_f => (P' \\/ Q'),
930
+ P /\\ <<N /\\ A>>_f => Q',
931
+ P => ENABLED <<A>>_f
932
+ PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
933
+
934
+ THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
935
+ ACTION N, ACTION A, TEMPORAL F,
936
+ P /\\ [N]_f => (P' \\/ Q'),
937
+ P /\\ <<N /\\ A>>_f => Q',
938
+ []P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
939
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
940
+
941
+ (***************************************************************************)
942
+ (* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
943
+ (* from the following two rules by the following substitutions: \`. *)
944
+ (* *)
945
+ (* ___ ___ _______________ *)
946
+ (* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
947
+ (***************************************************************************)
948
+ THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
949
+ ACTION A, ACTION B, ACTION N, ACTION M,
950
+ TEMPORAL F,
951
+ <<N /\\ B>>_f => <<M>>_g,
952
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
953
+ P /\\ EM => ENABLED A,
954
+ [][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
955
+ PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
956
+
957
+ THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
958
+ ACTION A, ACTION B, ACTION N, ACTION M,
959
+ TEMPORAL F,
960
+ <<N /\\ B>>_f => <<M>>_g,
961
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
962
+ P /\\ EM => ENABLED A,
963
+ [][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
964
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
965
+
966
+
967
+ (***************************************************************************)
968
+ (* The following rule is a special case of the general temporal logic *)
969
+ (* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
970
+ (* general rule is for arbitrary temporal formulas F and G, but it cannot *)
971
+ (* yet be handled by TLAPS. *)
972
+ (***************************************************************************)
973
+ THEOREM RuleInvImplication ==
974
+ ASSUME STATE F, STATE G,
975
+ F => G
976
+ PROVE []F => []G
977
+ PROOF OMITTED
978
+
979
+ (***************************************************************************)
980
+ (* The following rule is a special case of rule TLA2 from the paper "The *)
981
+ (* Temporal Logic of Actions". *)
982
+ (***************************************************************************)
983
+ THEOREM RuleStepSimulation ==
984
+ ASSUME STATE I, STATE f, STATE g,
985
+ ACTION M, ACTION N,
986
+ I /\\ I' /\\ [M]_f => [N]_g
987
+ PROVE []I /\\ [][M]_f => [][N]_g
988
+ PROOF OMITTED
989
+
990
+ (***************************************************************************)
991
+ (* The following may be used to invoke a decision procedure for *)
992
+ (* propositional temporal logic. *)
993
+ (***************************************************************************)
994
+ PropositionalTemporalLogic == TRUE
995
+ =============================================================================
996
+ `}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return tl}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return qi}});