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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/README.md +27 -141
  2. package/dist/deciders.cjs +366 -0
  3. package/dist/deciders.js +366 -0
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +37 -1
  6. package/dist/index.d.ts +37 -1
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +1 -4
  9. package/dist/parallel-worker.js +1 -4
  10. package/dist/prove-worker.cjs +9 -0
  11. package/dist/prove-worker.d.cts +9 -0
  12. package/dist/prove-worker.d.ts +9 -0
  13. package/dist/prove-worker.js +9 -0
  14. package/dist/prove.cjs +996 -0
  15. package/dist/prove.js +996 -0
  16. package/dist/run-cli.cjs +37 -47
  17. package/dist/run-cli.js +37 -47
  18. package/dist/tlapm.cjs +10 -0
  19. package/dist/tlapm.js +10 -0
  20. package/dist/transfer.cjs +38 -44
  21. package/dist/transfer.js +38 -44
  22. package/dist/worker.cjs +21 -0
  23. package/dist/worker.js +21 -0
  24. package/package.json +21 -12
  25. package/src/check.ts +1 -0
  26. package/src/codegen.ts +26 -7
  27. package/src/errors.ts +86 -0
  28. package/src/evaluate.ts +63 -20
  29. package/src/index.ts +10 -0
  30. package/src/{obligation-action.ts → obligations/action.ts} +265 -55
  31. package/src/{obligation-anon.ts → obligations/anon.ts} +47 -37
  32. package/src/obligations/ctx.ts +64 -0
  33. package/src/{obligation-deref.ts → obligations/deref.ts} +38 -61
  34. package/src/{obligation-expression.ts → obligations/expression.ts} +78 -45
  35. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  36. package/src/{obligation-generate.ts → obligations/generate.ts} +147 -74
  37. package/src/{obligations.ts → obligations/index.ts} +29 -13
  38. package/src/{obligation-levels.ts → obligations/levels.ts} +14 -5
  39. package/src/{obligation-module.ts → obligations/module.ts} +56 -33
  40. package/src/obligations/pickle.ts +98 -0
  41. package/src/obligations/pragma.ts +189 -0
  42. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  43. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
  44. package/src/{obligation-source.ts → obligations/source.ts} +159 -97
  45. package/src/obligations/temporal.ts +319 -0
  46. package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
  47. package/src/ocaml-marshal.ts +166 -0
  48. package/src/parallel-worker.ts +2 -18
  49. package/src/parallel.ts +10 -43
  50. package/src/prove/decide-pool.ts +100 -0
  51. package/src/prove/deciders.ts +33 -0
  52. package/src/prove/isabelle/LICENSE +36 -0
  53. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  54. package/src/prove/isabelle/decide.ts +47 -0
  55. package/src/prove/isabelle/encode.ts +503 -0
  56. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  57. package/src/prove/isabelle/isar/method.ts +367 -0
  58. package/src/prove/isabelle/isar/proof.ts +28 -0
  59. package/src/prove/isabelle/isar/statement.ts +57 -0
  60. package/src/prove/isabelle/isar/theory.ts +192 -0
  61. package/src/prove/isabelle/isar/type-check.ts +278 -0
  62. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  63. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  64. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  65. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  66. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  67. package/src/prove/isabelle/provers/blast/term.ts +547 -0
  68. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  69. package/src/prove/isabelle/provers/classical.ts +389 -0
  70. package/src/prove/isabelle/provers/hypsubst.ts +441 -0
  71. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  72. package/src/prove/isabelle/pure/consts.ts +32 -0
  73. package/src/prove/isabelle/pure/conv.ts +79 -0
  74. package/src/prove/isabelle/pure/drule.ts +264 -0
  75. package/src/prove/isabelle/pure/envir.ts +363 -0
  76. package/src/prove/isabelle/pure/goal.ts +53 -0
  77. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  78. package/src/prove/isabelle/pure/list.ts +12 -0
  79. package/src/prove/isabelle/pure/logic.ts +402 -0
  80. package/src/prove/isabelle/pure/name.ts +110 -0
  81. package/src/prove/isabelle/pure/net.ts +262 -0
  82. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  83. package/src/prove/isabelle/pure/pattern.ts +650 -0
  84. package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
  85. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  86. package/src/prove/isabelle/pure/search.ts +68 -0
  87. package/src/prove/isabelle/pure/seq.ts +156 -0
  88. package/src/prove/isabelle/pure/simplifier.ts +112 -0
  89. package/src/prove/isabelle/pure/table.ts +208 -0
  90. package/src/prove/isabelle/pure/tactic.ts +276 -0
  91. package/src/prove/isabelle/pure/tactical.ts +347 -0
  92. package/src/prove/isabelle/pure/term-ord.ts +159 -0
  93. package/src/prove/isabelle/pure/term.ts +808 -0
  94. package/src/prove/isabelle/pure/thm.ts +806 -0
  95. package/src/prove/isabelle/pure/type.ts +133 -0
  96. package/src/prove/isabelle/pure/unify.ts +753 -0
  97. package/src/prove/isabelle/pure/variable.ts +25 -0
  98. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  99. package/src/prove/isabelle/tla/context.ts +74 -0
  100. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  101. package/src/prove/isabelle/tla/logic.ts +215 -0
  102. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  103. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  104. package/src/prove/ocaml.ts +22 -0
  105. package/src/prove/prep/action.ts +521 -0
  106. package/src/prove/prep/defs.ts +33 -0
  107. package/src/prove/prep/elab.ts +156 -0
  108. package/src/prove/prep/enabled-axioms.ts +189 -0
  109. package/src/prove/prep/enabled.ts +43 -0
  110. package/src/prove/prep/fingerprint.ts +388 -0
  111. package/src/prove/prep/flatten.ts +70 -0
  112. package/src/prove/prep/level-comparison.ts +557 -0
  113. package/src/prove/prep/md5.ts +67 -0
  114. package/src/prove/prep/pragma.ts +221 -0
  115. package/src/prove/prep/trivial.ts +22 -0
  116. package/src/prove/prove-worker.ts +25 -0
  117. package/src/prove/prove.ts +505 -0
  118. package/src/prove/ptl/decide.ts +68 -0
  119. package/src/prove/ptl/encode.ts +256 -0
  120. package/src/prove/ptl/sat.ts +151 -0
  121. package/src/prove/ptl/tableau.ts +276 -0
  122. package/src/prove/smt/axiomatize.ts +69 -0
  123. package/src/prove/smt/axioms.ts +222 -0
  124. package/src/prove/smt/context.ts +108 -0
  125. package/src/prove/smt/data.ts +636 -0
  126. package/src/prove/smt/encode.ts +166 -0
  127. package/src/prove/smt/extensionality.ts +65 -0
  128. package/src/prove/smt/flatten.ts +112 -0
  129. package/src/prove/smt/format.ts +154 -0
  130. package/src/prove/smt/instances.ts +182 -0
  131. package/src/prove/smt/rewrite.ts +773 -0
  132. package/src/prove/smt/simplify.ts +57 -0
  133. package/src/prove/smt/solver/act-cache.ts +265 -0
  134. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  135. package/src/prove/smt/solver/array.ts +22 -0
  136. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  137. package/src/prove/smt/solver/ast-lt.ts +157 -0
  138. package/src/prove/smt/solver/ast-util.ts +147 -0
  139. package/src/prove/smt/solver/ast.ts +1315 -0
  140. package/src/prove/smt/solver/auf-solver.ts +572 -0
  141. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  142. package/src/prove/smt/solver/cg-table.ts +175 -0
  143. package/src/prove/smt/solver/clause.ts +276 -0
  144. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  145. package/src/prove/smt/solver/context.ts +1292 -0
  146. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  147. package/src/prove/smt/solver/der.ts +224 -0
  148. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  149. package/src/prove/smt/solver/e-matching.ts +659 -0
  150. package/src/prove/smt/solver/enode.ts +259 -0
  151. package/src/prove/smt/solver/expr-ref.ts +21 -0
  152. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  153. package/src/prove/smt/solver/fingerprints.ts +92 -0
  154. package/src/prove/smt/solver/flat-literals.ts +51 -0
  155. package/src/prove/smt/solver/goal.ts +138 -0
  156. package/src/prove/smt/solver/hash.ts +173 -0
  157. package/src/prove/smt/solver/hashtable.ts +166 -0
  158. package/src/prove/smt/solver/internalizer.ts +1381 -0
  159. package/src/prove/smt/solver/lbool.ts +5 -0
  160. package/src/prove/smt/solver/literal.ts +24 -0
  161. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  162. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  163. package/src/prove/smt/solver/lp/containers.ts +296 -0
  164. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  165. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  166. package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
  167. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  168. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  169. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  170. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  171. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  172. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  173. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  174. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  175. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  176. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  177. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  178. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  179. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  180. package/src/prove/smt/solver/lp/nex.ts +120 -0
  181. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  182. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  183. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  184. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  185. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  186. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  187. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  188. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  189. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  190. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  191. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  192. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  193. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  194. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  195. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  196. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  197. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  198. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  199. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  200. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  201. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  202. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  203. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  204. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  205. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  206. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  207. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  208. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  209. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  210. package/src/prove/smt/solver/model-checker.ts +347 -0
  211. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  212. package/src/prove/smt/solver/model-finder.ts +155 -0
  213. package/src/prove/smt/solver/model-generator.ts +97 -0
  214. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  215. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  216. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  217. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  218. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  219. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  220. package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
  221. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  222. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  223. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  224. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  225. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  226. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  227. package/src/prove/smt/solver/nnf.ts +469 -0
  228. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  229. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  230. package/src/prove/smt/solver/propagate-values.ts +83 -0
  231. package/src/prove/smt/solver/proto-model.ts +551 -0
  232. package/src/prove/smt/solver/pull-quant.ts +139 -0
  233. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  234. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  235. package/src/prove/smt/solver/qe-lite.ts +381 -0
  236. package/src/prove/smt/solver/qi-queue.ts +362 -0
  237. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  238. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  239. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  240. package/src/prove/smt/solver/random-gen.ts +10 -0
  241. package/src/prove/smt/solver/rational.ts +165 -0
  242. package/src/prove/smt/solver/ref-vector.ts +62 -0
  243. package/src/prove/smt/solver/relevancy.ts +247 -0
  244. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  245. package/src/prove/smt/solver/rewriter.ts +843 -0
  246. package/src/prove/smt/solver/rlimit.ts +79 -0
  247. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  248. package/src/prove/smt/solver/solver.ts +71 -0
  249. package/src/prove/smt/solver/sort.ts +35 -0
  250. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  251. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  252. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  253. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  254. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  255. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  256. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  257. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  258. package/src/prove/smt/solver/theory-lra.ts +56 -0
  259. package/src/prove/smt/solver/var-subst.ts +258 -0
  260. package/src/prove/smt/solver/z3-license.txt +10 -0
  261. package/src/prove/smt/table.ts +170 -0
  262. package/src/prove/tlapm/tlapm.ts +96 -0
  263. package/src/prove/tlaps-module.ts +510 -0
  264. package/src/prove/verdict.ts +18 -0
  265. package/src/prove/zenon/LICENSE +32 -0
  266. package/src/prove/zenon/check/check.ts +105 -0
  267. package/src/prove/zenon/check/definitions.ts +144 -0
  268. package/src/prove/zenon/check/equality.ts +182 -0
  269. package/src/prove/zenon/check/functions.ts +62 -0
  270. package/src/prove/zenon/check/keys.ts +125 -0
  271. package/src/prove/zenon/check/propositional.ts +104 -0
  272. package/src/prove/zenon/check/records.ts +188 -0
  273. package/src/prove/zenon/check/relations.ts +121 -0
  274. package/src/prove/zenon/check/rewrites.ts +224 -0
  275. package/src/prove/zenon/check/sets.ts +302 -0
  276. package/src/prove/zenon/check/terms.ts +127 -0
  277. package/src/prove/zenon/check/tla.ts +126 -0
  278. package/src/prove/zenon/decide.ts +113 -0
  279. package/src/prove/zenon/encode.ts +437 -0
  280. package/src/prove/zenon/eqrel.ts +300 -0
  281. package/src/prove/zenon/equality-rules.ts +435 -0
  282. package/src/prove/zenon/expr.ts +551 -0
  283. package/src/prove/zenon/index-table.ts +350 -0
  284. package/src/prove/zenon/isar-case.ts +513 -0
  285. package/src/prove/zenon/isar.ts +1249 -0
  286. package/src/prove/zenon/limits.ts +15 -0
  287. package/src/prove/zenon/llproof.ts +173 -0
  288. package/src/prove/zenon/mltoll.ts +1566 -0
  289. package/src/prove/zenon/node.ts +297 -0
  290. package/src/prove/zenon/ocaml.ts +169 -0
  291. package/src/prove/zenon/parse.ts +247 -0
  292. package/src/prove/zenon/phrase.ts +191 -0
  293. package/src/prove/zenon/proof.ts +198 -0
  294. package/src/prove/zenon/propositional-rules.ts +387 -0
  295. package/src/prove/zenon/rules.ts +94 -0
  296. package/src/prove/zenon/search.ts +288 -0
  297. package/src/prove/zenon/tla/functions.ts +151 -0
  298. package/src/prove/zenon/tla/llproof.ts +480 -0
  299. package/src/prove/zenon/tla/records.ts +225 -0
  300. package/src/prove/zenon/tla/rewrites.ts +447 -0
  301. package/src/prove/zenon/tla/sets.ts +304 -0
  302. package/src/prove/zenon/tla/terms.ts +181 -0
  303. package/src/prove/zenon/tla/tla.ts +506 -0
  304. package/src/run-cli.ts +334 -75
  305. package/src/standard-modules.ts +5 -2
  306. package/src/successors.ts +24 -5
  307. package/src/tlapm-cache.ts +236 -0
  308. package/src/tlc-random.ts +55 -32
  309. package/src/tlc-version.ts +8 -7
  310. package/src/values.ts +97 -47
  311. package/src/worker.ts +65 -0
  312. package/dist/parallel.cjs +0 -12
  313. package/dist/parallel.js +0 -12
package/dist/prove.js ADDED
@@ -0,0 +1,996 @@
1
+ /**
2
+ * @license tla-ts
3
+ *
4
+ * Copyright (c) Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ 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 te,l as ne,n as re,nt as x,o as S,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)},x=()=>{let n={count:i.count};return ne({...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 x();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(),w=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(w,t,c);let T=w.environment,E=oe(t,T,()=>p(e.source,de),c);if(y(w.assumptions,T)||!E||E.spec.init===void 0||E.spec.next===void 0||E.properties.liveness.length>0||d(T))return x();let me=u(),D={fingerprints:te()},O=/* @__PURE__ */ new Int32Array(2),he=Array.from({length:le},re),k={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,initialStates:void 0,outDegrees:Array.from({length:32},()=>0)},ge=[],A=()=>({status:`success`,violation:void 0,failure:void 0,...k,fingerprintDistance:ee(k.distinctStates,k.generatedStates,()=>{let e=new BigInt64Array(k.distinctStates);return ge.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),j=e=>{let t=[];for(let n of l(e,T,E.spec.scope))if(b(k.generatedStates,c),me(n),k.generatedStates++,v(E.getFingerprintState(n),O),ae(D.fingerprints)&&(D.fingerprints=_(D.fingerprints)),S(D.fingerprints,O[0],O[1])){if(E.findViolatedInvariant(n)||E.findFailedInitialPredicate(n))return!1;if(E.satisfiesConstraints(n)){if(!he[t.length%le].encode(n))return!1;t.push(n),k.distinctStates++}}return ge.push(BigInt64Array.from(t,e=>T.runtime.getFingerprint(e))),!0};c({kind:`initial-states-started`});try{if(!j(E.spec.init))return x()}catch(e){if(!(e instanceof n))throw e;return x()}if(h()!==C)return x();if(k.depth=k.generatedStates===0?0:1,k.initialStates={generated:k.generatedStates,distinct:k.distinctStates},c({kind:`initial-states-computed`,initialStates:k.initialStates}),k.distinctStates===0)return A();let _e=[],ve={count:le,resolve:e=>{}},ye=e=>{_e.push(e),(e.type===`abort`||_e.length===ve.count)&&ve.resolve(_e.splice(0))},M=e=>new Promise(t=>{ve.count=e,ve.resolve=t}),be=M(le),N=new Int32Array(new SharedArrayBuffer(le*4)),xe=new Int32Array(new SharedArrayBuffer(le*4)),Se=await Promise.all(Array.from({length:le},()=>o(new URL(`./parallel-worker.js`,import.meta.url),e=>ye(e),()=>ye({type:`abort`})))),Ce=()=>Se.forEach(e=>e.terminate()),we=/* @__PURE__ */ new Map,Te=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=we.get(n)??new MessageChannel;return we.set(n,r),e<t?r.port1:r.port2};Se.forEach((n,r)=>{let i=Array.from({length:le},(e,t)=>t===r?void 0:Te(r,t)),a=he[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:D.fingerprints,requests:N,remaining:xe};n.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let Ee=e=>e.some(e=>e.type===`abort`),De=e=>Se.forEach(t=>t.postMessage(e)),Oe=async e=>{let t=e.filter(e=>e.type===`paused`).length;if(t===0||Ee(e))return e;D.fingerprints=_(D.fingerprints);let n=M(t);return De({type:`resize`,fingerprints:D.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await Oe(await n)]};if(Ee(await be))return Ce(),x();for(let e=1;;e++){let t=M(le);N.forEach((e,t)=>Atomics.store(N,t,0)),De({type:`level`,level:e});let n=await Oe(await t);if(Ee(n))return Ce(),x();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(k.generatedStates+=r.reduce((e,t)=>e+t.generated,0),k.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>k.outDegrees[t]+=e),ge.push(e.fingerprints)}),i===0)return Ce(),A();k.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`}),w=e=>e?`${fe(e)} :\n`:``,T=e=>({kind:`Shift`,amount:e}),E=(e,t)=>({kind:`Cons`,expression:e,rest:t}),me=(e,t)=>e.reduce((e,t)=>E(t,e),t),D=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},O=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},he=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},k=(e,t,n)=>O({kind:`Apply`,operator:O({kind:`Internal`,builtin:e},n),args:t},n),ge=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},A=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),j=(e,t)=>t.reduce(A,e),_e=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},ve=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(he(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},ye=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},M=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},be=(e,t)=>{let n={state:e,hyp:void 0,parent:void 0,next:/* @__PURE__ */ new WeakMap};return(e,r=e)=>{let i=e.reduce((e,n,i)=>{let a=e.next.get(n);if(a)return a;let[o,s]=t(e.state,r[i],n),c={state:o,hyp:s,parent:e,next:/* @__PURE__ */ new WeakMap};return e.next.set(n,c),c},n),a=[];for(let e=i;e;e=e.parent)e.hyp&&a.push(e.hyp);return{state:i.state,context:a.reverse()}}},N=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),xe=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),Se=(e,t,n)=>{switch(e.kind){case`Shift`:return O({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?O(Te(e.expression),n):Se(e.rest,t-1,n);case`Compose`:return P(e.outer,Se(e.inner,t,n));case`Bump`:return t<=e.amount?O({kind:`Ix`,index:t},n):P(T(e.amount),Se(e.rest,t-e.amount,n))}},Ce=(e,t)=>t.map(t=>P(e,t)),we=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e(`Arity mismatch`);return Te(P(me(n,T(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?Te(t):{kind:`Apply`,operator:t,args:n}},Te=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},Ee=(e,t)=>[D(t.length,e),Re(t,t=>P(e,t))],De=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return Ve(t,t=>P(e,t));case`Instance`:{let n=D(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:P(n,e.expression)}))}}}}},Oe=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:P(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:De(e,t.definition)};case`Fact`:return{...t,expression:P(e,t.expression)}}},ke=(e,t)=>{let[n,r]=M(e,t.context,(e,t)=>[D(1,e),Oe(e,t)]);return{context:r,active:P(n,t.active)}},P=(e,t)=>{let n=t=>P(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return Se(e,t.index,t);case`Apply`:return O(we(n(t.operator),Ce(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:P(D(t.params.length,e),t.body)};case`Let`:{let[n,r]=M(e,t.definitions,(e,t)=>[D(1,e),De(e,t)]);return{...t,definitions:r,body:P(n,t.body)}}case`Sequent`:return{...t,sequent:ke(e,t.sequent)};case`With`:case`Dot`:case`Parens`:return{...t,expression:n(t.expression)};case`If`:return{...t,condition:n(t.condition),consequent:n(t.consequent),alternative:n(t.alternative)};case`List`:return{...t,items:Ce(e,t.items)};case`Quant`:case`Fcn`:{let[n,r]=Ee(e,t.bounds);return{...t,bounds:r,body:P(n,t.body)}}case`Tquant`:return{...t,body:P(D(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:P(D(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:P(D(1,e),t.body)};case`SetOf`:{let[n,r]=Ee(e,t.bounds);return{...t,bounds:r,element:P(n,t.element)}}case`SetEnum`:case`Tuple`:return{...t,elements:Ce(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`FcnApp`:return{...t,function:n(t.function),args:Ce(e,t.args)};case`Product`:return{...t,factors:Ce(e,t.factors)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:Be(t.specs,n)};case`Sub`:case`Tsub`:case`Fair`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)}}},F=(e,t)=>e===0?t:P(T(e),t),Ae=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),je=(e,t)=>e&&t?I(e,t):!e&&!t,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||!I(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`&&I(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`&&Ae(e.args,t.args,I);case`Label`:return t.kind===`Label`&&e.label===t.label&&Ae(e.args,t.args,I);default:return!0}},Fe=(e,t)=>{if((e.kind===`Operator`||e.kind===`Bpragma`)&&t.kind===e.kind)return I(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 Ae(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&&je(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`&&I(e.expression,t.expression),Le=(e,t)=>Ae(e.context,t.context,Ie)&&I(e.active,t.active),I=(e,t)=>{if(e.kind===`Parens`)return I(e.expression,t);if(t.kind===`Parens`)return I(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&&I(e.body,t.body);case`Apply`:return t.kind===`Apply`&&I(e.operator,t.operator)&&Ae(e.args,t.args,I);case`Sequent`:return t.kind===`Sequent`&&Le(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&I(e.expression,t.expression)&&Ae(e.selectors,t.selectors,Pe);case`With`:return t.kind===`With`&&I(e.expression,t.expression);case`Let`:return t.kind===`Let`&&Ae(e.definitions,t.definitions,Fe)&&I(e.body,t.body);case`If`:return t.kind===`If`&&I(e.condition,t.condition)&&I(e.consequent,t.consequent)&&I(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&Ae(e.items,t.items,I);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&Ae(e.bounds,t.bounds,Ne)&&I(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&Ae(e.names,t.names,(e,t)=>e===t)&&I(e.body,t.body);case`Choose`:return t.kind===`Choose`&&je(e.domain,t.domain)&&I(e.body,t.body);case`SetSt`:return t.kind===`SetSt`&&I(e.domain,t.domain)&&I(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&I(e.element,t.element)&&Ae(e.bounds,t.bounds,Ne);case`SetEnum`:case`Tuple`:return t.kind===e.kind&&Ae(e.elements,t.elements,I);case`Arrow`:return t.kind===`Arrow`&&I(e.domain,t.domain)&&I(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&Ae(e.bounds,t.bounds,Ne)&&I(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&Ae([e.function,...e.args],[t.function,...t.args],I);case`Product`:return t.kind===`Product`&&Ae(e.factors,t.factors,I);case`Rect`:case`Record`:return t.kind===e.kind&&Me(e.fields,t.fields);case`Except`:return t.kind===`Except`&&I(e.function,t.function)&&Ae(e.specs,t.specs,(e,t)=>Ae(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&I(e.expression,t.expression))&&I(e.value,t.value));case`Dot`:return t.kind===`Dot`&&I(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&I(e.action,t.action)&&I(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&I(e.subscript,t.subscript)&&I(e.action,t.action);case`Case`:return t.kind===`Case`&&(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:I(e.arms[0].condition,t.arms[0].condition)&&I(e.arms[0].body,t.arms[0].body))&&je(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)},L=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,N(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=N(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]=M(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]=M(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?xe(t.name,i):N(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=xe(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)=>L(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`?O({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=>N(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=>N(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,N(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of We(e)){let e=r(t);if(e)return e}return}},Ze=(e,t)=>me(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),T(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 P(me(r,T(0)),i)}case`Tquant`:return $e(t,O({kind:`Quant`,quantifier:n.quantifier,bounds:n.names.map(e=>({name:e,level:`State`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`Lambda`:return $e(t,O({kind:`Quant`,quantifier:`Forall`,bounds:n.params.map(e=>({name:e.name,level:`Unknown`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`SetSt`:case`Choose`:if(r.length!==1){let i=`Arity mismatch in subexpression instance.\nExpected 1 argument, but found ${r.length}.`;throw t(C(n.location,i)),new e(i,{failure:`Expr.Deref.deref_inst`})}return P(me(r,T(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=P(Ze(n,i.length),r);return[i,$e(t,a,Qe(i.length))]},tt=(t,n,r,i,a)=>{let o=n=>{if(!(r<=n))throw t(C(i.location,a)),new e(a,{failure:`Expr.Deref.deref_num`})},s=e=>(o(e.length),e[r-1]);if(n.kind===`With`)return tt(t,n.expression,r,i,a);let c=(()=>{switch(n.kind){case`Sequent`:{let i=n.sequent;o(i.context.length+1);let a=i.context[r-1];if(a&&a.kind!==`Fact`){let r=`subexpression reference does not resolve to an expression`;throw t(C(n.location,r)),new e(r,{failure:`Expr.Deref.deref_num`})}let s=P(T(-(r-1)),a?a.expression:i.active);if(Ye(s))throw t(C(n.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 s}case`Apply`:return s(n.args);case`If`:return s([n.condition,n.consequent,n.alternative]);case`List`:return s(n.items);case`SetEnum`:case`Tuple`:return s(n.elements);case`Product`:return s(n.factors);case`Let`:return o(1),n.body;case`Quant`:case`SetOf`:case`Fcn`:return s(n.bounds.flatMap(e=>e.domain.kind===`Domain`?[e.domain.expression]:[]));case`Choose`:case`SetSt`:if(!n.domain)break;return s([n.domain]);case`Arrow`:return s([n.domain,n.range]);case`FcnApp`:{let e=n.args.length===1?n.args[0]:O({kind:`Tuple`,elements:n.args},n);return s([n.function,e])}case`Rect`:case`Record`:return s(n.fields.map(e=>e.value));case`Dot`:return s([n.expression,O({kind:`String`,value:n.field},n)]);case`Except`:return s([n.function,...n.specs.map(e=>e.value)]);case`Sub`:case`Tsub`:return s([n.action,n.subscript]);case`Fair`:return s([n.subscript,n.action]);case`Case`:return s([...n.arms.map(e=>O({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...n.other?[O({kind:`Tuple`,elements:[Ge,n.other]},n.other)]:[]])}let i=`Expression has no subexpressions`;throw t(C(n.location,i)),new e(i,{failure:`Expr.Deref.deref_num`})})();if(Ke(c)){let i=`Cannot resolve subexpression reference !${r}`;throw t(C(n.location,i)),new e(i,{failure:`Expr.Deref.deref_num`})}return[n.kind===`Let`?n.definitions:[],c]},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`?O({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?O({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):P(T(-1),e),s.expression),f=P(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=>P(T(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=P(E(h[0],T(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`?O({...c,body:O({kind:`Parens`,expression:c.body,form:{kind:`Xlabel`,label:i,indices:c.params.map((e,t)=>({name:e.name,index:c.params.length-t}))}},c.body)},c):O({kind:`Parens`,expression:c,form:{kind:`Xlabel`,label:i,indices:[]}},c);return rt(t,n,O({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:O({kind:`Let`,definitions:r.definitions,body:r.expression},r.expression),t=r.params.length===0?e:O({kind:`Lambda`,params:r.params,body:e},e);return{...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=>P(T(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=>k(`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`])?k(`BoxTrue`,[k(`Implies`,[t(e.args[0]),k(`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=k(`ENABLED`,[O({kind:`Sub`,modal:`Dia`,action:t,subscript:n},t)],t),i=e.fairness===`Weak`?`Diamond`:`BoxTrue`,a=e.fairness===`Weak`?`BoxTrue`:`Diamond`;return k(`Implies`,[k(i,[k(a,[r],t)],t),k(`BoxTrue`,[O({kind:`Tsub`,modal:`Dia`,action:t,subscript:n},t)],t)],t)}),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`?k(`Disj`,[n,lt(r)],e):k(`Conj`,[n,k(`Neg`,[lt(r)],e)],e);return e.kind===`Sub`?i:k(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=>k(`Eq`,[k(`Prime`,[e],e),e],e));return t.length===0?O({kind:`Internal`,builtin:`TRUE`},e):t.length===1?t[0]:O({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)=>A(e,N(t,`Constant`)),e),bt=(e,t)=>{let n=t=>bt(e,t);switch(t.kind){case`Ix`:{let n=ye(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:A(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:A(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(A,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=>({warnedSteps:[],scope:e}),s=e=>e.scope?.size??0,c=(e,t)=>{if(t.kind===`At`&&t.isExcept)return a?F(s(e)-a.size,a.expression):t;if(t.kind!==`Except`)return p(e,t);let n=c(e,t.function);return t.specs.reduce((n,r)=>{let[i,o]=M(n,r.trail,(t,n)=>{if(n.kind===`Dot`)return[O({kind:`Dot`,expression:t,field:n.field},t),n];let r=c(e,n.expression);return[O({kind:`FcnApp`,function:t,args:[r]},t),{kind:`Apply`,expression:r}]}),l=a;a={expression:i,size:s(e)};let u=c(e,r.value);return a=l,O({kind:`Except`,function:n,specs:[{trail:o,value:u}]},t)},n)},l=(e,t,n)=>{let r=O({kind:`Ix`,index:e},n);return t.length===0?r:O({kind:`Apply`,operator:r,args:t},n)},u=(e,t,n,r,i)=>{if(t!==`Builtin`)return l(e,r,i);let a=F(e,n);return O(r.length===0?a:we(a,r),i)},d=(t,n,a,o)=>{let s=ve(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 c=s.depth+1,d=s.hyp;switch(d.kind){case`Defn`:{let t=d.definition;if(t.kind===`Operator`)return u(c,d.whereDefined,t.body,a,o);if(t.kind===`Recursive`)throw new e(`Recursive operators not supported by TLAPS`,{failure:`Expr.Anon: Recursive`});return l(c,a,o)}case`Fresh`:return l(c,a,o);case`Flex`:return O({kind:`Ix`,index:c},o);case`Fact`:throw new r(`File "src/expr/e_anon.ml", line 230, characters 24-36: Assertion failed`)}},f=(t,n,r,a,o,s)=>{let l=ve(t.scope,n);if(!l){let[o,...l]=a;if(o?.kind===`Label`){let e=o.args.map(e=>c(t,e));return f(t,`${n}!${o.label}`,[...r,...e],l,!0,s)}let u=`Operator "${n}" not found`;throw o&&i(C(s.location,u)),new e(u,{failure:`Expr.Anon: ${o?Dt[o.kind]:`1EMPTY`}`})}let d=l.hyp;if(d.kind!==`Defn`||d.definition.kind!==`Operator`&&d.definition.kind!==`Bpragma`)throw new e(`invalid subexpression reference`);let p=l.depth+1;if(a.length===0&&o)return r.length===0?O({kind:`Ix`,index:p},s):u(p,d.whereDefined,d.definition.body,r,s);let m=At(F(p,d.definition.body),s);return At(st(i,m,r,a),s)},p=(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=>c(e,t))),i=n.args.map(t=>c(e,t)),a=o(e.scope);return f(a,n.operator.name,i,r,!1,t)}return c(e,{...t,expression:O({kind:`Apply`,operator:n,args:[]},n)})}case`Apply`:{if(t.operator.kind!==`Opaque`)return y(e,t);let n=t.operator.name;if(e.warnedSteps.includes(n))return i({text:`${w(t.location)}Warning: ${n} does not introduce any assumptions. It does not make sense to use it here.\n`,channel:`toolbox`}),O({kind:`Internal`,builtin:`TRUE`},t);let r=t.args.map(t=>c(e,t));return d(e,n,r,t)}case`Opaque`:return c(e,O({kind:`Apply`,operator:t,args:[]},t));case`Parens`:return t.form.kind===`Syntax`?c(e,t.expression):{...t,expression:c(e,t.expression),form:m(e,t.form)};default:return y(e,t)}},m=(t,n)=>n.kind===`Nlabel`?{kind:`Xlabel`,label:n.label,indices:n.names.map(n=>{let r=ve(t.scope,n);if(!r)throw new e(`Identifier "${n}" in label parameters not found`);return{name:n,index:r.depth+1}})}:n,h=(e,t)=>({warnedSteps:e.warnedSteps,scope:t}),g=(e,t)=>h(e,A(e.scope,t)),_=(e,t)=>t.reduce((e,t)=>g(e,N(t.name,t.level)),e),v=(e,t)=>{let n=Re(t,t=>c(e,t));return[_(e,n),n]},y=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:ne(e,t.sequent)[1]};if(t.kind===`Let`){let[n,r]=ee(e,t.definitions);return{...t,definitions:r,body:c(n,t.body)}}return L(e,t,c,g)},b=(e,t)=>{if(t.kind!==`Operator`)return t;let n=t.body;if(n.kind!==`Fcn`)return{...t,body:c(e,n)};let r=c(g(e,N(t.name,`Constant`)),n);if(I(P(E({kind:`Opaque`,name:`%%%`},T(1)),r),r))return{...t,body:F(-1,r)};let i=k(`Eq`,[O({kind:`Ix`,index:1},r),r],r);return{...t,body:O({kind:`Choose`,name:t.name,domain:void 0,body:i},r)}},ee=(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=b(r,t);r=g(r,{kind:`Defn`,definition:o,whereDefined:`User`,visibility:`Visible`,isLocal:!0,isConstnessUnset:!0}),a.push(o)}return[r,a]},te=(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:c(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:b(e,t.definition)};case`Fact`:{let n=c(e,t.expression);return{...t,expression:n,time:St(e.scope,n)}}}})();return[g(e,n),n]},ne=(e,t)=>{let[n,r]=M(e,t.context,te);return[n,{context:r,active:c(n,t.active)}]},re=(e,t)=>({warnedSteps:[wt(t),...e.warnedSteps],scope:e.scope}),x=(e,t,n,r)=>g(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)=>h(e,j(e.scope,Array.from({length:t},()=>Et))),ie=e=>{let t=[...e.context.map((t,n)=>{let r=e.context.length-n+1;if(t.kind===`Fact`)return F(r,t.expression);if(t.kind!==`Fresh`||!t.domain)return Ot;let i=k(`Mem`,[O({kind:`Ix`,index:0},t.domain),t.domain],t.domain);return F(r,i)}),F(1,e.active)];return t.length===1?t[0]:{kind:`Tuple`,elements:t}},ae=e=>e.kind!==`Use`&&e.kind!==`Hide`&&e.kind!==`Define`,oe=(e,t)=>({facts:t.facts.map(t=>c(e,t)),defs:t.defs.flatMap(t=>{if(t.kind===`Dx`)return[t];let n=c(e,O({kind:`Opaque`,name:t.name},t));return n.kind===`Ix`?ye(e.scope,n.index-1)?.hyp.kind===`Defn`?[{kind:`Dx`,index:n.index,location:t.location}]:(i({text:`${w(t.location)}${JSON.stringify(t.name)} is not a definition and cannot be used in a DEF clause.`,channel:`toolbox`}),[]):(i({text:`${w(t.location)}Ignored unexpandable identifier ${JSON.stringify(t.name)} in BY DEF.`,channel:`stderr`}),[])})}),se=(e,t)=>{switch(t.kind){case`Steps`:{let[n,r]=M(e,t.steps,ce),i=se(t.step?re(n,t.step):n,t.qed.proof);return{...t,steps:r,qed:{...t.qed,proof:i}}}case`By`:return{...t,usable:oe(e,t.usable)};default:return t}},ce=(e,n)=>{let i=n.step?.kind===`Unnamed`&&ae(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]=ne(e,a.sequent),n=t.context.reduce(g,e),r=S(x(S(n,1),i,O(ie(t),a),a),1),o=t.context.length===0?re(r,i):r,s={...a,sequent:t,proof:se(o,a.proof)};return[S(x(e,i,O(ge(t),a),a),1),s]}case`Pcase`:{let t=c(e,a.expression),n=O({kind:`Tuple`,elements:[F(2,t)]},a),r=S(x(S(e,2),i,n,a),1),o={...a,expression:t,proof:se(r,a.proof)},s=x(e,i,O({kind:`Tuple`,elements:[t]},a),a);return[S(s,1),o]}case`Suffices`:{let[,t]=ne(e,a.sequent),n=O({kind:`Tuple`,elements:[O(ge(t),a)]},a),r=S(x(e,i,n,a),1),o={...a,sequent:t,proof:se(r,a.proof)},s=t.context.reduce(g,e),c=O({kind:`Tuple`,elements:[O(ie(t),a)]},a);return[S(x(S(s,1),i,c,a),1),o]}case`Have`:{let t=c(e,a.expression),n=O({kind:`Tuple`,elements:[F(2,t)]},a);return[S(x(S(e,2),i,n,a),1),{...a,expression:t}]}case`Take`:{let[t,n]=v(e,a.bounds),r=O({kind:`Quant`,quantifier:`Forall`,bounds:n,body:Ot},a);return[S(x(S(t,1),i,r,a),1),{...a,bounds:n}]}case`Witness`:{let t=a.expressions.map(t=>c(e,t)),n=O({kind:`Tuple`,elements:t},a);return[S(x(S(e,1),i,n,a),1),{...a,expressions:t}]}case`Pick`:{let[t,n]=v(e,a.bounds),r=c(t,a.expression),o=O({kind:`Quant`,quantifier:`Exists`,bounds:n,body:r},a),s=re(S(x(S(e,1),i,o,a),1),i),l={...a,bounds:n,expression:r,proof:se(s,a.proof)},u=_(S(e,2),n),d=F(4+n.length,o);return[S(x(S(u,2),i,d,a),1),l]}case`Use`:{let t=oe(e,a.usable);return[S(e,t.facts.length),{...a,usable:t}]}case`Hide`:return[e,{...a,usable:oe(e,a.usable)}];case`Define`:{let[t,n]=ee(e,a.definitions);return[t,{...a,definitions:n}]}case`Forget`:return[e,a]}};return{expr:(e,t)=>c(o(e),t),defn:(e,t)=>b(o(e),t),sequent:(e,t)=>ne(o(e),t)[1],usable:(e,t)=>oe(o(e),t),proof:(e,t)=>se(o(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=e=>{let t={size:-1,token:{kind:`Begin`,indent:0,box:`hov`},length:0};return{queue:[t],queueStart:0,scanStack:[Pt(),{leftTotal:1,element:t}],formatStack:[],margin:78,maxIndent:e,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.maxIndent)),e.output=t},Qt={h:`h`,v:`v`,hv:`hv`,hov:`hov`,b:`b`},$t=e=>({kind:`Text`,text:e,size:Nt(e)}),R=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)}},z=(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},B=(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,t=68)=>{let n=Ft(t);return rn(n,e),Xt(n)},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=>[z(`(`),e,z(`)`)],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[z(`@[<h>`),...a,z(`@]`)]}case`Infix`:{let r=t.left,i=t.right,a=n(r)||r.kind===`Op`&&r.name===e.name&&t.assoc===`Left`,o=n(i)||t.assoc===`Right`&&i.kind===`Op`&&i.skeleton.kind===`Infix`&&i.skeleton.assoc===`Right`;return[z(`@[<b0>`),bn(r,a),e.doc,bn(i,o),z(`@]`)]}}},V=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?[]:z(`@[<hov1>(%a)@]`,B(Array.from({length:e},()=>`_`),R)),En=e=>z(`%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),()=>z(`@[<b2>LAMBDA @[<hv0>%a@] :@ %a@]`,B(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(B(r,t=>{let n=B(t.names,R),r=e[t.index].domain;return r.kind===`NoDomain`?n:r.kind===`Ditto`?z(`@[<hov0>%a@ \\in ??????@]`,n):z(`@[<hov0>%a@ \\in %a@]`,n,i[t.index]??[])}))})},o=e=>{switch(e.kind){case`Down`:return z(`:`);case`Left`:return z(`<<`);case`Right`:return z(`>>`);case`At`:return R(`@`);case`Number`:return R(String(e.value));case`Instance`:return z(`@[<b1>(%a)@]`,B(e.args,r));case`Label`:return e.args.length===0?R(e.label):z(`@[<b2>%s@,@[<b1>(%a)@]@]`,e.label,B(e.args,r))}},s=e=>e.length===0?[]:[z(`!`),B(e,o,z(`!`))],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?he(r)??`??? FACT ???`:`#$${e}`},l=(t,n)=>{if(t.kind===`Lambda`)return{kind:`Op`,name:` `,doc:z(`@ `),low:20,high:20,skeleton:{kind:`Infix`,assoc:`Left`,left:Sn(i(t.params,t.body)),right:V(z(`(%a)`,B(n,r)))}};if(t.kind===`Bang`)return n.length===0?u(t):V(z(`@[<b2>%a@[<b1>(%a)@]@]`,r(t),B(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 V(z(`@[<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 V(R(a.name));if(a.fixity===`Nonfix`)return V(z(`@[<b2>%s@[<b1>(%a)@]@]`,a.name,B(n,r)));if(a.fixity===`Prefix`&&n.length===1)return o(/[A-Za-z]$/.test(a.name)?z(`%s@ `,a.name):R(a.name),{kind:`Prefix`,operand:u(n[0])});if(a.fixity===`Postfix`&&n.length===1)return o(R(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===`..`?R(a.name):z(`@ %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 V([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(z(`@[<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 V(z(`TRUE`));if(t.bullet===`Refs`&&t.items.length===1)return u(t.items[0]);let e=t.bullet===`Or`?`\\/`:`/\\`;return Sn(z(`@[<v0>%a@]`,B(t.items,t=>z(`@[<h>%s %a@]`,e,r(t)),z(`@,`))))}case`Let`:{let e=B(t.definitions,d,z(`@,`)),i=r(t.body);return un(n,t.definitions.length),Sn([z(`@[<hv0>LET @[<v0>`),e,z(`@]@
19
+ IN %a@]`,i)])}case`Quant`:return a(t.bounds,e=>Sn(z(`@[<b3>%s @[<b0>%a@] :@ %a@]`,t.quantifier===`Forall`?`\\A`:`\\E`,e,r(t.body))));case`Tquant`:return dn(n,t.names,e=>Sn(z(`@[<b4>%s @[<b0>%a@] : %a@]`,t.quantifier===`Forall`?`\\AA`:`\\EE`,B(e,R),r(t.body))));case`Choose`:{let e=t.domain&&r(t.domain);return dn(n,[t.name],([n])=>Sn(e?z(`@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]`,n,e,r(t.body)):z(`@[<b2>CHOOSE %s :@ %a@]`,n,r(t.body))))}case`SetSt`:{let e=r(t.domain);return dn(n,[t.name],([n])=>V(z(`@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]`,n,e,r(t.body))))}case`SetOf`:return a(t.bounds,e=>V(z(`@[<b3>{%a :@ %a}@]`,r(t.element),e)));case`SetEnum`:return V(z(`@[<h>{@[<b0>%a@]}@]`,B(t.elements,r)));case`Arrow`:return V(z(`@[<b3>[%a ->@ %a]@]`,r(t.domain),r(t.range)));case`Fcn`:return a(t.bounds,e=>V(z(`@[<b3>[%a |->@ %a]@]`,e,r(t.body))));case`FcnApp`:{let e=u(t.function),n=e.kind===`Atm`;return V(z(`@[<h>%s%a%s@[<b1>[%a]@]@]`,n?``:`(`,xn(e),n?``:`)`,B(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:z(`@ \\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 V(z(`@[<b2><<%a>>@]`,B(t.elements,r)));case`Rect`:case`Record`:{let e=t.kind===`Rect`?`:`:`|->`;return V(z(`@[<b1>[%a]@]`,B(t.fields,t=>z(`@[<h>%s ${e} %a@]`,t.name,r(t.value)))))}case`Except`:return V(z(`@[<b3>[%a EXCEPT@ @[<v0>%a@]]@]`,r(t.function),B(t.specs,e=>z(`!@[<h>%a = %a@]`,e.trail.map(e=>e.kind===`Dot`?z(`.%s`,e.field):z(`[%a]`,r(e.expression))),r(e.value)))));case`Dot`:return{kind:`Op`,name:`.`,doc:z(`.`),low:16,high:16,skeleton:{kind:`Infix`,assoc:`Left`,left:u(t.expression),right:V(R(t.field))}};case`Sub`:case`Tsub`:{let e=t.modal===`Box`,n=t.kind===`Sub`?e?`[`:`<<`:e?`[][`:`<><<`;return V(z(`@[<h>%s@[<b2>%a@]%s%a@]`,n,r(t.action),e?`]_`:`>>_`,r(t.subscript)))}case`Fair`:return Sn(z(`@[<h>%s_%a (%a)@]`,t.fairness===`Weak`?`WF`:`SF`,yn(r(t.subscript)),r(t.action)));case`Case`:return Sn(z(`@[<v2>CASE %a%a@]`,B(t.arms,e=>z(`@[<b2>%a ->@ %a@]`,r(e.condition),r(e.body)),z(`@,[] `)),t.other?z(`@,[] @[<b2>OTHER ->@ %a@]`,r(t.other)):[]));case`String`:return V(z(`"%s"`,t.value));case`Num`:return V(R(t.fraction===``?t.integer:`${t.integer}.${t.fraction}`));case`At`:return V(R(`@`));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 V(z(t,e.label,xn(i)))}let a=B(r,R),o=i.kind===`Atm`?`%s(%a)::%a`:i.kind===`Big`?`%s(%a)::(%a)`:`(%s(%a):: %a)`;return V(z(o,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 z(`@[<b2>%s@[<b1>(%a)@] ==@ %a@]`,a,B(t.params,En),i)}let i=r(t);return z(`@[<b2>%s ==@ %a@]`,ln(n,e.name),i)}case`Instance`:{let t=e.instance,i=dn(n,t.args,e=>({doc:z(`@[<b2>INSTANCE %s%a@]`,t.module,t.substitutions.length===0?[]:z(`@ WITH@ %a`,B(t.substitutions,e=>z(`@[<b2>%s <- %a@]`,e.name,r(e.expression))))),args:e})),a=ln(n,e.name),o=t.args.length===0?R(a):z(`%s (@[<b0>%a@])`,a,B(i.args,R));return z(`@[<b2>%a == %a@]`,o,i.doc)}case`Recursive`:{let t=ln(n,e.name);return z(`@[<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[z(`NEW %s %s%a`,Dn[e.level],i,Tn(e.shape)),t?z(` \\in %a`,t):[]]}case`Flex`:return z(`NEW VARIABLE %s`,ln(n,e.name));case`Defn`:return d(e.definition);case`Fact`:{let t=z(`@[<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,he(r)??``):t.push(f(r));let i=r(e.active);return un(n,e.context.length),t.length===0?i:[z(`@[<v0>ASSUME @[<v0>`),B(t,e=>e),z(`@]@
20
+ PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},kn=(e,t)=>On(e).printExpr(t),An=e=>On().printSequent(e),jn=e=>an(z(`@[<b0>%a@]`,An(e))).trimEnd(),Mn={kind:`At`,isExcept:!1},Nn=e=>({location:e.location,step:e.step,isSuppressed:e.isSuppressed,method:e.method}),Pn=e=>e?.kind===`Named`&&e.isAnonymous,Fn=e=>e?.level??0,In=e=>O({kind:`Internal`,builtin:`TRUE`},e),Ln=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2,Rn=(e,...t)=>an(z(e,...t)),zn=e=>Bn(e).map((e,t)=>{let n=e.domain.kind===`Domain`?F(t,e.domain.expression):void 0;return{kind:`Fresh`,name:e.name,shape:0,level:n?`Constant`:e.level,domain:n,domainVisibility:`Visible`}}),Bn=e=>{let t={kind:`NoDomain`};return e.map(e=>e.domain.kind===`Ditto`?{...e,domain:t}:(t=e.domain,e))},Vn=(e,t)=>t.context.flatMap((n,r)=>n.kind===`Fact`&&n.visibility===`Visible`?[F(e+t.context.length-1-r,n.expression)]:[]),Hn=(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}},Un=(e,t,n,r)=>{let i=Pn(n.step)?`Visible`:`Hidden`,a=t.context.map(e=>e.kind===`Fact`?{...e,visibility:i}:e),o=O({kind:`List`,bullet:`Refs`,items:Vn(2,t)},n),s=Ct(t.context,r);return{context:[...e,...a,{kind:`Fact`,expression:In(n),visibility:`Hidden`,time:r,location:n.location},Hn(n,o,s),{kind:`Fact`,expression:O({kind:`Ix`,index:1},n),visibility:`Hidden`,time:s,location:n.location}],active:F(3,t.active),time:s}},Wn=(e,t,n,r,i,a)=>{let o=e||Pn(i.step)?`Visible`:`Hidden`;return{context:[...t,Hn(i,O(ge(r),i),a),{kind:`Fact`,expression:O({kind:`Ix`,index:1},i),visibility:o,time:a,location:i.location}],active:F(2,n)}},Gn=(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`},Kn=(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)},qn=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`Mem`&&e.args[0]?.kind===`Ix`&&e.args[0].index===0&&I(t,e.args[1]),Jn=(t,n,r,i)=>{let a=!1,o=r,s=[...i];for(let e=i.length-1;e>=0;e--){o=F(-1,o);let t=i[e];t.kind===`Fact`&&I(t.expression,o)?(a=!0,s[e]={...t,visibility:n}):t.kind===`Fresh`&&t.domain&&qn(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},Yn=(e,t)=>{let n=Ee(T(1),t)[1];return n[0].domain.kind===`Ditto`&&e.domain.kind===`Domain`?[{...n[0],domain:{kind:`Domain`,expression:F(1,e.domain.expression)}},...n.slice(1)]:n},Xn=(e,t)=>{if(e.isSuppressed||t.length===0)return{kind:`Obvious`,...Nn(e)};let n=t.map((t,n)=>{let r=F(2*n+2,t);return{kind:`Assert`,sequent:{context:[],active:r},proof:{kind:`By`,usable:{facts:[F(3,r)],defs:[]},isOnly:!1,location:t.location,method:e.method},location:t.location}}),r={kind:`By`,usable:{facts:[O({kind:`Ix`,index:2*t.length+2},e),...t.map((n,r)=>O({kind:`Ix`,index:2*(t.length-r)},e))],defs:[]},isOnly:!0,...Nn(e),method:void 0};return{kind:`Steps`,steps:n,qed:{proof:r,location:r.location},...Nn(e)}},Zn=(e,t,n)=>({sequent:e,location:t.location,kind:n,method:t.method}),Qn={total:0,absent:[],omitted:[]},$n=(e,t)=>({total:e.total+t.total,absent:[...e.absent,...t.absent],omitted:[...e.omitted,...t.omitted]}),er=e=>{switch(e.kind){case`Use`:return{...Qn,total:e.obligations?.length??0};case`Assert`:case`Suffices`:case`Pcase`:case`Pick`:return tr(e.proof);default:return Qn}},tr=e=>e.kind===`Steps`?[...e.steps.map(er),tr(e.qed.proof)].reduce($n):e.kind!==`Omitted`||!e.obligations||!e.location?{...Qn,total:e.obligations?.length??0}:{total:e.obligations.length,absent:e.omission===`Implicit`?[e.location]:[],omitted:e.omission===`Explicit`?[e.location]:[]},nr=(e,t)=>e.kind===`At`&&!e.isExcept?O(Te(t),e):Ue(e,e=>nr(e,t)),rr=(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:[Zn(t,i,{kind:`Main`})]};case`Omitted`:return{...i,obligations:[Zn(t,i,{kind:`Omitted`,omission:i.omission})]};case`Error`:return{...i,obligations:[Zn(t,i,{kind:`Error`,message:i.message})]};case`By`:throw new e(`Proof.Gen.generate`);case`Steps`:{let[e,n]=M({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=Zn({...t,active:e},n,{kind:`Support`});return[{context:[...t.context,{kind:`Fact`,expression:e,visibility:`Visible`,time:Gn(t.context,e,r),location:e.location,useLocation:n.useLocation}],active:F(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)=>Kn(`Visible`,e,t),t.context);return[{...t,context:a},n,r]}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>Kn(`Hidden`,e,t),t.context),a=n.usable.facts.reduceRight((e,t)=>Jn(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:F(n.definitions.length,t.active)},n,r];case`Assert`:{let e=Un(t.context,n.sequent,n,r),i=a(e,n.proof,e.time),o={...n,proof:i};return[Wn(!1,t.context,t.active,n.sequent,o,r),o,r]}case`Suffices`:{let e=a(Wn(!0,t.context,t.active,n.sequent,n,r),n.proof,r),i={...n,proof:e},o=Un(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:{...Mn,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=>F(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=F(r.index,i.definition.body);if(n.kind!==`Apply`)return m(t,a);let o={...a,location:n.location};return m(t,O(we(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=>k(`Prime`,[e],e);return e.kind===`Quant`?O({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):Ln(e,`Implies`)||Ln(e,`Mem`)?O({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=nr(e.sequent.active,F(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:[F(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=Fn(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,a]=M({context:e,goal:t,time:r},i.steps,(e,t)=>{let[n,r,i,a]=v(e.context,e.goal,t,e.time);return[{context:n,goal:r,time:a},i]}),o=_(n.context,n.goal,i.qed.proof,n.time);return{...i,steps:a.flat(),qed:{...i.qed,proof:o}}}}},v=(t,n,r,i)=>{let a=Fn(r.step);switch(r.kind){case`Forget`:return[t,n,[r],i];case`Assert`:{let e=Un(t,r.sequent,r,i),a={...r,proof:_(e.context,e.active,r.proof,e.time)},o=Wn(!1,t,n,r.sequent,a,i);return[o.context,o.active,[a],i]}case`Suffices`:{let e=Wn(!0,t,n,r.sequent,r,i),a={...r,proof:_(e.context,e.active,r.proof,i)},o=Un(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:Mn,visibility:`Visible`,time:i,location:r.location}));return[[...t,...s],F(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}))],F(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=Ln(e,`Implies`),c={context:[o],active:s?F(1,e.args[1]):e},l=s?{kind:`By`,usable:{facts:[O({kind:`Ix`,index:2},r)],defs:[]},isOnly:!0,...Nn(r)}:{kind:`Error`,message:Rn(`@.@[<v2>@[%s@ %s@]@,%a@]@.`,`Error: this HAVE step is applied to the following goal,`,`which is not an implication:`,kn(t,n)),...Nn(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:F(1,n)},proof:r.proof,...Nn(r)};return v(t,n,p(a,e),i)}case`Pick`:{let a=O({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,...Nn(r),step:o},i),d=F(2,a);if(d.kind!==`Quant`)throw new e(`Proof.Simplify.simplify_step/PICK`);let f=[...zn(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:F(f.length,c)},proof:{kind:`Omitted`,omission:`Elsewhere`,...Nn(r)},...Nn(r)},u);return[p,m,[...l,...h],g]}}},y=(e,n)=>({kind:`Named`,level:Fn(e),label:`${e?.kind===`Named`?e.label:`_a`}${n}${Tt(t)}`,isAnonymous:!1}),b=(e,t,n)=>{let r=Bn(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 Rn(`@.@[<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=Bn(s.bounds).slice(1),u=o.domain,d=c.domain;if(u.kind===`NoDomain`&&d.kind===`Domain`)return Rn(`@.@[<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 Rn(`@.@[<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`&&!I(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=>Ee(T(t),[e])[1][0]):l;return i(t+1,f,O({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:In(t),visibility:`Visible`,time:`Now`,location:n.location}],active:t},proof:{kind:`Error`,message:a,...Nn(n)},...Nn(n)};let o=a.aux.filter((e,t)=>a.aux.findIndex(t=>I(e,t))===t),s=[O({kind:`Ix`,index:2},n),...o.map(e=>F(2,e))];return{kind:`Suffices`,sequent:{context:zn(r),active:a.goal},proof:{kind:`By`,usable:{facts:s,defs:[]},isOnly:!0,...Nn(n)},...Nn(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||=Rn(`@.@[<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:O({kind:`Quant`,quantifier:`Exists`,bounds:Yn(o,s),body:n.body},n),l=t;if(o.domain.kind===`Domain`){let n=o.domain.expression,a=m(e,t);if(Ln(a,`Mem`)){let[e,t]=a.args,i=I(t,n)?[]:[k(`Subseteq`,[t,n],t)];r.push(...i,a),l=e}else i||=Rn(`@.@[<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=k(`Unprimable`,[l],l);a=P(E(u,T(0)),c)}let o=i===``?Xn(n,r):{kind:`Error`,message:i,...Nn(n)};return{kind:`Suffices`,sequent:{context:[],active:a},proof:o,...Nn(n)}};return{generate:a,collect:l,mutate:c,simplify:_}},ir=(e,t=0)=>({level:e,weights:Array.from({length:t},()=>!0),params:/* @__PURE__ */ new Set}),ar={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]},or={Constant:0,State:1,Action:2,Temporal:3,Unknown:0},sr=e=>new Set(e.flatMap(e=>[...e])),cr=e=>({level:Math.max(0,...e.map(e=>e.level)),weights:[],params:sr(e.map(e=>e.params))}),lr=/* @__PURE__ */ new WeakMap,ur=e=>{let t=e.hyp;switch(t.kind){case`Flex`:return ir(1);case`Fresh`:return{...ir(or[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 mr(e.rest,n.body)}case`Fact`:return mr(e.rest,t.expression)}},dr=e=>{let t=lr.get(e);if(t)return t;let n=ur(e);return lr.set(e,n),n},fr=(e,t,n)=>{let r=t.flatMap(t=>t.domain.kind===`Domain`?[mr(e,t.domain.expression)]:[]),i=t.reduce((e,t)=>A(e,N(t.name,t.level)),e);return cr([mr(i,n),...r])},pr=(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:sr([t.params,...r.map(e=>e.params)])}},mr=(e,t)=>{let n=t=>mr(e,t);switch(t.kind){case`Ix`:{let n=ye(e,t.index-1);if(!n)throw new r;return dr(n)}case`Internal`:{let e=ar[t.builtin];if(!e)throw new r;return ir(e[0],e[1])}case`Opaque`:case`String`:case`Num`:return ir(0);case`Lambda`:{let n=t.params.reduce((e,t)=>A(e,N(t.name,`Unknown`,t.shape)),e),r=mr(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 pr(ir(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 ir(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),ir(2)):e.kind===`Internal`&&e.builtin===`Leadsto`?(t.args.forEach(n),ir(3,2)):pr(n(e),t.args.map(n))}case`Sequent`:{let[n,r]=M(e,t.sequent.context,(e,t)=>{let n=A(e,t);return[n,dr(n).level]});return ir(Math.max(0,...r,mr(n,t.sequent.active).level))}case`With`:case`Dot`:case`Parens`:return n(t.expression);case`Let`:{let n=t.definitions.reduce((e,t)=>A(e,{kind:`Defn`,definition:t,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),e);return mr(n,t.body)}case`If`:return cr([t.condition,t.consequent,t.alternative].map(n));case`List`:return cr(t.items.map(n));case`Quant`:case`Fcn`:return fr(e,t.bounds,t.body);case`SetOf`:return fr(e,t.bounds,t.element);case`Tquant`:return mr(t.names.reduce((e,t)=>A(e,{kind:`Flex`,name:t}),e),t.body),ir(3);case`Choose`:case`SetSt`:{let r=t.domain&&n(t.domain),i=t.domain?xe(t.name,t.domain):N(t.name,`Constant`);return cr([mr(A(e,i),t.body),...r?[r]:[]])}case`SetEnum`:case`Tuple`:return cr(t.elements.map(n));case`Product`:return cr(t.factors.map(n));case`FcnApp`:return cr([t.function,...t.args].map(n));case`Arrow`:return cr([n(t.domain),n(t.range)]);case`Rect`:case`Record`:return cr(t.fields.map(e=>n(e.value)));case`Except`:return cr([n(t.function),...t.specs.flatMap(e=>[...e.trail.flatMap(e=>e.kind===`Apply`?[n(e.expression)]:[]),n(e.value)])]);case`Sub`:return{...cr([n(t.action),n(t.subscript)]),level:2};case`Tsub`:case`Fair`:return n(t.action),n(t.subscript),ir(3);case`Case`:return cr([...t.arms.flatMap(e=>[n(e.condition),n(e.body)]),...t.other?[n(t.other)]:[]]);case`Bang`:case`At`:throw new r}},hr=`EnabledWrapper`,gr=`CdotWrapper`,_r="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`.",vr="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.",yr=`${vr} For example, writing \`BY ExpandCdot\`.`,br=e=>e?fe(e):`<unknown location>`,xr=(e,t)=>L(void 0,e,(e,n)=>t(n),()=>void 0),Sr=(e,t)=>{let n=ye(e,t-1)?.hyp;if(!n)throw new r;return n},Cr=e=>e.kind===`Internal`&&(e.builtin===`ENABLED`||e.builtin===`Cdot`),wr=e=>e.kind===`Opaque`&&(e.name===hr||e.name===gr),Tr=e=>e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`Lambda`&&(Cr(e.operator)||wr(e.operator)),Er=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t,Dr=e=>e===void 0?2:Math.min(2,e),Or=e=>e===void 0?void 0:Math.max(1,e-1),kr=(t,n,i,a,o)=>{let c=(e,r=o)=>kr(t,n,i,e,r);if(Tr(a))return a;if(a.kind===`Sub`)return{...a,action:c(a.action),subscript:c(a.subscript,Or(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){if(o!==void 0&&!t.isCdot)throw n(C(a.location,`${vr}For example, writing \`BY ExpandCdot\`.`)),new s(`Expr.Action`);return{...a,args:t.isCdot?[c(r,Dr(o)),c(i,1)]:[c(r),c(i)]}}if(e===`ENABLED`&&a.args.length===1){if(o!==void 0&&!t.isEnabled)throw n(C(a.location,_r)),new s(`Expr.Action`);return{...a,args:[t.isEnabled?c(r,Dr(o)):c(r)]}}if((e===`Prime`||e===`UNCHANGED`)&&a.args.length===1)return{...a,args:[c(r,Or(o))]}}let l=a.kind===`Apply`&&a.operator.kind===`Ix`?a.operator:a;if(l.kind!==`Ix`)return L(i,a,(e,r)=>kr(t,n,e,r,o),A);if(o===void 0)return a;let u=mr(i,a).level,d=Sr(i,l.index),f=e=>`The operator \`${e}\` is declared at:\n${br(d.location)}`;if(d.kind===`Fresh`&&d.level===`Unknown`)throw n(C(a.location,`Declared operator \`${d.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 ${u}.\n May need expansion. A declared operator cannot be expanded.\n${f(d.name)}\n and has arity: ${d.shape}`)),new r(`File "src/expr/e_action.ml", line 367, characters 20-26: Assertion failed`);if(u<o)return a;if(u>2||d.kind===`Fact`)throw new r;if(d.kind===`Flex`){if(a.kind!==`Ix`)throw new r;return a}if(d.kind===`Fresh`){let t=`The expression that results from applying the declared operator \`${d.name}\` has expression level ${u} within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${o}. A declared operator cannot be expanded.\n${f(d.name)}\n and has level: ${or[d.level]}\n and arity: ${d.shape}`;throw n(C(a.location,t)),new e(t)}let p=d.definition;if(p.kind!==`Operator`&&p.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=p.body.kind===`Lambda`?p.body.body:p.body,i=`Hidden definition of operator \`${p.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 \`${p.name}\` is defined at: \n\t${br(r.location)}\nand the operator \`${p.name}\` occurs at: \n\t${br(a.location)}\nUsing the proof directive \`AutoUSE\` from the module \`TLAPS\`, or \`BY DEF ${p.name}\` is expected to avoid this error.\n`;throw n(C(a.location,i)),new s(i)}n({text:`${pe(a.location)}[INFO]: Auto-expanding the definition of operator: ${p.name}\n`,channel:`stdout`});let m=P(T(l.index),p.body);return c(Te(a.kind===`Apply`?we(m,a.args):m))},Ar=e=>k(`Eq`,[k(`Prime`,[e],e),e],e),jr=e=>{let t=e=>e.kind===`Tuple`?e.elements.flatMap(t):[e],n=t(e);return n.length===0?O({kind:`Internal`,builtin:`TRUE`},e):n.length===1?Ar(n[0]):O({kind:`List`,bullet:`And`,items:n.map(Ar)},e)},Mr=e=>{if(e.kind===`Apply`&&e.args.length===1)return jr(e.args[0]);if(e.kind!==`Sub`)throw new r;let t=jr(e.subscript),n=e.modal===`Box`?t:k(`Neg`,[t],e);return k(e.modal===`Box`?`Disj`:`Conj`,[e.action,n],e)},Nr=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},Pr=e=>{let t=Array.from({length:16},()=>[]);return e.forEach((e,n)=>{if(t[Nr(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[Nr(e)&r.length-1].push(e)),t=r}),t.flat()},Fr=(e,t,n,i,a,o)=>{let c=r=>Fr(e,t,n,i,a,r),l=n!==void 0||i!==void 0,u=(r,s)=>{let c={names:[],depth:Math.max(n?.depth??0,i?.depth??0)+1},[l,u]=s,d=[Fr(e,t,n,c,a,l),...u?[Fr(e,t,c,i,a,u)]:[]],f=c.names.length===0?[`r#0`]:Pr(c.names);return O({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(Tr(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 u(o.operator,o.args);if(n===`ENABLED`&&l)throw t(C(o.location,_r)),new s(`Expr.Action`);if(n===`Cdot`&&l)throw t(C(o.location,yr)),new s(`Expr.Action`);if(n===`Prime`&&o.args.length===1){let n=Fr(e,t,i,void 0,a,o.args[0]);return i?n:{...o,args:[n]}}if(n===`UNCHANGED`&&l)return c(Mr(o))}if(o.kind===`Sub`&&l)return c(Mr(o));if(o.kind===`Ix`){if(!n)return o;let e=Sr(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),O({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 L(a,o,(r,a)=>Fr(e,t,n,i,r,a),A)},Ir=(e,t)=>{if(t.kind===`Apply`&&Cr(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=Ir({kind:`Compose`,outer:e,inner:T(a.length)},n.body);return{kind:`Apply`,operator:t.operator,args:[{kind:`Lambda`,params:a,body:o}]}}return t.kind===`Ix`?P(e,t):t.kind===`Apply`?O(we(Ir(e,t.operator),t.args.map(t=>Ir(e,t))),t):L(e,t,Ir,e=>D(1,e))},Lr=(e,t)=>{if(t.kind===`Apply`&&Cr(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`?gr:hr;return{kind:`Apply`,operator:O({kind:`Opaque`,name:i},t.operator),args:[{kind:`Lambda`,params:n.params.map((t,n)=>({name:e?t.name:`r#${n}`,shape:0})),body:Lr(e,n.body)}]}}return xr(t,t=>Lr(e,t))},Rr=e=>{if(Er(e,`Cdot`)&&e.args.length===1&&e.args[0].kind!==`Lambda`)throw new r;return xr(e,Rr)},zr=(e,t,n,r,i,a)=>{let o=Fr(i,t,void 0,void 0,n,r);return Lr(a,e.expr(n,Ir(T(0),o)))},Br={isEnabled:!0,isCdot:!0,isAutoUse:!0},Vr=(e,t,n,r,i=Br)=>{let a=kr(i,t,n,r,void 0);return Rr(zr(e,t,n,a,i,!1))},Hr=(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:Hr(e,t,j(n,r.map(e=>N(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===hr||e.isCdot&&i.name===gr))return a(s.params,s.body);if(i.kind===`Ix`&&(e.isEnabled||e.isCdot)){let e=Sr(n,i.index);if(e.kind===`Defn`&&e.definition.kind===`Operator`&&(e.definition.name===hr||e.definition.name===gr))return a(s.params,s.body)}if(Cr(i)&&o(i.builtin))return a(s.params,s.body)}if(Cr(i)&&o(i.builtin))return Hr(e,t,n,s,!0)}if(Er(r,`ENABLED`)&&i)throw t(C(r.location,_r)),new s(`Expr.Action`);if(Er(r,`Cdot`)&&i)throw t(C(r.location,yr)),new s(`Expr.Action`);return L(n,r,(n,r)=>Hr(e,t,n,r,i),A)},Ur=e=>{if(e.kind===`Quant`&&e.quantifier===`Exists`){let t=e.body;if(t.kind===`List`&&t.bullet===`Or`)return Ur({...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 Ur({...t,args:t.args.map(t=>({...e,body:t}))})}}return xr(e,Ur)},Wr=(e,t,n,r,i)=>{let a=kr(i,t,n,r,void 0),o=zr(e,t,n,a,i,!0);return Ur(Hr(i,t,n,o,!1))},Gr=(e,t)=>({kind:`Definition`,definition:{kind:`Operator`,name:e,body:{kind:`Internal`,builtin:t}},whereDefined:`Builtin`,visibility:`Visible`,isLocal:!1}),H=(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}),Kr=[Gr(`Nat`,`Nat`),H(2,`+`,`Plus`),H(2,`-`,`Minus`),H(2,`*`,`Times`),H(2,`^`,`Exp`),H(2,`<`,`Lt`),H(2,`>`,`Gt`),H(2,`=<`,`Lteq`),H(2,`>=`,`Gteq`),H(2,`%`,`Remainder`),H(2,`\\div`,`Quotient`),H(2,`..`,`Range`)],qr=[...Kr,Gr(`Int`,`Int`),H(1,`-.`,`Uminus`)],Jr=[...qr,Gr(`Real`,`Real`),H(2,`/`,`Ratio`),Gr(`Infinity`,`Infinity`)],Yr=[H(1,`Seq`,`Seq`),H(1,`Len`,`Len`),H(2,`BSeq`,`BSeq`),H(2,`\\o`,`Cat`),H(2,`Append`,`Append`),H(1,`Head`,`Head`),H(1,`Tail`,`Tail`),H(3,`SubSeq`,`SubSeq`),H(2,`SelectSeq`,`SelectSeq`)],Xr=[H(2,`Print`,`Print`),H(1,`PrintT`,`PrintT`),H(2,`Assert`,`Assert`),Gr(`JavaTime`,`JavaTime`),H(1,`TLCGet`,`TLCGet`),H(2,`TLCSet`,`TLCSet`),H(2,`:>`,`OneArg`),H(2,`@@`,`Extend`),H(1,`Permutations`,`Permutations`),H(2,`SortSeq`,`SortSeq`),H(1,`RandomElement`,`RandomElement`),Gr(`Any`,`Any`),H(1,`ToString`,`ToString`)],Zr=(e,t)=>({name:e,extendees:[],body:t,isImportant:!1,isStandard:!0}),Qr=new Map([Zr(`Naturals`,Kr),Zr(`Integers`,qr),Zr(`Reals`,Jr),Zr(`Sequences`,Yr),Zr(`TLC`,Xr)].map(e=>[e.name,e])),$r=e=>{let t=e.location;switch(e.kind){case`Constants`:return e.declarations.map(e=>({kind:`Fresh`,name:e.name,shape:e.shape,level:`Constant`,domain:void 0,domainVisibility:`Visible`,location:t}));case`Recursives`:return e.declarations.map(e=>({kind:`Defn`,definition:{kind:`Recursive`,name:e.name,shape:e.shape,location:t},whereDefined:`User`,visibility:`Hidden`,isLocal:!1,location:t}));case`Variables`:return e.names.map(e=>({kind:`Flex`,name:e,location:t}));case`Definition`:return[{kind:`Defn`,definition:e.definition,whereDefined:e.whereDefined,visibility:e.visibility,isLocal:e.isLocal,location:t}];case`Axiom`:case`Theorem`:{let n=e.kind===`Axiom`?e.expression:O(ge(ke(T(-e.axiomCount),{...e.sequent,context:e.sequent.context.slice(e.axiomCount)})),e);return e.name===void 0?[{kind:`Fact`,expression:n,visibility:`Hidden`,time:`Always`,location:t}]:ti(e.name,n,t)}case`Mutate`:return e.mode===`Use`?e.usable.facts.map((e,n)=>({kind:`Fact`,expression:F(n,e),visibility:`Visible`,time:`Always`,location:t})):[];case`Submod`:case`Anoninst`:return[]}},ei=e=>e.kind===`Axiom`||e.kind===`Theorem`?e.name===void 0?1:2:$r(e).length,ti=(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}],ni=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:ni(e.module)}}];default:return[e]}}),ri=(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(...ni(ri(t,n,i,/* @__PURE__ */ new Set([...a,s])))),i.add(s)}return{...n,body:[...o,...n.body].map(e=>e.kind===`Submod`?{...e,module:ri(t,e.module,/* @__PURE__ */ new Set)}:e)}},ii=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&&ai(e.instance)&&n(e.instance.module,e.instance.location),Object.values(e).forEach(o))},s=e=>{e.kind===`Submod`?(i.add(e.module.name),a.set(e.module.name,e.module),r(e.module),e.module.body.forEach(s)):o(e.kind===`Theorem`?e.sequent:e)};return e.body.forEach(s),i.forEach(e=>t.delete(e)),r(e),{dependencies:[...t.keys()].sort(oi),locations:t,submodules:a}},ai=e=>typeof e==`object`&&!!e&&`module`in e&&typeof e.module==`string`&&`substitutions`in e,oi=(e,t)=>e<t?-1:+(e>t),si=(t,n)=>({facts:Ce(t,n.facts),defs:n.defs.map(n=>{if(n.kind===`Dvar`)return n;let r=P(t,{kind:`Ix`,index:n.index});if(r.kind!==`Ix`)throw new e(`substitution produced bad definition`);return{...n,index:r.index}})}),ci=(e,t)=>{switch(t.kind){case`Constants`:case`Recursives`:return[D(t.declarations.length,e),t];case`Variables`:return[D(t.names.length,e),t];case`Definition`:return[D(1,e),{...t,definition:De(e,t.definition)}];case`Axiom`:return[D(ei(t),e),{...t,expression:P(e,t.expression)}];case`Theorem`:return[D(ei(t),e),{...t,sequent:ke(e,t.sequent)}];case`Submod`:return[e,{...t,module:{...t.module,body:li(e,t.module.body)}}];case`Mutate`:return[t.mode===`Hide`?e:D(t.usable.facts.length,e),{...t,usable:si(e,t.usable)}];case`Anoninst`:return[e,{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(t=>({name:t.name,expression:P(e,t.expression)}))}}]}},li=(e,t)=>M(e,t,ci)[1],ui=(t,n,i,a)=>{try{let e=Vr(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:O({kind:`Internal`,builtin:`TRUE`},a.active)}}},di=(e,t,n)=>{if(n.kind===`Theorem`)return{...n,sequent:ui(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=Vr(e.anonymizer,e.onWarning,t,r.body);return{...n,definition:{...r,body:i}}},fi=(e,t,n)=>M(t,n,(t,n)=>{if(n.kind===`Submod`){let[r,i]=fi(e,t,n.module.body);return[r,{...n,module:{...n.module,body:i}}]}let r=di(e,t,n);return[j(t,$r(r)),r]}),pi=(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=ei(s.remaining)===0;a=li(E(F(i,t),T(0)),r?o:[s.remaining,...o])}else r.push(t),i+=ei(t),a=o}return r},mi=(e,t,n)=>{let r=Array.from({length:t},(e,r)=>O({kind:`Ix`,index:t-r},{location:n})),i=Array.from({length:t},(e,t)=>O({kind:`Ix`,index:t+1},{location:n})),a=Array.from({length:e},(e,i)=>{let a=O({kind:`Ix`,index:i+t+1},{location:n});return t>0?O({kind:`Apply`,operator:a,args:r},{location:n}):a});return me([...a,...i].reverse(),T(e+t))},hi=(e,t)=>{let n=t.map(e=>({name:e,shape:0}));return e.kind===`Lambda`?{...e,params:[...n,...e.params]}:t.length===0?e:O({kind:`Lambda`,params:n,body:e},e)},gi=(t,n,r,i,a,o)=>{let s=e=>r===``?e:`${r}!${e}`,c=i.args.length,l=[],u=0,d=n,f=c===0,p=e=>{f||(f=!0,t.onWarning({text:e,channel:`stderr`}))};for(;d.length>0;){let[n,...r]=d;d=r;let f=e=>hi(P(mi(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(`${w(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+=ei(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(O(ge(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=li(T(-n.usable.facts.length),d));continue;case`Submod`:continue;default:throw new e(`Module.Elab.localize`)}}return l},_i=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?F(1,e.expression):O({kind:`Ix`,index:2},e),visibility:`Visible`,time:`Always`,location:i},o=0,s=r.map(e=>{let t=o;if(o+=ei(e),e.kind!==`Theorem`)return e;let n=ke(T(1),e.sequent);return{...e,sequent:{...n,context:[Oe(T(t),a),...n.context]},axiomCount:e.axiomCount+1}});n=li(T(-1),s)}return t},vi=e=>new Set(e.body.flatMap(e=>e.kind===`Constants`?e.declarations.map(e=>e.name):e.kind===`Variables`?e.names:[])),yi=(t,n,r,i,a,o,s)=>{let c=n.get(i.module);if(!c)throw new e(`Module "${i.module}" unknown`);let l=vi(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=j(r,i.args.map(e=>N(e,`Unknown`))),d=new Map(i.substitutions.map(e=>[e.name,e.expression]));for(let t of[...l].sort(oi))if(!d.has(t)){if(!ve(u,t))throw new e(`Required parameter ${t} for module ${i.module} could not be inferred.`);d.set(t,O({kind:`Opaque`,name:t},{location:s}))}let f=new Map([...d].map(([e,n])=>[e,t.anonymizer.expr(u,n)])),p=li(T((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]=fi(t,u,p);return _i(gi(t,pi(m,f),o,i,a,s))},bi=(e,t,n)=>e===void 0?{hyps:[],sequent:t}:{hyps:[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:O(ge(t),{location:n}),location:n},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:n}],sequent:ke(T(1),t)},xi=(t,n,r)=>{let i=r.instance.module;if(!t.latestModules.has(i))throw t.onWarning({text:`${w(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=yi(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=li(T(-ei(e)),t)}return o},Si=(e,t,n,r)=>{let i=[],a=n,o=e=>{i.push(e),a=j(a,$r(e))},s=e=>e!==void 0&&ve(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=yi(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=$r(s)[0],d=ve(a,t.name);if(d?.hyp.kind===`Defn`&&(d.hyp.definition.kind===`Recursive`||Ie(Oe(T(d.depth+1),d.hyp),u))){let e=c.slice(n+1),t=li(E(O({kind:`Ix`,index:d.depth+1},i),T(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=bi(c,u,i.location),f=j(j(a,d.hyps.map(e=>({...e,isConstnessUnset:!0}))),d.sequent.context),p=e.anonymizer.proof(f,l),m=r.isImportant?e.generator.simplify(_e(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:Si(e,t,a,i.module)});continue}}let l={...r,body:i,depth:n?.size??0};return t.set(r.name,l),l},Ci=(e,t,n)=>{let r=[],i=[],a=Qn,o=t;for(let t of n.body)switch(t.kind){case`Theorem`:{let n=bi(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=tr(l);i.push({...u,location:t.location}),a=$n(a,u);let d=t.name===void 0?O(ge(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=Ci(e,o,t.module);r.push(...n.obligations),a=$n(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,...$r(t)]}return{obligations:r,summary:{...a,theorems:i}}},wi=[`(`,`)`,`;`,`:`,`@`,`,`],Ti=e=>e===` `||e===`\r`||e===` `,Ei=(e,t)=>{let n={...t},r=()=>{for(;n.line<e.length;){let t=e[n.line];for(;Ti(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(!wi.includes(t[0]))return;i.push({kind:`Punct`,text:t[0]}),n.column++}}},Di=(e,t)=>e?.kind===`Punct`&&e.text===t,Oi=e=>e?.kind===`String`?{kind:`String`,value:e.text}:e?.kind===`Number`?{kind:`Float`,value:Number.parseFloat(e.text)}:Di(e,`@`)?{kind:`Default`}:void 0,ki=/* @__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`]]),Ai=(e,t)=>{let n=Ei(e,t);if(!n)return;let r=0,i=()=>{let e=n[r];return e?.kind===`Number`?(r++,{timeout:Number.parseFloat(e.text)}):{}},a=()=>{if(!Di(n[r],`(`))return;r++;let e=n[r++];if(e?.kind!==`Ident`)return;let t=(()=>{if(e.text===`isabelle`){let t=n[r];return t?.kind===`String`?(r++,{name:e.text,tactic:t.text,...i()}):void 0}if(e.text===`zenon`){let t=i();return Di(n[r],`(`)&&!a()?void 0:{name:e.text,...t}}let t=ki.get(e.text);return t===void 0?void 0:{name:t}})();if(t&&Di(n[r],`)`))return r++,t};if(n[r]?.kind!==`Ident`||n[r++].text!==`by`)return;let o=a();return r===n.length?o:void 0},ji=(e,t)=>{let n=Ei(e,t);if(!n)return;let r=0,i=[];for(;r<n.length;){let e=n[r++];if(e.kind!==`Ident`||e.text!==`by`&&e.text!==`set`||!Di(n[r],`(`))return;r++;let t=[];for(;;){let e=n[r++];if(e?.kind!==`Ident`||!Di(n[r],`:`))return;r++;let i=Oi(n[r++]);if(!i)return;if(t.push({hint:e.text,value:i}),Di(n[r],`)`))break;if(!Di(n[r],`;`))return;r++}r++,i.push(t)}return i},Mi=e=>({kind:`Opaque`,name:e}),Ni=e=>({kind:`Tuple`,elements:e.map(Mi)}),Pi=(e,t)=>({kind:`Apply`,operator:{kind:`Internal`,builtin:`Eq`},args:[e,t]}),Fi=e=>e.map(e=>({name:e,level:`Constant`,domain:{kind:`NoDomain`}})),Ii=(e,t)=>e?.kind===`Product`&&e.factors.length===t.length?e.factors:void 0,Li=(e,t)=>t.map((t,n)=>({kind:`Operator`,name:t,body:{kind:`FcnApp`,function:Mi(e),args:[{kind:`Num`,integer:String(n+1),fraction:``}]}})),Ri=(e,t)=>e.map((e,n)=>({name:e,level:`Constant`,domain:{kind:`Domain`,expression:t[n]}})),zi=e=>({name:e.name,level:`Constant`,domain:e.domain}),Bi=(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`?[zi(e)]:[]),body:t,location:t.location};let i=Ii(r.domain,r.names);if(i)return{kind:`Quant`,quantifier:e,bounds:Ri(r.names,i),body:t,location:t.location};let a={kind:`Apply`,operator:{kind:`Internal`,builtin:e===`Exists`?`Mem`:`Notmem`},args:[Ni(r.names),r.domain]};return{kind:`Quant`,quantifier:e,bounds:Fi(r.names),body:{kind:`List`,bullet:e===`Exists`?`And`:`Or`,items:[a,t]},location:t.location}},n)},Vi=(e,t,n,r)=>Ii(n,t)?{kind:`Let`,definitions:Li(e,t),body:r}:{kind:`Quant`,quantifier:`Exists`,bounds:Fi(t),body:{kind:`List`,bullet:`And`,items:[Pi(Mi(e),Ni(t)),r]}},Hi=(e,t,n)=>{let r=`choose#${e[0]}`;return{kind:`Choose`,name:r,domain:t,body:Vi(r,e,t,n)}},Ui=(e,t,n)=>{let r=`setst#${e[0]}`;return{kind:`SetSt`,name:r,domain:t,body:Vi(r,e,t,n)}},Wi=(e,t,n)=>{let r=e.map(e=>{if(e.kind===`Name`)return{bounds:[zi(e)],definitions:[]};let t=Ii(e.domain,e.names);if(t&&n)return{bounds:Ri(e.names,t),definitions:[]};let r=`fcn#${e.names[0]}`,i={name:r,level:`Constant`,domain:{kind:`Domain`,expression:e.domain}};if(t)return{bounds:[i],definitions:Li(r,e.names)};let a=`choose#${r}`;return{bounds:[i],definitions:[{kind:`Operator`,name:a,body:Hi(e.names,void 0,Pi(Mi(r),Ni(e.names)))},...Li(a,e.names)]}}),i=r.flatMap(e=>e.definitions);return{bounds:r.flatMap(e=>e.bounds),value:i.length===0?t:{kind:`Let`,definitions:i,body:t}}},Gi=(e,t)=>{let n=Wi(t,e,!0);return{kind:`SetOf`,element:n.value,bounds:n.bounds}},Ki=(e,t)=>{let n=Wi(e,t,!1);return{kind:`Fcn`,bounds:n.bounds,body:n.value}},qi={"=>":`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`},Ji=e=>hn(e).name,Yi=/^<(\d+|\*|\+)>([A-Za-z0-9_]*)\.*$/,Xi=(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}},Zi={Always:`[]`,Eventually:`<>`,Enabled:`ENABLED`,Unchanged:`UNCHANGED`},Qi=(e,t)=>e!==void 0&&t!==void 0&&e.line===t.line&&e.column===t.column,$i=e=>e.location.range?.start,ea=e=>e.location.range?.end,ta=(e,t)=>{let n=e.location.range;return n&&t?{...e,location:{...e.location,range:{...n,end:t}}}:e},na=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=Zi[e.kind];if(t!==void 0&&`expression`in e)return{operator:hn(t),isInfix:!1,operand:e.expression,replace:t=>({...e,expression:t})}},ra=(e,t)=>e.high<t.low,ia=e=>{let t=hn(e.operator),[n,r]=e.args,i=ea(e),a=t=>{let n=e.location.range,i=$i(t);return{...e,args:[t,r],location:n&&i?{...e.location,range:{...n,start:i}}:e.location}},o=(e,n)=>{let r=n?na(e):void 0;if(!r)return{kind:`Reduced`,isFinal:!1};let s=o(r.operand,Qi(ea(r.operand),ea(e)));return s.kind===`Attached`?{kind:`Attached`,expression:ta(r.replace(s.expression),i)}:!s.isFinal&&(ra(t,r.operator)||r.isInfix&&t.fixity===`InfixLeft`&&r.operator.fixity===`InfixLeft`&&!ra(r.operator,t))?{kind:`Reduced`,isFinal:!ra(t,r.operator)}:{kind:`Attached`,expression:ta(r.replace(a(r.operand)),i)}},s=o(n,Qi($i(n),$i(e)));return s.kind===`Attached`?s.expression:e},aa="use instead the class`E_visit.iter_concrete`",oa=(e,t)=>t>0&&e[t-1].set===e[t].set,sa=(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&&Ai(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?O({kind:`With`,expression:e,method:n},e):e},f=(e,n)=>({file:t,startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+n}),p=e=>e.range?s(e.range):f(e,1),m=(e,t)=>{let n=Ji(e),r=qi[n];return O(r?{kind:`Internal`,builtin:r}:{kind:`Opaque`,name:n},{location:t})},h=(e,t,n,r)=>{if(e.startsWith(`<`)){let t=O({kind:`Opaque`,name:e},{location:n});return O({kind:`Bang`,expression:t,selectors:[]},{location:n})}let i=qi[e];if(i&&t.length===0)return O({kind:`Internal`,builtin:i},{location:n});let a=e.split(`!`);if(a.length===1){let r=O({kind:`Opaque`,name:e},{location:n});return t.length===0?r:O({kind:`Apply`,operator:r,args:t},{location:n})}let o=r??a.map((e,n)=>n===a.length-1?t.length:0),s=o.map((e,t)=>o.slice(0,t).reduce((e,t)=>e+t,0)),c=e=>t.slice(s[e],s[e]+o[e]),l=O({kind:`Opaque`,name:a[0]},{location:n});return O({kind:`Bang`,expression:o[0]===0?l:O({kind:`Apply`,operator:l,args:c(0)},{location:n}),selectors:a.slice(1).map((e,t)=>({kind:`Label`,label:Ji(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:aa});return{name:r.pattern.name,level:`Constant`,domain:oa(t,i)?{kind:`Ditto`}:{kind:`Domain`,expression:b(r.set,n)}}}),_=(e,t)=>e.map((n,r)=>{let i=b(n.set,t);return n.pattern.kind===`Tuple`?{kind:`Tuple`,names:n.pattern.names,domain:i}:{kind:`Name`,name:n.pattern.name,domain:oa(e,r)?{kind:`Ditto`}:{kind:`Domain`,expression:i}}}),v=(t,n)=>{if(!a)throw new e(`Unexpected tuple declaration`,{failure:aa});return O(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?Xi(e[0].location,e[1].location):e.length!==1||!e[0].location?r:t===`Prefix`?Xi({...r,endLine:r.startLine,endColumn:r.startColumn+1},e[0].location):t===`Postfix`?Xi({...r,startLine:r.endLine,startColumn:r.endColumn-1},e[0].location):r,s=(e,t)=>O({kind:`Apply`,operator:{kind:`Internal`,builtin:e},args:[t]},{location:a([t],`Prefix`)});switch(t.kind){case`Number`:return O({kind:`Num`,integer:t.text??String(t.value),fraction:``},{location:r});case`Decimal`:{let[e,n]=t.text.split(`.`);return O({kind:`Num`,integer:e,fraction:n},{location:r})}case`String`:{let e=/"((?:[^"\\]|\\.)*)"$/.exec((o[r.endLine-1]??``).slice(0,r.endColumn-1));return O({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=ia(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):O({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 O({kind:`Lambda`,params:t.params.map(e=>({name:e,shape:0})),body:i(t.body)},{location:r});case`And`:case`Or`:{let e=t.operands.map(i);if(t.isBulleted)return O({kind:`List`,bullet:t.kind,items:e},{location:r});let n=t.kind===`And`?`Conj`:`Disj`;return e.reduce((e,t)=>O({kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:[e,t]},{location:Xi(e.location,t.location)}))}case`Prime`:{let e=i(t.expression);return O({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 O({kind:`If`,condition:i(t.condition),consequent:i(t.consequent),alternative:i(t.alternative)},{location:r});case`Case`:return O({kind:`Case`,arms:t.arms.map(e=>({condition:i(e.condition),body:i(e.body)})),other:t.other&&i(t.other)},{location:r});case`Let`:return O({kind:`Let`,definitions:[...t.definitions,...t.instances??[]].sort((e,t)=>e.location.line-t.location.line||e.location.column-t.location.column).map(e=>te(e,n)),body:i(t.body)},{location:r});case`Forall`:case`Exists`:return y(t.bounds)?v(Bi(t.kind,_(t.bounds,n),i(t.body)),r):O({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?O({kind:`Tquant`,quantifier:n,names:t.names,body:e},{location:r}):O({kind:`Quant`,quantifier:n,bounds:Fi(t.names),body:e},{location:r})}case`Choose`:return t.pattern.kind===`Tuple`?v(Hi(t.pattern.names,t.set&&i(t.set),i(t.body)),r):O({kind:`Choose`,name:t.pattern.name,domain:t.set&&i(t.set),body:i(t.body)},{location:r});case`SetEnumeration`:return O({kind:`SetEnum`,elements:t.elements.map(i)},{location:r});case`SetFilter`:return t.bound.pattern.kind===`Tuple`?v(Ui(t.bound.pattern.names,i(t.bound.set),i(t.predicate)),r):O({kind:`SetSt`,name:t.bound.pattern.name,domain:i(t.bound.set),body:i(t.predicate)},{location:r});case`SetMap`:return y(t.bounds)?v(Gi(i(t.expression),_(t.bounds,n)),r):O({kind:`SetOf`,element:i(t.expression),bounds:g(t.bounds,n)},{location:r});case`Tuple`:return O({kind:`Tuple`,elements:t.elements.map(i)},{location:{...r,startLine:r.endLine,startColumn:r.endColumn-2}});case`FunctionConstruction`:return y(t.bounds)?v(Ki(_(t.bounds,n),i(t.body)),r):O({kind:`Fcn`,bounds:g(t.bounds,n),body:i(t.body)},{location:r});case`FunctionSet`:return O({kind:`Arrow`,domain:i(t.domain),range:i(t.range)},{location:r});case`Record`:case`RecordSet`:return O({kind:t.kind===`Record`?`Record`:`Rect`,fields:t.fields.map(e=>({name:e.name,value:i(e.value)}))},{location:r});case`Except`:return O({kind:`Except`,function:i(t.function),specs:t.updates.map(e=>({trail:e.path.map(e=>e.kind===`Field`?{kind:`Dot`,field:e.name}:{kind:`Apply`,expression:e.args.length===1?i(e.args[0]):{kind:`Tuple`,elements:e.args.map(i)}}),value:b(e.value,!0)}))},{location:r});case`ExceptAt`:return O({kind:`At`,isExcept:n},{location:r});case`Bracket`:throw new e(`Unexpected [ without a function or subscript`);case`FunctionApplication`:return O({kind:`FcnApp`,function:i(t.function),args:t.args.map(i)},{location:r});case`FieldAccess`:return O({kind:`Dot`,expression:i(t.record),field:t.field},{location:r});case`Product`:return O({kind:`Product`,factors:t.factors.map(i)},{location:r});case`Always`:case`Eventually`:{let e=t.expression;return t.kind===`Always`&&e.kind===`BoxAction`?O({kind:`Tsub`,modal:`Box`,action:i(e.action),subscript:i(e.subscript)},{location:r}):t.kind===`Eventually`&&e.kind===`AngleAction`?O({kind:`Tsub`,modal:`Dia`,action:i(e.action),subscript:i(e.subscript)},{location:r}):s(t.kind===`Always`?`BoxTrue`:`Diamond`,i(e))}case`BoxAction`:case`AngleAction`:return O({kind:`Sub`,modal:t.kind===`BoxAction`?`Box`:`Dia`,action:i(t.action),subscript:i(t.subscript)},{location:r});case`WeakFairness`:case`StrongFairness`:return O({kind:`Fair`,fairness:t.kind===`WeakFairness`?`Weak`:`Strong`,subscript:i(t.subscript),action:i(t.action)},{location:r});case`Label`:return O({kind:`Parens`,expression:i(t.body),form:{kind:`Nlabel`,label:t.name,names:t.params}},{location:r});case`Subexpression`:{let[n,...a]=t.selectors;if(n.kind!==`Name`)throw new e(`Unexpected subexpression reference`);let o=O({kind:`Opaque`,name:n.name},{location:r}),s=n.args.length===0?o:O({kind:`Apply`,operator:o,args:n.args.map(i)},{location:r});return O({kind:`Bang`,expression:s,selectors:a.map(e=>{switch(e.kind){case`Name`:return{kind:`Label`,label:Ji(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:Ji(e.name),expression:b(e.expression,!1)}))}),te=(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=t.kind===`Operator`&&t.params.length===1&&t.name===`-`?`-.`:Ji(t.name),a=b(t.body,n);if(t.kind===`Function`&&y(t.bounds))return{kind:`Operator`,name:i,body:v(Ki(_(t.bounds,n),a),r),location:r};if(t.kind===`Function`){let e=g(t.bounds,n);return{kind:`Operator`,name:i,body:O({kind:`Fcn`,bounds:e,body:a},{location:r}),location:r}}let s=t.params.length===0?a:O({kind:`Lambda`,params:t.params.map(e=>({name:Ji(e.name),shape:e.arity,...e.location&&{location:f(e.location,e.name.length)}})),body:a},{location:r}),c=t.location.range?.end,l=c&&ji(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}},ne=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}},re=e=>e.kind===`AssumeProve`?{context:e.assumptions.map(e=>{if(e.kind===`NewSymbol`)return ne(e);let t=e.kind===`AssumeProve`?O({kind:`Sequent`,sequent:re(e)},{location:p(e.location)}):x(e);return{kind:`Fact`,expression:t,visibility:`Visible`,time:`Now`,location:t.location}}),active:b(e.conclusion,!1)}:{context:[],active:b(e,!1)},x=e=>{if(e.kind!==`Label`||e.params.length>0)return b(e,!1);let t=p(e.location);return O({kind:`Parens`,expression:b(e.body,!1),form:{kind:`Xlabel`,label:e.name,indices:[]}},{location:t})},S=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:Ji(e.name),location:t};if(e.kind===`OperatorReference`)return{kind:`Dvar`,name:Ji(e.operator),location:t};throw new i(`This DEF clause in proof obligations is not supported`)},ae=e=>({facts:e.facts.map(S),defs:e.defs.map(ie)}),oe=(e,t)=>e?.[2]?{kind:`Named`,level:t,label:e[2],isAnonymous:!1}:{kind:`Unnamed`,level:t,id:Tt(r)},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=>Yi.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:Xi(l,u.location),step:c};return{kind:`Steps`,steps:a,qed:d,location:a.reduce((e,t)=>Xi(e,t.location),d.location),step:d.step}}}},ce=e=>Xi(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:Xi(a,i.location),step:n}},d=e=>({...e,...u(t.head),step:n});switch(o.kind){case`Use`:case`Hide`:{let e=Xi(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{kind:`Define`,definitions:o.definitions.map(e=>te(e)),location:a,step:n};case`Have`:return d({kind:`Have`,expression:b(o.expression,!1)});case`Take`:return d({kind:`Take`,bounds:o.names.length>0?Fi(o.names):g(o.bounds,!1)});case`Witness`:return d({kind:`Witness`,expressions:o.expressions.map(e=>b(e,!1))});case`Pick`:{let e=o.names.length>0?Fi(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=re(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:Ji(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:te(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:te(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=re(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}},ca={start:0,end:1/0},la=/-{4,} *MODULE/,ua=`Unexpected EOF`,da=e=>e?`${e.startLine}:${e.startColumn}:${e.endLine}:${e.endColumn}`:``,fa=e=>{let t=x(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(la));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:ua,line:c?.line??o,column:c?c.endColumn+1:s,isEnd:!0}}},pa=e=>{try{return e()}catch(e){if(!(e instanceof t)||!e.failure)throw e;return e.failure}},ma=e=>typeof e==`object`&&!!e&&`reason`in e,ha=e=>{let t=pa(()=>fa(e));if(ma(t))return[t];let n=pa(()=>c(t?e.slice(0,t.offset):e));return t&&(!ma(n)||n.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:t.line,column:t.column,isEnd:!1},ma(n)&&n.reason===ua?n:t.end]:ma(n)?[n]:n},ga=(t,n,r,i,a)=>{if(!la.test(t.source))throw new e(`No tokens in file`);let o=ha(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=sa(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:`${w(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},_a=t=>{let n=new Map([...t].map(([e,t])=>[e,ii(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(oi).forEach(a),i},va=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${de(t)}`)],ya=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?de({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...va(`missing`,e.absent,t),...va(`omitted`,e.omitted,n),` ====`]},ba=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...ya(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
+ `)},xa=(t,n,r={})=>{let i=r.lines??ca,a=r.onWarning??(()=>{}),o={value:0},s=new Map(Qr);t.forEach(e=>{let t={...ga(e,o,!0,a,`File "<unknown>":
26
+ `),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>oi(e.name,t.name)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=ii(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)&&!Qr.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=ga(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(oi);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)=>xi(f,e,t),a),generator:rr(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},p=_a(s).map(e=>e.isStandard?e:ri(s,e,/* @__PURE__ */ new Set)),m=new Map(p.map(e=>[e.name,e]));return p.flatMap(e=>{if(e.isStandard)return[];let t=Si(f,m,void 0,e);if(!e.isImportant)return[];let n=Ci(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:`${jn(e.sequent)}\n`;return[{id:t+1,location:da(n),locus:n,text:r,kind:e.kind,sequent:e.sequent,method:e.method}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Sa=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),`error`in n){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}},Ca={"!":`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_`},wa=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(` `)),Ta=e=>/^[A-Za-z]$/.test(e),Ea=e=>{if(/^[A-Za-z0-9]$/.test(e))return;let t=Ca[e];if(t===void 0)throw new r;return t},Da=e=>{let t=[...e];return Ta(t[0]??``)&&Ta(t.at(-1)??``)&&t.every(e=>Ea(e)===void 0)&&!wa.has(e)?e:`a_${t.map(e=>Ea(e)??e).join(``)}a`},Oa=e=>`is${Da(e)}`,ka={TRUE:`TRUE`,FALSE:`FALSE`,STRING:`STRING`,BOOLEAN:`BOOLEAN`,Nat:`Nat`,Int:`Int`,Real:Oa(`Real`),Infinity:Oa(`Infinity`),Any:`Any`},Aa={Neg:`~`,DOMAIN:`DOMAIN`,SUBSET:`SUBSET`,UNION:`UNION`},ja={Implies:`\\<Rightarrow>`,Equiv:`\\<Leftrightarrow>`,Conj:`\\<and>`,Disj:`\\<or>`,Eq:`=`,Neq:`\\<noteq>`,Subseteq:`\\<subseteq>`,Mem:`\\<in>`,Notmem:`\\<notin>`,Setminus:`\\\\`,Cap:`\\<inter>`,Cup:`\\<union>`,OneArg:`:>`,Extend:`@@`},Ma={Plus:[`addint`,2],Minus:[`subint`,2],Uminus:[`minus`,1],Times:[`mult`,2],Ratio:[Oa(`/`),2],Quotient:[Oa(`\\div`),2],Remainder:[Oa(`%`),2],Exp:[Oa(`^`),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:[Oa(`\\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]},Na={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},Pa=[`consts`,...[[`Real`,0],[`/`,2],[`\\div`,2],[`%`,2],[`..`,2],[`Infinity`,0],[`[]`,1],[`<>`,1]].map(e=>` "${Oa(e[0])}" :: ${e[1]===0?`c`:`"[${Array(e[1]).fill(`c`).join(`,`)}] => c"`}`),``].join(`
27
+ `),Fa=e=>{let t=Number.parseInt(e,10);return`${`succ[`.repeat(t)}0${`]`.repeat(t)}`},Ia=(e,t)=>[`(* automatically generated -- do not edit manually *)`,`theory ${e} imports Constant Zenon begin`,...t?[`ML_command \\<open> writeln ("*** TLAPS PARSED\\n"); \\<close>`]:[],Pa],La=e=>{let t=sn(),n=e=>ln(t,Da(e)),a=()=>ln(t,``),o={isAssumed:!1},c=(e,r)=>{let i=r(n(e));return un(t,1),i},l=e=>`(${g(e)})`,u=e=>e.map(l).join(`, `),d=(e,t)=>`(${e} (${u(t)}))`,f=(e,t)=>{let n=ka[e];if(n!==void 0&&t.length===0)return n;let a=Aa[e];if(a!==void 0&&t.length===1)return`(${a} ${l(t[0])})`;let o=ja[e];if(o!==void 0&&t.length===2)return`(${l(t[0])} ${o} ${l(t[1])})`;let c=Ma[e];if(c&&c[1]===t.length)return d(c[0],t);if(e===`Unprimable`&&t.length===1)return l(t[0]);if(e===`Irregular`&&t.length===1)throw new i(`Irregular`);if((e===`Prime`||e===`StrongPrime`||e===`UNCHANGED`)&&t.length===1)throw new r;let u=Na[e];throw u&&u[1]===t.length?new s(`Unsupported operator \`${u[0]}\`.\n`):new s(`Backend.Isabelle.pp_apply`)},p=(e,i)=>{switch(e.kind){case`Ix`:{let n=cn(t,e.index);if(e.index<=0||n===void 0)throw new r;return i.length===0?n:`(${n} (${u(i)}))`}case`Opaque`:{let t=Da(e.name);return i.length===0?`(${t} :: c)`:`(${t} (${u(i)}) :: c)`}case`Internal`:return f(e.builtin,i);case`Lambda`:{let r=`\\<lambda> ${e.params.map(e=>`${n(e.name)} `).join(``)}. ${l(e.body)}`;return un(t,e.params.length),r}default:throw new r}},m=(e,t,n)=>{if(t.length===0)return g(n);let i=t[0],a=t.slice(1),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:F(1,e.domain.expression)}}:e),body:n,location:n.location},u=e===`Forall`?`\\<forall>`:`\\<exists>`;if(i.domain.kind===`NoDomain`)return c(i.name,e=>`${u}${e} : ${l(s)}`);if(i.domain.kind!==`Domain`)throw new r;let d=l(i.domain.expression);return c(i.name,e=>`${u} ${e} \\<in> ${d} : ${l(s)}`)},h=e=>{if(e.context.length===0)return l(e.active);let n=e.context[0],r=()=>h({context:e.context.slice(1),active:e.active});switch(n.kind){case`Flex`:return c(n.name,e=>`(\\<And> ${e} ${e}'.${r()})`);case`Fresh`:{if(n.domain&&n.domainVisibility===`Visible`){let e=l(n.domain);return c(n.name,t=>`(\\<And> ${t} :: c. ${t} \\<in> ${e} \\<Longrightarrow> ${r()})`)}let e=`${`c => `.repeat(n.shape)}c`;return c(n.name,t=>`(\\<And> ${t} :: ${e}. ${r()})`)}case`Fact`:{let e=n.visibility===`Visible`?l(n.expression):void 0;a();let i=e?`(${e} \\<Longrightarrow> ${r()})`:r();return un(t,1),i}case`Defn`:throw new i(`Inner definition`)}},g=e=>{switch(e.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return p(e,[]);case`Apply`:return p(e.operator,e.args);case`Bang`:throw new s(`Backend.Isabelle.module`);case`Sequent`:return h(e.sequent);case`With`:case`Parens`:return g(e.expression);case`Let`:throw new i(`LET`);case`List`:return e.bullet===`Refs`&&e.items.length===0?`TRUE`:e.bullet===`Refs`&&e.items.length===1?g(e.items[0]):e.items.map(l).join(e.bullet===`Or`?` | `:` & `);case`If`:return`cond(${l(e.condition)}, ${l(e.consequent)}, ${l(e.alternative)})`;case`Quant`:return m(e.quantifier,e.bounds,e.body);case`Tquant`:throw new i(e.quantifier===`Forall`?`\\\\AA`:`\\\\EE`);case`Choose`:{if(!e.domain)return c(e.name,t=>`Choice(%${t}. ${l(e.body)})`);let t=l(e.domain);return c(e.name,n=>`bChoice(${t}, %${n}. ${l(e.body)})`)}case`SetSt`:{let t=l(e.domain);return c(e.name,n=>`subsetOf(${t}, %${n}. ${l(e.body)})`)}case`SetOf`:{if(e.bounds.length===0)throw new r;let t=e.bounds[0];if(e.bounds.length!==1||t.domain.kind!==`Domain`)throw new i(`SetOf (multiple declared constants)`);let n=l(t.domain.expression);return c(t.name,t=>`setOfAll(${n}, %${t}. ${l(e.element)})`)}case`SetEnum`:return`{${u(e.elements)}}`;case`Fcn`:{let t=e.bounds[0];if(e.bounds.length!==1)throw new i(`function (multiple declared constants)`);if(t.domain.kind===`Ditto`)throw new r;let n=t.domain.kind===`Domain`?l(t.domain.expression):void 0;return c(t.name,t=>`[${n===void 0?t:` ${t} \\<in> ${n} `} \\<mapsto> ${l(e.body)}]`)}case`FcnApp`:{let t=l(e.function);return e.args.length===1?`fapply (${t}, ${l(e.args[0])})`:`fapply (${t}, <<${u(e.args)}>>)`}case`Arrow`:return`[${l(e.domain)} \\<rightarrow> ${l(e.range)}]`;case`Rect`:return`[${e.fields.map(e=>`''${e.name}'' : ${l(e.value)}`).join(`, `)}]`;case`Record`:return`(${e.fields.map(e=>`(''${e.name}'' :> ${l(e.value)})`).join(` @@ `)})`;case`Except`:{let t=e.specs.map(e=>`!${e.trail.map(e=>e.kind===`Dot`?`[''${e.field}'']`:`[${l(e.expression)}]`).join(``)} = ${l(e.value)}`);return`[${l(e.function)} EXCEPT ${t.join(`, `)}]`}case`Dot`:return`fapply (${l(e.expression)}, (''${e.field}''))`;case`Tuple`:return`<<${u(e.elements)}>>`;case`Product`:return e.factors.length===2?`(${l(e.factors[0])} \\<times> ${l(e.factors[1])})`:`Product(\\<langle>${u(e.factors)}\\<rangle>)`;case`Sub`:case`Tsub`:{let t=e.kind===`Sub`?`sub`:`tsub`;return`${e.modal===`Box`?Oa(`a'box'${t}`):`a'dia'${t}`}(${l(e.action)},${l(e.subscript)})`}case`Fair`:return`${Oa(e.fairness===`Weak`?`a'wf`:`a'sf`)}(${l(e.subscript)},${l(e.action)})`;case`Case`:{let t=u(e.arms.map(e=>e.condition)),n=u(e.arms.map(e=>e.body));return e.other?`CaseOther(<<${t}>>,<<${n}>>,${l(e.other)})`:`Case(<<${t}>>,<<${n}>>)`}case`String`:return`''${e.value}''`;case`Num`:if(e.fraction!==``)throw new i(`real constants`);return`(${Fa(e.integer)})`;case`At`:throw new r}},_=e=>{let n=t.stack.length;try{return l(e)}catch(e){if(!(e instanceof i))throw e;return un(t,t.stack.length-n),e}},v=e=>{let r=[];for(let s of e.context)switch(s.kind){case`Flex`:{let e=n(s.name);r.push(`fixes ${e} ${e}'`);break}case`Fresh`:{let e=s.domain&&s.domainVisibility===`Visible`?l(s.domain):void 0,t=n(s.name);if(r.push(`fixes ${t}`),e===void 0)break;o.isAssumed=!0,r.push(`assumes ${t}_in : "(${t} \\<in> ${e})"`);break}case`Fact`:{let e=t.stack.length,n=s.visibility===`Visible`?_(s.expression):void 0;if(a(),n instanceof i){r.push(`(* omitted temporal assumption : ${n.message} *)`);break}if(n===void 0)break;o.isAssumed=!0,r.push(`assumes v'${e}: "${n}"`);break}case`Defn`:if(s.definition.kind===`Bpragma`)return r.map(e=>`${e}\n`).join(``);r.push(`(* usable definition ${s.definition.name} suppressed *)`),n(s.definition.name)}return[...r,`shows "${l(e.active)}"`].join(`
28
+ `)};try{return{text:v(e),isAssumed:o.isAssumed}}catch(e){throw e instanceof i?new s(`isabelle : unsupported operator ${e.message}`):e}},Ra=(e,t,n,r)=>{let i=La(t);return[...Ia(r,!1),`lemma ob'${e}:`,`${i.text}(is "PROP ?ob'${e}")`,`proof -`,`show "PROP ?ob'${e}"`,`${i.isAssumed?`using assms `:``}by ${n}`,`qed`,`end`,``].join(`
29
+ `)},za=(e,t)=>[...Ia(e,!0),...t.flatMap(e=>[`lemma ob'${e.id}:`,`${La(e.sequent).text}(is "PROP ?ob'${e.id}")`,`proof -`,`ML_command \\<open> writeln "*** TLAPS ENTER ${e.id}"; \\<close>`,`show "PROP ?ob'${e.id}"`,`using assms by ${e.tactic}`,`ML_command \\<open> writeln "*** TLAPS EXIT ${e.id}"; \\<close> qed`]),`end`,``].join(`
30
+ `),Ba=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],Va=Array.from({length:64},(e,t)=>Math.floor(Math.abs(Math.sin(t+1))*2**32)),Ha=(e,t)=>e<<t|e>>>32-t,Ua=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+Va[o]+t[l]|0;return[i,n+Ha(u,Ba[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(``)},Wa=(e,t)=>{let n=ye(e,t-1)?.hyp;if(!n)throw new r;return n},Ga=(e,t)=>mr(e,t).level,Ka=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),qa=(e,t)=>{let n=be(void 0,(n,r)=>{let i=He(r,t=>e(n,t),t);return[A(n,i),i]});return(t,r)=>{let i=n(t,r.context);return{context:i.context,active:e(i.state,r.active)}}},Ja=(e,t)=>{if(t.kind===`Sub`||t.kind===`Tsub`){let n=Ja(e,t.action),r=Ja(e,t.subscript),i=k(`UNCHANGED`,[r],t),a=t.modal===`Box`?k(`Disj`,[n,i],t):k(`Conj`,[n,k(`Neg`,[i],t)],t);return t.kind===`Sub`?a:k(t.modal===`Box`?`BoxTrue`:`Diamond`,[a],t)}return L(e,t,Ja,A,`all`)},Ya=(e,t)=>t.kind===`Apply`&&Ka(t,[`UNCHANGED`])&&t.args.length===1?jr(t.args[0]):L(e,t,Ya,A,`all`),Xa=(e,t)=>k(e,[t],t),Za=(e,t)=>{if(t.kind===`Ix`){let n=Wa(e,t.index);return n.kind===`Fresh`&&n.level===`Constant`||n.kind===`Defn`&&n.definition.kind===`Operator`&&Ga(ye(e,t.index),n.definition.body)===0?t:Xa(`Prime`,t)}if(Ka(t,[`ENABLED`])||t.kind===`Opaque`||t.kind===`Sequent`||t.kind===`Let`)return Xa(`Prime`,t);if(Ka(t,[`UNCHANGED`,`Cdot`,`Leadsto`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`])||t.kind===`Tquant`||t.kind===`Sub`||t.kind===`Tsub`||t.kind===`Fair`)throw new r;return L(e,t,Za,A)},Qa=e=>{let t=e===`BoxTrue`?`Conj`:`Disj`,n=e===`BoxTrue`?`Forall`:`Exists`,r=(i,a)=>Ga(i,a)===0?a:Ka(a,[t])||(a.kind===`Quant`||a.kind===`Tquant`)&&a.quantifier===n?L(i,a,r,A):Xa(e,a);return r},$a={Prime:Za,BoxTrue:Qa(`BoxTrue`),Diamond:Qa(`Diamond`)},eo=(e,t)=>{if(t.kind===`Apply`&&t.operator.kind===`Internal`){let n=$a[t.operator.builtin];if(n){if(t.args.length!==1)throw new r;return n(e,t.args[0])}}return L(e,t,eo,A,`all`)},to=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],no={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},ro=(e,t)=>`${e}_${t}_`,io=(e,t,n)=>{if(t.kind!==`Operator`)return t.kind===`Bpragma`?{...t,body:uo(e,t.body)}:t;let i=uo(e,t.body),a=to[n??Ga(e,i)];if(a===void 0)throw new r;return{...t,name:ro(a,t.name),body:i}},ao=(e,t,n)=>{switch(t.kind){case`Fresh`:return{...t,name:ro(no[t.level],t.name),domain:t.domain&&uo(e,t.domain)};case`Flex`:return{...t,name:ro(`VARIABLE`,t.name)};case`Defn`:return{...t,definition:io(e,t.definition,n)};case`Fact`:return{...t,expression:uo(e,t.expression)}}},oo=(e,t)=>{if(t.kind!==`Defn`||t.definition.kind!==`Operator`)return;let n=t=>{if(!Ka(t,[`UNCHANGED`])||t.kind!==`Apply`)return Ga(e,t);let n=e=>e.kind===`Tuple`?e.elements.flatMap(n):[e],r=n(t.args[0]);return Ga(e,r.length===1?r[0]:t.args[0])},r=t.definition.body;return n(Ka(r,[`Prime`,`BoxTrue`,`Diamond`])&&r.kind===`Apply`&&r.args.length===1&&r.kind===`Apply`?r.args[0]:r)},so=be({scope:void 0,original:void 0},(e,t,n)=>{let r=ao(e.scope,t,oo(e.original,n));return[{scope:A(e.scope,r),original:A(e.original,n)},r]}),co=(e,t)=>{let n=so(t.context,e.context);return{context:n.context,active:uo(n.state.scope,e.active)}},lo=(e,t)=>{let[n,r]=M(e,t.context,(e,t)=>{let n=ao(e,t);return[A(e,n),n]});return{context:r,active:uo(n,t.active)}},uo=(e,t)=>{switch(t.kind){case`Lambda`:{let n=t.params.map(e=>({...e,name:ro(`Unknown`,e.name)})),r=j(e,n.map(e=>N(e.name,`Unknown`,e.shape)));return{...t,params:n,body:uo(r,t.body)}}case`Tquant`:{let n=j(e,t.names.map(e=>({kind:`Flex`,name:ro(`VARIABLE`,e)})));return{...t,body:uo(n,t.body)}}case`Choose`:{let n=t.domain&&uo(e,t.domain),r=ro(`CONSTANT`,t.name),i=n?xe(r,n):N(r,`Constant`);return{...t,name:r,domain:n,body:uo(A(e,i),t.body)}}case`SetSt`:{let n=uo(e,t.domain),r=ro(`CONSTANT`,t.name),i=uo(A(e,xe(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:ro(no[t.level],t.name),domain:t.domain.kind===`Domain`?{kind:`Domain`,expression:uo(e,t.domain.expression)}:t.domain})),r=j(e,n.map(e=>N(e.name,e.level)));return t.kind===`SetOf`?{...t,bounds:n,element:uo(r,t.element)}:{...t,bounds:n,body:uo(r,t.body)}}case`Let`:{let[n,r]=M(e,t.definitions,(e,t)=>{let n=io(e,t);return[A(e,{kind:`Defn`,definition:n,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),n]});return{...t,definitions:r,body:uo(n,t.body)}}case`Sequent`:return{...t,sequent:lo(e,t.sequent)};default:return L(e,t,uo,A,`all`)}},fo=/* @__PURE__ */ new WeakMap,po=(e,t)=>{let n=fo.get(t);if(n)return n;let r=t.kind===`Operator`?t.body:void 0;if(r?.kind!==`Lambda`)return[];let i=j(e,r.params.map(e=>N(e.name,`Unknown`,e.shape))),a=r.params.map((e,t)=>go(i,r.body,t+1,!0));return fo.set(t,a),a},mo=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`ENABLED`,`UNCHANGED`],ho=[`Leadsto`,`Actplus`,`Cdot`],go=(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(mo.includes(r)&&t.args.length===1||ho.includes(r)&&t.args.length===2)return t.args.every(t=>go(e,t,n,!1))}if(t.kind===`Sub`)return[t.action,t.subscript].every(t=>go(e,t,n,!1));if(t.kind===`Apply`&&t.operator.kind===`Ix`){let i=ye(e,t.operator.index-1),a=i?.hyp;if(i&&a?.kind===`Defn`&&a.definition.kind===`Operator`){let o=po(i.rest,a.definition);return t.args.every((t,i)=>{let a=o[i];if(a===void 0)throw new r;return go(e,t,n,a)})}}let a={isSubstitutive:!0};return L({scope:e,index:n},t,(e,t)=>(a.isSubstitutive&&=go(e.scope,t,e.index,i),t),(e,t)=>({scope:A(e.scope,t),index:e.index+1}),`all`),a.isSubstitutive},_o=(e,t)=>{let n=an(kn(_e(e),t));return`h${Ua(n).slice(0,5)}`},vo=(e,t)=>O({kind:`Opaque`,name:_o(e,t)},t),yo=(e,t,n,r,i)=>{let a=i.map((t,r)=>Ga(e,t)===0||n[i.length-r-1]?O({kind:`Opaque`,name:`*`},t):t);return vo(e,O({kind:`Apply`,operator:{kind:`Opaque`,name:t},args:a},r))},bo=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`Leadsto`,`ENABLED`,`Cdot`,`UNCHANGED`],xo=(e,t)=>{if(t.kind!==`Apply`)return L(e,t,xo,A);let n=t.operator,[i]=t.args;if(Ka(t,[`Prime`,`StrongPrime`])&&t.args.length===1&&i.kind===`Ix`){let n=Wa(e,i.index);if(n.kind===`Fresh`||n.kind===`Flex`)return O({kind:`Opaque`,name:`${n.name}#prime`},t)}if(Ka(t,bo))return vo(e,t);if(n.kind!==`Ix`)return L(e,t,xo,A);let a=ye(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=po(a.rest,o.definition);if(s.every((t,n)=>Ga(e,t)===0||r[s.length-n-1]))return L(e,t,xo,A);let i=yo(e,o.definition.name,r,n,s);return O({kind:`Apply`,operator:i,args:s.map(t=>xo(e,t))},t)}if(o.kind===`Flex`)return L(e,t,xo,A);if(o.kind===`Fresh`){if(o.level===`Constant`)return O({kind:`Apply`,operator:n,args:s.map(t=>xo(e,t))},t);let r=s.map(()=>!1);return yo(e,o.name,r,n,s)}throw new r},So=qa(Ja,`all`),Co=qa(Ya,`all`),wo=qa(eo,`all`),To=qa(xo,`visible`),Eo=e=>{let t=e.context,n=Co(t,So(t,e)),r=wo(t,n);return To(t,co(r,e))},Do=e=>be(T(0),(t,n)=>n.kind===`Defn`&&(e&&n.definition.kind===`Bpragma`||n.definition.kind===`Operator`&&n.visibility===`Visible`)?[E(P(t,n.definition.body),t),void 0]:[D(1,t),Oe(t,n)]),Oo=Do(!0),ko=Do(!1),Ao=(e,t=!0)=>{let n=(t?Oo:ko)(e.context);return{context:n.context,active:P(n.state,e.active)}},jo=/* @__PURE__ */ new Set([`BoxTrue`,`BoxFalse`,`Diamond`,`Actplus`,`Leadsto`,`Cdot`]),Mo=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]}},No=e=>{if(e.kind===`Tsub`||e.kind===`Fair`||e.kind===`Apply`&&e.operator.kind===`Internal`&&jo.has(e.operator.builtin))return!1;if(e.kind===`Sequent`){let t=e.sequent;return[...t.context.flatMap(Mo),t.active].every(No)}return We(e).every(No)},Po=t=>{if(t.kind!==`Let`)return Ue(t,Po);let[n,...r]=t.definitions;if(!n)return Po(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=Po(n.body),a={...t,definitions:r};return Po(P(E(i,T(0)),a))},Fo=(e,t)=>t.kind===`Dot`?O({kind:`Dot`,expression:e,field:t.field},e):O({kind:`FcnApp`,function:e,args:[t.expression]},e),Io=(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&I(e.expression,t.expression),Lo=(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},Ro=e=>{if(e.kind!==`Except`)return Ue(e,Ro);let t=e,n=(e,t)=>Lo(e,t)?.value??Fo(e,t),r=(e,n,r)=>{let i=Lo(e,n);if(e.kind!==`Record`||!i)return O({kind:`Except`,function:e,specs:[{trail:[n],value:r}]},t);let a=e.fields.map(e=>e.name===i.name?{name:e.name,value:r}:e);return O({kind:`Record`,fields:a},e)},i=(e,t)=>{let[a,...o]=t;if(!a)return e;if(a.trail.length===0)return i(a.value,o);let s=a.trail[0],c=t.findIndex(e=>e.trail.length===0||!Io(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(Ro(t.function),Be(t.specs,Ro))},zo=be(!0,(e,t)=>[e&&Mo(t).every(No),He(t,Po,`all`)]),Bo=be(void 0,(e,t)=>[void 0,He(t,Ro,`all`)]),Vo=e=>{let t=zo(e.context),n=Po(e.active);return t.state&&No(e.active)?{context:Bo(e.context,t.context).context,active:Ro(n)}:{context:t.context,active:n}},Ho={kind:`Internal`,builtin:`TRUE`},Uo=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2?e.args:void 0,Wo=e=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`ENABLED`&&e.args.length===1?e.args[0]:void 0,Go=(e,t)=>{let n=Uo(e,t),r=n&&Wo(n[0]),i=n&&Wo(n[1]);return r&&i?[r,i]:void 0},Ko=(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=ye(e.scope,t.index-1)?.hyp;if(!i)throw new r;i.kind===`Flex`&&e.isPrimed&&n.add(i.name)}else s!==`ENABLED`&&L(e,t,i,(e,t)=>({...e,scope:A(e.scope,t)}));return t};return i({scope:e,isPrimed:!1},t),n},qo=(e,t,n)=>{let r=Ko(e,t);return[...Ko(e,n)].every(e=>!r.has(e))},Jo=(e,t)=>{let n=t=>mr(e,t).level,i=(e,t)=>{if(n(e)>2||n(t)>2)throw new r},a=Wo(t),o=a&&Uo(a,`Disj`);if(o)return i(o[0],o[1]),{name:`abdisj_inverse`,left:o[0],right:o[1]};let s=Go(t,`Disj`);if(s)return i(s[0],s[1]),{name:`abdisj`,left:s[0],right:s[1]};let c=a&&Uo(a,`Conj`);if(c){let t=c[0],r=c[1],a=qo(e,t,r);return i(t,r),a?{name:n(t)===2?`abconj_inverse`:`pconj_inverse`,left:t,right:r}:void 0}let l=Go(t,`Conj`);if(l)return qo(e,l[0],l[1])?{name:`abconj`,left:l[0],right:l[1]}:void 0;let u=Uo(t,`Conj`),d=u&&Wo(u[1]);if(u&&d)return n(u[0])<=1&&n(d)<=2?{name:`pconj`,left:u[0],right:d}:void 0;let f=Go(t,`Equiv`)??Go(t,`Eq`);if(f)return{name:`equiv`,left:f[0],right:f[1]};let p=Go(t,`Implies`);return p&&{name:`implies`,left:p[0],right:p[1]}},Yo=e=>{let t=j(void 0,e.context),n=Jo(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=>I(F(a,e),n.left),c=e=>I(F(a,e),n.right),l=(e,t)=>e!==void 0&&s(e[0])&&c(e[1])&&t.includes(n.name),u=Wo(o),d=u&&Uo(u,`Conj`),f=Uo(o,`Conj`),p=f&&Wo(f[1]),m=Uo(o,`Mem`),h=m?.[1].kind===`Internal`&&m[1].builtin===`BOOLEAN`;l(d,[`pconj`])||l(u&&Uo(u,`Disj`),[`abdisj`])||l(Go(o,`Disj`),[`abdisj_inverse`])||l(d,[`abconj`])||l(Go(o,`Conj`),[`abconj_inverse`,`pconj_inverse`])||l(f&&p&&[f[0],p],[`pconj_inverse`])?r.isPremise=!0:l(Uo(o,`Equiv`),[`equiv`])?(r.isPremise=!0,r.isLeftBoolean=!0,r.isRightBoolean=!0):l(Uo(o,`Eq`),[`equiv`])?r.isPremise=!0:m&&h&&s(m[0])?r.isLeftBoolean=!0:m&&h&&c(m[0])?r.isRightBoolean=!0:l(Uo(o,`Implies`),[`implies`])&&(r.isPremise=!0)}),!r.isPremise||!r.isLeftBoolean||!r.isRightBoolean)throw new s(`ENABLEDaxioms proof directive did not succeed.
31
+ `);return{...e,active:Ho}},Xo={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,Qo=e=>[...new Map(e.toReversed().map(e=>[e.name,e.value]))].toSorted((e,t)=>e[0]<t[0]?-1:1),$o=(e,t)=>{let n=ye(e,t-1);if(!n)throw new r;let i=n.hyp;if(i.kind===`Fresh`)return{name:i.name,kind:i.level,level:Xo[i.level]??-1};if(i.kind===`Flex`)return{name:i.name,kind:`Variable`,level:1};if(i.kind===`Defn`&&i.definition.kind===`Operator`){let e=mr(n.rest,i.definition.body).level;return{name:i.definition.name,kind:`Definition`,level:e}}throw new r},es=(e,t)=>j(e,t.map(e=>N(e.name,e.level))),ts=(e,t)=>j(e,t.map(e=>N(e.name,`Unknown`,e.shape))),ns=(e,t)=>j(e,t.map(e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0}))),rs=(e,t)=>j(e,t.map(e=>({kind:`Flex`,name:e}))),is=(e,t,n,i)=>{let a=/* @__PURE__ */ new Map,o=(e,t,n,r)=>{let i=$o(e,n),o=$o(t,r);if(i.kind===`Unknown`)return n===r;if(i.kind===`Variable`||i.kind===`Definition`)return i.name===o.name&&o.kind===i.kind;let s=Xo[o.kind];if(!(s!==void 0&&s<=i.level||o.kind===`Definition`&&o.level<=i.level))return!1;let c=a.get(i.name);return c===void 0?(a.set(i.name,o.name),!0):c===o.name},s=(e,t,n,r)=>{if(n.kind===`Operator`&&r.kind===`Operator`||n.kind===`Bpragma`&&r.kind===`Bpragma`)return p(e,t,n.body,r.body);if(n.kind!==`Instance`||r.kind!==`Instance`)return!1;let i=n.instance.args,a=r.instance.args,o=(e,t)=>j(e,t.map(e=>N(e,`Unknown`))),s=e=>Qo(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(A(e,n[0]),A(t,r[0]),n.slice(1),r.slice(1)),f=(e,t,n,r)=>!n.domain||!r.domain?!n.domain&&!r.domain&&p(A(e,N(n.name,`Constant`)),A(t,N(r.name,`Constant`)),n.body,r.body):p(e,t,n.domain,r.domain)&&p(A(e,xe(n.name,n.domain)),A(t,xe(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(ts(e,n.params),ts(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(j(e,n.sequent.context),j(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(ns(e,n.definitions),ns(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(es(e,n.bounds),es(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(rs(e,n.names),rs(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(es(e,n.bounds),es(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(es(e,n.bounds),es(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,Qo(n.fields),Qo(i.fields));case`Record`:return i.kind===`Record`&&c(e,t,Qo(n.fields),Qo(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=_e(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)},as=e=>{let t=j(void 0,e.context);if(!e.context.some((n,r)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return!1;let i=ye(t,e.context.length-r),a=n.expression;return a.kind===`Sequent`?is(j(i,a.sequent.context),t,a.sequent.active,e.active):is(i,t,a,e.active)}))throw new s(`LevelComparison proof directive did not succeed.
32
+ `);return{...e,active:{kind:`Internal`,builtin:`TRUE`}}},os=(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`)?as(e):t.has(`enabledaxioms`)?Yo(e):e;let s=kt({value:0},()=>{throw new r},()=>{}),c={kind:`Sequent`,sequent:e},l=n||i?Wr(s,()=>{},void 0,c,{isEnabled:n,isCdot:i,isAutoUse:a}):Vr(s,()=>{},void 0,c,{isEnabled:!0,isCdot:!0,isAutoUse:a});if(l.kind!==`Sequent`)throw new r;return l.sequent},ss=/* @__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(`.`),cs={And:0,Or:1,Refs:2},ls={Forall:0,Exists:1},us={Box:0,Dia:1},ds={Weak:0,Strong:1},fs={34:`\\"`,92:`\\\\`,10:`\\n`,9:`\\t`,13:`\\r`,8:`\\b`},ps=e=>`"${[...new TextEncoder().encode(e)].map(e=>fs[e]??(e<32||e>126?`\\${String(e).padStart(3,`0`)}`:String.fromCharCode(e))).join(``)}"`,ms=e=>e===`BoxTrue`?`$Box`:e===`BoxFalse`?`$FakeBox`:`$${ss.indexOf(e)}`,hs=e=>e.level===`Unknown`?`Unknown`:e.level.toUpperCase(),gs=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 ms(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(${cs[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(${ls[t.quantifier]};${f(e.entries,t.bounds)}.${e.text})`}case`Tquant`:{let e=p(t.names.length,t.body);return`$Tquant(${ls[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}(${us[t.modal]},${a(t.action)},${a(t.subscript)})`;case`Fair`:return`$Fair(${ds[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 ps(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,A(s,c)),entry:a()});switch(c.kind){case`Fresh`:{if(!c.domain){let e=hs(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)},_s=e=>Ua(gs(e)),vs=e=>e.domain.kind===`NoDomain`,ys=e=>{if(e.kind===`List`&&(e.bullet===`And`||e.bullet===`Refs`)){let t=e.items.map(ys),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=ys(e.args[0]),n=ys(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(vs)){let t=ys(e.body),n=(t,n)=>O({kind:`Quant`,quantifier:`Forall`,bounds:e.bounds,body:t},n);return[t[0].map(e=>n(e,e)),t[1]&&n(t[1],e)]}return[[],e]},bs=e=>{let t=[],n=e.context.reduce((e,n)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return t.push(Oe(e,n)),D(1,e);let r=ys(n.expression),i=[...r[1]?[r[1]]:[],...r[0]];return i.forEach((r,i)=>t.push({...n,expression:F(i,P(e,r))})),{kind:`Compose`,outer:T(i.length-1),inner:D(1,e)}},T(0));return{context:t,active:P(n,e.active)}},xs=/* @__PURE__ */ new Set([`expandenabled`,`expandcdot`,`autouse`,`lambdify`,`enabledaxioms`,`levelcomparison`]),Ss=[{prover:`smt`,timeLimitMs:5e3},{prover:`zenon`,timeLimitMs:1e4},{prover:`isabelle`,timeLimitMs:3e4,tactic:`auto`}],Cs={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([...xs].map(e=>[e,{prover:e,seconds:0}]))},ws=(e,t,n,r)=>{let i=Cs[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`}}},Ts=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)))},Es=(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:Ts(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 ws(n.prover,n.timeout,n.rlimit,n.tactic)},Ds=e=>ws(e.name,e.timeout,void 0,e.tactic),Os=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(Ds(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=>Es(e,t)))}else if(s?.kind===`Meth`){if(a.kind===`Apply`)throw new r;n.methods.push(Ds(s.method))}}),n.methods},ks=e=>{let t=e.method===void 0?Os(e.sequent):[Ds(e.method)],n=t.filter(e=>!xs.has(e.prover));return{frontends:new Set(t.flatMap(e=>xs.has(e.prover)?[e.prover]:[])),provers:n.length>0?n:Ss}},As=e=>e.active.kind===`Internal`&&e.active.builtin===`TRUE`||e.context.some((t,n)=>t.kind===`Fact`?I(t.expression,F(n-e.context.length,e.active)):t.kind!==`Fresh`||!t.domain?!1:I(k(`Mem`,[{kind:`Ix`,index:1},F(1,t.domain)],{}),F(n+1-e.context.length,e.active))),js={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},Ms=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],Ns=(e,t)=>{let[n,r]=M(e,t.context,(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return{...t,name:`${js[t.level]}_${t.name}_`,domain:t.domain&&Ps(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=Ps(e,n.body),i=Ms[mr(e,r).level];return{...t,definition:{...n,name:`${i}_${n.name}_`,body:r}}}case`Fact`:return{...t,expression:Ps(e,t.expression)}}})();return[A(e,n),n]});return{context:r,active:Ps(n,t.active)}},Ps=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:Ns(e,t.sequent)};let n=L(e,t,Ps,A,`all`);switch(n.kind){case`Lambda`:return{...n,params:n.params.map(e=>({...e,name:`Unknown_${e.name}_`}))};case`Quant`:case`Fcn`:case`SetOf`:return{...n,bounds:n.bounds.map(e=>({...e,name:`${js[e.level]}_${e.name}_`}))};case`Choose`:case`SetSt`:return{...n,name:`CONSTANT_${n.name}_`};default:return n}},Fs=(e,t)=>{if(t.kind!==`Sequent`)return L(e,t,Fs,A,`all`);let n={scope:e,substitution:T(0),context:[]},r=e=>{let t=e.kind===`Fact`&&e.visibility===`Visible`&&e.time===`Always`?{...e,expression:k(`BoxTrue`,[e.expression],e.expression)}:e;n.context.push(t),n.scope=A(n.scope,t)};for(let e of t.sequent.context){let t=Oe(n.substitution,e);if(t.kind===`Fact`){r({...t,expression:Fs(n.scope,t.expression)}),n.substitution=D(1,n.substitution);continue}if(t.kind!==`Fresh`||!t.domain||e.kind!==`Fresh`||!e.domain){r(t),n.substitution=D(1,n.substitution);continue}let i=Fs(n.scope,t.domain);r({...t,domain:void 0}),r({kind:`Fact`,expression:k(`Mem`,[O({kind:`Ix`,index:1},i),F(1,i)],i),visibility:t.domainVisibility,time:t.level===`Constant`?St(n.scope,e.domain):`Now`,location:t.location}),n.substitution={kind:`Compose`,outer:T(1),inner:D(1,n.substitution)}}let i=P(n.substitution,t.sequent.active);return{...t,sequent:{context:n.context,active:Fs(n.scope,i)}}},Is={Conj:`&`,Disj:`|`,Implies:`->`,Equiv:`<->`},Ls={Neg:`~`,BoxTrue:`always`,BoxFalse:`always`,Diamond:`sometime`,Prime:`next`},Rs=e=>{if(e.kind===`Internal`&&e.builtin===`TRUE`)return;if(e.kind===`List`&&e.bullet!==`Or`){let t=e.items.flatMap(e=>Rs(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=Rs(e.args[0]),n=Rs(e.args[1]);return t&&n?{...e,args:[t,n]}:t??n},zs=`(cc | ~ cc)`,Bs=e=>{let t=(e,n,r=!1)=>{let i=n=>t(e,n);switch(n.kind){case`Internal`:if(n.builtin===`TRUE`)return zs;if(n.builtin===`FALSE`)return`(cc & ~ cc)`;break;case`Apply`:{let e=n.operator,t=n.args;if(e.kind!==`Internal`)break;let r=Is[e.builtin];if(r&&t.length===2)return`(${i(t[0])} ${r} ${i(t[1])})`;let a=Ls[e.builtin];if(a&&t.length===1)return`(${a} ${i(t[0])})`;break}case`List`:{if(n.items.length===0)return zs;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?Rs(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${Ua(an(kn(e,n))).slice(0,5)}`},n=Ps(void 0,{kind:`Sequent`,sequent:e});return`not (${t([],Fs(void 0,pt(dt(ft(n)))),!0)})`},Vs=(e,t)=>e<t?-1:+(e>t),Hs=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Vs(e,t);if(!Array.isArray(e)||!Array.isArray(t))return 0;let n=e.findIndex((e,n)=>n>=t.length||Hs(e,t[n])!==0);return n===-1?e.length-t.length:n>=t.length?1:Hs(e[n],t[n])},Us={"\\":`backslash_`,"+":`plussign_`,"-":`hyphen_`,"*":`asterisk_`,"/":`slash_`,"%":`percentsign_`,"^":`circumflexaccent_`,"&":`ampersand_`,"@":`atsign_`,"#":`pound_`,$:`dollarsign_`,"(":`leftparenthesis_`,")":`rightparenthesis_`,"|":`verticalbar_`,".":`period_`,":":`colon_`,"?":`questionmark_`,"!":`exclamationmark_`,"<":`lessthansign_`,">":`greaterthansign_`,"=":`equalsign_`," ":`space_`},Ws=e=>`smt__${e.replace(/[\\+\-*/%^&@#$()|.:?!<>= ]/g,e=>Us[e]).replaceAll(`_`,`__`)}`,Gs=Ws(`TLA__`),Ks=new Map(Object.entries(Us).map(e=>[e[1],e[0]])),qs=RegExp(`(${[...Ks.keys()].join(`|`)})`,`g`),U=e=>Ws(`TLA__${e}`),Js=e=>e.startsWith(Gs)?e.slice(Gs.length).replaceAll(`__`,`_`).replace(qs,e=>Ks.get(e)??e):void 0,W=U(`Mem`),Ys=U(`SetExtTrigger`),Xs=U(`SubsetEq`),Zs=U(`Cup`),Qs=U(`Cap`),$s=U(`SetMinus`),ec=U(`Subset`),tc=U(`Union`),nc=U(`Tt_Idv`),rc=U(`Cast_Bool`),ic=U(`BoolSet`),ac=U(`StrSet`),oc=U(`IntSet`),sc=U(`NatSet`),G=U(`Cast_Int`),K=U(`Proj_Int`),cc=U(`IntLteq`),lc=U(`IntRange`),q=U(`FunApp`),J=U(`FunDom`),uc=U(`FunIsafcn`),dc=U(`FunSet`),fc=U(`FunExcept`),pc=U(`TrigEq_Set$Idv$`),mc=U(`IsSetOf`),Y=U(`Seq`),X=U(`Len`),hc=U(`Cat`),gc=U(`Append`),_c=U(`Head`),vc=U(`Tail`),yc=U(`SubSeq`),bc=U(`Tuple_0`),xc={Cup:Zs,Cap:Qs,Setminus:$s,SUBSET:ec,UNION:tc,DOMAIN:J,Plus:U(`IntPlus`),Minus:U(`IntMinus`),Times:U(`IntTimes`),Exp:U(`IntExp`),Quotient:U(`IntQuotient`),Remainder:U(`IntRemainder`),Uminus:U(`IntUminus`),Range:lc,Seq:Y,Len:X,BSeq:U(`BSeq`),Cat:hc,Append:gc,Head:_c,Tail:vc,SubSeq:yc},Sc=(e,t)=>Array.from({length:t},(t,n)=>`${e}${n+1}`),Cc=(e,t=`Idv`)=>e.map(e=>`(${e} ${t})`).join(` `),Z=(e,t,n=[],r=`Idv`)=>e.length===0?t:`(forall (${Cc(e,r)}) ${n.length===0?t:`(! ${t} ${n.map(e=>`:pattern (${e.join(` `)})`).join(` `)})`})`,wc=e=>e.length===0?`true`:e.length===1?e[0]:`(and ${e.join(` `)})`,Tc=e=>e.length===0?`false`:e.length===1?e[0]:`(or ${e.join(` `)})`,Q=(e,t)=>t.length===0?e:`(${e} ${t.join(` `)})`,Ec=(e,t,n=`Idv`,r=`Idv`)=>`(declare-fun ${e} (${Array.from({length:t},()=>r).join(` `)}) ${n})`,Dc=(e,t)=>{let n={depth:0,index:t};for(;n.index<e.length;n.index++)if(e[n.index]===`(`&&n.depth++,e[n.index]===`)`&&n.depth--,n.depth===0)return n.index;return e.length},Oc=(e,t,n)=>e.replace(/[^\s()]+/g,e=>e===t?n:e),kc=/* @__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(`.`),Ac=/* @__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(`.`),jc=[`TIntPlus`,`TIntUminus`,`TIntMinus`,`TIntTimes`,`TIntQuotient`,`TIntRemainder`,`TIntLteq`],$=(e,t,n,r)=>({name:e,args:t,label:r??[e,...t.flat()].join(` `),formula:n}),Mc=e=>`${e.name} ${JSON.stringify(e.args)}`,Nc=e=>{let t=kc.indexOf(e.name);return t===-1?kc.length+Ac.indexOf(e.name):t},Pc=(e,t)=>Nc(e)-Nc(t)||Hs(e.args,t.args),Fc={IntPlus:[`+`,2],IntMinus:[`-`,2],IntTimes:[`*`,2],IntUminus:[`-`,1],IntQuotient:[`div`,2],IntRemainder:[`mod`,2],IntLteq:[`<=`,2]},Ic=e=>{let t=Fc[e][0],n=t===`div`||t===`mod`,r=Fc[e][1]===1?[`x1`]:n?[`x`,`y`]:[`x1`,`x2`],i=Q(U(e),r.map(e=>`(${G} ${e})`)),a=`(= ${i} ${t===`<=`?`(<= ${r.join(` `)})`:`(${G} (${t} ${r.join(` `)}))`})`;return $(`Typing`,[jc.indexOf(`T${e}`)],Z(r,n?`(=> (> y 0) ${a})`:a,[[i]],`Int`),`Typing T${e}`)},Lc=e=>{let t=U(`SetEnum_${e}`),n=Sc(`a`,e),r=Q(t,n),i=$(`EnumDefElim`,[e],Z([...n,`x`],e===0?`(not (${W} x ${r}))`:`(=> (${W} x ${r}) ${Tc(n.map(e=>`(= x ${e})`))})`,[[`(${W} x ${r})`]]));return e===0?[i]:[$(`EnumDefIntro`,[e],Z(n,wc(n.map(e=>`(${W} ${e} ${r})`)),[[r]])),i]},Rc=e=>Array.from({length:e},(e,t)=>`(${G} ${t+1})`),zc=e=>e.map(e=>U(`StrLit_${e}`)),Bc=(e,t,n,r)=>{let i=Sc(`x`,r.length);return r.map((r,a)=>{let o=`(${fc} ${Q(n,i)} ${r} x)`,s=i.map((e,t)=>t===a?`x`:e);return $(e,[...t,a+1],Z([...i,`x`],`(= ${o} ${Q(n,s)})`,[[o]]))})},Vc=e=>Bc(`TupExcept`,[e],U(`Tuple_${e}`),Rc(e)),Hc=e=>Bc(`RecExcept`,[e],U(`Record_${e.join(`_`)}`),zc(e)),Uc=(e,t)=>{let n=U(`Tuple_${e}`),r=Sc(`x`,e),i=Q(n,r),a=Rc(e);return[$(`TupIsafcn`,[e],Z(r,`(${uc} ${i})`,[[i]])),...e===0?[]:[$(`TupDomDef`,[e],Z(r,`(= (${J} ${i}) ${Q(U(`SetEnum_${e}`),a)})`,[[i]])),$(`TupAppDef`,[e],Z(r,wc(a.map((e,t)=>`(= (${q} ${i} ${e}) ${r[t]})`)),[[i]]))],$(`SeqTupTyping`,[e],Z([`a`,...r],e===0?`(${W} ${i} (${Y} a))`:`(=> ${wc(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?Vc(e):[]]},Wc=(e,t)=>{let n=U(`Record_${e.join(`_`)}`),r=zc(e),i=Sc(`x`,e.length),a=Q(n,i);return[$(`RecIsafcn`,[e],Z(i,`(${uc} ${a})`,[[a]])),$(`RecDomDef`,[e],Z(i,`(= (${J} ${a}) ${Q(U(`SetEnum_${e.length}`),r)})`,[[a]])),$(`RecAppDef`,[e],Z(i,wc(r.map((e,t)=>`(= (${q} ${a} ${e}) ${i[t]})`)),[[a]])),...t?Hc(e):[]]},Gc=(e,t,n,r,i,a)=>{let o=Sc(`s`,i.length),s=Sc(`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],`(=> ${wc(s.map((e,t)=>`(${W} ${e} ${o[t]})`))} (${W} ${l} ${c}))`,[[l,c]])),$(`${e}Elim`,t,Z([...o,a],`(=> (${W} ${a} ${c}) ${wc([`(= ${a} ${Q(r,u)})`,...u.map((e,t)=>`(${W} ${e} ${o[t]})`)])})`,[[`(${W} ${a} ${c})`]]))]},Kc=[`Mem`,`Seq`,`Len`,`FunApp`,`NatSet`,`Cast_Int`,`Proj_Int`],qc=(e,t)=>{let n=(e,t,n)=>({declaration:e,deps:t,axioms:n}),r=U(e),a=(e,t,i,a=`Idv`)=>n(Ec(r,e,a),t,i),o=/^SetEnum_(\d+)$/.exec(e);if(o)return a(Number(o[1]),[`Mem`],Lc(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`],`(${Ys} a b)`,[[`(${mc} a)`,`(${mc} 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} ${ac})`),...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`],Uc(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`],Gc(`Product`,[e],r,U(`Tuple_${e}`),Rc(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}`)],Wc(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}`)],Gc(`RecSet`,[u],r,U(e),zc(u),`r`))}let d=t.anonymous.get(e);if(d!==void 0)return a(d,[],[]);let f=Fc[e];if(f)return a(f[1],[`Cast_Int`],[Ic(e)],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 ${oc}) (${W} y ${oc}) (or (distinct x (${G} 0)) (${cc} (${G} 1) y))) (${W} (${r} x y) ${oc})) :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 ((${Ys} x y))))`)],`Bool`);case`SubsetEq`:return a(2,[`Mem`],[$(`SubsetEqIntro`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${W} z x) (${W} z y))) (${Xs} x y)) :pattern ((${Xs} x y))))`),$(`SubsetEqElim`,[],`(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${Xs} x y) (${W} z x)) (${W} z y)) :pattern ((${Xs} 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 (${tc} a))) :pattern ((${W} y a) (${W} x (${tc} a))) :pattern ((${W} x y) (${W} x (${tc} a))) :pattern ((${W} y a) (${W} x y) (${tc} a))))`),$(`UnionElim`,[],`(forall ((a Idv) (x Idv)) (! (=> (${W} x (${tc} a)) (exists ((y Idv)) (and (${W} y a) (${W} x y)))) :pattern ((${W} x (${tc} a)))))`)]);case`Subset`:return a(1,[`Mem`,`SubsetEq`],[$(`SubsetDefAlt`,[],`(forall ((a Idv) (x Idv)) (! (= (${W} x (${ec} a)) (${Xs} x a)) :pattern ((${W} x (${ec} a))) :pattern ((${Xs} x a) (${ec} 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)) (! (${Ys} (${Qs} x y) ${U(`SetEnum_0`)}) :pattern ((${Qs} 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 ${sc}) (and (${W} x ${oc}) (${cc} (${G} 0) x))) :pattern ((${W} x ${sc}))))`)]);case`IntRange`:return a(2,[`Mem`,`IntSet`,`IntLteq`],[$(`IntRangeDef`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${W} x (${lc} a b)) (and (${W} x ${oc}) (${cc} a x) (${cc} x b))) :pattern ((${W} x (${lc} a b)))))`)]);case`FunIsafcn`:return a(1,[`Mem`,`FunDom`,`FunFcn`,`FunApp`],[$(`FunExt`,[],`(forall ((f Idv) (g Idv)) (! (=> (and (${uc} f) (${uc} g) (= (${J} f) (${J} g)) (forall ((x Idv)) (=> (${W} x (${J} f)) (= (${q} f x) (${q} g x))))) (= f g)) :pattern ((${uc} f) (${uc} g))))`)],`Bool`);case`FunSet`:return t.isFunSet=!0,a(2,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunSetIntro`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (and (${uc} f) (= (${J} f) a) (forall ((x Idv)) (=> (${W} x a) (${W} (${q} f x) b)))) (${W} f (${dc} a b))) :pattern ((${W} f (${dc} a b)))))`),$(`FunSetElim1`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (${W} f (${dc} a b)) (and (${uc} f) (= (${J} f) a))) :pattern ((${W} f (${dc} a b)))))`),$(`FunSetElim2`,[],`(forall ((a Idv) (b Idv) (f Idv) (x Idv)) (! (=> (and (${W} f (${dc} a b)) (${W} x a)) (${W} (${q} f x) b)) :pattern ((${W} f (${dc} a b)) (${W} x a)) :pattern ((${W} f (${dc} 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=`(${fc} f x y)`;return a(3,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunExceptIsafcn`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (${uc} ${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(Vc),...t.records.flatMap(Hc)])}case`Seq`:return a(1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`Cast_Int`,`Proj_Int`],[$(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${uc} s) (>= (${K} (${X} s)) 0) (forall ((i Idv)) (= (${W} i (${J} s)) (and (${W} i ${oc}) (<= 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 (${uc} s) (${W} (${X} s) ${sc}) (= (${J} s) (${lc} (${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) (${lc} (${G} 1) (${G} z)))) (= (${X} s) (${G} z))))`)]);case`BSeq`:return a(1,[],[]);case`Cat`:return a(2,Kc,[$(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${W} s (${Y} a)) (${W} t (${Y} a))) (${W} (${hc} s t) (${Y} a))) :pattern ((${W} s (${Y} a)) (${hc} s t)) :pattern ((${W} t (${Y} a)) (${hc} s t))))`),$(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${W} (${X} s) ${sc}) (${W} (${X} t) ${sc})) (= (${X} (${hc} s t)) (${G} (+ (${K} (${X} s)) (${K} (${X} t)))))) :pattern ((${hc} s t))))`),$(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${W} (${X} s) ${sc}) (${W} (${X} t) ${sc}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${hc} s t) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${hc} s t) (${G} i))) :pattern ((${hc} s t) (${q} s (${G} i)))))`),$(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${W} (${X} s) ${sc}) (${W} (${X} t) ${sc}) (<= i (+ (${K} (${X} s)) (${K} (${X} t)))) (< (${K} (${X} s)) i)) (= (${q} (${hc} s t) (${G} i)) (${q} t (${G} (- i (${K} (${X} s))))))) :pattern ((${q} (${hc} s t) (${G} i)))))`)]);case`Append`:return a(2,Kc,[$(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${W} s (${Y} a)) (${W} x a)) (${W} (${gc} s x) (${Y} a))) :pattern ((${W} s (${Y} a)) (${gc} s x))))`),$(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${W} (${X} s) ${sc}) (= (${X} (${gc} s x)) (${G} (+ (${K} (${X} s)) 1)))) :pattern ((${gc} s x))))`),$(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${W} (${X} s) ${sc}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${gc} s x) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${gc} s x) (${G} i))) :pattern ((${gc} s x) (${q} s (${G} i)))))`),$(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${W} (${X} s) ${sc}) (= (${q} (${gc} s x) (${G} (+ (${K} (${X} s)) 1))) x)) :pattern ((${gc} s x))))`)]);case`Head`:return a(1,[`FunApp`,`Cast_Int`],[$(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${_c} s) (${q} s (${G} 1))) :pattern ((${_c} s))))`)]);case`Tail`:return a(1,Kc,[$(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${W} s (${Y} a)) (distinct (${K} (${X} s)) 0)) (${W} (${vc} s) (${Y} a))) :pattern ((${W} s (${Y} a)) (${vc} s))))`),$(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${W} (${X} s) ${sc}) (distinct (${K} (${X} s)) 0)) (= (${X} (${vc} s)) (${G} (- (${K} (${X} s)) 1)))) :pattern ((${vc} s))))`),$(`SeqTailApp`,[],`(forall ((s Idv) (i Int)) (! (=> (and (${W} (${X} s) ${sc}) (distinct (${K} (${X} s)) 0) (<= 1 i) (<= i (- (${K} (${X} s)) 1))) (= (${q} (${vc} s) (${G} i)) (${q} s (${G} (+ i 1))))) :pattern ((${q} (${vc} s) (${G} i)))))`)]);case`SubSeq`:{let e=`(${yc} 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(Ec(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) ${oc}) :pattern ((${G} z))))`),$(`TypeGuardElim`,[`Int`],`(forall ((x Idv)) (! (=> (${W} x ${oc}) (= x (${G} (${K} x)))) :pattern ((${W} x ${oc}))))`)]);case`Cast_Bool`:return n(Ec(r,1,`Idv`,`Bool`),[`Mem`,`BoolSet`,`Tt_Idv`],[$(`CastInjAlt`,[`Bool`],`(and (= (${rc} true) ${nc}) (distinct (${rc} false) ${nc}))`),$(`TypeGuardIntro`,[`Bool`],`(forall ((z Bool)) (! (${W} (${rc} z) ${ic}) :pattern ((${rc} z))))`),$(`TypeGuardElim`,[`Bool`],`(forall ((x Idv)) (! (=> (${W} x ${ic}) (or (= x (${rc} true)) (= x (${rc} false)))) :pattern ((${W} x ${ic}))))`)]);case`Proj_Int`:return n(Ec(r,1,`Int`),[],[]);case`TrigEq_Set$Idv$`:return a(2,[`SetExtTrigger`],[$(`ExtTrigEqDef`,[`Set$Idv$`],`(forall ((x Idv) (y Idv)) (! (= (${pc} x y) (= x y)) :pattern ((${pc} x y))))`),$(`ExtTrigEqTrigger`,[`Idv`],`(forall ((x Idv) (y Idv)) (! (${Ys} x y) :pattern ((${pc} 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`],[Ic(`IntLteq`)]);default:if(e.startsWith(`TIntLit_`))return n(void 0,[],[]);throw new i(`the symbol ${e}`)}},Jc=(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(Vs)[0];if(t.delete(e),a.has(e))continue;let n=qc(e,i);a.set(e,n),n.deps.forEach(e=>t.add(e)),n.axioms.forEach(e=>o.set(Mc(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=Js(i);return t!==void 0&&s(t),e}return o.kind!==``&&s(o.kind),n[a-1]===`(`?r.push({depth:e,text:o.visit}):c(o.visit),e},0)};return e.forEach(e=>{typeof e==`string`?c(e):`omitted`in e&&c(e.omitted)}),{symbols:a,axioms:o}},Yc=(e,t)=>t===0?e:`${e}_${t}`,Xc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Set;return{names:t,adjoin:n=>{let r=Ws(n),i=(e.get(r)??-1)+1,a=Array.from({length:t.size+1},(e,t)=>i+t).find(e=>!t.has(Yc(r,e)))??i;return{base:r,salt:a,name:Yc(r,a)}},enter:n=>{let r=e.get(n.base);return e.set(n.base,n.salt),t.add(n.name),()=>{t.delete(n.name),r===void 0?e.delete(n.base):e.set(n.base,r)}}}},Zc=e=>{let t=Xc();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(``)}}},Qc=(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)),$c=e=>e.length===1?e[0]:k(`Conj`,[e[0],$c(e.slice(1))],e[0]),el=(e,t,n)=>e.kind!==`Record`||t.kind!==`Record`||!Qc(e,t)?k(`Eq`,[e,t],n):$c(e.fields.map(e=>el(e.value,t.fields.find(t=>t.name===e.name)?.value??e.value,n))),tl=e=>{let t=Ue(e,tl);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`?O(el(t.args[0],t.args[1],t),t):t},nl=e=>e.kind===`Record`||e.kind===`Rect`?{...e,fields:e.fields.toSorted((e,t)=>Vs(e.name,t.name))}:Ue(e,nl),rl=(e,t)=>`${e}#${t}`,il=e=>Number(e.slice(e.lastIndexOf(`#`)+1)),al=`?unprimable`,ol=e=>{let t=e.indexOf(`(${al} `);if(t===-1)return e;let n=Dc(e,t);return e.slice(0,t)+ol(e.slice(t+11+2,n))+ol(e.slice(n+1))},sl=(e,t)=>/\((forall|exists|ite) /.test(e)?void 0:e.replace(/[^\s()]+#(\d+)/g,(e,n)=>Number(n)<t?`#`:`#${Number(n)-t}`),cl=()=>{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=Ws(`${l}_omitted_${e.size}`);return e.set(t,{symbol:t,kind:i,visit:ol(a),getLines:()=>[]}),t}let u=sl(`${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=Ws(f),m={symbol:p,kind:i,visit:ol(a),getLines:e=>[Ec(p,c),...s(p,e).map(e=>`(assert (! ${ol(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)}},ll=`?trigger`,ul=/* @__PURE__ */ new Set([tc,ec,Zs,Qs,$s,lc,dc,Y]),dl=e=>{let t=/^\(?([^\s()]+)/.exec(e)?.[1]??``;return ul.has(t)||/^smt__TLA____(SetEnum__\d+|SetSt__flatnd__\d+|SetOf__\d+__flatnd__\d+|Product__\d+|RecordSet__)/.test(t)},fl=(e,t)=>{let n=e.indexOf(`(${ll} `);if(n===-1)return e;let r=n+8+2,i=Dc(e,r)+1,a=Dc(e,i+1)+1,o=t?e.slice(r,i):e.slice(i+1,a);return e.slice(0,n)+o+fl(e.slice(a+1),t)},pl=(e,t,n,r)=>{let i=`(${pc} ${e} ${t})`,a=r?`(distinct ${e} ${t})`:`(= ${e} ${t})`;if(!dl(e)&&!dl(t))return a;let o=r?`(not ${i})`:i;return n===(r?`Positive`:`Negative`)?`(${ll} ${o} ${a})`:o},ml=(e,t,n,r)=>{let i=Q(e,[`a`,...t]);return[$(`SetStDef`,[],Z([...t,`a`,`x`],`(= (${W} x ${i}) (and (${W} x a) ${Oc(n,r,`x`)}))`,[[`(${W} x ${i})`],[`(${W} x a)`,i]]))]},hl=(e,t,n,r)=>{let i=r.length,a=Sc(`a`,i),o=Sc(`y`,i),s=r.reduce((e,t,n)=>Oc(e,t,o[n]),n),c=Q(e,[...a,...t]),l=o.map((e,t)=>`(${W} ${e} ${a[t]})`),u=i===1?[`a`]:a;return[$(`SetOfIntro`,[i],Z([...t,...a,...o],`(=> ${wc(l)} (${W} ${s} ${c}))`,[[s,c],[c,...l]])),$(`SetOfElim`,[i],Z([...t,...a,`x`],`(=> (${W} x ${c}) (exists (${Cc(o)}) ${wc([...l,`(= x ${s})`])}))`,[[`(${W} x ${c})`]])),$(`AssertIsSetOf`,[i],Z([...t,...u],`(${mc} ${Q(e,[...u,...t])})`,[[Q(e,[...u,...t])]]))]},gl=(e,t,n,r,i)=>{let a=Q(e,[`a`,...t]),o=Oc(n,r,`x`),s=i.has(Mc($(`FunTyping`,[],void 0)))?[$(`FunTyping`,[],Z([...t,`a`,`b`],`(=> (forall ((x Idv)) (=> (${W} x a) (${W} ${o} b))) (${W} ${a} (${dc} a b)))`,[[a,`(${dc} a b)`]]))]:[];return[$(`FunConstrIsafcn`,[],Z([...t,`a`],`(${uc} ${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]},_l=(e,t,n,r)=>[$(`ChooseDef`,[],Z([...t,`x`],`(=> ${Oc(n,r,`x`)} ${Oc(n,r,Q(e,t))})`))],vl=(e,t,n,r)=>{let i=n=>Q(e,[n,...t]),a=e=>Oc(n,r,e),o=i(`(${gc} 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) ${sc}) (<= (${K} (${X} ${i(`s`)})) (${K} (${X} s))))`,[[i(`s`)]])),$(`SeqSelectseqNil`,[],Z(t,`(= ${i(bc)} ${bc})`)),$(`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} (${gc} ${i(`s`)} x))) (=> (not ${a(`x`)}) (= ${o} ${i(`s`)})))`,[[o]]))]},yl=e=>{let t=cl(),n=t.flatten,r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=Xc(),s=/* @__PURE__ */ new Map,c=e=>e.isBool?e.text:`(= ${fl(e.text,!0)} ${nc})`,l=e=>e.isBool?`(${rc} ${fl(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=>il(e)<t).toSorted((e,t)=>il(e)-il(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}),te=(e,t,n)=>{let r=e.map((e,t)=>rl(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}}},ne=(e,t,n)=>{let r=b(e.bounds,t,n),i=te(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 (${Cc(i.variables)}) ${o.length===0?a:`(=> ${wc(o)} ${a})`})`:`(exists (${Cc(i.variables)}) ${wc([...o,a])})`},re=(e,t,r)=>{let i=v(e.domain,t,r),a=te([e.name],t,g(r)),o=y(e.body,a.env,a.mode),s=m(o,r.depth),c=n(`SetSt`,o,r,e=>ml(e,s,o,a.variables[0]),s.length+1);return d(Q(c,[i,...s]))},x=(e,t,r)=>{let i=ee(e.bounds,t,r,`a set of values`),a=te(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=>hl(e,s,o,a.variables),c+s.length);return d(Q(l,[...i,...s]))},S=(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=rl(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}):Rc(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)=>gl(e,u,l,o,t),u.length+1);return d(Q(f,[a,...u]))},ie=(e,t,r)=>{let i=te([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:wc([o,s]),l=m(c,r.depth),u=n(`Choose`,c,r,e=>_l(e,l,c,a),l.length);return d(Q(u,l))},ae=(e,t,n,r)=>pl(v(e[0],t,n),v(e[1],t,n),n.polarity,r),oe=(e,t,n)=>{let r=e.kind===`Lambda`&&e.params.length===1?e:void 0,i=te([r?.params[0].name??`x1`],t,g(n));return{body:y(r?.body??{kind:`Apply`,operator:F(1,e),args:[{kind:`Ix`,index:1}]},i.env,i.mode),variable:i.variables[0]}},se=(e,t,r,a)=>{let o=()=>t.map(e=>v(e,r,a));switch(e){case`Conj`:return u(wc(t.map(e=>y(e,r,a))));case`Disj`:return u(Tc(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(ae(t,r,a,!1));case`Neq`:return u(ae(t,r,a,!0));case`Mem`:return u(Q(W,o()));case`Notmem`:return u(`(not ${Q(W,o())})`);case`Subseteq`:return u(Q(Xs,o()));case`Lteq`:return u(Q(cc,o()));case`Gteq`:return u(Q(cc,o().toReversed()));case`Lt`:case`Gt`:{let t=()=>e===`Lt`?o():o().toReversed();return u(`(and ${Q(cc,t())} (distinct ${t().join(` `)}))`)}case`SelectSeq`:{let e=oe(t[1],r,a),i=m(e.body,a.depth),o=n(`SelectSeq`,e.body,a,t=>vl(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:`(${al} ${e.text})`}}default:{let t=xc[e];if(t===void 0)throw new i(`the operator ${e}`);return d(Q(t,o()))}}},ce=(e,t,r,a)=>{switch(e.kind){case`constant`:case`variable`:if(t.length>0)throw new i(`an applied ${e.kind}`);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=te(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)}},le=(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:le(e.rest,t)},ue=(e,t,n,i)=>{if(t.length===0&&e.endsWith(`#prime`))return d(le(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))))},de=(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`(${fc} ${e} ${c} ${l})`};return i(e,r.trail)},v(e.function,t,n)),fe=()=>{e.caseErrors++;let t=`Anon_incomplete_case_error_${e.caseErrors}`;return r.set(t,0),U(t)},pe=(e,t,n)=>{let r=e.arms.map(e=>w(e.body,t,n)),i=e.other?w(e.other,t,n):d(fe()),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))}},C=(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=rl(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=te([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 ce(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(ic);case`STRING`:return d(ac);case`Nat`:return d(sc);case`Int`:return d(oc);default:throw new i(`the operator ${e.builtin}`)}case`Apply`:{let r=e.operator;if(r.kind===`Internal`)return se(r.builtin,e.args,t,n);if(r.kind===`Ix`)return ce(f(t,r.index),e.args,t,n);if(r.kind===`Opaque`)return ue(r.name,e.args,t,n);if(r.kind===`Lambda`)return w({...we(r,e.args)},t,n);throw new i(`an application of ${r.kind}`)}case`Sequent`:return u(C(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 ${fl(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`?Tc(r):wc(r))}case`Opaque`:return ue(e.name,[],t,n);case`Quant`:return u(ne(e,t,n));case`Choose`:return ie(e,t,n);case`SetSt`:return re(e,t,n);case`SetOf`:return x(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 S(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(dc,[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(de(e,t,n));case`Dot`:return d(`(${q} ${v(e.expression,t,n)} ${U(`StrLit_${e.field}`)})`);case`Case`:return pe(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(),ol(fl(e,!1))],getUniqueName:h,flattened:t.flattened,anonymous:r,recordFields:a,declared:s}},bl={isOmitted:!1,polarity:`Negative`,at:void 0,depth:0},xl=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:A(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=Ec(i,n.shape);if(!n.domain||n.domainVisibility===`Hidden`)return r(a,[o]);let s=`(assert (${W} ${i} ${t.encodeIdv(n.domain,e.env,bl)}))`;return r(a,[o,...t.getEntries(s)])}case`Flex`:{let e=t.getUniqueName(n.name),i=t.getUniqueName(`${n.name}_prime`);return r({kind:`variable`,name:n.name,symbol:e,primed:i},[Ec(e,0),Ec(i,0)])}case`Defn`:{let e=n.definition;if(xl(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},[Ec(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},[Ec(o,a.length)])}case`Fact`:{let i={kind:`unsupported`,reason:`a reference to a fact`};if(n.visibility===`Hidden`)return r(i);let a=Sl(n.expression),o=t.getEntries(`(assert ${t.encodeBool(n.expression,e.env,{...bl,isOmitted:a})})`);return r(i,a?o.map(e=>typeof e==`string`?{omitted:e}:e):o)}}},{env:void 0,scope:void 0,entries:[]}),wl=(e,t)=>{let n=nl(tl({kind:`Sequent`,sequent:e})),r=n.kind===`Sequent`?n.sequent:e,i=yl(t),a=Cl(r.context,i),o=Sl(r.active)?[]:i.getEntries(`(assert (! (not ${i.encodeBool(r.active,a.env,{...bl,polarity:`Positive`})}) :named |Goal|))`),s=[...a.entries,...o],c=Zc(i.declared),l=Jc(s,i.flattened,i.anonymous,i.recordFields),u=[...l.symbols].toSorted((e,t)=>Vs(e[0],t[0])).flatMap(e=>e[1].declaration===void 0?[]:[e[1].declaration]),d=[...l.axioms.values()].toSorted(Pc).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`)&&!xl(e))?[`(declare-sort Idv 0)`]:[],...p].map(c.resolve).concat(`(check-sat)`,`(exit)`).join(`
33
+ `)},Tl=z(`@ `),El={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`},Dl={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]},Ol={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},kl=e=>{let t=Number.parseInt(e,10);return`${`(TLA.fapply TLA.Succ `.repeat(t)}0${`)`.repeat(t)}`},Al=(e,t)=>{let n=sn(),a=e=>ln(n,Da(e)),o=()=>ln(n,``),c=e=>B(e,g,Tl),l=(e,t)=>z(`(%s %a)`,e,c(t)),u=(e,t,r,i)=>{let o=a(e),s=z(`%a((%s) %a)%s`,t,o,g(r),i);return un(n,1),s},d=(e,t)=>{let n=El[e];if(n!==void 0&&t.length===0)return R(n);let i=Dl[e];if(i&&i[1]===t.length)return l(i[0],t);if(t.length===2)switch(e){case`Neq`:return z(`(-. %a)`,l(`=`,t));case`Notmem`:return z(`(-. %a)`,l(`TLA.in`,t));case`Minus`:return l(`arith.add`,[t[0],{kind:`Apply`,operator:{kind:`Internal`,builtin:`Uminus`,location:t[1].location},args:[t[1]],location:t[1].location}]);case`Gteq`:return l(`arith.le`,t.toReversed());case`Gt`:return l(`arith.lt`,t.toReversed())}if(e===`Unprimable`&&t.length===1)return g(t[0]);if((e===`Prime`||e===`StrongPrime`||e===`UNCHANGED`)&&t.length===1)throw new r;let a=Ol[e];throw a&&a[1]===t.length?new s(`Unsupported operator \`${a[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?R(i):l(i,t)}case`Opaque`:{let n=Da(e.name);return t.length===0?R(n):l(n,t)}case`Internal`:return d(e.builtin,t);case`Lambda`:{let t=e.params.map(e=>z(`%s `,a(e.name))),r=z(`((%a) %a)`,t,g(e.body));return un(n,e.params.length),r}default:throw new r}},p=(e,t,n)=>{if(t.length===0)return g(n);let i=t[0],a=t.slice(1),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:F(1,e.domain.expression)}}:e),body:n,location:n.location},c=e===`Forall`;if(i.domain.kind===`NoDomain`)return u(i.name,R(c?`(A. `:`(E. `),s,`)`);if(i.domain.kind!==`Domain`)throw new r;let l=g(i.domain.expression);return u(i.name,z(`(%s %a `,c?`TLA.bAll`:`TLA.bEx`,l),s,`)`)},m=(e,t,n,a)=>{if(t.length!==1)throw new i(`${a} (multiple declared constants)`);let o=t[0];if(o.domain.kind!==`Domain`)throw new r;return u(o.name,z(`(%s %a `,e,g(o.domain.expression)),n,`)`)},h=e=>{if(e.context.length===0)return g(e.active);let t=e.context[0],i=()=>h({context:e.context.slice(1),active:e.active});if(t.kind===`Fact`){let e=t.visibility===`Visible`?g(t.expression):void 0;o();let r=e?z(`(=> %a %a)`,e,i()):i();return un(n,1),r}if(t.kind===`Defn`)throw new r;let s=t.kind===`Fresh`&&t.domain&&t.domainVisibility===`Visible`?g(t.domain):void 0,c=a(t.name),l=t.kind===`Flex`?z(`(A. ((%s) (A. ((%s') %a))))`,c,c,i()):s?z(`(TLA.bAll %a ((%s) %a))`,s,c,i()):z(`(A. ((%s) %a))`,c,i());return un(n,1),l},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 z(`(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]):z(`(%s %a)`,e.bullet===`Or`?`\\/`:`/\\`,c(e.items));case`Quant`:return p(e.quantifier,e.bounds,e.body);case`Tquant`:throw new i(`\\AA or \\EE`);case`Choose`:return e.domain?u(e.name,z(`(TLA.bChoice %a `,g(e.domain)),e.body,`)`):u(e.name,R(`(t. `),e.body,`)`);case`SetSt`:return u(e.name,z(`(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?R(`TLA.emptyset`):[R(`(TLA.set`),e.elements.map(e=>z(` %a`,g(e))),R(`)`)];case`FcnApp`:{let t=g(e.function);return e.args.length===1?z(`(TLA.fapply %a %a)`,t,g(e.args[0])):z(`(TLA.fapply %a (TLA.tuple %a))`,t,c(e.args))}case`Arrow`:return z(`(TLA.FuncSet %a %a)`,g(e.domain),g(e.range));case`Rect`:case`Record`:return[R(e.kind===`Rect`?`(TLA.recordset`:`(TLA.record`),e.fields.map(e=>z(` "%s" %a`,e.name,g(e.value))),R(`)`)];case`Except`:{let t=e.specs[0];if(e.specs.length!==1||t.trail.length!==1)throw new i(`complex EXCEPT`);let n=t.trail[0],r=n.kind===`Dot`?R(`"${n.field}"`):g(n.expression);return z(`(TLA.except %a %a %a)`,g(e.function),r,g(t.value))}case`Dot`:return z(`(TLA.fapply %a "%s")`,g(e.expression),e.field);case`Tuple`:return z(`(TLA.tuple %a)`,c(e.elements));case`Product`:return e.factors.length===2?z(`(TLA.prod %a %a)`,g(e.factors[0]),g(e.factors[1])):z(`(TLA.Product (TLA.tuple %a))`,c(e.factors));case`Sub`:case`Tsub`:case`Fair`:throw new i(e.kind);case`Case`:{let t=B(e.arms,e=>z(`%a %a`,g(e.condition),g(e.body)),Tl);return e.other?z(`(TLA.CASE %a %a)@]`,t,g(e.other)):z(`(TLA.CASE %a )`,t)}case`String`:return z(`"%s"`,e.value);case`Num`:if(e.fraction!==``)throw new i(`Real number constants`);return R(kl(e.integer));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?z(`$hyp "%s_in" (TLA.in %s %a)@
34
+ `,n,n,t):[]}case`Flex`:return a(e.name),[];case`Defn`:{let t=a(e.definition.name);return e.visibility===`Visible`?z(`; 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?z(`; omitted temporal assumption : %s @.`,r.message):r?z(`$hyp "v'%s" %a@
35
+ `,t,r):[]}}},y=(()=>{try{return[t.context.map(v),z(`$goal %a`,g(t.active))]}catch(e){throw e instanceof i?new s(`Zenon: unsupported operator ${e.message}`):e}})();return an([z(`;; obligation #%s@
36
+ `,String(e)),y])},jl=`------------------------------- MODULE TLAPS --------------------------------
37
+
38
+ (* Backend pragmas. *)
39
+
40
+
41
+ (***************************************************************************)
42
+ (* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
43
+ (* is added to the context of an obligation most recently is the one whose *)
44
+ (* effects are triggered. *)
45
+ (***************************************************************************)
46
+
47
+ (***************************************************************************)
48
+ (* The following pragmas should be used only as a last resource. They are *)
49
+ (* dependent upon the particular backend provers, and are unlikely to have *)
50
+ (* any effect if the set of backend provers changes. Moreover, they are *)
51
+ (* meaningless to a reader of the proof. *)
52
+ (***************************************************************************)
53
+
54
+
55
+ (**************************************************************************)
56
+ (* Backend pragma: use the SMT solver for arithmetic. *)
57
+ (* *)
58
+ (* This method exists under this name for historical reasons. *)
59
+ (**************************************************************************)
60
+
61
+ SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
62
+
63
+
64
+ (**************************************************************************)
65
+ (* Backend pragma: SMT solver *)
66
+ (* *)
67
+ (* This method translates the proof obligation to SMTLIB2. The supported *)
68
+ (* fragment includes first-order logic, set theory, functions and *)
69
+ (* records. *)
70
+ (* SMT calls the smt-solver with the default timeout of 5 seconds *)
71
+ (* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
72
+ (* *)
73
+ (* SMTT also accepts a string argument of the form "rN" to bound the *)
74
+ (* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
75
+ (* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
76
+ (* resource count, so a small readable budget like "r5" is meaningful. *)
77
+ (* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
78
+ (* speed or load, so the proof's pass/fail outcome reproduces on any *)
79
+ (* machine and every rerun (for a fixed Z3 build); how long it takes to *)
80
+ (* consume the budget still varies by machine. This is Z3-specific. *)
81
+ (**************************************************************************)
82
+
83
+ SMT == TRUE (*{ by (prover:"smt3") }*)
84
+ SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
85
+
86
+
87
+ (**************************************************************************)
88
+ (* Backend pragma: CVC4 SMT solver *)
89
+ (* *)
90
+ (* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
91
+ (**************************************************************************)
92
+
93
+ (* The CVC3* methods are here for backward compatibility. They call CVC4. *)
94
+ CVC3 == TRUE (*{ by (prover: "cvc33") }*)
95
+ CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
96
+
97
+ CVC4 == TRUE (*{ by (prover: "cvc33") }*)
98
+ CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
99
+
100
+
101
+ (**************************************************************************)
102
+ (* Backend pragma: Yices SMT solver *)
103
+ (* *)
104
+ (* This method translates the proof obligation to Yices native language. *)
105
+ (**************************************************************************)
106
+
107
+ Yices == TRUE (*{ by (prover: "yices3") }*)
108
+ YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
109
+
110
+ (**************************************************************************)
111
+ (* Backend pragma: veriT SMT solver *)
112
+ (* *)
113
+ (* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
114
+ (**************************************************************************)
115
+
116
+ veriT == TRUE (*{ by (prover: "verit") }*)
117
+ veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
118
+
119
+ (**************************************************************************)
120
+ (* Backend pragma: Zipperposition solver *)
121
+ (* *)
122
+ (* This method translates the proof obligation to TPTP and *)
123
+ (* calls Zipperposition. *)
124
+ (**************************************************************************)
125
+
126
+ Zipper == TRUE (*{ by (prover: "zipper") }*)
127
+ ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
128
+
129
+ (**************************************************************************)
130
+ (* Backend pragma: Z3 SMT solver *)
131
+ (* *)
132
+ (* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
133
+ (* Z3 is used by default but you can also explicitly call it. *)
134
+ (* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
135
+ (* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
136
+ (* reproduces the same outcome on any machine (see SMTT). *)
137
+ (**************************************************************************)
138
+
139
+ Z3 == TRUE (*{ by (prover: "z33") }*)
140
+ Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
141
+
142
+ (**************************************************************************)
143
+ (* Backend pragma: SPASS superposition prover *)
144
+ (* *)
145
+ (* This method translates the proof obligation to the DFG format language *)
146
+ (* supported by the ATP SPASS. The translation is based on the SMT one. *)
147
+ (**************************************************************************)
148
+
149
+ Spass == TRUE (*{ by (prover: "spass") }*)
150
+ SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
151
+
152
+ (**************************************************************************)
153
+ (* Backend pragma: The PTL propositional linear time temporal logic *)
154
+ (* prover. It currently is the LS4 backend. *)
155
+ (* *)
156
+ (* This method translates the negetation of the proof obligation to *)
157
+ (* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
158
+ (**************************************************************************)
159
+
160
+ LS4 == TRUE (*{ by (prover: "ls4") }*)
161
+ LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
162
+ PTL == TRUE (*{ by (prover: "ls4") }*)
163
+
164
+ (**************************************************************************)
165
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
166
+ (* *)
167
+ (**************************************************************************)
168
+
169
+ Zenon == TRUE (*{ by (prover:"zenon") }*)
170
+ ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
171
+
172
+ (********************************************************************)
173
+ (* Backend pragma: Isabelle with different timeouts and tactics *)
174
+ (* (default is 30 seconds/auto) *)
175
+ (********************************************************************)
176
+
177
+ Isa == TRUE (*{ by (prover:"isabelle") }*)
178
+ IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
179
+ IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
180
+ IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
181
+
182
+ (***************************************************************************)
183
+ (* The following theorem expresses the (useful implication of the) law of *)
184
+ (* set extensionality, which can be written as *)
185
+ (* *)
186
+ (* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
187
+ (* *)
188
+ (* Theorem SetExtensionality is sometimes required by the SMT backend for *)
189
+ (* reasoning about sets. It is usually counterproductive to include *)
190
+ (* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
191
+ (* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
192
+ (* the Isabelle backend to use the rule of set extensionality. *)
193
+ (***************************************************************************)
194
+ IsaWithSetExtensionality == TRUE
195
+ (*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
196
+
197
+ THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
198
+ OBVIOUS
199
+
200
+ (***************************************************************************)
201
+ (* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
202
+ (* the definition *)
203
+ (* *)
204
+ (* NotInSetS == CHOOSE v : v \\notin SetS *)
205
+ (***************************************************************************)
206
+ THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
207
+ OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
208
+ -----------------------------------------------------------------------------
209
+
210
+
211
+
212
+ (********************************************************************)
213
+ (********************************************************************)
214
+ (********************************************************************)
215
+
216
+
217
+ (********************************************************************)
218
+ (* Old versions of Zenon and Isabelle pragmas below *)
219
+ (* (kept for compatibility) *)
220
+ (********************************************************************)
221
+
222
+
223
+ (**************************************************************************)
224
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
225
+ (* *)
226
+ (**************************************************************************)
227
+
228
+ SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
229
+ SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
230
+ VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
231
+ SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
232
+
233
+
234
+
235
+ (********************************************************************)
236
+ (* Backend pragma: Isabelle's automatic search ("auto") *)
237
+ (* *)
238
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
239
+ (* essentially simplification and equational reasoning. *)
240
+ (* Default imeout for all isabelle tactics is 30 seconds. *)
241
+ (********************************************************************)
242
+ Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
243
+ SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
244
+ SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
245
+ SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
246
+
247
+ (********************************************************************)
248
+ (* Backend pragma: Isabelle's "force" tactic *)
249
+ (* *)
250
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
251
+ (* quantifier reasoning. *)
252
+ (********************************************************************)
253
+ Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
254
+ SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
255
+ SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
256
+ SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
257
+
258
+ (***********************************************************************)
259
+ (* Backend pragma: Isabelle's "simplification" tactics *)
260
+ (* *)
261
+ (* These tactics simplify the goal before running one of the automated *)
262
+ (* tactics. They are often necessary for obligations involving record *)
263
+ (* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
264
+ (* sure you can get away with just Simplification *)
265
+ (***********************************************************************)
266
+ SimplifyAndSolve == TRUE
267
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
268
+ SlowSimplifyAndSolve == TRUE
269
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
270
+ SlowerSimplifyAndSolve == TRUE
271
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
272
+ SlowestSimplifyAndSolve == TRUE
273
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
274
+
275
+ Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
276
+ SlowSimplification == TRUE
277
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
278
+ SlowerSimplification == TRUE
279
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
280
+ SlowestSimplification == TRUE
281
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
282
+
283
+ (**************************************************************************)
284
+ (* Backend pragma: Isabelle's tableau prover ("blast") *)
285
+ (* *)
286
+ (* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
287
+ (* prover, Blast. It is almost never better than Zenon by itself, but *)
288
+ (* becomes very useful in combination with the Auto pragma above. The *)
289
+ (* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
290
+ (* Auto could not prove. (There is currently no way to use Zenon on the *)
291
+ (* results left over from Auto.) *)
292
+ (**************************************************************************)
293
+ Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
294
+ SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
295
+ SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
296
+ SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
297
+
298
+ AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
299
+
300
+
301
+ (**************************************************************************)
302
+ (* Backend pragmas: multi-back-ends *)
303
+ (* *)
304
+ (* These pragmas just run a bunch of back-ends one after the other in the *)
305
+ (* hope that one will succeed. This saves time and effort for the user at *)
306
+ (* the expense of computation time. *)
307
+ (**************************************************************************)
308
+
309
+ (* CVC3 goes first because it's bundled with TLAPS, then the other SMT
310
+ solvers are unlikely to succeed if CVC3 fails, so we run zenon and
311
+ Isabelle before them. *)
312
+ AllProvers == TRUE (*{
313
+ by (prover:"cvc33")
314
+ by (prover:"zenon")
315
+ by (prover:"isabelle"; tactic:"auto")
316
+ by (prover:"spass")
317
+ by (prover:"smt3")
318
+ by (prover:"yices3")
319
+ by (prover:"verit")
320
+ by (prover:"z33")
321
+ by (prover:"isabelle"; tactic:"force")
322
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
323
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
324
+ by (prover:"isabelle"; tactic:"clarsimp")
325
+ by (prover:"isabelle"; tactic:"auto, blast")
326
+ }*)
327
+ AllProversT(X) == TRUE (*{
328
+ by (prover:"cvc33"; timeout:@)
329
+ by (prover:"zenon"; timeout:@)
330
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
331
+ by (prover:"spass"; timeout:@)
332
+ by (prover:"smt3"; timeout:@)
333
+ by (prover:"yices3"; timeout:@)
334
+ by (prover:"verit"; timeout:@)
335
+ by (prover:"z33"; timeout:@)
336
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
337
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
338
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
339
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
340
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
341
+ }*)
342
+
343
+ AllSMT == TRUE (*{
344
+ by (prover:"cvc33")
345
+ by (prover:"smt3")
346
+ by (prover:"yices3")
347
+ by (prover:"verit")
348
+ by (prover:"z33")
349
+ }*)
350
+ AllSMTT(X) == TRUE (*{
351
+ by (prover:"cvc33"; timeout:@)
352
+ by (prover:"smt3"; timeout:@)
353
+ by (prover:"yices3"; timeout:@)
354
+ by (prover:"verit"; timeout:@)
355
+ by (prover:"z33"; timeout:@)
356
+ }*)
357
+
358
+ AllIsa == TRUE (*{
359
+ by (prover:"isabelle"; tactic:"auto")
360
+ by (prover:"isabelle"; tactic:"force")
361
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
362
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
363
+ by (prover:"isabelle"; tactic:"clarsimp")
364
+ by (prover:"isabelle"; tactic:"auto, blast")
365
+ }*)
366
+ AllIsaT(X) == TRUE (*{
367
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
368
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
369
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
370
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
371
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
372
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
373
+ }*)
374
+
375
+
376
+ (**************************************************************************)
377
+ (* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
378
+ (* *)
379
+ (* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
380
+ (* *)
381
+ (* The pragma AutoUSE invokes automated expansion of definitions, *)
382
+ (* for both of ExpandEnabled and ExpandCdot, when each is present. *)
383
+ (* *)
384
+ (* The pragma Lambdify invokes expansion of the operators *)
385
+ (* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
386
+ (* which is a form before introducing rigid quantifiers. *)
387
+ (* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
388
+ (* that are not nested. *)
389
+ (**************************************************************************)
390
+ ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
391
+ ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
392
+ AutoUSE == TRUE (*{ by (prover:"autouse") }*)
393
+ Lambdify == TRUE (*{ by (prover:"lambdify") }*)
394
+ ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
395
+ LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
396
+
397
+ (* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
398
+ (* representation within TLAPM. *)
399
+ EnabledWrapper(Op(_)) == FALSE
400
+ CdotWrapper(Op(_)) == FALSE
401
+
402
+ (***************************************************************************)
403
+ (* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
404
+ (* triviality checks in TLAPM. *)
405
+ (***************************************************************************)
406
+ Trivial == TRUE (*{ by (prover:"trivial") }*)
407
+
408
+
409
+ =============================================================================
410
+
411
+ The material below is obsolete: the TLA proof rules below are superseded by
412
+ the PTL decision procedure, and their formulation is unsound for the semantics
413
+ of temporal reasoning that TLAPS adopts.
414
+
415
+ ----------------------------------------------------------------------------
416
+ (***************************************************************************)
417
+ (* TEMPORAL LOGIC *)
418
+ (* *)
419
+ (* The following rules are intended to be used when TLAPS handles temporal *)
420
+ (* logic. They will not work now. Moreover when temporal reasoning is *)
421
+ (* implemented, these rules may be changed or omitted, and additional *)
422
+ (* rules will probably be added. However, they are included mainly so *)
423
+ (* their names will be defined, preventing the use of identifiers that are *)
424
+ (* likely to produce name clashes with future versions of this module. *)
425
+ (***************************************************************************)
426
+
427
+
428
+ (***************************************************************************)
429
+ (* The following proof rules (and their names) are from the paper "The *)
430
+ (* Temporal Logic of Actions". *)
431
+ (***************************************************************************)
432
+ THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
433
+ P /\\ (f' = f) => P'
434
+ PROVE []P <=> P /\\ [][P => P']_f
435
+
436
+ THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
437
+ ACTION A, ACTION B,
438
+ P /\\ [A]_f => Q /\\ [B]_g
439
+ PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
440
+
441
+ THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
442
+ I /\\ [N]_F => I'
443
+ PROVE I /\\ [][N]_F => []I
444
+
445
+ THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
446
+ PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
447
+
448
+ THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
449
+ P /\\ [N]_f => (P' \\/ Q'),
450
+ P /\\ <<N /\\ A>>_f => Q',
451
+ P => ENABLED <<A>>_f
452
+ PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
453
+
454
+ THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
455
+ ACTION N, ACTION A, TEMPORAL F,
456
+ P /\\ [N]_f => (P' \\/ Q'),
457
+ P /\\ <<N /\\ A>>_f => Q',
458
+ []P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
459
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
460
+
461
+ (***************************************************************************)
462
+ (* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
463
+ (* from the following two rules by the following substitutions: \`. *)
464
+ (* *)
465
+ (* ___ ___ _______________ *)
466
+ (* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
467
+ (***************************************************************************)
468
+ THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
469
+ ACTION A, ACTION B, ACTION N, ACTION M,
470
+ TEMPORAL F,
471
+ <<N /\\ B>>_f => <<M>>_g,
472
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
473
+ P /\\ EM => ENABLED A,
474
+ [][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
475
+ PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
476
+
477
+ THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
478
+ ACTION A, ACTION B, ACTION N, ACTION M,
479
+ TEMPORAL F,
480
+ <<N /\\ B>>_f => <<M>>_g,
481
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
482
+ P /\\ EM => ENABLED A,
483
+ [][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
484
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
485
+
486
+
487
+ (***************************************************************************)
488
+ (* The following rule is a special case of the general temporal logic *)
489
+ (* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
490
+ (* general rule is for arbitrary temporal formulas F and G, but it cannot *)
491
+ (* yet be handled by TLAPS. *)
492
+ (***************************************************************************)
493
+ THEOREM RuleInvImplication ==
494
+ ASSUME STATE F, STATE G,
495
+ F => G
496
+ PROVE []F => []G
497
+ PROOF OMITTED
498
+
499
+ (***************************************************************************)
500
+ (* The following rule is a special case of rule TLA2 from the paper "The *)
501
+ (* Temporal Logic of Actions". *)
502
+ (***************************************************************************)
503
+ THEOREM RuleStepSimulation ==
504
+ ASSUME STATE I, STATE f, STATE g,
505
+ ACTION M, ACTION N,
506
+ I /\\ I' /\\ [M]_f => [N]_g
507
+ PROVE []I /\\ [][M]_f => [][N]_g
508
+ PROOF OMITTED
509
+
510
+ (***************************************************************************)
511
+ (* The following may be used to invoke a decision procedure for *)
512
+ (* propositional temporal logic. *)
513
+ (***************************************************************************)
514
+ PropositionalTemporalLogic == TRUE
515
+ =============================================================================
516
+ `,Ml=[`tla-ts`,`tlapm`],Nl=e=>Ml.some(t=>t===e),Pl=e=>bs(Eo(e)),Fl={encode:(e,t,n,r)=>(n.rlimit===void 0?``:`(set-option :rlimit ${n.rlimit})\n`)+wl(Pl(t),r)},Il={smt:Fl,z3:Fl,zenon:{encode:(e,t)=>Al(e,Pl(t))},isabelle:{encode:(e,t,n)=>Ra(e,Pl(t),n.tactic??`auto`,`tlapm_${e}`)},ls4:{encode:(e,t)=>Bs(t)}},Ll=e=>e.kind===`Case`&&e.other===void 0||We(e).some(Ll),Rl=/* @__PURE__ */ new WeakMap,zl=e=>{let t=Rl.get(e);if(t!==void 0)return t;let n=[];He(e,e=>(n.push(e),e),`all`);let r=n.some(Ll);return Rl.set(e,r),r},Bl=e=>/-{4,}\s*MODULE\s+(\w+)/.exec(e)?.[1]??`Main`,Vl=e=>({id:e.id,location:e.location,text:e.text}),Hl=(e,t,n)=>({...Vl(e),status:t,reason:n}),Ul=(e,t=ks(e))=>os(Vo(Ao(e.sequent)),t.frontends),Wl=(e,t)=>`${jn(t?Vo(Ao(e.sequent,!1)):Ul(e))}\n`,Gl=(e,t,n)=>za(e,t.flatMap((e,t)=>e.attempts.filter(e=>e.method.prover===`isabelle`&&e.isProved&&!e.isReused).map(r=>({id:e.obligation.id,sequent:Pl(Ul(n[t])),tactic:r.method.tactic??`auto`})))),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},ql=async(e,t,n,r)=>{if(e.kind.kind===`Error`)return{obligation:Hl(e,`failed`,e.kind.message),attempts:[]};let a=ks(e),o=_s(e.sequent),c=n.lastByFingerprint.get(o);n.lastByFingerprint.set(o,n.tasks[t].done),await c;let l=[],u=t=>({obligation:{...Vl(e),status:`proved`,prover:t},attempts:l}),d=t=>{n.isFingerprinted(e)||n.results.delete(o);let r=n.results.get(o)?.get(t.prover);return r?.method.tactic===t.tactic?r:void 0},f=e=>e.rlimit??e.timeLimitMs/1e3,p=e=>l.push({...e,isReused:!0,timeUsedMs:void 0}),m=d(a.provers[0]);if(m?.isProved)return p(m),u(m.method.prover);let h=Ul(e,a);if(e.kind.kind===`Support`&&As(h))return n.results.set(o,n.results.get(o)??/* @__PURE__ */ new Map),{obligation:{...Vl(e),status:`trivial`},attempts:l};let g=[],_={isDecided:!1},v=e=>{l.push(e),n.results.set(o,(n.results.get(o)??/* @__PURE__ */ new Map).set(e.method.prover,e)),_.isDecided=!0};for(let o of a.provers){let a=d(o);if(a?.isProved)return p(a),u(o.prover);if(a&&f(a.method)>=f(o)){p(a),_.isDecided=!0,g.push(`${o.prover} failed on an obligation with the same fingerprint`);continue}if(!n.isProving)continue;if(o.prover===`trivial`)return u(o.prover);let c=Il[o.prover];if(c)try{let i=c===Fl&&(h.context.some(zl)||Ll(h.active))?await Kl(n,t):{caseErrors:0},a=c.encode(e.id,h,o,i),s=await n.decide(o.prover,a,{timeLimitMs:o.timeLimitMs,signal:r},t),l=s.verdict===`unsat`;if(v({method:o,isProved:l,isReused:!1,...!l&&{reason:s.timeUsedMs>=o.timeLimitMs?`timeout`:`false`},verdict:s.verdict,timeUsedMs:s.timeUsedMs}),l)return u(o.prover);g.push(`${o.prover} answered ${s.verdict}`)}catch(e){if(e instanceof s){v({method:o,isProved:!1,isReused:!1,reason:`false`}),g.push(`${o.prover} failed: ${e.message}`);continue}if(!(e instanceof i))throw e;let t=`${o.prover} can't encode ${e.message}`;l.push({method:o,isProved:!1,isReused:!1,reason:t}),g.push(t)}else{let e=`tla-ts has no ${o.prover} backend`;l.push({method:o,isProved:!1,isReused:!1,reason:e}),g.push(e)}}return{obligation:Hl(e,_.isDecided?`failed`:`unsupported`,g.join(`, `)),attempts:l}},Jl=async(e,t)=>{try{return await t()}catch(t){if(t instanceof i)return{obligation:Hl(e,`unsupported`,t.message),attempts:[]};if(t instanceof s)return{obligation:Hl(e,`failed`,t.message),attempts:[]};throw t}},Yl=async(e,t)=>{let n=t.workers??1,r=n>1&&a()?await Sa(n):void 0,i=()=>r?.terminate(t.signal?.reason);t.signal?.addEventListener(`abort`,i);let o={tasks:[],results:t.results??/* @__PURE__ */ new Map,isFingerprinted:t.isFingerprinted??(()=>!0),isProving:t.isProving??!0,lastByFingerprint:/* @__PURE__ */ new Map,decide:r?.decide??(async(e,t,n)=>le(e,t,n))},c=r?n*4:1,l=[],u=[],d=/* @__PURE__ */ new Set,f=[],p=async()=>{for(;u[f.length];){t.signal?.throwIfAborted();let n=await l[f.length];f.push(n),t.onReport?.(n,e[f.length-1]),await new Promise(e=>setTimeout(e))}};try{for(let[n,r]of e.entries()){t.signal?.throwIfAborted();let e=Promise.withResolvers();o.tasks.push({done:e.promise,session:void 0});let i=Jl(r,()=>ql(r,n,o,t.signal));l.push(i),d.add(e.promise);let a=()=>{u[n]=!0,d.delete(e.promise),e.resolve()};i.then(a,a),d.size>=c&&await Promise.race(d),await p()}await Promise.all(d),await p()}finally{t.signal?.removeEventListener(`abort`,i),r?.terminate(new s(`prove stopped`))}return f},Xl=(e,t)=>t?{...Vl(e),...t}:Hl(e,`unsupported`,`tlapm reported no result`),Zl=async e=>{let t=Bl(e.source),n=/* @__PURE__ */ new Map,r=xa([{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 --------------------------------
517
+
518
+ (* Backend pragmas. *)
519
+
520
+
521
+ (***************************************************************************)
522
+ (* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
523
+ (* is added to the context of an obligation most recently is the one whose *)
524
+ (* effects are triggered. *)
525
+ (***************************************************************************)
526
+
527
+ (***************************************************************************)
528
+ (* The following pragmas should be used only as a last resource. They are *)
529
+ (* dependent upon the particular backend provers, and are unlikely to have *)
530
+ (* any effect if the set of backend provers changes. Moreover, they are *)
531
+ (* meaningless to a reader of the proof. *)
532
+ (***************************************************************************)
533
+
534
+
535
+ (**************************************************************************)
536
+ (* Backend pragma: use the SMT solver for arithmetic. *)
537
+ (* *)
538
+ (* This method exists under this name for historical reasons. *)
539
+ (**************************************************************************)
540
+
541
+ SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
542
+
543
+
544
+ (**************************************************************************)
545
+ (* Backend pragma: SMT solver *)
546
+ (* *)
547
+ (* This method translates the proof obligation to SMTLIB2. The supported *)
548
+ (* fragment includes first-order logic, set theory, functions and *)
549
+ (* records. *)
550
+ (* SMT calls the smt-solver with the default timeout of 5 seconds *)
551
+ (* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
552
+ (* *)
553
+ (* SMTT also accepts a string argument of the form "rN" to bound the *)
554
+ (* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
555
+ (* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
556
+ (* resource count, so a small readable budget like "r5" is meaningful. *)
557
+ (* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
558
+ (* speed or load, so the proof's pass/fail outcome reproduces on any *)
559
+ (* machine and every rerun (for a fixed Z3 build); how long it takes to *)
560
+ (* consume the budget still varies by machine. This is Z3-specific. *)
561
+ (**************************************************************************)
562
+
563
+ SMT == TRUE (*{ by (prover:"smt3") }*)
564
+ SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
565
+
566
+
567
+ (**************************************************************************)
568
+ (* Backend pragma: CVC4 SMT solver *)
569
+ (* *)
570
+ (* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
571
+ (**************************************************************************)
572
+
573
+ (* The CVC3* methods are here for backward compatibility. They call CVC4. *)
574
+ CVC3 == TRUE (*{ by (prover: "cvc33") }*)
575
+ CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
576
+
577
+ CVC4 == TRUE (*{ by (prover: "cvc33") }*)
578
+ CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
579
+
580
+
581
+ (**************************************************************************)
582
+ (* Backend pragma: Yices SMT solver *)
583
+ (* *)
584
+ (* This method translates the proof obligation to Yices native language. *)
585
+ (**************************************************************************)
586
+
587
+ Yices == TRUE (*{ by (prover: "yices3") }*)
588
+ YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
589
+
590
+ (**************************************************************************)
591
+ (* Backend pragma: veriT SMT solver *)
592
+ (* *)
593
+ (* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
594
+ (**************************************************************************)
595
+
596
+ veriT == TRUE (*{ by (prover: "verit") }*)
597
+ veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
598
+
599
+ (**************************************************************************)
600
+ (* Backend pragma: Zipperposition solver *)
601
+ (* *)
602
+ (* This method translates the proof obligation to TPTP and *)
603
+ (* calls Zipperposition. *)
604
+ (**************************************************************************)
605
+
606
+ Zipper == TRUE (*{ by (prover: "zipper") }*)
607
+ ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
608
+
609
+ (**************************************************************************)
610
+ (* Backend pragma: Z3 SMT solver *)
611
+ (* *)
612
+ (* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
613
+ (* Z3 is used by default but you can also explicitly call it. *)
614
+ (* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
615
+ (* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
616
+ (* reproduces the same outcome on any machine (see SMTT). *)
617
+ (**************************************************************************)
618
+
619
+ Z3 == TRUE (*{ by (prover: "z33") }*)
620
+ Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
621
+
622
+ (**************************************************************************)
623
+ (* Backend pragma: SPASS superposition prover *)
624
+ (* *)
625
+ (* This method translates the proof obligation to the DFG format language *)
626
+ (* supported by the ATP SPASS. The translation is based on the SMT one. *)
627
+ (**************************************************************************)
628
+
629
+ Spass == TRUE (*{ by (prover: "spass") }*)
630
+ SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
631
+
632
+ (**************************************************************************)
633
+ (* Backend pragma: The PTL propositional linear time temporal logic *)
634
+ (* prover. It currently is the LS4 backend. *)
635
+ (* *)
636
+ (* This method translates the negetation of the proof obligation to *)
637
+ (* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
638
+ (**************************************************************************)
639
+
640
+ LS4 == TRUE (*{ by (prover: "ls4") }*)
641
+ LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
642
+ PTL == TRUE (*{ by (prover: "ls4") }*)
643
+
644
+ (**************************************************************************)
645
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
646
+ (* *)
647
+ (**************************************************************************)
648
+
649
+ Zenon == TRUE (*{ by (prover:"zenon") }*)
650
+ ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
651
+
652
+ (********************************************************************)
653
+ (* Backend pragma: Isabelle with different timeouts and tactics *)
654
+ (* (default is 30 seconds/auto) *)
655
+ (********************************************************************)
656
+
657
+ Isa == TRUE (*{ by (prover:"isabelle") }*)
658
+ IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
659
+ IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
660
+ IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
661
+
662
+ (***************************************************************************)
663
+ (* The following theorem expresses the (useful implication of the) law of *)
664
+ (* set extensionality, which can be written as *)
665
+ (* *)
666
+ (* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
667
+ (* *)
668
+ (* Theorem SetExtensionality is sometimes required by the SMT backend for *)
669
+ (* reasoning about sets. It is usually counterproductive to include *)
670
+ (* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
671
+ (* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
672
+ (* the Isabelle backend to use the rule of set extensionality. *)
673
+ (***************************************************************************)
674
+ IsaWithSetExtensionality == TRUE
675
+ (*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
676
+
677
+ THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
678
+ OBVIOUS
679
+
680
+ (***************************************************************************)
681
+ (* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
682
+ (* the definition *)
683
+ (* *)
684
+ (* NotInSetS == CHOOSE v : v \\notin SetS *)
685
+ (***************************************************************************)
686
+ THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
687
+ OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
688
+ -----------------------------------------------------------------------------
689
+
690
+
691
+
692
+ (********************************************************************)
693
+ (********************************************************************)
694
+ (********************************************************************)
695
+
696
+
697
+ (********************************************************************)
698
+ (* Old versions of Zenon and Isabelle pragmas below *)
699
+ (* (kept for compatibility) *)
700
+ (********************************************************************)
701
+
702
+
703
+ (**************************************************************************)
704
+ (* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
705
+ (* *)
706
+ (**************************************************************************)
707
+
708
+ SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
709
+ SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
710
+ VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
711
+ SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
712
+
713
+
714
+
715
+ (********************************************************************)
716
+ (* Backend pragma: Isabelle's automatic search ("auto") *)
717
+ (* *)
718
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
719
+ (* essentially simplification and equational reasoning. *)
720
+ (* Default imeout for all isabelle tactics is 30 seconds. *)
721
+ (********************************************************************)
722
+ Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
723
+ SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
724
+ SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
725
+ SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
726
+
727
+ (********************************************************************)
728
+ (* Backend pragma: Isabelle's "force" tactic *)
729
+ (* *)
730
+ (* This pragma bypasses Zenon. It is useful in situations involving *)
731
+ (* quantifier reasoning. *)
732
+ (********************************************************************)
733
+ Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
734
+ SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
735
+ SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
736
+ SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
737
+
738
+ (***********************************************************************)
739
+ (* Backend pragma: Isabelle's "simplification" tactics *)
740
+ (* *)
741
+ (* These tactics simplify the goal before running one of the automated *)
742
+ (* tactics. They are often necessary for obligations involving record *)
743
+ (* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
744
+ (* sure you can get away with just Simplification *)
745
+ (***********************************************************************)
746
+ SimplifyAndSolve == TRUE
747
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
748
+ SlowSimplifyAndSolve == TRUE
749
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
750
+ SlowerSimplifyAndSolve == TRUE
751
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
752
+ SlowestSimplifyAndSolve == TRUE
753
+ (*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
754
+
755
+ Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
756
+ SlowSimplification == TRUE
757
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
758
+ SlowerSimplification == TRUE
759
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
760
+ SlowestSimplification == TRUE
761
+ (*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
762
+
763
+ (**************************************************************************)
764
+ (* Backend pragma: Isabelle's tableau prover ("blast") *)
765
+ (* *)
766
+ (* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
767
+ (* prover, Blast. It is almost never better than Zenon by itself, but *)
768
+ (* becomes very useful in combination with the Auto pragma above. The *)
769
+ (* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
770
+ (* Auto could not prove. (There is currently no way to use Zenon on the *)
771
+ (* results left over from Auto.) *)
772
+ (**************************************************************************)
773
+ Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
774
+ SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
775
+ SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
776
+ SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
777
+
778
+ AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
779
+
780
+
781
+ (**************************************************************************)
782
+ (* Backend pragmas: multi-back-ends *)
783
+ (* *)
784
+ (* These pragmas just run a bunch of back-ends one after the other in the *)
785
+ (* hope that one will succeed. This saves time and effort for the user at *)
786
+ (* the expense of computation time. *)
787
+ (**************************************************************************)
788
+
789
+ (* CVC3 goes first because it's bundled with TLAPS, then the other SMT
790
+ solvers are unlikely to succeed if CVC3 fails, so we run zenon and
791
+ Isabelle before them. *)
792
+ AllProvers == TRUE (*{
793
+ by (prover:"cvc33")
794
+ by (prover:"zenon")
795
+ by (prover:"isabelle"; tactic:"auto")
796
+ by (prover:"spass")
797
+ by (prover:"smt3")
798
+ by (prover:"yices3")
799
+ by (prover:"verit")
800
+ by (prover:"z33")
801
+ by (prover:"isabelle"; tactic:"force")
802
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
803
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
804
+ by (prover:"isabelle"; tactic:"clarsimp")
805
+ by (prover:"isabelle"; tactic:"auto, blast")
806
+ }*)
807
+ AllProversT(X) == TRUE (*{
808
+ by (prover:"cvc33"; timeout:@)
809
+ by (prover:"zenon"; timeout:@)
810
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
811
+ by (prover:"spass"; timeout:@)
812
+ by (prover:"smt3"; timeout:@)
813
+ by (prover:"yices3"; timeout:@)
814
+ by (prover:"verit"; timeout:@)
815
+ by (prover:"z33"; timeout:@)
816
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
817
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
818
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
819
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
820
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
821
+ }*)
822
+
823
+ AllSMT == TRUE (*{
824
+ by (prover:"cvc33")
825
+ by (prover:"smt3")
826
+ by (prover:"yices3")
827
+ by (prover:"verit")
828
+ by (prover:"z33")
829
+ }*)
830
+ AllSMTT(X) == TRUE (*{
831
+ by (prover:"cvc33"; timeout:@)
832
+ by (prover:"smt3"; timeout:@)
833
+ by (prover:"yices3"; timeout:@)
834
+ by (prover:"verit"; timeout:@)
835
+ by (prover:"z33"; timeout:@)
836
+ }*)
837
+
838
+ AllIsa == TRUE (*{
839
+ by (prover:"isabelle"; tactic:"auto")
840
+ by (prover:"isabelle"; tactic:"force")
841
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
842
+ by (prover:"isabelle"; tactic:"clarsimp auto?")
843
+ by (prover:"isabelle"; tactic:"clarsimp")
844
+ by (prover:"isabelle"; tactic:"auto, blast")
845
+ }*)
846
+ AllIsaT(X) == TRUE (*{
847
+ by (prover:"isabelle"; tactic:"auto"; timeout:@)
848
+ by (prover:"isabelle"; tactic:"force"; timeout:@)
849
+ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
850
+ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
851
+ by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
852
+ by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
853
+ }*)
854
+
855
+
856
+ (**************************************************************************)
857
+ (* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
858
+ (* *)
859
+ (* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
860
+ (* *)
861
+ (* The pragma AutoUSE invokes automated expansion of definitions, *)
862
+ (* for both of ExpandEnabled and ExpandCdot, when each is present. *)
863
+ (* *)
864
+ (* The pragma Lambdify invokes expansion of the operators *)
865
+ (* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
866
+ (* which is a form before introducing rigid quantifiers. *)
867
+ (* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
868
+ (* that are not nested. *)
869
+ (**************************************************************************)
870
+ ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
871
+ ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
872
+ AutoUSE == TRUE (*{ by (prover:"autouse") }*)
873
+ Lambdify == TRUE (*{ by (prover:"lambdify") }*)
874
+ ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
875
+ LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
876
+
877
+ (* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
878
+ (* representation within TLAPM. *)
879
+ EnabledWrapper(Op(_)) == FALSE
880
+ CdotWrapper(Op(_)) == FALSE
881
+
882
+ (***************************************************************************)
883
+ (* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
884
+ (* triviality checks in TLAPM. *)
885
+ (***************************************************************************)
886
+ Trivial == TRUE (*{ by (prover:"trivial") }*)
887
+
888
+
889
+ =============================================================================
890
+
891
+ The material below is obsolete: the TLA proof rules below are superseded by
892
+ the PTL decision procedure, and their formulation is unsound for the semantics
893
+ of temporal reasoning that TLAPS adopts.
894
+
895
+ ----------------------------------------------------------------------------
896
+ (***************************************************************************)
897
+ (* TEMPORAL LOGIC *)
898
+ (* *)
899
+ (* The following rules are intended to be used when TLAPS handles temporal *)
900
+ (* logic. They will not work now. Moreover when temporal reasoning is *)
901
+ (* implemented, these rules may be changed or omitted, and additional *)
902
+ (* rules will probably be added. However, they are included mainly so *)
903
+ (* their names will be defined, preventing the use of identifiers that are *)
904
+ (* likely to produce name clashes with future versions of this module. *)
905
+ (***************************************************************************)
906
+
907
+
908
+ (***************************************************************************)
909
+ (* The following proof rules (and their names) are from the paper "The *)
910
+ (* Temporal Logic of Actions". *)
911
+ (***************************************************************************)
912
+ THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
913
+ P /\\ (f' = f) => P'
914
+ PROVE []P <=> P /\\ [][P => P']_f
915
+
916
+ THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
917
+ ACTION A, ACTION B,
918
+ P /\\ [A]_f => Q /\\ [B]_g
919
+ PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
920
+
921
+ THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
922
+ I /\\ [N]_F => I'
923
+ PROVE I /\\ [][N]_F => []I
924
+
925
+ THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
926
+ PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
927
+
928
+ THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
929
+ P /\\ [N]_f => (P' \\/ Q'),
930
+ P /\\ <<N /\\ A>>_f => Q',
931
+ P => ENABLED <<A>>_f
932
+ PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
933
+
934
+ THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
935
+ ACTION N, ACTION A, TEMPORAL F,
936
+ P /\\ [N]_f => (P' \\/ Q'),
937
+ P /\\ <<N /\\ A>>_f => Q',
938
+ []P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
939
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
940
+
941
+ (***************************************************************************)
942
+ (* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
943
+ (* from the following two rules by the following substitutions: \`. *)
944
+ (* *)
945
+ (* ___ ___ _______________ *)
946
+ (* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
947
+ (***************************************************************************)
948
+ THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
949
+ ACTION A, ACTION B, ACTION N, ACTION M,
950
+ TEMPORAL F,
951
+ <<N /\\ B>>_f => <<M>>_g,
952
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
953
+ P /\\ EM => ENABLED A,
954
+ [][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
955
+ PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
956
+
957
+ THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
958
+ ACTION A, ACTION B, ACTION N, ACTION M,
959
+ TEMPORAL F,
960
+ <<N /\\ B>>_f => <<M>>_g,
961
+ P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
962
+ P /\\ EM => ENABLED A,
963
+ [][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
964
+ PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
965
+
966
+
967
+ (***************************************************************************)
968
+ (* The following rule is a special case of the general temporal logic *)
969
+ (* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
970
+ (* general rule is for arbitrary temporal formulas F and G, but it cannot *)
971
+ (* yet be handled by TLAPS. *)
972
+ (***************************************************************************)
973
+ THEOREM RuleInvImplication ==
974
+ ASSUME STATE F, STATE G,
975
+ F => G
976
+ PROVE []F => []G
977
+ PROOF OMITTED
978
+
979
+ (***************************************************************************)
980
+ (* The following rule is a special case of rule TLA2 from the paper "The *)
981
+ (* Temporal Logic of Actions". *)
982
+ (***************************************************************************)
983
+ THEOREM RuleStepSimulation ==
984
+ ASSUME STATE I, STATE f, STATE g,
985
+ ACTION M, ACTION N,
986
+ I /\\ I' /\\ [M]_f => [N]_g
987
+ PROVE []I /\\ [][M]_f => [][N]_g
988
+ PROOF OMITTED
989
+
990
+ (***************************************************************************)
991
+ (* The following may be used to invoke a decision procedure for *)
992
+ (* propositional temporal logic. *)
993
+ (***************************************************************************)
994
+ PropositionalTemporalLogic == TRUE
995
+ =============================================================================
996
+ `:void 0);return i===void 0?void 0:{file:`${t}.tla`,source:i}}),a=r.flatMap(e=>e.obligations),o={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`),s=new Map(a.map(e=>[e.id,e])),c=await r.proveWithTlapm(t,new Map([[t,e.source],...n]),{signal:e.signal,onResult:(t,n)=>{let r=s.get(t);r&&e.onObligation?.(Xl(r,n))}});return{obligations:a.map(e=>Xl(e,c.get(e.id))),...o}}return{obligations:(await Yl(a,{workers:e.workers,signal:e.signal,onReport:t=>e.onObligation?.(t.obligation)})).map(e=>e.obligation),...o}};export{Zl as a,ca as c,An as d,z as f,ue as g,fe as h,Nl as i,ba as l,pe as m,Gl as n,Yl as o,an as p,Wl as r,jl as s,Ml as t,xa as u};