LinearAlgebra[Modular]
RowReduce
Gauss row reduction of input Matrix
Calling Sequence
Parameters
Description
Examples
RowReduce(p, A, rows, cols, rcol, det, pdet, rank, sig, incrow, redflag)
p
-
modulus
A
mod p Matrix
rows
number of rows, or range of rows to use
cols
number of columns, or range of columns to use
rcol
number of columns that represent variables
det
name to use for output determinant; 0 to disable
pdet
name to use for output pseudo-determinant; 0 to disable
rank
name to use for output rank; 0 to disable
sig
name to use for output signature; 0 to disable
incrow
name to use for output inconsistent row count; 0 to disable
redflag
boolean or integer; indicate whether to reduce row echelon form, or for how many rows
The RowReduce function performs in-place Gauss elimination on the input mod p Matrix A. If redflag=false, it produces a row echelon form. If redflag=true, it produces a reduced row echelon form.
Generally, it is required that p be a prime, as inverses are needed, but in some cases it is possible to obtain row echelon form when p is composite. For the cases where row echelon form cannot be obtained for p composite, the function returns an error indicating that the algorithm failed because p is composite.
RowReduce can act on a sub-Matrix or augmented Matrix based on the values of rows, cols, and rcol. The parameters rows and cols can be integer values, or nonempty ranges with integer endpoints, which represent the total rows and columns (including any augmented columns) on which the row reduction should be performed. If specified as integer values, the range is assumed to start at 1.
For a standard n⁢x⁢m Matrix, augmented with two columns, specify rows=n, cols=m+2, and rcol=m. For a partially reduced n⁢x⁢n Matrix with one augmented column, where the first r rows have leading identity, the reduction of the remaining rows can be accomplished by specifying rows=r..n, cols=r..n+1, and rcol=n−r+1.
If the determinant of the Matrix being reduced is required, specify det as a name. Otherwise, specify det as the value 0. On output, the name specified for det is assigned the value of the determinant. If the input Matrix has more variable columns than rows, the determinant is computed from the square Matrix formed by removing the extra columns from the end of the Matrix. If the input Matrix has fewer variable columns than rows, an error is produced.
Note: If the determinant is not required, set det to zero to avoid unnecessary calculations.
The pseudo-determinant of a Matrix is the determinant of the Matrix formed by removing any dependent rows and parametric columns (up to sign). In cases where the input ( n⁢x⁢m ) Matrix is of full rank with respect to the first n⁢x⁢n submatrix, the determinant and pseudo-determinant are the same. Use this value for reconstruction of solutions of integer linear systems that are rank deficient or underdetermined.
If the pseudo-determinant of the Matrix being reduced is required, specify pdet as a name. Otherwise, specify pdet as the value 0. On output, the name specified for pdet is assigned the value of the pseudo-determinant. If the input Matrix has fewer variable columns than rows, an error is produced.
Note: If the pseudo-determinant is not required, set pdet to zero to avoid unnecessary calculations.
The signature of a Matrix is an integer checksum that represents the correspondence of the solving columns and corresponding rows in the row echelon or reduced row echelon form of a Matrix. If for two Matrices, the pattern of pivots (location of the leading 1 entries in each row) is the same, their signature is also the same. However, two signatures being equal does not necessarily mean the two Matrices have the same pattern of pivots. Use this value is rapidly detect bad homomorphisms for reconstruction of the solution of an integer linear system.
If the signature of the Matrix being reduced is required, specify sig as a name. Otherwise, specify sig as the value 0. On output, the name specified for sig is assigned the value of the signature.
If the rank of the Matrix being reduced is required, specify rank as a name. Otherwise, specify rank as the value 0. On output, the name specified for rank is assigned the rank of the Matrix.
Specifying incrow as a name accomplishes two things. Firstly, it indicates that the algorithm continues computation even if inconsistent rows are found, placing those rows immediately after the consistent rows in the Matrix upon completion. Secondly, it indicates that the algorithm assigns the number of inconsistent rows found to incrow upon completion. If you specify incrow=0, the algorithm halts with an error when inconsistent rows are found.
The redflag parameter controls whether the output should be a reduced row echelon form (true) or a standard row echelon form with no back-substitution (false). In addition to these all-or-nothing settings, one can specify that the first i rows of a matrix should have back-substitution performed on them if redflag is set to −i.
This command is part of the LinearAlgebra[Modular] package, so it can be used in the form RowReduce(..) only after executing the command with(LinearAlgebra[Modular]). However, it can always be used in the form LinearAlgebra[Modular][RowReduce](..).
For this basic augmented system, find the rank and determinant.
with⁡LinearAlgebraModular:
p≔2741
A≔Mod⁡p,Matrix⁡4,5,i,j↦rand⁡,integer
A≔25431568127356581430154923761511183916419462114924183014807541049423
B≔Copy⁡p,A:
RowReduce⁡p,B,4,5,4,det,0,rank,0,0,true:
B,rank
1000191601006590010181000125,4
Check the determinant.
82
modp⁡LinearAlgebra:-Determinant⁡Matrix⁡A1..4,1..4,datatype=integer,p
Check the solution.
Multiply⁡p,A,1..4,1..4,B,1..4,5,Copy⁡p,A,1..4,5
58118392418423,58118392418423
Consider the system solution. Two steps looking at submatrices.
A≔Mod⁡p,Matrix⁡4,5,i,j↦rand⁡,float8
A≔1980.2533.1439.67.2051.2635.353.2657.1617.2198.2587.1857.827.1848.2338.1720.1181.493.1731.2264.
First step, working with the first two rows of B.
RowReduce⁡p,B,1..2,5,4,det1,0,0,0,0,true:
B
1.0.732.2653.1849.0.1.1097.941.1501.2587.1857.827.1848.2338.1720.1181.493.1731.2264.
Forward substitute.
forito2doforjto2doAddMultiple⁡p,p−B2+i,j,B,2+i,B,j,B,2+ienddoenddo:B
1.0.732.2653.1849.0.1.1097.941.1501.0.0.608.581.2260.0.0.508.1120.2290.
Work with the remaining two rows of B.
RowReduce⁡p,B,3..4,3..5,2,det2,0,0,0,0,true:
1.0.732.2653.1849.0.1.1097.941.1501.0.0.1.0.2413.0.0.0.1.1536.
Back-substitute last two rows with entries in first two by using shortcut specification for last three columns.
forito2doforjto2doAddMultiple⁡p,p−Bi,2+j,B,i,3..5,B,j+2,3,B,i,3enddoenddo:B
1.0.0.0.1596.0.1.0.0.1377.0.0.1.0.2413.0.0.0.1.1536.
modp⁡round⁡det1⁢det2,p
2603
modp⁡LinearAlgebra:-Determinant⁡Matrix⁡4,4,i,j↦round⁡Ai,j,datatype=integer,p
2051.2198.2338.2264.,2051.2198.2338.2264.
Back substitution only acting on the first row
p≔65521
M≔Create⁡p,4,5,random,integer
M≔376066440307911786645834553816159723313465421456079636696651356371352874493385050550237621146483
RowReduce⁡p,M,4,5,4,0,0,0,0,0,−1:
M
100017540014564514195369120016472852075000141141
See Also
LinearAlgebra/Details
LinearAlgebra[Modular][AddMultiple]
LinearAlgebra[Modular][Copy]
LinearAlgebra[Modular][Create]
LinearAlgebra[Modular][Determinant]
LinearAlgebra[Modular][Mod]
LinearAlgebra[Modular][Multiply]
Download Help Document