source: git/kernel/old.PowerSeries.h @ abe5c8

fieker-DuValspielwiese
Last change on this file since abe5c8 was 210e07, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
ADD: testing headers with "make test.o" FIX: cleaning up headers in kernel: TODO: kutil.h?! FIX: febase.h -> old.febase.h (remove later on) ADD: dummy headers instead of some splited or moved: febase.h, modulop.h (for later fixing) FIX: renamed various obsolette files into "old.*"
  • Property mode set to 100644
File size: 4.1 KB
Line 
1#ifndef POWER_SERIES_HEADER
2#define POWER_SERIES_HEADER
3#include <kernel/mod2.h>
4#include <kernel/Poly.h>
5template <class traits> class PowerSeriesInputIterator:
6public std::
7iterator<
8  std::input_iterator_tag,
9  typename traits::expansion_type,
10  int, 
11  shared_ptr<const typename traits::expansion_type>,
12  const typename traits::expansion_type
13  > {
14 private:
15  typedef typename traits::denominator_type denominator_type;
16  typedef typename traits::numerator_type numerator_type;
17  typedef typename traits::expansion_type expansion_type;
18  denominator_type denominator;
19  numerator_type numerator;
20  denominator_type toPot;
21  int state;
22  expansion_type data;
23  denominator_type lastPot;
24 public:
25  PowerSeriesInputIterator(numerator_type num_arg, 
26                           denominator_type den_arg):
27    data(den_arg.getRing()), 
28    lastPot(den_arg.getRing()),
29    numerator(num_arg),
30    denominator(den_arg){
31
32    ring r=denominator.getRing();
33
34    //not the lead coef    Number c=denominator.leadCoef();
35    Number c(1,r);
36    typename traits::denominator_type::iterator it=denominator.begin();
37    typename traits::denominator_type::iterator end=denominator.end();
38    while(it!=end){
39     
40      if ((*it).isConstant()){
41        //change this type
42        c=denominator_type(*it).leadCoef();
43       
44        break;
45      }
46     
47      ++it;
48     
49     
50 
51    }
52    c=Number(1,r)/c;
53    numerator*=c;
54    denominator*=c;
55    toPot=denominator+denominator_type(-1,r);
56   
57    toPot*=Number(-1,r);
58    //change this type
59    lastPot=denominator_type(1,r);
60    data=numerator;
61    state=0;
62   
63  }
64  PowerSeriesInputIterator(){
65    state=-1;
66  }
67  void shorten(){
68    typename expansion_type::iterator it=data.begin();
69    typename expansion_type::iterator end=data.end();
70    ring r=data.getRing();
71    expansion_type remove(r);
72    while(it!=end){
73      if(it->lmTotalDegree()<state){
74        remove+=expansion_type(*it);
75      }
76      it++;
77    }
78    remove*=Number(-1,r);
79    data+=remove;
80  }
81  expansion_type getValue(){
82    typename expansion_type::iterator it=data.begin();
83    typename expansion_type::iterator end=data.end();
84    ring r=data.getRing();
85    expansion_type res(r);
86    while(it!=end){
87      if(it->lmTotalDegree()==state)
88        {
89          res+=expansion_type(*it);
90        }
91      it++;
92    }
93    return res;
94  }
95  PowerSeriesInputIterator& operator++(){
96    state++;
97    shorten();
98    lastPot*=toPot;
99   
100    data+=lastPot*numerator;
101   
102 
103    return *this;
104   
105  }
106  //bad if this are iterators for different PowerSeries
107  bool operator==(const PowerSeriesInputIterator& t2){
108    return state==t2.state;
109  }
110  bool operator!=(const PowerSeriesInputIterator& t2){
111    return state!=t2.state;
112  }
113
114
115
116  PowerSeriesInputIterator operator++(int){
117    PowerSeriesInputIterator it(*this);
118    ++(*this);
119    return it;
120  }
121  const expansion_type operator*(){
122    return expansion_type(getValue());
123  }
124  shared_ptr<const expansion_type> operator->(){
125    return shared_ptr<const expansion_type>(new expansion_type(getValue()));
126  }
127  };
128
129
130template<class traits> class PowerSeriesBase{
131 public:
132  typedef typename traits::denominator_type denominator_type;
133  typedef typename traits::numerator_type numerator_type;
134 protected:
135  denominator_type denominator;
136  numerator_type numerator;
137 public:
138 
139  PowerSeriesBase(){
140  }
141  PowerSeriesBase(const numerator_type &a, const denominator_type & b):numerator(a),denominator(b){
142    assume(a.getRing()==b.getRing());
143    //asume b!=NULL
144  }
145  typedef PowerSeriesInputIterator<traits> iterator;
146  iterator begin(){
147    return iterator(numerator,denominator);
148  }
149  iterator end(){
150    return iterator();
151  }
152 
153
154};
155class PowerSeriesPolyTraits;
156class PowerSeriesVectorTraits;
157typedef PowerSeriesBase<PowerSeriesPolyTraits> PowerSeries;
158typedef PowerSeriesBase<PowerSeriesVectorTraits> VectorPowerSeries;
159class PowerSeriesPolyTraits{
160 public:
161  typedef Poly numerator_type;
162  typedef Poly denominator_type;
163  typedef PowerSeries create_type;
164  typedef Poly expansion_type;
165};
166class PowerSeriesVectorTraits{
167 public:
168  typedef Vector numerator_type;
169  typedef Poly denominator_type;
170  typedef VectorPowerSeries create_type;
171  typedef Vector expansion_type;
172};
173
174
175#endif
Note: See TracBrowser for help on using the repository browser.