829d6f2f5f358480f4d110f0f767d0cdd57f182d
1 /******************************************************************************
2 * Top contributors (to current version):
3 * Andrew Reynolds, Haniel Barbosa, Diego Della Rocca de Camargos
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 * The proof manager of the SMT engine.
16 #include "smt/proof_manager.h"
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"
28 #include "smt/preprocess_proof_generator.h"
29 #include "smt/proof_post_processor.h"
34 PfManager::PfManager(Env
& env
, SmtEngine
* smte
)
36 d_pchecker(new ProofChecker(options::proofPedantic())),
37 d_pnm(new ProofNodeManager(d_pchecker
.get())),
38 d_pppg(new PreprocessProofGenerator(
39 d_pnm
.get(), env
.getUserContext(), "smt::PreprocessProofGenerator")),
40 d_pfpp(new ProofPostproccess(
44 // by default the post-processor will update all assumptions, which
45 // can lead to SCOPE subproofs of the form
52 // ------------- SCOPE [B1, B2]
55 // where A is an available assumption from outside the scope (note
56 // that B1 was an assumption of this SCOPE subproof but since it could
57 // be inferred from A, it was updated). This shape is problematic for
58 // the veriT reconstruction, so we disable the update of scoped
59 // assumptions (which would disable the update of B1 in this case).
60 options::proofFormatMode() != options::ProofFormatMode::VERIT
)),
63 // add rules to eliminate here
64 if (options::proofGranularityMode() != options::ProofGranularityMode::OFF
)
66 d_pfpp
->setEliminateRule(PfRule::MACRO_SR_EQ_INTRO
);
67 d_pfpp
->setEliminateRule(PfRule::MACRO_SR_PRED_INTRO
);
68 d_pfpp
->setEliminateRule(PfRule::MACRO_SR_PRED_ELIM
);
69 d_pfpp
->setEliminateRule(PfRule::MACRO_SR_PRED_TRANSFORM
);
70 d_pfpp
->setEliminateRule(PfRule::MACRO_RESOLUTION_TRUST
);
71 d_pfpp
->setEliminateRule(PfRule::MACRO_RESOLUTION
);
72 d_pfpp
->setEliminateRule(PfRule::MACRO_ARITH_SCALE_SUM_UB
);
73 if (options::proofGranularityMode()
74 != options::ProofGranularityMode::REWRITE
)
76 d_pfpp
->setEliminateRule(PfRule::SUBS
);
77 d_pfpp
->setEliminateRule(PfRule::REWRITE
);
78 if (options::proofGranularityMode()
79 != options::ProofGranularityMode::THEORY_REWRITE
)
81 // this eliminates theory rewriting steps with finer-grained DSL rules
82 d_pfpp
->setEliminateRule(PfRule::THEORY_REWRITE
);
85 d_pfpp
->setEliminateRule(PfRule::BV_BITBLAST
);
87 d_false
= NodeManager::currentNM()->mkConst(false);
90 PfManager::~PfManager() {}
92 void PfManager::setFinalProof(std::shared_ptr
<ProofNode
> pfn
, Assertions
& as
)
94 // Note this assumes that setFinalProof is only called once per unsat
95 // response. This method would need to cache its result otherwise.
96 Trace("smt-proof") << "SmtEngine::setFinalProof(): get proof body...\n";
98 if (Trace
.isOn("smt-proof-debug"))
100 Trace("smt-proof-debug")
101 << "SmtEngine::setFinalProof(): Proof node for false:\n";
102 Trace("smt-proof-debug") << *pfn
.get() << std::endl
;
103 Trace("smt-proof-debug") << "=====" << std::endl
;
106 std::vector
<Node
> assertions
;
107 getAssertions(as
, assertions
);
109 if (Trace
.isOn("smt-proof"))
111 Trace("smt-proof") << "SmtEngine::setFinalProof(): get free assumptions..."
113 std::vector
<Node
> fassumps
;
114 expr::getFreeAssumptions(pfn
.get(), fassumps
);
116 << "SmtEngine::setFinalProof(): initial free assumptions are:\n";
117 for (const Node
& a
: fassumps
)
119 Trace("smt-proof") << "- " << a
<< std::endl
;
122 Trace("smt-proof") << "SmtEngine::setFinalProof(): assertions are:\n";
123 for (const Node
& n
: assertions
)
125 Trace("smt-proof") << "- " << n
<< std::endl
;
127 Trace("smt-proof") << "=====" << std::endl
;
130 Trace("smt-proof") << "SmtEngine::setFinalProof(): postprocess...\n";
131 Assert(d_pfpp
!= nullptr);
132 d_pfpp
->process(pfn
);
134 Trace("smt-proof") << "SmtEngine::setFinalProof(): make scope...\n";
136 // Now make the final scope, which ensures that the only open leaves of the
137 // proof are the assertions.
138 d_finalProof
= d_pnm
->mkScope(pfn
, assertions
);
139 Trace("smt-proof") << "SmtEngine::setFinalProof(): finished.\n";
142 void PfManager::printProof(std::ostream
& out
,
143 std::shared_ptr
<ProofNode
> pfn
,
146 Trace("smt-proof") << "PfManager::printProof: start" << std::endl
;
147 std::shared_ptr
<ProofNode
> fp
= getFinalProof(pfn
, as
);
148 // if we are in incremental mode, we don't want to invalidate the proof
149 // nodes in fp, since these may be reused in further check-sat calls
150 if (options::incrementalSolving()
151 && options::proofFormatMode() != options::ProofFormatMode::NONE
)
153 fp
= d_pnm
->clone(fp
);
155 // TODO (proj #37) according to the proof format, post process the proof node
156 // TODO (proj #37) according to the proof format, print the proof node
158 if (options::proofFormatMode() == options::ProofFormatMode::DOT
)
160 proof::DotPrinter dotPrinter
;
161 dotPrinter
.print(out
, fp
.get());
163 else if (options::proofFormatMode() == options::ProofFormatMode::TPTP
)
165 out
<< "% SZS output start Proof for " << d_env
.getOptions().driver
.filename
<< std::endl
;
166 // TODO (proj #37) print in TPTP compliant format
167 out
<< *fp
<< std::endl
;
168 out
<< "% SZS output end Proof for " << d_env
.getOptions().driver
.filename
<< std::endl
;
177 void PfManager::checkProof(std::shared_ptr
<ProofNode
> pfn
, Assertions
& as
)
179 Trace("smt-proof") << "PfManager::checkProof: start" << std::endl
;
180 std::shared_ptr
<ProofNode
> fp
= getFinalProof(pfn
, as
);
181 Trace("smt-proof-debug") << "PfManager::checkProof: returned " << *fp
.get()
185 ProofChecker
* PfManager::getProofChecker() const { return d_pchecker
.get(); }
187 ProofNodeManager
* PfManager::getProofNodeManager() const { return d_pnm
.get(); }
189 smt::PreprocessProofGenerator
* PfManager::getPreprocessProofGenerator() const
194 std::shared_ptr
<ProofNode
> PfManager::getFinalProof(
195 std::shared_ptr
<ProofNode
> pfn
, Assertions
& as
)
197 setFinalProof(pfn
, as
);
198 Assert(d_finalProof
);
202 void PfManager::getAssertions(Assertions
& as
,
203 std::vector
<Node
>& assertions
)
205 context::CDList
<Node
>* al
= as
.getAssertionList();
206 Assert(al
!= nullptr);
207 for (context::CDList
<Node
>::const_iterator i
= al
->begin(); i
!= al
->end();
210 assertions
.push_back(*i
);