tla-ts 0.0.4-dev.2be6058 → 0.0.4-dev.2da24e1

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 (314) hide show
  1. package/README.md +37 -126
  2. package/dist/deciders.cjs +366 -0
  3. package/dist/deciders.js +366 -0
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +35 -1
  6. package/dist/index.d.ts +35 -1
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +1 -4
  9. package/dist/parallel-worker.js +1 -4
  10. package/dist/prove-worker.cjs +9 -0
  11. package/dist/prove-worker.d.cts +9 -0
  12. package/dist/prove-worker.d.ts +9 -0
  13. package/dist/prove-worker.js +9 -0
  14. package/dist/prove.cjs +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 +255 -56
  29. package/src/index.ts +10 -0
  30. package/src/{obligation-action.ts → obligations/action.ts} +247 -69
  31. package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
  32. package/src/obligations/ctx.ts +64 -0
  33. package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
  34. package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
  35. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  36. package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
  37. package/src/{obligations.ts → obligations/index.ts} +32 -16
  38. package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
  39. package/src/{obligation-module.ts → obligations/module.ts} +113 -121
  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 -2
  44. package/src/{obligation-source.ts → obligations/source.ts} +154 -99
  45. package/src/obligations/temporal.ts +321 -0
  46. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  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 +95 -0
  51. package/src/prove/deciders.ts +33 -0
  52. package/src/prove/first-order.ts +78 -0
  53. package/src/prove/isabelle/LICENSE +36 -0
  54. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  55. package/src/prove/isabelle/decide.ts +47 -0
  56. package/src/prove/isabelle/encode.ts +446 -0
  57. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  58. package/src/prove/isabelle/isar/method.ts +367 -0
  59. package/src/prove/isabelle/isar/proof.ts +28 -0
  60. package/src/prove/isabelle/isar/statement.ts +57 -0
  61. package/src/prove/isabelle/isar/theory.ts +192 -0
  62. package/src/prove/isabelle/isar/type-check.ts +278 -0
  63. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  64. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  65. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  66. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  67. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  68. package/src/prove/isabelle/provers/blast/term.ts +547 -0
  69. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  70. package/src/prove/isabelle/provers/classical.ts +389 -0
  71. package/src/prove/isabelle/provers/hypsubst.ts +441 -0
  72. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  73. package/src/prove/isabelle/pure/consts.ts +32 -0
  74. package/src/prove/isabelle/pure/conv.ts +79 -0
  75. package/src/prove/isabelle/pure/drule.ts +264 -0
  76. package/src/prove/isabelle/pure/envir.ts +363 -0
  77. package/src/prove/isabelle/pure/goal.ts +53 -0
  78. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  79. package/src/prove/isabelle/pure/list.ts +12 -0
  80. package/src/prove/isabelle/pure/logic.ts +402 -0
  81. package/src/prove/isabelle/pure/name.ts +110 -0
  82. package/src/prove/isabelle/pure/net.ts +262 -0
  83. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  84. package/src/prove/isabelle/pure/pattern.ts +650 -0
  85. package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
  86. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  87. package/src/prove/isabelle/pure/search.ts +68 -0
  88. package/src/prove/isabelle/pure/seq.ts +156 -0
  89. package/src/prove/isabelle/pure/simplifier.ts +112 -0
  90. package/src/prove/isabelle/pure/table.ts +208 -0
  91. package/src/prove/isabelle/pure/tactic.ts +276 -0
  92. package/src/prove/isabelle/pure/tactical.ts +347 -0
  93. package/src/prove/isabelle/pure/term-ord.ts +159 -0
  94. package/src/prove/isabelle/pure/term.ts +808 -0
  95. package/src/prove/isabelle/pure/thm.ts +806 -0
  96. package/src/prove/isabelle/pure/type.ts +133 -0
  97. package/src/prove/isabelle/pure/unify.ts +753 -0
  98. package/src/prove/isabelle/pure/variable.ts +25 -0
  99. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  100. package/src/prove/isabelle/tla/context.ts +74 -0
  101. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  102. package/src/prove/isabelle/tla/logic.ts +215 -0
  103. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  104. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  105. package/src/prove/ocaml.ts +22 -0
  106. package/src/prove/prep/action.ts +508 -0
  107. package/src/prove/prep/defs.ts +33 -0
  108. package/src/prove/prep/elab.ts +156 -0
  109. package/src/prove/prep/enabled-axioms.ts +189 -0
  110. package/src/prove/prep/enabled.ts +43 -0
  111. package/src/prove/prep/fingerprint.ts +388 -0
  112. package/src/prove/prep/flatten.ts +70 -0
  113. package/src/prove/prep/level-comparison.ts +529 -0
  114. package/src/prove/prep/md5.ts +67 -0
  115. package/src/prove/prep/pragma.ts +221 -0
  116. package/src/prove/prep/trivial.ts +22 -0
  117. package/src/prove/prove-worker.ts +22 -0
  118. package/src/prove/prove.ts +498 -0
  119. package/src/prove/ptl/decide.ts +68 -0
  120. package/src/prove/ptl/encode.ts +255 -0
  121. package/src/prove/ptl/sat.ts +151 -0
  122. package/src/prove/ptl/tableau.ts +276 -0
  123. package/src/prove/smt/axiomatize.ts +69 -0
  124. package/src/prove/smt/axioms.ts +209 -0
  125. package/src/prove/smt/context.ts +108 -0
  126. package/src/prove/smt/data.ts +636 -0
  127. package/src/prove/smt/encode.ts +164 -0
  128. package/src/prove/smt/extensionality.ts +65 -0
  129. package/src/prove/smt/flatten.ts +112 -0
  130. package/src/prove/smt/format.ts +154 -0
  131. package/src/prove/smt/instances.ts +181 -0
  132. package/src/prove/smt/rewrite.ts +772 -0
  133. package/src/prove/smt/simplify.ts +57 -0
  134. package/src/prove/smt/solver/act-cache.ts +265 -0
  135. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  136. package/src/prove/smt/solver/array.ts +22 -0
  137. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  138. package/src/prove/smt/solver/ast-lt.ts +157 -0
  139. package/src/prove/smt/solver/ast-util.ts +147 -0
  140. package/src/prove/smt/solver/ast.ts +1315 -0
  141. package/src/prove/smt/solver/auf-solver.ts +572 -0
  142. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  143. package/src/prove/smt/solver/cg-table.ts +175 -0
  144. package/src/prove/smt/solver/clause.ts +276 -0
  145. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  146. package/src/prove/smt/solver/context.ts +1292 -0
  147. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  148. package/src/prove/smt/solver/der.ts +224 -0
  149. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  150. package/src/prove/smt/solver/e-matching.ts +659 -0
  151. package/src/prove/smt/solver/enode.ts +259 -0
  152. package/src/prove/smt/solver/expr-ref.ts +21 -0
  153. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  154. package/src/prove/smt/solver/fingerprints.ts +92 -0
  155. package/src/prove/smt/solver/flat-literals.ts +51 -0
  156. package/src/prove/smt/solver/goal.ts +138 -0
  157. package/src/prove/smt/solver/hash.ts +173 -0
  158. package/src/prove/smt/solver/hashtable.ts +166 -0
  159. package/src/prove/smt/solver/internalizer.ts +1381 -0
  160. package/src/prove/smt/solver/lbool.ts +5 -0
  161. package/src/prove/smt/solver/literal.ts +24 -0
  162. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  163. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  164. package/src/prove/smt/solver/lp/containers.ts +296 -0
  165. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  166. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  167. package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
  168. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  169. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  170. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  171. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  172. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  173. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  174. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  175. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  176. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  177. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  178. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  179. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  180. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  181. package/src/prove/smt/solver/lp/nex.ts +120 -0
  182. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  183. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  184. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  185. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  186. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  187. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  188. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  189. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  190. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  191. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  192. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  193. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  194. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  195. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  196. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  197. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  198. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  199. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  200. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  201. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  202. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  203. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  204. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  205. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  206. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  207. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  208. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  209. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  210. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  211. package/src/prove/smt/solver/model-checker.ts +347 -0
  212. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  213. package/src/prove/smt/solver/model-finder.ts +155 -0
  214. package/src/prove/smt/solver/model-generator.ts +97 -0
  215. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  216. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  217. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  218. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  219. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  220. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  221. package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
  222. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  223. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  224. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  225. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  226. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  227. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  228. package/src/prove/smt/solver/nnf.ts +469 -0
  229. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  230. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  231. package/src/prove/smt/solver/propagate-values.ts +83 -0
  232. package/src/prove/smt/solver/proto-model.ts +551 -0
  233. package/src/prove/smt/solver/pull-quant.ts +139 -0
  234. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  235. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  236. package/src/prove/smt/solver/qe-lite.ts +381 -0
  237. package/src/prove/smt/solver/qi-queue.ts +362 -0
  238. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  239. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  240. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  241. package/src/prove/smt/solver/random-gen.ts +10 -0
  242. package/src/prove/smt/solver/rational.ts +165 -0
  243. package/src/prove/smt/solver/ref-vector.ts +62 -0
  244. package/src/prove/smt/solver/relevancy.ts +247 -0
  245. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  246. package/src/prove/smt/solver/rewriter.ts +843 -0
  247. package/src/prove/smt/solver/rlimit.ts +79 -0
  248. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  249. package/src/prove/smt/solver/solver.ts +71 -0
  250. package/src/prove/smt/solver/sort.ts +35 -0
  251. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  252. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  253. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  254. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  255. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  256. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  257. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  258. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  259. package/src/prove/smt/solver/theory-lra.ts +56 -0
  260. package/src/prove/smt/solver/var-subst.ts +258 -0
  261. package/src/prove/smt/solver/z3-license.txt +10 -0
  262. package/src/prove/smt/table.ts +170 -0
  263. package/src/prove/tlapm/tlapm.ts +96 -0
  264. package/src/prove/tlaps-module.ts +510 -0
  265. package/src/prove/verdict.ts +18 -0
  266. package/src/prove/zenon/LICENSE +32 -0
  267. package/src/prove/zenon/check/check.ts +105 -0
  268. package/src/prove/zenon/check/definitions.ts +144 -0
  269. package/src/prove/zenon/check/equality.ts +182 -0
  270. package/src/prove/zenon/check/functions.ts +62 -0
  271. package/src/prove/zenon/check/keys.ts +125 -0
  272. package/src/prove/zenon/check/propositional.ts +104 -0
  273. package/src/prove/zenon/check/records.ts +188 -0
  274. package/src/prove/zenon/check/relations.ts +121 -0
  275. package/src/prove/zenon/check/rewrites.ts +224 -0
  276. package/src/prove/zenon/check/sets.ts +302 -0
  277. package/src/prove/zenon/check/terms.ts +127 -0
  278. package/src/prove/zenon/check/tla.ts +126 -0
  279. package/src/prove/zenon/decide.ts +113 -0
  280. package/src/prove/zenon/encode.ts +379 -0
  281. package/src/prove/zenon/eqrel.ts +300 -0
  282. package/src/prove/zenon/equality-rules.ts +435 -0
  283. package/src/prove/zenon/expr.ts +551 -0
  284. package/src/prove/zenon/index-table.ts +350 -0
  285. package/src/prove/zenon/isar-case.ts +513 -0
  286. package/src/prove/zenon/isar.ts +1249 -0
  287. package/src/prove/zenon/limits.ts +15 -0
  288. package/src/prove/zenon/llproof.ts +173 -0
  289. package/src/prove/zenon/mltoll.ts +1566 -0
  290. package/src/prove/zenon/node.ts +297 -0
  291. package/src/prove/zenon/ocaml.ts +169 -0
  292. package/src/prove/zenon/parse.ts +247 -0
  293. package/src/prove/zenon/phrase.ts +191 -0
  294. package/src/prove/zenon/proof.ts +198 -0
  295. package/src/prove/zenon/propositional-rules.ts +387 -0
  296. package/src/prove/zenon/rules.ts +94 -0
  297. package/src/prove/zenon/search.ts +288 -0
  298. package/src/prove/zenon/tla/functions.ts +151 -0
  299. package/src/prove/zenon/tla/llproof.ts +480 -0
  300. package/src/prove/zenon/tla/records.ts +225 -0
  301. package/src/prove/zenon/tla/rewrites.ts +447 -0
  302. package/src/prove/zenon/tla/sets.ts +304 -0
  303. package/src/prove/zenon/tla/terms.ts +181 -0
  304. package/src/prove/zenon/tla/tla.ts +506 -0
  305. package/src/run-cli.ts +283 -81
  306. package/src/standard-modules.ts +5 -2
  307. package/src/successors.ts +25 -6
  308. package/src/tlapm-cache.ts +236 -0
  309. package/src/tlc-random.ts +55 -32
  310. package/src/tlc-version.ts +8 -7
  311. package/src/values.ts +97 -47
  312. package/src/worker.ts +65 -0
  313. package/dist/parallel.cjs +0 -12
  314. 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 me=h(),C=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(C,t,c);let he=C.environment,w=oe(t,he,()=>p(e.source,de),c);if(y(C.assumptions,he)||!w||w.spec.init===void 0||w.spec.next===void 0||w.properties.liveness.length>0||d(he))return x();let ge=u(),_e={fingerprints:te()},T=/* @__PURE__ */ new Int32Array(2),E=Array.from({length:le},re),D={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,initialStates:void 0,outDegrees:Array.from({length:32},()=>0)},ve=[],O=()=>({status:`success`,violation:void 0,failure:void 0,...D,fingerprintDistance:ee(D.distinctStates,D.generatedStates,()=>{let e=new BigInt64Array(D.distinctStates);return ve.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),ye=e=>{let t=[];for(let n of l(e,he,w.spec.scope))if(b(D.generatedStates,c),ge(n),D.generatedStates++,v(w.getFingerprintState(n),T),ae(_e.fingerprints)&&(_e.fingerprints=_(_e.fingerprints)),S(_e.fingerprints,T[0],T[1])){if(w.findViolatedInvariant(n)||w.findFailedInitialPredicate(n))return!1;if(w.satisfiesConstraints(n)){if(!E[t.length%le].encode(n))return!1;t.push(n),D.distinctStates++}}return ve.push(BigInt64Array.from(t,e=>he.runtime.getFingerprint(e))),!0};c({kind:`initial-states-started`});try{if(!ye(w.spec.init))return x()}catch(e){if(!(e instanceof n))throw e;return x()}if(h()!==me)return x();if(D.depth=D.generatedStates===0?0:1,D.initialStates={generated:D.generatedStates,distinct:D.distinctStates},c({kind:`initial-states-computed`,initialStates:D.initialStates}),D.distinctStates===0)return O();let k=[],A={count:le,resolve:e=>{}},be=e=>{k.push(e),(e.type===`abort`||k.length===A.count)&&A.resolve(k.splice(0))},xe=e=>new Promise(t=>{A.count=e,A.resolve=t}),Se=xe(le),j=new Int32Array(new SharedArrayBuffer(le*4)),Ce=new Int32Array(new SharedArrayBuffer(le*4)),we=await Promise.all(Array.from({length:le},()=>o(new URL(`./parallel-worker.js`,import.meta.url),e=>be(e),()=>be({type:`abort`})))),Te=()=>we.forEach(e=>e.terminate()),M=/* @__PURE__ */ new Map,Ee=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=M.get(n)??new MessageChannel;return M.set(n,r),e<t?r.port1:r.port2};we.forEach((n,r)=>{let i=Array.from({length:le},(e,t)=>t===r?void 0:Ee(r,t)),a=E[r].finish(),o={type:`start`,source:e.source,config:t,modules:[...ue],classes:[...fe],index:r,ports:i,seed:a,isTool:e.isTool,isTraceRecorded:e.isTraceRecorded,isWarningEnabled:e.isWarningEnabled,version:e.version,fingerprints:_e.fingerprints,requests:j,remaining:Ce};n.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let De=e=>e.some(e=>e.type===`abort`),Oe=e=>we.forEach(t=>t.postMessage(e)),ke=async e=>{let t=e.filter(e=>e.type===`paused`).length;if(t===0||De(e))return e;_e.fingerprints=_(_e.fingerprints);let n=xe(t);return Oe({type:`resize`,fingerprints:_e.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await ke(await n)]};if(De(await Se))return Te(),x();for(let e=1;;e++){let t=xe(le);j.forEach((e,t)=>Atomics.store(j,t,0)),Oe({type:`level`,level:e});let n=await ke(await t);if(De(n))return Te(),x();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(D.generatedStates+=r.reduce((e,t)=>e+t.generated,0),D.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>D.outDegrees[t]+=e),ve.push(e.fingerprints)}),i===0)return Te(),O();D.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>`,me=e=>`${pe(e)}:\n`,C=(e,t)=>({text:`${me(e)}Error: ${t}`,channel:`stderr`}),he=e=>e?`${fe(e)} :\n`:``,w=e=>({kind:`Shift`,amount:e}),ge=(e,t)=>({kind:`Cons`,expression:e,rest:t}),_e=(e,t)=>e.reduce((e,t)=>ge(t,e),t),T=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},E=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},D=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},ve=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t,O=(e,t,n)=>E({kind:`Apply`,operator:E({kind:`Internal`,builtin:e},n),args:t},n),ye=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},k=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),A=(e,t)=>t.reduce(k,e),be=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},xe=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(D(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},Se=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},j=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},Ce=(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()}}},we=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),Te=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),M=(e,t,n,r)=>({kind:`Fact`,expression:e,visibility:t,time:n,location:r}),Ee=e=>we(e.name,e.level),De=e=>we(e.name,`Unknown`,e.shape),Oe=e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),ke=(e,t,n)=>{switch(e.kind){case`Shift`:return E({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?E(Me(e.expression),n):ke(e.rest,t-1,n);case`Compose`:return N(e.outer,ke(e.inner,t,n));case`Bump`:return t<=e.amount?E({kind:`Ix`,index:t},n):N(w(e.amount),ke(e.rest,t-e.amount,n))}},Ae=(e,t)=>t.map(t=>N(e,t)),je=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e(`Arity mismatch`);return Me(N(_e(n,w(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?Me(t):{kind:`Apply`,operator:t,args:n}},Me=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},Ne=(e,t)=>[T(t.length,e),We(t,t=>N(e,t))],Pe=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return qe(t,t=>N(e,t));case`Instance`:{let n=T(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:N(n,e.expression)}))}}}}},Fe=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:N(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:Pe(e,t.definition)};case`Fact`:return{...t,expression:N(e,t.expression)}}},Ie=(e,t)=>{let[n,r]=j(e,t.context,(e,t)=>[T(1,e),Fe(e,t)]);return{context:r,active:N(n,t.active)}},N=(e,t)=>{let n=t=>N(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return ke(e,t.index,t);case`Apply`:return E(je(n(t.operator),Ae(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>Ge(e,n))};case`Lambda`:return{...t,body:N(T(t.params.length,e),t.body)};case`Let`:{let[n,r]=j(e,t.definitions,(e,t)=>[T(1,e),Pe(e,t)]);return{...t,definitions:r,body:N(n,t.body)}}case`Sequent`:return{...t,sequent:Ie(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:Ae(e,t.items)};case`Quant`:case`Fcn`:{let[n,r]=Ne(e,t.bounds);return{...t,bounds:r,body:N(n,t.body)}}case`Tquant`:return{...t,body:N(T(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:N(T(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:N(T(1,e),t.body)};case`SetOf`:{let[n,r]=Ne(e,t.bounds);return{...t,bounds:r,element:N(n,t.element)}}case`SetEnum`:case`Tuple`:return{...t,elements:Ae(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`FcnApp`:return{...t,function:n(t.function),args:Ae(e,t.args)};case`Product`:return{...t,factors:Ae(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:Ke(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)}}},P=(e,t)=>e===0?t:N(w(e),t),F=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),Le=(e,t)=>e&&t?I(e,t):!e&&!t,Re=(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},ze=(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)),Be=(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`&&F(e.args,t.args,I);case`Label`:return t.kind===`Label`&&e.label===t.label&&F(e.args,t.args,I);default:return!0}},Ve=(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 F(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&Re(n,r)}return!1},He=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level===t.level&&e.shape===t.shape&&Le(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?Ve(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&I(e.expression,t.expression),Ue=(e,t)=>F(e.context,t.context,He)&&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)&&F(e.args,t.args,I);case`Sequent`:return t.kind===`Sequent`&&Ue(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&I(e.expression,t.expression)&&F(e.selectors,t.selectors,Be);case`With`:return t.kind===`With`&&I(e.expression,t.expression);case`Let`:return t.kind===`Let`&&F(e.definitions,t.definitions,Ve)&&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&&F(e.items,t.items,I);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&F(e.bounds,t.bounds,ze)&&I(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&F(e.names,t.names,(e,t)=>e===t)&&I(e.body,t.body);case`Choose`:return t.kind===`Choose`&&Le(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)&&F(e.bounds,t.bounds,ze);case`SetEnum`:case`Tuple`:return t.kind===e.kind&&F(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`&&F(e.bounds,t.bounds,ze)&&I(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&F([e.function,...e.args],[t.function,...t.args],I);case`Product`:return t.kind===`Product`&&F(e.factors,t.factors,I);case`Rect`:case`Record`:return t.kind===e.kind&&Re(e.fields,t.fields);case`Except`:return t.kind===`Except`&&I(e.function,t.function)&&F(e.specs,t.specs,(e,t)=>F(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))&&Le(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}},We=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),Ge=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,Ke=(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}}),qe=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,Je=(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:qe(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,Ee(t)),e);switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Lambda`:{let i=t.params.reduce((e,t)=>{let n=De(t);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=j(e,t.sequent.context,(e,t)=>{let a=Je(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]=j(e,t.definitions,(e,t)=>{let i=qe(t,t=>n(e,t));return[r(e,Oe(i)),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=We(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=We(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?Te(t.name,i):we(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=Te(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>Ge(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=Ke(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}}}},Ye=(e,t)=>L(void 0,e,(e,n)=>t(n),()=>void 0,`all`),Xe=e=>{let t=[];return Ye(e,e=>(t.push(e),e)),t},Ze={kind:`Opaque`,name:`$Bad`},Qe=e=>e.kind===`Opaque`&&e.name===Ze.name,$e=e=>{let t=e.kind===`Parens`?$e(e.expression):Ye(e,$e);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},et=e=>e.kind===`Let`?E({kind:`Let`,definitions:e.definitions,body:et(e.body)},e.body):e.kind===`Parens`?et(e.expression):Ye(e,et),tt=e=>e.kind===`Ix`?e.index<=0:Xe(e).some(tt),nt=(e,t,n)=>{let r=(e,r=n)=>nt(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(Ee)]);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(De)]);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,we(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 Xe(e)){let e=r(t);if(e)return e}return}},rt=(e,t)=>_e(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),w(e+t)),it=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),at=(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 N(_e(r,w(0)),i)}case`Tquant`:return at(t,E({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 at(t,E({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 N(_e(r,w(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw t(C(n.location,r)),new e(r,{failure:`Expr.Deref.deref_inst`})}}},ot=(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=N(rt(n,i.length),r);return[i,at(t,a,it(i.length))]},st=(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 st(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=N(w(-(r-1)),a?a.expression:i.active);if(tt(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]:E({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,E({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=>E({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...n.other?[E({kind:`Tuple`,elements:[Ze,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(Qe(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]},ct=(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])},lt=(t,n,i,a,o)=>{let s=nt(i,a,[]);if(!s)return t(C(i.location,`Could not find label ${a}`)),{params:[],definitions:[],expression:Ze};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?it(c.length):o,d=s.context.reduceRight((e,t)=>t.kind===`Defn`?E({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?E({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):N(w(-1),e),s.expression),f=N(rt(n,l.length),d),p=[],m=f,h=ct(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=>N(w(1),e));else{if(m.kind!==`Quant`||m.bounds.length!==1)throw new r(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);m=N(ge(h[0],w(0)),m.body),h=h.slice(1)}return{params:l,definitions:p,expression:m}},ut=(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`?E({...c,body:E({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):E({kind:`Parens`,expression:c,form:{kind:`Xlabel`,label:i,indices:[]}},c);return lt(t,n,E({kind:`Let`,definitions:r.definitions.slice(0,o),body:l},c),i,a)},dt=(t,n,r,i)=>{let[a,...o]=i;if(!a){let e=r.definitions.length===0?r.expression:E({kind:`Let`,definitions:r.definitions,body:r.expression},r.expression),t=r.params.length===0?e:E({kind:`Lambda`,params:r.params,body:e},e);return{...$e(t),isAtomic:!0}}if(r.expression.isAtomic)return t(C(r.expression.location,`Expression has no subexpressions`)),Ze;let s=n?r.expression:et(r.expression),c=r.definitions.length,l=(()=>{let i=(e,n)=>{let[i,a]=st(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{...ut(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:at(t,s,a.args),rest:o,isLabel:!1};case`Label`:return{...s.kind===`Let`&&!n?ut(t,c,s,a.label,a.args):lt(t,c,s,a.label,a.args),rest:o,isLabel:!0};case`At`:{let[e,n]=ot(t,c,s);return{params:e,definitions:[],expression:n,rest:o,isLabel:!1}}}})();return dt(t,l.isLabel,{params:[...r.params,...l.params],definitions:[...r.definitions,...l.definitions],expression:l.expression},l.rest.map(e=>Ge(e,e=>N(w(l.definitions.length),e))))},ft=(e,t,n)=>{if(n.length>0)return{params:[],definitions:[],expression:at(e,t,n)};if(t.kind!==`Lambda`)return{params:[],definitions:[],expression:t};let[r,i]=ot(e,0,t);return{params:r,definitions:[],expression:i}},pt=(t,n,r,i)=>{let a=dt(t,!0,ft(t,n,r),i);if(Qe(a)){let r=`Could not resolve subexpression reference`;throw t(C(n.location,r)),new e(r,{failure:`Expr.Anon: 2`})}return a},mt=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),ht=e=>O(`UNCHANGED`,[e],e),gt=e=>O(`Eq`,[O(`Prime`,[e],e),e],e),_t=e=>{let t=e=>e.kind===`Tuple`?e.elements.flatMap(t):[e],n=t(e);return n.length===0?E({kind:`Internal`,builtin:`TRUE`},e):n.length===1?gt(n[0]):E({kind:`List`,bullet:`And`,items:n.map(gt)},e)},vt=e=>t=>{let n=vt(e);return e(t,n)??Ye(t,n)},yt=vt((e,t)=>e.kind===`Apply`&&mt(e,[`Leadsto`])?O(`BoxTrue`,[O(`Implies`,[t(e.args[0]),O(`Diamond`,[t(e.args[1])],e)],e)],e):void 0),bt=vt(e=>{if(e.kind!==`Fair`)return;let t=e.action,n=e.subscript,r=O(`ENABLED`,[E({kind:`Sub`,modal:`Dia`,action:t,subscript:n},t)],t),i=e.fairness===`Weak`?`Diamond`:`BoxTrue`,a=e.fairness===`Weak`?`BoxTrue`:`Diamond`;return O(`Implies`,[O(i,[O(a,[r],t)],t),O(`BoxTrue`,[E({kind:`Tsub`,modal:`Dia`,action:t,subscript:n},t)],t)],t)}),xt=vt((e,t)=>{if(e.kind!==`Sub`&&e.kind!==`Tsub`)return;let n=t(e.action),r=t(e.subscript),i=e.modal===`Box`?O(`Disj`,[n,ht(r)],e):O(`Conj`,[n,O(`Neg`,[ht(r)],e)],e);return e.kind===`Sub`?i:O(e.modal===`Box`?`BoxTrue`:`Diamond`,[i],e)}),St=vt(e=>e.kind===`Apply`&&mt(e,[`UNCHANGED`])?_t(e.args[0]):void 0),Ct=[`Prime`,`StrongPrime`,`Leadsto`,`ENABLED`,`UNCHANGED`,`Cdot`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`],wt=/* @__PURE__ */ new WeakMap,Tt=(e,t)=>{switch(t.kind){case`Fresh`:return t.level===`Constant`;case`Defn`:return t.definition.kind===`Operator`&&Dt(e,t.definition.body);case`Fact`:return Dt(e,t.expression);case`Flex`:return!1}},Et=(e,t)=>A(e,t.map(e=>we(e,`Constant`))),Dt=(e,t)=>{let n=t=>Dt(e,t);switch(t.kind){case`Ix`:{let n=Se(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=wt.get(i);if(a!==void 0)return a;let o=Dt(n?.rest,i);return wt.set(i,o),o}case`Opaque`:case`String`:case`Num`:case`At`:return!0;case`Internal`:return!Ct.includes(t.builtin);case`Tquant`:case`Sub`:case`Tsub`:case`Fair`:return!1;case`Lambda`:return Dt(Et(e,t.params.map(e=>e.name)),t.body);case`Sequent`:{let n=t.sequent.context.reduce((e,t)=>({scope:k(e.scope,t),isGood:e.isGood&&Tt(e.scope,t)}),{scope:e,isGood:!0});return n.isGood&&Dt(n.scope,t.sequent.active)}case`Bang`:case`With`:case`Dot`:case`Parens`:return n(t.expression);case`Apply`:return n(t.operator)&&t.args.every(n);case`Let`:{let n=t.definitions.reduce((e,t)=>({scope:k(e.scope,Oe(t)),isGood:e.isGood&&t.kind===`Operator`&&Dt(e.scope,t.body)}),{scope:e,isGood:!0});return n.isGood&&Dt(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))&&Dt(Et(e,t.bounds.map(e=>e.name)),r)}case`Choose`:case`SetSt`:return(t.domain===void 0||n(t.domain))&&Dt(Et(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))}},Ot=(e,t,n)=>{if(Dt(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=>Ot(e,t,n));if(t.kind===`Sequent`)return Ot(A(e,t.sequent.context),t.sequent.active,n);if(t.kind!==`Apply`)return!1;let r=t.args;return mt(t,[`BoxTrue`,`BoxFalse`])&&n||mt(t,[`Diamond`])&&!n?!0:r.length===1&&mt(t,[`BoxTrue`,`BoxFalse`,`Diamond`,`Prime`])?Ot(e,r[0],n):r.length===1&&mt(t,[`Neg`])?Ot(e,r[0],!n):r.length===2&&mt(t,[`Conj`,`Disj`])?Ot(e,r[0],n)&&Ot(e,r[1],n):r.length===2&&mt(t,[`Implies`])?Ot(e,r[0],!n)&&Ot(e,r[1],n):r.length===2&&mt(t,[`Equiv`])?[!0,!1].every(t=>Ot(e,r[0],n!==t)&&Ot(e,r[1],n===t)):Ot(e,t.operator,n)&&r.every(t=>Ot(e,t,n))},kt=(e,t)=>Ot(e,yt(bt(xt(St(t)))),!0)?`Always`:`Now`,At=(e,t)=>t===`Always`&&e.some(e=>e.kind===`Fact`&&e.time===`Now`)?`Now`:t,jt=e=>e.kind===`Named`?`<${e.level}>${e.label}`:`<${e.level}>`,Mt=e=>++e.value,Nt={kind:`Fact`,expression:{kind:`At`,isExcept:!1},visibility:`Visible`,time:`Always`},Pt={Number:`1NUM`,Down:`1DOWN`,At:`1AT`,Instance:`1INST`,Left:`1`,Right:`1`},Ft={kind:`Opaque`,name:`$badexp`},It=(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?P(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]=j(n,r.trail,(t,n)=>{if(n.kind===`Dot`)return[E({kind:`Dot`,expression:t,field:n.field},t),n];let r=c(e,n.expression);return[E({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,E({kind:`Except`,function:n,specs:[{trail:o,value:u}]},t)},n)},l=(e,t,n)=>{let r=E({kind:`Ix`,index:e},n);return t.length===0?r:E({kind:`Apply`,operator:r,args:t},n)},u=(e,t,n,r,i)=>{if(t!==`Builtin`)return l(e,r,i);let a=P(e,n);return E(r.length===0?a:je(a,r),i)},d=(t,n,a,o)=>{let s=xe(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 E({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=xe(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?Pt[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?E({kind:`Ix`,index:p},s):u(p,d.whereDefined,d.definition.body,r,s);let m=Lt(P(p,d.definition.body),s);return Lt(pt(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=>Ge(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:E({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:`${he(t.location)}Warning: ${n} does not introduce any assumptions. It does not make sense to use it here.\n`,channel:`toolbox`}),E({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,E({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=xe(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,k(e.scope,t)),_=(e,t)=>h(e,A(e.scope,t.map(Ee))),v=(e,t)=>{let n=We(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,we(t.name,`Constant`)),n);if(I(N(ge({kind:`Opaque`,name:`%%%`},w(1)),r),r))return{...t,body:P(-1,r)};let i=O(`Eq`,[E({kind:`Ix`,index:1},r),r],r);return{...t,body:E({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,{...Oe(o),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:kt(e.scope,n)}}}})();return[g(e,n),n]},ne=(e,t)=>{let[n,r]=j(e,t.context,te);return[n,{context:r,active:c(n,t.active)}]},re=(e,t)=>({warnedSteps:[jt(t),...e.warnedSteps],scope:e.scope}),x=(e,t,n,r)=>g(e,{kind:`Defn`,definition:{kind:`Operator`,name:jt(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,A(e.scope,Array.from({length:t},()=>Nt))),ie=e=>{let t=[...e.context.map((t,n)=>{let r=e.context.length-n+1;if(t.kind===`Fact`)return P(r,t.expression);if(t.kind!==`Fresh`||!t.domain)return Ft;let i=O(`Mem`,[E({kind:`Ix`,index:0},t.domain),t.domain],t.domain);return P(r,i)}),P(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,E({kind:`Opaque`,name:t.name},t));return n.kind===`Ix`?Se(e.scope,n.index-1)?.hyp.kind===`Defn`?[{kind:`Dx`,index:n.index,location:t.location}]:(i({text:`${he(t.location)}${JSON.stringify(t.name)} is not a definition and cannot be used in a DEF clause.`,channel:`toolbox`}),[]):(i({text:`${he(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]=j(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${Mt(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,E(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,E(ye(t),a),a),1),s]}case`Pcase`:{let t=c(e,a.expression),n=E({kind:`Tuple`,elements:[P(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,E({kind:`Tuple`,elements:[t]},a),a);return[S(s,1),o]}case`Suffices`:{let[,t]=ne(e,a.sequent),n=E({kind:`Tuple`,elements:[E(ye(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=E({kind:`Tuple`,elements:[E(ie(t),a)]},a);return[S(x(S(s,1),i,c,a),1),o]}case`Have`:{let t=c(e,a.expression),n=E({kind:`Tuple`,elements:[P(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=E({kind:`Quant`,quantifier:`Forall`,bounds:n,body:Ft},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=E({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=E({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=P(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)}},Lt=(e,t)=>t.location?{...e,location:t.location}:e,Rt=1000000010,zt=new TextEncoder,Bt=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return zt.encode(e).length;return e.length},Vt=()=>({leftTotal:-1,element:{size:-1,token:{kind:`Text`,text:``},length:0}}),Ht=e=>{let t={size:-1,token:{kind:`Begin`,indent:0,box:`hov`},length:0};return{queue:[t],queueStart:0,scanStack:[Vt(),{leftTotal:1,element:t}],formatStack:[],margin:78,maxIndent:e,spaceLeft:78,currentIndent:0,isNewLine:!0,leftTotal:1,rightTotal:1,depth:1,output:[]}},Ut=(e,t)=>{e.rightTotal+=t.length,e.queue.push(t)},Wt=(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))},Gt=(e,t)=>{e.spaceLeft-=t,e.output.push(` `.repeat(t))},Kt=e=>{let t=e.formatStack.at(-1);t?t.width>e.spaceLeft&&t.box!==`fits`&&t.box!==`h`&&Wt(e,0,t.width):e.output.push(`
15
+ `)},qt=(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&&Kt(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?Wt(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?Wt(e,n.offset,i):Gt(e,n.width);return;case`b`:e.isNewLine?Gt(e,n.width):t>e.spaceLeft||e.currentIndent>e.margin-i+n.offset?Wt(e,n.offset,i):Gt(e,n.width);return;case`hv`:case`v`:Wt(e,n.offset,i);return;case`fits`:case`h`:Gt(e,n.width);return}}}},Jt=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++,qt(e,n?t.size:Rt,t.token),e.leftTotal+=t.length}e.queue.length=0,e.queueStart=0},Yt=(e,t)=>{Ut(e,t),Jt(e)},Xt=(e,t)=>{let n=e.scanStack.at(-1);n&&(n.leftTotal<e.leftTotal?e.scanStack=[Vt()]:n.element.token.kind===(t?`Break`:`Begin`)&&(n.element.size=e.rightTotal+n.element.size,e.scanStack.pop()))},Zt=(e,t,n)=>{Ut(e,n),t&&Xt(e,!0),e.scanStack.push({leftTotal:e.rightTotal,element:n})},Qt=(e,t,n)=>{e.depth++,Zt(e,!1,{size:-e.rightTotal,token:{kind:`Begin`,indent:n,box:t},length:0})},$t=e=>{e.depth<=1||(Ut(e,{size:0,token:{kind:`End`},length:0}),Xt(e,!0),Xt(e,!1),e.depth--)},en=(e,t,n)=>Yt(e,{size:t,token:{kind:`Text`,text:n},length:t}),tn=(e,t,n)=>Zt(e,!0,{size:-e.rightTotal,token:{kind:`Break`,width:t,offset:n},length:t}),nn=e=>Yt(e,{size:0,token:{kind:`Newline`},length:0}),rn=e=>{for(;e.depth>1;)$t(e);return e.rightTotal=Rt,Jt(e),e.output.join(``)},an=e=>{rn(e);let t=[...e.output,`
17
+ `];Object.assign(e,Ht(e.maxIndent)),e.output=t},on={h:`h`,v:`v`,hv:`hv`,hov:`hov`,b:`b`},sn=e=>({kind:`Text`,text:e,size:Bt(e)}),R=e=>e===``?[]:[sn(e)],cn={kind:`Break`,width:1,offset:0},ln={kind:`Break`,width:0,offset:0},un=e=>{let t=e.search(/\d|$/);return{kind:`Open`,box:on[e.slice(0,t)],indent:Number(e.slice(t)||0)}},z=(e,...t)=>{let n=[],r=0,i=``,a=()=>{i!==``&&(n.push(sn(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(sn(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(un(e.slice(o+3,t))),o=t;break}case`]`:n.push({kind:`Close`}),o++;break;case` `:n.push(cn),o++;break;case`,`:n.push(ln),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=[sn(`,`),cn])=>e.flatMap((e,r)=>r===0?[t(e)]:[n,t(e)]),dn=(e,t)=>{for(let n of t)if(Array.isArray(n))dn(e,n);else switch(n.kind){case`Open`:Qt(e,n.box,n.indent);break;case`Close`:$t(e);break;case`Text`:en(e,n.size,n.text);break;case`Break`:tn(e,n.width,n.offset);break;case`Newline`:nn(e);break;case`Flush`:an(e)}},fn=(e,t=68)=>{let n=Ht(t);return dn(n,e),rn(n)},pn=e=>e.salt===0?e.rep:`${e.rep}_${e.salt}`,mn=()=>({stack:[],idents:/* @__PURE__ */ new Map,defined:/* @__PURE__ */ new Map}),hn=(e,t)=>{let n=e.stack[e.stack.length-t];return n&&pn(n)},gn=(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(pn(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=pn(r);return e.defined.set(a,(e.defined.get(a)??0)+1),a},_n=(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=pn(t),r=(e.defined.get(n)??1)-1;r===0?e.defined.delete(n):e.defined.set(n,r)}},vn=(e,t,n)=>{let r=n(t.map(t=>gn(e,t)));return _n(e,t.length),r},yn=[[`=>`,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`,[]]],bn=/* @__PURE__ */ new Map;for(let[e,t,n,r,i]of yn){let a={name:e,low:t,high:n,fixity:r};for(let t of[e,...i])bn.set(t,a)}const xn=e=>({name:e,low:-1,high:-1,fixity:`Nonfix`}),Sn=e=>bn.get(e)??xn(e),Cn={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:`@@`},wn=e=>{if(e===`Divides`)return{name:`?|`,low:10,high:11,fixity:`InfixNon`};if(e===`Uminus`)return{...Sn(`-.`),name:`-`};let t=Cn[e];return t?Sn(t):xn(e)},Tn=(e,t)=>t.kind===`Atm`||t.kind===`Op`&&e<t.low,En=e=>[z(`(`),e,z(`)`)],Dn=(e,t)=>t?On(e):En(On(e)),On=e=>{if(e.kind!==`Op`)return e.doc;let t=e.skeleton,n=t=>Tn(e.high,t);switch(t.kind){case`Prefix`:case`Postfix`:{let r=t.operand,i=Dn(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>`),Dn(r,a),e.doc,Dn(i,o),z(`@]`)]}}},V=e=>({kind:`Atm`,doc:e}),kn=e=>({kind:`Big`,doc:e}),An=e=>e.kind===`Lambda`?An(e.body):e.kind===`Sequent`?An(e.sequent.active):e.kind===`With`,jn=e=>{if(e.kind===`Defn`){let t=e.definition,n=t.kind===`Operator`&&An(t.body);return e.visibility===`Hidden`||n||e.whereDefined!==`User`}return e.kind===`Fact`?e.visibility===`Hidden`||An(e.expression):!1},Mn=e=>e===0?[]:z(`@[<hov1>(%a)@]`,B(Array.from({length:e},()=>`_`),R)),Nn=e=>z(`%s%a`,e.name,Mn(e.shape)),Pn={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`UNKNOWN`},Fn=(t=[])=>{let n=mn(),r=e=>On(u(e)),i=(e,t)=>vn(n,e.map(e=>e.name),()=>z(`@[<b2>LAMBDA @[<hv0>%a@] :@ %a@]`,B(e,Nn),r(t))),a=(e,t)=>{let i=e.map(e=>e.domain.kind===`Domain`?r(e.domain.expression):void 0);return vn(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 hn(n,e);let r=t[t.length-(e-n.stack.length)];return r?D(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:kn(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 Sn(c(t.index));case`Opaque`:{let e=Sn(t.name);return{...e,name:`?${e.name}`}}case`Internal`:return wn(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 kn(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 kn(p(t.sequent));case`With`:return u(t.expression);case`If`:return kn(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 kn(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 _n(n,t.definitions.length),kn([z(`@[<hv0>LET @[<v0>`),e,z(`@]@
19
+ IN %a@]`,i)])}case`Quant`:return a(t.bounds,e=>kn(z(`@[<b3>%s @[<b0>%a@] :@ %a@]`,t.quantifier===`Forall`?`\\A`:`\\E`,e,r(t.body))));case`Tquant`:return vn(n,t.names,e=>kn(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 vn(n,[t.name],([n])=>kn(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 vn(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?``:`(`,On(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 kn(z(`@[<h>%s_%a (%a)@]`,t.fairness===`Weak`?`WF`:`SF`,En(r(t.subscript)),r(t.action)));case`Case`:return kn(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,On(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,On(i)))}}},d=e=>{switch(e.kind){case`Operator`:case`Bpragma`:{let t=e.body;if(t.kind===`Lambda`){let i=vn(n,t.params.map(e=>e.name),()=>r(t.body)),a=gn(n,e.name);return z(`@[<b2>%s@[<b1>(%a)@] ==@ %a@]`,a,B(t.params,Nn),i)}let i=r(t);return z(`@[<b2>%s ==@ %a@]`,gn(n,e.name),i)}case`Instance`:{let t=e.instance,i=vn(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=gn(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=gn(n,e.name);return z(`@[<b2>NEW CONSTANT %s%a@]`,t,Mn(e.shape))}}},f=e=>{switch(e.kind){case`Fresh`:{let t=e.domain&&e.domainVisibility===`Visible`?r(e.domain):void 0,i=gn(n,e.name);return[z(`NEW %s %s%a`,Pn[e.level],i,Mn(e.shape)),t?z(` \\in %a`,t):[]]}case`Flex`:return z(`NEW VARIABLE %s`,gn(n,e.name));case`Defn`:return d(e.definition);case`Fact`:{let t=z(`@[<h>%a @]`,r(e.expression));return gn(n,``),t}}},p=e=>{if(e.context.length===0)return r(e.active);let t=[];for(let r of e.context)jn(r)?gn(n,D(r)??``):t.push(f(r));let i=r(e.active);return _n(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}},In=(e,t)=>Fn(e).printExpr(t),Ln=e=>Fn().printSequent(e),Rn=e=>fn(z(`@[<b0>%a@]`,Ln(e))).trimEnd(),zn={kind:`At`,isExcept:!1},Bn=e=>({location:e.location,step:e.step,method:e.method}),Vn=e=>e?.kind===`Named`&&e.isAnonymous,Hn=e=>e?.level??0,Un=e=>E({kind:`Internal`,builtin:`TRUE`},e),Wn=(e,t)=>ve(e,t)&&e.args.length===2,Gn=(e,...t)=>fn(z(e,...t)),Kn=e=>qn(e).map((e,t)=>{let n=e.domain.kind===`Domain`?P(t,e.domain.expression):void 0;return{kind:`Fresh`,name:e.name,shape:0,level:n?`Constant`:e.level,domain:n,domainVisibility:`Visible`}}),qn=e=>{let t={kind:`NoDomain`};return e.map(e=>e.domain.kind===`Ditto`?{...e,domain:t}:(t=e.domain,e))},Jn=(e,t)=>t.context.flatMap((n,r)=>n.kind===`Fact`&&n.visibility===`Visible`?[P(e+t.context.length-1-r,n.expression)]:[]),Yn=(e,t,n)=>{if(!e.step)throw new r;return{kind:`Defn`,definition:{kind:`Operator`,name:jt(e.step),body:t,location:e.location},whereDefined:{kind:`Proof`,time:n},visibility:`Visible`,isLocal:!0,location:e.location}},Xn=(e,t,n,r)=>{let i=Vn(n.step)?`Visible`:`Hidden`,a=t.context.map(e=>e.kind===`Fact`?{...e,visibility:i}:e),o=E({kind:`List`,bullet:`Refs`,items:Jn(2,t)},n),s=At(t.context,r);return{context:[...e,...a,M(Un(n),`Hidden`,r,n.location),Yn(n,o,s),M(E({kind:`Ix`,index:1},n),`Hidden`,s,n.location)],active:P(3,t.active),time:s}},Zn=(e,t,n,r,i,a)=>{let o=e||Vn(i.step)?`Visible`:`Hidden`;return{context:[...t,Yn(i,E(ye(r),i),a),M(E({kind:`Ix`,index:1},i),o,a,i.location)],active:P(2,n)}},Qn=(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`},$n=(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)},er=(e,t)=>ve(e,`Mem`)&&e.args[0]?.kind===`Ix`&&e.args[0].index===0&&I(t,e.args[1]),tr=(t,n,r,i)=>{let a=!1,o=r,s=[...i];for(let e=i.length-1;e>=0;e--){o=P(-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&&er(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},nr=(e,t)=>{let n=Ne(w(1),t)[1];return n[0].domain.kind===`Ditto`&&e.domain.kind===`Domain`?[{...n[0],domain:{kind:`Domain`,expression:P(1,e.domain.expression)}},...n.slice(1)]:n},rr=(e,t)=>{if(t.length===0)return{kind:`Obvious`,...Bn(e)};let n=t.map((t,n)=>{let r=P(2*n+2,t);return{kind:`Assert`,sequent:{context:[],active:r},proof:{kind:`By`,usable:{facts:[P(3,r)],defs:[]},isOnly:!1,location:t.location,method:e.method},location:t.location}}),r={kind:`By`,usable:{facts:[E({kind:`Ix`,index:2*t.length+2},e),...t.map((n,r)=>E({kind:`Ix`,index:2*(t.length-r)},e))],defs:[]},isOnly:!0,...Bn(e),method:void 0};return{kind:`Steps`,steps:n,qed:{proof:r,location:r.location},...Bn(e)}},ir=(e,t,n)=>({sequent:e,location:t.location,kind:n,method:t.method}),ar={total:0,absent:[],omitted:[]},or=(e,t)=>({total:e.total+t.total,absent:[...e.absent,...t.absent],omitted:[...e.omitted,...t.omitted]}),sr=e=>e.kind===`Use`?{...ar,total:e.obligations?.length??0}:`proof`in e?cr(e.proof):ar,cr=e=>e.kind===`Steps`?[...e.steps.map(sr),cr(e.qed.proof)].reduce(or):e.kind!==`Omitted`||!e.obligations||!e.location?{...ar,total:e.obligations?.length??0}:{total:e.obligations.length,absent:e.omission===`Implicit`?[e.location]:[],omitted:e.omission===`Explicit`?[e.location]:[]},lr=(e,t)=>e.kind===`At`&&!e.isExcept?E(Me(t),e):Ye(e,e=>lr(e,t)),ur=(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:[ir(t,i,{kind:`Main`})]};case`Omitted`:return{...i,obligations:[ir(t,i,{kind:`Omitted`,omission:i.omission})]};case`Error`:return{...i,obligations:[ir(t,i,{kind:`Error`,message:i.message})]};case`By`:throw new e(`Proof.Gen.generate`);case`Steps`:{let[e,n]=j({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=ir({...t,active:e},n,{kind:`Support`});return[{context:[...t.context,{...M(e,`Visible`,Qn(t.context,e,r),e.location),useLocation:n.useLocation}],active:P(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)=>$n(`Visible`,e,t),t.context);return[{...t,context:a},n,r]}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>$n(`Hidden`,e,t),t.context),a=n.usable.facts.reduceRight((e,t)=>tr(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:P(n.definitions.length,t.active)},n,r];case`Assert`:{let e=Xn(t.context,n.sequent,n,r),i=a(e,n.proof,e.time),o={...n,proof:i};return[Zn(!1,t.context,t.active,n.sequent,o,r),o,r]}case`Suffices`:{let e=a(Zn(!0,t.context,t.active,n.sequent,n,r),n.proof,r),i={...n,proof:e},o=Xn(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:{...zn,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=>P(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&&t.push(...e.obligations)},r=e=>{e.kind===`Use`&&e.obligations&&t.push(...e.obligations),`proof`in e&&n(e.proof)};return n(e),t},u=e=>({kind:`Named`,level:e,label:`_a${Mt(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)};return`proof`in n?{...n,proof:f(e+1,n.proof)}: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=P(r.index,i.definition.body);if(n.kind!==`Apply`)return m(t,a);let o={...a,location:n.location};return m(t,E(je(o,n.args),o))}if(ve(n,`Prime`)){let e=m(t,n.args[0]),r=e=>O(`Prime`,[e],e);return e.kind===`Quant`?E({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):Wn(e,`Implies`)||Wn(e,`Mem`)?E({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=lr(e.sequent.active,P(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:[P(t,e)],defs:[]},isOnly:!1,location:e.location,useLocation:i.location})),r=i.isOnly?[{kind:`Forget`,count:e.facts.length,location:i.location}]:[],a=Hn(i.step),o=[...t,...n,...r].map(e=>({...e,step:u(a)})),s={kind:`Obvious`,location:i.location,step:u(a),method:i.method};return{kind:`Steps`,steps:o,qed:{proof:s,location:s.location,step:s.step},location:i.location,step:i.step}}case`Steps`:{let[n,a]=j({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=Hn(r.step);switch(r.kind){case`Forget`:return[t,n,[r],i];case`Assert`:{let e=Xn(t,r.sequent,r,i),a={...r,proof:_(e.context,e.active,r.proof,e.time)},o=Zn(!1,t,n,r.sequent,a,i);return[o.context,o.active,[a],i]}case`Suffices`:{let e=Zn(!0,t,n,r.sequent,r,i),a={...r,proof:_(e.context,e.active,r.proof,i)},o=Xn(t,r.sequent,a,i);return[o.context,o.active,[a],o.time]}case`Use`:{let a={kind:`By`,usable:r.usable,isOnly:r.isOnly,location:r.location,step:r.step,method:r.method},o=_(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(()=>M(zn,`Visible`,i,r.location));return[[...t,...s],P(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}))],P(r.definitions.length,n),[r],i];case`Have`:{let e=m(t,n),o=Wn(e,`Implies`),s={context:[M(r.expression,`Visible`,i,r.location)],active:o?P(1,e.args[1]):e},c=o?{kind:`By`,usable:{facts:[E({kind:`Ix`,index:2},r)],defs:[]},isOnly:!0,...Bn(r)}:{kind:`Error`,message:Gn(`@.@[<v2>@[%s@ %s@]@,%a@]@.`,`Error: this HAVE step is applied to the following goal,`,`which is not an implication:`,In(t,n)),...Bn(r)},l=p(a,{kind:`Suffices`,sequent:s,proof:c,location:r.location,step:r.step});return v(t,n,l,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:[M(r.expression,`Visible`,i,r.location)],active:P(1,n)},proof:r.proof,...Bn(r)};return v(t,n,p(a,e),i)}case`Pick`:{let a=E({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,...Bn(r),step:o},i),d=P(2,a);if(d.kind!==`Quant`)throw new e(`Proof.Simplify.simplify_step/PICK`);let f=[...Kn(d.bounds),M(d.body,`Visible`,u,d.body.location)],[p,m,h,g]=v(s,c,{kind:`Suffices`,sequent:{context:f,active:P(f.length,c)},proof:{kind:`Omitted`,omission:`Elsewhere`,...Bn(r)},...Bn(r)},u);return[p,m,[...l,...h],g]}}},y=(e,n)=>({kind:`Named`,level:Hn(e),label:`${e?.kind===`Named`?e.label:`_a`}${n}${Mt(t)}`,isAnonymous:!1}),b=(e,t,n)=>{let r=qn(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 Gn(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this TAKE step is applied to the following goal,`,`which is not a universal formula:`,In(e,r));let c=s.bounds[0],l=qn(s.bounds).slice(1),u=o.domain,d=c.domain;if(u.kind===`NoDomain`&&d.kind===`Domain`)return Gn(`@.@[<b0>%s (%s)@ %s (%s \\in %a)@]@.`,`Error: the TAKE argument`,o.name,`does not match the pattern`,c.name,In(e,d.expression));if(u.kind===`Domain`&&d.kind===`NoDomain`)return Gn(`@.@[<b0>%s (%s \\in %a)@ %s (%s)@]@.`,`Error: the TAKE argument`,o.name,In(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=>Ne(w(t),[e])[1][0]):l;return i(t+1,f,E({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:[M(Un(t),`Visible`,`Now`,n.location)],active:t},proof:{kind:`Error`,message:a,...Bn(n)},...Bn(n)};let o=a.aux.filter((e,t)=>a.aux.findIndex(t=>I(e,t))===t),s=[E({kind:`Ix`,index:2},n),...o.map(e=>P(2,e))];return{kind:`Suffices`,sequent:{context:Kn(r),active:a.goal},proof:{kind:`By`,usable:{facts:s,defs:[]},isOnly:!0,...Bn(n)},...Bn(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||=Gn(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this WITNESS step is applied to the following goal,`,`which is not an existential formula:`,In(e,n)),a=n;break}let[o,...s]=n.bounds,c=s.length===0?n.body:E({kind:`Quant`,quantifier:`Exists`,bounds:nr(o,s),body:n.body},n),l=t;if(o.domain.kind===`Domain`){let n=o.domain.expression,a=m(e,t);if(Wn(a,`Mem`)){let[e,t]=a.args,i=I(t,n)?[]:[O(`Subseteq`,[t,n],t)];r.push(...i,a),l=e}else i||=Gn(`@.@[<b0>%s (%a)@ %s (%s \\in %a)@]@.`,`Error: the WITNESS argument`,In(e,a),`does not match the pattern`,o.name,In(e,n)),l=a}let u=O(`Unprimable`,[l],l);a=N(ge(u,w(0)),c)}let o=i===``?rr(n,r):{kind:`Error`,message:i,...Bn(n)};return{kind:`Suffices`,sequent:{context:[],active:a},proof:o,...Bn(n)}};return{generate:a,collect:l,mutate:c,simplify:_}},dr=(e,t=0)=>({level:e,weights:Array.from({length:t},()=>!0),params:/* @__PURE__ */ new Set}),fr={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]},pr={Constant:0,State:1,Action:2,Temporal:3,Unknown:0},mr=e=>new Set(e.flatMap(e=>[...e])),hr=e=>({level:Math.max(0,...e.map(e=>e.level)),weights:[],params:mr(e.map(e=>e.params))}),gr=/* @__PURE__ */ new WeakMap,_r=e=>{let t=e.hyp;switch(t.kind){case`Flex`:return dr(1);case`Fresh`:return{...dr(pr[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 xr(e.rest,n.body)}case`Fact`:return xr(e.rest,t.expression)}},vr=e=>{let t=gr.get(e);if(t)return t;let n=_r(e);return gr.set(e,n),n},yr=(e,t,n)=>{let r=t.flatMap(t=>t.domain.kind===`Domain`?[xr(e,t.domain.expression)]:[]);return hr([xr(A(e,t.map(Ee)),n),...r])},br=(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:mr([t.params,...r.map(e=>e.params)])}},xr=(e,t)=>{let n=t=>xr(e,t);switch(t.kind){case`Ix`:{let n=Se(e,t.index-1);if(!n)throw new r;return vr(n)}case`Internal`:{let e=fr[t.builtin];if(!e)throw new r;return dr(e[0],e[1])}case`Opaque`:case`String`:case`Num`:return dr(0);case`Lambda`:{let n=xr(A(e,t.params.map(De)),t.body),r=new Set(t.params.map(e=>e.name));return{level:n.level,weights:t.params.map(e=>n.params.has(e.name)),params:new Set([...n.params].filter(e=>!r.has(e)))}}case`Apply`:{let e=t.operator;if(ve(e,`Prime`)&&e.args.length===1)return n({...t,operator:e.args[0]});if(e.kind===`Opaque`)return br(dr(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 dr(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),dr(2)):e.kind===`Internal`&&e.builtin===`Leadsto`?(t.args.forEach(n),dr(3,2)):br(n(e),t.args.map(n))}case`Sequent`:{let[n,r]=j(e,t.sequent.context,(e,t)=>{let n=k(e,t);return[n,vr(n).level]});return dr(Math.max(0,...r,xr(n,t.sequent.active).level))}case`With`:case`Dot`:case`Parens`:return n(t.expression);case`Let`:return xr(A(e,t.definitions.map(Oe)),t.body);case`If`:return hr([t.condition,t.consequent,t.alternative].map(n));case`List`:return hr(t.items.map(n));case`Quant`:case`Fcn`:return yr(e,t.bounds,t.body);case`SetOf`:return yr(e,t.bounds,t.element);case`Tquant`:return xr(A(e,t.names.map(e=>({kind:`Flex`,name:e}))),t.body),dr(3);case`Choose`:case`SetSt`:{let r=t.domain&&n(t.domain),i=t.domain?Te(t.name,t.domain):we(t.name,`Constant`);return hr([xr(k(e,i),t.body),...r?[r]:[]])}case`SetEnum`:case`Tuple`:return hr(t.elements.map(n));case`Product`:return hr(t.factors.map(n));case`FcnApp`:return hr([t.function,...t.args].map(n));case`Arrow`:return hr([n(t.domain),n(t.range)]);case`Rect`:case`Record`:return hr(t.fields.map(e=>n(e.value)));case`Except`:return hr([n(t.function),...t.specs.flatMap(e=>[...e.trail.flatMap(e=>e.kind===`Apply`?[n(e.expression)]:[]),n(e.value)])]);case`Sub`:return{...hr([n(t.action),n(t.subscript)]),level:2};case`Tsub`:case`Fair`:return n(t.action),n(t.subscript),dr(3);case`Case`:return hr([...t.arms.flatMap(e=>[n(e.condition),n(e.body)]),...t.other?[n(t.other)]:[]]);case`Bang`:case`At`:throw new r}},Sr=`EnabledWrapper`,Cr=`CdotWrapper`,wr="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`.",Tr="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.",Er=`${Tr} For example, writing \`BY ExpandCdot\`.`,Dr=(e,t)=>L(void 0,e,(e,n)=>t(n),()=>void 0),Or=(e,t)=>{let n=Se(e,t-1)?.hyp;if(!n)throw new r;return n},kr=e=>e.kind===`Internal`&&(e.builtin===`ENABLED`||e.builtin===`Cdot`),Ar=e=>e.kind===`Opaque`&&(e.name===Sr||e.name===Cr),jr=e=>e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`Lambda`&&(kr(e.operator)||Ar(e.operator)),Mr=e=>e===void 0?2:Math.min(2,e),Nr=e=>e===void 0?void 0:Math.max(1,e-1),Pr=(t,n,i,a,o)=>{let c=(e,r=o)=>Pr(t,n,i,e,r);if(jr(a))return a;if(a.kind===`Sub`)return{...a,action:c(a.action),subscript:c(a.subscript,Nr(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,`${Tr}For example, writing \`BY ExpandCdot\`.`)),new s(`Expr.Action`);return{...a,args:t.isCdot?[c(r,Mr(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,wr)),new s(`Expr.Action`);return{...a,args:[t.isEnabled?c(r,Mr(o)):c(r)]}}if((e===`Prime`||e===`UNCHANGED`)&&a.args.length===1)return{...a,args:[c(r,Nr(o))]}}let l=a.kind===`Apply`&&a.operator.kind===`Ix`?a.operator:a;if(l.kind!==`Ix`)return L(i,a,(e,r)=>Pr(t,n,e,r,o),k);if(o===void 0)return a;let u=xr(i,a).level,d=Or(i,l.index),f=e=>`The operator \`${e}\` is declared at:\n${pe(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: ${pr[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${pe(r.location)}\nand the operator \`${p.name}\` occurs at: \n\t${pe(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:`${me(a.location)}[INFO]: Auto-expanding the definition of operator: ${p.name}\n`,channel:`stdout`});let m=N(w(l.index),p.body);return c(Me(a.kind===`Apply`?je(m,a.args):m))},Fr=e=>{if(e.kind===`Apply`&&e.args.length===1)return _t(e.args[0]);if(e.kind!==`Sub`)throw new r;let t=_t(e.subscript),n=e.modal===`Box`?t:O(`Neg`,[t],e);return O(e.modal===`Box`?`Disj`:`Conj`,[e.action,n],e)},Ir=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},Lr=e=>{let t=Array.from({length:16},()=>[]);return e.forEach((e,n)=>{if(t[Ir(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[Ir(e)&r.length-1].push(e)),t=r}),t.flat()},Rr=(e,t,n,i,a,o)=>{let c=r=>Rr(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=[Rr(e,t,n,c,a,l),...u?[Rr(e,t,c,i,a,u)]:[]],f=c.names.length===0?[`r#0`]:Lr(c.names);return E({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(jr(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,wr)),new s(`Expr.Action`);if(n===`Cdot`&&l)throw t(C(o.location,Er)),new s(`Expr.Action`);if(n===`Prime`&&o.args.length===1){let n=Rr(e,t,i,void 0,a,o.args[0]);return i?n:{...o,args:[n]}}if(n===`UNCHANGED`&&l)return c(Fr(o))}if(o.kind===`Sub`&&l)return c(Fr(o));if(o.kind===`Ix`){if(!n)return o;let e=Or(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),E({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)=>Rr(e,t,n,i,r,a),k)},zr=(e,t)=>{if(t.kind===`Apply`&&kr(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=zr({kind:`Compose`,outer:e,inner:w(a.length)},n.body);return{kind:`Apply`,operator:t.operator,args:[{kind:`Lambda`,params:a,body:o}]}}return t.kind===`Ix`?N(e,t):t.kind===`Apply`?E(je(zr(e,t.operator),t.args.map(t=>zr(e,t))),t):L(e,t,zr,e=>T(1,e))},Br=(e,t)=>{if(t.kind===`Apply`&&kr(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`?Cr:Sr;return{kind:`Apply`,operator:E({kind:`Opaque`,name:i},t.operator),args:[{kind:`Lambda`,params:n.params.map((t,n)=>({name:e?t.name:`r#${n}`,shape:0})),body:Br(e,n.body)}]}}return Dr(t,t=>Br(e,t))},Vr=e=>{if(ve(e,`Cdot`)&&e.args.length===1&&e.args[0].kind!==`Lambda`)throw new r;return Dr(e,Vr)},Hr=(e,t,n,r,i,a)=>{let o=Rr(i,t,void 0,void 0,n,r);return Br(a,e.expr(n,zr(w(0),o)))},Ur={isEnabled:!0,isCdot:!0,isAutoUse:!0},Wr=(e,t,n,r,i=Ur)=>{let a=Pr(i,t,n,r,void 0);return Vr(Hr(e,t,n,a,i,!1))},Gr=(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:Gr(e,t,A(n,r.map(De)),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===Sr||e.isCdot&&i.name===Cr))return a(s.params,s.body);if(i.kind===`Ix`&&(e.isEnabled||e.isCdot)){let e=Or(n,i.index);if(e.kind===`Defn`&&e.definition.kind===`Operator`&&(e.definition.name===Sr||e.definition.name===Cr))return a(s.params,s.body)}if(kr(i)&&o(i.builtin))return a(s.params,s.body)}if(kr(i)&&o(i.builtin))return Gr(e,t,n,s,!0)}if(ve(r,`ENABLED`)&&i)throw t(C(r.location,wr)),new s(`Expr.Action`);if(ve(r,`Cdot`)&&i)throw t(C(r.location,Er)),new s(`Expr.Action`);return L(n,r,(n,r)=>Gr(e,t,n,r,i),k)},Kr=e=>{if(e.kind===`Quant`&&e.quantifier===`Exists`){let t=e.body;if(t.kind===`List`&&t.bullet===`Or`)return Kr({...t,items:t.items.map(t=>({...e,body:t}))});if(ve(t,`Disj`)){if(t.args.length!==2)throw new r;return Kr({...t,args:t.args.map(t=>({...e,body:t}))})}}return Dr(e,Kr)},qr=(e,t,n,r,i)=>{let a=Pr(i,t,n,r,void 0),o=Hr(e,t,n,a,i,!0);return Kr(Gr(i,t,n,o,!1))},H=(e,t,n)=>({kind:`Definition`,definition:{kind:`Operator`,name:t,body:e===0?{kind:`Internal`,builtin:n}:{kind:`Lambda`,params:Array.from({length:e},(e,t)=>({name:`x${t+1}`,shape:0})),body:{kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n}))}}},whereDefined:`Builtin`,visibility:`Visible`,isLocal:!1}),Jr=[H(0,`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`)],Yr=[...Jr,H(0,`Int`,`Int`),H(1,`-.`,`Uminus`)],Xr=[...Yr,H(0,`Real`,`Real`),H(2,`/`,`Ratio`),H(0,`Infinity`,`Infinity`)],Zr=[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`)],Qr=[H(2,`Print`,`Print`),H(1,`PrintT`,`PrintT`),H(2,`Assert`,`Assert`),H(0,`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`),H(0,`Any`,`Any`),H(1,`ToString`,`ToString`)],$r=(e,t)=>({name:e,extendees:[],body:t,isImportant:!1,isStandard:!0}),ei=new Map([$r(`Naturals`,Jr),$r(`Integers`,Yr),$r(`Reals`,Xr),$r(`Sequences`,Zr),$r(`TLC`,Qr)].map(e=>[e.name,e])),ti=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:E(ye(Ie(w(-e.axiomCount),{...e.sequent,context:e.sequent.context.slice(e.axiomCount)})),e);return e.name===void 0?[M(n,`Hidden`,`Always`,t)]:ri(e.name,n,t)}case`Mutate`:return e.mode===`Use`?e.usable.facts.map((e,n)=>M(P(n,e),`Visible`,`Always`,t)):[];case`Submod`:case`Anoninst`:return[]}},ni=e=>e.kind===`Axiom`||e.kind===`Theorem`?e.name===void 0?1:2:ti(e).length,ri=(e,t,n)=>[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:t,location:n},whereDefined:`User`,visibility:`Visible`,isLocal:!1,location:n},M({kind:`Ix`,index:1,location:n},`Hidden`,`Always`,n)],ii=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:ii(e.module)}}];default:return[e]}}),ai=(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(...ii(ai(t,n,i,/* @__PURE__ */ new Set([...a,s])))),i.add(s)}return{...n,body:[...o,...n.body].map(e=>e.kind===`Submod`?{...e,module:ai(t,e.module,/* @__PURE__ */ new Set)}:e)}},oi=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&&si(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(ci),locations:t,submodules:a}},si=e=>typeof e==`object`&&!!e&&`module`in e&&typeof e.module==`string`&&`substitutions`in e,ci=(e,t)=>e<t?-1:+(e>t),li=(t,n)=>({facts:Ae(t,n.facts),defs:n.defs.map(n=>{if(n.kind===`Dvar`)return n;let r=N(t,{kind:`Ix`,index:n.index});if(r.kind!==`Ix`)throw new e(`substitution produced bad definition`);return{...n,index:r.index}})}),ui=(e,t)=>{switch(t.kind){case`Constants`:case`Recursives`:return[T(t.declarations.length,e),t];case`Variables`:return[T(t.names.length,e),t];case`Definition`:return[T(1,e),{...t,definition:Pe(e,t.definition)}];case`Axiom`:return[T(ni(t),e),{...t,expression:N(e,t.expression)}];case`Theorem`:return[T(ni(t),e),{...t,sequent:Ie(e,t.sequent)}];case`Submod`:return[e,{...t,module:{...t.module,body:di(e,t.module.body)}}];case`Mutate`:return[t.mode===`Hide`?e:T(t.usable.facts.length,e),{...t,usable:li(e,t.usable)}];case`Anoninst`:return[e,{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(t=>({name:t.name,expression:N(e,t.expression)}))}}]}},di=(e,t)=>j(e,t,ui)[1],fi=(t,n,i,a)=>{try{let e=Wr(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: ${pe(r)}`;return t.onWarning({text:`${me(r)}[ERROR]${o}`,channel:`stdout`}),t.onWarning({text:o,channel:`toolboxOnly`}),{context:[],active:E({kind:`Internal`,builtin:`TRUE`},a.active)}}},pi=(e,t,n)=>{if(n.kind===`Theorem`)return{...n,sequent:fi(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=Wr(e.anonymizer,e.onWarning,t,r.body);return{...n,definition:{...r,body:i}}},mi=(e,t,n)=>j(t,n,(t,n)=>{if(n.kind===`Submod`){let[r,i]=mi(e,t,n.module.body);return[r,{...n,module:{...n.module,body:i}}]}let r=pi(e,t,n);return[A(t,ti(r)),r]}),hi=(t,n)=>{let r=[],i=0,a=t;for(;a.length>0;){let[t,...o]=a,s=t.kind===`Constants`?{name:t.declarations[0].name,remaining:{...t,declarations:t.declarations.slice(1)}}:t.kind===`Variables`?{name:t.names[0],remaining:{...t,names:t.names.slice(1)}}:void 0;if(s){let t=n.get(s.name);if(!t)throw new e(`Parameter ${s.name} has no substitute`);let r=ni(s.remaining)===0;a=di(ge(P(i,t),w(0)),r?o:[s.remaining,...o])}else r.push(t),i+=ni(t),a=o}return r},gi=(e,t,n)=>{let r=Array.from({length:t},(e,r)=>E({kind:`Ix`,index:t-r},{location:n})),i=Array.from({length:t},(e,t)=>E({kind:`Ix`,index:t+1},{location:n})),a=Array.from({length:e},(e,i)=>{let a=E({kind:`Ix`,index:i+t+1},{location:n});return t>0?E({kind:`Apply`,operator:a,args:r},{location:n}):a});return _e([...a,...i].reverse(),w(e+t))},_i=(e,t)=>{let n=t.map(e=>({name:e,shape:0}));return e.kind===`Lambda`?{...e,params:[...n,...e.params]}:t.length===0?e:E({kind:`Lambda`,params:n,body:e},e)},vi=(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=>_i(N(gi(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}$${Mt(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(`${he(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+=ni(e);continue}case`Theorem`:{p(`${me(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(E(ye(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=di(w(-n.usable.facts.length),d));continue;case`Submod`:continue;default:throw new e(`Module.Elab.localize`)}}return l},yi=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=M(e.name===void 0?P(1,e.expression):E({kind:`Ix`,index:2},e),`Visible`,`Always`,i),o=0,s=r.map(e=>{let t=o;if(o+=ni(e),e.kind!==`Theorem`)return e;let n=Ie(w(1),e.sequent);return{...e,sequent:{...n,context:[Fe(w(t),a),...n.context]},axiomCount:e.axiomCount+1}});n=di(w(-1),s)}return t},bi=e=>new Set(e.body.flatMap(e=>e.kind===`Constants`?e.declarations.map(e=>e.name):e.kind===`Variables`?e.names:[])),xi=(t,n,r,i,a,o,s)=>{let c=n.get(i.module);if(!c)throw new e(`Module "${i.module}" unknown`);let l=bi(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=A(r,i.args.map(e=>we(e,`Unknown`))),d=new Map(i.substitutions.map(e=>[e.name,e.expression]));for(let t of[...l].sort(ci))if(!d.has(t)){if(!xe(u,t))throw new e(`Required parameter ${t} for module ${i.module} could not be inferred.`);d.set(t,E({kind:`Opaque`,name:t},{location:s}))}let f=new Map([...d].map(([e,n])=>[e,t.anonymizer.expr(u,n)])),p=di(w((u?.size??0)-(c.depth??0)),c.body.map(e=>e.kind===`Theorem`?{...e,proof:{kind:`Omitted`,omission:`Implicit`,location:e.proof.location}}:e)),[,m]=mi(t,u,p);return yi(vi(t,hi(m,f),o,i,a,s))},Si=(e,t,n)=>e===void 0?{hyps:[],sequent:t}:{hyps:[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:E(ye(t),{location:n}),location:n},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:n}],sequent:Ie(w(1),t)},Ci=(t,n,r)=>{let i=r.instance.module;if(!t.latestModules.has(i))throw t.onWarning({text:`${he(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=xi(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=di(w(-ni(e)),t)}return o},wi=(e,t,n,r)=>{let i=[],a=n,o=e=>{i.push(e),a=A(a,ti(e))},s=e=>e!==void 0&&xe(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=xi(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=ti(s)[0],d=xe(a,t.name);if(d?.hyp.kind===`Defn`&&(d.hyp.definition.kind===`Recursive`||He(Fe(w(d.depth+1),d.hyp),u))){let e=c.slice(n+1),t=di(ge(E({kind:`Ix`,index:d.depth+1},i),w(0)),e.map(e=>e.unit));c.splice(n+1,e.length,...e.map((e,n)=>({...e,unit:t[n]})));continue}o(s);continue}case`Recursives`:case`Constants`:case`Variables`:o(i);continue;case`Axiom`:if(s(i.name))continue;e.latestModules=new Map(t),o({...i,expression:e.anonymizer.expr(a,i.expression)});continue;case`Theorem`:{let n=s(i.name),c=n?`(redundant)${i.name}`:i.name,l=n?{kind:`Obvious`,location:i.proof.location}:i.proof;e.latestModules=new Map(t);let u=e.anonymizer.sequent(a,i.sequent),d=Si(c,u,i.location),f=A(A(a,d.hyps.map(e=>({...e,isConstnessUnset:!0}))),d.sequent.context),p=e.anonymizer.proof(f,l),m=r.isImportant?e.generator.simplify(be(f),d.sequent.active,p,At(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:wi(e,t,a,i.module)});continue}}let l={...r,body:i,depth:n?.size??0};return t.set(r.name,l),l},Ti=(e,t,n)=>{let r=[],i=[],a=ar,o=t;for(let t of n.body)switch(t.kind){case`Theorem`:{let n=Si(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,At(c,`Always`));r.push(...e.generator.collect(l));let u=cr(l);i.push({...u,location:t.location}),a=or(a,u);let d=t.name===void 0?E(ye(t.sequent),t):{kind:`Ix`,index:1,location:t.location};o=[...s,M(d,`Hidden`,`Always`,t.location)];continue}case`Submod`:{let n=Ti(e,o,t.module);r.push(...n.obligations),a=or(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,...ti(t)]}return{obligations:r,summary:{...a,theorems:i}}},Ei=[`(`,`)`,`;`,`:`,`@`,`,`],Di=e=>e===` `||e===`\r`||e===` `,Oi=(e,t)=>{let n={...t},r=()=>{for(;n.line<e.length;){let t=e[n.line];for(;Di(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(!Ei.includes(t[0]))return;i.push({kind:`Punct`,text:t[0]}),n.column++}}},ki=(e,t)=>e?.kind===`Punct`&&e.text===t,Ai=e=>e?.kind===`String`?{kind:`String`,value:e.text}:e?.kind===`Number`?{kind:`Float`,value:Number.parseFloat(e.text)}:ki(e,`@`)?{kind:`Default`}:void 0,ji=/* @__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`]]),Mi=(e,t)=>{let n=Oi(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(!ki(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 ki(n[r],`(`)&&!a()?void 0:{name:e.text,...t}}let t=ji.get(e.text);return t===void 0?void 0:{name:t}})();if(t&&ki(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},Ni=(e,t)=>{let n=Oi(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`||!ki(n[r],`(`))return;r++;let t=[];for(;;){let e=n[r++];if(e?.kind!==`Ident`||!ki(n[r],`:`))return;r++;let i=Ai(n[r++]);if(!i)return;if(t.push({hint:e.text,value:i}),ki(n[r],`)`))break;if(!ki(n[r],`;`))return;r++}r++,i.push(t)}return i},Pi=e=>({kind:`Opaque`,name:e}),Fi=e=>({kind:`Tuple`,elements:e.map(Pi)}),Ii=(e,t)=>({kind:`Apply`,operator:{kind:`Internal`,builtin:`Eq`},args:[e,t]}),Li=e=>e.map(e=>({name:e,level:`Constant`,domain:{kind:`NoDomain`}})),Ri=(e,t)=>e?.kind===`Product`&&e.factors.length===t.length?e.factors:void 0,zi=(e,t)=>t.map((t,n)=>({kind:`Operator`,name:t,body:{kind:`FcnApp`,function:Pi(e),args:[{kind:`Num`,integer:String(n+1),fraction:``}]}})),Bi=(e,t)=>e.map((e,n)=>({name:e,level:`Constant`,domain:{kind:`Domain`,expression:t[n]}})),Vi=e=>({name:e.name,level:`Constant`,domain:e.domain}),Hi=(e,t,n)=>{let r=[];return t.forEach(e=>{e.kind===`Name`&&e.domain.kind===`Ditto`?r.at(-1)?.push(e):r.push([e])}),r.reduceRight((t,n)=>{let r=(n,r=t)=>({kind:`Quant`,quantifier:e,bounds:n,body:r,location:t.location}),i=n[0];if(i.kind===`Name`)return r(n.flatMap(e=>e.kind===`Name`?[Vi(e)]:[]));let a=Ri(i.domain,i.names);if(a)return r(Bi(i.names,a));let o={kind:`Apply`,operator:{kind:`Internal`,builtin:e===`Exists`?`Mem`:`Notmem`},args:[Fi(i.names),i.domain]};return r(Li(i.names),{kind:`List`,bullet:e===`Exists`?`And`:`Or`,items:[o,t]})},n)},Ui=(e,t,n)=>{let r=`${e.kind.toLowerCase()}#${t[0]}`;return{...e,name:r,body:Ri(e.domain,t)?{kind:`Let`,definitions:zi(r,t),body:n}:{kind:`Quant`,quantifier:`Exists`,bounds:Li(t),body:{kind:`List`,bullet:`And`,items:[Ii(Pi(r),Fi(t)),n]}}}},Wi=(e,t,n)=>{let r=e.map(e=>{if(e.kind===`Name`)return{bounds:[Vi(e)],definitions:[]};let t=Ri(e.domain,e.names);if(t&&n)return{bounds:Bi(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:zi(r,e.names)};let a=`choose#${r}`;return{bounds:[i],definitions:[{kind:`Operator`,name:a,body:Ui({kind:`Choose`,domain:void 0},e.names,Ii(Pi(r),Fi(e.names)))},...zi(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=>Sn(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=Sn(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:Sn(t),isInfix:!1,operand:e.expression,replace:t=>({...e,expression:t})}},ra=(e,t)=>e.high<t.low,ia=e=>{let t=Sn(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&&Mi(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?E({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 E(r?{kind:`Internal`,builtin:r}:{kind:`Opaque`,name:n},{location:t})},h=(e,t,n,r)=>{if(e.startsWith(`<`)){let t=E({kind:`Opaque`,name:e},{location:n});return E({kind:`Bang`,expression:t,selectors:[]},{location:n})}let i=qi[e];if(i&&t.length===0)return E({kind:`Internal`,builtin:i},{location:n});let a=e.split(`!`);if(a.length===1){let r=E({kind:`Opaque`,name:e},{location:n});return t.length===0?r:E({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=E({kind:`Opaque`,name:a[0]},{location:n});return E({kind:`Bang`,expression:o[0]===0?l:E({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 E(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)=>E({kind:`Apply`,operator:{kind:`Internal`,builtin:e},args:[t]},{location:a([t],`Prefix`)});switch(t.kind){case`Number`:return E({kind:`Num`,integer:t.text??String(t.value),fraction:``},{location:r});case`Decimal`:{let[e,n]=t.text.split(`.`);return E({kind:`Num`,integer:e,fraction:n},{location:r})}case`String`:{let e=/"((?:[^"\\]|\\.)*)"$/.exec((o[r.endLine-1]??``).slice(0,r.endColumn-1));return E({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=Sn(t.operator);return n.fixity===`Nonfix`?h(t.operator,e,r,t.argumentCounts):E({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 E({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 E({kind:`List`,bullet:t.kind,items:e},{location:r});let n=t.kind===`And`?`Conj`:`Disj`;return e.reduce((e,t)=>E({kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:[e,t]},{location:Xi(e.location,t.location)}))}case`Prime`:{let e=i(t.expression);return E({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 E({kind:`If`,condition:i(t.condition),consequent:i(t.consequent),alternative:i(t.alternative)},{location:r});case`Case`:return E({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 E({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(Hi(t.kind,_(t.bounds,n),i(t.body)),r):E({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?E({kind:`Tquant`,quantifier:n,names:t.names,body:e},{location:r}):E({kind:`Quant`,quantifier:n,bounds:Li(t.names),body:e},{location:r})}case`Choose`:return t.pattern.kind===`Tuple`?v(Ui({kind:`Choose`,domain:t.set&&i(t.set)},t.pattern.names,i(t.body)),r):E({kind:`Choose`,name:t.pattern.name,domain:t.set&&i(t.set),body:i(t.body)},{location:r});case`SetEnumeration`:return E({kind:`SetEnum`,elements:t.elements.map(i)},{location:r});case`SetFilter`:return t.bound.pattern.kind===`Tuple`?v(Ui({kind:`SetSt`,domain:i(t.bound.set)},t.bound.pattern.names,i(t.predicate)),r):E({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):E({kind:`SetOf`,element:i(t.expression),bounds:g(t.bounds,n)},{location:r});case`Tuple`:return E({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):E({kind:`Fcn`,bounds:g(t.bounds,n),body:i(t.body)},{location:r});case`FunctionSet`:return E({kind:`Arrow`,domain:i(t.domain),range:i(t.range)},{location:r});case`Record`:case`RecordSet`:return E({kind:t.kind===`Record`?`Record`:`Rect`,fields:t.fields.map(e=>({name:e.name,value:i(e.value)}))},{location:r});case`Except`:return E({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 E({kind:`At`,isExcept:n},{location:r});case`Bracket`:throw new e(`Unexpected [ without a function or subscript`);case`FunctionApplication`:return E({kind:`FcnApp`,function:i(t.function),args:t.args.map(i)},{location:r});case`FieldAccess`:return E({kind:`Dot`,expression:i(t.record),field:t.field},{location:r});case`Product`:return E({kind:`Product`,factors:t.factors.map(i)},{location:r});case`Always`:case`Eventually`:{let e=t.expression;return t.kind===`Always`&&e.kind===`BoxAction`?E({kind:`Tsub`,modal:`Box`,action:i(e.action),subscript:i(e.subscript)},{location:r}):t.kind===`Eventually`&&e.kind===`AngleAction`?E({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 E({kind:`Sub`,modal:t.kind===`BoxAction`?`Box`:`Dia`,action:i(t.action),subscript:i(t.subscript)},{location:r});case`WeakFairness`:case`StrongFairness`:return E({kind:`Fair`,fairness:t.kind===`WeakFairness`?`Weak`:`Strong`,subscript:i(t.subscript),action:i(t.action)},{location:r});case`Label`:return E({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=E({kind:`Opaque`,name:n.name},{location:r}),s=n.args.length===0?o:E({kind:`Apply`,operator:o,args:n.args.map(i)},{location:r});return E({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:E({kind:`Fcn`,bounds:e,body:a},{location:r}),location:r}}let s=t.params.length===0?a:E({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&&Ni(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`?E({kind:`Sequent`,sequent:re(e)},{location:p(e.location)}):x(e);return M(t,`Visible`,`Now`,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 E({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:Mt(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?Li(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?Li(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,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:`${he(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,oi(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(ci).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(ei);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)=>ci(e.name,t.name)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=oi(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)&&!ei.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,me(t.locations.get(e)));s.set(e,i),c.push(i)}}let d=[...l.keys()].filter(e=>!u.has(e)).sort(ci);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:It(o,(e,t)=>Ci(f,e,t),a),generator:ur(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:ai(s,e,/* @__PURE__ */ new Set)),m=new Map(p.map(e=>[e.name,e]));return p.flatMap(e=>{if(e.isStandard)return[];let t=wi(f,m,void 0,e);if(!e.isImportant)return[];let n=Ti(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:`${Rn(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,i=[],a={failure:void 0},c=()=>{for(;i.length>0&&n.length>0;){let e=n.reduce((e,t,r)=>t.priority<n[e].priority?r:e,0),[a]=n.splice(e,1),o=i.pop()??0;r.set(o,a),t[o].postMessage(a.request)}},l=(e,t)=>{let n=t,a=r.get(e);r.delete(e),i.push(e),`verdict`in n&&a?.resolve(n),`error`in n&&a?.reject(new s(n.error)),c()},u=e=>{a.failure||(a.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=>l(t,e),u)))),i.push(...t.keys()),{decide:(e,t,r,i)=>new Promise((o,s)=>{if(a.failure)return s(a.failure.reason);n.push({request:{prover:e,text:t,timeLimitMs:r.timeLimitMs},priority:i,resolve:o,reject:s}),c()}),terminate:u}},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={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},ka=(e,t,n)=>{if((e===`Prime`||e===`StrongPrime`||e===`UNCHANGED`)&&t===1)return new r;let i=Oa[e];return i&&i[1]===t?new s(`Unsupported operator \`${i[0]}\`.\n`):new s(n)},Aa=(e,t,n)=>{let r=t[0],i=t.slice(1),a=i[0]?.domain.kind===`Ditto`?[{...i[0],domain:r.domain},...i.slice(1)]:i;return a.length===0?{first:r,inner:n}:{first:r,inner:{kind:`Quant`,quantifier:e,bounds:a.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:P(1,e.domain.expression)}}:e),body:n,location:n.location}}},ja=(e,t)=>{let n=e.stack.length;try{return t()}catch(t){if(!(t instanceof i))throw t;return _n(e,e.stack.length-n),t}},Ma=e=>`is${Da(e)}`,Na={TRUE:`TRUE`,FALSE:`FALSE`,STRING:`STRING`,BOOLEAN:`BOOLEAN`,Nat:`Nat`,Int:`Int`,Real:Ma(`Real`),Infinity:Ma(`Infinity`),Any:`Any`},Pa={Neg:`~`,DOMAIN:`DOMAIN`,SUBSET:`SUBSET`,UNION:`UNION`},Fa={Implies:`\\<Rightarrow>`,Equiv:`\\<Leftrightarrow>`,Conj:`\\<and>`,Disj:`\\<or>`,Eq:`=`,Neq:`\\<noteq>`,Subseteq:`\\<subseteq>`,Mem:`\\<in>`,Notmem:`\\<notin>`,Setminus:`\\\\`,Cap:`\\<inter>`,Cup:`\\<union>`,OneArg:`:>`,Extend:`@@`},Ia={Plus:[`addint`,2],Minus:[`subint`,2],Uminus:[`minus`,1],Times:[`mult`,2],Ratio:[Ma(`/`),2],Quotient:[Ma(`\\div`),2],Remainder:[Ma(`%`),2],Exp:[Ma(`^`),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:[Ma(`\\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]},La=[`consts`,...[[`Real`,0],[`/`,2],[`\\div`,2],[`%`,2],[`..`,2],[`Infinity`,0],[`[]`,1],[`<>`,1]].map(e=>` "${Ma(e[0])}" :: ${e[1]===0?`c`:`"[${Array(e[1]).fill(`c`).join(`,`)}] => c"`}`),``].join(`
27
+ `),Ra=e=>{let t=Number.parseInt(e,10);return`${`succ[`.repeat(t)}0${`]`.repeat(t)}`},za=(e,t)=>[`(* automatically generated -- do not edit manually *)`,`theory ${e} imports Constant Zenon begin`,...t?[`ML_command \\<open> writeln ("*** TLAPS PARSED\\n"); \\<close>`]:[],La],Ba=e=>{let t=mn(),n=e=>gn(t,Da(e)),a=()=>gn(t,``),o=(e,r)=>{let i=r(n(e));return _n(t,1),i},c=e=>`(${h(e)})`,l=e=>e.map(c).join(`, `),u=(e,t)=>`(${e} (${l(t)}))`,d=(e,t)=>{let n=Na[e];if(n!==void 0&&t.length===0)return n;let r=Pa[e];if(r!==void 0&&t.length===1)return`(${r} ${c(t[0])})`;let a=Fa[e];if(a!==void 0&&t.length===2)return`(${c(t[0])} ${a} ${c(t[1])})`;let o=Ia[e];if(o&&o[1]===t.length)return u(o[0],t);if(e===`Unprimable`&&t.length===1)return c(t[0]);throw e===`Irregular`&&t.length===1?new i(`Irregular`):ka(e,t.length,`Backend.Isabelle.pp_apply`)},f=(e,i)=>{switch(e.kind){case`Ix`:{let n=hn(t,e.index);if(e.index<=0||n===void 0)throw new r;return i.length===0?n:`(${n} (${l(i)}))`}case`Opaque`:{let t=Da(e.name);return i.length===0?`(${t} :: c)`:`(${t} (${l(i)}) :: c)`}case`Internal`:return d(e.builtin,i);case`Lambda`:{let r=`\\<lambda> ${e.params.map(e=>`${n(e.name)} `).join(``)}. ${c(e.body)}`;return _n(t,e.params.length),r}default:throw new r}},p=(e,t,n)=>{if(t.length===0)return h(n);let i=Aa(e,t,n),a=e===`Forall`?`\\<forall>`:`\\<exists>`;if(i.first.domain.kind===`NoDomain`)return o(i.first.name,e=>`${a}${e} : ${c(i.inner)}`);if(i.first.domain.kind!==`Domain`)throw new r;let s=c(i.first.domain.expression);return o(i.first.name,e=>`${a} ${e} \\<in> ${s} : ${c(i.inner)}`)},m=e=>{if(e.context.length===0)return c(e.active);let n=e.context[0],r=()=>m({context:e.context.slice(1),active:e.active});switch(n.kind){case`Flex`:return o(n.name,e=>`(\\<And> ${e} ${e}'.${r()})`);case`Fresh`:{if(n.domain&&n.domainVisibility===`Visible`){let e=c(n.domain);return o(n.name,t=>`(\\<And> ${t} :: c. ${t} \\<in> ${e} \\<Longrightarrow> ${r()})`)}let e=`${`c => `.repeat(n.shape)}c`;return o(n.name,t=>`(\\<And> ${t} :: ${e}. ${r()})`)}case`Fact`:{let e=n.visibility===`Visible`?c(n.expression):void 0;a();let i=e?`(${e} \\<Longrightarrow> ${r()})`:r();return _n(t,1),i}case`Defn`:throw new i(`Inner definition`)}},h=e=>{switch(e.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return f(e,[]);case`Apply`:return f(e.operator,e.args);case`Bang`:throw new s(`Backend.Isabelle.module`);case`Sequent`:return m(e.sequent);case`With`:case`Parens`:return h(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?h(e.items[0]):e.items.map(c).join(e.bullet===`Or`?` | `:` & `);case`If`:return`cond(${c(e.condition)}, ${c(e.consequent)}, ${c(e.alternative)})`;case`Quant`:return p(e.quantifier,e.bounds,e.body);case`Tquant`:throw new i(e.quantifier===`Forall`?`\\\\AA`:`\\\\EE`);case`Choose`:{if(!e.domain)return o(e.name,t=>`Choice(%${t}. ${c(e.body)})`);let t=c(e.domain);return o(e.name,n=>`bChoice(${t}, %${n}. ${c(e.body)})`)}case`SetSt`:{let t=c(e.domain);return o(e.name,n=>`subsetOf(${t}, %${n}. ${c(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=c(t.domain.expression);return o(t.name,t=>`setOfAll(${n}, %${t}. ${c(e.element)})`)}case`SetEnum`:return`{${l(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`?c(t.domain.expression):void 0;return o(t.name,t=>`[${n===void 0?t:` ${t} \\<in> ${n} `} \\<mapsto> ${c(e.body)}]`)}case`FcnApp`:{let t=c(e.function);return e.args.length===1?`fapply (${t}, ${c(e.args[0])})`:`fapply (${t}, <<${l(e.args)}>>)`}case`Arrow`:return`[${c(e.domain)} \\<rightarrow> ${c(e.range)}]`;case`Rect`:return`[${e.fields.map(e=>`''${e.name}'' : ${c(e.value)}`).join(`, `)}]`;case`Record`:return`(${e.fields.map(e=>`(''${e.name}'' :> ${c(e.value)})`).join(` @@ `)})`;case`Except`:{let t=e.specs.map(e=>`!${e.trail.map(e=>e.kind===`Dot`?`[''${e.field}'']`:`[${c(e.expression)}]`).join(``)} = ${c(e.value)}`);return`[${c(e.function)} EXCEPT ${t.join(`, `)}]`}case`Dot`:return`fapply (${c(e.expression)}, (''${e.field}''))`;case`Tuple`:return`<<${l(e.elements)}>>`;case`Product`:return e.factors.length===2?`(${c(e.factors[0])} \\<times> ${c(e.factors[1])})`:`Product(\\<langle>${l(e.factors)}\\<rangle>)`;case`Sub`:case`Tsub`:{let t=e.kind===`Sub`?`sub`:`tsub`;return`${e.modal===`Box`?Ma(`a'box'${t}`):`a'dia'${t}`}(${c(e.action)},${c(e.subscript)})`}case`Fair`:return`${Ma(e.fairness===`Weak`?`a'wf`:`a'sf`)}(${c(e.subscript)},${c(e.action)})`;case`Case`:{let t=l(e.arms.map(e=>e.condition)),n=l(e.arms.map(e=>e.body));return e.other?`CaseOther(<<${t}>>,<<${n}>>,${c(e.other)})`:`Case(<<${t}>>,<<${n}>>)`}case`String`:return`''${e.value}''`;case`Num`:if(e.fraction!==``)throw new i(`real constants`);return`(${Ra(e.integer)})`;case`At`:throw new r}},g=e=>{let r=[];for(let o of e.context)switch(o.kind){case`Flex`:{let e=n(o.name);r.push(`fixes ${e} ${e}'`);break}case`Fresh`:{let e=o.domain&&o.domainVisibility===`Visible`?c(o.domain):void 0,t=n(o.name);if(r.push(`fixes ${t}`),e===void 0)break;r.push(`assumes ${t}_in : "(${t} \\<in> ${e})"`);break}case`Fact`:{let e=t.stack.length,n=o.visibility===`Visible`?ja(t,()=>c(o.expression)):void 0;if(a(),n instanceof i){r.push(`(* omitted temporal assumption : ${n.message} *)`);break}if(n===void 0)break;r.push(`assumes v'${e}: "${n}"`);break}case`Defn`:if(o.definition.kind===`Bpragma`)return[...r,``];r.push(`(* usable definition ${o.definition.name} suppressed *)`),n(o.definition.name)}return[...r,`shows "${c(e.active)}"`]};try{let t=g(e);return{text:t.join(`
28
+ `),isAssumed:t.some(e=>e.startsWith(`assumes `))}}catch(e){throw e instanceof i?new s(`isabelle : unsupported operator ${e.message}`):e}},Va=(e,t,n)=>{let r=Ba(t);return[...za(`tlapm_${e}`,!1),`lemma ob'${e}:`,`${r.text}(is "PROP ?ob'${e}")`,`proof -`,`show "PROP ?ob'${e}"`,`${r.isAssumed?`using assms `:``}by ${n}`,`qed`,`end`,``].join(`
29
+ `)},Ha=(e,t)=>[...za(e,!0),...t.flatMap(e=>[`lemma ob'${e.id}:`,`${Ba(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
+ `),Ua=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],Wa=Array.from({length:64},(e,t)=>Math.floor(Math.abs(Math.sin(t+1))*2**32)),Ga=(e,t)=>e<<t|e>>>32-t,Ka=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+Wa[o]+t[l]|0;return[i,n+Ga(u,Ua[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(``)},qa=(e,t)=>{let n=Se(e,t-1)?.hyp;if(!n)throw new r;return n},Ja=(e,t)=>xr(e,t).level,Ya=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),Xa=(e,t)=>{let n=Ce(void 0,(n,r)=>{let i=Je(r,t=>e(n,t),t);return[k(n,i),i]});return(t,r)=>{let i=n(t,r.context);return{context:i.context,active:e(i.state,r.active)}}},Za=(e,t)=>{if(t.kind===`Sub`||t.kind===`Tsub`){let n=Za(e,t.action),r=Za(e,t.subscript),i=O(`UNCHANGED`,[r],t),a=t.modal===`Box`?O(`Disj`,[n,i],t):O(`Conj`,[n,O(`Neg`,[i],t)],t);return t.kind===`Sub`?a:O(t.modal===`Box`?`BoxTrue`:`Diamond`,[a],t)}return L(e,t,Za,k,`all`)},Qa=(e,t)=>t.kind===`Apply`&&Ya(t,[`UNCHANGED`])&&t.args.length===1?_t(t.args[0]):L(e,t,Qa,k,`all`),$a=(e,t)=>O(e,[t],t),eo=(e,t)=>{if(t.kind===`Ix`){let n=qa(e,t.index);return n.kind===`Fresh`&&n.level===`Constant`||n.kind===`Defn`&&n.definition.kind===`Operator`&&Ja(Se(e,t.index),n.definition.body)===0?t:$a(`Prime`,t)}if(Ya(t,[`ENABLED`])||t.kind===`Opaque`||t.kind===`Sequent`||t.kind===`Let`)return $a(`Prime`,t);if(Ya(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,eo,k)},to=e=>{let t=e===`BoxTrue`?`Conj`:`Disj`,n=e===`BoxTrue`?`Forall`:`Exists`,r=(i,a)=>Ja(i,a)===0?a:Ya(a,[t])||(a.kind===`Quant`||a.kind===`Tquant`)&&a.quantifier===n?L(i,a,r,k):$a(e,a);return r},no={Prime:eo,BoxTrue:to(`BoxTrue`),Diamond:to(`Diamond`)},ro=(e,t)=>{if(t.kind===`Apply`&&t.operator.kind===`Internal`){let n=no[t.operator.builtin];if(n){if(t.args.length!==1)throw new r;return n(e,t.args[0])}}return L(e,t,ro,k,`all`)},io=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],ao={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},oo=(e,t)=>`${e}_${t}_`,so=(e,t,n)=>{if(t.kind!==`Operator`)return t.kind===`Bpragma`?{...t,body:U(e,t.body)}:t;let i=U(e,t.body),a=io[n??Ja(e,i)];if(a===void 0)throw new r;return{...t,name:oo(a,t.name),body:i}},co=(e,t,n)=>{switch(t.kind){case`Fresh`:return{...t,name:oo(ao[t.level],t.name),domain:t.domain&&U(e,t.domain)};case`Flex`:return{...t,name:oo(`VARIABLE`,t.name)};case`Defn`:return{...t,definition:so(e,t.definition,n)};case`Fact`:return{...t,expression:U(e,t.expression)}}},lo=(e,t)=>{if(t.kind!==`Defn`||t.definition.kind!==`Operator`)return;let n=t=>{if(!Ya(t,[`UNCHANGED`])||t.kind!==`Apply`)return Ja(e,t);let n=e=>e.kind===`Tuple`?e.elements.flatMap(n):[e],r=n(t.args[0]);return Ja(e,r.length===1?r[0]:t.args[0])},r=t.definition.body;return n(Ya(r,[`Prime`,`BoxTrue`,`Diamond`])&&r.kind===`Apply`&&r.args.length===1&&r.kind===`Apply`?r.args[0]:r)},uo=Ce({scope:void 0,original:void 0},(e,t,n)=>{let r=co(e.scope,t,lo(e.original,n));return[{scope:k(e.scope,r),original:k(e.original,n)},r]}),fo=(e,t)=>{let n=uo(t.context,e.context);return{context:n.context,active:U(n.state.scope,e.active)}},po=(e,t)=>{let[n,r]=j(e,t.context,(e,t)=>{let n=co(e,t);return[k(e,n),n]});return{context:r,active:U(n,t.active)}},U=(e,t)=>{switch(t.kind){case`Lambda`:{let n=t.params.map(e=>({...e,name:oo(`Unknown`,e.name)})),r=A(e,n.map(De));return{...t,params:n,body:U(r,t.body)}}case`Tquant`:{let n=A(e,t.names.map(e=>({kind:`Flex`,name:oo(`VARIABLE`,e)})));return{...t,body:U(n,t.body)}}case`Choose`:{let n=t.domain&&U(e,t.domain),r=oo(`CONSTANT`,t.name),i=n?Te(r,n):we(r,`Constant`);return{...t,name:r,domain:n,body:U(k(e,i),t.body)}}case`SetSt`:{let n=U(e,t.domain),r=oo(`CONSTANT`,t.name),i=U(k(e,Te(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:oo(ao[t.level],t.name),domain:t.domain.kind===`Domain`?{kind:`Domain`,expression:U(e,t.domain.expression)}:t.domain})),r=A(e,n.map(Ee));return t.kind===`SetOf`?{...t,bounds:n,element:U(r,t.element)}:{...t,bounds:n,body:U(r,t.body)}}case`Let`:{let[n,r]=j(e,t.definitions,(e,t)=>{let n=so(e,t);return[k(e,Oe(n)),n]});return{...t,definitions:r,body:U(n,t.body)}}case`Sequent`:return{...t,sequent:po(e,t.sequent)};default:return L(e,t,U,k,`all`)}},mo=/* @__PURE__ */ new WeakMap,ho=(e,t)=>{let n=mo.get(t);if(n)return n;let r=t.kind===`Operator`?t.body:void 0;if(r?.kind!==`Lambda`)return[];let i=A(e,r.params.map(De)),a=r.params.map((e,t)=>vo(i,r.body,t+1,!0));return mo.set(t,a),a},go=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`ENABLED`,`UNCHANGED`],_o=[`Leadsto`,`Actplus`,`Cdot`],vo=(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(go.includes(r)&&t.args.length===1||_o.includes(r)&&t.args.length===2)return t.args.every(t=>vo(e,t,n,!1))}if(t.kind===`Sub`)return[t.action,t.subscript].every(t=>vo(e,t,n,!1));if(t.kind===`Apply`&&t.operator.kind===`Ix`){let i=Se(e,t.operator.index-1),a=i?.hyp;if(i&&a?.kind===`Defn`&&a.definition.kind===`Operator`){let o=ho(i.rest,a.definition);return t.args.every((t,i)=>{let a=o[i];if(a===void 0)throw new r;return vo(e,t,n,a)})}}let a={isSubstitutive:!0};return L({scope:e,index:n},t,(e,t)=>(a.isSubstitutive&&=vo(e.scope,t,e.index,i),t),(e,t)=>({scope:k(e.scope,t),index:e.index+1}),`all`),a.isSubstitutive},yo=(e,t)=>{let n=fn(In(be(e),t));return`h${Ka(n).slice(0,5)}`},bo=(e,t)=>E({kind:`Opaque`,name:yo(e,t)},t),xo=(e,t,n,r,i)=>{let a=i.map((t,r)=>Ja(e,t)===0||n[i.length-r-1]?E({kind:`Opaque`,name:`*`},t):t);return bo(e,E({kind:`Apply`,operator:{kind:`Opaque`,name:t},args:a},r))},So=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`Leadsto`,`ENABLED`,`Cdot`,`UNCHANGED`],Co=(e,t)=>{if(t.kind!==`Apply`)return L(e,t,Co,k);let n=t.operator,[i]=t.args;if(Ya(t,[`Prime`,`StrongPrime`])&&t.args.length===1&&i.kind===`Ix`){let n=qa(e,i.index);if(n.kind===`Fresh`||n.kind===`Flex`)return E({kind:`Opaque`,name:`${n.name}#prime`},t)}if(Ya(t,So))return bo(e,t);if(n.kind!==`Ix`)return L(e,t,Co,k);let a=Se(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=ho(a.rest,o.definition);if(s.every((t,n)=>Ja(e,t)===0||r[s.length-n-1]))return L(e,t,Co,k);let i=xo(e,o.definition.name,r,n,s);return E({kind:`Apply`,operator:i,args:s.map(t=>Co(e,t))},t)}if(o.kind===`Flex`)return L(e,t,Co,k);if(o.kind===`Fresh`){if(o.level===`Constant`)return E({kind:`Apply`,operator:n,args:s.map(t=>Co(e,t))},t);let r=s.map(()=>!1);return xo(e,o.name,r,n,s)}throw new r},wo=Xa(Za,`all`),To=Xa(Qa,`all`),Eo=Xa(ro,`all`),Do=Xa(Co,`visible`),Oo=e=>{let t=e.context,n=To(t,wo(t,e)),r=Eo(t,n);return Do(t,fo(r,e))},ko=e=>Ce(w(0),(t,n)=>n.kind===`Defn`&&(e&&n.definition.kind===`Bpragma`||n.definition.kind===`Operator`&&n.visibility===`Visible`)?[ge(N(t,n.definition.body),t),void 0]:[T(1,t),Fe(t,n)]),Ao=ko(!0),jo=ko(!1),Mo=(e,t=!0)=>{let n=(t?Ao:jo)(e.context);return{context:n.context,active:N(n.state,e.active)}},No=/* @__PURE__ */ new Set([`BoxTrue`,`BoxFalse`,`Diamond`,`Actplus`,`Leadsto`,`Cdot`]),Po=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]}},Fo=e=>{if(e.kind===`Tsub`||e.kind===`Fair`||e.kind===`Apply`&&e.operator.kind===`Internal`&&No.has(e.operator.builtin))return!1;if(e.kind===`Sequent`){let t=e.sequent;return[...t.context.flatMap(Po),t.active].every(Fo)}return Xe(e).every(Fo)},Io=t=>{if(t.kind!==`Let`)return Ye(t,Io);let[n,...r]=t.definitions;if(!n)return Io(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=Io(n.body),a={...t,definitions:r};return Io(N(ge(i,w(0)),a))},Lo=(e,t)=>t.kind===`Dot`?E({kind:`Dot`,expression:e,field:t.field},e):E({kind:`FcnApp`,function:e,args:[t.expression]},e),Ro=(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&I(e.expression,t.expression),zo=(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},Bo=e=>{if(e.kind!==`Except`)return Ye(e,Bo);let t=e,n=(e,t)=>zo(e,t)?.value??Lo(e,t),r=(e,n,r)=>{let i=zo(e,n);if(e.kind!==`Record`||!i)return E({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 E({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||!Ro(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(Bo(t.function),Ke(t.specs,Bo))},Vo=Ce(!0,(e,t)=>[e&&Po(t).every(Fo),Je(t,Io,`all`)]),Ho=Ce(void 0,(e,t)=>[void 0,Je(t,Bo,`all`)]),Uo=e=>{let t=Vo(e.context),n=Io(e.active);return t.state&&Fo(e.active)?{context:Ho(e.context,t.context).context,active:Bo(n)}:{context:t.context,active:n}},Wo={kind:`Internal`,builtin:`TRUE`},Go=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2?e.args:void 0,Ko=e=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`ENABLED`&&e.args.length===1?e.args[0]:void 0,qo=(e,t)=>{let n=Go(e,t),r=n&&Ko(n[0]),i=n&&Ko(n[1]);return r&&i?[r,i]:void 0},Jo=(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=Se(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:k(e.scope,t)}));return t};return i({scope:e,isPrimed:!1},t),n},Yo=(e,t,n)=>{let r=Jo(e,t);return[...Jo(e,n)].every(e=>!r.has(e))},Xo=(e,t)=>{let n=t=>xr(e,t).level,i=(e,t)=>{if(n(e)>2||n(t)>2)throw new r},a=Ko(t),o=a&&Go(a,`Disj`);if(o)return i(o[0],o[1]),{name:`abdisj_inverse`,left:o[0],right:o[1]};let s=qo(t,`Disj`);if(s)return i(s[0],s[1]),{name:`abdisj`,left:s[0],right:s[1]};let c=a&&Go(a,`Conj`);if(c){let t=c[0],r=c[1],a=Yo(e,t,r);return i(t,r),a?{name:n(t)===2?`abconj_inverse`:`pconj_inverse`,left:t,right:r}:void 0}let l=qo(t,`Conj`);if(l)return Yo(e,l[0],l[1])?{name:`abconj`,left:l[0],right:l[1]}:void 0;let u=Go(t,`Conj`),d=u&&Ko(u[1]);if(u&&d)return n(u[0])<=1&&n(d)<=2?{name:`pconj`,left:u[0],right:d}:void 0;let f=qo(t,`Equiv`)??qo(t,`Eq`);if(f)return{name:`equiv`,left:f[0],right:f[1]};let p=qo(t,`Implies`);return p&&{name:`implies`,left:p[0],right:p[1]}},Zo=e=>{let t=A(void 0,e.context),n=Xo(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(P(a,e),n.left),c=e=>I(P(a,e),n.right),l=(e,t)=>e!==void 0&&s(e[0])&&c(e[1])&&t.includes(n.name),u=Ko(o),d=u&&Go(u,`Conj`),f=Go(o,`Conj`),p=f&&Ko(f[1]),m=Go(o,`Mem`),h=m?.[1].kind===`Internal`&&m[1].builtin===`BOOLEAN`;l(d,[`pconj`])||l(u&&Go(u,`Disj`),[`abdisj`])||l(qo(o,`Disj`),[`abdisj_inverse`])||l(d,[`abconj`])||l(qo(o,`Conj`),[`abconj_inverse`,`pconj_inverse`])||l(f&&p&&[f[0],p],[`pconj_inverse`])?r.isPremise=!0:l(Go(o,`Equiv`),[`equiv`])?(r.isPremise=!0,r.isLeftBoolean=!0,r.isRightBoolean=!0):l(Go(o,`Eq`),[`equiv`])?r.isPremise=!0:m&&h&&s(m[0])?r.isLeftBoolean=!0:m&&h&&c(m[0])?r.isRightBoolean=!0:l(Go(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:Wo}},Qo={Constant:0,State:1,Action:2,Temporal:3},$o=(e,t,n)=>e.every((e,r)=>r<t.length&&n(e,t[r]))&&e.length===t.length,es=e=>[...new Map(e.toReversed().map(e=>[e.name,e.value]))].toSorted((e,t)=>e[0]<t[0]?-1:1),ts=(e,t)=>{let n=Se(e,t-1);if(!n)throw new r;let i=n.hyp;if(i.kind===`Fresh`)return{name:i.name,kind:i.level,level:Qo[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=xr(n.rest,i.definition.body).level;return{name:i.definition.name,kind:`Definition`,level:e}}throw new r},ns=(e,t)=>A(e,t.map(Ee)),rs=(e,t)=>A(e,t.map(De)),is=(e,t)=>A(e,t.map(Oe)),as=(e,t)=>A(e,t.map(e=>({kind:`Flex`,name:e}))),os=(e,t,n,i)=>{let a=/* @__PURE__ */ new Map,o=(e,t,n,r)=>{let i=ts(e,n),o=ts(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=Qo[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)=>A(e,t.map(e=>we(e,`Unknown`))),s=e=>es(e.substitutions.map(e=>({name:e.name,value:e.expression})));return $o(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)=>$o(n,r,(n,r)=>n[0]===r[0]&&p(e,t,n[1],r[1])),l=(e,t,n,r)=>$o(n,r,(n,r)=>{if(n.level!==r.level)return!1;let i=n.domain,a=r.domain;return i.kind===`Domain`&&a.kind===`Domain`?p(e,t,i.expression,a.expression):i.kind===a.kind&&i.kind!==`Domain`}),u=(e,t,n,r)=>n.kind===`Fresh`&&r.kind===`Fresh`?n.level!==r.level||n.shape!==r.shape?!1:n.domain&&r.domain?p(e,t,n.domain,r.domain):!n.domain&&!r.domain:n.kind===`Flex`&&r.kind===`Flex`?!0:n.kind===`Defn`&&r.kind===`Defn`?s(e,t,n.definition,r.definition)&&n.isLocal===r.isLocal:n.kind===`Fact`&&r.kind===`Fact`&&p(e,t,n.expression,r.expression),d=(e,t,n,r)=>n.length===0||r.length===0?n.length===r.length:u(e,t,n[0],r[0])&&d(k(e,n[0]),k(t,r[0]),n.slice(1),r.slice(1)),f=(e,t,n,r)=>!n.domain||!r.domain?!n.domain&&!r.domain&&p(k(e,we(n.name,`Constant`)),k(t,we(r.name,`Constant`)),n.body,r.body):p(e,t,n.domain,r.domain)&&p(k(e,Te(n.name,n.domain)),k(t,Te(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)=>$o(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(rs(e,n.params),rs(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(A(e,n.sequent.context),A(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`&&$o(n.definitions,i.definitions,(n,r)=>s(e,t,n,r))&&p(is(e,n.definitions),is(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(ns(e,n.bounds),ns(t,n.bounds),n.body,i.body);case`Tquant`:return i.kind===`Tquant`&&n.quantifier===i.quantifier&&$o(n.names,i.names,(e,t)=>e===t)&&p(as(e,n.names),as(t,i.names),n.body,i.body);case`Choose`:case`SetSt`:return i.kind===n.kind&&f(e,t,n,i);case`SetOf`:return i.kind===`SetOf`&&p(ns(e,n.bounds),ns(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(ns(e,n.bounds),ns(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`:case`Record`:return i.kind===n.kind&&c(e,t,es(n.fields),es(i.fields));case`Except`:return i.kind===`Except`&&a(n.function,i.function)&&$o(n.specs,i.specs,(e,t)=>$o(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`:case`Tsub`:return i.kind===n.kind&&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=be(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)},ss=e=>{let t=A(void 0,e.context);if(!e.context.some((n,r)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return!1;let i=Se(t,e.context.length-r),a=n.expression;return a.kind===`Sequent`?os(A(i,a.sequent.context),t,a.sequent.active,e.active):os(i,t,a,e.active)}))throw new s(`LevelComparison proof directive did not succeed.
32
+ `);return{...e,active:{kind:`Internal`,builtin:`TRUE`}}},cs=(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`)?ss(e):t.has(`enabledaxioms`)?Zo(e):e;let s=It({value:0},()=>{throw new r},()=>{}),c={kind:`Sequent`,sequent:e},l=n||i?qr(s,()=>{},void 0,c,{isEnabled:n,isCdot:i,isAutoUse:a}):Wr(s,()=>{},void 0,c,{isEnabled:!0,isCdot:!0,isAutoUse:a});if(l.kind!==`Sequent`)throw new r;return l.sequent},ls=/* @__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(`.`),us={And:0,Or:1,Refs:2},ds={Forall:0,Exists:1},fs={Box:0,Dia:1},ps={Weak:0,Strong:1},ms={34:`\\"`,92:`\\\\`,10:`\\n`,9:`\\t`,13:`\\r`,8:`\\b`},hs=e=>`"${[...new TextEncoder().encode(e)].map(e=>ms[e]??(e<32||e>126?`\\${String(e).padStart(3,`0`)}`:String.fromCharCode(e))).join(``)}"`,gs=e=>e===`BoxTrue`?`$Box`:e===`BoxFalse`?`$FakeBox`:`$${ls.indexOf(e)}`,_s=e=>e.level===`Unknown`?`Unknown`:e.level.toUpperCase(),vs=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 gs(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(${us[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(${ds[t.quantifier]};${f(e.entries,t.bounds)}.${e.text})`}case`Tquant`:{let e=p(t.names.length,t.body);return`$Tquant(${ds[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}(${fs[t.modal]},${a(t.action)},${a(t.subscript)})`;case`Fair`:return`$Fair(${ps[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 hs(t.value);case`Num`:return`$Num(${t.integer},${t.fraction})`;case`At`:return`$At`;case`Bang`:throw new r}},d=e=>{let t={hyp:1,variable:1},n=(o,s)=>{let c=e.context[o];if(!c)return`$Goal(${u(t,e.active)})`;let d=e=>(i(e),{rest:n(o+1,k(s,c)),entry:a()});switch(c.kind){case`Fresh`:{if(!c.domain){let e=_s(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},${Dt(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)},ys=e=>Ka(vs(e)),bs=e=>e.domain.kind===`NoDomain`,xs=e=>{if(e.kind===`List`&&(e.bullet===`And`||e.bullet===`Refs`)){let t=e.items.map(xs),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=xs(e.args[0]),n=xs(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(bs)){let t=xs(e.body),n=(t,n)=>E({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]},Ss=e=>{let t=[],n=e.context.reduce((e,n)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return t.push(Fe(e,n)),T(1,e);let r=xs(n.expression),i=[...r[1]?[r[1]]:[],...r[0]];return i.forEach((r,i)=>t.push({...n,expression:P(i,N(e,r))})),{kind:`Compose`,outer:w(i.length-1),inner:T(1,e)}},w(0));return{context:t,active:N(n,e.active)}},Cs=/* @__PURE__ */ new Set([`expandenabled`,`expandcdot`,`autouse`,`lambdify`,`enabledaxioms`,`levelcomparison`]),ws=[{prover:`smt`,timeLimitMs:5e3},{prover:`zenon`,timeLimitMs:1e4},{prover:`isabelle`,timeLimitMs:3e4,tactic:`auto`}],Ts={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([...Cs].map(e=>[e,{prover:e,seconds:0}]))},Es=(e,t,n,r)=>{let i=Ts[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`}}},Ds=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)))},Os=(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:Ds(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 Es(n.prover,n.timeout,n.rlimit,n.tactic)},ks=e=>Es(e.name,e.timeout,void 0,e.tactic),As=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(ks(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=>Os(e,t)))}else if(s?.kind===`Meth`){if(a.kind===`Apply`)throw new r;n.methods.push(ks(s.method))}}),n.methods},js=e=>{let t=e.method===void 0?As(e.sequent):[ks(e.method)],n=t.filter(e=>!Cs.has(e.prover));return{frontends:new Set(t.flatMap(e=>Cs.has(e.prover)?[e.prover]:[])),provers:n.length>0?n:ws}},Ms=e=>e.active.kind===`Internal`&&e.active.builtin===`TRUE`||e.context.some((t,n)=>t.kind===`Fact`?I(t.expression,P(n-e.context.length,e.active)):t.kind!==`Fresh`||!t.domain?!1:I(O(`Mem`,[{kind:`Ix`,index:1},P(1,t.domain)],{}),P(n+1-e.context.length,e.active))),Ns={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},Ps=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],Fs=(e,t)=>{let[n,r]=j(e,t.context,(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return{...t,name:`${Ns[t.level]}_${t.name}_`,domain:t.domain&&Is(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=Is(e,n.body),i=Ps[xr(e,r).level];return{...t,definition:{...n,name:`${i}_${n.name}_`,body:r}}}case`Fact`:return{...t,expression:Is(e,t.expression)}}})();return[k(e,n),n]});return{context:r,active:Is(n,t.active)}},Is=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:Fs(e,t.sequent)};let n=L(e,t,Is,k,`all`);switch(n.kind){case`Lambda`:return{...n,params:n.params.map(e=>({...e,name:`Unknown_${e.name}_`}))};case`Quant`:case`Fcn`:case`SetOf`:return{...n,bounds:n.bounds.map(e=>({...e,name:`${Ns[e.level]}_${e.name}_`}))};case`Choose`:case`SetSt`:return{...n,name:`CONSTANT_${n.name}_`};default:return n}},Ls=(e,t)=>{if(t.kind!==`Sequent`)return L(e,t,Ls,k,`all`);let n={scope:e,substitution:w(0),context:[]},r=e=>{let t=e.kind===`Fact`&&e.visibility===`Visible`&&e.time===`Always`?{...e,expression:O(`BoxTrue`,[e.expression],e.expression)}:e;n.context.push(t),n.scope=k(n.scope,t)};for(let e of t.sequent.context){let t=Fe(n.substitution,e);if(t.kind!==`Fresh`||!t.domain||e.kind!==`Fresh`||!e.domain){r(t.kind===`Fact`?{...t,expression:Ls(n.scope,t.expression)}:t),n.substitution=T(1,n.substitution);continue}let i=Ls(n.scope,t.domain);r({...t,domain:void 0}),r({kind:`Fact`,expression:O(`Mem`,[E({kind:`Ix`,index:1},i),P(1,i)],i),visibility:t.domainVisibility,time:t.level===`Constant`?kt(n.scope,e.domain):`Now`,location:t.location}),n.substitution={kind:`Compose`,outer:w(1),inner:T(1,n.substitution)}}let i=N(n.substitution,t.sequent.active);return{...t,sequent:{context:n.context,active:Ls(n.scope,i)}}},Rs={Conj:`&`,Disj:`|`,Implies:`->`,Equiv:`<->`},zs={Neg:`~`,BoxTrue:`always`,BoxFalse:`always`,Diamond:`sometime`,Prime:`next`},Bs=e=>{if(e.kind===`Internal`&&e.builtin===`TRUE`)return;if(e.kind===`List`&&e.bullet!==`Or`){let t=e.items.flatMap(e=>Bs(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=Bs(e.args[0]),n=Bs(e.args[1]);return t&&n?{...e,args:[t,n]}:t??n},Vs=`(cc | ~ cc)`,Hs=e=>{let t=(e,n,r=!1)=>{let i=n=>t(e,n);switch(n.kind){case`Internal`:if(n.builtin===`TRUE`)return Vs;if(n.builtin===`FALSE`)return`(cc & ~ cc)`;break;case`Apply`:{let e=n.operator,t=n.args;if(e.kind!==`Internal`)break;let r=Rs[e.builtin];if(r&&t.length===2)return`(${i(t[0])} ${r} ${i(t[1])})`;let a=zs[e.builtin];if(a&&t.length===1)return`(${a} ${i(t[0])})`;break}case`List`:{if(n.items.length===0)return Vs;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?Bs(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${Ka(fn(In(e,n))).slice(0,5)}`},n=Is(void 0,{kind:`Sequent`,sequent:e});return`not (${t([],Ls(void 0,xt(yt(bt(n)))),!0)})`},Us=(e,t)=>e<t?-1:+(e>t),Ws=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Us(e,t);if(!Array.isArray(e)||!Array.isArray(t))return 0;let n=e.findIndex((e,n)=>n>=t.length||Ws(e,t[n])!==0);return n===-1?e.length-t.length:n>=t.length?1:Ws(e[n],t[n])},Gs={"\\":`backslash_`,"+":`plussign_`,"-":`hyphen_`,"*":`asterisk_`,"/":`slash_`,"%":`percentsign_`,"^":`circumflexaccent_`,"&":`ampersand_`,"@":`atsign_`,"#":`pound_`,$:`dollarsign_`,"(":`leftparenthesis_`,")":`rightparenthesis_`,"|":`verticalbar_`,".":`period_`,":":`colon_`,"?":`questionmark_`,"!":`exclamationmark_`,"<":`lessthansign_`,">":`greaterthansign_`,"=":`equalsign_`," ":`space_`},Ks=e=>`smt__${e.replace(/[\\+\-*/%^&@#$()|.:?!<>= ]/g,e=>Gs[e]).replaceAll(`_`,`__`)}`,qs=Ks(`TLA__`),Js=new Map(Object.entries(Gs).map(e=>[e[1],e[0]])),Ys=RegExp(`(${[...Js.keys()].join(`|`)})`,`g`),W=e=>Ks(`TLA__${e}`),Xs=e=>e.startsWith(qs)?e.slice(qs.length).replaceAll(`__`,`_`).replace(Ys,e=>Js.get(e)??e):void 0,G=W(`Mem`),Zs=W(`SetExtTrigger`),Qs=W(`SubsetEq`),$s=W(`Cup`),ec=W(`Cap`),tc=W(`SetMinus`),nc=W(`Subset`),rc=W(`Union`),ic=W(`Tt_Idv`),ac=W(`Cast_Bool`),oc=W(`BoolSet`),sc=W(`StrSet`),cc=W(`IntSet`),lc=W(`NatSet`),K=W(`Cast_Int`),q=W(`Proj_Int`),uc=W(`IntLteq`),dc=W(`IntRange`),J=W(`FunApp`),fc=W(`FunDom`),pc=W(`FunIsafcn`),mc=W(`FunSet`),hc=W(`FunExcept`),gc=W(`TrigEq_Set$Idv$`),_c=W(`IsSetOf`),Y=W(`Seq`),X=W(`Len`),vc=W(`Cat`),yc=W(`Append`),bc=W(`Head`),xc=W(`Tail`),Sc=W(`SubSeq`),Cc=W(`Tuple_0`),wc={Cup:$s,Cap:ec,Setminus:tc,SUBSET:nc,UNION:rc,DOMAIN:fc,Plus:W(`IntPlus`),Minus:W(`IntMinus`),Times:W(`IntTimes`),Exp:W(`IntExp`),Quotient:W(`IntQuotient`),Remainder:W(`IntRemainder`),Uminus:W(`IntUminus`),Range:dc,Seq:Y,Len:X,BSeq:W(`BSeq`),Cat:vc,Append:yc,Head:bc,Tail:xc,SubSeq:Sc},Tc=(e,t)=>Array.from({length:t},(t,n)=>`${e}${n+1}`),Ec=(e,t=`Idv`)=>e.map(e=>`(${e} ${t})`).join(` `),Z=(e,t,n=[],r=`Idv`)=>e.length===0?t:`(forall (${Ec(e,r)}) ${n.length===0?t:`(! ${t} ${n.map(e=>`:pattern (${e.join(` `)})`).join(` `)})`})`,Dc=e=>e.length===0?`true`:e.length===1?e[0]:`(and ${e.join(` `)})`,Oc=e=>e.length===0?`false`:e.length===1?e[0]:`(or ${e.join(` `)})`,Q=(e,t)=>t.length===0?e:`(${e} ${t.join(` `)})`,kc=(e,t,n=`Idv`,r=`Idv`)=>`(declare-fun ${e} (${Array.from({length:t},()=>r).join(` `)}) ${n})`,Ac=(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},jc=(e,t,n)=>e.replace(/[^\s()]+/g,e=>e===t?n:e),Mc=/* @__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(`.`),Nc=/* @__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(`.`),Pc=[`TIntPlus`,`TIntUminus`,`TIntMinus`,`TIntTimes`,`TIntQuotient`,`TIntRemainder`,`TIntLteq`],$=(e,t,n,r)=>({name:e,args:t,label:r??[e,...t.flat()].join(` `),formula:n}),Fc=e=>`${e.name} ${JSON.stringify(e.args)}`,Ic=e=>{let t=Mc.indexOf(e.name);return t===-1?Mc.length+Nc.indexOf(e.name):t},Lc=(e,t)=>Ic(e)-Ic(t)||Ws(e.args,t.args),Rc={IntPlus:[`+`,2],IntMinus:[`-`,2],IntTimes:[`*`,2],IntUminus:[`-`,1],IntQuotient:[`div`,2],IntRemainder:[`mod`,2],IntLteq:[`<=`,2]},zc=e=>{let t=Rc[e][0],n=t===`div`||t===`mod`,r=Rc[e][1]===1?[`x1`]:n?[`x`,`y`]:[`x1`,`x2`],i=Q(W(e),r.map(e=>`(${K} ${e})`)),a=`(= ${i} ${t===`<=`?`(<= ${r.join(` `)})`:`(${K} (${t} ${r.join(` `)}))`})`;return $(`Typing`,[Pc.indexOf(`T${e}`)],Z(r,n?`(=> (> y 0) ${a})`:a,[[i]],`Int`),`Typing T${e}`)},Bc=e=>{let t=W(`SetEnum_${e}`),n=Tc(`a`,e),r=Q(t,n),i=$(`EnumDefElim`,[e],Z([...n,`x`],e===0?`(not (${G} x ${r}))`:`(=> (${G} x ${r}) ${Oc(n.map(e=>`(= x ${e})`))})`,[[`(${G} x ${r})`]]));return e===0?[i]:[$(`EnumDefIntro`,[e],Z(n,Dc(n.map(e=>`(${G} ${e} ${r})`)),[[r]])),i]},Vc=e=>Array.from({length:e},(e,t)=>`(${K} ${t+1})`),Hc=e=>e.map(e=>W(`StrLit_${e}`)),Uc=(e,t,n,r)=>{let i=Tc(`x`,r.length);return r.map((r,a)=>{let o=`(${hc} ${Q(n,i)} ${r} x)`,s=i.map((e,t)=>t===a?`x`:e);return $(`${e}Except`,[...t,a+1],Z([...i,`x`],`(= ${o} ${Q(n,s)})`,[[o]]))})},Wc=e=>Uc(`Tup`,[e],W(`Tuple_${e}`),Vc(e)),Gc=e=>Uc(`Rec`,[e],W(`Record_${e.join(`_`)}`),Hc(e)),Kc=(e,t,n,r)=>{let i=Tc(`x`,r.length),a=Q(n,i),o=$(`${e}Isafcn`,t,Z(i,`(${pc} ${a})`,[[a]]));return r.length===0?[o]:[o,$(`${e}DomDef`,t,Z(i,`(= (${fc} ${a}) ${Q(W(`SetEnum_${r.length}`),r)})`,[[a]])),$(`${e}AppDef`,t,Z(i,Dc(r.map((e,t)=>`(= (${J} ${a} ${e}) ${i[t]})`)),[[a]]))]},qc=(e,t)=>{let n=W(`Tuple_${e}`),r=Tc(`x`,e),i=Q(n,r);return[...Kc(`Tup`,[e],n,Vc(e)),$(`SeqTupTyping`,[e],Z([`a`,...r],e===0?`(${G} ${i} (${Y} a))`:`(=> ${Dc(r.map(e=>`(${G} ${e} a)`))} (${G} ${i} (${Y} a)))`,[[...r.map(e=>`(${G} ${e} a)`),i]])),$(`SeqTupLen`,[e],Z(r,`(= (${X} ${i}) (${K} ${e}))`,[[i]])),...t?Wc(e):[]]},Jc=(e,t)=>[...Kc(`Rec`,[e],W(`Record_${e.join(`_`)}`),Hc(e)),...t?Gc(e):[]],Yc=(e,t,n,r,i,a)=>{let o=Tc(`s`,i.length),s=Tc(`x`,i.length),c=Q(n,o),l=Q(r,s),u=i.map(e=>`(${J} ${a} ${e})`);return[$(`${e}Intro`,t,Z([...o,...s],`(=> ${Dc(s.map((e,t)=>`(${G} ${e} ${o[t]})`))} (${G} ${l} ${c}))`,[[l,c]])),$(`${e}Elim`,t,Z([...o,a],`(=> (${G} ${a} ${c}) ${Dc([`(= ${a} ${Q(r,u)})`,...u.map((e,t)=>`(${G} ${e} ${o[t]})`)])})`,[[`(${G} ${a} ${c})`]]))]},Xc=[`Mem`,`Seq`,`Len`,`FunApp`,`NatSet`,`Cast_Int`,`Proj_Int`],Zc=(e,t)=>{let n=(e,t,n)=>({declaration:e,deps:t,axioms:n}),r=W(e),a=(e,t,i,a=`Idv`)=>n(kc(r,e,a),t,i),o=/^SetEnum_(\d+)$/.exec(e);if(o)return a(Number(o[1]),[`Mem`],Bc(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`],`(${Zs} a b)`,[[`(${_c} a)`,`(${_c} b)`]]))])}if(e.startsWith(`StrLit_`)){let n=e.slice(7),i=t.strings.map(e=>$(`StrLitDistinct`,[n,e],`(distinct ${r} ${W(`StrLit_${e}`)})`));return t.strings.push(n),a(0,[`Mem`,`StrSet`],[$(`StrLitIsstr`,[n],`(${G} ${r} ${sc})`),...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`],qc(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`],Yc(`Product`,[e],r,W(`Tuple_${e}`),Vc(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}`)],Jc(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}`)],Yc(`RecSet`,[u],r,W(e),Hc(u),`r`))}let d=t.anonymous.get(e);if(d!==void 0)return a(d,[],[]);let f=Rc[e];if(f)return a(f[1],[`Cast_Int`],[zc(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 (${G} x ${cc}) (${G} y ${cc}) (or (distinct x (${K} 0)) (${uc} (${K} 1) y))) (${G} (${r} x y) ${cc})) :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)) (= (${G} z x) (${G} z y))) (= x y)) :pattern ((${Zs} x y))))`)],`Bool`);case`SubsetEq`:return a(2,[`Mem`],[$(`SubsetEqIntro`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${G} z x) (${G} z y))) (${Qs} x y)) :pattern ((${Qs} x y))))`),$(`SubsetEqElim`,[],`(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${Qs} x y) (${G} z x)) (${G} z y)) :pattern ((${Qs} x y) (${G} z x))))`)],`Bool`);case`Union`:return a(1,[`Mem`],[$(`UnionIntro`,[],`(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${G} y a) (${G} x y)) (${G} x (${rc} a))) :pattern ((${G} y a) (${G} x (${rc} a))) :pattern ((${G} x y) (${G} x (${rc} a))) :pattern ((${G} y a) (${G} x y) (${rc} a))))`),$(`UnionElim`,[],`(forall ((a Idv) (x Idv)) (! (=> (${G} x (${rc} a)) (exists ((y Idv)) (and (${G} y a) (${G} x y)))) :pattern ((${G} x (${rc} a)))))`)]);case`Subset`:return a(1,[`Mem`,`SubsetEq`],[$(`SubsetDefAlt`,[],`(forall ((a Idv) (x Idv)) (! (= (${G} x (${nc} a)) (${Qs} x a)) :pattern ((${G} x (${nc} a))) :pattern ((${Qs} x a) (${nc} 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)) (! (= (${G} x (${r} a b)) ${t.replaceAll(`MEM`,G)}) :pattern ((${G} x (${r} a b))) :pattern ((${G} x a) (${r} a b)) :pattern ((${G} x b) (${r} a b))))`);return e===`Cap`?a(2,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[n,$(`DisjointTrigger`,[],`(forall ((x Idv) (y Idv)) (! (${Zs} (${ec} x y) ${W(`SetEnum_0`)}) :pattern ((${ec} 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)) (! (= (${G} x ${lc}) (and (${G} x ${cc}) (${uc} (${K} 0) x))) :pattern ((${G} x ${lc}))))`)]);case`IntRange`:return a(2,[`Mem`,`IntSet`,`IntLteq`],[$(`IntRangeDef`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${G} x (${dc} a b)) (and (${G} x ${cc}) (${uc} a x) (${uc} x b))) :pattern ((${G} x (${dc} a b)))))`)]);case`FunIsafcn`:return a(1,[`Mem`,`FunDom`,`FunFcn`,`FunApp`],[$(`FunExt`,[],`(forall ((f Idv) (g Idv)) (! (=> (and (${pc} f) (${pc} g) (= (${fc} f) (${fc} g)) (forall ((x Idv)) (=> (${G} x (${fc} f)) (= (${J} f x) (${J} g x))))) (= f g)) :pattern ((${pc} f) (${pc} g))))`)],`Bool`);case`FunSet`:return t.isFunSet=!0,a(2,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunSetIntro`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (and (${pc} f) (= (${fc} f) a) (forall ((x Idv)) (=> (${G} x a) (${G} (${J} f x) b)))) (${G} f (${mc} a b))) :pattern ((${G} f (${mc} a b)))))`),$(`FunSetElim1`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (${G} f (${mc} a b)) (and (${pc} f) (= (${fc} f) a))) :pattern ((${G} f (${mc} a b)))))`),$(`FunSetElim2`,[],`(forall ((a Idv) (b Idv) (f Idv) (x Idv)) (! (=> (and (${G} f (${mc} a b)) (${G} x a)) (${G} (${J} f x) b)) :pattern ((${G} f (${mc} a b)) (${G} x a)) :pattern ((${G} f (${mc} a b)) (${J} 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=`(${hc} f x y)`;return a(3,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunExceptIsafcn`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (${pc} ${e}) :pattern (${e})))`),$(`FunExceptDomDef`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (= (${fc} ${e}) (${fc} f)) :pattern (${e})))`),$(`FunExceptAppDef1`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (=> (${G} x (${fc} f)) (= (${J} ${e} x) y)) :pattern (${e})))`),$(`FunExceptAppDef2`,[],`(forall ((f Idv) (x Idv) (y Idv) (z Idv)) (! (=> (${G} z (${fc} f)) (and (=> (= z x) (= (${J} ${e} z) y)) (=> (distinct z x) (= (${J} ${e} z) (${J} f z))))) :pattern ((${J} ${e} z)) :pattern (${e} (${J} f z))))`),...t.tuples.flatMap(Wc),...t.records.flatMap(Gc)])}case`Seq`:return a(1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`Cast_Int`,`Proj_Int`],[$(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${pc} s) (>= (${q} (${X} s)) 0) (forall ((i Idv)) (= (${G} i (${fc} s)) (and (${G} i ${cc}) (<= 1 (${q} i)) (<= (${q} i) (${q} (${X} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${q} (${X} s)))) (${G} (${J} s (${K} i)) a)))) (${G} s (${Y} a))) :pattern ((${G} s (${Y} a)))))`),$(`SeqSetElim1`,[],`(forall ((a Idv) (s Idv)) (! (=> (${G} s (${Y} a)) (and (${pc} s) (${G} (${X} s) ${lc}) (= (${fc} s) (${dc} (${K} 1) (${X} s))))) :pattern ((${G} s (${Y} a)))))`,`SetSetElim1`),$(`SeqSetElim2`,[],`(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${G} s (${Y} a)) (<= 1 i) (<= i (${q} (${X} s)))) (${G} (${J} s (${K} i)) a)) :pattern ((${G} s (${Y} a)) (${J} s (${K} i)))))`,`SetSetElim2`)]);case`Len`:return a(1,[`FunDom`,`IntRange`,`Cast_Int`],[$(`SeqLenDef`,[],`(forall ((s Idv) (z Int)) (=> (and (>= z 0) (= (${fc} s) (${dc} (${K} 1) (${K} z)))) (= (${X} s) (${K} z))))`)]);case`BSeq`:return a(1,[],[]);case`Cat`:return a(2,Xc,[$(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${G} s (${Y} a)) (${G} t (${Y} a))) (${G} (${vc} s t) (${Y} a))) :pattern ((${G} s (${Y} a)) (${vc} s t)) :pattern ((${G} t (${Y} a)) (${vc} s t))))`),$(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${G} (${X} s) ${lc}) (${G} (${X} t) ${lc})) (= (${X} (${vc} s t)) (${K} (+ (${q} (${X} s)) (${q} (${X} t)))))) :pattern ((${vc} s t))))`),$(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${G} (${X} s) ${lc}) (${G} (${X} t) ${lc}) (<= 1 i) (<= i (${q} (${X} s)))) (= (${J} (${vc} s t) (${K} i)) (${J} s (${K} i)))) :pattern ((${J} (${vc} s t) (${K} i))) :pattern ((${vc} s t) (${J} s (${K} i)))))`),$(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${G} (${X} s) ${lc}) (${G} (${X} t) ${lc}) (<= i (+ (${q} (${X} s)) (${q} (${X} t)))) (< (${q} (${X} s)) i)) (= (${J} (${vc} s t) (${K} i)) (${J} t (${K} (- i (${q} (${X} s))))))) :pattern ((${J} (${vc} s t) (${K} i)))))`)]);case`Append`:return a(2,Xc,[$(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${G} s (${Y} a)) (${G} x a)) (${G} (${yc} s x) (${Y} a))) :pattern ((${G} s (${Y} a)) (${yc} s x))))`),$(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${G} (${X} s) ${lc}) (= (${X} (${yc} s x)) (${K} (+ (${q} (${X} s)) 1)))) :pattern ((${yc} s x))))`),$(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${G} (${X} s) ${lc}) (<= 1 i) (<= i (${q} (${X} s)))) (= (${J} (${yc} s x) (${K} i)) (${J} s (${K} i)))) :pattern ((${J} (${yc} s x) (${K} i))) :pattern ((${yc} s x) (${J} s (${K} i)))))`),$(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${G} (${X} s) ${lc}) (= (${J} (${yc} s x) (${K} (+ (${q} (${X} s)) 1))) x)) :pattern ((${yc} s x))))`)]);case`Head`:return a(1,[`FunApp`,`Cast_Int`],[$(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${bc} s) (${J} s (${K} 1))) :pattern ((${bc} s))))`)]);case`Tail`:return a(1,Xc,[$(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${G} s (${Y} a)) (distinct (${q} (${X} s)) 0)) (${G} (${xc} s) (${Y} a))) :pattern ((${G} s (${Y} a)) (${xc} s))))`),$(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${G} (${X} s) ${lc}) (distinct (${q} (${X} s)) 0)) (= (${X} (${xc} s)) (${K} (- (${q} (${X} s)) 1)))) :pattern ((${xc} s))))`),$(`SeqTailApp`,[],`(forall ((s Idv) (i Int)) (! (=> (and (${G} (${X} s) ${lc}) (distinct (${q} (${X} s)) 0) (<= 1 i) (<= i (- (${q} (${X} s)) 1))) (= (${J} (${xc} s) (${K} i)) (${J} s (${K} (+ i 1))))) :pattern ((${J} (${xc} s) (${K} i)))))`)]);case`SubSeq`:{let e=`(${Sc} s (${K} x) (${K} y))`;return a(3,[`Mem`,`Seq`,`Len`,`FunApp`,`IntSet`,`Cast_Int`,`Proj_Int`],[$(`SeqSubseqTyping`,[],`(forall ((a Idv) (s Idv) (x Int) (y Int)) (! (=> (or (< y x) (and (${G} s (${Y} a)) (<= 1 x) (<= y (${q} (${X} s))))) (${G} ${e} (${Y} a))) :pattern ((${G} s (${Y} a)) ${e})))`),$(`SeqSubseqLen`,[],`(forall ((s Idv) (x Int) (y Int)) (! (and (=> (<= x (+ y 1)) (= (${X} ${e}) (${K} (- (+ y 1) x)))) (=> (> x (+ y 1)) (= (${X} ${e}) (${K} 0)))) :pattern (${e})))`),$(`SeqSubseqApp`,[],`(forall ((s Idv) (x Int) (y Int) (z Int)) (! (=> (and (<= 1 x) (<= 1 z) (<= z (- (+ y 1) x))) (= (${J} ${e} (${K} z)) (${J} s (${K} (- (+ z x) 1))))) :pattern ((${J} ${e} (${K} z)))))`)])}case`Cast_Int`:return n(kc(r,1,`Idv`,`Int`),[`Mem`,`IntSet`,`Proj_Int`],[$(`CastInjAlt`,[`Int`],`(forall ((x Int)) (! (= x (${q} (${K} x))) :pattern ((${K} x))))`),$(`TypeGuardIntro`,[`Int`],`(forall ((z Int)) (! (${G} (${K} z) ${cc}) :pattern ((${K} z))))`),$(`TypeGuardElim`,[`Int`],`(forall ((x Idv)) (! (=> (${G} x ${cc}) (= x (${K} (${q} x)))) :pattern ((${G} x ${cc}))))`)]);case`Cast_Bool`:return n(kc(r,1,`Idv`,`Bool`),[`Mem`,`BoolSet`,`Tt_Idv`],[$(`CastInjAlt`,[`Bool`],`(and (= (${ac} true) ${ic}) (distinct (${ac} false) ${ic}))`),$(`TypeGuardIntro`,[`Bool`],`(forall ((z Bool)) (! (${G} (${ac} z) ${oc}) :pattern ((${ac} z))))`),$(`TypeGuardElim`,[`Bool`],`(forall ((x Idv)) (! (=> (${G} x ${oc}) (or (= x (${ac} true)) (= x (${ac} false)))) :pattern ((${G} x ${oc}))))`)]);case`Proj_Int`:return n(kc(r,1,`Int`),[],[]);case`TrigEq_Set$Idv$`:return a(2,[`SetExtTrigger`],[$(`ExtTrigEqDef`,[`Set$Idv$`],`(forall ((x Idv) (y Idv)) (! (= (${gc} x y) (= x y)) :pattern ((${gc} x y))))`),$(`ExtTrigEqTrigger`,[`Idv`],`(forall ((x Idv) (y Idv)) (! (${Zs} x y) :pattern ((${gc} 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`],[zc(`IntLteq`)]);default:if(e.startsWith(`TIntLit_`))return n(void 0,[],[]);throw new i(`the symbol ${e}`)}},Qc=(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(Us)[0];if(t.delete(e),a.has(e))continue;let n=Zc(e,i);a.set(e,n),n.deps.forEach(e=>t.add(e)),n.axioms.forEach(e=>o.set(Fc(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=Xs(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}},$c=(e,t)=>t===0?e:`${e}_${t}`,el=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Set;return{names:t,adjoin:n=>{let r=Ks(n),i=(e.get(r)??-1)+1,a=Array.from({length:t.size+1},(e,t)=>i+t).find(e=>!t.has($c(r,e)))??i;return{base:r,salt:a,name:$c(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)}}}},tl=e=>{let t=el();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(``)}}},nl=(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)),rl=e=>e.length===1?e[0]:O(`Conj`,[e[0],rl(e.slice(1))],e[0]),il=(e,t,n)=>e.kind!==`Record`||t.kind!==`Record`||!nl(e,t)?O(`Eq`,[e,t],n):rl(e.fields.map(e=>il(e.value,t.fields.find(t=>t.name===e.name)?.value??e.value,n))),al=e=>{let t=Ye(e,al);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:E(il(t.args[0],t.args[1],t),t)},ol=e=>e.kind===`Record`||e.kind===`Rect`?{...e,fields:e.fields.toSorted((e,t)=>Us(e.name,t.name))}:Ye(e,ol),sl=(e,t)=>`${e}#${t}`,cl=e=>Number(e.slice(e.lastIndexOf(`#`)+1)),ll=`?unprimable`,ul=e=>{let t=e.indexOf(`(${ll} `);if(t===-1)return e;let n=Ac(e,t);return e.slice(0,t)+ul(e.slice(t+11+2,n))+ul(e.slice(n+1))},dl=(e,t)=>/\((forall|exists|ite) /.test(e)?void 0:e.replace(/[^\s()]+#(\d+)/g,(e,n)=>Number(n)<t?`#`:`#${Number(n)-t}`),fl=()=>{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=Ks(`${l}_omitted_${e.size}`);return e.set(t,{symbol:t,kind:i,visit:ul(a),getLines:()=>[]}),t}let u=dl(`${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=Ks(f),m={symbol:p,kind:i,visit:ul(a),getLines:e=>[kc(p,c),...s(p,e).map(e=>`(assert (! ${ul(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)}},pl=`?trigger`,ml=/* @__PURE__ */ new Set([rc,nc,$s,ec,tc,dc,mc,Y]),hl=e=>{let t=/^\(?([^\s()]+)/.exec(e)?.[1]??``;return ml.has(t)||/^smt__TLA____(SetEnum__\d+|SetSt__flatnd__\d+|SetOf__\d+__flatnd__\d+|Product__\d+|RecordSet__)/.test(t)},gl=(e,t)=>{let n=e.indexOf(`(${pl} `);if(n===-1)return e;let r=n+8+2,i=Ac(e,r)+1,a=Ac(e,i+1)+1,o=t?e.slice(r,i):e.slice(i+1,a);return e.slice(0,n)+o+gl(e.slice(a+1),t)},_l=(e,t,n,r)=>{let i=`(${gc} ${e} ${t})`,a=r?`(distinct ${e} ${t})`:`(= ${e} ${t})`;if(!hl(e)&&!hl(t))return a;let o=r?`(not ${i})`:i;return n===(r?`Positive`:`Negative`)?`(${pl} ${o} ${a})`:o},vl=(e,t,n,r)=>{let i=Q(e,[`a`,...t]);return[$(`SetStDef`,[],Z([...t,`a`,`x`],`(= (${G} x ${i}) (and (${G} x a) ${jc(n,r,`x`)}))`,[[`(${G} x ${i})`],[`(${G} x a)`,i]]))]},yl=(e,t,n,r)=>{let i=r.length,a=Tc(`a`,i),o=Tc(`y`,i),s=r.reduce((e,t,n)=>jc(e,t,o[n]),n),c=Q(e,[...a,...t]),l=o.map((e,t)=>`(${G} ${e} ${a[t]})`),u=i===1?[`a`]:a,d=Q(e,[...u,...t]);return[$(`SetOfIntro`,[i],Z([...t,...a,...o],`(=> ${Dc(l)} (${G} ${s} ${c}))`,[[s,c],[c,...l]])),$(`SetOfElim`,[i],Z([...t,...a,`x`],`(=> (${G} x ${c}) (exists (${Ec(o)}) ${Dc([...l,`(= x ${s})`])}))`,[[`(${G} x ${c})`]])),$(`AssertIsSetOf`,[i],Z([...t,...u],`(${_c} ${d})`,[[d]]))]},bl=(e,t,n,r,i)=>{let a=Q(e,[`a`,...t]),o=jc(n,r,`x`),s=i.has(Fc($(`FunTyping`,[],void 0)))?[$(`FunTyping`,[],Z([...t,`a`,`b`],`(=> (forall ((x Idv)) (=> (${G} x a) (${G} ${o} b))) (${G} ${a} (${mc} a b)))`,[[a,`(${mc} a b)`]]))]:[];return[$(`FunConstrIsafcn`,[],Z([...t,`a`],`(${pc} ${a})`,[[a]])),$(`FunDomDef`,[],Z([...t,`a`],`(= (${fc} ${a}) a)`,[[a]])),$(`FunAppDef`,[],Z([...t,`a`,`x`],`(=> (${G} x a) (= (${J} ${a} x) ${o}))`,[[`(${J} ${a} x)`],[`(${G} x a)`,a]])),...s]},xl=(e,t,n,r)=>[$(`ChooseDef`,[],Z([...t,`x`],`(=> ${jc(n,r,`x`)} ${jc(n,r,Q(e,t))})`))],Sl=(e,t,n,r)=>{let i=n=>Q(e,[n,...t]),a=e=>jc(n,r,e),o=i(`(${yc} s x)`);return[$(`SeqSelectseqTyping`,[],Z([...t,`a`,`s`],`(=> (${G} s (${Y} a)) (${G} ${i(`s`)} (${Y} a)))`,[[`(${G} s (${Y} a))`,i(`s`)]])),$(`SeqSelectseqLen`,[],Z([...t,`s`],`(=> (${G} (${X} s) ${lc}) (<= (${q} (${X} ${i(`s`)})) (${q} (${X} s))))`,[[i(`s`)]])),$(`SeqSelectseqNil`,[],Z(t,`(= ${i(Cc)} ${Cc})`)),$(`SeqSelectseqApp`,[],Z([...t,`s`,`x`],`(=> (${G} x (${fc} ${i(`s`)})) ${a(`(${J} ${i(`s`)} x)`)})`,[[`(${J} ${i(`s`)} x)`]])),$(`SeqSelectseqAppend`,[],Z([...t,`s`,`x`],`(and (=> ${a(`x`)} (= ${o} (${yc} ${i(`s`)} x))) (=> (not ${a(`x`)}) (= ${o} ${i(`s`)})))`,[[o]]))]},Cl=e=>{let t=fl(),n=t.flatten,r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=el(),s=/* @__PURE__ */ new Map,c=e=>e.isBool?e.text:`(= ${gl(e.text,!0)} ${ic})`,l=e=>e.isBool?`(${ac} ${gl(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=>cl(e)<t).toSorted((e,t)=>cl(e)-cl(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(C(e,t,g(n))),y=(e,t,n)=>c(C(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)=>sl(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?[]:[`(${G} ${e} ${r[t]})`]);return e.quantifier===`Forall`?`(forall (${Ec(i.variables)}) ${o.length===0?a:`(=> ${Dc(o)} ${a})`})`:`(exists (${Ec(i.variables)}) ${Dc([...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=>vl(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=>yl(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(W(`Product_${i.length}`),i),o=sl(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}):Vc(i.length).reduce((e,t)=>p(e,{kind:`constant`,symbol:`(${J} ${o} ${t})`}),t),l=v(e.body,c,s),u=m(l,r.depth),f=n(`FunFcn`,l,r,(e,t)=>bl(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&&`(${G} ${a} ${v(e.domain,t,r)})`,s=y(e.body,i.env,i.mode),c=o===void 0?s:Dc([o,s]),l=m(c,r.depth),u=n(`Choose`,c,r,e=>xl(e,l,c,a),l.length);return d(Q(u,l))},ae=(e,t,n,r)=>_l(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:P(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(Dc(t.map(e=>y(e,r,a))));case`Disj`:return u(Oc(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(G,o()));case`Notmem`:return u(`(not ${Q(G,o())})`);case`Subseteq`:return u(Q(Qs,o()));case`Lteq`:return u(Q(uc,o()));case`Gteq`:return u(Q(uc,o().toReversed()));case`Lt`:case`Gt`:{let t=()=>e===`Lt`?o():o().toReversed();return u(`(and ${Q(uc,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=>Sl(t,i,e.body,e.variable),i.length+1);return d(Q(o,[v(t[0],r,a),...i]))}case`Unprimable`:{let e=C(t[0],r,g(a));return{...e,text:`(${ll} ${e.text})`}}default:{let t=wc[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(W(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`?W(`StrLit_${o.field}`):v(o.expression,t,n),c=s(),l=i(`(${J} ${e} ${a.length>1?s():c})`,a.slice(1));return`(${hc} ${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),W(t)},pe=(e,t,n)=>{let r=e.arms.map(e=>C(e.body,t,n)),i=e.other?C(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:`(${K} ${a})`,integer:a}}let o=e=>a?e.text:l(e);return{isBool:a,text:e.arms.reduceRight((e,i,a)=>`(ite ${y(i.condition,t,n)} ${o(r[a])} ${e})`,o(i))}},me=(e,t,n)=>{let r=e.context.reduce((e,t)=>{switch(t.kind){case`Fresh`:{if(t.shape>0){if(!e.mode.isOmitted)throw new i(`a second-order ASSUME`);let n=sl(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&&`(${G} ${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))},C=(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(oc);case`STRING`:return d(sc);case`Nat`:return d(lc);case`Int`:return d(cc);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 C(je(r,e.args),t,n);throw new i(`an application of ${r.kind}`)}case`Sequent`:return u(me(e.sequent,t,n));case`With`:case`Parens`:return C(e.expression,t,n);case`If`:{let r=y(e.condition,t,n),i=C(e.consequent,t,n),a=C(e.alternative,t,n);if(i.integer!==void 0&&a.integer!==void 0){let e=`(ite ${gl(r,!0)} ${i.integer} ${a.integer})`;return{isBool:!1,text:`(${K} ${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`?Oc(r):Dc(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(W(`SetEnum_${e.elements.length}`),e.elements.map(e=>v(e,t,n))));case`Product`:return d(Q(W(`Product_${e.factors.length}`),e.factors.map(e=>v(e,t,n))));case`Tuple`:return d(Q(W(`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(W(`Tuple_${i.length}`),i);return d(`(${J} ${r} ${a})`)}case`Arrow`:return d(Q(mc,[v(e.domain,t,n),v(e.range,t,n)]));case`Record`:case`Rect`:{let r=e.fields.map(e=>e.name),i=r.join(`_`);return a.set(`Record_${i}`,r),a.set(`RecordSet_${i}`,r),d(Q(W(`${e.kind===`Record`?`Record`:`RecordSet`}_${i}`),e.fields.map(e=>v(e.value,t,n))))}case`Except`:return d(de(e,t,n));case`Dot`:return d(`(${J} ${v(e.expression,t,n)} ${W(`StrLit_${e.field}`)})`);case`Case`:return pe(e,t,n);case`String`:return d(W(`StrLit_${e.value}`));case`Num`:if(e.fraction!==``)throw new i(`a real number`);return{isBool:!1,text:`(${K} ${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(),ul(gl(e,!1))],getUniqueName:h,flattened:t.flattened,anonymous:r,recordFields:a,declared:s}},wl={isOmitted:!1,polarity:`Negative`,at:void 0,depth:0},Tl=e=>e.definition.kind===`Bpragma`||e.definition.kind===`Operator`&&e.visibility===`Visible`,El=e=>e.kind===`Sequent`&&e.sequent.context.some(e=>e.kind===`Fresh`&&e.shape>0),Dl=(e,t)=>e.reduce((e,n)=>{let r=(n,r=[])=>({env:t.push(e.env,n),entries:[...e.entries,...r]});switch(n.kind){case`Fresh`:{let i=t.getUniqueName(n.name),a=n.shape===0?{kind:`constant`,symbol:i}:{kind:`operator`,symbol:i,arity:n.shape},o=kc(i,n.shape);if(!n.domain||n.domainVisibility===`Hidden`)return r(a,[o]);let s=`(assert (${G} ${i} ${t.encodeIdv(n.domain,e.env,wl)}))`;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},[kc(e,0),kc(i,0)])}case`Defn`:{let e=n.definition;if(Tl(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},[kc(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},[kc(o,a.length)])}case`Fact`:{let i={kind:`unsupported`,reason:`a reference to a fact`};if(n.visibility===`Hidden`)return r(i);let a=El(n.expression),o=t.getEntries(`(assert ${t.encodeBool(n.expression,e.env,{...wl,isOmitted:a})})`);return r(i,a?o.map(e=>typeof e==`string`?{omitted:e}:e):o)}}},{env:void 0,entries:[]}),Ol=(e,t)=>{let n=ol(al({kind:`Sequent`,sequent:e})),r=n.kind===`Sequent`?n.sequent:e,i=Cl(t),a=Dl(r.context,i),o=El(r.active)?[]:i.getEntries(`(assert (! (not ${i.encodeBool(r.active,a.env,{...wl,polarity:`Positive`})}) :named |Goal|))`),s=[...a.entries,...o],c=tl(i.declared),l=Qc(s,i.flattened,i.anonymous,i.recordFields),u=[...l.symbols].toSorted((e,t)=>Us(e[0],t[0])).flatMap(e=>e[1].declaration===void 0?[]:[e[1].declaration]),d=[...l.axioms.values()].toSorted(Lc).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`)&&!Tl(e))?[`(declare-sort Idv 0)`]:[],...p].map(c.resolve).concat(`(check-sat)`,`(exit)`).join(`
33
+ `)},kl=z(`@ `),Al={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`},jl={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]},Ml=e=>{let t=Number.parseInt(e,10);return`${`(TLA.fapply TLA.Succ `.repeat(t)}0${`)`.repeat(t)}`},Nl=(e,t)=>{let n=mn(),a=e=>gn(n,Da(e)),o=()=>gn(n,``),c=e=>B(e,g,kl),l=(e,t)=>z(`(%s %a)`,e,c(t)),u=(e,t,r)=>{let i=a(e),o=z(`%a((%s) %a))`,t,i,g(r));return _n(n,1),o},d=(e,t)=>{let n=Al[e];if(n!==void 0&&t.length===0)return R(n);let r=jl[e];if(r&&r[1]===t.length)return l(r[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]);throw ka(e,t.length,`Backend.Zenon.fmt_apply`)},f=(e,t)=>{switch(e.kind){case`Ix`:{let i=hn(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 _n(n,e.params.length),r}default:throw new r}},p=(e,t,n)=>{if(t.length===0)return g(n);let i=Aa(e,t,n),a=e===`Forall`;if(i.first.domain.kind===`NoDomain`)return u(i.first.name,R(a?`(A. `:`(E. `),i.inner);if(i.first.domain.kind!==`Domain`)throw new r;let o=g(i.first.domain.expression);return u(i.first.name,z(`(%s %a `,a?`TLA.bAll`:`TLA.bEx`,o),i.inner)},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 _n(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 _n(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)),kl);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(Ml(e.integer));case`Bang`:case`Let`:case`At`:throw new r}},_=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`?ja(n,()=>g(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):[]}}},v=(()=>{try{return[t.context.map(_),z(`$goal %a`,g(t.active))]}catch(e){throw e instanceof i?new s(`Zenon: unsupported operator ${e.message}`):e}})();return fn([z(`;; obligation #%s@
36
+ `,String(e)),v])},Pl=`------------------------------- 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
+ `,Fl=e=>Ss(Oo(e)),Il={encode:(e,t,n,r)=>(n.rlimit===void 0?``:`(set-option :rlimit ${n.rlimit})\n`)+Ol(Fl(t),r)},Ll={smt:Il,z3:Il,zenon:{encode:(e,t)=>Nl(e,Fl(t))},isabelle:{encode:(e,t,n)=>Va(e,Fl(t),n.tactic??`auto`)},ls4:{encode:(e,t)=>Hs(t)}},Rl=e=>e.kind===`Case`&&e.other===void 0||Xe(e).some(Rl),zl=/* @__PURE__ */ new WeakMap,Bl=e=>{let t=zl.get(e);if(t!==void 0)return t;let n=[];Je(e,e=>(n.push(e),e),`all`);let r=n.some(Rl);return zl.set(e,r),r},Vl=e=>/-{4,}\s*MODULE\s+(\w+)/.exec(e)?.[1]??`Main`,Hl=e=>({id:e.id,location:e.location,text:e.text}),Ul=(e,t,n,r=[])=>({obligation:{...Hl(e),status:t,reason:n},attempts:r}),Wl=(e,t=js(e))=>cs(Uo(Mo(e.sequent)),t.frontends),Gl=(e,t)=>`${Rn(t?Uo(Mo(e.sequent,!1)):Wl(e))}\n`,Kl=(e,t,n)=>Ha(e,t.flatMap((e,t)=>e.attempts.filter(e=>e.method.prover===`isabelle`&&e.isProved&&!e.isReused).map(r=>({id:e.obligation.id,sequent:Fl(Wl(n[t])),tactic:r.method.tactic??`auto`})))),ql=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},Jl=async(e,t,n,r)=>{if(e.kind.kind===`Error`)return Ul(e,`failed`,e.kind.message);let a=js(e),o=ys(e.sequent),c=n.lastByFingerprint.get(o);n.lastByFingerprint.set(o,n.tasks[t].done),await c;let l=[],u=[],d=t=>({obligation:{...Hl(e),status:`proved`,prover:t},attempts:l}),f=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},p=e=>e.rlimit??e.timeLimitMs/1e3,m=e=>l.push({...e,isReused:!0,timeUsedMs:void 0}),h=e=>{l.push(e),n.results.set(o,(n.results.get(o)??/* @__PURE__ */ new Map).set(e.method.prover,e))},g=(e,t)=>{l.push({method:e,isProved:!1,isReused:!1,reason:t}),u.push({reason:t,isDecided:!1})},_=f(a.provers[0]);if(_?.isProved)return m(_),d(_.method.prover);let v=Wl(e,a);if(e.kind.kind===`Support`&&Ms(v))return n.results.set(o,n.results.get(o)??/* @__PURE__ */ new Map),{obligation:{...Hl(e),status:`trivial`},attempts:l};for(let o of a.provers){let a=f(o);if(a?.isProved)return m(a),d(o.prover);if(a&&p(a.method)>=p(o)){m(a),u.push({reason:`${o.prover} failed on an obligation with the same fingerprint`,isDecided:!0});continue}if(!n.isProving)continue;if(o.prover===`trivial`)return d(o.prover);let c=Ll[o.prover];if(!c)g(o,`tla-ts has no ${o.prover} backend`);else try{let i=c===Il&&(v.context.some(Bl)||Rl(v.active))?await ql(n,t):{caseErrors:0},a=c.encode(e.id,v,o,i),s=await n.decide(o.prover,a,{timeLimitMs:o.timeLimitMs,signal:r},t),l=s.verdict===`unsat`;if(h({method:o,isProved:l,isReused:!1,...!l&&{reason:s.timeUsedMs>=o.timeLimitMs?`timeout`:`false`},verdict:s.verdict,timeUsedMs:s.timeUsedMs}),l)return d(o.prover);u.push({reason:`${o.prover} answered ${s.verdict}`,isDecided:!0})}catch(e){if(e instanceof s){h({method:o,isProved:!1,isReused:!1,reason:`false`}),u.push({reason:`${o.prover} failed: ${e.message}`,isDecided:!0});continue}if(!(e instanceof i))throw e;g(o,`${o.prover} can't encode ${e.message}`)}}return Ul(e,u.some(e=>e.isDecided)?`failed`:`unsupported`,u.map(e=>e.reason).join(`, `),l)},Yl=(e,t)=>{if(t instanceof i)return Ul(e,`unsupported`,t.message);if(t instanceof s)return Ul(e,`failed`,t.message);throw t},Xl=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,n,o,t.signal).catch(e=>Yl(r,e));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},Zl=(e,t)=>t?{...Hl(e),...t}:{...Hl(e),status:`unsupported`,reason:`tlapm reported no result`},Ql=async e=>{let t=Vl(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?.(Zl(r,n))}});return{obligations:a.map(e=>Zl(e,c.get(e.id))),...o}}return{obligations:(await Xl(a,{workers:e.workers,signal:e.signal,onReport:t=>e.onObligation?.(t.obligation)})).map(e=>e.obligation),...o}};export{Pl as a,xa as c,fn as d,me as f,Xl as i,Ln as l,ue as m,Gl as n,ca as o,fe as p,Ql as r,ba as s,Kl as t,z as u};