tla-ts 0.0.4-dev.7c70fed → 0.0.4-dev.8fefa42

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 (308) hide show
  1. package/README.md +62 -70
  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 +35 -1
  6. package/dist/index.d.ts +35 -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 +515 -0
  15. package/dist/prove.js +515 -0
  16. package/dist/run-cli.cjs +30 -47
  17. package/dist/run-cli.js +30 -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/errors.ts +86 -0
  27. package/src/evaluate.ts +54 -19
  28. package/src/index.ts +10 -0
  29. package/src/{obligation-action.ts → obligations/action.ts} +258 -37
  30. package/src/{obligation-anon.ts → obligations/anon.ts} +13 -7
  31. package/src/obligations/ctx.ts +64 -0
  32. package/src/{obligation-deref.ts → obligations/deref.ts} +2 -2
  33. package/src/{obligation-expression.ts → obligations/expression.ts} +54 -8
  34. package/src/{obligation-generate.ts → obligations/generate.ts} +134 -61
  35. package/src/{obligations.ts → obligations/index.ts} +26 -12
  36. package/src/{obligation-levels.ts → obligations/levels.ts} +12 -2
  37. package/src/{obligation-module.ts → obligations/module.ts} +46 -20
  38. package/src/obligations/pickle.ts +100 -0
  39. package/src/obligations/pragma.ts +189 -0
  40. package/src/{obligation-printer.ts → obligations/printer.ts} +5 -59
  41. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
  42. package/src/{obligation-source.ts → obligations/source.ts} +91 -35
  43. package/src/obligations/temporal.ts +319 -0
  44. package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
  45. package/src/parallel-worker.ts +2 -18
  46. package/src/parallel.ts +10 -43
  47. package/src/prove/decide-pool.ts +100 -0
  48. package/src/prove/deciders.ts +27 -0
  49. package/src/prove/isabelle/LICENSE +36 -0
  50. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  51. package/src/prove/isabelle/decide.ts +47 -0
  52. package/src/prove/isabelle/encode.ts +477 -0
  53. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  54. package/src/prove/isabelle/isar/method.ts +367 -0
  55. package/src/prove/isabelle/isar/proof.ts +28 -0
  56. package/src/prove/isabelle/isar/statement.ts +57 -0
  57. package/src/prove/isabelle/isar/theory.ts +192 -0
  58. package/src/prove/isabelle/isar/type-check.ts +278 -0
  59. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  60. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  61. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  62. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  63. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  64. package/src/prove/isabelle/provers/blast/term.ts +547 -0
  65. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  66. package/src/prove/isabelle/provers/classical.ts +389 -0
  67. package/src/prove/isabelle/provers/hypsubst.ts +441 -0
  68. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  69. package/src/prove/isabelle/pure/consts.ts +32 -0
  70. package/src/prove/isabelle/pure/conv.ts +79 -0
  71. package/src/prove/isabelle/pure/drule.ts +264 -0
  72. package/src/prove/isabelle/pure/envir.ts +363 -0
  73. package/src/prove/isabelle/pure/goal.ts +53 -0
  74. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  75. package/src/prove/isabelle/pure/list.ts +12 -0
  76. package/src/prove/isabelle/pure/logic.ts +402 -0
  77. package/src/prove/isabelle/pure/name.ts +110 -0
  78. package/src/prove/isabelle/pure/net.ts +262 -0
  79. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  80. package/src/prove/isabelle/pure/pattern.ts +650 -0
  81. package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
  82. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  83. package/src/prove/isabelle/pure/search.ts +68 -0
  84. package/src/prove/isabelle/pure/seq.ts +156 -0
  85. package/src/prove/isabelle/pure/simplifier.ts +112 -0
  86. package/src/prove/isabelle/pure/table.ts +208 -0
  87. package/src/prove/isabelle/pure/tactic.ts +276 -0
  88. package/src/prove/isabelle/pure/tactical.ts +347 -0
  89. package/src/prove/isabelle/pure/term-ord.ts +159 -0
  90. package/src/prove/isabelle/pure/term.ts +808 -0
  91. package/src/prove/isabelle/pure/thm.ts +806 -0
  92. package/src/prove/isabelle/pure/type.ts +133 -0
  93. package/src/prove/isabelle/pure/unify.ts +753 -0
  94. package/src/prove/isabelle/pure/variable.ts +25 -0
  95. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  96. package/src/prove/isabelle/tla/context.ts +74 -0
  97. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  98. package/src/prove/isabelle/tla/logic.ts +215 -0
  99. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  100. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  101. package/src/prove/ocaml.ts +22 -0
  102. package/src/prove/prep/action.ts +520 -0
  103. package/src/prove/prep/defs.ts +27 -0
  104. package/src/prove/prep/elab.ts +156 -0
  105. package/src/prove/prep/enabled-axioms.ts +189 -0
  106. package/src/prove/prep/enabled.ts +43 -0
  107. package/src/prove/prep/fingerprint.ts +388 -0
  108. package/src/prove/prep/flatten.ts +70 -0
  109. package/src/prove/prep/level-comparison.ts +552 -0
  110. package/src/prove/prep/md5.ts +67 -0
  111. package/src/prove/prep/pragma.ts +221 -0
  112. package/src/prove/prep/trivial.ts +22 -0
  113. package/src/prove/prove-worker.ts +29 -0
  114. package/src/prove/prove.ts +417 -0
  115. package/src/prove/ptl/decide.ts +68 -0
  116. package/src/prove/ptl/encode.ts +256 -0
  117. package/src/prove/ptl/sat.ts +151 -0
  118. package/src/prove/ptl/tableau.ts +276 -0
  119. package/src/prove/smt/axiomatize.ts +69 -0
  120. package/src/prove/smt/axioms.ts +210 -0
  121. package/src/prove/smt/context.ts +108 -0
  122. package/src/prove/smt/data.ts +665 -0
  123. package/src/prove/smt/encode.ts +169 -0
  124. package/src/prove/smt/extensionality.ts +63 -0
  125. package/src/prove/smt/flatten.ts +127 -0
  126. package/src/prove/smt/format.ts +143 -0
  127. package/src/prove/smt/instances.ts +182 -0
  128. package/src/prove/smt/rewrite.ts +784 -0
  129. package/src/prove/smt/simplify.ts +57 -0
  130. package/src/prove/smt/solver/act-cache.ts +265 -0
  131. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  132. package/src/prove/smt/solver/array.ts +22 -0
  133. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  134. package/src/prove/smt/solver/ast-lt.ts +157 -0
  135. package/src/prove/smt/solver/ast-util.ts +147 -0
  136. package/src/prove/smt/solver/ast.ts +1315 -0
  137. package/src/prove/smt/solver/auf-solver.ts +572 -0
  138. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  139. package/src/prove/smt/solver/cg-table.ts +175 -0
  140. package/src/prove/smt/solver/clause.ts +276 -0
  141. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  142. package/src/prove/smt/solver/context.ts +1292 -0
  143. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  144. package/src/prove/smt/solver/der.ts +224 -0
  145. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  146. package/src/prove/smt/solver/e-matching.ts +659 -0
  147. package/src/prove/smt/solver/enode.ts +259 -0
  148. package/src/prove/smt/solver/expr-ref.ts +21 -0
  149. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  150. package/src/prove/smt/solver/fingerprints.ts +92 -0
  151. package/src/prove/smt/solver/flat-literals.ts +51 -0
  152. package/src/prove/smt/solver/goal.ts +138 -0
  153. package/src/prove/smt/solver/hash.ts +173 -0
  154. package/src/prove/smt/solver/hashtable.ts +166 -0
  155. package/src/prove/smt/solver/internalizer.ts +1381 -0
  156. package/src/prove/smt/solver/lbool.ts +5 -0
  157. package/src/prove/smt/solver/literal.ts +24 -0
  158. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  159. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  160. package/src/prove/smt/solver/lp/containers.ts +296 -0
  161. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  162. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  163. package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
  164. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  165. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  166. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  167. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  168. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  169. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  170. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  171. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  172. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  173. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  174. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  175. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  176. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  177. package/src/prove/smt/solver/lp/nex.ts +120 -0
  178. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  179. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  180. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  181. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  182. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  183. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  184. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  185. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  186. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  187. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  188. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  189. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  190. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  191. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  192. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  193. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  194. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  195. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  196. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  197. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  198. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  199. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  200. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  201. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  202. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  203. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  204. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  205. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  206. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  207. package/src/prove/smt/solver/model-checker.ts +347 -0
  208. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  209. package/src/prove/smt/solver/model-finder.ts +155 -0
  210. package/src/prove/smt/solver/model-generator.ts +97 -0
  211. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  212. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  213. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  214. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  215. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  216. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  217. package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
  218. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  219. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  220. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  221. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  222. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  223. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  224. package/src/prove/smt/solver/nnf.ts +469 -0
  225. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  226. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  227. package/src/prove/smt/solver/propagate-values.ts +83 -0
  228. package/src/prove/smt/solver/proto-model.ts +551 -0
  229. package/src/prove/smt/solver/pull-quant.ts +139 -0
  230. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  231. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  232. package/src/prove/smt/solver/qe-lite.ts +381 -0
  233. package/src/prove/smt/solver/qi-queue.ts +362 -0
  234. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  235. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  236. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  237. package/src/prove/smt/solver/random-gen.ts +10 -0
  238. package/src/prove/smt/solver/rational.ts +165 -0
  239. package/src/prove/smt/solver/ref-vector.ts +62 -0
  240. package/src/prove/smt/solver/relevancy.ts +247 -0
  241. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  242. package/src/prove/smt/solver/rewriter.ts +843 -0
  243. package/src/prove/smt/solver/rlimit.ts +79 -0
  244. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  245. package/src/prove/smt/solver/solver.ts +71 -0
  246. package/src/prove/smt/solver/sort.ts +35 -0
  247. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  248. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  249. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  250. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  251. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  252. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  253. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  254. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  255. package/src/prove/smt/solver/theory-lra.ts +56 -0
  256. package/src/prove/smt/solver/var-subst.ts +258 -0
  257. package/src/prove/smt/solver/z3-license.txt +10 -0
  258. package/src/prove/smt/table.ts +170 -0
  259. package/src/prove/tlapm/tlapm.ts +96 -0
  260. package/src/prove/tlaps-module.ts +510 -0
  261. package/src/prove/verdict.ts +13 -0
  262. package/src/prove/zenon/LICENSE +32 -0
  263. package/src/prove/zenon/check/check.ts +105 -0
  264. package/src/prove/zenon/check/definitions.ts +144 -0
  265. package/src/prove/zenon/check/equality.ts +182 -0
  266. package/src/prove/zenon/check/functions.ts +62 -0
  267. package/src/prove/zenon/check/keys.ts +125 -0
  268. package/src/prove/zenon/check/propositional.ts +104 -0
  269. package/src/prove/zenon/check/records.ts +188 -0
  270. package/src/prove/zenon/check/relations.ts +121 -0
  271. package/src/prove/zenon/check/rewrites.ts +224 -0
  272. package/src/prove/zenon/check/sets.ts +302 -0
  273. package/src/prove/zenon/check/terms.ts +127 -0
  274. package/src/prove/zenon/check/tla.ts +126 -0
  275. package/src/prove/zenon/decide.ts +113 -0
  276. package/src/prove/zenon/encode.ts +444 -0
  277. package/src/prove/zenon/eqrel.ts +300 -0
  278. package/src/prove/zenon/equality-rules.ts +435 -0
  279. package/src/prove/zenon/expr.ts +551 -0
  280. package/src/prove/zenon/index-table.ts +350 -0
  281. package/src/prove/zenon/isar-case.ts +513 -0
  282. package/src/prove/zenon/isar.ts +1249 -0
  283. package/src/prove/zenon/limits.ts +15 -0
  284. package/src/prove/zenon/llproof.ts +173 -0
  285. package/src/prove/zenon/mltoll.ts +1566 -0
  286. package/src/prove/zenon/node.ts +297 -0
  287. package/src/prove/zenon/ocaml.ts +169 -0
  288. package/src/prove/zenon/parse.ts +247 -0
  289. package/src/prove/zenon/phrase.ts +191 -0
  290. package/src/prove/zenon/proof.ts +198 -0
  291. package/src/prove/zenon/propositional-rules.ts +387 -0
  292. package/src/prove/zenon/rules.ts +94 -0
  293. package/src/prove/zenon/search.ts +288 -0
  294. package/src/prove/zenon/tla/functions.ts +151 -0
  295. package/src/prove/zenon/tla/llproof.ts +480 -0
  296. package/src/prove/zenon/tla/records.ts +225 -0
  297. package/src/prove/zenon/tla/rewrites.ts +447 -0
  298. package/src/prove/zenon/tla/sets.ts +304 -0
  299. package/src/prove/zenon/tla/terms.ts +181 -0
  300. package/src/prove/zenon/tla/tla.ts +506 -0
  301. package/src/run-cli.ts +73 -20
  302. package/src/successors.ts +24 -5
  303. package/src/tlc-version.ts +8 -7
  304. package/src/values.ts +47 -4
  305. package/src/worker.ts +65 -0
  306. package/dist/parallel.cjs +0 -12
  307. package/dist/parallel.js +0 -12
  308. /package/src/{obligation-format.ts → obligations/format.ts} +0 -0
package/dist/prove.js ADDED
@@ -0,0 +1,515 @@
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
+ import{C as e,D as t,g as n,j as r,k as i,n as a,r as o,w as s}from"./worker.js";import{A as c,F as l,K as u,P as d,Q as f,S as p,X as m,Y as h,Z as g,a as _,c as v,d as y,f as b,g as ee,i as x,l as te,n as S,nt as ne,o as re,p as ie,s as ae,u as oe,x as se,y as ce}from"./transfer.js";import{t as le}from"./deciders.js";const ue=async e=>{let t=typeof e.config==`string`?f(e.config,e.version):e.config,r=e.onPrint??console.log,i={count:0},a=e=>[e.kind,`name`in e?e.name:``,`count`in e?e.count:``,`text`in e?e.text:``].join(` `),s=/* @__PURE__ */ new Set,c=t=>{s.add(a(t)),e.onProgress?.(t)},ne=()=>{let n={count:i.count};return te({...e,config:t,onPrint:e=>n.count-->0?void 0:r(e),onProgress:t=>{s.has(a(t))||e.onProgress?.(t)}})},le=e.workers??1;if(le<2||typeof SharedArrayBuffer!=`function`||e.dump!==void 0||t.view!==void 0||t.postconditions.length>0||t.possible.length>0)return ne();let ue=/* @__PURE__ */ new Map,de=t=>{let n=e.loadModule?.(t);return ue.set(t,n),n},fe=/* @__PURE__ */ new Map,pe=t=>{let n=e.loadClass?.(t);return fe.set(t,n),n};m(se(e.source,t,de)),g(e.version);let C=h(),me=ce(t,{source:e.source,loadModule:de,loadClass:pe,print:e=>{i.count++,r(e)},files:{readFile:e.readFile,writeFile:e.writeFile},isTool:e.isTool,isTraceRecorded:e.isTraceRecorded,isSanyReported:e.isSanyReported,isWarningEnabled:e.isWarningEnabled,version:e.version});ie(me,t,c);let w=me.environment,T=oe(t,w,()=>p(e.source,de),c);if(y(me.assumptions,w)||!T||T.spec.init===void 0||T.spec.next===void 0||T.properties.liveness.length>0||d(w))return ne();let he=u(),E={fingerprints:x()},D=/* @__PURE__ */ new Int32Array(2),ge=Array.from({length:le},S),O={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,initialStates:void 0,outDegrees:Array.from({length:32},()=>0)},_e=[],k=()=>({status:`success`,violation:void 0,failure:void 0,...O,fingerprintDistance:ee(O.distinctStates,O.generatedStates,()=>{let e=new BigInt64Array(O.distinctStates);return _e.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),ve=e=>{let t=[];for(let n of l(e,w,T.spec.scope))if(b(O.generatedStates,c),he(n),O.generatedStates++,v(T.getFingerprintState(n),D),ae(E.fingerprints)&&(E.fingerprints=_(E.fingerprints)),re(E.fingerprints,D[0],D[1])){if(T.findViolatedInvariant(n)||T.findFailedInitialPredicate(n))return!1;if(T.satisfiesConstraints(n)){if(!ge[t.length%le].encode(n))return!1;t.push(n),O.distinctStates++}}return _e.push(BigInt64Array.from(t,e=>w.runtime.getFingerprint(e))),!0};c({kind:`initial-states-started`});try{if(!ve(T.spec.init))return ne()}catch(e){if(!(e instanceof n))throw e;return ne()}if(h()!==C)return ne();if(O.depth=O.generatedStates===0?0:1,O.initialStates={generated:O.generatedStates,distinct:O.distinctStates},c({kind:`initial-states-computed`,initialStates:O.initialStates}),O.distinctStates===0)return k();let ye=[],be={count:le,resolve:e=>{}},xe=e=>{ye.push(e),(e.type===`abort`||ye.length===be.count)&&be.resolve(ye.splice(0))},A=e=>new Promise(t=>{be.count=e,be.resolve=t}),Se=A(le),j=new Int32Array(new SharedArrayBuffer(le*4)),Ce=new Int32Array(new SharedArrayBuffer(le*4)),we=await Promise.all(Array.from({length:le},()=>o(new URL(`./parallel-worker.js`,import.meta.url),e=>xe(e),()=>xe({type:`abort`})))),Te=()=>we.forEach(e=>e.terminate()),Ee=/* @__PURE__ */ new Map,De=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=Ee.get(n)??new MessageChannel;return Ee.set(n,r),e<t?r.port1:r.port2};we.forEach((n,r)=>{let i=Array.from({length:le},(e,t)=>t===r?void 0:De(r,t)),a=ge[r].finish(),o={type:`start`,source:e.source,config:t,modules:[...ue],classes:[...fe],index:r,ports:i,seed:a,isTool:e.isTool,isTraceRecorded:e.isTraceRecorded,isWarningEnabled:e.isWarningEnabled,version:e.version,fingerprints:E.fingerprints,requests:j,remaining:Ce};n.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let Oe=e=>e.some(e=>e.type===`abort`),ke=e=>we.forEach(t=>t.postMessage(e)),Ae=async e=>{let t=e.filter(e=>e.type===`paused`).length;if(t===0||Oe(e))return e;E.fingerprints=_(E.fingerprints);let n=A(t);return ke({type:`resize`,fingerprints:E.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await Ae(await n)]};if(Oe(await Se))return Te(),ne();for(let e=1;;e++){let t=A(le);j.forEach((e,t)=>Atomics.store(j,t,0)),ke({type:`level`,level:e});let n=await Ae(await t);if(Oe(n))return Te(),ne();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(O.generatedStates+=r.reduce((e,t)=>e+t.generated,0),O.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>O.outDegrees[t]+=e),_e.push(e.fingerprints)}),i===0)return Te(),k();O.depth++}},de=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}`},fe=e=>`File ${JSON.stringify(e.file)}, ${de(e)}`,pe=e=>`${e?fe(e):`<unknown location>`}:\n`,C=(e,t)=>({text:`${pe(e)}Error: ${t}`,channel:`stderr`}),me=e=>e?`${fe(e)} :\n`:``,w=e=>({kind:`Shift`,amount:e}),T=(e,t)=>({kind:`Cons`,expression:e,rest:t}),he=(e,t)=>e.reduce((e,t)=>T(t,e),t),E=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},D=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},ge=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},O=(e,t,n)=>D({kind:`Apply`,operator:D({kind:`Internal`,builtin:e},n),args:t},n),_e=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},k=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),ve=(e,t)=>t.reduce(k,e),ye=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},be=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(ge(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},xe=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},A=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},Se=(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()}}},j=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),Ce=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),we=(e,t,n)=>{switch(e.kind){case`Shift`:return D({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?D(De(e.expression),n):we(e.rest,t-1,n);case`Compose`:return M(e.outer,we(e.inner,t,n));case`Bump`:return t<=e.amount?D({kind:`Ix`,index:t},n):M(w(e.amount),we(e.rest,t-e.amount,n))}},Te=(e,t)=>t.map(t=>M(e,t)),Ee=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e(`Arity mismatch`);return De(M(he(n,w(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?De(t):{kind:`Apply`,operator:t,args:n}},De=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},Oe=(e,t)=>[E(t.length,e),Re(t,t=>M(e,t))],ke=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return Ve(t,t=>M(e,t));case`Instance`:{let n=E(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:M(n,e.expression)}))}}}}},Ae=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:M(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ke(e,t.definition)};case`Fact`:return{...t,expression:M(e,t.expression)}}},je=(e,t)=>{let[n,r]=A(e,t.context,(e,t)=>[E(1,e),Ae(e,t)]);return{context:r,active:M(n,t.active)}},M=(e,t)=>{let n=t=>M(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return we(e,t.index,t);case`Apply`:return D(Ee(n(t.operator),Te(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>ze(e,n))};case`Lambda`:return{...t,body:M(E(t.params.length,e),t.body)};case`Let`:{let[n,r]=A(e,t.definitions,(e,t)=>[E(1,e),ke(e,t)]);return{...t,definitions:r,body:M(n,t.body)}}case`Sequent`:return{...t,sequent:je(e,t.sequent)};case`With`: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:Te(e,t.items)};case`Quant`:{let[n,r]=Oe(e,t.bounds);return{...t,bounds:r,body:M(n,t.body)}}case`Tquant`:return{...t,body:M(E(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:M(E(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:M(E(1,e),t.body)};case`SetOf`:{let[n,r]=Oe(e,t.bounds);return{...t,bounds:r,element:M(n,t.element)}}case`SetEnum`:return{...t,elements:Te(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`Fcn`:{let[n,r]=Oe(e,t.bounds);return{...t,bounds:r,body:M(n,t.body)}}case`FcnApp`:return{...t,function:n(t.function),args:Te(e,t.args)};case`Product`:return{...t,factors:Te(e,t.factors)};case`Tuple`:return{...t,elements:Te(e,t.elements)};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:Be(t.specs,n)};case`Dot`:return{...t,expression:n(t.expression)};case`Sub`:case`Tsub`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Fair`:return{...t,subscript:n(t.subscript),action:n(t.action)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)};case`Parens`:return{...t,expression:n(t.expression)}}},N=(e,t)=>e===0?t:M(w(e),t),P=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),Me=(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||!F(t,n))return!1}return!0},Ne=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&F(e.domain.expression,t.domain.expression)),Pe=(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`&&P(e.args,t.args,F);case`Label`:return t.kind===`Label`&&e.label===t.label&&P(e.args,t.args,F);default:return!0}},Fe=(e,t)=>{if(e.kind===`Operator`&&t.kind===`Operator`||e.kind===`Bpragma`&&t.kind===`Bpragma`)return F(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 P(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&Me(n,r)}return!1},Ie=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level!==t.level||e.shape!==t.shape?!1:!e.domain||!t.domain?!e.domain&&!t.domain:F(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?Fe(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&F(e.expression,t.expression),Le=(e,t)=>P(e.context,t.context,Ie)&&F(e.active,t.active),F=(e,t)=>{if(e.kind===`Parens`)return F(e.expression,t);if(t.kind===`Parens`)return F(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&&F(e.body,t.body);case`Apply`:return t.kind===`Apply`&&F(e.operator,t.operator)&&P(e.args,t.args,F);case`Sequent`:return t.kind===`Sequent`&&Le(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&F(e.expression,t.expression)&&P(e.selectors,t.selectors,Pe);case`With`:return t.kind===`With`&&F(e.expression,t.expression);case`Let`:return t.kind===`Let`&&P(e.definitions,t.definitions,Fe)&&F(e.body,t.body);case`If`:return t.kind===`If`&&F(e.condition,t.condition)&&F(e.consequent,t.consequent)&&F(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&P(e.items,t.items,F);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&P(e.bounds,t.bounds,Ne)&&F(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&P(e.names,t.names,(e,t)=>e===t)&&F(e.body,t.body);case`Choose`:return t.kind===`Choose`?e.domain&&t.domain?F(e.domain,t.domain)&&F(e.body,t.body):!e.domain&&!t.domain&&F(e.body,t.body):!1;case`SetSt`:return t.kind===`SetSt`&&F(e.domain,t.domain)&&F(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&F(e.element,t.element)&&P(e.bounds,t.bounds,Ne);case`SetEnum`:return t.kind===`SetEnum`&&P(e.elements,t.elements,F);case`Arrow`:return t.kind===`Arrow`&&F(e.domain,t.domain)&&F(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&P(e.bounds,t.bounds,Ne)&&F(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&P([e.function,...e.args],[t.function,...t.args],F);case`Tuple`:return t.kind===`Tuple`&&P(e.elements,t.elements,F);case`Product`:return t.kind===`Product`&&P(e.factors,t.factors,F);case`Rect`:return t.kind===`Rect`&&Me(e.fields,t.fields);case`Record`:return t.kind===`Record`&&Me(e.fields,t.fields);case`Except`:return t.kind===`Except`&&F(e.function,t.function)&&P(e.specs,t.specs,(e,t)=>P(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&F(e.expression,t.expression))&&F(e.value,t.value));case`Dot`:return t.kind===`Dot`&&F(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&F(e.action,t.action)&&F(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&F(e.subscript,t.subscript)&&F(e.action,t.action);case`Case`:return t.kind!==`Case`||!(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:F(e.arms[0].condition,t.arms[0].condition)&&F(e.arms[0].body,t.arms[0].body))?!1:e.other&&t.other?F(e.other,t.other):!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}},Re=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),ze=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,Be=(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}}),Ve=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,He=(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:Ve(e.definition,t)}:{...e,expression:t(e.expression)},I=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,j(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=j(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]=A(e,t.sequent.context,(e,t)=>{let a=He(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]=A(e,t.definitions,(e,t)=>{let i=Ve(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=Re(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=Re(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?Ce(t.name,i):j(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=Ce(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>ze(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=Be(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}}}},Ue=(e,t)=>I(void 0,e,(e,n)=>t(n),()=>void 0,`all`),We=e=>{let t=[];return Ue(e,e=>(t.push(e),e)),t},Ge={kind:`Opaque`,name:`$Bad`},Ke=e=>e.kind===`Opaque`&&e.name===Ge.name,qe=e=>{let t=e.kind===`Parens`?qe(e.expression):Ue(e,qe);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},Je=e=>e.kind===`Let`?D({kind:`Let`,definitions:e.definitions,body:Je(e.body)},e.body):e.kind===`Parens`?Je(e.expression):Ue(e,Je),Ye=e=>e.kind===`Ix`?e.index<=0:We(e).some(Ye),Xe=(e,t,n)=>{let r=(e,r=n)=>Xe(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=>j(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=>j(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,j(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 We(e)){let e=r(t);if(e)return e}return}},Ze=(e,t)=>he(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),w(e+t)),Qe=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),$e=(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(C(n.location,a)),new e(a,{failure:`Expr.Deref.deref_inst`})}let i=n.kind===`SetOf`?n.element:n.body;return M(he(r,w(0)),i)}case`Tquant`:return $e(t,D({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 $e(t,D({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(C(n.location,i)),new e(i,{failure:`Expr.Deref.deref_inst`})}return M(he(r,w(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw t(C(n.location,r)),new e(r,{failure:`Expr.Deref.deref_inst`})}}},et=(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(C(r.location,n)),new e(n,{failure:`Expr.Deref.deref_at`})}}})(),a=M(Ze(n,i.length),r);return[i,$e(t,a,Qe(i.length))]},tt=(t,n,r,i,a,o)=>{let s=n=>{if(!(i<=n))throw t(C(a.location,o)),new e(o,{failure:`Expr.Deref.deref_num`})},c=e=>(s(e.length),e[i-1]),l=(()=>{switch(r.kind){case`Sequent`:{let a=r.sequent;s(a.context.length+1);let o=a.context[i-1];if(o&&o.kind!==`Fact`){let n=`subexpression reference does not resolve to an expression`;throw t(C(r.location,n)),new e(n,{failure:`Expr.Deref.deref_num`})}let c=M(w(-(i-1)),o?o.expression:a.active);if(Ye(c))throw t(C(r.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
10
+ Tlapm does not handle yet such subexpression namings.`)),new e(`Subexpression of ASSUME/PROVE uses identifiers declared therein
11
+
12
+ Tlapm does not handle yet such subexpression namings.`,{failure:`Expr.Deref.deref_num`});return[n,c]}case`Apply`:return[n,c(r.args)];case`With`:return tt(t,n,r.expression,i,a,o);case`If`:return[n,c([r.condition,r.consequent,r.alternative])];case`List`:return[n,c(r.items)];case`SetEnum`:case`Tuple`:return[n,c(r.elements)];case`Product`:return[n,c(r.factors)];case`Let`:return s(1),[[...n,...r.definitions],r.body];case`Quant`:case`SetOf`:case`Fcn`:return[n,c(r.bounds.flatMap(e=>e.domain.kind===`Domain`?[e.domain.expression]:[]))];case`Choose`:case`SetSt`:if(!r.domain)break;return[n,c([r.domain])];case`Arrow`:return[n,c([r.domain,r.range])];case`FcnApp`:{let e=r.args.length===1?r.args[0]:D({kind:`Tuple`,elements:r.args},r);return[n,c([r.function,e])]}case`Rect`:case`Record`:return[n,c(r.fields.map(e=>e.value))];case`Dot`:return[n,c([r.expression,D({kind:`String`,value:r.field},r)])];case`Except`:return[n,c([r.function,...r.specs.map(e=>e.value)])];case`Sub`:case`Tsub`:return[n,c([r.action,r.subscript])];case`Fair`:return[n,c([r.subscript,r.action])];case`Case`:return[n,c([...r.arms.map(e=>D({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...r.other?[D({kind:`Tuple`,elements:[Ge,r.other]},r.other)]:[]])]}let l=`Expression has no subexpressions`;throw t(C(r.location,l)),new e(l,{failure:`Expr.Deref.deref_num`})})();if(Ke(l[1])){let n=`Cannot resolve subexpression reference !${i}`;throw t(C(r.location,n)),new e(n,{failure:`Expr.Deref.deref_num`})}return l},nt=(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])},rt=(t,n,i,a,o)=>{let s=Xe(i,a,[]);if(!s)return t(C(i.location,`Could not find label ${a}`)),{params:[],definitions:[],expression:Ge};let c=s.indices;if(c.length!==o.length&&o.length>0){let n=c.length===1?``:`s`,r=`Expected ${c.length} argument${n} for labelled reference !${a}, but found ${o.length}`;throw t(C(s.expression.location,r)),new e(r,{failure:`Expr.Deref.deref_lsub`})}let l=o.length===0?c.map(e=>({name:e.name,shape:0})):[],u=o.length===0?Qe(c.length):o,d=s.context.reduceRight((e,t)=>t.kind===`Defn`?D({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?D({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):M(w(-1),e),s.expression),f=M(Ze(n,l.length),d),p=[],m=f,h=nt(c.map(e=>e.index),u);for(;h.length>0;)if(m.kind===`Let`&&m.definitions.length===1)p.push(m.definitions[0]),m=m.body,h=h.map(e=>M(w(1),e));else{if(m.kind!==`Quant`||m.bounds.length!==1)throw new r(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);m=M(T(h[0],w(0)),m.body),h=h.slice(1)}return{params:l,definitions:p,expression:m}},it=(t,n,r,i,a)=>{if(r.kind!==`Let`)throw t(C(r.location,`not a LET expression`)),new e(`not a LET expression`,{failure:`Expr.Deref.deref_letop`});let o=r.definitions.findIndex(e=>e.kind===`Operator`&&e.name===i),s=r.definitions[o];if(!s||s.kind!==`Operator`){let n=`no definition of operator ${i}`;throw t(C(r.location,n)),new e(n,{failure:`Expr.Deref.deref_letop`})}let c=s.body,l=c.kind===`Lambda`?D({...c,body:D({kind:`Parens`,expression:c.body,form:{kind:`Xlabel`,label:i,indices:c.params.map((e,t)=>({name:e.name,index:c.params.length-t}))}},c.body)},c):D({kind:`Parens`,expression:c,form:{kind:`Xlabel`,label:i,indices:[]}},c);return rt(t,n,D({kind:`Let`,definitions:r.definitions.slice(0,o),body:l},c),i,a)},at=(t,n,r,i)=>{let[a,...o]=i;if(!a){let e=r.definitions.length===0?r.expression:D({kind:`Let`,definitions:r.definitions,body:r.expression},r.expression),t=r.params.length===0?e:D({kind:`Lambda`,params:r.params,body:e},e);return{...qe(t),isAtomic:!0}}if(r.expression.isAtomic)return t(C(r.expression.location,`Expression has no subexpressions`)),Ge;let s=n?r.expression:Je(r.expression),c=r.definitions.length,l=(()=>{let i=(e,n)=>{let[i,a]=tt(t,[],s,e,r.expression,n);return{params:[],definitions:i,expression:a,rest:o,isLabel:!1}};switch(a.kind){case`Down`:{let[r,...i]=o;if(s.kind===`Let`&&r?.kind===`Label`&&n)return{...it(t,c,s,r.label,r.args),rest:i,isLabel:!0};if(n)return{params:[],definitions:[],expression:s,rest:o,isLabel:!1};throw new e(`!: 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:$e(t,s,a.args),rest:o,isLabel:!1};case`Label`:return{...s.kind===`Let`&&!n?it(t,c,s,a.label,a.args):rt(t,c,s,a.label,a.args),rest:o,isLabel:!0};case`At`:{let[e,n]=et(t,c,s);return{params:e,definitions:[],expression:n,rest:o,isLabel:!1}}}})();return at(t,l.isLabel,{params:[...r.params,...l.params],definitions:[...r.definitions,...l.definitions],expression:l.expression},l.rest.map(e=>ze(e,e=>M(w(l.definitions.length),e))))},ot=(e,t,n)=>{if(n.length>0)return{params:[],definitions:[],expression:$e(e,t,n)};if(t.kind!==`Lambda`)return{params:[],definitions:[],expression:t};let[r,i]=et(e,0,t);return{params:r,definitions:[],expression:i}},st=(t,n,r,i)=>{let a=at(t,!0,ot(t,n,r),i);if(Ke(a)){let r=`Could not resolve subexpression reference`;throw t(C(n.location,r)),new e(r,{failure:`Expr.Anon: 2`})}return a},ct=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),lt=e=>O(`UNCHANGED`,[e],e),ut=e=>t=>{let n=ut(e);return e(t,n)??Ue(t,n)},dt=ut((e,t)=>e.kind===`Apply`&&ct(e,[`Leadsto`])?O(`BoxTrue`,[O(`Implies`,[t(e.args[0]),O(`Diamond`,[t(e.args[1])],e)],e)],e):void 0),ft=ut(e=>{if(e.kind!==`Fair`)return;let t=e.action,n=e.subscript,r=O(`ENABLED`,[D({kind:`Sub`,modal:`Dia`,action:t,subscript:n},t)],t),i=e.fairness===`Weak`?`Diamond`:`BoxTrue`,a=e.fairness===`Weak`?`BoxTrue`:`Diamond`;return O(`Implies`,[O(i,[O(a,[r],t)],t),O(`BoxTrue`,[D({kind:`Tsub`,modal:`Dia`,action:t,subscript:n},t)],t)],t)}),pt=ut((e,t)=>{if(e.kind!==`Sub`&&e.kind!==`Tsub`)return;let n=t(e.action),r=t(e.subscript),i=e.modal===`Box`?O(`Disj`,[n,lt(r)],e):O(`Conj`,[n,O(`Neg`,[lt(r)],e)],e);return e.kind===`Sub`?i:O(e.modal===`Box`?`BoxTrue`:`Diamond`,[i],e)}),mt=e=>e.kind===`Tuple`?e.elements.flatMap(mt):[e],ht=ut(e=>{if(e.kind!==`Apply`||!ct(e,[`UNCHANGED`]))return;let t=mt(e.args[0]).map(e=>O(`Eq`,[O(`Prime`,[e],e),e],e));return t.length===0?D({kind:`Internal`,builtin:`TRUE`},e):t.length===1?t[0]:D({kind:`List`,bullet:`And`,items:t},e)}),gt=[`Prime`,`StrongPrime`,`Leadsto`,`ENABLED`,`UNCHANGED`,`Cdot`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`],_t=/* @__PURE__ */ new WeakMap,vt=(e,t)=>{switch(t.kind){case`Fresh`:return t.level===`Constant`;case`Defn`:return t.definition.kind===`Operator`&&bt(e,t.definition.body);case`Fact`:return bt(e,t.expression);case`Flex`:return!1}},yt=(e,t)=>t.reduce((e,t)=>k(e,j(t,`Constant`)),e),bt=(e,t)=>{let n=t=>bt(e,t);switch(t.kind){case`Ix`:{let n=xe(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=_t.get(i);if(a!==void 0)return a;let o=bt(n?.rest,i);return _t.set(i,o),o}case`Opaque`:case`String`:case`Num`:case`At`:return!0;case`Internal`:return!gt.includes(t.builtin);case`Tquant`:case`Sub`:case`Tsub`:case`Fair`:return!1;case`Lambda`:return bt(yt(e,t.params.map(e=>e.name)),t.body);case`Sequent`:{let n=t.sequent.context.reduce((e,t)=>({scope:k(e.scope,t),isGood:e.isGood&&vt(e.scope,t)}),{scope:e,isGood:!0});return n.isGood&&bt(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:k(e.scope,{kind:`Defn`,definition:t,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),isGood:e.isGood&&t.kind===`Operator`&&bt(e.scope,t.body)}),{scope:e,isGood:!0});return n.isGood&&bt(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))&&bt(yt(e,t.bounds.map(e=>e.name)),r)}case`Choose`:case`SetSt`:return(t.domain===void 0||n(t.domain))&&bt(yt(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))}},xt=(e,t,n)=>{if(bt(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=>xt(e,t,n));if(t.kind===`Sequent`){let r=t.sequent.context.reduce(k,e);return xt(r,t.sequent.active,n)}if(t.kind!==`Apply`)return!1;let r=t.args;return ct(t,[`BoxTrue`,`BoxFalse`])&&n||ct(t,[`Diamond`])&&!n?!0:r.length===1&&ct(t,[`BoxTrue`,`BoxFalse`,`Diamond`,`Prime`])?xt(e,r[0],n):r.length===1&&ct(t,[`Neg`])?xt(e,r[0],!n):r.length===2&&ct(t,[`Conj`,`Disj`])?xt(e,r[0],n)&&xt(e,r[1],n):r.length===2&&ct(t,[`Implies`])?xt(e,r[0],!n)&&xt(e,r[1],n):r.length===2&&ct(t,[`Equiv`])?[!0,!1].every(t=>xt(e,r[0],n!==t)&&xt(e,r[1],n===t)):xt(e,t.operator,n)&&r.every(t=>xt(e,t,n))},St=(e,t)=>xt(e,dt(ft(pt(ht(t)))),!0)?`Always`:`Now`,Ct=(e,t)=>t===`Always`&&e.some(e=>e.kind===`Fact`&&e.time===`Now`)?`Now`:t,wt=e=>e.kind===`Named`?`<${e.level}>${e.label}`:`<${e.level}>`,Tt=e=>++e.value,Et={kind:`Fact`,expression:{kind:`At`,isExcept:!1},visibility:`Visible`,time:`Always`},Dt={Number:`1NUM`,Down:`1DOWN`,At:`1AT`,Instance:`1INST`,Left:`1`,Right:`1`},Ot={kind:`Opaque`,name:`$badexp`},kt=(t,n,i)=>{let a,o=e=>e.scope?.size??0,s=(e,t)=>{if(t.kind===`At`&&t.isExcept)return a?N(o(e)-a.size,a.expression):t;if(t.kind!==`Except`)return f(e,t);let n=s(e,t.function);return t.specs.reduce((n,r)=>{let[i,c]=A(n,r.trail,(t,n)=>{if(n.kind===`Dot`)return[D({kind:`Dot`,expression:t,field:n.field},t),n];let r=s(e,n.expression);return[D({kind:`FcnApp`,function:t,args:[r]},t),{kind:`Apply`,expression:r}]}),l=a;a={expression:i,size:o(e)};let u=s(e,r.value);return a=l,D({kind:`Except`,function:n,specs:[{trail:c,value:u}]},t)},n)},c=(e,t,n)=>{let r=D({kind:`Ix`,index:e},n);return t.length===0?r:D({kind:`Apply`,operator:r,args:t},n)},l=(e,t,n,r,i)=>{if(t!==`Builtin`)return c(e,r,i);let a=N(e,n);return D(r.length===0?a:Ee(a,r),i)},u=(t,n,a,o)=>{let s=be(t.scope,n);if(!s){let t=`Operator "${n}" not found`;throw i(C(o.location,t)),new e(t,{failure:`Expr.Anon: 4`})}let u=s.depth+1,d=s.hyp;switch(d.kind){case`Defn`:{let t=d.definition;if(t.kind===`Operator`)return l(u,d.whereDefined,t.body,a,o);if(t.kind===`Recursive`)throw new e(`Recursive operators not supported by TLAPS`,{failure:`Expr.Anon: Recursive`});return c(u,a,o)}case`Fresh`:return c(u,a,o);case`Flex`:return D({kind:`Ix`,index:u},o);case`Fact`:throw new r(`File "src/expr/e_anon.ml", line 230, characters 24-36: Assertion failed`)}},d=(t,n,r,a,o,c)=>{let u=be(t.scope,n);if(!u){let[o,...l]=a;if(o?.kind===`Label`){let e=o.args.map(e=>s(t,e));return d(t,`${n}!${o.label}`,[...r,...e],l,!0,c)}let u=`Operator "${n}" not found`;throw o&&i(C(c.location,u)),new e(u,{failure:`Expr.Anon: ${o?Dt[o.kind]:`1EMPTY`}`})}let f=u.hyp;if(f.kind!==`Defn`||f.definition.kind!==`Operator`&&f.definition.kind!==`Bpragma`)throw new e(`invalid subexpression reference`);let p=u.depth+1;if(a.length===0&&o)return r.length===0?D({kind:`Ix`,index:p},c):l(p,f.whereDefined,f.definition.body,r,c);let m=At(N(p,f.definition.body),c);return At(st(i,m,r,a),c)},f=(e,t)=>{switch(t.kind){case`Bang`:{let n=t.expression;if(n.kind===`Apply`&&n.operator.kind===`Opaque`){let r=t.selectors.map(t=>ze(t,t=>s(e,t))),i=n.args.map(t=>s(e,t)),a={warnedSteps:[],scope:e.scope};return d(a,n.operator.name,i,r,!1,t)}return s(e,{...t,expression:D({kind:`Apply`,operator:n,args:[]},n)})}case`Apply`:{if(t.operator.kind!==`Opaque`)return _(e,t);let n=t.operator.name;if(e.warnedSteps.includes(n))return i({text:`${me(t.location)}Warning: ${n} does not introduce any assumptions. It does not make sense to use it here.\n`,channel:`toolbox`}),D({kind:`Internal`,builtin:`TRUE`},t);let r=t.args.map(t=>s(e,t));return u(e,n,r,t)}case`Opaque`:return s(e,D({kind:`Apply`,operator:t,args:[]},t));case`Parens`:return t.form.kind===`Syntax`?s(e,t.expression):{...t,expression:s(e,t.expression),form:p(e,t.form)};default:return _(e,t)}},p=(t,n)=>n.kind===`Nlabel`?{kind:`Xlabel`,label:n.label,indices:n.names.map(n=>{let r=be(t.scope,n);if(!r)throw new e(`Identifier "${n}" in label parameters not found`);return{name:n,index:r.depth+1}})}:n,m=(e,t)=>({warnedSteps:e.warnedSteps,scope:t}),h=(e,t)=>m(e,k(e.scope,t)),g=(e,t)=>{let n=Re(t,t=>s(e,t));return[n.reduce((e,t)=>h(e,j(t.name,t.level)),e),n]},_=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:ee(e,t.sequent)[1]};if(t.kind===`Let`){let[n,r]=y(e,t.definitions);return{...t,definitions:r,body:s(n,t.body)}}return I(e,t,s,h)},v=(e,t)=>{if(t.kind!==`Operator`)return t;let n=t.body;if(n.kind!==`Fcn`)return{...t,body:s(e,n)};let r=s(h(e,j(t.name,`Constant`)),n);if(F(M(T({kind:`Opaque`,name:`%%%`},w(1)),r),r))return{...t,body:N(-1,r)};let i=O(`Eq`,[D({kind:`Ix`,index:1},r),r],r);return{...t,body:D({kind:`Choose`,name:t.name,domain:void 0,body:i},r)}},y=(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=v(r,t);r=h(r,{kind:`Defn`,definition:o,whereDefined:`User`,visibility:`Visible`,isLocal:!0,isConstnessUnset:!0}),a.push(o)}return[r,a]},b=(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:s(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:v(e,t.definition)};case`Fact`:{let n=s(e,t.expression);return{...t,expression:n,time:St(e.scope,n)}}}})();return[h(e,n),n]},ee=(e,t)=>{let[n,r]=A(e,t.context,b);return[n,{context:r,active:s(n,t.active)}]},x=(e,t)=>({warnedSteps:[wt(t),...e.warnedSteps],scope:e.scope}),te=(e,t,n,r)=>h(e,{kind:`Defn`,definition:{kind:`Operator`,name:wt(t),body:n,location:r.location},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!0,isConstnessUnset:!0,location:r.location}),S=(e,t)=>m(e,ve(e.scope,Array.from({length:t},()=>Et))),ne=e=>{let t=[...e.context.map((t,n)=>{let r=e.context.length-n+1;if(t.kind===`Fact`)return N(r,t.expression);if(t.kind!==`Fresh`||!t.domain)return Ot;let i=O(`Mem`,[D({kind:`Ix`,index:0},t.domain),t.domain],t.domain);return N(r,i)}),N(1,e.active)];return t.length===1?t[0]:{kind:`Tuple`,elements:t}},re=e=>e.kind!==`Use`&&e.kind!==`Hide`&&e.kind!==`Define`,ie=(e,t)=>({facts:t.facts.map(t=>s(e,t)),defs:t.defs.flatMap(t=>{if(t.kind===`Dx`)return[t];let n=s(e,D({kind:`Opaque`,name:t.name},t));return n.kind===`Ix`?xe(e.scope,n.index-1)?.hyp.kind===`Defn`?[{kind:`Dx`,index:n.index,location:t.location}]:(i({text:`${me(t.location)}${JSON.stringify(t.name)} is not a definition and cannot be used in a DEF clause.`,channel:`toolbox`}),[]):(i({text:`${me(t.location)}Ignored unexpandable identifier ${JSON.stringify(t.name)} in BY DEF.`,channel:`stderr`}),[])})}),ae=(e,t)=>{switch(t.kind){case`Steps`:{let[n,r]=A(e,t.steps,oe),i=ae(t.step?x(n,t.step):n,t.qed.proof);return{...t,steps:r,qed:{...t.qed,proof:i}}}case`By`:return{...t,usable:ie(e,t.usable)};default:return t}},oe=(e,n)=>{let i=n.step?.kind===`Unnamed`&&re(n)?{kind:`Named`,level:n.step.level,label:`_a${Tt(t)}`,isAnonymous:!0}:n.step;if(!i)throw new r;let a={...n,step:i};switch(a.kind){case`Assert`:{let[,t]=ee(e,a.sequent),n=t.context.reduce(h,e),r=S(te(S(n,1),i,D(ne(t),a),a),1),o=t.context.length===0?x(r,i):r,s={...a,sequent:t,proof:ae(o,a.proof)};return[S(te(e,i,D(_e(t),a),a),1),s]}case`Pcase`:{let t=s(e,a.expression),n=D({kind:`Tuple`,elements:[N(2,t)]},a),r=S(te(S(e,2),i,n,a),1),o={...a,expression:t,proof:ae(r,a.proof)},c=te(e,i,D({kind:`Tuple`,elements:[t]},a),a);return[S(c,1),o]}case`Suffices`:{let[,t]=ee(e,a.sequent),n=D({kind:`Tuple`,elements:[D(_e(t),a)]},a),r=S(te(e,i,n,a),1),o={...a,sequent:t,proof:ae(r,a.proof)},s=t.context.reduce(h,e),c=D({kind:`Tuple`,elements:[D(ne(t),a)]},a);return[S(te(S(s,1),i,c,a),1),o]}case`Have`:{let t=s(e,a.expression),n=D({kind:`Tuple`,elements:[N(2,t)]},a);return[S(te(S(e,2),i,n,a),1),{...a,expression:t}]}case`Take`:{let[t,n]=g(e,a.bounds),r=D({kind:`Quant`,quantifier:`Forall`,bounds:n,body:Ot},a);return[S(te(S(t,1),i,r,a),1),{...a,bounds:n}]}case`Witness`:{let t=a.expressions.map(t=>s(e,t)),n=D({kind:`Tuple`,elements:t},a);return[S(te(S(e,1),i,n,a),1),{...a,expressions:t}]}case`Pick`:{let[t,n]=g(e,a.bounds),r=s(t,a.expression),o=D({kind:`Quant`,quantifier:`Exists`,bounds:n,body:r},a),c=x(S(te(S(e,1),i,o,a),1),i),l={...a,bounds:n,expression:r,proof:ae(c,a.proof)},u=n.reduce((e,t)=>h(e,j(t.name,t.level)),S(e,2)),d=N(4+n.length,o);return[S(te(S(u,2),i,d,a),1),l]}case`Use`:{let t=ie(e,a.usable);return[S(e,t.facts.length),{...a,usable:t}]}case`Hide`:return[e,{...a,usable:ie(e,a.usable)}];case`Define`:{let[t,n]=y(e,a.definitions);return[t,{...a,definitions:n}]}case`Forget`:return[e,a]}};return{expr:(e,t)=>s({warnedSteps:[],scope:e},t),defn:(e,t)=>v({warnedSteps:[],scope:e},t),sequent:(e,t)=>ee({warnedSteps:[],scope:e},t)[1],usable:(e,t)=>ie({warnedSteps:[],scope:e},t),proof:(e,t)=>ae({warnedSteps:[],scope:e},t)}},At=(e,t)=>t.location?{...e,location:t.location}:e,jt=1000000010,Mt=new TextEncoder,Nt=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return Mt.encode(e).length;return e.length},Pt=()=>({leftTotal:-1,element:{size:-1,token:{kind:`Text`,text:``},length:0}}),Ft=()=>{let e={size:-1,token:{kind:`Begin`,indent:0,box:`hov`},length:0};return{queue:[e],queueStart:0,scanStack:[Pt(),{leftTotal:1,element:e}],formatStack:[],margin:78,maxIndent:68,spaceLeft:78,currentIndent:0,isNewLine:!0,leftTotal:1,rightTotal:1,depth:1,output:[]}},It=(e,t)=>{e.rightTotal+=t.length,e.queue.push(t)},Lt=(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))},Rt=(e,t)=>{e.spaceLeft-=t,e.output.push(` `.repeat(t))},zt=e=>{let t=e.formatStack.at(-1);t?t.width>e.spaceLeft&&t.box!==`fits`&&t.box!==`h`&&Lt(e,0,t.width):e.output.push(`
15
+ `)},Bt=(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&&zt(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?Lt(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?Lt(e,n.offset,i):Rt(e,n.width);return;case`b`:e.isNewLine?Rt(e,n.width):t>e.spaceLeft||e.currentIndent>e.margin-i+n.offset?Lt(e,n.offset,i):Rt(e,n.width);return;case`hv`:case`v`:Lt(e,n.offset,i);return;case`fits`:case`h`:Rt(e,n.width);return}}}},Vt=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++,Bt(e,n?t.size:jt,t.token),e.leftTotal+=t.length}e.queue.length=0,e.queueStart=0},Ht=(e,t)=>{It(e,t),Vt(e)},Ut=(e,t)=>{let n=e.scanStack.at(-1);n&&(n.leftTotal<e.leftTotal?e.scanStack=[Pt()]:n.element.token.kind===(t?`Break`:`Begin`)&&(n.element.size=e.rightTotal+n.element.size,e.scanStack.pop()))},Wt=(e,t,n)=>{It(e,n),t&&Ut(e,!0),e.scanStack.push({leftTotal:e.rightTotal,element:n})},Gt=(e,t,n)=>{e.depth++,Wt(e,!1,{size:-e.rightTotal,token:{kind:`Begin`,indent:n,box:t},length:0})},Kt=e=>{e.depth<=1||(It(e,{size:0,token:{kind:`End`},length:0}),Ut(e,!0),Ut(e,!1),e.depth--)},qt=(e,t,n)=>Ht(e,{size:t,token:{kind:`Text`,text:n},length:t}),Jt=(e,t,n)=>Wt(e,!0,{size:-e.rightTotal,token:{kind:`Break`,width:t,offset:n},length:t}),Yt=e=>Ht(e,{size:0,token:{kind:`Newline`},length:0}),Xt=e=>{for(;e.depth>1;)Kt(e);return e.rightTotal=jt,Vt(e),e.output.join(``)},Zt=e=>{Xt(e);let t=[...e.output,`
17
+ `];Object.assign(e,Ft()),e.output=t},Qt={h:`h`,v:`v`,hv:`hv`,hov:`hov`,b:`b`},$t=e=>({kind:`Text`,text:e,size:Nt(e)}),L=e=>e===``?[]:[$t(e)],en={kind:`Break`,width:1,offset:0},tn={kind:`Break`,width:0,offset:0},nn=e=>{let t=e.search(/\d|$/);return{kind:`Open`,box:Qt[e.slice(0,t)],indent:Number(e.slice(t)||0)}},R=(e,...t)=>{let n=[],r=0,i=``,a=()=>{i!==``&&(n.push($t(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($t(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(nn(e.slice(o+3,t))),o=t;break}case`]`:n.push({kind:`Close`}),o++;break;case` `:n.push(en),o++;break;case`,`:n.push(tn),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},z=(e,t,n=[$t(`,`),en])=>e.flatMap((e,r)=>r===0?[t(e)]:[n,t(e)]),rn=(e,t)=>{for(let n of t)if(Array.isArray(n))rn(e,n);else switch(n.kind){case`Open`:Gt(e,n.box,n.indent);break;case`Close`:Kt(e);break;case`Text`:qt(e,n.size,n.text);break;case`Break`:Jt(e,n.width,n.offset);break;case`Newline`:Yt(e);break;case`Flush`:Zt(e)}},an=e=>{let t=Ft();return rn(t,e),Xt(t)},on=e=>e.salt===0?e.rep:`${e.rep}_${e.salt}`,sn=()=>({stack:[],idents:/* @__PURE__ */ new Map,defined:/* @__PURE__ */ new Map}),cn=(e,t)=>{let n=e.stack[e.stack.length-t];return n&&on(n)},ln=(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(on(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=on(r);return e.defined.set(a,(e.defined.get(a)??0)+1),a},un=(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=on(t),r=(e.defined.get(n)??1)-1;r===0?e.defined.delete(n):e.defined.set(n,r)}},dn=(e,t,n)=>{let r=n(t.map(t=>ln(e,t)));return un(e,t.length),r},fn=[[`=>`,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`,[]]],pn=/* @__PURE__ */ new Map;for(let[e,t,n,r,i]of fn){let a={name:e,low:t,high:n,fixity:r};for(let t of[e,...i])pn.set(t,a)}const mn=e=>({name:e,low:-1,high:-1,fixity:`Nonfix`}),hn=e=>pn.get(e)??mn(e),gn={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:`@@`},_n=e=>{if(e===`Divides`)return{name:`?|`,low:10,high:11,fixity:`InfixNon`};if(e===`Uminus`)return{...hn(`-.`),name:`-`};let t=gn[e];return t?hn(t):mn(e)},vn=(e,t)=>t.kind===`Atm`||t.kind===`Op`&&e<t.low,yn=e=>[R(`(`),e,R(`)`)],bn=(e,t)=>t?xn(e):yn(xn(e)),xn=e=>{if(e.kind!==`Op`)return e.doc;let t=e.skeleton,n=t=>vn(e.high,t);switch(t.kind){case`Prefix`:case`Postfix`:{let r=t.operand,i=bn(r,n(r)||r.kind===`Op`&&r.skeleton.kind===t.kind),a=t.kind===`Prefix`?[e.doc,i]:[i,e.doc];return[R(`@[<h>`),...a,R(`@]`)]}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[R(`@[<b0>`),bn(r,a),e.doc,bn(i,o),R(`@]`)]}}},B=e=>({kind:`Atm`,doc:e}),Sn=e=>({kind:`Big`,doc:e}),Cn=e=>e.kind===`Lambda`?Cn(e.body):e.kind===`Sequent`?Cn(e.sequent.active):e.kind===`With`,wn=e=>{if(e.kind===`Defn`){let t=e.definition,n=t.kind===`Operator`&&Cn(t.body);return e.visibility===`Hidden`||n||e.whereDefined!==`User`}return e.kind===`Fact`?e.visibility===`Hidden`||Cn(e.expression):!1},Tn=e=>e===0?[]:R(`@[<hov1>(%a)@]`,z(Array.from({length:e},()=>`_`),L)),En=e=>R(`%s%a`,e.name,Tn(e.shape)),Dn={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`UNKNOWN`},On=(t=[])=>{let n=sn(),r=e=>xn(u(e)),i=(e,t)=>dn(n,e.map(e=>e.name),()=>R(`@[<b2>LAMBDA @[<hv0>%a@] :@ %a@]`,z(e,En),r(t))),a=(e,t)=>{let i=e.map(e=>e.domain.kind===`Domain`?r(e.domain.expression):void 0);return dn(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(z(r,t=>{let n=z(t.names,L),r=e[t.index].domain;return r.kind===`NoDomain`?n:r.kind===`Ditto`?R(`@[<hov0>%a@ \\in ??????@]`,n):R(`@[<hov0>%a@ \\in %a@]`,n,i[t.index]??[])}))})},o=e=>{switch(e.kind){case`Down`:return R(`:`);case`Left`:return R(`<<`);case`Right`:return R(`>>`);case`At`:return L(`@`);case`Number`:return L(String(e.value));case`Instance`:return R(`@[<b1>(%a)@]`,z(e.args,r));case`Label`:return e.args.length===0?L(e.label):R(`@[<b2>%s@,@[<b1>(%a)@]@]`,e.label,z(e.args,r))}},s=e=>e.length===0?[]:[R(`!`),z(e,o,R(`!`))],c=e=>{if(e<0)return`#$$${Math.abs(e)}`;if(e===0)return`#$0`;if(e<=n.stack.length)return cn(n,e);let r=t[t.length-(e-n.stack.length)];return r?ge(r)??`??? FACT ???`:`#$${e}`},l=(t,n)=>{if(t.kind===`Lambda`)return{kind:`Op`,name:` `,doc:R(`@ `),low:20,high:20,skeleton:{kind:`Infix`,assoc:`Left`,left:Sn(i(t.params,t.body)),right:B(R(`(%a)`,z(n,r)))}};if(t.kind===`Bang`)return n.length===0?u(t):B(R(`@[<b2>%a@[<b1>(%a)@]@]`,r(t),z(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 B(R(`@[<h>@<1>%s%a@<1>%s@]`,`<[`,r(n[0]),`]>`))}let a=(()=>{switch(t.kind){case`Ix`:return hn(c(t.index));case`Opaque`:{let e=hn(t.name);return{...e,name:`?${e.name}`}}case`Internal`:return _n(t.builtin);default:throw new e(`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 B(L(a.name));if(a.fixity===`Nonfix`)return B(R(`@[<b2>%s@[<b1>(%a)@]@]`,a.name,z(n,r)));if(a.fixity===`Prefix`&&n.length===1)return o(/[A-Za-z]$/.test(a.name)?R(`%s@ `,a.name):L(a.name),{kind:`Prefix`,operand:u(n[0])});if(a.fixity===`Postfix`&&n.length===1)return o(L(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===`..`?L(a.name):R(`@ %s `,a.name),{kind:`Infix`,assoc:e,left:u(n[0]),right:u(n[1])})}throw new e(`Arity mismatch for operator ${a.name}`)},u=t=>{switch(t.kind){case`Ix`:case`Opaque`:case`Internal`:return l(t,[]);case`Lambda`:return Sn(i(t.params,t.body));case`Bang`:return B([r(t.expression),s(t.selectors)]);case`Apply`:return l(t.operator,t.args);case`Sequent`:return Sn(p(t.sequent));case`With`:return u(t.expression);case`If`:return Sn(R(`@[<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 B(R(`TRUE`));if(t.bullet===`Refs`&&t.items.length===1)return u(t.items[0]);let e=t.bullet===`Or`?`\\/`:`/\\`;return Sn(R(`@[<v0>%a@]`,z(t.items,t=>R(`@[<h>%s %a@]`,e,r(t)),R(`@,`))))}case`Let`:{let e=z(t.definitions,d,R(`@,`)),i=r(t.body);return un(n,t.definitions.length),Sn([R(`@[<hv0>LET @[<v0>`),e,R(`@]@
19
+ IN %a@]`,i)])}case`Quant`:return a(t.bounds,e=>Sn(R(`@[<b3>%s @[<b0>%a@] :@ %a@]`,t.quantifier===`Forall`?`\\A`:`\\E`,e,r(t.body))));case`Tquant`:return dn(n,t.names,e=>Sn(R(`@[<b4>%s @[<b0>%a@] : %a@]`,t.quantifier===`Forall`?`\\AA`:`\\EE`,z(e,L),r(t.body))));case`Choose`:{let e=t.domain&&r(t.domain);return dn(n,[t.name],([n])=>Sn(e?R(`@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]`,n,e,r(t.body)):R(`@[<b2>CHOOSE %s :@ %a@]`,n,r(t.body))))}case`SetSt`:{let e=r(t.domain);return dn(n,[t.name],([n])=>B(R(`@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]`,n,e,r(t.body))))}case`SetOf`:return a(t.bounds,e=>B(R(`@[<b3>{%a :@ %a}@]`,r(t.element),e)));case`SetEnum`:return B(R(`@[<h>{@[<b0>%a@]}@]`,z(t.elements,r)));case`Arrow`:return B(R(`@[<b3>[%a ->@ %a]@]`,r(t.domain),r(t.range)));case`Fcn`:return a(t.bounds,e=>B(R(`@[<b3>[%a |->@ %a]@]`,e,r(t.body))));case`FcnApp`:{let e=u(t.function),n=e.kind===`Atm`;return B(R(`@[<h>%s%a%s@[<b1>[%a]@]@]`,n?``:`(`,xn(e),n?``:`)`,z(t.args,r)))}case`Product`:if(t.factors.length===1)return u(t.factors[0]);if(t.factors.length===0)throw new e(`Expr.Fmt.fmt_expr: PRODUCT []`);return{kind:`Op`,name:`\\X`,doc:R(`@ \\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 B(R(`@[<b2><<%a>>@]`,z(t.elements,r)));case`Rect`:return B(R(`@[<b1>[%a]@]`,z(t.fields,e=>R(`@[<h>%s : %a@]`,e.name,r(e.value)))));case`Record`:return B(R(`@[<b1>[%a]@]`,z(t.fields,e=>R(`@[<h>%s |-> %a@]`,e.name,r(e.value)))));case`Except`:return B(R(`@[<b3>[%a EXCEPT@ @[<v0>%a@]]@]`,r(t.function),z(t.specs,e=>R(`!@[<h>%a = %a@]`,e.trail.map(e=>e.kind===`Dot`?R(`.%s`,e.field):R(`[%a]`,r(e.expression))),r(e.value)))));case`Dot`:return{kind:`Op`,name:`.`,doc:R(`.`),low:16,high:16,skeleton:{kind:`Infix`,assoc:`Left`,left:u(t.expression),right:B(L(t.field))}};case`Sub`:case`Tsub`:{let e=t.modal===`Box`,n=t.kind===`Sub`?e?`[`:`<<`:e?`[][`:`<><<`;return B(R(`@[<h>%s@[<b2>%a@]%s%a@]`,n,r(t.action),e?`]_`:`>>_`,r(t.subscript)))}case`Fair`:return Sn(R(`@[<h>%s_%a (%a)@]`,t.fairness===`Weak`?`WF`:`SF`,yn(r(t.subscript)),r(t.action)));case`Case`:return Sn(R(`@[<v2>CASE %a%a@]`,z(t.arms,e=>R(`@[<b2>%a ->@ %a@]`,r(e.condition),r(e.body)),R(`@,[] `)),t.other?R(`@,[] @[<b2>OTHER ->@ %a@]`,r(t.other)):[]));case`String`:return B(R(`"%s"`,t.value));case`Num`:return B(L(t.fraction===``?t.integer:`${t.integer}.${t.fraction}`));case`At`:return B(L(`@`));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 B(R(t,e.label,xn(i)))}let a=z(r,L);return i.kind===`Atm`?B(R(`%s(%a)::%a`,e.label,a,xn(i))):i.kind===`Big`?B(R(`%s(%a)::(%a)`,e.label,a,xn(i))):B(R(`(%s(%a):: %a)`,e.label,a,xn(i)))}}},d=e=>{switch(e.kind){case`Operator`:case`Bpragma`:{let t=e.body;if(t.kind===`Lambda`){let i=dn(n,t.params.map(e=>e.name),()=>r(t.body)),a=ln(n,e.name);return R(`@[<b2>%s@[<b1>(%a)@] ==@ %a@]`,a,z(t.params,En),i)}let i=r(t);return R(`@[<b2>%s ==@ %a@]`,ln(n,e.name),i)}case`Instance`:{let t=e.instance,i=dn(n,t.args,e=>({doc:R(`@[<b2>INSTANCE %s%a@]`,t.module,t.substitutions.length===0?[]:R(`@ WITH@ %a`,z(t.substitutions,e=>R(`@[<b2>%s <- %a@]`,e.name,r(e.expression))))),args:e})),a=ln(n,e.name),o=t.args.length===0?L(a):R(`%s (@[<b0>%a@])`,a,z(i.args,L));return R(`@[<b2>%a == %a@]`,o,i.doc)}case`Recursive`:{let t=ln(n,e.name);return R(`@[<b2>NEW CONSTANT %s%a@]`,t,Tn(e.shape))}}},f=e=>{switch(e.kind){case`Fresh`:{let t=e.domain&&e.domainVisibility===`Visible`?r(e.domain):void 0,i=ln(n,e.name);return[R(`NEW %s %s%a`,Dn[e.level],i,Tn(e.shape)),t?R(` \\in %a`,t):[]]}case`Flex`:return R(`NEW VARIABLE %s`,ln(n,e.name));case`Defn`:return d(e.definition);case`Fact`:{let t=R(`@[<h>%a @]`,r(e.expression));return ln(n,``),t}}},p=e=>{if(e.context.length===0)return r(e.active);let t=[];for(let r of e.context)wn(r)?ln(n,ge(r)??``):t.push(f(r));let i=r(e.active);return un(n,e.context.length),t.length===0?i:[R(`@[<v0>ASSUME @[<v0>`),z(t,e=>e),R(`@]@
20
+ PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},kn=(e,t)=>On(e).printExpr(t),An=e=>{let t=On();return an(R(`@[<b0>%a@]`,t.printSequent(e))).trimEnd()},jn={kind:`At`,isExcept:!1},Mn=e=>({location:e.location,step:e.step,isSuppressed:e.isSuppressed,method:e.method}),Nn=e=>e?.kind===`Named`&&e.isAnonymous,Pn=e=>e?.level??0,Fn=e=>D({kind:`Internal`,builtin:`TRUE`},e),In=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2,Ln=(e,...t)=>an(R(e,...t)),Rn=e=>zn(e).map((e,t)=>{let n=e.domain.kind===`Domain`?N(t,e.domain.expression):void 0;return{kind:`Fresh`,name:e.name,shape:0,level:n?`Constant`:e.level,domain:n,domainVisibility:`Visible`}}),zn=e=>{let t={kind:`NoDomain`};return e.map(e=>e.domain.kind===`Ditto`?{...e,domain:t}:(t=e.domain,e))},Bn=(e,t)=>t.context.flatMap((n,r)=>n.kind===`Fact`&&n.visibility===`Visible`?[N(e+t.context.length-1-r,n.expression)]:[]),Vn=(e,t,n)=>{if(!e.step)throw new r;return{kind:`Defn`,definition:{kind:`Operator`,name:wt(e.step),body:t,location:e.location},whereDefined:{kind:`Proof`,time:n},visibility:`Visible`,isLocal:!0,location:e.location}},Hn=(e,t,n,r)=>{let i=Nn(n.step)?`Visible`:`Hidden`,a=t.context.map(e=>e.kind===`Fact`?{...e,visibility:i}:e),o=D({kind:`List`,bullet:`Refs`,items:Bn(2,t)},n),s=Ct(t.context,r);return{context:[...e,...a,{kind:`Fact`,expression:Fn(n),visibility:`Hidden`,time:r,location:n.location},Vn(n,o,s),{kind:`Fact`,expression:D({kind:`Ix`,index:1},n),visibility:`Hidden`,time:s,location:n.location}],active:N(3,t.active),time:s}},Un=(e,t,n,r,i,a)=>{let o=e||Nn(i.step)?`Visible`:`Hidden`;return{context:[...t,Vn(i,D(_e(r),i),a),{kind:`Fact`,expression:D({kind:`Ix`,index:1},i),visibility:o,time:a,location:i.location}],active:N(2,n)}},Wn=(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`},Gn=(t,n,r)=>{if(r.kind!==`Dx`)throw new e(`Unknown definition ${r.name}`);let i=n.length-r.index,a=n[i];if(!a)return n;if(a.kind!==`Defn`)throw new e(`Indicated point is not a definition`);return n.map((e,n)=>n===i?{...a,visibility:t}:e)},Kn=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`Mem`&&e.args[0]?.kind===`Ix`&&e.args[0].index===0&&F(t,e.args[1]),qn=(t,n,r,i)=>{let a=!1,o=r,s=[...i];for(let e=i.length-1;e>=0;e--){o=N(-1,o);let t=i[e];t.kind===`Fact`&&F(t.expression,o)?(a=!0,s[e]={...t,visibility:n}):t.kind===`Fresh`&&t.domain&&Kn(o,t.domain)&&(a=!0,s[e]={...t,domainVisibility:n})}if(!a){let n=`This expression does not appear in the context and cannot be hidden.`;throw t(C(r.location,`${n}\n`)),new e(n,{failure:`proof.Gen.set_expr`})}return s},Jn=(e,t)=>{let n=Oe(w(1),t)[1];return n[0].domain.kind===`Ditto`&&e.domain.kind===`Domain`?[{...n[0],domain:{kind:`Domain`,expression:N(1,e.domain.expression)}},...n.slice(1)]:n},Yn=(e,t)=>{if(e.isSuppressed||t.length===0)return{kind:`Obvious`,...Mn(e)};let n=t.map((t,n)=>{let r=N(2*n+2,t);return{kind:`Assert`,sequent:{context:[],active:r},proof:{kind:`By`,usable:{facts:[N(3,r)],defs:[]},isOnly:!1,location:t.location,method:e.method},location:t.location}}),r={kind:`By`,usable:{facts:[D({kind:`Ix`,index:2*t.length+2},e),...t.map((n,r)=>D({kind:`Ix`,index:2*(t.length-r)},e))],defs:[]},isOnly:!0,...Mn(e),method:void 0};return{kind:`Steps`,steps:n,qed:{proof:r,location:r.location},...Mn(e)}},Xn=(e,t,n)=>({sequent:e,location:t.location,kind:n,method:t.method}),Zn={total:0,absent:[],omitted:[]},Qn=(e,t)=>({total:e.total+t.total,absent:[...e.absent,...t.absent],omitted:[...e.omitted,...t.omitted]}),$n=e=>{switch(e.kind){case`Use`:return{...Zn,total:e.obligations?.length??0};case`Assert`:case`Suffices`:case`Pcase`:case`Pick`:return er(e.proof);default:return Zn}},er=e=>e.kind===`Steps`?[...e.steps.map($n),er(e.qed.proof)].reduce(Qn):e.kind!==`Omitted`||!e.obligations||!e.location?{...Zn,total:e.obligations?.length??0}:{total:e.obligations.length,absent:e.omission===`Implicit`?[e.location]:[],omitted:e.omission===`Explicit`?[e.location]:[]},tr=(e,t)=>e.kind===`At`&&!e.isExcept?D(De(t),e):Ue(e,e=>tr(e,t)),nr=(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:[Xn(t,i,{kind:`Main`})]};case`Omitted`:return{...i,obligations:[Xn(t,i,{kind:`Omitted`,omission:i.omission})]};case`Error`:return{...i,obligations:[Xn(t,i,{kind:`Error`,message:i.message})]};case`By`:throw new e(`Proof.Gen.generate`);case`Steps`:{let[e,n]=A({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=Xn({...t,active:e},n,{kind:`Support`});return[{context:[...t.context,{kind:`Fact`,expression:e,visibility:`Visible`,time:Wn(t.context,e,r),location:e.location,useLocation:n.useLocation}],active:N(1,t.active)},{...n,obligations:[a]},r]}if(i.facts.length>0)throw new e(`Proof.Gen.gen_step: USE with facts and definitions`);let a=i.defs.reduce((e,t)=>Gn(`Visible`,e,t),t.context);return[{...t,context:a},n,r]}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>Gn(`Hidden`,e,t),t.context),a=n.usable.facts.reduceRight((e,t)=>qn(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:N(n.definitions.length,t.active)},n,r];case`Assert`:{let e=Hn(t.context,n.sequent,n,r),i=a(e,n.proof,e.time),o={...n,proof:i};return[Un(!1,t.context,t.active,n.sequent,o,r),o,r]}case`Suffices`:{let e=a(Un(!0,t.context,t.active,n.sequent,n,r),n.proof,r),i={...n,proof:e},o=Hn(t.context,n.sequent,i,r);return[o,i,o.time]}default:throw new e(`Proof.Gen.gen_step`)}},s=(e,t,n,r)=>{let i={kind:`Unnamed`,level:0,id:0},[a,s]=o({context:e,active:{...jn,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=>N(1,e)),[f,p]=c(l,t,{defs:[],facts:d},r);return[f,[...u,...p]]},l=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},u=e=>({kind:`Named`,level:e,label:`_a${Tt(t)}`,isAnonymous:!0}),d=(e,t)=>t?.kind===`Named`?{...t,level:e}:u(e),f=(e,t)=>{let n={...t,step:d(e,t.step)};if(n.kind!==`Steps`)return n;let r=n.steps.map(t=>p(e,t));return{...n,steps:r,qed:{...n.qed,proof:f(e+1,n.qed.proof)}}},p=(e,t)=>{let n={...t,step:d(e,t.step)};switch(n.kind){case`Assert`:case`Suffices`:case`Pcase`:case`Pick`:return{...n,proof:f(e+1,n.proof)};default:return n}},m=(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(`expose_connective`);if(i.kind!==`Defn`||i.definition.kind!==`Operator`)return n;let a=N(r.index,i.definition.body);if(n.kind!==`Apply`)return m(t,a);let o={...a,location:n.location};return m(t,D(Ee(o,n.args),o))}if(n.kind===`Apply`&&n.operator.kind===`Internal`&&n.operator.builtin===`Prime`){let e=m(t,n.args[0]),r=e=>O(`Prime`,[e],e);return e.kind===`Quant`?D({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):In(e,`Implies`)||In(e,`Mem`)?D({kind:`Apply`,operator:e.operator,args:[r(e.args[0]),r(e.args[1])]},n):r(e)}return n.kind===`Parens`?m(t,n.expression):n},h=e=>{if(e.kind!==`Assert`)return;let t=e.sequent.active;return t.kind===`Apply`&&t.args.length===2?t.args[1]:void 0},g=e=>{if(e.kind!==`Steps`)return e;let t=[];return e.steps.forEach(e=>{let n=t.at(-1),r=n&&h(n);if(e.kind!==`Assert`||!r){t.push(e);return}let i=tr(e.sequent.active,N(2,r));t.push({...e,sequent:{...e.sequent,active:i}})}),{...e,steps:t}},_=(e,t,n,r)=>{let i=g(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:[N(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=Pn(i.step),o=[...t,...n,...r].map(e=>({...e,step:u(a)})),s={kind:`Obvious`,location:i.location,step:u(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=e,a=t,o=r,s=i.steps.flatMap(e=>{let[t,r,i,s]=v(n,a,e,o);return n=t,a=r,o=s,i}),c=_(n,a,i.qed.proof,o);return{...i,steps:s,qed:{...i.qed,proof:c}}}}},v=(t,n,r,i)=>{let a=Pn(r.step);switch(r.kind){case`Forget`:return[t,n,[r],i];case`Assert`:{let e=Hn(t,r.sequent,r,i),a={...r,proof:_(e.context,e.active,r.proof,e.time)},o=Un(!1,t,n,r.sequent,a,i);return[o.context,o.active,[a],i]}case`Suffices`:{let e=Un(!0,t,n,r.sequent,r,i),a={...r,proof:_(e.context,e.active,r.proof,i)},o=Hn(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=_(t,n,a,i);if(o.kind!==`Steps`)throw new e(`simplifying BY does not produce a non-leaf proof!`);let s=r.usable.facts.map(()=>({kind:`Fact`,expression:jn,visibility:`Visible`,time:i,location:r.location}));return[[...t,...s],N(r.usable.facts.length,n),o.steps,i]}case`Hide`:return[r.usable.defs.reduce((t,n)=>{if(n.kind!==`Dx`)throw new e(`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(`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}))],N(r.definitions.length,n),[r],i];case`Have`:{let e=m(t,n),o={kind:`Fact`,expression:r.expression,visibility:`Visible`,time:i,location:r.location},s=In(e,`Implies`),c={context:[o],active:s?N(1,e.args[1]):e},l=s?{kind:`By`,usable:{facts:[D({kind:`Ix`,index:2},r)],defs:[]},isOnly:!0,...Mn(r)}:{kind:`Error`,message:Ln(`@.@[<v2>@[%s@ %s@]@,%a@]@.`,`Error: this HAVE step is applied to the following goal,`,`which is not an implication:`,kn(t,n)),...Mn(r)},u=p(a,{kind:`Suffices`,sequent:c,proof:l,location:r.location,step:r.step});return v(t,n,u,i)}case`Take`:return v(t,n,p(a,b(t,n,r)),i);case`Witness`:return v(t,n,p(a,ee(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:N(1,n)},proof:r.proof,...Mn(r)};return v(t,n,p(a,e),i)}case`Pick`:{let a=D({kind:`Quant`,quantifier:`Exists`,bounds:r.bounds,body:r.expression},r),o=y(r.step,`ex`),[s,c,l,u]=v(t,n,{kind:`Assert`,sequent:{context:[],active:a},proof:r.proof,...Mn(r),step:o},i),d=N(2,a);if(d.kind!==`Quant`)throw new e(`Proof.Simplify.simplify_step/PICK`);let f=[...Rn(d.bounds),{kind:`Fact`,expression:d.body,visibility:`Visible`,time:u,location:d.body.location}],[p,m,h,g]=v(s,c,{kind:`Suffices`,sequent:{context:f,active:N(f.length,c)},proof:{kind:`Omitted`,omission:`Elsewhere`,...Mn(r)},...Mn(r)},u);return[p,m,[...l,...h],g]}}},y=(e,n)=>({kind:`Named`,level:Pn(e),label:`${e?.kind===`Named`?e.label:`_a`}${n}${Tt(t)}`,isAnonymous:!1}),b=(e,t,n)=>{let r=zn(n.bounds),i=(t,n,r,a)=>{let o=a[0];if(!o)return{aux:n,goal:r};let s=m(e,r);if(s.kind!==`Quant`||s.quantifier!==`Forall`||s.bounds.length===0)return Ln(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this TAKE step is applied to the following goal,`,`which is not a universal formula:`,kn(e,r));let c=s.bounds[0],l=zn(s.bounds).slice(1),u=o.domain,d=c.domain;if(u.kind===`NoDomain`&&d.kind===`Domain`)return Ln(`@.@[<b0>%s (%s)@ %s (%s \\in %a)@]@.`,`Error: the TAKE argument`,o.name,`does not match the pattern`,c.name,kn(e,d.expression));if(u.kind===`Domain`&&d.kind===`NoDomain`)return Ln(`@.@[<b0>%s (%s \\in %a)@ %s (%s)@]@.`,`Error: the TAKE argument`,o.name,kn(e,u.expression),`does not match the pattern`,c.name);let f=u.kind===`Domain`&&d.kind===`Domain`&&!F(u.expression,d.expression)?[{kind:`Apply`,operator:{kind:`Internal`,builtin:`Subseteq`},args:[d.expression,u.expression]},...n]:n;if(l.length===0)return i(1,f,s.body,a.slice(1));let p=a.length===1?l.map(e=>Oe(w(t),[e])[1][0]):l;return i(t+1,f,D({kind:`Quant`,quantifier:`Forall`,bounds:p,body:s.body},s),a.slice(1))},a=i(1,[],t,r);if(typeof a==`string`)return{kind:`Suffices`,sequent:{context:[{kind:`Fact`,expression:Fn(t),visibility:`Visible`,time:`Now`,location:n.location}],active:t},proof:{kind:`Error`,message:a,...Mn(n)},...Mn(n)};let o=a.aux.filter((e,t)=>a.aux.findIndex(t=>F(e,t))===t),s=[D({kind:`Ix`,index:2},n),...o.map(e=>N(2,e))];return{kind:`Suffices`,sequent:{context:Rn(r),active:a.goal},proof:{kind:`By`,usable:{facts:s,defs:[]},isOnly:!0,...Mn(n)},...Mn(n)}},ee=(e,t,n)=>{let r=[],i=``,a=t;for(let t of n.expressions){let n=m(e,a);if(n.kind!==`Quant`||n.quantifier!==`Exists`||n.bounds.length===0){i||=Ln(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this WITNESS step is applied to the following goal,`,`which is not an existential formula:`,kn(e,n)),a=n;break}let[o,...s]=n.bounds,c=s.length===0?n.body:D({kind:`Quant`,quantifier:`Exists`,bounds:Jn(o,s),body:n.body},n),l=t;if(o.domain.kind===`Domain`){let n=o.domain.expression,a=m(e,t);if(In(a,`Mem`)){let[e,t]=a.args,i=F(t,n)?[]:[O(`Subseteq`,[t,n],t)];r.push(...i,a),l=e}else i||=Ln(`@.@[<b0>%s (%a)@ %s (%s \\in %a)@]@.`,`Error: the WITNESS argument`,kn(e,a),`does not match the pattern`,o.name,kn(e,n)),l=a}let u=O(`Unprimable`,[l],l);a=M(T(u,w(0)),c)}let o=i===``?Yn(n,r):{kind:`Error`,message:i,...Mn(n)};return{kind:`Suffices`,sequent:{context:[],active:a},proof:o,...Mn(n)}};return{generate:a,collect:l,mutate:c,simplify:_}},rr=(e,t=0)=>({level:e,weights:Array.from({length:t},()=>!0),params:/* @__PURE__ */ new Set}),ir={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]},ar={Constant:0,State:1,Action:2,Temporal:3,Unknown:0},or=e=>new Set(e.flatMap(e=>[...e])),sr=e=>({level:Math.max(0,...e.map(e=>e.level)),weights:[],params:or(e.map(e=>e.params))}),cr=/* @__PURE__ */ new WeakMap,lr=e=>{let t=e.hyp;switch(t.kind){case`Flex`:return rr(1);case`Fresh`:return{...rr(ar[t.level],t.shape),params:/* @__PURE__ */ new Set([t.name])};case`Defn`:{let n=t.definition;if(n.kind!==`Operator`&&n.kind!==`Bpragma`)throw new r;return pr(e.rest,n.body)}case`Fact`:return pr(e.rest,t.expression)}},ur=e=>{let t=cr.get(e);if(t)return t;let n=lr(e);return cr.set(e,n),n},dr=(e,t,n)=>{let r=t.flatMap(t=>t.domain.kind===`Domain`?[pr(e,t.domain.expression)]:[]),i=t.reduce((e,t)=>k(e,j(t.name,t.level)),e);return sr([pr(i,n),...r])},fr=(t,n)=>{if(t.weights.length!==n.length)throw new e(`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:or([t.params,...r.map(e=>e.params)])}},pr=(e,t)=>{let n=t=>pr(e,t);switch(t.kind){case`Ix`:{let n=xe(e,t.index-1);if(!n)throw new r;return ur(n)}case`Internal`:{let e=ir[t.builtin];if(!e)throw new r;return rr(e[0],e[1])}case`Opaque`:case`String`:case`Num`:return rr(0);case`Lambda`:{let n=t.params.reduce((e,t)=>k(e,j(t.name,`Unknown`,t.shape)),e),r=pr(n,t.body),i=new Set(t.params.map(e=>e.name));return{level:r.level,weights:t.params.map(e=>r.params.has(e.name)),params:new Set([...r.params].filter(e=>!i.has(e)))}}case`Apply`:{let e=t.operator;if(e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`Prime`&&e.args.length===1)return n({...t,operator:e.args[0]});if(e.kind===`Opaque`)return fr(rr(0,t.args.length),t.args.map(n));if(e.kind===`Internal`&&t.args.length===1){let i=t.args[0];switch(e.builtin){case`Prime`:case`StrongPrime`:if(n(i).level>1)throw new r;return rr(2,1);case`ENABLED`:{let e=n(i);if(e.level>2)throw new r;return{level:1,weights:[],params:e.params}}case`UNCHANGED`:{let e=n(i);if(e.level>1)throw new r;return{level:2,weights:[],params:e.params}}}}return e.kind===`Internal`&&e.builtin===`Cdot`?(t.args.forEach(n),rr(2)):e.kind===`Internal`&&e.builtin===`Leadsto`?(t.args.forEach(n),rr(3,2)):fr(n(e),t.args.map(n))}case`Sequent`:{let[n,r]=A(e,t.sequent.context,(e,t)=>{let n=k(e,t);return[n,ur(n).level]});return rr(Math.max(0,...r,pr(n,t.sequent.active).level))}case`With`:case`Dot`:case`Parens`:return n(t.expression);case`Let`:{let n=t.definitions.reduce((e,t)=>k(e,{kind:`Defn`,definition:t,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),e);return pr(n,t.body)}case`If`:return sr([t.condition,t.consequent,t.alternative].map(n));case`List`:return sr(t.items.map(n));case`Quant`:case`Fcn`:return dr(e,t.bounds,t.body);case`SetOf`:return dr(e,t.bounds,t.element);case`Tquant`:return pr(t.names.reduce((e,t)=>k(e,{kind:`Flex`,name:t}),e),t.body),rr(3);case`Choose`:case`SetSt`:{let r=t.domain&&n(t.domain),i=t.domain?Ce(t.name,t.domain):j(t.name,`Constant`);return sr([pr(k(e,i),t.body),...r?[r]:[]])}case`SetEnum`:case`Tuple`:return sr(t.elements.map(n));case`Product`:return sr(t.factors.map(n));case`FcnApp`:return sr([t.function,...t.args].map(n));case`Arrow`:return sr([n(t.domain),n(t.range)]);case`Rect`:case`Record`:return sr(t.fields.map(e=>n(e.value)));case`Except`:return sr([n(t.function),...t.specs.flatMap(e=>[...e.trail.flatMap(e=>e.kind===`Apply`?[n(e.expression)]:[]),n(e.value)])]);case`Sub`:return{...sr([n(t.action),n(t.subscript)]),level:2};case`Tsub`:case`Fair`:return n(t.action),n(t.subscript),rr(3);case`Case`:return sr([...t.arms.flatMap(e=>[n(e.condition),n(e.body)]),...t.other?[n(t.other)]:[]]);case`Bang`:case`At`:throw new r}},mr=`EnabledWrapper`,hr=`CdotWrapper`,gr="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`.",_r="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.",vr=(e,t,n,r=n)=>{throw e(C(t.location,n)),new s(r)},yr=(e,t)=>{let n=xe(e,t-1)?.hyp;if(!n)throw new r;return n},br=e=>e.kind===`Internal`&&(e.builtin===`ENABLED`||e.builtin===`Cdot`),xr=e=>e.kind===`Opaque`&&(e.name===mr||e.name===hr),Sr=e=>e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`Lambda`&&(br(e.operator)||xr(e.operator)),Cr=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t,wr=e=>e===void 0?2:Math.min(2,e),Tr=e=>e===void 0?void 0:Math.max(1,e-1),Er=(t,n,i,a,o)=>{let s=(e,r=o)=>Er(t,n,i,e,r);if(Sr(a))return a;if(a.kind===`Sub`)return{...a,action:s(a.action),subscript:s(a.subscript,Tr(o))};if(a.kind===`Apply`&&a.operator.kind===`Internal`){let e=a.operator.builtin,[r,i]=a.args;if(e===`Cdot`&&a.args.length===2)return o!==void 0&&!t.isCdot&&vr(n,a,`${_r}For example, writing \`BY ExpandCdot\`.`,`Expr.Action`),{...a,args:t.isCdot?[s(r,wr(o)),s(i,1)]:[s(r),s(i)]};if(e===`ENABLED`&&a.args.length===1)return o!==void 0&&!t.isEnabled&&vr(n,a,gr,`Expr.Action`),{...a,args:[t.isEnabled?s(r,wr(o)):s(r)]};if((e===`Prime`||e===`UNCHANGED`)&&a.args.length===1)return{...a,args:[s(r,Tr(o))]}}let c=a.kind===`Apply`&&a.operator.kind===`Ix`?a.operator:a;if(c.kind!==`Ix`)return I(i,a,(e,r)=>Er(t,n,e,r,o),k);if(o===void 0)return a;let l=pr(i,a).level,u=yr(i,c.index),d=e=>`The operator \`${e}\` is declared at:\n${u.location?fe(u.location):`<unknown location>`}`;if(u.kind===`Fresh`&&u.level===`Unknown`)throw n(C(a.location,`Declared operator \`${u.name}\` has unknown level and occurs within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${o}.\nIf a constant operator is substituted for this operator, then the expression that results from applying this declared operator has expression level ${l}.\n May need expansion. A declared operator cannot be expanded.\n${d(u.name)}\n and has arity: ${u.shape}`)),new r(`File "src/expr/e_action.ml", line 367, characters 20-26: Assertion failed`);if(l<o)return a;if(l>2||u.kind===`Fact`)throw new r;if(u.kind===`Flex`){if(a.kind!==`Ix`)throw new r;return a}if(u.kind===`Fresh`){let t=`The expression that results from applying the declared operator \`${u.name}\` has expression level ${l} within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${o}. A declared operator cannot be expanded.\n${d(u.name)}\n and has level: ${ar[u.level]}\n and arity: ${u.shape}`;throw n(C(a.location,t)),new e(t)}let f=u.definition;if(f.kind!==`Operator`&&f.kind!==`Bpragma`)throw new r;if(!t.isAutoUse){let e=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"],r=f.body.kind===`Lambda`?f.body.body:f.body,i=e=>e.location?fe(e.location):`<unknown location>`;vr(n,a,`Hidden definition of operator \`${f.name}\` needs expansion for soundly expanding ${e[0]} (using rigid quantification).\nThe expansion of ${e[0]} has been activated with the ${e[1]} from the module \`TLAPS\`.\nThe operator \`${f.name}\` is defined at: \n\t${i(r)}\nand the operator \`${f.name}\` occurs at: \n\t${i(a)}\nUsing the proof directive \`AutoUSE\` from the module \`TLAPS\`, or \`BY DEF ${f.name}\` is expected to avoid this error.\n`)}n({text:`${pe(a.location)}[INFO]: Auto-expanding the definition of operator: ${f.name}\n`,channel:`stdout`});let p=M(w(c.index),f.body);return s(De(a.kind===`Apply`?Ee(p,a.args):p))},Dr=e=>O(`Eq`,[O(`Prime`,[e],e),e],e),Or=e=>{let t=e=>e.kind===`Tuple`?e.elements.flatMap(t):[e],n=t(e);return n.length===0?D({kind:`Internal`,builtin:`TRUE`},e):n.length===1?Dr(n[0]):D({kind:`List`,bullet:`And`,items:n.map(Dr)},e)},kr=e=>{if(e.kind===`Apply`&&e.args.length===1)return Or(e.args[0]);if(e.kind!==`Sub`)throw new r;let t=Or(e.subscript),n=e.modal===`Box`?t:O(`Neg`,[t],e);return O(e.modal===`Box`?`Disj`:`Conj`,[e.action,n],e)},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},jr=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()},Mr=(e,t,n,i,a,o)=>{let s=r=>Mr(e,t,n,i,a,r),c=n!==void 0||i!==void 0,l=(r,s)=>{let c={names:[],depth:Math.max(n?.depth??0,i?.depth??0)+1},[l,u]=s,d=[Mr(e,t,n,c,a,l),...u?[Mr(e,t,c,i,a,u)]:[]],f=c.names.length===0?[`r#0`]:jr(c.names);return D({kind:`Apply`,operator:r,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(Sr(o))return o;if(o.kind===`Apply`&&o.operator.kind===`Internal`){let n=o.operator.builtin;if(e.isEnabled&&n===`ENABLED`&&o.args.length===1||e.isCdot&&n===`Cdot`&&o.args.length===2)return l(o.operator,o.args);if(n===`ENABLED`&&c&&vr(t,o,gr,`Expr.Action`),n===`Cdot`&&c&&vr(t,o,`${_r} For example, writing \`BY ExpandCdot\`.`,`Expr.Action`),n===`Prime`&&o.args.length===1){let n=Mr(e,t,i,void 0,a,o.args[0]);return i?n:{...o,args:[n]}}if(n===`UNCHANGED`&&c)return s(kr(o))}if(o.kind===`Sub`&&c)return s(kr(o));if(o.kind===`Ix`){if(!n)return o;let e=yr(a,o.index);if(e.kind===`Fact`)throw new r;if(e.kind!==`Flex`)return o;let t=`${e.name}#enabled#prime${n.depth}`;return n.names.includes(t)||n.names.push(t),D({kind:`Opaque`,name:t},o)}if(o.kind===`Apply`&&o.operator.kind===`Opaque`)throw t(C(o.location,`Named operator \`${o.operator.name}\` unexpected after anonymization.`)),new r(`File "src/expr/e_action.ml", line 1048, characters 12-18: Assertion failed`);return I(a,o,(r,a)=>Mr(e,t,n,i,r,a),k)},Nr=(e,t)=>{if(t.kind===`Apply`&&br(t.operator)){let[n]=t.args;if(t.args.length!==1||n.kind!==`Lambda`)throw new r;let[i,...a]=n.params;if(i.name!==`_`)return t;let o=Nr({kind:`Compose`,outer:e,inner:w(a.length)},n.body);return{kind:`Apply`,operator:t.operator,args:[{kind:`Lambda`,params:a,body:o}]}}return t.kind===`Ix`?M(e,t):t.kind===`Apply`?D(Ee(Nr(e,t.operator),t.args.map(t=>Nr(e,t))),t):I(e,t,Nr,e=>E(1,e))},Pr=(e,t)=>{if(t.kind===`Apply`&&br(t.operator)){let[n]=t.args;if(t.args.length!==1||n.kind!==`Lambda`||n.params[0].name===`_`)throw new r;let i=t.operator.builtin===`Cdot`?hr:mr;return{kind:`Apply`,operator:D({kind:`Opaque`,name:i},t.operator),args:[{kind:`Lambda`,params:n.params.map((t,n)=>({name:e?t.name:`r#${n}`,shape:0})),body:Pr(e,n.body)}]}}return I(void 0,t,(t,n)=>Pr(e,n),()=>void 0)},Fr=e=>{if(e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`Cdot`&&e.args.length===1&&e.args[0].kind!==`Lambda`)throw new r;return I(void 0,e,(e,t)=>Fr(t),()=>void 0)},Ir=(e,t,n,r,i,a)=>{let o=Mr(i,t,void 0,void 0,n,r);return Pr(a,e.expr(n,Nr(w(0),o)))},Lr={isEnabled:!0,isCdot:!0,isAutoUse:!0},Rr=(e,t,n,r,i=Lr)=>{let a=Er(i,t,n,r,void 0);return Fr(Ir(e,t,n,a,i,!1))},zr=(e,t,n,r,i)=>{let a=(r,i)=>({kind:`Quant`,quantifier:`Exists`,bounds:r.map(e=>({name:e.name,level:`Constant`,domain:{kind:`NoDomain`}})),body:zr(e,t,ve(n,r.map(e=>j(e.name,`Unknown`,e.shape))),i,!0)}),o=t=>t===`ENABLED`?e.isEnabled:e.isCdot;if(r.kind===`Apply`&&r.args.length===1){let i=r.operator,[s]=r.args;if(s.kind===`Lambda`){if(i.kind===`Opaque`&&(e.isEnabled&&i.name===mr||e.isCdot&&i.name===hr))return a(s.params,s.body);if(i.kind===`Ix`&&(e.isEnabled||e.isCdot)){let e=yr(n,i.index);if(e.kind===`Defn`&&e.definition.kind===`Operator`&&(e.definition.name===mr||e.definition.name===hr))return a(s.params,s.body)}if(br(i)&&o(i.builtin))return a(s.params,s.body)}if(br(i)&&o(i.builtin))return zr(e,t,n,s,!0)}return Cr(r,`ENABLED`)&&i&&vr(t,r,gr,`Expr.Action`),Cr(r,`Cdot`)&&i&&vr(t,r,`${_r} For example, writing \`BY ExpandCdot\`.`,`Expr.Action`),I(n,r,(n,r)=>zr(e,t,n,r,i),k)},Br=e=>{if(e.kind===`Quant`&&e.quantifier===`Exists`){let t=e.body;if(t.kind===`List`&&t.bullet===`Or`)return Br({...t,items:t.items.map(t=>({...e,body:t}))});if(t.kind===`Apply`&&t.operator.kind===`Internal`&&t.operator.builtin===`Disj`){if(t.args.length!==2)throw new r;return Br({...t,args:t.args.map(t=>({...e,body:t}))})}}return I(void 0,e,(e,t)=>Br(t),()=>void 0)},Vr=(e,t,n,r,i)=>{let a=Er(i,t,n,r,void 0),o=Ir(e,t,n,a,i,!0);return Br(zr(i,t,n,o,!1))},Hr=(e,t)=>({kind:`Definition`,definition:{kind:`Operator`,name:e,body:{kind:`Internal`,builtin:t}},whereDefined:`Builtin`,visibility:`Visible`,isLocal:!1}),V=(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}),Ur=[Hr(`Nat`,`Nat`),V(2,`+`,`Plus`),V(2,`-`,`Minus`),V(2,`*`,`Times`),V(2,`^`,`Exp`),V(2,`<`,`Lt`),V(2,`>`,`Gt`),V(2,`=<`,`Lteq`),V(2,`>=`,`Gteq`),V(2,`%`,`Remainder`),V(2,`\\div`,`Quotient`),V(2,`..`,`Range`)],Wr=[...Ur,Hr(`Int`,`Int`),V(1,`-.`,`Uminus`)],Gr=[...Wr,Hr(`Real`,`Real`),V(2,`/`,`Ratio`),Hr(`Infinity`,`Infinity`)],Kr=[V(1,`Seq`,`Seq`),V(1,`Len`,`Len`),V(2,`BSeq`,`BSeq`),V(2,`\\o`,`Cat`),V(2,`Append`,`Append`),V(1,`Head`,`Head`),V(1,`Tail`,`Tail`),V(3,`SubSeq`,`SubSeq`),V(2,`SelectSeq`,`SelectSeq`)],qr=[V(2,`Print`,`Print`),V(1,`PrintT`,`PrintT`),V(2,`Assert`,`Assert`),Hr(`JavaTime`,`JavaTime`),V(1,`TLCGet`,`TLCGet`),V(2,`TLCSet`,`TLCSet`),V(2,`:>`,`OneArg`),V(2,`@@`,`Extend`),V(1,`Permutations`,`Permutations`),V(2,`SortSeq`,`SortSeq`),V(1,`RandomElement`,`RandomElement`),Hr(`Any`,`Any`),V(1,`ToString`,`ToString`)],Jr=(e,t)=>({name:e,extendees:[],body:t,isImportant:!1,isStandard:!0}),Yr=new Map([Jr(`Naturals`,Ur),Jr(`Integers`,Wr),Jr(`Reals`,Gr),Jr(`Sequences`,Kr),Jr(`TLC`,qr)].map(e=>[e.name,e])),Xr=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`:return e.name===void 0?[{kind:`Fact`,expression:e.expression,visibility:`Hidden`,time:`Always`,location:t}]:Qr(e.name,e.expression,t);case`Theorem`:{let n=je(w(-e.axiomCount),{...e.sequent,context:e.sequent.context.slice(e.axiomCount)}),r=D(_e(n),e);return e.name===void 0?[{kind:`Fact`,expression:r,visibility:`Hidden`,time:`Always`,location:t}]:Qr(e.name,r,t)}case`Mutate`:return e.mode===`Use`?e.usable.facts.map((e,n)=>({kind:`Fact`,expression:N(n,e),visibility:`Visible`,time:`Always`,location:t})):[];case`Submod`:case`Anoninst`:return[]}},Zr=e=>e.kind===`Axiom`||e.kind===`Theorem`?e.name===void 0?1:2:Xr(e).length,Qr=(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}],$r=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:$r(e.module)}}];default:return[e]}}),ei=(t,n,i,a=/* @__PURE__ */ new Set([n.name]))=>{let o=[];for(let s of n.extendees){if(i.has(s))continue;if(a.has(s))throw new r(`Stack overflow`);let n=t.get(s);if(!n)throw new e(`Module "${s}" unknown`);o.push(...$r(ei(t,n,i,/* @__PURE__ */ new Set([...a,s])))),i.add(s)}return{...n,body:[...o,...n.body].map(e=>e.kind===`Submod`?{...e,module:ei(t,e.module,/* @__PURE__ */ new Set)}:e)}},ti=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&&ni(e.instance)&&n(e.instance.module,e.instance.location),Object.values(e).forEach(o))},s=e=>{e.kind===`Theorem`?o(e.sequent):e.kind!==`Submod`&&o(e),e.kind===`Submod`&&(i.add(e.module.name),a.set(e.module.name,e.module),r(e.module),e.module.body.forEach(s))};return e.body.forEach(s),i.forEach(e=>t.delete(e)),r(e),{dependencies:[...t.keys()].sort(ri),locations:t,submodules:a}},ni=e=>typeof e==`object`&&!!e&&`module`in e&&typeof e.module==`string`&&`substitutions`in e,ri=(e,t)=>e<t?-1:+(e>t),ii=(t,n)=>({facts:Te(t,n.facts),defs:n.defs.map(n=>{if(n.kind===`Dvar`)return n;let r=M(t,{kind:`Ix`,index:n.index});if(r.kind!==`Ix`)throw new e(`substitution produced bad definition`);return{...n,index:r.index}})}),ai=(e,t)=>{switch(t.kind){case`Constants`:case`Recursives`:return[E(t.declarations.length,e),t];case`Variables`:return[E(t.names.length,e),t];case`Definition`:return[E(1,e),{...t,definition:ke(e,t.definition)}];case`Axiom`:return[E(Zr(t),e),{...t,expression:M(e,t.expression)}];case`Theorem`:return[E(Zr(t),e),{...t,sequent:je(e,t.sequent)}];case`Submod`:return[e,{...t,module:{...t.module,body:oi(e,t.module.body)}}];case`Mutate`:return[t.mode===`Hide`?e:E(t.usable.facts.length,e),{...t,usable:ii(e,t.usable)}];case`Anoninst`:return[e,{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(t=>({name:t.name,expression:M(e,t.expression)}))}}]}},oi=(e,t)=>A(e,t,ai)[1],si=(t,n,i,a)=>{try{let e=Rr(t.anonymizer,t.onWarning,n,{kind:`Sequent`,sequent:a});if(e.kind!==`Sequent`)throw new r;return e.sequent}catch(n){if(!(n instanceof e)||n.failure===void 0)throw n;let r=a.active.location,o=`${n.failure}\nCould not instantiate the theorem ${i===void 0?``:`named: ${i}, `}at: ${r?fe(r):`<unknown location>`}`;return t.onWarning({text:`${pe(r)}[ERROR]${o}`,channel:`stdout`}),t.onWarning({text:o,channel:`toolboxOnly`}),{context:[],active:D({kind:`Internal`,builtin:`TRUE`},a.active)}}},ci=(e,t,n)=>{if(n.kind===`Theorem`)return{...n,sequent:si(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=Rr(e.anonymizer,e.onWarning,t,r.body);return{...n,definition:{...r,body:i}}},li=(e,t,n)=>A(t,n,(t,n)=>{if(n.kind===`Submod`){let[r,i]=li(e,t,n.module.body);return[r,{...n,module:{...n.module,body:i}}]}let r=ci(e,t,n);return[ve(t,Xr(r)),r]}),ui=(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(`Parameter ${s.name} has no substitute`);let r=Zr(s.remaining)===0;a=oi(T(N(i,t),w(0)),r?o:[s.remaining,...o])}else r.push(t),i+=Zr(t),a=o}return r},di=(e,t,n)=>{let r=Array.from({length:t},(e,r)=>D({kind:`Ix`,index:t-r},{location:n})),i=Array.from({length:t},(e,t)=>D({kind:`Ix`,index:t+1},{location:n})),a=Array.from({length:e},(e,i)=>{let a=D({kind:`Ix`,index:i+t+1},{location:n});return t>0?D({kind:`Apply`,operator:a,args:r},{location:n}):a});return he([...a,...i].reverse(),w(e+t))},fi=(e,t)=>{let n=t.map(e=>({name:e,shape:0}));return e.kind===`Lambda`?{...e,params:[...n,...e.params]}:t.length===0?e:D({kind:`Lambda`,params:n,body:e},e)},pi=(t,n,r,i,a,o)=>{let s=e=>r===``?e:`${r}!${e}`,c=i.args.length,l=[],u=0,d=n,f=c===0,p=e=>{f||(f=!0,t.onWarning({text:e,channel:`stderr`}))};for(;d.length>0;){let[n,...r]=d;d=r;let f=e=>fi(M(di(u,c,o),e),i.args);switch(n.kind){case`Definition`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e(`Module.Elab.localize`);let i=n.isLocal?`${r.name}$${Tt(t.salts)}`:r.name;l.push({...n,definition:{...r,name:s(i),body:f(r.body)},whereDefined:n.isLocal?`Builtin`:n.whereDefined,isLocal:n.isLocal||a}),u+=1;continue}case`Axiom`:{p(`${me(o)}Instancing produces parametric axioms.\nSuch axioms will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`);let e={...n,name:n.name===void 0?void 0:s(n.name),expression:f(n.expression)};l.push(e),u+=Zr(e);continue}case`Theorem`:{p(`${pe(o)}Warning: Instancing produces parametric theorems.\nSuch theorems will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`);let e=f(D(_e(n.sequent),n));l.push({...n,name:n.name===void 0?void 0:s(n.name),sequent:e.kind===`Sequent`?e.sequent:{context:[],active:e},proof:{kind:`Omitted`,omission:`Elsewhere`,location:n.location}}),u+=1;continue}case`Mutate`:n.mode===`Use`&&(d=oi(w(-n.usable.facts.length),d));continue;case`Submod`:continue;default:throw new e(`Module.Elab.localize`)}}return l},mi=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?N(1,e.expression):D({kind:`Ix`,index:2},e),visibility:`Visible`,time:`Always`,location:i},o=0,s=r.map(e=>{let t=o;if(o+=Zr(e),e.kind!==`Theorem`)return e;let n=je(w(1),e.sequent);return{...e,sequent:{...n,context:[Ae(w(t),a),...n.context]},axiomCount:e.axiomCount+1}});n=oi(w(-1),s)}return t},hi=e=>new Set(e.body.flatMap(e=>e.kind===`Constants`?e.declarations.map(e=>e.name):e.kind===`Variables`?e.names:[])),gi=(t,n,r,i,a,o,s)=>{let c=n.get(i.module);if(!c)throw new e(`Module "${i.module}" unknown`);let l=hi(c);for(let t of i.substitutions)if(!l.has(t.name))throw new e(`Parameter ${t.name} occurs in the statement \`INSTANCE ${i.module} WITH\`, and is not declared in the module ${i.module}`);let u=ve(r,i.args.map(e=>j(e,`Unknown`))),d=new Map(i.substitutions.map(e=>[e.name,e.expression]));for(let t of[...l].sort(ri))if(!d.has(t)){if(!be(u,t))throw new e(`Required parameter ${t} for module ${i.module} could not be inferred.`);d.set(t,D({kind:`Opaque`,name:t},{location:s}))}let f=new Map([...d].map(([e,n])=>[e,t.anonymizer.expr(u,n)])),p=oi(w((u?.size??0)-(c.depth??0)),c.body.map(e=>e.kind===`Theorem`?{...e,proof:{kind:`Omitted`,omission:`Implicit`,location:e.proof.location}}:e)),[,m]=li(t,u,p);return mi(pi(t,ui(m,f),o,i,a,s))},_i=(e,t,n)=>e===void 0?{hyps:[],sequent:t}:{hyps:[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:D(_e(t),{location:n}),location:n},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:n}],sequent:je(w(1),t)},vi=(t,n,r)=>{let i=r.instance.module;if(!t.latestModules.has(i))throw t.onWarning({text:`${me(r.instance.location)}Module ${JSON.stringify(i)} unknown\n`,channel:`toolbox`}),new e(`Module ${JSON.stringify(i)} unknown`,{failure:`Module.Elab.anon#defns`});let a=gi(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=oi(w(-Zr(e)),t)}return o},yi=(e,t,n,r)=>{let i=[],a=n,o=e=>{i.push(e),a=ve(a,Xr(e))},s=e=>e!==void 0&&be(a,e)!==void 0,c=r.body.map(e=>({unit:e,isAnonymized:!1}));for(let n=0;n<c.length;n++){let i=c[n].unit,l=(r,o,s)=>{let l=gi(e,t,a,r,o,s,i.location);c.splice(n+1,0,...l.map(e=>({unit:e,isAnonymized:!0})))};switch(i.kind){case`Anoninst`:l(i.instance,i.isLocal,``);continue;case`Definition`:{let t=i.definition;if(t.kind===`Instance`){l(t.instance,i.isLocal,t.name);continue}let r=t.kind===`Recursive`||c[n].isAnonymized?t:e.anonymizer.defn(a,t),s={...i,definition:r};if(t.kind===`Recursive`){o(s);continue}let u=Xr(s)[0],d=be(a,t.name);if(d?.hyp.kind===`Defn`&&(d.hyp.definition.kind===`Recursive`||Ie(Ae(w(d.depth+1),d.hyp),u))){let e=c.slice(n+1),t=oi(T(D({kind:`Ix`,index:d.depth+1},i),w(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=_i(c,u,i.location),f=ve(ve(a,d.hyps.map(e=>({...e,isConstnessUnset:!0}))),d.sequent.context),p=e.anonymizer.proof(f,l),m=r.isImportant?e.generator.simplify(ye(f),d.sequent.active,p,Ct(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:yi(e,t,a,i.module)});continue}}let l={...r,body:i,depth:n?.size??0};return t.set(r.name,l),l},bi=(e,t,n)=>{let r=[],i=[],a=Zn,o=t;for(let t of n.body)switch(t.kind){case`Theorem`:{let n=_i(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,Ct(c,`Always`));r.push(...e.generator.collect(l));let u=er(l);i.push({...u,location:t.location}),a=Qn(a,u);let d=t.name===void 0?D(_e(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=bi(e,o,t.module);r.push(...n.obligations),a=Qn(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,...Xr(t)]}return{obligations:r,summary:{...a,theorems:i}}},xi=[`(`,`)`,`;`,`:`,`@`,`,`],Si=e=>e===` `||e===`\r`||e===` `,Ci=(e,t)=>{let n={...t},r=()=>{for(;n.line<e.length;){let t=e[n.line];for(;Si(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(!xi.includes(t[0]))return;i.push({kind:`Punct`,text:t[0]}),n.column++}}},wi=e=>e?.kind===`String`?{kind:`String`,value:e.text}:e?.kind===`Number`?{kind:`Float`,value:Number.parseFloat(e.text)}:e?.kind===`Punct`&&e.text===`@`?{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`]]),Ei=(e,t)=>{let n=Ci(e,t);if(!n)return;let r=0,i=e=>n[r]?.kind===`Punct`&&n[r].text===e,a=()=>{let e=n[r];return e?.kind===`Number`?(r++,{timeout:Number.parseFloat(e.text)}):{}},o=()=>{if(!i(`(`))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,...a()}):void 0}if(e.text===`zenon`){let t=a();return i(`(`)&&!o()?void 0:{name:e.text,...t}}let t=Ti.get(e.text);return t===void 0?void 0:{name:t}})();if(t&&i(`)`))return r++,t};if(n[r]?.kind!==`Ident`||n[r++].text!==`by`)return;let s=o();return r===n.length?s:void 0},Di=(e,t)=>{let n=Ci(e,t);if(!n)return;let r=0,i=e=>n[r]?.kind===`Punct`&&n[r].text===e,a=[];for(;r<n.length;){let e=n[r++];if(e.kind!==`Ident`||e.text!==`by`&&e.text!==`set`||!i(`(`))return;r++;let t=[];for(;;){let e=n[r++];if(e?.kind!==`Ident`||!i(`:`))return;r++;let a=wi(n[r++]);if(!a)return;if(t.push({hint:e.text,value:a}),i(`)`))break;if(!i(`;`))return;r++}r++,a.push(t)}return a},Oi=e=>({kind:`Opaque`,name:e}),ki=e=>({kind:`Tuple`,elements:e.map(Oi)}),Ai=(e,t)=>({kind:`Apply`,operator:{kind:`Internal`,builtin:`Eq`},args:[e,t]}),ji=e=>e.map(e=>({name:e,level:`Constant`,domain:{kind:`NoDomain`}})),Mi=(e,t)=>e?.kind===`Product`&&e.factors.length===t.length?e.factors:void 0,Ni=(e,t)=>t.map((t,n)=>({kind:`Operator`,name:t,body:{kind:`FcnApp`,function:Oi(e),args:[{kind:`Num`,integer:String(n+1),fraction:``}]}})),Pi=(e,t)=>e.map((e,n)=>({name:e,level:`Constant`,domain:{kind:`Domain`,expression:t[n]}})),Fi=e=>({name:e.name,level:`Constant`,domain:e.domain}),Ii=(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`?[Fi(e)]:[]),body:t,location:t.location};let i=Mi(r.domain,r.names);if(i)return{kind:`Quant`,quantifier:e,bounds:Pi(r.names,i),body:t,location:t.location};let a={kind:`Apply`,operator:{kind:`Internal`,builtin:e===`Exists`?`Mem`:`Notmem`},args:[ki(r.names),r.domain]};return{kind:`Quant`,quantifier:e,bounds:ji(r.names),body:{kind:`List`,bullet:e===`Exists`?`And`:`Or`,items:[a,t]},location:t.location}},n)},Li=(e,t,n,r)=>Mi(n,t)?{kind:`Let`,definitions:Ni(e,t),body:r}:{kind:`Quant`,quantifier:`Exists`,bounds:ji(t),body:{kind:`List`,bullet:`And`,items:[Ai(Oi(e),ki(t)),r]}},Ri=(e,t,n)=>{let r=`choose#${e[0]}`;return{kind:`Choose`,name:r,domain:t,body:Li(r,e,t,n)}},zi=(e,t,n)=>{let r=`setst#${e[0]}`;return{kind:`SetSt`,name:r,domain:t,body:Li(r,e,t,n)}},Bi=(e,t,n)=>{let r=e.map(e=>{if(e.kind===`Name`)return{bounds:[Fi(e)],definitions:[]};let t=Mi(e.domain,e.names);if(t&&n)return{bounds:Pi(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:Ni(r,e.names)};let a=`choose#${r}`;return{bounds:[i],definitions:[{kind:`Operator`,name:a,body:Ri(e.names,void 0,Ai(Oi(r),ki(e.names)))},...Ni(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}}},Vi=(e,t)=>{let n=Bi(t,e,!0);return{kind:`SetOf`,element:n.value,bounds:n.bounds}},Hi=(e,t)=>{let n=Bi(e,t,!1);return{kind:`Fcn`,bounds:n.bounds,body:n.value}},Ui={"=>":`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`},Wi=(e,t=!1)=>t&&e===`-`?`-.`:hn(e).name,Gi=/^<(\d+|\*|\+)>([A-Za-z0-9_]*)\.*$/,Ki=(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}},qi={Always:`[]`,Eventually:`<>`,Enabled:`ENABLED`,Unchanged:`UNCHANGED`},Ji=(e,t)=>e!==void 0&&t!==void 0&&e.line===t.line&&e.column===t.column,Yi=e=>e.location.range?.start,Xi=e=>e.location.range?.end,Zi=(e,t)=>{let n=e.location.range;return n&&t?{...e,location:{...e.location,range:{...n,end:t}}}:e},Qi=e=>{if(e.kind===`Apply`){let t=hn(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=qi[e.kind];if(t!==void 0&&`expression`in e)return{operator:hn(t),isInfix:!1,operand:e.expression,replace:t=>({...e,expression:t})}},$i=(e,t)=>e.high<t.low,ea=e=>{let t=hn(e.operator),[n,r]=e.args,i=Xi(e),a=t=>{let n=e.location.range,i=Yi(t);return{...e,args:[t,r],location:n&&i?{...e.location,range:{...n,start:i}}:e.location}},o=(e,n)=>{let r=n?Qi(e):void 0;if(!r)return{kind:`Reduced`,isFinal:!1};let s=o(r.operand,Ji(Xi(r.operand),Xi(e)));return s.kind===`Attached`?{kind:`Attached`,expression:Zi(r.replace(s.expression),i)}:!s.isFinal&&($i(t,r.operator)||r.isInfix&&t.fixity===`InfixLeft`&&r.operator.fixity===`InfixLeft`&&!$i(r.operator,t))?{kind:`Reduced`,isFinal:!$i(t,r.operator)}:{kind:`Attached`,expression:Zi(r.replace(a(r.operand)),i)}},s=o(n,Ji(Yi(n),Yi(e)));return s.kind===`Attached`?s.expression:e},ta="use instead the class`E_visit.iter_concrete`",na=(t,n,r,a)=>{let o=n.split(`
21
+ `),s=e=>({file:t,startLine:e.start.line,startColumn:e.start.column,endLine:e.end.line,endColumn:e.end.column+1}),c=e=>{let t={line:e.endLine-1,column:e.endColumn-1},n=e=>e===` `||e===`\r`;for(;t.line<o.length;){let e=o[t.line];for(;n(e[t.column]);)t.column++;if(t.column<e.length)break;t.line++,t.column=0}if(!(o[t.line]??``).startsWith(`(*{`,t.column))return e;for(let n=t.line;n<o.length;n++){let r=o[n].indexOf(`}*)`,n===t.line?t.column:0);if(r!==-1)return{...e,endLine:n+1,endColumn:r+4}}return e},l=e=>e&&Ei(o,{line:e.end.line-1,column:e.end.column}),u=e=>{let t=l(e),n=s(e);return t?{location:c(n),method:t}:{location:n}},d=(e,t)=>{let n=l(t);return n?D({kind:`With`,expression:e,method:n},e):e},f=(e,n)=>({file:t,startLine:n.line,startColumn:n.column,endLine:n.line,endColumn:n.column+e.length}),p=e=>e.range?s(e.range):{file:t,startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+1},m=(e,t)=>{let n=Wi(e),r=Ui[n];return D(r?{kind:`Internal`,builtin:r}:{kind:`Opaque`,name:n},{location:t})},h=(e,t,n,r)=>{if(e.startsWith(`<`)){let t=D({kind:`Opaque`,name:e},{location:n});return D({kind:`Bang`,expression:t,selectors:[]},{location:n})}let i=Ui[e];if(i&&t.length===0)return D({kind:`Internal`,builtin:i},{location:n});let a=e.split(`!`);if(a.length===1){let r=D({kind:`Opaque`,name:e},{location:n});return t.length===0?r:D({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=D({kind:`Opaque`,name:a[0]},{location:n});return D({kind:`Bang`,expression:o[0]===0?l:D({kind:`Apply`,operator:l,args:c(0)},{location:n}),selectors:a.slice(1).map((e,t)=>({kind:`Label`,label:Wi(e),args:c(t+1)}))},{location:n})},g=(t,n)=>t.map((r,i)=>{if(r.pattern.kind===`Tuple`)throw new e(`Unexpected tuple declaration`,{failure:ta});let a=i>0&&t[i-1].set===r.set;return{name:r.pattern.name,level:`Constant`,domain:a?{kind:`Ditto`}:{kind:`Domain`,expression:b(r.set,n)}}}),_=(e,t)=>e.map((n,r)=>{let i=b(n.set,t);if(n.pattern.kind===`Tuple`)return{kind:`Tuple`,names:n.pattern.names,domain:i};let a=r>0&&e[r-1].set===n.set;return{kind:`Name`,name:n.pattern.name,domain:a?{kind:`Ditto`}:{kind:`Domain`,expression:i}}}),v=(t,n)=>{if(!a)throw new e(`Unexpected tuple declaration`,{failure:ta});return D(t(),{location:n})},y=e=>e.some(e=>e.pattern.kind===`Tuple`),b=(t,n)=>{let r=p(t.location),i=e=>b(e,n),a=(e,t)=>e.length===2?Ki(e[0].location,e[1].location):e.length!==1||!e[0].location?r:t===`Prefix`?Ki({...r,endLine:r.startLine,endColumn:r.startColumn+1},e[0].location):t===`Postfix`?Ki({...r,startLine:r.endLine,startColumn:r.endColumn-1},e[0].location):r,s=(e,t)=>D({kind:`Apply`,operator:{kind:`Internal`,builtin:e},args:[t]},{location:a([t],`Prefix`)});switch(t.kind){case`Number`:return D({kind:`Num`,integer:t.text??String(t.value),fraction:``},{location:r});case`Decimal`:{let[e,n]=t.text.split(`.`);return D({kind:`Num`,integer:e,fraction:n},{location:r})}case`String`:{let e=/"((?:[^"\\]|\\.)*)"$/.exec((o[r.endLine-1]??``).slice(0,r.endColumn-1));return D({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=ea(t);if(e!==t)return i(e)}let e=t.args.map(i),n=hn(t.operator);return n.fixity===`Nonfix`?h(t.operator,e,r,t.argumentCounts):D({kind:`Apply`,operator:m(t.operator,void 0),args:e},{location:a(e,n.fixity)})}case`OperatorReference`:return m(t.operator,r);case`Lambda`:return D({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 D({kind:`List`,bullet:t.kind,items:e},{location:r});let n=t.kind===`And`?`Conj`:`Disj`;return e.reduce((e,t)=>D({kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:[e,t]},{location:Ki(e.location,t.location)}))}case`Prime`:{let e=i(t.expression);return D({kind:`Apply`,operator:{kind:`Internal`,builtin:`Prime`},args:[e]},{location:a([e],`Postfix`)})}case`Unchanged`:return s(`UNCHANGED`,i(t.expression));case`Enabled`:return s(`ENABLED`,i(t.expression));case`If`:return D({kind:`If`,condition:i(t.condition),consequent:i(t.consequent),alternative:i(t.alternative)},{location:r});case`Case`:return D({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 D({kind:`Let`,definitions:[...t.definitions,...t.instances??[]].sort((e,t)=>e.location.line-t.location.line||e.location.column-t.location.column).map(e=>x(e,n)),body:i(t.body)},{location:r});case`Forall`:case`Exists`:if(y(t.bounds)){let e=_(t.bounds,n),a=i(t.body);return v(()=>Ii(t.kind,e,a),r)}return D({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?D({kind:`Tquant`,quantifier:n,names:t.names,body:e},{location:r}):D({kind:`Quant`,quantifier:n,bounds:ji(t.names),body:e},{location:r})}case`Choose`:if(t.pattern.kind===`Tuple`){let e=t.pattern.names,n=t.set&&i(t.set),a=i(t.body);return v(()=>Ri(e,n,a),r)}return D({kind:`Choose`,name:t.pattern.name,domain:t.set&&i(t.set),body:i(t.body)},{location:r});case`SetEnumeration`:return D({kind:`SetEnum`,elements:t.elements.map(i)},{location:r});case`SetFilter`:if(t.bound.pattern.kind===`Tuple`){let e=t.bound.pattern.names,n=i(t.bound.set),a=i(t.predicate);return v(()=>zi(e,n,a),r)}return D({kind:`SetSt`,name:t.bound.pattern.name,domain:i(t.bound.set),body:i(t.predicate)},{location:r});case`SetMap`:if(y(t.bounds)){let e=i(t.expression),a=_(t.bounds,n);return v(()=>Vi(e,a),r)}return D({kind:`SetOf`,element:i(t.expression),bounds:g(t.bounds,n)},{location:r});case`Tuple`:return D({kind:`Tuple`,elements:t.elements.map(i)},{location:{...r,startLine:r.endLine,startColumn:r.endColumn-2}});case`FunctionConstruction`:if(y(t.bounds)){let e=_(t.bounds,n),a=i(t.body);return v(()=>Hi(e,a),r)}return D({kind:`Fcn`,bounds:g(t.bounds,n),body:i(t.body)},{location:r});case`FunctionSet`:return D({kind:`Arrow`,domain:i(t.domain),range:i(t.range)},{location:r});case`Record`:case`RecordSet`:return D({kind:t.kind===`Record`?`Record`:`Rect`,fields:t.fields.map(e=>({name:e.name,value:i(e.value)}))},{location:r});case`Except`:return D({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 D({kind:`At`,isExcept:n},{location:r});case`Bracket`:throw new e(`Unexpected [ without a function or subscript`);case`FunctionApplication`:return D({kind:`FcnApp`,function:i(t.function),args:t.args.map(i)},{location:r});case`FieldAccess`:return D({kind:`Dot`,expression:i(t.record),field:t.field},{location:r});case`Product`:return D({kind:`Product`,factors:t.factors.map(i)},{location:r});case`Always`:case`Eventually`:{let e=t.expression;return t.kind===`Always`&&e.kind===`BoxAction`?D({kind:`Tsub`,modal:`Box`,action:i(e.action),subscript:i(e.subscript)},{location:r}):t.kind===`Eventually`&&e.kind===`AngleAction`?D({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 D({kind:`Sub`,modal:t.kind===`BoxAction`?`Box`:`Dia`,action:i(t.action),subscript:i(t.subscript)},{location:r});case`WeakFairness`:case`StrongFairness`:return D({kind:`Fair`,fairness:t.kind===`WeakFairness`?`Weak`:`Strong`,subscript:i(t.subscript),action:i(t.action)},{location:r});case`Label`:return D({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(`Unexpected subexpression reference`);let o=D({kind:`Opaque`,name:n.name},{location:r}),s=n.args.length===0?o:D({kind:`Apply`,operator:o,args:n.args.map(i)},{location:r});return D({kind:`Bang`,expression:s,selectors:a.map(e=>{switch(e.kind){case`Name`:return{kind:`Label`,label:Wi(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})}}},ee=e=>({location:s(e.definitionRange??e.instanceRange),args:e.params.map(e=>e.name),module:e.module,substitutions:e.substitutions.map(e=>({name:Wi(e.name),expression:b(e.expression,!1)}))}),x=(t,n=!1)=>{let r=p(t.location);if(t.kind===`Instance`){if(t.name===void 0)throw new e(`Unexpected keyword INSTANCE`);return{kind:`Instance`,name:t.name,instance:ee(t),location:r}}let i=Wi(t.name,t.kind===`Operator`&&t.params.length===1&&t.name===`-`),a=b(t.body,n);if(t.kind===`Function`&&y(t.bounds)){let e=_(t.bounds,n);return{kind:`Operator`,name:i,body:v(()=>Hi(e,a),r),location:r}}if(t.kind===`Function`){let e=g(t.bounds,n);return{kind:`Operator`,name:i,body:D({kind:`Fcn`,bounds:e,body:a},{location:r}),location:r}}let s=t.params.length===0?a:D({kind:`Lambda`,params:t.params.map(e=>({name:Wi(e.name),shape:e.arity,...e.location&&{location:f(e.name,e.location)}})),body:a},{location:r}),c=t.location.range?.end,l=c&&Di(o,{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}},te=e=>{let t=p(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}},S=e=>e.kind===`AssumeProve`?{context:e.assumptions.map(e=>{if(e.kind===`NewSymbol`)return te(e);if(e.kind===`AssumeProve`){let t=p(e.location);return{kind:`Fact`,expression:D({kind:`Sequent`,sequent:S(e)},{location:t}),visibility:`Visible`,time:`Now`,location:t}}let t=ne(e);return{kind:`Fact`,expression:t,visibility:`Visible`,time:`Now`,location:t.location}}),active:b(e.conclusion,!1)}:{context:[],active:b(e,!1)},ne=e=>{if(e.kind!==`Label`||e.params.length>0)return b(e,!1);let t=p(e.location);return D({kind:`Parens`,expression:b(e.body,!1),form:{kind:`Xlabel`,label:e.name,indices:[]}},{location:t})},re=e=>{if(e.kind===`ModuleFact`)throw new i(`MODULE facts in proof obligations are not supported`);let t=b(e,!1);return t.kind===`Bang`&&t.selectors.length===0?t.expression:t},ie=e=>{let t=p(e.location);if(e.kind===`ModuleFact`)return{kind:`Dvar`,name:e.name,location:t};if(e.kind===`Identifier`)return{kind:`Dvar`,name:Wi(e.name),location:t};if(e.kind===`OperatorReference`)return{kind:`Dvar`,name:Wi(e.operator),location:t};throw new i(`This DEF clause in proof obligations is not supported`)},ae=e=>({facts:e.facts.map(re),defs:e.defs.map(ie)}),oe=(e,t)=>{let n=e?e[2]:``;return n===``?{kind:`Unnamed`,level:t,id:Tt(r)}:{kind:`Named`,level:t,label:n,isAnonymous:!1}},se=(e,t,n)=>{if(!e)return{kind:`Omitted`,omission:`Implicit`,location:n};switch(e.kind){case`Obvious`:return{kind:`Obvious`,...u(e.keyword)};case`Omitted`:return{kind:`Omitted`,omission:`Explicit`,location:s(e.keyword)};case`By`:return{kind:`By`,usable:ae(e),isOnly:e.isOnly,location:s(e.keyword),step:{kind:`Unnamed`,level:t,id:0},method:l(e.location.range)};case`Steps`:{let n=e.steps.map(e=>Gi.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)=>le(e,oe(n[t],i),i)),o=e.steps[e.steps.length-1],c=oe(n[n.length-1],i),l=s(o.head),u=se(o.proof,i+1,l),d={proof:u,location:Ki(l,u.location),step:c};return{kind:`Steps`,steps:a,qed:d,location:a.reduce((e,t)=>Ki(e,t.location),d.location),step:d.step}}}},ce=e=>Ki(s(e.keyword),e.defs.length>0?p(e.defs[e.defs.length-1].location):void 0),le=(t,n,r)=>{let a=s(t.head),o=t.body,c=e=>{let i=se(t.proof,r+1,a);return{...e(i),location:Ki(a,i.location),step:n}},d=e=>({...e,location:a,step:n}),f=e=>({...e,...u(t.head),step:n});switch(o.kind){case`Use`:case`Hide`:{let e=Ki(s({...t.head,end:t.head.start}),ce(o)),r=ae(o);return o.kind===`Use`?{kind:`Use`,usable:r,isOnly:o.isOnly,location:e,step:n,method:l(o.location.range)}:{kind:`Hide`,usable:r,location:e,step:n}}case`Instance`:throw new e(`Unexpected keyword INSTANCE`);case`Define`:return d({kind:`Define`,definitions:o.definitions.map(e=>x(e))});case`Have`:return f({kind:`Have`,expression:b(o.expression,!1)});case`Take`:return f({kind:`Take`,bounds:o.names.length>0?ji(o.names):g(o.bounds,!1)});case`Witness`:return f({kind:`Witness`,expressions:o.expressions.map(e=>b(e,!1))});case`Pick`:{let e=o.names.length>0?ji(o.names):g(o.bounds,!1),t=b(o.body,!1);return c(n=>({kind:`Pick`,bounds:e,expression:t,proof:n}))}case`Case`:{let e=b(o.expression,!1);return c(t=>({kind:`Pcase`,expression:e,proof:t}))}case`Assert`:{let e=S(o.statement);return c(t=>o.isSuffices?{kind:`Suffices`,sequent:e,proof:t}:{kind:`Assert`,sequent:e,proof:t})}case`Qed`:throw new i(`QED in the middle of a proof`)}},ue=e=>({name:e.name,extendees:e.extends,extendeeLocations:e.extendsRanges.map(s),isImportant:!1,location:p(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:Wi(e.name),shape:e.arity})),location:p(e.declarations[0].location)};case`Variables`:return{kind:`Variables`,names:e.declarations.map(e=>e.name),location:p(e.declarations[0].location)};case`Definition`:return{kind:`Definition`,definition:x(e.definition),whereDefined:`User`,visibility:`Hidden`,isLocal:e.definition.isLocal,location:p(e.definition.location)};case`Instance`:{let t=e.instance,n=p(t.location);return t.name===void 0?{kind:`Anoninst`,instance:ee(t),isLocal:t.isLocal,location:n}:{kind:`Definition`,definition:x(t),whereDefined:`User`,visibility:`Hidden`,isLocal:t.isLocal,location:s(t.instanceRange)}}case`Assumption`:return{kind:`Axiom`,name:e.assumption.name,expression:d(b(e.assumption.expression,!1),e.assumption.location.range),location:p(e.assumption.location)};case`Theorem`:{let t=e.theorem,n=p(t.location),r=c(n),i=S(t.statement);return{kind:`Theorem`,name:t.name,sequent:{...i,active:d(i.active,t.statement.location.range)},axiomCount:0,proof:se(t.proof,0,{...r,startLine:r.endLine,startColumn:r.endColumn}),location:n}}case`Use`:return{kind:`Mutate`,mode:e.use.kind,isSuppressed:!1,usable:ae(e.use),location:ce(e.use)};case`Module`:return{kind:`Submod`,module:{...ue(e.module),isImportant:!0}}}})});return{convertModule:ue}},ra={start:0,end:1/0},ia=/-{4,} *MODULE/,aa=`Unexpected EOF`,oa=e=>e?`${e.startLine}:${e.startColumn}:${e.endLine}:${e.endColumn}`:``,sa=e=>{let t=ne(e),n=e.split(`
22
+ `),r=t.at(-1)?.line??n.length,i=n.slice(0,r-1).reduce((e,t)=>e+t.length+1,0)+n[r-1].indexOf(`====`),a=e.indexOf(` `,e.search(ia));if(a===-1||a>=i)return;let o=e.slice(0,a).split(`
23
+ `).length,s=a-e.lastIndexOf(`
24
+ `,a-1),c=t.findLast(e=>e.kind!==`End`&&(e.line<o||e.line===o&&e.column<s));return{offset:a,line:o,column:s,end:{reason:aa,line:c?.line??o,column:c?c.endColumn+1:s,isEnd:!0}}},ca=e=>{try{return e()}catch(e){if(!(e instanceof t)||!e.failure)throw e;return e.failure}},la=e=>typeof e==`object`&&!!e&&`reason`in e,ua=e=>{let t=ca(()=>sa(e));if(la(t))return[t];let n=ca(()=>c(t?e.slice(0,t.offset):e));return t&&(!la(n)||n.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:t.line,column:t.column,isEnd:!1},la(n)&&n.reason===aa?n:t.end]:la(n)?[n]:n},da=(t,n,r,i,a)=>{if(!ia.test(t.source))throw new e(`No tokens in file`);let o=ua(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(n,{failure:`Module.Parser.parse_file`})}let s=na(t.file,t.source,n,r).convertModule(o),c=t.file.slice(t.file.lastIndexOf(`/`)+1),l=c.replace(/\.tla$/,``);return s.name===l?s:(i({text:`${me(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},fa=t=>{let n=new Map([...t].map(([e,t])=>[e,ti(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(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(ri).forEach(a),i},pa=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${de(t)}`)],ma=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?de({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...pa(`missing`,e.absent,t),...pa(`omitted`,e.omitted,n),` ====`]},ha=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...ma(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
+ `)},ga=(t,n,r={})=>{let i=r.lines??ra,a=r.onWarning??(()=>{}),o={value:0},s=new Map(Yr);t.forEach(e=>{let t={...da(e,o,!0,a,`File "<unknown>":
26
+ `),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>ri(e.name,t.name)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=ti(c[e]);t.submodules.forEach((e,t)=>{u.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!Yr.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=da(r,o,!1,a,pe(t.locations.get(e)));s.set(e,i),c.push(i)}}let d=[...l.keys()].filter(e=>!u.has(e)).sort(ri);if(d.forEach(e=>a(C(l.get(e),`Unknown module ${JSON.stringify(e)}`))),d.length>0)throw new e(`Unknown module ${JSON.stringify(d[0])}`,{failure:`Module.Parser.load_module`});let f={anonymizer:kt(o,(e,t)=>vi(f,e,t),a),generator:nr(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},p=fa(s).map(e=>e.isStandard?e:ei(s,e,/* @__PURE__ */ new Set)),m=new Map(p.map(e=>[e.name,e]));return p.flatMap(e=>{if(e.isStandard)return[];let t=yi(f,m,void 0,e);if(!e.isImportant)return[];let n=bi(f,[],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:oa(n),text:r,kind:e.kind,sequent:e.sequent,method:e.method}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},_a=async e=>{let t=[],n=[],r=/* @__PURE__ */ new Map,a=[],c={failure:void 0},l=()=>{for(;a.length>0&&n.length>0;){let e=n.reduce((e,t,r)=>t.priority<n[e].priority?r:e,0),[i]=n.splice(e,1),o=a.pop()??0;r.set(o,i),t[o].postMessage(i.request)}},u=(e,t)=>{let n=t,o=r.get(e);if(r.delete(e),a.push(e),`verdict`in n)o?.resolve(n.verdict);else{let e=n.error.name===`TlaProverError`?s:i;o?.reject(new e(n.error.message))}l()},d=e=>{c.failure||(c.failure={reason:e},[...n.splice(0),...r.values()].forEach(t=>t.reject(e)),r.clear(),t.forEach(e=>e.terminate()))};return t.push(...await Promise.all(Array.from({length:e},(e,t)=>o(new URL(`./prove-worker.js`,import.meta.url),e=>u(t,e),d)))),a.push(...t.keys()),{decide:(e,t,r,i)=>new Promise((a,o)=>{if(c.failure)return o(c.failure.reason);n.push({request:{prover:e,text:t,timeLimitMs:r.timeLimitMs},priority:i,resolve:a,reject:o}),l()}),terminate:d}},va={"!":`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_`},ya=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(` `)),ba=e=>/^[A-Za-z]$/.test(e),xa=e=>{if(/^[A-Za-z0-9]$/.test(e))return;let t=va[e];if(t===void 0)throw new r;return t},Sa=e=>{let t=[...e];return ba(t[0]??``)&&ba(t.at(-1)??``)&&t.every(e=>xa(e)===void 0)&&!ya.has(e)?e:`a_${t.map(e=>xa(e)??e).join(``)}a`},Ca=e=>`is${Sa(e)}`,wa={TRUE:`TRUE`,FALSE:`FALSE`,STRING:`STRING`,BOOLEAN:`BOOLEAN`,Nat:`Nat`,Int:`Int`,Real:Ca(`Real`),Infinity:Ca(`Infinity`),Any:`Any`},Ta={Neg:`~`,DOMAIN:`DOMAIN`,SUBSET:`SUBSET`,UNION:`UNION`},Ea={Implies:`\\<Rightarrow>`,Equiv:`\\<Leftrightarrow>`,Conj:`\\<and>`,Disj:`\\<or>`,Eq:`=`,Neq:`\\<noteq>`,Subseteq:`\\<subseteq>`,Mem:`\\<in>`,Notmem:`\\<notin>`,Setminus:`\\\\`,Cap:`\\<inter>`,Cup:`\\<union>`,OneArg:`:>`,Extend:`@@`},Da={Plus:[`addint`,2],Minus:[`subint`,2],Uminus:[`minus`,1],Times:[`mult`,2],Ratio:[Ca(`/`),2],Quotient:[Ca(`\\div`),2],Remainder:[Ca(`%`),2],Exp:[Ca(`^`),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:[Ca(`\\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]},Oa={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},ka=[`consts`,...[[`Real`,0],[`/`,2],[`\\div`,2],[`%`,2],[`..`,2],[`Infinity`,0],[`[]`,1],[`<>`,1]].map(([e,t])=>` "${Ca(e)}" :: ${t===0?`c`:`"[${Array(t).fill(`c`).join(`,`)}] => c"`}`),``].join(`
27
+ `),Aa=e=>{throw new i(e)},ja=e=>{let t=Number.parseInt(e,10);return`${`succ[`.repeat(t)}0${`]`.repeat(t)}`},Ma=(e,t,n,a)=>{let o=sn(),c=e=>ln(o,Sa(e)),l=()=>ln(o,``),u={isAssumed:!1},d=(e,t)=>{let n=t(c(e));return un(o,1),n},f=e=>`(${y(e)})`,p=e=>e.map(f).join(`, `),m=(e,t)=>`(${e} (${p(t)}))`,h=(e,t)=>{let n=wa[e];if(n!==void 0&&t.length===0)return n;let i=Ta[e];if(i!==void 0&&t.length===1)return`(${i} ${f(t[0])})`;let a=Ea[e];if(a!==void 0&&t.length===2)return`(${f(t[0])} ${a} ${f(t[1])})`;let o=Da[e];if(o&&o[1]===t.length)return m(o[0],t);if(e===`Unprimable`&&t.length===1)return f(t[0]);if(e===`Irregular`&&t.length===1)return Aa(`Irregular`);if((e===`Prime`||e===`StrongPrime`||e===`UNCHANGED`)&&t.length===1)throw new r;let c=Oa[e];throw c&&c[1]===t.length?new s(`Unsupported operator \`${c[0]}\`.\n`):new s(`Backend.Isabelle.pp_apply`)},g=(e,t)=>{switch(e.kind){case`Ix`:{let n=cn(o,e.index);if(e.index<=0||n===void 0)throw new r;return t.length===0?n:`(${n} (${p(t)}))`}case`Opaque`:{let n=Sa(e.name);return t.length===0?`(${n} :: c)`:`(${n} (${p(t)}) :: c)`}case`Internal`:return h(e.builtin,t);case`Lambda`:{let t=`\\<lambda> ${e.params.map(e=>`${c(e.name)} `).join(``)}. ${f(e.body)}`;return un(o,e.params.length),t}default:throw new r}},_=(e,t,n)=>{let[i,...a]=t;if(!i)return y(n);let o=a[0]?.domain.kind===`Ditto`?[{...a[0],domain:i.domain},...a.slice(1)]:a,s=o.length===0?n:{kind:`Quant`,quantifier:e,bounds:o.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:N(1,e.domain.expression)}}:e),body:n,location:n.location},c=e===`Forall`?`\\<forall>`:`\\<exists>`;if(i.domain.kind===`NoDomain`)return d(i.name,e=>`${c}${e} : ${f(s)}`);if(i.domain.kind!==`Domain`)throw new r;let l=f(i.domain.expression);return d(i.name,e=>`${c} ${e} \\<in> ${l} : ${f(s)}`)},v=e=>{let[t,...n]=e.context;if(!t)return f(e.active);let r=()=>v({context:n,active:e.active});switch(t.kind){case`Flex`:return d(t.name,e=>`(\\<And> ${e} ${e}'.${r()})`);case`Fresh`:{if(t.domain&&t.domainVisibility===`Visible`){let e=f(t.domain);return d(t.name,t=>`(\\<And> ${t} :: c. ${t} \\<in> ${e} \\<Longrightarrow> ${r()})`)}let e=`${`c => `.repeat(t.shape)}c`;return d(t.name,t=>`(\\<And> ${t} :: ${e}. ${r()})`)}case`Fact`:{let e=t.visibility===`Visible`?f(t.expression):void 0;l();let n=e?`(${e} \\<Longrightarrow> ${r()})`:r();return un(o,1),n}case`Defn`:return Aa(`Inner definition`)}},y=e=>{switch(e.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return g(e,[]);case`Apply`:return g(e.operator,e.args);case`Bang`:throw new s(`Backend.Isabelle.module`);case`Sequent`:return v(e.sequent);case`With`:case`Parens`:return y(e.expression);case`Let`:return Aa(`LET`);case`List`:return e.bullet===`Refs`&&e.items.length===0?`TRUE`:e.bullet===`Refs`&&e.items.length===1?y(e.items[0]):e.items.map(f).join(e.bullet===`Or`?` | `:` & `);case`If`:return`cond(${f(e.condition)}, ${f(e.consequent)}, ${f(e.alternative)})`;case`Quant`:return _(e.quantifier,e.bounds,e.body);case`Tquant`:return Aa(e.quantifier===`Forall`?`\\\\AA`:`\\\\EE`);case`Choose`:{let t=e.body;if(!e.domain)return d(e.name,e=>`Choice(%${e}. ${f(t)})`);let n=f(e.domain);return d(e.name,e=>`bChoice(${n}, %${e}. ${f(t)})`)}case`SetSt`:{let t=e.body,n=f(e.domain);return d(e.name,e=>`subsetOf(${n}, %${e}. ${f(t)})`)}case`SetOf`:{let t=e.element,[n]=e.bounds;if(!n)throw new r;if(e.bounds.length!==1||n.domain.kind!==`Domain`)return Aa(`SetOf (multiple declared constants)`);let i=f(n.domain.expression);return d(n.name,e=>`setOfAll(${i}, %${e}. ${f(t)})`)}case`SetEnum`:return`{${p(e.elements)}}`;case`Fcn`:{let t=e.body,[n]=e.bounds;if(!n||e.bounds.length!==1)return Aa(`function (multiple declared constants)`);if(n.domain.kind===`Ditto`)throw new r;let i=n.domain.kind===`Domain`?f(n.domain.expression):void 0;return d(n.name,e=>`[${i===void 0?e:` ${e} \\<in> ${i} `} \\<mapsto> ${f(t)}]`)}case`FcnApp`:{let t=f(e.function);return e.args.length===1?`fapply (${t}, ${f(e.args[0])})`:`fapply (${t}, <<${p(e.args)}>>)`}case`Arrow`:return`[${f(e.domain)} \\<rightarrow> ${f(e.range)}]`;case`Rect`:return`[${e.fields.map(e=>`''${e.name}'' : ${f(e.value)}`).join(`, `)}]`;case`Record`:return`(${e.fields.map(e=>`(''${e.name}'' :> ${f(e.value)})`).join(` @@ `)})`;case`Except`:{let t=e.specs.map(e=>`!${e.trail.map(e=>e.kind===`Dot`?`[''${e.field}'']`:`[${f(e.expression)}]`).join(``)} = ${f(e.value)}`);return`[${f(e.function)} EXCEPT ${t.join(`, `)}]`}case`Dot`:return`fapply (${f(e.expression)}, (''${e.field}''))`;case`Tuple`:return`<<${p(e.elements)}>>`;case`Product`:return e.factors.length===2?`(${f(e.factors[0])} \\<times> ${f(e.factors[1])})`:`Product(\\<langle>${p(e.factors)}\\<rangle>)`;case`Sub`:case`Tsub`:{let t=e.kind===`Sub`?`sub`:`tsub`;return`${e.modal===`Box`?Ca(`a'box'${t}`):`a'dia'${t}`}(${f(e.action)},${f(e.subscript)})`}case`Fair`:return`${Ca(e.fairness===`Weak`?`a'wf`:`a'sf`)}(${f(e.subscript)},${f(e.action)})`;case`Case`:{let t=p(e.arms.map(e=>e.condition)),n=p(e.arms.map(e=>e.body));return e.other?`CaseOther(<<${t}>>,<<${n}>>,${f(e.other)})`:`Case(<<${t}>>,<<${n}>>)`}case`String`:return`''${e.value}''`;case`Num`:return e.fraction===``?`(${ja(e.integer)})`:Aa(`real constants`);case`At`:throw new r}},b=e=>{let t=o.stack.length;try{return f(e)}catch(e){if(!(e instanceof i))throw e;return un(o,o.stack.length-t),e}},ee=e=>{let t=[];for(let n of e.context)switch(n.kind){case`Flex`:{let e=c(n.name);t.push(`fixes ${e} ${e}'`);break}case`Fresh`:{let e=n.domain&&n.domainVisibility===`Visible`?f(n.domain):void 0,r=c(n.name);if(t.push(`fixes ${r}`),e===void 0)break;u.isAssumed=!0,t.push(`assumes ${r}_in : "(${r} \\<in> ${e})"`);break}case`Fact`:{let e=o.stack.length,r=n.visibility===`Visible`?b(n.expression):void 0;if(l(),r instanceof i){t.push(`(* omitted temporal assumption : ${r.message} *)`);break}if(r===void 0)break;u.isAssumed=!0,t.push(`assumes v'${e}: "${r}"`);break}case`Defn`:if(n.definition.kind===`Bpragma`)return t.map(e=>`${e}\n`).join(``);t.push(`(* usable definition ${n.definition.name} suppressed *)`),c(n.definition.name)}return[...t,`shows "${f(e.active)}"`].join(`
28
+ `)},x=(()=>{try{return ee(t)}catch(e){throw e instanceof i?new s(`isabelle : unsupported operator ${e.message}`):e}})();return[`(* automatically generated -- do not edit manually *)`,`theory ${a} imports Constant Zenon begin`,ka,`lemma ob'${e}:`,`${x}(is "PROP ?ob'${e}")`,`proof -`,`show "PROP ?ob'${e}"`,`${u.isAssumed?`using assms `:``}by ${n}`,`qed`,`end`,``].join(`
29
+ `)},Na=[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)),Fa=(e,t)=>e<<t|e>>>32-t,Ia=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+Fa(u,Na[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(``)},La=(e,t)=>{let n=xe(e,t-1)?.hyp;if(!n)throw new r;return n},Ra=(e,t)=>pr(e,t).level,za=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),Ba=(e,t)=>{let n=Se(void 0,(n,r)=>{let i=He(r,t=>e(n,t),t);return[k(n,i),i]});return(t,r)=>{let i=n(t,r.context);return{context:i.context,active:e(i.state,r.active)}}},Va=(e,t)=>{if(t.kind===`Sub`||t.kind===`Tsub`){let n=Va(e,t.action),r=Va(e,t.subscript),i=O(`UNCHANGED`,[r],t),a=t.modal===`Box`?O(`Disj`,[n,i],t):O(`Conj`,[n,O(`Neg`,[i],t)],t);return t.kind===`Sub`?a:O(t.modal===`Box`?`BoxTrue`:`Diamond`,[a],t)}return I(e,t,Va,k,`all`)},Ha=(e,t)=>t.kind===`Apply`&&za(t,[`UNCHANGED`])&&t.args.length===1?Or(t.args[0]):I(e,t,Ha,k,`all`),Ua=(e,t)=>O(e,[t],t),Wa=(e,t)=>{if(t.kind===`Ix`){let n=La(e,t.index);return n.kind===`Fresh`&&n.level===`Constant`||n.kind===`Defn`&&n.definition.kind===`Operator`&&Ra(xe(e,t.index),n.definition.body)===0?t:Ua(`Prime`,t)}if(za(t,[`ENABLED`])||t.kind===`Opaque`||t.kind===`Sequent`||t.kind===`Let`)return Ua(`Prime`,t);if(za(t,[`UNCHANGED`,`Cdot`,`Leadsto`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`])||t.kind===`Tquant`||t.kind===`Sub`||t.kind===`Tsub`||t.kind===`Fair`)throw new r;return I(e,t,Wa,k)},Ga=e=>{let t=e===`BoxTrue`?`Conj`:`Disj`,n=e===`BoxTrue`?`Forall`:`Exists`,r=(i,a)=>Ra(i,a)===0?a:za(a,[t])||(a.kind===`Quant`||a.kind===`Tquant`)&&a.quantifier===n?I(i,a,r,k):Ua(e,a);return r},Ka={Prime:Wa,BoxTrue:Ga(`BoxTrue`),Diamond:Ga(`Diamond`)},qa=(e,t)=>{if(t.kind===`Apply`&&t.operator.kind===`Internal`){let n=Ka[t.operator.builtin];if(n){if(t.args.length!==1)throw new r;return n(e,t.args[0])}}return I(e,t,qa,k,`all`)},Ja=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],Ya={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},Xa=(e,t)=>`${e}_${t}_`,Za=(e,t,n)=>{if(t.kind!==`Operator`)return t.kind===`Bpragma`?{...t,body:H(e,t.body)}:t;let i=H(e,t.body),a=Ja[n??Ra(e,i)];if(a===void 0)throw new r;return{...t,name:Xa(a,t.name),body:i}},Qa=(e,t,n)=>{switch(t.kind){case`Fresh`:return{...t,name:Xa(Ya[t.level],t.name),domain:t.domain&&H(e,t.domain)};case`Flex`:return{...t,name:Xa(`VARIABLE`,t.name)};case`Defn`:return{...t,definition:Za(e,t.definition,n)};case`Fact`:return{...t,expression:H(e,t.expression)}}},$a=(e,t)=>{if(t.kind!==`Defn`||t.definition.kind!==`Operator`)return;let n=t=>{if(!za(t,[`UNCHANGED`])||t.kind!==`Apply`)return Ra(e,t);let n=e=>e.kind===`Tuple`?e.elements.flatMap(n):[e],r=n(t.args[0]);return Ra(e,r.length===1?r[0]:t.args[0])},r=t.definition.body;return n(za(r,[`Prime`,`BoxTrue`,`Diamond`])&&r.kind===`Apply`&&r.args.length===1&&r.kind===`Apply`?r.args[0]:r)},eo=Se({scope:void 0,original:void 0},(e,t,n)=>{let r=Qa(e.scope,t,$a(e.original,n));return[{scope:k(e.scope,r),original:k(e.original,n)},r]}),to=(e,t)=>{let n=eo(t.context,e.context);return{context:n.context,active:H(n.state.scope,e.active)}},no=(e,t)=>{let[n,r]=A(e,t.context,(e,t)=>{let n=Qa(e,t);return[k(e,n),n]});return{context:r,active:H(n,t.active)}},H=(e,t)=>{switch(t.kind){case`Lambda`:{let n=t.params.map(e=>({...e,name:Xa(`Unknown`,e.name)})),r=n.reduce((e,t)=>k(e,j(t.name,`Unknown`,t.shape)),e);return{...t,params:n,body:H(r,t.body)}}case`Tquant`:{let n=t.names.reduce((e,t)=>k(e,{kind:`Flex`,name:Xa(`VARIABLE`,t)}),e);return{...t,body:H(n,t.body)}}case`Choose`:{let n=t.domain&&H(e,t.domain),r=Xa(`CONSTANT`,t.name),i=n?Ce(r,n):j(r,`Constant`);return{...t,name:r,domain:n,body:H(k(e,i),t.body)}}case`SetSt`:{let n=H(e,t.domain),r=Xa(`CONSTANT`,t.name),i=H(k(e,Ce(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:Xa(Ya[t.level],t.name),domain:t.domain.kind===`Domain`?{kind:`Domain`,expression:H(e,t.domain.expression)}:t.domain})),r=n.reduce((e,t)=>k(e,j(t.name,t.level)),e);return t.kind===`SetOf`?{...t,bounds:n,element:H(r,t.element)}:{...t,bounds:n,body:H(r,t.body)}}case`Let`:{let[n,r]=A(e,t.definitions,(e,t)=>{let n=Za(e,t);return[k(e,{kind:`Defn`,definition:n,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),n]});return{...t,definitions:r,body:H(n,t.body)}}case`Sequent`:return{...t,sequent:no(e,t.sequent)};default:return I(e,t,H,k,`all`)}},ro=/* @__PURE__ */ new WeakMap,io=(e,t)=>{let n=ro.get(t);if(n)return n;let r=t.kind===`Operator`?t.body:void 0;if(r?.kind!==`Lambda`)return[];let i=r.params.reduce((e,t)=>k(e,j(t.name,`Unknown`,t.shape)),e),a=r.params.map((e,t)=>ao(i,r.body,t+1,!0));return ro.set(t,a),a},ao=(e,t,n,i)=>{if(t.kind===`Ix`)return i||t.index!==n;if(t.kind===`Apply`&&t.operator.kind===`Internal`){let r=t.operator.builtin;if([`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`ENABLED`,`UNCHANGED`].includes(r)&&t.args.length===1||[`Leadsto`,`Actplus`,`Cdot`].includes(r)&&t.args.length===2)return t.args.every(t=>ao(e,t,n,!1))}if(t.kind===`Sub`)return[t.action,t.subscript].every(t=>ao(e,t,n,!1));if(t.kind===`Apply`&&t.operator.kind===`Ix`){let i=xe(e,t.operator.index-1),a=i?.hyp;if(i&&a?.kind===`Defn`&&a.definition.kind===`Operator`){let o=io(i.rest,a.definition);return t.args.every((t,i)=>{let a=o[i];if(a===void 0)throw new r;return ao(e,t,n,a)})}}let a=!0;return I({scope:e,index:n},t,(e,t)=>(a&&!ao(e.scope,t,e.index,i)&&(a=!1),t),(e,t)=>({scope:k(e.scope,t),index:e.index+1}),`all`),a},oo=(e,t)=>{let n=an(kn(ye(e),t));return`h${Ia(n).slice(0,5)}`},so=(e,t)=>D({kind:`Opaque`,name:oo(e,t)},t),co=(e,t,n,r,i)=>{let a=i.map((t,r)=>Ra(e,t)===0||n[i.length-r-1]?D({kind:`Opaque`,name:`*`},t):t);return so(e,D({kind:`Apply`,operator:{kind:`Opaque`,name:t},args:a},r))},lo=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`Leadsto`,`ENABLED`,`Cdot`,`UNCHANGED`],uo=(e,t)=>{if(t.kind!==`Apply`)return I(e,t,uo,k);let n=t.operator,[i]=t.args;if(za(t,[`Prime`,`StrongPrime`])&&t.args.length===1&&i.kind===`Ix`){let n=La(e,i.index);if(n.kind===`Fresh`||n.kind===`Flex`)return D({kind:`Opaque`,name:`${n.name}#prime`},t)}if(za(t,lo))return so(e,t);if(n.kind!==`Ix`)return I(e,t,uo,k);let a=xe(e,n.index-1),o=a?.hyp;if(!o)throw new r;let s=t.args;if(o.kind===`Defn`&&o.definition.kind===`Operator`){let r=io(a.rest,o.definition);if(s.every((t,n)=>Ra(e,t)===0||r[s.length-n-1]))return I(e,t,uo,k);let i=co(e,o.definition.name,r,n,s);return D({kind:`Apply`,operator:i,args:s.map(t=>uo(e,t))},t)}if(o.kind===`Flex`)return I(e,t,uo,k);if(o.kind===`Fresh`){if(o.level===`Constant`)return D({kind:`Apply`,operator:n,args:s.map(t=>uo(e,t))},t);let r=s.map(()=>!1);return co(e,o.name,r,n,s)}throw new r},fo=Ba(Va,`all`),po=Ba(Ha,`all`),mo=Ba(qa,`all`),ho=Ba(uo,`visible`),go=e=>{let t=e.context,n=po(t,fo(t,e)),r=mo(t,n);return ho(t,to(r,e))},_o=Se(w(0),(e,t)=>t.kind===`Defn`&&(t.definition.kind===`Bpragma`||t.definition.kind===`Operator`&&t.visibility===`Visible`)?[T(M(e,t.definition.body),e),void 0]:[E(1,e),Ae(e,t)]),vo=e=>{let t=_o(e.context);return{context:t.context,active:M(t.state,e.active)}},yo=/* @__PURE__ */ new Set([`BoxTrue`,`BoxFalse`,`Diamond`,`Actplus`,`Leadsto`,`Cdot`]),bo=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]}},xo=e=>{if(e.kind===`Tsub`||e.kind===`Fair`||e.kind===`Apply`&&e.operator.kind===`Internal`&&yo.has(e.operator.builtin))return!1;if(e.kind===`Sequent`){let t=e.sequent;return[...t.context.flatMap(bo),t.active].every(xo)}return We(e).every(xo)},So=t=>{if(t.kind!==`Let`)return Ue(t,So);let[n,...r]=t.definitions;if(!n)return So(t.body);if(n.kind!==`Operator`&&n.kind!==`Bpragma`)throw new e(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=So(n.body),a={...t,definitions:r};return So(M(T(i,w(0)),a))},Co=(e,t)=>t.kind===`Dot`?D({kind:`Dot`,expression:e,field:t.field},e):D({kind:`FcnApp`,function:e,args:[t.expression]},e),wo=(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&F(e.expression,t.expression),To=(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},Eo=e=>{if(e.kind!==`Except`)return Ue(e,Eo);let t=e,n=(e,t)=>To(e,t)?.value??Co(e,t),r=(e,n,r)=>{let i=To(e,n);if(e.kind!==`Record`||!i)return D({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 D({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||!wo(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(Eo(t.function),Be(t.specs,Eo))},Do=Se(!0,(e,t)=>[e&&bo(t).every(xo),He(t,So,`all`)]),Oo=Se(void 0,(e,t)=>[void 0,He(t,Eo,`all`)]),ko=e=>{let t=Do(e.context),n=So(e.active);return t.state&&xo(e.active)?{context:Oo(e.context,t.context).context,active:Eo(n)}:{context:t.context,active:n}},Ao={kind:`Internal`,builtin:`TRUE`},jo=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2?e.args:void 0,Mo=e=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`ENABLED`&&e.args.length===1?e.args[0]:void 0,No=(e,t)=>{let n=jo(e,t),r=n&&Mo(n[0]),i=n&&Mo(n[1]);return r&&i?[r,i]:void 0},Po=(e,t)=>{let n=/* @__PURE__ */ new Set,i=(e,t)=>{let a={...e,isPrimed:!0},o=t.kind===`Apply`&&t.operator.kind===`Internal`&&t.operator,s=o&&o.builtin,c=t.kind===`Apply`?t.args:[];if((s===`Prime`&&c.length===1||s===`ENABLED`||s===`Cdot`&&c.length===2||s===`UNCHANGED`&&c.length===1||t.kind===`Sub`)&&e.isPrimed)throw new r;if(s===`Prime`&&c.length===1)i(a,c[0]);else if(s===`Cdot`&&c.length===2)i(e,c[1]);else if(s===`UNCHANGED`&&c.length===1)i(a,c[0]);else if(t.kind===`Sub`)i(e,t.action),i(a,t.subscript);else if(t.kind===`Ix`){let i=xe(e.scope,t.index-1)?.hyp;if(!i)throw new r;i.kind===`Flex`&&e.isPrimed&&n.add(i.name)}else s!==`ENABLED`&&I(e,t,i,(e,t)=>({...e,scope:k(e.scope,t)}));return t};return i({scope:e,isPrimed:!1},t),n},Fo=(e,t,n)=>{let r=Po(e,t);return[...Po(e,n)].every(e=>!r.has(e))},Io=(e,t)=>{let n=t=>pr(e,t).level,i=(e,t)=>{if(n(e)>2||n(t)>2)throw new r},a=Mo(t),o=a&&jo(a,`Disj`);if(o)return i(o[0],o[1]),{name:`abdisj_inverse`,left:o[0],right:o[1]};let s=No(t,`Disj`);if(s)return i(s[0],s[1]),{name:`abdisj`,left:s[0],right:s[1]};let c=a&&jo(a,`Conj`);if(c){let t=c[0],r=c[1],a=Fo(e,t,r);return i(t,r),a?{name:n(t)===2?`abconj_inverse`:`pconj_inverse`,left:t,right:r}:void 0}let l=No(t,`Conj`);if(l)return Fo(e,l[0],l[1])?{name:`abconj`,left:l[0],right:l[1]}:void 0;let u=jo(t,`Conj`),d=u&&Mo(u[1]);if(u&&d)return n(u[0])<=1&&n(d)<=2?{name:`pconj`,left:u[0],right:d}:void 0;let f=No(t,`Equiv`)??No(t,`Eq`);if(f)return{name:`equiv`,left:f[0],right:f[1]};let p=No(t,`Implies`);return p&&{name:`implies`,left:p[0],right:p[1]}},Lo=e=>{let t=ve(void 0,e.context),n=Io(t,e.active),r={isPremise:!1,isLeftBoolean:!1,isRightBoolean:!1};if(e.context.forEach((t,i)=>{if(!n||t.kind!==`Fact`||t.visibility!==`Visible`)return;let a=e.context.length-i,o=t.expression,s=e=>F(N(a,e),n.left),c=e=>F(N(a,e),n.right),l=(e,t)=>e!==void 0&&s(e[0])&&c(e[1])&&t.includes(n.name),u=Mo(o),d=u&&jo(u,`Conj`),f=jo(o,`Conj`),p=f&&Mo(f[1]),m=jo(o,`Mem`),h=m?.[1].kind===`Internal`&&m[1].builtin===`BOOLEAN`;l(d,[`pconj`])||l(u&&jo(u,`Disj`),[`abdisj`])||l(No(o,`Disj`),[`abdisj_inverse`])||l(d,[`abconj`])||l(No(o,`Conj`),[`abconj_inverse`,`pconj_inverse`])||l(f&&p&&[f[0],p],[`pconj_inverse`])?r.isPremise=!0:l(jo(o,`Equiv`),[`equiv`])?(r.isPremise=!0,r.isLeftBoolean=!0,r.isRightBoolean=!0):l(jo(o,`Eq`),[`equiv`])?r.isPremise=!0:m&&h&&s(m[0])?r.isLeftBoolean=!0:m&&h&&c(m[0])?r.isRightBoolean=!0:l(jo(o,`Implies`),[`implies`])&&(r.isPremise=!0)}),!r.isPremise||!r.isLeftBoolean||!r.isRightBoolean)throw new s(`ENABLEDaxioms proof directive did not succeed.
30
+ `);return{...e,active:Ao}},Ro={Constant:0,State:1,Action:2,Temporal:3},zo=(e,t,n)=>e.every((e,r)=>r<t.length&&n(e,t[r]))&&e.length===t.length,Bo=e=>[...new Map(e.toReversed().map(e=>[e.name,e.value]))].toSorted((e,t)=>e[0]<t[0]?-1:1),Vo=(e,t)=>{let n=xe(e,t-1);if(!n)throw new r;let i=n.hyp;if(i.kind===`Fresh`)return{name:i.name,kind:i.level,level:Ro[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=pr(n.rest,i.definition.body).level;return{name:i.definition.name,kind:`Definition`,level:e}}throw new r},Ho=(e,t)=>t.reduce((e,t)=>k(e,j(t.name,t.level)),e),Uo=(e,t)=>t.reduce((e,t)=>k(e,j(t.name,`Unknown`,t.shape)),e),Wo=(e,t)=>t.reduce((e,t)=>k(e,{kind:`Defn`,definition:t,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),e),Go=(e,t)=>t.reduce((e,t)=>k(e,{kind:`Flex`,name:t}),e),Ko=(e,t,n,i)=>{let a=/* @__PURE__ */ new Map,o=(e,t,n,r)=>{let i=Vo(e,n),o=Vo(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=Ro[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)=>t.reduce((e,t)=>k(e,j(t,`Unknown`)),e),s=e=>Bo(e.substitutions.map(e=>({name:e.name,value:e.expression})));return zo(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)=>zo(n,r,(n,r)=>n[0]===r[0]&&p(e,t,n[1],r[1])),l=(e,t,n,r)=>zo(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(k(e,n[0]),k(t,r[0]),n.slice(1),r.slice(1)),f=(e,t,n,r)=>!n.domain||!r.domain?!n.domain&&!r.domain&&p(k(e,j(n.name,`Constant`)),k(t,j(r.name,`Constant`)),n.body,r.body):p(e,t,n.domain,r.domain)&&p(k(e,Ce(n.name,n.domain)),k(t,Ce(r.name,r.domain)),n.body,r.body),p=(e,t,n,i)=>{if(n.kind===`Parens`)return p(e,t,n.expression,i);if(i.kind===`Parens`)return p(e,t,n,i.expression);let a=(n,r)=>p(e,t,n,r),u=(e,t)=>zo(e,t,a);switch(n.kind){case`Ix`:return i.kind===`Ix`&&o(e,t,n.index,i.index);case`Opaque`:return i.kind===`Opaque`&&n.name===i.name;case`Internal`:return i.kind===`Internal`&&n.builtin===i.builtin;case`Lambda`:return i.kind===`Lambda`&&n.params.length===i.params.length&&p(Uo(e,n.params),Uo(t,i.params),n.body,i.body);case`Apply`:return i.kind===`Apply`&&a(n.operator,i.operator)&&u(n.args,i.args);case`Sequent`:return i.kind===`Sequent`&&d(e,t,n.sequent.context,i.sequent.context)&&p(ve(e,n.sequent.context),ve(t,i.sequent.context),n.sequent.active,i.sequent.active);case`Bang`:{if(i.kind!==`Bang`||!a(n.expression,i.expression))return!1;let e=i.selectors,t=n.selectors.every((t,n)=>{let r=e[n];return r?t.kind===`Number`&&r.kind===`Number`?t.value===r.value:t.kind===`Instance`&&r.kind===`Instance`?u(t.args,r.args):t.kind===`Label`&&r.kind===`Label`?t.label===r.label&&u(t.args,r.args):t.kind===r.kind:!0});if(t&&n.selectors.length!==e.length)throw new r(`Invalid_argument`);return t}case`With`:return i.kind===`With`&&a(n.expression,i.expression);case`Let`:return i.kind===`Let`&&zo(n.definitions,i.definitions,(n,r)=>s(e,t,n,r))&&p(Wo(e,n.definitions),Wo(t,i.definitions),n.body,i.body);case`If`:return i.kind===`If`&&a(n.condition,i.condition)&&a(n.consequent,i.consequent)&&a(n.alternative,i.alternative);case`List`:return i.kind===`List`&&n.bullet===i.bullet&&u(n.items,i.items);case`Quant`:return i.kind===`Quant`&&n.quantifier===i.quantifier&&l(e,t,n.bounds,i.bounds)&&p(Ho(e,n.bounds),Ho(t,n.bounds),n.body,i.body);case`Tquant`:return i.kind===`Tquant`&&n.quantifier===i.quantifier&&zo(n.names,i.names,(e,t)=>e===t)&&p(Go(e,n.names),Go(t,i.names),n.body,i.body);case`Choose`:return i.kind===`Choose`&&f(e,t,n,i);case`SetSt`:return i.kind===`SetSt`&&f(e,t,n,i);case`SetOf`:return i.kind===`SetOf`&&p(Ho(e,n.bounds),Ho(t,i.bounds),n.element,i.element)&&l(e,t,n.bounds,i.bounds);case`SetEnum`:return i.kind===`SetEnum`&&u(n.elements,i.elements);case`Arrow`:return i.kind===`Arrow`&&a(n.domain,i.domain)&&a(n.range,i.range);case`Fcn`:return i.kind===`Fcn`&&l(e,t,n.bounds,i.bounds)&&p(Ho(e,n.bounds),Ho(t,i.bounds),n.body,i.body);case`FcnApp`:return i.kind===`FcnApp`&&u([n.function,...n.args],[i.function,...i.args]);case`Tuple`:return i.kind===`Tuple`&&u(n.elements,i.elements);case`Product`:return i.kind===`Product`&&u(n.factors,i.factors);case`Rect`:return i.kind===`Rect`&&c(e,t,Bo(n.fields),Bo(i.fields));case`Record`:return i.kind===`Record`&&c(e,t,Bo(n.fields),Bo(i.fields));case`Except`:return i.kind===`Except`&&a(n.function,i.function)&&zo(n.specs,i.specs,(e,t)=>zo(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(n.expression,i.expression)&&n.field===i.field;case`Sub`:return i.kind===`Sub`&&n.modal===i.modal&&a(n.action,i.action)&&a(n.subscript,i.subscript);case`Tsub`:return i.kind===`Tsub`&&n.modal===i.modal&&a(n.action,i.action)&&a(n.subscript,i.subscript);case`Fair`:return i.kind===`Fair`&&n.fairness===i.fairness&&a(n.subscript,i.subscript)&&a(n.action,i.action);case`Case`:{if(i.kind!==`Case`)return!1;let e=n.arms[0],t=i.arms[0];return(e&&t?a(e.condition,t.condition)&&a(e.body,t.body):!e&&!t)?n.other&&i.other?a(n.other,i.other):!n.other&&!i.other:!1}case`String`:return i.kind===`String`&&n.value===i.value;case`Num`:return i.kind===`Num`&&n.integer===i.integer&&n.fraction===i.fraction;case`At`:return i.kind===`At`&&n.isExcept===i.isExcept}},m=p(e,t,n,i),h=ye(e),g=[...a].map(e=>e[0]===e[1]||h.reduce((t,n)=>{if(n.kind===`Fact`)return t;if(n.kind===`Defn`&&n.definition.kind!==`Operator`)throw new r;return t||(n.kind===`Defn`?n.definition.name:n.name)===e[0]},!1));return m&&g.every(Boolean)},qo=e=>{let t=ve(void 0,e.context);if(!e.context.some((n,r)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return!1;let i=xe(t,e.context.length-r),a=n.expression;return a.kind===`Sequent`?Ko(ve(i,a.sequent.context),t,a.sequent.active,e.active):Ko(i,t,a,e.active)}))throw new s(`LevelComparison proof directive did not succeed.
31
+ `);return{...e,active:{kind:`Internal`,builtin:`TRUE`}}},Jo=(e,t)=>{let n=t.has(`expandenabled`),i=t.has(`expandcdot`),a=t.has(`autouse`),o=t.has(`lambdify`);if(!n&&!i&&!o)return t.has(`levelcomparison`)?qo(e):t.has(`enabledaxioms`)?Lo(e):e;let s=kt({value:0},()=>{throw new r},()=>{}),c={kind:`Sequent`,sequent:e},l=n||i?Vr(s,()=>{},void 0,c,{isEnabled:n,isCdot:i,isAutoUse:a}):Rr(s,()=>{},void 0,c,{isEnabled:!0,isCdot:!0,isAutoUse:a});if(l.kind!==`Sequent`)throw new r;return l.sequent},Yo=/* @__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(`.`),Xo={And:0,Or:1,Refs:2},Zo={Forall:0,Exists:1},Qo={Box:0,Dia:1},$o={Weak:0,Strong:1},es={34:`\\"`,92:`\\\\`,10:`\\n`,9:`\\t`,13:`\\r`,8:`\\b`},ts=e=>`"${[...new TextEncoder().encode(e)].map(e=>es[e]??(e<32||e>126?`\\${String(e).padStart(3,`0`)}`:String.fromCharCode(e))).join(``)}"`,ns=e=>e===`BoxTrue`?`$Box`:e===`BoxFalse`?`$FakeBox`:`$${Yo.indexOf(e)}`,rs=e=>e.level===`Unknown`?`Unknown`:e.level.toUpperCase(),is=e=>{let t=[],n=e=>{let n=t[t.length-e];if(!n)throw new r;return n},i=e=>t.push({ident:e,isUsed:!1}),a=()=>{let e=t.pop();if(!e)throw new r;return e},o=e=>Array.from({length:e}).forEach(()=>i({kind:`Var`})),s=e=>Array.from({length:e},a),c=e=>{if(e.ident.kind===`VarIndex`)return e.ident.index;if(e.ident.kind===`Var`)return 0;throw new r},l=e=>{if(e.ident.kind!==`HypIndex`)throw new r;return e.ident.index},u=(e,t)=>{let a=t=>u(e,t),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(t.kind){case`Ix`:{let i=n(t.index);i.isUsed=!0;let a=i.ident;switch(a.kind){case`None`:return`$V(${t.index}SHOULD_NOT_APPEAR)`;case`Hyp`:{let t=e.hyp++;return i.ident={kind:`HypIndex`,index:t},`$${a.label}(${t})`}case`Var`:{let t=e.variable++;return i.ident={kind:`VarIndex`,index:t},`$PRM(${t})`}case`HypIndex`:return`$HYP(${a.index})`;case`VarIndex`:return`$PRM(${a.index})`;case`Pragma`:return``}throw new r}case`Opaque`:return t.name;case`Internal`:return ns(t.builtin);case`Lambda`:{let e=p(t.params.length,t.body);return`$Lam(${m(e.entries.toReversed())}${e.text})`}case`Sequent`:return d(t.sequent);case`Apply`:{let e=t.operator;return e.kind===`Ix`&&n(e.index).ident.kind===`Pragma`?``:`$OpApp(${a(e)};${l(t.args)})`}case`With`:case`Parens`:return a(t.expression);case`If`:return`$If(${a(t.condition)},${a(t.consequent)},${a(t.alternative)})`;case`List`:return`$List(${Xo[t.bullet]};${l(t.items)})`;case`Let`:{let e=t.definitions.map(e=>{if(e.kind!==`Operator`&&e.kind!==`Bpragma`)throw new r;let t=`${a(e.body)}.`;return i({kind:`Var`}),t}),n=a(t.body);return s(e.length),`${e.join(``)}${n}`}case`Quant`:{let e=p(t.bounds.length,t.body);return`$Quant(${Zo[t.quantifier]};${f(e.entries,t.bounds)}.${e.text})`}case`Tquant`:{let e=p(t.names.length,t.body);return`$Tquant(${Zo[t.quantifier]}${m(e.entries.toReversed())}${e.text})`}case`Choose`:{let e=p(1,t.body),n=c(e.entries[0]);return t.domain?`$Bch(${n}:${a(t.domain)};${e.text})`:`$Ch(${n}:${e.text})`}case`SetSt`:{let e=p(1,t.body);return`$SSt(${c(e.entries[0])}:${a(t.domain)};${e.text})`}case`SetOf`:{let e=p(t.bounds.length,t.element);return`$Sof(${f(e.entries.toReversed(),t.bounds)}.${e.text})`}case`Fcn`:{let e=p(t.bounds.length,t.body);return`$Fcn(${f(e.entries.toReversed(),t.bounds)}.${e.text})`}case`SetEnum`:return`$Set(${l(t.elements)})`;case`Tuple`:return`$Tup(${l(t.elements)})`;case`Product`:return`$Prod(${l(t.factors)})`;case`FcnApp`:return`$FcnApp(${a(t.function)};${l(t.args)})`;case`Arrow`:return`$Arrow(${a(t.domain)},${a(t.range)})`;case`Rect`:case`Record`:return`$${t.kind}(${t.fields.map(e=>`(${e.name},${a(e.value)})`).join(`,`)})`;case`Except`:return`$Except(${a(t.function)},${t.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(t.expression)},${t.field})`;case`Sub`:case`Tsub`:return`$${t.kind}(${Qo[t.modal]},${a(t.action)},${a(t.subscript)})`;case`Fair`:return`$Fair(${$o[t.fairness]},${a(t.subscript)},${a(t.action)})`;case`Case`:return`$Case(${t.arms.map(e=>`(${a(e.condition)},${a(e.body)})`).join(`,`)},${t.other?a(t.other):``})`;case`String`:return ts(t.value);case`Num`:return`$Num(${t.integer},${t.fraction})`;case`At`:return`$At`;case`Bang`:throw new r}},d=e=>{let t={hyp:1,variable:1},n=(o,s)=>{let c=e.context[o];if(!c)return`$Goal(${u(t,e.active)})`;let d=e=>(i(e),{rest:n(o+1,k(s,c)),entry:a()});switch(c.kind){case`Fresh`:{if(!c.domain){let e=rs(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 n=e.entry.isUsed?String(l(e.entry)):`_`;return`${e.rest}$Dom(${n};${u(t,c.domain)})`}case`Flex`:return d({kind:`Hyp`,label:`VAR`}).rest;case`Defn`:{let e=c.definition;if(e.kind===`Recursive`)return d({kind:`Hyp`,label:`CON`}).rest;if(e.kind===`Bpragma`)return d({kind:`Pragma`}).rest;if(e.kind===`Instance`)throw new r;let n=d({kind:`Hyp`,label:`HYP`});if(!n.entry.isUsed)return n.rest;let i=l(n.entry);return c.visibility===`Hidden`?`${n.rest}$Def(${i},${bt(s,e.body)?0:3})`:`${n.rest}$Def(${i};${u(t,e.body)})`}case`Fact`:return c.visibility===`Hidden`?d({kind:`None`}).rest:`${d({kind:`Hyp`,label:`HYP`}).rest}$Fact(${u(t,c.expression)},${c.time.toLowerCase()})`}};return n(0,void 0)};return d(e)},as=e=>Ia(is(e)),os=e=>e.domain.kind===`NoDomain`,ss=e=>{if(e.kind===`List`&&(e.bullet===`And`||e.bullet===`Refs`)){let t=e.items.map(ss),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=ss(e.args[0]),n=ss(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(os)){let t=ss(e.body),n=(t,n)=>D({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]},cs=e=>{let t=[],n=e.context.reduce((e,n)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return t.push(Ae(e,n)),E(1,e);let r=ss(n.expression),i=[...r[1]?[r[1]]:[],...r[0]];return i.forEach((r,i)=>t.push({...n,expression:N(i,M(e,r))})),{kind:`Compose`,outer:w(i.length-1),inner:E(1,e)}},w(0));return{context:t,active:M(n,e.active)}},ls=/* @__PURE__ */ new Set([`expandenabled`,`expandcdot`,`autouse`,`lambdify`,`enabledaxioms`,`levelcomparison`]),us=[{prover:`smt`,timeLimitMs:5e3},{prover:`zenon`,timeLimitMs:1e4},{prover:`isabelle`,timeLimitMs:3e4,tactic:`auto`}],ds={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([...ls].map(e=>[e,{prover:e,seconds:0}]))},fs=(e,t,n,r)=>{let i=ds[e];if(!i)throw new s(`Unknown prover: ${e}`);if(n!==void 0&&!i.isBudgeted)throw new s(`A Z3 rlimit budget ("rN") is only supported by the SMT and Z3 backends.`);return{prover:i.prover,timeLimitMs:n===void 0?(t??i.seconds)*1e3:1/0,...n!==void 0&&{rlimit:n},...i.prover===`isabelle`&&{tactic:r??`auto`}}},ps=e=>{let t=Number.parseFloat(e.slice(1));if(!/^[rR]./.test(e)||!Number.isFinite(t)||t<=0)throw new s(`Invalid SMT budget "${e}"`);return Math.max(1,Math.trunc(Math.min(t*3e6,4294967295)))},ms=(e,t)=>{let n=e.reduce((e,t)=>{let n=t.value,r=n.kind===`Default`?e.args[0]:void 0,i=n.kind===`Default`?e.args.slice(1):e.args;if(n.kind===`Default`&&!r)throw new s(`Some arguments are missing`);let a=n.kind===`String`?n.value:r?.kind===`String`?r.value:void 0;switch(t.hint){case`prover`:case`tactic`:if(a===void 0)throw new s(`This argument should be a string`);return{...e,args:i,[t.hint]:a};case`timeout`:if(n.kind===`Float`)return{...e,args:i,timeout:n.value};if(a!==void 0)return{...e,args:i,rlimit:ps(a)};if(r?.kind!==`Num`)throw new s(`This argument should be a number of seconds`);return{...e,args:i,timeout:Number(`${r.integer}.${r.fraction}`)};default:throw new s(`Unknown keyword in proof method definition: ${t.hint}`)}},{args:t});if(n.args.length>0)throw new s(`Too many arguments`);if(n.prover===void 0)throw new s(`Missing prover name`);return fs(n.prover,n.timeout,n.rlimit,n.tactic)},hs=e=>fs(e.name,e.timeout,void 0,e.tactic),gs=e=>{let t=[],n={methods:[],useLocation:null};return e.context.forEach((e,i)=>{let a=e.kind===`Fact`&&e.visibility===`Visible`&&e.expression;if(a&&a.kind===`With`){n.methods.push(hs(a.method)),t.push(void 0);return}if(e.kind===`Defn`&&e.definition.kind===`Bpragma`){t.push({kind:`Premeth`,groups:e.definition.methods});return}if(e.kind===`Defn`&&e.definition.kind===`Operator`&&e.visibility===`Visible`){let n=e.definition.body;t.push(n.kind===`With`?{kind:`Meth`,method:n.method}:void 0);return}if(t.push(void 0),!a||e.kind!==`Fact`)return;let o=a.kind===`Apply`?a.operator:a;if(o.kind!==`Ix`)return;let s=t[i-o.index];if(s?.kind===`Premeth`){e.useLocation!==n.useLocation&&(n.methods=[],n.useLocation=e.useLocation);let t=a.kind===`Apply`?a.args:[];n.methods.push(...s.groups.map(e=>ms(e,t)))}else if(s?.kind===`Meth`){if(a.kind===`Apply`)throw new r;n.methods.push(hs(s.method))}}),n.methods},_s=e=>{let t=e.method===void 0?gs(e.sequent):[hs(e.method)],n=t.filter(e=>!ls.has(e.prover));return{frontends:new Set(t.flatMap(e=>ls.has(e.prover)?[e.prover]:[])),provers:n.length>0?n:us}},vs=e=>e.active.kind===`Internal`&&e.active.builtin===`TRUE`||e.context.some((t,n)=>t.kind===`Fact`?F(t.expression,N(n-e.context.length,e.active)):t.kind!==`Fresh`||!t.domain?!1:F(O(`Mem`,[{kind:`Ix`,index:1},N(1,t.domain)],{}),N(n+1-e.context.length,e.active))),ys={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},bs=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],xs=(e,t)=>{let[n,r]=A(e,t.context,(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return{...t,name:`${ys[t.level]}_${t.name}_`,domain:t.domain&&Ss(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=Ss(e,n.body),i=bs[pr(e,r).level];return{...t,definition:{...n,name:`${i}_${n.name}_`,body:r}}}case`Fact`:return{...t,expression:Ss(e,t.expression)}}})();return[k(e,n),n]});return{context:r,active:Ss(n,t.active)}},Ss=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:xs(e,t.sequent)};let n=I(e,t,Ss,k,`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:`${ys[e.level]}_${e.name}_`}))};case`Choose`:case`SetSt`:return{...n,name:`CONSTANT_${n.name}_`};default:return n}},Cs=(e,t)=>{if(t.kind!==`Sequent`)return I(e,t,Cs,k,`all`);let n={scope:e,substitution:w(0),context:[]},r=e=>{let t=e.kind===`Fact`&&e.visibility===`Visible`&&e.time===`Always`?{...e,expression:O(`BoxTrue`,[e.expression],e.expression)}:e;n.context.push(t),n.scope=k(n.scope,t)};for(let e of t.sequent.context){let t=Ae(n.substitution,e);if(t.kind===`Fact`){r({...t,expression:Cs(n.scope,t.expression)}),n.substitution=E(1,n.substitution);continue}if(t.kind!==`Fresh`||!t.domain||e.kind!==`Fresh`||!e.domain){r(t),n.substitution=E(1,n.substitution);continue}let i=Cs(n.scope,t.domain);r({...t,domain:void 0}),r({kind:`Fact`,expression:O(`Mem`,[D({kind:`Ix`,index:1},i),N(1,i)],i),visibility:t.domainVisibility,time:t.level===`Constant`?St(n.scope,e.domain):`Now`,location:t.location}),n.substitution={kind:`Compose`,outer:w(1),inner:E(1,n.substitution)}}let i=M(n.substitution,t.sequent.active);return{...t,sequent:{context:n.context,active:Cs(n.scope,i)}}},ws={Conj:`&`,Disj:`|`,Implies:`->`,Equiv:`<->`},Ts={Neg:`~`,BoxTrue:`always`,BoxFalse:`always`,Diamond:`sometime`,Prime:`next`},Es=e=>{if(e.kind===`Internal`&&e.builtin===`TRUE`)return;if(e.kind===`List`&&e.bullet!==`Or`){let t=e.items.flatMap(e=>Es(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=Es(e.args[0]),n=Es(e.args[1]);return t&&n?{...e,args:[t,n]}:t??n},Ds=`(cc | ~ cc)`,Os=e=>{let t=(e,n,r=!1)=>{let i=n=>t(e,n);switch(n.kind){case`Internal`:if(n.builtin===`TRUE`)return Ds;if(n.builtin===`FALSE`)return`(cc & ~ cc)`;break;case`Apply`:{let e=n.operator,t=n.args;if(e.kind!==`Internal`)break;let r=ws[e.builtin];if(r&&t.length===2)return`(${i(t[0])} ${r} ${i(t[1])})`;let a=Ts[e.builtin];if(a&&t.length===1)return`(${a} ${i(t[0])})`;break}case`List`:{if(n.items.length===0)return Ds;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?Es(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${Ia(an(kn(e,n))).slice(0,5)}`},n=Ss(void 0,{kind:`Sequent`,sequent:e});return`not (${t([],Cs(void 0,pt(dt(ft(n)))),!0)})`},ks=(e,t)=>e<t?-1:+(e>t),As=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return ks(e,t);if(!Array.isArray(e)||!Array.isArray(t))return 0;let n=e.findIndex((e,n)=>n>=t.length||As(e,t[n])!==0);return n===-1?e.length-t.length:n>=t.length?1:As(e[n],t[n])},js={"\\":`backslash_`,"+":`plussign_`,"-":`hyphen_`,"*":`asterisk_`,"/":`slash_`,"%":`percentsign_`,"^":`circumflexaccent_`,"&":`ampersand_`,"@":`atsign_`,"#":`pound_`,$:`dollarsign_`,"(":`leftparenthesis_`,")":`rightparenthesis_`,"|":`verticalbar_`,".":`period_`,":":`colon_`,"?":`questionmark_`,"!":`exclamationmark_`,"<":`lessthansign_`,">":`greaterthansign_`,"=":`equalsign_`," ":`space_`},Ms=e=>`smt__${e.replace(/[\\+\-*/%^&@#$()|.:?!<>= ]/g,e=>js[e]).replaceAll(`_`,`__`)}`,Ns=Ms(`TLA__`),Ps=new Map(Object.entries(js).map(e=>[e[1],e[0]])),Fs=RegExp(`(${[...Ps.keys()].join(`|`)})`,`g`),U=e=>Ms(`TLA__${e}`),Is=e=>e.startsWith(Ns)?e.slice(Ns.length).replaceAll(`__`,`_`).replace(Fs,e=>Ps.get(e)??e):void 0,W=U(`Mem`),Ls=U(`SetExtTrigger`),Rs=U(`SubsetEq`),zs=U(`Cup`),Bs=U(`Cap`),Vs=U(`SetMinus`),Hs=U(`Subset`),Us=U(`Union`),Ws=U(`Tt_Idv`),Gs=U(`Cast_Bool`),Ks=U(`BoolSet`),qs=U(`StrSet`),Js=U(`IntSet`),Ys=U(`NatSet`),G=U(`Cast_Int`),K=U(`Proj_Int`),Xs=U(`IntLteq`),Zs=U(`IntRange`),q=U(`FunApp`),J=U(`FunDom`),Qs=U(`FunIsafcn`),$s=U(`FunSet`),ec=U(`FunExcept`),tc=U(`TrigEq_Set$Idv$`),nc=U(`IsSetOf`),Y=U(`Seq`),X=U(`Len`),rc=U(`Cat`),ic=U(`Append`),ac=U(`Head`),oc=U(`Tail`),sc=U(`SubSeq`),cc=U(`Tuple_0`),lc={Cup:zs,Cap:Bs,Setminus:Vs,SUBSET:Hs,UNION:Us,DOMAIN:J,Plus:U(`IntPlus`),Minus:U(`IntMinus`),Times:U(`IntTimes`),Exp:U(`IntExp`),Quotient:U(`IntQuotient`),Remainder:U(`IntRemainder`),Uminus:U(`IntUminus`),Range:Zs,Seq:Y,Len:X,BSeq:U(`BSeq`),Cat:rc,Append:ic,Head:ac,Tail:oc,SubSeq:sc},uc=(e,t)=>Array.from({length:t},(t,n)=>`${e}${n+1}`),dc=e=>e.map(e=>`(${e[0]} ${e[1]})`).join(` `),Z=(e,t,n=[],r=`Idv`)=>e.length===0?t:`(forall (${dc(e.map(e=>[e,r]))}) ${n.length===0?t:`(! ${t} ${n.map(e=>`:pattern (${e.join(` `)})`).join(` `)})`})`,fc=e=>e.length===0?`true`:e.length===1?e[0]:`(and ${e.join(` `)})`,pc=e=>e.length===0?`false`:e.length===1?e[0]:`(or ${e.join(` `)})`,Q=(e,t)=>t.length===0?e:`(${e} ${t.join(` `)})`,mc=(e,t,n=`Idv`,r=`Idv`)=>`(declare-fun ${e} (${Array.from({length:t},()=>r).join(` `)}) ${n})`,hc=(e,t,n)=>e.replace(/[^\s()]+/g,e=>e===t?n:e),gc=/* @__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(`.`),_c=/* @__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(`.`),vc=[`TIntPlus`,`TIntUminus`,`TIntMinus`,`TIntTimes`,`TIntQuotient`,`TIntRemainder`,`TIntLteq`],$=(e,t,n,r)=>({name:e,args:t,label:r??[e,...t.flat()].join(` `),formula:n}),yc=e=>`${e.name} ${JSON.stringify(e.args)}`,bc=e=>{let t=gc.indexOf(e.name);return t===-1?gc.length+_c.indexOf(e.name):t},xc=(e,t)=>bc(e)-bc(t)||As(e.args,t.args),Sc=(e,t,n,r=!1)=>{let i=U(e),a=n===1?[`x1`]:r?[`x`,`y`]:[`x1`,`x2`],o=Q(i,a.map(e=>`(${G} ${e})`)),s=`(= ${o} ${t===`<=`?`(<= ${a.join(` `)})`:`(${G} (${t} ${a.join(` `)}))`})`;return $(`Typing`,[vc.indexOf(`T${e}`)],Z(a,r?`(=> (> y 0) ${s})`:s,[[o]],`Int`),`Typing T${e}`)},Cc={IntPlus:()=>Sc(`IntPlus`,`+`,2),IntMinus:()=>Sc(`IntMinus`,`-`,2),IntTimes:()=>Sc(`IntTimes`,`*`,2),IntUminus:()=>Sc(`IntUminus`,`-`,1),IntQuotient:()=>Sc(`IntQuotient`,`div`,2,!0),IntRemainder:()=>Sc(`IntRemainder`,`mod`,2,!0),IntLteq:()=>Sc(`IntLteq`,`<=`,2)},wc=e=>{let t=U(`SetEnum_${e}`),n=uc(`a`,e),r=Q(t,n),i=$(`EnumDefElim`,[e],Z([...n,`x`],e===0?`(not (${W} x ${r}))`:`(=> (${W} x ${r}) ${pc(n.map(e=>`(= x ${e})`))})`,[[`(${W} x ${r})`]]));return e===0?[i]:[$(`EnumDefIntro`,[e],Z(n,fc(n.map(e=>`(${W} ${e} ${r})`)),[[r]])),i]},Tc=e=>Array.from({length:e},(e,t)=>`(${G} ${t+1})`),Ec=(e,t,n,r,i)=>{let a=uc(`x`,r.length),o=`(${ec} ${Q(n,a)} ${r[i]} x)`,s=a.map((e,t)=>t===i?`x`:e);return $(e,[...t,i+1],Z([...a,`x`],`(= ${o} ${Q(n,s)})`,[[o]]))},Dc=(e,t)=>{let n=U(`Tuple_${e}`),r=uc(`x`,e),i=Q(n,r),a=Tc(e);return[$(`TupIsafcn`,[e],Z(r,`(${Qs} ${i})`,[[i]])),...e===0?[]:[$(`TupDomDef`,[e],Z(r,`(= (${J} ${i}) ${Q(U(`SetEnum_${e}`),a)})`,[[i]])),$(`TupAppDef`,[e],Z(r,fc(a.map((e,t)=>`(= (${q} ${i} ${e}) ${r[t]})`)),[[i]]))],$(`SeqTupTyping`,[e],Z([`a`,...r],e===0?`(${W} ${i} (${Y} a))`:`(=> ${fc(r.map(e=>`(${W} ${e} a)`))} (${W} ${i} (${Y} a)))`,[[...r.map(e=>`(${W} ${e} a)`),i]])),$(`SeqTupLen`,[e],Z(r,`(= (${X} ${i}) (${G} ${e}))`,[[i]])),...t?a.map((t,r)=>Ec(`TupExcept`,[e],n,a,r)):[]]},Oc=(e,t)=>{let n=U(`Record_${e.join(`_`)}`),r=e.map(e=>U(`StrLit_${e}`)),i=uc(`x`,e.length),a=Q(n,i);return[$(`RecIsafcn`,[e],Z(i,`(${Qs} ${a})`,[[a]])),$(`RecDomDef`,[e],Z(i,`(= (${J} ${a}) ${Q(U(`SetEnum_${e.length}`),r)})`,[[a]])),$(`RecAppDef`,[e],Z(i,fc(r.map((e,t)=>`(= (${q} ${a} ${e}) ${i[t]})`)),[[a]])),...t?r.map((t,i)=>Ec(`RecExcept`,[e],n,r,i)):[]]},kc=(e,t,n,r,i,a)=>{let o=uc(`s`,i.length),s=uc(`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],`(=> ${fc(s.map((e,t)=>`(${W} ${e} ${o[t]})`))} (${W} ${l} ${c}))`,[[l,c]])),$(`${e}Elim`,t,Z([...o,a],`(=> (${W} ${a} ${c}) ${fc([`(= ${a} ${Q(r,u)})`,...u.map((e,t)=>`(${W} ${e} ${o[t]})`)])})`,[[`(${W} ${a} ${c})`]]))]},Ac=[`Mem`,`Seq`,`Len`,`FunApp`,`NatSet`,`Cast_Int`,`Proj_Int`],jc=(e,t)=>{let n=(e,t,n)=>({declaration:e,deps:t,axioms:n}),r=Ms(`TLA__${e}`),a=(e,t,i,a=`Idv`)=>n(mc(r,e,a),t,i),o=/^SetEnum_(\d+)$/.exec(e);if(o)return a(Number(o[1]),[`Mem`],wc(Number(o[1])));let s=/^SetOf_(\d+)$/.exec(e);if(s){let e=Number(s[1]);return n(void 0,[`Mem`,`IsSetOf`],[$(`SetOfIntro`,[e],void 0),$(`SetOfElim`,[e],void 0),$(`AssertIsSetOf`,[e],void 0),$(`CompareSetOfTrigger`,[],Z([`a`,`b`],`(${Ls} a b)`,[[`(${nc} a)`,`(${nc} b)`]]))])}if(e.startsWith(`StrLit_`)){let n=e.slice(7),i=t.strings.map(e=>$(`StrLitDistinct`,[n,e],`(distinct ${r} ${U(`StrLit_${e}`)})`));return t.strings.push(n),a(0,[`Mem`,`StrSet`],[$(`StrLitIsstr`,[n],`(${W} ${r} ${qs})`),...i])}let c=/^Tuple_(\d+)$/.exec(e);if(c){let e=Number(c[1]);return t.tuples.push(e),a(e,e===0?[`FunIsafcn`,`Cast_Int`,`Seq`,`Len`]:[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${e}`,`Cast_Int`,`Mem`,`Seq`,`Len`],Dc(e,t.isExcept))}let l=/^Product_(\d+)$/.exec(e);if(l){let e=Number(l[1]);return a(e,[`Mem`,`Tuple_${e}`,`FunApp`,`Cast_Int`,`Proj_Int`],kc(`Product`,[e],r,U(`Tuple_${e}`),Tc(e),`t`))}let u=t.recordFields.get(e);if(u&&e.startsWith(`Record_`))return t.records.push(u),a(u.length,[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${u.length}`,...u.map(e=>`StrLit_${e}`)],Oc(u,t.isExcept));if(u&&e.startsWith(`RecordSet_`)){let e=`Record_${u.join(`_`)}`;return a(u.length,[`Mem`,e,`FunApp`,...u.map(e=>`StrLit_${e}`)],kc(`RecSet`,[u],r,U(e),u.map(e=>U(`StrLit_${e}`)),`r`))}let d=t.anonymous.get(e);if(d!==void 0)return a(d,[],[]);let f=Cc[e];if(f)return a(e===`IntUminus`?1:2,[`Cast_Int`],[f()],e===`IntLteq`?`Bool`:`Idv`);switch(e){case`IntExp`:return a(2,[`Mem`,`IntSet`,`Cast_Int`,`TIntLteq`,`TIntLit_0`,`TIntLit_1`],[$(`IntExpTyping`,[],`(forall ((x Idv) (y Idv)) (! (=> (and (${W} x ${Js}) (${W} y ${Js}) (or (distinct x (${G} 0)) (${Xs} (${G} 1) y))) (${W} (${r} x y) ${Js})) :pattern ((${r} x y))))`)]);case`SelectSeq`:return n(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 n(void 0,[],[$(`ChooseDef`,[],void 0)]);case`Mem`:return a(2,[`SetExtTrigger`],[$(`SetExt`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (= (${W} z x) (${W} z y))) (= x y)) :pattern ((${Ls} x y))))`)],`Bool`);case`SubsetEq`:return a(2,[`Mem`],[$(`SubsetEqIntro`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${W} z x) (${W} z y))) (${Rs} x y)) :pattern ((${Rs} x y))))`),$(`SubsetEqElim`,[],`(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${Rs} x y) (${W} z x)) (${W} z y)) :pattern ((${Rs} x y) (${W} z x))))`)],`Bool`);case`Union`:return a(1,[`Mem`],[$(`UnionIntro`,[],`(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${W} y a) (${W} x y)) (${W} x (${Us} a))) :pattern ((${W} y a) (${W} x (${Us} a))) :pattern ((${W} x y) (${W} x (${Us} a))) :pattern ((${W} y a) (${W} x y) (${Us} a))))`),$(`UnionElim`,[],`(forall ((a Idv) (x Idv)) (! (=> (${W} x (${Us} a)) (exists ((y Idv)) (and (${W} y a) (${W} x y)))) :pattern ((${W} x (${Us} a)))))`)]);case`Subset`:return a(1,[`Mem`,`SubsetEq`],[$(`SubsetDefAlt`,[],`(forall ((a Idv) (x Idv)) (! (= (${W} x (${Hs} a)) (${Rs} x a)) :pattern ((${W} x (${Hs} a))) :pattern ((${Rs} x a) (${Hs} a))))`)]);case`Cup`:case`Cap`:case`SetMinus`:{let t=e===`Cup`?`(or (MEM x a) (MEM x b))`:e===`Cap`?`(and (MEM x a) (MEM x b))`:`(and (MEM x a) (not (MEM x b)))`,n=$(`${e}Def`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${W} x (${r} a b)) ${t.replaceAll(`MEM`,W)}) :pattern ((${W} x (${r} a b))) :pattern ((${W} x a) (${r} a b)) :pattern ((${W} x b) (${r} a b))))`);return e===`Cap`?a(2,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[n,$(`DisjointTrigger`,[],`(forall ((x Idv) (y Idv)) (! (${Ls} (${Bs} x y) ${U(`SetEnum_0`)}) :pattern ((${Bs} x y))))`)]):a(2,[`Mem`],[n])}case`SetSt`:return n(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)) (! (= (${W} x ${Ys}) (and (${W} x ${Js}) (${Xs} (${G} 0) x))) :pattern ((${W} x ${Ys}))))`)]);case`IntRange`:return a(2,[`Mem`,`IntSet`,`IntLteq`],[$(`IntRangeDef`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${W} x (${Zs} a b)) (and (${W} x ${Js}) (${Xs} a x) (${Xs} x b))) :pattern ((${W} x (${Zs} a b)))))`)]);case`FunIsafcn`:return a(1,[`Mem`,`FunDom`,`FunFcn`,`FunApp`],[$(`FunExt`,[],`(forall ((f Idv) (g Idv)) (! (=> (and (${Qs} f) (${Qs} g) (= (${J} f) (${J} g)) (forall ((x Idv)) (=> (${W} x (${J} f)) (= (${q} f x) (${q} g x))))) (= f g)) :pattern ((${Qs} f) (${Qs} g))))`)],`Bool`);case`FunSet`:return t.isFunSet=!0,a(2,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunSetIntro`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (and (${Qs} f) (= (${J} f) a) (forall ((x Idv)) (=> (${W} x a) (${W} (${q} f x) b)))) (${W} f (${$s} a b))) :pattern ((${W} f (${$s} a b)))))`),$(`FunSetElim1`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (${W} f (${$s} a b)) (and (${Qs} f) (= (${J} f) a))) :pattern ((${W} f (${$s} a b)))))`),$(`FunSetElim2`,[],`(forall ((a Idv) (b Idv) (f Idv) (x Idv)) (! (=> (and (${W} f (${$s} a b)) (${W} x a)) (${W} (${q} f x) b)) :pattern ((${W} f (${$s} a b)) (${W} x a)) :pattern ((${W} f (${$s} a b)) (${q} f x))))`),...t.isFunConstr?[$(`FunTyping`,[],void 0)]:[]]);case`FunFcn`:return t.isFunConstr=!0,n(void 0,[`FunIsafcn`],[$(`FunConstrIsafcn`,[],void 0),...t.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`:{t.isExcept=!0;let e=`(${ec} f x y)`;return a(3,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunExceptIsafcn`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (${Qs} ${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)) (! (=> (${W} x (${J} f)) (= (${q} ${e} x) y)) :pattern (${e})))`),$(`FunExceptAppDef2`,[],`(forall ((f Idv) (x Idv) (y Idv) (z Idv)) (! (=> (${W} 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))))`),...t.tuples.flatMap(e=>Tc(e).map((t,n)=>Ec(`TupExcept`,[e],U(`Tuple_${e}`),Tc(e),n))),...t.records.flatMap(e=>e.map((t,n)=>Ec(`RecExcept`,[e],U(`Record_${e.join(`_`)}`),e.map(e=>U(`StrLit_${e}`)),n)))])}case`Seq`:return a(1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`Cast_Int`,`Proj_Int`],[$(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${Qs} s) (>= (${K} (${X} s)) 0) (forall ((i Idv)) (= (${W} i (${J} s)) (and (${W} i ${Js}) (<= 1 (${K} i)) (<= (${K} i) (${K} (${X} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${K} (${X} s)))) (${W} (${q} s (${G} i)) a)))) (${W} s (${Y} a))) :pattern ((${W} s (${Y} a)))))`),$(`SeqSetElim1`,[],`(forall ((a Idv) (s Idv)) (! (=> (${W} s (${Y} a)) (and (${Qs} s) (${W} (${X} s) ${Ys}) (= (${J} s) (${Zs} (${G} 1) (${X} s))))) :pattern ((${W} s (${Y} a)))))`,`SetSetElim1`),$(`SeqSetElim2`,[],`(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${W} s (${Y} a)) (<= 1 i) (<= i (${K} (${X} s)))) (${W} (${q} s (${G} i)) a)) :pattern ((${W} 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) (${Zs} (${G} 1) (${G} z)))) (= (${X} s) (${G} z))))`)]);case`BSeq`:return a(1,[],[]);case`Cat`:return a(2,Ac,[$(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${W} s (${Y} a)) (${W} t (${Y} a))) (${W} (${rc} s t) (${Y} a))) :pattern ((${W} s (${Y} a)) (${rc} s t)) :pattern ((${W} t (${Y} a)) (${rc} s t))))`),$(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${W} (${X} s) ${Ys}) (${W} (${X} t) ${Ys})) (= (${X} (${rc} s t)) (${G} (+ (${K} (${X} s)) (${K} (${X} t)))))) :pattern ((${rc} s t))))`),$(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${W} (${X} s) ${Ys}) (${W} (${X} t) ${Ys}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${rc} s t) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${rc} s t) (${G} i))) :pattern ((${rc} s t) (${q} s (${G} i)))))`),$(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${W} (${X} s) ${Ys}) (${W} (${X} t) ${Ys}) (<= i (+ (${K} (${X} s)) (${K} (${X} t)))) (< (${K} (${X} s)) i)) (= (${q} (${rc} s t) (${G} i)) (${q} t (${G} (- i (${K} (${X} s))))))) :pattern ((${q} (${rc} s t) (${G} i)))))`)]);case`Append`:return a(2,Ac,[$(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${W} s (${Y} a)) (${W} x a)) (${W} (${ic} s x) (${Y} a))) :pattern ((${W} s (${Y} a)) (${ic} s x))))`),$(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${W} (${X} s) ${Ys}) (= (${X} (${ic} s x)) (${G} (+ (${K} (${X} s)) 1)))) :pattern ((${ic} s x))))`),$(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${W} (${X} s) ${Ys}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${ic} s x) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${ic} s x) (${G} i))) :pattern ((${ic} s x) (${q} s (${G} i)))))`),$(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${W} (${X} s) ${Ys}) (= (${q} (${ic} s x) (${G} (+ (${K} (${X} s)) 1))) x)) :pattern ((${ic} s x))))`)]);case`Head`:return a(1,[`FunApp`,`Cast_Int`],[$(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${ac} s) (${q} s (${G} 1))) :pattern ((${ac} s))))`)]);case`Tail`:return a(1,Ac,[$(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${W} s (${Y} a)) (distinct (${K} (${X} s)) 0)) (${W} (${oc} s) (${Y} a))) :pattern ((${W} s (${Y} a)) (${oc} s))))`),$(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${W} (${X} s) ${Ys}) (distinct (${K} (${X} s)) 0)) (= (${X} (${oc} s)) (${G} (- (${K} (${X} s)) 1)))) :pattern ((${oc} s))))`),$(`SeqTailApp`,[],`(forall ((s Idv) (i Int)) (! (=> (and (${W} (${X} s) ${Ys}) (distinct (${K} (${X} s)) 0) (<= 1 i) (<= i (- (${K} (${X} s)) 1))) (= (${q} (${oc} s) (${G} i)) (${q} s (${G} (+ i 1))))) :pattern ((${q} (${oc} s) (${G} i)))))`)]);case`SubSeq`:{let e=`(${sc} 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 (${W} s (${Y} a)) (<= 1 x) (<= y (${K} (${X} s))))) (${W} ${e} (${Y} a))) :pattern ((${W} 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 n(mc(r,1,`Idv`,`Int`),[`Mem`,`IntSet`,`Proj_Int`],[$(`CastInjAlt`,[`Int`],`(forall ((x Int)) (! (= x (${K} (${G} x))) :pattern ((${G} x))))`),$(`TypeGuardIntro`,[`Int`],`(forall ((z Int)) (! (${W} (${G} z) ${Js}) :pattern ((${G} z))))`),$(`TypeGuardElim`,[`Int`],`(forall ((x Idv)) (! (=> (${W} x ${Js}) (= x (${G} (${K} x)))) :pattern ((${W} x ${Js}))))`)]);case`Cast_Bool`:return n(mc(r,1,`Idv`,`Bool`),[`Mem`,`BoolSet`,`Tt_Idv`],[$(`CastInjAlt`,[`Bool`],`(and (= (${Gs} true) ${Ws}) (distinct (${Gs} false) ${Ws}))`),$(`TypeGuardIntro`,[`Bool`],`(forall ((z Bool)) (! (${W} (${Gs} z) ${Ks}) :pattern ((${Gs} z))))`),$(`TypeGuardElim`,[`Bool`],`(forall ((x Idv)) (! (=> (${W} x ${Ks}) (or (= x (${Gs} true)) (= x (${Gs} false)))) :pattern ((${W} x ${Ks}))))`)]);case`Proj_Int`:return n(mc(r,1,`Int`),[],[]);case`TrigEq_Set$Idv$`:return a(2,[`SetExtTrigger`],[$(`ExtTrigEqDef`,[`Set$Idv$`],`(forall ((x Idv) (y Idv)) (! (= (${tc} x y) (= x y)) :pattern ((${tc} x y))))`),$(`ExtTrigEqTrigger`,[`Idv`],`(forall ((x Idv) (y Idv)) (! (${Ls} x y) :pattern ((${tc} x y))))`)],`Bool`);case`SetExtTrigger`:case`IsSetOf`:return a(e===`IsSetOf`?1:2,[],[],`Bool`);case`BoolSet`:case`StrSet`:case`IntSet`:case`Tt_Idv`:return a(0,[],[]);case`TIntLteq`:return n(void 0,[`IntLteq`],[Cc.IntLteq()]);default:if(e.startsWith(`TIntLit_`))return n(void 0,[],[]);throw new i(`the symbol ${e}`)}},Mc=(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(ks)[0];if(t.delete(e),a.has(e))continue;let n=jc(e,i);a.set(e,n),n.deps.forEach(e=>t.add(e)),n.axioms.forEach(e=>o.set(yc(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=Is(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}},Nc=(e,t)=>t===0?e:`${e}_${t}`,Pc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Set;return{names:t,adjoin:n=>{let r=Ms(n),i=(e.get(r)??-1)+1,a=Array.from({length:t.size+1},(e,t)=>i+t).find(e=>!t.has(Nc(r,e)))??i;return{base:r,salt:a,name:Nc(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)}}}},Fc=e=>{let t=Pc();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(``)}}},Ic=(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)),Lc=e=>e.length===1?e[0]:O(`Conj`,[e[0],Lc(e.slice(1))],e[0]),Rc=(e,t,n)=>e.kind!==`Record`||t.kind!==`Record`||!Ic(e,t)?O(`Eq`,[e,t],n):Lc(e.fields.map(e=>Rc(e.value,t.fields.find(t=>t.name===e.name)?.value??e.value,n))),zc=e=>{let t=Ue(e,zc);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`?D(Rc(t.args[0],t.args[1],t),t):t},Bc=e=>e.kind===`Record`||e.kind===`Rect`?{...e,fields:e.fields.toSorted((e,t)=>ks(e.name,t.name))}:Ue(e,Bc),Vc=(e,t)=>`${e}#${t}`,Hc=e=>Number(e.slice(e.lastIndexOf(`#`)+1)),Uc=`?unprimable`,Wc=(e,t)=>{let n={depth:0};for(let r of Array.from({length:e.length-t},(e,n)=>t+n))if(e[r]===`(`&&n.depth++,e[r]===`)`&&n.depth--,n.depth===0)return r;return e.length},Gc=e=>{let t=e.indexOf(`(${Uc} `);if(t===-1)return e;let n=Wc(e,t);return e.slice(0,t)+Gc(e.slice(t+11+2,n))+Gc(e.slice(n+1))},Kc=(e,t)=>/\((forall|exists|ite) /.test(e)?void 0:e.replace(/[^\s()]+#(\d+)/g,(e,n)=>Number(n)<t?`#`:`#${Number(n)-t}`),qc=()=>{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=Ms(`${l}_omitted_${e.size}`);return e.set(t,{symbol:t,kind:i,visit:Gc(a),getLines:()=>[]}),t}let u=Kc(`${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=Ms(f),m={symbol:p,kind:i,visit:Gc(a),getLines:e=>[mc(p,c),...s(p,e).map(e=>`(assert (! ${Gc(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)}},Jc=`?trigger`,Yc=/* @__PURE__ */ new Set([Us,Hs,zs,Bs,Vs,Zs,$s,Y]),Xc=e=>{let t=/^\(?([^\s()]+)/.exec(e)?.[1]??``;return Yc.has(t)||/^smt__TLA____(SetEnum__\d+|SetSt__flatnd__\d+|SetOf__\d+__flatnd__\d+|Product__\d+|RecordSet__)/.test(t)},Zc=(e,t)=>{let n=e.indexOf(`(${Jc} `);if(n===-1)return e;let r=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+1;return e.length},i=n+8+2,a=r(i),o=r(a+1),s=t?e.slice(i,a):e.slice(a+1,o);return e.slice(0,n)+s+Zc(e.slice(o+1),t)},Qc=(e,t,n,r)=>{let i=`(${tc} ${e} ${t})`,a=r?`(distinct ${e} ${t})`:`(= ${e} ${t})`;if(!Xc(e)&&!Xc(t))return a;let o=r?`(not ${i})`:i;return n===(r?`Positive`:`Negative`)?`(${Jc} ${o} ${a})`:o},$c=(e,t,n,r)=>{let i=Q(e,[`a`,...t]);return[$(`SetStDef`,[],Z([...t,`a`,`x`],`(= (${W} x ${i}) (and (${W} x a) ${hc(n,r,`x`)}))`,[[`(${W} x ${i})`],[`(${W} x a)`,i]]))]},el=(e,t,n,r)=>{let i=r.length,a=uc(`a`,i),o=uc(`y`,i),s=r.reduce((e,t,n)=>hc(e,t,o[n]),n),c=Q(e,[...a,...t]),l=o.map((e,t)=>`(${W} ${e} ${a[t]})`),u=o.map(e=>`(${e} Idv)`).join(` `),d=i===1?[`a`]:a;return[$(`SetOfIntro`,[i],Z([...t,...a,...o],`(=> ${fc(l)} (${W} ${s} ${c}))`,[[s,c],[c,...l]])),$(`SetOfElim`,[i],Z([...t,...a,`x`],`(=> (${W} x ${c}) (exists (${u}) ${fc([...l,`(= x ${s})`])}))`,[[`(${W} x ${c})`]])),$(`AssertIsSetOf`,[i],Z([...t,...d],`(${nc} ${Q(e,[...d,...t])})`,[[Q(e,[...d,...t])]]))]},tl=(e,t,n,r,i)=>{let a=Q(e,[`a`,...t]),o=hc(n,r,`x`),s=i.has(yc($(`FunTyping`,[],void 0)))?[$(`FunTyping`,[],Z([...t,`a`,`b`],`(=> (forall ((x Idv)) (=> (${W} x a) (${W} ${o} b))) (${W} ${a} (${$s} a b)))`,[[a,`(${$s} a b)`]]))]:[];return[$(`FunConstrIsafcn`,[],Z([...t,`a`],`(${Qs} ${a})`,[[a]])),$(`FunDomDef`,[],Z([...t,`a`],`(= (${J} ${a}) a)`,[[a]])),$(`FunAppDef`,[],Z([...t,`a`,`x`],`(=> (${W} x a) (= (${q} ${a} x) ${o}))`,[[`(${q} ${a} x)`],[`(${W} x a)`,a]])),...s]},nl=(e,t,n,r)=>[$(`ChooseDef`,[],Z([...t,`x`],`(=> ${hc(n,r,`x`)} ${hc(n,r,Q(e,t))})`))],rl=(e,t,n,r)=>{let i=n=>Q(e,[n,...t]),a=e=>hc(n,r,e),o=i(`(${ic} s x)`);return[$(`SeqSelectseqTyping`,[],Z([...t,`a`,`s`],`(=> (${W} s (${Y} a)) (${W} ${i(`s`)} (${Y} a)))`,[[`(${W} s (${Y} a))`,i(`s`)]])),$(`SeqSelectseqLen`,[],Z([...t,`s`],`(=> (${W} (${X} s) ${Ys}) (<= (${K} (${X} ${i(`s`)})) (${K} (${X} s))))`,[[i(`s`)]])),$(`SeqSelectseqNil`,[],Z(t,`(= ${i(cc)} ${cc})`)),$(`SeqSelectseqApp`,[],Z([...t,`s`,`x`],`(=> (${W} x (${J} ${i(`s`)})) ${a(`(${q} ${i(`s`)} x)`)})`,[[`(${q} ${i(`s`)} x)`]])),$(`SeqSelectseqAppend`,[],Z([...t,`s`,`x`],`(and (=> ${a(`x`)} (= ${o} (${ic} ${i(`s`)} x))) (=> (not ${a(`x`)}) (= ${o} ${i(`s`)})))`,[[o]]))]},il=e=>{let t=qc(),n=t.flatten,r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=Pc(),s=/* @__PURE__ */ new Map,c=e=>e.isBool?e.text:`(= ${Zc(e.text,!0)} ${Ws})`,l=e=>e.isBool?`(${Gs} ${Zc(e.text,!0)})`:e.text,u=e=>({isBool:!0,text:e}),d=e=>({isBool:!1,text:e}),f=(e,t)=>{let n=Array.from({length:t-1}).reduce(e=>e?.rest,e);if(!n)throw new i(`a reference outside the obligation`);return n.binding},p=(e,t)=>({binding:t,rest:e}),m=(e,t)=>[...new Set(e.match(/[^\s()]+#\d+/g))].filter(e=>Hc(e)<t).toSorted((e,t)=>Hc(e)-Hc(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(w(e,t,g(n))),y=(e,t,n)=>c(w(e,t,n)),b=(e,t,n)=>e.reduce((e,t)=>t.domain.kind===`Ditto`?[...e,e.at(-1)]:t.domain.kind===`NoDomain`?[...e,void 0]:[...e,t.domain.expression],[]).map(e=>e===void 0?void 0:v(e,t,n)),ee=(e,t,n,r)=>b(e,t,n).map(e=>{if(e===void 0)throw new i(`${r} without a domain`);return e}),x=(e,t,n)=>{let r=e.map((e,t)=>Vc(e,n.depth+t));return{variables:r,env:r.reduce((e,t)=>p(e,{kind:`constant`,symbol:t}),t),mode:{...n,depth:n.depth+e.length}}},te=e=>e.map(e=>`(${e} Idv)`).join(` `),S=(e,t,n)=>{let r=b(e.bounds,t,n),i=x(e.bounds.map(e=>e.name),t,n),a=y(e.body,i.env,i.mode),o=i.variables.flatMap((e,t)=>r[t]===void 0?[]:[`(${W} ${e} ${r[t]})`]);return e.quantifier===`Forall`?`(forall (${te(i.variables)}) ${o.length===0?a:`(=> ${fc(o)} ${a})`})`:`(exists (${te(i.variables)}) ${fc([...o,a])})`},ne=(e,t,r)=>{let i=v(e.domain,t,r),a=x([e.name],t,g(r)),o=y(e.body,a.env,a.mode),s=m(o,r.depth),c=n(`SetSt`,o,r,e=>$c(e,s,o,a.variables[0]),s.length+1);return d(Q(c,[i,...s]))},re=(e,t,r)=>{let i=ee(e.bounds,t,r,`a set of values`),a=x(e.bounds.map(e=>e.name),t,g(r)),o=v(e.element,a.env,a.mode),s=m(o,r.depth),c=i.length,l=n(`SetOf_${c}`,o,r,e=>el(e,s,o,a.variables),c+s.length);return d(Q(l,[...i,...s]))},ie=(e,t,r)=>{let i=ee(e.bounds,t,r,`a function`),a=i.length===1?i[0]:Q(U(`Product_${i.length}`),i),o=Vc(i.length===1?e.bounds[0].name:`x`,r.depth),s={...g(r),depth:r.depth+1},c=i.length===1?p(t,{kind:`constant`,symbol:o}):Tc(i.length).reduce((e,t)=>p(e,{kind:`constant`,symbol:`(${q} ${o} ${t})`}),t),l=v(e.body,c,s),u=m(l,r.depth),f=n(`FunFcn`,l,r,(e,t)=>tl(e,u,l,o,t),u.length+1);return d(Q(f,[a,...u]))},ae=(e,t,r)=>{let i=x([e.name],t,g(r)),a=i.variables[0],o=e.domain&&`(${W} ${a} ${v(e.domain,t,r)})`,s=y(e.body,i.env,i.mode),c=o===void 0?s:fc([o,s]),l=m(c,r.depth),u=n(`Choose`,c,r,e=>nl(e,l,c,a),l.length);return d(Q(u,l))},oe=(e,t,n,r,i)=>{let a=v(e,n,r),o=v(t,n,r);return Qc(a,o,r.polarity,i)},se=(e,t,n)=>{let r=e.kind===`Lambda`&&e.params.length===1?e:void 0,i=x([r?.params[0].name??`x1`],t,g(n));return{body:y(r?.body??{kind:`Apply`,operator:N(1,e),args:[{kind:`Ix`,index:1}]},i.env,i.mode),variable:i.variables[0]}},ce=(e,t,r,a)=>{let o=()=>t.map(e=>v(e,r,a));switch(e){case`Conj`:return u(fc(t.map(e=>y(e,r,a))));case`Disj`:return u(pc(t.map(e=>y(e,r,a))));case`Implies`:return u(`(=> ${y(t[0],r,_(a))} ${y(t[1],r,a)})`);case`Equiv`:return u(`(= ${t.map(e=>y(e,r,g(a))).join(` `)})`);case`Neg`:return u(`(not ${y(t[0],r,_(a))})`);case`Eq`:return u(oe(t[0],t[1],r,a,!1));case`Neq`:return u(oe(t[0],t[1],r,a,!0));case`Mem`:return u(Q(W,o()));case`Notmem`:return u(`(not ${Q(W,o())})`);case`Subseteq`:return u(Q(Rs,o()));case`Lteq`:return u(Q(Xs,o()));case`Gteq`:return u(Q(Xs,o().toReversed()));case`Lt`:case`Gt`:{let t=()=>e===`Lt`?o():o().toReversed();return u(`(and ${Q(Xs,t())} (distinct ${t().join(` `)}))`)}case`SelectSeq`:{let e=se(t[1],r,a),i=m(e.body,a.depth),o=n(`SelectSeq`,e.body,a,t=>rl(t,i,e.body,e.variable),i.length+1);return d(Q(o,[v(t[0],r,a),...i]))}case`Unprimable`:{let e=w(t[0],r,g(a));return{...e,text:`(${Uc} ${e.text})`}}default:{let t=lc[e];if(t===void 0)throw new i(`the operator ${e}`);return d(Q(t,o()))}}},le=(e,t,r,a)=>{switch(e.kind){case`constant`:if(t.length>0)throw new i(`an applied constant`);return d(e.symbol);case`variable`:if(t.length>0)throw new i(`an applied variable`);return d(e.symbol);case`operator`:if(t.length!==e.arity)throw new i(`an operator applied to the wrong number of arguments`);return d(Q(e.symbol,t.map(e=>v(e,r,a))));case`secondOrder`:{if(t.length!==e.shapes.length)throw new i(`an operator applied to the wrong number of arguments`);let o=t.map((t,n)=>{if(e.shapes[n]===0)return{isFirstOrder:!0,text:v(t,r,a)};if(t.kind===`Ix`){let e=f(r,t.index);if(e.kind!==`operator`)throw new i(`an operator argument that isn't a LAMBDA`);return{isFirstOrder:!1,text:e.symbol}}if(t.kind!==`Lambda`)throw new i(`an operator argument that isn't a LAMBDA`);let o=x(t.params.map(e=>e.name),r,g(a));return{isFirstOrder:!1,text:v(t.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=n(``,c.join(` `),a,()=>[],s.length+l.length,e.name);return d(Q(u,[...s,...l]))}case`unsupported`:throw new i(e.reason)}},ue=(e,t)=>{if(!e)throw new i(`a primed declaration that isn't a variable`);let n=e.binding;return n.kind===`variable`&&n.name===t?n.primed:ue(e.rest,t)},de=(e,t,n,i)=>{if(t.length===0&&e.endsWith(`#prime`))return d(ue(n,e.slice(0,-6)));let a=t.length===0?`Anon_OPAQUE_${e}`:`Anon_${e}`;return r.set(a,t.length),d(Q(U(a),t.map(e=>v(e,n,i))))},fe=(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`?U(`StrLit_${o.field}`):v(o.expression,t,n),c=s(),l=i(`(${q} ${e} ${a.length>1?s():c})`,a.slice(1));return`(${ec} ${e} ${c} ${l})`};return i(e,r.trail)},v(e.function,t,n)),pe=()=>{e.caseErrors++;let t=`Anon_incomplete_case_error_${e.caseErrors}`;return r.set(t,0),U(t)},C=(e,t,n)=>{let r=e.arms.map(e=>w(e.body,t,n)),i=e.other?w(e.other,t,n):d(pe()),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))}},me=(e,t,n)=>{let r=e.context.reduce((e,t)=>{switch(t.kind){case`Fresh`:{if(t.shape>0){if(!e.mode.isOmitted)throw new i(`a second-order ASSUME`);let n=Vc(t.name,e.mode.depth);return{env:p(e.env,{kind:`operator`,symbol:n,arity:t.shape}),mode:{...e.mode,depth:e.mode.depth+1},wrappers:[...e.wrappers,e=>`(forall ((${n} Idv)) ${e})`]}}if(t.level!==`Constant`)throw new i(`a NEW declaration that isn't constant`);let n=t.domain&&v(t.domain,e.env,e.mode),r=x([t.name],e.env,e.mode),a=r.variables[0],o=n&&`(${W} ${a} ${n})`;return{env:r.env,mode:r.mode,wrappers:[...e.wrappers,e=>`(forall ((${a} Idv)) ${o?`(=> ${o} ${e})`:e})`]}}case`Fact`:{let n=t.visibility===`Visible`?y(t.expression,e.env,_(e.mode)):void 0;return{env:p(e.env,{kind:`unsupported`,reason:`a reference to a fact`}),mode:e.mode,wrappers:n?[...e.wrappers,e=>`(=> ${n} ${e})`]:e.wrappers}}default:throw new i(`a ${t.kind} in a nested ASSUME`)}},{env:t,mode:n,wrappers:[]});return r.wrappers.reduceRight((e,t)=>t(e),y(e.active,r.env,r.mode))},w=(e,t,n)=>{switch(e.kind){case`Ix`:return le(f(t,e.index),[],t,n);case`Internal`:switch(e.builtin){case`TRUE`:return u(`true`);case`FALSE`:return u(`false`);case`BOOLEAN`:return d(Ks);case`STRING`:return d(qs);case`Nat`:return d(Ys);case`Int`:return d(Js);default:throw new i(`the operator ${e.builtin}`)}case`Apply`:{let r=e.operator;if(r.kind===`Internal`)return ce(r.builtin,e.args,t,n);if(r.kind===`Ix`)return le(f(t,r.index),e.args,t,n);if(r.kind===`Opaque`)return de(r.name,e.args,t,n);if(r.kind===`Lambda`)return w({...Ee(r,e.args)},t,n);throw new i(`an application of ${r.kind}`)}case`Sequent`:return u(me(e.sequent,t,n));case`With`:case`Parens`:return w(e.expression,t,n);case`If`:{let r=y(e.condition,t,n),i=w(e.consequent,t,n),a=w(e.alternative,t,n);if(i.integer!==void 0&&a.integer!==void 0){let e=`(ite ${Zc(r,!0)} ${i.integer} ${a.integer})`;return{isBool:!1,text:`(${G} ${e})`,integer:e}}return i.isBool&&a.isBool?u(`(ite ${r} ${i.text} ${a.text})`):d(`(ite ${r} ${l(i)} ${l(a)})`)}case`List`:{let r=e.items.map(e=>y(e,t,n));return u(e.bullet===`Or`?pc(r):fc(r))}case`Opaque`:return de(e.name,[],t,n);case`Quant`:return u(S(e,t,n));case`Choose`:return ae(e,t,n);case`SetSt`:return ne(e,t,n);case`SetOf`:return re(e,t,n);case`SetEnum`:return d(Q(U(`SetEnum_${e.elements.length}`),e.elements.map(e=>v(e,t,n))));case`Product`:return d(Q(U(`Product_${e.factors.length}`),e.factors.map(e=>v(e,t,n))));case`Tuple`:return d(Q(U(`Tuple_${e.elements.length}`),e.elements.map(e=>v(e,t,n))));case`Fcn`:return ie(e,t,n);case`FcnApp`:{let r=v(e.function,t,n),i=e.args.map(e=>v(e,t,n)),a=i.length===1?i[0]:Q(U(`Tuple_${i.length}`),i);return d(`(${q} ${r} ${a})`)}case`Arrow`:return d(Q($s,[v(e.domain,t,n),v(e.range,t,n)]));case`Record`:case`Rect`:{let r=e.fields,i=r.map(e=>e.name);a.set(`Record_${i.join(`_`)}`,i),a.set(`RecordSet_${i.join(`_`)}`,i);let o=`${e.kind===`Record`?`Record`:`RecordSet`}_${i.join(`_`)}`;return d(Q(U(o),r.map(e=>v(e.value,t,n))))}case`Except`:return d(fe(e,t,n));case`Dot`:return d(`(${q} ${v(e.expression,t,n)} ${U(`StrLit_${e.field}`)})`);case`Case`:return C(e,t,n);case`String`:return d(U(`StrLit_${e.value}`));case`Num`:if(e.fraction!==``)throw new i(`a real number`);return{isBool:!1,text:`(${G} ${BigInt(e.integer)})`,integer:String(BigInt(e.integer))};case`At`:if(n.at===void 0)throw new i(`@ outside EXCEPT`);return d(n.at);case`Tquant`:case`Tsub`:case`Fair`:throw new i(`a temporal formula`);default:throw new i(`the expression ${e.kind}`)}};return{encodeIdv:v,encodeBool:y,push:p,getEntries:e=>[...t.takeIntroduced(),Gc(Zc(e,!1))],getUniqueName:h,flattened:t.flattened,anonymous:r,recordFields:a,declared:s}},al={polarity:`Negative`,at:void 0,depth:0},ol=e=>e.definition.kind===`Bpragma`||e.definition.kind===`Operator`&&e.visibility===`Visible`,sl=e=>e.kind===`Sequent`&&e.sequent.context.some(e=>e.kind===`Fresh`&&e.shape>0),cl=(e,t)=>e.reduce((e,n)=>{let r=(r,i=[])=>({env:t.push(e.env,r),scope:k(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=mc(i,n.shape),s=n.domain;if(!s||n.domainVisibility===`Hidden`)return r(a,[o]);let c=`(assert (${W} ${i} ${t.encodeIdv(s,e.env,al)}))`;return r(a,[o,...t.getEntries(c)])}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},[mc(e,0),mc(i,0)])}case`Defn`:{let e=n.definition;if(ol(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},[mc(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},[mc(o,a.length)])}case`Fact`:{let i={kind:`unsupported`,reason:`a reference to a fact`};if(n.visibility===`Hidden`)return r(i);if(!sl(n.expression)){let a=`(assert ${t.encodeBool(n.expression,e.env,al)})`;return r(i,t.getEntries(a))}let a=`(assert ${t.encodeBool(n.expression,e.env,{...al,isOmitted:!0})})`;return r(i,t.getEntries(a).map(e=>typeof e==`string`?{omitted:e}:e))}}},{env:void 0,scope:void 0,entries:[]}),ll=(e,t)=>{let n=Bc(zc({kind:`Sequent`,sequent:e})),r=n.kind===`Sequent`?n.sequent:e,i=il(t),a=cl(r.context,i),o=sl(r.active)?[]:i.getEntries(`(assert (! (not ${i.encodeBool(r.active,a.env,{...al,polarity:`Positive`})}) :named |Goal|))`),s=[...a.entries,...o],c=Fc(i.declared),l=Mc(s,i.flattened,i.anonymous,i.recordFields),u=[...l.symbols].toSorted((e,t)=>ks(e[0],t[0])).flatMap(e=>e[1].declaration===void 0?[]:[e[1].declaration]),d=[...l.axioms.values()].toSorted(xc).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`)&&!ol(e))?[`(declare-sort Idv 0)`]:[],...p].map(c.resolve).concat(`(check-sat)`,`(exit)`).join(`
32
+ `)},ul=R(`@ `),dl={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`},fl={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]},pl={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},ml=e=>{throw new i(e)},hl=e=>{let t=Number.parseInt(e,10);return`${`(TLA.fapply TLA.Succ `.repeat(t)}0${`)`.repeat(t)}`},gl=(e,t)=>{let n=sn(),a=e=>ln(n,Sa(e)),o=()=>ln(n,``),c=e=>z(e,g,ul),l=(e,t)=>R(`(%s %a)`,e,c(t)),u=(e,t,r,i)=>{let o=a(e),s=R(`%a((%s) %a)%s`,t,o,g(r),i);return un(n,1),s},d=(e,t)=>{let n=dl[e];if(n!==void 0&&t.length===0)return L(n);let i=fl[e];if(i&&i[1]===t.length)return l(i[0],t);let[a,o]=t;if(t.length===2)switch(e){case`Neq`:return R(`(-. %a)`,l(`=`,t));case`Notmem`:return R(`(-. %a)`,l(`TLA.in`,t));case`Minus`:return l(`arith.add`,[a,{kind:`Apply`,operator:{kind:`Internal`,builtin:`Uminus`,location:o.location},args:[o],location:o.location}]);case`Gteq`:return l(`arith.le`,[o,a]);case`Gt`:return l(`arith.lt`,[o,a])}if(e===`Unprimable`&&t.length===1)return g(a);if((e===`Prime`||e===`StrongPrime`||e===`UNCHANGED`)&&t.length===1)throw new r;let c=pl[e];throw c&&c[1]===t.length?new s(`Unsupported operator \`${c[0]}\`.\n`):new s(`Backend.Zenon.fmt_apply`)},f=(e,t)=>{switch(e.kind){case`Ix`:{let i=cn(n,e.index);if(e.index<=0||i===void 0)throw new r;return t.length===0?L(i):l(i,t)}case`Opaque`:{let n=Sa(e.name);return t.length===0?L(n):l(n,t)}case`Internal`:return d(e.builtin,t);case`Lambda`:{let t=e.params.map(e=>R(`%s `,a(e.name))),r=R(`((%a) %a)`,t,g(e.body));return un(n,e.params.length),r}default:throw new r}},p=(e,t,n)=>{let[i,...a]=t;if(!i)return g(n);let o=a[0]?.domain.kind===`Ditto`?[{...a[0],domain:i.domain},...a.slice(1)]:a,s=o.length===0?n:{kind:`Quant`,quantifier:e,bounds:o.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:N(1,e.domain.expression)}}:e),body:n,location:n.location},c=e===`Forall`;if(i.domain.kind===`NoDomain`)return u(i.name,L(c?`(A. `:`(E. `),s,`)`);if(i.domain.kind!==`Domain`)throw new r;let l=g(i.domain.expression);return u(i.name,R(`(%s %a `,c?`TLA.bAll`:`TLA.bEx`,l),s,`)`)},m=(e,t,n,i)=>{if(t.length!==1)return ml(`${i} (multiple declared constants)`);let a=t[0];if(a.domain.kind!==`Domain`)throw new r;return u(a.name,R(`(%s %a `,e,g(a.domain.expression)),n,`)`)},h=e=>{let[t,...i]=e.context;if(!t)return g(e.active);let s=()=>h({context:i,active:e.active});if(t.kind===`Fact`){let e=t.visibility===`Visible`?g(t.expression):void 0;o();let r=e?R(`(=> %a %a)`,e,s()):s();return un(n,1),r}if(t.kind===`Defn`)throw new r;let c=t.kind===`Fresh`&&t.domain&&t.domainVisibility===`Visible`?g(t.domain):void 0,l=a(t.name),u=t.kind===`Flex`?R(`(A. ((%s) (A. ((%s') %a))))`,l,l,s()):c?R(`(TLA.bAll %a ((%s) %a))`,c,l,s()):R(`(A. ((%s) %a))`,l,s());return un(n,1),u},g=e=>{switch(e.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return f(e,[]);case`Apply`:return f(e.operator,e.args);case`Sequent`:return h(e.sequent);case`With`:case`Parens`:return g(e.expression);case`If`:return R(`(TLA.cond %a %a %a)`,g(e.condition),g(e.consequent),g(e.alternative));case`List`:if(e.bullet===`Refs`&&e.items.length===0)throw new r;return e.bullet===`Refs`&&e.items.length===1?g(e.items[0]):R(`(%s %a)`,e.bullet===`Or`?`\\/`:`/\\`,c(e.items));case`Quant`:return p(e.quantifier,e.bounds,e.body);case`Tquant`:return ml(`\\AA or \\EE`);case`Choose`:return e.domain?u(e.name,R(`(TLA.bChoice %a `,g(e.domain)),e.body,`)`):u(e.name,L(`(t. `),e.body,`)`);case`SetSt`:return u(e.name,R(`(TLA.subsetOf %a `,g(e.domain)),e.body,`)`);case`SetOf`:return m(`TLA.setOfAll`,e.bounds,e.element,`Setof`);case`Fcn`:return m(`TLA.Fcn`,e.bounds,e.body,`Fcn`);case`SetEnum`:return e.elements.length===0?L(`TLA.emptyset`):[L(`(TLA.set`),e.elements.map(e=>R(` %a`,g(e))),L(`)`)];case`FcnApp`:{let t=g(e.function);return e.args.length===1?R(`(TLA.fapply %a %a)`,t,g(e.args[0])):R(`(TLA.fapply %a (TLA.tuple %a))`,t,c(e.args))}case`Arrow`:return R(`(TLA.FuncSet %a %a)`,g(e.domain),g(e.range));case`Rect`:case`Record`:return[L(e.kind===`Rect`?`(TLA.recordset`:`(TLA.record`),e.fields.map(e=>R(` "%s" %a`,e.name,g(e.value))),L(`)`)];case`Except`:{let t=e.specs[0];if(e.specs.length!==1||t.trail.length!==1)return ml(`complex EXCEPT`);let n=t.trail[0],r=n.kind===`Dot`?L(`"${n.field}"`):g(n.expression);return R(`(TLA.except %a %a %a)`,g(e.function),r,g(t.value))}case`Dot`:return R(`(TLA.fapply %a "%s")`,g(e.expression),e.field);case`Tuple`:return R(`(TLA.tuple %a)`,c(e.elements));case`Product`:return e.factors.length===2?R(`(TLA.prod %a %a)`,g(e.factors[0]),g(e.factors[1])):R(`(TLA.Product (TLA.tuple %a))`,c(e.factors));case`Sub`:case`Tsub`:case`Fair`:return ml(e.kind);case`Case`:{let t=z(e.arms,e=>R(`%a %a`,g(e.condition),g(e.body)),ul);return e.other?R(`(TLA.CASE %a %a)@]`,t,g(e.other)):R(`(TLA.CASE %a )`,t)}case`String`:return R(`"%s"`,e.value);case`Num`:return e.fraction===``?L(hl(e.integer)):ml(`Real number constants`);case`Bang`:case`Let`:case`At`:throw new r}},_=e=>{let t=n.stack.length;try{return g(e)}catch(e){if(!(e instanceof i))throw e;return un(n,n.stack.length-t),e}},v=e=>{switch(e.kind){case`Fresh`:{let t=e.domain&&e.domainVisibility===`Visible`?g(e.domain):void 0,n=a(e.name);return t?R(`$hyp "%s_in" (TLA.in %s %a)@
33
+ `,n,n,t):[]}case`Flex`:return a(e.name),[];case`Defn`:{let t=a(e.definition.name);return e.visibility===`Visible`?R(`; usable definition %s suppressed@.`,t):[]}case`Fact`:{let t=String(n.stack.length),r=e.visibility===`Visible`?_(e.expression):void 0;return o(),r instanceof i?R(`; omitted temporal assumption : %s @.`,r.message):r?R(`$hyp "v'%s" %a@
34
+ `,t,r):[]}}},y=(()=>{try{return[t.context.map(v),R(`$goal %a`,g(t.active))]}catch(e){throw e instanceof i?new s(`Zenon: unsupported operator ${e.message}`):e}})();return an([R(`;; obligation #%s@
35
+ `,String(e)),y])},_l=[`tla-ts`,`tlapm`],vl=e=>_l.some(t=>t===e),yl=e=>cs(go(e)),bl={encode:(e,t,n,r)=>(n.rlimit===void 0?``:`(set-option :rlimit ${n.rlimit})\n`)+ll(yl(t),r)},xl={smt:bl,z3:bl,zenon:{encode:(e,t)=>gl(e,yl(t))},isabelle:{encode:(e,t,n)=>Ma(e,yl(t),n.tactic??`auto`,`tlapm_${e}`)},ls4:{encode:(e,t)=>Os(t)}},Sl=e=>e.kind===`Case`&&e.other===void 0||We(e).some(Sl),Cl=/* @__PURE__ */ new WeakMap,wl=e=>{let t=Cl.get(e);if(t!==void 0)return t;let n=[];He(e,e=>(n.push(e),e),`all`);let r=n.some(Sl);return Cl.set(e,r),r},Tl=e=>/-{4,}\s*MODULE\s+(\w+)/.exec(e)?.[1]??`Main`,El=e=>({id:e.id,location:e.location,text:e.text}),Dl=(e,t,n)=>({...El(e),status:t,reason:n}),Ol=(e,t)=>Jo(ko(vo(e)),t),kl=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},Al=async(e,t,n,r)=>{if(e.kind.kind===`Error`)return Dl(e,`failed`,e.kind.message);let a=_s(e),o=as(e.sequent),c=n.lastByFingerprint.get(o);n.lastByFingerprint.set(o,n.tasks[t].done),await c;let l=n.results.get(o)??/* @__PURE__ */ new Map;n.results.set(o,l);let u=t=>({...El(e),status:`proved`,prover:t}),d=e=>{let t=l.get(e.prover);return t?.tactic===e.tactic?t:void 0},f=(e,t)=>l.set(e.prover,{isProved:t,timeLimitMs:e.timeLimitMs,tactic:e.tactic});if(d(a.provers[0])?.isProved)return u(a.provers[0].prover);let p=Ol(e.sequent,a.frontends);if(e.kind.kind===`Support`&&vs(p))return{...El(e),status:`trivial`};let m=[],h={isDecided:!1};for(let o of a.provers){let a=d(o);if(a?.isProved)return u(o.prover);if(a&&a.timeLimitMs>=o.timeLimitMs){h.isDecided=!0,m.push(`${o.prover} failed on an obligation with the same fingerprint`);continue}if(o.prover===`trivial`)return u(o.prover);let c=xl[o.prover];if(!c)m.push(`tla-ts has no ${o.prover} backend`);else try{let i=c===bl&&(p.context.some(wl)||Sl(p.active))?await kl(n,t):{caseErrors:0},a=c.encode(e.id,p,o,i),s=await n.decide(o.prover,a,{timeLimitMs:o.timeLimitMs,signal:r},t);if(f(o,s===`unsat`),s===`unsat`)return u(o.prover);h.isDecided=!0,m.push(`${o.prover} answered ${s}`)}catch(e){if(e instanceof s){f(o,!1),h.isDecided=!0,m.push(`${o.prover} failed: ${e.message}`);continue}if(!(e instanceof i))throw e;m.push(`${o.prover} can't encode ${e.message}`)}}return Dl(e,h.isDecided?`failed`:`unsupported`,m.join(`, `))},jl=async(e,t)=>{try{return await t()}catch(t){if(t instanceof i)return Dl(e,`unsupported`,t.message);if(t instanceof s)return Dl(e,`failed`,t.message);throw t}},Ml=(e,t)=>t?{...El(e),...t}:Dl(e,`unsupported`,`tlapm reported no result`),Nl=async e=>{let t=Tl(e.source),n=/* @__PURE__ */ new Map,r=ga([{file:`${t}.tla`,source:e.source}],t=>{let r=e.loadModule?.(t);r!==void 0&&n.set(t,r);let i=r??(t===`TLAPS`?`------------------------------- MODULE TLAPS --------------------------------
36
+
37
+ (* Backend pragmas. *)
38
+
39
+
40
+ (***************************************************************************)
41
+ (* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
42
+ (* is added to the context of an obligation most recently is the one whose *)
43
+ (* effects are triggered. *)
44
+ (***************************************************************************)
45
+
46
+ (***************************************************************************)
47
+ (* The following pragmas should be used only as a last resource. They are *)
48
+ (* dependent upon the particular backend provers, and are unlikely to have *)
49
+ (* any effect if the set of backend provers changes. Moreover, they are *)
50
+ (* meaningless to a reader of the proof. *)
51
+ (***************************************************************************)
52
+
53
+
54
+ (**************************************************************************)
55
+ (* Backend pragma: use the SMT solver for arithmetic. *)
56
+ (* *)
57
+ (* This method exists under this name for historical reasons. *)
58
+ (**************************************************************************)
59
+
60
+ SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
61
+
62
+
63
+ (**************************************************************************)
64
+ (* Backend pragma: SMT solver *)
65
+ (* *)
66
+ (* This method translates the proof obligation to SMTLIB2. The supported *)
67
+ (* fragment includes first-order logic, set theory, functions and *)
68
+ (* records. *)
69
+ (* SMT calls the smt-solver with the default timeout of 5 seconds *)
70
+ (* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
71
+ (* *)
72
+ (* SMTT also accepts a string argument of the form "rN" to bound the *)
73
+ (* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
74
+ (* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
75
+ (* resource count, so a small readable budget like "r5" is meaningful. *)
76
+ (* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
77
+ (* speed or load, so the proof's pass/fail outcome reproduces on any *)
78
+ (* machine and every rerun (for a fixed Z3 build); how long it takes to *)
79
+ (* consume the budget still varies by machine. This is Z3-specific. *)
80
+ (**************************************************************************)
81
+
82
+ SMT == TRUE (*{ by (prover:"smt3") }*)
83
+ SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
84
+
85
+
86
+ (**************************************************************************)
87
+ (* Backend pragma: CVC4 SMT solver *)
88
+ (* *)
89
+ (* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
90
+ (**************************************************************************)
91
+
92
+ (* The CVC3* methods are here for backward compatibility. They call CVC4. *)
93
+ CVC3 == TRUE (*{ by (prover: "cvc33") }*)
94
+ CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
95
+
96
+ CVC4 == TRUE (*{ by (prover: "cvc33") }*)
97
+ CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
98
+
99
+
100
+ (**************************************************************************)
101
+ (* Backend pragma: Yices SMT solver *)
102
+ (* *)
103
+ (* This method translates the proof obligation to Yices native language. *)
104
+ (**************************************************************************)
105
+
106
+ Yices == TRUE (*{ by (prover: "yices3") }*)
107
+ YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
108
+
109
+ (**************************************************************************)
110
+ (* Backend pragma: veriT SMT solver *)
111
+ (* *)
112
+ (* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
113
+ (**************************************************************************)
114
+
115
+ veriT == TRUE (*{ by (prover: "verit") }*)
116
+ veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
117
+
118
+ (**************************************************************************)
119
+ (* Backend pragma: Zipperposition solver *)
120
+ (* *)
121
+ (* This method translates the proof obligation to TPTP and *)
122
+ (* calls Zipperposition. *)
123
+ (**************************************************************************)
124
+
125
+ Zipper == TRUE (*{ by (prover: "zipper") }*)
126
+ ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
127
+
128
+ (**************************************************************************)
129
+ (* Backend pragma: Z3 SMT solver *)
130
+ (* *)
131
+ (* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
132
+ (* Z3 is used by default but you can also explicitly call it. *)
133
+ (* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
134
+ (* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
135
+ (* reproduces the same outcome on any machine (see SMTT). *)
136
+ (**************************************************************************)
137
+
138
+ Z3 == TRUE (*{ by (prover: "z33") }*)
139
+ Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
140
+
141
+ (**************************************************************************)
142
+ (* Backend pragma: SPASS superposition prover *)
143
+ (* *)
144
+ (* This method translates the proof obligation to the DFG format language *)
145
+ (* supported by the ATP SPASS. The translation is based on the SMT one. *)
146
+ (**************************************************************************)
147
+
148
+ Spass == TRUE (*{ by (prover: "spass") }*)
149
+ SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
150
+
151
+ (**************************************************************************)
152
+ (* Backend pragma: The PTL propositional linear time temporal logic *)
153
+ (* prover. It currently is the LS4 backend. *)
154
+ (* *)
155
+ (* This method translates the negetation of the proof obligation to *)
156
+ (* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
157
+ (**************************************************************************)
158
+
159
+ LS4 == TRUE (*{ by (prover: "ls4") }*)
160
+ LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
161
+ PTL == TRUE (*{ by (prover: "ls4") }*)
162
+
163
+ (**************************************************************************)
164
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
165
+ (* *)
166
+ (**************************************************************************)
167
+
168
+ Zenon == TRUE (*{ by (prover:"zenon") }*)
169
+ ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
170
+
171
+ (********************************************************************)
172
+ (* Backend pragma: Isabelle with different timeouts and tactics *)
173
+ (* (default is 30 seconds/auto) *)
174
+ (********************************************************************)
175
+
176
+ Isa == TRUE (*{ by (prover:"isabelle") }*)
177
+ IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
178
+ IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
179
+ IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
180
+
181
+ (***************************************************************************)
182
+ (* The following theorem expresses the (useful implication of the) law of *)
183
+ (* set extensionality, which can be written as *)
184
+ (* *)
185
+ (* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
186
+ (* *)
187
+ (* Theorem SetExtensionality is sometimes required by the SMT backend for *)
188
+ (* reasoning about sets. It is usually counterproductive to include *)
189
+ (* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
190
+ (* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
191
+ (* the Isabelle backend to use the rule of set extensionality. *)
192
+ (***************************************************************************)
193
+ IsaWithSetExtensionality == TRUE
194
+ (*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
195
+
196
+ THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
197
+ OBVIOUS
198
+
199
+ (***************************************************************************)
200
+ (* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
201
+ (* the definition *)
202
+ (* *)
203
+ (* NotInSetS == CHOOSE v : v \\notin SetS *)
204
+ (***************************************************************************)
205
+ THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
206
+ OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
207
+ -----------------------------------------------------------------------------
208
+
209
+
210
+
211
+ (********************************************************************)
212
+ (********************************************************************)
213
+ (********************************************************************)
214
+
215
+
216
+ (********************************************************************)
217
+ (* Old versions of Zenon and Isabelle pragmas below *)
218
+ (* (kept for compatibility) *)
219
+ (********************************************************************)
220
+
221
+
222
+ (**************************************************************************)
223
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
224
+ (* *)
225
+ (**************************************************************************)
226
+
227
+ SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
228
+ SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
229
+ VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
230
+ SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
231
+
232
+
233
+
234
+ (********************************************************************)
235
+ (* Backend pragma: Isabelle's automatic search ("auto") *)
236
+ (* *)
237
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
238
+ (* essentially simplification and equational reasoning. *)
239
+ (* Default imeout for all isabelle tactics is 30 seconds. *)
240
+ (********************************************************************)
241
+ Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
242
+ SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
243
+ SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
244
+ SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
245
+
246
+ (********************************************************************)
247
+ (* Backend pragma: Isabelle's "force" tactic *)
248
+ (* *)
249
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
250
+ (* quantifier reasoning. *)
251
+ (********************************************************************)
252
+ Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
253
+ SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
254
+ SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
255
+ SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
256
+
257
+ (***********************************************************************)
258
+ (* Backend pragma: Isabelle's "simplification" tactics *)
259
+ (* *)
260
+ (* These tactics simplify the goal before running one of the automated *)
261
+ (* tactics. They are often necessary for obligations involving record *)
262
+ (* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
263
+ (* sure you can get away with just Simplification *)
264
+ (***********************************************************************)
265
+ SimplifyAndSolve == TRUE
266
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
267
+ SlowSimplifyAndSolve == TRUE
268
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
269
+ SlowerSimplifyAndSolve == TRUE
270
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
271
+ SlowestSimplifyAndSolve == TRUE
272
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
273
+
274
+ Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
275
+ SlowSimplification == TRUE
276
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
277
+ SlowerSimplification == TRUE
278
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
279
+ SlowestSimplification == TRUE
280
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
281
+
282
+ (**************************************************************************)
283
+ (* Backend pragma: Isabelle's tableau prover ("blast") *)
284
+ (* *)
285
+ (* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
286
+ (* prover, Blast. It is almost never better than Zenon by itself, but *)
287
+ (* becomes very useful in combination with the Auto pragma above. The *)
288
+ (* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
289
+ (* Auto could not prove. (There is currently no way to use Zenon on the *)
290
+ (* results left over from Auto.) *)
291
+ (**************************************************************************)
292
+ Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
293
+ SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
294
+ SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
295
+ SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
296
+
297
+ AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
298
+
299
+
300
+ (**************************************************************************)
301
+ (* Backend pragmas: multi-back-ends *)
302
+ (* *)
303
+ (* These pragmas just run a bunch of back-ends one after the other in the *)
304
+ (* hope that one will succeed. This saves time and effort for the user at *)
305
+ (* the expense of computation time. *)
306
+ (**************************************************************************)
307
+
308
+ (* CVC3 goes first because it's bundled with TLAPS, then the other SMT
309
+ solvers are unlikely to succeed if CVC3 fails, so we run zenon and
310
+ Isabelle before them. *)
311
+ AllProvers == TRUE (*{
312
+ by (prover:"cvc33")
313
+ by (prover:"zenon")
314
+ by (prover:"isabelle"; tactic:"auto")
315
+ by (prover:"spass")
316
+ by (prover:"smt3")
317
+ by (prover:"yices3")
318
+ by (prover:"verit")
319
+ by (prover:"z33")
320
+ by (prover:"isabelle"; tactic:"force")
321
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
322
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
323
+ by (prover:"isabelle"; tactic:"clarsimp")
324
+ by (prover:"isabelle"; tactic:"auto, blast")
325
+ }*)
326
+ AllProversT(X) == TRUE (*{
327
+ by (prover:"cvc33"; timeout:@)
328
+ by (prover:"zenon"; timeout:@)
329
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
330
+ by (prover:"spass"; timeout:@)
331
+ by (prover:"smt3"; timeout:@)
332
+ by (prover:"yices3"; timeout:@)
333
+ by (prover:"verit"; timeout:@)
334
+ by (prover:"z33"; timeout:@)
335
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
336
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
337
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
338
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
339
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
340
+ }*)
341
+
342
+ AllSMT == TRUE (*{
343
+ by (prover:"cvc33")
344
+ by (prover:"smt3")
345
+ by (prover:"yices3")
346
+ by (prover:"verit")
347
+ by (prover:"z33")
348
+ }*)
349
+ AllSMTT(X) == TRUE (*{
350
+ by (prover:"cvc33"; timeout:@)
351
+ by (prover:"smt3"; timeout:@)
352
+ by (prover:"yices3"; timeout:@)
353
+ by (prover:"verit"; timeout:@)
354
+ by (prover:"z33"; timeout:@)
355
+ }*)
356
+
357
+ AllIsa == TRUE (*{
358
+ by (prover:"isabelle"; tactic:"auto")
359
+ by (prover:"isabelle"; tactic:"force")
360
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
361
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
362
+ by (prover:"isabelle"; tactic:"clarsimp")
363
+ by (prover:"isabelle"; tactic:"auto, blast")
364
+ }*)
365
+ AllIsaT(X) == TRUE (*{
366
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
367
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
368
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
369
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
370
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
371
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
372
+ }*)
373
+
374
+
375
+ (**************************************************************************)
376
+ (* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
377
+ (* *)
378
+ (* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
379
+ (* *)
380
+ (* The pragma AutoUSE invokes automated expansion of definitions, *)
381
+ (* for both of ExpandEnabled and ExpandCdot, when each is present. *)
382
+ (* *)
383
+ (* The pragma Lambdify invokes expansion of the operators *)
384
+ (* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
385
+ (* which is a form before introducing rigid quantifiers. *)
386
+ (* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
387
+ (* that are not nested. *)
388
+ (**************************************************************************)
389
+ ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
390
+ ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
391
+ AutoUSE == TRUE (*{ by (prover:"autouse") }*)
392
+ Lambdify == TRUE (*{ by (prover:"lambdify") }*)
393
+ ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
394
+ LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
395
+
396
+ (* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
397
+ (* representation within TLAPM. *)
398
+ EnabledWrapper(Op(_)) == FALSE
399
+ CdotWrapper(Op(_)) == FALSE
400
+
401
+ (***************************************************************************)
402
+ (* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
403
+ (* triviality checks in TLAPM. *)
404
+ (***************************************************************************)
405
+ Trivial == TRUE (*{ by (prover:"trivial") }*)
406
+
407
+
408
+ =============================================================================
409
+
410
+ The material below is obsolete: the TLA proof rules below are superseded by
411
+ the PTL decision procedure, and their formulation is unsound for the semantics
412
+ of temporal reasoning that TLAPS adopts.
413
+
414
+ ----------------------------------------------------------------------------
415
+ (***************************************************************************)
416
+ (* TEMPORAL LOGIC *)
417
+ (* *)
418
+ (* The following rules are intended to be used when TLAPS handles temporal *)
419
+ (* logic. They will not work now. Moreover when temporal reasoning is *)
420
+ (* implemented, these rules may be changed or omitted, and additional *)
421
+ (* rules will probably be added. However, they are included mainly so *)
422
+ (* their names will be defined, preventing the use of identifiers that are *)
423
+ (* likely to produce name clashes with future versions of this module. *)
424
+ (***************************************************************************)
425
+
426
+
427
+ (***************************************************************************)
428
+ (* The following proof rules (and their names) are from the paper "The *)
429
+ (* Temporal Logic of Actions". *)
430
+ (***************************************************************************)
431
+ THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
432
+ P /\\ (f' = f) => P'
433
+ PROVE []P <=> P /\\ [][P => P']_f
434
+
435
+ THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
436
+ ACTION A, ACTION B,
437
+ P /\\ [A]_f => Q /\\ [B]_g
438
+ PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
439
+
440
+ THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
441
+ I /\\ [N]_F => I'
442
+ PROVE I /\\ [][N]_F => []I
443
+
444
+ THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
445
+ PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
446
+
447
+ THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
448
+ P /\\ [N]_f => (P' \\/ Q'),
449
+ P /\\ <<N /\\ A>>_f => Q',
450
+ P => ENABLED <<A>>_f
451
+ PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
452
+
453
+ THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
454
+ ACTION N, ACTION A, TEMPORAL F,
455
+ P /\\ [N]_f => (P' \\/ Q'),
456
+ P /\\ <<N /\\ A>>_f => Q',
457
+ []P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
458
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
459
+
460
+ (***************************************************************************)
461
+ (* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
462
+ (* from the following two rules by the following substitutions: \`. *)
463
+ (* *)
464
+ (* ___ ___ _______________ *)
465
+ (* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
466
+ (***************************************************************************)
467
+ THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
468
+ ACTION A, ACTION B, ACTION N, ACTION M,
469
+ TEMPORAL F,
470
+ <<N /\\ B>>_f => <<M>>_g,
471
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
472
+ P /\\ EM => ENABLED A,
473
+ [][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
474
+ PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
475
+
476
+ THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
477
+ ACTION A, ACTION B, ACTION N, ACTION M,
478
+ TEMPORAL F,
479
+ <<N /\\ B>>_f => <<M>>_g,
480
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
481
+ P /\\ EM => ENABLED A,
482
+ [][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
483
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
484
+
485
+
486
+ (***************************************************************************)
487
+ (* The following rule is a special case of the general temporal logic *)
488
+ (* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
489
+ (* general rule is for arbitrary temporal formulas F and G, but it cannot *)
490
+ (* yet be handled by TLAPS. *)
491
+ (***************************************************************************)
492
+ THEOREM RuleInvImplication ==
493
+ ASSUME STATE F, STATE G,
494
+ F => G
495
+ PROVE []F => []G
496
+ PROOF OMITTED
497
+
498
+ (***************************************************************************)
499
+ (* The following rule is a special case of rule TLA2 from the paper "The *)
500
+ (* Temporal Logic of Actions". *)
501
+ (***************************************************************************)
502
+ THEOREM RuleStepSimulation ==
503
+ ASSUME STATE I, STATE f, STATE g,
504
+ ACTION M, ACTION N,
505
+ I /\\ I' /\\ [M]_f => [N]_g
506
+ PROVE []I /\\ [][M]_f => [][N]_g
507
+ PROOF OMITTED
508
+
509
+ (***************************************************************************)
510
+ (* The following may be used to invoke a decision procedure for *)
511
+ (* propositional temporal logic. *)
512
+ (***************************************************************************)
513
+ PropositionalTemporalLogic == TRUE
514
+ =============================================================================
515
+ `:void 0);return i===void 0?void 0:{file:`${t}.tla`,source:i}}),o=r.flatMap(e=>e.obligations),c={missingProofCount:r.reduce((e,t)=>e+t.summary.absent.length,0),omittedProofCount:r.reduce((e,t)=>e+t.summary.omitted.length,0)};if(e.backend===`tlapm`){if(typeof process>`u`||process.versions?.node===void 0)throw new i(`The tlapm backend runs only in Node and Bun.`);let r=await import(`./tlapm.js`),a=new Map(o.map(e=>[e.id,e])),s=await r.proveWithTlapm(t,new Map([[t,e.source],...n]),{signal:e.signal,onResult:(t,n)=>{let r=a.get(t);r&&e.onObligation?.(Ml(r,n))}});return{obligations:o.map(e=>Ml(e,s.get(e.id))),...c}}let l=e.workers??1,u=l>1&&a()?await _a(l):void 0,d=()=>u?.terminate(e.signal?.reason);e.signal?.addEventListener(`abort`,d);let f={tasks:[],results:/* @__PURE__ */ new Map,lastByFingerprint:/* @__PURE__ */ new Map,decide:u?.decide??(async(e,t,n)=>le[e](t,n))},p=u?l*4:1,m=[],h=[],g=/* @__PURE__ */ new Set,_=[],v=async()=>{for(;h[_.length];){e.signal?.throwIfAborted();let t=await m[_.length];_.push(t),e.onObligation?.(t),await new Promise(e=>setTimeout(e))}};try{for(let[t,n]of o.entries()){e.signal?.throwIfAborted();let r=Promise.withResolvers();f.tasks.push({done:r.promise,session:void 0});let i=jl(n,()=>Al(n,t,f,e.signal));m.push(i),g.add(r.promise);let a=()=>{h[t]=!0,g.delete(r.promise),r.resolve()};i.then(a,a),g.size>=p&&await Promise.race(g),await v()}await Promise.all(g),await v()}finally{e.signal?.removeEventListener(`abort`,d),u?.terminate(new s(`prove stopped`))}return{obligations:_,...c}};export{ha as a,fe as c,ra as i,ue as l,vl as n,ga as o,Nl as r,pe as s,_l as t};