1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Haniel Barbosa, Diego Della Rocca de Camargos |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
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 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* The proof manager of the SMT engine. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "smt/proof_manager.h" |
17 |
|
|
18 |
|
#include "options/base_options.h" |
19 |
|
#include "options/main_options.h" |
20 |
|
#include "options/proof_options.h" |
21 |
|
#include "options/smt_options.h" |
22 |
|
#include "proof/dot/dot_printer.h" |
23 |
|
#include "proof/proof_checker.h" |
24 |
|
#include "proof/proof_node_algorithm.h" |
25 |
|
#include "proof/proof_node_manager.h" |
26 |
|
#include "smt/assertions.h" |
27 |
|
#include "smt/difficulty_post_processor.h" |
28 |
|
#include "smt/env.h" |
29 |
|
#include "smt/preprocess_proof_generator.h" |
30 |
|
#include "smt/proof_post_processor.h" |
31 |
|
|
32 |
|
namespace cvc5 { |
33 |
|
namespace smt { |
34 |
|
|
35 |
3794 |
PfManager::PfManager(Env& env) |
36 |
|
: EnvObj(env), |
37 |
|
d_pchecker(new ProofChecker( |
38 |
3794 |
options().proof.proofCheck == options::ProofCheckMode::EAGER, |
39 |
7588 |
options().proof.proofPedantic)), |
40 |
3794 |
d_pnm(new ProofNodeManager(d_pchecker.get())), |
41 |
|
d_pppg(new PreprocessProofGenerator( |
42 |
7588 |
d_pnm.get(), env.getUserContext(), "smt::PreprocessProofGenerator")), |
43 |
|
d_pfpp(nullptr), |
44 |
22764 |
d_finalProof(nullptr) |
45 |
|
{ |
46 |
|
// enable proof support in the environment/rewriter |
47 |
3794 |
d_env.setProofNodeManager(d_pnm.get()); |
48 |
|
// Now, initialize the proof postprocessor with the environment. |
49 |
|
// By default the post-processor will update all assumptions, which |
50 |
|
// can lead to SCOPE subproofs of the form |
51 |
|
// A |
52 |
|
// ... |
53 |
|
// B1 B2 |
54 |
|
// ... ... |
55 |
|
// ------------ |
56 |
|
// C |
57 |
|
// ------------- SCOPE [B1, B2] |
58 |
|
// B1 ^ B2 => C |
59 |
|
// |
60 |
|
// where A is an available assumption from outside the scope (note |
61 |
|
// that B1 was an assumption of this SCOPE subproof but since it could |
62 |
|
// be inferred from A, it was updated). This shape is problematic for |
63 |
|
// the veriT reconstruction, so we disable the update of scoped |
64 |
|
// assumptions (which would disable the update of B1 in this case). |
65 |
7588 |
d_pfpp.reset(new ProofPostproccess( |
66 |
|
env, |
67 |
3794 |
d_pppg.get(), |
68 |
|
nullptr, |
69 |
3794 |
options::proofFormatMode() != options::ProofFormatMode::VERIT)); |
70 |
|
|
71 |
|
// add rules to eliminate here |
72 |
3794 |
if (options::proofGranularityMode() != options::ProofGranularityMode::OFF) |
73 |
|
{ |
74 |
1188 |
d_pfpp->setEliminateRule(PfRule::MACRO_SR_EQ_INTRO); |
75 |
1188 |
d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_INTRO); |
76 |
1188 |
d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_ELIM); |
77 |
1188 |
d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_TRANSFORM); |
78 |
1188 |
d_pfpp->setEliminateRule(PfRule::MACRO_RESOLUTION_TRUST); |
79 |
1188 |
d_pfpp->setEliminateRule(PfRule::MACRO_RESOLUTION); |
80 |
1188 |
d_pfpp->setEliminateRule(PfRule::MACRO_ARITH_SCALE_SUM_UB); |
81 |
2376 |
if (options::proofGranularityMode() |
82 |
1188 |
!= options::ProofGranularityMode::REWRITE) |
83 |
|
{ |
84 |
1188 |
d_pfpp->setEliminateRule(PfRule::SUBS); |
85 |
1188 |
d_pfpp->setEliminateRule(PfRule::REWRITE); |
86 |
2376 |
if (options::proofGranularityMode() |
87 |
1188 |
!= options::ProofGranularityMode::THEORY_REWRITE) |
88 |
|
{ |
89 |
|
// this eliminates theory rewriting steps with finer-grained DSL rules |
90 |
|
d_pfpp->setEliminateRule(PfRule::THEORY_REWRITE); |
91 |
|
} |
92 |
|
} |
93 |
|
// theory-specific lazy proof reconstruction |
94 |
1188 |
d_pfpp->setEliminateRule(PfRule::STRING_INFERENCE); |
95 |
1188 |
d_pfpp->setEliminateRule(PfRule::BV_BITBLAST); |
96 |
|
} |
97 |
3794 |
d_false = NodeManager::currentNM()->mkConst(false); |
98 |
3794 |
} |
99 |
|
|
100 |
7588 |
PfManager::~PfManager() {} |
101 |
|
|
102 |
2819 |
void PfManager::setFinalProof(std::shared_ptr<ProofNode> pfn, Assertions& as) |
103 |
|
{ |
104 |
|
// Note this assumes that setFinalProof is only called once per unsat |
105 |
|
// response. This method would need to cache its result otherwise. |
106 |
2819 |
Trace("smt-proof") << "SmtEngine::setFinalProof(): get proof body...\n"; |
107 |
|
|
108 |
2819 |
if (Trace.isOn("smt-proof-debug")) |
109 |
|
{ |
110 |
|
Trace("smt-proof-debug") |
111 |
|
<< "SmtEngine::setFinalProof(): Proof node for false:\n"; |
112 |
|
Trace("smt-proof-debug") << *pfn.get() << std::endl; |
113 |
|
Trace("smt-proof-debug") << "=====" << std::endl; |
114 |
|
} |
115 |
|
|
116 |
5638 |
std::vector<Node> assertions; |
117 |
2819 |
getAssertions(as, assertions); |
118 |
|
|
119 |
2819 |
if (Trace.isOn("smt-proof")) |
120 |
|
{ |
121 |
|
Trace("smt-proof") << "SmtEngine::setFinalProof(): get free assumptions..." |
122 |
|
<< std::endl; |
123 |
|
std::vector<Node> fassumps; |
124 |
|
expr::getFreeAssumptions(pfn.get(), fassumps); |
125 |
|
Trace("smt-proof") |
126 |
|
<< "SmtEngine::setFinalProof(): initial free assumptions are:\n"; |
127 |
|
for (const Node& a : fassumps) |
128 |
|
{ |
129 |
|
Trace("smt-proof") << "- " << a << std::endl; |
130 |
|
} |
131 |
|
|
132 |
|
Trace("smt-proof") << "SmtEngine::setFinalProof(): assertions are:\n"; |
133 |
|
for (const Node& n : assertions) |
134 |
|
{ |
135 |
|
Trace("smt-proof") << "- " << n << std::endl; |
136 |
|
} |
137 |
|
Trace("smt-proof") << "=====" << std::endl; |
138 |
|
} |
139 |
|
|
140 |
2819 |
Trace("smt-proof") << "SmtEngine::setFinalProof(): postprocess...\n"; |
141 |
2819 |
Assert(d_pfpp != nullptr); |
142 |
2819 |
d_pfpp->process(pfn); |
143 |
|
|
144 |
2819 |
Trace("smt-proof") << "SmtEngine::setFinalProof(): make scope...\n"; |
145 |
|
|
146 |
|
// Now make the final scope, which ensures that the only open leaves of the |
147 |
|
// proof are the assertions. |
148 |
2819 |
d_finalProof = d_pnm->mkScope(pfn, assertions); |
149 |
2819 |
Trace("smt-proof") << "SmtEngine::setFinalProof(): finished.\n"; |
150 |
2819 |
} |
151 |
|
|
152 |
5 |
void PfManager::printProof(std::ostream& out, |
153 |
|
std::shared_ptr<ProofNode> pfn, |
154 |
|
Assertions& as) |
155 |
|
{ |
156 |
5 |
Trace("smt-proof") << "PfManager::printProof: start" << std::endl; |
157 |
10 |
std::shared_ptr<ProofNode> fp = getFinalProof(pfn, as); |
158 |
|
// if we are in incremental mode, we don't want to invalidate the proof |
159 |
|
// nodes in fp, since these may be reused in further check-sat calls |
160 |
10 |
if (options::incrementalSolving() |
161 |
5 |
&& options::proofFormatMode() != options::ProofFormatMode::NONE) |
162 |
|
{ |
163 |
|
fp = d_pnm->clone(fp); |
164 |
|
} |
165 |
|
// TODO (proj #37) according to the proof format, post process the proof node |
166 |
|
// TODO (proj #37) according to the proof format, print the proof node |
167 |
|
|
168 |
|
// according to the proof format, post process and print the proof node |
169 |
5 |
if (options::proofFormatMode() == options::ProofFormatMode::DOT) |
170 |
|
{ |
171 |
|
proof::DotPrinter dotPrinter; |
172 |
|
dotPrinter.print(out, fp.get()); |
173 |
|
} |
174 |
5 |
else if (options::proofFormatMode() == options::ProofFormatMode::TPTP) |
175 |
|
{ |
176 |
|
out << "% SZS output start Proof for " << options().driver.filename |
177 |
|
<< std::endl; |
178 |
|
// TODO (proj #37) print in TPTP compliant format |
179 |
|
out << *fp << std::endl; |
180 |
|
out << "% SZS output end Proof for " << options().driver.filename |
181 |
|
<< std::endl; |
182 |
|
} |
183 |
|
else |
184 |
|
{ |
185 |
|
// otherwise, print using default printer |
186 |
5 |
out << "(proof\n"; |
187 |
5 |
out << *fp; |
188 |
5 |
out << "\n)\n"; |
189 |
|
} |
190 |
5 |
} |
191 |
1376 |
void PfManager::checkProof(std::shared_ptr<ProofNode> pfn, Assertions& as) |
192 |
|
{ |
193 |
1376 |
Trace("smt-proof") << "PfManager::checkProof: start" << std::endl; |
194 |
2752 |
std::shared_ptr<ProofNode> fp = getFinalProof(pfn, as); |
195 |
2752 |
Trace("smt-proof-debug") << "PfManager::checkProof: returned " << *fp.get() |
196 |
1376 |
<< std::endl; |
197 |
1376 |
} |
198 |
|
|
199 |
4 |
void PfManager::translateDifficultyMap(std::map<Node, Node>& dmap, |
200 |
|
Assertions& as) |
201 |
|
{ |
202 |
4 |
Trace("difficulty") << "PfManager::translateDifficultyMap" << std::endl; |
203 |
4 |
if (dmap.empty()) |
204 |
|
{ |
205 |
4 |
return; |
206 |
|
} |
207 |
|
std::map<Node, Node> dmapp = dmap; |
208 |
|
dmap.clear(); |
209 |
|
std::vector<Node> ppAsserts; |
210 |
|
for (const std::pair<const Node, Node>& ppa : dmapp) |
211 |
|
{ |
212 |
|
Trace("difficulty") << " preprocess difficulty: " << ppa.second << " for " |
213 |
|
<< ppa.first << std::endl; |
214 |
|
ppAsserts.push_back(ppa.first); |
215 |
|
} |
216 |
|
// assume a SAT refutation from all input assertions that were marked |
217 |
|
// as having a difficulty |
218 |
|
CDProof cdp(d_pnm.get()); |
219 |
|
Node fnode = NodeManager::currentNM()->mkConst(false); |
220 |
|
cdp.addStep(fnode, PfRule::SAT_REFUTATION, ppAsserts, {}); |
221 |
|
std::shared_ptr<ProofNode> pf = cdp.getProofFor(fnode); |
222 |
|
std::shared_ptr<ProofNode> fpf = getFinalProof(pf, as); |
223 |
|
Trace("difficulty-debug") << "Final proof is " << *fpf.get() << std::endl; |
224 |
|
Assert(fpf->getRule() == PfRule::SCOPE); |
225 |
|
fpf = fpf->getChildren()[0]; |
226 |
|
// analyze proof |
227 |
|
Assert(fpf->getRule() == PfRule::SAT_REFUTATION); |
228 |
|
const std::vector<std::shared_ptr<ProofNode>>& children = fpf->getChildren(); |
229 |
|
DifficultyPostprocessCallback dpc; |
230 |
|
ProofNodeUpdater dpnu(d_pnm.get(), dpc); |
231 |
|
// For each child of SAT_REFUTATION, we increment the difficulty on all |
232 |
|
// "source" free assumptions (see DifficultyPostprocessCallback) by the |
233 |
|
// difficulty of the preprocessed assertion. |
234 |
|
for (const std::shared_ptr<ProofNode>& c : children) |
235 |
|
{ |
236 |
|
Node res = c->getResult(); |
237 |
|
Assert(dmapp.find(res) != dmapp.end()); |
238 |
|
Trace("difficulty-debug") << " process: " << res << std::endl; |
239 |
|
Trace("difficulty-debug") << " .dvalue: " << dmapp[res] << std::endl; |
240 |
|
Trace("difficulty-debug") << " ..proof: " << *c.get() << std::endl; |
241 |
|
if (!dpc.setCurrentDifficulty(dmapp[res])) |
242 |
|
{ |
243 |
|
continue; |
244 |
|
} |
245 |
|
dpnu.process(c); |
246 |
|
} |
247 |
|
// get the accumulated difficulty map from the callback |
248 |
|
dpc.getDifficultyMap(dmap); |
249 |
|
} |
250 |
|
|
251 |
|
ProofChecker* PfManager::getProofChecker() const { return d_pchecker.get(); } |
252 |
|
|
253 |
|
ProofNodeManager* PfManager::getProofNodeManager() const { return d_pnm.get(); } |
254 |
|
|
255 |
|
rewriter::RewriteDb* PfManager::getRewriteDatabase() const { return nullptr; } |
256 |
|
|
257 |
3794 |
smt::PreprocessProofGenerator* PfManager::getPreprocessProofGenerator() const |
258 |
|
{ |
259 |
3794 |
return d_pppg.get(); |
260 |
|
} |
261 |
|
|
262 |
2819 |
std::shared_ptr<ProofNode> PfManager::getFinalProof( |
263 |
|
std::shared_ptr<ProofNode> pfn, Assertions& as) |
264 |
|
{ |
265 |
2819 |
setFinalProof(pfn, as); |
266 |
2819 |
Assert(d_finalProof); |
267 |
2819 |
return d_finalProof; |
268 |
|
} |
269 |
|
|
270 |
2819 |
void PfManager::getAssertions(Assertions& as, |
271 |
|
std::vector<Node>& assertions) |
272 |
|
{ |
273 |
2819 |
context::CDList<Node>* al = as.getAssertionList(); |
274 |
2819 |
Assert(al != nullptr); |
275 |
37271 |
for (context::CDList<Node>::const_iterator i = al->begin(); i != al->end(); |
276 |
|
++i) |
277 |
|
{ |
278 |
34452 |
assertions.push_back(*i); |
279 |
|
} |
280 |
2819 |
} |
281 |
|
|
282 |
|
} // namespace smt |
283 |
29589 |
} // namespace cvc5 |