Remove equality inference option for quantifiers (#3282)
[cvc5.git] / src / theory / quantifiers_engine.cpp
1 /********************* */
2 /*! \file quantifiers_engine.cpp
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Morgan Deters, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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
11 **
12 ** \brief Implementation of quantifiers engine class
13 **/
14
15 #include "theory/quantifiers_engine.h"
16
17 #include "options/quantifiers_options.h"
18 #include "options/uf_options.h"
19 #include "smt/smt_statistics_registry.h"
20 #include "theory/quantifiers/alpha_equivalence.h"
21 #include "theory/quantifiers/anti_skolem.h"
22 #include "theory/quantifiers/conjecture_generator.h"
23 #include "theory/quantifiers/ematching/instantiation_engine.h"
24 #include "theory/quantifiers/fmf/bounded_integers.h"
25 #include "theory/quantifiers/fmf/full_model_check.h"
26 #include "theory/quantifiers/fmf/model_engine.h"
27 #include "theory/quantifiers/inst_propagator.h"
28 #include "theory/quantifiers/inst_strategy_enumerative.h"
29 #include "theory/quantifiers/local_theory_ext.h"
30 #include "theory/quantifiers/quant_conflict_find.h"
31 #include "theory/quantifiers/quant_split.h"
32 #include "theory/quantifiers/quantifiers_rewriter.h"
33 #include "theory/quantifiers/rewrite_engine.h"
34 #include "theory/quantifiers/sygus/synth_engine.h"
35 #include "theory/sep/theory_sep.h"
36 #include "theory/theory_engine.h"
37 #include "theory/uf/equality_engine.h"
38
39 using namespace std;
40 using namespace CVC4::kind;
41
42 namespace CVC4 {
43 namespace theory {
44
45 class QuantifiersEnginePrivate
46 {
47 public:
48 QuantifiersEnginePrivate()
49 : d_inst_prop(nullptr),
50 d_alpha_equiv(nullptr),
51 d_inst_engine(nullptr),
52 d_model_engine(nullptr),
53 d_bint(nullptr),
54 d_qcf(nullptr),
55 d_rr_engine(nullptr),
56 d_sg_gen(nullptr),
57 d_synth_e(nullptr),
58 d_lte_part_inst(nullptr),
59 d_fs(nullptr),
60 d_i_cbqi(nullptr),
61 d_qsplit(nullptr),
62 d_anti_skolem(nullptr)
63 {
64 }
65 ~QuantifiersEnginePrivate() {}
66 //------------------------------ private quantifier utilities
67 /** quantifiers instantiation propagator */
68 std::unique_ptr<quantifiers::InstPropagator> d_inst_prop;
69 //------------------------------ end private quantifier utilities
70 //------------------------------ quantifiers modules
71 /** alpha equivalence */
72 std::unique_ptr<quantifiers::AlphaEquivalence> d_alpha_equiv;
73 /** instantiation engine */
74 std::unique_ptr<quantifiers::InstantiationEngine> d_inst_engine;
75 /** model engine */
76 std::unique_ptr<quantifiers::ModelEngine> d_model_engine;
77 /** bounded integers utility */
78 std::unique_ptr<quantifiers::BoundedIntegers> d_bint;
79 /** Conflict find mechanism for quantifiers */
80 std::unique_ptr<quantifiers::QuantConflictFind> d_qcf;
81 /** rewrite rules utility */
82 std::unique_ptr<quantifiers::RewriteEngine> d_rr_engine;
83 /** subgoal generator */
84 std::unique_ptr<quantifiers::ConjectureGenerator> d_sg_gen;
85 /** ceg instantiation */
86 std::unique_ptr<quantifiers::SynthEngine> d_synth_e;
87 /** lte partial instantiation */
88 std::unique_ptr<quantifiers::LtePartialInst> d_lte_part_inst;
89 /** full saturation */
90 std::unique_ptr<quantifiers::InstStrategyEnum> d_fs;
91 /** counterexample-based quantifier instantiation */
92 std::unique_ptr<quantifiers::InstStrategyCegqi> d_i_cbqi;
93 /** quantifiers splitting */
94 std::unique_ptr<quantifiers::QuantDSplit> d_qsplit;
95 /** quantifiers anti-skolemization */
96 std::unique_ptr<quantifiers::QuantAntiSkolem> d_anti_skolem;
97 //------------------------------ end quantifiers modules
98 /** initialize
99 *
100 * This constructs the above modules based on the current options. It adds
101 * a pointer to each module it constructs to modules. This method sets
102 * needsBuilder to true if we require a strategy-specific model builder
103 * utility, and needsRelDom to true if we require the relevant domain
104 * utility.
105 */
106 void initialize(QuantifiersEngine* qe,
107 context::Context* c,
108 std::vector<QuantifiersModule*>& modules,
109 bool& needsBuilder,
110 bool& needsRelDom)
111 {
112 // add quantifiers modules
113 if (options::quantConflictFind() || options::quantRewriteRules())
114 {
115 d_qcf.reset(new quantifiers::QuantConflictFind(qe, c));
116 modules.push_back(d_qcf.get());
117 }
118 if (options::conjectureGen())
119 {
120 d_sg_gen.reset(new quantifiers::ConjectureGenerator(qe, c));
121 modules.push_back(d_sg_gen.get());
122 }
123 if (!options::finiteModelFind() || options::fmfInstEngine())
124 {
125 d_inst_engine.reset(new quantifiers::InstantiationEngine(qe));
126 modules.push_back(d_inst_engine.get());
127 }
128 if (options::cbqi())
129 {
130 d_i_cbqi.reset(new quantifiers::InstStrategyCegqi(qe));
131 modules.push_back(d_i_cbqi.get());
132 qe->getInstantiate()->addRewriter(d_i_cbqi->getInstRewriter());
133 }
134 if (options::ceGuidedInst())
135 {
136 d_synth_e.reset(new quantifiers::SynthEngine(qe, c));
137 modules.push_back(d_synth_e.get());
138 }
139 // finite model finding
140 if (options::finiteModelFind())
141 {
142 if (options::fmfBound())
143 {
144 d_bint.reset(new quantifiers::BoundedIntegers(c, qe));
145 modules.push_back(d_bint.get());
146 }
147 d_model_engine.reset(new quantifiers::ModelEngine(c, qe));
148 modules.push_back(d_model_engine.get());
149 // finite model finder has special ways of building the model
150 needsBuilder = true;
151 }
152 if (options::quantRewriteRules())
153 {
154 d_rr_engine.reset(new quantifiers::RewriteEngine(c, qe, d_qcf.get()));
155 modules.push_back(d_rr_engine.get());
156 }
157 if (options::ltePartialInst())
158 {
159 d_lte_part_inst.reset(new quantifiers::LtePartialInst(qe, c));
160 modules.push_back(d_lte_part_inst.get());
161 }
162 if (options::quantDynamicSplit() != quantifiers::QUANT_DSPLIT_MODE_NONE)
163 {
164 d_qsplit.reset(new quantifiers::QuantDSplit(qe, c));
165 modules.push_back(d_qsplit.get());
166 }
167 if (options::quantAntiSkolem())
168 {
169 d_anti_skolem.reset(new quantifiers::QuantAntiSkolem(qe));
170 modules.push_back(d_anti_skolem.get());
171 }
172 if (options::quantAlphaEquiv())
173 {
174 d_alpha_equiv.reset(new quantifiers::AlphaEquivalence(qe));
175 }
176 // full saturation : instantiate from relevant domain, then arbitrary terms
177 if (options::fullSaturateQuant() || options::fullSaturateInterleave())
178 {
179 d_fs.reset(new quantifiers::InstStrategyEnum(qe));
180 modules.push_back(d_fs.get());
181 needsRelDom = true;
182 }
183 }
184 };
185
186 QuantifiersEngine::QuantifiersEngine(context::Context* c,
187 context::UserContext* u,
188 TheoryEngine* te)
189 : d_te(te),
190 d_eq_query(new quantifiers::EqualityQueryQuantifiersEngine(c, this)),
191 d_tr_trie(new inst::TriggerTrie),
192 d_model(nullptr),
193 d_rel_dom(nullptr),
194 d_builder(nullptr),
195 d_qepr(nullptr),
196 d_term_util(new quantifiers::TermUtil(this)),
197 d_term_canon(new expr::TermCanonize),
198 d_term_db(new quantifiers::TermDb(c, u, this)),
199 d_sygus_tdb(nullptr),
200 d_quant_attr(new quantifiers::QuantAttributes(this)),
201 d_instantiate(new quantifiers::Instantiate(this, u)),
202 d_skolemize(new quantifiers::Skolemize(this, u)),
203 d_term_enum(new quantifiers::TermEnumeration),
204 d_conflict_c(c, false),
205 // d_quants(u),
206 d_quants_prereg(u),
207 d_quants_red(u),
208 d_lemmas_produced_c(u),
209 d_ierCounter_c(c),
210 // d_ierCounter(c),
211 // d_ierCounter_lc(c),
212 // d_ierCounterLastLc(c),
213 d_presolve(u, true),
214 d_presolve_in(u),
215 d_presolve_cache(u),
216 d_presolve_cache_wq(u),
217 d_presolve_cache_wic(u)
218 {
219 // initialize the private utility
220 d_private.reset(new QuantifiersEnginePrivate);
221
222 //---- utilities
223 d_util.push_back(d_eq_query.get());
224 // term util must come before the other utilities
225 d_util.push_back(d_term_util.get());
226 d_util.push_back(d_term_db.get());
227
228 if (options::ceGuidedInst()) {
229 d_sygus_tdb.reset(new quantifiers::TermDbSygus(c, this));
230 }
231
232 if( options::instPropagate() ){
233 // notice that this option is incompatible with options::qcfAllConflict()
234 d_private->d_inst_prop.reset(new quantifiers::InstPropagator(this));
235 d_util.push_back(d_private->d_inst_prop.get());
236 d_instantiate->addNotify(d_private->d_inst_prop->getInstantiationNotify());
237 }
238
239
240 d_util.push_back(d_instantiate.get());
241
242 d_curr_effort_level = QuantifiersModule::QEFFORT_NONE;
243 d_conflict = false;
244 d_hasAddedLemma = false;
245 d_useModelEe = false;
246 //don't add true lemma
247 d_lemmas_produced_c[d_term_util->d_true] = true;
248
249 Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
250 Trace("quant-engine-debug") << "Initialize model, mbqi : " << options::mbqiMode() << std::endl;
251
252 if( options::quantEpr() ){
253 Assert( !options::incrementalSolving() );
254 d_qepr.reset(new quantifiers::QuantEPR);
255 }
256 //---- end utilities
257
258 //allow theory combination to go first, once initially
259 d_ierCounter = options::instWhenTcFirst() ? 0 : 1;
260 d_ierCounter_c = d_ierCounter;
261 d_ierCounter_lc = 0;
262 d_ierCounterLastLc = 0;
263 d_inst_when_phase = 1 + ( options::instWhenPhase()<1 ? 1 : options::instWhenPhase() );
264
265 bool needsBuilder = false;
266 bool needsRelDom = false;
267 d_private->initialize(this, c, d_modules, needsBuilder, needsRelDom);
268
269 if( needsRelDom ){
270 d_rel_dom.reset(new quantifiers::RelevantDomain(this));
271 d_util.push_back(d_rel_dom.get());
272 }
273
274 // if we require specialized ways of building the model
275 if( needsBuilder ){
276 Trace("quant-engine-debug") << "Initialize model engine, mbqi : " << options::mbqiMode() << " " << options::fmfBound() << std::endl;
277 if (options::mbqiMode() == quantifiers::MBQI_FMC
278 || options::mbqiMode() == quantifiers::MBQI_TRUST
279 || options::fmfBound())
280 {
281 Trace("quant-engine-debug") << "...make fmc builder." << std::endl;
282 d_model.reset(new quantifiers::fmcheck::FirstOrderModelFmc(
283 this, c, "FirstOrderModelFmc"));
284 d_builder.reset(new quantifiers::fmcheck::FullModelChecker(c, this));
285 }else{
286 Trace("quant-engine-debug") << "...make default model builder." << std::endl;
287 d_model.reset(
288 new quantifiers::FirstOrderModel(this, c, "FirstOrderModel"));
289 d_builder.reset(new quantifiers::QModelBuilder(c, this));
290 }
291 }else{
292 d_model.reset(new quantifiers::FirstOrderModel(this, c, "FirstOrderModel"));
293 }
294 }
295
296 QuantifiersEngine::~QuantifiersEngine() {}
297
298 context::Context* QuantifiersEngine::getSatContext()
299 {
300 return d_te->theoryOf(THEORY_QUANTIFIERS)->getSatContext();
301 }
302
303 context::UserContext* QuantifiersEngine::getUserContext()
304 {
305 return d_te->theoryOf(THEORY_QUANTIFIERS)->getUserContext();
306 }
307
308 OutputChannel& QuantifiersEngine::getOutputChannel()
309 {
310 return d_te->theoryOf(THEORY_QUANTIFIERS)->getOutputChannel();
311 }
312 /** get default valuation for the quantifiers engine */
313 Valuation& QuantifiersEngine::getValuation()
314 {
315 return d_te->theoryOf(THEORY_QUANTIFIERS)->getValuation();
316 }
317
318 const LogicInfo& QuantifiersEngine::getLogicInfo() const
319 {
320 return d_te->getLogicInfo();
321 }
322
323 EqualityQuery* QuantifiersEngine::getEqualityQuery() const
324 {
325 return d_eq_query.get();
326 }
327 quantifiers::RelevantDomain* QuantifiersEngine::getRelevantDomain() const
328 {
329 return d_rel_dom.get();
330 }
331 quantifiers::QModelBuilder* QuantifiersEngine::getModelBuilder() const
332 {
333 return d_builder.get();
334 }
335 quantifiers::QuantEPR* QuantifiersEngine::getQuantEPR() const
336 {
337 return d_qepr.get();
338 }
339 quantifiers::FirstOrderModel* QuantifiersEngine::getModel() const
340 {
341 return d_model.get();
342 }
343 quantifiers::TermDb* QuantifiersEngine::getTermDatabase() const
344 {
345 return d_term_db.get();
346 }
347 quantifiers::TermDbSygus* QuantifiersEngine::getTermDatabaseSygus() const
348 {
349 return d_sygus_tdb.get();
350 }
351 quantifiers::TermUtil* QuantifiersEngine::getTermUtil() const
352 {
353 return d_term_util.get();
354 }
355 expr::TermCanonize* QuantifiersEngine::getTermCanonize() const
356 {
357 return d_term_canon.get();
358 }
359 quantifiers::QuantAttributes* QuantifiersEngine::getQuantAttributes() const
360 {
361 return d_quant_attr.get();
362 }
363 quantifiers::Instantiate* QuantifiersEngine::getInstantiate() const
364 {
365 return d_instantiate.get();
366 }
367 quantifiers::Skolemize* QuantifiersEngine::getSkolemize() const
368 {
369 return d_skolemize.get();
370 }
371 quantifiers::TermEnumeration* QuantifiersEngine::getTermEnumeration() const
372 {
373 return d_term_enum.get();
374 }
375 inst::TriggerTrie* QuantifiersEngine::getTriggerDatabase() const
376 {
377 return d_tr_trie.get();
378 }
379
380 QuantifiersModule * QuantifiersEngine::getOwner( Node q ) {
381 std::map< Node, QuantifiersModule * >::iterator it = d_owner.find( q );
382 if( it==d_owner.end() ){
383 return NULL;
384 }else{
385 return it->second;
386 }
387 }
388
389 void QuantifiersEngine::setOwner( Node q, QuantifiersModule * m, int priority ) {
390 QuantifiersModule * mo = getOwner( q );
391 if( mo!=m ){
392 if( mo!=NULL ){
393 if( priority<=d_owner_priority[q] ){
394 Trace("quant-warn") << "WARNING: setting owner of " << q << " to " << ( m ? m->identify() : "null" ) << ", but already has owner " << mo->identify() << " with higher priority!" << std::endl;
395 return;
396 }
397 }
398 d_owner[q] = m;
399 d_owner_priority[q] = priority;
400 }
401 }
402
403 void QuantifiersEngine::setOwner(Node q, quantifiers::QAttributes& qa)
404 {
405 if (!qa.d_rr.isNull())
406 {
407 if (d_private->d_rr_engine.get() == nullptr)
408 {
409 Trace("quant-warn") << "WARNING : rewrite engine is null, and we have : "
410 << q << std::endl;
411 }
412 // set rewrite engine as owner
413 setOwner(q, d_private->d_rr_engine.get(), 2);
414 }
415 if (qa.d_sygus)
416 {
417 if (d_private->d_synth_e.get() == nullptr)
418 {
419 Trace("quant-warn") << "WARNING : synth engine is null, and we have : "
420 << q << std::endl;
421 }
422 // set synth engine as owner
423 setOwner(q, d_private->d_synth_e.get(), 2);
424 }
425 }
426
427 bool QuantifiersEngine::hasOwnership( Node q, QuantifiersModule * m ) {
428 QuantifiersModule * mo = getOwner( q );
429 return mo==m || mo==NULL;
430 }
431
432 bool QuantifiersEngine::isFiniteBound(Node q, Node v) const
433 {
434 quantifiers::BoundedIntegers* bi = d_private->d_bint.get();
435 if (bi && bi->isBound(q, v))
436 {
437 return true;
438 }
439 TypeNode tn = v.getType();
440 if (tn.isSort() && options::finiteModelFind())
441 {
442 return true;
443 }
444 else if (d_term_enum->mayComplete(tn))
445 {
446 return true;
447 }
448 return false;
449 }
450
451 BoundVarType QuantifiersEngine::getBoundVarType(Node q, Node v) const
452 {
453 quantifiers::BoundedIntegers* bi = d_private->d_bint.get();
454 if (bi)
455 {
456 return bi->getBoundVarType(q, v);
457 }
458 return isFiniteBound(q, v) ? BOUND_FINITE : BOUND_NONE;
459 }
460
461 void QuantifiersEngine::getBoundVarIndices(Node q,
462 std::vector<unsigned>& indices) const
463 {
464 Assert(indices.empty());
465 // we take the bounded variables first
466 quantifiers::BoundedIntegers* bi = d_private->d_bint.get();
467 if (bi)
468 {
469 bi->getBoundVarIndices(q, indices);
470 }
471 // then get the remaining ones
472 for (unsigned i = 0, nvars = q[0].getNumChildren(); i < nvars; i++)
473 {
474 if (std::find(indices.begin(), indices.end(), i) == indices.end())
475 {
476 indices.push_back(i);
477 }
478 }
479 }
480
481 bool QuantifiersEngine::getBoundElements(RepSetIterator* rsi,
482 bool initial,
483 Node q,
484 Node v,
485 std::vector<Node>& elements) const
486 {
487 quantifiers::BoundedIntegers* bi = d_private->d_bint.get();
488 if (bi)
489 {
490 return bi->getBoundElements(rsi, initial, q, v, elements);
491 }
492 return false;
493 }
494
495 void QuantifiersEngine::presolve() {
496 Trace("quant-engine-proc") << "QuantifiersEngine : presolve " << std::endl;
497 for( unsigned i=0; i<d_modules.size(); i++ ){
498 d_modules[i]->presolve();
499 }
500 d_term_db->presolve();
501 d_presolve = false;
502 //add all terms to database
503 if( options::incrementalSolving() ){
504 Trace("quant-engine-proc") << "Add presolve cache " << d_presolve_cache.size() << std::endl;
505 for( unsigned i=0; i<d_presolve_cache.size(); i++ ){
506 addTermToDatabase( d_presolve_cache[i], d_presolve_cache_wq[i], d_presolve_cache_wic[i] );
507 }
508 Trace("quant-engine-proc") << "Done add presolve cache " << std::endl;
509 }
510 }
511
512 void QuantifiersEngine::ppNotifyAssertions(
513 const std::vector<Node>& assertions) {
514 Trace("quant-engine-proc")
515 << "ppNotifyAssertions in QE, #assertions = " << assertions.size()
516 << " check epr = " << (d_qepr != NULL) << std::endl;
517 if (options::instLevelInputOnly() && options::instMaxLevel() != -1)
518 {
519 for (const Node& a : assertions)
520 {
521 quantifiers::QuantAttributes::setInstantiationLevelAttr(a, 0);
522 }
523 }
524 if (d_qepr != NULL)
525 {
526 for (const Node& a : assertions)
527 {
528 d_qepr->registerAssertion(a);
529 }
530 // must handle sources of other new constants e.g. separation logic
531 // FIXME (as part of project 3) : cleanup
532 sep::TheorySep* theory_sep =
533 static_cast<sep::TheorySep*>(getTheoryEngine()->theoryOf(THEORY_SEP));
534 theory_sep->initializeBounds();
535 d_qepr->finishInit();
536 }
537 if (options::ceGuidedInst())
538 {
539 quantifiers::SynthEngine* sye = d_private->d_synth_e.get();
540 for (const Node& a : assertions)
541 {
542 sye->preregisterAssertion(a);
543 }
544 }
545 }
546
547 void QuantifiersEngine::check( Theory::Effort e ){
548 CodeTimer codeTimer(d_statistics.d_time);
549 d_useModelEe = options::quantModelEe() && ( e>=Theory::EFFORT_LAST_CALL );
550 // if we want to use the model's equality engine, build the model now
551 if( d_useModelEe && !d_model->isBuilt() ){
552 Trace("quant-engine-debug") << "Build the model." << std::endl;
553 if (!d_te->getModelBuilder()->buildModel(d_model.get()))
554 {
555 //we are done if model building was unsuccessful
556 flushLemmas();
557 if( d_hasAddedLemma ){
558 Trace("quant-engine-debug") << "...failed." << std::endl;
559 return;
560 }
561 }
562 }
563
564 if( !getActiveEqualityEngine()->consistent() ){
565 Trace("quant-engine-debug") << "Master equality engine not consistent, return." << std::endl;
566 return;
567 }
568 if (d_conflict_c.get())
569 {
570 if (e < Theory::EFFORT_LAST_CALL)
571 {
572 // this can happen in rare cases when quantifiers is the first to realize
573 // there is a quantifier-free conflict, for example, when it discovers
574 // disequal and congruent terms in the master equality engine during
575 // term indexing. In such cases, quantifiers reports a "conflicting lemma"
576 // that is, one that is entailed to be false by the current assignment.
577 // If this lemma is not a SAT conflict, we may get another call to full
578 // effort check and the quantifier-free solvers still haven't realized
579 // there is a conflict. In this case, we return, trusting that theory
580 // combination will do the right thing (split on equalities until there is
581 // a conflict at the quantifier-free level).
582 Trace("quant-engine-debug")
583 << "Conflicting lemma already reported by quantifiers, return."
584 << std::endl;
585 return;
586 }
587 // we reported what we thought was a conflicting lemma, but now we have
588 // gotten a check at LAST_CALL effort, indicating that the lemma we reported
589 // was not conflicting. This should never happen, but in production mode, we
590 // proceed with the check.
591 Assert(false);
592 }
593 bool needsCheck = !d_lemmas_waiting.empty();
594 QuantifiersModule::QEffort needsModelE = QuantifiersModule::QEFFORT_NONE;
595 std::vector< QuantifiersModule* > qm;
596 if( d_model->checkNeeded() ){
597 needsCheck = needsCheck || e>=Theory::EFFORT_LAST_CALL; //always need to check at or above last call
598 for (QuantifiersModule*& mdl : d_modules)
599 {
600 if (mdl->needsCheck(e))
601 {
602 qm.push_back(mdl);
603 needsCheck = true;
604 //can only request model at last call since theory combination can find inconsistencies
605 if( e>=Theory::EFFORT_LAST_CALL ){
606 QuantifiersModule::QEffort me = mdl->needsModel(e);
607 needsModelE = me<needsModelE ? me : needsModelE;
608 }
609 }
610 }
611 }
612
613 d_conflict = false;
614 d_hasAddedLemma = false;
615 bool setIncomplete = false;
616
617 Trace("quant-engine-debug2") << "Quantifiers Engine call to check, level = " << e << ", needsCheck=" << needsCheck << std::endl;
618 if( needsCheck ){
619 //flush previous lemmas (for instance, if was interupted), or other lemmas to process
620 flushLemmas();
621 if( d_hasAddedLemma ){
622 return;
623 }
624
625 double clSet = 0;
626 if( Trace.isOn("quant-engine") ){
627 clSet = double(clock())/double(CLOCKS_PER_SEC);
628 Trace("quant-engine") << ">>>>> Quantifiers Engine Round, effort = " << e << " <<<<<" << std::endl;
629 }
630
631 if( Trace.isOn("quant-engine-debug") ){
632 Trace("quant-engine-debug") << "Quantifiers Engine check, level = " << e << std::endl;
633 Trace("quant-engine-debug") << " depth : " << d_ierCounter_c << std::endl;
634 Trace("quant-engine-debug") << " modules to check : ";
635 for( unsigned i=0; i<qm.size(); i++ ){
636 Trace("quant-engine-debug") << qm[i]->identify() << " ";
637 }
638 Trace("quant-engine-debug") << std::endl;
639 Trace("quant-engine-debug") << " # quantified formulas = " << d_model->getNumAssertedQuantifiers() << std::endl;
640 if( !d_lemmas_waiting.empty() ){
641 Trace("quant-engine-debug") << " lemmas waiting = " << d_lemmas_waiting.size() << std::endl;
642 }
643 Trace("quant-engine-debug") << " Theory engine finished : " << !d_te->needCheck() << std::endl;
644 Trace("quant-engine-debug") << " Needs model effort : " << needsModelE << std::endl;
645 }
646 if( Trace.isOn("quant-engine-ee-pre") ){
647 Trace("quant-engine-ee-pre") << "Equality engine (pre-inference): " << std::endl;
648 debugPrintEqualityEngine( "quant-engine-ee-pre" );
649 }
650 if( Trace.isOn("quant-engine-assert") ){
651 Trace("quant-engine-assert") << "Assertions : " << std::endl;
652 getTheoryEngine()->printAssertions("quant-engine-assert");
653 }
654
655 //reset utilities
656 Trace("quant-engine-debug") << "Resetting all utilities..." << std::endl;
657 for (QuantifiersUtil*& util : d_util)
658 {
659 Trace("quant-engine-debug2") << "Reset " << util->identify().c_str()
660 << "..." << std::endl;
661 if (!util->reset(e))
662 {
663 flushLemmas();
664 if( d_hasAddedLemma ){
665 return;
666 }else{
667 //should only fail reset if added a lemma
668 Assert( false );
669 }
670 }
671 }
672
673 if( Trace.isOn("quant-engine-ee") ){
674 Trace("quant-engine-ee") << "Equality engine : " << std::endl;
675 debugPrintEqualityEngine( "quant-engine-ee" );
676 }
677
678 //reset the model
679 Trace("quant-engine-debug") << "Reset model..." << std::endl;
680 d_model->reset_round();
681
682 //reset the modules
683 Trace("quant-engine-debug") << "Resetting all modules..." << std::endl;
684 for (QuantifiersModule*& mdl : d_modules)
685 {
686 Trace("quant-engine-debug2") << "Reset " << mdl->identify().c_str()
687 << std::endl;
688 mdl->reset_round(e);
689 }
690 Trace("quant-engine-debug") << "Done resetting all modules." << std::endl;
691 //reset may have added lemmas
692 flushLemmas();
693 if( d_hasAddedLemma ){
694 return;
695 }
696
697 if( e==Theory::EFFORT_LAST_CALL ){
698 ++(d_statistics.d_instantiation_rounds_lc);
699 }else if( e==Theory::EFFORT_FULL ){
700 ++(d_statistics.d_instantiation_rounds);
701 }
702 Trace("quant-engine-debug") << "Check modules that needed check..." << std::endl;
703 for (unsigned qef = QuantifiersModule::QEFFORT_CONFLICT;
704 qef <= QuantifiersModule::QEFFORT_LAST_CALL;
705 ++qef)
706 {
707 QuantifiersModule::QEffort quant_e =
708 static_cast<QuantifiersModule::QEffort>(qef);
709 d_curr_effort_level = quant_e;
710 //build the model if any module requested it
711 if (needsModelE == quant_e)
712 {
713 if (!d_model->isBuilt())
714 {
715 // theory engine's model builder is quantifier engine's builder if it
716 // has one
717 Assert(!getModelBuilder()
718 || getModelBuilder() == d_te->getModelBuilder());
719 Trace("quant-engine-debug") << "Build model..." << std::endl;
720 if (!d_te->getModelBuilder()->buildModel(d_model.get()))
721 {
722 flushLemmas();
723 }
724 }
725 if (!d_model->isBuiltSuccess())
726 {
727 break;
728 }
729 }
730 if( !d_hasAddedLemma ){
731 //check each module
732 for (QuantifiersModule*& mdl : qm)
733 {
734 Trace("quant-engine-debug") << "Check " << mdl->identify().c_str()
735 << " at effort " << quant_e << "..."
736 << std::endl;
737 mdl->check(e, quant_e);
738 if( d_conflict ){
739 Trace("quant-engine-debug") << "...conflict!" << std::endl;
740 break;
741 }
742 }
743 //flush all current lemmas
744 flushLemmas();
745 }
746 //if we have added one, stop
747 if( d_hasAddedLemma ){
748 break;
749 }else{
750 Assert( !d_conflict );
751 if (quant_e == QuantifiersModule::QEFFORT_CONFLICT)
752 {
753 if( e==Theory::EFFORT_FULL ){
754 //increment if a last call happened, we are not strictly enforcing interleaving, or already were in phase
755 if( d_ierCounterLastLc!=d_ierCounter_lc || !options::instWhenStrictInterleave() || d_ierCounter%d_inst_when_phase!=0 ){
756 d_ierCounter = d_ierCounter + 1;
757 d_ierCounterLastLc = d_ierCounter_lc;
758 d_ierCounter_c = d_ierCounter_c.get() + 1;
759 }
760 }else if( e==Theory::EFFORT_LAST_CALL ){
761 d_ierCounter_lc = d_ierCounter_lc + 1;
762 }
763 }
764 else if (quant_e == QuantifiersModule::QEFFORT_MODEL)
765 {
766 if( e==Theory::EFFORT_LAST_CALL ){
767 //sources of incompleteness
768 for (QuantifiersUtil*& util : d_util)
769 {
770 if (!util->checkComplete())
771 {
772 Trace("quant-engine-debug") << "Set incomplete because utility "
773 << util->identify().c_str()
774 << " was incomplete." << std::endl;
775 setIncomplete = true;
776 }
777 }
778 if (d_conflict_c.get())
779 {
780 // we reported a conflicting lemma, should return
781 setIncomplete = true;
782 }
783 //if we have a chance not to set incomplete
784 if( !setIncomplete ){
785 //check if we should set the incomplete flag
786 for (QuantifiersModule*& mdl : d_modules)
787 {
788 if (!mdl->checkComplete())
789 {
790 Trace("quant-engine-debug")
791 << "Set incomplete because module "
792 << mdl->identify().c_str() << " was incomplete."
793 << std::endl;
794 setIncomplete = true;
795 break;
796 }
797 }
798 if( !setIncomplete ){
799 //look at individual quantified formulas, one module must claim completeness for each one
800 for( unsigned i=0; i<d_model->getNumAssertedQuantifiers(); i++ ){
801 bool hasCompleteM = false;
802 Node q = d_model->getAssertedQuantifier( i );
803 QuantifiersModule * qmd = getOwner( q );
804 if( qmd!=NULL ){
805 hasCompleteM = qmd->checkCompleteFor( q );
806 }else{
807 for( unsigned j=0; j<d_modules.size(); j++ ){
808 if( d_modules[j]->checkCompleteFor( q ) ){
809 qmd = d_modules[j];
810 hasCompleteM = true;
811 break;
812 }
813 }
814 }
815 if( !hasCompleteM ){
816 Trace("quant-engine-debug") << "Set incomplete because " << q << " was not fully processed." << std::endl;
817 setIncomplete = true;
818 break;
819 }else{
820 Assert( qmd!=NULL );
821 Trace("quant-engine-debug2") << "Complete for " << q << " due to " << qmd->identify().c_str() << std::endl;
822 }
823 }
824 }
825 }
826 //if setIncomplete = false, we will answer SAT, otherwise we will run at quant_e QEFFORT_LAST_CALL
827 if( !setIncomplete ){
828 break;
829 }
830 }
831 }
832 }
833 }
834 d_curr_effort_level = QuantifiersModule::QEFFORT_NONE;
835 Trace("quant-engine-debug") << "Done check modules that needed check." << std::endl;
836 if( d_hasAddedLemma ){
837 d_instantiate->debugPrint();
838 }
839 if( Trace.isOn("quant-engine") ){
840 double clSet2 = double(clock())/double(CLOCKS_PER_SEC);
841 Trace("quant-engine") << "Finished quantifiers engine, total time = " << (clSet2-clSet);
842 Trace("quant-engine") << ", added lemma = " << d_hasAddedLemma;
843 Trace("quant-engine") << std::endl;
844 }
845
846 Trace("quant-engine-debug2") << "Finished quantifiers engine check." << std::endl;
847 }else{
848 Trace("quant-engine-debug2") << "Quantifiers Engine does not need check." << std::endl;
849 }
850
851 //SAT case
852 if( e==Theory::EFFORT_LAST_CALL && !d_hasAddedLemma ){
853 if( setIncomplete ){
854 Trace("quant-engine") << "Set incomplete flag." << std::endl;
855 getOutputChannel().setIncomplete();
856 }
857 //output debug stats
858 d_instantiate->debugPrintModel();
859 }
860 }
861
862 void QuantifiersEngine::notifyCombineTheories() {
863 //if allowing theory combination to happen at most once between instantiation rounds
864 //d_ierCounter = 1;
865 //d_ierCounterLastLc = -1;
866 }
867
868 bool QuantifiersEngine::reduceQuantifier( Node q ) {
869 //TODO: this can be unified with preregistration: AlphaEquivalence takes ownership of reducable quants
870 BoolMap::const_iterator it = d_quants_red.find( q );
871 if( it==d_quants_red.end() ){
872 Node lem;
873 std::map< Node, Node >::iterator itr = d_quants_red_lem.find( q );
874 if( itr==d_quants_red_lem.end() ){
875 if (d_private->d_alpha_equiv)
876 {
877 Trace("quant-engine-red") << "Alpha equivalence " << q << "?" << std::endl;
878 //add equivalence with another quantified formula
879 lem = d_private->d_alpha_equiv->reduceQuantifier(q);
880 if( !lem.isNull() ){
881 Trace("quant-engine-red") << "...alpha equivalence success." << std::endl;
882 ++(d_statistics.d_red_alpha_equiv);
883 }
884 }
885 d_quants_red_lem[q] = lem;
886 }else{
887 lem = itr->second;
888 }
889 if( !lem.isNull() ){
890 getOutputChannel().lemma( lem );
891 }
892 d_quants_red[q] = !lem.isNull();
893 return !lem.isNull();
894 }else{
895 return (*it).second;
896 }
897 }
898
899 void QuantifiersEngine::registerQuantifierInternal(Node f)
900 {
901 std::map< Node, bool >::iterator it = d_quants.find( f );
902 if( it==d_quants.end() ){
903 Trace("quant") << "QuantifiersEngine : Register quantifier ";
904 Trace("quant") << " : " << f << std::endl;
905 unsigned prev_lemma_waiting = d_lemmas_waiting.size();
906 ++(d_statistics.d_num_quant);
907 Assert( f.getKind()==FORALL );
908 // register with utilities
909 for (unsigned i = 0; i < d_util.size(); i++)
910 {
911 d_util[i]->registerQuantifier(f);
912 }
913 // compute attributes
914 d_quant_attr->computeAttributes(f);
915
916 for (QuantifiersModule*& mdl : d_modules)
917 {
918 Trace("quant-debug") << "check ownership with " << mdl->identify()
919 << "..." << std::endl;
920 mdl->checkOwnership(f);
921 }
922 QuantifiersModule* qm = getOwner(f);
923 Trace("quant") << " Owner : " << (qm == nullptr ? "[none]" : qm->identify())
924 << std::endl;
925 // register with each module
926 for (QuantifiersModule*& mdl : d_modules)
927 {
928 Trace("quant-debug") << "register with " << mdl->identify() << "..."
929 << std::endl;
930 mdl->registerQuantifier(f);
931 // since this is context-independent, we should not add any lemmas during
932 // this call
933 Assert(d_lemmas_waiting.size() == prev_lemma_waiting);
934 }
935 Trace("quant-debug") << "...finish." << std::endl;
936 d_quants[f] = true;
937 AlwaysAssert(d_lemmas_waiting.size() == prev_lemma_waiting);
938 }
939 }
940
941 void QuantifiersEngine::preRegisterQuantifier(Node q)
942 {
943 NodeSet::const_iterator it = d_quants_prereg.find(q);
944 if (it != d_quants_prereg.end())
945 {
946 return;
947 }
948 Trace("quant-debug") << "QuantifiersEngine : Pre-register " << q << std::endl;
949 d_quants_prereg.insert(q);
950 // try to reduce
951 if (reduceQuantifier(q))
952 {
953 // if we can reduce it, nothing left to do
954 return;
955 }
956 // ensure that it is registered
957 registerQuantifierInternal(q);
958 // register with each module
959 for (QuantifiersModule*& mdl : d_modules)
960 {
961 Trace("quant-debug") << "pre-register with " << mdl->identify() << "..."
962 << std::endl;
963 mdl->preRegisterQuantifier(q);
964 }
965 // flush the lemmas
966 flushLemmas();
967 Trace("quant-debug") << "...finish pre-register " << q << "..." << std::endl;
968 }
969
970 void QuantifiersEngine::registerPattern( std::vector<Node> & pattern) {
971 for(std::vector<Node>::iterator p = pattern.begin(); p != pattern.end(); ++p){
972 std::set< Node > added;
973 getTermDatabase()->addTerm( *p, added );
974 }
975 }
976
977 void QuantifiersEngine::assertQuantifier( Node f, bool pol ){
978 if (reduceQuantifier(f))
979 {
980 // if we can reduce it, nothing left to do
981 return;
982 }
983 if( !pol ){
984 // do skolemization
985 Node lem = d_skolemize->process(f);
986 if (!lem.isNull())
987 {
988 if (Trace.isOn("quantifiers-sk-debug"))
989 {
990 Node slem = Rewriter::rewrite(lem);
991 Trace("quantifiers-sk-debug")
992 << "Skolemize lemma : " << slem << std::endl;
993 }
994 getOutputChannel().lemma(lem, false, true);
995 }
996 return;
997 }
998 // ensure the quantified formula is registered
999 registerQuantifierInternal(f);
1000 // assert it to each module
1001 d_model->assertQuantifier(f);
1002 for (QuantifiersModule*& mdl : d_modules)
1003 {
1004 mdl->assertNode(f);
1005 }
1006 addTermToDatabase(d_term_util->getInstConstantBody(f), true);
1007 }
1008
1009 void QuantifiersEngine::addTermToDatabase( Node n, bool withinQuant, bool withinInstClosure ){
1010 if( options::incrementalSolving() ){
1011 if( d_presolve_in.find( n )==d_presolve_in.end() ){
1012 d_presolve_in.insert( n );
1013 d_presolve_cache.push_back( n );
1014 d_presolve_cache_wq.push_back( withinQuant );
1015 d_presolve_cache_wic.push_back( withinInstClosure );
1016 }
1017 }
1018 //only wait if we are doing incremental solving
1019 if( !d_presolve || !options::incrementalSolving() ){
1020 std::set< Node > added;
1021 d_term_db->addTerm(n, added, withinQuant, withinInstClosure);
1022
1023 if (!withinQuant)
1024 {
1025 if (d_sygus_tdb)
1026 {
1027 d_sygus_tdb->getEvalUnfold()->registerEvalTerm(n);
1028 }
1029 }
1030 }
1031 }
1032
1033 void QuantifiersEngine::eqNotifyNewClass(TNode t) {
1034 addTermToDatabase( t );
1035 }
1036
1037 bool QuantifiersEngine::addLemma( Node lem, bool doCache, bool doRewrite ){
1038 if( doCache ){
1039 if( doRewrite ){
1040 lem = Rewriter::rewrite(lem);
1041 }
1042 Trace("inst-add-debug") << "Adding lemma : " << lem << std::endl;
1043 BoolMap::const_iterator itp = d_lemmas_produced_c.find( lem );
1044 if( itp==d_lemmas_produced_c.end() || !(*itp).second ){
1045 //d_curr_out->lemma( lem, false, true );
1046 d_lemmas_produced_c[ lem ] = true;
1047 d_lemmas_waiting.push_back( lem );
1048 Trace("inst-add-debug") << "Added lemma" << std::endl;
1049 return true;
1050 }else{
1051 Trace("inst-add-debug") << "Duplicate." << std::endl;
1052 return false;
1053 }
1054 }else{
1055 //do not need to rewrite, will be rewritten after sending
1056 d_lemmas_waiting.push_back( lem );
1057 return true;
1058 }
1059 }
1060
1061 bool QuantifiersEngine::removeLemma( Node lem ) {
1062 std::vector< Node >::iterator it = std::find( d_lemmas_waiting.begin(), d_lemmas_waiting.end(), lem );
1063 if( it!=d_lemmas_waiting.end() ){
1064 d_lemmas_waiting.erase( it, it + 1 );
1065 d_lemmas_produced_c[ lem ] = false;
1066 return true;
1067 }else{
1068 return false;
1069 }
1070 }
1071
1072 void QuantifiersEngine::addRequirePhase( Node lit, bool req ){
1073 d_phase_req_waiting[lit] = req;
1074 }
1075
1076 void QuantifiersEngine::markRelevant( Node q ) {
1077 d_model->markRelevant( q );
1078 }
1079
1080 void QuantifiersEngine::setConflict() {
1081 d_conflict = true;
1082 d_conflict_c = true;
1083 }
1084
1085 bool QuantifiersEngine::getInstWhenNeedsCheck( Theory::Effort e ) {
1086 Trace("quant-engine-debug2") << "Get inst when needs check, counts=" << d_ierCounter << ", " << d_ierCounter_lc << std::endl;
1087 //determine if we should perform check, based on instWhenMode
1088 bool performCheck = false;
1089 if( options::instWhenMode()==quantifiers::INST_WHEN_FULL ){
1090 performCheck = ( e >= Theory::EFFORT_FULL );
1091 }else if( options::instWhenMode()==quantifiers::INST_WHEN_FULL_DELAY ){
1092 performCheck = ( e >= Theory::EFFORT_FULL ) && !getTheoryEngine()->needCheck();
1093 }else if( options::instWhenMode()==quantifiers::INST_WHEN_FULL_LAST_CALL ){
1094 performCheck = ( ( e==Theory::EFFORT_FULL && d_ierCounter%d_inst_when_phase!=0 ) || e==Theory::EFFORT_LAST_CALL );
1095 }else if( options::instWhenMode()==quantifiers::INST_WHEN_FULL_DELAY_LAST_CALL ){
1096 performCheck = ( ( e==Theory::EFFORT_FULL && !getTheoryEngine()->needCheck() && d_ierCounter%d_inst_when_phase!=0 ) || e==Theory::EFFORT_LAST_CALL );
1097 }else if( options::instWhenMode()==quantifiers::INST_WHEN_LAST_CALL ){
1098 performCheck = ( e >= Theory::EFFORT_LAST_CALL );
1099 }else{
1100 performCheck = true;
1101 }
1102 if( e==Theory::EFFORT_LAST_CALL ){
1103 //with bounded integers, skip every other last call,
1104 // since matching loops may occur with infinite quantification
1105 if( d_ierCounter_lc%2==0 && options::fmfBound() ){
1106 performCheck = false;
1107 }
1108 }
1109 return performCheck;
1110 }
1111
1112 quantifiers::UserPatMode QuantifiersEngine::getInstUserPatMode() {
1113 if( options::userPatternsQuant()==quantifiers::USER_PAT_MODE_INTERLEAVE ){
1114 return d_ierCounter%2==0 ? quantifiers::USER_PAT_MODE_USE : quantifiers::USER_PAT_MODE_RESORT;
1115 }else{
1116 return options::userPatternsQuant();
1117 }
1118 }
1119
1120 void QuantifiersEngine::flushLemmas(){
1121 if( !d_lemmas_waiting.empty() ){
1122 //filter based on notify classes
1123 if (d_instantiate->hasNotify())
1124 {
1125 unsigned prev_lem_sz = d_lemmas_waiting.size();
1126 d_instantiate->notifyFlushLemmas();
1127 if( prev_lem_sz!=d_lemmas_waiting.size() ){
1128 Trace("quant-engine") << "...filtered instances : " << d_lemmas_waiting.size() << " / " << prev_lem_sz << std::endl;
1129 }
1130 }
1131 //take default output channel if none is provided
1132 d_hasAddedLemma = true;
1133 for( unsigned i=0; i<d_lemmas_waiting.size(); i++ ){
1134 Trace("qe-lemma") << "Lemma : " << d_lemmas_waiting[i] << std::endl;
1135 getOutputChannel().lemma( d_lemmas_waiting[i], false, true );
1136 }
1137 d_lemmas_waiting.clear();
1138 }
1139 if( !d_phase_req_waiting.empty() ){
1140 for( std::map< Node, bool >::iterator it = d_phase_req_waiting.begin(); it != d_phase_req_waiting.end(); ++it ){
1141 Trace("qe-lemma") << "Require phase : " << it->first << " -> " << it->second << std::endl;
1142 getOutputChannel().requirePhase( it->first, it->second );
1143 }
1144 d_phase_req_waiting.clear();
1145 }
1146 }
1147
1148 bool QuantifiersEngine::getUnsatCoreLemmas( std::vector< Node >& active_lemmas ) {
1149 return d_instantiate->getUnsatCoreLemmas(active_lemmas);
1150 }
1151
1152 bool QuantifiersEngine::getUnsatCoreLemmas( std::vector< Node >& active_lemmas, std::map< Node, Node >& weak_imp ) {
1153 return d_instantiate->getUnsatCoreLemmas(active_lemmas, weak_imp);
1154 }
1155
1156 void QuantifiersEngine::getInstantiationTermVectors( Node q, std::vector< std::vector< Node > >& tvecs ) {
1157 d_instantiate->getInstantiationTermVectors(q, tvecs);
1158 }
1159
1160 void QuantifiersEngine::getInstantiationTermVectors( std::map< Node, std::vector< std::vector< Node > > >& insts ) {
1161 d_instantiate->getInstantiationTermVectors(insts);
1162 }
1163
1164 void QuantifiersEngine::getExplanationForInstLemmas(
1165 const std::vector<Node>& lems,
1166 std::map<Node, Node>& quant,
1167 std::map<Node, std::vector<Node> >& tvec)
1168 {
1169 d_instantiate->getExplanationForInstLemmas(lems, quant, tvec);
1170 }
1171
1172 void QuantifiersEngine::printInstantiations( std::ostream& out ) {
1173 bool printed = false;
1174 // print the skolemizations
1175 if (d_skolemize->printSkolemization(out))
1176 {
1177 printed = true;
1178 }
1179 // print the instantiations
1180 if (d_instantiate->printInstantiations(out))
1181 {
1182 printed = true;
1183 }
1184 if( !printed ){
1185 out << "No instantiations" << std::endl;
1186 }
1187 }
1188
1189 void QuantifiersEngine::printSynthSolution( std::ostream& out ) {
1190 if (d_private->d_synth_e)
1191 {
1192 d_private->d_synth_e->printSynthSolution(out);
1193 }else{
1194 out << "Internal error : module for synth solution not found." << std::endl;
1195 }
1196 }
1197
1198 void QuantifiersEngine::getInstantiatedQuantifiedFormulas( std::vector< Node >& qs ) {
1199 d_instantiate->getInstantiatedQuantifiedFormulas(qs);
1200 }
1201
1202 void QuantifiersEngine::getInstantiations( std::map< Node, std::vector< Node > >& insts ) {
1203 d_instantiate->getInstantiations(insts);
1204 }
1205
1206 void QuantifiersEngine::getInstantiations( Node q, std::vector< Node >& insts ) {
1207 d_instantiate->getInstantiations(q, insts);
1208 }
1209
1210 Node QuantifiersEngine::getInstantiatedConjunction( Node q ) {
1211 return d_instantiate->getInstantiatedConjunction(q);
1212 }
1213
1214 QuantifiersEngine::Statistics::Statistics()
1215 : d_time("theory::QuantifiersEngine::time"),
1216 d_qcf_time("theory::QuantifiersEngine::time_qcf"),
1217 d_ematching_time("theory::QuantifiersEngine::time_ematching"),
1218 d_num_quant("QuantifiersEngine::Num_Quantifiers", 0),
1219 d_instantiation_rounds("QuantifiersEngine::Rounds_Instantiation_Full", 0),
1220 d_instantiation_rounds_lc("QuantifiersEngine::Rounds_Instantiation_Last_Call", 0),
1221 d_triggers("QuantifiersEngine::Triggers", 0),
1222 d_simple_triggers("QuantifiersEngine::Triggers_Simple", 0),
1223 d_multi_triggers("QuantifiersEngine::Triggers_Multi", 0),
1224 d_multi_trigger_instantiations("QuantifiersEngine::Multi_Trigger_Instantiations", 0),
1225 d_red_alpha_equiv("QuantifiersEngine::Reductions_Alpha_Equivalence", 0),
1226 d_instantiations_user_patterns("QuantifiersEngine::Instantiations_User_Patterns", 0),
1227 d_instantiations_auto_gen("QuantifiersEngine::Instantiations_Auto_Gen", 0),
1228 d_instantiations_guess("QuantifiersEngine::Instantiations_Guess", 0),
1229 d_instantiations_qcf("QuantifiersEngine::Instantiations_Qcf_Conflict", 0),
1230 d_instantiations_qcf_prop("QuantifiersEngine::Instantiations_Qcf_Prop", 0),
1231 d_instantiations_fmf_exh("QuantifiersEngine::Instantiations_Fmf_Exh", 0),
1232 d_instantiations_fmf_mbqi("QuantifiersEngine::Instantiations_Fmf_Mbqi", 0),
1233 d_instantiations_cbqi("QuantifiersEngine::Instantiations_Cbqi", 0),
1234 d_instantiations_rr("QuantifiersEngine::Instantiations_Rewrite_Rules", 0)
1235 {
1236 smtStatisticsRegistry()->registerStat(&d_time);
1237 smtStatisticsRegistry()->registerStat(&d_qcf_time);
1238 smtStatisticsRegistry()->registerStat(&d_ematching_time);
1239 smtStatisticsRegistry()->registerStat(&d_num_quant);
1240 smtStatisticsRegistry()->registerStat(&d_instantiation_rounds);
1241 smtStatisticsRegistry()->registerStat(&d_instantiation_rounds_lc);
1242 smtStatisticsRegistry()->registerStat(&d_triggers);
1243 smtStatisticsRegistry()->registerStat(&d_simple_triggers);
1244 smtStatisticsRegistry()->registerStat(&d_multi_triggers);
1245 smtStatisticsRegistry()->registerStat(&d_multi_trigger_instantiations);
1246 smtStatisticsRegistry()->registerStat(&d_red_alpha_equiv);
1247 smtStatisticsRegistry()->registerStat(&d_instantiations_user_patterns);
1248 smtStatisticsRegistry()->registerStat(&d_instantiations_auto_gen);
1249 smtStatisticsRegistry()->registerStat(&d_instantiations_guess);
1250 smtStatisticsRegistry()->registerStat(&d_instantiations_qcf);
1251 smtStatisticsRegistry()->registerStat(&d_instantiations_qcf_prop);
1252 smtStatisticsRegistry()->registerStat(&d_instantiations_fmf_exh);
1253 smtStatisticsRegistry()->registerStat(&d_instantiations_fmf_mbqi);
1254 smtStatisticsRegistry()->registerStat(&d_instantiations_cbqi);
1255 smtStatisticsRegistry()->registerStat(&d_instantiations_rr);
1256 }
1257
1258 QuantifiersEngine::Statistics::~Statistics(){
1259 smtStatisticsRegistry()->unregisterStat(&d_time);
1260 smtStatisticsRegistry()->unregisterStat(&d_qcf_time);
1261 smtStatisticsRegistry()->unregisterStat(&d_ematching_time);
1262 smtStatisticsRegistry()->unregisterStat(&d_num_quant);
1263 smtStatisticsRegistry()->unregisterStat(&d_instantiation_rounds);
1264 smtStatisticsRegistry()->unregisterStat(&d_instantiation_rounds_lc);
1265 smtStatisticsRegistry()->unregisterStat(&d_triggers);
1266 smtStatisticsRegistry()->unregisterStat(&d_simple_triggers);
1267 smtStatisticsRegistry()->unregisterStat(&d_multi_triggers);
1268 smtStatisticsRegistry()->unregisterStat(&d_multi_trigger_instantiations);
1269 smtStatisticsRegistry()->unregisterStat(&d_red_alpha_equiv);
1270 smtStatisticsRegistry()->unregisterStat(&d_instantiations_user_patterns);
1271 smtStatisticsRegistry()->unregisterStat(&d_instantiations_auto_gen);
1272 smtStatisticsRegistry()->unregisterStat(&d_instantiations_guess);
1273 smtStatisticsRegistry()->unregisterStat(&d_instantiations_qcf);
1274 smtStatisticsRegistry()->unregisterStat(&d_instantiations_qcf_prop);
1275 smtStatisticsRegistry()->unregisterStat(&d_instantiations_fmf_exh);
1276 smtStatisticsRegistry()->unregisterStat(&d_instantiations_fmf_mbqi);
1277 smtStatisticsRegistry()->unregisterStat(&d_instantiations_cbqi);
1278 smtStatisticsRegistry()->unregisterStat(&d_instantiations_rr);
1279 }
1280
1281 eq::EqualityEngine* QuantifiersEngine::getMasterEqualityEngine() const
1282 {
1283 return d_te->getMasterEqualityEngine();
1284 }
1285
1286 eq::EqualityEngine* QuantifiersEngine::getActiveEqualityEngine() const
1287 {
1288 if( d_useModelEe ){
1289 return d_model->getEqualityEngine();
1290 }
1291 return d_te->getMasterEqualityEngine();
1292 }
1293
1294 Node QuantifiersEngine::getInternalRepresentative( Node a, Node q, int index ){
1295 bool prevModelEe = d_useModelEe;
1296 d_useModelEe = false;
1297 Node ret = d_eq_query->getInternalRepresentative( a, q, index );
1298 d_useModelEe = prevModelEe;
1299 return ret;
1300 }
1301
1302 void QuantifiersEngine::getSynthSolutions(std::map<Node, Node>& sol_map)
1303 {
1304 d_private->d_synth_e->getSynthSolutions(sol_map);
1305 }
1306
1307 void QuantifiersEngine::debugPrintEqualityEngine( const char * c ) {
1308 eq::EqualityEngine* ee = getActiveEqualityEngine();
1309 eq::EqClassesIterator eqcs_i = eq::EqClassesIterator( ee );
1310 std::map< TypeNode, int > typ_num;
1311 while( !eqcs_i.isFinished() ){
1312 TNode r = (*eqcs_i);
1313 TypeNode tr = r.getType();
1314 if( typ_num.find( tr )==typ_num.end() ){
1315 typ_num[tr] = 0;
1316 }
1317 typ_num[tr]++;
1318 bool firstTime = true;
1319 Trace(c) << " " << r;
1320 Trace(c) << " : { ";
1321 eq::EqClassIterator eqc_i = eq::EqClassIterator( r, ee );
1322 while( !eqc_i.isFinished() ){
1323 TNode n = (*eqc_i);
1324 if( r!=n ){
1325 if( firstTime ){
1326 Trace(c) << std::endl;
1327 firstTime = false;
1328 }
1329 Trace(c) << " " << n << std::endl;
1330 }
1331 ++eqc_i;
1332 }
1333 if( !firstTime ){ Trace(c) << " "; }
1334 Trace(c) << "}" << std::endl;
1335 ++eqcs_i;
1336 }
1337 Trace(c) << std::endl;
1338 for( std::map< TypeNode, int >::iterator it = typ_num.begin(); it != typ_num.end(); ++it ){
1339 Trace(c) << "# eqc for " << it->first << " : " << it->second << std::endl;
1340 }
1341 }
1342
1343 } // namespace theory
1344 } // namespace CVC4