bridge/class-master/depend/pari/src/basemath/alglin1.c
/* Assumes a a square t_MAT of dimension n > 0. Returns det(a) using
 * Gauss-Bareiss. */
Assumes a a square t_MAT of dimension n > 0.
Assumes a a square t_MAT of dimension n > 0 .
static GEN
det_bareiss(GEN a)
{
  pari_sp av = avma;
  long nbco = lg(a)-1,i,j,k,s = 1;
  GEN p, pprec;
  a = RgM_shallowcopy(a);
  for (pprec=gen_1,i=1; i<nbco; i++,pprec=p)
  {
    int diveuc = (gequal1(pprec)==0);
    GEN ci;
    p = gcoeff(a,i,i);
    if (gequal0(p))
    {
      k=i+1; while (k<=nbco && gequal0(gcoeff(a,i,k))) k++;
      if (k>nbco) return gerepilecopy(av, p);
      swap(gel(a,k), gel(a,i)); s = -s;
      p = gcoeff(a,i,i);
    }
    ci = gel(a,i);
    for (k=i+1; k<=nbco; k++)
    {
      GEN ck = gel(a,k), m = gel(ck,i);
      if (gequal0(m))
      {
        if (gequal1(p))
        {
          if (diveuc)
            gel(a,k) = gdiv(gel(a,k), pprec);
        }
        else
          for (j=i+1; j<=nbco; j++)
          {
            GEN p1 = gmul(p, gel(ck,j));
            if (diveuc) p1 = gdiv(p1,pprec);
            gel(ck,j) = p1;
          }
      }
      else
        for (j=i+1; j<=nbco; j++)
        {
          pari_sp av2 = avma;
          GEN p1 = gsub(gmul(p,gel(ck,j)), gmul(m,gel(ci,j)));
          if (diveuc) p1 = gdiv(p1,pprec);
          gel(ck,j) = gerepileupto(av2, p1);
        }
      if (gc_needed(av,2))
      {
        if(DEBUGMEM>1) pari_warn(warnmem,"det. col = %ld",i);
        gerepileall(av,2, &a,&pprec);
        ci = gel(a,i);
        p = gcoeff(a,i,i);
      }
    }
  }
  p = gcoeff(a,nbco,nbco);
  p = (s < 0)? gneg(p): gcopy(p);
  return gerepileupto(av, p);
}
static GEN det_bareiss ( GEN a ) { pari_sp av = avma ; long nbco = lg ( a ) - 1 , i , j , k , s = 1 ; GEN p , pprec ; a = RgM_shallowcopy ( a ) ; for ( pprec = gen_1 , i = 1 ; i < nbco ; i ++ , pprec = p ) { int diveuc = ( gequal1 ( pprec ) == 0 ) ; GEN ci ; p = gcoeff ( a , i , i ) ; if ( gequal0 ( p ) ) { k = i + 1 ; while ( k <= nbco && gequal0 ( gcoeff ( a , i , k ) ) ) k ++ ; if ( k > nbco ) return gerepilecopy ( av , p ) ; swap ( gel ( a , k ) , gel ( a , i ) ) ; s = - s ; p = gcoeff ( a , i , i ) ; } ci = gel ( a , i ) ; for ( k = i + 1 ; k <= nbco ; k ++ ) { GEN ck = gel ( a , k ) , m = gel ( ck , i ) ; if ( gequal0 ( m ) ) { if ( gequal1 ( p ) ) { if ( diveuc ) gel ( a , k ) = gdiv ( gel ( a , k ) , pprec ) ; } else for ( j = i + 1 ; j <= nbco ; j ++ ) { GEN p1 = gmul ( p , gel ( ck , j ) ) ; if ( diveuc ) p1 = gdiv ( p1 , pprec ) ; gel ( ck , j ) = p1 ; } } else for ( j = i + 1 ; j <= nbco ; j ++ ) { pari_sp av2 = avma ; GEN p1 = gsub ( gmul ( p , gel ( ck , j ) ) , gmul ( m , gel ( ci , j ) ) ) ; if ( diveuc ) p1 = gdiv ( p1 , pprec ) ; gel ( ck , j ) = gerepileupto ( av2 , p1 ) ; } if ( gc_needed ( av , 2 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " , i ) ; gerepileall ( av , 2 , & a , & pprec ) ; ci = gel ( a , i ) ; p = gcoeff ( a , i , i ) ; } } } p = gcoeff ( a , nbco , nbco ) ; p = ( s < 0 ) ? gneg ( p ) : gcopy ( p ) ; return gerepileupto ( av , p ) ; }
Assumes a a square t_MAT of dimension n > 0.
Assumes a a square t_MAT of dimension n > 0 .