1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 |
|
* Relevance manager. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__RELEVANCE_MANAGER__H |
19 |
|
#define CVC5__THEORY__RELEVANCE_MANAGER__H |
20 |
|
|
21 |
|
#include <unordered_map> |
22 |
|
#include <unordered_set> |
23 |
|
|
24 |
|
#include "context/cdlist.h" |
25 |
|
#include "expr/node.h" |
26 |
|
#include "theory/difficulty_manager.h" |
27 |
|
#include "theory/valuation.h" |
28 |
|
|
29 |
|
namespace cvc5 { |
30 |
|
namespace theory { |
31 |
|
|
32 |
|
class TheoryModel; |
33 |
|
|
34 |
|
/** |
35 |
|
* This class manages queries related to relevance of asserted literals. |
36 |
|
* In particular, note the following definition: |
37 |
|
* |
38 |
|
* Let F be a formula, and let L = { l_1, ..., l_n } be a set of |
39 |
|
* literals that propositionally entail it. A "relevant selection of L with |
40 |
|
* respect to F" is a subset of L that also propositionally entails F. |
41 |
|
* |
42 |
|
* This class computes a relevant selection of the current assertion stack |
43 |
|
* at FULL effort with respect to the input formula + theory lemmas that are |
44 |
|
* critical to justify (see LemmaProperty::NEEDS_JUSTIFY). By default, theory |
45 |
|
* lemmas are not critical to justify; in fact, all T-valid theory lemmas |
46 |
|
* are not critical to justify, since they are guaranteed to be satisfied in |
47 |
|
* all inputs. However, some theory lemmas that introduce skolems need |
48 |
|
* justification. |
49 |
|
* |
50 |
|
* As an example of such a lemma, take the example input formula: |
51 |
|
* (and (exists ((x Int)) (P x)) (not (P 0))) |
52 |
|
* A skolemization lemma like the following needs justification: |
53 |
|
* (=> (exists ((x Int)) (P x)) (P k)) |
54 |
|
* Intuitively, this is because the satisfiability of the existential above is |
55 |
|
* being deferred to the satisfiability of (P k) where k is fresh. Thus, |
56 |
|
* a relevant selection must include both (exists ((x Int)) (P x)) and (P k) |
57 |
|
* in this example. |
58 |
|
* |
59 |
|
* Theories are responsible for marking such lemmas using the NEEDS_JUSTIFY |
60 |
|
* property when calling OutputChannel::lemma. |
61 |
|
* |
62 |
|
* Notice that this class has some relation to the justification decision |
63 |
|
* heuristic (--decision=justification), which constructs a relevant selection |
64 |
|
* of the input formula by construction. This class is orthogonal to this |
65 |
|
* method, since it computes relevant selection *after* a full assignment. Thus |
66 |
|
* its main advantage with respect to decision=justification is that it can be |
67 |
|
* used in combination with any SAT decision heuristic. |
68 |
|
* |
69 |
|
* Internally, this class stores the input assertions and can be asked if an |
70 |
|
* asserted literal is part of the current relevant selection. The relevant |
71 |
|
* selection is computed lazily, i.e. only when someone asks if a literal is |
72 |
|
* relevant, and only at most once per FULL effort check. |
73 |
|
*/ |
74 |
18 |
class RelevanceManager |
75 |
|
{ |
76 |
|
typedef context::CDList<Node> NodeList; |
77 |
|
|
78 |
|
public: |
79 |
|
RelevanceManager(context::UserContext* userContext, Valuation val); |
80 |
|
/** |
81 |
|
* Notify (preprocessed) assertions. This is called for input formulas or |
82 |
|
* lemmas that need justification that have been fully processed, just before |
83 |
|
* adding them to the PropEngine. |
84 |
|
*/ |
85 |
|
void notifyPreprocessedAssertions(const std::vector<Node>& assertions); |
86 |
|
/** Singleton version of above */ |
87 |
|
void notifyPreprocessedAssertion(Node n); |
88 |
|
/** |
89 |
|
* Reset round, called at the beginning of a full effort check in |
90 |
|
* TheoryEngine. |
91 |
|
*/ |
92 |
|
void resetRound(); |
93 |
|
/** |
94 |
|
* Is lit part of the current relevant selection? This computes the set of |
95 |
|
* relevant assertions if not already done so. This call is valid during a |
96 |
|
* full effort check in TheoryEngine, or after TheoryEngine has terminated |
97 |
|
* with "sat". This means that theories can query this during FULL or |
98 |
|
* LAST_CALL efforts, through the Valuation class. |
99 |
|
*/ |
100 |
|
bool isRelevant(Node lit); |
101 |
|
/** |
102 |
|
* Get the current relevant selection (see above). This computes this set |
103 |
|
* if not already done so. This call is valid during a full effort check in |
104 |
|
* TheoryEngine, or after TheoryEngine has terminated with "sat". This method |
105 |
|
* sets the flag success to false if we failed to compute relevant |
106 |
|
* assertions, which occurs if the values from the SAT solver do not satisfy |
107 |
|
* the assertions we are notified of. This should never happen. |
108 |
|
* |
109 |
|
* The value of this return is only valid if success was not updated to false. |
110 |
|
*/ |
111 |
|
const std::unordered_set<TNode>& getRelevantAssertions(bool& success); |
112 |
|
/** Notify lemma, for difficulty measurements */ |
113 |
|
void notifyLemma(Node n); |
114 |
|
/** Notify that m is a (candidate) model, for difficulty measurements */ |
115 |
|
void notifyCandidateModel(TheoryModel* m); |
116 |
|
/** |
117 |
|
* Get difficulty map |
118 |
|
*/ |
119 |
|
void getDifficultyMap(std::map<Node, Node>& dmap); |
120 |
|
|
121 |
|
private: |
122 |
|
/** |
123 |
|
* Add the set of assertions to the formulas known to this class. This |
124 |
|
* method handles optimizations such as breaking apart top-level applications |
125 |
|
* of and. |
126 |
|
*/ |
127 |
|
void addAssertionsInternal(std::vector<Node>& toProcess); |
128 |
|
/** compute the relevant selection */ |
129 |
|
void computeRelevance(); |
130 |
|
/** |
131 |
|
* Justify formula n. To "justify" means we have added literals to our |
132 |
|
* relevant selection set (d_rset) whose current values ensure that n |
133 |
|
* evaluates to true or false. |
134 |
|
* |
135 |
|
* This method returns 1 if we justified n to be true, -1 means |
136 |
|
* justified n to be false, 0 means n could not be justified. |
137 |
|
*/ |
138 |
|
int justify(TNode n, std::unordered_map<TNode, int>& cache); |
139 |
|
/** Is the top symbol of cur a Boolean connective? */ |
140 |
|
bool isBooleanConnective(TNode cur); |
141 |
|
/** |
142 |
|
* Update justify last child. This method is a helper function for justify, |
143 |
|
* which is called at the moment that Boolean connective formula cur |
144 |
|
* has a new child that has been computed in the justify cache. |
145 |
|
* |
146 |
|
* @param cur The Boolean connective formula |
147 |
|
* @param childrenJustify The values of the previous children (not including |
148 |
|
* the current one) |
149 |
|
* @param cache The justify cache |
150 |
|
* @return True if we wish to visit the next child. If this is the case, then |
151 |
|
* the justify value of the current child is added to childrenJustify. |
152 |
|
*/ |
153 |
|
bool updateJustifyLastChild(TNode cur, |
154 |
|
std::vector<int>& childrenJustify, |
155 |
|
std::unordered_map<TNode, int>& cache); |
156 |
|
/** The valuation object, used to query current value of theory literals */ |
157 |
|
Valuation d_val; |
158 |
|
/** The input assertions */ |
159 |
|
NodeList d_input; |
160 |
|
/** The current relevant selection. */ |
161 |
|
std::unordered_set<TNode> d_rset; |
162 |
|
/** Have we computed the relevant selection this round? */ |
163 |
|
bool d_computed; |
164 |
|
/** |
165 |
|
* Did we succeed in computing the relevant selection? If this is false, there |
166 |
|
* was a syncronization issue between the input formula and the satisfying |
167 |
|
* assignment since this class found that the input formula was not satisfied |
168 |
|
* by the assignment. This should never happen, but if it does, this class |
169 |
|
* aborts and indicates that all literals are relevant. |
170 |
|
*/ |
171 |
|
bool d_success; |
172 |
|
/** Are we tracking the sources of why a literal is relevant */ |
173 |
|
bool d_trackRSetExp; |
174 |
|
/** |
175 |
|
* Whether we have miniscoped top-level AND of assertions, which is done |
176 |
|
* as an optimization. This is disabled if e.g. we are computing difficulty, |
177 |
|
* which requires preserving the original form of the preprocessed |
178 |
|
* assertions. |
179 |
|
*/ |
180 |
|
bool d_miniscopeTopLevel; |
181 |
|
/** |
182 |
|
* Map from the domain of d_rset to the assertion in d_input that is the |
183 |
|
* reason why that literal is currently relevant. |
184 |
|
*/ |
185 |
|
std::map<TNode, TNode> d_rsetExp; |
186 |
|
/** Difficulty module */ |
187 |
|
std::unique_ptr<DifficultyManager> d_dman; |
188 |
|
}; |
189 |
|
|
190 |
|
} // namespace theory |
191 |
|
} // namespace cvc5 |
192 |
|
|
193 |
|
#endif /* CVC5__THEORY__RELEVANCE_MANAGER__H */ |