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