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,10 +1,5 @@
|
|
|
1
1
|
// Ported from Z3 (src/math/lp/dioph_eq.cpp, src/math/lp/var_register.h), MIT license, see
|
|
2
|
-
// z3-license.txt.
|
|
3
|
-
// Modulo Linear Integer Arithmetic": every integer term t with column j gives the equation
|
|
4
|
-
// t - j = 0 over the columns that are not fixed. The equations are normalized by the gcd of their
|
|
5
|
-
// coefficients, which finds a conflict when the gcd does not divide the constant, and solved for a
|
|
6
|
-
// column with a unit coefficient, or rewritten with a fresh column until one appears. The bounds of
|
|
7
|
-
// the term columns are then tightened modulo the gcd of their terms after the substitutions.
|
|
2
|
+
// z3-license.txt.
|
|
8
3
|
import { SmtInvariantError } from "../../../../errors";
|
|
9
4
|
import { getGcd, getLcm, Rational } from "../rational";
|
|
10
5
|
import { IndexedUintSet, UnorderedUintMap } from "./containers";
|
|
@@ -12,6 +7,7 @@ import { KIND_GE, KIND_LE } from "./constraints";
|
|
|
12
7
|
import { LP_CANCELLED, LP_FEASIBLE, LP_OPTIMAL } from "./core-solver";
|
|
13
8
|
import { type Dependency, mkJoin } from "./dependency";
|
|
14
9
|
import { Explanation } from "./explanation";
|
|
10
|
+
import { getRemainder } from "./hnf";
|
|
15
11
|
import type { IntSolver } from "./int-solver";
|
|
16
12
|
import type { LarSolver } from "./lar-solver";
|
|
17
13
|
import { LarTerm } from "./lar-term";
|
|
@@ -32,10 +28,8 @@ interface FreshDefinition {
|
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
const NO_VAR = -1;
|
|
35
|
-
// m_tighten_size_max: a longer term likely has gcd one.
|
|
36
31
|
const TIGHTEN_SIZE_MAX = 10;
|
|
37
32
|
|
|
38
|
-
// join of lia_move, for the moves the Diophantine solver makes.
|
|
39
33
|
const joinMoves = (first: DioMove, second: DioMove): DioMove => {
|
|
40
34
|
if (first === second || second === "undef") return first;
|
|
41
35
|
if (first === "undef") return second;
|
|
@@ -45,7 +39,6 @@ const joinMoves = (first: DioMove, second: DioMove): DioMove => {
|
|
|
45
39
|
const getTermMonomials = (term: LarTerm): Monomial[] =>
|
|
46
40
|
[...term.coeffs].map((entry) => ({ coeff: entry[1], column: entry[0] }));
|
|
47
41
|
|
|
48
|
-
// ext_coeffs: the monomials of the term and then the term column with coefficient -1.
|
|
49
42
|
const getExtendedMonomials = (term: LarTerm) => [
|
|
50
43
|
...getTermMonomials(term),
|
|
51
44
|
{ coeff: Rational.minusOne, column: term.column },
|
|
@@ -53,13 +46,9 @@ const getExtendedMonomials = (term: LarTerm) => [
|
|
|
53
46
|
|
|
54
47
|
const isUnit = (value: Rational) => value.equals(Rational.one) || value.equals(Rational.minusOne);
|
|
55
48
|
|
|
56
|
-
// rem and machine_div_rem of integers: truncating, so the remainder has the sign of the dividend.
|
|
57
|
-
const getRemainder = (left: Rational, right: Rational) => Rational.of(left.num % right.num);
|
|
58
|
-
|
|
59
49
|
const getTruncatedQuotient = (left: Rational, right: Rational) => Rational.of(left.num / right.num);
|
|
60
50
|
|
|
61
|
-
|
|
62
|
-
const getBitsize = (value: Rational) => {
|
|
51
|
+
const getRationalBitsize = (value: Rational) => {
|
|
63
52
|
const getIntBitsize = (part: bigint) =>
|
|
64
53
|
part === 0n ? 1 : (part < 0n ? -part : part).toString(2).length;
|
|
65
54
|
return value.isInt()
|
|
@@ -67,7 +56,6 @@ const getBitsize = (value: Rational) => {
|
|
|
67
56
|
: getIntBitsize(value.num) + getIntBitsize(value.den);
|
|
68
57
|
};
|
|
69
58
|
|
|
70
|
-
// gcd_of_coeffs: one as soon as a unit coefficient shows up when asked to look for one.
|
|
71
59
|
const getGcdOfCoeffs = (monomials: Iterable<{ coeff: Rational }>, isCheckingForOne: boolean) => {
|
|
72
60
|
if (isCheckingForOne)
|
|
73
61
|
for (const monomial of monomials) if (isUnit(monomial.coeff)) return Rational.one;
|
|
@@ -79,8 +67,6 @@ const getGcdOfCoeffs = (monomials: Iterable<{ coeff: Rational }>, isCheckingForO
|
|
|
79
67
|
return gcd;
|
|
80
68
|
};
|
|
81
69
|
|
|
82
|
-
// term_with_index: the monomials in a vector with the position of every column, and a removal
|
|
83
|
-
// that moves the last monomial into the gap.
|
|
84
70
|
class TermWithIndex {
|
|
85
71
|
readonly data: Monomial[] = [];
|
|
86
72
|
private positions: number[] = [];
|
|
@@ -127,7 +113,6 @@ class TermWithIndex {
|
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
115
|
|
|
130
|
-
// protected_queue: a queue of distinct columns that can also lose a column in the middle.
|
|
131
116
|
class ProtectedQueue {
|
|
132
117
|
readonly items: number[] = [];
|
|
133
118
|
private members = new Set<number>();
|
|
@@ -159,8 +144,6 @@ class ProtectedQueue {
|
|
|
159
144
|
}
|
|
160
145
|
}
|
|
161
146
|
|
|
162
|
-
// var_register: the local columns of the equations, and the lar_solver column of each, or none
|
|
163
|
-
// for a fresh column.
|
|
164
147
|
class VarRegister {
|
|
165
148
|
private localToExternal: number[] = [];
|
|
166
149
|
private externalToLocal = new Map<number, number>();
|
|
@@ -182,7 +165,6 @@ class VarRegister {
|
|
|
182
165
|
return this.externalToLocal.has(external);
|
|
183
166
|
}
|
|
184
167
|
|
|
185
|
-
// external_to_local, which Z3 asserts finds the column.
|
|
186
168
|
getLocal(external: number) {
|
|
187
169
|
const local = this.externalToLocal.get(external);
|
|
188
170
|
if (local === undefined)
|
|
@@ -202,8 +184,6 @@ class VarRegister {
|
|
|
202
184
|
}
|
|
203
185
|
}
|
|
204
186
|
|
|
205
|
-
// m_fresh_k2xt_terms: the definition of a substituted column k by a fresh column xt, reachable
|
|
206
|
-
// from both. The map from k to xt is an unordered_map whose order Z3 iterates.
|
|
207
187
|
class FreshDefinitions {
|
|
208
188
|
readonly keyToFresh = new UnorderedUintMap<number>();
|
|
209
189
|
private freshToKey = new Map<number, number>();
|
|
@@ -248,22 +228,16 @@ class FreshDefinitions {
|
|
|
248
228
|
}
|
|
249
229
|
|
|
250
230
|
export class DiophantineSolver {
|
|
251
|
-
// m_some_terms_are_ignored: a term was not integral or had a big number, so the GCD test and
|
|
252
|
-
// Gomory cuts run.
|
|
253
231
|
hasIgnoredTerms = false;
|
|
254
232
|
private readonly solver: LarSolver;
|
|
255
233
|
private sumOfFixed: Rational[] = [];
|
|
256
234
|
private varRegister = new VarRegister();
|
|
257
|
-
// m_e_matrix: the equations over local columns. m_l_matrix: each as a combination of the term
|
|
258
|
-
// definitions, which explains it.
|
|
259
235
|
private eMatrix = new StaticMatrix();
|
|
260
236
|
private lMatrix = new StaticMatrix();
|
|
261
237
|
private infeasExplanation = new Explanation();
|
|
262
|
-
// m_c, the constant of m_espace.
|
|
263
238
|
private constant = Rational.zero;
|
|
264
239
|
private lspace = new TermWithIndex();
|
|
265
240
|
private espace = new TermWithIndex();
|
|
266
|
-
// m_k2s: the column each equation of S is solved for, and back.
|
|
267
241
|
private keyToRow = new Map<number, number>();
|
|
268
242
|
private rowToKey = new Map<number, number>();
|
|
269
243
|
private freshDefinitions = new FreshDefinitions();
|
|
@@ -287,8 +261,7 @@ export class DiophantineSolver {
|
|
|
287
261
|
}
|
|
288
262
|
|
|
289
263
|
check() {
|
|
290
|
-
|
|
291
|
-
settings.stats.dioCalls++;
|
|
264
|
+
this.solver.settings.stats.dioCalls++;
|
|
292
265
|
const fVector: number[] = [];
|
|
293
266
|
let move: DioMove;
|
|
294
267
|
do {
|
|
@@ -304,15 +277,11 @@ export class DiophantineSolver {
|
|
|
304
277
|
for (const constraint of this.infeasExplanation) explanation.push(constraint);
|
|
305
278
|
return;
|
|
306
279
|
}
|
|
307
|
-
|
|
308
|
-
this.
|
|
309
|
-
this.conflictGcd,
|
|
280
|
+
explanation.pushDependency(
|
|
281
|
+
this.explainFixedInMetaTerm(this.lMatrix.rows[this.conflictRow], this.conflictGcd),
|
|
310
282
|
);
|
|
311
|
-
explanation.pushDependency(dep);
|
|
312
283
|
}
|
|
313
284
|
|
|
314
|
-
// Callbacks of lar_solver.
|
|
315
|
-
|
|
316
285
|
private addTermCallback(term: LarTerm) {
|
|
317
286
|
if (!this.solver.isInt(term.column)) {
|
|
318
287
|
this.hasIgnoredTerms = true;
|
|
@@ -361,8 +330,6 @@ export class DiophantineSolver {
|
|
|
361
330
|
}
|
|
362
331
|
}
|
|
363
332
|
|
|
364
|
-
// elimination_work_estimate: the words that eliminating the column of the retired term from
|
|
365
|
-
// m_l_matrix touches.
|
|
366
333
|
private getEliminationWorkEstimate() {
|
|
367
334
|
const lMatrix = this.lMatrix;
|
|
368
335
|
if (lMatrix.getColumnCount() === 0 || lMatrix.getRowCount() === 0) return 0;
|
|
@@ -370,12 +337,10 @@ export class DiophantineSolver {
|
|
|
370
337
|
if (columnSize <= 1) return 0;
|
|
371
338
|
let words = 0;
|
|
372
339
|
for (const cell of lMatrix.rows[lMatrix.getRowCount() - 1])
|
|
373
|
-
words += 1 + Math.floor(
|
|
340
|
+
words += 1 + Math.floor(getRationalBitsize(cell.coeff) / 32);
|
|
374
341
|
return (columnSize - 1) * words;
|
|
375
342
|
}
|
|
376
343
|
|
|
377
|
-
// reset_state: drops what was derived, and puts the active terms back to be added again in the
|
|
378
|
-
// order of their columns.
|
|
379
344
|
private resetState() {
|
|
380
345
|
for (const term of this.activeTerms) {
|
|
381
346
|
this.deregisterColumnsOfTerm(term);
|
|
@@ -404,7 +369,6 @@ export class DiophantineSolver {
|
|
|
404
369
|
this.solver.settings.stats.dioStateResets++;
|
|
405
370
|
}
|
|
406
371
|
|
|
407
|
-
// shrink_matrices: removes the equation of the retired term, the last one.
|
|
408
372
|
private shrinkMatrices() {
|
|
409
373
|
const lastRow = this.lMatrix.getRowCount() - 1;
|
|
410
374
|
this.eliminateLastTermColumn();
|
|
@@ -422,8 +386,6 @@ export class DiophantineSolver {
|
|
|
422
386
|
this.sumOfFixed.pop();
|
|
423
387
|
}
|
|
424
388
|
|
|
425
|
-
// eliminate_last_term_column: pivots the last column of m_l_matrix into its last row, and marks
|
|
426
|
-
// the rows that change, whose equations are recalculated later.
|
|
427
389
|
private eliminateLastTermColumn() {
|
|
428
390
|
const lMatrix = this.lMatrix;
|
|
429
391
|
const termColumn = lMatrix.getColumnCount() - 1;
|
|
@@ -443,8 +405,6 @@ export class DiophantineSolver {
|
|
|
443
405
|
}
|
|
444
406
|
}
|
|
445
407
|
|
|
446
|
-
// Filling the equations.
|
|
447
|
-
|
|
448
408
|
private init(fVector: number[]) {
|
|
449
409
|
this.infeasExplanation.clear();
|
|
450
410
|
this.lia.term.clear();
|
|
@@ -468,7 +428,6 @@ export class DiophantineSolver {
|
|
|
468
428
|
}
|
|
469
429
|
}
|
|
470
430
|
|
|
471
|
-
// fill_entry: the equation t - j = 0 with the fixed columns in the constant, explained by j.
|
|
472
431
|
private fillEntry(term: LarTerm) {
|
|
473
432
|
const solver = this.solver;
|
|
474
433
|
const row = this.eMatrix.getRowCount();
|
|
@@ -490,7 +449,6 @@ export class DiophantineSolver {
|
|
|
490
449
|
this.subsEntry(row);
|
|
491
450
|
}
|
|
492
451
|
|
|
493
|
-
// subs_entry: substitutes the solved and the freshly defined columns in the equation.
|
|
494
452
|
private subsEntry(row: number) {
|
|
495
453
|
if (row >= this.eMatrix.getRowCount()) return;
|
|
496
454
|
const queue = this.queue;
|
|
@@ -515,14 +473,12 @@ export class DiophantineSolver {
|
|
|
515
473
|
}
|
|
516
474
|
}
|
|
517
475
|
|
|
518
|
-
// add_two_entries: adds an equation times coeff to another.
|
|
519
476
|
private addTwoEntries(coeff: Rational, from: number, to: number) {
|
|
520
477
|
this.eMatrix.addRows(coeff, from, to);
|
|
521
478
|
this.lMatrix.addRows(coeff, from, to);
|
|
522
479
|
this.sumOfFixed[to] = this.sumOfFixed[to].add(coeff.mul(this.sumOfFixed[from]));
|
|
523
480
|
}
|
|
524
481
|
|
|
525
|
-
// recalculate_entry: the equation again from its explanation, scaled to integers.
|
|
526
482
|
private recalculateEntry(row: number) {
|
|
527
483
|
let fixedSum = this.openLTermToEspace(row);
|
|
528
484
|
const eRow = this.eMatrix.rows[row];
|
|
@@ -544,8 +500,6 @@ export class DiophantineSolver {
|
|
|
544
500
|
if (this.rowToKey.has(row)) this.removeFromS(row);
|
|
545
501
|
}
|
|
546
502
|
|
|
547
|
-
// open_l_term_to_espace: the combination of term definitions of the row, over lar_solver
|
|
548
|
-
// columns, with the fixed ones in the returned constant.
|
|
549
503
|
private openLTermToEspace(row: number) {
|
|
550
504
|
const solver = this.solver;
|
|
551
505
|
this.espace.clear();
|
|
@@ -560,8 +514,6 @@ export class DiophantineSolver {
|
|
|
560
514
|
return constant;
|
|
561
515
|
}
|
|
562
516
|
|
|
563
|
-
// process_m_changed_f_columns: recalculates the equations that the columns that became fixed or
|
|
564
|
-
// stopped being fixed, and the changed terms, touch.
|
|
565
517
|
private processChangedFixedColumns(fVector: number[]) {
|
|
566
518
|
for (const column of this.changedFixedColumns.elems.slice()) {
|
|
567
519
|
const terms = this.columnsToTerms.get(column);
|
|
@@ -610,7 +562,6 @@ export class DiophantineSolver {
|
|
|
610
562
|
this.changedTerms.clear();
|
|
611
563
|
}
|
|
612
564
|
|
|
613
|
-
// is_big_term_or_no_term: also marks the terms ignored for their big numbers.
|
|
614
565
|
private isBigTermOrNoTerm(column: number) {
|
|
615
566
|
const solver = this.solver;
|
|
616
567
|
if (column >= solver.getColumnCount() || !solver.hasTerm(column)) return true;
|
|
@@ -624,9 +575,6 @@ export class DiophantineSolver {
|
|
|
624
575
|
return false;
|
|
625
576
|
}
|
|
626
577
|
|
|
627
|
-
// Fresh definitions.
|
|
628
|
-
|
|
629
|
-
// collect_dependent_fresh_vars: the fresh columns whose definitions use a removed one.
|
|
630
578
|
private collectDependentFreshVars(removed: number, toRemove: number[]) {
|
|
631
579
|
const newlyFound: number[] = [];
|
|
632
580
|
for (const entry of this.freshDefinitions.keyToFresh) {
|
|
@@ -640,8 +588,6 @@ export class DiophantineSolver {
|
|
|
640
588
|
for (const fresh of newlyFound) this.collectDependentFreshVars(fresh, toRemove);
|
|
641
589
|
}
|
|
642
590
|
|
|
643
|
-
// deep_remove_fresh_var: removes the fresh column and those that depend on it, and marks the
|
|
644
|
-
// rows that use them.
|
|
645
591
|
private deepRemoveFreshVar(removed: number) {
|
|
646
592
|
if (!this.freshDefinitions.hasFresh(removed)) return;
|
|
647
593
|
const toRemove = [removed];
|
|
@@ -680,8 +626,6 @@ export class DiophantineSolver {
|
|
|
680
626
|
for (const row of rows) this.removeIrrelevantFreshDefsForRow(row);
|
|
681
627
|
}
|
|
682
628
|
|
|
683
|
-
// fresh_var_step: step 7 of the paper. With the smallest coefficient a of k in row h, the fresh
|
|
684
|
-
// column xt = k + sum (a_i div a) x_i replaces k in the equations of F.
|
|
685
629
|
private freshVarStep(row: number, key: number, ahk: Rational) {
|
|
686
630
|
const fresh = this.varRegister.addVar(NO_VAR);
|
|
687
631
|
while (fresh >= this.eMatrix.getColumnCount()) this.eMatrix.addColumn();
|
|
@@ -693,8 +637,7 @@ export class DiophantineSolver {
|
|
|
693
637
|
const quotient = getTruncatedQuotient(cell.coeff, ahk);
|
|
694
638
|
if (!quotient.isZero()) freshTerm.addMonomial(quotient, cell.column);
|
|
695
639
|
}
|
|
696
|
-
//
|
|
697
|
-
// it, so the stored term is reinserted twice in iteration order.
|
|
640
|
+
// Z3 copies the term twice (std::make_pair, then bij_map), reinserting it in iteration order.
|
|
698
641
|
const stored = new LarTerm(new LarTerm(freshTerm.coeffs).coeffs);
|
|
699
642
|
this.freshDefinitions.add(key, fresh, { term: stored, row });
|
|
700
643
|
const defs = this.rowToFreshDefs.get(row);
|
|
@@ -708,8 +651,6 @@ export class DiophantineSolver {
|
|
|
708
651
|
}
|
|
709
652
|
}
|
|
710
653
|
|
|
711
|
-
// Solving F.
|
|
712
|
-
|
|
713
654
|
private processFAndTightenTerms(fVector: number[]): DioMove {
|
|
714
655
|
const move = this.processF(fVector);
|
|
715
656
|
if (move !== "undef") return move;
|
|
@@ -735,8 +676,6 @@ export class DiophantineSolver {
|
|
|
735
676
|
this.solver.settings.stats.dioRewriteConflicts++;
|
|
736
677
|
}
|
|
737
678
|
|
|
738
|
-
// rewrite_eqs: steps 6 and 7 of the paper on the equation of F with the smallest coefficient,
|
|
739
|
-
// and of those the one whose substitution fills the fewest cells.
|
|
740
679
|
private rewriteEqs(fVector: number[]): DioMove {
|
|
741
680
|
if (fVector.length === 0) return "undef";
|
|
742
681
|
let chosenRow = NO_VAR;
|
|
@@ -792,8 +731,6 @@ export class DiophantineSolver {
|
|
|
792
731
|
return "continue";
|
|
793
732
|
}
|
|
794
733
|
|
|
795
|
-
// find_minimal_abs_coeff: the first column with the smallest coefficient, its sign, and the
|
|
796
|
-
// Markowitz number of the pivot.
|
|
797
734
|
private findMinimalAbsCoeff(row: number) {
|
|
798
735
|
let ahk = Rational.zero;
|
|
799
736
|
let column = NO_VAR;
|
|
@@ -811,8 +748,6 @@ export class DiophantineSolver {
|
|
|
811
748
|
return { ahk, column, sign, markovich };
|
|
812
749
|
}
|
|
813
750
|
|
|
814
|
-
// normalize_e_by_gcd: the gcd of the coefficients after dividing the equation by it, or
|
|
815
|
-
// undefined on the conflict of a gcd that does not divide the constant.
|
|
816
751
|
private normalizeEByGcd(row: number) {
|
|
817
752
|
const gcd = getGcdOfCoeffs(this.eMatrix.rows[row], true);
|
|
818
753
|
if (gcd.isZero() || gcd.equals(Rational.one)) return gcd;
|
|
@@ -827,7 +762,6 @@ export class DiophantineSolver {
|
|
|
827
762
|
return gcd;
|
|
828
763
|
}
|
|
829
764
|
|
|
830
|
-
// eliminate_var_in_f: substitutes the column solved by the row in the other equations of F.
|
|
831
765
|
private eliminateVarInF(row: number, key: number, sign: number) {
|
|
832
766
|
const constant = this.sumOfFixed[row];
|
|
833
767
|
const column = this.eMatrix.columns[key];
|
|
@@ -856,10 +790,6 @@ export class DiophantineSolver {
|
|
|
856
790
|
return this.keyToRow.has(column) || this.freshDefinitions.hasKey(column);
|
|
857
791
|
}
|
|
858
792
|
|
|
859
|
-
private isFresh(column: number) {
|
|
860
|
-
return this.freshDefinitions.hasFresh(column);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
793
|
private getCoeffInERow(row: number, column: number) {
|
|
864
794
|
return this.eMatrix.rows[row].find((cell) => cell.column === column)?.coeff ?? Rational.zero;
|
|
865
795
|
}
|
|
@@ -868,13 +798,6 @@ export class DiophantineSolver {
|
|
|
868
798
|
return this.getCoeffInERow(row, column).isPositive() ? 1 : -1;
|
|
869
799
|
}
|
|
870
800
|
|
|
871
|
-
private getRowMonomials(matrix: StaticMatrix, row: number): Monomial[] {
|
|
872
|
-
return matrix.rows[row].map((cell) => ({ coeff: cell.coeff, column: cell.column }));
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
// Tightening the bounds of term columns.
|
|
876
|
-
|
|
877
|
-
// tighten_terms_with_S: the terms whose bounds changed, the most shared first.
|
|
878
801
|
private tightenTermsWithS(): DioMove {
|
|
879
802
|
const solver = this.solver;
|
|
880
803
|
const sortedTerms: number[] = [];
|
|
@@ -925,8 +848,6 @@ export class DiophantineSolver {
|
|
|
925
848
|
return this.tightenOnEspace(column);
|
|
926
849
|
}
|
|
927
850
|
|
|
928
|
-
// init_substitutions: m_espace is the term over local columns with its fixed part in m_c, and
|
|
929
|
-
// m_lspace explains it. False on a big number.
|
|
930
851
|
private initSubstitutions(term: LarTerm, queue: ProtectedQueue) {
|
|
931
852
|
const solver = this.solver;
|
|
932
853
|
const isIgnoringBigNums = solver.settings.isDioIgnoringBigNums;
|
|
@@ -970,8 +891,6 @@ export class DiophantineSolver {
|
|
|
970
891
|
return joinMoves(move, tightened);
|
|
971
892
|
}
|
|
972
893
|
|
|
973
|
-
// find_var_to_substitute_on_espace: the queued column whose substitution adds the fewest new
|
|
974
|
-
// columns, drawn at random among ties, and the queued columns no longer in m_espace dropped.
|
|
975
894
|
private findVarToSubstituteOnEspace(queue: ProtectedQueue) {
|
|
976
895
|
const espace = this.espace;
|
|
977
896
|
let best = NO_VAR;
|
|
@@ -1006,7 +925,6 @@ export class DiophantineSolver {
|
|
|
1006
925
|
return best;
|
|
1007
926
|
}
|
|
1008
927
|
|
|
1009
|
-
// subs_qfront_by_fresh: replaces k by its fresh definition, which leaves m_lspace as it is.
|
|
1010
928
|
private subsByFresh(key: number, queue: ProtectedQueue, column: number) {
|
|
1011
929
|
const term = this.freshDefinitions.getByKey(key).term;
|
|
1012
930
|
const coeff = this.espace.get(key).neg();
|
|
@@ -1019,8 +937,6 @@ export class DiophantineSolver {
|
|
|
1019
937
|
return this.tightenOnEspace(column);
|
|
1020
938
|
}
|
|
1021
939
|
|
|
1022
|
-
// subs_qfront_by_S: replaces k by the equation solved for it, and adds that equation's
|
|
1023
|
-
// explanation to m_lspace.
|
|
1024
940
|
private subsByS(key: number, queue: ProtectedQueue, column: number) {
|
|
1025
941
|
const row = this.keyToRow.get(key) ?? NO_VAR;
|
|
1026
942
|
const constant = this.sumOfFixed[row];
|
|
@@ -1043,7 +959,7 @@ export class DiophantineSolver {
|
|
|
1043
959
|
const fixed: number[] = [];
|
|
1044
960
|
for (const monomial of this.espace.data)
|
|
1045
961
|
if (
|
|
1046
|
-
!this.
|
|
962
|
+
!this.freshDefinitions.hasFresh(monomial.column) &&
|
|
1047
963
|
solver.isFixed(this.varRegister.getExternal(monomial.column))
|
|
1048
964
|
)
|
|
1049
965
|
fixed.push(monomial.column);
|
|
@@ -1054,8 +970,6 @@ export class DiophantineSolver {
|
|
|
1054
970
|
}
|
|
1055
971
|
}
|
|
1056
972
|
|
|
1057
|
-
// tighten_on_espace: with g the gcd of m_espace, the bounds of the term column move to the
|
|
1058
|
-
// nearest values congruent to m_c modulo g, and a constant m_espace is checked against them.
|
|
1059
973
|
private tightenOnEspace(column: number): DioMove {
|
|
1060
974
|
const gcd = getGcdOfCoeffs(this.espace.data, true);
|
|
1061
975
|
if (gcd.equals(Rational.one)) return "undef";
|
|
@@ -1091,7 +1005,6 @@ export class DiophantineSolver {
|
|
|
1091
1005
|
this.infeasExplanation.pushDependency(dep);
|
|
1092
1006
|
}
|
|
1093
1007
|
|
|
1094
|
-
// tighten_bounds_for_non_trivial_gcd: whether tightening the bound found a conflict.
|
|
1095
1008
|
private tightenBoundsForNonTrivialGcd(gcd: Rational, column: number, isUpper: boolean) {
|
|
1096
1009
|
const bound = this.solver.getBound(column, isUpper);
|
|
1097
1010
|
if (bound === undefined) return false;
|
|
@@ -1102,8 +1015,6 @@ export class DiophantineSolver {
|
|
|
1102
1015
|
);
|
|
1103
1016
|
}
|
|
1104
1017
|
|
|
1105
|
-
// tighten_bound_kind: t = g*t' + m_c <= rs gives t <= rs - (rs - m_c) mod g, and a lower bound
|
|
1106
|
-
// likewise. The fixed columns whose coefficients g divides do not explain the new bound.
|
|
1107
1018
|
private tightenBoundKind(
|
|
1108
1019
|
gcd: Rational,
|
|
1109
1020
|
column: number,
|
|
@@ -1128,7 +1039,6 @@ export class DiophantineSolver {
|
|
|
1128
1039
|
return true;
|
|
1129
1040
|
}
|
|
1130
1041
|
|
|
1131
|
-
// open_fixed_from_ml: the fixed columns of a combination of term definitions.
|
|
1132
1042
|
private openFixedFromMl(monomials: Iterable<Monomial>) {
|
|
1133
1043
|
const solver = this.solver;
|
|
1134
1044
|
const result = new TermWithIndex();
|
|
@@ -1143,8 +1053,6 @@ export class DiophantineSolver {
|
|
|
1143
1053
|
return this.explainFixed(this.openFixedFromMl(monomials).data, gcd);
|
|
1144
1054
|
}
|
|
1145
1055
|
|
|
1146
|
-
// explain_fixed: the bounds of the fixed columns, but those whose coefficients a nonzero gcd
|
|
1147
|
-
// divides.
|
|
1148
1056
|
private explainFixed(monomials: Iterable<Monomial>, gcd: Rational) {
|
|
1149
1057
|
let dep: Dependency = null;
|
|
1150
1058
|
for (const monomial of monomials) {
|
|
@@ -1167,7 +1075,6 @@ const popEmptyColumns = (matrix: StaticMatrix) => {
|
|
|
1167
1075
|
matrix.popColumn();
|
|
1168
1076
|
};
|
|
1169
1077
|
|
|
1170
|
-
// Swaps the cell of the pivot row to the head of the column, as the pivots of Z3 do.
|
|
1171
1078
|
const moveCellToFront = (
|
|
1172
1079
|
matrix: StaticMatrix,
|
|
1173
1080
|
column: { row: number; offset: number }[],
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/explanation.h), MIT license, see z3-license.txt.
|
|
2
|
-
// behind a conflict or a propagation: weighted pairs, or a set of constraint indices whose
|
|
3
|
-
// iteration order is the slot order of Z3's hashtable.
|
|
1
|
+
// Ported from Z3 (src/math/lp/explanation.h), MIT license, see z3-license.txt.
|
|
4
2
|
import { getIdentityHash, ObjMap } from "../hashtable";
|
|
5
3
|
import { Rational } from "../rational";
|
|
6
4
|
import { type Dependency, linearize } from "./dependency";
|
|
@@ -22,7 +20,6 @@ export class Explanation {
|
|
|
22
20
|
this.indices.set(constraint, true);
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
// push_explanation: the constraints behind a dependency.
|
|
26
23
|
pushDependency(dep: Dependency) {
|
|
27
24
|
for (const constraint of linearize([dep])) this.push(constraint);
|
|
28
25
|
}
|
|
@@ -31,14 +28,12 @@ export class Explanation {
|
|
|
31
28
|
return this.pairs.length === 0 && this.indices.size === 0;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
// add_expl: the pairs of the other explanation, or its indices when it has no pairs.
|
|
35
31
|
addExplanation(other: Explanation) {
|
|
36
32
|
if (other.pairs.length === 0)
|
|
37
33
|
for (const constraint of other.indices.keys()) this.push(constraint);
|
|
38
34
|
else for (const pair of other.pairs) this.addPair(pair[0], pair[1]);
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
// The constraints, from the pairs when there are any and from the indices otherwise.
|
|
42
37
|
*[Symbol.iterator](): IterableIterator<number> {
|
|
43
38
|
if (this.pairs.length > 0) for (const pair of this.pairs) yield pair[0];
|
|
44
39
|
else yield* this.indices.keys();
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/gomory.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// row of a fractional basic column whose non-basic columns sit at bounds, the inequality that every
|
|
3
|
-
// integer solution meets and the current solution violates.
|
|
1
|
+
// Ported from Z3 (src/math/lp/gomory.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import { Rational } from "../rational";
|
|
5
3
|
import { KIND_GE, KIND_LE } from "./constraints";
|
|
6
4
|
import { LP_CANCELLED } from "./core-solver";
|
|
@@ -16,7 +14,7 @@ const POLARITY_MIXED = 3;
|
|
|
16
14
|
|
|
17
15
|
const HALF = Rational.of(1n, 2n);
|
|
18
16
|
|
|
19
|
-
const getFractionalPart = (value: Rational) => value.sub(value.floor());
|
|
17
|
+
export const getFractionalPart = (value: Rational) => value.sub(value.floor());
|
|
20
18
|
|
|
21
19
|
interface Cut {
|
|
22
20
|
coeffs: [number, Rational][];
|
|
@@ -24,7 +22,6 @@ interface Cut {
|
|
|
24
22
|
dep: Dependency;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
// create_cut: the cut of one row, in the term and the offset of the integer solver.
|
|
28
25
|
class CutBuilder {
|
|
29
26
|
polarity = POLARITY_UNDEF;
|
|
30
27
|
offset = Rational.one;
|
|
@@ -62,8 +59,7 @@ class CutBuilder {
|
|
|
62
59
|
if (Rational.of(newA.num).compare(this.bigNumber) > 0) this.isBigFound = true;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
private addIntCase(column: number, fj: Rational) {
|
|
62
|
+
private intCaseInGomoryCut(column: number, fj: Rational) {
|
|
67
63
|
const solver = this.lia.solver;
|
|
68
64
|
const oneMinusFj = Rational.one.sub(fj);
|
|
69
65
|
if (this.lia.atLower(column)) {
|
|
@@ -80,8 +76,7 @@ class CutBuilder {
|
|
|
80
76
|
this.addMonomial(newA, column);
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
|
|
84
|
-
private addRealCase(a: Rational, column: number) {
|
|
79
|
+
private realCaseInGomoryCut(a: Rational, column: number) {
|
|
85
80
|
const solver = this.lia.solver;
|
|
86
81
|
const isLower = this.lia.atLower(column);
|
|
87
82
|
const isGrowing = a.isPositive() === isLower;
|
|
@@ -114,9 +109,10 @@ class CutBuilder {
|
|
|
114
109
|
this.lia.explanation.pushDependency(solver.getUpperWitness(column));
|
|
115
110
|
continue;
|
|
116
111
|
}
|
|
117
|
-
if (!solver.isInt(column)) this.
|
|
112
|
+
if (!solver.isInt(column)) this.realCaseInGomoryCut(cell.coeff.neg(), column);
|
|
118
113
|
else {
|
|
119
|
-
if (!cell.coeff.isInt())
|
|
114
|
+
if (!cell.coeff.isInt())
|
|
115
|
+
this.intCaseInGomoryCut(column, getFractionalPart(cell.coeff.neg()));
|
|
120
116
|
if (this.polarity !== POLARITY_MIXED) this.setPolarityForInt(cell.coeff, column);
|
|
121
117
|
}
|
|
122
118
|
if (this.isBigFound) return "undef";
|
|
@@ -127,15 +123,12 @@ class CutBuilder {
|
|
|
127
123
|
}
|
|
128
124
|
}
|
|
129
125
|
|
|
130
|
-
// get_gomory_score: the distance of the value of the column to the nearest integer.
|
|
131
126
|
const getGomoryScore = (lia: IntSolver, column: number) => {
|
|
132
127
|
const value = lia.solver.getValue(column).x;
|
|
133
128
|
const fraction = getFractionalPart(value);
|
|
134
129
|
return fraction.compare(HALF) <= 0 ? fraction : Rational.one.sub(fraction);
|
|
135
130
|
};
|
|
136
131
|
|
|
137
|
-
// is_gomory_cut_target: every other column of the row is integral with an integral coefficient,
|
|
138
|
-
// or sits at a bound without an infinitesimal.
|
|
139
132
|
const isGomoryCutTarget = (lia: IntSolver, column: number) => {
|
|
140
133
|
const solver = lia.solver;
|
|
141
134
|
for (const cell of solver.getRow(solver.core.heading[column])) {
|
|
@@ -147,9 +140,7 @@ const isGomoryCutTarget = (lia: IntSolver, column: number) => {
|
|
|
147
140
|
return true;
|
|
148
141
|
};
|
|
149
142
|
|
|
150
|
-
|
|
151
|
-
// toward the values closest to integers.
|
|
152
|
-
const selectColumns = (lia: IntSolver, cutCount: number) => {
|
|
143
|
+
const gomorySelectIntInfeasibleVars = (lia: IntSolver, cutCount: number) => {
|
|
153
144
|
const solver = lia.solver;
|
|
154
145
|
const scores = new Map<number, Rational>();
|
|
155
146
|
const sorted: number[] = [];
|
|
@@ -176,8 +167,6 @@ const selectColumns = (lia: IntSolver, cutCount: number) => {
|
|
|
176
167
|
return selected;
|
|
177
168
|
};
|
|
178
169
|
|
|
179
|
-
// add_deps: the bounds of the integer columns with integral coefficients, which the cut leaves
|
|
180
|
-
// out of its explanation.
|
|
181
170
|
const addDeps = (lia: IntSolver, dep: Dependency, row: RowCell[], basic: number) => {
|
|
182
171
|
const solver = lia.solver;
|
|
183
172
|
let result = dep;
|
|
@@ -193,8 +182,6 @@ const addDeps = (lia: IntSolver, dep: Dependency, row: RowCell[], basic: number)
|
|
|
193
182
|
return result;
|
|
194
183
|
};
|
|
195
184
|
|
|
196
|
-
// get_gomory_cuts: cuts for the selected rows. Cuts with big coefficients stay out unless the
|
|
197
|
-
// small ones alone leave the problem feasible.
|
|
198
185
|
export const getGomoryCuts = (lia: IntSolver, cutCount: number): LiaMove => {
|
|
199
186
|
const solver = lia.solver;
|
|
200
187
|
const bigCuts: Cut[] = [];
|
|
@@ -209,7 +196,7 @@ export const getGomoryCuts = (lia: IntSolver, cutCount: number): LiaMove => {
|
|
|
209
196
|
solver.getInfeasibilityExplanation(lia.explanation);
|
|
210
197
|
return false;
|
|
211
198
|
};
|
|
212
|
-
for (const column of
|
|
199
|
+
for (const column of gomorySelectIntInfeasibleVars(lia, cutCount)) {
|
|
213
200
|
const row = solver.getRow(solver.core.heading[column]);
|
|
214
201
|
const builder = new CutBuilder(lia, column, row);
|
|
215
202
|
const result = builder.cut();
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/hnf_cutter.cpp, and get_equality_and_right_side_for_term_on_current_x
|
|
2
|
-
// in src/math/lp/lar_solver.cpp), MIT license, see z3-license.txt. Cuts from proofs: the integer
|
|
3
|
-
// terms tight at the current solution form A x = b; with A in Hermite normal form H, a row of
|
|
4
|
-
// H^-1 b that is fractional gives a cut that every integer solution meets.
|
|
1
|
+
// Ported from Z3 (src/math/lp/hnf_cutter.cpp, and get_equality_and_right_side_for_term_on_current_x in src/math/lp/lar_solver.cpp), MIT license, see z3-license.txt.
|
|
5
2
|
import { Rational } from "../rational";
|
|
6
3
|
import type { Dependency } from "./dependency";
|
|
7
4
|
import { GeneralMatrix, getDeterminantOfRectangularMatrix, getHermiteNormalForm } from "./hnf";
|
|
@@ -15,8 +12,6 @@ interface TightTerm {
|
|
|
15
12
|
dep: Dependency;
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
// get_equality_and_right_side_for_term_on_current_x: the non-strict bound of an integer term that
|
|
19
|
-
// its current value meets, without infinitesimals.
|
|
20
15
|
const getTightTerm = (lia: IntSolver, term: LarTerm): TightTerm | undefined => {
|
|
21
16
|
const solver = lia.solver;
|
|
22
17
|
const column = term.column;
|
|
@@ -38,7 +33,6 @@ const getTightTerm = (lia: IntSolver, term: LarTerm): TightTerm | undefined => {
|
|
|
38
33
|
return undefined;
|
|
39
34
|
};
|
|
40
35
|
|
|
41
|
-
// find_cut_row_index: a fractional entry, drawn uniformly by reservoir sampling.
|
|
42
36
|
const findCutRowIndex = (lia: IntSolver, values: Rational[]) => {
|
|
43
37
|
let result = -1;
|
|
44
38
|
let count = 0;
|
|
@@ -52,7 +46,6 @@ const findCutRowIndex = (lia: IntSolver, values: Rational[]) => {
|
|
|
52
46
|
return result;
|
|
53
47
|
};
|
|
54
48
|
|
|
55
|
-
// make_hnf_cut: the cut, in the term and the explanation of the integer solver.
|
|
56
49
|
export const makeHnfCut = (lia: IntSolver): LiaMove => {
|
|
57
50
|
const solver = lia.solver;
|
|
58
51
|
const settings = solver.settings;
|
|
@@ -87,31 +80,32 @@ export const makeHnfCut = (lia: IntSolver): LiaMove => {
|
|
|
87
80
|
});
|
|
88
81
|
const basisRows: number[] = [];
|
|
89
82
|
const bigNumber = absMax.mul(absMax).mul(absMax);
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
83
|
+
const determinant = getDeterminantOfRectangularMatrix(matrix, basisRows, bigNumber);
|
|
84
|
+
if (determinant.compare(bigNumber) >= 0 || settings.isCanceled()) return { kind: "undef" };
|
|
92
85
|
const isFullRank = basisRows.length === tightTerms.length;
|
|
93
86
|
matrix.shrinkToRank(basisRows);
|
|
94
87
|
const deps = isFullRank
|
|
95
88
|
? tightTerms.map((tight) => tight.dep)
|
|
96
89
|
: basisRows.map((row) => tightTerms[row].dep);
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
90
|
+
const hermite = getHermiteNormalForm(matrix, determinant, settings.isCanceled);
|
|
91
|
+
if (hermite === undefined) return { kind: "undef" };
|
|
92
|
+
const rightSides = isFullRank
|
|
100
93
|
? tightTerms.map((tight) => tight.rightSide)
|
|
101
94
|
: basisRows.map((row) => tightTerms[row].rightSide);
|
|
102
|
-
for (let
|
|
103
|
-
for (let
|
|
104
|
-
|
|
95
|
+
for (let row = 0; row < hermite.length; row++) {
|
|
96
|
+
for (let column = 0; column < row; column++)
|
|
97
|
+
rightSides[row] = rightSides[row].sub(hermite[row][column].mul(rightSides[column]));
|
|
98
|
+
rightSides[row] = rightSides[row].div(hermite[row][row]);
|
|
105
99
|
}
|
|
106
|
-
const cutRow = findCutRowIndex(lia,
|
|
100
|
+
const cutRow = findCutRowIndex(lia, rightSides);
|
|
107
101
|
if (cutRow === -1) return { kind: "undef" };
|
|
108
|
-
// get_ei_H_minus_1: the row cutRow of the inverse of H.
|
|
109
102
|
const inverseRow = Array.from({ length: matrix.getColumnCount() }, () => Rational.zero);
|
|
110
|
-
inverseRow[cutRow] = Rational.one.div(
|
|
111
|
-
for (let
|
|
103
|
+
inverseRow[cutRow] = Rational.one.div(hermite[cutRow][cutRow]);
|
|
104
|
+
for (let column = cutRow - 1; column >= 0; column--) {
|
|
112
105
|
let sum = Rational.zero;
|
|
113
|
-
for (let
|
|
114
|
-
|
|
106
|
+
for (let row = column + 1; row <= cutRow; row++)
|
|
107
|
+
sum = sum.add(hermite[row][column].mul(inverseRow[row]));
|
|
108
|
+
inverseRow[column] = sum.neg().div(hermite[column][column]);
|
|
115
109
|
}
|
|
116
110
|
for (let column = 0; column < matrix.getColumnCount(); column++) {
|
|
117
111
|
let coeff = Rational.zero;
|
|
@@ -121,5 +115,5 @@ export const makeHnfCut = (lia: IntSolver): LiaMove => {
|
|
|
121
115
|
}
|
|
122
116
|
lia.explanation.clear();
|
|
123
117
|
for (const dep of deps) lia.explanation.pushDependency(dep);
|
|
124
|
-
return { kind: "cut", offset:
|
|
118
|
+
return { kind: "cut", offset: rightSides[cutRow].floor(), isUpper: true };
|
|
125
119
|
};
|