/********************************************************************************
*  Program for finding discarding proceses used in the manuscript               *
*  The Diagonal Polynomials of Dimension Four                                   *
*  by H.L. Fetter, J.H. Arredondo R and L.B.  Morales                           *
*                                                                               *
*  Version    17 January  2003                                                  *
*                                                                               *
********************************************************************************/

/********************************************************************************
* Here, $g$ denotes a polynomial of the form (3)                                *
*                                                                               *
********************************************************************************/                         
/********************************************************************************
*                                                                               *
*  $M$, $P_1,...,P_r$, $U_1,...,U_r$, $(i_s,j_s,k_s,l_s)$, $c_s$  $(s=1,...p)$  *
*  denote the parameters of a process                                           *
*                                                                               *
*  If the  set $U_t$ has the form $<e_{i_t},e_{j_t}>$   ($t=1,...r$)            *
*  then the coefficients of the polynomial $g|U_t$ are $a_{e_i_t},a_{e_j_t}$    *
*  $a_{2e_i_t},a_{e_i_t+e_j_t},a_{2e_j_t},a_{3e_i_t},a_{3e_j_t},                *
*  a_{e_i_t+2e_j_t},a_{2e_i_t+e_j_t}$                                           *
*  Henceforth, we drop the subindex t the above vectors                         *
*  the vectors $e_i,e_j,2e_i,e_i+e_j,2e_j,3e_i,3e_j,e_i+2e_j,2e_i+e_j$          *
*  are stored in the array $K$  ($K[t][h][s]$, $0<t<r, 0<h<10, 1<s<5$)          *
*  The array K is used as a local variable in the procedure Principal           *
*                                                                               *
********************************************************************************/ 
#include<stdio.h>
#include<stdlib.h>  
#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>


/*********************************************************************************************                         
*                                                                                            *
* Here the input and the output of the program are explained                                 *
*                                                                                            *        
* Input File ParameterTable.H (H=2,...,15):                                                  *
*===                                                                                         *
*  S                                     parameter  s                                        *
*  i_1 j_1 k_1 l_1,...,i_s j_s k_s l_s   parameters (i_1,j_1,k_1,l_1),...,(i_s,j_s,k_s,l_s)  *
*  c_1,...,c_s                           parameters c_1,...,c_s                              *
*  R                                     parameter  r                                        *
*  i_1 j_1 k_1 l_1                       indexes i_1,j_1,k_1,l_1 of  U_1=<e_1,...,e_4>       *
*     .                                                                                      *
*     .                                                                                      *
*     .                                                                                      *
*  i_r j_r k_r l_r                       indexes i_r,j_r,k_r,l_r of  U_r=<e_1,...,e_4>       *
*===                                                                                         *
*                                                                                            *
*===                                                                                         *
* Output File Table.H ((H=2,...,15) contains the Table H                                     *
*===                                                                                         *
*  For each process j from file ParameterTable.H (H=2,...,15), our program opens S Files     *
*       Process_jP_1TH.tex                                                                   *
*           .                                                                                *
*           .                                                                                *
*           .                                                                                *
*       Process_jP_sTH.tex                                                                   *
*                                                                                            *
*  Each File contains the polynomials (in format Latex) of the set P_t of                    *
*  the j process from file                                                                   *
*********************************************************************************************/

FILE *fsal,*finput,*ftabla;

int top = 36;     /* w = 2,..., top                                */
int S;            /* number of vectors $(i_s,j_s,k_s,l_s)$ in a Discarding Process  */
int R;            /* number of sets $P_t$ in a Discarding Process  */
int t;            /* t = 0,...,R-1                                 */
int ijkl[5];      /* parameter $(i_s,j_s,k_s,l_s)$ is stored in the array ijkl  */
int C[3];         /* parameter $c_s$ is stored in the array  C       */
int  num_aijkl;   /* position of $(i_s,j_s,k_s,l_s)$ in the array K  */

int term_aijkl;                                                                                                        
int num_coef[40]; /* num_coef[t] number of coefficients of the polynomials $g|U_t$   */

int NProc,AUX[10][10], nTable;
int NUM_POL[10];  /* NUM_POL[t] number of polynomials in $P_t$  */ 

#define begin {
#define end ;}


/********************************************************************************
*                                                                               *
*  The possible values for the coefficients $a_{e_i+2e_j}$ and $a_{2e_i+e_j}$   *
*  ($i\not=j$) of the polynomial $g$ are stored in the f and s fields of the    *
*   structure REbb                                                              *                  
*  The number of these possible values of these coefficients is stored in the   *
*  cota field of Rebb                                                           *
*                                                                               *
********************************************************************************/
typedef struct {
  int f[12]; 
  int s[12];  
  int cota;   
 } REbb;  

/********************************************************************************
*                                                                               *
*  The possible values for other coefficients $a_{ijkl}$ of $g$ are stored in   *
*  the v field of the structure REb                                             *                
*  The number of these possible values of these coefficients is stored in the   *
*  cota field of Rebb                                                           *
*                                                                               *
********************************************************************************/
typedef struct {
  int v[15]; 
  int cota;  
 } REb;


/********************************************************************************
*                                                                               *
*  The x and imagen fields of the  structure REGISTRO is used to store the      *
*  vector $(x_1,x_2,x_3,x_4)$ and  $g(x_1,x_2,x_3,x_4)$                         *
*                                                                               *
********************************************************************************/
typedef struct {
  int x[5];      
  int imagen;    
 } REGISTRO;

/********************************************************************************
*                                                                               *
*  The i,j,k and l fields of the structure aIJ are used to store the indexes    *
*  $i,j,k,l$ of the set $U_t=<e_i,e_j,e_k,e_l}>$                                * 
*                                                                               *
********************************************************************************/
 typedef struct {
  int i;
  int j;
  int k;
  int l;
 } AIJ; 
/********************************************************************************/

struct nodoBinImagen { 
   REGISTRO reg;
   struct nodoBinImagen *izq;
   struct nodoBinImagen *der; 
 };    

typedef struct nodoBinImagen *NODOBINimagenPTR;

NODOBINimagenPTR arbImagen = NULL; /* raiz de arbol */

/********************************************************************************
*  NODOBINimagenPTR nuevo_nodoBinImagen(),                                      *
*  void libera_mem_arbolImagen(r),                                              *
*  int compara(a1,b1),                                                          *
*  int search(datos,pp),                                                        *
*  These procedures are used to check injectivity of the polynomial $g$         * 
*                                                                               *
********************************************************************************/

NODOBINimagenPTR nuevo_nodoBinImagen() /* pag 134 K&R */
begin
  NODOBINimagenPTR p;
  p = (NODOBINimagenPTR) malloc( sizeof( struct nodoBinImagen ) );

  if (p == NULL)
    begin
      fprintf(fsal,"no hay celdas para árbol\n");
      fprintf(fsal,"no hay celdas para árbol\n");
      exit (33);
    end;
  return(p);
end
/*****/

void libera_mem_arbolImagen(r)
  NODOBINimagenPTR r;
begin
  if (r != NULL)
    begin
      libera_mem_arbolImagen(r->izq);
      libera_mem_arbolImagen(r->der);
      free(r)
    end
end
/*****/

int compara(a1,b1)
  int a1,b1;
begin
 
  if (a1<b1) return(-1);
  else
    if (a1>b1) return(1);
  return(0)
end
/*****/

int search(datos,pp) 
  REGISTRO datos;
  NODOBINimagenPTR *pp;
begin
  int i;
  if ( *pp == NULL )
    begin  /* datos no se encontró, inserta nodo con el */
      *pp = nuevo_nodoBinImagen();
      (*pp)->reg = datos;
      (*pp)->izq = NULL;
      (*pp)->der = NULL;
      return (1);
    end
  else
  switch (compara(datos.imagen,(*pp)->reg.imagen))
    begin
      case -1: return(search(datos, &(*pp)->izq));
      case  0: {
                 for (i=0;i<=3;i++)
                    if ((*pp)->reg.x[i]!=datos.x[i]){
/***********************************************************************************
* Here you can see the points $x$ and $y$  where the polynomials is does inyective *
***********************************************************************************/
/*
                    {
                         fprintf(fsal,"g(");
                         for (i=0;i<=3;i++)
                            fprintf (fsal,"%3d", (*pp)->reg.x[i]);
                          fprintf(fsal,") = %5d", (*pp)->reg.imagen);
                         fprintf(fsal," = g( ");
                          for (i=0;i<=3;i++)
                             fprintf (fsal,"%3d", datos.x[i]);
                          fprintf(fsal,") = %5d\n", datos.imagen);
                    } 
*/

                      return (0);
                    }
                  return(1);
                }
      case  1: return(search(datos, &(*pp)->der));
    end
 return (2);
end
/*******************************************************************************/

void BeginLatex(outset)
FILE *outset;
{
 
  fprintf (outset, "\\setlength{\\oddsidemargin}{.0001in}\n");
  fprintf (outset, "\\setlength{\\evensidemargin}{.0001in}\n");
  fprintf (outset, "\\setlength{\\textwidth}{6.5in}\n");
  fprintf (outset, "\\setlength{\\textheight}{8.5in}\n");
  fprintf (outset, "\\setlength{\\topmargin}{0.0in}\n");
 
  fprintf (outset, "\\documentstyle[11pt]{report} \n");
  fprintf (outset, "\\begin{document}  \n");
  fprintf (outset, "\\def\\vx{{\\rm \\bf x}}\n");
}
 
void EndLatex(outset)
FILE *outset;
{
 fprintf (outset, "\\end{document}  \n");
}               

/*******************************************************************************
*   This procedure writes the binomial coefficients (in format latex) to       *     
*   the file pols.tex                                                          * 
*******************************************************************************/
void WriteChoose(K,n,outset)
int  K[9][5];
int n;
FILE *outset;
{
 int i;
 
 for (i=1;i<=4;i++){
   if (K[n][i]!=0){
     if (K[n][i]!=1)
       fprintf (outset,"{x_%d \\choose %d}", i, K[n][i]  );
    if (K[n][i]==1)
       fprintf (outset,"x_%d",i);
   }
 
 }
}       

/*******************************************************************************
*   This pocedure writes the polynomial $g|U_t$ (in format latex) to the      *
*   file pols.tex                                                              * 
*******************************************************************************/
void WritePolynomial(K,a)
int  K[9][5];
int a[4][4][4][4];
{
 int n,i;
 int contar = 0;
 FILE *outset;
 char NamSet[100];
 
 
 sprintf(NamSet,"Process%dP_%dT%d.tex",NProc,(t+1),nTable);
 outset = fopen (NamSet,"a");        

 if (AUX[NProc][t]==0)
   BeginLatex(outset);

 fprintf (outset,"\\begin{eqnarray*}\n");
 fprintf (outset,"g|U_%d(\\vx) & = & \n",(t+1));
 for (n=1;n<=num_coef[t];n++){
    if (a[K[n][1]][K[n][2]][K[n][3]][K[n][4]]!=0){
       contar++;
      if (contar%8==0 && n<num_coef[t]){ fprintf (outset,"\\\\ & &\n"); }
      if (a[K[n][1]][K[n][2]][K[n][3]][K[n][4]]>=1 && contar>1)
        fprintf (outset,"+");
      if (a[K[n][1]][K[n][2]][K[n][3]][K[n][4]]==-1)
        fprintf (outset,"-");
      if (abs(a[K[n][1]][K[n][2]][K[n][3]][K[n][4]])!=1)
         fprintf (outset,"%2d",a[K[n][1]][K[n][2]][K[n][3]][K[n][4]]);
        WriteChoose (K,n,outset);
    }
 }       
 fprintf (outset,"\n");
 fprintf (outset,"\\end{eqnarray*}\n");

 AUX[NProc][t]=1;

 fclose (outset);
}          

/********************************************************************************
*                                                                               *
*  This procedure determines the allowed values for the coefficients of the     *
*  polynomials in the parameter $M$ of the process                              *
*                                                                               *
********************************************************************************/
int AllowedValue(b,bb)
 REb b[4][4][4][4]; 
 REbb bb[5][5];  
{
 int i,j,k,l,n;
 int suma;

/********************************************************************************
*  Values of $a_{3e_i}$ according to  Lemma 3.1                                 *   
********************************************************************************/
 b[3][0][0][0].cota  = 1;    
 b[0][3][0][0].cota  = 1;
 b[0][0][3][0].cota  = 1;
 b[0][0][0][3].cota  = 1;      
 for (i=0;i<=1;i++){           
   b[3][0][0][0].v[i] = i;
   b[0][3][0][0].v[i] = i;
   b[0][0][3][0].v[i] = i;
   b[0][0][0][3].v[i] = i;
 }

/********************************************************************************
*  Values of _{e_i}$ according to Lemma 3.2                                     *   
********************************************************************************/
 b[1][0][0][0].cota = 0; 
 b[1][0][0][0].v[0] = 0; 
 b[0][1][0][0].cota = 0; 
 b[0][1][0][0].v[0] = 1; 
 b[0][0][1][0].cota = 0; 
 b[0][0][1][0].v[0] = 2; 
 b[0][0][0][1].cota = 0; 
 b[0][0][0][1].v[0] = 3; 
 
/********************************************************************************
*  Values of $a_{2e_i}$ according to Lemma 3.3                                  *   
********************************************************************************/
 b[2][0][0][0].cota  = 5;
 b[0][0][0][2].cota  = 5;
 for (i=0;i<=5;i++){
   b[2][0][0][0].v[i] = i;    
   b[0][0][0][2].v[i] = i-2;    
 }
 b[0][2][0][0].cota  = 6;
 b[0][0][2][0].cota  = 6;
 for (i=0;i<=6;i++){
   b[0][2][0][0].v[i] = i-1;    
   b[0][0][2][0].v[i] = i-2;    
 }

/********************************************************************************
*  Values of $a_{e_i+e_j}$ according to Lemma 3.4                               *   
********************************************************************************/
  for (i=0;i<=1;i++)
    for (j=0;j<=1;j++)
      for (k=0;k<=1;k++)
        for (l=0;l<=1;l++){
         suma = i+j+k+l;
         if (suma==2 &&(i==1 || j==1 || k==1 || l==1)){
            b[i][j][k][l].cota = 9;
            for (n=0;n<=9;n++){
              b[i][j][k][l].v[n] = n+2-i-2*j-3*k-4*l; 
            } 
         }
        }

/********************************************************************************
*  Values of $(a_{2e_i+e_j},a_{e_i+2e_j})$ according to Lemma 3.5               *
********************************************************************************/
 for (i=1;i<=4;i++)
   for (j=1;j<=4;j++)
     if (i!=j){
     bb[i][j].cota = 11;
     bb[i][j].f[0] = -1; bb[i][j].s[0] =  1;
     bb[i][j].f[1] =  1; bb[i][j].s[1] = -1;
     bb[i][j].f[2] =  2; bb[i][j].s[2] =  0;
     bb[i][j].f[3] =  0; bb[i][j].s[3] =  2;
     bb[i][j].f[4] = -2; bb[i][j].s[4] =  3;
     bb[i][j].f[5] =  3; bb[i][j].s[5] = -2;
     bb[i][j].f[6] = -1; bb[i][j].s[6] =  2;
     bb[i][j].f[7] =  2; bb[i][j].s[7] = -1;
     bb[i][j].f[8] =  0; bb[i][j].s[8] =  1;
     bb[i][j].f[9] =  1; bb[i][j].s[9] =  0;
     bb[i][j].f[10] = 0; bb[i][j].s[10] = 0;
     bb[i][j].f[11] = 1; bb[i][j].s[11] = 1;
   }
/********************************************************************************
*  Values of $a_{e_i+e_j+e_k}$ according to Lemma 3.8                           *
********************************************************************************/
  for (i=0;i<=1;i++)
    for (j=0;j<=1;j++)
      for (k=0;k<=1;k++)
        for (l=0;l<=1;l++){
         suma = i+j+k+l;
         if (suma==3 &&(i!=2 && j!=2 && k!=2 && l!=2)){
            b[i][j][k][l].cota = 7;
            for (n=0;n<=7;n++){
              b[i][j][k][l].v[n] = n-3;
            }
         }
        }      
 

/********************************************************************************
*  To generate the processes of the Tables 4, 5 and 6                           *
********************************************************************************/
 if (S==2){
    /* Polynomias in ${\cal G}$ */
    return (1);
 }


/********************************************************************************
* Values of $(a_{2e_i+e_j},a_{e_i+2e_j})$ according to Corollary 5.4            *
********************************************************************************/
 for (i=1;i<=4;i++)
   for (j=1;j<=4;j++)
     if (i!=j){
     bb[i][j].cota = 3;
     bb[i][j].f[0] = 0; bb[i][j].s[0] = 0;
     bb[i][j].f[1] = 0; bb[i][j].s[1] = 1;
     bb[i][j].f[2] = 1; bb[i][j].s[2] = 0;
     bb[i][j].f[3] = 1; bb[i][j].s[3] = 1;
   }

/********************************************************************************
*  To  generate the processes of the third and fifth rows of Table 6            *
********************************************************************************/
 if (ijkl[1]==2 && ijkl[2]==0 && ijkl[3]==0 && ijkl[4]==0 && C[1]>3){ 
   /* Polynomias in ${\cal G_1}$ */ 
   return (1);
 }


/********************************************************************************
*                     By Lemma 6.1 (third and fifth rows of Table 6)            *
********************************************************************************/
 b[2][0][0][0].cota = 3;

/********************************************************************************
*  To  generate the processes in 8th, 10th and 12th of Table 6                  *
********************************************************************************/
 if (ijkl[1]==0 && ijkl[2]==2 && ijkl[3]==0 && ijkl[4]==0 && (C[1]>3 || C[1]==-1)){
    /* Polynomias in ${\cal G_1^\prime}$ */   
    return (1);
 }


/********************************************************************************
*                     By Lemma 6.1 (8th, 10th and 12th of Table 6)              *
********************************************************************************/
 b[0][2][0][0].cota = 3;
 for (i=0;i<=3;i++)
    b[0][2][0][0].v[i] = i; 

/********************************************************************************
*                         By Lemma 6.1                                          *   
********************************************************************************/
 b[2][0][0][0].cota = b[0][2][0][0].cota = 
 b[0][0][2][0].cota = b[0][0][0][2].cota = 3;
 for (i=0;i<=3;i++)
   b[2][0][0][0].v[i] = b[0][2][0][0].v[i] = 
   b[0][0][2][0].v[i] = b[0][0][0][2].v[i] = i;    

/********************************************************************************
*  To generate the processes of Table 7                                         * 
********************************************************************************/
 if (ijkl[1]==1 && ijkl[2]==1 && ijkl[3]==0 && ijkl[4]==0 && C[1]>3){
    /* Polynomias in ${\cal G_2}$ */   
    return (1);
 }

/********************************************************************************
*  To  generate the processes of Table 8                                        * 
********************************************************************************/
 if (ijkl[1]==1 && ijkl[2]==0 && ijkl[3]==1 && ijkl[4]==0 &&  C[1] >2){
    /* Polynomias in ${\cal G_2}$ */   
    return (1);
 }

/********************************************************************************
*                        By Lemma 6.2(i)-(ii)                                   *   
********************************************************************************/
 b[1][1][0][0].cota = 4;
 for (i=0;i<=4;i++)
    b[1][1][0][0].v[i] = i-1; 

 b[0][0][1][1].cota = 4;
 for (i=0;i<=4;i++)
    b[0][0][1][1].v[i] = i; 


/********************************************************************************
*                        By Lemma 6.2(iii)-(iv)                                 *   
********************************************************************************/
 b[1][0][1][0].cota = 4; 
 for (i=0;i<=4;i++)
    b[1][0][1][0].v[i] = i-2; 

 b[0][1][0][1].cota = 4; 
 for (i=0;i<=4;i++)
    b[0][1][0][1].v[i] = i+1; 

/********************************************************************************
* To generate the processes of Table 9                                          *
********************************************************************************/
 if ((ijkl[1]==1 && ijkl[2]==0 && ijkl[3]==0 && ijkl[4]==1 &&  C[1] >4)||
     (ijkl[1]==0 && ijkl[2]==1 && ijkl[3]==1 && ijkl[4]==0 &&  C[1] >2)){
    /* Polynomias in ${\cal G_2~\prime}$ */
    return (1);
 }


/********************************************************************************
*                        By Lemma 6.2 (Table 9)                                 *   
********************************************************************************/
 b[1][0][0][1].cota = 5; 
 for (i=0;i<=5;i++)
    b[1][0][0][1].v[i] = i-1; 

 b[0][1][1][0].cota = 1; 
 for (i=0;i<=1;i++)
    b[0][1][1][0].v[i] = i+1; 

/********************************************************************************
*  To generate the processes of Table 10                                        *
********************************************************************************/
 if (ijkl[1]==1 && ijkl[2]==1 && ijkl[3]==0 && ijkl[4]==0 &&  C[1]==3){
    /* Polynomias in ${\cal G_2^{\prime\prime}}$ */
    return (1);
 }      


/********************************************************************************
*                        By Lemma 6.3                                           *   
********************************************************************************/
 b[1][1][0][0].cota = 3;


/********************************************************************************
*  To generate the processes of Table 11                                       *                                         
********************************************************************************/
 if ((ijkl[1]==0 && ijkl[2]==0 && ijkl[3]==0 && ijkl[4]==3 &&  C[1]==0)||
     (ijkl[1]==0 && ijkl[2]==0 && ijkl[3]==0 && ijkl[4]==3 &&  C[1]==1)) {
     /* Here, we must suppose that a3000=1    */
     b[3][0][0][0].cota = 0; 
     b[3][0][0][0].v[0] = 1;
    /* Polynomias in ${\cal G_2^{\prime\prime\prime}}$ */
     return (1);
 }

/********************************************************************************
*                        By Lemma 6.4                                           *   
********************************************************************************/
  b[3][0][0][0].cota  = 0;    
  b[0][0][0][3].cota  = 0;      
  b[0][0][0][3].v[0]  = 1;      

/********************************************************************************
*  To generate the processes of Table 12                                        *
********************************************************************************/
 if (ijkl[1]==1 && ijkl[2]==1 && ijkl[3]==0 && ijkl[4]==0 &&  C[1]==-1){
     /* Polynomias in ${\cal G_3}$ */
      return (1);
 }

/********************************************************************************
*  To generate the processes of Table 13                                        *
********************************************************************************/
 if (ijkl[1]==1 && ijkl[2]==0 && ijkl[3]==1 && ijkl[4]==0 && (C[1]==-2 || C[1]==-1)){
     /* Polynomias in ${\cal G_3^\prime}$ */
     return (1);
 }

/********************************************************************************
*                        By Lemma 6.5(ii) (Table 13)                            *   
********************************************************************************/
   b[1][0][1][0].cota = 2;
   for (i=0;i<=2;i++)
     b[1][0][1][0].v[i] = i;

/********************************************************************************
*  To generate the processes of Table 14                                        *
********************************************************************************/
 if (ijkl[1]==1 && ijkl[2]==0 && ijkl[3]==0 && ijkl[4]==1 &&  C[1]==-1){
     /* Polynomias in ${\cal G_3^{\prime\prime}$ */
   return (1);
 }

/********************************************************************************
*                      By Lemmas 6.2, 6.3, 6.5 and 6.6                          *   
********************************************************************************/
  b[2][0][0][0].cota = b[1][1][0][0].cota = 0;
  b[2][0][0][0].v[0] = b[1][1][0][0].v[0] = 0;
 
  b[0][0][0][2].cota = b[0][0][1][1].cota = 0;
  b[0][0][0][2].v[0] = b[0][0][1][1].v[0] = 3; 

  b[1][0][1][0].cota = 2;
  for (j=0;j<=2 ;j++)
   b[1][0][1][0].v[j] = j ;

  b[0][1][0][1].cota = 4;
  for (j=0;j<=4 ;j++)
   b[0][1][0][1].v[j] = j+1;

  b[1][0][0][1].cota = 4;
  for (j=0;j<=4 ;j++)
   b[1][0][0][1].v[j] = j;

  b[0][1][1][0].cota = 1;
  for (j=0;j<=1 ;j++)
   b[0][1][1][0].v[j] = j+1;

/********************************************************************************
*  To generate the process of Table 15                                          *
********************************************************************************/
 if (ijkl[1]==1 && ijkl[2]==0 && ijkl[3]==0 && ijkl[4]==0 &&  C[1]==0){
     /* Polynomias in ${\cal G_4}$ */
   return (1);
 }
   
}
/*******************/


/********************************************************************************
*  This function calculates  $x(x-1)* ... *(x-n+1)/n!$                           *
********************************************************************************/
int XI(n,x)
int n,x;
{
 int i,prod1,prod2;

 if (n==0) return (1); 
 prod1 = n;
 prod2 = x;
 for (i=1;i<n;i++){
   prod1 = prod1*i;
   prod2 = prod2*(x-i);
 }
 prod1 = prod2/prod1;
 return (prod1);
}

/*******************************************************************************
*  This procedure calculates the right side of inequality  (2)                 * 
*******************************************************************************/
int coef_bi(w)
int w;   
{
return (-1+((w+3)*(w+2)*(w+1))/6);
}
   
/*******************************************************************************
*  This function calculates the polynomial $g(x1,x2,x3,x4)$ for given          * 
*  coefficients                                                                *
*******************************************************************************/
int  poly(x1,x2,x3,x4,a)
int x1,x2,x3,x4;      /* variables of $g$     */ 
int a[4][4][4][4];    /* given coefficients of $g$  */
{
 int i,j,k,l;
 int sum,pol,pol1;

 pol = 0;
 for (i=0;i<=3;i++)
   for (j=0;j<=3;j++)
     for (k=0;k<=3;k++)
       for (l=0;l<=3;l++){
         sum = i+j+k+l;
         if (0<sum && sum<4){
             pol1 = a[i][j][k][l]*XI(i,x1)*XI(j,x2)*XI(k,x3)*XI(l,x4);
             pol = pol + pol1;
         }
       }
 return(pol); 
}

/********************************************************************************
* This procedure checks that $a_{2e_i+e_j}$ and $a_{3e_i}$ satisfy Lemma 3.6    *   
********************************************************************************/
int Lemma3_6 (a2ij,a3i)
int a2ij,a3i;    
{
 if (a2ij>=2 && a3i==1) return (0);
 if (a2ij<=-1 && a3i==0) return (0);
 return (1);  
}

/********************************************************************************
* This procedure checks that $a_{3e_i}$ and $a_{2e_i}$ satisfy Lemma 3.7        *   
********************************************************************************/
int Lemma3_7 (a3i,a2i)
int a3i,a2i;
{
 if (a3i==1 && a2i>3) return (0);
 if (a3i==0 && a2i<0) return (0);
 return (1);
}

/*******************************************************************************
* This procedure outs the nozero coefficients  of $g|U_t$                      *
********************************************************************************/
void WritePolynomialA (K,a)
int  K[40][5];
int a[4][4][4][4];
{
 int n;
 
 for (n=1;n<=num_coef[t];n++){
   if (a[K[n][1]][K[n][2]][K[n][3]][K[n][4]]!=0){
      fprintf (fsal," a%d%d%d%d=",K[n][1],K[n][2],K[n][3],K[n][4]);
      fprintf (fsal,"%2d",a[K[n][1]][K[n][2]][K[n][3]][K[n][4]]);
   }
 }
 fprintf (fsal,"\n");
}
/*******************************/

/*****************************************************************************
* This procedure writes the possible values of the coefficients of $g|U_j$   *
*****************************************************************************/
          
void WritePossibleCoeffient(K,b,bb,tt)
int  K[40][5];
REb b[4][4][4][4];
REbb bb[5][5];
int tt;
{
 int n,i,cota;
 int aux1,aux2;
 int aux;

 if (num_coef[tt]==9) aux = 7;
 if (num_coef[tt]==19) aux = 13;
 if (num_coef[tt]==34) aux = 22;

 for (n=1;n<=aux;n++){
    fprintf (fsal,"a[%d][%d][%d][%d]   ",K[n][1],K[n][2],K[n][3],K[n][4]);
    if (tt!=0 || n!=num_aijkl){
      cota = b[K[n][1]][K[n][2]][K[n][3]][K[n][4]].cota;
      for (i=0;i<=cota;i++)
        fprintf (fsal,"%3d",b[K[n][1]][K[n][2]][K[n][3]][K[n][4]].v[i]);
      fprintf (fsal,"\n");
    }
    else{
      fprintf (fsal,"%3d",term_aijkl);
      fprintf (fsal,"\n");
    
    }
 }
 for (n=(aux+1);n<=num_coef[tt];n++){
     for (i=1;i<=4;i++){
       if (K[n][i]==1) aux1 = i;
       if (K[n][i]==2) aux2 = i;
     }
    if (aux1<aux2){
       fprintf (fsal,"(a[%d][%d][%d][%d],\n",K[n][1],K[n][2],K[n][3],K[n][4]);
       fprintf (fsal,"a");
       for (i=1;i<=4;i++){
          if (i==aux1) fprintf (fsal,"[2]");
          if (i==aux2) fprintf (fsal,"[1]");
          if (i!=aux1 && i!=aux2)  fprintf (fsal,"[0]"); 
       }
           fprintf (fsal,")    "); 
       if (tt!=0 || n!=num_aijkl){
          for (i=0;i<=bb[aux1][aux2].cota;i++)
          fprintf (fsal,"(%2d%2d)",bb[aux1][aux2].f[i],bb[aux1][aux2].s[i]);
          fprintf (fsal,"\n");
       }
       else{
          fprintf (fsal,"(%2d%2d)",bb[aux1][aux2].f[num_aijkl],bb[aux1][aux2].s[num_aijkl]);
          fprintf (fsal,"\n");
 
       }              
    }
 }
}
/*******************************/



/********************************************************************************
*  This procedure generates the array K                                         * 
********************************************************************************/

void GenerateCoefficient (ii,K,tt)
int ii[5];
int K[40][5];
int tt;
{
 int i,j,l,k,suma;
 int w,jj[5];
 int c2,c1,c;
 int m;

 
 num_coef[tt] = 0; 
 for (m=0;m<=1;m++)
 for (w=1;w<=3;w++){ 
   for (l=0;l<=3*ii[4];l++)
     for (k=0;k<=3*ii[3];k++)
       for (j=0;j<=3*ii[2];j++)
         for (i=0;i<=3*ii[1];i++){

          jj[1]= i*ii[1]; jj[2] = j*ii[2]; jj[3]=k*ii[3]; jj[4]=l*ii[4];
          suma =  jj[1]+ jj[2]+ jj[3]+ jj[4];
          if (suma==w){
            if (suma==3 && (jj[1]==2 || jj[2]==2 || jj[3]==2 || jj[4]==2)){
               if (m==1){
                  c1 = c2 = 0;
                  for (c=1;c<=4;c++){
                     if (jj[c]==1) c1 = c;
                     if (jj[c]==2) c2 = c;
                  }
                  if (c1!=0 && c2!=0){
                     num_coef[tt]++;
                     memcpy(K[num_coef[tt]],jj,5*sizeof(int));
                  }
               }
            }
            else{
               if (m==0){
                  num_coef[tt]++;
                  memcpy(K[num_coef[tt]],jj,5*sizeof(int));
               }
            }
          }
        }
  }
}
/*********************************/

/*********************************************************************************
*  This procedure checks to see if there are $x \not= y$ such that               *
*  $g|U_t(x) = g|U_j(y)$ for $j<t$                                               *
*                                                                                *   
*********************************************************************************/


/********************************************************************************
*  This procedure stores images of the polynomials $g|U_$ for $j<t$             *   
********************************************************************************/
void CheckPolynomialA(I,a,w)
int I[7][5];
int a[7][4][4][4][4]; 
int w;
{
 REGISTRO datos; 
 int v1,v2,v3,v4; 
 int i,j;
 
 for (j=0;j<t;j++){
   for (v1=0;v1<=(w*I[j][1]);v1++)
     for (v2=0;v2<=(w*I[j][2]);v2++)
       for (v3=0;v3<=(w*I[j][3]);v3++)
         for (v4=0;v4<=(w*I[j][4]);v4++){
           if ((v1+v2+v3+v4)==w){
              datos.x[0] = v1;
              datos.x[1] = v2;
              datos.x[2] = v3;    
              datos.x[3] = v4;
              datos.imagen = poly(v1,v2,v3,v4,a[j]);
              search(datos,&arbImagen);
           }
      }
 }
}
/***************************/

/*********************************************************************************
*  This procedure checks to see if $g$ satisfies inequality (2) and if $g_{$ is  *
*  a polynomial inyective                                                        *   
*********************************************************************************/
int CheckPolynomial(I,a,NOTWO)
int I[7][5];
int a[7][4][4][4][4];
int *NOTWO;
{   
 REGISTRO datos; 
 int w,v1,v2,v3,v4; 
 int maximo,SEARCH;
 int i;

 for (w=2;w<=top;w++){
   maximo = coef_bi(w);
   libera_mem_arbolImagen(arbImagen);
   arbImagen = NULL;
   if (t>0){ 
      CheckPolynomialA(I,a,w);
   }
   for (v1=0;v1<=(w*I[t][1]);v1++)
      for (v2=0;v2<=(w*I[t][2]);v2++)
        for (v3=0;v3<=(w*I[t][3]);v3++)
          for (v4=0;v4<=(w*I[t][4]);v4++)
            if ((v1+v2+v3+v4)==w){
               datos.x[0] = v1;
               datos.x[1] = v2;
               datos.x[2] = v3;
               datos.x[3] = v4;       
               datos.imagen = poly(v1,v2,v3,v4,a[t]);

/*  checking  injectivity of the polynomials    */
               SEARCH = search(datos,&arbImagen);
               if (SEARCH==0 || 0>datos.imagen || datos.imagen>maximo){
/*  checking  inequality (2)   */
                 if (0>datos.imagen||datos.imagen>maximo){
                    (*NOTWO)++; 
                 }
                 return (0);
               }
            }
 }           
 return (1);
}


int FindIndex(K,n,j1,j2)
int  K[7][40][5];
int n;
int *j1,*j2;
{
 int i,j;
 
 if (t==0){
    *j1 = *j2 = -1; return (0);
 }
 for (i=0;i<t;i++){
   for (j=1;j<=num_coef[i];j++){
     if (K[t][n][1]==K[i][j][1] && K[t][n][2]==K[i][j][2] &&
         K[t][n][3]==K[i][j][3] && K[t][n][4]==K[i][j][4]){
         *j1 = i; 
         *j2 = j; 
         return (1);
     }
   }
 }
 return (0);
}                   

int valorK(K,b,a,n,f,i,j,dummy)
int K[7][40][5];
REb b[4][4][4][4];
int a[7][4][4][4][4];
int n,f;
int i,j;
int dummy;
{
 if (dummy==1){
    return (a[i][K[i][j][1]][K[i][j][2]][K[i][j][3]][K[i][j][4]]);
 }
 else{ 
    return ( b[K[t][n][1]][K[t][n][2]][K[t][n][3]][K[t][n][4]].v[f] );   
      
 }
}
/****************************/


/********************************************************************************
*                                                                               *
* This procedure generates the polynomials $g|U_t$ with U_t = <e_i,e_j,e_k,e_l> *
*                                                                               *
********************************************************************************/
int GeneratePolynomial4(Ka,I,a,b,bb)
int  Ka[7][40][5];
int I[7][5];
int a[7][4][4][4][4];
REb b[4][4][4][4];
REbb bb[5][5];
{
 int K[40][5];
 int i;
 int i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17,i18,i19,i20,i21,i22;
 int a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22;
 int i23,i24,i25,i26,i27,i28;
 int i29,i30,i31,i32,i33,i34;
 int a23,a24,a25,a26,a27,a28; 
 int a29,a30,a31,a32,a33,a34;
 int dummy[40];
 int j1,j2;
 int ci[40],cf[40];
 int TOTAL,OK,NOTWO;
 
 t++;
 if (t == R){
       t--;
       return (1);
  }

 TOTAL=OK=NOTWO = 0; 
 memcpy(K,Ka[t],40*5*sizeof(int));
 memset (a[t],0,4*4*4*4*sizeof(int));

 for (i=5;i<=22;i++){
    ci[i] =  0;
    cf[i] = b[K[i][1]][K[i][2]][K[i][3]][K[i][4]].cota;
 }
 for (i=23;i<=num_coef[t];i++){
    ci[i] = 0;
    cf[i] = bb[1][2].cota;
 }      

 if (t==0){
    if (num_aijkl==24) num_aijkl = 23;
    if (num_aijkl==27) num_aijkl = 25;
    if (num_aijkl==28) num_aijkl = 26;
    if (num_aijkl==32) num_aijkl = 29;
    if (num_aijkl==33) num_aijkl = 30;
    if (num_aijkl==34) num_aijkl = 31;
    ci[num_aijkl] = cf[num_aijkl] = term_aijkl;
 }      

 a[t][K[1][1]][K[1][2]][K[1][3]][K[1][4]] =
            b[K[1][1]][K[1][2]][K[1][3]][K[1][4]].v[0];
 a[t][K[2][1]][K[2][2]][K[2][3]][K[2][4]] =
             b[K[2][1]][K[2][2]][K[2][3]][K[2][4]].v[0];
 a[t][K[3][1]][K[3][2]][K[3][3]][K[3][4]] =
             b[K[3][1]][K[3][2]][K[3][3]][K[3][4]].v[0];
 a[t][K[4][1]][K[4][2]][K[4][3]][K[4][4]] =
            b[K[4][1]][K[4][2]][K[4][3]][K[4][4]].v[0];
                                                               
 

 dummy[5]=FindIndex(Ka,5,&j1,&j2);
 if (t!=0 && dummy[5])
   ci[5]=cf[5]=0;
 for (i5=ci[5];i5<=cf[5];i5++){
    a5=a[t][K[5][1]][K[5][2]][K[5][3]][K[5][4]]=
        valorK(Ka,b,a,5,i5,j1,j2,dummy[5]);
   dummy[6]=FindIndex(Ka,6,&j1,&j2);
   if (t!=0 && dummy[6])
     ci[6]=cf[6]=0;
   for (i6=ci[6];i6<=cf[6];i6++){
      a6=a[t][K[6][1]][K[6][2]][K[6][3]][K[6][4]]=
          valorK(Ka,b,a,6,i6,j1,j2,dummy[6]);
     dummy[7]=FindIndex(Ka,7,&j1,&j2);
     if (t!=0 && dummy[7])
       ci[7]=cf[7]=0;
     for (i7=ci[7];i7<=cf[7];i7++){
        a7=a[t][K[7][1]][K[7][2]][K[7][3]][K[7][4]]=
            valorK(Ka,b,a,7,i7,j1,j2,dummy[7]);
       dummy[8]=FindIndex(Ka,8,&j1,&j2);
       if (t!=0 && dummy[8])
         ci[8]=cf[8]=0;
       for (i8=ci[8];i8<=cf[8];i8++){
          a8=a[t][K[8][1]][K[8][2]][K[8][3]][K[8][4]]=
              valorK(Ka,b,a,8,i8,j1,j2,dummy[8]);
         dummy[9]=FindIndex(Ka,9,&j1,&j2);
         if (t!=0 && dummy[9])
           ci[9]=cf[9]=0;
         for (i9=ci[9];i9<=cf[9];i9++){
            a9=a[t][K[9][1]][K[9][2]][K[9][3]][K[9][4]]=
                valorK(Ka,b,a,9,i9,j1,j2,dummy[9]);
           dummy[10]=FindIndex(Ka,10,&j1,&j2);
           if (t!=0 && dummy[10])
             ci[10]=cf[10]=0;
           for (i10=ci[10];i10<=cf[10];i10++){
              a10=a[t][K[10][1]][K[10][2]][K[10][3]][K[10][4]]=
                  valorK(Ka,b,a,10,i10,j1,j2,dummy[10]);
             dummy[11]=FindIndex(Ka,11,&j1,&j2);
             if (t!=0 && dummy[11])
               ci[11]=cf[11]=0;
             for (i11=ci[11];i11<=cf[11];i11++){
                a11=a[t][K[11][1]][K[11][2]][K[11][3]][K[11][4]]=
                    valorK(Ka,b,a,11,i11,j1,j2,dummy[11]);
               dummy[12]=FindIndex(Ka,12,&j1,&j2);
               if (t!=0 && dummy[12])
                 ci[12]=cf[12]=0;
               for (i12=ci[12];i12<=cf[12];i12++){
                  a12=a[t][K[12][1]][K[12][2]][K[12][3]][K[12][4]]=
                      valorK(Ka,b,a,12,i12,j1,j2,dummy[12]);
                 dummy[13]=FindIndex(Ka,13,&j1,&j2);
                 if (t!=0 && dummy[13])
                   ci[13]=cf[13]=0;
                 for (i13=ci[13];i13<=cf[13];i13++){
                    a13=a[t][K[13][1]][K[13][2]][K[13][3]][K[13][4]]=
                        valorK(Ka,b,a,13,i13,j1,j2,dummy[13]);
                   dummy[14]=FindIndex(Ka,14,&j1,&j2);
                   if (t!=0 && dummy[14])
                     ci[14]=cf[14]=0;
                   for (i14=ci[14];i14<=cf[14];i14++){
                      a14=a[t][K[14][1]][K[14][2]][K[14][3]][K[14][4]]=
                          valorK(Ka,b,a,14,i14,j1,j2,dummy[14]);
                     dummy[15]=FindIndex(Ka,15,&j1,&j2);
                     if (t!=0 && dummy[15])
                       ci[15]=cf[15]=0;
                     for (i15=ci[15];i15<=cf[15];i15++){
                        a15=a[t][K[15][1]][K[15][2]][K[15][3]][K[15][4]]=
                            valorK(Ka,b,a,15,i15,j1,j2,dummy[15]);
                       dummy[16]=FindIndex(Ka,16,&j1,&j2);
                       if (t!=0 && dummy[16])
                         ci[16]=cf[16]=0;
                       for (i16=ci[16];i16<=cf[16];i16++){
                          a16=a[t][K[16][1]][K[16][2]][K[16][3]][K[16][4]]=
                              valorK(Ka,b,a,16,i16,j1,j2,dummy[16]);
                         dummy[17]=FindIndex(Ka,17,&j1,&j2);
                         if (t!=0 && dummy[17])
                           ci[17]=cf[17]=0;
                         for (i17=ci[17];i17<=cf[17];i17++){
                            a17=a[t][K[17][1]][K[17][2]][K[17][3]][K[17][4]]=
                                valorK(Ka,b,a,17,i17,j1,j2,dummy[17]);
                           dummy[18]=FindIndex(Ka,18,&j1,&j2);
                           if (t!=0 && dummy[18])
                             ci[18]=cf[18]=0;
                           for (i18=ci[18];i18<=cf[18];i18++){
                              a18=a[t][K[18][1]][K[18][2]][K[18][3]][K[18][4]]=
                                  valorK(Ka,b,a,18,i18,j1,j2,dummy[18]);
                             dummy[19]=FindIndex(Ka,19,&j1,&j2);
                             if (t!=0 && dummy[19])
                               ci[19]=cf[19]=0;
                             for (i19=ci[19];i19<=cf[19];i19++){
                                a19=a[t][K[19][1]][K[19][2]][K[19][3]][K[19][4]]=
                                    valorK(Ka,b,a,19,i19,j1,j2,dummy[19]);
                               dummy[20]=FindIndex(Ka,20,&j1,&j2);
                               if (t!=0 && dummy[20])
                                 ci[20]=cf[20]=0;
                               for (i20=ci[20];i20<=cf[20];i20++){
                                  a20=a[t][K[20][1]][K[20][2]][K[20][3]][K[20][4]]=
                                      valorK(Ka,b,a,20,i20,j1,j2,dummy[20]);
                                 dummy[21]=FindIndex(Ka,21,&j1,&j2);
                                 if (t!=0 && dummy[21])
                                   ci[21]=cf[21]=0;
                                 for (i21=ci[21];i21<=cf[21];i21++){
                                    a21=a[t][K[21][1]][K[21][2]][K[21][3]][K[21][4]]=
                                        valorK(Ka,b,a,21,i21,j1,j2,dummy[21]);
                                   dummy[22]=FindIndex(Ka,22,&j1,&j2);
                                   if (t!=0 && dummy[22])
                                     ci[22]=cf[22]=0;
                                   for (i22=ci[22];i22<=cf[22];i22++){
                                      a22=a[t][K[22][1]][K[22][2]][K[22][3]][K[22][4]]=
                                          valorK(Ka,b,a,22,i22,j1,j2,dummy[22]);


 dummy[23]=FindIndex(Ka,23,&j1,&j2);
 if (t!=0 && dummy[23])
   ci[23]=cf[23]=0;
 for (i23=ci[23];i23<=cf[23];i23++){
    if (dummy[23]){
      a23=a[t][K[23][1]][K[23][2]][K[23][3]][K[23][4]]=
          valorK(Ka,b,a,23,i23,j1,j2,dummy[23]);
       dummy[24]=FindIndex(Ka,24,&j1,&j2);
      a24=a[t][K[24][1]][K[24][2]][K[24][3]][K[24][4]]=
          valorK(Ka,b,a,24,i24,j1,j2,dummy[24]);
    }
    else{
      a23=a[t][K[23][1]][K[23][2]][K[23][3]][K[23][4]]= bb[1][2].f[i23];
      a24=a[t][K[24][1]][K[24][2]][K[24][3]][K[24][4]]= bb[1][2].s[i23];
    }
   dummy[25]=FindIndex(Ka,25,&j1,&j2);
   if (t!=0 && dummy[25])
     ci[25]=cf[25]=0;
   for (i25=ci[25];i25<=cf[25];i25++){
      if (dummy[25]){
        a25=a[t][K[25][1]][K[25][2]][K[25][3]][K[25][4]]=
            valorK(Ka,b,a,25,i25,j1,j2,dummy[25]);
         dummy[27]=FindIndex(Ka,27,&j1,&j2);
        a27=a[t][K[27][1]][K[27][2]][K[27][3]][K[27][4]]=
            valorK(Ka,b,a,27,i27,j1,j2,dummy[27]);
      }
      else{
        a25=a[t][K[25][1]][K[25][2]][K[25][3]][K[25][4]]= bb[1][2].f[i25];
        a27=a[t][K[27][1]][K[27][2]][K[27][3]][K[27][4]]= bb[1][2].s[i25];
      }
     dummy[26]=FindIndex(Ka,26,&j1,&j2);
     if (t!=0 && dummy[26])
       ci[26]=cf[26]=0;
     for (i26=ci[26];i26<=cf[26];i26++){
        if (dummy[26]){
          a26=a[t][K[26][1]][K[26][2]][K[26][3]][K[26][4]]=
              valorK(Ka,b,a,26,i26,j1,j2,dummy[26]);
           dummy[28]=FindIndex(Ka,28,&j1,&j2);
          a28=a[t][K[28][1]][K[28][2]][K[28][3]][K[28][4]]=
              valorK(Ka,b,a,28,i28,j1,j2,dummy[28]);
        }
        else{
          a26=a[t][K[26][1]][K[26][2]][K[26][3]][K[26][4]]= bb[1][2].f[i26];
          a28=a[t][K[28][1]][K[28][2]][K[28][3]][K[28][4]]= bb[1][2].s[i26];
        }
       dummy[29]=FindIndex(Ka,29,&j1,&j2);
       if (t!=0 && dummy[29])
         ci[29]=cf[29]=0;
       for (i29=ci[29];i29<=cf[29];i29++){
          if (dummy[29]){
            a29=a[t][K[29][1]][K[29][2]][K[29][3]][K[29][4]]=
                valorK(Ka,b,a,29,i29,j1,j2,dummy[29]);
             dummy[32]=FindIndex(Ka,32,&j1,&j2);
            a32=a[t][K[32][1]][K[32][2]][K[32][3]][K[32][4]]=
                valorK(Ka,b,a,32,i32,j1,j2,dummy[32]);
          }
          else{
            a29=a[t][K[29][1]][K[29][2]][K[29][3]][K[29][4]]= bb[1][2].f[i29];
            a32=a[t][K[32][1]][K[32][2]][K[32][3]][K[32][4]]= bb[1][2].s[i29];
          }
         dummy[30]=FindIndex(Ka,30,&j1,&j2);
         if (t!=0 && dummy[30])
           ci[30]=cf[30]=0;
         for (i30=ci[30];i30<=cf[30];i30++){
            if (dummy[30]){
              a30=a[t][K[30][1]][K[30][2]][K[30][3]][K[30][4]]=
                  valorK(Ka,b,a,30,i30,j1,j2,dummy[30]);
               dummy[33]=FindIndex(Ka,33,&j1,&j2);
              a33=a[t][K[33][1]][K[33][2]][K[33][3]][K[33][4]]=
                  valorK(Ka,b,a,33,i33,j1,j2,dummy[33]);
            }
            else{
              a30=a[t][K[30][1]][K[30][2]][K[30][3]][K[30][4]]= bb[1][2].f[i30];
              a33=a[t][K[33][1]][K[33][2]][K[33][3]][K[33][4]]= bb[1][2].s[i30];
            }
           dummy[31]=FindIndex(Ka,31,&j1,&j2);
           if (t!=0 && dummy[31])
             ci[31]=cf[31]=0;
           for (i31=ci[31];i31<=cf[31];i31++){
              if (dummy[31]){
                a31=a[t][K[31][1]][K[31][2]][K[31][3]][K[31][4]]=
                    valorK(Ka,b,a,31,i31,j1,j2,dummy[31]);
                 dummy[34]=FindIndex(Ka,34,&j1,&j2);
                a34=a[t][K[34][1]][K[34][2]][K[34][3]][K[34][4]]=
                    valorK(Ka,b,a,34,i34,j1,j2,dummy[34]);
              }
              else{
                a31=a[t][K[31][1]][K[31][2]][K[31][3]][K[31][4]]= bb[1][2].f[i31];
                a34=a[t][K[34][1]][K[34][2]][K[34][3]][K[31][4]]= bb[1][2].s[i31];
              }
                TOTAL++;
                if (CheckPolynomial(I,a,&NOTWO)){  
                    NUM_POL[t]++;
                    OK++;
                    WritePolynomial (Ka[t],a[t]);   
                }

           }
         }
       }
     }
   }
 }
/*================================================================*/

                                   }
                                 }
                               }
                             }
                           }
                         }
                       }
                     }
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
 }
 fprintf (fsal,"(%3d)%10d%10d%10d%10d\n",t,TOTAL,(TOTAL-NOTWO-OK),NOTWO,OK);
 t--;
 return (0);
}
/*************************/

/********************************************************************************
*                                                                               *
* This procedure generates the polynomials $g|U_t$ with U_t = <e_i,e_j,e_k>     *                                                      *
*                                                                               *
********************************************************************************/

int GeneratePolynomial3(Ka,I,a,b,bb)
int  Ka[7][40][5];
int I[7][5];
int a[7][4][4][4][4]; 
REb b[4][4][4][4];
REbb bb[5][5];
{
 int K[40][5]; 
 int i;
 int i4,i5,i6,i7,i8,i9,i10,i11,i12,i13;
 int a4,a5,a6,a7,a8,a9,a10,a11,a12,a13;  
 int i14,i15,i16,i17,i18,i19;
 int a14,a15,a16,a17,a18,a19;
 int dummy[40];
 int j1,j2;
 int ci[40],cf[40];
 int TOTAL,OK,NOTWO; 

 t++;
 if (t == R){
       t--;  
       return (1);
  }


 TOTAL=OK=NOTWO = 0;
 memcpy(K,Ka[t],40*5*sizeof(int));
 memset (a[t],0,4*4*4*4*sizeof(int));

 for (i=4;i<=13;i++){
    ci[i] =  0;
    cf[i] = b[K[i][1]][K[i][2]][K[i][3]][K[i][4]].cota; 
 }            
 for (i=14;i<=num_coef[t];i++){
    ci[i] = 0;
    cf[i] = bb[1][2].cota;
 }
 if (t==0){
    if (num_aijkl==15) num_aijkl = 14;
    if (num_aijkl==18) num_aijkl = 16;
    if (num_aijkl==19) num_aijkl = 17;
    ci[num_aijkl] = cf[num_aijkl] = term_aijkl;
 }

/********************************************************************************
* For each coefficient $a_{ijkl}$ of the polynomial $g|U_1$ we have             *
*                                                                               *
* (i)  $aijkl = c_h$, if $(i,j,k,l) = (i_h,j_h,k_h,l_h)$ (parameter)            *
* (ii) $aijkl$ runs over possible values for this coefficient, otherwise        *
*                                                                               *
********************************************************************************/
 
/********************************************************************************
* For each coefficient $a_{ijkl}$ of the polynomial $g|U_t$ (t>1) we have       *
*                                                                               *
* (i) $a_{ijkl} =  d$, if $(i,j,k,l)$ is the index of the coefficient $d$ of    *
*                                                 the polynomial $g|U_{t-1}$    *
* (ii) aijkl runs over possible values for this coefficient, otherwise          *
*                                                                               *
********************************************************************************/     


 a[t][K[1][1]][K[1][2]][K[1][3]][K[1][4]] =
            b[K[1][1]][K[1][2]][K[1][3]][K[1][4]].v[0];
 a[t][K[2][1]][K[2][2]][K[2][3]][K[2][4]] =
             b[K[2][1]][K[2][2]][K[2][3]][K[2][4]].v[0];  
 a[t][K[3][1]][K[3][2]][K[3][3]][K[3][4]] =
             b[K[3][1]][K[3][2]][K[3][3]][K[3][4]].v[0];  


    dummy[4]=FindIndex(Ka,4,&j1,&j2);
    if (t!=0 && dummy[4])
      ci[4]=cf[4]=0;
    for (i4=ci[4];i4<=cf[4];i4++){
       a4=a[t][K[4][1]][K[4][2]][K[4][3]][K[4][4]]=
           valorK(Ka,b,a,4,i4,j1,j2,dummy[4]);
      dummy[5]=FindIndex(Ka,5,&j1,&j2);
      if (t!=0 && dummy[5])
        ci[5]=cf[5]=0;
      for (i5=ci[5];i5<=cf[5];i5++){
         a5=a[t][K[5][1]][K[5][2]][K[5][3]][K[5][4]]=
             valorK(Ka,b,a,5,i5,j1,j2,dummy[5]);
        dummy[6]=FindIndex(Ka,6,&j1,&j2);
        if (t==2) fprintf (fsal,"dummy[6]= %d\n",dummy[6]);
        if (t!=0 && dummy[6])
          ci[6]=cf[6]=0;
        for (i6=ci[6];i6<=cf[6];i6++){
           a6=a[t][K[6][1]][K[6][2]][K[6][3]][K[6][4]]=
               valorK(Ka,b,a,6,i6,j1,j2,dummy[6]);
        if (t==2) fprintf (fsal,"i6 = %d a6 = %d\n",i6,a6);
          dummy[7]=FindIndex(Ka,7,&j1,&j2);
          if (t!=0 && dummy[7])
            ci[7]=cf[7]=0;
          for (i7=ci[7];i7<=cf[7];i7++){
             a7=a[t][K[7][1]][K[7][2]][K[7][3]][K[7][4]]=
                 valorK(Ka,b,a,7,i7,j1,j2,dummy[7]);
            dummy[8]=FindIndex(Ka,8,&j1,&j2);
            if (t!=0 && dummy[8])
              ci[8]=cf[8]=0;
            for (i8=ci[8];i8<=cf[8];i8++){
               a8=a[t][K[8][1]][K[8][2]][K[8][3]][K[8][4]]=
                   valorK(Ka,b,a,8,i8,j1,j2,dummy[8]);
              dummy[9]=FindIndex(Ka,9,&j1,&j2);
              if (t!=0 && dummy[9])
                ci[9]=cf[9]=0;
              for (i9=ci[9];i9<=cf[9];i9++){
                 a9=a[t][K[9][1]][K[9][2]][K[9][3]][K[9][4]]=
                     valorK(Ka,b,a,9,i9,j1,j2,dummy[9]);
                dummy[10]=FindIndex(Ka,10,&j1,&j2);
                if (t!=0 && dummy[10])
                  ci[10]=cf[10]=0;
                for (i10=ci[10];i10<=cf[10];i10++){
                   a10=a[t][K[10][1]][K[10][2]][K[10][3]][K[10][4]]=
                       valorK(Ka,b,a,10,i10,j1,j2,dummy[10]);
                  dummy[11]=FindIndex(Ka,11,&j1,&j2);
                  if (t!=0 && dummy[11])
                    ci[11]=cf[11]=0;
                  for (i11=ci[11];i11<=cf[11];i11++){
                     a11=a[t][K[11][1]][K[11][2]][K[11][3]][K[11][4]]=
                         valorK(Ka,b,a,11,i11,j1,j2,dummy[11]);
                    dummy[12]=FindIndex(Ka,12,&j1,&j2);
                    if (t!=0 && dummy[12])
                      ci[12]=cf[12]=0;
                    for (i12=ci[12];i12<=cf[12];i12++){
                       a12=a[t][K[12][1]][K[12][2]][K[12][3]][K[12][4]]=
                           valorK(Ka,b,a,12,i12,j1,j2,dummy[12]);
                      dummy[13]=FindIndex(Ka,13,&j1,&j2);
                      if (t!=0 && dummy[13])
                        ci[13]=cf[13]=0;
                      for (i13=ci[13];i13<=cf[13];i13++){
                         a13=a[t][K[13][1]][K[13][2]][K[13][3]][K[13][4]]=
                             valorK(Ka,b,a,13,i13,j1,j2,dummy[13]);


 dummy[14]=FindIndex(Ka,14,&j1,&j2);
 if (t!=0 && dummy[14])
   ci[14]=cf[14]=0;
 for (i14=ci[14];i14<=cf[14];i14++){
    if (dummy[14]){
      a14=a[t][K[14][1]][K[14][2]][K[14][3]][K[14][4]]=
          valorK(Ka,b,a,14,i14,j1,j2,dummy[14]);
       dummy[15]=FindIndex(Ka,15,&j1,&j2);
      a15=a[t][K[15][1]][K[15][2]][K[15][3]][K[15][4]]=
          valorK(Ka,b,a,15,i15,j1,j2,dummy[15]);
    }
    else{
      a14=a[t][K[14][1]][K[14][2]][K[14][3]][K[14][4]]= bb[1][2].f[i14];
      a15=a[t][K[15][1]][K[15][2]][K[15][3]][K[15][4]]= bb[1][2].s[i14];
    }
   dummy[16]=FindIndex(Ka,16,&j1,&j2);
   if (t!=0 && dummy[16])
     ci[16]=cf[16]=0;
   for (i16=ci[16];i16<=cf[16];i16++){
      if (dummy[16]){
        a16=a[t][K[16][1]][K[16][2]][K[16][3]][K[16][4]]=
            valorK(Ka,b,a,16,i16,j1,j2,dummy[16]);
         dummy[18]=FindIndex(Ka,18,&j1,&j2);
        a18=a[t][K[18][1]][K[18][2]][K[18][3]][K[18][4]]=
            valorK(Ka,b,a,18,i18,j1,j2,dummy[18]);
      }
      else{
        a16=a[t][K[16][1]][K[16][2]][K[16][3]][K[16][4]]= bb[1][2].f[i16];
        a18=a[t][K[18][1]][K[18][2]][K[18][3]][K[18][4]]= bb[1][2].s[i16];
      }
     dummy[17]=FindIndex(Ka,17,&j1,&j2);
     if (t!=0 && dummy[17])
       ci[17]=cf[17]=0;
     for (i17=ci[17];i17<=cf[17];i17++){
        if (dummy[17]){
          a17=a[t][K[17][1]][K[17][2]][K[17][3]][K[17][4]]=
              valorK(Ka,b,a,17,i17,j1,j2,dummy[17]);
           dummy[19]=FindIndex(Ka,19,&j1,&j2);
          a19=a[t][K[19][1]][K[19][2]][K[19][3]][K[19][4]]=
              valorK(Ka,b,a,19,i19,j1,j2,dummy[19]);
        }
        else{
          a17=a[t][K[17][1]][K[17][2]][K[17][3]][K[17][4]]= bb[1][2].f[i17];
          a19=a[t][K[19][1]][K[19][2]][K[19][3]][K[19][4]]= bb[1][2].s[i17];
        }

                        if (Lemma3_6(a14,a10) && Lemma3_6(a15,a11) && Lemma3_6(a16,a10))  
                        if (Lemma3_6(a17,a11) && Lemma3_6(a18,a13) && Lemma3_6(a19,a13))  
                        if (Lemma3_7(a10,a4) && Lemma3_7(a11,a6) && Lemma3_7(a13,a9)){
                           TOTAL++;   
                           if (CheckPolynomial(I,a,&NOTWO)){  
                               NUM_POL[t]++;
                               OK++;
                               WritePolynomial (Ka[t],a[t]);      
                               if (t==4){
                                    GeneratePolynomial4(Ka,I,a,b,bb);
                               }                    
                                
                           }
 }
 }
 }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
 fprintf (fsal,"(%3d)%10d%10d%10d%10d\n",t,TOTAL,(TOTAL-NOTWO-OK),NOTWO,OK);
 t--;
 return (0);
}
/*******************************/

/********************************************************************************
*                                                                               *
* This procedure generates the polynomials $g|U_t$ with U_t = <e_i,e_j>         *
*                                                                               *
********************************************************************************/
int GeneratePolynomial2(Ka,I,a,b,bb)
int  Ka[7][40][5];
int I[7][5];
int a[7][4][4][4][4]; 
REb b[4][4][4][4];
REbb bb[5][5];
{
 int K[40][5]; 
 int i;
 int i3,i4,i5,i6,i7,i8;
 int a3,a5,a6,a7,a8,a9;
 int dummy[20];
 int j1,j2;
 int ci[40],cf[40];
 int TOTAL,OK,NOTWO; 

 t++;
 if (t == R){
       t--;  
       return (1);
  }

 TOTAL=OK=NOTWO = 0;
 memcpy(K,Ka[t],40*5*sizeof(int));
 memset (a[t],0,4*4*4*4*sizeof(int));
 
 if (num_aijkl==9) num_aijkl=8;


 for (i=3;i<=7;i++){
     ci[i] =  0;
     cf[i] = b[K[i][1]][K[i][2]][K[i][3]][K[i][4]].cota; 
 }            
 ci[8] = 0;
 cf[8] = bb[1][2].cota;

 if (t==0){
    ci[num_aijkl] =  cf[num_aijkl] = term_aijkl;
 }

/********************************************************************************
* For each coefficient $a_{ijkl}$ of the polynomial $g|U_1$ we have             *
*                                                                               *
* (i)  $aijkl = c_h$, if $(i,j,k,l) = (i_h,j_h,k_h,l_h)$ (parameter)            *
* (ii) $aijkl$ runs over possible values for this coefficient, otherwise        *
*                                                                               *
********************************************************************************/ 

/********************************************************************************
* For each coefficient $a_{ijkl}$ of the polynomial $g|U_t$ (t>1) we have       *
*                                                                               *
* (i) $a_{ijkl} =  d$, if $(i,j,k,l)$ is the index of the coefficient $d$ of    *
*                                                 the polynomial $g|U_{t-1}$    *
* (ii) aijkl runs over possible values for this coefficient, otherwise          *
*                                                                               *
********************************************************************************/ 

 for (i8=ci[8];i8<=cf[8];i8++){
    a8=a[t][K[8][1]][K[8][2]][K[8][3]][K[8][4]] =  bb[1][2].f[i8];
    a9=a[t][K[9][1]][K[9][2]][K[9][3]][K[9][4]] =  bb[1][2].s[i8];

      a[t][K[1][1]][K[1][2]][K[1][3]][K[1][4]] =
            b[K[1][1]][K[1][2]][K[1][3]][K[1][4]].v[0];
      a[t][K[2][1]][K[2][2]][K[2][3]][K[2][4]] =
             b[K[2][1]][K[2][2]][K[2][3]][K[2][4]].v[0];  
    
          dummy[3] = FindIndex(Ka,3,&j1,&j2);
          if (t!=0 && dummy[3])
              ci[3] = cf[3] = 0;
          for (i3=ci[3];i3<=cf[3];i3++){
              a3=a[t][K[3][1]][K[3][2]][K[3][3]][K[3][4]] = 
                                 valorK(Ka,b,a,3,i3,j1,j2,dummy[3]);
             dummy[4] = FindIndex(Ka,4,&j1,&j2);
             if (t!=0 && dummy[4])
                 ci[4] = cf[4] = 0;
             for (i4=ci[4];i4<=cf[4];i4++){
                   a[t][K[4][1]][K[4][2]][K[4][3]][K[4][4]] = 
                       b[K[4][1]][K[4][2]][K[4][3]][K[4][4]].v[i4]; 
                dummy[5] = FindIndex(Ka,5,&j1,&j2);
                if (t!=0 && dummy[5])
                     ci[5] = cf[5] = 0;
                for (i5=ci[5];i5<=cf[5];i5++){
                   a5=a[t][K[5][1]][K[5][2]][K[5][3]][K[5][4]] = 
                                      valorK(Ka,b,a,5,i5,j1,j2,dummy[5]);  
                   dummy[6] = FindIndex(Ka,6,&j1,&j2);
                   if (t!=0 && dummy[6])
                        ci[6] = cf[6] = 0;
                   for (i6=ci[6];i6<=cf[6];i6++){
                      a6= a[t][K[6][1]][K[6][2]][K[6][3]][K[6][4]] = 
                                         valorK(Ka,b,a,6,i6,j1,j2,dummy[6]);  
                      dummy[7] = FindIndex(Ka,7,&j1,&j2);
                      if (t!=0 && dummy[7])
                          ci[7] = cf[7] = 0;
                       for (i7=ci[7];i7<=cf[7];i7++){
                          a7=a[t][K[7][1]][K[7][2]][K[7][3]][K[7][4]] =
                                             valorK(Ka,b,a,7,i7,j1,j2,dummy[7]);  

                         if (Lemma3_6(a8,a6) && Lemma3_6(a9,a7))
                            if (Lemma3_7(a6,a3) && Lemma3_7(a7,a5)) {
                               TOTAL++;
                               if (CheckPolynomial(I,a,&NOTWO)){
                                  NUM_POL[t]++;
                                  OK++;
                                  WritePolynomial (Ka[t],a[t]);      
                                  if (t==3){
                                    GeneratePolynomial3(Ka,I,a,b,bb); 
                                  }
                                  if (t<=2){
                                    GeneratePolynomial2(Ka,I,a,b,bb);
                                  }
                               }
                            }
                       }
                   }
                }
             } 
          }
 }
 fprintf (fsal,"(%3d)%10d%10d%10d%10d\n",t,TOTAL,(TOTAL-NOTWO-OK),NOTWO,OK);
 t--;
 return (0);
}
/*******************************/

/********************************************************************************
*                                                                               *
*  This Prucedure  reads the parameters of a process from                       *
*  file ParameterTable.H (H=2,...,15)                                           *
*                                                                               *
********************************************************************************/
void ReadParameter(Ka,I,a,b,bb,aIJ)
int  Ka[7][40][5];
int  I[7][5];
int  a[7][4][4][4][4]; 
REb  b[4][4][4][4];
REbb bb[5][5];
AIJ  aIJ[7]; 
{
 char rengEnt[100];
 int d1,d2,d3,d4;
 int i,j,p; 


 /* Reading  parameter $S$ */
 fscanf(finput,"%d", &S);         
 fgets(rengEnt, 100, finput);                  
 if (S>2){ 
    fprintf (stderr,"Error, S<3 \n");     
    exit (5);
 }

 for (j=1;j<=S;j++){
   for (i=1;i<=4;i++){ 
      /* Reading parameters $(i_1,j_1,k_1,l_1),...,$(i_s,j_s,k_s,l_s) */
      fscanf(finput,"%2d", &ijkl[i]);  
   }
 }
 fgets(rengEnt, 100, finput);                  

 for (j=1;j<=S;j++){
   /* Reading  parameters $c_1, ..., c_s$  */
   fscanf(finput,"%2d", &C[j]);  
 }
 fgets(rengEnt, 100, finput);                  


 /* Reading parameter $R$   */
 fscanf(finput,"%d", &R);   
 fgets(rengEnt, 100, finput);                  

 memset (I,0,7*5*sizeof(int));
 for (i=0;i<R;i++){
   /* Reading indexes $i_t,j_t,k_t,l_t$ of sets $U_t=<e_1_t,,..,,e_4_t>$, $t=0,...,R-1$  */
   fscanf(finput,"%d %d %d %d", &d1,&d2,&d3,&d4); 
   fgets(rengEnt, 100, finput);                  
   aIJ[i].i = d1; aIJ[i].j =  d2; aIJ[i].k = d3; aIJ[i].l = d4;
   I[i][d1] = 1;  
   I[i][d2] = 1;  
   I[i][d3] = 1;  
   I[i][d4] = 1;  
 }
}
/*******************/

void Principal()
{
 int i,j,p;
 FILE *outset;
 char NamSet[100]; 
 

 REb   b[4][4][4][4]; /* possible values for the coefficient                        */
                      /*  a_ijkl (not=a_{2e_i+e_j}) are stored in                   */
                      /* b[i][j][k][l].v[0],...,b[i][j][k][l].v[b[i][j][k][l].cota] */
 
 REbb  bb[5][5]; /* possible values for the coefficients (a_{2e_i+e_j},a_{e_i+2e_j}) */
                 /* are stored in (bb[i][j].f[0], bb[i][j].s[0]),...,                */
                 /* (bb[i][j].f[(bb[i][j].cota], bb[i][j].s[bb[i][j].cota])          */
 
 int a[7][4][4][4][4]; /* the coefficient a_{ijkl} of the polynomial g|U_t          */
                       /* is stored in a[t][4][4][4][4]                             */  
 
 AIJ  aIJ[7];  /* Indexes $i_t,i_j,j_k,j_l$ of $U_t=<e_{i_t},e_{j_t},e_{k_t},e_{l_t}>$  */
               /* are stored in the i,j,k and l fields of the  structure  aIJ[t]        */ 
 
 int K[7][40][5];  /* the values for the coefficient of $g|U_j$ are stored     */
                   /* in the array K[j]                                           */

 int I[7][5];
 

 memset(NUM_POL,0,10*sizeof(int));
 memset(K,-1,7*40*5*sizeof(int));
 memset(a,-11,7*4*4*4*4*sizeof(int));        

 ReadParameter(K,I,a,b,bb,aIJ);

 AllowedValue(b,bb);                    

 for (i=0;i<R;i++){
   GenerateCoefficient (I[i],K[i],i);
 }

 for (i=1;i<=num_coef[0];i++){
   if (K[0][i][1]==ijkl[1] && K[0][i][2]==ijkl[2] && 
       K[0][i][3]==ijkl[3] && K[0][i][4]==ijkl[4]){
      num_aijkl = i;
      break;
   }
 }

 term_aijkl = -10;
 if (S==1){
   for (j=0;j<=b[K[0][i][1]][K[0][i][2]][K[0][i][3]][K[0][i][4]].cota;j++)
     if (b[K[0][i][1]][K[0][i][2]][K[0][i][3]][K[0][i][4]].v[j]==C[1]){
        term_aijkl = j;
        break;
     } 
 }
 else{
   for (j=0;j<=bb[1][2].cota;j++){
     if(bb[1][2].f[j]==C[1] && bb[1][2].s[j]==C[2]){
       term_aijkl = j;
       break;
     }
   }
 }

/********************************************************************************
* Checks for valid input                                                        *
********************************************************************************/
 if (term_aijkl == -10){
    printf("Error in the second row of the file %d\n", term_aijkl);
    exit (23);
 }
   
 fprintf (fsal,"Possible values of the coefficients of the polynomials for the  process  %d\n",NProc);
 for (i=0;i<R;i++){
  fprintf (fsal,"Coefficients    Possible Values\n");
   WritePossibleCoeffient(K[i],b,bb,i);
 }

 GeneratePolynomial2(K,I,a,b,bb);

/***************************************************************
* Writing the processes in file Table.nTable                   * 
***************************************************************/
 p = num_aijkl;   
 if (S==1)
    fprintf (ftabla,"a%d%d%d%d",K[0][p][1],K[0][p][2],K[0][p][3],K[0][p][4]);
 else{
   fprintf (ftabla,"(a%d%d%d%d,",K[0][8][1],K[0][8][2],K[0][8][3],K[0][8][4]);
   fprintf (ftabla,"a%d%d%d%d)",K[0][p][1],K[0][p][2],K[0][p][3],K[0][p][4]);
 }  
 
 fprintf (ftabla," ");
 for (i=0;i<R;i++){
  if(i<4) fprintf (ftabla,"%9d ",i+1);
  if(i==4) fprintf (ftabla,"%14d ",i+1);
   if (i!=(R-1))  fprintf (ftabla,",");
 }                                                                
 fprintf (ftabla,"\n");    
 if (S==1)
   fprintf (ftabla,"%5d",b[K[0][p][1]][K[0][p][2]][K[0][p][3]][K[0][p][4]].v[term_aijkl]);
  else
   fprintf (ftabla,"(%5d,%5d)",bb[1][2].f[term_aijkl],bb[1][2].s[term_aijkl]); 

 fprintf (ftabla," ");
 for (i=0;i<R;i++){
   if (i<4)
      fprintf (ftabla,"<e_%d, e_%d>",aIJ[i].i,aIJ[i].j);
   if (i==4) 
      fprintf (ftabla,"<e_%d, e_%d, e_%d>",aIJ[i].i,aIJ[i].j,aIJ[i].k);
   if (i==5) 
      fprintf (ftabla,"<e_%d, e_%d, e_%d, e_%d>",aIJ[i].i,aIJ[i].j,aIJ[i].k,aIJ[i].l);

   if (i!=(R-1))  fprintf (ftabla,",");
 }
 fprintf (ftabla,"\n");
 if (S==1)
   fprintf (ftabla,"      ");
 else
   fprintf (ftabla,"              ");       
 for (i=0;i<R;i++){
   if (i<4) fprintf (ftabla,"%9d ",NUM_POL[i]);
   if (i==4) fprintf (ftabla,"%14d ",NUM_POL[i]);
   if (i==5) fprintf (ftabla,"%19d ",NUM_POL[i]);
   if (i!=(R-1))  fprintf (ftabla,",");
 }
 fprintf (ftabla,"\n");  


 if (AUX[NProc][0]==1){
    for (j=0;j<(R-1);j++){
       sprintf(NamSet,"Process%dP_%dT%d.tex",NProc,(j+1),nTable);  
       outset = fopen (NamSet,"a");
       EndLatex(outset);
       fclose(outset);
    }
    sprintf(NamSet,"Process%dP_%dT%d.tex",NProc,R,nTable);
    outset = fopen (NamSet,"r");
   if (outset){
     fclose(outset);
     outset = fopen (NamSet,"a");
     EndLatex(outset);
     fclose(outset);
   }
 }

}
/***********************/


int main(argc, argv)
int argc;
char *argv[];
{
 char nomArchEnt[100],nomArchSal[100];   
 int i,j,aux;
 

  fprintf(stdout,"    Input File: ParameterTable.H, 1< H <16\n");
  fprintf(stdout,"    Enter number of  Table  ");
  fscanf (stdin, "%d",&nTable);
  if (nTable<2 || nTable>15){
   fprintf (stderr,"1< %d < 16 %d\n",nTable);
    exit(1);
  }
 
 sprintf(nomArchEnt,"ParameterTable.%d", nTable); 
 sprintf(nomArchSal,"Table.%d", nTable); 

  finput = fopen(nomArchEnt,"r");
  if (!finput) {
   fprintf (stderr,"Cannot open the file %s\n",nomArchEnt);
    exit(2);
  }       

 ftabla = fopen (nomArchSal,"w");

 if (!finput) {
   fprintf (stderr," Cannot open the file \n");
    exit(2);
  }        
 fsal = fopen ("salida","w");

 memset(AUX,0,10*7*sizeof(int));
 NProc = 1;

 t=-1;
 while (!feof(finput)){     
   Principal();
   aux = fgetc (finput);
   NProc++;  
   if (!feof(finput)) ungetc(aux, finput);
 }
 fclose (finput);
 fclose (fsal);
 fclose (ftabla);
 
 exit (5);
}



