00001
00027
00028
00029
00030
00031
00032 #ifndef __unit__
00033 #define __unit__
00034
00035
00036 #include "Chain.hpp"
00037 #include "Clause.hpp"
00038 #include "Formula.hpp"
00039
00040
00041 class Clause;
00042 class Problem;
00043 class UnitList;
00044
00045
00046 enum InputType {
00047 AXIOM,
00048 CONJECTURE,
00049 HYPOTHESIS
00050 };
00051
00052
00053 enum UnitType {
00054 CLAUSE,
00055 FORMULA
00056 };
00057
00058
00059 enum DefType {
00060 DT_NONE,
00061 DT_PRED,
00062 DT_FUN
00063 };
00064
00065
00066 enum InferenceRule {
00067 IR_INPUT,
00068 IR_PROP,
00069 IR_PERMUT,
00070 IR_FLATTEN,
00071 IR_REORDER_EQ,
00072 IR_HALF_EQUIV,
00073 IR_ENNF,
00074 IR_RM_EQUIV,
00075 IR_MINISCOPE,
00076 IR_SKOLEMIZE,
00077 IR_RECTIFY,
00078 IR_SWAP,
00079 IR_CLAUSIFY,
00080 IR_UNKNOWN
00081 };
00082
00083
00084
00085
00086
00087 class Unit {
00088 private:
00089 class Data;
00090
00091 public:
00092
00093 Unit ();
00094 Unit (const Unit& a);
00095 Unit (char* name, InputType untype, const Formula&);
00096 Unit (char* name, InputType untype, const Clause&);
00097 Unit (InferenceRule, const Formula&, const Unit& parent);
00098 Unit (InferenceRule, const Clause&, const Unit& parent);
00099 Unit (const Clause&, const UnitList& parents);
00100 Unit (const Formula&, const UnitList& parents);
00101 explicit Unit (void*);
00102 ~Unit ();
00103 void operator = (const Unit& rhs);
00104
00105
00106 bool operator == (const Unit& rhs) const;
00107 UnitType unitType () const;
00108 InputType inputType () const;
00109 DefType defType () const;
00110 void setDefType (DefType);
00111 const Formula& formula () const;
00112 const Clause& clause () const;
00113 void setFormula (Formula f);
00114 char* name () const;
00115 InferenceRule rule () const;
00116 long number () const;
00117 const UnitList& parents () const;
00118 void* giveAway ();
00119
00120
00121 void* operator new (size_t);
00122
00123
00124 bool isEqualityAxiom () const;
00125 bool formulaWithFreeVars () const;
00126 bool makeDefinition (Unit& def);
00127 private:
00128
00129 Data* _data;
00130 };
00131
00132
00133 class UnitList
00134 : public Lst<Unit>
00135 {
00136 public:
00137
00138 UnitList ();
00139 UnitList (const UnitList&);
00140 explicit UnitList (const Unit& t);
00141 UnitList (const Unit& head, const UnitList& tail);
00142 explicit UnitList (LstData<Unit>*);
00143 UnitList (InputType tp, const FormulaList& formulas);
00144
00145
00146 const UnitList& tail () const
00147 { return static_cast<const UnitList&>(Lst<Unit>::tail()); }
00148 };
00149
00150
00151 class Unit::Data
00152 # if DEBUG_PREPRO
00153 : public Memory <CID_UNIT>
00154 # endif
00155 {
00156 public:
00157 Data (char* name, InputType untype, const Formula&);
00158 Data (char* name, InputType untype, const Clause&);
00159 Data (InferenceRule, const Formula&, const Unit& parent);
00160 Data (InferenceRule, const Clause&, const Unit& parent);
00161 Data (const Clause&, const UnitList& parents);
00162 Data (const Formula&, const UnitList& parents);
00163 ~Data ();
00164
00165 void ref ();
00166 void deref ();
00167
00168
00169 UnitType unitType () const;
00170 InputType inputType () const;
00171 DefType defType () const;
00172 void setDefType (DefType);
00173 const Formula& formula () const;
00174 const Clause& clause () const;
00175 void setFormula (Formula f);
00176 char* name () const;
00177 InferenceRule rule () const;
00178 long number () const;
00179 const UnitList& parents () const;
00180 InputType intype () const;
00181
00182 private:
00183
00184 int _counter;
00185 UnitType _untype;
00186 InputType _intype;
00187 InferenceRule _rule;
00188 long _number;
00189 UnitList _parents;
00190 char* _name;
00191 Clause _clause;
00192 Formula _formula;
00193 DefType _defType;
00194
00195 static long _lastNumber;
00196 };
00197
00198
00199 typedef Chain<Unit,CID_UNIT_LINK> UnitChain;
00200
00201
00202 ostream& operator << (ostream&, InputType);
00203 ostream& operator << (ostream&, UnitType);
00204 ostream& operator << (ostream&, UnitChain&);
00205 ostream& operator << (ostream&, Unit);
00206
00207
00208
00209
00210 inline
00211 Unit::Unit ()
00212 :
00213 _data (0)
00214 {
00215 }
00216
00217
00218 inline
00219 Unit::~Unit ()
00220 {
00221 if (_data) {
00222 _data->deref ();
00223 }
00224 }
00225
00226
00227
00228 inline
00229 Unit::Unit (const Unit& t)
00230 :
00231 _data (t._data)
00232 {
00233 if (_data) {
00234 _data->ref ();
00235 }
00236 }
00237
00238
00239
00240
00241 inline
00242 Unit::Unit (void* d)
00243 :
00244 _data (reinterpret_cast<Data*>(d))
00245 {
00246 _data->ref();
00247 }
00248
00249
00250 inline
00251 Unit::Unit (char* name, InputType untype, const Formula& formula)
00252 :
00253 _data (new Data(name, untype, formula))
00254 {
00255 }
00256
00257
00258 inline
00259 Unit::Unit (char* name, InputType untype, const Clause& clause)
00260 :
00261 _data (new Data(name, untype, clause))
00262 {
00263 }
00264
00265
00266 inline
00267 Unit::Unit (InferenceRule ir, const Formula& f, const Unit& parent)
00268 :
00269 _data (new Data(ir, f, parent))
00270 {
00271 }
00272
00273
00274 inline
00275 Unit::Unit (InferenceRule ir, const Clause& clause, const Unit& parent)
00276 :
00277 _data (new Data(ir, clause, parent))
00278 {
00279 }
00280
00281
00282 inline
00283 Unit::Unit (const Clause& clause, const UnitList& parents)
00284 :
00285 _data (new Data(clause, parents))
00286 {
00287 }
00288
00289
00290 inline
00291 Unit::Unit (const Formula& formula, const UnitList& parents)
00292 :
00293 _data (new Data(formula, parents))
00294 {
00295 }
00296
00297
00298 inline
00299 bool Unit::operator == (const Unit& rhs) const
00300 {
00301 ASS (_data && rhs._data);
00302
00303 return _data == rhs._data;
00304 }
00305
00306
00307 inline
00308 UnitType Unit::unitType () const
00309 {
00310 return _data->unitType ();
00311 }
00312
00313
00314 inline
00315 const Formula& Unit::formula () const
00316 {
00317 ASS (unitType() == FORMULA);
00318
00319 return _data->formula();
00320 }
00321
00322
00323 inline
00324 void Unit::setFormula (Formula f)
00325 {
00326 _data->setFormula(f);
00327 }
00328
00329
00330 inline
00331 void Unit::setDefType (DefType dt)
00332 {
00333 _data->setDefType (dt);
00334 }
00335
00336
00337 inline
00338 const Clause& Unit::clause () const
00339 {
00340 ASS (unitType() == CLAUSE);
00341
00342 return _data->clause();
00343 }
00344
00345
00346 inline
00347 InputType Unit::inputType () const
00348 {
00349 return _data->inputType ();
00350 }
00351
00352
00353 inline
00354 DefType Unit::defType () const
00355 {
00356 return _data->defType ();
00357 }
00358
00359
00360 inline
00361 long Unit::number () const
00362 {
00363 return _data->number ();
00364 }
00365
00366
00367 inline
00368 InferenceRule Unit::rule () const
00369 {
00370 return _data->rule ();
00371 }
00372
00373
00374 inline
00375 const UnitList& Unit::parents () const
00376 {
00377 return _data->parents ();
00378 }
00379
00380
00381 inline
00382 char* Unit::name () const
00383 {
00384 return _data->name ();
00385 }
00386
00387
00388
00389
00390
00391 inline
00392 void* Unit::giveAway ()
00393 {
00394 return _data;
00395 }
00396
00397
00398
00399
00400
00401 inline
00402 void Unit::Data::ref ()
00403 {
00404 ASS (this);
00405
00406 _counter++;
00407 }
00408
00409
00410 inline
00411 void Unit::Data::deref ()
00412 {
00413 ASS (this);
00414 ASS (_counter > 0);
00415 _counter--;
00416
00417 if (_counter == 0) {
00418 delete this;
00419 }
00420 }
00421
00422
00423 inline
00424 UnitType Unit::Data::unitType () const
00425 {
00426 return _untype;
00427 }
00428
00429
00430 inline
00431 const Formula& Unit::Data::formula () const
00432 {
00433 return _formula;
00434 }
00435
00436
00437 inline
00438 void Unit::Data::setFormula (Formula f)
00439 {
00440 _formula = f;
00441 }
00442
00443
00444 inline
00445 void Unit::Data::setDefType (DefType dt)
00446 {
00447 _defType = dt;
00448 }
00449
00450
00451 inline
00452 const Clause& Unit::Data::clause () const
00453 {
00454 return _clause;
00455 }
00456
00457
00458
00459
00460
00461 inline
00462 const UnitList& Unit::Data::parents () const
00463 {
00464 return _parents;
00465 }
00466
00467
00468 inline
00469 InputType Unit::Data::inputType () const
00470 {
00471 return _intype;
00472 }
00473
00474
00475 inline
00476 DefType Unit::Data::defType () const
00477 {
00478 return _defType;
00479 }
00480
00481
00482 inline
00483 long Unit::Data::number () const
00484 {
00485 return _number;
00486 }
00487
00488
00489 inline
00490 char* Unit::Data::name () const
00491 {
00492 return _name;
00493 }
00494
00495
00496 inline
00497 InferenceRule Unit::Data::rule () const
00498 {
00499 return _rule;
00500 }
00501
00502
00503
00504
00505 inline
00506 UnitList::UnitList ()
00507 :
00508 Lst<Unit> ()
00509 {
00510 }
00511
00512
00513
00514
00515 inline
00516 UnitList::UnitList (const UnitList& ts)
00517 :
00518 Lst<Unit> (ts)
00519 {
00520 }
00521
00522
00523
00524
00525 inline
00526 UnitList::UnitList (LstData<Unit>* d)
00527 :
00528 Lst<Unit> (d)
00529 {
00530 }
00531
00532
00533
00534
00535 inline
00536 UnitList::UnitList (const Unit &hd, const UnitList& tl)
00537 :
00538 Lst<Unit> (hd,tl)
00539 {
00540 }
00541
00542
00543
00544
00545 inline
00546 UnitList::UnitList (const Unit &hd)
00547 :
00548 Lst<Unit> (hd)
00549 {
00550 }
00551
00552
00553 #endif // __unit__