%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%  crt.tex       LiDIA documentation
%%
%%  This file contains the documentation of the classes crt_table and crt
%%
%%  Copyright   (c)   1995   by  LiDIA-Group
%%
%%  Authors: Frank J. Lehmann
%%

\begin{lidia_man}
\markright{\BF{crt\_table, crt}}

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

\NAME
\BF{crt\_table, crt} \DOTFILL Chinese Remainder Theorem

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

\ABSTRACT
\BF{crt\_table} and \BF{crt} are classes that allow explicit use of
the Chinese Remainder Theorem.

A common method in computer algebra is to replace a multi--precision
computation by several single--precision computations and one application
of the Chinese Remainder Theorem. This is applicable for both, rational
and modular integers.  Thus classes \BF{crt\_table} and \BF{crt} provide interfaces
to type \BF{bigint} and \BF{bigmod} and to different objects over these
types; i.e. single objects, pointer--arrays, base\_vectors and
base\_matrices.

The class \BF{crt\_table} provides internally stored tables which can be accessed
by the class \BF{crt}.
The class \BF{crt} can be seen as a black box that can reduce numbers
(represented as \BF{bigint} or \BF{bigmod})  modulo single--precision prime
numbers, as well as combine the modular results to the final result of type 
\BF{bigint} or \BF{bigmod}.

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

\DESCRIPTION
The Chinese Remainder Theorem says, that given \MATH{n} moduli \MATH{m_i}
(\MATH{1 \LE i \LE n}) of pairwise coprime integers and a
set of congruential equations
\MATH{x \EQUIV c_i \; (\mbox{mod} \; m_i) \;  (1 \LE i \LE n)}
for an arbitrary integer \MATH{x},
there is a unique solution \MATH{c} for \MATH{x} modulo the product
\MATH{M = \prod_{i=1}^n m_i};
say \MATH{x \EQUIV c \; (\mbox{mod} \; M)}.

Let us assume in this situation that we know an upper bound for the
absolute value of \MATH{x}; \MATH{|x| \LE B}. Furthermore the number \MATH{n}
of  moduli shall be chosen in a way that \MATH{B < \FRAC{M}{2}}.
If we then represent \MATH{c} by its absolutely least residue modulo \MATH{M},
we know that \MATH{c} and \MATH{x} coincide. Thus \MATH{x} is uniquely
determined by the above congruential equations.

If we consider \MATH{x} to be the result of some algorithm,
this implies an alternative  strategy for computations with multi--precision integers.
If we want to compute some results over the integers, and if we know an
upper bound on their absolute values, we can choose an appropriate number of
single--precision (pairwise coprime) moduli and perform the algorithm
modulo each of them while using a suitable single--precision modular
arithmetic. As a result of that we will obtain a set of congruential
equations that we can use as an input to the Chinese Remainder Theorem.
Its application will provide the correct multi--precision result
of the computation.

Not only is this method suitable for rational integers, we can also easily
extend it componentwise to vectors or matrices with integer entries.
We then have to find an upper bound on \EM{all\/} the coefficients of the
respective object.

Moreover, this strategy is also applicable for multi--precision modular
arithmetic. Here, we consider the residues as integers, compute the
result of the problem over \MATH{\Z} and accomplish by using some
reduction--steps to compute residues again.

The classes \BF{crt\_table} and \BF{crt} allow finding the solution of one
application of the Chinese Remainder Theorem by successively presenting the
residues \MATH{c_i} (in the notation above) to an object of type \BF{crt}.
The moduli \MATH{m_i} are prime numbers provided by the two classes.
They can be generated automatically by initializing a \BF{crt\_table} object
with the upper bound \MATH{B} on the absolute values of the results.
The system then chooses primes, until the product \MATH{M} of all of them exceeds
\MATH{2 \CDOT B}. Another possibiltiy is to  explicitely  store 
a vector of prime numbers into a \BF{crt\_table} object. If the product
of these primes is \MATH{M}, this object can be used to compute integers
of absolute value \MATH{\FRAC{M}{2}} at most.

To allow prime numbers of arbitrary shape to be generated, the internal
prime number generator may be replaced by a corresponding user--defined function.

A standard application for these classes looks as follows:

\begin{enumerate}

\item Determine an upper bound \MATH{B} for the absolute values of the numbers
that result from your algorithm. For computations of type
\BF{bigmod} consider the residues as rational integers.

\item Create an object \MATH{T} of type \BF{crt\_table} and initialize it with
bound \MATH{B} and when computing with  \BF{bigmod} also with the
corresponding modulus (by using a constructor or \TT{init()} member function
of class \BF{crt\_table}). Then \MATH{T} contains a list of prime numbers
you have to use for modular computations.

\item Create an object \MATH{C} of type \BF{crt} and initialize it with
the previously generated object \MATH{T}, thus providing \MATH{C}
with all the internal data of \MATH{T} (by using a constructor or 
\TT{init()} member function of class \BF{crt}). 

\item Perform the computation modulo any prime contained in the
internal list of \MATH{T} (see member function \TT{get\_prime()})
and store the respective results in \MATH{C}
(by using a suitable \TT{combine()} member function).

\item Read the final results out of \MATH{C} (by using a suitable \TT{get\_result()}
member function).

\end{enumerate}


Thus, this method does \BF{not} require to store each residue modulo
every prime before an application of the Chinese Remainder Theorem.

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

\STITLE{Class crt\_table}
An instance of type \BF{crt\_table} can be initialized by either a constructor
or by a suitable \TT{init()} member function. These functions require
an upper bound \MATH{B} for the absolute values of the results of your computation.
When computing with type \BF{bigmod} the residues are considered as rational integers,
and the global modulus must then be given to each initialization as parameter \MATH{P}.
Using a modulus when initializing an instance sets its mode to
\BF{MODULAR}; otherwise, the mode will be set to \BF{INTEGER}. The mode
of an instance defines whether a \BF{crt} object by which it is used,
provides interfaces to \BF{bigint} (\BF{INTEGER}) or to \BF{bigmod} (\BF{MODULAR}) only.

Any object of class  \BF{crt\_table} contains a reference counter
to control whether or not it is used by a \BF{crt} object. 
One may initialize (or clear) an instance only if this counter is zero.

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

\CONS
\fcode{ct}{crt\_table}{}
{
creates an empty instance, no tables are initialized.}


\fcode{ct}{crt\_table}{const bigint \& B}
{
generates primes, beginning with initial seed \MATH{2^{31}-1} to the
internal prime number generator. When using
the default prime generator, the prime table will consist of subsequent
prime numbers less than \MATH{2^{31}-1} and in descending order.
This function initializes the internal tables for computations where the absolute
values of the later results must not exceed \MATH{B}. (INTEGER mode)}


\fcode{ct}{crt\_table}{const bigint \& B \k const sdigit \& prime\_bound}
{
generates primes, beginning with initial seed \MATH{prime\_bound} to the
internal prime number generator; \MATH{prime\_bound} must be positve. When using
the default prime generator, the prime table will consist of subsequent
prime numbers less than \MATH{prime\_bound} and in descending order.
This function initializes the internal tables for computations where the absolute
values of the later results must not exceed \MATH{B}. (INTEGER mode)}


\fcode{ct}{crt\_table}{const base\_vector\MATH{<}sdigit\MATH{>} \& Primes}
{
copies all numbers in \MATH{Primes} into the internal prime table and initializes
the internal tables. If any of these numbers is negative, its absolute value
will be considered; if \MATH{Primes} contains at least two entries with
a non--trivial greatest common divisor, a call to the \TT{lidia\_error\_handler} will be
invoked.
The absolute values of the later results must be bounded by \MATH{\FRAC{M}{2}},
where \MATH{M} is the product of all numbers in vector \MATH{Primes} (INTEGER mode).
(Actually, those do not have to be primes but only pairwise coprime.)}



\fcode{ct}{crt\_table}{const bigint \& B \k const bigint \& P}
{
generates primes, beginning with initial seed \MATH{2^{31}-1} to the
internal prime number generator. When using
the default prime generator, the prime table will consist of subsequent
prime numbers less than \MATH{2^{31}-1} and in descending order.
This function initializes the internal tables for computations where the absolute
values of the later results must not exceed \MATH{B}. 
If \MATH{P} is non--zero, precomputations are performed modulo
\MATH{P} (MODULAR mode); otherwise \MATH{P} will be ignored (INTEGER mode).}


\fcode{ct}{crt\_table}{const bigint \& B \k const sdigit \& prime\_bound \k const bigint \& P}
{
generates primes, beginning with initial seed \MATH{prime\_bound} to the
internal prime number generator; \MATH{prime\_bound} must be positve. When using
the default prime generator, the prime table will consist of subsequent
prime numbers less than \MATH{prime\_bound} and in descending order.
This function initializes the internal tables for computations where the absolute
values of the later results must not exceed \MATH{B}. 
If \MATH{P} is non--zero, precomputations are performed modulo
\MATH{P} (MODULAR mode); otherwise \MATH{P} will be ignored (INTEGER mode).}


\fcode{ct}{crt\_table}{const base\_vector\MATH{<}sdigit\MATH{>} \& Primes \k const bigint \& P}
{
copies all numbers in \MATH{Primes} into the internal prime table and initializes
the internal tables. If any of these numbers is negative, its absolute value
will be considered; if \MATH{Primes} contains at least two entries with
a non--trivial greatest common divisor, a call to the \TT{lidia\_error\_handler} will be
invoked.
The absolute values of the later results must be bounded by \MATH{\FRAC{M}{2}},
where \MATH{M} is the product of all numbers in vector \MATH{Primes} (INTEGER mode).
(Actually, those do not have to be primes but only pairwise coprime.)
If \MATH{P} is non-zero, precomputations are performed modulo
\MATH{P} (MODULAR mode); otherwise, \MATH{P} will be ignored (INTEGER mode).}


\fcode{dt}{\SIM crt\_table}{}{}

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

\INIT
The initialization functions allow to create the internal data of a 
\BF{crt\_table} object after its definition or to reset an object for new
computations. Modifying an object for which there is still a reference in some
instance of class \BF{crt}, invokes the \TT{lidia\_error\_handler}.

Let \MATH{a} be of type \BF{crt\_table}.


\fcode{void}{a.init}{const bigint \& B}
{
initializes \MATH{a} like the constructor \TT{crt\_table(B)}.}


\fcode{void}{a.init}{const bigint \& B \k const sdigit \& prime\_bound}
{
initializes \MATH{a} like the constructor \TT{crt\_table(B, prime\_bound)}.}



\fcode{void}{a.init}{const base\_vector\MATH{<}sdigit\MATH{>} \& Primes}
{
initializes \MATH{a} like the constructor \TT{crt\_table(Primes)}.}



\fcode{void}{a.init}{const bigint \& B \k const bigint \& P}
{
initializes \MATH{a} like the constructor \TT{crt\_table(B, P)}.}



\fcode{void}{a.init}{const bigint \& B \k const sdigit \& prime\_bound \k const bigint \& P}
{
initializes \MATH{a} like the constructor \TT{crt\_table(B, prime\_bound, P)}.}


\fcode{void}{a.init}{const base\_vector\MATH{<}sdigit\MATH{>} \& Primes \k const bigint \& P}
{
initializes \MATH{a} like the constructor \TT{crt\_table(Primes, P)}.}


\fcode{void}{a.clear}{}
{
deletes all internally stored tables.}

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

\ACCS
Let \MATH{a} be of type \BF{crt\_table}.


\cfcode{lidia\_size\_t}{a.number\_of\_primes}{}
{
returns number of internally stored primes for which precomputations
have been done.}


\cfcode{sdigit}{a.get\_prime}{lidia\_size\_t  ix}
{
returns prime with index \MATH{ix} from the table.
The \TT{lidia\_error\_handler} will be invoked if index is negative or not less than 
\TT{a.number\_of\_primes()}.}


\cfcode{lidia\_size\_t}{a.how\_much\_to\_use}{bigint B}
{
If each result of the computation has an absolute
value of at most \MATH{B} but \MATH{a} has been initialized with some greater bound,
it might be sufficient to regard computations only modulo the first \MATH{l}
primes from the internal table instead of using all of them. In that case,
the function returns \MATH{l}; it returns \MATH{-1} if the table is not
large enough.

This option is only possible in INTEGER mode. When initialized with a modulus,
one always has to use every prime that has been generated before. Thus
in MODULAR mode, always the number of internal primes will be returned.}


\fcode{void}{a.set\_prime\_generator}{sdigit (*np) (const sdigit \& q) = nil}
{
changes the internal prime number generator to the function
\MATH{np} is pointing to. This must be a function which has a const reference
to an \BF{sdigit} as the only argument and returns an \BF{sdigit}.
Internally, only positive prime numbers are used. Thus any negative
return--value of \MATH{np} will be multiplied by \MATH{-1}.
Furthermore, one has to consider the fact, that \MATH{2^{31}-1} will be
given to this function by a constructor or an \TT{init()} member function.
Thus \MATH{np} should be able to accept this value as an input.
If no function pointer is given, the prime generator will be reset
to the default routine, which returns the next prime less than \MATH{q}.}


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

\STITLE{Class crt}
Member functions of this class are not applicable to an instance,
unless it is assigned a reference to an object \MATH{T} of class \BF{crt\_table}.
(The latter must already be initialized.) This can be done by means
of either a constructor or an \TT{init()} member function.

Depending on the mode (INTEGER or MODULAR) of \MATH{T}, all input data and final
results will be assumed to be of type \BF{bigint} or \BF{bigmod}. Only the
corresponding member functions are enabled.

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

\CONS
\fcode{ct}{crt}{}
{
creates an empty instance of the class crt.}


\fcode{ct}{crt}{crt\_table \& M}
{
creates an instance and stores a reference to \MATH{M}.
The reference counter of \MATH{M} will therefore be modified.}


\fcode{dt}{\SIM crt}{}
{
deletes all internal data and decreases the reference counter of
the corresponding \BF{crt\_table} object by one.}

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

\INIT
Let \MATH{a} be of type \BF{crt}.



\fcode{void}{a.init}{crt\_table \& M}
{
stores a reference to table \MATH{M}, that will then be used during the 
reduction and combining steps. If \MATH{M} has not been initialized before,
this will invoke the \TT{lidia\_error\_handler}.}


\fcode{void}{a.reset}{}
{
deletes any information that is stored in \MATH{a}, but leaves the reference
to an \BF{crt\_table} object unchanged.}


\fcode{void}{a.clear}{}
{
deletes any information that is stored in \MATH{a}, including the reference to
the \BF{crt\_table} object.}

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

\BASIC
\cfcode{sdigit}{a.get\_prime}{lidia\_size\_t ix}
{
returns the prime with index \MATH{ix} from underlying \BF{crt\_table} object.
The \TT{lidia\_error\_handler} will be invoked if \MATH{ix} is negative or not less than the number of
internal primes.}


\cfcode{lidia\_size\_t}{a.number\_of\_primes}{}
{
returns number of internally stored primes for which precomputations
have been made in the uderlying \BF{crt\_table} object.}


\cfcode{lidia\_size\_t}{a.how\_much\_to\_use}{const bigint \& B}
{
If each result of the computation has an absolute
value of at most \MATH{B} but the \BF{crt\_table} object referred to
has been initialized with some greater bound,
it might be sufficient to regard computations only modulo the first \MATH{l}
primes from the internal table, instead of using all of them. In that case,
the function returns \MATH{l}. It returns \MATH{-1} if the table is not
large enough.

This option is only possible in INTEGER mode. In MODULAR mode
one always has to use every prime that has been generated before. Thus
in the latter case, always the number of internal primes will be returned.}

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

\ARTH
\SSTITLE{Compute Residues}
Let \MATH{a} be of type \BF{crt}.

The \TT{reduce()} member functions provide easy reduction modulo the internal primes.
They do not modify any information stored in \MATH{a}.
To compute the residues, the remainder functions of class \BF{bigint} are used.


\cfcode{void}{a.reduce}{sdigit \&small \k const bigint \& big \k lidia\_size\_t ix}
{
\MATH{small \; = \; big \; \% \; p},

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}).}


\cfcode{void}{a.reduce}{sdigit* small\_vec \k const bigint* big\_vec \k long bsize, lidia\_size\_t ix}
{
\MATH{small\_vec[i] \; = \; big\_vec[i] \; \% \; p \quad (0 \LE i < bsize)},

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}).
This function does not allocate any space for \MATH{small\_vec}. Thus it must
be a pointer to an array of appropriate size.}


\cfcode{void}{a.reduce}{base\_vector\MATH{<}sdigit\MATH{>} \& small\_vec \k const base\_vector\MATH{<}bigint\MATH{>} \& big\_vec \k lidia\_size\_t ix}
{
\MATH{small\_vec[i] \; = \; big\_vec[i] \; \% \; p \quad (0 \LE i < big\_vec.size())},

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}).
The size and capacity of \MATH{small\_vec} are set to the size of \MATH{big\_vec}.}


\cfcode{void}{a.reduce}{base\_matrix\MATH{<}sdigit\MATH{>} \& small\_mat \k const base\_matrix\MATH{<}bigint\MATH{>} \& big\_mat \k lidia\_size\_t ix}
{
\MATH{small\_mat[i][j] \; = \; big\_mat[i][j] \; \% \; p \;\;
(0 \LE i < r, 0 \LE j < c)}

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}). Here \MATH{r} and \MATH{c}
represent the numbers of rows and columns of matrix \MATH{big\_mat}.
The size of \MATH{small\_mat} is adjusted to that of \MATH{big\_mat}.}



\cfcode{void}{a.reduce}{sdigit \&small \k const bigmod \& big \k lidia\_size\_t ix}
{
\MATH{small \; = \; big.mantissa() \; \% \; p},

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}).}


\cfcode{void}{a.reduce}{sdigit* small\_vec \k const bigmod* big\_vec \k long bsize, lidia\_size\_t ix}
{
\MATH{small\_vec[i] \; = \; big\_vec[i].mantissa() \; \% \; p \quad 
(0 \LE i < bsize)},

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}).
This function does not allocate any space for \MATH{small\_vec}. Thus it must
be a pointer to an array of appropriate size.}


\cfcode{void}{a.reduce}{base\_vector\MATH{<}sdigit\MATH{>} \& small\_vec \k const base\_vector\MATH{<}bigmod\MATH{>} \& big\_vec \k lidia\_size\_t ix}
{
\MATH{small\_vec[i] \; = \; big\_vec[i].mantissa() \; \% \; p \quad 
(0 \LE i < big\_vec.size())},

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}).
The size and capacity of \MATH{small\_vec} are set to the size of \MATH{big\_vec}.}


\cfcode{void}{a.reduce}{base\_matrix\MATH{<}sdigit\MATH{>} \& small\_mat \k const base\_matrix\MATH{<}bigmod\MATH{>} \& big\_mat \k lidia\_size\_t ix}
{
\MATH{small\_mat[i][j] \; = \; big\_mat[i][j].mantissa() \; \% \; p }

\MATH{(0 \LE i < r, 0 \LE j < c)}

for \MATH{p =}\TT{ a.get\_prime}(\MATH{ix}). Here, \MATH{r} and \MATH{c}
represent the number of rows and columns of matrix \MATH{big\_mat}.
The size of \MATH{small\_mat} is adjusted to that of \MATH{big\_mat}.}

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

\SSTITLE{Add Congruencial Equations}
The results of  computations modulo a particular prime are combined
to the final result via the \TT{combine()} member functions. You may not combine
a result modulo a specific prime twice.
The first call to any of these functions defines the data structure of the input
and final result: single, pointer array, \BF{base\_vector}, or \BF{base\_matrix}.
If, for example, the first function call is \TT{a.combine(u,ix1)} with 
an \BF{sdigit} \MATH{u}, then every attempt to use \TT{a.combine(uvec,ix2)} with
\MATH{uvec} as a \BF{base\_vector\MATH{<}sdigit\MATH{>}} will invoke the 
\TT{lidia\_error\_handler}.  Furthermore, you may not use objects of different size 
in subsequent calls to the function. This invokes the \TT{lidia\_error\_handler}.

To prematurely terminate a computation and allow the use of a \BF{crt} object
with some other input, one may use either of the two functions \TT{reset()}
and \TT{clear()}.



\fcode{void}{a.combine}{const sdigit \& small \k lidia\_size\_t ix}
{
stores the result modulo \TT{a.get\_prime(ix)}.}


\fcode{void}{a.combine}{const sdigit* small\_vec \k long l \k lidia\_size\_t ix}
{
stores the result modulo \TT{a.get\_prime(ix)}.}


\fcode{void}{a.combine}{const base\_vector\MATH{<}sdigit\MATH{>} \& small\_vec \k lidia\_size\_t ix}
{
stores the result modulo \TT{a.get\_prime(ix)}.}


\fcode{void}{a.combine}{const base\_matrix\MATH{<}sdigit\MATH{>} \& small\_mat \k lidia\_size\_t ix}
{
stores the result modulo \TT{a.get\_prime(ix)}.}

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

\SSTITLE{Reading Results}
Having defined  the congruencial equations, one can now
compute the result of the Chinese Remainder Theorem. In MODULAR
mode, congruences must be defined for each internal prime.
The INTEGER mode allows to choose arbitrarily many congruences.
Rational integers (\BF{bigint}) will then be computed as the absolutely
least residues modulo the product of all primes, that have been
used before. 

A call of the \TT{get\_result()} member function is only possible, if its argument
corresponds to preceeding uses of \TT{combine()}. I.e. if congruences
have been defined for matrices, then \TT{a.get\_result(big\_mat)} is
the only applicable function to obtain the solution.

After a call to the function \TT{get\_result()}, the information about
the object that was used will no longer be stored. Thus \MATH{a}
can later  arbitrarily be used again.


\fcode{void}{a.get\_result}{bigint \& big}
{
computes in \MATH{big} the result of the Chinese Remainder Theorem
according to the previously combined congruences.}



\fcode{void}{a.get\_result}{bigint*\& big\_vec \k lidia\_size\_t \& l}
{
computes in \MATH{big\_vec[i] \; (0 \LE i < l)} the result of the Chinese Remainder
Theorem according to the previously combined congruences.
First, \MATH{l} must be the size of the array \MATH{big\_vec} is
pointing to. If it differs from the size of the internal object,
\MATH{big\_vec} will be reallocated appropriately and its
new size will be assigned to \MATH{l}.}


\fcode{void}{a.get\_result}{base\_vector\MATH{<}bigint\MATH{>} \& big\_vec}
{
computes in \MATH{big\_vec[i] \; (0 \LE i < l)} the result of the Chinese Remainder
Theorem according to the previously combined congruences. The capacity
and size of vector \MATH{big\_vec} will previously be set to \MATH{l},
which is the size of the internal object.}


\fcode{void}{a.get\_result}{base\_matrix\MATH{<}bigint\MATH{>} \& big\_mat}
{
computes in \MATH{big\_mat[i][j] \; (0 \LE i < r, 0 \LE j < c)} the result of the
Chinese Remainder Theorem according to the previously combined congruences.
The number of rows and colums of \MATH{big\_mat} will previously be
set to \MATH{r} and \MATH{c}, respectively. Here \MATH{r} and \MATH{c}
represent the size of the internal matrix.}



\fcode{void}{a.get\_result}{bigmod \& big}
{
computes in \MATH{big} the result of the Chinese Remainder Theorem
according to the previously combined congruences.}



\fcode{void}{a.get\_result}{bigmod*\& big\_vec \k lidia\_size\_t \& l}
{
computes in \MATH{big\_vec[i] \; (0 \LE i < l)} the result of the Chinese Remainder
Theorem according to the previously combined congruences.
First, \MATH{l} must be the size of the array \MATH{big\_vec} is
pointing to. If it differs from the size of the internal object,
\MATH{big\_vec} will be reallocated appropriately and the 
new size will be assigned to \MATH{l}.}


\fcode{void}{a.get\_result}{base\_vector\MATH{<}bigmod\MATH{>} \& big\_vec}
{
computes in \MATH{big\_vec[i] \; (0 \LE i < l)} the result of the Chinese Remainder
Theorem according to the previously combined congruences. The capacity
and size of vector \MATH{big\_vec} will previously be set to \MATH{l},
which is the size of the internal object.}


\fcode{void}{a.get\_result}{base\_matrix\MATH{<}bigmod\MATH{>} \& big\_mat}
{
computes in \MATH{big\_mat[i][j] \; (0 \LE i < r, 0 \LE j < c)} the result of the
Chinese Remainder Theorem according to the previously combined congruences.
The number of rows and colums of \MATH{big\_mat} will previously be
set to \MATH{r} and \MATH{c}, respectively. Here \MATH{r} and \MATH{c}
represent the size of the internal matrix.}

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

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

           main ()
            {
              int    i , n  ;
              bigint big, B ;
              sdigit small  ;

              crt_table T ;
              crt       C ;
   
              cout << " Bound for absolute value : " ;
              cin  >> B ;
   
              T.init ( B ) ;
              C.init ( T ) ;
              n = C.number_of_primes() ;

              cout << " " << n << " congruences needed \n\n" ;
   
              for ( i = 0 ; i < n ; i++ )
               {
                 cout << " Congruence modulo "  ;
                 cout <<   C.get_prime(i) << " : " ;
                 cin  >>   small ;
                 C.combine ( small, i ) ;
               }
              C.get_result ( big ) ;
              cout << "\n Solution : " << big << endl ;
            }


        \end{verbatim}

For further reference please refer to\\
\TT{LiDIA/src/simple\_classes/chinese\_rem/crt\_appl.c}

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

\SEEALSO
\BF{base\_vector}, \BF{base\_matrix}, \BF{bigint}, \BF{bigmod}

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

\AUTHOR
Frank J. Lehmann, Thomas Pfahler
\end{lidia_man}

