@@ -288,11 +288,11 @@ cdef class BooleanFunction(SageObject):
288288 if isinstance (x, str ):
289289 L = ZZ(len (x))
290290 if L.is_power_of(2 ):
291- x = ZZ(" 0x" + x).digits(base = 2 ,padto = 4 * L)
291+ x = ZZ(" 0x" + x).digits(base = 2 , padto = 4 * L)
292292 else :
293293 raise ValueError (" the length of the truth table must be a power of 2" )
294294 from types import GeneratorType
295- if isinstance (x, (list ,tuple ,GeneratorType)):
295+ if isinstance (x, (list , tuple , GeneratorType)):
296296 # initialisation from a truth table
297297
298298 # first, check the length
@@ -336,14 +336,15 @@ cdef class BooleanFunction(SageObject):
336336 FiniteField_givaro = ()
337337 if isinstance (K, FiniteField_givaro): # the ordering is not the same in this case
338338 for u in K:
339- bitset_set_to(self ._truth_table, ZZ(u._vector_().list(),2 ), (x(u)).trace())
339+ bitset_set_to(self ._truth_table,
340+ ZZ(u._vector_().list(), 2 ), (x(u)).trace())
340341 else :
341- for i,u in enumerate (K):
342+ for i, u in enumerate (K):
342343 bitset_set_to(self ._truth_table, i, (x(u)).trace())
343344 elif isinstance (x, BooleanFunction):
344345 self ._nvariables = x.nvariables()
345346 bitset_init(self ._truth_table, < mp_bitcnt_t> (1 << self ._nvariables))
346- bitset_copy(self ._truth_table,(< BooleanFunction> x)._truth_table)
347+ bitset_copy(self ._truth_table, (< BooleanFunction> x)._truth_table)
347348 else :
348349 raise TypeError (" unable to init the Boolean function" )
349350
@@ -507,7 +508,7 @@ cdef class BooleanFunction(SageObject):
507508 bitset_copy(anf, self ._truth_table)
508509 reed_muller(anf.bits, ZZ(anf.limbs).exact_log(2 ))
509510 from sage.rings.polynomial.pbori.pbori import BooleanPolynomialRing
510- R = BooleanPolynomialRing(self ._nvariables," x" )
511+ R = BooleanPolynomialRing(self ._nvariables, " x" )
511512 G = R.gens()
512513 P = R(0 )
513514
@@ -517,7 +518,7 @@ cdef class BooleanFunction(SageObject):
517518 inf = i* sizeof(long )* 8
518519 sup = min ((i+ 1 )* sizeof(long )* 8 , (1 << self ._nvariables))
519520 for j in range (inf, sup):
520- if bitset_in(anf,j):
521+ if bitset_in(anf, j):
521522 m = R(1 )
522523 for k in range (self ._nvariables):
523524 if (j>> k)& 1 :
@@ -592,9 +593,9 @@ cdef class BooleanFunction(SageObject):
592593 if format == ' bin' :
593594 return tuple (self )
594595 if format == ' int' :
595- return tuple (map (int ,self ))
596+ return tuple (map (int , self ))
596597 if format == ' hex' :
597- S = ZZ(self .truth_table(),2 ).str(16 )
598+ S = ZZ(self .truth_table(), 2 ).str(16 )
598599 S = " 0" * ((1 << (self ._nvariables- 2 )) - len (S)) + S
599600 return S
600601 raise ValueError (" unknown output format" )
@@ -713,7 +714,7 @@ cdef class BooleanFunction(SageObject):
713714 ( 0, -4, 0, 4, 0, 4, 0, 4)
714715 """
715716 cdef long * temp
716- cdef mp_bitcnt_t i,n
717+ cdef mp_bitcnt_t i, n
717718
718719 if self ._walsh_hadamard_transform is None :
719720 n = self ._truth_table.size
@@ -1010,7 +1011,7 @@ cdef class BooleanFunction(SageObject):
10101011 """
10111012 # NOTE: this is a toy implementation
10121013 from sage.rings.polynomial.polynomial_ring_constructor import BooleanPolynomialRing_constructor
1013- R = BooleanPolynomialRing_constructor(self ._nvariables,' x' )
1014+ R = BooleanPolynomialRing_constructor(self ._nvariables, ' x' )
10141015 G = R.gens()
10151016 r = [R(1 )]
10161017
@@ -1022,7 +1023,8 @@ cdef class BooleanFunction(SageObject):
10221023
10231024 from sage.matrix.constructor import Matrix
10241025 from sage.arith.misc import binomial
1025- M = Matrix(GF(2 ), sum (binomial(self ._nvariables,i) for i in range (d+ 1 )), len (s))
1026+ M = Matrix(GF(2 ), sum (binomial(self ._nvariables, i)
1027+ for i in range (d+ 1 )), len (s))
10261028
10271029 cdef long i
10281030 for i in range (1 , d+ 1 ):
@@ -1036,23 +1038,20 @@ cdef class BooleanFunction(SageObject):
10361038 cdef long j
10371039 cdef mp_bitcnt_t v
10381040
1039- for i,m in enumerate (r):
1041+ for i, m in enumerate (r):
10401042 t = BooleanFunction(m)
1041- for j,v in enumerate (s):
1043+ for j, v in enumerate (s):
10421044 sig_check()
1043- M[i,j] = bitset_in(t._truth_table,v)
1045+ M[i, j] = bitset_in(t._truth_table, v)
10441046
10451047 kg = M.kernel().gens()
10461048
10471049 if kg:
1048- res = sum ([kg[0 ][i]* ri for i,ri in enumerate (r)])
1050+ res = sum ([kg[0 ][i]* ri for i, ri in enumerate (r)])
10491051 else :
10501052 res = None
10511053
1052- if dim:
1053- return res, len (kg)
1054- else :
1055- return res
1054+ return (res, len (kg)) if dim else res
10561055
10571056 def algebraic_immunity (self , annihilator = False ):
10581057 """
@@ -1483,5 +1482,5 @@ def random_boolean_function(n):
14831482 T[0 ] = B._truth_table[0 ]
14841483 for i in range (T.limbs):
14851484 sig_check()
1486- T.bits[i] = r.randrange(0 ,Integer(1 )<< (sizeof(unsigned long )* 8 ))
1485+ T.bits[i] = r.randrange(0 , Integer(1 )<< (sizeof(unsigned long )* 8 ))
14871486 return B
0 commit comments