CVC3
|
00001 /*****************************************************************************/ 00002 /*! 00003 * \file theorem_producer.cpp 00004 * \brief See theorem_producer.h file for more information. 00005 * 00006 * Author: Sergey Berezin 00007 * 00008 * Created: Thu Feb 20 16:22:31 2003 00009 * 00010 * <hr> 00011 * 00012 * License to use, copy, modify, sell and/or distribute this software 00013 * and its documentation for any purpose is hereby granted without 00014 * royalty, subject to the terms and conditions defined in the \ref 00015 * LICENSE file provided with this distribution. 00016 * 00017 * <hr> 00018 * 00019 */ 00020 /*****************************************************************************/ 00021 00022 00023 #define _CVC3_TRUSTED_ 00024 #include "theorem_producer.h" 00025 #include "sound_exception.h" 00026 #include "command_line_flags.h" 00027 00028 00029 using namespace std; 00030 using namespace CVC3; 00031 00032 00033 void TheoremProducer::soundError(const std::string& file, int line, 00034 const std::string& cond, 00035 const std::string& msg) 00036 { 00037 ostringstream ss; 00038 ss << "in " << file << ":" << line << " (" << cond << ")\n" << msg; 00039 throw SoundException(ss.str()); 00040 } 00041 00042 00043 // Constructor 00044 TheoremProducer::TheoremProducer(TheoremManager *tm) 00045 : d_tm(tm), d_em(tm->getEM()), 00046 d_checkProofs(&(tm->getFlags()["check-proofs"].getBool())), 00047 // Proof rule application: will have kids 00048 d_pfOp(PF_APPLY) 00049 { d_hole = d_em->newLeafExpr(PF_HOLE); } 00050 00051 00052 Proof TheoremProducer::newLabel(const Expr& e) 00053 { 00054 // Counter to generate unique proof labels ('u') 00055 static int s_counter = 0; 00056 static string s_prefix = "assump"; 00057 ostringstream ss; 00058 ss << s_counter++; 00059 00060 if ((d_tm->getFlags()["lfsc-mode"]).getInt()!= 0 ) { 00061 return newPf("assumptions", e); 00062 } 00063 else { 00064 //TODO: Get rid of hack storing expr in Type field 00065 // the following lines are commented by Yeting, for neat proofs 00066 Expr var = d_tm->getEM()->newBoundVarExpr(s_prefix, ss.str(), Type(e, true)); 00067 return Proof(var); //by Yeting. 00068 } 00069 00070 return newPf("assumptions", e); 00071 //return newPf("assumptions", var , e); 00072 } 00073 00074 00075 Proof TheoremProducer::newPf(const string& name) 00076 { return Proof(Expr(d_pfOp, d_em->newVarExpr(name))); } 00077 00078 00079 Proof TheoremProducer::newPf(const string& name, const Expr& e) 00080 { return Proof(Expr(d_pfOp, d_em->newVarExpr(name), e)); } 00081 00082 00083 Proof TheoremProducer::newPf(const string& name, const Proof& pf) 00084 { return Proof(Expr(d_pfOp, d_em->newVarExpr(name), pf.getExpr())); } 00085 00086 00087 Proof TheoremProducer::newPf(const string& name, 00088 const Expr& e1, const Expr& e2) 00089 { return Proof(Expr(d_pfOp, d_em->newVarExpr(name), e1, e2)); } 00090 00091 00092 Proof TheoremProducer::newPf(const string& name, const Expr& e, 00093 const Proof& pf) 00094 { return Proof(Expr(d_pfOp, d_em->newVarExpr(name), e, pf.getExpr())); } 00095 00096 00097 Proof TheoremProducer::newPf(const string& name, const Expr& e1, 00098 const Expr& e2, const Expr& e3) { 00099 vector<Expr> kids; 00100 kids.push_back(d_em->newVarExpr(name)); 00101 kids.push_back(e1); 00102 kids.push_back(e2); 00103 kids.push_back(e3); 00104 return Proof(Expr(d_pfOp, kids)); 00105 } 00106 00107 00108 Proof TheoremProducer::newPf(const string& name, const Expr& e1, 00109 const Expr& e2, const Proof& pf) { 00110 vector<Expr> kids; 00111 kids.push_back(d_em->newVarExpr(name)); 00112 kids.push_back(e1); 00113 kids.push_back(e2); 00114 kids.push_back(pf.getExpr()); 00115 return Proof(Expr(d_pfOp, kids)); 00116 } 00117 00118 00119 Proof TheoremProducer::newPf(const string& name, 00120 Expr::iterator begin, 00121 const Expr::iterator &end) { 00122 vector<Expr> kids; 00123 kids.push_back(d_em->newVarExpr(name)); 00124 kids.insert(kids.end(), begin, end); 00125 return Proof(Expr(d_pfOp, kids)); 00126 } 00127 00128 00129 Proof TheoremProducer::newPf(const string& name, const Expr& e, 00130 Expr::iterator begin, const Expr::iterator &end) { 00131 vector<Expr> kids; 00132 kids.push_back(d_em->newVarExpr(name)); 00133 kids.push_back(e); 00134 kids.insert(kids.end(), begin, end); 00135 return Proof(Expr(d_pfOp, kids)); 00136 } 00137 00138 00139 Proof TheoremProducer::newPf(const string& name, 00140 Expr::iterator begin, const Expr::iterator &end, 00141 const vector<Proof>& pfs) { 00142 vector<Expr> kids; 00143 kids.push_back(d_em->newVarExpr(name)); 00144 kids.insert(kids.end(), begin, end); 00145 for(vector<Proof>::const_iterator i=pfs.begin(), iend=pfs.end(); 00146 i != iend; ++i) 00147 kids.push_back(i->getExpr()); 00148 return Proof(Expr(d_pfOp, kids)); 00149 } 00150 00151 00152 Proof TheoremProducer::newPf(const string& name, 00153 const vector<Expr>& args) { 00154 vector<Expr> kids; 00155 kids.push_back(d_em->newVarExpr(name)); 00156 kids.insert(kids.end(), args.begin(), args.end()); 00157 return Proof(Expr(d_pfOp, kids)); 00158 } 00159 00160 00161 Proof TheoremProducer::newPf(const string& name, 00162 const Expr& e, 00163 const vector<Expr>& args) { 00164 vector<Expr> kids; 00165 kids.push_back(d_em->newVarExpr(name)); 00166 kids.push_back(e); 00167 kids.insert(kids.end(), args.begin(), args.end()); 00168 return Proof(Expr(d_pfOp, kids)); 00169 } 00170 00171 00172 Proof TheoremProducer::newPf(const string& name, 00173 const Expr& e, 00174 const vector<Proof>& pfs) { 00175 vector<Expr> kids; 00176 kids.push_back(d_em->newVarExpr(name)); 00177 kids.push_back(e); 00178 for(vector<Proof>::const_iterator i=pfs.begin(), iend=pfs.end(); 00179 i != iend; ++i) 00180 kids.push_back(i->getExpr()); 00181 return Proof(Expr(d_pfOp, kids)); 00182 } 00183 00184 00185 Proof TheoremProducer::newPf(const string& name, 00186 const Expr& e1, const Expr& e2, 00187 const vector<Proof>& pfs) { 00188 vector<Expr> kids; 00189 kids.push_back(d_em->newVarExpr(name)); 00190 kids.push_back(e1); 00191 kids.push_back(e2); 00192 for(vector<Proof>::const_iterator i=pfs.begin(), iend=pfs.end(); 00193 i != iend; ++i) 00194 kids.push_back(i->getExpr()); 00195 return Proof(Expr(d_pfOp, kids)); 00196 } 00197 00198 00199 Proof TheoremProducer::newPf(const string& name, 00200 const vector<Proof>& pfs) { 00201 vector<Expr> kids; 00202 kids.push_back(d_em->newVarExpr(name)); 00203 for(vector<Proof>::const_iterator i=pfs.begin(), iend=pfs.end(); 00204 i != iend; ++i) 00205 kids.push_back(i->getExpr()); 00206 return Proof(Expr(d_pfOp, kids)); 00207 } 00208 00209 00210 Proof TheoremProducer::newPf(const string& name, 00211 const vector<Expr>& args, 00212 const Proof& pf) { 00213 vector<Expr> kids; 00214 kids.push_back(d_em->newVarExpr(name)); 00215 kids.insert(kids.end(), args.begin(), args.end()); 00216 kids.push_back(pf.getExpr()); 00217 return Proof(Expr(d_pfOp, kids)); 00218 } 00219 00220 00221 Proof TheoremProducer::newPf(const string& name, 00222 const vector<Expr>& args, 00223 const vector<Proof>& pfs) { 00224 vector<Expr> kids; 00225 kids.push_back(d_em->newVarExpr(name)); 00226 kids.insert(kids.end(), args.begin(), args.end()); 00227 for(vector<Proof>::const_iterator i=pfs.begin(), iend=pfs.end(); 00228 i != iend; ++i) 00229 kids.push_back(i->getExpr()); 00230 return Proof(Expr(d_pfOp, kids)); 00231 } 00232 00233 00234 Proof TheoremProducer::newPf(const Proof& label, const Expr& frm, 00235 const Proof& pf) { 00236 Expr v(label.getExpr()); 00237 IF_DEBUG(Type tp(frm, true);) 00238 DebugAssert(v.isVar() && v.getType() == tp, 00239 "TheoremProducer::newPf: bad variable in LAMBDA expression: " 00240 +v.toString()); 00241 vector<Expr> u; 00242 u.push_back(v); 00243 return Proof(d_tm->getEM()->newClosureExpr(LAMBDA, u, pf.getExpr())); 00244 } 00245 00246 00247 Proof TheoremProducer::newPf(const Proof& label, const Proof& pf) { 00248 Expr v(label.getExpr()); 00249 DebugAssert(v.isVar(), 00250 "TheoremProducer::newPf: bad variable in LAMBDA expression: " 00251 +v.toString()); 00252 vector<Expr> u; 00253 u.push_back(v); 00254 return Proof(d_tm->getEM()->newClosureExpr(LAMBDA, u, pf.getExpr())); 00255 } 00256 00257 00258 Proof TheoremProducer::newPf(const std::vector<Proof>& labels, 00259 const std::vector<Expr>& frms, 00260 const Proof& pf) { 00261 std::vector<Expr> u; 00262 for(unsigned i=0; i<labels.size(); i++) { 00263 const Expr& v = labels[i].getExpr(); 00264 IF_DEBUG(Type tp(frms[i], true);) 00265 DebugAssert(v.isVar(), 00266 "TheoremProducer::newPf: bad variable in LAMBDA expression: " 00267 +v.toString()); 00268 DebugAssert(v.getType() == tp, 00269 "TheoremProducer::newPf: wrong variable type in " 00270 "LAMBDA expression.\nExpected: "+tp.getExpr().toString() 00271 +"\nFound: "+v.getType().getExpr().toString()); 00272 u.push_back(v); 00273 } 00274 return Proof(d_tm->getEM()->newClosureExpr(LAMBDA, u, pf.getExpr())); 00275 } 00276 00277 00278 Proof TheoremProducer::newPf(const std::vector<Proof>& labels, 00279 const Proof& pf) { 00280 std::vector<Expr> u; 00281 for(unsigned i=0; i<labels.size(); i++) { 00282 const Expr& v = labels[i].getExpr(); 00283 DebugAssert(v.isVar(), 00284 "TheoremProducer::newPf: bad variable in LAMBDA expression: " 00285 +v.toString()); 00286 u.push_back(v); 00287 } 00288 return Proof(d_tm->getEM()->newClosureExpr(LAMBDA, u, pf.getExpr())); 00289 }