1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Kshitij Bansal, Mudathir Mohamed |
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 |
|
* Sets theory implementation. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__SETS__THEORY_SETS_PRIVATE_H |
19 |
|
#define CVC5__THEORY__SETS__THEORY_SETS_PRIVATE_H |
20 |
|
|
21 |
|
#include "context/cdhashset.h" |
22 |
|
#include "context/cdqueue.h" |
23 |
|
#include "expr/node_trie.h" |
24 |
|
#include "theory/sets/cardinality_extension.h" |
25 |
|
#include "theory/sets/inference_manager.h" |
26 |
|
#include "theory/sets/solver_state.h" |
27 |
|
#include "theory/sets/term_registry.h" |
28 |
|
#include "theory/sets/theory_sets_rels.h" |
29 |
|
#include "theory/sets/theory_sets_rewriter.h" |
30 |
|
#include "theory/theory.h" |
31 |
|
#include "theory/uf/equality_engine.h" |
32 |
|
|
33 |
|
namespace cvc5 { |
34 |
|
namespace theory { |
35 |
|
namespace sets { |
36 |
|
|
37 |
|
/** Internal classes, forward declared here */ |
38 |
|
class TheorySets; |
39 |
|
|
40 |
|
class TheorySetsPrivate { |
41 |
|
typedef context::CDHashMap<Node, bool> NodeBoolMap; |
42 |
|
typedef context::CDHashSet<Node> NodeSet; |
43 |
|
|
44 |
|
public: |
45 |
|
void eqNotifyNewClass(TNode t); |
46 |
|
void eqNotifyMerge(TNode t1, TNode t2); |
47 |
|
void eqNotifyDisequal(TNode t1, TNode t2, TNode reason); |
48 |
|
|
49 |
|
private: |
50 |
|
/** Are a and b trigger terms in the equality engine that may be disequal? */ |
51 |
|
bool areCareDisequal(Node a, Node b); |
52 |
|
/** |
53 |
|
* Invoke the decision procedure for this theory, which is run at |
54 |
|
* full effort. This will either send a lemma or conflict on the output |
55 |
|
* channel of this class, or otherwise the current set of constraints is |
56 |
|
* satisfiable w.r.t. the theory of sets. |
57 |
|
*/ |
58 |
|
void fullEffortCheck(); |
59 |
|
/** |
60 |
|
* Reset the information for a full effort check. |
61 |
|
*/ |
62 |
|
void fullEffortReset(); |
63 |
|
/** |
64 |
|
* This implements an inference schema based on the "downwards closure" of |
65 |
|
* set membership. This roughly corresponds to the rules UNION DOWN I and II, |
66 |
|
* INTER DOWN I and II from Bansal et al IJCAR 2016, as well as rules for set |
67 |
|
* difference. |
68 |
|
*/ |
69 |
|
void checkDownwardsClosure(); |
70 |
|
/** |
71 |
|
* This implements an inference schema based on the "upwards closure" of |
72 |
|
* set membership. This roughly corresponds to the rules UNION UP, INTER |
73 |
|
* UP I and II from Bansal et al IJCAR 2016, as well as rules for set |
74 |
|
* difference. |
75 |
|
*/ |
76 |
|
void checkUpwardsClosure(); |
77 |
|
/** |
78 |
|
* This implements a strategy for splitting for set disequalities which |
79 |
|
* roughly corresponds the SET DISEQUALITY rule from Bansal et al IJCAR 2016. |
80 |
|
*/ |
81 |
|
void checkDisequalities(); |
82 |
|
/** |
83 |
|
* Check comprehensions. This adds reduction lemmas for all set comprehensions |
84 |
|
* in the current context. |
85 |
|
*/ |
86 |
|
void checkReduceComprehensions(); |
87 |
|
|
88 |
|
void addCarePairs(TNodeTrie* t1, |
89 |
|
TNodeTrie* t2, |
90 |
|
unsigned arity, |
91 |
|
unsigned depth, |
92 |
|
unsigned& n_pairs); |
93 |
|
|
94 |
|
Node d_true; |
95 |
|
Node d_false; |
96 |
|
Node d_zero; |
97 |
|
NodeBoolMap d_deq; |
98 |
|
/** |
99 |
|
* The set of terms that we have reduced via a lemma in the current user |
100 |
|
* context. |
101 |
|
*/ |
102 |
|
NodeSet d_termProcessed; |
103 |
|
|
104 |
|
//propagation |
105 |
|
class EqcInfo |
106 |
|
{ |
107 |
|
public: |
108 |
|
EqcInfo( context::Context* c ); |
109 |
4883 |
~EqcInfo(){} |
110 |
|
// singleton or emptyset equal to this eqc |
111 |
|
context::CDO< Node > d_singleton; |
112 |
|
}; |
113 |
|
/** information necessary for equivalence classes */ |
114 |
|
std::map< Node, EqcInfo* > d_eqc_info; |
115 |
|
/** get or make eqc info */ |
116 |
|
EqcInfo* getOrMakeEqcInfo( TNode n, bool doMake = false ); |
117 |
|
|
118 |
|
/** full check incomplete |
119 |
|
* |
120 |
|
* This flag is set to true during a full effort check if this theory |
121 |
|
* is incomplete for some reason (for instance, if we combine cardinality |
122 |
|
* with a relation or extended function kind). |
123 |
|
*/ |
124 |
|
bool d_fullCheckIncomplete; |
125 |
|
/** The reason we set the above flag to true */ |
126 |
|
IncompleteId d_fullCheckIncompleteId; |
127 |
|
std::map< Node, TypeNode > d_most_common_type; |
128 |
|
std::map< Node, Node > d_most_common_type_term; |
129 |
|
|
130 |
|
public: |
131 |
|
|
132 |
|
/** |
133 |
|
* Constructs a new instance of TheorySetsPrivate w.r.t. the provided |
134 |
|
* contexts. |
135 |
|
*/ |
136 |
|
TheorySetsPrivate(TheorySets& external, |
137 |
|
SolverState& state, |
138 |
|
InferenceManager& im, |
139 |
|
SkolemCache& skc, |
140 |
|
ProofNodeManager* pnm); |
141 |
|
|
142 |
|
~TheorySetsPrivate(); |
143 |
|
|
144 |
9926 |
TheoryRewriter* getTheoryRewriter() { return &d_rewriter; } |
145 |
|
|
146 |
|
/** Get the solver state */ |
147 |
|
SolverState* getSolverState() { return &d_state; } |
148 |
|
|
149 |
|
/** |
150 |
|
* Finish initialize, called after the equality engine of theory sets has |
151 |
|
* been determined. |
152 |
|
*/ |
153 |
|
void finishInit(); |
154 |
|
|
155 |
|
//--------------------------------- standard check |
156 |
|
/** Post-check, called after the fact queue of the theory is processed. */ |
157 |
|
void postCheck(Theory::Effort level); |
158 |
|
/** Notify new fact */ |
159 |
|
void notifyFact(TNode atom, bool polarity, TNode fact); |
160 |
|
//--------------------------------- end standard check |
161 |
|
|
162 |
|
/** Collect model values in m based on the relevant terms given by termSet */ |
163 |
|
void addSharedTerm(TNode); |
164 |
|
bool collectModelValues(TheoryModel* m, const std::set<Node>& termSet); |
165 |
|
|
166 |
|
void computeCareGraph(); |
167 |
|
|
168 |
|
Node explain(TNode); |
169 |
|
|
170 |
|
void preRegisterTerm(TNode node); |
171 |
|
|
172 |
|
/** ppRewrite, which expands choose and is_singleton. */ |
173 |
|
TrustNode ppRewrite(Node n, std::vector<SkolemLemma>& lems); |
174 |
|
|
175 |
|
void presolve(); |
176 |
|
|
177 |
|
/** get the valuation */ |
178 |
|
Valuation& getValuation(); |
179 |
|
private: |
180 |
|
TheorySets& d_external; |
181 |
|
/** The state of the sets solver at full effort */ |
182 |
|
SolverState& d_state; |
183 |
|
/** The inference manager of the sets solver */ |
184 |
|
InferenceManager& d_im; |
185 |
|
/** Reference to the skolem cache */ |
186 |
|
SkolemCache& d_skCache; |
187 |
|
/** The term registry */ |
188 |
|
TermRegistry d_treg; |
189 |
|
|
190 |
|
/** Pointer to the equality engine of theory of sets */ |
191 |
|
eq::EqualityEngine* d_equalityEngine; |
192 |
|
|
193 |
|
bool isCareArg( Node n, unsigned a ); |
194 |
|
|
195 |
|
public: |
196 |
|
/** Is formula n entailed to have polarity pol in the current context? */ |
197 |
|
bool isEntailed(Node n, bool pol) { return d_state.isEntailed(n, pol); } |
198 |
|
|
199 |
|
private: |
200 |
|
/** get choose function |
201 |
|
* |
202 |
|
* Returns the existing uninterpreted function for the choose operator for the |
203 |
|
* given set type, or creates a new one if it does not exist. |
204 |
|
*/ |
205 |
|
Node getChooseFunction(const TypeNode& setType); |
206 |
|
/** expand the definition of the choose operator */ |
207 |
|
TrustNode expandChooseOperator(const Node& node, |
208 |
|
std::vector<SkolemLemma>& lems); |
209 |
|
/** expand the definition of is_singleton operator */ |
210 |
|
TrustNode expandIsSingletonOperator(const Node& node); |
211 |
|
/** subtheory solver for the theory of relations */ |
212 |
|
std::unique_ptr<TheorySetsRels> d_rels; |
213 |
|
/** subtheory solver for the theory of sets with cardinality */ |
214 |
|
std::unique_ptr<CardinalityExtension> d_cardSolver; |
215 |
|
/** are relations enabled? |
216 |
|
* |
217 |
|
* This flag is set to true during a full effort check if any constraint |
218 |
|
* involving relational constraints is asserted to this theory. |
219 |
|
*/ |
220 |
|
bool d_rels_enabled; |
221 |
|
/** is cardinality enabled? |
222 |
|
* |
223 |
|
* This flag is set to true during a full effort check if any constraint |
224 |
|
* involving cardinality constraints is asserted to this theory. |
225 |
|
*/ |
226 |
|
bool d_card_enabled; |
227 |
|
|
228 |
|
/** The theory rewriter for this theory. */ |
229 |
|
TheorySetsRewriter d_rewriter; |
230 |
|
|
231 |
|
/** a map that stores the choose functions for set types */ |
232 |
|
std::map<TypeNode, Node> d_chooseFunctions; |
233 |
|
|
234 |
|
/** a map that maps each set to an existential quantifier generated for |
235 |
|
* operator is_singleton */ |
236 |
|
std::map<Node, Node> d_isSingletonNodes; |
237 |
|
};/* class TheorySetsPrivate */ |
238 |
|
|
239 |
|
} // namespace sets |
240 |
|
} // namespace theory |
241 |
|
} // namespace cvc5 |
242 |
|
|
243 |
|
#endif /* CVC5__THEORY__SETS__THEORY_SETS_PRIVATE_H */ |