bridge/class-master/depend/pari/src/basemath/base2.c
/* given bnf and a pseudo-basis of an order in HNF [A,I], tries to simplify
 * the HNF as much as possible. The resulting matrix will be upper triangular
 * but the diagonal coefficients will not be equal to 1. The ideals are
 * guaranteed to be integral and primitive. */
given bnf and a pseudo-basis of an order in HNF [A,I], tries to simplify
the HNF as much as possible. The resulting matrix will be upper triangular
but the diagonal coefficients will not be equal to 1. The ideals are
guaranteed to be integral and primitive.
given bnf and a pseudo - basis of an order in HNF [ A I ] tries to simplify the HNF as much as possible . The resulting matrix will be upper triangular but the diagonal coefficients will not be equal to 1 . The ideals are guaranteed to be integral and primitive .
GEN
rnfsimplifybasis(GEN bnf, GEN x)
{
  pari_sp av = avma;
  long i, l;
  GEN y, Az, Iz, nf, A, I;
  bnf = checkbnf(bnf); nf = bnf_get_nf(bnf);
  if (!is_pseudo_matrix(x)) pari_err_TYPE("rnfsimplifybasis",x);
  A = gel(x,1);
  I = gel(x,2); l = lg(I);
  y = cgetg(3, t_VEC);
  Az = cgetg(l, t_MAT); gel(y,1) = Az;
  Iz = cgetg(l, t_VEC); gel(y,2) = Iz;
  for (i = 1; i < l; i++)
  {
    GEN c, d;
    if (ideal_is1(gel(I,i))) {
      gel(Iz,i) = gen_1;
      gel(Az,i) = gel(A,i);
      continue;
    }
    gel(Iz,i) = Q_primitive_part(gel(I,i), &c);
    gel(Az,i) = c? RgC_Rg_mul(gel(A,i),c): gel(A,i);
    if (c && ideal_is1(gel(Iz,i))) continue;
    d = gen_if_principal(bnf, gel(Iz,i));
    if (d)
    {
      gel(Iz,i) = gen_1;
      gel(Az,i) = nfC_nf_mul(nf, gel(Az,i), d);
    }
  }
  return gerepilecopy(av, y);
}
GEN rnfsimplifybasis ( GEN bnf , GEN x ) { pari_sp av = avma ; long i , l ; GEN y , Az , Iz , nf , A , I ; bnf = checkbnf ( bnf ) ; nf = bnf_get_nf ( bnf ) ; if ( ! is_pseudo_matrix ( x ) ) pari_err_TYPE ( " " , x ) ; A = gel ( x , 1 ) ; I = gel ( x , 2 ) ; l = lg ( I ) ; y = cgetg ( 3 , t_VEC ) ; Az = cgetg ( l , t_MAT ) ; gel ( y , 1 ) = Az ; Iz = cgetg ( l , t_VEC ) ; gel ( y , 2 ) = Iz ; for ( i = 1 ; i < l ; i ++ ) { GEN c , d ; if ( ideal_is1 ( gel ( I , i ) ) ) { gel ( Iz , i ) = gen_1 ; gel ( Az , i ) = gel ( A , i ) ; continue ; } gel ( Iz , i ) = Q_primitive_part ( gel ( I , i ) , & c ) ; gel ( Az , i ) = c ? RgC_Rg_mul ( gel ( A , i ) , c ) : gel ( A , i ) ; if ( c && ideal_is1 ( gel ( Iz , i ) ) ) continue ; d = gen_if_principal ( bnf , gel ( Iz , i ) ) ; if ( d ) { gel ( Iz , i ) = gen_1 ; gel ( Az , i ) = nfC_nf_mul ( nf , gel ( Az , i ) , d ) ; } } return gerepilecopy ( av , y ) ; }
given bnf and a pseudo-basis of an order in HNF [A,I], tries to simplify
 the HNF as much as possible.
given bnf and a pseudo - basis of an order in HNF [ A I ] tries to simplify the HNF as much as possible .