TEACHING STUDENTS TO USE THE GAUSS METHOD FOR INTEGER MATRICES WHEN IMPLEMENTED ON A COMPUTER

The paper is written on the basis of a part of “Analysis of algorithms” course for students of the Computer science department of the Division of mathematics and mechanics of Saint Petersburg State University. The example of the computer implementation of the Gauss method illustrates the difference between the algebraic complexity (the number of arithmetic operations) of processing integers and the computational complexity which depends on the length of the input data. A formula which speciﬁes the increase in the length of matrix coeﬃcients, along with the implementation the Gauss method, is proved. The problems arising in the processing of large integers associated with “chopping” numbers are shown. To overcome the indicated problems, the possibility of using multi-valued integers is proposed. The upper bounds of the number of steps for processing the multi-valued integers is shown to coincide with such bounds for a multi-tape Turing machine.


INTRODUCRION
This article is written as a part of "Analysis of algorithms" lecture course for students of the Computer science department of the Division of mathematics and mechanics of Saint Petersburg State University. The idea of including the material presented here in these courses emerged a long time ago, after N. K. Kosovsky [1] noticed the fact that using the Gauss method with integers (only multiplication and addition/subtraction operations are allowed), the length of matrix elements increases exponentially with the number of iterations and, therefore, with the length of the input data. However, firstly, all textbooks write that the Gauss method is a polynomial algorithm, and secondly, with an exponential increase in the length of the recorded result, the algorithm cannot be polynomial. Appeal to specialists in algebra did not give a positive resolution of this problem: the complexity of an algorithm, in algebra, is considered to be the number of arithmetic operations performed, not paying attention to the increase in the length of the recorded result. The people who are engaged in applications are well aware of the overflows that arise and the "struggle" with them by developing approximate methods.

THE PROBLEMS EMERGING WITH COMPUTER IMPLEMENTATION OF GAUSS METHOD FOR INTEGER-VALUED MATRICES
Every mathematician knows the following properties of Gauss method for solving a system of linear equations (as well as for calculation of an inverse matrix): the method is faithful, the method is unstable. With the implementation to matrices with elements of type real, various methods of "combating" the instability of the method are developed. Such an instability is closely connected with the fact that the division operation in the computer is performed approximately (moreover, the lower digits of the number are chopped, not rounded).
First-year students learn to implement Gauss method without division (except, may be, division without a remainder) to integer-valued matrices. In such a case there is no a round-off error. It would seem that all the elements of the type real of each row of the array can be multiplied by the common denominator of its elements to get an integer matrix of an equivalent system. After that, calculations are made without using division.
What happens in most modern computers if the result of an arithmetic operation with numbers of type integer does not fit in a cell? The senior digits of a result are "chopped". That is, in reality, arithmetic operations with numbers of type integer or longinteger are performed in a computer modulo 2 16 or 2 32 , respectively.
Consider a very simple and illustrative example of solving a system of linear equations with integer coefficients on a computing device that runs with decimal integers of length 2 (that is, with integers from the segment [−99, 99] modulo + 100). Upon getting a number which length exceeds two digits, the result is "chopped" at the expense of higher digits. 1 Solve a system of linear equations with an extended matrix 99 −73 26 84 15 99 .
Obviously, the solution of this system are the numbers 1 and 1. When using the Gauss method without division, the following actions should be performed: 15 · 99 − 84 · (−73) and 99 · 99 − 84 · 26.
As a result of applying the first iteration of the Gauss method, we obtain an extended matrix 99 −73 26 −83 17 .
Obviously, the numbers 1 and 1 are not a solution of this system.

ANALYSIS OF THE INCREASING COEFFICIENTS WITH THE DIRECT USE OF THE GAUSS METHOD FOR MATRICES WITH INTEGER COEFFICIENTS
Why, when using the Gauss method for matrices with integer coefficients, not apply the algorithm that students are taught in their first year? It's all about the high increase of the elements of the matrix in the process of applying the Gauss method. Let's see how fast they increase. 1 In a real computer, this happens modulo 2 16 for numbers of type integer or modulo 2 32 for numbers of type longinteger.

COMPUTER IN EDUCATION
It is well known (see, for example, [2]) that the Gauss method requires no more than polynomial (cubic) in the dimension of the matrix number of arithmetic operations. But when estimating the computational complexity of algorithms, the parameter is not the number of arguments of the problem, but the length of their recorded output. How many operations does a computer actually do?
Let an integer n × m matrix be given, and the length of each of its element does not exceed M (∥ a i j ∥ ≤ M , i = 1, . . . m, j = 1, . . . n). 2 After the first iteration, we have a matrix of the form Taking into account that upon multiplying integers, their lengths are added (perhaps minus one), and upon adding (subtracting) the length of the recorded output does not exceed the maximum of their lengths plus 1, we have After Here, of course, it is necessary to stipulate cases where b k−1 kk = 0, b k−1 ki = 0 for all i = k, . . . m, but in the "worst" case (in terms of the number of operations performed and the increase of the lengths of the coefficients) we have By induction, taking into account the stipulated cases, it is easy to prove that after the direct passage of the Gauss method for a matrix of rank r It is known [3] that no algorithm, for which the length of the intermediate data exponentially depends on the length of the input data, can run in a polynomial number of steps under the length of the input data. Does it turn out that the Gauss method is not polynomial?

ANALYSIS OF THE INCREASING COEFFICIENTS WITH THE DIRECT USE OF THE GAUSS METHOD FOR MATRICES WITH INTEGER COEFFICIENTS USING THE SYLVESTER THEOREM
The Sylvester theorem is formulated in [2]. According to this theorem, for all k ≥ 2 each element b k i j (i = k + 1, . . . , m, j = k + 1, . . . , n) can be divided without a remainder by b k−2 (k−1)(k−1) (here b 0 11 = a 11 ). Thus, when calculating elements b k i j with k ≥ 2, it is possible, while remaining in the framework of integers, to use the formula . (

3)
In this case, the length of b k i j will decrease by at least the length of b k−2 (k−1)(k−1) minus one. Let us see how the estimate (2) of the length of elements changes after the direct passage of Gauss method for a matrix of rank r .
For k ≥ 2, i = k + 1, . . . , m, j = k + 1, . . . , n we have By induction, taking into account the mentioned cases, it is easy to prove that after the direct passage of the Gauss method for a matrix of rank r The coefficient r + 1 at M is essentially less than 2 r . Moreover, the estimate (4) of the computational complexity of the Gauss method is polynomial under the length of the input matrix, while the estimate (3) is exponential. So, for example, if M = 16 and the rank of the matrix r = 10, then the estimate (2) without using the Sylvester theorem gives guaranteed lengths of the coefficients not exceeding 2 10 · 16 − 1 = 16383 ≈ 1024 · 16. Using this theorem, their guaranteed lengths do not exceed 11 · 16 + 10 2 = 276 = 17, 25 · 16.
However, it is still a much longer number than that for a value of type integer (binary length does not exceed 16) or longinteger (binary length does not exceed 32).

THE USE OF MULTI-DIGIT NUMBERS
For processing numbers which lengths do not allow to write them using standard data types, it is possible to use the so-called multi-digit numbers that can be stored as lists or dynamic arrays. Computations with such numbers are described in detail, for example, in [4]. In this case, the numbers written in one cell are called macro digits.
In lectures given to students, the author proves estimates for the computational complexity of arithmetic operations on multi-digit numbers x and y of length n and m, respectively. When adding (or subtracting) two multi-digit integers, the number of steps is O(max{n, m}), where a step is the addition of two macro-digits.
Predicates of equality and inequalities of multi-digit integers are checked in min{n, m} steps, where by a step we mean a comparison of two macro-digits.
When multiplying two integers under the assumption that m ≤ n (this condition is checked in 1 step, otherwise the numbers can be multiplied in another order), the number of steps is O(nm), where by a step we mean multiplication or addition of two macro-digits.
The calculation of the partial quotient of dividing two integer multi-digit numbers may be done in O(nm·(|n−m|) steps, where by a step we mean multiplication, or addition (subtraction), or comparison of two macro-digits. At the same time, students are taught that the estimates obtained coincide with the estimates of the number of steps of a multi-tape Turing machine that performs the corresponding operations.

CONCLUSION
The paper describes a theoretical justification for the need to use multi-digit numbers (that is, numbers of arbitrary length that cannot be written as a number of the type integer or longinteger) using the Gauss method for matrices with integer coefficients.