GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/theory_state.cpp Lines: 68 70 97.1 %
Date: 2021-09-17 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
119346
TheoryState::TheoryState(Env& env, Valuation val)
24
119346
    : EnvObj(env), d_valuation(val), d_ee(nullptr), d_conflict(context(), false)
25
{
26
119346
}
27
28
119304
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
29
30
28844108
bool TheoryState::hasTerm(TNode a) const
31
{
32
28844108
  Assert(d_ee != nullptr);
33
28844108
  return d_ee->hasTerm(a);
34
}
35
36
15136396
TNode TheoryState::getRepresentative(TNode t) const
37
{
38
15136396
  Assert(d_ee != nullptr);
39
15136396
  if (d_ee->hasTerm(t))
40
  {
41
14978321
    return d_ee->getRepresentative(t);
42
  }
43
158075
  return t;
44
}
45
46
9585334
bool TheoryState::areEqual(TNode a, TNode b) const
47
{
48
9585334
  Assert(d_ee != nullptr);
49
9585334
  if (a == b)
50
  {
51
2445832
    return true;
52
  }
53
7139502
  else if (hasTerm(a) && hasTerm(b))
54
  {
55
7099717
    return d_ee->areEqual(a, b);
56
  }
57
39785
  return false;
58
}
59
60
576774
bool TheoryState::areDisequal(TNode a, TNode b) const
61
{
62
576774
  Assert(d_ee != nullptr);
63
576774
  if (a == b)
64
  {
65
245990
    return false;
66
  }
67
68
330784
  bool isConst = true;
69
330784
  bool hasTerms = true;
70
330784
  if (hasTerm(a))
71
  {
72
330221
    a = d_ee->getRepresentative(a);
73
330221
    isConst = a.isConst();
74
  }
75
563
  else if (!a.isConst())
76
  {
77
    // if not constant and not a term in the ee, it cannot be disequal
78
321
    return false;
79
  }
80
  else
81
  {
82
242
    hasTerms = false;
83
  }
84
85
330463
  if (hasTerm(b))
86
  {
87
330071
    b = d_ee->getRepresentative(b);
88
330071
    isConst = isConst && b.isConst();
89
  }
90
392
  else if (!b.isConst())
91
  {
92
    // same as above, it cannot be disequal
93
57
    return false;
94
  }
95
  else
96
  {
97
335
    hasTerms = false;
98
  }
99
100
330406
  if (isConst)
101
  {
102
    // distinct constants are disequal
103
64216
    return a != b;
104
  }
105
266190
  else if (!hasTerms)
106
  {
107
339
    return false;
108
  }
109
  // otherwise there may be an explicit disequality in the equality engine
110
265851
  return d_ee->areDisequal(a, b, false);
111
}
112
113
8279
void TheoryState::getEquivalenceClass(Node a, std::vector<Node>& eqc) const
114
{
115
8279
  if (d_ee->hasTerm(a))
116
  {
117
15024
    Node rep = d_ee->getRepresentative(a);
118
7512
    eq::EqClassIterator eqc_iter(rep, d_ee);
119
118834
    while (!eqc_iter.isFinished())
120
    {
121
55661
      eqc.push_back(*eqc_iter);
122
55661
      eqc_iter++;
123
    }
124
  }
125
  else
126
  {
127
767
    eqc.push_back(a);
128
  }
129
  // a should be in its equivalence class
130
8279
  Assert(std::find(eqc.begin(), eqc.end(), a) != eqc.end());
131
8279
}
132
133
7269394
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
134
135
2545624
void TheoryState::notifyInConflict() { d_conflict = true; }
136
137
50687666
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
6929128
TheoryModel* TheoryState::getModel() { return d_valuation.getModel(); }
145
146
5153
SortInference* TheoryState::getSortInference()
147
{
148
5153
  return d_valuation.getSortInference();
149
}
150
151
41175
bool TheoryState::hasSatValue(TNode n, bool& value) const
152
{
153
41175
  return d_valuation.hasSatValue(n, value);
154
}
155
156
7639
context::CDList<Assertion>::const_iterator TheoryState::factsBegin(TheoryId tid)
157
{
158
7639
  return d_valuation.factsBegin(tid);
159
}
160
7639
context::CDList<Assertion>::const_iterator TheoryState::factsEnd(TheoryId tid)
161
{
162
7639
  return d_valuation.factsEnd(tid);
163
}
164
165
11629
bool TheoryState::isFiniteType(TypeNode tn) const
166
{
167
11629
  return d_valuation.isFiniteType(tn);
168
}
169
170
1345146
Valuation& TheoryState::getValuation() { return d_valuation; }
171
172
}  // namespace theory
173
29577
}  // namespace cvc5