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