GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/unsat_core_manager.cpp Lines: 47 56 83.9 %
Date: 2021-11-07 Branches: 69 182 37.9 %

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