assumptions.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file assumptions.h
00004  * 
00005  * Author: Sergey Berezin
00006  * 
00007  * Created: Dec 10 00:37:49 GMT 2002
00008  *
00009  * <hr>
00010  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00011  * Junior University and by New York University. 
00012  *
00013  * License to use, copy, modify, sell and/or distribute this software
00014  * and its documentation for any purpose is hereby granted without
00015  * royalty, subject to the terms and conditions defined in the \ref
00016  * LICENSE file provided with this distribution.  In particular:
00017  *
00018  * - The above copyright notice and this permission notice must appear
00019  * in all copies of the software and related documentation.
00020  *
00021  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00022  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00023  * 
00024  * <hr>
00025  * 
00026  */
00027 /*****************************************************************************/
00028 // CLASS: Assumptions
00029 //
00030 // AUTHOR: Sergey Berezin, 12/03/2002
00031 //
00032 // Abstract:
00033 //
00034 // Mathematically, the value of class Assumptions is a set of pairs
00035 // 'u:A' on the LHS of the Theorem's sequent.  Both u and A are Expr.
00036 //
00037 // Null assumptions is almost always treated as the empty set.  The
00038 // only exception: iterators cannot be constructed for Null.
00039 //
00040 // This interface should be used as little as possible by the users of
00041 // Theorem class.
00042 ///////////////////////////////////////////////////////////////////////////////
00043 #ifndef _CVC_lite__expr_h_
00044 #include "expr.h"
00045 #endif
00046 
00047 #ifndef _CVC_lite__assumptions_h_
00048 #define _CVC_lite__assumptions_h_
00049 
00050 namespace CVCL {
00051 
00052   //class Theorem;
00053   class AssumptionsValue;
00054   class AVHash;
00055 
00056   class Assumptions {
00057   private:
00058     AssumptionsValue *d_val;
00059 
00060   private:
00061     // Private constructor for internal use.  Assumes v != NULL.
00062     Assumptions(AssumptionsValue *v);
00063 
00064     // helper function for []
00065     const Theorem& findTheorem(const Expr& e) const; 
00066 
00067     static bool findExpr(const Assumptions& a, const Expr& e, 
00068                          std::vector<Theorem>& gamma);
00069     static bool findExprs(const Assumptions& a, const std::vector<Expr>& es, 
00070                           std::vector<Theorem>& gamma);
00071 
00072   public:
00073     //! Default constructor: no value is created
00074     Assumptions() : d_val(NULL) { }
00075     //! Constructor from a vector of theorems
00076     Assumptions(const std::vector<Theorem>& v);
00077     //! Constructor for one theorem (common case)
00078     Assumptions(const Theorem& t);
00079     //! Constructor for two theorems (common case)
00080     Assumptions(const Theorem& t1, const Theorem& t2);
00081 
00082     // Destructor
00083     ~Assumptions();
00084     // Copy constructor.  IMPORTANT: it does NOT create a clean copy
00085     // of the set, but only copies the pointer.  Modifying the copy
00086     // will modify the original value!  Use copy() for cloning.
00087     Assumptions(const Assumptions &assump);
00088     // Assignment.
00089     Assumptions &operator=(const Assumptions &assump);
00090 
00091     bool isNull() const { return d_val == NULL; }
00092     // If we are Null, create a new empty AssumptionsValue.  Otherwise
00093     // do nothing.
00094     void init();
00095     // Create a clean copy of Assumptions, completely independent of
00096     // the original one
00097     Assumptions copy() const;
00098     // Add a new assumption.  If label is not supplied, generate a new one.
00099     // If we are Null, the initialization happens.
00100     void add(const Theorem& t);
00101     void add(const Assumptions& a);
00102     // clear the set of assumptions
00103     void clear();
00104     // get the size
00105     int size() const;
00106     bool empty() const;
00107     // Check / set the flag indicating that the value is constant
00108     bool isConst() const;
00109     void setConst();
00110     
00111     // Print functions
00112     std::string toString() const;
00113     void print() const;
00114 
00115     // Return Assumption associated with the expression.  The
00116     // value will be Null if the assumption is not in the set.
00117     //
00118     // NOTE: do not try to assign anything to the result, it won't work.
00119     const Theorem& operator[](const Expr& e) const;
00120 
00121     // find only searches through current set of assumptions, will not recurse
00122     const Theorem& find(const Expr& e) const;
00123 
00124     //! Iterator for the Assumptions: points to class Theorem.
00125     /*! Cannot inherit from vector<Theorem>::const_iterator in gcc 2.96 */
00126     class iterator : public std::iterator<std::input_iterator_tag,Theorem,ptrdiff_t> {
00127       // Let's be friends
00128       friend class Assumptions;
00129     private:
00130       std::vector<Theorem>::const_iterator d_it;
00131 
00132       iterator(const std::vector<Theorem>::const_iterator& i): d_it(i) { }
00133     public:
00134       //! Default constructor
00135       iterator() { }
00136       //! Destructor
00137       ~iterator() { }
00138       //! Equality
00139       bool operator==(const iterator& i) const { return (d_it == i.d_it); }
00140       //! Disequality
00141       bool operator!=(const iterator& i) const { return (d_it != i.d_it); }
00142       //! Dereference operator
00143       const Theorem& operator*() const { return *d_it; }
00144       //! Member dereference operator
00145       const Theorem* operator->() const { return &(operator*()); }
00146       //! Prefix increment
00147       iterator& operator++();
00148       //! Proxy class for postfix increment
00149       class Proxy {
00150         const Theorem* d_t;
00151       public:
00152         Proxy(const Theorem& t) : d_t(&t) { }
00153         const Theorem& operator*() { return *d_t; }
00154       };
00155       //! Postfix increment
00156       Proxy operator++(int);
00157     };
00158 
00159     iterator begin() const;
00160     iterator end() const;
00161 
00162     // Adding from iterators
00163     void add(const iterator& it) { add(*it); }
00164 
00165     // Merging assumptions
00166     //    friend Assumptions operator+(const Assumptions& a1, const Assumptions& a2);
00167 
00168     //! Returns all (recursive) assumptions except e
00169     friend Assumptions operator-(const Assumptions& a, const Expr& e);
00170     //! Returns all (recursive) assumptions except those in es
00171     friend Assumptions operator-(const Assumptions& a,
00172                                  const std::vector<Expr>& es);
00173 
00174     friend std::ostream& operator<<(std::ostream& os,
00175                                     const Assumptions &assump);
00176 
00177     friend bool operator==(const Assumptions& a1, const Assumptions& a2);
00178     friend bool operator!=(const Assumptions& a1, const Assumptions& a2);
00179 
00180   }; // end of class Assumptions
00181 
00182 } // end of namespace CVCL
00183 
00184 #endif

Generated on Thu Apr 13 16:57:29 2006 for CVC Lite by  doxygen 1.4.4