1 /******************************************************************************
2 * Top contributors (to current version):
3 * Aina Niemetz, Mathias Preiner
5 * This file is part of the cvc5 project.
7 * Copyright (c) 2009-2021 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.
11 * ****************************************************************************
13 * A bit-blaster wrapper around BBSimple for proof logging.
15 #include "theory/bv/bitblast/proof_bitblaster.h"
17 #include <unordered_set>
19 #include "proof/conv_proof_generator.h"
20 #include "theory/theory_model.h"
26 BBProof::BBProof(TheoryState
* state
, ProofNodeManager
* pnm
, bool fineGrained
)
27 : d_bb(new NodeBitblaster(state
)),
29 d_tcontext(new TheoryLeafTermContext(theory::THEORY_BV
)),
30 d_tcpg(pnm
? new TConvProofGenerator(
33 /* ONCE to visit each term only once, post-order. FIXPOINT
34 * could lead to infinite loops due to terms being rewritten
35 * to terms that contain themselves */
37 /* STATIC to get the same ProofNode for a shared subterm. */
38 TConvCachePolicy::STATIC
,
39 "BBProof::TConvProofGenerator",
43 d_recordFineGrainedProofs(fineGrained
)
47 BBProof::~BBProof() {}
49 void BBProof::bbAtom(TNode node
)
51 std::vector
<TNode
> visit
;
52 visit
.push_back(node
);
53 std::unordered_set
<TNode
> visited
;
55 bool fpenabled
= isProofsEnabled() && d_recordFineGrainedProofs
;
57 NodeManager
* nm
= NodeManager::currentNM();
59 while (!visit
.empty())
61 TNode n
= visit
.back();
62 if (hasBBAtom(n
) || hasBBTerm(n
))
68 if (visited
.find(n
) == visited
.end())
71 if (!Theory::isLeafOf(n
, theory::THEORY_BV
))
73 visit
.insert(visit
.end(), n
.begin(), n
.end());
78 if (Theory::isLeafOf(n
, theory::THEORY_BV
) && !n
.isConst())
81 d_bb
->makeVariable(n
, bits
);
84 Node n_tobv
= nm
->mkNode(kind::BITVECTOR_BB_TERM
, bits
);
85 d_bbMap
.emplace(n
, n_tobv
);
86 d_tcpg
->addRewriteStep(n
,
88 PfRule::BV_BITBLAST_STEP
,
94 else if (n
.getType().isBitVector())
97 d_bb
->bbTerm(n
, bits
);
98 Kind kind
= n
.getKind();
101 Node n_tobv
= nm
->mkNode(kind::BITVECTOR_BB_TERM
, bits
);
102 d_bbMap
.emplace(n
, n_tobv
);
110 std::vector
<Node
> children_tobv
;
111 if (n
.getMetaKind() == kind::metakind::PARAMETERIZED
)
113 children_tobv
.push_back(n
.getOperator());
116 for (const auto& child
: n
)
118 children_tobv
.push_back(d_bbMap
.at(child
));
120 c_tobv
= nm
->mkNode(kind
, children_tobv
);
122 d_tcpg
->addRewriteStep(c_tobv
,
124 PfRule::BV_BITBLAST_STEP
,
126 {c_tobv
.eqNode(n_tobv
)},
135 Node n_tobv
= getStoredBBAtom(n
);
136 std::vector
<Node
> children_tobv
;
137 for (const auto& child
: n
)
139 children_tobv
.push_back(d_bbMap
.at(child
));
141 Node c_tobv
= nm
->mkNode(n
.getKind(), children_tobv
);
142 d_tcpg
->addRewriteStep(c_tobv
,
144 PfRule::BV_BITBLAST_STEP
,
146 {c_tobv
.eqNode(n_tobv
)},
153 /* Record coarse-grain bit-blast proof step. */
154 if (isProofsEnabled() && !d_recordFineGrainedProofs
)
156 Node node_tobv
= getStoredBBAtom(node
);
157 d_tcpg
->addRewriteStep(node
,
161 {node
.eqNode(node_tobv
)},
166 bool BBProof::hasBBAtom(TNode atom
) const { return d_bb
->hasBBAtom(atom
); }
168 bool BBProof::hasBBTerm(TNode atom
) const { return d_bb
->hasBBTerm(atom
); }
170 Node
BBProof::getStoredBBAtom(TNode node
)
172 return d_bb
->getStoredBBAtom(node
);
175 bool BBProof::collectModelValues(TheoryModel
* m
,
176 const std::set
<Node
>& relevantTerms
)
178 return d_bb
->collectModelValues(m
, relevantTerms
);
181 TConvProofGenerator
* BBProof::getProofGenerator() { return d_tcpg
.get(); }
183 bool BBProof::isProofsEnabled() const { return d_pnm
!= nullptr; }
186 } // namespace theory