Computing the Boolean product of two n\times n Boolean matrices using O(n^2) mechanical operation
aa r X i v : . [ c s . D S ] M a y Computing the Boolean product of two n × n Boolean matrices using O ( n ) mechanicaloperations Andrzej Lingas and Mia Persson Department of Computer Science, Lund University
[email protected] Department of Computer Science, Malmö University
Abstract.
We study the problem of determining the Boolean productof two n × n Boolean matrices in an unconventional computational modelallowing for mechanical operations. We show that O ( n ) operations aresufficient to compute the product in this model. Keywords : Boolean matrix multiplication, Boolean matrix-vector multiplica-tion, mechanical computing, time complexity
The problem of Boolean matrix multiplication has a wide range of fundamentalapplications, for instance, in graph algorithms (see, e.g., [18]). The Boolean prod-uct of two Boolean n × n matrices can be computed using O ( n ) Boolean ANDand OR binary operations following its definition. This is optimal if only thesetwo types of operations are allowed [8,9,10]. If also the one argument NOT opera-tion is allowed then the product can be computed using O ( n ω ) operations, where ω stands for the exponent of the so called fast arithmetic matrix multiplication.The O ( n ω ) bound follows by a straightforward reduction of Boolean matrix mul-tiplication to the arithmetic one for 0 − O ( n . ) multiplications, additionsand subtractions [11]. The following series of improvements of the exponent ω of fast matrix multiplication culminates in the recent results of Le Gall andVassilevska Williams showing ω < .
373 [6,12]. On the other hand, Alman etal. have recently shown that there is an ℓ > ω better than ℓ by using the known approaches [1]. Also, thesubstantially sub-cubic algebraic algorithms for matrix multiplication have verylarge overhead which makes them hardly practical. Unfortunately, no the socalled combinatorial (i.e., with small constants) algorithm for Boolean matrixmultiplication running in O ( n − ǫ ) time, for a fixed ǫ > , is known [2,13]. Thefastest known combinatorial algorithm for Boolean matrix multiplication dueo Yu runs in O ( n poly (log log n ) / log n )) time [17]. Hence, a natural questionarises about the complexity of Boolean matrix multiplication in different modelsof computation, possibly more powerful or unconventional.To begin with, if one uses huge integers, requiring O ( n log n ) bits then theBoolean product of two n × n Boolean matrices can computed in O ( n ) steps onRAM as observed in [7]. Recently, also a nondeterministic algorithm for n × n matrix multiplication using O ( n ) arithmetic operations has been presented byKorec and Wiedermann in [4]. It results from a derandomization of Freivalds’ O ( n )-time randomized algorithm for integer matrix product verification [3]. Sim-ply, the algorithm guesses first the product matrix and then verifies its correct-ness. Again, the derandomization involves huge numbers requiring O ( n ) timesmore bits than the input numbers [4]. More recently, Wiedermann has presentedtwo further, slightly slower nondeterministic algorithms for matrix multiplica-tion, both running in O ( n log n ) time and relying on the derandomization ofFreivalds’ algorithm. The first runs on a real RAM, the second on a unit-costRAM using only integers of size proportional to that of the largest entry in theinput matrices [14]. On the other hand, no quantum algorithm for Boolean ma-trix product faster than those based on fast algebraic matrix multiplication inthe standard computational model has been devised so far [5].From the perspective of modern electronic computing, mechanical computingseems not only old-fashioned but even unconventional. The history of mechanicaldevices assisting computing stretches several thousands years back, e.g., the socalled Roman abacus was used as early as 2700-2300 B.C. in Babylonia [16].Under several thousands of years mechanical devices assisted astronomical andnavigation calculations. The slide-rule has been used since 1620 and mechanicalcalculators were intensively developed in 17, 18 and 19 centuries (e.g., by Pascal,Leibniz and Babbage).In this paper, we study the problem of determining the Boolean product oftwo n × n Boolean matrices in an unconventional computational model allow-ing for mechanical operations. We show that the Boolean product of an n × n Boolean matrix with an n -dimensional Boolean column vector can be computedusing O ( n ) operations. Hence, we can infer that O ( n ) operations are sufficientto compute the Boolean product of two n × n Boolean matrices in this model.For smaller matrices the mechanical operations can be performed even manu-ally while for the larger ones the operations can be automatized using electricpower. Our result demonstrates that already ancient civilizations had sufficienttechnology to perform relatively fast matrix multiplication of moderately largeBoolean matrices. To the best of our knowledge, we are not familiar with anyprior mechanical approach to (Boolean) matrix multiplication.
Our mechanical algorithm for Boolean matrix multiplication computes the Booleanproduct of the two input n × n Boolean matrices by repetitive multiplication ofthe first matrix with consecutive columns of the second matrix. While computinghe Boolean product of a fixed Boolean n × n matrix with a Boolean column vec-tor one encounters two major bottlenecks that prohibit obtaining a substantiallysub-quadratic in n number of operations in the standard computational model(solely poly-logarithmic speedups are known after preprocessing [15]). Note thatonly the j -th columns of the fixed matrix where the j -th coordinate of the inputcolumn vector is 1 can affect the output product vector. The first bottleneckis the selection of the aforementioned columns (alternatively, activating themand deactivating the remaining ones). The other bottleneck is the computationof the disjunction of entries belonging to active columns for each row of thefixed matrix. We design a special purpose mechanical processor for computingthe Boolean product of a Boolean n × n matrix with a Boolean n -dimensionalcolumn vector that solves each of the two bottleneck problems using O ( n ) me-chanical operations. The matrix-vector processor (MVP) needs also to performa number of other operations, e.g., reading the input vector or the input matrixor outputting the product vector etc., that can be implemented purely mechan-ically (if one insists on that) in many ways. We leave here the details to thereader. We shall use a special purpose processor for computing the Boolean product of aBoolean n × n matrix with a Boolean n -dimensional column vector. We shall termsuch a processor MVP for short. In particular, an MVP has an input n × n arraypart, an input n -dimensional vector part, and an output n -dimensional vectorpart, see Fig. 3. In this section, we shall provide solely general requirements thatan MVP should satisfy. In Section 4, we shall outline implementations of MVPincluding mechanical operations that allow for fulfillment of these requirements.The list of requirements is as follows.1. A Boolean n × n matrix can be read into the MVP input array using O ( n )operations.2. A Boolean n -dimensional vector can be read into the MVP input vectorusing O ( n ) operations.3. The MVP output vector can be reported using O ( n ) operations.4. All j -th columns of the MVP input array can be appropriately activated/deactivated(if necessary) such that afterwards the j -th column is active if and only ifthe j -th coordinate of the MVP input vector is set to 1, using totally O ( n )operations.5. For all i -th rows of the MVP input array that include at least one 1 belongingto an active column of the array the i -th coordinate of the MVP output vectorcan be set to 1 while all other coordinates of the output vector can be set to0 using totally O ( n ) operations.6. The MVP output vector can be reset to an initial state using O ( n ) opera-tions. nput: a Boolean n × n matrix A and a Boolean n -dimensional column vector V in the MVP input array and the MVP input vector, respectively. Output: the Boolean column vector product of A and V. for j = 1 to n do if V [ j ] = 1 and the j -th column of the MVP input array is not active then activate the j -th column3: if V [ j ] = 0 and the j -th column of the MVP input array is active then deactivate the j -th column4: end for for i = 1 to n do if the i -th row of the MVP input array includes at least one 1 thatbelongs to an active column of the array then set the i -th coordinate ofthe MVP output vector to 1 else set this coordinate of the MVP outputvector to 07: end for return the output vector Fig. 1.
The functional procedure Matvec(A,V)
In this section, we present two simple mechanical algorithms for Boolean matrix-vector product and Boolean matrix-matrix product, respectively. Both are basedon the use of an MVP. It will be convenient to refer to the first algorithm as afunctional procedure
M atvec ( A, V ) in order to facilitate its repetitive use in thesecond algorithm.
Lemma 1.
The procedure Matvec(A,V) computes the Boolean column vectorproduct of A and V correctly, using O ( n ) operations.Proof. The correctness of the procedure follows from the following two facts.1. The i -th coordinate of the MVP output vector is set to 1 if and only if the i -th row of the MVP input array includes at least one 1 belonging to anactive column of the array.2. The j -th column of the MVP input array is active if and only if the j -thcoordinate of the MVP input vector is set to 1 . The upper bound on the number of operations necessary to implement
M atvec ( A, V )follows from the requirements on an MVP (see the previous section). In particu-lar the upper bound on the total number of operations necessary to implementthe first loop follows from Requirement 4 while that for the second loop fromRequirement 5. ⊓⊔ By repetitively applying
M atvec ( A, B [ ∗ , j ]) to consecutive columns B [ ∗ , j ])of the second input Boolean matrix B, we obtain our algorithm (Algorithm 1)for Boolean matrix-matrix product. nput: Boolean n × n matrices A and B. Output: the Boolean matrix product of A and B
1: read the matrix A into the MVP input array2: for j = 1 to n do
3: read the j -th column B [ ∗ , j ] of B in the MVP input vector4: return Matvec ( A, B [ ∗ , j ])5: reset the MVP output vector to their initial state6: end forFig. 2. The mechanical algorithm for Boolean matrix multiplication (Algorithm 1)
Theorem 1.
Algorithm 1 computes the Boolean product of the matrices A and B correctly, using O ( n ) operations.Proof. The correctness of the algorithm follows from the fact that it computesthe consecutive columns of the Boolean product of A and B correctly byLemma 1. The n calls of the procedure M atvec require totally O ( n ) operationsby Lemma 1. Reading the matrix A in the input array requires O ( n ) operationsby Requirement 1 on an MVP. Reading the consecutive columns of the matrix B into the MVP input vector totally requires O ( n ) operations by Requirement2. Finally, resetting the MVP output vectors requires O ( n ) operations by Re-quirement 6. ⊓⊔ Remark 1.
Observe that all the requirements on MVP but for the bottleneckones 4 and 5 can be easily realized up to logarithmic factors in such standardsequential computational models as RAM, Turing machine or Boolean circuits.Hence, if the bottleneck requirements could be realized in substantially sub-quadratic in n time (even allowing for a subcubic in n preprocessing of thematrix) by combinatorial algorithms in the aforementioned standard models, itwould yield substantially subcubic in n combinatorial algorithms for Booleanmatrix multiplication, which would be a breakthrough (cf. [17,15]). In this section, we outline an idea of implementation of an MVP with help ofmechanical operations.Each column of the MVP input array is modelled by an axis with attachedequal size segments representing consecutive column entries. Each such a seg-ment is either aligned to the axis which is interpreted as the corresponding entryis set to 0 or it is set into a perpendicular to the axis position which is interpretedas the corresponding entry is set to 1 . See Fig. 4 for an example. If the columnmodelled by the axis is not active, the perpendicular segments are placed horizon-tally. If the column should be activated then the axis rotates 90 degrees so all theattached perpendicular segments take vertical positions under the axis. Symmet-rically, if the column is active and it should be deactivated the axis modelling itis rotated in the reverse direction by 90 degrees. Such an activation/deactivationf a column is counted as a single operation. There are many possible ways toimplement the rotation of the axis by 90 degrees that we omit here. The wholeprocess of activating/deactivating (if necessary) the j -th columns of the inputarray such that afterwards the j -th column is active if and only if the j -th co-ordinate of the MVP input vector is set to 1 requires at most n operations ofcolumn activations/deactivations and scanning the representation of the inputMVP vector. For instance, we may assume that the representation of the inputvector is placed perpendicularly to the column axes close to their start-points sothe whole process of activating/deactivating columns requires O ( n ) walking andscanning steps besides the O ( n ) activation/deactivation operations. In this way,Requirement 4 can be fulfilled.In order to fulfill Requirement 5 for each row of the MVP input array, weplace a ladder under the segments attached to the axes corresponding to therow, in the initial state when no column is active. The ladders are placed per-pendicularly to the axes, see Fig. 5, 6. They can have some wheels to facilitatetheir horizontal movements in the direction perpendicular to the axes. We shallterm the rectangular space between two successive ladder steps and the arms ofthe ladder as an opening. Each opening of the ladder lies exactly under one ofthe segments attached to an axis in the initial state when no column is active.Importantly, the placements and sizes of the axes, ladders, segments etc. are sochosen that the rotations of the axes with attached perpendicular segments arenot obstructed by the ladders. If a segment is placed vertically after the rota-tion then it goes through and a bit sticks out under the corresponding ladderopening, see Fig. 5. A representation of the MVP output vector is placed alongthe rightmost axis. Initially, all coordinates of the output vector are set to 1 . Inorder to set the i -th coordinate of the output vector, the ladder corresponding tothe i -th row of the input array is moved from the left to the right at most by thelength of one opening, see Fig. 6. If no perpendicular segment sticks through anyof its openings such a movement by the length of one opening is possible and theladder hits the representation of the output vector in the section correspondingto its i -th coordinate switching its state from 1 to 0 . (Again, there are many pos-sible technical ways of representing the MVP output vector and implementingsuch a switch that we omit here.) Otherwise, such a full movement is not possibleand the state of the section remains set to 1 . In effect, the i -th coordinate of theoutput vector is set to 1 if and only if the i -th row of the input array includes atleast one 1 belonging to an active column of the array. Each such a movement ofthe ladder with a possible triggering the switch of the state of the correspondingsection is counted as ,say, O (1) operations. Hence, setting all the coordinates ofthe output vector requires O ( n ) operations and Requirement 5 is fulfilled.To read a Boolean n × n matrix A into the MVP input array one can traversethe array for example in a column-wise snake fashion and pull out segmentscorresponding to the 1 entries of the matrix A that are aligned to their axis andpush back the pulled out segments that correspond to the 0 entries of the matrix A. Thus, we may assume that the reading of a Boolean n × n matrix in the inputarray requires O ( n ) operations.imilarly, reading a Boolean n -dimensional vector into the MVP input vectoras well as outputting the MVP output vector require O ( n ) operations. Finally,to reset the MVP output vector, we need to pull back the n ladders to the leftto their initial positions and switch all the 0 coordinates of the output vectorback to 1 using O ( n ) operations. It follows that the remaining requirements canbe fulfilled in this way. input arrayinput vector OutputVector Fig. 3.
The basic parts of the mechanical MVP
Fig. 4. (a) An axis modeling a not active column with entries 1 , , , . (b) In orderto activate the column the axis rotates by 90 degrees. In fact, the activations/deactivations of the appropriate columns of the MVPinput array as well as setting the values of the coordinates of the MVP outputvector can be done in parallel.It is not difficult to design a bit more complex mechanical MVP where anappropriate representation of the MVP input vector is moved towards the start-points of the axes and the 1s in the representation hit the start-pints triggering ig. 5.
A vertical segment attached to an axis representing a 1 entry of the activecolumn modelled by the axis sticks through an opening of a ladder. The segmentblocks the full movement of the ladder by the length of one opening to the right. Inresult, the coordinate of the MVP output vector remains set to 1 . ladder 1ladder 2ladder 3ladder 4 axis 4axis 1 axis 3axis 2 Fig. 6. (a) The MVP input array with columns set to 1101 , , , and 0101 , respectively. The columns are not active and the ladders are in their initial positions.(b) The input array after the activation of the first and third columns and the movementof the ladders to the right. he activation of the corresponding columns of the input array. More exactly,if the j -th coordinate of the input vector is set to 1 then the representationof this 1 hits the start-point of the axis modelling the j -th column casing itsactivation. Hence, the activations of all the columns can be done in one stepof the movement of the representation of the input vector. In order to fulfillRequirement 4, we need to deactivate all columns first before the activationmovement. The deactivation of all the columns can be obtained by the reversemovement of the representation of the previous input vector.As for setting the output vector, i.e., Requirement 5, all the n movements ofthe ladders to the right can be done independently of each other in one parallelstep. (Still, if one would like to count the ladder movements as a single operation,one could elevate slightly the whole left part of the processor to cause slidingthe ladders to the right at most by one opening length etc.) The same holds forthe reverse movements of the ladders back to the left, i.e., resetting the outputvector. Finally, the reading of an input vector into the MVP input vector canbe also done in a single parallel step using O ( n ) operations while the reading ofthe input matrix into the input array can be done in O ( n ) parallel steps, eachusing O ( n ) operations.Hence, we obtain the following lemma and theorem. Lemma 2.
By using the parallel mechanical MVP, the procedure
M atvec ( A, V ) can be implemented in O (1) parallel steps using O ( n ) operations. Theorem 2.
By using the parallel mechanical MVP, the Boolean product of twoBoolean n × n matrices can be computed in O ( n ) parallel steps, each using O ( n ) operations. Here, we shall outline an alternative implementation of MVP using mechanicaland light operations. Each column of the MVP input n × n array is modelledby a thin movable wall vertically divided into 2 n sections. Each even numberedsection has an always open round window of the same size in its middle. The2 k − k -th entry of the column in the input array. It hasalso a window of the same shape and size in the middle. The window can beeither open or closed. The former is interpreted as setting the k -th entry in thecolumn to 0 while the latter as setting this entry to 1 . Now, the activation ofa column in the input array consists in shifting the corresponding wall by thelength of a single section down. See Fig. 7 for an example. The deactivationof the column is obtained by the reverse move of the wall up. Both moves arecounted as single operations. Hence, arguing similarly as in the previous section,we infer that Requirement 4 can be fulfilled.To fulfill Requirement 5, lights are placed in front of even sections of thefirst wall in its initial deactivated position. See Fig. 7. The distance between twoconsecutive walls is very small. Such an i -th light can be observed on the otherside at the last wall through the windows of walls modelling deactivated columns ight 1light 2light 3light 4 Fig. 7. (a) A thin wall modeling a not active column of the MVP input array withentries 1 , , , . To activate the column the wall has to be moved down. (b) Thesecond and fourth columns of the MVP input array are active. and the open windows of walls modelling active columns if and only if the i -throw of the input array does not contain any 1 belonging to an active column.Thus, in case the light is observed the i -th coordinate of the MVP output vectoris set to 0 and otherwise it is set to 1 . Since the observation of the light is countedas a single observation, Requirement 5 can be also fulfilled. The fulfillment ofthe remaining MVP requirements do not require any involved ideas and can beachieved in many ways so we omit its discussion.
The mechanical operations used in our method like turning or shifting mechanicalunits are very slow compared to the electronic ones. Also, it would be technicallyhard to apply the aforementioned mechanical operations to very large matrices.For these reasons, in the range of matrix sizes feasible for the mechanical opera-tions, Boolean matrix multiplication can be performed much faster by electroniccomputers, even if they run the straightforward cubic-time algorithm.’ Still, itseems of at least theoretical interest that in the realm of mechanical compu-tations one can design an algorithm for Boolean matrix multiplication using aquadratic number of operations in contrast to the straightforward one using acubic number of operations. The two ideas behind our mechanical algorithm forBoolean matrix multiplication are switching on/off all entries of an array columnin a single mechanical step and computing the disjunction of switched on entriesof an array row in a single mechanical step. It would be interesting to study thecomplexity of other matrix/graph problems assuming that the aforementionedoperations can be performed in single steps. cknowledgments
The research has been supported in part by Swedish Research Council grant621-2017-03750.
References
1. J. Alman and V. Vassilevska Williams.
Limits on All Known (and Some Unknown)Approaches to Matrix Multiplication . Proc. FOCS 2018.2. N. Bansal and R. Williams.
Regularity Lemmas and Combinatorial Algorithms.
Theory of Computing, Vol. 8, No. 1, pp. 69-94, 2012.3. R. Freivalds.
Probabilistic Machines Can Use Less Running Time . IFIP Congress1977, pp. 839–842.4. I. Korec and J. Widermann.
Deterministic Verification of Integer Matrix Multi-plication in Quadratic Time.
SOFSEM 2014: Theory and Practice of ComputerScience, Lecture Notes in Computer Science Volume 8327, pp 375-382, 2014.5. F. Le Gall.
A Time-Efficient Output-Sensitive Quantum Algorithm for BooleanMatrix Multiplication.
ISAAC 2012, PP. 639–648, 2012.6. F. Le Gall.
Powers of Tensors and Fast Matrix Multiplication . 39th InternationalSymposium on Symbolic and Algebraic Computation, July 2014.7. A. Lingas, M. Persson, and D. Sledneu.
Bounds for Semi-disjoint Bilinear Forms ina Unit-cost Computational Model.
Proc. of the 13th annual conference on Theoryand Applications of Models of Computation (TAMC 2016/2017), Lecture Notes inComputer Science, pp. 412-424, April 2017..8. K. Mehlhorn and Z. Galil.
Monotone Switching Circuits and Boolean Matrix Prod-uct.
Computing 16, pp. 99-111, 1976.9. M. Paterson.
Complexity of Monotone Networks for Boolean Matrix Product .Theor. Comput. Sci. 1(1), pp. 13-20 (1975)10. V.R. Pratt.
The Power of Negative Thinking in Multiplying Boolean Matrices.
SIAM J. Comput. 4(3), pp. 326-330, 1975.11. V. Strassen.
Gaussian elimination is not optimal . Numerische Mathematik 13, pp.354-356, 1969.12. V. Vassilevska Williams.
Multiplying matrices faster than Coppersmith-Winograd .Proc. STOC 2012, pp. 887–898.13. Vassilevska Williams, V. and Williams, R.: Subcubic Equivalences Between Path,Matrix, and Triangle Problems, J. ACM, Vol. 65(5), September 2018 (preliminaryversion FOCS 2010)14. J. Wiedermann
Fast Nondeterministic Matrix Multiplication via Derandomizationof Freivalds’ Algorithm.
IFIP TCS 2014, pp. 123–13515. R. Williams,
Matrix-vector multiplication in sub-quadratic time (some preprocess-ing required).
Proc. of SODA 2007, pp. 995-2001.16.
The history of computing hardware . Wikipedia, 21 November 2019.17. H. Yu.
An Improved Combinatorial Algorithm for Boolean Matrix Multiplication.
Proc. of ICALP 2015. pp 1094-1105.18. U. Zwick.