GiNaCRA
0.6.4
|
00001 /* 00002 * GiNaCRA - GiNaC Real Algebra package 00003 * Copyright (C) 2010-2012 Ulrich Loup, Joachim Redies, Sebastian Junges 00004 * 00005 * This file is part of GiNaCRA. 00006 * 00007 * GiNaCRA is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * GiNaCRA is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GiNaCRA. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 */ 00021 00022 00023 #ifndef GINACRA_OPENINTERVAL_H 00024 #define GINACRA_OPENINTERVAL_H 00025 00026 #include <ginac/ginac.h> 00027 #include <stdexcept> 00028 00029 #include "settings.h" 00030 00031 namespace GiNaCRA 00032 { 00033 using GiNaC::basic; 00034 using GiNaC::numeric; 00035 using GiNaC::ex; 00036 using GiNaC::print_context; 00037 using GiNaC::status_flags; 00038 00040 // Typedefs // 00042 00043 class OpenInterval; 00044 typedef std::map<GiNaC::symbol, OpenInterval, GiNaC::ex_is_less> evalintervalmap; 00045 00055 class OpenInterval: 00056 public basic 00057 { 00058 // Call GiNaC macro (registrar.h) for initiating the implementation into the basic type. 00059 GINAC_DECLARE_REGISTERED_CLASS(OpenInterval, basic) 00060 00061 public: 00062 00064 // Con- and destructors // 00066 00071 OpenInterval( const numeric& n ); 00072 00078 OpenInterval( const numeric& l, const numeric& r ) throw ( std::invalid_argument ); 00079 00084 OpenInterval( const OpenInterval& i ); 00085 00086 ~OpenInterval(); 00087 00089 // Selectors // 00091 00096 void setLeft( const numeric& l ) throw ( std::invalid_argument ); 00097 00102 void setRight( const numeric& r ) throw ( std::invalid_argument ); 00103 00108 const numeric left() const; 00109 00114 const numeric right() const; 00115 00117 // Operations // 00119 00123 const bool isZero() const; 00124 00128 const bool isNormalized() const; 00129 00134 const bool contains( const numeric& n ) const; 00135 00140 const bool contains( const OpenInterval& o ) const; 00141 00147 const bool meets( const numeric& n ) const; 00148 00153 const OpenInterval intersection( const OpenInterval& o ) const; 00154 00158 const numeric midpoint() const; 00159 00165 const numeric sample() const; 00166 00170 const numeric sampleFast() const 00171 { 00172 return (mLeft.numer() < RealAlgebraicNumberSettings::MAX_FASTSAMPLE_BOUND 00173 && mRight.numer() < RealAlgebraicNumberSettings::MAX_FASTSAMPLE_BOUND 00174 && mLeft.denom() < RealAlgebraicNumberSettings::MAX_FASTSAMPLE_BOUND 00175 && mRight.denom() < RealAlgebraicNumberSettings::MAX_FASTSAMPLE_BOUND) ? sample() : midpoint(); 00176 } 00177 00183 const OpenInterval abs() const; 00184 00186 // Arithmetic Operations // 00188 00193 const OpenInterval add( const OpenInterval& o ) const; 00194 00198 const OpenInterval minus() const; 00199 00204 const OpenInterval mul( const OpenInterval& o ) const; 00205 00211 const OpenInterval div( const OpenInterval& o ) const throw ( std::invalid_argument ); 00212 00217 const OpenInterval pow( unsigned e ) const; 00218 00225 static OpenInterval evaluate( const ex& p, evalintervalmap m ) throw ( std::invalid_argument ); 00226 00228 // Relational Operations // 00230 00235 const bool isEqual( const OpenInterval& o ) const; 00236 00241 const bool isLess( const OpenInterval& o ) const; 00242 00247 const bool isGreater( const OpenInterval& o ) const; 00248 00249 protected: 00250 00252 // Methods from basic // 00254 00255 bool is_equal_same_type( const basic& ) const; 00256 void do_print( const print_context&, unsigned level = 0 ) const; 00257 ex evalf( int level = 0 ) const; 00258 unsigned calchash() const; 00259 00260 private: 00261 00263 // Attributes // 00265 00266 numeric mLeft; // pointer to the left bound of the interval (pointer is fixed, value not) 00267 numeric mRight; // pointer to the right bound of the interval (pointer is fixed, value not) 00268 00270 // AUXILIARY FUNCTIONS // 00272 00281 inline static const numeric findSample( cln::cl_I numeratorL, cln::cl_I denominatorL, cln::cl_I numeratorR, cln::cl_I denominatorR ); 00282 00291 inline static const numeric findSample( long numeratorL, long denominatorL, long numeratorR, long denominatorR ); 00292 00293 }; // class OpenInterval 00294 00295 } // namespace GiNaC 00296 00297 #endif