GiNaCRA  0.6.4
RealAlgebraicNumberIR.h
Go to the documentation of this file.
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 GINAC_RA_INTERVALREPRESENTATION_H
00024 #define GINAC_RA_INTERVALREPRESENTATION_H
00025 
00026 // Optimization flags
00027 #define GINACRA_INTERVALREPRESENTATION_OPT_NORMALIZE_POLYNOMIAL // call normalizePolynomial in the constructor
00028 
00029 #include <ginac/flags.h>
00030 #include <ginac/registrar.h>
00031 #include <ginac/ginac.h>
00032 #include <stdexcept>
00033 
00034 #include "settings.h"
00035 #include "RationalUnivariatePolynomial.h"
00036 #include "OpenInterval.h"
00037 #include "RealAlgebraicNumber.h"
00038 #include "operators.h"
00039 
00040 namespace GiNaCRA
00041 {
00052     class RealAlgebraicNumberIR:
00053         public RealAlgebraicNumber,
00054         public basic
00055     {
00056         // Call GiNaC macro (registrar.h) for initiating the implementation into the basic type.
00057         GINAC_DECLARE_REGISTERED_CLASS(RealAlgebraicNumberIR, basic)
00058 
00059         public:
00060 
00062             // Con- and destructors //
00064 
00065             //     RealAlgebraicNumberIR(const symbol& s) throw(invalid_argument); -> private
00066 
00070             //RealAlgebraicNumberIR( );
00071 
00086             RealAlgebraicNumberIR( const RationalUnivariatePolynomial& p,
00087                                    const OpenInterval& i,
00088                                    const list<RationalUnivariatePolynomial>& s = list<RationalUnivariatePolynomial>(),
00089                                    const bool normalize = true,
00090                                    const bool isRoot = true )
00091                     throw ( invalid_argument );
00092 
00096             ~RealAlgebraicNumberIR();
00097 
00101             RealAlgebraicNumberPtr clone() const;
00102 
00104             // Selectors //
00106 
00111             const RationalUnivariatePolynomial polynomial() const
00112             {
00113                 return mPolynomial;
00114             }
00115 
00120             const OpenInterval interval() const
00121             {
00122                 return mInterval;
00123             }
00124 
00129             const list<RationalUnivariatePolynomial> sturmSequence() const
00130             {
00131                 return mSturmSequence;
00132             }
00133 
00137             const unsigned refinementCount() const
00138             {
00139                 return mRefinementCount;
00140             }
00141 
00143             // Operators //
00145 
00146             // assignment operators
00147 
00151             const RealAlgebraicNumberIR& operator = ( const RealAlgebraicNumberIR& );
00152 
00154             // Operations //
00156 
00159             void normalizeInterval() throw ( invalid_argument );
00160 
00166             void refine( RealAlgebraicNumberSettings::RefinementStrategy strategy = RealAlgebraicNumberSettings::DEFAULT_REFINEMENTSTRATEGY );
00167 
00171             inline void refine( numeric eps )
00172             {
00173                 while( mInterval.right() - mInterval.left() > eps )
00174                     this->refine();
00175             }
00176 
00183             bool refineAvoiding( numeric n );
00184 
00189             GiNaC::sign sgn() const;
00190 
00196             GiNaC::sign sgn( const RationalUnivariatePolynomial& p ) const;
00197 
00202             const numeric approximateValue() const
00203             {
00204                 return mInterval.midpoint();
00205             }
00206 
00211             const numeric sampleValue() const
00212             {
00213                 return mInterval.sample();
00214             }
00215 
00217             // Arithmetic Operations //
00219 
00224             RealAlgebraicNumberIR& add( RealAlgebraicNumberIR& o ) throw ( invalid_argument );
00225 
00229             RealAlgebraicNumberIR& minus() const;
00230 
00235             RealAlgebraicNumberIR& mul( RealAlgebraicNumberIR& o ) throw ( invalid_argument );
00236 
00240             RealAlgebraicNumberIR& inverse() const throw ( invalid_argument );
00241 
00246             RealAlgebraicNumberIR& pow( int e ) throw ( invalid_argument );
00247 
00249             // Relational Operations //
00251 
00256             const bool isEqual( RealAlgebraicNumberIR& o );
00257 
00262             const bool isLessWhileUnequal( RealAlgebraicNumberIR& o );
00263 
00268             const bool isLess( RealAlgebraicNumberIR& o );
00269 
00271             // Methods from basic //
00273 
00274             bool info( unsigned inf ) const;
00275 
00277             // Static Methods //
00279 
00284             static RealAlgebraicNumberIR* zero( const symbol& s );
00285 
00286         protected:
00287 
00289             // Methods from basic //
00291 
00292             bool is_equal_same_type( const basic& other ) const;
00293 
00294             void do_print( const print_context& c, unsigned level = 0 ) const;
00295 
00304             ex evalf( int level = 0 ) const;
00305 
00306             unsigned calchash() const;
00307 
00308         private:
00309 
00311             // Attributes //
00313 
00315             RationalUnivariatePolynomial mPolynomial;
00317             OpenInterval mInterval;
00319             list<RationalUnivariatePolynomial> mSturmSequence;
00321             unsigned mRefinementCount;
00322 
00324             // Con- and destructors //
00326 
00331             RealAlgebraicNumberIR( const symbol& s ) throw ( invalid_argument );
00332     };
00333 
00334     typedef std::tr1::shared_ptr<RealAlgebraicNumberIR> RealAlgebraicNumberIRPtr;
00335 
00336 }    // namespace GiNaC
00337 
00338 #endif