polynom.h

Go to the documentation of this file.
00001 
00002 #ifndef POLYNOM_H4D45E74F99FC
00003 #define POLYNOM_H4D45E74F99FC
00004 
00005 #if _MSC_VER > 1000
00006 #pragma once
00007 #endif // _MSC_VER > 1000
00008 
00009 
00010 #include <fstream>
00011 #include <iostream>
00012 #include <assert.h>
00013 
00014 #include <stdlib.h>
00015 #include <iostream>
00016 #include <sstream>
00017 #include <string>
00018 #include <vector>
00019 
00020 
00021 
00027 //using namespace std;
00028 using  std::cout;
00029 using  std::cerr;
00030 using  std::endl;
00031 using  std::string;
00032 using  std::vector;
00033 using  std::ostream;
00034 using  std::stringstream;
00035 
00036 #include "parseTools.h"
00037 
00038 template <class PolynomXY_Type, class RingType, class _istream>
00039 PolynomXY_Type  createFromStream (_istream & _polynomStream, RingType & ringRef )
00040 {
00041 
00042         
00043 //      std::cerr << "_polynomStream: "<<  _polynomStream.str() << std::endl;
00044 
00045         std::string             polynomStr = extractNextBracedData( _polynomStream );
00046 
00047         std::stringstream       polynomStream( polynomStr);
00048 
00049         int                             mononGroupNum = countSubGroups( polynomStream );
00050 
00051         //std::cerr << "momonroups: "<<  mononGroupNum << std::endl;
00052 
00053         
00054         int     MaxMonomDegree = getMaxMonomDegree( polynomStr );
00055         vector<int> degreeTracking(MaxMonomDegree + 1);
00056         
00057         PolynomXY_Type res(MaxMonomDegree);
00058         
00059         
00060         polynomStream.clear();
00061         polynomStream.seekg(0);
00062         
00063         extractChar(polynomStream, '{');
00064         //std::cerr << "matrixStream" << matrixStream.str() << std::endl;
00065 
00066         for ( int currMonomGroupNum = 1;  currMonomGroupNum <= mononGroupNum ;  currMonomGroupNum ++ )
00067         {
00068                 std::string  monomGroup   = extractNextBracedData(polynomStream);
00069                 std::stringstream ssMonomGroup(monomGroup);
00070 
00071                 int currDegree = countElements(ssMonomGroup) -1;
00072                 //std::cerr << "currDegree" << currDegree << std::endl; 
00073                 ssMonomGroup.clear();
00074                 ssMonomGroup.seekg(0);
00075                 //safety:
00076                 assert(degreeTracking[currDegree] == 0);
00077                 degreeTracking[currDegree]  = 1 ;
00078 
00079                 //std::cerr << "monomGroup" << monomGroup << std::endl; 
00080                         
00081                 extractChar(ssMonomGroup, '{');
00082 
00083                 for ( int y_exp=0;  y_exp <= currDegree ;  y_exp++)
00084                 {
00085                         // extract next unbraced Element on current brace Level (finished by ',' or '}')
00086                         string nextElement=extractNextData(ssMonomGroup);
00087 
00088                 //      std::cerr << "nextElement" << nextElement << std::endl; 
00089 
00090                         typename PolynomXY_Type::CoefficientType  coeff = parseNumber( &ringRef, nextElement.c_str(), ringRef.getEpsPrecision() );
00091                 
00092                         res.setCoeff( currDegree - y_exp, y_exp, coeff );
00093 
00094                         if (y_exp !=currDegree ) 
00095                                 extractChar( ssMonomGroup, ',' );
00096                         else extractChar( ssMonomGroup, '}' );
00097                 }
00098                 if (currMonomGroupNum !=mononGroupNum ) 
00099                                 extractChar( polynomStream, ',' );
00100                 else extractChar( polynomStream, '}' );
00101         }
00102         //std::cerr << "polynom initialization OK" << std::endl;
00103         return res;
00104 }
00105 
00106 template <class PolynomXY_Type, class RingType>
00107 PolynomXY_Type  createFromString (string & _polynomString, RingType & ringRef )
00108 {
00109         stringstream strstream   (   _polynomString);
00110         return createFromStream<PolynomXY_Type>( strstream, ringRef);
00111 }
00112 
00118 template <class TNum, class TIndex>
00119 class polynomXY  
00120 {
00121 private:
00122          short  maxDegree; 
00123          short  maxDegreePlusOne;
00124         TIndex   idefs;
00125          short  size;   
00126         TNum *  koeff;  
00127 
00128         //TNum * *      offsets;
00129         string  name;   
00130         
00131 
00132 public:
00133 
00134         typedef TNum    CoefficientType;
00135 
00138                 polynomXY();
00139                 polynomXY(const short _maxDegree);
00140         
00141                 polynomXY(string _name, const short _maxDegree);
00142         
00144                 polynomXY(const polynomXY&);
00145 
00146                 ~polynomXY();
00152                 inline void     setDegree(short maxDegree);
00153 
00154                 inline void     clear(short maxDegree);
00155                 inline void     clear();
00161                 inline void             setCoeff(const short x_exp,const short y_exp, const TNum value);
00162         
00163                 inline TNum             getCoeff(const short x_exp,const short y_exp)   const;
00164         
00165                 inline TNum const       getCoeffConst(const short x_exp,const short y_exp) const;
00166         
00167                 inline const TNum &     getCoeffConstRef(const int x_exp,const int y_exp) const;
00168         
00169                 inline TNum&            getCoeffRef(const short x_exp, const short y_exp);
00170 
00171                 inline TNum const *     getCoeffConstAddr(const short x_exp, const short y_exp) const;
00172                 inline TNum *           getCoeffAddr(const short x_exp, const short y_exp);
00178                 inline  short   getDegree() const;
00179                 
00180                 inline string   getName() const {       return name;    };
00181 
00183                 inline short    getMaxDegree() const;
00191                 inline void testBounds(const short x_exp, const short y_exp) const;
00196 
00197                 polynomXY& operator=(const polynomXY&);
00198                 bool operator==(const polynomXY&) const;
00200         //void update(std::string s);
00201         //void update(std::string s);
00202 
00205                 void OutputPureCoefficients( ostream &datei, int maxDegree, bool mitKomma) const;
00206                 void output( std::ostream& os) const;
00207                 void printInMacaulayStyle( std::ostream& os) const;
00208                 void outputMatrix() const;
00209                 void print( std::ostream& os) const;
00211         private:
00212                 inline int  getIndex(const short x_exp, const short y_exp) const;
00213 
00214 };
00215 
00216 
00217 
00218 
00219 
00229 template <class TNum>
00230 class polynomx
00231 {
00232         private:
00233                  int    maxDegree;
00234                  int    size;
00235                 TNum *          koeff; 
00236 
00237         protected:
00240                         inline void             testbounds(const int x_exp) const;
00242         public:
00243         
00244                 typedef TNum    CoefficientType;
00245 
00248                         polynomx(const int gr);
00249                         inline  polynomx(const polynomx & fpx);
00250 
00251                         virtual ~polynomx();
00252 
00255                         inline polynomx & operator=(const polynomx & fpx);
00256 
00257         
00260                         void    clear(int _degree);
00261                         void    clear();
00267                         inline TNum             getCoeff(const int x_exp)  const;
00268                 
00269                         inline  TNum&           getCoeffRef(const int x_exp) ;
00270 
00271                         inline  const TNum&     getCoeffConstRef(const int x_exp) const;
00272 
00273                         inline  TNum const      getCoeffConst(const int x_exp)  const;
00274                 
00275                         inline void             setCoeff(const int x_exp, const TNum& value);
00276         
00282                         inline const int        getDegree() const ;
00287 };
00288 
00289 
00290 
00291 template <typename TNum, typename TIndex>
00292 std::ostream &  operator<<(std::ostream & out, const polynomXY<TNum, TIndex>& z)  
00293 {       
00294         z.print(out);
00295         return out;
00296 }
00297 
00298 
00299 
00300 
00301 
00302 #include "polynom.cpp"
00303 
00304 #endif // ifndef POLYNOM_H4D45E74F99FC
Generated on Tue Nov 23 13:10:52 2010 for centerfocus by  doxygen 1.6.3