% from 18.3.1992 hk
% user packages comp GB
% new version by pesch, 8.6.96 hk

\section{Comprehensive Gr\"obner bases} %------------------

\index{comprehensive Gr\"obner base}\index{Gr\"obner base! comprehensive}
The main point of comprehensive Gr\"obner bases is that the 
construction of a Gr\"obner base is not performed over a field, 
but over a ring (with parameters) 
such that the specialization of the parameters to 
elements of {\bf any} field leads to a Gr\"obner base 
over this field.
In this sense such an ideal base is a 
{\em comprehensive Gr\"obner base}.
In general the property of being a Gr\"obner base is lost under 
specialization of the coefficients as the following 
example from \cite{Wei90} shows.
Let $S = \Q \lbrack U \rbrack \lbrack X, Y \rbrack$ 
be a polynomial ring in $X, Y$ with parameter $U$ and with $X < Y$.
Let 
$$ 
   F = \{ X + 1, U Y + X \},
$$ 
then $F$ is a Gr\"obner base in $\Q \lbrack U, X, Y \rbrack$ wrt.\ $<$. 
Let $\sigma: \Q \lbrack U \rbrack \longrightarrow \K$ 
be a specialization, which embeds $\Q$ into $\K$ and 
with $\sigma(U) \in \K$. 
Then $\sigma(F)$ (defined by applying $\sigma$ to the coefficients) 
is a Gr\"obner base in $\K \lbrack X, Y \rbrack$ 
for any $\sigma$ with $\sigma(U) \neq 0$. 
But for a specialization with $\sigma(U) = 0$ we have 
$\sigma(F) = \{ X + 1, X \}$ and we see 
that $1 \in \ideal( \sigma(F) )$ but $1$ is not reducible with 
respect to $\sigma(F)$. So $\sigma(F)$ can not be a Gr\"obner base.
To obtain a comprehensive Gr\"obner base one would 
consider also the case when $U = 0$ and under this condition the 
polynomial $X + 1 - ( U Y + X ) = - U Y + 1 \in \ideal(F)$. 
So in this example 
$$
   G = \{ X + 1, U Y + X, - U Y + 1 \}
$$ 
would be a comprehensive Gr\"obner base, since now also 
under the specialization $\sigma(U) = 0$ we see 
that $\sigma(G) = \{ X + 1, X, 1 \}$ is a Gr\"obner base.

The construction of a comprehensive Gr\"obner base is 
performed by the usual process of building 
S-polynomials and reductions. But now the conditions 
under which the steps are performed are recorded 
in a set of conditions. This leads first to a tree 
of ideal bases where the nodes are labeled by 
the set of conditions under which the step has 
been performed. 
This tree of ideal bases is called a Gr\"obner system 
and a comprehensive Gr\"obner base is afterwards
obtained by taking the union of all ideal bases at 
the leaves of the tree. 
A condensed coding of the conditions applied to 
the coefficients of the polynomials under consideration 
is called a {\em colouring}.
A coefficient is coloured {\em red} if it is 
non-zero under the current set of conditions, 
it is coloured {\em green} if it is 
zero under the current set of conditions, 
otherwise it is coloured {\em white}.
A determined set of polynomials is a set of 
polynomials together with a set of conditions 
such that the first non-green term of a polynomial is 
coloured red. This term then serves as a head term
during the following steps of the reduction and 
S-polynomial construction. 
Using these constructions the algorithms for 
the construction of Gr\"obner systems are developed. 

\subsection{The new implementation and interface} %-------------

The comprehensive Gr\"obner basis package of MAS 0.7 has been changed in
many respects. There is a new user interface making better use of the
MAS interpreter. The old user interface is still present but will no
longer be supported. New features have been added. These include:
Conditions can now be evaluated by using reduced sets or
Gr\"obner bases. Comprehensive Gr\"obner bases for coefficient fields of
arbitrary characteristic can be computed. Computation can be restricted
to the generic case. This section is intended to explain
the {\em interactive usage} of the new comprehensive Gr\"obner basis 
package.

\subsubsection{A first example}

In case you just want to compute a comprehensive Gr\"obner basis and do not
want to know about options you may want to change the following example input
file \verb/example.in/ to suit your needs and start computation by entering
\verb/mas -f example.in/. Note that most of the blanks are mandatory
(including one after \verb/BEGIN/)!

\begin{verbatim}
       BEGIN
       p:=CDPREAD();
       CGBOPT(LIST(0,1,0,2,0,4,4));
       g:=GSYS(p);
       c:=CGBFGSYS(g);
       CDPWRITE(p);
       CGBOPTWRITE();
       GSYSWRITE(g);
       CGBWRITE(c);
       END.
       
       IP (a,b,c,d) (X,Y,Z) 
       
       0 
       () 
       1 
       () 
       . 
       
       (
       ( ( a**2 b**2 + a b ) X Y Z + ( c**3 d ) Y + 1 )
       ( X + ( c**2 d**2 + b ) Y )
       ).
       
       EXIT.
\end{verbatim}

\subsection{Features} %----

This package allows to 
\begin{itemize}
\item compute Gr\"obner systems and
\item compute comprehensive Gr\"obner bases.
\end{itemize}

Gr\"obner systems can be
\begin{itemize}
\item written to the output stream,
\item reduced and
\item converted to comprehensive Gr\"obner bases.
\end{itemize}

Comprehensive Gr\"obner bases can be
\begin{itemize}
\item written to the output stream,
\item globally reduced and
\item converted to a quantifier free formula.
\end{itemize}

The computations depend on some options.
\begin{itemize}
\item The amount of output generated during computation can be selected.
\item Factorization of coefficients can be used.
\item Top reduction can be used instead of ``normal'' reduction.
\item Conditions can be evaluated in three different ways:
\begin{itemize}
\item by just comparing polynomials,
\item by using reduced sets and
\item by using Gr\"obner bases.
\end{itemize}
\item Computations can be done in arbitrary characteristic instead of
characteristic zero. Note that in this case d-reduction is used
instead of reduction when evaluating conditions with reduced sets.
Note that evaluating conditions using Gr\"obner bases makes no sense in
arbitrary characteristic.
\item The term order for polynomials and coefficients can be selected.
\item The term order for polynomials and coefficients can be selected.
\item Computation can be restricted to the generic case only.
\end{itemize}
%

\subsection{Functions available through the interpreter} %--

The following functions supplied by this package 
are available through the MAS interpreter:

\begin{verbatim}
       PROCEDURE CDPREAD():LIST;        

       PROCEDURE CDPWRITE(CDP: LIST);
       
       PROCEDURE CGBOPT(O: LIST);
       
       PROCEDURE CGBOPTWRITE();
       
       PROCEDURE GSYS(CDP: LIST): LIST;
       
       PROCEDURE GSYSRED(GS: LIST): LIST;
       
       PROCEDURE GSYSWRITE(S: LIST);
       
       PROCEDURE CGBFGSYS(S: LIST): LIST;
       
       PROCEDURE CGBGLOBRED(CGB: LIST): LIST;
       
       PROCEDURE CGBWRITE(CGB: LIST);
       
       PROCEDURE CGBQFF(CGB: LIST): LIST;
\end{verbatim}

To compute a comprehensive Gr\"obner basis you first read the polynomial
system and the initial case distinction with \verb/CDPREAD/. This can be 
printed by \verb/CDPWRITE/. You can change the options with \verb/CGBOPT/
and write them with \verb/CGBOPTWRITE/.
Then you can compute a Gr\"obner system using \verb/GSYS/.
This can be reduced with \verb/GSYSRED/ and written to the output stream
with \verb/GSYSWRITE/.
The next step is computing a comprehensive Gr\"obner basis with
\verb/CGBFGSYS/. It can be written by \verb/CGBWRITE/ and globally reduced by
\verb/CGBGLOBRED/. The corresponding quantifier free formula can be
computed by \verb/CGBQFF/.

\subsection{User selectable Options} %--

All functions in this package depend on some global options.

\subsubsection{Writing Options} %--
The current state of the options can be printed out by
\begin{verbatim}
       CGBOPTWRITE().
\end{verbatim}
The output (if the default options are in effect) will be

{\footnotesize
\begin{verbatim}
   Options for computation of Groebner systems are: ( 1,1,0,0,0,4,4,0 )
   Some output during computation.
   With factorization of coefficients.
   Top-reduction only.
   Conditions are evaluated by comparing.
   Characteristic is 0.
   Term order: Total degree inverse lexicographical
   Coefficient term order: Total degree inverse lexicographical
\end{verbatim}
}

\subsubsection{Setting Options} %--
All options can be set by calling 
\begin{verbatim}
       CGBOPT(O).
\end{verbatim}
\verb/O/ is a list with an arbitrary number of elements.
The elements of \verb/O/ (if existent) are interpreted as follows:
\begin{description}
\item[1st element:] if 0 no output during computation, otherwise chatty.
\item[2nd element:] if 1 factorize coefficients, otherwise do not.
\item[3rd element:] if 0 use top reduction only, if 1 use "`normal"' reduction.
\item[4th element:] evaluate conditions using:
             if 0: simple method, if 1: reduced sets, if 2: Gr\"obner bases.
\item[5th element:] if 0: characteristic 0, otherwise
 arbritrary characteristic.
\item[6th element:] term order for polynomials
\item[7th element:] term order for coefficients
\item[8th element:] if 1 only the generic case is considered, otherwise all
cases
\end{description}

\subsection{Case Distinction and Polynomial Set} %--
A {\em case distinction and polynomial set} is the data structure
needed as input to compute comprehensive Gr\"obner bases. It contains
a domain descriptor, an initial case distinction and a list of polynomials.
\subsubsection{Reading Case Distinction and Polynomial Sets}\label{CDPREAD}
A {\em case distinction and polynomial set} can be read in by entering

\begin{verbatim}
       CDP:=CDPREAD().
       
       IP (<list of coeff. variables>) (<list of main variables>)
       
       0
       (<list of polynomials = 0>)
       1
       (<list of polynomials <> 0>)
       .
       
       (<list of polynomials>)
       .
\end{verbatim}

\subsubsection{Writing Case Distinction and Polynomial Sets} %--

A case distinction and polynomial set \verb/CDP/ can be written by
\begin{verbatim}
       CDPWRITE(CDP).
\end{verbatim}

\subsection{Gr\"obner Systems} %--

\subsubsection{Computing Gr\"obner Systems} %--

A Gr\"obner system can be computed by calling
\begin{verbatim}
       S:=GSYS(CDP).
\end{verbatim}
where \verb/CDP/ is a case distinction and polynomial set (see \ref{CDPREAD}).

\subsubsection{Computing Factorized Gr\"obner Systems}

{\bf This function is experimental!}
A factorized Gr\"obner system can be computed from a
case distinction and polynomial set \verb/CDP/ by
\begin{verbatim}
       S:=GSYSF(CDP).
\end{verbatim}

\subsubsection{Reducing Gr\"obner Systems}
A Gr\"obner system \verb/S/ can be reduced by
\begin{verbatim}
       S:=GSYSRED(S).
\end{verbatim}

\subsubsection{Writing Gr\"obner Systems}
A Gr\"obner system \verb/S/ can be printed by entering
\begin{verbatim}
       GSYSWRITE(S).
\end{verbatim}

\subsection{Comprehensive Gr\"obner Bases}
\subsubsection{Computing Comprehensive Gr\"obner Bases}
A comprehensive Gr\"obner basis can be computed from a Gr\"obner System
\verb/S/ by entering
\begin{verbatim}
       CGB:=CGBFGSYS(S).
\end{verbatim}

\subsubsection{Writing Comprehensive Gr\"obner Bases}
A comprehensive Gr\"obner basis \verb/S/ can be written to the output stream by
\begin{verbatim}
       CGBWRITE(CGB).
\end{verbatim}

\subsubsection{Globally Reducing Comprehensive Gr\"obner Bases}
A comprehensive Gr\"obner basis \verb/CGB/ can be globally reduced by
\begin{verbatim}
       CGB:=CGBGLOBRED(CGB).
\end{verbatim}

\subsection{Quantifier Elimination}
\subsubsection{Computing quantifier free formulas}
A quantifier free formula containing a condition for the
existence of common zeroes of the polynomials in a comprehensive
Gr\"obner basis \verb/CGB/ can be computed by
\begin{verbatim}
       QFF:=CGBQFF(CGB).
\end{verbatim}

\subsection{Writing the actual state of computation}

{\bf This feature is experimental!}
While MAS computes a Gr\"obner system sending \verb/SIGUSR1/ to MAS
will cause the actual state of computation to be written on the
terminal (even if output is redirected). This can be done from the
command line by entering
\begin{verbatim}
       kill -USR1 <pid of MAS>
\end{verbatim}
%

\subsection{A Sample Session} %----

In this section we give a sample interactive session. Note that some
uninteresting parts of the output (e.g.\ blank lines) have been omitted.
First we start MAS.

{\footnotesize\begin{verbatim}
{pesch@alice}[~]1: /mas

** Storage initialization ... 
** ... completed. 
 
Modula-2 Algebra System, Version 1.0
 
Copyrights: 
(c) 1989 - 1996, MAS: H. Kredel, Uni Passau.
(c) 1982, SAC-2:      G. E. Collins, Uni Ohio, R. Loos, Uni Tuebingen.
 
(non-profit redistribution is permitted)
 
\end{verbatim}
}

Next a set of polynomials and an initial (empty) case distinction is read.
{\footnotesize
\begin{verbatim}
       MAS: CDP:=CDPREAD().
       
       IP (a,b,c,d) (X,Y,Z) 
       
       0
        
       () 
       1 
       () 
       . 
       
       (
       ( ( a**2 b**2 + a b ) X Y Z + ( c**3 d ) Y + 1 )
       ( X + ( c**2 d**2 + b ) Y )
       ).
       
       ANS: [...]
\end{verbatim}
}

We write this to the output stream. 
{\footnotesize\begin{verbatim}
       MAS: CDPWRITE(CDP).
       
       Case distinction: 
       Condition: Empty.
        
       Polynomial set:
       Ring: IP(a,b,c,d) (* Integral Polynomial *) (X,Y,Z)
       ( (  a**2 b**2 + a b ) X Y Z +  c**3 d  Y + 1  )
        
       ( (  c**2 d**2 + b ) Y + X )
        
       
       ANS: ()
\end{verbatim}
}

We set the options, and write them to the output stream.
{\footnotesize\begin{verbatim}
       MAS: CGBOPT(LIST(0,1,0,1,0,4,4,0)). 
       
       ANS: ()
        
       MAS: CGBOPTWRITE().
        
       Options for computation of Groebner systems are: ( 0,1,0,1,0,4,4,0,)
       No output.
       With factorization of coefficients.
       Top-reduction only.
       Conditions are evaluated using reduced sets. 
       Characteristic is 0.
       Term order: Total degree inverse lexicographical
       Coefficient term order: Total degree inverse lexicographical
        
       ANS: ()
\end{verbatim}
}
 
We compute a Gr\"obner system, reduce it and write the result
to the output stream.
{\footnotesize\begin{verbatim}
       MAS: GS:=GSYS(CDP).
       
       ANS: [...]
       
       MAS: GSR:=GSYSRED(GS).
       
       ANS: [...]
       MAS: GSYSWRITE(GSR).
       
        
       Groebner system:
       Condition: 
       (  c**2 d**2 + b )= 0
       (  a b +1 )<> 0
         b <> 0
         a <> 0
        
       1 Condition.
        
       Basis: 
       ( (  c**2 d**2 + b ) Y + X )
        
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) Y**2 Z -  c**3 
       d  Y - 1  )
        
       Condition: 
       (  c**2 d**2 + b )<> 0
       (  a b +1 )<> 0
         b <> 0
         a <> 0
        
       1 Condition.
        
       Basis: 
       ( (  c**2 d**2 + b ) Y + X )
        
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) X**2 Z +(  c**5
        d**3 + b c**3 d ) X -(  c**4 d**4 +2 b c**2 d**2 + b**2 ) )
        
       Condition: 
         c = 0
         d = 0
         b = 0
         a = 0
        
       Condition: 
         d = 0
         b = 0
         a = 0
         c <> 0
        
       Condition: 
         c = 0
         b = 0
         a = 0
         d <> 0
        
       Condition: 
         c = 0
         d = 0
         a = 0
         b <> 0
        
       Condition: 
         d = 0
         a = 0
         c <> 0
         b <> 0
        
       Condition: 
         c = 0
         a = 0
         d <> 0
         b <> 0
        
       Condition: 
         c = 0
         d = 0
         b = 0
         a <> 0
        
       Condition: 
         d = 0
         b = 0
         c <> 0
         a <> 0
        
       Condition: 
         c = 0
         b = 0
         d <> 0
         a <> 0
        
       Condition: 
         c = 0
         d = 0
       (  a b +1 )= 0
         b <> 0
         a <> 0
        
       Condition: 
         d = 0
       (  a b +1 )= 0
         c <> 0
         b <> 0
         a <> 0
        
       Condition: 
         c = 0
       (  a b +1 )= 0
         d <> 0
         b <> 0
         a <> 0
        
       12 Conditions.
        
       Basis: 
       ( (  a**2 b**2 + a b ) X Y Z +  c**3 d  Y + 1  )
        
       Condition: 
       (  a b +1 )= 0
       (  c**2 d**2 + b )<> 0
         c <> 0
         d <> 0
         b <> 0
         a <> 0
        
       Condition: 
         b = 0
         c**2 d**2 <> 0
         c <> 0
         d <> 0
         a <> 0
        
       Condition: 
         a = 0
       (  c**2 d**2 + b )<> 0
         c <> 0
         d <> 0
         b <> 0
        
       Condition: 
         b = 0
         a = 0
         c**2 d**2 <> 0
         c <> 0
         d <> 0
        
       4 Conditions.
        
       Basis: 
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) X Y Z +(  c**5 
       d**3 + b c**3 d ) Y +(  c**2 d**2 + b ) )
        
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) X Y Z -  c**3 d
         X +(  c**2 d**2 + b ) )
        
       Condition: 
       (  c**2 d**2 + b )= 0
       (  a b +1 )= 0
         c <> 0
         d <> 0
         b <> 0
         a <> 0
        
       Condition: 
       (  c**2 d**2 + b )= 0
         c**2 d**2 = 0
         b = 0
         c <> 0
         d <> 0
         a <> 0
        
       Condition: 
       (  c**2 d**2 + b )= 0
         a = 0
         c <> 0
         d <> 0
         b <> 0
        
       Condition: 
       (  c**2 d**2 + b )= 0
         c**2 d**2 = 0
         b = 0
         a = 0
         c <> 0
         d <> 0
        
       4 Conditions.
        
       Basis: 
       ( (  a**2 b**2 + a b ) X Y Z +  c**3 d  Y + 1  )
        
       ( (  c**2 d**2 + b ) Y + X )
        
       ANS: ()
\end{verbatim}
}

We compute a comprehensive Groebner basis and write it to the output stream.
{\footnotesize\begin{verbatim}
 
       MAS: CGB:=CGBFGSYS(GSR).
       
       ANS: [...]
        
       MAS: CGBWRITE(CGB).
       

 
       Comprehensive-Groebner-Basis: 
       ( (  c**2 d**2 + b ) Y + X )
        
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) X**2 Z +(  c**5
        d**3 + b c**3 d ) X -(  c**4 d**4 +2 b c**2 d**2 + b**2 ) )
        
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) X Y Z -  c**3 d
         X +(  c**2 d**2 + b ) )
        
       ( (  a**2 b**2 + a b ) X Y Z +  c**3 d  Y + 1  )
        
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) X Y Z +(  c**5 
       d**3 + b c**3 d ) Y +(  c**2 d**2 + b ) )
        
       ( (  a**2 b**2 c**2 d**2 + a b c**2 d**2 + a**2 b**3 + a b**2 ) Y**2 Z -  c**3 
       d  Y - 1  )
 
       22 Conditions.
        
       ANS: ()
\end{verbatim}
}

This is the end of the comprehensive Gr\"obner base example. 


%\section{} %----------

%{\footnotesize %-------------------------
%\begin{verbatim} 
%\end{verbatim}
%}
%{\footnotesize %-------------------------
%\begin{verbatim} 
%\end{verbatim}
%}
