tla-ts 0.0.4-dev.81d0769 → 0.0.4-dev.8fefa42
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 +62 -70
- package/dist/deciders.cjs +366 -0
- package/dist/deciders.js +366 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -4
- package/dist/parallel-worker.js +1 -4
- package/dist/prove-worker.cjs +9 -0
- package/dist/prove-worker.d.cts +9 -0
- package/dist/prove-worker.d.ts +9 -0
- package/dist/prove-worker.js +9 -0
- package/dist/prove.cjs +515 -0
- package/dist/prove.js +515 -0
- package/dist/run-cli.cjs +30 -47
- package/dist/run-cli.js +30 -47
- package/dist/tlapm.cjs +10 -0
- package/dist/tlapm.js +10 -0
- package/dist/transfer.cjs +38 -44
- package/dist/transfer.js +38 -44
- package/dist/worker.cjs +21 -0
- package/dist/worker.js +21 -0
- package/package.json +21 -12
- package/src/errors.ts +86 -0
- package/src/evaluate.ts +29 -8
- package/src/index.ts +10 -0
- package/src/{obligation-action.ts → obligations/action.ts} +258 -37
- package/src/{obligation-anon.ts → obligations/anon.ts} +13 -7
- package/src/obligations/ctx.ts +64 -0
- package/src/{obligation-deref.ts → obligations/deref.ts} +2 -2
- package/src/{obligation-expression.ts → obligations/expression.ts} +54 -8
- package/src/{obligation-generate.ts → obligations/generate.ts} +134 -61
- package/src/{obligations.ts → obligations/index.ts} +26 -12
- package/src/{obligation-levels.ts → obligations/levels.ts} +12 -2
- package/src/{obligation-module.ts → obligations/module.ts} +46 -20
- package/src/obligations/pickle.ts +100 -0
- package/src/obligations/pragma.ts +189 -0
- package/src/{obligation-printer.ts → obligations/printer.ts} +5 -59
- package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
- package/src/{obligation-source.ts → obligations/source.ts} +91 -35
- package/src/obligations/temporal.ts +319 -0
- package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
- package/src/parallel-worker.ts +2 -18
- package/src/parallel.ts +10 -43
- package/src/prove/decide-pool.ts +100 -0
- package/src/prove/deciders.ts +27 -0
- package/src/prove/isabelle/LICENSE +36 -0
- package/src/prove/isabelle/LICENSE-tlapm +26 -0
- package/src/prove/isabelle/decide.ts +47 -0
- package/src/prove/isabelle/encode.ts +477 -0
- package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
- package/src/prove/isabelle/isar/method.ts +367 -0
- package/src/prove/isabelle/isar/proof.ts +28 -0
- package/src/prove/isabelle/isar/statement.ts +57 -0
- package/src/prove/isabelle/isar/theory.ts +192 -0
- package/src/prove/isabelle/isar/type-check.ts +278 -0
- package/src/prove/isabelle/provers/blast/blast.ts +258 -0
- package/src/prove/isabelle/provers/blast/branch.ts +322 -0
- package/src/prove/isabelle/provers/blast/prove.ts +347 -0
- package/src/prove/isabelle/provers/blast/rules.ts +330 -0
- package/src/prove/isabelle/provers/blast/state.ts +180 -0
- package/src/prove/isabelle/provers/blast/term.ts +547 -0
- package/src/prove/isabelle/provers/clasimp.ts +150 -0
- package/src/prove/isabelle/provers/classical.ts +389 -0
- package/src/prove/isabelle/provers/hypsubst.ts +441 -0
- package/src/prove/isabelle/pure/bicompose.ts +174 -0
- package/src/prove/isabelle/pure/consts.ts +32 -0
- package/src/prove/isabelle/pure/conv.ts +79 -0
- package/src/prove/isabelle/pure/drule.ts +264 -0
- package/src/prove/isabelle/pure/envir.ts +363 -0
- package/src/prove/isabelle/pure/goal.ts +53 -0
- package/src/prove/isabelle/pure/interrupt.ts +16 -0
- package/src/prove/isabelle/pure/list.ts +12 -0
- package/src/prove/isabelle/pure/logic.ts +402 -0
- package/src/prove/isabelle/pure/name.ts +110 -0
- package/src/prove/isabelle/pure/net.ts +262 -0
- package/src/prove/isabelle/pure/object-logic.ts +41 -0
- package/src/prove/isabelle/pure/pattern.ts +650 -0
- package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
- package/src/prove/isabelle/pure/rewriter.ts +602 -0
- package/src/prove/isabelle/pure/search.ts +68 -0
- package/src/prove/isabelle/pure/seq.ts +156 -0
- package/src/prove/isabelle/pure/simplifier.ts +112 -0
- package/src/prove/isabelle/pure/table.ts +208 -0
- package/src/prove/isabelle/pure/tactic.ts +276 -0
- package/src/prove/isabelle/pure/tactical.ts +347 -0
- package/src/prove/isabelle/pure/term-ord.ts +159 -0
- package/src/prove/isabelle/pure/term.ts +808 -0
- package/src/prove/isabelle/pure/thm.ts +806 -0
- package/src/prove/isabelle/pure/type.ts +133 -0
- package/src/prove/isabelle/pure/unify.ts +753 -0
- package/src/prove/isabelle/pure/variable.ts +25 -0
- package/src/prove/isabelle/tla/classical-setup.ts +101 -0
- package/src/prove/isabelle/tla/context.ts +74 -0
- package/src/prove/isabelle/tla/logic-data.ts +5 -0
- package/src/prove/isabelle/tla/logic.ts +215 -0
- package/src/prove/isabelle/tla/simpdata.ts +241 -0
- package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
- package/src/prove/ocaml.ts +22 -0
- package/src/prove/prep/action.ts +520 -0
- package/src/prove/prep/defs.ts +27 -0
- package/src/prove/prep/elab.ts +156 -0
- package/src/prove/prep/enabled-axioms.ts +189 -0
- package/src/prove/prep/enabled.ts +43 -0
- package/src/prove/prep/fingerprint.ts +388 -0
- package/src/prove/prep/flatten.ts +70 -0
- package/src/prove/prep/level-comparison.ts +552 -0
- package/src/prove/prep/md5.ts +67 -0
- package/src/prove/prep/pragma.ts +221 -0
- package/src/prove/prep/trivial.ts +22 -0
- package/src/prove/prove-worker.ts +29 -0
- package/src/prove/prove.ts +417 -0
- package/src/prove/ptl/decide.ts +68 -0
- package/src/prove/ptl/encode.ts +256 -0
- package/src/prove/ptl/sat.ts +151 -0
- package/src/prove/ptl/tableau.ts +276 -0
- package/src/prove/smt/axiomatize.ts +69 -0
- package/src/prove/smt/axioms.ts +210 -0
- package/src/prove/smt/context.ts +108 -0
- package/src/prove/smt/data.ts +665 -0
- package/src/prove/smt/encode.ts +169 -0
- package/src/prove/smt/extensionality.ts +63 -0
- package/src/prove/smt/flatten.ts +127 -0
- package/src/prove/smt/format.ts +143 -0
- package/src/prove/smt/instances.ts +182 -0
- package/src/prove/smt/rewrite.ts +784 -0
- package/src/prove/smt/simplify.ts +57 -0
- package/src/prove/smt/solver/act-cache.ts +265 -0
- package/src/prove/smt/solver/arith-rewriter.ts +962 -0
- package/src/prove/smt/solver/array.ts +22 -0
- package/src/prove/smt/solver/asserted-formulas.ts +469 -0
- package/src/prove/smt/solver/ast-lt.ts +157 -0
- package/src/prove/smt/solver/ast-util.ts +147 -0
- package/src/prove/smt/solver/ast.ts +1315 -0
- package/src/prove/smt/solver/auf-solver.ts +572 -0
- package/src/prove/smt/solver/case-split-queue.ts +178 -0
- package/src/prove/smt/solver/cg-table.ts +175 -0
- package/src/prove/smt/solver/clause.ts +276 -0
- package/src/prove/smt/solver/conflict-resolution.ts +343 -0
- package/src/prove/smt/solver/context.ts +1292 -0
- package/src/prove/smt/solver/ctx-simplify.ts +334 -0
- package/src/prove/smt/solver/der.ts +224 -0
- package/src/prove/smt/solver/dyn-ack.ts +141 -0
- package/src/prove/smt/solver/e-matching.ts +659 -0
- package/src/prove/smt/solver/enode.ts +259 -0
- package/src/prove/smt/solver/expr-ref.ts +21 -0
- package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
- package/src/prove/smt/solver/fingerprints.ts +92 -0
- package/src/prove/smt/solver/flat-literals.ts +51 -0
- package/src/prove/smt/solver/goal.ts +138 -0
- package/src/prove/smt/solver/hash.ts +173 -0
- package/src/prove/smt/solver/hashtable.ts +166 -0
- package/src/prove/smt/solver/internalizer.ts +1381 -0
- package/src/prove/smt/solver/lbool.ts +5 -0
- package/src/prove/smt/solver/literal.ts +24 -0
- package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
- package/src/prove/smt/solver/lp/constraints.ts +78 -0
- package/src/prove/smt/solver/lp/containers.ts +296 -0
- package/src/prove/smt/solver/lp/core-solver.ts +504 -0
- package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
- package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
- package/src/prove/smt/solver/lp/dependency.ts +51 -0
- package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
- package/src/prove/smt/solver/lp/explanation.ts +46 -0
- package/src/prove/smt/solver/lp/gomory.ts +255 -0
- package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
- package/src/prove/smt/solver/lp/hnf.ts +281 -0
- package/src/prove/smt/solver/lp/int-cube.ts +295 -0
- package/src/prove/smt/solver/lp/int-solver.ts +514 -0
- package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
- package/src/prove/smt/solver/lp/lar-term.ts +62 -0
- package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
- package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
- package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
- package/src/prove/smt/solver/lp/nex.ts +120 -0
- package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
- package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
- package/src/prove/smt/solver/lp/nla-core.ts +968 -0
- package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
- package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
- package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
- package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
- package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
- package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
- package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
- package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
- package/src/prove/smt/solver/lp/nla-order.ts +307 -0
- package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
- package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
- package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
- package/src/prove/smt/solver/lp/nla-types.ts +124 -0
- package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
- package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
- package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
- package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
- package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
- package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
- package/src/prove/smt/solver/lp/pdd.ts +971 -0
- package/src/prove/smt/solver/lp/random-updater.ts +138 -0
- package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
- package/src/prove/smt/solver/lp/union-find.ts +96 -0
- package/src/prove/smt/solver/mam-compiler.ts +847 -0
- package/src/prove/smt/solver/mam-interpreter.ts +400 -0
- package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
- package/src/prove/smt/solver/model-checker.ts +347 -0
- package/src/prove/smt/solver/model-evaluator.ts +262 -0
- package/src/prove/smt/solver/model-finder.ts +155 -0
- package/src/prove/smt/solver/model-generator.ts +97 -0
- package/src/prove/smt/solver/model-macro-solver.ts +728 -0
- package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
- package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
- package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
- package/src/prove/smt/solver/nlsat/explain.ts +607 -0
- package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
- package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
- package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
- package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
- package/src/prove/smt/solver/nlsat/solver.ts +911 -0
- package/src/prove/smt/solver/nlsat/types.ts +43 -0
- package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
- package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
- package/src/prove/smt/solver/nnf.ts +469 -0
- package/src/prove/smt/solver/pattern-inference.ts +351 -0
- package/src/prove/smt/solver/poly-rewriter.ts +477 -0
- package/src/prove/smt/solver/propagate-values.ts +83 -0
- package/src/prove/smt/solver/proto-model.ts +551 -0
- package/src/prove/smt/solver/pull-quant.ts +139 -0
- package/src/prove/smt/solver/qe-lite-der.ts +526 -0
- package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
- package/src/prove/smt/solver/qe-lite.ts +381 -0
- package/src/prove/smt/solver/qi-queue.ts +362 -0
- package/src/prove/smt/solver/quant-tactics.ts +117 -0
- package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
- package/src/prove/smt/solver/quantifier-manager.ts +186 -0
- package/src/prove/smt/solver/random-gen.ts +10 -0
- package/src/prove/smt/solver/rational.ts +165 -0
- package/src/prove/smt/solver/ref-vector.ts +62 -0
- package/src/prove/smt/solver/relevancy.ts +247 -0
- package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
- package/src/prove/smt/solver/rewriter.ts +843 -0
- package/src/prove/smt/solver/rlimit.ts +79 -0
- package/src/prove/smt/solver/smtlib-parser.ts +526 -0
- package/src/prove/smt/solver/solver.ts +71 -0
- package/src/prove/smt/solver/sort.ts +35 -0
- package/src/prove/smt/solver/sticky-generations.ts +69 -0
- package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
- package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
- package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
- package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
- package/src/prove/smt/solver/theory-lra-model.ts +243 -0
- package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
- package/src/prove/smt/solver/theory-lra-state.ts +43 -0
- package/src/prove/smt/solver/theory-lra.ts +56 -0
- package/src/prove/smt/solver/var-subst.ts +258 -0
- package/src/prove/smt/solver/z3-license.txt +10 -0
- package/src/prove/smt/table.ts +170 -0
- package/src/prove/tlapm/tlapm.ts +96 -0
- package/src/prove/tlaps-module.ts +510 -0
- package/src/prove/verdict.ts +13 -0
- package/src/prove/zenon/LICENSE +32 -0
- package/src/prove/zenon/check/check.ts +105 -0
- package/src/prove/zenon/check/definitions.ts +144 -0
- package/src/prove/zenon/check/equality.ts +182 -0
- package/src/prove/zenon/check/functions.ts +62 -0
- package/src/prove/zenon/check/keys.ts +125 -0
- package/src/prove/zenon/check/propositional.ts +104 -0
- package/src/prove/zenon/check/records.ts +188 -0
- package/src/prove/zenon/check/relations.ts +121 -0
- package/src/prove/zenon/check/rewrites.ts +224 -0
- package/src/prove/zenon/check/sets.ts +302 -0
- package/src/prove/zenon/check/terms.ts +127 -0
- package/src/prove/zenon/check/tla.ts +126 -0
- package/src/prove/zenon/decide.ts +113 -0
- package/src/prove/zenon/encode.ts +444 -0
- package/src/prove/zenon/eqrel.ts +300 -0
- package/src/prove/zenon/equality-rules.ts +435 -0
- package/src/prove/zenon/expr.ts +551 -0
- package/src/prove/zenon/index-table.ts +350 -0
- package/src/prove/zenon/isar-case.ts +513 -0
- package/src/prove/zenon/isar.ts +1249 -0
- package/src/prove/zenon/limits.ts +15 -0
- package/src/prove/zenon/llproof.ts +173 -0
- package/src/prove/zenon/mltoll.ts +1566 -0
- package/src/prove/zenon/node.ts +297 -0
- package/src/prove/zenon/ocaml.ts +169 -0
- package/src/prove/zenon/parse.ts +247 -0
- package/src/prove/zenon/phrase.ts +191 -0
- package/src/prove/zenon/proof.ts +198 -0
- package/src/prove/zenon/propositional-rules.ts +387 -0
- package/src/prove/zenon/rules.ts +94 -0
- package/src/prove/zenon/search.ts +288 -0
- package/src/prove/zenon/tla/functions.ts +151 -0
- package/src/prove/zenon/tla/llproof.ts +480 -0
- package/src/prove/zenon/tla/records.ts +225 -0
- package/src/prove/zenon/tla/rewrites.ts +447 -0
- package/src/prove/zenon/tla/sets.ts +304 -0
- package/src/prove/zenon/tla/terms.ts +181 -0
- package/src/prove/zenon/tla/tla.ts +506 -0
- package/src/run-cli.ts +73 -20
- package/src/successors.ts +24 -5
- package/src/tlc-version.ts +8 -7
- package/src/values.ts +8 -3
- package/src/worker.ts +65 -0
- package/dist/parallel.cjs +0 -12
- package/dist/parallel.js +0 -12
- /package/src/{obligation-format.ts → obligations/format.ts} +0 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Ported from Z3 (src/smt/smt_enode.h, src/smt/smt_eq_justification.h, src/smt/smt_justification.h),
|
|
2
|
+
// MIT license, see z3-license.txt. E-graph nodes and the justifications for their equalities.
|
|
3
|
+
import type { Literal } from "./literal";
|
|
4
|
+
|
|
5
|
+
export interface Antecedents {
|
|
6
|
+
markLiteral(literal: Literal): void;
|
|
7
|
+
markEq(first: Enode, second: Enode): void;
|
|
8
|
+
markJustification(justification: Justification): void;
|
|
9
|
+
markJustifiedEq(first: Enode, second: Enode, justification: EqJustification): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export abstract class Justification {
|
|
13
|
+
isMarked = false;
|
|
14
|
+
abstract getAntecedents(antecedents: Antecedents): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// eq_justification: why two nodes on a transitivity branch are equal.
|
|
18
|
+
export type EqJustification =
|
|
19
|
+
| { kind: "axiom" }
|
|
20
|
+
| { kind: "congruence"; isCommutative: boolean }
|
|
21
|
+
| { kind: "equation"; literal: Literal }
|
|
22
|
+
| { kind: "justification"; justification: Justification };
|
|
23
|
+
|
|
24
|
+
export const AXIOM_EQ_JUSTIFICATION: EqJustification = { kind: "axiom" };
|
|
25
|
+
|
|
26
|
+
// The congruence justifications, which carry no data of their own and so are shared.
|
|
27
|
+
export const CONGRUENCE_JUSTIFICATIONS: readonly EqJustification[] = [
|
|
28
|
+
{ kind: "congruence", isCommutative: false },
|
|
29
|
+
{ kind: "congruence", isCommutative: true },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
// The parents of a node without any, and the arguments past the second of a node with at most two.
|
|
33
|
+
// Nothing adds to it: addParent gives a node its own list, so that a node with one parent holds one
|
|
34
|
+
// entry instead of V8's sixteen.
|
|
35
|
+
export const NO_ENODES: Enode[] = [];
|
|
36
|
+
|
|
37
|
+
const IS_EQ = 1;
|
|
38
|
+
const IS_BOOL = 2;
|
|
39
|
+
const IS_MERGE_TF = 4;
|
|
40
|
+
const IS_CGC_ENABLED = 8;
|
|
41
|
+
const IS_MARKED = 16;
|
|
42
|
+
const IS_MARKED2 = 32;
|
|
43
|
+
const IS_INTERPRETED = 64;
|
|
44
|
+
// The number of arguments, in the bits of flags above the Boolean fields.
|
|
45
|
+
const NUM_ARGS_SHIFT = 7;
|
|
46
|
+
|
|
47
|
+
export class Enode {
|
|
48
|
+
root: Enode = this;
|
|
49
|
+
next: Enode = this;
|
|
50
|
+
cg: Enode = this;
|
|
51
|
+
classSize = 1;
|
|
52
|
+
parents: Enode[] = NO_ENODES;
|
|
53
|
+
// m_trans: the next node on the transitivity branch toward the root of the proof tree, and why the
|
|
54
|
+
// two are equal.
|
|
55
|
+
transTarget: Enode | null = null;
|
|
56
|
+
transJustification: EqJustification = AXIOM_EQ_JUSTIFICATION;
|
|
57
|
+
thVar = -1;
|
|
58
|
+
// The approximate label sets of the class, 64 bits in two words: the low 32 bits, then the high.
|
|
59
|
+
lbls = 0;
|
|
60
|
+
lblsHigh = 0;
|
|
61
|
+
plbls = 0;
|
|
62
|
+
plblsHigh = 0;
|
|
63
|
+
lblHash = -1;
|
|
64
|
+
// The Boolean fields, one bit each, so a node takes 48 bytes less, and the number of arguments.
|
|
65
|
+
private flags: number;
|
|
66
|
+
// m_args: the first two arguments inline, like Z3's arguments after the node, and the rest in an
|
|
67
|
+
// array. A missing argument is the node itself.
|
|
68
|
+
private readonly arg0: Enode;
|
|
69
|
+
private readonly arg1: Enode;
|
|
70
|
+
private readonly moreArgs: Enode[];
|
|
71
|
+
|
|
72
|
+
// moreArgs are the arguments past the second, and arg0 and arg1 are null when there are fewer.
|
|
73
|
+
constructor(
|
|
74
|
+
readonly owner: number,
|
|
75
|
+
readonly decl: number,
|
|
76
|
+
numArgs: number,
|
|
77
|
+
arg0: Enode | null,
|
|
78
|
+
arg1: Enode | null,
|
|
79
|
+
moreArgs: Enode[],
|
|
80
|
+
public generation: number,
|
|
81
|
+
isEq: boolean,
|
|
82
|
+
isBool: boolean,
|
|
83
|
+
isMergeTf: boolean,
|
|
84
|
+
isCgcEnabled: boolean,
|
|
85
|
+
readonly iscopeLevel: number,
|
|
86
|
+
) {
|
|
87
|
+
this.arg0 = arg0 ?? this;
|
|
88
|
+
this.arg1 = arg1 ?? this;
|
|
89
|
+
this.moreArgs = moreArgs;
|
|
90
|
+
this.flags =
|
|
91
|
+
(numArgs << NUM_ARGS_SHIFT) |
|
|
92
|
+
(isEq ? IS_EQ : 0) |
|
|
93
|
+
(isBool ? IS_BOOL : 0) |
|
|
94
|
+
(isMergeTf ? IS_MERGE_TF : 0) |
|
|
95
|
+
(isCgcEnabled ? IS_CGC_ENABLED : 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private setFlag(flag: number, value: boolean) {
|
|
99
|
+
this.flags = value ? this.flags | flag : this.flags & ~flag;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get numArgs() {
|
|
103
|
+
return this.flags >>> NUM_ARGS_SHIFT;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
getArg(index: number) {
|
|
107
|
+
return index === 0 ? this.arg0 : index === 1 ? this.arg1 : this.moreArgs[index - 2];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get isEq() {
|
|
111
|
+
return (this.flags & IS_EQ) !== 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get isBool() {
|
|
115
|
+
return (this.flags & IS_BOOL) !== 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get isCgcEnabled() {
|
|
119
|
+
return (this.flags & IS_CGC_ENABLED) !== 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get isMergeTf() {
|
|
123
|
+
return (this.flags & IS_MERGE_TF) !== 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
set isMergeTf(value: boolean) {
|
|
127
|
+
this.setFlag(IS_MERGE_TF, value);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get isMarked() {
|
|
131
|
+
return (this.flags & IS_MARKED) !== 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
set isMarked(value: boolean) {
|
|
135
|
+
this.setFlag(IS_MARKED, value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get isMarked2() {
|
|
139
|
+
return (this.flags & IS_MARKED2) !== 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
set isMarked2(value: boolean) {
|
|
143
|
+
this.setFlag(IS_MARKED2, value);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
get isInterpreted() {
|
|
147
|
+
return (this.flags & IS_INTERPRETED) !== 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
set isInterpreted(value: boolean) {
|
|
151
|
+
this.setFlag(IS_INTERPRETED, value);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
addParent(parent: Enode) {
|
|
155
|
+
if (this.parents.length === 0) this.parents = [parent];
|
|
156
|
+
else this.parents.push(parent);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
isCgr() {
|
|
160
|
+
return this.cg === this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
isTrueEq() {
|
|
164
|
+
return this.isEq && this.arg0.root === this.arg1.root;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
usesCgTable() {
|
|
168
|
+
return this.numArgs > 0 && this.isCgcEnabled && !this.isTrueEq();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// eq_propagation_justification: the equality atom is true because its sides are in one class.
|
|
173
|
+
export class EqPropagationJustification extends Justification {
|
|
174
|
+
constructor(
|
|
175
|
+
private first: Enode,
|
|
176
|
+
private second: Enode,
|
|
177
|
+
) {
|
|
178
|
+
super();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
getAntecedents(antecedents: Antecedents) {
|
|
182
|
+
antecedents.markEq(this.first, this.second);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// eq_root_propagation_justification: a Boolean node merged with true or false.
|
|
187
|
+
export class EqRootPropagationJustification extends Justification {
|
|
188
|
+
constructor(private node: Enode) {
|
|
189
|
+
super();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
getAntecedents(antecedents: Antecedents) {
|
|
193
|
+
antecedents.markEq(this.node, this.node.root);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// eq_conflict_justification: two interpreted roots, such as two numerals, were merged.
|
|
198
|
+
export class EqConflictJustification extends Justification {
|
|
199
|
+
constructor(
|
|
200
|
+
private first: Enode,
|
|
201
|
+
private second: Enode,
|
|
202
|
+
private justification: EqJustification,
|
|
203
|
+
) {
|
|
204
|
+
super();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getAntecedents(antecedents: Antecedents) {
|
|
208
|
+
antecedents.markEq(this.first, this.first.root);
|
|
209
|
+
antecedents.markEq(this.second, this.second.root);
|
|
210
|
+
antecedents.markJustifiedEq(this.first, this.second, this.justification);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// mp_iff_justification: a Boolean node takes the value of an equal node.
|
|
215
|
+
export class MpIffJustification extends Justification {
|
|
216
|
+
constructor(
|
|
217
|
+
private first: Enode,
|
|
218
|
+
private second: Enode,
|
|
219
|
+
private getLiteral: (node: Enode) => Literal,
|
|
220
|
+
) {
|
|
221
|
+
super();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
getAntecedents(antecedents: Antecedents) {
|
|
225
|
+
antecedents.markEq(this.first, this.second);
|
|
226
|
+
antecedents.markLiteral(this.getLiteral(this.first));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// unit_resolution_justification: a clause simplified with literals that were false.
|
|
231
|
+
export class UnitResolutionJustification extends Justification {
|
|
232
|
+
constructor(
|
|
233
|
+
private justification: Justification | null,
|
|
234
|
+
private literals: Literal[],
|
|
235
|
+
) {
|
|
236
|
+
super();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
getAntecedents(antecedents: Antecedents) {
|
|
240
|
+
if (this.justification !== null) antecedents.markJustification(this.justification);
|
|
241
|
+
for (const literal of this.literals) antecedents.markLiteral(literal);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ext_theory_propagation_justification: theory reasoning from literals and equalities.
|
|
246
|
+
export class TheoryJustification extends Justification {
|
|
247
|
+
constructor(
|
|
248
|
+
private literals: Literal[],
|
|
249
|
+
private eqs: Enode[],
|
|
250
|
+
) {
|
|
251
|
+
super();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
getAntecedents(antecedents: Antecedents) {
|
|
255
|
+
for (const literal of this.literals) antecedents.markLiteral(literal);
|
|
256
|
+
for (let index = 0; index < this.eqs.length; index += 2)
|
|
257
|
+
antecedents.markEq(this.eqs[index], this.eqs[index + 1]);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Ported from Z3 (src/ast/ast.h), MIT license, see z3-license.txt. The assignments of expr_ref, for
|
|
2
|
+
// code that keeps Z3's reference counts by hand so that expressions are created and deleted in Z3's
|
|
3
|
+
// order. -1 stands for a null expression.
|
|
4
|
+
import type { AstManager } from "./ast";
|
|
5
|
+
|
|
6
|
+
// expr_ref's assignment: the new value gains a reference before the old one loses its own.
|
|
7
|
+
export const assign = (manager: AstManager, old: number, value: number) => {
|
|
8
|
+
if (value !== -1) manager.incRef(value);
|
|
9
|
+
if (old !== -1) manager.decRef(old);
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// expr_ref's move assignment of a value the caller owns.
|
|
14
|
+
export const assignOwned = (manager: AstManager, old: number, value: number) => {
|
|
15
|
+
if (old !== -1) manager.decRef(old);
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const release = (manager: AstManager, expr: number) => {
|
|
20
|
+
if (expr !== -1) manager.decRef(expr);
|
|
21
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Ported from Z3 (src/ast/rewriter/expr_safe_replace.cpp), MIT license, see z3-license.txt.
|
|
2
|
+
// Replaces subterms by terms, under quantifiers too, without rewriting. Like Z3, it visits the
|
|
3
|
+
// arguments of an application from the last one, and holds the expressions it creates.
|
|
4
|
+
import { SmtInvariantError } from "../../../errors";
|
|
5
|
+
import { KIND_APP, KIND_VAR, type AstManager } from "./ast";
|
|
6
|
+
import { RefVector } from "./ref-vector";
|
|
7
|
+
import { VarShifter } from "./rewriter-tpl";
|
|
8
|
+
import { VarSubst } from "./var-subst";
|
|
9
|
+
|
|
10
|
+
export class ExprSafeReplace {
|
|
11
|
+
readonly sources: RefVector;
|
|
12
|
+
readonly targets: RefVector;
|
|
13
|
+
private refs: RefVector;
|
|
14
|
+
private cache = new Map<number, number>();
|
|
15
|
+
|
|
16
|
+
constructor(private manager: AstManager) {
|
|
17
|
+
this.sources = new RefVector(manager);
|
|
18
|
+
this.targets = new RefVector(manager);
|
|
19
|
+
this.refs = new RefVector(manager);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
insert(source: number, target: number) {
|
|
23
|
+
this.sources.push(source);
|
|
24
|
+
this.targets.push(target);
|
|
25
|
+
this.cache.clear();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// operator(): the result comes with a reference, which the caller releases.
|
|
29
|
+
apply(expr: number) {
|
|
30
|
+
const manager = this.manager;
|
|
31
|
+
if (this.sources.size === 0) {
|
|
32
|
+
manager.incRef(expr);
|
|
33
|
+
return expr;
|
|
34
|
+
}
|
|
35
|
+
if (this.cache.size === 0)
|
|
36
|
+
this.sources.items.forEach((source, index) => {
|
|
37
|
+
if (!this.cache.has(source)) this.cache.set(source, this.targets.items[index]);
|
|
38
|
+
});
|
|
39
|
+
const todo = [expr];
|
|
40
|
+
this.refs.push(expr);
|
|
41
|
+
while (todo.length > 0) {
|
|
42
|
+
const current = todo[todo.length - 1];
|
|
43
|
+
if (this.cache.get(current) !== undefined) todo.pop();
|
|
44
|
+
else if (manager.kinds[current] === KIND_VAR) {
|
|
45
|
+
this.cache.set(current, current);
|
|
46
|
+
todo.pop();
|
|
47
|
+
} else if (manager.kinds[current] === KIND_APP) {
|
|
48
|
+
const args: number[] = [];
|
|
49
|
+
let isDifferent = false;
|
|
50
|
+
let hasAllArgs = true;
|
|
51
|
+
for (let index = 0; index < manager.getNumArgs(current); index++) {
|
|
52
|
+
const arg = manager.getArg(current, index);
|
|
53
|
+
const replaced = hasAllArgs ? this.cache.get(arg) : undefined;
|
|
54
|
+
if (replaced !== undefined) {
|
|
55
|
+
args.push(replaced);
|
|
56
|
+
isDifferent ||= arg !== replaced;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
todo.push(arg);
|
|
60
|
+
hasAllArgs = false;
|
|
61
|
+
}
|
|
62
|
+
if (hasAllArgs) {
|
|
63
|
+
const result = isDifferent
|
|
64
|
+
? manager.mkApp(manager.decls[current], args, manager.sorts[current])
|
|
65
|
+
: current;
|
|
66
|
+
if (isDifferent) this.refs.push(result);
|
|
67
|
+
this.cache.set(current, result);
|
|
68
|
+
todo.pop();
|
|
69
|
+
}
|
|
70
|
+
} else this.applyQuantifier(current, todo);
|
|
71
|
+
}
|
|
72
|
+
const result = this.cache.get(expr);
|
|
73
|
+
if (result === undefined) throw new SmtInvariantError("the replaced expression has no result");
|
|
74
|
+
manager.incRef(result);
|
|
75
|
+
if (this.refs.size > 1 << 20) {
|
|
76
|
+
this.cache.clear();
|
|
77
|
+
this.refs.reset();
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Replaces the quantifier, or pushes the children it still needs.
|
|
83
|
+
private applyQuantifier(quantifier: number, todo: number[]) {
|
|
84
|
+
const manager = this.manager;
|
|
85
|
+
const data = manager.getQuantifier(quantifier);
|
|
86
|
+
const patterns = new RefVector(manager);
|
|
87
|
+
let body = -1;
|
|
88
|
+
const isAllGround =
|
|
89
|
+
this.sources.items.every((source) => manager.isGroundApp(source)) &&
|
|
90
|
+
this.targets.items.every((target) => manager.isGroundApp(target));
|
|
91
|
+
if (isAllGround) {
|
|
92
|
+
let hasAllData = true;
|
|
93
|
+
const cachedBody = this.cache.get(data.body);
|
|
94
|
+
if (cachedBody === undefined) {
|
|
95
|
+
todo.push(data.body);
|
|
96
|
+
hasAllData = false;
|
|
97
|
+
} else {
|
|
98
|
+
body = cachedBody;
|
|
99
|
+
manager.incRef(body);
|
|
100
|
+
}
|
|
101
|
+
for (const pattern of data.patterns) {
|
|
102
|
+
const replaced = hasAllData ? this.cache.get(pattern) : undefined;
|
|
103
|
+
if (replaced !== undefined) {
|
|
104
|
+
patterns.push(replaced);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
todo.push(pattern);
|
|
108
|
+
hasAllData = false;
|
|
109
|
+
}
|
|
110
|
+
if (!hasAllData) {
|
|
111
|
+
patterns.reset();
|
|
112
|
+
if (body !== -1) manager.decRef(body);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
const replace = new ExprSafeReplace(manager);
|
|
117
|
+
const shifter = new VarShifter(manager);
|
|
118
|
+
const numDecls = data.sorts.length;
|
|
119
|
+
let source = -1;
|
|
120
|
+
let target = -1;
|
|
121
|
+
let pattern = -1;
|
|
122
|
+
this.sources.items.forEach((original, index) => {
|
|
123
|
+
const shiftedSource = shifter.shift(original, 0, numDecls, 0);
|
|
124
|
+
if (source !== -1) manager.decRef(source);
|
|
125
|
+
source = shiftedSource;
|
|
126
|
+
const shiftedTarget = shifter.shift(this.targets.items[index], 0, numDecls, 0);
|
|
127
|
+
if (target !== -1) manager.decRef(target);
|
|
128
|
+
target = shiftedTarget;
|
|
129
|
+
replace.insert(source, target);
|
|
130
|
+
});
|
|
131
|
+
for (const original of data.patterns) {
|
|
132
|
+
const replaced = replace.apply(original);
|
|
133
|
+
if (pattern !== -1) manager.decRef(pattern);
|
|
134
|
+
pattern = replaced;
|
|
135
|
+
patterns.push(pattern);
|
|
136
|
+
}
|
|
137
|
+
const isAllVars = replace.sources.items.every(
|
|
138
|
+
(replaced) => manager.kinds[replaced] === KIND_VAR,
|
|
139
|
+
);
|
|
140
|
+
if (isAllVars) {
|
|
141
|
+
const maxIndex = Math.max(
|
|
142
|
+
0,
|
|
143
|
+
...replace.sources.items.map((replaced) => manager.values[replaced]),
|
|
144
|
+
);
|
|
145
|
+
const args = Array.from({ length: maxIndex + 1 }, () => -1);
|
|
146
|
+
replace.sources.items.forEach((replaced, index) => {
|
|
147
|
+
args[manager.values[replaced]] = replace.targets.items[index];
|
|
148
|
+
});
|
|
149
|
+
const subst = new VarSubst(manager, false);
|
|
150
|
+
body = subst.apply(data.body, args);
|
|
151
|
+
subst.release();
|
|
152
|
+
} else body = replace.apply(data.body);
|
|
153
|
+
for (const expr of [pattern, target, source]) if (expr !== -1) manager.decRef(expr);
|
|
154
|
+
shifter.release();
|
|
155
|
+
replace.release();
|
|
156
|
+
}
|
|
157
|
+
const result = manager.mkQuantifier({ ...data, body, patterns: [...patterns.items] });
|
|
158
|
+
this.refs.push(result);
|
|
159
|
+
this.cache.set(quantifier, result);
|
|
160
|
+
todo.pop();
|
|
161
|
+
patterns.reset();
|
|
162
|
+
manager.decRef(body);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ~expr_safe_replace.
|
|
166
|
+
release() {
|
|
167
|
+
this.cache.clear();
|
|
168
|
+
this.refs.reset();
|
|
169
|
+
this.targets.reset();
|
|
170
|
+
this.sources.reset();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Ported from Z3 (src/smt/fingerprints.cpp), MIT license, see z3-license.txt. The set of
|
|
2
|
+
// quantifier instances already found, so a match on equal terms is not instantiated twice. Scopes
|
|
3
|
+
// undo the insertions.
|
|
4
|
+
import type { AstManager } from "./ast";
|
|
5
|
+
import type { Enode } from "./enode";
|
|
6
|
+
import { getCompositeHash } from "./hash";
|
|
7
|
+
import { shrink } from "./array";
|
|
8
|
+
|
|
9
|
+
export class FingerprintSet {
|
|
10
|
+
// The quantifier, hash and roots of each fingerprint, in the order of insertion.
|
|
11
|
+
private quantifiers: number[] = [];
|
|
12
|
+
private hashes: number[] = [];
|
|
13
|
+
private roots: Enode[][] = [];
|
|
14
|
+
// Open addressing with linear probing over the indices of the fingerprints, -1 for an empty slot.
|
|
15
|
+
// Scopes remove the newest fingerprints first, and the table grows by inserting them in order, so
|
|
16
|
+
// emptying the slot of a removed fingerprint never cuts the probe of one that remains.
|
|
17
|
+
private slots = new Int32Array(1024).fill(-1);
|
|
18
|
+
private scopes: number[] = [];
|
|
19
|
+
// The hashes and the roots of the bindings of the instance being inserted.
|
|
20
|
+
private bindingHashes: number[] = [];
|
|
21
|
+
private bindingRoots: Enode[] = [];
|
|
22
|
+
|
|
23
|
+
constructor(private manager: AstManager) {}
|
|
24
|
+
|
|
25
|
+
// fingerprint_set::insert: the roots of the bindings, which a new fingerprint keeps, or null when
|
|
26
|
+
// the instance is already in the set. The hash comes from the bindings themselves, and the set is
|
|
27
|
+
// searched with the bindings and then with their roots.
|
|
28
|
+
insert(quantifier: number, bindings: Enode[]) {
|
|
29
|
+
const manager = this.manager;
|
|
30
|
+
const bindingHashes = this.bindingHashes;
|
|
31
|
+
shrink(bindingHashes, 0);
|
|
32
|
+
for (const binding of bindings) bindingHashes.push(manager.hashes[binding.owner]);
|
|
33
|
+
const hash = getCompositeHash(bindingHashes, manager.ids[quantifier]);
|
|
34
|
+
if (this.find(quantifier, hash, bindings) === -1) return null;
|
|
35
|
+
const bindingRoots = this.bindingRoots;
|
|
36
|
+
shrink(bindingRoots, 0);
|
|
37
|
+
for (const binding of bindings) bindingRoots.push(binding.root);
|
|
38
|
+
const slot = this.find(quantifier, hash, bindingRoots);
|
|
39
|
+
if (slot === -1) return null;
|
|
40
|
+
const roots = bindingRoots.slice();
|
|
41
|
+
this.quantifiers.push(quantifier);
|
|
42
|
+
this.hashes.push(hash);
|
|
43
|
+
this.roots.push(roots);
|
|
44
|
+
if (2 * this.quantifiers.length <= this.slots.length)
|
|
45
|
+
this.slots[slot] = this.quantifiers.length - 1;
|
|
46
|
+
else {
|
|
47
|
+
this.slots = new Int32Array(2 * this.slots.length).fill(-1);
|
|
48
|
+
for (let index = 0; index < this.quantifiers.length; index++) this.place(index);
|
|
49
|
+
}
|
|
50
|
+
return roots;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The empty slot that ends the probe for the fingerprint, or -1 when the set has it.
|
|
54
|
+
private find(quantifier: number, hash: number, args: Enode[]) {
|
|
55
|
+
const mask = this.slots.length - 1;
|
|
56
|
+
let slot = hash & mask;
|
|
57
|
+
for (; this.slots[slot] !== -1; slot = (slot + 1) & mask) {
|
|
58
|
+
const index = this.slots[slot];
|
|
59
|
+
if (this.hashes[index] !== hash || this.quantifiers[index] !== quantifier) continue;
|
|
60
|
+
const existing = this.roots[index];
|
|
61
|
+
let position = 0;
|
|
62
|
+
while (position < args.length && existing[position] === args[position]) position++;
|
|
63
|
+
if (position === args.length) return -1;
|
|
64
|
+
}
|
|
65
|
+
return slot;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private place(index: number) {
|
|
69
|
+
const mask = this.slots.length - 1;
|
|
70
|
+
let slot = this.hashes[index] & mask;
|
|
71
|
+
while (this.slots[slot] !== -1) slot = (slot + 1) & mask;
|
|
72
|
+
this.slots[slot] = index;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
push() {
|
|
76
|
+
this.scopes.push(this.quantifiers.length);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
pop(numScopes: number) {
|
|
80
|
+
const limit = this.scopes[this.scopes.length - numScopes];
|
|
81
|
+
const mask = this.slots.length - 1;
|
|
82
|
+
for (let index = this.quantifiers.length - 1; index >= limit; index--) {
|
|
83
|
+
let slot = this.hashes[index] & mask;
|
|
84
|
+
while (this.slots[slot] !== index) slot = (slot + 1) & mask;
|
|
85
|
+
this.slots[slot] = -1;
|
|
86
|
+
}
|
|
87
|
+
shrink(this.quantifiers, limit);
|
|
88
|
+
shrink(this.hashes, limit);
|
|
89
|
+
shrink(this.roots, limit);
|
|
90
|
+
shrink(this.scopes, this.scopes.length - numScopes);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Ported from Z3 (src/ast/rewriter/bool_rewriter.cpp), MIT license, see z3-license.txt. The
|
|
2
|
+
// literals of a flattened conjunction or disjunction, without duplicates. Like the expr_fast_mark1
|
|
3
|
+
// and expr_fast_mark2 of mk_nflat_and_core, it marks the literals and the negated atoms it holds,
|
|
4
|
+
// here with a stamp for each use, so it finds a complementary pair without creating each negation.
|
|
5
|
+
// Its manager owns the one instance that its rewriters share: a list is filled and read before any
|
|
6
|
+
// other starts, so like Z3's ptr_buffer it reuses one array.
|
|
7
|
+
import { shrink } from "./array";
|
|
8
|
+
import type { AstManager } from "./ast";
|
|
9
|
+
|
|
10
|
+
export class FlatLiterals {
|
|
11
|
+
readonly list: number[] = [];
|
|
12
|
+
private stamp = 0;
|
|
13
|
+
private literalStamps = new Int32Array(1024);
|
|
14
|
+
private negatedAtomStamps = new Int32Array(1024);
|
|
15
|
+
|
|
16
|
+
constructor(private manager: AstManager) {}
|
|
17
|
+
|
|
18
|
+
// Starts a new, empty list.
|
|
19
|
+
clear() {
|
|
20
|
+
shrink(this.list, 0);
|
|
21
|
+
this.stamp++;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Adds a literal, and returns whether its complement is already there. An expression's arguments
|
|
25
|
+
// are older than it, so their ids are smaller.
|
|
26
|
+
add(literal: number) {
|
|
27
|
+
const manager = this.manager;
|
|
28
|
+
if (literal >= this.literalStamps.length) {
|
|
29
|
+
const size = Math.max(2 * this.literalStamps.length, literal + 1);
|
|
30
|
+
const literalStamps = new Int32Array(size);
|
|
31
|
+
literalStamps.set(this.literalStamps);
|
|
32
|
+
this.literalStamps = literalStamps;
|
|
33
|
+
const negatedAtomStamps = new Int32Array(size);
|
|
34
|
+
negatedAtomStamps.set(this.negatedAtomStamps);
|
|
35
|
+
this.negatedAtomStamps = negatedAtomStamps;
|
|
36
|
+
}
|
|
37
|
+
if (this.literalStamps[literal] === this.stamp) return false;
|
|
38
|
+
const isNegated = manager.isNot(literal);
|
|
39
|
+
const atom = isNegated ? manager.getArg(literal, 0) : literal;
|
|
40
|
+
if (
|
|
41
|
+
isNegated
|
|
42
|
+
? this.literalStamps[atom] === this.stamp
|
|
43
|
+
: this.negatedAtomStamps[atom] === this.stamp
|
|
44
|
+
)
|
|
45
|
+
return true;
|
|
46
|
+
this.list.push(literal);
|
|
47
|
+
this.literalStamps[literal] = this.stamp;
|
|
48
|
+
if (isNegated) this.negatedAtomStamps[atom] = this.stamp;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|