1 /********************* */
2 /*! \file quantifiers_engine.h
4 ** Original author: ajreynol
5 ** Major contributors: none
6 ** Minor contributors (to current version): mdeters, bobot
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009-2012 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
; }
48 /* whether this module needs to check this round */
49 virtual bool needsCheck( Theory::Effort e
) { return e
>=Theory::EFFORT_LAST_CALL
; }
50 /* Call during quantifier engine's check */
51 virtual void check( Theory::Effort e
) = 0;
52 /* Called for new quantifiers */
53 virtual void registerQuantifier( Node n
) = 0;
54 virtual void assertNode( Node n
) = 0;
55 virtual void propagate( Theory::Effort level
){}
56 virtual Node
getNextDecisionRequest() { return TNode::null(); }
57 virtual Node
explain(TNode n
) = 0;
58 };/* class QuantifiersModule */
60 namespace quantifiers
{
61 class InstantiationEngine
;
64 class FirstOrderModel
;
65 }/* CVC4::theory::quantifiers */
69 }/* CVC4::theory::inst */
73 }/* CVC4::theory::inst */
75 class EfficientEMatcher
;
76 class EqualityQueryQuantifiersEngine
;
78 class QuantifiersEngine
{
79 friend class quantifiers::InstantiationEngine
;
80 friend class quantifiers::ModelEngine
;
81 friend class inst::InstMatch
;
83 typedef context::CDHashMap
< Node
, bool, NodeHashFunction
> BoolMap
;
84 /** reference to theory engine object */
86 /** vector of modules for quantifiers */
87 std::vector
< QuantifiersModule
* > d_modules
;
88 /** instantiation engine */
89 quantifiers::InstantiationEngine
* d_inst_engine
;
91 quantifiers::ModelEngine
* d_model_engine
;
92 /** equality query class */
93 EqualityQueryQuantifiersEngine
* d_eq_query
;
94 /** for computing relevance of quantifiers */
95 QuantRelevance d_quant_rel
;
96 /** phase requirements for each quantifier for each instantiation literal */
97 std::map
< Node
, QuantPhaseReq
* > d_phase_reqs
;
98 /** efficient e-matcher */
99 EfficientEMatcher
* d_eem
;
101 /** list of all quantifiers seen */
102 std::vector
< Node
> d_quants
;
103 /** list of all lemmas produced */
104 std::map
< Node
, bool > d_lemmas_produced
;
105 /** lemmas waiting */
106 std::vector
< Node
> d_lemmas_waiting
;
107 /** has added lemma this round */
108 bool d_hasAddedLemma
;
109 /** list of all instantiations produced for each quantifier */
110 std::map
< Node
, inst::InstMatchTrie
> d_inst_match_trie
;
112 quantifiers::TermDb
* d_term_db
;
113 /** all triggers will be stored in this trie */
114 inst::TriggerTrie
* d_tr_trie
;
115 /** all triggers for rewrite rules will be stored in this trie */
116 rrinst::TriggerTrie
* d_rr_tr_trie
;
117 /** extended model object */
118 quantifiers::FirstOrderModel
* d_model
;
120 KEEP_STATISTIC(TimerStat
, d_time
, "theory::QuantifiersEngine::time");
122 QuantifiersEngine(context::Context
* c
, TheoryEngine
* te
);
123 ~QuantifiersEngine();
124 /** get instantiator for id */
125 Instantiator
* getInstantiator( theory::TheoryId id
);
126 /** get theory engine */
127 TheoryEngine
* getTheoryEngine() { return d_te
; }
128 /** get equality query object for the given type. The default is the
130 EqualityQuery
* getEqualityQuery();
131 /** get instantiation engine */
132 quantifiers::InstantiationEngine
* getInstantiationEngine() { return d_inst_engine
; }
133 /** get model engine */
134 quantifiers::ModelEngine
* getModelEngine() { return d_model_engine
; }
135 /** get default sat context for quantifiers engine */
136 context::Context
* getSatContext();
137 /** get default output channel for the quantifiers engine */
138 OutputChannel
& getOutputChannel();
139 /** get default valuation for the quantifiers engine */
140 Valuation
& getValuation();
141 /** get quantifier relevance */
142 QuantRelevance
* getQuantifierRelevance() { return &d_quant_rel
; }
143 /** get phase requirement information */
144 QuantPhaseReq
* getPhaseRequirements( Node f
) { return d_phase_reqs
.find( f
)==d_phase_reqs
.end() ? NULL
: d_phase_reqs
[f
]; }
145 /** get phase requirement terms */
146 void getPhaseReqTerms( Node f
, std::vector
< Node
>& nodes
);
147 /** get efficient e-matching utility */
148 EfficientEMatcher
* getEfficientEMatcher() { return d_eem
; }
150 /** check at level */
151 void check( Theory::Effort e
);
152 /** register quantifier */
153 void registerQuantifier( Node f
);
154 /** register quantifier */
155 void registerPattern( std::vector
<Node
> & pattern
);
156 /** assert universal quantifier */
157 void assertNode( Node f
);
159 void propagate( Theory::Effort level
);
160 /** get next decision request */
161 Node
getNextDecisionRequest();
163 /** compute term vector */
164 void computeTermVector( Node f
, InstMatch
& m
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
);
165 /** instantiate f with arguments terms */
166 bool addInstantiation( Node f
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
);
167 /** set instantiation level attr */
168 void setInstantiationLevelAttr( Node n
, uint64_t level
);
170 /** get instantiation */
171 Node
getInstantiation( Node f
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
);
172 /** get instantiation */
173 Node
getInstantiation( Node f
, InstMatch
& m
);
174 /** exist instantiation ? */
175 bool existsInstantiation( Node f
, InstMatch
& m
, bool modEq
= true, bool modInst
= false );
177 bool addLemma( Node lem
);
178 /** do instantiation specified by m */
179 bool addInstantiation( Node f
, InstMatch
& m
, bool modEq
= true, bool modInst
= false, bool mkRep
= true );
180 /** split on node n */
181 bool addSplit( Node n
, bool reqPhase
= false, bool reqPhasePol
= true );
182 /** add split equality */
183 bool addSplitEquality( Node n1
, Node n2
, bool reqPhase
= false, bool reqPhasePol
= true );
184 /** has added lemma */
185 bool hasAddedLemma() { return !d_lemmas_waiting
.empty() || d_hasAddedLemma
; }
187 void flushLemmas( OutputChannel
* out
);
188 /** get number of waiting lemmas */
189 int getNumLemmasWaiting() { return (int)d_lemmas_waiting
.size(); }
191 /** get number of quantifiers */
192 int getNumQuantifiers() { return (int)d_quants
.size(); }
193 /** get quantifier */
194 Node
getQuantifier( int i
) { return d_quants
[i
]; }
197 quantifiers::FirstOrderModel
* getModel() { return d_model
; }
198 /** get term database */
199 quantifiers::TermDb
* getTermDatabase() { return d_term_db
; }
200 /** get trigger database */
201 inst::TriggerTrie
* getTriggerDatabase() { return d_tr_trie
; }
202 /** get rewrite trigger database */
203 rrinst::TriggerTrie
* getRRTriggerDatabase() { return d_rr_tr_trie
; }
204 /** add term to database */
205 void addTermToDatabase( Node n
, bool withinQuant
= false );
207 /** statistics class */
211 IntStat d_instantiation_rounds
;
212 IntStat d_instantiation_rounds_lc
;
213 IntStat d_instantiations
;
214 IntStat d_max_instantiation_level
;
216 IntStat d_total_inst_var
;
217 IntStat d_total_inst_var_unspec
;
218 IntStat d_inst_unspec
;
219 IntStat d_inst_duplicate
;
220 IntStat d_lit_phase_req
;
221 IntStat d_lit_phase_nreq
;
223 IntStat d_simple_triggers
;
224 IntStat d_multi_triggers
;
225 IntStat d_multi_trigger_instantiations
;
226 IntStat d_term_in_termdb
;
227 IntStat d_num_mono_candidates
;
228 IntStat d_num_mono_candidates_new_term
;
229 IntStat d_num_multi_candidates
;
230 IntStat d_mono_candidates_cache_hit
;
231 IntStat d_mono_candidates_cache_miss
;
232 IntStat d_multi_candidates_cache_hit
;
233 IntStat d_multi_candidates_cache_miss
;
236 };/* class QuantifiersEngine::Statistics */
237 Statistics d_statistics
;
240 bool d_optInstCheckDuplicate
;
241 bool d_optInstMakeRepresentative
;
242 bool d_optInstAddSplits
;
243 bool d_optMatchIgnoreModelBasis
;
244 bool d_optInstLimitActive
;
246 };/* class QuantifiersEngine */
250 /** equality query object using theory engine */
251 class EqualityQueryQuantifiersEngine
: public EqualityQuery
254 /** pointer to theory engine */
255 QuantifiersEngine
* d_qe
;
256 /** internal representatives */
257 std::map
< Node
, Node
> d_int_rep
;
259 std::map
< Node
, int > d_rep_score
;
264 Node
getInstance( Node n
, std::vector
< Node
>& eqc
);
266 int getRepScore( Node n
);
268 EqualityQueryQuantifiersEngine( QuantifiersEngine
* qe
) : d_qe( qe
), d_reset_count( 0 ){}
269 ~EqualityQueryQuantifiersEngine(){}
272 /** general queries about equality */
273 bool hasTerm( Node a
);
274 Node
getRepresentative( Node a
);
275 bool areEqual( Node a
, Node b
);
276 bool areDisequal( Node a
, Node b
);
277 eq::EqualityEngine
* getEngine();
278 void getEquivalenceClass( Node a
, std::vector
< Node
>& eqc
);
279 /** getInternalRepresentative gets the current best representative in the equivalence class of a, based on some criteria.
280 If cbqi is active, this will return a term in the equivalence class of "a" that does
281 not contain instantiation constants, if such a term exists.
283 Node
getInternalRepresentative( Node a
);
284 }; /* EqualityQueryQuantifiersEngine */
286 }/* CVC4::theory namespace */
287 }/* CVC4 namespace */
289 #endif /* __CVC4__THEORY__QUANTIFIERS_ENGINE_H */