bridge/class-master/depend/pari/src/basemath/alglin1.c
/* a square t_MAT, 'bound' a rough upper bound for the number of
 * multiplications we are willing to pay while developing rows/columns before
 * switching to Gaussian elimination */
a square t_MAT, 'bound' a rough upper bound for the number of
multiplications we are willing to pay while developing rows/columns before
switching to Gaussian elimination
a square t_MAT ' bound ' a rough upper bound for the number of multiplications we are willing to pay while developing rows / columns before switching to Gaussian elimination
static GEN
det_develop(GEN M, long max, double bound)
{
  pari_sp av = avma;
  long i,j, n = lg(M)-1, lbest = max+2, best_col = 0, best_row = 0;
  GEN best = NULL;
  if (bound < 1.) return det_bareiss(M); 
  switch(n)
  {
    case 0: return gen_1;
    case 1: return gcopy(gcoeff(M,1,1));
    case 2: return RgM_det2(M);
  }
  if (max > ((n+2)>>1)) max = (n+2)>>1;
  for (j = 1; j <= n; j++)
  {
    pari_sp av2 = avma;
    GEN v = col_count_non_zero(M, j, max);
    long lv;
    if (!v || (lv = lg(v)) >= lbest) { avma = av2; continue; }
    if (lv == 1) { avma = av; return gen_0; }
    if (lv == 2) {
      avma = av;
      return gerepileupto(av, coeff_det(M,v[1],j,max,bound));
    }
    best = v; lbest = lv; best_col = j;
  }
  for (i = 1; i <= n; i++)
  {
    pari_sp av2 = avma;
    GEN v = row_count_non_zero(M, i, max);
    long lv;
    if (!v || (lv = lg(v)) >= lbest) { avma = av2; continue; }
    if (lv == 1) { avma = av; return gen_0; }
    if (lv == 2) {
      avma = av;
      return gerepileupto(av, coeff_det(M,i,v[1],max,bound));
    }
    best = v; lbest = lv; best_row = i;
  }
  if (best_row)
  {
    double d = lbest-1;
    GEN s = NULL;
    long k;
    bound /= d*d*d;
    for (k = 1; k < lbest; k++)
    {
      GEN c = coeff_det(M, best_row, best[k], max, bound);
      s = s? gadd(s, c): c;
    }
    return gerepileupto(av, s);
  }
  if (best_col)
  {
    double d = lbest-1;
    GEN s = NULL;
    long k;
    bound /= d*d*d;
    for (k = 1; k < lbest; k++)
    {
      GEN c = coeff_det(M, best[k], best_col, max, bound);
      s = s? gadd(s, c): c;
    }
    return gerepileupto(av, s);
  }
  return det_bareiss(M);
}
static GEN det_develop ( GEN M , long max , double bound ) { pari_sp av = avma ; long i , j , n = lg ( M ) - 1 , lbest = max + 2 , best_col = 0 , best_row = 0 ; GEN best = NULL ; if ( bound < 1. ) return det_bareiss ( M ) ; switch ( n ) { case 0 : return gen_1 ; case 1 : return gcopy ( gcoeff ( M , 1 , 1 ) ) ; case 2 : return RgM_det2 ( M ) ; } if ( max > ( ( n + 2 ) >> 1 ) ) max = ( n + 2 ) >> 1 ; for ( j = 1 ; j <= n ; j ++ ) { pari_sp av2 = avma ; GEN v = col_count_non_zero ( M , j , max ) ; long lv ; if ( ! v || ( lv = lg ( v ) ) >= lbest ) { avma = av2 ; continue ; } if ( lv == 1 ) { avma = av ; return gen_0 ; } if ( lv == 2 ) { avma = av ; return gerepileupto ( av , coeff_det ( M , v [ 1 ] , j , max , bound ) ) ; } best = v ; lbest = lv ; best_col = j ; } for ( i = 1 ; i <= n ; i ++ ) { pari_sp av2 = avma ; GEN v = row_count_non_zero ( M , i , max ) ; long lv ; if ( ! v || ( lv = lg ( v ) ) >= lbest ) { avma = av2 ; continue ; } if ( lv == 1 ) { avma = av ; return gen_0 ; } if ( lv == 2 ) { avma = av ; return gerepileupto ( av , coeff_det ( M , i , v [ 1 ] , max , bound ) ) ; } best = v ; lbest = lv ; best_row = i ; } if ( best_row ) { double d = lbest - 1 ; GEN s = NULL ; long k ; bound /= d * d * d ; for ( k = 1 ; k < lbest ; k ++ ) { GEN c = coeff_det ( M , best_row , best [ k ] , max , bound ) ; s = s ? gadd ( s , c ) : c ; } return gerepileupto ( av , s ) ; } if ( best_col ) { double d = lbest - 1 ; GEN s = NULL ; long k ; bound /= d * d * d ; for ( k = 1 ; k < lbest ; k ++ ) { GEN c = coeff_det ( M , best [ k ] , best_col , max , bound ) ; s = s ? gadd ( s , c ) : c ; } return gerepileupto ( av , s ) ; } return det_bareiss ( M ) ; }
a square t_MAT, 'bound' a rough upper bound for the number of
 multiplications we are willing to pay while developing rows/columns before
 switching to Gaussian elimination
a square t_MAT ' bound ' a rough upper bound for the number of multiplications we are willing to pay while developing rows / columns before switching to Gaussian elimination
/* too costly now */