Skip to content

Commit

Permalink
some pep8 fixes in combinat/designs
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Sep 4, 2024
1 parent 24698e7 commit 2efa372
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 166 deletions.
18 changes: 8 additions & 10 deletions src/sage/combinat/designs/bibd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,10 +1355,10 @@ def BIBD_from_arc_in_desarguesian_projective_plane(n,k,existence=False):
:doi:`10.1016/S0021-9800(69)80095-5`
"""
q = (n-1)//(k-1)-1
if (k % 2 or
q % 2 or
q <= k or
n != (k-1)*(q+1)+1 or
if (k % 2 or
q % 2 or
q <= k or
n != (k-1)*(q+1)+1 or
not is_prime_power(k) or
not is_prime_power(q)):
if existence:
Expand Down Expand Up @@ -1391,12 +1391,10 @@ def BIBD_from_arc_in_desarguesian_projective_plane(n,k,existence=False):
# [Denniston69] is the set of all elements of K of degree < log_n
# (seeing elements of K as polynomials in 'a')

K_iter = list(K) # faster iterations
log_n = is_prime_power(n,get_data=True)[1]
C = [(x,y,one)
for x in K_iter
for y in K_iter
if Q(x,y).polynomial().degree() < log_n]
K_iter = list(K) # faster iterations
log_n = is_prime_power(n, get_data=True)[1]
C = [(x, y, one) for x in K_iter for y in K_iter
if Q(x, y).polynomial().degree() < log_n]

from sage.combinat.designs.block_design import DesarguesianProjectivePlaneDesign
return DesarguesianProjectivePlaneDesign(q).trace(C)._blocks
Expand Down
27 changes: 14 additions & 13 deletions src/sage/combinat/designs/block_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
---------------------
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2007 Peter Dobcsanyi <peter@designtheory.org>
# Copyright (C) 2007 David Joyner <wdjoyner@gmail.com>
#
Expand All @@ -51,7 +51,7 @@
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# https://www.gnu.org/licenses/
#*****************************************************************************
# ****************************************************************************
from sage.arith.misc import binomial, integer_floor, is_prime_power
from sage.categories.sets_cat import EmptySetError
from sage.misc.lazy_import import lazy_import
Expand All @@ -69,7 +69,7 @@

BlockDesign = IncidenceStructure

### utility functions -------------------------------------------------------
# utility functions -----------------------------------------------------


def tdesign_params(t, v, k, L):
Expand Down Expand Up @@ -338,9 +338,10 @@ def DesarguesianProjectivePlaneDesign(n, point_coordinates=True, check=True):
"""
K = FiniteField(n, 'a')
n2 = n**2
relabel = {x:i for i,x in enumerate(K)}
Kiter = relabel # it is much faster to iterate through a dict than through
# the finite field K
relabel = {x: i for i, x in enumerate(K)}
Kiter = relabel
# it is much faster to iterate through a dict than through
# the finite field K

# we decompose the (equivalence class) of points [x:y:z] of the projective
# plane into an affine plane, an affine line and a point. At the same time,
Expand Down Expand Up @@ -996,14 +997,14 @@ def HadamardDesign(n):
"""
from sage.combinat.matrices.hadamard_matrix import hadamard_matrix
from sage.matrix.constructor import matrix
H = hadamard_matrix(n+1) #assumed to be normalised.
H = hadamard_matrix(n + 1) # assumed to be normalised.
H1 = H.matrix_from_columns(range(1,n+1))
H2 = H1.matrix_from_rows(range(1,n+1))
J = matrix(ZZ,n,n,[1]*n*n)
MS = J.parent()
A = MS((H2+J)/2) # convert -1's to 0's; coerce entries to ZZ
A = MS((H2+J)/2) # convert -1's to 0's; coerce entries to ZZ
# A is the incidence matrix of the block design
return IncidenceStructure(incidence_matrix=A,name='HadamardDesign')
return IncidenceStructure(incidence_matrix=A, name='HadamardDesign')


def Hadamard3Design(n):
Expand Down Expand Up @@ -1060,10 +1061,10 @@ def Hadamard3Design(n):
raise ValueError("The Hadamard design with n = %s does not extend to a three design." % n)
from sage.combinat.matrices.hadamard_matrix import hadamard_matrix
from sage.matrix.constructor import matrix, block_matrix
H = hadamard_matrix(n) #assumed to be normalised.
H = hadamard_matrix(n) # assumed to be normalised.
H1 = H.matrix_from_columns(range(1, n))
J = matrix(ZZ, n, n-1, [1]*(n-1)*n)
A1 = (H1+J)/2
A2 = (J-H1)/2
A = block_matrix(1, 2, [A1, A2]) #the incidence matrix of the design.
A1 = (H1 + J) / 2
A2 = (J - H1) / 2
A = block_matrix(1, 2, [A1, A2]) # the incidence matrix of the design.
return IncidenceStructure(incidence_matrix=A, name='HadamardThreeDesign')
18 changes: 7 additions & 11 deletions src/sage/combinat/designs/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ def OA_10_205():
baer_subplane_size = 4**2+4+1

B = [0, 1, 22, 33, 83, 122, 135, 141, 145, 159, 175, 200, 226, 229, 231, 238, 246]
pplane = [[(xx+i) % pplane_size for xx in B] for i in range(pplane_size)]
pplane = [[(xx+i) % pplane_size for xx in B] for i in range(pplane_size)]
baer_subplane = set([i*pplane_size/baer_subplane_size for i in range(baer_subplane_size)])

p = list(baer_subplane)[0]
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def OA_11_254():

# Base block of a PG(2,19)
B = (0,1,19,28,96,118,151,153,176,202,240,254,290,296,300,307,337,361,366,369)
BIBD = [[(x+i) % 381 for x in B] for i in range(381)]
BIBD = [[(x+i) % 381 for x in B] for i in range(381)]

# We only keep points congruent to 0,1 mod 3 and relabel the PBD. The result is
# a (254,{11,13,16})-PBD
Expand Down Expand Up @@ -1708,7 +1708,7 @@ def OA_10_469():
731,824,837,848,932,1002,1051,1055,1089,1105,1145,1165,1196,1217,1226,
1274,1281,1309,1405)

BIBD = [[(x+i) % 1407 for x in B] for i in range(1407)]
BIBD = [[(x+i) % 1407 for x in B] for i in range(1407)]

# Only keep points v congruent to 0 mod 3 and relabel
PBD = [[x//3 for x in B if x % 3 == 0] for B in BIBD]
Expand Down Expand Up @@ -4171,7 +4171,7 @@ def RBIBD_120_8_1():

# A (precomputed) set that every block of the BIBD intersects on 0 or 2 points
hyperoval = [128, 192, 194, 4, 262, 140, 175, 48, 81, 180, 245, 271, 119, 212, 249, 189, 62, 255]
#for B in BIBD:
# for B in BIBD:
# len_trace = sum(x in hyperoval for x in B)
# assert len_trace == 0 or len_trace == 2

Expand Down Expand Up @@ -4577,13 +4577,9 @@ def HigmanSimsDesign():
from sage.combinat.designs.block_design import WittDesign
from .incidence_structures import IncidenceStructure
W = WittDesign(24)
a,b = 0,1
Wa = [set(B) for B in W
if (a in B and
b not in B)]
Wb = [set(B) for B in W
if (b in B and
a not in B)]
a, b = 0, 1
Wa = [set(B) for B in W if a in B and b not in B]
Wb = [set(B) for B in W if b in B and a not in B]

H = [[i for i, A in enumerate(Wa) if len(A & B) != 2]
for B in Wb]
Expand Down
43 changes: 22 additions & 21 deletions src/sage/combinat/designs/difference_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def block_stabilizer(G, B):
S = []
for b in B:
# fun: if we replace +(-b) with -b it completely fails!!
bb0 = op(b,b0) # bb0 = b-B[0]
if all(op(bb0,c) in B for c in B):
bb0 = op(b, b0) # bb0 = b-B[0]
if all(op(bb0, c) in B for c in B):
S.append(bb0)
return S

Expand Down Expand Up @@ -279,7 +279,7 @@ def is_difference_family(G, D, v=None, k=None, l=None, verbose=False):
for c in d:
if b == c:
continue
gg = mul(b,inv(c)) # = b-c or bc^{-1}
gg = mul(b, inv(c)) # = b-c or bc^{-1}
if gg not in tmp_counter:
tmp_counter[gg] = 0
where[gg].add(i)
Expand Down Expand Up @@ -319,7 +319,7 @@ def is_difference_family(G, D, v=None, k=None, l=None, verbose=False):
g, counter[g], sorted(where[g])))
if too_much:
print("Too much:")
for g in too_much:
for g in too_much:
print(" {} is obtained {} times in blocks {}".format(
g, counter[g], sorted(where[g])))
if too_few or too_much:
Expand Down Expand Up @@ -388,9 +388,10 @@ def singer_difference_set(q,d):
# build a polynomial c over GF(q) such that GF(q)[x] / (c(x)) is a
# GF(q**(d+1)) and such that x is a multiplicative generator.
p,e = q.factor()[0]
c = conway_polynomial(p,e*(d+1))
if e != 1: # i.e. q is not a prime, so we factorize c over GF(q) and pick
# one of its factor
c = conway_polynomial(p, e*(d+1))
if e != 1:
# i.e. q is not a prime, so we factorize c over GF(q) and pick
# one of its factor
K = GF(q,'z')
c = c.change_ring(K).factor()[0][0]
else:
Expand Down Expand Up @@ -454,7 +455,7 @@ def df_q_6_1(K, existence=False, check=True):
xx = x**5
to_coset = {x**i * xx**j: i for i in range(5) for j in range((v-1)/5)}

for c in to_coset: # the loop runs through all nonzero elements of K
for c in to_coset: # the loop runs through all nonzero elements of K
if c == one or c == r or c == r2:
continue
if len(set(to_coset[elt] for elt in (r-one, c*(r-one), c-one, c-r, c-r**2))) == 5:
Expand Down Expand Up @@ -796,13 +797,13 @@ def one_radical_difference_family(K, k):
A = [r**i - 1 for i in range(1,m+1)]
else:
m = k // 2
r = x ** ((q-1) // (k-1)) # (k-1)-th root of unity
r = x ** ((q-1) // (k-1)) # (k-1)-th root of unity
A = [r**i - 1 for i in range(1,m)]
A.append(K.one())

# instead of the complicated multiplicative group K^*/(±C) we use the
# discrete logarithm to convert everything into the additive group Z/cZ
c = m * (q-1) // e # cardinal of ±C
c = m * (q-1) // e # cardinal of ±C
from sage.groups.generic import discrete_log
logA = [discrete_log(a,x) % c for a in A]

Expand Down Expand Up @@ -1036,18 +1037,18 @@ def are_mcfarland_1973_parameters(v, k, lmbda, return_parameters=False):
96 20 4 4 1
"""
if v <= k or k <= lmbda:
return (False,None) if return_parameters else False
return (False, None) if return_parameters else False
k = ZZ(k)
lmbda = ZZ(lmbda)
qs,r = (k - lmbda).sqrtrem() # sqrt(k-l) should be q^s
qs, r = (k - lmbda).sqrtrem() # sqrt(k-l) should be q^s
if r or (qs*(qs-1)) % lmbda:
return (False,None) if return_parameters else False
return (False, None) if return_parameters else False

q = qs*(qs-1) // lmbda + 1
if (q <= 1 or
v * (q-1) != qs*q * (qs*q+q-2) or
v * (q-1) != qs*q * (qs*q+q-2) or
k * (q-1) != qs * (qs*q-1)):
return (False,None) if return_parameters else False
return (False, None) if return_parameters else False

# NOTE: below we compute the value of s so that qs = q^s. If the method
# is_power_of of integers would be able to return the exponent, we could use
Expand All @@ -1057,7 +1058,7 @@ def are_mcfarland_1973_parameters(v, k, lmbda, return_parameters=False):
p2,a2 = q.is_prime_power(get_data=True)

if a1 == 0 or a2 == 0 or p1 != p2 or a1 % a2:
return (False,None) if return_parameters else False
return (False, None) if return_parameters else False

return (True, (q, a1//a2)) if return_parameters else True

Expand Down Expand Up @@ -1265,10 +1266,10 @@ def turyn_1965_3x3xK(k=4):
else:
raise ValueError("k must be 2 or 4")

L = [[(0,1),(1,1),(2,1),(0,2),(1,2),(2,2)], # complement of y=0
[(0,0),(1,1),(2,2)], # x-y=0
[(0,0),(1,2),(2,1)], # x+y=0
[(0,0),(0,1),(0,2)]] # x=0
L = [[(0,1),(1,1),(2,1),(0,2),(1,2),(2,2)], # complement of y=0
[(0,0),(1,1),(2,2)], # x-y=0
[(0,0),(1,2),(2,1)], # x+y=0
[(0,0),(0,1),(0,2)]] # x=0

return G, [[G(v + k) for l, k in zip(L, K) for v in l]]

Expand Down Expand Up @@ -1835,7 +1836,7 @@ def supplementary_difference_set_from_rel_diff_set(q, existence=False, check=Tru
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
P = PolynomialRing(ZZ, 'x')

#Compute psi3, psi4
# Compute psi3, psi4
hall = 0
for d in set1:
hall += P.monomial(d[0])
Expand Down
21 changes: 10 additions & 11 deletions src/sage/combinat/designs/ext_rep.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,11 @@ def _start_element(self, name, attrs):
check_dtrs_protocols('source', attrs['dtrs_protocol'])
if self.list_of_designs_start_proc:
self.list_of_designs_start_proc(attrs)
#self.outf.write('<%s' % name)
#pp_attributes(self.outf, attrs, indent='', precision_stack=[])
#self.outf.write('>\n')
# self.outf.write('<%s' % name)
# pp_attributes(self.outf, attrs, indent='', precision_stack=[])
# self.outf.write('>\n')
elif name == 'designs':
pass # self.outf.write(' <%s>\n' % name)
pass # self.outf.write(' <%s>\n' % name)
if self.in_item:
for k, v in attrs.items():
attrs[k] = _encode_attribute(v)
Expand Down Expand Up @@ -916,7 +916,7 @@ def _end_element(self, name):
if name == 'block' or name == 'permutation' \
or name == 'preimage' or name == 'ksubset' \
or name == 'cycle_type' or name == 'row':
# these enclose lists of numbers
# these enclose lists of numbers
children.append(ps)
else:
# the rest is a single number
Expand All @@ -929,19 +929,19 @@ def _end_element(self, name):
if self.save_designs:
init_bd = XTree(self.current_node[2][0])
self.list_of_designs.append((init_bd.v, list(init_bd.blocks)))
#print_subxt(self.current_node[2][0], level=2, outf=self.outf)
# print_subxt(self.current_node[2][0], level=2, outf=self.outf)
self._init()
elif name == 'info':
if self.info_proc:
self.info_proc(self.current_node[2][0])
#print_subxt(self.current_node[2][0], level=1, outf=self.outf)
# print_subxt(self.current_node[2][0], level=1, outf=self.outf)
self._init()
else:
if name == 'designs':
if self.designs_end_proc:
self.designs_end_proc()
#self.outf.write(' ')
#self.outf.write('</%s>\n' % name)
# self.outf.write(' ')
# self.outf.write('</%s>\n' % name)

def _char_data(self, data):
"""
Expand All @@ -962,9 +962,8 @@ def _char_data(self, data):
{'b': 26, 'id': 't2-v13-b26-r6-k3-L1-0', 'v': 13},
['[ DESIGN-1.1, GRAPE-4.2, GAPDoc-0.9999, GAP-4.4.3]'])
"""

if self.in_item:
#@ this stripping may distort char data in the <info> subtree
# @ this stripping may distort char data in the <info> subtree
# if they are not bracketed in some way.
data = data.strip()
if data:
Expand Down
Loading

0 comments on commit 2efa372

Please sign in to comment.