d_match_pattern_type = pat.getType();
d_next = NULL;
d_matchPolicy = MATCH_GEN_DEFAULT;
+ d_eq_class_rel = false;
}
InstMatchGenerator::InstMatchGenerator() {
}
}
-void InstMatchGenerator::initialize( QuantifiersEngine* qe, std::vector< InstMatchGenerator * > & gens ){
+void InstMatchGenerator::initialize( Node q, QuantifiersEngine* qe, std::vector< InstMatchGenerator * > & gens ){
if( !d_pattern.isNull() ){
Debug("inst-match-gen") << "Pattern term is " << d_pattern << std::endl;
if( d_match_pattern.getKind()==NOT ){
//now, collect children of d_match_pattern
//int childMatchPolicy = MATCH_GEN_DEFAULT;
for( int i=0; i<(int)d_match_pattern.getNumChildren(); i++ ){
- if( quantifiers::TermDb::hasInstConstAttr(d_match_pattern[i]) ){
- InstMatchGenerator * cimg = Trigger::getInstMatchGenerator( d_match_pattern[i] );
+ Node qa = quantifiers::TermDb::getInstConstAttr(d_match_pattern[i]);
+ if( !qa.isNull() ){
+ InstMatchGenerator * cimg = Trigger::getInstMatchGenerator( q, d_match_pattern[i] );
if( cimg ){
d_children.push_back( cimg );
d_children_index.push_back( i );
gens.push_back( cimg );
d_children_types.push_back( 1 );
}else{
- d_var_num[i] = d_match_pattern[i].getAttribute(InstVarNumAttribute());
- d_children_types.push_back( 0 );
+ if( d_match_pattern[i].getKind()==INST_CONSTANT && qa==q ){
+ d_var_num[i] = d_match_pattern[i].getAttribute(InstVarNumAttribute());
+ d_children_types.push_back( 0 );
+ }else{
+ d_children_types.push_back( -1 );
+ }
}
}else{
d_children_types.push_back( -1 );
//store the equivalence class that we will call d_cg->reset( ... ) on
d_eq_class = d_pattern[1];
}
+ d_eq_class_rel = true;
Assert( Trigger::isAtomicTrigger( d_match_pattern ) );
//we are matching only in a particular equivalence class
d_cg = new inst::CandidateGeneratorQE( qe, d_match_pattern_op );
Assert( d_match_pattern.getKind()==INST_CONSTANT || t.getKind()==d_match_pattern.getKind() );
Assert( !Trigger::isAtomicTrigger( d_match_pattern ) || t.getOperator()==d_match_pattern.getOperator() );
//first, check if ground arguments are not equal, or a match is in conflict
+ Trace("matching-debug2") << "Setting immediate matches..." << std::endl;
for( int i=0; i<(int)d_match_pattern.getNumChildren(); i++ ){
if( d_children_types[i]==0 ){
Trace("matching-debug2") << "Setting " << d_var_num[i] << " to " << t[i] << "..." << std::endl;
}
}
}
+ Trace("matching-debug2") << "Done setting immediate matches, success = " << success << "." << std::endl;
//for variable matching
if( d_match_pattern.getKind()==INST_CONSTANT ){
bool addToPrev = m.get( d_var_num[0] ).isNull();
}
}
//for relational matching
- }else if( !d_eq_class.isNull() && d_eq_class.getKind()==INST_CONSTANT ){
+ }else if( d_eq_class_rel && d_eq_class.getKind()==INST_CONSTANT ){
int v = d_eq_class.getAttribute(InstVarNumAttribute());
//also must fit match to equivalence class
bool pol = d_pattern.getKind()!=NOT;
}
}
if( success ){
+ Trace("matching-debug2") << "Reset children..." << std::endl;
//now, fit children into match
//we will be requesting candidates for matching terms for each child
for( int i=0; i<(int)d_children.size(); i++ ){
d_children[i]->reset( t[ d_children_index[i] ], qe );
}
+ Trace("matching-debug2") << "Continue next " << d_next << std::endl;
success = continueNextMatch( f, m, qe );
}
if( !success ){
//we have a specific equivalence class in mind
//we are producing matches for f(E) ~ t, where E is a non-ground vector of terms, and t is a ground term
//just look in equivalence class of the RHS
- d_cg->reset( d_eq_class.getKind()==INST_CONSTANT ? Node::null() : d_eq_class );
+ d_cg->reset( d_eq_class_rel ? Node::null() : d_eq_class );
d_needsReset = false;
}
bool InstMatchGenerator::getNextMatch( Node f, InstMatch& m, QuantifiersEngine* qe ){
if( d_needsReset ){
Trace("matching") << "Reset not done yet, must do the reset..." << std::endl;
- reset( d_eq_class.getKind()==INST_CONSTANT ? Node::null() : d_eq_class, qe );
+ reset( d_eq_class_rel ? Node::null() : d_eq_class, qe );
}
m.d_matched = Node::null();
Trace("matching") << this << " " << d_match_pattern << " get next match " << m << " in eq class " << d_eq_class << std::endl;
if( !success ){
Trace("matching") << this << " failed, reset " << d_eq_class << std::endl;
//we failed, must reset
- reset( d_eq_class.getKind()==INST_CONSTANT ? Node::null() : d_eq_class, qe );
+ reset( d_eq_class_rel ? Node::null() : d_eq_class, qe );
}
return success;
}
}
-InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator( Node pat, QuantifiersEngine* qe ) {
+InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator( Node q, Node pat, QuantifiersEngine* qe ) {
std::vector< Node > pats;
pats.push_back( pat );
- return mkInstMatchGenerator( pats, qe );
+ return mkInstMatchGenerator( q, pats, qe );
}
-InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator( std::vector< Node >& pats, QuantifiersEngine* qe ) {
+InstMatchGenerator* InstMatchGenerator::mkInstMatchGenerator( Node q, std::vector< Node >& pats, QuantifiersEngine* qe ) {
size_t pCounter = 0;
InstMatchGenerator* prev = NULL;
InstMatchGenerator* oinit = NULL;
if( prev ){
prev->d_next = curr;
}
- curr->initialize(qe, gens);
+ curr->initialize(q, qe, gens);
prev = curr;
counter++;
}
for( int i=0; i<(int)pats.size(); i++ ){
Node n = pats[i];
//make the match generator
- d_children.push_back( InstMatchGenerator::mkInstMatchGenerator( n, qe ) );
+ d_children.push_back( InstMatchGenerator::mkInstMatchGenerator(f, n, qe ) );
//compute unique/shared variables
std::vector< int > unique_vars;
std::map< int, bool > shared_vars;
InstMatchGeneratorSimple::InstMatchGeneratorSimple( Node f, Node pat ) : d_f( f ), d_match_pattern( pat ) {
for( unsigned i=0; i<d_match_pattern.getNumChildren(); i++ ){
if( d_match_pattern[i].getKind()==INST_CONSTANT ){
- d_var_num[i] = d_match_pattern[i].getAttribute(InstVarNumAttribute());
+ if( !options::cbqi() || quantifiers::TermDb::getInstConstAttr(d_match_pattern[i])==f ){
+ d_var_num[i] = d_match_pattern[i].getAttribute(InstVarNumAttribute());
+ }else{
+ d_var_num[i] = -1;
+ }
}
d_match_pattern_arg_types.push_back( d_match_pattern[i].getType() );
}
}else{
if( d_match_pattern[argIndex].getKind()==INST_CONSTANT ){
int v = d_var_num[argIndex];
- for( std::map< TNode, quantifiers::TermArgTrie >::iterator it = tat->d_data.begin(); it != tat->d_data.end(); ++it ){
- Node t = it->first;
- Node prev = m.get( v );
- //using representatives, just check if equal
- if( ( prev.isNull() || prev==t ) && t.getType().isSubtypeOf( d_match_pattern_arg_types[argIndex] ) ){
- m.setValue( v, t);
- addInstantiations( m, qe, addedLemmas, argIndex+1, &(it->second) );
- m.setValue( v, prev);
+ if( v!=-1 ){
+ for( std::map< TNode, quantifiers::TermArgTrie >::iterator it = tat->d_data.begin(); it != tat->d_data.end(); ++it ){
+ Node t = it->first;
+ Node prev = m.get( v );
+ //using representatives, just check if equal
+ if( ( prev.isNull() || prev==t ) && t.getType().isSubtypeOf( d_match_pattern_arg_types[argIndex] ) ){
+ m.setValue( v, t);
+ addInstantiations( m, qe, addedLemmas, argIndex+1, &(it->second) );
+ m.setValue( v, prev);
+ }
}
+ return;
}
- }else{
- Node r = qe->getEqualityQuery()->getRepresentative( d_match_pattern[argIndex] );
- std::map< TNode, quantifiers::TermArgTrie >::iterator it = tat->d_data.find( r );
- if( it!=tat->d_data.end() ){
- addInstantiations( m, qe, addedLemmas, argIndex+1, &(it->second) );
- }
+ }
+ Node r = qe->getEqualityQuery()->getRepresentative( d_match_pattern[argIndex] );
+ std::map< TNode, quantifiers::TermArgTrie >::iterator it = tat->d_data.find( r );
+ if( it!=tat->d_data.end() ){
+ addInstantiations( m, qe, addedLemmas, argIndex+1, &(it->second) );
}
}
}