bridge/class-master/depend/pari/src/basemath/elltors.c
/* w a variable number of highest priority */
w a variable number of highest priority
w a variable number of highest priority
static long
ellisdivisible_i(GEN E, GEN P, GEN n, long w, GEN *pQ)
{
  GEN xP, R, K = NULL, N = NULL;
  long i, l;
  checkell(E);
  switch(ell_get_type(E))
  {
    case t_ELL_Q: break;
    case t_ELL_NF: K = ellnf_get_nf(E); break;
    default: pari_err_TYPE("ellisdivisible",E);
  }
  checkellpt(P);
  switch(typ(n))
  {
    case t_INT:
      N = n;
      if (!isprime(absi_shallow(n)))
      {
        GEN f = absZ_factor(n), LP = gel(f,1), LE = gel(f,2);
        l = lg(LP);
        for (i = 1; i < l; i++)
        {
          long j, e = itos(gel(LE,i));
          GEN xp = ellxn(E,itos(gel(LP,i)), w);
          for (j = 1; j <= e; j++)
            if (!ellisdivisible(E, P, xp, &P)) return 0;
        }
        if (pQ) *pQ = signe(n) < 0? ellneg(E, P): P;
        return 1;
      }
      n = ellxn(E, itou(n), w);
      break;
    case t_VEC:
      if (lg(n) == 3 && typ(gel(n,1)) == t_POL && typ(gel(n,2)) == t_POL) break;
    default:
      pari_err_TYPE("ellisdivisible",n);
      break;
  }
  if (ell_is_inf(P)) { if (pQ) *pQ = ellinf(); return 1; }
  if (!N)
  {
    long d, d2 = degpol(gel(n,1));
    if (d2 < 0)
      N = gen_0;
    else
    {
      if (!uissquareall(d2,(ulong*)&d)) pari_err_TYPE("ellisdivisible",n);
      N = stoi(d);
    }
  }
  if (!signe(N)) return 0;
  xP = gel(P,1);
  R = nfroots(K, RgX_sub(RgX_Rg_mul(gel(n,2), xP), gel(n,1)));
  l = lg(R);
  for(i = 1; i < l; i++)
  {
    GEN Q,y, x = gel(R,i), a = ellordinate(E,x,0);
    if (lg(a) == 1) continue;
    y = gel(a,1);
    Q = mkvec2(x,y);
    if (!gequal(P,ellmul(E,Q,N))) Q = ellneg(E,Q); 
    if (pQ) *pQ = Q;
    return 1;
  }
  return 0;
}
static long ellisdivisible_i ( GEN E , GEN P , GEN n , long w , GEN * pQ ) { GEN xP , R , K = NULL , N = NULL ; long i , l ; checkell ( E ) ; switch ( ell_get_type ( E ) ) { case t_ELL_Q : break ; case t_ELL_NF : K = ellnf_get_nf ( E ) ; break ; default : pari_err_TYPE ( " " , E ) ; } checkellpt ( P ) ; switch ( typ ( n ) ) { case t_INT : N = n ; if ( ! isprime ( absi_shallow ( n ) ) ) { GEN f = absZ_factor ( n ) , LP = gel ( f , 1 ) , LE = gel ( f , 2 ) ; l = lg ( LP ) ; for ( i = 1 ; i < l ; i ++ ) { long j , e = itos ( gel ( LE , i ) ) ; GEN xp = ellxn ( E , itos ( gel ( LP , i ) ) , w ) ; for ( j = 1 ; j <= e ; j ++ ) if ( ! ellisdivisible ( E , P , xp , & P ) ) return 0 ; } if ( pQ ) * pQ = signe ( n ) < 0 ? ellneg ( E , P ) : P ; return 1 ; } n = ellxn ( E , itou ( n ) , w ) ; break ; case t_VEC : if ( lg ( n ) == 3 && typ ( gel ( n , 1 ) ) == t_POL && typ ( gel ( n , 2 ) ) == t_POL ) break ; default : pari_err_TYPE ( " " , n ) ; break ; } if ( ell_is_inf ( P ) ) { if ( pQ ) * pQ = ellinf ( ) ; return 1 ; } if ( ! N ) { long d , d2 = degpol ( gel ( n , 1 ) ) ; if ( d2 < 0 ) N = gen_0 ; else { if ( ! uissquareall ( d2 , ( ulong * ) & d ) ) pari_err_TYPE ( " " , n ) ; N = stoi ( d ) ; } } if ( ! signe ( N ) ) return 0 ; xP = gel ( P , 1 ) ; R = nfroots ( K , RgX_sub ( RgX_Rg_mul ( gel ( n , 2 ) , xP ) , gel ( n , 1 ) ) ) ; l = lg ( R ) ; for ( i = 1 ; i < l ; i ++ ) { GEN Q , y , x = gel ( R , i ) , a = ellordinate ( E , x , 0 ) ; if ( lg ( a ) == 1 ) continue ; y = gel ( a , 1 ) ; Q = mkvec2 ( x , y ) ; if ( ! gequal ( P , ellmul ( E , Q , N ) ) ) Q = ellneg ( E , Q ) ; if ( pQ ) * pQ = Q ; return 1 ; } return 0 ; }
w a variable number of highest priority
w a variable number of highest priority
/* nQ = -P */