1 /********************* */
2 /*! \file bv_solver_simple.cpp
4 ** Top contributors (to current version):
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
8 ** in the top-level source directory and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief Simple bit-blast solver
14 ** Simple bit-blast solver that sends bitblast lemmas directly to MiniSat.
17 #include "theory/bv/bv_solver_simple.h"
19 #include "theory/bv/theory_bv.h"
20 #include "theory/bv/theory_bv_utils.h"
21 #include "theory/theory_model.h"
27 /* -------------------------------------------------------------------------- */
31 bool isBVAtom(TNode n
)
33 return (n
.getKind() == kind::EQUAL
&& n
[0].getType().isBitVector())
34 || n
.getKind() == kind::BITVECTOR_ULT
35 || n
.getKind() == kind::BITVECTOR_ULE
36 || n
.getKind() == kind::BITVECTOR_SLT
37 || n
.getKind() == kind::BITVECTOR_SLE
;
40 /* Traverse Boolean nodes and collect BV atoms. */
41 void collectBVAtoms(TNode n
, std::unordered_set
<Node
, NodeHashFunction
>& atoms
)
43 std::vector
<TNode
> visit
;
44 std::unordered_set
<TNode
, TNodeHashFunction
> visited
;
50 TNode cur
= visit
.back();
53 if (visited
.find(cur
) != visited
.end() || !cur
.getType().isBoolean())
63 visit
.insert(visit
.end(), cur
.begin(), cur
.end());
64 } while (!visit
.empty());
69 BVSolverSimple::BVSolverSimple(TheoryState
* s
,
70 TheoryInferenceManager
& inferMgr
,
71 ProofNodeManager
* pnm
)
72 : BVSolver(*s
, inferMgr
),
73 d_bitblaster(new BBSimple(s
)),
74 d_epg(pnm
? new EagerProofGenerator(pnm
, s
->getUserContext(), "")
79 d_bvProofChecker
.registerTo(pnm
->getChecker());
83 void BVSolverSimple::addBBLemma(TNode fact
)
85 if (!d_bitblaster
->hasBBAtom(fact
))
87 d_bitblaster
->bbAtom(fact
);
89 NodeManager
* nm
= NodeManager::currentNM();
91 Node atom_bb
= d_bitblaster
->getStoredBBAtom(fact
);
92 Node lemma
= nm
->mkNode(kind::EQUAL
, fact
, atom_bb
);
96 d_im
.lemma(lemma
, InferenceId::UNKNOWN
);
100 TrustNode tlem
= d_epg
->mkTrustNode(lemma
, PfRule::BV_BITBLAST
, {}, {fact
});
101 d_im
.trustedLemma(tlem
, InferenceId::UNKNOWN
);
105 bool BVSolverSimple::preNotifyFact(
106 TNode atom
, bool pol
, TNode fact
, bool isPrereg
, bool isInternal
)
108 if (fact
.getKind() == kind::NOT
)
117 else if (fact
.getKind() == kind::BITVECTOR_EAGER_ATOM
)
121 NodeManager
* nm
= NodeManager::currentNM();
122 Node lemma
= nm
->mkNode(kind::EQUAL
, fact
, n
);
124 if (d_epg
== nullptr)
126 d_im
.lemma(lemma
, InferenceId::UNKNOWN
);
131 d_epg
->mkTrustNode(lemma
, PfRule::BV_EAGER_ATOM
, {}, {fact
});
132 d_im
.trustedLemma(tlem
, InferenceId::UNKNOWN
);
135 std::unordered_set
<Node
, NodeHashFunction
> bv_atoms
;
136 collectBVAtoms(n
, bv_atoms
);
137 for (const Node
& nn
: bv_atoms
)
146 bool BVSolverSimple::collectModelValues(TheoryModel
* m
,
147 const std::set
<Node
>& termSet
)
149 return d_bitblaster
->collectModelValues(m
, termSet
);
153 } // namespace theory