0

I want to implement the Swinnerton dyer polynomials in python with the library sympy. Now I came up with the following code:

from itertools import *
from sympy import *
x = symbols("x")
y = symbols("y")
def swinnerton_dyer(N):
   combos = list(product([0,1],repeat=N))
   lin_facs = []
   p = Poly(1,y)
   for combo in combos:
      lin_fac = y
      for i in range(len(combo)):
         lin_fac += (-1)**combo[i] * sqrt(x+i)
  lin_facs.append(lin_fac)
  p*=lin_fac

The code works fine so far.

My question is: Is it possible to calculate this directly in the product function from itertools?

Ragon
  • 151
  • 6
  • 1
    Express the logic for computing a single `lin_fac` value as a function, then use ordinary techniques (such as a list comprehension) to apply that to the `product` values (rather than creating an explicit `list` first). See the linked duplicate for details. – Karl Knechtel Aug 23 '23 at 17:54

0 Answers0