tla-ts 0.0.8 → 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 +98 -19
- package/dist/index.d.ts +98 -19
- 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 -106
- package/dist/transfer.js +128 -106
- 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 -69
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +314 -24
- package/src/dfid.ts +618 -0
- package/src/environment.ts +263 -129
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +734 -980
- 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 +150 -70
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +122 -64
- 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 +536 -180
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +167 -49
- 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 +269 -85
- package/src/symmetry.ts +59 -147
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +226 -151
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +56 -82
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +564 -212
- 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 +910 -318
- package/src/worker.ts +7 -8
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
// Ported from Z3 (src/math/lp/monomial_bounds.{h,cpp}, src/util/mpq.h root), MIT license, see
|
|
2
|
-
// z3-license.txt.
|
|
3
|
-
// linearization of monomials with at most one non-fixed factor, and the optimization of the bounds
|
|
4
|
-
// of nonlinear variables over the tableau. The shared-factor and binomial-sign lemmas, off by
|
|
5
|
-
// default (arith.nl.monomial_sandwich, arith.nl.monomial_binomial_sign), are not ported.
|
|
2
|
+
// z3-license.txt.
|
|
6
3
|
import { getLcm, Rational } from "../rational";
|
|
7
4
|
import { type ConstraintKind, KIND_EQ, KIND_GE, KIND_GT, KIND_LE, KIND_LT } from "./constraints";
|
|
8
5
|
import {
|
|
9
|
-
DepInterval,
|
|
6
|
+
type DepInterval,
|
|
10
7
|
div,
|
|
11
8
|
mkDepInterval,
|
|
12
9
|
mul,
|
|
@@ -16,7 +13,7 @@ import {
|
|
|
16
13
|
setValue,
|
|
17
14
|
} from "./dep-intervals";
|
|
18
15
|
import { LP_INFEASIBLE } from "./core-solver";
|
|
19
|
-
import { Dependency, linearize, mkJoin } from "./dependency";
|
|
16
|
+
import { type Dependency, linearize, mkJoin } from "./dependency";
|
|
20
17
|
import { Explanation } from "./explanation";
|
|
21
18
|
import { NULL_LPVAR } from "./lar-solver";
|
|
22
19
|
import { Impq } from "./numeric-pair";
|
|
@@ -40,8 +37,7 @@ interface ImprovedBound {
|
|
|
40
37
|
const getAbs = (value: Impq) =>
|
|
41
38
|
value.x.isNegative() || (value.x.isZero() && value.y.isNegative()) ? value.neg() : value;
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
const roundDown = (value: Impq, divisor: Rational) => {
|
|
40
|
+
const normalizeGain = (value: Impq, divisor: Rational) => {
|
|
45
41
|
if (divisor.equals(Rational.one)) return new Impq(value.floor());
|
|
46
42
|
if (divisor.equals(Rational.minusOne)) return value;
|
|
47
43
|
return new Impq(value.div(divisor).floor().mul(divisor));
|
|
@@ -50,8 +46,6 @@ const roundDown = (value: Impq, divisor: Rational) => {
|
|
|
50
46
|
export class MonomialBounds {
|
|
51
47
|
constructor(private core: NlaCore) {}
|
|
52
48
|
|
|
53
|
-
// generate_lemmas: with the sandwich and binomial-sign lemmas off, the conflict of an infeasible
|
|
54
|
-
// lp solver, once some monic needs refinement.
|
|
55
49
|
generateLemmas() {
|
|
56
50
|
if (this.core.toRefine.size > 0) this.addLemma();
|
|
57
51
|
}
|
|
@@ -87,7 +81,6 @@ export class MonomialBounds {
|
|
|
87
81
|
} else interval.isUpperInf = true;
|
|
88
82
|
}
|
|
89
83
|
|
|
90
|
-
// tighten_lp: the bounds of the factors from the monic's interval, and of the monic from theirs.
|
|
91
84
|
private tightenLp(monic: Monic) {
|
|
92
85
|
const analysis = this.analyzeMonomial(monic);
|
|
93
86
|
const isPropagatingUp = analysis.numFree === 0;
|
|
@@ -145,7 +138,6 @@ export class MonomialBounds {
|
|
|
145
138
|
);
|
|
146
139
|
}
|
|
147
140
|
|
|
148
|
-
// analyze_monomial: the number of free variables of odd degree, and the last of them.
|
|
149
141
|
private analyzeMonomial(monic: Monic) {
|
|
150
142
|
let numFree = 0;
|
|
151
143
|
let freeVar = -1;
|
|
@@ -176,7 +168,6 @@ export class MonomialBounds {
|
|
|
176
168
|
return isPropagated;
|
|
177
169
|
}
|
|
178
170
|
|
|
179
|
-
// add_lemma: a conflict lemma when the lp solver is infeasible.
|
|
180
171
|
private addLemma() {
|
|
181
172
|
const lra = this.core.lra;
|
|
182
173
|
if (lra.status !== LP_INFEASIBLE) return false;
|
|
@@ -195,21 +186,16 @@ export class MonomialBounds {
|
|
|
195
186
|
}
|
|
196
187
|
|
|
197
188
|
private linearize(monic: Monic, nonFixed: number, fixedToZero: number) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
? this.propagateFixed(monic, product)
|
|
205
|
-
: this.propagateNonfixed(monic, product, nonFixed);
|
|
206
|
-
}
|
|
189
|
+
const isPropagated =
|
|
190
|
+
fixedToZero !== -1
|
|
191
|
+
? this.propagateFixedToZero(monic, fixedToZero)
|
|
192
|
+
: nonFixed === -1
|
|
193
|
+
? this.propagateFixed(monic, this.getFixedVarProduct(monic, nonFixed))
|
|
194
|
+
: this.propagateNonfixed(monic, this.getFixedVarProduct(monic, nonFixed), nonFixed);
|
|
207
195
|
if (isPropagated) this.core.stats.nlaPropagateEq++;
|
|
208
196
|
return isPropagated;
|
|
209
197
|
}
|
|
210
198
|
|
|
211
|
-
// propagate_violated_linear_monomials: the defining rows of violated monomials with at most one
|
|
212
|
-
// non-fixed factor, except for small fixed products, which branching enumerates.
|
|
213
199
|
propagateViolatedLinearMonomials() {
|
|
214
200
|
const core = this.core;
|
|
215
201
|
if (!NLA_PARAMS.linearizeViolatedMonomials || !core.lra.isFeasible()) return false;
|
|
@@ -220,7 +206,7 @@ export class MonomialBounds {
|
|
|
220
206
|
if (linear === undefined) continue;
|
|
221
207
|
if (linear.fixedToZero === -1 && linear.nonFixed !== -1) {
|
|
222
208
|
const product = this.getFixedVarProduct(monic, linear.nonFixed);
|
|
223
|
-
if (product.isInt() &&
|
|
209
|
+
if (product.isInt() && getNumeratorBitSize(product) <= 16) continue;
|
|
224
210
|
}
|
|
225
211
|
if (this.linearize(monic, linear.nonFixed, linear.fixedToZero)) isPropagated = true;
|
|
226
212
|
if (core.lra.status === LP_INFEASIBLE) break;
|
|
@@ -261,7 +247,6 @@ export class MonomialBounds {
|
|
|
261
247
|
return true;
|
|
262
248
|
}
|
|
263
249
|
|
|
264
|
-
// propagate_nonfixed: the row m - k * w = 0.
|
|
265
250
|
private propagateNonfixed(monic: Monic, coeff: Rational, nonFixed: number) {
|
|
266
251
|
const core = this.core;
|
|
267
252
|
if (core.val(monic.variable).equals(coeff.mul(core.val(nonFixed)))) return false;
|
|
@@ -298,7 +283,6 @@ export class MonomialBounds {
|
|
|
298
283
|
return dep;
|
|
299
284
|
}
|
|
300
285
|
|
|
301
|
-
// is_linear: the one non-fixed factor, or a factor fixed to zero, unless two are non-fixed.
|
|
302
286
|
private getLinear(monic: Monic) {
|
|
303
287
|
const core = this.core;
|
|
304
288
|
let nonFixed = -1;
|
|
@@ -311,7 +295,6 @@ export class MonomialBounds {
|
|
|
311
295
|
return { nonFixed, fixedToZero: -1 };
|
|
312
296
|
}
|
|
313
297
|
|
|
314
|
-
// fixed_var_product: from the lower bounds, since a value may lie outside its bounds.
|
|
315
298
|
private getFixedVarProduct(monic: Monic, nonFixed: number) {
|
|
316
299
|
let product = Rational.one;
|
|
317
300
|
for (const lpVar of monic.vars)
|
|
@@ -319,7 +302,6 @@ export class MonomialBounds {
|
|
|
319
302
|
return product;
|
|
320
303
|
}
|
|
321
304
|
|
|
322
|
-
// range is an interval that v^p lies in: v's upper bound from it.
|
|
323
305
|
private tightenLpUpperBound(range: DepInterval, lpVar: number, exponent: number) {
|
|
324
306
|
const core = this.core;
|
|
325
307
|
const isImprovingUpper = (candidate: Rational) =>
|
|
@@ -392,7 +374,6 @@ export class MonomialBounds {
|
|
|
392
374
|
return isTightened;
|
|
393
375
|
}
|
|
394
376
|
|
|
395
|
-
// propagate_lp_bound: a bound on v, integral when v is.
|
|
396
377
|
private propagateLpBound(lpVar: number, kind: ConstraintKind, value: Rational, dep: Dependency) {
|
|
397
378
|
const lra = this.core.lra;
|
|
398
379
|
const update = (updateKind: ConstraintKind, bound: Rational) =>
|
|
@@ -419,9 +400,6 @@ export class MonomialBounds {
|
|
|
419
400
|
return isNewBound;
|
|
420
401
|
}
|
|
421
402
|
|
|
422
|
-
// max_min: a bounded-effort primal simplex walk that maximizes or minimizes a column, keeping
|
|
423
|
-
// integer columns integral, as theory_arith::max_min does.
|
|
424
|
-
|
|
425
403
|
private isSafeGain(gain: Gain) {
|
|
426
404
|
return gain.isUnbounded || new Impq(gain.minGain).compare(gain.maxGain) <= 0;
|
|
427
405
|
}
|
|
@@ -462,12 +440,12 @@ export class MonomialBounds {
|
|
|
462
440
|
gain.minGain = gain.minGain.isNegative()
|
|
463
441
|
? coeffDen
|
|
464
442
|
: Rational.of(getLcm(gain.minGain.num, coeffDen.num));
|
|
465
|
-
if (!gain.isUnbounded) gain.maxGain =
|
|
443
|
+
if (!gain.isUnbounded) gain.maxGain = normalizeGain(gain.maxGain, gain.minGain);
|
|
466
444
|
}
|
|
467
445
|
if (isBasicInt && !gain.isUnbounded && !gain.maxGain.isInt())
|
|
468
|
-
gain.maxGain =
|
|
446
|
+
gain.maxGain = normalizeGain(new Impq(gain.maxGain.floor()), gain.minGain);
|
|
469
447
|
if (!isBounded) return false;
|
|
470
|
-
if (isBasicInt) maxIncrease =
|
|
448
|
+
if (isBasicInt) maxIncrease = normalizeGain(new Impq(maxIncrease.floor()), gain.minGain);
|
|
471
449
|
if (gain.isUnbounded) {
|
|
472
450
|
gain.isUnbounded = false;
|
|
473
451
|
gain.maxGain = maxIncrease;
|
|
@@ -588,7 +566,7 @@ export class MonomialBounds {
|
|
|
588
566
|
if (bestEfforts !== 0 || !core.x[target].y.isZero()) return undefined;
|
|
589
567
|
return core.x[target].x;
|
|
590
568
|
}
|
|
591
|
-
const gain
|
|
569
|
+
const gain = best;
|
|
592
570
|
if (gain.minGain.isPositive() && !gain.minGain.equals(Rational.one)) bestEfforts++;
|
|
593
571
|
if (leaving === -1) {
|
|
594
572
|
const hasBlockingBound = isIncreasing
|
|
@@ -616,7 +594,6 @@ export class MonomialBounds {
|
|
|
616
594
|
return undefined;
|
|
617
595
|
}
|
|
618
596
|
|
|
619
|
-
// mm_dep_from_row: the witnesses of the bounds that bound the column through its row.
|
|
620
597
|
private getDepFromRow(target: number, isMaximizing: boolean) {
|
|
621
598
|
const lra = this.core.lra;
|
|
622
599
|
const core = lra.core;
|
|
@@ -656,8 +633,6 @@ export class MonomialBounds {
|
|
|
656
633
|
return { bound, dep };
|
|
657
634
|
}
|
|
658
635
|
|
|
659
|
-
// optimize_nl_bounds: tightens the bounds of the variables of monomials by optimizing each over
|
|
660
|
-
// the tableau, then applies them together and makes the tableau feasible again.
|
|
661
636
|
optimizeNlBounds() {
|
|
662
637
|
const core = this.core;
|
|
663
638
|
const lra = core.lra;
|
|
@@ -709,7 +684,7 @@ export class MonomialBounds {
|
|
|
709
684
|
}
|
|
710
685
|
}
|
|
711
686
|
|
|
712
|
-
const
|
|
687
|
+
const getNumeratorBitSize = (value: Rational) => {
|
|
713
688
|
const magnitude = value.num < 0n ? -value.num : value.num;
|
|
714
689
|
return magnitude === 0n ? 1 : magnitude.toString(2).length;
|
|
715
690
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/nla_monotone_lemmas.h, src/math/lp/nla_monotone_lemmas.cpp), MIT
|
|
2
|
-
// license, see z3-license.txt. The monotonicity lemmas of nla: the absolute value of a monomial is
|
|
3
|
-
// at most, or at least, the product of its factors' absolute values when they are.
|
|
1
|
+
// Ported from Z3 (src/math/lp/nla_monotone_lemmas.h, src/math/lp/nla_monotone_lemmas.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import { Rational } from "../rational";
|
|
5
3
|
import { KIND_GE, KIND_GT, KIND_LE, KIND_LT } from "./constraints";
|
|
6
4
|
import { type NlaCore } from "./nla-core";
|
|
@@ -22,7 +20,7 @@ export class Monotone {
|
|
|
22
20
|
private monotonicityLemmaOnMonic(monic: Monic) {
|
|
23
21
|
const core = this.core;
|
|
24
22
|
if (core.monHasZero(monic.vars) || core.hasBigNum(monic)) return;
|
|
25
|
-
const productValue = core.
|
|
23
|
+
const productValue = core.mulVal(monic).abs();
|
|
26
24
|
const monicValue = core.varVal(monic).abs();
|
|
27
25
|
const isLt = monicValue.compare(productValue) < 0;
|
|
28
26
|
if (core.throttle.insertMonotone(THROTTLE_MONOTONE_LEMMA, monic.variable, isLt)) return;
|
|
@@ -30,7 +28,6 @@ export class Monotone {
|
|
|
30
28
|
else if (monicValue.compare(productValue) > 0) this.monotonicityLemmaGt(monic);
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
// /\_i |m[i]| <= |val(m[i])| => |m| <= |product_i val(m[i])|
|
|
34
31
|
private monotonicityLemmaGt(monic: Monic) {
|
|
35
32
|
const core = this.core;
|
|
36
33
|
const lemma = new LemmaBuilder(core);
|
|
@@ -44,7 +41,6 @@ export class Monotone {
|
|
|
44
41
|
lemma.addIneq(mkIneq(monic.variable, product.isNegative() ? KIND_GE : KIND_LE, product));
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
// /\_i |m[i]| >= |val(m[i])| => |m| >= |product_i val(m[i])|
|
|
48
44
|
private monotonicityLemmaLt(monic: Monic) {
|
|
49
45
|
const core = this.core;
|
|
50
46
|
const lemma = new LemmaBuilder(core);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/nla_order_lemmas.h, src/math/lp/nla_order_lemmas.cpp), MIT
|
|
2
|
-
//
|
|
3
|
-
// binary factorizations of the monomials to refine, and the sign lemmas of binomials.
|
|
1
|
+
// Ported from Z3 (src/math/lp/nla_order_lemmas.h, src/math/lp/nla_order_lemmas.cpp), MIT license,
|
|
2
|
+
// see z3-license.txt.
|
|
4
3
|
import { Rational } from "../rational";
|
|
5
4
|
import { KIND_EQ, KIND_GE, KIND_GT, KIND_LE, KIND_LT, KIND_NE } from "./constraints";
|
|
6
5
|
import { LarTerm } from "./lar-term";
|
|
@@ -34,7 +33,6 @@ export class Order {
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
// Either variable of the binomial plays the role of c.
|
|
38
36
|
private orderLemmaOnBinomial(ac: Monic) {
|
|
39
37
|
const core = this.core;
|
|
40
38
|
const isGt = core.varVal(ac).compare(core.mulVal(ac)) > 0;
|
|
@@ -44,7 +42,6 @@ export class Order {
|
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
// y <= 0 or x < a or xy >= ay, and the like for the sign of val(xy) - val(x) * val(y).
|
|
48
45
|
private orderLemmaOnBinomialSign(xy: Monic, x: number, y: number, sign: number) {
|
|
49
46
|
if (!NLA_PARAMS.orderBinomialSign) return;
|
|
50
47
|
const core = this.core;
|
|
@@ -69,7 +66,6 @@ export class Order {
|
|
|
69
66
|
);
|
|
70
67
|
}
|
|
71
68
|
|
|
72
|
-
// The monics bd with d equivalent to ac[k].
|
|
73
69
|
private orderLemmaOnFactorBinomialExplore(ac: Monic, k: number) {
|
|
74
70
|
const core = this.core;
|
|
75
71
|
for (const bd of core.emons.getProductsOf(ac.vars[k])) {
|
|
@@ -85,7 +81,6 @@ export class Order {
|
|
|
85
81
|
if (b !== undefined) this.orderLemmaOnBinomialAcBd(ac, k, bd, b, d.variable);
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
// ac >= bd && |c| = |d| => ac/|c| >= bd/|d|
|
|
89
84
|
private orderLemmaOnBinomialAcBd(ac: Monic, k: number, bd: Monic, b: Factor, d: number) {
|
|
90
85
|
const core = this.core;
|
|
91
86
|
const a = ac.vars[1 - k];
|
|
@@ -102,7 +97,6 @@ export class Order {
|
|
|
102
97
|
this.generateMonOl(ac, a, cSign, c, bd, b, dSign, d, KIND_GT);
|
|
103
98
|
}
|
|
104
99
|
|
|
105
|
-
// ac > bd => ac/|c| > bd/|d| => a*c_sign > b*d_sign, whose last inequality does not hold.
|
|
106
100
|
private generateMonOl(
|
|
107
101
|
ac: Monic,
|
|
108
102
|
a: number,
|
|
@@ -158,7 +152,6 @@ export class Order {
|
|
|
158
152
|
lemma.explainVar(d);
|
|
159
153
|
}
|
|
160
154
|
|
|
161
|
-
// ac_f[k] plays the role of c.
|
|
162
155
|
private orderLemmaOnAcAndBc(ac: Monic, acFactorization: Factorization, k: number, bd: Monic) {
|
|
163
156
|
const factors = acFactorization.factors;
|
|
164
157
|
const b = this.core.divide(bd, factors[k]);
|
|
@@ -167,7 +160,6 @@ export class Order {
|
|
|
167
160
|
);
|
|
168
161
|
}
|
|
169
162
|
|
|
170
|
-
// m = ab: a monic n = cd with |b| = |d| gives m R n & |b| = |d| => ab/|b| R cd/|d|.
|
|
171
163
|
private orderLemmaOnFactorization(monic: Monic, ab: Factorization) {
|
|
172
164
|
const core = this.core;
|
|
173
165
|
let isNegated = false;
|
|
@@ -227,7 +219,6 @@ export class Order {
|
|
|
227
219
|
this.explainOl(lemma, ac, a, bc, b, c);
|
|
228
220
|
}
|
|
229
221
|
|
|
230
|
-
// c > 0 and ac >= bc => a >= b, and the like for the other signs and relations.
|
|
231
222
|
private generateOl(ac: Monic, a: Factor, c: Factor, bc: Monic, b: Factor) {
|
|
232
223
|
const core = this.core;
|
|
233
224
|
const lemma = new LemmaBuilder(core);
|
|
@@ -263,7 +254,6 @@ export class Order {
|
|
|
263
254
|
lemma.explainFactor(c);
|
|
264
255
|
}
|
|
265
256
|
|
|
266
|
-
// ac = a*c and bc = b*c: ac >= bc implies ac/|c| >= bc/|c|.
|
|
267
257
|
private orderLemmaOnAcAndBcAndFactors(ac: Monic, a: Factor, c: Factor, bc: Monic, b: Factor) {
|
|
268
258
|
const core = this.core;
|
|
269
259
|
const cSign = Rational.fromNumber(getRatSign(core.valFactor(c)));
|
|
@@ -282,7 +272,6 @@ export class Order {
|
|
|
282
272
|
return false;
|
|
283
273
|
}
|
|
284
274
|
|
|
285
|
-
// sign * m = ab: b != val(b) or sign*m <= a*val(b), or >= when not gt.
|
|
286
275
|
private orderLemmaOnAb(
|
|
287
276
|
lemma: LemmaBuilder,
|
|
288
277
|
monic: Monic,
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/nla_patcher.{h,cpp}, src/util/mpz.cpp is_perfect_square), MIT
|
|
2
|
-
// license, see z3-license.txt. Moves the values of monic variables, or of one of their factors, to
|
|
3
|
-
// agree with the products, without breaking monics that are already correct.
|
|
1
|
+
// Ported from Z3 (src/math/lp/nla_patcher.{h,cpp}, src/util/mpz.cpp is_perfect_square), MIT license, see z3-license.txt.
|
|
4
2
|
import { Rational } from "../rational";
|
|
5
3
|
import type { Impq } from "./numeric-pair";
|
|
6
4
|
import type { NlaCore } from "./nla-core";
|
|
7
5
|
import type { Monic } from "./nla-emonics";
|
|
8
6
|
|
|
9
|
-
// in_power: whether the variable at an index occurs next to an equal one.
|
|
10
7
|
const isInPower = (vars: number[], index: number) => {
|
|
11
8
|
const lpVar = vars[index];
|
|
12
9
|
return (
|
|
@@ -42,7 +39,7 @@ export class Patcher {
|
|
|
42
39
|
const core = this.core;
|
|
43
40
|
const update = (monic: Monic) => {
|
|
44
41
|
if (core.varVal(monic).equals(core.mulVal(monic))) core.eraseFromToRefine(monic.variable);
|
|
45
|
-
else core.
|
|
42
|
+
else core.toRefine.add(monic.variable);
|
|
46
43
|
};
|
|
47
44
|
for (const monic of core.emons.getUseList(lpVar)) update(monic);
|
|
48
45
|
if (core.isMonicVar(lpVar)) update(core.emon(lpVar));
|
|
@@ -82,8 +79,8 @@ export class Patcher {
|
|
|
82
79
|
const root = product.root(2);
|
|
83
80
|
if (root === undefined) return;
|
|
84
81
|
this.patchedVar = monic.vars[0];
|
|
85
|
-
if (!this.varBreaksCorrectMonic(this.patchedVar))
|
|
86
|
-
|
|
82
|
+
if (!this.varBreaksCorrectMonic(this.patchedVar) && !this.tryToPatch(root))
|
|
83
|
+
this.tryToPatch(root.neg());
|
|
87
84
|
return;
|
|
88
85
|
}
|
|
89
86
|
if (product.isZero()) return;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// Ported from Z3 (src/math/lp/nla_tangent_lemmas.h, src/math/lp/nla_tangent_lemmas.cpp), MIT
|
|
2
|
-
// license, see z3-license.txt.
|
|
3
|
-
// wrong, the lines through the point of its factors' values and two planes tangent to z = xy that
|
|
4
|
-
// cut the point off.
|
|
2
|
+
// license, see z3-license.txt.
|
|
5
3
|
import { Rational } from "../rational";
|
|
6
4
|
import { KIND_EQ, KIND_GE, KIND_GT, KIND_LE, KIND_LT, KIND_NE } from "./constraints";
|
|
7
5
|
import { LarTerm } from "./lar-term";
|
|
@@ -20,14 +18,11 @@ const mkPoint = (x: Rational, y: Rational): Point => ({ x, y });
|
|
|
20
18
|
|
|
21
19
|
const TWO = Rational.of(2n);
|
|
22
20
|
|
|
23
|
-
// tangent_imp: the lemmas for one monic and its binary factorization.
|
|
24
21
|
class TangentImp {
|
|
25
22
|
private a = mkPoint(Rational.zero, Rational.zero);
|
|
26
23
|
private b = mkPoint(Rational.zero, Rational.zero);
|
|
27
24
|
private readonly correctValue: Rational;
|
|
28
|
-
// Whether the wrong value is below the correct one.
|
|
29
25
|
private readonly isBelow: boolean;
|
|
30
|
-
// Whether the tangent points are strictly inside the bound box.
|
|
31
26
|
private isPlStrictInterior = true;
|
|
32
27
|
private readonly monicVar: number;
|
|
33
28
|
private readonly x: Factor;
|
|
@@ -154,7 +149,6 @@ class TangentImp {
|
|
|
154
149
|
this.explain(lemma);
|
|
155
150
|
}
|
|
156
151
|
|
|
157
|
-
// get_initial_points: two planes tangent to z = xy, at a and at b, that make a cut.
|
|
158
152
|
private getInitialPoints() {
|
|
159
153
|
const x = this.xy.x;
|
|
160
154
|
const y = this.xy.y;
|
|
@@ -170,7 +164,6 @@ class TangentImp {
|
|
|
170
164
|
this.b = mkPoint(x.add(delta), y.add(delta));
|
|
171
165
|
}
|
|
172
166
|
|
|
173
|
-
// push_point: the point moved away from xy, doubling the distance, while the plane still cuts.
|
|
174
167
|
private pushPoint(point: Point) {
|
|
175
168
|
let result = point;
|
|
176
169
|
let difference = mkPoint(point.x.sub(this.xy.x), point.y.sub(this.xy.y));
|
|
@@ -187,7 +180,6 @@ class TangentImp {
|
|
|
187
180
|
return point.x.mul(this.xy.y).add(point.y.mul(this.xy.x)).sub(point.x.mul(point.y));
|
|
188
181
|
}
|
|
189
182
|
|
|
190
|
-
// set_box_corners: McCormick points at the corners of the factors' bound box.
|
|
191
183
|
private setBoxCorners() {
|
|
192
184
|
const core = this.core;
|
|
193
185
|
const xVar = this.xVar;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/nla_throttle.h, src/math/lp/nla_throttle.cpp), MIT license, see
|
|
2
|
-
// z3-license.txt. The signatures of the lemmas nla has generated in the current scope, so that a
|
|
3
|
-
// pass does not generate the same lemma twice.
|
|
1
|
+
// Ported from Z3 (src/math/lp/nla_throttle.h, src/math/lp/nla_throttle.cpp), MIT license, see z3-license.txt.
|
|
4
2
|
import type { Rational } from "../rational";
|
|
5
3
|
import type { LarSolver } from "./lar-solver";
|
|
6
4
|
import type { LpStats } from "./lp-settings";
|
|
@@ -23,8 +21,6 @@ export class NlaThrottle {
|
|
|
23
21
|
private stats: LpStats,
|
|
24
22
|
) {}
|
|
25
23
|
|
|
26
|
-
// insert_new: whether the signature, its 8 values padded with zeros, was seen, recording it when
|
|
27
|
-
// not.
|
|
28
24
|
private insertNew(values: number[]) {
|
|
29
25
|
const key = [...values, ...Array.from({ length: 8 - values.length }, () => 0)].join(",");
|
|
30
26
|
if (this.seen.has(key)) {
|
|
@@ -72,7 +68,6 @@ export class NlaThrottle {
|
|
|
72
68
|
return this.insertNew([kind, monicVar, xVar, yVar, isBelow ? 1 : 0, planeType]);
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
// The simplified tangent signature, without the plane type.
|
|
76
71
|
insertSimplifiedTangent(
|
|
77
72
|
kind: number,
|
|
78
73
|
monicVar: number,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Ported from Z3 (src/math/lp/nla_types.h, src/math/lp/nla_defs.h, src/math/lp/nla_common.h, and
|
|
2
|
-
// lemma_builder of src/math/lp/nla_core.cpp), MIT license, see z3-license.txt.
|
|
3
|
-
// lemmas that the nla passes make, and the builder that adds a lemma to the core.
|
|
2
|
+
// lemma_builder of src/math/lp/nla_core.cpp), MIT license, see z3-license.txt.
|
|
4
3
|
import { Rational } from "../rational";
|
|
5
4
|
import { KIND_EQ, KIND_GE, KIND_GT, KIND_LE, KIND_LT, KIND_NE } from "./constraints";
|
|
6
5
|
import { Explanation } from "./explanation";
|
|
@@ -31,7 +30,6 @@ export const getRatSign = (value: Rational) =>
|
|
|
31
30
|
|
|
32
31
|
export const signToRat = (isNegated: boolean) => (isNegated ? Rational.minusOne : Rational.one);
|
|
33
32
|
|
|
34
|
-
// An ineq: term cmp rs.
|
|
35
33
|
export interface Ineq {
|
|
36
34
|
readonly cmp: number;
|
|
37
35
|
readonly term: LarTerm;
|
|
@@ -44,7 +42,6 @@ export const mkIneq = (term: LarTerm | number, cmp: number, rs: Rational | numbe
|
|
|
44
42
|
rs: typeof rs === "number" ? Rational.fromNumber(rs) : rs,
|
|
45
43
|
});
|
|
46
44
|
|
|
47
|
-
// A lemma: its explanation implies one of its inequalities, or false when it has none.
|
|
48
45
|
export interface Lemma {
|
|
49
46
|
readonly ineqs: Ineq[];
|
|
50
47
|
readonly expl: Explanation;
|
|
@@ -52,7 +49,6 @@ export interface Lemma {
|
|
|
52
49
|
|
|
53
50
|
export const isConflictLemma = (lemma: Lemma) => lemma.ineqs.length === 0 && !lemma.expl.isEmpty;
|
|
54
51
|
|
|
55
|
-
// lemma_builder: adds a lemma to the core and builds it in place.
|
|
56
52
|
export class LemmaBuilder {
|
|
57
53
|
private readonly lemma: Lemma = { ineqs: [], expl: new Explanation() };
|
|
58
54
|
|
|
@@ -60,11 +56,6 @@ export class LemmaBuilder {
|
|
|
60
56
|
core.lemmas.push(this.lemma);
|
|
61
57
|
}
|
|
62
58
|
|
|
63
|
-
get expl() {
|
|
64
|
-
return this.lemma.expl;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// |=: an inequality, unless the bounds already explain its negation away.
|
|
68
59
|
addIneq(ineq: Ineq) {
|
|
69
60
|
if (!this.core.explainIneq(this, ineq.term, ineq.cmp, ineq.rs)) this.lemma.ineqs.push(ineq);
|
|
70
61
|
return this;
|
|
@@ -75,7 +66,6 @@ export class LemmaBuilder {
|
|
|
75
66
|
return this;
|
|
76
67
|
}
|
|
77
68
|
|
|
78
|
-
// &= on a monic: the equivalences of its variables.
|
|
79
69
|
explainMonic(monic: Monic) {
|
|
80
70
|
for (const lpVar of monic.vars) this.explainVar(lpVar);
|
|
81
71
|
return this;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// Ported from Z3 (src/math/lp/var_eqs.h, src/math/lp/nla_defs.h), MIT license, see z3-license.txt.
|
|
2
|
-
|
|
3
|
-
// signed variable is the index 2 * var + sign.
|
|
4
|
-
import { Dependency } from "./dependency";
|
|
2
|
+
import type { Dependency } from "./dependency";
|
|
5
3
|
import type { Explanation } from "./explanation";
|
|
6
|
-
import { TrailStack, UnionFind, UnionFindHandler } from "./union-find";
|
|
4
|
+
import { TrailStack, UnionFind, type UnionFindHandler } from "./union-find";
|
|
7
5
|
import { shrink } from "../array";
|
|
8
6
|
|
|
9
7
|
export const mkSignedVar = (lpVar: number, isNegated: boolean) => lpVar * 2 + (isNegated ? 1 : 0);
|
|
@@ -11,7 +9,6 @@ export const getSignedVarVar = (signedVar: number) => signedVar >> 1;
|
|
|
11
9
|
export const isSignedVarNegated = (signedVar: number) => (signedVar & 1) === 1;
|
|
12
10
|
export const negateSignedVar = (signedVar: number) => signedVar ^ 1;
|
|
13
11
|
|
|
14
|
-
// An eq_justification: its dependencies up to the first null.
|
|
15
12
|
type EqJustification = Dependency[];
|
|
16
13
|
|
|
17
14
|
interface EqEdge {
|
|
@@ -25,7 +22,7 @@ interface VarFrame {
|
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
export class VarEqs {
|
|
28
|
-
readonly trail = new TrailStack();
|
|
25
|
+
private readonly trail = new TrailStack();
|
|
29
26
|
private eqTrail: [number, number][] = [];
|
|
30
27
|
private eqTrailScopes: number[] = [];
|
|
31
28
|
private eqs: EqEdge[][] = [];
|
|
@@ -56,7 +53,7 @@ export class VarEqs {
|
|
|
56
53
|
this.trail.popScope(count);
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
merge(v1: number, v2: number, justification: EqJustification) {
|
|
56
|
+
private merge(v1: number, v2: number, justification: EqJustification) {
|
|
60
57
|
if (v1 === v2 || getSignedVarVar(this.find(v1)) === getSignedVarVar(this.find(v2))) return;
|
|
61
58
|
const maxIndex = Math.max(v1, v2) + 2;
|
|
62
59
|
while (this.eqs.length < maxIndex) this.eqs.push([]);
|
|
@@ -86,11 +83,6 @@ export class VarEqs {
|
|
|
86
83
|
return this.find(mkSignedVar(lpVar, false));
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
isRoot(lpVar: number) {
|
|
90
|
-
return getSignedVarVar(this.findVar(lpVar)) === lpVar;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// explain_bfs: the justifications along a shortest path from v1 to v2.
|
|
94
86
|
explain(v1: number, v2: number, explanation: Explanation) {
|
|
95
87
|
if (v1 === v2) return;
|
|
96
88
|
const todo: VarFrame[] = [{ signedVar: v1, index: 0 }];
|
|
@@ -125,17 +117,4 @@ export class VarEqs {
|
|
|
125
117
|
const signedVar = mkSignedVar(lpVar, false);
|
|
126
118
|
this.explain(this.find(signedVar), signedVar, explanation);
|
|
127
119
|
}
|
|
128
|
-
|
|
129
|
-
// The members of the class of a signed variable, from the variable around the union-find cycle.
|
|
130
|
-
*getClass(signedVar: number) {
|
|
131
|
-
if (signedVar >= this.unionFind.numVars) {
|
|
132
|
-
yield signedVar;
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
let current = signedVar;
|
|
136
|
-
do {
|
|
137
|
-
yield current;
|
|
138
|
-
current = this.unionFind.next(current);
|
|
139
|
-
} while (current !== signedVar);
|
|
140
|
-
}
|
|
141
120
|
}
|