tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0493be549
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 +30 -0
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +80 -10
- package/dist/index.d.ts +80 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +605 -311
- package/src/cli/options.ts +12 -6
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +545 -218
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +632 -298
- package/src/exit-codes.ts +37 -3
- package/src/fingerprints.ts +10 -10
- package/src/index.ts +3 -0
- package/src/instances.ts +79 -11
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/obligations/action.ts +4 -28
- package/src/obligations/anonymize.ts +84 -80
- package/src/obligations/equality.ts +1 -1
- package/src/obligations/expression.ts +2 -19
- package/src/obligations/format.ts +1 -9
- package/src/obligations/generate.ts +1 -11
- package/src/obligations/index.ts +0 -11
- package/src/obligations/levels.ts +4 -8
- package/src/obligations/module.ts +1 -15
- package/src/obligations/normalize.ts +5 -24
- package/src/obligations/operators.ts +1 -2
- package/src/obligations/pragma.ts +1 -10
- package/src/obligations/printer.ts +47 -46
- package/src/obligations/proof.ts +1 -5
- package/src/obligations/regroup.ts +1 -4
- package/src/obligations/simplify.ts +3 -14
- package/src/obligations/source.ts +1 -21
- package/src/obligations/subexpression.ts +5 -11
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +8 -14
- package/src/obligations/tuples.ts +3 -9
- package/src/parallel-worker.ts +31 -38
- package/src/parallel.ts +41 -17
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/decide-pool.ts +5 -10
- package/src/prover/deciders.ts +0 -4
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +0 -6
- package/src/prover/isabelle/encode.ts +11 -23
- package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
- package/src/prover/isabelle/isar/method.ts +25 -38
- package/src/prover/isabelle/isar/proof.ts +1 -10
- package/src/prover/isabelle/isar/statement.ts +1 -6
- package/src/prover/isabelle/isar/theory.ts +15 -26
- package/src/prover/isabelle/isar/type-check.ts +11 -25
- package/src/prover/isabelle/provers/blast/blast.ts +10 -41
- package/src/prover/isabelle/provers/blast/branch.ts +1 -32
- package/src/prover/isabelle/provers/blast/prove.ts +1 -35
- package/src/prover/isabelle/provers/blast/rules.ts +6 -44
- package/src/prover/isabelle/provers/blast/state.ts +2 -28
- package/src/prover/isabelle/provers/blast/term.ts +9 -36
- package/src/prover/isabelle/provers/clasimp.ts +1 -13
- package/src/prover/isabelle/provers/classical.ts +14 -42
- package/src/prover/isabelle/provers/hypsubst.ts +11 -25
- package/src/prover/isabelle/pure/bicompose.ts +16 -13
- package/src/prover/isabelle/pure/consts.ts +1 -7
- package/src/prover/isabelle/pure/conv.ts +1 -9
- package/src/prover/isabelle/pure/drule.ts +24 -40
- package/src/prover/isabelle/pure/envir.ts +3 -52
- package/src/prover/isabelle/pure/goal.ts +1 -7
- package/src/prover/isabelle/pure/interrupt.ts +0 -5
- package/src/prover/isabelle/pure/list.ts +0 -3
- package/src/prover/isabelle/pure/logic.ts +1 -14
- package/src/prover/isabelle/pure/name.ts +2 -9
- package/src/prover/isabelle/pure/net.ts +3 -59
- package/src/prover/isabelle/pure/object-logic.ts +3 -10
- package/src/prover/isabelle/pure/pattern.ts +2 -19
- package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
- package/src/prover/isabelle/pure/rewriter.ts +26 -58
- package/src/prover/isabelle/pure/search.ts +3 -10
- package/src/prover/isabelle/pure/seq.ts +1 -10
- package/src/prover/isabelle/pure/simplifier.ts +4 -12
- package/src/prover/isabelle/pure/table.ts +1 -31
- package/src/prover/isabelle/pure/tactic.ts +12 -22
- package/src/prover/isabelle/pure/tactical.ts +6 -12
- package/src/prover/isabelle/pure/term-ord.ts +2 -6
- package/src/prover/isabelle/pure/term.ts +2 -43
- package/src/prover/isabelle/pure/thm.ts +13 -36
- package/src/prover/isabelle/pure/type.ts +2 -15
- package/src/prover/isabelle/pure/unify.ts +20 -30
- package/src/prover/isabelle/pure/variable.ts +3 -7
- package/src/prover/isabelle/tla/classical-setup.ts +9 -19
- package/src/prover/isabelle/tla/context.ts +8 -16
- package/src/prover/isabelle/tla/logic.ts +4 -11
- package/src/prover/isabelle/tla/simpdata.ts +46 -34
- package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
- package/src/prover/ocaml.ts +0 -6
- package/src/prover/prep/action.ts +4 -36
- package/src/prover/prep/enabled-axioms.ts +12 -19
- package/src/prover/prep/fingerprint.ts +0 -16
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +9 -36
- package/src/prover/prep/normalize.ts +4 -28
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +0 -36
- package/src/prover/ptl/decide.ts +7 -12
- package/src/prover/ptl/encode.ts +14 -36
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +12 -26
- package/src/prover/smt/axioms.ts +0 -7
- package/src/prover/smt/context.ts +19 -26
- package/src/prover/smt/data.ts +51 -54
- package/src/prover/smt/encode.ts +14 -35
- package/src/prover/smt/extensionality.ts +0 -10
- package/src/prover/smt/flatten.ts +3 -22
- package/src/prover/smt/format.ts +5 -10
- package/src/prover/smt/instances.ts +0 -10
- package/src/prover/smt/rewrite.ts +66 -101
- package/src/prover/smt/solver/act-cache.ts +0 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -48
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +1 -43
- package/src/prover/smt/solver/ast-lt.ts +1 -11
- package/src/prover/smt/solver/ast-util.ts +1 -6
- package/src/prover/smt/solver/ast.ts +1 -143
- package/src/prover/smt/solver/auf-solver.ts +6 -39
- package/src/prover/smt/solver/case-split-queue.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +1 -18
- package/src/prover/smt/solver/clause.ts +1 -27
- package/src/prover/smt/solver/conflict-resolution.ts +0 -9
- package/src/prover/smt/solver/context.ts +4 -61
- package/src/prover/smt/solver/ctx-simplify.ts +14 -41
- package/src/prover/smt/solver/der.ts +2 -21
- package/src/prover/smt/solver/dyn-ack.ts +1 -11
- package/src/prover/smt/solver/e-matching.ts +3 -34
- package/src/prover/smt/solver/enode.ts +1 -21
- package/src/prover/smt/solver/expr-ref.ts +1 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
- package/src/prover/smt/solver/fingerprints.ts +1 -12
- package/src/prover/smt/solver/flat-literals.ts +1 -9
- package/src/prover/smt/solver/goal.ts +2 -14
- package/src/prover/smt/solver/hash.ts +0 -8
- package/src/prover/smt/solver/hashtable.ts +1 -12
- package/src/prover/smt/solver/internalizer.ts +6 -98
- package/src/prover/smt/solver/lbool.ts +1 -2
- package/src/prover/smt/solver/literal.ts +0 -3
- package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
- package/src/prover/smt/solver/lp/constraints.ts +2 -8
- package/src/prover/smt/solver/lp/containers.ts +12 -30
- package/src/prover/smt/solver/lp/core-solver.ts +10 -31
- package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
- package/src/prover/smt/solver/lp/dependency.ts +1 -4
- package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
- package/src/prover/smt/solver/lp/explanation.ts +1 -6
- package/src/prover/smt/solver/lp/gomory.ts +9 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
- package/src/prover/smt/solver/lp/hnf.ts +11 -26
- package/src/prover/smt/solver/lp/int-cube.ts +15 -36
- package/src/prover/smt/solver/lp/int-solver.ts +4 -34
- package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
- package/src/prover/smt/solver/lp/lar-term.ts +1 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
- package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
- package/src/prover/smt/solver/lp/nex.ts +1 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
- package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
- package/src/prover/smt/solver/lp/nla-core.ts +35 -130
- package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
- package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
- package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
- package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
- package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
- package/src/prover/smt/solver/lp/nla-order.ts +2 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
- package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
- package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
- package/src/prover/smt/solver/lp/nla-types.ts +1 -11
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
- package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
- package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +1 -8
- package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
- package/src/prover/smt/solver/lp/union-find.ts +1 -6
- package/src/prover/smt/solver/mam-compiler.ts +14 -56
- package/src/prover/smt/solver/mam-interpreter.ts +1 -21
- package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
- package/src/prover/smt/solver/model-checker.ts +2 -36
- package/src/prover/smt/solver/model-evaluator.ts +3 -29
- package/src/prover/smt/solver/model-finder.ts +3 -15
- package/src/prover/smt/solver/model-generator.ts +1 -12
- package/src/prover/smt/solver/model-macro-solver.ts +12 -69
- package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
- package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
- package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
- package/src/prover/smt/solver/nlsat/explain.ts +3 -47
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
- package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
- package/src/prover/smt/solver/nlsat/solver.ts +7 -67
- package/src/prover/smt/solver/nlsat/types.ts +1 -8
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
- package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
- package/src/prover/smt/solver/nnf.ts +3 -38
- package/src/prover/smt/solver/pattern-inference.ts +2 -15
- package/src/prover/smt/solver/poly-rewriter.ts +3 -23
- package/src/prover/smt/solver/propagate-values.ts +1 -10
- package/src/prover/smt/solver/proto-model.ts +3 -48
- package/src/prover/smt/solver/pull-quant.ts +1 -12
- package/src/prover/smt/solver/qe-lite-der.ts +1 -29
- package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
- package/src/prover/smt/solver/qe-lite.ts +3 -33
- package/src/prover/smt/solver/qi-queue.ts +1 -16
- package/src/prover/smt/solver/quant-tactics.ts +5 -22
- package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
- package/src/prover/smt/solver/quantifier-manager.ts +1 -8
- package/src/prover/smt/solver/random-gen.ts +1 -2
- package/src/prover/smt/solver/rational.ts +1 -8
- package/src/prover/smt/solver/ref-vector.ts +1 -6
- package/src/prover/smt/solver/relevancy.ts +2 -15
- package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
- package/src/prover/smt/solver/rewriter.ts +3 -85
- package/src/prover/smt/solver/rlimit.ts +2 -20
- package/src/prover/smt/solver/smtlib-parser.ts +2 -37
- package/src/prover/smt/solver/solver.ts +23 -34
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/sticky-generations.ts +0 -5
- package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
- package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
- package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
- package/src/prover/smt/solver/theory-lra-model.ts +4 -19
- package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
- package/src/prover/smt/solver/theory-lra-state.ts +3 -8
- package/src/prover/smt/solver/theory-lra.ts +1 -8
- package/src/prover/smt/solver/var-subst.ts +2 -26
- package/src/prover/smt/table.ts +0 -8
- package/src/prover/tlapm/cache.ts +20 -25
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +12 -17
- package/src/prover/verdict.ts +0 -2
- package/src/prover/zenon/check/check.ts +0 -9
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +0 -5
- package/src/prover/zenon/check/relations.ts +0 -13
- package/src/prover/zenon/check/rewrites.ts +0 -6
- package/src/prover/zenon/check/sets.ts +0 -3
- package/src/prover/zenon/check/terms.ts +0 -17
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +0 -12
- package/src/prover/zenon/encode.ts +1 -8
- package/src/prover/zenon/eqrel.ts +0 -13
- package/src/prover/zenon/equality-rules.ts +0 -4
- package/src/prover/zenon/expr.ts +1 -26
- package/src/prover/zenon/index-table.ts +17 -38
- package/src/prover/zenon/isar-case.ts +9 -19
- package/src/prover/zenon/isar.ts +1 -29
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +0 -9
- package/src/prover/zenon/mltoll.ts +54 -76
- package/src/prover/zenon/node.ts +1 -11
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +2 -7
- package/src/prover/zenon/phrase.ts +1 -11
- package/src/prover/zenon/proof.ts +0 -9
- package/src/prover/zenon/propositional-rules.ts +0 -5
- package/src/prover/zenon/rules.ts +2 -6
- package/src/prover/zenon/search.ts +1 -17
- package/src/prover/zenon/tla/functions.ts +57 -29
- package/src/prover/zenon/tla/llproof.ts +63 -70
- package/src/prover/zenon/tla/records.ts +56 -27
- package/src/prover/zenon/tla/rewrites.ts +12 -19
- package/src/prover/zenon/tla/sets.ts +68 -39
- package/src/prover/zenon/tla/terms.ts +0 -6
- package/src/prover/zenon/tla/tla.ts +59 -58
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +128 -176
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +31 -29
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +0 -31
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +29 -63
- package/src/sany/selectors.ts +15 -39
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +13 -63
- package/src/search.ts +533 -174
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +481 -0
- package/src/typescript/collections.ts +600 -0
- package/src/typescript/compile.ts +65 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +152 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +163 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +165 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -255
- 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,14 @@ export class DiophantineSolver {
|
|
|
304
277
|
for (const constraint of this.infeasExplanation) explanation.push(constraint);
|
|
305
278
|
return;
|
|
306
279
|
}
|
|
307
|
-
|
|
308
|
-
this.
|
|
309
|
-
|
|
280
|
+
explanation.pushDependency(
|
|
281
|
+
this.explainFixedInMetaTerm(
|
|
282
|
+
this.getRowMonomials(this.lMatrix, this.conflictRow),
|
|
283
|
+
this.conflictGcd,
|
|
284
|
+
),
|
|
310
285
|
);
|
|
311
|
-
explanation.pushDependency(dep);
|
|
312
286
|
}
|
|
313
287
|
|
|
314
|
-
// Callbacks of lar_solver.
|
|
315
|
-
|
|
316
288
|
private addTermCallback(term: LarTerm) {
|
|
317
289
|
if (!this.solver.isInt(term.column)) {
|
|
318
290
|
this.hasIgnoredTerms = true;
|
|
@@ -361,8 +333,6 @@ export class DiophantineSolver {
|
|
|
361
333
|
}
|
|
362
334
|
}
|
|
363
335
|
|
|
364
|
-
// elimination_work_estimate: the words that eliminating the column of the retired term from
|
|
365
|
-
// m_l_matrix touches.
|
|
366
336
|
private getEliminationWorkEstimate() {
|
|
367
337
|
const lMatrix = this.lMatrix;
|
|
368
338
|
if (lMatrix.getColumnCount() === 0 || lMatrix.getRowCount() === 0) return 0;
|
|
@@ -370,12 +340,10 @@ export class DiophantineSolver {
|
|
|
370
340
|
if (columnSize <= 1) return 0;
|
|
371
341
|
let words = 0;
|
|
372
342
|
for (const cell of lMatrix.rows[lMatrix.getRowCount() - 1])
|
|
373
|
-
words += 1 + Math.floor(
|
|
343
|
+
words += 1 + Math.floor(getRationalBitsize(cell.coeff) / 32);
|
|
374
344
|
return (columnSize - 1) * words;
|
|
375
345
|
}
|
|
376
346
|
|
|
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
347
|
private resetState() {
|
|
380
348
|
for (const term of this.activeTerms) {
|
|
381
349
|
this.deregisterColumnsOfTerm(term);
|
|
@@ -404,7 +372,6 @@ export class DiophantineSolver {
|
|
|
404
372
|
this.solver.settings.stats.dioStateResets++;
|
|
405
373
|
}
|
|
406
374
|
|
|
407
|
-
// shrink_matrices: removes the equation of the retired term, the last one.
|
|
408
375
|
private shrinkMatrices() {
|
|
409
376
|
const lastRow = this.lMatrix.getRowCount() - 1;
|
|
410
377
|
this.eliminateLastTermColumn();
|
|
@@ -422,8 +389,6 @@ export class DiophantineSolver {
|
|
|
422
389
|
this.sumOfFixed.pop();
|
|
423
390
|
}
|
|
424
391
|
|
|
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
392
|
private eliminateLastTermColumn() {
|
|
428
393
|
const lMatrix = this.lMatrix;
|
|
429
394
|
const termColumn = lMatrix.getColumnCount() - 1;
|
|
@@ -443,8 +408,6 @@ export class DiophantineSolver {
|
|
|
443
408
|
}
|
|
444
409
|
}
|
|
445
410
|
|
|
446
|
-
// Filling the equations.
|
|
447
|
-
|
|
448
411
|
private init(fVector: number[]) {
|
|
449
412
|
this.infeasExplanation.clear();
|
|
450
413
|
this.lia.term.clear();
|
|
@@ -468,7 +431,6 @@ export class DiophantineSolver {
|
|
|
468
431
|
}
|
|
469
432
|
}
|
|
470
433
|
|
|
471
|
-
// fill_entry: the equation t - j = 0 with the fixed columns in the constant, explained by j.
|
|
472
434
|
private fillEntry(term: LarTerm) {
|
|
473
435
|
const solver = this.solver;
|
|
474
436
|
const row = this.eMatrix.getRowCount();
|
|
@@ -490,7 +452,6 @@ export class DiophantineSolver {
|
|
|
490
452
|
this.subsEntry(row);
|
|
491
453
|
}
|
|
492
454
|
|
|
493
|
-
// subs_entry: substitutes the solved and the freshly defined columns in the equation.
|
|
494
455
|
private subsEntry(row: number) {
|
|
495
456
|
if (row >= this.eMatrix.getRowCount()) return;
|
|
496
457
|
const queue = this.queue;
|
|
@@ -515,14 +476,12 @@ export class DiophantineSolver {
|
|
|
515
476
|
}
|
|
516
477
|
}
|
|
517
478
|
|
|
518
|
-
// add_two_entries: adds an equation times coeff to another.
|
|
519
479
|
private addTwoEntries(coeff: Rational, from: number, to: number) {
|
|
520
480
|
this.eMatrix.addRows(coeff, from, to);
|
|
521
481
|
this.lMatrix.addRows(coeff, from, to);
|
|
522
482
|
this.sumOfFixed[to] = this.sumOfFixed[to].add(coeff.mul(this.sumOfFixed[from]));
|
|
523
483
|
}
|
|
524
484
|
|
|
525
|
-
// recalculate_entry: the equation again from its explanation, scaled to integers.
|
|
526
485
|
private recalculateEntry(row: number) {
|
|
527
486
|
let fixedSum = this.openLTermToEspace(row);
|
|
528
487
|
const eRow = this.eMatrix.rows[row];
|
|
@@ -544,8 +503,6 @@ export class DiophantineSolver {
|
|
|
544
503
|
if (this.rowToKey.has(row)) this.removeFromS(row);
|
|
545
504
|
}
|
|
546
505
|
|
|
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
506
|
private openLTermToEspace(row: number) {
|
|
550
507
|
const solver = this.solver;
|
|
551
508
|
this.espace.clear();
|
|
@@ -560,8 +517,6 @@ export class DiophantineSolver {
|
|
|
560
517
|
return constant;
|
|
561
518
|
}
|
|
562
519
|
|
|
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
520
|
private processChangedFixedColumns(fVector: number[]) {
|
|
566
521
|
for (const column of this.changedFixedColumns.elems.slice()) {
|
|
567
522
|
const terms = this.columnsToTerms.get(column);
|
|
@@ -610,7 +565,6 @@ export class DiophantineSolver {
|
|
|
610
565
|
this.changedTerms.clear();
|
|
611
566
|
}
|
|
612
567
|
|
|
613
|
-
// is_big_term_or_no_term: also marks the terms ignored for their big numbers.
|
|
614
568
|
private isBigTermOrNoTerm(column: number) {
|
|
615
569
|
const solver = this.solver;
|
|
616
570
|
if (column >= solver.getColumnCount() || !solver.hasTerm(column)) return true;
|
|
@@ -624,9 +578,6 @@ export class DiophantineSolver {
|
|
|
624
578
|
return false;
|
|
625
579
|
}
|
|
626
580
|
|
|
627
|
-
// Fresh definitions.
|
|
628
|
-
|
|
629
|
-
// collect_dependent_fresh_vars: the fresh columns whose definitions use a removed one.
|
|
630
581
|
private collectDependentFreshVars(removed: number, toRemove: number[]) {
|
|
631
582
|
const newlyFound: number[] = [];
|
|
632
583
|
for (const entry of this.freshDefinitions.keyToFresh) {
|
|
@@ -640,8 +591,6 @@ export class DiophantineSolver {
|
|
|
640
591
|
for (const fresh of newlyFound) this.collectDependentFreshVars(fresh, toRemove);
|
|
641
592
|
}
|
|
642
593
|
|
|
643
|
-
// deep_remove_fresh_var: removes the fresh column and those that depend on it, and marks the
|
|
644
|
-
// rows that use them.
|
|
645
594
|
private deepRemoveFreshVar(removed: number) {
|
|
646
595
|
if (!this.freshDefinitions.hasFresh(removed)) return;
|
|
647
596
|
const toRemove = [removed];
|
|
@@ -680,8 +629,6 @@ export class DiophantineSolver {
|
|
|
680
629
|
for (const row of rows) this.removeIrrelevantFreshDefsForRow(row);
|
|
681
630
|
}
|
|
682
631
|
|
|
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
632
|
private freshVarStep(row: number, key: number, ahk: Rational) {
|
|
686
633
|
const fresh = this.varRegister.addVar(NO_VAR);
|
|
687
634
|
while (fresh >= this.eMatrix.getColumnCount()) this.eMatrix.addColumn();
|
|
@@ -693,8 +640,7 @@ export class DiophantineSolver {
|
|
|
693
640
|
const quotient = getTruncatedQuotient(cell.coeff, ahk);
|
|
694
641
|
if (!quotient.isZero()) freshTerm.addMonomial(quotient, cell.column);
|
|
695
642
|
}
|
|
696
|
-
//
|
|
697
|
-
// it, so the stored term is reinserted twice in iteration order.
|
|
643
|
+
// Z3 copies the term twice (std::make_pair, then bij_map), reinserting it in iteration order.
|
|
698
644
|
const stored = new LarTerm(new LarTerm(freshTerm.coeffs).coeffs);
|
|
699
645
|
this.freshDefinitions.add(key, fresh, { term: stored, row });
|
|
700
646
|
const defs = this.rowToFreshDefs.get(row);
|
|
@@ -708,8 +654,6 @@ export class DiophantineSolver {
|
|
|
708
654
|
}
|
|
709
655
|
}
|
|
710
656
|
|
|
711
|
-
// Solving F.
|
|
712
|
-
|
|
713
657
|
private processFAndTightenTerms(fVector: number[]): DioMove {
|
|
714
658
|
const move = this.processF(fVector);
|
|
715
659
|
if (move !== "undef") return move;
|
|
@@ -735,8 +679,6 @@ export class DiophantineSolver {
|
|
|
735
679
|
this.solver.settings.stats.dioRewriteConflicts++;
|
|
736
680
|
}
|
|
737
681
|
|
|
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
682
|
private rewriteEqs(fVector: number[]): DioMove {
|
|
741
683
|
if (fVector.length === 0) return "undef";
|
|
742
684
|
let chosenRow = NO_VAR;
|
|
@@ -792,8 +734,6 @@ export class DiophantineSolver {
|
|
|
792
734
|
return "continue";
|
|
793
735
|
}
|
|
794
736
|
|
|
795
|
-
// find_minimal_abs_coeff: the first column with the smallest coefficient, its sign, and the
|
|
796
|
-
// Markowitz number of the pivot.
|
|
797
737
|
private findMinimalAbsCoeff(row: number) {
|
|
798
738
|
let ahk = Rational.zero;
|
|
799
739
|
let column = NO_VAR;
|
|
@@ -811,8 +751,6 @@ export class DiophantineSolver {
|
|
|
811
751
|
return { ahk, column, sign, markovich };
|
|
812
752
|
}
|
|
813
753
|
|
|
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
754
|
private normalizeEByGcd(row: number) {
|
|
817
755
|
const gcd = getGcdOfCoeffs(this.eMatrix.rows[row], true);
|
|
818
756
|
if (gcd.isZero() || gcd.equals(Rational.one)) return gcd;
|
|
@@ -827,7 +765,6 @@ export class DiophantineSolver {
|
|
|
827
765
|
return gcd;
|
|
828
766
|
}
|
|
829
767
|
|
|
830
|
-
// eliminate_var_in_f: substitutes the column solved by the row in the other equations of F.
|
|
831
768
|
private eliminateVarInF(row: number, key: number, sign: number) {
|
|
832
769
|
const constant = this.sumOfFixed[row];
|
|
833
770
|
const column = this.eMatrix.columns[key];
|
|
@@ -856,10 +793,6 @@ export class DiophantineSolver {
|
|
|
856
793
|
return this.keyToRow.has(column) || this.freshDefinitions.hasKey(column);
|
|
857
794
|
}
|
|
858
795
|
|
|
859
|
-
private isFresh(column: number) {
|
|
860
|
-
return this.freshDefinitions.hasFresh(column);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
796
|
private getCoeffInERow(row: number, column: number) {
|
|
864
797
|
return this.eMatrix.rows[row].find((cell) => cell.column === column)?.coeff ?? Rational.zero;
|
|
865
798
|
}
|
|
@@ -872,9 +805,6 @@ export class DiophantineSolver {
|
|
|
872
805
|
return matrix.rows[row].map((cell) => ({ coeff: cell.coeff, column: cell.column }));
|
|
873
806
|
}
|
|
874
807
|
|
|
875
|
-
// Tightening the bounds of term columns.
|
|
876
|
-
|
|
877
|
-
// tighten_terms_with_S: the terms whose bounds changed, the most shared first.
|
|
878
808
|
private tightenTermsWithS(): DioMove {
|
|
879
809
|
const solver = this.solver;
|
|
880
810
|
const sortedTerms: number[] = [];
|
|
@@ -925,8 +855,6 @@ export class DiophantineSolver {
|
|
|
925
855
|
return this.tightenOnEspace(column);
|
|
926
856
|
}
|
|
927
857
|
|
|
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
858
|
private initSubstitutions(term: LarTerm, queue: ProtectedQueue) {
|
|
931
859
|
const solver = this.solver;
|
|
932
860
|
const isIgnoringBigNums = solver.settings.isDioIgnoringBigNums;
|
|
@@ -970,8 +898,6 @@ export class DiophantineSolver {
|
|
|
970
898
|
return joinMoves(move, tightened);
|
|
971
899
|
}
|
|
972
900
|
|
|
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
901
|
private findVarToSubstituteOnEspace(queue: ProtectedQueue) {
|
|
976
902
|
const espace = this.espace;
|
|
977
903
|
let best = NO_VAR;
|
|
@@ -1006,7 +932,6 @@ export class DiophantineSolver {
|
|
|
1006
932
|
return best;
|
|
1007
933
|
}
|
|
1008
934
|
|
|
1009
|
-
// subs_qfront_by_fresh: replaces k by its fresh definition, which leaves m_lspace as it is.
|
|
1010
935
|
private subsByFresh(key: number, queue: ProtectedQueue, column: number) {
|
|
1011
936
|
const term = this.freshDefinitions.getByKey(key).term;
|
|
1012
937
|
const coeff = this.espace.get(key).neg();
|
|
@@ -1019,8 +944,6 @@ export class DiophantineSolver {
|
|
|
1019
944
|
return this.tightenOnEspace(column);
|
|
1020
945
|
}
|
|
1021
946
|
|
|
1022
|
-
// subs_qfront_by_S: replaces k by the equation solved for it, and adds that equation's
|
|
1023
|
-
// explanation to m_lspace.
|
|
1024
947
|
private subsByS(key: number, queue: ProtectedQueue, column: number) {
|
|
1025
948
|
const row = this.keyToRow.get(key) ?? NO_VAR;
|
|
1026
949
|
const constant = this.sumOfFixed[row];
|
|
@@ -1043,7 +966,7 @@ export class DiophantineSolver {
|
|
|
1043
966
|
const fixed: number[] = [];
|
|
1044
967
|
for (const monomial of this.espace.data)
|
|
1045
968
|
if (
|
|
1046
|
-
!this.
|
|
969
|
+
!this.freshDefinitions.hasFresh(monomial.column) &&
|
|
1047
970
|
solver.isFixed(this.varRegister.getExternal(monomial.column))
|
|
1048
971
|
)
|
|
1049
972
|
fixed.push(monomial.column);
|
|
@@ -1054,8 +977,6 @@ export class DiophantineSolver {
|
|
|
1054
977
|
}
|
|
1055
978
|
}
|
|
1056
979
|
|
|
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
980
|
private tightenOnEspace(column: number): DioMove {
|
|
1060
981
|
const gcd = getGcdOfCoeffs(this.espace.data, true);
|
|
1061
982
|
if (gcd.equals(Rational.one)) return "undef";
|
|
@@ -1091,7 +1012,6 @@ export class DiophantineSolver {
|
|
|
1091
1012
|
this.infeasExplanation.pushDependency(dep);
|
|
1092
1013
|
}
|
|
1093
1014
|
|
|
1094
|
-
// tighten_bounds_for_non_trivial_gcd: whether tightening the bound found a conflict.
|
|
1095
1015
|
private tightenBoundsForNonTrivialGcd(gcd: Rational, column: number, isUpper: boolean) {
|
|
1096
1016
|
const bound = this.solver.getBound(column, isUpper);
|
|
1097
1017
|
if (bound === undefined) return false;
|
|
@@ -1102,8 +1022,6 @@ export class DiophantineSolver {
|
|
|
1102
1022
|
);
|
|
1103
1023
|
}
|
|
1104
1024
|
|
|
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
1025
|
private tightenBoundKind(
|
|
1108
1026
|
gcd: Rational,
|
|
1109
1027
|
column: number,
|
|
@@ -1128,7 +1046,6 @@ export class DiophantineSolver {
|
|
|
1128
1046
|
return true;
|
|
1129
1047
|
}
|
|
1130
1048
|
|
|
1131
|
-
// open_fixed_from_ml: the fixed columns of a combination of term definitions.
|
|
1132
1049
|
private openFixedFromMl(monomials: Iterable<Monomial>) {
|
|
1133
1050
|
const solver = this.solver;
|
|
1134
1051
|
const result = new TermWithIndex();
|
|
@@ -1143,8 +1060,6 @@ export class DiophantineSolver {
|
|
|
1143
1060
|
return this.explainFixed(this.openFixedFromMl(monomials).data, gcd);
|
|
1144
1061
|
}
|
|
1145
1062
|
|
|
1146
|
-
// explain_fixed: the bounds of the fixed columns, but those whose coefficients a nonzero gcd
|
|
1147
|
-
// divides.
|
|
1148
1063
|
private explainFixed(monomials: Iterable<Monomial>, gcd: Rational) {
|
|
1149
1064
|
let dep: Dependency = null;
|
|
1150
1065
|
for (const monomial of monomials) {
|
|
@@ -1167,7 +1082,6 @@ const popEmptyColumns = (matrix: StaticMatrix) => {
|
|
|
1167
1082
|
matrix.popColumn();
|
|
1168
1083
|
};
|
|
1169
1084
|
|
|
1170
|
-
// Swaps the cell of the pivot row to the head of the column, as the pivots of Z3 do.
|
|
1171
1085
|
const moveCellToFront = (
|
|
1172
1086
|
matrix: StaticMatrix,
|
|
1173
1087
|
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
|
};
|