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