1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Mudathir Mohamed, Andrew Reynolds, Gereon Kremer |
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 |
|
* Inference generator utility. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__BAGS__INFERENCE_GENERATOR_H |
19 |
|
#define CVC5__THEORY__BAGS__INFERENCE_GENERATOR_H |
20 |
|
|
21 |
|
#include "expr/node.h" |
22 |
|
#include "infer_info.h" |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
namespace theory { |
26 |
|
namespace bags { |
27 |
|
|
28 |
|
class InferenceManager; |
29 |
|
class SolverState; |
30 |
|
|
31 |
|
/** |
32 |
|
* An inference generator class. This class is used by the core solver to |
33 |
|
* generate lemmas |
34 |
|
*/ |
35 |
30536 |
class InferenceGenerator |
36 |
|
{ |
37 |
|
public: |
38 |
|
InferenceGenerator(SolverState* state, InferenceManager* im); |
39 |
|
|
40 |
|
/** |
41 |
|
* @param A is a bag of type (Bag E) |
42 |
|
* @param e is a node of type E |
43 |
|
* @return an inference that represents the following implication |
44 |
|
* (=> |
45 |
|
* true |
46 |
|
* (>= (bag.count e A) 0) |
47 |
|
*/ |
48 |
|
InferInfo nonNegativeCount(Node n, Node e); |
49 |
|
|
50 |
|
/** |
51 |
|
* @param n is (bag x c) of type (Bag E) |
52 |
|
* @param e is a node of type E |
53 |
|
* @return an inference that represents the following cases: |
54 |
|
* 1- e, x are in the same equivalent class, then we infer: |
55 |
|
* (= (bag.count e skolem) (ite (>= c 1) c 0))) |
56 |
|
* 2- e, x are known to be disequal, then we infer: |
57 |
|
* (= (bag.count e skolem) 0)) |
58 |
|
* 3- if neither holds, we infer: |
59 |
|
* (= (bag.count e skolem) (ite (and (= e x) (>= c 1)) c 0))) |
60 |
|
* where skolem = (bag x c) is a fresh variable |
61 |
|
*/ |
62 |
|
InferInfo mkBag(Node n, Node e); |
63 |
|
/** |
64 |
|
* @param n is (= A B) where A, B are bags of type (Bag E), and |
65 |
|
* (not (= A B)) is an assertion in the equality engine |
66 |
|
* @return an inference that represents the following implication |
67 |
|
* (=> |
68 |
|
* (not (= A B)) |
69 |
|
* (not (= (count e A) (count e B)))) |
70 |
|
* where e is a fresh skolem of type E. |
71 |
|
*/ |
72 |
|
InferInfo bagDisequality(Node n); |
73 |
|
/** |
74 |
|
* @param n is (as emptybag (Bag E)) |
75 |
|
* @param e is a node of Type E |
76 |
|
* @return an inference that represents the following implication |
77 |
|
* (=> |
78 |
|
* true |
79 |
|
* (= 0 (count e skolem))) |
80 |
|
* where skolem = (as emptybag (Bag String)) |
81 |
|
*/ |
82 |
|
InferInfo empty(Node n, Node e); |
83 |
|
/** |
84 |
|
* @param n is (union_disjoint A B) where A, B are bags of type (Bag E) |
85 |
|
* @param e is a node of Type E |
86 |
|
* @return an inference that represents the following implication |
87 |
|
* (=> |
88 |
|
* true |
89 |
|
* (= (count e skolem) |
90 |
|
* (+ (count e A) (count e B)))) |
91 |
|
* where skolem is a fresh variable equals (union_disjoint A B) |
92 |
|
*/ |
93 |
|
InferInfo unionDisjoint(Node n, Node e); |
94 |
|
/** |
95 |
|
* @param n is (union_disjoint A B) where A, B are bags of type (Bag E) |
96 |
|
* @param e is a node of Type E |
97 |
|
* @return an inference that represents the following implication |
98 |
|
* (=> |
99 |
|
* true |
100 |
|
* (= |
101 |
|
* (count e skolem) |
102 |
|
* (ite |
103 |
|
* (> (count e A) (count e B)) |
104 |
|
* (count e A) |
105 |
|
* (count e B))))) |
106 |
|
* where skolem is a fresh variable equals (union_max A B) |
107 |
|
*/ |
108 |
|
InferInfo unionMax(Node n, Node e); |
109 |
|
/** |
110 |
|
* @param n is (intersection_min A B) where A, B are bags of type (Bag E) |
111 |
|
* @param e is a node of Type E |
112 |
|
* @return an inference that represents the following implication |
113 |
|
* (=> |
114 |
|
* true |
115 |
|
* (= |
116 |
|
* (count e skolem) |
117 |
|
* (ite( |
118 |
|
* (< (count e A) (count e B)) |
119 |
|
* (count e A) |
120 |
|
* (count e B))))) |
121 |
|
* where skolem is a fresh variable equals (intersection_min A B) |
122 |
|
*/ |
123 |
|
InferInfo intersection(Node n, Node e); |
124 |
|
/** |
125 |
|
* @param n is (difference_subtract A B) where A, B are bags of type (Bag E) |
126 |
|
* @param e is a node of Type E |
127 |
|
* @return an inference that represents the following implication |
128 |
|
* (=> |
129 |
|
* true |
130 |
|
* (= |
131 |
|
* (count e skolem) |
132 |
|
* (ite |
133 |
|
* (>= (count e A) (count e B)) |
134 |
|
* (- (count e A) (count e B)) |
135 |
|
* 0)))) |
136 |
|
* where skolem is a fresh variable equals (difference_subtract A B) |
137 |
|
*/ |
138 |
|
InferInfo differenceSubtract(Node n, Node e); |
139 |
|
/** |
140 |
|
* @param n is (difference_remove A B) where A, B are bags of type (Bag E) |
141 |
|
* @param e is a node of Type E |
142 |
|
* @return an inference that represents the following implication |
143 |
|
* (=> |
144 |
|
* true |
145 |
|
* (= |
146 |
|
* (count e skolem) |
147 |
|
* (ite |
148 |
|
* (<= (count e B) 0) |
149 |
|
* (count e A) |
150 |
|
* 0)))) |
151 |
|
* where skolem is a fresh variable equals (difference_remove A B) |
152 |
|
*/ |
153 |
|
InferInfo differenceRemove(Node n, Node e); |
154 |
|
/** |
155 |
|
* @param n is (duplicate_removal A) where A is a bag of type (Bag E) |
156 |
|
* @param e is a node of Type E |
157 |
|
* @return an inference that represents the following implication |
158 |
|
* (=> |
159 |
|
* true |
160 |
|
* (= |
161 |
|
* (count e skolem) |
162 |
|
* (ite (>= (count e A) 1) 1 0)))) |
163 |
|
* where skolem is a fresh variable equals (duplicate_removal A) |
164 |
|
*/ |
165 |
|
InferInfo duplicateRemoval(Node n, Node e); |
166 |
|
/** |
167 |
|
* @param n is (bag.map f A) where f is a function (-> E T), A a bag of type |
168 |
|
* (Bag E) |
169 |
|
* @param e is a node of Type E |
170 |
|
* @return an inference that represents the following implication |
171 |
|
* (and |
172 |
|
* (= (sum 0) 0) |
173 |
|
* (= (sum preImageSize) (bag.count e skolem)) |
174 |
|
* (>= preImageSize 0) |
175 |
|
* (forall ((i Int)) |
176 |
|
* (let ((uf_i (uf i))) |
177 |
|
* (let ((count_uf_i (bag.count uf_i A))) |
178 |
|
* (=> |
179 |
|
* (and (>= i 1) (<= i preImageSize)) |
180 |
|
* (and |
181 |
|
* (= (f uf_i) e) |
182 |
|
* (>= count_uf_i 1) |
183 |
|
* (= (sum i) (+ (sum (- i 1)) count_uf_i)) |
184 |
|
* (forall ((j Int)) |
185 |
|
* (or |
186 |
|
* (not (and (< i j) (<= j preImageSize))) |
187 |
|
* (not (= (uf i) (uf j)))) ) |
188 |
|
* )))))) |
189 |
|
* where uf: Int -> E is an uninterpreted function from integers to the |
190 |
|
* type of the elements of A |
191 |
|
* preImageSize is the cardinality of the distinct elements in A that are |
192 |
|
* mapped to e by function f (i.e., preimage of {e}) |
193 |
|
* sum: Int -> Int is a function that aggregates the multiplicities of the |
194 |
|
* preimage of e, |
195 |
|
* and skolem is a fresh variable equals (bag.map f A)) |
196 |
|
*/ |
197 |
|
std::tuple<InferInfo, Node, Node> mapDownwards(Node n, Node e); |
198 |
|
|
199 |
|
/** |
200 |
|
* @param n is (bag.map f A) where f is a function (-> E T), A a bag of type |
201 |
|
* (Bag E) |
202 |
|
* @param uf is an uninterpreted function Int -> E |
203 |
|
* @param preImageSize is the cardinality of the distinct elements in A that |
204 |
|
* are mapped to y by function f (i.e., preimage of {y}) |
205 |
|
* @param y is an element of type T |
206 |
|
* @param e is an element of type E |
207 |
|
* @return an inference that represents the following implication |
208 |
|
* (=> |
209 |
|
* (>= (bag.count x A) 1) |
210 |
|
* (or |
211 |
|
* (not (= (f x) y) |
212 |
|
* (and |
213 |
|
* (>= skolem 1) |
214 |
|
* (<= skolem preImageSize) |
215 |
|
* (= (uf skolem) x))))) |
216 |
|
* where skolem is a fresh variable |
217 |
|
*/ |
218 |
|
InferInfo mapUpwards(Node n, Node uf, Node preImageSize, Node y, Node x); |
219 |
|
|
220 |
|
/** |
221 |
|
* @param element of type T |
222 |
|
* @param bag of type (bag T) |
223 |
|
* @return a count term (bag.count element bag) |
224 |
|
*/ |
225 |
|
Node getMultiplicityTerm(Node element, Node bag); |
226 |
|
|
227 |
|
private: |
228 |
|
/** generate skolem variable for node n and add it to inferInfo */ |
229 |
|
Node getSkolem(Node& n, InferInfo& inferInfo); |
230 |
|
|
231 |
|
NodeManager* d_nm; |
232 |
|
SkolemManager* d_sm; |
233 |
|
SolverState* d_state; |
234 |
|
/** Pointer to the inference manager */ |
235 |
|
InferenceManager* d_im; |
236 |
|
/** Commonly used constants */ |
237 |
|
Node d_true; |
238 |
|
Node d_zero; |
239 |
|
Node d_one; |
240 |
|
}; |
241 |
|
|
242 |
|
} // namespace bags |
243 |
|
} // namespace theory |
244 |
|
} // namespace cvc5 |
245 |
|
|
246 |
|
#endif /* CVC5__THEORY__BAGS__INFERENCE_GENERATOR_H */ |