GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
1[1X4 [33X[0;0YGaussian Algorithms[133X[101X234[1X4.1 [33X[0;0YA list of the available algorithms[133X[101X56[33X[0;0YAs decribed earlier, the main functions of [5XGauss[105X are [2XEchelonMat[102X ([14X4.2-1[114X) and7[2XEchelonMatTransformation[102X ([14X4.2-2[114X), [2XReduceMat[102X ([14X4.2-3[114X) and8[2XReduceMatTransformation[102X ([14X4.2-4[114X), [2XKernelMat[102X ([14X4.2-5[114X) and, additionally [2XRank[102X9([14X4.2-6[114X). These are all documented in the next section, but of course rely on10specific algorithms depending on the base ring of the matrix. These are not11fully documented but it should be very easy to find out how they work based12on the documentation of the main functions.[133X1314EchelonMat15Field: [10XEchelonMatDestructive[110X16Ring: [10XHermiteMatDestructive[110X17EchelonMatTransformation18Field: [10XEchelonMatTransformationDestructive[110X19Ring: [10XHermiteMatTransformationDestructive[110X20ReduceMat21Field: [10XReduceMatWithEchelonMat[110X22Ring: [10XReduceMatWithHermiteMat[110X23ReduceMatTransformation24Field: [10XReduceMatWithEchelonMatTransformation[110X25Ring: [10XReduceMatWithHermiteMatTransformation[110X26KernelMat27Field: [10XKernelEchelonMatDestructive[110X28Ring: [10XKernelHermiteMatDestructive[110X29Rank30Field (dense): [10XRank[110X ([5XGAP[105X method)31Field (sparse): [10XRankDestructive[110X32GF(2) (sparse): [10XRankOfIndicesListList[110X33Ring: n.a.343536[1X4.2 [33X[0;0YMethods and Functions for [5XGauss[105X[101X[1Xian algorithms[133X[101X3738[1X4.2-1 EchelonMat[101X3940[29X[2XEchelonMat[102X( [3Xmat[103X ) [32X method41[6XReturns:[106X [33X[0;10Ya record that contains information about an echelonized form of42the matrix [3Xmat[103X.[133X4344[33X[0;10YThe components of this record are[133X4546[33X[0;10Y`vectors'[133X4748[33X[0;10Ythe reduced row echelon / hermite form of the matrix [3Xmat[103X without49zero rows.[133X5051[33X[0;10Y`heads'[133X5253[33X[0;10Ylist that contains at position <i>, if nonzero, the number of the54row for that the pivot element is in column <i>.[133X5556[33X[0;0Ycomputes the reduced row echelon form RREF of a dense or sparse matrix [3Xmat[103X57over a field, or the hermite form of a sparse matrix [3Xmat[103X over [22Xℤ / < p^n >[122X.[133X5859[4X[32X Example [32X[104X60[4X[25Xgap>[125X [27XM := [[0,0,0,1,0],[0,1,1,1,1],[1,1,1,1,0]] * One( GF(2) );;[127X[104X61[4X[25Xgap>[125X [27XDisplay(M);[127X[104X62[4X[28X . . . 1 .[128X[104X63[4X[28X . 1 1 1 1[128X[104X64[4X[28X 1 1 1 1 .[128X[104X65[4X[25Xgap>[125X [27XEchelonMat(M);[127X[104X66[4X[28Xrec( heads := [ 1, 2, 0, 3, 0 ],[128X[104X67[4X[28X vectors := [ <an immutable GF2 vector of length 5>,[128X[104X68[4X[28X <an immutable GF2 vector of length 5>,[128X[104X69[4X[28X <an immutable GF2 vector of length 5> ] )[128X[104X70[4X[25Xgap>[125X [27XDisplay( last.vectors );[127X[104X71[4X[28X 1 . . . 1[128X[104X72[4X[28X . 1 1 . 1[128X[104X73[4X[28X . . . 1 .[128X[104X74[4X[25Xgap>[125X [27XSM := SparseMatrix( M );[127X[104X75[4X[28X<a 3 x 5 sparse matrix over GF(2)>[128X[104X76[4X[25Xgap>[125X [27XEchelonMat( SM );[127X[104X77[4X[28Xrec( heads := [ 1, 2, 0, 3, 0 ], vectors := <a 3 x 5 sparse matrix over GF([128X[104X78[4X[28X 2)> )[128X[104X79[4X[25Xgap>[125X [27XDisplay(last.vectors);[127X[104X80[4X[28X 1 . . . 1[128X[104X81[4X[28X . 1 1 . 1[128X[104X82[4X[28X . . . 1 .[128X[104X83[4X[25Xgap>[125X [27XSM := SparseMatrix( [[7,4,5],[0,0,6],[0,4,4]] * One( Integers mod 8 ) );[127X[104X84[4X[28X<a 3 x 3 sparse matrix over (Integers mod 8)>[128X[104X85[4X[25Xgap>[125X [27XDisplay( SM );[127X[104X86[4X[28X 7 4 5[128X[104X87[4X[28X . . 6[128X[104X88[4X[28X . 4 4[128X[104X89[4X[25Xgap>[125X [27XEchelonMat( SM );[127X[104X90[4X[28Xrec( heads := [ 1, 2, 3 ],[128X[104X91[4X[28X vectors := <a 3 x 3 sparse matrix over (Integers mod 8)> )[128X[104X92[4X[25Xgap>[125X [27XDisplay( last.vectors );[127X[104X93[4X[28X 1 . 1[128X[104X94[4X[28X . 4 .[128X[104X95[4X[28X . . 2 [128X[104X96[4X[32X[104X9798[1X4.2-2 EchelonMatTransformation[101X99100[29X[2XEchelonMatTransformation[102X( [3Xmat[103X ) [32X method101[6XReturns:[106X [33X[0;10Ya record that contains information about an echelonized form of102the matrix [3Xmat[103X.[133X103104[33X[0;10YThe components of this record are[133X105106[33X[0;10Y`vectors'[133X107108[33X[0;10Ythe reduced row echelon / hermite form of the matrix [3Xmat[103X without109zero rows.[133X110111[33X[0;10Y`heads'[133X112113[33X[0;10Ylist that contains at position <i>, if nonzero, the number of the114row for that the pivot element is in column <i>.[133X115116[33X[0;10Y`coeffs'[133X117118[33X[0;10Ythe transformation matrix needed to obtain the RREF from [3Xmat[103X.[133X119120[33X[0;10Y`relations'[133X121122[33X[0;10Ythe kernel of the matrix [3Xmat[103X if RingOfDefinition([3Xmat[103X) is a field.123Otherwise these are only the obvious row relations of [3Xmat[103X, there124might be more kernel vectors - --> [2XKernelMat[102X ([14X4.2-5[114X).[133X125126[33X[0;0Ycomputes the reduced row echelon form RREF of a dense or sparse matrix [3Xmat[103X127over a field, or the hermite form of a sparse matrix [3Xmat[103X over [22Xℤ / < p^n >[122X.128In either case, the transformation matrix [22XT[122X is calculated as the row union129of `coeffs' and `relations'.[133X130131[4X[32X Example [32X[104X132[4X[25Xgap>[125X [27XM := [[1,0,1],[1,1,0],[1,0,1],[1,1,0],[1,1,1]] * One( GF(2) );;[127X[104X133[4X[25Xgap>[125X [27XEchelonMatTransformation( M );[127X[104X134[4X[28Xrec( [128X[104X135[4X[28X coeffs := [ <an immutable GF2 vector of length 5>,[128X[104X136[4X[28X <an immutable GF2 vector of length 5>, [128X[104X137[4X[28X <an immutable GF2 vector of length 5> ], heads := [ 1, 2, 3 ], [128X[104X138[4X[28X relations := [128X[104X139[4X[28X [ <an immutable GF2 vector of length 5>,[128X[104X140[4X[28X <an immutable GF2 vector of length 5> ], [128X[104X141[4X[28X vectors := [ <an immutable GF2 vector of length 3>,[128X[104X142[4X[28X <an immutable GF2 vector of length 3>,[128X[104X143[4X[28X <an immutable GF2 vector of length 3> ] )[128X[104X144[4X[25Xgap>[125X [27XDisplay(last.vectors);[127X[104X145[4X[28X 1 . .[128X[104X146[4X[28X . 1 .[128X[104X147[4X[28X . . 1[128X[104X148[4X[25Xgap>[125X [27XDisplay(last.coeffs);[127X[104X149[4X[28X 1 1 . . 1[128X[104X150[4X[28X 1 . . . 1[128X[104X151[4X[28X . 1 . . 1[128X[104X152[4X[25Xgap>[125X [27XDisplay(last.relations);[127X[104X153[4X[28X 1 . 1 . .[128X[104X154[4X[28X . 1 . 1 .[128X[104X155[4X[25Xgap>[125X [27XDisplay( Concatenation( last.coeffs, last.relations ) * M );[127X[104X156[4X[28X 1 . .[128X[104X157[4X[28X . 1 .[128X[104X158[4X[28X . . 1[128X[104X159[4X[28X . . .[128X[104X160[4X[28X . . .[128X[104X161[4X[25Xgap>[125X [27XSM := SparseMatrix( M );[127X[104X162[4X[28X<a 5 x 3 sparse matrix over GF(2)>[128X[104X163[4X[25Xgap>[125X [27XEchelonMatTransformation( SM );[127X[104X164[4X[28Xrec( coeffs := <a 3 x 5 sparse matrix over GF(2)>, [128X[104X165[4X[28X heads := [ 1, 2, 3 ], [128X[104X166[4X[28X relations := <a 2 x 5 sparse matrix over GF(2)>, [128X[104X167[4X[28X vectors := <a 3 x 3 sparse matrix over GF(2)> )[128X[104X168[4X[25Xgap>[125X [27XDisplay(last.vectors);[127X[104X169[4X[28X 1 . .[128X[104X170[4X[28X . 1 .[128X[104X171[4X[28X . . 1[128X[104X172[4X[25Xgap>[125X [27XDisplay(last.coeffs);[127X[104X173[4X[28X 1 1 . . 1[128X[104X174[4X[28X 1 . . . 1[128X[104X175[4X[28X . 1 . . 1[128X[104X176[4X[25Xgap>[125X [27XDisplay(last.relations);[127X[104X177[4X[28X 1 . 1 . .[128X[104X178[4X[28X . 1 . 1 .[128X[104X179[4X[25Xgap>[125X [27XDisplay( UnionOfRows( last.coeffs, last.relations ) * SM );[127X[104X180[4X[28X 1 . .[128X[104X181[4X[28X . 1 .[128X[104X182[4X[28X . . 1[128X[104X183[4X[28X . . .[128X[104X184[4X[28X . . .[128X[104X185[4X[32X[104X186187[1X4.2-3 ReduceMat[101X188189[29X[2XReduceMat[102X( [3XA[103X, [3XB[103X ) [32X method190[6XReturns:[106X [33X[0;10Ya record with a single component `reduced_matrix' := M. M is191created by reducing [3XA[103X with [3XB[103X, where [3XB[103X must be in Echelon/Hermite192form. M will have the same dimensions as [3XA[103X.[133X193194[4X[32X Example [32X[104X195[4X[25Xgap>[125X [27XM := [[0,0,0,1,0],[0,1,1,1,1],[1,1,1,1,0]] * One( GF(2) );;[127X[104X196[4X[25Xgap>[125X [27XDisplay(M);[127X[104X197[4X[28X . . . 1 .[128X[104X198[4X[28X . 1 1 1 1[128X[104X199[4X[28X 1 1 1 1 .[128X[104X200[4X[25Xgap>[125X [27XN := [[1,1,0,0,0],[0,0,1,0,1]] * One( GF(2) );;[127X[104X201[4X[25Xgap>[125X [27XDisplay(N);[127X[104X202[4X[28X 1 1 . . .[128X[104X203[4X[28X . . 1 . 1[128X[104X204[4X[25Xgap>[125X [27XReduceMat(M,N);[127X[104X205[4X[28Xrec([128X[104X206[4X[28X reduced_matrix := [ <a GF2 vector of length 5>, <a GF2 vector of length 5>,[128X[104X207[4X[28X <a GF2 vector of length 5> ] )[128X[104X208[4X[25Xgap>[125X [27XDisplay(last.reduced_matrix);[127X[104X209[4X[28X . . . 1 .[128X[104X210[4X[28X . 1 . 1 .[128X[104X211[4X[28X . . . 1 1[128X[104X212[4X[25Xgap>[125X [27XSM := SparseMatrix(M); SN := SparseMatrix(N);[127X[104X213[4X[28X<a 3 x 5 sparse matrix over GF(2)>[128X[104X214[4X[28X<a 2 x 5 sparse matrix over GF(2)>[128X[104X215[4X[25Xgap>[125X [27XReduceMat(SM,SN);[127X[104X216[4X[28Xrec( reduced_matrix := <a 3 x 5 sparse matrix over GF(2)> )[128X[104X217[4X[25Xgap>[125X [27XDisplay(last.reduced_matrix);[127X[104X218[4X[28X . . . 1 .[128X[104X219[4X[28X . 1 . 1 .[128X[104X220[4X[28X . . . 1 1[128X[104X221[4X[32X[104X222223[1X4.2-4 ReduceMatTransformation[101X224225[29X[2XReduceMatTransformation[102X( [3XA[103X, [3XB[103X ) [32X method226[6XReturns:[106X [33X[0;10Ya record with a component `reduced_matrix' := M. M is created by227reducing [3XA[103X with [3XB[103X, where [3XB[103X must be in Echelon/Hermite form. M will228have the same dimensions as [3XA[103X. In addition to the (identical)229output as ReduceMat this record also includes the component230`transformation', which stores the row operations that were needed231to reduce [3XA[103X with [3XB[103X. This differs from "normal" transformation232matrices because only rows of [3XB[103X had to be moved. Therefore, the233transformation matrix solves M = A + T * B.[133X234235[4X[32X Example [32X[104X236[4X[25Xgap>[125X [27XM := [[0,0,0,1,0],[0,1,1,1,1],[1,1,1,1,0]] * One( GF(2) );;[127X[104X237[4X[25Xgap>[125X [27XDisplay(M);[127X[104X238[4X[28X . . . 1 .[128X[104X239[4X[28X . 1 1 1 1[128X[104X240[4X[28X 1 1 1 1 .[128X[104X241[4X[25Xgap>[125X [27XN := [[1,1,0,0,0],[0,0,1,0,1]] * One( GF(2) );;[127X[104X242[4X[25Xgap>[125X [27XDisplay(N);[127X[104X243[4X[28X 1 1 . . .[128X[104X244[4X[28X . . 1 . 1[128X[104X245[4X[25Xgap>[125X [27XReduceMatTransformation(M,N);[127X[104X246[4X[28Xrec( [128X[104X247[4X[28X reduced_matrix := [128X[104X248[4X[28X [ <a GF2 vector of length 5>, <a GF2 vector of length 5>, [128X[104X249[4X[28X <a GF2 vector of length 5> ], [128X[104X250[4X[28X transformation := [ <a GF2 vector of length 2>,[128X[104X251[4X[28X <a GF2 vector of length 2>, <a GF2 vector of length 2> ] )[128X[104X252[4X[25Xgap>[125X [27XDisplay(last.reduced_matrix);[127X[104X253[4X[28X . . . 1 .[128X[104X254[4X[28X . 1 . 1 .[128X[104X255[4X[28X . . . 1 1[128X[104X256[4X[25Xgap>[125X [27XDisplay(last.transformation);[127X[104X257[4X[28X . .[128X[104X258[4X[28X . 1[128X[104X259[4X[28X 1 1[128X[104X260[4X[25Xgap>[125X [27XDisplay( M + last.transformation * N );[127X[104X261[4X[28X . . . 1 .[128X[104X262[4X[28X . 1 . 1 .[128X[104X263[4X[28X . . . 1 1 [128X[104X264[4X[25Xgap>[125X [27XSM := SparseMatrix(M); SN := SparseMatrix(N);[127X[104X265[4X[28X<a 3 x 5 sparse matrix over GF(2)>[128X[104X266[4X[28X<a 2 x 5 sparse matrix over GF(2)>[128X[104X267[4X[25Xgap>[125X [27XReduceMatTransformation(SM,SN);[127X[104X268[4X[28Xrec( reduced_matrix := <a 3 x 5 sparse matrix over GF(2)>,[128X[104X269[4X[28X transformation := <a 3 x 2 sparse matrix over GF(2)> )[128X[104X270[4X[25Xgap>[125X [27XDisplay(last.reduced_matrix);[127X[104X271[4X[28X . . . 1 .[128X[104X272[4X[28X . 1 . 1 .[128X[104X273[4X[28X . . . 1 1[128X[104X274[4X[25Xgap>[125X [27XDisplay(last.transformation);[127X[104X275[4X[28X . .[128X[104X276[4X[28X . 1[128X[104X277[4X[28X 1 1[128X[104X278[4X[25Xgap>[125X [27XDisplay( SM + last.transformation * SN );[127X[104X279[4X[28X . . . 1 .[128X[104X280[4X[28X . 1 . 1 .[128X[104X281[4X[28X . . . 1 1[128X[104X282[4X[32X[104X283284[1X4.2-5 KernelMat[101X285286[29X[2XKernelMat[102X( [3XM[103X ) [32X function287[6XReturns:[106X [33X[0;10Ya record with a single component `relations'.[133X288289[33X[0;0YIf [3XM[103X is a matrix over a field this is the same output as290[2XEchelonMatTransformation[102X ([14X4.2-2[114X) provides in the `relations' component, but291with less memory and CPU usage. If the base ring of [3XM[103X is a non-field, the292Kernel might have additional generators, which are added to the output.[133X293294[4X[32X Example [32X[104X295[4X[25Xgap>[125X [27XM := [[2,1],[0,2]];[127X[104X296[4X[28X[ [ 2, 1 ], [ 0, 2 ] ][128X[104X297[4X[25Xgap>[125X [27XSM := SparseMatrix( M * One( GF(3) ) );[127X[104X298[4X[28X<a 2 x 2 sparse matrix over GF(3)>[128X[104X299[4X[25Xgap>[125X [27XKernelMat(SM);[127X[104X300[4X[28Xrec( relations := <a 0 x 2 sparse matrix over GF(3)> )[128X[104X301[4X[25Xgap>[125X [27XSN := SparseMatrix( M * One( Integers mod 4 ) );[127X[104X302[4X[28X<a 2 x 2 sparse matrix over (Integers mod 4)>[128X[104X303[4X[25Xgap>[125X [27XKernelMat(SN);[127X[104X304[4X[28Xrec( relations := <a 1 x 2 sparse matrix over (Integers mod 4)> )[128X[104X305[4X[25Xgap>[125X [27XDisplay(last.relations);[127X[104X306[4X[28X 2 1[128X[104X307[4X[32X[104X308309[1X4.2-6 Rank[101X310311[29X[2XRank[102X( [3Xsm[103X[, [3Xboundary[103X] ) [32X method312[6XReturns:[106X [33X[0;10Ythe rank of the sparse matrix [3Xsm[103X. Only works for fields.[133X313314[33X[0;0YComputes the rank of a sparse matrix. If the optional argument [3Xboundary[103X is315provided, some algorithms take into account the fact that Rank([3Xsm[103X) <=316[3Xboundary[103X, thus possibly terminating earlier.[133X317318[4X[32X Example [32X[104X319[4X[25Xgap>[125X [27XM := SparseDiagMat( ListWithIdenticalEntries( 10,[127X[104X320[4X[25X>[125X [27X SparseMatrix( [[1,1],[1,1]] * One( GF(5) ) ) ) );[127X[104X321[4X[28X<a 20 x 20 sparse matrix over GF(5)>[128X[104X322[4X[25Xgap>[125X [27XDisplay(M);[127X[104X323[4X[28X 1 1 . . . . . . . . . . . . . . . . . .[128X[104X324[4X[28X 1 1 . . . . . . . . . . . . . . . . . .[128X[104X325[4X[28X . . 1 1 . . . . . . . . . . . . . . . .[128X[104X326[4X[28X . . 1 1 . . . . . . . . . . . . . . . .[128X[104X327[4X[28X . . . . 1 1 . . . . . . . . . . . . . .[128X[104X328[4X[28X . . . . 1 1 . . . . . . . . . . . . . .[128X[104X329[4X[28X . . . . . . 1 1 . . . . . . . . . . . .[128X[104X330[4X[28X . . . . . . 1 1 . . . . . . . . . . . .[128X[104X331[4X[28X . . . . . . . . 1 1 . . . . . . . . . .[128X[104X332[4X[28X . . . . . . . . 1 1 . . . . . . . . . .[128X[104X333[4X[28X . . . . . . . . . . 1 1 . . . . . . . .[128X[104X334[4X[28X . . . . . . . . . . 1 1 . . . . . . . .[128X[104X335[4X[28X . . . . . . . . . . . . 1 1 . . . . . .[128X[104X336[4X[28X . . . . . . . . . . . . 1 1 . . . . . .[128X[104X337[4X[28X . . . . . . . . . . . . . . 1 1 . . . .[128X[104X338[4X[28X . . . . . . . . . . . . . . 1 1 . . . .[128X[104X339[4X[28X . . . . . . . . . . . . . . . . 1 1 . .[128X[104X340[4X[28X . . . . . . . . . . . . . . . . 1 1 . .[128X[104X341[4X[28X . . . . . . . . . . . . . . . . . . 1 1[128X[104X342[4X[28X . . . . . . . . . . . . . . . . . . 1 1[128X[104X343[4X[25Xgap>[125X [27XRank(M);[127X[104X344[4X[28X10[128X[104X345[4X[32X[104X346347348349