Loading...
Searching...
No Matches
PowerSeries.h
Go to the documentation of this file.
#ifndef POWER_SERIES_HEADER
#define POWER_SERIES_HEADER
#include "kernel/mod2.h"
#include "Poly.h"
template <class traits> class PowerSeriesInputIterator:
public std::
iterator<
std::input_iterator_tag,
typename traits::expansion_type,
int,
shared_ptr<const typename traits::expansion_type>,
const typename traits::expansion_type
>
{
private:
typedef typename traits::denominator_type denominator_type;
typedef typename traits::numerator_type numerator_type;
typedef typename traits::expansion_type expansion_type;
denominator_type denominator;
numerator_type numerator;
denominator_type toPot;
int state;
expansion_type data;
denominator_type lastPot;
public:
PowerSeriesInputIterator(numerator_type num_arg,
denominator_type den_arg):
data(den_arg.getRing()),
lastPot(den_arg.getRing()),
numerator(num_arg),
denominator(den_arg)
{
ring r=denominator.getRing();
//not the lead coef Number c=denominator.leadCoef();
Number c(1,r);
typename traits::denominator_type::iterator it=denominator.begin();
typename traits::denominator_type::iterator end=denominator.end();
while(it!=end)
{
if ((*it).isConstant())
{
//change this type
c=denominator_type(*it).leadCoef();
break;
}
++it;
}
c=Number(1,r)/c;
numerator*=c;
denominator*=c;
toPot=denominator+denominator_type(-1,r);
toPot*=Number(-1,r);
//change this type
lastPot=denominator_type(1,r);
data=numerator;
state=0;
}
PowerSeriesInputIterator()
{
state=-1;
}
void shorten()
{
typename expansion_type::iterator it=data.begin();
typename expansion_type::iterator end=data.end();
ring r=data.getRing();
expansion_type remove(r);
while(it!=end)
{
if(it->lmTotalDegree()<state)
{
remove+=expansion_type(*it);
}
it++;
}
remove*=Number(-1,r);
data+=remove;
}
expansion_type getValue()
{
typename expansion_type::iterator it=data.begin();
typename expansion_type::iterator end=data.end();
ring r=data.getRing();
expansion_type res(r);
while(it!=end)
{
if(it->lmTotalDegree()==state)
{
res+=expansion_type(*it);
}
it++;
}
return res;
}
PowerSeriesInputIterator& operator++()
{
state++;
shorten();
lastPot*=toPot;
data+=lastPot*numerator;
return *this;
}
//bad if this are iterators for different PowerSeries
bool operator==(const PowerSeriesInputIterator& t2)
{
return state==t2.state;
}
bool operator!=(const PowerSeriesInputIterator& t2)
{
return state!=t2.state;
}
PowerSeriesInputIterator operator++(int)
{
PowerSeriesInputIterator it(*this);
++(*this);
return it;
}
const expansion_type operator*()
{
return expansion_type(getValue());
}
shared_ptr<const expansion_type> operator->()
{
return shared_ptr<const expansion_type>(new expansion_type(getValue()));
}
};
template<class traits> class PowerSeriesBase
{
public:
typedef typename traits::denominator_type denominator_type;
typedef typename traits::numerator_type numerator_type;
protected:
denominator_type denominator;
numerator_type numerator;
public:
PowerSeriesBase(){}
PowerSeriesBase(const numerator_type &a, const denominator_type & b):numerator(a),denominator(b)
{
assume(a.getRing()==b.getRing());
//asume b!=NULL
}
typedef PowerSeriesInputIterator<traits> iterator;
iterator begin()
{
return iterator(numerator,denominator);
}
iterator end()
{
return iterator();
}
};
class PowerSeriesPolyTraits;
class PowerSeriesVectorTraits;
typedef PowerSeriesBase<PowerSeriesPolyTraits> PowerSeries;
typedef PowerSeriesBase<PowerSeriesVectorTraits> VectorPowerSeries;
class PowerSeriesPolyTraits
{
public:
typedef Poly numerator_type;
typedef Poly denominator_type;
typedef PowerSeries create_type;
typedef Poly expansion_type;
};
class PowerSeriesVectorTraits
{
public:
typedef Vector numerator_type;
typedef Poly denominator_type;
typedef VectorPowerSeries create_type;
typedef Vector expansion_type;
};
#endif
Poly.h
PowerSeries
PowerSeriesBase< PowerSeriesPolyTraits > PowerSeries
Definition PowerSeries.h:156
VectorPowerSeries
PowerSeriesBase< PowerSeriesVectorTraits > VectorPowerSeries
Definition PowerSeries.h:157
PowerSeriesPolyTraits::expansion_type
Poly expansion_type
Definition PowerSeries.h:164
PowerSeriesPolyTraits::denominator_type
Poly denominator_type
Definition PowerSeries.h:162
PowerSeriesVectorTraits::create_type
VectorPowerSeries create_type
Definition PowerSeries.h:171
PowerSeriesVectorTraits::numerator_type
Vector numerator_type
Definition PowerSeries.h:169
PowerSeriesVectorTraits::expansion_type
Vector expansion_type
Definition PowerSeries.h:172
PowerSeriesVectorTraits::denominator_type
Poly denominator_type
Definition PowerSeries.h:170
PowerSeriesPolyTraits::create_type
PowerSeries create_type
Definition PowerSeries.h:163
PowerSeriesPolyTraits::numerator_type
Poly numerator_type
Definition PowerSeries.h:161
PowerSeriesPolyTraits
Definition PowerSeries.h:159
PowerSeriesVectorTraits
Definition PowerSeries.h:167
b
CanonicalForm b
Definition cfModGcd.cc:4111
Number
Definition Number.h:34
PolyBase::getRing
ring getRing() const
Definition Poly.h:427
PowerSeriesBase
Definition PowerSeries.h:130
PowerSeriesBase< PowerSeriesPolyTraits >::denominator
denominator_type denominator
Definition PowerSeries.h:135
PowerSeriesBase::numerator_type
traits::numerator_type numerator_type
Definition PowerSeries.h:133
PowerSeriesBase::denominator_type
traits::denominator_type denominator_type
Definition PowerSeries.h:132
PowerSeriesBase::PowerSeriesBase
PowerSeriesBase()
Definition PowerSeries.h:138
PowerSeriesBase< PowerSeriesPolyTraits >::numerator
numerator_type numerator
Definition PowerSeries.h:136
PowerSeriesBase::begin
iterator begin()
Definition PowerSeries.h:145
PowerSeriesBase::iterator
PowerSeriesInputIterator< traits > iterator
Definition PowerSeries.h:144
PowerSeriesBase::PowerSeriesBase
PowerSeriesBase(const numerator_type &a, const denominator_type &b)
Definition PowerSeries.h:139
PowerSeriesBase::end
iterator end()
Definition PowerSeries.h:149
PowerSeriesInputIterator
Definition PowerSeries.h:14
PowerSeriesInputIterator::operator==
bool operator==(const PowerSeriesInputIterator &t2)
Definition PowerSeries.h:104
PowerSeriesInputIterator::PowerSeriesInputIterator
PowerSeriesInputIterator()
Definition PowerSeries.h:58
PowerSeriesInputIterator::operator*
const expansion_type operator*()
Definition PowerSeries.h:118
PowerSeriesInputIterator::getValue
expansion_type getValue()
Definition PowerSeries.h:79
PowerSeriesInputIterator::denominator_type
traits::denominator_type denominator_type
Definition PowerSeries.h:16
PowerSeriesInputIterator::PowerSeriesInputIterator
PowerSeriesInputIterator(numerator_type num_arg, denominator_type den_arg)
Definition PowerSeries.h:26
PowerSeriesInputIterator::expansion_type
traits::expansion_type expansion_type
Definition PowerSeries.h:18
PowerSeriesInputIterator::data
expansion_type data
Definition PowerSeries.h:23
PowerSeriesInputIterator::operator!=
bool operator!=(const PowerSeriesInputIterator &t2)
Definition PowerSeries.h:108
PowerSeriesInputIterator::numerator_type
traits::numerator_type numerator_type
Definition PowerSeries.h:17
PowerSeriesInputIterator::operator++
PowerSeriesInputIterator & operator++()
Definition PowerSeries.h:95
PowerSeriesInputIterator::lastPot
denominator_type lastPot
Definition PowerSeries.h:24
PowerSeriesInputIterator::numerator
numerator_type numerator
Definition PowerSeries.h:20
PowerSeriesInputIterator::operator++
PowerSeriesInputIterator operator++(int)
Definition PowerSeries.h:112
PowerSeriesInputIterator::toPot
denominator_type toPot
Definition PowerSeries.h:21
PowerSeriesInputIterator::state
int state
Definition PowerSeries.h:22
PowerSeriesInputIterator::operator->
shared_ptr< const expansion_type > operator->()
Definition PowerSeries.h:122
PowerSeriesInputIterator::shorten
void shorten()
Definition PowerSeries.h:62
PowerSeriesInputIterator::denominator
denominator_type denominator
Definition PowerSeries.h:19
Vector
Definition Poly.h:509
res
CanonicalForm res
Definition facAbsFact.cc:60
mod2.h
assume
#define assume(x)
Definition mod2.h:389
Poly
Definition janet.h:15