From: ajreynol Date: Tue, 22 Sep 2015 12:28:33 +0000 (+0200) Subject: Improve ITE redundant branch elimination in quantifiers. X-Git-Tag: cvc5-1.0.0~6234 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ccd1638ac6b0eb93d62ca485c1f6d55966bdc056;p=cvc5.git Improve ITE redundant branch elimination in quantifiers. --- diff --git a/src/theory/quantifiers/quantifiers_rewriter.cpp b/src/theory/quantifiers/quantifiers_rewriter.cpp index 0fbf7e6a3..bf17867bf 100644 --- a/src/theory/quantifiers/quantifiers_rewriter.cpp +++ b/src/theory/quantifiers/quantifiers_rewriter.cpp @@ -416,7 +416,133 @@ void QuantifiersRewriter::computeDtTesterIteSplit( Node n, std::map< Node, Node } } +bool addEntailedCond( Node n, bool pol, std::map< Node, bool >& currCond, std::vector< Node >& new_cond ) { + std::map< Node, bool >::iterator it = currCond.find( n ); + if( it==currCond.end() ){ + Trace("quantifiers-rewrite-ite-debug") << "ITE cond : " << n << " -> " << pol << std::endl; + new_cond.push_back( n ); + currCond[n] = pol; + return true; + }else{ + Assert( it->second==pol ); + return false; + } +} + +void setEntailedCond( Node n, bool pol, std::map< Node, bool >& currCond, std::vector< Node >& new_cond ) { + if( ( n.getKind()==AND && pol ) || ( n.getKind()==OR && !pol ) ){ + for( unsigned i=0; i1 ); + if( pol ){ + for( unsigned i=0; imkNode( APPLY_TESTER, Node::fromExpr( dt[i].getTester() ), n[0] ); + addEntailedCond( t, false, currCond, new_cond ); + } + } + }else{ + if( dt.getNumConstructors()==2 ){ + int oindex = 1-index; + Node t = NodeManager::currentNM()->mkNode( APPLY_TESTER, Node::fromExpr( dt[oindex].getTester() ), n[0] ); + addEntailedCond( t, true, currCond, new_cond ); + } + } + } + } +} + +int getEntailedCond( Node n, std::map< Node, bool >& currCond ){ + std::map< Node, bool >::iterator it = currCond.find( n ); + if( it!=currCond.end() ){ + return it->second ? 1 : -1; + }else if( n.getKind()==AND || n.getKind()==OR ){ + bool hasZero = false; + for( unsigned i=0; i& currCond ) { + bool changed = false; + std::vector< Node > children; + for( size_t i=0; i new_cond; + if( body.getKind()==ITE && i>0 ){ + setEntailedCond( children[0], i==1, currCond, new_cond ); + } + bool newHasPol; + bool newPol; + QuantPhaseReq::getPolarity( body, i, hasPol, pol, newHasPol, newPol ); + Node nn = computeProcessIte( body[i], newHasPol, newPol, currCond ); + if( body.getKind()==ITE ){ + if( i==0 ){ + int res = getEntailedCond( nn, currCond ); + if( res==1 ){ + return computeProcessIte( body[1], hasPol, pol, currCond ); + }else if( res==-1 ){ + return computeProcessIte( body[2], hasPol, pol, currCond ); + } + }else{ + for( unsigned j=0; jmkNode( body.getKind(), children ); + } + if( body.getKind()==EQUAL && options::iteLiftQuant()!=ITE_LIFT_QUANT_MODE_NONE ){ for( size_t i=0; i<2; i++ ){ if( body[i].getKind()==ITE ){ @@ -481,40 +607,7 @@ Node QuantifiersRewriter::computeProcessIte( Node body, bool hasPol, bool pol, s } } } - bool changed = false; - std::vector< Node > children; - for( size_t i=0; i0 ){ - currCond[children[0]] = (i==1); - } - Node nn = computeProcessIte( body[i], newHasPol, newPol, currCond ); - if( body.getKind()==ITE && i==0 ){ - std::map< Node, bool >::iterator itc = currCond.find( nn ); - if( itc!=currCond.end() ){ - if( itc->second ){ - return computeProcessIte( body[1], hasPol, pol, currCond ); - }else{ - return computeProcessIte( body[2], hasPol, pol, currCond ); - } - } - } - children.push_back( nn ); - changed = changed || nn!=body[i]; - } - if( body.getKind()==ITE ){ - currCond.erase( children[0] ); - } - if( changed ){ - if( body.getMetaKind() == kind::metakind::PARAMETERIZED ){ - children.insert( children.begin(), body.getOperator() ); - } - return NodeManager::currentNM()->mkNode( body.getKind(), children ); - }else{ - return body; - } + return body; } Node QuantifiersRewriter::computeProcessIte2( Node body ){