CVC3

LFSCConvert.cpp

Go to the documentation of this file.
00001 #include "LFSCConvert.h"
00002 
00003 #include "LFSCUtilProof.h"
00004 #include "LFSCBoolProof.h"
00005 #include "LFSCLraProof.h"
00006 
00007 std::map< Expr, int > vMap;
00008 
00009 LFSCConvert::LFSCConvert( int lfscm )
00010 {
00011   nodeCount = 0;
00012   nodeCountTh = 0;
00013   unodeCount = 0;
00014   unodeCountTh = 0;
00015   ignore_theory_lemmas = lfsc_mode==22;
00016 }
00017 
00018 void LFSCConvert::convert( const Expr& pf ) 
00019 { 
00020   TReturn* tfinal = cvc3_to_lfsc( pf, false, false ); 
00021   pfinal = tfinal->getLFSCProof();
00022 
00023   //print out sat_lem if we are in clausal form
00024   if( tfinal->getProvesY()==3 ){
00025     ostringstream os1, os2;
00026     os1 << "(satlem _ _ _ ";
00027     os2 << "(\\ @done @done))" << endl;
00028     pfinal = LFSCProofGeneric::Make( os1.str(), pfinal.get(), os2.str() );
00029   }
00030 
00031   //print out all necessary proof let's
00032   pfinal = make_let_proof( pfinal.get() );
00033 
00034   //double ratio = (double)( nodeCountTh )/double( nodeCount + nodeCountTh );
00035   //cout << "Theory Node ratio : " << ratio << endl;
00036   //cout << "Node Count      : " << nodeCount << endl;
00037   //cout << "Th Node Count   : " << nodeCountTh << endl;
00038   //cout << "Total Count     : " << ( nodeCount + nodeCountTh ) << endl;
00039   //cout << (double)( nodeCountTh )/double( nodeCount + nodeCountTh ) << endl;
00040   //cout << "uNode Count     : " << unodeCount << endl;
00041   //cout << "Th uNode Count  : " << unodeCountTh << endl;
00042   //cout << "LFSC proof count: " << LFSCProof::get_proof_counter() << endl;
00043   //cout << "getNumNodes     : " << getNumNodes( pf, false ) << endl;
00044   //nnode_map.clear();
00045   //cout << "getNumNodes(rc) : " << getNumNodes( pf, true ) << endl;
00046   //cout << "map size 1      : " << (int)d_th_trans_map[1].size() << endl;
00047   //cout << "map size 2      : " << (int)d_th_trans_map[0].size() << endl;
00048   //std::map< Expr, int >::iterator vmIt = vMap.begin();
00049   //while( vmIt != vMap.end() ){
00050   //  cout << (*vmIt).first << ": " << (*vmIt).second << endl;
00051   //  ++vmIt;
00052   //}
00053   //exit( 0 );
00054 }
00055 
00056 // helper method to identify axioms of the form |- 0 = 0
00057 bool LFSCConvert::isTrivialTheoryAxiom(const Expr& expr, bool checkBody){
00058   if( expr[0]==d_plus_predicate_str || expr[0]==d_right_minus_left_str ||
00059       expr[0]==d_minus_to_plus_str || expr[0]==d_mult_ineqn_str ||
00060       expr[0]==d_canon_mult_str || expr[0]==d_canon_plus_str ||
00061       expr[0]==d_flip_inequality_str || expr[0]==d_negated_inequality_str ||
00062       expr[0]==d_rewrite_eq_symm_str || expr[0]==d_refl_str ||
00063       expr[0]==d_mult_eqn_str || expr[0]==d_canon_invert_divide_str ||
00064       expr[0]==d_rewrite_eq_refl_str || expr[0]==d_uminus_to_mult_str ||
00065       expr[0]==d_rewrite_not_true_str || expr[0]==d_rewrite_not_false_str ||
00066       expr[0]==d_int_const_eq_str ){
00067     Expr pe;
00068     Expr yexpr;
00069     if( !checkBody || ( what_is_proven( expr, pe ) && getY( pe, yexpr ) ) ){
00070       return true;
00071     }else{
00072       //cout << "Trivial theory axiom with bad arguments : " << expr[0] << std::endl;
00073     }
00074   }
00075   return false;
00076   //FIXME: should rewrite_not_true be used in theory lemma?    expr==d_rewrite_not_true_str
00077 }
00078 
00079 bool LFSCConvert::isTrivialBooleanAxiom(const Expr& expr)
00080 {
00081   return ( expr==d_rewrite_not_not_str );
00082 }
00083 
00084 
00085 // *****NOTE that these rules must have a subproof expr[2]
00086 bool LFSCConvert::isIgnoredRule(const Expr& expr)
00087 {
00088   return ( expr==d_iff_not_false_str || expr==d_iff_true_str ||
00089            expr==d_iff_false_elim_str || expr==d_iff_true_elim_str ||
00090            expr==d_not_not_elim_str || expr==d_not_to_iff_str );
00091 }
00092 
00093 TReturn* LFSCConvert::cvc3_to_lfsc(const Expr& pf, bool beneath_lc, bool rev_pol){
00094   if( beneath_lc )
00095     nodeCountTh++;
00096   else
00097     nodeCount++;
00098   if( lfsc_mode==5){
00099     cvc3_mimic = cvc3_mimic_input || !beneath_lc;
00100   }
00101   int cvcm = cvc3_mimic ? 1 : 0;
00102   TReturn* tRetVal = NULL;
00103   //if( !tRetVal && cvcm==0 ){
00104   //  tRetVal = d_th_trans_map[1][pf];
00105   //}
00106   if( d_th_trans_map[cvcm].find( pf )!=d_th_trans_map[cvcm].end() ){
00107     tRetVal = d_th_trans_map[cvcm][pf];
00108     if( d_th_trans_lam[cvcm].find( tRetVal )==d_th_trans_lam[cvcm].end() ){
00109       if( debug_conv )
00110         cout << "set th_trans" << std::endl;
00111       //set this TReturn to be lambda'ed into a let proof
00112       d_th_trans_lam[cvcm][tRetVal] = true;
00113     }
00114     return tRetVal;
00115   }
00116 
00117   if( beneath_lc )
00118     unodeCountTh++;
00119   else
00120     unodeCount++;
00121 
00122   //if( (unodeCountTh + unodeCount)%10000==0 )
00123   //  cout << unodeCount << " " << unodeCountTh << endl;
00124   //if( pf.isSelected() )
00125   //  std::cout << "already did this one?" << std::endl;
00126 
00127   if( vMap.find( pf[0] )==vMap.end() ){
00128     vMap[ pf[0] ] = 0;
00129   }
00130   vMap[ pf[0] ]++;
00131 
00132 
00133   std::vector< int > emptyL;
00134   std::vector< int > emptyLUsed;
00135   int yMode = -2;
00136   ostringstream ose;
00137   if( debug_conv ){
00138     cout << "handle ";
00139     pf[0].print();
00140   }
00141   Expr pfMod;
00142   int pfPat = get_proof_pattern( pf, pfMod );
00143   if( pfPat==0 )
00144   {
00145     if (pf[0] == d_CNF_str ){
00146       RefPtr< LFSCProof > p = LFSCProof::Make_CNF( pf[2], pf[1], pf[4].getRational().getNumerator().getInt() );
00147       if( p.get() )
00148       {
00149         tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 3 );
00150       }
00151     }
00152     else if( pf[0] == d_CNFITE_str ){
00153       if( pf[5].isRational() ){
00154         RefPtr< LFSCProof > p = LFSCProof::Make_CNF( pf[1], d_ite_s, pf[5].getRational().getNumerator().getInt() );
00155         if( p.get() ){
00156           tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 3 );
00157         }
00158       }
00159     }else if( pf[0] == d_cnf_add_unit_str ){
00160       TReturn* t = cvc3_to_lfsc( pf[2] );
00161       yMode = TReturn::normalize_tr( pf[2], t, 3 );
00162       if( yMode==3 ){
00163         tRetVal = t;
00164       }
00165     }
00166     else if( pf[0] == d_cnf_convert_str ){
00167       if( pf.arity()>3 ){
00168         if( ignore_theory_lemmas && pf[3][0]==d_learned_clause_str ){
00169           TReturn* t = make_trusted( pf );
00170           tRetVal = new TReturn( LFSCClausify::Make( pf[1], t->getLFSCProof(), true ), emptyL, emptyLUsed, nullRat, false, 3 );
00171         }else{
00172           TReturn* t = cvc3_to_lfsc( pf[3],beneath_lc, rev_pol);
00173           if( TReturn::normalize_tr( pf[3], t, 3, rev_pol )==3 ){
00174             RefPtr< LFSCProof > p = t->getLFSCProof();
00175             tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 3 );
00176           }
00177         }
00178       }
00179     }
00180     else if( pf[0] == d_bool_res_str ){
00181       //ajr_debug_print( pf );
00182       TReturn* t1 = cvc3_to_lfsc( pf[2],beneath_lc, rev_pol);
00183       TReturn* t2 = cvc3_to_lfsc( pf[3],beneath_lc, rev_pol);
00184       //t1->getL( emptyL, emptyLUsed );
00185       //t2->getL( emptyL, emptyLUsed );
00186       TReturn::normalize_tr( pf[2], t1, 3, rev_pol );
00187       TReturn::normalize_tr( pf[3], t2, 3, rev_pol );
00188       if( t1->getProvesY()==3 && t2->getProvesY()==3 ){
00189         tRetVal = new TReturn( LFSCBoolRes::Make( t1->getLFSCProof(), t2->getLFSCProof(), pf[1], pf ),
00190                             emptyL, emptyLUsed, nullRat, false, 3 );
00191       }
00192     }
00193     else if( pf[0] == d_minisat_proof_str ){
00194       tRetVal = cvc3_to_lfsc( pf[2] );
00195     }
00196     else if(pf[0]==d_assump_str){      //assumptions rule
00197       Expr ce = cascade_expr( pf[1] );
00198       int val = queryM( ce );
00199       RefPtr< LFSCProof > p;
00200       yMode = 0;
00201       if( d_assump_map.find( ce ) != d_assump_map.end() ){
00202         //cout << "This is an assumption: " << pf[1] << std::endl;
00203         p = LFSCPfVar::Make( "@F", abs( val ) );
00204         if( !cvc3_mimic ){
00205 #ifndef LRA2_PRIME
00206           p = LFSCProof::Make_not_not_elim( pf[1], p.get() );
00207 #endif
00208         }
00209       }else if( beneath_lc ){
00210         p = LFSCPfVar::MakeV( abs( val ) );
00211         if( cvc3_mimic ){
00212           //ostringstream os1, os2;
00213           //os1 << "(spec ";
00214           //RefPtr< LFSCProof > ps = LFSCProofExpr::Make( pf[1] );
00215           //os2 << ")";
00216           //p = LFSCProofGeneric::Make( os1.str(), p.get(), ps.get(), os2.str() );
00217           d_formulas_printed[queryAtomic( ce, true )] = true;
00218         }
00219 #ifdef OPTIMIZE
00220         p->assumeVarUsed = val;
00221 #else
00222         emptyLUsed.push_back( val );
00223 #endif
00224       }else{
00225         ostringstream os;
00226         os << "WARNING: Assuming a trusted formula: " << ce << std::endl;
00227         print_error( os.str().c_str(), cout );
00228         int valT = queryM( ce, true, true );
00229         p = LFSCPfVar::Make( "@T", abs( valT ) );
00230       }
00231       if( beneath_lc ){
00232 #ifdef OPTIMIZE
00233         p->assumeVar = val;
00234 #else
00235         emptyL.push_back( val );
00236 #endif
00237         if( !cvc3_mimic ){
00238           Expr ey;
00239           if( getY( ce, ey ) ){
00240             p = LFSCLraPoly::Make( ce, p.get() );
00241             yMode = 1;
00242           }else{
00243             ostringstream os;
00244             os << "WARNING: Beneath a learned clause and Y is not defined for assumption " << pf[1] << std::endl;
00245             print_error( os.str().c_str(), cout );
00246           }
00247         }
00248       }
00249       tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, yMode );
00250     }
00251     else if( pf[0] == d_iff_trans_str ){
00252       TReturn* t1 = cvc3_to_lfsc(pf[4],beneath_lc, rev_pol);
00253 #ifdef LRA2_PRIME
00254       if( ( isTrivialBooleanAxiom( pf[5][0] ) || pf[5][0]==d_rewrite_not_true_str ) && !cvc3_mimic  && t1->getProvesY()==1 ){ 
00255 #else
00256       if( ( isTrivialBooleanAxiom( pf[5][0] ) || pf[5][0]==d_rewrite_not_true_str ) && !cvc3_mimic  ){
00257 #endif
00258         tRetVal = t1;
00259       }else{
00260         TReturn* t2 = cvc3_to_lfsc(pf[5],beneath_lc, rev_pol);
00261         t1->getL( emptyL, emptyLUsed );
00262         t2->getL( emptyL, emptyLUsed );
00263         yMode = TReturn::normalize_tret( pf[4], t1, pf[5], t2, rev_pol );
00264         //case for arithmetic simplification
00265         if( yMode==1 )
00266         {
00267           int knd2 = queryAtomic( pf[2] ).getKind();
00268           int knd3 = queryAtomic( pf[3] ).getKind();
00269           //if we have an equation on the RHS
00270           if( is_eq_kind( knd3 ) )
00271           {
00272             RefPtr< LFSCProof > lfsc_pf = t1->getLFSCProof();
00273             if( t2->hasRational() )
00274               lfsc_pf = LFSCLraMulC::Make(t1->getLFSCProof(), t2->getRational(), EQ);
00275             LFSCLraAdd::Make( lfsc_pf.get(), t2->getLFSCProof(), EQ, EQ);
00276 
00277             Rational newR = t1->mult_rational( t2 );
00278             tRetVal = new TReturn(lfsc_pf.get(), emptyL, emptyLUsed, t1->mult_rational( t2 ), t1->hasRational() || t2->hasRational(),1);
00279           }
00280           else if( knd3==FALSE_EXPR || knd3==TRUE_EXPR )
00281           {
00282 #ifdef PRINT_MAJOR_METHODS
00283             cout << ";[M]: iff_trans, logical " << (knd3==TRUE_EXPR) << std::endl;
00284 #endif
00285             RefPtr< LFSCProof > p;
00286             if ( knd3==TRUE_EXPR ){
00287               p = LFSCLraAdd::Make( t1->getLFSCProof(), t2->getLFSCProof(), EQ, is_eq_kind( knd2 ) ? get_normalized( knd2, true ) : EQ );
00288             }else{
00289               p = LFSCLraSub::Make( t2->getLFSCProof(), t1->getLFSCProof(), is_eq_kind( knd2 ) ? get_normalized( knd2, true ) : EQ, EQ );
00290             }
00291             if( t1->hasRational() ){
00292               Rational r = 1/t1->getRational();
00293               p = LFSCLraMulC::Make( p.get(), r, is_eq_kind( knd2 ) ? get_normalized( knd2, true ) : EQ );
00294             }
00295             tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 1 );
00296           }
00297         }else if( yMode == 3 ){
00298 //#ifdef PRINT_MAJOR_METHODS
00299 //           cout << ";[M]: iff_trans, boolean " << std::endl;
00300 //#endif
00301 //          //resolving on the middle formula
00302 //          RefPtr< LFSCProof > p;
00303 //          if( rev_pol ){
00304 //            p = LFSCBoolRes::Make( t2->getLFSCProof(), t1->getLFSCProof(), pf[2], pf );
00305 //          }else{
00306 //            p = LFSCBoolRes::Make( t1->getLFSCProof(), t2->getLFSCProof(), pf[2], pf );
00307 //          }
00308           //tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, 1, 1, 3 );
00309         }else if( yMode == 0 || yMode==2 ){
00310           ostringstream os1;
00311           os1 << "(" << (yMode==0 ? "iff" : "impl" ) << "_trans _ _ _ ";
00312           //if( yMode==2 && t1->getLFSCProof()->get_string_length()<100 ){
00313           //  os1 << "[";
00314           //  t1->getLFSCProof()->print( os1, 0 );
00315           //  os1 << "]";
00316           //}
00317           ostringstream os2;
00318           os2 << ")";
00319 
00320           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() ),
00321                               emptyL, emptyLUsed, nullRat, false, yMode );
00322         }
00323       }
00324     }
00325     else if (pf[0] == d_iff_mp_str ){   //iff_mp rule
00326       TReturn* t1 = cvc3_to_lfsc(pf[3],beneath_lc);
00327 #ifdef LRA2_PRIME
00328       if( isTrivialBooleanAxiom( pf[4][0] ) && !cvc3_mimic && t1->getProvesY()==1 ){ 
00329 #else
00330       if( isTrivialBooleanAxiom( pf[4][0] ) && !cvc3_mimic ){
00331 #endif
00332         tRetVal = t1;
00333       }else{
00334         TReturn* t2 = cvc3_to_lfsc(pf[4],beneath_lc);
00335         t1->getL( emptyL, emptyLUsed );
00336         t2->getL( emptyL, emptyLUsed );
00337         if( t1->getProvesY()==1 && t2->getProvesY()==1 )
00338         {
00339           yMode = 1;
00340           int knd = queryAtomic( pf[1] ).getKind();
00341           int knd2 = queryAtomic( pf[2] ).getKind();
00342           if( is_eq_kind( knd2 ) )
00343           {
00344             RefPtr< LFSCProof > p = t1->getLFSCProof();
00345             if( t2->hasRational() )
00346               p = LFSCLraMulC::Make(p.get(), t2->getRational(), get_normalized( knd ));
00347             p = LFSCLraSub::Make( p.get(), t2->getLFSCProof(), get_normalized( knd ), EQ);
00348             tRetVal = new TReturn(p.get(), emptyL, emptyLUsed, t2->getRational(), t2->hasRational() , 1);
00349           }else if( knd2==FALSE_EXPR ){    //false case
00350 #ifdef PRINT_MAJOR_METHODS
00351             //cout << ";[M]: iff_mp, false" << std::endl;
00352 #endif
00353             //becomes a contradiction
00354             RefPtr< LFSCProof > p = t1->getLFSCProof();
00355             p = LFSCLraAdd::Make( p.get(), t2->getLFSCProof(),
00356                                   get_normalized( knd ),
00357                                   get_normalized( knd, true ) );
00358             p = LFSCLraContra::Make( p.get(), is_comparison( knd ) ? (int)GT : (int)DISTINCT );
00359             tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 1 );
00360           }
00361         }else if( t2->getProvesY()==3 || t1->getProvesY()==3 ){
00362 //          yMode = TReturn::normalize_tret( pf[3], t1, pf[4], t2, rev_pol );
00363 //          if( yMode==3 ){
00364 //#ifdef PRINT_MAJOR_METHODS
00365 //            cout << ";[M]: iff_mp, boolean" << std::endl;
00366 //#endif
00367 //            //do boolean resolution
00368 //            tRetVal = new TReturn( LFSCBoolRes::Make( t1->getLFSCProof(), t2->getLFSCProof(), pf[1], pf ),
00369 //                                emptyL, emptyLUsed, nullRat, false, 3 );
00370 //          }
00371         }else{
00372           if( t2->getProvesY()!=1 || TReturn::normalize_tr( pf[4], t2, 2, rev_pol )!=-1 ){
00373             if( t1->getProvesY()!=1 || TReturn::normalize_tr( pf[3], t1, 2, rev_pol )!=-1 ){
00374               ostringstream os1;
00375               os1 << "(" << (t2->getProvesY()==0 ? "iff" : "impl" ) << "_mp _ _ ";
00376               ostringstream os2;
00377               os2 << ")";
00378               tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
00379             }
00380           }
00381         }
00382       }
00383     }
00384     else if(pf[0]==d_iff_symm_str )
00385     {
00386       TReturn* t = cvc3_to_lfsc( pf[3], beneath_lc, !rev_pol );
00387       yMode = t->getProvesY();
00388       t->getL( emptyL, emptyLUsed );
00389       if( yMode==1 )
00390       {
00391 #ifdef PRINT_MAJOR_METHODS
00392         cout << ";[M]: iff_symm" << std::endl;
00393 #endif
00394         if( t->hasRational() ){
00395           Rational r = 1/t->getRational();
00396           //adding this
00397           Rational rNeg = -1/t->getRational();
00398           RefPtr< LFSCProof > p = LFSCLraMulC::Make( t->getLFSCProof(), rNeg, EQ );
00399           tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, r, true, 1 );
00400         }else{
00401           Rational r = Rational( -1 );
00402           RefPtr< LFSCProof > p = LFSCLraMulC::Make( t->getLFSCProof(), r, EQ );
00403           tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 1 );
00404         }
00405       }
00406       else if( yMode==0 )
00407       {
00408         tRetVal = new TReturn( LFSCProof::Make_mimic( pf, t->getLFSCProof(), 2 ), emptyL, emptyLUsed, t->getRational(), t->hasRational(), 0 );
00409       }
00410     }
00411     else if(pf[0]==d_impl_mp_str){ // impl_mp rule
00412       // get subproofs
00413       TReturn* t1 = cvc3_to_lfsc(pf[3],beneath_lc);
00414       TReturn* t2 = cvc3_to_lfsc(pf[4],beneath_lc);
00415       t1->getL( emptyL, emptyLUsed );
00416       t2->getL( emptyL, emptyLUsed );
00417       yMode = TReturn::normalize_tret( pf[3], t1, pf[4], t2);
00418       if( yMode==1 ){
00419         int knd1 = get_normalized( queryAtomic( pf[1] ).getKind() );
00420         int knd2 = get_normalized( queryAtomic( pf[2] ).getKind() );
00421         if( is_eq_kind( knd2 ) )
00422         {
00423 #ifdef PRINT_MAJOR_METHODS
00424           cout << ";[M]: impl_mp" << std::endl;
00425 #endif
00426           RefPtr< LFSCProof > p1 = LFSCLraAdd::Make( t1->getLFSCProof(), t2->getLFSCProof(), knd1, knd2 );
00427           // if non-homogenous case
00428           if( knd1 == GT && knd2 == GE ){
00429             ostringstream os1;
00430             os1 <<"(>0_to_>=0_Real _";
00431             ostringstream os2;
00432             os2 <<")";
00433             p1 = LFSCProofGeneric::Make(os1.str(), p1.get(), os2.str());
00434             p1->setChOp( GE );
00435           }
00436           tRetVal = new TReturn(p1.get(), emptyL, emptyLUsed, nullRat, false, 1);
00437         }else{
00438           cout << "Kind = " << kind_to_str( knd2 ) << std::endl;
00439         }
00440       }
00441       else
00442       {
00443         ostringstream os1, os2;
00444         os1 << "(impl_mp _ _ ";
00445         os2 << ")";
00446         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0);
00447       }
00448     }
00449     else if( pf[0]==d_basic_subst_op_str || pf[0]==d_basic_subst_op1_str )
00450     {
00451       if( pf.arity()==5 ){
00452         // get subproofs
00453         bool prevCvc3Mimic = cvc3_mimic;
00454 #ifdef LRA2_PRIME
00455         if( pf[1].getKind()==IFF || pf[1].getKind()==AND || pf[1].getKind()==OR && getNumNodes( pf )<=3 ){
00456 #else
00457         if( pf[1].getKind()==IFF ){
00458 #endif
00459           cvc3_mimic = true;
00460         }
00461 #ifdef PRINT_MAJOR_METHODS
00462         cout << ";[M]: basic_subst_op1 " << kind_to_str( pf[1].getKind() ) << std::endl;
00463 #endif
00464         //cvc3_mimic = (( pe1.getKind()==AND || pe1.getKind()==OR ) && getNumNodes( pf1 )<5 ) ? true : prevCvc3Mimic;
00465         TReturn* t1 = cvc3_to_lfsc(pf[3],beneath_lc, rev_pol);
00466         //cvc3_mimic = (( pe1.getKind()==AND || pe1.getKind()==OR ) && getNumNodes( pf2 )<5 ) ? true : prevCvc3Mimic;
00467         TReturn* t2 = cvc3_to_lfsc(pf[4],beneath_lc, rev_pol);
00468         cvc3_mimic = prevCvc3Mimic;
00469 
00470         tRetVal = do_bso( pf, beneath_lc, rev_pol, t1, t2, ose );
00471       }
00472     }
00473     else if( pf[0]==d_basic_subst_op0_str ){
00474       if( pf.arity()==4 ){
00475         TReturn* t = cvc3_to_lfsc(pf[3],beneath_lc, !rev_pol);
00476         yMode = t->getProvesY();
00477         t->getL( emptyL, emptyLUsed );
00478         if( yMode==1 ){
00479           if( pf[1].isNot() || pf[1].getKind()==UMINUS ){
00480             if( !pf[2][0].isFalse() && !pf[2][0].isTrue() ){
00481               RefPtr< LFSCProof > p = LFSCLraMulC::Make( t->getLFSCProof(), Rational( -1 ), EQ );
00482               tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, t->getRational(), t->hasRational(), 1 );
00483             }else{
00484               tRetVal = t;
00485             }
00486           }
00487         }else if( yMode==3 ){
00488         }else if( yMode==2 ){
00489           if( pf[1].isNot() )     //rev_pol should have switched things already
00490             tRetVal = t;
00491         }else if( yMode==0 ){
00492           ostringstream os1;
00493           os1 << "(basic_subst_op0_" << kind_to_str( pf[1].getKind() ) << " _ _ ";
00494           ostringstream os2;
00495           os2 << ")";
00496           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t->getLFSCProof(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
00497         }
00498       }
00499       if( !tRetVal ){
00500         ose << "subst0 kind = " << kind_to_str( pf[1].getKind() ) << std::endl;
00501         ose << "subst0 arity = " << pf.arity() << std::endl;
00502       }
00503     }
00504     else if( pf[0]==d_optimized_subst_op_str )
00505     {
00506       if( pf[1].getKind()==ITE ){
00507 #ifdef PRINT_MAJOR_METHODS
00508         cout << ";[M]: optimized_subst_op, ite " << std::endl;
00509 #endif
00510         //make reflexive proof of proven statement
00511         RefPtr< LFSCProof > p = LFSCProofExpr::Make( pf[1] );
00512 
00513         ostringstream os1, os2;
00514         if( isFormula( pf[1] ) ){
00515           os1 << "(iff_refl ";
00516         }else{
00517           os1 << "(refl Real ";
00518         }
00519         os2 << ")";
00520         p = LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() );
00521 
00522         bool success = true;
00523         for( int a=3; a<pf.arity(); a++ ){
00524           if( success ){
00525             success = false;
00526             Expr pe;
00527             if( what_is_proven( pf[a], pe ) )
00528             {
00529               int type = -1;
00530               for( int b=0; b<3; b++ ){
00531                 if( pe[0]==pf[1][b] )
00532                   type = b;
00533               }
00534               //set cvc3 mimic to true if we are proving an equivalence of the conditional formula
00535               bool prev_cvc3_mimic = cvc3_mimic;
00536               if( type==0 || isFormula( pf[1] ) )
00537                 cvc3_mimic = true;
00538 
00539               TReturn* t = cvc3_to_lfsc(pf[a],beneath_lc);
00540 
00541               cvc3_mimic = prev_cvc3_mimic;
00542 
00543               t->getL( emptyL, emptyLUsed );
00544               if( TReturn::normalize_tr( pf[a], t, 0 )==0 ){
00545                 if( type!=-1 ){
00546                   ostringstream os1, os2;
00547                   os1 << "(optimized_subst_op_";
00548                   if( isFormula( pf[1] ) )
00549                     os1 << "ifte";
00550                   else
00551                     os1 << "ite";
00552                   if( type==1 )
00553                     os1 << "_t1";
00554                   else if( type==2 )
00555                     os1 << "_t2";
00556                   os1 << " _ _ _ _ _ _ _ ";
00557                   os2 << ")";
00558                   p = LFSCProofGeneric::Make( os1.str(), p.get(), t->getLFSCProof(), os2.str() );
00559                   success = true;
00560                 }
00561               }
00562             }
00563           }
00564         }
00565         if( success ){
00566           tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 0 );
00567         }
00568       }else if( pf[1].getKind()==PLUS ){
00569         //cout << ";[M]: optimized_subst_op, plus " << std::endl;
00570         TReturn* t = cvc3_to_lfsc(pf[3],beneath_lc);
00571         yMode = t->getProvesY();
00572         t->getL( emptyL, emptyLUsed );
00573         if( t->getProvesY()==1 ){
00574           tRetVal = t;
00575         }else{
00576           //tRetVal = make_trusted( pf );
00577           Expr pe;
00578           if( what_is_proven( pf[3], pe ) )
00579           {
00580             if( pe.getKind()==EQ )
00581             {
00582               ostringstream os1, os2;
00583               os1 << "(canonize_conv _ _ _ _ _ _ ";
00584               int pnt1 = queryMt( Expr( MINUS, pe[0], pe[1] ) );
00585               int pnt2 = queryMt( Expr( MINUS, pf[1], pf[2] ) );
00586               os1 << "@pnt" << pnt1 << " @pnt" << pnt2 << " ";
00587               os2 << ")";
00588               pntNeeded[ pnt1 ] = true;
00589               pntNeeded[ pnt2 ] = true;
00590               tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t->getLFSCProof(), os2.str() ),
00591                                   emptyL, emptyLUsed, t->getRational(), t->hasRational(), 0 );
00592             }else{
00593               cout << "proving kind " << kind_to_str( pe.getKind() ) << std::endl;
00594               cout << pf[3][0] << " " << pe << std::endl;
00595             }
00596           }
00597         }
00598       }else{
00599         //tRetVal = make_trusted( pf );
00600         if( pf[1].arity()==pf.arity()-3 ){
00601 #ifdef PRINT_MAJOR_METHODS
00602           cout << ";[M]: optimized_subst_op, cascade " << kind_to_str( pf[1].getKind() ) << std::endl;
00603 #endif
00604           Expr pfn = pf[pf.arity()-1];
00605           Expr cf1 = pf[1][pf.arity()-4];
00606           Expr cf2 = pf[2][pf.arity()-4];
00607           tRetVal = cvc3_to_lfsc( pf[pf.arity()-1], beneath_lc, rev_pol );
00608           for( int a=(int)pf.arity()-2; a>=3; a-- ){
00609             cf1 = Expr( pf[1].getKind(), pf[1][a-3], cf1 );
00610             cf2 = Expr( pf[2].getKind(), pf[2][a-3], cf2 );
00611             std::vector < Expr > exprs;
00612             exprs.push_back( d_basic_subst_op1_str );
00613             exprs.push_back( cf1 );
00614             exprs.push_back( cf2 );
00615             exprs.push_back( pf[a] );
00616             exprs.push_back( pfn );
00617             //cascade it, turn it into a different proof
00618             pfn = Expr(PF_APPLY, exprs );
00619             TReturn* tc = cvc3_to_lfsc( pf[a], beneath_lc, rev_pol );
00620             tRetVal = do_bso( pfn, beneath_lc, rev_pol, tc, tRetVal, ose );
00621           }
00622         }else{
00623           ose << "opt_subst_op arity pv1 = " << pf[1].arity() << " " << pf.arity()-3 << std::endl;
00624           ose << "opt_subst_op arity pv2 = " << pf[2].arity() << " " << pf.arity()-3 << std::endl;
00625         }
00626       }
00627       if( !tRetVal ){
00628         for( int a=0; a<pf.arity(); a++ ){
00629           if( a>=3 && pf[a].arity()>0 ){
00630             ose << a << ": ";
00631             ose << pf[a][0] << std::endl;
00632             Expr pre;
00633             what_is_proven( pf[a], pre );
00634             ose << "wip: " << pre << std::endl;
00635           }else{
00636             ose << a << ": " << pf[a] << std::endl;
00637           }
00638         }
00639         //RefPtr< LFSCProof > p;
00640         //TReturn* curr = NULL;
00641         //for( int a=(int)(pf.arity()-1); a>=4; a-- ){
00642         //  TReturn* t = cvc3_to_lfsc(pf[a],beneath_lc);
00643         //  if( curr ){
00644         //    int cyMode = TReturn::normalize_tret(
00645         //    if( pf[1].getKind()==AND || pf[1].getKind()==OR ){
00646         //      ostringstream os1, os2;
00647         //      os1 << "(optimized_subst_op_";
00648         //      if( yMode==2 )
00649         //        os1 << "impl_";
00650         //      os1 << kind_to_str( pf[1].getKind() );
00651         //      os1 << " _ _ _ _ ";
00652         //      os2 << ")";
00653         //      p = LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() );
00654         //  }else{
00655         //    curr = t;
00656         //  }
00657         //  tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, t->getProvesY() );
00658         //}
00659         ose << "opt_subst_op kind = " << kind_to_str( pf[1].getKind() ) << std::endl;
00660         ose << "opt_subst_op arity = " << pf.arity() << std::endl;
00661       }
00662     }
00663     else if( pf[0]==d_eq_trans_str ){
00664       // get subproofs
00665       TReturn* t1 = cvc3_to_lfsc(pf[5],beneath_lc);
00666       TReturn* t2 = cvc3_to_lfsc(pf[6],beneath_lc);
00667       t1->getL( emptyL, emptyLUsed );
00668       t2->getL( emptyL, emptyLUsed );
00669       yMode = TReturn::normalize_tret( pf[5], t1, pf[6], t2 );
00670       if( yMode==1 ){
00671         // merge literals
00672         tRetVal = new TReturn( LFSCLraAdd::Make( t1->getLFSCProof(), t2->getLFSCProof(),
00673                                               EQ, EQ ), emptyL, emptyLUsed, nullRat, false, 1 );
00674       }else if( yMode==0 ){
00675         std::vector< RefPtr< LFSCProof > > pfs;
00676         std::vector< string > strs;
00677         ostringstream os1, os2, os3;
00678         os1 << "(trans Real ";
00679         os2 << " ";
00680         os3 << ")";
00681         pfs.push_back( LFSCProofExpr::Make( pf[2] ) );
00682         pfs.push_back( LFSCProofExpr::Make( pf[3] ) );
00683         pfs.push_back( LFSCProofExpr::Make( pf[4] ) );
00684         pfs.push_back( t1->getLFSCProof() );
00685         pfs.push_back( t2->getLFSCProof() );
00686         strs.push_back( os1.str() );
00687         strs.push_back( os2.str() );
00688         strs.push_back( os2.str() );
00689         strs.push_back( os2.str() );
00690         strs.push_back( os2.str() );
00691         strs.push_back( os3.str() );
00692         tRetVal = new TReturn( LFSCProofGeneric::Make( pfs, strs ), emptyL, emptyLUsed, nullRat, false, 0 );
00693       }
00694     }
00695     else if(pf[0] == d_eq_symm_str){ // eq_symm rule
00696       TReturn* t = cvc3_to_lfsc(pf[4],beneath_lc);
00697       t->getL( emptyL, emptyLUsed );
00698       if( t->getProvesY()==1 )
00699       {
00700         tRetVal = new TReturn(LFSCLraMulC::Make(t->getLFSCProof(), Rational( -1 ), EQ), emptyL, emptyLUsed, nullRat, false, 1);
00701       }
00702       else if( t->getProvesY()==0 )
00703       {
00704         ostringstream os1, os2;
00705         os1 << "(symm Real _ _ ";
00706         os2 << ")";
00707         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t->getLFSCProof(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0);
00708       }
00709     }
00710     else if( pf[0]==d_real_shadow_str )
00711     {
00712       // get subproofs
00713       TReturn* t1 = cvc3_to_lfsc(pf[3],beneath_lc);
00714       TReturn* t2 = cvc3_to_lfsc(pf[4],beneath_lc);
00715       t1->getL( emptyL, emptyLUsed );
00716       t2->getL( emptyL, emptyLUsed );
00717       yMode = TReturn::normalize_tret( pf[3], t1, pf[4], t2 );
00718       if( yMode==1 )
00719       {
00720         int op1 = get_normalized( queryAtomic( pf[1] ).getKind() );
00721         int op2 = get_normalized( queryAtomic( pf[2] ).getKind() );
00722         tRetVal = new TReturn( LFSCLraAdd::Make( t1->getLFSCProof(), t2->getLFSCProof(), op1, op2 ), emptyL, emptyLUsed, nullRat, false, 1 );
00723       }
00724       else if( yMode==0 )
00725       {
00726         ostringstream os1, os2;
00727         os1 << "(real_shadow_" << kind_to_str( pf[1].getKind() );
00728         os1 << "_" << kind_to_str( pf[2].getKind() );
00729         os1 << " _ _ _ ";
00730         os2 << ")";
00731         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() ),
00732                             emptyL, emptyLUsed, nullRat, false, 0 );
00733       }
00734     }
00735     else if( pf[0]==d_addInequalities_str )
00736     {
00737       // get subproofs
00738       TReturn* t1 = cvc3_to_lfsc(pf[3],beneath_lc);
00739       TReturn* t2 = cvc3_to_lfsc(pf[4],beneath_lc);
00740       t1->getL( emptyL, emptyLUsed );
00741       t2->getL( emptyL, emptyLUsed );
00742       yMode = TReturn::normalize_tret( pf[3], t1, pf[4], t2 );
00743       if( yMode==1 )
00744       {
00745         tRetVal = new TReturn( LFSCLraAdd::Make( t1->getLFSCProof(), t2->getLFSCProof(),
00746                                               pf[1].getKind(), pf[2].getKind() ), emptyL, emptyLUsed, nullRat, false, 1 );
00747       }
00748       else if( yMode==0 )
00749       {
00750         ostringstream os1, os2;
00751         os1 << "(add_inequalities_" << kind_to_str( pf[1].getKind() );
00752         os1 << "_" << kind_to_str( pf[2].getKind() );
00753         os1 << " _ _ _ _ ";
00754         os2 << ")";
00755         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() ),
00756                             emptyL, emptyLUsed, nullRat, false, 0 );
00757       }
00758     }
00759     else if( pf[0] == d_real_shadow_eq_str){
00760       TReturn* t1 = cvc3_to_lfsc(pf[3], beneath_lc);
00761       TReturn* t2 = cvc3_to_lfsc(pf[4], beneath_lc);
00762       t1->getL( emptyL, emptyLUsed );
00763       t2->getL( emptyL, emptyLUsed );
00764       yMode = TReturn::normalize_tret( pf[3], t1, pf[4], t2 );
00765       if( yMode==1 ){
00766         ostringstream os1, os2;
00767         os1 << "(lra_>=_>=_to_= _ _ ";
00768         os2 << ")";
00769         RefPtr< LFSCProof > p = LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() );
00770         p->setChOp( EQ );
00771         tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 1 );
00772       }else if( yMode==0 || yMode==2 ){
00773         ostringstream os1, os2;
00774         os1 << "(real_shadow_eq _ _";
00775         os2 << ")";
00776         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() ),
00777                             emptyL, emptyLUsed, nullRat, false, 0 );
00778       }
00779     }
00780     else if( pf[0]==d_cycle_conflict_str )
00781     {
00782       // get subproofs
00783       bool isErr = false;
00784       int n = ( pf.arity() - 1 )/2 + 1;
00785       std::vector < TReturn* > trets;
00786       for( int a=n; a<pf.arity(); a++ ){
00787         if( !isErr ){
00788           TReturn* t = cvc3_to_lfsc(pf[a],beneath_lc);
00789           if( TReturn::normalize_tr( pf[a], t, 1 )!=1 ){
00790             isErr = true;
00791           }else{
00792             trets.push_back( t );
00793             t->getL( emptyL, emptyLUsed );
00794           }
00795         }
00796       }
00797       //add them together
00798       if( !isErr ){
00799         int currOp = get_normalized( pf[1].getKind() );
00800         RefPtr< LFSCProof > p1 = trets[0]->getLFSCProof();
00801         for( int a=1; a<(int)trets.size(); a++ ){
00802           int op = get_normalized( pf[a+1].getKind() );
00803           p1 = LFSCLraAdd::Make( trets[a]->getLFSCProof(), p1.get(), op, currOp );
00804           if( op==GT ){
00805             currOp = GT;
00806           }else if( op==GE ){
00807             currOp = currOp==GT ? GT : GE;
00808           }
00809         }
00810         tRetVal = new TReturn( LFSCLraContra::Make( p1.get(), GT ), emptyL, emptyLUsed, nullRat, false, 0 );
00811       }
00812     }
00813     else if( pf[0]==d_learned_clause_str )
00814     {
00815       if( pf.arity()==2 )
00816       {
00817         TReturn* t = cvc3_to_lfsc(pf[1],true);
00818         t->getL( emptyL, emptyLUsed );
00819         RefPtr< LFSCProof > p = t->getLFSCProof();
00820 
00821         Expr pe;
00822         what_is_proven( pf[1], pe );
00823         bool success = true;
00824         if( !pe.isFalse() ){
00825           success = false;
00826           if( TReturn::normalize_tr( pf[1], t, 3, false )==3 )
00827           {
00828             p = t->getLFSCProof();
00829             success = true;
00830           }
00831 #ifdef PRINT_MAJOR_METHODS
00832           cout << ";[M]: learned clause, not proven false" << std::endl;
00833 #endif
00834         }
00835         else if( cvc3_mimic && pf[1][0]!=d_cycle_conflict_str )
00836         {
00837           ostringstream os1, os2;
00838           os1 << "(clausify_false ";
00839           os2 << ")";
00840           p = LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() );
00841         }
00842         if( success ){
00843           //ostringstream os1, os2;
00844           //if( debug_var )
00845           //  os1 << "LC:";
00846           //we must close all proof-lets that contain free variables
00847           //p = make_let_proof( p.get(), emptyL, false );
00848 #ifdef OPTIMIZE
00849           std::vector< int > assumes, assumesUsed;
00850           t->calcL( assumes, assumesUsed );
00851           for( int a=0; a<(int)assumes.size(); a++ ){
00852             p = LFSCAssume::Make( assumes[a], p.get(), true );
00853           }
00854 #else
00855           for( int a=0; a<(int)emptyL.size(); a++ ){
00856             p = LFSCAssume::Make( emptyL[a], p.get(), true );
00857           }
00858 #endif
00859           emptyL.clear();
00860           emptyLUsed.clear();
00861           tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 3 );
00862         }
00863       }
00864     }
00865     else if( pf[0]==d_andE_str )
00866     {
00867       TReturn* t = cvc3_to_lfsc(pf[3],beneath_lc);
00868       t->getL( emptyL, emptyLUsed );
00869       if( t->getProvesY()==0 )
00870       {
00871         int pos = pf[1].getRational().getNumerator().getInt();
00872         RefPtr< LFSCProof > p = LFSCProof::Make_and_elim( pf[2], t->getLFSCProof(), pos, pf[2][pos] );
00873         tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, t->getRational(), t->hasRational(), 0 );
00874       }
00875       else if( t->getProvesY()==3 )
00876       {
00877         //need to use and CNF rules
00878         RefPtr< LFSCProof > p = LFSCProof::Make_CNF( pf[2], d_and_mid_s,
00879                                                 pf[1].getRational().getNumerator().getInt() );
00880         p = LFSCBoolRes::Make( t->getLFSCProof(), p.get(), pf[2], pf );
00881         tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 3 );
00882       }
00883     }
00884     else if( pf[0]==d_rewrite_implies_str )
00885     {
00886       if( !cvc3_mimic )
00887       {
00888         Expr ei = Expr( IMPLIES, pf[1], pf[2] );
00889         RefPtr< LFSCProof > p = LFSCProof::Make_CNF( ei, d_imp_s, 3 );
00890         if( p.get() )
00891         {
00892           tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 3 );
00893         }
00894       }
00895       else
00896       {
00897         //tRetVal = new TReturn( LFSCProofGeneric::MakeStr( "(rewrite_implies _ _)" ), emptyL, emptyLUsed, nullRat, false, 0 );
00898       }
00899     }
00900     else if( pf[0]==d_rewrite_ite_same_str )
00901     {
00902       ostringstream os1, os2;
00903       os1 << "(rewrite_ite_same ";
00904       RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[2] );
00905       RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[3] );
00906       os2 << ")";
00907       tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ),
00908                           emptyL, emptyLUsed, nullRat, false, 0 );
00909     }
00910     else if( pf[0]==d_rewrite_and_str || pf[0]==d_rewrite_or_str )
00911     {
00912       //Expr e = Expr( IFF, pf[1], pf[2] );
00913       bool isAnd = pf[0]==d_rewrite_and_str;
00914       if( pf[1].arity()==2 && pf[1][0]==pf[1][1] ){   //try to apply binary redundant rule
00915         ostringstream os1, os2 ;
00916         os1 << "(" << ( isAnd ? "and" : "or" ) << "_redundant ";
00917         RefPtr< LFSCProof > p = LFSCProofExpr::Make( pf[1][0] );
00918         os2 << ")";
00919         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
00920       }else if( isFlat( pf[2] ) ){        //try to do the normalize
00921         Expr e1 = cascade_expr( pf[1] );
00922         Expr e2 = cascade_expr( pf[2] );
00923         Expr pe;
00924         make_flatten_expr( e1, pe, pf[1].getKind() );
00925         //cout << "we have an and normalize " << e1 << std::endl;
00926         //cout << "making and normalize for " << pe << std::endl;
00927         //cout << "this should be equal to  " << e2 << std::endl;
00928         //cout << (pe==e2) << std::endl;
00929         if( pe==e2 ){     //standard and normalize
00930           ostringstream os1, os2;
00931           os1 << "(" << ( isAnd ? "and" : "or" ) << "_normalize _ ";
00932           os2 << ")";
00933           RefPtr< LFSCProof > p = LFSCProofExpr::Make( pf[1] );
00934           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
00935         }
00936         //else if( pf[1].arity()==2 ){    //try to normalize the symm version 
00937         //  Expr e1s = cascade_expr( Expr( pf[1].getKind(), pf[1][1], pf[1][0] ) );
00938         //  make_flatten_expr( e1s, pe, pf[1].getKind() );
00939         //  if( pe==e2 ){
00940         //    ostringstream oss1, oss2, oss3, oss4;
00941         //    oss1 << "(iff_trans _ _ (" << ( isAnd ? "and" : "or" );
00942         //    oss1 << "_symm ";
00943         //    RefPtr< LFSCProof > pex1 = LFSCProofExpr::Make( pf[1][0] );
00944         //    oss2 << " ";
00945         //    RefPtr< LFSCProof > pex2 = LFSCProofExpr::Make( pf[1][1] );
00946         //    oss3 << ") " << "(" << ( isAnd ? "and" : "or" ) << "_normalize _ ";
00947         //    RefPtr< LFSCProof > ps = LFSCProofExpr::Make( e1s );
00948         //    oss4 << "))";
00949         //    std::vector< RefPtr< LFSCProof > > pfs;
00950         //    pfs.push_back( pex1.get() );
00951         //    pfs.push_back( pex2.get() );
00952         //    pfs.push_back( ps.get() );
00953         //    std::vector< string > strs;
00954         //    strs.push_back( oss1.str() );
00955         //    strs.push_back( oss2.str() );
00956         //    strs.push_back( oss3.str() );
00957         //    strs.push_back( oss4.str() );
00958         //    tRetVal = new TReturn( LFSCProofGeneric::Make( pfs, strs ), emptyL, emptyLUsed, nullRat, false, 0 );
00959         //  }
00960         //}
00961       }
00962       if( !tRetVal ){
00963         //going to have to trust it
00964         TReturn* t = make_trusted( pf );
00965         //this code runs the normalize side condition, but ignores it (for consistency with proof checking times)
00966         ostringstream os1, os2;
00967         os1 << "(" << (isAnd ? "and" : "or" ) << "_nd _ _ _ ";
00968         os2 << ")";
00969         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t->getLFSCProof(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
00970       }
00971     }
00972     else if( pf[0]==d_rewrite_iff_symm_str )
00973     {
00974       ostringstream os1, os2;
00975       os1 << "(rewrite_iff_symm ";
00976       RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1] );
00977       RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[2] );
00978       os2 << ")";
00979       tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
00980     }
00981     else if( pf[0]== d_implyEqualities_str){
00982 
00983       if( pf.arity()==5 ){
00984         TReturn* t1 = cvc3_to_lfsc(pf[3],beneath_lc);
00985         TReturn* t2 = cvc3_to_lfsc(pf[4],beneath_lc);
00986         t1->getL( emptyL, emptyLUsed );
00987         t2->getL( emptyL, emptyLUsed );
00988         if( TReturn::normalize_tr( pf[3], t1, 0 )==0 && TReturn::normalize_tr( pf[4], t2, 0 )==0 )
00989         {
00990           Expr e1, e2;
00991           if( what_is_proven( pf[3], e1 ) && what_is_proven( pf[4], e2 ) )
00992           {
00993             int m1 = queryMt( Expr( MINUS, e1[1], e1[0] ) );
00994             int m2 = queryMt( Expr( MINUS, e2[1], e2[0] ) );
00995 
00996             ostringstream os1, os2;
00997             os1<<"(imply_equalities _ _ _ _ _ _ ";
00998             os1 << "@pnt" << abs( m1 ) << " @pnt" << abs( m2 ) << " ";
00999             os2 << ")";
01000             tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t1->getLFSCProof(), t2->getLFSCProof(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01001           }
01002         }
01003       }
01004     }
01005     else if( pf[0]==d_implyWeakerInequality_str )
01006     {
01007 #ifdef PRINT_MAJOR_METHODS
01008       //cout << ";[M]: imply weaker equality " << pf[1] << std::endl;
01009 #endif
01010       if( !cvc3_mimic ){
01011         if( pf[1].arity()==2 && pf[2].arity()==2 && pf[1][1][0].isRational() && pf[2][1][0].isRational() )
01012         {
01013           //Rational r = pf[1][1][0].getRational() - pf[2][1][0].getRational();
01014           //tRetVal = new TReturn( LFSCLraAxiom::Make( r, GT ), emptyL, emptyLUsed, nullRat, false, 1 );
01015           tRetVal = new TReturn( LFSCLraAxiom::MakeEq(), emptyL, emptyLUsed, nullRat, false, 1 );
01016         }
01017       }else{
01018         Rational r1, r2;
01019         ostringstream os1, os2;
01020         getRat(pf[1][1][0], r1);
01021         getRat(pf[2][1][0], r2);
01022         RefPtr <LFSCProof> p;
01023 
01024         os1 <<"(imply_weaker_inequality_" << kind_to_str( pf[1].getKind() ) << "_" << kind_to_str( pf[2].getKind() );
01025         if(pf[1][1].arity() > 2)
01026         {
01027           vector<Expr> t1_children;
01028           int start_i = 1;
01029           int end_i = pf[1][1].arity();
01030           for(int i = start_i; i < end_i; i ++) {
01031             const Expr& term = pf[1][1][i];
01032             t1_children.push_back(term);
01033           }
01034           p = LFSCProofExpr::Make(Expr(pf[1][1].getKind(), t1_children));
01035         }
01036         else
01037         {
01038           p = LFSCProofExpr::Make(pf[1][1][1]);
01039         }
01040         os2<<" ";
01041         print_rational(r1, os2);
01042         os2 << " ";
01043         print_rational(r2, os2);
01044         os2<<")";
01045         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ),
01046                             emptyL, emptyLUsed, nullRat, false, 0 );
01047       }
01048     }
01049     else if( pf[0]==d_implyNegatedInequality_str )
01050     {
01051 #ifdef PRINT_MAJOR_METHODS
01052       //cout << ";[M]: imply negated equality " << pf[1] << std::endl;
01053 #endif
01054       if( !cvc3_mimic ){
01055         if( pf[1].arity()==2 && pf[2].arity()==2 && pf[1][1][0].isRational() && pf[2][1][0].isRational() )
01056         {
01057           //Rational r = -( pf[1][1][0].getRational() + pf[2][1][0].getRational() );
01058           //tRetVal = new TReturn( LFSCLraAxiom::Make( r, GT ), emptyL, emptyLUsed, nullRat, false, 1 );
01059           tRetVal = new TReturn( LFSCLraAxiom::MakeEq(), emptyL, emptyLUsed, nullRat, false, 1 );
01060         }
01061       }else{
01062         Rational r1, r2;
01063         if( getRat( pf[1][1][0], r1 ) && getRat(pf[2][1][0], r2) ){
01064           Expr ep = pf[1][1][1];
01065           Rational negOne = Rational( -1 );
01066           bool isNeg = false;
01067           if ( pf[1][1][1].getKind()==MULT && pf[1][1][1][0].isRational() && pf[1][1][1][0].getRational()==negOne ){
01068             isNeg = true;
01069             if(pf[1][1].arity() > 2)
01070             {
01071               vector<Expr> t1_children;
01072               int start_i = 1;
01073               int end_i = pf[1][1].arity();
01074               for(int i = start_i; i < end_i; i ++) {
01075                 const Expr& term = pf[1][1][i];
01076                 t1_children.push_back(term);
01077               }
01078               ep = Expr(pf[1][1].getKind(), t1_children);
01079             }
01080             else
01081             {
01082               ep = pf[1][1][1][1];
01083             }
01084 
01085           }
01086           if(r1 == r2) {
01087             ostringstream os1, os2;
01088             os1 << "(imply_negated_inequality_<" << (isNeg ? "n" : "" );
01089             os1 << " ";
01090             RefPtr< LFSCProof > p = LFSCProofExpr::Make( ep );
01091             os2 << " ";
01092             print_rational( r1, os2 );
01093             os2 << ")";
01094             tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ),
01095                                 emptyL, emptyLUsed, nullRat, false, 0 );
01096           }else{
01097             ostringstream os1, os2;
01098             os1 << "(imply_negated_inequality_";
01099             os1 << kind_to_str(pf[1].getKind()) << "_"<<kind_to_str(pf[2].getKind()) << (isNeg ? "n" : "" );
01100             os1 << " ";
01101             RefPtr< LFSCProof > p = LFSCProofExpr::Make( ep );
01102             os2 << " ";
01103             print_rational( r1, os2 );
01104             os2 << " ";
01105             print_rational( r2, os2 );
01106             os2 << ")";
01107             tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ),
01108                                 emptyL, emptyLUsed, nullRat, false, 0 );
01109           }
01110         }
01111       }
01112     }
01113     else if( pf[0]==d_rewrite_iff_str){
01114       ostringstream os1, os2;
01115 
01116       // then it's just the iff_refl rule
01117       if(pf[1] == pf[2]){
01118         os1 << "(iff_refl ";
01119         os2 << ")";
01120         RefPtr< LFSCProof > p = LFSCProofExpr::Make( pf[1] );
01121         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ), emptyL, emptyLUsed,
01122                             nullRat, false, 0 );
01123       }
01124       if(pf[1] == d_pf_expr.getEM()->trueExpr()){
01125         os1 << "(rewrite_iff_true_l ";
01126         RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[2] );
01127         os2 << ")";
01128         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01129       }
01130       if(pf[1] == d_pf_expr.getEM()->falseExpr()){
01131         os1 << "(rewrite_iff_false_l ";
01132         RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[2] );
01133         os2 << ")";
01134         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01135       }
01136       if(pf[2] == d_pf_expr.getEM()->trueExpr()){
01137         os1 << "(rewrite_iff_true_r ";
01138         RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1] );
01139         os2 << ")";
01140         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01141       }
01142       if(pf[2] == d_pf_expr.getEM()->falseExpr()){
01143         os1 << "(rewrite_iff_false_r ";
01144         RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1] );
01145         os2 << ")";
01146         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01147       }
01148       if(pf[1].isNot() && pf[1][0] == pf[2]){
01149         os1 << "(rewrite_iff_not_l ";
01150         RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1][0] );
01151 
01152         os2 << ")";
01153         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01154       }
01155       if(pf[2].isNot() && pf[2][0] == pf[1]){
01156         os1 << "(rewrite_iff_not_r ";
01157         RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[2][0] );
01158         os2 << ")";
01159         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01160       }
01161       // just flips them
01162       if(pf[1] < pf[2]){
01163         os1 << "(rewrite_iff_symm ";
01164         RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1] );
01165         RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[2] );
01166         os2 << ")";
01167         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01168       }
01169       if( !tRetVal ){
01170         os1 << "(iff_refl ";
01171         os2 << ")";
01172         RefPtr< LFSCProof > p = LFSCProofExpr::Make( pf[1].iffExpr(pf[2]) );
01173         tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ), emptyL, emptyLUsed,
01174                             nullRat, false, 0 );
01175       }
01176     }
01177     else if( isIgnoredRule( pf[0] ) )
01178     {
01179       TReturn* t = cvc3_to_lfsc(pf[2],beneath_lc);
01180       yMode = t->getProvesY();
01181       t->getL( emptyL, emptyLUsed );
01182       if( !cvc3_mimic )
01183       {
01184         if( yMode==1 ){
01185           tRetVal = t;
01186         }
01187       }
01188       else
01189       {
01190         if( yMode==0 || yMode==2 )
01191         {
01192           ostringstream os1, os2;
01193           os1 << "(" << pf[0] << (yMode==2 ? "_impl" : "" ) << " _ ";
01194           os2 << ")";
01195           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), t->getLFSCProof(), os2.str() ), emptyL, emptyLUsed,
01196                               t->getRational(), t->hasRational(), 0 );
01197         }
01198       }
01199     }
01200     else if( isTrivialTheoryAxiom( pf ) )
01201     {
01202       //find the rational multiplier for the axiom
01203       Rational r;
01204       bool hasRat = false;
01205       if( pf[0]==d_mult_ineqn_str || pf[0]==d_mult_eqn_str || pf[0]==d_rewrite_eq_symm_str || pf[0]==d_int_const_eq_str ){
01206         if( pf[0]==d_mult_ineqn_str && pf[2].arity()==2 && pf[2][1].arity()==2 ){
01207           if( pf[2][1][1].isRational() ){
01208             r = pf[2][1][1].getRational();
01209             hasRat = true;
01210           }else if( pf[2][1][0].isRational() ){
01211             r = pf[2][1][0].getRational();
01212             hasRat = true;
01213           }
01214         }else if( pf[0]==d_mult_eqn_str && pf[3].isRational() ){
01215           r = pf[3].getRational();
01216           hasRat = true;
01217         }else if( pf[0]==d_rewrite_eq_symm_str ){
01218           r = -1;
01219           hasRat = true;
01220         }else if( pf[0]==d_int_const_eq_str ){
01221           if( pf[1].getKind()==EQ && !pf[2].isFalse() ){
01222             if( pf[1][1].getKind()==MULT && getRat( pf[1][1][0], r ) ){
01223               r = -r;
01224             }else if( pf[1][1].getKind()==PLUS && pf[1][1][1].getKind()==MULT && getRat( pf[1][1][1][0], r ) ){
01225               r = -r;
01226             }else{
01227               r = -1;
01228             }
01229             hasRat = true;
01230           }
01231         }
01232         if( !hasRat )
01233         {
01234           ose << pf[0] << ", Warning: Can't find rational multiplier " << std::endl;
01235           ose << pf[2] << std::endl;
01236         }
01237       }
01238       //handle the axiom  -  only do it if the term is polynomial normalizable
01239       if( !cvc3_mimic && isTrivialTheoryAxiom( pf, true ) )
01240       {
01241         //ignore it if cvc3_mimic is false
01242         if( hasRat && r<0 && pf[0]==d_mult_ineqn_str ){
01243           r = -r;
01244         }
01245         //if( debug_conv && !beneath_lc ){
01246         //  cout << "WARNING: Trivial theory axiom used, not underneath learned clause: " << pf[0] << std::endl;
01247         //}
01248         tRetVal = new TReturn( LFSCLraAxiom::MakeEq(), emptyL, emptyLUsed, r, hasRat, 1 );
01249       }else{
01250         //int val = queryM( pf[1] );
01251         if( pf[0] == d_refl_str )
01252         {
01253           if( isFormula( pf[1] ) ){
01254             ostringstream os1, os2;
01255             os1 << "(iff_refl ";
01256             os2 << ")";
01257             RefPtr< LFSCProof > p = LFSCProofExpr::Make( pf[1] );
01258             tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ), emptyL, emptyLUsed,
01259                                 nullRat, false, 0 );
01260           }else{
01261             ostringstream os1, os2;
01262             os1 << "(refl Real ";
01263             os2 << ")";
01264             RefPtr< LFSCProof > p = LFSCProofExpr::Make( pf[1] );
01265             tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p.get(), os2.str() ), emptyL, emptyLUsed,
01266                                 nullRat, false, 0 );
01267           }
01268         }
01269         else if( pf[0] == d_flip_inequality_str )
01270         {
01271           ostringstream os1, os2;
01272           os1 << "(flip_inequality_" << kind_to_str( pf[1].getKind() );
01273           os1 << "_" << kind_to_str( pf[2].getKind() ) << " ";
01274           os2 << ")";
01275           RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1][0] );
01276           RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[1][1] );
01277           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed,
01278                               nullRat, false, 0 );
01279         }
01280         else if( pf[0] == d_right_minus_left_str )
01281         {
01282           ostringstream os1, os2;
01283           os1 << "(right_minus_left_" << kind_to_str( pf[1].getKind() ) << " ";
01284           os2 << ")";
01285           RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1][0] );
01286           RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[1][1] );
01287           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed,
01288                               nullRat, false, 0 );
01289         }
01290         else if( pf[0] == d_minus_to_plus_str )
01291         {
01292           ostringstream os1, os2;
01293           os1 << "(minus_to_plus ";
01294           os2 << ")";
01295           RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1] );
01296           RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[2] );
01297           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed,
01298                               nullRat, false, 0 );
01299         }
01300         else if( pf[0] == d_plus_predicate_str )
01301         {
01302           ostringstream os1, os2;
01303           os1 << "(plus_predicate_" << kind_to_str( pf[1].getKind() ) << " ";
01304           std::vector< string > strs;
01305           std::vector< RefPtr< LFSCProof > > pfs;
01306           pfs.push_back( LFSCProofExpr::Make( pf[1][0] ) );
01307           pfs.push_back( LFSCProofExpr::Make( pf[1][1] ) );
01308           pfs.push_back( LFSCProofExpr::Make( pf[2][0][1] ) );
01309           os2 << ")";
01310           std::string spc( " " );
01311           strs.push_back( os1.str() );
01312           strs.push_back( spc );
01313           strs.push_back( spc );
01314           strs.push_back( os2.str() );
01315           tRetVal = new TReturn( LFSCProofGeneric::Make( pfs, strs ), emptyL, emptyLUsed,
01316                               nullRat, false, 0 );
01317         }
01318         else if( pf[0] == d_canon_plus_str || pf[0]==d_canon_mult_str )
01319         {
01320           int m = queryMt( Expr( MINUS, pf[1], pf[2] ) );
01321           ostringstream os;
01322           os << "(canonize_= _ _ _ ";
01323           os << "@pnt" << m << ")";
01324           pntNeeded[ m ] = true;
01325           tRetVal = new TReturn( LFSCProofGeneric::MakeStr( os.str().c_str() ), emptyL, emptyLUsed,
01326                               nullRat, false, 0 );
01327         }
01328         else if( pf[0] == d_canon_invert_divide_str )
01329         {
01330           Rational r1 = Rational( 1 );
01331           Expr er1 = d_pf_expr.getEM()->newRatExpr( pf[1][0].getRational() );
01332           Expr er2 = d_pf_expr.getEM()->newRatExpr( r1/pf[1][1].getRational() );
01333           //cout << "we have made " << er1 << " " << er2 << std::endl;
01334           int m = queryMt( Expr( MINUS, pf[1], Expr( MULT, er1, er2 )) );
01335           ostringstream os;
01336           os << "(canonize_= _ _ _ ";
01337           os << "@pnt" << m << ")";
01338           pntNeeded[ m ] = true;
01339           tRetVal = new TReturn( LFSCProofGeneric::MakeStr( os.str().c_str() ), emptyL, emptyLUsed,
01340                               nullRat, false, 0 );
01341         }
01342         else if( pf[0] == d_mult_ineqn_str && hasRat )
01343         {
01344           ostringstream os1, os2;
01345           os1 << "(mult_ineqn_" << (r<0 ? "neg_" : "");
01346           os1 << kind_to_str( pf[1].getKind() ) << " ";
01347           RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1][0] );
01348           RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[1][1] );
01349           os2 << " ";
01350           print_rational( r, os2 );
01351           os2 << ")";
01352           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed,
01353                               nullRat, false, 0 );
01354         }
01355         else if( pf[0] == d_mult_eqn_str && hasRat )
01356         {
01357           ostringstream os1, os2;
01358           os1 << "(mult_eqn ";
01359           RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1] );
01360           RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[2] );
01361           os2 << " ";
01362           print_rational( r, os2 );
01363           os2 << ")";
01364           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed,
01365                               nullRat, false, 0 );
01366         }
01367         else if( pf[0] == d_negated_inequality_str )
01368         {
01369           Expr e1 = queryAtomic( pf[1], true );
01370 
01371           ostringstream os1, os2;
01372           os1 << "(negated_inequality_" << kind_to_str( e1.getKind() );
01373           os1 << "_" << kind_to_str( get_not( e1.getKind() ) ) << " ";
01374           RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[1][0][0] );
01375           RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[1][0][1] );
01376           os2 << ")";
01377           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed,
01378                               nullRat, false, 0 );
01379         }
01380         else if( pf[0] == d_rewrite_eq_symm_str )
01381         {
01382           ostringstream os1, os2;
01383           os1 << "(rewrite_eq_symm ";
01384           RefPtr< LFSCProof > p1 = LFSCProofExpr::Make( pf[2] );
01385           RefPtr< LFSCProof > p2 = LFSCProofExpr::Make( pf[3] );
01386           os2 << ")";
01387           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), p1.get(), p2.get(), os2.str() ), emptyL, emptyLUsed,
01388                               nullRat, false, 0 );
01389         }
01390         else if( pf[0] == d_rewrite_eq_refl_str )
01391         {
01392           ostringstream os1, os2;
01393           os1 << "(rewrite_eq_refl ";
01394           os2 << ")";
01395           tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), LFSCProofExpr::Make( pf[2] ), os2.str() ),
01396                                                       emptyL, emptyLUsed, nullRat, false, 0 );
01397         }
01398         else if( pf[0] == d_uminus_to_mult_str )
01399         {
01400           if( pf[1].isRational() )
01401           {
01402             ostringstream os;
01403             os << "(uminus_to_mult ";
01404             print_rational( pf[1].getRational(), os );
01405             os << ")";
01406             tRetVal = new TReturn( LFSCProofGeneric::MakeStr( os.str().c_str() ), emptyL, emptyLUsed,
01407                                 nullRat, false, 0 );
01408           }
01409         }
01410         else if( pf[0] == d_rewrite_not_true_str )
01411         {
01412           tRetVal = new TReturn( LFSCProofGeneric::MakeStr( "rewrite_not_true" ), emptyL, emptyLUsed, nullRat, false, 0 );
01413         }
01414         else if( pf[0] == d_rewrite_not_false_str )
01415         {
01416           tRetVal = new TReturn( LFSCProofGeneric::MakeStr( "rewrite_not_false" ), emptyL, emptyLUsed, nullRat, false, 0 );
01417         }
01418         else if( pf[0] == d_int_const_eq_str )
01419         {
01420           int m1 = queryMt( Expr( MINUS, pf[1][0], pf[1][1] ) );
01421           int m2 = queryMt( Expr( MINUS, pf[2][0], pf[2][1] ) );
01422           ostringstream os;
01423           os << "(canonize_iff _ _ _ _ _ _ @pnt" << m1 << " @pnt" << m2 << ")";
01424           pntNeeded[ m1 ] = true;
01425           pntNeeded[ m2 ] = true;
01426           tRetVal = new TReturn( LFSCProofGeneric::MakeStr( os.str().c_str() ), emptyL, emptyLUsed, nullRat, false, 0 );
01427         }
01428       }
01429     }
01430     else if( pf[0]==d_lessThan_To_LE_rhs_rwr_str )
01431     {
01432       //FIXME: this introduces weirdness into the logic of completeness of the proof conversion
01433       //why is integer reasoning used in CVC3 QF_LRA proofs?
01434       if( !cvc3_mimic )
01435         tRetVal = new TReturn( LFSCLraAxiom::MakeEq(), emptyL, emptyLUsed, nullRat, false, 1 );
01436       else{
01437         tRetVal = make_trusted( pf );
01438       }
01439     }
01440     else if( pf[0]==d_rewrite_not_not_str )
01441     {
01442       //note that "not not" is already taken care of  FIXME
01443 #ifdef LRA2_PRIME
01444       tRetVal = new TReturn( LFSCProofGeneric::MakeStr("(rewrite_not_not _)"), emptyL, emptyLUsed, nullRat, false, 0 );
01445 #else
01446       if( !cvc3_mimic ){
01447         tRetVal = new TReturn( LFSCProofGeneric::MakeStr("(iff_refl _)"), emptyL, emptyLUsed, nullRat, false, 0 );
01448       }else{
01449         tRetVal = new TReturn( LFSCProofGeneric::MakeStr("(rewrite_not_not _)"), emptyL, emptyLUsed, nullRat, false, 0 );
01450       }
01451 #endif
01452     }
01453     else if( isTrivialBooleanAxiom( pf[0] ) )
01454     {
01455       if( !cvc3_mimic ){
01456         tRetVal = new TReturn( LFSCLem::Make( queryM( pf[1] ) ), emptyL, emptyLUsed, nullRat, false, 3 );
01457       }else{
01458 
01459       }
01460     }
01461     else if( pf[0]==d_const_predicate_str )
01462     {
01463       if( is_eq_kind( pf[1].getKind() ) )
01464       {
01465         Rational r1, r2;
01466         //int knd = pf[2].isFalse() ? get_not( pf[1].getKind() ) : pf[1].getKind();
01467         RefPtr< LFSCProof > p;
01468         if( getRat( pf[1][0], r1 ) && getRat( pf[1][1], r2 ) ){
01469 #ifdef PRINT_MAJOR_METHODS
01470           cout << ";[M]: const_pred " << kind_to_str( pf[1].getKind() );
01471           cout << " " << pf[2].isFalse();
01472           cout << ", rp=" << rev_pol << ", cvc=" << cvc3_mimic << std::endl;
01473 #endif
01474           if( !cvc3_mimic ){
01475             //if( rev_pol ){
01476             //  ostringstream ose1;
01477             //  ose1 << "Warning: Const predicate, rev pol true" << std::endl;
01478             //  print_warning( ose1.str().c_str() ); 
01479             //  knd = get_not( knd );
01480             //}
01481             if( pf[1].getKind()==EQ ){
01482               p = LFSCLraAxiom::MakeEq();
01483             }else{
01484               //Rational r = is_opposite( knd ) ? r2 - r1 : r1 - r2;
01485               //if( knd==GT )
01486               //  r = Rational( 1, 1000000 );
01487               //if( knd==GE
01488               //  r = Rational( 0 );
01489               //p = LFSCLraAxiom::Make( r, get_normalized( knd ) );
01490               p = LFSCLraAxiom::MakeEq();
01491             }
01492             if( p.get() ){
01493               tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 1 );
01494             }
01495           }
01496           else
01497           {
01498             ostringstream os;
01499             os << "(const_predicate_" << kind_to_str( pf[1].getKind() );
01500             if( pf[2].getKind()==TRUE_EXPR )
01501               os << "_t";
01502             os << " ";
01503             print_rational( r1, os );
01504             os << " ";
01505             print_rational( r2, os );
01506             os << ")";
01507             tRetVal = new TReturn( LFSCProofGeneric::MakeStr( os.str().c_str() ),
01508                                 emptyL, emptyLUsed, nullRat, false, 0 );
01509           }
01510         }else{
01511           ose << "ERROR: Could not find rational for const predicate" << std::endl;
01512         }
01513       }
01514       if( !tRetVal )
01515         ose << "kind = " << kind_to_str( pf[1].getKind() );
01516     }
01517   }
01518   else
01519   {
01520     //use Expr pfMod
01521     //switch( pfPat )
01522     //{
01523     //}
01524     if( pfPat==1 )
01525     {
01526       ostringstream os1, os2, os3;
01527       os1 << "(ite_axiom ";
01528       os2 << " ";
01529       os3 << ")";
01530       std::vector< string > strs;
01531       std::vector< RefPtr< LFSCProof > > pfs;
01532 
01533       strs.push_back( os1.str() );
01534       pfs.push_back( LFSCProofExpr::Make( pf[1][0] ) );
01535       strs.push_back( os2.str() );
01536       pfs.push_back( LFSCProofExpr::Make( pf[1][1][1] ) );
01537       strs.push_back( os2.str() );
01538       pfs.push_back( LFSCProofExpr::Make( pf[1][2][1] ) );
01539       strs.push_back( os3.str() );
01540       RefPtr< LFSCProof > p = LFSCProofGeneric::Make( pfs, strs );
01541 
01542       tRetVal = new TReturn( LFSCClausify::Make( pf[1], p.get() ), emptyL, emptyLUsed,
01543                           nullRat, false, 3 );
01544     }else{
01545       ostringstream ose;
01546       ose << "WARNING: Unknown proof pattern [" << pfPat << "]";
01547       print_error( ose.str().c_str(), cout );
01548       //ostringstream os1;
01549       //os1 << "PROOF_PAT_" << pfPat;
01550       //tRetVal = new TReturn( LFSCProofGeneric::MakeStr( os1.str().c_str() ), emptyL, emptyLUsed, nullRat, false, 3 );
01551     }
01552   }
01553   if( !tRetVal ){
01554     static bool firstTime = true;
01555     if(pf.arity()>0 && (yMode!=-1 || firstTime ) ){
01556       firstTime = false;
01557       ose << "Unknown proof rule (" << d_rules[pf[0]] << ") " << pf[0] << endl;
01558       ose << "YMode : ";
01559       if( yMode==-2 )
01560         ose << "unknown";
01561       else if( yMode==-1 )
01562         ose << "fail";
01563       else
01564         ose << yMode;
01565       ose << std::endl;
01566       if( rev_pol )
01567         ose << "rev_pol = true" << std::endl;
01568       if( pfPat!=0 )
01569       {
01570         ose << "proof pattern = " << pfPat << std::endl;
01571       }
01572       print_error( ose.str().c_str(), cout );
01573     }
01574     tRetVal = new TReturn( LFSCProofGeneric::MakeUnk(), emptyL, emptyLUsed, nullRat, false, -1 );
01575   }
01576 
01577 
01578   if( debug_conv ){
01579     //cout << "print length = " << tRetVal->getLFSCProof()->get_string_length() << std::endl;
01580     cout << "...done " << pf[0] << " " << tRetVal->getProvesY() << std::endl;
01581   }
01582   if( debug_var ){
01583     ostringstream os1, os2;
01584     os1 << "[" << pf[0];
01585     if( pf[0]==d_basic_subst_op1_str || pf[0]==d_optimized_subst_op_str || pf[0]==d_basic_subst_op0_str || pf[0]==d_const_predicate_str || pf[0]==d_basic_subst_op_str )
01586       os1 << "_" << kind_to_str( pf[1].getKind() );
01587     if( pf[0]==d_const_predicate_str )
01588       os1 << "_" << pf[2];
01589     os1 << " ";
01590     os2 << "]";
01591     std::vector< int > lv, lvUsed;
01592     tRetVal->getL( lv, lvUsed );
01593     tRetVal = new TReturn( LFSCProofGeneric::Make( os1.str(), tRetVal->getLFSCProof(), os2.str(), true ),
01594                            lv, lvUsed, tRetVal->getRational(), tRetVal->hasRational(), tRetVal->getProvesY() );
01595   }
01596   //dont bother making small proofs into lambdas (length less than 30), or they are trivial
01597   if( !tRetVal->getLFSCProof()->isTrivial() && tRetVal->getLFSCProof()->get_string_length()>30 )
01598   {
01599     d_th_trans[pf] = true;
01600     //if( !d_th_trans_map[cvcm][pf] && pf.isSelected() ){
01601     //  std::cout << "already selected" << std::endl;
01602     //}
01603     d_th_trans_map[cvcm][pf] = tRetVal;
01604     //pf.setSelected();
01605   }
01606   //else if( tRetVal->getLFSCProof()->get_string_length()<=30 && getNumNodes( pf )>10 ){
01607   //  std::cout << "strange proof " << pf[0] << " " << getNumNodes( pf ) << std::endl;
01608   //  tRetVal->getLFSCProof()->print( cout );
01609   //  cout << endl;
01610   //}
01611   //if( cvc3_mimic && ( tRetVal->getProvesY()==1 || tRetVal->getProvesY()==2 ) ){
01612   //  ostringstream ose;
01613   //  ose << "Warning: After " << pf[0] << ", cvc_mimic, Ymode = " << tRetVal->getProvesY() << std::endl;
01614   //  print_warning( ose.str().c_str() );
01615   //}
01616   //if( tRetVal->getProvesY()==1 ){
01617   //  if( tRetVal->getLFSCProof()->checkOp()==-1 ){
01618   //    ostringstream ose;
01619   //    ose << "Error: After " << pf[0] << ", check op failed. " << tRetVal->getLFSCProof()->getNumChildren() << std::endl;
01620   //    ose << pf << std::endl;
01621   //    tRetVal->getLFSCProof()->print_pf( ose );
01622   //    print_warning( ose.str().c_str() );
01623   //  }
01624   //}
01625   //if( tRetVal->getProvesY()==1 ){
01626   //  Expr pe;
01627   //  Expr yexpr;
01628   //  if( !what_is_proven( pf, pe ) || !getY( pe, yexpr ) ){
01629   //    ostringstream ose;
01630   //    ose << "Warning: Bad yMode 1 formula after " << pf[0] << std::endl;
01631   //    if( pe.isInitialized() )
01632   //      ose << pe << std::endl;
01633   //    ose << pf << std::endl;
01634   //    print_error( ose.str().c_str(), cout );
01635   //  }
01636   //}
01637   return tRetVal;
01638 }
01639 
01640 //look at the pattern of the proof, return relevant information in modE
01641 int LFSCConvert::get_proof_pattern( const Expr& pf, Expr& modE )
01642 {
01643   if( pf[0]==d_cnf_add_unit_str )
01644   {
01645     if( pf[2][0]==d_iff_mp_str )
01646     {
01647       if( pf[2][3][0]==d_eq_symm_str && pf[2][4][0]==d_if_lift_rule_str )
01648       {
01649         if( pf[2][3][4][0]==d_iff_mp_str )
01650         {
01651           if( pf[2][3][4][3][0]==d_var_intro_str &&
01652               pf[2][3][4][4][0]==d_assump_str )
01653           {
01654             return 1;
01655           }
01656         }
01657       }
01658     }
01659   }
01660   return 0;
01661 }
01662 
01663 LFSCProof* LFSCConvert::make_let_proof( LFSCProof* p )
01664 {
01665   if( debug_conv )
01666     cout << "make let proof..." <<  std::endl;
01667   //std::map< TReturn*, bool >::iterator t_lbend = d_th_trans_lam.begin(), t_lb = d_th_trans_lam.end();
01668   //--t_lb;
01669   if( !d_th_trans.empty() ){
01670     //ExprMap< TReturn* >::iterator t_lb = d_th_trans.begin(), t_lbend = d_th_trans.end();
01671     ExprMap< bool >::iterator t_lbend = d_th_trans.begin(), t_lb = d_th_trans.end();
01672     --t_lb;
01673     while(t_lb != t_lbend){
01674       for( int cvcm=0; cvcm<2; cvcm++ ){
01675         if( d_th_trans_map[cvcm].find( (*t_lb).first )!= d_th_trans_map[cvcm].end() )
01676         {
01677           TReturn* t = d_th_trans_map[cvcm][(*t_lb).first];
01678           if( t ){
01679             std::vector< int > lv;
01680             std::vector< int > lvUsed;
01681 #ifdef OPTIMIZE
01682             t->calcL( lv, lvUsed );
01683 #else
01684             t->getL( lv, lvUsed );
01685 #endif
01686             if( d_th_trans_lam[cvcm][t] ){
01687               d_th_trans_lam[cvcm][t] = false;
01688               int lmt1 = LFSCProof::make_lambda( t->getLFSCProof() );
01689               RefPtr< LFSCProof > pfV = LFSCPfVar::Make( "@l", lmt1 );
01690               p = LFSCPfLet::Make( t->getLFSCProof(), (LFSCPfVar*)pfV.get(), p,
01691                                   t->getProvesY()!=3, lvUsed );
01692             }
01693           }
01694         }
01695       }
01696       --t_lb;
01697       //t_lb++;
01698     }
01699   }
01700   if( debug_conv )
01701     cout << "...done " << std::endl;
01702   return p;
01703 }
01704 
01705 TReturn* LFSCConvert::make_trusted( const Expr& pf )
01706 {
01707   Expr e;
01708   std::vector< int > emptyL;
01709   std::vector< int > emptyLUsed;
01710   if( what_is_proven( pf, e ) ){
01711     int valT = queryM( e, true, true );
01712     return new TReturn( LFSCPfVar::Make( "@T", valT ), emptyL, emptyLUsed, nullRat, false, 0 );
01713   }else{
01714     return new TReturn( LFSCProofGeneric::MakeStr( "@T-unk" ), emptyL, emptyLUsed, nullRat, false, 0 );
01715   }
01716 }
01717 
01718 TReturn* LFSCConvert::do_bso( const Expr& pf, bool beneath_lc, bool rev_pol, 
01719                               TReturn* t1, TReturn* t2, ostringstream& ose )
01720 {
01721   std::vector< int > emptyL;
01722   std::vector< int > emptyLUsed;
01723   int yMode = -2;
01724   TReturn* tRetVal = NULL;
01725   // merge literals
01726   t1->getL( emptyL, emptyLUsed );
01727   t2->getL( emptyL, emptyLUsed );
01728   bool isErr = false;
01729   if( pf[1].getKind()==PLUS || pf[1].getKind()==MINUS ||
01730       pf[1].getKind()==MULT || is_eq_kind( pf[1].getKind() ) )
01731   {
01732     yMode = TReturn::normalize_tret( pf[3], t1, pf[4], t2, rev_pol );
01733     if( yMode==1 )
01734     {
01735       if( pf[1].getKind()==PLUS )
01736         tRetVal = new TReturn( LFSCLraAdd::Make( t1->getLFSCProof(), t2->getLFSCProof(), EQ, EQ ),
01737                             emptyL, emptyLUsed, nullRat, false, 1 );
01738       else if( pf[1].getKind()==MINUS )
01739         tRetVal = new TReturn( LFSCLraSub::Make( t1->getLFSCProof(), t2->getLFSCProof(), EQ, EQ ),
01740                             emptyL, emptyLUsed, nullRat, false, 1 );
01741       else if( pf[1].getKind()==MULT ){
01742 #ifdef PRINT_MAJOR_METHODS
01743         cout << ";[M]: basic_subst_op1_* " << std::endl;
01744 #endif
01745         Rational r;
01746         if( getRat( pf[1][0], r ) ){
01747           tRetVal = new TReturn( LFSCLraMulC::Make( t2->getLFSCProof(), r, EQ ),
01748                               emptyL, emptyLUsed, nullRat, false, 1 );
01749         }else if( getRat( pf[1][1], r ) ){
01750           tRetVal = new TReturn( LFSCLraMulC::Make( t1->getLFSCProof(), r, EQ ),
01751                               emptyL, emptyLUsed, nullRat, false, 1 );
01752         }else{
01753           print_error( "Could not find rational mult in basic_subst_op1", cout );
01754           isErr = true;
01755         }
01756       }else if( is_eq_kind( pf[1].getKind() ) ){
01757         RefPtr< LFSCProof > p;
01758         if( is_opposite( pf[1].getKind() ) ){
01759           p = LFSCLraSub::Make( t2->getLFSCProof(), t1->getLFSCProof(), EQ, EQ );
01760         }else{
01761           p = LFSCLraSub::Make( t1->getLFSCProof(), t2->getLFSCProof(), EQ, EQ );
01762         }
01763         tRetVal = new TReturn( p.get(), emptyL, emptyLUsed, nullRat, false, 1 );
01764       }
01765       if( !tRetVal && debug_conv ){
01766         cout << "basic_subst_op1: abort, have to normalize to 2, for " << kind_to_str( pf[1].getKind() ) << std::endl;
01767       }
01768     }
01769   }
01770   if( !tRetVal ){
01771     if( !isErr ){
01772       if( t1->getProvesY()==1 ){
01773         TReturn::normalize_tr( pf[3], t1, 2, rev_pol );
01774       }
01775       if( t2->getProvesY()==1 ){
01776         TReturn::normalize_tr( pf[4], t2, 2, rev_pol );
01777       }
01778     }
01779     yMode = TReturn::normalize_tret( pf[3], t1, pf[4], t2, rev_pol );
01780     if( yMode==0 || yMode==2 )
01781     {
01782       if( pf[1].getKind()==OR || pf[1].getKind()==AND ||
01783           pf[1].getKind()==IFF || pf[1].getKind()==PLUS ||
01784           is_eq_kind( pf[1].getKind() ) || pf[1].getKind()==MULT || pf[1].getKind()==MINUS ){
01785 
01786         ostringstream os1, os2, os3;
01787         os1 << "(basic_subst_op1_";
01788         if( yMode==2 )
01789           os1 << "impl_";
01790         os1 << kind_to_str( pf[1].getKind() ) << " ";
01791         os3 << " ";
01792         os2 << ")";
01793         std::vector< string > strs;
01794         std::vector< RefPtr< LFSCProof > > pfs;
01795         strs.push_back( os1.str() );
01796         pfs.push_back( LFSCProofExpr::Make( cascade_expr( pf[1][0] ), true ) );
01797         strs.push_back( os3.str() );
01798         pfs.push_back( LFSCProofExpr::Make( cascade_expr( pf[2][0] ), true ) );
01799         strs.push_back( os3.str() );
01800         pfs.push_back( LFSCProofExpr::Make( cascade_expr( pf[1][1] ), true ) );
01801         strs.push_back( os3.str() );
01802         pfs.push_back( LFSCProofExpr::Make( cascade_expr( pf[2][1] ), true ) );
01803         strs.push_back( os3.str() );
01804         pfs.push_back( t1->getLFSCProof() );
01805         strs.push_back( os3.str() );
01806         pfs.push_back( t2->getLFSCProof() );
01807         strs.push_back( os2.str() );
01808         tRetVal = new TReturn( LFSCProofGeneric::Make( pfs, strs ), emptyL, emptyLUsed, nullRat, false, yMode );
01809       }
01810     }
01811   }
01812   if( !tRetVal ){
01813     ose << pf[0] << endl;
01814     for( int a=0; a<pf.arity(); a++ ){
01815       if( a>=3 ){
01816         ose << a << ": " << pf[a][0] << std::endl;
01817         Expr pre;
01818         what_is_proven( pf[a], pre );
01819         ose << "wip: " << pre << std::endl;
01820       }else{
01821         ose << a << ": " << pf[a] << std::endl;
01822       }
01823     }
01824     ose << "subst kind = " << kind_to_str( pf[1].getKind() ) << std::endl;
01825     ose << "subst arity = " << pf.arity() << std::endl;
01826   }
01827   return tRetVal;
01828 }