bridge/class-master/depend/pari/src/basemath/base3.c
/* square of INTEGER (t_INT or ZC) x in nf */
square of INTEGER (t_INT or ZC) x in nf
square of INTEGER ( t_INT or ZC ) x in nf
GEN
nfsqri(GEN nf, GEN x)
{
  long i, j, k, N;
  GEN s, v, TAB = get_tab(nf, &N);
  if (typ(x) == t_INT) return sqri(x);
  v = cgetg(N+1,t_COL);
  for (k=1; k<=N; k++)
  {
    pari_sp av = avma;
    GEN TABi = TAB;
    if (k == 1)
      s = sqri(gel(x,1));
    else
      s = shifti(mulii(gel(x,1),gel(x,k)), 1);
    for (i=2; i<=N; i++)
    {
      GEN p1, c, t, xi = gel(x,i);
      TABi += N;
      if (!signe(xi)) continue;
      c = gcoeff(TABi, k, i);
      t = signe(c)? _mulii(c,xi): NULL;
      for (j=i+1; j<=N; j++)
      {
        c = gcoeff(TABi, k, j);
        if (!signe(c)) continue;
        p1 = _mulii(c, shifti(gel(x,j),1));
        t = t? addii(t, p1): p1;
      }
      if (t) s = addii(s, mulii(xi, t));
    }
    gel(v,k) = gerepileuptoint(av,s);
  }
  return v;
}
GEN nfsqri ( GEN nf , GEN x ) { long i , j , k , N ; GEN s , v , TAB = get_tab ( nf , & N ) ; if ( typ ( x ) == t_INT ) return sqri ( x ) ; v = cgetg ( N + 1 , t_COL ) ; for ( k = 1 ; k <= N ; k ++ ) { pari_sp av = avma ; GEN TABi = TAB ; if ( k == 1 ) s = sqri ( gel ( x , 1 ) ) ; else s = shifti ( mulii ( gel ( x , 1 ) , gel ( x , k ) ) , 1 ) ; for ( i = 2 ; i <= N ; i ++ ) { GEN p1 , c , t , xi = gel ( x , i ) ; TABi += N ; if ( ! signe ( xi ) ) continue ; c = gcoeff ( TABi , k , i ) ; t = signe ( c ) ? _mulii ( c , xi ) : NULL ; for ( j = i + 1 ; j <= N ; j ++ ) { c = gcoeff ( TABi , k , j ) ; if ( ! signe ( c ) ) continue ; p1 = _mulii ( c , shifti ( gel ( x , j ) , 1 ) ) ; t = t ? addii ( t , p1 ) : p1 ; } if ( t ) s = addii ( s , mulii ( xi , t ) ) ; } gel ( v , k ) = gerepileuptoint ( av , s ) ; } return v ; }
square of INTEGER (t_INT or ZC) x in nf
square of INTEGER ( t_INT or ZC ) x in nf