1 /********************* */
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Morgan Deters, Mathias Preiner
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief quantifier util
15 #include "cvc4_private.h"
17 #ifndef CVC4__THEORY__QUANT_UTIL_H
18 #define CVC4__THEORY__QUANT_UTIL_H
24 #include "theory/quantifiers/quantifiers_inference_manager.h"
25 #include "theory/quantifiers/quantifiers_registry.h"
26 #include "theory/quantifiers/quantifiers_state.h"
27 #include "theory/theory.h"
28 #include "theory/uf/equality_engine.h"
33 class QuantifiersEngine
;
35 namespace quantifiers
{
40 /** QuantifiersModule class
42 * This is the virtual class for defining subsolvers of the quantifiers theory.
43 * It has a similar interface to a Theory object.
45 class QuantifiersModule
{
47 /** effort levels for quantifiers modules check */
50 // conflict effort, for conflict-based instantiation
52 // standard effort, for heuristic instantiation
54 // model effort, for model-based instantiation
56 // last call effort, for last resort techniques
63 QuantifiersModule(quantifiers::QuantifiersState
& qs
,
64 quantifiers::QuantifiersInferenceManager
& qim
,
65 quantifiers::QuantifiersRegistry
& qr
,
66 QuantifiersEngine
* qe
);
67 virtual ~QuantifiersModule(){}
70 * Called at the beginning of check-sat call.
72 virtual void presolve() {}
75 * Returns true if this module wishes a call to be made
76 * to check(e) during QuantifiersEngine::check(e).
78 virtual bool needsCheck( Theory::Effort e
) { return e
>=Theory::EFFORT_LAST_CALL
; }
81 * Whether this module needs a model built during a
82 * call to QuantifiersEngine::check(e)
83 * It returns one of QEFFORT_* from quantifiers_engine.h,
84 * which specifies the quantifiers effort in which it requires the model to
87 virtual QEffort
needsModel(Theory::Effort e
);
90 * Called at the beginning of QuantifiersEngine::check(e).
92 virtual void reset_round( Theory::Effort e
){}
95 * Called during QuantifiersEngine::check(e) depending
96 * if needsCheck(e) returns true.
98 virtual void check(Theory::Effort e
, QEffort quant_e
) = 0;
101 * Returns false if the module's reasoning was globally incomplete
102 * (e.g. "sat" must be replaced with "incomplete").
104 * This is called just before the quantifiers engine will return
105 * with no lemmas added during a LAST_CALL effort check.
107 virtual bool checkComplete() { return true; }
108 /** Check was complete for quantified formula q
110 * If for each quantified formula q, some module returns true for
111 * checkCompleteFor( q ),
112 * and no lemmas are added by the quantifiers theory, then we may answer
114 * we are incomplete for other reasons.
116 virtual bool checkCompleteFor( Node q
) { return false; }
119 * Called once for new quantified formulas that are registered by the
120 * quantifiers theory. The primary purpose of this function is to establish
121 * if this module is the owner of quantified formula q.
123 virtual void checkOwnership(Node q
) {}
124 /** Register quantifier
126 * Called once for new quantified formulas q that are pre-registered by the
127 * quantifiers theory, after internal ownership of quantified formulas is
128 * finalized. This does context-independent initialization of this module
129 * for quantified formula q.
131 virtual void registerQuantifier(Node q
) {}
132 /** Pre-register quantifier
134 * Called once for new quantified formulas that are
135 * pre-registered by the quantifiers theory, after
136 * internal ownership of quantified formulas is finalized.
138 virtual void preRegisterQuantifier(Node q
) {}
141 * Called when a quantified formula q is asserted to the quantifiers theory
143 virtual void assertNode(Node q
) {}
144 /** Identify this module (for debugging, dynamic configuration, etc..) */
145 virtual std::string
identify() const = 0;
146 //----------------------------general queries
147 /** get currently used the equality engine */
148 eq::EqualityEngine
* getEqualityEngine() const;
149 /** are n1 and n2 equal in the current used equality engine? */
150 bool areEqual(TNode n1
, TNode n2
) const;
151 /** are n1 and n2 disequal in the current used equality engine? */
152 bool areDisequal(TNode n1
, TNode n2
) const;
153 /** get the representative of n in the current used equality engine */
154 TNode
getRepresentative(TNode n
) const;
155 /** get quantifiers engine that owns this module */
156 QuantifiersEngine
* getQuantifiersEngine() const;
157 /** get currently used term database */
158 quantifiers::TermDb
* getTermDatabase() const;
159 /** get currently used term utility object */
160 quantifiers::TermUtil
* getTermUtil() const;
161 /** get the quantifiers state */
162 quantifiers::QuantifiersState
& getState();
163 /** get the quantifiers inference manager */
164 quantifiers::QuantifiersInferenceManager
& getInferenceManager();
165 //----------------------------end general queries
167 /** pointer to the quantifiers engine that owns this module */
168 QuantifiersEngine
* d_quantEngine
;
169 /** The state of the quantifiers engine */
170 quantifiers::QuantifiersState
& d_qstate
;
171 /** The quantifiers inference manager */
172 quantifiers::QuantifiersInferenceManager
& d_qim
;
173 /** The quantifiers registry */
174 quantifiers::QuantifiersRegistry
& d_qreg
;
175 };/* class QuantifiersModule */
177 /** Quantifiers utility
179 * This is a lightweight version of a quantifiers module that does not implement
181 * for checking satisfiability.
183 class QuantifiersUtil
{
186 virtual ~QuantifiersUtil(){}
188 * Called at the beginning of an instantiation round
189 * Returns false if the reset failed. When reset fails, the utility should
190 * have added a lemma via a call to d_qim.addPendingLemma.
192 virtual bool reset( Theory::Effort e
) = 0;
193 /* Called for new quantifiers */
194 virtual void registerQuantifier(Node q
) = 0;
195 /** Identify this module (for debugging, dynamic configuration, etc..) */
196 virtual std::string
identify() const = 0;
199 * Returns false if the utility's reasoning was globally incomplete
200 * (e.g. "sat" must be replaced with "incomplete").
202 virtual bool checkComplete() { return true; }
208 /** helper functions compute phase requirements */
209 void computePhaseReqs( Node n
, bool polarity
, std::map
< Node
, int >& phaseReqs
);
212 QuantPhaseReq( Node n
, bool computeEq
= false );
214 void initialize( Node n
, bool computeEq
);
215 /** is phase required */
216 bool isPhaseReq( Node lit
) { return d_phase_reqs
.find( lit
)!=d_phase_reqs
.end(); }
217 /** get phase requirement */
218 bool getPhaseReq( Node lit
) { return d_phase_reqs
.find( lit
)==d_phase_reqs
.end() ? false : d_phase_reqs
[ lit
]; }
219 /** phase requirements for each quantifier for each instantiation literal */
220 std::map
< Node
, bool > d_phase_reqs
;
221 std::map
< Node
, bool > d_phase_reqs_equality
;
222 std::map
< Node
, Node
> d_phase_reqs_equality_term
;
224 static void getPolarity( Node n
, int child
, bool hasPol
, bool pol
, bool& newHasPol
, bool& newPol
);
225 static void getEntailPolarity( Node n
, int child
, bool hasPol
, bool pol
, bool& newHasPol
, bool& newPol
);
228 /** Types of bounds that can be inferred for quantified formulas */
231 // a variable has a finite bound because it has finite cardinality
233 // a variable has a finite bound because it is in an integer range, e.g.
234 // forall x. u <= x <= l => P(x)
236 // a variable has a finite bound because it is a member of a set, e.g.
237 // forall x. x in S => P(x)
239 // a variable has a finite bound because only a fixed set of terms are
240 // relevant for it in the domain of the quantified formula, e.g.
241 // forall x. ( x = t1 OR ... OR x = tn ) => P(x)
243 // a bound has not been inferred for the variable
249 #endif /* CVC4__THEORY__QUANT_UTIL_H */