@@ -288,11 +288,11 @@ cdef class BooleanFunction(SageObject):
288
288
if isinstance (x, str ):
289
289
L = ZZ(len (x))
290
290
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)
292
292
else :
293
293
raise ValueError (" the length of the truth table must be a power of 2" )
294
294
from types import GeneratorType
295
- if isinstance (x, (list ,tuple ,GeneratorType)):
295
+ if isinstance (x, (list , tuple , GeneratorType)):
296
296
# initialisation from a truth table
297
297
298
298
# first, check the length
@@ -336,14 +336,15 @@ cdef class BooleanFunction(SageObject):
336
336
FiniteField_givaro = ()
337
337
if isinstance (K, FiniteField_givaro): # the ordering is not the same in this case
338
338
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())
340
341
else :
341
- for i,u in enumerate (K):
342
+ for i, u in enumerate (K):
342
343
bitset_set_to(self ._truth_table, i, (x(u)).trace())
343
344
elif isinstance (x, BooleanFunction):
344
345
self ._nvariables = x.nvariables()
345
346
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)
347
348
else :
348
349
raise TypeError (" unable to init the Boolean function" )
349
350
@@ -507,7 +508,7 @@ cdef class BooleanFunction(SageObject):
507
508
bitset_copy(anf, self ._truth_table)
508
509
reed_muller(anf.bits, ZZ(anf.limbs).exact_log(2 ))
509
510
from sage.rings.polynomial.pbori.pbori import BooleanPolynomialRing
510
- R = BooleanPolynomialRing(self ._nvariables," x" )
511
+ R = BooleanPolynomialRing(self ._nvariables, " x" )
511
512
G = R.gens()
512
513
P = R(0 )
513
514
@@ -517,7 +518,7 @@ cdef class BooleanFunction(SageObject):
517
518
inf = i* sizeof(long )* 8
518
519
sup = min ((i+ 1 )* sizeof(long )* 8 , (1 << self ._nvariables))
519
520
for j in range (inf, sup):
520
- if bitset_in(anf,j):
521
+ if bitset_in(anf, j):
521
522
m = R(1 )
522
523
for k in range (self ._nvariables):
523
524
if (j>> k)& 1 :
@@ -592,9 +593,9 @@ cdef class BooleanFunction(SageObject):
592
593
if format == ' bin' :
593
594
return tuple (self )
594
595
if format == ' int' :
595
- return tuple (map (int ,self ))
596
+ return tuple (map (int , self ))
596
597
if format == ' hex' :
597
- S = ZZ(self .truth_table(),2 ).str(16 )
598
+ S = ZZ(self .truth_table(), 2 ).str(16 )
598
599
S = " 0" * ((1 << (self ._nvariables- 2 )) - len (S)) + S
599
600
return S
600
601
raise ValueError (" unknown output format" )
@@ -713,7 +714,7 @@ cdef class BooleanFunction(SageObject):
713
714
( 0, -4, 0, 4, 0, 4, 0, 4)
714
715
"""
715
716
cdef long * temp
716
- cdef mp_bitcnt_t i,n
717
+ cdef mp_bitcnt_t i, n
717
718
718
719
if self ._walsh_hadamard_transform is None :
719
720
n = self ._truth_table.size
@@ -1010,7 +1011,7 @@ cdef class BooleanFunction(SageObject):
1010
1011
"""
1011
1012
# NOTE: this is a toy implementation
1012
1013
from sage.rings.polynomial.polynomial_ring_constructor import BooleanPolynomialRing_constructor
1013
- R = BooleanPolynomialRing_constructor(self ._nvariables,' x' )
1014
+ R = BooleanPolynomialRing_constructor(self ._nvariables, ' x' )
1014
1015
G = R.gens()
1015
1016
r = [R(1 )]
1016
1017
@@ -1022,7 +1023,8 @@ cdef class BooleanFunction(SageObject):
1022
1023
1023
1024
from sage.matrix.constructor import Matrix
1024
1025
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))
1026
1028
1027
1029
cdef long i
1028
1030
for i in range (1 , d+ 1 ):
@@ -1036,23 +1038,20 @@ cdef class BooleanFunction(SageObject):
1036
1038
cdef long j
1037
1039
cdef mp_bitcnt_t v
1038
1040
1039
- for i,m in enumerate (r):
1041
+ for i, m in enumerate (r):
1040
1042
t = BooleanFunction(m)
1041
- for j,v in enumerate (s):
1043
+ for j, v in enumerate (s):
1042
1044
sig_check()
1043
- M[i,j] = bitset_in(t._truth_table,v)
1045
+ M[i, j] = bitset_in(t._truth_table, v)
1044
1046
1045
1047
kg = M.kernel().gens()
1046
1048
1047
1049
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)])
1049
1051
else :
1050
1052
res = None
1051
1053
1052
- if dim:
1053
- return res, len (kg)
1054
- else :
1055
- return res
1054
+ return (res, len (kg)) if dim else res
1056
1055
1057
1056
def algebraic_immunity (self , annihilator = False ):
1058
1057
"""
@@ -1483,5 +1482,5 @@ def random_boolean_function(n):
1483
1482
T[0 ] = B._truth_table[0 ]
1484
1483
for i in range (T.limbs):
1485
1484
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 ))
1487
1486
return B
0 commit comments