summaryrefslogtreecommitdiff
path: root/src/theory/theory_state.cpp
blob: ec7955125fb6405ff9ffd290400894c673473113 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds, Mathias Preiner
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 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.
 * ****************************************************************************
 *
 * A theory state for Theory.
 */

#include "theory/theory_state.h"

#include "theory/uf/equality_engine.h"

namespace cvc5 {
namespace theory {

TheoryState::TheoryState(Env& env, Valuation val)
    : EnvObj(env), d_valuation(val), d_ee(nullptr), d_conflict(context(), false)
{
}

void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }

context::Context* TheoryState::getSatContext() const { return context(); }

context::UserContext* TheoryState::getUserContext() const
{
  return userContext();
}

bool TheoryState::hasTerm(TNode a) const
{
  Assert(d_ee != nullptr);
  return d_ee->hasTerm(a);
}

TNode TheoryState::getRepresentative(TNode t) const
{
  Assert(d_ee != nullptr);
  if (d_ee->hasTerm(t))
  {
    return d_ee->getRepresentative(t);
  }
  return t;
}

bool TheoryState::areEqual(TNode a, TNode b) const
{
  Assert(d_ee != nullptr);
  if (a == b)
  {
    return true;
  }
  else if (hasTerm(a) && hasTerm(b))
  {
    return d_ee->areEqual(a, b);
  }
  return false;
}

bool TheoryState::areDisequal(TNode a, TNode b) const
{
  Assert(d_ee != nullptr);
  if (a == b)
  {
    return false;
  }

  bool isConst = true;
  bool hasTerms = true;
  if (hasTerm(a))
  {
    a = d_ee->getRepresentative(a);
    isConst = a.isConst();
  }
  else if (!a.isConst())
  {
    // if not constant and not a term in the ee, it cannot be disequal
    return false;
  }
  else
  {
    hasTerms = false;
  }

  if (hasTerm(b))
  {
    b = d_ee->getRepresentative(b);
    isConst = isConst && b.isConst();
  }
  else if (!b.isConst())
  {
    // same as above, it cannot be disequal
    return false;
  }
  else
  {
    hasTerms = false;
  }

  if (isConst)
  {
    // distinct constants are disequal
    return a != b;
  }
  else if (!hasTerms)
  {
    return false;
  }
  // otherwise there may be an explicit disequality in the equality engine
  return d_ee->areDisequal(a, b, false);
}

void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
{
  if (d_ee->hasTerm(a))
  {
    Node rep = d_ee->getRepresentative(a);
    eq::EqClassIterator eqc_iter(rep, d_ee);
    while (!eqc_iter.isFinished())
    {
      eqc.push_back(*eqc_iter);
      eqc_iter++;
    }
  }
  else
  {
    eqc.push_back(a);
  }
  // a should be in its equivalence class
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
}

eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }

void TheoryState::notifyInConflict() { d_conflict = true; }

bool TheoryState::isInConflict() const { return d_conflict; }

bool TheoryState::isSatLiteral(TNode lit) const
{
  return d_valuation.isSatLiteral(lit);
}

TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }

SortInference* TheoryState::getSortInference()
{
  return d_valuation.getSortInference();
}

bool TheoryState::hasSatValue(TNode n, bool& value) const
{
  return d_valuation.hasSatValue(n, value);
}

context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
{
  return d_valuation.factsBegin(tid);
}
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
{
  return d_valuation.factsEnd(tid);
}

bool TheoryState::isFiniteType(TypeNode tn) const
{
  return d_valuation.isFiniteType(tn);
}

Valuation& TheoryState::getValuation() { return d_valuation; }

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