Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Atom.hpp

Go to the documentation of this file.
00001 
00027 //
00028 //  file Atom.hpp
00029 //  defines class Atom
00030 //
00031 
00032 #ifndef __Atom__
00033 #define __Atom__
00034 
00035 class AtomList;
00036 
00037 #include "Term.hpp"
00038 
00039 
00040 // ****************** class Atom, definition *************************
00041 
00042 
00043 class Atom {
00044  private:
00045   class Data;
00046 
00047  public:
00048   // constructors/destructors
00049   Atom ();
00050   Atom (Signature::Pred* p, const TermList& args); // for atoms
00051   Atom (Signature::Pred* p);                       // for propositional atoms
00052   Atom (const Term& l, const Term& r);             // for equality 
00053   Atom (const Atom& a);
00054   ~Atom ();
00055   void operator = (const Atom& rhs);
00056 
00057   // structure
00058   Signature::Pred* functor () const;
00059   const TermList& args () const;
00060   bool operator == (const Atom& rhs) const;
00061   bool isEquality () const;
00062 
00063   // declared but not defined, to prevent on-heap allocation
00064   void* operator new (size_t);
00065 
00066   // various
00067   bool occurs ( const Signature::Pred* ) const;
00068   bool occurs ( Var v ) const;
00069   bool equal (Atom t) const;
00070   Compare compare (Atom l) const; // comparison, used for normalisation
00071   /*  bool defines (Atom lhs) const;  // auxiliary function for atoms */
00072   void apply (const Substitution& subst);
00073   void rectify (Substitution&, Var& last, VarList& freeVars);
00074   bool hasVarsNotIn (VarListList) const;
00075   bool isDefinition ( Term& lhs, Term& rhs ) const;
00076   void normalize ();
00077   bool isFlat () const; // atom has the form P (x1,...,xn) where xi are variables
00078 
00079   // functions for checking equality axioms
00080   bool isTautology () const;
00081   static bool transitivity (Atom a1, Atom a2, Atom a3);
00082   static bool functionMonotonicity (Atom a1, Atom a2);
00083   static bool predicateMonotonicity (Atom a1, Atom a2, Atom a3);
00084   bool swap (Atom a) const; // true if this is t1 = t2 and a is t2 = t1 */
00085   bool isRenamingOf (Atom a, Substitution& sbst) const;
00086   void occurring (bool* occurrences, Var max) const; // auxiliary for Formula::occurring
00087 
00088  private:
00089   // structure
00090   Data* _data;
00091 }; // class Atom
00092 
00093 
00094 class AtomList 
00095 : public Lst<Atom>
00096 {
00097  public:
00098   // constructors
00099   AtomList ();
00100   AtomList (const AtomList&);
00101   explicit AtomList (const Atom& t); // one-element list
00102   AtomList (const Atom& head, const AtomList& tail);
00103   explicit AtomList (LstData<Atom>*);
00104 
00105   // inherited functions
00106   const AtomList& tail () const
00107     { return static_cast<const AtomList&>(Lst<Atom>::tail()); }
00108 
00109   // miscellaneous
00110   /*
00111   bool occurs ( const Signature::Fun* ) const;
00112   bool occurs ( Var v ) const;
00113   bool equal (AtomList t) const;
00114   Compare compare (AtomList l) const; // comparison, used for normalisation
00115   bool varsOnly () const; // list consists of variables only
00116   int length () const;
00117   void apply (const Substitution& subst);
00118   void rectify (Substitution&, Var& last, VarList& freeVars);
00119   */
00120 }; // class AtomList
00121 
00122 
00123 class Atom::Data 
00124 #   if DEBUG_PREPRO
00125 //    : public Memory <CID_ATOM>
00126 #   endif
00127 {
00128  public:
00129   Data ();
00130   ~Data ();
00131   Data (Signature::Pred* f, const TermList& args);
00132   explicit Data (Signature::Pred* f);
00133   Data (const Term& l, const Term& r);             // for equality 
00134   void ref ();
00135   void deref ();
00136 
00137   Signature::Pred* functor () const;
00138   const TermList& args () const;
00139 
00140  protected:
00141   // structure
00142   int _counter;
00143   Signature::Pred* _functor;
00144   TermList _args;
00145 }; // Atom::Data
00146 
00147 
00148 // ******************* Atom definitions ************************
00149 
00150 inline
00151 Atom::Atom () 
00152   : 
00153   _data (0) 
00154 {
00155 } // Atom::Atom
00156 
00157 
00158 inline
00159 Atom::~Atom () 
00160 {
00161   if (_data) {
00162     _data->deref ();
00163   }
00164 } // Atom::~Atom
00165 
00166 
00167 // 25/08/2002 Torrevieja
00168 inline
00169 Atom::Atom (const Atom& t)
00170   :
00171   _data (t._data)
00172 {
00173   if (_data) {
00174     _data->ref ();
00175   }
00176 } // Atom::Atom
00177 
00178 
00179 // atom constructor
00180 // 25/08/2002 Torrevieja
00181 inline
00182 Atom::Atom (Signature::Pred* p, const TermList& args)
00183   :
00184   _data (new Data (p,args))
00185 {
00186 } // Atom (Signature::Pred* f, TermList& args)
00187 
00188 
00189 // equality atom constructor
00190 // 25/08/2002 Torrevieja
00191 inline
00192 Atom::Atom (const Term& lhs, const Term& rhs)
00193   :
00194   _data (new Data (lhs,rhs))
00195 {
00196 } // Atom (const Term& lhs, const Term& rhs)
00197 
00198 
00199 // propositional atom constructor
00200 // 25/08/2002 Torrevieja
00201 inline
00202 Atom::Atom (Signature::Pred* p)
00203   :
00204   _data (new Data (p))
00205 {
00206 } // Atom (Signature::Pred* p)
00207 
00208 
00209 inline
00210 bool Atom::operator == (const Atom& rhs) const
00211 { 
00212   ASS (_data && rhs._data);
00213 
00214   return _data == rhs._data; 
00215 } // Atom::operator ==
00216 
00217 
00218 inline
00219 Signature::Pred* Atom::functor () const
00220 {
00221   return _data->functor ();
00222 } // Atom::functor ()
00223 
00224 
00225 inline
00226 const TermList& Atom::args () const
00227 {
00228   return _data->args ();
00229 } // Atom::args ()
00230 
00231 
00232 inline
00233 bool Atom::isEquality () const
00234 { 
00235   return functor()->isEquality (); 
00236 } // Atom::isEquality ()
00237 
00238 
00239 // true if the atom has free variables not occurring in vs
00240 // 06/05/2002 Manchester
00241 inline
00242 bool Atom::hasVarsNotIn (VarListList vs) const
00243 {
00244   return args().hasVarsNotIn (vs);
00245 } // Atom::hasVarsNotIn
00246 
00247 
00248 // true if the atom is p(x1,...,xn) where all of xi's are variables
00249 inline 
00250 bool Atom::isFlat () const
00251 {
00252   return args().varsOnly();
00253 } // Atom::isFlat
00254 
00255 
00256 // **************** Atom::Data definitions *********************
00257 
00258 inline 
00259 Atom::Data::~Data ()
00260 {
00261   TRACER( "Atom::Data::~Data" );
00262 
00263   ASS (_counter == 0);
00264 } // Atom::Data::~Data ()
00265 
00266 
00267 inline
00268 void Atom::Data::ref () 
00269 { 
00270   ASS (this);
00271 
00272   _counter++;
00273 } // Atom::Data::ref ()
00274 
00275 
00276 inline
00277 void Atom::Data::deref () 
00278 { 
00279   ASS (this);
00280   ASS (_counter > 0);
00281   _counter--;
00282 
00283   if (_counter == 0) {
00284     delete this;
00285   }
00286 } // Atom::Data::deref ()
00287 
00288 
00289 inline
00290 Atom::Data::Data (Signature::Pred* f, const TermList& args) 
00291   : 
00292   _counter (1),
00293   _functor (f), 
00294   _args (args) 
00295 {
00296 } // Atom::Data::Data
00297 
00298 
00299 inline
00300 Atom::Data::Data (Signature::Pred* f) 
00301   : 
00302   _counter (1),
00303   _functor (f) 
00304 {
00305 } // Atom::Data::Data
00306 
00307 
00308 inline
00309 Signature::Pred* Atom::Data::functor () const 
00310 { 
00311   ASS (this);
00312 
00313   return _functor; 
00314 } // Atom::Data::functor ()
00315 
00316 
00317 inline
00318 const TermList& Atom::Data::args () const 
00319 { 
00320   ASS (this);
00321 
00322   return _args; 
00323 } // Atom::Data::args ()
00324 
00325 
00326 // ******************* AtomList definitions ************************
00327 
00328 inline
00329 AtomList::AtomList () 
00330   : 
00331   Lst<Atom> ()
00332 {
00333 } // AtomList::AtomList
00334 
00335 
00336 // copy constructor
00337 // 25/08/2002 Torrevieja
00338 inline
00339 AtomList::AtomList (const AtomList& ts)
00340   :
00341   Lst<Atom> (ts)
00342 {
00343 } // AtomList::AtomList
00344 
00345 
00346 // almost a copy constructor
00347 // 25/08/2002 Torrevieja
00348 inline
00349 AtomList::AtomList (LstData<Atom>* d)
00350   :
00351   Lst<Atom> (d)
00352 {
00353 } // AtomList::AtomList
00354 
00355 
00356 // 'cons' list constructor
00357 // 25/08/2002 Torrevieja
00358 inline
00359 AtomList::AtomList (const Atom &hd, const AtomList& tl)
00360   :
00361   Lst<Atom> (hd,tl)
00362 {
00363 } // AtomList::AtomList
00364 
00365 
00366 // 'cons' list constructor
00367 // 25/08/2002 Torrevieja
00368 inline
00369 AtomList::AtomList (const Atom &hd)
00370   :
00371   Lst<Atom> (hd)
00372 {
00373 } // AtomList::AtomList
00374 
00375 
00376 ostream& operator << (ostream& str, Atom);
00377 
00378 
00379 #endif // __atom__

Generated on Sat Jun 28 15:08:57 2003 for Vampire by doxygen 1.3.2