forked from vprover/vampire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SATInference.hpp
197 lines (165 loc) · 5.11 KB
/
SATInference.hpp
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* File SATInference.hpp.
*
* 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
*
* In summary, you are allowed to use Vampire for non-commercial
* purposes but not allowed to distribute, modify, copy, create derivatives,
* or use in competitions.
* For other uses of Vampire please contact developers for a different
* licence, which we will make an effort to provide.
*/
/**
* @file SATInference.hpp
* Defines class SATInference.
*/
#ifndef __SATInference__
#define __SATInference__
#include "Forwards.hpp"
#include "Lib/List.hpp"
#include "SATClause.hpp"
namespace SAT {
using namespace Kernel;
class SATInference
{
public:
enum InfType {
PROP_INF,
FO_CONVERSION,
ASSUMPTION
};
virtual ~SATInference() {}
virtual InfType getType() const = 0;
template <typename Filter>
static void collectFilteredFOPremises(SATClause* cl, Stack<Unit*>& acc, Filter f);
static void collectFOPremises(SATClause* cl, Stack<Unit*>& acc);
static void collectPropAxioms(SATClause* cl, SATClauseStack& res);
static UnitList* getFOPremises(SATClause* cl);
static SATInference* copy(const SATInference* inf);
};
class PropInference : public SATInference
{
public:
CLASS_NAME(PropInference);
USE_ALLOCATOR(PropInference);
PropInference(SATClauseList* premises) : _premises(premises) {}
PropInference(SATClause* prem) : _premises(0)
{
SATClauseList::push(prem, _premises);
}
PropInference(SATClause* prem1, SATClause* prem2) : _premises(0)
{
SATClauseList::push(prem1, _premises);
SATClauseList::push(prem2, _premises);
}
~PropInference()
{
SATClauseList::destroy(_premises);
}
virtual InfType getType() const { return PROP_INF; }
SATClauseList* getPremises() const { return const_cast<SATClauseList*>(_premises); }
void setPremises(SATClauseList* prems) { _premises = prems; }
private:
SATClauseList* _premises;
};
class FOConversionInference : public SATInference
{
public:
CLASS_NAME(FOConversionInference);
USE_ALLOCATOR(FOConversionInference);
FOConversionInference(Unit* origin);
FOConversionInference(Clause* cl);
~FOConversionInference();
virtual InfType getType() const { return FO_CONVERSION; }
Unit* getOrigin() const { return _origin; }
private:
Unit* _origin;
};
class AssumptionInference : public SATInference
{
public:
CLASS_NAME(AssumptionInference);
USE_ALLOCATOR(AssumptionInference);
virtual InfType getType() const { return ASSUMPTION; }
};
/**
* A first order inference coming from a SAT refutation.
* Possibly the SAT refutation was unnecessarily too large
* and may be minimized before the final proof outputting.
*/
class InferenceFromSatRefutation : public Kernel::InferenceMany
{
public:
/**
* The inherited first order part (@b premises) must be already given,
* but it is expected that it is much larger than necessary.
*
* A list of @b satPremises is just taken
* (no memory responsibility overtaken; the list must survive till the minimization call),
* a stack of @b usedAssumptions is copied.
*/
InferenceFromSatRefutation(Rule rule, UnitList* premises, SATClauseList* satPremises, const SATLiteralStack& usedAssumptions) :
InferenceMany(rule,premises), _minimized(false), _satPremises(satPremises), _usedAssumptions(usedAssumptions) {}
/**
* Constructor versions with no assumptions.
*/
InferenceFromSatRefutation(Rule rule, UnitList* premises, SATClauseList* satPremises) :
InferenceMany(rule,premises), _minimized(false), _satPremises(satPremises) {}
virtual void minimizePremises() override;
CLASS_NAME(InferenceFromSatRefutation);
USE_ALLOCATOR(InferenceFromSatRefutation);
protected:
bool _minimized;
SATClauseList* _satPremises;
SATLiteralStack _usedAssumptions;
};
/**
* Collect first-order premises of @c cl into @c res. Make sure that elements in @c res are unique.
* Only consider those SATClauses and their parents which pass the given Filter f.
*/
template <typename Filter>
void SATInference::collectFilteredFOPremises(SATClause* cl, Stack<Unit*>& acc, Filter f)
{
CALL("SATInference::collectFilteredFOPremises");
ASS_ALLOC_TYPE(cl, "SATClause");
static Stack<SATClause*> toDo;
static DHSet<SATClause*> seen;
toDo.reset();
seen.reset();
toDo.push(cl);
while (toDo.isNonEmpty()) {
SATClause* cur = toDo.pop();
if (!f(cur)) {
continue;
}
if (!seen.insert(cur)) {
continue;
}
SATInference* sinf = cur->inference();
ASS(sinf);
switch(sinf->getType()) {
case SATInference::FO_CONVERSION:
acc.push(static_cast<FOConversionInference*>(sinf)->getOrigin());
break;
case SATInference::ASSUMPTION:
break;
case SATInference::PROP_INF:
{
PropInference* pinf = static_cast<PropInference*>(sinf);
toDo.loadFromIterator(SATClauseList::Iterator(pinf->getPremises()));
break;
}
default:
ASSERTION_VIOLATION;
}
}
makeUnique(acc);
}
}
#endif // __SATInference__