Debian Codegraph @

doc/ref/chap24.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
7 <head>
8 <title>GAP (ref) - Chapter 24: Matrices</title>
9 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10 <meta name="generator" content="GAPDoc2HTML" />
11 <link rel="stylesheet" type="text/css" href="manual.css" />
12 <script src="manual.js" type="text/javascript"></script>
13 <script type="text/javascript">overwriteStyle();</script>
14 </head>
15 <body class="chap24" onload="jscontent()">
16
17
18 <div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
19
20 <div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap23.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap25.html">[Next Chapter]</a>&nbsp; </div>
21
22 <p id="mathjaxlink" class="pcenter"><a href="chap24_mj.html">[MathJax on]</a></p>
23 <p><a id="X812CCAB278643A59" name="X812CCAB278643A59"></a></p>
24 <div class="ChapSects"><a href="chap24.html#X812CCAB278643A59">24 <span class="Heading">Matrices</span></a>
25 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X801E1B5D7EC8DDD3">24.1 <span class="Heading">InfoMatrix (Info Class)</span></a>
26 </span>
27 <div class="ContSSBlock">
28 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X78EC82D27B4191DA">24.1-1 InfoMatrix</a></span>
29 </div></div>
30 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X866E55A58164FAED">24.2 <span class="Heading">Categories of Matrices</span></a>
31 </span>
32 <div class="ContSSBlock">
33 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7E1AE46B862B185F">24.2-1 IsMatrix</a></span>
34 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7CF42B8A845BC6A9">24.2-2 IsOrdinaryMatrix</a></span>
35 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X86EC33E17DD12D0E">24.2-3 IsLieMatrix</a></span>
36 </div></div>
37 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X7899335779A39A95">24.3 <span class="Heading">Operators for Matrices</span></a>
38 </span>
39 </div>
40 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X7F5AD28E869B66CB">24.4 <span class="Heading">Properties and Attributes of Matrices</span></a>
41 </span>
42 <div class="ContSSBlock">
43 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X83A9DC2085D3A972">24.4-1 DimensionsMat</a></span>
44 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X80AE547B8095A5CB">24.4-2 DefaultFieldOfMatrix</a></span>
45 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X784EC2777C06AFE4">24.4-3 TraceMatrix</a></span>
46 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8488D69A7ADDB4E2">24.4-4 DeterminantMatrix</a></span>
47 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X824B5DC2875118B3">24.4-5 DeterminantMatrixDestructive</a></span>
48 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X80693FAB7D541804">24.4-6 DeterminantMatrixDivFree</a></span>
49 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7F8D25897EC1630B">24.4-7 IsEmptyMatrix</a></span>
50 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X848B80437CE65FF3">24.4-8 IsMonomialMatrix</a></span>
51 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7EEC8E768178696E">24.4-9 IsDiagonalMatrix</a></span>
52 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8740E71C799C0BCC">24.4-10 IsUpperTriangularMatrix</a></span>
53 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X853A5B988306DBFE">24.4-11 IsLowerTriangularMatrix</a></span>
54 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7FD5345487011416">24.4-12 IsSquareMatrix</a></span>
55 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7ACD31A77E8458AA">24.4-13 IsSymmetricMatrix</a></span>
56 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X833DA1E07B0B23EF">24.4-14 IsAntisymmetricMatrix</a></span>
57 </div></div>
58 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X823FB2398697B957">24.5 <span class="Heading">Matrix Constructions</span></a>
59 </span>
60 <div class="ContSSBlock">
61 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7DB902CE848D1524">24.5-1 IdentityMat</a></span>
62 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X86D343A77D9B3D4D">24.5-2 NullMat</a></span>
63 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8508A7EA812BA0CC">24.5-3 EmptyMatrix</a></span>
64 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X81042E7A7F247ADE">24.5-4 DiagonalMat</a></span>
65 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X87BADF217C19CBE1">24.5-5 DiagonalMatrix</a></span>
66 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X806C62A67A7D5379">24.5-6 PermutationMat</a></span>
67 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7C52A38C79C36C35">24.5-7 TransposedMatImmutable</a></span>
68 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7DBB40847E2B6252">24.5-8 TransposedMatDestructive</a></span>
69 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8634C79E7DB22934">24.5-9 KroneckerProduct</a></span>
70 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X845EC4D18054D140">24.5-10 ReflectionMat</a></span>
71 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7DEBC9967DFDFC18">24.5-11 PrintArray</a></span>
72 </div></div>
73 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X79CC5F568252D341">24.6 <span class="Heading">Random Matrices</span></a>
74 </span>
75 <div class="ContSSBlock">
76 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7F957F0280A87961">24.6-1 RandomMat</a></span>
77 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7D31ACA4809B321B">24.6-2 RandomMatrix</a></span>
78 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7C939B4A7EDF015D">24.6-3 RandomInvertibleMat</a></span>
79 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8743657384B15B5B">24.6-4 RandomInvertibleMatrix</a></span>
80 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X84743732846ACB44">24.6-5 RandomUnimodularMat</a></span>
81 </div></div>
82 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X85485DCE809E323A">24.7 <span class="Heading">Matrices Representing Linear Equations and the Gaussian Algorithm</span></a>
83 </span>
84 <div class="ContSSBlock">
85 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7A995A74838950E6">24.7-1 RankMatrix</a></span>
86 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7BA26C3387AB434E">24.7-2 TriangulizedMat</a></span>
87 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8384CA8E7B3850D3">24.7-3 TriangulizeMat</a></span>
88 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7DA0D5887DB12DC4">24.7-4 NullspaceMat</a></span>
89 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X87684B0F7AB7B7DB">24.7-5 NullspaceMatDestructive</a></span>
90 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X838A519C7CD2969E">24.7-6 SolutionMat</a></span>
91 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7A7880D27CE7C1FE">24.7-7 SolutionMatDestructive</a></span>
92 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7AB5AC547809F999">24.7-8 BaseFixedSpace</a></span>
93 </div></div>
94 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X871FCAA97C60B2BA">24.8 <span class="Heading">Eigenvectors and eigenvalues</span></a>
95 </span>
96 <div class="ContSSBlock">
97 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7A2462CC7B0C9D66">24.8-1 GeneralisedEigenvalues</a></span>
98 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X845CA0457D65876D">24.8-2 GeneralisedEigenspaces</a></span>
99 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8413C6FB7CEE9D59">24.8-3 Eigenvalues</a></span>
100 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7A6B047281B52FD7">24.8-4 Eigenspaces</a></span>
101 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8506584579D4EA18">24.8-5 Eigenvectors</a></span>
102 </div></div>
103 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X7E5405D085661B29">24.9 <span class="Heading">Elementary Divisors</span></a>
104 </span>
105 <div class="ContSSBlock">
106 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7AC4D74F81908109">24.9-1 ElementaryDivisorsMat</a></span>
107 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7AA1C9047B102204">24.9-2 ElementaryDivisorsTransformationsMat</a></span>
108 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X85819D3F7A582180">24.9-3 DiagonalizeMat</a></span>
109 </div></div>
110 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X7CA6B51D7AE3172B">24.10 <span class="Heading">Echelonized Matrices</span></a>
111 </span>
112 <div class="ContSSBlock">
113 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7D5D6BD07B7E981B">24.10-1 SemiEchelonMat</a></span>
114 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8251F6F57D346385">24.10-2 SemiEchelonMatDestructive</a></span>
115 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7EFD1DB5861A54F0">24.10-3 SemiEchelonMatTransformation</a></span>
116 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X827D7971800DB661">24.10-4 SemiEchelonMats</a></span>
117 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X808F493B839BC7A6">24.10-5 SemiEchelonMatsDestructive</a></span>
118 </div></div>
119 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X86B0D4A886BC0C6E">24.11 <span class="Heading">Matrices as Basis of a Row Space</span></a>
120 </span>
121 <div class="ContSSBlock">
122 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7AD6B5F5794D9E46">24.11-1 BaseMat</a></span>
123 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X78B094597E382A5F">24.11-2 BaseMatDestructive</a></span>
124 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X78B94EFF87A455BE">24.11-3 BaseOrthogonalSpaceMat</a></span>
125 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7AFF8BCF80C88B45">24.11-4 SumIntersectionMat</a></span>
126 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8245D54F7AC532EB">24.11-5 BaseSteinitzVectors</a></span>
127 </div></div>
128 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X79D5E53685F0FBEE">24.12 <span class="Heading">Triangular Matrices</span></a>
129 </span>
130 <div class="ContSSBlock">
131 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7A9139D686ACB7D8">24.12-1 DiagonalOfMatrix</a></span>
132 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X84A78C057F9DAE5E">24.12-2 UpperSubdiagonal</a></span>
133 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X84D74DEA798A9094">24.12-3 DepthOfUpperTriangularMatrix</a></span>
134 </div></div>
135 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X85B403857F2855F7">24.13 <span class="Heading">Matrices as Linear Mappings</span></a>
136 </span>
137 <div class="ContSSBlock">
138 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X87FA0A727CDB060B">24.13-1 CharacteristicPolynomial</a></span>
139 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7B52560C792C1A0F">24.13-2 RationalCanonicalFormTransform</a></span>
140 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X83F55D4E79BA5D1B">24.13-3 JordanDecomposition</a></span>
141 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X85923C107A4569D0">24.13-4 BlownUpMat</a></span>
142 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X82AC277D84EC5749">24.13-5 BlownUpVector</a></span>
143 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7E06762479A00DF4">24.13-6 CompanionMatrix</a></span>
144 </div></div>
145 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X873822B6830CE367">24.14 <span class="Heading">Matrices over Finite Fields</span></a>
146 </span>
147 <div class="ContSSBlock">
148 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7DED2522828B6C30">24.14-1 ImmutableMatrix</a></span>
149 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8587A62F818AA0D6">24.14-2 ConvertToMatrixRep</a></span>
150 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X84A76F7A7B4166BC">24.14-3 ProjectiveOrder</a></span>
151 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X847ADC6779E33A1C">24.14-4 SimultaneousEigenvalues</a></span>
152 </div></div>
153 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X8593A5337D3B2C70">24.15 <span class="Heading">Inverse and Nullspace of an Integer Matrix Modulo an Ideal</span></a>
154 </span>
155 <div class="ContSSBlock">
156 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7D8D1E0E83C7F872">24.15-1 InverseMatMod</a></span>
157 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7D7DF873826A7C20">24.15-2 BasisNullspaceModN</a></span>
158 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X86AE919983B242E2">24.15-3 NullspaceModQ</a></span>
159 </div></div>
160 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X787DF5F07DC7D86E">24.16 <span class="Heading">Special Multiplication Algorithms for Matrices over GF(2)</span></a>
161 </span>
162 <div class="ContSSBlock">
163 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7C0C26027FAE0C83">24.16-1 PROD_GF2MAT_GF2MAT_SIMPLE</a></span>
164 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X81965B7D7F45E088">24.16-2 PROD_GF2MAT_GF2MAT_ADVANCED</a></span>
165 </div></div>
166 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X7F8A71F38201A250">24.17 <span class="Heading">Block Matrices</span></a>
167 </span>
168 <div class="ContSSBlock">
169 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X7D675B3C79CF8871">24.17-1 AsBlockMatrix</a></span>
170 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X8633538685551E7A">24.17-2 BlockMatrix</a></span>
171 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X83FAF4158180041F">24.17-3 MatrixByBlockMatrix</a></span>
172 </div></div>
173 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap24.html#X782F2EBF80C431D0">24.18 <span class="Heading">Linear Programming</span></a>
174 </span>
175 <div class="ContSSBlock">
176 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap24.html#X845D5F8D7D905CB8">24.18-1 SimplexMethod</a></span>
177 </div></div>
178 </div>
179
180 <h3>24 <span class="Heading">Matrices</span></h3>
181
182 <p>In <strong class="pkg">GAP</strong>, Matrices can be represented by lists of row vectors, see <a href="chap23.html#X82C7E6CF7BA03391"><span class="RefLink">23</span></a>. (For a more general way to represent vectors and matrices, see Chapter <a href="chap26.html#X856C23B87E50F118"><span class="RefLink">26</span></a>). The row vectors must all have the same length, and their elements must lie in a common ring. However, since checking rectangularness can be expensive functions and methods of operations for matrices often will not give an error message for non-rectangular lists of lists –in such cases the result is undefined.</p>
183
184 <p>Because matrices are just a special case of lists, all operations and functions for lists are applicable to matrices also (see chapter <a href="chap21.html#X7B256AE5780F140A"><span class="RefLink">21</span></a>). This especially includes accessing elements of a matrix (see <a href="chap21.html#X7921047F83F5FA28"><span class="RefLink">21.3</span></a>), changing elements of a matrix (see <a href="chap21.html#X8611EF768210625B"><span class="RefLink">21.4</span></a>), and comparing matrices (see <a href="chap21.html#X8016D50F85147A77"><span class="RefLink">21.10</span></a>).</p>
185
186 <p>Note that, since a matrix is a list of lists, the behaviour of <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) for matrices is just a special case of <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) for lists (see <a href="chap21.html#X7ED7C0738495556F"><span class="RefLink">21.7</span></a>); called with an immutable matrix <var class="Arg">mat</var>, <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) returns a mutable matrix whose rows are identical to the rows of <var class="Arg">mat</var>. In particular the rows are still immutable. To get a matrix whose rows are mutable, one can use <code class="code">List( <var class="Arg">mat</var>, ShallowCopy )</code>.</p>
187
188 <p><a id="X801E1B5D7EC8DDD3" name="X801E1B5D7EC8DDD3"></a></p>
189
190 <h4>24.1 <span class="Heading">InfoMatrix (Info Class)</span></h4>
191
192 <p><a id="X78EC82D27B4191DA" name="X78EC82D27B4191DA"></a></p>
193
194 <h5>24.1-1 InfoMatrix</h5>
195
196 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; InfoMatrix</code></td><td class="tdright">(&nbsp;info class&nbsp;)</td></tr></table></div>
197 <p>The info class for matrix operations is <code class="func">InfoMatrix</code>.</p>
198
199 <p><a id="X866E55A58164FAED" name="X866E55A58164FAED"></a></p>
200
201 <h4>24.2 <span class="Heading">Categories of Matrices</span></h4>
202
203 <p><a id="X7E1AE46B862B185F" name="X7E1AE46B862B185F"></a></p>
204
205 <h5>24.2-1 IsMatrix</h5>
206
207 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsMatrix</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
208 <p>By convention <em>matrix</em> is a list of lists of equal length whose entries lie in a common ring.</p>
209
210 <p>For technical reasons laid out at the top of Chapter <a href="chap24.html#X812CCAB278643A59"><span class="RefLink">24</span></a>, the filter <code class="func">IsMatrix</code> is a synonym for a table of ring elements, (see <code class="func">IsTable</code> (<a href="chap21.html#X80872FAF80EB5DF9"><span class="RefLink">21.1-4</span></a>) and <code class="func">IsRingElement</code> (<a href="chap31.html#X84BF40CA86C07361"><span class="RefLink">31.14-16</span></a>)). This means that <code class="func">IsMatrix</code> returns <code class="keyw">true</code> for tables such as <code class="code">[[1,2],[3]]</code>. If necessary, <code class="func">IsRectangularTable</code> (<a href="chap21.html#X79581E0387F7F7A9"><span class="RefLink">21.1-5</span></a>) can be used to test whether an object is a list of homogeneous lists of equal lengths manually.</p>
211
212 <p>Note that matrices may have different multiplications, besides the usual matrix product there is for example the Lie product. So there are categories such as <code class="func">IsOrdinaryMatrix</code> (<a href="chap24.html#X7CF42B8A845BC6A9"><span class="RefLink">24.2-2</span></a>) and <code class="func">IsLieMatrix</code> (<a href="chap24.html#X86EC33E17DD12D0E"><span class="RefLink">24.2-3</span></a>) that describe the matrix multiplication. One can form the product of two matrices only if they support the same multiplication.</p>
213
214
215 <div class="example"><pre>
216 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2,3],[4,5,6],[7,8,9]];</span>
217 [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
218 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsMatrix(mat);</span>
219 true
220 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2],[3]];</span>
221 [ [ 1, 2 ], [ 3 ] ]
222 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsMatrix(mat);</span>
223 true
224 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRectangularTable(mat);</span>
225 false
226 </pre></div>
227
228 <p>Note that the empty list <code class="code">[]</code> and more complex <q>empty</q> structures such as <code class="code">[[]]</code> are <em>not</em> matrices, although special methods allow them be used in place of matrices in some situations. See <code class="func">EmptyMatrix</code> (<a href="chap24.html#X8508A7EA812BA0CC"><span class="RefLink">24.5-3</span></a>) below.</p>
229
230
231 <div class="example"><pre>
232 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">[[0]]*[[]];</span>
233 [ [ ] ]
234 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsMatrix([[]]);</span>
235 false
236 </pre></div>
237
238 <p><a id="X7CF42B8A845BC6A9" name="X7CF42B8A845BC6A9"></a></p>
239
240 <h5>24.2-2 IsOrdinaryMatrix</h5>
241
242 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsOrdinaryMatrix</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
243 <p>An <em>ordinary matrix</em> is a matrix whose multiplication is the ordinary matrix multiplication.</p>
244
245 <p>Each matrix in internal representation is in the category <code class="func">IsOrdinaryMatrix</code>, and arithmetic operations with objects in <code class="func">IsOrdinaryMatrix</code> produce again matrices in <code class="func">IsOrdinaryMatrix</code>.</p>
246
247 <p>Note that we want that Lie matrices shall be matrices that behave in the same way as ordinary matrices, except that they have a different multiplication. So we must distinguish the different matrix multiplications, in order to be able to describe the applicability of multiplication, and also in order to form a matrix of the appropriate type as the sum, difference etc. of two matrices which have the same multiplication.</p>
248
249 <p><a id="X86EC33E17DD12D0E" name="X86EC33E17DD12D0E"></a></p>
250
251 <h5>24.2-3 IsLieMatrix</h5>
252
253 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsLieMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
254 <p>A <em>Lie matrix</em> is a matrix whose multiplication is given by the Lie bracket. (Note that a matrix with ordinary matrix multiplication is in the category <code class="func">IsOrdinaryMatrix</code> (<a href="chap24.html#X7CF42B8A845BC6A9"><span class="RefLink">24.2-2</span></a>).)</p>
255
256 <p>Each matrix created by <code class="func">LieObject</code> (<a href="chap64.html#X87F121978775AF48"><span class="RefLink">64.1-1</span></a>) is in the category <code class="func">IsLieMatrix</code>, and arithmetic operations with objects in <code class="func">IsLieMatrix</code> produce again matrices in <code class="func">IsLieMatrix</code>.</p>
257
258 <p><a id="X7899335779A39A95" name="X7899335779A39A95"></a></p>
259
260 <h4>24.3 <span class="Heading">Operators for Matrices</span></h4>
261
262 <p>The rules for arithmetic operations involving matrices are in fact special cases of those for the arithmetic of lists, given in Section <a href="chap21.html#X845EEAF083D43CCE"><span class="RefLink">21.11</span></a> and the following sections, here we reiterate that definition, in the language of vectors and matrices.</p>
263
264 <p>Note that the additive behaviour sketched below is defined only for lists in the category <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>), and the multiplicative behaviour is defined only for lists in the category <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) (see <a href="chap21.html#X84D642967B8546B7"><span class="RefLink">21.12</span></a>).</p>
265
266 <p><code class="code"><var class="Arg">mat1</var> + <var class="Arg">mat2</var></code></p>
267
268 <p>returns the sum of the two matrices <var class="Arg">mat1</var> and <var class="Arg">mat2</var>, Probably the most usual situation is that <var class="Arg">mat1</var> and <var class="Arg">mat2</var> have the same dimensions and are defined over a common field; in this case the sum is a new matrix over the same field where each entry is the sum of the corresponding entries of the matrices.</p>
269
270 <p>In more general situations, the sum of two matrices need not be a matrix, for example adding an integer matrix <var class="Arg">mat1</var> and a matrix <var class="Arg">mat2</var> over a finite field yields the table of pointwise sums, which will be a mixture of finite field elements and integers if <var class="Arg">mat1</var> has bigger dimensions than <var class="Arg">mat2</var>.</p>
271
272 <p><code class="code"><var class="Arg">scalar</var> + <var class="Arg">mat</var></code></p>
273
274 <p><code class="code"><var class="Arg">mat</var> + <var class="Arg">scalar</var></code></p>
275
276 <p>returns the sum of the scalar <var class="Arg">scalar</var> and the matrix <var class="Arg">mat</var>. Probably the most usual situation is that the entries of <var class="Arg">mat</var> lie in a common field with <var class="Arg">scalar</var>; in this case the sum is a new matrix over the same field where each entry is the sum of the scalar and the corresponding entry of the matrix.</p>
277
278 <p>More general situations are for example the sum of an integer scalar and a matrix over a finite field, or the sum of a finite field element and an integer matrix.</p>
279
280 <p><code class="code"><var class="Arg">mat1</var> - <var class="Arg">mat2</var></code></p>
281
282 <p><code class="code"><var class="Arg">scalar</var> - <var class="Arg">mat</var></code></p>
283
284 <p><code class="code"><var class="Arg">mat</var> - <var class="Arg">scalar</var></code></p>
285
286 <p>Subtracting a matrix or scalar is defined as adding its additive inverse, so the statements for the addition hold likewise.</p>
287
288 <p><code class="code"><var class="Arg">scalar</var> * <var class="Arg">mat</var></code></p>
289
290 <p><code class="code"><var class="Arg">mat</var> * <var class="Arg">scalar</var></code></p>
291
292 <p>returns the product of the scalar <var class="Arg">scalar</var> and the matrix <var class="Arg">mat</var>. Probably the most usual situation is that the elements of <var class="Arg">mat</var> lie in a common field with <var class="Arg">scalar</var>; in this case the product is a new matrix over the same field where each entry is the product of the scalar and the corresponding entry of the matrix.</p>
293
294 <p>More general situations are for example the product of an integer scalar and a matrix over a finite field, or the product of a finite field element and an integer matrix.</p>
295
296 <p><code class="code"><var class="Arg">vec</var> * <var class="Arg">mat</var></code></p>
297
298 <p>returns the product of the row vector <var class="Arg">vec</var> and the matrix <var class="Arg">mat</var>. Probably the most usual situation is that <var class="Arg">vec</var> and <var class="Arg">mat</var> have the same lengths and are defined over a common field, and that all rows of <var class="Arg">mat</var> have some common length <span class="SimpleMath">m</span>; in this case the product is a new row vector of length <span class="SimpleMath">m</span> over the same field which is the sum of the scalar multiples of the rows of <var class="Arg">mat</var> with the corresponding entries of <var class="Arg">vec</var>.</p>
299
300 <p>More general situations are for example the product of an integer vector and a matrix over a finite field, or the product of a vector over a finite field and an integer matrix.</p>
301
302 <p><code class="code"><var class="Arg">mat</var> * <var class="Arg">vec</var></code></p>
303
304 <p>returns the product of the matrix <var class="Arg">mat</var> and the row vector <var class="Arg">vec</var>. (This is the standard product of a matrix with a <em>column</em> vector.) Probably the most usual situation is that the length of <var class="Arg">vec</var> and of all rows of <var class="Arg">mat</var> are equal, and that the elements of <var class="Arg">mat</var> and <var class="Arg">vec</var> lie in a common field; in this case the product is a new row vector of the same length as <var class="Arg">mat</var> and over the same field which is the sum of the scalar multiples of the columns of <var class="Arg">mat</var> with the corresponding entries of <var class="Arg">vec</var>.</p>
305
306 <p>More general situations are for example the product of an integer matrix and a vector over a finite field, or the product of a matrix over a finite field and an integer vector.</p>
307
308 <p><code class="code"><var class="Arg">mat1</var> * <var class="Arg">mat2</var></code></p>
309
310 <p>This form evaluates to the (Cauchy) product of the two matrices <var class="Arg">mat1</var> and <var class="Arg">mat2</var>. Probably the most usual situation is that the number of columns of <var class="Arg">mat1</var> equals the number of rows of <var class="Arg">mat2</var>, and that the elements of <var class="Arg">mat</var> and <var class="Arg">vec</var> lie in a common field; if <var class="Arg">mat1</var> is a matrix with <span class="SimpleMath">m</span> rows and <span class="SimpleMath">n</span> columns and <var class="Arg">mat2</var> is a matrix with <span class="SimpleMath">n</span> rows and <span class="SimpleMath">o</span> columns, the result is a new matrix with <span class="SimpleMath">m</span> rows and <span class="SimpleMath">o</span> columns. The element in row <span class="SimpleMath">i</span> at position <span class="SimpleMath">j</span> of the product is the sum of <span class="SimpleMath"><var class="Arg">mat1</var>[i][l] * <var class="Arg">mat2</var>[l][j]</span>, with <span class="SimpleMath">l</span> running from <span class="SimpleMath">1</span> to <span class="SimpleMath">n</span>.</p>
311
312 <p><code class="code">Inverse( <var class="Arg">mat</var> )</code></p>
313
314 <p>returns the inverse of the matrix <var class="Arg">mat</var>, which must be an invertible square matrix. If <var class="Arg">mat</var> is not invertible then <code class="keyw">fail</code> is returned.</p>
315
316 <p><code class="code"><var class="Arg">mat1</var> / <var class="Arg">mat2</var></code></p>
317
318 <p><code class="code"><var class="Arg">scalar</var> / <var class="Arg">mat</var></code></p>
319
320 <p><code class="code"><var class="Arg">mat</var> / <var class="Arg">scalar</var></code></p>
321
322 <p><code class="code"><var class="Arg">vec</var> / <var class="Arg">mat</var></code></p>
323
324 <p>In general, <code class="code"><var class="Arg">left</var> / <var class="Arg">right</var></code> is defined as <code class="code"><var class="Arg">left</var> * <var class="Arg">right</var>^-1</code>. Thus in the above forms the right operand must always be invertible.</p>
325
326 <p><code class="code"><var class="Arg">mat</var> ^ <var class="Arg">int</var></code></p>
327
328 <p><code class="code"><var class="Arg">mat1</var> ^ <var class="Arg">mat2</var></code></p>
329
330 <p><code class="code"><var class="Arg">vec</var> ^ <var class="Arg">mat</var></code></p>
331
332 <p>Powering a square matrix <var class="Arg">mat</var> by an integer <var class="Arg">int</var> yields the <var class="Arg">int</var>-th power of <var class="Arg">mat</var>; if <var class="Arg">int</var> is negative then <var class="Arg">mat</var> must be invertible, if <var class="Arg">int</var> is <code class="code">0</code> then the result is the identity matrix <code class="code">One( <var class="Arg">mat</var> )</code>, even if <var class="Arg">mat</var> is not invertible.</p>
333
334 <p>Powering a square matrix <var class="Arg">mat1</var> by an invertible square matrix <var class="Arg">mat2</var> of the same dimensions yields the conjugate of <var class="Arg">mat1</var> by <var class="Arg">mat2</var>, i.e., the matrix <code class="code"><var class="Arg">mat2</var>^-1 * <var class="Arg">mat1</var> * <var class="Arg">mat2</var></code>.</p>
335
336 <p>Powering a row vector <var class="Arg">vec</var> by a matrix <var class="Arg">mat</var> is in every respect equivalent to <code class="code"><var class="Arg">vec</var> * <var class="Arg">mat</var></code>. This operations reflects the fact that matrices act naturally on row vectors by multiplication from the right, and that the powering operator is <strong class="pkg">GAP</strong>'s standard for group actions.</p>
337
338 <p><code class="code">Comm( <var class="Arg">mat1</var>, <var class="Arg">mat2</var> )</code></p>
339
340 <p>returns the commutator of the square invertible matrices <var class="Arg">mat1</var> and <var class="Arg">mat2</var> of the same dimensions and over a common field, which is the matrix <code class="code"><var class="Arg">mat1</var>^-1 * <var class="Arg">mat2</var>^-1 * <var class="Arg">mat1</var> * <var class="Arg">mat2</var></code>.</p>
341
342 <p>The following cases are still special cases of the general list arithmetic defined in <a href="chap21.html#X845EEAF083D43CCE"><span class="RefLink">21.11</span></a>.</p>
343
344 <p><code class="code"><var class="Arg">scalar</var> + <var class="Arg">matlist</var></code></p>
345
346 <p><code class="code"><var class="Arg">matlist</var> + <var class="Arg">scalar</var></code></p>
347
348 <p><code class="code"><var class="Arg">scalar</var> - <var class="Arg">matlist</var></code></p>
349
350 <p><code class="code"><var class="Arg">matlist</var> - <var class="Arg">scalar</var></code></p>
351
352 <p><code class="code"><var class="Arg">scalar</var> * <var class="Arg">matlist</var></code></p>
353
354 <p><code class="code"><var class="Arg">matlist</var> * <var class="Arg">scalar</var></code></p>
355
356 <p><code class="code"><var class="Arg">matlist</var> / <var class="Arg">scalar</var></code></p>
357
358 <p>A scalar <var class="Arg">scalar</var> may also be added, subtracted, multiplied with, or divided into a list <var class="Arg">matlist</var> of matrices. The result is a new list of matrices where each matrix is the result of performing the operation with the corresponding matrix in <var class="Arg">matlist</var>.</p>
359
360 <p><code class="code"><var class="Arg">mat</var> * <var class="Arg">matlist</var></code></p>
361
362 <p><code class="code"><var class="Arg">matlist</var> * <var class="Arg">mat</var></code></p>
363
364 <p>A matrix <var class="Arg">mat</var> may also be multiplied with a list <var class="Arg">matlist</var> of matrices. The result is a new list of matrices, where each entry is the product of <var class="Arg">mat</var> and the corresponding entry in <var class="Arg">matlist</var>.</p>
365
366 <p><code class="code"><var class="Arg">matlist</var> / <var class="Arg">mat</var></code></p>
367
368 <p>Dividing a list <var class="Arg">matlist</var> of matrices by an invertible matrix <var class="Arg">mat</var> evaluates to <code class="code"><var class="Arg">matlist</var> * <var class="Arg">mat</var>^-1</code>.</p>
369
370 <p><code class="code"><var class="Arg">vec</var> * <var class="Arg">matlist</var></code></p>
371
372 <p>returns the product of the vector <var class="Arg">vec</var> and the list of matrices <var class="Arg">mat</var>. The lengths <var class="Arg">l</var> of <var class="Arg">vec</var> and <var class="Arg">matlist</var> must be equal. All matrices in <var class="Arg">matlist</var> must have the same dimensions. The elements of <var class="Arg">vec</var> and the elements of the matrices in <var class="Arg">matlist</var> must lie in a common ring. The product is the sum over <code class="code"><var class="Arg">vec</var>[<var class="Arg">i</var>] * <var class="Arg">matlist</var>[<var class="Arg">i</var>]</code> with <var class="Arg">i</var> running from 1 to <var class="Arg">l</var>.</p>
373
374 <p>For the mutability of results of arithmetic operations, see <a href="chap12.html#X7F0C119682196D65"><span class="RefLink">12.6</span></a>.</p>
375
376 <p><a id="X7F5AD28E869B66CB" name="X7F5AD28E869B66CB"></a></p>
377
378 <h4>24.4 <span class="Heading">Properties and Attributes of Matrices</span></h4>
379
380 <p><a id="X83A9DC2085D3A972" name="X83A9DC2085D3A972"></a></p>
381
382 <h5>24.4-1 DimensionsMat</h5>
383
384 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DimensionsMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
385 <p>is a list of length 2, the first being the number of rows, the second being the number of columns of the matrix <var class="Arg">mat</var>. If <var class="Arg">mat</var> is malformed, that is, it is not a <code class="func">IsRectangularTable</code> (<a href="chap21.html#X79581E0387F7F7A9"><span class="RefLink">21.1-5</span></a>), returns <code class="keyw">fail</code>.</p>
386
387
388 <div class="example"><pre>
389 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DimensionsMat([[1,2,3],[4,5,6]]);</span>
390 [ 2, 3 ]
391 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DimensionsMat([[1,2,3],[4,5]]);</span>
392 fail
393 </pre></div>
394
395 <p><a id="X80AE547B8095A5CB" name="X80AE547B8095A5CB"></a></p>
396
397 <h5>24.4-2 DefaultFieldOfMatrix</h5>
398
399 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DefaultFieldOfMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
400 <p>For a matrix <var class="Arg">mat</var>, <code class="func">DefaultFieldOfMatrix</code> returns either a field (not necessarily the smallest one) containing all entries of <var class="Arg">mat</var>, or <code class="keyw">fail</code>.</p>
401
402 <p>If <var class="Arg">mat</var> is a matrix of finite field elements or a matrix of cyclotomics, <code class="func">DefaultFieldOfMatrix</code> returns the default field generated by the matrix entries (see <a href="chap59.html#X81B54A8378734C33"><span class="RefLink">59.3</span></a> and <a href="chap18.html#X79E25C3085AA568F"><span class="RefLink">18.1</span></a>).</p>
403
404
405 <div class="example"><pre>
406 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DefaultFieldOfMatrix([[Z(4),Z(8)]]);</span>
407 GF(2^6)
408 </pre></div>
409
410 <p><a id="X784EC2777C06AFE4" name="X784EC2777C06AFE4"></a></p>
411
412 <h5>24.4-3 TraceMatrix</h5>
413
414 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TraceMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
415 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TraceMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
416 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Trace</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
417 <p>The trace of a square matrix is the sum of its diagonal entries.</p>
418
419
420 <div class="example"><pre>
421 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">TraceMatrix([[1,2,3],[4,5,6],[7,8,9]]);</span>
422 15
423 </pre></div>
424
425 <p><a id="X8488D69A7ADDB4E2" name="X8488D69A7ADDB4E2"></a></p>
426
427 <h5>24.4-4 DeterminantMatrix</h5>
428
429 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DeterminantMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
430 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DeterminantMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
431 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Determinant</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
432 <p>returns the determinant of the square matrix <var class="Arg">mat</var>.</p>
433
434 <p>These methods assume implicitly that <var class="Arg">mat</var> is defined over an integral domain whose quotient field is implemented in <strong class="pkg">GAP</strong>. For matrices defined over an arbitrary commutative ring with one see <code class="func">DeterminantMatDivFree</code> (<a href="chap24.html#X80693FAB7D541804"><span class="RefLink">24.4-6</span></a>).</p>
435
436 <p><a id="X824B5DC2875118B3" name="X824B5DC2875118B3"></a></p>
437
438 <h5>24.4-5 DeterminantMatrixDestructive</h5>
439
440 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DeterminantMatrixDestructive</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
441 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DeterminantMatDestructive</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
442 <p>Does the same as <code class="func">DeterminantMatrix</code> (<a href="chap24.html#X8488D69A7ADDB4E2"><span class="RefLink">24.4-4</span></a>), with the difference that it may destroy its argument. The matrix <var class="Arg">mat</var> must be mutable.</p>
443
444
445 <div class="example"><pre>
446 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DeterminantMatrix([[1,2],[2,1]]);</span>
447 -3
448 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm:= [[1,2],[2,1]];;</span>
449 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DeterminantMatrixDestructive( mm );</span>
450 -3
451 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm;</span>
452 [ [ 1, 2 ], [ 0, -3 ] ]
453 </pre></div>
454
455 <p><a id="X80693FAB7D541804" name="X80693FAB7D541804"></a></p>
456
457 <h5>24.4-6 DeterminantMatrixDivFree</h5>
458
459 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DeterminantMatrixDivFree</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
460 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DeterminantMatDivFree</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
461 <p>return the determinant of a square matrix <var class="Arg">mat</var> over an arbitrary commutative ring with one using the division free method of Mahajan and Vinay <a href="chapBib.html#biBMV97">[MV97]</a>.</p>
462
463 <p><a id="X7F8D25897EC1630B" name="X7F8D25897EC1630B"></a></p>
464
465 <h5>24.4-7 IsEmptyMatrix</h5>
466
467 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsEmptyMatrix</code>( <var class="Arg">M</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
468 <p>Returns: A boolean</p>
469
470 <p>Is <code class="keyw">true</code> if the matrix object <var class="Arg">M</var> either has zero columns or zero rows, and <code class="keyw">false</code> otherwise. In other words, a matrix object is empty if it has no entries.</p>
471
472 <p><a id="X848B80437CE65FF3" name="X848B80437CE65FF3"></a></p>
473
474 <h5>24.4-8 IsMonomialMatrix</h5>
475
476 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsMonomialMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
477 <p>A matrix is monomial if and only if it has exactly one nonzero entry in every row and every column.</p>
478
479
480 <div class="example"><pre>
481 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsMonomialMatrix([[0,1],[1,0]]);</span>
482 true
483 </pre></div>
484
485 <p><a id="X7EEC8E768178696E" name="X7EEC8E768178696E"></a></p>
486
487 <h5>24.4-9 IsDiagonalMatrix</h5>
488
489 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsDiagonalMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
490 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsDiagonalMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
491 <p>return <code class="keyw">true</code> if the matrix <var class="Arg">mat</var> has only zero entries off the main diagonal, and <code class="keyw">false</code> otherwise.</p>
492
493
494 <div class="example"><pre>
495 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsDiagonalMatrix( [ [ 1 ] ] );</span>
496 true
497 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsDiagonalMatrix( [ [ 1, 0, 0 ], [ 0, 1, 0 ] ] );</span>
498 true
499 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsDiagonalMatrix( [ [ 0, 1 ], [ 1, 0 ] ] );</span>
500 false
501 </pre></div>
502
503 <p><a id="X8740E71C799C0BCC" name="X8740E71C799C0BCC"></a></p>
504
505 <h5>24.4-10 IsUpperTriangularMatrix</h5>
506
507 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsUpperTriangularMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
508 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsUpperTriangularMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
509 <p>return <code class="keyw">true</code> if the matrix <var class="Arg">mat</var> has only zero entries below the main diagonal, and <code class="keyw">false</code> otherwise.</p>
510
511
512 <div class="example"><pre>
513 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsUpperTriangularMatrix( [ [ 1 ] ] );</span>
514 true
515 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsUpperTriangularMatrix( [ [ 1, 2, 3 ], [ 0, 5, 6 ] ] );</span>
516 true
517 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsUpperTriangularMatrix( [ [ 0, 1 ], [ 1, 0 ] ] );</span>
518 false
519 </pre></div>
520
521 <p><a id="X853A5B988306DBFE" name="X853A5B988306DBFE"></a></p>
522
523 <h5>24.4-11 IsLowerTriangularMatrix</h5>
524
525 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsLowerTriangularMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
526 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsLowerTriangularMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
527 <p>return <code class="keyw">true</code> if the matrix <var class="Arg">mat</var> has only zero entries above the main diagonal, and <code class="keyw">false</code> otherwise.</p>
528
529
530 <div class="example"><pre>
531 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsLowerTriangularMatrix( [ [ 1 ] ] );</span>
532 true
533 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsLowerTriangularMatrix( [ [ 1, 0, 0 ], [ 2, 3, 0 ] ] );</span>
534 true
535 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsLowerTriangularMatrix( [ [ 0, 1 ], [ 1, 0 ] ] );</span>
536 false
537 </pre></div>
538
539 <p><a id="X7FD5345487011416" name="X7FD5345487011416"></a></p>
540
541 <h5>24.4-12 IsSquareMatrix</h5>
542
543 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsSquareMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
544 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsSquareMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
545 <p>return <code class="keyw">true</code> if the matrix <var class="Arg">mat</var> has the same number of rows and columns, and <code class="keyw">false</code> otherwise.</p>
546
547
548 <div class="example"><pre>
549 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsSquareMatrix( [ [ 1 ] ] );</span>
550 true
551 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsSquareMatrix( [ [ 1, 2 ], [ 3, 4 ] ] );</span>
552 true
553 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsSquareMatrix( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );</span>
554 false
555 </pre></div>
556
557 <p><a id="X7ACD31A77E8458AA" name="X7ACD31A77E8458AA"></a></p>
558
559 <h5>24.4-13 IsSymmetricMatrix</h5>
560
561 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsSymmetricMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
562 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsSymmetricMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
563 <p>return <code class="keyw">true</code> if the matrix <var class="Arg">mat</var> is a square matrix and satisfies <code class="code"><var class="Arg">mat</var>[i,j] = <var class="Arg">mat</var>[j,i]</code> for all <span class="SimpleMath">i, j</span>, and <code class="keyw">false</code> otherwise.</p>
564
565
566 <div class="example"><pre>
567 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsSymmetricMatrix( [ [ 1 ] ] );</span>
568 true
569 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsSymmetricMatrix( [ [ 1, 2 ], [ 2, 1 ] ] );</span>
570 true
571 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsSymmetricMatrix( [ [ 0, 1 ], [ 2, 0 ] ] );</span>
572 false
573 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsSymmetricMatrix( [ [ 1, 2, 3 ], [ 2, 4, 5 ] ] );</span>
574 false
575 </pre></div>
576
577 <p><a id="X833DA1E07B0B23EF" name="X833DA1E07B0B23EF"></a></p>
578
579 <h5>24.4-14 IsAntisymmetricMatrix</h5>
580
581 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsAntisymmetricMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
582 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsAntisymmetricMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;property&nbsp;)</td></tr></table></div>
583 <p>return <code class="keyw">true</code> if the matrix <var class="Arg">mat</var> is a square matrix and satisfies <code class="code"><var class="Arg">mat</var>[i,j] = -<var class="Arg">mat</var>[j,i]</code> for all <span class="SimpleMath">i, j</span>, and <code class="keyw">false</code> otherwise. (In particular, the diagonal entries must be zero.)</p>
584
585
586 <div class="example"><pre>
587 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsAntisymmetricMatrix( [ [ 0 ] ] );</span>
588 true
589 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsAntisymmetricMatrix( [ [ 0, 1 ], [ -1, 0 ] ] );</span>
590 true
591 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsAntisymmetricMatrix( [ [ 0, 1 ], [ 1, 0 ] ] );</span>
592 false
593 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsAntisymmetricMatrix( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );</span>
594 false
595 </pre></div>
596
597 <p><a id="X823FB2398697B957" name="X823FB2398697B957"></a></p>
598
599 <h4>24.5 <span class="Heading">Matrix Constructions</span></h4>
600
601 <p><a id="X7DB902CE848D1524" name="X7DB902CE848D1524"></a></p>
602
603 <h5>24.5-1 IdentityMat</h5>
604
605 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IdentityMat</code>( <var class="Arg">m</var>[, <var class="Arg">R</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
606 <p>returns a (mutable) <var class="Arg">m</var><span class="SimpleMath">×</span><var class="Arg">m</var> identity matrix over the ring given by <var class="Arg">R</var>. Here, <var class="Arg">R</var> can be either a ring, or an element of a ring. By default, an integer matrix is created.</p>
607
608
609 <div class="example"><pre>
610 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IdentityMat(3);</span>
611 [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]
612 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IdentityMat(2,Integers mod 15);</span>
613 [ [ ZmodnZObj( 1, 15 ), ZmodnZObj( 0, 15 ) ],
614 [ ZmodnZObj( 0, 15 ), ZmodnZObj( 1, 15 ) ] ]
615 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IdentityMat(2,Z(3));</span>
616 [ [ Z(3)^0, 0*Z(3) ], [ 0*Z(3), Z(3)^0 ] ]
617 </pre></div>
618
619 <p><a id="X86D343A77D9B3D4D" name="X86D343A77D9B3D4D"></a></p>
620
621 <h5>24.5-2 NullMat</h5>
622
623 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NullMat</code>( <var class="Arg">m</var>, <var class="Arg">n</var>[, <var class="Arg">R</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
624 <p>returns a (mutable) <var class="Arg">m</var><span class="SimpleMath">×</span><var class="Arg">n</var> null matrix over the ring given by by <var class="Arg">R</var>. Here, <var class="Arg">R</var> can be either a ring, or an element of a ring. By default, an integer matrix is created.</p>
625
626
627 <div class="example"><pre>
628 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullMat(3,2);</span>
629 [ [ 0, 0 ], [ 0, 0 ], [ 0, 0 ] ]
630 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullMat(2,2,Integers mod 15);</span>
631 [ [ ZmodnZObj( 0, 15 ), ZmodnZObj( 0, 15 ) ],
632 [ ZmodnZObj( 0, 15 ), ZmodnZObj( 0, 15 ) ] ]
633 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullMat(3,2,Z(3));</span>
634 [ [ 0*Z(3), 0*Z(3) ], [ 0*Z(3), 0*Z(3) ], [ 0*Z(3), 0*Z(3) ] ]
635 </pre></div>
636
637 <p><a id="X8508A7EA812BA0CC" name="X8508A7EA812BA0CC"></a></p>
638
639 <h5>24.5-3 EmptyMatrix</h5>
640
641 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; EmptyMatrix</code>( <var class="Arg">char</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
642 <p>is an empty (ordinary) matrix in characteristic <var class="Arg">char</var> that can be added to or multiplied with empty lists (representing zero-dimensional row vectors). It also acts (via the operation <code class="func">\^</code> (<a href="chap31.html#X8481C9B97B214C23"><span class="RefLink">31.12-1</span></a>)) on empty lists.</p>
643
644
645 <div class="example"><pre>
646 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">EmptyMatrix(5);</span>
647 EmptyMatrix( 5 )
648 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">AsList(last);</span>
649 [ ]
650 </pre></div>
651
652 <p><a id="X81042E7A7F247ADE" name="X81042E7A7F247ADE"></a></p>
653
654 <h5>24.5-4 DiagonalMat</h5>
655
656 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DiagonalMat</code>( <var class="Arg">vector</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
657 <p>returns a diagonal matrix <var class="Arg">mat</var> with the diagonal entries given by <var class="Arg">vector</var>.</p>
658
659
660 <div class="example"><pre>
661 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DiagonalMat([1,2,3]);</span>
662 [ [ 1, 0, 0 ], [ 0, 2, 0 ], [ 0, 0, 3 ] ]
663 </pre></div>
664
665 <p><a id="X87BADF217C19CBE1" name="X87BADF217C19CBE1"></a></p>
666
667 <h5>24.5-5 DiagonalMatrix</h5>
668
669 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DiagonalMatrix</code>( [<var class="Arg">filt</var>, ]<var class="Arg">R</var>, <var class="Arg">vector</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
670 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DiagonalMatrix</code>( <var class="Arg">vector</var>[, <var class="Arg">M</var>] )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
671 <p>Returns: a square matrix or matrix object with column number equal to the length of the dense list <var class="Arg">vector</var>, whose diagonal entries are given by the entries of <var class="Arg">vector</var>, and whose off-diagonal entries are zero.</p>
672
673 <p>If a semiring <var class="Arg">R</var> is given then it will be the base domain (see <code class="func">BaseDomain</code> (<a href="chap26.html#X8662026C7CCDB446"><span class="RefLink">26.3-1</span></a>)) of the returned matrix. In this case, a filter <var class="Arg">filt</var> can be specified that defines the internal representation of the result (see <code class="func">ConstructingFilter</code> (<a href="chap26.html#X85ABF33684865ED5"><span class="RefLink">26.3-2</span></a>)). The default value for <var class="Arg">filt</var> is determined from <var class="Arg">R</var>.</p>
674
675 <p>If a matrix object <var class="Arg">M</var> is given then the returned matrix will have the same internal representation and the same base domain as <var class="Arg">M</var>.</p>
676
677 <p>If only <var class="Arg">vector</var> is given then it is used to compute a default for <var class="Arg">R</var>.</p>
678
679 <p>If the <code class="func">ConstructingFilter</code> (<a href="chap26.html#X85ABF33684865ED5"><span class="RefLink">26.3-2</span></a>) value of the result implies <code class="func">IsCopyable</code> (<a href="chap12.html#X811EFD727EBD1ADC"><span class="RefLink">12.6-1</span></a>) then the result is fully mutable.</p>
680
681
682 <div class="example"><pre>
683 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">d1:= DiagonalMatrix( GF(9), [ 1, 2 ] * Z(3)^0 );</span>
684 [ [ Z(3)^0, 0*Z(3) ], [ 0*Z(3), Z(3) ] ]
685 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Is8BitMatrixRep( d1 );</span>
686 true
687 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">d2:= DiagonalMatrix( IsPlistMatrixRep, GF(9), [ 1, 2 ] * Z(3)^0 );</span>
688 &lt;2x2-matrix over GF(3^2)&gt;
689 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsPlistMatrixRep( d2 );</span>
690 true
691 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DiagonalMatrix( [ 1, 2 ] );</span>
692 &lt;2x2-matrix over Rationals&gt;
693 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DiagonalMatrix( [ 1, 2 ], Matrix( Integers, [ [ 1 ] ], 1 ) );</span>
694 &lt;2x2-matrix over Integers&gt;
695 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DiagonalMatrix( [ 1, 2 ], [ [ 1 ] ] );</span>
696 [ [ 1, 0 ], [ 0, 2 ] ]
697 </pre></div>
698
699 <p><a id="X806C62A67A7D5379" name="X806C62A67A7D5379"></a></p>
700
701 <h5>24.5-6 PermutationMat</h5>
702
703 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PermutationMat</code>( <var class="Arg">perm</var>, <var class="Arg">dim</var>[, <var class="Arg">F</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
704 <p>returns a matrix in dimension <var class="Arg">dim</var> over the field given by <var class="Arg">F</var> (i.e. the smallest field containing the element <var class="Arg">F</var> or <var class="Arg">F</var> itself if it is a field) that represents the permutation <var class="Arg">perm</var> acting by permuting the basis vectors as it permutes points.</p>
705
706
707 <div class="example"><pre>
708 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PermutationMat((1,2,3),4,1);</span>
709 [ [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 1, 0, 0, 0 ], [ 0, 0, 0, 1 ] ]
710 </pre></div>
711
712 <p><a id="X7C52A38C79C36C35" name="X7C52A38C79C36C35"></a></p>
713
714 <h5>24.5-7 TransposedMatImmutable</h5>
715
716 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TransposedMatImmutable</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
717 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TransposedMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
718 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TransposedMatMutable</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
719 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TransposedMatOp</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
720 <p>These functions all return the transposed of the matrix object <var class="Arg">mat</var>, i.e., a matrix object <span class="SimpleMath">trans</span> such that <span class="SimpleMath">trans[i,k] = <var class="Arg">mat</var>[k,i]</span> holds.</p>
721
722 <p>They differ only w.r.t. the mutability of the result.</p>
723
724 <p><code class="func">TransposedMat</code> is an attribute and hence returns an immutable result. <code class="func">TransposedMatMutable</code> is guaranteed to return a new <em>mutable</em> matrix.</p>
725
726 <p><code class="func">TransposedMatImmutable</code> is a synonym of <code class="func">TransposedMat</code>, and <code class="func">TransposedMatOp</code> is a synonym of <code class="func">TransposedMatMutable</code>, in analogy to operations such as <code class="func">Zero</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>).</p>
727
728 <p><a id="X7DBB40847E2B6252" name="X7DBB40847E2B6252"></a></p>
729
730 <h5>24.5-8 TransposedMatDestructive</h5>
731
732 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TransposedMatDestructive</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
733 <p>If <var class="Arg">mat</var> is a mutable matrix, then the transposed is computed by swapping the entries in <var class="Arg">mat</var>. In this way <var class="Arg">mat</var> gets changed. In all other cases the transposed is computed by <code class="func">TransposedMat</code> (<a href="chap24.html#X7C52A38C79C36C35"><span class="RefLink">24.5-7</span></a>).</p>
734
735
736 <div class="example"><pre>
737 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">TransposedMat([[1,2,3],[4,5,6],[7,8,9]]);</span>
738 [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]
739 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm:= [[1,2,3],[4,5,6],[7,8,9]];;</span>
740 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">TransposedMatDestructive( mm );</span>
741 [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]
742 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm;</span>
743 [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]
744 </pre></div>
745
746 <p><a id="X8634C79E7DB22934" name="X8634C79E7DB22934"></a></p>
747
748 <h5>24.5-9 KroneckerProduct</h5>
749
750 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; KroneckerProduct</code>( <var class="Arg">mat1</var>, <var class="Arg">mat2</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
751 <p>The Kronecker product of two matrices is the matrix obtained when replacing each entry <var class="Arg">a</var> of <var class="Arg">mat1</var> by the product <code class="code"><var class="Arg">a</var>*<var class="Arg">mat2</var></code> in one matrix.</p>
752
753
754 <div class="example"><pre>
755 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">KroneckerProduct([[1,2]],[[5,7],[9,2]]);</span>
756 [ [ 5, 7, 10, 14 ], [ 9, 2, 18, 4 ] ]
757 </pre></div>
758
759 <p><a id="X845EC4D18054D140" name="X845EC4D18054D140"></a></p>
760
761 <h5>24.5-10 ReflectionMat</h5>
762
763 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ReflectionMat</code>( <var class="Arg">coeffs</var>[, <var class="Arg">conj</var>][, <var class="Arg">root</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
764 <p>Let <var class="Arg">coeffs</var> be a row vector. <code class="func">ReflectionMat</code> returns the matrix of the reflection in this vector.</p>
765
766 <p>More precisely, if <var class="Arg">coeffs</var> is the coefficients list of a vector <span class="SimpleMath">v</span> w.r.t. a basis <span class="SimpleMath">B</span> (see <code class="func">Basis</code> (<a href="chap61.html#X837BE54C80DE368E"><span class="RefLink">61.5-2</span></a>)) then the returned matrix describes the reflection in <span class="SimpleMath">v</span> w.r.t. <span class="SimpleMath">B</span> as a map on a row space, with action from the right.</p>
767
768 <p>The optional argument <var class="Arg">root</var> is a root of unity that determines the order of the reflection. The default is a reflection of order 2. For triflections one should choose a third root of unity etc. (see <code class="func">E</code> (<a href="chap18.html#X8631458886314588"><span class="RefLink">18.1-1</span></a>)).</p>
769
770 <p><var class="Arg">conj</var> is a function of one argument that conjugates a ring element. The default is <code class="func">ComplexConjugate</code> (<a href="chap18.html#X7BE001A0811CD599"><span class="RefLink">18.5-2</span></a>).</p>
771
772 <p>The matrix of the reflection in <span class="SimpleMath">v</span> is defined as</p>
773
774 <p class="pcenter">M = I_n + <var class="Arg">conj</var>(v^tr) ⋅ (<var class="Arg">root</var>-1) / (v ⋅ <var class="Arg">conj</var>(v^tr)) ⋅ v</p>
775
776 <p>where <span class="SimpleMath">n</span> is the length of the coefficient list.</p>
777
778 <p>So <span class="SimpleMath">v</span> is mapped to <var class="Arg">root</var><span class="SimpleMath">⋅ v</span>, with default <span class="SimpleMath">-v</span>, and any vector <span class="SimpleMath">x</span> with the property <span class="SimpleMath">x ⋅</span><var class="Arg">conj</var><span class="SimpleMath">(v^tr) = 0</span> is fixed by the reflection.</p>
779
780 <p><a id="X7DEBC9967DFDFC18" name="X7DEBC9967DFDFC18"></a></p>
781
782 <h5>24.5-11 PrintArray</h5>
783
784 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PrintArray</code>( <var class="Arg">array</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
785 <p>pretty-prints the array <var class="Arg">array</var>.</p>
786
787 <p><a id="X79CC5F568252D341" name="X79CC5F568252D341"></a></p>
788
789 <h4>24.6 <span class="Heading">Random Matrices</span></h4>
790
791 <p><a id="X7F957F0280A87961" name="X7F957F0280A87961"></a></p>
792
793 <h5>24.6-1 RandomMat</h5>
794
795 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RandomMat</code>( [<var class="Arg">rs</var>, ]<var class="Arg">m</var>, <var class="Arg">n</var>[, <var class="Arg">R</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
796 <p><code class="func">RandomMat</code> returns a new mutable random matrix with <var class="Arg">m</var> rows and <var class="Arg">n</var> columns with elements taken from the ring <var class="Arg">R</var>, which defaults to <code class="func">Integers</code> (<a href="chap14.html#X853DF11B80068ED5"><span class="RefLink">14</span></a>). Optionally, a random source <var class="Arg">rs</var> can be supplied.</p>
797
798
799 <div class="example"><pre>
800 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RandomMat(2,3,GF(3));</span>
801 [ [ Z(3), Z(3), 0*Z(3) ], [ Z(3), Z(3)^0, Z(3) ] ]
802 </pre></div>
803
804 <p><a id="X7D31ACA4809B321B" name="X7D31ACA4809B321B"></a></p>
805
806 <h5>24.6-2 RandomMatrix</h5>
807
808 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RandomMatrix</code>( [<var class="Arg">filt</var>, ][<var class="Arg">rs</var>, ]<var class="Arg">R</var>, <var class="Arg">m</var>, <var class="Arg">n</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
809 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RandomMatrix</code>( [<var class="Arg">rs</var>, ]<var class="Arg">m</var>, <var class="Arg">n</var>, <var class="Arg">M</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
810 <p>Returns: a matrix or matrix object with <var class="Arg">m</var> rows and <var class="Arg">n</var> columns, with base domain <var class="Arg">R</var> or equal to <code class="code">BaseDomain( <var class="Arg">M</var> )</code>.</p>
811
812 <p>If a semiring <var class="Arg">R</var> is given then it will be the base domain (see <code class="func">BaseDomain</code> (<a href="chap26.html#X8662026C7CCDB446"><span class="RefLink">26.3-1</span></a>)) of the returned matrix. In this case, a filter <var class="Arg">filt</var> can be specified that defines the internal representation of the result (see <code class="func">ConstructingFilter</code> (<a href="chap26.html#X85ABF33684865ED5"><span class="RefLink">26.3-2</span></a>)). The default value for <var class="Arg">filt</var> is determined from <var class="Arg">R</var>.</p>
813
814 <p>If a matrix object <var class="Arg">M</var> is given then the returned matrix will have the same internal representation and the same base domain as <var class="Arg">M</var>.</p>
815
816 <p>If a random source <var class="Arg">rs</var> is given (see <a href="chap14.html#X85361FAE8088C006"><span class="RefLink">14.7</span></a>) then the entries of the result are computed using <var class="Arg">rs</var>, the default random source is <code class="func">GlobalMersenneTwister</code> (<a href="chap14.html#X7AC96008820FAF1F"><span class="RefLink">14.7-4</span></a>).</p>
817
818 <p>If the <code class="func">ConstructingFilter</code> (<a href="chap26.html#X85ABF33684865ED5"><span class="RefLink">26.3-2</span></a>) value of the result implies <code class="func">IsCopyable</code> (<a href="chap12.html#X811EFD727EBD1ADC"><span class="RefLink">12.6-1</span></a>) then the result is fully mutable.</p>
819
820
821 <div class="example"><pre>
822 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m:= RandomMatrix( GF(9), 2, 3 );;</span>
823 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DimensionsMat( m );</span>
824 [ 2, 3 ]
825 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BaseDomain( m );</span>
826 GF(3^2)
827 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Is8BitMatrixRep( m );</span>
828 true
829 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m1:= RandomMatrix( IsPlistMatrixRep, GF(9), 2, 3 );;</span>
830 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsPlistMatrixRep( m1 );</span>
831 true
832 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m2:= RandomMatrix( 3, 4, m1 );;</span>
833 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DimensionsMat( m2 );</span>
834 [ 3, 4 ]
835 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsPlistMatrixRep( m2 );</span>
836 true
837 </pre></div>
838
839 <p><a id="X7C939B4A7EDF015D" name="X7C939B4A7EDF015D"></a></p>
840
841 <h5>24.6-3 RandomInvertibleMat</h5>
842
843 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RandomInvertibleMat</code>( [<var class="Arg">rs</var>, ]<var class="Arg">m</var>[, <var class="Arg">R</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
844 <p><code class="func">RandomInvertibleMat</code> returns a new mutable invertible random matrix with <var class="Arg">m</var> rows and columns with elements taken from the ring <var class="Arg">R</var>, which defaults to <code class="func">Integers</code> (<a href="chap14.html#X853DF11B80068ED5"><span class="RefLink">14</span></a>). Optionally, a random source <var class="Arg">rs</var> can be supplied.</p>
845
846 <p>Note that the result need <em>not</em> be invertible over the prescribed ring <var class="Arg">R</var>. Use <code class="func">RandomInvertibleMatrix</code> (<a href="chap24.html#X8743657384B15B5B"><span class="RefLink">24.6-4</span></a>) for creating random matrices with this stronger property.</p>
847
848
849 <div class="example"><pre>
850 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := RandomInvertibleMat( 4, Integers );</span>
851 [ [ 1, -4, 0, 1 ], [ 0, -2, 3, 1 ], [ 0, -2, -1, -1 ],
852 [ 0, -2, 2, 4 ] ]
853 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m^-1;</span>
854 [ [ 1, -1/14, -19/14, -4/7 ], [ 0, -1/14, -5/14, -1/14 ],
855 [ 0, 5/14, -3/14, -1/7 ], [ 0, -3/14, -1/14, 2/7 ] ]
856 </pre></div>
857
858 <p><a id="X8743657384B15B5B" name="X8743657384B15B5B"></a></p>
859
860 <h5>24.6-4 RandomInvertibleMatrix</h5>
861
862 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RandomInvertibleMatrix</code>( [<var class="Arg">filt</var>, ][<var class="Arg">rs</var>, ]<var class="Arg">R</var>, <var class="Arg">m</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
863 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RandomInvertibleMatrix</code>( [<var class="Arg">rs</var>, ]<var class="Arg">m</var>, <var class="Arg">M</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
864 <p>Returns: a matrix or matrix object <span class="SimpleMath">I</span> with <var class="Arg">m</var> columns, with base domain <var class="Arg">R</var> or equal to <code class="code">BaseDomain( <var class="Arg">M</var> )</code>, such that <span class="SimpleMath">I</span> is invertible over its base domain.</p>
865
866 <p>If a semiring <var class="Arg">R</var> is given then it will be the base domain (see <code class="func">BaseDomain</code> (<a href="chap26.html#X8662026C7CCDB446"><span class="RefLink">26.3-1</span></a>)) of the returned matrix. In this case, a filter <var class="Arg">filt</var> can be specified that defines the internal representation of the result (see <code class="func">ConstructingFilter</code> (<a href="chap26.html#X85ABF33684865ED5"><span class="RefLink">26.3-2</span></a>)). The default value for <var class="Arg">filt</var> is determined from <var class="Arg">R</var>.</p>
867
868 <p>If a matrix object <var class="Arg">M</var> is given then the returned matrix will have the same internal representation and the same base domain as <var class="Arg">M</var>.</p>
869
870 <p>If a random source <var class="Arg">rs</var> is given (see <a href="chap14.html#X85361FAE8088C006"><span class="RefLink">14.7</span></a>) then the entries of the result are computed using <var class="Arg">rs</var>, the default random source is <code class="func">GlobalMersenneTwister</code> (<a href="chap14.html#X7AC96008820FAF1F"><span class="RefLink">14.7-4</span></a>).</p>
871
872 <p>If the <code class="func">ConstructingFilter</code> (<a href="chap26.html#X85ABF33684865ED5"><span class="RefLink">26.3-2</span></a>) value of the result implies <code class="func">IsCopyable</code> (<a href="chap12.html#X811EFD727EBD1ADC"><span class="RefLink">12.6-1</span></a>) then the result is fully mutable.</p>
873
874
875 <div class="example"><pre>
876 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m:= RandomInvertibleMatrix( GF(9), 2 );;</span>
877 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RankMatrix( m );</span>
878 2
879 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DimensionsMat( m );</span>
880 [ 2, 2 ]
881 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BaseDomain( m );</span>
882 GF(3^2)
883 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Is8BitMatrixRep( m );</span>
884 true
885 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m1:= RandomInvertibleMatrix( IsPlistMatrixRep, GF(9), 2 );;</span>
886 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsPlistMatrixRep( m1 );</span>
887 true
888 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m2:= RandomInvertibleMatrix( 2, m1 );;</span>
889 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsPlistMatrixRep( m2 );</span>
890 true
891 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m:= RandomInvertibleMatrix( Integers, 2 );;</span>
892 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsUnit( Integers, DeterminantMatrix( m ) );</span>
893 true
894 </pre></div>
895
896 <p><a id="X84743732846ACB44" name="X84743732846ACB44"></a></p>
897
898 <h5>24.6-5 RandomUnimodularMat</h5>
899
900 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RandomUnimodularMat</code>( [<var class="Arg">rs</var>, ]<var class="Arg">m</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
901 <p>returns a new random mutable <var class="Arg">m</var><span class="SimpleMath">×</span><var class="Arg">m</var> matrix with integer entries that is invertible over the integers. Optionally, a random source <var class="Arg">rs</var> can be supplied. If the option <var class="Arg">domain</var> is given, random selection is made from <var class="Arg">domain</var>, otherwise from <var class="Arg">Integers</var></p>
902
903
904 <div class="example"><pre>
905 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := RandomUnimodularMat(3);</span>
906 [ [ 1, -5, 26 ], [ 0, 1, -6 ], [ 0, 0, 1 ] ]
907 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m^-1;</span>
908 [ [ 1, 5, 4 ], [ 0, 1, 6 ], [ 0, 0, 1 ] ]
909 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RandomUnimodularMat(3:domain:=[-1000..1000]);</span>
910 [ [ 6001314, 239514853714734, -44705745791413 ],
911 [ -1448123744, -57795200635226587, 10787546189680040 ],
912 [ -671, -26780118200, 4998542420 ] ]
913 </pre></div>
914
915 <p><a id="X85485DCE809E323A" name="X85485DCE809E323A"></a></p>
916
917 <h4>24.7 <span class="Heading">Matrices Representing Linear Equations and the Gaussian Algorithm</span></h4>
918
919 <p><a id="X7A995A74838950E6" name="X7A995A74838950E6"></a></p>
920
921 <h5>24.7-1 RankMatrix</h5>
922
923 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RankMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
924 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RankMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
925 <p>If <var class="Arg">mat</var> is a matrix object representing a matrix whose rows span a free module over the ring generated by the matrix entries and their inverses then <code class="func">RankMatrix</code> returns the dimension of this free module. Otherwise <code class="keyw">fail</code> is returned.</p>
926
927 <p>Note that <code class="func">RankMatrix</code> may perform a Gaussian elimination. For large rational matrices this may take very long, because the entries may become very large.</p>
928
929
930 <div class="example"><pre>
931 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
932 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RankMatrix( mat );</span>
933 2
934 </pre></div>
935
936 <p><a id="X7BA26C3387AB434E" name="X7BA26C3387AB434E"></a></p>
937
938 <h5>24.7-2 TriangulizedMat</h5>
939
940 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TriangulizedMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
941 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RREF</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
942 <p>Computes an upper triangular form of the matrix <var class="Arg">mat</var> via the Gaussian Algorithm. It returns a mutable matrix in upper triangular form. This is sometimes also called <q>Hermite normal form</q> or <q>Reduced Row Echelon Form</q>. <code class="code">RREF</code> is a synonym for <code class="code">TriangulizedMat</code>.</p>
943
944 <p><a id="X8384CA8E7B3850D3" name="X8384CA8E7B3850D3"></a></p>
945
946 <h5>24.7-3 TriangulizeMat</h5>
947
948 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TriangulizeMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
949 <p>Applies the Gaussian Algorithm to the mutable matrix <var class="Arg">mat</var> and changes <var class="Arg">mat</var> such that it is in upper triangular normal form (sometimes called <q>Hermite normal form</q> or <q>Reduced Row Echelon Form</q>).</p>
950
951
952 <div class="example"><pre>
953 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m:=TransposedMatMutable(mat);</span>
954 [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]
955 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">TriangulizeMat(m);m;</span>
956 [ [ 1, 0, -1 ], [ 0, 1, 2 ], [ 0, 0, 0 ] ]
957 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m:=TransposedMatMutable(mat);</span>
958 [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]
959 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">TriangulizedMat(m);m;</span>
960 [ [ 1, 0, -1 ], [ 0, 1, 2 ], [ 0, 0, 0 ] ]
961 [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]
962 </pre></div>
963
964 <p><a id="X7DA0D5887DB12DC4" name="X7DA0D5887DB12DC4"></a></p>
965
966 <h5>24.7-4 NullspaceMat</h5>
967
968 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NullspaceMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
969 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TriangulizedNullspaceMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
970 <p>returns a list of row vectors that form a basis of the vector space of solutions to the equation <code class="code"><var class="Arg">vec</var>*<var class="Arg">mat</var>=0</code>. The result is an immutable matrix. This basis is not guaranteed to be in any specific form.</p>
971
972 <p>The variant <code class="func">TriangulizedNullspaceMat</code> returns a basis of the nullspace in triangulized form as is often needed for algorithms.</p>
973
974 <p><a id="X87684B0F7AB7B7DB" name="X87684B0F7AB7B7DB"></a></p>
975
976 <h5>24.7-5 NullspaceMatDestructive</h5>
977
978 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NullspaceMatDestructive</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
979 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TriangulizedNullspaceMatDestructive</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
980 <p>This function does the same as <code class="func">NullspaceMat</code> (<a href="chap24.html#X7DA0D5887DB12DC4"><span class="RefLink">24.7-4</span></a>). However, the latter function makes a copy of <var class="Arg">mat</var> to avoid having to change it. This function does not do that; it returns the nullspace and may destroy <var class="Arg">mat</var>; this saves a lot of memory in case <var class="Arg">mat</var> is big. The matrix <var class="Arg">mat</var> must be mutable.</p>
981
982 <p>The variant <code class="func">TriangulizedNullspaceMatDestructive</code> returns a basis of the nullspace in triangulized form. It may destroy the matrix <var class="Arg">mat</var>.</p>
983
984
985 <div class="example"><pre>
986 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
987 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullspaceMat(mat);</span>
988 [ [ 1, -2, 1 ] ]
989 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
990 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullspaceMatDestructive( mm );</span>
991 [ [ 1, -2, 1 ] ]
992 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm;</span>
993 [ [ 1, 2, 3 ], [ 0, -3, -6 ], [ 0, 0, 0 ] ]
994 </pre></div>
995
996 <p><a id="X838A519C7CD2969E" name="X838A519C7CD2969E"></a></p>
997
998 <h5>24.7-6 SolutionMat</h5>
999
1000 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SolutionMat</code>( <var class="Arg">mat</var>, <var class="Arg">vec</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1001 <p>returns a row vector <var class="Arg">x</var> that is a solution of the equation <code class="code"><var class="Arg">x</var> * <var class="Arg">mat</var> = <var class="Arg">vec</var></code>. It returns <code class="keyw">fail</code> if no such vector exists.</p>
1002
1003 <p><a id="X7A7880D27CE7C1FE" name="X7A7880D27CE7C1FE"></a></p>
1004
1005 <h5>24.7-7 SolutionMatDestructive</h5>
1006
1007 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SolutionMatDestructive</code>( <var class="Arg">mat</var>, <var class="Arg">vec</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1008 <p>Does the same as <code class="code">SolutionMat( <var class="Arg">mat</var>, <var class="Arg">vec</var> )</code> except that it may destroy the matrix <var class="Arg">mat</var> and the vector <var class="Arg">vec</var>. The matrix <var class="Arg">mat</var> must be mutable.</p>
1009
1010
1011 <div class="example"><pre>
1012 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
1013 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SolutionMat(mat,[3,5,7]);</span>
1014 [ 5/3, 1/3, 0 ]
1015 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm:= [[1,2,3],[4,5,6],[7,8,9]];;</span>
1016 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">v:= [3,5,7];;</span>
1017 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SolutionMatDestructive( mm, v );</span>
1018 [ 5/3, 1/3, 0 ]
1019 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm;</span>
1020 [ [ 1, 2, 3 ], [ 0, -3, -6 ], [ 0, 0, 0 ] ]
1021 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">v;</span>
1022 [ 0, 0, 0 ]
1023 </pre></div>
1024
1025 <p><a id="X7AB5AC547809F999" name="X7AB5AC547809F999"></a></p>
1026
1027 <h5>24.7-8 BaseFixedSpace</h5>
1028
1029 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BaseFixedSpace</code>( <var class="Arg">mats</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1030 <p><code class="func">BaseFixedSpace</code> returns a list of row vectors that form a base of the vector space <span class="SimpleMath">V</span> such that <span class="SimpleMath">v M = v</span> for all <span class="SimpleMath">v</span> in <span class="SimpleMath">V</span> and all matrices <span class="SimpleMath">M</span> in the list <var class="Arg">mats</var>. (This is the common eigenspace of all matrices in <var class="Arg">mats</var> for the eigenvalue 1.)</p>
1031
1032
1033 <div class="example"><pre>
1034 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BaseFixedSpace([[[1,2],[0,1]]]);</span>
1035 [ [ 0, 1 ] ]
1036 </pre></div>
1037
1038 <p><a id="X871FCAA97C60B2BA" name="X871FCAA97C60B2BA"></a></p>
1039
1040 <h4>24.8 <span class="Heading">Eigenvectors and eigenvalues</span></h4>
1041
1042 <p><a id="X7A2462CC7B0C9D66" name="X7A2462CC7B0C9D66"></a></p>
1043
1044 <h5>24.8-1 GeneralisedEigenvalues</h5>
1045
1046 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; GeneralisedEigenvalues</code>( <var class="Arg">F</var>, <var class="Arg">A</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1047 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; GeneralizedEigenvalues</code>( <var class="Arg">F</var>, <var class="Arg">A</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1048 <p>The generalised eigenvalues of the matrix <var class="Arg">A</var> over the field <var class="Arg">F</var>.</p>
1049
1050 <p><a id="X845CA0457D65876D" name="X845CA0457D65876D"></a></p>
1051
1052 <h5>24.8-2 GeneralisedEigenspaces</h5>
1053
1054 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; GeneralisedEigenspaces</code>( <var class="Arg">F</var>, <var class="Arg">A</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1055 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; GeneralizedEigenspaces</code>( <var class="Arg">F</var>, <var class="Arg">A</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1056 <p>The generalised eigenspaces of the matrix <var class="Arg">A</var> over the field <var class="Arg">F</var>.</p>
1057
1058 <p><a id="X8413C6FB7CEE9D59" name="X8413C6FB7CEE9D59"></a></p>
1059
1060 <h5>24.8-3 Eigenvalues</h5>
1061
1062 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Eigenvalues</code>( <var class="Arg">F</var>, <var class="Arg">A</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1063 <p>The eigenvalues of the matrix <var class="Arg">A</var> over the field <var class="Arg">F</var>.</p>
1064
1065 <p><a id="X7A6B047281B52FD7" name="X7A6B047281B52FD7"></a></p>
1066
1067 <h5>24.8-4 Eigenspaces</h5>
1068
1069 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Eigenspaces</code>( <var class="Arg">F</var>, <var class="Arg">A</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1070 <p>The eigenspaces of the matrix <var class="Arg">A</var> over the field <var class="Arg">F</var>.</p>
1071
1072 <p><a id="X8506584579D4EA18" name="X8506584579D4EA18"></a></p>
1073
1074 <h5>24.8-5 Eigenvectors</h5>
1075
1076 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Eigenvectors</code>( <var class="Arg">F</var>, <var class="Arg">A</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1077 <p>The eigenvectors of the matrix <var class="Arg">A</var> over the field <var class="Arg">F</var>.</p>
1078
1079 <p><a id="X7E5405D085661B29" name="X7E5405D085661B29"></a></p>
1080
1081 <h4>24.9 <span class="Heading">Elementary Divisors</span></h4>
1082
1083 <p>See also chapter <a href="chap25.html#X8414F20D8412DDA4"><span class="RefLink">25</span></a>.</p>
1084
1085 <p><a id="X7AC4D74F81908109" name="X7AC4D74F81908109"></a></p>
1086
1087 <h5>24.9-1 ElementaryDivisorsMat</h5>
1088
1089 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ElementaryDivisorsMat</code>( [<var class="Arg">ring</var>, ]<var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1090 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ElementaryDivisorsMatDestructive</code>( <var class="Arg">ring</var>, <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1091 <p>returns a list of the elementary divisors, i.e., the unique <span class="SimpleMath">d</span> with <span class="SimpleMath">d[i]</span> divides <span class="SimpleMath">d[i+1]</span> and <var class="Arg">mat</var> is equivalent to a diagonal matrix with the elements <span class="SimpleMath">d[i]</span> on the diagonal. The operations are performed over the euclidean ring <var class="Arg">ring</var>, which must contain all matrix entries. For compatibility reasons it can be omitted and defaults to the <code class="func">DefaultRing</code> (<a href="chap56.html#X83AFFCC77DE6ABDA"><span class="RefLink">56.1-3</span></a>) of the matrix entries.</p>
1092
1093 <p>The function <code class="func">ElementaryDivisorsMatDestructive</code> produces the same result but in the process may destroy the contents of <var class="Arg">mat</var>.</p>
1094
1095
1096 <div class="example"><pre>
1097 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
1098 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ElementaryDivisorsMat(mat);</span>
1099 [ 1, 3, 0 ]
1100 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">x:=Indeterminate(Rationals,"x");;</span>
1101 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=mat*One(x)-x*mat^0;</span>
1102 [ [ -x+1, 2, 3 ], [ 4, -x+5, 6 ], [ 7, 8, -x+9 ] ]
1103 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ElementaryDivisorsMat(PolynomialRing(Rationals,1),mat);</span>
1104 [ 1, 1, x^3-15*x^2-18*x ]
1105 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=KroneckerProduct(CompanionMat((x-1)^2),</span>
1106 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> CompanionMat((x^3-1)*(x-1)));;</span>
1107 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=mat*One(x)-x*mat^0;</span>
1108 [ [ -x, 0, 0, 0, 0, 0, 0, 1 ], [ 0, -x, 0, 0, -1, 0, 0, -1 ],
1109 [ 0, 0, -x, 0, 0, -1, 0, 0 ], [ 0, 0, 0, -x, 0, 0, -1, -1 ],
1110 [ 0, 0, 0, -1, -x, 0, 0, -2 ], [ 1, 0, 0, 1, 2, -x, 0, 2 ],
1111 [ 0, 1, 0, 0, 0, 2, -x, 0 ], [ 0, 0, 1, 1, 0, 0, 2, -x+2 ] ]
1112 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ElementaryDivisorsMat(PolynomialRing(Rationals,1),mat);</span>
1113 [ 1, 1, 1, 1, 1, 1, x-1, x^7-x^6-2*x^4+2*x^3+x-1 ]
1114 </pre></div>
1115
1116 <p><a id="X7AA1C9047B102204" name="X7AA1C9047B102204"></a></p>
1117
1118 <h5>24.9-2 ElementaryDivisorsTransformationsMat</h5>
1119
1120 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ElementaryDivisorsTransformationsMat</code>( [<var class="Arg">ring</var>, ]<var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1121 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ElementaryDivisorsTransformationsMatDestructive</code>( <var class="Arg">ring</var>, <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1122 <p><code class="code">ElementaryDivisorsTransformations</code>, in addition to the tasks done by <code class="code">ElementaryDivisorsMat</code>, also calculates transforming matrices. It returns a record with components <code class="code">normal</code> (a matrix <span class="SimpleMath">S</span>), <code class="code">rowtrans</code> (a matrix <span class="SimpleMath">P</span>), and <code class="code">coltrans</code> (a matrix <span class="SimpleMath">Q</span>) such that <span class="SimpleMath">P A Q = S</span>. The operations are performed over the euclidean ring <var class="Arg">ring</var>, which must contain all matrix entries. For compatibility reasons it can be omitted and defaults to the <code class="func">DefaultRing</code> (<a href="chap56.html#X83AFFCC77DE6ABDA"><span class="RefLink">56.1-3</span></a>) of the matrix entries.</p>
1123
1124 <p>The function <code class="func">ElementaryDivisorsTransformationsMatDestructive</code> produces the same result but in the process destroys the contents of <var class="Arg">mat</var>.</p>
1125
1126
1127 <div class="example"><pre>
1128 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=KroneckerProduct(CompanionMat((x-1)^2),CompanionMat((x^3-1)*(x-1)));;</span>
1129 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=mat*One(x)-x*mat^0;</span>
1130 [ [ -x, 0, 0, 0, 0, 0, 0, 1 ], [ 0, -x, 0, 0, -1, 0, 0, -1 ],
1131 [ 0, 0, -x, 0, 0, -1, 0, 0 ], [ 0, 0, 0, -x, 0, 0, -1, -1 ],
1132 [ 0, 0, 0, -1, -x, 0, 0, -2 ], [ 1, 0, 0, 1, 2, -x, 0, 2 ],
1133 [ 0, 1, 0, 0, 0, 2, -x, 0 ], [ 0, 0, 1, 1, 0, 0, 2, -x+2 ] ]
1134 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">t:=ElementaryDivisorsTransformationsMat(PolynomialRing(Rationals,1),mat);</span>
1135 rec( coltrans := [ [ 0, 0, 0, 0, 0, 0, 1/6*x^2-7/9*x-1/18, -3*x^3-x^2-x-1 ],
1136 [ 0, 0, 0, 0, 0, 0, -1/6*x^2+x-1, 3*x^3-3*x^2 ],
1137 [ 0, 0, 0, 0, 0, 1, -1/18*x^4+1/3*x^3-1/3*x^2-1/9*x, x^5-x^4+2*x^2-2*x
1138 ], [ 0, 0, 0, 0, -1, 0, -1/9*x^3+1/2*x^2+1/9*x, 2*x^4+x^3+x^2+2*x ],
1139 [ 0, -1, 0, 0, 0, 0, -2/9*x^2+19/18*x, 4*x^3+x^2+x ],
1140 [ 0, 0, -1, 0, 0, -x, 1/18*x^5-1/3*x^4+1/3*x^3+1/9*x^2,
1141 -x^6+x^5-2*x^3+2*x^2 ],
1142 [ 0, 0, 0, -1, x, 0, 1/9*x^4-2/3*x^3+2/3*x^2+1/18*x,
1143 -2*x^5+2*x^4-x^2+x ],
1144 [ 1, 0, 0, 0, 0, 0, 1/6*x^3-7/9*x^2-1/18*x, -3*x^4-x^3-x^2-x ] ],
1145 normal := [ [ 1, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0, 0, 0 ],
1146 [ 0, 0, 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0, 0, 0 ],
1147 [ 0, 0, 0, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1, 0, 0 ],
1148 [ 0, 0, 0, 0, 0, 0, x-1, 0 ],
1149 [ 0, 0, 0, 0, 0, 0, 0, x^7-x^6-2*x^4+2*x^3+x-1 ] ],
1150 rowtrans := [ [ 1, 0, 0, 0, 0, 0, 0, 0 ], [ 1, 1, 0, 0, 0, 0, 0, 0 ],
1151 [ 0, 0, 1, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 1, 0, 0, 0, 0 ],
1152 [ -x+2, -x, 0, 0, 1, 0, 0, 0 ],
1153 [ 2*x^2-4*x+2, 2*x^2-x, 0, 2, -2*x+1, 0, 0, 1 ],
1154 [ 3*x^3-6*x^2+3*x, 3*x^3-2*x^2, 2, 3*x, -3*x^2+2*x, 0, 1, 2*x ],
1155 [ 1/6*x^8-7/6*x^7+2*x^6-4/3*x^5+7/3*x^4-4*x^3+13/6*x^2-7/6*x+2,
1156 1/6*x^8-17/18*x^7+13/18*x^6-5/18*x^5+35/18*x^4-31/18*x^3+1/9*x^2-x+\
1157 2, 1/9*x^5-5/9*x^4+1/9*x^3-1/9*x^2+14/9*x-1/9,
1158 1/6*x^6-5/6*x^5+1/6*x^4-1/6*x^3+11/6*x^2-1/6*x,
1159 -1/6*x^7+17/18*x^6-13/18*x^5+5/18*x^4-35/18*x^3+31/18*x^2-1/9*x+1,
1160 1, 1/18*x^5-5/18*x^4+1/18*x^3-1/18*x^2+23/18*x-1/18,
1161 1/9*x^6-5/9*x^5+1/9*x^4-1/9*x^3+14/9*x^2-1/9*x ] ] )
1162 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">t.rowtrans*mat*t.coltrans;</span>
1163 [ [ 1, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 1, 0, 0, 0, 0, 0, 0 ],
1164 [ 0, 0, 1, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 1, 0, 0, 0, 0 ],
1165 [ 0, 0, 0, 0, 1, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 1, 0, 0 ],
1166 [ 0, 0, 0, 0, 0, 0, x-1, 0 ],
1167 [ 0, 0, 0, 0, 0, 0, 0, x^7-x^6-2*x^4+2*x^3+x-1 ] ]
1168 </pre></div>
1169
1170 <p><a id="X85819D3F7A582180" name="X85819D3F7A582180"></a></p>
1171
1172 <h5>24.9-3 DiagonalizeMat</h5>
1173
1174 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DiagonalizeMat</code>( <var class="Arg">ring</var>, <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1175 <p>brings the mutable matrix <var class="Arg">mat</var>, considered as a matrix over <var class="Arg">ring</var>, into diagonal form by elementary row and column operations.</p>
1176
1177
1178 <div class="example"><pre>
1179 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m:=[[1,2],[2,1]];;</span>
1180 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DiagonalizeMat(Integers,m);m;</span>
1181 [ [ 1, 0 ], [ 0, 3 ] ]
1182 </pre></div>
1183
1184 <p><a id="X7CA6B51D7AE3172B" name="X7CA6B51D7AE3172B"></a></p>
1185
1186 <h4>24.10 <span class="Heading">Echelonized Matrices</span></h4>
1187
1188 <p><a id="X7D5D6BD07B7E981B" name="X7D5D6BD07B7E981B"></a></p>
1189
1190 <h5>24.10-1 SemiEchelonMat</h5>
1191
1192 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SemiEchelonMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1193 <p>A matrix over a field <span class="SimpleMath">F</span> is in semi-echelon form if the first nonzero element in each row is the identity of <span class="SimpleMath">F</span>, and all values exactly below these pivots are the zero of <span class="SimpleMath">F</span>.</p>
1194
1195 <p><code class="func">SemiEchelonMat</code> returns a record that contains information about a semi-echelonized form of the matrix <var class="Arg">mat</var>.</p>
1196
1197 <p>The components of this record are</p>
1198
1199
1200 <dl>
1201 <dt><strong class="Mark"><code class="code">vectors</code></strong></dt>
1202 <dd><p>list of row vectors, each with pivot element the identity of <span class="SimpleMath">F</span>,</p>
1203
1204 </dd>
1205 <dt><strong class="Mark"><code class="code">heads</code></strong></dt>
1206 <dd><p>list that contains at position <var class="Arg">i</var>, if nonzero, the number of the row for that the pivot element is in column <var class="Arg">i</var>.</p>
1207
1208 </dd>
1209 </dl>
1210 <p><a id="X8251F6F57D346385" name="X8251F6F57D346385"></a></p>
1211
1212 <h5>24.10-2 SemiEchelonMatDestructive</h5>
1213
1214 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SemiEchelonMatDestructive</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1215 <p>This does the same as <code class="code">SemiEchelonMat( <var class="Arg">mat</var> )</code>, except that it may (and probably will) destroy the matrix <var class="Arg">mat</var>.</p>
1216
1217
1218 <div class="example"><pre>
1219 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
1220 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SemiEchelonMatDestructive( mm );</span>
1221 rec( heads := [ 1, 2, 0 ], vectors := [ [ 1, 2, 3 ], [ 0, 1, 2 ] ] )
1222 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm;</span>
1223 [ [ 1, 2, 3 ], [ 0, 1, 2 ], [ 0, 0, 0 ] ]
1224 </pre></div>
1225
1226 <p><a id="X7EFD1DB5861A54F0" name="X7EFD1DB5861A54F0"></a></p>
1227
1228 <h5>24.10-3 SemiEchelonMatTransformation</h5>
1229
1230 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SemiEchelonMatTransformation</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1231 <p>does the same as <code class="func">SemiEchelonMat</code> (<a href="chap24.html#X7D5D6BD07B7E981B"><span class="RefLink">24.10-1</span></a>) but additionally stores the linear transformation <span class="SimpleMath">T</span> performed on the matrix. The additional components of the result are</p>
1232
1233
1234 <dl>
1235 <dt><strong class="Mark"><code class="code">coeffs</code></strong></dt>
1236 <dd><p>a list of coefficients vectors of the <code class="code">vectors</code> component, with respect to the rows of <var class="Arg">mat</var>, that is, <code class="code">coeffs * mat</code> is the <code class="code">vectors</code> component.</p>
1237
1238 </dd>
1239 <dt><strong class="Mark"><code class="code">relations</code></strong></dt>
1240 <dd><p>a list of basis vectors for the (left) null space of <var class="Arg">mat</var>.</p>
1241
1242 </dd>
1243 </dl>
1244
1245 <div class="example"><pre>
1246 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SemiEchelonMatTransformation([[1,2,3],[0,0,1]]);</span>
1247 rec( coeffs := [ [ 1, 0 ], [ 0, 1 ] ], heads := [ 1, 0, 2 ],
1248 relations := [ ], vectors := [ [ 1, 2, 3 ], [ 0, 0, 1 ] ] )
1249 </pre></div>
1250
1251 <p><a id="X827D7971800DB661" name="X827D7971800DB661"></a></p>
1252
1253 <h5>24.10-4 SemiEchelonMats</h5>
1254
1255 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SemiEchelonMats</code>( <var class="Arg">mats</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1256 <p>A list of matrices over a field <span class="SimpleMath">F</span> is in semi-echelon form if the list of row vectors obtained on concatenating the rows of each matrix is a semi-echelonized matrix (see <code class="func">SemiEchelonMat</code> (<a href="chap24.html#X7D5D6BD07B7E981B"><span class="RefLink">24.10-1</span></a>)).</p>
1257
1258 <p><code class="func">SemiEchelonMats</code> returns a record that contains information about a semi-echelonized form of the list <var class="Arg">mats</var> of matrices.</p>
1259
1260 <p>The components of this record are</p>
1261
1262
1263 <dl>
1264 <dt><strong class="Mark"><code class="code">vectors</code></strong></dt>
1265 <dd><p>list of matrices, each with pivot element the identity of <span class="SimpleMath">F</span>,</p>
1266
1267 </dd>
1268 <dt><strong class="Mark"><code class="code">heads</code></strong></dt>
1269 <dd><p>matrix that contains at position [<var class="Arg">i</var>,<var class="Arg">j</var>], if nonzero, the number of the matrix that has the pivot element in this position</p>
1270
1271 </dd>
1272 </dl>
1273 <p><a id="X808F493B839BC7A6" name="X808F493B839BC7A6"></a></p>
1274
1275 <h5>24.10-5 SemiEchelonMatsDestructive</h5>
1276
1277 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SemiEchelonMatsDestructive</code>( <var class="Arg">mats</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1278 <p>Does the same as <code class="func">SemiEchelonMats</code> (<a href="chap24.html#X827D7971800DB661"><span class="RefLink">24.10-4</span></a>), except that it may destroy its argument. Therefore the argument must be a list of matrices that are mutable.</p>
1279
1280 <p><a id="X86B0D4A886BC0C6E" name="X86B0D4A886BC0C6E"></a></p>
1281
1282 <h4>24.11 <span class="Heading">Matrices as Basis of a Row Space</span></h4>
1283
1284 <p>See also chapter <a href="chap25.html#X8414F20D8412DDA4"><span class="RefLink">25</span></a></p>
1285
1286 <p><a id="X7AD6B5F5794D9E46" name="X7AD6B5F5794D9E46"></a></p>
1287
1288 <h5>24.11-1 BaseMat</h5>
1289
1290 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BaseMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1291 <p>returns a basis for the row space generated by the rows of <var class="Arg">mat</var> in the form of an immutable matrix.</p>
1292
1293 <p><a id="X78B094597E382A5F" name="X78B094597E382A5F"></a></p>
1294
1295 <h5>24.11-2 BaseMatDestructive</h5>
1296
1297 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BaseMatDestructive</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1298 <p>Does the same as <code class="func">BaseMat</code> (<a href="chap24.html#X7AD6B5F5794D9E46"><span class="RefLink">24.11-1</span></a>), with the difference that it may destroy the matrix <var class="Arg">mat</var>. The matrix <var class="Arg">mat</var> must be mutable.</p>
1299
1300
1301 <div class="example"><pre>
1302 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
1303 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BaseMat(mat);</span>
1304 [ [ 1, 2, 3 ], [ 0, 1, 2 ] ]
1305 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm:= [[1,2,3],[4,5,6],[5,7,9]];;</span>
1306 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BaseMatDestructive( mm );</span>
1307 [ [ 1, 2, 3 ], [ 0, 1, 2 ] ]
1308 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mm;</span>
1309 [ [ 1, 2, 3 ], [ 0, 1, 2 ], [ 0, 0, 0 ] ]
1310 </pre></div>
1311
1312 <p><a id="X78B94EFF87A455BE" name="X78B94EFF87A455BE"></a></p>
1313
1314 <h5>24.11-3 BaseOrthogonalSpaceMat</h5>
1315
1316 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BaseOrthogonalSpaceMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1317 <p>Let <span class="SimpleMath">V</span> be the row space generated by the rows of <var class="Arg">mat</var> (over any field that contains all entries of <var class="Arg">mat</var>). <code class="code">BaseOrthogonalSpaceMat( <var class="Arg">mat</var> )</code> computes a base of the orthogonal space of <span class="SimpleMath">V</span>.</p>
1318
1319 <p>The rows of <var class="Arg">mat</var> need not be linearly independent.</p>
1320
1321 <p><a id="X7AFF8BCF80C88B45" name="X7AFF8BCF80C88B45"></a></p>
1322
1323 <h5>24.11-4 SumIntersectionMat</h5>
1324
1325 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SumIntersectionMat</code>( <var class="Arg">M1</var>, <var class="Arg">M2</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1326 <p>performs Zassenhaus' algorithm to compute bases for the sum and the intersection of spaces generated by the rows of the matrices <var class="Arg">M1</var>, <var class="Arg">M2</var>.</p>
1327
1328 <p>returns a list of length 2, at first position a base of the sum, at second position a base of the intersection. Both bases are in semi-echelon form (see <a href="chap24.html#X7CA6B51D7AE3172B"><span class="RefLink">24.10</span></a>).</p>
1329
1330
1331 <div class="example"><pre>
1332 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SumIntersectionMat(mat,[[2,7,6],[5,9,4]]);</span>
1333 [ [ [ 1, 2, 3 ], [ 0, 1, 2 ], [ 0, 0, 1 ] ], [ [ 1, -3/4, -5/2 ] ] ]
1334 </pre></div>
1335
1336 <p><a id="X8245D54F7AC532EB" name="X8245D54F7AC532EB"></a></p>
1337
1338 <h5>24.11-5 BaseSteinitzVectors</h5>
1339
1340 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BaseSteinitzVectors</code>( <var class="Arg">bas</var>, <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1341 <p>find vectors extending mat to a basis spanning the span of <var class="Arg">bas</var>. Both <var class="Arg">bas</var> and <var class="Arg">mat</var> must be matrices of full (row) rank. It returns a record with the following components:</p>
1342
1343
1344 <dl>
1345 <dt><strong class="Mark"><code class="code">subspace</code></strong></dt>
1346 <dd><p>is a basis of the space spanned by <var class="Arg">mat</var> in upper triangular form with leading ones at all echelon steps and zeroes above these ones.</p>
1347
1348 </dd>
1349 <dt><strong class="Mark"><code class="code">factorspace</code></strong></dt>
1350 <dd><p>is a list of extending vectors in upper triangular form.</p>
1351
1352 </dd>
1353 <dt><strong class="Mark"><code class="code">factorzero</code></strong></dt>
1354 <dd><p>is a zero vector.</p>
1355
1356 </dd>
1357 <dt><strong class="Mark"><code class="code">heads</code></strong></dt>
1358 <dd><p>is a list of integers which can be used to decompose vectors in the basis vectors. The <var class="Arg">i</var>th entry indicating the vector that gives an echelon step at position <var class="Arg">i</var>. A negative number indicates an echelon step in the subspace, a positive number an echelon step in the complement, the absolute value gives the position of the vector in the lists <code class="code">subspace</code> and <code class="code">factorspace</code>.</p>
1359
1360 </dd>
1361 </dl>
1362
1363 <div class="example"><pre>
1364 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BaseSteinitzVectors(IdentityMat(3,1),[[11,13,15]]);</span>
1365 rec( factorspace := [ [ 0, 1, 15/13 ], [ 0, 0, 1 ] ],
1366 factorzero := [ 0, 0, 0 ], heads := [ -1, 1, 2 ],
1367 subspace := [ [ 1, 13/11, 15/11 ] ] )
1368 </pre></div>
1369
1370 <p><a id="X79D5E53685F0FBEE" name="X79D5E53685F0FBEE"></a></p>
1371
1372 <h4>24.12 <span class="Heading">Triangular Matrices</span></h4>
1373
1374 <p><a id="X7A9139D686ACB7D8" name="X7A9139D686ACB7D8"></a></p>
1375
1376 <h5>24.12-1 DiagonalOfMatrix</h5>
1377
1378 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DiagonalOfMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1379 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DiagonalOfMat</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1380 <p>return the diagonal of the matrix <var class="Arg">mat</var>. If <var class="Arg">mat</var> is not a square matrix, then the result has the same length as the rows of <var class="Arg">mat</var>, and is padded with zeros if <var class="Arg">mat</var> has fewer rows than columns.</p>
1381
1382
1383 <div class="example"><pre>
1384 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DiagonalOfMatrix( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );</span>
1385 [ 1, 5, 0 ]
1386 </pre></div>
1387
1388 <p><a id="X84A78C057F9DAE5E" name="X84A78C057F9DAE5E"></a></p>
1389
1390 <h5>24.12-2 UpperSubdiagonal</h5>
1391
1392 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; UpperSubdiagonal</code>( <var class="Arg">mat</var>, <var class="Arg">pos</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1393 <p>returns a mutable list containing the entries of the <var class="Arg">pos</var>th upper subdiagonal of the matrix <var class="Arg">mat</var>.</p>
1394
1395
1396 <div class="example"><pre>
1397 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">UpperSubdiagonal( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ], 1 );</span>
1398 [ 2, 6 ]
1399 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">UpperSubdiagonal( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], 1 );</span>
1400 [ 2 ]
1401 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">UpperSubdiagonal( [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ], 1 );</span>
1402 [ 2, 7 ]
1403 </pre></div>
1404
1405 <p><a id="X84D74DEA798A9094" name="X84D74DEA798A9094"></a></p>
1406
1407 <h5>24.12-3 DepthOfUpperTriangularMatrix</h5>
1408
1409 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DepthOfUpperTriangularMatrix</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1410 <p>If <var class="Arg">mat</var> is an upper triangular matrix this attribute returns the index of the first nonzero diagonal.</p>
1411
1412
1413 <div class="example"><pre>
1414 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DepthOfUpperTriangularMatrix([[0,1,2],[0,0,1],[0,0,0]]);</span>
1415 1
1416 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DepthOfUpperTriangularMatrix([[0,0,2],[0,0,0],[0,0,0]]);</span>
1417 2
1418 </pre></div>
1419
1420 <p><a id="X85B403857F2855F7" name="X85B403857F2855F7"></a></p>
1421
1422 <h4>24.13 <span class="Heading">Matrices as Linear Mappings</span></h4>
1423
1424 <p><a id="X87FA0A727CDB060B" name="X87FA0A727CDB060B"></a></p>
1425
1426 <h5>24.13-1 CharacteristicPolynomial</h5>
1427
1428 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CharacteristicPolynomial</code>( [<var class="Arg">F</var>, <var class="Arg">E</var>, ]<var class="Arg">mat</var>[, <var class="Arg">ind</var>] )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1429 <p>For a square matrix <var class="Arg">mat</var>, <code class="func">CharacteristicPolynomial</code> returns the <em>characteristic polynomial</em> of <var class="Arg">mat</var>, that is, the <code class="func">StandardAssociate</code> (<a href="chap56.html#X7B1A9A4C7C59FB36"><span class="RefLink">56.5-5</span></a>) of the determinant of the matrix <span class="SimpleMath"><var class="Arg">mat</var> - X ⋅ I</span>, where <span class="SimpleMath">X</span> is an indeterminate and <span class="SimpleMath">I</span> is the appropriate identity matrix.</p>
1430
1431 <p>If fields <var class="Arg">F</var> and <var class="Arg">E</var> are given, then <var class="Arg">F</var> must be a subfield of <var class="Arg">E</var>, and <var class="Arg">mat</var> must have entries in <var class="Arg">E</var>. Then <code class="func">CharacteristicPolynomial</code> returns the characteristic polynomial of the <var class="Arg">F</var>-linear mapping induced by <var class="Arg">mat</var> on the underlying <var class="Arg">E</var>-vector space of <var class="Arg">mat</var>. In this case, the characteristic polynomial is computed using <code class="func">BlownUpMat</code> (<a href="chap24.html#X85923C107A4569D0"><span class="RefLink">24.13-4</span></a>) for the field extension of <span class="SimpleMath">E/F</span> generated by the default field. Thus, if <span class="SimpleMath">F = E</span>, the result is the same as for the one argument version.</p>
1432
1433 <p>The returned polynomials are expressed in the indeterminate number <var class="Arg">ind</var>. If <var class="Arg">ind</var> is not given, it defaults to <span class="SimpleMath">1</span>.</p>
1434
1435 <p><code class="code">CharacteristicPolynomial(<var class="Arg">F</var>, <var class="Arg">E</var>, <var class="Arg">mat</var>)</code> is a multiple of the minimal polynomial <code class="code">MinimalPolynomial(<var class="Arg">F</var>, <var class="Arg">mat</var>)</code> (see <code class="func">MinimalPolynomial</code> (<a href="chap66.html#X8643915A8424DAF8"><span class="RefLink">66.8-1</span></a>)).</p>
1436
1437 <p>Note that, up to <strong class="pkg">GAP</strong> version 4.4.6, <code class="func">CharacteristicPolynomial</code> only allowed to specify one field (corresponding to <var class="Arg">F</var>) as an argument. That usage has been disabled because its definition turned out to be ambiguous and may have lead to unexpected results. (To ensure backward compatibility, it is still possible to use the old form if <var class="Arg">F</var> contains the default field of the matrix, see <code class="func">DefaultFieldOfMatrix</code> (<a href="chap24.html#X80AE547B8095A5CB"><span class="RefLink">24.4-2</span></a>), but this feature will disappear in future versions of <strong class="pkg">GAP</strong>.)</p>
1438
1439
1440 <div class="example"><pre>
1441 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CharacteristicPolynomial( [ [ 1, 1 ], [ 0, 1 ] ] );</span>
1442 x^2-2*x+1
1443 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat := [[0,1],[E(4)-1,E(4)]];;</span>
1444 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CharacteristicPolynomial( mat );</span>
1445 x^2+(-E(4))*x+(1-E(4))
1446 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CharacteristicPolynomial( Rationals, CF(4), mat );</span>
1447 x^4+3*x^2+2*x+2
1448 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:= [ [ E(4), 1 ], [ 0, -E(4) ] ];;</span>
1449 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CharacteristicPolynomial( mat );</span>
1450 x^2+1
1451 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CharacteristicPolynomial( Rationals, CF(4), mat );</span>
1452 x^4+2*x^2+1
1453 </pre></div>
1454
1455 <p><a id="X7B52560C792C1A0F" name="X7B52560C792C1A0F"></a></p>
1456
1457 <h5>24.13-2 RationalCanonicalFormTransform</h5>
1458
1459 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RationalCanonicalFormTransform</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1460 <p>For a matrix <code class="code">A</code>, return a matrix <code class="code">P</code> such that <span class="SimpleMath">A^P</span> is in rational canonical form (also called Frobenius normal form). The algorithm used is the basic textbook version and thus not of optimal complexity.</p>
1461
1462
1463 <div class="example"><pre>
1464 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">aa:=[[0,-8,12,40,-36,4,0,59,15,-9],[-2,-2,-2,6,-11,1,-1,10,1,0],</span>
1465 <span class="GAPprompt">&gt;</span> <span class="GAPinput">[1,5,0,-6,12,-2,0,-12,-4,2],[0,0,0,2,0,0,0,7,0,0],</span>
1466 <span class="GAPprompt">&gt;</span> <span class="GAPinput">[0,2,-3,-7,8,-1,0,-7,-3,2],[-5,-4,-6,18,-30,2,-2,35,5,-1],</span>
1467 <span class="GAPprompt">&gt;</span> <span class="GAPinput">[-1,-6,6,20,-28,3,0,24,10,-6],[0,0,0,-1,0,0,0,-3,0,0],</span>
1468 <span class="GAPprompt">&gt;</span> <span class="GAPinput">[0,0,-1,-2,-2,0,-1,-7,0,0],[0,-8,9,21,-36,4,-2,12,12,-8]];;</span>
1469 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">t:=RationalCanonicalFormTransform(aa);;</span>
1470 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">aa^t;</span>
1471 [ [ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
1472 [ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ],
1473 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
1474 [ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ], [ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ],
1475 [ 0, 0, 0, 0, 0, 0, 0, 1, 0, -1 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 ] ]
1476 </pre></div>
1477
1478 <p><a id="X83F55D4E79BA5D1B" name="X83F55D4E79BA5D1B"></a></p>
1479
1480 <h5>24.13-3 JordanDecomposition</h5>
1481
1482 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; JordanDecomposition</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1483 <p><code class="code">JordanDecomposition( <var class="Arg">mat </var> )</code> returns a list <code class="code">[S,N]</code> such that <code class="code">S</code> is a semisimple matrix and <code class="code">N</code> is nilpotent. Furthermore, <code class="code">S</code> and <code class="code">N</code> commute and <code class="code"><var class="Arg">mat</var>=S+N</code>.</p>
1484
1485
1486 <div class="example"><pre>
1487 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:=[[1,2,3],[4,5,6],[7,8,9]];;</span>
1488 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">JordanDecomposition(mat);</span>
1489 [ [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ],
1490 [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ] ]
1491 </pre></div>
1492
1493 <p><a id="X85923C107A4569D0" name="X85923C107A4569D0"></a></p>
1494
1495 <h5>24.13-4 BlownUpMat</h5>
1496
1497 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BlownUpMat</code>( <var class="Arg">B</var>, <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1498 <p>Let <var class="Arg">B</var> be a basis of a field extension <span class="SimpleMath">F / K</span>, and <var class="Arg">mat</var> a matrix whose entries are all in <span class="SimpleMath">F</span>. (This is not checked.) <code class="func">BlownUpMat</code> returns a matrix over <span class="SimpleMath">K</span> that is obtained by replacing each entry of <var class="Arg">mat</var> by its regular representation w.r.t. <var class="Arg">B</var>.</p>
1499
1500 <p>More precisely, regard <var class="Arg">mat</var> as the matrix of a linear transformation on the row space <span class="SimpleMath">F^n</span> w.r.t. the <span class="SimpleMath">F</span>-basis with vectors <span class="SimpleMath">(v_1, ..., v_n)</span> and suppose that the basis <var class="Arg">B</var> consists of the vectors <span class="SimpleMath">(b_1, ..., b_m)</span>; then the returned matrix is the matrix of the linear transformation on the row space <span class="SimpleMath">K^mn</span> w.r.t. the <span class="SimpleMath">K</span>-basis whose vectors are <span class="SimpleMath">(b_1 v_1, ... b_m v_1, ..., b_m v_n)</span>.</p>
1501
1502 <p>Note that the linear transformations act on <em>row</em> vectors, i.e., each row of the matrix is a concatenation of vectors of <var class="Arg">B</var>-coefficients.</p>
1503
1504 <p><a id="X82AC277D84EC5749" name="X82AC277D84EC5749"></a></p>
1505
1506 <h5>24.13-5 BlownUpVector</h5>
1507
1508 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BlownUpVector</code>( <var class="Arg">B</var>, <var class="Arg">vector</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1509 <p>Let <var class="Arg">B</var> be a basis of a field extension <span class="SimpleMath">F / K</span>, and <var class="Arg">vector</var> a row vector whose entries are all in <span class="SimpleMath">F</span>. <code class="func">BlownUpVector</code> returns a row vector over <span class="SimpleMath">K</span> that is obtained by replacing each entry of <var class="Arg">vector</var> by its coefficients w.r.t. <var class="Arg">B</var>.</p>
1510
1511 <p>So <code class="func">BlownUpVector</code> and <code class="func">BlownUpMat</code> (<a href="chap24.html#X85923C107A4569D0"><span class="RefLink">24.13-4</span></a>) are compatible in the sense that for a matrix <var class="Arg">mat</var> over <span class="SimpleMath">F</span>, <code class="code">BlownUpVector( <var class="Arg">B</var>, <var class="Arg">mat</var> * <var class="Arg">vector</var> )</code> is equal to <code class="code">BlownUpMat( <var class="Arg">B</var>, <var class="Arg">mat</var> ) * BlownUpVector( <var class="Arg">B</var>, <var class="Arg">vector</var> )</code>.</p>
1512
1513
1514 <div class="example"><pre>
1515 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">B:= Basis( CF(4), [ 1, E(4) ] );;</span>
1516 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:= [ [ 1, E(4) ], [ 0, 1 ] ];; vec:= [ 1, E(4) ];;</span>
1517 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">bmat:= BlownUpMat( B, mat );; bvec:= BlownUpVector( B, vec );;</span>
1518 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( bmat ); bvec;</span>
1519 [ [ 1, 0, 0, 1 ],
1520 [ 0, 1, -1, 0 ],
1521 [ 0, 0, 1, 0 ],
1522 [ 0, 0, 0, 1 ] ]
1523 [ 1, 0, 0, 1 ]
1524 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">bvec * bmat = BlownUpVector( B, vec * mat );</span>
1525 true
1526 </pre></div>
1527
1528 <p><a id="X7E06762479A00DF4" name="X7E06762479A00DF4"></a></p>
1529
1530 <h5>24.13-6 CompanionMatrix</h5>
1531
1532 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CompanionMatrix</code>( <var class="Arg">poly</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1533 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CompanionMat</code>( <var class="Arg">poly</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1534 <p>Return a fully mutable matrix that is the companion matrix of the polynomial <var class="Arg">poly</var>. The negatives of the coefficients of <var class="Arg">poly</var> appear in the last column of the result.</p>
1535
1536 <p>The companion matrix of <var class="Arg">poly</var> has <var class="Arg">poly</var> as its minimal polynomial (see <code class="func">MinimalPolynomial</code> (<a href="chap66.html#X8643915A8424DAF8"><span class="RefLink">66.8-1</span></a>)) and as its characteristic polynomial (see <code class="func">CharacteristicPolynomial</code> (<a href="chap24.html#X87FA0A727CDB060B"><span class="RefLink">24.13-1</span></a>)).</p>
1537
1538
1539 <div class="example"><pre>
1540 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">x:= X( Rationals );; pol:= x^3 + x^2 + 2*x + 3;;</span>
1541 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">M:= CompanionMatrix( pol );;</span>
1542 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( M );</span>
1543 [ [ 0, 0, -3 ],
1544 [ 1, 0, -2 ],
1545 [ 0, 1, -1 ] ]
1546 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">MinimalPolynomial( M ) = pol;</span>
1547 true
1548 </pre></div>
1549
1550 <p><a id="X873822B6830CE367" name="X873822B6830CE367"></a></p>
1551
1552 <h4>24.14 <span class="Heading">Matrices over Finite Fields</span></h4>
1553
1554 <p>Just as for row vectors, (see section <a href="chap23.html#X8679F7DD7DFCBD9C"><span class="RefLink">23.3</span></a>), <strong class="pkg">GAP</strong> has a special representation for matrices over small finite fields.</p>
1555
1556 <p>To be eligible to be represented in this way, each row of a matrix must be able to be represented as a compact row vector of the same length over <em>the same</em> finite field.</p>
1557
1558
1559 <div class="example"><pre>
1560 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">v := Z(2)*[1,0,0,1,1];</span>
1561 [ Z(2)^0, 0*Z(2), 0*Z(2), Z(2)^0, Z(2)^0 ]
1562 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ConvertToVectorRep(v,2);</span>
1563 2
1564 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">v;</span>
1565 &lt;a GF2 vector of length 5&gt;
1566 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := [v];; ConvertToMatrixRep(m,GF(2));; m;</span>
1567 &lt;a 1x5 matrix over GF2&gt;
1568 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := [v,v];; ConvertToMatrixRep(m,GF(2));; m;</span>
1569 &lt;a 2x5 matrix over GF2&gt;
1570 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := [v,v,v];; ConvertToMatrixRep(m,GF(2));; m;</span>
1571 &lt;a 3x5 matrix over GF2&gt;
1572 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">v := Z(3)*[1..8];</span>
1573 [ Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0 ]
1574 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ConvertToVectorRep(v);</span>
1575 3
1576 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := [v];; ConvertToMatrixRep(m,GF(3));; m;</span>
1577 [ [ Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0, 0*Z(3), Z(3), Z(3)^0 ] ]
1578 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RepresentationsOfObject(m);</span>
1579 [ "IsPositionalObjectRep", "Is8BitMatrixRep" ]
1580 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := [v,v,v,v];; ConvertToMatrixRep(m,GF(3));; m;</span>
1581 &lt; mutable compressed matrix 4x8 over GF(3) &gt;
1582 </pre></div>
1583
1584 <p>All compressed matrices over GF(2) are viewed as <code class="code">&lt;a <var class="Arg">n</var>x<var class="Arg">m</var> matrix over GF2&gt;</code>, while over fields GF(q) for q between 3 and 256, matrices with 25 or more entries are viewed in this way, and smaller ones as lists of lists.</p>
1585
1586 <p>Matrices can be converted to this special representation via the following functions.</p>
1587
1588 <p>Note that the main advantage of this special representation of matrices is in low dimensions, where various overheads can be reduced. In higher dimensions, a list of compressed vectors will be almost as fast. Note also that list access and assignment will be somewhat slower for compressed matrices than for plain lists.</p>
1589
1590 <p>In order to form a row of a compressed matrix a vector must accept certain restrictions. Specifically, it cannot change its length or change the field over which it is compressed. The main consequences of this are: that only elements of the appropriate field can be assigned to entries of the vector, and only to positions between 1 and the original length; that the vector cannot be shared between two matrices compressed over different fields.</p>
1591
1592 <p>This is enforced by the filter <code class="code">IsLockedRepresentationVector</code>. When a vector becomes part of a compressed matrix, this filter is set for it. Assignment, <code class="func">Unbind</code> (<a href="chap21.html#X78B72FDF7BD63C0B"><span class="RefLink">21.5-3</span></a>), <code class="func">ConvertToVectorRep</code> (<a href="chap23.html#X810E46927F9E8F75"><span class="RefLink">23.3-1</span></a>) and <code class="func">ConvertToMatrixRep</code> (<a href="chap24.html#X8587A62F818AA0D6"><span class="RefLink">24.14-2</span></a>) are all prevented from altering a vector with this filter.</p>
1593
1594
1595 <div class="example"><pre>
1596 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">v := [Z(2),Z(2)];; ConvertToVectorRep(v,GF(2));; v;</span>
1597 &lt;a GF2 vector of length 2&gt;
1598 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m := [v,v];</span>
1599 [ &lt;a GF2 vector of length 2&gt;, &lt;a GF2 vector of length 2&gt; ]
1600 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ConvertToMatrixRep(m,GF(2));</span>
1601 2
1602 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m2 := [m[1], [Z(4),Z(4)]]; # now try and mix in some GF(4)</span>
1603 [ &lt;a GF2 vector of length 2&gt;, [ Z(2^2), Z(2^2) ] ]
1604 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ConvertToMatrixRep(m2); # but m2[1] is locked</span>
1605 #I ConvertToVectorRep: locked vector not converted to different field
1606 fail
1607 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m2 := [ShallowCopy(m[1]), [Z(4),Z(4)]]; # a fresh copy of row 1</span>
1608 [ &lt;a GF2 vector of length 2&gt;, [ Z(2^2), Z(2^2) ] ]
1609 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ConvertToMatrixRep(m2); # now it works</span>
1610 4
1611 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">m2;</span>
1612 [ [ Z(2)^0, Z(2)^0 ], [ Z(2^2), Z(2^2) ] ]
1613 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RepresentationsOfObject(m2);</span>
1614 [ "IsPositionalObjectRep", "Is8BitMatrixRep" ]
1615 </pre></div>
1616
1617 <p>Arithmetic operations (see <a href="chap21.html#X845EEAF083D43CCE"><span class="RefLink">21.11</span></a> and the following sections) preserve the compression status of matrices in the sense that if all arguments are compressed matrices written over the same field and the result is a matrix then also the result is a compressed matrix written over this field.</p>
1618
1619 <p>There are also two operations that are only available for matrices written over finite fields.</p>
1620
1621 <p><a id="X7DED2522828B6C30" name="X7DED2522828B6C30"></a></p>
1622
1623 <h5>24.14-1 ImmutableMatrix</h5>
1624
1625 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ImmutableMatrix</code>( <var class="Arg">field</var>, <var class="Arg">matrix</var>[, <var class="Arg">change</var>] )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1626 <p>Let <var class="Arg">matrix</var> be an object for which either <code class="func">IsMatrix</code> (<a href="chap24.html#X7E1AE46B862B185F"><span class="RefLink">24.2-1</span></a>) or <code class="func">IsMatrixObj</code> (<a href="chap26.html#X7E7617A0781D1E4B"><span class="RefLink">26.2-2</span></a>) returns <code class="keyw">true</code>. In the former case, <var class="Arg">matrix</var> is a list of lists, and <code class="func">ImmutableMatrix</code> returns an immutable object for which <code class="func">IsMatrix</code> (<a href="chap24.html#X7E1AE46B862B185F"><span class="RefLink">24.2-1</span></a>) returns <code class="keyw">true</code> (in particular again a list of lists), which is equal to <var class="Arg">matrix</var>, and which is in the optimal (concerning space and runtime) representation for matrices defined over <var class="Arg">field</var>, provided that the entries of <var class="Arg">matrix</var> lie in <var class="Arg">field</var>. In the latter case, <code class="func">ImmutableMatrix</code> returns an immutable object that is equal to the result of <code class="func">ChangedBaseDomain</code> (<a href="chap26.html#X85E896F67CE2F925"><span class="RefLink">26.6-3</span></a>) when this is called with <var class="Arg">matrix</var> and <var class="Arg">field</var>.</p>
1627
1628 <p>This means that matrices obtained by several calls of <code class="func">ImmutableMatrix</code> for the same <var class="Arg">field</var> are compatible for fast arithmetic without need for field conversion.</p>
1629
1630 <p>If the input matrix <var class="Arg">matrix</var> is in <code class="func">IsMatrix</code> (<a href="chap24.html#X7E1AE46B862B185F"><span class="RefLink">24.2-1</span></a>) then it or its rows might change their representation as a side effect of this function. However, one cannot rely on this side effect. Also, if <var class="Arg">matrix</var> is already immutable and the result of <code class="func">ImmutableMatrix</code> has the same internal representation as <var class="Arg">matrix</var>, the result is not necessarily <em>identical</em> to <var class="Arg">matrix</var>.</p>
1631
1632 <p>If <var class="Arg">change</var> is <code class="keyw">true</code>, <var class="Arg">matrix</var> or its rows (if there are subobjects that represent rows) may be changed to become immutable; otherwise the rows of <var class="Arg">matrix</var> are copied first.</p>
1633
1634 <p><a id="X8587A62F818AA0D6" name="X8587A62F818AA0D6"></a></p>
1635
1636 <h5>24.14-2 ConvertToMatrixRep</h5>
1637
1638 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ConvertToMatrixRep</code>( <var class="Arg">list</var>[, <var class="Arg">field</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1639 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ConvertToMatrixRep</code>( <var class="Arg">list</var>[, <var class="Arg">fieldsize</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1640 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ConvertToMatrixRepNC</code>( <var class="Arg">list</var>[, <var class="Arg">field</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1641 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ConvertToMatrixRepNC</code>( <var class="Arg">list</var>[, <var class="Arg">fieldsize</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1642 <p>This function is more technical version of <code class="func">ImmutableMatrix</code> (<a href="chap24.html#X7DED2522828B6C30"><span class="RefLink">24.14-1</span></a>), which will never copy a matrix (or any rows of it) but may fail if it encounters rows locked in the wrong representation, or various other more technical problems. Most users should use <code class="func">ImmutableMatrix</code> (<a href="chap24.html#X7DED2522828B6C30"><span class="RefLink">24.14-1</span></a>) instead. The NC versions of the function do less checking of the argument and may cause unpredictable results or crashes if given unsuitable arguments. Called with one argument <var class="Arg">list</var>, <code class="func">ConvertToMatrixRep</code> converts <var class="Arg">list</var> to an internal matrix representation if possible.</p>
1643
1644 <p>Called with a list <var class="Arg">list</var> and a finite field <var class="Arg">field</var>, <code class="func">ConvertToMatrixRep</code> converts <var class="Arg">list</var> to an internal matrix representation appropriate for a matrix over <var class="Arg">field</var>.</p>
1645
1646 <p>Instead of a <var class="Arg">field</var> also its size <var class="Arg">fieldsize</var> may be given.</p>
1647
1648 <p>It is forbidden to call this function unless all elements of <var class="Arg">list</var> are row vectors with entries in the field <var class="Arg">field</var>. Violation of this condition can lead to unpredictable behaviour or a system crash. (Setting the assertion level to at least 2 might catch some violations before a crash, see <code class="func">SetAssertionLevel</code> (<a href="chap7.html#X7C7596418423660B"><span class="RefLink">7.5-1</span></a>).)</p>
1649
1650 <p><var class="Arg">list</var> may already be a compressed matrix. In this case, if no <var class="Arg">field</var> or <var class="Arg">fieldsize</var> is given, then nothing happens.</p>
1651
1652 <p>The return value is the size of the field over which the matrix ends up written, if it is written in a compressed representation.</p>
1653
1654 <p><a id="X84A76F7A7B4166BC" name="X84A76F7A7B4166BC"></a></p>
1655
1656 <h5>24.14-3 ProjectiveOrder</h5>
1657
1658 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ProjectiveOrder</code>( <var class="Arg">mat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1659 <p>Returns an integer n and a finite field element e such that <var class="Arg">A</var>^n = eI. <var class="Arg">mat</var> must be a matrix defined over a finite field.</p>
1660
1661
1662 <div class="example"><pre>
1663 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ProjectiveOrder([[1,4],[5,2]]*Z(11)^0);</span>
1664 [ 5, Z(11)^5 ]
1665 </pre></div>
1666
1667 <p><a id="X847ADC6779E33A1C" name="X847ADC6779E33A1C"></a></p>
1668
1669 <h5>24.14-4 SimultaneousEigenvalues</h5>
1670
1671 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SimultaneousEigenvalues</code>( <var class="Arg">matlist</var>, <var class="Arg">expo</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1672 <p>The matrices in <var class="Arg">matlist</var> must be matrices over GF(<var class="Arg">q</var>) for some prime <var class="Arg">q</var>. Together, they must generate an abelian p-group of exponent <var class="Arg">expo</var>. Then the eigenvalues of <var class="Arg">mat</var> in the splitting field <code class="code">GF(<var class="Arg">q</var>^<var class="Arg">r</var>)</code> for some <var class="Arg">r</var> are powers of an element <span class="SimpleMath">ξ</span> in the splitting field, which is of order <var class="Arg">expo</var>. <code class="func">SimultaneousEigenvalues</code> returns a matrix of integers mod <var class="Arg">expo</var> <span class="SimpleMath">(a_{i,j})</span>, such that the power <span class="SimpleMath">ξ^{a_{i,j}}</span> is an eigenvalue of the <var class="Arg">i</var>-th matrix in <var class="Arg">matlist</var> and the eigenspaces of the different matrices to the eigenvalues <span class="SimpleMath">ξ^{a_{i,j}}</span> for fixed <var class="Arg">j</var> are equal.</p>
1673
1674 <p><a id="X8593A5337D3B2C70" name="X8593A5337D3B2C70"></a></p>
1675
1676 <h4>24.15 <span class="Heading">Inverse and Nullspace of an Integer Matrix Modulo an Ideal</span></h4>
1677
1678 <p>The following operations deal with matrices over a ring, but only care about the residues of their entries modulo some ring element. In the case of the integers and a prime number <span class="SimpleMath">p</span>, this is effectively computation in a matrix over the prime field in characteristic <span class="SimpleMath">p</span>.</p>
1679
1680 <p><a id="X7D8D1E0E83C7F872" name="X7D8D1E0E83C7F872"></a></p>
1681
1682 <h5>24.15-1 InverseMatMod</h5>
1683
1684 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; InverseMatMod</code>( <var class="Arg">mat</var>, <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
1685 <p>For a square matrix <var class="Arg">mat</var>, <code class="func">InverseMatMod</code> returns a matrix <var class="Arg">inv</var> such that <code class="code"><var class="Arg">inv</var> * <var class="Arg">mat</var></code> is congruent to the identity matrix modulo <var class="Arg">obj</var>, if such a matrix exists, and <code class="keyw">fail</code> otherwise.</p>
1686
1687
1688 <div class="example"><pre>
1689 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:= [ [ 1, 2 ], [ 3, 4 ] ];; inv:= InverseMatMod( mat, 5 );</span>
1690 [ [ 3, 1 ], [ 4, 2 ] ]
1691 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat * inv;</span>
1692 [ [ 11, 5 ], [ 25, 11 ] ]
1693 </pre></div>
1694
1695 <p><a id="X7D7DF873826A7C20" name="X7D7DF873826A7C20"></a></p>
1696
1697 <h5>24.15-2 BasisNullspaceModN</h5>
1698
1699 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BasisNullspaceModN</code>( <var class="Arg">M</var>, <var class="Arg">n</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1700 <p><var class="Arg">M</var> must be a matrix of integers and <var class="Arg">n</var> a positive integer. Then <code class="func">BasisNullspaceModN</code> returns a set <var class="Arg">B</var> of vectors such that every vector <var class="Arg">v</var> of integer modulo <var class="Arg">n</var> satisfying <var class="Arg">v</var> <var class="Arg">M</var> = 0 modulo <var class="Arg">n</var> can be expressed by a Z-linear combination of elements of <var class="Arg">B</var>.</p>
1701
1702 <p><a id="X86AE919983B242E2" name="X86AE919983B242E2"></a></p>
1703
1704 <h5>24.15-3 NullspaceModQ</h5>
1705
1706 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NullspaceModQ</code>( <var class="Arg">M</var>, <var class="Arg">q</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1707 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NullspaceModN</code>( <var class="Arg">M</var>, <var class="Arg">n</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1708 <p><var class="Arg">M</var> must be a matrix of integers and <var class="Arg">n</var> a positive integer. Then <code class="func">NullspaceModN</code> returns the set of all vectors of integers modulo <var class="Arg">n</var>, which solve the homogeneous equation system <var class="Arg">v</var> <var class="Arg">M</var> = 0 modulo <var class="Arg">n</var>.</p>
1709
1710 <p><code class="func">NullspaceModQ</code> is a synonym for <code class="func">NullspaceModN</code>.</p>
1711
1712
1713 <div class="example"><pre>
1714 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullspaceModN( [ [ 2 ] ], 8 );</span>
1715 [ [ 0 ], [ 4 ] ]
1716 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullspaceModN( [ [ 2, 1 ], [ 0, 2 ] ], 6 );</span>
1717 [ [ 0, 0 ], [ 0, 3 ] ]
1718 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">mat:= [ [ 1, 3 ], [ 1, 2 ], [ 1, 1 ] ];;</span>
1719 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NullspaceModN( mat, 5 );</span>
1720 [ [ 0, 0, 0 ], [ 1, 3, 1 ], [ 2, 1, 2 ], [ 3, 4, 3 ], [ 4, 2, 4 ] ]
1721 </pre></div>
1722
1723 <p><a id="X787DF5F07DC7D86E" name="X787DF5F07DC7D86E"></a></p>
1724
1725 <h4>24.16 <span class="Heading">Special Multiplication Algorithms for Matrices over GF(2)</span></h4>
1726
1727 <p>When multiplying two compressed matrices <span class="SimpleMath">M</span> and <span class="SimpleMath">N</span> over GF(2) of dimensions <span class="SimpleMath">a × b</span> and <span class="SimpleMath">b × c</span>, where <span class="SimpleMath">a</span>, <span class="SimpleMath">b</span> and <span class="SimpleMath">c</span> are all greater than or equal to 128, <strong class="pkg">GAP</strong> by default uses a more sophisticated matrix multiplication algorithm, in which linear combinations of groups of 8 rows of <span class="SimpleMath">M</span> are remembered and re-used in constructing various rows of the product. This is called level 8 grease. To optimise memory access patterns, these combinations are stored for <span class="SimpleMath">(b+255)/256</span> sets of 8 rows at once. This number is called the blocking level.</p>
1728
1729 <p>These levels of grease and blocking are found experimentally to give good performance across a range of processors and matrix sizes, but other levels may do even better in some cases. You can control the levels exactly using the functions below.</p>
1730
1731 <p>We plan to include greased blocked matrix multiplication for other finite fields, and greased blocked algorithms for inversion and other matrix operations in a future release.</p>
1732
1733 <p><a id="X7C0C26027FAE0C83" name="X7C0C26027FAE0C83"></a></p>
1734
1735 <h5>24.16-1 PROD_GF2MAT_GF2MAT_SIMPLE</h5>
1736
1737 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PROD_GF2MAT_GF2MAT_SIMPLE</code>( <var class="Arg">m1</var>, <var class="Arg">m2</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1738 <p>This function performs the standard unblocked and ungreased matrix multiplication for matrices of any size.</p>
1739
1740 <p><a id="X81965B7D7F45E088" name="X81965B7D7F45E088"></a></p>
1741
1742 <h5>24.16-2 PROD_GF2MAT_GF2MAT_ADVANCED</h5>
1743
1744 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PROD_GF2MAT_GF2MAT_ADVANCED</code>( <var class="Arg">m1</var>, <var class="Arg">m2</var>, <var class="Arg">g</var>, <var class="Arg">b</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1745 <p>This function computes the product of <var class="Arg">m1</var> and <var class="Arg">m2</var>, which must be compressed matrices over GF(2) of compatible dimensions, using level <var class="Arg">g</var> grease and level <var class="Arg">b</var> blocking.</p>
1746
1747 <p><a id="X7F8A71F38201A250" name="X7F8A71F38201A250"></a></p>
1748
1749 <h4>24.17 <span class="Heading">Block Matrices</span></h4>
1750
1751 <p>Block matrices are a special representation of matrices which can save a lot of memory if large matrices have a block structure with lots of zero blocks. <strong class="pkg">GAP</strong> uses the representation <code class="code">IsBlockMatrixRep</code> to store block matrices.</p>
1752
1753 <p><a id="X7D675B3C79CF8871" name="X7D675B3C79CF8871"></a></p>
1754
1755 <h5>24.17-1 AsBlockMatrix</h5>
1756
1757 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; AsBlockMatrix</code>( <var class="Arg">m</var>, <var class="Arg">nrb</var>, <var class="Arg">ncb</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1758 <p>returns a block matrix with <var class="Arg">nrb</var> row blocks and <var class="Arg">ncb</var> column blocks which is equal to the ordinary matrix <var class="Arg">m</var>.</p>
1759
1760 <p><a id="X8633538685551E7A" name="X8633538685551E7A"></a></p>
1761
1762 <h5>24.17-2 BlockMatrix</h5>
1763
1764 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BlockMatrix</code>( <var class="Arg">blocks</var>, <var class="Arg">nrb</var>, <var class="Arg">ncb</var>[, <var class="Arg">rpb</var>, <var class="Arg">cpb</var>, <var class="Arg">zero</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1765 <p><code class="func">BlockMatrix</code> returns an immutable matrix in the sparse representation <code class="code">IsBlockMatrixRep</code>. The nonzero blocks are described by the list <var class="Arg">blocks</var> of triples <span class="SimpleMath">[ <var class="Arg">i</var>, <var class="Arg">j</var>, M(i,j) ]</span> each consisting of a matrix <span class="SimpleMath">M(i,j)</span> and its block coordinates in the block matrix to be constructed. All matrices <span class="SimpleMath">M(i,j)</span> must have the same dimensions. As usual the first coordinate specifies the row and the second one the column. The resulting matrix has <var class="Arg">nrb</var> row blocks and <var class="Arg">ncb</var> column blocks.</p>
1766
1767 <p>If <var class="Arg">blocks</var> is empty (i.e., if the matrix is a zero matrix) then the dimensions of the blocks must be entered as <var class="Arg">rpb</var> and <var class="Arg">cpb</var>, and the zero element as <var class="Arg">zero</var>.</p>
1768
1769 <p>Note that all blocks must be ordinary matrices (see <code class="func">IsOrdinaryMatrix</code> (<a href="chap24.html#X7CF42B8A845BC6A9"><span class="RefLink">24.2-2</span></a>)), and also the block matrix is an ordinary matrix.</p>
1770
1771
1772 <div class="example"><pre>
1773 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">M := BlockMatrix([[1,1,[[1, 2],[ 3, 4]]],</span>
1774 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> [1,2,[[9,10],[11,12]]],</span>
1775 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> [2,2,[[5, 6],[ 7, 8]]]],2,2);</span>
1776 &lt;block matrix of dimensions (2*2)x(2*2)&gt;
1777 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display(M);</span>
1778 [ [ 1, 2, 9, 10 ],
1779 [ 3, 4, 11, 12 ],
1780 [ 0, 0, 5, 6 ],
1781 [ 0, 0, 7, 8 ] ]
1782 </pre></div>
1783
1784 <p><a id="X83FAF4158180041F" name="X83FAF4158180041F"></a></p>
1785
1786 <h5>24.17-3 MatrixByBlockMatrix</h5>
1787
1788 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; MatrixByBlockMatrix</code>( <var class="Arg">blockmat</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
1789 <p>returns a plain ordinary matrix that is equal to the block matrix <var class="Arg">blockmat</var>.</p>
1790
1791 <p><a id="X782F2EBF80C431D0" name="X782F2EBF80C431D0"></a></p>
1792
1793 <h4>24.18 <span class="Heading">Linear Programming</span></h4>
1794
1795 <p><a id="X845D5F8D7D905CB8" name="X845D5F8D7D905CB8"></a></p>
1796
1797 <h5>24.18-1 SimplexMethod</h5>
1798
1799 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SimplexMethod</code>( <var class="Arg">A</var>, <var class="Arg">b</var>, <var class="Arg">c</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
1800 <p>Find a rational vector <var class="Arg">x</var> that maximizes <span class="SimpleMath"><var class="Arg">x</var>cdot<var class="Arg">c</var></span>, subject to the constraint <span class="SimpleMath"><var class="Arg">A</var>cdot<var class="Arg">x</var>le<var class="Arg">b</var></span>.</p>
1801
1802
1803 <div class="example"><pre>
1804 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">A:=[[3,1,1,4],[1,-3,2,3],[2,1,3,-1]];;</span>
1805 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">b:=[12,7,10];;c:=[2,4,3,1];;</span>
1806 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SimplexMethod(A,b,c);</span>
1807 [ [ 0, 52/5, 0, 2/5 ], 42 ]
1808 </pre></div>
1809
1810
1811 <div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap23.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap25.html">[Next Chapter]</a>&nbsp; </div>
1812
1813
1814 <div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
1815
1816 <hr />
1817 <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
1818 </body>
1819 </html>