Maximum permuted of a matrix Definition 1. A mn binary matrix is a matrix of m rows and n columns whose entries are ones and zeros. We denote the set of binary mn matrices by Bmn. Definition 2. Let A, BBmn. We define B is permuted of A (denoted BA) if there are a permutation r on the set {1, ..., m} and a permutation c on the set {1,...,n}, such that an entry bi j in row i, column j of B takes the value of entry in row r(i), column c(j) of A, where 1im and 1jn. We denote the set of permuted of A by Per(A). Lemma 1. The relation is an equivalence relation in the set Bmn. Proof Let A, B, C be any matrices in Bmn. Reflexivity. AA: The matrix A can be obtained by identity permutations of its rows and columns. Thus, AA holds. Symmetry. If BA, then AB: Let BA. So, B is obtained by permuting rows (r) and columns (c) of A. Thus, A is obtained from B taking the inverse permutations (r-1 and c-1). Therefore, AB holds. Transitivity. If (BA and CB), then CA: Since CB, C is obtained from B by permuting its rows (r) and columns (c). Since BA, B is obtained from A by permuting its rows (´r) and columns (´c). Then, C can be obtained from A by permuting rows and columns of A through composing (r´r) and (c´c), respectively. Thus, CA holds. This completes the proof. Remark 1. Because of lemma 1, following properties are satisfied for every A, B, CBmn: APer(A). APer(B) BPer(A). BPer(A) , CPer(B) CPer(A) Definition 3. Let A, BBmn. We denote AB and say that A and B are equivalent by permutation if BA or AB. Theorem 1. The relation is an equivalence relation in the set Bmn. Proof It is obvious from AB holds if and only if AB, since the symmetry of . Lemma 2. The following properties hold for every A, BBmn. a) AB Per(A) = Per(B) b) Per(A)Per(B) Per(A) = Per(B). Proof Both properties are satisfied since is an equivalence relation in the set Bmn and Per(A) is the equivalence class of a binary mn matrix A. Part a) tell us that equivalent matrices are in the same equivalence class. Part b) tell us that different equivalence classes are disjoint. Definition 4. We define the relation is previous to in the set {1,...,m}{1,...,n} of positions in a mn binary matrix as follows: 1 Given row h, column k in ABmn, we denote (h, k) (h´, k´) and say that position (h, k) is previous to position (h´, k´) if k+(h-1)n k´+(h´-1)n is satisfied. Lemma 3. The relation “is previous to” is a total order relation in the set of positions {1,...,m}{1,...n} of a binary mn matrix. Proof. Let (h, k), (h´, k´), (h, k) be any positions in A. Reflexivity. (h, k) (h, k): Since k+(h-1)n = k+(h-1)n, we have that (h, k) (h, k). Anti-symmetry. If (h, k) (h´, k´) and (h´, k´) (h, k), then (h, k) = (h´, k´): If (h, k) (h´, k´), then k+(h-1)n k´+(h´-1)n. If (h´, k´) (h, k), then k´+(h´-1)n k+(h-1)n. Both inequalities imply that k+(h-1)n = k´+(h´+1)n. Then, k-k´ = n(h´-h). (1) From 1kn and 1k´n, we have 1-nk-k´n-1 (2). Since k, h, k´, h´ are integers satisfying expressions (1) and (2), then it must be h´-h=0 and k-k´=0, say (h, k)=(h´, k´). Transitivity. If (h, k) (h´, k´) and (h´, k´) (h, k), then (h, k) (h, k): If (h, k) (h´, k´), then k+(h-1)n k´+(h´-1)n. If (h´, k´) (h, k), then k´+(h´-1)n k+(h-1)n. Both inequalities imply that k+(h-1)n k+(h-1)n. Thus, (h, k) (h, k). Completeness. Either (h, k) (h´, k´) or (h´, k´) (h, k) or both: By comparing the numbers k+(h-1)n and k´+(h´-1)n three cases arise: 1) k+(h-1)n < k´+(h´-1)n. Then we have that (h, k) (h´, k´). 2) k´+(h´-1)n < k+(h-1)n. Then we have that (h´, k´) (h, k). 3) k+(h-1)n = k´+(h´-1)n. Then both hold, (h, k) (h´, k´) and (h´, k´) (h, k). This completes the proof. Remark 2. We denote (h, k) < (h´, k´) if (h, k) (h´, k´) and (h, k)(h´, k´). Definition 5. We define a relation > on Bmn as follows: Given A, BBmn, we denote A>B if there are a position (h, k) such that ah k>bh k and ai j=bi j for any position (i, j) such that (i, j) < (h, k). Definition 6. We define a relation on Bmn as follows: Given A, BBmn , AB if either A>B or A=B. Lemma 4. The relation is a total order in Bmn. Proof Let A, B, C be any matrices in Bmn. Reflexivity. AA: For any ABmn , A=A holds. Therefore, AA. Anti-symmetry. If (AB and BA), then A=B: From AB, either A=B or A>B. From BA, either A=B or B>A. We shall show that A>B and B>A are contradictories. So, it should be A=B. (a) If A>B, there are a position (h, k) such that ah k>bh k and ai j=bi j for any position (i, j) < (h, k). 2 (b) If B>A, there are a position (h´, k´) such that bh´ k´>ah´ k´ and bi j=ai j for any position (i, j) < (h´, k´). If (a) and (b) hold, we shall prove that neither (h, k) (h´, k´) nor (h´, k´) (h, k). This tell us that (a) and (b) contradict the fact that is total order, therefore we conclude that it should be A=B. (1) First we shall prove that (a) and (b) hold, then (h, k) (h´, k´). If (h, k) = (h´, k´), from (a) it should be ah k>bh k and from (b) bh k>ah k , that are contradictory inequalities. (2) We shall show that if (a) and (b) hold, (h, k) not is previous to (h´, k´): If (h, k) (h´, k´), then from (1) it follows that (h, k) < (h´, k´). Thus, from (a) it should be ah k>bh k and setting (i, j) = (h, k) in (b), we have bh k = ah k, that are contradictory relations. (3) We shall prove that if (a) and (b) hold, then (h´, k´) not is previous to (h, k): If (h´, k´) (h, k), then from (1) it follows that (h´, k´) < (h, k). Thus, setting (i, j) = (h´, k´) in (a) we have ah´ k´=bh´ k´ and from (b) bh´ k´>ah´ k´, that are contradictory relations. Transitivity. (AB and BC) implies AC: Let AB and BC: Case 1. A>B and B>C. (a) From A>B, there are a position (h, k), such that ah k>bh k, and ai j=bi j for any position (i, j) < (h, k). (b) From B>C, there are a position (h´, k´) such that bh´ k´>ch´ k´ and bi j=ci j for any position (i, j) < (h´, k´). If (h, k) < (h´, k´), from (a) it should be ah k>bh k and setting (i, j) = (h, k) in (b) we have bh k=ch k . Moreover, for any (i, j) < (h, k), from (a) we have ai j=bi j and from (b) bi j=ci j Thus, we have ah k>ch k and ai j=ci j for any position (i, j) < (h, k). So, A>C. If (h´, k´) < (h, k), similarly, from both (a) and (b) we have ah´ k´=bh´ k´>ch´ k´ and ai j=bi j=ci j for any (i, j) < (h´, k´). Thus, A>C. If (h, k) = (h´, k´), then from (a) and setting (h´, k´) = (h, k) in (b) we have ah k>bh k>ch k and ai j=bi j=ci j for any position (i, j) < (h, k). Therefore, A>C. Case 2. If A>B and B=C, then it is obvious that A>C. Case 3. If A=B and B>C, then it is obvious that A>C. Case 4. If A=B and B=C, then it is obvious that A=C. Therefore, if (AB and BC), then AC. Completeness. Either AB or BA or both. If A=B, then both AB and BA hold. If AB, then there are a position (h, k) such that ah k bh k, and ai j=bi j for any position (i, j) < (h, k). Two cases there arise by comparing ah k bh k: (a) ah k>bh k : Then A>B, so AB . (c) ah k<bh k : Then B>A, so BA. This completes the proof. Definition 7. Given a set CBmn we call maximum matrix of C to the unique binary matrix Max(C)Bmn such that Max(C) A, for every AC. Definition 8. Given a matrix ABmn we define the maximum-permuted of A (denoted Maxper(A) ), as the maximum matrix of the set Per(A). That is, Maxper(A)=Max(Per(A)). Theorem 2. For every A,BBmn, the following are equivalent. a) AB b) Maxper(A)=Maxper(B) Proof 3 a) b) Assume that AB. Per(A)=Per(B) Max(Per(A))=Max(Per(B)) Maxper(A)=Maxper(B) [Lemma 2.a] [Definition 7] [Definition 8] a) b) Assume that Maxper(A)=Maxper(B). Max(Per(A))=Max(Per(B)) Max(Per(A))Per(A)Per(B) Per(A)=Per(B) AB [Definition 8] [Definition 7] [Lemma 2.b] [Lemma 2.a]. Definition 9. For a mn binary matrix A, we define h-band, for 1hm, as follows: We call h-band in ABmn to every sub-matrix that contains the successive columns of A whose entries in rows 1,...,h don’t change. That is, columns p, q are columns in a h-band, if and only if ai p=ai j for every 1ih, pjq. Remark 3. There are a number bh of h-bands in a mn binary matrix, where 1<bhn. We call first h-band to the leftmost h-band and we continue on this way ordering the h-bands until the rightmost h-band will be the last h-band. Example 1. There are two 1-bands in the following matrix A: first 1-band of columns 1 to 4, whose entries in first row are 1, and second 1-band of columns 5 and 6, whose entries in first row are 0. There are four 2-bands: first 2-band with columns 1, 2, second 2-band with columns 3, 4, third 2-band with column 5 and fourth 2-band with column 6. Finally, there are six 3-bands: each one 3-band with each column of A. 1 1 1 1 0 0 A 1 1 0 0 1 0 1 0 1 0 0 1 first 1-band 1111 1100 1bands: 1 1 1 1 0 0 1 1 0 0 1 0 1 0 1 0 0 1 2bands: 1 1 1 1 0 0 1 1 0 0 1 0 1 0 1 0 0 1 3bands: 1 1 1 1 0 0 1 1 0 0 1 0 1 0 1 0 0 1 second 1-band 00 10 4 1010 01 first 2-band 11 11 10 second 2-band 11 00 10 first 3-band 1 1 1 second 3-band 1 1 0 third 2-band 0 1 0 third 3-band 1 0 1 fourth 3-band 1 0 0 fourth 2-band 0 0 A= 1 = fifth 3-band 0 1 0 sixth 3-band 0 0 1 Theorem 3.Properties of maximum-permuted of a matrix Let ABmn be a binary matrix. The maximum-permuted of A, Maxper(A), whose entry in row i, column j is denoted by gi j, whose row i is denoted by ri, satisfies the following properties: 1. The rows are in descendent order: If 1h<km, then rhrk. That is, there is an integer t, 1tn, such that gh t>gk t and gh j=gk j for every 1j<t. 2. 3. 4. 5. The number of ones in the first row is bigger than or equal to the number of ones in the remaining rows of the matrix. The first row is the form 1...10...0, that is, the position of each one in the first row is previous to the position of any 0 in the first row. Let h be any integer such that 1<hm. The number of ones in row h in the first (h-1)-band is bigger than or equal to the number of ones in every row i in the same (h-1)-band, for h<in. Let h, i be integers such that 1<h<im, and suppose that rows h, i, have the same number of ones in the first, second,...,(s-1)-th h-bands. Then, the number of ones in the s-th h-band in row h is bigger than or equal to the number of ones in row i. Let h be any integer such that 1<hn. The position of every 1 in row h in any (h-1)-band is previous to the position of every 0 in the same row and band. Proof 1. If rhrk, then rows h, k, can be interchanged, and a greater matrix than given matrix is obtained. This contradicts definition 8 of Maxper(A). 6. 2. If row i has more ones than the first row, then rows 1, i can be interchanged, and, by interchanging of columns, if necessary, the ones of the first row are brined before its zeros. Thus, a greater matrix than given matrix is obtained. This contradicts definition 8 of Maxper(A). 3. If there is a zero before a one in the first row, say g1 h=0, g1 k=1, for h<k, columns h, k can be interchanged and a greater matrix than given matrix will be obtained. This contradicts definition 8 of Maxper(A). 4. If there are i>h such that the first (h-1)-band has more ones in row i that in row h, then rows i, h can be interchanged. Then ones of new row h can be brined before its zeros, by interchanging of columns, if necessary. Thus, a greater matrix than given matrix will be obtained. This contradicts definition 8 of Maxper(A). 5 5. Assume that there are i>h such that a (h-1)-band has more ones in row i that in row h, and the remaining (h-1)-bands on the left have the same ones in rows i, h. Then rows i, h can be interchanged and ones of new row h can be brined before its zeros in every (h-1)-band, by interchanging of columns in each band, if necessary. Since any entries in each (h-1)-band on row kh-1 are equals, these entries do not change by interchanging two columns that are in the same (h-1)-band. Thus, a greater matrix than given matrix will be obtained. This contradicts definition 8 of Maxper(A). 6. Suppose that there is a zero before a one in row h, in a (h-1)-band. Let b1 be the first column and let b2 be the last column of the (h-1)-band. Then there are integers p, q, such that gh p=0, gh q=1, where b1p<qb2. Since columns p, q are in the same (h-1)-band, from definition 9, gi p=gi q for every 1ih-1. On the other hand, gh p<gh q, thus, by interchanging columns p, q we will obtain a greater matrix than given matrix. This contradicts definition 8 of Maxper(A). Lemma 5. Maxper(A) is not necessary the unique matrix in the set Per(A) that satisfies all of properties of theorem 3. Proof For inspection, properties 1 to 6 of theorem 3 are satisfied by the following different matrices A, B. Moreover, BA, through permutations r ={2,3,1,4} on rows and c ={1,2,5,6,4,3} on columns, that is, BPer(A). From remark 1, APer(A). Therefore, there are more than one unique matrix in Per(A) that satisfy these properties. A B 111100 111100 110011 111000 110010 110011 100010 101000 Lemma 6. For any binary matrix ABmn, columns of Maxper(A) are in descendent order. Proof We denote the entry of Maxper(M) of position (i, j) by gi j, its column i by ci. Suppose that there are p<q such that cqcp. Then there are s such that gs q>gs p and gi p=gi q for any 1i<s. Entries of positions (i, j) < (s, p) don’t change by interchanging columns p, q, thus a greater matrix than Maxper(A) is obtained. This contradicts definition 8 of Maxper(A). Definition 9. We define the subset GPer(A) Per(A) as follows: Let ABmn. We define B is a great-permuted of A (denoted AB) if BPer(A) and B satisfies the properties 1 to 6 of theorem 3. We denote the set of great-permuted of A by GPer(A). Algorithm 1. Finding a great-permuted of a matrix. Given a mn binary matrix A, we shall develop an algorithm for finding a great-permuted of A, denoted by B. Step 1. By replicating the matrix A, get Bo=A. Count the ones in each row of Bo. Then, choose the first row whose number of ones is the maximum. Perform a row interchange, if necessary, to bring the chosen row as row 1 in Bo. Step 2. Perform a column interchange, if necessary, to bring all the ones of the first row in Bo before its zeros. Call B1 the new matrix. 6 Step 3. Consider the 1-bands in the matrix B1. Count the ones in the first 1-band in each row 2,...,m. If there are some rows whose number of ones is the maximum, then find the number of ones of these rows in the second 1-band. Select among them the first row whose number of ones will be the maximum. Perform a row interchange, if necessary, to bring the chosen row as second row of B1. Step 4. By interchanging columns that are in the same 1-band, if necessary, bring the ones of the row 2 before its zeros in each 1-band of B1. Denote by B2 the new matrix. Step 5. In the Bs matrix, where s<m-1, count the ones of any row (s+1),...,m in the first sband, and, if there are some rows whose number of ones is the maximum, then count the ones of these rows in the second s-band, and continuing in this way, if necessary, choose among them the first row whose number of ones in the last s-band is the maximum. Perform a row interchange, if necessary, to bring the chosen row as row s+1 of Bs. Step 6. By interchanging columns that are in the same s-band, if necessary, bring the ones at row s before its zeros in each s-band of Bs. Denote by Bs+1 the new matrix. Step 7. Repeat steps 5 and 6 until either the number s of selected rows will be s=m-1, or the number bs of s-bands in the matrix Bs will be bs=n. Step 8. Perform a row interchange, if necessary, to put the rows of Bs in descendent order. Denote by B the new matrix. End of algorithm. Treorem 3. For any binary matrix ABmn , there are a matrix M such that AM and MA. Proof We shall construe a matrix M such that MA, AM by mean of algorithm 1. Some cases there arise by verifying theorem 3 for A: Case 1. Properties 1 to 6 of theorem 3 hold. Setting M=A, we have MA and AM. Consider now that A don’t satisfies theorem 3: Case 2. Property 1 falls. By ordering rows, then we obtain a matrix A´>A. We need only show A´M and MA´. To do it, verify theorem 3 for A´ as before on A. Case 3. Property 1 holds and property 2 falls. Then the first row in A has fewer ones than some of the remaining rows in A, and step 1 and following of algorithm 1 allows us to construe a matrix M such that M>A and AM. Case 4. Properties 1 and 2 hold and property 3 falls. By replicating A, let Mo=A. From property 3 falls, there is a zero before a one in the first row of Mo. Then, step 2 and following of algorithm 1 allow us to construe a matrix M such that M>Mo=A and A=MoM. Case 5. Properties 1 to 3 hold and property 4 falls. From property 4 falls, there is an integer h such that property 4 holds for rows i<h. By replicating A, let Mh-1=A. There must be some rows i>h whose number of ones in the first (h-1)-band of Mh-1 is bigger than row h. Let k>h be a row whose number of ones in the first (h-1)-band is the maximum. By interchanging rows k, h of Mh-1, then applying steps 6 and following of algorithm 1, we construe M such that M>Mh-1=A and A=Mh-1M. Case 6. Properties 1 to 4 hold and property 5 falls. There is an integer h such that property 5 holds for every row i<h. By replicating A, let Mh-1=A. There is an integer s such that property 5 holds for bands 1,...,s-1. Then there must be some rows i>h whose number of ones in the first 1,...,(s-1)-th (h-1)-bands are equal to row h, and whose number of ones in the s-th (h-1)-band is bigger than row h. Let k>h a row with the maximum number of ones in the s-th (h-1)-band. By interchanging rows k, h in Mh-1, then applying steps 6 and following of algorithm 1, we can construe M such that M>Mh1 =A and A=Mh-1M. 7 Case 7. Properties 1 to 5 hold and property 6 falls. There is an integer h such that property 5 holds for every row i<h. By replicating A, let Mh=A. There is an integer s such that property 6 falls for the s-th (h-1)-band. Then, there must be a zero before a one in the s-th (h-1)-band. By interchanging its respective columns in Mh, every row i<h don’t change and new row h is bigger than given row h. Then, by applying steps 7 and 8 of algorithm 1, we can construe M such that M> Mh=A and A=MhM. Theorem 4. The maximum-permuted of a binary matrix A, is the unique matrix G that is the maximum of the set GPer(A). That is, Max(GPer(A)) = Maxper(A). Proof Assume that G is the maximum of the set GPer(A). We must show that G is the maximum of the set Per(A), that is, GB, for any matrix BPer(A). Let BPer(A). From proof of theorem 3 process, we can construct a matrix M such that MB and BM. This implies AM, that is MGPer(A) and, from hypothesis for G, then GM. From transitivity of , we have GB. Therefore G is the maximum of Per(A), or G=Max(GPer(A))=Maxper(A). Algorithm 2. Finding the set GPer(A). Given a binary matrix ABmn , we shall develop an algorithm for finding any greatpermuted of A, by doing some changes on algorithm 1. We denote the ng obtained matrices by Bi, where 1ingm!n! 1) In step 1 of algorithm 1, select all of rows i=1,...,no with the maximum. If no>1, replicate the matrix Bo to obtain Boi for i=1,...,no. Repeat the following steps of algorithm 1 for any Boi matrix. 2) In step 3 of algorithm 1 on B1i, select all of rows h=1,...,n1 with the maximum number of ones in the last 1-band. If n1>1, replicate the matrix B1i to obtain B1ih for h=1,...,n1. Repeat the following steps of algorithm 1 for any B1ih matrix. 3) In step 5 on Bsi, select all of rows h=1,...,ns with the maximum. If ns>1, replicate the matrix Bsi to obtain Bsih for h=1,...,ns . Repeat the following steps of algorithm 1 for any Msih matrix. 4) In step 8, denote by Bi the new matrix. Add 1 to i. End of algorithm. Theorem 5. Let A be a binary matrix ABmn . By applying algorithm 2 on A provides the set GPer(A). Proof First of all, we see that the number ng of great-permuted of A is finite, because of ng<m!n!. From theorem 3, by applying algorithm 1 on A, provides a great-permuted of A. By applying algorithm 2 provides a great-permuted of A for each chosen row in steps 1, 3 and 5 of algorithm 1, modified as algorithm 2 tell us. Every row that verifies properties 1 to 6 of theorem 3 is chosen. So, every great-permuted of A is construed. Algorithm 3. Finding the maximum-permuted of a matrix. Given a binary matrix ABmn , we shall develop an algorithm for finding the maximumpermuted of A, say Maxper(A). Step 1. Obtain the ng great-permuted of A, by applying algorithm 2 on A. Denote by Bk the kth great-permuted matrix of A, where 1kngm!n!. Step 2. Compare all the matrices Bk. To do it, set G=B1 the first great-permuted of A given by algorithm 2. Setting k=2, denote the entries of BkGPer(A) by bi j. Setting i=1, j=1, compare gi j, bi j : Case 1. gij=bij, then: 8 a) If j<n add 1 to j, and repeat the comparing. b) If j=n and i<m add 1 to i, and repeat the comparing. c) If j=n and i=m go to step 3. Case 2. gij>bij , then go to step 3. Case 3. gij<bij then set G=Bk. Step 3. If k<ng, add 1 to k. Repeat steps 1 and 2. If k=ng, then G=Maxper(A). End of algorithm. Theorem 6. Let A be a binary matrix ABmn . By applying algorithm 3 on A provides the maximum-permuted of the matrix A, say Maxper(A). Proof The first step of algorithm 3 consists in applying algorithm 2 on A. From theorem 5, we will have the set GPer(A). The second an third steps of algorithm 3 consists in comparing the matrices of GPer(A) and select the greatest among them, that is, the maximum of GPer(A). The maximum matrix of this set, from theorem 4, is the matrix Maxper(A). Per(A) GPer(A) Maxper(A) Bmn 9