Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -144,11 +144,8 @@ InstallValue( GradedRingTableForMacaulay2Tools,

MultiWeightedDegreeOfRingElement :=
function( r, weights, R )
local externally_stored_weights;

externally_stored_weights := MatrixOfWeightsOfIndeterminates( R );

return StringToIntList( homalgSendBlocking( [ "MultiDeg(", r, externally_stored_weights, R, ")" ], "need_output", HOMALG_IO.Pictograms.DegreeOfRingElement ) );
return StringToIntList( homalgSendBlocking( [ "MultiDeg(", r, weights, R, ")" ], "need_output", HOMALG_IO.Pictograms.DegreeOfRingElement ) );

end,

@@ -261,23 +258,28 @@ AppendTohomalgTablesOfCreatedExternalRings( GradedRingTableForMacaulay2Tools, Is
##
InstallMethod( MatrixOfWeightsOfIndeterminates,
"for external rings in Macaulay2",
[ IsHomalgExternalRingInMacaulay2Rep and HasWeightsOfIndeterminates ],
[ IsHomalgExternalRingInMacaulay2Rep, IsList ],

function( R )
local degrees, n, m, ext_obj;
function( R, weights )
local n, m, ext_obj;

degrees := WeightsOfIndeterminates( R );
if IsHomalgElement( weights[1] ) then

## this should be handled with care, as it will eventually fail if the module is not over the ring of integers
weights := List( weights, UnderlyingListOfRingElements );

fi;

n := Length( degrees );
n := Length( weights );

if n > 0 and IsList( degrees[1] ) then
m := Length( degrees[1] );
degrees := Flat( TransposedMat( degrees ) );
if n > 0 and IsList( weights[1] ) then
m := Length( weights[1] );
weights := Flat( TransposedMat( weights ) );
else
m := 1;
fi;

ext_obj := homalgSendBlocking( [ "pack(", n, ",{", degrees, "})" ], "break_lists", R, HOMALG_IO.Pictograms.CreateList );
ext_obj := homalgSendBlocking( [ "pack(", n, ",{", weights, "})" ], "break_lists", R, HOMALG_IO.Pictograms.CreateList );

return HomalgMatrix( ext_obj, m, n, R );

@@ -270,10 +270,25 @@ InstallMethod( MonomialMatrix,
[ IsInt, IsHomalgGradedRing ],

function( d, S )
local weights, weightlist;

weights := WeightsOfIndeterminates( S );

if IsHomalgElement( weights[ 1 ] ) then

weightlist := List( weights, UnderlyingListOfRingElements );

if Length( weightlist[ 1 ] ) = 1 then

weightlist := List( weightlist, i -> i[ 1 ] );

fi;

fi;

return MatrixOverGradedRing(
MonomialMatrixWeighted(
d, UnderlyingNonGradedRing( S ), WeightsOfIndeterminates( S ) ),
d, UnderlyingNonGradedRing( S ), weightlist ),
S );

end );
@@ -284,10 +299,25 @@ InstallMethod( MonomialMatrix,
[ IsList, IsHomalgGradedRing ],

function( d, S )
local weights, weightlist;

weights := WeightsOfIndeterminates( S );

if IsHomalgElement( weights[ 1 ] ) then

weightlist := List( weights, UnderlyingListOfRingElements );

if Length( weightlist[ 1 ] ) = 1 then

weightlist := List( weightlist, i -> i[ 1 ] );

fi;

fi;

return MatrixOverGradedRing(
MonomialMatrixWeighted(
d, UnderlyingNonGradedRing( S ), WeightsOfIndeterminates( S ) ),
d, UnderlyingNonGradedRing( S ), weightlist ),
S );

end );
@@ -320,11 +350,74 @@ InstallMethod( RandomMatrixBetweenGradedFreeLeftModules,
[ IsList, IsList, IsHomalgGradedRingRep ],

function( degreesS, degreesT, S )
local weights, weightlist;

weights := WeightsOfIndeterminates( S );

if IsHomalgElement( weights[ 1 ] ) then

weightlist := List( weights, UnderlyingListOfRingElements );

if Length( weightlist[ 1 ] ) = 1 then

weightlist := List( weightlist, i -> i[ 1 ] );

fi;

fi;

if ForAny( degreesS, IsHomalgElement ) then

degreesS := List( degreesS, function( i )
if IsHomalgElement( i ) then
return UnderlyingListOfRingElements( i );
else
return i;
fi;
end );

if ForAny( degreesS, IsList ) then

degreesS := List( degreesS, function( i )
if IsList( i ) and Length( i ) = 1 then
return i[ 1 ];
else
return i;
fi;
end );

fi;

fi;

if IsHomalgElement( degreesT[ 1 ] ) then

degreesT := List( degreesT, function( i )
if IsHomalgElement( i ) then
return UnderlyingListOfRingElements( i );
else
return i;
fi;
end );

if ForAny( degreesT, IsList ) then

degreesT := List( degreesT, function( i )
if IsList( i ) and Length( i ) = 1 then
return i[ 1 ];
else
return i;
fi;
end );

fi;

fi;

return MatrixOverGradedRing(
RandomMatrixBetweenGradedFreeLeftModulesWeighted(
degreesS, degreesT,
UnderlyingNonGradedRing( S ), WeightsOfIndeterminates( S ) ),
UnderlyingNonGradedRing( S ), weightlist ),
S );

end );
@@ -356,11 +449,50 @@ InstallMethod( RandomMatrixBetweenGradedFreeRightModules,
[ IsList, IsList, IsHomalgGradedRingRep ],

function( degreesS, degreesT, S )
local weights, weightlist;

weights := WeightsOfIndeterminates( S );

if IsHomalgElement( weights[ 1 ] ) then

weightlist := List( weights, UnderlyingListOfRingElements );

if Length( weightlist[ 1 ] ) = 1 then

weightlist := List( weightlist, i -> i[ 1 ] );

fi;

fi;

if IsHomalgElement( degreesS[ 1 ] ) then

degreesS := List( degreesS, UnderlyingListOfRingElements );

if Length( degreesS[ 1 ] ) = 1 then

degreesS := List( degreesS, i -> i[ 1 ] );

fi;

fi;

if IsHomalgElement( degreesT[ 1 ] ) then

degreesT := List( degreesT, UnderlyingListOfRingElements );

if Length( degreesT[ 1 ] ) = 1 then

degreesT := List( degreesT, i -> i[ 1 ] );

fi;

fi;

return MatrixOverGradedRing(
RandomMatrixBetweenGradedFreeRightModulesWeighted(
degreesS, degreesT,
UnderlyingNonGradedRing( S ), WeightsOfIndeterminates( S ) ),
UnderlyingNonGradedRing( S ), weightlist ),
S );

end );
@@ -397,23 +529,27 @@ InstallMethod( NonTrivialDegreePerRow,
return ListWithIdenticalEntries( NrRows( C ), DegreeOfRingElement( One( S ) ) ); ## One( S ) is not a mistake
fi;

## CASHING ##
if IsBound( C!.NonTrivialDegreePerRow ) then
degrees := _ElmWPObj_ForHomalg( C!.NonTrivialDegreePerRow, S, fail );
degrees := _ElmPObj_ForHomalg( C!.NonTrivialDegreePerRow, S, fail );
if degrees <> fail then
return degrees;
fi;
else
C!.NonTrivialDegreePerRow :=
ContainerForWeakPointers(
TheTypeContainerForWeakPointersOnComputedValues,
ContainerForPointers(
TheTypeContainerForPointersOnComputedValues,
[ "operation", "NonTrivialDegreePerRow" ] );
fi;
## ENDCASHING ##

degrees := NonTrivialDegreePerRowWithColPositionFunction( S )( C );

## CASHING ##
if not IsMutable( C ) then
_AddTwoElmWPObj_ForHomalg( C!.NonTrivialDegreePerRow, S, degrees );
_AddTwoElmPObj_ForHomalg( C!.NonTrivialDegreePerRow, S, degrees );
fi;
## ENDCASHING ##

return degrees;

@@ -473,23 +609,26 @@ InstallMethod( NonTrivialDegreePerColumn,
fi;

if IsBound( C!.NonTrivialDegreePerColumn ) then
degrees := _ElmWPObj_ForHomalg( C!.NonTrivialDegreePerColumn, S, fail );
degrees := _ElmPObj_ForHomalg( C!.NonTrivialDegreePerColumn, S, fail );
if degrees <> fail then
return degrees;
fi;

else
C!.NonTrivialDegreePerColumn :=
ContainerForWeakPointers(
TheTypeContainerForWeakPointersOnComputedValues,
ContainerForPointers(
TheTypeContainerForPointersOnComputedValues,
[ "operation", "NonTrivialDegreePerColumn" ] );
fi;

degrees := NonTrivialDegreePerColumnWithRowPositionFunction( S )( C );

if not IsMutable( C ) then
_AddTwoElmWPObj_ForHomalg( C!.NonTrivialDegreePerColumn, S, degrees );
_AddTwoElmPObj_ForHomalg( C!.NonTrivialDegreePerColumn, S, degrees );
fi;



return degrees;

end );
@@ -256,11 +256,14 @@ InstallValue( GradedRingTableForSingularTools,

MultiWeightedDegreeOfRingElement :=
function( r, weights, R )
local externally_stored_weights;

externally_stored_weights := MatrixOfWeightsOfIndeterminates( R );
if IsList( weights ) then

weights := MatrixOfWeightsOfIndeterminates( R, weights );

fi;

return StringToIntList( homalgSendBlocking( [ "MultiDeg(", r, externally_stored_weights, ")" ], "need_output", HOMALG_IO.Pictograms.DegreeOfRingElement ) );
return StringToIntList( homalgSendBlocking( [ "MultiDeg(", r, weights, ")" ], "need_output", HOMALG_IO.Pictograms.DegreeOfRingElement ) );

end,

@@ -280,7 +283,7 @@ InstallValue( GradedRingTableForSingularTools,
function( M, weights )
local list_string, L;

list_string := homalgSendBlocking( [ "WeightedDegreesOfEntries(", M, ",intvec(", weights, "))" ], "need_output", HOMALG_IO.Pictograms.DegreesOfEntries );
list_string := homalgSendBlocking( [ "WeightedDegreesOfEntries(", M, ",", weights, ")" ], "need_output", HOMALG_IO.Pictograms.DegreesOfEntries );

L := StringToIntList( list_string );

@@ -406,24 +409,30 @@ AppendTohomalgTablesOfCreatedExternalRings( GradedRingTableForSingularTools, IsH
##
InstallMethod( MatrixOfWeightsOfIndeterminates,
"for external rings in Singular",
[ IsHomalgExternalRingInSingularRep and HasWeightsOfIndeterminates ],
[ IsHomalgExternalRingInSingularRep, IsList ],

function( R )
local degrees, n, m, ext_obj;
function( R, weights )
local n, m, ext_obj;

degrees := WeightsOfIndeterminates( R );
if IsHomalgElement( weights[1] ) then

weights := List( weights, UnderlyingListOfRingElementsInCurrentPresentation );

fi;

n := Length( degrees );
n := Length( weights );

if n > 0 and IsList( degrees[1] ) then
m := Length( degrees[1] );
degrees := Flat( TransposedMat( degrees ) );
if n > 0 then
m := Length( weights[1] );
weights := Flat( TransposedMat( weights ) );
else
m := 1;
fi;

ext_obj := homalgSendBlocking( [ "CreateListListOfIntegers(intvec(", degrees, "),", m, n, ")" ], [ "list" ], R, HOMALG_IO.Pictograms.CreateList );
ext_obj := homalgSendBlocking( [ "CreateListListOfIntegers(intvec(", weights, "),", m, n, ")" ], [ "list" ], R, HOMALG_IO.Pictograms.CreateList );

## CAUTION: ext_obj does not a pointer on a matrix in Singular
## but on an intvec; use with care
return HomalgMatrix( ext_obj, m, n, R );

end );
@@ -20,9 +20,15 @@
DeclareOperation( "DegreeOfRingElementFunction",
[ IsHomalgRing, IsList ] );

DeclareOperation( "DegreeOfRingElementFunction",
[ IsHomalgRing, IsHomalgMatrix ] );

DeclareOperation( "DegreesOfEntriesFunction",
[ IsHomalgRing, IsList ] );

DeclareOperation( "DegreesOfEntriesFunction",
[ IsHomalgRing, IsHomalgMatrix ] );

DeclareOperation( "NonTrivialDegreePerRowWithColPositionFunction",
[ IsHomalgRing, IsList, IsObject, IsObject ] );

@@ -30,15 +30,19 @@ InstallMethod( DegreeOfRingElementFunction,
if set_weights = [ 1 ] then

if IsBound(RP!.DegreeOfRingElement) then

return r -> RP!.DegreeOfRingElement( r, R );

fi;

elif Length( set_weights ) = 1 and set_weights[1] in Rationals then

weight := set_weights[1];

if weight <> 0 and IsBound(RP!.DegreeOfRingElement) then

return r -> weight * RP!.DegreeOfRingElement( r, R );

fi;

elif Length( set_weights ) = 2 and 0 in set_weights and
@@ -60,16 +64,12 @@ InstallMethod( DegreeOfRingElementFunction,

return function( r ) if IsZero( r ) then return -1; else return 0; fi; end;

elif IsList( weights[1] ) then

if IsBound(RP!.MultiWeightedDegreeOfRingElement) then
return r -> RP!.MultiWeightedDegreeOfRingElement( r, weights, R );
fi;

else

if IsBound(RP!.WeightedDegreeOfRingElement) then
return r -> RP!.WeightedDegreeOfRingElement( r, weights, R );

return r -> RP!.MultiWeightedDegreeOfRingElement( r, weights, R );

fi;

fi;
@@ -80,6 +80,20 @@ InstallMethod( DegreeOfRingElementFunction,

end );

##
InstallMethod( DegreeOfRingElementFunction,
"for a homalg ring and a homalg matrix (of weights)",
[ IsHomalgRing, IsHomalgMatrix ],

function( R, weights )
local RP;

RP := homalgTable( R );

return r -> RP!.MultiWeightedDegreeOfRingElement( r, weights, R );

end );

##
InstallMethod( DegreeOfRingElementFunction,
"for homalg residue class rings",
@@ -175,6 +189,22 @@ InstallMethod( DegreesOfEntriesFunction,

end );


##
InstallMethod( DegreesOfEntriesFunction,
"for homalg rings",
[ IsHomalgRing, IsHomalgMatrix ],

function( R, weights )
local RP;

RP := homalgTable( R );

return r -> RP!.MultiWeightedDegreesOfEntries( r, weights, R );

end );


##
InstallMethod( NonTrivialDegreePerRowWithColPositionFunction,
"for homalg rings",