1 /********************* */
2 /*! \file quantifiers_engine.cpp
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Tim King, Morgan Deters
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2016 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
12 ** \brief Implementation of quantifiers engine class
15 #include "theory/quantifiers_engine.h"
17 #include "options/quantifiers_options.h"
18 #include "options/uf_options.h"
19 #include "smt/smt_statistics_registry.h"
20 #include "theory/arrays/theory_arrays.h"
21 #include "theory/datatypes/theory_datatypes.h"
22 #include "theory/quantifiers/alpha_equivalence.h"
23 #include "theory/quantifiers/ambqi_builder.h"
24 #include "theory/quantifiers/bounded_integers.h"
25 #include "theory/quantifiers/ce_guided_instantiation.h"
26 #include "theory/quantifiers/conjecture_generator.h"
27 #include "theory/quantifiers/first_order_model.h"
28 #include "theory/quantifiers/full_model_check.h"
29 #include "theory/quantifiers/fun_def_engine.h"
30 #include "theory/quantifiers/inst_strategy_cbqi.h"
31 #include "theory/quantifiers/inst_strategy_e_matching.h"
32 #include "theory/quantifiers/instantiation_engine.h"
33 #include "theory/quantifiers/local_theory_ext.h"
34 #include "theory/quantifiers/model_engine.h"
35 #include "theory/quantifiers/quant_conflict_find.h"
36 #include "theory/quantifiers/quant_equality_engine.h"
37 #include "theory/quantifiers/quantifiers_rewriter.h"
38 #include "theory/quantifiers/relevant_domain.h"
39 #include "theory/quantifiers/rewrite_engine.h"
40 #include "theory/quantifiers/term_database.h"
41 #include "theory/quantifiers/trigger.h"
42 #include "theory/quantifiers/quant_split.h"
43 #include "theory/quantifiers/anti_skolem.h"
44 #include "theory/quantifiers/equality_infer.h"
45 #include "theory/quantifiers/inst_propagator.h"
46 #include "theory/theory_engine.h"
47 #include "theory/uf/equality_engine.h"
48 #include "theory/uf/theory_uf.h"
49 #include "theory/uf/theory_uf_strong_solver.h"
53 using namespace CVC4::kind
;
54 using namespace CVC4::context
;
55 using namespace CVC4::theory
;
56 using namespace CVC4::theory::inst
;
58 QuantifiersEngine::QuantifiersEngine(context::Context
* c
, context::UserContext
* u
, TheoryEngine
* te
):
60 d_conflict_c(c
, false),
63 d_lemmas_produced_c(u
),
68 //d_ierCounterLastLc(c),
72 d_presolve_cache_wq(u
),
73 d_presolve_cache_wic(u
){
75 d_eq_query
= new EqualityQueryQuantifiersEngine( c
, this );
76 d_util
.push_back( d_eq_query
);
78 d_term_db
= new quantifiers::TermDb( c
, u
, this );
79 d_util
.push_back( d_term_db
);
81 if( options::instPropagate() ){
82 d_inst_prop
= new quantifiers::InstPropagator( this );
83 d_util
.push_back( d_inst_prop
);
84 d_inst_notify
.push_back( d_inst_prop
->getInstantiationNotify() );
89 d_tr_trie
= new inst::TriggerTrie
;
90 d_curr_effort_level
= QEFFORT_NONE
;
92 d_hasAddedLemma
= false;
93 //don't add true lemma
94 d_lemmas_produced_c
[d_term_db
->d_true
] = true;
96 Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl
;
97 Trace("quant-engine-debug") << "Initialize model, mbqi : " << options::mbqiMode() << std::endl
;
100 if( options::mbqiMode()==quantifiers::MBQI_FMC
||
101 options::mbqiMode()==quantifiers::MBQI_FMC_INTERVAL
|| options::fmfBoundInt() ||
102 options::mbqiMode()==quantifiers::MBQI_TRUST
){
103 d_model
= new quantifiers::fmcheck::FirstOrderModelFmc( this, c
, "FirstOrderModelFmc" );
104 }else if( options::mbqiMode()==quantifiers::MBQI_ABS
){
105 d_model
= new quantifiers::FirstOrderModelAbs( this, c
, "FirstOrderModelAbs" );
107 d_model
= new quantifiers::FirstOrderModelIG( this, c
, "FirstOrderModelIG" );
109 if( options::relevantTriggers() ){
110 d_quant_rel
= new QuantRelevance( false );
117 d_inst_engine
= NULL
;
120 d_anti_skolem
= NULL
;
121 d_model_engine
= NULL
;
125 d_lte_part_inst
= NULL
;
126 d_alpha_equiv
= NULL
;
127 d_fun_def_engine
= NULL
;
133 d_trackInstLemmas
= options::proof() && options::trackInstLemmas();
135 d_total_inst_count_debug
= 0;
136 //allow theory combination to go first, once initially
137 d_ierCounter
= options::instWhenTcFirst() ? 0 : 1;
138 d_ierCounter_c
= d_ierCounter
;
140 d_ierCounterLastLc
= 0;
141 d_inst_when_phase
= 1 + ( options::instWhenPhase()<1 ? 1 : options::instWhenPhase() );
144 QuantifiersEngine::~QuantifiersEngine(){
145 for(std::map
< Node
, inst::CDInstMatchTrie
* >::iterator
146 i
= d_c_inst_match_trie
.begin(), iend
= d_c_inst_match_trie
.end();
151 d_c_inst_match_trie
.clear();
153 delete d_alpha_equiv
;
157 delete d_model_engine
;
158 delete d_inst_engine
;
168 delete d_lte_part_inst
;
169 delete d_fun_def_engine
;
174 delete d_anti_skolem
;
178 EqualityQueryQuantifiersEngine
* QuantifiersEngine::getEqualityQuery() {
182 context::Context
* QuantifiersEngine::getSatContext(){
183 return d_te
->theoryOf( THEORY_QUANTIFIERS
)->getSatContext();
186 context::UserContext
* QuantifiersEngine::getUserContext(){
187 return d_te
->theoryOf( THEORY_QUANTIFIERS
)->getUserContext();
190 OutputChannel
& QuantifiersEngine::getOutputChannel(){
191 return d_te
->theoryOf( THEORY_QUANTIFIERS
)->getOutputChannel();
193 /** get default valuation for the quantifiers engine */
194 Valuation
& QuantifiersEngine::getValuation(){
195 return d_te
->theoryOf( THEORY_QUANTIFIERS
)->getValuation();
198 void QuantifiersEngine::finishInit(){
199 context::Context
* c
= getSatContext();
200 Trace("quant-engine-debug") << "QuantifiersEngine : finishInit " << std::endl
;
201 bool needsBuilder
= false;
202 bool needsRelDom
= false;
203 //add quantifiers modules
204 if( options::quantConflictFind() || options::quantRewriteRules() ){
205 d_qcf
= new quantifiers::QuantConflictFind( this, c
);
206 d_modules
.push_back( d_qcf
);
208 if( options::conjectureGen() ){
209 d_sg_gen
= new quantifiers::ConjectureGenerator( this, c
);
210 d_modules
.push_back( d_sg_gen
);
212 //maintain invariant : either InstantiationEngine or ModelEngine must be in d_modules
213 if( !options::finiteModelFind() || options::fmfInstEngine() ){
214 d_inst_engine
= new quantifiers::InstantiationEngine( this );
215 d_modules
.push_back( d_inst_engine
);
217 if( options::cbqi() ){
218 if( options::cbqiSplx() ){
219 d_i_cbqi
= new quantifiers::InstStrategySimplex( (arith::TheoryArith
*)getTheoryEngine()->theoryOf( THEORY_ARITH
), this );
220 d_modules
.push_back( d_i_cbqi
);
222 d_i_cbqi
= new quantifiers::InstStrategyCegqi( this );
223 d_modules
.push_back( d_i_cbqi
);
224 if( options::cbqiModel() ){
229 if( options::ceGuidedInst() ){
230 d_ceg_inst
= new quantifiers::CegInstantiation( this, c
);
231 d_modules
.push_back( d_ceg_inst
);
234 //finite model finding
235 if( options::finiteModelFind() ){
236 if( options::fmfBoundInt() ){
237 d_bint
= new quantifiers::BoundedIntegers( c
, this );
238 d_modules
.push_back( d_bint
);
240 d_model_engine
= new quantifiers::ModelEngine( c
, this );
241 d_modules
.push_back( d_model_engine
);
244 if( options::quantRewriteRules() ){
245 d_rr_engine
= new quantifiers::RewriteEngine( c
, this );
246 d_modules
.push_back(d_rr_engine
);
248 if( options::ltePartialInst() ){
249 d_lte_part_inst
= new quantifiers::LtePartialInst( this, c
);
250 d_modules
.push_back( d_lte_part_inst
);
252 if( ( options::finiteModelFind() && options::quantDynamicSplit()!=quantifiers::QUANT_DSPLIT_MODE_NONE
) ||
253 options::quantDynamicSplit()==quantifiers::QUANT_DSPLIT_MODE_AGG
){
254 d_qsplit
= new quantifiers::QuantDSplit( this, c
);
255 d_modules
.push_back( d_qsplit
);
257 if( options::quantAntiSkolem() ){
258 d_anti_skolem
= new quantifiers::QuantAntiSkolem( this );
259 d_modules
.push_back( d_anti_skolem
);
261 if( options::quantAlphaEquiv() ){
262 d_alpha_equiv
= new quantifiers::AlphaEquivalence( this );
264 //if( options::funDefs() ){
265 // d_fun_def_engine = new quantifiers::FunDefEngine( this, c );
266 // d_modules.push_back( d_fun_def_engine );
268 if( options::quantEqualityEngine() ){
269 d_uee
= new quantifiers::QuantEqualityEngine( this, c
);
270 d_modules
.push_back( d_uee
);
272 //full saturation : instantiate from relevant domain, then arbitrary terms
273 if( options::fullSaturateQuant() || options::fullSaturateInst() ){
274 d_fs
= new quantifiers::FullSaturation( this );
275 d_modules
.push_back( d_fs
);
280 d_rel_dom
= new quantifiers::RelevantDomain( this, d_model
);
281 d_util
.push_back( d_rel_dom
);
285 Trace("quant-engine-debug") << "Initialize model engine, mbqi : " << options::mbqiMode() << " " << options::fmfBoundInt() << std::endl
;
286 if( options::mbqiMode()==quantifiers::MBQI_FMC
|| options::mbqiMode()==quantifiers::MBQI_FMC_INTERVAL
||
287 options::mbqiMode()==quantifiers::MBQI_TRUST
|| options::fmfBoundInt() ){
288 Trace("quant-engine-debug") << "...make fmc builder." << std::endl
;
289 d_builder
= new quantifiers::fmcheck::FullModelChecker( c
, this );
290 }else if( options::mbqiMode()==quantifiers::MBQI_ABS
){
291 Trace("quant-engine-debug") << "...make abs mbqi builder." << std::endl
;
292 d_builder
= new quantifiers::AbsMbqiBuilder( c
, this );
294 Trace("quant-engine-debug") << "...make default model builder." << std::endl
;
295 d_builder
= new quantifiers::QModelBuilderDefault( c
, this );
301 QuantifiersModule
* QuantifiersEngine::getOwner( Node q
) {
302 std::map
< Node
, QuantifiersModule
* >::iterator it
= d_owner
.find( q
);
303 if( it
==d_owner
.end() ){
310 void QuantifiersEngine::setOwner( Node q
, QuantifiersModule
* m
, int priority
) {
311 QuantifiersModule
* mo
= getOwner( q
);
314 if( priority
<=d_owner_priority
[q
] ){
315 Trace("quant-warn") << "WARNING: setting owner of " << q
<< " to " << ( m
? m
->identify() : "null" ) << ", but already has owner " << mo
->identify() << " with higher priority!" << std::endl
;
320 d_owner_priority
[q
] = priority
;
324 bool QuantifiersEngine::hasOwnership( Node q
, QuantifiersModule
* m
) {
325 QuantifiersModule
* mo
= getOwner( q
);
326 return mo
==m
|| mo
==NULL
;
329 void QuantifiersEngine::presolve() {
330 Trace("quant-engine-proc") << "QuantifiersEngine : presolve " << std::endl
;
331 for( unsigned i
=0; i
<d_modules
.size(); i
++ ){
332 d_modules
[i
]->presolve();
334 d_term_db
->presolve();
336 //add all terms to database
337 if( options::incrementalSolving() ){
338 Trace("quant-engine-proc") << "Add presolve cache " << d_presolve_cache
.size() << std::endl
;
339 for( unsigned i
=0; i
<d_presolve_cache
.size(); i
++ ){
340 addTermToDatabase( d_presolve_cache
[i
], d_presolve_cache_wq
[i
], d_presolve_cache_wic
[i
] );
342 Trace("quant-engine-proc") << "Done add presolve cache " << std::endl
;
346 void QuantifiersEngine::check( Theory::Effort e
){
347 CodeTimer
codeTimer(d_statistics
.d_time
);
348 if( !getMasterEqualityEngine()->consistent() ){
349 Trace("quant-engine-debug") << "Master equality engine not consistent, return." << std::endl
;
352 bool needsCheck
= !d_lemmas_waiting
.empty();
353 unsigned needsModelE
= QEFFORT_NONE
;
354 std::vector
< QuantifiersModule
* > qm
;
355 if( d_model
->checkNeeded() ){
356 needsCheck
= needsCheck
|| e
>=Theory::EFFORT_LAST_CALL
; //always need to check at or above last call
357 for( unsigned i
=0; i
<d_modules
.size(); i
++ ){
358 if( d_modules
[i
]->needsCheck( e
) ){
359 qm
.push_back( d_modules
[i
] );
361 //can only request model at last call since theory combination can find inconsistencies
362 if( e
>=Theory::EFFORT_LAST_CALL
){
363 unsigned me
= d_modules
[i
]->needsModel( e
);
364 needsModelE
= me
<needsModelE
? me
: needsModelE
;
371 d_hasAddedLemma
= false;
372 bool setIncomplete
= false;
373 if( e
==Theory::EFFORT_LAST_CALL
){
374 //sources of incompleteness
375 if( d_lte_part_inst
&& d_lte_part_inst
->wasInvoked() ){
376 Trace("quant-engine-debug") << "Set incomplete due to LTE partial instantiation." << std::endl
;
377 setIncomplete
= true;
380 bool usedModelBuilder
= false;
382 Trace("quant-engine-debug2") << "Quantifiers Engine call to check, level = " << e
<< ", needsCheck=" << needsCheck
<< std::endl
;
384 //this will fail if a set of instances is marked as a conflict, but is not
385 Assert( !d_conflict_c
.get() );
386 //flush previous lemmas (for instance, if was interupted), or other lemmas to process
388 if( d_hasAddedLemma
){
391 if( !d_recorded_inst
.empty() ){
392 Trace("quant-engine-debug") << "Removing " << d_recorded_inst
.size() << " instantiations..." << std::endl
;
393 //remove explicitly recorded instantiations
394 for( unsigned i
=0; i
<d_recorded_inst
.size(); i
++ ){
395 removeInstantiationInternal( d_recorded_inst
[i
].first
, d_recorded_inst
[i
].second
);
397 d_recorded_inst
.clear();
401 if( Trace
.isOn("quant-engine") ){
402 clSet
= double(clock())/double(CLOCKS_PER_SEC
);
403 Trace("quant-engine") << ">>>>> Quantifiers Engine Round, effort = " << e
<< " <<<<<" << std::endl
;
406 if( Trace
.isOn("quant-engine-debug") ){
407 Trace("quant-engine-debug") << "Quantifiers Engine check, level = " << e
<< std::endl
;
408 Trace("quant-engine-debug") << " depth : " << d_ierCounter_c
<< std::endl
;
409 Trace("quant-engine-debug") << " modules to check : ";
410 for( unsigned i
=0; i
<qm
.size(); i
++ ){
411 Trace("quant-engine-debug") << qm
[i
]->identify() << " ";
413 Trace("quant-engine-debug") << std::endl
;
414 Trace("quant-engine-debug") << " # quantified formulas = " << d_model
->getNumAssertedQuantifiers() << std::endl
;
415 if( !d_lemmas_waiting
.empty() ){
416 Trace("quant-engine-debug") << " lemmas waiting = " << d_lemmas_waiting
.size() << std::endl
;
418 Trace("quant-engine-debug") << " Theory engine finished : " << !d_te
->needCheck() << std::endl
;
419 Trace("quant-engine-debug") << " Needs model effort : " << needsModelE
<< std::endl
;
421 if( Trace
.isOn("quant-engine-ee-pre") ){
422 Trace("quant-engine-ee-pre") << "Equality engine (pre-inference): " << std::endl
;
423 debugPrintEqualityEngine( "quant-engine-ee-pre" );
425 if( Trace
.isOn("quant-engine-assert") ){
426 Trace("quant-engine-assert") << "Assertions : " << std::endl
;
427 getTheoryEngine()->printAssertions("quant-engine-assert");
431 Trace("quant-engine-debug") << "Resetting all utilities..." << std::endl
;
432 for( unsigned i
=0; i
<d_util
.size(); i
++ ){
433 Trace("quant-engine-debug2") << "Reset " << d_util
[i
]->identify().c_str() << "..." << std::endl
;
434 if( !d_util
[i
]->reset( e
) ){
436 if( d_hasAddedLemma
){
439 //should only fail reset if added a lemma
445 if( Trace
.isOn("quant-engine-ee") ){
446 Trace("quant-engine-ee") << "Equality engine : " << std::endl
;
447 debugPrintEqualityEngine( "quant-engine-ee" );
451 Trace("quant-engine-debug") << "Reset model..." << std::endl
;
452 d_model
->reset_round();
455 Trace("quant-engine-debug") << "Resetting all modules..." << std::endl
;
456 for( unsigned i
=0; i
<d_modules
.size(); i
++ ){
457 Trace("quant-engine-debug2") << "Reset " << d_modules
[i
]->identify().c_str() << std::endl
;
458 d_modules
[i
]->reset_round( e
);
460 Trace("quant-engine-debug") << "Done resetting all modules." << std::endl
;
461 //reset may have added lemmas
463 if( d_hasAddedLemma
){
467 if( e
==Theory::EFFORT_LAST_CALL
){
468 //if effort is last call, try to minimize model first
469 //uf::StrongSolverTheoryUF * ufss = ((uf::TheoryUF*)getTheoryEngine()->theoryOf( THEORY_UF ))->getStrongSolver();
470 //if( ufss && !ufss->minimize() ){ return; }
471 ++(d_statistics
.d_instantiation_rounds_lc
);
472 }else if( e
==Theory::EFFORT_FULL
){
473 ++(d_statistics
.d_instantiation_rounds
);
475 Trace("quant-engine-debug") << "Check modules that needed check..." << std::endl
;
476 for( unsigned quant_e
= QEFFORT_CONFLICT
; quant_e
<=QEFFORT_LAST_CALL
; quant_e
++ ){
477 d_curr_effort_level
= quant_e
;
479 //build the model if any module requested it
480 if( needsModelE
==quant_e
){
481 Assert( d_builder
!=NULL
);
482 Trace("quant-engine-debug") << "Build model..." << std::endl
;
483 usedModelBuilder
= true;
484 d_builder
->d_addedLemmas
= 0;
485 d_builder
->buildModel( d_model
, false );
486 //we are done if model building was unsuccessful
487 if( d_builder
->d_addedLemmas
>0 ){
493 for( unsigned i
=0; i
<qm
.size(); i
++ ){
494 Trace("quant-engine-debug") << "Check " << qm
[i
]->identify().c_str() << " at effort " << quant_e
<< "..." << std::endl
;
495 qm
[i
]->check( e
, quant_e
);
497 Trace("quant-engine-debug") << "...conflict!" << std::endl
;
502 //flush all current lemmas
504 //if we have added one, stop
505 if( d_hasAddedLemma
){
508 Assert( !d_conflict
);
509 if( quant_e
==QEFFORT_CONFLICT
){
510 if( e
==Theory::EFFORT_FULL
){
511 //increment if a last call happened, we are not strictly enforcing interleaving, or already were in phase
512 if( d_ierCounterLastLc
!=d_ierCounter_lc
|| !options::instWhenStrictInterleave() || d_ierCounter
%d_inst_when_phase
!=0 ){
513 d_ierCounter
= d_ierCounter
+ 1;
514 d_ierCounterLastLc
= d_ierCounter_lc
;
515 d_ierCounter_c
= d_ierCounter_c
.get() + 1;
517 }else if( e
==Theory::EFFORT_LAST_CALL
){
518 d_ierCounter_lc
= d_ierCounter_lc
+ 1;
520 }else if( quant_e
==QEFFORT_MODEL
){
521 if( e
==Theory::EFFORT_LAST_CALL
){
522 if( !d_recorded_inst
.empty() ){
523 setIncomplete
= true;
525 //if we have a chance not to set incomplete
526 if( !setIncomplete
){
527 setIncomplete
= false;
528 //check if we should set the incomplete flag
529 for( unsigned i
=0; i
<qm
.size(); i
++ ){
530 if( !qm
[i
]->checkComplete() ){
531 Trace("quant-engine-debug") << "Set incomplete because " << qm
[i
]->identify().c_str() << " was incomplete." << std::endl
;
532 setIncomplete
= true;
537 //if setIncomplete = false, we will answer SAT, otherwise we will run at quant_e QEFFORT_LAST_CALL
538 if( !setIncomplete
){
545 d_curr_effort_level
= QEFFORT_NONE
;
546 Trace("quant-engine-debug") << "Done check modules that needed check." << std::endl
;
547 if( d_hasAddedLemma
){
549 if( Trace
.isOn("inst-per-quant-round") ){
550 for( std::map
< Node
, int >::iterator it
= d_temp_inst_debug
.begin(); it
!= d_temp_inst_debug
.end(); ++it
){
551 Trace("inst-per-quant-round") << " * " << it
->second
<< " for " << it
->first
<< std::endl
;
552 d_temp_inst_debug
[it
->first
] = 0;
556 if( Trace
.isOn("quant-engine") ){
557 double clSet2
= double(clock())/double(CLOCKS_PER_SEC
);
558 Trace("quant-engine") << "Finished quantifiers engine, total time = " << (clSet2
-clSet
);
559 Trace("quant-engine") << ", added lemma = " << d_hasAddedLemma
;
560 Trace("quant-engine") << std::endl
;
563 Trace("quant-engine-debug2") << "Finished quantifiers engine check." << std::endl
;
565 Trace("quant-engine-debug2") << "Quantifiers Engine does not need check." << std::endl
;
569 if( e
==Theory::EFFORT_LAST_CALL
&& !d_hasAddedLemma
){
570 if( options::produceModels() ){
571 if( usedModelBuilder
){
572 Trace("quant-engine-debug") << "Build completed model..." << std::endl
;
573 d_builder
->buildModel( d_model
, true );
574 }else if( !d_model
->isModelSet() ){
575 //use default model builder when no module built the model
576 Trace("quant-engine-debug") << "Build the model..." << std::endl
;
577 d_te
->getModelBuilder()->buildModel( d_model
, true );
578 Trace("quant-engine-debug") << "Done building the model." << std::endl
;
582 Trace("quant-engine") << "Set incomplete flag." << std::endl
;
583 getOutputChannel().setIncomplete();
586 if( Trace
.isOn("inst-per-quant") ){
587 for( std::map
< Node
, int >::iterator it
= d_total_inst_debug
.begin(); it
!= d_total_inst_debug
.end(); ++it
){
588 Trace("inst-per-quant") << " * " << it
->second
<< " for " << it
->first
<< std::endl
;
594 void QuantifiersEngine::notifyCombineTheories() {
595 //if allowing theory combination to happen at most once between instantiation rounds
597 //d_ierCounterLastLc = -1;
600 bool QuantifiersEngine::reduceQuantifier( Node q
) {
601 BoolMap::const_iterator it
= d_quants_red
.find( q
);
602 if( it
==d_quants_red
.end() ){
604 std::map
< Node
, Node
>::iterator itr
= d_quants_red_lem
.find( q
);
605 if( itr
==d_quants_red_lem
.end() ){
607 Trace("quant-engine-red") << "Alpha equivalence " << q
<< "?" << std::endl
;
608 //add equivalence with another quantified formula
609 lem
= d_alpha_equiv
->reduceQuantifier( q
);
611 Trace("quant-engine-red") << "...alpha equivalence success." << std::endl
;
612 ++(d_statistics
.d_red_alpha_equiv
);
615 d_quants_red_lem
[q
] = lem
;
620 getOutputChannel().lemma( lem
);
622 d_quants_red
[q
] = !lem
.isNull();
623 return !lem
.isNull();
629 bool QuantifiersEngine::registerQuantifier( Node f
){
630 std::map
< Node
, bool >::iterator it
= d_quants
.find( f
);
631 if( it
==d_quants
.end() ){
632 Trace("quant") << "QuantifiersEngine : Register quantifier ";
633 Trace("quant") << " : " << f
<< std::endl
;
634 ++(d_statistics
.d_num_quant
);
635 Assert( f
.getKind()==FORALL
);
637 //check whether we should apply a reduction
638 if( reduceQuantifier( f
) ){
639 Trace("quant") << "...reduced." << std::endl
;
643 //make instantiation constants for f
644 d_term_db
->makeInstantiationConstantsFor( f
);
645 d_term_db
->computeAttributes( f
);
646 for( unsigned i
=0; i
<d_modules
.size(); i
++ ){
647 Trace("quant-debug") << "pre-register with " << d_modules
[i
]->identify() << "..." << std::endl
;
648 d_modules
[i
]->preRegisterQuantifier( f
);
650 QuantifiersModule
* qm
= getOwner( f
);
652 Trace("quant") << " Owner : " << qm
->identify() << std::endl
;
654 //register with quantifier relevance
656 d_quant_rel
->registerQuantifier( f
);
658 //register with each module
659 for( unsigned i
=0; i
<d_modules
.size(); i
++ ){
660 Trace("quant-debug") << "register with " << d_modules
[i
]->identify() << "..." << std::endl
;
661 d_modules
[i
]->registerQuantifier( f
);
664 Node ceBody
= d_term_db
->getInstConstantBody( f
);
665 //also register it with the strong solver
666 //if( options::finiteModelFind() ){
667 // ((uf::TheoryUF*)d_te->theoryOf( THEORY_UF ))->getStrongSolver()->registerQuantifier( f );
677 void QuantifiersEngine::registerPattern( std::vector
<Node
> & pattern
) {
678 for(std::vector
<Node
>::iterator p
= pattern
.begin(); p
!= pattern
.end(); ++p
){
679 std::set
< Node
> added
;
680 getTermDatabase()->addTerm( *p
, added
);
684 void QuantifiersEngine::assertQuantifier( Node f
, bool pol
){
687 if( !reduceQuantifier( f
) ){
689 if( d_skolemized
.find( f
)==d_skolemized
.end() ){
690 Node body
= d_term_db
->getSkolemizedBody( f
);
691 NodeBuilder
<> nb(kind::OR
);
692 nb
<< f
<< body
.notNode();
694 if( Trace
.isOn("quantifiers-sk-debug") ){
695 Node slem
= Rewriter::rewrite( lem
);
696 Trace("quantifiers-sk-debug") << "Skolemize lemma : " << slem
<< std::endl
;
698 getOutputChannel().lemma( lem
, false, true );
699 d_skolemized
[f
] = true;
703 //assert to modules TODO : also for !pol?
704 //register the quantifier, assert it to each module
705 if( registerQuantifier( f
) ){
706 d_model
->assertQuantifier( f
);
707 for( int i
=0; i
<(int)d_modules
.size(); i
++ ){
708 d_modules
[i
]->assertNode( f
);
710 addTermToDatabase( d_term_db
->getInstConstantBody( f
), true );
715 void QuantifiersEngine::propagate( Theory::Effort level
){
716 CodeTimer
codeTimer(d_statistics
.d_time
);
718 for( int i
=0; i
<(int)d_modules
.size(); i
++ ){
719 d_modules
[i
]->propagate( level
);
723 Node
QuantifiersEngine::getNextDecisionRequest(){
724 for( unsigned i
=0; i
<d_modules
.size(); i
++ ){
725 Node n
= d_modules
[i
]->getNextDecisionRequest();
733 quantifiers::TermDbSygus
* QuantifiersEngine::getTermDatabaseSygus() {
734 return getTermDatabase()->getTermDatabaseSygus();
737 void QuantifiersEngine::addTermToDatabase( Node n
, bool withinQuant
, bool withinInstClosure
){
738 if( options::incrementalSolving() ){
739 if( d_presolve_in
.find( n
)==d_presolve_in
.end() ){
740 d_presolve_in
.insert( n
);
741 d_presolve_cache
.push_back( n
);
742 d_presolve_cache_wq
.push_back( withinQuant
);
743 d_presolve_cache_wic
.push_back( withinInstClosure
);
746 //only wait if we are doing incremental solving
747 if( !d_presolve
|| !options::incrementalSolving() ){
748 std::set
< Node
> added
;
749 getTermDatabase()->addTerm( n
, added
, withinQuant
, withinInstClosure
);
750 //maybe have triggered instantiations if we are doing eager instantiation
751 if( options::eagerInstQuant() ){
754 //added contains also the Node that just have been asserted in this branch
756 for( std::set
< Node
>::iterator i
=added
.begin(), end
=added
.end(); i
!=end
; i
++ ){
758 d_quant_rel
->setRelevance( i
->getOperator(), 0 );
765 void QuantifiersEngine::eqNotifyNewClass(TNode t
) {
766 addTermToDatabase( t
);
767 if( d_eq_query
->getEqualityInference() ){
768 d_eq_query
->getEqualityInference()->eqNotifyNewClass( t
);
772 void QuantifiersEngine::eqNotifyPreMerge(TNode t1
, TNode t2
) {
773 if( d_eq_query
->getEqualityInference() ){
774 d_eq_query
->getEqualityInference()->eqNotifyMerge( t1
, t2
);
778 void QuantifiersEngine::eqNotifyPostMerge(TNode t1
, TNode t2
) {
782 void QuantifiersEngine::eqNotifyDisequal(TNode t1
, TNode t2
, TNode reason
) {
784 // d_qcf->assertDisequal( t1, t2 );
788 void QuantifiersEngine::computeTermVector( Node f
, InstMatch
& m
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
){
789 for( size_t i
=0; i
<f
[0].getNumChildren(); i
++ ){
792 vars
.push_back( f
[0][i
] );
793 terms
.push_back( n
);
799 bool QuantifiersEngine::recordInstantiationInternal( Node q
, std::vector
< Node
>& terms
, bool modEq
, bool addedLem
) {
801 //record the instantiation for deletion later
802 d_recorded_inst
.push_back( std::pair
< Node
, std::vector
< Node
> >( q
, terms
) );
804 if( options::incrementalSolving() ){
805 Trace("inst-add-debug") << "Adding into context-dependent inst trie, modEq = " << modEq
<< std::endl
;
806 inst::CDInstMatchTrie
* imt
;
807 std::map
< Node
, inst::CDInstMatchTrie
* >::iterator it
= d_c_inst_match_trie
.find( q
);
808 if( it
!=d_c_inst_match_trie
.end() ){
811 imt
= new CDInstMatchTrie( getUserContext() );
812 d_c_inst_match_trie
[q
] = imt
;
814 return imt
->addInstMatch( this, q
, terms
, getUserContext(), modEq
);
816 Trace("inst-add-debug") << "Adding into inst trie" << std::endl
;
817 return d_inst_match_trie
[q
].addInstMatch( this, q
, terms
, modEq
);
821 bool QuantifiersEngine::removeInstantiationInternal( Node q
, std::vector
< Node
>& terms
) {
822 if( options::incrementalSolving() ){
823 std::map
< Node
, inst::CDInstMatchTrie
* >::iterator it
= d_c_inst_match_trie
.find( q
);
824 if( it
!=d_c_inst_match_trie
.end() ){
825 return it
->second
->removeInstMatch( this, q
, terms
);
830 return d_inst_match_trie
[q
].removeInstMatch( this, q
, terms
);
834 void QuantifiersEngine::setInstantiationLevelAttr( Node n
, Node qn
, uint64_t level
){
835 Trace("inst-level-debug2") << "IL : " << n
<< " " << qn
<< " " << level
<< std::endl
;
836 //if not from the vector of terms we instantiatied
837 if( qn
.getKind()!=BOUND_VARIABLE
&& n
!=qn
){
838 //if this is a new term, without an instantiation level
839 if( !n
.hasAttribute(InstLevelAttribute()) ){
840 InstLevelAttribute ila
;
841 n
.setAttribute(ila
,level
);
842 Trace("inst-level-debug") << "Set instantiation level " << n
<< " to " << level
<< std::endl
;
844 Assert( n
.getNumChildren()==qn
.getNumChildren() );
845 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
846 setInstantiationLevelAttr( n
[i
], qn
[i
], level
);
851 void QuantifiersEngine::setInstantiationLevelAttr( Node n
, uint64_t level
){
852 if( !n
.hasAttribute(InstLevelAttribute()) ){
853 InstLevelAttribute ila
;
854 n
.setAttribute(ila
,level
);
855 Trace("inst-level-debug") << "Set instantiation level " << n
<< " to " << level
<< std::endl
;
857 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
858 setInstantiationLevelAttr( n
[i
], level
);
862 Node
QuantifiersEngine::getSubstitute( Node n
, std::vector
< Node
>& terms
){
863 if( n
.getKind()==INST_CONSTANT
){
864 Debug("check-inst") << "Substitute inst constant : " << n
<< std::endl
;
865 return terms
[n
.getAttribute(InstVarNumAttribute())];
867 //if( !quantifiers::TermDb::hasInstConstAttr( n ) ){
868 //Debug("check-inst") << "No inst const attr : " << n << std::endl;
871 //Debug("check-inst") << "Recurse on : " << n << std::endl;
872 std::vector
< Node
> cc
;
873 if( n
.getMetaKind() == kind::metakind::PARAMETERIZED
){
874 cc
.push_back( n
.getOperator() );
876 bool changed
= false;
877 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
878 Node c
= getSubstitute( n
[i
], terms
);
880 changed
= changed
|| c
!=n
[i
];
883 Node ret
= NodeManager::currentNM()->mkNode( n
.getKind(), cc
);
892 Node
QuantifiersEngine::getInstantiation( Node q
, std::vector
< Node
>& vars
, std::vector
< Node
>& terms
, bool doVts
){
894 Assert( vars
.size()==terms
.size() );
895 //process partial instantiation if necessary
896 if( q
[0].getNumChildren()!=vars
.size() ){
897 body
= q
[ 1 ].substitute( vars
.begin(), vars
.end(), terms
.begin(), terms
.end() );
898 std::vector
< Node
> uninst_vars
;
899 //doing a partial instantiation, must add quantifier for all uninstantiated variables
900 for( unsigned i
=0; i
<q
[0].getNumChildren(); i
++ ){
901 if( std::find( vars
.begin(), vars
.end(), q
[0][i
] )==vars
.end() ){
902 uninst_vars
.push_back( q
[0][i
] );
905 Trace("partial-inst") << "Partially instantiating with " << vars
.size() << " / " << q
[0].getNumChildren() << " for " << q
<< std::endl
;
906 Assert( !uninst_vars
.empty() );
907 Node bvl
= NodeManager::currentNM()->mkNode( BOUND_VAR_LIST
, uninst_vars
);
908 body
= NodeManager::currentNM()->mkNode( FORALL
, bvl
, body
);
909 Trace("partial-inst") << "Partial instantiation : " << q
<< std::endl
;
910 Trace("partial-inst") << " : " << body
<< std::endl
;
912 if( options::cbqi() ){
913 body
= q
[ 1 ].substitute( vars
.begin(), vars
.end(), terms
.begin(), terms
.end() );
915 //do optimized version
916 Node icb
= d_term_db
->getInstConstantBody( q
);
917 body
= getSubstitute( icb
, terms
);
918 if( Debug
.isOn("check-inst") ){
919 Node body2
= q
[ 1 ].substitute( vars
.begin(), vars
.end(), terms
.begin(), terms
.end() );
921 Debug("check-inst") << "Substitution is wrong : " << body
<< " " << body2
<< std::endl
;
927 //do virtual term substitution
928 body
= Rewriter::rewrite( body
);
929 Trace("quant-vts-debug") << "Rewrite vts symbols in " << body
<< std::endl
;
930 Node body_r
= d_term_db
->rewriteVtsSymbols( body
);
931 Trace("quant-vts-debug") << " ...result: " << body_r
<< std::endl
;
937 Node
QuantifiersEngine::getInstantiation( Node q
, InstMatch
& m
, bool doVts
){
938 std::vector
< Node
> vars
;
939 std::vector
< Node
> terms
;
940 computeTermVector( q
, m
, vars
, terms
);
941 return getInstantiation( q
, vars
, terms
, doVts
);
944 Node
QuantifiersEngine::getInstantiation( Node q
, std::vector
< Node
>& terms
, bool doVts
) {
945 Assert( d_term_db
->d_vars
.find( q
)!=d_term_db
->d_vars
.end() );
946 return getInstantiation( q
, d_term_db
->d_vars
[q
], terms
, doVts
);
950 bool QuantifiersEngine::existsInstantiation( Node f, InstMatch& m, bool modEq ){
951 if( options::incrementalSolving() ){
952 if( d_c_inst_match_trie.find( f )!=d_c_inst_match_trie.end() ){
953 if( d_c_inst_match_trie[f]->existsInstMatch( this, f, m, getUserContext(), modEq ) ){
958 if( d_inst_match_trie.find( f )!=d_inst_match_trie.end() ){
959 if( d_inst_match_trie[f].existsInstMatch( this, f, m, modEq ) ){
968 bool QuantifiersEngine::addLemma( Node lem
, bool doCache
, bool doRewrite
){
971 lem
= Rewriter::rewrite(lem
);
973 Trace("inst-add-debug") << "Adding lemma : " << lem
<< std::endl
;
974 BoolMap::const_iterator itp
= d_lemmas_produced_c
.find( lem
);
975 if( itp
==d_lemmas_produced_c
.end() || !(*itp
).second
){
976 //d_curr_out->lemma( lem, false, true );
977 d_lemmas_produced_c
[ lem
] = true;
978 d_lemmas_waiting
.push_back( lem
);
979 Trace("inst-add-debug") << "Added lemma" << std::endl
;
982 Trace("inst-add-debug") << "Duplicate." << std::endl
;
986 //do not need to rewrite, will be rewritten after sending
987 d_lemmas_waiting
.push_back( lem
);
992 bool QuantifiersEngine::removeLemma( Node lem
) {
993 std::vector
< Node
>::iterator it
= std::find( d_lemmas_waiting
.begin(), d_lemmas_waiting
.end(), lem
);
994 if( it
!=d_lemmas_waiting
.end() ){
995 d_lemmas_waiting
.erase( it
, it
+ 1 );
996 d_lemmas_produced_c
[ lem
] = false;
1003 void QuantifiersEngine::addRequirePhase( Node lit
, bool req
){
1004 d_phase_req_waiting
[lit
] = req
;
1007 bool QuantifiersEngine::addInstantiation( Node q
, InstMatch
& m
, bool mkRep
, bool modEq
, bool doVts
){
1008 std::vector
< Node
> terms
;
1009 m
.getTerms( q
, terms
);
1010 return addInstantiation( q
, terms
, mkRep
, modEq
, doVts
);
1013 bool QuantifiersEngine::addInstantiation( Node q
, std::vector
< Node
>& terms
, bool mkRep
, bool modEq
, bool doVts
) {
1014 // For resource-limiting (also does a time check).
1015 getOutputChannel().safePoint(options::quantifierStep());
1016 Assert( !d_conflict
);
1017 Assert( terms
.size()==q
[0].getNumChildren() );
1018 Trace("inst-add-debug") << "For quantified formula " << q
<< ", add instantiation: " << std::endl
;
1019 std::vector
< Node
> rlv_cond
;
1020 for( unsigned i
=0; i
<terms
.size(); i
++ ){
1021 Trace("inst-add-debug") << " " << q
[0][i
];
1022 Trace("inst-add-debug2") << " -> " << terms
[i
];
1023 if( terms
[i
].isNull() ){
1024 terms
[i
] = d_term_db
->getModelBasisTerm( q
[0][i
].getType() );
1027 //pick the best possible representative for instantiation, based on past use and simplicity of term
1028 terms
[i
] = d_eq_query
->getInternalRepresentative( terms
[i
], q
, i
);
1030 //ensure the type is correct
1031 terms
[i
] = quantifiers::TermDb::ensureType( terms
[i
], q
[0][i
].getType() );
1033 Trace("inst-add-debug") << " -> " << terms
[i
] << std::endl
;
1034 if( terms
[i
].isNull() ){
1035 Trace("inst-add-debug") << " --> Failed to make term vector, due to term/type restrictions." << std::endl
;
1038 //get relevancy conditions
1039 if( options::instRelevantCond() ){
1040 quantifiers::TermDb::getRelevancyCondition( terms
[i
], rlv_cond
);
1043 #ifdef CVC4_ASSERTIONS
1044 bool bad_inst
= false;
1045 if( quantifiers::TermDb::containsUninterpretedConstant( terms
[i
] ) ){
1046 Trace("inst") << "***& inst contains uninterpreted constant : " << terms
[i
] << std::endl
;
1048 }else if( !terms
[i
].getType().isSubtypeOf( q
[0][i
].getType() ) ){
1049 Trace("inst") << "***& inst bad type : " << terms
[i
] << " " << terms
[i
].getType() << "/" << q
[0][i
].getType() << std::endl
;
1051 }else if( options::cbqi() ){
1052 Node icf
= quantifiers::TermDb::getInstConstAttr(terms
[i
]);
1053 if( !icf
.isNull() ){
1055 Trace("inst") << "***& inst contains inst constant attr : " << terms
[i
] << std::endl
;
1057 }else if( quantifiers::TermDb::containsTerms( terms
[i
], d_term_db
->d_inst_constants
[q
] ) ){
1058 Trace("inst") << "***& inst contains inst constants : " << terms
[i
] << std::endl
;
1063 //this assertion is critical to soundness
1065 Trace("inst")<< "***& Bad Instantiate " << q
<< " with " << std::endl
;
1066 for( unsigned j
=0; j
<terms
.size(); j
++ ){
1067 Trace("inst") << " " << terms
[j
] << std::endl
;
1074 //check based on instantiation level
1075 if( options::instMaxLevel()!=-1 || options::lteRestrictInstClosure() ){
1076 for( unsigned i
=0; i
<terms
.size(); i
++ ){
1077 if( !d_term_db
->isTermEligibleForInstantiation( terms
[i
], q
, true ) ){
1083 //check for positive entailment
1084 if( options::instNoEntail() ){
1085 //TODO: check consistency of equality engine (if not aborting on utility's reset)
1086 std::map
< TNode
, TNode
> subs
;
1087 for( unsigned i
=0; i
<terms
.size(); i
++ ){
1088 subs
[q
[0][i
]] = terms
[i
];
1090 if( d_term_db
->isEntailed( q
[1], subs
, false, true ) ){
1091 Trace("inst-add-debug") << " --> Currently entailed." << std::endl
;
1094 //Node eval = d_term_db->evaluateTerm( q[1], subs, false, true );
1095 //Trace("ajr-temp") << "Instantiation evaluates to : " << std::endl;
1096 //Trace("ajr-temp") << " " << eval << std::endl;
1099 //check for term vector duplication
1100 bool alreadyExists
= !recordInstantiationInternal( q
, terms
, modEq
);
1101 if( alreadyExists
){
1102 Trace("inst-add-debug") << " --> Already exists." << std::endl
;
1103 ++(d_statistics
.d_inst_duplicate_eq
);
1107 //construct the instantiation
1108 Trace("inst-add-debug") << "Constructing instantiation..." << std::endl
;
1109 Assert( d_term_db
->d_vars
[q
].size()==terms
.size() );
1110 Node body
= getInstantiation( q
, d_term_db
->d_vars
[q
], terms
, doVts
); //do virtual term substitution
1111 Node orig_body
= body
;
1112 body
= quantifiers::QuantifiersRewriter::preprocess( body
, true );
1113 Trace("inst-debug") << "...preprocess to " << body
<< std::endl
;
1115 //construct the lemma
1116 Trace("inst-assert") << "(assert " << body
<< ")" << std::endl
;
1117 body
= Rewriter::rewrite(body
);
1119 if( rlv_cond
.empty() ){
1120 lem
= NodeManager::currentNM()->mkNode( kind::OR
, q
.negate(), body
);
1122 rlv_cond
.push_back( q
.negate() );
1123 rlv_cond
.push_back( body
);
1124 lem
= NodeManager::currentNM()->mkNode( kind::OR
, rlv_cond
);
1126 lem
= Rewriter::rewrite(lem
);
1128 //check for lemma duplication
1129 if( addLemma( lem
, true, false ) ){
1130 d_total_inst_debug
[q
]++;
1131 d_temp_inst_debug
[q
]++;
1132 d_total_inst_count_debug
++;
1133 if( Trace
.isOn("inst") ){
1134 Trace("inst") << "*** Instantiate " << q
<< " with " << std::endl
;
1135 for( unsigned i
=0; i
<terms
.size(); i
++ ){
1136 if( Trace
.isOn("inst") ){
1137 Trace("inst") << " " << terms
[i
];
1138 if( Trace
.isOn("inst-debug") ){
1139 Trace("inst-debug") << ", type=" << terms
[i
].getType() << ", var_type=" << q
[0][i
].getType();
1141 Trace("inst") << std::endl
;
1145 if( options::instMaxLevel()!=-1 ){
1147 //virtual term substitution/instantiation level features are incompatible
1150 uint64_t maxInstLevel
= 0;
1151 for( unsigned i
=0; i
<terms
.size(); i
++ ){
1152 if( terms
[i
].hasAttribute(InstLevelAttribute()) ){
1153 if( terms
[i
].getAttribute(InstLevelAttribute())>maxInstLevel
){
1154 maxInstLevel
= terms
[i
].getAttribute(InstLevelAttribute());
1158 setInstantiationLevelAttr( orig_body
, q
[1], maxInstLevel
+1 );
1161 if( d_curr_effort_level
>QEFFORT_CONFLICT
&& d_curr_effort_level
<QEFFORT_NONE
){
1163 for( unsigned j
=0; j
<d_inst_notify
.size(); j
++ ){
1164 if( !d_inst_notify
[j
]->notifyInstantiation( d_curr_effort_level
, q
, lem
, terms
, body
) ){
1165 Trace("inst-add-debug") << "...we are in conflict." << std::endl
;
1167 d_conflict_c
= true;
1168 Assert( !d_lemmas_waiting
.empty() );
1173 if( d_trackInstLemmas
){
1175 if( options::incrementalSolving() ){
1176 recorded
= d_c_inst_match_trie
[q
]->recordInstLemma( q
, terms
, lem
);
1178 recorded
= d_inst_match_trie
[q
].recordInstLemma( q
, terms
, lem
);
1180 Trace("inst-add-debug") << "...was recorded : " << recorded
<< std::endl
;
1183 Trace("inst-add-debug") << " --> Success." << std::endl
;
1184 ++(d_statistics
.d_instantiations
);
1187 Trace("inst-add-debug") << " --> Lemma already exists." << std::endl
;
1188 ++(d_statistics
.d_inst_duplicate
);
1193 bool QuantifiersEngine::removeInstantiation( Node q
, Node lem
, std::vector
< Node
>& terms
) {
1194 //lem must occur in d_waiting_lemmas
1195 if( removeLemma( lem
) ){
1196 return removeInstantiationInternal( q
, terms
);
1202 bool QuantifiersEngine::addSplit( Node n
, bool reqPhase
, bool reqPhasePol
){
1203 n
= Rewriter::rewrite( n
);
1204 Node lem
= NodeManager::currentNM()->mkNode( OR
, n
, n
.notNode() );
1205 if( addLemma( lem
) ){
1206 Debug("inst") << "*** Add split " << n
<< std::endl
;
1212 bool QuantifiersEngine::addSplitEquality( Node n1
, Node n2
, bool reqPhase
, bool reqPhasePol
){
1213 //Assert( !areEqual( n1, n2 ) );
1214 //Assert( !areDisequal( n1, n2 ) );
1215 Kind knd
= n1
.getType()==NodeManager::currentNM()->booleanType() ? IFF
: EQUAL
;
1216 Node fm
= NodeManager::currentNM()->mkNode( knd
, n1
, n2
);
1217 return addSplit( fm
);
1220 void QuantifiersEngine::markRelevant( Node q
) {
1221 d_model
->markRelevant( q
);
1224 bool QuantifiersEngine::getInstWhenNeedsCheck( Theory::Effort e
) {
1225 Trace("quant-engine-debug2") << "Get inst when needs check, counts=" << d_ierCounter
<< ", " << d_ierCounter_lc
<< std::endl
;
1226 //determine if we should perform check, based on instWhenMode
1227 bool performCheck
= false;
1228 if( options::instWhenMode()==quantifiers::INST_WHEN_FULL
){
1229 performCheck
= ( e
>= Theory::EFFORT_FULL
);
1230 }else if( options::instWhenMode()==quantifiers::INST_WHEN_FULL_DELAY
){
1231 performCheck
= ( e
>= Theory::EFFORT_FULL
) && !getTheoryEngine()->needCheck();
1232 }else if( options::instWhenMode()==quantifiers::INST_WHEN_FULL_LAST_CALL
){
1233 performCheck
= ( ( e
==Theory::EFFORT_FULL
&& d_ierCounter
%d_inst_when_phase
!=0 ) || e
==Theory::EFFORT_LAST_CALL
);
1234 }else if( options::instWhenMode()==quantifiers::INST_WHEN_FULL_DELAY_LAST_CALL
){
1235 performCheck
= ( ( e
==Theory::EFFORT_FULL
&& !getTheoryEngine()->needCheck() && d_ierCounter
%d_inst_when_phase
!=0 ) || e
==Theory::EFFORT_LAST_CALL
);
1236 }else if( options::instWhenMode()==quantifiers::INST_WHEN_LAST_CALL
){
1237 performCheck
= ( e
>= Theory::EFFORT_LAST_CALL
);
1239 performCheck
= true;
1241 if( e
==Theory::EFFORT_LAST_CALL
){
1242 //with bounded integers, skip every other last call,
1243 // since matching loops may occur with infinite quantification
1244 if( d_ierCounter_lc
%2==0 && options::fmfBoundInt() ){
1245 performCheck
= false;
1248 return performCheck
;
1251 quantifiers::UserPatMode
QuantifiersEngine::getInstUserPatMode() {
1252 if( options::userPatternsQuant()==quantifiers::USER_PAT_MODE_INTERLEAVE
){
1253 return d_ierCounter
%2==0 ? quantifiers::USER_PAT_MODE_USE
: quantifiers::USER_PAT_MODE_RESORT
;
1255 return options::userPatternsQuant();
1259 void QuantifiersEngine::flushLemmas(){
1260 if( !d_lemmas_waiting
.empty() ){
1261 //filter based on notify classes
1262 if( !d_inst_notify
.empty() ){
1263 unsigned prev_lem_sz
= d_lemmas_waiting
.size();
1264 for( unsigned j
=0; j
<d_inst_notify
.size(); j
++ ){
1265 d_inst_notify
[j
]->filterInstantiations();
1267 if( prev_lem_sz
!=d_lemmas_waiting
.size() ){
1268 Trace("quant-engine") << "...filtered instances : " << d_lemmas_waiting
.size() << " / " << prev_lem_sz
<< std::endl
;
1271 //take default output channel if none is provided
1272 d_hasAddedLemma
= true;
1273 for( unsigned i
=0; i
<d_lemmas_waiting
.size(); i
++ ){
1274 Trace("qe-lemma") << "Lemma : " << d_lemmas_waiting
[i
] << std::endl
;
1275 getOutputChannel().lemma( d_lemmas_waiting
[i
], false, true );
1277 d_lemmas_waiting
.clear();
1279 if( !d_phase_req_waiting
.empty() ){
1280 for( std::map
< Node
, bool >::iterator it
= d_phase_req_waiting
.begin(); it
!= d_phase_req_waiting
.end(); ++it
){
1281 Trace("qe-lemma") << "Require phase : " << it
->first
<< " -> " << it
->second
<< std::endl
;
1282 getOutputChannel().requirePhase( it
->first
, it
->second
);
1284 d_phase_req_waiting
.clear();
1288 bool QuantifiersEngine::getUnsatCoreLemmas( std::vector
< Node
>& active_lemmas
) {
1289 //only if unsat core available
1290 bool isUnsatCoreAvailable
= false;
1291 if( options::proof() ){
1292 isUnsatCoreAvailable
= ProofManager::currentPM()->unsatCoreAvailable();
1294 if( isUnsatCoreAvailable
){
1295 Trace("inst-unsat-core") << "Get instantiations in unsat core..." << std::endl
;
1296 ProofManager::currentPM()->getLemmasInUnsatCore(theory::THEORY_QUANTIFIERS
, active_lemmas
);
1297 if( Trace
.isOn("inst-unsat-core") ){
1298 Trace("inst-unsat-core") << "Quantifiers lemmas in unsat core: " << std::endl
;
1299 for (unsigned i
= 0; i
< active_lemmas
.size(); ++i
) {
1300 Trace("inst-unsat-core") << " " << active_lemmas
[i
] << std::endl
;
1302 Trace("inst-unsat-core") << std::endl
;
1310 void QuantifiersEngine::getExplanationForInstLemmas( std::vector
< Node
>& lems
, std::map
< Node
, Node
>& quant
, std::map
< Node
, std::vector
< Node
> >& tvec
) {
1311 if( d_trackInstLemmas
){
1312 if( options::incrementalSolving() ){
1313 for( std::map
< Node
, inst::CDInstMatchTrie
* >::iterator it
= d_c_inst_match_trie
.begin(); it
!= d_c_inst_match_trie
.end(); ++it
){
1314 it
->second
->getExplanationForInstLemmas( it
->first
, lems
, quant
, tvec
);
1317 for( std::map
< Node
, inst::InstMatchTrie
>::iterator it
= d_inst_match_trie
.begin(); it
!= d_inst_match_trie
.end(); ++it
){
1318 it
->second
.getExplanationForInstLemmas( it
->first
, lems
, quant
, tvec
);
1321 #ifdef CVC4_ASSERTIONS
1322 for( unsigned j
=0; j
<lems
.size(); j
++ ){
1323 Assert( quant
.find( lems
[j
] )!=quant
.end() );
1324 Assert( tvec
.find( lems
[j
] )!=tvec
.end() );
1332 void QuantifiersEngine::printInstantiations( std::ostream
& out
) {
1333 bool useUnsatCore
= false;
1334 std::vector
< Node
> active_lemmas
;
1335 if( d_trackInstLemmas
&& getUnsatCoreLemmas( active_lemmas
) ){
1336 useUnsatCore
= true;
1339 bool printed
= false;
1340 for( BoolMap::iterator it
= d_skolemized
.begin(); it
!= d_skolemized
.end(); ++it
){
1341 Node q
= (*it
).first
;
1343 out
<< "(skolem " << q
<< std::endl
;
1345 for( unsigned i
=0; i
<d_term_db
->d_skolem_constants
[q
].size(); i
++ ){
1346 if( i
>0 ){ out
<< " "; }
1347 out
<< d_term_db
->d_skolem_constants
[q
][i
];
1349 out
<< " )" << std::endl
;
1350 out
<< ")" << std::endl
;
1352 if( options::incrementalSolving() ){
1353 for( std::map
< Node
, inst::CDInstMatchTrie
* >::iterator it
= d_c_inst_match_trie
.begin(); it
!= d_c_inst_match_trie
.end(); ++it
){
1354 bool firstTime
= true;
1355 it
->second
->print( out
, it
->first
, firstTime
, useUnsatCore
, active_lemmas
);
1357 out
<< ")" << std::endl
;
1359 printed
= printed
|| !firstTime
;
1362 for( std::map
< Node
, inst::InstMatchTrie
>::iterator it
= d_inst_match_trie
.begin(); it
!= d_inst_match_trie
.end(); ++it
){
1363 bool firstTime
= true;
1364 it
->second
.print( out
, it
->first
, firstTime
, useUnsatCore
, active_lemmas
);
1366 out
<< ")" << std::endl
;
1368 printed
= printed
|| !firstTime
;
1372 out
<< "No instantiations" << std::endl
;
1376 void QuantifiersEngine::printSynthSolution( std::ostream
& out
) {
1378 d_ceg_inst
->printSynthSolution( out
);
1380 out
<< "Internal error : module for synth solution not found." << std::endl
;
1384 void QuantifiersEngine::getInstantiations( std::map
< Node
, std::vector
< Node
> >& insts
) {
1385 bool useUnsatCore
= false;
1386 std::vector
< Node
> active_lemmas
;
1387 if( d_trackInstLemmas
&& getUnsatCoreLemmas( active_lemmas
) ){
1388 useUnsatCore
= true;
1391 if( options::incrementalSolving() ){
1392 for( std::map
< Node
, inst::CDInstMatchTrie
* >::iterator it
= d_c_inst_match_trie
.begin(); it
!= d_c_inst_match_trie
.end(); ++it
){
1393 it
->second
->getInstantiations( insts
[it
->first
], it
->first
, this, useUnsatCore
, active_lemmas
);
1396 for( std::map
< Node
, inst::InstMatchTrie
>::iterator it
= d_inst_match_trie
.begin(); it
!= d_inst_match_trie
.end(); ++it
){
1397 it
->second
.getInstantiations( insts
[it
->first
], it
->first
, this, useUnsatCore
, active_lemmas
);
1402 QuantifiersEngine::Statistics::Statistics()
1403 : d_time("theory::QuantifiersEngine::time"),
1404 d_num_quant("QuantifiersEngine::Num_Quantifiers", 0),
1405 d_instantiation_rounds("QuantifiersEngine::Rounds_Instantiation_Full", 0),
1406 d_instantiation_rounds_lc("QuantifiersEngine::Rounds_Instantiation_Last_Call", 0),
1407 d_instantiations("QuantifiersEngine::Instantiations_Total", 0),
1408 d_inst_duplicate("QuantifiersEngine::Duplicate_Inst", 0),
1409 d_inst_duplicate_eq("QuantifiersEngine::Duplicate_Inst_Eq", 0),
1410 d_triggers("QuantifiersEngine::Triggers", 0),
1411 d_simple_triggers("QuantifiersEngine::Triggers_Simple", 0),
1412 d_multi_triggers("QuantifiersEngine::Triggers_Multi", 0),
1413 d_multi_trigger_instantiations("QuantifiersEngine::Multi_Trigger_Instantiations", 0),
1414 d_red_alpha_equiv("QuantifiersEngine::Reductions_Alpha_Equivalence", 0),
1415 d_red_lte_partial_inst("QuantifiersEngine::Reductions_Lte_Partial_Inst", 0),
1416 d_instantiations_user_patterns("QuantifiersEngine::Instantiations_User_Patterns", 0),
1417 d_instantiations_auto_gen("QuantifiersEngine::Instantiations_Auto_Gen", 0),
1418 d_instantiations_guess("QuantifiersEngine::Instantiations_Guess", 0),
1419 d_instantiations_cbqi_arith("QuantifiersEngine::Instantiations_Cbqi_Arith", 0)
1421 smtStatisticsRegistry()->registerStat(&d_time
);
1422 smtStatisticsRegistry()->registerStat(&d_num_quant
);
1423 smtStatisticsRegistry()->registerStat(&d_instantiation_rounds
);
1424 smtStatisticsRegistry()->registerStat(&d_instantiation_rounds_lc
);
1425 smtStatisticsRegistry()->registerStat(&d_instantiations
);
1426 smtStatisticsRegistry()->registerStat(&d_inst_duplicate
);
1427 smtStatisticsRegistry()->registerStat(&d_inst_duplicate_eq
);
1428 smtStatisticsRegistry()->registerStat(&d_triggers
);
1429 smtStatisticsRegistry()->registerStat(&d_simple_triggers
);
1430 smtStatisticsRegistry()->registerStat(&d_multi_triggers
);
1431 smtStatisticsRegistry()->registerStat(&d_multi_trigger_instantiations
);
1432 smtStatisticsRegistry()->registerStat(&d_red_alpha_equiv
);
1433 smtStatisticsRegistry()->registerStat(&d_red_lte_partial_inst
);
1434 smtStatisticsRegistry()->registerStat(&d_instantiations_user_patterns
);
1435 smtStatisticsRegistry()->registerStat(&d_instantiations_auto_gen
);
1436 smtStatisticsRegistry()->registerStat(&d_instantiations_guess
);
1437 smtStatisticsRegistry()->registerStat(&d_instantiations_cbqi_arith
);
1440 QuantifiersEngine::Statistics::~Statistics(){
1441 smtStatisticsRegistry()->unregisterStat(&d_time
);
1442 smtStatisticsRegistry()->unregisterStat(&d_num_quant
);
1443 smtStatisticsRegistry()->unregisterStat(&d_instantiation_rounds
);
1444 smtStatisticsRegistry()->unregisterStat(&d_instantiation_rounds_lc
);
1445 smtStatisticsRegistry()->unregisterStat(&d_instantiations
);
1446 smtStatisticsRegistry()->unregisterStat(&d_inst_duplicate
);
1447 smtStatisticsRegistry()->unregisterStat(&d_inst_duplicate_eq
);
1448 smtStatisticsRegistry()->unregisterStat(&d_triggers
);
1449 smtStatisticsRegistry()->unregisterStat(&d_simple_triggers
);
1450 smtStatisticsRegistry()->unregisterStat(&d_multi_triggers
);
1451 smtStatisticsRegistry()->unregisterStat(&d_multi_trigger_instantiations
);
1452 smtStatisticsRegistry()->unregisterStat(&d_red_alpha_equiv
);
1453 smtStatisticsRegistry()->unregisterStat(&d_red_lte_partial_inst
);
1454 smtStatisticsRegistry()->unregisterStat(&d_instantiations_user_patterns
);
1455 smtStatisticsRegistry()->unregisterStat(&d_instantiations_auto_gen
);
1456 smtStatisticsRegistry()->unregisterStat(&d_instantiations_guess
);
1457 smtStatisticsRegistry()->unregisterStat(&d_instantiations_cbqi_arith
);
1460 eq::EqualityEngine
* QuantifiersEngine::getMasterEqualityEngine(){
1461 return getTheoryEngine()->getMasterEqualityEngine();
1464 void QuantifiersEngine::debugPrintEqualityEngine( const char * c
) {
1465 eq::EqualityEngine
* ee
= getMasterEqualityEngine();
1466 eq::EqClassesIterator eqcs_i
= eq::EqClassesIterator( ee
);
1467 std::map
< TypeNode
, int > typ_num
;
1468 while( !eqcs_i
.isFinished() ){
1469 TNode r
= (*eqcs_i
);
1470 TypeNode tr
= r
.getType();
1471 if( typ_num
.find( tr
)==typ_num
.end() ){
1475 bool firstTime
= true;
1476 Trace(c
) << " " << r
;
1477 Trace(c
) << " : { ";
1478 eq::EqClassIterator eqc_i
= eq::EqClassIterator( r
, ee
);
1479 while( !eqc_i
.isFinished() ){
1483 Trace(c
) << std::endl
;
1486 Trace(c
) << " " << n
<< std::endl
;
1490 if( !firstTime
){ Trace(c
) << " "; }
1491 Trace(c
) << "}" << std::endl
;
1494 Trace(c
) << std::endl
;
1495 for( std::map
< TypeNode
, int >::iterator it
= typ_num
.begin(); it
!= typ_num
.end(); ++it
){
1496 Trace(c
) << "# eqc for " << it
->first
<< " : " << it
->second
<< std::endl
;
1501 EqualityQueryQuantifiersEngine::EqualityQueryQuantifiersEngine( context::Context
* c
, QuantifiersEngine
* qe
) : d_qe( qe
), d_eqi_counter( c
), d_reset_count( 0 ){
1502 if( options::inferArithTriggerEq() ){
1503 d_eq_inference
= new quantifiers::EqualityInference( c
, options::inferArithTriggerEqExp() );
1505 d_eq_inference
= NULL
;
1509 EqualityQueryQuantifiersEngine::~EqualityQueryQuantifiersEngine(){
1510 delete d_eq_inference
;
1513 bool EqualityQueryQuantifiersEngine::reset( Theory::Effort e
){
1516 return processInferences( e
);
1519 bool EqualityQueryQuantifiersEngine::processInferences( Theory::Effort e
) {
1520 if( options::inferArithTriggerEq() ){
1521 eq::EqualityEngine
* ee
= getEngine();
1522 //updated implementation
1523 while( d_eqi_counter
.get()<d_eq_inference
->getNumPendingMerges() ){
1524 Node eq
= d_eq_inference
->getPendingMerge( d_eqi_counter
.get() );
1525 Node eq_exp
= d_eq_inference
->getPendingMergeExplanation( d_eqi_counter
.get() );
1526 Trace("quant-engine-ee-proc") << "processInferences : Infer : " << eq
<< std::endl
;
1527 Trace("quant-engine-ee-proc") << " explanation : " << eq_exp
<< std::endl
;
1528 Assert( ee
->hasTerm( eq
[0] ) );
1529 Assert( ee
->hasTerm( eq
[1] ) );
1530 if( areDisequal( eq
[0], eq
[1] ) ){
1531 Trace("quant-engine-ee-proc") << "processInferences : Conflict : " << eq
<< std::endl
;
1532 if( Trace
.isOn("term-db-lemma") ){
1533 Trace("term-db-lemma") << "Disequal terms, equal by normalization : " << eq
[0] << " " << eq
[1] << "!!!!" << std::endl
;
1534 if( !d_qe
->getTheoryEngine()->needCheck() ){
1535 Trace("term-db-lemma") << " all theories passed with no lemmas." << std::endl
;
1536 //this should really never happen (implies arithmetic is incomplete when sharing is enabled)
1539 Trace("term-db-lemma") << " add split on : " << eq
<< std::endl
;
1541 d_qe
->addSplit( eq
);
1544 ee
->assertEquality( eq
, true, eq_exp
);
1545 d_eqi_counter
= d_eqi_counter
.get() + 1;
1548 Assert( ee
->consistent() );
1553 bool EqualityQueryQuantifiersEngine::hasTerm( Node a
){
1554 return getEngine()->hasTerm( a
);
1557 Node
EqualityQueryQuantifiersEngine::getRepresentative( Node a
){
1558 eq::EqualityEngine
* ee
= getEngine();
1559 if( ee
->hasTerm( a
) ){
1560 return ee
->getRepresentative( a
);
1566 bool EqualityQueryQuantifiersEngine::areEqual( Node a
, Node b
){
1570 eq::EqualityEngine
* ee
= getEngine();
1571 if( ee
->hasTerm( a
) && ee
->hasTerm( b
) ){
1572 return ee
->areEqual( a
, b
);
1579 bool EqualityQueryQuantifiersEngine::areDisequal( Node a
, Node b
){
1583 eq::EqualityEngine
* ee
= getEngine();
1584 if( ee
->hasTerm( a
) && ee
->hasTerm( b
) ){
1585 return ee
->areDisequal( a
, b
, false );
1587 return a
.isConst() && b
.isConst();
1592 Node
EqualityQueryQuantifiersEngine::getInternalRepresentative( Node a
, Node f
, int index
){
1593 Assert( f
.isNull() || f
.getKind()==FORALL
);
1594 Node r
= getRepresentative( a
);
1595 if( options::finiteModelFind() ){
1596 if( r
.isConst() && quantifiers::TermDb::containsUninterpretedConstant( r
) ){
1597 //map back from values assigned by model, if any
1598 if( d_qe
->getModel() ){
1599 std::map
< Node
, Node
>::iterator it
= d_qe
->getModel()->d_rep_set
.d_values_to_terms
.find( r
);
1600 if( it
!=d_qe
->getModel()->d_rep_set
.d_values_to_terms
.end() ){
1602 r
= getRepresentative( r
);
1604 if( r
.getType().isSort() ){
1605 Trace("internal-rep-warn") << "No representative for UF constant." << std::endl
;
1606 //should never happen : UF constants should never escape model
1613 if( options::quantRepMode()==quantifiers::QUANT_REP_MODE_EE
){
1616 TypeNode v_tn
= f
.isNull() ? a
.getType() : f
[0][index
].getType();
1617 std::map
< Node
, Node
>::iterator itir
= d_int_rep
[v_tn
].find( r
);
1618 if( itir
==d_int_rep
[v_tn
].end() ){
1619 //find best selection for representative
1621 //if( options::fmfRelevantDomain() && !f.isNull() ){
1622 // Trace("internal-rep-debug") << "Consult relevant domain to mkRep " << r << std::endl;
1623 // r_best = d_qe->getRelevantDomain()->getRelevantTerm( f, index, r );
1624 // Trace("internal-rep-debug") << "Returned " << r_best << " " << r << std::endl;
1626 std::vector
< Node
> eqc
;
1627 getEquivalenceClass( r
, eqc
);
1628 Trace("internal-rep-select") << "Choose representative for equivalence class : { ";
1629 for( unsigned i
=0; i
<eqc
.size(); i
++ ){
1630 if( i
>0 ) Trace("internal-rep-select") << ", ";
1631 Trace("internal-rep-select") << eqc
[i
];
1633 Trace("internal-rep-select") << " }, type = " << v_tn
<< std::endl
;
1634 int r_best_score
= -1;
1635 for( size_t i
=0; i
<eqc
.size(); i
++ ){
1636 int score
= getRepScore( eqc
[i
], f
, index
, v_tn
);
1638 if( r_best
.isNull() || ( score
>=0 && ( r_best_score
<0 || score
<r_best_score
) ) ){
1640 r_best_score
= score
;
1644 if( r_best
.isNull() ){
1645 Trace("internal-rep-warn") << "No valid choice for representative in eqc class." << std::endl
;
1648 //now, make sure that no other member of the class is an instance
1649 std::hash_map
<TNode
, Node
, TNodeHashFunction
> cache
;
1650 r_best
= getInstance( r_best
, eqc
, cache
);
1651 //store that this representative was chosen at this point
1652 if( d_rep_score
.find( r_best
)==d_rep_score
.end() ){
1653 d_rep_score
[ r_best
] = d_reset_count
;
1655 Trace("internal-rep-select") << "...Choose " << r_best
<< " with score " << r_best_score
<< std::endl
;
1656 Assert( r_best
.getType().isSubtypeOf( v_tn
) );
1657 d_int_rep
[v_tn
][r
] = r_best
;
1659 Trace("internal-rep-debug") << "rep( " << a
<< " ) = " << r
<< ", " << std::endl
;
1660 Trace("internal-rep-debug") << "int_rep( " << a
<< " ) = " << r_best
<< ", " << std::endl
;
1664 return itir
->second
;
1669 void EqualityQueryQuantifiersEngine::flattenRepresentatives( std::map
< TypeNode
, std::vector
< Node
> >& reps
) {
1670 //make sure internal representatives currently exist
1671 for( std::map
< TypeNode
, std::vector
< Node
> >::iterator it
= reps
.begin(); it
!= reps
.end(); ++it
){
1672 if( it
->first
.isSort() ){
1673 for( unsigned i
=0; i
<it
->second
.size(); i
++ ){
1674 Node r
= getInternalRepresentative( it
->second
[i
], Node::null(), 0 );
1678 Trace("internal-rep-flatten") << "---Flattening representatives : " << std::endl
;
1679 for( std::map
< TypeNode
, std::map
< Node
, Node
> >::iterator itt
= d_int_rep
.begin(); itt
!= d_int_rep
.end(); ++itt
){
1680 for( std::map
< Node
, Node
>::iterator it
= itt
->second
.begin(); it
!= itt
->second
.end(); ++it
){
1681 Trace("internal-rep-flatten") << itt
->first
<< " : irep( " << it
->first
<< " ) = " << it
->second
<< std::endl
;
1684 //store representatives for newly created terms
1685 std::map
< Node
, Node
> temp_rep_map
;
1690 for( std::map
< TypeNode
, std::map
< Node
, Node
> >::iterator itt
= d_int_rep
.begin(); itt
!= d_int_rep
.end(); ++itt
){
1691 for( std::map
< Node
, Node
>::iterator it
= itt
->second
.begin(); it
!= itt
->second
.end(); ++it
){
1692 if( it
->second
.getKind()==APPLY_UF
&& it
->second
.getType().isSort() ){
1693 Node ni
= it
->second
;
1694 std::vector
< Node
> cc
;
1695 cc
.push_back( it
->second
.getOperator() );
1696 bool changed
= false;
1697 for( unsigned j
=0; j
<ni
.getNumChildren(); j
++ ){
1698 if( ni
[j
].getType().isSort() ){
1699 Node r
= getRepresentative( ni
[j
] );
1700 if( itt
->second
.find( r
)==itt
->second
.end() ){
1701 Assert( temp_rep_map
.find( r
)!=temp_rep_map
.end() );
1702 r
= temp_rep_map
[r
];
1705 //found sub-term as instance
1706 Trace("internal-rep-flatten-debug") << "...Changed " << it
->second
<< " to subterm " << ni
[j
] << std::endl
;
1707 itt
->second
[it
->first
] = ni
[j
];
1712 Node ir
= itt
->second
[r
];
1724 Node n
= NodeManager::currentNM()->mkNode( APPLY_UF
, cc
);
1725 Trace("internal-rep-flatten-debug") << "...Changed " << it
->second
<< " to " << n
<< std::endl
;
1727 itt
->second
[it
->first
] = n
;
1728 temp_rep_map
[n
] = it
->first
;
1734 Trace("internal-rep-flatten") << "---After flattening : " << std::endl
;
1735 for( std::map
< TypeNode
, std::map
< Node
, Node
> >::iterator itt
= d_int_rep
.begin(); itt
!= d_int_rep
.end(); ++itt
){
1736 for( std::map
< Node
, Node
>::iterator it
= itt
->second
.begin(); it
!= itt
->second
.end(); ++it
){
1737 Trace("internal-rep-flatten") << itt
->first
<< " : irep( " << it
->first
<< " ) = " << it
->second
<< std::endl
;
1742 eq::EqualityEngine
* EqualityQueryQuantifiersEngine::getEngine(){
1743 return d_qe
->getMasterEqualityEngine();
1746 void EqualityQueryQuantifiersEngine::getEquivalenceClass( Node a
, std::vector
< Node
>& eqc
){
1747 eq::EqualityEngine
* ee
= getEngine();
1748 if( ee
->hasTerm( a
) ){
1749 Node rep
= ee
->getRepresentative( a
);
1750 eq::EqClassIterator
eqc_iter( rep
, ee
);
1751 while( !eqc_iter
.isFinished() ){
1752 eqc
.push_back( *eqc_iter
);
1758 //a should be in its equivalence class
1759 Assert( std::find( eqc
.begin(), eqc
.end(), a
)!=eqc
.end() );
1762 TNode
EqualityQueryQuantifiersEngine::getCongruentTerm( Node f
, std::vector
< TNode
>& args
) {
1763 return d_qe
->getTermDatabase()->getCongruentTerm( f
, args
);
1768 Node
EqualityQueryQuantifiersEngine::getInstance( Node n
, const std::vector
< Node
>& eqc
, std::hash_map
<TNode
, Node
, TNodeHashFunction
>& cache
){
1769 if(cache
.find(n
) != cache
.end()) {
1772 for( size_t i
=0; i
<n
.getNumChildren(); i
++ ){
1773 Node nn
= getInstance( n
[i
], eqc
, cache
);
1775 return cache
[n
] = nn
;
1778 if( std::find( eqc
.begin(), eqc
.end(), n
)!=eqc
.end() ){
1779 return cache
[n
] = n
;
1781 return cache
[n
] = Node::null();
1785 //-2 : invalid, -1 : undesired, otherwise : smaller the score, the better
1786 int EqualityQueryQuantifiersEngine::getRepScore( Node n
, Node f
, int index
, TypeNode v_tn
){
1787 if( options::cbqi() && quantifiers::TermDb::hasInstConstAttr(n
) ){ //reject
1789 }else if( !n
.getType().isSubtypeOf( v_tn
) ){ //reject if incorrect type
1791 }else if( options::lteRestrictInstClosure() && ( !d_qe
->getTermDatabase()->isInstClosure( n
) || !d_qe
->getTermDatabase()->hasTermCurrent( n
, false ) ) ){
1793 }else if( options::instMaxLevel()!=-1 ){
1794 //score prefer lowest instantiation level
1795 if( n
.hasAttribute(InstLevelAttribute()) ){
1796 return n
.getAttribute(InstLevelAttribute());
1798 return options::instLevelInputOnly() ? -1 : 0;
1801 if( options::quantRepMode()==quantifiers::QUANT_REP_MODE_FIRST
){
1802 //score prefers earliest use of this term as a representative
1803 return d_rep_score
.find( n
)==d_rep_score
.end() ? -1 : d_rep_score
[n
];
1805 Assert( options::quantRepMode()==quantifiers::QUANT_REP_MODE_DEPTH
);
1806 return quantifiers::TermDb::getTermDepth( n
);