tla-ts 0.0.3 → 0.0.4-dev.2a873ee
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.
- package/README.md +46 -115
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +194 -8
- package/dist/index.d.ts +194 -8
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +996 -0
- package/dist/prove.js +996 -0
- package/dist/run-cli.cjs +37 -20
- package/dist/run-cli.js +37 -20
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +1387 -18
- package/dist/transfer.js +1387 -18
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +24 -11
- package/src/ast.ts +149 -8
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1540 -235
- package/src/cli-options.ts +12 -6
- package/src/cli.ts +8 -1
- package/src/codegen.ts +98 -39
- package/src/config.ts +254 -181
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +540 -140
- package/src/errors.ts +284 -4
- package/src/evaluate.ts +1043 -293
- package/src/exit-codes.ts +22 -43
- package/src/fingerprints.ts +46 -11
- package/src/index.ts +11 -0
- package/src/instances.ts +19 -16
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +191 -45
- package/src/lexer.ts +127 -30
- package/src/live-check.ts +867 -0
- package/src/liveness.ts +218 -572
- package/src/{obligation-action.ts → obligations/action.ts} +247 -69
- package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
- package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
- package/src/{obligations.ts → obligations/index.ts} +32 -16
- package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
- package/src/{obligation-module.ts → obligations/module.ts} +113 -121
- package/src/obligations/pickle.ts +98 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/{obligation-source.ts → obligations/source.ts} +156 -99
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/ocaml-marshal.ts +166 -0
- package/src/parallel-worker.ts +169 -224
- package/src/parallel.ts +140 -81
- package/src/parser.ts +456 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/prove/decide-pool.ts +95 -0
- package/src/prove/deciders.ts +33 -0
- package/src/prove/first-order.ts +78 -0
- package/src/prove/isabelle/LICENSE +36 -0
- package/src/prove/isabelle/LICENSE-tlapm +26 -0
- package/src/prove/isabelle/decide.ts +47 -0
- package/src/prove/isabelle/encode.ts +446 -0
- package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prove/isabelle/isar/method.ts +367 -0
- package/src/prove/isabelle/isar/proof.ts +28 -0
- package/src/prove/isabelle/isar/statement.ts +57 -0
- package/src/prove/isabelle/isar/theory.ts +192 -0
- package/src/prove/isabelle/isar/type-check.ts +278 -0
- package/src/prove/isabelle/provers/blast/blast.ts +258 -0
- package/src/prove/isabelle/provers/blast/branch.ts +322 -0
- package/src/prove/isabelle/provers/blast/prove.ts +347 -0
- package/src/prove/isabelle/provers/blast/rules.ts +330 -0
- package/src/prove/isabelle/provers/blast/state.ts +180 -0
- package/src/prove/isabelle/provers/blast/term.ts +546 -0
- package/src/prove/isabelle/provers/clasimp.ts +150 -0
- package/src/prove/isabelle/provers/classical.ts +389 -0
- package/src/prove/isabelle/provers/hypsubst.ts +433 -0
- package/src/prove/isabelle/pure/bicompose.ts +174 -0
- package/src/prove/isabelle/pure/consts.ts +32 -0
- package/src/prove/isabelle/pure/conv.ts +79 -0
- package/src/prove/isabelle/pure/drule.ts +264 -0
- package/src/prove/isabelle/pure/envir.ts +331 -0
- package/src/prove/isabelle/pure/goal.ts +53 -0
- package/src/prove/isabelle/pure/interrupt.ts +16 -0
- package/src/prove/isabelle/pure/list.ts +12 -0
- package/src/prove/isabelle/pure/logic.ts +330 -0
- package/src/prove/isabelle/pure/name.ts +98 -0
- package/src/prove/isabelle/pure/net.ts +215 -0
- package/src/prove/isabelle/pure/object-logic.ts +41 -0
- package/src/prove/isabelle/pure/pattern.ts +631 -0
- package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prove/isabelle/pure/rewriter.ts +602 -0
- package/src/prove/isabelle/pure/search.ts +68 -0
- package/src/prove/isabelle/pure/seq.ts +133 -0
- package/src/prove/isabelle/pure/simplifier.ts +106 -0
- package/src/prove/isabelle/pure/table.ts +201 -0
- package/src/prove/isabelle/pure/tactic.ts +168 -0
- package/src/prove/isabelle/pure/tactical.ts +264 -0
- package/src/prove/isabelle/pure/term-ord.ts +105 -0
- package/src/prove/isabelle/pure/term.ts +688 -0
- package/src/prove/isabelle/pure/thm.ts +783 -0
- package/src/prove/isabelle/pure/type.ts +121 -0
- package/src/prove/isabelle/pure/unify.ts +753 -0
- package/src/prove/isabelle/pure/variable.ts +25 -0
- package/src/prove/isabelle/tla/classical-setup.ts +101 -0
- package/src/prove/isabelle/tla/context.ts +74 -0
- package/src/prove/isabelle/tla/logic-data.ts +5 -0
- package/src/prove/isabelle/tla/logic.ts +215 -0
- package/src/prove/isabelle/tla/simpdata.ts +241 -0
- package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prove/ocaml.ts +22 -0
- package/src/prove/prep/action.ts +508 -0
- package/src/prove/prep/defs.ts +33 -0
- package/src/prove/prep/elab.ts +156 -0
- package/src/prove/prep/enabled-axioms.ts +189 -0
- package/src/prove/prep/enabled.ts +43 -0
- package/src/prove/prep/fingerprint.ts +388 -0
- package/src/prove/prep/flatten.ts +70 -0
- package/src/prove/prep/level-comparison.ts +529 -0
- package/src/prove/prep/md5.ts +67 -0
- package/src/prove/prep/pragma.ts +221 -0
- package/src/prove/prep/trivial.ts +22 -0
- package/src/prove/prove-worker.ts +22 -0
- package/src/prove/prove.ts +498 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +255 -0
- package/src/prove/ptl/sat.ts +151 -0
- package/src/prove/ptl/tableau.ts +276 -0
- package/src/prove/smt/axiomatize.ts +69 -0
- package/src/prove/smt/axioms.ts +209 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +636 -0
- package/src/prove/smt/encode.ts +164 -0
- package/src/prove/smt/extensionality.ts +65 -0
- package/src/prove/smt/flatten.ts +112 -0
- package/src/prove/smt/format.ts +154 -0
- package/src/prove/smt/instances.ts +181 -0
- package/src/prove/smt/rewrite.ts +772 -0
- package/src/prove/smt/simplify.ts +57 -0
- package/src/prove/smt/solver/act-cache.ts +265 -0
- package/src/prove/smt/solver/arith-rewriter.ts +962 -0
- package/src/prove/smt/solver/array.ts +22 -0
- package/src/prove/smt/solver/asserted-formulas.ts +469 -0
- package/src/prove/smt/solver/ast-lt.ts +157 -0
- package/src/prove/smt/solver/ast-util.ts +91 -0
- package/src/prove/smt/solver/ast.ts +1315 -0
- package/src/prove/smt/solver/auf-solver.ts +572 -0
- package/src/prove/smt/solver/case-split-queue.ts +178 -0
- package/src/prove/smt/solver/cg-table.ts +175 -0
- package/src/prove/smt/solver/clause.ts +276 -0
- package/src/prove/smt/solver/conflict-resolution.ts +343 -0
- package/src/prove/smt/solver/context.ts +1292 -0
- package/src/prove/smt/solver/ctx-simplify.ts +334 -0
- package/src/prove/smt/solver/der.ts +224 -0
- package/src/prove/smt/solver/dyn-ack.ts +141 -0
- package/src/prove/smt/solver/e-matching.ts +659 -0
- package/src/prove/smt/solver/enode.ts +259 -0
- package/src/prove/smt/solver/expr-ref.ts +21 -0
- package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prove/smt/solver/fingerprints.ts +92 -0
- package/src/prove/smt/solver/flat-literals.ts +51 -0
- package/src/prove/smt/solver/goal.ts +138 -0
- package/src/prove/smt/solver/hash.ts +173 -0
- package/src/prove/smt/solver/hashtable.ts +166 -0
- package/src/prove/smt/solver/internalizer.ts +1381 -0
- package/src/prove/smt/solver/lbool.ts +5 -0
- package/src/prove/smt/solver/literal.ts +24 -0
- package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prove/smt/solver/lp/constraints.ts +78 -0
- package/src/prove/smt/solver/lp/containers.ts +296 -0
- package/src/prove/smt/solver/lp/core-solver.ts +504 -0
- package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prove/smt/solver/lp/dependency.ts +51 -0
- package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prove/smt/solver/lp/explanation.ts +46 -0
- package/src/prove/smt/solver/lp/gomory.ts +255 -0
- package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prove/smt/solver/lp/hnf.ts +281 -0
- package/src/prove/smt/solver/lp/int-cube.ts +295 -0
- package/src/prove/smt/solver/lp/int-solver.ts +514 -0
- package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prove/smt/solver/lp/lar-term.ts +62 -0
- package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prove/smt/solver/lp/nex.ts +120 -0
- package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prove/smt/solver/lp/nla-core.ts +968 -0
- package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prove/smt/solver/lp/nla-order.ts +307 -0
- package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prove/smt/solver/lp/nla-types.ts +124 -0
- package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prove/smt/solver/lp/pdd.ts +971 -0
- package/src/prove/smt/solver/lp/random-updater.ts +138 -0
- package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prove/smt/solver/lp/union-find.ts +96 -0
- package/src/prove/smt/solver/mam-compiler.ts +847 -0
- package/src/prove/smt/solver/mam-interpreter.ts +400 -0
- package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prove/smt/solver/model-checker.ts +347 -0
- package/src/prove/smt/solver/model-evaluator.ts +262 -0
- package/src/prove/smt/solver/model-finder.ts +155 -0
- package/src/prove/smt/solver/model-generator.ts +97 -0
- package/src/prove/smt/solver/model-macro-solver.ts +728 -0
- package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prove/smt/solver/nlsat/explain.ts +607 -0
- package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prove/smt/solver/nlsat/solver.ts +911 -0
- package/src/prove/smt/solver/nlsat/types.ts +43 -0
- package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prove/smt/solver/nnf.ts +469 -0
- package/src/prove/smt/solver/pattern-inference.ts +351 -0
- package/src/prove/smt/solver/poly-rewriter.ts +477 -0
- package/src/prove/smt/solver/propagate-values.ts +83 -0
- package/src/prove/smt/solver/proto-model.ts +551 -0
- package/src/prove/smt/solver/pull-quant.ts +139 -0
- package/src/prove/smt/solver/qe-lite-der.ts +526 -0
- package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prove/smt/solver/qe-lite.ts +381 -0
- package/src/prove/smt/solver/qi-queue.ts +362 -0
- package/src/prove/smt/solver/quant-tactics.ts +117 -0
- package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prove/smt/solver/quantifier-manager.ts +186 -0
- package/src/prove/smt/solver/random-gen.ts +10 -0
- package/src/prove/smt/solver/rational.ts +165 -0
- package/src/prove/smt/solver/ref-vector.ts +62 -0
- package/src/prove/smt/solver/relevancy.ts +247 -0
- package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prove/smt/solver/rewriter.ts +843 -0
- package/src/prove/smt/solver/rlimit.ts +79 -0
- package/src/prove/smt/solver/smtlib-parser.ts +526 -0
- package/src/prove/smt/solver/solver.ts +71 -0
- package/src/prove/smt/solver/sort.ts +35 -0
- package/src/prove/smt/solver/sticky-generations.ts +69 -0
- package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prove/smt/solver/theory-lra-model.ts +243 -0
- package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prove/smt/solver/theory-lra-state.ts +43 -0
- package/src/prove/smt/solver/theory-lra.ts +56 -0
- package/src/prove/smt/solver/var-subst.ts +258 -0
- package/src/prove/smt/solver/z3-license.txt +10 -0
- package/src/prove/smt/table.ts +170 -0
- package/src/prove/tlapm/tlapm.ts +96 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +18 -0
- package/src/prove/zenon/LICENSE +32 -0
- package/src/prove/zenon/check/check.ts +105 -0
- package/src/prove/zenon/check/definitions.ts +144 -0
- package/src/prove/zenon/check/equality.ts +182 -0
- package/src/prove/zenon/check/functions.ts +62 -0
- package/src/prove/zenon/check/keys.ts +125 -0
- package/src/prove/zenon/check/propositional.ts +104 -0
- package/src/prove/zenon/check/records.ts +188 -0
- package/src/prove/zenon/check/relations.ts +121 -0
- package/src/prove/zenon/check/rewrites.ts +224 -0
- package/src/prove/zenon/check/sets.ts +302 -0
- package/src/prove/zenon/check/terms.ts +127 -0
- package/src/prove/zenon/check/tla.ts +126 -0
- package/src/prove/zenon/decide.ts +113 -0
- package/src/prove/zenon/encode.ts +379 -0
- package/src/prove/zenon/eqrel.ts +300 -0
- package/src/prove/zenon/equality-rules.ts +435 -0
- package/src/prove/zenon/expr.ts +551 -0
- package/src/prove/zenon/index-table.ts +350 -0
- package/src/prove/zenon/isar-case.ts +513 -0
- package/src/prove/zenon/isar.ts +1249 -0
- package/src/prove/zenon/limits.ts +15 -0
- package/src/prove/zenon/llproof.ts +173 -0
- package/src/prove/zenon/mltoll.ts +1566 -0
- package/src/prove/zenon/node.ts +297 -0
- package/src/prove/zenon/ocaml.ts +169 -0
- package/src/prove/zenon/parse.ts +247 -0
- package/src/prove/zenon/phrase.ts +191 -0
- package/src/prove/zenon/proof.ts +198 -0
- package/src/prove/zenon/propositional-rules.ts +387 -0
- package/src/prove/zenon/rules.ts +94 -0
- package/src/prove/zenon/search.ts +288 -0
- package/src/prove/zenon/tla/functions.ts +151 -0
- package/src/prove/zenon/tla/llproof.ts +480 -0
- package/src/prove/zenon/tla/records.ts +225 -0
- package/src/prove/zenon/tla/rewrites.ts +447 -0
- package/src/prove/zenon/tla/sets.ts +304 -0
- package/src/prove/zenon/tla/terms.ts +162 -0
- package/src/prove/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1481 -426
- package/src/run-cli.ts +1483 -212
- package/src/runtime.ts +19 -1
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +356 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +42 -11
- package/src/standard-modules.ts +203 -148
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +180 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +241 -110
- package/src/symmetry.ts +194 -54
- package/src/tableau.ts +54 -25
- package/src/tlapm-cache.ts +236 -0
- package/src/tlc-ext.ts +42 -29
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +52 -43
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +78 -10
- package/src/tlc-random.ts +84 -33
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +19 -0
- package/src/transfer.ts +15 -3
- package/src/values.ts +787 -190
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
package/dist/prove.cjs
ADDED
|
@@ -0,0 +1,996 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license tla-ts
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Aiden Bai
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
const e=require("./worker.cjs"),t=require("./transfer.cjs"),n=require("./deciders.cjs"),r=async n=>{let r=typeof n.config==`string`?t.Q(n.config,n.version):n.config,i=n.onPrint??console.log,a={count:0},o=e=>[e.kind,`name`in e?e.name:``,`count`in e?e.count:``,`text`in e?e.text:``].join(` `),s=/* @__PURE__ */ new Set,c=e=>{s.add(o(e)),n.onProgress?.(e)},l=()=>{let e={count:a.count};return t.l({...n,config:r,onPrint:t=>e.count-->0?void 0:i(t),onProgress:e=>{s.has(o(e))||n.onProgress?.(e)}})},u=n.workers??1;if(u<2||typeof SharedArrayBuffer!=`function`||n.dump!==void 0||r.view!==void 0||r.postconditions.length>0||r.possible.length>0)return l();let d=/* @__PURE__ */ new Map,f=e=>{let t=n.loadModule?.(e);return d.set(e,t),t},p=/* @__PURE__ */ new Map,m=e=>{let t=n.loadClass?.(e);return p.set(e,t),t};t.X(t.x(n.source,r,f)),t.Z(n.version);let h=t.Y(),g=t.y(r,{source:n.source,loadModule:f,loadClass:m,print:e=>{a.count++,i(e)},files:{readFile:n.readFile,writeFile:n.writeFile},isTool:n.isTool,isTraceRecorded:n.isTraceRecorded,isSanyReported:n.isSanyReported,isWarningEnabled:n.isWarningEnabled,version:n.version});t.p(g,r,c);let _=g.environment,v=t.u(r,_,()=>t.S(n.source,f),c);if(t.d(g.assumptions,_)||!v||v.spec.init===void 0||v.spec.next===void 0||v.properties.liveness.length>0||t.P(_))return l();let y=t.K(),b={fingerprints:t.i()},ee=/* @__PURE__ */ new Int32Array(2),x=Array.from({length:u},t.n),S={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,initialStates:void 0,outDegrees:Array.from({length:32},()=>0)},C=[],te=()=>({status:`success`,violation:void 0,failure:void 0,...S,fingerprintDistance:t.g(S.distinctStates,S.generatedStates,()=>{let e=new BigInt64Array(S.distinctStates);return C.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),w=e=>{let n=[];for(let r of t.F(e,_,v.spec.scope))if(t.f(S.generatedStates,c),y(r),S.generatedStates++,t.c(v.getFingerprintState(r),ee),t.s(b.fingerprints)&&(b.fingerprints=t.a(b.fingerprints)),t.o(b.fingerprints,ee[0],ee[1])){if(v.findViolatedInvariant(r)||v.findFailedInitialPredicate(r))return!1;if(v.satisfiesConstraints(r)){if(!x[n.length%u].encode(r))return!1;n.push(r),S.distinctStates++}}return C.push(BigInt64Array.from(n,e=>_.runtime.getFingerprint(e))),!0};c({kind:`initial-states-started`});try{if(!w(v.spec.init))return l()}catch(t){if(!(t instanceof e.g))throw t;return l()}if(t.Y()!==h)return l();if(S.depth=S.generatedStates===0?0:1,S.initialStates={generated:S.generatedStates,distinct:S.distinctStates},c({kind:`initial-states-computed`,initialStates:S.initialStates}),S.distinctStates===0)return te();let T=[],E={count:u,resolve:e=>{}},ne=e=>{T.push(e),(e.type===`abort`||T.length===E.count)&&E.resolve(T.splice(0))},re=e=>new Promise(t=>{E.count=e,E.resolve=t}),ie=re(u),ae=new Int32Array(new SharedArrayBuffer(u*4)),oe=new Int32Array(new SharedArrayBuffer(u*4)),se=await Promise.all(Array.from({length:u},()=>e.r(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href),e=>ne(e),()=>ne({type:`abort`})))),ce=()=>se.forEach(e=>e.terminate()),le=/* @__PURE__ */ new Map,ue=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=le.get(n)??new MessageChannel;return le.set(n,r),e<t?r.port1:r.port2};se.forEach((e,t)=>{let i=Array.from({length:u},(e,n)=>n===t?void 0:ue(t,n)),a=x[t].finish(),o={type:`start`,source:n.source,config:r,modules:[...d],classes:[...p],index:t,ports:i,seed:a,isTool:n.isTool,isTraceRecorded:n.isTraceRecorded,isWarningEnabled:n.isWarningEnabled,version:n.version,fingerprints:b.fingerprints,requests:ae,remaining:oe};e.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let de=e=>e.some(e=>e.type===`abort`),D=e=>se.forEach(t=>t.postMessage(e)),O=async e=>{let n=e.filter(e=>e.type===`paused`).length;if(n===0||de(e))return e;b.fingerprints=t.a(b.fingerprints);let r=re(n);return D({type:`resize`,fingerprints:b.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await O(await r)]};if(de(await ie))return ce(),l();for(let e=1;;e++){let t=re(u);ae.forEach((e,t)=>Atomics.store(ae,t,0)),D({type:`level`,level:e});let n=await O(await t);if(de(n))return ce(),l();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(S.generatedStates+=r.reduce((e,t)=>e+t.generated,0),S.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>S.outDegrees[t]+=e),C.push(e.fingerprints)}),i===0)return ce(),te();S.depth++}},i=e=>{let t=e.endColumn-1;return e.startLine===e.endLine?e.startColumn>=t?`line ${e.startLine}, character ${e.startColumn}`:`line ${e.startLine}, characters ${e.startColumn}-${t}`:`line ${e.startLine}, character ${e.startColumn} to line ${e.endLine}, character ${t}`},a=e=>`File ${JSON.stringify(e.file)}, ${i(e)}`,o=e=>e?a(e):`<unknown location>`,s=e=>`${o(e)}:\n`,c=(e,t)=>({text:`${s(e)}Error: ${t}`,channel:`stderr`}),l=e=>e?`${a(e)} :\n`:``,u=e=>({kind:`Shift`,amount:e}),d=(e,t)=>({kind:`Cons`,expression:e,rest:t}),f=(e,t)=>e.reduce((e,t)=>d(t,e),t),p=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},m=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},h=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},g=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t,_=(e,t,n)=>m({kind:`Apply`,operator:m({kind:`Internal`,builtin:e},n),args:t},n),v=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},y=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),b=(e,t)=>t.reduce(y,e),ee=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},x=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(h(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},S=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},C=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},te=(e,t)=>{let n={state:e,hyp:void 0,parent:void 0,next:/* @__PURE__ */ new WeakMap};return(e,r=e)=>{let i=e.reduce((e,n,i)=>{let a=e.next.get(n);if(a)return a;let[o,s]=t(e.state,r[i],n),c={state:o,hyp:s,parent:e,next:/* @__PURE__ */ new WeakMap};return e.next.set(n,c),c},n),a=[];for(let e=i;e;e=e.parent)e.hyp&&a.push(e.hyp);return{state:i.state,context:a.reverse()}}},w=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),T=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),E=(e,t,n,r)=>({kind:`Fact`,expression:e,visibility:t,time:n,location:r}),ne=e=>w(e.name,e.level),re=e=>w(e.name,`Unknown`,e.shape),ie=e=>({kind:`Defn`,definition:e,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),ae=(e,t,n)=>{switch(e.kind){case`Shift`:return m({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?m(ce(e.expression),n):ae(e.rest,t-1,n);case`Compose`:return O(e.outer,ae(e.inner,t,n));case`Bump`:return t<=e.amount?m({kind:`Ix`,index:t},n):O(u(e.amount),ae(e.rest,t-e.amount,n))}},oe=(e,t)=>t.map(t=>O(e,t)),se=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e.C(`Arity mismatch`);return ce(O(f(n,u(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?ce(t):{kind:`Apply`,operator:t,args:n}},ce=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},le=(e,t)=>[p(t.length,e),ve(t,t=>O(e,t))],ue=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return xe(t,t=>O(e,t));case`Instance`:{let n=p(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:O(n,e.expression)}))}}}}},de=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:O(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ue(e,t.definition)};case`Fact`:return{...t,expression:O(e,t.expression)}}},D=(e,t)=>{let[n,r]=C(e,t.context,(e,t)=>[p(1,e),de(e,t)]);return{context:r,active:O(n,t.active)}},O=(e,t)=>{let n=t=>O(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return ae(e,t.index,t);case`Apply`:return m(se(n(t.operator),oe(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>ye(e,n))};case`Lambda`:return{...t,body:O(p(t.params.length,e),t.body)};case`Let`:{let[n,r]=C(e,t.definitions,(e,t)=>[p(1,e),ue(e,t)]);return{...t,definitions:r,body:O(n,t.body)}}case`Sequent`:return{...t,sequent:D(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:oe(e,t.items)};case`Quant`:case`Fcn`:{let[n,r]=le(e,t.bounds);return{...t,bounds:r,body:O(n,t.body)}}case`Tquant`:return{...t,body:O(p(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:O(p(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:O(p(1,e),t.body)};case`SetOf`:{let[n,r]=le(e,t.bounds);return{...t,bounds:r,element:O(n,t.element)}}case`SetEnum`:case`Tuple`:return{...t,elements:oe(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`FcnApp`:return{...t,function:n(t.function),args:oe(e,t.args)};case`Product`:return{...t,factors:oe(e,t.factors)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:be(t.specs,n)};case`Sub`:case`Tsub`:case`Fair`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)}}},k=(e,t)=>e===0?t:O(u(e),t),A=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),j=(e,t)=>e&&t?M(e,t):!e&&!t,fe=(e,t)=>{let n=new Map(e.map(e=>[e.name,e.value])),r=new Map(t.map(e=>[e.name,e.value]));if(n.size!==r.size)return!1;for(let[e,t]of n){let n=r.get(e);if(!n||!M(t,n))return!1}return!0},pe=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&M(e.domain.expression,t.domain.expression)),me=(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`&&A(e.args,t.args,M);case`Label`:return t.kind===`Label`&&e.label===t.label&&A(e.args,t.args,M);default:return!0}},he=(e,t)=>{if((e.kind===`Operator`||e.kind===`Bpragma`)&&t.kind===e.kind)return M(e.body,t.body);if(e.kind===`Instance`&&t.kind===`Instance`){let n=e.instance.substitutions.map(e=>({name:e.name,value:e.expression})),r=t.instance.substitutions.map(e=>({name:e.name,value:e.expression}));return A(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&fe(n,r)}return!1},ge=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level===t.level&&e.shape===t.shape&&j(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?he(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&M(e.expression,t.expression),_e=(e,t)=>A(e.context,t.context,ge)&&M(e.active,t.active),M=(e,t)=>{if(e.kind===`Parens`)return M(e.expression,t);if(t.kind===`Parens`)return M(e,t.expression);switch(e.kind){case`Ix`:return t.kind===`Ix`&&e.index===t.index;case`Opaque`:return t.kind===`Opaque`&&e.name===t.name;case`Internal`:return t.kind===`Internal`&&e.builtin===t.builtin;case`Lambda`:return t.kind===`Lambda`&&e.params.length===t.params.length&&M(e.body,t.body);case`Apply`:return t.kind===`Apply`&&M(e.operator,t.operator)&&A(e.args,t.args,M);case`Sequent`:return t.kind===`Sequent`&&_e(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&M(e.expression,t.expression)&&A(e.selectors,t.selectors,me);case`With`:return t.kind===`With`&&M(e.expression,t.expression);case`Let`:return t.kind===`Let`&&A(e.definitions,t.definitions,he)&&M(e.body,t.body);case`If`:return t.kind===`If`&&M(e.condition,t.condition)&&M(e.consequent,t.consequent)&&M(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&A(e.items,t.items,M);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&A(e.bounds,t.bounds,pe)&&M(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&A(e.names,t.names,(e,t)=>e===t)&&M(e.body,t.body);case`Choose`:return t.kind===`Choose`&&j(e.domain,t.domain)&&M(e.body,t.body);case`SetSt`:return t.kind===`SetSt`&&M(e.domain,t.domain)&&M(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&M(e.element,t.element)&&A(e.bounds,t.bounds,pe);case`SetEnum`:case`Tuple`:return t.kind===e.kind&&A(e.elements,t.elements,M);case`Arrow`:return t.kind===`Arrow`&&M(e.domain,t.domain)&&M(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&A(e.bounds,t.bounds,pe)&&M(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&A([e.function,...e.args],[t.function,...t.args],M);case`Product`:return t.kind===`Product`&&A(e.factors,t.factors,M);case`Rect`:case`Record`:return t.kind===e.kind&&fe(e.fields,t.fields);case`Except`:return t.kind===`Except`&&M(e.function,t.function)&&A(e.specs,t.specs,(e,t)=>A(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&M(e.expression,t.expression))&&M(e.value,t.value));case`Dot`:return t.kind===`Dot`&&M(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&M(e.action,t.action)&&M(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&M(e.subscript,t.subscript)&&M(e.action,t.action);case`Case`:return t.kind===`Case`&&(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:M(e.arms[0].condition,t.arms[0].condition)&&M(e.arms[0].body,t.arms[0].body))&&j(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}},ve=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),ye=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,be=(e,t)=>e.map(e=>{let n=t(e.value);return{trail:e.trail.map(e=>e.kind===`Apply`?{kind:`Apply`,expression:t(e.expression)}:e),value:n}}),xe=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,Se=(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:xe(e.definition,t)}:{...e,expression:t(e.expression)},N=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,ne(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=re(t);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=C(e,t.sequent.context,(e,t)=>{let a=Se(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]=C(e,t.definitions,(e,t)=>{let i=xe(t,t=>n(e,t));return[r(e,ie(i)),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=ve(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=ve(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?T(t.name,i):w(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=T(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>ye(e,a));return{...t,expression:a(t.expression),selectors:e}}case`Apply`:{let e=t.args.map(a);return{...t,operator:a(t.operator),args:e}}case`With`:case`Dot`:case`Parens`:return{...t,expression:a(t.expression)};case`If`:{let e=a(t.alternative),n=a(t.consequent);return{...t,condition:a(t.condition),consequent:n,alternative:e}}case`List`:return{...t,items:t.items.map(a)};case`SetEnum`:case`Tuple`:return{...t,elements:t.elements.map(a)};case`Product`:return{...t,factors:t.factors.map(a)};case`FcnApp`:{let e=t.args.map(a);return{...t,function:a(t.function),args:e}}case`Arrow`:{let e=a(t.range);return{...t,domain:a(t.domain),range:e}}case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:a(e.value)}))};case`Except`:{let e=be(t.specs,a);return{...t,function:a(t.function),specs:e}}case`Sub`:case`Tsub`:case`Fair`:return{...t,subscript:a(t.subscript),action:a(t.action)};case`Case`:{let e=t.other&&a(t.other),n=t.arms.map(e=>{let t=a(e.body);return{condition:a(e.condition),body:t}});return{...t,arms:n,other:e}}}},Ce=(e,t)=>N(void 0,e,(e,n)=>t(n),()=>void 0,`all`),we=e=>{let t=[];return Ce(e,e=>(t.push(e),e)),t},Te={kind:`Opaque`,name:`$Bad`},Ee=e=>e.kind===`Opaque`&&e.name===Te.name,De=e=>{let t=e.kind===`Parens`?De(e.expression):Ce(e,De);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},Oe=e=>e.kind===`Let`?m({kind:`Let`,definitions:e.definitions,body:Oe(e.body)},e.body):e.kind===`Parens`?Oe(e.expression):Ce(e,Oe),ke=e=>e.kind===`Ix`?e.index<=0:we(e).some(ke),Ae=(e,t,n)=>{let r=(e,r=n)=>Ae(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(ne)]);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(re)]);case`Let`:{let t=[...n];for(let n of e.definitions){let e=n.kind===`Operator`||n.kind===`Bpragma`?r(n.body,[...t]):void 0;if(e)return e;t.push({kind:`Defn`,definition:n,whereDefined:`Builtin`,visibility:`Visible`,isLocal:!0})}return r(e.body,t)}case`Quant`:case`Fcn`:return i(e.bounds,e.body);case`SetOf`:return i(e.bounds,e.element);case`Tquant`:return r(e.body,[...n,...e.names.map(e=>({kind:`Flex`,name:e}))]);case`Choose`:case`SetSt`:return(e.domain&&r(e.domain))??r(e.body,[...n,w(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of we(e)){let e=r(t);if(e)return e}return}},je=(e,t)=>f(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),u(e+t)),Me=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),Ne=(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.C(a,{failure:`Expr.Deref.deref_inst`})}let i=n.kind===`SetOf`?n.element:n.body;return O(f(r,u(0)),i)}case`Tquant`:return Ne(t,m({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 Ne(t,m({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.C(i,{failure:`Expr.Deref.deref_inst`})}return O(f(r,u(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw t(c(n.location,r)),new e.C(r,{failure:`Expr.Deref.deref_inst`})}}},Pe=(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.C(n,{failure:`Expr.Deref.deref_at`})}}})(),a=O(je(n,i.length),r);return[i,Ne(t,a,Me(i.length))]},Fe=(t,n,r,i,a)=>{let o=n=>{if(!(r<=n))throw t(c(i.location,a)),new e.C(a,{failure:`Expr.Deref.deref_num`})},s=e=>(o(e.length),e[r-1]);if(n.kind===`With`)return Fe(t,n.expression,r,i,a);let l=(()=>{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.C(r,{failure:`Expr.Deref.deref_num`})}let s=O(u(-(r-1)),a?a.expression:i.active);if(ke(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.C(`Subexpression of ASSUME/PROVE uses identifiers declared therein
|
|
11
|
+
|
|
12
|
+
Tlapm does not handle yet such subexpression namings.`,{failure:`Expr.Deref.deref_num`});return 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]:m({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,m({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=>m({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...n.other?[m({kind:`Tuple`,elements:[Te,n.other]},n.other)]:[]])}let i=`Expression has no subexpressions`;throw t(c(n.location,i)),new e.C(i,{failure:`Expr.Deref.deref_num`})})();if(Ee(l)){let i=`Cannot resolve subexpression reference !${r}`;throw t(c(n.location,i)),new e.C(i,{failure:`Expr.Deref.deref_num`})}return[n.kind===`Let`?n.definitions:[],l]},Ie=(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])},Le=(t,n,r,i,a)=>{let o=Ae(r,i,[]);if(!o)return t(c(r.location,`Could not find label ${i}`)),{params:[],definitions:[],expression:Te};let s=o.indices;if(s.length!==a.length&&a.length>0){let n=s.length===1?``:`s`,r=`Expected ${s.length} argument${n} for labelled reference !${i}, but found ${a.length}`;throw t(c(o.expression.location,r)),new e.C(r,{failure:`Expr.Deref.deref_lsub`})}let l=a.length===0?s.map(e=>({name:e.name,shape:0})):[],f=a.length===0?Me(s.length):a,p=o.context.reduceRight((e,t)=>t.kind===`Defn`?m({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?m({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):O(u(-1),e),o.expression),h=O(je(n,l.length),p),g=[],_=h,v=Ie(s.map(e=>e.index),f);for(;v.length>0;)if(_.kind===`Let`&&_.definitions.length===1)g.push(_.definitions[0]),_=_.body,v=v.map(e=>O(u(1),e));else{if(_.kind!==`Quant`||_.bounds.length!==1)throw new e.j(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);_=O(d(v[0],u(0)),_.body),v=v.slice(1)}return{params:l,definitions:g,expression:_}},Re=(t,n,r,i,a)=>{if(r.kind!==`Let`)throw t(c(r.location,`not a LET expression`)),new e.C(`not a LET expression`,{failure:`Expr.Deref.deref_letop`});let o=r.definitions.findIndex(e=>e.kind===`Operator`&&e.name===i),s=r.definitions[o];if(!s||s.kind!==`Operator`){let n=`no definition of operator ${i}`;throw t(c(r.location,n)),new e.C(n,{failure:`Expr.Deref.deref_letop`})}let l=s.body,u=l.kind===`Lambda`?m({...l,body:m({kind:`Parens`,expression:l.body,form:{kind:`Xlabel`,label:i,indices:l.params.map((e,t)=>({name:e.name,index:l.params.length-t}))}},l.body)},l):m({kind:`Parens`,expression:l,form:{kind:`Xlabel`,label:i,indices:[]}},l);return Le(t,n,m({kind:`Let`,definitions:r.definitions.slice(0,o),body:u},l),i,a)},ze=(t,n,r,i)=>{let[a,...o]=i;if(!a){let e=r.definitions.length===0?r.expression:m({kind:`Let`,definitions:r.definitions,body:r.expression},r.expression),t=r.params.length===0?e:m({kind:`Lambda`,params:r.params,body:e},e);return{...De(t),isAtomic:!0}}if(r.expression.isAtomic)return t(c(r.expression.location,`Expression has no subexpressions`)),Te;let s=n?r.expression:Oe(r.expression),l=r.definitions.length,d=(()=>{let i=(e,n)=>{let[i,a]=Fe(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{...Re(t,l,s,r.label,r.args),rest:i,isLabel:!0};if(n)return{params:[],definitions:[],expression:s,rest:o,isLabel:!1};throw new e.C(`!: is forbidden for this expression.
|
|
13
|
+
`,{failure:`Expr.Deref.deref: !:`})}case`Number`:return i(a.value,`Cannot resolve !${a.value}`);case`Left`:return i(1,`Cannot resolve !<<`);case`Right`:return i(2,`Cannot resolve !>>`);case`Instance`:return{params:[],definitions:[],expression:Ne(t,s,a.args),rest:o,isLabel:!1};case`Label`:return{...s.kind===`Let`&&!n?Re(t,l,s,a.label,a.args):Le(t,l,s,a.label,a.args),rest:o,isLabel:!0};case`At`:{let[e,n]=Pe(t,l,s);return{params:e,definitions:[],expression:n,rest:o,isLabel:!1}}}})();return ze(t,d.isLabel,{params:[...r.params,...d.params],definitions:[...r.definitions,...d.definitions],expression:d.expression},d.rest.map(e=>ye(e,e=>O(u(d.definitions.length),e))))},Be=(e,t,n)=>{if(n.length>0)return{params:[],definitions:[],expression:Ne(e,t,n)};if(t.kind!==`Lambda`)return{params:[],definitions:[],expression:t};let[r,i]=Pe(e,0,t);return{params:r,definitions:[],expression:i}},Ve=(t,n,r,i)=>{let a=ze(t,!0,Be(t,n,r),i);if(Ee(a)){let r=`Could not resolve subexpression reference`;throw t(c(n.location,r)),new e.C(r,{failure:`Expr.Anon: 2`})}return a},He=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),Ue=e=>_(`UNCHANGED`,[e],e),We=e=>_(`Eq`,[_(`Prime`,[e],e),e],e),Ge=e=>{let t=e=>e.kind===`Tuple`?e.elements.flatMap(t):[e],n=t(e);return n.length===0?m({kind:`Internal`,builtin:`TRUE`},e):n.length===1?We(n[0]):m({kind:`List`,bullet:`And`,items:n.map(We)},e)},Ke=e=>t=>{let n=Ke(e);return e(t,n)??Ce(t,n)},qe=Ke((e,t)=>e.kind===`Apply`&&He(e,[`Leadsto`])?_(`BoxTrue`,[_(`Implies`,[t(e.args[0]),_(`Diamond`,[t(e.args[1])],e)],e)],e):void 0),Je=Ke(e=>{if(e.kind!==`Fair`)return;let t=e.action,n=e.subscript,r=_(`ENABLED`,[m({kind:`Sub`,modal:`Dia`,action:t,subscript:n},t)],t),i=e.fairness===`Weak`?`Diamond`:`BoxTrue`,a=e.fairness===`Weak`?`BoxTrue`:`Diamond`;return _(`Implies`,[_(i,[_(a,[r],t)],t),_(`BoxTrue`,[m({kind:`Tsub`,modal:`Dia`,action:t,subscript:n},t)],t)],t)}),Ye=Ke((e,t)=>{if(e.kind!==`Sub`&&e.kind!==`Tsub`)return;let n=t(e.action),r=t(e.subscript),i=e.modal===`Box`?_(`Disj`,[n,Ue(r)],e):_(`Conj`,[n,_(`Neg`,[Ue(r)],e)],e);return e.kind===`Sub`?i:_(e.modal===`Box`?`BoxTrue`:`Diamond`,[i],e)}),Xe=Ke(e=>e.kind===`Apply`&&He(e,[`UNCHANGED`])?Ge(e.args[0]):void 0),Ze=[`Prime`,`StrongPrime`,`Leadsto`,`ENABLED`,`UNCHANGED`,`Cdot`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`],Qe=/* @__PURE__ */ new WeakMap,$e=(e,t)=>{switch(t.kind){case`Fresh`:return t.level===`Constant`;case`Defn`:return t.definition.kind===`Operator`&&tt(e,t.definition.body);case`Fact`:return tt(e,t.expression);case`Flex`:return!1}},et=(e,t)=>b(e,t.map(e=>w(e,`Constant`))),tt=(e,t)=>{let n=t=>tt(e,t);switch(t.kind){case`Ix`:{let n=S(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=Qe.get(i);if(a!==void 0)return a;let o=tt(n?.rest,i);return Qe.set(i,o),o}case`Opaque`:case`String`:case`Num`:case`At`:return!0;case`Internal`:return!Ze.includes(t.builtin);case`Tquant`:case`Sub`:case`Tsub`:case`Fair`:return!1;case`Lambda`:return tt(et(e,t.params.map(e=>e.name)),t.body);case`Sequent`:{let n=t.sequent.context.reduce((e,t)=>({scope:y(e.scope,t),isGood:e.isGood&&$e(e.scope,t)}),{scope:e,isGood:!0});return n.isGood&&tt(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:y(e.scope,ie(t)),isGood:e.isGood&&t.kind===`Operator`&&tt(e.scope,t.body)}),{scope:e,isGood:!0});return n.isGood&&tt(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))&&tt(et(e,t.bounds.map(e=>e.name)),r)}case`Choose`:case`SetSt`:return(t.domain===void 0||n(t.domain))&&tt(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))}},nt=(e,t,n)=>{if(tt(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=>nt(e,t,n));if(t.kind===`Sequent`)return nt(b(e,t.sequent.context),t.sequent.active,n);if(t.kind!==`Apply`)return!1;let r=t.args;return He(t,[`BoxTrue`,`BoxFalse`])&&n||He(t,[`Diamond`])&&!n?!0:r.length===1&&He(t,[`BoxTrue`,`BoxFalse`,`Diamond`,`Prime`])?nt(e,r[0],n):r.length===1&&He(t,[`Neg`])?nt(e,r[0],!n):r.length===2&&He(t,[`Conj`,`Disj`])?nt(e,r[0],n)&&nt(e,r[1],n):r.length===2&&He(t,[`Implies`])?nt(e,r[0],!n)&&nt(e,r[1],n):r.length===2&&He(t,[`Equiv`])?[!0,!1].every(t=>nt(e,r[0],n!==t)&&nt(e,r[1],n===t)):nt(e,t.operator,n)&&r.every(t=>nt(e,t,n))},rt=(e,t)=>nt(e,qe(Je(Ye(Xe(t)))),!0)?`Always`:`Now`,it=(e,t)=>t===`Always`&&e.some(e=>e.kind===`Fact`&&e.time===`Now`)?`Now`:t,at=e=>e.kind===`Named`?`<${e.level}>${e.label}`:`<${e.level}>`,ot=e=>++e.value,st={kind:`Fact`,expression:{kind:`At`,isExcept:!1},visibility:`Visible`,time:`Always`},ct={Number:`1NUM`,Down:`1DOWN`,At:`1AT`,Instance:`1INST`,Left:`1`,Right:`1`},lt={kind:`Opaque`,name:`$badexp`},ut=(t,n,r)=>{let i,a=e=>({warnedSteps:[],scope:e}),o=e=>e.scope?.size??0,s=(e,t)=>{if(t.kind===`At`&&t.isExcept)return i?k(o(e)-i.size,i.expression):t;if(t.kind!==`Except`)return ee(e,t);let n=s(e,t.function);return t.specs.reduce((n,r)=>{let[a,c]=C(n,r.trail,(t,n)=>{if(n.kind===`Dot`)return[m({kind:`Dot`,expression:t,field:n.field},t),n];let r=s(e,n.expression);return[m({kind:`FcnApp`,function:t,args:[r]},t),{kind:`Apply`,expression:r}]}),l=i;i={expression:a,size:o(e)};let u=s(e,r.value);return i=l,m({kind:`Except`,function:n,specs:[{trail:c,value:u}]},t)},n)},f=(e,t,n)=>{let r=m({kind:`Ix`,index:e},n);return t.length===0?r:m({kind:`Apply`,operator:r,args:t},n)},p=(e,t,n,r,i)=>{if(t!==`Builtin`)return f(e,r,i);let a=k(e,n);return m(r.length===0?a:se(a,r),i)},h=(t,n,i,a)=>{let o=x(t.scope,n);if(!o){let t=`Operator "${n}" not found`;throw r(c(a.location,t)),new e.C(t,{failure:`Expr.Anon: 4`})}let s=o.depth+1,l=o.hyp;switch(l.kind){case`Defn`:{let t=l.definition;if(t.kind===`Operator`)return p(s,l.whereDefined,t.body,i,a);if(t.kind===`Recursive`)throw new e.C(`Recursive operators not supported by TLAPS`,{failure:`Expr.Anon: Recursive`});return f(s,i,a)}case`Fresh`:return f(s,i,a);case`Flex`:return m({kind:`Ix`,index:s},a);case`Fact`:throw new e.j(`File "src/expr/e_anon.ml", line 230, characters 24-36: Assertion failed`)}},g=(t,n,i,a,o,l)=>{let u=x(t.scope,n);if(!u){let[o,...u]=a;if(o?.kind===`Label`){let e=o.args.map(e=>s(t,e));return g(t,`${n}!${o.label}`,[...i,...e],u,!0,l)}let d=`Operator "${n}" not found`;throw o&&r(c(l.location,d)),new e.C(d,{failure:`Expr.Anon: ${o?ct[o.kind]:`1EMPTY`}`})}let d=u.hyp;if(d.kind!==`Defn`||d.definition.kind!==`Operator`&&d.definition.kind!==`Bpragma`)throw new e.C(`invalid subexpression reference`);let f=u.depth+1;if(a.length===0&&o)return i.length===0?m({kind:`Ix`,index:f},l):p(f,d.whereDefined,d.definition.body,i,l);let h=dt(k(f,d.definition.body),l);return dt(Ve(r,h,i,a),l)},ee=(e,t)=>{switch(t.kind){case`Bang`:{let n=t.expression;if(n.kind===`Apply`&&n.operator.kind===`Opaque`){let r=t.selectors.map(t=>ye(t,t=>s(e,t))),i=n.args.map(t=>s(e,t)),o=a(e.scope);return g(o,n.operator.name,i,r,!1,t)}return s(e,{...t,expression:m({kind:`Apply`,operator:n,args:[]},n)})}case`Apply`:{if(t.operator.kind!==`Opaque`)return oe(e,t);let n=t.operator.name;if(e.warnedSteps.includes(n))return r({text:`${l(t.location)}Warning: ${n} does not introduce any assumptions. It does not make sense to use it here.\n`,channel:`toolbox`}),m({kind:`Internal`,builtin:`TRUE`},t);let i=t.args.map(t=>s(e,t));return h(e,n,i,t)}case`Opaque`:return s(e,m({kind:`Apply`,operator:t,args:[]},t));case`Parens`:return t.form.kind===`Syntax`?s(e,t.expression):{...t,expression:s(e,t.expression),form:te(e,t.form)};default:return oe(e,t)}},te=(t,n)=>n.kind===`Nlabel`?{kind:`Xlabel`,label:n.label,indices:n.names.map(n=>{let r=x(t.scope,n);if(!r)throw new e.C(`Identifier "${n}" in label parameters not found`);return{name:n,index:r.depth+1}})}:n,T=(e,t)=>({warnedSteps:e.warnedSteps,scope:t}),E=(e,t)=>T(e,y(e.scope,t)),re=(e,t)=>T(e,b(e.scope,t.map(ne))),ae=(e,t)=>{let n=ve(t,t=>s(e,t));return[re(e,n),n]},oe=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:de(e,t.sequent)[1]};if(t.kind===`Let`){let[n,r]=le(e,t.definitions);return{...t,definitions:r,body:s(n,t.body)}}return N(e,t,s,E)},ce=(e,t)=>{if(t.kind!==`Operator`)return t;let n=t.body;if(n.kind!==`Fcn`)return{...t,body:s(e,n)};let r=s(E(e,w(t.name,`Constant`)),n);if(M(O(d({kind:`Opaque`,name:`%%%`},u(1)),r),r))return{...t,body:k(-1,r)};let i=_(`Eq`,[m({kind:`Ix`,index:1},r),r],r);return{...t,body:m({kind:`Choose`,name:t.name,domain:void 0,body:i},r)}},le=(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=ce(r,t);r=E(r,{...ie(o),isConstnessUnset:!0}),a.push(o)}return[r,a]},ue=(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:s(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ce(e,t.definition)};case`Fact`:{let n=s(e,t.expression);return{...t,expression:n,time:rt(e.scope,n)}}}})();return[E(e,n),n]},de=(e,t)=>{let[n,r]=C(e,t.context,ue);return[n,{context:r,active:s(n,t.active)}]},D=(e,t)=>({warnedSteps:[at(t),...e.warnedSteps],scope:e.scope}),A=(e,t,n,r)=>E(e,{kind:`Defn`,definition:{kind:`Operator`,name:at(t),body:n,location:r.location},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!0,isConstnessUnset:!0,location:r.location}),j=(e,t)=>T(e,b(e.scope,Array.from({length:t},()=>st))),fe=e=>{let t=[...e.context.map((t,n)=>{let r=e.context.length-n+1;if(t.kind===`Fact`)return k(r,t.expression);if(t.kind!==`Fresh`||!t.domain)return lt;let i=_(`Mem`,[m({kind:`Ix`,index:0},t.domain),t.domain],t.domain);return k(r,i)}),k(1,e.active)];return t.length===1?t[0]:{kind:`Tuple`,elements:t}},pe=e=>e.kind!==`Use`&&e.kind!==`Hide`&&e.kind!==`Define`,me=(e,t)=>({facts:t.facts.map(t=>s(e,t)),defs:t.defs.flatMap(t=>{if(t.kind===`Dx`)return[t];let n=s(e,m({kind:`Opaque`,name:t.name},t));return n.kind===`Ix`?S(e.scope,n.index-1)?.hyp.kind===`Defn`?[{kind:`Dx`,index:n.index,location:t.location}]:(r({text:`${l(t.location)}${JSON.stringify(t.name)} is not a definition and cannot be used in a DEF clause.`,channel:`toolbox`}),[]):(r({text:`${l(t.location)}Ignored unexpandable identifier ${JSON.stringify(t.name)} in BY DEF.`,channel:`stderr`}),[])})}),he=(e,t)=>{switch(t.kind){case`Steps`:{let[n,r]=C(e,t.steps,ge),i=he(t.step?D(n,t.step):n,t.qed.proof);return{...t,steps:r,qed:{...t.qed,proof:i}}}case`By`:return{...t,usable:me(e,t.usable)};default:return t}},ge=(n,r)=>{let i=r.step?.kind===`Unnamed`&&pe(r)?{kind:`Named`,level:r.step.level,label:`_a${ot(t)}`,isAnonymous:!0}:r.step;if(!i)throw new e.j;let a={...r,step:i};switch(a.kind){case`Assert`:{let[,e]=de(n,a.sequent),t=e.context.reduce(E,n),r=j(A(j(t,1),i,m(fe(e),a),a),1),o=e.context.length===0?D(r,i):r,s={...a,sequent:e,proof:he(o,a.proof)};return[j(A(n,i,m(v(e),a),a),1),s]}case`Pcase`:{let e=s(n,a.expression),t=m({kind:`Tuple`,elements:[k(2,e)]},a),r=j(A(j(n,2),i,t,a),1),o={...a,expression:e,proof:he(r,a.proof)},c=A(n,i,m({kind:`Tuple`,elements:[e]},a),a);return[j(c,1),o]}case`Suffices`:{let[,e]=de(n,a.sequent),t=m({kind:`Tuple`,elements:[m(v(e),a)]},a),r=j(A(n,i,t,a),1),o={...a,sequent:e,proof:he(r,a.proof)},s=e.context.reduce(E,n),c=m({kind:`Tuple`,elements:[m(fe(e),a)]},a);return[j(A(j(s,1),i,c,a),1),o]}case`Have`:{let e=s(n,a.expression),t=m({kind:`Tuple`,elements:[k(2,e)]},a);return[j(A(j(n,2),i,t,a),1),{...a,expression:e}]}case`Take`:{let[e,t]=ae(n,a.bounds),r=m({kind:`Quant`,quantifier:`Forall`,bounds:t,body:lt},a);return[j(A(j(e,1),i,r,a),1),{...a,bounds:t}]}case`Witness`:{let e=a.expressions.map(e=>s(n,e)),t=m({kind:`Tuple`,elements:e},a);return[j(A(j(n,1),i,t,a),1),{...a,expressions:e}]}case`Pick`:{let[e,t]=ae(n,a.bounds),r=s(e,a.expression),o=m({kind:`Quant`,quantifier:`Exists`,bounds:t,body:r},a),c=D(j(A(j(n,1),i,o,a),1),i),l={...a,bounds:t,expression:r,proof:he(c,a.proof)},u=re(j(n,2),t),d=k(4+t.length,o);return[j(A(j(u,2),i,d,a),1),l]}case`Use`:{let e=me(n,a.usable);return[j(n,e.facts.length),{...a,usable:e}]}case`Hide`:return[n,{...a,usable:me(n,a.usable)}];case`Define`:{let[e,t]=le(n,a.definitions);return[e,{...a,definitions:t}]}case`Forget`:return[n,a]}};return{expr:(e,t)=>s(a(e),t),defn:(e,t)=>ce(a(e),t),sequent:(e,t)=>de(a(e),t)[1],usable:(e,t)=>me(a(e),t),proof:(e,t)=>he(a(e),t)}},dt=(e,t)=>t.location?{...e,location:t.location}:e,ft=1000000010,pt=new TextEncoder,mt=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return pt.encode(e).length;return e.length},ht=()=>({leftTotal:-1,element:{size:-1,token:{kind:`Text`,text:``},length:0}}),gt=e=>{let t={size:-1,token:{kind:`Begin`,indent:0,box:`hov`},length:0};return{queue:[t],queueStart:0,scanStack:[ht(),{leftTotal:1,element:t}],formatStack:[],margin:78,maxIndent:e,spaceLeft:78,currentIndent:0,isNewLine:!0,leftTotal:1,rightTotal:1,depth:1,output:[]}},_t=(e,t)=>{e.rightTotal+=t.length,e.queue.push(t)},vt=(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))},yt=(e,t)=>{e.spaceLeft-=t,e.output.push(` `.repeat(t))},bt=e=>{let t=e.formatStack.at(-1);t?t.width>e.spaceLeft&&t.box!==`fits`&&t.box!==`h`&&vt(e,0,t.width):e.output.push(`
|
|
15
|
+
`)},xt=(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&&bt(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?vt(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?vt(e,n.offset,i):yt(e,n.width);return;case`b`:e.isNewLine?yt(e,n.width):t>e.spaceLeft||e.currentIndent>e.margin-i+n.offset?vt(e,n.offset,i):yt(e,n.width);return;case`hv`:case`v`:vt(e,n.offset,i);return;case`fits`:case`h`:yt(e,n.width);return}}}},St=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++,xt(e,n?t.size:ft,t.token),e.leftTotal+=t.length}e.queue.length=0,e.queueStart=0},Ct=(e,t)=>{_t(e,t),St(e)},wt=(e,t)=>{let n=e.scanStack.at(-1);n&&(n.leftTotal<e.leftTotal?e.scanStack=[ht()]:n.element.token.kind===(t?`Break`:`Begin`)&&(n.element.size=e.rightTotal+n.element.size,e.scanStack.pop()))},Tt=(e,t,n)=>{_t(e,n),t&&wt(e,!0),e.scanStack.push({leftTotal:e.rightTotal,element:n})},Et=(e,t,n)=>{e.depth++,Tt(e,!1,{size:-e.rightTotal,token:{kind:`Begin`,indent:n,box:t},length:0})},Dt=e=>{e.depth<=1||(_t(e,{size:0,token:{kind:`End`},length:0}),wt(e,!0),wt(e,!1),e.depth--)},Ot=(e,t,n)=>Ct(e,{size:t,token:{kind:`Text`,text:n},length:t}),kt=(e,t,n)=>Tt(e,!0,{size:-e.rightTotal,token:{kind:`Break`,width:t,offset:n},length:t}),At=e=>Ct(e,{size:0,token:{kind:`Newline`},length:0}),jt=e=>{for(;e.depth>1;)Dt(e);return e.rightTotal=ft,St(e),e.output.join(``)},Mt=e=>{jt(e);let t=[...e.output,`
|
|
17
|
+
`];Object.assign(e,gt(e.maxIndent)),e.output=t},Nt={h:`h`,v:`v`,hv:`hv`,hov:`hov`,b:`b`},Pt=e=>({kind:`Text`,text:e,size:mt(e)}),P=e=>e===``?[]:[Pt(e)],Ft={kind:`Break`,width:1,offset:0},It={kind:`Break`,width:0,offset:0},Lt=e=>{let t=e.search(/\d|$/);return{kind:`Open`,box:Nt[e.slice(0,t)],indent:Number(e.slice(t)||0)}},F=(e,...t)=>{let n=[],r=0,i=``,a=()=>{i!==``&&(n.push(Pt(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(Pt(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(Lt(e.slice(o+3,t))),o=t;break}case`]`:n.push({kind:`Close`}),o++;break;case` `:n.push(Ft),o++;break;case`,`:n.push(It),o++;break;case`
|
|
18
|
+
`:n.push({kind:`Newline`}),o++;break;case`.`:n.push({kind:`Flush`}),o++;break;case`;`:{let t=e.indexOf(`>`,o),r=e.slice(o+3,t).split(` `);n.push({kind:`Break`,width:Number(r[0]),offset:Number(r[1])}),o=t;break}case`<`:{let i=e.indexOf(`>`,o);n.push({kind:`Text`,text:String(t[r++]),size:Number(e.slice(o+2,i))}),o=i+2;break}}}return a(),n},I=(e,t,n=[Pt(`,`),Ft])=>e.flatMap((e,r)=>r===0?[t(e)]:[n,t(e)]),Rt=(e,t)=>{for(let n of t)if(Array.isArray(n))Rt(e,n);else switch(n.kind){case`Open`:Et(e,n.box,n.indent);break;case`Close`:Dt(e);break;case`Text`:Ot(e,n.size,n.text);break;case`Break`:kt(e,n.width,n.offset);break;case`Newline`:At(e);break;case`Flush`:Mt(e)}},zt=(e,t=68)=>{let n=gt(t);return Rt(n,e),jt(n)},Bt=e=>e.salt===0?e.rep:`${e.rep}_${e.salt}`,Vt=()=>({stack:[],idents:/* @__PURE__ */ new Map,defined:/* @__PURE__ */ new Map}),Ht=(e,t)=>{let n=e.stack[e.stack.length-t];return n&&Bt(n)},Ut=(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(Bt(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=Bt(r);return e.defined.set(a,(e.defined.get(a)??0)+1),a},Wt=(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=Bt(t),r=(e.defined.get(n)??1)-1;r===0?e.defined.delete(n):e.defined.set(n,r)}},Gt=(e,t,n)=>{let r=n(t.map(t=>Ut(e,t)));return Wt(e,t.length),r},Kt=[[`=>`,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`,[]]],qt=/* @__PURE__ */ new Map;for(let[e,t,n,r,i]of Kt){let a={name:e,low:t,high:n,fixity:r};for(let t of[e,...i])qt.set(t,a)}const Jt=e=>({name:e,low:-1,high:-1,fixity:`Nonfix`}),Yt=e=>qt.get(e)??Jt(e),Xt={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:`@@`},Zt=e=>{if(e===`Divides`)return{name:`?|`,low:10,high:11,fixity:`InfixNon`};if(e===`Uminus`)return{...Yt(`-.`),name:`-`};let t=Xt[e];return t?Yt(t):Jt(e)},Qt=(e,t)=>t.kind===`Atm`||t.kind===`Op`&&e<t.low,$t=e=>[F(`(`),e,F(`)`)],en=(e,t)=>t?tn(e):$t(tn(e)),tn=e=>{if(e.kind!==`Op`)return e.doc;let t=e.skeleton,n=t=>Qt(e.high,t);switch(t.kind){case`Prefix`:case`Postfix`:{let r=t.operand,i=en(r,n(r)||r.kind===`Op`&&r.skeleton.kind===t.kind),a=t.kind===`Prefix`?[e.doc,i]:[i,e.doc];return[F(`@[<h>`),...a,F(`@]`)]}case`Infix`:{let r=t.left,i=t.right,a=n(r)||r.kind===`Op`&&r.name===e.name&&t.assoc===`Left`,o=n(i)||t.assoc===`Right`&&i.kind===`Op`&&i.skeleton.kind===`Infix`&&i.skeleton.assoc===`Right`;return[F(`@[<b0>`),en(r,a),e.doc,en(i,o),F(`@]`)]}}},L=e=>({kind:`Atm`,doc:e}),nn=e=>({kind:`Big`,doc:e}),rn=e=>e.kind===`Lambda`?rn(e.body):e.kind===`Sequent`?rn(e.sequent.active):e.kind===`With`,an=e=>{if(e.kind===`Defn`){let t=e.definition,n=t.kind===`Operator`&&rn(t.body);return e.visibility===`Hidden`||n||e.whereDefined!==`User`}return e.kind===`Fact`?e.visibility===`Hidden`||rn(e.expression):!1},on=e=>e===0?[]:F(`@[<hov1>(%a)@]`,I(Array.from({length:e},()=>`_`),P)),sn=e=>F(`%s%a`,e.name,on(e.shape)),cn={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`UNKNOWN`},ln=(t=[])=>{let n=Vt(),r=e=>tn(u(e)),i=(e,t)=>Gt(n,e.map(e=>e.name),()=>F(`@[<b2>LAMBDA @[<hv0>%a@] :@ %a@]`,I(e,sn),r(t))),a=(e,t)=>{let i=e.map(e=>e.domain.kind===`Domain`?r(e.domain.expression):void 0);return Gt(n,e.map(e=>e.name),n=>{let r=[];return e.forEach((e,t)=>{t>0&&e.domain.kind===`Ditto`?r.at(-1)?.names.push(n[t]):r.push({names:[n[t]],index:t})}),t(I(r,t=>{let n=I(t.names,P),r=e[t.index].domain;return r.kind===`NoDomain`?n:r.kind===`Ditto`?F(`@[<hov0>%a@ \\in ??????@]`,n):F(`@[<hov0>%a@ \\in %a@]`,n,i[t.index]??[])}))})},o=e=>{switch(e.kind){case`Down`:return F(`:`);case`Left`:return F(`<<`);case`Right`:return F(`>>`);case`At`:return P(`@`);case`Number`:return P(String(e.value));case`Instance`:return F(`@[<b1>(%a)@]`,I(e.args,r));case`Label`:return e.args.length===0?P(e.label):F(`@[<b2>%s@,@[<b1>(%a)@]@]`,e.label,I(e.args,r))}},s=e=>e.length===0?[]:[F(`!`),I(e,o,F(`!`))],c=e=>{if(e<0)return`#$$${Math.abs(e)}`;if(e===0)return`#$0`;if(e<=n.stack.length)return Ht(n,e);let r=t[t.length-(e-n.stack.length)];return r?h(r)??`??? FACT ???`:`#$${e}`},l=(t,n)=>{if(t.kind===`Lambda`)return{kind:`Op`,name:` `,doc:F(`@ `),low:20,high:20,skeleton:{kind:`Infix`,assoc:`Left`,left:nn(i(t.params,t.body)),right:L(F(`(%a)`,I(n,r)))}};if(t.kind===`Bang`)return n.length===0?u(t):L(F(`@[<b2>%a@[<b1>(%a)@]@]`,r(t),I(n,r)));if(t.kind===`Internal`&&n.length===1){if(t.builtin===`BoxFalse`||t.builtin===`Unprimable`)return u(n[0]);if(t.builtin===`Irregular`)return L(F(`@[<h>@<1>%s%a@<1>%s@]`,`<[`,r(n[0]),`]>`))}let a=(()=>{switch(t.kind){case`Ix`:return Yt(c(t.index));case`Opaque`:{let e=Yt(t.name);return{...e,name:`?${e.name}`}}case`Internal`:return Zt(t.builtin);default:throw new e.C(`Cannot print this operator`)}})(),o=(e,t)=>({kind:`Op`,name:a.name,doc:e,low:a.low,high:a.high,skeleton:t});if(n.length===0)return L(P(a.name));if(a.fixity===`Nonfix`)return L(F(`@[<b2>%s@[<b1>(%a)@]@]`,a.name,I(n,r)));if(a.fixity===`Prefix`&&n.length===1)return o(/[A-Za-z]$/.test(a.name)?F(`%s@ `,a.name):P(a.name),{kind:`Prefix`,operand:u(n[0])});if(a.fixity===`Postfix`&&n.length===1)return o(P(a.name),{kind:`Postfix`,operand:u(n[0])});if(a.fixity.startsWith(`Infix`)&&n.length===2){let e=a.fixity===`InfixLeft`?`Left`:a.fixity===`InfixRight`?`Right`:`Non`;return o(a.name===`..`?P(a.name):F(`@ %s `,a.name),{kind:`Infix`,assoc:e,left:u(n[0]),right:u(n[1])})}throw new e.C(`Arity mismatch for operator ${a.name}`)},u=t=>{switch(t.kind){case`Ix`:case`Opaque`:case`Internal`:return l(t,[]);case`Lambda`:return nn(i(t.params,t.body));case`Bang`:return L([r(t.expression),s(t.selectors)]);case`Apply`:return l(t.operator,t.args);case`Sequent`:return nn(p(t.sequent));case`With`:return u(t.expression);case`If`:return nn(F(`@[<hv2>@[<b2>IF@ %a@]@ @[<b2>THEN %a@]@ @[<b2>ELSE %a@]@]`,r(t.condition),r(t.consequent),r(t.alternative)));case`List`:{if(t.bullet===`Refs`&&t.items.length===0)return L(F(`TRUE`));if(t.bullet===`Refs`&&t.items.length===1)return u(t.items[0]);let e=t.bullet===`Or`?`\\/`:`/\\`;return nn(F(`@[<v0>%a@]`,I(t.items,t=>F(`@[<h>%s %a@]`,e,r(t)),F(`@,`))))}case`Let`:{let e=I(t.definitions,d,F(`@,`)),i=r(t.body);return Wt(n,t.definitions.length),nn([F(`@[<hv0>LET @[<v0>`),e,F(`@]@
|
|
19
|
+
IN %a@]`,i)])}case`Quant`:return a(t.bounds,e=>nn(F(`@[<b3>%s @[<b0>%a@] :@ %a@]`,t.quantifier===`Forall`?`\\A`:`\\E`,e,r(t.body))));case`Tquant`:return Gt(n,t.names,e=>nn(F(`@[<b4>%s @[<b0>%a@] : %a@]`,t.quantifier===`Forall`?`\\AA`:`\\EE`,I(e,P),r(t.body))));case`Choose`:{let e=t.domain&&r(t.domain);return Gt(n,[t.name],([n])=>nn(e?F(`@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]`,n,e,r(t.body)):F(`@[<b2>CHOOSE %s :@ %a@]`,n,r(t.body))))}case`SetSt`:{let e=r(t.domain);return Gt(n,[t.name],([n])=>L(F(`@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]`,n,e,r(t.body))))}case`SetOf`:return a(t.bounds,e=>L(F(`@[<b3>{%a :@ %a}@]`,r(t.element),e)));case`SetEnum`:return L(F(`@[<h>{@[<b0>%a@]}@]`,I(t.elements,r)));case`Arrow`:return L(F(`@[<b3>[%a ->@ %a]@]`,r(t.domain),r(t.range)));case`Fcn`:return a(t.bounds,e=>L(F(`@[<b3>[%a |->@ %a]@]`,e,r(t.body))));case`FcnApp`:{let e=u(t.function),n=e.kind===`Atm`;return L(F(`@[<h>%s%a%s@[<b1>[%a]@]@]`,n?``:`(`,tn(e),n?``:`)`,I(t.args,r)))}case`Product`:if(t.factors.length===1)return u(t.factors[0]);if(t.factors.length===0)throw new e.C(`Expr.Fmt.fmt_expr: PRODUCT []`);return{kind:`Op`,name:`\\X`,doc:F(`@ \\X `),low:10,high:13,skeleton:{kind:`Infix`,assoc:`Right`,left:u(t.factors[0]),right:u({...t,factors:t.factors.slice(1)})}};case`Tuple`:return L(F(`@[<b2><<%a>>@]`,I(t.elements,r)));case`Rect`:case`Record`:{let e=t.kind===`Rect`?`:`:`|->`;return L(F(`@[<b1>[%a]@]`,I(t.fields,t=>F(`@[<h>%s ${e} %a@]`,t.name,r(t.value)))))}case`Except`:return L(F(`@[<b3>[%a EXCEPT@ @[<v0>%a@]]@]`,r(t.function),I(t.specs,e=>F(`!@[<h>%a = %a@]`,e.trail.map(e=>e.kind===`Dot`?F(`.%s`,e.field):F(`[%a]`,r(e.expression))),r(e.value)))));case`Dot`:return{kind:`Op`,name:`.`,doc:F(`.`),low:16,high:16,skeleton:{kind:`Infix`,assoc:`Left`,left:u(t.expression),right:L(P(t.field))}};case`Sub`:case`Tsub`:{let e=t.modal===`Box`,n=t.kind===`Sub`?e?`[`:`<<`:e?`[][`:`<><<`;return L(F(`@[<h>%s@[<b2>%a@]%s%a@]`,n,r(t.action),e?`]_`:`>>_`,r(t.subscript)))}case`Fair`:return nn(F(`@[<h>%s_%a (%a)@]`,t.fairness===`Weak`?`WF`:`SF`,$t(r(t.subscript)),r(t.action)));case`Case`:return nn(F(`@[<v2>CASE %a%a@]`,I(t.arms,e=>F(`@[<b2>%a ->@ %a@]`,r(e.condition),r(e.body)),F(`@,[] `)),t.other?F(`@,[] @[<b2>OTHER ->@ %a@]`,r(t.other)):[]));case`String`:return L(F(`"%s"`,t.value));case`Num`:return L(P(t.fraction===``?t.integer:`${t.integer}.${t.fraction}`));case`At`:return L(P(`@`));case`Parens`:{let e=t.form;if(e.kind===`Syntax`)return u(t.expression);let r=e.kind===`Nlabel`?e.names:e.indices.map(e=>e.index>=1&&e.index<=n.stack.length?c(e.index):`¶${e.index}`),i=u(t.expression);if(r.length===0){let t=i.kind===`Op`?`%s::(%a)`:`%s::%a`;return L(F(t,e.label,tn(i)))}let a=I(r,P),o=i.kind===`Atm`?`%s(%a)::%a`:i.kind===`Big`?`%s(%a)::(%a)`:`(%s(%a):: %a)`;return L(F(o,e.label,a,tn(i)))}}},d=e=>{switch(e.kind){case`Operator`:case`Bpragma`:{let t=e.body;if(t.kind===`Lambda`){let i=Gt(n,t.params.map(e=>e.name),()=>r(t.body)),a=Ut(n,e.name);return F(`@[<b2>%s@[<b1>(%a)@] ==@ %a@]`,a,I(t.params,sn),i)}let i=r(t);return F(`@[<b2>%s ==@ %a@]`,Ut(n,e.name),i)}case`Instance`:{let t=e.instance,i=Gt(n,t.args,e=>({doc:F(`@[<b2>INSTANCE %s%a@]`,t.module,t.substitutions.length===0?[]:F(`@ WITH@ %a`,I(t.substitutions,e=>F(`@[<b2>%s <- %a@]`,e.name,r(e.expression))))),args:e})),a=Ut(n,e.name),o=t.args.length===0?P(a):F(`%s (@[<b0>%a@])`,a,I(i.args,P));return F(`@[<b2>%a == %a@]`,o,i.doc)}case`Recursive`:{let t=Ut(n,e.name);return F(`@[<b2>NEW CONSTANT %s%a@]`,t,on(e.shape))}}},f=e=>{switch(e.kind){case`Fresh`:{let t=e.domain&&e.domainVisibility===`Visible`?r(e.domain):void 0,i=Ut(n,e.name);return[F(`NEW %s %s%a`,cn[e.level],i,on(e.shape)),t?F(` \\in %a`,t):[]]}case`Flex`:return F(`NEW VARIABLE %s`,Ut(n,e.name));case`Defn`:return d(e.definition);case`Fact`:{let t=F(`@[<h>%a @]`,r(e.expression));return Ut(n,``),t}}},p=e=>{if(e.context.length===0)return r(e.active);let t=[];for(let r of e.context)an(r)?Ut(n,h(r)??``):t.push(f(r));let i=r(e.active);return Wt(n,e.context.length),t.length===0?i:[F(`@[<v0>ASSUME @[<v0>`),I(t,e=>e),F(`@]@
|
|
20
|
+
PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},un=(e,t)=>ln(e).printExpr(t),dn=e=>ln().printSequent(e),fn=e=>zt(F(`@[<b0>%a@]`,dn(e))).trimEnd(),pn={kind:`At`,isExcept:!1},R=e=>({location:e.location,step:e.step,method:e.method}),mn=e=>e?.kind===`Named`&&e.isAnonymous,hn=e=>e?.level??0,gn=e=>m({kind:`Internal`,builtin:`TRUE`},e),_n=(e,t)=>g(e,t)&&e.args.length===2,vn=(e,...t)=>zt(F(e,...t)),yn=e=>bn(e).map((e,t)=>{let n=e.domain.kind===`Domain`?k(t,e.domain.expression):void 0;return{kind:`Fresh`,name:e.name,shape:0,level:n?`Constant`:e.level,domain:n,domainVisibility:`Visible`}}),bn=e=>{let t={kind:`NoDomain`};return e.map(e=>e.domain.kind===`Ditto`?{...e,domain:t}:(t=e.domain,e))},xn=(e,t)=>t.context.flatMap((n,r)=>n.kind===`Fact`&&n.visibility===`Visible`?[k(e+t.context.length-1-r,n.expression)]:[]),Sn=(t,n,r)=>{if(!t.step)throw new e.j;return{kind:`Defn`,definition:{kind:`Operator`,name:at(t.step),body:n,location:t.location},whereDefined:{kind:`Proof`,time:r},visibility:`Visible`,isLocal:!0,location:t.location}},Cn=(e,t,n,r)=>{let i=mn(n.step)?`Visible`:`Hidden`,a=t.context.map(e=>e.kind===`Fact`?{...e,visibility:i}:e),o=m({kind:`List`,bullet:`Refs`,items:xn(2,t)},n),s=it(t.context,r);return{context:[...e,...a,E(gn(n),`Hidden`,r,n.location),Sn(n,o,s),E(m({kind:`Ix`,index:1},n),`Hidden`,s,n.location)],active:k(3,t.active),time:s}},wn=(e,t,n,r,i,a)=>{let o=e||mn(i.step)?`Visible`:`Hidden`;return{context:[...t,Sn(i,m(v(r),i),a),E(m({kind:`Ix`,index:1},i),o,a,i.location)],active:k(2,n)}},Tn=(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`},En=(t,n,r)=>{if(r.kind!==`Dx`)throw new e.C(`Unknown definition ${r.name}`);let i=n.length-r.index,a=n[i];if(!a)return n;if(a.kind!==`Defn`)throw new e.C(`Indicated point is not a definition`);return n.map((e,n)=>n===i?{...a,visibility:t}:e)},Dn=(e,t)=>g(e,`Mem`)&&e.args[0]?.kind===`Ix`&&e.args[0].index===0&&M(t,e.args[1]),On=(t,n,r,i)=>{let a=!1,o=r,s=[...i];for(let e=i.length-1;e>=0;e--){o=k(-1,o);let t=i[e];t.kind===`Fact`&&M(t.expression,o)?(a=!0,s[e]={...t,visibility:n}):t.kind===`Fresh`&&t.domain&&Dn(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.C(n,{failure:`proof.Gen.set_expr`})}return s},kn=(e,t)=>{let n=le(u(1),t)[1];return n[0].domain.kind===`Ditto`&&e.domain.kind===`Domain`?[{...n[0],domain:{kind:`Domain`,expression:k(1,e.domain.expression)}},...n.slice(1)]:n},An=(e,t)=>{if(t.length===0)return{kind:`Obvious`,...R(e)};let n=t.map((t,n)=>{let r=k(2*n+2,t);return{kind:`Assert`,sequent:{context:[],active:r},proof:{kind:`By`,usable:{facts:[k(3,r)],defs:[]},isOnly:!1,location:t.location,method:e.method},location:t.location}}),r={kind:`By`,usable:{facts:[m({kind:`Ix`,index:2*t.length+2},e),...t.map((n,r)=>m({kind:`Ix`,index:2*(t.length-r)},e))],defs:[]},isOnly:!0,...R(e),method:void 0};return{kind:`Steps`,steps:n,qed:{proof:r,location:r.location},...R(e)}},jn=(e,t,n)=>({sequent:e,location:t.location,kind:n,method:t.method}),Mn={total:0,absent:[],omitted:[]},Nn=(e,t)=>({total:e.total+t.total,absent:[...e.absent,...t.absent],omitted:[...e.omitted,...t.omitted]}),Pn=e=>e.kind===`Use`?{...Mn,total:e.obligations?.length??0}:`proof`in e?Fn(e.proof):Mn,Fn=e=>e.kind===`Steps`?[...e.steps.map(Pn),Fn(e.qed.proof)].reduce(Nn):e.kind!==`Omitted`||!e.obligations||!e.location?{...Mn,total:e.obligations?.length??0}:{total:e.obligations.length,absent:e.omission===`Implicit`?[e.location]:[],omitted:e.omission===`Explicit`?[e.location]:[]},In=(e,t)=>e.kind===`At`&&!e.isExcept?m(ce(t),e):Ce(e,e=>In(e,t)),Ln=(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:[jn(t,i,{kind:`Main`})]};case`Omitted`:return{...i,obligations:[jn(t,i,{kind:`Omitted`,omission:i.omission})]};case`Error`:return{...i,obligations:[jn(t,i,{kind:`Error`,message:i.message})]};case`By`:throw new e.C(`Proof.Gen.generate`);case`Steps`:{let[e,n]=C({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=jn({...t,active:e},n,{kind:`Support`});return[{context:[...t.context,{...E(e,`Visible`,Tn(t.context,e,r),e.location),useLocation:n.useLocation}],active:k(1,t.active)},{...n,obligations:[a]},r]}if(i.facts.length>0)throw new e.C(`Proof.Gen.gen_step: USE with facts and definitions`);let a=i.defs.reduce((e,t)=>En(`Visible`,e,t),t.context);return[{...t,context:a},n,r]}case`Hide`:{let e=n.usable.defs.reduce((e,t)=>En(`Hidden`,e,t),t.context),a=n.usable.facts.reduceRight((e,t)=>On(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:k(n.definitions.length,t.active)},n,r];case`Assert`:{let e=Cn(t.context,n.sequent,n,r),i=a(e,n.proof,e.time),o={...n,proof:i};return[wn(!1,t.context,t.active,n.sequent,o,r),o,r]}case`Suffices`:{let e=a(wn(!0,t.context,t.active,n.sequent,n,r),n.proof,r),i={...n,proof:e},o=Cn(t.context,n.sequent,i,r);return[o,i,o.time]}default:throw new e.C(`Proof.Gen.gen_step`)}},s=(e,t,n,r)=>{let i={kind:`Unnamed`,level:0,id:0},[a,s]=o({context:e,active:{...pn,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=>k(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},f=e=>({kind:`Named`,level:e,label:`_a${ot(t)}`,isAnonymous:!0}),p=(e,t)=>t?.kind===`Named`?{...t,level:e}:f(e),h=(e,t)=>{let n={...t,step:p(e,t.step)};if(n.kind!==`Steps`)return n;let r=n.steps.map(t=>v(e,t));return{...n,steps:r,qed:{...n.qed,proof:h(e+1,n.qed.proof)}}},v=(e,t)=>{let n={...t,step:p(e,t.step)};return`proof`in n?{...n,proof:h(e+1,n.proof)}:n},y=(t,n)=>{let r=n.kind===`Apply`?n.operator:n;if(r.kind===`Ix`){let i=t[t.length-r.index];if(!i)throw new e.C(`expose_connective`);if(i.kind!==`Defn`||i.definition.kind!==`Operator`)return n;let a=k(r.index,i.definition.body);if(n.kind!==`Apply`)return y(t,a);let o={...a,location:n.location};return y(t,m(se(o,n.args),o))}if(g(n,`Prime`)){let e=y(t,n.args[0]),r=e=>_(`Prime`,[e],e);return e.kind===`Quant`?m({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):_n(e,`Implies`)||_n(e,`Mem`)?m({kind:`Apply`,operator:e.operator,args:[r(e.args[0]),r(e.args[1])]},n):r(e)}return n.kind===`Parens`?y(t,n.expression):n},b=e=>{if(e.kind!==`Assert`)return;let t=e.sequent.active;return t.kind===`Apply`&&t.args.length===2?t.args[1]:void 0},ee=e=>{if(e.kind!==`Steps`)return e;let t=[];return e.steps.forEach(e=>{let n=t.at(-1),r=n&&b(n);if(e.kind!==`Assert`||!r){t.push(e);return}let i=In(e.sequent.active,k(2,r));t.push({...e,sequent:{...e.sequent,active:i}})}),{...e,steps:t}},x=(e,t,n,r)=>{let i=ee(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:[k(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:f(a)})),s={kind:`Obvious`,location:i.location,step:f(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]=C({context:e,goal:t,time:r},i.steps,(e,t)=>{let[n,r,i,a]=S(e.context,e.goal,t,e.time);return[{context:n,goal:r,time:a},i]}),o=x(n.context,n.goal,i.qed.proof,n.time);return{...i,steps:a.flat(),qed:{...i.qed,proof:o}}}}},S=(t,n,r,i)=>{let a=hn(r.step);switch(r.kind){case`Forget`:return[t,n,[r],i];case`Assert`:{let e=Cn(t,r.sequent,r,i),a={...r,proof:x(e.context,e.active,r.proof,e.time)},o=wn(!1,t,n,r.sequent,a,i);return[o.context,o.active,[a],i]}case`Suffices`:{let e=wn(!0,t,n,r.sequent,r,i),a={...r,proof:x(e.context,e.active,r.proof,i)},o=Cn(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=x(t,n,a,i);if(o.kind!==`Steps`)throw new e.C(`simplifying BY does not produce a non-leaf proof!`);let s=r.usable.facts.map(()=>E(pn,`Visible`,i,r.location));return[[...t,...s],k(r.usable.facts.length,n),o.steps,i]}case`Hide`:return[r.usable.defs.reduce((t,n)=>{if(n.kind!==`Dx`)throw new e.C(`set_vis`);let i=t.length-n.index,a=t[i];if(a?.kind!==`Defn`){let t=a?a.kind===`Fact`?`??? FACT ???`:a.name:``;throw new e.C(`USE DEF ${t} invalid because ${t} is not a defined operator`)}return t.map((e,t)=>t===i?{...a,visibility:`Hidden`,location:r.location}:e)},t),n,[r],i];case`Define`:return[[...t,...r.definitions.map(e=>({kind:`Defn`,definition:e,whereDefined:{kind:`Proof`,time:i},visibility:`Visible`,isLocal:!0,location:r.location}))],k(r.definitions.length,n),[r],i];case`Have`:{let e=y(t,n),o=_n(e,`Implies`),s={context:[E(r.expression,`Visible`,i,r.location)],active:o?k(1,e.args[1]):e},c=o?{kind:`By`,usable:{facts:[m({kind:`Ix`,index:2},r)],defs:[]},isOnly:!0,...R(r)}:{kind:`Error`,message:vn(`@.@[<v2>@[%s@ %s@]@,%a@]@.`,`Error: this HAVE step is applied to the following goal,`,`which is not an implication:`,un(t,n)),...R(r)},l=v(a,{kind:`Suffices`,sequent:s,proof:c,location:r.location,step:r.step});return S(t,n,l,i)}case`Take`:return S(t,n,v(a,w(t,n,r)),i);case`Witness`:return S(t,n,v(a,T(t,n,r)),i);case`Pcase`:{let e={kind:`Assert`,sequent:{context:[E(r.expression,`Visible`,i,r.location)],active:k(1,n)},proof:r.proof,...R(r)};return S(t,n,v(a,e),i)}case`Pick`:{let a=m({kind:`Quant`,quantifier:`Exists`,bounds:r.bounds,body:r.expression},r),o=te(r.step,`ex`),[s,c,l,u]=S(t,n,{kind:`Assert`,sequent:{context:[],active:a},proof:r.proof,...R(r),step:o},i),d=k(2,a);if(d.kind!==`Quant`)throw new e.C(`Proof.Simplify.simplify_step/PICK`);let f=[...yn(d.bounds),E(d.body,`Visible`,u,d.body.location)],[p,h,g,_]=S(s,c,{kind:`Suffices`,sequent:{context:f,active:k(f.length,c)},proof:{kind:`Omitted`,omission:`Elsewhere`,...R(r)},...R(r)},u);return[p,h,[...l,...g],_]}}},te=(e,n)=>({kind:`Named`,level:hn(e),label:`${e?.kind===`Named`?e.label:`_a`}${n}${ot(t)}`,isAnonymous:!1}),w=(e,t,n)=>{let r=bn(n.bounds),i=(t,n,r,a)=>{let o=a[0];if(!o)return{aux:n,goal:r};let s=y(e,r);if(s.kind!==`Quant`||s.quantifier!==`Forall`||s.bounds.length===0)return vn(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this TAKE step is applied to the following goal,`,`which is not a universal formula:`,un(e,r));let c=s.bounds[0],l=bn(s.bounds).slice(1),d=o.domain,f=c.domain;if(d.kind===`NoDomain`&&f.kind===`Domain`)return vn(`@.@[<b0>%s (%s)@ %s (%s \\in %a)@]@.`,`Error: the TAKE argument`,o.name,`does not match the pattern`,c.name,un(e,f.expression));if(d.kind===`Domain`&&f.kind===`NoDomain`)return vn(`@.@[<b0>%s (%s \\in %a)@ %s (%s)@]@.`,`Error: the TAKE argument`,o.name,un(e,d.expression),`does not match the pattern`,c.name);let p=d.kind===`Domain`&&f.kind===`Domain`&&!M(d.expression,f.expression)?[{kind:`Apply`,operator:{kind:`Internal`,builtin:`Subseteq`},args:[f.expression,d.expression]},...n]:n;if(l.length===0)return i(1,p,s.body,a.slice(1));let h=a.length===1?l.map(e=>le(u(t),[e])[1][0]):l;return i(t+1,p,m({kind:`Quant`,quantifier:`Forall`,bounds:h,body:s.body},s),a.slice(1))},a=i(1,[],t,r);if(typeof a==`string`)return{kind:`Suffices`,sequent:{context:[E(gn(t),`Visible`,`Now`,n.location)],active:t},proof:{kind:`Error`,message:a,...R(n)},...R(n)};let o=a.aux.filter((e,t)=>a.aux.findIndex(t=>M(e,t))===t),s=[m({kind:`Ix`,index:2},n),...o.map(e=>k(2,e))];return{kind:`Suffices`,sequent:{context:yn(r),active:a.goal},proof:{kind:`By`,usable:{facts:s,defs:[]},isOnly:!0,...R(n)},...R(n)}},T=(e,t,n)=>{let r=[],i=``,a=t;for(let t of n.expressions){let n=y(e,a);if(n.kind!==`Quant`||n.quantifier!==`Exists`||n.bounds.length===0){i||=vn(`@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.`,`Error: this WITNESS step is applied to the following goal,`,`which is not an existential formula:`,un(e,n)),a=n;break}let[o,...s]=n.bounds,c=s.length===0?n.body:m({kind:`Quant`,quantifier:`Exists`,bounds:kn(o,s),body:n.body},n),l=t;if(o.domain.kind===`Domain`){let n=o.domain.expression,a=y(e,t);if(_n(a,`Mem`)){let[e,t]=a.args,i=M(t,n)?[]:[_(`Subseteq`,[t,n],t)];r.push(...i,a),l=e}else i||=vn(`@.@[<b0>%s (%a)@ %s (%s \\in %a)@]@.`,`Error: the WITNESS argument`,un(e,a),`does not match the pattern`,o.name,un(e,n)),l=a}let f=_(`Unprimable`,[l],l);a=O(d(f,u(0)),c)}let o=i===``?An(n,r):{kind:`Error`,message:i,...R(n)};return{kind:`Suffices`,sequent:{context:[],active:a},proof:o,...R(n)}};return{generate:a,collect:l,mutate:c,simplify:x}},Rn=(e,t=0)=>({level:e,weights:Array.from({length:t},()=>!0),params:/* @__PURE__ */ new Set}),zn={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]},Bn={Constant:0,State:1,Action:2,Temporal:3,Unknown:0},Vn=e=>new Set(e.flatMap(e=>[...e])),Hn=e=>({level:Math.max(0,...e.map(e=>e.level)),weights:[],params:Vn(e.map(e=>e.params))}),Un=/* @__PURE__ */ new WeakMap,Wn=t=>{let n=t.hyp;switch(n.kind){case`Flex`:return Rn(1);case`Fresh`:return{...Rn(Bn[n.level],n.shape),params:/* @__PURE__ */ new Set([n.name])};case`Defn`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e.j;return z(t.rest,r.body)}case`Fact`:return z(t.rest,n.expression)}},Gn=e=>{let t=Un.get(e);if(t)return t;let n=Wn(e);return Un.set(e,n),n},Kn=(e,t,n)=>{let r=t.flatMap(t=>t.domain.kind===`Domain`?[z(e,t.domain.expression)]:[]);return Hn([z(b(e,t.map(ne)),n),...r])},qn=(t,n)=>{if(t.weights.length!==n.length)throw new e.C(`Invalid number of arguments`);let r=n.filter((e,n)=>t.weights[n]);return{level:Math.max(t.level,...r.map(e=>e.level)),weights:[],params:Vn([t.params,...r.map(e=>e.params)])}},z=(t,n)=>{let r=e=>z(t,e);switch(n.kind){case`Ix`:{let r=S(t,n.index-1);if(!r)throw new e.j;return Gn(r)}case`Internal`:{let t=zn[n.builtin];if(!t)throw new e.j;return Rn(t[0],t[1])}case`Opaque`:case`String`:case`Num`:return Rn(0);case`Lambda`:{let e=z(b(t,n.params.map(re)),n.body),r=new Set(n.params.map(e=>e.name));return{level:e.level,weights:n.params.map(t=>e.params.has(t.name)),params:new Set([...e.params].filter(e=>!r.has(e)))}}case`Apply`:{let t=n.operator;if(g(t,`Prime`)&&t.args.length===1)return r({...n,operator:t.args[0]});if(t.kind===`Opaque`)return qn(Rn(0,n.args.length),n.args.map(r));if(t.kind===`Internal`&&n.args.length===1){let i=n.args[0];switch(t.builtin){case`Prime`:case`StrongPrime`:if(r(i).level>1)throw new e.j;return Rn(2,1);case`ENABLED`:{let t=r(i);if(t.level>2)throw new e.j;return{level:1,weights:[],params:t.params}}case`UNCHANGED`:{let t=r(i);if(t.level>1)throw new e.j;return{level:2,weights:[],params:t.params}}}}return t.kind===`Internal`&&t.builtin===`Cdot`?(n.args.forEach(r),Rn(2)):t.kind===`Internal`&&t.builtin===`Leadsto`?(n.args.forEach(r),Rn(3,2)):qn(r(t),n.args.map(r))}case`Sequent`:{let[e,r]=C(t,n.sequent.context,(e,t)=>{let n=y(e,t);return[n,Gn(n).level]});return Rn(Math.max(0,...r,z(e,n.sequent.active).level))}case`With`:case`Dot`:case`Parens`:return r(n.expression);case`Let`:return z(b(t,n.definitions.map(ie)),n.body);case`If`:return Hn([n.condition,n.consequent,n.alternative].map(r));case`List`:return Hn(n.items.map(r));case`Quant`:case`Fcn`:return Kn(t,n.bounds,n.body);case`SetOf`:return Kn(t,n.bounds,n.element);case`Tquant`:return z(b(t,n.names.map(e=>({kind:`Flex`,name:e}))),n.body),Rn(3);case`Choose`:case`SetSt`:{let e=n.domain&&r(n.domain),i=n.domain?T(n.name,n.domain):w(n.name,`Constant`);return Hn([z(y(t,i),n.body),...e?[e]:[]])}case`SetEnum`:case`Tuple`:return Hn(n.elements.map(r));case`Product`:return Hn(n.factors.map(r));case`FcnApp`:return Hn([n.function,...n.args].map(r));case`Arrow`:return Hn([r(n.domain),r(n.range)]);case`Rect`:case`Record`:return Hn(n.fields.map(e=>r(e.value)));case`Except`:return Hn([r(n.function),...n.specs.flatMap(e=>[...e.trail.flatMap(e=>e.kind===`Apply`?[r(e.expression)]:[]),r(e.value)])]);case`Sub`:return{...Hn([r(n.action),r(n.subscript)]),level:2};case`Tsub`:case`Fair`:return r(n.action),r(n.subscript),Rn(3);case`Case`:return Hn([...n.arms.flatMap(e=>[r(e.condition),r(e.body)]),...n.other?[r(n.other)]:[]]);case`Bang`:case`At`:throw new e.j}},Jn=`EnabledWrapper`,Yn=`CdotWrapper`,Xn="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`.",Zn="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.",Qn=`${Zn} For example, writing \`BY ExpandCdot\`.`,$n=(e,t)=>N(void 0,e,(e,n)=>t(n),()=>void 0),er=(t,n)=>{let r=S(t,n-1)?.hyp;if(!r)throw new e.j;return r},tr=e=>e.kind===`Internal`&&(e.builtin===`ENABLED`||e.builtin===`Cdot`),nr=e=>e.kind===`Opaque`&&(e.name===Jn||e.name===Yn),rr=e=>e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`Lambda`&&(tr(e.operator)||nr(e.operator)),ir=e=>e===void 0?2:Math.min(2,e),ar=e=>e===void 0?void 0:Math.max(1,e-1),or=(t,n,r,i,a)=>{let l=(e,i=a)=>or(t,n,r,e,i);if(rr(i))return i;if(i.kind===`Sub`)return{...i,action:l(i.action),subscript:l(i.subscript,ar(a))};if(i.kind===`Apply`&&i.operator.kind===`Internal`){let r=i.operator.builtin,[o,s]=i.args;if(r===`Cdot`&&i.args.length===2){if(a!==void 0&&!t.isCdot)throw n(c(i.location,`${Zn}For example, writing \`BY ExpandCdot\`.`)),new e.w(`Expr.Action`);return{...i,args:t.isCdot?[l(o,ir(a)),l(s,1)]:[l(o),l(s)]}}if(r===`ENABLED`&&i.args.length===1){if(a!==void 0&&!t.isEnabled)throw n(c(i.location,Xn)),new e.w(`Expr.Action`);return{...i,args:[t.isEnabled?l(o,ir(a)):l(o)]}}if((r===`Prime`||r===`UNCHANGED`)&&i.args.length===1)return{...i,args:[l(o,ar(a))]}}let d=i.kind===`Apply`&&i.operator.kind===`Ix`?i.operator:i;if(d.kind!==`Ix`)return N(r,i,(e,r)=>or(t,n,e,r,a),y);if(a===void 0)return i;let f=z(r,i).level,p=er(r,d.index),m=e=>`The operator \`${e}\` is declared at:\n${o(p.location)}`;if(p.kind===`Fresh`&&p.level===`Unknown`)throw n(c(i.location,`Declared operator \`${p.name}\` has unknown level and occurs within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${a}.\nIf a constant operator is substituted for this operator, then the expression that results from applying this declared operator has expression level ${f}.\n May need expansion. A declared operator cannot be expanded.\n${m(p.name)}\n and has arity: ${p.shape}`)),new e.j(`File "src/expr/e_action.ml", line 367, characters 20-26: Assertion failed`);if(f<a)return i;if(f>2||p.kind===`Fact`)throw new e.j;if(p.kind===`Flex`){if(i.kind!==`Ix`)throw new e.j;return i}if(p.kind===`Fresh`){let t=`The expression that results from applying the declared operator \`${p.name}\` has expression level ${f} within the scope of \`ENABLED\` or \`\\cdot\` where soundness requires expanding expressions of level >= ${a}. A declared operator cannot be expanded.\n${m(p.name)}\n and has level: ${Bn[p.level]}\n and arity: ${p.shape}`;throw n(c(i.location,t)),new e.C(t)}let h=p.definition;if(h.kind!==`Operator`&&h.kind!==`Bpragma`)throw new e.j;if(!t.isAutoUse){let r=t.isEnabled&&t.isCdot?["the operators `ENABLED` and `\\cdot`","the proof directives `ExpandENABLED` and `ExpandCdot`"]:t.isEnabled?["the operator `ENABLED`","`ExpandENABLED` proof directive"]:["the operator `\\cdot`","`ExpandCdot` proof directive"],a=h.body.kind===`Lambda`?h.body.body:h.body,s=`Hidden definition of operator \`${h.name}\` needs expansion for soundly expanding ${r[0]} (using rigid quantification).\nThe expansion of ${r[0]} has been activated with the ${r[1]} from the module \`TLAPS\`.\nThe operator \`${h.name}\` is defined at: \n\t${o(a.location)}\nand the operator \`${h.name}\` occurs at: \n\t${o(i.location)}\nUsing the proof directive \`AutoUSE\` from the module \`TLAPS\`, or \`BY DEF ${h.name}\` is expected to avoid this error.\n`;throw n(c(i.location,s)),new e.w(s)}n({text:`${s(i.location)}[INFO]: Auto-expanding the definition of operator: ${h.name}\n`,channel:`stdout`});let g=O(u(d.index),h.body);return l(ce(i.kind===`Apply`?se(g,i.args):g))},sr=t=>{if(t.kind===`Apply`&&t.args.length===1)return Ge(t.args[0]);if(t.kind!==`Sub`)throw new e.j;let n=Ge(t.subscript),r=t.modal===`Box`?n:_(`Neg`,[n],t);return _(t.modal===`Box`?`Disj`:`Conj`,[t.action,r],t)},cr=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[cr(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[cr(e)&r.length-1].push(e)),t=r}),t.flat()},ur=(t,n,r,i,a,o)=>{let s=e=>ur(t,n,r,i,a,e),l=r!==void 0||i!==void 0,u=(e,s)=>{let c={names:[],depth:Math.max(r?.depth??0,i?.depth??0)+1},[l,u]=s,d=[ur(t,n,r,c,a,l),...u?[ur(t,n,c,i,a,u)]:[]],f=c.names.length===0?[`r#0`]:lr(c.names);return m({kind:`Apply`,operator:e,args:[{kind:`Lambda`,params:[`_`,...f].map(e=>({name:e,shape:0})),body:d.length===1?d[0]:{kind:`List`,bullet:`And`,items:d}}]},o)};if(rr(o))return o;if(o.kind===`Apply`&&o.operator.kind===`Internal`){let r=o.operator.builtin;if(t.isEnabled&&r===`ENABLED`&&o.args.length===1||t.isCdot&&r===`Cdot`&&o.args.length===2)return u(o.operator,o.args);if(r===`ENABLED`&&l)throw n(c(o.location,Xn)),new e.w(`Expr.Action`);if(r===`Cdot`&&l)throw n(c(o.location,Qn)),new e.w(`Expr.Action`);if(r===`Prime`&&o.args.length===1){let e=ur(t,n,i,void 0,a,o.args[0]);return i?e:{...o,args:[e]}}if(r===`UNCHANGED`&&l)return s(sr(o))}if(o.kind===`Sub`&&l)return s(sr(o));if(o.kind===`Ix`){if(!r)return o;let t=er(a,o.index);if(t.kind===`Fact`)throw new e.j;if(t.kind!==`Flex`)return o;let n=`${t.name}#enabled#prime${r.depth}`;return r.names.includes(n)||r.names.push(n),m({kind:`Opaque`,name:n},o)}if(o.kind===`Apply`&&o.operator.kind===`Opaque`)throw n(c(o.location,`Named operator \`${o.operator.name}\` unexpected after anonymization.`)),new e.j(`File "src/expr/e_action.ml", line 1048, characters 12-18: Assertion failed`);return N(a,o,(e,a)=>ur(t,n,r,i,e,a),y)},dr=(t,n)=>{if(n.kind===`Apply`&&tr(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`)throw new e.j;let[i,...a]=r.params;if(i.name!==`_`)return n;let o=dr({kind:`Compose`,outer:t,inner:u(a.length)},r.body);return{kind:`Apply`,operator:n.operator,args:[{kind:`Lambda`,params:a,body:o}]}}return n.kind===`Ix`?O(t,n):n.kind===`Apply`?m(se(dr(t,n.operator),n.args.map(e=>dr(t,e))),n):N(t,n,dr,e=>p(1,e))},fr=(t,n)=>{if(n.kind===`Apply`&&tr(n.operator)){let[r]=n.args;if(n.args.length!==1||r.kind!==`Lambda`||r.params[0].name===`_`)throw new e.j;let i=n.operator.builtin===`Cdot`?Yn:Jn;return{kind:`Apply`,operator:m({kind:`Opaque`,name:i},n.operator),args:[{kind:`Lambda`,params:r.params.map((e,n)=>({name:t?e.name:`r#${n}`,shape:0})),body:fr(t,r.body)}]}}return $n(n,e=>fr(t,e))},pr=t=>{if(g(t,`Cdot`)&&t.args.length===1&&t.args[0].kind!==`Lambda`)throw new e.j;return $n(t,pr)},mr=(e,t,n,r,i,a)=>{let o=ur(i,t,void 0,void 0,n,r);return fr(a,e.expr(n,dr(u(0),o)))},hr={isEnabled:!0,isCdot:!0,isAutoUse:!0},gr=(e,t,n,r,i=hr)=>{let a=or(i,t,n,r,void 0);return pr(mr(e,t,n,a,i,!1))},_r=(t,n,r,i,a)=>{let o=(e,i)=>({kind:`Quant`,quantifier:`Exists`,bounds:e.map(e=>({name:e.name,level:`Constant`,domain:{kind:`NoDomain`}})),body:_r(t,n,b(r,e.map(re)),i,!0)}),s=e=>e===`ENABLED`?t.isEnabled:t.isCdot;if(i.kind===`Apply`&&i.args.length===1){let e=i.operator,[a]=i.args;if(a.kind===`Lambda`){if(e.kind===`Opaque`&&(t.isEnabled&&e.name===Jn||t.isCdot&&e.name===Yn))return o(a.params,a.body);if(e.kind===`Ix`&&(t.isEnabled||t.isCdot)){let t=er(r,e.index);if(t.kind===`Defn`&&t.definition.kind===`Operator`&&(t.definition.name===Jn||t.definition.name===Yn))return o(a.params,a.body)}if(tr(e)&&s(e.builtin))return o(a.params,a.body)}if(tr(e)&&s(e.builtin))return _r(t,n,r,a,!0)}if(g(i,`ENABLED`)&&a)throw n(c(i.location,Xn)),new e.w(`Expr.Action`);if(g(i,`Cdot`)&&a)throw n(c(i.location,Qn)),new e.w(`Expr.Action`);return N(r,i,(e,r)=>_r(t,n,e,r,a),y)},vr=t=>{if(t.kind===`Quant`&&t.quantifier===`Exists`){let n=t.body;if(n.kind===`List`&&n.bullet===`Or`)return vr({...n,items:n.items.map(e=>({...t,body:e}))});if(g(n,`Disj`)){if(n.args.length!==2)throw new e.j;return vr({...n,args:n.args.map(e=>({...t,body:e}))})}}return $n(t,vr)},yr=(e,t,n,r,i)=>{let a=or(i,t,n,r,void 0),o=mr(e,t,n,a,i,!0);return vr(_r(i,t,n,o,!1))},B=(e,t,n)=>({kind:`Definition`,definition:{kind:`Operator`,name:t,body:e===0?{kind:`Internal`,builtin:n}:{kind:`Lambda`,params:Array.from({length:e},(e,t)=>({name:`x${t+1}`,shape:0})),body:{kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n}))}}},whereDefined:`Builtin`,visibility:`Visible`,isLocal:!1}),br=[B(0,`Nat`,`Nat`),B(2,`+`,`Plus`),B(2,`-`,`Minus`),B(2,`*`,`Times`),B(2,`^`,`Exp`),B(2,`<`,`Lt`),B(2,`>`,`Gt`),B(2,`=<`,`Lteq`),B(2,`>=`,`Gteq`),B(2,`%`,`Remainder`),B(2,`\\div`,`Quotient`),B(2,`..`,`Range`)],xr=[...br,B(0,`Int`,`Int`),B(1,`-.`,`Uminus`)],Sr=[...xr,B(0,`Real`,`Real`),B(2,`/`,`Ratio`),B(0,`Infinity`,`Infinity`)],Cr=[B(1,`Seq`,`Seq`),B(1,`Len`,`Len`),B(2,`BSeq`,`BSeq`),B(2,`\\o`,`Cat`),B(2,`Append`,`Append`),B(1,`Head`,`Head`),B(1,`Tail`,`Tail`),B(3,`SubSeq`,`SubSeq`),B(2,`SelectSeq`,`SelectSeq`)],wr=[B(2,`Print`,`Print`),B(1,`PrintT`,`PrintT`),B(2,`Assert`,`Assert`),B(0,`JavaTime`,`JavaTime`),B(1,`TLCGet`,`TLCGet`),B(2,`TLCSet`,`TLCSet`),B(2,`:>`,`OneArg`),B(2,`@@`,`Extend`),B(1,`Permutations`,`Permutations`),B(2,`SortSeq`,`SortSeq`),B(1,`RandomElement`,`RandomElement`),B(0,`Any`,`Any`),B(1,`ToString`,`ToString`)],Tr=(e,t)=>({name:e,extendees:[],body:t,isImportant:!1,isStandard:!0}),Er=new Map([Tr(`Naturals`,br),Tr(`Integers`,xr),Tr(`Reals`,Sr),Tr(`Sequences`,Cr),Tr(`TLC`,wr)].map(e=>[e.name,e])),Dr=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:m(v(D(u(-e.axiomCount),{...e.sequent,context:e.sequent.context.slice(e.axiomCount)})),e);return e.name===void 0?[E(n,`Hidden`,`Always`,t)]:kr(e.name,n,t)}case`Mutate`:return e.mode===`Use`?e.usable.facts.map((e,n)=>E(k(n,e),`Visible`,`Always`,t)):[];case`Submod`:case`Anoninst`:return[]}},Or=e=>e.kind===`Axiom`||e.kind===`Theorem`?e.name===void 0?1:2:Dr(e).length,kr=(e,t,n)=>[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:t,location:n},whereDefined:`User`,visibility:`Visible`,isLocal:!1,location:n},E({kind:`Ix`,index:1,location:n},`Hidden`,`Always`,n)],Ar=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:Ar(e.module)}}];default:return[e]}}),jr=(t,n,r,i=/* @__PURE__ */ new Set([n.name]))=>{let a=[];for(let o of n.extendees){if(r.has(o))continue;if(i.has(o))throw new e.j(`Stack overflow`);let n=t.get(o);if(!n)throw new e.C(`Module "${o}" unknown`);a.push(...Ar(jr(t,n,r,/* @__PURE__ */ new Set([...i,o])))),r.add(o)}return{...n,body:[...a,...n.body].map(e=>e.kind===`Submod`?{...e,module:jr(t,e.module,/* @__PURE__ */ new Set)}:e)}},Mr=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&&Nr(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(Pr),locations:t,submodules:a}},Nr=e=>typeof e==`object`&&!!e&&`module`in e&&typeof e.module==`string`&&`substitutions`in e,Pr=(e,t)=>e<t?-1:+(e>t),Fr=(t,n)=>({facts:oe(t,n.facts),defs:n.defs.map(n=>{if(n.kind===`Dvar`)return n;let r=O(t,{kind:`Ix`,index:n.index});if(r.kind!==`Ix`)throw new e.C(`substitution produced bad definition`);return{...n,index:r.index}})}),Ir=(e,t)=>{switch(t.kind){case`Constants`:case`Recursives`:return[p(t.declarations.length,e),t];case`Variables`:return[p(t.names.length,e),t];case`Definition`:return[p(1,e),{...t,definition:ue(e,t.definition)}];case`Axiom`:return[p(Or(t),e),{...t,expression:O(e,t.expression)}];case`Theorem`:return[p(Or(t),e),{...t,sequent:D(e,t.sequent)}];case`Submod`:return[e,{...t,module:{...t.module,body:Lr(e,t.module.body)}}];case`Mutate`:return[t.mode===`Hide`?e:p(t.usable.facts.length,e),{...t,usable:Fr(e,t.usable)}];case`Anoninst`:return[e,{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(t=>({name:t.name,expression:O(e,t.expression)}))}}]}},Lr=(e,t)=>C(e,t,Ir)[1],Rr=(t,n,r,i)=>{try{let r=gr(t.anonymizer,t.onWarning,n,{kind:`Sequent`,sequent:i});if(r.kind!==`Sequent`)throw new e.j;return r.sequent}catch(n){if(!(n instanceof e.C)||n.failure===void 0)throw n;let a=i.active.location,c=`${n.failure}\nCould not instantiate the theorem ${r===void 0?``:`named: ${r}, `}at: ${o(a)}`;return t.onWarning({text:`${s(a)}[ERROR]${c}`,channel:`stdout`}),t.onWarning({text:c,channel:`toolboxOnly`}),{context:[],active:m({kind:`Internal`,builtin:`TRUE`},i.active)}}},zr=(e,t,n)=>{if(n.kind===`Theorem`)return{...n,sequent:Rr(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=gr(e.anonymizer,e.onWarning,t,r.body);return{...n,definition:{...r,body:i}}},Br=(e,t,n)=>C(t,n,(t,n)=>{if(n.kind===`Submod`){let[r,i]=Br(e,t,n.module.body);return[r,{...n,module:{...n.module,body:i}}]}let r=zr(e,t,n);return[b(t,Dr(r)),r]}),Vr=(t,n)=>{let r=[],i=0,a=t;for(;a.length>0;){let[t,...o]=a,s=t.kind===`Constants`?{name:t.declarations[0].name,remaining:{...t,declarations:t.declarations.slice(1)}}:t.kind===`Variables`?{name:t.names[0],remaining:{...t,names:t.names.slice(1)}}:void 0;if(s){let t=n.get(s.name);if(!t)throw new e.C(`Parameter ${s.name} has no substitute`);let r=Or(s.remaining)===0;a=Lr(d(k(i,t),u(0)),r?o:[s.remaining,...o])}else r.push(t),i+=Or(t),a=o}return r},Hr=(e,t,n)=>{let r=Array.from({length:t},(e,r)=>m({kind:`Ix`,index:t-r},{location:n})),i=Array.from({length:t},(e,t)=>m({kind:`Ix`,index:t+1},{location:n})),a=Array.from({length:e},(e,i)=>{let a=m({kind:`Ix`,index:i+t+1},{location:n});return t>0?m({kind:`Apply`,operator:a,args:r},{location:n}):a});return f([...a,...i].reverse(),u(e+t))},Ur=(e,t)=>{let n=t.map(e=>({name:e,shape:0}));return e.kind===`Lambda`?{...e,params:[...n,...e.params]}:t.length===0?e:m({kind:`Lambda`,params:n,body:e},e)},Wr=(t,n,r,i,a,o)=>{let c=e=>r===``?e:`${r}!${e}`,d=i.args.length,f=[],p=0,h=n,g=d===0,_=e=>{g||(g=!0,t.onWarning({text:e,channel:`stderr`}))};for(;h.length>0;){let[n,...r]=h;h=r;let g=e=>Ur(O(Hr(p,d,o),e),i.args);switch(n.kind){case`Definition`:{let r=n.definition;if(r.kind!==`Operator`&&r.kind!==`Bpragma`)throw new e.C(`Module.Elab.localize`);let i=n.isLocal?`${r.name}$${ot(t.salts)}`:r.name;f.push({...n,definition:{...r,name:c(i),body:g(r.body)},whereDefined:n.isLocal?`Builtin`:n.whereDefined,isLocal:n.isLocal||a}),p+=1;continue}case`Axiom`:{_(`${l(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:c(n.name),expression:g(n.expression)};f.push(e),p+=Or(e);continue}case`Theorem`:{_(`${s(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=g(m(v(n.sequent),n));f.push({...n,name:n.name===void 0?void 0:c(n.name),sequent:e.kind===`Sequent`?e.sequent:{context:[],active:e},proof:{kind:`Omitted`,omission:`Elsewhere`,location:n.location}}),p+=1;continue}case`Mutate`:n.mode===`Use`&&(h=Lr(u(-n.usable.facts.length),h));continue;case`Submod`:continue;default:throw new e.C(`Module.Elab.localize`)}}return f},Gr=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=E(e.name===void 0?k(1,e.expression):m({kind:`Ix`,index:2},e),`Visible`,`Always`,i),o=0,s=r.map(e=>{let t=o;if(o+=Or(e),e.kind!==`Theorem`)return e;let n=D(u(1),e.sequent);return{...e,sequent:{...n,context:[de(u(t),a),...n.context]},axiomCount:e.axiomCount+1}});n=Lr(u(-1),s)}return t},Kr=e=>new Set(e.body.flatMap(e=>e.kind===`Constants`?e.declarations.map(e=>e.name):e.kind===`Variables`?e.names:[])),qr=(t,n,r,i,a,o,s)=>{let c=n.get(i.module);if(!c)throw new e.C(`Module "${i.module}" unknown`);let l=Kr(c);for(let t of i.substitutions)if(!l.has(t.name))throw new e.C(`Parameter ${t.name} occurs in the statement \`INSTANCE ${i.module} WITH\`, and is not declared in the module ${i.module}`);let d=b(r,i.args.map(e=>w(e,`Unknown`))),f=new Map(i.substitutions.map(e=>[e.name,e.expression]));for(let t of[...l].sort(Pr))if(!f.has(t)){if(!x(d,t))throw new e.C(`Required parameter ${t} for module ${i.module} could not be inferred.`);f.set(t,m({kind:`Opaque`,name:t},{location:s}))}let p=new Map([...f].map(([e,n])=>[e,t.anonymizer.expr(d,n)])),h=Lr(u((d?.size??0)-(c.depth??0)),c.body.map(e=>e.kind===`Theorem`?{...e,proof:{kind:`Omitted`,omission:`Implicit`,location:e.proof.location}}:e)),[,g]=Br(t,d,h);return Gr(Wr(t,Vr(g,p),o,i,a,s))},Jr=(e,t,n)=>e===void 0?{hyps:[],sequent:t}:{hyps:[{kind:`Defn`,definition:{kind:`Operator`,name:e,body:m(v(t),{location:n}),location:n},whereDefined:{kind:`Proof`,time:`Always`},visibility:`Visible`,isLocal:!1,location:n}],sequent:D(u(1),t)},Yr=(t,n,r)=>{let i=r.instance.module;if(!t.latestModules.has(i))throw t.onWarning({text:`${l(r.instance.location)}Module ${JSON.stringify(i)} unknown\n`,channel:`toolbox`}),new e.C(`Module ${JSON.stringify(i)} unknown`,{failure:`Module.Elab.anon#defns`});let a=qr(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=Lr(u(-Or(e)),t)}return o},Xr=(e,t,n,r)=>{let i=[],a=n,o=e=>{i.push(e),a=b(a,Dr(e))},s=e=>e!==void 0&&x(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=qr(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 f=Dr(s)[0],p=x(a,t.name);if(p?.hyp.kind===`Defn`&&(p.hyp.definition.kind===`Recursive`||ge(de(u(p.depth+1),p.hyp),f))){let e=c.slice(n+1),t=Lr(d(m({kind:`Ix`,index:p.depth+1},i),u(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=Jr(c,u,i.location),f=b(b(a,d.hyps.map(e=>({...e,isConstnessUnset:!0}))),d.sequent.context),p=e.anonymizer.proof(f,l),m=r.isImportant?e.generator.simplify(ee(f),d.sequent.active,p,it(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:Xr(e,t,a,i.module)});continue}}let l={...r,body:i,depth:n?.size??0};return t.set(r.name,l),l},Zr=(e,t,n)=>{let r=[],i=[],a=Mn,o=t;for(let t of n.body)switch(t.kind){case`Theorem`:{let n=Jr(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,it(c,`Always`));r.push(...e.generator.collect(l));let u=Fn(l);i.push({...u,location:t.location}),a=Nn(a,u);let d=t.name===void 0?m(v(t.sequent),t):{kind:`Ix`,index:1,location:t.location};o=[...s,E(d,`Hidden`,`Always`,t.location)];continue}case`Submod`:{let n=Zr(e,o,t.module);r.push(...n.obligations),a=Nn(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,...Dr(t)]}return{obligations:r,summary:{...a,theorems:i}}},Qr=[`(`,`)`,`;`,`:`,`@`,`,`],$r=e=>e===` `||e===`\r`||e===` `,ei=(e,t)=>{let n={...t},r=()=>{for(;n.line<e.length;){let t=e[n.line];for(;$r(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(!Qr.includes(t[0]))return;i.push({kind:`Punct`,text:t[0]}),n.column++}}},ti=(e,t)=>e?.kind===`Punct`&&e.text===t,ni=e=>e?.kind===`String`?{kind:`String`,value:e.text}:e?.kind===`Number`?{kind:`Float`,value:Number.parseFloat(e.text)}:ti(e,`@`)?{kind:`Default`}:void 0,ri=/* @__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`]]),ii=(e,t)=>{let n=ei(e,t);if(!n)return;let r=0,i=()=>{let e=n[r];return e?.kind===`Number`?(r++,{timeout:Number.parseFloat(e.text)}):{}},a=()=>{if(!ti(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 ti(n[r],`(`)&&!a()?void 0:{name:e.text,...t}}let t=ri.get(e.text);return t===void 0?void 0:{name:t}})();if(t&&ti(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},ai=(e,t)=>{let n=ei(e,t);if(!n)return;let r=0,i=[];for(;r<n.length;){let e=n[r++];if(e.kind!==`Ident`||e.text!==`by`&&e.text!==`set`||!ti(n[r],`(`))return;r++;let t=[];for(;;){let e=n[r++];if(e?.kind!==`Ident`||!ti(n[r],`:`))return;r++;let i=ni(n[r++]);if(!i)return;if(t.push({hint:e.text,value:i}),ti(n[r],`)`))break;if(!ti(n[r],`;`))return;r++}r++,i.push(t)}return i},oi=e=>({kind:`Opaque`,name:e}),si=e=>({kind:`Tuple`,elements:e.map(oi)}),ci=(e,t)=>({kind:`Apply`,operator:{kind:`Internal`,builtin:`Eq`},args:[e,t]}),li=e=>e.map(e=>({name:e,level:`Constant`,domain:{kind:`NoDomain`}})),ui=(e,t)=>e?.kind===`Product`&&e.factors.length===t.length?e.factors:void 0,di=(e,t)=>t.map((t,n)=>({kind:`Operator`,name:t,body:{kind:`FcnApp`,function:oi(e),args:[{kind:`Num`,integer:String(n+1),fraction:``}]}})),fi=(e,t)=>e.map((e,n)=>({name:e,level:`Constant`,domain:{kind:`Domain`,expression:t[n]}})),pi=e=>({name:e.name,level:`Constant`,domain:e.domain}),mi=(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`?[pi(e)]:[]));let a=ui(i.domain,i.names);if(a)return r(fi(i.names,a));let o={kind:`Apply`,operator:{kind:`Internal`,builtin:e===`Exists`?`Mem`:`Notmem`},args:[si(i.names),i.domain]};return r(li(i.names),{kind:`List`,bullet:e===`Exists`?`And`:`Or`,items:[o,t]})},n)},hi=(e,t,n)=>{let r=`${e.kind.toLowerCase()}#${t[0]}`;return{...e,name:r,body:ui(e.domain,t)?{kind:`Let`,definitions:di(r,t),body:n}:{kind:`Quant`,quantifier:`Exists`,bounds:li(t),body:{kind:`List`,bullet:`And`,items:[ci(oi(r),si(t)),n]}}}},gi=(e,t,n)=>{let r=e.map(e=>{if(e.kind===`Name`)return{bounds:[pi(e)],definitions:[]};let t=ui(e.domain,e.names);if(t&&n)return{bounds:fi(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:di(r,e.names)};let a=`choose#${r}`;return{bounds:[i],definitions:[{kind:`Operator`,name:a,body:hi({kind:`Choose`,domain:void 0},e.names,ci(oi(r),si(e.names)))},...di(a,e.names)]}}),i=r.flatMap(e=>e.definitions);return{bounds:r.flatMap(e=>e.bounds),value:i.length===0?t:{kind:`Let`,definitions:i,body:t}}},_i=(e,t)=>{let n=gi(t,e,!0);return{kind:`SetOf`,element:n.value,bounds:n.bounds}},vi=(e,t)=>{let n=gi(e,t,!1);return{kind:`Fcn`,bounds:n.bounds,body:n.value}},yi={"=>":`Implies`,"<=>":`Equiv`,"/\\":`Conj`,"\\/":`Disj`,"~":`Neg`,"=":`Eq`,"#":`Neq`,SUBSET:`SUBSET`,UNION:`UNION`,DOMAIN:`DOMAIN`,"\\subseteq":`Subseteq`,"\\in":`Mem`,"\\notin":`Notmem`,"\\":`Setminus`,"\\cap":`Cap`,"\\cup":`Cup`,"'":`Prime`,"~>":`Leadsto`,ENABLED:`ENABLED`,UNCHANGED:`UNCHANGED`,"\\cdot":`Cdot`,"-+->":`Actplus`,"[]":`BoxTrue`,"<>":`Diamond`,TRUE:`TRUE`,FALSE:`FALSE`,BOOLEAN:`BOOLEAN`,STRING:`STRING`},bi=e=>Yt(e).name,xi=/^<(\d+|\*|\+)>([A-Za-z0-9_]*)\.*$/,Si=(e,t)=>{if(!e||!t)return e??t;let n=e.startLine<t.startLine||e.startLine===t.startLine&&e.startColumn<=t.startColumn,r=e.endLine>t.endLine||e.endLine===t.endLine&&e.endColumn>=t.endColumn;return{file:e.file,startLine:n?e.startLine:t.startLine,startColumn:n?e.startColumn:t.startColumn,endLine:r?e.endLine:t.endLine,endColumn:r?e.endColumn:t.endColumn}},Ci={Always:`[]`,Eventually:`<>`,Enabled:`ENABLED`,Unchanged:`UNCHANGED`},wi=(e,t)=>e!==void 0&&t!==void 0&&e.line===t.line&&e.column===t.column,Ti=e=>e.location.range?.start,Ei=e=>e.location.range?.end,Di=(e,t)=>{let n=e.location.range;return n&&t?{...e,location:{...e.location,range:{...n,end:t}}}:e},Oi=e=>{if(e.kind===`Apply`){let t=Yt(e.operator),n=e.args.length===2&&t.fixity.startsWith(`Infix`),r=e.args.length===1&&t.fixity===`Prefix`;if(!n&&!r)return;let i=e.args.length-1;return{operator:t,isInfix:n,operand:e.args[i],replace:t=>({...e,args:[...e.args.slice(0,i),t]})}}let t=Ci[e.kind];if(t!==void 0&&`expression`in e)return{operator:Yt(t),isInfix:!1,operand:e.expression,replace:t=>({...e,expression:t})}},ki=(e,t)=>e.high<t.low,Ai=e=>{let t=Yt(e.operator),[n,r]=e.args,i=Ei(e),a=t=>{let n=e.location.range,i=Ti(t);return{...e,args:[t,r],location:n&&i?{...e.location,range:{...n,start:i}}:e.location}},o=(e,n)=>{let r=n?Oi(e):void 0;if(!r)return{kind:`Reduced`,isFinal:!1};let s=o(r.operand,wi(Ei(r.operand),Ei(e)));return s.kind===`Attached`?{kind:`Attached`,expression:Di(r.replace(s.expression),i)}:!s.isFinal&&(ki(t,r.operator)||r.isInfix&&t.fixity===`InfixLeft`&&r.operator.fixity===`InfixLeft`&&!ki(r.operator,t))?{kind:`Reduced`,isFinal:!ki(t,r.operator)}:{kind:`Attached`,expression:Di(r.replace(a(r.operand)),i)}},s=o(n,wi(Ti(n),Ti(e)));return s.kind===`Attached`?s.expression:e},ji="use instead the class`E_visit.iter_concrete`",Mi=(e,t)=>t>0&&e[t-1].set===e[t].set,Ni=(t,n,r,i)=>{let a=n.split(`
|
|
21
|
+
`),o=e=>({file:t,startLine:e.start.line,startColumn:e.start.column,endLine:e.end.line,endColumn:e.end.column+1}),s=e=>{let t={line:e.endLine-1,column:e.endColumn-1},n=e=>e===` `||e===`\r`;for(;t.line<a.length;){let e=a[t.line];for(;n(e[t.column]);)t.column++;if(t.column<e.length)break;t.line++,t.column=0}if(!(a[t.line]??``).startsWith(`(*{`,t.column))return e;for(let n=t.line;n<a.length;n++){let r=a[n].indexOf(`}*)`,n===t.line?t.column:0);if(r!==-1)return{...e,endLine:n+1,endColumn:r+4}}return e},c=e=>e&&ii(a,{line:e.end.line-1,column:e.end.column}),l=e=>{let t=c(e),n=o(e);return t?{location:s(n),method:t}:{location:n}},u=(e,t)=>{let n=c(t);return n?m({kind:`With`,expression:e,method:n},e):e},d=(e,n)=>({file:t,startLine:e.line,startColumn:e.column,endLine:e.line,endColumn:e.column+n}),f=e=>e.range?o(e.range):d(e,1),p=(e,t)=>{let n=bi(e),r=yi[n];return m(r?{kind:`Internal`,builtin:r}:{kind:`Opaque`,name:n},{location:t})},h=(e,t,n,r)=>{if(e.startsWith(`<`)){let t=m({kind:`Opaque`,name:e},{location:n});return m({kind:`Bang`,expression:t,selectors:[]},{location:n})}let i=yi[e];if(i&&t.length===0)return m({kind:`Internal`,builtin:i},{location:n});let a=e.split(`!`);if(a.length===1){let r=m({kind:`Opaque`,name:e},{location:n});return t.length===0?r:m({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=m({kind:`Opaque`,name:a[0]},{location:n});return m({kind:`Bang`,expression:o[0]===0?l:m({kind:`Apply`,operator:l,args:c(0)},{location:n}),selectors:a.slice(1).map((e,t)=>({kind:`Label`,label:bi(e),args:c(t+1)}))},{location:n})},g=(t,n)=>t.map((r,i)=>{if(r.pattern.kind===`Tuple`)throw new e.C(`Unexpected tuple declaration`,{failure:ji});return{name:r.pattern.name,level:`Constant`,domain:Mi(t,i)?{kind:`Ditto`}:{kind:`Domain`,expression:b(r.set,n)}}}),_=(e,t)=>e.map((n,r)=>{let i=b(n.set,t);return n.pattern.kind===`Tuple`?{kind:`Tuple`,names:n.pattern.names,domain:i}:{kind:`Name`,name:n.pattern.name,domain:Mi(e,r)?{kind:`Ditto`}:{kind:`Domain`,expression:i}}}),v=(t,n)=>{if(!i)throw new e.C(`Unexpected tuple declaration`,{failure:ji});return m(t,{location:n})},y=e=>e.some(e=>e.pattern.kind===`Tuple`),b=(t,n)=>{let r=f(t.location),i=e=>b(e,n),o=(e,t)=>e.length===2?Si(e[0].location,e[1].location):e.length!==1||!e[0].location?r:t===`Prefix`?Si({...r,endLine:r.startLine,endColumn:r.startColumn+1},e[0].location):t===`Postfix`?Si({...r,startLine:r.endLine,startColumn:r.endColumn-1},e[0].location):r,s=(e,t)=>m({kind:`Apply`,operator:{kind:`Internal`,builtin:e},args:[t]},{location:o([t],`Prefix`)});switch(t.kind){case`Number`:return m({kind:`Num`,integer:t.text??String(t.value),fraction:``},{location:r});case`Decimal`:{let[e,n]=t.text.split(`.`);return m({kind:`Num`,integer:e,fraction:n},{location:r})}case`String`:{let e=/"((?:[^"\\]|\\.)*)"$/.exec((a[r.endLine-1]??``).slice(0,r.endColumn-1));return m({kind:`String`,value:e?.[1]??t.value},{location:r})}case`Identifier`:return h(t.name,[],r);case`Apply`:{if(t.args.length===2){let e=Ai(t);if(e!==t)return i(e)}let e=t.args.map(i),n=Yt(t.operator);return n.fixity===`Nonfix`?h(t.operator,e,r,t.argumentCounts):m({kind:`Apply`,operator:p(t.operator,void 0),args:e},{location:o(e,n.fixity)})}case`OperatorReference`:return p(t.operator,r);case`Lambda`:return m({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 m({kind:`List`,bullet:t.kind,items:e},{location:r});let n=t.kind===`And`?`Conj`:`Disj`;return e.reduce((e,t)=>m({kind:`Apply`,operator:{kind:`Internal`,builtin:n},args:[e,t]},{location:Si(e.location,t.location)}))}case`Prime`:{let e=i(t.expression);return m({kind:`Apply`,operator:{kind:`Internal`,builtin:`Prime`},args:[e]},{location:o([e],`Postfix`)})}case`Unchanged`:return s(`UNCHANGED`,i(t.expression));case`Enabled`:return s(`ENABLED`,i(t.expression));case`If`:return m({kind:`If`,condition:i(t.condition),consequent:i(t.consequent),alternative:i(t.alternative)},{location:r});case`Case`:return m({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 m({kind:`Let`,definitions:[...t.definitions,...t.instances??[]].sort((e,t)=>e.location.line-t.location.line||e.location.column-t.location.column).map(e=>x(e,n)),body:i(t.body)},{location:r});case`Forall`:case`Exists`:return y(t.bounds)?v(mi(t.kind,_(t.bounds,n),i(t.body)),r):m({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?m({kind:`Tquant`,quantifier:n,names:t.names,body:e},{location:r}):m({kind:`Quant`,quantifier:n,bounds:li(t.names),body:e},{location:r})}case`Choose`:return t.pattern.kind===`Tuple`?v(hi({kind:`Choose`,domain:t.set&&i(t.set)},t.pattern.names,i(t.body)),r):m({kind:`Choose`,name:t.pattern.name,domain:t.set&&i(t.set),body:i(t.body)},{location:r});case`SetEnumeration`:return m({kind:`SetEnum`,elements:t.elements.map(i)},{location:r});case`SetFilter`:return t.bound.pattern.kind===`Tuple`?v(hi({kind:`SetSt`,domain:i(t.bound.set)},t.bound.pattern.names,i(t.predicate)),r):m({kind:`SetSt`,name:t.bound.pattern.name,domain:i(t.bound.set),body:i(t.predicate)},{location:r});case`SetMap`:return y(t.bounds)?v(_i(i(t.expression),_(t.bounds,n)),r):m({kind:`SetOf`,element:i(t.expression),bounds:g(t.bounds,n)},{location:r});case`Tuple`:return m({kind:`Tuple`,elements:t.elements.map(i)},{location:{...r,startLine:r.endLine,startColumn:r.endColumn-2}});case`FunctionConstruction`:return y(t.bounds)?v(vi(_(t.bounds,n),i(t.body)),r):m({kind:`Fcn`,bounds:g(t.bounds,n),body:i(t.body)},{location:r});case`FunctionSet`:return m({kind:`Arrow`,domain:i(t.domain),range:i(t.range)},{location:r});case`Record`:case`RecordSet`:return m({kind:t.kind===`Record`?`Record`:`Rect`,fields:t.fields.map(e=>({name:e.name,value:i(e.value)}))},{location:r});case`Except`:return m({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 m({kind:`At`,isExcept:n},{location:r});case`Bracket`:throw new e.C(`Unexpected [ without a function or subscript`);case`FunctionApplication`:return m({kind:`FcnApp`,function:i(t.function),args:t.args.map(i)},{location:r});case`FieldAccess`:return m({kind:`Dot`,expression:i(t.record),field:t.field},{location:r});case`Product`:return m({kind:`Product`,factors:t.factors.map(i)},{location:r});case`Always`:case`Eventually`:{let e=t.expression;return t.kind===`Always`&&e.kind===`BoxAction`?m({kind:`Tsub`,modal:`Box`,action:i(e.action),subscript:i(e.subscript)},{location:r}):t.kind===`Eventually`&&e.kind===`AngleAction`?m({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 m({kind:`Sub`,modal:t.kind===`BoxAction`?`Box`:`Dia`,action:i(t.action),subscript:i(t.subscript)},{location:r});case`WeakFairness`:case`StrongFairness`:return m({kind:`Fair`,fairness:t.kind===`WeakFairness`?`Weak`:`Strong`,subscript:i(t.subscript),action:i(t.action)},{location:r});case`Label`:return m({kind:`Parens`,expression:i(t.body),form:{kind:`Nlabel`,label:t.name,names:t.params}},{location:r});case`Subexpression`:{let[n,...a]=t.selectors;if(n.kind!==`Name`)throw new e.C(`Unexpected subexpression reference`);let o=m({kind:`Opaque`,name:n.name},{location:r}),s=n.args.length===0?o:m({kind:`Apply`,operator:o,args:n.args.map(i)},{location:r});return m({kind:`Bang`,expression:s,selectors:a.map(e=>{switch(e.kind){case`Name`:return{kind:`Label`,label:bi(e.name),args:e.args.map(i)};case`Operand`:return e.operand===`<<`?{kind:`Left`}:e.operand===`>>`?{kind:`Right`}:{kind:`Number`,value:e.operand};case`Bound`:return{kind:`Instance`,args:e.args.map(i)};case`At`:return{kind:`At`};case`Colon`:return{kind:`Down`}}})},{location:r})}}},ee=e=>({location:o(e.definitionRange??e.instanceRange),args:e.params.map(e=>e.name),module:e.module,substitutions:e.substitutions.map(e=>({name:bi(e.name),expression:b(e.expression,!1)}))}),x=(t,n=!1)=>{let r=f(t.location);if(t.kind===`Instance`){if(t.name===void 0)throw new e.C(`Unexpected keyword INSTANCE`);return{kind:`Instance`,name:t.name,instance:ee(t),location:r}}let i=t.kind===`Operator`&&t.params.length===1&&t.name===`-`?`-.`:bi(t.name),o=b(t.body,n);if(t.kind===`Function`&&y(t.bounds))return{kind:`Operator`,name:i,body:v(vi(_(t.bounds,n),o),r),location:r};if(t.kind===`Function`){let e=g(t.bounds,n);return{kind:`Operator`,name:i,body:m({kind:`Fcn`,bounds:e,body:o},{location:r}),location:r}}let s=t.params.length===0?o:m({kind:`Lambda`,params:t.params.map(e=>({name:bi(e.name),shape:e.arity,...e.location&&{location:d(e.location,e.name.length)}})),body:o},{location:r}),c=t.location.range?.end,l=c&&ai(a,{line:c.line-1,column:c.column});return l?{kind:`Bpragma`,name:i,body:s,methods:l,location:r}:{kind:`Operator`,name:i,body:s,location:r}},S=e=>{let t=f(e.location);return e.level===`Variable`?{kind:`Flex`,name:e.name,location:t}:{kind:`Fresh`,name:e.name,shape:e.arity,level:e.level,domain:e.set&&b(e.set,!1),domainVisibility:`Visible`,location:t}},C=e=>e.kind===`AssumeProve`?{context:e.assumptions.map(e=>{if(e.kind===`NewSymbol`)return S(e);let t=e.kind===`AssumeProve`?m({kind:`Sequent`,sequent:C(e)},{location:f(e.location)}):te(e);return E(t,`Visible`,`Now`,t.location)}),active:b(e.conclusion,!1)}:{context:[],active:b(e,!1)},te=e=>{if(e.kind!==`Label`||e.params.length>0)return b(e,!1);let t=f(e.location);return m({kind:`Parens`,expression:b(e.body,!1),form:{kind:`Xlabel`,label:e.name,indices:[]}},{location:t})},w=t=>{if(t.kind===`ModuleFact`)throw new e.k(`MODULE facts in proof obligations are not supported`);let n=b(t,!1);return n.kind===`Bang`&&n.selectors.length===0?n.expression:n},T=t=>{let n=f(t.location);if(t.kind===`ModuleFact`)return{kind:`Dvar`,name:t.name,location:n};if(t.kind===`Identifier`)return{kind:`Dvar`,name:bi(t.name),location:n};if(t.kind===`OperatorReference`)return{kind:`Dvar`,name:bi(t.operator),location:n};throw new e.k(`This DEF clause in proof obligations is not supported`)},ne=e=>({facts:e.facts.map(w),defs:e.defs.map(T)}),re=(e,t)=>e?.[2]?{kind:`Named`,level:t,label:e[2],isAnonymous:!1}:{kind:`Unnamed`,level:t,id:ot(r)},ie=(e,t,n)=>{if(!e)return{kind:`Omitted`,omission:`Implicit`,location:n};switch(e.kind){case`Obvious`:return{kind:`Obvious`,...l(e.keyword)};case`Omitted`:return{kind:`Omitted`,omission:`Explicit`,location:o(e.keyword)};case`By`:return{kind:`By`,usable:ne(e),isOnly:e.isOnly,location:o(e.keyword),step:{kind:`Unnamed`,level:t,id:0},method:c(e.location.range)};case`Steps`:{let n=e.steps.map(e=>xi.exec(e.token)),r=n[0],i=r&&r[1]!==`*`&&r[1]!==`+`?Number(r[1]):t,a=e.steps.slice(0,-1).map((e,t)=>oe(e,re(n[t],i),i)),s=e.steps[e.steps.length-1],c=re(n[n.length-1],i),l=o(s.head),u=ie(s.proof,i+1,l),d={proof:u,location:Si(l,u.location),step:c};return{kind:`Steps`,steps:a,qed:d,location:a.reduce((e,t)=>Si(e,t.location),d.location),step:d.step}}}},ae=e=>Si(o(e.keyword),e.defs.length>0?f(e.defs[e.defs.length-1].location):void 0),oe=(t,n,r)=>{let i=o(t.head),a=t.body,s=e=>{let a=ie(t.proof,r+1,i);return{...e(a),location:Si(i,a.location),step:n}},u=e=>({...e,...l(t.head),step:n});switch(a.kind){case`Use`:case`Hide`:{let e=Si(o({...t.head,end:t.head.start}),ae(a)),r=ne(a);return a.kind===`Use`?{kind:`Use`,usable:r,isOnly:a.isOnly,location:e,step:n,method:c(a.location.range)}:{kind:`Hide`,usable:r,location:e,step:n}}case`Instance`:throw new e.C(`Unexpected keyword INSTANCE`);case`Define`:return{kind:`Define`,definitions:a.definitions.map(e=>x(e)),location:i,step:n};case`Have`:return u({kind:`Have`,expression:b(a.expression,!1)});case`Take`:return u({kind:`Take`,bounds:a.names.length>0?li(a.names):g(a.bounds,!1)});case`Witness`:return u({kind:`Witness`,expressions:a.expressions.map(e=>b(e,!1))});case`Pick`:{let e=a.names.length>0?li(a.names):g(a.bounds,!1),t=b(a.body,!1);return s(n=>({kind:`Pick`,bounds:e,expression:t,proof:n}))}case`Case`:{let e=b(a.expression,!1);return s(t=>({kind:`Pcase`,expression:e,proof:t}))}case`Assert`:{let e=C(a.statement);return s(t=>a.isSuffices?{kind:`Suffices`,sequent:e,proof:t}:{kind:`Assert`,sequent:e,proof:t})}case`Qed`:throw new e.k(`QED in the middle of a proof`)}},se=e=>({name:e.name,extendees:e.extends,extendeeLocations:e.extendsRanges.map(o),isImportant:!1,location:f(e.location),body:e.units.map(e=>{switch(e.kind){case`Constants`:case`Recursive`:return{kind:e.kind===`Constants`?`Constants`:`Recursives`,declarations:e.declarations.map(e=>({name:bi(e.name),shape:e.arity})),location:f(e.declarations[0].location)};case`Variables`:return{kind:`Variables`,names:e.declarations.map(e=>e.name),location:f(e.declarations[0].location)};case`Definition`:return{kind:`Definition`,definition:x(e.definition),whereDefined:`User`,visibility:`Hidden`,isLocal:e.definition.isLocal,location:f(e.definition.location)};case`Instance`:{let t=e.instance,n=f(t.location);return t.name===void 0?{kind:`Anoninst`,instance:ee(t),isLocal:t.isLocal,location:n}:{kind:`Definition`,definition:x(t),whereDefined:`User`,visibility:`Hidden`,isLocal:t.isLocal,location:o(t.instanceRange)}}case`Assumption`:return{kind:`Axiom`,name:e.assumption.name,expression:u(b(e.assumption.expression,!1),e.assumption.location.range),location:f(e.assumption.location)};case`Theorem`:{let t=e.theorem,n=f(t.location),r=s(n),i=C(t.statement);return{kind:`Theorem`,name:t.name,sequent:{...i,active:u(i.active,t.statement.location.range)},axiomCount:0,proof:ie(t.proof,0,{...r,startLine:r.endLine,startColumn:r.endColumn}),location:n}}case`Use`:return{kind:`Mutate`,mode:e.use.kind,usable:ne(e.use),location:ae(e.use)};case`Module`:return{kind:`Submod`,module:{...se(e.module),isImportant:!0}}}})});return{convertModule:se}},Pi={start:0,end:1/0},Fi=/-{4,} *MODULE/,Ii=`Unexpected EOF`,Li=e=>e?`${e.startLine}:${e.startColumn}:${e.endLine}:${e.endColumn}`:``,Ri=e=>{let n=t.nt(e),r=e.split(`
|
|
22
|
+
`),i=n.at(-1)?.line??r.length,a=r.slice(0,i-1).reduce((e,t)=>e+t.length+1,0)+r[i-1].indexOf(`====`),o=e.indexOf(` `,e.search(Fi));if(o===-1||o>=a)return;let s=e.slice(0,o).split(`
|
|
23
|
+
`).length,c=o-e.lastIndexOf(`
|
|
24
|
+
`,o-1),l=n.findLast(e=>e.kind!==`End`&&(e.line<s||e.line===s&&e.column<c));return{offset:o,line:s,column:c,end:{reason:Ii,line:l?.line??s,column:l?l.endColumn+1:c,isEnd:!0}}},zi=t=>{try{return t()}catch(t){if(!(t instanceof e.D)||!t.failure)throw t;return t.failure}},Bi=e=>typeof e==`object`&&!!e&&`reason`in e,Vi=e=>{let n=zi(()=>Ri(e));if(Bi(n))return[n];let r=zi(()=>t.A(n?e.slice(0,n.offset):e));return n&&(!Bi(r)||r.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:n.line,column:n.column,isEnd:!1},Bi(r)&&r.reason===Ii?r:n.end]:Bi(r)?[r]:r},Hi=(t,n,r,i,a)=>{if(!Fi.test(t.source))throw new e.C(`No tokens in file`);let o=Vi(t.source);if(Array.isArray(o)){o.forEach(e=>{let n=`File ${JSON.stringify(t.file)}, line ${e.line}, character ${e.column}\n${e.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`})});let n=`Could not parse ${JSON.stringify(t.file)} successfully.`;throw i({text:`${a}Error: ${n}`,channel:`stderr`}),new e.C(n,{failure:`Module.Parser.parse_file`})}let s=Ni(t.file,t.source,n,r).convertModule(o),c=t.file.slice(t.file.lastIndexOf(`/`)+1),u=c.replace(/\.tla$/,``);return s.name===u?s:(i({text:`${l(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:u})},Ui=t=>{let n=new Map([...t].map(([e,t])=>[e,Mr(t).dependencies])),r=/* @__PURE__ */ new Set,i=[],a=o=>{if(r.has(o))return;r.add(o);let s=t.get(o);if(!s)throw new e.C(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(Pr).forEach(a),i},Wi=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${i(t)}`)],Gi=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?i({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...Wi(`missing`,e.absent,t),...Wi(`omitted`,e.omitted,n),` ====`]},Ki=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...Gi(t,e.missing,e.omitted)],missing:e.missing+t.absent.length,omitted:e.omitted+t.omitted.length},{lines:[],missing:0,omitted:0});return[`---- summary of module ${JSON.stringify(e.name)} ----`,` obligations_count = ${t.total}`,...t.absent.length>0?[` missing_proofs_count = ${t.absent.length}`]:[],...t.omitted.length>0?[` omitted_proofs_count = ${t.omitted.length}`]:[],...n.lines,`====`].join(`
|
|
25
|
+
`)},qi=(t,n,r={})=>{let i=r.lines??Pi,a=r.onWarning??(()=>{}),o={value:0},l=new Map(Er);t.forEach(e=>{let t={...Hi(e,o,!0,a,`File "<unknown>":
|
|
26
|
+
`),isImportant:!0};l.set(t.name,t)});let u=[...l.values()].sort((e,t)=>Pr(e.name,t.name)),d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<u.length;e++){let t=Mr(u[e]);t.submodules.forEach((e,t)=>{f.add(t),l.has(t)||l.set(t,e)});for(let e of t.dependencies){if(l.has(e)&&!Er.has(e))continue;let r=n(e);if(!r){!l.has(e)&&!d.has(e)&&d.set(e,t.locations.get(e));continue}let i=Hi(r,o,!1,a,s(t.locations.get(e)));l.set(e,i),u.push(i)}}let p=[...d.keys()].filter(e=>!f.has(e)).sort(Pr);if(p.forEach(e=>a(c(d.get(e),`Unknown module ${JSON.stringify(e)}`))),p.length>0)throw new e.C(`Unknown module ${JSON.stringify(p[0])}`,{failure:`Module.Parser.load_module`});let m={anonymizer:ut(o,(e,t)=>Yr(m,e,t),a),generator:Ln(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},h=Ui(l).map(e=>e.isStandard?e:jr(l,e,/* @__PURE__ */ new Set)),g=new Map(h.map(e=>[e.name,e]));return h.flatMap(e=>{if(e.isStandard)return[];let t=Xr(m,g,void 0,e);if(!e.isImportant)return[];let n=Zr(m,[],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${fn(e.sequent)}\n`;return[{id:t+1,location:Li(n),locus:n,text:r,kind:e.kind,sequent:e.sequent,method:e.method}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Ji=async t=>{let n=[],r=[],i=/* @__PURE__ */ new Map,a=[],o={failure:void 0},s=()=>{for(;a.length>0&&r.length>0;){let e=r.reduce((e,t,n)=>t.priority<r[e].priority?n:e,0),[t]=r.splice(e,1),o=a.pop()??0;i.set(o,t),n[o].postMessage(t.request)}},c=(t,n)=>{let r=n,o=i.get(t);i.delete(t),a.push(t),`verdict`in r&&o?.resolve(r),`error`in r&&o?.reject(new e.w(r.error)),s()},l=e=>{o.failure||(o.failure={reason:e},[...r.splice(0),...i.values()].forEach(t=>t.reject(e)),i.clear(),n.forEach(e=>e.terminate()))};return n.push(...await Promise.all(Array.from({length:t},(t,n)=>e.r(new URL(`./prove-worker.js`,require("url").pathToFileURL(__filename).href),e=>c(n,e),l)))),a.push(...n.keys()),{decide:(e,t,n,i)=>new Promise((a,c)=>{if(o.failure)return c(o.failure.reason);r.push({request:{prover:e,text:t,timeLimitMs:n.timeLimitMs},priority:i,resolve:a,reject:c}),s()}),terminate:l}},Yi={"!":`excl_`,"#":`hash_`,$:`doll_`,"%":`perc_`,"&":`ampe_`,"'":`quot_`,"(":`lpar_`,")":`rpar_`,"*":`star_`,"+":`plus_`,"-":`dash_`,".":`peri_`,"/":`slas_`,":":`colo_`,"<":`less_`,"=":`equa_`,">":`more_`,"?":`ques_`,"@":`atsi_`,"[":`lbrk_`,"\\":`bksl_`,"]":`rbrk_`,"^":`care_`,_:`unde_`,"|":`vert_`,"~":`tild_`},Xi=new Set((/* @__PURE__ */ `All Append Bijections Case CaseArm CaseOther Char Choice EnumFuncSet Ex Fcn FuncSet INTER Id.Image Injections Injective InjectiveOn Int Inverse Len Let Monotonic Nat Nibble Not PeanoAxioms.Pred Product Range Seq String Succ Surjections Surjective TYPE Trueprop Zero abs addElt addnat.all antisymmetric any aprop arbitrary args arith_add asms bAll bChoice bEx boolify c cap cargs.case_arm case_arms cases_conj cases_equal cases_forall cases_implies char cidts classes cond.conj conjunction converse cs cup default diff diffnat disj div divmodNat divmod_rel domrng.domrngs dummy dummy_pattern dvd emptySeq eq equivalence except extend fapply float_const.float_token fun geq gfp greater id idt idts iff imp in index infinity irreflexive isAFcn isASeq.isBool isNeg isPos itself leq less letbind letbinds lfp logic longid minus mod mult multnat.natInterval num num_const oneArg prod prop psubset psupset pttrn pttrns reflexive rel_comp.rel_domain rel_image rel_range setOfAll setOfPairs setminus sgn sort sort_constraint struct.subsetOf subseteq symmetric term tid tpl transitive tvar type types upair upto var xcpt xnum.xstr.ML ML_command ML_export ML_file ML_file_debug ML_file_no_debug ML_prf ML_val ROOTS_file.SML_export SML_file SML_file_debug SML_file_no_debug SML_import abbreviation abbrevs alias also.and apply apply_end assume assumes attribute_setup axiomatization back begin bibtex_file binder.bundle by case chapter class class_deps code_datatype compile_generated_files consider.constrains consts context corollary declaration declare default_sort defer define defines.definition done end experiment export_files export_generated_files export_prefix external_file.external_files extract extract_type finally find_consts find_theorems fix fixes for from.full_prf generate_file global_interpretation guess have help hence hide_class hide_const.hide_fact hide_type if imports in include includes including infix infixl infixr instance.instantiation interpret interpretation is judgment keywords lemma lemmas let local_setup locale.locale_deps method_setup moreover named_theorems next no_notation no_syntax no_translations.no_type_notation nonterminal notation note notepad notes obtain obtains oops open opening oracle.output overloaded overloading paragraph parse_ast_translation parse_translation pervasive prefer.premises presume prf print_ML_antiquotations print_abbrevs print_antiquotations.print_ast_translation print_attributes print_bundles print_cases print_classes print_codesetup.print_commands print_context print_definitions print_defn_rules print_facts print_interps.print_locale print_locales print_methods print_options print_rules print_simpset print_state.print_statement print_syntax print_term_bindings print_theorems print_theory print_trans_rules.print_translation private proof prop proposition qed qualified realizability realizers rewrites.schematic_goal section setup show shows simproc_setup sorry structure subclass subgoal sublocale.subparagraph subsection subsubsection supply syntax syntax_declaration term text text_raw then.theorem theory thm thm_deps thm_oracles thus thy_deps translations txt typ type_alias.type_notation type_synonym typed_print_translation typedecl ultimately unbundle unchecked.unfolding unused_thms using welcome when where with write.O max status`.split(`.`)).join(` `).split(` `)),Zi=e=>/^[A-Za-z]$/.test(e),Qi=t=>{if(/^[A-Za-z0-9]$/.test(t))return;let n=Yi[t];if(n===void 0)throw new e.j;return n},$i=e=>{let t=[...e];return Zi(t[0]??``)&&Zi(t.at(-1)??``)&&t.every(e=>Qi(e)===void 0)&&!Xi.has(e)?e:`a_${t.map(e=>Qi(e)??e).join(``)}a`},ea={Leadsto:[`Leadsto`,2],ENABLED:[`ENABLED`,1],Cdot:[`\\cdot`,2],Actplus:[`-+->`,2],BoxTrue:[`[]`,1],BoxFalse:[`[]`,1],Diamond:[`<>`,1]},ta=(t,n,r)=>{if((t===`Prime`||t===`StrongPrime`||t===`UNCHANGED`)&&n===1)return new e.j;let i=ea[t];return i&&i[1]===n?new e.w(`Unsupported operator \`${i[0]}\`.\n`):new e.w(r)},na=(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:k(1,e.domain.expression)}}:e),body:n,location:n.location}}},ra=(t,n)=>{let r=t.stack.length;try{return n()}catch(n){if(!(n instanceof e.k))throw n;return Wt(t,t.stack.length-r),n}},ia=e=>`is${$i(e)}`,aa={TRUE:`TRUE`,FALSE:`FALSE`,STRING:`STRING`,BOOLEAN:`BOOLEAN`,Nat:`Nat`,Int:`Int`,Real:ia(`Real`),Infinity:ia(`Infinity`),Any:`Any`},oa={Neg:`~`,DOMAIN:`DOMAIN`,SUBSET:`SUBSET`,UNION:`UNION`},sa={Implies:`\\<Rightarrow>`,Equiv:`\\<Leftrightarrow>`,Conj:`\\<and>`,Disj:`\\<or>`,Eq:`=`,Neq:`\\<noteq>`,Subseteq:`\\<subseteq>`,Mem:`\\<in>`,Notmem:`\\<notin>`,Setminus:`\\\\`,Cap:`\\<inter>`,Cup:`\\<union>`,OneArg:`:>`,Extend:`@@`},ca={Plus:[`addint`,2],Minus:[`subint`,2],Uminus:[`minus`,1],Times:[`mult`,2],Ratio:[ia(`/`),2],Quotient:[ia(`\\div`),2],Remainder:[ia(`%`),2],Exp:[ia(`^`),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:[ia(`\\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=>` "${ia(e[0])}" :: ${e[1]===0?`c`:`"[${Array(e[1]).fill(`c`).join(`,`)}] => c"`}`),``].join(`
|
|
27
|
+
`),ua=e=>{let t=Number.parseInt(e,10);return`${`succ[`.repeat(t)}0${`]`.repeat(t)}`},da=(e,t)=>[`(* automatically generated -- do not edit manually *)`,`theory ${e} imports Constant Zenon begin`,...t?[`ML_command \\<open> writeln ("*** TLAPS PARSED\\n"); \\<close>`]:[],la],fa=t=>{let n=Vt(),r=e=>Ut(n,$i(e)),i=()=>Ut(n,``),a=(e,t)=>{let i=t(r(e));return Wt(n,1),i},o=e=>`(${p(e)})`,s=e=>e.map(o).join(`, `),c=(e,t)=>`(${e} (${s(t)}))`,l=(t,n)=>{let r=aa[t];if(r!==void 0&&n.length===0)return r;let i=oa[t];if(i!==void 0&&n.length===1)return`(${i} ${o(n[0])})`;let a=sa[t];if(a!==void 0&&n.length===2)return`(${o(n[0])} ${a} ${o(n[1])})`;let s=ca[t];if(s&&s[1]===n.length)return c(s[0],n);if(t===`Unprimable`&&n.length===1)return o(n[0]);throw t===`Irregular`&&n.length===1?new e.k(`Irregular`):ta(t,n.length,`Backend.Isabelle.pp_apply`)},u=(t,i)=>{switch(t.kind){case`Ix`:{let r=Ht(n,t.index);if(t.index<=0||r===void 0)throw new e.j;return i.length===0?r:`(${r} (${s(i)}))`}case`Opaque`:{let e=$i(t.name);return i.length===0?`(${e} :: c)`:`(${e} (${s(i)}) :: c)`}case`Internal`:return l(t.builtin,i);case`Lambda`:{let e=`\\<lambda> ${t.params.map(e=>`${r(e.name)} `).join(``)}. ${o(t.body)}`;return Wt(n,t.params.length),e}default:throw new e.j}},d=(t,n,r)=>{if(n.length===0)return p(r);let i=na(t,n,r),s=t===`Forall`?`\\<forall>`:`\\<exists>`;if(i.first.domain.kind===`NoDomain`)return a(i.first.name,e=>`${s}${e} : ${o(i.inner)}`);if(i.first.domain.kind!==`Domain`)throw new e.j;let c=o(i.first.domain.expression);return a(i.first.name,e=>`${s} ${e} \\<in> ${c} : ${o(i.inner)}`)},f=t=>{if(t.context.length===0)return o(t.active);let r=t.context[0],s=()=>f({context:t.context.slice(1),active:t.active});switch(r.kind){case`Flex`:return a(r.name,e=>`(\\<And> ${e} ${e}'.${s()})`);case`Fresh`:{if(r.domain&&r.domainVisibility===`Visible`){let e=o(r.domain);return a(r.name,t=>`(\\<And> ${t} :: c. ${t} \\<in> ${e} \\<Longrightarrow> ${s()})`)}let e=`${`c => `.repeat(r.shape)}c`;return a(r.name,t=>`(\\<And> ${t} :: ${e}. ${s()})`)}case`Fact`:{let e=r.visibility===`Visible`?o(r.expression):void 0;i();let t=e?`(${e} \\<Longrightarrow> ${s()})`:s();return Wt(n,1),t}case`Defn`:throw new e.k(`Inner definition`)}},p=t=>{switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return u(t,[]);case`Apply`:return u(t.operator,t.args);case`Bang`:throw new e.w(`Backend.Isabelle.module`);case`Sequent`:return f(t.sequent);case`With`:case`Parens`:return p(t.expression);case`Let`:throw new e.k(`LET`);case`List`:return t.bullet===`Refs`&&t.items.length===0?`TRUE`:t.bullet===`Refs`&&t.items.length===1?p(t.items[0]):t.items.map(o).join(t.bullet===`Or`?` | `:` & `);case`If`:return`cond(${o(t.condition)}, ${o(t.consequent)}, ${o(t.alternative)})`;case`Quant`:return d(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.k(t.quantifier===`Forall`?`\\\\AA`:`\\\\EE`);case`Choose`:{if(!t.domain)return a(t.name,e=>`Choice(%${e}. ${o(t.body)})`);let e=o(t.domain);return a(t.name,n=>`bChoice(${e}, %${n}. ${o(t.body)})`)}case`SetSt`:{let e=o(t.domain);return a(t.name,n=>`subsetOf(${e}, %${n}. ${o(t.body)})`)}case`SetOf`:{if(t.bounds.length===0)throw new e.j;let n=t.bounds[0];if(t.bounds.length!==1||n.domain.kind!==`Domain`)throw new e.k(`SetOf (multiple declared constants)`);let r=o(n.domain.expression);return a(n.name,e=>`setOfAll(${r}, %${e}. ${o(t.element)})`)}case`SetEnum`:return`{${s(t.elements)}}`;case`Fcn`:{let n=t.bounds[0];if(t.bounds.length!==1)throw new e.k(`function (multiple declared constants)`);if(n.domain.kind===`Ditto`)throw new e.j;let r=n.domain.kind===`Domain`?o(n.domain.expression):void 0;return a(n.name,e=>`[${r===void 0?e:` ${e} \\<in> ${r} `} \\<mapsto> ${o(t.body)}]`)}case`FcnApp`:{let e=o(t.function);return t.args.length===1?`fapply (${e}, ${o(t.args[0])})`:`fapply (${e}, <<${s(t.args)}>>)`}case`Arrow`:return`[${o(t.domain)} \\<rightarrow> ${o(t.range)}]`;case`Rect`:return`[${t.fields.map(e=>`''${e.name}'' : ${o(e.value)}`).join(`, `)}]`;case`Record`:return`(${t.fields.map(e=>`(''${e.name}'' :> ${o(e.value)})`).join(` @@ `)})`;case`Except`:{let e=t.specs.map(e=>`!${e.trail.map(e=>e.kind===`Dot`?`[''${e.field}'']`:`[${o(e.expression)}]`).join(``)} = ${o(e.value)}`);return`[${o(t.function)} EXCEPT ${e.join(`, `)}]`}case`Dot`:return`fapply (${o(t.expression)}, (''${t.field}''))`;case`Tuple`:return`<<${s(t.elements)}>>`;case`Product`:return t.factors.length===2?`(${o(t.factors[0])} \\<times> ${o(t.factors[1])})`:`Product(\\<langle>${s(t.factors)}\\<rangle>)`;case`Sub`:case`Tsub`:{let e=t.kind===`Sub`?`sub`:`tsub`;return`${t.modal===`Box`?ia(`a'box'${e}`):`a'dia'${e}`}(${o(t.action)},${o(t.subscript)})`}case`Fair`:return`${ia(t.fairness===`Weak`?`a'wf`:`a'sf`)}(${o(t.subscript)},${o(t.action)})`;case`Case`:{let e=s(t.arms.map(e=>e.condition)),n=s(t.arms.map(e=>e.body));return t.other?`CaseOther(<<${e}>>,<<${n}>>,${o(t.other)})`:`Case(<<${e}>>,<<${n}>>)`}case`String`:return`''${t.value}''`;case`Num`:if(t.fraction!==``)throw new e.k(`real constants`);return`(${ua(t.integer)})`;case`At`:throw new e.j}},m=t=>{let a=[];for(let s of t.context)switch(s.kind){case`Flex`:{let e=r(s.name);a.push(`fixes ${e} ${e}'`);break}case`Fresh`:{let e=s.domain&&s.domainVisibility===`Visible`?o(s.domain):void 0,t=r(s.name);if(a.push(`fixes ${t}`),e===void 0)break;a.push(`assumes ${t}_in : "(${t} \\<in> ${e})"`);break}case`Fact`:{let t=n.stack.length,r=s.visibility===`Visible`?ra(n,()=>o(s.expression)):void 0;if(i(),r instanceof e.k){a.push(`(* omitted temporal assumption : ${r.message} *)`);break}if(r===void 0)break;a.push(`assumes v'${t}: "${r}"`);break}case`Defn`:if(s.definition.kind===`Bpragma`)return[...a,``];a.push(`(* usable definition ${s.definition.name} suppressed *)`),r(s.definition.name)}return[...a,`shows "${o(t.active)}"`]};try{let e=m(t);return{text:e.join(`
|
|
28
|
+
`),isAssumed:e.some(e=>e.startsWith(`assumes `))}}catch(t){throw t instanceof e.k?new e.w(`isabelle : unsupported operator ${t.message}`):t}},pa=(e,t,n)=>{let r=fa(t);return[...da(`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
|
+
`)},ma=(e,t)=>[...da(e,!0),...t.flatMap(e=>[`lemma ob'${e.id}:`,`${fa(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
|
+
`),ha=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],ga=Array.from({length:64},(e,t)=>Math.floor(Math.abs(Math.sin(t+1))*2**32)),_a=(e,t)=>e<<t|e>>>32-t,va=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+ga[o]+t[l]|0;return[i,n+_a(u,ha[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(``)},ya=(t,n)=>{let r=S(t,n-1)?.hyp;if(!r)throw new e.j;return r},ba=(e,t)=>z(e,t).level,xa=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&t.includes(e.operator.builtin),Sa=(e,t)=>{let n=te(void 0,(n,r)=>{let i=Se(r,t=>e(n,t),t);return[y(n,i),i]});return(t,r)=>{let i=n(t,r.context);return{context:i.context,active:e(i.state,r.active)}}},Ca=(e,t)=>{if(t.kind===`Sub`||t.kind===`Tsub`){let n=Ca(e,t.action),r=Ca(e,t.subscript),i=_(`UNCHANGED`,[r],t),a=t.modal===`Box`?_(`Disj`,[n,i],t):_(`Conj`,[n,_(`Neg`,[i],t)],t);return t.kind===`Sub`?a:_(t.modal===`Box`?`BoxTrue`:`Diamond`,[a],t)}return N(e,t,Ca,y,`all`)},wa=(e,t)=>t.kind===`Apply`&&xa(t,[`UNCHANGED`])&&t.args.length===1?Ge(t.args[0]):N(e,t,wa,y,`all`),Ta=(e,t)=>_(e,[t],t),Ea=(t,n)=>{if(n.kind===`Ix`){let e=ya(t,n.index);return e.kind===`Fresh`&&e.level===`Constant`||e.kind===`Defn`&&e.definition.kind===`Operator`&&ba(S(t,n.index),e.definition.body)===0?n:Ta(`Prime`,n)}if(xa(n,[`ENABLED`])||n.kind===`Opaque`||n.kind===`Sequent`||n.kind===`Let`)return Ta(`Prime`,n);if(xa(n,[`UNCHANGED`,`Cdot`,`Leadsto`,`Actplus`,`BoxTrue`,`BoxFalse`,`Diamond`])||n.kind===`Tquant`||n.kind===`Sub`||n.kind===`Tsub`||n.kind===`Fair`)throw new e.j;return N(t,n,Ea,y)},Da=e=>{let t=e===`BoxTrue`?`Conj`:`Disj`,n=e===`BoxTrue`?`Forall`:`Exists`,r=(i,a)=>ba(i,a)===0?a:xa(a,[t])||(a.kind===`Quant`||a.kind===`Tquant`)&&a.quantifier===n?N(i,a,r,y):Ta(e,a);return r},Oa={Prime:Ea,BoxTrue:Da(`BoxTrue`),Diamond:Da(`Diamond`)},ka=(t,n)=>{if(n.kind===`Apply`&&n.operator.kind===`Internal`){let r=Oa[n.operator.builtin];if(r){if(n.args.length!==1)throw new e.j;return r(t,n.args[0])}}return N(t,n,ka,y,`all`)},Aa=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],ja={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},Ma=(e,t)=>`${e}_${t}_`,Na=(t,n,r)=>{if(n.kind!==`Operator`)return n.kind===`Bpragma`?{...n,body:V(t,n.body)}:n;let i=V(t,n.body),a=Aa[r??ba(t,i)];if(a===void 0)throw new e.j;return{...n,name:Ma(a,n.name),body:i}},Pa=(e,t,n)=>{switch(t.kind){case`Fresh`:return{...t,name:Ma(ja[t.level],t.name),domain:t.domain&&V(e,t.domain)};case`Flex`:return{...t,name:Ma(`VARIABLE`,t.name)};case`Defn`:return{...t,definition:Na(e,t.definition,n)};case`Fact`:return{...t,expression:V(e,t.expression)}}},Fa=(e,t)=>{if(t.kind!==`Defn`||t.definition.kind!==`Operator`)return;let n=t=>{if(!xa(t,[`UNCHANGED`])||t.kind!==`Apply`)return ba(e,t);let n=e=>e.kind===`Tuple`?e.elements.flatMap(n):[e],r=n(t.args[0]);return ba(e,r.length===1?r[0]:t.args[0])},r=t.definition.body;return n(xa(r,[`Prime`,`BoxTrue`,`Diamond`])&&r.kind===`Apply`&&r.args.length===1&&r.kind===`Apply`?r.args[0]:r)},Ia=te({scope:void 0,original:void 0},(e,t,n)=>{let r=Pa(e.scope,t,Fa(e.original,n));return[{scope:y(e.scope,r),original:y(e.original,n)},r]}),La=(e,t)=>{let n=Ia(t.context,e.context);return{context:n.context,active:V(n.state.scope,e.active)}},Ra=(e,t)=>{let[n,r]=C(e,t.context,(e,t)=>{let n=Pa(e,t);return[y(e,n),n]});return{context:r,active:V(n,t.active)}},V=(e,t)=>{switch(t.kind){case`Lambda`:{let n=t.params.map(e=>({...e,name:Ma(`Unknown`,e.name)})),r=b(e,n.map(re));return{...t,params:n,body:V(r,t.body)}}case`Tquant`:{let n=b(e,t.names.map(e=>({kind:`Flex`,name:Ma(`VARIABLE`,e)})));return{...t,body:V(n,t.body)}}case`Choose`:{let n=t.domain&&V(e,t.domain),r=Ma(`CONSTANT`,t.name),i=n?T(r,n):w(r,`Constant`);return{...t,name:r,domain:n,body:V(y(e,i),t.body)}}case`SetSt`:{let n=V(e,t.domain),r=Ma(`CONSTANT`,t.name),i=V(y(e,T(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:Ma(ja[t.level],t.name),domain:t.domain.kind===`Domain`?{kind:`Domain`,expression:V(e,t.domain.expression)}:t.domain})),r=b(e,n.map(ne));return t.kind===`SetOf`?{...t,bounds:n,element:V(r,t.element)}:{...t,bounds:n,body:V(r,t.body)}}case`Let`:{let[n,r]=C(e,t.definitions,(e,t)=>{let n=Na(e,t);return[y(e,ie(n)),n]});return{...t,definitions:r,body:V(n,t.body)}}case`Sequent`:return{...t,sequent:Ra(e,t.sequent)};default:return N(e,t,V,y,`all`)}},za=/* @__PURE__ */ new WeakMap,Ba=(e,t)=>{let n=za.get(t);if(n)return n;let r=t.kind===`Operator`?t.body:void 0;if(r?.kind!==`Lambda`)return[];let i=b(e,r.params.map(re)),a=r.params.map((e,t)=>Ua(i,r.body,t+1,!0));return za.set(t,a),a},Va=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`ENABLED`,`UNCHANGED`],Ha=[`Leadsto`,`Actplus`,`Cdot`],Ua=(t,n,r,i)=>{if(n.kind===`Ix`)return i||n.index!==r;if(n.kind===`Apply`&&n.operator.kind===`Internal`){let e=n.operator.builtin;if(Va.includes(e)&&n.args.length===1||Ha.includes(e)&&n.args.length===2)return n.args.every(e=>Ua(t,e,r,!1))}if(n.kind===`Sub`)return[n.action,n.subscript].every(e=>Ua(t,e,r,!1));if(n.kind===`Apply`&&n.operator.kind===`Ix`){let i=S(t,n.operator.index-1),a=i?.hyp;if(i&&a?.kind===`Defn`&&a.definition.kind===`Operator`){let o=Ba(i.rest,a.definition);return n.args.every((n,i)=>{let a=o[i];if(a===void 0)throw new e.j;return Ua(t,n,r,a)})}}let a={isSubstitutive:!0};return N({scope:t,index:r},n,(e,t)=>(a.isSubstitutive&&=Ua(e.scope,t,e.index,i),t),(e,t)=>({scope:y(e.scope,t),index:e.index+1}),`all`),a.isSubstitutive},Wa=(e,t)=>{let n=zt(un(ee(e),t));return`h${va(n).slice(0,5)}`},Ga=(e,t)=>m({kind:`Opaque`,name:Wa(e,t)},t),Ka=(e,t,n,r,i)=>{let a=i.map((t,r)=>ba(e,t)===0||n[i.length-r-1]?m({kind:`Opaque`,name:`*`},t):t);return Ga(e,m({kind:`Apply`,operator:{kind:`Opaque`,name:t},args:a},r))},qa=[`Prime`,`StrongPrime`,`BoxTrue`,`BoxFalse`,`Diamond`,`Leadsto`,`ENABLED`,`Cdot`,`UNCHANGED`],Ja=(t,n)=>{if(n.kind!==`Apply`)return N(t,n,Ja,y);let r=n.operator,[i]=n.args;if(xa(n,[`Prime`,`StrongPrime`])&&n.args.length===1&&i.kind===`Ix`){let e=ya(t,i.index);if(e.kind===`Fresh`||e.kind===`Flex`)return m({kind:`Opaque`,name:`${e.name}#prime`},n)}if(xa(n,qa))return Ga(t,n);if(r.kind!==`Ix`)return N(t,n,Ja,y);let a=S(t,r.index-1),o=a?.hyp;if(!o)throw new e.j;let s=n.args;if(o.kind===`Defn`&&o.definition.kind===`Operator`){let e=Ba(a.rest,o.definition);if(s.every((n,r)=>ba(t,n)===0||e[s.length-r-1]))return N(t,n,Ja,y);let i=Ka(t,o.definition.name,e,r,s);return m({kind:`Apply`,operator:i,args:s.map(e=>Ja(t,e))},n)}if(o.kind===`Flex`)return N(t,n,Ja,y);if(o.kind===`Fresh`){if(o.level===`Constant`)return m({kind:`Apply`,operator:r,args:s.map(e=>Ja(t,e))},n);let e=s.map(()=>!1);return Ka(t,o.name,e,r,s)}throw new e.j},Ya=Sa(Ca,`all`),Xa=Sa(wa,`all`),Za=Sa(ka,`all`),Qa=Sa(Ja,`visible`),$a=e=>{let t=e.context,n=Xa(t,Ya(t,e)),r=Za(t,n);return Qa(t,La(r,e))},eo=e=>te(u(0),(t,n)=>n.kind===`Defn`&&(e&&n.definition.kind===`Bpragma`||n.definition.kind===`Operator`&&n.visibility===`Visible`)?[d(O(t,n.definition.body),t),void 0]:[p(1,t),de(t,n)]),to=eo(!0),no=eo(!1),ro=(e,t=!0)=>{let n=(t?to:no)(e.context);return{context:n.context,active:O(n.state,e.active)}},io=/* @__PURE__ */ new Set([`BoxTrue`,`BoxFalse`,`Diamond`,`Actplus`,`Leadsto`,`Cdot`]),ao=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]}},oo=e=>{if(e.kind===`Tsub`||e.kind===`Fair`||e.kind===`Apply`&&e.operator.kind===`Internal`&&io.has(e.operator.builtin))return!1;if(e.kind===`Sequent`){let t=e.sequent;return[...t.context.flatMap(ao),t.active].every(oo)}return we(e).every(oo)},so=t=>{if(t.kind!==`Let`)return Ce(t,so);let[n,...r]=t.definitions;if(!n)return so(t.body);if(n.kind!==`Operator`&&n.kind!==`Bpragma`)throw new e.C(n.kind===`Instance`?`Found INSTANCE in Expr.Elab.let_normalize, all INSTANCE statements have been replaced with definitions in Module.Elab `:`Expr.Elab.let_normalize`);let i=so(n.body),a={...t,definitions:r};return so(O(d(i,u(0)),a))},co=(e,t)=>t.kind===`Dot`?m({kind:`Dot`,expression:e,field:t.field},e):m({kind:`FcnApp`,function:e,args:[t.expression]},e),lo=(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&M(e.expression,t.expression),uo=(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},fo=e=>{if(e.kind!==`Except`)return Ce(e,fo);let t=e,n=(e,t)=>uo(e,t)?.value??co(e,t),r=(e,n,r)=>{let i=uo(e,n);if(e.kind!==`Record`||!i)return m({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 m({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||!lo(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(fo(t.function),be(t.specs,fo))},po=te(!0,(e,t)=>[e&&ao(t).every(oo),Se(t,so,`all`)]),mo=te(void 0,(e,t)=>[void 0,Se(t,fo,`all`)]),ho=e=>{let t=po(e.context),n=so(e.active);return t.state&&oo(e.active)?{context:mo(e.context,t.context).context,active:fo(n)}:{context:t.context,active:n}},go={kind:`Internal`,builtin:`TRUE`},_o=(e,t)=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===t&&e.args.length===2?e.args:void 0,vo=e=>e.kind===`Apply`&&e.operator.kind===`Internal`&&e.operator.builtin===`ENABLED`&&e.args.length===1?e.args[0]:void 0,yo=(e,t)=>{let n=_o(e,t),r=n&&vo(n[0]),i=n&&vo(n[1]);return r&&i?[r,i]:void 0},bo=(t,n)=>{let r=/* @__PURE__ */ new Set,i=(t,n)=>{let a={...t,isPrimed:!0},o=n.kind===`Apply`&&n.operator.kind===`Internal`&&n.operator,s=o&&o.builtin,c=n.kind===`Apply`?n.args:[];if((s===`Prime`&&c.length===1||s===`ENABLED`||s===`Cdot`&&c.length===2||s===`UNCHANGED`&&c.length===1||n.kind===`Sub`)&&t.isPrimed)throw new e.j;if(s===`Prime`&&c.length===1)i(a,c[0]);else if(s===`Cdot`&&c.length===2)i(t,c[1]);else if(s===`UNCHANGED`&&c.length===1)i(a,c[0]);else if(n.kind===`Sub`)i(t,n.action),i(a,n.subscript);else if(n.kind===`Ix`){let i=S(t.scope,n.index-1)?.hyp;if(!i)throw new e.j;i.kind===`Flex`&&t.isPrimed&&r.add(i.name)}else s!==`ENABLED`&&N(t,n,i,(e,t)=>({...e,scope:y(e.scope,t)}));return n};return i({scope:t,isPrimed:!1},n),r},xo=(e,t,n)=>{let r=bo(e,t);return[...bo(e,n)].every(e=>!r.has(e))},So=(t,n)=>{let r=e=>z(t,e).level,i=(t,n)=>{if(r(t)>2||r(n)>2)throw new e.j},a=vo(n),o=a&&_o(a,`Disj`);if(o)return i(o[0],o[1]),{name:`abdisj_inverse`,left:o[0],right:o[1]};let s=yo(n,`Disj`);if(s)return i(s[0],s[1]),{name:`abdisj`,left:s[0],right:s[1]};let c=a&&_o(a,`Conj`);if(c){let e=c[0],n=c[1],a=xo(t,e,n);return i(e,n),a?{name:r(e)===2?`abconj_inverse`:`pconj_inverse`,left:e,right:n}:void 0}let l=yo(n,`Conj`);if(l)return xo(t,l[0],l[1])?{name:`abconj`,left:l[0],right:l[1]}:void 0;let u=_o(n,`Conj`),d=u&&vo(u[1]);if(u&&d)return r(u[0])<=1&&r(d)<=2?{name:`pconj`,left:u[0],right:d}:void 0;let f=yo(n,`Equiv`)??yo(n,`Eq`);if(f)return{name:`equiv`,left:f[0],right:f[1]};let p=yo(n,`Implies`);return p&&{name:`implies`,left:p[0],right:p[1]}},Co=t=>{let n=b(void 0,t.context),r=So(n,t.active),i={isPremise:!1,isLeftBoolean:!1,isRightBoolean:!1};if(t.context.forEach((e,n)=>{if(!r||e.kind!==`Fact`||e.visibility!==`Visible`)return;let a=t.context.length-n,o=e.expression,s=e=>M(k(a,e),r.left),c=e=>M(k(a,e),r.right),l=(e,t)=>e!==void 0&&s(e[0])&&c(e[1])&&t.includes(r.name),u=vo(o),d=u&&_o(u,`Conj`),f=_o(o,`Conj`),p=f&&vo(f[1]),m=_o(o,`Mem`),h=m?.[1].kind===`Internal`&&m[1].builtin===`BOOLEAN`;l(d,[`pconj`])||l(u&&_o(u,`Disj`),[`abdisj`])||l(yo(o,`Disj`),[`abdisj_inverse`])||l(d,[`abconj`])||l(yo(o,`Conj`),[`abconj_inverse`,`pconj_inverse`])||l(f&&p&&[f[0],p],[`pconj_inverse`])?i.isPremise=!0:l(_o(o,`Equiv`),[`equiv`])?(i.isPremise=!0,i.isLeftBoolean=!0,i.isRightBoolean=!0):l(_o(o,`Eq`),[`equiv`])?i.isPremise=!0:m&&h&&s(m[0])?i.isLeftBoolean=!0:m&&h&&c(m[0])?i.isRightBoolean=!0:l(_o(o,`Implies`),[`implies`])&&(i.isPremise=!0)}),!i.isPremise||!i.isLeftBoolean||!i.isRightBoolean)throw new e.w(`ENABLEDaxioms proof directive did not succeed.
|
|
31
|
+
`);return{...t,active:go}},wo={Constant:0,State:1,Action:2,Temporal:3},To=(e,t,n)=>e.every((e,r)=>r<t.length&&n(e,t[r]))&&e.length===t.length,Eo=e=>[...new Map(e.toReversed().map(e=>[e.name,e.value]))].toSorted((e,t)=>e[0]<t[0]?-1:1),Do=(t,n)=>{let r=S(t,n-1);if(!r)throw new e.j;let i=r.hyp;if(i.kind===`Fresh`)return{name:i.name,kind:i.level,level:wo[i.level]??-1};if(i.kind===`Flex`)return{name:i.name,kind:`Variable`,level:1};if(i.kind===`Defn`&&i.definition.kind===`Operator`){let e=z(r.rest,i.definition.body).level;return{name:i.definition.name,kind:`Definition`,level:e}}throw new e.j},Oo=(e,t)=>b(e,t.map(ne)),ko=(e,t)=>b(e,t.map(re)),Ao=(e,t)=>b(e,t.map(ie)),jo=(e,t)=>b(e,t.map(e=>({kind:`Flex`,name:e}))),Mo=(t,n,r,i)=>{let a=/* @__PURE__ */ new Map,o=(e,t,n,r)=>{let i=Do(e,n),o=Do(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=wo[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)=>b(e,t.map(e=>w(e,`Unknown`))),s=e=>Eo(e.substitutions.map(e=>({name:e.name,value:e.expression})));return To(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)=>To(n,r,(n,r)=>n[0]===r[0]&&p(e,t,n[1],r[1])),l=(e,t,n,r)=>To(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(y(e,n[0]),y(t,r[0]),n.slice(1),r.slice(1)),f=(e,t,n,r)=>!n.domain||!r.domain?!n.domain&&!r.domain&&p(y(e,w(n.name,`Constant`)),y(t,w(r.name,`Constant`)),n.body,r.body):p(e,t,n.domain,r.domain)&&p(y(e,T(n.name,n.domain)),y(t,T(r.name,r.domain)),n.body,r.body),p=(t,n,r,i)=>{if(r.kind===`Parens`)return p(t,n,r.expression,i);if(i.kind===`Parens`)return p(t,n,r,i.expression);let a=(e,r)=>p(t,n,e,r),u=(e,t)=>To(e,t,a);switch(r.kind){case`Ix`:return i.kind===`Ix`&&o(t,n,r.index,i.index);case`Opaque`:return i.kind===`Opaque`&&r.name===i.name;case`Internal`:return i.kind===`Internal`&&r.builtin===i.builtin;case`Lambda`:return i.kind===`Lambda`&&r.params.length===i.params.length&&p(ko(t,r.params),ko(n,i.params),r.body,i.body);case`Apply`:return i.kind===`Apply`&&a(r.operator,i.operator)&&u(r.args,i.args);case`Sequent`:return i.kind===`Sequent`&&d(t,n,r.sequent.context,i.sequent.context)&&p(b(t,r.sequent.context),b(n,i.sequent.context),r.sequent.active,i.sequent.active);case`Bang`:{if(i.kind!==`Bang`||!a(r.expression,i.expression))return!1;let t=i.selectors,n=r.selectors.every((e,n)=>{let r=t[n];return r?e.kind===`Number`&&r.kind===`Number`?e.value===r.value:e.kind===`Instance`&&r.kind===`Instance`?u(e.args,r.args):e.kind===`Label`&&r.kind===`Label`?e.label===r.label&&u(e.args,r.args):e.kind===r.kind:!0});if(n&&r.selectors.length!==t.length)throw new e.j(`Invalid_argument`);return n}case`With`:return i.kind===`With`&&a(r.expression,i.expression);case`Let`:return i.kind===`Let`&&To(r.definitions,i.definitions,(e,r)=>s(t,n,e,r))&&p(Ao(t,r.definitions),Ao(n,i.definitions),r.body,i.body);case`If`:return i.kind===`If`&&a(r.condition,i.condition)&&a(r.consequent,i.consequent)&&a(r.alternative,i.alternative);case`List`:return i.kind===`List`&&r.bullet===i.bullet&&u(r.items,i.items);case`Quant`:return i.kind===`Quant`&&r.quantifier===i.quantifier&&l(t,n,r.bounds,i.bounds)&&p(Oo(t,r.bounds),Oo(n,r.bounds),r.body,i.body);case`Tquant`:return i.kind===`Tquant`&&r.quantifier===i.quantifier&&To(r.names,i.names,(e,t)=>e===t)&&p(jo(t,r.names),jo(n,i.names),r.body,i.body);case`Choose`:case`SetSt`:return i.kind===r.kind&&f(t,n,r,i);case`SetOf`:return i.kind===`SetOf`&&p(Oo(t,r.bounds),Oo(n,i.bounds),r.element,i.element)&&l(t,n,r.bounds,i.bounds);case`SetEnum`:return i.kind===`SetEnum`&&u(r.elements,i.elements);case`Arrow`:return i.kind===`Arrow`&&a(r.domain,i.domain)&&a(r.range,i.range);case`Fcn`:return i.kind===`Fcn`&&l(t,n,r.bounds,i.bounds)&&p(Oo(t,r.bounds),Oo(n,i.bounds),r.body,i.body);case`FcnApp`:return i.kind===`FcnApp`&&u([r.function,...r.args],[i.function,...i.args]);case`Tuple`:return i.kind===`Tuple`&&u(r.elements,i.elements);case`Product`:return i.kind===`Product`&&u(r.factors,i.factors);case`Rect`:case`Record`:return i.kind===r.kind&&c(t,n,Eo(r.fields),Eo(i.fields));case`Except`:return i.kind===`Except`&&a(r.function,i.function)&&To(r.specs,i.specs,(e,t)=>To(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&a(e.expression,t.expression))&&a(e.value,t.value));case`Dot`:return i.kind===`Dot`&&a(r.expression,i.expression)&&r.field===i.field;case`Sub`:case`Tsub`:return i.kind===r.kind&&r.modal===i.modal&&a(r.action,i.action)&&a(r.subscript,i.subscript);case`Fair`:return i.kind===`Fair`&&r.fairness===i.fairness&&a(r.subscript,i.subscript)&&a(r.action,i.action);case`Case`:{if(i.kind!==`Case`)return!1;let e=r.arms[0],t=i.arms[0];return(e&&t?a(e.condition,t.condition)&&a(e.body,t.body):!e&&!t)?r.other&&i.other?a(r.other,i.other):!r.other&&!i.other:!1}case`String`:return i.kind===`String`&&r.value===i.value;case`Num`:return i.kind===`Num`&&r.integer===i.integer&&r.fraction===i.fraction;case`At`:return i.kind===`At`&&r.isExcept===i.isExcept}},m=p(t,n,r,i),h=ee(t),g=[...a].map(t=>t[0]===t[1]||h.reduce((n,r)=>{if(r.kind===`Fact`)return n;if(r.kind===`Defn`&&r.definition.kind!==`Operator`)throw new e.j;return n||(r.kind===`Defn`?r.definition.name:r.name)===t[0]},!1));return m&&g.every(Boolean)},No=t=>{let n=b(void 0,t.context);if(!t.context.some((e,r)=>{if(e.kind!==`Fact`||e.visibility!==`Visible`)return!1;let i=S(n,t.context.length-r),a=e.expression;return a.kind===`Sequent`?Mo(b(i,a.sequent.context),n,a.sequent.active,t.active):Mo(i,n,a,t.active)}))throw new e.w(`LevelComparison proof directive did not succeed.
|
|
32
|
+
`);return{...t,active:{kind:`Internal`,builtin:`TRUE`}}},Po=(t,n)=>{let r=n.has(`expandenabled`),i=n.has(`expandcdot`),a=n.has(`autouse`),o=n.has(`lambdify`);if(!r&&!i&&!o)return n.has(`levelcomparison`)?No(t):n.has(`enabledaxioms`)?Co(t):t;let s=ut({value:0},()=>{throw new e.j},()=>{}),c={kind:`Sequent`,sequent:t},l=r||i?yr(s,()=>{},void 0,c,{isEnabled:r,isCdot:i,isAutoUse:a}):gr(s,()=>{},void 0,c,{isEnabled:!0,isCdot:!0,isAutoUse:a});if(l.kind!==`Sequent`)throw new e.j;return l.sequent},Fo=/* @__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(`.`),Io={And:0,Or:1,Refs:2},Lo={Forall:0,Exists:1},Ro={Box:0,Dia:1},zo={Weak:0,Strong:1},Bo={34:`\\"`,92:`\\\\`,10:`\\n`,9:`\\t`,13:`\\r`,8:`\\b`},Vo=e=>`"${[...new TextEncoder().encode(e)].map(e=>Bo[e]??(e<32||e>126?`\\${String(e).padStart(3,`0`)}`:String.fromCharCode(e))).join(``)}"`,Ho=e=>e===`BoxTrue`?`$Box`:e===`BoxFalse`?`$FakeBox`:`$${Fo.indexOf(e)}`,Uo=e=>e.level===`Unknown`?`Unknown`:e.level.toUpperCase(),Wo=t=>{let n=[],r=t=>{let r=n[n.length-t];if(!r)throw new e.j;return r},i=e=>n.push({ident:e,isUsed:!1}),a=()=>{let t=n.pop();if(!t)throw new e.j;return t},o=e=>Array.from({length:e}).forEach(()=>i({kind:`Var`})),s=e=>Array.from({length:e},a),c=t=>{if(t.ident.kind===`VarIndex`)return t.ident.index;if(t.ident.kind===`Var`)return 0;throw new e.j},l=t=>{if(t.ident.kind!==`HypIndex`)throw new e.j;return t.ident.index},u=(t,n)=>{let a=e=>u(t,e),l=e=>e.map(a).join(`,`),f=(e,t)=>t.map((t,n)=>t.domain.kind===`Domain`?`${c(e[n])}:${a(t.domain.expression)},`:``).join(``),p=(e,t)=>(o(e),{text:a(t),entries:s(e)}),m=e=>e.map(e=>`${c(e)}.`).join(``);switch(n.kind){case`Ix`:{let i=r(n.index);i.isUsed=!0;let a=i.ident;switch(a.kind){case`None`:return`$V(${n.index}SHOULD_NOT_APPEAR)`;case`Hyp`:{let e=t.hyp++;return i.ident={kind:`HypIndex`,index:e},`$${a.label}(${e})`}case`Var`:{let e=t.variable++;return i.ident={kind:`VarIndex`,index:e},`$PRM(${e})`}case`HypIndex`:return`$HYP(${a.index})`;case`VarIndex`:return`$PRM(${a.index})`;case`Pragma`:return``}throw new e.j}case`Opaque`:return n.name;case`Internal`:return Ho(n.builtin);case`Lambda`:{let e=p(n.params.length,n.body);return`$Lam(${m(e.entries.toReversed())}${e.text})`}case`Sequent`:return d(n.sequent);case`Apply`:{let e=n.operator;return e.kind===`Ix`&&r(e.index).ident.kind===`Pragma`?``:`$OpApp(${a(e)};${l(n.args)})`}case`With`:case`Parens`:return a(n.expression);case`If`:return`$If(${a(n.condition)},${a(n.consequent)},${a(n.alternative)})`;case`List`:return`$List(${Io[n.bullet]};${l(n.items)})`;case`Let`:{let t=n.definitions.map(t=>{if(t.kind!==`Operator`&&t.kind!==`Bpragma`)throw new e.j;let n=`${a(t.body)}.`;return i({kind:`Var`}),n}),r=a(n.body);return s(t.length),`${t.join(``)}${r}`}case`Quant`:{let e=p(n.bounds.length,n.body);return`$Quant(${Lo[n.quantifier]};${f(e.entries,n.bounds)}.${e.text})`}case`Tquant`:{let e=p(n.names.length,n.body);return`$Tquant(${Lo[n.quantifier]}${m(e.entries.toReversed())}${e.text})`}case`Choose`:{let e=p(1,n.body),t=c(e.entries[0]);return n.domain?`$Bch(${t}:${a(n.domain)};${e.text})`:`$Ch(${t}:${e.text})`}case`SetSt`:{let e=p(1,n.body);return`$SSt(${c(e.entries[0])}:${a(n.domain)};${e.text})`}case`SetOf`:{let e=p(n.bounds.length,n.element);return`$Sof(${f(e.entries.toReversed(),n.bounds)}.${e.text})`}case`Fcn`:{let e=p(n.bounds.length,n.body);return`$Fcn(${f(e.entries.toReversed(),n.bounds)}.${e.text})`}case`SetEnum`:return`$Set(${l(n.elements)})`;case`Tuple`:return`$Tup(${l(n.elements)})`;case`Product`:return`$Prod(${l(n.factors)})`;case`FcnApp`:return`$FcnApp(${a(n.function)};${l(n.args)})`;case`Arrow`:return`$Arrow(${a(n.domain)},${a(n.range)})`;case`Rect`:case`Record`:return`$${n.kind}(${n.fields.map(e=>`(${e.name},${a(e.value)})`).join(`,`)})`;case`Except`:return`$Except(${a(n.function)},${n.specs.map(e=>`(${e.trail.map(e=>e.kind===`Dot`?`.${e.field}`:`.${a(e.expression)}`).join(``)}=${a(e.value)})`).join(`,`)})`;case`Dot`:return`$Dot(${a(n.expression)},${n.field})`;case`Sub`:case`Tsub`:return`$${n.kind}(${Ro[n.modal]},${a(n.action)},${a(n.subscript)})`;case`Fair`:return`$Fair(${zo[n.fairness]},${a(n.subscript)},${a(n.action)})`;case`Case`:return`$Case(${n.arms.map(e=>`(${a(e.condition)},${a(e.body)})`).join(`,`)},${n.other?a(n.other):``})`;case`String`:return Vo(n.value);case`Num`:return`$Num(${n.integer},${n.fraction})`;case`At`:return`$At`;case`Bang`:throw new e.j}},d=t=>{let n={hyp:1,variable:1},r=(o,s)=>{let c=t.context[o];if(!c)return`$Goal(${u(n,t.active)})`;let d=e=>(i(e),{rest:r(o+1,y(s,c)),entry:a()});switch(c.kind){case`Fresh`:{if(!c.domain){let e=Uo(c),t=d({kind:`Hyp`,label:e});return t.entry.isUsed?`${t.rest}${e}${c.name}`:t.rest}let e=d({kind:`Hyp`,label:`CON`});if(c.domainVisibility===`Hidden`)return e.rest;let t=e.entry.isUsed?String(l(e.entry)):`_`;return`${e.rest}$Dom(${t};${u(n,c.domain)})`}case`Flex`:return d({kind:`Hyp`,label:`VAR`}).rest;case`Defn`:{let t=c.definition;if(t.kind===`Recursive`)return d({kind:`Hyp`,label:`CON`}).rest;if(t.kind===`Bpragma`)return d({kind:`Pragma`}).rest;if(t.kind===`Instance`)throw new e.j;let r=d({kind:`Hyp`,label:`HYP`});if(!r.entry.isUsed)return r.rest;let i=l(r.entry);return c.visibility===`Hidden`?`${r.rest}$Def(${i},${tt(s,t.body)?0:3})`:`${r.rest}$Def(${i};${u(n,t.body)})`}case`Fact`:return c.visibility===`Hidden`?d({kind:`None`}).rest:`${d({kind:`Hyp`,label:`HYP`}).rest}$Fact(${u(n,c.expression)},${c.time.toLowerCase()})`}};return r(0,void 0)};return d(t)},Go=e=>va(Wo(e)),Ko=e=>e.domain.kind===`NoDomain`,qo=e=>{if(e.kind===`List`&&(e.bullet===`And`||e.bullet===`Refs`)){let t=e.items.map(qo),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=qo(e.args[0]),n=qo(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(Ko)){let t=qo(e.body),n=(t,n)=>m({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]},Jo=e=>{let t=[],n=e.context.reduce((e,n)=>{if(n.kind!==`Fact`||n.visibility!==`Visible`)return t.push(de(e,n)),p(1,e);let r=qo(n.expression),i=[...r[1]?[r[1]]:[],...r[0]];return i.forEach((r,i)=>t.push({...n,expression:k(i,O(e,r))})),{kind:`Compose`,outer:u(i.length-1),inner:p(1,e)}},u(0));return{context:t,active:O(n,e.active)}},Yo=/* @__PURE__ */ new Set([`expandenabled`,`expandcdot`,`autouse`,`lambdify`,`enabledaxioms`,`levelcomparison`]),Xo=[{prover:`smt`,timeLimitMs:5e3},{prover:`zenon`,timeLimitMs:1e4},{prover:`isabelle`,timeLimitMs:3e4,tactic:`auto`}],Zo={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([...Yo].map(e=>[e,{prover:e,seconds:0}]))},Qo=(t,n,r,i)=>{let a=Zo[t];if(!a)throw new e.w(`Unknown prover: ${t}`);if(r!==void 0&&!a.isBudgeted)throw new e.w(`A Z3 rlimit budget ("rN") is only supported by the SMT and Z3 backends.`);return{prover:a.prover,timeLimitMs:r===void 0?(n??a.seconds)*1e3:1/0,...r!==void 0&&{rlimit:r},...a.prover===`isabelle`&&{tactic:i??`auto`}}},$o=t=>{let n=Number.parseFloat(t.slice(1));if(!/^[rR]./.test(t)||!Number.isFinite(n)||n<=0)throw new e.w(`Invalid SMT budget "${t}"`);return Math.max(1,Math.trunc(Math.min(n*3e6,4294967295)))},es=(t,n)=>{let r=t.reduce((t,n)=>{let r=n.value,i=r.kind===`Default`?t.args[0]:void 0,a=r.kind===`Default`?t.args.slice(1):t.args;if(r.kind===`Default`&&!i)throw new e.w(`Some arguments are missing`);let o=r.kind===`String`?r.value:i?.kind===`String`?i.value:void 0;switch(n.hint){case`prover`:case`tactic`:if(o===void 0)throw new e.w(`This argument should be a string`);return{...t,args:a,[n.hint]:o};case`timeout`:if(r.kind===`Float`)return{...t,args:a,timeout:r.value};if(o!==void 0)return{...t,args:a,rlimit:$o(o)};if(i?.kind!==`Num`)throw new e.w(`This argument should be a number of seconds`);return{...t,args:a,timeout:Number(`${i.integer}.${i.fraction}`)};default:throw new e.w(`Unknown keyword in proof method definition: ${n.hint}`)}},{args:n});if(r.args.length>0)throw new e.w(`Too many arguments`);if(r.prover===void 0)throw new e.w(`Missing prover name`);return Qo(r.prover,r.timeout,r.rlimit,r.tactic)},ts=e=>Qo(e.name,e.timeout,void 0,e.tactic),ns=t=>{let n=[],r={methods:[],useLocation:null};return t.context.forEach((t,i)=>{let a=t.kind===`Fact`&&t.visibility===`Visible`&&t.expression;if(a&&a.kind===`With`){r.methods.push(ts(a.method)),n.push(void 0);return}if(t.kind===`Defn`&&t.definition.kind===`Bpragma`){n.push({kind:`Premeth`,groups:t.definition.methods});return}if(t.kind===`Defn`&&t.definition.kind===`Operator`&&t.visibility===`Visible`){let e=t.definition.body;n.push(e.kind===`With`?{kind:`Meth`,method:e.method}:void 0);return}if(n.push(void 0),!a||t.kind!==`Fact`)return;let o=a.kind===`Apply`?a.operator:a;if(o.kind!==`Ix`)return;let s=n[i-o.index];if(s?.kind===`Premeth`){t.useLocation!==r.useLocation&&(r.methods=[],r.useLocation=t.useLocation);let e=a.kind===`Apply`?a.args:[];r.methods.push(...s.groups.map(t=>es(t,e)))}else if(s?.kind===`Meth`){if(a.kind===`Apply`)throw new e.j;r.methods.push(ts(s.method))}}),r.methods},rs=e=>{let t=e.method===void 0?ns(e.sequent):[ts(e.method)],n=t.filter(e=>!Yo.has(e.prover));return{frontends:new Set(t.flatMap(e=>Yo.has(e.prover)?[e.prover]:[])),provers:n.length>0?n:Xo}},is=e=>e.active.kind===`Internal`&&e.active.builtin===`TRUE`||e.context.some((t,n)=>t.kind===`Fact`?M(t.expression,k(n-e.context.length,e.active)):t.kind!==`Fresh`||!t.domain?!1:M(_(`Mem`,[{kind:`Ix`,index:1},k(1,t.domain)],{}),k(n+1-e.context.length,e.active))),as={Constant:`CONSTANT`,State:`STATE`,Action:`ACTION`,Temporal:`TEMPORAL`,Unknown:`Unknown`},os=[`CONSTANT`,`STATE`,`ACTION`,`TEMPORAL`],ss=(e,t)=>{let[n,r]=C(e,t.context,(e,t)=>{let n=(()=>{switch(t.kind){case`Fresh`:return{...t,name:`${as[t.level]}_${t.name}_`,domain:t.domain&&cs(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=cs(e,n.body),i=os[z(e,r).level];return{...t,definition:{...n,name:`${i}_${n.name}_`,body:r}}}case`Fact`:return{...t,expression:cs(e,t.expression)}}})();return[y(e,n),n]});return{context:r,active:cs(n,t.active)}},cs=(e,t)=>{if(t.kind===`Sequent`)return{...t,sequent:ss(e,t.sequent)};let n=N(e,t,cs,y,`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:`${as[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 N(e,t,ls,y,`all`);let n={scope:e,substitution:u(0),context:[]},r=e=>{let t=e.kind===`Fact`&&e.visibility===`Visible`&&e.time===`Always`?{...e,expression:_(`BoxTrue`,[e.expression],e.expression)}:e;n.context.push(t),n.scope=y(n.scope,t)};for(let e of t.sequent.context){let t=de(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=p(1,n.substitution);continue}let i=ls(n.scope,t.domain);r({...t,domain:void 0}),r({kind:`Fact`,expression:_(`Mem`,[m({kind:`Ix`,index:1},i),k(1,i)],i),visibility:t.domainVisibility,time:t.level===`Constant`?rt(n.scope,e.domain):`Now`,location:t.location}),n.substitution={kind:`Compose`,outer:u(1),inner:p(1,n.substitution)}}let i=O(n.substitution,t.sequent.active);return{...t,sequent:{context:n.context,active:ls(n.scope,i)}}},us={Conj:`&`,Disj:`|`,Implies:`->`,Equiv:`<->`},ds={Neg:`~`,BoxTrue:`always`,BoxFalse:`always`,Diamond:`sometime`,Prime:`next`},fs=e=>{if(e.kind===`Internal`&&e.builtin===`TRUE`)return;if(e.kind===`List`&&e.bullet!==`Or`){let t=e.items.flatMap(e=>fs(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=fs(e.args[0]),n=fs(e.args[1]);return t&&n?{...e,args:[t,n]}:t??n},ps=`(cc | ~ cc)`,ms=e=>{let t=(e,n,r=!1)=>{let i=n=>t(e,n);switch(n.kind){case`Internal`:if(n.builtin===`TRUE`)return ps;if(n.builtin===`FALSE`)return`(cc & ~ cc)`;break;case`Apply`:{let e=n.operator,t=n.args;if(e.kind!==`Internal`)break;let r=us[e.builtin];if(r&&t.length===2)return`(${i(t[0])} ${r} ${i(t[1])})`;let a=ds[e.builtin];if(a&&t.length===1)return`(${a} ${i(t[0])})`;break}case`List`:{if(n.items.length===0)return ps;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?fs(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${va(zt(un(e,n))).slice(0,5)}`},n=cs(void 0,{kind:`Sequent`,sequent:e});return`not (${t([],ls(void 0,Ye(qe(Je(n)))),!0)})`},hs=(e,t)=>e<t?-1:+(e>t),gs=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return hs(e,t);if(!Array.isArray(e)||!Array.isArray(t))return 0;let n=e.findIndex((e,n)=>n>=t.length||gs(e,t[n])!==0);return n===-1?e.length-t.length:n>=t.length?1:gs(e[n],t[n])},_s={"\\":`backslash_`,"+":`plussign_`,"-":`hyphen_`,"*":`asterisk_`,"/":`slash_`,"%":`percentsign_`,"^":`circumflexaccent_`,"&":`ampersand_`,"@":`atsign_`,"#":`pound_`,$:`dollarsign_`,"(":`leftparenthesis_`,")":`rightparenthesis_`,"|":`verticalbar_`,".":`period_`,":":`colon_`,"?":`questionmark_`,"!":`exclamationmark_`,"<":`lessthansign_`,">":`greaterthansign_`,"=":`equalsign_`," ":`space_`},vs=e=>`smt__${e.replace(/[\\+\-*/%^&@#$()|.:?!<>= ]/g,e=>_s[e]).replaceAll(`_`,`__`)}`,ys=vs(`TLA__`),bs=new Map(Object.entries(_s).map(e=>[e[1],e[0]])),xs=RegExp(`(${[...bs.keys()].join(`|`)})`,`g`),H=e=>vs(`TLA__${e}`),Ss=e=>e.startsWith(ys)?e.slice(ys.length).replaceAll(`__`,`_`).replace(xs,e=>bs.get(e)??e):void 0,U=H(`Mem`),Cs=H(`SetExtTrigger`),ws=H(`SubsetEq`),Ts=H(`Cup`),Es=H(`Cap`),Ds=H(`SetMinus`),Os=H(`Subset`),ks=H(`Union`),As=H(`Tt_Idv`),js=H(`Cast_Bool`),Ms=H(`BoolSet`),Ns=H(`StrSet`),Ps=H(`IntSet`),W=H(`NatSet`),G=H(`Cast_Int`),K=H(`Proj_Int`),Fs=H(`IntLteq`),Is=H(`IntRange`),q=H(`FunApp`),J=H(`FunDom`),Ls=H(`FunIsafcn`),Rs=H(`FunSet`),zs=H(`FunExcept`),Bs=H(`TrigEq_Set$Idv$`),Vs=H(`IsSetOf`),Y=H(`Seq`),X=H(`Len`),Hs=H(`Cat`),Us=H(`Append`),Ws=H(`Head`),Gs=H(`Tail`),Ks=H(`SubSeq`),qs=H(`Tuple_0`),Js={Cup:Ts,Cap:Es,Setminus:Ds,SUBSET:Os,UNION:ks,DOMAIN:J,Plus:H(`IntPlus`),Minus:H(`IntMinus`),Times:H(`IntTimes`),Exp:H(`IntExp`),Quotient:H(`IntQuotient`),Remainder:H(`IntRemainder`),Uminus:H(`IntUminus`),Range:Is,Seq:Y,Len:X,BSeq:H(`BSeq`),Cat:Hs,Append:Us,Head:Ws,Tail:Gs,SubSeq:Ks},Ys=(e,t)=>Array.from({length:t},(t,n)=>`${e}${n+1}`),Xs=(e,t=`Idv`)=>e.map(e=>`(${e} ${t})`).join(` `),Z=(e,t,n=[],r=`Idv`)=>e.length===0?t:`(forall (${Xs(e,r)}) ${n.length===0?t:`(! ${t} ${n.map(e=>`:pattern (${e.join(` `)})`).join(` `)})`})`,Zs=e=>e.length===0?`true`:e.length===1?e[0]:`(and ${e.join(` `)})`,Qs=e=>e.length===0?`false`:e.length===1?e[0]:`(or ${e.join(` `)})`,Q=(e,t)=>t.length===0?e:`(${e} ${t.join(` `)})`,$s=(e,t,n=`Idv`,r=`Idv`)=>`(declare-fun ${e} (${Array.from({length:t},()=>r).join(` `)}) ${n})`,ec=(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},tc=(e,t,n)=>e.replace(/[^\s()]+/g,e=>e===t?n:e),nc=/* @__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(`.`),rc=/* @__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(`.`),ic=[`TIntPlus`,`TIntUminus`,`TIntMinus`,`TIntTimes`,`TIntQuotient`,`TIntRemainder`,`TIntLteq`],$=(e,t,n,r)=>({name:e,args:t,label:r??[e,...t.flat()].join(` `),formula:n}),ac=e=>`${e.name} ${JSON.stringify(e.args)}`,oc=e=>{let t=nc.indexOf(e.name);return t===-1?nc.length+rc.indexOf(e.name):t},sc=(e,t)=>oc(e)-oc(t)||gs(e.args,t.args),cc={IntPlus:[`+`,2],IntMinus:[`-`,2],IntTimes:[`*`,2],IntUminus:[`-`,1],IntQuotient:[`div`,2],IntRemainder:[`mod`,2],IntLteq:[`<=`,2]},lc=e=>{let t=cc[e][0],n=t===`div`||t===`mod`,r=cc[e][1]===1?[`x1`]:n?[`x`,`y`]:[`x1`,`x2`],i=Q(H(e),r.map(e=>`(${G} ${e})`)),a=`(= ${i} ${t===`<=`?`(<= ${r.join(` `)})`:`(${G} (${t} ${r.join(` `)}))`})`;return $(`Typing`,[ic.indexOf(`T${e}`)],Z(r,n?`(=> (> y 0) ${a})`:a,[[i]],`Int`),`Typing T${e}`)},uc=e=>{let t=H(`SetEnum_${e}`),n=Ys(`a`,e),r=Q(t,n),i=$(`EnumDefElim`,[e],Z([...n,`x`],e===0?`(not (${U} x ${r}))`:`(=> (${U} x ${r}) ${Qs(n.map(e=>`(= x ${e})`))})`,[[`(${U} x ${r})`]]));return e===0?[i]:[$(`EnumDefIntro`,[e],Z(n,Zs(n.map(e=>`(${U} ${e} ${r})`)),[[r]])),i]},dc=e=>Array.from({length:e},(e,t)=>`(${G} ${t+1})`),fc=e=>e.map(e=>H(`StrLit_${e}`)),pc=(e,t,n,r)=>{let i=Ys(`x`,r.length);return r.map((r,a)=>{let o=`(${zs} ${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]]))})},mc=e=>pc(`Tup`,[e],H(`Tuple_${e}`),dc(e)),hc=e=>pc(`Rec`,[e],H(`Record_${e.join(`_`)}`),fc(e)),gc=(e,t,n,r)=>{let i=Ys(`x`,r.length),a=Q(n,i),o=$(`${e}Isafcn`,t,Z(i,`(${Ls} ${a})`,[[a]]));return r.length===0?[o]:[o,$(`${e}DomDef`,t,Z(i,`(= (${J} ${a}) ${Q(H(`SetEnum_${r.length}`),r)})`,[[a]])),$(`${e}AppDef`,t,Z(i,Zs(r.map((e,t)=>`(= (${q} ${a} ${e}) ${i[t]})`)),[[a]]))]},_c=(e,t)=>{let n=H(`Tuple_${e}`),r=Ys(`x`,e),i=Q(n,r);return[...gc(`Tup`,[e],n,dc(e)),$(`SeqTupTyping`,[e],Z([`a`,...r],e===0?`(${U} ${i} (${Y} a))`:`(=> ${Zs(r.map(e=>`(${U} ${e} a)`))} (${U} ${i} (${Y} a)))`,[[...r.map(e=>`(${U} ${e} a)`),i]])),$(`SeqTupLen`,[e],Z(r,`(= (${X} ${i}) (${G} ${e}))`,[[i]])),...t?mc(e):[]]},vc=(e,t)=>[...gc(`Rec`,[e],H(`Record_${e.join(`_`)}`),fc(e)),...t?hc(e):[]],yc=(e,t,n,r,i,a)=>{let o=Ys(`s`,i.length),s=Ys(`x`,i.length),c=Q(n,o),l=Q(r,s),u=i.map(e=>`(${q} ${a} ${e})`);return[$(`${e}Intro`,t,Z([...o,...s],`(=> ${Zs(s.map((e,t)=>`(${U} ${e} ${o[t]})`))} (${U} ${l} ${c}))`,[[l,c]])),$(`${e}Elim`,t,Z([...o,a],`(=> (${U} ${a} ${c}) ${Zs([`(= ${a} ${Q(r,u)})`,...u.map((e,t)=>`(${U} ${e} ${o[t]})`)])})`,[[`(${U} ${a} ${c})`]]))]},bc=[`Mem`,`Seq`,`Len`,`FunApp`,`NatSet`,`Cast_Int`,`Proj_Int`],xc=(t,n)=>{let r=(e,t,n)=>({declaration:e,deps:t,axioms:n}),i=H(t),a=(e,t,n,a=`Idv`)=>r($s(i,e,a),t,n),o=/^SetEnum_(\d+)$/.exec(t);if(o)return a(Number(o[1]),[`Mem`],uc(Number(o[1])));let s=/^SetOf_(\d+)$/.exec(t);if(s){let e=Number(s[1]);return r(void 0,[`Mem`,`IsSetOf`],[$(`SetOfIntro`,[e],void 0),$(`SetOfElim`,[e],void 0),$(`AssertIsSetOf`,[e],void 0),$(`CompareSetOfTrigger`,[],Z([`a`,`b`],`(${Cs} a b)`,[[`(${Vs} a)`,`(${Vs} b)`]]))])}if(t.startsWith(`StrLit_`)){let e=t.slice(7),r=n.strings.map(t=>$(`StrLitDistinct`,[e,t],`(distinct ${i} ${H(`StrLit_${t}`)})`));return n.strings.push(e),a(0,[`Mem`,`StrSet`],[$(`StrLitIsstr`,[e],`(${U} ${i} ${Ns})`),...r])}let c=/^Tuple_(\d+)$/.exec(t);if(c){let e=Number(c[1]);return n.tuples.push(e),a(e,e===0?[`FunIsafcn`,`Cast_Int`,`Seq`,`Len`]:[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${e}`,`Cast_Int`,`Mem`,`Seq`,`Len`],_c(e,n.isExcept))}let l=/^Product_(\d+)$/.exec(t);if(l){let e=Number(l[1]);return a(e,[`Mem`,`Tuple_${e}`,`FunApp`,`Cast_Int`,`Proj_Int`],yc(`Product`,[e],i,H(`Tuple_${e}`),dc(e),`t`))}let u=n.recordFields.get(t);if(u&&t.startsWith(`Record_`))return n.records.push(u),a(u.length,[`FunIsafcn`,`FunDom`,`FunApp`,`SetEnum_${u.length}`,...u.map(e=>`StrLit_${e}`)],vc(u,n.isExcept));if(u&&t.startsWith(`RecordSet_`)){let e=`Record_${u.join(`_`)}`;return a(u.length,[`Mem`,e,`FunApp`,...u.map(e=>`StrLit_${e}`)],yc(`RecSet`,[u],i,H(e),fc(u),`r`))}let d=n.anonymous.get(t);if(d!==void 0)return a(d,[],[]);let f=cc[t];if(f)return a(f[1],[`Cast_Int`],[lc(t)],t===`IntLteq`?`Bool`:`Idv`);switch(t){case`IntExp`:return a(2,[`Mem`,`IntSet`,`Cast_Int`,`TIntLteq`,`TIntLit_0`,`TIntLit_1`],[$(`IntExpTyping`,[],`(forall ((x Idv) (y Idv)) (! (=> (and (${U} x ${Ps}) (${U} y ${Ps}) (or (distinct x (${G} 0)) (${Fs} (${G} 1) y))) (${U} (${i} x y) ${Ps})) :pattern ((${i} x y))))`)]);case`SelectSeq`:return r(void 0,[`Mem`,`Seq`,`Len`,`Append`,`FunApp`,`FunDom`,`IntSet`,`NatSet`,`Tuple_0`,`Proj_Int`],[$(`SeqSelectseqTyping`,[],void 0),$(`SeqSelectseqLen`,[],void 0),$(`SeqSelectseqNil`,[],void 0),$(`SeqSelectseqApp`,[],void 0),$(`SeqSelectseqAppend`,[],void 0)]);case`Choose`:return r(void 0,[],[$(`ChooseDef`,[],void 0)]);case`Mem`:return a(2,[`SetExtTrigger`],[$(`SetExt`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (= (${U} z x) (${U} z y))) (= x y)) :pattern ((${Cs} x y))))`)],`Bool`);case`SubsetEq`:return a(2,[`Mem`],[$(`SubsetEqIntro`,[],`(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${U} z x) (${U} z y))) (${ws} x y)) :pattern ((${ws} x y))))`),$(`SubsetEqElim`,[],`(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${ws} x y) (${U} z x)) (${U} z y)) :pattern ((${ws} x y) (${U} z x))))`)],`Bool`);case`Union`:return a(1,[`Mem`],[$(`UnionIntro`,[],`(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${U} y a) (${U} x y)) (${U} x (${ks} a))) :pattern ((${U} y a) (${U} x (${ks} a))) :pattern ((${U} x y) (${U} x (${ks} a))) :pattern ((${U} y a) (${U} x y) (${ks} a))))`),$(`UnionElim`,[],`(forall ((a Idv) (x Idv)) (! (=> (${U} x (${ks} a)) (exists ((y Idv)) (and (${U} y a) (${U} x y)))) :pattern ((${U} x (${ks} a)))))`)]);case`Subset`:return a(1,[`Mem`,`SubsetEq`],[$(`SubsetDefAlt`,[],`(forall ((a Idv) (x Idv)) (! (= (${U} x (${Os} a)) (${ws} x a)) :pattern ((${U} x (${Os} a))) :pattern ((${ws} x a) (${Os} a))))`)]);case`Cup`:case`Cap`:case`SetMinus`:{let e=t===`Cup`?`(or (MEM x a) (MEM x b))`:t===`Cap`?`(and (MEM x a) (MEM x b))`:`(and (MEM x a) (not (MEM x b)))`,n=$(`${t}Def`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${U} x (${i} a b)) ${e.replaceAll(`MEM`,U)}) :pattern ((${U} x (${i} a b))) :pattern ((${U} x a) (${i} a b)) :pattern ((${U} x b) (${i} a b))))`);return t===`Cap`?a(2,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[n,$(`DisjointTrigger`,[],`(forall ((x Idv) (y Idv)) (! (${Cs} (${Es} x y) ${H(`SetEnum_0`)}) :pattern ((${Es} x y))))`)]):a(2,[`Mem`],[n])}case`SetSt`:return r(void 0,[`Mem`,`SetEnum_0`,`SetExtTrigger`],[$(`SetStDef`,[],void 0),$(`EmptyComprehensionTrigger`,[],void 0)]);case`NatSet`:return a(0,[`IntSet`,`TIntLit_0`,`Cast_Int`,`IntLteq`],[$(`NatSetDef`,[],`(forall ((x Idv)) (! (= (${U} x ${W}) (and (${U} x ${Ps}) (${Fs} (${G} 0) x))) :pattern ((${U} x ${W}))))`)]);case`IntRange`:return a(2,[`Mem`,`IntSet`,`IntLteq`],[$(`IntRangeDef`,[],`(forall ((a Idv) (b Idv) (x Idv)) (! (= (${U} x (${Is} a b)) (and (${U} x ${Ps}) (${Fs} a x) (${Fs} x b))) :pattern ((${U} x (${Is} a b)))))`)]);case`FunIsafcn`:return a(1,[`Mem`,`FunDom`,`FunFcn`,`FunApp`],[$(`FunExt`,[],`(forall ((f Idv) (g Idv)) (! (=> (and (${Ls} f) (${Ls} g) (= (${J} f) (${J} g)) (forall ((x Idv)) (=> (${U} x (${J} f)) (= (${q} f x) (${q} g x))))) (= f g)) :pattern ((${Ls} f) (${Ls} g))))`)],`Bool`);case`FunSet`:return n.isFunSet=!0,a(2,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunSetIntro`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (and (${Ls} f) (= (${J} f) a) (forall ((x Idv)) (=> (${U} x a) (${U} (${q} f x) b)))) (${U} f (${Rs} a b))) :pattern ((${U} f (${Rs} a b)))))`),$(`FunSetElim1`,[],`(forall ((a Idv) (b Idv) (f Idv)) (! (=> (${U} f (${Rs} a b)) (and (${Ls} f) (= (${J} f) a))) :pattern ((${U} f (${Rs} a b)))))`),$(`FunSetElim2`,[],`(forall ((a Idv) (b Idv) (f Idv) (x Idv)) (! (=> (and (${U} f (${Rs} a b)) (${U} x a)) (${U} (${q} f x) b)) :pattern ((${U} f (${Rs} a b)) (${U} x a)) :pattern ((${U} f (${Rs} a b)) (${q} f x))))`),...n.isFunConstr?[$(`FunTyping`,[],void 0)]:[]]);case`FunFcn`:return n.isFunConstr=!0,r(void 0,[`FunIsafcn`],[$(`FunConstrIsafcn`,[],void 0),...n.isFunSet?[$(`FunTyping`,[],void 0)]:[]]);case`FunDom`:return a(1,[`FunFcn`],[$(`FunDomDef`,[],void 0)]);case`FunApp`:return a(2,[`Mem`,`FunFcn`],[$(`FunAppDef`,[],void 0)]);case`FunExcept`:{n.isExcept=!0;let e=`(${zs} f x y)`;return a(3,[`Mem`,`FunIsafcn`,`FunDom`,`FunApp`],[$(`FunExceptIsafcn`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (${Ls} ${e}) :pattern (${e})))`),$(`FunExceptDomDef`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (= (${J} ${e}) (${J} f)) :pattern (${e})))`),$(`FunExceptAppDef1`,[],`(forall ((f Idv) (x Idv) (y Idv)) (! (=> (${U} x (${J} f)) (= (${q} ${e} x) y)) :pattern (${e})))`),$(`FunExceptAppDef2`,[],`(forall ((f Idv) (x Idv) (y Idv) (z Idv)) (! (=> (${U} z (${J} f)) (and (=> (= z x) (= (${q} ${e} z) y)) (=> (distinct z x) (= (${q} ${e} z) (${q} f z))))) :pattern ((${q} ${e} z)) :pattern (${e} (${q} f z))))`),...n.tuples.flatMap(mc),...n.records.flatMap(hc)])}case`Seq`:return a(1,[`Mem`,`Len`,`FunIsafcn`,`FunDom`,`FunApp`,`IntSet`,`NatSet`,`IntRange`,`Cast_Int`,`Proj_Int`],[$(`SeqSetIntro`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${Ls} s) (>= (${K} (${X} s)) 0) (forall ((i Idv)) (= (${U} i (${J} s)) (and (${U} i ${Ps}) (<= 1 (${K} i)) (<= (${K} i) (${K} (${X} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${K} (${X} s)))) (${U} (${q} s (${G} i)) a)))) (${U} s (${Y} a))) :pattern ((${U} s (${Y} a)))))`),$(`SeqSetElim1`,[],`(forall ((a Idv) (s Idv)) (! (=> (${U} s (${Y} a)) (and (${Ls} s) (${U} (${X} s) ${W}) (= (${J} s) (${Is} (${G} 1) (${X} s))))) :pattern ((${U} s (${Y} a)))))`,`SetSetElim1`),$(`SeqSetElim2`,[],`(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${U} s (${Y} a)) (<= 1 i) (<= i (${K} (${X} s)))) (${U} (${q} s (${G} i)) a)) :pattern ((${U} s (${Y} a)) (${q} s (${G} i)))))`,`SetSetElim2`)]);case`Len`:return a(1,[`FunDom`,`IntRange`,`Cast_Int`],[$(`SeqLenDef`,[],`(forall ((s Idv) (z Int)) (=> (and (>= z 0) (= (${J} s) (${Is} (${G} 1) (${G} z)))) (= (${X} s) (${G} z))))`)]);case`BSeq`:return a(1,[],[]);case`Cat`:return a(2,bc,[$(`SeqCatTyping`,[],`(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${U} s (${Y} a)) (${U} t (${Y} a))) (${U} (${Hs} s t) (${Y} a))) :pattern ((${U} s (${Y} a)) (${Hs} s t)) :pattern ((${U} t (${Y} a)) (${Hs} s t))))`),$(`SeqCatLen`,[],`(forall ((s Idv) (t Idv)) (! (=> (and (${U} (${X} s) ${W}) (${U} (${X} t) ${W})) (= (${X} (${Hs} s t)) (${G} (+ (${K} (${X} s)) (${K} (${X} t)))))) :pattern ((${Hs} s t))))`),$(`SeqCatApp1`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (${U} (${X} t) ${W}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${Hs} s t) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${Hs} s t) (${G} i))) :pattern ((${Hs} s t) (${q} s (${G} i)))))`),$(`SeqCatApp2`,[],`(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (${U} (${X} t) ${W}) (<= i (+ (${K} (${X} s)) (${K} (${X} t)))) (< (${K} (${X} s)) i)) (= (${q} (${Hs} s t) (${G} i)) (${q} t (${G} (- i (${K} (${X} s))))))) :pattern ((${q} (${Hs} s t) (${G} i)))))`)]);case`Append`:return a(2,bc,[$(`SeqAppendTyping`,[],`(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${U} s (${Y} a)) (${U} x a)) (${U} (${Us} s x) (${Y} a))) :pattern ((${U} s (${Y} a)) (${Us} s x))))`),$(`SeqAppendLen`,[],`(forall ((s Idv) (x Idv)) (! (=> (${U} (${X} s) ${W}) (= (${X} (${Us} s x)) (${G} (+ (${K} (${X} s)) 1)))) :pattern ((${Us} s x))))`),$(`SeqAppendApp1`,[],`(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (<= 1 i) (<= i (${K} (${X} s)))) (= (${q} (${Us} s x) (${G} i)) (${q} s (${G} i)))) :pattern ((${q} (${Us} s x) (${G} i))) :pattern ((${Us} s x) (${q} s (${G} i)))))`),$(`SeqAppendApp2`,[],`(forall ((s Idv) (x Idv)) (! (=> (${U} (${X} s) ${W}) (= (${q} (${Us} s x) (${G} (+ (${K} (${X} s)) 1))) x)) :pattern ((${Us} s x))))`)]);case`Head`:return a(1,[`FunApp`,`Cast_Int`],[$(`SeqHeadDef`,[],`(forall ((s Idv)) (! (= (${Ws} s) (${q} s (${G} 1))) :pattern ((${Ws} s))))`)]);case`Tail`:return a(1,bc,[$(`SeqTailTyping`,[],`(forall ((a Idv) (s Idv)) (! (=> (and (${U} s (${Y} a)) (distinct (${K} (${X} s)) 0)) (${U} (${Gs} s) (${Y} a))) :pattern ((${U} s (${Y} a)) (${Gs} s))))`),$(`SeqTailLen`,[],`(forall ((s Idv)) (! (=> (and (${U} (${X} s) ${W}) (distinct (${K} (${X} s)) 0)) (= (${X} (${Gs} s)) (${G} (- (${K} (${X} s)) 1)))) :pattern ((${Gs} s))))`),$(`SeqTailApp`,[],`(forall ((s Idv) (i Int)) (! (=> (and (${U} (${X} s) ${W}) (distinct (${K} (${X} s)) 0) (<= 1 i) (<= i (- (${K} (${X} s)) 1))) (= (${q} (${Gs} s) (${G} i)) (${q} s (${G} (+ i 1))))) :pattern ((${q} (${Gs} s) (${G} i)))))`)]);case`SubSeq`:{let e=`(${Ks} s (${G} x) (${G} y))`;return a(3,[`Mem`,`Seq`,`Len`,`FunApp`,`IntSet`,`Cast_Int`,`Proj_Int`],[$(`SeqSubseqTyping`,[],`(forall ((a Idv) (s Idv) (x Int) (y Int)) (! (=> (or (< y x) (and (${U} s (${Y} a)) (<= 1 x) (<= y (${K} (${X} s))))) (${U} ${e} (${Y} a))) :pattern ((${U} s (${Y} a)) ${e})))`),$(`SeqSubseqLen`,[],`(forall ((s Idv) (x Int) (y Int)) (! (and (=> (<= x (+ y 1)) (= (${X} ${e}) (${G} (- (+ y 1) x)))) (=> (> x (+ y 1)) (= (${X} ${e}) (${G} 0)))) :pattern (${e})))`),$(`SeqSubseqApp`,[],`(forall ((s Idv) (x Int) (y Int) (z Int)) (! (=> (and (<= 1 x) (<= 1 z) (<= z (- (+ y 1) x))) (= (${q} ${e} (${G} z)) (${q} s (${G} (- (+ z x) 1))))) :pattern ((${q} ${e} (${G} z)))))`)])}case`Cast_Int`:return r($s(i,1,`Idv`,`Int`),[`Mem`,`IntSet`,`Proj_Int`],[$(`CastInjAlt`,[`Int`],`(forall ((x Int)) (! (= x (${K} (${G} x))) :pattern ((${G} x))))`),$(`TypeGuardIntro`,[`Int`],`(forall ((z Int)) (! (${U} (${G} z) ${Ps}) :pattern ((${G} z))))`),$(`TypeGuardElim`,[`Int`],`(forall ((x Idv)) (! (=> (${U} x ${Ps}) (= x (${G} (${K} x)))) :pattern ((${U} x ${Ps}))))`)]);case`Cast_Bool`:return r($s(i,1,`Idv`,`Bool`),[`Mem`,`BoolSet`,`Tt_Idv`],[$(`CastInjAlt`,[`Bool`],`(and (= (${js} true) ${As}) (distinct (${js} false) ${As}))`),$(`TypeGuardIntro`,[`Bool`],`(forall ((z Bool)) (! (${U} (${js} z) ${Ms}) :pattern ((${js} z))))`),$(`TypeGuardElim`,[`Bool`],`(forall ((x Idv)) (! (=> (${U} x ${Ms}) (or (= x (${js} true)) (= x (${js} false)))) :pattern ((${U} x ${Ms}))))`)]);case`Proj_Int`:return r($s(i,1,`Int`),[],[]);case`TrigEq_Set$Idv$`:return a(2,[`SetExtTrigger`],[$(`ExtTrigEqDef`,[`Set$Idv$`],`(forall ((x Idv) (y Idv)) (! (= (${Bs} x y) (= x y)) :pattern ((${Bs} x y))))`),$(`ExtTrigEqTrigger`,[`Idv`],`(forall ((x Idv) (y Idv)) (! (${Cs} x y) :pattern ((${Bs} x y))))`)],`Bool`);case`SetExtTrigger`:case`IsSetOf`:return a(t===`IsSetOf`?1:2,[],[],`Bool`);case`BoolSet`:case`StrSet`:case`IntSet`:case`Tt_Idv`:return a(0,[],[]);case`TIntLteq`:return r(void 0,[`IntLteq`],[lc(`IntLteq`)]);default:if(t.startsWith(`TIntLit_`))return r(void 0,[],[]);throw new e.k(`the symbol ${t}`)}},Sc=(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(hs)[0];if(t.delete(e),a.has(e))continue;let n=xc(e,i);a.set(e,n),n.deps.forEach(e=>t.add(e)),n.axioms.forEach(e=>o.set(ac(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=Ss(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}},Cc=(e,t)=>t===0?e:`${e}_${t}`,wc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Set;return{names:t,adjoin:n=>{let r=vs(n),i=(e.get(r)??-1)+1,a=Array.from({length:t.size+1},(e,t)=>i+t).find(e=>!t.has(Cc(r,e)))??i;return{base:r,salt:a,name:Cc(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)}}}},Tc=e=>{let t=wc();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(``)}}},Ec=(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)),Dc=e=>e.length===1?e[0]:_(`Conj`,[e[0],Dc(e.slice(1))],e[0]),Oc=(e,t,n)=>e.kind!==`Record`||t.kind!==`Record`||!Ec(e,t)?_(`Eq`,[e,t],n):Dc(e.fields.map(e=>Oc(e.value,t.fields.find(t=>t.name===e.name)?.value??e.value,n))),kc=e=>{let t=Ce(e,kc);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:m(Oc(t.args[0],t.args[1],t),t)},Ac=e=>e.kind===`Record`||e.kind===`Rect`?{...e,fields:e.fields.toSorted((e,t)=>hs(e.name,t.name))}:Ce(e,Ac),jc=(e,t)=>`${e}#${t}`,Mc=e=>Number(e.slice(e.lastIndexOf(`#`)+1)),Nc=`?unprimable`,Pc=e=>{let t=e.indexOf(`(${Nc} `);if(t===-1)return e;let n=ec(e,t);return e.slice(0,t)+Pc(e.slice(t+11+2,n))+Pc(e.slice(n+1))},Fc=(e,t)=>/\((forall|exists|ite) /.test(e)?void 0:e.replace(/[^\s()]+#(\d+)/g,(e,n)=>Number(n)<t?`#`:`#${Number(n)-t}`),Ic=()=>{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=vs(`${l}_omitted_${e.size}`);return e.set(t,{symbol:t,kind:i,visit:Pc(a),getLines:()=>[]}),t}let u=Fc(`${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=vs(f),m={symbol:p,kind:i,visit:Pc(a),getLines:e=>[$s(p,c),...s(p,e).map(e=>`(assert (! ${Pc(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)}},Lc=`?trigger`,Rc=/* @__PURE__ */ new Set([ks,Os,Ts,Es,Ds,Is,Rs,Y]),zc=e=>{let t=/^\(?([^\s()]+)/.exec(e)?.[1]??``;return Rc.has(t)||/^smt__TLA____(SetEnum__\d+|SetSt__flatnd__\d+|SetOf__\d+__flatnd__\d+|Product__\d+|RecordSet__)/.test(t)},Bc=(e,t)=>{let n=e.indexOf(`(${Lc} `);if(n===-1)return e;let r=n+8+2,i=ec(e,r)+1,a=ec(e,i+1)+1,o=t?e.slice(r,i):e.slice(i+1,a);return e.slice(0,n)+o+Bc(e.slice(a+1),t)},Vc=(e,t,n,r)=>{let i=`(${Bs} ${e} ${t})`,a=r?`(distinct ${e} ${t})`:`(= ${e} ${t})`;if(!zc(e)&&!zc(t))return a;let o=r?`(not ${i})`:i;return n===(r?`Positive`:`Negative`)?`(${Lc} ${o} ${a})`:o},Hc=(e,t,n,r)=>{let i=Q(e,[`a`,...t]);return[$(`SetStDef`,[],Z([...t,`a`,`x`],`(= (${U} x ${i}) (and (${U} x a) ${tc(n,r,`x`)}))`,[[`(${U} x ${i})`],[`(${U} x a)`,i]]))]},Uc=(e,t,n,r)=>{let i=r.length,a=Ys(`a`,i),o=Ys(`y`,i),s=r.reduce((e,t,n)=>tc(e,t,o[n]),n),c=Q(e,[...a,...t]),l=o.map((e,t)=>`(${U} ${e} ${a[t]})`),u=i===1?[`a`]:a,d=Q(e,[...u,...t]);return[$(`SetOfIntro`,[i],Z([...t,...a,...o],`(=> ${Zs(l)} (${U} ${s} ${c}))`,[[s,c],[c,...l]])),$(`SetOfElim`,[i],Z([...t,...a,`x`],`(=> (${U} x ${c}) (exists (${Xs(o)}) ${Zs([...l,`(= x ${s})`])}))`,[[`(${U} x ${c})`]])),$(`AssertIsSetOf`,[i],Z([...t,...u],`(${Vs} ${d})`,[[d]]))]},Wc=(e,t,n,r,i)=>{let a=Q(e,[`a`,...t]),o=tc(n,r,`x`),s=i.has(ac($(`FunTyping`,[],void 0)))?[$(`FunTyping`,[],Z([...t,`a`,`b`],`(=> (forall ((x Idv)) (=> (${U} x a) (${U} ${o} b))) (${U} ${a} (${Rs} a b)))`,[[a,`(${Rs} a b)`]]))]:[];return[$(`FunConstrIsafcn`,[],Z([...t,`a`],`(${Ls} ${a})`,[[a]])),$(`FunDomDef`,[],Z([...t,`a`],`(= (${J} ${a}) a)`,[[a]])),$(`FunAppDef`,[],Z([...t,`a`,`x`],`(=> (${U} x a) (= (${q} ${a} x) ${o}))`,[[`(${q} ${a} x)`],[`(${U} x a)`,a]])),...s]},Gc=(e,t,n,r)=>[$(`ChooseDef`,[],Z([...t,`x`],`(=> ${tc(n,r,`x`)} ${tc(n,r,Q(e,t))})`))],Kc=(e,t,n,r)=>{let i=n=>Q(e,[n,...t]),a=e=>tc(n,r,e),o=i(`(${Us} s x)`);return[$(`SeqSelectseqTyping`,[],Z([...t,`a`,`s`],`(=> (${U} s (${Y} a)) (${U} ${i(`s`)} (${Y} a)))`,[[`(${U} s (${Y} a))`,i(`s`)]])),$(`SeqSelectseqLen`,[],Z([...t,`s`],`(=> (${U} (${X} s) ${W}) (<= (${K} (${X} ${i(`s`)})) (${K} (${X} s))))`,[[i(`s`)]])),$(`SeqSelectseqNil`,[],Z(t,`(= ${i(qs)} ${qs})`)),$(`SeqSelectseqApp`,[],Z([...t,`s`,`x`],`(=> (${U} x (${J} ${i(`s`)})) ${a(`(${q} ${i(`s`)} x)`)})`,[[`(${q} ${i(`s`)} x)`]])),$(`SeqSelectseqAppend`,[],Z([...t,`s`,`x`],`(and (=> ${a(`x`)} (= ${o} (${Us} ${i(`s`)} x))) (=> (not ${a(`x`)}) (= ${o} ${i(`s`)})))`,[[o]]))]},qc=t=>{let n=Ic(),r=n.flatten,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=wc(),s=/* @__PURE__ */ new Map,c=e=>e.isBool?e.text:`(= ${Bc(e.text,!0)} ${As})`,l=e=>e.isBool?`(${js} ${Bc(e.text,!0)})`:e.text,u=e=>({isBool:!0,text:e}),d=e=>({isBool:!1,text:e}),f=(t,n)=>{let r=Array.from({length:n-1}).reduce(e=>e?.rest,t);if(!r)throw new e.k(`a reference outside the obligation`);return r.binding},p=(e,t)=>({binding:t,rest:e}),m=(e,t)=>[...new Set(e.match(/[^\s()]+#\d+/g))].filter(e=>Mc(e)<t).toSorted((e,t)=>Mc(e)-Mc(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(D(e,t,g(n))),y=(e,t,n)=>c(D(e,t,n)),b=(e,t,n)=>e.reduce((e,t)=>t.domain.kind===`Ditto`?[...e,e.at(-1)]:t.domain.kind===`NoDomain`?[...e,void 0]:[...e,t.domain.expression],[]).map(e=>e===void 0?void 0:v(e,t,n)),ee=(t,n,r,i)=>b(t,n,r).map(t=>{if(t===void 0)throw new e.k(`${i} without a domain`);return t}),x=(e,t,n)=>{let r=e.map((e,t)=>jc(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}}},S=(e,t,n)=>{let r=b(e.bounds,t,n),i=x(e.bounds.map(e=>e.name),t,n),a=y(e.body,i.env,i.mode),o=i.variables.flatMap((e,t)=>r[t]===void 0?[]:[`(${U} ${e} ${r[t]})`]);return e.quantifier===`Forall`?`(forall (${Xs(i.variables)}) ${o.length===0?a:`(=> ${Zs(o)} ${a})`})`:`(exists (${Xs(i.variables)}) ${Zs([...o,a])})`},C=(e,t,n)=>{let i=v(e.domain,t,n),a=x([e.name],t,g(n)),o=y(e.body,a.env,a.mode),s=m(o,n.depth),c=r(`SetSt`,o,n,e=>Hc(e,s,o,a.variables[0]),s.length+1);return d(Q(c,[i,...s]))},te=(e,t,n)=>{let i=ee(e.bounds,t,n,`a set of values`),a=x(e.bounds.map(e=>e.name),t,g(n)),o=v(e.element,a.env,a.mode),s=m(o,n.depth),c=i.length,l=r(`SetOf_${c}`,o,n,e=>Uc(e,s,o,a.variables),c+s.length);return d(Q(l,[...i,...s]))},w=(e,t,n)=>{let i=ee(e.bounds,t,n,`a function`),a=i.length===1?i[0]:Q(H(`Product_${i.length}`),i),o=jc(i.length===1?e.bounds[0].name:`x`,n.depth),s={...g(n),depth:n.depth+1},c=i.length===1?p(t,{kind:`constant`,symbol:o}):dc(i.length).reduce((e,t)=>p(e,{kind:`constant`,symbol:`(${q} ${o} ${t})`}),t),l=v(e.body,c,s),u=m(l,n.depth),f=r(`FunFcn`,l,n,(e,t)=>Wc(e,u,l,o,t),u.length+1);return d(Q(f,[a,...u]))},T=(e,t,n)=>{let i=x([e.name],t,g(n)),a=i.variables[0],o=e.domain&&`(${U} ${a} ${v(e.domain,t,n)})`,s=y(e.body,i.env,i.mode),c=o===void 0?s:Zs([o,s]),l=m(c,n.depth),u=r(`Choose`,c,n,e=>Gc(e,l,c,a),l.length);return d(Q(u,l))},E=(e,t,n,r)=>Vc(v(e[0],t,n),v(e[1],t,n),n.polarity,r),ne=(e,t,n)=>{let r=e.kind===`Lambda`&&e.params.length===1?e:void 0,i=x([r?.params[0].name??`x1`],t,g(n));return{body:y(r?.body??{kind:`Apply`,operator:k(1,e),args:[{kind:`Ix`,index:1}]},i.env,i.mode),variable:i.variables[0]}},re=(t,n,i,a)=>{let o=()=>n.map(e=>v(e,i,a));switch(t){case`Conj`:return u(Zs(n.map(e=>y(e,i,a))));case`Disj`:return u(Qs(n.map(e=>y(e,i,a))));case`Implies`:return u(`(=> ${y(n[0],i,_(a))} ${y(n[1],i,a)})`);case`Equiv`:return u(`(= ${n.map(e=>y(e,i,g(a))).join(` `)})`);case`Neg`:return u(`(not ${y(n[0],i,_(a))})`);case`Eq`:return u(E(n,i,a,!1));case`Neq`:return u(E(n,i,a,!0));case`Mem`:return u(Q(U,o()));case`Notmem`:return u(`(not ${Q(U,o())})`);case`Subseteq`:return u(Q(ws,o()));case`Lteq`:return u(Q(Fs,o()));case`Gteq`:return u(Q(Fs,o().toReversed()));case`Lt`:case`Gt`:{let e=()=>t===`Lt`?o():o().toReversed();return u(`(and ${Q(Fs,e())} (distinct ${e().join(` `)}))`)}case`SelectSeq`:{let e=ne(n[1],i,a),t=m(e.body,a.depth),o=r(`SelectSeq`,e.body,a,n=>Kc(n,t,e.body,e.variable),t.length+1);return d(Q(o,[v(n[0],i,a),...t]))}case`Unprimable`:{let e=D(n[0],i,g(a));return{...e,text:`(${Nc} ${e.text})`}}default:{let n=Js[t];if(n===void 0)throw new e.k(`the operator ${t}`);return d(Q(n,o()))}}},ie=(t,n,i,a)=>{switch(t.kind){case`constant`:case`variable`:if(n.length>0)throw new e.k(`an applied ${t.kind}`);return d(t.symbol);case`operator`:if(n.length!==t.arity)throw new e.k(`an operator applied to the wrong number of arguments`);return d(Q(t.symbol,n.map(e=>v(e,i,a))));case`secondOrder`:{if(n.length!==t.shapes.length)throw new e.k(`an operator applied to the wrong number of arguments`);let o=n.map((n,r)=>{if(t.shapes[r]===0)return{isFirstOrder:!0,text:v(n,i,a)};if(n.kind===`Ix`){let t=f(i,n.index);if(t.kind!==`operator`)throw new e.k(`an operator argument that isn't a LAMBDA`);return{isFirstOrder:!1,text:t.symbol}}if(n.kind!==`Lambda`)throw new e.k(`an operator argument that isn't a LAMBDA`);let o=x(n.params.map(e=>e.name),i,g(a));return{isFirstOrder:!1,text:v(n.body,o.env,o.mode)}}),s=o.flatMap(e=>e.isFirstOrder?[e.text]:[]),c=o.flatMap(e=>e.isFirstOrder?[]:[e.text]),l=m(c.join(` `),a.depth),u=r(``,c.join(` `),a,()=>[],s.length+l.length,t.name);return d(Q(u,[...s,...l]))}case`unsupported`:throw new e.k(t.reason)}},ae=(t,n)=>{if(!t)throw new e.k(`a primed declaration that isn't a variable`);let r=t.binding;return r.kind===`variable`&&r.name===n?r.primed:ae(t.rest,n)},oe=(e,t,n,r)=>{if(t.length===0&&e.endsWith(`#prime`))return d(ae(n,e.slice(0,-6)));let a=t.length===0?`Anon_OPAQUE_${e}`:`Anon_${e}`;return i.set(a,t.length),d(Q(H(a),t.map(e=>v(e,n,r))))},ce=(e,t,n)=>e.specs.reduce((e,r)=>{let i=(e,a)=>{if(a.length===0)return v(r.value,t,{...n,at:e});let o=a[0],s=()=>o.kind===`Dot`?H(`StrLit_${o.field}`):v(o.expression,t,n),c=s(),l=i(`(${q} ${e} ${a.length>1?s():c})`,a.slice(1));return`(${zs} ${e} ${c} ${l})`};return i(e,r.trail)},v(e.function,t,n)),le=()=>{t.caseErrors++;let e=`Anon_incomplete_case_error_${t.caseErrors}`;return i.set(e,0),H(e)},ue=(e,t,n)=>{let r=e.arms.map(e=>D(e.body,t,n)),i=e.other?D(e.other,t,n):d(le()),a=i.isBool&&r.every(e=>e.isBool);if(i.integer!==void 0&&r.every(e=>e.integer!==void 0)){let a=e.arms.reduceRight((e,i,a)=>`(ite ${y(i.condition,t,g(n))} ${r[a].integer} ${e})`,i.integer??``);return{isBool:!1,text:`(${G} ${a})`,integer:a}}let o=e=>a?e.text:l(e);return{isBool:a,text:e.arms.reduceRight((e,i,a)=>`(ite ${y(i.condition,t,n)} ${o(r[a])} ${e})`,o(i))}},de=(t,n,r)=>{let i=t.context.reduce((t,n)=>{switch(n.kind){case`Fresh`:{if(n.shape>0){if(!t.mode.isOmitted)throw new e.k(`a second-order ASSUME`);let r=jc(n.name,t.mode.depth);return{env:p(t.env,{kind:`operator`,symbol:r,arity:n.shape}),mode:{...t.mode,depth:t.mode.depth+1},wrappers:[...t.wrappers,e=>`(forall ((${r} Idv)) ${e})`]}}if(n.level!==`Constant`)throw new e.k(`a NEW declaration that isn't constant`);let r=n.domain&&v(n.domain,t.env,t.mode),i=x([n.name],t.env,t.mode),a=i.variables[0],o=r&&`(${U} ${a} ${r})`;return{env:i.env,mode:i.mode,wrappers:[...t.wrappers,e=>`(forall ((${a} Idv)) ${o?`(=> ${o} ${e})`:e})`]}}case`Fact`:{let e=n.visibility===`Visible`?y(n.expression,t.env,_(t.mode)):void 0;return{env:p(t.env,{kind:`unsupported`,reason:`a reference to a fact`}),mode:t.mode,wrappers:e?[...t.wrappers,t=>`(=> ${e} ${t})`]:t.wrappers}}default:throw new e.k(`a ${n.kind} in a nested ASSUME`)}},{env:n,mode:r,wrappers:[]});return i.wrappers.reduceRight((e,t)=>t(e),y(t.active,i.env,i.mode))},D=(t,n,r)=>{switch(t.kind){case`Ix`:return ie(f(n,t.index),[],n,r);case`Internal`:switch(t.builtin){case`TRUE`:return u(`true`);case`FALSE`:return u(`false`);case`BOOLEAN`:return d(Ms);case`STRING`:return d(Ns);case`Nat`:return d(W);case`Int`:return d(Ps);default:throw new e.k(`the operator ${t.builtin}`)}case`Apply`:{let i=t.operator;if(i.kind===`Internal`)return re(i.builtin,t.args,n,r);if(i.kind===`Ix`)return ie(f(n,i.index),t.args,n,r);if(i.kind===`Opaque`)return oe(i.name,t.args,n,r);if(i.kind===`Lambda`)return D(se(i,t.args),n,r);throw new e.k(`an application of ${i.kind}`)}case`Sequent`:return u(de(t.sequent,n,r));case`With`:case`Parens`:return D(t.expression,n,r);case`If`:{let e=y(t.condition,n,r),i=D(t.consequent,n,r),a=D(t.alternative,n,r);if(i.integer!==void 0&&a.integer!==void 0){let t=`(ite ${Bc(e,!0)} ${i.integer} ${a.integer})`;return{isBool:!1,text:`(${G} ${t})`,integer:t}}return i.isBool&&a.isBool?u(`(ite ${e} ${i.text} ${a.text})`):d(`(ite ${e} ${l(i)} ${l(a)})`)}case`List`:{let e=t.items.map(e=>y(e,n,r));return u(t.bullet===`Or`?Qs(e):Zs(e))}case`Opaque`:return oe(t.name,[],n,r);case`Quant`:return u(S(t,n,r));case`Choose`:return T(t,n,r);case`SetSt`:return C(t,n,r);case`SetOf`:return te(t,n,r);case`SetEnum`:return d(Q(H(`SetEnum_${t.elements.length}`),t.elements.map(e=>v(e,n,r))));case`Product`:return d(Q(H(`Product_${t.factors.length}`),t.factors.map(e=>v(e,n,r))));case`Tuple`:return d(Q(H(`Tuple_${t.elements.length}`),t.elements.map(e=>v(e,n,r))));case`Fcn`:return w(t,n,r);case`FcnApp`:{let e=v(t.function,n,r),i=t.args.map(e=>v(e,n,r)),a=i.length===1?i[0]:Q(H(`Tuple_${i.length}`),i);return d(`(${q} ${e} ${a})`)}case`Arrow`:return d(Q(Rs,[v(t.domain,n,r),v(t.range,n,r)]));case`Record`:case`Rect`:{let e=t.fields.map(e=>e.name),i=e.join(`_`);return a.set(`Record_${i}`,e),a.set(`RecordSet_${i}`,e),d(Q(H(`${t.kind===`Record`?`Record`:`RecordSet`}_${i}`),t.fields.map(e=>v(e.value,n,r))))}case`Except`:return d(ce(t,n,r));case`Dot`:return d(`(${q} ${v(t.expression,n,r)} ${H(`StrLit_${t.field}`)})`);case`Case`:return ue(t,n,r);case`String`:return d(H(`StrLit_${t.value}`));case`Num`:if(t.fraction!==``)throw new e.k(`a real number`);return{isBool:!1,text:`(${G} ${BigInt(t.integer)})`,integer:String(BigInt(t.integer))};case`At`:if(r.at===void 0)throw new e.k(`@ outside EXCEPT`);return d(r.at);case`Tquant`:case`Tsub`:case`Fair`:throw new e.k(`a temporal formula`);default:throw new e.k(`the expression ${t.kind}`)}};return{encodeIdv:v,encodeBool:y,push:p,getEntries:e=>[...n.takeIntroduced(),Pc(Bc(e,!1))],getUniqueName:h,flattened:n.flattened,anonymous:i,recordFields:a,declared:s}},Jc={isOmitted:!1,polarity:`Negative`,at:void 0,depth:0},Yc=e=>e.definition.kind===`Bpragma`||e.definition.kind===`Operator`&&e.visibility===`Visible`,Xc=e=>e.kind===`Sequent`&&e.sequent.context.some(e=>e.kind===`Fresh`&&e.shape>0),Zc=(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=$s(i,n.shape);if(!n.domain||n.domainVisibility===`Hidden`)return r(a,[o]);let s=`(assert (${U} ${i} ${t.encodeIdv(n.domain,e.env,Jc)}))`;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},[$s(e,0),$s(i,0)])}case`Defn`:{let e=n.definition;if(Yc(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},[$s(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},[$s(o,a.length)])}case`Fact`:{let i={kind:`unsupported`,reason:`a reference to a fact`};if(n.visibility===`Hidden`)return r(i);let a=Xc(n.expression),o=t.getEntries(`(assert ${t.encodeBool(n.expression,e.env,{...Jc,isOmitted:a})})`);return r(i,a?o.map(e=>typeof e==`string`?{omitted:e}:e):o)}}},{env:void 0,entries:[]}),Qc=(e,t)=>{let n=Ac(kc({kind:`Sequent`,sequent:e})),r=n.kind===`Sequent`?n.sequent:e,i=qc(t),a=Zc(r.context,i),o=Xc(r.active)?[]:i.getEntries(`(assert (! (not ${i.encodeBool(r.active,a.env,{...Jc,polarity:`Positive`})}) :named |Goal|))`),s=[...a.entries,...o],c=Tc(i.declared),l=Sc(s,i.flattened,i.anonymous,i.recordFields),u=[...l.symbols].toSorted((e,t)=>hs(e[0],t[0])).flatMap(e=>e[1].declaration===void 0?[]:[e[1].declaration]),d=[...l.axioms.values()].toSorted(sc).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`)&&!Yc(e))?[`(declare-sort Idv 0)`]:[],...p].map(c.resolve).concat(`(check-sat)`,`(exit)`).join(`
|
|
33
|
+
`)},$c=F(`@ `),el={TRUE:`T.`,FALSE:`F.`,STRING:`TLA.STRING`,BOOLEAN:`(TLA.set T. F.)`,Nat:`arith.N`,Int:`arith.Z`,Real:`arith.R`,Infinity:`arith.Infinity`,Any:`TLA.Any`},tl={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]},nl=e=>{let t=Number.parseInt(e,10);return`${`(TLA.fapply TLA.Succ `.repeat(t)}0${`)`.repeat(t)}`},rl=(t,n)=>{let r=Vt(),i=e=>Ut(r,$i(e)),a=()=>Ut(r,``),o=e=>I(e,m,$c),s=(e,t)=>F(`(%s %a)`,e,o(t)),c=(e,t,n)=>{let a=i(e),o=F(`%a((%s) %a))`,t,a,m(n));return Wt(r,1),o},l=(e,t)=>{let n=el[e];if(n!==void 0&&t.length===0)return P(n);let r=tl[e];if(r&&r[1]===t.length)return s(r[0],t);if(t.length===2)switch(e){case`Neq`:return F(`(-. %a)`,s(`=`,t));case`Notmem`:return F(`(-. %a)`,s(`TLA.in`,t));case`Minus`:return s(`arith.add`,[t[0],{kind:`Apply`,operator:{kind:`Internal`,builtin:`Uminus`,location:t[1].location},args:[t[1]],location:t[1].location}]);case`Gteq`:return s(`arith.le`,t.toReversed());case`Gt`:return s(`arith.lt`,t.toReversed())}if(e===`Unprimable`&&t.length===1)return m(t[0]);throw ta(e,t.length,`Backend.Zenon.fmt_apply`)},u=(t,n)=>{switch(t.kind){case`Ix`:{let i=Ht(r,t.index);if(t.index<=0||i===void 0)throw new e.j;return n.length===0?P(i):s(i,n)}case`Opaque`:{let e=$i(t.name);return n.length===0?P(e):s(e,n)}case`Internal`:return l(t.builtin,n);case`Lambda`:{let e=t.params.map(e=>F(`%s `,i(e.name))),n=F(`((%a) %a)`,e,m(t.body));return Wt(r,t.params.length),n}default:throw new e.j}},d=(t,n,r)=>{if(n.length===0)return m(r);let i=na(t,n,r),a=t===`Forall`;if(i.first.domain.kind===`NoDomain`)return c(i.first.name,P(a?`(A. `:`(E. `),i.inner);if(i.first.domain.kind!==`Domain`)throw new e.j;let o=m(i.first.domain.expression);return c(i.first.name,F(`(%s %a `,a?`TLA.bAll`:`TLA.bEx`,o),i.inner)},f=(t,n,r,i)=>{if(n.length!==1)throw new e.k(`${i} (multiple declared constants)`);let a=n[0];if(a.domain.kind!==`Domain`)throw new e.j;return c(a.name,F(`(%s %a `,t,m(a.domain.expression)),r)},p=t=>{if(t.context.length===0)return m(t.active);let n=t.context[0],o=()=>p({context:t.context.slice(1),active:t.active});if(n.kind===`Fact`){let e=n.visibility===`Visible`?m(n.expression):void 0;a();let t=e?F(`(=> %a %a)`,e,o()):o();return Wt(r,1),t}if(n.kind===`Defn`)throw new e.j;let s=n.kind===`Fresh`&&n.domain&&n.domainVisibility===`Visible`?m(n.domain):void 0,c=i(n.name),l=n.kind===`Flex`?F(`(A. ((%s) (A. ((%s') %a))))`,c,c,o()):s?F(`(TLA.bAll %a ((%s) %a))`,s,c,o()):F(`(A. ((%s) %a))`,c,o());return Wt(r,1),l},m=t=>{switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`Lambda`:return u(t,[]);case`Apply`:return u(t.operator,t.args);case`Sequent`:return p(t.sequent);case`With`:case`Parens`:return m(t.expression);case`If`:return F(`(TLA.cond %a %a %a)`,m(t.condition),m(t.consequent),m(t.alternative));case`List`:if(t.bullet===`Refs`&&t.items.length===0)throw new e.j;return t.bullet===`Refs`&&t.items.length===1?m(t.items[0]):F(`(%s %a)`,t.bullet===`Or`?`\\/`:`/\\`,o(t.items));case`Quant`:return d(t.quantifier,t.bounds,t.body);case`Tquant`:throw new e.k(`\\AA or \\EE`);case`Choose`:return t.domain?c(t.name,F(`(TLA.bChoice %a `,m(t.domain)),t.body):c(t.name,P(`(t. `),t.body);case`SetSt`:return c(t.name,F(`(TLA.subsetOf %a `,m(t.domain)),t.body);case`SetOf`:return f(`TLA.setOfAll`,t.bounds,t.element,`Setof`);case`Fcn`:return f(`TLA.Fcn`,t.bounds,t.body,`Fcn`);case`SetEnum`:return t.elements.length===0?P(`TLA.emptyset`):[P(`(TLA.set`),t.elements.map(e=>F(` %a`,m(e))),P(`)`)];case`FcnApp`:{let e=m(t.function);return t.args.length===1?F(`(TLA.fapply %a %a)`,e,m(t.args[0])):F(`(TLA.fapply %a (TLA.tuple %a))`,e,o(t.args))}case`Arrow`:return F(`(TLA.FuncSet %a %a)`,m(t.domain),m(t.range));case`Rect`:case`Record`:return[P(t.kind===`Rect`?`(TLA.recordset`:`(TLA.record`),t.fields.map(e=>F(` "%s" %a`,e.name,m(e.value))),P(`)`)];case`Except`:{let n=t.specs[0];if(t.specs.length!==1||n.trail.length!==1)throw new e.k(`complex EXCEPT`);let r=n.trail[0],i=r.kind===`Dot`?P(`"${r.field}"`):m(r.expression);return F(`(TLA.except %a %a %a)`,m(t.function),i,m(n.value))}case`Dot`:return F(`(TLA.fapply %a "%s")`,m(t.expression),t.field);case`Tuple`:return F(`(TLA.tuple %a)`,o(t.elements));case`Product`:return t.factors.length===2?F(`(TLA.prod %a %a)`,m(t.factors[0]),m(t.factors[1])):F(`(TLA.Product (TLA.tuple %a))`,o(t.factors));case`Sub`:case`Tsub`:case`Fair`:throw new e.k(t.kind);case`Case`:{let e=I(t.arms,e=>F(`%a %a`,m(e.condition),m(e.body)),$c);return t.other?F(`(TLA.CASE %a %a)@]`,e,m(t.other)):F(`(TLA.CASE %a )`,e)}case`String`:return F(`"%s"`,t.value);case`Num`:if(t.fraction!==``)throw new e.k(`Real number constants`);return P(nl(t.integer));case`Bang`:case`Let`:case`At`:throw new e.j}},h=t=>{switch(t.kind){case`Fresh`:{let e=t.domain&&t.domainVisibility===`Visible`?m(t.domain):void 0,n=i(t.name);return e?F(`$hyp "%s_in" (TLA.in %s %a)@
|
|
34
|
+
`,n,n,e):[]}case`Flex`:return i(t.name),[];case`Defn`:{let e=i(t.definition.name);return t.visibility===`Visible`?F(`; usable definition %s suppressed@.`,e):[]}case`Fact`:{let n=String(r.stack.length),i=t.visibility===`Visible`?ra(r,()=>m(t.expression)):void 0;return a(),i instanceof e.k?F(`; omitted temporal assumption : %s @.`,i.message):i?F(`$hyp "v'%s" %a@
|
|
35
|
+
`,n,i):[]}}},g=(()=>{try{return[n.context.map(h),F(`$goal %a`,m(n.active))]}catch(t){throw t instanceof e.k?new e.w(`Zenon: unsupported operator ${t.message}`):t}})();return zt([F(`;; obligation #%s@
|
|
36
|
+
`,String(t)),g])},il=e=>Jo($a(e)),al={encode:(e,t,n,r)=>(n.rlimit===void 0?``:`(set-option :rlimit ${n.rlimit})\n`)+Qc(il(t),r)},ol={smt:al,z3:al,zenon:{encode:(e,t)=>rl(e,il(t))},isabelle:{encode:(e,t,n)=>pa(e,il(t),n.tactic??`auto`)},ls4:{encode:(e,t)=>ms(t)}},sl=e=>e.kind===`Case`&&e.other===void 0||we(e).some(sl),cl=/* @__PURE__ */ new WeakMap,ll=e=>{let t=cl.get(e);if(t!==void 0)return t;let n=[];Se(e,e=>(n.push(e),e),`all`);let r=n.some(sl);return cl.set(e,r),r},ul=e=>/-{4,}\s*MODULE\s+(\w+)/.exec(e)?.[1]??`Main`,dl=e=>({id:e.id,location:e.location,text:e.text}),fl=(e,t,n,r=[])=>({obligation:{...dl(e),status:t,reason:n},attempts:r}),pl=(e,t=rs(e))=>Po(ho(ro(e.sequent)),t.frontends),ml=(e,t)=>`${fn(t?ho(ro(e.sequent,!1)):pl(e))}\n`,hl=(e,t,n)=>ma(e,t.flatMap((e,t)=>e.attempts.filter(e=>e.method.prover===`isabelle`&&e.isProved&&!e.isReused).map(r=>({id:e.obligation.id,sequent:il(pl(n[t])),tactic:r.method.tactic??`auto`})))),gl=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},_l=async(t,n,r,i)=>{if(t.kind.kind===`Error`)return fl(t,`failed`,t.kind.message);let a=rs(t),o=Go(t.sequent),s=r.lastByFingerprint.get(o);r.lastByFingerprint.set(o,r.tasks[n].done),await s;let c=[],l=[],u=e=>({obligation:{...dl(t),status:`proved`,prover:e},attempts:c}),d=e=>{r.isFingerprinted(t)||r.results.delete(o);let n=r.results.get(o)?.get(e.prover);return n?.method.tactic===e.tactic?n:void 0},f=e=>e.rlimit??e.timeLimitMs/1e3,p=e=>c.push({...e,isReused:!0,timeUsedMs:void 0}),m=e=>{c.push(e),r.results.set(o,(r.results.get(o)??/* @__PURE__ */ new Map).set(e.method.prover,e))},h=(e,t)=>{c.push({method:e,isProved:!1,isReused:!1,reason:t}),l.push({reason:t,isDecided:!1})},g=d(a.provers[0]);if(g?.isProved)return p(g),u(g.method.prover);let _=pl(t,a);if(t.kind.kind===`Support`&&is(_))return r.results.set(o,r.results.get(o)??/* @__PURE__ */ new Map),{obligation:{...dl(t),status:`trivial`},attempts:c};for(let o of a.provers){let a=d(o);if(a?.isProved)return p(a),u(o.prover);if(a&&f(a.method)>=f(o)){p(a),l.push({reason:`${o.prover} failed on an obligation with the same fingerprint`,isDecided:!0});continue}if(!r.isProving)continue;if(o.prover===`trivial`)return u(o.prover);let s=ol[o.prover];if(!s)h(o,`tla-ts has no ${o.prover} backend`);else try{let e=s===al&&(_.context.some(ll)||sl(_.active))?await gl(r,n):{caseErrors:0},a=s.encode(t.id,_,o,e),c=await r.decide(o.prover,a,{timeLimitMs:o.timeLimitMs,signal:i},n),d=c.verdict===`unsat`;if(m({method:o,isProved:d,isReused:!1,...!d&&{reason:c.timeUsedMs>=o.timeLimitMs?`timeout`:`false`},verdict:c.verdict,timeUsedMs:c.timeUsedMs}),d)return u(o.prover);l.push({reason:`${o.prover} answered ${c.verdict}`,isDecided:!0})}catch(t){if(t instanceof e.w){m({method:o,isProved:!1,isReused:!1,reason:`false`}),l.push({reason:`${o.prover} failed: ${t.message}`,isDecided:!0});continue}if(!(t instanceof e.k))throw t;h(o,`${o.prover} can't encode ${t.message}`)}}return fl(t,l.some(e=>e.isDecided)?`failed`:`unsupported`,l.map(e=>e.reason).join(`, `),c)},vl=(t,n)=>{if(n instanceof e.k)return fl(t,`unsupported`,n.message);if(n instanceof e.w)return fl(t,`failed`,n.message);throw n},yl=async(t,r)=>{let i=r.workers??1,a=i>1&&e.n()?await Ji(i):void 0,o=()=>a?.terminate(r.signal?.reason);r.signal?.addEventListener(`abort`,o);let s={tasks:[],results:r.results??/* @__PURE__ */ new Map,isFingerprinted:r.isFingerprinted??(()=>!0),isProving:r.isProving??!0,lastByFingerprint:/* @__PURE__ */ new Map,decide:a?.decide??(async(e,t,r)=>n.t(e,t,r))},c=a?i*4:1,l=[],u=[],d=/* @__PURE__ */ new Set,f=[],p=async()=>{for(;u[f.length];){r.signal?.throwIfAborted();let e=await l[f.length];f.push(e),r.onReport?.(e,t[f.length-1]),await new Promise(e=>setTimeout(e))}};try{for(let[e,n]of t.entries()){r.signal?.throwIfAborted();let t=Promise.withResolvers();s.tasks.push({done:t.promise,session:void 0});let i=_l(n,e,s,r.signal).catch(e=>vl(n,e));l.push(i),d.add(t.promise);let a=()=>{u[e]=!0,d.delete(t.promise),t.resolve()};i.then(a,a),d.size>=c&&await Promise.race(d),await p()}await Promise.all(d),await p()}finally{r.signal?.removeEventListener(`abort`,o),a?.terminate(new e.w(`prove stopped`))}return f},bl=(e,t)=>t?{...dl(e),...t}:{...dl(e),status:`unsupported`,reason:`tlapm reported no result`},xl=async t=>{let n=ul(t.source),r=/* @__PURE__ */ new Map,i=qi([{file:`${n}.tla`,source:t.source}],e=>{let n=t.loadModule?.(e);n!==void 0&&r.set(e,n);let i=n??(e===`TLAPS`?`------------------------------- MODULE TLAPS --------------------------------
|
|
37
|
+
|
|
38
|
+
(* Backend pragmas. *)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
(***************************************************************************)
|
|
42
|
+
(* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
|
|
43
|
+
(* is added to the context of an obligation most recently is the one whose *)
|
|
44
|
+
(* effects are triggered. *)
|
|
45
|
+
(***************************************************************************)
|
|
46
|
+
|
|
47
|
+
(***************************************************************************)
|
|
48
|
+
(* The following pragmas should be used only as a last resource. They are *)
|
|
49
|
+
(* dependent upon the particular backend provers, and are unlikely to have *)
|
|
50
|
+
(* any effect if the set of backend provers changes. Moreover, they are *)
|
|
51
|
+
(* meaningless to a reader of the proof. *)
|
|
52
|
+
(***************************************************************************)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
(**************************************************************************)
|
|
56
|
+
(* Backend pragma: use the SMT solver for arithmetic. *)
|
|
57
|
+
(* *)
|
|
58
|
+
(* This method exists under this name for historical reasons. *)
|
|
59
|
+
(**************************************************************************)
|
|
60
|
+
|
|
61
|
+
SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
(**************************************************************************)
|
|
65
|
+
(* Backend pragma: SMT solver *)
|
|
66
|
+
(* *)
|
|
67
|
+
(* This method translates the proof obligation to SMTLIB2. The supported *)
|
|
68
|
+
(* fragment includes first-order logic, set theory, functions and *)
|
|
69
|
+
(* records. *)
|
|
70
|
+
(* SMT calls the smt-solver with the default timeout of 5 seconds *)
|
|
71
|
+
(* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
|
|
72
|
+
(* *)
|
|
73
|
+
(* SMTT also accepts a string argument of the form "rN" to bound the *)
|
|
74
|
+
(* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
|
|
75
|
+
(* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
|
|
76
|
+
(* resource count, so a small readable budget like "r5" is meaningful. *)
|
|
77
|
+
(* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
|
|
78
|
+
(* speed or load, so the proof's pass/fail outcome reproduces on any *)
|
|
79
|
+
(* machine and every rerun (for a fixed Z3 build); how long it takes to *)
|
|
80
|
+
(* consume the budget still varies by machine. This is Z3-specific. *)
|
|
81
|
+
(**************************************************************************)
|
|
82
|
+
|
|
83
|
+
SMT == TRUE (*{ by (prover:"smt3") }*)
|
|
84
|
+
SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
(**************************************************************************)
|
|
88
|
+
(* Backend pragma: CVC4 SMT solver *)
|
|
89
|
+
(* *)
|
|
90
|
+
(* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
|
|
91
|
+
(**************************************************************************)
|
|
92
|
+
|
|
93
|
+
(* The CVC3* methods are here for backward compatibility. They call CVC4. *)
|
|
94
|
+
CVC3 == TRUE (*{ by (prover: "cvc33") }*)
|
|
95
|
+
CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
|
|
96
|
+
|
|
97
|
+
CVC4 == TRUE (*{ by (prover: "cvc33") }*)
|
|
98
|
+
CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
(**************************************************************************)
|
|
102
|
+
(* Backend pragma: Yices SMT solver *)
|
|
103
|
+
(* *)
|
|
104
|
+
(* This method translates the proof obligation to Yices native language. *)
|
|
105
|
+
(**************************************************************************)
|
|
106
|
+
|
|
107
|
+
Yices == TRUE (*{ by (prover: "yices3") }*)
|
|
108
|
+
YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
|
|
109
|
+
|
|
110
|
+
(**************************************************************************)
|
|
111
|
+
(* Backend pragma: veriT SMT solver *)
|
|
112
|
+
(* *)
|
|
113
|
+
(* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
|
|
114
|
+
(**************************************************************************)
|
|
115
|
+
|
|
116
|
+
veriT == TRUE (*{ by (prover: "verit") }*)
|
|
117
|
+
veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
|
|
118
|
+
|
|
119
|
+
(**************************************************************************)
|
|
120
|
+
(* Backend pragma: Zipperposition solver *)
|
|
121
|
+
(* *)
|
|
122
|
+
(* This method translates the proof obligation to TPTP and *)
|
|
123
|
+
(* calls Zipperposition. *)
|
|
124
|
+
(**************************************************************************)
|
|
125
|
+
|
|
126
|
+
Zipper == TRUE (*{ by (prover: "zipper") }*)
|
|
127
|
+
ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
|
|
128
|
+
|
|
129
|
+
(**************************************************************************)
|
|
130
|
+
(* Backend pragma: Z3 SMT solver *)
|
|
131
|
+
(* *)
|
|
132
|
+
(* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
|
|
133
|
+
(* Z3 is used by default but you can also explicitly call it. *)
|
|
134
|
+
(* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
|
|
135
|
+
(* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
|
|
136
|
+
(* reproduces the same outcome on any machine (see SMTT). *)
|
|
137
|
+
(**************************************************************************)
|
|
138
|
+
|
|
139
|
+
Z3 == TRUE (*{ by (prover: "z33") }*)
|
|
140
|
+
Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
|
|
141
|
+
|
|
142
|
+
(**************************************************************************)
|
|
143
|
+
(* Backend pragma: SPASS superposition prover *)
|
|
144
|
+
(* *)
|
|
145
|
+
(* This method translates the proof obligation to the DFG format language *)
|
|
146
|
+
(* supported by the ATP SPASS. The translation is based on the SMT one. *)
|
|
147
|
+
(**************************************************************************)
|
|
148
|
+
|
|
149
|
+
Spass == TRUE (*{ by (prover: "spass") }*)
|
|
150
|
+
SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
|
|
151
|
+
|
|
152
|
+
(**************************************************************************)
|
|
153
|
+
(* Backend pragma: The PTL propositional linear time temporal logic *)
|
|
154
|
+
(* prover. It currently is the LS4 backend. *)
|
|
155
|
+
(* *)
|
|
156
|
+
(* This method translates the negetation of the proof obligation to *)
|
|
157
|
+
(* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
|
|
158
|
+
(**************************************************************************)
|
|
159
|
+
|
|
160
|
+
LS4 == TRUE (*{ by (prover: "ls4") }*)
|
|
161
|
+
LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
|
|
162
|
+
PTL == TRUE (*{ by (prover: "ls4") }*)
|
|
163
|
+
|
|
164
|
+
(**************************************************************************)
|
|
165
|
+
(* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
|
|
166
|
+
(* *)
|
|
167
|
+
(**************************************************************************)
|
|
168
|
+
|
|
169
|
+
Zenon == TRUE (*{ by (prover:"zenon") }*)
|
|
170
|
+
ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
|
|
171
|
+
|
|
172
|
+
(********************************************************************)
|
|
173
|
+
(* Backend pragma: Isabelle with different timeouts and tactics *)
|
|
174
|
+
(* (default is 30 seconds/auto) *)
|
|
175
|
+
(********************************************************************)
|
|
176
|
+
|
|
177
|
+
Isa == TRUE (*{ by (prover:"isabelle") }*)
|
|
178
|
+
IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
|
|
179
|
+
IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
|
|
180
|
+
IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
|
|
181
|
+
|
|
182
|
+
(***************************************************************************)
|
|
183
|
+
(* The following theorem expresses the (useful implication of the) law of *)
|
|
184
|
+
(* set extensionality, which can be written as *)
|
|
185
|
+
(* *)
|
|
186
|
+
(* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
|
|
187
|
+
(* *)
|
|
188
|
+
(* Theorem SetExtensionality is sometimes required by the SMT backend for *)
|
|
189
|
+
(* reasoning about sets. It is usually counterproductive to include *)
|
|
190
|
+
(* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
|
|
191
|
+
(* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
|
|
192
|
+
(* the Isabelle backend to use the rule of set extensionality. *)
|
|
193
|
+
(***************************************************************************)
|
|
194
|
+
IsaWithSetExtensionality == TRUE
|
|
195
|
+
(*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
|
|
196
|
+
|
|
197
|
+
THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
|
|
198
|
+
OBVIOUS
|
|
199
|
+
|
|
200
|
+
(***************************************************************************)
|
|
201
|
+
(* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
|
|
202
|
+
(* the definition *)
|
|
203
|
+
(* *)
|
|
204
|
+
(* NotInSetS == CHOOSE v : v \\notin SetS *)
|
|
205
|
+
(***************************************************************************)
|
|
206
|
+
THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
|
|
207
|
+
OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
|
|
208
|
+
-----------------------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
(********************************************************************)
|
|
213
|
+
(********************************************************************)
|
|
214
|
+
(********************************************************************)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
(********************************************************************)
|
|
218
|
+
(* Old versions of Zenon and Isabelle pragmas below *)
|
|
219
|
+
(* (kept for compatibility) *)
|
|
220
|
+
(********************************************************************)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
(**************************************************************************)
|
|
224
|
+
(* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
|
|
225
|
+
(* *)
|
|
226
|
+
(**************************************************************************)
|
|
227
|
+
|
|
228
|
+
SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
|
|
229
|
+
SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
|
|
230
|
+
VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
|
|
231
|
+
SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
(********************************************************************)
|
|
236
|
+
(* Backend pragma: Isabelle's automatic search ("auto") *)
|
|
237
|
+
(* *)
|
|
238
|
+
(* This pragma bypasses Zenon. It is useful in situations involving *)
|
|
239
|
+
(* essentially simplification and equational reasoning. *)
|
|
240
|
+
(* Default imeout for all isabelle tactics is 30 seconds. *)
|
|
241
|
+
(********************************************************************)
|
|
242
|
+
Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
|
|
243
|
+
SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
|
|
244
|
+
SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
|
|
245
|
+
SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
|
|
246
|
+
|
|
247
|
+
(********************************************************************)
|
|
248
|
+
(* Backend pragma: Isabelle's "force" tactic *)
|
|
249
|
+
(* *)
|
|
250
|
+
(* This pragma bypasses Zenon. It is useful in situations involving *)
|
|
251
|
+
(* quantifier reasoning. *)
|
|
252
|
+
(********************************************************************)
|
|
253
|
+
Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
|
|
254
|
+
SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
|
|
255
|
+
SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
|
|
256
|
+
SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
|
|
257
|
+
|
|
258
|
+
(***********************************************************************)
|
|
259
|
+
(* Backend pragma: Isabelle's "simplification" tactics *)
|
|
260
|
+
(* *)
|
|
261
|
+
(* These tactics simplify the goal before running one of the automated *)
|
|
262
|
+
(* tactics. They are often necessary for obligations involving record *)
|
|
263
|
+
(* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
|
|
264
|
+
(* sure you can get away with just Simplification *)
|
|
265
|
+
(***********************************************************************)
|
|
266
|
+
SimplifyAndSolve == TRUE
|
|
267
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
|
|
268
|
+
SlowSimplifyAndSolve == TRUE
|
|
269
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
|
|
270
|
+
SlowerSimplifyAndSolve == TRUE
|
|
271
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
|
|
272
|
+
SlowestSimplifyAndSolve == TRUE
|
|
273
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
|
|
274
|
+
|
|
275
|
+
Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
|
|
276
|
+
SlowSimplification == TRUE
|
|
277
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
|
|
278
|
+
SlowerSimplification == TRUE
|
|
279
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
|
|
280
|
+
SlowestSimplification == TRUE
|
|
281
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
|
|
282
|
+
|
|
283
|
+
(**************************************************************************)
|
|
284
|
+
(* Backend pragma: Isabelle's tableau prover ("blast") *)
|
|
285
|
+
(* *)
|
|
286
|
+
(* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
|
|
287
|
+
(* prover, Blast. It is almost never better than Zenon by itself, but *)
|
|
288
|
+
(* becomes very useful in combination with the Auto pragma above. The *)
|
|
289
|
+
(* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
|
|
290
|
+
(* Auto could not prove. (There is currently no way to use Zenon on the *)
|
|
291
|
+
(* results left over from Auto.) *)
|
|
292
|
+
(**************************************************************************)
|
|
293
|
+
Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
|
|
294
|
+
SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
|
|
295
|
+
SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
|
|
296
|
+
SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
|
|
297
|
+
|
|
298
|
+
AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
(**************************************************************************)
|
|
302
|
+
(* Backend pragmas: multi-back-ends *)
|
|
303
|
+
(* *)
|
|
304
|
+
(* These pragmas just run a bunch of back-ends one after the other in the *)
|
|
305
|
+
(* hope that one will succeed. This saves time and effort for the user at *)
|
|
306
|
+
(* the expense of computation time. *)
|
|
307
|
+
(**************************************************************************)
|
|
308
|
+
|
|
309
|
+
(* CVC3 goes first because it's bundled with TLAPS, then the other SMT
|
|
310
|
+
solvers are unlikely to succeed if CVC3 fails, so we run zenon and
|
|
311
|
+
Isabelle before them. *)
|
|
312
|
+
AllProvers == TRUE (*{
|
|
313
|
+
by (prover:"cvc33")
|
|
314
|
+
by (prover:"zenon")
|
|
315
|
+
by (prover:"isabelle"; tactic:"auto")
|
|
316
|
+
by (prover:"spass")
|
|
317
|
+
by (prover:"smt3")
|
|
318
|
+
by (prover:"yices3")
|
|
319
|
+
by (prover:"verit")
|
|
320
|
+
by (prover:"z33")
|
|
321
|
+
by (prover:"isabelle"; tactic:"force")
|
|
322
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
|
|
323
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?")
|
|
324
|
+
by (prover:"isabelle"; tactic:"clarsimp")
|
|
325
|
+
by (prover:"isabelle"; tactic:"auto, blast")
|
|
326
|
+
}*)
|
|
327
|
+
AllProversT(X) == TRUE (*{
|
|
328
|
+
by (prover:"cvc33"; timeout:@)
|
|
329
|
+
by (prover:"zenon"; timeout:@)
|
|
330
|
+
by (prover:"isabelle"; tactic:"auto"; timeout:@)
|
|
331
|
+
by (prover:"spass"; timeout:@)
|
|
332
|
+
by (prover:"smt3"; timeout:@)
|
|
333
|
+
by (prover:"yices3"; timeout:@)
|
|
334
|
+
by (prover:"verit"; timeout:@)
|
|
335
|
+
by (prover:"z33"; timeout:@)
|
|
336
|
+
by (prover:"isabelle"; tactic:"force"; timeout:@)
|
|
337
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
|
|
338
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
|
|
339
|
+
by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
|
|
340
|
+
by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
|
|
341
|
+
}*)
|
|
342
|
+
|
|
343
|
+
AllSMT == TRUE (*{
|
|
344
|
+
by (prover:"cvc33")
|
|
345
|
+
by (prover:"smt3")
|
|
346
|
+
by (prover:"yices3")
|
|
347
|
+
by (prover:"verit")
|
|
348
|
+
by (prover:"z33")
|
|
349
|
+
}*)
|
|
350
|
+
AllSMTT(X) == TRUE (*{
|
|
351
|
+
by (prover:"cvc33"; timeout:@)
|
|
352
|
+
by (prover:"smt3"; timeout:@)
|
|
353
|
+
by (prover:"yices3"; timeout:@)
|
|
354
|
+
by (prover:"verit"; timeout:@)
|
|
355
|
+
by (prover:"z33"; timeout:@)
|
|
356
|
+
}*)
|
|
357
|
+
|
|
358
|
+
AllIsa == TRUE (*{
|
|
359
|
+
by (prover:"isabelle"; tactic:"auto")
|
|
360
|
+
by (prover:"isabelle"; tactic:"force")
|
|
361
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
|
|
362
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?")
|
|
363
|
+
by (prover:"isabelle"; tactic:"clarsimp")
|
|
364
|
+
by (prover:"isabelle"; tactic:"auto, blast")
|
|
365
|
+
}*)
|
|
366
|
+
AllIsaT(X) == TRUE (*{
|
|
367
|
+
by (prover:"isabelle"; tactic:"auto"; timeout:@)
|
|
368
|
+
by (prover:"isabelle"; tactic:"force"; timeout:@)
|
|
369
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
|
|
370
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
|
|
371
|
+
by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
|
|
372
|
+
by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
|
|
373
|
+
}*)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
(**************************************************************************)
|
|
377
|
+
(* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
|
|
378
|
+
(* *)
|
|
379
|
+
(* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
|
|
380
|
+
(* *)
|
|
381
|
+
(* The pragma AutoUSE invokes automated expansion of definitions, *)
|
|
382
|
+
(* for both of ExpandEnabled and ExpandCdot, when each is present. *)
|
|
383
|
+
(* *)
|
|
384
|
+
(* The pragma Lambdify invokes expansion of the operators *)
|
|
385
|
+
(* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
|
|
386
|
+
(* which is a form before introducing rigid quantifiers. *)
|
|
387
|
+
(* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
|
|
388
|
+
(* that are not nested. *)
|
|
389
|
+
(**************************************************************************)
|
|
390
|
+
ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
|
|
391
|
+
ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
|
|
392
|
+
AutoUSE == TRUE (*{ by (prover:"autouse") }*)
|
|
393
|
+
Lambdify == TRUE (*{ by (prover:"lambdify") }*)
|
|
394
|
+
ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
|
|
395
|
+
LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
|
|
396
|
+
|
|
397
|
+
(* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
|
|
398
|
+
(* representation within TLAPM. *)
|
|
399
|
+
EnabledWrapper(Op(_)) == FALSE
|
|
400
|
+
CdotWrapper(Op(_)) == FALSE
|
|
401
|
+
|
|
402
|
+
(***************************************************************************)
|
|
403
|
+
(* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
|
|
404
|
+
(* triviality checks in TLAPM. *)
|
|
405
|
+
(***************************************************************************)
|
|
406
|
+
Trivial == TRUE (*{ by (prover:"trivial") }*)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
=============================================================================
|
|
410
|
+
|
|
411
|
+
The material below is obsolete: the TLA proof rules below are superseded by
|
|
412
|
+
the PTL decision procedure, and their formulation is unsound for the semantics
|
|
413
|
+
of temporal reasoning that TLAPS adopts.
|
|
414
|
+
|
|
415
|
+
----------------------------------------------------------------------------
|
|
416
|
+
(***************************************************************************)
|
|
417
|
+
(* TEMPORAL LOGIC *)
|
|
418
|
+
(* *)
|
|
419
|
+
(* The following rules are intended to be used when TLAPS handles temporal *)
|
|
420
|
+
(* logic. They will not work now. Moreover when temporal reasoning is *)
|
|
421
|
+
(* implemented, these rules may be changed or omitted, and additional *)
|
|
422
|
+
(* rules will probably be added. However, they are included mainly so *)
|
|
423
|
+
(* their names will be defined, preventing the use of identifiers that are *)
|
|
424
|
+
(* likely to produce name clashes with future versions of this module. *)
|
|
425
|
+
(***************************************************************************)
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
(***************************************************************************)
|
|
429
|
+
(* The following proof rules (and their names) are from the paper "The *)
|
|
430
|
+
(* Temporal Logic of Actions". *)
|
|
431
|
+
(***************************************************************************)
|
|
432
|
+
THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
|
|
433
|
+
P /\\ (f' = f) => P'
|
|
434
|
+
PROVE []P <=> P /\\ [][P => P']_f
|
|
435
|
+
|
|
436
|
+
THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
|
|
437
|
+
ACTION A, ACTION B,
|
|
438
|
+
P /\\ [A]_f => Q /\\ [B]_g
|
|
439
|
+
PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
|
|
440
|
+
|
|
441
|
+
THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
|
|
442
|
+
I /\\ [N]_F => I'
|
|
443
|
+
PROVE I /\\ [][N]_F => []I
|
|
444
|
+
|
|
445
|
+
THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
|
|
446
|
+
PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
|
|
447
|
+
|
|
448
|
+
THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
|
|
449
|
+
P /\\ [N]_f => (P' \\/ Q'),
|
|
450
|
+
P /\\ <<N /\\ A>>_f => Q',
|
|
451
|
+
P => ENABLED <<A>>_f
|
|
452
|
+
PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
|
|
453
|
+
|
|
454
|
+
THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
|
|
455
|
+
ACTION N, ACTION A, TEMPORAL F,
|
|
456
|
+
P /\\ [N]_f => (P' \\/ Q'),
|
|
457
|
+
P /\\ <<N /\\ A>>_f => Q',
|
|
458
|
+
[]P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
|
|
459
|
+
PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
|
|
460
|
+
|
|
461
|
+
(***************************************************************************)
|
|
462
|
+
(* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
|
|
463
|
+
(* from the following two rules by the following substitutions: \`. *)
|
|
464
|
+
(* *)
|
|
465
|
+
(* ___ ___ _______________ *)
|
|
466
|
+
(* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
|
|
467
|
+
(***************************************************************************)
|
|
468
|
+
THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
|
|
469
|
+
ACTION A, ACTION B, ACTION N, ACTION M,
|
|
470
|
+
TEMPORAL F,
|
|
471
|
+
<<N /\\ B>>_f => <<M>>_g,
|
|
472
|
+
P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
|
|
473
|
+
P /\\ EM => ENABLED A,
|
|
474
|
+
[][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
|
|
475
|
+
PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
|
|
476
|
+
|
|
477
|
+
THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
|
|
478
|
+
ACTION A, ACTION B, ACTION N, ACTION M,
|
|
479
|
+
TEMPORAL F,
|
|
480
|
+
<<N /\\ B>>_f => <<M>>_g,
|
|
481
|
+
P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
|
|
482
|
+
P /\\ EM => ENABLED A,
|
|
483
|
+
[][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
|
|
484
|
+
PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
(***************************************************************************)
|
|
488
|
+
(* The following rule is a special case of the general temporal logic *)
|
|
489
|
+
(* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
|
|
490
|
+
(* general rule is for arbitrary temporal formulas F and G, but it cannot *)
|
|
491
|
+
(* yet be handled by TLAPS. *)
|
|
492
|
+
(***************************************************************************)
|
|
493
|
+
THEOREM RuleInvImplication ==
|
|
494
|
+
ASSUME STATE F, STATE G,
|
|
495
|
+
F => G
|
|
496
|
+
PROVE []F => []G
|
|
497
|
+
PROOF OMITTED
|
|
498
|
+
|
|
499
|
+
(***************************************************************************)
|
|
500
|
+
(* The following rule is a special case of rule TLA2 from the paper "The *)
|
|
501
|
+
(* Temporal Logic of Actions". *)
|
|
502
|
+
(***************************************************************************)
|
|
503
|
+
THEOREM RuleStepSimulation ==
|
|
504
|
+
ASSUME STATE I, STATE f, STATE g,
|
|
505
|
+
ACTION M, ACTION N,
|
|
506
|
+
I /\\ I' /\\ [M]_f => [N]_g
|
|
507
|
+
PROVE []I /\\ [][M]_f => [][N]_g
|
|
508
|
+
PROOF OMITTED
|
|
509
|
+
|
|
510
|
+
(***************************************************************************)
|
|
511
|
+
(* The following may be used to invoke a decision procedure for *)
|
|
512
|
+
(* propositional temporal logic. *)
|
|
513
|
+
(***************************************************************************)
|
|
514
|
+
PropositionalTemporalLogic == TRUE
|
|
515
|
+
=============================================================================
|
|
516
|
+
`:void 0);return i===void 0?void 0:{file:`${e}.tla`,source:i}}),a=i.flatMap(e=>e.obligations),o={missingProofCount:i.reduce((e,t)=>e+t.summary.absent.length,0),omittedProofCount:i.reduce((e,t)=>e+t.summary.omitted.length,0)};if(t.backend===`tlapm`){if(typeof process>`u`||process.versions?.node===void 0)throw new e.k(`The tlapm backend runs only in Node and Bun.`);let i=await Promise.resolve().then(()=>require("./tlapm.cjs")),s=new Map(a.map(e=>[e.id,e])),c=await i.proveWithTlapm(n,new Map([[n,t.source],...r]),{signal:t.signal,onResult:(e,n)=>{let r=s.get(e);r&&t.onObligation?.(bl(r,n))}});return{obligations:a.map(e=>bl(e,c.get(e.id))),...o}}return{obligations:(await yl(a,{workers:t.workers,signal:t.signal,onReport:e=>t.onObligation?.(e.obligation)})).map(e=>e.obligation),...o}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return`------------------------------- MODULE TLAPS --------------------------------
|
|
517
|
+
|
|
518
|
+
(* Backend pragmas. *)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
(***************************************************************************)
|
|
522
|
+
(* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
|
|
523
|
+
(* is added to the context of an obligation most recently is the one whose *)
|
|
524
|
+
(* effects are triggered. *)
|
|
525
|
+
(***************************************************************************)
|
|
526
|
+
|
|
527
|
+
(***************************************************************************)
|
|
528
|
+
(* The following pragmas should be used only as a last resource. They are *)
|
|
529
|
+
(* dependent upon the particular backend provers, and are unlikely to have *)
|
|
530
|
+
(* any effect if the set of backend provers changes. Moreover, they are *)
|
|
531
|
+
(* meaningless to a reader of the proof. *)
|
|
532
|
+
(***************************************************************************)
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
(**************************************************************************)
|
|
536
|
+
(* Backend pragma: use the SMT solver for arithmetic. *)
|
|
537
|
+
(* *)
|
|
538
|
+
(* This method exists under this name for historical reasons. *)
|
|
539
|
+
(**************************************************************************)
|
|
540
|
+
|
|
541
|
+
SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
(**************************************************************************)
|
|
545
|
+
(* Backend pragma: SMT solver *)
|
|
546
|
+
(* *)
|
|
547
|
+
(* This method translates the proof obligation to SMTLIB2. The supported *)
|
|
548
|
+
(* fragment includes first-order logic, set theory, functions and *)
|
|
549
|
+
(* records. *)
|
|
550
|
+
(* SMT calls the smt-solver with the default timeout of 5 seconds *)
|
|
551
|
+
(* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
|
|
552
|
+
(* *)
|
|
553
|
+
(* SMTT also accepts a string argument of the form "rN" to bound the *)
|
|
554
|
+
(* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
|
|
555
|
+
(* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
|
|
556
|
+
(* resource count, so a small readable budget like "r5" is meaningful. *)
|
|
557
|
+
(* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
|
|
558
|
+
(* speed or load, so the proof's pass/fail outcome reproduces on any *)
|
|
559
|
+
(* machine and every rerun (for a fixed Z3 build); how long it takes to *)
|
|
560
|
+
(* consume the budget still varies by machine. This is Z3-specific. *)
|
|
561
|
+
(**************************************************************************)
|
|
562
|
+
|
|
563
|
+
SMT == TRUE (*{ by (prover:"smt3") }*)
|
|
564
|
+
SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
(**************************************************************************)
|
|
568
|
+
(* Backend pragma: CVC4 SMT solver *)
|
|
569
|
+
(* *)
|
|
570
|
+
(* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
|
|
571
|
+
(**************************************************************************)
|
|
572
|
+
|
|
573
|
+
(* The CVC3* methods are here for backward compatibility. They call CVC4. *)
|
|
574
|
+
CVC3 == TRUE (*{ by (prover: "cvc33") }*)
|
|
575
|
+
CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
|
|
576
|
+
|
|
577
|
+
CVC4 == TRUE (*{ by (prover: "cvc33") }*)
|
|
578
|
+
CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
(**************************************************************************)
|
|
582
|
+
(* Backend pragma: Yices SMT solver *)
|
|
583
|
+
(* *)
|
|
584
|
+
(* This method translates the proof obligation to Yices native language. *)
|
|
585
|
+
(**************************************************************************)
|
|
586
|
+
|
|
587
|
+
Yices == TRUE (*{ by (prover: "yices3") }*)
|
|
588
|
+
YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
|
|
589
|
+
|
|
590
|
+
(**************************************************************************)
|
|
591
|
+
(* Backend pragma: veriT SMT solver *)
|
|
592
|
+
(* *)
|
|
593
|
+
(* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
|
|
594
|
+
(**************************************************************************)
|
|
595
|
+
|
|
596
|
+
veriT == TRUE (*{ by (prover: "verit") }*)
|
|
597
|
+
veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
|
|
598
|
+
|
|
599
|
+
(**************************************************************************)
|
|
600
|
+
(* Backend pragma: Zipperposition solver *)
|
|
601
|
+
(* *)
|
|
602
|
+
(* This method translates the proof obligation to TPTP and *)
|
|
603
|
+
(* calls Zipperposition. *)
|
|
604
|
+
(**************************************************************************)
|
|
605
|
+
|
|
606
|
+
Zipper == TRUE (*{ by (prover: "zipper") }*)
|
|
607
|
+
ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
|
|
608
|
+
|
|
609
|
+
(**************************************************************************)
|
|
610
|
+
(* Backend pragma: Z3 SMT solver *)
|
|
611
|
+
(* *)
|
|
612
|
+
(* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
|
|
613
|
+
(* Z3 is used by default but you can also explicitly call it. *)
|
|
614
|
+
(* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
|
|
615
|
+
(* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
|
|
616
|
+
(* reproduces the same outcome on any machine (see SMTT). *)
|
|
617
|
+
(**************************************************************************)
|
|
618
|
+
|
|
619
|
+
Z3 == TRUE (*{ by (prover: "z33") }*)
|
|
620
|
+
Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
|
|
621
|
+
|
|
622
|
+
(**************************************************************************)
|
|
623
|
+
(* Backend pragma: SPASS superposition prover *)
|
|
624
|
+
(* *)
|
|
625
|
+
(* This method translates the proof obligation to the DFG format language *)
|
|
626
|
+
(* supported by the ATP SPASS. The translation is based on the SMT one. *)
|
|
627
|
+
(**************************************************************************)
|
|
628
|
+
|
|
629
|
+
Spass == TRUE (*{ by (prover: "spass") }*)
|
|
630
|
+
SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
|
|
631
|
+
|
|
632
|
+
(**************************************************************************)
|
|
633
|
+
(* Backend pragma: The PTL propositional linear time temporal logic *)
|
|
634
|
+
(* prover. It currently is the LS4 backend. *)
|
|
635
|
+
(* *)
|
|
636
|
+
(* This method translates the negetation of the proof obligation to *)
|
|
637
|
+
(* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
|
|
638
|
+
(**************************************************************************)
|
|
639
|
+
|
|
640
|
+
LS4 == TRUE (*{ by (prover: "ls4") }*)
|
|
641
|
+
LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
|
|
642
|
+
PTL == TRUE (*{ by (prover: "ls4") }*)
|
|
643
|
+
|
|
644
|
+
(**************************************************************************)
|
|
645
|
+
(* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
|
|
646
|
+
(* *)
|
|
647
|
+
(**************************************************************************)
|
|
648
|
+
|
|
649
|
+
Zenon == TRUE (*{ by (prover:"zenon") }*)
|
|
650
|
+
ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
|
|
651
|
+
|
|
652
|
+
(********************************************************************)
|
|
653
|
+
(* Backend pragma: Isabelle with different timeouts and tactics *)
|
|
654
|
+
(* (default is 30 seconds/auto) *)
|
|
655
|
+
(********************************************************************)
|
|
656
|
+
|
|
657
|
+
Isa == TRUE (*{ by (prover:"isabelle") }*)
|
|
658
|
+
IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
|
|
659
|
+
IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
|
|
660
|
+
IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
|
|
661
|
+
|
|
662
|
+
(***************************************************************************)
|
|
663
|
+
(* The following theorem expresses the (useful implication of the) law of *)
|
|
664
|
+
(* set extensionality, which can be written as *)
|
|
665
|
+
(* *)
|
|
666
|
+
(* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
|
|
667
|
+
(* *)
|
|
668
|
+
(* Theorem SetExtensionality is sometimes required by the SMT backend for *)
|
|
669
|
+
(* reasoning about sets. It is usually counterproductive to include *)
|
|
670
|
+
(* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
|
|
671
|
+
(* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
|
|
672
|
+
(* the Isabelle backend to use the rule of set extensionality. *)
|
|
673
|
+
(***************************************************************************)
|
|
674
|
+
IsaWithSetExtensionality == TRUE
|
|
675
|
+
(*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
|
|
676
|
+
|
|
677
|
+
THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
|
|
678
|
+
OBVIOUS
|
|
679
|
+
|
|
680
|
+
(***************************************************************************)
|
|
681
|
+
(* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
|
|
682
|
+
(* the definition *)
|
|
683
|
+
(* *)
|
|
684
|
+
(* NotInSetS == CHOOSE v : v \\notin SetS *)
|
|
685
|
+
(***************************************************************************)
|
|
686
|
+
THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
|
|
687
|
+
OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
|
|
688
|
+
-----------------------------------------------------------------------------
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
(********************************************************************)
|
|
693
|
+
(********************************************************************)
|
|
694
|
+
(********************************************************************)
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
(********************************************************************)
|
|
698
|
+
(* Old versions of Zenon and Isabelle pragmas below *)
|
|
699
|
+
(* (kept for compatibility) *)
|
|
700
|
+
(********************************************************************)
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
(**************************************************************************)
|
|
704
|
+
(* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
|
|
705
|
+
(* *)
|
|
706
|
+
(**************************************************************************)
|
|
707
|
+
|
|
708
|
+
SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
|
|
709
|
+
SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
|
|
710
|
+
VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
|
|
711
|
+
SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
(********************************************************************)
|
|
716
|
+
(* Backend pragma: Isabelle's automatic search ("auto") *)
|
|
717
|
+
(* *)
|
|
718
|
+
(* This pragma bypasses Zenon. It is useful in situations involving *)
|
|
719
|
+
(* essentially simplification and equational reasoning. *)
|
|
720
|
+
(* Default imeout for all isabelle tactics is 30 seconds. *)
|
|
721
|
+
(********************************************************************)
|
|
722
|
+
Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
|
|
723
|
+
SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
|
|
724
|
+
SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
|
|
725
|
+
SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
|
|
726
|
+
|
|
727
|
+
(********************************************************************)
|
|
728
|
+
(* Backend pragma: Isabelle's "force" tactic *)
|
|
729
|
+
(* *)
|
|
730
|
+
(* This pragma bypasses Zenon. It is useful in situations involving *)
|
|
731
|
+
(* quantifier reasoning. *)
|
|
732
|
+
(********************************************************************)
|
|
733
|
+
Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
|
|
734
|
+
SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
|
|
735
|
+
SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
|
|
736
|
+
SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
|
|
737
|
+
|
|
738
|
+
(***********************************************************************)
|
|
739
|
+
(* Backend pragma: Isabelle's "simplification" tactics *)
|
|
740
|
+
(* *)
|
|
741
|
+
(* These tactics simplify the goal before running one of the automated *)
|
|
742
|
+
(* tactics. They are often necessary for obligations involving record *)
|
|
743
|
+
(* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
|
|
744
|
+
(* sure you can get away with just Simplification *)
|
|
745
|
+
(***********************************************************************)
|
|
746
|
+
SimplifyAndSolve == TRUE
|
|
747
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
|
|
748
|
+
SlowSimplifyAndSolve == TRUE
|
|
749
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
|
|
750
|
+
SlowerSimplifyAndSolve == TRUE
|
|
751
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
|
|
752
|
+
SlowestSimplifyAndSolve == TRUE
|
|
753
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
|
|
754
|
+
|
|
755
|
+
Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
|
|
756
|
+
SlowSimplification == TRUE
|
|
757
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
|
|
758
|
+
SlowerSimplification == TRUE
|
|
759
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
|
|
760
|
+
SlowestSimplification == TRUE
|
|
761
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
|
|
762
|
+
|
|
763
|
+
(**************************************************************************)
|
|
764
|
+
(* Backend pragma: Isabelle's tableau prover ("blast") *)
|
|
765
|
+
(* *)
|
|
766
|
+
(* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
|
|
767
|
+
(* prover, Blast. It is almost never better than Zenon by itself, but *)
|
|
768
|
+
(* becomes very useful in combination with the Auto pragma above. The *)
|
|
769
|
+
(* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
|
|
770
|
+
(* Auto could not prove. (There is currently no way to use Zenon on the *)
|
|
771
|
+
(* results left over from Auto.) *)
|
|
772
|
+
(**************************************************************************)
|
|
773
|
+
Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
|
|
774
|
+
SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
|
|
775
|
+
SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
|
|
776
|
+
SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
|
|
777
|
+
|
|
778
|
+
AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
(**************************************************************************)
|
|
782
|
+
(* Backend pragmas: multi-back-ends *)
|
|
783
|
+
(* *)
|
|
784
|
+
(* These pragmas just run a bunch of back-ends one after the other in the *)
|
|
785
|
+
(* hope that one will succeed. This saves time and effort for the user at *)
|
|
786
|
+
(* the expense of computation time. *)
|
|
787
|
+
(**************************************************************************)
|
|
788
|
+
|
|
789
|
+
(* CVC3 goes first because it's bundled with TLAPS, then the other SMT
|
|
790
|
+
solvers are unlikely to succeed if CVC3 fails, so we run zenon and
|
|
791
|
+
Isabelle before them. *)
|
|
792
|
+
AllProvers == TRUE (*{
|
|
793
|
+
by (prover:"cvc33")
|
|
794
|
+
by (prover:"zenon")
|
|
795
|
+
by (prover:"isabelle"; tactic:"auto")
|
|
796
|
+
by (prover:"spass")
|
|
797
|
+
by (prover:"smt3")
|
|
798
|
+
by (prover:"yices3")
|
|
799
|
+
by (prover:"verit")
|
|
800
|
+
by (prover:"z33")
|
|
801
|
+
by (prover:"isabelle"; tactic:"force")
|
|
802
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
|
|
803
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?")
|
|
804
|
+
by (prover:"isabelle"; tactic:"clarsimp")
|
|
805
|
+
by (prover:"isabelle"; tactic:"auto, blast")
|
|
806
|
+
}*)
|
|
807
|
+
AllProversT(X) == TRUE (*{
|
|
808
|
+
by (prover:"cvc33"; timeout:@)
|
|
809
|
+
by (prover:"zenon"; timeout:@)
|
|
810
|
+
by (prover:"isabelle"; tactic:"auto"; timeout:@)
|
|
811
|
+
by (prover:"spass"; timeout:@)
|
|
812
|
+
by (prover:"smt3"; timeout:@)
|
|
813
|
+
by (prover:"yices3"; timeout:@)
|
|
814
|
+
by (prover:"verit"; timeout:@)
|
|
815
|
+
by (prover:"z33"; timeout:@)
|
|
816
|
+
by (prover:"isabelle"; tactic:"force"; timeout:@)
|
|
817
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
|
|
818
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
|
|
819
|
+
by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
|
|
820
|
+
by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
|
|
821
|
+
}*)
|
|
822
|
+
|
|
823
|
+
AllSMT == TRUE (*{
|
|
824
|
+
by (prover:"cvc33")
|
|
825
|
+
by (prover:"smt3")
|
|
826
|
+
by (prover:"yices3")
|
|
827
|
+
by (prover:"verit")
|
|
828
|
+
by (prover:"z33")
|
|
829
|
+
}*)
|
|
830
|
+
AllSMTT(X) == TRUE (*{
|
|
831
|
+
by (prover:"cvc33"; timeout:@)
|
|
832
|
+
by (prover:"smt3"; timeout:@)
|
|
833
|
+
by (prover:"yices3"; timeout:@)
|
|
834
|
+
by (prover:"verit"; timeout:@)
|
|
835
|
+
by (prover:"z33"; timeout:@)
|
|
836
|
+
}*)
|
|
837
|
+
|
|
838
|
+
AllIsa == TRUE (*{
|
|
839
|
+
by (prover:"isabelle"; tactic:"auto")
|
|
840
|
+
by (prover:"isabelle"; tactic:"force")
|
|
841
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
|
|
842
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?")
|
|
843
|
+
by (prover:"isabelle"; tactic:"clarsimp")
|
|
844
|
+
by (prover:"isabelle"; tactic:"auto, blast")
|
|
845
|
+
}*)
|
|
846
|
+
AllIsaT(X) == TRUE (*{
|
|
847
|
+
by (prover:"isabelle"; tactic:"auto"; timeout:@)
|
|
848
|
+
by (prover:"isabelle"; tactic:"force"; timeout:@)
|
|
849
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
|
|
850
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
|
|
851
|
+
by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
|
|
852
|
+
by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
|
|
853
|
+
}*)
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
(**************************************************************************)
|
|
857
|
+
(* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
|
|
858
|
+
(* *)
|
|
859
|
+
(* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
|
|
860
|
+
(* *)
|
|
861
|
+
(* The pragma AutoUSE invokes automated expansion of definitions, *)
|
|
862
|
+
(* for both of ExpandEnabled and ExpandCdot, when each is present. *)
|
|
863
|
+
(* *)
|
|
864
|
+
(* The pragma Lambdify invokes expansion of the operators *)
|
|
865
|
+
(* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
|
|
866
|
+
(* which is a form before introducing rigid quantifiers. *)
|
|
867
|
+
(* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
|
|
868
|
+
(* that are not nested. *)
|
|
869
|
+
(**************************************************************************)
|
|
870
|
+
ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
|
|
871
|
+
ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
|
|
872
|
+
AutoUSE == TRUE (*{ by (prover:"autouse") }*)
|
|
873
|
+
Lambdify == TRUE (*{ by (prover:"lambdify") }*)
|
|
874
|
+
ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
|
|
875
|
+
LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
|
|
876
|
+
|
|
877
|
+
(* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
|
|
878
|
+
(* representation within TLAPM. *)
|
|
879
|
+
EnabledWrapper(Op(_)) == FALSE
|
|
880
|
+
CdotWrapper(Op(_)) == FALSE
|
|
881
|
+
|
|
882
|
+
(***************************************************************************)
|
|
883
|
+
(* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
|
|
884
|
+
(* triviality checks in TLAPM. *)
|
|
885
|
+
(***************************************************************************)
|
|
886
|
+
Trivial == TRUE (*{ by (prover:"trivial") }*)
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
=============================================================================
|
|
890
|
+
|
|
891
|
+
The material below is obsolete: the TLA proof rules below are superseded by
|
|
892
|
+
the PTL decision procedure, and their formulation is unsound for the semantics
|
|
893
|
+
of temporal reasoning that TLAPS adopts.
|
|
894
|
+
|
|
895
|
+
----------------------------------------------------------------------------
|
|
896
|
+
(***************************************************************************)
|
|
897
|
+
(* TEMPORAL LOGIC *)
|
|
898
|
+
(* *)
|
|
899
|
+
(* The following rules are intended to be used when TLAPS handles temporal *)
|
|
900
|
+
(* logic. They will not work now. Moreover when temporal reasoning is *)
|
|
901
|
+
(* implemented, these rules may be changed or omitted, and additional *)
|
|
902
|
+
(* rules will probably be added. However, they are included mainly so *)
|
|
903
|
+
(* their names will be defined, preventing the use of identifiers that are *)
|
|
904
|
+
(* likely to produce name clashes with future versions of this module. *)
|
|
905
|
+
(***************************************************************************)
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
(***************************************************************************)
|
|
909
|
+
(* The following proof rules (and their names) are from the paper "The *)
|
|
910
|
+
(* Temporal Logic of Actions". *)
|
|
911
|
+
(***************************************************************************)
|
|
912
|
+
THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
|
|
913
|
+
P /\\ (f' = f) => P'
|
|
914
|
+
PROVE []P <=> P /\\ [][P => P']_f
|
|
915
|
+
|
|
916
|
+
THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
|
|
917
|
+
ACTION A, ACTION B,
|
|
918
|
+
P /\\ [A]_f => Q /\\ [B]_g
|
|
919
|
+
PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
|
|
920
|
+
|
|
921
|
+
THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
|
|
922
|
+
I /\\ [N]_F => I'
|
|
923
|
+
PROVE I /\\ [][N]_F => []I
|
|
924
|
+
|
|
925
|
+
THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
|
|
926
|
+
PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
|
|
927
|
+
|
|
928
|
+
THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
|
|
929
|
+
P /\\ [N]_f => (P' \\/ Q'),
|
|
930
|
+
P /\\ <<N /\\ A>>_f => Q',
|
|
931
|
+
P => ENABLED <<A>>_f
|
|
932
|
+
PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
|
|
933
|
+
|
|
934
|
+
THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
|
|
935
|
+
ACTION N, ACTION A, TEMPORAL F,
|
|
936
|
+
P /\\ [N]_f => (P' \\/ Q'),
|
|
937
|
+
P /\\ <<N /\\ A>>_f => Q',
|
|
938
|
+
[]P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
|
|
939
|
+
PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
|
|
940
|
+
|
|
941
|
+
(***************************************************************************)
|
|
942
|
+
(* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
|
|
943
|
+
(* from the following two rules by the following substitutions: \`. *)
|
|
944
|
+
(* *)
|
|
945
|
+
(* ___ ___ _______________ *)
|
|
946
|
+
(* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
|
|
947
|
+
(***************************************************************************)
|
|
948
|
+
THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
|
|
949
|
+
ACTION A, ACTION B, ACTION N, ACTION M,
|
|
950
|
+
TEMPORAL F,
|
|
951
|
+
<<N /\\ B>>_f => <<M>>_g,
|
|
952
|
+
P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
|
|
953
|
+
P /\\ EM => ENABLED A,
|
|
954
|
+
[][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
|
|
955
|
+
PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
|
|
956
|
+
|
|
957
|
+
THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
|
|
958
|
+
ACTION A, ACTION B, ACTION N, ACTION M,
|
|
959
|
+
TEMPORAL F,
|
|
960
|
+
<<N /\\ B>>_f => <<M>>_g,
|
|
961
|
+
P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
|
|
962
|
+
P /\\ EM => ENABLED A,
|
|
963
|
+
[][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
|
|
964
|
+
PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
(***************************************************************************)
|
|
968
|
+
(* The following rule is a special case of the general temporal logic *)
|
|
969
|
+
(* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
|
|
970
|
+
(* general rule is for arbitrary temporal formulas F and G, but it cannot *)
|
|
971
|
+
(* yet be handled by TLAPS. *)
|
|
972
|
+
(***************************************************************************)
|
|
973
|
+
THEOREM RuleInvImplication ==
|
|
974
|
+
ASSUME STATE F, STATE G,
|
|
975
|
+
F => G
|
|
976
|
+
PROVE []F => []G
|
|
977
|
+
PROOF OMITTED
|
|
978
|
+
|
|
979
|
+
(***************************************************************************)
|
|
980
|
+
(* The following rule is a special case of rule TLA2 from the paper "The *)
|
|
981
|
+
(* Temporal Logic of Actions". *)
|
|
982
|
+
(***************************************************************************)
|
|
983
|
+
THEOREM RuleStepSimulation ==
|
|
984
|
+
ASSUME STATE I, STATE f, STATE g,
|
|
985
|
+
ACTION M, ACTION N,
|
|
986
|
+
I /\\ I' /\\ [M]_f => [N]_g
|
|
987
|
+
PROVE []I /\\ [][M]_f => [][N]_g
|
|
988
|
+
PROOF OMITTED
|
|
989
|
+
|
|
990
|
+
(***************************************************************************)
|
|
991
|
+
(* The following may be used to invoke a decision procedure for *)
|
|
992
|
+
(* propositional temporal logic. *)
|
|
993
|
+
(***************************************************************************)
|
|
994
|
+
PropositionalTemporalLogic == TRUE
|
|
995
|
+
=============================================================================
|
|
996
|
+
`}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return qi}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return zt}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return yl}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return dn}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return ml}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Pi}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return xl}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return Ki}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return hl}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return F}});
|