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
181
182
183
/*
* This file is part of the source code of the software program
* Vampire. It is protected by applicable
* copyright laws.
*
* This source code is distributed under the licence found here
* https://vprover.github.io/license.html
* and in the source directory
*/
#include "Kernel/Clause.hpp"
#include "Kernel/SortHelper.hpp"
#include "Kernel/Term.hpp"
#include "Lib/Environment.hpp"
#include "Shell/Statistics.hpp"
#include "Shell/TheoryFinder.hpp"
#include "Saturation/ExtensionalityClauseContainer.hpp"
namespace Saturation
{
using namespace std;
using namespace Shell;
/**
* Check if clause is considered as an extensionality clause (according to
* options). If so, track in extensionality container for extensionality
* resolution inferences.
*
* Common to all extensionality clauses is a single positive variable equality
* X=Y, which is returned in case of a positive match, 0 otherwise.
*/
Literal* ExtensionalityClauseContainer::addIfExtensionality(Clause* c) {
// Clause is already in extensionality container. We only have to search X=Y.
if (c->isExtensionality()) {
//cout << "Using " << c->toString() << endl;
return getSingleVarEq(c);
}
// We only consider extensionality clauses of at least length 2, but can also
// specify a length limit.
unsigned clen = c->length();
if (clen < 2 || (_maxLen > 1 && clen > _maxLen))
return 0;
Literal* varEq = 0;
TermList sort;
if (_onlyKnown) {
// We only match against specific extensionality axiom patterns (e.g. set,
// array, ...).
if(!TheoryFinder::matchKnownExtensionality(c))
return 0;
// We know that the patterns only have a single X=Y.
varEq = getSingleVarEq(c);
sort = varEq->twoVarEqSort();
} else if (!_onlyTagged || c->isTaggedExtensionality()) {
// Generic filter for extensionality clauses.
// * Exactly one X=Y
// * No inequality of same sort as X=Y
// * No equality except X=Y (optional).
static DHSet<TermList> negEqSorts;
negEqSorts.reset();
for (auto l : c->iterLits()) {
if (l->isTwoVarEquality() && l->isPositive()) {
if (varEq != 0)
return 0;
sort = l->twoVarEqSort();
if (negEqSorts.contains(sort))
return 0;
varEq = l;
} else if (l->isEquality()) {
if (!_allowPosEq && l->isPositive())
return 0;
TermList negEqSort = SortHelper::getEqualityArgumentSort(l);
if (varEq == 0)
negEqSorts.insert(negEqSort);
else if (sort == negEqSort)
return 0;
}
}
}
if (varEq != 0) {
// If varEq is nonzero then sort must have been set above.
c->setExtensionality(true);
add(ExtensionalityClause(c, varEq, sort));
_size++;
env.statistics->extensionalityClauses++;
return varEq;
}
return 0;
}
/**
* Get the single positive variable equality of an extensionality clause.
* Actually returns the first such equality and hence should be used only in
* places where we already know that @c c is an extensionality clause.
*/
Literal* ExtensionalityClauseContainer::getSingleVarEq(Clause* c) {
for (unsigned i = 0; i < c->length(); ++i) {
Literal* varEq = (*c)[i];
if (varEq->isTwoVarEquality() && varEq->isPositive()) {
return varEq;
break;
}
}
ASSERTION_VIOLATION;
}
void ExtensionalityClauseContainer::add(ExtensionalityClause c) {
ExtensionalityClauseList** l;
_clausesBySort.getValuePtr(c.sort,l,ExtensionalityClauseList::empty());
ExtensionalityClauseList::push(c,*l);
}
/**
* Functor for lazily removing deleted extensionality clauses from the container.
* See activeIterator(unsigned sort).
*/
struct ExtensionalityClauseContainer::ActiveFilterFn
{
ActiveFilterFn(ExtensionalityClauseContainer& parent) : _parent(parent) {}
bool operator()(ExtensionalityClause extCl)
{
if (extCl.clause->store() != Clause::ACTIVE) {
extCl.clause->setExtensionality(false);
_parent._size--;
return false;
}
return true;
}
private:
ExtensionalityClauseContainer& _parent;
};
/**
* Returns an iterator over the active extensionality clauses of a particular @c
* sort. Nonactive clauses in the container are removed during iteration.
*
* In other words, if an extensionality clause gets deleted from the search
* space, we do not immediately remove it from the container. Instead we check
* this lazily during generating inferences.
*/
ExtensionalityClauseIterator ExtensionalityClauseContainer::activeIterator(TermList sort) {
if(_clausesBySort.find(sort)){
return pvi(getFilteredDelIterator(
ExtensionalityClauseList::DelIterator(_clausesBySort.get(sort)),
ActiveFilterFn(*this)));
} else {
return ExtensionalityClauseIterator::getEmpty();
}
}
void ExtensionalityClauseContainer::print (std::ostream& out) {
out << "#####################" << endl;
ClausesBySort::Iterator cbs(_clausesBySort);
while(cbs.hasNext()){
ExtensionalityClauseList* l = cbs.next();
ExtensionalityClauseList::Iterator it(l);
while(it.hasNext()) {
ExtensionalityClause c = it.next();
out << c.clause->toString() << endl
<< c.literal->toString() << endl
<< c.sort << endl;
}
}
out << "#####################" << endl;
}
}