GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/proof_manager.cpp Lines: 68 88 77.3 %
Date: 2021-05-22 Branches: 101 330 30.6 %

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
3600
PfManager::PfManager(context::UserContext* u, SmtEngine* smte)
33
7200
    : d_pchecker(new ProofChecker(options::proofPedantic())),
34
3600
      d_pnm(new ProofNodeManager(d_pchecker.get())),
35
      d_pppg(new PreprocessProofGenerator(
36
7200
          d_pnm.get(), u, "smt::PreprocessProofGenerator")),
37
      d_pfpp(new ProofPostproccess(
38
3600
          d_pnm.get(),
39
          smte,
40
3600
          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
7201
          options::proofFormatMode() != options::ProofFormatMode::VERIT)),
58
21600
      d_finalProof(nullptr)
59
{
60
  // add rules to eliminate here
61
14334
  if (options::proofGranularityMode() != options::ProofGranularityMode::OFF)
62
  {
63
1124
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_EQ_INTRO);
64
1124
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_INTRO);
65
1124
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_ELIM);
66
1124
    d_pfpp->setEliminateRule(PfRule::MACRO_SR_PRED_TRANSFORM);
67
1124
    d_pfpp->setEliminateRule(PfRule::MACRO_RESOLUTION_TRUST);
68
1124
    d_pfpp->setEliminateRule(PfRule::MACRO_RESOLUTION);
69
1124
    d_pfpp->setEliminateRule(PfRule::MACRO_ARITH_SCALE_SUM_UB);
70
2248
    if (options::proofGranularityMode()
71
1124
        != options::ProofGranularityMode::REWRITE)
72
    {
73
1124
      d_pfpp->setEliminateRule(PfRule::SUBS);
74
1124
      d_pfpp->setEliminateRule(PfRule::REWRITE);
75
2248
      if (options::proofGranularityMode()
76
1124
          != options::ProofGranularityMode::THEORY_REWRITE)
77
      {
78
        // this eliminates theory rewriting steps with finer-grained DSL rules
79
        d_pfpp->setEliminateRule(PfRule::THEORY_REWRITE);
80
      }
81
    }
82
  }
83
3600
  d_false = NodeManager::currentNM()->mkConst(false);
84
3600
}
85
86
3600
PfManager::~PfManager() {}
87
88
2690
void PfManager::setFinalProof(std::shared_ptr<ProofNode> pfn, Assertions& as)
89
{
90
  // Note this assumes that setFinalProof is only called once per unsat
91
  // response. This method would need to cache its result otherwise.
92
2690
  Trace("smt-proof") << "SmtEngine::setFinalProof(): get proof body...\n";
93
94
2690
  if (Trace.isOn("smt-proof-debug"))
95
  {
96
    Trace("smt-proof-debug")
97
        << "SmtEngine::setFinalProof(): Proof node for false:\n";
98
    Trace("smt-proof-debug") << *pfn.get() << std::endl;
99
    Trace("smt-proof-debug") << "=====" << std::endl;
100
  }
101
102
5380
  std::vector<Node> assertions;
103
2690
  getAssertions(as, assertions);
104
105
2690
  if (Trace.isOn("smt-proof"))
106
  {
107
    Trace("smt-proof") << "SmtEngine::setFinalProof(): get free assumptions..."
108
                       << std::endl;
109
    std::vector<Node> fassumps;
110
    expr::getFreeAssumptions(pfn.get(), fassumps);
111
    Trace("smt-proof")
112
        << "SmtEngine::setFinalProof(): initial free assumptions are:\n";
113
    for (const Node& a : fassumps)
114
    {
115
      Trace("smt-proof") << "- " << a << std::endl;
116
    }
117
118
    Trace("smt-proof") << "SmtEngine::setFinalProof(): assertions are:\n";
119
    for (const Node& n : assertions)
120
    {
121
      Trace("smt-proof") << "- " << n << std::endl;
122
    }
123
    Trace("smt-proof") << "=====" << std::endl;
124
  }
125
126
2690
  Trace("smt-proof") << "SmtEngine::setFinalProof(): postprocess...\n";
127
2690
  Assert(d_pfpp != nullptr);
128
2690
  d_pfpp->process(pfn);
129
130
2690
  Trace("smt-proof") << "SmtEngine::setFinalProof(): make scope...\n";
131
132
  // Now make the final scope, which ensures that the only open leaves of the
133
  // proof are the assertions, unless we are doing proofs to generate unsat
134
  // cores, in which case we do not care.
135
2690
  d_finalProof = d_pnm->mkScope(pfn, assertions, !options::unsatCores());
136
2690
  Trace("smt-proof") << "SmtEngine::setFinalProof(): finished.\n";
137
2690
}
138
139
1
void PfManager::printProof(std::ostream& out,
140
                           std::shared_ptr<ProofNode> pfn,
141
                           Assertions& as)
142
{
143
1
  Trace("smt-proof") << "PfManager::printProof: start" << std::endl;
144
2
  std::shared_ptr<ProofNode> fp = getFinalProof(pfn, as);
145
  // if we are in incremental mode, we don't want to invalidate the proof
146
  // nodes in fp, since these may be reused in further check-sat calls
147
2
  if (options::incrementalSolving()
148
1
      && options::proofFormatMode() != options::ProofFormatMode::NONE)
149
  {
150
    fp = d_pnm->clone(fp);
151
  }
152
  // TODO (proj #37) according to the proof format, post process the proof node
153
  // TODO (proj #37) according to the proof format, print the proof node
154
155
1
  if (options::proofFormatMode() == options::ProofFormatMode::DOT)
156
  {
157
    proof::DotPrinter::print(out, fp.get());
158
  }
159
  else
160
  {
161
1
    out << "(proof\n";
162
1
    out << *fp;
163
1
    out << "\n)\n";
164
  }
165
1
}
166
1318
void PfManager::checkProof(std::shared_ptr<ProofNode> pfn, Assertions& as)
167
{
168
1318
  Trace("smt-proof") << "PfManager::checkProof: start" << std::endl;
169
2636
  std::shared_ptr<ProofNode> fp = getFinalProof(pfn, as);
170
2636
  Trace("smt-proof-debug") << "PfManager::checkProof: returned " << *fp.get()
171
1318
                           << std::endl;
172
1318
}
173
174
ProofChecker* PfManager::getProofChecker() const { return d_pchecker.get(); }
175
176
3600
ProofNodeManager* PfManager::getProofNodeManager() const { return d_pnm.get(); }
177
178
3600
smt::PreprocessProofGenerator* PfManager::getPreprocessProofGenerator() const
179
{
180
3600
  return d_pppg.get();
181
}
182
183
2690
std::shared_ptr<ProofNode> PfManager::getFinalProof(
184
    std::shared_ptr<ProofNode> pfn, Assertions& as)
185
{
186
2690
  setFinalProof(pfn, as);
187
2690
  Assert(d_finalProof);
188
2690
  return d_finalProof;
189
}
190
191
2690
void PfManager::getAssertions(Assertions& as,
192
                              std::vector<Node>& assertions)
193
{
194
2690
  context::CDList<Node>* al = as.getAssertionList();
195
2690
  Assert(al != nullptr);
196
37913
  for (context::CDList<Node>::const_iterator i = al->begin(); i != al->end();
197
       ++i)
198
  {
199
35223
    assertions.push_back(*i);
200
  }
201
2690
}
202
203
}  // namespace smt
204
46126
}  // namespace cvc5