def dup_zz_cyclotomic_factor(f, K):
 (lc_f, tc_f) = (dup_LC(f, K), dup_TC(f, K))
 if (dup_degree(f) <= 0):
  return None
 if ((lc_f != 1) or (tc_f not in [(-1), 1])):
  return None
 if any((bool(cf) for cf in f[1:(-1)])):
  return None
 n = dup_degree(f)
 F = _dup_cyclotomic_decompose(n, K)
 if (not K.is_one(tc_f)):
  return F
 else:
  H = []
  for h in _dup_cyclotomic_decompose((2 * n), K):
   if (h not in F):
    H.append(h)
  return H

def dup_zz_cyclotomic_factor ( f , K ) : ( lc_f , tc_f ) = ( dup_LC ( f , K ) , dup_TC ( f , K ) ) if ( dup_degree ( f ) <= 0 ) : return None if ( ( lc_f != 1 ) or ( tc_f not in [ ( - 1 ) , 1 ] ) ) : return None if any ( ( bool ( cf ) for cf in f [ 1 : ( - 1 ) ] ) ) : return None n = dup_degree ( f ) F = _dup_cyclotomic_decompose ( n , K ) if ( not K . is_one ( tc_f ) ) : return F else : H = [ ] for h in _dup_cyclotomic_decompose ( ( 2 * n ) , K ) : if ( h not in F ) : H . append ( h ) return H
efficiently factor polynomials x**n - 1 and x**n + 1 in z[x] .