GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/inference_manager.cpp Lines: 48 65 73.8 %
Date: 2021-05-21 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
8954
InferenceManager::InferenceManager(TheoryArith& ta,
28
                                   ArithState& astate,
29
8954
                                   ProofNodeManager* pnm)
30
8954
    : InferenceManagerBuffered(ta, astate, pnm, "theory::arith::")
31
{
32
8954
}
33
34
9039
void InferenceManager::addPendingLemma(std::unique_ptr<SimpleTheoryLemma> lemma,
35
                                       bool isWaiting)
36
{
37
18078
  Trace("arith::infman") << "Add " << lemma->getId() << " " << lemma->d_node
38
9039
                         << (isWaiting ? " as waiting" : "") << std::endl;
39
9039
  if (hasCachedLemma(lemma->d_node, lemma->d_property))
40
  {
41
169
    return;
42
  }
43
8870
  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
8870
  if (isWaiting)
56
  {
57
1995
    d_waitingLem.emplace_back(std::move(lemma));
58
  }
59
  else
60
  {
61
6875
    d_pendingLem.emplace_back(std::move(lemma));
62
  }
63
}
64
2907
void InferenceManager::addPendingLemma(const SimpleTheoryLemma& lemma,
65
                                       bool isWaiting)
66
{
67
5814
  addPendingLemma(
68
5814
      std::unique_ptr<SimpleTheoryLemma>(new SimpleTheoryLemma(lemma)),
69
      isWaiting);
70
2907
}
71
6132
void InferenceManager::addPendingLemma(const Node& lemma,
72
                                       InferenceId inftype,
73
                                       ProofGenerator* pg,
74
                                       bool isWaiting,
75
                                       LemmaProperty p)
76
{
77
12264
  addPendingLemma(std::unique_ptr<SimpleTheoryLemma>(
78
6132
                      new SimpleTheoryLemma(inftype, lemma, p, pg)),
79
                  isWaiting);
80
6132
}
81
82
530
void InferenceManager::flushWaitingLemmas()
83
{
84
1442
  for (auto& lem : d_waitingLem)
85
  {
86
1824
    Trace("arith::infman") << "Flush waiting lemma to pending: "
87
1824
                           << lem->getId() << " " << lem->d_node
88
912
                           << std::endl;
89
912
    d_pendingLem.emplace_back(std::move(lem));
90
  }
91
530
  d_waitingLem.clear();
92
530
}
93
2799
void InferenceManager::clearWaitingLemmas()
94
{
95
2799
  d_waitingLem.clear();
96
2799
}
97
98
2915
bool InferenceManager::hasUsed() const
99
{
100
2915
  return hasSent() || hasPending();
101
}
102
103
214
bool InferenceManager::hasWaitingLemma() const
104
{
105
214
  return !d_waitingLem.empty();
106
}
107
108
4273
std::size_t InferenceManager::numWaitingLemmas() const
109
{
110
4273
  return d_waitingLem.size();
111
}
112
113
9039
bool InferenceManager::hasCachedLemma(TNode lem, LemmaProperty p)
114
{
115
18078
  Node rewritten = Rewriter::rewrite(lem);
116
18078
  return TheoryInferenceManager::hasCachedLemma(rewritten, p);
117
}
118
119
147610
bool InferenceManager::cacheLemma(TNode lem, LemmaProperty p)
120
{
121
295220
  Node rewritten = Rewriter::rewrite(lem);
122
295220
  return TheoryInferenceManager::cacheLemma(rewritten, p);
123
}
124
125
8870
bool InferenceManager::isEntailedFalse(const SimpleTheoryLemma& lem)
126
{
127
17740
  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
8870
  return false;
147
}
148
149
}  // namespace arith
150
}  // namespace theory
151
36605
}  // namespace cvc5