GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/unsat_core_manager.cpp Lines: 47 57 82.5 %
Date: 2021-09-29 Branches: 69 198 34.8 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Haniel Barbosa
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
 * Implementation of the unsat core manager of SmtEngine.
14
 */
15
16
#include "unsat_core_manager.h"
17
18
#include "proof/proof_node_algorithm.h"
19
#include "smt/assertions.h"
20
21
namespace cvc5 {
22
namespace smt {
23
24
63
void UnsatCoreManager::getUnsatCore(std::shared_ptr<ProofNode> pfn,
25
                                    Assertions& as,
26
                                    std::vector<Node>& core)
27
{
28
126
  Trace("unsat-core") << "UCManager::getUnsatCore: final proof: " << *pfn.get()
29
63
                      << "\n";
30
63
  Assert(pfn->getRule() == PfRule::SCOPE);
31
126
  std::vector<Node> fassumps;
32
63
  expr::getFreeAssumptions(pfn->getChildren()[0].get(), fassumps);
33
126
  Trace("unsat-core") << "UCManager::getUnsatCore: free assumptions: "
34
63
                      << fassumps << "\n";
35
63
  context::CDList<Node>* al = as.getAssertionList();
36
63
  Assert(al != nullptr);
37
1244
  for (context::CDList<Node>::const_iterator i = al->begin(); i != al->end();
38
       ++i)
39
  {
40
1181
    Trace("unsat-core") << "is assertion " << *i << " there?\n";
41
1181
    if (std::find(fassumps.begin(), fassumps.end(), *i) != fassumps.end())
42
    {
43
190
      Trace("unsat-core") << "\tyes\n";
44
190
      core.push_back(*i);
45
    }
46
  }
47
63
  if (Trace.isOn("unsat-core"))
48
  {
49
    Trace("unsat-core") << "UCManager::getUnsatCore():\n";
50
    for (const Node& n : core)
51
    {
52
      Trace("unsat-core") << "- " << n << "\n";
53
    }
54
  }
55
63
}
56
57
1
void UnsatCoreManager::getRelevantInstantiations(
58
    std::shared_ptr<ProofNode> pfn,
59
    std::map<Node, InstantiationList>& insts,
60
    bool getDebugInfo)
61
{
62
2
  std::unordered_map<ProofNode*, bool> visited;
63
1
  std::unordered_map<ProofNode*, bool>::iterator it;
64
2
  std::vector<std::shared_ptr<ProofNode>> visit;
65
1
  std::map<Node, InstantiationList>::iterator itq;
66
2
  std::shared_ptr<ProofNode> cur;
67
1
  visit.push_back(pfn);
68
21
  do
69
  {
70
22
    cur = visit.back();
71
22
    visit.pop_back();
72
22
    it = visited.find(cur.get());
73
22
    if (it != visited.end())
74
    {
75
      continue;
76
    }
77
22
    visited[cur.get()] = true;
78
22
    const std::vector<std::shared_ptr<ProofNode>>& cs = cur->getChildren();
79
22
    if (cur->getRule() == PfRule::INSTANTIATE)
80
    {
81
2
      const std::vector<Node>& instTerms = cur->getArguments();
82
2
      Assert(cs.size() == 1);
83
4
      Node q = cs[0]->getResult();
84
      // the instantiation is a prefix of the arguments up to the number of
85
      // variables
86
2
      itq = insts.find(q);
87
2
      if (itq == insts.end())
88
      {
89
2
        insts[q].initialize(q);
90
2
        itq = insts.find(q);
91
      }
92
8
      itq->second.d_inst.push_back(InstantiationVec(
93
6
          {instTerms.begin(), instTerms.begin() + q[0].getNumChildren()}));
94
2
      if (getDebugInfo)
95
      {
96
        std::vector<Node> extraArgs(instTerms.begin() + q[0].getNumChildren(),
97
                                    instTerms.end());
98
        if (extraArgs.size() >= 1)
99
        {
100
          getInferenceId(extraArgs[0], itq->second.d_inst.back().d_id);
101
        }
102
        if (extraArgs.size() >= 2)
103
        {
104
          itq->second.d_inst.back().d_pfArg = extraArgs[1];
105
        }
106
      }
107
    }
108
43
    for (const std::shared_ptr<ProofNode>& cp : cs)
109
    {
110
21
      visit.push_back(cp);
111
    }
112
22
  } while (!visit.empty());
113
1
}
114
115
}  // namespace smt
116
22746
}  // namespace cvc5