GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/unsat_core_manager.cpp Lines: 41 44 93.2 %
Date: 2021-05-21 Branches: 60 164 36.6 %

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 "expr/proof_node_algorithm.h"
19
#include "smt/assertions.h"
20
21
namespace cvc5 {
22
namespace smt {
23
24
1008
void UnsatCoreManager::getUnsatCore(std::shared_ptr<ProofNode> pfn,
25
                                    Assertions& as,
26
                                    std::vector<Node>& core)
27
{
28
2016
  Trace("unsat-core") << "UCManager::getUnsatCore: final proof: " << *pfn.get()
29
1008
                      << "\n";
30
1008
  Assert(pfn->getRule() == PfRule::SCOPE);
31
2016
  std::vector<Node> fassumps;
32
1008
  expr::getFreeAssumptions(pfn->getChildren()[0].get(), fassumps);
33
2016
  Trace("unsat-core") << "UCManager::getUnsatCore: free assumptions: "
34
1008
                      << fassumps << "\n";
35
1008
  context::CDList<Node>* al = as.getAssertionList();
36
1008
  Assert(al != nullptr);
37
16894
  for (context::CDList<Node>::const_iterator i = al->begin(); i != al->end();
38
       ++i)
39
  {
40
15886
    Trace("unsat-core") << "is assertion " << *i << " there?\n";
41
15886
    if (std::find(fassumps.begin(), fassumps.end(), *i) != fassumps.end())
42
    {
43
4762
      Trace("unsat-core") << "\tyes\n";
44
4762
      core.push_back(*i);
45
    }
46
  }
47
1008
  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
1008
}
56
57
6
void UnsatCoreManager::getRelevantInstantiations(
58
    std::shared_ptr<ProofNode> pfn,
59
    std::map<Node, std::vector<std::vector<Node>>>& insts)
60
{
61
12
  std::unordered_map<ProofNode*, bool> visited;
62
6
  std::unordered_map<ProofNode*, bool>::iterator it;
63
12
  std::vector<std::shared_ptr<ProofNode>> visit;
64
65
12
  std::shared_ptr<ProofNode> cur;
66
6
  visit.push_back(pfn);
67
290
  do
68
  {
69
296
    cur = visit.back();
70
296
    visit.pop_back();
71
296
    it = visited.find(cur.get());
72
296
    if (it != visited.end())
73
    {
74
38
      continue;
75
    }
76
258
    visited[cur.get()] = true;
77
258
    const std::vector<std::shared_ptr<ProofNode>>& cs = cur->getChildren();
78
258
    if (cur->getRule() == PfRule::INSTANTIATE)
79
    {
80
15
      const std::vector<Node>& instTerms = cur->getArguments();
81
15
      Assert(cs.size() == 1);
82
30
      Node q = cs[0]->getResult();
83
15
      insts[q].push_back({instTerms.begin(), instTerms.end()});
84
    }
85
548
    for (const std::shared_ptr<ProofNode>& cp : cs)
86
    {
87
290
      visit.push_back(cp);
88
    }
89
296
  } while (!visit.empty());
90
6
}
91
92
}  // namespace smt
93
27735
}  // namespace cvc5