(f, factor=False)
return sorted(roots, key=default_sort_key)
Compute roots of cyclotomic polynomials.
Compute roots of cyclotomic polynomials.
Compute roots of cyclotomic polynomials .
def roots_cyclotomic(f, factor=False):
    """Compute roots of cyclotomic polynomials. """
    L, U = _inv_totient_estimate(f.degree())

    for n in xrange(L, U + 1):
        g = cyclotomic_poly(n, f.gen, polys=True)

        if f == g:
            break
    else:  # pragma: no cover
        raise RuntimeError("failed to find index of a cyclotomic polynomial")

    roots = []

    if not factor:
        for k in xrange(1, n + 1):
            if igcd(k, n) == 1:
                roots.append(exp(2*k*S.Pi*I/n).expand(complex=True))
    else:
        g = Poly(f, extension=(-1)**Rational(1, n))

        for h, _ in g.factor_list()[1]:
            roots.append(-h.TC())

    return sorted(roots, key=default_sort_key)
def roots_cyclotomic ( f , factor = False ) : L , U = _inv_totient_estimate ( f . degree ( ) ) for n in xrange ( L , U + 1 ) : g = cyclotomic_poly ( n , f . gen , polys = True ) if f == g : break else : # pragma: no cover raise RuntimeError ( "failed to find index of a cyclotomic polynomial" ) roots = [ ] if not factor : for k in xrange ( 1 , n + 1 ) : if igcd ( k , n ) == 1 : roots . append ( exp ( 2 * k * S . Pi * I / n ) . expand ( complex = True ) ) else : g = Poly ( f , extension = ( - 1 ) ** Rational ( 1 , n ) ) for h , _ in g . factor_list ( ) [ 1 ] : roots . append ( - h . TC ( ) ) return sorted ( roots , key = default_sort_key )