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