ТЕKA. COMMISSION OF MOTORIZATION AND ENERGETICS IN AGRICULTURE – 2016, Vol. 16, No.2, 33-36

Some algorithms of computer algebra

O. Porkuian, A. Timoshyn, L. Timoshyna

Volodymyr Dahl East-Ukrainian National University, e-mail: [email protected]

Received May 27.2016: accepted June 20.2015

Summary. The article describes one of the methods simplification of formal integration. Various operations for computing without using fractions with such objects assume symbolic computation. In some proposed by Bareiss. This problem has a clear algorithmic literature computer algebra is referred as a branch of character in nature and refers to the field of computer mathematics lying on the intersection of algebra and algebra. The implementation of this algorithm is proposed numerical methods. Indeed, there are many problems of in the known Maxima system of symbolic computations. algebra and mathematical analysis, which are connected In addition, this method makes it possible to get enough with symbolic computation [13-17]. The direct analysis of convenient formula for the calculation of the of these issues related to matrices, and, in particular, the unitriangular transformation of a quadratic form to a special algorithms for computing determinants, is canonical one. presented in [18]. Key words: computer algebra, Maxima system, , Bareiss algorithm, a quadratic form, OBJECTIVES unitriangular transformation. The main aims of this study are: INTRODUCTION - to study an algorithm for computing the determinant of a matrix without using fractions proposed by Bareiss, Modern computer algebra is inextricably linked with followed by the implementation of this algorithm in the use of computer processing technology, and especially Maxima system. with the software, which includes applied mathematical - to investigate, on the basis of this algorithm, the packages. Such packages as MatLab and Scilab are reduction of a quadratic form to a canonical one by means powerful professional mathematical packages. The of unitriangular transformation, or rather, to get essential difference between these packages is that Scilab convenient formula for calculating the unitriangular is open source software, while MatLab being a transformation matrix. commercial product [1, 2]. These packages have much in common, particularly, they inherently have a tendency for THE MAIN RESULTS OF THE RESEARCH performing numerical calculations. Although MatLab includes many tools of symbolic computations, yet the Let us consider the so-called dense matrices. A clear most effective up-today systems of analytical computation definition of dense matrices can be given to the aspect of are Maple, Maxima, Mathematica. For example, Maxima sparse matrices. The matrix of order n is called sparse, if system has a modern user interface, powerful the number of its non-zero elements does not exceed n1q visualization tools of all phases of operation, a wide range where q  1 . So for the of order 50 (with of functions and special packages. The packages for q  0.5) the number of its non-zero elements equals to matrix computations are especially useful [3-5]. However, built-in computer algebra system functions about 350, which accounts to a small percentage of the are not sufficient in some cases. There is a set of total number of matrix elements. As a rule, when dealing problems, such as calculating a determinant of the matrix with sparse matrices, computer algebra uses without using fractions, the solutions of which are representations, in which each row of the matrix is connected with certain algorithms, i.e. a set of commands defined by a list of non-zero elements of the row, each and functions. The extensive use of matrix algebra in being stored in memory, with indicating the number of its solving economic and technical problems makes this task column. Now it is possible to say that the dense matrices even more urgent [6, 7]. are those that do not belong to sparse ones. In the systems of computer algebra dense matrices THE ANALYSIS OF RECENT RESEARCHES AND are defined by rows. In particular, in Maxima system the PUBLICATIONS matrix function (the call syntax: matrix(row1, ..., rown)) is used for presetting matrices. The presence of symbolic Not so much literature is devoted to algorithms for elements in these matrices can lead to serious problems of computer algebra associated with the matrix analysis. "swelling" the data, both the intermediate and the final Most of the sources [8-12] on computer algebra contain ones. materials relating to the issues of numbers representation, Another serious problem is connected with the polynomials, rational and algebraic functions, polynomial that occurs, for example, when calculating 34 O. Porkuian, A. Timoshyn, L. Timoshyna determinants. The idea is that the calculation of the being integers. According to (1), det(A)  (n 1,n,n). determinant of the matrix as the sum of the products of On the other hand, according to (2): the matrix elements, taken one by one from each row and each column (the method of calculating the determinant is det(A)  (n 1,n,n)  sometimes called Cramer's rule ), numerically very 1 inefficient: the number of operations in this case is   O(n(n!)), while the calculation of determinants by (n  3,n  2,n  2)

Gaussian elimination algorithm the number of operations (n  2,n 1,n 1) (n  2,n 1,n) is O(n3). It is obvious, that  . (n  2,n,n 1) (n  2,n,n) algorithm requires division which can lead to fractions. In addition, for matrices with elements of a ring with zero divisors the successive elimination method may be simply We are dealing with a recursive algorithm, which in impossible. This may occur when the elements of the Maxima system can be implemented as follows: matrix has no unit divisors. For example, in the residue- class ring by modulo 6, the determinant of the matrix determ[n,i,j]:= 4 3 if n=1 then A[n,n]*A[i, j]A[i,n]*A[n,j] else   equals to 1, however, elements 3 and 4 in ring if n=2 then (1/A[n1,n1])*(determ[n1,n,n]* 3 4   determ[n1,i,j]determ[n1,n,j]*determ[n1,i,n]) else Z6 have no unit divisors, making it impossible to divide, (1/determ[n2,n1,n1])*(determ[n1,n,n]* i.e. to apply the algorithm of elimination. determ[n1,i,j]determ[n1,n,j]*determ[n1,i,n])$. As noted in [18], there is a whole family of elimination methods without using fractions, i.e., those This algorithm is a relative of the algorithms of where all appropriate division are performed accurately. elimination elements. Indeed, consider an arbitrary Let us consider in detail a step-by-step algorithm for symbolic square matrix: computing determinants without using fractions, proposed by Bareiss, which is based on generalization of A  ([a11,a12, ], [a21,a22, ], [a31,a32, ], ). Sylvester’s identity [19].

We introduce some notation. Let a square matrix be Let us perform the following elementary given of order n, where the matrix elements A  (aij ) transformations of the rows of this matrix (as a rule, such being integers. Consider the determinant of the following a transformation is performed at a reduction of a matrix to form: echelon form for calculating the rank of a matrix or solving the system of linear equations). We multiply the first row of the matrix to the element a21, and the second a11 a12 ... a1k a1 j a a ... a a row to the element (a11), and then add the first row to 21 22 2k 2 j the second one. The second row will look: (k,i, j)  ...... (1) ak1 ak2 ... akk akj [0, a11a22  a12a21, a11a23  a13a21, ...].

ai1 ai2 ... aik aij The resulting second row in the notation of (1) can be

rewritten as follows: Note that the determinant (k,i, j) is obtained by bordering the i-th row and the j-th column of the upper- [0, (1,2,2), (1,2,3), ...]. left corner (main) k of order k of matrix A, where n  i, j  k . Similarly, we set to zero the element a31 and repeat The basic ratio of the step-by-step algorithm for the procedure for the newly obtained second and third computing determinants without using fractions has the rows. We have following form: [0, 0, a11 (2,3,3), ...]. 1 (k,i, j)   (k  2,k 1,k 1) It is obvious, that all of the remaining elements of the (2) third row are divided by a11. A similar situation occurs (k 1,k,k) (k 1,k, j)  . for the following rows, which provides integer results. (k 1,i,k) (k 1,i, j) Let us consider one more algebraic problem, which is reduced to a recursive algorithm, while again there occur It is obvious, that the value of the determinant the determinants of type (k,i, j). (k,i, j) is an integer (from (1) it can be computed by n Let f (X )  i, j1aij xi x j be a quadratic form, where Cramer's rule). Hence, the right side of (2) is an integer, being a matrix of a quadratic form. Lagrange’s i.e. the division is performed without a remainder. A  (aij ) This makes it possible to calculate the determinant of method, the eigenvectors method and Jacobi’s method can the matrix A in step-by-step way, the intermediate results be referred as the most well-known methods of reducing a quadratic form to a canonical one. The reduction problem SOME ALGORITHMS OF COMPUTER ALGEBRA 35 involves finding the canonical coefficients and the  a a  1 12 13  corresponding transformation, i.e. a matrix B that   T  1 1  A  B AB being a diagonal matrix. For Lagrange’s  (1,2,3)  R  0 1 . method and the method of eigenvectors the reduction 3  (1,2,2)  problem is fairly well presented in any textbook of   0 0 1  algebra. However, when using the Jacobi’s method   (which is also called the method of unitriangular   transformation), as a rule, researchers confine themselves to finding the canonical coefficients. Constructing an Thus, we get enough convenient formula for appropriate transformation is based on the following calculating the matrix (in fact, it is a matrix R1 ) of theorems [20]. unitriangular transformation of a quadratic forms to a Theorem 1. Let a matrix of a quadratic form be non- canonical one for dimension 3. degenerate. In order to transform it to a canonical form Further calculations show that when increasing the using a right unitriangular matrix, it is necessary and dimension the matrix R has the following form: sufficient that the principal minors of the matrix of the quadratic form be non-zero.  a a a1 j  Theorem 2. For the presentation of a non-degenerate  1 12 13      matrix A  (a ) of order n as a product of the left  1 1 1  ij  (1,2,3) (1,2, j)  0 1   unitriangular, diagonal and right unitriangular matrix, i.e. R    .  (1,2,2) (1,2,2)  A  LDR, it is necessary and sufficient that the principal (2,3, j)  0 0 1   minors of the matrix be non-zero.   Since the matrix of a quadratic form is symmetric, (2,3,3)       A  RT DR . Introduce the following notation:  

CONCLUSIONS  Ak 1 ak   Rk 1 X k  Ak   , Rk   ,  bk akk   0 1  The following important conclusions can be drawn from this study: 1. As a result of analyzing the known packages of D 0  k 1  computer algebra the decision of using Maxima system in Dk   ,  0 dk  further investigations has been made. This system has all functions and libraries necessary for performing matrix computations. where: n  k  2, b  aT . k k 2. Learning different literature on computer algebra Provided that A  RT DR , the equality enables to state that insufficient attention is paid to special A  R T D R is true. This leads to the following algorithms of matrix computations. The problems of k k k k implementing these algorithms in the systems of relationships: computer algebra are not being practically discussed. 3. Based on the step-by-step algorithm for  det Ak k computing determinants without using fractions, proposed dk    det Ak1 k1 , by Bareiss, the recursive procedure for computing minors  1 T 1 of the type (k,i, j) in Maxima system has been X k  Dk1(Rk1) ak constructed. where: D  d  a , R 1, X is an unknown 4. More detailed study of Jacobi’s method (the 1 1 11 1 k method of transformation of a quadratic form to a column. canonical one) also leads to minors of the type (k,i, j). In case of n  3, we have: In particular, the convenient formula for computing matrices of unitriangular transformation, which uses  a12  1 a12 1  minors of the type (k,i, j) has been obtained in this X 2  d1 a12  . R2   1  , 1   study. 0 1  REFERENCES  a13    1. Some systems symbolic computation open-source. 1 T 1 T  1  X 3  D2 (R2 ) [a13a23]  , Available online at: < http://cph.phys.spbu.ru/>  a11a23  a12a13    2. Klimenko V. P., Lyakhov A. L., Gvozdik D. N. d d  1 2  2011. Modern features of computer algebra systems. Journal Mathematical Machines and Systems. Vol. 1. Nr 2, 3-18. (in Russia). 36 O. Porkuian, A. Timoshyn, L. Timoshyna

3. Chichkarev E. A. 2009. Computer mathematics with CASC 2014 Warsaw, Poland, September 8-12, 2014 Maxima: Guide pupils and students.  M.: ALT Proceedings. 242-255. (in English). Linux, 2009. (in Russia). 14. Fermat is a computer algebra system for polynomial 4. Stahin N. A. 2008. Basics of system analysis and matrix computation. Available online at: (symbolic) Maxima computing (software for solving . analytical problems computation). Tutorial.  M.: Mir, 15. Kh. D. Ikramov, M. Matin far, A. A. Chesnokov.  86. (in Russia). 2004. Computer algebra procedures for the Drazin 5. Maxima system of computer algebra. Available online inversion of a singular matrix. Comput. Math. Math.. at: < http://maxima.sourceforge.net>. Phys, 44: 7 (2004), 1155-1163. (in English). 6. Sergiy Gutyrya, Victor Yaglinsky. 2006. System 16. Ikramov Kh. D. , Matin M. far. 2003. On computer criteria an alysis and function optimization of algebra procedures for matrix pseudoinversion, Zh. industrial robots // TEKA. Commission of Vychisl. Mat. Mat. Fiz., 43:2 (2003), 163–168. (in Motorization and Power Industry in Agriculture, Russia). Poland. – Lublin: Polish Academy of Sciences Branch 17. Akritas A. 1994. Elements of Computer Algebra with in Lublin, 2006. – V. 6A, 70-81. (in English). Applications / Trans. from English. - M.: Mir, - 544. 7. Valentin Shishov, Pavel Nosko, Pavel Fil, Alexandr (in Russia). Muhovatiy, Julia Sklyar. 2008. Parametrical 18. Davenport J., Siret Y., Tournier E.. 1991. Calcul optimization of worm gears based on losses in gearing formel: Symbolic and algebraic computation / Trans. // TEKA. Commission of Motorization and Power from English.  M.: Mir,  350. (in Russia). Industry in Agriculture, Poland. – Lublin: Polish 19. Prasolov V. V. 2008. Problems and theorems of linear Academy of Sciences Branch in Lublin, 2008. – V. 8, algebra. – M.: Nauka,  269. (in Russia). 213-221. (in English). 20. Faddeev D. K. 1984. Lectures on algebra. Textbook 8. Kuznetsov M. I., Burlankov D. E., Dolgov G. A., for high schools.  M .: Nauka,  416. (in Russia). Chirkov A., Yakovlev V. A. 2002. Computer Algebra.  N. Novgorod. Publishing House of the НЕКОТОРЫЕ АЛГОРИТМЫ Nizhny Novgorod State University Press, 223. (in КОМПЬЮТЕРНОЙ АЛГЕБРЫ Russia). 9. Pankratiev E. V. 2010. Elements of computer О.В. Поркуян, А.С.Тимошин, Л.В. Тимошина algebra.  M .: Binom,  248. (in Russia). 10. Buchberger B., Collins G., Loos R.. 1983. Computer Аннотация. В статье рассмотрен один из методов вычисления определителей без использования дробей, Algebra. Symbolic and Algebraic Computation.  By предложенный Барейсом. Эта задача имеет четко Springer Verlag/Wien,  288. (in English). выраженный алгоритмический характер и относится к 11. Cooke D. J., Bez H. E. 1984. Computer Mathematics. разделу компьютерной алгебры. Реализация  Cambridge University Press,  408. (in English). соответствующего алгоритма предлагается в 12. Roman Dmytryshyn. 2011. Accuracy of the Hilbert th известной системе символьных вычислений Maxima. matrix determinant calculation. 12 International Кроме того, этот метод дает возможность получить Workshop “Computational Problems of Electrical достаточно удобную формулу для расчета матрицы Engineering”, 19-20. (in English). унитреугольного преобразования квадратичной 13. Takuya Kitamoto. 2014. On the Computation of the формы к каноническому виду. Determinant of a Generalized Vandermonde Matrix // Ключевые слова: компьютерная алгебра, система Vladimir P. Gerdt, Wolfram Koepf, Werner M. Seiler, Maxima, определитель, алгоритм Барейса, Evgenii V. Vorozhtsov. Computer Algebra in квадратичная форма, унитреугольное преобразование. Scientific Computing: 16th International Workshop,