tla-ts 0.0.4-dev.fa107ef → 0.0.5-dev.cc59f31
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 +37 -126
- 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 +44 -12
- package/dist/index.d.ts +44 -12
- 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 +1006 -0
- package/dist/prove.js +1006 -0
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +76 -92
- package/dist/transfer.js +76 -92
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1153
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/{run-cli.ts → cli/tlc.ts} +115 -721
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +43 -22
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +97 -35
- package/src/evaluate.ts +135 -120
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/index.ts +10 -0
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/{obligation-action.ts → obligations/action.ts} +248 -74
- package/src/{obligation-anon.ts → obligations/anonymize.ts} +55 -57
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +618 -0
- package/src/{obligation-format.ts → obligations/format.ts} +7 -8
- package/src/obligations/generate.ts +457 -0
- package/src/{obligations.ts → obligations/index.ts} +46 -32
- package/src/{obligation-levels.ts → obligations/levels.ts} +44 -40
- package/src/obligations/module.ts +445 -0
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +195 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +65 -230
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
- package/src/obligations/regroup.ts +100 -0
- package/src/{obligation-generate.ts → obligations/simplify.ts} +130 -536
- package/src/{obligation-source.ts → obligations/source.ts} +172 -216
- package/src/{obligation-deref.ts → obligations/subexpression.ts} +84 -115
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +321 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
- package/src/parallel-worker.ts +39 -51
- package/src/parallel.ts +39 -66
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prover/decide-pool.ts +95 -0
- package/src/prover/deciders.ts +33 -0
- package/src/prover/first-order.ts +175 -0
- package/src/prover/isabelle/LICENSE +36 -0
- package/src/prover/isabelle/LICENSE-tlapm +26 -0
- package/src/prover/isabelle/decide.ts +44 -0
- package/src/prover/isabelle/encode.ts +445 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prover/isabelle/isar/method.ts +367 -0
- package/src/prover/isabelle/isar/proof.ts +28 -0
- package/src/prover/isabelle/isar/statement.ts +57 -0
- package/src/prover/isabelle/isar/theory.ts +192 -0
- package/src/prover/isabelle/isar/type-check.ts +278 -0
- package/src/prover/isabelle/provers/blast/blast.ts +258 -0
- package/src/prover/isabelle/provers/blast/branch.ts +322 -0
- package/src/prover/isabelle/provers/blast/prove.ts +347 -0
- package/src/prover/isabelle/provers/blast/rules.ts +330 -0
- package/src/prover/isabelle/provers/blast/state.ts +180 -0
- package/src/prover/isabelle/provers/blast/term.ts +546 -0
- package/src/prover/isabelle/provers/clasimp.ts +150 -0
- package/src/prover/isabelle/provers/classical.ts +389 -0
- package/src/prover/isabelle/provers/hypsubst.ts +433 -0
- package/src/prover/isabelle/pure/bicompose.ts +174 -0
- package/src/prover/isabelle/pure/consts.ts +32 -0
- package/src/prover/isabelle/pure/conv.ts +79 -0
- package/src/prover/isabelle/pure/drule.ts +264 -0
- package/src/prover/isabelle/pure/envir.ts +331 -0
- package/src/prover/isabelle/pure/goal.ts +53 -0
- package/src/prover/isabelle/pure/interrupt.ts +16 -0
- package/src/prover/isabelle/pure/list.ts +12 -0
- package/src/prover/isabelle/pure/logic.ts +330 -0
- package/src/prover/isabelle/pure/name.ts +98 -0
- package/src/prover/isabelle/pure/net.ts +215 -0
- package/src/prover/isabelle/pure/object-logic.ts +41 -0
- package/src/prover/isabelle/pure/pattern.ts +631 -0
- package/src/prover/isabelle/pure/raw-simplifier.ts +338 -0
- package/src/prover/isabelle/pure/rewriter.ts +602 -0
- package/src/prover/isabelle/pure/search.ts +68 -0
- package/src/prover/isabelle/pure/seq.ts +133 -0
- package/src/prover/isabelle/pure/simplifier.ts +106 -0
- package/src/prover/isabelle/pure/table.ts +201 -0
- package/src/prover/isabelle/pure/tactic.ts +168 -0
- package/src/prover/isabelle/pure/tactical.ts +264 -0
- package/src/prover/isabelle/pure/term-ord.ts +105 -0
- package/src/prover/isabelle/pure/term.ts +688 -0
- package/src/prover/isabelle/pure/thm.ts +783 -0
- package/src/prover/isabelle/pure/type.ts +121 -0
- package/src/prover/isabelle/pure/unify.ts +753 -0
- package/src/prover/isabelle/pure/variable.ts +25 -0
- package/src/prover/isabelle/tla/classical-setup.ts +101 -0
- package/src/prover/isabelle/tla/context.ts +74 -0
- package/src/prover/isabelle/tla/logic-data.ts +5 -0
- package/src/prover/isabelle/tla/logic.ts +215 -0
- package/src/prover/isabelle/tla/simpdata.ts +241 -0
- package/src/prover/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prover/ocaml.ts +22 -0
- package/src/prover/prep/action.ts +508 -0
- package/src/prover/prep/enabled-axioms.ts +189 -0
- package/src/prover/prep/fingerprint.ts +388 -0
- package/src/prover/prep/level-comparison.ts +529 -0
- package/src/prover/prep/md5.ts +60 -0
- package/src/prover/prep/methods.ts +221 -0
- package/src/prover/prep/normalize.ts +309 -0
- package/src/prover/prove-worker.ts +22 -0
- package/src/prover/prove.ts +492 -0
- package/src/prover/ptl/decide.ts +68 -0
- package/src/prover/ptl/encode.ts +244 -0
- package/src/prover/ptl/sat.ts +151 -0
- package/src/prover/ptl/tableau.ts +276 -0
- package/src/prover/smt/axioms.ts +209 -0
- package/src/prover/smt/context.ts +108 -0
- package/src/prover/smt/data.ts +636 -0
- package/src/prover/smt/encode.ts +275 -0
- package/src/prover/smt/extensionality.ts +65 -0
- package/src/prover/smt/flatten.ts +112 -0
- package/src/prover/smt/format.ts +154 -0
- package/src/prover/smt/instances.ts +181 -0
- package/src/prover/smt/rewrite.ts +766 -0
- package/src/prover/smt/solver/act-cache.ts +265 -0
- package/src/prover/smt/solver/arith-rewriter.ts +962 -0
- package/src/prover/smt/solver/array.ts +22 -0
- package/src/prover/smt/solver/asserted-formulas.ts +469 -0
- package/src/prover/smt/solver/ast-lt.ts +157 -0
- package/src/prover/smt/solver/ast-util.ts +91 -0
- package/src/prover/smt/solver/ast.ts +1315 -0
- package/src/prover/smt/solver/auf-solver.ts +572 -0
- package/src/prover/smt/solver/case-split-queue.ts +178 -0
- package/src/prover/smt/solver/cg-table.ts +175 -0
- package/src/prover/smt/solver/clause.ts +276 -0
- package/src/prover/smt/solver/conflict-resolution.ts +343 -0
- package/src/prover/smt/solver/context.ts +1292 -0
- package/src/prover/smt/solver/ctx-simplify.ts +334 -0
- package/src/prover/smt/solver/der.ts +224 -0
- package/src/prover/smt/solver/dyn-ack.ts +141 -0
- package/src/prover/smt/solver/e-matching.ts +659 -0
- package/src/prover/smt/solver/enode.ts +259 -0
- package/src/prover/smt/solver/expr-ref.ts +21 -0
- package/src/prover/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prover/smt/solver/fingerprints.ts +92 -0
- package/src/prover/smt/solver/flat-literals.ts +51 -0
- package/src/prover/smt/solver/goal.ts +138 -0
- package/src/prover/smt/solver/hash.ts +173 -0
- package/src/prover/smt/solver/hashtable.ts +166 -0
- package/src/prover/smt/solver/internalizer.ts +1381 -0
- package/src/prover/smt/solver/lbool.ts +5 -0
- package/src/prover/smt/solver/literal.ts +24 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prover/smt/solver/lp/constraints.ts +78 -0
- package/src/prover/smt/solver/lp/containers.ts +296 -0
- package/src/prover/smt/solver/lp/core-solver.ts +504 -0
- package/src/prover/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prover/smt/solver/lp/dep-intervals.ts +642 -0
- package/src/prover/smt/solver/lp/dependency.ts +51 -0
- package/src/prover/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prover/smt/solver/lp/explanation.ts +46 -0
- package/src/prover/smt/solver/lp/gomory.ts +255 -0
- package/src/prover/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prover/smt/solver/lp/hnf.ts +281 -0
- package/src/prover/smt/solver/lp/int-cube.ts +295 -0
- package/src/prover/smt/solver/lp/int-solver.ts +514 -0
- package/src/prover/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prover/smt/solver/lp/lar-term.ts +62 -0
- package/src/prover/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prover/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prover/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prover/smt/solver/lp/nex.ts +120 -0
- package/src/prover/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prover/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prover/smt/solver/lp/nla-core.ts +968 -0
- package/src/prover/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prover/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prover/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prover/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prover/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prover/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prover/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prover/smt/solver/lp/nla-order.ts +307 -0
- package/src/prover/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prover/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prover/smt/solver/lp/nla-types.ts +124 -0
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prover/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prover/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prover/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prover/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prover/smt/solver/lp/pdd.ts +971 -0
- package/src/prover/smt/solver/lp/random-updater.ts +138 -0
- package/src/prover/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prover/smt/solver/lp/union-find.ts +96 -0
- package/src/prover/smt/solver/mam-compiler.ts +847 -0
- package/src/prover/smt/solver/mam-interpreter.ts +400 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prover/smt/solver/model-checker.ts +347 -0
- package/src/prover/smt/solver/model-evaluator.ts +262 -0
- package/src/prover/smt/solver/model-finder.ts +155 -0
- package/src/prover/smt/solver/model-generator.ts +97 -0
- package/src/prover/smt/solver/model-macro-solver.ts +728 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prover/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prover/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prover/smt/solver/nlsat/explain.ts +607 -0
- package/src/prover/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prover/smt/solver/nlsat/levelwise.ts +737 -0
- package/src/prover/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prover/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prover/smt/solver/nlsat/solver.ts +911 -0
- package/src/prover/smt/solver/nlsat/types.ts +43 -0
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prover/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prover/smt/solver/nnf.ts +469 -0
- package/src/prover/smt/solver/pattern-inference.ts +351 -0
- package/src/prover/smt/solver/poly-rewriter.ts +477 -0
- package/src/prover/smt/solver/propagate-values.ts +83 -0
- package/src/prover/smt/solver/proto-model.ts +551 -0
- package/src/prover/smt/solver/pull-quant.ts +139 -0
- package/src/prover/smt/solver/qe-lite-der.ts +526 -0
- package/src/prover/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prover/smt/solver/qe-lite.ts +381 -0
- package/src/prover/smt/solver/qi-queue.ts +362 -0
- package/src/prover/smt/solver/quant-tactics.ts +117 -0
- package/src/prover/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prover/smt/solver/quantifier-manager.ts +186 -0
- package/src/prover/smt/solver/random-gen.ts +10 -0
- package/src/prover/smt/solver/rational.ts +165 -0
- package/src/prover/smt/solver/ref-vector.ts +62 -0
- package/src/prover/smt/solver/relevancy.ts +247 -0
- package/src/prover/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prover/smt/solver/rewriter.ts +843 -0
- package/src/prover/smt/solver/rlimit.ts +79 -0
- package/src/prover/smt/solver/smtlib-parser.ts +526 -0
- package/src/prover/smt/solver/solver.ts +71 -0
- package/src/prover/smt/solver/sort.ts +35 -0
- package/src/prover/smt/solver/sticky-generations.ts +69 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prover/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prover/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prover/smt/solver/theory-lra-model.ts +243 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prover/smt/solver/theory-lra-state.ts +43 -0
- package/src/prover/smt/solver/theory-lra.ts +56 -0
- package/src/prover/smt/solver/var-subst.ts +258 -0
- package/src/prover/smt/solver/z3-license.txt +10 -0
- package/src/prover/smt/table.ts +170 -0
- package/src/prover/tlapm/cache.ts +236 -0
- package/src/prover/tlapm/ocaml-marshal.ts +166 -0
- package/src/prover/tlapm/tlapm.ts +96 -0
- package/src/prover/tlaps-module.ts +510 -0
- package/src/prover/verdict.ts +13 -0
- package/src/prover/zenon/LICENSE +32 -0
- package/src/prover/zenon/check/check.ts +105 -0
- package/src/prover/zenon/check/definitions.ts +144 -0
- package/src/prover/zenon/check/equality.ts +182 -0
- package/src/prover/zenon/check/functions.ts +62 -0
- package/src/prover/zenon/check/keys.ts +125 -0
- package/src/prover/zenon/check/propositional.ts +104 -0
- package/src/prover/zenon/check/records.ts +188 -0
- package/src/prover/zenon/check/relations.ts +121 -0
- package/src/prover/zenon/check/rewrites.ts +224 -0
- package/src/prover/zenon/check/sets.ts +302 -0
- package/src/prover/zenon/check/terms.ts +127 -0
- package/src/prover/zenon/check/tla.ts +126 -0
- package/src/prover/zenon/decide.ts +107 -0
- package/src/prover/zenon/encode.ts +378 -0
- package/src/prover/zenon/eqrel.ts +300 -0
- package/src/prover/zenon/equality-rules.ts +435 -0
- package/src/prover/zenon/expr.ts +551 -0
- package/src/prover/zenon/index-table.ts +350 -0
- package/src/prover/zenon/isar-case.ts +513 -0
- package/src/prover/zenon/isar.ts +1249 -0
- package/src/prover/zenon/limits.ts +15 -0
- package/src/prover/zenon/llproof.ts +173 -0
- package/src/prover/zenon/mltoll.ts +1566 -0
- package/src/prover/zenon/node.ts +297 -0
- package/src/prover/zenon/ocaml.ts +169 -0
- package/src/prover/zenon/parse.ts +247 -0
- package/src/prover/zenon/phrase.ts +191 -0
- package/src/prover/zenon/proof.ts +198 -0
- package/src/prover/zenon/propositional-rules.ts +387 -0
- package/src/prover/zenon/rules.ts +94 -0
- package/src/prover/zenon/search.ts +288 -0
- package/src/prover/zenon/tla/functions.ts +151 -0
- package/src/prover/zenon/tla/llproof.ts +480 -0
- package/src/prover/zenon/tla/records.ts +225 -0
- package/src/prover/zenon/tla/rewrites.ts +447 -0
- package/src/prover/zenon/tla/sets.ts +304 -0
- package/src/prover/zenon/tla/terms.ts +162 -0
- package/src/prover/zenon/tla/tla.ts +506 -0
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +21 -22
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +38 -22
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -190
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/{tlc-version.ts → tlc/version.ts} +8 -7
- package/src/transfer.ts +32 -32
- package/src/values.ts +154 -105
- package/src/worker.ts +62 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- package/dist/run-cli.cjs +0 -55
- package/dist/run-cli.js +0 -55
- package/src/canonical.ts +0 -40
- package/src/obligation-expression.ts +0 -1060
- package/src/obligation-module.ts +0 -1042
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// Ported from Z3 (src/smt/smt_conflict_resolution.cpp), MIT license, see z3-license.txt.
|
|
2
|
+
// First-UIP conflict resolution with lemma minimization. Equalities in a conflict are explained
|
|
3
|
+
// by walking the transitivity branches of the E-graph down to literals.
|
|
4
|
+
import { BinJustification, type BJustification } from "./clause";
|
|
5
|
+
import type { Context } from "./context";
|
|
6
|
+
import { Enode, EqJustification, Justification } from "./enode";
|
|
7
|
+
import { BoolVar, getVar, Literal, negate } from "./literal";
|
|
8
|
+
import { RefVector } from "./ref-vector";
|
|
9
|
+
import { shrink } from "./array";
|
|
10
|
+
|
|
11
|
+
export class ConflictResolution {
|
|
12
|
+
private antecedents: Literal[] = [];
|
|
13
|
+
private todoJustifications: Justification[] = [];
|
|
14
|
+
private todoJustificationsHead = 0;
|
|
15
|
+
private todoEqs: Enode[] = [];
|
|
16
|
+
private processedEqs = new Set<string>();
|
|
17
|
+
lemma: Literal[] = [];
|
|
18
|
+
// m_lemma_atoms: the atoms of the lemma, which it holds until the lemma is a clause.
|
|
19
|
+
readonly lemmaAtoms: RefVector;
|
|
20
|
+
private conflictLevel = 0;
|
|
21
|
+
newScopeLevel = 0;
|
|
22
|
+
lemmaIscopeLevel = 0;
|
|
23
|
+
private unmark: BoolVar[] = [];
|
|
24
|
+
// m_lvl_set: a level_approx_set, whose bit level mod 32 stands for each level of the lemma, so
|
|
25
|
+
// other levels can pass for them.
|
|
26
|
+
private levelSet = 0;
|
|
27
|
+
private minimizationStack: BoolVar[] = [];
|
|
28
|
+
|
|
29
|
+
constructor(private context: Context) {
|
|
30
|
+
this.lemmaAtoms = new RefVector(context.manager);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
markLiteral(literal: Literal) {
|
|
34
|
+
this.antecedents.push(literal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// mark_eq: the pair starts with the node whose owner has the smaller id, which fixes the order in
|
|
38
|
+
// which eq2literals walks the two branches.
|
|
39
|
+
markEq(first: Enode, second: Enode) {
|
|
40
|
+
if (first === second) return;
|
|
41
|
+
const ids = this.context.manager.ids;
|
|
42
|
+
const isSwapped = ids[first.owner] > ids[second.owner];
|
|
43
|
+
const lower = isSwapped ? second : first;
|
|
44
|
+
const upper = isSwapped ? first : second;
|
|
45
|
+
const key = `${lower.owner}:${upper.owner}`;
|
|
46
|
+
if (this.processedEqs.has(key)) return;
|
|
47
|
+
this.processedEqs.add(key);
|
|
48
|
+
this.todoEqs.push(lower, upper);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
markJustification(justification: Justification) {
|
|
52
|
+
if (justification.isMarked) return;
|
|
53
|
+
justification.isMarked = true;
|
|
54
|
+
this.todoJustifications.push(justification);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
markJustifiedEq(first: Enode, second: Enode, justification: EqJustification) {
|
|
58
|
+
this.eqJustificationToLiterals(first, second, justification);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private findCommonAncestor(first: Enode, second: Enode) {
|
|
62
|
+
for (let node: Enode | null = first; node !== null; node = node.transTarget)
|
|
63
|
+
node.isMarked2 = true;
|
|
64
|
+
let result = second;
|
|
65
|
+
while (!result.isMarked2) {
|
|
66
|
+
const target = result.transTarget;
|
|
67
|
+
if (target === null) break;
|
|
68
|
+
result = target;
|
|
69
|
+
}
|
|
70
|
+
for (let node: Enode | null = first; node !== null; node = node.transTarget)
|
|
71
|
+
node.isMarked2 = false;
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private eqJustificationToLiterals(lhs: Enode, rhs: Enode, justification: EqJustification) {
|
|
76
|
+
if (justification.kind === "equation") this.antecedents.push(justification.literal);
|
|
77
|
+
else if (justification.kind === "justification")
|
|
78
|
+
this.markJustification(justification.justification);
|
|
79
|
+
else if (justification.kind === "congruence") {
|
|
80
|
+
if (justification.isCommutative) {
|
|
81
|
+
this.markEq(lhs.getArg(0), rhs.getArg(1));
|
|
82
|
+
this.markEq(lhs.getArg(1), rhs.getArg(0));
|
|
83
|
+
} else
|
|
84
|
+
for (let index = 0; index < lhs.numArgs; index++)
|
|
85
|
+
this.markEq(lhs.getArg(index), rhs.getArg(index));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private eqBranchToLiterals(start: Enode, ancestor: Enode) {
|
|
90
|
+
let node = start;
|
|
91
|
+
while (node !== ancestor) {
|
|
92
|
+
const target = node.transTarget;
|
|
93
|
+
if (target === null) break;
|
|
94
|
+
this.eqJustificationToLiterals(node, target, node.transJustification);
|
|
95
|
+
node = target;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private processJustifications() {
|
|
100
|
+
for (;;) {
|
|
101
|
+
while (this.todoJustificationsHead < this.todoJustifications.length) {
|
|
102
|
+
const justification = this.todoJustifications[this.todoJustificationsHead];
|
|
103
|
+
this.todoJustificationsHead++;
|
|
104
|
+
justification.getAntecedents(this);
|
|
105
|
+
}
|
|
106
|
+
while (this.todoEqs.length > 0) {
|
|
107
|
+
const second = this.todoEqs.pop();
|
|
108
|
+
const first = this.todoEqs.pop();
|
|
109
|
+
if (first === undefined || second === undefined) break;
|
|
110
|
+
const ancestor = this.findCommonAncestor(first, second);
|
|
111
|
+
this.eqBranchToLiterals(first, ancestor);
|
|
112
|
+
this.eqBranchToLiterals(second, ancestor);
|
|
113
|
+
}
|
|
114
|
+
if (this.todoJustificationsHead === this.todoJustifications.length) return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private unmarkJustifications(oldHead: number) {
|
|
119
|
+
for (let index = oldHead; index < this.todoJustifications.length; index++)
|
|
120
|
+
this.todoJustifications[index].isMarked = false;
|
|
121
|
+
shrink(this.todoJustifications, oldHead);
|
|
122
|
+
this.todoJustificationsHead = oldHead;
|
|
123
|
+
this.todoEqs.length = 0;
|
|
124
|
+
this.processedEqs.clear();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private justificationToLiteralsCore(justification: Justification) {
|
|
128
|
+
const saved = this.antecedents;
|
|
129
|
+
this.antecedents = [];
|
|
130
|
+
this.markJustification(justification);
|
|
131
|
+
this.processJustifications();
|
|
132
|
+
const result = this.antecedents;
|
|
133
|
+
this.antecedents = saved;
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
justificationToLiterals(justification: Justification) {
|
|
138
|
+
const result = this.justificationToLiteralsCore(justification);
|
|
139
|
+
this.unmarkJustifications(0);
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private getJustificationMaxLevel(justification: Justification) {
|
|
144
|
+
let result = 0;
|
|
145
|
+
for (const literal of this.justificationToLiterals(justification))
|
|
146
|
+
result = Math.max(result, this.context.getAssignLevel(literal));
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private getMaxLevel(consequent: Literal, justification: BJustification) {
|
|
151
|
+
const context = this.context;
|
|
152
|
+
let result = consequent !== context.falseLiteral ? context.getAssignLevel(consequent) : 0;
|
|
153
|
+
if (justification instanceof Justification)
|
|
154
|
+
return Math.max(result, this.getJustificationMaxLevel(justification));
|
|
155
|
+
if (justification instanceof BinJustification)
|
|
156
|
+
return Math.max(result, context.getAssignLevel(justification.literal));
|
|
157
|
+
if (justification === null || justification === "axiom") return result;
|
|
158
|
+
const clauses = context.clauses;
|
|
159
|
+
const numLiterals = clauses.getNumLiterals(justification);
|
|
160
|
+
let start = 0;
|
|
161
|
+
if (consequent !== context.falseLiteral) {
|
|
162
|
+
if (clauses.getLiteral(justification, 0) === consequent) start = 1;
|
|
163
|
+
else {
|
|
164
|
+
result = Math.max(result, context.getAssignLevel(clauses.getLiteral(justification, 0)));
|
|
165
|
+
start = 2;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (let index = start; index < numLiterals; index++)
|
|
169
|
+
result = Math.max(result, context.getAssignLevel(clauses.getLiteral(justification, index)));
|
|
170
|
+
const clauseJustification = clauses.getJustification(justification);
|
|
171
|
+
if (clauseJustification !== null)
|
|
172
|
+
result = Math.max(result, this.getJustificationMaxLevel(clauseJustification));
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private processAntecedent(antecedent: Literal, marks: { count: number }) {
|
|
177
|
+
const context = this.context;
|
|
178
|
+
const boolVar = getVar(antecedent);
|
|
179
|
+
const level = context.getLevel(boolVar);
|
|
180
|
+
if (context.isMarked(boolVar) || level <= context.baseLevel) return;
|
|
181
|
+
context.setMark(boolVar, true);
|
|
182
|
+
context.incBvarActivity(boolVar);
|
|
183
|
+
if (level === this.conflictLevel) marks.count++;
|
|
184
|
+
else {
|
|
185
|
+
this.lemma.push(negate(antecedent));
|
|
186
|
+
this.lemmaAtoms.push(context.boolVar2Expr[boolVar]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private processJustification(justification: Justification, marks: { count: number }) {
|
|
191
|
+
for (const literal of this.justificationToLiteralsCore(justification))
|
|
192
|
+
this.processAntecedent(literal, marks);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Returns false when the conflict is at the search level, so the problem is unsat.
|
|
196
|
+
resolve(conflict: BJustification, notLiteral: Literal | null) {
|
|
197
|
+
const context = this.context;
|
|
198
|
+
this.lemma = [];
|
|
199
|
+
this.lemmaAtoms.reset();
|
|
200
|
+
let justification = conflict;
|
|
201
|
+
let consequent = notLiteral !== null ? negate(notLiteral) : context.falseLiteral;
|
|
202
|
+
this.conflictLevel = this.getMaxLevel(consequent, justification);
|
|
203
|
+
if (this.conflictLevel <= context.searchLevel) return false;
|
|
204
|
+
const assigned = context.assignedLiterals;
|
|
205
|
+
let index = assigned.length - 1;
|
|
206
|
+
while (index > 0 && context.getAssignLevel(assigned[index]) > this.conflictLevel) index--;
|
|
207
|
+
// The first slot holds the negated first unique implication point, found below.
|
|
208
|
+
this.lemma.push(context.falseLiteral);
|
|
209
|
+
this.lemmaAtoms.push(-1);
|
|
210
|
+
const marks = { count: 0 };
|
|
211
|
+
if (notLiteral !== null) this.processAntecedent(notLiteral, marks);
|
|
212
|
+
do {
|
|
213
|
+
if (justification instanceof Justification) this.processJustification(justification, marks);
|
|
214
|
+
else if (justification instanceof BinJustification)
|
|
215
|
+
this.processAntecedent(justification.literal, marks);
|
|
216
|
+
else if (justification !== null && justification !== "axiom") {
|
|
217
|
+
const clause = justification;
|
|
218
|
+
const clauses = context.clauses;
|
|
219
|
+
if (clauses.isLemma(clause)) clauses.incActivity(clause);
|
|
220
|
+
const numLiterals = clauses.getNumLiterals(clause);
|
|
221
|
+
let start = 0;
|
|
222
|
+
if (consequent !== context.falseLiteral) {
|
|
223
|
+
if (clauses.getLiteral(clause, 0) === consequent) start = 1;
|
|
224
|
+
else {
|
|
225
|
+
this.processAntecedent(negate(clauses.getLiteral(clause, 0)), marks);
|
|
226
|
+
start = 2;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
for (let literalIndex = start; literalIndex < numLiterals; literalIndex++)
|
|
230
|
+
this.processAntecedent(negate(clauses.getLiteral(clause, literalIndex)), marks);
|
|
231
|
+
const clauseJustification = clauses.getJustification(clause);
|
|
232
|
+
if (clauseJustification !== null) this.processJustification(clauseJustification, marks);
|
|
233
|
+
}
|
|
234
|
+
while (!context.isMarked(getVar(assigned[index]))) index--;
|
|
235
|
+
consequent = assigned[index];
|
|
236
|
+
const consequentVar = getVar(consequent);
|
|
237
|
+
justification = context.justifications[consequentVar];
|
|
238
|
+
index--;
|
|
239
|
+
marks.count--;
|
|
240
|
+
context.setMark(consequentVar, false);
|
|
241
|
+
} while (marks.count > 0);
|
|
242
|
+
this.lemma[0] = negate(consequent);
|
|
243
|
+
this.lemmaAtoms.set(0, context.boolVar2Expr[getVar(consequent)]);
|
|
244
|
+
this.finalizeResolve();
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private finalizeResolve() {
|
|
249
|
+
const context = this.context;
|
|
250
|
+
this.unmarkJustifications(0);
|
|
251
|
+
this.minimizeLemma();
|
|
252
|
+
this.newScopeLevel = context.searchLevel;
|
|
253
|
+
this.lemmaIscopeLevel = context.getInternLevel(getVar(this.lemma[0]));
|
|
254
|
+
for (let index = 1; index < this.lemma.length; index++) {
|
|
255
|
+
const boolVar = getVar(this.lemma[index]);
|
|
256
|
+
context.setMark(boolVar, false);
|
|
257
|
+
this.newScopeLevel = Math.max(this.newScopeLevel, context.getLevel(boolVar));
|
|
258
|
+
this.lemmaIscopeLevel = Math.max(this.lemmaIscopeLevel, context.getInternLevel(boolVar));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private processAntecedentForMinimization(antecedent: Literal) {
|
|
263
|
+
const context = this.context;
|
|
264
|
+
const boolVar = getVar(antecedent);
|
|
265
|
+
const level = context.getLevel(boolVar);
|
|
266
|
+
if (context.isMarked(boolVar) || level <= context.baseLevel) return true;
|
|
267
|
+
if ((this.levelSet & (1 << (level & 31))) === 0) return false;
|
|
268
|
+
context.setMark(boolVar, true);
|
|
269
|
+
this.unmark.push(boolVar);
|
|
270
|
+
this.minimizationStack.push(boolVar);
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private processJustificationForMinimization(justification: Justification) {
|
|
275
|
+
for (const literal of this.justificationToLiteralsCore(justification))
|
|
276
|
+
if (!this.processAntecedentForMinimization(literal)) return false;
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private resetUnmark(oldSize: number, oldHead: number) {
|
|
281
|
+
for (let index = oldSize; index < this.unmark.length; index++)
|
|
282
|
+
this.context.setMark(this.unmark[index], false);
|
|
283
|
+
shrink(this.unmark, oldSize);
|
|
284
|
+
this.unmarkJustifications(oldHead);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private isImpliedByMarked(literal: Literal) {
|
|
288
|
+
const context = this.context;
|
|
289
|
+
this.minimizationStack = [getVar(literal)];
|
|
290
|
+
const oldSize = this.unmark.length;
|
|
291
|
+
const oldHead = this.todoJustificationsHead;
|
|
292
|
+
while (this.minimizationStack.length > 0) {
|
|
293
|
+
const boolVar = this.minimizationStack.pop() ?? -1;
|
|
294
|
+
const justification = context.justifications[boolVar];
|
|
295
|
+
let isImplied = true;
|
|
296
|
+
if (justification instanceof Justification)
|
|
297
|
+
isImplied = this.processJustificationForMinimization(justification);
|
|
298
|
+
else if (justification instanceof BinJustification)
|
|
299
|
+
isImplied = this.processAntecedentForMinimization(justification.literal);
|
|
300
|
+
else if (justification === null || justification === "axiom")
|
|
301
|
+
isImplied = context.getLevel(boolVar) <= context.baseLevel;
|
|
302
|
+
else {
|
|
303
|
+
const clauses = context.clauses;
|
|
304
|
+
const numLiterals = clauses.getNumLiterals(justification);
|
|
305
|
+
const position = getVar(clauses.getLiteral(justification, 1)) === boolVar ? 1 : 0;
|
|
306
|
+
for (let index = 0; index < numLiterals && isImplied; index++)
|
|
307
|
+
if (index !== position)
|
|
308
|
+
isImplied = this.processAntecedentForMinimization(
|
|
309
|
+
negate(clauses.getLiteral(justification, index)),
|
|
310
|
+
);
|
|
311
|
+
const clauseJustification = clauses.getJustification(justification);
|
|
312
|
+
if (isImplied && clauseJustification !== null)
|
|
313
|
+
isImplied = this.processJustificationForMinimization(clauseJustification);
|
|
314
|
+
}
|
|
315
|
+
if (!isImplied) {
|
|
316
|
+
this.resetUnmark(oldSize, oldHead);
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private minimizeLemma() {
|
|
324
|
+
const context = this.context;
|
|
325
|
+
this.unmark = [];
|
|
326
|
+
this.levelSet = 0;
|
|
327
|
+
for (const literal of this.lemma)
|
|
328
|
+
this.levelSet |= 1 << (context.getLevel(getVar(literal)) & 31);
|
|
329
|
+
let kept = 1;
|
|
330
|
+
for (let index = 1; index < this.lemma.length; index++) {
|
|
331
|
+
const literal = this.lemma[index];
|
|
332
|
+
if (this.isImpliedByMarked(literal)) this.unmark.push(getVar(literal));
|
|
333
|
+
else {
|
|
334
|
+
this.lemma[kept] = literal;
|
|
335
|
+
if (kept !== index) this.lemmaAtoms.set(kept, this.lemmaAtoms.items[index]);
|
|
336
|
+
kept++;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
this.resetUnmark(0, 0);
|
|
340
|
+
shrink(this.lemma, kept);
|
|
341
|
+
this.lemmaAtoms.shrink(kept);
|
|
342
|
+
}
|
|
343
|
+
}
|