summaryrefslogtreecommitdiff
path: root/src/theory/arith/inference_manager.cpp
blob: d03d2ba3778584012f1b0c8bf171322b0ad3280a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*********************                                                        */
/*! \file inference_manager.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Gereon Kremer
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Implementation of the inference manager for the theory of strings.
 **/

#include "theory/arith/inference_manager.h"

#include "options/arith_options.h"
#include "theory/arith/theory_arith.h"
#include "theory/rewriter.h"

namespace CVC4 {
namespace theory {
namespace arith {

InferenceManager::InferenceManager(TheoryArith& ta,
                                   ArithState& astate,
                                   ProofNodeManager* pnm)
    : InferenceManagerBuffered(ta, astate, pnm), d_lemmasPp(ta.getUserContext())
{
}

void InferenceManager::addPendingArithLemma(std::unique_ptr<ArithLemma> lemma,
                                            bool isWaiting)
{
  lemma->d_node = Rewriter::rewrite(lemma->d_node);
  if (hasCachedLemma(lemma->d_node, lemma->d_property))
  {
    return;
  }
  if (isEntailedFalse(*lemma))
  {
    if (isWaiting)
    {
      d_waitingLem.clear();
    }
    else
    {
      d_pendingLem.clear();
      d_theoryState.notifyInConflict();
    }
  }
  if (isWaiting)
  {
    d_waitingLem.emplace_back(std::move(lemma));
  }
  else
  {
    d_pendingLem.emplace_back(std::move(lemma));
  }
}
void InferenceManager::addPendingArithLemma(const ArithLemma& lemma,
                                            bool isWaiting)
{
  addPendingArithLemma(std::unique_ptr<ArithLemma>(new ArithLemma(lemma)),
                       isWaiting);
}
void InferenceManager::addPendingArithLemma(const Node& lemma,
                                            InferenceId inftype,
                                            bool isWaiting)
{
  addPendingArithLemma(std::unique_ptr<ArithLemma>(new ArithLemma(
                           lemma, LemmaProperty::NONE, nullptr, inftype)),
                       isWaiting);
}

void InferenceManager::flushWaitingLemmas()
{
  for (auto& lem : d_waitingLem)
  {
    d_pendingLem.emplace_back(std::move(lem));
  }
  d_waitingLem.clear();
}

void InferenceManager::addConflict(const Node& conf, InferenceId inftype)
{
  conflict(Rewriter::rewrite(conf));
}

std::size_t InferenceManager::numWaitingLemmas() const
{
  return d_waitingLem.size();
}

bool InferenceManager::hasCachedLemma(TNode lem, LemmaProperty p)
{
  if (isLemmaPropertyPreprocess(p))
  {
    return d_lemmasPp.find(lem) != d_lemmasPp.end();
  }
  return TheoryInferenceManager::hasCachedLemma(lem, p);
}

bool InferenceManager::cacheLemma(TNode lem, LemmaProperty p)
{
  if (isLemmaPropertyPreprocess(p))
  {
    if (d_lemmasPp.find(lem) != d_lemmasPp.end())
    {
      return false;
    }
    d_lemmasPp.insert(lem);
    return true;
  }
  return TheoryInferenceManager::cacheLemma(lem, p);
}

bool InferenceManager::isEntailedFalse(const ArithLemma& lem)
{
  if (options::nlExtEntailConflicts())
  {
    Node ch_lemma = lem.d_node.negate();
    ch_lemma = Rewriter::rewrite(ch_lemma);
    Trace("arith-inf-manager") << "InferenceManager::Check entailment of "
                               << ch_lemma << "..." << std::endl;

    std::pair<bool, Node> et = d_theory.getValuation().entailmentCheck(
        options::TheoryOfMode::THEORY_OF_TYPE_BASED, ch_lemma);
    Trace("arith-inf-manager") << "entailment test result : " << et.first << " "
                               << et.second << std::endl;
    if (et.first)
    {
      Trace("arith-inf-manager")
          << "*** Lemma entailed to be in conflict : " << lem.d_node
          << std::endl;
      return true;
    }
  }
  return false;
}

}  // namespace arith
}  // namespace theory
}  // namespace CVC4
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback