1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andres Noetzli, Andrew Reynolds, Morgan Deters |
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 |
|
* AssertionPipeline stores a list of assertions modified by |
14 |
|
* preprocessing passes. |
15 |
|
*/ |
16 |
|
|
17 |
|
#include "cvc5_private.h" |
18 |
|
|
19 |
|
#ifndef CVC5__PREPROCESSING__ASSERTION_PIPELINE_H |
20 |
|
#define CVC5__PREPROCESSING__ASSERTION_PIPELINE_H |
21 |
|
|
22 |
|
#include <vector> |
23 |
|
|
24 |
|
#include "expr/node.h" |
25 |
|
#include "proof/trust_node.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
|
29 |
|
class ProofGenerator; |
30 |
|
namespace smt { |
31 |
|
class PreprocessProofGenerator; |
32 |
|
} |
33 |
|
|
34 |
|
namespace preprocessing { |
35 |
|
|
36 |
|
using IteSkolemMap = std::unordered_map<size_t, Node>; |
37 |
|
|
38 |
|
/** |
39 |
|
* Assertion Pipeline stores a list of assertions modified by preprocessing |
40 |
|
* passes. It is assumed that all assertions after d_realAssertionsEnd were |
41 |
|
* generated by ITE removal. Hence, d_iteSkolemMap maps into only these. |
42 |
|
*/ |
43 |
10487 |
class AssertionPipeline |
44 |
|
{ |
45 |
|
public: |
46 |
|
AssertionPipeline(); |
47 |
|
|
48 |
662843 |
size_t size() const { return d_nodes.size(); } |
49 |
|
|
50 |
2 |
void resize(size_t n) { d_nodes.resize(n); } |
51 |
|
|
52 |
|
/** |
53 |
|
* Clear the list of assertions and assumptions. |
54 |
|
*/ |
55 |
|
void clear(); |
56 |
|
|
57 |
1922322 |
const Node& operator[](size_t i) const { return d_nodes[i]; } |
58 |
|
|
59 |
|
/** |
60 |
|
* Adds an assertion/assumption to be preprocessed. |
61 |
|
* |
62 |
|
* @param n The assertion/assumption |
63 |
|
* @param isAssumption If true, records that \p n is an assumption. Note that |
64 |
|
* all assumptions have to be added contiguously. |
65 |
|
* @param isInput If true, n is an input formula (an assumption in the main |
66 |
|
* body of the overall proof). |
67 |
|
* @param pg The proof generator who can provide a proof of n. The proof |
68 |
|
* generator is not required and is ignored if isInput is true. |
69 |
|
*/ |
70 |
|
void push_back(Node n, |
71 |
|
bool isAssumption = false, |
72 |
|
bool isInput = false, |
73 |
|
ProofGenerator* pg = nullptr); |
74 |
|
/** Same as above, with TrustNode */ |
75 |
|
void pushBackTrusted(TrustNode trn); |
76 |
|
|
77 |
|
/** |
78 |
|
* Get the constant reference to the underlying assertions. It is only |
79 |
|
* possible to modify these via the replace methods below. |
80 |
|
*/ |
81 |
20926 |
const std::vector<Node>& ref() const { return d_nodes; } |
82 |
|
|
83 |
33 |
std::vector<Node>::const_iterator begin() const { return d_nodes.cbegin(); } |
84 |
61 |
std::vector<Node>::const_iterator end() const { return d_nodes.cend(); } |
85 |
|
|
86 |
|
/* |
87 |
|
* Replaces assertion i with node n and records the dependency between the |
88 |
|
* original assertion and its replacement. |
89 |
|
* |
90 |
|
* @param i The position of the assertion to replace. |
91 |
|
* @param n The replacement assertion. |
92 |
|
* @param pg The proof generator who can provide a proof of d_nodes[i] == n, |
93 |
|
* where d_nodes[i] is the assertion at position i prior to this call. |
94 |
|
*/ |
95 |
|
void replace(size_t i, Node n, ProofGenerator* pg = nullptr); |
96 |
|
/** |
97 |
|
* Same as above, with TrustNode trn, which is of kind REWRITE and proves |
98 |
|
* d_nodes[i] = n for some n. |
99 |
|
*/ |
100 |
|
void replaceTrusted(size_t i, TrustNode trn); |
101 |
|
|
102 |
44744 |
IteSkolemMap& getIteSkolemMap() { return d_iteSkolemMap; } |
103 |
|
const IteSkolemMap& getIteSkolemMap() const { return d_iteSkolemMap; } |
104 |
|
|
105 |
12403 |
size_t getRealAssertionsEnd() const { return d_realAssertionsEnd; } |
106 |
|
|
107 |
|
/** @return The index of the first assumption */ |
108 |
|
size_t getAssumptionsStart() const { return d_assumptionsStart; } |
109 |
|
|
110 |
|
/** @return The number of assumptions */ |
111 |
13735 |
size_t getNumAssumptions() const { return d_numAssumptions; } |
112 |
|
|
113 |
13743 |
void updateRealAssertionsEnd() { d_realAssertionsEnd = d_nodes.size(); } |
114 |
|
|
115 |
|
/** |
116 |
|
* Returns true if substitutions must be stored as assertions. This is for |
117 |
|
* example the case when we do incremental solving. |
118 |
|
*/ |
119 |
9920 |
bool storeSubstsInAsserts() { return d_storeSubstsInAsserts; } |
120 |
|
|
121 |
|
/** |
122 |
|
* Enables storing substitutions as assertions. |
123 |
|
*/ |
124 |
|
void enableStoreSubstsInAsserts(); |
125 |
|
|
126 |
|
/** |
127 |
|
* Disables storing substitutions as assertions. |
128 |
|
*/ |
129 |
|
void disableStoreSubstsInAsserts(); |
130 |
|
|
131 |
|
/** |
132 |
|
* Adds a substitution node of the form (= lhs rhs) to the assertions. |
133 |
|
* This conjoins n to assertions at a distinguished index given by |
134 |
|
* d_substsIndex. |
135 |
|
* |
136 |
|
* @param n The substitution node |
137 |
|
* @param pg The proof generator that can provide a proof of n. |
138 |
|
*/ |
139 |
|
void addSubstitutionNode(Node n, ProofGenerator* pg = nullptr); |
140 |
|
|
141 |
|
/** |
142 |
|
* Conjoin n to the assertion vector at position i. This replaces |
143 |
|
* d_nodes[i] with the rewritten form of (AND d_nodes[i] n). |
144 |
|
* |
145 |
|
* @param i The assertion to replace |
146 |
|
* @param n The formula to conjoin at position i |
147 |
|
* @param pg The proof generator that can provide a proof of n |
148 |
|
*/ |
149 |
|
void conjoin(size_t i, Node n, ProofGenerator* pg = nullptr); |
150 |
|
|
151 |
|
/** |
152 |
|
* Checks whether the assertion at a given index represents substitutions. |
153 |
|
* |
154 |
|
* @param i The index in question |
155 |
|
*/ |
156 |
303618 |
bool isSubstsIndex(size_t i) |
157 |
|
{ |
158 |
303618 |
return d_storeSubstsInAsserts && i == d_substsIndex; |
159 |
|
} |
160 |
|
//------------------------------------ for proofs |
161 |
|
/** Set proof generator */ |
162 |
|
void setProofGenerator(smt::PreprocessProofGenerator* pppg); |
163 |
|
/** Is proof enabled? */ |
164 |
|
bool isProofEnabled() const; |
165 |
|
//------------------------------------ end for proofs |
166 |
|
private: |
167 |
|
/** The list of current assertions */ |
168 |
|
std::vector<Node> d_nodes; |
169 |
|
|
170 |
|
/** |
171 |
|
* Map from skolem variables to index in d_assertions containing |
172 |
|
* corresponding introduced Boolean ite |
173 |
|
*/ |
174 |
|
IteSkolemMap d_iteSkolemMap; |
175 |
|
|
176 |
|
/** Size of d_nodes when preprocessing starts */ |
177 |
|
size_t d_realAssertionsEnd; |
178 |
|
|
179 |
|
/** |
180 |
|
* If true, we store the substitutions as assertions. This is necessary when |
181 |
|
* doing incremental solving because we cannot apply them to existing |
182 |
|
* assertions while preprocessing new assertions. |
183 |
|
*/ |
184 |
|
bool d_storeSubstsInAsserts; |
185 |
|
|
186 |
|
/** |
187 |
|
* The index of the assertions that holds the substitutions. |
188 |
|
* |
189 |
|
* TODO(#2473): replace by separate vector of substitution assertions. |
190 |
|
*/ |
191 |
|
size_t d_substsIndex; |
192 |
|
|
193 |
|
/** Index of the first assumption */ |
194 |
|
size_t d_assumptionsStart; |
195 |
|
/** The number of assumptions */ |
196 |
|
size_t d_numAssumptions; |
197 |
|
/** The proof generator, if one is provided */ |
198 |
|
smt::PreprocessProofGenerator* d_pppg; |
199 |
|
}; /* class AssertionPipeline */ |
200 |
|
|
201 |
|
} // namespace preprocessing |
202 |
|
} // namespace cvc5 |
203 |
|
|
204 |
|
#endif /* CVC5__PREPROCESSING__ASSERTION_PIPELINE_H */ |