GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/inference_manager.cpp Lines: 48 65 73.8 %
Date: 2021-05-24 Branches: 48 146 32.9 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Gereon Kremer, Makai Mann, Mathias Preiner
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 inference manager for the theory of strings.
14
 */
15
16
#include "theory/arith/inference_manager.h"
17
18
#include "options/arith_options.h"
19
#include "theory/arith/arith_state.h"
20
#include "theory/arith/theory_arith.h"
21
#include "theory/rewriter.h"
22
23
namespace cvc5 {
24
namespace theory {
25
namespace arith {
26
27
9459
InferenceManager::InferenceManager(TheoryArith& ta,
28
                                   ArithState& astate,
29
9459
                                   ProofNodeManager* pnm)
30
9459
    : InferenceManagerBuffered(ta, astate, pnm, "theory::arith::")
31
{
32
9459
}
33
34
9123
void InferenceManager::addPendingLemma(std::unique_ptr<SimpleTheoryLemma> lemma,
35
                                       bool isWaiting)
36
{
37
18246
  Trace("arith::infman") << "Add " << lemma->getId() << " " << lemma->d_node
38
9123
                         << (isWaiting ? " as waiting" : "") << std::endl;
39
9123
  if (hasCachedLemma(lemma->d_node, lemma->d_property))
40
  {
41
169
    return;
42
  }
43
8954
  if (isEntailedFalse(*lemma))
44
  {
45
    if (isWaiting)
46
    {
47
      d_waitingLem.clear();
48
    }
49
    else
50
    {
51
      d_pendingLem.clear();
52
      d_theoryState.notifyInConflict();
53
    }
54
  }
55
8954
  if (isWaiting)
56
  {
57
2004
    d_waitingLem.emplace_back(std::move(lemma));
58
  }
59
  else
60
  {
61
6950
    d_pendingLem.emplace_back(std::move(lemma));
62
  }
63
}
64
2946
void InferenceManager::addPendingLemma(const SimpleTheoryLemma& lemma,
65
                                       bool isWaiting)
66
{
67
5892
  addPendingLemma(
68
5892
      std::unique_ptr<SimpleTheoryLemma>(new SimpleTheoryLemma(lemma)),
69
      isWaiting);
70
2946
}
71
6177
void InferenceManager::addPendingLemma(const Node& lemma,
72
                                       InferenceId inftype,
73
                                       ProofGenerator* pg,
74
                                       bool isWaiting,
75
                                       LemmaProperty p)
76
{
77
12354
  addPendingLemma(std::unique_ptr<SimpleTheoryLemma>(
78
6177
                      new SimpleTheoryLemma(inftype, lemma, p, pg)),
79
                  isWaiting);
80
6177
}
81
82
542
void InferenceManager::flushWaitingLemmas()
83
{
84
1461
  for (auto& lem : d_waitingLem)
85
  {
86
1838
    Trace("arith::infman") << "Flush waiting lemma to pending: "
87
1838
                           << lem->getId() << " " << lem->d_node
88
919
                           << std::endl;
89
919
    d_pendingLem.emplace_back(std::move(lem));
90
  }
91
542
  d_waitingLem.clear();
92
542
}
93
2864
void InferenceManager::clearWaitingLemmas()
94
{
95
2864
  d_waitingLem.clear();
96
2864
}
97
98
2985
bool InferenceManager::hasUsed() const
99
{
100
2985
  return hasSent() || hasPending();
101
}
102
103
215
bool InferenceManager::hasWaitingLemma() const
104
{
105
215
  return !d_waitingLem.empty();
106
}
107
108
4340
std::size_t InferenceManager::numWaitingLemmas() const
109
{
110
4340
  return d_waitingLem.size();
111
}
112
113
9123
bool InferenceManager::hasCachedLemma(TNode lem, LemmaProperty p)
114
{
115
18246
  Node rewritten = Rewriter::rewrite(lem);
116
18246
  return TheoryInferenceManager::hasCachedLemma(rewritten, p);
117
}
118
119
152437
bool InferenceManager::cacheLemma(TNode lem, LemmaProperty p)
120
{
121
304874
  Node rewritten = Rewriter::rewrite(lem);
122
304874
  return TheoryInferenceManager::cacheLemma(rewritten, p);
123
}
124
125
8954
bool InferenceManager::isEntailedFalse(const SimpleTheoryLemma& lem)
126
{
127
17908
  if (options::nlExtEntailConflicts())
128
  {
129
    Node ch_lemma = lem.d_node.negate();
130
    ch_lemma = Rewriter::rewrite(ch_lemma);
131
    Trace("arith-inf-manager") << "InferenceManager::Check entailment of "
132
                               << ch_lemma << "..." << std::endl;
133
134
    std::pair<bool, Node> et = d_theory.getValuation().entailmentCheck(
135
        options::TheoryOfMode::THEORY_OF_TYPE_BASED, ch_lemma);
136
    Trace("arith-inf-manager") << "entailment test result : " << et.first << " "
137
                               << et.second << std::endl;
138
    if (et.first)
139
    {
140
      Trace("arith-inf-manager")
141
          << "*** Lemma entailed to be in conflict : " << lem.d_node
142
          << std::endl;
143
      return true;
144
    }
145
  }
146
8954
  return false;
147
}
148
149
}  // namespace arith
150
}  // namespace theory
151
37145
}  // namespace cvc5