bridge/class-master/depend/pari/src/basemath/qfisom.c
/* checks, whether the vector v[I] has the Bacher-polynomial pol  */
checks, whether the vector v[I] has the Bacher-polynomial pol
checks whether the vector v [ I ] has the Bacher - polynomial pol
static long
bachcomp(GEN pol, long I, GEN V, GEN W, GEN Fv)
{
  pari_sp av = avma;
  GEN co, list, listxy, vI;
  long i, j, k;
  long nlist, nxy, count;
  const long n = lg(V)-1, S = mael(W,I,1) / 2;
  long sum = mael(pol,1,1), mind = mael(pol,1,2), maxd = mael(pol,1,3);
  GEN coef = gel(pol,2);
  vI = gel(V,I);
  list = zero_Flv(sum);
  nlist = 0;
  for (i = 1; i <= n  &&  nlist <= sum; ++i)
  {
    if (mael(W,i,1) == mael(W,I,1))
    {
      long s = zv_dotproduct(vI, gel(Fv,i));
      if (s == S)
      {
        if (nlist < sum)
          list[nlist+1] = i;
        nlist++;
      }
      if (-s == S)
      {
        if (nlist < sum)
          list[nlist+1] = -i;
        nlist++;
      }
    }
  }
  if (nlist != sum)
  {
    avma=av; return 0;
  }
  if (nlist == 0) { avma=av; return 1; }
  listxy = cgetg(nlist+1,t_VECSMALL);
  co = zero_Flv(maxd - mind + 1);
  for (i = 1; i <= nlist; ++i)
  {
    long S1 = list[i] > 0 ? S : -S;
    for (j = 1; j <= nlist; ++j)
      listxy[j] = 0;
    nxy = 0;
    for (j = 1; j <= nlist; ++j)
    {
      long S2 = list[j] > 0 ? S1 : -S1;
      if (zv_dotproduct(gel(V,labs(list[i])), gel(Fv,labs(list[j]))) == S2)
        listxy[++nxy] = list[j];
    }
    count = 0;
    for (j = 1; j <= nxy  &&  count <= maxd; ++j)
    {
      long S1 = listxy[j] > 0 ? S : -S;
      for (k = j+1; k <= nxy  &&  count <= maxd; ++k)
      {
        long S2 = listxy[k] > 0 ? S1 : -S1;
        long lj = labs(listxy[j]), lk = labs(listxy[k]);
        if (zv_dotproduct(gel(V,lj), gel(Fv,lk)) == S2)
          count++;
      }
    }
    if (count < mind  ||  count > maxd  ||
        co[count-mind+1] >= coef[count-mind+1])
    {
      avma = av;
      return 0;
    }
    else
      co[count-mind+1]++;
  }
  avma = av;
  return 1;
}
static long bachcomp ( GEN pol , long I , GEN V , GEN W , GEN Fv ) { pari_sp av = avma ; GEN co , list , listxy , vI ; long i , j , k ; long nlist , nxy , count ; const long n = lg ( V ) - 1 , S = mael ( W , I , 1 ) / 2 ; long sum = mael ( pol , 1 , 1 ) , mind = mael ( pol , 1 , 2 ) , maxd = mael ( pol , 1 , 3 ) ; GEN coef = gel ( pol , 2 ) ; vI = gel ( V , I ) ; list = zero_Flv ( sum ) ; nlist = 0 ; for ( i = 1 ; i <= n && nlist <= sum ; ++ i ) { if ( mael ( W , i , 1 ) == mael ( W , I , 1 ) ) { long s = zv_dotproduct ( vI , gel ( Fv , i ) ) ; if ( s == S ) { if ( nlist < sum ) list [ nlist + 1 ] = i ; nlist ++ ; } if ( - s == S ) { if ( nlist < sum ) list [ nlist + 1 ] = - i ; nlist ++ ; } } } if ( nlist != sum ) { avma = av ; return 0 ; } if ( nlist == 0 ) { avma = av ; return 1 ; } listxy = cgetg ( nlist + 1 , t_VECSMALL ) ; co = zero_Flv ( maxd - mind + 1 ) ; for ( i = 1 ; i <= nlist ; ++ i ) { long S1 = list [ i ] > 0 ? S : - S ; for ( j = 1 ; j <= nlist ; ++ j ) listxy [ j ] = 0 ; nxy = 0 ; for ( j = 1 ; j <= nlist ; ++ j ) { long S2 = list [ j ] > 0 ? S1 : - S1 ; if ( zv_dotproduct ( gel ( V , labs ( list [ i ] ) ) , gel ( Fv , labs ( list [ j ] ) ) ) == S2 ) listxy [ ++ nxy ] = list [ j ] ; } count = 0 ; for ( j = 1 ; j <= nxy && count <= maxd ; ++ j ) { long S1 = listxy [ j ] > 0 ? S : - S ; for ( k = j + 1 ; k <= nxy && count <= maxd ; ++ k ) { long S2 = listxy [ k ] > 0 ? S1 : - S1 ; long lj = labs ( listxy [ j ] ) , lk = labs ( listxy [ k ] ) ; if ( zv_dotproduct ( gel ( V , lj ) , gel ( Fv , lk ) ) == S2 ) count ++ ; } } if ( count < mind || count > maxd || co [ count - mind + 1 ] >= coef [ count - mind + 1 ] ) { avma = av ; return 0 ; } else co [ count - mind + 1 ] ++ ; } avma = av ; return 1 ; }
checks, whether the vector v[I] has the Bacher-polynomial pol
checks whether the vector v [ I ] has the Bacher - polynomial pol
/* nlist should be equal to pol.sum */ /* the number of vectors with scalar product S is already different */ /* listxy is the list of the nxy vectors from list that have scalar product S
     with v[list[i]] */ /* count is the number of pairs */ /* if the number of pairs is smaller than pol.mind or larger than pol.maxd
       or if the coefficient of X^count becomes now larger than the one in pol,
       then the Bacher-polynomials can not be equal */ /* the Bacher-polynomials are equal */