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