1 /********************* */
2 /*! \file quantifiers_engine.h
4 ** Original author: Morgan Deters
5 ** Major contributors: Andrew Reynolds
6 ** Minor contributors (to current version): Francois Bobot
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief Theory instantiator, Instantiation Engine classes
15 #include "cvc4_private.h"
17 #ifndef __CVC4__THEORY__QUANTIFIERS_ENGINE_H
18 #define __CVC4__THEORY__QUANTIFIERS_ENGINE_H
20 #include "theory/theory.h"
21 #include "util/hash.h"
22 #include "theory/quantifiers/inst_match.h"
23 #include "theory/rewriterules/rr_inst_match.h"
24 #include "theory/quantifiers/quant_util.h"
26 #include "util/statistics_registry.h"
28 #include <ext/hash_set>
38 class QuantifiersEngine
;
40 class QuantifiersModule
{
42 QuantifiersEngine
* d_quantEngine
;
44 QuantifiersModule( QuantifiersEngine
* qe
) : d_quantEngine( qe
){}
45 virtual ~QuantifiersModule(){}
46 //get quantifiers engine
47 QuantifiersEngine
* getQuantifiersEngine() { return d_quantEngine
; }
49 virtual void finishInit() {}
50 /* whether this module needs to check this round */
51 virtual bool needsCheck( Theory::Effort e
) { return e
>=Theory::EFFORT_LAST_CALL
; }
52 /* Call during quantifier engine's check */
53 virtual void check( Theory::Effort e
) = 0;
54 /* Called for new quantifiers */
55 virtual void registerQuantifier( Node n
) = 0;
56 virtual void assertNode( Node n
) = 0;
57 virtual void propagate( Theory::Effort level
){}
58 virtual Node
getNextDecisionRequest() { return TNode::null(); }
59 virtual Node
explain(TNode n
) { return TNode::null(); }
60 };/* class QuantifiersModule */
62 namespace quantifiers
{
64 class FirstOrderModel
;
66 class InstantiationEngine
;
68 class BoundedIntegers
;
70 }/* CVC4::theory::quantifiers */
74 }/* CVC4::theory::inst */
78 }/* CVC4::theory::inst */
80 class EfficientEMatcher
;
81 class EqualityQueryQuantifiersEngine
;
83 class QuantifiersEngine
{
84 friend class quantifiers::InstantiationEngine
;
85 friend class quantifiers::ModelEngine
;
86 friend class quantifiers::RewriteEngine
;
87 friend class inst::InstMatch
;
89 typedef context::CDHashMap
< Node
, bool, NodeHashFunction
> BoolMap
;
90 /** reference to theory engine object */
92 /** vector of modules for quantifiers */
93 std::vector
< QuantifiersModule
* > d_modules
;
94 /** equality query class */
95 EqualityQueryQuantifiersEngine
* d_eq_query
;
96 /** for computing relevance of quantifiers */
97 QuantRelevance d_quant_rel
;
98 /** phase requirements for each quantifier for each instantiation literal */
99 std::map
< Node
, QuantPhaseReq
* > d_phase_reqs
;
100 /** efficient e-matcher */
101 EfficientEMatcher
* d_eem
;
102 /** instantiation engine */
103 quantifiers::InstantiationEngine
* d_inst_engine
;
105 quantifiers::ModelEngine
* d_model_engine
;
106 /** bounded integers utility */
107 quantifiers::BoundedIntegers
* d_bint
;
108 /** rewrite rules utility */
109 quantifiers::RewriteEngine
* d_rr_engine
;
111 /** list of all quantifiers seen */
112 std::vector
< Node
> d_quants
;
113 /** list of all lemmas produced */
114 //std::map< Node, bool > d_lemmas_produced;
115 BoolMap d_lemmas_produced_c
;
116 /** lemmas waiting */
117 std::vector
< Node
> d_lemmas_waiting
;
118 /** has added lemma this round */
119 bool d_hasAddedLemma
;
120 /** list of all instantiations produced for each quantifier */
121 std::map
< Node
, inst::CDInstMatchTrie
* > d_inst_match_trie
;
123 quantifiers::TermDb
* d_term_db
;
124 /** all triggers will be stored in this trie */
125 inst::TriggerTrie
* d_tr_trie
;
126 /** all triggers for rewrite rules will be stored in this trie */
127 rrinst::TriggerTrie
* d_rr_tr_trie
;
128 /** extended model object */
129 quantifiers::FirstOrderModel
* d_model
;
130 /** statistics for debugging */
131 std::map
< Node
, int > d_total_inst_debug
;
132 std::map
< Node
, int > d_temp_inst_debug
;
133 int d_total_inst_count_debug
;
135 KEEP_STATISTIC(TimerStat
, d_time
, "theory::QuantifiersEngine::time");
137 QuantifiersEngine(context::Context
* c
, context::UserContext
* u
, TheoryEngine
* te
);
138 ~QuantifiersEngine();
139 /** get instantiator for id */
140 //Instantiator* getInstantiator( theory::TheoryId id );
141 /** get theory engine */
142 TheoryEngine
* getTheoryEngine() { return d_te
; }
143 /** get equality query object for the given type. The default is the
145 EqualityQueryQuantifiersEngine
* getEqualityQuery();
146 /** get instantiation engine */
147 quantifiers::InstantiationEngine
* getInstantiationEngine() { return d_inst_engine
; }
148 /** get model engine */
149 quantifiers::ModelEngine
* getModelEngine() { return d_model_engine
; }
150 /** get default sat context for quantifiers engine */
151 context::Context
* getSatContext();
152 /** get default sat context for quantifiers engine */
153 context::Context
* getUserContext();
154 /** get default output channel for the quantifiers engine */
155 OutputChannel
& getOutputChannel();
156 /** get default valuation for the quantifiers engine */
157 Valuation
& getValuation();
158 /** get quantifier relevance */
159 QuantRelevance
* getQuantifierRelevance() { return &d_quant_rel
; }
160 /** get phase requirement information */
161 QuantPhaseReq
* getPhaseRequirements( Node f
) { return d_phase_reqs
.find( f
)==d_phase_reqs
.end() ? NULL
: d_phase_reqs
[f
]; }
162 /** get phase requirement terms */
163 void getPhaseReqTerms( Node f
, std::vector
< Node
>& nodes
);
164 /** get efficient e-matching utility */
165 EfficientEMatcher
* getEfficientEMatcher() { return d_eem
; }
166 /** get bounded integers utility */
167 quantifiers::BoundedIntegers
* getBoundedIntegers() { return d_bint
; }
171 /** check at level */
172 void check( Theory::Effort e
);
173 /** register quantifier */
174 void registerQuantifier( Node f
);
175 /** register quantifier */
176 void registerPattern( std::vector
<Node
> & pattern
);
177 /** assert universal quantifier */
178 void assertNode( Node f
);
180 void propagate( Theory::Effort level
);
181 /** get next decision request */
182 Node
getNextDecisionRequest();
184 /** compute term vector */
185 void computeTermVector( Node f
, InstMatch
& m
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
);
186 /** instantiate f with arguments terms */
187 bool addInstantiation( Node f
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
);
188 /** set instantiation level attr */
189 void setInstantiationLevelAttr( Node n
, uint64_t level
);
190 /** do substitution */
191 Node
doSubstitute( Node n
, std::vector
< Node
>& terms
);
193 /** get instantiation */
194 Node
getInstantiation( Node f
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
);
195 /** get instantiation */
196 Node
getInstantiation( Node f
, InstMatch
& m
);
197 /** exist instantiation ? */
198 bool existsInstantiation( Node f
, InstMatch
& m
, bool modEq
= true, bool modInst
= false );
200 bool addLemma( Node lem
);
201 /** do instantiation specified by m */
202 bool addInstantiation( Node f
, InstMatch
& m
, bool modEq
= true, bool modInst
= false, bool mkRep
= true );
203 /** split on node n */
204 bool addSplit( Node n
, bool reqPhase
= false, bool reqPhasePol
= true );
205 /** add split equality */
206 bool addSplitEquality( Node n1
, Node n2
, bool reqPhase
= false, bool reqPhasePol
= true );
207 /** has added lemma */
208 bool hasAddedLemma() { return !d_lemmas_waiting
.empty() || d_hasAddedLemma
; }
210 void flushLemmas( OutputChannel
* out
);
211 /** get number of waiting lemmas */
212 int getNumLemmasWaiting() { return (int)d_lemmas_waiting
.size(); }
214 /** get number of quantifiers */
215 int getNumQuantifiers() { return (int)d_quants
.size(); }
216 /** get quantifier */
217 Node
getQuantifier( int i
) { return d_quants
[i
]; }
220 quantifiers::FirstOrderModel
* getModel() { return d_model
; }
221 /** get term database */
222 quantifiers::TermDb
* getTermDatabase() { return d_term_db
; }
223 /** get trigger database */
224 inst::TriggerTrie
* getTriggerDatabase() { return d_tr_trie
; }
225 /** get rewrite trigger database */
226 rrinst::TriggerTrie
* getRRTriggerDatabase() { return d_rr_tr_trie
; }
227 /** add term to database */
228 void addTermToDatabase( Node n
, bool withinQuant
= false );
229 /** get the master equality engine */
230 eq::EqualityEngine
* getMasterEqualityEngine() ;
232 /** statistics class */
236 IntStat d_instantiation_rounds
;
237 IntStat d_instantiation_rounds_lc
;
238 IntStat d_instantiations
;
239 IntStat d_inst_duplicate
;
240 IntStat d_inst_duplicate_eq
;
241 IntStat d_lit_phase_req
;
242 IntStat d_lit_phase_nreq
;
244 IntStat d_simple_triggers
;
245 IntStat d_multi_triggers
;
246 IntStat d_multi_trigger_instantiations
;
247 IntStat d_term_in_termdb
;
248 IntStat d_num_mono_candidates
;
249 IntStat d_num_mono_candidates_new_term
;
250 IntStat d_num_multi_candidates
;
251 IntStat d_mono_candidates_cache_hit
;
252 IntStat d_mono_candidates_cache_miss
;
253 IntStat d_multi_candidates_cache_hit
;
254 IntStat d_multi_candidates_cache_miss
;
257 };/* class QuantifiersEngine::Statistics */
258 Statistics d_statistics
;
261 bool d_optInstCheckDuplicate
;
262 bool d_optInstMakeRepresentative
;
263 bool d_optInstAddSplits
;
264 bool d_optMatchIgnoreModelBasis
;
265 bool d_optInstLimitActive
;
267 };/* class QuantifiersEngine */
271 /** equality query object using theory engine */
272 class EqualityQueryQuantifiersEngine
: public EqualityQuery
275 /** pointer to theory engine */
276 QuantifiersEngine
* d_qe
;
277 /** internal representatives */
278 std::map
< Node
, Node
> d_int_rep
;
280 std::map
< Node
, int > d_rep_score
;
287 Node
getInstance( Node n
, std::vector
< Node
>& eqc
);
289 int getRepScore( Node n
, Node f
, int index
);
291 EqualityQueryQuantifiersEngine( QuantifiersEngine
* qe
) : d_qe( qe
), d_reset_count( 0 ), d_liberal( false ){}
292 ~EqualityQueryQuantifiersEngine(){}
295 /** general queries about equality */
296 bool hasTerm( Node a
);
297 Node
getRepresentative( Node a
);
298 bool areEqual( Node a
, Node b
);
299 bool areDisequal( Node a
, Node b
);
300 eq::EqualityEngine
* getEngine();
301 void getEquivalenceClass( Node a
, std::vector
< Node
>& eqc
);
302 /** getInternalRepresentative gets the current best representative in the equivalence class of a, based on some criteria.
303 If cbqi is active, this will return a term in the equivalence class of "a" that does
304 not contain instantiation constants, if such a term exists.
306 Node
getInternalRepresentative( Node a
, Node f
, int index
);
307 /** flatten representatives */
308 void flattenRepresentatives( std::map
< TypeNode
, std::vector
< Node
> >& reps
);
310 void setLiberal( bool l
) { d_liberal
= l
; }
311 }; /* EqualityQueryQuantifiersEngine */
313 }/* CVC4::theory namespace */
314 }/* CVC4 namespace */
316 #endif /* __CVC4__THEORY__QUANTIFIERS_ENGINE_H */