GiNaCRA  0.6.4
UnivariatePolynomialSet.cpp
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 #include <assert.h>
00024 
00025 #include "UnivariatePolynomialSet.h"
00026 
00035 namespace GiNaCRA
00036 {
00038     // Selectors //
00040 
00041     const bool UnivariatePolynomialSet::isConstant( symbol& x ) const
00042     {
00043         for( UnivariatePolynomialSet::const_iterator it = this->begin(); it != this->end(); ++it )
00044         {
00045             if( static_cast<ex>(*it).degree( x ) != 0 )
00046                 return false;
00047         }
00048         return true;
00049     }
00050 
00051     const symbol UnivariatePolynomialSet::variable() const
00052     {
00053         return this->begin()->variable();
00054     }
00055 
00057     // Modifiers //
00059 
00060     pair<UnivariatePolynomialSet::iterator, bool> UnivariatePolynomialSet::insert( const UnivariatePolynomial& x ) throw ( invalid_argument )
00061     {
00062         assert( this->empty() || (x.variable() == this->begin()->variable()));
00063         //            throw invalid_argument( "The main variable does not fit!" );
00064         return unordered_set<UnivariatePolynomial, UnivariatePolynomialSetHasher, UnivariatePolynomialSetEquals>::insert( x );
00065     }
00066 
00067     template<class InputIterator>
00068     void UnivariatePolynomialSet::insert( InputIterator first, InputIterator last ) throw ( invalid_argument )
00069     {
00070         for( UnivariatePolynomialSet::iterator it = first; it != last; ++it )
00071             insert( *it );
00072     }
00073 
00074     void UnivariatePolynomialSet::removeNumbers()
00075     {
00076         list<UnivariatePolynomial> toDelete = list<UnivariatePolynomial>();
00077         for( UnivariatePolynomialSet::const_iterator it = this->begin(); it != this->end(); ++it )
00078             if( it->isConstant() && GiNaC::is_exactly_a<numeric>( it->lcoeff() ))
00079                 toDelete.push_back( *it );
00080         for( list<UnivariatePolynomial>::const_iterator i = toDelete.begin(); i != toDelete.end(); ++i )
00081             this->erase( *i );
00082     }
00083 
00084     const UnivariatePolynomialSet UnivariatePolynomialSet::makePrimitive()
00085     {
00086         UnivariatePolynomialSet reducedSet = UnivariatePolynomialSet();
00087         for( UnivariatePolynomialSet::const_iterator it = this->cbegin(); it != this->cend(); ++it )
00088         {
00089             ex c = it->content();
00090             if( GiNaC::is_exactly_a<numeric>( c ))
00091                 reducedSet.insert( it->primpart( c ));
00092             else
00093                 reducedSet.insert( *it );
00094         }
00095         return reducedSet;
00096     }
00097 }    // namespace GiNaC
00098