bridge/class-master/depend/pari/src/basemath/alglin2.c
/* assume x a non-empty square t_MAT */
assume x a non-empty square t_MAT
assume x a non - empty square t_MAT
static GEN
RgM_hess(GEN x0, long prec)
{
  pari_sp av;
  long lx = lg(x0), bit = prec? 8 - bit_accuracy(prec): 0, m, i, j;
  GEN x;
  if (bit) x0 = RgM_shallowcopy(x0);
  av = avma; x = RgM_shallowcopy(x0);
  for (m=2; m<lx-1; m++)
  {
    GEN t = NULL;
    for (i=m+1; i<lx; i++)
    {
      t = gcoeff(x,i,m-1);
      if (!relative0(t, gcoeff(x0,i,m-1), bit)) break;
    }
    if (i == lx) continue;
    for (j=m-1; j<lx; j++) swap(gcoeff(x,i,j), gcoeff(x,m,j));
    swap(gel(x,i), gel(x,m));
    if (bit)
    {
      for (j=m-1; j<lx; j++) swap(gcoeff(x0,i,j), gcoeff(x0,m,j));
      swap(gel(x0,i), gel(x0,m));
    }
    t = ginv(t);
    for (i=m+1; i<lx; i++)
    {
      GEN c = gcoeff(x,i,m-1);
      if (gequal0(c)) continue;
      c = gmul(c,t); gcoeff(x,i,m-1) = gen_0;
      for (j=m; j<lx; j++)
        gcoeff(x,i,j) = gsub(gcoeff(x,i,j), gmul(c,gcoeff(x,m,j)));
      for (j=1; j<lx; j++)
        gcoeff(x,j,m) = gadd(gcoeff(x,j,m), gmul(c,gcoeff(x,j,i)));
      if (gc_needed(av,2))
      {
        if (DEBUGMEM>1) pari_warn(warnmem,"hess, m = %ld", m);
        gerepileall(av,2, &x, &t);
      }
    }
  }
  return x;
}
static GEN RgM_hess ( GEN x0 , long prec ) { pari_sp av ; long lx = lg ( x0 ) , bit = prec ? 8 - bit_accuracy ( prec ) : 0 , m , i , j ; GEN x ; if ( bit ) x0 = RgM_shallowcopy ( x0 ) ; av = avma ; x = RgM_shallowcopy ( x0 ) ; for ( m = 2 ; m < lx - 1 ; m ++ ) { GEN t = NULL ; for ( i = m + 1 ; i < lx ; i ++ ) { t = gcoeff ( x , i , m - 1 ) ; if ( ! relative0 ( t , gcoeff ( x0 , i , m - 1 ) , bit ) ) break ; } if ( i == lx ) continue ; for ( j = m - 1 ; j < lx ; j ++ ) swap ( gcoeff ( x , i , j ) , gcoeff ( x , m , j ) ) ; swap ( gel ( x , i ) , gel ( x , m ) ) ; if ( bit ) { for ( j = m - 1 ; j < lx ; j ++ ) swap ( gcoeff ( x0 , i , j ) , gcoeff ( x0 , m , j ) ) ; swap ( gel ( x0 , i ) , gel ( x0 , m ) ) ; } t = ginv ( t ) ; for ( i = m + 1 ; i < lx ; i ++ ) { GEN c = gcoeff ( x , i , m - 1 ) ; if ( gequal0 ( c ) ) continue ; c = gmul ( c , t ) ; gcoeff ( x , i , m - 1 ) = gen_0 ; for ( j = m ; j < lx ; j ++ ) gcoeff ( x , i , j ) = gsub ( gcoeff ( x , i , j ) , gmul ( c , gcoeff ( x , m , j ) ) ) ; for ( j = 1 ; j < lx ; j ++ ) gcoeff ( x , j , m ) = gadd ( gcoeff ( x , j , m ) , gmul ( c , gcoeff ( x , j , i ) ) ) ; if ( gc_needed ( av , 2 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " , m ) ; gerepileall ( av , 2 , & x , & t ) ; } } } return x ; }
assume x a non-empty square t_MAT
assume x a non - empty square t_MAT