bridge/class-master/depend/pari/src/basemath/base3.c
/* number of distinct roots of sigma(f) */
number of distinct roots of sigma(f)
number of distinct roots of sigma ( f )
GEN
nfpolsturm(GEN nf, GEN f, GEN ind0)
{
  pari_sp av = avma;
  long d, l, r1, single;
  GEN ind, u, v, vr1, T, s, t;
  nf = checknf(nf); T = nf_get_pol(nf); r1 = nf_get_r1(nf);
  ind = parse_embed(ind0, r1, "nfpolsturm");
  single = ind0 && typ(ind0) == t_INT;
  l = lg(ind);
  if (gequal0(f)) pari_err_ROOTS0("nfpolsturm");
  if (typ(f) == t_POL && varn(f) != varn(T))
  {
    f = RgX_nffix("nfsturn", T, f,1);
    if (lg(f) == 3) f = NULL;
  }
  else
  {
    (void)Rg_nffix("nfpolsturm", T, f, 0);
    f = NULL;
  }
  if (!f) { avma = av; return single? gen_0: zerovec(l-1); }
  d = degpol(f);
  if (d == 1) { avma = av; return single? gen_1: const_vec(l-1,gen_1); }
  vr1 = const_vecsmall(l-1, 1);
  u = Q_primpart(f); s = ZV_to_zv(nfeltsign(nf, gel(u,d+2), ind));
  v = RgX_deriv(u); t = odd(d)? leafcopy(s): zv_neg(s);
  for(;;)
  {
    GEN r = RgX_neg( Q_primpart(RgX_pseudorem(u, v)) ), sr;
    long i, dr = degpol(r);
    if (dr < 0) break;
    sr = ZV_to_zv(nfeltsign(nf, gel(r,dr+2), ind));
    for (i = 1; i < l; i++)
      if (sr[i] != s[i]) { s[i] = sr[i], vr1[i]--; }
    if (odd(dr)) sr = zv_neg(sr);
    for (i = 1; i < l; i++)
      if (sr[i] != t[i]) { t[i] = sr[i], vr1[i]++; }
    if (!dr) break;
    u = v; v = r;
  }
  if (single) { avma = av; return stoi(vr1[1]); }
  return gerepileupto(av, zv_to_ZV(vr1));
}
GEN nfpolsturm ( GEN nf , GEN f , GEN ind0 ) { pari_sp av = avma ; long d , l , r1 , single ; GEN ind , u , v , vr1 , T , s , t ; nf = checknf ( nf ) ; T = nf_get_pol ( nf ) ; r1 = nf_get_r1 ( nf ) ; ind = parse_embed ( ind0 , r1 , " " ) ; single = ind0 && typ ( ind0 ) == t_INT ; l = lg ( ind ) ; if ( gequal0 ( f ) ) pari_err_ROOTS0 ( " " ) ; if ( typ ( f ) == t_POL && varn ( f ) != varn ( T ) ) { f = RgX_nffix ( " " , T , f , 1 ) ; if ( lg ( f ) == 3 ) f = NULL ; } else { ( void ) Rg_nffix ( " " , T , f , 0 ) ; f = NULL ; } if ( ! f ) { avma = av ; return single ? gen_0 : zerovec ( l - 1 ) ; } d = degpol ( f ) ; if ( d == 1 ) { avma = av ; return single ? gen_1 : const_vec ( l - 1 , gen_1 ) ; } vr1 = const_vecsmall ( l - 1 , 1 ) ; u = Q_primpart ( f ) ; s = ZV_to_zv ( nfeltsign ( nf , gel ( u , d + 2 ) , ind ) ) ; v = RgX_deriv ( u ) ; t = odd ( d ) ? leafcopy ( s ) : zv_neg ( s ) ; for ( ; ; ) { GEN r = RgX_neg ( Q_primpart ( RgX_pseudorem ( u , v ) ) ) , sr ; long i , dr = degpol ( r ) ; if ( dr < 0 ) break ; sr = ZV_to_zv ( nfeltsign ( nf , gel ( r , dr + 2 ) , ind ) ) ; for ( i = 1 ; i < l ; i ++ ) if ( sr [ i ] != s [ i ] ) { s [ i ] = sr [ i ] , vr1 [ i ] -- ; } if ( odd ( dr ) ) sr = zv_neg ( sr ) ; for ( i = 1 ; i < l ; i ++ ) if ( sr [ i ] != t [ i ] ) { t [ i ] = sr [ i ] , vr1 [ i ] ++ ; } if ( ! dr ) break ; u = v ; v = r ; } if ( single ) { avma = av ; return stoi ( vr1 [ 1 ] ) ; } return gerepileupto ( av , zv_to_ZV ( vr1 ) ) ; }
number of distinct roots of sigma(f)
number of distinct roots of sigma ( f )