International Conference on Advanced Computer Science and Electronics Information (ICACSEI 2013)

The Transitive Closures of Matrices over Idempotent and its Applications*

Wang Zhixi1, Wang Yana1, He Yong1, Hu Binliang2 1 School of Computer Science and Engineering, Hunan University of Science and Technology, Xiangtan 411201, Hunan, China 2Colleges of Electromechanical Engineering, Hunan University of Science and Technology, Xiangtan 411201, Hunan, China [email protected], [email protected], [email protected], [email protected]

Abstract - The Algebraic Path Problem is an important issue method has been improved from every angle and its with a broad background. Consider the problem to solve the application has a gradual expansion from some special algebraic path problem can be concluded to find the Kleene semirings first to general cases, and the computing power of the adjacency , an algorithm of time complexity O() n 3 to with the introduction of advanced technologies such as find the transitive closure of matrices over idempotent is parallel computing has been greatly improved [7-14]. constructed, as well as the conditions applicable to it are provided. However, the semirings applied to Gauβ- Jordan elimination Compared with the Gauβ-Jordan elimination, this algorithm could method always required completeness and closeness. extend the applicable range to certain semirings which do not have Note that the Kleene Closures of matrices over completeness and closeness, Thus, it has a wide application since it Idempotent semirings are easily obtained by their Transitive can provide a new method to solve the algebraic path problem over Closures. This paper constructs an algorithm to find the idempotent semirings which do not have completeness and closeness. Transitive Closures of matrices over idempotent semiring and Index Terms - Idempotent semiring, Transitive Closures, provides conditions applicable to it. Actually, the algorithm Transitive_Closure Algorithm, Algebraic Path Problem. extends the applicable range of Gauβ-Jordan elimination method to certain semirings which do not have completeness I. Introduction and closeness.

The Algebraic Path Problem, which is to perform a II. Preliminary special unary operation, called closure, on a square matrix over semirings based on semirings-algebraic theory, is an Let R be a non-empty defined the addition  and important issue with a broad background. This problem the multiplication  . If (,)R  is a commutative , and generalizes some matrix problems(such as computing the (,)R  is a semigroup, moreover, multiplication  satisfies inverse of a real-valued matrix), graph problems(e.g. transitive closure, shortest path, the stochastic communication the distributive law to addition  , then the algebraic system network problem), and regular language problems(e.g. the RR(,,)   is called a semiring. Usually, the product a b proof of the correspondence between regular expressions and of elements a , b over semiring R is denoted byab . Denote finite automata). Algebraic path problem and its algorithms that a(m ) a  a 2   am for the element a of R and positive have a wide application in the field of network engineering, image processing and pattern recognition. integer m . In 1956, Kleene proved that every regular language can Assume that R is a semiring. If 1R is the identity be represented by a regular expression. Actually, it was the element of (,)R  , then we say that 1 is the first algorithm for the algebraic path problem[1]. And in of R . If 0R is the identity element of (,)R  and the zero 1962, Warshall algorithm for computing the transitive closure and Floyd algorithm for shortest path problem were element of(,)R  , then we say 0 is the zero element of R . respectively proposed[2-3]. Later, Gaussian elimination for Define the  over semiring R as computing the inverse of matrices was also presented[4-5]. a b  a  b  a . We call R an idempotent semiring if for any Warshall algorithms, Floyd algorithms and Gaussian a R , then a a . It is easy to prove that the relation  over elimination method are classical algorithms for these three the idempotent semirings is a partial order relation. The problems respectively [2-4]. Until 1971, Carré discovered the idempotent semirings have a significant application in similarities between these algorithms and proposed their solving optimization problems and the classification of general form Gauβ-Jordan elimination for solving them based regular languages, c.f. [14-16]. on semirings algebra theory. The algorithm for solving algebraic path problem boiled down to find the Kleene For the element a of R , let (a )  { x  R x  a , x  xx } , closure of , i.e., the summation of all non- we call that at is the transitive closure of a if at () a and negative integer powers of the adjacency matrix[6]. Since t then, with an in-depth study, Gauβ-Jordan elimination for any x()A , x a .

* This work is supported by National Nature Science Foundation of China (No:61272196), Hunan Provincial Natural Science Foundation of China ( No: 10JJ3067), and Scientific Research Fund of Hunan Provincial Education Department (No: 11C0534).

© 2013. The authors - Published by Atlantis Press 174 Similar to the numerical matrices, we can define The Analysis of The Complexity of Algorithm. matrices and their addition and multiplication over semiring The algorithm firstly is to compute the matrices A[]n , R . Denote the element (,)i j  of A over R by Aij , and then is to check the applicable conditions of the algorithm. Taken the assignment, addition, multiplication and matrix that the element (,)i j  is a over R by ()a . The set ij ij comparison operations of the elements of the semiring as a of all n square matrix over R is recorded as MRn() .Then basic operation respectively, we can conclude that the first part needs 3n ( n 1)2 times of basic operations, and the second MRn() with regard to matrix addition and multiplication also forms a semiring called an n square matrix semiring over part takes up at most 2n 3 times of the basic operations. 3 R . The relation  on MRn() is defined as: ABAB ij  ij Hence, the time complexity of the algorithm is O() n , which has the same order with the time complexity of the Floyd for 1i , j  n . Obviously, MRn() is idempotent if and only if algorithm and the Gauβ-Jordan algorithm, c.f. [4], [12]. R is idempotent. For the n square matrix A over R and positive integer m , we set AAAA(m )  2   m , and denote IV. Proof Of The Transitive_Closure Algorithm m m the element (,)i j  of A by Aij , and also the element In this section, we assume that R is an idempotent

()m ()m semiring, n is a given positive integer, and A()() aij  M n R . (,)i j  of A by Aij . The basic properties of matrices We need Lemma 2 to Lemma 4 as follows to prove the over semirings and the details of semirings can be found in Transitive_Closure algorithm, i.e., the Theorem 1. literature [15]. Lemma 2 Let a,,,, b c d x R with 1i  m . Then the following For the n square matrix A over R and the non- i [][]k k condition holds: negative integer k with kn , we define matrices AA ij  m a x a x i1, 2, , m recursively as follows: (1)  i if and only if i , for . i1 A , k0  ij (2) If there exists an integer i such that xi a , then AA[k ] [ k 1] , i k or j  k ij ij m A[k 1] A [ k  1] A [ k  1] , 1 k  n and i  k and j  k  ij ik kj xi a . i1 III. The Analysis Of The Complexity Of Transitive_Closure (3) If a b , cd , then acbd . Algorithm Proof. (1) Assume that a xi with i1, 2, , m , then The following theorem is the main conclusion of this m m m article, and we will consider the proof of this matter in next a xi  () a  xi   a  a . section. i1 i  1 i1 m Theorem 1. Let R is an idempotent semiring, AMRn() , Conversely, assume that a xi , then for each xi , we i1 t[] n [][][]n n n then AA if and only if AAAij ik kj for 1i , j , k  n . m m have a xi  a  xi  x i  a   xi  a . Theorem 1 provides an algorithm to compute the i1 i1 transitive closures of the n square matrix over idempotent (2) Assume that there exists an integer i such that semiring, the algorithm can be described by the pseudo codes x a . Further assume that i1 , then as follows: i m m m Transitive_Closure Algorithm a xi () a  x1   xi   x i . i1 i2 i  1 Function Transitive_Closure(Matrix A, Matrix W) (3) Assume that a b , c d , then n = A.rows, W = A ac bd ( a  b )( c  d )  bd '' n is the order of the matrix, W is the result matrix '' First part: Calculate the matrix W, i.e., the matrix A[n] ac  ad  bc  bd  bd For k = 1 To n ac  ad  bc  bd . For i = 1 To n, j = 1 To n Do '' Calculate the matrix A[k] (a  b )( c  d ) If i = k Or j = k Then Continue For ac W(i, j) = W(i, j) + W(i, k) * W(k, j)) Lemma 3. Assume a R , x() a , then the following Next Next k conditions holds: '' Second part: Check the applicable condition of the algorithm (max(r , p q )) For i = 1 To n, j = 1 To n, k = 1 To n Do (1) a()()()r a p a q  a , where r,, p q are all positive '' Check whether W <= W * W integers. If Not W(i, j) <= W(i, k) * W(k, j) Then Return FALSE m ()m Next (2) For any positive integer m , x a and x a . Return TRUE (3) If there exists a positive integer m such that a()m  x , End Function then at  x ()a()m .

175 B. Judgment Of Loop_Nonnegative Matrices Proof . (1) By the idempotence of MRn(), we can conclude that The element x is non-negative if it satisfies the relation p q 1x in semiring R . For the n square matrix A() aij over ()()()()r p q r i i a a a  a  a   a semiring R , we call that A is loop non-negative if all of the i1 i  1 p q ()r i j elements in {ai i a i i a i i |1m , 1i1 , i 2 , , im n } are non- a   a 1 2 2 3m 1 i1 j  1 p q negative. a()r  a  ai i2 Theorem 2. Let R is an idempotent semiring, and AMR() . a()()r  a p q n [][][]n n n (max(r , p q )) If AAA , then A is loop_nonnegative if and only if a []n (2) The proof is by mathematical induction. It is evident 1Aii , for 1i  n . that xa is trivial. Assume that for some positive integer m , Proof. Since AAA[][][]n n n , thus we can easily know xam . From the fact that w() a and by (3) of Lemma 2, AA []n . And by (1) of Lemma 2, we also have: we can easily get that x xx  aam  a m1 , thus, for any positive 1a a a 1AA  []n A m i i i i i i if and only if i i i i , that is to say, is integer m , we have xa . Recall that (1) of Lemma 2, we 1 2 2 3m 1 1 1 1 1 []n obtain xa()m for any positive integer m . loop_nonnegative if and only if for 1i  n , 1Aii . (3) By applying (2) and the anti-symmetry property, we We can conclude by Theorem 2 that Transitive_Closure n obtain x a()m . Moreover, it is also clear that for any algorithm can be used to judge whether the -square matrix ()m t A over the idempotent semiring R is loop_nonnegative after w() A , w a  x . Then, by the definition of a , we have some appropriate changes. The method is to add the at x  a() m . following statements before the statement "Return TRUE", where “Identity” denotes 1 . Lemma 4. For any positive integer k with kn , we have

k AA(2 ) [k ] . For i = 1 To n Do '' Check Identity <= W(i, i) If Not Identity <= W(i, i) Then Return FALSE '' NOT Proof. By the definition of A[1] and (2) of Lemma 2, we Next can get AAAA(2)  2  [1] . By induction hypothesis, assume C. The Algebraic Path Problems k that for some positive integer with k n , we have Let R be a semiring, GVE(,) be a (directed) graph, k (2k ) [k ] (2)k1 (2)k (2) k (2 ) []k [][] k k [1] k AA , then AAAAAAAA     is where V{1,2, , n } is the vertices set, and EVV  is the obtained by the definition of A[k 1] , (2) of Lemma 2 and (1) of edges set. The set of all paths from vertex i to vertex j is Lemma 3. For above all, then we have: denoted by i j . the length of the path p in G is denoted by Proof of Theorem 1. |p | . For a given function w: E R , we can define the By (1) of Lemma 2, we can conclude that for weighted graph G(,,) V E w over R . The image w() e of [][][]n n n [][][]n n n 1i , j , k  n , AAAij ik kj is equivalent to AAA . function w is called the value of e . The adjacency matrix n  A()() G w of G is defined as follows: ) If AAt    , by the definition of At , AAA[][][]n n n . ij []n [][][]n n n []n w(( i , j )), ( i , j ) E ) Since AA and AAA , we can obtain A ()A . w  ij 0, (i , j ) E n  Then, we also have AA(2 ) [n ] by Lemma 4. and hence by (3) For p(,,,) p p p i  j , we say that w()() pk w p is of Lemma 3, AAt [] n . 0 1 k i0 i defined as dij   w() p . V. The Application Of Transitive_Closure Algorithm p i  j Algebraic path problems over a semiring is actually to A. The Plus Closure of Matrices find the distance between any two vertices i and j over the The sum a a  a2  a 3  of all positive integer power weighted graph G(,,) V E w of R . If there exist solutions to of element a in semiring R is called the Plus Closure of a . the algebraic path problems, we call that the matrix If R is an idempotent semiring and AMR n() satisfies  S()() G dij is the solution matrix of G . Obviously, if AG() [][][]n n n []n AAA , then A ()A . By (2) of Lemma 3, we obtain  n exists, then SGAG()()  . Consequently, If R is an AA[]n   . Moreover, Lemma 4 allows to show AAA (2 ) [n ] . idempotent semiring and AAG () satisfies the relation Consequently, the anti-symmetry property yields that [][][]n n n AA []n . Therefore, Transitive_Closure algorithm can be AAA , Transitive_Closure algorithm is an effective used to compute the Plus Closure of matrices over idempotent method to find the solution matrix SG() of G . Actually, if semirings. *  the process of computing the Kleene Closure AIAn  of

176 A can be added to the algorithm, where I is the n square [2] Warshall S. A Theorem on Boolean Matrices[J]. Journal of the ACM, n 1962, 9(1): 11-12. identity matrix, then we can obtain the same results as the [3] Floyd R W. Algorithm 97: Shortest path[J]. Communications of the Gauβ-Jordan elimination method. In this case, there is no ACM, 1962, 5(6): 345. need to require completeness and closeness of R . [4] Dasgupta S. Papadimitriou C. Vazirani U. Algorithms[M], The McGraw- Hill Companies, Inc., New York, 2008. D. The Shortest Path Problem Over Totally Ordered Idempotent [5] Forsythe G. E. and Moller C. B. computer solution of linear algebraic Semiring systems. Prentice Hall, Englewood Cliffs, NJ,1967. If R is an idempotent semiring and the partial order [6] Carré B A. An algebra for network routine problems[J]. Journal of the Institute of Mathematical and Its Applications, 1971, 7: 273-294. relation  over R is a total ordering relation, we say that R [7] Zimmermann U. Linear and combinatorial optimization in ordered is a total ordering idempotent semiring. For any two vertices algebraic structures[J]. Annals of Discrete Mathematics, 1981, 10: 1-380. i, j of G , note that even if d may exists, the shortest path [8] Gunter-Roze G. A systolic array algorithm for the algebraic path problem ij (Shortest path; Matrix inversion) [J]. Computing, 1985, 34: 191-219. from i to j may still not. When R is a total ordering [9] Tsai H, Horng S, Tsai S, et al. Solving an algebraic path problem and idempotent semiring and AAG () satisfies the relation some related graph problems on a hyper-bus broadcast network[J]. IEEE Transactions on Parallel and Distributed Systems, 1997, 8 (12): 1226- AAA[][][]n n n , then by the total ordering property of the partial 1235. ordering relation  over R , necessarily there exists a [10] Djamegni C T, Quinton P, Rajopadhye S, et al. Derivation of systolic algorithms for the algebraic path problem by recurrence shortest path from i to j . Therefore, Modeled on Floyd transformations[J]. Parallel Computing, 2000, 26 (17): 1429-1445. algorithms, we can construct an algorithm based on [11] Takahashi A, Sedukhin S. Parallel Blocked Algorithm for solving the Transitive_Closure algorithm to solve the shortest path algebraic path problem on a matrix processor[J]. Lecture Notes in problems over R . Computer Science, 2005, 3726: 786-795. [12] Lluch-Lafuente A, Montanari A. Quantitative μ-calculus and CTL VI. Acknowledgment defined over constraint semirings[J]. Theoretical Computer Science, 2005, 346 (1): 135-160. This work is supported by National Nature Science [13] Mohri M. Semiring frameworks and algorithms for shortest-distance Foundation of China (No:61272196), Hunan Provincial problems[J]. Journal of Automata, Languages and Combinatorics, 2003, Natural Science Foundation of China ( No: 10JJ3067), and 7 (3): 321-350 [14] Penn G. Efficient transitive closure of sparse matrices over closed Scientific Research Fund of Hunan Provincial Education semirings[J]. Theoretical Computer Science, 2006, 354 (1): 72 - 81 . Department (No: 11C0534). [15] Polak . A classification of rational languages by semilattice-ordered [J]. Archiv der Mathematik, 2004, 3153: 635-647. References [16] Golan J S. Semirings and Their Applications[M]. Kluwer Academic [1] Kleenee S. C. Representation of events in nerve nets and finite automata. Publishers, Dordrecht, 1999. Annals Of Mathematics Studies 34, Automata Studies, eds: J. McCarthy and C.E. Shannon, 1956, page 3-41.

177