bridge/class-master/depend/pari/src/basemath/bb_group.c
/***********************************************************************/
/**                                                                   **/
/**                    ORDER OF AN ELEMENT                            **/
/**                                                                   **/
/***********************************************************************/
/*Find the exact order of a assuming a^o==1*/
ORDER OF AN ELEMENT

Find the exact order of a assuming a^o==1
ORDER OF AN ELEMENT Find the exact order of a assuming a^o == 1
GEN
gen_order(GEN a, GEN o, void *E, const struct bb_group *grp)
{
  pari_sp av = avma;
  long i, l;
  GEN m;
  m = get_arith_ZZM(o);
  if (!m) pari_err_TYPE("gen_order [missing order]",a);
  o = gel(m,1);
  m = gel(m,2); l = lgcols(m);
  for (i = l-1; i; i--)
  {
    GEN t, y, p = gcoeff(m,i,1);
    long j, e = itos(gcoeff(m,i,2));
    if (l == 2) {
      t = gen_1;
      y = a;
    } else {
      t = diviiexact(o, powiu(p,e));
      y = grp->pow(E, a, t);
    }
    if (grp->equal1(y)) o = t;
    else {
      for (j = 1; j < e; j++)
      {
        y = grp->pow(E, y, p);
        if (grp->equal1(y)) break;
      }
      if (j < e) {
        if (j > 1) p = powiu(p, j);
        o = mulii(t, p);
      }
    }
  }
  return gerepilecopy(av, o);
}
GEN gen_order ( GEN a , GEN o , void * E , const struct bb_group * grp ) { pari_sp av = avma ; long i , l ; GEN m ; m = get_arith_ZZM ( o ) ; if ( ! m ) pari_err_TYPE ( " " , a ) ; o = gel ( m , 1 ) ; m = gel ( m , 2 ) ; l = lgcols ( m ) ; for ( i = l - 1 ; i ; i -- ) { GEN t , y , p = gcoeff ( m , i , 1 ) ; long j , e = itos ( gcoeff ( m , i , 2 ) ) ; if ( l == 2 ) { t = gen_1 ; y = a ; } else { t = diviiexact ( o , powiu ( p , e ) ) ; y = grp -> pow ( E , a , t ) ; } if ( grp -> equal1 ( y ) ) o = t ; else { for ( j = 1 ; j < e ; j ++ ) { y = grp -> pow ( E , y , p ) ; if ( grp -> equal1 ( y ) ) break ; } if ( j < e ) { if ( j > 1 ) p = powiu ( p , j ) ; o = mulii ( t , p ) ; } } } return gerepilecopy ( av , o ) ; }
ORDER OF AN ELEMENT
ORDER OF AN ELEMENT