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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #ifndef _CVC_lite__expr_h_
00056 #include "expr.h"
00057 #endif
00058
00059 #ifndef _CVC_lite__theorem_h_
00060 #define _CVC_lite__theorem_h_
00061
00062 #include "proof.h"
00063 #include "assumptions.h"
00064
00065 namespace CVCL {
00066
00067
00068 class TheoremManager;
00069 class TheoremValue;
00070 class Assumptions;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 class Theorem {
00085 private:
00086
00087
00088 friend class TheoremProducer;
00089
00090 friend class Theorem3;
00091
00092 TheoremValue *d_thm;
00093
00094
00095 friend int compare(const Theorem& t1, const Theorem& t2);
00096
00097 friend int compare(const Theorem& t1, const Expr& e2);
00098
00099 friend int compareByPtr(const Theorem& t1, const Theorem& t2);
00100
00101 friend bool operator==(const Theorem& t1, const Theorem& t2)
00102 { return (compare(t1, t2)==0); }
00103
00104 friend bool operator!=(const Theorem& t1, const Theorem& t2)
00105 { return (compare(t1, t2) != 0); }
00106
00107
00108 Theorem(TheoremManager* tm, const Expr &thm, const Assumptions& assump,
00109 const Proof& pf, bool isAssump = false, int scope = -1);
00110
00111
00112
00113
00114
00115 Theorem(TheoremManager* tm, const Expr& lhs, const Expr& rhs,
00116 const Assumptions& assump, const Proof& pf, bool isAssump = false,
00117 int scope = -1);
00118
00119
00120 Theorem(TheoremManager* tm, const Expr& e, const Proof& pf);
00121
00122 void recursivePrint(int& i) const;
00123 void getAssumptionsRec(std::set<Expr>& assumptions) const;
00124
00125 public:
00126
00127
00128
00129
00130 void printDebug() const {
00131 this->clearAllFlags();
00132 this->setCachedValue(0);
00133 this->setFlag();
00134 int i = 1;
00135 recursivePrint(i);
00136 }
00137
00138
00139
00140
00141 Theorem(): d_thm(NULL) { }
00142
00143 Theorem(const Theorem &th);
00144
00145 Theorem& operator=(const Theorem &th);
00146
00147
00148 virtual ~Theorem();
00149
00150 bool isNull() const { return d_thm == NULL; }
00151
00152
00153 bool isRewrite() const;
00154
00155 bool isAssump() const;
00156
00157
00158 const Expr& getExpr() const;
00159 const Expr& getLHS() const;
00160 const Expr& getRHS() const;
00161
00162
00163
00164 const Assumptions& getAssumptions() const;
00165
00166 void getLeafAssumptions(std::vector<Expr>& assumptions,
00167 bool negate = false) const;
00168 const Assumptions& getAssumptionsRef() const;
00169
00170
00171
00172 Assumptions getAssumptionsCopy() const;
00173
00174
00175 const Proof& getProof() const;
00176
00177
00178 int getScope() const;
00179
00180
00181 bool withProof() const;
00182 bool withAssumptions() const;
00183
00184
00185 std::string toString() const;
00186
00187
00188 void printx() const;
00189 void print() const;
00190
00191
00192
00193
00194
00195
00196
00197
00198 bool isFlagged() const;
00199
00200 void clearAllFlags() const;
00201
00202 void setFlag() const;
00203
00204
00205 void setExpandFlag(bool val) const;
00206
00207 bool getExpandFlag() const;
00208
00209
00210
00211 void setLitFlag(bool val) const;
00212
00213
00214
00215 bool getLitFlag() const;
00216
00217 bool isAbsLiteral() const;
00218
00219 bool refutes(const Expr& e) const
00220 {
00221 return
00222 (e.isNot() && e[0] == getExpr()) ||
00223 (getExpr().isNot() && getExpr()[0] == e);
00224 }
00225
00226 bool proves(const Expr& e) const
00227 {
00228 return getExpr() == e;
00229 }
00230
00231 bool matches(const Expr& e) const
00232 {
00233 return proves(e) || refutes(e);
00234 }
00235
00236 void setCachedValue(int value) const;
00237 int getCachedValue() const;
00238
00239
00240
00241
00242 std::ostream& print(std::ostream& os, const std::string& name) const;
00243
00244 friend std::ostream& operator<<(std::ostream& os, const Theorem& t) {
00245 return t.print(os, "Theorem");
00246 }
00247 };
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 class Theorem3 {
00270 private:
00271
00272
00273 friend class TheoremProducer;
00274
00275 Theorem d_thm;
00276
00277 friend bool operator==(const Theorem3& t1, const Theorem3& t2) {
00278 return t1.d_thm == t2.d_thm;
00279 }
00280 friend bool operator!=(const Theorem3& t1, const Theorem3& t2) {
00281 return t1.d_thm != t2.d_thm;
00282 }
00283
00284
00285
00286 Theorem3(TheoremManager* tm, const Expr &thm, const Assumptions& assump,
00287 const Proof& pf, bool isAssump = false, int scope = -1)
00288 : d_thm(tm, thm, assump, pf, isAssump, scope) { }
00289
00290
00291
00292
00293 Theorem3(TheoremManager* tm, const Expr& lhs, const Expr& rhs,
00294 const Assumptions& assump, const Proof& pf)
00295 : d_thm(tm, lhs, rhs, assump, pf) { }
00296
00297 public:
00298
00299
00300
00301
00302 void printDebug() const { d_thm.printDebug(); }
00303
00304
00305
00306
00307 Theorem3() { }
00308
00309
00310 virtual ~Theorem3() { }
00311
00312 bool isNull() const { return d_thm.isNull(); }
00313
00314
00315 bool isRewrite() const { return d_thm.isRewrite(); }
00316 bool isAssump() const { return d_thm.isAssump(); }
00317
00318
00319 const Expr& getExpr() const { return d_thm.getExpr(); }
00320 const Expr& getLHS() const { return d_thm.getLHS(); }
00321 const Expr& getRHS() const { return d_thm.getRHS(); }
00322
00323
00324
00325 const Assumptions getAssumptions() const { return d_thm.getAssumptions(); }
00326 const Assumptions& getAssumptionsRef() const {
00327 return d_thm.getAssumptionsRef();
00328 }
00329
00330
00331
00332 Assumptions getAssumptionsCopy() const {
00333 return d_thm.getAssumptionsCopy();
00334 }
00335
00336
00337 const Proof& getProof() const { return d_thm.getProof(); }
00338
00339
00340
00341 int getScope() const { return d_thm.getScope(); }
00342
00343
00344 bool withProof() const { return d_thm.withProof(); }
00345 bool withAssumptions() const { return d_thm.withAssumptions(); }
00346
00347
00348 std::string toString() const;
00349
00350
00351 void printx() const { d_thm.printx(); }
00352 void print() const { d_thm.print(); }
00353
00354
00355 bool isAbsLiteral() const { return d_thm.isAbsLiteral(); }
00356
00357 friend std::ostream& operator<<(std::ostream& os, const Theorem3& t) {
00358 return t.d_thm.print(os, "Theorem3");
00359 }
00360 };
00361
00362
00363 class TheoremLess {
00364 public:
00365 bool operator()(const Theorem& t1, const Theorem& t2) const {
00366 return (compareByPtr(t1, t2) < 0);
00367 }
00368 };
00369 typedef std::map<Theorem,bool, TheoremLess> TheoremMap;
00370
00371 inline std::string Theorem::toString() const {
00372 std::ostringstream ss;
00373 ss << (*this);
00374 return ss.str();
00375 }
00376
00377 inline std::string Theorem3::toString() const {
00378 std::ostringstream ss;
00379 ss << (*this);
00380 return ss.str();
00381 }
00382
00383
00384 inline Assumptions merge(const Theorem& t1, const Theorem& t2) {
00385 return Assumptions(t1, t2);
00386 }
00387 inline Assumptions merge(const Assumptions& a, const Theorem& t) {
00388 Assumptions a2 = a.copy();
00389 a2.add(t);
00390 return a2;
00391 }
00392 inline Assumptions merge(const Theorem& t, const Assumptions& a) {
00393 Assumptions a2 = a.copy();
00394 a2.add(t);
00395 return a2;
00396 }
00397 inline Assumptions merge(const std::vector<Theorem>& t) {
00398 return Assumptions(t);
00399 }
00400
00401 inline bool operator<(const Theorem& t1, const Theorem& t2)
00402 { return compare(t1, t2) < 0; }
00403 inline bool operator<=(const Theorem& t1, const Theorem& t2)
00404 { return compare(t1, t2) <= 0; }
00405 inline bool operator>(const Theorem& t1, const Theorem& t2)
00406 { return compare(t1, t2) > 0; }
00407 inline bool operator>=(const Theorem& t1, const Theorem& t2)
00408 { return compare(t1, t2) >= 0; }
00409
00410 };
00411
00412 #endif