arXiv:1811.04421v3 [cs.DM] 14 Feb 2020
Some Problems and Algorithms Related to the Weight Order
Relation on the n-dimensional Boolean Cube
VALENTIN BAKOEV
“St. Cyril and St. Methodius” University of V. Tarnovo
Faculty of Mathematics and Informatics
2 Theodosii Tarnovski Str., 5003 Veliko Tarnovo
BULGARIA
v.bakoev@ts.uni-vt.bg
Abstract: The problem “Given a Boolean function f of n variables by its truth table vector. Find (if exists) a vector
α ∈ {0, 1}n of maximal (or minimal) weight, such that f (α) = 1.” is considered here. It is closely related to the
problem of fast computing the algebraic degree of Boolean functions. It is an important cryptographic parameter
used in the design of S-boxes in modern block ciphers, pseudo-random numbers generators in stream ciphers, at
Reed-Muller codes, etc. To find effective solutions to this problem we explore the orders of the vectors of the
n-dimensional Boolean cube {0, 1}n in accordance with their weights. The notion of “k-th layer” of {0, 1}n is
involved in the definition and examination of the “weight order” relation. It is compared with the known relation
“precedes”. Several enumeration problems concerning these relations are solved and the corresponding comments
were added to 3 sequences in the On-line Encyclopedia of Integer Sequences (OEIS). One special order (among
the numerous weight orders) is defined and examined in detail. The lexicographic order is a second criterion
for an ordinance of the vectors of equal weights. So a total order called Weight-Lexicographic Order (WLO) is
obtained. Two algorithms for generating the WLO sequence and two algorithms for generating the characteristic
vectors of the layers are proposed. Their results were used in creating 2 new sequences: A294648 and A305860
in the OEIS. Two algorithms for solving the problem considered are developed—the first one works in a byte-wise
manner and uses the WLO sequence, and the second one works in a bitwise manner and uses the characteristic
vector as masks. The experimental results from numerous tests confirm the efficiency of these algorithms. Some
other applications of the obtained algorithms are also discussed—for example, when representing, generating and
ranking other combinatorial objects.
Key–Words: Boolean cube, binary vector, serial number, lexicographic order, weight order, characteristic vector,
layer, maximum chains enumerating, weight-lexicographic order, generating algorithm, search algorithm
1 Introduction
The algebraic degree of Boolean function (or vectorial Boolean function, called S-box) is an important
cryptographic parameter. It is used in the design of Sboxes for modern block ciphers, pseudo-random numbers generators in stream ciphers, at the Reed-Muller
codes, etc. [7, 8, 2]. The algorithms that compute this
parameter (as well as the other cryptographic parameters) must be very fast since when generating such examples, this parameter is computed for each of them.
As faster is the algorithm, more examples can be generated and a better choice among them to be done.
The problem we consider here is closely related
to the problem of computing the algebraic degree of
Boolean function. It is: “Given a Boolean function
f of n variables by its Truth Table vector, denoted
by T T (f ). Find (if exists) a vector α ∈ {0, 1}n of
maximal (or minimal) weight, such that f (α) = 1.”.
For brevity, we call this problem VectorOfMaxWeight.
The simplest way to solve it is to perform an exhaustive (linear) search: for each vector β ∈ {0, 1}n
it checks whether f (β) = 1 and selects the vector
of maximal (resp. minimal) weight. Since the values (coordinates) in T T (f ) correspond to the lexicographic order of the vectors of {0, 1}n , the algorithm cannot stop before to check each coordinate
of f . So, it performs Θ(2n ) checks. However, if
the values of T T (f ) are checked in accordance with
the vectors’ weights, from the highest to the lowest
weight, the search will finish after finding the first
vector β ∈ {0, 1}n , such that f (β) = 1. Once the
desired weight order of the vectors has been obtained,
this approach needs O(2n ) checks. This order can be
obtained by an algorithm that: (1) computes the vectors’ weights and (2) sorts the vectors in accordance
with their weights. So it needs at least Θ(n.2n ) oper-
ations. Instead of this simple solution, here we investigate the properties of the weight order relation defined on {0, 1}n . These properties are applied to solve
some enumeration problems and have useful generalizations and applications that are the basis for creating more efficient algorithms. Another approach for
computing the algebraic degree of Boolean function
f , that investigates the support of f , derives and uses
its algebraic properties, is proposed in [9].
This paper represents the comprehensive study
of the subject under discussion and the results obtained so far (the first of them were reported in [4]).
It is organized as follows. The necessary basic notions concerning the Boolean cube and their properties are given in Section 2. In Section 3, the relation “precedes by weight” is defined, examined and
compared with the known relation “precedes”. Some
enumeration problems concerning both relations are
solved and the corresponding notes were added to
the sequences A051459, A001142 and A000142 in
the OEIS [17]. In Section 4 one special order called
a Weight-Lexicographic Order (WLO) is introduced
and explored. Two algorithms for generating the
WLO sequence ln are proposed. A third algorithm,
that uses the sequence ln in solving the problem VectorOfMaxWeight, is also proposed and discussed. The
results in this section were used in creating the sequence A294648 in the OEIS [17]. In Section 5, the
characteristic vectors of the layers and their generating are considered. A bitwise version of an algorithm
for solving the problem VectorOfMaxWeight is discussed, where these vectors are used as masks. The
sequence A305860 in OEIS [17] was created by using the results from this section. Section 6 shows the
experimental results from numerous tests conducted
for comparison of the efficiency of algorithms discussed. The results show convincingly the superiority of the algorithms based on WLO. The last section contains comments and explanations about the
algorithms based on WLO and their applications in
computing the algebraic degree of Boolean functions.
Some applications of the obtained algorithms in generating other combinatorial objects, their representations, ranking/unranking are also discussed.
vectors. So their number is |{0, 1}n | = |{0, 1}|n =
2n . However, the following alternative, inductive and
constructive definition is more useful further.
2 Basic notions, properties
Theorem 3. If the vectors of {0, 1}n are obtained in
accordance with Definition 1, then:
1) They are in lexicographic order.
2) The serial numbers of the vectors form the sequence of natural numbers: 0, 1, . . . , 2n − 1. So
α ≤ β if and only if #α ≤ #β.
3) The weights of the vectors in the second half
of {0, 1}n are obtained by adding 1 to the weights of
corresponding vectors from the first half of the cube.
The necessary basic concepts about the Boolean cube
and their properties are represented following [3]. Let
N be the set of natural numbers, and N+ = N\{0} be
the set of positive natural numbers.
Usually, the n-dimensional Boolean cube is defined as {0, 1}n = {(x1 , x2 , . . . , xn )|xi ∈ {0, 1}, i =
1, 2, . . . , n}, i.e., the set of all n-dimensional binary
Definition 1. 1) The set {0, 1} = {(0), (1)} is called
one-dimensional Boolean cube and its elements (0)
and (1) are called one-dimensional binary vectors.
2) Let {0, 1}n−1 = {α0 , α1 , . . . , α2n−1 −1 } be the
(n − 1)-dimensional Boolean cube and α0 , α1 , . . . ,
α2n−1 −1 be its (n − 1)-dimensional binary vectors.
3) The n-dimensional Boolean cube {0, 1}n is built
by taking the vectors of {0, 1}n−1 twice: firstly, each
vector of {0, 1}n−1 is prefixed by zero, and thereafter
each vector of {0, 1}n−1 is prefixed by one, i.e.,
{0, 1}n =
{(0, α0 ), (0, α1 ), . . . , (0, α2n−1 −1 ),
(1, α0 ), (1, α1 ), . . . , (1, α2n−1 −1 )}.
n be an arbiLet α = (a1 , a2 , . . . , an ) ∈ {0, 1}P
trary vector. The natural number #α = ni=1 ai .2n−i
is called a serial number of the vector α. So #α is the
natural number whose n-digit binary representation is
a1 a2 . . . an . A weight (or Hamming weight) of α is
the natural number wt(α), equal to theP
number of nonzero coordinates of α, i.e., wt(α) = ni=1 ai . These
and some of the following notions are illustrated in
Figure 1 and Example 6.
Definition 2. For arbitrary vectors α = (a1 , a2 , . . . ,
an ) and β = (b1 , b2 ,. . . , bn ) ∈ {0, 1}n , the relation
lexicographic precedence R≤ ⊆ {0, 1}n × {0, 1}n is
defined as follows: (α, β) ∈ R≤ , if α = β or ∃ i, 1 ≤
i ≤ n, such that ai < bi , and aj = bj for j < i. When
(α, β) ∈ R≤ we say that α lexicographically precedes
β and write α ≤ β.
The relation R≤ is reflexive, antisymmetric and
transitive. Furthermore, each pair of vectors α, β ∈
{0, 1}n are comparable with respect to R≤ , i.e., either
α ≤ β, or β ≤ α holds. So R≤ is a total order in
{0, 1}n . This means that its vectors can be ordered
(or sorted) lexicographically in a unique way in the
sequence α0 , α1 , . . . , αk , . . . , α2n −1 , such that αl ≤
αk , ∀ l < k, and αk ≤ αr , ∀ k < r, and for any
k = 0, 1, . . . , 2n − 1.
Following Definition 1, the proof of the theorem
by induction on n is easy and that is why it is omitted. The theorem states the bijection between the vectors in lexicographic order and their serial numbers,
i.e., the vectors of {0, 1}n are in lexicographic order
if and only if the sequence of their serial numbers is
0, 1, . . . , 2n −1. It also shows the relation between the
vectors in lexicographic order and their weights. Its
assertions are illustrated in Figure 1. The right column
is the sequence A000120 in the OEIS [17], titled “1’scounting sequence: number of 1’s in binary expansion
of n (or the binary weight of n).”. This column shows
that the sequence of weights for the lower half of each
subcube is obtained by the addition of the number 1
to the corresponding terms of the sequence for the upper half of the same subcube, following the third (inductive) step of Definition 1. These relations can be
used for efficient computing of the vectors’ weights of
{0, 1}n , as in [6]. Analogously, the left column shows
that the sequence of serial numbers in the lower half
of each subcube is obtained from the corresponding
sequence of the upper half of the same subcube by
consecutive addition of the number 21 , 22 , . . . , 2n−1 ,
following the third step of Definition 1 again.
fined as Hn = (Vn , En ), where Vn = {0, 1}n and
En = {{α, β}| α, β ∈ {0, 1}n : d(α, β) = 1}, i.e.,
the vectors of the cube are vertices of Hn and each
pair adjacent vectors are connected by an edge. The
graphs H1 , . . . , H4 are shown in Figure 2.
Figure 2: The graphs H1 , . . . , H4
Definition 4. The precedence relation is denoted by
R and it is defined as follows: for arbitrary vectors
α = (a1 , a2 , . . . , an ), β = (b1 , b2 , . . . , bn ) ∈ {0, 1}n ,
(α, β) ∈ R if ai ≤ bi , ∀ i = 1, 2, . . . , n. When
(α, β) ∈ R we say that α precedes β and write α
β. When α β or β α the vectors α and β are
called comparable, and otherwise—incomparable.
Figure 1: Illustration of the statement of Theorem 3
Let α = (a1 , a2 , . . . , an ) and β = (b1 , b2 , . . . ,
bn ) be arbitrary vectors of {0, 1}n . A Hamming distance between α and β is the natural number d(α, β)
equal to the number of coordinates in which α and β
differ. If d(α, β) = 1, then α and β are called adjacent, or more precisely adjacent in i-th coordinate
if they differ in this coordinate only. If d(α, β) = n,
the vectors α and β are called opposite to each other.
The graph of the n-dimensional boolean cube is de-
R is reflexive, antisymmetric and transitive, and
so it is a partial order in {0, 1}n . Thus {0, 1}n is a
partially ordered set (POSet) with respect to R . It is
denoted by ({0, 1}n , R ) or simply by ({0, 1}n , ).
R is not a total order because not all pairs α, β ∈
{0, 1}n are comparable—for example, all vectors of
equal weights are incomparable.
The vector α ∈ {0, 1}n is called a minimal element of the POSet ({0, 1}n , R ), if α β, for any
β ∈ {0, 1}n . Analogously, the vector δ ∈ {0, 1}n
is called a maximal element of ({0, 1}n , R ), if
γ δ, for any γ ∈ {0, 1}n . So, the zero vector ~0n = (0, 0, . . . , 0) of n-coordinates and the allones vector ~1n = (1, 1, . . . , 1) of n-coordinates are
the minimal and the maximal elements of the POSet
({0, 1}n , ), correspondingly. If any pair of vectors
of the subset C ⊂ {0, 1}n are comparable, they can
be ordered in a unique way in a chain, for example
αi1 , αi2 , . . . , αik , . . . , αim , such that αil αik , for
l < k, and αik αir , for k < r, and for k =
1, 2, . . . , m. A chain that is not a proper subset of any
other chain is a maximal chain. For example, (0, 0, 0),
(0, 1, 0), (1, 1, 0), (1, 1, 1) is a maximal chain in
{0, 1}3 , whereas (0, 1, 0, 0), (0, 1, 0, 1), (1, 1, 0, 1),
(1, 1, 1, 1) is not a maximal chain in {0, 1}4 —see Figure 2. The maximal chain should contain the minimal
and maximal element of the corresponding POSet.
Each chain of greatest possible size is called a maximum (or longest) chain.
Definition 5. Let U = {x1 , x2 , . . . , xn } be a given
set, n ∈ N+ , and X ⊆ U . The vector α = (a1 , a2 ,
. . . , an ) ∈ {0, 1}n , defined as:
ai =
0, if xi ∈
/X,
1, if xi ∈ X ,
for i = 1, 2, . . . , n, is called a characteristic vector of
the set X.
Example 6. Let U = {a, b, c, d, e, f }, X = {b, c, e}
and Y = {c, a, f, d}. Since |U | = 6, α =
(0, 1, 1, 0, 1, 0) ∈ {0, 1}6 is the characteristic vector of X, and β = (1, 0, 1, 1, 0, 1)—the characteristic
vector of Y . The vectors γ = ~06 and δ = ~16 are the
characteristic vectors of ∅ ⊆ U and U ⊆ U , correspondingly. Furthermore:
• #α = 26, #β = 45, #γ = 0, #δ = 65;
• wt(α) = 3, wt(β) = 4, wt(γ) = 0, wt(δ) = 6;
• d(α, γ) = 3, d(α, β) = 5, d(β, δ) = 2, etc.;
• γ ≤ α ≤ β ≤ δ, in accordance with Definition 2
and Theorem 3;
• γ α, γ β, α δ, β δ, etc., but α and β
are incomparable with respect to R .
Theorem 7. Let U be an n-element set, n ∈ N+ , and
P(U ) be the power set of U . Let f : P(U ) → {0, 1}n
be a function defined as follows: f (X) = α, where
α ∈ {0, 1}n is the characteristic vector of X, for any
X ∈ P(U ). Then f is a bijection.
The proof of the theorem is omitted because it
is trivial. The function f from Theorem 7 bijectively relates (maps) the bitwise operations on the
binary vectors to the operations on the subsets of a
given n-element set U as follows: ∨ (disjunction)
and ∪ (union); ∧ (conjunction) and ∩ (intersection);
(negation) and (complement); ⊕ (sum modulo
2, XOR) and ∆ (symmetric difference), correspondingly. These properties are generalized in the following theorem [15, 12, 11].
Theorem 8. Let U be an n-element set, n ∈ N+ .
Then the Boolean algebras (P(U ), ∪, ∩, , ∅, U ) and
({0, 1}n , ∨, ∧, , ~0n , ~1n ) are isomorphic.
Furthermore, the bijection f from Theorem 7
concerns the relations R⊆ (defined on a given universal set U , |U | = n ∈ N+ ) and R (defined on
{0, 1}n ). For arbitrary A, B ⊆ U , having characteristic vectors α, β ∈ {0, 1}n , correspondingly, it is easy
to prove that A ⊆ B ⇔ α β, i.e., (A, B) ∈ R⊆
⇔ (f (A), f (B)) ∈ R . Thus f is an isomorphism
between the POSets (P(U ), R⊆ ) and ({0, 1}n , R )
that preserves the relations and the orders corresponding to them. This property is illustrated in Figure 5 by
the graphs of the corresponding relations, for n = 3.
These important structural properties are used in
[13, 1, 16, 19, 14, 18, 10, 20], etc., for:
• Computer representations of sets by binary vectors or arrays and performance of the basic operations on them. The concepts of characteristic vector and serial number, bijectively related
by Theorem 7, are used for ranking/unranking of
the subsets of a given universal set and this is the
most natural ranking/unranking function.
• Generating all subsets (or the k-element subsets,
k-combinations) of a given n-element set in a
definite order.
The following exposition is related to all these
properties and applications.
3 The weight-order relation and enumeration problems related to it
Definition 9. For an arbitrary k ∈ N, k ≤ n, the set of
all n-dimensional binary vectors of weight k is called
a k-th layer of the n-dimensional Boolean cube. We
denote it by Ln,k = {α| α ∈ {0, 1}n : wt(α) = k}.
Figure 2 illustrates the notion of layer from Definition 9. All vectors in the same horizontal level in
the figure form the corresponding layer of the cube.
Since k coordinates can be chosen among
n coordin
nates (and filled
in
with
units)
in
ways,
hence
k
|Ln,k | = nk , for k = 0, 1, . . . , n. The family of
all layers Ln = {Ln,0 , Ln,1 , . . . , Ln,n } is a partition
of the n-dimensional Boolean cube into layers and
hence:
n
n
n
X
X
[
n
|Li | =
Li =
= 2n = |{0, 1}n | .
k
i=0
k=0
k=0
Moreover, the sequence of layers Ln,0 , Ln,1 , . . . , Ln,n
is an order of the vectors of {0, 1}n in accordance with
their weights. So, if α, β ∈ {0, 1}n and wt(α) <
wt(β), then α precedes β in the sequence of layers,
and when wt(α) = wt(β) = k, then α, β ∈ Ln,k and
there is no precedence between them. More precisely,
the corresponding relation R<wt can be defined as follows: for arbitrary α, β ∈ {0, 1}n , (α, β) ∈ R<wt
if wt(α) < wt(β). We want R<wt to be reflexive
and we set (α, α) ∈ R<wt . When (α, β) ∈ R<wt
we say that ”α precedes by weight β” and write also
α <wt β. It is easy to verify that R<wt is a partial
order in {0, 1}n and we refer to it as a Weight-Order
(WO) further.
The vectors of Ln,k can be rearranged in nk!
Q
ways, for k = 0, 1, . . . , n. Thus we obtain nk=0 nk !
ways for WO of the vectors of {0, 1}n .
The
product values obtained for n = 1, 2, 3, 4, . . . are
1, 2, 36, 414720, . . . , correspondingly. They form the
sequence A051459 in the OEIS [17], which is defined by Yuval Dekel (Nov 15 2003) very shortly as
“Number of orderings of the subsets of a set with n
elements that are compatible with the subsets’ sizes;
i.e., if A, B are two subsets with A <= B then
Card(A) <= Card(B)”. This description corresponds to the assertion of Theorem 7 and to the notion
WO, since the vectors in the layer Ln,k are characteristic vectors of all k-element subsets of an n-element
set,
Qn for nk = 0, 1, . . . , n. In addition, we note that
k=0 k ! is the number of all possible topological
orders (or sorts) of the directed acyclic graph defined
by the same POSet. The corresponding comments
were added to the sequence A051459.
Theorem 10. The number of maximum
in the
Q chains
POSet ({0, 1}n , R<wt ) is equal to nk=0 nk , for any
n ∈ N+ .
Proof. We consider the POSet ({0, 1}n , R<wt ), for
arbitrary n ∈ N+ . A maximum chain cannot contain
2 or more vectors from the same layer because there
is no precedence by weight between any two vectors
from the same layer. So the length of any maximum
chain is equal to the number of layers in {0, 1}n ,
which
is n + 1. For each k = 0, 1, . . . , n, there are
n
ways
to choose a vector from Ln,k which to park
ticipate in a maximumQ
chain. Following
the multipli
cation rule, there are nk=0 nk maximum chains in
this POSet.
Q
The formula nk=0 nk means the product of binomial coefficients from the n-th row of Pascal triangle. Its values obtained for n = 1, 2, 3, 4, 5 . . . are
1, 2, 9, 96, 2500 . . . , correspondingly, and they form
the sequence A001142 in the OEIS [17]. The assertion of Theorem 10 was added in the description of
A001142.
Let us consider the connection between the relations R<wt and R . We note that α β always
implies α <wt β. However, α <wt β does not imply α β in the general case. A simple example that confirms this assertion is: α = (1, 0, 0, 0),
β = (0, 1, 1, 0) and so α <wt β, whereas α and β are
incomparable with respect to the relation ””. Therefore R ⊂ R<wt .
We can enumerate the maximum chains in the
POSet ({0, 1}n , R ) with the help of the next assertion.
Lemma 11. Let α be an arbitrary vector of the layer
Ln,k , for some integer k, 0 < k < n. Then α has k
adjacent vectors in the layer Ln,k−1 and also n − k
adjacent vectors in the layer Ln,k+1 .
Proof. Let β ∈ Ln,k be an arbitrary vector such that β
contains units in the coordinates i1 , i2 , . . . , ik , where
1 ≤ i1 ≤ · · · ≤ ik ≤ n. The set of all vectors adjacent
to β is partitioned into two subsets. The first one contains all vectors α, such that α β, i.e., exactly one of
the coordinates i1 , i2 , . . . , ik is inverted to zero and all
remaining coordinates are the same. Hence, there are
k such vectors and they are elements of Ln,k−1 . The
second subset contains all vectors γ, such that β γ,
i.e., all coordinates i1 , i2 , . . . , ik are ones and exactly
one of the remaining n − k coordinates is inverted to
one. So the number of all these vectors is n − k and
they belong to Ln,k+1 .
Theorem 12. The number of maximum chains in the
POSet ({0, 1}n , R ) is equal to n! , for any n ∈ N+ .
Proof. Obviously, the length of any maximum chain
is equal to the number of layers in {0, 1}n , which is
n + 1. Let ~0n , α1 , . . . , αk , . . . , αn−1 , ~1n be a maximum chain. Starting from the vector ~0n and following Lemma 11, there are n possible ways to choose
the vector α1 ∈ Ln,1 which is adjacent to ~0n . There
are n − 1 possible ways to choose a vector α2 ∈ Ln,2
which is adjacent to α1 , etc. There are k ways to
choose a vector αk ∈ Ln,k which is adjacent to
αk−1 , etc. Finally, the last vector ~1n can be chosen in a unique way. Applying the multiplication
rule we obtain that the number of maximum chains
is n.(n − 1) . . . k . . . 2.1 = n!.
The values of n!, for n = 0, 1, 2, . . . , form the
sequence A000142 (called Factorial numbers) in the
OEIS [17]. Among its numerous comments, only one
corresponds to the assertion of Theorem 12. It was
done on Feb 05 2006 by Rick L. Shepherd as follows: “The number of chains of maximal length in the
power set of 1, 2, ..., n ordered by the subset relation.”.
Beside the assertion of Theorem 12, one more comment was added to the sequence A000142—it contains the number of all shortest paths (obtained by
Breadth First Search, for example) between the nodes
~0n and ~1n in the graph Hn .
4 The weight-lexicographic order relation and two generating algorithms
To solve the problem formulated in Section 1 we need
the serial numbers of the vectors in the sequence of
layers instead of the vectors themselves. So, we shall
represent the WO of {0, 1}n by the sequence of serial
numbers of the vectors in the layers, in accordance
with Theorem 3. For that purpose, for an arbitrary
layer Ln,k = {α0 , α1 , . . . , αm } of {0, 1}n , we denote
by ln,k = #α0 , #α1 , . . . , #αm the sequence of
serial numbers, corresponding to the vectors of Ln,k .
If ln = ln,0 , ln,1 , . . . , ln,n denotes the sequence of
all serial numbers, corresponding to the vectors in
the sequence of layers Ln,0 , Ln,1 , . . . , Ln,n , then ln
represents a WO of the vectors of {0, 1}n . Briefly, we
refer to ln as a WO sequence
of {0, 1}n . We note that
Qn
n
any of all possible k=0 k ! WO sequences can be
used in solving the considered problem. But one of
them deserves a special attention and we propose two
algorithms for its generating. The first one (called
simply Algorithm 1) is similar to the known Bucket
sort algorithm [10]. We consider each sequence
ln,k as a bucket B[k] for all vectors of weight k, for
k = 0, 1, . . . , n. For more clarity and convenience,
we assume that the buckets are represented by lists.
Here is the pseudocode of Algorithm 1.
Algorithm 1. Computing the sequence ln .
Input: the integer n ∈ N+ .
Output: the sequence ln .
Procedure:
1. Precomputing: following Theorem 3 and explanations after it, compute and store the weights of the
vectors of {0, 1}n in the array wt. So, for i = 0, 1,
. . . , 2n − 1, set wt[i] = weight(α), where #α = i.
2. Initialization: for k = 0, 1, . . . , n, set B[k] =
N U LL (i.e., empty list). Set ln = N U LL.
3. Filling in the buckets: for i = 0, 1, . . . , 2n − 1,
append the number i to the end of B[wt[i]].
4. Concatenation: for k = 0, 1, . . . , n, append the list
B[k] to the end of ln.
5. Return ln.
Notes and comments on Algorithm 1:
• Its procedure and the explanations above imply
its correctness.
• Its time complexity is a sum of the time complexities of its steps 1–4. Thus we obtain Θ(2n ) +
Θ(n) + Θ(2n ) + Θ(n) = Θ(2n ), which is of
exponential type with respect to the size of the
input. It can not be better since it produces an
output of exponential size. But more important
is that the algorithm has a linear time complexity
with respect to the size of the output.
• In step 3, append the number i to B[wt[i]] means
that if wt[i] = k, then the integer i is appended
to B[k].
• Sorting buckets is not necessary and such a step
is omitted. Any permutation into any bucket does
not change WO of the entire list (sequence).
In step 3 it is written “append . . . to the end . . . ”.
Because of this and since the vectors are processed
(by their serial numbers) in lexicographic order (see
the cycle “for . . . ”), the integers in any bucket will
be sorted. So the numbers in each subsequence ln,k
are in strictly increasing order, for 0 ≤ k ≤ n, which
means that the corresponding vectors in Ln,k are in
lexicographic order, for 0 ≤ k ≤ n. Hence, after step
4 a total weight order for the sequence ln is obtained,
where the lexicographic order is a second criterion for
ordering the vectors of equal weights. We call it a
Weight-Lexicographic Order (WLO) and then WLO
algorithm 1 is a more correct name of Algorithm 1.
Let us continue with the mathematical bases for
the second algorithm. We need the following operation on a sequence of integers.
Definition 13. Let n, m ∈ N+ and s = a1 , a2 , . . . , an
be a sequence of integers. We define the operation
addition of the natural number m to the sequence s as
follows: s + m = a1 + m, a2 + m, . . . , an + m.
This operation can be seen in Figure 1. Following
the idea in this figure and Definition 1, we define one
special WO sequence ln inductively.
Definition 14. 1) The WO sequence of the onedimensional Boolean cube is l1 = 0, 1.
2) Let ln−1 = ln−1,0 , ln−1,1 , . . . , ln−1,n−1 be the WO
sequence of the (n − 1)-dimensional Boolean cube.
3) The WO sequence of n-dimensional Boolean cube
ln = ln,0 , ln,1 , . . . , ln,n is defined as follows:
• ln,0 = 0 and it corresponds to the layer Ln,0 =
{~0n };
• ln,n = 2n − 1 and it corresponds to the layer
Ln,n = {~1n };
• ln,k = ln−1,k , ln−1,k−1 + 2n−1 , for k =
1, 2, . . . , n − 1. Here ln,k is a concatenation of two
sequences: the sequence ln−1,k is taken (or copied)
firstly, and the sequence ln−1,k−1 + 2n−1 follows after
it. The sequence ln,k corresponds to the layer Ln,k .
The corresponding recursive definition of ln is:
If n = 1, then l1 = 0, 1 .
If n >
1, then ln = ln,0 , . . . , ln,k , . . . , ln,n , where:
0, if k = 0,
2n − 1, if k = n,
ln,k =
ln−1,k , ln−1,k−1 + 2n−1 , for 0 < k < n .
Figure 3 and Figure 4 illustrate how the WO sequences l2 and l3 are obtained in accordance with Definition 14.
Figure 3: The WO sequence l2 , obtained from l1
Figure 4: The WO sequence l3 , obtained from l2
The last two definitions resemble the definition of
Pascal’s
triangle. As we noted, the length of ln,k =
n
for k = 0, 1, . . . , n. Instead of the rule
k = |Ln,k |,
n
n−1
n−1
=
+
used in Pascal’s triangle, we
k
k−1
k
use a similar rule ln,k = ln−1,k , ln−1,k−1 + 2n−1 . The
next theorem clarifies it.
Theorem 15. Let n ∈ N+ and ln = ln,0 , ln,1 , . . . , ln,n
be the WO sequence, obtained in accordance with
Definition 14. Then ln represents the vectors of
{0, 1}n in WLO.
Proof. We prove the theorem by induction on m, m ∈
N+ , following Definition 14.
1) For m = 1 the assertion is obvious.
2) Suppose that the theorem holds for an arbitrary integer m > 1: the sequence lm = lm,0 , lm,1 ,
. . . , lm,m obtained in accordance with Definition 14
represents the vectors of {0, 1}m in WLO.
3) Let lm+1 = lm+1,0 , lm+1,1 , . . . , lm+1,m+1 be
the sequence, obtained in accordance with Definition
14. For lm+1,0 = 0 and lm+1,m+1 = 2m+1 − 1,
the corresponding layers Lm+1,0 = {~0m+1 } and
Lm+1,m+1 = {~1m+1 } are in lexicographic order.
Furthermore, lm+1,0 and lm+1,m+1 are in their right
places in lm+1 . Let lm+1,k be one of the rest of
the subsequences in lm+1 , for an arbitrary integer
k, 1 ≤ k ≤ m. In accordance with Definition
14, lm+1,k is a concatenation of two subsequences:
lm,k and lm,k−1 + 2m , placed in that order. So, the
layer Lm+1,k corresponding to lm+1,k is partitioned
into two groups. The first one consists of all vectors of Lm+1,k , that begin with zero. Hence their
serial numbers coincide with these in the sequence
lm,k . It corresponds to the layer Lm,k , whose vectors are in lexicographic order, in accordance with the
inductive suggestion. So the vectors in the first group
are also in lexicographic order. The second group includes all vectors of Lm+1,k that begin with one. So
their serial numbers are obtained by an addition of
the integer 2m to the serial numbers of the sequence
lm,k−1 . Following the inductive suggestion, the vectors of the corresponding layer Lm,k−1 are in lexicographic order and therefore the vectors in the second group are also in lexicographic order. Moreover,
each vector from the first group precedes lexicographically each vector from the second group. Therefore,
the sequence lm+1,k determines a lexicographic order
into the corresponding layer Lm+1,k . This conclusion holds for any integer k, 1 ≤ k ≤ m. So, the
subsequences lm+1,0 , lm+1,1 , . . . , lm+1,m+1 represent
the corresponding layers in a WO. In addition, each
subsequence determines a lexicographic order into the
corresponding layer. Therefore the sequence lm+1
represents the vectors of {0, 1}m+1 in a WLO. So the
theorem is proven.
The second algorithm that we developed is called
WLO algorithm 2. It computes the sequence ln for
a given input n ∈ N+ . The algorithm uses an array
(denoted by P_t) for the binomial coefficients from
Pascal’s triangle that represents the lengths of the subsequences and one more array (denoted by ss_beg)
where the beginning of each subsequence is computed
and stored. The values in these two arrays are computed firstly. The code of the corresponding function
is simple and it is omitted. WLO algorithm 2 is based
on Definition 14. Starting from l1 it computes consec-
utively the sequences l2 , l3 , . . . , ln in the array seqs,
as shown by the C/C++ programming language.
Listing 1: Computing the WLO sequence ln
t yp ed ef unsigned i n t u i n t ;
void f i l l i n s e q s ( i n t n ) {
seqs [1][0]= 0; / / i n i t i a l i z a t i o n
s e q s [ 1 ] [ 1 ] = 1 ; / / f o r n =1: l 1
u i n t m= 2 ; / / t o be added t o a s u b s e q .
f o r ( i n t r = 2 ; r <=n ; r ++) {
seqs [ r ][0]= 0;
u i n t k =1;
f o r ( i n t c = 1 ; c<=r ; c ++) {
/ / Preparing for step 1
u i n t s e q l e n = P t [ r −1][ c ] ;
u i n t s s b e g = s s b e g [ r −1][ c ] ;
/ / step 1 − copying a subsequence
f o r ( u i n t j = 0 ; j <s e q l e n ; j ++)
s e q s [ r ] [ k ++]= s e q s [ r −1][ s s b e g + j ] ;
/ / Preparing for step 2
s e q l e n = P t [ r −1][ c −1];
s s b e g = s s b e g [ r −1][ c −1];
/ / s t e p 2 − add m t o a s u b s e q u e n c e .
f o r ( u i n t j = 0 ; j <s e q l e n ; j ++)
s e q s [ r ] [ k ++]= s e q s [ r −1][ s s b e g + j ] +m;
}
m ∗= 2 ;
}
}
Some results obtained by the WLO algorithms,
for n = 1, 2, . . . , 5, are given in Table 1. More results
can be seen in the OEIS [17], sequence A294648. The
results represented above were used in its creation.
n
1
2
3
4
5
ln
0, 1
0, 1, 2, 3
0, 1, 2, 4, 3, 5, 6, 7
0, 1, 2, 4, 8, 3, 5, 6, 9, 10, 12, 7, 11, 13, 14, 15
0, 1, 2, 4, 8, 16, 3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 7, . . .
Table 1: Results obtained by the WLO algorithms, for
n = 1, 2, . . . , 5
As we said, WLO algorithm 2 is based on Definition 14 and follows its steps. This definition and
Theorem 15 determine its correctness. Let us compute the time complexity of the algorithm. The time
for filling in both additional arrays (P_t, for Pascal’s triangle and ss_beg, for the beginning of each
subsequence) is proportional to the number of integers that they contain, i.e., Θ(n2 ). The function
fill in seqs in Listing 1 runs as follows. On the
k-th step, 2 ≤ k ≤ n, it copies generally 2k−1 − 1
values from lk−1 to lk , and also it adds the constant
m = 2k−1 to 2k−1 − 1 members of lk−1 and stores
them in lk . So, it performs Θ(2k ) assignments and
Θ(2k−1 ) summations, i.e., Θ(2k ) operations generally on the k-th step. Therefore, the time complexity
of the algorithm is
n
X
k=2
k
Θ(2 ) = Θ
n
X
k=2
k
2
!
= Θ(2n+1 ) = Θ(2n ) .
So, the time complexity of WLO algorithm 2 is of
the same type as at WLO algorithm 1. Let us consider
the space complexity of WLO algorithm 2. For clarity,
in Listing 1 we use a two-dimensional array of size
2n × 2n and hence, the space complexity is Θ(22n ).
We recall that the existence of lk is sufficient to obtain
lk+1 . So, instead of the square array we can use:
• Two one-dimensional static arrays of size 2n —
for the existing sequence lk and for the new sequence lk+1 . After we obtain lk+1 , we change
the role of the arrays to obtain the next sequence
lk+2 , and so on.
• One-dimensional arrays of size 2k which are created/deleted dynamically in the k-th step, for
k = 1, 2, . . . , n.
In both cases the space complexity of the WLO algorithm reduces to Θ(2n ).
Let us return to the VectorOfMaxWeight problem and comment on the usage of WLO sequence
ln in its solving. Let f be a Boolean function of
n variables given by its true table vector T T (f ) =
(y0 , y1 , . . . , y2n −1 ). We want to find (if exists) a vector α ∈ {0, 1}n of maximal weight, such that f (α) =
1. After we know enough about the WLO, we do
not comment more on the trivial approach (exhaustive
search). The efficient solving of this problem consists
of consecutive checks of the coordinates of T T (f ) in
accordance with the WLO sequence ln , from the last
to the first term of it. Let k be the first number of a
non-zero coordinate in T T (f ). Then k = #α such
that f (α) = 1, α has a maximal weight and all other
such vectors (if exist) preceded lexicographically α.
This is seen in the following C/C++ code, where the
array f stands for T T (f ), and the arrays wt and ln
mean the same as in WLO algorithm 1.
Listing 2: Search by the WLO sequence ln
i n t vector of max weight ( bool f [ s i z e ] ) {
f o r ( i n t i = s i z e − 1 ; i >=0; i −−) {
i n t k= l n [ i ]
if ( f [k])
r e t u r n k ; / / and wt [ k ] i f n e c e s s a r y
}
r e t u r n −1; / / when f i s t h e 0− c o n s t a n t
}
The distribution of Boolean functions according
to their algebraic degrees given in [5] and [17, sequence A319511] shows that when n grows, almost
100% of all Boolean functions of n variables have
algebraic degree n or n − 1 (i.e., exists a vector of
weight n or n − 1 which is a solution to the VectorOfMaxWeight problem). So, this search will finish
after no more than n + 1 checks at almost 100% of
all such functions. But the general time complexity of
this search is proportional to the length of WLO sequence ln , and so it is O(2n ). For brevity, we call this
algorithm Search by WLO.
Finally, we note that the bijection between the
n-dimensional Boolean cube and the power set of
a given n-element set (Theorem 7) means that both
WLO algorithms can have more general applications.
For example, they can be used in solving problems
related to representing and generating the subsets of
a given set in a certain order, or some of its subsets (for example, all subsets of k elements, or kcombinations), etc., as it is shown in Figure 5. In such
cases, the WLO sequence considered as a sequence of
serial numbers of characteristic vectors means a cardinality order of the subsets. Furthermore, if the elements of the set are in lexicographic order, the corresponding subsets of equal size will be in reverse lexicographic order. Figure 5 summarizes some of the
discussed results and illustrates:
• the bijection between subsequences of l3 and the
layers of {0, 1}3 ;
• the bijection f between the vectors of {0, 1}3 and
the subsets of {a, b, c} (see Theorem 7);
• the isomorphism f between the POSets
({0, 1}3 , ) and (P({a, b, c}), ⊆) by the graphs
of the corresponding relations.
Figure 5: Illustration of the bijections between the
sequence l3 , the layers of {0, 1}3 and the subsets
of {a, b, c}, as well as the isomorphism between the
POSets ({0, 1}3 , ) and (P({a, b, c}), ⊆)
5 Characteristic vectors (masks) of
the layers and their generating
So far we have considered the representation of the
vectors from the layer Ln,k by the corresponding sequence ln,k of their serial numbers, for k = 0, 1,
. . . , n. Another way for representation is by the characteristic vector mn,k of the layer Ln,k , for k = 0,
1, . . . , n (the denotation m comes from “mask” and
will be understood later). Following Definition 5, we
define it as follows: mn,k = (a0 , a1 , . . . , a2n −1 ) ∈
n
{0, 1}2 , where:
0, if αi ∈
/ Ln,k ,
ai =
1, if αi ∈ Ln,k ,
αi ∈ {0, 1}n , for i = 0, 1, . . . , 2n − 1.
Since the characteristic vectors are binary vectors,
they can be represented in a bitwise manner in one or
several compute words. For example, for given n, d ∈
N+ , where d is the number of bits in one computer
word, there are n + 1 characteristic vectors, and each
of them will occupy s computer words, where s = 1
if n ≤ d, or s = 2n−d if n > d.
Let f be a Boolean function of n variables given
by its T T (f ). This vector can be represented in a
byte-wise way or in a bitwise way. The byte-wise representation of T T (f ) is used in the Search by WLO
algorithm (see Listing 2). So it is natural to think
about its bitwise version of this algorithm. It is possible to check the bits of T T (f ) in accordance with
the WLO sequence ln . Then the corresponding algorithm will be similar to the byte-wise Search by WLO
algorithm and it will have the same time complexity.
However, we can check all vectors in the same layer
in one (or several, say s) step(s). For this purpose,
we shall use the characteristic vectors, since mn,k is a
binary vector of the same length as T T (f ) and mn,k
contains units only in these bits that correspond to the
integers in the subsequence ln,k (and hence these units
correspond to the vectors in Ln,k ), for k = 0, 1, . . . , n.
So, mn,k masks only the significant bits for Ln,k ,
0 ≤ k ≤ n, and that is why the characteristic vectors
are called masks in this application. Thus, we need to
repeat bitwise conjunctions between T T (f ) and mn,i ,
for i = n, n − 1, . . . , 0, until the result of the serial
conjunctions is zero. The first index k, 0 ≤ k ≤ n, for
which T T (f ) ∧ mn,k > 0 means that there are one or
more vectors in Ln,k , such that f takes a value 1 on
each of them. If the algorithm returns k (the maximal
weight) and stops, this is enough for computing the
algebraic degree of a Boolean function. But this is a
solution to the restricted version of the VectorOfMaxWeight problem since the algorithm does not return a
vector. When we need a vector, we have to process
the result of T T (f ) ∧ mn,k when it becomes > 0 for
the first time.
Let us comment on some details of the version
that computes only the maximal weight. We call it
Bitwise Search by WLO algorithm, accepting that it
always uses masks. When T T (f ) occupies one computer word, the algorithm performs at most n + 1
steps and so its time complexity is O(n), i.e., it is
of logarithmic type (n = log2 2n ) with respect to
the size of the input. If the size of computer word
is 64 = 26 bits and f is a function of n > 6 variables,
then T T (f ) occupies s = 2n−6 computer words. So,
mn,i will occupy s computer words also and the computing of T T (f ) ∧ mn,i will be done in s steps, for
i = n, n − 1, . . . , 0. If on some of these steps the conjunction between the corresponding computer words
of T T (f ) and mn,i is greater than zero, the algorithm returns i and stops. Therefore, in this (general)
case, the time complexity of the algorithm becomes
O(n).O(s) = O(n.2n−6 ). This is seen in the following C/C++ code, where the masks are represented
by a two-dimensional array. The number of its rows
is equal to the number of variables (n vars) +1, and
the number of columns is equal to the number of computer words (n cwords) used for the representation of
T T (f ) (the variable f in the code).
Listing 3: Bitwise Search by WLO
t yp ed ef unsigned long long u l l ;
i n t max deg by masks ( u l l f [ ] ) {
f o r ( i n t row= n v a r s ; row >= 0 ; row−−) {
f o r ( i n t c o l = 0 ; c o l <n c w o r d s ; c o l ++) {
i f ( f [ c o l ] & masks [ row ] [ c o l ] )
r e t u r n row ; / / t h e l a y e r ’ s number
}
}
r e t u r n −1; / / when f i s t h e 0− c o n s t a n t
}
It is important to consider the masks’ generating.
For arbitrary i, 0 ≤ i ≤ n, it is easy to put units in
all these bits of mn,i that correspond to the numbers
in the subsequence ln,i . So this way of generating the
masks has a time complexity which is proportional to
the length of WLO sequence ln , i.e., Θ(2n ).
We propose one more way to generate the masks.
As at the layers, we use the serial numbers of the
masks #mn,i instead of their vectors mn,i , for 0 ≤
i ≤ n. They will be obtained and stored in the necessary number of 64-bits computer words—as many
as for the T T (f ) vector. So, we can generate them in
accordance with the following definition.
Definition 16. 1) For n = 1, the serial numbers of the
masks corresponding to the subsequences l1,0 and l1,1
are #m1,0 = 2 and #m1,1 = 1.
2) Let #mn−1,0 , #mn−1,1 , . . . , #mn−1,n−1 be the
serial numbers of the masks corresponding to the subsequences ln−1,0 , ln−1,1 , . . . , ln−1,n−1 .
3) The serial number of the mask #mn,i corresponding to the subsequence ln,i is:
2n−1
n
.#mn−1,0 = 22 −1 , if i = 0 ,
2
1, if i = n ,
#mn,i =
2n−1 .#m
2
n−1,i + #mn−1,i−1 ,
if 0 < i < n ,
for i = 0, 1, . . . , n.
Definition 16 corresponds to definitions 1 and 14.
Its correctness can be proven strictly by mathematical induction. The algorithm for masks’ generating
based on this definition, as well as the previous one,
have some particularities when n > 6 and they work
with s = 2n−6 computer words. The running time for
generating (precomputing) the masks by each of these
two algorithms is negligible (≈ 0 seconds). The serial
numbers of the masks grow exponentially, as it is seen
in Table 2.
n=
1
2
3
4
#mn,0
2
8
128
32768
#mn,1
1
6
104
26752
#mn,2
–
1
22
5736
#mn,3
–
–
1
278
#mn,4
–
–
–
1
Table 2: The serial numbers of the masks, for n =
1, . . . , 4
These and some additional results were used in
creating the sequence A305860 in OEIS [17].
Example 17. We shall illustrate how the problem
considered is solved by the Byte-wise and Bitwise
Search by WLO algorithms, for a Boolean function
f of 4 variables. Its T T (f ), the coordinates’ numbers and the masks (for n = 4) are given in Table
3. When we use the Byte-wise WLO Algorithm, it
checks consecutively the coordinates of T T (f ), from
right to left, i.e., 15, 14, 13, 11, 7, 12—see the
WLO sequence l4 in Table 1. T T (f )f contains zeros in all coordinates before 12-th, but T T (f ) contains one in this coordinate and so the algorithm stops
after 6 checks. Since 12 is a term of l4,2 , hence the
vector of maximal weight (= 2) has a serial number 12. When the Bitwise WLO Algorithm is used,
it computes the conjunctions: T T (f ) ∧ m4,4 = 0,
T T (f ) ∧ m4,3 = 0, T T (f ) ∧ m4,2 > 0 and thereafter
it stops. So a vector of weight 2 is a solution to the
problem and it is computed in 3 steps. As a continuation outside the algorithm, the vector T T (f )∧m4,2 =
(0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0) contains units
in coordinates 3, 5, 6, 10, 12. They are the serial numbers of all vectors from {0, 1}4 that have weight 2 and
f takes a value 1 on each of them.
Coordinates’ numbers
T T (f ) =
#m4,0 = 32768, m4,0 =
#m4,1 = 26752, m4,1 =
#m4,2 = 5736, m4,2 =
#m4,3 = 278, m4,3 =
#m4,4 = 1,
m4,4 =
01234567
10010110
10000000
01101000
00010110
00000001
00000000
89012345
10101000
00000000
10000000
01101000
00010110
00000001
Table 3: The data used in Example 17
6 Experimental results
We developed three algorithms for solving a version
of the VectorOfMaxWeight problem where the algorithms compute the maximal weight of a vector α such
that f (α) = 1. Their names Exhaustive search, Bytewise Search by WLO and Bitwise Search by WLO
show how they work. We conducted a series of tests
to compare the efficiency of these algorithms after we
know their theoretical time complexities, i.e., to understand what is the difference between Θ(2n ) and
O(2n ) at this problem. All tests were executed on the
same computer (Intel Pentium CPU G4400, 3.3 GHz,
4GB RAM, Samsung SSD 650 120 GB), at the same
conditions. The programs were developed (and executed) under Windows 10 OS and MVS Express 2015
for Windows Desktop. They are written in C++ programming language, built in Release mode as 32-bits
and 64-bits console applications and executed without an Internet connection. All tests were executed
3 times and the running times are taken on average.
The T T (f ) vectors of all tested Boolean functions
are represented in a byte-wise and bitwise manner. In
the next tables, the time for conversion between these
types of representation, as well as the time for reading from a file, are excluded from the running times.
The time for generating (precomputing) the WLO sequence ln and the masks is negligible and it also is
excluded.
Table 4 shows the pure running time of the algorithms, for all 232 Boolean functions of 5 variables.
Implementation
32 bits appl.
64 bits appl.
Pure running time in seconds for:
Exhaustive Byte-wise
Bitwise
Search
S. by WLO S. by WLO
130.292
39.989
3,053
174.819
45.786
3,240
Table 4: Experimental results for all 232 Boolean
functions of 5 variables
To test Boolean functions of 6 and more variables,
we created and used a file of 108 randomly generated 64-bits unsigned integers (the file size is ≈ 1.39
GBytes). If n > 6 then 2n−6 integers are read from
the file and thus they form the consecutive Boolean
function. Tables 5 and 6 show the pure running time
of the algorithms being compared, for Boolean functions (BFs) of 6 and more variables.
Number of
variables
and BFs
6 vars,
108 BFs
8 vars,
108 /4 BFs
10 vars,
108 /16 BFs
12 vars,
108 /64 BFs
16 vars,
97656 BFs
Pure running time in seconds for:
Exhaustive Byte-wise
Bitwise
Search
S. by WLO S. by WLO
18.371
1.540
0,507
22.758
0.380
0,703
24.130
0.224
0,177
25.310
0.074
0.074
26.000
0.068
0.070
Table 5: Experimental results for the 32 bits implementations
Number of
variables
and BFs
6 vars,
108 BFs
8 vars,
108 /4 BFs
10 vars,
108 /16 BFs
12 vars,
108 /64 BFs
16 vars,
97656 BFs
Pure running time in seconds for:
Exhaustive Byte-wise
Bitwise
Search
S. by WLO S. by WLO
21.802
1.816
0,583
23.381
0.083
0,045
23.520
0.045
0,181
24.574
0.029
0,125
25.911
0.015
0.203
Table 6: Experimental results for the 64 bits implementations
These results clearly show the benefits of the
WLO approaches in solving the VectorOfMaxWeight
problem. The reader can make his own conclusions
about the efficiency depending on the algorithm chosen, its implementation, the number of variables, etc.
7 Conclusions
We should note, that the problem considered has very
specific searching space—almost 100% of all Boolean
functions of n variables are of degree n or n − 1, as it
is shown in [5] and [17, sequence A319511]. This fact
explains the efficiency of algorithms based on WLO,
as well as why the Byte-wise Search by WLO becomes faster than the Bitwise one when n grows. As
it was shown, in almost 100% of all cases the first algorithm finishes after at most n + 1 steps, whereas the
second—after at most n + 1 steps, when n ≤ 6, or
at most 2n−6 + 1 steps when n > 6. Thus (n + 1)
becomes smaller than 2n−6 + 1 when n > 9 and this
explains the results in tables 5 and 6 obtained by the
algorithms for searching by WLO.
We note that if the Boolean function is represented by the vector of coefficients of its algebraic
normal form instead of its T T (f ), then the algorithms
will compute the algebraic degree of this Boolean
function. We have already shown that the computing of this important cryptographic parameter can be
performed more efficiently by using WLO based algorithms.
At the end of Section 4 we discussed some other
applications of the algorithms for generating the WLO
sequence—in representing and generating all subsets
of a given set in a definite order, or some of its
subsets (for example, all k-element subsets, or kcombinations), etc. The same applications can have
the algorithms for generating the masks considered in
Section 5. It is important to note that the bijection
between the subsets, their characteristic vectors and
their serial numbers is a very simple and convenient
ranking/unranking function. All these algorithms use
and process only the serial numbers in generating, i.e.,
they do not generate the objects but their ranked representation. Furthermore, they do this very efficiently.
Acknowledgments: The author is grateful for the partial support from the Research Fund of the University
of Veliko Tarnovo, Bulgaria, under Contract FSD-31340-14/26.03.2019.
References:
[1] A. V. Aho, J. E. Hopcroft and J. D. Ullman, The
Design and Analysis of Computer Algorithms,
Addison-Wesley Publishing Company, 1974.
grees, Serdica Journal of Computing, Vol. 13,
No 1-2, 2019 (to appear).
[6] I. Bouyukliev I. and V. Bakoev, Efficient Computing of Some Vector Operations over GF(3)
and GF(4), Serdica Journal of Computing, 2,
2008, pp 137–144.
[7] C. Carlet, Boolean Functions for Cryptography and Error Correcting Codes, in: Y. Crama,
P. L. Hammer (Eds.), Boolean Models and Methods in Mathematics, Computer Science, and
Engineering, Cambridge Univ. Press, 2010, pp
257–397.
[8] C. Carlet, Vectorial Boolean Functions for Cryptography, in: Y. Crama, P. L. Hammer (Eds.),
Boolean Models and Methods in Mathematics,
Computer Science, and Engineering, Cambridge
Univ. Press, 2010, pp 398–469.
[9] J.-J. Climent, F. Garcı́a and V. Requena, The degree of a Boolean function and some algebraic
properties of its support. In: Data Management
and Security, WIT Press, 2013, pp. 25–36.
[10] T. Cormen, Ch. Leiserson, R. Rivest and Cl.
Stein, Introduction to Algorithms, Third Edition,
2009, The MIT Press.
[11] R. Garnier and J. Taylor, Discrete Mathematics
for New Technology, Second Edition, IOP Publishing Ltd, 2002.
[12] R. Grimaldi, Discrete and Combinatorial Mathematics. An Applied Introduction, Fifth Edition,
Addison-Wesley, 2004.
[13] D. Knuth, The art of computer programming,
Volume 4A: Combinatorial Algorithms, Part 1,
Addison-Wesley, 2011.
[2] A. Canteaut, Lecture notes on Cryptographic
Boolean Functions. Inria, Paris, France, 2016.
[14] D. Kreher and D. Stinson, Combinatorial algorithms: generation, enumeration and search,
CRC Press LLC, 1999.
[3] V. Bakoev, Discrete mathematics: Sets, Relations, Combinatorics, KLMN, Sofia, 2014. (in
Bulgarian)
[15] O. Kuznetsov, Discrete mathematics for engineers, Sixth Edition, Lan, St. PeterburgMoskow-Krasnodar, 2006. (in Russian)
[4] V. Bakoev, Ordinances of the vectors of the ndimensional Boolean cube in accordance with
their weights, Book of Abstracts of 14SMAK,
Kragujevac, Serbia, May 16–19, 2018, p. 103;
[16] A. Nijenhuis and H. Wilf, Combinatorial Algorithms for Computers and Calculators, Second
Edition, Academic Press, 1978.
[5] V. Bakoev, Distribution of the Boolean functions
of n variables according to their algebraic de-
[17] OEIS Foundation Inc., The On-line Encyclopedia of Integer Sequences. Accessible on-line at
https://oeis.org/
[18] E. Reingold, J. Nievergelt and N. Deo, Combinatorial algorithms, Theory and practice, PrenticeHall, New Jersey, 1977.
[19] F. Ruskey, Combinatorial Generation. Working
Version (1j-CSC 425/520), 2003. Accessible
on-line at
http://www.1stworks.com/ref/ruskeycombgen.pdf
[20] S. Skiena, The Algorithm Design Manual, Second Edition, Springer, 2008.