-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathmatobj.xml
More file actions
568 lines (468 loc) · 20.4 KB
/
matobj.xml
File metadata and controls
568 lines (468 loc) · 20.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- matobj.xml GAP documentation Max Neunhoeffer -->
<!-- -->
<!-- Copyright (C) 2011 The GAP Group -->
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Chapter Label="Vector and Matrix Objects">
<Heading>Vector and Matrix Objects</Heading>
This chapter describes an interface to vector and matrix objects
which are not represented by plain lists (of plain lists),
cf. Chapters <Ref Chap="Row Vectors"/> and <Ref Chap="Matrices"/>.
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Concepts and Rules for Vector and Matrix Objects">
<Heading>Concepts and Rules for Vector and Matrix Objects</Heading>
<#Include Label="MatObj_Overview">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Categories of Vector and Matrix Objects">
<Heading>Categories of Vector and Matrix Objects</Heading>
Currently the following categories of vector and matrix objects
are supported in &GAP;.
More can be added as soon as there is need for them.
<!-- For example, flat matrices? -->
<#Include Label="IsVectorObj">
<#Include Label="IsMatrixObj">
<#Include Label="IsMatrixOrMatrixObj">
<#Include Label="IsRowListMatrix">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Defining Attributes of Vector and Matrix Objects">
<Heading>Defining Attributes of Vector and Matrix Objects</Heading>
<#Include Label="BaseDomain">
<#Include Label="ConstructingFilter">
<#Include Label="CompatibleVectorFilter">
<#Include Label="Length_IsVectorObj">
<#Include Label="NumberRowsNumberColumns">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Constructing Vector and Matrix Objects">
<Heading>Constructing Vector and Matrix Objects</Heading>
<#Include Label="NewVector">
<#Include Label="Vector">
<#Include Label="VectorObj_ZeroVector">
<#Include Label="NewMatrix">
<#Include Label="MatObj_Matrix">
<#Include Label="MatObj_ZeroMatrix">
<#Include Label="MatObj_IdentityMatrix">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Operations for Base Domains of Vector and Matrix Objects">
<Heading>Operations for Base Domains of Vector and Matrix Objects</Heading>
<#Include Label="OneOfBaseDomain">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Operations for Vector and Matrix Objects">
<Heading>Operations for Vector and Matrix Objects</Heading>
<#Include Label="MatrixObjCompare">
<#Include Label="Unpack">
<#Include Label="ChangedBaseDomain">
<#Include Label="Randomize">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="List Like Operations for Vector Objects">
<Heading>List Like Operations for Vector Objects</Heading>
The following operations that are defined for lists are useful
also for vector objects.
(More such operations can be added if this is appropriate.)
<#Include Label="ElementAccessVectorObj">
<#Include Label="MatObj_PositionNonZero">
<#Include Label="MatObj_PositionLastNonZero">
<#Include Label="MatObj_ListOp">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Arithmetical Operations for Vector Objects">
<Heading>Arithmetical Operations for Vector Objects</Heading>
<#Include Label="VectorObj_UnaryArithmetics">
<#Include Label="VectorObj_BinaryArithmetics">
<#Include Label="MatObj_AddVector">
<#Include Label="MatObj_MultVectorLeft">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Operations for Vector Objects">
<Heading>Operations for Vector Objects</Heading>
<#Include Label="MatObj_ConcatenationOfVectors">
<#Include Label="MatObj_ExtractSubVector">
<#Include Label="CopySubVector">
<#Include Label="MatObj_WeightOfVector">
<#Include Label="MatObj_DistanceOfVectors">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Arithmetical Operations for Matrix Objects">
<Heading>Arithmetical Operations for Matrix Objects</Heading>
<#Include Label="MatrixObj_UnaryArithmetics">
<#Include Label="MatrixObj_BinaryArithmetics">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Operations for Matrix Objects">
<Heading>Operations for Matrix Objects</Heading>
<#Include Label="MatObj_MatElm">
<#Include Label="MatObj_SetMatElm">
<#Include Label="ExtractSubMatrix">
<#Include Label="MutableCopyMatrix">
<#Include Label="CopySubMatrix">
<#Include Label="CompatibleVector">
<#Include Label="RowsOfMatrix">
<#Include Label="MatObj_CompanionMatrix">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Operations for Row List Matrix Objects">
<Heading>Operations for Row List Matrix Objects</Heading>
In general, matrix objects are not lists in the sense of <Ref Filt="IsList"/>,
and they need not behave like lists,
that is, they need not obey all the rules for lists that are stated in
Chapter <Ref Chap="Lists"/>.
There are situations where one wants to have matrix objects
that can on the one hand benefit from &GAP;'s method selection,
as is explained in
Section <Ref Sect="Concepts and Rules for Vector and Matrix Objects"/>,
and do on the other hands support access to &GAP; objects that represent
their rows (which are suitable vector objects).
Matrix objects whose
<Ref Attr="ConstructingFilter" Label="for a matrix object"/> value implies
<Ref Filt="IsRowListMatrix"/> support the operations described in this
section.
<P/>
One implementation of such matrices is given by the
<Ref Attr="ConstructingFilter" Label="for a matrix object"/> value
<Ref Filt="IsPlistMatrixRep"/>,
and any row of these matrices is a vector object in
<Ref Filt="IsPlistVectorRep"/>.
Note that these objects do <E>not</E> lie in <Ref Filt="IsList"/>
(and in particular not in <Ref Filt="IsPlistRep"/>),
thus we are allowed to define the above operations only restrictively,
as follows.
<P/>
Unbinding an entry in a row or unbinding a row in a matrix is allowed only
in the last position,
that is, the vector and matrix objects insist on being dense.
All rows of a matrix must have the same length and the same base domain.
<#Include Label="RowListMatObj_[]">
<#Include Label="RowListMatObj_[]_ASS">
<#Include Label="RowListMatObj_{}">
<#Include Label="RowListMatObj_{}_ASS">
<#Include Label="RowListMatObj_IsBound">
<#Include Label="RowListMatObj_Unbind">
<#Include Label="RowListMatObj_Add">
<#Include Label="RowListMatObj_Remove">
<#Include Label="RowListMatObj_Append">
<#Include Label="RowListMatObj_ShallowCopy">
<#Include Label="RowListMatObj_ListOp">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Basic operations for row/column reductions">
<Heading>Basic operations for row/column reductions</Heading>
<#Include Label="MultMatrixRow">
<#Include Label="MultMatrixRowRight">
<#Include Label="MultMatrixColumn">
<#Include Label="MultMatrixColumnLeft">
<#Include Label="AddMatrixRows">
<#Include Label="AddMatrixRowsRight">
<#Include Label="AddMatrixColumns">
<#Include Label="AddMatrixColumnsLeft">
<#Include Label="PositionNonZeroInRow">
<#Include Label="SwapMatrixRows">
<#Include Label="SwapMatrixColumns">
<#Include Label="AddMatrix">
<#Include Label="MultMatrix">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Implementing New Vector and Matrix Objects Types">
<Heading>Implementing New Vector and Matrix Objects Types</Heading>
The first step in the design of a new type of vector or matrix objects
is to create a new filter that serves as the
<Ref Attr="ConstructingFilter" Label="for a vector object"/>
of the new objects,
see the sections <Ref Sect="Available Representations of Vector Objects"/>
and <Ref Sect="Available Representations of Matrix Objects"/>
for an overview of such filters that are already available.
<P/>
Here we list those operations for vector and matrix objects
for which no default methods can be installed.
When one implements a new type of vector or matrix objects
then one has to install specific methods at least for these operations,
in order to make the objects behave as described in this chapter.
It is advisable to install specific methods also for other
operations, for performance reasons.
The installations of default methods can be found in the file
<F>lib/matobj.gi</F> of the &GAP; distribution.
There one can check for which operations it makes sense to overload them
for the new type of vector or matrix objects.
Note that the specific methods must be installed with
<Ref Func="InstallTagBasedMethod"/> whenever the default method is installed
with this function.
<P/>
<E>Vector objects</E>
<List>
<Item>
<Ref Attr="BaseDomain" Label="for a vector object"/>,
</Item>
<Item>
<Ref Attr="Length" Label="for a vector object"/>,
</Item>
<Item>
<Ref Oper="\[\]" Label="for a vector object and an integer"/>,
</Item>
<Item>
<Ref Oper="\[\]\:\=" Label="for a vector object and an integer"/>
(with consistency checks if the global option <C>check</C> is not set to
<K>false</K>),
</Item>
<Item>
<Ref Oper="\<"/> (see <Ref Oper="\<" Label="for two vector objects"/>),
</Item>
<Item>
<Ref Attr="ConstructingFilter" Label="for a vector object"/>,
</Item>
<Item>
<Ref Oper="NewVector"/>
(with consistency checks if the global option <C>check</C> is not set to
<K>false</K>, install the method with <Ref Func="InstallTagBasedMethod"/>).
</Item>
</List>
<P/>
<E>Matrix objects</E>
<List>
<Item>
<Ref Attr="BaseDomain" Label="for a matrix object"/>,
</Item>
<Item>
<Ref Attr="NumberRows" Label="for a matrix object"/>,
</Item>
<Item>
<Ref Attr="NumberColumns" Label="for a matrix object"/>,
</Item>
<Item>
<Ref Oper="MatElm"/>,
</Item>
<Item>
<Ref Oper="SetMatElm"/>
(with consistency checks if the global option <C>check</C> is not set to
<K>false</K>),
</Item>
<Item>
<Ref Oper="\<"/> (see <Ref Oper="\<" Label="for two matrix objects"/>),
</Item>
<Item>
<Ref Attr="ConstructingFilter" Label="for a matrix object"/>,
</Item>
<Item>
<Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/>,
</Item>
<Item>
<Ref Oper="NewMatrix"/>
(with consistency checks if the global option <C>check</C> is not set to
<K>false</K>, install the method with <Ref Func="InstallTagBasedMethod"/>).
</Item>
</List>
<P/>
Methods for <Ref Oper="NewVector"/> and
<Ref Oper="NewMatrix"/> must check their arguments for consistency
(do the given filter and base domain fit together,
are the entries compatible with the given base domain,
is the number of matrix entries a multiple of the given number of columns)
except if the global option <C>check</C> is set to <K>false</K>.
(See Chapter <Ref Chap="Options Stack"/> for information about global
options.)
The same holds for methods for operations that modify mutable vector
or matrix objects,
such as <Ref Oper="\[\]\:\=" Label="for a vector object and an integer"/>,
<Ref Oper="SetMatElm"/>, <Ref Oper="CopySubVector"/>,
<Ref Oper="CopySubMatrix"/>,
and for those methods of
<Ref Oper="Vector" Label="for filter, base domain, and list"/> and
<Ref Oper="Matrix" Label="for filter, base domain, list, ncols"/>
that do not delegate to <Ref Oper="NewVector"/> and
<Ref Oper="NewMatrix"/>, respectively.
<P/>
For the implementation of new vector and matrix object types,
we recommend that the low level function <Ref Func="Objectify"/> gets called
only by some helper functions that handle the choice of the type of
the desired object and the consistency checks for the internal data.
An example can be found in the file <F>lib/matobjplist.gi</F>,
the helper functions are <C>MakeIsPlistVectorRep</C> and
<C>MakeIsPlistMatrixRep</C>.
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Available Representations of Vector Objects">
<Heading>Available Representations of Vector Objects</Heading>
The following filters define vector objects for which the the functionality
described in this chapter is supported.
<#Include Label="IsGF2VectorRep">
<#Include Label="Is8BitVectorRep">
<#Include Label="IsPlistVectorRep">
<#Include Label="IsZmodnZVectorRep">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Available Representations of Matrix Objects">
<Heading>Available Representations of Matrix Objects</Heading>
The following filters define matrix objects for which the the functionality
described in this chapter is supported.
<#Include Label="IsGF2MatrixRep">
<#Include Label="Is8BitMatrixRep">
<#Include Label="IsPlistMatrixRep">
<#Include Label="IsZmodnZMatrixRep">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Groups Consisting of Matrix Objects">
<Heading>Groups Consisting of Matrix Objects</Heading>
One application of matrix objects is to construct groups whose elements
are matrix objects.
The following conventions hold for such a group <C>G</C>.
<List>
<Item>
All elements of <C>G</C> have the same
<Ref Attr="ConstructingFilter" Label="for a matrix object"/>
and the same <Ref Attr="BaseDomain" Label="for a matrix object"/>.
For a given matrix or matrix object <C>M</C>,
a matrix object that can be multiplied with elements of <C>G</C>
can be constructed as <C>Matrix( M, Representative( G ) )</C>,
and the result can be tested for membership in <C>G</C>.
</Item>
</List>
<#Include Label="ConstructingFiltersForMatrixGroupElements">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="How to Write Code for Vector and Matrix Objects">
<Heading>How to Write Code for Vector and Matrix Objects</Heading>
Vector and matrix objects have a number of different representations in &GAP;
which are optimised for different things;
see the list <Ref Var="ConstructingFiltersForMatrixGroupElements"/> for
examples of available
<Ref Attr="ConstructingFilter" Label="for a matrix object"/> values
of matrix objects.
Most &GAP; functions accepting vector or matrix objects as arguments
do not depend on any particular representation for these objects.
If the output of such a function involves vector and matrix objects,
then these are expected to have the same representations as the inputs.
For example, a function that computes the Kronecker product of two
matrix objects <C>mat1</C>, <C>mat2</C> may take the two inputs,
which must have the same
<Ref Attr="ConstructingFilter" Label="for a matrix object"/> value,
create a new matrix object which also lies in this filter,
for example by calling <C>ZeroMatrix( m, n, mat1 )</C>,
and then set the entries in this matrix.
<P/>
Functions like
<Ref Oper="ZeroMatrix" Label="for dimensions and matrix object"/>,
<Ref Oper="IdentityMatrix" Label="for dimension and matrix object"/>,
and <Ref Oper="Matrix" Label="for a list and a matrix object"/>
admit different kinds of inputs.
<C>ZeroMatrix( R, m, n )</C> can be used, for example,
if we want to leave the decision about the representation of the result
to &GAP;.
This might be useful if the result of <C>ZeroMatrix( R, m, n )</C> is
the first matrix we create, and then later matrices are created
relative to this matrix.
If we already have a matrix object <C>M</C> and want <C>ZeroMatrix</C>
to return a new matrix object that has the same representation as <C>M</C>,
then <C>ZeroMatrix( R, m, n )</C> may not return a matrix with the expected
representation.
For example, even if we use the same <C>R</C> as before, &GAP; might decide
to use a sparse representation for large enough <C>m</C> and <C>n</C>.
It is possible to create a <C>ZeroMatrix</C> in the same representation
as <C>M</C> by fully specifying this representation as follows
<C>ZeroMatrix( ConstructingFilter( M ), BaseDomain( M ), m, n )</C>.
It is also possible to produce the same result using the more convenient
<C>ZeroMatrix( m, n, M )</C>.
<P/>
This approach works also in many situation where the input involves
the <Q>list of list</Q> matrices in the filter <Ref Filt="IsMatrix"/>.
In practice, the question is often the other way round:
one has old &GAP; code that was written for objects in <Ref Filt="IsMatrix"/>,
and wants to rewrite it such that it works for general matrix objects also.
In such cases, the following guidelines may be useful.
<List>
<Item>
Use <C>M[i, j]</C> not <C>M[i][j]</C>
for accessing/assigning matrix entries.
<P/>
<E>Reason:</E>
<C>M[i][j]</C> means to fetch or even create <C>M[i]</C>
and then take the <C>j</C>-th entry of it.
</Item>
<Item>
Use <C>ExtractSubMatrix( M, rows, cols )</C> not <C>M{ rows }{ cols }</C>
for accessing submatrices,
similarly use <C>CopySubMatrix( src, dst, srows, drows, scols, dcols )</C>.
<P/>
<E>Reason:</E>
The <C>M{ rows }</C> syntax is supported only for
row-list matrices, see <Ref Filt="IsRowListMatrix"/>.
</Item>
<Item>
Use <C>ZeroVector( R, n )</C> not <C>[ 1 .. n ] * Zero( R )</C> for
creating a zero vector over a given domain <C>R</C>.
<P/>
<E>Reason:</E>
The latter syntax creates an unnecessary new object <C>[ 1 .. n ]</C>,
multiplies each of its entries with <C>Zero( R )</C>
(not knowing that the result will be <C>Zero( R )</C> in each case),
and creates not a vector object but a plain list of the results.
</Item>
<Item>
Use <C>ZeroVector( n, M )</C> not <C>0 * M[1]</C> for a
given matrix object <C>M</C> with <C>n</C> columns.
<P/>
<E>Reason:</E>
Calling <C>M[1]</C> may have to create an unnecessary new object
<C>M[1]</C>.
</Item>
<Item>
Use <Ref Attr="BaseDomain" Label="for a matrix object"/>
not <Ref Attr="DefaultFieldOfMatrix"/>.
<P/>
<E>Reason:</E>
This is just a conceptual issue, the results should in fact coincide.
A matrix object <C>M</C> which is not a list of lists stores its
<Ref Attr="BaseDomain" Label="for a matrix object"/> value.
For convenience, <C>DefaultFieldOfMatrix( M )</C> is defined
to return this value (although this need not be a field).
On the other hand, a list of lists <C>M</C> in <Ref Filt="IsMatrix"/>
does not store the two attribute values,
<Ref Attr="DefaultFieldOfMatrix"/> value is computed from the entries
of <C>M</C>,
and for convenience, <C>BaseDomain( M )</C> is defined to return the
<Ref Attr="DefaultFieldOfMatrix"/> value.
</Item>
<Item>
Do not use the unary versions of
<Ref Func="ConvertToVectorRep" Label="for a list (and a field)"/>
and <Ref Func="ConvertToMatrixRep" Label="for a list (and a field)"/>.
<P/>
<E>Reason:</E>
For example, consider the two matrices <C>M1 = [ [ Z(4) ] ]</C> and
<C>M2 = [ [ Z(4)^3 ] ]</C> over the field with four elements.
The latter is in fact a matrix over the field with two elements,
and <C>ConvertToMatrixRep( M2 )</C> turns it into a matrix in
<Ref Filt="IsGF2MatrixRep"/>, whereas <C>ConvertToMatrixRep( M1 )</C>
yields a matrix in <Ref Filt="Is8BitMatrixRep"/>.
Thus computing products or sums of these matrices is more expensive
than computations with two matrices in <Ref Filt="Is8BitMatrixRep"/>.
</Item>
<Item>
Use <Ref Oper="ImmutableMatrix"/> and the binary versions of
<Ref Func="ConvertToVectorRep" Label="for a list (and a field)"/>
and <Ref Func="ConvertToMatrixRep" Label="for a list (and a field)"/>
only when creating initial objects
which need not be compatible with given vectors or matrices.
<P/>
<E>Reason:</E>
The idea behind these functions is to choose a good representation
for initial data (for example for some expensive MeatAxe computations,
see Chapter <Ref Chap="The MeatAxe"/>).
The results of computations with these data should then automatically
be in the same representation.
If not then the code in question has problems,
and <Q>adjusting</Q> the representation of intermediate results by
calling the abovementioned conversion functions just hides these problems.
</Item>
</List>
Conversely, do <E>not</E> use functions for vector and matrix objects
when you want to create an object that shall be used just as a list.
For example, use <C>ListWithIdenticalEntries( n, Zero( R ) )</C>
not <C>Vector( R, n )</C> in this case.
For creating a list with <C>n</C> entries, you can also first call
<Ref Func="EmptyPlist"/> for creating a big enough list,
and then enter the values.
</Section>
</Chapter>