GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/proof_manager.cpp Lines: 67 87 77.0 %
Date: 2021-05-21 Branches: 100 328 30.5 %

Line Exec Source
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 "expr/proof_checker.h"
19
#include "expr/proof_node_algorithm.h"
20
#include "expr/proof_node_manager.h"
21
#include "options/base_options.h"
22
#include "options/proof_options.h"
23
#include "options/smt_options.h"
24
#include "proof/dot/dot_printer.h"
25
#include "smt/assertions.h"
26
#include "smt/preprocess_proof_generator.h"
27
#include "smt/proof_post_processor.h"
28
29
namespace cvc5 {
30
namespace smt {
31
32
3117
PfManager::PfManager(context::UserContext* u, SmtEngine* smte)
33
6234
    : d_pchecker(new ProofChecker(options::proofPedantic())),
34
3117
      d_pnm(new ProofNodeManager(d_pchecker.get())),
35
      d_pppg(new PreprocessProofGenerator(
36
6234
          d_pnm.get(), u, "smt::PreprocessProofGenerator")),
37
      d_pfpp(new ProofPostproccess(
38
3117
          d_pnm.get(),
39
          smte,
40
3117
          d_pppg.get(),
41
          // by default the post-processor will update all assumptions, which
42
          // can lead to SCOPE subproofs of the form
43
          //   A
44
          //  ...
45
          //   B1    B2
46
          //  ...   ...
47
          // ------------
48
          //      C
49
          // ------------- SCOPE [B1, B2]
50
          // B1 ^ B2 => C
51
          //
52
          // where A is an available assumption from outside the scope (note
53
          // that B1 was an assumption of this SCOPE subproof but since it could
54
          // be inferred from A, it was updated). This shape is problematic for
55
          // the veriT reconstruction, so we disable the update of scoped
56
          // assumptions (which would disable the update of B1 in this case).
57
6235
          options::proofFormatMode() != options::ProofFormatMode::VERIT)),
58
18702
      d_finalProof(nullptr)
59
{
60
  // add rules to eliminate here
61
12386
  if (options::proofGranularityMode() != options::ProofGranularityMode::OFF)
62
  {
63
1139
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_EQ_INTRO);
64
1139
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_INTRO);
65
1139
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_ELIM);
66
1139
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_TRANSFORM);
67
1139
    d_pfpp->setEliminateRule(PfRule::MACRO_RESOLUTION_TRUST);
68
1139
    d_pfpp->setEliminateRule(PfRule::MACRO_RESOLUTION);
69
2278
    if (options::proofGranularityMode()
70
1139
        != options::ProofGranularityMode::REWRITE)
71
    {
72
1139
      d_pfpp->setEliminateRule(PfRule::SUBS);
73
1139
      d_pfpp->setEliminateRule(PfRule::REWRITE);
74
2278
      if (options::proofGranularityMode()
75
1139
          != options::ProofGranularityMode::THEORY_REWRITE)
76
      {
77
        // this eliminates theory rewriting steps with finer-grained DSL rules
78
        d_pfpp->setEliminateRule(PfRule::THEORY_REWRITE);
79
      }
80
    }
81
  }
82
3117
  d_false = NodeManager::currentNM()->mkConst(false);
83
3117
}
84
85
3117
PfManager::~PfManager() {}
86
87
2340
void PfManager::setFinalProof(std::shared_ptr<ProofNode> pfn, Assertions& as)
88
{
89
  // Note this assumes that setFinalProof is only called once per unsat
90
  // response. This method would need to cache its result otherwise.
91
2340
  Trace("smt-proof") << "SmtEngine::setFinalProof(): get proof body...\n";
92
93
2340
  if (Trace.isOn("smt-proof-debug"))
94
  {
95
    Trace("smt-proof-debug")
96
        << "SmtEngine::setFinalProof(): Proof node for false:\n";
97
    Trace("smt-proof-debug") << *pfn.get() << std::endl;
98
    Trace("smt-proof-debug") << "=====" << std::endl;
99
  }
100
101
4680
  std::vector<Node> assertions;
102
2340
  getAssertions(as, assertions);
103
104
2340
  if (Trace.isOn("smt-proof"))
105
  {
106
    Trace("smt-proof") << "SmtEngine::setFinalProof(): get free assumptions..."
107
                       << std::endl;
108
    std::vector<Node> fassumps;
109
    expr::getFreeAssumptions(pfn.get(), fassumps);
110
    Trace("smt-proof")
111
        << "SmtEngine::setFinalProof(): initial free assumptions are:\n";
112
    for (const Node& a : fassumps)
113
    {
114
      Trace("smt-proof") << "- " << a << std::endl;
115
    }
116
117
    Trace("smt-proof") << "SmtEngine::setFinalProof(): assertions are:\n";
118
    for (const Node& n : assertions)
119
    {
120
      Trace("smt-proof") << "- " << n << std::endl;
121
    }
122
    Trace("smt-proof") << "=====" << std::endl;
123
  }
124
125
2340
  Trace("smt-proof") << "SmtEngine::setFinalProof(): postprocess...\n";
126
2340
  Assert(d_pfpp != nullptr);
127
2340
  d_pfpp->process(pfn);
128
129
2340
  Trace("smt-proof") << "SmtEngine::setFinalProof(): make scope...\n";
130
131
  // Now make the final scope, which ensures that the only open leaves of the
132
  // proof are the assertions, unless we are doing proofs to generate unsat
133
  // cores, in which case we do not care.
134
2340
  d_finalProof = d_pnm->mkScope(pfn, assertions, !options::unsatCores());
135
2340
  Trace("smt-proof") << "SmtEngine::setFinalProof(): finished.\n";
136
2340
}
137
138
1
void PfManager::printProof(std::ostream& out,
139
                           std::shared_ptr<ProofNode> pfn,
140
                           Assertions& as)
141
{
142
1
  Trace("smt-proof") << "PfManager::printProof: start" << std::endl;
143
2
  std::shared_ptr<ProofNode> fp = getFinalProof(pfn, as);
144
  // if we are in incremental mode, we don't want to invalidate the proof
145
  // nodes in fp, since these may be reused in further check-sat calls
146
2
  if (options::incrementalSolving()
147
1
      && options::proofFormatMode() != options::ProofFormatMode::NONE)
148
  {
149
    fp = d_pnm->clone(fp);
150
  }
151
  // TODO (proj #37) according to the proof format, post process the proof node
152
  // TODO (proj #37) according to the proof format, print the proof node
153
154
1
  if (options::proofFormatMode() == options::ProofFormatMode::DOT)
155
  {
156
    proof::DotPrinter::print(out, fp.get());
157
  }
158
  else
159
  {
160
1
    out << "(proof\n";
161
1
    out << *fp;
162
1
    out << "\n)\n";
163
  }
164
1
}
165
1325
void PfManager::checkProof(std::shared_ptr<ProofNode> pfn, Assertions& as)
166
{
167
1325
  Trace("smt-proof") << "PfManager::checkProof: start" << std::endl;
168
2650
  std::shared_ptr<ProofNode> fp = getFinalProof(pfn, as);
169
2650
  Trace("smt-proof-debug") << "PfManager::checkProof: returned " << *fp.get()
170
1325
                           << std::endl;
171
1325
}
172
173
ProofChecker* PfManager::getProofChecker() const { return d_pchecker.get(); }
174
175
3117
ProofNodeManager* PfManager::getProofNodeManager() const { return d_pnm.get(); }
176
177
3117
smt::PreprocessProofGenerator* PfManager::getPreprocessProofGenerator() const
178
{
179
3117
  return d_pppg.get();
180
}
181
182
2340
std::shared_ptr<ProofNode> PfManager::getFinalProof(
183
    std::shared_ptr<ProofNode> pfn, Assertions& as)
184
{
185
2340
  setFinalProof(pfn, as);
186
2340
  Assert(d_finalProof);
187
2340
  return d_finalProof;
188
}
189
190
2340
void PfManager::getAssertions(Assertions& as,
191
                              std::vector<Node>& assertions)
192
{
193
2340
  context::CDList<Node>* al = as.getAssertionList();
194
2340
  Assert(al != nullptr);
195
35143
  for (context::CDList<Node>::const_iterator i = al->begin(); i != al->end();
196
       ++i)
197
  {
198
32803
    assertions.push_back(*i);
199
  }
200
2340
}
201
202
}  // namespace smt
203
43239
}  // namespace cvc5