#ifndef GINAC_RA_OPENINTERVAL_H #define GINAC_RA_OPENINTERVAL_H /** * A class for an open interval providing interval arithmetic operations. * All operations are performed in constant time. * *@author Ulrich Loup *@since 2010-08-03 *@version 2010-09-22 * * Notation is following http://www.possibility.com/Cpp/CppCodingStandard.html. */ #include using namespace GiNaC; #include #include #include using namespace std; namespace GiNaC { class OpenInterval : public basic { GINAC_DECLARE_REGISTERED_CLASS(OpenInterval, basic) public: ////////////////////////// // Con- and destructors // ////////////////////////// /** * Constructs an open interval ]n-1, n+1[. *@param n middle */ OpenInterval(const numeric& n); /** * Constructs an open interval ]l, r[. *@param l left bound of the open interval ]l, r[ *@param r right bound of the open interval ]l, r[ */ OpenInterval(const numeric& l, const numeric& r) throw(invalid_argument); /** * Constructs an open interval from another. *@param i other open interval */ OpenInterval(const OpenInterval& i); ~OpenInterval(); /////////////// // Selectors // /////////////// /** * Selects the left bound reference. *@return *numeric */ const numeric& Left() const; /** * Selects the right bound reference. *@return *numeric */ const numeric& Right() const; /** * Set new bounds for the interval. *@param l new left bound *@param r new right bound */ void setBounds(const numeric&, const numeric&) throw(invalid_argument); /////////////// // Operators // /////////////// const bool operator==(const OpenInterval&) const; const bool operator!=(const OpenInterval&) const; const bool operator<=(const OpenInterval&) const; const bool operator>=(const OpenInterval&) const; //////////////// // Operations // //////////////// /** * @return true in case the bounds of the interval are both zero */ const bool isZero() const; /** * @return true in case the interval is zero or it does not contain zero and its right bound is not zero itself (for root order determination) */ const bool isNormalized() const; /** *@param n *@return true in case n is contained in this OpenInterval */ const bool contains(const numeric& n) const; /////////////////////////// // Arithmetic Operations // /////////////////////////// /** Adds two intervals and returns a reference to their sum, allocated on the heap. *@param o *@return sum allocated on the heap */ const OpenInterval& add_dyn(const OpenInterval& o) const; /** Returns the negative value, allocated on the heap. *@return negative value allocated on the heap */ const OpenInterval& minus_dyn() const; /** Multiplies two intervals and returns a reference to their product, allocated on the heap. *@param o *@return product allocated on the heap */ const OpenInterval& mul_dyn(const OpenInterval& o) const; /////////////////////////// // Relational Operations // /////////////////////////// /** *@param o *@return true in case the other interval equals this */ inline const bool isEqual(const OpenInterval& o) const; /** *@param o *@return true in case the other interval is less then this */ inline const bool isLess(const OpenInterval& o) const; /** *@param o *@return true in case the other interval is greater then this */ inline const bool isGreater(const OpenInterval& o) const; protected: ///////////////////////// // Methods from basic // ///////////////////////// // int compare_same_type(const basic & other) const; void do_print(const print_context&, unsigned level = 0) const; bool is_equal_same_type(const basic&) const; ex eval(int level = 0) const; // unsigned calchash() const; private: //////////////// // Attributes // //////////////// numeric* const mpLeft; // pointer to the left bound of the interval (pointer is fixed, value not) numeric* const mpRight; // pointer to the right bound of the interval (pointer is fixed, value not) }; // class OpenInterval } // namespace GiNaC #endif