bridge/class-master/depend/pari/src/basemath/char.c
/* discrete log on canonical "primitive root" generators
 * Allow log(x) instead of x [usual discrete log on bid's generators */
discrete log on canonical "primitive root" generators
Allow log(x) instead of x [usual discrete log on bid's generators
discrete log on canonical " primitive root " generators Allow log ( x ) instead of x [ usual discrete log on bid ' s generators
GEN
znconreylog(GEN bid, GEN x)
{
  pari_sp av = avma;
  GEN N, L, F, P,E, y, pe, fao, gen, lo, cycg;
  long i, l;
  if (!checkznstar_i(bid)) pari_err_TYPE("znconreylog", bid);
  N = znstar_get_N(bid);
  if (typ(N) != t_INT) pari_err_TYPE("znconreylog", N);
  if (abscmpiu(N, 2) <= 0) return cgetg(1, t_COL);
  cycg = znstar_get_conreycyc(bid);
  switch(typ(x))
  {
    GEN Ui;
    case t_INT:
      if (!signe(x)) pari_err_COPRIME("znconreylog", x, N);
      break;
    case t_COL: 
      Ui = znstar_get_Ui(bid);
      if (!RgV_is_ZV(x) || lg(x) != lg(Ui)) pari_err_TYPE("znconreylog", x);
      return gerepileupto(av, vecmodii(ZM_ZC_mul(Ui,x), cycg));
    case t_VEC:
      return gerepilecopy(av, znconreyfromchar(bid, x));
    default: pari_err_TYPE("znconreylog", x);
  }
  F = znstar_get_faN(bid); 
  P = gel(F, 1); 
  E = gel(F, 2); 
  L = gel(bid,4);
  pe = znstar_get_pe(bid);
  fao = gel(L,2);
  gen = znstar_get_conreygen(bid); 
  lo = gel(L,6); 
  l = lg(gen); i = 1;
  y = cgetg(l, t_COL);
  if (!mod2(N) && !mod2(x)) pari_err_COPRIME("znconreylog", x, N);
  if (absequaliu(gel(P,1), 2) && E[1] >= 2)
  {
    if (E[1] == 2)
      gel(y,i++) = mod4(x) == 1? gen_0: gen_1;
    else
    {
      GEN a, x2, q2 = gel(pe,1);
      x2 = modii(x, q2);
      if (mod4(x) == 1) 
        gel(y,i++) = gen_0;
      else 
      { gel(y,i++) = gen_1; x2 = subii(q2, x2); }
      a = Zideallog_2k(x2, gel(gen,i), E[1], q2);
      if (!a) pari_err_COPRIME("znconreylog", x, N);
      gel(y, i++) = a;
    }
  }
  while (i < l)
  {
    GEN p = gel(P,i), q = gel(pe,i), xpe = modii(x, q);
    GEN a = Zideallog_pk(xpe, gel(gen,i), p, E[i], q, gel(fao,i), gel(lo,i));
    if (!a) pari_err_COPRIME("znconreylog", x, N);
    gel(y, i++) = a;
  }
  return gerepilecopy(av, y);
}
GEN znconreylog ( GEN bid , GEN x ) { pari_sp av = avma ; GEN N , L , F , P , E , y , pe , fao , gen , lo , cycg ; long i , l ; if ( ! checkznstar_i ( bid ) ) pari_err_TYPE ( " " , bid ) ; N = znstar_get_N ( bid ) ; if ( typ ( N ) != t_INT ) pari_err_TYPE ( " " , N ) ; if ( abscmpiu ( N , 2 ) <= 0 ) return cgetg ( 1 , t_COL ) ; cycg = znstar_get_conreycyc ( bid ) ; switch ( typ ( x ) ) { GEN Ui ; case t_INT : if ( ! signe ( x ) ) pari_err_COPRIME ( " " , x , N ) ; break ; case t_COL : Ui = znstar_get_Ui ( bid ) ; if ( ! RgV_is_ZV ( x ) || lg ( x ) != lg ( Ui ) ) pari_err_TYPE ( " " , x ) ; return gerepileupto ( av , vecmodii ( ZM_ZC_mul ( Ui , x ) , cycg ) ) ; case t_VEC : return gerepilecopy ( av , znconreyfromchar ( bid , x ) ) ; default : pari_err_TYPE ( " " , x ) ; } F = znstar_get_faN ( bid ) ; P = gel ( F , 1 ) ; E = gel ( F , 2 ) ; L = gel ( bid , 4 ) ; pe = znstar_get_pe ( bid ) ; fao = gel ( L , 2 ) ; gen = znstar_get_conreygen ( bid ) ; lo = gel ( L , 6 ) ; l = lg ( gen ) ; i = 1 ; y = cgetg ( l , t_COL ) ; if ( ! mod2 ( N ) && ! mod2 ( x ) ) pari_err_COPRIME ( " " , x , N ) ; if ( absequaliu ( gel ( P , 1 ) , 2 ) && E [ 1 ] >= 2 ) { if ( E [ 1 ] == 2 ) gel ( y , i ++ ) = mod4 ( x ) == 1 ? gen_0 : gen_1 ; else { GEN a , x2 , q2 = gel ( pe , 1 ) ; x2 = modii ( x , q2 ) ; if ( mod4 ( x ) == 1 ) gel ( y , i ++ ) = gen_0 ; else { gel ( y , i ++ ) = gen_1 ; x2 = subii ( q2 , x2 ) ; } a = Zideallog_2k ( x2 , gel ( gen , i ) , E [ 1 ] , q2 ) ; if ( ! a ) pari_err_COPRIME ( " " , x , N ) ; gel ( y , i ++ ) = a ; } } while ( i < l ) { GEN p = gel ( P , i ) , q = gel ( pe , i ) , xpe = modii ( x , q ) ; GEN a = Zideallog_pk ( xpe , gel ( gen , i ) , p , E [ i ] , q , gel ( fao , i ) , gel ( lo , i ) ) ; if ( ! a ) pari_err_COPRIME ( " " , x , N ) ; gel ( y , i ++ ) = a ; } return gerepilecopy ( av , y ) ; }
discrete log on canonical "primitive root" generators
 Allow log(x) instead of x [usual discrete log on bid's generators
discrete log on canonical " primitive root " generators Allow log ( x ) instead of x [ usual discrete log on bid ' s generators
/* log_bid(x) */ /* factor(N) */ /* prime divisors of N */ /* exponents */ /* local generators of (Z/p^k)^* */ /* 1/log_p((g_i)^(p_i-1)) */ /* 1 or 5 mod 8*/ /* 3 or 7 */ /* x2 = 5^x mod q */