tla-ts 0.0.9-dev.8298a52 → 0.0.10-dev.06b481ee0
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 +8 -0
- package/dist/compile.cjs +6 -6
- package/dist/compile.js +10 -10
- package/dist/deciders.cjs +41 -37
- package/dist/deciders.js +57 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +121 -12
- package/dist/index.d.ts +121 -12
- 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 +144 -31
- package/dist/run.js +144 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +134 -104
- package/dist/transfer.js +134 -104
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +56 -60
- package/src/bags.ts +128 -110
- package/src/builtins.ts +31 -77
- package/src/bundled-modules.ts +1 -8
- package/src/check-failure.ts +118 -0
- package/src/check-trace.ts +320 -0
- package/src/check.ts +1155 -900
- package/src/cli/options.ts +12 -32
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +100 -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 +701 -0
- package/src/cli/tlc-usage.ts +360 -0
- package/src/cli/tlc.ts +318 -656
- package/src/cli/typescript.ts +0 -3
- package/src/cli/xml-exporter.ts +27 -49
- package/src/cli.ts +0 -1
- package/src/codegen.ts +217 -82
- package/src/config.ts +140 -109
- package/src/coverage.ts +1019 -0
- package/src/dependencies.ts +101 -66
- package/src/dfid.ts +683 -0
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +260 -371
- package/src/errors.ts +93 -58
- package/src/evaluate.ts +848 -374
- package/src/exit-codes.ts +63 -13
- package/src/fingerprints.ts +75 -11
- package/src/index.ts +3 -0
- package/src/instances.ts +97 -43
- package/src/java-hash.ts +21 -0
- package/src/java-overrides.ts +6 -21
- package/src/json-reader.ts +455 -0
- package/src/json.ts +252 -139
- package/src/levels.ts +231 -154
- package/src/lexer.ts +83 -101
- package/src/liveness-checker.ts +743 -325
- package/src/liveness.ts +224 -131
- 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 +39 -20
- package/src/obligations/levels.ts +27 -18
- package/src/obligations/module.ts +28 -55
- package/src/obligations/normalize.ts +31 -41
- package/src/obligations/operators.ts +0 -3
- package/src/obligations/pragma.ts +52 -24
- package/src/obligations/printer.ts +94 -63
- 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 +121 -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 +34 -57
- package/src/parallel.ts +62 -72
- package/src/parser.ts +1184 -531
- 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 +226 -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 +1 -15
- package/src/prover/isabelle/provers/classical.ts +58 -61
- package/src/prover/isabelle/provers/hypsubst.ts +29 -54
- 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 +34 -77
- 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 +4 -47
- 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 +26 -31
- 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 +1021 -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 +626 -56
- 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 +319 -0
- package/src/prover/smt/solver/array.ts +1 -3
- package/src/prover/smt/solver/asserted-formulas.ts +241 -99
- package/src/prover/smt/solver/ast-lt.ts +165 -21
- package/src/prover/smt/solver/ast-util.ts +160 -7
- package/src/prover/smt/solver/ast.ts +1480 -184
- package/src/prover/smt/solver/auf-solver.ts +30 -56
- package/src/prover/smt/solver/bit-blast-tactic.ts +608 -0
- package/src/prover/smt/solver/bit-blaster.ts +871 -0
- package/src/prover/smt/solver/blast-term-ite.ts +47 -0
- package/src/prover/smt/solver/bound-manager.ts +196 -0
- package/src/prover/smt/solver/bound-simplifier.ts +598 -0
- package/src/prover/smt/solver/bv-bound-chk.ts +492 -0
- package/src/prover/smt/solver/bv-decl-plugin.ts +341 -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 +127 -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 +293 -0
- package/src/prover/smt/solver/conflict-resolution.ts +78 -11
- package/src/prover/smt/solver/context.ts +600 -187
- package/src/prover/smt/solver/ctx-simplify.ts +34 -52
- package/src/prover/smt/solver/ctx-solver-simplify.ts +122 -0
- package/src/prover/smt/solver/datatype-decl-plugin.ts +580 -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 +93 -0
- package/src/prover/smt/solver/der.ts +39 -30
- package/src/prover/smt/solver/diff-neq.ts +205 -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 +296 -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-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-small-bv-tactic.ts +129 -0
- package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +542 -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 +901 -0
- package/src/prover/smt/solver/euf/euf-solver.ts +1204 -0
- package/src/prover/smt/solver/euf/fpa-solver.ts +317 -0
- package/src/prover/smt/solver/euf/mam.ts +1046 -0
- package/src/prover/smt/solver/euf/q-ematch.ts +829 -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 +328 -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 +271 -0
- package/src/prover/smt/solver/factor.ts +163 -0
- package/src/prover/smt/solver/fd-solver.ts +734 -0
- package/src/prover/smt/solver/fingerprints.ts +15 -26
- package/src/prover/smt/solver/fix-dl-var.ts +147 -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 +639 -0
- package/src/prover/smt/solver/fpa2bv-converter.ts +2251 -0
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +349 -0
- package/src/prover/smt/solver/fpa2bv-tactic.ts +73 -0
- package/src/prover/smt/solver/goal.ts +179 -28
- package/src/prover/smt/solver/goal2nlsat.ts +216 -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 +30 -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 +113 -133
- 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 +355 -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 +18 -31
- package/src/prover/smt/solver/lp/core-solver.ts +35 -37
- package/src/prover/smt/solver/lp/cross-nested.ts +4 -21
- 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 +70 -83
- package/src/prover/smt/solver/lp/lar-term.ts +0 -5
- package/src/prover/smt/solver/lp/lp-settings.ts +6 -16
- package/src/prover/smt/solver/lp/maximize-term.ts +76 -52
- package/src/prover/smt/solver/lp/nex-creator.ts +7 -30
- package/src/prover/smt/solver/lp/nex.ts +2 -7
- 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 +92 -136
- 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 +177 -149
- 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 +164 -147
- package/src/prover/smt/solver/lp/numeric-pair.ts +0 -4
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -5
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +61 -34
- package/src/prover/smt/solver/lp/pdd-solver.ts +74 -72
- package/src/prover/smt/solver/lp/pdd.ts +730 -358
- 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 +310 -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 +106 -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 +20 -63
- package/src/prover/smt/solver/model-evaluator.ts +192 -40
- package/src/prover/smt/solver/model-finder.ts +14 -32
- package/src/prover/smt/solver/model-generator.ts +104 -46
- 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 +709 -0
- package/src/prover/smt/solver/mus.ts +50 -0
- package/src/prover/smt/solver/muz/dl-context.ts +382 -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 +495 -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 +214 -0
- package/src/prover/smt/solver/muz/rule-properties.ts +359 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +1404 -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 +219 -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 +357 -236
- package/src/prover/smt/solver/nlsat/atoms.ts +73 -54
- package/src/prover/smt/solver/nlsat/evaluator.ts +16 -22
- package/src/prover/smt/solver/nlsat/explain.ts +429 -275
- package/src/prover/smt/solver/nlsat/interval-set.ts +9 -51
- package/src/prover/smt/solver/nlsat/levelwise.ts +477 -344
- package/src/prover/smt/solver/nlsat/mpbq.ts +47 -14
- package/src/prover/smt/solver/nlsat/polynomial.ts +2385 -832
- package/src/prover/smt/solver/nlsat/solver.ts +297 -156
- package/src/prover/smt/solver/nlsat/transcendental-eval.ts +310 -0
- package/src/prover/smt/solver/nlsat/transcendentals.ts +391 -0
- package/src/prover/smt/solver/nlsat/types.ts +0 -9
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +9 -51
- package/src/prover/smt/solver/nlsat/upolynomial.ts +49 -109
- package/src/prover/smt/solver/nlsat-tactic.ts +82 -0
- package/src/prover/smt/solver/nnf.ts +112 -61
- 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 +801 -0
- package/src/prover/smt/solver/opt-nlsat.ts +386 -0
- package/src/prover/smt/solver/opt-pareto.ts +301 -0
- package/src/prover/smt/solver/opt-preprocess.ts +101 -0
- package/src/prover/smt/solver/opt-solver.ts +312 -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 +281 -0
- package/src/prover/smt/solver/pb2bv-tactic.ts +540 -0
- package/src/prover/smt/solver/poly-rewriter.ts +261 -79
- package/src/prover/smt/solver/probes.ts +577 -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/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +1096 -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 +41 -51
- package/src/prover/smt/solver/qe-mbp.ts +270 -0
- package/src/prover/smt/solver/qe.ts +1499 -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 +829 -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 +22 -32
- 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 +262 -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 +59 -135
- package/src/prover/smt/solver/rewriter.ts +507 -144
- package/src/prover/smt/solver/rlimit.ts +46 -24
- 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 +579 -0
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +464 -0
- package/src/prover/smt/solver/sat/model-converter.ts +136 -0
- package/src/prover/smt/solver/sat/pb-constraint.ts +268 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +1596 -0
- package/src/prover/smt/solver/sat/probing.ts +170 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +53 -0
- package/src/prover/smt/solver/sat/sat2goal.ts +189 -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 +2107 -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 +995 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +819 -0
- package/src/prover/smt/solver/seq-derive.ts +1298 -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 +730 -0
- package/src/prover/smt/solver/seq-range-predicate.ts +235 -0
- package/src/prover/smt/solver/seq-re-rewriter.ts +1171 -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 +2404 -0
- package/src/prover/smt/solver/seq-skolem.ts +294 -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 +124 -0
- package/src/prover/smt/solver/smt-logics.ts +66 -0
- package/src/prover/smt/solver/smt-setup.ts +589 -0
- package/src/prover/smt/solver/smt2-printer.ts +765 -0
- package/src/prover/smt/solver/smtlib-parser.ts +3546 -406
- package/src/prover/smt/solver/smtlib-script.ts +2134 -0
- package/src/prover/smt/solver/solve-eqs.ts +928 -0
- package/src/prover/smt/solver/solver.ts +129 -38
- 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 +2141 -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 +1210 -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 +60 -91
- package/src/prover/smt/solver/theory-lra-internalize.ts +96 -53
- package/src/prover/smt/solver/theory-lra-model.ts +23 -53
- package/src/prover/smt/solver/theory-lra-propagate.ts +34 -42
- package/src/prover/smt/solver/theory-lra-state.ts +7 -28
- package/src/prover/smt/solver/theory-lra.ts +189 -9
- package/src/prover/smt/solver/theory-pb.ts +951 -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 +852 -0
- package/src/prover/smt/solver/theory-seq.ts +961 -0
- package/src/prover/smt/solver/theory-without-terms.ts +24 -0
- package/src/prover/smt/solver/theory.ts +189 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +486 -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 +74 -48
- 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 +24 -6
- package/src/prover/zenon/expr.ts +29 -28
- package/src/prover/zenon/index-table.ts +33 -61
- package/src/prover/zenon/isar-case.ts +9 -21
- package/src/prover/zenon/isar.ts +37 -67
- 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 +2 -14
- package/src/prover/zenon/proof.ts +0 -11
- package/src/prover/zenon/propositional-rules.ts +0 -7
- package/src/prover/zenon/rules.ts +3 -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 +1132 -430
- package/src/runtime.ts +33 -23
- package/src/sany/builtins.ts +11 -14
- package/src/sany/generation.ts +383 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +688 -0
- package/src/sany/generator-expressions.ts +1108 -0
- package/src/sany/generator-proofs.ts +665 -0
- package/src/sany/generator.ts +192 -2764
- package/src/sany/levels.ts +5 -35
- package/src/sany/lexer.ts +61 -80
- package/src/sany/linter.ts +0 -10
- package/src/sany/modules.ts +5 -7
- package/src/sany/nodes.ts +6 -44
- package/src/sany/parse-error.ts +39 -117
- package/src/sany/report.ts +32 -69
- package/src/sany/selectors.ts +60 -82
- package/src/sany/source.ts +1 -17
- package/src/sany/xml.ts +37 -120
- package/src/search.ts +913 -227
- package/src/simulate.ts +765 -0
- package/src/spec-description.ts +198 -104
- package/src/standard-definitions.ts +4 -4
- package/src/standard-modules.ts +302 -99
- package/src/state-graph.ts +52 -33
- package/src/subexpressions.ts +578 -166
- package/src/substitution-levels.ts +7 -7
- package/src/successors.ts +296 -105
- package/src/symmetry.ts +37 -28
- package/src/tableau.ts +29 -26
- package/src/tlc/fingerprint.ts +267 -79
- package/src/tlc/jar-data.ts +122 -6
- package/src/tlc/messages.ts +127 -56
- package/src/tlc/order.ts +53 -72
- package/src/tlc/random.ts +38 -49
- package/src/tlc/replay.ts +579 -230
- package/src/tlc/summary.ts +64 -60
- package/src/tlc/tlc-operators.ts +83 -47
- package/src/tlc/tlcext-operators.ts +205 -127
- package/src/tlc/trace-spec.ts +235 -0
- package/src/tlc/value-stream.ts +139 -0
- package/src/tlc/version.ts +1 -4
- package/src/trace-liveness.ts +529 -0
- package/src/transfer.ts +22 -25
- package/src/typed-tier.ts +6556 -0
- package/src/typescript/actions.ts +10 -25
- package/src/typescript/collections.ts +34 -35
- package/src/typescript/compile.ts +1 -8
- package/src/typescript/context.ts +0 -12
- package/src/typescript/emit.ts +0 -1
- package/src/typescript/expressions.ts +0 -12
- package/src/typescript/formula.ts +9 -15
- package/src/typescript/functions.ts +6 -17
- package/src/typescript/model.ts +14 -16
- package/src/typescript/names.ts +0 -2
- package/src/typescript/program.ts +0 -3
- package/src/typescript/properties.ts +6 -8
- package/src/typescript/scope.ts +0 -5
- package/src/typescript/steps.ts +20 -28
- package/src/typescript/types.ts +3 -10
- package/src/values.ts +917 -522
- 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,21 @@ 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;
|
|
39
|
+
export const FAMILY_DATALOG_RELATION = 15;
|
|
40
|
+
export const FAMILY_FF = 16;
|
|
41
|
+
export const FAMILY_SPECIAL_RELATIONS = 17;
|
|
24
42
|
|
|
25
43
|
export const OP_TRUE = 0;
|
|
26
44
|
export const OP_FALSE = 1;
|
|
@@ -49,18 +67,281 @@ export const OP_DIV = 23;
|
|
|
49
67
|
export const OP_TO_REAL = 24;
|
|
50
68
|
export const OP_TO_INT = 25;
|
|
51
69
|
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
70
|
export const OP_DIV0 = 27;
|
|
55
71
|
export const OP_IDIV0 = 28;
|
|
56
72
|
export const OP_MOD0 = 29;
|
|
57
|
-
export const
|
|
58
|
-
const
|
|
73
|
+
export const OP_POWER = 30;
|
|
74
|
+
export const OP_POWER0 = 31;
|
|
75
|
+
export const OP_SIN = 32;
|
|
76
|
+
export const OP_COS = 33;
|
|
77
|
+
export const OP_TAN = 34;
|
|
78
|
+
export const OP_ASIN = 35;
|
|
79
|
+
export const OP_ACOS = 36;
|
|
80
|
+
export const OP_ATAN = 37;
|
|
81
|
+
export const OP_SINH = 38;
|
|
82
|
+
export const OP_COSH = 39;
|
|
83
|
+
export const OP_TANH = 40;
|
|
84
|
+
export const OP_ASINH = 41;
|
|
85
|
+
export const OP_ACOSH = 42;
|
|
86
|
+
export const OP_ATANH = 43;
|
|
87
|
+
export const OP_EXP = 44;
|
|
88
|
+
export const OP_ATAN2 = 45;
|
|
89
|
+
export const OP_LOG = 46;
|
|
90
|
+
export const OP_PI = 47;
|
|
91
|
+
export const OP_E = 48;
|
|
92
|
+
export const OP_ALGEBRAIC_NUM = 49;
|
|
93
|
+
export const OP_REM = 50;
|
|
94
|
+
export const OP_NEG_ROOT = 51;
|
|
95
|
+
export const OP_U_ASIN = 52;
|
|
96
|
+
export const OP_U_ACOS = 53;
|
|
97
|
+
export const OP_UNINTERPRETED = 60;
|
|
98
|
+
const OP_MODEL_VALUE = 61;
|
|
99
|
+
|
|
100
|
+
const BV_OP_BASE = 100;
|
|
101
|
+
export const OP_BV_NUM = BV_OP_BASE;
|
|
102
|
+
export const OP_BNEG = BV_OP_BASE + 3;
|
|
103
|
+
export const OP_BADD = BV_OP_BASE + 4;
|
|
104
|
+
export const OP_BSUB = BV_OP_BASE + 5;
|
|
105
|
+
export const OP_BMUL = BV_OP_BASE + 6;
|
|
106
|
+
export const OP_BSDIV = BV_OP_BASE + 7;
|
|
107
|
+
export const OP_BUDIV = BV_OP_BASE + 8;
|
|
108
|
+
export const OP_BSREM = BV_OP_BASE + 9;
|
|
109
|
+
export const OP_BUREM = BV_OP_BASE + 10;
|
|
110
|
+
export const OP_BSMOD = BV_OP_BASE + 11;
|
|
111
|
+
export const OP_BSDIV0 = BV_OP_BASE + 12;
|
|
112
|
+
export const OP_BUDIV0 = BV_OP_BASE + 13;
|
|
113
|
+
export const OP_BSREM0 = BV_OP_BASE + 14;
|
|
114
|
+
export const OP_BUREM0 = BV_OP_BASE + 15;
|
|
115
|
+
export const OP_BSMOD0 = BV_OP_BASE + 16;
|
|
116
|
+
export const OP_BSDIV_I = BV_OP_BASE + 17;
|
|
117
|
+
export const OP_BUDIV_I = BV_OP_BASE + 18;
|
|
118
|
+
export const OP_BSREM_I = BV_OP_BASE + 19;
|
|
119
|
+
export const OP_BUREM_I = BV_OP_BASE + 20;
|
|
120
|
+
export const OP_BSMOD_I = BV_OP_BASE + 21;
|
|
121
|
+
export const OP_ULEQ = BV_OP_BASE + 22;
|
|
122
|
+
export const OP_SLEQ = BV_OP_BASE + 23;
|
|
123
|
+
export const OP_UGEQ = BV_OP_BASE + 24;
|
|
124
|
+
export const OP_SGEQ = BV_OP_BASE + 25;
|
|
125
|
+
export const OP_ULT = BV_OP_BASE + 26;
|
|
126
|
+
export const OP_SLT = BV_OP_BASE + 27;
|
|
127
|
+
export const OP_UGT = BV_OP_BASE + 28;
|
|
128
|
+
export const OP_SGT = BV_OP_BASE + 29;
|
|
129
|
+
export const OP_BAND = BV_OP_BASE + 30;
|
|
130
|
+
export const OP_BOR = BV_OP_BASE + 31;
|
|
131
|
+
export const OP_BNOT = BV_OP_BASE + 32;
|
|
132
|
+
export const OP_BXOR = BV_OP_BASE + 33;
|
|
133
|
+
export const OP_BNAND = BV_OP_BASE + 34;
|
|
134
|
+
export const OP_BNOR = BV_OP_BASE + 35;
|
|
135
|
+
export const OP_BXNOR = BV_OP_BASE + 36;
|
|
136
|
+
export const OP_CONCAT = BV_OP_BASE + 37;
|
|
137
|
+
export const OP_SIGN_EXT = BV_OP_BASE + 38;
|
|
138
|
+
export const OP_ZERO_EXT = BV_OP_BASE + 39;
|
|
139
|
+
export const OP_EXTRACT = BV_OP_BASE + 40;
|
|
140
|
+
export const OP_REPEAT = BV_OP_BASE + 41;
|
|
141
|
+
export const OP_BREDOR = BV_OP_BASE + 42;
|
|
142
|
+
export const OP_BREDAND = BV_OP_BASE + 43;
|
|
143
|
+
export const OP_BCOMP = BV_OP_BASE + 44;
|
|
144
|
+
export const OP_BSHL = BV_OP_BASE + 45;
|
|
145
|
+
export const OP_BLSHR = BV_OP_BASE + 46;
|
|
146
|
+
export const OP_BASHR = BV_OP_BASE + 47;
|
|
147
|
+
export const OP_ROTATE_LEFT = BV_OP_BASE + 48;
|
|
148
|
+
export const OP_ROTATE_RIGHT = BV_OP_BASE + 49;
|
|
149
|
+
export const OP_EXT_ROTATE_LEFT = BV_OP_BASE + 50;
|
|
150
|
+
export const OP_EXT_ROTATE_RIGHT = BV_OP_BASE + 51;
|
|
151
|
+
export const OP_BUMUL_NO_OVFL = BV_OP_BASE + 52;
|
|
152
|
+
export const OP_BSMUL_NO_OVFL = BV_OP_BASE + 53;
|
|
153
|
+
export const OP_BSMUL_NO_UDFL = BV_OP_BASE + 54;
|
|
154
|
+
export const OP_BUMUL_OVFL = BV_OP_BASE + 55;
|
|
155
|
+
export const OP_BSMUL_OVFL = BV_OP_BASE + 56;
|
|
156
|
+
export const OP_BSDIV_OVFL = BV_OP_BASE + 57;
|
|
157
|
+
export const OP_BNEG_OVFL = BV_OP_BASE + 58;
|
|
158
|
+
export const OP_BUADD_OVFL = BV_OP_BASE + 59;
|
|
159
|
+
export const OP_BSADD_OVFL = BV_OP_BASE + 60;
|
|
160
|
+
export const OP_BUSUB_OVFL = BV_OP_BASE + 61;
|
|
161
|
+
export const OP_BSSUB_OVFL = BV_OP_BASE + 62;
|
|
162
|
+
export const OP_BIT2BOOL = BV_OP_BASE + 63;
|
|
163
|
+
export const OP_MKBV = BV_OP_BASE + 64;
|
|
164
|
+
export const OP_INT2BV = BV_OP_BASE + 65;
|
|
165
|
+
export const OP_UBV2INT = BV_OP_BASE + 66;
|
|
166
|
+
export const OP_SBV2INT = BV_OP_BASE + 67;
|
|
167
|
+
export const OP_CARRY = BV_OP_BASE + 68;
|
|
168
|
+
export const OP_XOR3 = BV_OP_BASE + 69;
|
|
169
|
+
|
|
170
|
+
const ARRAY_OP_BASE = 200;
|
|
171
|
+
export const OP_STORE = ARRAY_OP_BASE;
|
|
172
|
+
export const OP_SELECT = ARRAY_OP_BASE + 1;
|
|
173
|
+
export const OP_CONST_ARRAY = ARRAY_OP_BASE + 2;
|
|
174
|
+
export const OP_ARRAY_EXT = ARRAY_OP_BASE + 3;
|
|
175
|
+
export const OP_ARRAY_DEFAULT = ARRAY_OP_BASE + 4;
|
|
176
|
+
export const OP_ARRAY_MAP = ARRAY_OP_BASE + 5;
|
|
177
|
+
export const OP_AS_ARRAY = ARRAY_OP_BASE + 11;
|
|
178
|
+
const DATATYPE_OP_BASE = 300;
|
|
179
|
+
export const OP_DT_CONSTRUCTOR = DATATYPE_OP_BASE;
|
|
180
|
+
export const OP_DT_RECOGNISER = DATATYPE_OP_BASE + 1;
|
|
181
|
+
export const OP_DT_IS = DATATYPE_OP_BASE + 2;
|
|
182
|
+
export const OP_DT_ACCESSOR = DATATYPE_OP_BASE + 3;
|
|
183
|
+
export const OP_DT_UPDATE_FIELD = DATATYPE_OP_BASE + 4;
|
|
184
|
+
const FPA_OP_BASE = 400;
|
|
185
|
+
export const OP_FPA_RM_NEAREST_TIES_TO_EVEN = FPA_OP_BASE;
|
|
186
|
+
export const OP_FPA_RM_NEAREST_TIES_TO_AWAY = FPA_OP_BASE + 1;
|
|
187
|
+
export const OP_FPA_RM_TOWARD_POSITIVE = FPA_OP_BASE + 2;
|
|
188
|
+
export const OP_FPA_RM_TOWARD_NEGATIVE = FPA_OP_BASE + 3;
|
|
189
|
+
export const OP_FPA_RM_TOWARD_ZERO = FPA_OP_BASE + 4;
|
|
190
|
+
export const OP_FPA_NUM = FPA_OP_BASE + 5;
|
|
191
|
+
export const OP_FPA_PLUS_INF = FPA_OP_BASE + 6;
|
|
192
|
+
export const OP_FPA_MINUS_INF = FPA_OP_BASE + 7;
|
|
193
|
+
export const OP_FPA_NAN = FPA_OP_BASE + 8;
|
|
194
|
+
export const OP_FPA_PLUS_ZERO = FPA_OP_BASE + 9;
|
|
195
|
+
export const OP_FPA_MINUS_ZERO = FPA_OP_BASE + 10;
|
|
196
|
+
export const OP_FPA_ADD = FPA_OP_BASE + 11;
|
|
197
|
+
export const OP_FPA_SUB = FPA_OP_BASE + 12;
|
|
198
|
+
export const OP_FPA_NEG = FPA_OP_BASE + 13;
|
|
199
|
+
export const OP_FPA_MUL = FPA_OP_BASE + 14;
|
|
200
|
+
export const OP_FPA_DIV = FPA_OP_BASE + 15;
|
|
201
|
+
export const OP_FPA_REM = FPA_OP_BASE + 16;
|
|
202
|
+
export const OP_FPA_ABS = FPA_OP_BASE + 17;
|
|
203
|
+
export const OP_FPA_MIN = FPA_OP_BASE + 18;
|
|
204
|
+
export const OP_FPA_MAX = FPA_OP_BASE + 19;
|
|
205
|
+
export const OP_FPA_MIN_I = FPA_OP_BASE + 20;
|
|
206
|
+
export const OP_FPA_MAX_I = FPA_OP_BASE + 21;
|
|
207
|
+
export const OP_FPA_FMA = FPA_OP_BASE + 22;
|
|
208
|
+
export const OP_FPA_SQRT = FPA_OP_BASE + 23;
|
|
209
|
+
export const OP_FPA_ROUND_TO_INTEGRAL = FPA_OP_BASE + 24;
|
|
210
|
+
export const OP_FPA_EQ = FPA_OP_BASE + 25;
|
|
211
|
+
export const OP_FPA_LT = FPA_OP_BASE + 26;
|
|
212
|
+
export const OP_FPA_GT = FPA_OP_BASE + 27;
|
|
213
|
+
export const OP_FPA_LE = FPA_OP_BASE + 28;
|
|
214
|
+
export const OP_FPA_GE = FPA_OP_BASE + 29;
|
|
215
|
+
export const OP_FPA_IS_NAN = FPA_OP_BASE + 30;
|
|
216
|
+
export const OP_FPA_IS_INF = FPA_OP_BASE + 31;
|
|
217
|
+
export const OP_FPA_IS_ZERO = FPA_OP_BASE + 32;
|
|
218
|
+
export const OP_FPA_IS_NORMAL = FPA_OP_BASE + 33;
|
|
219
|
+
export const OP_FPA_IS_SUBNORMAL = FPA_OP_BASE + 34;
|
|
220
|
+
export const OP_FPA_IS_NEGATIVE = FPA_OP_BASE + 35;
|
|
221
|
+
export const OP_FPA_IS_POSITIVE = FPA_OP_BASE + 36;
|
|
222
|
+
export const OP_FPA_FP = FPA_OP_BASE + 37;
|
|
223
|
+
export const OP_FPA_TO_FP = FPA_OP_BASE + 38;
|
|
224
|
+
export const OP_FPA_TO_FP_UNSIGNED = FPA_OP_BASE + 39;
|
|
225
|
+
export const OP_FPA_TO_UBV = FPA_OP_BASE + 40;
|
|
226
|
+
export const OP_FPA_TO_SBV = FPA_OP_BASE + 41;
|
|
227
|
+
export const OP_FPA_TO_REAL = FPA_OP_BASE + 42;
|
|
228
|
+
export const OP_FPA_TO_REAL_I = FPA_OP_BASE + 43;
|
|
229
|
+
export const OP_FPA_TO_SBV_I = FPA_OP_BASE + 44;
|
|
230
|
+
export const OP_FPA_TO_UBV_I = FPA_OP_BASE + 45;
|
|
231
|
+
export const OP_FPA_TO_IEEE_BV = FPA_OP_BASE + 46;
|
|
232
|
+
export const OP_FPA_TO_IEEE_BV_I = FPA_OP_BASE + 47;
|
|
233
|
+
export const OP_FPA_BVWRAP = FPA_OP_BASE + 48;
|
|
234
|
+
export const OP_FPA_BV2RM = FPA_OP_BASE + 49;
|
|
235
|
+
const SEQ_OP_BASE = 500;
|
|
236
|
+
export const OP_SEQ_UNIT = SEQ_OP_BASE;
|
|
237
|
+
export const OP_SEQ_EMPTY = SEQ_OP_BASE + 1;
|
|
238
|
+
export const OP_SEQ_CONCAT = SEQ_OP_BASE + 2;
|
|
239
|
+
export const OP_SEQ_PREFIX = SEQ_OP_BASE + 3;
|
|
240
|
+
export const OP_SEQ_SUFFIX = SEQ_OP_BASE + 4;
|
|
241
|
+
export const OP_SEQ_CONTAINS = SEQ_OP_BASE + 5;
|
|
242
|
+
export const OP_SEQ_EXTRACT = SEQ_OP_BASE + 6;
|
|
243
|
+
export const OP_SEQ_REPLACE = SEQ_OP_BASE + 7;
|
|
244
|
+
export const OP_SEQ_AT = SEQ_OP_BASE + 8;
|
|
245
|
+
export const OP_SEQ_NTH = SEQ_OP_BASE + 9;
|
|
246
|
+
export const OP_SEQ_NTH_I = SEQ_OP_BASE + 10;
|
|
247
|
+
export const OP_SEQ_NTH_U = SEQ_OP_BASE + 11;
|
|
248
|
+
export const OP_SEQ_LENGTH = SEQ_OP_BASE + 12;
|
|
249
|
+
export const OP_SEQ_INDEX = SEQ_OP_BASE + 13;
|
|
250
|
+
export const OP_SEQ_LAST_INDEX = SEQ_OP_BASE + 14;
|
|
251
|
+
export const OP_SEQ_TO_RE = SEQ_OP_BASE + 15;
|
|
252
|
+
export const OP_SEQ_IN_RE = SEQ_OP_BASE + 16;
|
|
253
|
+
export const OP_SEQ_REPLACE_RE_ALL = SEQ_OP_BASE + 17;
|
|
254
|
+
export const OP_SEQ_REPLACE_RE = SEQ_OP_BASE + 18;
|
|
255
|
+
export const OP_SEQ_REPLACE_ALL = SEQ_OP_BASE + 19;
|
|
256
|
+
export const OP_SEQ_MAP = SEQ_OP_BASE + 20;
|
|
257
|
+
export const OP_SEQ_MAPI = SEQ_OP_BASE + 21;
|
|
258
|
+
export const OP_SEQ_FOLDL = SEQ_OP_BASE + 22;
|
|
259
|
+
export const OP_SEQ_FOLDLI = SEQ_OP_BASE + 23;
|
|
260
|
+
export const OP_SEQ_POWER = SEQ_OP_BASE + 24;
|
|
261
|
+
export const OP_RE_PLUS = SEQ_OP_BASE + 25;
|
|
262
|
+
export const OP_RE_STAR = SEQ_OP_BASE + 26;
|
|
263
|
+
export const OP_RE_OPTION = SEQ_OP_BASE + 27;
|
|
264
|
+
export const OP_RE_RANGE = SEQ_OP_BASE + 28;
|
|
265
|
+
export const OP_RE_CONCAT = SEQ_OP_BASE + 29;
|
|
266
|
+
export const OP_RE_UNION = SEQ_OP_BASE + 30;
|
|
267
|
+
export const OP_RE_DIFF = SEQ_OP_BASE + 31;
|
|
268
|
+
export const OP_RE_INTERSECT = SEQ_OP_BASE + 32;
|
|
269
|
+
export const OP_RE_XOR = SEQ_OP_BASE + 33;
|
|
270
|
+
export const OP_RE_LOOP = SEQ_OP_BASE + 34;
|
|
271
|
+
export const OP_RE_POWER = SEQ_OP_BASE + 35;
|
|
272
|
+
export const OP_RE_COMPLEMENT = SEQ_OP_BASE + 36;
|
|
273
|
+
export const OP_RE_EMPTY_SET = SEQ_OP_BASE + 37;
|
|
274
|
+
export const OP_RE_FULL_SEQ_SET = SEQ_OP_BASE + 38;
|
|
275
|
+
export const OP_RE_FULL_CHAR_SET = SEQ_OP_BASE + 39;
|
|
276
|
+
export const OP_RE_OF_PRED = SEQ_OP_BASE + 40;
|
|
277
|
+
export const OP_RE_REVERSE = SEQ_OP_BASE + 41;
|
|
278
|
+
export const OP_RE_DERIVATIVE = SEQ_OP_BASE + 42;
|
|
279
|
+
export const OP_STRING_CONST = SEQ_OP_BASE + 43;
|
|
280
|
+
export const OP_STRING_ITOS = SEQ_OP_BASE + 44;
|
|
281
|
+
export const OP_STRING_STOI = SEQ_OP_BASE + 45;
|
|
282
|
+
export const OP_STRING_UBVTOS = SEQ_OP_BASE + 46;
|
|
283
|
+
export const OP_STRING_SBVTOS = SEQ_OP_BASE + 47;
|
|
284
|
+
export const OP_STRING_LT = SEQ_OP_BASE + 48;
|
|
285
|
+
export const OP_STRING_LE = SEQ_OP_BASE + 49;
|
|
286
|
+
export const OP_STRING_IS_DIGIT = SEQ_OP_BASE + 50;
|
|
287
|
+
export const OP_STRING_TO_CODE = SEQ_OP_BASE + 51;
|
|
288
|
+
export const OP_STRING_FROM_CODE = SEQ_OP_BASE + 52;
|
|
289
|
+
export const OP_INTERNAL_STRING_FROM_CHAR = SEQ_OP_BASE + 53;
|
|
290
|
+
export const OP_INTERNAL_STRING_STRREPL = SEQ_OP_BASE + 54;
|
|
291
|
+
export const OP_INTERNAL_STRING_CONCAT = SEQ_OP_BASE + 55;
|
|
292
|
+
export const OP_INTERNAL_STRING_LENGTH = SEQ_OP_BASE + 56;
|
|
293
|
+
export const OP_INTERNAL_STRING_STRCTN = SEQ_OP_BASE + 57;
|
|
294
|
+
export const OP_INTERNAL_STRING_PREFIX = SEQ_OP_BASE + 58;
|
|
295
|
+
export const OP_INTERNAL_STRING_SUFFIX = SEQ_OP_BASE + 59;
|
|
296
|
+
export const OP_INTERNAL_STRING_IN_REGEXP = SEQ_OP_BASE + 60;
|
|
297
|
+
export const OP_INTERNAL_STRING_TO_REGEXP = SEQ_OP_BASE + 61;
|
|
298
|
+
export const OP_INTERNAL_STRING_CHARAT = SEQ_OP_BASE + 62;
|
|
299
|
+
export const OP_INTERNAL_STRING_SUBSTR = SEQ_OP_BASE + 63;
|
|
300
|
+
export const OP_INTERNAL_STRING_STRIDOF = SEQ_OP_BASE + 64;
|
|
301
|
+
export const OP_INTERNAL_STRING_POWER = SEQ_OP_BASE + 65;
|
|
302
|
+
export const OP_INTERNAL_REGEXP_EMPTY = SEQ_OP_BASE + 66;
|
|
303
|
+
export const OP_INTERNAL_REGEXP_FULL_CHAR = SEQ_OP_BASE + 67;
|
|
304
|
+
export const OP_SEQ_SKOLEM = SEQ_OP_BASE + 69;
|
|
305
|
+
const CHAR_OP_BASE = 600;
|
|
306
|
+
export const OP_CHAR_CONST = CHAR_OP_BASE;
|
|
307
|
+
export const OP_CHAR_LE = CHAR_OP_BASE + 1;
|
|
308
|
+
export const OP_CHAR_TO_INT = CHAR_OP_BASE + 2;
|
|
309
|
+
export const OP_CHAR_TO_BV = CHAR_OP_BASE + 3;
|
|
310
|
+
export const OP_CHAR_FROM_BV = CHAR_OP_BASE + 4;
|
|
311
|
+
export const OP_CHAR_IS_DIGIT = CHAR_OP_BASE + 5;
|
|
312
|
+
const LABEL_OP_BASE = 700;
|
|
313
|
+
export const OP_LABEL = LABEL_OP_BASE;
|
|
314
|
+
export const OP_LABEL_LIT = LABEL_OP_BASE + 1;
|
|
315
|
+
const PB_OP_BASE = 800;
|
|
316
|
+
export const OP_AT_MOST_K = PB_OP_BASE;
|
|
317
|
+
export const OP_AT_LEAST_K = PB_OP_BASE + 1;
|
|
318
|
+
export const OP_PB_LE = PB_OP_BASE + 2;
|
|
319
|
+
export const OP_PB_GE = PB_OP_BASE + 3;
|
|
320
|
+
export const OP_PB_EQ = PB_OP_BASE + 4;
|
|
321
|
+
export const OP_PB_AUX_BOOL = PB_OP_BASE + 5;
|
|
322
|
+
const RECFUN_OP_BASE = 900;
|
|
323
|
+
export const OP_FUN_DEFINED = RECFUN_OP_BASE;
|
|
324
|
+
export const OP_FUN_CASE_PRED = RECFUN_OP_BASE + 1;
|
|
325
|
+
export const OP_NUM_ROUNDS = RECFUN_OP_BASE + 2;
|
|
326
|
+
|
|
327
|
+
// The number of elements of a sort, with -1 for an infinite sort and -2 for a very big one.
|
|
328
|
+
export const SORT_SIZE_INFINITE = -1n;
|
|
329
|
+
export const SORT_SIZE_VERY_BIG = -2n;
|
|
330
|
+
|
|
331
|
+
const UNCACHED_BV_OPS: ReadonlySet<number> = new Set([
|
|
332
|
+
OP_CONCAT,
|
|
333
|
+
OP_SIGN_EXT,
|
|
334
|
+
OP_ZERO_EXT,
|
|
335
|
+
OP_EXTRACT,
|
|
336
|
+
OP_REPEAT,
|
|
337
|
+
OP_ROTATE_LEFT,
|
|
338
|
+
OP_ROTATE_RIGHT,
|
|
339
|
+
]);
|
|
59
340
|
|
|
60
|
-
// A Z3 symbol: a string, or a number for a numerical symbol, which Z3 prints as k!n.
|
|
61
341
|
export type SmtSymbol = string | number;
|
|
62
342
|
|
|
63
|
-
const getSymbolName = (symbol: SmtSymbol) =>
|
|
343
|
+
export const getSymbolName = (symbol: SmtSymbol) =>
|
|
344
|
+
typeof symbol === "number" ? `k!${symbol}` : symbol;
|
|
64
345
|
|
|
65
346
|
export interface FuncDecl {
|
|
66
347
|
name: SmtSymbol;
|
|
@@ -69,20 +350,36 @@ export interface FuncDecl {
|
|
|
69
350
|
domain: number[];
|
|
70
351
|
range: number;
|
|
71
352
|
isSkolem: boolean;
|
|
72
|
-
// Z3's small id of the declaration, which its matcher hashes.
|
|
73
353
|
smallId: number;
|
|
354
|
+
parameters: number[];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// The rhs of a definition is -1 until its body is parsed.
|
|
358
|
+
export interface RecFunDef {
|
|
359
|
+
decl: number;
|
|
360
|
+
rhs: number;
|
|
361
|
+
isMacro: boolean;
|
|
362
|
+
cases: RecFunCase[];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export interface RecFunCase {
|
|
366
|
+
pred: number;
|
|
367
|
+
guards: number[];
|
|
368
|
+
rhs: number;
|
|
369
|
+
isImmediate: boolean;
|
|
370
|
+
def: RecFunDef;
|
|
74
371
|
}
|
|
75
372
|
|
|
76
373
|
interface QuantifierData {
|
|
77
|
-
|
|
374
|
+
kind: number;
|
|
78
375
|
sorts: number[];
|
|
79
|
-
// The names of the variables, which tell apart quantifiers that differ only in them, as in Z3.
|
|
80
376
|
names: SmtSymbol[];
|
|
81
377
|
body: number;
|
|
82
|
-
// Applications of the pattern declaration to the terms of each multi-pattern.
|
|
83
378
|
patterns: number[];
|
|
379
|
+
noPatterns: number[];
|
|
84
380
|
weight: number;
|
|
85
381
|
qid: string;
|
|
382
|
+
skid?: string;
|
|
86
383
|
}
|
|
87
384
|
|
|
88
385
|
const BUILTIN_DECLS: [string, number, number, number][] = [
|
|
@@ -116,18 +413,51 @@ const BUILTIN_DECLS: [string, number, number, number][] = [
|
|
|
116
413
|
["/0", FAMILY_ARITH, OP_DIV0, SORT_REAL],
|
|
117
414
|
["div0", FAMILY_ARITH, OP_IDIV0, SORT_INT],
|
|
118
415
|
["mod0", FAMILY_ARITH, OP_MOD0, SORT_INT],
|
|
416
|
+
["^", FAMILY_ARITH, OP_POWER, SORT_REAL],
|
|
417
|
+
["^0", FAMILY_ARITH, OP_POWER0, SORT_REAL],
|
|
418
|
+
["sin", FAMILY_ARITH, OP_SIN, SORT_REAL],
|
|
419
|
+
["cos", FAMILY_ARITH, OP_COS, SORT_REAL],
|
|
420
|
+
["tan", FAMILY_ARITH, OP_TAN, SORT_REAL],
|
|
421
|
+
["asin", FAMILY_ARITH, OP_ASIN, SORT_REAL],
|
|
422
|
+
["acos", FAMILY_ARITH, OP_ACOS, SORT_REAL],
|
|
423
|
+
["atan", FAMILY_ARITH, OP_ATAN, SORT_REAL],
|
|
424
|
+
["sinh", FAMILY_ARITH, OP_SINH, SORT_REAL],
|
|
425
|
+
["cosh", FAMILY_ARITH, OP_COSH, SORT_REAL],
|
|
426
|
+
["tanh", FAMILY_ARITH, OP_TANH, SORT_REAL],
|
|
427
|
+
["asinh", FAMILY_ARITH, OP_ASINH, SORT_REAL],
|
|
428
|
+
["acosh", FAMILY_ARITH, OP_ACOSH, SORT_REAL],
|
|
429
|
+
["atanh", FAMILY_ARITH, OP_ATANH, SORT_REAL],
|
|
430
|
+
["exp", FAMILY_ARITH, OP_EXP, SORT_REAL],
|
|
431
|
+
["atan2", FAMILY_ARITH, OP_ATAN2, SORT_REAL],
|
|
432
|
+
["log", FAMILY_ARITH, OP_LOG, SORT_REAL],
|
|
433
|
+
["pi", FAMILY_ARITH, OP_PI, SORT_REAL],
|
|
434
|
+
["euler", FAMILY_ARITH, OP_E, SORT_REAL],
|
|
435
|
+
["RootObject", FAMILY_ARITH, OP_ALGEBRAIC_NUM, SORT_REAL],
|
|
436
|
+
["rem", FAMILY_ARITH, OP_REM, SORT_INT],
|
|
437
|
+
["neg-root", FAMILY_ARITH, OP_NEG_ROOT, SORT_REAL],
|
|
438
|
+
["asin-u", FAMILY_ARITH, OP_U_ASIN, SORT_REAL],
|
|
439
|
+
["acos-u", FAMILY_ARITH, OP_U_ACOS, SORT_REAL],
|
|
119
440
|
];
|
|
120
441
|
|
|
121
|
-
// Z3's family ids and decl kinds, which its AST hashes include.
|
|
122
442
|
const Z3_BASIC_FAMILY = 0;
|
|
443
|
+
const Z3_LABEL_FAMILY = 1;
|
|
123
444
|
const Z3_PATTERN_FAMILY = 2;
|
|
124
445
|
const Z3_MODEL_VALUE_FAMILY = 3;
|
|
125
446
|
const Z3_USER_SORT_FAMILY = 4;
|
|
126
447
|
const Z3_ARITH_FAMILY = 5;
|
|
448
|
+
const Z3_BV_FAMILY = 8;
|
|
449
|
+
const Z3_ARRAY_FAMILY = 9;
|
|
450
|
+
const Z3_DATATYPE_FAMILY = 7;
|
|
127
451
|
const Z3_RECFUN_FAMILY = 10;
|
|
452
|
+
const Z3_CHAR_FAMILY = 11;
|
|
453
|
+
const Z3_SEQ_FAMILY = 12;
|
|
454
|
+
const Z3_PB_FAMILY = 13;
|
|
455
|
+
const Z3_FPA_FAMILY = 14;
|
|
456
|
+
const Z3_SEQ_SORT = 0;
|
|
457
|
+
const Z3_RE_SORT = 1;
|
|
458
|
+
const Z3_FLOATING_POINT_SORT = 0;
|
|
459
|
+
const Z3_ROUNDING_MODE_SORT = 1;
|
|
128
460
|
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
461
|
const Z3_BUILTINS = new Map<number, [string, number, number]>([
|
|
132
462
|
[OP_TRUE, ["true", 0, 0]],
|
|
133
463
|
[OP_FALSE, ["false", 1, 0]],
|
|
@@ -149,6 +479,7 @@ const Z3_BUILTINS = new Map<number, [string, number, number]>([
|
|
|
149
479
|
[OP_MUL, ["*", 9, 2]],
|
|
150
480
|
[OP_IDIV, ["div", 11, 2]],
|
|
151
481
|
[OP_MOD, ["mod", 16, 2]],
|
|
482
|
+
[OP_REM, ["rem", 15, 2]],
|
|
152
483
|
[OP_ABS, ["abs", 21, 1]],
|
|
153
484
|
[OP_PATTERN, ["pattern", 0, -1]],
|
|
154
485
|
[OP_DIV, ["/", 10, 2]],
|
|
@@ -158,13 +489,30 @@ const Z3_BUILTINS = new Map<number, [string, number, number]>([
|
|
|
158
489
|
[OP_DIV0, ["/0", 12, 2]],
|
|
159
490
|
[OP_IDIV0, ["div0", 13, 2]],
|
|
160
491
|
[OP_MOD0, ["mod0", 17, 2]],
|
|
492
|
+
[OP_POWER, ["^", 22, 2]],
|
|
493
|
+
[OP_POWER0, ["^0", 23, 2]],
|
|
494
|
+
[OP_SIN, ["sin", 24, 1]],
|
|
495
|
+
[OP_COS, ["cos", 25, 1]],
|
|
496
|
+
[OP_TAN, ["tan", 26, 1]],
|
|
497
|
+
[OP_ASIN, ["asin", 27, 1]],
|
|
498
|
+
[OP_ACOS, ["acos", 28, 1]],
|
|
499
|
+
[OP_ATAN, ["atan", 29, 1]],
|
|
500
|
+
[OP_SINH, ["sinh", 30, 1]],
|
|
501
|
+
[OP_COSH, ["cosh", 31, 1]],
|
|
502
|
+
[OP_TANH, ["tanh", 32, 1]],
|
|
503
|
+
[OP_ASINH, ["asinh", 33, 1]],
|
|
504
|
+
[OP_ACOSH, ["acosh", 34, 1]],
|
|
505
|
+
[OP_ATANH, ["atanh", 35, 1]],
|
|
506
|
+
[OP_EXP, ["exp", 36, 1]],
|
|
507
|
+
[OP_ATAN2, ["atan2", 37, 2]],
|
|
508
|
+
[OP_LOG, ["log", 38, 1]],
|
|
509
|
+
[OP_PI, ["pi", 43, 0]],
|
|
510
|
+
[OP_E, ["euler", 44, 0]],
|
|
511
|
+
[OP_NEG_ROOT, ["neg-root", 45, 2]],
|
|
512
|
+
[OP_U_ASIN, ["asin-u", 46, 1]],
|
|
513
|
+
[OP_U_ACOS, ["acos-u", 47, 1]],
|
|
161
514
|
]);
|
|
162
515
|
|
|
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
516
|
const Z3_SMALL_IDS = new Map([
|
|
169
517
|
[OP_TRUE, 1],
|
|
170
518
|
[OP_FALSE, 2],
|
|
@@ -181,6 +529,7 @@ const Z3_SMALL_IDS = new Map([
|
|
|
181
529
|
[OP_SUB, 37],
|
|
182
530
|
[OP_MUL, 38],
|
|
183
531
|
[OP_IDIV, 39],
|
|
532
|
+
[OP_REM, 40],
|
|
184
533
|
[OP_MOD, 41],
|
|
185
534
|
[OP_UMINUS, 42],
|
|
186
535
|
[OP_ABS, 50],
|
|
@@ -188,28 +537,42 @@ const Z3_SMALL_IDS = new Map([
|
|
|
188
537
|
[OP_TO_REAL, 43],
|
|
189
538
|
[OP_TO_INT, 45],
|
|
190
539
|
[OP_IS_INT, 47],
|
|
540
|
+
[OP_POWER, 48],
|
|
541
|
+
[OP_SIN, 52],
|
|
542
|
+
[OP_COS, 53],
|
|
543
|
+
[OP_TAN, 54],
|
|
544
|
+
[OP_ASIN, 55],
|
|
545
|
+
[OP_ACOS, 56],
|
|
546
|
+
[OP_ATAN, 57],
|
|
547
|
+
[OP_SINH, 58],
|
|
548
|
+
[OP_COSH, 59],
|
|
549
|
+
[OP_TANH, 60],
|
|
550
|
+
[OP_ASINH, 61],
|
|
551
|
+
[OP_ACOSH, 62],
|
|
552
|
+
[OP_ATANH, 63],
|
|
553
|
+
[OP_EXP, 64],
|
|
554
|
+
[OP_ATAN2, 65],
|
|
555
|
+
[OP_LOG, 66],
|
|
556
|
+
[OP_PI, 67],
|
|
557
|
+
[OP_E, 68],
|
|
558
|
+
[OP_NEG_ROOT, 69],
|
|
559
|
+
[OP_U_ASIN, 70],
|
|
560
|
+
[OP_U_ACOS, 71],
|
|
191
561
|
]);
|
|
192
562
|
|
|
193
|
-
// The small id of the first sort or declaration a problem declares, after Z3's own.
|
|
194
563
|
const FIRST_DECLARED_SMALL_ID = 143;
|
|
195
564
|
|
|
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
565
|
const FIRST_FREE_ID = 22;
|
|
199
|
-
// MAX_SMALL_NUM_TO_CACHE: arith_decl_plugin holds the numerals below it once it makes them.
|
|
200
566
|
const MAX_SMALL_NUM_TO_CACHE = 16;
|
|
201
|
-
// The sorts that finite_set_decl_plugin::init makes.
|
|
202
567
|
const NUM_FINITE_SET_PLUGIN_SORTS = 7;
|
|
203
568
|
|
|
204
|
-
|
|
205
|
-
|
|
569
|
+
const PB_OP_NAMES = ["at-most", "at-least", "pble", "pbge", "pbeq"];
|
|
570
|
+
|
|
571
|
+
export const getSymbolHash = (symbol: SmtSymbol) =>
|
|
206
572
|
typeof symbol === "number" ? symbol : stringHash(symbol, 17);
|
|
207
573
|
|
|
208
|
-
// Whether a sort is Int or Real.
|
|
209
574
|
export const isArithSort = (sort: number) => sort === SORT_INT || sort === SORT_REAL;
|
|
210
575
|
|
|
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
576
|
const getIntegerHash = (value: bigint) => {
|
|
214
577
|
const magnitude = value < 0n ? -value : value;
|
|
215
578
|
if (magnitude <= 0xffffffffn) return Number(magnitude);
|
|
@@ -218,115 +581,158 @@ const getIntegerHash = (value: bigint) => {
|
|
|
218
581
|
return bytesHash(new Uint8Array(Uint32Array.from(digits).buffer), 17);
|
|
219
582
|
};
|
|
220
583
|
|
|
221
|
-
// decl_info::hash.
|
|
222
584
|
const getInfoHash = (family: number, kind: number, parameterHashes: number[]) =>
|
|
223
585
|
mkMix(family, kind, parameterHashes.length === 0 ? 0 : getCompositeHash(parameterHashes));
|
|
224
586
|
|
|
225
|
-
// The kinds of an integer signature, in its low three bits.
|
|
226
587
|
const SIGNATURE_EQ = 0;
|
|
227
588
|
const SIGNATURE_ITE = 1;
|
|
228
589
|
const SIGNATURE_DIV0 = 2;
|
|
229
590
|
const SIGNATURE_MODEL_VALUE = 3;
|
|
230
591
|
const SIGNATURE_NUMERAL = 4;
|
|
592
|
+
const SIGNATURE_ALGEBRAIC = 5;
|
|
593
|
+
|
|
594
|
+
interface AlgebraicNumeral {
|
|
595
|
+
value: Anum;
|
|
596
|
+
id: number;
|
|
597
|
+
}
|
|
231
598
|
|
|
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
599
|
interface SignatureDecl {
|
|
235
600
|
smallId: number;
|
|
236
601
|
refCount: number;
|
|
237
602
|
}
|
|
238
603
|
|
|
604
|
+
const hasOwnDeclHash = (family: number) =>
|
|
605
|
+
family === FAMILY_USER ||
|
|
606
|
+
family === FAMILY_BV ||
|
|
607
|
+
family === FAMILY_ARRAY ||
|
|
608
|
+
family === FAMILY_DATATYPE ||
|
|
609
|
+
family === FAMILY_FPA ||
|
|
610
|
+
family === FAMILY_CHAR ||
|
|
611
|
+
family === FAMILY_SEQ ||
|
|
612
|
+
family === FAMILY_LABEL ||
|
|
613
|
+
family === FAMILY_PB ||
|
|
614
|
+
family === FAMILY_RECFUN;
|
|
615
|
+
|
|
616
|
+
// The declarations that Z3 makes once and counts references to, rather than on each use.
|
|
617
|
+
const isDeclared = (funcDecl: FuncDecl) =>
|
|
618
|
+
funcDecl.family === FAMILY_USER ||
|
|
619
|
+
funcDecl.family === FAMILY_RECFUN ||
|
|
620
|
+
funcDecl.op === OP_PB_AUX_BOOL;
|
|
621
|
+
|
|
239
622
|
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
623
|
private numNodes = 0;
|
|
244
624
|
kinds = new Uint8Array(1024);
|
|
245
|
-
// The declaration of an application.
|
|
246
625
|
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
626
|
private argPool = new Int32Array(1024);
|
|
251
627
|
private argStarts = new Int32Array(1024);
|
|
252
628
|
sorts = new Int32Array(1024);
|
|
253
|
-
// The index of a variable or model value, or of a numeral's value in numeralValues.
|
|
254
629
|
values = new Int32Array(1024);
|
|
255
630
|
private numeralValues: Rational[] = [];
|
|
256
|
-
//
|
|
631
|
+
// An irrational numeral is never shared: each takes a fresh id, which its deletion frees.
|
|
632
|
+
private algebraicNumerals: AlgebraicNumeral[] = [];
|
|
633
|
+
private freeAlgebraicIds: number[] = [];
|
|
634
|
+
private nextAlgebraicId = 0;
|
|
635
|
+
private algebraicManager: AlgebraicManager | undefined;
|
|
257
636
|
private intNumerals = new Map<bigint, number>();
|
|
258
|
-
// One more than the largest free de Bruijn index, so 0 means the expression is ground.
|
|
259
637
|
freeVarBounds = new Int32Array(1024);
|
|
260
638
|
hasQuantifierFlags = new Uint8Array(1024);
|
|
639
|
+
hasLabelFlags = new Uint8Array(1024);
|
|
261
640
|
depths = new Int32Array(1024);
|
|
262
|
-
// Z3's hash of each expression, which orders Z3's hash tables.
|
|
263
641
|
hashes = new Uint32Array(1024);
|
|
264
642
|
quantifiers = new Map<number, QuantifierData>();
|
|
265
|
-
// The marks that the rewriters of this manager share to flatten conjunctions and disjunctions.
|
|
266
643
|
readonly flatLiterals = new FlatLiterals(this);
|
|
267
644
|
funcDecls: FuncDecl[] = [];
|
|
268
645
|
sortNames: string[] = ["Bool", "Int", "Real"];
|
|
646
|
+
private sortFamilies: number[] = [FAMILY_BASIC, FAMILY_ARITH, FAMILY_ARITH];
|
|
647
|
+
private sortWidths: number[] = [0, 0, 0];
|
|
648
|
+
private sortSbits: number[] = [0, 0, 0];
|
|
649
|
+
private sortParameters: number[][] = [[], [], []];
|
|
650
|
+
private sortSizes: bigint[] = [2n, SORT_SIZE_INFINITE, SORT_SIZE_INFINITE];
|
|
651
|
+
private arraySorts = new Map<string, number>();
|
|
652
|
+
private arrayDecls = new Map<string, number>();
|
|
653
|
+
readonly datatypeDefs = new Map<string, DatatypeDef>();
|
|
654
|
+
hasNestedRecDatatype = false;
|
|
655
|
+
datatypeConstructors: number[][] = [];
|
|
656
|
+
constructorAccessors: number[][] = [];
|
|
657
|
+
constructorRecognizers: number[] = [];
|
|
658
|
+
nonRecConstructors: number[] = [];
|
|
659
|
+
nonRecDepths: number[] = [];
|
|
660
|
+
private parametricSorts = new Map<string, number>();
|
|
661
|
+
private datatypeDecls = new Map<string, number>();
|
|
662
|
+
private userSortKinds = new Map<SmtSymbol, number>();
|
|
663
|
+
private sortSmallIds: number[] = [];
|
|
664
|
+
private typeParameters: number[] = [];
|
|
665
|
+
private numUserSorts = 0;
|
|
666
|
+
private bvSorts = new Map<number, number>();
|
|
667
|
+
private bvDecls = new Map<string, number>();
|
|
668
|
+
private fpSorts = new Map<string, number>();
|
|
669
|
+
private rmSort = -1;
|
|
670
|
+
private fpaDecls = new Map<string, number>();
|
|
671
|
+
private labelDecls = new Map<string, number>();
|
|
672
|
+
private pbDecls = new Map<string, number>();
|
|
673
|
+
// The parameters of a pseudo-Boolean declaration: its bound, then a coefficient per argument.
|
|
674
|
+
private pbParameters = new Map<number, Rational[]>();
|
|
675
|
+
// The names of the labels, which the parameters of a label declaration index.
|
|
676
|
+
private labelNames: string[] = [];
|
|
677
|
+
private labelNameIds = new Map<string, number>();
|
|
678
|
+
private fpValues: Mpf[] = [];
|
|
679
|
+
private fpValueIds = new Map<string, number>();
|
|
680
|
+
private charSort = -1;
|
|
681
|
+
private stringSort = -1;
|
|
682
|
+
private reglanSort = -1;
|
|
683
|
+
private isSeqPluginInitialized = false;
|
|
684
|
+
private seqSorts = new Map<string, number>();
|
|
685
|
+
private seqDecls = new Map<string, number>();
|
|
686
|
+
private stringValues: number[][] = [];
|
|
687
|
+
private stringValueIds = new Map<string, number>();
|
|
269
688
|
private sortHashes = [
|
|
270
689
|
combineHash(getSymbolHash("Bool"), getInfoHash(Z3_BASIC_FAMILY, 0, [])),
|
|
271
690
|
combineHash(getSymbolHash("Int"), getInfoHash(Z3_ARITH_FAMILY, 1, [])),
|
|
272
691
|
combineHash(getSymbolHash("Real"), getInfoHash(Z3_ARITH_FAMILY, 0, [])),
|
|
273
692
|
];
|
|
274
|
-
// The hash of each uninterpreted declaration, and of each builtin by its Z3 declaration.
|
|
275
693
|
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
694
|
private builtinKeys = new Int32Array(4 * 256).fill(-1);
|
|
280
695
|
private builtinHashes = new Uint32Array(256);
|
|
281
696
|
private numBuiltinHashes = 0;
|
|
282
|
-
// The hash of each pattern declaration by its domain and range.
|
|
283
697
|
private patternHashes = new Map<string, number>();
|
|
284
698
|
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
699
|
private appHandles = new Int32Array(1024).fill(-1);
|
|
289
700
|
private appHashes = new Int32Array(1024);
|
|
290
701
|
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
702
|
private nextSmallId = FIRST_DECLARED_SMALL_ID;
|
|
295
703
|
private freeSmallIds: number[] = [];
|
|
296
704
|
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
705
|
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
706
|
private declRefCounts: number[] = [];
|
|
304
|
-
// The named expressions of the recfun plugin, by declaration.
|
|
305
707
|
readonly macros = new ObjMap<number>((decl) => this.declHashes[decl]);
|
|
708
|
+
// The recfun plugin's definitions by declaration, and their cases by case predicate.
|
|
709
|
+
readonly recFunDefs = new ObjMap<RecFunDef>((decl) => this.declHashes[decl]);
|
|
710
|
+
readonly recFunCases = new Map<number, RecFunCase>();
|
|
711
|
+
hasRecDefs = false;
|
|
712
|
+
private numRoundsDecls = new Map<number, number>();
|
|
306
713
|
private deletedDecls = new Set<number>();
|
|
307
|
-
// ast_manager::m_fresh_id, which numbers fresh declarations and variable names.
|
|
308
714
|
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
715
|
ids = new Int32Array(1024);
|
|
313
716
|
private refCounts = new Int32Array(1024);
|
|
314
717
|
private freeIds: number[] = [];
|
|
315
718
|
private nextId = 1;
|
|
316
719
|
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
720
|
private temporaries: number[] = [];
|
|
321
721
|
private temporariesMark = -1;
|
|
322
|
-
// The arguments mkApp copies out of a caller's array that starts past index 0.
|
|
323
722
|
private argBuffer: number[] = [];
|
|
324
|
-
// m_small_ints and m_small_reals: the numerals below MAX_SMALL_NUM_TO_CACHE, which are held.
|
|
325
723
|
private smallInts: number[] = [];
|
|
326
724
|
private smallReals: number[] = [];
|
|
327
|
-
|
|
725
|
+
// The finite set plugin makes the only type variables, so this is set once it is initialized.
|
|
726
|
+
hasTypeVars = false;
|
|
328
727
|
readonly trueExpr: number;
|
|
329
728
|
readonly falseExpr: number;
|
|
729
|
+
readonly piExpr: number;
|
|
730
|
+
readonly eulerExpr: number;
|
|
731
|
+
isHiDiv0 = true;
|
|
732
|
+
maxChar = 196607;
|
|
733
|
+
charBits = 18;
|
|
734
|
+
isSeqUsed = false;
|
|
735
|
+
isReUsed = false;
|
|
330
736
|
|
|
331
737
|
constructor(readonly limit: ResourceLimit) {
|
|
332
738
|
for (const builtin of BUILTIN_DECLS)
|
|
@@ -338,11 +744,27 @@ export class AstManager {
|
|
|
338
744
|
range: builtin[3],
|
|
339
745
|
isSkolem: false,
|
|
340
746
|
smallId: Z3_SMALL_IDS.get(builtin[2]) ?? -1,
|
|
747
|
+
parameters: [],
|
|
341
748
|
});
|
|
749
|
+
// Each has one signature in Z3, and a model's tables hash its declaration as a user's.
|
|
750
|
+
for (const entry of Z3_BUILTINS)
|
|
751
|
+
if (entry[0] === OP_DIV0 || entry[0] === OP_IDIV0 || entry[0] === OP_MOD0) {
|
|
752
|
+
const range = this.funcDecls[entry[0]].range;
|
|
753
|
+
this.declHashes[entry[0]] = this.getFuncDeclHash(
|
|
754
|
+
entry[1][0],
|
|
755
|
+
[range, range],
|
|
756
|
+
range,
|
|
757
|
+
getInfoHash(Z3_ARITH_FAMILY, entry[1][1], []),
|
|
758
|
+
);
|
|
759
|
+
}
|
|
342
760
|
this.trueExpr = this.mkApp(OP_TRUE, [], SORT_BOOL);
|
|
343
761
|
this.falseExpr = this.mkApp(OP_FALSE, [], SORT_BOOL);
|
|
344
762
|
this.incRef(this.trueExpr);
|
|
345
763
|
this.incRef(this.falseExpr);
|
|
764
|
+
this.piExpr = this.mkApp(OP_PI, [], SORT_REAL);
|
|
765
|
+
this.eulerExpr = this.mkApp(OP_E, [], SORT_REAL);
|
|
766
|
+
this.incRef(this.piExpr);
|
|
767
|
+
this.incRef(this.eulerExpr);
|
|
346
768
|
this.nextId = FIRST_FREE_ID;
|
|
347
769
|
}
|
|
348
770
|
|
|
@@ -350,12 +772,10 @@ export class AstManager {
|
|
|
350
772
|
return this.refCounts[expr];
|
|
351
773
|
}
|
|
352
774
|
|
|
353
|
-
// get_num_asts: the live expressions, declarations and sorts, with Z3's own expressions.
|
|
354
775
|
getNumAsts() {
|
|
355
|
-
return this.numLive + FIRST_FREE_ID -
|
|
776
|
+
return this.numLive + FIRST_FREE_ID - 4 + this.numDecls;
|
|
356
777
|
}
|
|
357
778
|
|
|
358
|
-
// The declaration that a held signature names.
|
|
359
779
|
private getSignatureDecl(key: number | string) {
|
|
360
780
|
const signatureDecl = this.signatureDecls.get(key);
|
|
361
781
|
if (signatureDecl === undefined)
|
|
@@ -368,20 +788,14 @@ export class AstManager {
|
|
|
368
788
|
return this.freeSmallIds.pop() ?? this.nextSmallId++;
|
|
369
789
|
}
|
|
370
790
|
|
|
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
791
|
initFiniteSetPlugin() {
|
|
375
|
-
if (this.
|
|
376
|
-
this.
|
|
792
|
+
if (this.hasTypeVars) return;
|
|
793
|
+
this.hasTypeVars = true;
|
|
377
794
|
for (let index = 0; index < NUM_FINITE_SET_PLUGIN_SORTS; index++) this.mkSmallId();
|
|
378
795
|
this.freeSmallIds.push(this.mkSmallId());
|
|
379
796
|
this.numDecls--;
|
|
380
797
|
}
|
|
381
798
|
|
|
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
799
|
mkMacro(name: string, expr: number) {
|
|
386
800
|
const decl = this.funcDecls.length;
|
|
387
801
|
this.declHashes[decl] = this.getFuncDeclHash(
|
|
@@ -398,29 +812,93 @@ export class AstManager {
|
|
|
398
812
|
range: this.sorts[expr],
|
|
399
813
|
isSkolem: false,
|
|
400
814
|
smallId: this.mkSmallId(),
|
|
815
|
+
parameters: [],
|
|
401
816
|
});
|
|
402
817
|
this.declRefCounts[decl] = 1;
|
|
403
818
|
this.mkSmallId();
|
|
404
819
|
this.macros.set(decl, expr);
|
|
820
|
+
return decl;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
eraseRecFunDef(decl: number) {
|
|
824
|
+
this.macros.delete(decl);
|
|
825
|
+
const def = this.recFunDefs.get(decl);
|
|
826
|
+
if (def === undefined) return;
|
|
827
|
+
for (const recFunCase of def.cases) this.recFunCases.delete(recFunCase.pred);
|
|
828
|
+
this.recFunDefs.delete(decl);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// recfun::def: the declaration of a defined function, which the definition holds.
|
|
832
|
+
mkRecFuncDecl(name: SmtSymbol, domain: number[], range: number) {
|
|
833
|
+
const decl = this.mkRecFunDecl(OP_FUN_DEFINED, name, [0], domain, range);
|
|
834
|
+
this.declRefCounts[decl] = 1;
|
|
835
|
+
this.recFunDefs.set(decl, { decl, rhs: -1, isMacro: false, cases: [] });
|
|
836
|
+
return decl;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// case_def: the predicate of a case, which the case holds.
|
|
840
|
+
mkRecFunCasePredDecl(def: number, index: number) {
|
|
841
|
+
const decl = this.mkRecFunDecl(
|
|
842
|
+
OP_FUN_CASE_PRED,
|
|
843
|
+
"case-def",
|
|
844
|
+
[index, def],
|
|
845
|
+
this.funcDecls[def].domain,
|
|
846
|
+
SORT_BOOL,
|
|
847
|
+
);
|
|
848
|
+
this.declRefCounts[decl] = 1;
|
|
849
|
+
return decl;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// mk_num_rounds_pred: Z3 makes the declaration again once its last application is deleted.
|
|
853
|
+
mkNumRoundsPred(round: number) {
|
|
854
|
+
let decl = this.numRoundsDecls.get(round);
|
|
855
|
+
if (decl === undefined) {
|
|
856
|
+
decl = this.mkRecFunDecl(OP_NUM_ROUNDS, "recfun-num-rounds", [round], [], SORT_BOOL);
|
|
857
|
+
this.declRefCounts[decl] = 0;
|
|
858
|
+
this.numRoundsDecls.set(round, decl);
|
|
859
|
+
}
|
|
860
|
+
return this.mkApp(decl, [], SORT_BOOL);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
private mkRecFunDecl(
|
|
864
|
+
op: number,
|
|
865
|
+
name: SmtSymbol,
|
|
866
|
+
parameters: number[],
|
|
867
|
+
domain: number[],
|
|
868
|
+
range: number,
|
|
869
|
+
) {
|
|
870
|
+
return this.addDecl(
|
|
871
|
+
name,
|
|
872
|
+
FAMILY_RECFUN,
|
|
873
|
+
op,
|
|
874
|
+
domain,
|
|
875
|
+
range,
|
|
876
|
+
parameters,
|
|
877
|
+
getInfoHash(
|
|
878
|
+
Z3_RECFUN_FAMILY,
|
|
879
|
+
op - RECFUN_OP_BASE,
|
|
880
|
+
op === OP_FUN_CASE_PRED ? [parameters[0], this.declHashes[parameters[1]]] : parameters,
|
|
881
|
+
),
|
|
882
|
+
);
|
|
405
883
|
}
|
|
406
884
|
|
|
407
|
-
// The signature of a builtin declaration that Z3 makes on first use, or null for a declaration
|
|
408
|
-
// that is not one. The low three bits of an integer signature tell its kind: an equality or ite
|
|
409
|
-
// by sort, a division by zero or model value by declaration, or a numeral by its value, which a
|
|
410
|
-
// numeral expression has alone. A distinct or pattern is keyed by its domain.
|
|
411
885
|
private getSignature(expr: number) {
|
|
412
886
|
const decl = this.decls[expr];
|
|
413
|
-
if (decl === OP_NUM
|
|
887
|
+
if (decl === OP_NUM || this.funcDecls[decl].op === OP_BV_NUM)
|
|
888
|
+
return 8 * this.values[expr] + SIGNATURE_NUMERAL;
|
|
414
889
|
if (decl === OP_EQ) return 8 * this.sorts[this.getArg(expr, 0)] + SIGNATURE_EQ;
|
|
415
890
|
if (decl === OP_ITE) return 8 * this.sorts[expr] + SIGNATURE_ITE;
|
|
416
891
|
if (decl === OP_DIV0 || decl === OP_IDIV0 || decl === OP_MOD0) return 8 * decl + SIGNATURE_DIV0;
|
|
892
|
+
if (decl === OP_POWER0)
|
|
893
|
+
return 8 * (decl + 64 * this.sorts[this.getArg(expr, 0)]) + SIGNATURE_DIV0;
|
|
894
|
+
if (decl === OP_ALGEBRAIC_NUM) return 8 * this.getAlgebraicId(expr) + SIGNATURE_ALGEBRAIC;
|
|
417
895
|
if (decl === OP_DISTINCT || decl === OP_PATTERN)
|
|
418
896
|
return `${decl}:${this.mapArgs(expr, (arg) => this.sorts[arg]).join(",")}`;
|
|
419
897
|
if (this.funcDecls[decl].family === FAMILY_MODEL_VALUE) return 8 * decl + SIGNATURE_MODEL_VALUE;
|
|
898
|
+
if (UNCACHED_BV_OPS.has(this.funcDecls[decl].op)) return `bv${decl}`;
|
|
420
899
|
return null;
|
|
421
900
|
}
|
|
422
901
|
|
|
423
|
-
// The id that Z3 gives the declaration of an application.
|
|
424
902
|
getDeclId(expr: number) {
|
|
425
903
|
const signature = this.getSignature(expr);
|
|
426
904
|
return signature === null
|
|
@@ -428,10 +906,9 @@ export class AstManager {
|
|
|
428
906
|
: this.getSignatureDecl(signature).smallId;
|
|
429
907
|
}
|
|
430
908
|
|
|
431
|
-
// An application holds its declaration, which Z3 makes with its first application.
|
|
432
909
|
private holdDecl(expr: number) {
|
|
433
910
|
const decl = this.decls[expr];
|
|
434
|
-
if (this.funcDecls[decl]
|
|
911
|
+
if (isDeclared(this.funcDecls[decl])) {
|
|
435
912
|
this.incDeclRef(decl);
|
|
436
913
|
return;
|
|
437
914
|
}
|
|
@@ -443,17 +920,14 @@ export class AstManager {
|
|
|
443
920
|
return;
|
|
444
921
|
}
|
|
445
922
|
const smallId = this.mkSmallId();
|
|
446
|
-
// Z3 keeps the equality and ite declarations once it makes them.
|
|
447
923
|
this.signatureDecls.set(key, { smallId, refCount: decl === OP_EQ || decl === OP_ITE ? 2 : 1 });
|
|
448
924
|
if (decl !== OP_NUM && this.funcDecls[decl].family === FAMILY_MODEL_VALUE)
|
|
449
925
|
this.funcDecls[decl].smallId = smallId;
|
|
450
926
|
}
|
|
451
927
|
|
|
452
|
-
// The small id of the declaration a deleted application releases for good, or -1 when the
|
|
453
|
-
// declaration stays.
|
|
454
928
|
private releaseDecl(expr: number) {
|
|
455
929
|
const decl = this.decls[expr];
|
|
456
|
-
if (this.funcDecls[decl]
|
|
930
|
+
if (isDeclared(this.funcDecls[decl])) {
|
|
457
931
|
this.declRefCounts[decl]--;
|
|
458
932
|
if (this.declRefCounts[decl] > 0) return -1;
|
|
459
933
|
this.deletedDecls.add(decl);
|
|
@@ -472,7 +946,6 @@ export class AstManager {
|
|
|
472
946
|
this.refCounts[expr]++;
|
|
473
947
|
}
|
|
474
948
|
|
|
475
|
-
// A model value's declaration is counted under its signature, like the applications that hold it.
|
|
476
949
|
incDeclRef(decl: number) {
|
|
477
950
|
if (this.funcDecls[decl].family === FAMILY_MODEL_VALUE) {
|
|
478
951
|
const key = 8 * decl + SIGNATURE_MODEL_VALUE;
|
|
@@ -508,9 +981,6 @@ export class AstManager {
|
|
|
508
981
|
this.numDecls--;
|
|
509
982
|
}
|
|
510
983
|
|
|
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
984
|
withTemporaries<T>(
|
|
515
985
|
body: () => T,
|
|
516
986
|
getKept: (result: T) => number[] = (result) => [result as number],
|
|
@@ -522,8 +992,6 @@ export class AstManager {
|
|
|
522
992
|
return result;
|
|
523
993
|
}
|
|
524
994
|
|
|
525
|
-
// withTemporaries without closures, for the hot paths: the caller passes what beginTemporaries
|
|
526
|
-
// returns to endTemporaries, and takes its references before it.
|
|
527
995
|
beginTemporaries() {
|
|
528
996
|
const outer = this.temporariesMark;
|
|
529
997
|
this.temporariesMark = this.temporaries.length;
|
|
@@ -539,24 +1007,21 @@ export class AstManager {
|
|
|
539
1007
|
shrink(temporaries, mark);
|
|
540
1008
|
}
|
|
541
1009
|
|
|
542
|
-
// Runs body without temporaries, for code whose references are counted explicitly.
|
|
543
1010
|
withoutTemporaries<T>(body: () => T) {
|
|
544
1011
|
const outer = this.temporariesMark;
|
|
545
1012
|
this.temporariesMark = -1;
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
1013
|
+
try {
|
|
1014
|
+
return body();
|
|
1015
|
+
} finally {
|
|
1016
|
+
this.temporariesMark = outer;
|
|
1017
|
+
}
|
|
549
1018
|
}
|
|
550
1019
|
|
|
551
|
-
// Hands a reference the caller owns to the innermost withTemporaries, or releases it now.
|
|
552
1020
|
releaseLater(expr: number) {
|
|
553
1021
|
if (this.temporariesMark === -1) this.decRef(expr);
|
|
554
1022
|
else this.temporaries.push(expr);
|
|
555
1023
|
}
|
|
556
1024
|
|
|
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
1025
|
decRef(expr: number) {
|
|
561
1026
|
if (this.ids[expr] === -1) return;
|
|
562
1027
|
this.refCounts[expr]--;
|
|
@@ -571,10 +1036,10 @@ export class AstManager {
|
|
|
571
1036
|
this.deleteNode(node);
|
|
572
1037
|
if (this.kinds[node] === KIND_APP) {
|
|
573
1038
|
const smallId = this.releaseDecl(node);
|
|
1039
|
+
if (this.decls[node] === OP_ALGEBRAIC_NUM)
|
|
1040
|
+
this.freeAlgebraicIds.push(this.getAlgebraicId(node));
|
|
574
1041
|
if (smallId !== -1) worklist.push(-1 - smallId);
|
|
575
1042
|
}
|
|
576
|
-
// The children: the arguments of an application, and the body and then the patterns of a
|
|
577
|
-
// quantifier.
|
|
578
1043
|
if (this.kinds[node] !== KIND_QUANTIFIER) {
|
|
579
1044
|
const end = this.argStarts[node + 1];
|
|
580
1045
|
for (let index = this.argStarts[node]; index < end; index++)
|
|
@@ -584,6 +1049,7 @@ export class AstManager {
|
|
|
584
1049
|
const data = this.getQuantifier(node);
|
|
585
1050
|
this.releaseChild(data.body, worklist);
|
|
586
1051
|
for (const pattern of data.patterns) this.releaseChild(pattern, worklist);
|
|
1052
|
+
for (const noPattern of data.noPatterns) this.releaseChild(noPattern, worklist);
|
|
587
1053
|
}
|
|
588
1054
|
}
|
|
589
1055
|
|
|
@@ -598,13 +1064,10 @@ export class AstManager {
|
|
|
598
1064
|
this.ids[expr] = -1;
|
|
599
1065
|
}
|
|
600
1066
|
|
|
601
|
-
// register_node_core: a new expression takes an id and a reference to each child.
|
|
602
1067
|
private registerNode(expr: number) {
|
|
603
1068
|
this.ids[expr] = this.freeIds.pop() ?? this.nextId++;
|
|
604
1069
|
this.numLive++;
|
|
605
1070
|
this.refCounts[expr] = 0;
|
|
606
|
-
// The children: the arguments of an application, and the body and then the patterns of a
|
|
607
|
-
// quantifier.
|
|
608
1071
|
if (this.kinds[expr] !== KIND_QUANTIFIER) {
|
|
609
1072
|
const end = this.argStarts[expr + 1];
|
|
610
1073
|
for (let index = this.argStarts[expr]; index < end; index++)
|
|
@@ -613,6 +1076,7 @@ export class AstManager {
|
|
|
613
1076
|
const data = this.getQuantifier(expr);
|
|
614
1077
|
this.incRef(this.revive(data.body));
|
|
615
1078
|
for (const pattern of data.patterns) this.incRef(this.revive(pattern));
|
|
1079
|
+
for (const noPattern of data.noPatterns) this.incRef(this.revive(noPattern));
|
|
616
1080
|
}
|
|
617
1081
|
if (this.kinds[expr] === KIND_APP) this.holdDecl(expr);
|
|
618
1082
|
if (this.temporariesMark === -1) return;
|
|
@@ -620,7 +1084,6 @@ export class AstManager {
|
|
|
620
1084
|
this.temporaries.push(expr);
|
|
621
1085
|
}
|
|
622
1086
|
|
|
623
|
-
// The arguments of an application, and the body of a quantifier as its one argument.
|
|
624
1087
|
getNumArgs(expr: number) {
|
|
625
1088
|
return this.argStarts[expr + 1] - this.argStarts[expr];
|
|
626
1089
|
}
|
|
@@ -629,20 +1092,17 @@ export class AstManager {
|
|
|
629
1092
|
return this.argPool[this.argStarts[expr] + index];
|
|
630
1093
|
}
|
|
631
1094
|
|
|
632
|
-
// Appends the arguments to target, for a caller that needs them as an array.
|
|
633
1095
|
pushArgs(expr: number, target: number[]) {
|
|
634
1096
|
const end = this.argStarts[expr + 1];
|
|
635
1097
|
for (let index = this.argStarts[expr]; index < end; index++) target.push(this.argPool[index]);
|
|
636
1098
|
}
|
|
637
1099
|
|
|
638
|
-
// A new array of the arguments.
|
|
639
1100
|
getArgs(expr: number) {
|
|
640
1101
|
const args: number[] = [];
|
|
641
1102
|
this.pushArgs(expr, args);
|
|
642
1103
|
return args;
|
|
643
1104
|
}
|
|
644
1105
|
|
|
645
|
-
// The callbacks may create expressions, which can replace argPool, so each argument is read anew.
|
|
646
1106
|
mapArgs<T>(expr: number, map: (arg: number, index: number) => T) {
|
|
647
1107
|
const result: T[] = [];
|
|
648
1108
|
for (let index = 0; index < this.getNumArgs(expr); index++)
|
|
@@ -662,25 +1122,640 @@ export class AstManager {
|
|
|
662
1122
|
return true;
|
|
663
1123
|
}
|
|
664
1124
|
|
|
665
|
-
// A lookup that finds a deleted expression creates it again.
|
|
666
1125
|
private revive(expr: number) {
|
|
667
|
-
if (this.ids[expr]
|
|
1126
|
+
if (this.ids[expr] !== -1) return expr;
|
|
1127
|
+
if (this.decls[expr] === OP_ALGEBRAIC_NUM)
|
|
1128
|
+
this.algebraicNumerals[this.values[expr]].id = this.mkAlgebraicId();
|
|
1129
|
+
this.registerNode(expr);
|
|
668
1130
|
return expr;
|
|
669
1131
|
}
|
|
670
1132
|
|
|
671
|
-
mkSort(name:
|
|
672
|
-
this.
|
|
1133
|
+
mkSort(name: SmtSymbol) {
|
|
1134
|
+
const sort = this.addSort(
|
|
1135
|
+
getSymbolName(name),
|
|
1136
|
+
FAMILY_USER,
|
|
1137
|
+
[],
|
|
673
1138
|
combineHash(
|
|
674
1139
|
getSymbolHash(name),
|
|
675
|
-
getInfoHash(Z3_USER_SORT_FAMILY, this.
|
|
1140
|
+
getInfoHash(Z3_USER_SORT_FAMILY, this.getUserSortKind(name), []),
|
|
676
1141
|
),
|
|
677
1142
|
);
|
|
678
|
-
this.sortNames.push(name);
|
|
679
1143
|
this.mkSmallId();
|
|
1144
|
+
return sort;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
mkBvSort(width: number) {
|
|
1148
|
+
const existing = this.bvSorts.get(width);
|
|
1149
|
+
if (existing !== undefined) return existing;
|
|
1150
|
+
const sort = this.addSort(
|
|
1151
|
+
"bv",
|
|
1152
|
+
FAMILY_BV,
|
|
1153
|
+
[],
|
|
1154
|
+
combineHash(getSymbolHash("bv"), getInfoHash(Z3_BV_FAMILY, 0, [width])),
|
|
1155
|
+
width,
|
|
1156
|
+
0,
|
|
1157
|
+
width < 64 ? 1n << BigInt(width) : SORT_SIZE_VERY_BIG,
|
|
1158
|
+
);
|
|
1159
|
+
// bv_decl_plugin makes the sorts up to 64 bits when Z3 starts.
|
|
1160
|
+
if (width > 64) this.mkSmallId();
|
|
1161
|
+
this.bvSorts.set(width, sort);
|
|
1162
|
+
return sort;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
mkFpSort(ebits: number, sbits: number) {
|
|
1166
|
+
const key = `${ebits}:${sbits}`;
|
|
1167
|
+
const existing = this.fpSorts.get(key);
|
|
1168
|
+
if (existing !== undefined) return existing;
|
|
1169
|
+
const sort = this.addSort(
|
|
1170
|
+
"FloatingPoint",
|
|
1171
|
+
FAMILY_FPA,
|
|
1172
|
+
[],
|
|
1173
|
+
combineHash(
|
|
1174
|
+
getSymbolHash("FloatingPoint"),
|
|
1175
|
+
getInfoHash(Z3_FPA_FAMILY, Z3_FLOATING_POINT_SORT, [ebits, sbits]),
|
|
1176
|
+
),
|
|
1177
|
+
ebits,
|
|
1178
|
+
sbits,
|
|
1179
|
+
SORT_SIZE_VERY_BIG,
|
|
1180
|
+
);
|
|
1181
|
+
this.mkSmallId();
|
|
1182
|
+
this.fpSorts.set(key, sort);
|
|
1183
|
+
return sort;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
mkRmSort() {
|
|
1187
|
+
if (this.rmSort !== -1) return this.rmSort;
|
|
1188
|
+
this.rmSort = this.addSort(
|
|
1189
|
+
"RoundingMode",
|
|
1190
|
+
FAMILY_FPA,
|
|
1191
|
+
[],
|
|
1192
|
+
combineHash(
|
|
1193
|
+
getSymbolHash("RoundingMode"),
|
|
1194
|
+
getInfoHash(Z3_FPA_FAMILY, Z3_ROUNDING_MODE_SORT, []),
|
|
1195
|
+
),
|
|
1196
|
+
);
|
|
1197
|
+
this.mkSmallId();
|
|
1198
|
+
return this.rmSort;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
isFpSort(sort: number) {
|
|
1202
|
+
return this.sortFamilies[sort] === FAMILY_FPA && sort !== this.rmSort;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
isRmSort(sort: number) {
|
|
1206
|
+
return sort === this.rmSort;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
getEbits(sort: number) {
|
|
1210
|
+
return this.sortWidths[sort];
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
getSbits(sort: number) {
|
|
1214
|
+
return this.sortSbits[sort];
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
private addDecl(
|
|
1218
|
+
name: SmtSymbol,
|
|
1219
|
+
family: number,
|
|
1220
|
+
op: number,
|
|
1221
|
+
domain: number[],
|
|
1222
|
+
range: number,
|
|
1223
|
+
parameters: number[],
|
|
1224
|
+
infoHash: number,
|
|
1225
|
+
hasSmallId = true,
|
|
1226
|
+
) {
|
|
1227
|
+
const decl = this.funcDecls.length;
|
|
1228
|
+
this.declHashes[decl] = this.getFuncDeclHash(name, domain, range, infoHash);
|
|
1229
|
+
this.funcDecls.push({
|
|
1230
|
+
name,
|
|
1231
|
+
family,
|
|
1232
|
+
op,
|
|
1233
|
+
domain,
|
|
1234
|
+
range,
|
|
1235
|
+
isSkolem: false,
|
|
1236
|
+
smallId: hasSmallId ? this.mkSmallId() : -1,
|
|
1237
|
+
parameters,
|
|
1238
|
+
});
|
|
1239
|
+
return decl;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
mkFpaDecl(op: number, name: string, parameters: number[], domain: number[], range: number) {
|
|
1243
|
+
const key = `${op}:${name}:${parameters.join(",")}:${domain.join(",")}:${range}`;
|
|
1244
|
+
const existing = this.fpaDecls.get(key);
|
|
1245
|
+
if (existing !== undefined) return existing;
|
|
1246
|
+
const decl = this.addDecl(
|
|
1247
|
+
name,
|
|
1248
|
+
FAMILY_FPA,
|
|
1249
|
+
op,
|
|
1250
|
+
domain,
|
|
1251
|
+
range,
|
|
1252
|
+
parameters,
|
|
1253
|
+
getInfoHash(Z3_FPA_FAMILY, op - FPA_OP_BASE, parameters),
|
|
1254
|
+
);
|
|
1255
|
+
this.fpaDecls.set(key, decl);
|
|
1256
|
+
return decl;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// pb_decl_plugin::mk_func_decl: a parameter that fits in 32 bits is an integer, else a rational.
|
|
1260
|
+
mkPbDecl(op: number, parameters: Rational[], domain: number[]) {
|
|
1261
|
+
const key = `${op}:${parameters.join(",")}:${domain.join(",")}`;
|
|
1262
|
+
const existing = this.pbDecls.get(key);
|
|
1263
|
+
if (existing !== undefined) return existing;
|
|
1264
|
+
const decl = this.addDecl(
|
|
1265
|
+
PB_OP_NAMES[op - PB_OP_BASE],
|
|
1266
|
+
FAMILY_PB,
|
|
1267
|
+
op,
|
|
1268
|
+
domain,
|
|
1269
|
+
SORT_BOOL,
|
|
1270
|
+
[],
|
|
1271
|
+
getInfoHash(
|
|
1272
|
+
Z3_PB_FAMILY,
|
|
1273
|
+
op - PB_OP_BASE,
|
|
1274
|
+
parameters.map((parameter) =>
|
|
1275
|
+
parameter.isInt() && parameter.num >= -(2n ** 31n) && parameter.num < 2n ** 31n
|
|
1276
|
+
? Number(BigInt.asUintN(32, parameter.num))
|
|
1277
|
+
: (getIntegerHash(parameter.num) + 3 * getIntegerHash(parameter.den)) >>> 0,
|
|
1278
|
+
),
|
|
1279
|
+
),
|
|
1280
|
+
);
|
|
1281
|
+
this.pbParameters.set(decl, parameters);
|
|
1282
|
+
this.pbDecls.set(key, decl);
|
|
1283
|
+
return decl;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
getPbParameters(decl: number) {
|
|
1287
|
+
return this.pbParameters.get(decl) as Rational[];
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
mkFpValueId(value: Mpf) {
|
|
1291
|
+
const key = `${value.ebits}:${value.sbits}:${value.sign}:${value.exponent}:${value.significand}`;
|
|
1292
|
+
const existing = this.fpValueIds.get(key);
|
|
1293
|
+
if (existing !== undefined) return existing;
|
|
1294
|
+
this.fpValues.push({ ...value });
|
|
1295
|
+
this.fpValueIds.set(key, this.fpValues.length - 1);
|
|
1296
|
+
return this.fpValues.length - 1;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
getFpValue(id: number): Readonly<Mpf> {
|
|
1300
|
+
return this.fpValues[id];
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
private addSort(
|
|
1304
|
+
name: string,
|
|
1305
|
+
family: number,
|
|
1306
|
+
parameters: number[],
|
|
1307
|
+
hash: number,
|
|
1308
|
+
width = 0,
|
|
1309
|
+
sbits = 0,
|
|
1310
|
+
size = SORT_SIZE_INFINITE,
|
|
1311
|
+
) {
|
|
1312
|
+
this.sortHashes.push(hash);
|
|
1313
|
+
this.sortNames.push(name);
|
|
1314
|
+
this.sortFamilies.push(family);
|
|
1315
|
+
this.sortWidths.push(width);
|
|
1316
|
+
this.sortSbits.push(sbits);
|
|
1317
|
+
this.sortParameters.push(parameters);
|
|
1318
|
+
this.sortSizes.push(size);
|
|
680
1319
|
return this.sortNames.length - 1;
|
|
681
1320
|
}
|
|
682
1321
|
|
|
683
|
-
//
|
|
1322
|
+
// Z3 makes the Char and String sorts at startup, so they take no small id.
|
|
1323
|
+
mkCharSort() {
|
|
1324
|
+
if (this.charSort === -1)
|
|
1325
|
+
this.charSort = this.addSort(
|
|
1326
|
+
"Unicode",
|
|
1327
|
+
FAMILY_CHAR,
|
|
1328
|
+
[],
|
|
1329
|
+
combineHash(getSymbolHash("Unicode"), getInfoHash(Z3_CHAR_FAMILY, 0, [])),
|
|
1330
|
+
);
|
|
1331
|
+
return this.charSort;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
// String keeps its element out of its parameters, since it prints as a plain name.
|
|
1335
|
+
mkStringSort() {
|
|
1336
|
+
if (this.stringSort !== -1) return this.stringSort;
|
|
1337
|
+
const charHash = this.sortHashes[this.mkCharSort()];
|
|
1338
|
+
this.stringSort = this.addSort(
|
|
1339
|
+
"String",
|
|
1340
|
+
FAMILY_SEQ,
|
|
1341
|
+
[],
|
|
1342
|
+
combineHash(getSymbolHash("String"), getInfoHash(Z3_SEQ_FAMILY, Z3_SEQ_SORT, [charHash])),
|
|
1343
|
+
);
|
|
1344
|
+
return this.stringSort;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
initSeqPlugin() {
|
|
1348
|
+
if (this.isSeqPluginInitialized) return;
|
|
1349
|
+
this.isSeqPluginInitialized = true;
|
|
1350
|
+
const element = this.mkTypeParameter(0);
|
|
1351
|
+
this.mkReSort(this.mkSeqSort(element));
|
|
1352
|
+
this.mkReSort(this.mkStringSort());
|
|
1353
|
+
this.mkArraySort([element, SORT_BOOL]);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
mkSeqSort(element: number) {
|
|
1357
|
+
if (element === this.mkCharSort()) return this.mkStringSort();
|
|
1358
|
+
this.initSeqPlugin();
|
|
1359
|
+
const key = `s${element}`;
|
|
1360
|
+
const existing = this.seqSorts.get(key);
|
|
1361
|
+
if (existing !== undefined) return existing;
|
|
1362
|
+
const sort = this.addSort(
|
|
1363
|
+
"Seq",
|
|
1364
|
+
FAMILY_SEQ,
|
|
1365
|
+
[element],
|
|
1366
|
+
combineHash(
|
|
1367
|
+
getSymbolHash("Seq"),
|
|
1368
|
+
getInfoHash(Z3_SEQ_FAMILY, Z3_SEQ_SORT, [this.sortHashes[element]]),
|
|
1369
|
+
),
|
|
1370
|
+
);
|
|
1371
|
+
this.mkSmallId();
|
|
1372
|
+
this.seqSorts.set(key, sort);
|
|
1373
|
+
return sort;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
mkReSort(seq: number) {
|
|
1377
|
+
this.initSeqPlugin();
|
|
1378
|
+
const isReglan = seq === this.mkStringSort();
|
|
1379
|
+
if (isReglan && this.reglanSort !== -1) return this.reglanSort;
|
|
1380
|
+
const key = `r${seq}`;
|
|
1381
|
+
const existing = this.seqSorts.get(key);
|
|
1382
|
+
if (existing !== undefined) return existing;
|
|
1383
|
+
const sort = this.addSort(
|
|
1384
|
+
"RegEx",
|
|
1385
|
+
FAMILY_SEQ,
|
|
1386
|
+
[seq],
|
|
1387
|
+
combineHash(
|
|
1388
|
+
getSymbolHash("RegEx"),
|
|
1389
|
+
getInfoHash(Z3_SEQ_FAMILY, Z3_RE_SORT, [this.sortHashes[seq]]),
|
|
1390
|
+
),
|
|
1391
|
+
);
|
|
1392
|
+
this.mkSmallId();
|
|
1393
|
+
if (isReglan) this.reglanSort = sort;
|
|
1394
|
+
else this.seqSorts.set(key, sort);
|
|
1395
|
+
return sort;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
isCharSort(sort: number) {
|
|
1399
|
+
return sort === this.charSort;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
isStringSort(sort: number) {
|
|
1403
|
+
return sort === this.stringSort;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
isSeqSort(sort: number) {
|
|
1407
|
+
return this.sortFamilies[sort] === FAMILY_SEQ && this.sortNames[sort] !== "RegEx";
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
isReSort(sort: number) {
|
|
1411
|
+
return this.sortFamilies[sort] === FAMILY_SEQ && this.sortNames[sort] === "RegEx";
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
getSeqElementSort(sort: number) {
|
|
1415
|
+
return sort === this.stringSort ? this.charSort : this.sortParameters[sort][0];
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
getReSeqSort(sort: number) {
|
|
1419
|
+
return this.sortParameters[sort][0];
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
mkSeqDecl(
|
|
1423
|
+
op: number,
|
|
1424
|
+
name: string,
|
|
1425
|
+
parameters: number[],
|
|
1426
|
+
parameterHashes: number[],
|
|
1427
|
+
domain: number[],
|
|
1428
|
+
range: number,
|
|
1429
|
+
) {
|
|
1430
|
+
const key = `${op}:${name}:${parameters.join(",")}:${domain.join(",")}:${range}`;
|
|
1431
|
+
const existing = this.seqDecls.get(key);
|
|
1432
|
+
if (existing !== undefined) return existing;
|
|
1433
|
+
const isChar = op >= CHAR_OP_BASE;
|
|
1434
|
+
const decl = this.addDecl(
|
|
1435
|
+
name,
|
|
1436
|
+
isChar ? FAMILY_CHAR : FAMILY_SEQ,
|
|
1437
|
+
op,
|
|
1438
|
+
domain,
|
|
1439
|
+
range,
|
|
1440
|
+
parameters,
|
|
1441
|
+
getInfoHash(
|
|
1442
|
+
isChar ? Z3_CHAR_FAMILY : Z3_SEQ_FAMILY,
|
|
1443
|
+
op - (isChar ? CHAR_OP_BASE : SEQ_OP_BASE),
|
|
1444
|
+
parameterHashes,
|
|
1445
|
+
),
|
|
1446
|
+
);
|
|
1447
|
+
this.seqDecls.set(key, decl);
|
|
1448
|
+
return decl;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
mkStringValueId(chars: readonly number[]) {
|
|
1452
|
+
const key = chars.join(",");
|
|
1453
|
+
const existing = this.stringValueIds.get(key);
|
|
1454
|
+
if (existing !== undefined) return existing;
|
|
1455
|
+
this.stringValues.push([...chars]);
|
|
1456
|
+
this.stringValueIds.set(key, this.stringValues.length - 1);
|
|
1457
|
+
return this.stringValues.length - 1;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
getStringHash(id: number) {
|
|
1461
|
+
return bytesHash(new Uint8Array(Uint32Array.from(this.stringValues[id]).buffer), 23);
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
getSortHash(sort: number) {
|
|
1465
|
+
return this.sortHashes[sort];
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
mkString(chars: readonly number[]) {
|
|
1469
|
+
const id = this.mkStringValueId(chars);
|
|
1470
|
+
const sort = this.mkStringSort();
|
|
1471
|
+
const decl = this.mkSeqDecl(
|
|
1472
|
+
OP_STRING_CONST,
|
|
1473
|
+
"String",
|
|
1474
|
+
[id],
|
|
1475
|
+
[this.getStringHash(id)],
|
|
1476
|
+
[],
|
|
1477
|
+
sort,
|
|
1478
|
+
);
|
|
1479
|
+
return this.mkApp(decl, [], sort);
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
getString(expr: number): readonly number[] | undefined {
|
|
1483
|
+
if (this.getOp(expr) !== OP_STRING_CONST) return undefined;
|
|
1484
|
+
return this.stringValues[this.funcDecls[this.decls[expr]].parameters[0]];
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
mkChar(code: number) {
|
|
1488
|
+
const sort = this.mkCharSort();
|
|
1489
|
+
return this.mkApp(this.mkSeqDecl(OP_CHAR_CONST, "Char", [code], [code], [], sort), [], sort);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
getChar(expr: number) {
|
|
1493
|
+
return this.getOp(expr) === OP_CHAR_CONST ? this.funcDecls[this.decls[expr]].parameters[0] : -1;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
mkArraySort(parameters: number[]) {
|
|
1497
|
+
const key = parameters.join(",");
|
|
1498
|
+
const existing = this.arraySorts.get(key);
|
|
1499
|
+
if (existing !== undefined) return existing;
|
|
1500
|
+
const sort = this.addSort(
|
|
1501
|
+
"Array",
|
|
1502
|
+
FAMILY_ARRAY,
|
|
1503
|
+
parameters,
|
|
1504
|
+
combineHash(
|
|
1505
|
+
getSymbolHash("Array"),
|
|
1506
|
+
getInfoHash(
|
|
1507
|
+
Z3_ARRAY_FAMILY,
|
|
1508
|
+
0,
|
|
1509
|
+
parameters.map((parameter) => this.sortHashes[parameter]),
|
|
1510
|
+
),
|
|
1511
|
+
),
|
|
1512
|
+
0,
|
|
1513
|
+
0,
|
|
1514
|
+
this.getArraySortSize(parameters),
|
|
1515
|
+
);
|
|
1516
|
+
this.mkSmallId();
|
|
1517
|
+
this.arraySorts.set(key, sort);
|
|
1518
|
+
return sort;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
private getArraySortSize(parameters: number[]) {
|
|
1522
|
+
const sizes = parameters.map((parameter) => this.sortSizes[parameter]);
|
|
1523
|
+
if (sizes[sizes.length - 1] === 1n) return 1n;
|
|
1524
|
+
if (sizes.includes(SORT_SIZE_INFINITE)) return SORT_SIZE_INFINITE;
|
|
1525
|
+
if (sizes.includes(SORT_SIZE_VERY_BIG)) return SORT_SIZE_VERY_BIG;
|
|
1526
|
+
const domainSize = sizes.slice(0, -1).reduce((product, size) => product * size, 1n);
|
|
1527
|
+
if (domainSize > 128n) return SORT_SIZE_VERY_BIG;
|
|
1528
|
+
const size = sizes[sizes.length - 1] ** domainSize;
|
|
1529
|
+
return size >= 1n << 64n ? SORT_SIZE_VERY_BIG : size;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
isArraySort(sort: number) {
|
|
1533
|
+
return this.sortFamilies[sort] === FAMILY_ARRAY;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
getSortParameters(sort: number): readonly number[] {
|
|
1537
|
+
return this.sortParameters[sort];
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
getArrayArity(sort: number) {
|
|
1541
|
+
return this.sortParameters[sort].length - 1;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
getArrayRange(sort: number) {
|
|
1545
|
+
const parameters = this.sortParameters[sort];
|
|
1546
|
+
return parameters[parameters.length - 1];
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
getSortName(sort: number): string {
|
|
1550
|
+
if (this.isBvSort(sort)) return `(_ BitVec ${this.getBvSize(sort)})`;
|
|
1551
|
+
if (this.isFpSort(sort))
|
|
1552
|
+
return `(_ FloatingPoint ${this.getEbits(sort)} ${this.getSbits(sort)})`;
|
|
1553
|
+
const parameters = this.sortParameters[sort].map((parameter) => this.getSortName(parameter));
|
|
1554
|
+
if (parameters.length === 0) return this.sortNames[sort];
|
|
1555
|
+
return `(${this.sortNames[sort]} ${parameters.join(" ")})`;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
getSortSize(sort: number) {
|
|
1559
|
+
return this.sortSizes[sort];
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
mkArrayDecl(op: number, name: string, parameters: number[], domain: number[], range: number) {
|
|
1563
|
+
const key = `${op}:${parameters.join(",")}:${domain.join(",")}`;
|
|
1564
|
+
const existing = this.arrayDecls.get(key);
|
|
1565
|
+
if (existing !== undefined) return existing;
|
|
1566
|
+
const parameterHashes = parameters.map((parameter) =>
|
|
1567
|
+
op === OP_CONST_ARRAY
|
|
1568
|
+
? this.sortHashes[parameter]
|
|
1569
|
+
: op === OP_ARRAY_MAP || op === OP_AS_ARRAY
|
|
1570
|
+
? // A builtin declaration hashes by the signature of each application, which a map lacks.
|
|
1571
|
+
(this.getDeclHash(parameter) ?? 0)
|
|
1572
|
+
: parameter,
|
|
1573
|
+
);
|
|
1574
|
+
const decl = this.addDecl(
|
|
1575
|
+
name,
|
|
1576
|
+
FAMILY_ARRAY,
|
|
1577
|
+
op,
|
|
1578
|
+
domain,
|
|
1579
|
+
range,
|
|
1580
|
+
parameters,
|
|
1581
|
+
getInfoHash(Z3_ARRAY_FAMILY, op - ARRAY_OP_BASE, parameterHashes),
|
|
1582
|
+
);
|
|
1583
|
+
this.arrayDecls.set(key, decl);
|
|
1584
|
+
return decl;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
private mkParametricSort(
|
|
1588
|
+
family: number,
|
|
1589
|
+
name: SmtSymbol,
|
|
1590
|
+
parameters: number[],
|
|
1591
|
+
infoHash: number,
|
|
1592
|
+
) {
|
|
1593
|
+
const key = `${family}:${typeof name}:${name}:${parameters.join(",")}`;
|
|
1594
|
+
const existing = this.parametricSorts.get(key);
|
|
1595
|
+
if (existing !== undefined) return existing;
|
|
1596
|
+
const sort = this.addSort(
|
|
1597
|
+
getSymbolName(name),
|
|
1598
|
+
family,
|
|
1599
|
+
parameters,
|
|
1600
|
+
combineHash(getSymbolHash(name), infoHash),
|
|
1601
|
+
);
|
|
1602
|
+
this.sortSmallIds[sort] = this.mkSmallId();
|
|
1603
|
+
this.parametricSorts.set(key, sort);
|
|
1604
|
+
return sort;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
private getUserSortKind(name: SmtSymbol) {
|
|
1608
|
+
const existing = this.userSortKinds.get(name);
|
|
1609
|
+
if (existing !== undefined) return existing;
|
|
1610
|
+
this.userSortKinds.set(name, this.numUserSorts);
|
|
1611
|
+
return this.numUserSorts++;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
mkUninterpretedSort(name: SmtSymbol, parameters: number[]) {
|
|
1615
|
+
return this.mkParametricSort(
|
|
1616
|
+
FAMILY_USER,
|
|
1617
|
+
name,
|
|
1618
|
+
parameters,
|
|
1619
|
+
getInfoHash(
|
|
1620
|
+
Z3_USER_SORT_FAMILY,
|
|
1621
|
+
this.getUserSortKind(name),
|
|
1622
|
+
parameters.map((parameter) => this.sortHashes[parameter]),
|
|
1623
|
+
),
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
mkDatatypeSort(name: string, parameters: number[]) {
|
|
1628
|
+
return this.mkParametricSort(
|
|
1629
|
+
FAMILY_DATATYPE,
|
|
1630
|
+
name,
|
|
1631
|
+
parameters,
|
|
1632
|
+
getInfoHash(Z3_DATATYPE_FAMILY, 0, [
|
|
1633
|
+
getSymbolHash(name),
|
|
1634
|
+
...parameters.map((parameter) => this.sortHashes[parameter]),
|
|
1635
|
+
]),
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
setSortSize(sort: number, size: bigint) {
|
|
1640
|
+
this.sortSizes[sort] = size;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// The sort named by the number index, which stands for a parameter of a datatype declaration.
|
|
1644
|
+
mkTypeParameter(index: number) {
|
|
1645
|
+
const sort = this.mkUninterpretedSort(index, []);
|
|
1646
|
+
this.typeParameters[index] = sort;
|
|
1647
|
+
return sort;
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
getTypeParameterIndex(sort: number) {
|
|
1651
|
+
return this.typeParameters.indexOf(sort);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
getSortSmallId(sort: number) {
|
|
1655
|
+
return this.sortSmallIds[sort];
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
isDatatypeSort(sort: number) {
|
|
1659
|
+
return this.sortFamilies[sort] === FAMILY_DATATYPE;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
// The parameters are those of the port, and parameterHashes hash Z3's.
|
|
1663
|
+
mkDatatypeDecl(
|
|
1664
|
+
op: number,
|
|
1665
|
+
name: string,
|
|
1666
|
+
parameters: number[],
|
|
1667
|
+
parameterHashes: number[],
|
|
1668
|
+
domain: number[],
|
|
1669
|
+
range: number,
|
|
1670
|
+
) {
|
|
1671
|
+
const key = `${op}:${name}:${parameters.join(",")}:${domain.join(",")}:${range}`;
|
|
1672
|
+
const existing = this.datatypeDecls.get(key);
|
|
1673
|
+
if (existing !== undefined) return existing;
|
|
1674
|
+
const decl = this.addDecl(
|
|
1675
|
+
name,
|
|
1676
|
+
FAMILY_DATATYPE,
|
|
1677
|
+
op,
|
|
1678
|
+
domain,
|
|
1679
|
+
range,
|
|
1680
|
+
parameters,
|
|
1681
|
+
getInfoHash(Z3_DATATYPE_FAMILY, op - DATATYPE_OP_BASE, parameterHashes),
|
|
1682
|
+
);
|
|
1683
|
+
this.datatypeDecls.set(key, decl);
|
|
1684
|
+
return decl;
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
getBvSize(sort: number) {
|
|
1688
|
+
return this.sortWidths[sort];
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
isBvSort(sort: number) {
|
|
1692
|
+
return this.sortFamilies[sort] === FAMILY_BV;
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
mkBvDecl(op: number, name: string, parameters: number[], domain: number[], range: number) {
|
|
1696
|
+
const key = `${op}:${parameters.join(",")}:${domain.join(",")}`;
|
|
1697
|
+
const existing = this.bvDecls.get(key);
|
|
1698
|
+
if (existing !== undefined) return existing;
|
|
1699
|
+
const decl = this.addDecl(
|
|
1700
|
+
name,
|
|
1701
|
+
FAMILY_BV,
|
|
1702
|
+
op,
|
|
1703
|
+
domain,
|
|
1704
|
+
range,
|
|
1705
|
+
parameters,
|
|
1706
|
+
getInfoHash(Z3_BV_FAMILY, op - BV_OP_BASE, parameters),
|
|
1707
|
+
!UNCACHED_BV_OPS.has(op),
|
|
1708
|
+
);
|
|
1709
|
+
this.bvDecls.set(key, decl);
|
|
1710
|
+
return decl;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
mkBvNumeral(value: bigint, width: number) {
|
|
1714
|
+
const modulus = 1n << BigInt(width);
|
|
1715
|
+
const normalized = ((value % modulus) + modulus) % modulus;
|
|
1716
|
+
const sort = this.mkBvSort(width);
|
|
1717
|
+
const key = `b${width}:${normalized}`;
|
|
1718
|
+
const existing = this.table.get(key);
|
|
1719
|
+
if (existing !== undefined) return this.revive(existing);
|
|
1720
|
+
let decl = this.bvDecls.get(`n${width}`);
|
|
1721
|
+
if (decl === undefined) {
|
|
1722
|
+
decl = this.funcDecls.length;
|
|
1723
|
+
this.funcDecls.push({
|
|
1724
|
+
name: "bv",
|
|
1725
|
+
family: FAMILY_BV,
|
|
1726
|
+
op: OP_BV_NUM,
|
|
1727
|
+
domain: [],
|
|
1728
|
+
range: sort,
|
|
1729
|
+
isSkolem: false,
|
|
1730
|
+
smallId: -1,
|
|
1731
|
+
parameters: [width],
|
|
1732
|
+
});
|
|
1733
|
+
this.bvDecls.set(`n${width}`, decl);
|
|
1734
|
+
}
|
|
1735
|
+
this.numeralValues.push(Rational.of(normalized));
|
|
1736
|
+
const numeralDecl = decl;
|
|
1737
|
+
return this.intern(key, KIND_APP, numeralDecl, [], sort, this.numeralValues.length - 1, () =>
|
|
1738
|
+
this.getFuncDeclHash(
|
|
1739
|
+
"bv",
|
|
1740
|
+
[],
|
|
1741
|
+
sort,
|
|
1742
|
+
getInfoHash(Z3_BV_FAMILY, 0, [(getIntegerHash(normalized) + 3) >>> 0, width]),
|
|
1743
|
+
),
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
isBvNumeral(expr: number) {
|
|
1748
|
+
return this.getOp(expr) === OP_BV_NUM;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
getBvNumeralValue(expr: number) {
|
|
1752
|
+
return this.numeralValues[this.values[expr]].num;
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
getSortFamily(sort: number) {
|
|
1756
|
+
return this.sortFamilies[sort];
|
|
1757
|
+
}
|
|
1758
|
+
|
|
684
1759
|
private getFuncDeclHash(name: SmtSymbol, domain: number[], range: number, infoHash: number) {
|
|
685
1760
|
return astArrayHash(
|
|
686
1761
|
domain,
|
|
@@ -689,14 +1764,13 @@ export class AstManager {
|
|
|
689
1764
|
);
|
|
690
1765
|
}
|
|
691
1766
|
|
|
692
|
-
// The name, Z3 decl kind and domain of the Z3 declaration of a builtin application.
|
|
693
1767
|
getBuiltinSignature(op: number, args: number[]) {
|
|
694
1768
|
const builtin = Z3_BUILTINS.get(op);
|
|
695
1769
|
if (builtin === undefined)
|
|
696
1770
|
throw new SmtInvariantError(`the operator ${op} has no Z3 declaration`);
|
|
697
1771
|
const argSort = op === OP_ITE ? this.sorts[args[1]] : this.sorts[args[0]];
|
|
698
1772
|
const arity = builtin[2] === -1 ? args.length : builtin[2];
|
|
699
|
-
const domain = Array.from({ length: arity }, (
|
|
1773
|
+
const domain = Array.from({ length: arity }, (_value, index) =>
|
|
700
1774
|
op === OP_PATTERN
|
|
701
1775
|
? this.sorts[args[index]]
|
|
702
1776
|
: op === OP_ITE && index === 0
|
|
@@ -706,7 +1780,6 @@ export class AstManager {
|
|
|
706
1780
|
return { name: builtin[0], kind: builtin[1], domain };
|
|
707
1781
|
}
|
|
708
1782
|
|
|
709
|
-
// The hash of a pattern's Z3 declaration.
|
|
710
1783
|
private getPatternHash(args: number[], range: number) {
|
|
711
1784
|
const key = `${args.map((arg) => this.sorts[arg]).join(",")}:${range}`;
|
|
712
1785
|
const existing = this.patternHashes.get(key);
|
|
@@ -716,9 +1789,7 @@ export class AstManager {
|
|
|
716
1789
|
return hash;
|
|
717
1790
|
}
|
|
718
1791
|
|
|
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.
|
|
1792
|
+
// Returns the slot, a small integer, because V8 boxes a hash it returns.
|
|
722
1793
|
private getBuiltinSlot(op: number, args: number[], range: number) {
|
|
723
1794
|
const argSort = args.length === 0 ? 0 : this.sorts[op === OP_ITE ? args[1] : args[0]];
|
|
724
1795
|
const count = args.length;
|
|
@@ -744,7 +1815,6 @@ export class AstManager {
|
|
|
744
1815
|
return this.insertBuiltinHash(op, argSort, range, count, hash);
|
|
745
1816
|
}
|
|
746
1817
|
|
|
747
|
-
// The slot of the builtin hash with these keys, or the free slot where it goes.
|
|
748
1818
|
private findBuiltinSlot(op: number, argSort: number, range: number, count: number) {
|
|
749
1819
|
const keys = this.builtinKeys;
|
|
750
1820
|
const mask = this.builtinHashes.length - 1;
|
|
@@ -789,11 +1859,20 @@ export class AstManager {
|
|
|
789
1859
|
);
|
|
790
1860
|
}
|
|
791
1861
|
|
|
792
|
-
// The hash of a user declaration, which Z3's tables of declarations hash.
|
|
793
1862
|
getDeclHash(decl: number) {
|
|
794
1863
|
return this.declHashes[decl];
|
|
795
1864
|
}
|
|
796
1865
|
|
|
1866
|
+
getAppDeclHash(app: number) {
|
|
1867
|
+
const decl = this.decls[app];
|
|
1868
|
+
const funcDecl = this.funcDecls[decl];
|
|
1869
|
+
if (hasOwnDeclHash(funcDecl.family)) return this.declHashes[decl];
|
|
1870
|
+
const args = this.getArgs(app);
|
|
1871
|
+
return funcDecl.op === OP_PATTERN
|
|
1872
|
+
? this.getPatternHash(args, this.sorts[app])
|
|
1873
|
+
: this.builtinHashes[this.getBuiltinSlot(funcDecl.op, args, this.sorts[app])];
|
|
1874
|
+
}
|
|
1875
|
+
|
|
797
1876
|
mkFuncDecl(name: SmtSymbol, domain: number[], range: number, isSkolem = false) {
|
|
798
1877
|
this.declHashes[this.funcDecls.length] = this.getFuncDeclHash(
|
|
799
1878
|
name,
|
|
@@ -809,25 +1888,49 @@ export class AstManager {
|
|
|
809
1888
|
range,
|
|
810
1889
|
isSkolem,
|
|
811
1890
|
smallId: this.mkSmallId(),
|
|
1891
|
+
parameters: [],
|
|
812
1892
|
});
|
|
813
1893
|
this.declRefCounts[this.funcDecls.length - 1] = 1;
|
|
814
1894
|
return this.funcDecls.length - 1;
|
|
815
1895
|
}
|
|
816
1896
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1897
|
+
mkFreshFuncDecl(
|
|
1898
|
+
prefix: SmtSymbol | null,
|
|
1899
|
+
domain: number[],
|
|
1900
|
+
range: number,
|
|
1901
|
+
isSkolem = true,
|
|
1902
|
+
suffix = "",
|
|
1903
|
+
) {
|
|
1904
|
+
const name =
|
|
1905
|
+
prefix === null && suffix === ""
|
|
1906
|
+
? this.freshId
|
|
1907
|
+
: `${prefix === null ? "sk" : getSymbolName(prefix)}!${suffix === "" ? "" : `${suffix}!`}${this.freshId}`;
|
|
820
1908
|
this.freshId++;
|
|
821
1909
|
const decl = this.mkFuncDecl(name, domain, range, isSkolem);
|
|
822
1910
|
this.declRefCounts[decl] = 0;
|
|
823
1911
|
return decl;
|
|
824
1912
|
}
|
|
825
1913
|
|
|
826
|
-
|
|
1914
|
+
mkPbAuxBool() {
|
|
1915
|
+
const decl = this.addDecl(
|
|
1916
|
+
this.mkFreshVarName("pb"),
|
|
1917
|
+
FAMILY_PB,
|
|
1918
|
+
OP_PB_AUX_BOOL,
|
|
1919
|
+
[],
|
|
1920
|
+
SORT_BOOL,
|
|
1921
|
+
[],
|
|
1922
|
+
getInfoHash(Z3_PB_FAMILY, OP_PB_AUX_BOOL - PB_OP_BASE, []),
|
|
1923
|
+
);
|
|
1924
|
+
this.declRefCounts[decl] = 0;
|
|
1925
|
+
return this.mkApp(decl, [], SORT_BOOL);
|
|
1926
|
+
}
|
|
1927
|
+
|
|
827
1928
|
mkFreshVarName(prefix: string | null) {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1929
|
+
return `${prefix ?? "var"}!${this.mkFreshId()}`;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
mkFreshId() {
|
|
1933
|
+
return this.freshId++;
|
|
831
1934
|
}
|
|
832
1935
|
|
|
833
1936
|
private intern(
|
|
@@ -863,6 +1966,7 @@ export class AstManager {
|
|
|
863
1966
|
this.values = grow(this.values);
|
|
864
1967
|
this.freeVarBounds = grow(this.freeVarBounds);
|
|
865
1968
|
this.hasQuantifierFlags = grow(this.hasQuantifierFlags);
|
|
1969
|
+
this.hasLabelFlags = grow(this.hasLabelFlags);
|
|
866
1970
|
this.depths = grow(this.depths);
|
|
867
1971
|
this.hashes = grow(this.hashes);
|
|
868
1972
|
this.ids = grow(this.ids);
|
|
@@ -871,7 +1975,6 @@ export class AstManager {
|
|
|
871
1975
|
this.hashes[id] = hash;
|
|
872
1976
|
this.kinds[id] = kind;
|
|
873
1977
|
this.decls[id] = decl;
|
|
874
|
-
// Like Z3, a node keeps its own copy of the arguments, so callers may reuse their arrays.
|
|
875
1978
|
const start = this.argStarts[id];
|
|
876
1979
|
const end = start + args.length;
|
|
877
1980
|
if (end > this.argPool.length) {
|
|
@@ -890,25 +1993,30 @@ export class AstManager {
|
|
|
890
1993
|
this.values[id] = value;
|
|
891
1994
|
let freeVarBound = kind === KIND_VAR ? value + 1 : 0;
|
|
892
1995
|
let hasQuantifier = kind === KIND_QUANTIFIER;
|
|
1996
|
+
let hasLabel = kind === KIND_APP && this.funcDecls[decl].op === OP_LABEL;
|
|
893
1997
|
let depth = 1;
|
|
894
1998
|
for (let index = 0; index < args.length; index++) {
|
|
895
1999
|
const arg = args[index];
|
|
896
2000
|
if (this.freeVarBounds[arg] > freeVarBound) freeVarBound = this.freeVarBounds[arg];
|
|
897
2001
|
if (this.hasQuantifierFlags[arg]) hasQuantifier = true;
|
|
2002
|
+
if (this.hasLabelFlags[arg]) hasLabel = true;
|
|
898
2003
|
if (this.depths[arg] + 1 > depth) depth = this.depths[arg] + 1;
|
|
899
2004
|
}
|
|
900
2005
|
this.freeVarBounds[id] = freeVarBound;
|
|
901
2006
|
this.hasQuantifierFlags[id] = hasQuantifier ? 1 : 0;
|
|
2007
|
+
this.hasLabelFlags[id] = hasLabel ? 1 : 0;
|
|
902
2008
|
this.depths[id] = depth;
|
|
903
2009
|
return id;
|
|
904
2010
|
}
|
|
905
2011
|
|
|
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
2012
|
mkApp(decl: number, args: number[], sort: number, start = 0) {
|
|
909
2013
|
const funcDecl = this.funcDecls[decl];
|
|
910
|
-
|
|
911
|
-
|
|
2014
|
+
if (
|
|
2015
|
+
decl === OP_NUM ||
|
|
2016
|
+
decl === OP_ALGEBRAIC_NUM ||
|
|
2017
|
+
funcDecl.family === FAMILY_MODEL_VALUE ||
|
|
2018
|
+
funcDecl.op === OP_BV_NUM
|
|
2019
|
+
)
|
|
912
2020
|
throw new SmtInvariantError(`${funcDecl.name} needs a value`);
|
|
913
2021
|
let hash = decl;
|
|
914
2022
|
for (let index = start; index < args.length; index++)
|
|
@@ -931,17 +2039,16 @@ export class AstManager {
|
|
|
931
2039
|
for (let index = start; index < args.length; index++) this.argBuffer.push(args[index]);
|
|
932
2040
|
}
|
|
933
2041
|
const nodeArgs = start > 0 ? this.argBuffer : args;
|
|
934
|
-
|
|
2042
|
+
const hasOwnHash = hasOwnDeclHash(funcDecl.family);
|
|
935
2043
|
const builtinSlot =
|
|
936
|
-
|
|
2044
|
+
hasOwnHash || funcDecl.op === OP_PATTERN
|
|
937
2045
|
? -1
|
|
938
2046
|
: this.getBuiltinSlot(funcDecl.op, nodeArgs, sort);
|
|
939
|
-
const declHash =
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
: this.builtinHashes[builtinSlot];
|
|
2047
|
+
const declHash = hasOwnHash
|
|
2048
|
+
? this.declHashes[decl]
|
|
2049
|
+
: builtinSlot === -1
|
|
2050
|
+
? this.getPatternHash(nodeArgs, sort)
|
|
2051
|
+
: this.builtinHashes[builtinSlot];
|
|
945
2052
|
const id = this.create(
|
|
946
2053
|
KIND_APP,
|
|
947
2054
|
decl,
|
|
@@ -950,7 +2057,6 @@ export class AstManager {
|
|
|
950
2057
|
0,
|
|
951
2058
|
astArrayHash(nodeArgs, this.hashes, declHash),
|
|
952
2059
|
);
|
|
953
|
-
// The lookup ended at a free slot, which the application takes unless the table doubles.
|
|
954
2060
|
if (2 * (this.numApps + 1) > this.appHandles.length) {
|
|
955
2061
|
const handles = this.appHandles;
|
|
956
2062
|
const hashes = this.appHashes;
|
|
@@ -978,8 +2084,6 @@ export class AstManager {
|
|
|
978
2084
|
this.numApps++;
|
|
979
2085
|
}
|
|
980
2086
|
|
|
981
|
-
// A numeral's declaration has the parameters (value, is_int), and a rational hashes as
|
|
982
|
-
// hash(numerator) + 3 hash(denominator).
|
|
983
2087
|
private internNumeral(key: string, value: Rational, sort: number) {
|
|
984
2088
|
const existing = this.table.get(key);
|
|
985
2089
|
if (existing !== undefined) return this.revive(existing);
|
|
@@ -998,6 +2102,60 @@ export class AstManager {
|
|
|
998
2102
|
);
|
|
999
2103
|
}
|
|
1000
2104
|
|
|
2105
|
+
get am() {
|
|
2106
|
+
this.algebraicManager ??= new AlgebraicManager(this.limit);
|
|
2107
|
+
return this.algebraicManager;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
mkAlgebraicNumeral(value: Anum, sort = SORT_REAL) {
|
|
2111
|
+
if (this.am.isRational(value)) return this.mkNumeralOfSort(this.am.toRational(value), sort);
|
|
2112
|
+
if (sort === SORT_INT)
|
|
2113
|
+
throw new SmtInvariantError("invalid irrational value passed as an integer");
|
|
2114
|
+
const id = this.mkAlgebraicId();
|
|
2115
|
+
this.algebraicNumerals.push({ value: this.am.copy(value), id });
|
|
2116
|
+
const expr = this.create(
|
|
2117
|
+
KIND_APP,
|
|
2118
|
+
OP_ALGEBRAIC_NUM,
|
|
2119
|
+
[],
|
|
2120
|
+
SORT_REAL,
|
|
2121
|
+
this.algebraicNumerals.length - 1,
|
|
2122
|
+
this.getFuncDeclHash("RootObject", [], SORT_REAL, getInfoHash(Z3_ARITH_FAMILY, 1, [id])),
|
|
2123
|
+
);
|
|
2124
|
+
this.registerNode(expr);
|
|
2125
|
+
return expr;
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
private mkAlgebraicId() {
|
|
2129
|
+
return this.freeAlgebraicIds.pop() ?? this.nextAlgebraicId++;
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
isAlgebraicNumeral(expr: number) {
|
|
2133
|
+
return this.getOp(expr) === OP_ALGEBRAIC_NUM;
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
getAlgebraicValue(expr: number) {
|
|
2137
|
+
return this.algebraicNumerals[this.values[expr]].value;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
private getAnumOrNumeral(expr: number) {
|
|
2141
|
+
if (this.isAlgebraicNumeral(expr)) return this.getAlgebraicValue(expr);
|
|
2142
|
+
return this.isNumeral(expr) ? new Anum(this.getRationalValue(expr)) : undefined;
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
compareArithValues(first: number, second: number) {
|
|
2146
|
+
if (this.isNumeral(first) && this.isNumeral(second))
|
|
2147
|
+
return this.getRationalValue(first).compare(this.getRationalValue(second));
|
|
2148
|
+
const firstValue = this.getAnumOrNumeral(first);
|
|
2149
|
+
const secondValue = this.getAnumOrNumeral(second);
|
|
2150
|
+
if (firstValue === undefined || secondValue === undefined)
|
|
2151
|
+
throw new SmtInvariantError("arith_value_order compares numerals");
|
|
2152
|
+
return this.am.compare(firstValue, secondValue);
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
getAlgebraicId(expr: number) {
|
|
2156
|
+
return this.algebraicNumerals[this.values[expr]].id;
|
|
2157
|
+
}
|
|
2158
|
+
|
|
1001
2159
|
mkRealNumeral(value: Rational) {
|
|
1002
2160
|
const numeral = this.internNumeral(`r${value}`, value, SORT_REAL);
|
|
1003
2161
|
return value.isInt() ? this.holdSmallNumeral(numeral, value.num, this.smallReals) : numeral;
|
|
@@ -1021,12 +2179,10 @@ export class AstManager {
|
|
|
1021
2179
|
return numeral;
|
|
1022
2180
|
}
|
|
1023
2181
|
|
|
1024
|
-
// mk_numeral(value, is_int).
|
|
1025
2182
|
mkNumeralOfSort(value: Rational, sort: number) {
|
|
1026
2183
|
return sort === SORT_INT ? this.mkNumeral(value.num) : this.mkRealNumeral(value);
|
|
1027
2184
|
}
|
|
1028
2185
|
|
|
1029
|
-
// mk_model_value: the element with this index in the universe of an uninterpreted sort.
|
|
1030
2186
|
mkModelValue(index: number, sort: number) {
|
|
1031
2187
|
const key = `m${sort}:${index}`;
|
|
1032
2188
|
const existing = this.table.get(key);
|
|
@@ -1039,6 +2195,7 @@ export class AstManager {
|
|
|
1039
2195
|
range: sort,
|
|
1040
2196
|
isSkolem: false,
|
|
1041
2197
|
smallId: -1,
|
|
2198
|
+
parameters: [],
|
|
1042
2199
|
});
|
|
1043
2200
|
const decl = this.funcDecls.length - 1;
|
|
1044
2201
|
this.declHashes[decl] = this.getFuncDeclHash(
|
|
@@ -1063,19 +2220,30 @@ export class AstManager {
|
|
|
1063
2220
|
mkQuantifier(data: QuantifierData) {
|
|
1064
2221
|
if (data.names.length !== data.sorts.length)
|
|
1065
2222
|
throw new SmtInvariantError("a quantifier needs a name for each variable");
|
|
1066
|
-
|
|
2223
|
+
// Z3 keeps no-patterns only on a quantifier without patterns.
|
|
2224
|
+
const noPatterns = data.patterns.length > 0 ? [] : data.noPatterns;
|
|
2225
|
+
const key = `q${data.kind}:${data.sorts.join(",")}:${JSON.stringify(data.names)}:${
|
|
1067
2226
|
data.body
|
|
1068
|
-
}:${data.patterns.join(",")}:${data.weight}`;
|
|
2227
|
+
}:${data.patterns.join(",")}:${noPatterns.join(",")}:${data.weight}:${data.qid}`;
|
|
1069
2228
|
const existing = this.table.get(key);
|
|
1070
|
-
if (existing !== undefined)
|
|
2229
|
+
if (existing !== undefined) {
|
|
2230
|
+
// A dead quantifier comes back as the new one Z3 makes, with its skolem id.
|
|
2231
|
+
if (this.ids[existing] === -1) {
|
|
2232
|
+
const old = this.getQuantifier(existing);
|
|
2233
|
+
this.quantifiers.set(existing, { ...old, skid: data.skid });
|
|
2234
|
+
}
|
|
2235
|
+
return this.revive(existing);
|
|
2236
|
+
}
|
|
1071
2237
|
const id = this.create(
|
|
1072
2238
|
KIND_QUANTIFIER,
|
|
1073
2239
|
-1,
|
|
1074
2240
|
[data.body],
|
|
1075
|
-
|
|
2241
|
+
data.kind === QUANTIFIER_LAMBDA
|
|
2242
|
+
? this.mkArraySort([...data.sorts, this.sorts[data.body]])
|
|
2243
|
+
: SORT_BOOL,
|
|
1076
2244
|
0,
|
|
1077
2245
|
mkMix(
|
|
1078
|
-
astArrayHash(data.sorts, this.sortHashes, data.
|
|
2246
|
+
astArrayHash(data.sorts, this.sortHashes, data.kind === QUANTIFIER_FORALL ? 31 : 19),
|
|
1079
2247
|
data.patterns.length,
|
|
1080
2248
|
this.hashes[data.body],
|
|
1081
2249
|
),
|
|
@@ -1088,12 +2256,65 @@ export class AstManager {
|
|
|
1088
2256
|
sorts: [...data.sorts],
|
|
1089
2257
|
names: [...data.names],
|
|
1090
2258
|
patterns: [...data.patterns],
|
|
2259
|
+
noPatterns: [...noPatterns],
|
|
1091
2260
|
});
|
|
1092
2261
|
this.registerNode(id);
|
|
1093
2262
|
return id;
|
|
1094
2263
|
}
|
|
1095
2264
|
|
|
1096
|
-
//
|
|
2265
|
+
// A label takes its polarity and names as the parameters of its declaration, and a label literal
|
|
2266
|
+
// takes its names.
|
|
2267
|
+
mkLabel(isPositive: boolean, names: string[], expr: number) {
|
|
2268
|
+
return this.mkApp(this.mkLabelDecl(OP_LABEL, isPositive, names), [expr], SORT_BOOL);
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
mkLabelLit(names: string[]) {
|
|
2272
|
+
return this.mkApp(this.mkLabelDecl(OP_LABEL_LIT, true, names), [], SORT_BOOL);
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
private mkLabelDecl(op: number, isPositive: boolean, names: string[]) {
|
|
2276
|
+
const nameIds = names.map((name) => {
|
|
2277
|
+
const existing = this.labelNameIds.get(name);
|
|
2278
|
+
if (existing !== undefined) return existing;
|
|
2279
|
+
this.labelNames.push(name);
|
|
2280
|
+
this.labelNameIds.set(name, this.labelNames.length - 1);
|
|
2281
|
+
return this.labelNames.length - 1;
|
|
2282
|
+
});
|
|
2283
|
+
const parameters = op === OP_LABEL ? [isPositive ? 1 : 0, ...nameIds] : nameIds;
|
|
2284
|
+
const key = `${op}:${parameters.join(",")}`;
|
|
2285
|
+
const existing = this.labelDecls.get(key);
|
|
2286
|
+
if (existing !== undefined) return existing;
|
|
2287
|
+
const name = op === OP_LABEL_LIT ? "lbl-lit" : isPositive ? "lblpos" : "lblneg";
|
|
2288
|
+
const domain = op === OP_LABEL ? [SORT_BOOL] : [];
|
|
2289
|
+
const parameterHashes = names.map(getSymbolHash);
|
|
2290
|
+
const decl = this.addDecl(
|
|
2291
|
+
name,
|
|
2292
|
+
FAMILY_LABEL,
|
|
2293
|
+
op,
|
|
2294
|
+
domain,
|
|
2295
|
+
SORT_BOOL,
|
|
2296
|
+
parameters,
|
|
2297
|
+
getInfoHash(
|
|
2298
|
+
Z3_LABEL_FAMILY,
|
|
2299
|
+
op - LABEL_OP_BASE,
|
|
2300
|
+
op === OP_LABEL ? [isPositive ? 1 : 0, ...parameterHashes] : parameterHashes,
|
|
2301
|
+
),
|
|
2302
|
+
);
|
|
2303
|
+
this.labelDecls.set(key, decl);
|
|
2304
|
+
return decl;
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
isLabelPositive(decl: number) {
|
|
2308
|
+
return this.funcDecls[decl].parameters[0] === 1;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
getLabelNames(decl: number) {
|
|
2312
|
+
const funcDecl = this.funcDecls[decl];
|
|
2313
|
+
return funcDecl.parameters
|
|
2314
|
+
.slice(funcDecl.op === OP_LABEL ? 1 : 0)
|
|
2315
|
+
.map((nameId) => this.labelNames[nameId]);
|
|
2316
|
+
}
|
|
2317
|
+
|
|
1097
2318
|
mkPattern(terms: number[]) {
|
|
1098
2319
|
return this.mkApp(OP_PATTERN, terms, SORT_BOOL);
|
|
1099
2320
|
}
|
|
@@ -1104,6 +2325,12 @@ export class AstManager {
|
|
|
1104
2325
|
return data;
|
|
1105
2326
|
}
|
|
1106
2327
|
|
|
2328
|
+
isLambda(expr: number) {
|
|
2329
|
+
return (
|
|
2330
|
+
this.kinds[expr] === KIND_QUANTIFIER && this.getQuantifier(expr).kind === QUANTIFIER_LAMBDA
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
|
|
1107
2334
|
isApp(expr: number) {
|
|
1108
2335
|
return this.kinds[expr] === KIND_APP;
|
|
1109
2336
|
}
|
|
@@ -1116,7 +2343,6 @@ export class AstManager {
|
|
|
1116
2343
|
return this.freeVarBounds[expr] === 0;
|
|
1117
2344
|
}
|
|
1118
2345
|
|
|
1119
|
-
// Z3's is_ground: an application without variables or quantifiers.
|
|
1120
2346
|
isGroundApp(expr: number) {
|
|
1121
2347
|
return (
|
|
1122
2348
|
this.kinds[expr] === KIND_APP &&
|
|
@@ -1170,40 +2396,113 @@ export class AstManager {
|
|
|
1170
2396
|
return this.getOp(expr) === OP_NUM;
|
|
1171
2397
|
}
|
|
1172
2398
|
|
|
1173
|
-
// The value of an integer numeral.
|
|
1174
2399
|
getNumeral(expr: number) {
|
|
1175
2400
|
return this.isNumeral(expr) && this.sorts[expr] === SORT_INT
|
|
1176
2401
|
? this.getNumeralValue(expr)
|
|
1177
2402
|
: undefined;
|
|
1178
2403
|
}
|
|
1179
2404
|
|
|
1180
|
-
// The value of an expression that is an integer numeral.
|
|
1181
2405
|
getNumeralValue(expr: number) {
|
|
1182
2406
|
return this.numeralValues[this.values[expr]].num;
|
|
1183
2407
|
}
|
|
1184
2408
|
|
|
1185
|
-
// The value of an expression that is a numeral of either sort.
|
|
1186
2409
|
getRationalValue(expr: number) {
|
|
1187
2410
|
return this.numeralValues[this.values[expr]];
|
|
1188
2411
|
}
|
|
1189
2412
|
|
|
1190
|
-
|
|
1191
|
-
isUniqueValue(expr: number) {
|
|
2413
|
+
isUniqueValue(expr: number): boolean {
|
|
1192
2414
|
const op = this.getOp(expr);
|
|
1193
|
-
return
|
|
2415
|
+
return (
|
|
2416
|
+
op === OP_NUM ||
|
|
2417
|
+
op === OP_PI ||
|
|
2418
|
+
op === OP_E ||
|
|
2419
|
+
op === OP_TRUE ||
|
|
2420
|
+
op === OP_FALSE ||
|
|
2421
|
+
op === OP_MODEL_VALUE ||
|
|
2422
|
+
op === OP_BV_NUM ||
|
|
2423
|
+
op === OP_CHAR_CONST ||
|
|
2424
|
+
(op >= OP_FPA_RM_NEAREST_TIES_TO_EVEN && op <= OP_FPA_RM_TOWARD_ZERO) ||
|
|
2425
|
+
(op === OP_CONST_ARRAY && this.isUniqueValue(this.getArg(expr, 0))) ||
|
|
2426
|
+
(op === OP_DT_CONSTRUCTOR && this.everyArg(expr, (arg) => this.isUniqueValue(arg))) ||
|
|
2427
|
+
(op === OP_FPA_FP && this.isUniqueFp(expr))
|
|
2428
|
+
);
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
private isUniqueFp(expr: number) {
|
|
2432
|
+
if (!this.everyArg(expr, (arg) => this.isValue(arg))) return false;
|
|
2433
|
+
const exponent = this.getArg(expr, 1);
|
|
2434
|
+
const value = this.getBvNumeralValue(exponent);
|
|
2435
|
+
return value !== 0n && value !== (1n << BigInt(this.getBvSize(this.sorts[exponent]))) - 1n;
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
isValue(expr: number): boolean {
|
|
2439
|
+
let current = expr;
|
|
2440
|
+
while (this.getOp(current) === OP_STORE) {
|
|
2441
|
+
for (let index = 1; index < this.getNumArgs(current); index++)
|
|
2442
|
+
if (!this.isValue(this.getArg(current, index))) return false;
|
|
2443
|
+
current = this.getArg(current, 0);
|
|
2444
|
+
}
|
|
2445
|
+
if (this.getOp(current) === OP_CONST_ARRAY) return this.isValue(this.getArg(current, 0));
|
|
2446
|
+
if (this.getOp(current) === OP_DT_CONSTRUCTOR || this.getOp(current) === OP_FPA_FP)
|
|
2447
|
+
return this.everyArg(current, (arg) => this.isValue(arg));
|
|
2448
|
+
if (this.getOp(current) >= OP_FPA_NUM && this.getOp(current) <= OP_FPA_MINUS_ZERO) return true;
|
|
2449
|
+
if (this.getOp(current) === OP_ALGEBRAIC_NUM) return true;
|
|
2450
|
+
if (this.getFamily(current) === FAMILY_SEQ) return this.isSeqValue(current);
|
|
2451
|
+
return current === expr && this.isUniqueValue(expr);
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
private isSeqValue(expr: number) {
|
|
2455
|
+
const todo = [expr];
|
|
2456
|
+
for (let current = todo.pop(); current !== undefined; current = todo.pop()) {
|
|
2457
|
+
const op = this.getOp(current);
|
|
2458
|
+
if (op === OP_SEQ_EMPTY || op === OP_STRING_CONST) continue;
|
|
2459
|
+
if (op === OP_SEQ_UNIT && this.isValue(this.getArg(current, 0))) continue;
|
|
2460
|
+
if (op !== OP_SEQ_CONCAT || !this.everyArg(current, (arg) => this.isApp(arg))) return false;
|
|
2461
|
+
this.pushArgs(current, todo);
|
|
2462
|
+
}
|
|
2463
|
+
return true;
|
|
1194
2464
|
}
|
|
1195
2465
|
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
2466
|
+
private areSeqsDistinct(first: number, second: number): boolean {
|
|
2467
|
+
const firstOp = this.getOp(first);
|
|
2468
|
+
const secondOp = this.getOp(second);
|
|
2469
|
+
if (first === second) return false;
|
|
2470
|
+
if (firstOp === OP_STRING_CONST && secondOp === OP_STRING_CONST) return true;
|
|
2471
|
+
if (firstOp === OP_SEQ_UNIT && secondOp === OP_SEQ_UNIT)
|
|
2472
|
+
return this.areDistinct(this.getArg(first, 0), this.getArg(second, 0));
|
|
2473
|
+
return (
|
|
2474
|
+
(firstOp === OP_SEQ_EMPTY && secondOp === OP_SEQ_UNIT) ||
|
|
2475
|
+
(firstOp === OP_SEQ_UNIT && secondOp === OP_SEQ_EMPTY)
|
|
2476
|
+
);
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
areDistinct(first: number, second: number): boolean {
|
|
1200
2480
|
if (this.kinds[first] !== KIND_APP || this.kinds[second] !== KIND_APP) return false;
|
|
2481
|
+
const pluginFamily =
|
|
2482
|
+
this.getFamily(first) === FAMILY_USER ? this.getFamily(second) : this.getFamily(first);
|
|
2483
|
+
if (pluginFamily === FAMILY_SEQ) return this.areSeqsDistinct(first, second);
|
|
1201
2484
|
if (first !== second && this.isUniqueValue(first) && this.isUniqueValue(second)) return true;
|
|
1202
2485
|
const family = this.funcDecls[this.decls[first]].family;
|
|
2486
|
+
if (family === FAMILY_DATATYPE) {
|
|
2487
|
+
if (this.getOp(first) !== OP_DT_CONSTRUCTOR || this.getOp(second) !== OP_DT_CONSTRUCTOR)
|
|
2488
|
+
return false;
|
|
2489
|
+
if (this.decls[first] !== this.decls[second]) return true;
|
|
2490
|
+
for (let index = this.getNumArgs(first) - 1; index >= 0; index--)
|
|
2491
|
+
if (this.areDistinct(this.getArg(first, index), this.getArg(second, index))) return true;
|
|
2492
|
+
return false;
|
|
2493
|
+
}
|
|
1203
2494
|
if (
|
|
1204
2495
|
(family === FAMILY_USER ? this.funcDecls[this.decls[second]].family : family) !== FAMILY_ARITH
|
|
1205
2496
|
)
|
|
1206
2497
|
return false;
|
|
2498
|
+
const firstValue = this.getAnumOrNumeral(first);
|
|
2499
|
+
const secondValue = this.getAnumOrNumeral(second);
|
|
2500
|
+
if (
|
|
2501
|
+
firstValue !== undefined &&
|
|
2502
|
+
secondValue !== undefined &&
|
|
2503
|
+
(this.isAlgebraicNumeral(first) || this.isAlgebraicNumeral(second))
|
|
2504
|
+
)
|
|
2505
|
+
return this.am.compare(firstValue, secondValue) !== 0;
|
|
1207
2506
|
const isOffsetOf = (sum: number, term: number) => {
|
|
1208
2507
|
if (this.getOp(sum) !== OP_ADD || this.getNumArgs(sum) !== 2) return false;
|
|
1209
2508
|
const first = this.getArg(sum, 0);
|
|
@@ -1220,10 +2519,9 @@ export class AstManager {
|
|
|
1220
2519
|
}
|
|
1221
2520
|
|
|
1222
2521
|
isUninterpretedSort(sort: number) {
|
|
1223
|
-
return sort
|
|
2522
|
+
return this.sortFamilies[sort] === FAMILY_USER;
|
|
1224
2523
|
}
|
|
1225
2524
|
|
|
1226
|
-
// An uninterpreted constant, such as a declared constant or a Skolem constant.
|
|
1227
2525
|
isUninterpretedConst(expr: number) {
|
|
1228
2526
|
return this.isUninterpreted(expr) && this.getNumArgs(expr) === 0;
|
|
1229
2527
|
}
|
|
@@ -1232,7 +2530,6 @@ export class AstManager {
|
|
|
1232
2530
|
return this.getFamily(expr) === FAMILY_USER;
|
|
1233
2531
|
}
|
|
1234
2532
|
|
|
1235
|
-
// arith_util::is_times_minus_one: the t of (* -1 t).
|
|
1236
2533
|
getTimesMinusOneArg(expr: number) {
|
|
1237
2534
|
if (this.getOp(expr) !== OP_MUL || this.getNumArgs(expr) !== 2) return undefined;
|
|
1238
2535
|
const coefficient = this.getArg(expr, 0);
|
|
@@ -1242,7 +2539,6 @@ export class AstManager {
|
|
|
1242
2539
|
: undefined;
|
|
1243
2540
|
}
|
|
1244
2541
|
|
|
1245
|
-
// occurs: decl is applied somewhere in expr.
|
|
1246
2542
|
isOccurring(decl: number, expr: number) {
|
|
1247
2543
|
return this.someSubterm(expr, (current) => this.decls[current] === decl);
|
|
1248
2544
|
}
|
|
@@ -1251,8 +2547,6 @@ export class AstManager {
|
|
|
1251
2547
|
return this.someSubterm(expr, (current) => this.isModelValue(current));
|
|
1252
2548
|
}
|
|
1253
2549
|
|
|
1254
|
-
// for_each_expr: visits the subterms with a stack of its own, so deep terms do not exhaust the call
|
|
1255
|
-
// stack.
|
|
1256
2550
|
private someSubterm(expr: number, predicate: (expr: number) => boolean) {
|
|
1257
2551
|
const visited = new Set<number>();
|
|
1258
2552
|
const todo = [expr];
|
|
@@ -1300,8 +2594,10 @@ export class AstManager {
|
|
|
1300
2594
|
if (kind === KIND_VAR) return `(:var ${this.values[expr]})`;
|
|
1301
2595
|
if (kind === KIND_QUANTIFIER) {
|
|
1302
2596
|
const data = this.getQuantifier(expr);
|
|
1303
|
-
return `(${
|
|
2597
|
+
return `(${["forall", "exists", "lambda"][data.kind]} (${data.sorts.length}) ${this.toString(data.body)})`;
|
|
1304
2598
|
}
|
|
2599
|
+
if (this.getOp(expr) === OP_BV_NUM)
|
|
2600
|
+
return `(_ bv${this.getBvNumeralValue(expr)} ${this.getBvSize(this.sorts[expr])})`;
|
|
1305
2601
|
if (this.getOp(expr) === OP_NUM) {
|
|
1306
2602
|
const value = this.getRationalValue(expr);
|
|
1307
2603
|
if (this.sorts[expr] === SORT_INT) return String(value.num);
|