tla-ts 0.0.9 → 0.0.10-dev.63a6693bd
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 +29 -29
- package/dist/deciders.js +42 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -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 +117 -37
- 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 +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +48 -62
- package/src/bags.ts +99 -102
- package/src/builtins.ts +28 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +599 -754
- package/src/cli/options.ts +12 -32
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +19 -12
- package/src/cli/tlapm.ts +14 -25
- package/src/cli/tlc-arguments.ts +652 -0
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +309 -658
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +27 -49
- package/src/cli.ts +0 -1
- package/src/codegen.ts +196 -74
- package/src/config.ts +140 -109
- package/src/coverage.ts +830 -0
- package/src/dependencies.ts +14 -53
- package/src/dfid.ts +618 -0
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +169 -335
- package/src/errors.ts +71 -55
- package/src/evaluate.ts +598 -340
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +75 -11
- package/src/index.ts +3 -0
- package/src/instances.ts +126 -21
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +252 -139
- package/src/levels.ts +46 -58
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +103 -153
- package/src/liveness.ts +150 -109
- package/src/obligations/action.ts +8 -39
- package/src/obligations/anonymize.ts +88 -82
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +20 -21
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +46 -49
- package/src/obligations/index.ts +2 -13
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +28 -53
- package/src/obligations/normalize.ts +7 -25
- 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 +42 -58
- package/src/obligations/source.ts +48 -78
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +13 -19
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +30 -60
- package/src/parallel.ts +57 -71
- package/src/parser.ts +584 -316
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +8 -13
- package/src/prover/deciders.ts +3 -7
- 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 +114 -115
- package/src/prover/isabelle/isar/method.ts +29 -53
- 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 +26 -36
- package/src/prover/isabelle/isar/type-check.ts +17 -31
- package/src/prover/isabelle/provers/blast/blast.ts +17 -104
- 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 +28 -51
- package/src/prover/isabelle/pure/bicompose.ts +25 -38
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +3 -17
- package/src/prover/isabelle/pure/drule.ts +33 -42
- 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 +2 -15
- 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 +17 -62
- package/src/prover/isabelle/pure/rewriter.ts +31 -67
- 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 +3 -32
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +48 -47
- 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 +27 -47
- 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 +17 -24
- package/src/prover/isabelle/tla/context.ts +15 -18
- package/src/prover/isabelle/tla/logic.ts +14 -32
- package/src/prover/isabelle/tla/simpdata.ts +46 -43
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +14 -54
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +2 -21
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +33 -39
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +87 -100
- 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 +20 -28
- package/src/prover/smt/data.ts +433 -424
- package/src/prover/smt/encode.ts +43 -52
- 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 +663 -667
- 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 -165
- package/src/prover/smt/solver/auf-solver.ts +8 -44
- 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 +7 -64
- 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 +4 -35
- 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 +1 -6
- 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 +7 -100
- 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 +9 -102
- 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 +36 -135
- 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 +18 -58
- 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 +3 -37
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +15 -32
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +23 -88
- package/src/prover/smt/solver/nlsat/algebraic.ts +63 -159
- package/src/prover/smt/solver/nlsat/atoms.ts +25 -23
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +10 -69
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +49 -135
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +29 -159
- package/src/prover/smt/solver/nlsat/solver.ts +18 -90
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +2 -45
- 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 -52
- 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 +27 -47
- package/src/prover/smt/solver/quantifier-manager.ts +2 -13
- 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 +80 -131
- 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 +1 -7
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +6 -43
- 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 +45 -40
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +21 -20
- package/src/prover/verdict.ts +7 -2
- package/src/prover/zenon/check/check.ts +1 -11
- 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 +1 -6
- package/src/prover/zenon/check/relations.ts +2 -14
- package/src/prover/zenon/check/rewrites.ts +2 -21
- package/src/prover/zenon/check/sets.ts +40 -61
- package/src/prover/zenon/check/terms.ts +1 -19
- 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 +2 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +8 -26
- package/src/prover/zenon/index-table.ts +26 -57
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +36 -64
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +2 -20
- package/src/prover/zenon/mltoll.ts +66 -104
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +4 -12
- 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 +5 -31
- package/src/prover/zenon/tla/functions.ts +59 -31
- package/src/prover/zenon/tla/llproof.ts +67 -76
- package/src/prover/zenon/tla/records.ts +57 -33
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +83 -53
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +66 -64
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +67 -184
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +191 -2764
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +58 -77
- package/src/sany/linter.ts +1 -9
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +5 -43
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +32 -69
- package/src/sany/selectors.ts +49 -76
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +35 -117
- package/src/search.ts +541 -163
- package/src/simulate.ts +709 -0
- package/src/spec-description.ts +192 -100
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +264 -95
- package/src/state-graph.ts +52 -31
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +7 -7
- package/src/successors.ts +266 -99
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +125 -54
- package/src/tlc/order.ts +39 -69
- package/src/tlc/random.ts +37 -49
- package/src/tlc/replay.ts +553 -228
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +78 -44
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +249 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +479 -0
- package/src/typescript/collections.ts +614 -0
- package/src/typescript/compile.ts +63 -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 +154 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +162 -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 +167 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -484
- package/src/worker.ts +7 -8
|
@@ -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;
|
|
@@ -287,10 +265,8 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
287
265
|
toEnsureEnode.push(term);
|
|
288
266
|
const op = manager.getOp(term);
|
|
289
267
|
if (op === OP_ADD) {
|
|
290
|
-
for (let argIndex = 0; argIndex < manager.getNumArgs(term); argIndex++)
|
|
291
|
-
|
|
292
|
-
push(arg, coeffs[index]);
|
|
293
|
-
}
|
|
268
|
+
for (let argIndex = 0; argIndex < manager.getNumArgs(term); argIndex++)
|
|
269
|
+
push(manager.getArg(term, argIndex), coeffs[index]);
|
|
294
270
|
if (terms.size !== index + 1) {
|
|
295
271
|
terms.set(index, terms.items[terms.size - 1]);
|
|
296
272
|
coeffs[index] = coeffs[coeffs.length - 1];
|
|
@@ -346,10 +322,7 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
346
322
|
if (op === OP_DIV) {
|
|
347
323
|
const divisor = context.rewriter.rewrite(manager.getArg(term, 1));
|
|
348
324
|
if (!this.isNonzeroNumeral(divisor)) this.foundUnderspecified(term);
|
|
349
|
-
|
|
350
|
-
const arg = manager.getArg(term, argIndex);
|
|
351
|
-
toEnsureVar.push(arg);
|
|
352
|
-
}
|
|
325
|
+
manager.pushArgs(term, toEnsureVar);
|
|
353
326
|
} else if (op === OP_IDIV) {
|
|
354
327
|
if (!this.isNonzeroNumeral(manager.getArg(term, 1))) this.foundUnderspecified(term);
|
|
355
328
|
const remainder = manager.mkApp(OP_MOD, manager.getArgs(term), SORT_INT);
|
|
@@ -367,7 +340,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
367
340
|
} else if (op === OP_MOD) {
|
|
368
341
|
const isNonzeroDivisor = this.isNonzeroNumeral(manager.getArg(term, 1));
|
|
369
342
|
if (!isNonzeroDivisor) this.foundUnderspecified(term);
|
|
370
|
-
// Without relevancy, Z3 makes the axioms before it registers the division with nla.
|
|
371
343
|
if (!context.relevancy.isEnabled)
|
|
372
344
|
this.mkIdivModAxioms(manager.getArg(term, 0), manager.getArg(term, 1));
|
|
373
345
|
if (this.nla !== undefined && isNonzeroDivisor) {
|
|
@@ -385,16 +357,10 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
385
357
|
nla.divisions.addDivisibility(this.registerDivision(quotient, term));
|
|
386
358
|
}
|
|
387
359
|
} else if (op === OP_IDIV0 || op === OP_MOD0) {
|
|
388
|
-
|
|
389
|
-
const arg = manager.getArg(term, argIndex);
|
|
390
|
-
toEnsureVar.push(arg);
|
|
391
|
-
}
|
|
360
|
+
manager.pushArgs(term, toEnsureVar);
|
|
392
361
|
} else if (op !== OP_TO_INT && op !== OP_DIV0) {
|
|
393
362
|
this.foundUnsupported(term);
|
|
394
|
-
|
|
395
|
-
const arg = manager.getArg(term, argIndex);
|
|
396
|
-
toEnsureVar.push(arg);
|
|
397
|
-
}
|
|
363
|
+
manager.pushArgs(term, toEnsureVar);
|
|
398
364
|
}
|
|
399
365
|
if (!context.relevancy.isEnabled && op !== OP_MOD) this.relevantEh(term);
|
|
400
366
|
}
|
|
@@ -411,7 +377,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
411
377
|
return { vars, coeffs: coeffs.slice(0, vars.length) };
|
|
412
378
|
}
|
|
413
379
|
|
|
414
|
-
// init_left_side: the coefficients of the variables summed, in the order of the variables.
|
|
415
380
|
private initLeftSide(vars: number[], coeffs: Rational[]) {
|
|
416
381
|
const sums = new Map<number, Rational>();
|
|
417
382
|
vars.forEach((thVar, index) =>
|
|
@@ -427,7 +392,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
427
392
|
return leftSide;
|
|
428
393
|
}
|
|
429
394
|
|
|
430
|
-
// internalize_def: the variable of a term, with a column for its linear combination.
|
|
431
395
|
protected internalizeDef(expr: number) {
|
|
432
396
|
const terms = this.pushInternalizeState();
|
|
433
397
|
terms.push(expr);
|
|
@@ -436,7 +400,6 @@ export abstract class TheoryLraInternalize extends TheoryLraAxioms {
|
|
|
436
400
|
return thVar;
|
|
437
401
|
}
|
|
438
402
|
|
|
439
|
-
// internalize_linearized_def: term - v = 0, unless the term is its own variable.
|
|
440
403
|
private internalizeLinearizedDef(expr: number, linearized: LinearizedSum) {
|
|
441
404
|
const thVar = this.mkVar(expr);
|
|
442
405
|
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 (
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// propagates: asserted bounds go to the lp solver, the tableau is made feasible, and implied bounds
|
|
3
|
-
// and equalities of fixed columns come back as literals and equalities.
|
|
1
|
+
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import { OP_ITE, OP_SUB, SORT_BOOL } from "./ast";
|
|
5
3
|
import { TheoryJustification } from "./enode";
|
|
6
4
|
import { getIdentityHash, ObjMap } from "./hashtable";
|
|
@@ -55,7 +53,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
55
53
|
this.propagateCore();
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
// propagate_core: whether there was anything to propagate.
|
|
59
56
|
protected propagateCore() {
|
|
60
57
|
const context = this.context;
|
|
61
58
|
this.isModelInitialized = false;
|
|
@@ -135,7 +132,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
135
132
|
return true;
|
|
136
133
|
}
|
|
137
134
|
|
|
138
|
-
// propagate_eqs: a bound that fixes a column, with the opposite bound of the same value.
|
|
139
135
|
private propagateEqs(
|
|
140
136
|
column: number,
|
|
141
137
|
constraint: number,
|
|
@@ -151,7 +147,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
151
147
|
this.fixedVarEh(bound.thVar, column, mkJoin(mkLeaf(constraint), opposite), value);
|
|
152
148
|
}
|
|
153
149
|
|
|
154
|
-
// set_bound: records the bound of a term column, or checks that a column has the bound.
|
|
155
150
|
private setTermBound(column: number, constraint: number, value: Rational, isLower: boolean) {
|
|
156
151
|
const solver = this.solver;
|
|
157
152
|
if (!solver.hasTerm(column)) {
|
|
@@ -172,7 +167,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
172
167
|
return true;
|
|
173
168
|
}
|
|
174
169
|
|
|
175
|
-
// has_bound: the dependency of a bound of the column with the value, if it has one.
|
|
176
170
|
private getFixingBound(
|
|
177
171
|
column: number,
|
|
178
172
|
value: Rational,
|
|
@@ -199,7 +193,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
199
193
|
return this.getEnode(first).root === this.getEnode(second).root;
|
|
200
194
|
}
|
|
201
195
|
|
|
202
|
-
// report_equality_of_fixed_vars: two columns fixed to the same value are equal.
|
|
203
196
|
protected reportEqualityOfFixedVars(first: number, second: number) {
|
|
204
197
|
const solver = this.solver;
|
|
205
198
|
const v1 = solver.getExternal(first);
|
|
@@ -220,8 +213,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
220
213
|
this.assignEq(v1, v2);
|
|
221
214
|
}
|
|
222
215
|
|
|
223
|
-
// fixed_var_eh: a column fixed to a value is equal to an offset term, or to the variable of the
|
|
224
|
-
// numeral with that value.
|
|
225
216
|
private fixedVarEh(thVar: number, column: number, dep: Dependency, value: Rational) {
|
|
226
217
|
if (this.propagateOffsetEq(column, dep, value)) return;
|
|
227
218
|
const isInt = this.isIntVar(thVar);
|
|
@@ -238,7 +229,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
238
229
|
this.assignEq(thVar, other);
|
|
239
230
|
}
|
|
240
231
|
|
|
241
|
-
// propagate_offset_eq: x - y fixed to 0 makes x and y equal.
|
|
242
232
|
private propagateOffsetEq(column: number, dep: Dependency, value: Rational) {
|
|
243
233
|
if (!value.isZero() || !this.solver.hasTerm(column)) return false;
|
|
244
234
|
const coeffs = this.getTermCoeffs(this.solver.getTerm(column));
|
|
@@ -254,8 +244,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
254
244
|
return true;
|
|
255
245
|
}
|
|
256
246
|
|
|
257
|
-
// term2coeffs: the coefficients of the theory variables of a term, with term columns expanded,
|
|
258
|
-
// in the slot order of Z3's u_map.
|
|
259
247
|
protected getTermCoeffs(term: LarTerm) {
|
|
260
248
|
const coeffs = new ObjMap<Rational>(getIdentityHash);
|
|
261
249
|
const visit = (current: LarTerm, coeff: Rational) => {
|
|
@@ -281,7 +269,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
281
269
|
});
|
|
282
270
|
}
|
|
283
271
|
|
|
284
|
-
// add_eq: an equality that the lp solver implies, with its explanation.
|
|
285
272
|
protected addEq(first: number, second: number, explanation: Explanation, isFixed: boolean) {
|
|
286
273
|
if (this.context.isInconsistent()) return false;
|
|
287
274
|
const v1 = this.solver.getExternal(first);
|
|
@@ -363,7 +350,6 @@ export abstract class TheoryLraPropagate extends TheoryLraBounds {
|
|
|
363
350
|
}
|
|
364
351
|
}
|
|
365
352
|
|
|
366
|
-
// is_bound_implied: the literal of the bound that the implied bound makes true or false.
|
|
367
353
|
private isBoundImplied(kind: ConstraintKind, value: Rational, bound: ApiBound) {
|
|
368
354
|
const literal = getAtomLiteral(bound);
|
|
369
355
|
const comparison = value.compare(bound.value);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
|
|
3
|
-
// atoms, and what the scopes undo. The theory is a chain of classes, one file each, from this state
|
|
4
|
-
// to TheoryLra, so each part reaches the ones before it.
|
|
5
|
-
import { AstManager } from "./ast";
|
|
1
|
+
// Ported from Z3 (src/smt/theory_lra.cpp), MIT license, see z3-license.txt.
|
|
2
|
+
import type { AstManager } from "./ast";
|
|
6
3
|
import type { Context } from "./context";
|
|
7
|
-
import { Enode } from "./enode";
|
|
4
|
+
import type { Enode } from "./enode";
|
|
8
5
|
import { LarSolver } from "./lp/lar-solver";
|
|
9
6
|
|
|
10
7
|
export abstract class TheoryLraState {
|
|
@@ -19,8 +16,6 @@ export abstract class TheoryLraState {
|
|
|
19
16
|
return this.context.manager;
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
// get_enode, get_expr and get_num_vars: the theory reaches enodes only through these and
|
|
23
|
-
// isEqual.
|
|
24
19
|
getEnode(thVar: number) {
|
|
25
20
|
return this.varEnodes[thVar];
|
|
26
21
|
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/smt/theory_lra.cpp, src/smt/arith_eq_adapter.cpp, src/math/lp/lp_api.h), MIT
|
|
2
|
-
// license, see z3-license.txt. Linear integer and real arithmetic, as the theory_lra solver that
|
|
3
|
-
// Z3's default configuration uses for UFNIA. Terms become columns of the lp solver, integer or not
|
|
4
|
-
// by their sort, atoms become bounds on them, propagation makes the tableau feasible and propagates
|
|
5
|
-
// implied bounds and equalities, and the final check runs the integer solver and assumes equalities
|
|
6
|
-
// between shared terms with equal values. Nonlinear products and divisions go to nla
|
|
7
|
-
// (src/math/lp/nla_core.cpp), which refines the model with lemmas, and runs nlsat on what they
|
|
8
|
-
// leave open. This class adds the scopes to the chain of classes that theory-lra-state.ts starts.
|
|
1
|
+
// Ported from Z3 (src/smt/theory_lra.cpp, src/smt/arith_eq_adapter.cpp, src/math/lp/lp_api.h), MIT license, see z3-license.txt.
|
|
9
2
|
import { shrink } from "./array";
|
|
10
3
|
import { TheoryLraFinalCheck } from "./theory-lra-final-check";
|
|
11
4
|
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
// Ported from Z3 (src/ast/rewriter/var_subst.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// shifting of de Bruijn variables.
|
|
1
|
+
// Ported from Z3 (src/ast/rewriter/var_subst.cpp), MIT license, see z3-license.txt.
|
|
3
2
|
import { KIND_APP, KIND_QUANTIFIER, KIND_VAR, type AstManager, type SmtSymbol } from "./ast";
|
|
4
3
|
import { ExprSafeReplace } from "./expr-safe-replace";
|
|
5
4
|
import { BetaReducer } from "./rewriter-tpl";
|
|
6
5
|
|
|
7
|
-
// var_subst: substitutes args for the free variables, args[n - 1 - i] for (:var i) in standard
|
|
8
|
-
// order and args[i] otherwise, where -1 keeps the variable. Each result comes with a reference,
|
|
9
|
-
// which the caller releases.
|
|
10
6
|
export class VarSubst {
|
|
11
7
|
private reducer: BetaReducer;
|
|
12
8
|
|
|
@@ -61,14 +57,11 @@ export class VarSubst {
|
|
|
61
57
|
return this.reducer.rewrite(expr);
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
// ~var_subst.
|
|
65
60
|
release() {
|
|
66
61
|
this.reducer.release();
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
|
|
70
|
-
// A term whose children replaceFreeVars is rebuilding: where its children's results start on the
|
|
71
|
-
// result stack, and the next child to visit.
|
|
72
65
|
interface ReplaceFrame {
|
|
73
66
|
expr: number;
|
|
74
67
|
shift: number;
|
|
@@ -76,9 +69,6 @@ interface ReplaceFrame {
|
|
|
76
69
|
next: number;
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
// Rebuilds expr with each free variable replaced. replace gets the variable, its de Bruijn index
|
|
80
|
-
// relative to expr, and the number of binders above it. Like Z3's rewriter_tpl, it keeps its own
|
|
81
|
-
// stack, so deep terms do not exhaust the call stack.
|
|
82
72
|
export const replaceFreeVars = (
|
|
83
73
|
manager: AstManager,
|
|
84
74
|
expr: number,
|
|
@@ -108,7 +98,6 @@ export const replaceFreeVars = (
|
|
|
108
98
|
const frame = frames[frames.length - 1];
|
|
109
99
|
const current = frame.expr;
|
|
110
100
|
const data = manager.kinds[current] === KIND_QUANTIFIER ? manager.getQuantifier(current) : null;
|
|
111
|
-
// A quantifier's children are its body and its patterns, under its binders.
|
|
112
101
|
const numChildren = data === null ? manager.getNumArgs(current) : 1 + data.patterns.length;
|
|
113
102
|
if (frame.next < numChildren) {
|
|
114
103
|
const index = frame.next++;
|
|
@@ -129,9 +118,6 @@ export const replaceFreeVars = (
|
|
|
129
118
|
return results[0];
|
|
130
119
|
};
|
|
131
120
|
|
|
132
|
-
// used_vars::process: the sort of each free variable of expr below count, indexed by de Bruijn
|
|
133
|
-
// index, undefined for a variable that does not occur. Like Z3, it walks the term without rebuilding
|
|
134
|
-
// it, and visits a shared term once for each number of binders above it.
|
|
135
121
|
export const getFreeVarSorts = (manager: AstManager, expr: number, count: number) => {
|
|
136
122
|
const sorts: (number | undefined)[] = Array.from({ length: count }, () => undefined);
|
|
137
123
|
const exprs = [expr];
|
|
@@ -151,8 +137,7 @@ export const getFreeVarSorts = (manager: AstManager, expr: number, count: number
|
|
|
151
137
|
if (index < count && sorts[index] === undefined) sorts[index] = manager.sorts[current];
|
|
152
138
|
} else if (kind === KIND_APP)
|
|
153
139
|
for (let index = 0; index < manager.getNumArgs(current); index++) {
|
|
154
|
-
|
|
155
|
-
exprs.push(arg);
|
|
140
|
+
exprs.push(manager.getArg(current, index));
|
|
156
141
|
deltas.push(delta);
|
|
157
142
|
}
|
|
158
143
|
else {
|
|
@@ -166,12 +151,9 @@ export const getFreeVarSorts = (manager: AstManager, expr: number, count: number
|
|
|
166
151
|
return sorts;
|
|
167
152
|
};
|
|
168
153
|
|
|
169
|
-
// Which variables of a quantifier body occur, indexed by de Bruijn index.
|
|
170
154
|
export const collectUsedVars = (manager: AstManager, expr: number, count: number) =>
|
|
171
155
|
getFreeVarSorts(manager, expr, count).map((sort) => sort !== undefined);
|
|
172
156
|
|
|
173
|
-
// unused_vars_eliminator: drops the variables that neither the body nor a pattern uses. Its
|
|
174
|
-
// var_subst keeps the cache of its last substitution until the next one.
|
|
175
157
|
export class UnusedVarsEliminator {
|
|
176
158
|
private subst: VarSubst;
|
|
177
159
|
|
|
@@ -179,18 +161,15 @@ export class UnusedVarsEliminator {
|
|
|
179
161
|
this.subst = new VarSubst(manager, true);
|
|
180
162
|
}
|
|
181
163
|
|
|
182
|
-
// The result comes with a reference, which the caller releases.
|
|
183
164
|
apply(expr: number) {
|
|
184
165
|
const manager = this.manager;
|
|
185
166
|
return manager.withoutTemporaries(() => {
|
|
186
167
|
const data = manager.kinds[expr] === KIND_QUANTIFIER ? manager.getQuantifier(expr) : null;
|
|
187
|
-
// ignore_patterns_on_ground_qbody: a ground body drops the patterns with the variables.
|
|
188
168
|
const kept = data === null ? expr : manager.isGround(data.body) ? data.body : -1;
|
|
189
169
|
if (kept !== -1 || data === null) {
|
|
190
170
|
manager.incRef(kept);
|
|
191
171
|
return kept;
|
|
192
172
|
}
|
|
193
|
-
// used_vars: the sort of each free variable of the body and the patterns.
|
|
194
173
|
const usedSorts: (number | undefined)[] = [];
|
|
195
174
|
for (const term of [data.body, ...data.patterns])
|
|
196
175
|
getFreeVarSorts(manager, term, manager.freeVarBounds[term]).forEach((sort, index) => {
|
|
@@ -208,7 +187,6 @@ export class UnusedVarsEliminator {
|
|
|
208
187
|
keptSorts.push(sort);
|
|
209
188
|
keptNames.push(data.names[index]);
|
|
210
189
|
});
|
|
211
|
-
// var_mapping: (:var i) becomes the variable it moves to, and an unused variable stays.
|
|
212
190
|
const mapping: number[] = [];
|
|
213
191
|
let numRemoved = 0;
|
|
214
192
|
for (let index = 0; index < Math.max(numDecls, usedSorts.length); index++) {
|
|
@@ -242,13 +220,11 @@ export class UnusedVarsEliminator {
|
|
|
242
220
|
});
|
|
243
221
|
}
|
|
244
222
|
|
|
245
|
-
// ~unused_vars_eliminator.
|
|
246
223
|
release() {
|
|
247
224
|
this.subst.release();
|
|
248
225
|
}
|
|
249
226
|
}
|
|
250
227
|
|
|
251
|
-
// elim_unused_vars: unused_vars_eliminator with a var_subst of its own. The result is a temporary.
|
|
252
228
|
export const elimUnusedVars = (manager: AstManager, expr: number) => {
|
|
253
229
|
const eliminator = new UnusedVarsEliminator(manager);
|
|
254
230
|
const result = eliminator.apply(expr);
|