GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/unsat_core_manager.cpp Lines: 48 57 84.2 %
Date: 2021-09-17 Branches: 71 198 35.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 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
1432
void UnsatCoreManager::getUnsatCore(std::shared_ptr<ProofNode> pfn,
25
                                    Assertions& as,
26
                                    std::vector<Node>& core)
27
{
28
2864
  Trace("unsat-core") << "UCManager::getUnsatCore: final proof: " << *pfn.get()
29
1432
                      << "\n";
30
1432
  Assert(pfn->getRule() == PfRule::SCOPE);
31
2864
  std::vector<Node> fassumps;
32
1432
  expr::getFreeAssumptions(pfn->getChildren()[0].get(), fassumps);
33
2864
  Trace("unsat-core") << "UCManager::getUnsatCore: free assumptions: "
34
1432
                      << fassumps << "\n";
35
1432
  context::CDList<Node>* al = as.getAssertionList();
36
1432
  Assert(al != nullptr);
37
19755
  for (context::CDList<Node>::const_iterator i = al->begin(); i != al->end();
38
       ++i)
39
  {
40
18323
    Trace("unsat-core") << "is assertion " << *i << " there?\n";
41
18323
    if (std::find(fassumps.begin(), fassumps.end(), *i) != fassumps.end())
42
    {
43
6093
      Trace("unsat-core") << "\tyes\n";
44
6093
      core.push_back(*i);
45
    }
46
  }
47
1432
  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
1432
}
56
57
7
void UnsatCoreManager::getRelevantInstantiations(
58
    std::shared_ptr<ProofNode> pfn,
59
    std::map<Node, InstantiationList>& insts,
60
    bool getDebugInfo)
61
{
62
14
  std::unordered_map<ProofNode*, bool> visited;
63
7
  std::unordered_map<ProofNode*, bool>::iterator it;
64
14
  std::vector<std::shared_ptr<ProofNode>> visit;
65
7
  std::map<Node, InstantiationList>::iterator itq;
66
14
  std::shared_ptr<ProofNode> cur;
67
7
  visit.push_back(pfn);
68
317
  do
69
  {
70
324
    cur = visit.back();
71
324
    visit.pop_back();
72
324
    it = visited.find(cur.get());
73
324
    if (it != visited.end())
74
    {
75
38
      continue;
76
    }
77
286
    visited[cur.get()] = true;
78
286
    const std::vector<std::shared_ptr<ProofNode>>& cs = cur->getChildren();
79
286
    if (cur->getRule() == PfRule::INSTANTIATE)
80
    {
81
17
      const std::vector<Node>& instTerms = cur->getArguments();
82
17
      Assert(cs.size() == 1);
83
34
      Node q = cs[0]->getResult();
84
      // the instantiation is a prefix of the arguments up to the number of
85
      // variables
86
17
      itq = insts.find(q);
87
17
      if (itq == insts.end())
88
      {
89
11
        insts[q].initialize(q);
90
11
        itq = insts.find(q);
91
      }
92
68
      itq->second.d_inst.push_back(InstantiationVec(
93
51
          {instTerms.begin(), instTerms.begin() + q[0].getNumChildren()}));
94
17
      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
603
    for (const std::shared_ptr<ProofNode>& cp : cs)
109
    {
110
317
      visit.push_back(cp);
111
    }
112
324
  } while (!visit.empty());
113
7
}
114
115
}  // namespace smt
116
29577
}  // namespace cvc5