(n, x=None, **args)
Generates n-th Swinnerton-Dyer polynomial in `x`.
Generates n-th Swinnerton-Dyer polynomial in `x`.
Generates n - th Swinnerton - Dyer polynomial in x .
def swinnerton_dyer_poly(n, x=None, **args):
    """Generates n-th Swinnerton-Dyer polynomial in `x`.  """
    from .numberfields import minimal_polynomial
    if n <= 0:
        raise ValueError(
            "can't generate Swinnerton-Dyer polynomial of order %s" % n)

    if x is not None:
        sympify(x)
    else:
        x = Dummy('x')

    if n > 3:
        p = 2
        a = [sqrt(2)]
        for i in xrange(2, n + 1):
            p = nextprime(p)
            a.append(sqrt(p))
        return minimal_polynomial(Add(*a), x, polys=args.get('polys', False))

    if n == 1:
        ex = x**2 - 2
    elif n == 2:
        ex = x**4 - 10*x**2 + 1
    elif n == 3:
        ex = x**8 - 40*x**6 + 352*x**4 - 960*x**2 + 576
    if not args.get('polys', False):
        return ex
    else:
        return PurePoly(ex, x)
def swinnerton_dyer_poly ( n , x = None , * * args ) : from . numberfields import minimal_polynomial if n <= 0 : raise ValueError ( "can't generate Swinnerton-Dyer polynomial of order %s" % n ) if x is not None : sympify ( x ) else : x = Dummy ( 'x' ) if n > 3 : p = 2 a = [ sqrt ( 2 ) ] for i in xrange ( 2 , n + 1 ) : p = nextprime ( p ) a . append ( sqrt ( p ) ) return minimal_polynomial ( Add ( * a ) , x , polys = args . get ( 'polys' , False ) ) if n == 1 : ex = x ** 2 - 2 elif n == 2 : ex = x ** 4 - 10 * x ** 2 + 1 elif n == 3 : ex = x ** 8 - 40 * x ** 6 + 352 * x ** 4 - 960 * x ** 2 + 576 if not args . get ( 'polys' , False ) : return ex else : return PurePoly ( ex , x )