Goto Chapter: Top 1 2 3 4 5 6 A B C D E F Bib Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

B The Matrix Tool Operations
 B.1 The Tool Operations without a Fallback Method
 B.2 The Tool Operations with a Fallback Method

B The Matrix Tool Operations

The functions listed below are components of the homalgTable object stored in the ring. They are only indirectly accessible through standard methods that invoke them.

B.1 The Tool Operations without a Fallback Method

There are matrix methods for which homalg needs a homalgTable entry for non-internal rings, as it cannot provide a suitable fallback. Below is the list of these homalgTable entries.

B.1-1 InitialMatrix
‣ InitialMatrix( C )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.InitialMatrix is bound then the method Eval (C.4-1) resets the filter IsInitialMatrix and returns \(RP\)!.InitialMatrix\(( \textit{C} )\).

B.1-2 InitialIdentityMatrix
‣ InitialIdentityMatrix( C )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.InitialIdentityMatrix is bound then the method Eval (C.4-2) resets the filter IsInitialIdentityMatrix and returns \(RP\)!.InitialIdentityMatrix\(( \textit{C} )\).

B.1-3 ZeroMatrix
‣ ZeroMatrix( C )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.ZeroMatrix is bound then the method Eval (C.4-3) returns \(RP\)!.ZeroMatrix\(( \textit{C} )\).

B.1-4 IdentityMatrix
‣ IdentityMatrix( C )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.IdentityMatrix is bound then the method Eval (C.4-4) returns \(RP\)!.IdentityMatrix\(( \textit{C} )\).

B.1-5 Involution
‣ Involution( M )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.Involution is bound then the method Eval (C.4-7) returns \(RP\)!.Involution applied to the content of the attribute EvalInvolution\(( \textit{C} ) = \textit{M}\).

B.1-6 TransposedMatrix
‣ TransposedMatrix( M )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.TransposedMatrix is bound then the method Eval (C.4-8) returns \(RP\)!.TransposedMatrix applied to the content of the attribute EvalTransposedMatrix\(( \textit{C} ) = \textit{M}\).

B.1-7 CertainRows
‣ CertainRows( M, plist )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.CertainRows is bound then the method Eval (C.4-10) returns \(RP\)!.CertainRows applied to the content of the attribute EvalCertainRows\(( \textit{C} ) = [ \textit{M}, \textit{plist} ]\).

B.1-8 CertainColumns
‣ CertainColumns( M, plist )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.CertainColumns is bound then the method Eval (C.4-11) returns \(RP\)!.CertainColumns applied to the content of the attribute EvalCertainColumns\(( \textit{C} ) = [ \textit{M}, \textit{plist} ]\).

B.1-9 UnionOfRows
‣ UnionOfRows( L )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.UnionOfRows is bound then the method Eval (C.4-12) returns \(RP\)!.UnionOfRows applied to the content of the attribute EvalUnionOfRows\(( \textit{C} ) = \textit{L}\).

B.1-10 UnionOfRowsPair
‣ UnionOfRowsPair( A, B )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.UnionOfRowsPair is bound and the homalgTable component \(RP\)!.UnionOfRows is not bound then the method Eval (C.4-12) returns \(RP\)!.UnionOfRowsPair applied recursively to a balanced binary tree created from the content of the attribute EvalUnionOfRows\(( \textit{C} )\).

B.1-11 UnionOfColumns
‣ UnionOfColumns( L )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.UnionOfColumns is bound then the method Eval (C.4-13) returns \(RP\)!.UnionOfColumns applied to the content of the attribute EvalUnionOfColumns\(( \textit{C} ) = \textit{L}\).

B.1-12 UnionOfColumnsPair
‣ UnionOfColumnsPair( A, B )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.UnionOfColumnsPair is bound and the homalgTable component \(RP\)!.UnionOfColumns is not bound then the method Eval (C.4-13) returns \(RP\)!.UnionOfColumnsPair applied recursively to a balanced binary tree created from the content of the attribute EvalUnionOfRows\(( \textit{C} )\).

B.1-13 DiagMat
‣ DiagMat( e )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.DiagMat is bound then the method Eval (C.4-14) returns \(RP\)!.DiagMat applied to the content of the attribute EvalDiagMat\(( \textit{C} ) = \textit{e}\).

B.1-14 KroneckerMat
‣ KroneckerMat( A, B )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.KroneckerMat is bound then the method Eval (C.4-15) returns \(RP\)!.KroneckerMat applied to the content of the attribute EvalKroneckerMat\(( \textit{C} ) = [ \textit{A}, \textit{B} ]\).

B.1-15 DualKroneckerMat
‣ DualKroneckerMat( A, B )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.DualKroneckerMat is bound then the method Eval (C.4-16) returns \(RP\)!.DualKroneckerMat applied to the content of the attribute EvalDualKroneckerMat\(( \textit{C} ) = [ \textit{A}, \textit{B} ]\).

B.1-16 MulMat
‣ MulMat( a, A )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.MulMat is bound then the method Eval (C.4-17) returns \(RP\)!.MulMat applied to the content of the attribute EvalMulMat\(( \textit{C} ) = [ \textit{a}, \textit{A} ]\).

B.1-17 AddMat
‣ AddMat( A, B )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.AddMat is bound then the method Eval (C.4-18) returns \(RP\)!.AddMat applied to the content of the attribute EvalAddMat\(( \textit{C} ) = [ \textit{A}, \textit{B} ]\).

B.1-18 SubMat
‣ SubMat( A, B )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.SubMat is bound then the method Eval (C.4-19) returns \(RP\)!.SubMat applied to the content of the attribute EvalSubMat\(( \textit{C} ) = [ \textit{A}, \textit{B} ]\).

B.1-19 Compose
‣ Compose( A, B )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.Compose is bound then the method Eval (C.4-20) returns \(RP\)!.Compose applied to the content of the attribute EvalCompose\(( \textit{C} ) = [ \textit{A}, \textit{B} ]\).

B.1-20 IsZeroMatrix
‣ IsZeroMatrix( M )( function )

Returns: true or false

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.IsZeroMatrix is bound then the standard method for the property IsZero (5.3-1) shown below returns \(RP\)!.IsZeroMatrix\(( \textit{M} )\).

InstallMethod( IsZero,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( M )
    local R, RP;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.IsZeroMatrix) then
        ## CAUTION: the external system must be able
        ## to check zero modulo possible ring relations!
        
        return RP!.IsZeroMatrix( M ); ## with this, \= can fall back to IsZero
    fi;
    
    #=====# the fallback method #=====#
    
    ## from the GAP4 documentation: ?Zero
    ## `ZeroSameMutability( <obj> )' is equivalent to `0 * <obj>'.
    
    return M = 0 * M; ## hence, by default, IsZero falls back to \= (see below)
    
end );

B.1-21 NumberRows
‣ NumberRows( C )( function )

Returns: a nonnegative integer

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.NumberRows is bound then the standard method for the attribute NumberRows (5.4-1) shown below returns \(RP\)!.NumberRows\(( \textit{C} )\).

InstallMethod( NumberRows,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( C )
    local R, RP;
    
    R := HomalgRing( C );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.NumberRows) then
        return RP!.NumberRows( C );
    fi;
    
    if not IsHomalgInternalMatrixRep( C ) then
        Error( "could not find a procedure called NumberRows ",
               "in the homalgTable of the non-internal ring\n" );
    fi;
    
    #=====# can only work for homalg internal matrices #=====#
    
    return Length( Eval( C )!.matrix );
    
end );

B.1-22 NumberColumns
‣ NumberColumns( C )( function )

Returns: a nonnegative integer

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.NumberColumns is bound then the standard method for the attribute NumberColumns (5.4-2) shown below returns \(RP\)!.NumberColumns\(( \textit{C} )\).

InstallMethod( NumberColumns,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( C )
    local R, RP;
    
    R := HomalgRing( C );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.NumberColumns) then
        return RP!.NumberColumns( C );
    fi;
    
    if not IsHomalgInternalMatrixRep( C ) then
        Error( "could not find a procedure called NumberColumns ",
               "in the homalgTable of the non-internal ring\n" );
    fi;
    
    #=====# can only work for homalg internal matrices #=====#
    
    return Length( Eval( C )!.matrix[ 1 ] );
    
end );

B.1-23 Determinant
‣ Determinant( C )( function )

Returns: a ring element

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.Determinant is bound then the standard method for the attribute DeterminantMat (5.4-3) shown below returns \(RP\)!.Determinant\(( \textit{C} )\).

InstallMethod( DeterminantMat,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( C )
    local R, RP;
    
    R := HomalgRing( C );
    
    RP := homalgTable( R );
    
    if NumberRows( C ) <> NumberColumns( C ) then
        Error( "the matrix is not a square matrix\n" );
    fi;
    
    if IsEmptyMatrix( C ) then
        return One( R );
    elif IsZero( C ) then
        return Zero( R );
    fi;
    
    if IsBound(RP!.Determinant) then
        return RingElementConstructor( R )( RP!.Determinant( C ), R );
    fi;
    
    if not IsHomalgInternalMatrixRep( C ) then
        Error( "could not find a procedure called Determinant ",
               "in the homalgTable of the non-internal ring\n" );
    fi;
    
    #=====# can only work for homalg internal matrices #=====#
    
    return Determinant( Eval( C )!.matrix );
    
end );


InstallMethod( Determinant,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( C )
    
    return DeterminantMat( C );
    
end );

B.1-24 CoefficientsWithGivenMonomials
‣ CoefficientsWithGivenMonomials( M, monomials )( function )

Returns: the Eval value of a homalg matrix C

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.CoefficientsWithGivenMonomials is bound then the method Eval (C.4-21) returns \(RP\)!.CoefficientsWithGivenMonomials applied to the content of the attribute EvalCoefficientsWithGivenMonomials\(( \textit{C} ) = [ \textit{M}, \textit{monomials} ]\).

B.2 The Tool Operations with a Fallback Method

These are the methods for which it is recommended for performance reasons to have a homalgTable entry for non-internal rings. homalg only provides a generic fallback method.

B.2-1 AreEqualMatrices
‣ AreEqualMatrices( M1, M2 )( function )

Returns: true or false

Let \(R :=\) HomalgRing\(( \textit{M1} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.AreEqualMatrices is bound then the standard method for the operation \= (5.5-23) shown below returns \(RP\)!.AreEqualMatrices\(( \textit{M1}, \textit{M2} )\).

InstallMethod( \=,
        "for homalg comparable matrices",
        [ IsHomalgMatrix, IsHomalgMatrix ],
        
  function( M1, M2 )
    local R, RP, are_equal;
    
    ## do not touch mutable matrices
    if not ( IsMutable( M1 ) or IsMutable( M2 ) ) then
        
        if IsBound( M1!.AreEqual ) then
            are_equal := _ElmWPObj_ForHomalg( M1!.AreEqual, M2, fail );
            if are_equal <> fail then
                return are_equal;
            fi;
        else
            M1!.AreEqual :=
              ContainerForWeakPointers(
                      TheTypeContainerForWeakPointersOnComputedValues,
                      [ "operation", "AreEqual" ] );
        fi;
        
        if IsBound( M2!.AreEqual ) then
            are_equal := _ElmWPObj_ForHomalg( M2!.AreEqual, M1, fail );
            if are_equal <> fail then
                return are_equal;
            fi;
        fi;
        ## do not store things symmetrically below to ``save'' memory
        
    fi;
    
    R := HomalgRing( M1 );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.AreEqualMatrices) then
        ## CAUTION: the external system must be able to check equality
        ## modulo possible ring relations (known to the external system)!
        are_equal := RP!.AreEqualMatrices( M1, M2 );
    elif IsBound(RP!.Equal) then
        ## CAUTION: the external system must be able to check equality
        ## modulo possible ring relations (known to the external system)!
        are_equal := RP!.Equal( M1, M2 );
    elif IsBound(RP!.IsZeroMatrix) then   ## ensuring this avoids infinite loops
        are_equal := IsZero( M1 - M2 );
    fi;
    
    if IsBound( are_equal ) then
        
        ## do not touch mutable matrices
        if not ( IsMutable( M1 ) or IsMutable( M2 ) ) then
            
            if are_equal then
                MatchPropertiesAndAttributes( M1, M2,
                        LIMAT.intrinsic_properties,
                        LIMAT.intrinsic_attributes,
                        LIMAT.intrinsic_components,
                        LIMAT.intrinsic_attributes_do_not_check_their_equality
                        );
            fi;
            
            ## do not store things symmetrically to ``save'' memory
            _AddTwoElmWPObj_ForHomalg( M1!.AreEqual, M2, are_equal );
            
        fi;
        
        return are_equal;
    fi;
    
    TryNextMethod( );
    
end );

B.2-2 IsIdentityMatrix
‣ IsIdentityMatrix( M )( function )

Returns: true or false

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.IsIdentityMatrix is bound then the standard method for the property IsOne (5.3-2) shown below returns \(RP\)!.IsIdentityMatrix\(( \textit{M} )\).

InstallMethod( IsOne,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( M )
    local R, RP;
    
    if NumberRows( M ) <> NumberColumns( M ) then
        return false;
    fi;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.IsIdentityMatrix) then
        return RP!.IsIdentityMatrix( M );
    fi;
    
    #=====# the fallback method #=====#
    
    return M = HomalgIdentityMatrix( NumberRows( M ), HomalgRing( M ) );
    
end );

B.2-3 IsDiagonalMatrix
‣ IsDiagonalMatrix( M )( function )

Returns: true or false

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.IsDiagonalMatrix is bound then the standard method for the property IsDiagonalMatrix (5.3-13) shown below returns \(RP\)!.IsDiagonalMatrix\(( \textit{M} )\).

InstallMethod( IsDiagonalMatrix,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( M )
    local R, RP, diag;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.IsDiagonalMatrix) then
        return RP!.IsDiagonalMatrix( M );
    fi;
    
    #=====# the fallback method #=====#
    
    diag := DiagonalEntries( M );
    
    return M = HomalgDiagonalMatrix( diag, NumberRows( M ), NumberColumns( M ), R );
    
end );

B.2-4 ZeroRows
‣ ZeroRows( C )( function )

Returns: a (possibly empty) list of positive integers

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.ZeroRows is bound then the standard method of the attribute ZeroRows (5.4-4) shown below returns \(RP\)!.ZeroRows\(( \textit{C} )\).

InstallMethod( ZeroRows,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( C )
    local R, RP, z;
    
    R := HomalgRing( C );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.ZeroRows) then
        return RP!.ZeroRows( C );
    fi;
    
    #=====# the fallback method #=====#
    
    z := HomalgZeroMatrix( 1, NumberColumns( C ), R );
    
    return Filtered( [ 1 .. NumberRows( C ) ], a -> CertainRows( C, [ a ] ) = z );
    
end );

B.2-5 ZeroColumns
‣ ZeroColumns( C )( function )

Returns: a (possibly empty) list of positive integers

Let \(R :=\) HomalgRing\(( \textit{C} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.ZeroColumns is bound then the standard method of the attribute ZeroColumns (5.4-5) shown below returns \(RP\)!.ZeroColumns\(( \textit{C} )\).

InstallMethod( ZeroColumns,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( C )
    local R, RP, z;
    
    R := HomalgRing( C );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.ZeroColumns) then
        return RP!.ZeroColumns( C );
    fi;
    
    #=====# the fallback method #=====#
    
    z := HomalgZeroMatrix( NumberRows( C ), 1, R );
    
    return Filtered( [ 1 .. NumberColumns( C ) ], a -> CertainColumns( C, [ a ] ) = z );
    
end );

B.2-6 GetColumnIndependentUnitPositions
‣ GetColumnIndependentUnitPositions( M, poslist )( function )

Returns: a (possibly empty) list of pairs of positive integers

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.GetColumnIndependentUnitPositions is bound then the standard method of the operation GetColumnIndependentUnitPositions (5.5-24) shown below returns \(RP\)!.GetColumnIndependentUnitPositions\(( \textit{M}, \textit{poslist} )\).

InstallMethod( GetColumnIndependentUnitPositions,
        "for homalg matrices",
        [ IsHomalgMatrix, IsHomogeneousList ],
        
  function( M, poslist )
    local cache, R, RP, rest, pos, i, j, k;
    
    if IsBound( M!.GetColumnIndependentUnitPositions ) then
        cache := M!.GetColumnIndependentUnitPositions;
        if IsBound( cache.(String( poslist )) ) then
            return cache.(String( poslist ));
        fi;
    else
        cache := rec( );
        M!.GetColumnIndependentUnitPositions := cache;
    fi;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.GetColumnIndependentUnitPositions) then
        pos := RP!.GetColumnIndependentUnitPositions( M, poslist );
        if pos <> [ ] then
            SetIsZero( M, false );
        fi;
        cache.(String( poslist )) := pos;
        return pos;
    fi;
    
    #=====# the fallback method #=====#
    
    rest := [ 1 .. NumberColumns( M ) ];
    
    pos := [ ];
    
    for i in [ 1 .. NumberRows( M ) ] do
        for k in Reversed( rest ) do
            if not [ i, k ] in poslist and
               IsUnit( R, M[ i, k ] ) then
                Add( pos, [ i, k ] );
                rest := Filtered( rest,
                                a -> IsZero( M[ i, a ] ) );
                break;
            fi;
        od;
    od;
    
    if pos <> [ ] then
        SetIsZero( M, false );
    fi;
    
    cache.(String( poslist )) := pos;
    
    return pos;
    
end );

B.2-7 GetRowIndependentUnitPositions
‣ GetRowIndependentUnitPositions( M, poslist )( function )

Returns: a (possibly empty) list of pairs of positive integers

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.GetRowIndependentUnitPositions is bound then the standard method of the operation GetRowIndependentUnitPositions (5.5-25) shown below returns \(RP\)!.GetRowIndependentUnitPositions\(( \textit{M}, \textit{poslist} )\).

InstallMethod( GetRowIndependentUnitPositions,
        "for homalg matrices",
        [ IsHomalgMatrix, IsHomogeneousList ],
        
  function( M, poslist )
    local cache, R, RP, rest, pos, j, i, k;
    
    if IsBound( M!.GetRowIndependentUnitPositions ) then
        cache := M!.GetRowIndependentUnitPositions;
        if IsBound( cache.(String( poslist )) ) then
            return cache.(String( poslist ));
        fi;
    else
        cache := rec( );
        M!.GetRowIndependentUnitPositions := cache;
    fi;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.GetRowIndependentUnitPositions) then
        pos := RP!.GetRowIndependentUnitPositions( M, poslist );
        if pos <> [ ] then
            SetIsZero( M, false );
        fi;
        cache.( String( poslist ) ) := pos;
        return pos;
    fi;
    
    #=====# the fallback method #=====#
    
    rest := [ 1 .. NumberRows( M ) ];
    
    pos := [ ];
    
    for j in [ 1 .. NumberColumns( M ) ] do
        for k in Reversed( rest ) do
            if not [ j, k ] in poslist and
               IsUnit( R, M[ k, j ] ) then
                Add( pos, [ j, k ] );
                rest := Filtered( rest,
                                a -> IsZero( M[ a, j ] ) );
                break;
            fi;
        od;
    od;
    
    if pos <> [ ] then
        SetIsZero( M, false );
    fi;
    
    cache.( String( poslist ) ) := pos;
    
    return pos;
    
end );

B.2-8 GetUnitPosition
‣ GetUnitPosition( M, poslist )( function )

Returns: a (possibly empty) list of pairs of positive integers

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.GetUnitPosition is bound then the standard method of the operation GetUnitPosition (5.5-26) shown below returns \(RP\)!.GetUnitPosition\(( \textit{M}, \textit{poslist} )\).

InstallMethod( GetUnitPosition,
        "for homalg matrices",
        [ IsHomalgMatrix, IsHomogeneousList ],
        
  function( M, poslist )
    local R, RP, pos, m, n, i, j;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.GetUnitPosition) then
        pos := RP!.GetUnitPosition( M, poslist );
        if IsList( pos ) and IsPosInt( pos[1] ) and IsPosInt( pos[2] ) then
            SetIsZero( M, false );
        fi;
        return pos;
    fi;
    
    #=====# the fallback method #=====#
    
    m := NumberRows( M );
    n := NumberColumns( M );
    
    for i in [ 1 .. m ] do
        for j in [ 1 .. n ] do
            if not [ i, j ] in poslist and not j in poslist and
               IsUnit( R, M[ i, j ] ) then
                SetIsZero( M, false );
                return [ i, j ];
            fi;
        od;
    od;
    
    return fail;
    
end );

B.2-9 PositionOfFirstNonZeroEntryPerRow
‣ PositionOfFirstNonZeroEntryPerRow( M, poslist )( function )

Returns: a list of nonnegative integers

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.PositionOfFirstNonZeroEntryPerRow is bound then the standard method of the attribute PositionOfFirstNonZeroEntryPerRow (5.4-8) shown below returns \(RP\)!.PositionOfFirstNonZeroEntryPerRow\(( \textit{M} )\).

InstallMethod( PositionOfFirstNonZeroEntryPerRow,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( M )
    local R, RP, pos, entries, r, c, i, k, j;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.PositionOfFirstNonZeroEntryPerRow) then
        return RP!.PositionOfFirstNonZeroEntryPerRow( M );
    elif IsBound(RP!.PositionOfFirstNonZeroEntryPerColumn) then
        return PositionOfFirstNonZeroEntryPerColumn( Involution( M ) );
    fi;
    
    #=====# the fallback method #=====#
    
    entries := EntriesOfHomalgMatrix( M );
    
    r := NumberRows( M );
    c := NumberColumns( M );
    
    pos := ListWithIdenticalEntries( r, 0 );
    
    for i in [ 1 .. r ] do
        k := (i - 1) * c;
        for j in [ 1 .. c ] do
            if not IsZero( entries[k + j] ) then
                pos[i] := j;
                break;
            fi;
        od;
    od;
    
    return pos;
    
end );

B.2-10 PositionOfFirstNonZeroEntryPerColumn
‣ PositionOfFirstNonZeroEntryPerColumn( M, poslist )( function )

Returns: a list of nonnegative integers

Let \(R :=\) HomalgRing\(( \textit{M} )\) and \(RP :=\) homalgTable\(( R )\). If the homalgTable component \(RP\)!.PositionOfFirstNonZeroEntryPerColumn is bound then the standard method of the attribute PositionOfFirstNonZeroEntryPerColumn (5.4-9) shown below returns \(RP\)!.PositionOfFirstNonZeroEntryPerColumn\(( \textit{M} )\).

InstallMethod( PositionOfFirstNonZeroEntryPerColumn,
        "for homalg matrices",
        [ IsHomalgMatrix ],
        
  function( M )
    local R, RP, pos, entries, r, c, j, i, k;
    
    R := HomalgRing( M );
    
    RP := homalgTable( R );
    
    if IsBound(RP!.PositionOfFirstNonZeroEntryPerColumn) then
        return RP!.PositionOfFirstNonZeroEntryPerColumn( M );
    elif IsBound(RP!.PositionOfFirstNonZeroEntryPerRow) then
        return PositionOfFirstNonZeroEntryPerRow( Involution( M ) );
    fi;
    
    #=====# the fallback method #=====#
    
    entries := EntriesOfHomalgMatrix( M );
    
    r := NumberRows( M );
    c := NumberColumns( M );
    
    pos := ListWithIdenticalEntries( c, 0 );
    
    for j in [ 1 .. c ] do
        for i in [ 1 .. r ] do
            k := (i - 1) * c;
            if not IsZero( entries[k + j] ) then
                pos[j] := i;
                break;
            fi;
        od;
    od;
    
    return pos;
    
end );
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 4 5 6 A B C D E F Bib Ind

generated by GAPDoc2HTML