tla-ts 0.0.9 → 0.0.10-dev.28c823e4b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +28 -28
- package/dist/deciders.js +43 -43
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +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 +129 -104
- package/dist/transfer.js +129 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +4 -23
- package/src/bags.ts +99 -102
- package/src/builtins.ts +40 -78
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +599 -388
- package/src/cli/options.ts +11 -6
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +18 -11
- package/src/cli/tlapm.ts +0 -12
- package/src/cli/tlc-arguments.ts +640 -0
- package/src/cli/tlc-usage.ts +361 -0
- package/src/cli/tlc.ts +538 -220
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +4 -16
- package/src/cli.ts +0 -1
- package/src/codegen.ts +191 -64
- package/src/config.ts +140 -109
- package/src/coverage.ts +837 -0
- package/src/dependencies.ts +6 -40
- package/src/dfid.ts +618 -0
- package/src/environment.ts +240 -118
- package/src/errors.ts +70 -55
- package/src/evaluate.ts +596 -339
- 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 +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +255 -139
- package/src/levels.ts +8 -17
- package/src/lexer.ts +80 -100
- package/src/liveness-checker.ts +82 -119
- package/src/liveness.ts +112 -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 +29 -39
- package/src/parallel.ts +53 -44
- package/src/parser.ts +565 -282
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +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 +81 -35
- package/src/resolve.ts +12 -112
- package/src/runtime.ts +22 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generator.ts +149 -252
- package/src/sany/levels.ts +6 -34
- package/src/sany/lexer.ts +41 -61
- package/src/sany/linter.ts +1 -9
- 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 +495 -155
- package/src/simulate.ts +685 -0
- package/src/spec-description.ts +176 -69
- package/src/standard-definitions.ts +0 -4
- package/src/standard-modules.ts +254 -69
- package/src/state-graph.ts +50 -24
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +2 -3
- package/src/successors.ts +263 -94
- package/src/symmetry.ts +33 -25
- package/src/tableau.ts +27 -24
- package/src/tlc/fingerprint.ts +183 -67
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +110 -44
- package/src/tlc/order.ts +37 -60
- package/src/tlc/random.ts +33 -45
- package/src/tlc/replay.ts +549 -217
- package/src/tlc/summary.ts +36 -47
- package/src/tlc/tlc-operators.ts +76 -41
- package/src/tlc/tlcext-operators.ts +139 -122
- package/src/tlc/trace-spec.ts +269 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typescript/actions.ts +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 +780 -337
- package/src/worker.ts +7 -8
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/monic.h, src/math/lp/emonics.h, src/math/lp/emonics.cpp), MIT
|
|
2
|
-
|
|
3
|
-
// variable equivalences, with the cyclic use lists of their variables and the congruence classes
|
|
4
|
-
// of monomials equal up to sign.
|
|
5
|
-
import { getSignedVarVar, isSignedVarNegated, negateSignedVar, VarEqs } from "./nla-var-eqs";
|
|
1
|
+
// Ported from Z3 (src/math/lp/monic.h, src/math/lp/emonics.h, src/math/lp/emonics.cpp), MIT license, see z3-license.txt.
|
|
2
|
+
import { getSignedVarVar, isSignedVarNegated, negateSignedVar, type VarEqs } from "./nla-var-eqs";
|
|
6
3
|
import { TrailStack, UnionFind } from "./union-find";
|
|
7
4
|
|
|
8
5
|
const compareNumbers = (first: number, second: number) => first - second;
|
|
9
6
|
|
|
10
7
|
export class Monic {
|
|
11
8
|
readonly vars: number[];
|
|
12
|
-
// The roots of the variables, sorted, and the parity of their signs.
|
|
13
9
|
rvars: number[] = [];
|
|
14
10
|
rsign = false;
|
|
15
11
|
visited = 0;
|
|
@@ -32,7 +28,6 @@ export class Monic {
|
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
// A cell of a cyclic use list: the index of a monic, and the next cell.
|
|
36
31
|
class Cell {
|
|
37
32
|
next: Cell = this;
|
|
38
33
|
|
|
@@ -53,15 +48,13 @@ export class Emonics {
|
|
|
53
48
|
private var2index: number[] = [];
|
|
54
49
|
private visitedStamp = 0;
|
|
55
50
|
private useLists: HeadTail[] = [];
|
|
56
|
-
// The congruence table: the monics of each rooted variable list, the first its representative.
|
|
57
51
|
private cgTable = new Map<string, number[]>();
|
|
58
52
|
|
|
59
53
|
constructor(private varEqs: VarEqs) {
|
|
60
54
|
varEqs.setMergeHandler(this.varEqsHandler);
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
readonly varEqsHandler = {
|
|
57
|
+
private readonly varEqsHandler = {
|
|
65
58
|
afterMergeEh: (r2: number, r1: number) => {
|
|
66
59
|
if (
|
|
67
60
|
getSignedVarVar(r1) !== getSignedVarVar(r2) &&
|
|
@@ -230,7 +223,6 @@ export class Emonics {
|
|
|
230
223
|
return this.useLists[root].head;
|
|
231
224
|
}
|
|
232
225
|
|
|
233
|
-
// The monics in the use list of a variable's root, around the cycle from its head.
|
|
234
226
|
*getUseList(lpVar: number) {
|
|
235
227
|
const head = this.getHead(lpVar);
|
|
236
228
|
if (head === null) return;
|
|
@@ -246,11 +238,6 @@ export class Emonics {
|
|
|
246
238
|
return table === undefined || table.length === 0 ? undefined : this.get(table[0]);
|
|
247
239
|
}
|
|
248
240
|
|
|
249
|
-
isCanonicalMonic(lpVar: number) {
|
|
250
|
-
const index = this.var2index[lpVar];
|
|
251
|
-
return index >= this.unionFind.numVars || this.unionFind.find(index) === index;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
241
|
private removeCg(lpVar: number) {
|
|
255
242
|
const first = this.useLists[lpVar].head;
|
|
256
243
|
if (first === null) return;
|
|
@@ -328,8 +315,7 @@ export class Emonics {
|
|
|
328
315
|
for (const monic of this.monics) this.doCanonize(monic);
|
|
329
316
|
}
|
|
330
317
|
|
|
331
|
-
|
|
332
|
-
canonizeDivides(divisor: Monic, product: Monic) {
|
|
318
|
+
private canonizeDivides(divisor: Monic, product: Monic) {
|
|
333
319
|
if (divisor.size > product.size) return false;
|
|
334
320
|
let divisorIndex = 0;
|
|
335
321
|
let productIndex = 0;
|
|
@@ -346,8 +332,6 @@ export class Emonics {
|
|
|
346
332
|
}
|
|
347
333
|
}
|
|
348
334
|
|
|
349
|
-
// get_products_of: the monics, other than the given one, that it divides, or every monic using
|
|
350
|
-
// the variable, each once.
|
|
351
335
|
*getProductsOf(factor: Monic | number) {
|
|
352
336
|
this.incVisited();
|
|
353
337
|
const isMonic = factor instanceof Monic;
|
|
@@ -360,7 +344,6 @@ export class Emonics {
|
|
|
360
344
|
}
|
|
361
345
|
}
|
|
362
346
|
|
|
363
|
-
// enum_sign_equiv_monics: the monics equal to this one up to sign, around its class's cycle.
|
|
364
347
|
*getSignEquivMonics(monic: Monic) {
|
|
365
348
|
const start = this.var2index[monic.variable];
|
|
366
349
|
let index = start;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/factorization.h), MIT license, see z3-license.txt.
|
|
2
|
-
// monic is a variable or a monic, with a sign. The core makes the factorizations, see
|
|
3
|
-
// getFactorizations in nla-core.ts.
|
|
1
|
+
// Ported from Z3 (src/math/lp/factorization.h), MIT license, see z3-license.txt.
|
|
4
2
|
import type { Monic } from "./nla-emonics";
|
|
5
3
|
import { signToRat } from "./nla-types";
|
|
6
4
|
|
|
@@ -18,7 +16,6 @@ export const mkFactor = (variable: number, isMon: boolean): Factor => ({
|
|
|
18
16
|
|
|
19
17
|
export const getFactorSign = (factor: Factor) => signToRat(factor.isNegated);
|
|
20
18
|
|
|
21
|
-
// A factorization: the factors of a monic, which is set for the factorization into its variables.
|
|
22
19
|
export interface Factorization {
|
|
23
20
|
readonly factors: Factor[];
|
|
24
21
|
mon: Monic | null;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/nla_grobner.h, src/math/lp/nla_grobner.cpp), MIT license, see
|
|
2
|
-
//
|
|
3
|
-
// equations, which dd::solver saturates, and the equations then yield lemmas: interval conflicts,
|
|
4
|
-
// quotient and residue bounds, failed gcd tests, fixed variables, factorizations, and new linear
|
|
5
|
-
// rows. Z3's nlsat conflict check (is_nla_conflict) is not ported, nor are the statistics.
|
|
1
|
+
// Ported from Z3 (src/math/lp/nla_grobner.h, src/math/lp/nla_grobner.cpp), MIT license, see z3-license.txt.
|
|
2
|
+
// Deviation from Z3: its nlsat conflict check (is_nla_conflict) is not ported.
|
|
6
3
|
import { PddMemoryOutError } from "../../../../errors";
|
|
7
4
|
import { getEuclideanMod, getGcd, getLcm, Rational } from "../rational";
|
|
8
5
|
import { KIND_EQ, KIND_GE, KIND_LE, KIND_LT, KIND_NE } from "./constraints";
|
|
@@ -40,7 +37,6 @@ const ADAPTIVE_MAX = 4 * 16;
|
|
|
40
37
|
const ADAPTIVE_BUMP_AFTER = 2;
|
|
41
38
|
const DELAY_CAP = 1000000;
|
|
42
39
|
|
|
43
|
-
// A dependency that pdd_expr and val_of_fixed_var_with_deps extend, where Z3 passes a reference.
|
|
44
40
|
interface DepRef {
|
|
45
41
|
dep: Dependency;
|
|
46
42
|
}
|
|
@@ -63,11 +59,9 @@ const getRationalLcm = (first: Rational, second: Rational) =>
|
|
|
63
59
|
|
|
64
60
|
const getDenominator = (value: Rational) => Rational.of(value.den);
|
|
65
61
|
|
|
66
|
-
// divides: whether the integer a divides the integer b, where 0 divides only 0.
|
|
67
62
|
const divides = (divisor: Rational, value: Rational) =>
|
|
68
63
|
divisor.isZero() ? value.isZero() : value.num % divisor.num === 0n;
|
|
69
64
|
|
|
70
|
-
// ps_root: the root a of a^2 * M^2, a perfect square with every variable of even multiplicity.
|
|
71
65
|
const getPerfectSquareRoot = (coeff: Rational, vars: number[]) => {
|
|
72
66
|
if (vars.length % 2 === 1) return undefined;
|
|
73
67
|
const root = coeff.root(2);
|
|
@@ -80,8 +74,6 @@ const getPerfectSquareRoot = (coeff: Rational, vars: number[]) => {
|
|
|
80
74
|
return root;
|
|
81
75
|
};
|
|
82
76
|
|
|
83
|
-
// ps_cross: whether (c12, v12) is the cross term -2ab*M1*M2 of the perfect squares a^2*M1^2 and
|
|
84
|
-
// b^2*M2^2.
|
|
85
77
|
const isPerfectSquareCross = (
|
|
86
78
|
first: Rational,
|
|
87
79
|
firstVars: number[],
|
|
@@ -112,12 +104,11 @@ export class Grobner {
|
|
|
112
104
|
private readonly solver: PddSolver;
|
|
113
105
|
private readonly nexCreator = new NexCreator();
|
|
114
106
|
private readonly rows = new IndexedUintSet();
|
|
115
|
-
private quota
|
|
107
|
+
private quota = NLA_PARAMS.grQ;
|
|
116
108
|
private delayBase = 0;
|
|
117
109
|
private delay = 0;
|
|
118
110
|
private growthBoost = ADAPTIVE_UNIT;
|
|
119
111
|
private hitStreak = 0;
|
|
120
|
-
private readonly isAddingAllEqs = false;
|
|
121
112
|
private mon2var = new Map<string, number>();
|
|
122
113
|
|
|
123
114
|
constructor(private core: NlaCore) {
|
|
@@ -125,7 +116,6 @@ export class Grobner {
|
|
|
125
116
|
this.solver = new PddSolver(this.manager, () => core.isCanceled());
|
|
126
117
|
}
|
|
127
118
|
|
|
128
|
-
// operator(): runs the pass, unless the quota of misses delays it.
|
|
129
119
|
run() {
|
|
130
120
|
if (this.core.lra.getColumnCount() > 5000) return;
|
|
131
121
|
if (this.quota === 0) this.quota = NLA_PARAMS.grQ;
|
|
@@ -166,7 +156,6 @@ export class Grobner {
|
|
|
166
156
|
if (this.quota > 0) this.quota--;
|
|
167
157
|
}
|
|
168
158
|
|
|
169
|
-
// Z3 catches every exception here, of which a failed pdd allocation is the one that can occur.
|
|
170
159
|
private catchMemoryOut(propagate: () => boolean) {
|
|
171
160
|
try {
|
|
172
161
|
return propagate();
|
|
@@ -176,8 +165,6 @@ export class Grobner {
|
|
|
176
165
|
}
|
|
177
166
|
}
|
|
178
167
|
|
|
179
|
-
// update_growth_boost: two productive runs in a row raise the boost by half, up to the cap, and a
|
|
180
|
-
// miss takes back a quarter of the excess over the unit.
|
|
181
168
|
private updateGrowthBoost(isProductive: boolean) {
|
|
182
169
|
if (isProductive) {
|
|
183
170
|
if (++this.hitStreak < ADAPTIVE_BUMP_AFTER) return;
|
|
@@ -222,7 +209,6 @@ export class Grobner {
|
|
|
222
209
|
return this.countPropagations((equation) => this.propagateQuotientsOf(equation));
|
|
223
210
|
}
|
|
224
211
|
|
|
225
|
-
// propagate_fixed: k*x = 0 gives x = 0, and x + b = 0 gives x = -b.
|
|
226
212
|
private propagateFixed(equation: Equation) {
|
|
227
213
|
const poly = equation.poly;
|
|
228
214
|
if (poly.isUnary()) {
|
|
@@ -246,7 +232,6 @@ export class Grobner {
|
|
|
246
232
|
return true;
|
|
247
233
|
}
|
|
248
234
|
|
|
249
|
-
// propagate_factorization: x*q = 0 gives x = 0 or q = 0, for a linear q.
|
|
250
235
|
private propagateFactorizationOf(equation: Equation) {
|
|
251
236
|
const factors = equation.poly.varFactors();
|
|
252
237
|
if (factors.vars.length === 0 || !factors.poly.isLinear()) return false;
|
|
@@ -259,8 +244,6 @@ export class Grobner {
|
|
|
259
244
|
return true;
|
|
260
245
|
}
|
|
261
246
|
|
|
262
|
-
// linear_to_term: the linear polynomial times the lcm of its denominators, as a term and an
|
|
263
|
-
// offset.
|
|
264
247
|
private linearToTerm(poly: Pdd): LinearTerm {
|
|
265
248
|
let lcm = Rational.one;
|
|
266
249
|
let current = poly;
|
|
@@ -289,8 +272,6 @@ export class Grobner {
|
|
|
289
272
|
);
|
|
290
273
|
}
|
|
291
274
|
|
|
292
|
-
// propagate_gcd_test: x^k - y = 0 limits y modulo k^2. For each residue r of x modulo k, the
|
|
293
|
-
// gcd of the coefficients of p with k*x + r for x must divide its constant term.
|
|
294
275
|
private propagateGcdTestOf(equation: Equation) {
|
|
295
276
|
let poly = equation.poly;
|
|
296
277
|
if (poly.isLinear() || poly.isVal() || !this.isIntPoly(poly)) return false;
|
|
@@ -330,8 +311,6 @@ export class Grobner {
|
|
|
330
311
|
return false;
|
|
331
312
|
}
|
|
332
313
|
|
|
333
|
-
// propagate_quotients: for x*y + z = 0 over the integers, the residue of a linear variable and
|
|
334
|
-
// bounds that relate a factor to the rest.
|
|
335
314
|
private propagateQuotientsOf(equation: Equation) {
|
|
336
315
|
const poly = equation.poly;
|
|
337
316
|
if (poly.isLinear() || poly.isVal() || !this.isIntPoly(poly)) return false;
|
|
@@ -355,8 +334,6 @@ export class Grobner {
|
|
|
355
334
|
return isLemmaFound;
|
|
356
335
|
}
|
|
357
336
|
|
|
358
|
-
// mod_residue: when every monomial but c_v*v is a multiple of M*c_v and the constant term is
|
|
359
|
-
// K*c_v, then v = -K modulo M, so 0 <= v < M forces v to the residue.
|
|
360
337
|
private propagateModResidue(equation: Equation) {
|
|
361
338
|
const poly = equation.poly;
|
|
362
339
|
for (const linear of poly) {
|
|
@@ -399,14 +376,12 @@ export class Grobner {
|
|
|
399
376
|
return false;
|
|
400
377
|
}
|
|
401
378
|
|
|
402
|
-
// The lemmas of p = v*lc + r for a linear r, by the values of v, lc and r.
|
|
403
379
|
private addQuotientLemma(equation: Equation, variable: number, lc: Pdd, rest: Pdd) {
|
|
404
380
|
const variableValue = this.core.val(variable);
|
|
405
381
|
const restValue = this.getValue(rest);
|
|
406
382
|
const lcValue = this.getValue(lc);
|
|
407
383
|
if (restValue.isZero()) {
|
|
408
384
|
if (variableValue.isZero() || lcValue.isZero() || !lc.isLinear()) return false;
|
|
409
|
-
// v = 0 or lc = 0 or r != 0
|
|
410
385
|
const lcTerm = this.linearToTerm(lc);
|
|
411
386
|
const restTerm = this.linearToTerm(rest);
|
|
412
387
|
this.addDependencies(new LemmaBuilder(this.core), equation)
|
|
@@ -416,7 +391,6 @@ export class Grobner {
|
|
|
416
391
|
return true;
|
|
417
392
|
}
|
|
418
393
|
if (variableValue.isZero()) {
|
|
419
|
-
// v = 0 => r = 0
|
|
420
394
|
const lemma = this.addDependencies(new LemmaBuilder(this.core), equation);
|
|
421
395
|
const restTerm = this.linearToTerm(rest);
|
|
422
396
|
lemma
|
|
@@ -426,7 +400,6 @@ export class Grobner {
|
|
|
426
400
|
}
|
|
427
401
|
if (lcValue.isZero()) {
|
|
428
402
|
if (!lc.isLinear()) return false;
|
|
429
|
-
// lc = 0 => r = 0
|
|
430
403
|
const lemma = this.addDependencies(new LemmaBuilder(this.core), equation);
|
|
431
404
|
const lcTerm = this.linearToTerm(lc);
|
|
432
405
|
const restTerm = this.linearToTerm(rest);
|
|
@@ -439,7 +412,6 @@ export class Grobner {
|
|
|
439
412
|
const isVariablePositive = variableValue.isPositive();
|
|
440
413
|
const isRestPositive = restValue.isPositive();
|
|
441
414
|
if (variableValue.abs().compare(restValue.abs()) > 0) {
|
|
442
|
-
// v*c + t = 0 with |v| > |t| != 0: v changes sign, t changes sign, or |v| <= |t|
|
|
443
415
|
const lemma = new LemmaBuilder(this.core);
|
|
444
416
|
const restTerm = this.linearToTerm(rest);
|
|
445
417
|
this.addDependencies(lemma, equation);
|
|
@@ -460,7 +432,6 @@ export class Grobner {
|
|
|
460
432
|
variableValue.abs().compare(one) > 0 &&
|
|
461
433
|
variableValue.abs().compare(restValue.abs()) >= 0
|
|
462
434
|
) {
|
|
463
|
-
// v*c + t = 0 & |c| > 1, |v| > 1 => |v| < |t|
|
|
464
435
|
const lemma = new LemmaBuilder(this.core);
|
|
465
436
|
const restTerm = this.linearToTerm(rest);
|
|
466
437
|
const lcTerm = this.linearToTerm(lc);
|
|
@@ -497,7 +468,7 @@ export class Grobner {
|
|
|
497
468
|
|
|
498
469
|
private configure() {
|
|
499
470
|
this.solver.reset();
|
|
500
|
-
|
|
471
|
+
const isLoaded = this.catchMemoryOut(() => {
|
|
501
472
|
this.setLevel2var();
|
|
502
473
|
for (const lpVar of this.core.activeVarSet.elems) {
|
|
503
474
|
if (this.core.lra.isBase(lpVar)) {
|
|
@@ -505,10 +476,9 @@ export class Grobner {
|
|
|
505
476
|
}
|
|
506
477
|
if (this.core.isMonicVar(lpVar) && this.core.varIsFixed(lpVar)) this.addFixedMonic(lpVar);
|
|
507
478
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
479
|
+
return true;
|
|
480
|
+
});
|
|
481
|
+
if (!isLoaded) return false;
|
|
512
482
|
const config = getDefaultPddSolverConfig();
|
|
513
483
|
config.maxSteps = this.solver.equations().length;
|
|
514
484
|
config.maxSimplified = NLA_PARAMS.grobnerMaxSimplified;
|
|
@@ -530,7 +500,6 @@ export class Grobner {
|
|
|
530
500
|
return true;
|
|
531
501
|
}
|
|
532
502
|
|
|
533
|
-
// equation_is_true: the equation holds at the values, or a free column can make it hold.
|
|
534
503
|
private isEquationTrue(equation: Equation) {
|
|
535
504
|
if (equation.poly.freeVars().some((variable) => this.core.lra.isFree(variable))) return true;
|
|
536
505
|
return this.getValue(equation.poly).isZero();
|
|
@@ -542,8 +511,6 @@ export class Grobner {
|
|
|
542
511
|
return interval;
|
|
543
512
|
};
|
|
544
513
|
|
|
545
|
-
// is_conflicting: the interval of the polynomial excludes 0, or a cross-nested form or a
|
|
546
|
-
// perfect square shows that it does.
|
|
547
514
|
private isEquationConflicting(equation: Equation) {
|
|
548
515
|
if (this.isEquationTrue(equation)) return false;
|
|
549
516
|
const interval = getPddInterval(equation.poly, "without-deps", this.getVarInterval);
|
|
@@ -563,7 +530,6 @@ export class Grobner {
|
|
|
563
530
|
new LemmaBuilder(this.core).addExplanation(explanation);
|
|
564
531
|
}
|
|
565
532
|
|
|
566
|
-
// monomial_interval: coeff times the product of the variables' intervals.
|
|
567
533
|
private getMonomialInterval(coeff: Rational, vars: number[], mode: DepsMode) {
|
|
568
534
|
const result = mkDepInterval();
|
|
569
535
|
setValue(result, coeff);
|
|
@@ -580,8 +546,6 @@ export class Grobner {
|
|
|
580
546
|
return result;
|
|
581
547
|
}
|
|
582
548
|
|
|
583
|
-
// add_perfect_square_conflict: a triple of monomials a^2*M1^2, b^2*M2^2 and -2ab*M1*M2 is
|
|
584
|
-
// (a*M1 - b*M2)^2, at least 0, which replaces their interval when its lower bound is negative.
|
|
585
549
|
private addPerfectSquareConflict(equation: Equation) {
|
|
586
550
|
const monomials: SortedMonomial[] = [...equation.poly].map((monomial) => ({
|
|
587
551
|
coeff: monomial.coeff,
|
|
@@ -632,7 +596,6 @@ export class Grobner {
|
|
|
632
596
|
}
|
|
633
597
|
}
|
|
634
598
|
if (!isFound) return false;
|
|
635
|
-
// [0, oo) for the perfect squares is an unconditional bound, without a dependency.
|
|
636
599
|
const sum = mkDepInterval();
|
|
637
600
|
sum.isLowerInf = false;
|
|
638
601
|
sum.lower = Rational.zero;
|
|
@@ -658,7 +621,6 @@ export class Grobner {
|
|
|
658
621
|
return this.getMonomialInterval(monomial.coeff, monomial.vars, "without-deps");
|
|
659
622
|
}
|
|
660
623
|
|
|
661
|
-
// add_horner_conflict: the cross-nested forms of the polynomial, whose intervals may exclude 0.
|
|
662
624
|
private addHornerConflict(equation: Equation) {
|
|
663
625
|
const nexCreator = this.nexCreator;
|
|
664
626
|
const freeVars = equation.poly.freeVars();
|
|
@@ -688,8 +650,6 @@ export class Grobner {
|
|
|
688
650
|
return crossNested.done();
|
|
689
651
|
}
|
|
690
652
|
|
|
691
|
-
// propagate_linear_equations: an equation whose monomials all have columns and that the values
|
|
692
|
-
// violate becomes a new row fixed to its constant.
|
|
693
653
|
private propagateLinearEquations() {
|
|
694
654
|
this.mon2var.clear();
|
|
695
655
|
for (const monic of this.core.emons.monics)
|
|
@@ -701,8 +661,7 @@ export class Grobner {
|
|
|
701
661
|
return changed > 0;
|
|
702
662
|
}
|
|
703
663
|
|
|
704
|
-
//
|
|
705
|
-
// the monics.
|
|
664
|
+
// Like Z3, the variables are looked up in the pdd's order among the monics' sorted variables.
|
|
706
665
|
private getMonomialColumn(vars: number[]) {
|
|
707
666
|
return this.mon2var.get(vars.join(","));
|
|
708
667
|
}
|
|
@@ -739,7 +698,6 @@ export class Grobner {
|
|
|
739
698
|
return true;
|
|
740
699
|
}
|
|
741
700
|
|
|
742
|
-
// find_nl_cluster: the variables and rows reachable from the monomials to refine.
|
|
743
701
|
private findNlCluster() {
|
|
744
702
|
this.rows.clear();
|
|
745
703
|
this.core.activeVarSet.clear();
|
|
@@ -749,7 +707,6 @@ export class Grobner {
|
|
|
749
707
|
}
|
|
750
708
|
}
|
|
751
709
|
|
|
752
|
-
// add_var_and_its_factors_to_q_and_collect_new_rows.
|
|
753
710
|
private addVarAndItsFactorsToQueue(lpVar: number, queue: number[]) {
|
|
754
711
|
const core = this.core;
|
|
755
712
|
const lra = core.lra;
|
|
@@ -769,17 +726,12 @@ export class Grobner {
|
|
|
769
726
|
if (this.rows.has(row)) continue;
|
|
770
727
|
this.rows.add(row);
|
|
771
728
|
const basic = lra.core.basis[row];
|
|
772
|
-
// A free column over the reals can be assigned.
|
|
773
729
|
if (lra.isFree(basic) && basic !== lpVar) {
|
|
774
730
|
if (!lra.isInt(basic)) continue;
|
|
775
|
-
|
|
776
|
-
if (
|
|
777
|
-
// A free integer column with integer coefficients can be assigned.
|
|
778
|
-
if (!this.isAddingAllEqs && lra.getRow(row).every((rowCell) => rowCell.coeff.isInt()))
|
|
779
|
-
continue;
|
|
731
|
+
if (!this.hasGcdTest && !this.propagatesQuotients) continue;
|
|
732
|
+
if (lra.getRow(row).every((rowCell) => rowCell.coeff.isInt())) continue;
|
|
780
733
|
}
|
|
781
|
-
if (
|
|
782
|
-
continue;
|
|
734
|
+
if (lra.getRow(row).length > NLA_PARAMS.hornerRowLengthLimit) continue;
|
|
783
735
|
for (const rowCell of lra.getRow(row)) this.addVarAndItsFactorsToQueue(rowCell.column, queue);
|
|
784
736
|
}
|
|
785
737
|
}
|
|
@@ -792,13 +744,11 @@ export class Grobner {
|
|
|
792
744
|
|
|
793
745
|
private getTermPdd(term: LarTerm, ref: DepRef) {
|
|
794
746
|
let result = this.manager.mkVal(Rational.zero);
|
|
795
|
-
for (const entry of term.coeffs) result = result.add(this.
|
|
747
|
+
for (const entry of term.coeffs) result = result.add(this.getPddExpr(entry[1], entry[0], ref));
|
|
796
748
|
return result;
|
|
797
749
|
}
|
|
798
750
|
|
|
799
|
-
|
|
800
|
-
// the products of their variables.
|
|
801
|
-
private getPdd(coeff: Rational, lpVar: number, ref: DepRef) {
|
|
751
|
+
private getPddExpr(coeff: Rational, lpVar: number, ref: DepRef) {
|
|
802
752
|
const core = this.core;
|
|
803
753
|
let result = this.manager.mkVal(coeff);
|
|
804
754
|
const vars = [lpVar];
|
|
@@ -822,8 +772,6 @@ export class Grobner {
|
|
|
822
772
|
return result;
|
|
823
773
|
}
|
|
824
774
|
|
|
825
|
-
// is_solved: p = 0 as v = r, for a linear p where v is the only variable bounded on one side
|
|
826
|
-
// while several are bounded on the other, so that r has no bound on that side.
|
|
827
775
|
private getSolvedForm(poly: Pdd) {
|
|
828
776
|
if (!poly.isLinear()) return null;
|
|
829
777
|
let numLo = 0;
|
|
@@ -862,7 +810,6 @@ export class Grobner {
|
|
|
862
810
|
};
|
|
863
811
|
}
|
|
864
812
|
|
|
865
|
-
// add_eq: adds the equation in solved form when it has one.
|
|
866
813
|
private addEq(poly: Pdd, dep: Dependency) {
|
|
867
814
|
const simplified = this.solver.simplify(poly, dep);
|
|
868
815
|
const solved = this.getSolvedForm(simplified.poly);
|
|
@@ -874,7 +821,7 @@ export class Grobner {
|
|
|
874
821
|
const ref: DepRef = { dep: null };
|
|
875
822
|
let product = this.manager.mkVal(Rational.one);
|
|
876
823
|
for (const factor of this.core.emons.get(lpVar).vars) {
|
|
877
|
-
product = product.mul(this.
|
|
824
|
+
product = product.mul(this.getPddExpr(Rational.one, factor, ref));
|
|
878
825
|
}
|
|
879
826
|
product = product.sub(this.getValOfFixedVarWithDeps(lpVar, ref));
|
|
880
827
|
this.addEq(product, ref.dep);
|
|
@@ -883,11 +830,10 @@ export class Grobner {
|
|
|
883
830
|
private addRow(row: RowCell[]) {
|
|
884
831
|
const ref: DepRef = { dep: null };
|
|
885
832
|
let sum = this.manager.mkVal(Rational.zero);
|
|
886
|
-
for (const cell of row) sum = sum.add(this.
|
|
833
|
+
for (const cell of row) sum = sum.add(this.getPddExpr(cell.coeff, cell.column, ref));
|
|
887
834
|
this.addEq(sum, ref.dep);
|
|
888
835
|
}
|
|
889
836
|
|
|
890
|
-
// set_level2var: the columns by weight, then index, from the lowest level.
|
|
891
837
|
private setLevel2var() {
|
|
892
838
|
const core = this.core;
|
|
893
839
|
const count = core.lra.getColumnCount();
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// Ported from Z3 (src/math/lp/horner.h, src/math/lp/horner.cpp, and nexvar, create_sum_from_row,
|
|
2
|
-
// and add_deps_of_fixed from src/math/lp/nla_common.cpp), MIT license, see z3-license.txt.
|
|
3
|
-
// lemmas: a tableau row is a sum that equals zero. Each cross-nested form of the row that
|
|
4
|
-
// intervals proves nonzero yields a conflict.
|
|
2
|
+
// and add_deps_of_fixed from src/math/lp/nla_common.cpp), MIT license, see z3-license.txt.
|
|
5
3
|
import { Rational } from "../rational";
|
|
6
4
|
import { CrossNested } from "./cross-nested";
|
|
7
5
|
import { type Dependency, mkJoin } from "./dependency";
|
|
@@ -12,7 +10,6 @@ import type { RowCell } from "./static-matrix";
|
|
|
12
10
|
|
|
13
11
|
export class Horner {
|
|
14
12
|
private readonly nexCreator = new NexCreator();
|
|
15
|
-
// The joined bounds of the fixed variables that the row's sum replaced by their values.
|
|
16
13
|
private fixedDep: Dependency = null;
|
|
17
14
|
|
|
18
15
|
constructor(private readonly core: NlaCore) {}
|
|
@@ -38,7 +35,6 @@ export class Horner {
|
|
|
38
35
|
return false;
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
// row_is_interesting: whether two monomials of the row share a variable.
|
|
42
38
|
private rowIsInteresting(row: RowCell[]) {
|
|
43
39
|
if (row.length > NLA_PARAMS.hornerRowLengthLimit) return false;
|
|
44
40
|
const core = this.core;
|
|
@@ -60,7 +56,7 @@ export class Horner {
|
|
|
60
56
|
const core = this.core;
|
|
61
57
|
core.activeVarSet.clear();
|
|
62
58
|
this.fixedDep = null;
|
|
63
|
-
const summands = row.map((cell) => this.
|
|
59
|
+
const summands = row.map((cell) => this.mkNexVar(cell.coeff, cell.column));
|
|
64
60
|
const fixedDep = this.fixedDep;
|
|
65
61
|
this.setActiveVarsWeights();
|
|
66
62
|
const expr = this.nexCreator.simplify(this.nexCreator.mkSum(summands));
|
|
@@ -76,21 +72,17 @@ export class Horner {
|
|
|
76
72
|
return crossNested.done();
|
|
77
73
|
}
|
|
78
74
|
|
|
79
|
-
// set_active_vars_weights: without the weights the comparisons of nex_creator are wrong.
|
|
80
75
|
private setActiveVarsWeights() {
|
|
81
76
|
this.nexCreator.setNumberOfVars(this.core.lra.getColumnCount());
|
|
82
77
|
for (const lpVar of this.core.activeVarSet.elems)
|
|
83
78
|
this.nexCreator.setVarWeight(lpVar, this.core.getVarWeight(lpVar));
|
|
84
79
|
}
|
|
85
80
|
|
|
86
|
-
// add_deps_of_fixed.
|
|
87
81
|
private addDepsOfFixed(lpVar: number) {
|
|
88
82
|
this.fixedDep = mkJoin(this.fixedDep, this.core.lra.getBoundWitnesses(lpVar));
|
|
89
83
|
}
|
|
90
84
|
|
|
91
|
-
|
|
92
|
-
// variables by their values (1) or only those fixed to zero (2).
|
|
93
|
-
private nexvar(coeff: Rational, lpVar: number): Nex {
|
|
85
|
+
private mkNexVar(coeff: Rational, lpVar: number): Nex {
|
|
94
86
|
const core = this.core;
|
|
95
87
|
const creator = this.nexCreator;
|
|
96
88
|
const subsFixed: number = NLA_PARAMS.hornerSubsFixed;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
// Ported from Z3 (src/math/lp/nla_intervals.h, src/math/lp/nla_intervals.cpp), MIT license, see
|
|
2
|
-
// z3-license.txt. Evaluates a nex expression over the bounds of its variables. When the interval
|
|
3
|
-
// excludes zero, the expression cannot vanish, so the bounds behind the interval and the
|
|
4
|
-
// dependencies of the row conflict with the row's equation, and the conflict becomes a lemma.
|
|
1
|
+
// Ported from Z3 (src/math/lp/nla_intervals.h, src/math/lp/nla_intervals.cpp), MIT license, see z3-license.txt.
|
|
5
2
|
import { Rational } from "../rational";
|
|
6
3
|
import {
|
|
7
4
|
type DepInterval,
|
|
@@ -38,7 +35,6 @@ const mkExplanation = (constraints: number[]) => {
|
|
|
38
35
|
export class Intervals {
|
|
39
36
|
constructor(private readonly core: NlaCore) {}
|
|
40
37
|
|
|
41
|
-
// check_nex: whether the expression's interval excludes zero, in which case a lemma explains it.
|
|
42
38
|
checkNex(expr: Nex, initialDeps: Dependency) {
|
|
43
39
|
const report: ReportConflict = (explanation) =>
|
|
44
40
|
new LemmaBuilder(this.core).addExplanation(explanation);
|
|
@@ -74,8 +70,6 @@ export class Intervals {
|
|
|
74
70
|
return hasInf;
|
|
75
71
|
}
|
|
76
72
|
|
|
77
|
-
// expression_to_normalized_term: the sum a*t + b, where t is the linear part divided by the
|
|
78
|
-
// coefficient of its smallest variable, which is a.
|
|
79
73
|
private expressionToNormalizedTerm(sum: NexSum) {
|
|
80
74
|
const pairs: [Rational, number][] = [];
|
|
81
75
|
let constant = Rational.zero;
|
|
@@ -134,8 +128,6 @@ export class Intervals {
|
|
|
134
128
|
if (mode === "with-deps") interval.upperDep = upperDep;
|
|
135
129
|
}
|
|
136
130
|
|
|
137
|
-
// interval_from_term: the interval of a linear sum from the bounds of the term column that
|
|
138
|
-
// equals it, or from an equivalence that fixes it.
|
|
139
131
|
private intervalFromTerm(sum: NexSum, interval: DepInterval, mode: DepsMode) {
|
|
140
132
|
const normalized = this.expressionToNormalizedTerm(sum);
|
|
141
133
|
const explanation = new Explanation();
|
|
@@ -176,12 +168,11 @@ export class Intervals {
|
|
|
176
168
|
return true;
|
|
177
169
|
}
|
|
178
170
|
|
|
179
|
-
// conflict_u_l: whether first's upper bound is below second's lower bound. Like Z3, equal
|
|
180
|
-
// bounds conflict when either upper bound is open.
|
|
181
171
|
private conflictUpperLower(first: DepInterval, second: DepInterval) {
|
|
182
172
|
if (first.isUpperInf || second.isLowerInf) return false;
|
|
183
173
|
const comparison = first.upper.compare(second.lower);
|
|
184
174
|
if (comparison !== 0) return comparison < 0;
|
|
175
|
+
// Like Z3, equal bounds conflict when either upper bound is open.
|
|
185
176
|
return first.isUpperOpen || second.isUpperOpen;
|
|
186
177
|
}
|
|
187
178
|
|
|
@@ -242,7 +233,6 @@ export class Intervals {
|
|
|
242
233
|
set(interval, result, mode);
|
|
243
234
|
}
|
|
244
235
|
|
|
245
|
-
// interval_of_expr: false when a sum met a conflict, which report received.
|
|
246
236
|
private intervalOfExpr(
|
|
247
237
|
expr: Nex,
|
|
248
238
|
exponent: number,
|