tla-ts 0.0.9 → 0.0.10-dev.09e53c2a6
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 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +41 -37
- package/dist/deciders.js +57 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +109 -10
- package/dist/index.d.ts +109 -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 +2746 -410
- package/dist/prove.js +2745 -409
- package/dist/run.cjs +146 -31
- package/dist/run.js +146 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +132 -104
- package/dist/transfer.js +132 -104
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +3 -1
- package/src/ast.ts +45 -59
- package/src/bags.ts +99 -102
- package/src/builtins.ts +28 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +797 -782
- package/src/cli/options.ts +12 -32
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +136 -0
- package/src/cli/shared.ts +19 -12
- package/src/cli/tlapm.ts +433 -82
- package/src/cli/tlc-arguments.ts +652 -0
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +360 -0
- package/src/cli/tlc.ts +323 -658
- package/src/cli/typescript.ts +23 -0
- package/src/cli/xml-exporter.ts +27 -49
- package/src/cli.ts +0 -1
- package/src/codegen.ts +196 -74
- package/src/config.ts +140 -109
- package/src/coverage.ts +830 -0
- package/src/dependencies.ts +36 -54
- package/src/dfid.ts +618 -0
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +178 -339
- package/src/errors.ts +100 -57
- package/src/evaluate.ts +598 -340
- package/src/exit-codes.ts +38 -3
- package/src/fingerprints.ts +75 -11
- package/src/index.ts +3 -0
- package/src/instances.ts +126 -21
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -19
- package/src/json-reader.ts +455 -0
- package/src/json.ts +252 -139
- package/src/levels.ts +46 -58
- package/src/lexer.ts +83 -101
- package/src/liveness-checker.ts +590 -311
- package/src/liveness.ts +180 -124
- package/src/obligations/action.ts +17 -44
- package/src/obligations/anonymize.ts +120 -95
- package/src/obligations/enabled-axioms.ts +218 -0
- package/src/obligations/equality.ts +1 -3
- package/src/obligations/expression.ts +37 -26
- package/src/obligations/format.ts +0 -10
- package/src/obligations/generate.ts +66 -64
- package/src/obligations/index.ts +38 -19
- package/src/obligations/levels.ts +27 -18
- package/src/obligations/module.ts +28 -55
- package/src/obligations/normalize.ts +30 -37
- package/src/obligations/operators.ts +0 -3
- package/src/obligations/pragma.ts +52 -24
- package/src/obligations/printer.ts +89 -58
- package/src/obligations/proof.ts +3 -6
- package/src/obligations/regroup.ts +0 -5
- package/src/obligations/simplify.ts +57 -63
- package/src/obligations/source.ts +119 -95
- package/src/obligations/subexpression.ts +49 -28
- package/src/obligations/substitution.ts +1 -5
- package/src/obligations/temporal.ts +12 -20
- package/src/obligations/tuples.ts +2 -10
- package/src/parallel-worker.ts +30 -60
- package/src/parallel.ts +59 -73
- package/src/parser.ts +1082 -399
- package/src/pcal/ast.ts +53 -86
- package/src/pcal/parse.ts +144 -219
- package/src/pcal/tokenize.ts +91 -131
- package/src/pcal/translate.ts +83 -130
- package/src/pcal/validate.ts +48 -68
- package/src/pretty-print.ts +7 -8
- package/src/prover/decide-pool.ts +8 -13
- package/src/prover/deciders.ts +12 -13
- package/src/prover/first-order.ts +0 -11
- package/src/prover/isabelle/decide.ts +3 -31
- package/src/prover/isabelle/encode.ts +82 -64
- package/src/prover/isabelle/isar/attrib.ts +250 -0
- package/src/prover/isabelle/isar/context.ts +335 -0
- package/src/prover/isabelle/isar/induct.ts +382 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +262 -117
- package/src/prover/isabelle/isar/method.ts +510 -226
- package/src/prover/isabelle/isar/proof.ts +570 -23
- package/src/prover/isabelle/isar/rule-cases.ts +224 -0
- package/src/prover/isabelle/isar/theory.ts +488 -88
- package/src/prover/isabelle/isar/toplevel.ts +331 -0
- package/src/prover/isabelle/isar/type-check.ts +99 -38
- package/src/prover/isabelle/provers/blast/blast.ts +16 -105
- package/src/prover/isabelle/provers/blast/branch.ts +0 -33
- package/src/prover/isabelle/provers/blast/prove.ts +0 -36
- package/src/prover/isabelle/provers/blast/rules.ts +5 -45
- package/src/prover/isabelle/provers/blast/state.ts +1 -29
- package/src/prover/isabelle/provers/blast/term.ts +8 -37
- package/src/prover/isabelle/provers/clasimp.ts +0 -14
- package/src/prover/isabelle/provers/classical.ts +58 -61
- package/src/prover/isabelle/provers/hypsubst.ts +27 -52
- package/src/prover/isabelle/pure/bicompose.ts +24 -39
- package/src/prover/isabelle/pure/consts.ts +0 -8
- package/src/prover/isabelle/pure/conv.ts +2 -18
- package/src/prover/isabelle/pure/drule.ts +95 -45
- package/src/prover/isabelle/pure/envir.ts +2 -53
- package/src/prover/isabelle/pure/goal.ts +1 -9
- 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 -16
- package/src/prover/isabelle/pure/name.ts +1 -10
- package/src/prover/isabelle/pure/net.ts +2 -60
- package/src/prover/isabelle/pure/object-logic.ts +15 -16
- package/src/prover/isabelle/pure/pattern.ts +1 -20
- package/src/prover/isabelle/pure/raw-simplifier.ts +16 -63
- package/src/prover/isabelle/pure/rewriter.ts +31 -74
- package/src/prover/isabelle/pure/search.ts +2 -11
- package/src/prover/isabelle/pure/seq.ts +0 -11
- package/src/prover/isabelle/pure/simplifier.ts +27 -16
- package/src/prover/isabelle/pure/table.ts +2 -33
- package/src/prover/isabelle/pure/tactic.ts +11 -23
- package/src/prover/isabelle/pure/tactical.ts +47 -48
- package/src/prover/isabelle/pure/term-ord.ts +1 -7
- package/src/prover/isabelle/pure/term.ts +1 -44
- package/src/prover/isabelle/pure/thm.ts +26 -48
- package/src/prover/isabelle/pure/type.ts +1 -16
- package/src/prover/isabelle/pure/unify.ts +19 -31
- package/src/prover/isabelle/pure/variable.ts +2 -8
- package/src/prover/isabelle/tla/classical-setup.ts +17 -25
- package/src/prover/isabelle/tla/context.ts +65 -26
- package/src/prover/isabelle/tla/logic-data.ts +1 -1
- package/src/prover/isabelle/tla/logic.ts +53 -32
- package/src/prover/isabelle/tla/simpdata.ts +45 -44
- package/src/prover/isabelle/tools/intuitionistic.ts +28 -21
- package/src/prover/ocaml.ts +4 -7
- package/src/prover/prep/action.ts +33 -66
- package/src/prover/prep/enabled-axioms.ts +22 -20
- package/src/prover/prep/fingerprint.ts +2 -21
- package/src/prover/prep/level-comparison.ts +8 -12
- package/src/prover/prep/md5.ts +0 -2
- package/src/prover/prep/methods.ts +189 -86
- package/src/prover/prep/normalize.ts +42 -37
- package/src/prover/prove-worker.ts +0 -2
- package/src/prover/prove.ts +398 -133
- package/src/prover/ptl/decide.ts +96 -56
- package/src/prover/ptl/encode.ts +15 -38
- package/src/prover/ptl/sat.ts +24 -32
- package/src/prover/ptl/tableau.ts +40 -28
- package/src/prover/smt/arithmetic.ts +310 -0
- package/src/prover/smt/axioms.ts +12 -15
- package/src/prover/smt/context.ts +60 -32
- package/src/prover/smt/data.ts +517 -401
- package/src/prover/smt/encode.ts +155 -85
- package/src/prover/smt/extensionality.ts +5 -13
- package/src/prover/smt/flatten.ts +7 -28
- package/src/prover/smt/format.ts +33 -14
- package/src/prover/smt/instances.ts +7 -11
- package/src/prover/smt/layout.ts +91 -0
- package/src/prover/smt/rewrite.ts +1026 -658
- package/src/prover/smt/simplify.ts +441 -0
- package/src/prover/smt/solver/ackermannize-bv-tactic.ts +61 -0
- package/src/prover/smt/solver/ackr-helper.ts +179 -0
- package/src/prover/smt/solver/ackr-model-converter.ts +105 -0
- package/src/prover/smt/solver/act-cache.ts +0 -16
- package/src/prover/smt/solver/add-bounds-tactic.ts +59 -0
- package/src/prover/smt/solver/aig-tactic.ts +52 -0
- package/src/prover/smt/solver/aig.ts +889 -0
- package/src/prover/smt/solver/arith-rewriter.ts +615 -53
- package/src/prover/smt/solver/arith-terms.ts +121 -0
- package/src/prover/smt/solver/array-decl-plugin.ts +175 -0
- package/src/prover/smt/solver/array-rewriter.ts +309 -0
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +87 -58
- package/src/prover/smt/solver/ast-lt.ts +166 -22
- package/src/prover/smt/solver/ast-util.ts +160 -7
- package/src/prover/smt/solver/ast.ts +1424 -180
- package/src/prover/smt/solver/auf-solver.ts +7 -44
- package/src/prover/smt/solver/bit-blast-tactic.ts +582 -0
- package/src/prover/smt/solver/bit-blaster.ts +871 -0
- package/src/prover/smt/solver/bound-manager.ts +196 -0
- package/src/prover/smt/solver/bound-simplifier.ts +600 -0
- package/src/prover/smt/solver/bv-bound-chk.ts +492 -0
- package/src/prover/smt/solver/bv-decl-plugin.ts +338 -0
- package/src/prover/smt/solver/bv-divrem-bounds.ts +95 -0
- package/src/prover/smt/solver/bv-rewriter.ts +1901 -0
- package/src/prover/smt/solver/bv1-blast.ts +214 -0
- package/src/prover/smt/solver/bv2fpa-converter.ts +174 -0
- package/src/prover/smt/solver/bv2int-rewriter.ts +544 -0
- package/src/prover/smt/solver/bv2real-rewriter.ts +533 -0
- package/src/prover/smt/solver/card2bv.ts +110 -0
- package/src/prover/smt/solver/case-split-queue.ts +0 -10
- package/src/prover/smt/solver/cg-table.ts +39 -42
- package/src/prover/smt/solver/check-logic.ts +330 -0
- package/src/prover/smt/solver/clause.ts +0 -27
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +278 -0
- package/src/prover/smt/solver/conflict-resolution.ts +78 -11
- package/src/prover/smt/solver/context.ts +519 -175
- package/src/prover/smt/solver/ctx-simplify.ts +33 -50
- package/src/prover/smt/solver/ctx-solver-simplify.ts +122 -0
- package/src/prover/smt/solver/datatype-decl-plugin.ts +572 -0
- package/src/prover/smt/solver/datatype-rewriter.ts +82 -0
- package/src/prover/smt/solver/demodulator.ts +786 -0
- package/src/prover/smt/solver/dependent-expr-state.ts +81 -0
- package/src/prover/smt/solver/der.ts +39 -30
- package/src/prover/smt/solver/diff-neq.ts +206 -0
- package/src/prover/smt/solver/distribute-forall.ts +57 -0
- package/src/prover/smt/solver/dom-simplify.ts +511 -0
- package/src/prover/smt/solver/dt2bv-tactic.ts +260 -0
- package/src/prover/smt/solver/dyn-ack.ts +0 -11
- package/src/prover/smt/solver/e-matching.ts +9 -41
- package/src/prover/smt/solver/elim-small-bv-tactic.ts +129 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +545 -0
- package/src/prover/smt/solver/enode.ts +100 -23
- package/src/prover/smt/solver/eq2bv-tactic.ts +218 -0
- package/src/prover/smt/solver/euf/arith-axioms.ts +403 -0
- package/src/prover/smt/solver/euf/arith-internalize.ts +653 -0
- package/src/prover/smt/solver/euf/arith-solver.ts +889 -0
- package/src/prover/smt/solver/euf/array-axioms.ts +527 -0
- package/src/prover/smt/solver/euf/array-internalize.ts +428 -0
- package/src/prover/smt/solver/euf/array-solver.ts +306 -0
- package/src/prover/smt/solver/euf/bv-ackerman.ts +162 -0
- package/src/prover/smt/solver/euf/bv-internalize.ts +748 -0
- package/src/prover/smt/solver/euf/bv-solver.ts +449 -0
- package/src/prover/smt/solver/euf/dt-solver.ts +618 -0
- package/src/prover/smt/solver/euf/egraph.ts +907 -0
- package/src/prover/smt/solver/euf/euf-solver.ts +1205 -0
- package/src/prover/smt/solver/euf/fpa-solver.ts +317 -0
- package/src/prover/smt/solver/euf/mam.ts +1050 -0
- package/src/prover/smt/solver/euf/q-ematch.ts +830 -0
- package/src/prover/smt/solver/euf/q-mbi.ts +587 -0
- package/src/prover/smt/solver/euf/q-model-fixer.ts +296 -0
- package/src/prover/smt/solver/euf/q-solver.ts +361 -0
- package/src/prover/smt/solver/euf/th-solver.ts +335 -0
- package/src/prover/smt/solver/euf/th-solvers.ts +30 -0
- package/src/prover/smt/solver/expr-ref.ts +0 -5
- package/src/prover/smt/solver/expr-safe-replace.ts +26 -7
- package/src/prover/smt/solver/expr2polynomial.ts +146 -0
- package/src/prover/smt/solver/factor.ts +141 -0
- package/src/prover/smt/solver/fd-solver.ts +265 -0
- package/src/prover/smt/solver/fingerprints.ts +15 -26
- package/src/prover/smt/solver/fix-dl-var.ts +148 -0
- package/src/prover/smt/solver/flat-literals.ts +0 -9
- package/src/prover/smt/solver/fm-tactic.ts +884 -0
- package/src/prover/smt/solver/fpa-decl-plugin.ts +618 -0
- package/src/prover/smt/solver/fpa-rewriter.ts +640 -0
- package/src/prover/smt/solver/fpa2bv-converter.ts +2249 -0
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +348 -0
- package/src/prover/smt/solver/fpa2bv-tactic.ts +73 -0
- package/src/prover/smt/solver/goal.ts +176 -28
- package/src/prover/smt/solver/goal2nlsat.ts +189 -0
- package/src/prover/smt/solver/guard-set.ts +219 -0
- package/src/prover/smt/solver/hash.ts +0 -9
- package/src/prover/smt/solver/hashtable.ts +26 -23
- package/src/prover/smt/solver/inf-eps.ts +63 -0
- package/src/prover/smt/solver/inj-axiom.ts +101 -0
- package/src/prover/smt/solver/internalizer.ts +112 -132
- package/src/prover/smt/solver/lackr.ts +381 -0
- package/src/prover/smt/solver/lbool.ts +0 -2
- package/src/prover/smt/solver/lia2card.ts +268 -0
- package/src/prover/smt/solver/lia2pb.ts +154 -0
- package/src/prover/smt/solver/literal.ts +0 -4
- package/src/prover/smt/solver/logic-tactics.ts +345 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +7 -26
- package/src/prover/smt/solver/lp/constraints.ts +1 -8
- package/src/prover/smt/solver/lp/containers.ts +11 -30
- package/src/prover/smt/solver/lp/core-solver.ts +23 -29
- package/src/prover/smt/solver/lp/cross-nested.ts +5 -20
- package/src/prover/smt/solver/lp/dep-intervals.ts +6 -24
- package/src/prover/smt/solver/lp/dependency.ts +0 -5
- package/src/prover/smt/solver/lp/dioph-eq.ts +8 -103
- package/src/prover/smt/solver/lp/explanation.ts +0 -6
- package/src/prover/smt/solver/lp/gomory.ts +8 -22
- package/src/prover/smt/solver/lp/hnf-cutter.ts +16 -23
- package/src/prover/smt/solver/lp/hnf.ts +10 -28
- package/src/prover/smt/solver/lp/int-cube.ts +17 -39
- package/src/prover/smt/solver/lp/int-solver.ts +3 -35
- package/src/prover/smt/solver/lp/lar-solver.ts +69 -82
- package/src/prover/smt/solver/lp/lar-term.ts +0 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +0 -14
- package/src/prover/smt/solver/lp/maximize-term.ts +76 -52
- package/src/prover/smt/solver/lp/nex-creator.ts +4 -28
- package/src/prover/smt/solver/lp/nex.ts +0 -6
- package/src/prover/smt/solver/lp/nla-backoff.ts +0 -5
- package/src/prover/smt/solver/lp/nla-basics.ts +48 -30
- package/src/prover/smt/solver/lp/nla-core.ts +91 -135
- package/src/prover/smt/solver/lp/nla-divisions.ts +31 -43
- package/src/prover/smt/solver/lp/nla-emonics.ts +3 -21
- package/src/prover/smt/solver/lp/nla-factorization.ts +0 -4
- package/src/prover/smt/solver/lp/nla-grobner.ts +22 -72
- package/src/prover/smt/solver/lp/nla-horner.ts +2 -12
- package/src/prover/smt/solver/lp/nla-intervals.ts +1 -12
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +15 -42
- package/src/prover/smt/solver/lp/nla-monotone.ts +1 -6
- package/src/prover/smt/solver/lp/nla-order.ts +0 -13
- package/src/prover/smt/solver/lp/nla-patcher.ts +3 -7
- package/src/prover/smt/solver/lp/nla-powers.ts +220 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +0 -10
- package/src/prover/smt/solver/lp/nla-throttle.ts +0 -6
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +324 -0
- package/src/prover/smt/solver/lp/nla-types.ts +0 -12
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -26
- package/src/prover/smt/solver/lp/nra-solver.ts +123 -112
- package/src/prover/smt/solver/lp/numeric-pair.ts +0 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +0 -3
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +1 -14
- package/src/prover/smt/solver/lp/pdd-solver.ts +2 -33
- package/src/prover/smt/solver/lp/pdd.ts +7 -70
- package/src/prover/smt/solver/lp/random-updater.ts +0 -9
- package/src/prover/smt/solver/lp/static-matrix.ts +8 -19
- package/src/prover/smt/solver/lp/union-find.ts +5 -5
- package/src/prover/smt/solver/macro-finder.ts +530 -0
- package/src/prover/smt/solver/mam-compiler.ts +129 -139
- package/src/prover/smt/solver/mam-interpreter.ts +0 -21
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +17 -0
- package/src/prover/smt/solver/max-cliques.ts +105 -0
- package/src/prover/smt/solver/maxcore.ts +309 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +8 -21
- package/src/prover/smt/solver/maxlex.ts +115 -0
- package/src/prover/smt/solver/maxsmt-base.ts +105 -0
- package/src/prover/smt/solver/maxsmt.ts +92 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +467 -0
- package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +101 -0
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +287 -0
- package/src/prover/smt/solver/mbp/mbp-qel.ts +48 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +271 -0
- package/src/prover/smt/solver/mbp/mbp-term-graph.ts +606 -0
- package/src/prover/smt/solver/model-based-opt.ts +844 -0
- package/src/prover/smt/solver/model-checker.ts +19 -62
- package/src/prover/smt/solver/model-evaluator.ts +190 -40
- package/src/prover/smt/solver/model-finder.ts +14 -32
- package/src/prover/smt/solver/model-generator.ts +56 -40
- package/src/prover/smt/solver/model-macro-solver.ts +60 -114
- package/src/prover/smt/solver/model-printer.ts +214 -0
- package/src/prover/smt/solver/mpf.ts +711 -0
- package/src/prover/smt/solver/mus.ts +51 -0
- package/src/prover/smt/solver/muz/dl-context.ts +404 -0
- package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +97 -0
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +167 -0
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +125 -0
- package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +299 -0
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +455 -0
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +340 -0
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +163 -0
- package/src/prover/smt/solver/muz/dl-rule-set.ts +273 -0
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +123 -0
- package/src/prover/smt/solver/muz/dl-rule.ts +496 -0
- package/src/prover/smt/solver/muz/hnf.ts +201 -0
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +176 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +201 -0
- package/src/prover/smt/solver/muz/rule-properties.ts +337 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +1406 -0
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +52 -0
- package/src/prover/smt/solver/muz/spacer-generalizers.ts +241 -0
- package/src/prover/smt/solver/muz/spacer-manager.ts +127 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +218 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +333 -0
- package/src/prover/smt/solver/muz/spacer-util.ts +282 -0
- package/src/prover/smt/solver/muz/substitution.ts +203 -0
- package/src/prover/smt/solver/nla2bv-tactic.ts +285 -0
- package/src/prover/smt/solver/nlqsat.ts +484 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +177 -160
- package/src/prover/smt/solver/nlsat/atoms.ts +24 -24
- package/src/prover/smt/solver/nlsat/evaluator.ts +16 -22
- package/src/prover/smt/solver/nlsat/explain.ts +65 -69
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -51
- package/src/prover/smt/solver/nlsat/levelwise.ts +48 -135
- package/src/prover/smt/solver/nlsat/mpbq.ts +47 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +29 -161
- package/src/prover/smt/solver/nlsat/solver.ts +241 -110
- package/src/prover/smt/solver/nlsat/transcendental-eval.ts +310 -0
- package/src/prover/smt/solver/nlsat/transcendentals.ts +367 -0
- package/src/prover/smt/solver/nlsat/types.ts +0 -9
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -47
- package/src/prover/smt/solver/nlsat/upolynomial.ts +10 -93
- package/src/prover/smt/solver/nlsat-tactic.ts +82 -0
- package/src/prover/smt/solver/nnf.ts +107 -60
- package/src/prover/smt/solver/normalize-bounds.ts +53 -0
- package/src/prover/smt/solver/occf.ts +97 -0
- package/src/prover/smt/solver/opt-context.ts +787 -0
- package/src/prover/smt/solver/opt-nlsat.ts +375 -0
- package/src/prover/smt/solver/opt-pareto.ts +282 -0
- package/src/prover/smt/solver/opt-preprocess.ts +101 -0
- package/src/prover/smt/solver/opt-solver.ts +308 -0
- package/src/prover/smt/solver/opt-value.ts +55 -0
- package/src/prover/smt/solver/optsmt.ts +692 -0
- package/src/prover/smt/solver/parallel-tactic.ts +299 -0
- package/src/prover/smt/solver/pattern-inference.ts +21 -26
- package/src/prover/smt/solver/pb-rewriter.ts +284 -0
- package/src/prover/smt/solver/pb2bv-tactic.ts +540 -0
- package/src/prover/smt/solver/poly-rewriter.ts +204 -79
- package/src/prover/smt/solver/probes.ts +512 -0
- package/src/prover/smt/solver/propagate-values.ts +37 -30
- package/src/prover/smt/solver/proto-model.ts +650 -66
- package/src/prover/smt/solver/pull-quant.ts +28 -23
- package/src/prover/smt/solver/purify-arith.ts +632 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +1098 -0
- package/src/prover/smt/solver/qe-lite-der.ts +2 -31
- package/src/prover/smt/solver/qe-lite-fm.ts +4 -28
- package/src/prover/smt/solver/qe-lite.ts +39 -49
- package/src/prover/smt/solver/qe-mbp.ts +270 -0
- package/src/prover/smt/solver/qe.ts +1498 -0
- package/src/prover/smt/solver/qel.ts +25 -0
- package/src/prover/smt/solver/qi-queue.ts +0 -16
- package/src/prover/smt/solver/qsat.ts +814 -0
- package/src/prover/smt/solver/quant-hoist.ts +196 -0
- package/src/prover/smt/solver/quant-tactics.ts +17 -74
- package/src/prover/smt/solver/quantifier-analyzer.ts +26 -47
- package/src/prover/smt/solver/quantifier-manager.ts +8 -23
- package/src/prover/smt/solver/quasi-macros.ts +243 -0
- package/src/prover/smt/solver/random-gen.ts +0 -2
- package/src/prover/smt/solver/rational.ts +45 -8
- package/src/prover/smt/solver/recfun-decl-plugin.ts +261 -0
- package/src/prover/smt/solver/recfun-rewriter.ts +107 -0
- package/src/prover/smt/solver/reduce-args.ts +225 -0
- package/src/prover/smt/solver/reduce-bv-size.ts +119 -0
- package/src/prover/smt/solver/ref-vector.ts +0 -6
- package/src/prover/smt/solver/relevancy.ts +2 -16
- package/src/prover/smt/solver/rewriter-tpl.ts +52 -129
- package/src/prover/smt/solver/rewriter.ts +477 -120
- package/src/prover/smt/solver/rlimit.ts +39 -21
- package/src/prover/smt/solver/sat/asymm-branch.ts +325 -0
- package/src/prover/smt/solver/sat/big.ts +177 -0
- package/src/prover/smt/solver/sat/clause-use-list.ts +71 -0
- package/src/prover/smt/solver/sat/clause.ts +203 -0
- package/src/prover/smt/solver/sat/cleaner.ts +94 -0
- package/src/prover/smt/solver/sat/config.ts +122 -0
- package/src/prover/smt/solver/sat/consequences.ts +203 -0
- package/src/prover/smt/solver/sat/elim-eqs.ts +142 -0
- package/src/prover/smt/solver/sat/goal2sat.ts +526 -0
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +378 -0
- package/src/prover/smt/solver/sat/model-converter.ts +136 -0
- package/src/prover/smt/solver/sat/pb-constraint.ts +261 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +1577 -0
- package/src/prover/smt/solver/sat/probing.ts +170 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +43 -0
- package/src/prover/smt/solver/sat/sat2goal.ts +165 -0
- package/src/prover/smt/solver/sat/scc.ts +142 -0
- package/src/prover/smt/solver/sat/simplifier.ts +1618 -0
- package/src/prover/smt/solver/sat/solver.ts +2127 -0
- package/src/prover/smt/solver/sat/var-queue.ts +117 -0
- package/src/prover/smt/solver/sat/watch-list.ts +140 -0
- package/src/prover/smt/solver/search-tree.ts +284 -0
- package/src/prover/smt/solver/seq-axioms.ts +1010 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +819 -0
- package/src/prover/smt/solver/seq-derive.ts +1301 -0
- package/src/prover/smt/solver/seq-eq-approx.ts +236 -0
- package/src/prover/smt/solver/seq-eq-solver.ts +439 -0
- package/src/prover/smt/solver/seq-factory.ts +89 -0
- package/src/prover/smt/solver/seq-monadic.ts +728 -0
- package/src/prover/smt/solver/seq-range-predicate.ts +235 -0
- package/src/prover/smt/solver/seq-re-rewriter.ts +1170 -0
- package/src/prover/smt/solver/seq-re-util.ts +758 -0
- package/src/prover/smt/solver/seq-regex-bisim.ts +144 -0
- package/src/prover/smt/solver/seq-regex-live.ts +200 -0
- package/src/prover/smt/solver/seq-rewriter.ts +2402 -0
- package/src/prover/smt/solver/seq-skolem.ts +317 -0
- package/src/prover/smt/solver/seq-subset.ts +165 -0
- package/src/prover/smt/solver/seq-view-witness.ts +353 -0
- package/src/prover/smt/solver/smt-consequences.ts +297 -0
- package/src/prover/smt/solver/smt-kernel.ts +83 -0
- package/src/prover/smt/solver/smt-logics.ts +66 -0
- package/src/prover/smt/solver/smt-setup.ts +496 -0
- package/src/prover/smt/solver/smt2-printer.ts +765 -0
- package/src/prover/smt/solver/smtlib-parser.ts +3140 -365
- package/src/prover/smt/solver/smtlib-script.ts +1631 -0
- package/src/prover/smt/solver/solve-eqs.ts +929 -0
- package/src/prover/smt/solver/solver.ts +119 -39
- package/src/prover/smt/solver/sort.ts +1 -5
- package/src/prover/smt/solver/static-features.ts +314 -0
- package/src/prover/smt/solver/sticky-generations.ts +0 -6
- package/src/prover/smt/solver/tactic.ts +1986 -0
- package/src/prover/smt/solver/term-enumeration.ts +205 -0
- package/src/prover/smt/solver/theory-array.ts +1240 -0
- package/src/prover/smt/solver/theory-bv.ts +1200 -0
- package/src/prover/smt/solver/theory-char.ts +355 -0
- package/src/prover/smt/solver/theory-datatype.ts +598 -0
- package/src/prover/smt/solver/theory-finite-set.ts +30 -0
- package/src/prover/smt/solver/theory-fpa.ts +389 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +55 -25
- package/src/prover/smt/solver/theory-lra-bounds.ts +31 -11
- package/src/prover/smt/solver/theory-lra-final-check.ts +59 -91
- package/src/prover/smt/solver/theory-lra-internalize.ts +94 -53
- package/src/prover/smt/solver/theory-lra-model.ts +23 -53
- package/src/prover/smt/solver/theory-lra-propagate.ts +24 -40
- package/src/prover/smt/solver/theory-lra-state.ts +6 -27
- package/src/prover/smt/solver/theory-lra.ts +188 -8
- package/src/prover/smt/solver/theory-pb.ts +934 -0
- package/src/prover/smt/solver/theory-polymorphism.ts +58 -0
- package/src/prover/smt/solver/theory-recfun.ts +307 -0
- package/src/prover/smt/solver/theory-seq-regex.ts +867 -0
- package/src/prover/smt/solver/theory-seq-solve.ts +1373 -0
- package/src/prover/smt/solver/theory-seq-state.ts +871 -0
- package/src/prover/smt/solver/theory-seq.ts +961 -0
- package/src/prover/smt/solver/theory.ts +189 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +485 -0
- package/src/prover/smt/solver/var-subst.ts +37 -39
- package/src/prover/smt/table.ts +3 -10
- package/src/prover/smt/types.ts +146 -0
- package/src/prover/tlapm/cache.ts +67 -41
- package/src/prover/tlapm/ocaml-marshal.ts +19 -21
- package/src/prover/tlapm/tlapm.ts +21 -20
- package/src/prover/tlapm-library.ts +3208 -0
- package/src/prover/verdict.ts +9 -2
- package/src/prover/zenon/check/check.ts +1 -11
- package/src/prover/zenon/check/definitions.ts +5 -15
- package/src/prover/zenon/check/equality.ts +0 -8
- package/src/prover/zenon/check/functions.ts +0 -4
- package/src/prover/zenon/check/keys.ts +0 -7
- package/src/prover/zenon/check/propositional.ts +0 -3
- package/src/prover/zenon/check/records.ts +1 -6
- package/src/prover/zenon/check/relations.ts +2 -14
- package/src/prover/zenon/check/rewrites.ts +2 -21
- package/src/prover/zenon/check/sets.ts +40 -61
- package/src/prover/zenon/check/terms.ts +1 -19
- package/src/prover/zenon/check/tla.ts +0 -6
- package/src/prover/zenon/decide.ts +10 -19
- package/src/prover/zenon/encode.ts +0 -9
- package/src/prover/zenon/eqrel.ts +2 -15
- package/src/prover/zenon/equality-rules.ts +0 -6
- package/src/prover/zenon/expr.ts +8 -28
- package/src/prover/zenon/index-table.ts +26 -59
- package/src/prover/zenon/isar-case.ts +8 -20
- package/src/prover/zenon/isar.ts +35 -65
- package/src/prover/zenon/limits.ts +0 -4
- package/src/prover/zenon/llproof.ts +2 -22
- package/src/prover/zenon/mltoll.ts +66 -106
- package/src/prover/zenon/node.ts +20 -15
- package/src/prover/zenon/ocaml.ts +1 -17
- package/src/prover/zenon/parse.ts +9 -13
- package/src/prover/zenon/phrase.ts +1 -13
- package/src/prover/zenon/proof.ts +0 -11
- package/src/prover/zenon/propositional-rules.ts +0 -7
- package/src/prover/zenon/rules.ts +2 -8
- package/src/prover/zenon/search.ts +11 -35
- package/src/prover/zenon/tla/functions.ts +59 -33
- package/src/prover/zenon/tla/llproof.ts +67 -78
- package/src/prover/zenon/tla/records.ts +57 -35
- package/src/prover/zenon/tla/rewrites.ts +12 -21
- package/src/prover/zenon/tla/sets.ts +88 -59
- package/src/prover/zenon/tla/terms.ts +0 -8
- package/src/prover/zenon/tla/tla.ts +66 -66
- package/src/randomization.ts +81 -35
- package/src/resolve.ts +67 -185
- package/src/runtime.ts +26 -22
- package/src/sany/builtins.ts +2 -5
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +191 -2764
- package/src/sany/levels.ts +5 -35
- package/src/sany/lexer.ts +58 -77
- package/src/sany/linter.ts +0 -10
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +5 -43
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +32 -69
- package/src/sany/selectors.ts +49 -76
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +35 -117
- package/src/search.ts +671 -169
- package/src/simulate.ts +712 -0
- package/src/spec-description.ts +192 -100
- package/src/standard-definitions.ts +4 -4
- package/src/standard-modules.ts +264 -95
- package/src/state-graph.ts +52 -33
- package/src/subexpressions.ts +69 -52
- package/src/substitution-levels.ts +7 -7
- package/src/successors.ts +267 -100
- package/src/symmetry.ts +35 -27
- package/src/tableau.ts +29 -26
- package/src/tlc/fingerprint.ts +267 -79
- package/src/tlc/jar-data.ts +112 -6
- package/src/tlc/messages.ts +125 -54
- package/src/tlc/order.ts +39 -69
- package/src/tlc/random.ts +37 -49
- package/src/tlc/replay.ts +553 -228
- package/src/tlc/summary.ts +64 -60
- package/src/tlc/tlc-operators.ts +78 -44
- package/src/tlc/tlcext-operators.ts +171 -122
- package/src/tlc/trace-spec.ts +249 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/transfer.ts +22 -25
- package/src/typed-tier.ts +6535 -0
- package/src/typescript/actions.ts +479 -0
- package/src/typescript/collections.ts +614 -0
- package/src/typescript/compile.ts +63 -0
- package/src/typescript/context.ts +94 -0
- package/src/typescript/emit.ts +121 -0
- package/src/typescript/expressions.ts +496 -0
- package/src/typescript/formula.ts +154 -0
- package/src/typescript/functions.ts +284 -0
- package/src/typescript/model.ts +162 -0
- package/src/typescript/names.ts +114 -0
- package/src/typescript/program.ts +48 -0
- package/src/typescript/properties.ts +139 -0
- package/src/typescript/scope.ts +112 -0
- package/src/typescript/steps.ts +167 -0
- package/src/typescript/types.ts +171 -0
- package/src/values.ts +832 -484
- package/src/worker.ts +7 -8
- package/src/prover/isabelle/isar/statement.ts +0 -57
- package/src/prover/smt/solver/z3-license.txt +0 -10
- package/src/prover/tlaps-module.ts +0 -510
- package/src/prover/zenon/LICENSE +0 -32
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
// Ported from Z3 (src/ast/ast.h, src/ast/ast.cpp), MIT license, see z3-license.txt.
|
|
2
|
-
// A hash-consed DAG of applications, de Bruijn variables and quantifiers, as in Z3's ast_manager.
|
|
3
1
|
import { SmtInvariantError } from "../../../errors";
|
|
4
2
|
import { FlatLiterals } from "./flat-literals";
|
|
5
3
|
import { astArrayHash, bytesHash, combineHash, getCompositeHash, mkMix, stringHash } from "./hash";
|
|
6
4
|
import { ObjMap } from "./hashtable";
|
|
7
5
|
import { Rational } from "./rational";
|
|
8
6
|
import { grow, shrink } from "./array";
|
|
7
|
+
import type { DatatypeDef } from "./datatype-decl-plugin";
|
|
8
|
+
import { AlgebraicManager, Anum } from "./nlsat/algebraic";
|
|
9
|
+
import type { Mpf } from "./mpf";
|
|
9
10
|
import type { ResourceLimit } from "./rlimit";
|
|
10
11
|
|
|
11
12
|
export const KIND_APP = 0;
|
|
12
13
|
export const KIND_VAR = 1;
|
|
13
14
|
export const KIND_QUANTIFIER = 2;
|
|
14
15
|
|
|
16
|
+
export const QUANTIFIER_FORALL = 0;
|
|
17
|
+
export const QUANTIFIER_EXISTS = 1;
|
|
18
|
+
export const QUANTIFIER_LAMBDA = 2;
|
|
19
|
+
|
|
15
20
|
export const SORT_BOOL = 0;
|
|
16
21
|
export const SORT_INT = 1;
|
|
17
22
|
export const SORT_REAL = 2;
|
|
@@ -19,8 +24,18 @@ export const SORT_REAL = 2;
|
|
|
19
24
|
export const FAMILY_BASIC = 0;
|
|
20
25
|
export const FAMILY_ARITH = 1;
|
|
21
26
|
export const FAMILY_USER = 2;
|
|
22
|
-
// Model values: the elements that a model gives to an uninterpreted sort.
|
|
23
27
|
export const FAMILY_MODEL_VALUE = 3;
|
|
28
|
+
export const FAMILY_FINITE_SET = 4;
|
|
29
|
+
export const FAMILY_BV = 5;
|
|
30
|
+
export const FAMILY_ARRAY = 6;
|
|
31
|
+
export const FAMILY_DATATYPE = 7;
|
|
32
|
+
export const FAMILY_FPA = 8;
|
|
33
|
+
export const FAMILY_CHAR = 9;
|
|
34
|
+
export const FAMILY_SEQ = 10;
|
|
35
|
+
export const FAMILY_LABEL = 11;
|
|
36
|
+
export const FAMILY_PB = 12;
|
|
37
|
+
export const FAMILY_RECFUN = 13;
|
|
38
|
+
export const FAMILY_POLY = 14;
|
|
24
39
|
|
|
25
40
|
export const OP_TRUE = 0;
|
|
26
41
|
export const OP_FALSE = 1;
|
|
@@ -49,18 +64,281 @@ export const OP_DIV = 23;
|
|
|
49
64
|
export const OP_TO_REAL = 24;
|
|
50
65
|
export const OP_TO_INT = 25;
|
|
51
66
|
export const OP_IS_INT = 26;
|
|
52
|
-
// Z3's div0, idiv0 and mod0: division by zero, which theory_lra's found_underspecified equates with
|
|
53
|
-
// the division it stands for.
|
|
54
67
|
export const OP_DIV0 = 27;
|
|
55
68
|
export const OP_IDIV0 = 28;
|
|
56
69
|
export const OP_MOD0 = 29;
|
|
57
|
-
export const
|
|
58
|
-
const
|
|
70
|
+
export const OP_POWER = 30;
|
|
71
|
+
export const OP_POWER0 = 31;
|
|
72
|
+
export const OP_SIN = 32;
|
|
73
|
+
export const OP_COS = 33;
|
|
74
|
+
export const OP_TAN = 34;
|
|
75
|
+
export const OP_ASIN = 35;
|
|
76
|
+
export const OP_ACOS = 36;
|
|
77
|
+
export const OP_ATAN = 37;
|
|
78
|
+
export const OP_SINH = 38;
|
|
79
|
+
export const OP_COSH = 39;
|
|
80
|
+
export const OP_TANH = 40;
|
|
81
|
+
export const OP_ASINH = 41;
|
|
82
|
+
export const OP_ACOSH = 42;
|
|
83
|
+
export const OP_ATANH = 43;
|
|
84
|
+
export const OP_EXP = 44;
|
|
85
|
+
export const OP_ATAN2 = 45;
|
|
86
|
+
export const OP_LOG = 46;
|
|
87
|
+
export const OP_PI = 47;
|
|
88
|
+
export const OP_E = 48;
|
|
89
|
+
export const OP_ALGEBRAIC_NUM = 49;
|
|
90
|
+
export const OP_REM = 50;
|
|
91
|
+
export const OP_NEG_ROOT = 51;
|
|
92
|
+
export const OP_U_ASIN = 52;
|
|
93
|
+
export const OP_U_ACOS = 53;
|
|
94
|
+
export const OP_UNINTERPRETED = 60;
|
|
95
|
+
const OP_MODEL_VALUE = 61;
|
|
96
|
+
|
|
97
|
+
const BV_OP_BASE = 100;
|
|
98
|
+
export const OP_BV_NUM = BV_OP_BASE;
|
|
99
|
+
export const OP_BNEG = BV_OP_BASE + 3;
|
|
100
|
+
export const OP_BADD = BV_OP_BASE + 4;
|
|
101
|
+
export const OP_BSUB = BV_OP_BASE + 5;
|
|
102
|
+
export const OP_BMUL = BV_OP_BASE + 6;
|
|
103
|
+
export const OP_BSDIV = BV_OP_BASE + 7;
|
|
104
|
+
export const OP_BUDIV = BV_OP_BASE + 8;
|
|
105
|
+
export const OP_BSREM = BV_OP_BASE + 9;
|
|
106
|
+
export const OP_BUREM = BV_OP_BASE + 10;
|
|
107
|
+
export const OP_BSMOD = BV_OP_BASE + 11;
|
|
108
|
+
export const OP_BSDIV0 = BV_OP_BASE + 12;
|
|
109
|
+
export const OP_BUDIV0 = BV_OP_BASE + 13;
|
|
110
|
+
export const OP_BSREM0 = BV_OP_BASE + 14;
|
|
111
|
+
export const OP_BUREM0 = BV_OP_BASE + 15;
|
|
112
|
+
export const OP_BSMOD0 = BV_OP_BASE + 16;
|
|
113
|
+
export const OP_BSDIV_I = BV_OP_BASE + 17;
|
|
114
|
+
export const OP_BUDIV_I = BV_OP_BASE + 18;
|
|
115
|
+
export const OP_BSREM_I = BV_OP_BASE + 19;
|
|
116
|
+
export const OP_BUREM_I = BV_OP_BASE + 20;
|
|
117
|
+
export const OP_BSMOD_I = BV_OP_BASE + 21;
|
|
118
|
+
export const OP_ULEQ = BV_OP_BASE + 22;
|
|
119
|
+
export const OP_SLEQ = BV_OP_BASE + 23;
|
|
120
|
+
export const OP_UGEQ = BV_OP_BASE + 24;
|
|
121
|
+
export const OP_SGEQ = BV_OP_BASE + 25;
|
|
122
|
+
export const OP_ULT = BV_OP_BASE + 26;
|
|
123
|
+
export const OP_SLT = BV_OP_BASE + 27;
|
|
124
|
+
export const OP_UGT = BV_OP_BASE + 28;
|
|
125
|
+
export const OP_SGT = BV_OP_BASE + 29;
|
|
126
|
+
export const OP_BAND = BV_OP_BASE + 30;
|
|
127
|
+
export const OP_BOR = BV_OP_BASE + 31;
|
|
128
|
+
export const OP_BNOT = BV_OP_BASE + 32;
|
|
129
|
+
export const OP_BXOR = BV_OP_BASE + 33;
|
|
130
|
+
export const OP_BNAND = BV_OP_BASE + 34;
|
|
131
|
+
export const OP_BNOR = BV_OP_BASE + 35;
|
|
132
|
+
export const OP_BXNOR = BV_OP_BASE + 36;
|
|
133
|
+
export const OP_CONCAT = BV_OP_BASE + 37;
|
|
134
|
+
export const OP_SIGN_EXT = BV_OP_BASE + 38;
|
|
135
|
+
export const OP_ZERO_EXT = BV_OP_BASE + 39;
|
|
136
|
+
export const OP_EXTRACT = BV_OP_BASE + 40;
|
|
137
|
+
export const OP_REPEAT = BV_OP_BASE + 41;
|
|
138
|
+
export const OP_BREDOR = BV_OP_BASE + 42;
|
|
139
|
+
export const OP_BREDAND = BV_OP_BASE + 43;
|
|
140
|
+
export const OP_BCOMP = BV_OP_BASE + 44;
|
|
141
|
+
export const OP_BSHL = BV_OP_BASE + 45;
|
|
142
|
+
export const OP_BLSHR = BV_OP_BASE + 46;
|
|
143
|
+
export const OP_BASHR = BV_OP_BASE + 47;
|
|
144
|
+
export const OP_ROTATE_LEFT = BV_OP_BASE + 48;
|
|
145
|
+
export const OP_ROTATE_RIGHT = BV_OP_BASE + 49;
|
|
146
|
+
export const OP_EXT_ROTATE_LEFT = BV_OP_BASE + 50;
|
|
147
|
+
export const OP_EXT_ROTATE_RIGHT = BV_OP_BASE + 51;
|
|
148
|
+
export const OP_BUMUL_NO_OVFL = BV_OP_BASE + 52;
|
|
149
|
+
export const OP_BSMUL_NO_OVFL = BV_OP_BASE + 53;
|
|
150
|
+
export const OP_BSMUL_NO_UDFL = BV_OP_BASE + 54;
|
|
151
|
+
export const OP_BUMUL_OVFL = BV_OP_BASE + 55;
|
|
152
|
+
export const OP_BSMUL_OVFL = BV_OP_BASE + 56;
|
|
153
|
+
export const OP_BSDIV_OVFL = BV_OP_BASE + 57;
|
|
154
|
+
export const OP_BNEG_OVFL = BV_OP_BASE + 58;
|
|
155
|
+
export const OP_BUADD_OVFL = BV_OP_BASE + 59;
|
|
156
|
+
export const OP_BSADD_OVFL = BV_OP_BASE + 60;
|
|
157
|
+
export const OP_BUSUB_OVFL = BV_OP_BASE + 61;
|
|
158
|
+
export const OP_BSSUB_OVFL = BV_OP_BASE + 62;
|
|
159
|
+
export const OP_BIT2BOOL = BV_OP_BASE + 63;
|
|
160
|
+
export const OP_MKBV = BV_OP_BASE + 64;
|
|
161
|
+
export const OP_INT2BV = BV_OP_BASE + 65;
|
|
162
|
+
export const OP_UBV2INT = BV_OP_BASE + 66;
|
|
163
|
+
export const OP_SBV2INT = BV_OP_BASE + 67;
|
|
164
|
+
export const OP_CARRY = BV_OP_BASE + 68;
|
|
165
|
+
export const OP_XOR3 = BV_OP_BASE + 69;
|
|
166
|
+
|
|
167
|
+
const ARRAY_OP_BASE = 200;
|
|
168
|
+
export const OP_STORE = ARRAY_OP_BASE;
|
|
169
|
+
export const OP_SELECT = ARRAY_OP_BASE + 1;
|
|
170
|
+
export const OP_CONST_ARRAY = ARRAY_OP_BASE + 2;
|
|
171
|
+
export const OP_ARRAY_EXT = ARRAY_OP_BASE + 3;
|
|
172
|
+
export const OP_ARRAY_DEFAULT = ARRAY_OP_BASE + 4;
|
|
173
|
+
export const OP_ARRAY_MAP = ARRAY_OP_BASE + 5;
|
|
174
|
+
export const OP_AS_ARRAY = ARRAY_OP_BASE + 11;
|
|
175
|
+
const DATATYPE_OP_BASE = 300;
|
|
176
|
+
export const OP_DT_CONSTRUCTOR = DATATYPE_OP_BASE;
|
|
177
|
+
export const OP_DT_RECOGNISER = DATATYPE_OP_BASE + 1;
|
|
178
|
+
export const OP_DT_IS = DATATYPE_OP_BASE + 2;
|
|
179
|
+
export const OP_DT_ACCESSOR = DATATYPE_OP_BASE + 3;
|
|
180
|
+
export const OP_DT_UPDATE_FIELD = DATATYPE_OP_BASE + 4;
|
|
181
|
+
const FPA_OP_BASE = 400;
|
|
182
|
+
export const OP_FPA_RM_NEAREST_TIES_TO_EVEN = FPA_OP_BASE;
|
|
183
|
+
export const OP_FPA_RM_NEAREST_TIES_TO_AWAY = FPA_OP_BASE + 1;
|
|
184
|
+
export const OP_FPA_RM_TOWARD_POSITIVE = FPA_OP_BASE + 2;
|
|
185
|
+
export const OP_FPA_RM_TOWARD_NEGATIVE = FPA_OP_BASE + 3;
|
|
186
|
+
export const OP_FPA_RM_TOWARD_ZERO = FPA_OP_BASE + 4;
|
|
187
|
+
export const OP_FPA_NUM = FPA_OP_BASE + 5;
|
|
188
|
+
export const OP_FPA_PLUS_INF = FPA_OP_BASE + 6;
|
|
189
|
+
export const OP_FPA_MINUS_INF = FPA_OP_BASE + 7;
|
|
190
|
+
export const OP_FPA_NAN = FPA_OP_BASE + 8;
|
|
191
|
+
export const OP_FPA_PLUS_ZERO = FPA_OP_BASE + 9;
|
|
192
|
+
export const OP_FPA_MINUS_ZERO = FPA_OP_BASE + 10;
|
|
193
|
+
export const OP_FPA_ADD = FPA_OP_BASE + 11;
|
|
194
|
+
export const OP_FPA_SUB = FPA_OP_BASE + 12;
|
|
195
|
+
export const OP_FPA_NEG = FPA_OP_BASE + 13;
|
|
196
|
+
export const OP_FPA_MUL = FPA_OP_BASE + 14;
|
|
197
|
+
export const OP_FPA_DIV = FPA_OP_BASE + 15;
|
|
198
|
+
export const OP_FPA_REM = FPA_OP_BASE + 16;
|
|
199
|
+
export const OP_FPA_ABS = FPA_OP_BASE + 17;
|
|
200
|
+
export const OP_FPA_MIN = FPA_OP_BASE + 18;
|
|
201
|
+
export const OP_FPA_MAX = FPA_OP_BASE + 19;
|
|
202
|
+
export const OP_FPA_MIN_I = FPA_OP_BASE + 20;
|
|
203
|
+
export const OP_FPA_MAX_I = FPA_OP_BASE + 21;
|
|
204
|
+
export const OP_FPA_FMA = FPA_OP_BASE + 22;
|
|
205
|
+
export const OP_FPA_SQRT = FPA_OP_BASE + 23;
|
|
206
|
+
export const OP_FPA_ROUND_TO_INTEGRAL = FPA_OP_BASE + 24;
|
|
207
|
+
export const OP_FPA_EQ = FPA_OP_BASE + 25;
|
|
208
|
+
export const OP_FPA_LT = FPA_OP_BASE + 26;
|
|
209
|
+
export const OP_FPA_GT = FPA_OP_BASE + 27;
|
|
210
|
+
export const OP_FPA_LE = FPA_OP_BASE + 28;
|
|
211
|
+
export const OP_FPA_GE = FPA_OP_BASE + 29;
|
|
212
|
+
export const OP_FPA_IS_NAN = FPA_OP_BASE + 30;
|
|
213
|
+
export const OP_FPA_IS_INF = FPA_OP_BASE + 31;
|
|
214
|
+
export const OP_FPA_IS_ZERO = FPA_OP_BASE + 32;
|
|
215
|
+
export const OP_FPA_IS_NORMAL = FPA_OP_BASE + 33;
|
|
216
|
+
export const OP_FPA_IS_SUBNORMAL = FPA_OP_BASE + 34;
|
|
217
|
+
export const OP_FPA_IS_NEGATIVE = FPA_OP_BASE + 35;
|
|
218
|
+
export const OP_FPA_IS_POSITIVE = FPA_OP_BASE + 36;
|
|
219
|
+
export const OP_FPA_FP = FPA_OP_BASE + 37;
|
|
220
|
+
export const OP_FPA_TO_FP = FPA_OP_BASE + 38;
|
|
221
|
+
export const OP_FPA_TO_FP_UNSIGNED = FPA_OP_BASE + 39;
|
|
222
|
+
export const OP_FPA_TO_UBV = FPA_OP_BASE + 40;
|
|
223
|
+
export const OP_FPA_TO_SBV = FPA_OP_BASE + 41;
|
|
224
|
+
export const OP_FPA_TO_REAL = FPA_OP_BASE + 42;
|
|
225
|
+
export const OP_FPA_TO_REAL_I = FPA_OP_BASE + 43;
|
|
226
|
+
export const OP_FPA_TO_SBV_I = FPA_OP_BASE + 44;
|
|
227
|
+
export const OP_FPA_TO_UBV_I = FPA_OP_BASE + 45;
|
|
228
|
+
export const OP_FPA_TO_IEEE_BV = FPA_OP_BASE + 46;
|
|
229
|
+
export const OP_FPA_TO_IEEE_BV_I = FPA_OP_BASE + 47;
|
|
230
|
+
export const OP_FPA_BVWRAP = FPA_OP_BASE + 48;
|
|
231
|
+
export const OP_FPA_BV2RM = FPA_OP_BASE + 49;
|
|
232
|
+
const SEQ_OP_BASE = 500;
|
|
233
|
+
export const OP_SEQ_UNIT = SEQ_OP_BASE;
|
|
234
|
+
export const OP_SEQ_EMPTY = SEQ_OP_BASE + 1;
|
|
235
|
+
export const OP_SEQ_CONCAT = SEQ_OP_BASE + 2;
|
|
236
|
+
export const OP_SEQ_PREFIX = SEQ_OP_BASE + 3;
|
|
237
|
+
export const OP_SEQ_SUFFIX = SEQ_OP_BASE + 4;
|
|
238
|
+
export const OP_SEQ_CONTAINS = SEQ_OP_BASE + 5;
|
|
239
|
+
export const OP_SEQ_EXTRACT = SEQ_OP_BASE + 6;
|
|
240
|
+
export const OP_SEQ_REPLACE = SEQ_OP_BASE + 7;
|
|
241
|
+
export const OP_SEQ_AT = SEQ_OP_BASE + 8;
|
|
242
|
+
export const OP_SEQ_NTH = SEQ_OP_BASE + 9;
|
|
243
|
+
export const OP_SEQ_NTH_I = SEQ_OP_BASE + 10;
|
|
244
|
+
export const OP_SEQ_NTH_U = SEQ_OP_BASE + 11;
|
|
245
|
+
export const OP_SEQ_LENGTH = SEQ_OP_BASE + 12;
|
|
246
|
+
export const OP_SEQ_INDEX = SEQ_OP_BASE + 13;
|
|
247
|
+
export const OP_SEQ_LAST_INDEX = SEQ_OP_BASE + 14;
|
|
248
|
+
export const OP_SEQ_TO_RE = SEQ_OP_BASE + 15;
|
|
249
|
+
export const OP_SEQ_IN_RE = SEQ_OP_BASE + 16;
|
|
250
|
+
export const OP_SEQ_REPLACE_RE_ALL = SEQ_OP_BASE + 17;
|
|
251
|
+
export const OP_SEQ_REPLACE_RE = SEQ_OP_BASE + 18;
|
|
252
|
+
export const OP_SEQ_REPLACE_ALL = SEQ_OP_BASE + 19;
|
|
253
|
+
export const OP_SEQ_MAP = SEQ_OP_BASE + 20;
|
|
254
|
+
export const OP_SEQ_MAPI = SEQ_OP_BASE + 21;
|
|
255
|
+
export const OP_SEQ_FOLDL = SEQ_OP_BASE + 22;
|
|
256
|
+
export const OP_SEQ_FOLDLI = SEQ_OP_BASE + 23;
|
|
257
|
+
export const OP_SEQ_POWER = SEQ_OP_BASE + 24;
|
|
258
|
+
export const OP_RE_PLUS = SEQ_OP_BASE + 25;
|
|
259
|
+
export const OP_RE_STAR = SEQ_OP_BASE + 26;
|
|
260
|
+
export const OP_RE_OPTION = SEQ_OP_BASE + 27;
|
|
261
|
+
export const OP_RE_RANGE = SEQ_OP_BASE + 28;
|
|
262
|
+
export const OP_RE_CONCAT = SEQ_OP_BASE + 29;
|
|
263
|
+
export const OP_RE_UNION = SEQ_OP_BASE + 30;
|
|
264
|
+
export const OP_RE_DIFF = SEQ_OP_BASE + 31;
|
|
265
|
+
export const OP_RE_INTERSECT = SEQ_OP_BASE + 32;
|
|
266
|
+
export const OP_RE_XOR = SEQ_OP_BASE + 33;
|
|
267
|
+
export const OP_RE_LOOP = SEQ_OP_BASE + 34;
|
|
268
|
+
export const OP_RE_POWER = SEQ_OP_BASE + 35;
|
|
269
|
+
export const OP_RE_COMPLEMENT = SEQ_OP_BASE + 36;
|
|
270
|
+
export const OP_RE_EMPTY_SET = SEQ_OP_BASE + 37;
|
|
271
|
+
export const OP_RE_FULL_SEQ_SET = SEQ_OP_BASE + 38;
|
|
272
|
+
export const OP_RE_FULL_CHAR_SET = SEQ_OP_BASE + 39;
|
|
273
|
+
export const OP_RE_OF_PRED = SEQ_OP_BASE + 40;
|
|
274
|
+
export const OP_RE_REVERSE = SEQ_OP_BASE + 41;
|
|
275
|
+
export const OP_RE_DERIVATIVE = SEQ_OP_BASE + 42;
|
|
276
|
+
export const OP_STRING_CONST = SEQ_OP_BASE + 43;
|
|
277
|
+
export const OP_STRING_ITOS = SEQ_OP_BASE + 44;
|
|
278
|
+
export const OP_STRING_STOI = SEQ_OP_BASE + 45;
|
|
279
|
+
export const OP_STRING_UBVTOS = SEQ_OP_BASE + 46;
|
|
280
|
+
export const OP_STRING_SBVTOS = SEQ_OP_BASE + 47;
|
|
281
|
+
export const OP_STRING_LT = SEQ_OP_BASE + 48;
|
|
282
|
+
export const OP_STRING_LE = SEQ_OP_BASE + 49;
|
|
283
|
+
export const OP_STRING_IS_DIGIT = SEQ_OP_BASE + 50;
|
|
284
|
+
export const OP_STRING_TO_CODE = SEQ_OP_BASE + 51;
|
|
285
|
+
export const OP_STRING_FROM_CODE = SEQ_OP_BASE + 52;
|
|
286
|
+
export const OP_INTERNAL_STRING_FROM_CHAR = SEQ_OP_BASE + 53;
|
|
287
|
+
export const OP_INTERNAL_STRING_STRREPL = SEQ_OP_BASE + 54;
|
|
288
|
+
export const OP_INTERNAL_STRING_CONCAT = SEQ_OP_BASE + 55;
|
|
289
|
+
export const OP_INTERNAL_STRING_LENGTH = SEQ_OP_BASE + 56;
|
|
290
|
+
export const OP_INTERNAL_STRING_STRCTN = SEQ_OP_BASE + 57;
|
|
291
|
+
export const OP_INTERNAL_STRING_PREFIX = SEQ_OP_BASE + 58;
|
|
292
|
+
export const OP_INTERNAL_STRING_SUFFIX = SEQ_OP_BASE + 59;
|
|
293
|
+
export const OP_INTERNAL_STRING_IN_REGEXP = SEQ_OP_BASE + 60;
|
|
294
|
+
export const OP_INTERNAL_STRING_TO_REGEXP = SEQ_OP_BASE + 61;
|
|
295
|
+
export const OP_INTERNAL_STRING_CHARAT = SEQ_OP_BASE + 62;
|
|
296
|
+
export const OP_INTERNAL_STRING_SUBSTR = SEQ_OP_BASE + 63;
|
|
297
|
+
export const OP_INTERNAL_STRING_STRIDOF = SEQ_OP_BASE + 64;
|
|
298
|
+
export const OP_INTERNAL_STRING_POWER = SEQ_OP_BASE + 65;
|
|
299
|
+
export const OP_INTERNAL_REGEXP_EMPTY = SEQ_OP_BASE + 66;
|
|
300
|
+
export const OP_INTERNAL_REGEXP_FULL_CHAR = SEQ_OP_BASE + 67;
|
|
301
|
+
export const OP_RE_IS_NULLABLE = SEQ_OP_BASE + 68;
|
|
302
|
+
export const OP_SEQ_SKOLEM = SEQ_OP_BASE + 69;
|
|
303
|
+
const CHAR_OP_BASE = 600;
|
|
304
|
+
export const OP_CHAR_CONST = CHAR_OP_BASE;
|
|
305
|
+
export const OP_CHAR_LE = CHAR_OP_BASE + 1;
|
|
306
|
+
export const OP_CHAR_TO_INT = CHAR_OP_BASE + 2;
|
|
307
|
+
export const OP_CHAR_TO_BV = CHAR_OP_BASE + 3;
|
|
308
|
+
export const OP_CHAR_FROM_BV = CHAR_OP_BASE + 4;
|
|
309
|
+
export const OP_CHAR_IS_DIGIT = CHAR_OP_BASE + 5;
|
|
310
|
+
const LABEL_OP_BASE = 700;
|
|
311
|
+
export const OP_LABEL = LABEL_OP_BASE;
|
|
312
|
+
export const OP_LABEL_LIT = LABEL_OP_BASE + 1;
|
|
313
|
+
const PB_OP_BASE = 800;
|
|
314
|
+
export const OP_AT_MOST_K = PB_OP_BASE;
|
|
315
|
+
export const OP_AT_LEAST_K = PB_OP_BASE + 1;
|
|
316
|
+
export const OP_PB_LE = PB_OP_BASE + 2;
|
|
317
|
+
export const OP_PB_GE = PB_OP_BASE + 3;
|
|
318
|
+
export const OP_PB_EQ = PB_OP_BASE + 4;
|
|
319
|
+
const RECFUN_OP_BASE = 900;
|
|
320
|
+
export const OP_FUN_DEFINED = RECFUN_OP_BASE;
|
|
321
|
+
export const OP_FUN_CASE_PRED = RECFUN_OP_BASE + 1;
|
|
322
|
+
export const OP_NUM_ROUNDS = RECFUN_OP_BASE + 2;
|
|
323
|
+
|
|
324
|
+
// The number of elements of a sort, with -1 for an infinite sort and -2 for a very big one.
|
|
325
|
+
export const SORT_SIZE_INFINITE = -1n;
|
|
326
|
+
export const SORT_SIZE_VERY_BIG = -2n;
|
|
327
|
+
|
|
328
|
+
const UNCACHED_BV_OPS: ReadonlySet<number> = new Set([
|
|
329
|
+
OP_CONCAT,
|
|
330
|
+
OP_SIGN_EXT,
|
|
331
|
+
OP_ZERO_EXT,
|
|
332
|
+
OP_EXTRACT,
|
|
333
|
+
OP_REPEAT,
|
|
334
|
+
OP_ROTATE_LEFT,
|
|
335
|
+
OP_ROTATE_RIGHT,
|
|
336
|
+
]);
|
|
59
337
|
|
|
60
|
-
// A Z3 symbol: a string, or a number for a numerical symbol, which Z3 prints as k!n.
|
|
61
338
|
export type SmtSymbol = string | number;
|
|
62
339
|
|
|
63
|
-
const getSymbolName = (symbol: SmtSymbol) =>
|
|
340
|
+
export const getSymbolName = (symbol: SmtSymbol) =>
|
|
341
|
+
typeof symbol === "number" ? `k!${symbol}` : symbol;
|
|
64
342
|
|
|
65
343
|
export interface FuncDecl {
|
|
66
344
|
name: SmtSymbol;
|
|
@@ -69,20 +347,36 @@ export interface FuncDecl {
|
|
|
69
347
|
domain: number[];
|
|
70
348
|
range: number;
|
|
71
349
|
isSkolem: boolean;
|
|
72
|
-
// Z3's small id of the declaration, which its matcher hashes.
|
|
73
350
|
smallId: number;
|
|
351
|
+
parameters: number[];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// The rhs of a definition is -1 until its body is parsed.
|
|
355
|
+
export interface RecFunDef {
|
|
356
|
+
decl: number;
|
|
357
|
+
rhs: number;
|
|
358
|
+
isMacro: boolean;
|
|
359
|
+
cases: RecFunCase[];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface RecFunCase {
|
|
363
|
+
pred: number;
|
|
364
|
+
guards: number[];
|
|
365
|
+
rhs: number;
|
|
366
|
+
isImmediate: boolean;
|
|
367
|
+
def: RecFunDef;
|
|
74
368
|
}
|
|
75
369
|
|
|
76
370
|
interface QuantifierData {
|
|
77
|
-
|
|
371
|
+
kind: number;
|
|
78
372
|
sorts: number[];
|
|
79
|
-
// The names of the variables, which tell apart quantifiers that differ only in them, as in Z3.
|
|
80
373
|
names: SmtSymbol[];
|
|
81
374
|
body: number;
|
|
82
|
-
// Applications of the pattern declaration to the terms of each multi-pattern.
|
|
83
375
|
patterns: number[];
|
|
376
|
+
noPatterns: number[];
|
|
84
377
|
weight: number;
|
|
85
378
|
qid: string;
|
|
379
|
+
skid?: string;
|
|
86
380
|
}
|
|
87
381
|
|
|
88
382
|
const BUILTIN_DECLS: [string, number, number, number][] = [
|
|
@@ -116,18 +410,51 @@ const BUILTIN_DECLS: [string, number, number, number][] = [
|
|
|
116
410
|
["/0", FAMILY_ARITH, OP_DIV0, SORT_REAL],
|
|
117
411
|
["div0", FAMILY_ARITH, OP_IDIV0, SORT_INT],
|
|
118
412
|
["mod0", FAMILY_ARITH, OP_MOD0, SORT_INT],
|
|
413
|
+
["^", FAMILY_ARITH, OP_POWER, SORT_REAL],
|
|
414
|
+
["^0", FAMILY_ARITH, OP_POWER0, SORT_REAL],
|
|
415
|
+
["sin", FAMILY_ARITH, OP_SIN, SORT_REAL],
|
|
416
|
+
["cos", FAMILY_ARITH, OP_COS, SORT_REAL],
|
|
417
|
+
["tan", FAMILY_ARITH, OP_TAN, SORT_REAL],
|
|
418
|
+
["asin", FAMILY_ARITH, OP_ASIN, SORT_REAL],
|
|
419
|
+
["acos", FAMILY_ARITH, OP_ACOS, SORT_REAL],
|
|
420
|
+
["atan", FAMILY_ARITH, OP_ATAN, SORT_REAL],
|
|
421
|
+
["sinh", FAMILY_ARITH, OP_SINH, SORT_REAL],
|
|
422
|
+
["cosh", FAMILY_ARITH, OP_COSH, SORT_REAL],
|
|
423
|
+
["tanh", FAMILY_ARITH, OP_TANH, SORT_REAL],
|
|
424
|
+
["asinh", FAMILY_ARITH, OP_ASINH, SORT_REAL],
|
|
425
|
+
["acosh", FAMILY_ARITH, OP_ACOSH, SORT_REAL],
|
|
426
|
+
["atanh", FAMILY_ARITH, OP_ATANH, SORT_REAL],
|
|
427
|
+
["exp", FAMILY_ARITH, OP_EXP, SORT_REAL],
|
|
428
|
+
["atan2", FAMILY_ARITH, OP_ATAN2, SORT_REAL],
|
|
429
|
+
["log", FAMILY_ARITH, OP_LOG, SORT_REAL],
|
|
430
|
+
["pi", FAMILY_ARITH, OP_PI, SORT_REAL],
|
|
431
|
+
["euler", FAMILY_ARITH, OP_E, SORT_REAL],
|
|
432
|
+
["RootObject", FAMILY_ARITH, OP_ALGEBRAIC_NUM, SORT_REAL],
|
|
433
|
+
["rem", FAMILY_ARITH, OP_REM, SORT_INT],
|
|
434
|
+
["neg-root", FAMILY_ARITH, OP_NEG_ROOT, SORT_REAL],
|
|
435
|
+
["asin-u", FAMILY_ARITH, OP_U_ASIN, SORT_REAL],
|
|
436
|
+
["acos-u", FAMILY_ARITH, OP_U_ACOS, SORT_REAL],
|
|
119
437
|
];
|
|
120
438
|
|
|
121
|
-
// Z3's family ids and decl kinds, which its AST hashes include.
|
|
122
439
|
const Z3_BASIC_FAMILY = 0;
|
|
440
|
+
const Z3_LABEL_FAMILY = 1;
|
|
123
441
|
const Z3_PATTERN_FAMILY = 2;
|
|
124
442
|
const Z3_MODEL_VALUE_FAMILY = 3;
|
|
125
443
|
const Z3_USER_SORT_FAMILY = 4;
|
|
126
444
|
const Z3_ARITH_FAMILY = 5;
|
|
445
|
+
const Z3_BV_FAMILY = 8;
|
|
446
|
+
const Z3_ARRAY_FAMILY = 9;
|
|
447
|
+
const Z3_DATATYPE_FAMILY = 7;
|
|
127
448
|
const Z3_RECFUN_FAMILY = 10;
|
|
449
|
+
const Z3_CHAR_FAMILY = 11;
|
|
450
|
+
const Z3_SEQ_FAMILY = 12;
|
|
451
|
+
const Z3_PB_FAMILY = 13;
|
|
452
|
+
const Z3_FPA_FAMILY = 14;
|
|
453
|
+
const Z3_SEQ_SORT = 0;
|
|
454
|
+
const Z3_RE_SORT = 1;
|
|
455
|
+
const Z3_FLOATING_POINT_SORT = 0;
|
|
456
|
+
const Z3_ROUNDING_MODE_SORT = 1;
|
|
128
457
|
const Z3_NULL = 0xffffffff;
|
|
129
|
-
// The name, Z3 decl kind and arity of each builtin, whose Z3 declaration has this many arguments
|
|
130
|
-
// whatever the number of arguments of the application (-1 for the arguments' own number).
|
|
131
458
|
const Z3_BUILTINS = new Map<number, [string, number, number]>([
|
|
132
459
|
[OP_TRUE, ["true", 0, 0]],
|
|
133
460
|
[OP_FALSE, ["false", 1, 0]],
|
|
@@ -149,6 +476,7 @@ const Z3_BUILTINS = new Map<number, [string, number, number]>([
|
|
|
149
476
|
[OP_MUL, ["*", 9, 2]],
|
|
150
477
|
[OP_IDIV, ["div", 11, 2]],
|
|
151
478
|
[OP_MOD, ["mod", 16, 2]],
|
|
479
|
+
[OP_REM, ["rem", 15, 2]],
|
|
152
480
|
[OP_ABS, ["abs", 21, 1]],
|
|
153
481
|
[OP_PATTERN, ["pattern", 0, -1]],
|
|
154
482
|
[OP_DIV, ["/", 10, 2]],
|
|
@@ -158,13 +486,30 @@ const Z3_BUILTINS = new Map<number, [string, number, number]>([
|
|
|
158
486
|
[OP_DIV0, ["/0", 12, 2]],
|
|
159
487
|
[OP_IDIV0, ["div0", 13, 2]],
|
|
160
488
|
[OP_MOD0, ["mod0", 17, 2]],
|
|
489
|
+
[OP_POWER, ["^", 22, 2]],
|
|
490
|
+
[OP_POWER0, ["^0", 23, 2]],
|
|
491
|
+
[OP_SIN, ["sin", 24, 1]],
|
|
492
|
+
[OP_COS, ["cos", 25, 1]],
|
|
493
|
+
[OP_TAN, ["tan", 26, 1]],
|
|
494
|
+
[OP_ASIN, ["asin", 27, 1]],
|
|
495
|
+
[OP_ACOS, ["acos", 28, 1]],
|
|
496
|
+
[OP_ATAN, ["atan", 29, 1]],
|
|
497
|
+
[OP_SINH, ["sinh", 30, 1]],
|
|
498
|
+
[OP_COSH, ["cosh", 31, 1]],
|
|
499
|
+
[OP_TANH, ["tanh", 32, 1]],
|
|
500
|
+
[OP_ASINH, ["asinh", 33, 1]],
|
|
501
|
+
[OP_ACOSH, ["acosh", 34, 1]],
|
|
502
|
+
[OP_ATANH, ["atanh", 35, 1]],
|
|
503
|
+
[OP_EXP, ["exp", 36, 1]],
|
|
504
|
+
[OP_ATAN2, ["atan2", 37, 2]],
|
|
505
|
+
[OP_LOG, ["log", 38, 1]],
|
|
506
|
+
[OP_PI, ["pi", 43, 0]],
|
|
507
|
+
[OP_E, ["euler", 44, 0]],
|
|
508
|
+
[OP_NEG_ROOT, ["neg-root", 45, 2]],
|
|
509
|
+
[OP_U_ASIN, ["asin-u", 46, 1]],
|
|
510
|
+
[OP_U_ACOS, ["acos-u", 47, 1]],
|
|
161
511
|
]);
|
|
162
512
|
|
|
163
|
-
// The small ids of the Int declarations Z3 makes when it starts, from arith_decl_plugin::set_manager,
|
|
164
|
-
// which Real terms share. The declarations of Real terms only have the ids of Real's /, Int's
|
|
165
|
-
// to_real, Real's to_int and is_int. Z3 makes =, ite, distinct, pattern, numeral, /0, div0 and mod0
|
|
166
|
-
// declarations per signature on first use, so they get -1 here, and their small ids are kept by
|
|
167
|
-
// signature.
|
|
168
513
|
const Z3_SMALL_IDS = new Map([
|
|
169
514
|
[OP_TRUE, 1],
|
|
170
515
|
[OP_FALSE, 2],
|
|
@@ -181,6 +526,7 @@ const Z3_SMALL_IDS = new Map([
|
|
|
181
526
|
[OP_SUB, 37],
|
|
182
527
|
[OP_MUL, 38],
|
|
183
528
|
[OP_IDIV, 39],
|
|
529
|
+
[OP_REM, 40],
|
|
184
530
|
[OP_MOD, 41],
|
|
185
531
|
[OP_UMINUS, 42],
|
|
186
532
|
[OP_ABS, 50],
|
|
@@ -188,28 +534,42 @@ const Z3_SMALL_IDS = new Map([
|
|
|
188
534
|
[OP_TO_REAL, 43],
|
|
189
535
|
[OP_TO_INT, 45],
|
|
190
536
|
[OP_IS_INT, 47],
|
|
537
|
+
[OP_POWER, 48],
|
|
538
|
+
[OP_SIN, 52],
|
|
539
|
+
[OP_COS, 53],
|
|
540
|
+
[OP_TAN, 54],
|
|
541
|
+
[OP_ASIN, 55],
|
|
542
|
+
[OP_ACOS, 56],
|
|
543
|
+
[OP_ATAN, 57],
|
|
544
|
+
[OP_SINH, 58],
|
|
545
|
+
[OP_COSH, 59],
|
|
546
|
+
[OP_TANH, 60],
|
|
547
|
+
[OP_ASINH, 61],
|
|
548
|
+
[OP_ACOSH, 62],
|
|
549
|
+
[OP_ATANH, 63],
|
|
550
|
+
[OP_EXP, 64],
|
|
551
|
+
[OP_ATAN2, 65],
|
|
552
|
+
[OP_LOG, 66],
|
|
553
|
+
[OP_PI, 67],
|
|
554
|
+
[OP_E, 68],
|
|
555
|
+
[OP_NEG_ROOT, 69],
|
|
556
|
+
[OP_U_ASIN, 70],
|
|
557
|
+
[OP_U_ACOS, 71],
|
|
191
558
|
]);
|
|
192
559
|
|
|
193
|
-
// The small id of the first sort or declaration a problem declares, after Z3's own.
|
|
194
560
|
const FIRST_DECLARED_SMALL_ID = 143;
|
|
195
561
|
|
|
196
|
-
// The ids of Z3's own expressions when it starts: the undef proof, true and false, then pi, euler, a
|
|
197
|
-
// bit-vector numeral, fifteen real variables and a sum of two of them, which no problem shares.
|
|
198
562
|
const FIRST_FREE_ID = 22;
|
|
199
|
-
// MAX_SMALL_NUM_TO_CACHE: arith_decl_plugin holds the numerals below it once it makes them.
|
|
200
563
|
const MAX_SMALL_NUM_TO_CACHE = 16;
|
|
201
|
-
// The sorts that finite_set_decl_plugin::init makes.
|
|
202
564
|
const NUM_FINITE_SET_PLUGIN_SORTS = 7;
|
|
203
565
|
|
|
204
|
-
|
|
205
|
-
|
|
566
|
+
const PB_OP_NAMES = ["at-most", "at-least", "pble", "pbge", "pbeq"];
|
|
567
|
+
|
|
568
|
+
export const getSymbolHash = (symbol: SmtSymbol) =>
|
|
206
569
|
typeof symbol === "number" ? symbol : stringHash(symbol, 17);
|
|
207
570
|
|
|
208
|
-
// Whether a sort is Int or Real.
|
|
209
571
|
export const isArithSort = (sort: number) => sort === SORT_INT || sort === SORT_REAL;
|
|
210
572
|
|
|
211
|
-
// mpz_manager::hash: the absolute value of an integer below 2^32, else the hash of its 32-bit digits,
|
|
212
|
-
// least significant first.
|
|
213
573
|
const getIntegerHash = (value: bigint) => {
|
|
214
574
|
const magnitude = value < 0n ? -value : value;
|
|
215
575
|
if (magnitude <= 0xffffffffn) return Number(magnitude);
|
|
@@ -218,115 +578,154 @@ const getIntegerHash = (value: bigint) => {
|
|
|
218
578
|
return bytesHash(new Uint8Array(Uint32Array.from(digits).buffer), 17);
|
|
219
579
|
};
|
|
220
580
|
|
|
221
|
-
// decl_info::hash.
|
|
222
581
|
const getInfoHash = (family: number, kind: number, parameterHashes: number[]) =>
|
|
223
582
|
mkMix(family, kind, parameterHashes.length === 0 ? 0 : getCompositeHash(parameterHashes));
|
|
224
583
|
|
|
225
|
-
// The kinds of an integer signature, in its low three bits.
|
|
226
584
|
const SIGNATURE_EQ = 0;
|
|
227
585
|
const SIGNATURE_ITE = 1;
|
|
228
586
|
const SIGNATURE_DIV0 = 2;
|
|
229
587
|
const SIGNATURE_MODEL_VALUE = 3;
|
|
230
588
|
const SIGNATURE_NUMERAL = 4;
|
|
589
|
+
const SIGNATURE_ALGEBRAIC = 5;
|
|
590
|
+
|
|
591
|
+
interface AlgebraicNumeral {
|
|
592
|
+
value: Anum;
|
|
593
|
+
id: number;
|
|
594
|
+
}
|
|
231
595
|
|
|
232
|
-
// A builtin declaration that Z3 makes once per signature: its small id, and the references that
|
|
233
|
-
// applications and model values hold to it.
|
|
234
596
|
interface SignatureDecl {
|
|
235
597
|
smallId: number;
|
|
236
598
|
refCount: number;
|
|
237
599
|
}
|
|
238
600
|
|
|
601
|
+
const hasOwnDeclHash = (family: number) =>
|
|
602
|
+
family === FAMILY_USER ||
|
|
603
|
+
family === FAMILY_BV ||
|
|
604
|
+
family === FAMILY_ARRAY ||
|
|
605
|
+
family === FAMILY_DATATYPE ||
|
|
606
|
+
family === FAMILY_FPA ||
|
|
607
|
+
family === FAMILY_CHAR ||
|
|
608
|
+
family === FAMILY_SEQ ||
|
|
609
|
+
family === FAMILY_LABEL ||
|
|
610
|
+
family === FAMILY_PB ||
|
|
611
|
+
family === FAMILY_RECFUN;
|
|
612
|
+
|
|
613
|
+
// The declarations that Z3 makes once and counts references to, rather than on each use.
|
|
614
|
+
const isDeclaredFamily = (family: number) => family === FAMILY_USER || family === FAMILY_RECFUN;
|
|
615
|
+
|
|
239
616
|
export class AstManager {
|
|
240
|
-
// The tables of the expressions are typed arrays indexed by expression, which the collector does
|
|
241
|
-
// not scan. They have room for more expressions than numNodes and double when full, which
|
|
242
|
-
// replaces them, so a caller does not keep one across the creation of an expression.
|
|
243
617
|
private numNodes = 0;
|
|
244
618
|
kinds = new Uint8Array(1024);
|
|
245
|
-
// The declaration of an application.
|
|
246
619
|
decls = new Int32Array(1024);
|
|
247
|
-
// The arguments of every expression end to end: those of expr are argPool[argStarts[expr]] up to
|
|
248
|
-
// argPool[argStarts[expr + 1]]. Variables and constants take an empty range and a quantifier
|
|
249
|
-
// takes its body. Both grow by doubling, which replaces the arrays.
|
|
250
620
|
private argPool = new Int32Array(1024);
|
|
251
621
|
private argStarts = new Int32Array(1024);
|
|
252
622
|
sorts = new Int32Array(1024);
|
|
253
|
-
// The index of a variable or model value, or of a numeral's value in numeralValues.
|
|
254
623
|
values = new Int32Array(1024);
|
|
255
624
|
private numeralValues: Rational[] = [];
|
|
256
|
-
//
|
|
625
|
+
// An irrational numeral is never shared: each takes a fresh id, which its deletion frees.
|
|
626
|
+
private algebraicNumerals: AlgebraicNumeral[] = [];
|
|
627
|
+
private freeAlgebraicIds: number[] = [];
|
|
628
|
+
private nextAlgebraicId = 0;
|
|
629
|
+
private algebraicManager: AlgebraicManager | undefined;
|
|
257
630
|
private intNumerals = new Map<bigint, number>();
|
|
258
|
-
// One more than the largest free de Bruijn index, so 0 means the expression is ground.
|
|
259
631
|
freeVarBounds = new Int32Array(1024);
|
|
260
632
|
hasQuantifierFlags = new Uint8Array(1024);
|
|
633
|
+
hasLabelFlags = new Uint8Array(1024);
|
|
261
634
|
depths = new Int32Array(1024);
|
|
262
|
-
// Z3's hash of each expression, which orders Z3's hash tables.
|
|
263
635
|
hashes = new Uint32Array(1024);
|
|
264
636
|
quantifiers = new Map<number, QuantifierData>();
|
|
265
|
-
// The marks that the rewriters of this manager share to flatten conjunctions and disjunctions.
|
|
266
637
|
readonly flatLiterals = new FlatLiterals(this);
|
|
267
638
|
funcDecls: FuncDecl[] = [];
|
|
268
639
|
sortNames: string[] = ["Bool", "Int", "Real"];
|
|
640
|
+
private sortFamilies: number[] = [FAMILY_BASIC, FAMILY_ARITH, FAMILY_ARITH];
|
|
641
|
+
private sortWidths: number[] = [0, 0, 0];
|
|
642
|
+
private sortSbits: number[] = [0, 0, 0];
|
|
643
|
+
private sortParameters: number[][] = [[], [], []];
|
|
644
|
+
private sortSizes: bigint[] = [2n, SORT_SIZE_INFINITE, SORT_SIZE_INFINITE];
|
|
645
|
+
private arraySorts = new Map<string, number>();
|
|
646
|
+
private arrayDecls = new Map<string, number>();
|
|
647
|
+
readonly datatypeDefs = new Map<string, DatatypeDef>();
|
|
648
|
+
hasNestedRecDatatype = false;
|
|
649
|
+
datatypeConstructors: number[][] = [];
|
|
650
|
+
constructorAccessors: number[][] = [];
|
|
651
|
+
constructorRecognizers: number[] = [];
|
|
652
|
+
nonRecConstructors: number[] = [];
|
|
653
|
+
nonRecDepths: number[] = [];
|
|
654
|
+
private parametricSorts = new Map<string, number>();
|
|
655
|
+
private datatypeDecls = new Map<string, number>();
|
|
656
|
+
private userSortKinds = new Map<SmtSymbol, number>();
|
|
657
|
+
private sortSmallIds: number[] = [];
|
|
658
|
+
private typeParameters: number[] = [];
|
|
659
|
+
private numUserSorts = 0;
|
|
660
|
+
private bvSorts = new Map<number, number>();
|
|
661
|
+
private bvDecls = new Map<string, number>();
|
|
662
|
+
private fpSorts = new Map<string, number>();
|
|
663
|
+
private rmSort = -1;
|
|
664
|
+
private fpaDecls = new Map<string, number>();
|
|
665
|
+
private labelDecls = new Map<string, number>();
|
|
666
|
+
private pbDecls = new Map<string, number>();
|
|
667
|
+
// The parameters of a pseudo-Boolean declaration: its bound, then a coefficient per argument.
|
|
668
|
+
private pbParameters = new Map<number, Rational[]>();
|
|
669
|
+
// The names of the labels, which the parameters of a label declaration index.
|
|
670
|
+
private labelNames: string[] = [];
|
|
671
|
+
private labelNameIds = new Map<string, number>();
|
|
672
|
+
private fpValues: Mpf[] = [];
|
|
673
|
+
private fpValueIds = new Map<string, number>();
|
|
674
|
+
private charSort = -1;
|
|
675
|
+
private stringSort = -1;
|
|
676
|
+
private reglanSort = -1;
|
|
677
|
+
private seqSorts = new Map<string, number>();
|
|
678
|
+
private seqDecls = new Map<string, number>();
|
|
679
|
+
private stringValues: number[][] = [];
|
|
680
|
+
private stringValueIds = new Map<string, number>();
|
|
269
681
|
private sortHashes = [
|
|
270
682
|
combineHash(getSymbolHash("Bool"), getInfoHash(Z3_BASIC_FAMILY, 0, [])),
|
|
271
683
|
combineHash(getSymbolHash("Int"), getInfoHash(Z3_ARITH_FAMILY, 1, [])),
|
|
272
684
|
combineHash(getSymbolHash("Real"), getInfoHash(Z3_ARITH_FAMILY, 0, [])),
|
|
273
685
|
];
|
|
274
|
-
// The hash of each uninterpreted declaration, and of each builtin by its Z3 declaration.
|
|
275
686
|
private declHashes: number[] = [];
|
|
276
|
-
// The hash of each builtin declaration other than pattern by op, argument sort, range and number
|
|
277
|
-
// of arguments: open addressing with linear probing, with the four keys of slot i at 4 i in
|
|
278
|
-
// builtinKeys and -1 for an empty slot.
|
|
279
687
|
private builtinKeys = new Int32Array(4 * 256).fill(-1);
|
|
280
688
|
private builtinHashes = new Uint32Array(256);
|
|
281
689
|
private numBuiltinHashes = 0;
|
|
282
|
-
// The hash of each pattern declaration by its domain and range.
|
|
283
690
|
private patternHashes = new Map<string, number>();
|
|
284
691
|
private table = new Map<string, number>();
|
|
285
|
-
// The hash-consing table of applications: open addressing with linear probing over the handles,
|
|
286
|
-
// -1 for an empty slot, which takes a few bytes per application where a map of buckets takes
|
|
287
|
-
// dozens. Applications stay in it when they are deleted, so a lookup can create them again.
|
|
288
692
|
private appHandles = new Int32Array(1024).fill(-1);
|
|
289
693
|
private appHashes = new Int32Array(1024);
|
|
290
694
|
private numApps = 0;
|
|
291
|
-
// id_gen for sorts and declarations: the small id of the next one, and the ids of deleted ones,
|
|
292
|
-
// which Z3 reuses the last freed first. Z3 keeps the declarations of = and ite, and deletes the
|
|
293
|
-
// others with their last reference.
|
|
294
695
|
private nextSmallId = FIRST_DECLARED_SMALL_ID;
|
|
295
696
|
private freeSmallIds: number[] = [];
|
|
296
697
|
private numDecls = FIRST_DECLARED_SMALL_ID;
|
|
297
|
-
// The small id and the number of live applications of each builtin declaration that Z3 makes
|
|
298
|
-
// per signature, by its signature.
|
|
299
698
|
private signatureDecls = new Map<number | string, SignatureDecl>();
|
|
300
|
-
// The references to each user declaration: the script holds the declared ones, and applications
|
|
301
|
-
// and models hold the fresh ones. A deleted declaration keeps its small id here, in case an
|
|
302
|
-
// application of it is created again.
|
|
303
699
|
private declRefCounts: number[] = [];
|
|
304
|
-
// The named expressions of the recfun plugin, by declaration.
|
|
305
700
|
readonly macros = new ObjMap<number>((decl) => this.declHashes[decl]);
|
|
701
|
+
// The recfun plugin's definitions by declaration, and their cases by case predicate.
|
|
702
|
+
readonly recFunDefs = new ObjMap<RecFunDef>((decl) => this.declHashes[decl]);
|
|
703
|
+
readonly recFunCases = new Map<number, RecFunCase>();
|
|
704
|
+
hasRecDefs = false;
|
|
705
|
+
private numRoundsDecls = new Map<number, number>();
|
|
306
706
|
private deletedDecls = new Set<number>();
|
|
307
|
-
// ast_manager::m_fresh_id, which numbers fresh declarations and variable names.
|
|
308
707
|
private freshId = 0;
|
|
309
|
-
// Z3's id of each expression, which orders Z3's sorts. Like Z3, the manager counts references and
|
|
310
|
-
// gives the id of a deleted expression to the next expression it creates, so its ids follow
|
|
311
|
-
// Z3's. A deleted expression stays in the tables with the id -1 until it is created again.
|
|
312
708
|
ids = new Int32Array(1024);
|
|
313
709
|
private refCounts = new Int32Array(1024);
|
|
314
710
|
private freeIds: number[] = [];
|
|
315
711
|
private nextId = 1;
|
|
316
712
|
private numLive = 0;
|
|
317
|
-
// The expressions that the open withTemporaries hold, like the expr_ref temporaries of Z3
|
|
318
|
-
// functions on the C++ stack: the innermost holds those from temporariesMark on, and -1 marks that
|
|
319
|
-
// no temporaries are held.
|
|
320
713
|
private temporaries: number[] = [];
|
|
321
714
|
private temporariesMark = -1;
|
|
322
|
-
// The arguments mkApp copies out of a caller's array that starts past index 0.
|
|
323
715
|
private argBuffer: number[] = [];
|
|
324
|
-
// m_small_ints and m_small_reals: the numerals below MAX_SMALL_NUM_TO_CACHE, which are held.
|
|
325
716
|
private smallInts: number[] = [];
|
|
326
717
|
private smallReals: number[] = [];
|
|
327
|
-
|
|
718
|
+
// The finite set plugin makes the only type variables, so this is set once it is initialized.
|
|
719
|
+
hasTypeVars = false;
|
|
328
720
|
readonly trueExpr: number;
|
|
329
721
|
readonly falseExpr: number;
|
|
722
|
+
readonly piExpr: number;
|
|
723
|
+
readonly eulerExpr: number;
|
|
724
|
+
isHiDiv0 = true;
|
|
725
|
+
maxChar = 196607;
|
|
726
|
+
charBits = 18;
|
|
727
|
+
isSeqUsed = false;
|
|
728
|
+
isReUsed = false;
|
|
330
729
|
|
|
331
730
|
constructor(readonly limit: ResourceLimit) {
|
|
332
731
|
for (const builtin of BUILTIN_DECLS)
|
|
@@ -338,11 +737,16 @@ export class AstManager {
|
|
|
338
737
|
range: builtin[3],
|
|
339
738
|
isSkolem: false,
|
|
340
739
|
smallId: Z3_SMALL_IDS.get(builtin[2]) ?? -1,
|
|
740
|
+
parameters: [],
|
|
341
741
|
});
|
|
342
742
|
this.trueExpr = this.mkApp(OP_TRUE, [], SORT_BOOL);
|
|
343
743
|
this.falseExpr = this.mkApp(OP_FALSE, [], SORT_BOOL);
|
|
344
744
|
this.incRef(this.trueExpr);
|
|
345
745
|
this.incRef(this.falseExpr);
|
|
746
|
+
this.piExpr = this.mkApp(OP_PI, [], SORT_REAL);
|
|
747
|
+
this.eulerExpr = this.mkApp(OP_E, [], SORT_REAL);
|
|
748
|
+
this.incRef(this.piExpr);
|
|
749
|
+
this.incRef(this.eulerExpr);
|
|
346
750
|
this.nextId = FIRST_FREE_ID;
|
|
347
751
|
}
|
|
348
752
|
|
|
@@ -350,12 +754,10 @@ export class AstManager {
|
|
|
350
754
|
return this.refCounts[expr];
|
|
351
755
|
}
|
|
352
756
|
|
|
353
|
-
// get_num_asts: the live expressions, declarations and sorts, with Z3's own expressions.
|
|
354
757
|
getNumAsts() {
|
|
355
|
-
return this.numLive + FIRST_FREE_ID -
|
|
758
|
+
return this.numLive + FIRST_FREE_ID - 4 + this.numDecls;
|
|
356
759
|
}
|
|
357
760
|
|
|
358
|
-
// The declaration that a held signature names.
|
|
359
761
|
private getSignatureDecl(key: number | string) {
|
|
360
762
|
const signatureDecl = this.signatureDecls.get(key);
|
|
361
763
|
if (signatureDecl === undefined)
|
|
@@ -368,20 +770,14 @@ export class AstManager {
|
|
|
368
770
|
return this.freeSmallIds.pop() ?? this.nextSmallId++;
|
|
369
771
|
}
|
|
370
772
|
|
|
371
|
-
// finite_set_decl_plugin::init, which the first final check of theory_finite_set runs when it
|
|
372
|
-
// makes a set.range declaration: the plugin makes the sorts A and B, three FiniteSet sorts and two
|
|
373
|
-
// Array sorts, which the manager keeps. The set.range declaration is released at once.
|
|
374
773
|
initFiniteSetPlugin() {
|
|
375
|
-
if (this.
|
|
376
|
-
this.
|
|
774
|
+
if (this.hasTypeVars) return;
|
|
775
|
+
this.hasTypeVars = true;
|
|
377
776
|
for (let index = 0; index < NUM_FINITE_SET_PLUGIN_SORTS; index++) this.mkSmallId();
|
|
378
777
|
this.freeSmallIds.push(this.mkSmallId());
|
|
379
778
|
this.numDecls--;
|
|
380
779
|
}
|
|
381
780
|
|
|
382
|
-
// insert_macro: cmd_context keeps a named expression as a recursive function with one case, whose
|
|
383
|
-
// declaration and case predicate it holds. The recfun plugin maps the declaration to the
|
|
384
|
-
// expression, which a model of the context takes as the declaration's interpretation.
|
|
385
781
|
mkMacro(name: string, expr: number) {
|
|
386
782
|
const decl = this.funcDecls.length;
|
|
387
783
|
this.declHashes[decl] = this.getFuncDeclHash(
|
|
@@ -398,29 +794,84 @@ export class AstManager {
|
|
|
398
794
|
range: this.sorts[expr],
|
|
399
795
|
isSkolem: false,
|
|
400
796
|
smallId: this.mkSmallId(),
|
|
797
|
+
parameters: [],
|
|
401
798
|
});
|
|
402
799
|
this.declRefCounts[decl] = 1;
|
|
403
800
|
this.mkSmallId();
|
|
404
801
|
this.macros.set(decl, expr);
|
|
405
802
|
}
|
|
406
803
|
|
|
407
|
-
//
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
804
|
+
// recfun::def: the declaration of a defined function, which the definition holds.
|
|
805
|
+
mkRecFuncDecl(name: SmtSymbol, domain: number[], range: number) {
|
|
806
|
+
const decl = this.mkRecFunDecl(OP_FUN_DEFINED, name, [0], domain, range);
|
|
807
|
+
this.declRefCounts[decl] = 1;
|
|
808
|
+
this.recFunDefs.set(decl, { decl, rhs: -1, isMacro: false, cases: [] });
|
|
809
|
+
return decl;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// case_def: the predicate of a case, which the case holds.
|
|
813
|
+
mkRecFunCasePredDecl(def: number, index: number) {
|
|
814
|
+
const decl = this.mkRecFunDecl(
|
|
815
|
+
OP_FUN_CASE_PRED,
|
|
816
|
+
"case-def",
|
|
817
|
+
[index, def],
|
|
818
|
+
this.funcDecls[def].domain,
|
|
819
|
+
SORT_BOOL,
|
|
820
|
+
);
|
|
821
|
+
this.declRefCounts[decl] = 1;
|
|
822
|
+
return decl;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// mk_num_rounds_pred: Z3 makes the declaration again once its last application is deleted.
|
|
826
|
+
mkNumRoundsPred(round: number) {
|
|
827
|
+
let decl = this.numRoundsDecls.get(round);
|
|
828
|
+
if (decl === undefined) {
|
|
829
|
+
decl = this.mkRecFunDecl(OP_NUM_ROUNDS, "recfun-num-rounds", [round], [], SORT_BOOL);
|
|
830
|
+
this.declRefCounts[decl] = 0;
|
|
831
|
+
this.numRoundsDecls.set(round, decl);
|
|
832
|
+
}
|
|
833
|
+
return this.mkApp(decl, [], SORT_BOOL);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
private mkRecFunDecl(
|
|
837
|
+
op: number,
|
|
838
|
+
name: SmtSymbol,
|
|
839
|
+
parameters: number[],
|
|
840
|
+
domain: number[],
|
|
841
|
+
range: number,
|
|
842
|
+
) {
|
|
843
|
+
return this.addDecl(
|
|
844
|
+
name,
|
|
845
|
+
FAMILY_RECFUN,
|
|
846
|
+
op,
|
|
847
|
+
domain,
|
|
848
|
+
range,
|
|
849
|
+
parameters,
|
|
850
|
+
getInfoHash(
|
|
851
|
+
Z3_RECFUN_FAMILY,
|
|
852
|
+
op - RECFUN_OP_BASE,
|
|
853
|
+
op === OP_FUN_CASE_PRED ? [parameters[0], this.declHashes[parameters[1]]] : parameters,
|
|
854
|
+
),
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
|
|
411
858
|
private getSignature(expr: number) {
|
|
412
859
|
const decl = this.decls[expr];
|
|
413
|
-
if (decl === OP_NUM
|
|
860
|
+
if (decl === OP_NUM || this.funcDecls[decl].op === OP_BV_NUM)
|
|
861
|
+
return 8 * this.values[expr] + SIGNATURE_NUMERAL;
|
|
414
862
|
if (decl === OP_EQ) return 8 * this.sorts[this.getArg(expr, 0)] + SIGNATURE_EQ;
|
|
415
863
|
if (decl === OP_ITE) return 8 * this.sorts[expr] + SIGNATURE_ITE;
|
|
416
864
|
if (decl === OP_DIV0 || decl === OP_IDIV0 || decl === OP_MOD0) return 8 * decl + SIGNATURE_DIV0;
|
|
865
|
+
if (decl === OP_POWER0)
|
|
866
|
+
return 8 * (decl + 64 * this.sorts[this.getArg(expr, 0)]) + SIGNATURE_DIV0;
|
|
867
|
+
if (decl === OP_ALGEBRAIC_NUM) return 8 * this.getAlgebraicId(expr) + SIGNATURE_ALGEBRAIC;
|
|
417
868
|
if (decl === OP_DISTINCT || decl === OP_PATTERN)
|
|
418
869
|
return `${decl}:${this.mapArgs(expr, (arg) => this.sorts[arg]).join(",")}`;
|
|
419
870
|
if (this.funcDecls[decl].family === FAMILY_MODEL_VALUE) return 8 * decl + SIGNATURE_MODEL_VALUE;
|
|
871
|
+
if (UNCACHED_BV_OPS.has(this.funcDecls[decl].op)) return `bv${decl}`;
|
|
420
872
|
return null;
|
|
421
873
|
}
|
|
422
874
|
|
|
423
|
-
// The id that Z3 gives the declaration of an application.
|
|
424
875
|
getDeclId(expr: number) {
|
|
425
876
|
const signature = this.getSignature(expr);
|
|
426
877
|
return signature === null
|
|
@@ -428,10 +879,9 @@ export class AstManager {
|
|
|
428
879
|
: this.getSignatureDecl(signature).smallId;
|
|
429
880
|
}
|
|
430
881
|
|
|
431
|
-
// An application holds its declaration, which Z3 makes with its first application.
|
|
432
882
|
private holdDecl(expr: number) {
|
|
433
883
|
const decl = this.decls[expr];
|
|
434
|
-
if (this.funcDecls[decl].family
|
|
884
|
+
if (isDeclaredFamily(this.funcDecls[decl].family)) {
|
|
435
885
|
this.incDeclRef(decl);
|
|
436
886
|
return;
|
|
437
887
|
}
|
|
@@ -443,17 +893,14 @@ export class AstManager {
|
|
|
443
893
|
return;
|
|
444
894
|
}
|
|
445
895
|
const smallId = this.mkSmallId();
|
|
446
|
-
// Z3 keeps the equality and ite declarations once it makes them.
|
|
447
896
|
this.signatureDecls.set(key, { smallId, refCount: decl === OP_EQ || decl === OP_ITE ? 2 : 1 });
|
|
448
897
|
if (decl !== OP_NUM && this.funcDecls[decl].family === FAMILY_MODEL_VALUE)
|
|
449
898
|
this.funcDecls[decl].smallId = smallId;
|
|
450
899
|
}
|
|
451
900
|
|
|
452
|
-
// The small id of the declaration a deleted application releases for good, or -1 when the
|
|
453
|
-
// declaration stays.
|
|
454
901
|
private releaseDecl(expr: number) {
|
|
455
902
|
const decl = this.decls[expr];
|
|
456
|
-
if (this.funcDecls[decl].family
|
|
903
|
+
if (isDeclaredFamily(this.funcDecls[decl].family)) {
|
|
457
904
|
this.declRefCounts[decl]--;
|
|
458
905
|
if (this.declRefCounts[decl] > 0) return -1;
|
|
459
906
|
this.deletedDecls.add(decl);
|
|
@@ -472,7 +919,6 @@ export class AstManager {
|
|
|
472
919
|
this.refCounts[expr]++;
|
|
473
920
|
}
|
|
474
921
|
|
|
475
|
-
// A model value's declaration is counted under its signature, like the applications that hold it.
|
|
476
922
|
incDeclRef(decl: number) {
|
|
477
923
|
if (this.funcDecls[decl].family === FAMILY_MODEL_VALUE) {
|
|
478
924
|
const key = 8 * decl + SIGNATURE_MODEL_VALUE;
|
|
@@ -508,9 +954,6 @@ export class AstManager {
|
|
|
508
954
|
this.numDecls--;
|
|
509
955
|
}
|
|
510
956
|
|
|
511
|
-
// Runs body, holding each expression it creates until it returns, then releases them, the last
|
|
512
|
-
// created first. The caller gets a reference to each expression that getKept picks from the
|
|
513
|
-
// result, by default the result itself, and releases it.
|
|
514
957
|
withTemporaries<T>(
|
|
515
958
|
body: () => T,
|
|
516
959
|
getKept: (result: T) => number[] = (result) => [result as number],
|
|
@@ -522,8 +965,6 @@ export class AstManager {
|
|
|
522
965
|
return result;
|
|
523
966
|
}
|
|
524
967
|
|
|
525
|
-
// withTemporaries without closures, for the hot paths: the caller passes what beginTemporaries
|
|
526
|
-
// returns to endTemporaries, and takes its references before it.
|
|
527
968
|
beginTemporaries() {
|
|
528
969
|
const outer = this.temporariesMark;
|
|
529
970
|
this.temporariesMark = this.temporaries.length;
|
|
@@ -539,7 +980,6 @@ export class AstManager {
|
|
|
539
980
|
shrink(temporaries, mark);
|
|
540
981
|
}
|
|
541
982
|
|
|
542
|
-
// Runs body without temporaries, for code whose references are counted explicitly.
|
|
543
983
|
withoutTemporaries<T>(body: () => T) {
|
|
544
984
|
const outer = this.temporariesMark;
|
|
545
985
|
this.temporariesMark = -1;
|
|
@@ -548,15 +988,11 @@ export class AstManager {
|
|
|
548
988
|
return result;
|
|
549
989
|
}
|
|
550
990
|
|
|
551
|
-
// Hands a reference the caller owns to the innermost withTemporaries, or releases it now.
|
|
552
991
|
releaseLater(expr: number) {
|
|
553
992
|
if (this.temporariesMark === -1) this.decRef(expr);
|
|
554
993
|
else this.temporaries.push(expr);
|
|
555
994
|
}
|
|
556
995
|
|
|
557
|
-
// dec_ref and delete_node: an expression without references is deleted, and so are its children
|
|
558
|
-
// and declaration that lose their last reference, in the order of Z3's worklist. A released
|
|
559
|
-
// declaration's small id goes on the worklist as -1 - id.
|
|
560
996
|
decRef(expr: number) {
|
|
561
997
|
if (this.ids[expr] === -1) return;
|
|
562
998
|
this.refCounts[expr]--;
|
|
@@ -571,10 +1007,10 @@ export class AstManager {
|
|
|
571
1007
|
this.deleteNode(node);
|
|
572
1008
|
if (this.kinds[node] === KIND_APP) {
|
|
573
1009
|
const smallId = this.releaseDecl(node);
|
|
1010
|
+
if (this.decls[node] === OP_ALGEBRAIC_NUM)
|
|
1011
|
+
this.freeAlgebraicIds.push(this.getAlgebraicId(node));
|
|
574
1012
|
if (smallId !== -1) worklist.push(-1 - smallId);
|
|
575
1013
|
}
|
|
576
|
-
// The children: the arguments of an application, and the body and then the patterns of a
|
|
577
|
-
// quantifier.
|
|
578
1014
|
if (this.kinds[node] !== KIND_QUANTIFIER) {
|
|
579
1015
|
const end = this.argStarts[node + 1];
|
|
580
1016
|
for (let index = this.argStarts[node]; index < end; index++)
|
|
@@ -584,6 +1020,7 @@ export class AstManager {
|
|
|
584
1020
|
const data = this.getQuantifier(node);
|
|
585
1021
|
this.releaseChild(data.body, worklist);
|
|
586
1022
|
for (const pattern of data.patterns) this.releaseChild(pattern, worklist);
|
|
1023
|
+
for (const noPattern of data.noPatterns) this.releaseChild(noPattern, worklist);
|
|
587
1024
|
}
|
|
588
1025
|
}
|
|
589
1026
|
|
|
@@ -598,13 +1035,10 @@ export class AstManager {
|
|
|
598
1035
|
this.ids[expr] = -1;
|
|
599
1036
|
}
|
|
600
1037
|
|
|
601
|
-
// register_node_core: a new expression takes an id and a reference to each child.
|
|
602
1038
|
private registerNode(expr: number) {
|
|
603
1039
|
this.ids[expr] = this.freeIds.pop() ?? this.nextId++;
|
|
604
1040
|
this.numLive++;
|
|
605
1041
|
this.refCounts[expr] = 0;
|
|
606
|
-
// The children: the arguments of an application, and the body and then the patterns of a
|
|
607
|
-
// quantifier.
|
|
608
1042
|
if (this.kinds[expr] !== KIND_QUANTIFIER) {
|
|
609
1043
|
const end = this.argStarts[expr + 1];
|
|
610
1044
|
for (let index = this.argStarts[expr]; index < end; index++)
|
|
@@ -613,6 +1047,7 @@ export class AstManager {
|
|
|
613
1047
|
const data = this.getQuantifier(expr);
|
|
614
1048
|
this.incRef(this.revive(data.body));
|
|
615
1049
|
for (const pattern of data.patterns) this.incRef(this.revive(pattern));
|
|
1050
|
+
for (const noPattern of data.noPatterns) this.incRef(this.revive(noPattern));
|
|
616
1051
|
}
|
|
617
1052
|
if (this.kinds[expr] === KIND_APP) this.holdDecl(expr);
|
|
618
1053
|
if (this.temporariesMark === -1) return;
|
|
@@ -620,7 +1055,6 @@ export class AstManager {
|
|
|
620
1055
|
this.temporaries.push(expr);
|
|
621
1056
|
}
|
|
622
1057
|
|
|
623
|
-
// The arguments of an application, and the body of a quantifier as its one argument.
|
|
624
1058
|
getNumArgs(expr: number) {
|
|
625
1059
|
return this.argStarts[expr + 1] - this.argStarts[expr];
|
|
626
1060
|
}
|
|
@@ -629,20 +1063,17 @@ export class AstManager {
|
|
|
629
1063
|
return this.argPool[this.argStarts[expr] + index];
|
|
630
1064
|
}
|
|
631
1065
|
|
|
632
|
-
// Appends the arguments to target, for a caller that needs them as an array.
|
|
633
1066
|
pushArgs(expr: number, target: number[]) {
|
|
634
1067
|
const end = this.argStarts[expr + 1];
|
|
635
1068
|
for (let index = this.argStarts[expr]; index < end; index++) target.push(this.argPool[index]);
|
|
636
1069
|
}
|
|
637
1070
|
|
|
638
|
-
// A new array of the arguments.
|
|
639
1071
|
getArgs(expr: number) {
|
|
640
1072
|
const args: number[] = [];
|
|
641
1073
|
this.pushArgs(expr, args);
|
|
642
1074
|
return args;
|
|
643
1075
|
}
|
|
644
1076
|
|
|
645
|
-
// The callbacks may create expressions, which can replace argPool, so each argument is read anew.
|
|
646
1077
|
mapArgs<T>(expr: number, map: (arg: number, index: number) => T) {
|
|
647
1078
|
const result: T[] = [];
|
|
648
1079
|
for (let index = 0; index < this.getNumArgs(expr); index++)
|
|
@@ -662,25 +1093,631 @@ export class AstManager {
|
|
|
662
1093
|
return true;
|
|
663
1094
|
}
|
|
664
1095
|
|
|
665
|
-
// A lookup that finds a deleted expression creates it again.
|
|
666
1096
|
private revive(expr: number) {
|
|
667
|
-
if (this.ids[expr]
|
|
1097
|
+
if (this.ids[expr] !== -1) return expr;
|
|
1098
|
+
if (this.decls[expr] === OP_ALGEBRAIC_NUM)
|
|
1099
|
+
this.algebraicNumerals[this.values[expr]].id = this.mkAlgebraicId();
|
|
1100
|
+
this.registerNode(expr);
|
|
668
1101
|
return expr;
|
|
669
1102
|
}
|
|
670
1103
|
|
|
671
|
-
mkSort(name:
|
|
672
|
-
this.
|
|
1104
|
+
mkSort(name: SmtSymbol) {
|
|
1105
|
+
const sort = this.addSort(
|
|
1106
|
+
getSymbolName(name),
|
|
1107
|
+
FAMILY_USER,
|
|
1108
|
+
[],
|
|
673
1109
|
combineHash(
|
|
674
1110
|
getSymbolHash(name),
|
|
675
|
-
getInfoHash(Z3_USER_SORT_FAMILY, this.
|
|
1111
|
+
getInfoHash(Z3_USER_SORT_FAMILY, this.getUserSortKind(name), []),
|
|
1112
|
+
),
|
|
1113
|
+
);
|
|
1114
|
+
this.mkSmallId();
|
|
1115
|
+
return sort;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
mkBvSort(width: number) {
|
|
1119
|
+
const existing = this.bvSorts.get(width);
|
|
1120
|
+
if (existing !== undefined) return existing;
|
|
1121
|
+
const sort = this.addSort(
|
|
1122
|
+
"bv",
|
|
1123
|
+
FAMILY_BV,
|
|
1124
|
+
[],
|
|
1125
|
+
combineHash(getSymbolHash("bv"), getInfoHash(Z3_BV_FAMILY, 0, [width])),
|
|
1126
|
+
width,
|
|
1127
|
+
0,
|
|
1128
|
+
width < 64 ? 1n << BigInt(width) : SORT_SIZE_VERY_BIG,
|
|
1129
|
+
);
|
|
1130
|
+
// bv_decl_plugin makes the sorts up to 64 bits when Z3 starts.
|
|
1131
|
+
if (width > 64) this.mkSmallId();
|
|
1132
|
+
this.bvSorts.set(width, sort);
|
|
1133
|
+
return sort;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
mkFpSort(ebits: number, sbits: number) {
|
|
1137
|
+
const key = `${ebits}:${sbits}`;
|
|
1138
|
+
const existing = this.fpSorts.get(key);
|
|
1139
|
+
if (existing !== undefined) return existing;
|
|
1140
|
+
const sort = this.addSort(
|
|
1141
|
+
"FloatingPoint",
|
|
1142
|
+
FAMILY_FPA,
|
|
1143
|
+
[],
|
|
1144
|
+
combineHash(
|
|
1145
|
+
getSymbolHash("FloatingPoint"),
|
|
1146
|
+
getInfoHash(Z3_FPA_FAMILY, Z3_FLOATING_POINT_SORT, [ebits, sbits]),
|
|
1147
|
+
),
|
|
1148
|
+
ebits,
|
|
1149
|
+
sbits,
|
|
1150
|
+
SORT_SIZE_VERY_BIG,
|
|
1151
|
+
);
|
|
1152
|
+
this.mkSmallId();
|
|
1153
|
+
this.fpSorts.set(key, sort);
|
|
1154
|
+
return sort;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
mkRmSort() {
|
|
1158
|
+
if (this.rmSort !== -1) return this.rmSort;
|
|
1159
|
+
this.rmSort = this.addSort(
|
|
1160
|
+
"RoundingMode",
|
|
1161
|
+
FAMILY_FPA,
|
|
1162
|
+
[],
|
|
1163
|
+
combineHash(
|
|
1164
|
+
getSymbolHash("RoundingMode"),
|
|
1165
|
+
getInfoHash(Z3_FPA_FAMILY, Z3_ROUNDING_MODE_SORT, []),
|
|
676
1166
|
),
|
|
677
1167
|
);
|
|
678
|
-
this.sortNames.push(name);
|
|
679
1168
|
this.mkSmallId();
|
|
1169
|
+
return this.rmSort;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
isFpSort(sort: number) {
|
|
1173
|
+
return this.sortFamilies[sort] === FAMILY_FPA && sort !== this.rmSort;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
isRmSort(sort: number) {
|
|
1177
|
+
return sort === this.rmSort;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
getEbits(sort: number) {
|
|
1181
|
+
return this.sortWidths[sort];
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
getSbits(sort: number) {
|
|
1185
|
+
return this.sortSbits[sort];
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
private addDecl(
|
|
1189
|
+
name: SmtSymbol,
|
|
1190
|
+
family: number,
|
|
1191
|
+
op: number,
|
|
1192
|
+
domain: number[],
|
|
1193
|
+
range: number,
|
|
1194
|
+
parameters: number[],
|
|
1195
|
+
infoHash: number,
|
|
1196
|
+
hasSmallId = true,
|
|
1197
|
+
) {
|
|
1198
|
+
const decl = this.funcDecls.length;
|
|
1199
|
+
this.declHashes[decl] = this.getFuncDeclHash(name, domain, range, infoHash);
|
|
1200
|
+
this.funcDecls.push({
|
|
1201
|
+
name,
|
|
1202
|
+
family,
|
|
1203
|
+
op,
|
|
1204
|
+
domain,
|
|
1205
|
+
range,
|
|
1206
|
+
isSkolem: false,
|
|
1207
|
+
smallId: hasSmallId ? this.mkSmallId() : -1,
|
|
1208
|
+
parameters,
|
|
1209
|
+
});
|
|
1210
|
+
return decl;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
mkFpaDecl(op: number, name: string, parameters: number[], domain: number[], range: number) {
|
|
1214
|
+
const key = `${op}:${name}:${parameters.join(",")}:${domain.join(",")}:${range}`;
|
|
1215
|
+
const existing = this.fpaDecls.get(key);
|
|
1216
|
+
if (existing !== undefined) return existing;
|
|
1217
|
+
const decl = this.addDecl(
|
|
1218
|
+
name,
|
|
1219
|
+
FAMILY_FPA,
|
|
1220
|
+
op,
|
|
1221
|
+
domain,
|
|
1222
|
+
range,
|
|
1223
|
+
parameters,
|
|
1224
|
+
getInfoHash(Z3_FPA_FAMILY, op - FPA_OP_BASE, parameters),
|
|
1225
|
+
);
|
|
1226
|
+
this.fpaDecls.set(key, decl);
|
|
1227
|
+
return decl;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
// pb_decl_plugin::mk_func_decl: a parameter that fits in 32 bits is an integer, else a rational.
|
|
1231
|
+
mkPbDecl(op: number, parameters: Rational[], domain: number[]) {
|
|
1232
|
+
const key = `${op}:${parameters.join(",")}:${domain.join(",")}`;
|
|
1233
|
+
const existing = this.pbDecls.get(key);
|
|
1234
|
+
if (existing !== undefined) return existing;
|
|
1235
|
+
const decl = this.addDecl(
|
|
1236
|
+
PB_OP_NAMES[op - PB_OP_BASE],
|
|
1237
|
+
FAMILY_PB,
|
|
1238
|
+
op,
|
|
1239
|
+
domain,
|
|
1240
|
+
SORT_BOOL,
|
|
1241
|
+
[],
|
|
1242
|
+
getInfoHash(
|
|
1243
|
+
Z3_PB_FAMILY,
|
|
1244
|
+
op - PB_OP_BASE,
|
|
1245
|
+
parameters.map((parameter) =>
|
|
1246
|
+
parameter.isInt() && parameter.num >= -(2n ** 31n) && parameter.num < 2n ** 31n
|
|
1247
|
+
? Number(BigInt.asUintN(32, parameter.num))
|
|
1248
|
+
: (getIntegerHash(parameter.num) + 3 * getIntegerHash(parameter.den)) >>> 0,
|
|
1249
|
+
),
|
|
1250
|
+
),
|
|
1251
|
+
);
|
|
1252
|
+
this.pbParameters.set(decl, parameters);
|
|
1253
|
+
this.pbDecls.set(key, decl);
|
|
1254
|
+
return decl;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
getPbParameters(decl: number) {
|
|
1258
|
+
return this.pbParameters.get(decl) as Rational[];
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
mkFpValueId(value: Mpf) {
|
|
1262
|
+
const key = `${value.ebits}:${value.sbits}:${value.sign}:${value.exponent}:${value.significand}`;
|
|
1263
|
+
const existing = this.fpValueIds.get(key);
|
|
1264
|
+
if (existing !== undefined) return existing;
|
|
1265
|
+
this.fpValues.push({ ...value });
|
|
1266
|
+
this.fpValueIds.set(key, this.fpValues.length - 1);
|
|
1267
|
+
return this.fpValues.length - 1;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
getFpValue(id: number): Readonly<Mpf> {
|
|
1271
|
+
return this.fpValues[id];
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
private addSort(
|
|
1275
|
+
name: string,
|
|
1276
|
+
family: number,
|
|
1277
|
+
parameters: number[],
|
|
1278
|
+
hash: number,
|
|
1279
|
+
width = 0,
|
|
1280
|
+
sbits = 0,
|
|
1281
|
+
size = SORT_SIZE_INFINITE,
|
|
1282
|
+
) {
|
|
1283
|
+
this.sortHashes.push(hash);
|
|
1284
|
+
this.sortNames.push(name);
|
|
1285
|
+
this.sortFamilies.push(family);
|
|
1286
|
+
this.sortWidths.push(width);
|
|
1287
|
+
this.sortSbits.push(sbits);
|
|
1288
|
+
this.sortParameters.push(parameters);
|
|
1289
|
+
this.sortSizes.push(size);
|
|
680
1290
|
return this.sortNames.length - 1;
|
|
681
1291
|
}
|
|
682
1292
|
|
|
683
|
-
//
|
|
1293
|
+
// Z3 makes the Char, String and RegLan sorts at startup, so they take no small id.
|
|
1294
|
+
mkCharSort() {
|
|
1295
|
+
if (this.charSort === -1)
|
|
1296
|
+
this.charSort = this.addSort(
|
|
1297
|
+
"Unicode",
|
|
1298
|
+
FAMILY_CHAR,
|
|
1299
|
+
[],
|
|
1300
|
+
combineHash(getSymbolHash("Unicode"), getInfoHash(Z3_CHAR_FAMILY, 0, [])),
|
|
1301
|
+
);
|
|
1302
|
+
return this.charSort;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// String keeps its element out of its parameters, since it prints as a plain name.
|
|
1306
|
+
mkStringSort() {
|
|
1307
|
+
if (this.stringSort !== -1) return this.stringSort;
|
|
1308
|
+
const charHash = this.sortHashes[this.mkCharSort()];
|
|
1309
|
+
this.stringSort = this.addSort(
|
|
1310
|
+
"String",
|
|
1311
|
+
FAMILY_SEQ,
|
|
1312
|
+
[],
|
|
1313
|
+
combineHash(getSymbolHash("String"), getInfoHash(Z3_SEQ_FAMILY, Z3_SEQ_SORT, [charHash])),
|
|
1314
|
+
);
|
|
1315
|
+
return this.stringSort;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
mkSeqSort(element: number) {
|
|
1319
|
+
if (element === this.mkCharSort()) return this.mkStringSort();
|
|
1320
|
+
const key = `s${element}`;
|
|
1321
|
+
const existing = this.seqSorts.get(key);
|
|
1322
|
+
if (existing !== undefined) return existing;
|
|
1323
|
+
const sort = this.addSort(
|
|
1324
|
+
"Seq",
|
|
1325
|
+
FAMILY_SEQ,
|
|
1326
|
+
[element],
|
|
1327
|
+
combineHash(
|
|
1328
|
+
getSymbolHash("Seq"),
|
|
1329
|
+
getInfoHash(Z3_SEQ_FAMILY, Z3_SEQ_SORT, [this.sortHashes[element]]),
|
|
1330
|
+
),
|
|
1331
|
+
);
|
|
1332
|
+
this.mkSmallId();
|
|
1333
|
+
this.seqSorts.set(key, sort);
|
|
1334
|
+
return sort;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
mkReSort(seq: number) {
|
|
1338
|
+
const isReglan = seq === this.mkStringSort();
|
|
1339
|
+
if (isReglan && this.reglanSort !== -1) return this.reglanSort;
|
|
1340
|
+
const key = `r${seq}`;
|
|
1341
|
+
const existing = this.seqSorts.get(key);
|
|
1342
|
+
if (existing !== undefined) return existing;
|
|
1343
|
+
const sort = this.addSort(
|
|
1344
|
+
"RegEx",
|
|
1345
|
+
FAMILY_SEQ,
|
|
1346
|
+
[seq],
|
|
1347
|
+
combineHash(
|
|
1348
|
+
getSymbolHash("RegEx"),
|
|
1349
|
+
getInfoHash(Z3_SEQ_FAMILY, Z3_RE_SORT, [this.sortHashes[seq]]),
|
|
1350
|
+
),
|
|
1351
|
+
);
|
|
1352
|
+
if (isReglan) this.reglanSort = sort;
|
|
1353
|
+
else {
|
|
1354
|
+
this.mkSmallId();
|
|
1355
|
+
this.seqSorts.set(key, sort);
|
|
1356
|
+
}
|
|
1357
|
+
return sort;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
isCharSort(sort: number) {
|
|
1361
|
+
return sort === this.charSort;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
isStringSort(sort: number) {
|
|
1365
|
+
return sort === this.stringSort;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
isSeqSort(sort: number) {
|
|
1369
|
+
return this.sortFamilies[sort] === FAMILY_SEQ && this.sortNames[sort] !== "RegEx";
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
isReSort(sort: number) {
|
|
1373
|
+
return this.sortFamilies[sort] === FAMILY_SEQ && this.sortNames[sort] === "RegEx";
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
getSeqElementSort(sort: number) {
|
|
1377
|
+
return sort === this.stringSort ? this.charSort : this.sortParameters[sort][0];
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
getReSeqSort(sort: number) {
|
|
1381
|
+
return this.sortParameters[sort][0];
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
mkSeqDecl(
|
|
1385
|
+
op: number,
|
|
1386
|
+
name: string,
|
|
1387
|
+
parameters: number[],
|
|
1388
|
+
parameterHashes: number[],
|
|
1389
|
+
domain: number[],
|
|
1390
|
+
range: number,
|
|
1391
|
+
) {
|
|
1392
|
+
const key = `${op}:${name}:${parameters.join(",")}:${domain.join(",")}:${range}`;
|
|
1393
|
+
const existing = this.seqDecls.get(key);
|
|
1394
|
+
if (existing !== undefined) return existing;
|
|
1395
|
+
const isChar = op >= CHAR_OP_BASE;
|
|
1396
|
+
const decl = this.addDecl(
|
|
1397
|
+
name,
|
|
1398
|
+
isChar ? FAMILY_CHAR : FAMILY_SEQ,
|
|
1399
|
+
op,
|
|
1400
|
+
domain,
|
|
1401
|
+
range,
|
|
1402
|
+
parameters,
|
|
1403
|
+
getInfoHash(
|
|
1404
|
+
isChar ? Z3_CHAR_FAMILY : Z3_SEQ_FAMILY,
|
|
1405
|
+
op - (isChar ? CHAR_OP_BASE : SEQ_OP_BASE),
|
|
1406
|
+
parameterHashes,
|
|
1407
|
+
),
|
|
1408
|
+
);
|
|
1409
|
+
this.seqDecls.set(key, decl);
|
|
1410
|
+
return decl;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
mkStringValueId(chars: readonly number[]) {
|
|
1414
|
+
const key = chars.join(",");
|
|
1415
|
+
const existing = this.stringValueIds.get(key);
|
|
1416
|
+
if (existing !== undefined) return existing;
|
|
1417
|
+
this.stringValues.push([...chars]);
|
|
1418
|
+
this.stringValueIds.set(key, this.stringValues.length - 1);
|
|
1419
|
+
return this.stringValues.length - 1;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
getStringHash(id: number) {
|
|
1423
|
+
return bytesHash(new Uint8Array(Uint32Array.from(this.stringValues[id]).buffer), 23);
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
getSortHash(sort: number) {
|
|
1427
|
+
return this.sortHashes[sort];
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
mkString(chars: readonly number[]) {
|
|
1431
|
+
const id = this.mkStringValueId(chars);
|
|
1432
|
+
const sort = this.mkStringSort();
|
|
1433
|
+
const decl = this.mkSeqDecl(
|
|
1434
|
+
OP_STRING_CONST,
|
|
1435
|
+
"String",
|
|
1436
|
+
[id],
|
|
1437
|
+
[this.getStringHash(id)],
|
|
1438
|
+
[],
|
|
1439
|
+
sort,
|
|
1440
|
+
);
|
|
1441
|
+
return this.mkApp(decl, [], sort);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
getString(expr: number): readonly number[] | undefined {
|
|
1445
|
+
if (this.getOp(expr) !== OP_STRING_CONST) return undefined;
|
|
1446
|
+
return this.stringValues[this.funcDecls[this.decls[expr]].parameters[0]];
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
mkChar(code: number) {
|
|
1450
|
+
const sort = this.mkCharSort();
|
|
1451
|
+
return this.mkApp(this.mkSeqDecl(OP_CHAR_CONST, "Char", [code], [code], [], sort), [], sort);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
getChar(expr: number) {
|
|
1455
|
+
return this.getOp(expr) === OP_CHAR_CONST ? this.funcDecls[this.decls[expr]].parameters[0] : -1;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
mkArraySort(parameters: number[]) {
|
|
1459
|
+
const key = parameters.join(",");
|
|
1460
|
+
const existing = this.arraySorts.get(key);
|
|
1461
|
+
if (existing !== undefined) return existing;
|
|
1462
|
+
const sort = this.addSort(
|
|
1463
|
+
"Array",
|
|
1464
|
+
FAMILY_ARRAY,
|
|
1465
|
+
parameters,
|
|
1466
|
+
combineHash(
|
|
1467
|
+
getSymbolHash("Array"),
|
|
1468
|
+
getInfoHash(
|
|
1469
|
+
Z3_ARRAY_FAMILY,
|
|
1470
|
+
0,
|
|
1471
|
+
parameters.map((parameter) => this.sortHashes[parameter]),
|
|
1472
|
+
),
|
|
1473
|
+
),
|
|
1474
|
+
0,
|
|
1475
|
+
0,
|
|
1476
|
+
this.getArraySortSize(parameters),
|
|
1477
|
+
);
|
|
1478
|
+
this.mkSmallId();
|
|
1479
|
+
this.arraySorts.set(key, sort);
|
|
1480
|
+
return sort;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
private getArraySortSize(parameters: number[]) {
|
|
1484
|
+
const sizes = parameters.map((parameter) => this.sortSizes[parameter]);
|
|
1485
|
+
if (sizes[sizes.length - 1] === 1n) return 1n;
|
|
1486
|
+
if (sizes.includes(SORT_SIZE_INFINITE)) return SORT_SIZE_INFINITE;
|
|
1487
|
+
if (sizes.includes(SORT_SIZE_VERY_BIG)) return SORT_SIZE_VERY_BIG;
|
|
1488
|
+
const domainSize = sizes.slice(0, -1).reduce((product, size) => product * size, 1n);
|
|
1489
|
+
if (domainSize > 128n) return SORT_SIZE_VERY_BIG;
|
|
1490
|
+
const size = sizes[sizes.length - 1] ** domainSize;
|
|
1491
|
+
return size >= 1n << 64n ? SORT_SIZE_VERY_BIG : size;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
isArraySort(sort: number) {
|
|
1495
|
+
return this.sortFamilies[sort] === FAMILY_ARRAY;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
getSortParameters(sort: number): readonly number[] {
|
|
1499
|
+
return this.sortParameters[sort];
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
getArrayArity(sort: number) {
|
|
1503
|
+
return this.sortParameters[sort].length - 1;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
getArrayRange(sort: number) {
|
|
1507
|
+
const parameters = this.sortParameters[sort];
|
|
1508
|
+
return parameters[parameters.length - 1];
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
getSortName(sort: number): string {
|
|
1512
|
+
if (this.isBvSort(sort)) return `(_ BitVec ${this.getBvSize(sort)})`;
|
|
1513
|
+
if (this.isFpSort(sort))
|
|
1514
|
+
return `(_ FloatingPoint ${this.getEbits(sort)} ${this.getSbits(sort)})`;
|
|
1515
|
+
const parameters = this.sortParameters[sort].map((parameter) => this.getSortName(parameter));
|
|
1516
|
+
if (parameters.length === 0) return this.sortNames[sort];
|
|
1517
|
+
return `(${this.sortNames[sort]} ${parameters.join(" ")})`;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
getSortSize(sort: number) {
|
|
1521
|
+
return this.sortSizes[sort];
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
mkArrayDecl(op: number, name: string, parameters: number[], domain: number[], range: number) {
|
|
1525
|
+
const key = `${op}:${parameters.join(",")}:${domain.join(",")}`;
|
|
1526
|
+
const existing = this.arrayDecls.get(key);
|
|
1527
|
+
if (existing !== undefined) return existing;
|
|
1528
|
+
const parameterHashes = parameters.map((parameter) =>
|
|
1529
|
+
op === OP_CONST_ARRAY
|
|
1530
|
+
? this.sortHashes[parameter]
|
|
1531
|
+
: op === OP_ARRAY_MAP || op === OP_AS_ARRAY
|
|
1532
|
+
? // A builtin declaration hashes by the signature of each application, which a map lacks.
|
|
1533
|
+
(this.getDeclHash(parameter) ?? 0)
|
|
1534
|
+
: parameter,
|
|
1535
|
+
);
|
|
1536
|
+
const decl = this.addDecl(
|
|
1537
|
+
name,
|
|
1538
|
+
FAMILY_ARRAY,
|
|
1539
|
+
op,
|
|
1540
|
+
domain,
|
|
1541
|
+
range,
|
|
1542
|
+
parameters,
|
|
1543
|
+
getInfoHash(Z3_ARRAY_FAMILY, op - ARRAY_OP_BASE, parameterHashes),
|
|
1544
|
+
);
|
|
1545
|
+
this.arrayDecls.set(key, decl);
|
|
1546
|
+
return decl;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
private mkParametricSort(
|
|
1550
|
+
family: number,
|
|
1551
|
+
name: SmtSymbol,
|
|
1552
|
+
parameters: number[],
|
|
1553
|
+
infoHash: number,
|
|
1554
|
+
) {
|
|
1555
|
+
const key = `${family}:${typeof name}:${name}:${parameters.join(",")}`;
|
|
1556
|
+
const existing = this.parametricSorts.get(key);
|
|
1557
|
+
if (existing !== undefined) return existing;
|
|
1558
|
+
const sort = this.addSort(
|
|
1559
|
+
getSymbolName(name),
|
|
1560
|
+
family,
|
|
1561
|
+
parameters,
|
|
1562
|
+
combineHash(getSymbolHash(name), infoHash),
|
|
1563
|
+
);
|
|
1564
|
+
this.sortSmallIds[sort] = this.mkSmallId();
|
|
1565
|
+
this.parametricSorts.set(key, sort);
|
|
1566
|
+
return sort;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
private getUserSortKind(name: SmtSymbol) {
|
|
1570
|
+
const existing = this.userSortKinds.get(name);
|
|
1571
|
+
if (existing !== undefined) return existing;
|
|
1572
|
+
this.userSortKinds.set(name, this.numUserSorts);
|
|
1573
|
+
return this.numUserSorts++;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
mkUninterpretedSort(name: SmtSymbol, parameters: number[]) {
|
|
1577
|
+
return this.mkParametricSort(
|
|
1578
|
+
FAMILY_USER,
|
|
1579
|
+
name,
|
|
1580
|
+
parameters,
|
|
1581
|
+
getInfoHash(
|
|
1582
|
+
Z3_USER_SORT_FAMILY,
|
|
1583
|
+
this.getUserSortKind(name),
|
|
1584
|
+
parameters.map((parameter) => this.sortHashes[parameter]),
|
|
1585
|
+
),
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
mkDatatypeSort(name: string, parameters: number[]) {
|
|
1590
|
+
return this.mkParametricSort(
|
|
1591
|
+
FAMILY_DATATYPE,
|
|
1592
|
+
name,
|
|
1593
|
+
parameters,
|
|
1594
|
+
getInfoHash(Z3_DATATYPE_FAMILY, 0, [
|
|
1595
|
+
getSymbolHash(name),
|
|
1596
|
+
...parameters.map((parameter) => this.sortHashes[parameter]),
|
|
1597
|
+
]),
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
setSortSize(sort: number, size: bigint) {
|
|
1602
|
+
this.sortSizes[sort] = size;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// The sort named by the number index, which stands for a parameter of a datatype declaration.
|
|
1606
|
+
mkTypeParameter(index: number) {
|
|
1607
|
+
const sort = this.mkUninterpretedSort(index, []);
|
|
1608
|
+
this.typeParameters[index] = sort;
|
|
1609
|
+
return sort;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
getTypeParameterIndex(sort: number) {
|
|
1613
|
+
return this.typeParameters.indexOf(sort);
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
getSortSmallId(sort: number) {
|
|
1617
|
+
return this.sortSmallIds[sort];
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
isDatatypeSort(sort: number) {
|
|
1621
|
+
return this.sortFamilies[sort] === FAMILY_DATATYPE;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
// The parameters are those of the port, and parameterHashes hash Z3's.
|
|
1625
|
+
mkDatatypeDecl(
|
|
1626
|
+
op: number,
|
|
1627
|
+
name: string,
|
|
1628
|
+
parameters: number[],
|
|
1629
|
+
parameterHashes: number[],
|
|
1630
|
+
domain: number[],
|
|
1631
|
+
range: number,
|
|
1632
|
+
) {
|
|
1633
|
+
const key = `${op}:${name}:${parameters.join(",")}:${domain.join(",")}:${range}`;
|
|
1634
|
+
const existing = this.datatypeDecls.get(key);
|
|
1635
|
+
if (existing !== undefined) return existing;
|
|
1636
|
+
const decl = this.addDecl(
|
|
1637
|
+
name,
|
|
1638
|
+
FAMILY_DATATYPE,
|
|
1639
|
+
op,
|
|
1640
|
+
domain,
|
|
1641
|
+
range,
|
|
1642
|
+
parameters,
|
|
1643
|
+
getInfoHash(Z3_DATATYPE_FAMILY, op - DATATYPE_OP_BASE, parameterHashes),
|
|
1644
|
+
);
|
|
1645
|
+
this.datatypeDecls.set(key, decl);
|
|
1646
|
+
return decl;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
getBvSize(sort: number) {
|
|
1650
|
+
return this.sortWidths[sort];
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
isBvSort(sort: number) {
|
|
1654
|
+
return this.sortFamilies[sort] === FAMILY_BV;
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
mkBvDecl(op: number, name: string, parameters: number[], domain: number[], range: number) {
|
|
1658
|
+
const key = `${op}:${parameters.join(",")}:${domain.join(",")}`;
|
|
1659
|
+
const existing = this.bvDecls.get(key);
|
|
1660
|
+
if (existing !== undefined) return existing;
|
|
1661
|
+
const decl = this.addDecl(
|
|
1662
|
+
name,
|
|
1663
|
+
FAMILY_BV,
|
|
1664
|
+
op,
|
|
1665
|
+
domain,
|
|
1666
|
+
range,
|
|
1667
|
+
parameters,
|
|
1668
|
+
getInfoHash(Z3_BV_FAMILY, op - BV_OP_BASE, parameters),
|
|
1669
|
+
!UNCACHED_BV_OPS.has(op),
|
|
1670
|
+
);
|
|
1671
|
+
this.bvDecls.set(key, decl);
|
|
1672
|
+
return decl;
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
mkBvNumeral(value: bigint, width: number) {
|
|
1676
|
+
const modulus = 1n << BigInt(width);
|
|
1677
|
+
const normalized = ((value % modulus) + modulus) % modulus;
|
|
1678
|
+
const sort = this.mkBvSort(width);
|
|
1679
|
+
const key = `b${width}:${normalized}`;
|
|
1680
|
+
const existing = this.table.get(key);
|
|
1681
|
+
if (existing !== undefined) return this.revive(existing);
|
|
1682
|
+
let decl = this.bvDecls.get(`n${width}`);
|
|
1683
|
+
if (decl === undefined) {
|
|
1684
|
+
decl = this.funcDecls.length;
|
|
1685
|
+
this.funcDecls.push({
|
|
1686
|
+
name: "bv",
|
|
1687
|
+
family: FAMILY_BV,
|
|
1688
|
+
op: OP_BV_NUM,
|
|
1689
|
+
domain: [],
|
|
1690
|
+
range: sort,
|
|
1691
|
+
isSkolem: false,
|
|
1692
|
+
smallId: -1,
|
|
1693
|
+
parameters: [width],
|
|
1694
|
+
});
|
|
1695
|
+
this.bvDecls.set(`n${width}`, decl);
|
|
1696
|
+
}
|
|
1697
|
+
this.numeralValues.push(Rational.of(normalized));
|
|
1698
|
+
const numeralDecl = decl;
|
|
1699
|
+
return this.intern(key, KIND_APP, numeralDecl, [], sort, this.numeralValues.length - 1, () =>
|
|
1700
|
+
this.getFuncDeclHash(
|
|
1701
|
+
"bv",
|
|
1702
|
+
[],
|
|
1703
|
+
sort,
|
|
1704
|
+
getInfoHash(Z3_BV_FAMILY, 0, [(getIntegerHash(normalized) + 3) >>> 0, width]),
|
|
1705
|
+
),
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
isBvNumeral(expr: number) {
|
|
1710
|
+
return this.getOp(expr) === OP_BV_NUM;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
getBvNumeralValue(expr: number) {
|
|
1714
|
+
return this.numeralValues[this.values[expr]].num;
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
getSortFamily(sort: number) {
|
|
1718
|
+
return this.sortFamilies[sort];
|
|
1719
|
+
}
|
|
1720
|
+
|
|
684
1721
|
private getFuncDeclHash(name: SmtSymbol, domain: number[], range: number, infoHash: number) {
|
|
685
1722
|
return astArrayHash(
|
|
686
1723
|
domain,
|
|
@@ -689,7 +1726,6 @@ export class AstManager {
|
|
|
689
1726
|
);
|
|
690
1727
|
}
|
|
691
1728
|
|
|
692
|
-
// The name, Z3 decl kind and domain of the Z3 declaration of a builtin application.
|
|
693
1729
|
getBuiltinSignature(op: number, args: number[]) {
|
|
694
1730
|
const builtin = Z3_BUILTINS.get(op);
|
|
695
1731
|
if (builtin === undefined)
|
|
@@ -706,7 +1742,6 @@ export class AstManager {
|
|
|
706
1742
|
return { name: builtin[0], kind: builtin[1], domain };
|
|
707
1743
|
}
|
|
708
1744
|
|
|
709
|
-
// The hash of a pattern's Z3 declaration.
|
|
710
1745
|
private getPatternHash(args: number[], range: number) {
|
|
711
1746
|
const key = `${args.map((arg) => this.sorts[arg]).join(",")}:${range}`;
|
|
712
1747
|
const existing = this.patternHashes.get(key);
|
|
@@ -716,9 +1751,7 @@ export class AstManager {
|
|
|
716
1751
|
return hash;
|
|
717
1752
|
}
|
|
718
1753
|
|
|
719
|
-
//
|
|
720
|
-
// domain depends only on the sort of an argument and the number of arguments, which key the cache
|
|
721
|
-
// with the op and range. It returns the slot, a small integer, because V8 boxes a hash it returns.
|
|
1754
|
+
// Returns the slot, a small integer, because V8 boxes a hash it returns.
|
|
722
1755
|
private getBuiltinSlot(op: number, args: number[], range: number) {
|
|
723
1756
|
const argSort = args.length === 0 ? 0 : this.sorts[op === OP_ITE ? args[1] : args[0]];
|
|
724
1757
|
const count = args.length;
|
|
@@ -744,7 +1777,6 @@ export class AstManager {
|
|
|
744
1777
|
return this.insertBuiltinHash(op, argSort, range, count, hash);
|
|
745
1778
|
}
|
|
746
1779
|
|
|
747
|
-
// The slot of the builtin hash with these keys, or the free slot where it goes.
|
|
748
1780
|
private findBuiltinSlot(op: number, argSort: number, range: number, count: number) {
|
|
749
1781
|
const keys = this.builtinKeys;
|
|
750
1782
|
const mask = this.builtinHashes.length - 1;
|
|
@@ -789,11 +1821,20 @@ export class AstManager {
|
|
|
789
1821
|
);
|
|
790
1822
|
}
|
|
791
1823
|
|
|
792
|
-
// The hash of a user declaration, which Z3's tables of declarations hash.
|
|
793
1824
|
getDeclHash(decl: number) {
|
|
794
1825
|
return this.declHashes[decl];
|
|
795
1826
|
}
|
|
796
1827
|
|
|
1828
|
+
getAppDeclHash(app: number) {
|
|
1829
|
+
const decl = this.decls[app];
|
|
1830
|
+
const funcDecl = this.funcDecls[decl];
|
|
1831
|
+
if (hasOwnDeclHash(funcDecl.family)) return this.declHashes[decl];
|
|
1832
|
+
const args = this.getArgs(app);
|
|
1833
|
+
return funcDecl.op === OP_PATTERN
|
|
1834
|
+
? this.getPatternHash(args, this.sorts[app])
|
|
1835
|
+
: this.builtinHashes[this.getBuiltinSlot(funcDecl.op, args, this.sorts[app])];
|
|
1836
|
+
}
|
|
1837
|
+
|
|
797
1838
|
mkFuncDecl(name: SmtSymbol, domain: number[], range: number, isSkolem = false) {
|
|
798
1839
|
this.declHashes[this.funcDecls.length] = this.getFuncDeclHash(
|
|
799
1840
|
name,
|
|
@@ -809,25 +1850,35 @@ export class AstManager {
|
|
|
809
1850
|
range,
|
|
810
1851
|
isSkolem,
|
|
811
1852
|
smallId: this.mkSmallId(),
|
|
1853
|
+
parameters: [],
|
|
812
1854
|
});
|
|
813
1855
|
this.declRefCounts[this.funcDecls.length - 1] = 1;
|
|
814
1856
|
return this.funcDecls.length - 1;
|
|
815
1857
|
}
|
|
816
1858
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1859
|
+
mkFreshFuncDecl(
|
|
1860
|
+
prefix: SmtSymbol | null,
|
|
1861
|
+
domain: number[],
|
|
1862
|
+
range: number,
|
|
1863
|
+
isSkolem = true,
|
|
1864
|
+
suffix = "",
|
|
1865
|
+
) {
|
|
1866
|
+
const name =
|
|
1867
|
+
prefix === null && suffix === ""
|
|
1868
|
+
? this.freshId
|
|
1869
|
+
: `${prefix === null ? "sk" : getSymbolName(prefix)}!${suffix === "" ? "" : `${suffix}!`}${this.freshId}`;
|
|
820
1870
|
this.freshId++;
|
|
821
1871
|
const decl = this.mkFuncDecl(name, domain, range, isSkolem);
|
|
822
1872
|
this.declRefCounts[decl] = 0;
|
|
823
1873
|
return decl;
|
|
824
1874
|
}
|
|
825
1875
|
|
|
826
|
-
// mk_fresh_var_name.
|
|
827
1876
|
mkFreshVarName(prefix: string | null) {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1877
|
+
return `${prefix ?? "var"}!${this.mkFreshId()}`;
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
mkFreshId() {
|
|
1881
|
+
return this.freshId++;
|
|
831
1882
|
}
|
|
832
1883
|
|
|
833
1884
|
private intern(
|
|
@@ -863,6 +1914,7 @@ export class AstManager {
|
|
|
863
1914
|
this.values = grow(this.values);
|
|
864
1915
|
this.freeVarBounds = grow(this.freeVarBounds);
|
|
865
1916
|
this.hasQuantifierFlags = grow(this.hasQuantifierFlags);
|
|
1917
|
+
this.hasLabelFlags = grow(this.hasLabelFlags);
|
|
866
1918
|
this.depths = grow(this.depths);
|
|
867
1919
|
this.hashes = grow(this.hashes);
|
|
868
1920
|
this.ids = grow(this.ids);
|
|
@@ -871,7 +1923,6 @@ export class AstManager {
|
|
|
871
1923
|
this.hashes[id] = hash;
|
|
872
1924
|
this.kinds[id] = kind;
|
|
873
1925
|
this.decls[id] = decl;
|
|
874
|
-
// Like Z3, a node keeps its own copy of the arguments, so callers may reuse their arrays.
|
|
875
1926
|
const start = this.argStarts[id];
|
|
876
1927
|
const end = start + args.length;
|
|
877
1928
|
if (end > this.argPool.length) {
|
|
@@ -890,25 +1941,30 @@ export class AstManager {
|
|
|
890
1941
|
this.values[id] = value;
|
|
891
1942
|
let freeVarBound = kind === KIND_VAR ? value + 1 : 0;
|
|
892
1943
|
let hasQuantifier = kind === KIND_QUANTIFIER;
|
|
1944
|
+
let hasLabel = kind === KIND_APP && this.funcDecls[decl].op === OP_LABEL;
|
|
893
1945
|
let depth = 1;
|
|
894
1946
|
for (let index = 0; index < args.length; index++) {
|
|
895
1947
|
const arg = args[index];
|
|
896
1948
|
if (this.freeVarBounds[arg] > freeVarBound) freeVarBound = this.freeVarBounds[arg];
|
|
897
1949
|
if (this.hasQuantifierFlags[arg]) hasQuantifier = true;
|
|
1950
|
+
if (this.hasLabelFlags[arg]) hasLabel = true;
|
|
898
1951
|
if (this.depths[arg] + 1 > depth) depth = this.depths[arg] + 1;
|
|
899
1952
|
}
|
|
900
1953
|
this.freeVarBounds[id] = freeVarBound;
|
|
901
1954
|
this.hasQuantifierFlags[id] = hasQuantifier ? 1 : 0;
|
|
1955
|
+
this.hasLabelFlags[id] = hasLabel ? 1 : 0;
|
|
902
1956
|
this.depths[id] = depth;
|
|
903
1957
|
return id;
|
|
904
1958
|
}
|
|
905
1959
|
|
|
906
|
-
// The op of a builtin declaration doubles as its index in funcDecls. The arguments are those of
|
|
907
|
-
// args from start on, so that a rewriter passes its result stack without copying it.
|
|
908
1960
|
mkApp(decl: number, args: number[], sort: number, start = 0) {
|
|
909
1961
|
const funcDecl = this.funcDecls[decl];
|
|
910
|
-
|
|
911
|
-
|
|
1962
|
+
if (
|
|
1963
|
+
decl === OP_NUM ||
|
|
1964
|
+
decl === OP_ALGEBRAIC_NUM ||
|
|
1965
|
+
funcDecl.family === FAMILY_MODEL_VALUE ||
|
|
1966
|
+
funcDecl.op === OP_BV_NUM
|
|
1967
|
+
)
|
|
912
1968
|
throw new SmtInvariantError(`${funcDecl.name} needs a value`);
|
|
913
1969
|
let hash = decl;
|
|
914
1970
|
for (let index = start; index < args.length; index++)
|
|
@@ -931,17 +1987,16 @@ export class AstManager {
|
|
|
931
1987
|
for (let index = start; index < args.length; index++) this.argBuffer.push(args[index]);
|
|
932
1988
|
}
|
|
933
1989
|
const nodeArgs = start > 0 ? this.argBuffer : args;
|
|
934
|
-
|
|
1990
|
+
const hasOwnHash = hasOwnDeclHash(funcDecl.family);
|
|
935
1991
|
const builtinSlot =
|
|
936
|
-
|
|
1992
|
+
hasOwnHash || funcDecl.op === OP_PATTERN
|
|
937
1993
|
? -1
|
|
938
1994
|
: this.getBuiltinSlot(funcDecl.op, nodeArgs, sort);
|
|
939
|
-
const declHash =
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
: this.builtinHashes[builtinSlot];
|
|
1995
|
+
const declHash = hasOwnHash
|
|
1996
|
+
? this.declHashes[decl]
|
|
1997
|
+
: builtinSlot === -1
|
|
1998
|
+
? this.getPatternHash(nodeArgs, sort)
|
|
1999
|
+
: this.builtinHashes[builtinSlot];
|
|
945
2000
|
const id = this.create(
|
|
946
2001
|
KIND_APP,
|
|
947
2002
|
decl,
|
|
@@ -950,7 +2005,6 @@ export class AstManager {
|
|
|
950
2005
|
0,
|
|
951
2006
|
astArrayHash(nodeArgs, this.hashes, declHash),
|
|
952
2007
|
);
|
|
953
|
-
// The lookup ended at a free slot, which the application takes unless the table doubles.
|
|
954
2008
|
if (2 * (this.numApps + 1) > this.appHandles.length) {
|
|
955
2009
|
const handles = this.appHandles;
|
|
956
2010
|
const hashes = this.appHashes;
|
|
@@ -978,8 +2032,6 @@ export class AstManager {
|
|
|
978
2032
|
this.numApps++;
|
|
979
2033
|
}
|
|
980
2034
|
|
|
981
|
-
// A numeral's declaration has the parameters (value, is_int), and a rational hashes as
|
|
982
|
-
// hash(numerator) + 3 hash(denominator).
|
|
983
2035
|
private internNumeral(key: string, value: Rational, sort: number) {
|
|
984
2036
|
const existing = this.table.get(key);
|
|
985
2037
|
if (existing !== undefined) return this.revive(existing);
|
|
@@ -998,6 +2050,60 @@ export class AstManager {
|
|
|
998
2050
|
);
|
|
999
2051
|
}
|
|
1000
2052
|
|
|
2053
|
+
get am() {
|
|
2054
|
+
this.algebraicManager ??= new AlgebraicManager();
|
|
2055
|
+
return this.algebraicManager;
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
mkAlgebraicNumeral(value: Anum, sort = SORT_REAL) {
|
|
2059
|
+
if (this.am.isRational(value)) return this.mkNumeralOfSort(this.am.toRational(value), sort);
|
|
2060
|
+
if (sort === SORT_INT)
|
|
2061
|
+
throw new SmtInvariantError("invalid irrational value passed as an integer");
|
|
2062
|
+
const id = this.mkAlgebraicId();
|
|
2063
|
+
this.algebraicNumerals.push({ value: this.am.copy(value), id });
|
|
2064
|
+
const expr = this.create(
|
|
2065
|
+
KIND_APP,
|
|
2066
|
+
OP_ALGEBRAIC_NUM,
|
|
2067
|
+
[],
|
|
2068
|
+
SORT_REAL,
|
|
2069
|
+
this.algebraicNumerals.length - 1,
|
|
2070
|
+
this.getFuncDeclHash("RootObject", [], SORT_REAL, getInfoHash(Z3_ARITH_FAMILY, 1, [id])),
|
|
2071
|
+
);
|
|
2072
|
+
this.registerNode(expr);
|
|
2073
|
+
return expr;
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
private mkAlgebraicId() {
|
|
2077
|
+
return this.freeAlgebraicIds.pop() ?? this.nextAlgebraicId++;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
isAlgebraicNumeral(expr: number) {
|
|
2081
|
+
return this.getOp(expr) === OP_ALGEBRAIC_NUM;
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
getAlgebraicValue(expr: number) {
|
|
2085
|
+
return this.algebraicNumerals[this.values[expr]].value;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
private getAnumOrNumeral(expr: number) {
|
|
2089
|
+
if (this.isAlgebraicNumeral(expr)) return this.getAlgebraicValue(expr);
|
|
2090
|
+
return this.isNumeral(expr) ? new Anum(this.getRationalValue(expr)) : undefined;
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
compareArithValues(first: number, second: number) {
|
|
2094
|
+
if (this.isNumeral(first) && this.isNumeral(second))
|
|
2095
|
+
return this.getRationalValue(first).compare(this.getRationalValue(second));
|
|
2096
|
+
const firstValue = this.getAnumOrNumeral(first);
|
|
2097
|
+
const secondValue = this.getAnumOrNumeral(second);
|
|
2098
|
+
if (firstValue === undefined || secondValue === undefined)
|
|
2099
|
+
throw new SmtInvariantError("arith_value_order compares numerals");
|
|
2100
|
+
return this.am.compare(firstValue, secondValue);
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
getAlgebraicId(expr: number) {
|
|
2104
|
+
return this.algebraicNumerals[this.values[expr]].id;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
1001
2107
|
mkRealNumeral(value: Rational) {
|
|
1002
2108
|
const numeral = this.internNumeral(`r${value}`, value, SORT_REAL);
|
|
1003
2109
|
return value.isInt() ? this.holdSmallNumeral(numeral, value.num, this.smallReals) : numeral;
|
|
@@ -1021,12 +2127,10 @@ export class AstManager {
|
|
|
1021
2127
|
return numeral;
|
|
1022
2128
|
}
|
|
1023
2129
|
|
|
1024
|
-
// mk_numeral(value, is_int).
|
|
1025
2130
|
mkNumeralOfSort(value: Rational, sort: number) {
|
|
1026
2131
|
return sort === SORT_INT ? this.mkNumeral(value.num) : this.mkRealNumeral(value);
|
|
1027
2132
|
}
|
|
1028
2133
|
|
|
1029
|
-
// mk_model_value: the element with this index in the universe of an uninterpreted sort.
|
|
1030
2134
|
mkModelValue(index: number, sort: number) {
|
|
1031
2135
|
const key = `m${sort}:${index}`;
|
|
1032
2136
|
const existing = this.table.get(key);
|
|
@@ -1039,6 +2143,7 @@ export class AstManager {
|
|
|
1039
2143
|
range: sort,
|
|
1040
2144
|
isSkolem: false,
|
|
1041
2145
|
smallId: -1,
|
|
2146
|
+
parameters: [],
|
|
1042
2147
|
});
|
|
1043
2148
|
const decl = this.funcDecls.length - 1;
|
|
1044
2149
|
this.declHashes[decl] = this.getFuncDeclHash(
|
|
@@ -1063,19 +2168,30 @@ export class AstManager {
|
|
|
1063
2168
|
mkQuantifier(data: QuantifierData) {
|
|
1064
2169
|
if (data.names.length !== data.sorts.length)
|
|
1065
2170
|
throw new SmtInvariantError("a quantifier needs a name for each variable");
|
|
1066
|
-
|
|
2171
|
+
// Z3 keeps no-patterns only on a quantifier without patterns.
|
|
2172
|
+
const noPatterns = data.patterns.length > 0 ? [] : data.noPatterns;
|
|
2173
|
+
const key = `q${data.kind}:${data.sorts.join(",")}:${JSON.stringify(data.names)}:${
|
|
1067
2174
|
data.body
|
|
1068
|
-
}:${data.patterns.join(",")}:${data.weight}`;
|
|
2175
|
+
}:${data.patterns.join(",")}:${noPatterns.join(",")}:${data.weight}:${data.qid}`;
|
|
1069
2176
|
const existing = this.table.get(key);
|
|
1070
|
-
if (existing !== undefined)
|
|
2177
|
+
if (existing !== undefined) {
|
|
2178
|
+
// A dead quantifier comes back as the new one Z3 makes, with its skolem id.
|
|
2179
|
+
if (this.ids[existing] === -1) {
|
|
2180
|
+
const old = this.getQuantifier(existing);
|
|
2181
|
+
this.quantifiers.set(existing, { ...old, skid: data.skid });
|
|
2182
|
+
}
|
|
2183
|
+
return this.revive(existing);
|
|
2184
|
+
}
|
|
1071
2185
|
const id = this.create(
|
|
1072
2186
|
KIND_QUANTIFIER,
|
|
1073
2187
|
-1,
|
|
1074
2188
|
[data.body],
|
|
1075
|
-
|
|
2189
|
+
data.kind === QUANTIFIER_LAMBDA
|
|
2190
|
+
? this.mkArraySort([...data.sorts, this.sorts[data.body]])
|
|
2191
|
+
: SORT_BOOL,
|
|
1076
2192
|
0,
|
|
1077
2193
|
mkMix(
|
|
1078
|
-
astArrayHash(data.sorts, this.sortHashes, data.
|
|
2194
|
+
astArrayHash(data.sorts, this.sortHashes, data.kind === QUANTIFIER_FORALL ? 31 : 19),
|
|
1079
2195
|
data.patterns.length,
|
|
1080
2196
|
this.hashes[data.body],
|
|
1081
2197
|
),
|
|
@@ -1088,12 +2204,65 @@ export class AstManager {
|
|
|
1088
2204
|
sorts: [...data.sorts],
|
|
1089
2205
|
names: [...data.names],
|
|
1090
2206
|
patterns: [...data.patterns],
|
|
2207
|
+
noPatterns: [...noPatterns],
|
|
1091
2208
|
});
|
|
1092
2209
|
this.registerNode(id);
|
|
1093
2210
|
return id;
|
|
1094
2211
|
}
|
|
1095
2212
|
|
|
1096
|
-
//
|
|
2213
|
+
// A label takes its polarity and names as the parameters of its declaration, and a label literal
|
|
2214
|
+
// takes its names.
|
|
2215
|
+
mkLabel(isPositive: boolean, names: string[], expr: number) {
|
|
2216
|
+
return this.mkApp(this.mkLabelDecl(OP_LABEL, isPositive, names), [expr], SORT_BOOL);
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
mkLabelLit(names: string[]) {
|
|
2220
|
+
return this.mkApp(this.mkLabelDecl(OP_LABEL_LIT, true, names), [], SORT_BOOL);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
private mkLabelDecl(op: number, isPositive: boolean, names: string[]) {
|
|
2224
|
+
const nameIds = names.map((name) => {
|
|
2225
|
+
const existing = this.labelNameIds.get(name);
|
|
2226
|
+
if (existing !== undefined) return existing;
|
|
2227
|
+
this.labelNames.push(name);
|
|
2228
|
+
this.labelNameIds.set(name, this.labelNames.length - 1);
|
|
2229
|
+
return this.labelNames.length - 1;
|
|
2230
|
+
});
|
|
2231
|
+
const parameters = op === OP_LABEL ? [isPositive ? 1 : 0, ...nameIds] : nameIds;
|
|
2232
|
+
const key = `${op}:${parameters.join(",")}`;
|
|
2233
|
+
const existing = this.labelDecls.get(key);
|
|
2234
|
+
if (existing !== undefined) return existing;
|
|
2235
|
+
const name = op === OP_LABEL_LIT ? "lbl-lit" : isPositive ? "lblpos" : "lblneg";
|
|
2236
|
+
const domain = op === OP_LABEL ? [SORT_BOOL] : [];
|
|
2237
|
+
const parameterHashes = names.map(getSymbolHash);
|
|
2238
|
+
const decl = this.addDecl(
|
|
2239
|
+
name,
|
|
2240
|
+
FAMILY_LABEL,
|
|
2241
|
+
op,
|
|
2242
|
+
domain,
|
|
2243
|
+
SORT_BOOL,
|
|
2244
|
+
parameters,
|
|
2245
|
+
getInfoHash(
|
|
2246
|
+
Z3_LABEL_FAMILY,
|
|
2247
|
+
op - LABEL_OP_BASE,
|
|
2248
|
+
op === OP_LABEL ? [isPositive ? 1 : 0, ...parameterHashes] : parameterHashes,
|
|
2249
|
+
),
|
|
2250
|
+
);
|
|
2251
|
+
this.labelDecls.set(key, decl);
|
|
2252
|
+
return decl;
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
isLabelPositive(decl: number) {
|
|
2256
|
+
return this.funcDecls[decl].parameters[0] === 1;
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
getLabelNames(decl: number) {
|
|
2260
|
+
const funcDecl = this.funcDecls[decl];
|
|
2261
|
+
return funcDecl.parameters
|
|
2262
|
+
.slice(funcDecl.op === OP_LABEL ? 1 : 0)
|
|
2263
|
+
.map((nameId) => this.labelNames[nameId]);
|
|
2264
|
+
}
|
|
2265
|
+
|
|
1097
2266
|
mkPattern(terms: number[]) {
|
|
1098
2267
|
return this.mkApp(OP_PATTERN, terms, SORT_BOOL);
|
|
1099
2268
|
}
|
|
@@ -1104,6 +2273,12 @@ export class AstManager {
|
|
|
1104
2273
|
return data;
|
|
1105
2274
|
}
|
|
1106
2275
|
|
|
2276
|
+
isLambda(expr: number) {
|
|
2277
|
+
return (
|
|
2278
|
+
this.kinds[expr] === KIND_QUANTIFIER && this.getQuantifier(expr).kind === QUANTIFIER_LAMBDA
|
|
2279
|
+
);
|
|
2280
|
+
}
|
|
2281
|
+
|
|
1107
2282
|
isApp(expr: number) {
|
|
1108
2283
|
return this.kinds[expr] === KIND_APP;
|
|
1109
2284
|
}
|
|
@@ -1116,7 +2291,6 @@ export class AstManager {
|
|
|
1116
2291
|
return this.freeVarBounds[expr] === 0;
|
|
1117
2292
|
}
|
|
1118
2293
|
|
|
1119
|
-
// Z3's is_ground: an application without variables or quantifiers.
|
|
1120
2294
|
isGroundApp(expr: number) {
|
|
1121
2295
|
return (
|
|
1122
2296
|
this.kinds[expr] === KIND_APP &&
|
|
@@ -1170,40 +2344,113 @@ export class AstManager {
|
|
|
1170
2344
|
return this.getOp(expr) === OP_NUM;
|
|
1171
2345
|
}
|
|
1172
2346
|
|
|
1173
|
-
// The value of an integer numeral.
|
|
1174
2347
|
getNumeral(expr: number) {
|
|
1175
2348
|
return this.isNumeral(expr) && this.sorts[expr] === SORT_INT
|
|
1176
2349
|
? this.getNumeralValue(expr)
|
|
1177
2350
|
: undefined;
|
|
1178
2351
|
}
|
|
1179
2352
|
|
|
1180
|
-
// The value of an expression that is an integer numeral.
|
|
1181
2353
|
getNumeralValue(expr: number) {
|
|
1182
2354
|
return this.numeralValues[this.values[expr]].num;
|
|
1183
2355
|
}
|
|
1184
2356
|
|
|
1185
|
-
// The value of an expression that is a numeral of either sort.
|
|
1186
2357
|
getRationalValue(expr: number) {
|
|
1187
2358
|
return this.numeralValues[this.values[expr]];
|
|
1188
2359
|
}
|
|
1189
2360
|
|
|
1190
|
-
|
|
1191
|
-
isUniqueValue(expr: number) {
|
|
2361
|
+
isUniqueValue(expr: number): boolean {
|
|
1192
2362
|
const op = this.getOp(expr);
|
|
1193
|
-
return
|
|
2363
|
+
return (
|
|
2364
|
+
op === OP_NUM ||
|
|
2365
|
+
op === OP_PI ||
|
|
2366
|
+
op === OP_E ||
|
|
2367
|
+
op === OP_TRUE ||
|
|
2368
|
+
op === OP_FALSE ||
|
|
2369
|
+
op === OP_MODEL_VALUE ||
|
|
2370
|
+
op === OP_BV_NUM ||
|
|
2371
|
+
op === OP_CHAR_CONST ||
|
|
2372
|
+
(op >= OP_FPA_RM_NEAREST_TIES_TO_EVEN && op <= OP_FPA_RM_TOWARD_ZERO) ||
|
|
2373
|
+
(op === OP_CONST_ARRAY && this.isUniqueValue(this.getArg(expr, 0))) ||
|
|
2374
|
+
(op === OP_DT_CONSTRUCTOR && this.everyArg(expr, (arg) => this.isUniqueValue(arg))) ||
|
|
2375
|
+
(op === OP_FPA_FP && this.isUniqueFp(expr))
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
private isUniqueFp(expr: number) {
|
|
2380
|
+
if (!this.everyArg(expr, (arg) => this.isValue(arg))) return false;
|
|
2381
|
+
const exponent = this.getArg(expr, 1);
|
|
2382
|
+
const value = this.getBvNumeralValue(exponent);
|
|
2383
|
+
return value !== 0n && value !== (1n << BigInt(this.getBvSize(this.sorts[exponent]))) - 1n;
|
|
1194
2384
|
}
|
|
1195
2385
|
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
2386
|
+
isValue(expr: number): boolean {
|
|
2387
|
+
let current = expr;
|
|
2388
|
+
while (this.getOp(current) === OP_STORE) {
|
|
2389
|
+
for (let index = 1; index < this.getNumArgs(current); index++)
|
|
2390
|
+
if (!this.isValue(this.getArg(current, index))) return false;
|
|
2391
|
+
current = this.getArg(current, 0);
|
|
2392
|
+
}
|
|
2393
|
+
if (this.getOp(current) === OP_CONST_ARRAY) return this.isValue(this.getArg(current, 0));
|
|
2394
|
+
if (this.getOp(current) === OP_DT_CONSTRUCTOR || this.getOp(current) === OP_FPA_FP)
|
|
2395
|
+
return this.everyArg(current, (arg) => this.isValue(arg));
|
|
2396
|
+
if (this.getOp(current) >= OP_FPA_NUM && this.getOp(current) <= OP_FPA_MINUS_ZERO) return true;
|
|
2397
|
+
if (this.getOp(current) === OP_ALGEBRAIC_NUM) return true;
|
|
2398
|
+
if (this.getFamily(current) === FAMILY_SEQ) return this.isSeqValue(current);
|
|
2399
|
+
return current === expr && this.isUniqueValue(expr);
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
private isSeqValue(expr: number) {
|
|
2403
|
+
const todo = [expr];
|
|
2404
|
+
for (let current = todo.pop(); current !== undefined; current = todo.pop()) {
|
|
2405
|
+
const op = this.getOp(current);
|
|
2406
|
+
if (op === OP_SEQ_EMPTY || op === OP_STRING_CONST) continue;
|
|
2407
|
+
if (op === OP_SEQ_UNIT && this.isValue(this.getArg(current, 0))) continue;
|
|
2408
|
+
if (op !== OP_SEQ_CONCAT || !this.everyArg(current, (arg) => this.isApp(arg))) return false;
|
|
2409
|
+
this.pushArgs(current, todo);
|
|
2410
|
+
}
|
|
2411
|
+
return true;
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
private areSeqsDistinct(first: number, second: number): boolean {
|
|
2415
|
+
const firstOp = this.getOp(first);
|
|
2416
|
+
const secondOp = this.getOp(second);
|
|
2417
|
+
if (first === second) return false;
|
|
2418
|
+
if (firstOp === OP_STRING_CONST && secondOp === OP_STRING_CONST) return true;
|
|
2419
|
+
if (firstOp === OP_SEQ_UNIT && secondOp === OP_SEQ_UNIT)
|
|
2420
|
+
return this.areDistinct(this.getArg(first, 0), this.getArg(second, 0));
|
|
2421
|
+
return (
|
|
2422
|
+
(firstOp === OP_SEQ_EMPTY && secondOp === OP_SEQ_UNIT) ||
|
|
2423
|
+
(firstOp === OP_SEQ_UNIT && secondOp === OP_SEQ_EMPTY)
|
|
2424
|
+
);
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
areDistinct(first: number, second: number): boolean {
|
|
1200
2428
|
if (this.kinds[first] !== KIND_APP || this.kinds[second] !== KIND_APP) return false;
|
|
2429
|
+
const pluginFamily =
|
|
2430
|
+
this.getFamily(first) === FAMILY_USER ? this.getFamily(second) : this.getFamily(first);
|
|
2431
|
+
if (pluginFamily === FAMILY_SEQ) return this.areSeqsDistinct(first, second);
|
|
1201
2432
|
if (first !== second && this.isUniqueValue(first) && this.isUniqueValue(second)) return true;
|
|
1202
2433
|
const family = this.funcDecls[this.decls[first]].family;
|
|
2434
|
+
if (family === FAMILY_DATATYPE) {
|
|
2435
|
+
if (this.getOp(first) !== OP_DT_CONSTRUCTOR || this.getOp(second) !== OP_DT_CONSTRUCTOR)
|
|
2436
|
+
return false;
|
|
2437
|
+
if (this.decls[first] !== this.decls[second]) return true;
|
|
2438
|
+
for (let index = this.getNumArgs(first) - 1; index >= 0; index--)
|
|
2439
|
+
if (this.areDistinct(this.getArg(first, index), this.getArg(second, index))) return true;
|
|
2440
|
+
return false;
|
|
2441
|
+
}
|
|
1203
2442
|
if (
|
|
1204
2443
|
(family === FAMILY_USER ? this.funcDecls[this.decls[second]].family : family) !== FAMILY_ARITH
|
|
1205
2444
|
)
|
|
1206
2445
|
return false;
|
|
2446
|
+
const firstValue = this.getAnumOrNumeral(first);
|
|
2447
|
+
const secondValue = this.getAnumOrNumeral(second);
|
|
2448
|
+
if (
|
|
2449
|
+
firstValue !== undefined &&
|
|
2450
|
+
secondValue !== undefined &&
|
|
2451
|
+
(this.isAlgebraicNumeral(first) || this.isAlgebraicNumeral(second))
|
|
2452
|
+
)
|
|
2453
|
+
return this.am.compare(firstValue, secondValue) !== 0;
|
|
1207
2454
|
const isOffsetOf = (sum: number, term: number) => {
|
|
1208
2455
|
if (this.getOp(sum) !== OP_ADD || this.getNumArgs(sum) !== 2) return false;
|
|
1209
2456
|
const first = this.getArg(sum, 0);
|
|
@@ -1220,10 +2467,9 @@ export class AstManager {
|
|
|
1220
2467
|
}
|
|
1221
2468
|
|
|
1222
2469
|
isUninterpretedSort(sort: number) {
|
|
1223
|
-
return sort
|
|
2470
|
+
return this.sortFamilies[sort] === FAMILY_USER;
|
|
1224
2471
|
}
|
|
1225
2472
|
|
|
1226
|
-
// An uninterpreted constant, such as a declared constant or a Skolem constant.
|
|
1227
2473
|
isUninterpretedConst(expr: number) {
|
|
1228
2474
|
return this.isUninterpreted(expr) && this.getNumArgs(expr) === 0;
|
|
1229
2475
|
}
|
|
@@ -1232,7 +2478,6 @@ export class AstManager {
|
|
|
1232
2478
|
return this.getFamily(expr) === FAMILY_USER;
|
|
1233
2479
|
}
|
|
1234
2480
|
|
|
1235
|
-
// arith_util::is_times_minus_one: the t of (* -1 t).
|
|
1236
2481
|
getTimesMinusOneArg(expr: number) {
|
|
1237
2482
|
if (this.getOp(expr) !== OP_MUL || this.getNumArgs(expr) !== 2) return undefined;
|
|
1238
2483
|
const coefficient = this.getArg(expr, 0);
|
|
@@ -1242,7 +2487,6 @@ export class AstManager {
|
|
|
1242
2487
|
: undefined;
|
|
1243
2488
|
}
|
|
1244
2489
|
|
|
1245
|
-
// occurs: decl is applied somewhere in expr.
|
|
1246
2490
|
isOccurring(decl: number, expr: number) {
|
|
1247
2491
|
return this.someSubterm(expr, (current) => this.decls[current] === decl);
|
|
1248
2492
|
}
|
|
@@ -1251,8 +2495,6 @@ export class AstManager {
|
|
|
1251
2495
|
return this.someSubterm(expr, (current) => this.isModelValue(current));
|
|
1252
2496
|
}
|
|
1253
2497
|
|
|
1254
|
-
// for_each_expr: visits the subterms with a stack of its own, so deep terms do not exhaust the call
|
|
1255
|
-
// stack.
|
|
1256
2498
|
private someSubterm(expr: number, predicate: (expr: number) => boolean) {
|
|
1257
2499
|
const visited = new Set<number>();
|
|
1258
2500
|
const todo = [expr];
|
|
@@ -1300,8 +2542,10 @@ export class AstManager {
|
|
|
1300
2542
|
if (kind === KIND_VAR) return `(:var ${this.values[expr]})`;
|
|
1301
2543
|
if (kind === KIND_QUANTIFIER) {
|
|
1302
2544
|
const data = this.getQuantifier(expr);
|
|
1303
|
-
return `(${
|
|
2545
|
+
return `(${["forall", "exists", "lambda"][data.kind]} (${data.sorts.length}) ${this.toString(data.body)})`;
|
|
1304
2546
|
}
|
|
2547
|
+
if (this.getOp(expr) === OP_BV_NUM)
|
|
2548
|
+
return `(_ bv${this.getBvNumeralValue(expr)} ${this.getBvSize(this.sorts[expr])})`;
|
|
1305
2549
|
if (this.getOp(expr) === OP_NUM) {
|
|
1306
2550
|
const value = this.getRationalValue(expr);
|
|
1307
2551
|
if (this.sorts[expr] === SORT_INT) return String(value.num);
|