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