1. Introduction
Matrix multiplication over various rings or semirings is a basic tool in science and engineering. By the definition, the matrix product of two
$n\times n$ matrices can be easily computed using
$O\left({n}^{3}\right)$ additions and multiplications over the respective ring or semiring. This is optimal in the arithmetic case and the Boolean case if, respectively, only the operations of arithmetic addition and multiplication or the Boolean OR and AND are allowed [
1,
2]. Five decades ago, Strassen presented a divideandconquer algorithm for arithmetic matrix multiplication based on algebraic term cancellation, breaking out of the
$O\left({n}^{3}\right)$ method. It used only
$O\left({n}^{2.8074}\right)$ multiplications, additions and subtractions [
3]. The complexity of matrix multiplication is measured in terms of
$\omega $ which is the smallest real number such that two
$n\times n$ matrices can be multiplied using
$O\left({n}^{\omega +\u03f5}\right)$ operations over the field of reals, for all
$\u03f5>0$ (i.e., the number of operations is
$O\left({n}^{\omega +o\left(1\right)}\right)$ [
4]. The series of improvements of the upper bounds on
$\omega $ starting from
$\omega <2.8074$ culminates in the recent result of Alman and Vassilevska Williams showing
$\omega <2.3729$ [
4]. By a straightforward reduction of the Boolean matrix product to the corresponding arithmetic one for
$01$ matrices, the same asymptotic upper bounds hold for the Boolean matrix product.
We generalize the concept of matrix product of two matrices over a ring or semiring to include that of a kdimensional matrix product D of k matrices ${A}_{1},\dots ,{A}_{k},$ of sizes ${n}_{1}\times n,\dots ,{n}_{k}\times n,$ respectively, where $D[{i}_{1},\dots ,{i}_{k}]={\sum}_{\ell =1}^{n}{A}_{1}[{i}_{1},\ell ]\times \dots \times {A}_{k}[{i}_{k},\ell ]$. Note that the $two$dimensional product of the matrices ${A}_{1}$ and ${A}_{2}$ is equivalent to the standard matrix product of ${A}_{1}$ and the transpose ${\left({A}_{2}\right)}^{T}$ of the matrix ${A}_{2}$. For $k\ge 2,$ we define ${\omega}_{k}(1,r)$ as the smallest real number such that the kdimensional arithmetic product of k $n\times {n}^{r}$ matrices can be computed using $O\left({n}^{{\omega}_{k}(1,r)+\u03f5}\right)$ operations over the field of reals, for all $\u03f5>0$. We show that ${\omega}_{k}(1,r)$ does not exceed $\omega (\lceil k/2\rceil ,r,\lfloor k/2\rfloor )$, where $\omega (p,q,r)$ stands for the smallest real number such that an ${n}^{p}\times {n}^{q}$ matrix can be multiplied by ${n}^{q}\times {n}^{r}$ matrix using $O\left({n}^{\omega (p,q,r)+\u03f5}\right)$ operations over the field of reals for all $\u03f5>0$.
If A and B are two Boolean matrices and C is their Boolean matrix product, then for any entry $C[i,j]=1$ of $C$, a witness is an index m such that $A[i,m]\wedge B[m,j]=1$. The smallest (or, largest) possible witness is called the minimum witness (or, maximum witness, respectively).
The problems of finding “witnesses” have been studied for several decades, mostly within stringology (e.g., algorithms for symbol matches or mismatches [
5,
6]) and graph algorithms (e.g., algorithms for shortest paths [
7,
8]). More recently, the problems of finding extreme (i.e., minimum or maximum) witnesses have found numerous applications (e.g., algorithms for allpairs lowest common ancestors [
9] or allpairs bottleneck weight path problem [
10]). Alon and Naour showed that the witness problem for the Boolean matrix product of two Boolean matrices, i.e., the problem of reporting a witness for each nonzero entry of the product, to be solvable in time required to compute the product up to polylogarithmic multiplicative factors [
11]. (By the
time complexity of an algorithm, we mean the number of operations performed by the algorithm in the unit cost random access machine model, which is expressed as a function of an input size parameter. Note that when the inputs to the aforementioned operations are integers of size polynomial in the input size, then the number of required bit operations is larger than that of unit cost operations only by a polylogarithmic factor.) Czumaj et al. showed that the maximum witness problem, i.e., the problem of reporting the maximum witness for each nonzero entry of the Boolean matrix product of two
$n\times n$ Boolean matrices, was solvable in
$O\left({n}^{2+\lambda +o\left(1\right)}\right)$ time [
9], where
$\lambda $ satisfies the equation
$\omega (1,\lambda ,1)=1+2\lambda $.
We also generalize the concept of a witness for a nonzero entry of the Boolean matrix product of two Boolean matrices to include a witness for a nonzero entry of the kdimensional Boolean product of k Boolean matrices. For a nonzero entry $D[{i}_{1},\dots ,{i}_{k}]$ of the kdimensional Boolean product of k Boolean matrices ${A}_{1},\dots ,{A}_{k},$ of sizes ${n}_{1}\times n,\dots ,{n}_{k}\times n,$ respectively, a witness is any index ℓ such that ${\bigwedge}_{j=1}^{k}{A}_{j}[{i}_{j},\ell ]=1$. The witness problem for the kdimensional Boolean matrix product D is to report a witness for each nonzero entry of D and analogously, the maximum witness problem for D is to report the maximum witness for each nonzero entry of $D.$ We show that for $n\times n$ matrices ${A}_{1},\dots ,{A}_{k}$, the witness problem for their kdimensional Boolean product can be solved in $O\left({n}^{\omega (\lceil k/2\rceil ,1,\lfloor k/2\rfloor )+o\left(1\right)}\right)$ time, while the maximum witness problem for this product admits a solution in $O\left({n}^{k+\lambda +o\left(1\right)}\right)=O\left({n}^{k+{\lambda}^{\prime}+o\left(1\right)}\right)$ time, where $\lambda $ satisfies the equation ${\omega}_{k}(1,\lambda )=k1+2\lambda $ and ${\lambda}^{\prime}$ satisfies the equation $\omega (\lceil k/2\rceil ,{\lambda}^{\prime},\lfloor k/2\rfloor )=k1+2{\lambda}^{\prime}$. By the recent results on rectangular matrix multiplication, the latter bound for $k=2$ is $O\left({n}^{2.529}\right).$
In the second part of our paper, we provide an alternative simple method of detection/counting copies of fixed size cliques based on the multidimensional matrix product. We show also an immediate reduction of the kdominating set problem to the multidimensional matrix product implying the $W\left[2\right]$ hardness of computing the product. Finally, we provide an efficient reduction of the problem of finding lowest common ancestors for all ktuples of vertices in a directed acyclic graph to the problem of finding maximum witnesses of the Boolean variant of the multidimensional matrix product. These applications demonstrate the versatility of the multidimensional matrix product. Although the time complexities of the algorithms resulting from the aforementioned reductions solely match those of the known algorithms, the advantage of our algorithms is simplicity.
1.1. Clique Detection
Our first application of the multidimensional matrix product provides a simple alternative method for clique detection.
The problems of detecting, finding, counting or listing subgraphs or induced subgraphs of a host graph that are isomorphic to a pattern graph are central in graph algorithms. They are generally termed as subgraph isomorphism and induced subgraph isomorphism, respectively. Several wellknown NPhard problems such as the independent set, clique, Hamiltonian cycle or Hamiltonian path can be regarded as their special cases.
Recent examples of applications of different variants of subgraph isomorphism include among other things [
12,
13]: a comparison of biomolecular networks by their socalled motifs [
14], an analysis of social networks by counting the number of copies of a small pattern graph [
15], graphmatching constraints in the automatic design of processor systems [
16], and the detection of communication patterns between intruders in network security [
17]. In the aforementioned applications, the pattern graphs are typically of fixed size which allows for polynomialtime solutions.
At the beginning of the 1980s, Itai and Rodeh [
18] presented the following straightforward reduction of not only triangle detection but also triangle counting to fast matrix multiplication. Let
A be the
$01$ adjacency matrix of the host graph
G on
n vertices (see Preliminaries). Consider the matrix product
$C=A\times A.$ Note that
$C[i,j]={\sum}_{l=1}^{n}A[i,l]A[l,j]$ is equal to the number of twoedge paths connecting the vertices
i and
$j.$ Hence, if
$\{i,j\}$ is an edge of
G, then
$C[i,j]$ is the number of triangles in
G including the edge
$\{i,j\}$. Consequently, the number of triangles in an
nvertex graph can be reported in
$O\left({n}^{\omega +o\left(1\right)}\right)$ time.
A few years later, Necetril and Poljak [
19] showed an efficient reduction of detecting and counting copies of any pattern graph both in the standard and induced case to the aforementioned method for triangle detection and counting. The idea is to divide the pattern graph into three almost equal parts and to build an auxiliary graph on copies of subgraphs isomorphic to one of three parts. Then, the triangle detection/counting method is run on the auxiliary graph. Two decades later, Eisenbrand and Grandoni [
20] (cf. [
21]) refined this general triangle method by using fast algorithms for rectangular matrix multiplication instead of those for square matrix multiplication. For a pattern graph on
$r\ge 3$ vertices and a host graph on
n vertices, the (refined) general triangle method runs in time
$O\left({n}^{\omega (\lfloor r/3\rfloor ,\lceil (r1)/3\rceil ,\lceil r/3\rceil )+o\left(1\right)}\right)$ [
19,
20,
21].
Up to now, the general triangle method remains the fastest known universal method for the detection and counting standard and induced copies of fixed pattern graphs. In the recent two decades, there has been a real progress in the design of efficient algorithms for the detection and even counting of fixed pattern graphs both in the standard [
12,
22] and induced case [
12,
13,
23,
24,
25]. Among other things, the progress has been based on the use of equations between the numbers of copies of different fixed patterns in the host graph [
13,
21,
22,
24] and randomization [
12,
13,
24]. Unfortunately, this progress has not included complete pattern graphs, i.e.,
${K}_{r}$ graphs (and their complements, i.e., edgefree pattern graphs in the induced setting). For the aforementioned pattern graphs, the generalized triangle method remains the fastest known one.
In this paper, we consider another universal and simple method that in fact can be viewed as another type of generalization of the classic algorithm for triangle detection and counting due to Itai and Rodeh. We can rephrase the description of their algorithm as follows. At the beginning, we form a list of subgraphs isomorphic to
${K}_{2}$ (i.e., edges), and then for each subgraph on the list, we count the number of vertices outside it that are adjacent to both vertices of the subgraph; in other words, we count the number of extensions of the subgraph to a clique on three vertices. The latter task can be completed efficiently by squaring the adjacency matrix of the host graph. We can generalize the algorithm to include detection/counting
${K}_{r}$ copies,
$r\ge 3,$ by replacing
${K}_{2}$ with
${K}_{r1}$ and using the
$(r1)$dimensional matrix product of
$r1$ copies of the adjacency matrix instead of squaring the matrix. Listing the subgraphs of the host graph isomorphic to
${K}_{r1}$ can be completed by enumerating
$(r1)$ vertex subsets and checking if they induce
${K}_{r1}.$ For
$r=O\left(1\right),$ it takes
$O\left({n}^{r1}\right)$ time, so the overall time required by this simple alternative method is
$O({n}^{r1}+{n}^{{\omega}_{r1}+o\left(1\right)}),$ where
${\omega}_{k}$ is the smallest real number such that the
kdimensional matrix product of
k $n\times n$ matrices can be computed using
$O\left({n}^{{\omega}_{k}+\u03f5}\right)$ operations over the field of reals, for all
$\u03f5>0$ (see Definition 1 in
Section 3). Recall that we show in particular
${\omega}_{k}\le \omega (\lceil k/2\rceil ,1,\lfloor k/2\rfloor )$. Hence, our alternative method in particular computes the number of
${K}_{4}$ copies in an
nvertex graph in
$O\left({n}^{\omega (2,1,1)+o\left(1\right)}\right)$ time and the number of
${K}_{5}$ copies in
$O\left({n}^{\omega (2,1,2)+o\left(1\right)}\right)$ time. In addition, if the input graph contains a copy of
${K}_{4}$ or
${K}_{5}$, respectively, then a copy of
${K}_{4}$ can be found in the graph in
$O\left({n}^{\omega (2,1,1)+o\left(1\right)}\right)$ time while that of
${K}_{5}$ can be found in the graph in
$O\left({n}^{\omega (2,1,2)+o\left(1\right)}\right)$ time by a slightly modified alternative method. Thus, our upper time bounds for
${K}_{4}$ and
${K}_{5}$ at least match those for
${K}_{4}$ and
${K}_{5}$ yielded by the generalized triangle method [
20]. If
${\omega}_{k}<\omega (\lceil k/2\rceil ,1,\lfloor k/2\rfloor )$ for
k equal to 3 or 4, then we would achieve a breakthrough in the detection/counting of
${K}_{4}$ or
${K}_{5},$ respectively. For
${K}_{r},$ where
$r\ge 6,$ the generalized triangle method asymptotically subsumes our alternative method and for
${K}_{3}$, the methods coincide.
1.2. Small Dominating Sets
Our second application of the multidimensional matrix product is an immediate reduction of the
kdominating set problem to the
kdimensional matrix product. It rephrases the known algorithm for the aforementioned problem due to Eisenbrand and Grandoni [
20] (cf. [
26]). The
kdominating set problem for a graph
G and a fixed natural number
k is to determine if there is a set
S of at most
k vertices in
G such that each vertex in
G outside
S is adjacent to at least one vertex in
$S.$ It is a basic
$W\left[2\right]$ complete problem equivalent to the
kset cover problem asking if there is a set cover of cardinality at most
k [
27].
1.3. Finding Lowest Common Ancestors
Our third application of the multidimensional matrix product provides a simple generalization of known results on finding the lowest common ancestors for all pairs of vertices to include all ktuples of vertices for fixed $k\ge 2.$
The problem of finding a
lowest common ancestor (LCA) for sets of vertices in a tree, or more generally, in a
directed acyclic graph (DAG) is a basic problem in algorithmic graph theory. It has several applications ranging from algorithm design through objectoriented programming languages [
28] to phylogenetic networks [
29]. An LCA of a set
S of vertices in a DAG is an ancestor of all vertices in
S that has no proper descendant which is an ancestor of all vertices in
S [
30]. The problem of preprocessing a DAG such that LCA queries can be answered quickly for any pair of vertices has been studied extensively in the literature [
9,
31,
32,
33]. The allpairs LCA problem is to compute LCA for all pairs of vertices in the input tree or DAG. For trees, it can be solved in linear time [
34]. For DAGs, Bender et al. were the first to provide a substantially subcubic algorithm for this problem [
35]. Czumaj et al. improved their upper bound to
$O\left({n}^{2.575}\right)$ by a reduction to the problem of finding maximum witnesses for the Boolean matrix product of two
$n\times n$ Boolean matrices [
9]. Taking into account the recent progress in fast rectangular matrix multiplication, the latter bound reduces to
$O\left({n}^{2.529}\right).$ Very recently, Grandoni et al. have presented an
$\tilde{O}\left({n}^{2.447}\right)$time algorithm for the all pairs LCA problem [
33].
The problem of finding LCAs for vertex sets of size greater than two is natural, e.g., in a genealogy search in phylogenetic networks [
29]. Yuster generalized the allpairs LCA problem in DAGs to include finding lowest common ancestors for all
ktuples of vertices [
36] (cf. [
37]). We term the generalized problem as the all
ktuples LCA problem.
We provide a simple reduction of the all
ktuples LCA problem to the maximum witness problem for the
kdimensional Boolean matrix product of
k copies of the transitive closure matrix of the input DAG. As a result, we obtain upper time bounds for the all
ktuples LCA problem matching those established by Yuster in [
36] and Kowaluk et al. in [
37].
1.4. Paper Organization
In the next section, the basic matrix and graph notation used in the paper is presented.
Section 3 is devoted to the
kdimensional matrix product of
k matrices, in particular the upper time bounds on the product and the related problems of computing witnesses and maximum witnesses for the Boolean version of the product in terms of those for fast rectangular matrix multiplication. In
Section 4, the alternative method for detection/counting copies of fixed cliques in a host graph relying on the multidimensional matrix product is presented and analyzed. In
Section 5, the immediate reduction of the
kdominating set problem to the
kdimensional matrix product is given. In
Section 6, the application of the results from
Section 3 to the all
ktuples LCA problem is presented. We conclude with final remarks.
2. Preliminaries
For a positive integer $r,$ we shall denote the set of positive integers not greater than r by $\left[r\right].$
For a matrix $D,$ ${D}^{T}$ denotes its transpose. Recall that for positive real numbers $p,\phantom{\rule{4pt}{0ex}}q,\phantom{\rule{4pt}{0ex}}s,$ $\omega (p,q,s)$ denotes the smallest real number such that an ${n}^{p}\times {n}^{q}$ matrix can be multiplied by ${n}^{q}\times {n}^{s}$ matrix using $O\left({n}^{\omega (p,q,s)+\u03f5}\right)$ operations over the field of reals for all $\u03f5>0.$ For convenience, $\omega $ stands for $\omega (1,1,1).$
Let
$\alpha $ stand for
$sup\{0\le q\le 1:\omega (1,q,1)=2+o(1\left)\right\}.$ The following recent lower bound on
$\alpha $ is due to Le Gall and Urrutia [
38].
Fact 1. The inequality $\alpha >0.31389$ holds [38]. Recall also that a witness for a nonzero entry $C[i,j]$ of the Boolean matrix product C of a Boolean $p\times q$ matrix A and a Boolean $q\times s$ matrix B is any index $\ell \in \left[q\right]$ such that $A[i,\ell ]$ and $B[\ell ,j]$ are equal to 1. The witness problem is to report a witness for each nonzero entry of the Boolean matrix product of the two input Boolean matrices.
Alon and Naor provided a solution to the witness problem for the Boolean matrix product of two square Boolean matrices [
11] which is almost equally fast as that for square matrix multiplication [
4]. It can be easily generalized to include the Boolean product of two rectangular Boolean matrices of sizes
${n}^{p}\times {n}^{q}$ and
${n}^{q}\times {n}^{s},$ respectively. The asymptotic matrix multiplication time
${n}^{\omega +o\left(1\right)}$ is replaced by
${n}^{\omega (p,q,s)+o\left(1\right)}$ in the generalization.
Fact 2. For positive $p,q,s,$ the witness problem for the Boolean matrix product of an ${n}^{p}\times {n}^{q}$ Boolean matrix with an ${n}^{q}\times {n}^{s}$ Boolean matrix can be solved (deterministically) in $O\left({n}^{\omega (p,q,s)+o\left(1\right)}\right)$ time.
A directed acyclic graph (DAG) is a directed graph not containing directed cycles. A vertex v is an ancestor (proper ancestor) of a vertex u in a DAG if there is a directed path (directed path of nonzero length, respectively) from u to v. A vertex u is a descendant (proper descendant) of a vertex v in a DAG if v is an ancestor (proper ancestor) of u in the DAG. Recall that a lowest common ancestor (LCA) of a set of vertices in a DAG is a vertex that is an ancestor of all vertices in the set but none of its proper descendants is also an ancestor of all vertices in the set.
We shall consider also simple undirected graphs.
A subgraph of the graph $G=(V,E)$ is a graph $H=({V}_{H},{E}_{H})$ such that ${V}_{H}\subseteq V$ and ${E}_{H}\subseteq E$.
An induced subgraph of the graph $G=(V,E)$ is a graph $H=({V}_{H},{E}_{H})$ such that ${V}_{H}\subseteq V$ and ${E}_{H}=E\cap ({V}_{H}\times {V}_{H})$. A subgraph of G induced by $S\subseteq V$ is a graph $F=({V}_{F},{E}_{F})$ such that ${V}_{F}=S$ and ${E}_{F}=E\cap (S\times S)$. It is denoted by $G\left[S\right].$
For simplicity, we shall refer to a subgraph of a graph G that is isomorphic to ${K}_{r}$ as a copy of ${K}_{r}$ in G or just a ${K}_{r}$ copy in $G.$
The adjacency matrix A of a graph $G=(V,E)$ is the $01$ $n\times n$ matrix such that $n=\leftV\right$ and for $1\le i,j\le n,$ $A[i,j]=1$ if and only if $\{i,j\}\in E$.
3. MultiDimensional Matrix Product and Its Witnesses
For the convenience of the reader, we gather all the definitions related to the multidimensional matrix product, repeating some of them, below.
Definition 1. For k ${n}_{q}\times n$ matrices ${A}_{q}$, $q=1,\dots ,k,$ (arithmetic or Boolean, respectively), their kdimensional (arithmetic or Boolean, respectively) matrix product D is defined byrespectively, where ${i}_{q}\in \left[{n}_{q}\right]$ for $q=1,\dots ,k.$ In the arithmetic case, ${\omega}_{k}({r}_{1},{r}_{2})$ denotes the smallest real number such that the kdimensional arithmetic product of k ${n}^{{r}_{1}}\times {n}^{{r}_{2}}$ matrices can be computed using $O\left({n}^{{\omega}_{k}(1,r)+\u03f5}\right)$ operations over the field of reals, for all $\u03f5>0.$ For convenience, ${\omega}_{k}$ stands for ${\omega}_{k}(1,1).$ In the Boolean case, the corresponding numbers are denoted by ${\omega}_{k}^{B}({r}_{1},{r}_{2})$ and ${\omega}_{k}^{B},$ respectively. Clearly, we have ${\omega}_{k}^{B}({r}_{1},{r}_{2})\le {\omega}_{k}({r}_{1},{r}_{2})$ and ${\omega}_{k}^{B}\le {\omega}_{k}.$ A witness for a nonzero entry $D[{i}_{1},{i}_{2},\dots ,{i}_{k}]$ of the kdimensional Boolean matrix product is any index $\ell \in \left[n\right]$ such that ${A}_{1}[{i}_{1},\ell ]\wedge {A}_{2}[{i}_{2},\ell ]\wedge \dots \wedge {A}_{k}[{i}_{k},\ell ]$ is equal to (Boolean) $1.$ The witness problem for the kdimensional Boolean matrix product is to report a witness for each nonzero entry of the product. The maximum witness problem for the kdimensional Boolean matrix product is to report the maximum witness for each nonzero entry of the product.
Note that in particular, the $two$dimensional matrix product of the matrices ${A}_{1}$ and ${A}_{2}$ coincides with the standard matrix product of ${A}_{1}$ and ${\left({A}_{2}\right)}^{T}$ which yields ${\omega}_{2}=\omega .$
The following lemma provides an upper bound on the time complexity of the multidimensional matrix product in terms of those for rectangular matrix multiplication.
Lemma 1. Let $k,{k}_{1},{k}_{2}$ be three positive integers such that $k={k}_{1}+{k}_{2}.$ Both in the arithmetic and Boolean case, the kdimensional matrix product of k $n\times {n}^{r}$ matrices can be computed using $O\left({n}^{\omega ({k}_{1},r,{k}_{2})+o\left(1\right)}\right)$ arithmetic operations, consequently ${\omega}_{k}\le \omega ({k}_{1},1,{k}_{2}).$ In addition, in the Boolean case, the witness problem for the kdimensional matrix product can be solved in $O\left({n}^{\omega ({k}_{1},r,{k}_{2})+o\left(1\right)}\right)$ time.
Proof. To prove the first part, it is sufficient to consider the arithmetic case as the Boolean one trivially reduces to it.
Let ${A}_{1},\dots ,{A}_{k}$ be the input matrices. Form an ${n}^{{k}_{1}}\times {n}^{r}$ matrix A whose rows are indexed by ${k}_{1}$tuples of indices in $\left[n\right]$ and whose columns are indexed by indices in $\left[{n}^{r}\right]$ such that $A[{i}_{1},\dots ,{i}_{{k}_{1}},\ell ]={A}_{1}[{i}_{1},\ell ]\times \dots \times {A}_{{k}_{1}}[{i}_{{k}_{1}},\ell ].$ Similarly, form an ${n}^{{k}_{2}}\times {n}^{r}$ matrix B whose rows are indexed by ${k}_{2}$tuples of indices in $\left[n\right]$ and whose columns are indexed by indices in $\left[{n}^{r}\right]$ such that $B[{j}_{1},\dots ,{j}_{{k}_{2}},\ell ]={A}_{{k}_{1}+1}[{j}_{1},\ell ]\times \dots \times {A}_{k}[{j}_{{k}_{2}},\ell ].$ Compute the rectangular matrix product C of the matrix A with the matrix ${B}^{T}$. By the definitions, the $D[{i}_{1},\dots ,{i}_{{k}_{1}},{i}_{{k}_{1}+1},\dots ,{i}_{k}]$ entry of the kdimensional product of the input matrices ${A}_{1},\dots ,{A}_{k}$ is equal to the entry $C[{i}_{1},\dots ,{i}_{{k}_{1}},{i}_{{k}_{1}+1},\dots ,{i}_{k}].$ The matrices $A,\phantom{\rule{4pt}{0ex}}B$ can be formed in $O({n}^{{k}_{1}+r}+{n}^{{k}_{2}+r})$ time, i.e., $O\left({n}^{max({k}_{1}+r,{k}_{2}+r)}\right)$ time, while the product C can be computed in $O\left({n}^{\omega ({k}_{1},r,{k}_{2})+o\left(1\right)}\right)$ time.
To prove the second part of the lemma, it is sufficient to consider Boolean versions of the matrices $A,\phantom{\rule{4pt}{0ex}}B,\phantom{\rule{4pt}{0ex}}C$ and use Fact 2. □
By combining Lemma 1 with Fact 1, we obtain the following corollary.
Corollary 1. For even $k\ge 8,$ ${\omega}_{k}=k+o\left(1\right).$
Proof. We obtain the following chain of equations on the asymptotic time required by the
kdimensional matrix product using Lemma 1 and Fact 1:
□
Consider the Boolean case. By the definition, the kdimensional Boolean matrix product can be computed in time proportional to the size of the product multiplied by the size of witness range. By generalizing the column–row method for the Boolean matrix product of two Boolean matrices, we obtain an outputsensitive upper bound on the time required to compute the kdimensional Boolean matrix product.
Theorem 1. Suppose $k\ge 2$ and $k=O\left(1\right).$ Let w be the total number of witnesses for the entries of the kdimensional Boolean product of k $n\times n$ Boolean matrices. The nonzero entries of the product can be listed in $O({n}^{2}+w)$ time. Consequently, they can be listed in $O({n}^{2}+sn)$ time, where s is the number of nonzero entries in the product.
Proof. Let D stand for the kdimensional Boolean matrix product. For $m=1,\dots ,k,$ $\ell =1,\dots ,n,$ compute the set ${S}_{m}(\ell )$ of indices i such that ${A}_{m}[i,\ell ]=1.$ Next, for $\ell =1,\dots ,n,$ compute the Cartesian product $S(\ell )={S}_{1}(\ell )\times \dots \times {S}_{k}(\ell ).$ Note that $S(\ell )$ coincides with the set of ktuples ${i}_{1},\dots ,{i}_{k}$ such that ℓ is a witness for $D[{i}_{1},\dots ,{i}_{k}].$
Assuming $k=O\left(1\right),$ we can compute the sets ${S}_{m}(\ell )$ in $O\left({n}^{2}\right)$ time. The sets $S(\ell )$ can be computed in $O(w+n)$ time. On their basis, the nonnegative entries of the product D can be listed in $O\left(w\right)$ time. This proves the first part. The second part follows immediately from the fact that a nonzero entry of D can have at most n witnesses. □
The best known algorithm for the maximum witness problem for the twodimensional Boolean matrix product from [
9] relies on the multiplication of rectangular submatrices of the input matrices. We generalize this idea to include the maximum witness problem for the
kdimensional Boolean matrix product.
First, each of the input matrices is divided into vertical strip submatrices of an appropriate width
$\le \ell $. Then, the multidimensional Boolean products of the corresponding submatrices are computed in order to detect, for each positive entry of the multidimensional output matrix, the interval of length
$\le \ell $ containing the maximum witness. Finally, the maximum witnesses are found separately for each of the positive entries by verifying the respective
$\le \ell $ candidates. More details can be found in the following pseudocode (in Algorithm 1).
Algorithm 1 Generalize the multiplication of rectangular submatrices of the input matrices to include the maximum witness problem for the kdimensional Boolean matrix product. 
Input: Boolean $n\times n$ matrices ${A}_{i}$, $i\in \left[k\right],$ and a parameter $\ell \in \left[n\right].$ Output: maximum witnesses for all nonzero entries of the kdimensional Boolean product of the matrices ${A}_{1},\dots ,{A}_{k}$ and “No” for all zero entries of the product.
For $i\in \left[k\right],$ divide ${A}_{i}$ into $\lceil n/\ell \rceil $ vertical strip submatrices ${A}_{i}^{1},\dots ,{A}_{i}^{\lceil n/\ell \rceil}$ of width ℓ with the exception of the last one that can have width $\le \ell .$ for$p\in [\lceil n/\ell \rceil ]$ compute the kdimensional Boolean product ${B}_{p}$ of ${A}_{1}^{p},\dots ,{A}_{k}^{p}$ for all ${i}_{1},\dots ,{i}_{k}\in \left[n\right]$ do  (a)
Find the largest p such that ${B}_{p}[{i}_{1},\dots ,{i}_{k}]=1$ or set $p=0$ if it does not exist.  (b)
if$p>0$then return $\ell (p1)+max\{r\in [\ell (p1)+1,\ell p]{A}_{1}^{p}[{i}_{1},r]\wedge \dots \wedge {A}_{k}^{p}[{i}_{k},r]=1\}$ else return “No”

The correctness of Algorithm 1 is obvious. By its time analysis and Lemma 1, we obtain the following theorem.
Theorem 2. Suppose $k\ge 2$ and $k=O\left(1\right).$ For any $\ell \in \left[n\right]$, the maximum witness problem for the kdimensional Boolean product of k Boolean $n\times n$ matrices can be solved by Algorithm 1 in time $O((n/\ell ){n}^{{\omega}_{k}(1,{log}_{n}\ell )+o\left(1\right)}+{n}^{k+1}/\ell +{n}^{k}\ell )\le $
$O((n/\ell ){n}^{\omega (\lceil k/2\rceil ,{log}_{n}\ell ,\lfloor k/2\rfloor )+o\left(1\right)}+{n}^{k+1}/\ell +{n}^{k}\ell )$.
Proof. Step 1 takes $O\left({n}^{2}\right)$ time. Step 2 requires $O\left((n/\ell ){n}^{{\omega}_{k}(1,{log}_{n}\ell )+o\left(1\right)}\right)$ time. Step 3(a) takes $O({n}^{k}\times n/\ell )$ time totally. Finally, Step 3(b) requires $O({n}^{k}\ell )$ time totally. □
By Theorem 2, the total time taken by Algorithm 1 for maximum witnesses is
By setting r to ${log}_{n}\ell $, our upper bound transforms to $O({n}^{1r+{\omega}_{k}(1,r)+o\left(1\right)}+{n}^{k+1r}+{n}^{k+r})$. Since a solution $\lambda $ to the equation $1r+{\omega}_{k}(1,r)=k+r$ satisfies $\lambda \ge \frac{1}{2}$ by ${\omega}_{k}(1,\lambda )\ge k$, we can get rid of the additive ${n}^{k+1r}$ term. In addition, it follows from ${\omega}_{k}(1,\lambda )\le \omega (\lceil k/2\rceil ,\lambda ,\lfloor k/2\rfloor )$ that $\lambda \le {\lambda}^{\prime},$ where ${\lambda}^{\prime}$ satisfies $\omega (\lceil k/2\rceil ,{\lambda}^{\prime},\lfloor k/2\rfloor )=k1+2{\lambda}^{\prime}.$ Hence, we obtain the following result.
Theorem 3. Let λ satisfy ${\omega}_{k}(1,\lambda )=k1+2\lambda $ and let ${\lambda}^{\prime}$ satisfy $\omega (\lceil k/2\rceil ,{\lambda}^{\prime},\lfloor k/2\rfloor )=k1+2{\lambda}^{\prime},$ respectively. Suppose $k=O\left(1\right).$ The maximum witnesses for all nonzero entries of the kdimensional Boolean product of k $n\times n$ Boolean matrices can be computed by Algorithm 1 in $O\left({n}^{k+\lambda +o\left(1\right)}\right)=O\left({n}^{k+{\lambda}^{\prime}+o\left(1\right)}\right)$ time.
4. Breaking the Hegemony of the Triangle Method in Clique Detection
The following Algorithm 2 is a straightforward generalization of that due to Itai and Rodeh for triangle counting [
18] to include
${K}_{r}$ counting, for
$r\ge 3$.
Algorithm 2 A straightforward generalization of that due to Itai and Rodeh for triangle counting [18] to include ${K}_{r}$ counting, for $r\ge 3$. 

The correctness of Algorithm 2 follows from the fact that the number of ${K}_{r}$ copies including a given copy C of ${K}_{r1}$ in the host graph is equal to the number of vertices outside C in the graph that are adjacent to all vertices in C and that a copy of ${K}_{r}$ includes exactly r distinct copies of ${K}_{r1}$ in the graph.
The first step of Algorithm 2 can be implemented in $O\left({n}^{r1}\right)$ time. We can use the $(r1)$dimensional matrix product to implement the third step by using the next lemma. It immediately follows from the definition of the product.
Lemma 2. Let D be the kdimensional matrix product of k copies of the adjacency matrix of the input graph G on n vertices. Then, for any k tuple ${i}_{1},\phantom{\rule{4pt}{0ex}}{i}_{2},\phantom{\rule{4pt}{0ex}}\dots ,\phantom{\rule{4pt}{0ex}}{i}_{k}$ of vertices of G, the number of vertices in G adjacent to each vertex in the k tuple is equal to $D[{i}_{1},{i}_{2},\dots ,{i}_{k}].$
By the discussion and Lemma 2, we obtain the following theorem.
Theorem 4. The number of ${K}_{r}$ copies in the input graph on n vertices can be computed (by Algorithm 2) in $O({n}^{r1}+{n}^{{\omega}_{r1}+o\left(1\right)})$ time.
By Lemma 1, we obtain the following corollary from Theorem 4, matching the upper time bounds on the detection/counting copies of
${K}_{4}$ and
${K}_{5}$ established in [
20].
Corollary 2. The number of ${K}_{4}$ copies in an nvertex graph can be computed (by Algorithm 2) in $O\left({n}^{\omega (2,1,1)+o\left(1\right)}\right)$ time while the number of ${K}_{5}$ copies in an nvertex graph can be computed (by Algorithm 2) in $O\left({n}^{\omega (2,1,2)+o\left(1\right)}\right)$ time. In addition, if the input graph contains a copy of ${K}_{4}$ or ${K}_{5}$, respectively, then a copy of ${K}_{4}$ can be found in the graph in $O\left({n}^{\omega (2,1,1)+o\left(1\right)}\right)$ time while that of ${K}_{5}$ ca n be found in the graph in $O\left({n}^{\omega (2,1,2)+o\left(1\right)}\right)$ time (by a modification of Algorithm 2).
5. kDominating Set
The problem of the
kdominating set is to determine, for a graph
G and a fixed natural number
k, if there is a set
S of
k vertices in
G such that each vertex in
G either is adjacent to at least one vertex in
S or belongs to
$S.$ It is a basic
$W\left[2\right]$ complete problem equivalent to the
kset cover [
27].
Eisenbrand and Grandoni improved on the straightforward enumeration algorithm by using fast rectangular matrix multiplication [
20] (cf. [
26]). Their Algorithm 3 can be simply rephrased in terms of a
kdimensional matrix product as follows.
Algorithm 3 Improved straightforward enumeration algorithm by using fast rectangular matrix multiplication. 
$\overline{A}$← the complement of the adjacency matrix of G D← the k dimensional matrix product of k copies of $\overline{A}$ if if there is a zero entry $D[{i}_{1},\dots ,{i}_{k}]$ then output “Yes” else output “No”

It is easy to see that for a set
$S=\{{v}_{{i}_{1}},\dots ,{v}_{{i}_{k}}\}$ of
k vertices in
G,
$D[{i}_{1},\dots ,{i}_{k}]$ is just the number of vertices that are not adjacent to (dominated by) any vertex in
$S.$ Thus,
S is a
kdominating set if
$D[{i}_{1},\dots ,{i}_{k}]=0$. Hence, assuming that
n is the number of vertices in
$G,$ we obtain the following upper bound given in [
20] by a simple application of Lemma 1.
Theorem 5. Algorithm 3 solves the kdominating set problem in $O\left({n}^{\omega (\lceil k/2\rceil ,1,\lfloor k/2\rfloor )+o\left(1\right)}\right)$ time.
The reduction of the
kdominating set problem to the
kdimensional matrix product given in Algorithm 3 implies the
$W\left[2\right]$ hardness of the problem of computing the
kdimensional matrix product. By Theorem 5.4 in [
39], we obtain the following corollary.
Corollary 3. The problem of computing the kdimensional Boolean matrix product is not solvable in $f\left(k\right){n}^{O\left(k\right)}$ time, for any function $f,$ unless $FPT=W\left[1\right].$
6. All kTuples LCA
In this section, we consider the lowest common ancestors of
$k\ge 2$ vertices [
30]. For an example, see
Figure 1.
Recall that an LCA of vertices ${v}_{1},\dots ,{v}_{k}$ is an ancestor v of each vertex ${v}_{i}$, $i\in \left[k\right]$ such that v has no proper descendant that is also an ancestor of each vertex ${v}_{i}$, $i\in \left[k\right]$.
We can generalize the method of solving the all pairs LCA problem in DAGs based on maximum witnesses of Boolean matrix products from [
9] to include the all
ktuples LCA problem, i.e., reporting for each
ktuple of vertices in the input DAG an LCA, as follows (in Algorithm 4).
Algorithm 4 Reporting for each ktuple of vertices in the input DAG an LCA. 
Topologically sort vertices of the input DAG G and number them in the sorted order starting from the source vertices. Compute the $n\times n$ transitive closure matrix A of G such that $A[i,j]=1$ if and only if the vertex j is an ancestor of the vertex $i.$ Compute maximum witnesses for nonzero entries of the kdimensional Boolean matrix product D of k copies of the Boolean version of the matrix $A.$ For each ktuple ${i}_{1},{i}_{2},\dots ,{i}_{k}$ of vertices, output the maximum witness of $D[{i}_{1},{i}_{2},\dots ,{i}_{k}]$ (if any) as the LCA of the ktuple.

The correctness of this generalized method follows from the fact that by the definition of the matrix A and the kdimensional Boolean matrix product D, the set of witnesses of $D[{i}_{1},{i}_{2},\dots ,{i}_{k}]$ coincides with the set of common ancestors of ${i}_{1},{i}_{2},\dots ,{i}_{k}$, and that the maximum witness of of $D[{i}_{1},{i}_{2},\dots ,{i}_{k}]$ cannot have any descendant in the aforementioned set by the vertex numbering.
The topological sort requires
$O\left({n}^{2}\right)$ time while computing the transitive closure takes
$O\left({n}^{\omega +o\left(1\right)}\right)$ time. Hence, by Theorem 3, we obtain upper bounds basically matching those derived by Yuster in [
36] and Kowaluk et al. in [
37].
Theorem 6. Let λ satisfy ${\omega}_{k}(1,\lambda )=k1+2\lambda $ and let ${\lambda}^{\prime}$ satisfy $\omega (\lceil k/2\rceil ,{\lambda}^{\prime},\lfloor k/2\rfloor )=k1+2{\lambda}^{\prime},$ respectively. Suppose $k=O\left(1\right).$ The all ktuples LCA problem can be solved by Algorithm 4 in $O\left({n}^{k+\lambda +o\left(1\right)}\right)=O\left({n}^{k+{\lambda}^{\prime}+o\left(1\right)}\right)$ time.
Corollary 4. Let $\lambda ,{\lambda}^{\prime}$ and ${\lambda}^{\u2033}$ satisfy ${\omega}_{3}(1,\lambda )=2+2\lambda $, $\omega (2,{\lambda}^{\prime},1)=2+2{\lambda}^{\prime}$, and $\omega (1,{\lambda}^{\u2033},1)=1+2{\lambda}^{\u2033}$, respectively. The all 3tuples LCA problem can be solved in $O\left({n}^{3+\lambda +o\left(1\right)}\right)=O\left({n}^{3+{\lambda}^{\prime}+o\left(1\right)}\right)$
$=\left({n}^{3+{\lambda}^{\u2033}+o\left(1\right)}\right)=O\left({n}^{3.529}\right)$ time.
Proof. By dividing an ${n}^{2}\times {n}^{r}$ matrix into n $n\times {n}^{r}$ matrices, we obtain the inequality $1+\omega (1,r,1)\ge \omega (2,r,1)$. The inequality ${\lambda}^{\u2033}\ge {\lambda}^{\prime}$ follows from $1+\omega (1,r,1)\ge \omega (2,r,1)$ similarly as ${\lambda}^{\prime}\ge \lambda $ follows from ${\omega}_{3}(1,r)\le \omega (2,r,1)$ in the proof of Theorem 3. By the recent results on fast rectangular multiplication, ${\lambda}^{\u2033}<0.529$ holds. □
7. Final Remarks
We have applied our results on the multidimensional matrix product to provide a simple alternative method for clique detection and to rephrase known algorithms for kdominating set problem and the all ktuples LCA problem in DAGs. Our direct reduction of the kdominating set problem to the kdimensional matrix product yields the $W\left[2\right]$ hardness of the latter problem. In the context of the reduction, note that the problem of computing the kdimensional (even Boolean) matrix product is more general than the kdominating set problem, since the input matrices do not have to be identical as in the reduction.
It is an intriguing open problem if the upper bounds in terms of rectangular matrix multiplication on the kdimensional matrix product of k square matrices given in Lemma 1 are asymptotically tight. In other words, the question is if ${\omega}_{k}={min}_{{k}^{\prime}=1}^{k1}\omega ({k}^{\prime},1,k{k}^{\prime})$ holds or more specifically if ${\omega}_{k}=\omega (\lceil k/2\rceil ,1,\lfloor k/2\rfloor )$? If this was not the case for k equal to 3 or 4, then we would achieve a breakthrough in detection/counting of ${K}_{4}$ or ${K}_{5},$ respectively.
An argument for the inequality ${\omega}_{k}<\omega ({k}_{1},1,{k}_{2})$, for positive integers ${k}_{1},\phantom{\rule{4pt}{0ex}}{k}_{2}$ satisfying $k={k}_{1}+{k}_{2},$ is that in the context of the efficient reduction in the proof of Lemma 1, the rectangular matrix product seems more general than the kdimensional one. A reverse efficient reduction seems to be possible only under very special assumptions. However, proving such an inequality would be extremely hard as it would imply $\omega ({k}_{1},1,{k}_{2})>k$ and in consequence $\omega >2$ by the straightforward reduction of the rectangular matrix product to the square one. On the other hand, this does not exclude the possibility of establishing better upper bounds on ${\omega}_{k}$ than those known on $\omega ({k}_{1},1,{k}_{2})$.
A related question is whether or not $\lambda $ satisfying the equation ${\omega}_{k}(1,\lambda )=k1+2\lambda $ is equal or less than ${\lambda}^{\prime}$ satisfying the equation $\omega (\lceil k/2\rceil ,\lambda ,\lfloor k/2\rfloor )=k1+2\lambda $? An inequality for $k=2$ would yield the improvement of the longstanding upper time bound for the maximum witness problem of the Boolean product of two $n\times n$ Boolean matrices from $O\left({n}^{2+{\lambda}^{\prime}}\right)$ to $O\left({n}^{2+\lambda}\right).$
These two open problems and the quest for finding further applications of the multidimensional matrix product form the future directions of our research.