GiNaCRA  0.6.4
MultivariatePolynomial.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 GINACRA_MULTIVARIATEPOLYNOMIAL_H
00024 #define GINACRA_MULTIVARIATEPOLYNOMIAL_H
00025 
00026 // #define GINACRA_MULTIVARIATEPOLYNOMIAL_DEBUG
00027 
00028 #include <ginac/ginac.h>
00029 #include <stdexcept>
00030 
00031 #include "Polynomial.h"
00032 #include "utilities.h"
00033 
00034 namespace GiNaCRA
00035 {
00047     template<class monomialOrdering>
00048     class MultivariatePolynomial:
00049         public Polynomial
00050     {
00051         template<typename monomialOrdering1>
00052         friend class MultivariateTerm;
00053         template<typename monomialOrdering2>
00054         friend class MultivariateMonomial;
00055         template<typename monomialOrdering3>
00056         friend class MultivariateCoefficient;
00057 
00058         public:
00059 
00061             // Con- and destructors //
00063 
00067             MultivariatePolynomial<monomialOrdering>();
00068 
00073             MultivariatePolynomial<monomialOrdering>( const MultivariatePolynomial<monomialOrdering>& p );
00074 
00080             MultivariatePolynomial<monomialOrdering>( const ex& p, const vector<symbol>& l ) throw ( invalid_argument );
00081 
00083             // Selectors //
00085 
00090             const vector<symbol> Variables() const;
00091 
00095             const symbol Variable() const;
00096 
00101             const list<ex> CoefficientExs() const;
00102 
00107             const list<ex> MonomialExs() const;
00108 
00110             // Operators //
00112 
00113             // binary arithmetic operators, see: operators.h
00114             // const MultivariatePolynomial<monomialOrdering> operator+(const MultivariatePolynomial<monomialOrdering>&);
00115             // const MultivariatePolynomial<monomialOrdering> operator-(const MultivariatePolynomial<monomialOrdering>&);
00116             // const MultivariatePolynomial<monomialOrdering> operator*(const MultivariatePolynomial<monomialOrdering>&);
00117 
00118             // unary arithmetic operators, see: operators.h
00119             // const MultivariatePolynomial<monomialOrdering> operator-();
00120 
00121             // relational operators
00122             const bool operator ==( const MultivariatePolynomial<monomialOrdering>& ) const;
00123             const bool operator !=( const MultivariatePolynomial<monomialOrdering>& ) const;
00124 
00125             // assignment operators
00126             const MultivariatePolynomial<monomialOrdering>& operator = ( const MultivariatePolynomial<monomialOrdering>& );
00127             const MultivariatePolynomial<monomialOrdering>& operator = ( const ex& );
00128 
00130             // Operations //
00132 
00138             MultivariatePolynomial<monomialOrdering> diff( const symbol& s, unsigned nth = 1 ) const;
00139 
00145             MultivariatePolynomial<monomialOrdering> diff( const vector<symbol>::const_iterator i, unsigned nth = 1 ) const;
00146 
00152             MultivariatePolynomial<monomialOrdering> trunc( const symbol& s ) const;
00153 
00158             MultivariatePolynomial<monomialOrdering> trunc() const;
00159 
00165             const MultivariatePolynomial<monomialOrdering> divideByLcoeff() const;
00166 
00171             int degree( const symbol& s ) const;
00172 
00176             int degree() const;
00177 
00182             int ldegree( const symbol& s ) const;
00183 
00187             int ldegree() const;
00188 
00193             int tdegree() const;
00194 
00200             int tdegree( const symbol& s ) const;
00201 
00205             const ex lterm() const;
00206 
00210             const ex lcoeff() const;
00211 
00217             const ex coeff( const symbol& s, const unsigned int& n ) const;
00218 
00223             const ex lcoeff( const symbol& s ) const;
00224 
00229             const ex coeff( const ex& monomial ) const throw ( invalid_argument );
00230 
00234             const ex lmon() const;
00235 
00240             bool isZero() const;
00241 
00246             bool isConstant() const;
00247 
00256             const MultivariatePolynomial<monomialOrdering> reduction( const MultivariatePolynomial<monomialOrdering>& g,
00257                                                                       const ex& m ) const
00258                     throw ( invalid_argument );
00259 
00265             const MultivariatePolynomial<monomialOrdering> normalForm( const list<MultivariatePolynomial<monomialOrdering> >& gb ) const
00266                     throw ( invalid_argument );
00267 
00269             // Arithmetic Operations //
00271 
00276             const MultivariatePolynomial<monomialOrdering> add( const MultivariatePolynomial<monomialOrdering>& o ) const throw ( invalid_argument );
00277 
00281             const MultivariatePolynomial<monomialOrdering> minus() const;
00282 
00287             const MultivariatePolynomial<monomialOrdering> mul( const MultivariatePolynomial<monomialOrdering>& o ) const throw ( invalid_argument );
00288 
00293             const MultivariatePolynomial<monomialOrdering> pow( const unsigned e ) const throw ( invalid_argument );
00294 
00296             // Methods from ex //
00298 
00299             void print( const print_context& c, unsigned level = 0 ) const;
00300 
00302             // Auxiliary methods//
00304 
00308             const vector<symbol> mergeVariables( vector<symbol> l ) const;
00309 
00310         protected:
00311 
00313             // Relational Operations //
00315 
00320             inline const bool isEqual( const MultivariatePolynomial<monomialOrdering>& o ) const;
00321 
00322         private:
00323 
00325             // Attributes //
00327 
00328             // Caution: order of declaration == order of initialization
00329             vector<symbol>                     mVariables;    // ordered lexicographicly
00330             symbol                             mVariable;    // the symbol with the maximal degree (not necessarily unique)
00331             std::map<ex, ex, monomialOrdering> mTermExs;    // std::map assigning monomials to their respective coefficients of this polynomial in order given by constructor. mTermExs.first are the monomials, mTermExs.second the coefficients
00332 
00334             // Auxiliary methods//
00336 
00340             const symbol determineVariable() const;
00341 
00345             const std::map<ex, ex, monomialOrdering> determineTermExs() const;
00346 
00347     };    // class MultivariatePolynomial
00348 
00350     // IMPLEMENTATION (in header file because of template parameter) //
00352 
00353 #include "MultivariatePolynomial.tpp"
00354 
00355 }    // namespace GiNaC
00356 
00357 #endif