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
|
/********************* */
/*! \file theory_state.cpp
** \verbatim
** Top contributors (to current version):
** Andrew Reynolds
** 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 A theory state for Theory
**/
#include "theory/theory_state.h"
#include "theory/uf/equality_engine.h"
namespace CVC4 {
namespace theory {
TheoryState::TheoryState(context::Context* c,
context::UserContext* u,
Valuation val)
: d_context(c),
d_ucontext(u),
d_valuation(val),
d_ee(nullptr),
d_conflict(c, false)
{
}
void TheoryState::setEqualityEngine(eq::EqualityEngine* ee) { d_ee = ee; }
context::Context* TheoryState::getSatContext() const { return d_context; }
context::UserContext* TheoryState::getUserContext() const { return d_ucontext; }
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);
}
eq::EqualityEngine* TheoryState::getEqualityEngine() const { return d_ee; }
void TheoryState::notifyInConflict() { d_conflict = true; }
bool TheoryState::isInConflict() const { return d_conflict; }
} // namespace theory
} // namespace CVC4
|