bridge/class-master/depend/pari/src/basemath/base5.c
/* Given a pseudo-basis x, outputs a multiple of its ideal determinant */
Given a pseudo-basis x, outputs a multiple of its ideal determinant
Given a pseudo - basis x outputs a multiple of its ideal determinant
GEN
nfdetint(GEN nf, GEN x)
{
  GEN pass,c,v,det1,piv,pivprec,vi,p1,A,I,id,idprod;
  long i, j, k, rg, n, m, m1, cm=0, N;
  pari_sp av = avma, av1;
  nf = checknf(nf); N = nf_get_degree(nf);
  check_ZKmodule(x, "nfdetint");
  A = gel(x,1);
  I = gel(x,2);
  n = lg(A)-1; if (!n) return gen_1;
  m1 = lgcols(A); m = m1-1;
  id = matid(N);
  c = new_chunk(m1); for (k=1; k<=m; k++) c[k] = 0;
  piv = pivprec = gen_1;
  av1 = avma;
  det1 = idprod = gen_0; 
  pass = cgetg(m1,t_MAT);
  v = cgetg(m1,t_COL);
  for (j=1; j<=m; j++)
  {
    gel(pass,j) = zerocol(m);
    gel(v,j) = gen_0; 
  }
  for (rg=0,k=1; k<=n; k++)
  {
    long t = 0;
    for (i=1; i<=m; i++)
      if (!c[i])
      {
        vi=nfmul(nf,piv,gcoeff(A,i,k));
        for (j=1; j<=m; j++)
          if (c[j]) vi=gadd(vi,nfmul(nf,gcoeff(pass,i,j),gcoeff(A,j,k)));
        gel(v,i) = vi; if (!t && !gequal0(vi)) t=i;
      }
    if (t)
    {
      pivprec = piv;
      if (rg == m-1)
      {
        if (!cm)
        {
          cm=1; idprod = id;
          for (i=1; i<=m; i++)
            if (i!=t)
              idprod = (idprod==id)? gel(I,c[i])
                                   : idealmul(nf,idprod,gel(I,c[i]));
        }
        p1 = idealmul(nf,gel(v,t),gel(I,k)); c[t]=0;
        det1 = (typ(det1)==t_INT)? p1: idealadd(nf,p1,det1);
      }
      else
      {
        rg++; piv=gel(v,t); c[t]=k;
        for (i=1; i<=m; i++)
          if (!c[i])
          {
            for (j=1; j<=m; j++)
              if (c[j] && j!=t)
              {
                p1 = gsub(nfmul(nf,piv,gcoeff(pass,i,j)),
                          nfmul(nf,gel(v,i),gcoeff(pass,t,j)));
                gcoeff(pass,i,j) = rg>1? nfdiv(nf,p1,pivprec)
                                       : p1;
              }
            gcoeff(pass,i,t) = gneg(gel(v,i));
          }
      }
    }
    if (gc_needed(av1,1))
    {
      if(DEBUGMEM>1) pari_warn(warnmem,"nfdetint");
      gerepileall(av1,6, &det1,&piv,&pivprec,&pass,&v,&idprod);
    }
  }
  if (!cm) { avma = av; return cgetg(1,t_MAT); }
  return gerepileupto(av, idealmul(nf,idprod,det1));
}
GEN nfdetint ( GEN nf , GEN x ) { GEN pass , c , v , det1 , piv , pivprec , vi , p1 , A , I , id , idprod ; long i , j , k , rg , n , m , m1 , cm = 0 , N ; pari_sp av = avma , av1 ; nf = checknf ( nf ) ; N = nf_get_degree ( nf ) ; check_ZKmodule ( x , " " ) ; A = gel ( x , 1 ) ; I = gel ( x , 2 ) ; n = lg ( A ) - 1 ; if ( ! n ) return gen_1 ; m1 = lgcols ( A ) ; m = m1 - 1 ; id = matid ( N ) ; c = new_chunk ( m1 ) ; for ( k = 1 ; k <= m ; k ++ ) c [ k ] = 0 ; piv = pivprec = gen_1 ; av1 = avma ; det1 = idprod = gen_0 ; pass = cgetg ( m1 , t_MAT ) ; v = cgetg ( m1 , t_COL ) ; for ( j = 1 ; j <= m ; j ++ ) { gel ( pass , j ) = zerocol ( m ) ; gel ( v , j ) = gen_0 ; } for ( rg = 0 , k = 1 ; k <= n ; k ++ ) { long t = 0 ; for ( i = 1 ; i <= m ; i ++ ) if ( ! c [ i ] ) { vi = nfmul ( nf , piv , gcoeff ( A , i , k ) ) ; for ( j = 1 ; j <= m ; j ++ ) if ( c [ j ] ) vi = gadd ( vi , nfmul ( nf , gcoeff ( pass , i , j ) , gcoeff ( A , j , k ) ) ) ; gel ( v , i ) = vi ; if ( ! t && ! gequal0 ( vi ) ) t = i ; } if ( t ) { pivprec = piv ; if ( rg == m - 1 ) { if ( ! cm ) { cm = 1 ; idprod = id ; for ( i = 1 ; i <= m ; i ++ ) if ( i != t ) idprod = ( idprod == id ) ? gel ( I , c [ i ] ) : idealmul ( nf , idprod , gel ( I , c [ i ] ) ) ; } p1 = idealmul ( nf , gel ( v , t ) , gel ( I , k ) ) ; c [ t ] = 0 ; det1 = ( typ ( det1 ) == t_INT ) ? p1 : idealadd ( nf , p1 , det1 ) ; } else { rg ++ ; piv = gel ( v , t ) ; c [ t ] = k ; for ( i = 1 ; i <= m ; i ++ ) if ( ! c [ i ] ) { for ( j = 1 ; j <= m ; j ++ ) if ( c [ j ] && j != t ) { p1 = gsub ( nfmul ( nf , piv , gcoeff ( pass , i , j ) ) , nfmul ( nf , gel ( v , i ) , gcoeff ( pass , t , j ) ) ) ; gcoeff ( pass , i , j ) = rg > 1 ? nfdiv ( nf , p1 , pivprec ) : p1 ; } gcoeff ( pass , i , t ) = gneg ( gel ( v , i ) ) ; } } } if ( gc_needed ( av1 , 1 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " ) ; gerepileall ( av1 , 6 , & det1 , & piv , & pivprec , & pass , & v , & idprod ) ; } } if ( ! cm ) { avma = av ; return cgetg ( 1 , t_MAT ) ; } return gerepileupto ( av , idealmul ( nf , idprod , det1 ) ) ; }
Given a pseudo-basis x, outputs a multiple of its ideal determinant
Given a pseudo - basis x outputs a multiple of its ideal determinant
/* dummy for gerepileall */ /* dummy */