GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/inference_manager.cpp Lines: 56 73 76.7 %
Date: 2021-08-06 Branches: 60 182 33.0 %

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
9853
InferenceManager::InferenceManager(TheoryArith& ta,
28
                                   ArithState& astate,
29
9853
                                   ProofNodeManager* pnm)
30
    : InferenceManagerBuffered(ta, astate, pnm, "theory::arith::"),
31
      // currently must track propagated literals if using the equality solver
32
9853
      d_trackPropLits(options::arithEqSolver()),
33
19706
      d_propLits(astate.getSatContext())
34
{
35
9853
}
36
37
8812
void InferenceManager::addPendingLemma(std::unique_ptr<SimpleTheoryLemma> lemma,
38
                                       bool isWaiting)
39
{
40
17624
  Trace("arith::infman") << "Add " << lemma->getId() << " " << lemma->d_node
41
8812
                         << (isWaiting ? " as waiting" : "") << std::endl;
42
8812
  if (hasCachedLemma(lemma->d_node, lemma->d_property))
43
  {
44
169
    return;
45
  }
46
8643
  if (isEntailedFalse(*lemma))
47
  {
48
    if (isWaiting)
49
    {
50
      d_waitingLem.clear();
51
    }
52
    else
53
    {
54
      d_pendingLem.clear();
55
      d_theoryState.notifyInConflict();
56
    }
57
  }
58
8643
  if (isWaiting)
59
  {
60
1910
    d_waitingLem.emplace_back(std::move(lemma));
61
  }
62
  else
63
  {
64
6733
    d_pendingLem.emplace_back(std::move(lemma));
65
  }
66
}
67
2810
void InferenceManager::addPendingLemma(const SimpleTheoryLemma& lemma,
68
                                       bool isWaiting)
69
{
70
5620
  addPendingLemma(
71
5620
      std::unique_ptr<SimpleTheoryLemma>(new SimpleTheoryLemma(lemma)),
72
      isWaiting);
73
2810
}
74
6002
void InferenceManager::addPendingLemma(const Node& lemma,
75
                                       InferenceId inftype,
76
                                       ProofGenerator* pg,
77
                                       bool isWaiting,
78
                                       LemmaProperty p)
79
{
80
12004
  addPendingLemma(std::unique_ptr<SimpleTheoryLemma>(
81
6002
                      new SimpleTheoryLemma(inftype, lemma, p, pg)),
82
                  isWaiting);
83
6002
}
84
85
566
void InferenceManager::flushWaitingLemmas()
86
{
87
1475
  for (auto& lem : d_waitingLem)
88
  {
89
1818
    Trace("arith::infman") << "Flush waiting lemma to pending: "
90
1818
                           << lem->getId() << " " << lem->d_node
91
909
                           << std::endl;
92
909
    d_pendingLem.emplace_back(std::move(lem));
93
  }
94
566
  d_waitingLem.clear();
95
566
}
96
2830
void InferenceManager::clearWaitingLemmas()
97
{
98
2830
  d_waitingLem.clear();
99
2830
}
100
101
2975
bool InferenceManager::hasUsed() const
102
{
103
2975
  return hasSent() || hasPending();
104
}
105
106
233
bool InferenceManager::hasWaitingLemma() const
107
{
108
233
  return !d_waitingLem.empty();
109
}
110
111
4331
std::size_t InferenceManager::numWaitingLemmas() const
112
{
113
4331
  return d_waitingLem.size();
114
}
115
116
8812
bool InferenceManager::hasCachedLemma(TNode lem, LemmaProperty p)
117
{
118
17624
  Node rewritten = Rewriter::rewrite(lem);
119
17624
  return TheoryInferenceManager::hasCachedLemma(rewritten, p);
120
}
121
122
163152
bool InferenceManager::cacheLemma(TNode lem, LemmaProperty p)
123
{
124
326304
  Node rewritten = Rewriter::rewrite(lem);
125
326304
  return TheoryInferenceManager::cacheLemma(rewritten, p);
126
}
127
128
8643
bool InferenceManager::isEntailedFalse(const SimpleTheoryLemma& lem)
129
{
130
17286
  if (options::nlExtEntailConflicts())
131
  {
132
    Node ch_lemma = lem.d_node.negate();
133
    ch_lemma = Rewriter::rewrite(ch_lemma);
134
    Trace("arith-inf-manager") << "InferenceManager::Check entailment of "
135
                               << ch_lemma << "..." << std::endl;
136
137
    std::pair<bool, Node> et = d_theory.getValuation().entailmentCheck(
138
        options::TheoryOfMode::THEORY_OF_TYPE_BASED, ch_lemma);
139
    Trace("arith-inf-manager") << "entailment test result : " << et.first << " "
140
                               << et.second << std::endl;
141
    if (et.first)
142
    {
143
      Trace("arith-inf-manager")
144
          << "*** Lemma entailed to be in conflict : " << lem.d_node
145
          << std::endl;
146
      return true;
147
    }
148
  }
149
8643
  return false;
150
}
151
152
1418798
bool InferenceManager::propagateLit(TNode lit)
153
{
154
1418798
  if (d_trackPropLits)
155
  {
156
990
    d_propLits.insert(lit);
157
  }
158
1418798
  return TheoryInferenceManager::propagateLit(lit);
159
}
160
161
186
bool InferenceManager::hasPropagated(TNode lit) const
162
{
163
186
  Assert(d_trackPropLits);
164
186
  return d_propLits.find(lit) != d_propLits.end();
165
}
166
167
}  // namespace arith
168
}  // namespace theory
169
37965
}  // namespace cvc5