1<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 2<!-- %% --> 3<!-- %A matrix.msk GAP documentation Martin Schönert --> 4<!-- %A Alexander Hulpke --> 5<!-- %% --> 6<!-- %A @(#)<M>Id: matrix.msk,v 1.42 2006/03/09 16:47:16 sal Exp </M> --> 7<!-- %% --> 8<!-- %Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland --> 9<!-- %Y Copyright (C) 2002 The GAP Group --> 10<!-- %% --> 11<Chapter Label="Matrices"> 12<Heading>Matrices</Heading> 13 14Matrices are represented in &GAP; by lists of row vectors 15(see <Ref Chap="Row Vectors"/>) (for future changes to this 16policy see Chapter <Ref Chap="Vector and Matrix Objects"/>). 17The vectors must all have the same length, and their elements must lie in 18a common ring. However, since checking rectangularness can be expensive 19functions and methods of operations for matrices often will not give an error 20message for non-rectangular lists of lists –in such cases the result is 21undefined. 22<P/> 23Because matrices are just a special case of lists, all operations and 24functions for lists are applicable to matrices also (see chapter 25<Ref Chap="Lists"/>). 26This especially includes accessing elements of a matrix (see 27<Ref Sect="List Elements"/>), 28changing elements of a matrix (see <Ref Sect="List Assignment"/>), 29and comparing matrices (see <Ref Sect="Comparisons of Lists"/>). 30<P/> 31Note that, since a matrix is a list of lists, 32the behaviour of <Ref Oper="ShallowCopy"/> 33for matrices is just a special case of <Ref Oper="ShallowCopy"/> for lists 34(see <Ref Sect="Duplication of Lists"/>); 35called with an immutable matrix <A>mat</A>, 36<Ref Oper="ShallowCopy"/> returns a mutable matrix 37whose rows are identical to the rows of <A>mat</A>. 38In particular the rows are still immutable. 39To get a matrix whose rows are mutable, 40one can use <C>List( <A>mat</A>, ShallowCopy )</C>. 41 42 43<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 44<Section Label="sect:InfoMatrix"> 45<Heading>InfoMatrix (Info Class)</Heading> 46 47<#Include Label="InfoMatrix"> 48 49</Section> 50 51 52<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 53<Section Label="Categories of Matrices"> 54<Heading>Categories of Matrices</Heading> 55 56<#Include Label="IsMatrix"> 57<#Include Label="IsOrdinaryMatrix"> 58<#Include Label="IsLieMatrix"> 59 60</Section> 61 62 63<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 64<Section Label="Operators for Matrices"> 65<Heading>Operators for Matrices</Heading> 66 67The rules for arithmetic operations involving matrices are in fact 68special cases of those for the arithmetic of lists, 69given in Section <Ref Sect="Arithmetic for Lists"/> and the following sections, 70here we reiterate that definition, in the language of vectors and matrices. 71<P/> 72Note that the additive behaviour sketched below is defined only for lists in 73the category <Ref Filt="IsGeneralizedRowVector"/>, 74and the multiplicative behaviour is defined only for lists in the category 75<Ref Filt="IsMultiplicativeGeneralizedRowVector"/> 76(see <Ref Sect="Filters Controlling the Arithmetic Behaviour of Lists"/>). 77<P/> 78<Index Subkey="matrices">addition</Index> 79<C><A>mat1</A> + <A>mat2</A></C> 80<P/> 81returns the sum of the two matrices <A>mat1</A> and <A>mat2</A>, 82Probably the most usual situation is that <A>mat1</A> and <A>mat2</A> have the same 83dimensions and are defined over a common field; 84in this case the sum is a new matrix over the same field where each entry 85is the sum of the corresponding entries of the matrices. 86<P/> 87In more general situations, the sum of two matrices need not be a matrix, 88for example adding an integer matrix <A>mat1</A> and a matrix <A>mat2</A> over 89a finite field yields the table of pointwise sums, 90which will be a mixture of finite field elements and integers if <A>mat1</A> has 91bigger dimensions than <A>mat2</A>. 92<P/> 93<Index Subkey="scalar and matrix">addition</Index> 94<C><A>scalar</A> + <A>mat</A></C> 95<P/> 96<Index Subkey="matrix and scalar">addition</Index> 97<C><A>mat</A> + <A>scalar</A></C> 98<P/> 99returns the sum of the scalar <A>scalar</A> and the matrix <A>mat</A>. 100Probably the most usual situation is that the entries of <A>mat</A> lie in a 101common field with <A>scalar</A>; 102in this case the sum is a new matrix over the same field where each entry 103is the sum of the scalar and the corresponding entry of the matrix. 104<P/> 105More general situations are for example the sum of an integer scalar and a 106matrix over a finite field, or the sum of a finite field element and an 107integer matrix. 108<P/> 109<Index Subkey="matrices">subtraction</Index> 110<C><A>mat1</A> - <A>mat2</A></C> 111<P/> 112<Index Subkey="scalar and matrix">subtraction</Index> 113<C><A>scalar</A> - <A>mat</A></C> 114<P/> 115<Index Subkey="matrix and scalar">subtraction</Index> 116<C><A>mat</A> - <A>scalar</A></C> 117<P/> 118Subtracting a matrix or scalar is defined as adding its additive inverse, 119so the statements for the addition hold likewise. 120<P/> 121<Index Subkey="scalar and matrix">multiplication</Index> 122<C><A>scalar</A> * <A>mat</A></C> 123<P/> 124<Index Subkey="matrix and scalar">multiplication</Index> 125<C><A>mat</A> * <A>scalar</A></C> 126<P/> 127returns the product of the scalar <A>scalar</A> and the matrix <A>mat</A>. 128Probably the most usual situation is that the elements of <A>mat</A> lie in a 129common field with <A>scalar</A>; 130in this case the product is a new matrix over the same field where each 131entry is the product of the scalar and the corresponding entry of the matrix. 132<P/> 133More general situations are for example the product of an integer scalar and 134a matrix over a finite field, 135or the product of a finite field element and an integer matrix. 136<P/> 137<Index Subkey="vector and matrix">multiplication</Index> 138<C><A>vec</A> * <A>mat</A></C> 139<P/> 140returns the product of the row vector <A>vec</A> and the matrix <A>mat</A>. 141Probably the most usual situation is that <A>vec</A> and <A>mat</A> have the same 142lengths and are defined over a common field, 143and that all rows of <A>mat</A> have the same length <M>m</M>, say; 144in this case the product is a new row vector of length <M>m</M> over the same 145field which is the sum of the scalar multiples of the rows of <A>mat</A> with the 146corresponding entries of <A>vec</A>. 147<P/> 148More general situations are for example the product of an integer vector and 149a matrix over a finite field, 150or the product of a vector over a finite field and an integer matrix. 151<P/> 152<Index Subkey="matrix and vector">multiplication</Index> 153<C><A>mat</A> * <A>vec</A></C> 154<P/> 155returns the product of the matrix <A>mat</A> and the row vector <A>vec</A>. 156(This is the standard product of a matrix with a <E>column</E> vector.) 157Probably the most usual situation is that the length of <A>vec</A> and of all rows 158of <A>mat</A> are equal, and that the elements of <A>mat</A> and <A>vec</A> lie in a common 159field; 160in this case the product is a new row vector of the same length as <A>mat</A> and 161over the same field which is the sum of the scalar multiples of the columns 162of <A>mat</A> with the corresponding entries of <A>vec</A>. 163<P/> 164More general situations are for example the product of an integer matrix and 165a vector over a finite field, 166or the product of a matrix over a finite field and an integer vector. 167<P/> 168<Index Subkey="matrices">multiplication</Index> 169<C><A>mat1</A> * <A>mat2</A></C> 170<P/> 171This form evaluates to the (Cauchy) product of the two matrices <A>mat1</A> and 172<A>mat2</A>. 173Probably the most usual situation is that the number of columns of <A>mat1</A> 174equals the number of rows of <A>mat2</A>, 175and that the elements of <A>mat</A> and <A>vec</A> lie in a common field; 176if <A>mat1</A> is a matrix with <M>m</M> rows and <M>n</M> columns, say, and <A>mat2</A> is a 177matrix with <M>n</M> rows and <M>o</M> columns, the result is a new matrix with <M>m</M> 178rows and <M>o</M> columns. 179The element in row <M>i</M> at position <M>j</M> of the product is the sum of 180<M><A>mat1</A>[i][l] * <A>mat2</A>[l][j]</M>, with <M>l</M> running from <M>1</M> to <M>n</M>. 181<P/> 182<Index Subkey="matrix">inverse</Index> 183<C>Inverse( <A>mat</A> )</C> 184<P/> 185returns the inverse of the matrix <A>mat</A>, 186which must be an invertible square matrix. 187If <A>mat</A> is not invertible then <K>fail</K> is returned. 188<P/> 189<Index Subkey="matrices">quotient</Index> 190<C><A>mat1</A> / <A>mat2</A></C> 191<P/> 192<Index Subkey="scalar and matrix">quotient</Index> 193<C><A>scalar</A> / <A>mat</A></C> 194<P/> 195<Index Subkey="matrix and scalar">quotient</Index> 196<C><A>mat</A> / <A>scalar</A></C> 197<P/> 198<Index Subkey="vector and matrix">quotient</Index> 199<C><A>vec</A> / <A>mat</A></C> 200<P/> 201In general, <C><A>left</A> / <A>right</A></C> is defined as <C><A>left</A> * <A>right</A>^-1</C>. 202Thus in the above forms the right operand must always be invertible. 203<P/> 204<Index Subkey="matrix">power</Index> 205<C><A>mat</A> ^ <A>int</A></C> 206<P/> 207<Index Subkey="matrix">conjugate</Index> 208<C><A>mat1</A> ^ <A>mat2</A></C> 209<P/> 210<Index Subkey="vector under matrix">image</Index> 211<C><A>vec</A> ^ <A>mat</A></C> 212<P/> 213Powering a square matrix <A>mat</A> by an integer <A>int</A> yields the <A>int</A>-th power 214of <A>mat</A>; if <A>int</A> is negative then <A>mat</A> must be invertible, 215if <A>int</A> is <C>0</C> then the result is the identity matrix <C>One( <A>mat</A> )</C>, 216even if <A>mat</A> is not invertible. 217<P/> 218Powering a square matrix <A>mat1</A> by an invertible square matrix <A>mat2</A> of the 219same dimensions yields the conjugate of <A>mat1</A> by <A>mat2</A>, i.e., 220the matrix <C><A>mat2</A>^-1 * <A>mat1</A> * <A>mat2</A></C>. 221<P/> 222Powering a row vector <A>vec</A> by a matrix <A>mat</A> is in every respect equivalent 223to <C><A>vec</A> * <A>mat</A></C>. 224This operations reflects the fact that matrices act naturally on row vectors 225by multiplication from the right, and that the powering operator is &GAP;'s 226standard for group actions. 227<P/> 228<Index Subkey="commutator">matrices</Index> 229<C>Comm( <A>mat1</A>, <A>mat2</A> )</C> 230<P/> 231returns the commutator of the square invertible matrices <A>mat1</A> and <A>mat2</A> 232of the same dimensions and over a common field, 233which is the matrix <C><A>mat1</A>^-1 * <A>mat2</A>^-1 * <A>mat1</A> * <A>mat2</A></C>. 234<P/> 235 236The following cases are still special cases of the general list arithmetic 237defined in <Ref Sect="Arithmetic for Lists"/>. 238<P/> 239<Index Subkey="scalar and matrix list">addition</Index> 240<C><A>scalar</A> + <A>matlist</A></C> 241<P/> 242<Index Subkey="scalar and matrix list">addition</Index> 243<C><A>matlist</A> + <A>scalar</A></C> 244<P/> 245<Index Subkey="scalar and matrix list">subtraction</Index> 246<C><A>scalar</A> - <A>matlist</A></C> 247<P/> 248<Index Subkey="scalar and matrix list">subtraction</Index> 249<C><A>matlist</A> - <A>scalar</A></C> 250<P/> 251<Index Subkey="scalar and matrix list">multiplication</Index> 252<C><A>scalar</A> * <A>matlist</A></C> 253<P/> 254<Index Subkey="scalar and matrix list">multiplication</Index> 255<C><A>matlist</A> * <A>scalar</A></C> 256<P/> 257<Index Subkey="scalar and matrix list">quotient</Index> 258<C><A>matlist</A> / <A>scalar</A></C> 259<P/> 260A scalar <A>scalar</A> may also be added, subtracted, multiplied with, or 261divided into a list <A>matlist</A> of matrices. The result is a new list 262of matrices where each matrix is the result of performing the operation 263with the corresponding matrix in <A>matlist</A>. 264<P/> 265<Index Subkey="matrix and matrix list">multiplication</Index> 266<C><A>mat</A> * <A>matlist</A></C> 267<P/> 268<Index Subkey="matrix and matrix list">multiplication</Index> 269<C><A>matlist</A> * <A>mat</A></C> 270<P/> 271A matrix <A>mat</A> may also be multiplied with a list <A>matlist</A> of matrices. 272The result is a new list of matrices, where each entry is the product of 273<A>mat</A> and the corresponding entry in <A>matlist</A>. 274<P/> 275<Index Subkey="matrix and matrix list">quotient</Index> 276<C><A>matlist</A> / <A>mat</A></C> 277<P/> 278Dividing a list <A>matlist</A> of matrices by an invertible matrix <A>mat</A> 279evaluates to <C><A>matlist</A> * <A>mat</A>^-1</C>. 280<P/> 281<Index Subkey="vector and matrix list">multiplication</Index> 282<C><A>vec</A> * <A>matlist</A></C> 283<P/> 284returns the product of the vector <A>vec</A> and the list of matrices <A>mat</A>. 285The lengths <A>l</A> of <A>vec</A> and <A>matlist</A> must be equal. 286All matrices in <A>matlist</A> must have the same dimensions. The elements of 287<A>vec</A> and the elements of the matrices in <A>matlist</A> must lie in a common 288ring. The product is the sum over <C><A>vec</A>[<A>i</A>] * <A>matlist</A>[<A>i</A>]</C> with 289<A>i</A> running from 1 to <A>l</A>. 290<P/> 291 292For the mutability of results of arithmetic operations, 293see <Ref Sect="Mutability and Copyability"/>. 294 295</Section> 296 297 298<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 299<Section Label="Properties and Attributes of Matrices"> 300<Heading>Properties and Attributes of Matrices</Heading> 301 302<#Include Label="DimensionsMat"> 303<#Include Label="DefaultFieldOfMatrix"> 304<#Include Label="TraceMat"> 305<#Include Label="DeterminantMat"> 306<#Include Label="DeterminantMatDestructive"> 307<#Include Label="DeterminantMatDivFree"> 308<#Include Label="MatObj_IsEmptyMatrix"> 309<#Include Label="IsMonomialMatrix"> 310<#Include Label="IsDiagonalMat"> 311<#Include Label="IsUpperTriangularMat"> 312<#Include Label="IsLowerTriangularMat"> 313 314</Section> 315 316 317<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 318<Section Label="Matrix Constructions"> 319<Heading>Matrix Constructions</Heading> 320 321<#Include Label="IdentityMat"> 322<#Include Label="NullMat"> 323<#Include Label="EmptyMatrix"> 324<#Include Label="DiagonalMat"> 325<#Include Label="PermutationMat"> 326<#Include Label="TransposedMatImmutable"> 327<#Include Label="TransposedMatDestructive"> 328<#Include Label="KroneckerProduct"> 329<#Include Label="ReflectionMat"> 330<#Include Label="PrintArray"> 331 332</Section> 333 334 335<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 336<Section Label="Random Matrices"> 337<Heading>Random Matrices</Heading> 338 339<#Include Label="RandomMat"> 340<#Include Label="RandomInvertibleMat"> 341<#Include Label="RandomUnimodularMat"> 342 343</Section> 344 345 346<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 347<Section Label="Matrices Representing Linear Equations and the Gaussian Algorithm"> 348<Heading>Matrices Representing Linear Equations and the Gaussian Algorithm</Heading> 349 350<Index>Gaussian algorithm</Index> 351<#Include Label="RankMat"> 352<#Include Label="TriangulizedMat"> 353<#Include Label="TriangulizeMat"> 354<#Include Label="NullspaceMat"> 355<#Include Label="NullspaceMatDestructive"> 356<#Include Label="SolutionMat"> 357<#Include Label="SolutionMatDestructive"> 358<#Include Label="BaseFixedSpace"> 359 360</Section> 361 362 363<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 364<Section Label="Eigenvectors and eigenvalues"> 365<Heading>Eigenvectors and eigenvalues</Heading> 366 367<#Include Label="GeneralisedEigenvalues"> 368<#Include Label="GeneralisedEigenspaces"> 369<#Include Label="Eigenvalues"> 370<#Include Label="Eigenspaces"> 371<#Include Label="Eigenvectors"> 372 373</Section> 374 375 376<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 377<Section Label="Elementary Divisors"> 378<Heading>Elementary Divisors</Heading> 379 380See also chapter <Ref Chap="Integral matrices and lattices"/>. 381 382<#Include Label="ElementaryDivisorsMat"> 383<#Include Label="ElementaryDivisorsTransformationsMat"> 384<#Include Label="DiagonalizeMat"> 385 386</Section> 387 388 389<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 390<Section Label="Echelonized Matrices"> 391<Heading>Echelonized Matrices</Heading> 392 393<#Include Label="SemiEchelonMat"> 394<#Include Label="SemiEchelonMatDestructive"> 395<#Include Label="SemiEchelonMatTransformation"> 396<#Include Label="SemiEchelonMats"> 397<#Include Label="SemiEchelonMatsDestructive"> 398 399</Section> 400 401 402<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 403<Section Label="Matrices as Basis of a Row Space"> 404<Heading>Matrices as Basis of a Row Space</Heading> 405 406See also chapter <Ref Chap="Integral matrices and lattices"/> 407 408<#Include Label="BaseMat"> 409<#Include Label="BaseMatDestructive"> 410<#Include Label="BaseOrthogonalSpaceMat"> 411<#Include Label="SumIntersectionMat"> 412<#Include Label="BaseSteinitzVectors"> 413 414</Section> 415 416 417<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 418<Section Label="Triangular Matrices"> 419<Heading>Triangular Matrices</Heading> 420 421<#Include Label="DiagonalOfMat"> 422<#Include Label="UpperSubdiagonal"> 423<#Include Label="DepthOfUpperTriangularMatrix"> 424 425</Section> 426 427 428<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 429<Section Label="Matrices as Linear Mappings"> 430<Heading>Matrices as Linear Mappings</Heading> 431 432<#Include Label="CharacteristicPolynomial"> 433<#Include Label="RationalCanonicalFormTransform"> 434<#Include Label="JordanDecomposition"> 435<#Include Label="BlownUpMat"> 436<#Include Label="BlownUpVector"> 437<#Include Label="CompanionMat"> 438 439</Section> 440 441 442<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 443<Section Label="Matrices over Finite Fields"> 444<Heading>Matrices over Finite Fields</Heading> 445 446Just as for row vectors, 447(see section <Ref Sect="Row Vectors over Finite Fields"/>), 448&GAP; has a special representation for matrices over small finite fields. 449<P/> 450To be eligible to be represented in this way, each row of a matrix 451must be able to be represented as a compact row vector of the same 452length over <E>the same</E> finite field. 453<P/> 454<Example><![CDATA[ 455gap> v := Z(2)*[1,0,0,1,1]; 456[ Z(2)^0, 0*Z(2), 0*Z(2), Z(2)^0, Z(2)^0 ] 457gap> ConvertToVectorRep(v,2); 4582 459gap> v; 460<a GF2 vector of length 5> 461gap> m := [v];; ConvertToMatrixRep(m,GF(2));; m; 462<a 1x5 matrix over GF2> 463gap> m := [v,v];; ConvertToMatrixRep(m,GF(2));; m; 464<a 2x5 matrix over GF2> 465gap> m := [v,v,v];; ConvertToMatrixRep(m,GF(2));; m; 466<a 3x5 matrix over GF2> 467gap> v := Z(3)*[1..8]; 468[ Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0 ] 469gap> ConvertToVectorRep(v); 4703 471gap> m := [v];; ConvertToMatrixRep(m,GF(3));; m; 472[ [ Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0 ] ] 473gap> RepresentationsOfObject(m); 474[ "IsPositionalObjectRep", "Is8BitMatrixRep" ] 475gap> m := [v,v,v,v];; ConvertToMatrixRep(m,GF(3));; m; 476< mutable compressed matrix 4x8 over GF(3) > 477]]></Example> 478<P/> 479All compressed matrices over GF(2) are viewed as 480<C><a <A>n</A>x<A>m</A> matrix over GF2></C>, 481while over fields GF(q) for q between 3 and 256, matrices 482with 25 or more entries are viewed in this way, and smaller ones as 483lists of lists. 484<P/> 485Matrices can be converted to this special representation via 486the following functions. 487<P/> 488Note that the main advantage of this special representation of 489matrices is in low dimensions, where various overheads can be 490reduced. In higher dimensions, a list of compressed vectors will be 491almost as fast. Note also that list access and assignment will be 492somewhat slower for compressed matrices than for plain lists. 493<P/> 494In order to form a row of a compressed matrix a vector must accept 495certain restrictions. Specifically, it cannot change its length or 496change the field over which it is compressed. The main consequences of 497this are: that only elements of the appropriate field can be assigned 498to entries of the vector, and only to positions between 1 and the 499original length; that the vector cannot be shared between two matrices 500compressed over different fields. 501<P/> 502This is enforced by the filter <C>IsLockedRepresentationVector</C>. When a 503vector becomes part of a compressed matrix, this filter is set for it. 504Assignment, <Ref Oper="Unbind" Label="unbind a list entry"/>, 505<Ref Func="ConvertToVectorRep" Label="for a list (and a field)"/> and 506<Ref Func="ConvertToMatrixRep" Label="for a list (and a field)"/> 507are all prevented from altering a vector with this filter. 508<P/> 509<Example><![CDATA[ 510gap> v := [Z(2),Z(2)];; ConvertToVectorRep(v,GF(2));; v; 511<a GF2 vector of length 2> 512gap> m := [v,v]; 513[ <a GF2 vector of length 2>, <a GF2 vector of length 2> ] 514gap> ConvertToMatrixRep(m,GF(2)); 5152 516gap> m2 := [m[1], [Z(4),Z(4)]]; # now try and mix in some GF(4) 517[ <a GF2 vector of length 2>, [ Z(2^2), Z(2^2) ] ] 518gap> ConvertToMatrixRep(m2); # but m2[1] is locked 519#I ConvertToVectorRep: locked vector not converted to different field 520fail 521gap> m2 := [ShallowCopy(m[1]), [Z(4),Z(4)]]; # a fresh copy of row 1 522[ <a GF2 vector of length 2>, [ Z(2^2), Z(2^2) ] ] 523gap> ConvertToMatrixRep(m2); # now it works 5244 525gap> m2; 526[ [ Z(2)^0, Z(2)^0 ], [ Z(2^2), Z(2^2) ] ] 527gap> RepresentationsOfObject(m2); 528[ "IsPositionalObjectRep", "Is8BitMatrixRep" ] 529]]></Example> 530<P/> 531Arithmetic operations (see <Ref Sect="Arithmetic for Lists"/> and the following 532sections) preserve the compression status of matrices in the sense that 533if all arguments are compressed matrices written over the same field and 534the result is a matrix then also the result is a compressed matrix 535written over this field. 536<P/> 537There are also two operations that are only available for matrices 538written over finite fields. 539 540<#Include Label="ImmutableMatrix"> 541<#Include Label="ConvertToMatrixRep"> 542<#Include Label="ProjectiveOrder"> 543<#Include Label="SimultaneousEigenvalues"> 544 545</Section> 546 547 548<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 549<Section Label="Inverse and Nullspace of an Integer Matrix Modulo an Ideal"> 550<Heading>Inverse and Nullspace of an Integer Matrix Modulo an Ideal</Heading> 551 552The following operations deal with matrices over a ring, 553but only care about the residues of their entries modulo some ring element. 554In the case of the integers and a prime number <M>p</M>, say, 555this is effectively computation in a matrix over the prime field 556in characteristic <M>p</M>. 557 558<#Include Label="InverseMatMod"> 559<#Include Label="BasisNullspaceModN"> 560<#Include Label="NullspaceModN"> 561 562</Section> 563 564 565<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 566<Section Label="Special Multiplication Algorithms for Matrices over GF(2)"> 567<Heading>Special Multiplication Algorithms for Matrices over GF(2)</Heading> 568 569When multiplying two compressed matrices <M>M</M> and <M>N</M> over GF(2) of dimensions 570<M>a \times b</M> and <M>b \times c</M>, say, 571where <M>a</M>, <M>b</M> and <M>c</M> are all 572greater than or equal to 128, &GAP; by default uses a more 573sophisticated matrix multiplication algorithm, in which linear 574combinations of groups of 8 rows of <M>M</M> are remembered and re-used in 575constructing various rows of the product. This is called level 8 576grease. To optimise memory access patterns, these combinations are 577stored for <M>(b+255)/256</M> sets of 8 rows at once. This number is called 578the blocking level. 579<P/> 580These levels of grease and blocking are found experimentally to give 581good performance across a range of processors and matrix sizes, but 582other levels may do even better in some cases. You can control the 583levels exactly using the functions below. 584<P/> 585We plan to include greased blocked matrix multiplication for other 586finite fields, and greased blocked algorithms for inversion and other 587matrix operations in a future release. 588<P/> 589<ManSection> 590<Func Name="PROD_GF2MAT_GF2MAT_SIMPLE" Arg='m1, m2'/> 591 592<Description> 593This function performs the standard unblocked and ungreased matrix 594multiplication for matrices of any size. 595</Description> 596</ManSection> 597<P/> 598<ManSection> 599<Func Name="PROD_GF2MAT_GF2MAT_ADVANCED" Arg='m1, m2, g, b'/> 600 601<Description> 602This function computes the product of <A>m1</A> and <A>m2</A>, which must be 603compressed matrices over GF(2) of compatible dimensions, using level <A>g</A> 604grease and level <A>b</A> blocking. 605</Description> 606</ManSection> 607 608</Section> 609 610 611<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 612<Section Label="Block Matrices"> 613<Heading>Block Matrices</Heading> 614 615<#Include Label="[1]{matblock}"> 616<#Include Label="AsBlockMatrix"> 617<#Include Label="BlockMatrix"> 618<#Include Label="MatrixByBlockMatrix"> 619 620</Section> 621 622 623<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 624<Section Label="Linear Programming"> 625<Heading>Linear Programming</Heading> 626 627<#Include Label="SimplexMethod"> 628 629</Section> 630</Chapter> 631 632<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 633<!-- %% --> 634<!-- %E --> 635 636