Thirteenth International Workshop on Algebraic and Combinatorial Coding Theory
June 15-21, 2012, Pomorie, Bulgaria
pp. 47–52
One more way for counting monotone Boolean
functions1
Valentin Bakoev
v.bakoev@uni-vt.bg
University of Veliko Turnovo, Bulgaria
Abstract. Here we represent the outline of a new algorithm for counting the
monotone Boolean functions of n variables. It is a continuation of our previous
investigation and results, related to this problem.
1
Introduction
In 1897 Dedekind sets the problem of counting the elements of free distributive
lattices of n generators, or equivalently, the number ψ(n) of monotone Boolean
functions (MBFs) of n variables. Since then the scientists investigate this problem in two main directions. The first one is to compute this number for a given
n – by deriving appropriate formulas for it, or by algorithms for counting, etc.
The second (when the first one is not successful enough) is to estimate this
number – many formulas for evaluating ψ(n) are obtained in [5–8]. In spite of
their efforts, the values of ψ(n) are known only for n ≤ 8 [4, 11, 12]:
n
0
1
2
3
4
5
6
7
8
ψ(n)
2
3
6
20
168
7 581
7 828 354
2 414 682 040 998
56 130 437 228 687 557 907 788
Computed by
R. Dedekind, 1897
R. Dedekind, 1897
R. Dedekind, 1897
R. Dedekind, 1897
R. Dedekind, 1897
R. Church, 1940
M. Ward, 1946
R. Church, 1965
D. Wiedemann, 1991
Table 1. ψ(n), for 0 ≤ n ≤ 8, and the history of their computing.
To feel the complexity of the problem we note that in 1991 Wiedemann
used a Cray-2 processor for about 200 hours to compute ψ(8). It took almost
a century to compute the last 4 values of ψ(n).
The algorithms for computing ψ(n) that we know, are not too numerous and
various. Most of them follow the principle ”generating and counting” [3, 4, 9,
10]. The algorithms in [11] use propositional calculus and #SAT-algorithms in
computing these numbers. The most powerful algorithms (represented in [4,12])
compute ψ(8) by appropriate decomposition of functions and/or sets.
1
This work is partially supported by V. Turnovo University Science Fund under Contract
RD-642-01/26.07.2010.
48
ACCT2012
This work continues our previous investigations of the Dedekind’s problem.
In [1, 2] we proposed a new algorithm for generating (and counting) all MBFs
up to 6 variables, based on the properties of a certain matrix structure. In
spite of its numerous improvements (the running-time for computing ψ(6) was
reduced to 0,5 sec.), it is not powerful enough for computing the next values.
Here we represent some new ideas about applying the dynamic-programming
strategy in solving the Dedekind’s problem.
2
Basic notions and preliminary results
Let {0, 1}n be the n−dimensional Boolean cube and α = (a1 , . . . , an ), β =
(b1 , . . . , bn ) be binary vectors in it. Ordinal number of α is the integer #(α) =
a1 .2n−1 + a2 .2n−2 + · · · + an .20 . Vector α precedes lexicographically vector β, if
∃ an integer k, 1 ≤ k ≤ n, such that ai = bi , for i = 1, 2, . . . , k − 1, and ak < bk ,
or if α = β. The vectors of {0, 1}n are in lexicographic order (as we consider
further) iff their ordinal numbers form the sequence 0, 1, . . . , 2n − 1.
The relation ”¹” is defined over {0, 1}n ×{0, 1}n as follows: α ¹ β if ai ≤ bi ,
for i = 1, 2, . . . , n. This relation is reflexive, antisymmetric and transitive and
so {0, 1}n is a partially ordered set (POSet) with respect to it. When α ¹ β or
β ¹ α we call α and β comparable, otherwise they are incomparable.
A Boolean function f of n variables is a mapping f : {0, 1}n → {0, 1}.
The function f is called monotone if for any α, β ∈ {0, 1}n , α ¹ β implies
f (α) ≤ f (β). It is well known that if f is a monotone function, it has an unique
minimal disjunctive normal form (MDNF), consisting of all prime implicants
of f , where all literals are uncomplemented.
We define a matrix of precedences of the vectors in {0, 1}n as follows: Mn =
||mi,j || has dimension 2n × 2n , and for each pair of vectors α, β ∈ {0, 1}n , such
that #(α) = i and #(β) = j, we set mi,j = 1 if α ¹ β, or mi,j = 0 otherwise.
Theorem 1. The matrix Mn is a block matrix, defined recursively, or by Kronecker product:
µ
M1 =
11
01
¶
µ
, Mn =
Mn−1 Mn−1
On−1 Mn−1
¶
,
or Mn = M1 ⊗ Mn−1 =
n
O
M1 ,
i=1
where Mn−1 denotes the same matrix of dimension 2n−1 × 2n−1 , and On−1 is
the 2n−1 × 2n−1 zero matrix.
Theorem 2. Let α = (a1 , a2 , . . . , an ) ∈ {0, 1}n , #(α) = i, 1 ≤ i ≤ 2n − 1,
and α has ones in positions (i1 , i2 , . . . , ir ), 1 ≤ r ≤ n. Then the i-th row
ri of the matrix Mn is the vector of functional values of the prime implicant
ci = xi1 xi2 . . . xir , i.e. α is a characteristic vector of the literals in ci , which is
a monotone function. When #(α) = 0, the zero row of Mn corresponds to the
constant 1̃.
Bakoev
49
α = (x1 , x2 , x3 )
(0
(0
(0
(0
(1
(1
(1
(1
0
0
1
1
0
0
1
1
0)
1)
0)
1)
0)
1)
0)
1)
i = #(α)
0
1
2
3
4
5
6
7
M3
1
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
1
0
0
0
0
1
0
0
0
1
0
0
0
ci
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
1
1
1
1
1
1
1
1
¯
1̃
x3
x2
x2 x3
x1
x1 x3
x1 x2
x1 x2 x3
Table 2. Illustration of the assertion of Theorem 2, for n = 3.
So the vector of any monotone function f can be expressed in terms of a
linear combination f (x1 , x2 , . . . , xn ) = a0 r0 ∨ a1 r1 ∨ · · · ∨ a2n −1 r2n −1 , where
ri is the i-th row of the matrix Mn and its coefficient ai ∈ {0, 1}, for i =
0, 1, . . . , 2n − 1. In other words, Mn plays the role of a generator matrix for the
set of all MBFs of n variables. When f (x1 , x2 , . . . , xn ) = ri1 ∨ ri2 ∨ · · · ∨ rik
corresponds to a MDNF of f , then any two rows rij and ril (corresponding to
the prime implicants cij and cil ), 1 ≤ j < l ≤ k, are pairwise incomparable.
Our algorithm, called GEN, generates all MBFs of n variables, 1 ≤ n ≤ 7,
as vectors in lexicographic order. It is based on the properties of the matrix
Mn (more details are given in [1]).
Algorithm: GEN.
Input: the number of the variables n.
Output: the vectors of all MBFs of n variables in lexicographic order.
Procedure:
1) Generate the matrix Mn .
2) Set f = (0, 0, . . . , 0) – the zero constant. Output f .
3) For each row ri of Mn , i = 2n − 1, . . . , 0, set f = ri and:
a) output f ;
b) for each position j, j = 2n − 2, 2n − 3, . . . , i + 1, check whether
f [j] = 0, i.e. whether the i-th and the j-th rows are incomparable. If ”Yes”
then set (recursively) f = f ∨ rj and go to step 3.a.
4) End.
The essential part of its code (steps 3.a and 3.b), written in C, looks like
this:
void Gen_I ( bool G[], int i ) {
bool H [Max_Dim];
for ( int k=i; k<N; k++ )
// N= 2^n is a global variable
H[k]= G[k] || M[i][k];
// M is M_n
Print ( H );
for ( int j= N-1; j>i; j-- )
// step 3.b
if ( !H[j] ) Gen_I ( H, j );
}
50
ACCT2012
3
Outline of an algorithm for counting MBFs
While trying to improve and speed-up the algorithm GEN, we observe that the same
subfunctions are generated many times in the different iterations of the main cycle in
GEN. Their number grows extremely fast when the number of variables grows. So
we shall concentrate on counting that avoids generating. We set the problem ”Let
the value of the cell mi,j in matrix Mn be 0, for a given n. How many MBFs can be
obtained by disjunction of row ri and all possible rows (one or more than one), having
indices ≥ j?”. To solve this problem (for n ≤ 7) we modify the algorithm GEN and
its new version we call GEN Cell. So we add to the function Gen I a parameter for
the depth of the recursion, and also a counter for the generated functions (when the
depth is 0 we return the value of this counter for storing and then set it to 0 for the
next recursive call). The integers computed in this way we store in a 2n × 2n matrix
denoted by Resn , which elements are set to 0 initially. We have to fill only these cells
of Resn , which correspond (i.e. have the same indices) to zero elements above the main
diagonal in Mn . For example, the results for n = 4 are given in Table 3.
1
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
1
0
0
0
0
1
0
0
0
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
M4
1 1
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1
1
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
1
0
0
0
0
1
0
0
0
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
1
1
1
1
1
1
1
1
row
0
1
2
3
4
5
6
7
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
1
0
0
0
0
1
0
0
0
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
1
1
1
1
1
1
1
1
8
9
10
11
12
13
14
15
1
0
0
0
0
0
0
0
Res4
00000 0 00 00000000
00503 0 50 10201010
00003 5 00 12001100
0 0 0 0 5 20 11 0 1 5 3 0 1 2 1 0
00000 0 00 12110000
0 0 0 0 0 0 11 0 1 5 2 3 1 0 1 0
00000 0 00 14331100
00000 0 00 15351210
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
1
2
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
si
1
19
14
50
6
25
14
19
1
5
3
5
1
2
1
1
Total: S = 167
Table 1: M4 , Res4 and si – the number of MBFs on rows.
We can see that the same submatrices in M4 or, more precisely, certain shapes of
zeros in them, correspond to the same shapes of non-zero values in the matrix Res4 .
Obviously, this is due to the recursively defined block structure of the matrix Mn ,
the nature of generating and hence the nature of the algorithm GEN. This fact can
be proved rigorously by induction on n and it demonstrates the property overlapping
subproblems – one of the key ingredients that enables us to apply the dynamic programming strategy. The same is valid for the other key property – optimal substructure.
Indeed, if (for a given n) the subproblems are solved, i.e. the necessary values are
computed and stored in the matrix Resn , we can obtain the solution of the problem
(i.e. to find ψ(n)) as follows:
(1) sum the numbers in the i-th row of the matrix Resn and add 1 (because every
Bakoev
51
row of Mn is in itself a monotone function). Denote this sum by si , i = 0, 1, . . . , 2n − 1;
P2n −1
(2) compute the sum S = i=0 si ;
(3) set ψ(n) = S + 1 (since the constant 0 is yet not counted) and return it.
For example, the last column of Table 3 contains the sums si of the elements of
each row mentioned in (1). If we take the sum s14 + s15 + 1 (since M1 is placed in the
lower right corner of M4 ), we obtain 3 = ψ(1). If we do the same for the last 4 rows:
s12 + · · · + s15 + 1 (since M2 is also placed in the lower right corner of M4 ), we obtain
6 = ψ(2). For the the last 8 rows, we obtain s8 + · · · + s15 + 1 = 20 = ψ(3), and finally,
for all rows, we obtain s0 + · · · + s15 + 1 = S + 1 = 168 = ψ(4).
The next improvement of algorithm GEN Cell seems obvious: after computing the
value of Resn (i, j), we copy it in the corresponding cells of the same shapes above –
so we prevent from solving the same subproblems more than once. Even so, executing
GEN Cell for one cell only can cause generating many subfunctions, which have been
already generated. Their memorization can take a large amount of memory, and our
goal is to restrict the generating as possible. We continue with our next idea. Assume
that i < j, Mn (i, j) = 0 and Resn (i, j) = 0. We need to compute the value of
Resn (i, j), i.e. to count all MBFs, which are disjunction of i-th row of Mn with all
rows of Mn , having indices ≥ j. All cells of the i-th row from the j-th cell to the last
one we consider as a vector and denote it by (0α). Analogously for the j-th row, all
cells from the j-th to the last cell we consider as a vector and denote it by (1β). For
α and β we have 3 cases: (1) α ¹ β; (2) β ≺ α, and (3) α and β are incomparable.
Using the properties of the matrix Mn and the above arguments we can prove:
P2n −1
Proposition 1. Case (1): if α ¹ β then Resn (i, j) = 1 + k=j+1 Resn (j, k) = sj + 1.
Proposition 2. Case (2): if β ≺ α then Resn (i, j) = 1 +
P2n −1
k=j+1
Resn (i, k).
Suppose we want to compute Resn (i, j) and we have already computed Resn (i, k)
and Resn (j, k), for k = j + 1, . . . , 2n − 1. If α ¹ β or β ≺ α, we apply Proposition 1 or
2, respectively. For the third case we use GEN Cell, since we have not found a better
algorithm (or a formula) till now.
Next proposition follows directly from the definition of matrix Mn .
Proposition 3. For a given n, the matrix Mn contains 4n elements and:
1) 3n of them are equal to 1 and they are placed on the main diagonal or above it;
2) all (4n −2n )/2 elements under the main diagonal are zeros, and also (4n −2.3n +
n
2 )/2 zeros are placed above the main diagonal.
So our algorithm has to compute and fill in (4n − 2.3n + 2n )/2 numbers in the
cells of Resn . Some of these numbers are obtained in accordance with the considered 3
cases. The rest of them are simply copies of numbers already computed. Experimental
results for the number of the cells in each case, for n = 6, 7, 8, are given in Table 4.
4
Conclusions
The results in Table 4 seem to be optimistic, especially if we compare them with the
values of ψ(n), given in Table 1. The main and still open problem is to develop an
View publication stats
52
ACCT2012
n
6
7
8
(4n − 2.3n + 2n )/2
1351
6069
26335
In case 1
211
665
2059
In case 2
26
57
120
In case 3
544
2645
12018
Copies
570
2702
12138
Table 2: Number of cells from each case in the matrix Resn .
efficient way for computing in Case 3. Some secondary problems also have to be solved
– for example, representation and summation of long integers, efficient usage of the
memory, especially for the matrices Mn and Resn , etc. Their efficient solutions will
decrease essentially the running-time for computing ψ(7) and ψ(8) and may allow us
to compute ψ(9) in a reasonable time.
References
[1] V. Bakoev, Generating and identification of monotone Boolean functions, Mathematics and education in mathematics, Sofia (2003), pp. 226–232.
[2] V. Bakoev, Some properties of one matrix structure at monotone Boolean functions, Proc. EWM Intern. Workshop Groups and Graphs, Varna, Bulgaria (2002),
pp. 5–8.
[3] J. Dezert, F. Smarandache, On the generation of hyper-powersets for the DSmT,
Proc. of the 6th Int. Conf. of Information Fusion (2003), pp. 1118–1125.
[4] R. Fidytek, A. Mostowski, R. Somla, A. Szepietowski, Algorithms counting monotone Boolean functions, Inform. Proc. Letters 79 (2001), pp. 203-209.
[5] A. Kisielewicz, A solution of Dedekinds problem on the number of isotone Boolean
functions, J. reine angew. math., Vol. 386 (1988) pp. 139–144.
[6] D. Kleitman, On Dedekinds problem: the number of monotone Boolean functions,
Proc. of AMS, 21(3) (1969), pp. 677-682.
[7] A. Korshunov, On the number of monotone Boolean functions, Problemy Kibernetiki, Vol. 38, Moscow, Nauka (1981), pp. 5-108 (in Russian).
[8] A. Korshunov, I. Shmulevich, On the distribution of the number of monotone
Boolean functions relative to the number of lower units, Discrete Mathematics,
257 (2002), pp. 463-479.
[9] http://mathpages.com/home/kmath094.htm, Generating the M. B. Functions
[10] http://angelfire.com/blog/ronz/, Ron Zeno’s site
[11] M. Tombak, A. Isotamm, T. Tamme, On logical method for counting Dedekind
numbers, Lect. Notes Comp. Sci., 2138, Springer-Verlag (2001), pp. 424–427.
[12] D. Wiedemann, A computation of the eighth Dedekind number, Order, no. 8
(1991), pp. 5–6.