%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  
%%  power_seriess.tex       LiDIA documentation
%%  
%%  This file contains the documentation of the classes
%%  sparse\_power\_seriess<T> and dense\_power\_seriess<T>
%%
%%  Copyright   (c)   1995   by  LiDIA-Group  
%%      
%%  Authors: Frank Lehmann, Markus Maurer
%%

\begin{lidia_man}
\markright{\BF{dense\_power\_series}, sparse\_power\_series}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NAME
\BF{dense\_power\_series\TEMPL{T}, sparse\_power\_series\TEMPL{T}} \DOTFILL
an arithmetic for approximations of power seriess

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ABSTRACT
\BF{dense\_power\_series\TEMPL{T}} and \BF{sparse\_power\_series\TEMPL{T}} are C++
template classes which represent seriess of the form
\begin{center}
\SUM{i=n}{\INFTY}{\MATH{a_{i}} \CDOT \MATH{X^{i}} }, \MATH{ } \MATH{a_{n} \NEQ 0},
\MATH{ } \MATH{a_{i} = 0}, \MATH{ } \MATH{i < n}, \MATH{ } \MATH{n \IN \Z}
\end{center}
by approximations
\begin{center}
\SUM{i=n}{M}{\MATH{a_{i}} \CDOT \MATH{X^{i}} }, \MATH{ } \MATH{a_{n}\NEQ 0}, 
\MATH{ } \MATH{M \IN \Z_{\GE n}}
\end{center}
where the coefficients \MATH{a_{i}} are elements of type \BF{T} and the indices \MATH{i}
of type \BF{lidia\_size\_t}.
The difference between \BF{dense\_power\_series\TEMPL{T}} and \BF{sparse\_power\_series\TEMPL{T}}
is that in the dense representation all coefficients \MATH{a_{i}, n \LE i \LE M}, are stored,
whereas in the sparse representation only the non-zero ones together with their
corresponding exponents are kept.
The two classes provide basic operations on power seriess like
comparisons, addition, multiplication etc.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DESCRIPTION
An approximation of a power series
\begin{center}
\SUM{i=n}{M}{\MATH{a_{i}} \CDOT \MATH{X^{i}} }, \MATH{a_{n}\NEQ 0}, \MATH{M \IN \Z_{\GE n}}
\end{center}
can be represented in two different ways. A \BF{dense\_power\_series\TEMPL{T}} stores
the exponent n and the vector of the coefficients, e.g.
\begin{center}
\MATH{(n, a_{n},\LDOTS,a_{M})}.
\end{center}
A \BF{sparse\_power\_series\TEMPL{T}} only holds the non-zero coefficients together
with their corresponding exponents, e.g.
\begin{center}
\MATH{ ( (a_{i_{1}},i_{1}), \LDOTS (a_{i_{k}},i_{k}) ) }, \MATH{a_{i_{j}} \NEQ 0},
\MATH{n \LE i_{j} \LE M}.
\end{center}
The exponent \MATH{n} is called the first exponent of the approximation,
because it is the smallest exponent which belongs to a non-zero coefficient.
Similarly, we call \MATH{M} the last exponent of the approximation,
because it is the largest exponent of the series which the corresponding coefficient is
known of. If all coefficients of an approximation are zero, so that there is no
element \MATH{a_{n} \NEQ 0}, we can imagine this zero-approximation to be represented as
\begin{center}
\MATH{ a_{M} \CDOT X^{M}}, \MATH{a_{M} = 0}
\end{center}
and we set the first and last exponent to M.

The coefficients \MATH{a_{i}} are type \BF{T} elements, where \BF{T} must be a C++ - class
which provides the following operators, member and friend functions


\fcode{istream}{operator\TT{>>}}{istream\k T}{}
\fcode{ostream}{operator\TT{<<}}{ostream\k T}{}
\fcode{bool}{operator\TT{==}}{T \k T}{}
\fcode{bool}{operator\TT{!=}}{T \k T}{}

\cfcode{bool}{a.is\_zero}{}
{
returns \TRUE\ if \MATH{\TT{a} = 0}, \FALSE\ otherwise.}

\cfcode{bool}{a.is\_one}{}
{
returns \TRUE\ if \MATH{\TT{a} = 1}, \FALSE\ otherwise.}

\fcode{void}{a.assign\_zero}{}
{
\MATH{\TT{a} = 0}.}

\fcode{void}{a.assign\_one}{}
{
\MATH{\TT{a} = 1}.}


\fcode{void}{add}{T \& c, T \& a, T \& b}
{
\TT{c = a + b.}}

\fcode{void}{subtract}{T \& c, T \& a, T \& b}
{
\TT{c = a - b.}}

\fcode{void}{multiply}{T \& c, T \& a, T \& b}
{
\TT{c = a * b.}}

\fcode{void}{invert}{T \& c, T \& a}
{
\TT{c = 1 / a.}}

In the following description of operators, member and friend functions
we will use the type psr as an abbreviation which can be substituted by
\BF{sparse\_power\_series\TEMPL{T}} or \BF{dense\_power\_series\TEMPL{T}}, respectively,
because nearly all functions are defined for both, sparse and
dense representation. 

Furthermore, for an approximation \MATH{a} of a series, we denote the first
and last exponent of \MATH{a} (as defined above) by \BF{\MATH{f(a)}} and
\BF{\MATH{l(a)}}, respectively. By \MATH{a_{i}} we denote that coefficient
of \MATH{a} which belongs to the exponent \MATH{i \IN \Z}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\CONS
\fcode{ct}{psr}{}
{
sets the series to an uninitialized state; the first and last
		exponent are undefined. Any function call, beside setting
		coefficients, the series is involved in causes a call
		of the \TT{lidia\_error\_handler}.}


\fcode{ct}{psr}{const T \& z \k lidia\_size\_t l}
{
initializes the series with \MATH{ z \CDOT X^{0} + \SUM{i=1}{l}{0 \CDOT X^{i}} }\\
			\MATH{f(this) = 0}, if \MATH{z \NEQ 0}, \MATH{l} otherwise 
			\MATH{l(this) = l}}


\fcode{ct}{psr}{const base\_vector\TEMPL{T} \& v \k lidia\_size\_t f}
{
initializes the series with \MATH{ \SUM{i=f}{f+v.size()-1}{v[i-f] \CDOT X^{i}} }\\
			\MATH{ f \LE f(this) \LE l(this)} \\
			\MATH{ l(this) = f + v.size() - 1}}


\fcode{ct}{psr}{const psr\TEMPL{T} \& c}
{
initializes the series with \MATH{c}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ASGN
The operator\TT{=} is overloaded. More precisely, the following assignments are
possible:


\fcode{const dense\_power\_series  \&}{operator\TT{=}}{const dense\_power\_series\TEMPL{T}  \&}{}
\fcode{const dense\_power\_series  \&}{operator\TT{=}}{const sparse\_power\_series\TEMPL{T} \&}{}
\fcode{const sparse\_power\_series \&}{operator\TT{=}}{const sparse\_power\_series\TEMPL{T} \&}{}
\fcode{const sparse\_power\_series \&}{operator\TT{=}}{const dense\_power\_series\TEMPL{T}  \&}{}

\fcode{void}{a.assign\_zero}{lidia\_size\_t l}
{
\MATH{a = 0 \CDOT X^{l} } \\
		\MATH{f(c) = l} \\
		\MATH{l(c) = l}}


\fcode{void}{a.assign\_one}{lidia\_size\_t l}
{
\MATH{a = 1 \CDOT X^{0} + \SUM{i=1}{l}{0 \CDOT X^{i}} } \\
		\MATH{f(a) = 0} \\
		\MATH{l(a) = l} \\
		If \MATH{l} is less than zero the \TT{lidia\_error\_handler} will be invoked.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ARTH
The operators \TT{+}, \TT{+=}, \TT{-}, \TT{-=}, \TT{*}, \TT{*=}, \TT{/}, and \TT{/=}
are overloaded.

To avoid copying, these operations can also be performed by
the following functions, where the output may always alias the input:


\fcode{void}{add}{psr \& c\k const psr \& a\k const psr \& b}
{
\MATH{c = a + b} \\ 
		\MATH{l(c) = min(l(a),l(b))} \\
		\MATH{min(f(a),f(b)) \LE f(c) \LE l(c)}}


\fcode{void}{add}{psr \& c\k const psr \& a\k const T \& b}
{
\MATH{c = a + \LEFT( b \CDOT X^{0} + \SUM {i=1} {l(a)} {0 \CDOT X^{i}} \RIGHT) } \\
		\MATH{l(c) = l(a)} \\
		\MATH{f(a) \LE f(c) \LE l(c)}}


\fcode{void}{add}{psr \& c\k const T \& a\k const psr \& b}
{
\MATH{c = \LEFT( a \CDOT X^{0} + \SUM {i=1} {l(b)} {0 \CDOT X^{i}} \RIGHT) + b } \\
		\MATH{l(c) = l(b)} \\
		\MATH{f(b) \LE f(c) \LE l(c)}}



\fcode{void}{subtract}{psr \& c\k const psr \& a\k const psr \& b}
{
\MATH{c = a - b} \\
		\MATH{l(c) = min(l(a),l(b))} \\
		\MATH{min(f(a),f(b)) \LE f(c) \LE l(c)}}


\fcode{void}{subtract}{psr \& c\k const psr \& a\k const T \& b}
{
\MATH{c = a - \LEFT( b \CDOT X^{0} + \SUM {i=1} {l(a)} {0 \CDOT X^{i}} \RIGHT) } \\
		\MATH{l(c) = l(a)} \\
		\MATH{f(a) \LE f(c) \LE l(c)}}


\fcode{void}{subtract}{psr \& c\k const T \& a\k const psr \& b}
{
\MATH{c = \LEFT( a \CDOT X^{0} + \SUM {i=1} {l(b)} {0 \CDOT X^{i}} \RIGHT) - b } \\
		\MATH{l(c) = l(b)} \\
		\MATH{f(b) \LE f(c) \LE l(c)}}



\fcode{void}{multiply}{psr \& c\k const psr \& a\k const psr \& b}
{
\MATH{c = a * b} \\
		\MATH{f(c) = f(a) + f(b)} \\
		\MATH{l(c) = f(c) + min(l(a)-f(a),l(b)-f(b))} \\
		If \MATH{a} and \MATH{b} refer to the same object the \TT{square(c,a)}-function is called
		in the case of \BF{dense\_power\_series\TEMPL{T}}.}


\fcode{void}{multiply}{psr \& c\k const psr \& a\k const T \& b}
{
\MATH{c = \SUM{i=f(a)} {l(a)} {\LEFT( a_{i} \CDOT b \RIGHT) \CDOT X^{i}} } \\
		\MATH{f(c) = f(a)} if \MATH{b \NEQ 0} \k otherwise \MATH{f(c) = l(c)} \\
		\MATH{l(c) = l(a)}}


\fcode{void}{multiply}{psr \& c\k const T \& a\k const psr \& b}
{
\MATH{c = \SUM{i=f(b)} {l(b)} {\LEFT( a \CDOT b_{i} \RIGHT) \CDOT X^{i}} } \\
		\MATH{f(c) = f(b)} if \MATH{a \NEQ 0} \k otherwise \MATH{f(c) = l(c)} \\
		\MATH{l(c) = l(b)}}



\fcode{void}{invert}{psr \& c\k const psr \& a}
{
\MATH{c = 1/a} \\
		\MATH{f(c) = - f(a)} \\
		\MATH{l(c) = - 2 \CDOT f(a) + l(a)} \\
		If \TT{a} is not invertible, the \TT{lidia\_error\_handler} will be invoked.}



\fcode{void}{divide}{psr \& c\k const psr \& a\k const psr \& b}
{
\MATH{c = a / b} \\
		\MATH{f(c) = f(a) - f(b)} \\
		\MATH{l(c) = f(c) + min(l(a)-f(a),l(b)-f(b))} \\
		If \TT{b} is not invertible, the \TT{lidia\_error\_handler} will be invoked.}


\fcode{void}{divide}{psr \& c\k const psr \& a\k const T \& b}
{
\MATH{c = \SUM{i=f(a)} {l(a)} {\LEFT( a_{i} \CDOT (1/b) \RIGHT) \CDOT X^{i}} } \\
		\MATH{f(c) = f(a)} \\
		\MATH{l(c) = l(a)}}


\fcode{void}{divide}{psr \& c\k const T \& a\k const psr \& b}
{
\MATH{c = \SUM{i=f(d)} {l(d)} {\LEFT( a \CDOT d_{i} \RIGHT) \CDOT X^{i}} } where \MATH{d = 1/b }\\
		\MATH{f(c) = - f(b)} if \MATH{a \NEQ 0} \k otherwise \MATH{f(c) = l(c)} \\
		\MATH{l(c) = - 2 \CDOT f(b) + l(b)} \\
		If \TT{b} is not invertible, the \TT{lidia\_error\_handler} will be invoked.}



\fcode{void}{square}{psr \& c\k const psr \& a}
{
\MATH{c = a^{2}} \\
		\MATH{f(c) = 2 \CDOT f(a)} \\
		\MATH{l(c) = f(a) + l(a)} \\
		At the moment, we use algorithms with quadratic running time to compute the
		product of two seriess. Therefore squaring is twice as fast as multiplying
		in the case of \BF{dense\_power\_series\TEMPL{T}}.}


\fcode{void}{power}{psr \& c\k const psr \& a \k long n}
{
\MATH{c = a^{n} } \\
		If \MATH{n = 0} and \MATH{a} is a zero-approximation then 
			\MATH{c = 1 \CDOT X^{0}}, \MATH{l(c) = 0}; \\
		if \MATH{n = 0} and \MATH{a} is not a zero-approximation then
			\MATH{c = 1 + \SUM {i=1} {l(a)-f(a)} {0 \CDOT X^{i}} }; \\ 
		if \MATH{n \NEQ 0} and \MATH{a} is a zero-approximation then 
			\MATH{c = 0 \CDOT X^{n \CDOT l(a)}}, \MATH{f(c) = l(c) = n \CDOT l(a)}; \\
		otherwise \MATH{f(c) = n \CDOT f(a)} and \MATH{l(c) = (n-1) \CDOT f(a) + l(a)}.}


Let \MATH{a} be of type \BF{psr}.


\fcode{void}{a.multiply\_by\_xn}{lidia\_size\_t n}
{
\MATH{a = \SUM {i=f(a)} {l(a)} {a_{i} \CDOT X^{i+n}} } \\
		\MATH{f(a) = f(a) + n} \\
		\MATH{l(a) = l(a) + n}}


\fcode{void}{a.compose}{lidia\_size\_t n}
{
\MATH{a = \SUM {i=f(a)} {l(a)} {a_{i} \CDOT \LEFT(X^{n}\RIGHT)^{i}} } \\
		\MATH{f(a) = f(a) * n} \\
		\MATH{l(a) = l(a) * n}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\COMP
The  binary operators \TT{==} and \TT{!=} are overloaded.
Let \MATH{a} be of type \BF{psr}.


\cfcode{bool}{a.is\_zero}{}
{
returns \TRUE\ if \MATH{a = 0 \CDOT X^{l}, l \IN \Z}, \FALSE\ otherwise.}


\cfcode{bool}{a.is\_one}{}
{
returns \TRUE\ if \MATH{a = 1 + \SUM{i=1} {l} {0 \CDOT X^{i}}, l \IN \Z_{>0}}, \FALSE\ otherwise.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\BASIC
Let \MATH{a} be of type \BF{psr}.


\cfcode{lidia\_size\_t}{a.get\_first}{}
{
returns the first exponent of \MATH{a}.}


\cfcode{lidia\_size\_t}{a.get\_last}{}
{
returns the last exponent of \MATH{a}.}



\fcode{void}{a.set\_coeff}{const T \& z, lidia\_size\_t e}
{
sets the coefficient with exponent \MATH{e} to \MATH{z}.
		If \MATH{e} is less than \MATH{f(a)} all coefficients
		with exponent \MATH{i}, \MATH{e \LT i \LT f(a)}, are set to zero
		just as all coeffients with exponent \MATH{i}, \MATH{l(a) \LT i \LT e},
		in the case that \MATH{e} is greater than \MATH{l(a)}.}


\fcode{void}{a.set}{const psr \& b}
{
\MATH{a = b.}}


\fcode{void}{a.set}{const T \& z, lidia\_size\_t l}
{
\MATH{ a = z \CDOT X^{0} + \SUM {i=1} {l} {0 \CDOT X^{i}.} }
		If \MATH{l} is less than zero, \MATH{a} is set to
		\MATH{0 \CDOT X^{l}}.}



\fcode{void}{a.get\_coeff}{T \& z, lidia\_size\_t e}
{
assigns \MATH{a_{e}} to \MATH{z}.
		If \MATH{e} is greater than \MATH{l(a)} the \TT{lidia\_error\_handler} 
		will be invoked.}


\fcode{T}{a.operator[]}{lidia\_size\_t e}
{
returns a copy of \MATH{a_{e}}.
		If \MATH{e} is greater than \MATH{l(a)} the \TT{lidia\_error\_handler} 
		will be invoked.}



\fcode{void}{a.clear}{}
{
deletes all coefficients in \MATH{a} and resets \MATH{a} to
		an uninitialized state in the same way the default constructor
		does.}

\fcode{void}{a.reduce\_last}{lidia\_size\_t l}
{
If \TT{a} is of the form \MATH{a = \SUM {i=f(a)} {l(a)} {a_{i} \CDOT X^{i}}}
		before the call of this function, it will be set to
		\MATH{a = \SUM {i=f(a)} {l} {a_{i} \CDOT X^{i}}}, where the coefficients
		with exponents between \MATH{l+1} and \MATH{l(a)} are cut off and \MATH{l(a)}
		will be decreased to \MATH{l}.
		If \MATH{l} is greater than \MATH{l(a)} the \TT{lidia\_error\_handler}
		will be invoked. The memory reserved for the invalid coefficients, i.e.
	 	those coefficients that have been cut off before, is not deallocated,
		but these coefficients are not accessible anymore.}


\fcode{void}{a.normalize}{}
{
deallocates memory which is occupied by invalid coefficients. This
		function is useful after several calls of \TT{a.reduce\_last()}
}


\fcode{void}{swap}{psr \& a\k psr \& b}
{
exchanges the approximations of \MATH{a} and \MATH{b}.}



Let \MATH{a} be of type \BF{sparse\_power\_series\TEMPL{T}}.


\fcode{void}{a.set}{const base\_vector\TEMPL{T} \& v, const base\_vector\MATH{<}lidia\_size\_t\MATH{>} \& e, lidia\_size\_t l}
{
builds the power\_series \MATH{a} using the coefficient vector \MATH{v} and the
exponent vector \MATH{e}. The coefficient \MATH{v[i]} obtains the exponent
\MATH{e[i]} for \MATH{0 \LE i < \TT{v.size()}}. Furthermore, the last exponent of \MATH{a}
is set to \MATH{l} and \MATH{l} must be greater than or equal to the maximum of the exponents \MATH{e[i]}.}



\fcode{void}{a.set}{const T* v, const lidia\_size\_t* e, lidia\_size\_t sz, lidia\_size\_t l}
{
builds the power\_series \MATH{a} using the coefficient vector \MATH{v} and the
exponent vector \MATH{e}. The coefficient \MATH{v[i]} obtains the exponent
\MATH{e[i]} for \MATH{ 0 \LE i < sz}. Furthermore, the last exponent of \MATH{a}
is set to \MATH{l} and \MATH{l} must be greater than or equal to the maximum of the exponents \MATH{e[i]}.}


\fcode{void}{a.get}{base\_vector\TEMPL{T} \& v, base\_vector\MATH{<}lidia\_size\_t\MATH{>} \& e}
{
assigns the non-zero coefficients of \MATH{a} to \MATH{v} and stores the corresponding
exponents in \MATH{e}, i.e. \MATH{e[i]} holds the exponent of \MATH{v[i]} and the exponents
are in increasing order. The capacity and the sizes of \MATH{v} and \MATH{e} are set to the
number of non-zero elements of \MATH{a}.
In the special case that \MATH{a} is a zero-approximation, the
sizes and capacities of \MATH{v} and \MATH{e} are set to one,
\MATH{v[0]} is set to zero and \MATH{e[0]} to \MATH{l(a)}.}

\fcode{void}{a.get}{T* \& v, lidia\_size\_t* \& e, lidia\_size\_t \& sz}
{
assigns the non-zero coefficients of \MATH{a} to \MATH{v} and stores the corresponding
exponents in \MATH{e}, i.e. \MATH{e[i]} holds the exponent of \MATH{v[i]} and the exponents
are in increasing order. The variable \MATH{sz} holds the size of \MATH{v} and \MATH{e} which is the
number of elements of \MATH{v}.
Especially, if \MATH{a} is a zero-approximation, the
sizes of \MATH{v} and \MATH{e} are set to one, 
\MATH{v[0]} is set to zero and \MATH{e[0]} to \MATH{l(a)}.}



Let \MATH{a} be of type \BF{dense\_power\_series\TEMPL{T}}.


\fcode{void}{a.set}{const base\_vector\TEMPL{T} \& v, lidia\_size\_t f}
{
\MATH{ a = \SUM{i=f}{f+\TT{v.size()}-1}{v[i-f] \CDOT X^{i}.} }}


\fcode{void}{a.set}{const T* v, lidia\_size\_t sz, lidia\_size\_t f}
{
\MATH{ a = \SUM{i=f}{f+sz-1}{v[i-f] \CDOT X^{i}.} }}


\fcode{void}{a.get}{base\_vector\TEMPL{T} \& v}
{
\MATH{v[i-f(a)] = a_{i}}, \MATH{f(a) \LE i \LE l(a)} \\
\MATH{\TT{v.capacity()} = \TT{v.size()} = l(a)-f(a)+1} \\
Especially, if \MATH{a} is a zero-approximation, the
size and capacity of \MATH{v} are set to one and 
\MATH{v[0]} is set to zero.}

\fcode{void}{a.get}{T* \& v, lidia\_size\_t \& sz}
{
sets \MATH{sz = l(a) - f(a) + 1}, allocates \MATH{sz}
coefficients for \MATH{v}, and sets \\
\MATH{v[i-f(a)] = a_{i}}, \MATH{f(a) \LE i \LE l(a)}.
Especially, if \MATH{a} are a zero-approximation, \MATH{v} only
holds one zero-element.}


For efficiency reasons, the class \BF{dense\_power\_series\TEMPL{T}} puts at disposal
the following operator :


\fcode{T \&}{a.operator()}{lidia\_size\_t e}
{
returns a reference to the coefficient with exponent \MATH{e}.

This operator allows the setting of coefficients without initializing
a temporary variable, \MATH{x}, as it is necessary if the member function 
\TT{a.set\_coeff(T \& x ,lidia\_size\_t)} is used. Furthermore, it is possible to read coefficients
without copying, as it is necessary when using the operator \TT{T a.operator[](lidia\_size\_t)}.

But the \TT{operator()} always assumes that the user intends to set 
the returned coefficient. Therefore, whenever \MATH{e} is less than \MATH{f(a)},
memory for the coefficients with exponent \MATH{i}, \MATH{e \LE i \LT f(a)},
is allocated just as for the coefficients with exponent \MATH{i},
\MATH{l(a) \LT i \LE e}, in the case that \MATH{e} is greater than \MATH{l(a)}.
These coefficients are initialized with zero.

\ATTENTION

If the operator is used for reading cofficients and, by mistake, the exponent 
\MATH{e} is greater than \MATH{l(a)}, this operation may cause an incorrect approximation,
because it sets the last exponent to \MATH{e} and the coefficients in between
to zero.

Furthermore, zero coefficients whose exponents are less than the first exponent
of an approximation should not be set using this operator, because then these
coefficients are explicitly stored. The class \BF{dense\_power\_series\TEMPL{T}}
is able to handle leading zeros, but the running time of arithmetical operations
increases.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\IO
The \BF{istream}  operator  \TT{>>}  and  the \BF{ostream}  operator \TT{<<} are
overloaded.

The input and output format of type \BF{dense\_power\_series\TEMPL{T}}
is of the form
\begin{center}
\MATH{[ f \; [ a_{f} \LDOTS a_{l}] ] }
\end{center}
and symbolizes the approximation
\begin{center}
\SUM {i=f} {l} {a_{i} \CDOT X^{i}}.
\end{center}
The operator\TT{>>} can handle leading zeros, i.e. \MATH{a_{f} = 0}.

The input and output format of type \BF{sparse\_power\_series\TEMPL{T}}
is of the form
\begin{center}
\MATH{[ [ (b_{i_{1}},i_{1}), \LDOTS, (b_{i_{k}},i_{k}) ] \; l ] }
\end{center}
and symbolizes the approximation
\begin{center}
\SUM { i=min(i_{1},\LDOTS,i_{k}) } {l} {a_{i} \CDOT X^{i}},
with \MATH{a_{i} = b_{i}} if \MATH{ i \IN \{i_{1}, \LDOTS, i_{k}\} }, \MATH{0} otherwise.
\end{center}
The operator\TT{>>} can handle zero coefficients, i.e. \MATH{b_{i} = 0}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NOTES
The two data structures \BF{dense\_power\_series\TEMPL{T}}
and \BF{sparse\_power\_series\TEMPL{T}} use the LiDIA class 
\BF{base\_vector\TEMPL{T}} to store the coefficients of a series.
Therefore, the number of necessary memory allocations when initializing
a series by setting coefficients, i.e. using the member function
\TT{set\_coeff()} or the \TT{operator()}, depends on the order in which the coefficients
are set. To minimize the running time of this process, setting of coefficients
should be done in the following way :

\BF{dense\_power\_series\TEMPL{T}}
\begin{enumerate}
\item Set the coefficient that belongs to the first exponent.
\item Set the coefficient that belongs to the last exponent.
\item Set the remaining non-zero coefficients.
\end{enumerate}

\BF{sparse\_power\_series\TEMPL{T}}
\begin{enumerate}
\item Set the coefficient that belongs to the first exponent.
\item Set the non-zero coefficient with the largest exponent.
\item Set the remaining non-zero coefficients and if the coefficient
which corresponds to the last exponent is zero, set this
coefficient too.
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\EXAMPLES
    \begin{verbatim}
        #include <LiDIA/dense_power_series.h>

        main()
         {
             dense_power_series<bigint> a, b, c;

             cout << "Please enter a : "; cin >> a ; 
             cout << "Please enter b : "; cin >> b ;
             cout << "\n";

             c = a + b;

             cout << "a + b = " << c << "\n";
         }

\end{verbatim}

For further examples please refer to \\
\TT{LiDIA/src/templates/\{dense\_power\_series\_appl.c,sparse\_power\_series\_appl.c\}}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\AUTHOR
Frank Lehmann, Markus Maurer

\end{lidia_man}

