bridge/class-master/depend/pari/src/basemath/QX_factor.c
/* Bradford-Davenport algorithm.
 * f a squarefree ZX of degree > 0, return NULL or a vector of coprime
 * cyclotomic factors of f [ possibly reducible ] */
Bradford-Davenport algorithm.
f a squarefree ZX of degree > 0, return NULL or a vector of coprime
cyclotomic factors of f [ possibly reducible ]
Bradford - Davenport algorithm . f a squarefree ZX of degree > 0 return NULL or a vector of coprime cyclotomic factors of f [ possibly reducible ]
static GEN
BD(GEN f)
{
  GEN G = NULL, Gs = NULL, Gp = NULL, Gi = NULL;
  GEN fs2, fp, f2, f1, fe, fo, fe1, fo1;
  RgX_even_odd(f, &fe, &fo);
  fe1 = ZX_eval1(fe);
  fo1 = ZX_eval1(fo);
  if (absequalii(fe1, fo1)) 
  {
    long i, v = varn(f);
    if (!signe(fe1))
      G = mkvec2(polcyclo(1, v), polcyclo(2, v)); 
    else if (signe(fe1) == signe(fo1))
      G = mkvec(polcyclo(2, v)); 
    else
      G = mkvec(polcyclo(1, v)); 
    for (i = lg(G)-1; i; i--) f = RgX_div(f, gel(G,i));
  }
  if (degpol(f) <= 1) return G;
  f1 = ZX_graeffe(f); 
  if (ZX_equal(f1, f)) return myconcat(G,f); 
  fs2 = ZX_gcd_all(f1, ZX_deriv(f1), &f2); 
  if (degpol(fs2))
  { 
    GEN fs = RgX_inflate(fs2, 2);
    (void)ZX_gcd_all(f, fs, &f); 
    Gs = BD(fs2);
    if (Gs)
    {
      long i;
      for (i = lg(Gs)-1; i; i--) gel(Gs,i) = RgX_inflate(gel(Gs,i), 2);
      G = myconcat(G, Gs);
    }
    f1 = RgX_div(f2, fs2); 
  }
  fp = ZX_gcd(f, f1); 
  if (degpol(fp))
  {
    Gp = BD_odd(fp);
    if (Gp) G = myconcat(G, Gp);
    f = RgX_div(f, fp);
  }
  if (degpol(f))
  { 
    Gi = BD_odd(ZX_z_unscale(f, -1));
    if (Gi)
    { 
      Gi = ZX_z_unscale(Gi, -1);
      G = myconcat(G, Gi);
    }
  }
  return G;
}
static GEN BD ( GEN f ) { GEN G = NULL , Gs = NULL , Gp = NULL , Gi = NULL ; GEN fs2 , fp , f2 , f1 , fe , fo , fe1 , fo1 ; RgX_even_odd ( f , & fe , & fo ) ; fe1 = ZX_eval1 ( fe ) ; fo1 = ZX_eval1 ( fo ) ; if ( absequalii ( fe1 , fo1 ) ) { long i , v = varn ( f ) ; if ( ! signe ( fe1 ) ) G = mkvec2 ( polcyclo ( 1 , v ) , polcyclo ( 2 , v ) ) ; else if ( signe ( fe1 ) == signe ( fo1 ) ) G = mkvec ( polcyclo ( 2 , v ) ) ; else G = mkvec ( polcyclo ( 1 , v ) ) ; for ( i = lg ( G ) - 1 ; i ; i -- ) f = RgX_div ( f , gel ( G , i ) ) ; } if ( degpol ( f ) <= 1 ) return G ; f1 = ZX_graeffe ( f ) ; if ( ZX_equal ( f1 , f ) ) return myconcat ( G , f ) ; fs2 = ZX_gcd_all ( f1 , ZX_deriv ( f1 ) , & f2 ) ; if ( degpol ( fs2 ) ) { GEN fs = RgX_inflate ( fs2 , 2 ) ; ( void ) ZX_gcd_all ( f , fs , & f ) ; Gs = BD ( fs2 ) ; if ( Gs ) { long i ; for ( i = lg ( Gs ) - 1 ; i ; i -- ) gel ( Gs , i ) = RgX_inflate ( gel ( Gs , i ) , 2 ) ; G = myconcat ( G , Gs ) ; } f1 = RgX_div ( f2 , fs2 ) ; } fp = ZX_gcd ( f , f1 ) ; if ( degpol ( fp ) ) { Gp = BD_odd ( fp ) ; if ( Gp ) G = myconcat ( G , Gp ) ; f = RgX_div ( f , fp ) ; } if ( degpol ( f ) ) { Gi = BD_odd ( ZX_z_unscale ( f , -1 ) ) ; if ( Gi ) { Gi = ZX_z_unscale ( Gi , -1 ) ; G = myconcat ( G , Gi ) ; } } return G ; }
Bradford-Davenport algorithm.
Bradford - Davenport algorithm .
/* f(1) = 0 or f(-1) = 0 */ /* both 0 */ /*f(-1) = 0*/ /*f(1) = 0*/ /* f no longer divisible by Phi_1 or Phi_2 */ /* has at most square factors */ /* f = product of Phi_n, n odd */ /* fs2 squarefree */ /* fs contains all Phi_n | f, 4 | n; and only those */ /* In that case, Graeffe(Phi_n) = Phi_{n/2}^2, and Phi_n = Phi_{n/2}(x^2) */ /* remove those Phi_n | f, 4 | n */ /* prod Gs[i] is the product of all Phi_n | f, 4 | n */ /* f2 = f1 / fs2 */ /* f1 / fs2^2 */ /* contains all Phi_n | f, n > 1 odd; and only those */ /* Gp is the product of all Phi_n | f, n odd */ /* contains all Phi_n originally dividing f, n = 2 mod 4, n > 2;
     * and only those
     * In that case, Graeffe(Phi_n) = Phi_{n/2}, and Phi_n = Phi_{n/2}(-x) */ /* N.B. Phi_2 does not divide f */ /* Gi is the product of all Phi_n | f, n = 2 mod 4 */