bridge/class-master/depend/pari/src/basemath/alglin1.c
/*******************************************************************/
/*                                                                 */
/*                    KERNEL of an m x n matrix                    */
/*          return n - rk(x) linearly independent vectors          */
/*                                                                 */
/*******************************************************************/
KERNEL of an m x n matrix
return n - rk(x) linearly independent vectors
KERNEL of an m x n matrix return n - rk ( x ) linearly independent vectors
static GEN
RgM_deplin_i(GEN x0)
{
  pari_sp av = avma, av2;
  long i, j, k, nl, nc = lg(x0)-1;
  GEN D, x, y, c, l, d, ck;
  if (!nc) { avma=av; return NULL; }
  nl = nbrows(x0);
  c = zero_zv(nl);
  l = cgetg(nc+1, t_VECSMALL); 
  av2 = avma;
  x = RgM_shallowcopy(x0);
  d = const_vec(nl, gen_1); 
  ck = NULL; 
  for (k=1; k<=nc; k++)
  {
    ck = gel(x,k);
    for (j=1; j<k; j++)
    {
      GEN cj = gel(x,j), piv = gel(d,j), q = gel(ck,l[j]);
      for (i=1; i<=nl; i++)
        if (i!=l[j]) gel(ck,i) = gsub(gmul(piv, gel(ck,i)), gmul(q, gel(cj,i)));
    }
    i = gauss_get_pivot_NZ(x, NULL, k, c);
    if (i > nl) break;
    if (gc_needed(av,1))
    {
      if (DEBUGMEM>1) pari_warn(warnmem,"deplin k = %ld/%ld",k,nc);
      gerepileall(av2, 2, &x, &d);
      ck = gel(x,k);
    }
    gel(d,k) = gel(ck,i);
    c[i] = k; l[k] = i; 
  }
  if (k > nc) { avma = av; return NULL; }
  if (k == 1) { avma = av; return scalarcol_shallow(gen_1,nc); }
  y = cgetg(nc+1,t_COL);
  gel(y,1) = gcopy(gel(ck, l[1]));
  for (D=gel(d,1),j=2; j<k; j++)
  {
    gel(y,j) = gmul(gel(ck, l[j]), D);
    D = gmul(D, gel(d,j));
  }
  gel(y,j) = gneg(D);
  for (j++; j<=nc; j++) gel(y,j) = gen_0;
  y = primitive_part(y, &c);
  return c? gerepileupto(av, y): gerepilecopy(av, y);
}
static GEN RgM_deplin_i ( GEN x0 ) { pari_sp av = avma , av2 ; long i , j , k , nl , nc = lg ( x0 ) - 1 ; GEN D , x , y , c , l , d , ck ; if ( ! nc ) { avma = av ; return NULL ; } nl = nbrows ( x0 ) ; c = zero_zv ( nl ) ; l = cgetg ( nc + 1 , t_VECSMALL ) ; av2 = avma ; x = RgM_shallowcopy ( x0 ) ; d = const_vec ( nl , gen_1 ) ; ck = NULL ; for ( k = 1 ; k <= nc ; k ++ ) { ck = gel ( x , k ) ; for ( j = 1 ; j < k ; j ++ ) { GEN cj = gel ( x , j ) , piv = gel ( d , j ) , q = gel ( ck , l [ j ] ) ; for ( i = 1 ; i <= nl ; i ++ ) if ( i != l [ j ] ) gel ( ck , i ) = gsub ( gmul ( piv , gel ( ck , i ) ) , gmul ( q , gel ( cj , i ) ) ) ; } i = gauss_get_pivot_NZ ( x , NULL , k , c ) ; if ( i > nl ) break ; if ( gc_needed ( av , 1 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " , k , nc ) ; gerepileall ( av2 , 2 , & x , & d ) ; ck = gel ( x , k ) ; } gel ( d , k ) = gel ( ck , i ) ; c [ i ] = k ; l [ k ] = i ; } if ( k > nc ) { avma = av ; return NULL ; } if ( k == 1 ) { avma = av ; return scalarcol_shallow ( gen_1 , nc ) ; } y = cgetg ( nc + 1 , t_COL ) ; gel ( y , 1 ) = gcopy ( gel ( ck , l [ 1 ] ) ) ; for ( D = gel ( d , 1 ) , j = 2 ; j < k ; j ++ ) { gel ( y , j ) = gmul ( gel ( ck , l [ j ] ) , D ) ; D = gmul ( D , gel ( d , j ) ) ; } gel ( y , j ) = gneg ( D ) ; for ( j ++ ; j <= nc ; j ++ ) gel ( y , j ) = gen_0 ; y = primitive_part ( y , & c ) ; return c ? gerepileupto ( av , y ) : gerepilecopy ( av , y ) ; }
KERNEL of an m x n matrix
return n - rk(x) linearly independent vectors
KERNEL of an m x n matrix return n - rk ( x ) linearly independent vectors
/* not initialized */ /* pivot list */ /* gcc -Wall */ /* pivot d[k] in x[i,k] */