GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 68 70 97.1 %
Date: 2021-09-29 Branches: 80 192 41.7 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, 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
 * A theory state for Theory.
14
 */
15
16
#include "theory/theory_state.h"
17
18
#include "theory/uf/equality_engine.h"
19
20
namespace cvc5 {
21
namespace theory {
22
23
75294
TheoryState::TheoryState(Env& env, Valuation val)
24
75294
    : EnvObj(env), d_valuation(val), d_ee(nullptr), d_conflict(context(), false)
25
{
26
75294
}
27
28
75252
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
29
30
14105023
bool TheoryState::hasTerm(TNode a) const
31
{
32
14105023
  Assert(d_ee != nullptr);
33
14105023
  return d_ee->hasTerm(a);
34
}
35
36
8198080
TNode TheoryState::getRepresentative(TNode t) const
37
{
38
8198080
  Assert(d_ee != nullptr);
39
8198080
  if (d_ee->hasTerm(t))
40
  {
41
8137220
    return d_ee->getRepresentative(t);
42
  }
43
60860
  return t;
44
}
45
46
5710625
bool TheoryState::areEqual(TNode a, TNode b) const
47
{
48
5710625
  Assert(d_ee != nullptr);
49
5710625
  if (a == b)
50
  {
51
1479226
    return true;
52
  }
53
4231399
  else if (hasTerm(a) && hasTerm(b))
54
  {
55
4206817
    return d_ee->areEqual(a, b);
56
  }
57
24582
  return false;
58
}
59
60
281600
bool TheoryState::areDisequal(TNode a, TNode b) const
61
{
62
281600
  Assert(d_ee != nullptr);
63
281600
  if (a == b)
64
  {
65
99635
    return false;
66
  }
67
68
181965
  bool isConst = true;
69
181965
  bool hasTerms = true;
70
181965
  if (hasTerm(a))
71
  {
72
181544
    a = d_ee->getRepresentative(a);
73
181544
    isConst = a.isConst();
74
  }
75
421
  else if (!a.isConst())
76
  {
77
    // if not constant and not a term in the ee, it cannot be disequal
78
181
    return false;
79
  }
80
  else
81
  {
82
240
    hasTerms = false;
83
  }
84
85
181784
  if (hasTerm(b))
86
  {
87
181613
    b = d_ee->getRepresentative(b);
88
181613
    isConst = isConst && b.isConst();
89
  }
90
171
  else if (!b.isConst())
91
  {
92
    // same as above, it cannot be disequal
93
16
    return false;
94
  }
95
  else
96
  {
97
155
    hasTerms = false;
98
  }
99
100
181768
  if (isConst)
101
  {
102
    // distinct constants are disequal
103
40278
    return a != b;
104
  }
105
141490
  else if (!hasTerms)
106
  {
107
325
    return false;
108
  }
109
  // otherwise there may be an explicit disequality in the equality engine
110
141165
  return d_ee->areDisequal(a, b, false);
111
}
112
113
7004
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
114
{
115
7004
  if (d_ee->hasTerm(a))
116
  {
117
12716
    Node rep = d_ee->getRepresentative(a);
118
6358
    eq::EqClassIterator eqc_iter(rep, d_ee);
119
105040
    while (!eqc_iter.isFinished())
120
    {
121
49341
      eqc.push_back(*eqc_iter);
122
49341
      eqc_iter++;
123
    }
124
  }
125
  else
126
  {
127
646
    eqc.push_back(a);
128
  }
129
  // a should be in its equivalence class
130
7004
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
131
7004
}
132
133
3350080
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
134
135
1554697
void TheoryState::notifyInConflict() { d_conflict = true; }
136
137
31229665
bool TheoryState::isInConflict() const { return d_conflict; }
138
139
bool TheoryState::isSatLiteral(TNode lit) const
140
{
141
  return d_valuation.isSatLiteral(lit);
142
}
143
144
5285910
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
145
146
3349
SortInference* TheoryState::getSortInference()
147
{
148
3349
  return d_valuation.getSortInference();
149
}
150
151
424
bool TheoryState::hasSatValue(TNode n, bool& value) const
152
{
153
424
  return d_valuation.hasSatValue(n, value);
154
}
155
156
5016
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
157
{
158
5016
  return d_valuation.factsBegin(tid);
159
}
160
5016
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
161
{
162
5016
  return d_valuation.factsEnd(tid);
163
}
164
165
6828
bool TheoryState::isFiniteType(TypeNode tn) const
166
{
167
6828
  return d_valuation.isFiniteType(tn);
168
}
169
170
1304964
Valuation& TheoryState::getValuation() { return d_valuation; }
171
172
}  // namespace theory
173
22746
}  // namespace cvc5