00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _cvc3__include__theory_core_h_
00022 #define _cvc3__include__theory_core_h_
00023
00024 #include <queue>
00025 #include "theory.h"
00026 #include "cdmap.h"
00027 #include "statistics.h"
00028 #include <string>
00029 #include "notifylist.h"
00030
00031
00032 namespace CVC3 {
00033
00034 class ExprTransform;
00035
00036 class CoreProofRules;
00037 class Translator;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 class TheoryCore :public Theory {
00052 friend class Theory;
00053
00054
00055 ContextManager* d_cm;
00056
00057
00058 TheoremManager* d_tm;
00059
00060
00061 CoreProofRules* d_rules;
00062
00063
00064 const CLFlags& d_flags;
00065
00066
00067 Statistics& d_statistics;
00068
00069
00070 PrettyPrinter* d_printer;
00071
00072
00073 ExprManager::TypeComputer* d_typeComputer;
00074
00075
00076 ExprTransform* d_exprTrans;
00077
00078
00079 Translator* d_translator;
00080
00081
00082 std::queue<Theorem> d_queue;
00083
00084 std::vector<Theorem> d_queueSE;
00085
00086
00087 CDO<bool> d_inconsistent;
00088
00089 CDMap<std::string, bool> d_incomplete;
00090
00091
00092 CDO<Theorem> d_incThm;
00093
00094 CDList<Expr> d_terms;
00095
00096
00097 std::hash_map<Expr, Theorem> d_termTheorems;
00098
00099
00100
00101 CDList<Expr> d_predicates;
00102
00103 CDList<Expr> d_vars;
00104
00105 std::map<std::string, Expr> d_globals;
00106
00107 std::vector<std::pair<std::string, Expr> > d_boundVarStack;
00108
00109 std::hash_map<std::string, Expr> d_boundVarMap;
00110
00111 ExprMap<Expr> d_parseCache;
00112
00113 ExprMap<Expr> d_tccCache;
00114
00115
00116 std::vector<Theory*> d_theories;
00117
00118
00119 std::hash_map<int, Theory*> d_theoryMap;
00120
00121
00122 Theory* d_solver;
00123
00124
00125 ExprHashMap<std::vector<Expr> > d_varModelMap;
00126
00127 ExprHashMap<Theorem> d_varAssignments;
00128
00129 std::vector<Expr> d_basicModelVars;
00130
00131
00132
00133
00134
00135
00136 ExprHashMap<Theorem> d_simplifiedModelVars;
00137
00138
00139 const bool* d_simplifyInPlace;
00140
00141 Theorem (TheoryCore::*d_currentRecursiveSimplifier)(const Expr&);
00142
00143
00144
00145
00146
00147
00148 unsigned d_resourceLimit;
00149
00150
00151
00152
00153
00154 unsigned d_timeBase;
00155 unsigned d_timeLimit;
00156
00157 bool d_inCheckSATCore;
00158 bool d_inAddFact;
00159 bool d_inRegisterAtom;
00160 bool d_inPP;
00161
00162 IF_DEBUG(ExprMap<bool> d_simpStack;)
00163
00164
00165
00166 friend class CoreNotifyObj;
00167 class CoreNotifyObj :public ContextNotifyObj {
00168 TheoryCore* d_theoryCore;
00169 public:
00170 CoreNotifyObj(TheoryCore* tc, Context* context)
00171 : ContextNotifyObj(context), d_theoryCore(tc) {}
00172 void notify() { d_theoryCore->getEM()->invalidateSimpCache(); }
00173 };
00174 CoreNotifyObj d_notifyObj;
00175
00176
00177 CDList<Theorem> d_impliedLiterals;
00178
00179
00180 CDO<unsigned> d_impliedLiteralsIdx;
00181
00182
00183
00184
00185 std::vector<Theorem> d_update_thms;
00186
00187
00188 std::vector<Expr> d_update_data;
00189
00190
00191 NotifyList d_notifyEq;
00192
00193
00194 unsigned d_inUpdate;
00195
00196 public:
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 class CoreSatAPI {
00208 public:
00209 CoreSatAPI() {}
00210 virtual ~CoreSatAPI() {}
00211
00212 virtual void addLemma(const Theorem& thm, int priority = 0,
00213 bool atBottomScope = false) = 0;
00214
00215
00216 virtual Theorem addAssumption(const Expr& assump) = 0;
00217
00218
00219
00220
00221
00222
00223 virtual void addSplitter(const Expr& e, int priority) = 0;
00224
00225 virtual bool check(const Expr& e) = 0;
00226 };
00227 private:
00228 CoreSatAPI* d_coreSatAPI;
00229
00230 private:
00231
00232
00233
00234
00235
00236
00237 CoreProofRules* createProofRules(TheoremManager* tm);
00238
00239
00240
00241
00242
00243
00244
00245
00246 typedef enum {
00247 LOW,
00248 NORMAL,
00249 FULL
00250 } EffortLevel;
00251
00252
00253
00254 bool processFactQueue(EffortLevel effort = NORMAL);
00255
00256 void processNotify(const Theorem& e, NotifyList* L);
00257
00258 Theorem rewriteCore(const Theorem& e);
00259
00260 void setupSubFormulas(const Expr& s, const Expr& e, const Theorem& thm);
00261
00262 void processUpdates();
00263
00264
00265
00266 void assertFactCore(const Theorem& e);
00267
00268 void assertFormula(const Theorem& e);
00269
00270 IF_DEBUG(void checkRewriteType(const Theorem& thm);)
00271
00272
00273 Theorem rewriteCore(const Expr& e);
00274
00275
00276
00277
00278
00279
00280 void setFindLiteral(const Theorem& thm);
00281
00282 Theorem rewriteLitCore(const Expr& e);
00283
00284
00285
00286 Theorem getModelValue(const Expr& e);
00287
00288
00289 Expr processCond(const Expr& e, int i);
00290
00291
00292 bool isBasicKind(int kind);
00293
00294
00295 void checkEquation(const Theorem& thm);
00296
00297 void checkSolved(const Theorem& thm);
00298
00299
00300 bool timeLimitReached();
00301
00302 public:
00303
00304 TheoryCore(ContextManager* cm, ExprManager* em,
00305 TheoremManager* tm, Translator* tr,
00306 const CLFlags& flags,
00307 Statistics& statistics);
00308
00309 ~TheoryCore();
00310
00311
00312
00313
00314
00315
00316
00317 void getResource() {
00318 getStatistics().counter("resource")++;
00319 if (d_resourceLimit > 1) d_resourceLimit--;
00320 }
00321
00322
00323 void registerCoreSatAPI(CoreSatAPI* coreSatAPI) { d_coreSatAPI = coreSatAPI; }
00324
00325
00326 void addNotifyEq(Theory* t, const Expr& e) { d_notifyEq.add(t, e); }
00327
00328
00329 Theorem callTheoryPreprocess(const Expr& e);
00330
00331 ContextManager* getCM() const { return d_cm; }
00332 TheoremManager* getTM() const { return d_tm; }
00333 const CLFlags& getFlags() const { return d_flags; }
00334 Statistics& getStatistics() const { return d_statistics; }
00335 ExprTransform* getExprTrans() const { return d_exprTrans; }
00336 CoreProofRules* getCoreRules() const { return d_rules; }
00337 Translator* getTranslator() const { return d_translator; }
00338
00339
00340 ExprMap<Expr>& tccCache() { return d_tccCache; }
00341
00342
00343 const CDList<Expr>& getTerms() { return d_terms; }
00344
00345 int getCurQuantLevel();
00346
00347
00348 void setInPP() { d_inPP = true; }
00349 void clearInPP() { d_inPP = false; }
00350
00351
00352 Theorem getTheoremForTerm(const Expr& e);
00353
00354 unsigned getQuantLevelForTerm(const Expr& e);
00355
00356 const CDList<Expr>& getPredicates() { return d_predicates; }
00357
00358 bool inUpdate() { return d_inUpdate > 0; }
00359
00360 bool okToEnqueue()
00361 { return d_inAddFact || d_inCheckSATCore || d_inRegisterAtom || d_inPP; }
00362
00363
00364
00365
00366 void addSharedTerm(const Expr& e) { }
00367 void assertFact(const Theorem& e);
00368 void checkSat(bool fullEffort) { }
00369 Theorem rewrite(const Expr& e);
00370
00371
00372
00373 void setup(const Expr& e) { }
00374 void update(const Theorem& e, const Expr& d);
00375 Theorem solve(const Theorem& e);
00376
00377 Theorem simplifyOp(const Expr& e);
00378 void checkType(const Expr& e);
00379 Cardinality finiteTypeInfo(Expr& e, Unsigned& n,
00380 bool enumerate, bool computeSize);
00381 void computeType(const Expr& e);
00382 Type computeBaseType(const Type& t);
00383 Expr computeTCC(const Expr& e);
00384 Expr computeTypePred(const Type& t,const Expr& e);
00385 Expr parseExprOp(const Expr& e);
00386 ExprStream& print(ExprStream& os, const Expr& e);
00387
00388
00389 void refineCounterExample();
00390 bool refineCounterExample(Theorem& thm);
00391 void computeModelBasic(const std::vector<Expr>& v);
00392
00393
00394
00395
00396
00397
00398
00399 void addFact(const Theorem& e);
00400
00401
00402 Theorem simplify(const Expr& e);
00403
00404
00405 bool inconsistent() { return d_inconsistent ; }
00406
00407
00408 Theorem inconsistentThm() { return d_incThm; }
00409
00410
00411
00412
00413
00414
00415 bool checkSATCore();
00416
00417
00418 bool incomplete() { return d_incomplete.size() > 0 ; }
00419
00420 bool incomplete(std::vector<std::string>& reasons);
00421
00422
00423
00424
00425 void registerAtom(const Expr& e, const Theorem& thm);
00426
00427
00428 Theorem getImpliedLiteral(void);
00429
00430
00431 unsigned numImpliedLiterals() { return d_impliedLiterals.size(); }
00432
00433
00434 Theorem getImpliedLiteralByIndex(unsigned index);
00435
00436
00437
00438
00439
00440
00441 Expr parseExpr(const Expr& e);
00442
00443
00444 Expr parseExprTop(const Expr& e) {
00445 d_boundVarStack.clear();
00446 d_parseCache.clear();
00447 return parseExpr(e);
00448 }
00449
00450
00451 void assignValue(const Expr& t, const Expr& val);
00452
00453 void assignValue(const Theorem& thm);
00454
00455
00456 void addToVarDB(const Expr & e);
00457
00458
00459
00460
00461
00462
00463 void collectBasicVars();
00464
00465 void buildModel(ExprMap<Expr>& m);
00466 bool buildModel(Theorem& thm);
00467
00468 void collectModelValues(const Expr& e, ExprMap<Expr>& m);
00469
00470
00471 void setResourceLimit(unsigned limit) { d_resourceLimit = limit; }
00472
00473 unsigned getResourceLimit() { return d_resourceLimit; }
00474
00475 bool outOfResources() { return d_resourceLimit == 1; }
00476
00477
00478 void initTimeLimit();
00479
00480
00481 void setTimeLimit(unsigned limit);
00482
00483
00484 Theorem rewriteLiteral(const Expr& e);
00485
00486 private:
00487
00488
00489
00490
00491
00492 void assertEqualities(const Theorem& e);
00493
00494
00495 void setIncomplete(const std::string& reason);
00496
00497
00498
00499 Theorem typePred(const Expr& e);
00500
00501 public:
00502
00503
00504
00505 void enqueueFact(const Theorem& e);
00506 void enqueueSE(const Theorem& thm);
00507
00508
00509 void setInconsistent(const Theorem& e);
00510
00511
00512
00513 void setupTerm(const Expr& e, Theory* i, const Theorem& thm);
00514
00515
00516 };
00517
00518
00519 std::ostream& operator<<(std::ostream& os, const NotifyList& l);
00520
00521 }
00522
00523 #endif