CVC3

LFSCLraProof.cpp

Go to the documentation of this file.
00001 #include "LFSCLraProof.h"
00002 
00003 //LFSCLraAdd ...
00004 
00005 void LFSCLraAdd::print_pf( std::ostream& s, int ind )
00006 {
00007   s<<"(lra_add_";
00008   s <<kind_to_str(d_op1);
00009   s <<"_";
00010   s << kind_to_str(d_op2);
00011   s <<" _ _ _ ";
00012   d_children[0]->print(s, ind+1);
00013   s<<" ";
00014   d_children[1]->print(s, ind+1);
00015   s<<")";
00016 }
00017 LFSCProof* LFSCLraAdd::Make(LFSCProof* pf1, LFSCProof* pf2, int op1, int op2)
00018 {
00019   if( pf1->isTrivial() )
00020     return pf2;
00021   else if( pf2->isTrivial() )
00022     return pf1;
00023   else{
00024     op1 = pf1->checkOp()!=-1 ? pf1->checkOp() : op1;
00025     op2 = pf2->checkOp()!=-1 ? pf2->checkOp() : op2;
00026     if( get_knd_order( op1 )>get_knd_order( op2 ) )
00027       return Make( pf2, pf1, op2, op1 );
00028     else
00029       return new LFSCLraAdd( pf1, pf2, op1, op2 );
00030   }
00031 }
00032 
00033 // LFSCLraAxiom ...
00034 
00035 RefPtr< LFSCProof > LFSCLraAxiom::eq;
00036 
00037 LFSCProof* LFSCLraAxiom::MakeEq(){ 
00038   if( !eq.get() ){
00039     eq = new LFSCLraAxiom( EQ ); 
00040   }
00041   return eq.get();
00042 }
00043 
00044 void LFSCLraAxiom::print_pf( std::ostream& s, int ind )
00045 {
00046   s<<"(lra_axiom_" << kind_to_str(d_op);
00047   if( d_op!= EQ ){
00048     s << " ";
00049     print_rational( d_r, s );
00050   }
00051   s<<")";
00052 }
00053 
00054 //LFSCLraMulC ...
00055 
00056 void LFSCLraMulC::print_pf( std::ostream& s, int ind )
00057 {
00058   s <<"(lra_mul_c_"<<kind_to_str(d_op)<<" _ _ ";
00059   print_rational( d_r, s );
00060   s << " ";
00061   d_pf->print( s, ind+1 );
00062   s << ")";
00063 }
00064 
00065 LFSCProof* LFSCLraMulC::Make(LFSCProof* pf, Rational r, int op)
00066 {
00067   if( pf->isTrivial() || r==1 )
00068     return pf;
00069   else if( pf->AsLFSCLraMulC() ){
00070     Rational rt = r*pf->AsLFSCLraMulC()->d_r;
00071     if( rt==1 )
00072       return pf->AsLFSCLraMulC()->d_pf.get();
00073     else
00074       return new LFSCLraMulC( pf->AsLFSCLraMulC()->d_pf.get(), rt, op );
00075   }else
00076     return new LFSCLraMulC( pf, r, op );
00077 }
00078 
00079 //LFSCLraSub ...
00080 
00081 void LFSCLraSub::print_pf( std::ostream& s, int ind ){
00082   s <<"(lra_sub_"<<kind_to_str(d_op1)<<"_"<<kind_to_str(d_op2)<<" _ _ _ ";
00083   d_children[0]->print(s, ind+1);
00084   s <<" ";
00085   d_children[1]->print(s, ind+1);
00086   s <<")";
00087 }
00088 
00089 LFSCProof* LFSCLraSub::Make(LFSCProof* pf1, LFSCProof* pf2, int op1, int op2){
00090   if( pf2->isTrivial() )
00091     return pf1;
00092   else if( pf1->isTrivial() ){
00093     Rational r = Rational( -1 );
00094     return LFSCLraMulC::Make( pf2, r, op2 );
00095   }else
00096     return new LFSCLraSub( pf1, pf2, op1, op2 );
00097 }
00098 
00099 //LFSCLraPoly ...
00100 
00101 void LFSCLraPoly::print_pf( std::ostream& s, int ind ){
00102   if( d_var<0 ){
00103     s << "(lra_not_" << kind_to_str(get_normalized( d_op ));
00104     s << "_to_" << kind_to_str(get_normalized( get_not( d_op ) ));
00105     s << " _ _";
00106   }
00107   s << " (poly_form";
00108   if( d_var<0 )
00109     s << "_not";
00110   s << " _ _ @pn" << abs( d_var ) << " ";
00111   d_pf->print( s, ind );
00112   s << ")";
00113   if( d_var<0 )
00114     s << ")";
00115 }
00116 
00117 LFSCProof* LFSCLraPoly::Make( const Expr& e, LFSCProof* p )
00118 {
00119   Expr e1 = queryAtomic( e );
00120   Expr eb = queryAtomic( e, true );
00121   if( is_eq_kind( e1.getKind() ) )
00122   {
00123     int m = queryM( e );
00124     //get the required term that is needed to normalize
00125     Expr et;
00126     if( is_opposite( eb.getKind() )  )
00127       et = Expr( MINUS, eb[1], eb[0] );
00128     else
00129       et = Expr( MINUS, eb[0], eb[1] );
00130 
00131     //et.print();
00132 
00133     //get the polynomial normalization proof number
00134     int valT = queryMt( et );
00135     //store it in d_pn_form (this will setup the proper pn*)
00136     d_pn_form[eb] = valT;
00137 
00138     p = LFSCLraPoly::Make( p, m, eb.getKind() );
00139     p->setChOp( get_normalized( e1.getKind() ) );
00140     return p;
00141     //if( m<0 )
00142     //{
00143     //  os << "(lra_not_" << kind_to_str(get_normalized( eb.getKind() ));
00144     //  os << "_to_" << kind_to_str(get_normalized( get_not( eb.getKind() ) ));
00145     //  os << " _ _";
00146     //  os2 << ")";
00147     //}
00148     //os << " (poly_form";
00149     //if( m<0 )
00150     //  os << "_not";
00151     //os << " _ _ @pn" << abs( m ) << " ";
00152     //os2 << ")";
00153   }
00154   else
00155   {
00156     ostringstream ose;
00157     ose << "ERROR:make_polynomial_proof: Trying to make non-atomic " << e1 << " " << e.isNot() << std::endl;
00158     ose << e << std::endl;
00159     print_error( ose.str().c_str(), cout );
00160     return NULL;
00161   }
00162 }