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