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