bridge/class-master/depend/pari/src/basemath/volcano.c
/* This is Sutherland 2009 Algorithm Ascend (p12) */
This is Sutherland 2009 Algorithm Ascend (p12)
This is Sutherland 2009 Algorithm Ascend ( p12 )
ulong
ascend_volcano(GEN phi, ulong j, ulong p, ulong pi, long level, long L,
  long depth, long steps)
{
  pari_sp ltop = avma, av;
  GEN path_g = cgetg(depth + 2, t_VECSMALL);
  ulong *path = zv_to_ulongptr(path_g);
  long max_len = depth - level;
  int first_iter = 1;
  if (steps <= 0 || max_len < 0) pari_err_BUG("ascend_volcano: bad params");
  av = avma;
  while (steps--)
  {
    GEN nhbr_pol = first_iter? Flm_Fl_polmodular_evalx(phi, L, j, p, pi)
                             : nhbr_polynomial(path+1, phi, p, pi, L);
    GEN nhbrs = Flx_roots(nhbr_pol, p);
    long nhbrs_len = lg(nhbrs)-1, i;
    pari_sp btop = avma;
    path[0] = j;
    first_iter = 0;
    j = nhbrs[nhbrs_len];
    for (i = 1; i < nhbrs_len; i++)
    {
      ulong next_j = nhbrs[i], last_j;
      long len;
      if (is_j_exceptional(next_j, p))
      {
        if (steps)
          pari_err_BUG("ascend_volcano: Got to the top with more steps to go!");
        j = next_j; break;
      }
      path[1] = next_j;
      len = extend_path(path, phi, p, pi, L, max_len);
      last_j = path[len];
      if (len == max_len
          && (is_j_exceptional(last_j, p)
              || node_degree(phi, L, last_j, p, pi) > 1)) { j = next_j; break; }
      avma = btop;
    }
    path[1] = j; 
    max_len++; avma = av;
  }
  avma = ltop; return j;
}
ulong ascend_volcano ( GEN phi , ulong j , ulong p , ulong pi , long level , long L , long depth , long steps ) { pari_sp ltop = avma , av ; GEN path_g = cgetg ( depth + 2 , t_VECSMALL ) ; ulong * path = zv_to_ulongptr ( path_g ) ; long max_len = depth - level ; int first_iter = 1 ; if ( steps <= 0 || max_len < 0 ) pari_err_BUG ( " " ) ; av = avma ; while ( steps -- ) { GEN nhbr_pol = first_iter ? Flm_Fl_polmodular_evalx ( phi , L , j , p , pi ) : nhbr_polynomial ( path + 1 , phi , p , pi , L ) ; GEN nhbrs = Flx_roots ( nhbr_pol , p ) ; long nhbrs_len = lg ( nhbrs ) - 1 , i ; pari_sp btop = avma ; path [ 0 ] = j ; first_iter = 0 ; j = nhbrs [ nhbrs_len ] ; for ( i = 1 ; i < nhbrs_len ; i ++ ) { ulong next_j = nhbrs [ i ] , last_j ; long len ; if ( is_j_exceptional ( next_j , p ) ) { if ( steps ) pari_err_BUG ( " " ) ; j = next_j ; break ; } path [ 1 ] = next_j ; len = extend_path ( path , phi , p , pi , L , max_len ) ; last_j = path [ len ] ; if ( len == max_len && ( is_j_exceptional ( last_j , p ) || node_degree ( phi , L , last_j , p , pi ) > 1 ) ) { j = next_j ; break ; } avma = btop ; } path [ 1 ] = j ; max_len ++ ; avma = av ; } avma = ltop ; return j ; }
This is Sutherland 2009 Algorithm Ascend (p12)
This is Sutherland 2009 Algorithm Ascend ( p12 )
/* path will never hold more than max_len < depth elements */ /* Fouquet & Morain, Section 4.3, if j = 0 or 1728, then it is on the
         * surface.  So we just return it. */ /* Ended up on the surface */ /* For nhbr_polynomial() at the top. */