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: AssumptionsValue
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 
00044 #include "expr.h"
00045 
00046 #ifndef _CVC_lite__assumptions_h_
00047 #define _CVC_lite__assumptions_h_
00048 
00049 #include <iostream>
00050 #include <functional>
00051 #include <iterator>
00052 #include <vector>
00053 // #include "theorem.h"
00054 // #include "proof.h"
00055 // #include "assumptions_value.h"
00056 
00057 namespace CVCL {
00058 
00059   //class Theorem;
00060   class AssumptionsValue;
00061   class AVHash;
00062 
00063   class Assumptions {
00064   private:
00065     AssumptionsValue *d_val;
00066     // Private constructors for internal use.  Assumes v != NULL.
00067     Assumptions(AssumptionsValue *v);
00068 
00069     friend bool findExpr(const Assumptions& a, const Expr& e, 
00070                          std::vector<Theorem>& gamma);
00071     friend bool findExprs(const Assumptions& a, const std::vector<Expr>& es, 
00072                           std::vector<Theorem>& gamma);
00073 
00074     // helper function for []
00075     const Theorem& findTheorem(const Expr& e) const; 
00076 
00077 
00078   public:
00079     //! Default constructor: no value is created
00080     Assumptions() : d_val(NULL) { }
00081     //! Constructor from a vector of theorems
00082     Assumptions(const std::vector<Theorem>& v);
00083     //! Constructor for one theorem (common case)
00084     Assumptions(const Theorem& t);
00085     //! Constructor for two theorems (common case)
00086     Assumptions(const Theorem& t1, const Theorem& t2);
00087 
00088     // Desctructor
00089     ~Assumptions();
00090     // Copy constructor.  IMPORTANT: it does NOT create a clean copy
00091     // of the set, but only copies the pointer.  Modifying the copy
00092     // will modify the original value!  Use copy() for cloning.
00093     Assumptions(const Assumptions &assump);
00094     // Assignment.
00095     Assumptions &operator=(const Assumptions &assump);
00096 
00097     bool isNull() const { return d_val == NULL; }
00098     // If we are Null, create a new empty AssumptionsValue.  Otherwise
00099     // do nothing.
00100     void init();
00101     // Create a clean copy of Assumptions, completely independent of
00102     // the original one
00103     Assumptions copy() const;
00104     // Add a new assumption.  If label is not supplied, generate a new one.
00105     // If we are Null, the initialization happens.
00106     void add(const Theorem& t);
00107     void add(const Assumptions& a);
00108 //     void add(const Expr &e);
00109 //     void add(const Expr& e, int level);
00110 //     void add(const Expr& e, int level, const Proof& label);
00111     // Remove the assumption A from the set.  'A' does not have to be
00112     // in the set.
00113     // Note, that even if the set becomes empty, the value remains non-Null.
00114     //void erase(const Expr &e); // TODO: remove or change to remove parent?
00115     // Similarly, erase a set of assumptions at once
00116     //void erase(const Theorem &t);
00117     //void erase(const Assumptions& a);
00118     // Return Assumption associated with the expression.  The
00119     // value will be Null if the assumption is not in the set.
00120     //
00121     // NOTE: do not try to assign anything to the result, it won't work.
00122     const Theorem& operator[](const Expr& e) const;
00123 
00124     // find only searches through current set of assumptions, will not recurse
00125     const Theorem& find(const Expr& e) const;
00126 
00127     // clear the set of assumptions
00128     void clear();
00129 
00130     // get the size
00131     int size() const;
00132     
00133     //! Iterator for the Assumptions: points to class Theorem.
00134     /*! Cannot inherit from vector<Theorem>::const_iterator in gcc 2.96 */
00135     class iterator : public std::iterator<std::input_iterator_tag,Theorem,ptrdiff_t> {
00136       // Let's be friends
00137       friend class Assumptions;
00138     private:
00139       std::vector<Theorem>::const_iterator d_it;
00140 
00141       iterator(const std::vector<Theorem>::const_iterator& i): d_it(i) { }
00142     public:
00143       //! Default constructor
00144       iterator() { }
00145       //! Destructor
00146       ~iterator() { }
00147       //! Equality
00148       bool operator==(const iterator& i) const { return (d_it == i.d_it); }
00149       //! Disequality
00150       bool operator!=(const iterator& i) const { return (d_it != i.d_it); }
00151       //! Dereference operator
00152       const Theorem& operator*() const { return *d_it; }
00153       //! Member dereference operator
00154       const Theorem* operator->() const { return &(operator*()); }
00155       //! Prefix increment
00156       iterator& operator++();
00157       //! Proxy class for postfix increment
00158       class Proxy {
00159         const Theorem* d_t;
00160       public:
00161         Proxy(const Theorem& t) : d_t(&t) { }
00162         const Theorem& operator*() { return *d_t; }
00163       };
00164       //! Postfix increment
00165       Proxy operator++(int);
00166     };
00167 
00168     iterator begin() const;
00169     iterator end() const;
00170 
00171     // Adding from iterators
00172     void add(const iterator& it) {
00173       add(*it);
00174     }
00175 
00176 //     size_t size()  const { return (d_val)? d_val->d_map.size() : 0; }
00177     bool empty() const;
00178 
00179     // Check / set the flag indicating that the value is constant
00180     bool isConst() const;
00181     void setConst();
00182 
00183     // Merging assumptions
00184     friend Assumptions operator+(const Assumptions& a1,
00185                                  const Assumptions& a2);
00186 
00187     friend Assumptions operator-(const Assumptions& a1,
00188                                  const Assumptions& a2);
00189 
00190     // returns all assumptions except e or es
00191     // functions will do recursive graph traversal
00192     friend Assumptions operator-(const Assumptions& a,
00193                                   const Expr& e);
00194     friend Assumptions operator-(const Assumptions& a,
00195                                  const std::vector<Expr>& es);
00196 
00197     // Print functions
00198     std::string toString() const;
00199 
00200     friend std::ostream&
00201       operator<<(std::ostream& os, const Assumptions &assump);
00202 
00203     friend bool operator==(const Assumptions& a1, const Assumptions& a2);
00204     friend bool operator!=(const Assumptions& a1, const Assumptions& a2);
00205 
00206     void print() const;
00207   }; // end of class Assumptions
00208 
00209   bool operator==(const AssumptionsValue& a1, const AssumptionsValue& a2);
00210   bool operator!=(const AssumptionsValue& a1, const AssumptionsValue& a2);
00211 
00212   // comparison operators
00213   inline bool operator==(const Assumptions& a1, const Assumptions& a2) {
00214     if (a1.d_val == a2.d_val) return true;
00215     if (a1.d_val == NULL || a2.d_val == NULL) return false;
00216     return (*a1.d_val == *a2.d_val);
00217   }
00218 
00219   inline bool operator!=(const Assumptions& a1, const Assumptions& a2) { 
00220     if (a1.d_val == a2.d_val) return false;
00221     if (a1.d_val == NULL || a2.d_val == NULL) return true;
00222     return (*a1.d_val != *a2.d_val);
00223   }
00224 
00225 } // end of namespace CVCL
00226 
00227 #endif

Generated on Fri May 20 13:13:48 2005 for CVC Lite by  doxygen 1.3.9.1