bridge/class-master/depend/pari/src/basemath/base2.c
/* Given bnf and either an order as output by rnfpseudobasis or a polynomial,
 * and outputs a basis if it is free, an n+1-generating set if it is not */
Given bnf and either an order as output by rnfpseudobasis or a polynomial,
and outputs a basis if it is free, an n+1-generating set if it is not
Given bnf and either an order as output by rnfpseudobasis or a polynomial and outputs a basis if it is free an n + 1 - generating set if it is not
GEN
rnfbasis(GEN bnf, GEN order)
{
  pari_sp av = avma;
  long j, n;
  GEN nf, A, I, cl, col, a;
  bnf = checkbnf(bnf); nf = bnf_get_nf(bnf);
  order = get_order(nf, order, "rnfbasis");
  I = gel(order,2); n = lg(I)-1;
  j=1; while (j<n && ideal_is1(gel(I,j))) j++;
  if (j<n)
  {
    order = rnfsteinitz(nf,order);
    I = gel(order,2);
  }
  A = gel(order,1);
  col= gel(A,n); A = vecslice(A, 1, n-1);
  cl = gel(I,n);
  a = gen_if_principal(bnf, cl);
  if (!a)
  {
    GEN v = idealtwoelt(nf, cl);
    A = shallowconcat(A, gmul(gel(v,1), col));
    a = gel(v,2);
  }
  A = shallowconcat(A, nfC_nf_mul(nf, col, a));
  return gerepilecopy(av, A);
}
GEN rnfbasis ( GEN bnf , GEN order ) { pari_sp av = avma ; long j , n ; GEN nf , A , I , cl , col , a ; bnf = checkbnf ( bnf ) ; nf = bnf_get_nf ( bnf ) ; order = get_order ( nf , order , " " ) ; I = gel ( order , 2 ) ; n = lg ( I ) - 1 ; j = 1 ; while ( j < n && ideal_is1 ( gel ( I , j ) ) ) j ++ ; if ( j < n ) { order = rnfsteinitz ( nf , order ) ; I = gel ( order , 2 ) ; } A = gel ( order , 1 ) ; col = gel ( A , n ) ; A = vecslice ( A , 1 , n - 1 ) ; cl = gel ( I , n ) ; a = gen_if_principal ( bnf , cl ) ; if ( ! a ) { GEN v = idealtwoelt ( nf , cl ) ; A = shallowconcat ( A , gmul ( gel ( v , 1 ) , col ) ) ; a = gel ( v , 2 ) ; } A = shallowconcat ( A , nfC_nf_mul ( nf , col , a ) ) ; return gerepilecopy ( av , A ) ; }
Given bnf and either an order as output by rnfpseudobasis or a polynomial,
 and outputs a basis if it is free, an n+1-generating set if it is not
Given bnf and either an order as output by rnfpseudobasis or a polynomial and outputs a basis if it is free an n + 1 - generating set if it is not