CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
B The Matrix Tool Operations
3
4
The functions listed below are components of the homalgTable object stored
5
in the ring. They are only indirectly accessible through standard methods
6
that invoke them.
7
8
9
B.1 The Tool Operations without a Fallback Method
10
11
There are matrix methods for which homalg needs a homalgTable entry for
12
non-internal rings, as it cannot provide a suitable fallback. Below is the
13
list of these homalgTable entries.
14
15
B.1-1 InitialMatrix
16
17
InitialMatrix( C )  function
18
Returns: the Eval value of a homalg matrix C
19
20
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
21
component RP!.InitialMatrix is bound then the method Eval (C.4-1) resets the
22
filter IsInitialMatrix and returns RP!.InitialMatrix( C ).
23
24
B.1-2 InitialIdentityMatrix
25
26
InitialIdentityMatrix( C )  function
27
Returns: the Eval value of a homalg matrix C
28
29
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
30
component RP!.InitialIdentityMatrix is bound then the method Eval (C.4-2)
31
resets the filter IsInitialIdentityMatrix and returns
32
RP!.InitialIdentityMatrix( C ).
33
34
B.1-3 ZeroMatrix
35
36
ZeroMatrix( C )  function
37
Returns: the Eval value of a homalg matrix C
38
39
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
40
component RP!.ZeroMatrix is bound then the method Eval (C.4-3) returns
41
RP!.ZeroMatrix( C ).
42
43
B.1-4 IdentityMatrix
44
45
IdentityMatrix( C )  function
46
Returns: the Eval value of a homalg matrix C
47
48
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
49
component RP!.IdentityMatrix is bound then the method Eval (C.4-4) returns
50
RP!.IdentityMatrix( C ).
51
52
B.1-5 Involution
53
54
Involution( M )  function
55
Returns: the Eval value of a homalg matrix C
56
57
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
58
component RP!.Involution is bound then the method Eval (C.4-7) returns
59
RP!.Involution applied to the content of the attribute EvalInvolution( C ) =
60
M.
61
62
B.1-6 CertainRows
63
64
CertainRows( M, plist )  function
65
Returns: the Eval value of a homalg matrix C
66
67
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
68
component RP!.CertainRows is bound then the method Eval (C.4-8) returns
69
RP!.CertainRows applied to the content of the attribute EvalCertainRows( C )
70
= [ M, plist ].
71
72
B.1-7 CertainColumns
73
74
CertainColumns( M, plist )  function
75
Returns: the Eval value of a homalg matrix C
76
77
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
78
component RP!.CertainColumns is bound then the method Eval (C.4-9) returns
79
RP!.CertainColumns applied to the content of the attribute
80
EvalCertainColumns( C ) = [ M, plist ].
81
82
B.1-8 UnionOfRows
83
84
UnionOfRows( A, B )  function
85
Returns: the Eval value of a homalg matrix C
86
87
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
88
component RP!.UnionOfRows is bound then the method Eval (C.4-10) returns
89
RP!.UnionOfRows applied to the content of the attribute EvalUnionOfRows( C )
90
= [ A, B ].
91
92
B.1-9 UnionOfColumns
93
94
UnionOfColumns( A, B )  function
95
Returns: the Eval value of a homalg matrix C
96
97
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
98
component RP!.UnionOfColumns is bound then the method Eval (C.4-11) returns
99
RP!.UnionOfColumns applied to the content of the attribute
100
EvalUnionOfColumns( C ) = [ A, B ].
101
102
B.1-10 DiagMat
103
104
DiagMat( e )  function
105
Returns: the Eval value of a homalg matrix C
106
107
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
108
component RP!.DiagMat is bound then the method Eval (C.4-12) returns
109
RP!.DiagMat applied to the content of the attribute EvalDiagMat( C ) = e.
110
111
B.1-11 KroneckerMat
112
113
KroneckerMat( A, B )  function
114
Returns: the Eval value of a homalg matrix C
115
116
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
117
component RP!.KroneckerMat is bound then the method Eval (C.4-13) returns
118
RP!.KroneckerMat applied to the content of the attribute EvalKroneckerMat( C
119
) = [ A, B ].
120
121
B.1-12 MulMat
122
123
MulMat( a, A )  function
124
Returns: the Eval value of a homalg matrix C
125
126
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
127
component RP!.MulMat is bound then the method Eval (C.4-14) returns
128
RP!.MulMat applied to the content of the attribute EvalMulMat( C ) = [ a, A
129
].
130
131
B.1-13 AddMat
132
133
AddMat( A, B )  function
134
Returns: the Eval value of a homalg matrix C
135
136
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
137
component RP!.AddMat is bound then the method Eval (C.4-15) returns
138
RP!.AddMat applied to the content of the attribute EvalAddMat( C ) = [ A, B
139
].
140
141
B.1-14 SubMat
142
143
SubMat( A, B )  function
144
Returns: the Eval value of a homalg matrix C
145
146
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
147
component RP!.SubMat is bound then the method Eval (C.4-16) returns
148
RP!.SubMat applied to the content of the attribute EvalSubMat( C ) = [ A, B
149
].
150
151
B.1-15 Compose
152
153
Compose( A, B )  function
154
Returns: the Eval value of a homalg matrix C
155
156
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
157
component RP!.Compose is bound then the method Eval (C.4-17) returns
158
RP!.Compose applied to the content of the attribute EvalCompose( C ) = [ A,
159
B ].
160
161
B.1-16 IsZeroMatrix
162
163
IsZeroMatrix( M )  function
164
Returns: true or false
165
166
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
167
component RP!.IsZeroMatrix is bound then the standard method for the
168
property IsZero (5.3-1) shown below returns RP!.IsZeroMatrix( M ).
169
170
 Code 
171
InstallMethod( IsZero,
172
 "for homalg matrices",
173
 [ IsHomalgMatrix ],
174
 
175
 function( M )
176
 local R, RP;
177
 
178
 R := HomalgRing( M );
179
 
180
 RP := homalgTable( R );
181
 
182
 if IsBound(RP!.IsZeroMatrix) then
183
 ## CAUTION: the external system must be able
184
 ## to check zero modulo possible ring relations!
185
 
186
 return RP!.IsZeroMatrix( M ); ## with this, \= can fall back to IsZero
187
 fi;
188
 
189
 #=====# the fallback method #=====#
190
 
191
 ## from the GAP4 documentation: ?Zero
192
 ## `ZeroSameMutability( <obj> )' is equivalent to `0 * <obj>'.
193
 
194
 return M = 0 * M; ## hence, by default, IsZero falls back to \= (see below)
195
 
196
end );
197

198
199
B.1-17 NrRows
200
201
NrRows( C )  function
202
Returns: a nonnegative integer
203
204
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
205
component RP!.NrRows is bound then the standard method for the attribute
206
NrRows (5.4-1) shown below returns RP!.NrRows( C ).
207
208
 Code 
209
InstallMethod( NrRows,
210
 "for homalg matrices",
211
 [ IsHomalgMatrix ],
212
 
213
 function( C )
214
 local R, RP;
215
 
216
 R := HomalgRing( C );
217
 
218
 RP := homalgTable( R );
219
 
220
 if IsBound(RP!.NrRows) then
221
 return RP!.NrRows( C );
222
 fi;
223
 
224
 if not IsHomalgInternalMatrixRep( C ) then
225
 Error( "could not find a procedure called NrRows ",
226
 "in the homalgTable of the non-internal ring\n" );
227
 fi;
228
 
229
 #=====# can only work for homalg internal matrices #=====#
230
 
231
 return Length( Eval( C )!.matrix );
232
 
233
end );
234

235
236
B.1-18 NrColumns
237
238
NrColumns( C )  function
239
Returns: a nonnegative integer
240
241
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
242
component RP!.NrColumns is bound then the standard method for the attribute
243
NrColumns (5.4-2) shown below returns RP!.NrColumns( C ).
244
245
 Code 
246
InstallMethod( NrColumns,
247
 "for homalg matrices",
248
 [ IsHomalgMatrix ],
249
 
250
 function( C )
251
 local R, RP;
252
 
253
 R := HomalgRing( C );
254
 
255
 RP := homalgTable( R );
256
 
257
 if IsBound(RP!.NrColumns) then
258
 return RP!.NrColumns( C );
259
 fi;
260
 
261
 if not IsHomalgInternalMatrixRep( C ) then
262
 Error( "could not find a procedure called NrColumns ",
263
 "in the homalgTable of the non-internal ring\n" );
264
 fi;
265
 
266
 #=====# can only work for homalg internal matrices #=====#
267
 
268
 return Length( Eval( C )!.matrix[ 1 ] );
269
 
270
end );
271

272
273
B.1-19 Determinant
274
275
Determinant( C )  function
276
Returns: a ring element
277
278
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
279
component RP!.Determinant is bound then the standard method for the
280
attribute DeterminantMat (5.4-3) shown below returns RP!.Determinant( C ).
281
282
 Code 
283
InstallMethod( DeterminantMat,
284
 "for homalg matrices",
285
 [ IsHomalgMatrix ],
286
 
287
 function( C )
288
 local R, RP;
289
 
290
 R := HomalgRing( C );
291
 
292
 RP := homalgTable( R );
293
 
294
 if NrRows( C ) <> NrColumns( C ) then
295
 Error( "the matrix is not a square matrix\n" );
296
 fi;
297
 
298
 if IsEmptyMatrix( C ) then
299
 return One( R );
300
 elif IsZero( C ) then
301
 return Zero( R );
302
 fi;
303
 
304
 if IsBound(RP!.Determinant) then
305
 return RingElementConstructor( R )( RP!.Determinant( C ), R );
306
 fi;
307
 
308
 if not IsHomalgInternalMatrixRep( C ) then
309
 Error( "could not find a procedure called Determinant ",
310
 "in the homalgTable of the non-internal ring\n" );
311
 fi;
312
 
313
 #=====# can only work for homalg internal matrices #=====#
314
 
315
 return Determinant( Eval( C )!.matrix );
316
 
317
end );
318

319

320
InstallMethod( Determinant,
321
 "for homalg matrices",
322
 [ IsHomalgMatrix ],
323
 
324
 function( C )
325
 
326
 return DeterminantMat( C );
327
 
328
end );
329

330
331
332
B.2 The Tool Operations with a Fallback Method
333
334
These are the methods for which it is recommended for performance reasons to
335
have a homalgTable entry for non-internal rings. homalg only provides a
336
generic fallback method.
337
338
B.2-1 AreEqualMatrices
339
340
AreEqualMatrices( M1, M2 )  function
341
Returns: true or false
342
343
Let R := HomalgRing( M1 ) and RP := homalgTable( R ). If the homalgTable
344
component RP!.AreEqualMatrices is bound then the standard method for the
345
operation \= (5.5-17) shown below returns RP!.AreEqualMatrices( M1, M2 ).
346
347
 Code 
348
InstallMethod( \=,
349
 "for homalg comparable matrices",
350
 [ IsHomalgMatrix, IsHomalgMatrix ],
351
 
352
 function( M1, M2 )
353
 local R, RP, are_equal;
354
 
355
 ## do not touch mutable matrices
356
 if not ( IsMutable( M1 ) or IsMutable( M2 ) ) then
357
 
358
 if IsBound( M1!.AreEqual ) then
359
 are_equal := _ElmWPObj_ForHomalg( M1!.AreEqual, M2, fail );
360
 if are_equal <> fail then
361
 return are_equal;
362
 fi;
363
 else
364
 M1!.AreEqual :=
365
 ContainerForWeakPointers(
366
 TheTypeContainerForWeakPointersOnComputedValues,
367
 [ "operation", "AreEqual" ] );
368
 fi;
369
 
370
 if IsBound( M2!.AreEqual ) then
371
 are_equal := _ElmWPObj_ForHomalg( M2!.AreEqual, M1, fail );
372
 if are_equal <> fail then
373
 return are_equal;
374
 fi;
375
 fi;
376
 ## do not store things symmetrically below to ``save'' memory
377
 
378
 fi;
379
 
380
 R := HomalgRing( M1 );
381
 
382
 RP := homalgTable( R );
383
 
384
 if IsBound(RP!.AreEqualMatrices) then
385
 ## CAUTION: the external system must be able to check equality
386
 ## modulo possible ring relations (known to the external system)!
387
 are_equal := RP!.AreEqualMatrices( M1, M2 );
388
 elif IsBound(RP!.Equal) then
389
 ## CAUTION: the external system must be able to check equality
390
 ## modulo possible ring relations (known to the external system)!
391
 are_equal := RP!.Equal( M1, M2 );
392
 elif IsBound(RP!.IsZeroMatrix) then ## ensuring this avoids infinite loops
393
 are_equal := IsZero( M1 - M2 );
394
 fi;
395
 
396
 if IsBound( are_equal ) then
397
 
398
 ## do not touch mutable matrices
399
 if not ( IsMutable( M1 ) or IsMutable( M2 ) ) then
400
 
401
 if are_equal then
402
 MatchPropertiesAndAttributes( M1, M2,
403
 LIMAT.intrinsic_properties,
404
 LIMAT.intrinsic_attributes,
405
 LIMAT.intrinsic_components
406
 );
407
 fi;
408
 
409
 ## do not store things symmetrically to ``save'' memory
410
 _AddTwoElmWPObj_ForHomalg( M1!.AreEqual, M2, are_equal );
411
 
412
 fi;
413
 
414
 return are_equal;
415
 fi;
416
 
417
 TryNextMethod( );
418
 
419
end );
420

421
422
B.2-2 IsIdentityMatrix
423
424
IsIdentityMatrix( M )  function
425
Returns: true or false
426
427
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
428
component RP!.IsIdentityMatrix is bound then the standard method for the
429
property IsOne (5.3-2) shown below returns RP!.IsIdentityMatrix( M ).
430
431
 Code 
432
InstallMethod( IsOne,
433
 "for homalg matrices",
434
 [ IsHomalgMatrix ],
435
 
436
 function( M )
437
 local R, RP;
438
 
439
 if NrRows( M ) <> NrColumns( M ) then
440
 return false;
441
 fi;
442
 
443
 R := HomalgRing( M );
444
 
445
 RP := homalgTable( R );
446
 
447
 if IsBound(RP!.IsIdentityMatrix) then
448
 return RP!.IsIdentityMatrix( M );
449
 fi;
450
 
451
 #=====# the fallback method #=====#
452
 
453
 return M = HomalgIdentityMatrix( NrRows( M ), HomalgRing( M ) );
454
 
455
end );
456

457
458
B.2-3 IsDiagonalMatrix
459
460
IsDiagonalMatrix( M )  function
461
Returns: true or false
462
463
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
464
component RP!.IsDiagonalMatrix is bound then the standard method for the
465
property IsDiagonalMatrix (5.3-13) shown below returns RP!.IsDiagonalMatrix(
466
M ).
467
468
 Code 
469
InstallMethod( IsDiagonalMatrix,
470
 "for homalg matrices",
471
 [ IsHomalgMatrix ],
472
 
473
 function( M )
474
 local R, RP, diag;
475
 
476
 R := HomalgRing( M );
477
 
478
 RP := homalgTable( R );
479
 
480
 if IsBound(RP!.IsDiagonalMatrix) then
481
 return RP!.IsDiagonalMatrix( M );
482
 fi;
483
 
484
 #=====# the fallback method #=====#
485
 
486
 diag := DiagonalEntries( M );
487
 
488
 return M = HomalgDiagonalMatrix( diag, NrRows( M ), NrColumns( M ), R );
489
 
490
end );
491

492
493
B.2-4 ZeroRows
494
495
ZeroRows( C )  function
496
Returns: a (possibly empty) list of positive integers
497
498
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
499
component RP!.ZeroRows is bound then the standard method of the attribute
500
ZeroRows (5.4-4) shown below returns RP!.ZeroRows( C ).
501
502
 Code 
503
InstallMethod( ZeroRows,
504
 "for homalg matrices",
505
 [ IsHomalgMatrix ],
506
 
507
 function( C )
508
 local R, RP, z;
509
 
510
 R := HomalgRing( C );
511
 
512
 RP := homalgTable( R );
513
 
514
 if IsBound(RP!.ZeroRows) then
515
 return RP!.ZeroRows( C );
516
 fi;
517
 
518
 #=====# the fallback method #=====#
519
 
520
 z := HomalgZeroMatrix( 1, NrColumns( C ), R );
521
 
522
 return Filtered( [ 1 .. NrRows( C ) ], a -> CertainRows( C, [ a ] ) = z );
523
 
524
end );
525

526
527
B.2-5 ZeroColumns
528
529
ZeroColumns( C )  function
530
Returns: a (possibly empty) list of positive integers
531
532
Let R := HomalgRing( C ) and RP := homalgTable( R ). If the homalgTable
533
component RP!.ZeroColumns is bound then the standard method of the attribute
534
ZeroColumns (5.4-5) shown below returns RP!.ZeroColumns( C ).
535
536
 Code 
537
InstallMethod( ZeroColumns,
538
 "for homalg matrices",
539
 [ IsHomalgMatrix ],
540
 
541
 function( C )
542
 local R, RP, z;
543
 
544
 R := HomalgRing( C );
545
 
546
 RP := homalgTable( R );
547
 
548
 if IsBound(RP!.ZeroColumns) then
549
 return RP!.ZeroColumns( C );
550
 fi;
551
 
552
 #=====# the fallback method #=====#
553
 
554
 z := HomalgZeroMatrix( NrRows( C ), 1, R );
555
 
556
 return Filtered( [ 1 .. NrColumns( C ) ], a -> CertainColumns( C, [ a ] ) = z );
557
 
558
end );
559

560
561
B.2-6 GetColumnIndependentUnitPositions
562
563
GetColumnIndependentUnitPositions( M, poslist )  function
564
Returns: a (possibly empty) list of pairs of positive integers
565
566
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
567
component RP!.GetColumnIndependentUnitPositions is bound then the standard
568
method of the operation GetColumnIndependentUnitPositions (5.5-18) shown
569
below returns RP!.GetColumnIndependentUnitPositions( M, poslist ).
570
571
 Code 
572
InstallMethod( GetColumnIndependentUnitPositions,
573
 "for homalg matrices",
574
 [ IsHomalgMatrix, IsHomogeneousList ],
575
 
576
 function( M, poslist )
577
 local cache, R, RP, rest, pos, i, j, k;
578
 
579
 if IsBound( M!.GetColumnIndependentUnitPositions ) then
580
 cache := M!.GetColumnIndependentUnitPositions;
581
 if IsBound( cache.(String( poslist )) ) then
582
 return cache.(String( poslist ));
583
 fi;
584
 else
585
 cache := rec( );
586
 M!.GetColumnIndependentUnitPositions := cache;
587
 fi;
588
 
589
 R := HomalgRing( M );
590
 
591
 RP := homalgTable( R );
592
 
593
 if IsBound(RP!.GetColumnIndependentUnitPositions) then
594
 pos := RP!.GetColumnIndependentUnitPositions( M, poslist );
595
 if pos <> [ ] then
596
 SetIsZero( M, false );
597
 fi;
598
 cache.(String( poslist )) := pos;
599
 return pos;
600
 fi;
601
 
602
 #=====# the fallback method #=====#
603
 
604
 rest := [ 1 .. NrColumns( M ) ];
605
 
606
 pos := [ ];
607
 
608
 for i in [ 1 .. NrRows( M ) ] do
609
 for k in Reversed( rest ) do
610
 if not [ i, k ] in poslist and
611
 IsUnit( R, MatElm( M, i, k ) ) then
612
 Add( pos, [ i, k ] );
613
 rest := Filtered( rest,
614
 a -> IsZero( MatElm( M, i, a ) ) );
615
 break;
616
 fi;
617
 od;
618
 od;
619
 
620
 if pos <> [ ] then
621
 SetIsZero( M, false );
622
 fi;
623
 
624
 cache.(String( poslist )) := pos;
625
 
626
 return pos;
627
 
628
end );
629

630
631
B.2-7 GetRowIndependentUnitPositions
632
633
GetRowIndependentUnitPositions( M, poslist )  function
634
Returns: a (possibly empty) list of pairs of positive integers
635
636
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
637
component RP!.GetRowIndependentUnitPositions is bound then the standard
638
method of the operation GetRowIndependentUnitPositions (5.5-19) shown below
639
returns RP!.GetRowIndependentUnitPositions( M, poslist ).
640
641
 Code 
642
InstallMethod( GetRowIndependentUnitPositions,
643
 "for homalg matrices",
644
 [ IsHomalgMatrix, IsHomogeneousList ],
645
 
646
 function( M, poslist )
647
 local cache, R, RP, rest, pos, j, i, k;
648
 
649
 if IsBound( M!.GetRowIndependentUnitPositions ) then
650
 cache := M!.GetRowIndependentUnitPositions;
651
 if IsBound( cache.(String( poslist )) ) then
652
 return cache.(String( poslist ));
653
 fi;
654
 else
655
 cache := rec( );
656
 M!.GetRowIndependentUnitPositions := cache;
657
 fi;
658
 
659
 R := HomalgRing( M );
660
 
661
 RP := homalgTable( R );
662
 
663
 if IsBound(RP!.GetRowIndependentUnitPositions) then
664
 pos := RP!.GetRowIndependentUnitPositions( M, poslist );
665
 if pos <> [ ] then
666
 SetIsZero( M, false );
667
 fi;
668
 cache.( String( poslist ) ) := pos;
669
 return pos;
670
 fi;
671
 
672
 #=====# the fallback method #=====#
673
 
674
 rest := [ 1 .. NrRows( M ) ];
675
 
676
 pos := [ ];
677
 
678
 for j in [ 1 .. NrColumns( M ) ] do
679
 for k in Reversed( rest ) do
680
 if not [ j, k ] in poslist and
681
 IsUnit( R, MatElm( M, k, j ) ) then
682
 Add( pos, [ j, k ] );
683
 rest := Filtered( rest,
684
 a -> IsZero( MatElm( M, a, j ) ) );
685
 break;
686
 fi;
687
 od;
688
 od;
689
 
690
 if pos <> [ ] then
691
 SetIsZero( M, false );
692
 fi;
693
 
694
 cache.( String( poslist ) ) := pos;
695
 
696
 return pos;
697
 
698
end );
699

700
701
B.2-8 GetUnitPosition
702
703
GetUnitPosition( M, poslist )  function
704
Returns: a (possibly empty) list of pairs of positive integers
705
706
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
707
component RP!.GetUnitPosition is bound then the standard method of the
708
operation GetUnitPosition (5.5-20) shown below returns RP!.GetUnitPosition(
709
M, poslist ).
710
711
 Code 
712
InstallMethod( GetUnitPosition,
713
 "for homalg matrices",
714
 [ IsHomalgMatrix, IsHomogeneousList ],
715
 
716
 function( M, poslist )
717
 local R, RP, pos, m, n, i, j;
718
 
719
 R := HomalgRing( M );
720
 
721
 RP := homalgTable( R );
722
 
723
 if IsBound(RP!.GetUnitPosition) then
724
 pos := RP!.GetUnitPosition( M, poslist );
725
 if IsList( pos ) and IsPosInt( pos[1] ) and IsPosInt( pos[2] ) then
726
 SetIsZero( M, false );
727
 fi;
728
 return pos;
729
 fi;
730
 
731
 #=====# the fallback method #=====#
732
 
733
 m := NrRows( M );
734
 n := NrColumns( M );
735
 
736
 for i in [ 1 .. m ] do
737
 for j in [ 1 .. n ] do
738
 if not [ i, j ] in poslist and not j in poslist and
739
 IsUnit( R, MatElm( M, i, j ) ) then
740
 SetIsZero( M, false );
741
 return [ i, j ];
742
 fi;
743
 od;
744
 od;
745
 
746
 return fail;
747
 
748
end );
749

750
751
B.2-9 PositionOfFirstNonZeroEntryPerRow
752
753
PositionOfFirstNonZeroEntryPerRow( M, poslist )  function
754
Returns: a list of nonnegative integers
755
756
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
757
component RP!.PositionOfFirstNonZeroEntryPerRow is bound then the standard
758
method of the attribute PositionOfFirstNonZeroEntryPerRow (5.4-8) shown
759
below returns RP!.PositionOfFirstNonZeroEntryPerRow( M ).
760
761
 Code 
762
InstallMethod( PositionOfFirstNonZeroEntryPerRow,
763
 "for homalg matrices",
764
 [ IsHomalgMatrix ],
765
 
766
 function( M )
767
 local R, RP, pos, entries, r, c, i, k, j;
768
 
769
 R := HomalgRing( M );
770
 
771
 RP := homalgTable( R );
772
 
773
 if IsBound(RP!.PositionOfFirstNonZeroEntryPerRow) then
774
 return RP!.PositionOfFirstNonZeroEntryPerRow( M );
775
 elif IsBound(RP!.PositionOfFirstNonZeroEntryPerColumn) then
776
 return PositionOfFirstNonZeroEntryPerColumn( Involution( M ) );
777
 fi;
778
 
779
 #=====# the fallback method #=====#
780
 
781
 entries := EntriesOfHomalgMatrix( M );
782
 
783
 r := NrRows( M );
784
 c := NrColumns( M );
785
 
786
 pos := ListWithIdenticalEntries( r, 0 );
787
 
788
 for i in [ 1 .. r ] do
789
 k := (i - 1) * c;
790
 for j in [ 1 .. c ] do
791
 if not IsZero( entries[k + j] ) then
792
 pos[i] := j;
793
 break;
794
 fi;
795
 od;
796
 od;
797
 
798
 return pos;
799
 
800
end );
801

802
803
B.2-10 PositionOfFirstNonZeroEntryPerColumn
804
805
PositionOfFirstNonZeroEntryPerColumn( M, poslist )  function
806
Returns: a list of nonnegative integers
807
808
Let R := HomalgRing( M ) and RP := homalgTable( R ). If the homalgTable
809
component RP!.PositionOfFirstNonZeroEntryPerColumn is bound then the
810
standard method of the attribute PositionOfFirstNonZeroEntryPerColumn
811
(5.4-9) shown below returns RP!.PositionOfFirstNonZeroEntryPerColumn( M ).
812
813
 Code 
814
InstallMethod( PositionOfFirstNonZeroEntryPerColumn,
815
 "for homalg matrices",
816
 [ IsHomalgMatrix ],
817
 
818
 function( M )
819
 local R, RP, pos, entries, r, c, j, i, k;
820
 
821
 R := HomalgRing( M );
822
 
823
 RP := homalgTable( R );
824
 
825
 if IsBound(RP!.PositionOfFirstNonZeroEntryPerColumn) then
826
 return RP!.PositionOfFirstNonZeroEntryPerColumn( M );
827
 elif IsBound(RP!.PositionOfFirstNonZeroEntryPerRow) then
828
 return PositionOfFirstNonZeroEntryPerRow( Involution( M ) );
829
 fi;
830
 
831
 #=====# the fallback method #=====#
832
 
833
 entries := EntriesOfHomalgMatrix( M );
834
 
835
 r := NrRows( M );
836
 c := NrColumns( M );
837
 
838
 pos := ListWithIdenticalEntries( c, 0 );
839
 
840
 for j in [ 1 .. c ] do
841
 for i in [ 1 .. r ] do
842
 k := (i - 1) * c;
843
 if not IsZero( entries[k + j] ) then
844
 pos[j] := i;
845
 break;
846
 fi;
847
 od;
848
 od;
849
 
850
 return pos;
851
 
852
end );
853

854
855
856