tla-ts 0.0.9 → 0.0.10
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 +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +72 -10
- package/dist/index.d.ts +72 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +576 -300
- package/src/cli/options.ts +11 -6
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +538 -220
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +630 -297
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +29 -39
- package/src/parallel.ts +29 -13
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +119 -169
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +1 -8
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +494 -154
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +826 -276
- package/src/worker.ts +7 -8
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/smt_solver.cpp, src/smt/smt_kernel.cpp, src/smt/smt_setup.cpp), MIT
|
|
2
|
-
// license, see z3-license.txt. Decides an SMT-LIB problem the way `z3 -smt2 AUTO_CONFIG=false
|
|
3
|
-
// smt.MBQI=true` does for tlapm's UFNIA obligations.
|
|
1
|
+
// Ported from Z3 (src/smt/smt_solver.cpp, src/smt/smt_kernel.cpp, src/smt/smt_setup.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import { isStackOverflow, SmtCanceledError, SmtUnsupportedError } from "../../../errors";
|
|
5
3
|
import type { DecideOptions, Verdict } from "../../verdict";
|
|
6
4
|
import { AssertedFormulas } from "./asserted-formulas";
|
|
@@ -16,46 +14,37 @@ interface SmtCheck {
|
|
|
16
14
|
numInstances: number;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
// The verdict, and the number of quantifier instances the search made.
|
|
20
17
|
export const checkSmt = (text: string, options: DecideOptions): SmtCheck => {
|
|
21
18
|
const manager = new AstManager(
|
|
22
19
|
new ResourceLimit(Date.now() + options.timeLimitMs, options.signal),
|
|
23
20
|
);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// kernel's model finder counts a step of the resource limit when it is made, and
|
|
27
|
-
// solver::assert_expr counts one for each assertion.
|
|
28
|
-
const incremental = new AssertedFormulas(manager);
|
|
29
|
-
manager.limit.inc();
|
|
30
|
-
const problem = parseSmtlib(text, manager, (assertion) => {
|
|
21
|
+
try {
|
|
22
|
+
const incremental = new AssertedFormulas(manager);
|
|
31
23
|
manager.limit.inc();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
const problem = parseSmtlib(text, manager, (assertion) => {
|
|
25
|
+
manager.limit.inc();
|
|
26
|
+
incremental.assertExpr(assertion);
|
|
27
|
+
});
|
|
28
|
+
if (!problem.hasCheckSat) return { verdict: "unknown", numInstances: 0 };
|
|
29
|
+
const goal = applyUfniaTactic(manager, problem.assertions);
|
|
30
|
+
if (goal.isInconsistent || goal.forms.size === 0) {
|
|
31
|
+
return { verdict: goal.isInconsistent ? "unsat" : "sat", numInstances: 0 };
|
|
32
|
+
}
|
|
33
|
+
const asserted = new AssertedFormulas(manager);
|
|
34
|
+
const context = new Context(manager, { isMbqi: true, relevancyLevel: 2 });
|
|
35
|
+
for (const assertion of goal.forms.items) asserted.assertExpr(assertion);
|
|
36
|
+
context.setupContext();
|
|
37
|
+
context.internalizeAssertions(asserted);
|
|
38
|
+
const result = context.search();
|
|
39
|
+
return {
|
|
40
|
+
verdict: result === L_FALSE ? "unsat" : result === L_TRUE ? "sat" : "unknown",
|
|
41
|
+
numInstances: context.qmanager.getNumInstances(),
|
|
42
|
+
};
|
|
43
|
+
} finally {
|
|
38
44
|
manager.limit.release();
|
|
39
|
-
return { verdict: goal.isInconsistent ? "unsat" : "sat", numInstances: 0 };
|
|
40
45
|
}
|
|
41
|
-
// smt_tactic makes the context, which makes its asserted formulas first, and asserts the goal.
|
|
42
|
-
// setup_context then makes the theories, before the formulas are reduced.
|
|
43
|
-
const asserted = new AssertedFormulas(manager);
|
|
44
|
-
const context = new Context(manager, { isMbqi: true, relevancyLevel: 2 });
|
|
45
|
-
for (const assertion of goal.forms.items) asserted.assertExpr(assertion);
|
|
46
|
-
context.setupContext();
|
|
47
|
-
context.internalizeAssertions(asserted);
|
|
48
|
-
const result = context.search();
|
|
49
|
-
manager.limit.release();
|
|
50
|
-
return {
|
|
51
|
-
verdict: result === L_FALSE ? "unsat" : result === L_TRUE ? "sat" : "unknown",
|
|
52
|
-
numInstances: context.qmanager.getNumInstances(),
|
|
53
|
-
};
|
|
54
46
|
};
|
|
55
47
|
|
|
56
|
-
// Throws SmtParseError on malformed input. Input outside the subset the solver supports is unknown,
|
|
57
|
-
// and so is a search that runs past the time limit, that the signal aborts, or that exhausts the
|
|
58
|
-
// heap or the stack.
|
|
59
48
|
export const decideSmt = (text: string, options: DecideOptions): Verdict => {
|
|
60
49
|
try {
|
|
61
50
|
return checkSmt(text, options).verdict;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Array.prototype.sort copies its array before sorting,
|
|
2
|
-
// clauses and disjunctions. Insertion sort is stable like it and sorts a short array in place, so
|
|
3
|
-
// both give the same order.
|
|
1
|
+
// Array.prototype.sort copies its array before sorting, so a short array is insertion sorted in place, which is stable too.
|
|
4
2
|
const MAX_INSERTION_SORT_LENGTH = 16;
|
|
5
3
|
|
|
6
4
|
export const sortByKey = (values: number[], getKey: (value: number) => number) => {
|
|
@@ -18,8 +16,6 @@ export const sortByKey = (values: number[], getKey: (value: number) => number) =
|
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
// std::sort of literals: sortByKey with the number as its key, which a call site of its own keeps
|
|
22
|
-
// cheap.
|
|
23
19
|
export const sortNumbers = (values: number[]) => {
|
|
24
20
|
if (values.length > MAX_INSERTION_SORT_LENGTH) {
|
|
25
21
|
values.sort((first, second) => first - second);
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
// Ported from Z3 (src/smt/smt_context.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// m_sticky_generation_updates: the generations that update_generation lowered, by node. Only a node
|
|
3
|
-
// of the same declaration can be congruent to another, so the updates are grouped by declaration.
|
|
4
|
-
// Each group keeps its updates in the order of insertion, as a Map does, in arrays that iterate
|
|
5
|
-
// without allocating. A deleted update leaves a hole until holes are half of its group.
|
|
6
2
|
import { shrink } from "./array";
|
|
7
3
|
import type { Enode } from "./enode";
|
|
8
4
|
|
|
@@ -47,7 +43,6 @@ export class StickyGenerations {
|
|
|
47
43
|
if (2 * group.numHoles > group.nodes.length) compact(group);
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
// The updates of the declaration in the order of insertion, where a deleted one is null.
|
|
51
46
|
getGroup(decl: number): Readonly<Pick<Group, "nodes" | "generations">> | undefined {
|
|
52
47
|
return this.groups.get(decl);
|
|
53
48
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/theory_lra.cpp, src/smt/arith_eq_adapter.cpp), MIT license, see
|
|
2
|
-
// z3-license.txt. The axioms of theory_lra: those of div, mod, to_int and is_int, and the
|
|
3
|
-
// arith_eq_adapter axioms that tie an equality of terms to their two inequalities.
|
|
1
|
+
// Ported from Z3 (src/smt/theory_lra.cpp, src/smt/arith_eq_adapter.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import { SmtInvariantError } from "../../../errors";
|
|
5
3
|
import {
|
|
6
4
|
OP_ADD,
|
|
@@ -18,7 +16,7 @@ import {
|
|
|
18
16
|
SORT_INT,
|
|
19
17
|
SORT_REAL,
|
|
20
18
|
} from "./ast";
|
|
21
|
-
import { Enode } from "./enode";
|
|
19
|
+
import type { Enode } from "./enode";
|
|
22
20
|
import { FALSE_LITERAL, getVar, isNegated, Literal, negate, TRUE_LITERAL } from "./literal";
|
|
23
21
|
import { Rational } from "./rational";
|
|
24
22
|
import { TheoryLraState } from "./theory-lra-state";
|
|
@@ -26,10 +24,8 @@ import { TheoryLraState } from "./theory-lra-state";
|
|
|
26
24
|
export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
27
25
|
private processedEqs = new Set<string>();
|
|
28
26
|
|
|
29
|
-
// m_restart_pairs: equalities whose axioms a backjump to the base level drops, remade on restart.
|
|
30
27
|
protected restartPairs: Enode[][] = [];
|
|
31
28
|
|
|
32
|
-
// The enode of a term, internalized first if it has none.
|
|
33
29
|
protected getInternalizedEnode(expr: number) {
|
|
34
30
|
const context = this.context;
|
|
35
31
|
if (!context.isEInternalized(expr)) context.internalize(expr, false);
|
|
@@ -133,27 +129,21 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
133
129
|
else if (op === OP_MOD) this.mkIdivModAxioms(manager.getArg(expr, 0), manager.getArg(expr, 1));
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
// mk_literal.
|
|
137
132
|
protected mkLiteral(atom: number) {
|
|
138
133
|
const context = this.context;
|
|
139
134
|
if (!context.isEInternalized(atom)) context.internalize(atom, false);
|
|
140
135
|
return context.getLiteral(atom);
|
|
141
136
|
}
|
|
142
137
|
|
|
143
|
-
// ensure_enode: the relevant enode of a term.
|
|
144
138
|
private ensureEnode(expr: number) {
|
|
145
139
|
const node = this.getInternalizedEnode(expr);
|
|
146
140
|
this.context.markAsRelevant(expr);
|
|
147
141
|
return node;
|
|
148
142
|
}
|
|
149
143
|
|
|
150
|
-
//
|
|
151
|
-
// relevant only once the first is false. A unit axiom is the clause of false and the literal, so
|
|
152
|
-
// mk_clause drops false and the literal is justified by unit resolution with true, which lemma
|
|
153
|
-
// minimization can see through, rather than by an axiom.
|
|
144
|
+
// A unit axiom is the clause of false and the literal, so Z3 justifies the literal by unit resolution, not by an axiom.
|
|
154
145
|
protected mkAxiom(literals: Literal[]) {
|
|
155
146
|
const context = this.context;
|
|
156
|
-
// mkThAxiom simplifies the literals it is given, which this reads after.
|
|
157
147
|
context.mkThAxiom(
|
|
158
148
|
literals.length === 1 ? [context.falseLiteral, literals[0]] : literals.slice(),
|
|
159
149
|
);
|
|
@@ -167,12 +157,10 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
167
157
|
context.relevancy.addWatch(
|
|
168
158
|
context.boolVar2Expr[getVar(literals[0])],
|
|
169
159
|
isNegated(literals[0]),
|
|
170
|
-
// simple_relevancy_eh marks the consequent without propagating.
|
|
171
160
|
() => context.relevancy.markAsRelevant(consequent),
|
|
172
161
|
);
|
|
173
162
|
}
|
|
174
163
|
|
|
175
|
-
// mk_div_axiom: q = 0 or q * (p / q) = p.
|
|
176
164
|
private mkDivAxiom(dividend: number, divisor: number) {
|
|
177
165
|
const manager = this.manager;
|
|
178
166
|
if (this.isZeroNumeral(divisor)) return;
|
|
@@ -185,7 +173,6 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
185
173
|
this.mkAxiom([isZero, this.mkEq(product, dividend)]);
|
|
186
174
|
}
|
|
187
175
|
|
|
188
|
-
// mk_to_int_axiom: to_int (to_real x) = x, and to_real (to_int x) <= x < to_real (to_int x) + 1.
|
|
189
176
|
private mkToIntAxiom(term: number) {
|
|
190
177
|
const manager = this.manager;
|
|
191
178
|
const arg = manager.getArg(term, 0);
|
|
@@ -210,7 +197,6 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
210
197
|
this.mkAxiom([negate(upperLiteral)]);
|
|
211
198
|
}
|
|
212
199
|
|
|
213
|
-
// mk_is_int_axiom: is_int x if and only if to_real (to_int x) = x.
|
|
214
200
|
protected mkIsIntAxiom(atom: number) {
|
|
215
201
|
const manager = this.manager;
|
|
216
202
|
const arg = manager.getArg(atom, 0);
|
|
@@ -223,7 +209,6 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
223
209
|
this.mkAxiom([isInt, negate(eq)]);
|
|
224
210
|
}
|
|
225
211
|
|
|
226
|
-
// theory::mk_eq: the literal of an equality between two terms, internalized.
|
|
227
212
|
protected mkEq(first: number, second: number) {
|
|
228
213
|
const manager = this.manager;
|
|
229
214
|
if (first === second) return TRUE_LITERAL;
|
|
@@ -233,11 +218,9 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
233
218
|
return this.context.getLiteral(atom);
|
|
234
219
|
}
|
|
235
220
|
|
|
236
|
-
// mk_idiv_mod_axioms: q * (div p q) + (mod p q) = p and 0 <= (mod p q) < |q| when q is not 0.
|
|
237
221
|
protected mkIdivModAxioms(dividend: number, divisor: number) {
|
|
238
222
|
const manager = this.manager;
|
|
239
223
|
if (manager.getNumeral(divisor) === 0n) return;
|
|
240
|
-
// The expr_refs of mk_idiv_mod_axioms, released in reverse when it returns.
|
|
241
224
|
const refs: number[] = [];
|
|
242
225
|
const hold = (expr: number) => {
|
|
243
226
|
manager.incRef(expr);
|
|
@@ -255,7 +238,6 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
255
238
|
const remainder = hold(manager.mkApp(OP_MOD, [dividend, divisor], SORT_INT));
|
|
256
239
|
const zero = hold(manager.mkNumeral(0n));
|
|
257
240
|
if (manager.getNumeral(dividend) === 0n) {
|
|
258
|
-
// q != 0 implies div 0 q = 0 and mod 0 q = 0.
|
|
259
241
|
const isDivisorNonnegative = this.mkLiteral(manager.mkApp(OP_GE, [divisor, zero], SORT_BOOL));
|
|
260
242
|
const isDivisorNonpositive = this.mkLiteral(manager.mkApp(OP_LE, [divisor, zero], SORT_BOOL));
|
|
261
243
|
const consequents = [
|
|
@@ -289,7 +271,6 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
289
271
|
this.mkAxiom([this.mkLiteral(manager.mkApp(OP_LE, [remainder, upper], SORT_BOOL))]);
|
|
290
272
|
return;
|
|
291
273
|
}
|
|
292
|
-
// q = 0 or (mod p q) >= 0, q >= 0 or (mod p q) + q <= -1, and q <= 0 or (mod p q) - q <= -1.
|
|
293
274
|
const minusOne = hold(manager.mkNumeral(-1n));
|
|
294
275
|
const minusDivisor = hold(manager.mkApp(OP_MUL, [minusOne, divisor], SORT_INT));
|
|
295
276
|
const isZero = this.mkLiteral(manager.mkEq(divisor, zero));
|
|
@@ -317,8 +298,6 @@ export abstract class TheoryLraAxioms extends TheoryLraState {
|
|
|
317
298
|
);
|
|
318
299
|
this.mkAxiom([isDivisorNonnegative, isBelowNegatedDivisor]);
|
|
319
300
|
this.mkEqAxioms(this.ensureEnode(combination), this.ensureEnode(dividend));
|
|
320
|
-
// q = 0 or q * (div p q) <= p. The rewritten atom replaces the unrewritten one, which Z3
|
|
321
|
-
// releases at once, and its own expr_ref goes at the end of the block.
|
|
322
301
|
const unrewritten = manager.mkApp(
|
|
323
302
|
OP_GE,
|
|
324
303
|
[
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
// Ported from Z3 (src/smt/theory_lra.cpp, src/math/lp/lp_api.h), MIT license, see z3-license.txt.
|
|
2
|
-
// The atoms of theory_lra: each is a bound on a column, with axioms between the bounds of the same
|
|
3
|
-
// column.
|
|
4
2
|
import { OP_GE, OP_IS_INT, OP_LE } from "./ast";
|
|
5
3
|
import { BoolVar, Literal, mkLiteral, negate } from "./literal";
|
|
6
4
|
import { Rational } from "./rational";
|
|
@@ -68,7 +66,6 @@ export abstract class TheoryLraBounds extends TheoryLraInternalize {
|
|
|
68
66
|
this.unassignedBounds[thVar] = saved + increment;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
// bound2constraint_kind: the kind of the bound when its atom is true or false.
|
|
72
69
|
protected getBoundKind(bound: ApiBound, isTrue: boolean) {
|
|
73
70
|
if (bound.isLower) return isTrue ? KIND_GE : bound.isInt ? KIND_LE : KIND_LT;
|
|
74
71
|
return isTrue ? KIND_LE : bound.isInt ? KIND_GE : KIND_GT;
|
|
@@ -94,7 +91,6 @@ export abstract class TheoryLraBounds extends TheoryLraInternalize {
|
|
|
94
91
|
return { boolVar, thVar, column, value, constraintTrue, constraintFalse, ...partial };
|
|
95
92
|
}
|
|
96
93
|
|
|
97
|
-
// mk_bound_axioms: implications between a new bound and its closest neighbors on the variable.
|
|
98
94
|
private mkBoundAxioms(bound: ApiBound) {
|
|
99
95
|
if (!this.context.isSearching) {
|
|
100
96
|
this.newBounds.push(bound);
|
|
@@ -146,7 +142,6 @@ export abstract class TheoryLraBounds extends TheoryLraInternalize {
|
|
|
146
142
|
else mkClause([negate(l1), l2]);
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
// flush_bound_axioms: the axioms of the bounds created before the search, per variable.
|
|
150
145
|
protected flushBoundAxioms() {
|
|
151
146
|
while (this.newBounds.length > 0) {
|
|
152
147
|
const pending = this.newBounds.slice().sort((first, second) => first.thVar - second.thVar);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// theory_lra: the integer solver and its branches and cuts, then nla on nonlinear terms, whose
|
|
3
|
-
// lemmas become clauses.
|
|
1
|
+
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import { OP_ADD, OP_GE, OP_LE, OP_MUL, OP_TO_REAL, SORT_BOOL, SORT_INT, SORT_REAL } from "./ast";
|
|
5
3
|
import { FC_CONTINUE, FC_DONE, FC_GIVEUP } from "./context";
|
|
6
4
|
import { TheoryJustification } from "./enode";
|
|
@@ -8,11 +6,11 @@ import { L_FALSE, L_TRUE, L_UNDEF } from "./lbool";
|
|
|
8
6
|
import { getVar, Literal, negate } from "./literal";
|
|
9
7
|
import { getGcd, getLcm, Rational } from "./rational";
|
|
10
8
|
import { KIND_EQ, KIND_GE, KIND_GT, KIND_LT, KIND_NE } from "./lp/constraints";
|
|
11
|
-
import { Explanation } from "./lp/explanation";
|
|
9
|
+
import type { Explanation } from "./lp/explanation";
|
|
12
10
|
import { IntSolver } from "./lp/int-solver";
|
|
13
11
|
import type { LarTerm } from "./lp/lar-term";
|
|
14
|
-
import { NlaCore } from "./lp/nla-core";
|
|
15
|
-
import { Ineq, Lemma } from "./lp/nla-types";
|
|
12
|
+
import type { NlaCore } from "./lp/nla-core";
|
|
13
|
+
import type { Ineq, Lemma } from "./lp/nla-types";
|
|
16
14
|
import { TheoryLraModel } from "./theory-lra-model";
|
|
17
15
|
|
|
18
16
|
export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
@@ -37,18 +35,14 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
37
35
|
let result = FC_DONE;
|
|
38
36
|
const nlaStatus = this.checkNla(level);
|
|
39
37
|
if (nlaStatus === FC_CONTINUE) return FC_CONTINUE;
|
|
40
|
-
// Nonlinear bound optimization may invalidate integer feasibility.
|
|
41
38
|
if (nlaStatus === FC_DONE && !this.nla?.isUsingNraModel && solver.hasInfInt())
|
|
42
39
|
return FC_CONTINUE;
|
|
43
40
|
if (nlaStatus === FC_GIVEUP) result = FC_GIVEUP;
|
|
44
41
|
if (this.assumeEqs()) return FC_CONTINUE;
|
|
45
42
|
if (this.unsupportedTerms.length > 0) this.initVariableValues();
|
|
46
|
-
// eval_unsupported gives up on every term but powers, which are not supported here.
|
|
47
43
|
return this.unsupportedTerms.some((term) => context.isRelevant(term)) ? FC_GIVEUP : result;
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
// check_nla: whether the values of the monomials agree with their factors', or the lemmas that
|
|
51
|
-
// refine them.
|
|
52
46
|
private checkNla(level: number) {
|
|
53
47
|
if (this.context.checkCanceled()) return FC_GIVEUP;
|
|
54
48
|
const nla = this.nla;
|
|
@@ -61,7 +55,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
61
55
|
return status === L_TRUE ? FC_DONE : FC_GIVEUP;
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
// check_idiv_bounds: the lemmas of the bounded divisions.
|
|
65
58
|
private checkIdivBounds() {
|
|
66
59
|
const nla = this.nla;
|
|
67
60
|
if (nla === undefined) return true;
|
|
@@ -70,7 +63,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
70
63
|
return nla.lemmas.length === 0;
|
|
71
64
|
}
|
|
72
65
|
|
|
73
|
-
// propagate_nla and incremental_propagate_nla: the bounds nla derives for monomials.
|
|
74
66
|
protected propagateNla(isIncremental: boolean) {
|
|
75
67
|
const nla = this.nla;
|
|
76
68
|
if (nla === undefined) return;
|
|
@@ -97,7 +89,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
97
89
|
this.addEq(equality.first, equality.second, equality.explanation, false);
|
|
98
90
|
}
|
|
99
91
|
|
|
100
|
-
// add_equality: a column fixed to a value, equal to the variable of the value's numeral.
|
|
101
92
|
private addEquality(column: number, value: Rational, explanation: Explanation) {
|
|
102
93
|
const thVar = value.equals(Rational.one)
|
|
103
94
|
? this.oneVar
|
|
@@ -108,9 +99,7 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
108
99
|
this.addEq(this.registerVar(thVar), column, explanation, true);
|
|
109
100
|
}
|
|
110
101
|
|
|
111
|
-
// mk_literal: the literal of an inequality of nla, over a bound or equality atom.
|
|
112
102
|
private mkNlaLiteral(ineq: Ineq) {
|
|
113
|
-
// scoped_auxiliary: the bounds of the atom are auxiliary constraints.
|
|
114
103
|
const constraints = this.solver.constraints;
|
|
115
104
|
constraints.isAuxiliaryMode = true;
|
|
116
105
|
const literal = this.mkNlaLiteralCore(ineq);
|
|
@@ -130,7 +119,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
130
119
|
return kind === KIND_LT || kind === KIND_GT ? negate(literal) : literal;
|
|
131
120
|
}
|
|
132
121
|
|
|
133
|
-
// mk_eq: the atom term = offset.
|
|
134
122
|
private mkTermEq(term: LarTerm, offset: Rational) {
|
|
135
123
|
const manager = this.manager;
|
|
136
124
|
const coeffs = this.getTermCoeffs(term);
|
|
@@ -145,8 +133,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
145
133
|
return atom;
|
|
146
134
|
}
|
|
147
135
|
|
|
148
|
-
// false_case_of_check_nla and set_conflict_or_lemma: the lemma as a theory axiom, unless one of
|
|
149
|
-
// its literals is already true.
|
|
150
136
|
private falseCaseOfCheckNla(lemma: Lemma) {
|
|
151
137
|
const context = this.context;
|
|
152
138
|
const literals = lemma.ineqs.map((ineq) => negate(this.mkNlaLiteral(ineq)));
|
|
@@ -164,7 +150,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
164
150
|
context.mkThAxiom(clause);
|
|
165
151
|
}
|
|
166
152
|
|
|
167
|
-
// check_lia: whether the integer solver found the integer columns integral.
|
|
168
153
|
private isLiaSat() {
|
|
169
154
|
if (this.context.checkCanceled()) return false;
|
|
170
155
|
const move = this.lia.check();
|
|
@@ -185,7 +170,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
185
170
|
return move.kind === "sat";
|
|
186
171
|
}
|
|
187
172
|
|
|
188
|
-
// mk_bound: the atom of a bound on an lp term, over the theory variables of its columns.
|
|
189
173
|
private mkBound(lpTerm: LarTerm, inputOffset: Rational, inputIsLower: boolean) {
|
|
190
174
|
const manager = this.manager;
|
|
191
175
|
const context = this.context;
|
|
@@ -226,8 +210,6 @@ export abstract class TheoryLraFinalCheck extends TheoryLraModel {
|
|
|
226
210
|
return atom;
|
|
227
211
|
}
|
|
228
212
|
|
|
229
|
-
// coeffs2app: the sum of the expressions of theory variables times coefficients, with Int
|
|
230
|
-
// expressions of a Real sum coerced to Real.
|
|
231
213
|
private coeffsToApp(coeffs: [number, Rational][], isInt: boolean) {
|
|
232
214
|
const manager = this.manager;
|
|
233
215
|
const sort = isInt ? SORT_INT : SORT_REAL;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// internalizes terms: a term becomes a column of the lp solver, a linear sum becomes a term column,
|
|
3
|
-
// nonlinear products and divisions go to nla, and numerals are fixed columns.
|
|
1
|
+
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import {
|
|
5
3
|
FAMILY_ARITH,
|
|
6
4
|
OP_ADD,
|
|
@@ -29,7 +27,6 @@ import { NlaCore } from "./lp/nla-core";
|
|
|
29
27
|
import type { Division } from "./lp/nla-divisions";
|
|
30
28
|
import { TheoryLraAxioms } from "./theory-lra-axioms";
|
|
31
29
|
|
|
32
|
-
// api_bound: an atom v <= value or v >= value, with its constraints when true and when false.
|
|
33
30
|
export interface ApiBound {
|
|
34
31
|
readonly boolVar: BoolVar;
|
|
35
32
|
readonly thVar: number;
|
|
@@ -48,7 +45,6 @@ interface Scope {
|
|
|
48
45
|
numVars: number;
|
|
49
46
|
}
|
|
50
47
|
|
|
51
|
-
// The theory variables of a linear sum and their coefficients.
|
|
52
48
|
interface LinearizedSum {
|
|
53
49
|
vars: number[];
|
|
54
50
|
coeffs: Rational[];
|
|
@@ -62,30 +58,23 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
62
58
|
protected realOneVar = NULL_LPVAR;
|
|
63
59
|
protected realZeroVar = NULL_LPVAR;
|
|
64
60
|
|
|
65
|
-
// The literal of each inequality constraint, and null for a definition.
|
|
66
61
|
protected constraintSources: (Literal | null)[] = [];
|
|
67
62
|
|
|
68
63
|
protected bounds: ApiBound[][] = [];
|
|
69
64
|
protected unassignedBounds: number[] = [];
|
|
70
65
|
protected isNewDef = false;
|
|
71
66
|
|
|
72
|
-
// m_internalize_states: the terms of each nesting depth of internalize_def and mk_var_bound, which
|
|
73
|
-
// hold references until the next one at that depth resets them.
|
|
74
67
|
private internalizeStates: RefVector[] = [];
|
|
75
68
|
|
|
76
69
|
protected internalizeHead = 0;
|
|
77
70
|
protected scopes: Scope[] = [];
|
|
78
71
|
protected value2var = new Map<string, number>();
|
|
79
72
|
|
|
80
|
-
// m_not_handled: terms that the theory treats as uninterpreted, so a model may not satisfy them.
|
|
81
|
-
// Their arguments have variables, as the factors of an nla monomial do.
|
|
82
73
|
protected unsupportedTerms: number[] = [];
|
|
83
74
|
|
|
84
75
|
protected underspecifiedTerms: number[] = [];
|
|
85
76
|
protected nla: NlaCore | undefined;
|
|
86
77
|
|
|
87
|
-
// init: the constants 1 and 0, integer and then real, each in a scope of its own. The context
|
|
88
|
-
// runs it once, when it registers the theory.
|
|
89
78
|
init() {
|
|
90
79
|
const manager = this.manager;
|
|
91
80
|
this.oneVar = this.addConst(manager.mkNumeral(1n));
|
|
@@ -126,7 +115,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
126
115
|
return column !== NULL_LPVAR ? column : this.solver.addVar(thVar, this.isIntVar(thVar));
|
|
127
116
|
}
|
|
128
117
|
|
|
129
|
-
// mk_enode: the arguments, which become relevant, then the term.
|
|
130
118
|
protected mkEnode(expr: number) {
|
|
131
119
|
const context = this.context;
|
|
132
120
|
for (let index = 0; index < this.manager.getNumArgs(expr); index++) {
|
|
@@ -149,14 +137,11 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
149
137
|
}
|
|
150
138
|
}
|
|
151
139
|
|
|
152
|
-
// found_unsupported: the list of unsupported terms is on the trail.
|
|
153
140
|
protected foundUnsupported(expr: number) {
|
|
154
141
|
this.unsupportedTerms.push(expr);
|
|
155
142
|
this.context.pushTrail(() => this.unsupportedTerms.pop());
|
|
156
143
|
}
|
|
157
144
|
|
|
158
|
-
// found_underspecified: a division by a term or by zero equals the division by zero it stands
|
|
159
|
-
// for, which the model interprets freely.
|
|
160
145
|
private foundUnderspecified(expr: number) {
|
|
161
146
|
const manager = this.manager;
|
|
162
147
|
const context = this.context;
|
|
@@ -197,7 +182,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
197
182
|
return thVar;
|
|
198
183
|
}
|
|
199
184
|
|
|
200
|
-
// internalize_mul: a product of terms is a variable whose arguments have variables.
|
|
201
185
|
private internalizeMul(expr: number) {
|
|
202
186
|
this.internalizeArgs(expr);
|
|
203
187
|
const hasVar = this.context.isEInternalized(expr) && this.isAttachedExpr(expr);
|
|
@@ -214,7 +198,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
214
198
|
return thVar;
|
|
215
199
|
}
|
|
216
200
|
|
|
217
|
-
// ensure_nla: the nonlinear solver, made on the first nonlinear term, in the current scopes.
|
|
218
201
|
private ensureNla() {
|
|
219
202
|
if (this.nla !== undefined) return this.nla;
|
|
220
203
|
const nla = new NlaCore(this.solver, this.manager.limit);
|
|
@@ -225,8 +208,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
225
208
|
return nla;
|
|
226
209
|
}
|
|
227
210
|
|
|
228
|
-
// The columns of a quotient, its dividend and divisor, and the remainder, internalized in that
|
|
229
|
-
// order.
|
|
230
211
|
private registerDivision(quotient: number, remainder: number): Division {
|
|
231
212
|
const register = (expr: number) => {
|
|
232
213
|
this.internalizeTermCore(expr);
|
|
@@ -244,7 +225,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
244
225
|
return this.manager.isNumeral(expr) && !this.manager.getRationalValue(expr).isZero();
|
|
245
226
|
}
|
|
246
227
|
|
|
247
|
-
// arith_util::is_bounded: a numeral, a mod by a numeral, or a div by a numeral of a bounded term.
|
|
248
228
|
private isBounded(expr: number): boolean {
|
|
249
229
|
const manager = this.manager;
|
|
250
230
|
const op = manager.getOp(expr);
|
|
@@ -258,7 +238,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
258
238
|
return node !== undefined && this.isAttachedToVar(node);
|
|
259
239
|
}
|
|
260
240
|
|
|
261
|
-
// scoped_internalize_state: the terms of the next depth, reset. The caller decrements the head.
|
|
262
241
|
protected pushInternalizeState() {
|
|
263
242
|
const terms = (this.internalizeStates[this.internalizeHead] ??= new RefVector(this.manager));
|
|
264
243
|
this.internalizeHead++;
|
|
@@ -266,7 +245,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
266
245
|
return terms;
|
|
267
246
|
}
|
|
268
247
|
|
|
269
|
-
// linearize: the theory variables of a weighted sum of terms, with their coefficients.
|
|
270
248
|
private linearize(terms: RefVector, coeffs: Rational[]) {
|
|
271
249
|
const manager = this.manager;
|
|
272
250
|
const context = this.context;
|
|
@@ -367,7 +345,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
367
345
|
} else if (op === OP_MOD) {
|
|
368
346
|
const isNonzeroDivisor = this.isNonzeroNumeral(manager.getArg(term, 1));
|
|
369
347
|
if (!isNonzeroDivisor) this.foundUnderspecified(term);
|
|
370
|
-
// Without relevancy, Z3 makes the axioms before it registers the division with nla.
|
|
371
348
|
if (!context.relevancy.isEnabled)
|
|
372
349
|
this.mkIdivModAxioms(manager.getArg(term, 0), manager.getArg(term, 1));
|
|
373
350
|
if (this.nla !== undefined && isNonzeroDivisor) {
|
|
@@ -411,7 +388,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
411
388
|
return { vars, coeffs: coeffs.slice(0, vars.length) };
|
|
412
389
|
}
|
|
413
390
|
|
|
414
|
-
// init_left_side: the coefficients of the variables summed, in the order of the variables.
|
|
415
391
|
private initLeftSide(vars: number[], coeffs: Rational[]) {
|
|
416
392
|
const sums = new Map<number, Rational>();
|
|
417
393
|
vars.forEach((thVar, index) =>
|
|
@@ -427,7 +403,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
427
403
|
return leftSide;
|
|
428
404
|
}
|
|
429
405
|
|
|
430
|
-
// internalize_def: the variable of a term, with a column for its linear combination.
|
|
431
406
|
protected internalizeDef(expr: number) {
|
|
432
407
|
const terms = this.pushInternalizeState();
|
|
433
408
|
terms.push(expr);
|
|
@@ -436,7 +411,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
436
411
|
return thVar;
|
|
437
412
|
}
|
|
438
413
|
|
|
439
|
-
// internalize_linearized_def: term - v = 0, unless the term is its own variable.
|
|
440
414
|
private internalizeLinearizedDef(expr: number, linearized: LinearizedSum) {
|
|
441
415
|
const thVar = this.mkVar(expr);
|
|
442
416
|
if (
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// theory_lra: the values of its variables, and the equalities between shared terms with equal
|
|
3
|
-
// values that it assumes.
|
|
1
|
+
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import {
|
|
5
3
|
FAMILY_ARITH,
|
|
6
4
|
FAMILY_BASIC,
|
|
@@ -13,7 +11,7 @@ import {
|
|
|
13
11
|
OP_MOD0,
|
|
14
12
|
} from "./ast";
|
|
15
13
|
import { SmtUnsupportedError } from "../../../errors";
|
|
16
|
-
import { Enode } from "./enode";
|
|
14
|
+
import type { Enode } from "./enode";
|
|
17
15
|
import type { ProtoModel } from "./proto-model";
|
|
18
16
|
import { Rational } from "./rational";
|
|
19
17
|
import { NULL_LPVAR } from "./lp/lar-solver";
|
|
@@ -30,9 +28,8 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
30
28
|
protected initVariableValues() {
|
|
31
29
|
this.isModelInitialized = false;
|
|
32
30
|
if (this.context.checkCanceled() || this.getNumVars() === 0) return;
|
|
33
|
-
const saved = this.isModelInitialized;
|
|
34
31
|
this.context.pushTrail(() => {
|
|
35
|
-
this.isModelInitialized =
|
|
32
|
+
this.isModelInitialized = false;
|
|
36
33
|
});
|
|
37
34
|
this.isModelInitialized = this.solver.initModel();
|
|
38
35
|
}
|
|
@@ -41,7 +38,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
41
38
|
return this.context.isRelevant(node.owner) && this.isShared(node);
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
// random_update: moves the values of shared variables that collide with others.
|
|
45
41
|
private randomUpdate() {
|
|
46
42
|
if (this.nla?.hasRelevantMonomial()) return;
|
|
47
43
|
const solver = this.solver;
|
|
@@ -70,7 +66,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
70
66
|
if (columns.length > 0) randomUpdate(solver, columns);
|
|
71
67
|
}
|
|
72
68
|
|
|
73
|
-
// assume_eqs: model-based theory combination.
|
|
74
69
|
protected assumeEqs() {
|
|
75
70
|
if (this.delayedAssumeEqs()) return true;
|
|
76
71
|
this.randomUpdate();
|
|
@@ -86,7 +81,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
86
81
|
const thVar = (index + start) % numVars;
|
|
87
82
|
if (!this.isRelevantAndShared(this.getEnode(thVar))) continue;
|
|
88
83
|
const column = this.registerVar(thVar);
|
|
89
|
-
// m_model_eqs: with nlsat's model, the values are compared one by one.
|
|
90
84
|
const key = `${this.isIntVar(thVar)}:${solver.getValue(column)}`;
|
|
91
85
|
const other = this.nla?.isUsingNraModel
|
|
92
86
|
? representatives.find(
|
|
@@ -130,8 +124,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
130
124
|
return false;
|
|
131
125
|
}
|
|
132
126
|
|
|
133
|
-
// init_model: the model knows the value of every theory variable without δ, so fresh numbers
|
|
134
|
-
// avoid them. Like get_value(enode*, expr_ref&), it skips an integer with a fractional value.
|
|
135
127
|
initModel(model: ProtoModel) {
|
|
136
128
|
this.initVariableValues();
|
|
137
129
|
if (!this.isModelInitialized) return;
|
|
@@ -144,7 +136,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
144
136
|
}
|
|
145
137
|
}
|
|
146
138
|
|
|
147
|
-
// mk_value: the value of the class of a root, rounded down for an integer.
|
|
148
139
|
mkValue(node: Enode) {
|
|
149
140
|
if (node.thVar < 0) return undefined;
|
|
150
141
|
const nla = this.nla;
|
|
@@ -154,7 +145,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
154
145
|
this.solver.externalToLocalColumn(node.thVar) === NULL_LPVAR
|
|
155
146
|
)
|
|
156
147
|
return this.getValueExpr(node.thVar);
|
|
157
|
-
// nlsat's value, zero for an integer whose value is not one.
|
|
158
148
|
const value = this.getNlValue(nla, node.thVar).value;
|
|
159
149
|
if (this.isIntVar(node.thVar))
|
|
160
150
|
return this.manager.mkNumeral(value instanceof Rational && value.isInt() ? value.num : 0n);
|
|
@@ -162,7 +152,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
162
152
|
return this.manager.mkRealNumeral(value);
|
|
163
153
|
}
|
|
164
154
|
|
|
165
|
-
// is_eq: whether two variables have the same value, in nlsat's model when nla uses it.
|
|
166
155
|
private isEq(first: number, second: number) {
|
|
167
156
|
const nla = this.nla;
|
|
168
157
|
if (nla !== undefined && nla.isUsingNraModel)
|
|
@@ -173,7 +162,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
173
162
|
.equals(solver.getValue(this.registerVar(second)));
|
|
174
163
|
}
|
|
175
164
|
|
|
176
|
-
// nl_value: the value of a variable in nlsat's model, a term's the sum over its columns.
|
|
177
165
|
private getNlValue(nla: NlaCore, thVar: number) {
|
|
178
166
|
const solver = this.solver;
|
|
179
167
|
const am = nla.nra.am;
|
|
@@ -181,8 +169,7 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
181
169
|
if (!solver.hasTerm(column)) return nla.nra.value(column);
|
|
182
170
|
let result = new Anum(Rational.zero);
|
|
183
171
|
const todo: [number, Rational][] = [[column, Rational.one]];
|
|
184
|
-
|
|
185
|
-
const pending = todo.pop()!;
|
|
172
|
+
for (let pending = todo.pop(); pending !== undefined; pending = todo.pop()) {
|
|
186
173
|
for (const entry of solver.getTerm(pending[0]).coeffs) {
|
|
187
174
|
const coeff = entry[1].mul(pending[1]);
|
|
188
175
|
if (solver.hasTerm(entry[0])) todo.push([entry[0], coeff]);
|
|
@@ -216,7 +203,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
216
203
|
return this.isSharedWithUnderspecified(root);
|
|
217
204
|
}
|
|
218
205
|
|
|
219
|
-
// theory_lra::is_shared: whether the class is an argument of a division by a term or by zero.
|
|
220
206
|
private isSharedWithUnderspecified(root: Enode) {
|
|
221
207
|
const manager = this.manager;
|
|
222
208
|
const count = this.underspecifiedTerms.length;
|
|
@@ -228,7 +214,6 @@ export abstract class TheoryLraModel extends TheoryLraPropagate {
|
|
|
228
214
|
return root.parents.some((parent) => this.isUnderspecified(parent.owner));
|
|
229
215
|
}
|
|
230
216
|
|
|
231
|
-
// arith_util::is_underspecified.
|
|
232
217
|
private isUnderspecified(expr: number) {
|
|
233
218
|
const op = this.manager.getOp(expr);
|
|
234
219
|
return (
|