injectivitylemma.py: use namedtuple for clarity, and switch to Python 3.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2020-02-18 09:41:29 +00:00
parent c6e1112e1f
commit daff0c4197
1 changed files with 10 additions and 7 deletions

View File

@ -1,16 +1,19 @@
#!/usr/bin/python
#!/usr/bin/python3
from itertools import product
from collections import namedtuple
cd_pair = namedtuple('cd_pair', ['c', 'd'])
def c_d():
yield (-1, 0)
yield ( 1, 0)
yield ( 0, -1)
yield ( 0, 1)
yield cd_pair(-1, 0)
yield cd_pair( 1, 0)
yield cd_pair( 0, -1)
yield cd_pair( 0, 1)
def sums_mod4(cd):
return ((2**(k+1) + sum([cd[j][0] * (2**j) for j in range(k)])) % 4,
(2**(k+1) + sum([cd[j][1] * (2**j) for j in range(k)])) % 4)
return ((2**(k+1) + sum([cd[j].c * (2**j) for j in range(k)])) % 4,
(2**(k+1) + sum([cd[j].d * (2**j) for j in range(k)])) % 4)
for k in (1, 2):
M_k = [list(s) for s in product(c_d(), repeat=k)]