Application of the Transpositions matrix for obtaining n-dimensional rotation matrices

— This article proposes an algorithm for generation of N-dimensional rotation matrix R, N=m+n, m=2 p , n=2 q , p,q  [2, 4, 8] which rotates given N-dimensional vector X in the direction of coordinate axis x 1 Algorithm uses block diagonal matrix, composed by Transpositions matrices. As practical realization article gives Matlab code of functions, which creates Householder and Transpositions matrices and V matrix for given n-dimensional vector X.


I. INTRODUCTION
This paper proposes an algorithm for creating an ndimensional rotation matrix V, which rotates a given vector X in the direction of the coordinate axis x1 using block diagonal Transpositions (Trs) matrices. Matrices that rotate a given vector X in the direction of a given coordinate axis are used in calculations such as QR decomposition and in obtaining a rotation matrix according to the NRMG algorithm [2].

II. ROTATION OF N-DIMENSIONAL VECTOR X TO THE DIRECTION OF AXIS X1
The rotation of an N-dimensional vector X to the direction of one of the coordinate axes is a basic operation of the NRMG algorithm for obtaining an n-dimensional rotation matrix [2] and for QR decomposition [9] of a matrix A into a product A = QR of an orthogonal matrix Q and an upper triangular matrix R.

Definition 1:
We will call a V matrix or VX matrix an orthogonal matrix that rotates a given vector X in the direction of the x1 coordinate axis.
To obtain a V matrix for dense vectors, the method using Householder reflections is considered the most effective [7], [13], while for sparse vectors the method using Givens rotations may be more effective. However, for vectors of dimensions 2, 4 and 8, the method using a Transpositions matrix is the most effective [1]. The following is a description of these three methods for obtaining an orthogonal matrix V that rotates a given vector X to the direction of given coordinate axis (e.g. axis x1).

OBTAINING AN V MATRIX USING HOUSEHOLDER REFLECTION
According to the transformation of Householder [13] if X and Y are vectors with the same norm there exists an orthogonal symmetric matrix P, which rotates vector X to the direction of vector Y such that then matrix P will rotates vector X to the direction of the coordinate axis x1 Matrix P is matrix of reflection (not a rotation) because det( P) = -1, (which gives the name to method) The following example shows the Matlab code of the function Householder(X,k) that creates and returns orthogonal matrix V which rotates given vector X to the As it can be seen, function Householder(x,k) performs two normalization of vectors and calculates elements of matrix w.w T , which needs n 2 floating points multiplications.

OBTAINING AN V MATRIX USING GIVENS ROTATIONS
Rotation of given vector X in the direction of one of coordinate axes (e.g. axis x1) can be performed by subsequent multiplications by Givens matrices [2] as follows: where G(k, k+1, θk) is Givens matrix, which rotates vector in coordinate plane (k, k+1) by angle k and rX is the norm of vector X.
Thus searched matrix VX can be calculated as multiplication of Givens matrices where coefficients of rotation sin(θk) and cos( θk) are calculated using formulas (5). Calculation of angles of two-dimensional rotations θk really is not needed. If 0 x x 2 1 k 2 k = + + then corresponding Givens matrix is equal to Identity matrix G(k, k+1, θk) = Ino rotation.

OBTAINING AN V MATRIX USING TRANSPOSITIONS_MATRIX
Definition 2 Transpositions matrix (Tr matrix) [1] is square matrix with dimension n=2 m , m  N, which rows are permutations of elements xk, k  [0, n-1] of given ndimensional vector X and the values of elements Trp, q of matrix are obtained from the elements of given vector as follows: where denotes operation 'bitwise exclusive or' (XOR) [15],[16], [17].

Definition 3
Transpositions matrix with mutually orthogonal rows (Trs matrix) [1], [2] is square matrix with dimension n=2,4 or 8, which is obtained as Hadamard product [10], (denoted by ○) of Tr matrix and ndimensional Hadamard matrix whose rows (except the first one) are rearranged relative to the rows of Sylvester-Hadamard matrix [10]  By definition, Trs(X) is a matrix whose rows are mutually orthogonal and contain transpositions of a given vector X, while the first row contains the values of X without inversions. Therefore, if ||X||=1 then the multiplication of Trs(X/||X||) by X gives unit vector to the direction of the coordinate axis x1. The preparation of an orthogonal Trs matrix from a Tr matrix and a Sylvester-Hadamard matrix for a given vector X is given by the formula: where: • ○ denotes operation Hadamard product of matrices [13], It is important to note, that the ordering P of Hadamard matrix's rows (against the Sylvester-Hadamard matrix) does not depend on the vector X but only on its dimension.
An algorithm for creating Trs matrices for an arbitrary vector X for dimensions 2, 4 and 8 is proposed in [1].
The following example shows the code of a Matlab function that creates and returns Trs matrix which rotates given vector X of dimension n = 2, 4, or 8 in the direction of coordinate axis x1. As it can be seen, function TrsMatrix(X) obtains elements of matrix V, which needs n 2 bitwise multiplications of the indices of the vector's elements.

III. COMPARISON OF THE COMPUTATIONAL EFFICIENCY OF THE METHODS FOR CREATING AN V MATRIX
We will compare the computational efficiency of the methods for creating a matrix that rotates an n-dimensional vector in the direction of the x1 coordinate axis (V matrix) using Householder Reflection and using Transpositions_matrix.

THE COMPUTATIONAL EFFICIENCY OF THE METHOD THAT USES HOUSEHOLDER REFLECTION
Rotation of given vector X in the direction of one of coordinate axes (e.g. axis x1) can be performed by subsequent multiplications by Givens matrices [2] as follows: As can be seen from formula (2), to obtain a matrix P (which for us is the required matrix V) the vector Y must be a unit vector Y = [1,0,…, 0] T . The calculation of the matrix R includes the calculation of the norm of the vector

THE COMPUTATIONAL EFFICIENCY OF THE METHOD THAT USES TRANSPOSITIONS MATRIX
As can be seen from formula (6), obtaining a Transpositions matrix Trs (X) for a given vector X with dimension 2, 4 or 8 includes the following operations: • normalization of the vector X   CTrs< CH (12) and therefore the method for creating a 4-and 8dimensional orthogonal matrix R that rotates a given vector X in the direction of the x1 coordinate axis that uses Transpositions_matrix has higher performance than the method that uses Householder Reflection

THE COMPUTATIONAL EFFICIENCY OF THE METHOD THAT USES BLOCK DIAGONAL TRANSPOSITIONS MATRICES
In [1] the possibility of using Transpositions matrices to obtain an orthogonal matrix that rotates a given Ndimensional vector X in the direction of a given coordinate axis (i.e. axis x1) is considered. Block diagonal Transpositions matrices are used for this purpose. This paper examines the effectiveness of a method that uses a block-diagonal matrix Trb, consisting of two blocks of Trs matrices. When multiplying the block-diagonal matrix Trb by the specified vector X, it is obtained a vector Y1, which contains two non-zero elements. By multiplying the vector Y1 with a Givens matrix, is obtained the vector Y2, which is in the direction of a coordinate axis x1. Obtaining this result can be represented as follows: where: • X=[X1,X2]T is given vector of dimension N  16.

ALGORITHM FOR CALCULATING V MATRIX USING BLOCK DIAGONAL TRB MATRIX:
The algorithm for calculating V matrix using block diagonal Trb matrix, includes the following operations: Step 1: Split the given vector X into vectors X1 and X2 with dimensions 2, 4 or 8.
Step 2: From the given vector X = [X1, X2] T a vector X is obtained. The two parts of vector X -the vectors 1 X and 2 X , are calculates by vectors X1 and X2 as it is given in formulas: Step 3: The matrix V is obtained as follows: where: • Gn (1,m+1, ) is Givens matrix, which has coefficients X / 2 X S , • Trb is block diagonal matrix, which consists blocks 1) X Trs( and 2) X Trs( as it is given above. Multiplying the matrix V obtained by formula (15) by the vector X gives as a result vector Y=[||X||,0,…,0] T . The matrix V calculated by formula (15) has the form:

Fig. 1 Scheme for computing the V matrix
As can be seen from Fig. 1, obtaining the V matrix involves obtaining two Trs matrices of sizes m and n-m, respectively, and a total of 2n multiplications with the coefficients of C and S of the Givens matrix. In addition, to calculate the coefficients of C and S of the Givens matrix, it is necessary to calculate the norm ||X|| of the given vector X. Thus, for the volume CR of computational operations when using block diagonal Transpositions matrices using formula (11), we can record the following estimate CR = 2.(1 norm + n 2 /4 bitwise multiplications + n 2 /4 changes of sign) +1 norm and consequently CR = 3 norms+ n 2 /2 bitwise multiplications + n 2 /2 changes of sign (17) A comparison of estimates of the volume of calculations using Householder Reflection and using block diagonal Transpositions matrices shows that the volume of calculations is approximately the same CR  CH. In some cases, when using a more efficient vector norm calculation algorithm, using block diagonal Transpositions matrices may be a better choice. Theorem: V matrix, created using algorithm, described above, is matrix of rotation.

Proof:
The V matrix is represented as a product of a Givens matrix and a Trb matrix V=Gn(1,m+1,).Trb (15). Since the Givens matrix is a rotation matrix, for the V matrix to be a matrix of rotation it suffices to prove that the Trb matrix is a matrix of rotation. For this purpose, it is necessary to prove that Trb is an orthogonal matrix (i.e. Trb.Trb T =I, where I is identity matrix) and that det(Trb)=1.
First, for Trb.Trb T = we get:  As it can be seen, function OrthogonalTrs(X1,X2) calculates norms of input vectors X1 and X2, obtain V matrix as block diagonal matrix, the blocks of which are Transpositions (Trs) matrices. The rows number 1 and n1+1 of block diagonal matrix are replaced by the result of multiplication of vectors X1 and X2 by the coefficients C and S of Givens matrix, calculated as it is given in formula (16).

IV. NUMERICAL EXPERIMENTS
Executing the Matlab code below yields a V matrix using the OrthogonalTrs function. Obtained V matrix rotates given vector X= (1,2 is obtained the following orthogonal V matrix: Fig. 2 An orthogonal V matrix obtained by the OrthogonalTrs function. V matrix rotates the vector X= (1,2,3,4,5,6) T along the x1 coordinate axis.
As a result of multiplying the obtained matrix V by the specified vector X, a vector Y is obtained, which is in the direction of the coordinate axis x1.

V. CONCLUSION
The proposed algorithm for creating an N-dimensional orthogonal matrix V, which rotates a given vector X of dimension N = m + n, m=2 p , n=2 q , p,q  [2,4,8] in the direction of the x1 coordinate axis using Transpositions matrices (Trs) allows to obtain similar performance compared to the computational efficiency of the method that uses Householder Reflection under the above vector dimension limits. The matrix, obtained by the proposed algorithm, can be useful in performing some operations in linear algebra such as QR decomposition of matrices.