Группа корней из единицы степени n

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
from numpy import dot
import math
from math import pi
#returns smallest power of 2 that is greater or equal than v
def power_2_bound(v):
v -= 1
v |= v >> 1
v |= v >> 2
v |= v >> 4
v |= v >> 8
v |= v >> 16
return v + 1
#complex mul and add
def cdot(x, y):
return np.array([x[0] * y[0] - x[1] * y[1], x[0] * y[1] + x[1] * y[0]])
def cadd(x, y):
return np.array([x[0] + y[0], x[1] + y[1]])
np.set_printoptions(suppress=True)
resolution = power_2_bound(n)
root_angles = np.array([(2 * math.pi) * i / resolution for i in xrange(resolution)])
roots = np.array([np.cos(root_angles), np.sin(root_angles)])
for i in xrange(resolution):
for j in xrange(resolution):
print i, j, cdot(roots[:, i], roots[:, j]), roots[:, (i + j)%resolution]