Skip to content

Commit

Permalink
Merge pull request #1408 from kamalsaleh/lincomb
Browse files Browse the repository at this point in the history
add 'LinearCombinationOfMorphisms' to the method record
  • Loading branch information
zickgraf authored Aug 14, 2023
2 parents 479ac4d + 25ae038 commit 83500f6
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CAP/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SetPackageInfo( rec(

PackageName := "CAP",
Subtitle := "Categories, Algorithms, Programming",
Version := "2023.08-06",
Version := "2023.08-07",
Date := (function ( ) if IsBound( GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE ) then return GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE; else return Concatenation( ~.Version{[ 1 .. 4 ]}, "-", ~.Version{[ 6, 7 ]}, "-01" ); fi; end)( ),
License := "GPL-2.0-or-later",

Expand Down
2 changes: 1 addition & 1 deletion CAP/examples/TerminalCategoryWithMultipleObjects.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ T := TerminalCategoryWithMultipleObjects( );
Display( T );
#! A CAP category with name TerminalCategoryWithMultipleObjects( ):
#!
#! 65 primitive operations were used to derive 306 operations for this category \
#! 65 primitive operations were used to derive 307 operations for this category \
#! which algorithmically
#! * IsCategoryWithDecidableColifts
#! * IsCategoryWithDecidableLifts
Expand Down
2 changes: 1 addition & 1 deletion CAP/examples/TerminalCategoryWithSingleObject.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ T := TerminalCategoryWithSingleObject( );
Display( T );
#! A CAP category with name TerminalCategoryWithSingleObject( ):
#!
#! 63 primitive operations were used to derive 306 operations for this category \
#! 63 primitive operations were used to derive 307 operations for this category \
#! which algorithmically
#! * IsCategoryWithDecidableColifts
#! * IsCategoryWithDecidableLifts
Expand Down
19 changes: 19 additions & 0 deletions CAP/gap/AddFunctions.autogen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,25 @@ DeclareOperation( "AddLiftOrFail",
DeclareOperation( "AddLiftOrFail",
[ IsCapCategory, IsList ] );

#! @Description
#! The arguments are a category $C$ and a function $F$.
#! This operation adds the given function $F$
#! to the category for the basic operation `LinearCombinationOfMorphisms`.
#! $F: ( source, list_of_ring_elements, list_of_morphisms, range ) \mapsto \mathtt{LinearCombinationOfMorphisms}(source, list_of_ring_elements, list_of_morphisms, range)$.
#! @Returns nothing
#! @Arguments C, F
DeclareOperation( "AddLinearCombinationOfMorphisms",
[ IsCapCategory, IsFunction ] );

DeclareOperation( "AddLinearCombinationOfMorphisms",
[ IsCapCategory, IsFunction, IsInt ] );

DeclareOperation( "AddLinearCombinationOfMorphisms",
[ IsCapCategory, IsList, IsInt ] );

DeclareOperation( "AddLinearCombinationOfMorphisms",
[ IsCapCategory, IsList ] );

#! @Description
#! The arguments are a category $C$ and a function $F$.
#! This operation adds the given function $F$
Expand Down
10 changes: 10 additions & 0 deletions CAP/gap/CategoryMorphisms.gd
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,16 @@ DeclareOperation( "PostComposeList",
DeclareOperation( "SumOfMorphisms",
[ IsCapCategoryObject, IsList, IsCapCategoryObject ] );

#! @Description
#! The arguments are two objects <A>s</A>, <A>r</A> in some linear category over a ring $R$,
#! a list <A>coeffs</A> of ring elements in $R$ and a list <A>mors</A> of morphisms from <A>s</A> to <A>r</A>.
#! The output is the linear combination of the morphisms in <A>mors</A> with respect to the coefficients list <A>coeffs</A>,
#! or the zero morphism from <A>s</A> to <A>r</A> if <A>coeffs</A> and <A>mors</A> are the empty lists.
#! @Returns a morphism in $\mathrm{Hom}(s,r)$
#! @Arguments s, coeffs, mors, r
DeclareOperation( "LinearCombinationOfMorphisms",
[ IsCapCategoryObject, IsList, IsList, IsCapCategoryObject ] );

###################################
##
#! @Section Well-Definedness of Morphisms
Expand Down
15 changes: 15 additions & 0 deletions CAP/gap/DerivedMethods.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,21 @@ AddDerivationToCAP( SumOfMorphisms,

end : CategoryFilter := IsAbCategory );

##
AddDerivationToCAP( LinearCombinationOfMorphisms,
"LinearCombinationOfMorphisms using SumOfMorphisms and MultiplyWithElementOfCommutativeRingForMorphisms",
[ [ MultiplyWithElementOfCommutativeRingForMorphisms, 2 ],
[ SumOfMorphisms, 1 ] ],

function( cat, obj1, coeffs, mors, obj2 )
local morphisms;

morphisms := ListN( coeffs, mors, { r, alpha } -> MultiplyWithElementOfCommutativeRingForMorphisms( cat, r, alpha ) );

return SumOfMorphisms( cat, obj1, morphisms, obj2 );

end : CategoryFilter := IsLinearCategoryOverCommutativeRing );

##
AddDerivationToCAP( LiftAlongMonomorphism,
"LiftAlongMonomorphism using Lift",
Expand Down
37 changes: 37 additions & 0 deletions CAP/gap/MethodRecord.gi
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,43 @@ SumOfMorphisms := rec(
compatible_with_congruence_of_morphisms := true,
),

LinearCombinationOfMorphisms := rec(
filter_list := [ "category", "object", "list_of_elements_of_commutative_ring_of_linear_structure", "list_of_morphisms", "object" ],
input_arguments_names := [ "cat", "source", "list_of_ring_elements", "list_of_morphisms", "range" ],
pre_function := function( cat, source, list_of_ring_elements, list_of_morphisms, range )
local m;

if not Length( list_of_ring_elements ) = Length( list_of_morphisms ) then

return [ false, "the length of the lists of coefficients and morphisms must be the same" ];

fi;

for m in list_of_morphisms do

if not IsEqualForObjects( cat, source, Source( m ) ) or not IsEqualForObjects( cat, range, Range( m ) ) then

return [ false, "some of the morphisms are not compatible with the provided source and range objects" ];

fi;

od;

return [ true ];

end,
return_type := "morphism",
output_source_getter_string := "source",
output_range_getter_string := "range",
dual_operation := "LinearCombinationOfMorphisms",
dual_preprocessor_func := function( arg )
local list;
list := CAP_INTERNAL_OPPOSITE_RECURSIVE( arg );
return NTuple( 5, list[1], list[5], list[3], list[4], list[2] );
end,
compatible_with_congruence_of_morphisms := true,
),

PreComposeList := rec(
filter_list := [ "category", "list_of_morphisms" ],
input_arguments_names := [ "cat", "list_of_morphisms" ],
Expand Down
2 changes: 1 addition & 1 deletion CAP/gap/OppositeCategory.gi
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ BindGlobal( "CAP_INTERNAL_INSTALL_OPPOSITE_ADDS_FROM_CATEGORY",

return Concatenation( "MorphismDatum( cat, ", argument_name, " )" );

elif filter = "integer" or filter = "element_of_commutative_ring_of_linear_structure" or filter = "nonneg_integer_or_infinity" then
elif filter in [ "integer", "element_of_commutative_ring_of_linear_structure", "nonneg_integer_or_infinity", "list_of_elements_of_commutative_ring_of_linear_structure" ] then

return argument_name;

Expand Down
4 changes: 2 additions & 2 deletions FreydCategoriesForCAP/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SetPackageInfo( rec(

PackageName := "FreydCategoriesForCAP",
Subtitle := "Freyd categories - Formal (co)kernels for additive categories",
Version := "2023.08-01",
Version := "2023.08-02",
Date := (function ( ) if IsBound( GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE ) then return GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE; else return Concatenation( ~.Version{[ 1 .. 4 ]}, "-", ~.Version{[ 6, 7 ]}, "-01" ); fi; end)( ),
License := "GPL-2.0-or-later",

Expand Down Expand Up @@ -87,7 +87,7 @@ PackageDoc := rec(

Dependencies := rec(
GAP := ">= 4.12.1",
NeededOtherPackages := [ [ "CAP", ">= 2023.06-04" ],
NeededOtherPackages := [ [ "CAP", ">= 2023.08-07" ],
[ "MatricesForHomalg", ">= 2023.01-01" ],
[ "GradedRingForHomalg", ">=2019.08.07" ],
[ "MonoidalCategories", ">= 2023.02-04" ],
Expand Down
18 changes: 13 additions & 5 deletions FreydCategoriesForCAP/examples/RingsAsAbCats.g
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ BasisOfExternalHom( u, u );
#! [ <1> ]
CoefficientsOfMorphism( alpha );
#! [ 2 ]
IsCongruentForMorphisms( alpha, SumOfMorphisms( u, ListN( CoefficientsOfMorphism( alpha ), BasisOfExternalHom( u, u ), { x, y } -> MultiplyWithElementOfCommutativeRingForMorphisms( x, y ) ), u ) );
IsCongruentForMorphisms( alpha, LinearCombinationOfMorphisms( u, CoefficientsOfMorphism( alpha ), BasisOfExternalHom( u, u ), u ) );
#! true

EEE := KoszulDualRing( HomalgFieldOfRationalsInSingular( ) * "x,y" );;
Expand Down Expand Up @@ -72,11 +72,19 @@ Lift( alpha * alpha, alpha );
#! <5*e0*e1+3*e0+4*e1+2>
Colift( alpha, alpha * alpha );
#! <5*e0*e1+3*e0+4*e1+2>
BasisOfExternalHom( u, u );
basis := BasisOfExternalHom( u, u );
#! [ <1>, <e0>, <e1>, <e0*e1> ]
CoefficientsOfMorphism( alpha );
coeffs := CoefficientsOfMorphism( alpha );
#! [ 2, 3, 4, 5 ]
IsCongruentForMorphisms( alpha, SumOfMorphisms( u, ListN( CoefficientsOfMorphism( alpha ), BasisOfExternalHom( u, u ), { x, y } -> MultiplyWithElementOfCommutativeRingForMorphisms( x, y ) ), u ) );
IsCongruentForMorphisms( alpha, LinearCombinationOfMorphisms( u, coeffs, basis, u ) );
#! true
u_op := Opposite( u );
#! <An object in Opposite( Ring as category( Q{e0,e1} ) )>
alpha_op := Opposite( alpha );
#! <A morphism in Opposite( Ring as category( Q{e0,e1} ) )>
basis := BasisOfExternalHom( u_op, u_op );;
coeffs := CoefficientsOfMorphism( alpha_op );
#! [ 2, 3, 4, 5 ]
IsCongruentForMorphisms( alpha_op, LinearCombinationOfMorphisms( u_op, coeffs, basis, u_op ) );
#! true

#! @EndExample
1 change: 1 addition & 0 deletions FreydCategoriesForCAP/gap/CategoryOfRows.autogen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
#! * <Ref BookName="CAP" Func="InterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructure" Label="for Is" />
#! * <Ref BookName="CAP" Func="InterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructureWithGivenObjects" Label="for Is" />
#! * <Ref BookName="CAP" Func="InterpretMorphismFromDistinguishedObjectToHomomorphismStructureAsMorphism" Label="for Is" />
#! * <Ref BookName="CAP" Func="LinearCombinationOfMorphisms" Label="for Is" />
#! * <Ref BookName="CAP" Func="MereExistenceOfSolutionOfLinearSystemInAbCategory" Label="for Is" />
#! * <Ref BookName="CAP" Func="MultiplyWithElementOfCommutativeRingForMorphisms" Label="for Is" />
#! * <Ref BookName="CAP" Func="SolveLinearSystemInAbCategory" Label="for Is" />
Expand Down
10 changes: 4 additions & 6 deletions FreydCategoriesForCAP/gap/CategoryOfRows.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1326,9 +1326,8 @@ AddFinalDerivationBundle( "Using BasisOfExternalHom and CoefficientsOfMorphism t
[
[ BasisOfExternalHom, 1 ],
[ CoefficientsOfMorphism, 2 ],
[ MultiplyWithElementOfCommutativeRingForMorphisms, 2 ],
[ PreComposeList, 2 ],
[ SumOfMorphisms, 1 ]
[ LinearCombinationOfMorphisms, 1 ],
[ PreComposeList, 2 ]
],
[
HomomorphismStructureOnObjects,
Expand Down Expand Up @@ -1405,8 +1404,7 @@ AddFinalDerivationBundle( "Using BasisOfExternalHom and CoefficientsOfMorphism t
InterpretMorphismFromDistinguishedObjectToHomomorphismStructureAsMorphism,
[
[ BasisOfExternalHom, 1 ],
[ MultiplyWithElementOfCommutativeRingForMorphisms, 2 ],
[ SumOfMorphisms, 1 ]
[ LinearCombinationOfMorphisms, 1 ],
],
function ( cat, a, b, iota )
local coeffs, basis;
Expand All @@ -1415,7 +1413,7 @@ AddFinalDerivationBundle( "Using BasisOfExternalHom and CoefficientsOfMorphism t

basis := BasisOfExternalHom( cat, a, b );

return SumOfMorphisms( cat, a, ListN( coeffs, basis, { c, m } -> MultiplyWithElementOfCommutativeRingForMorphisms( cat, c, m ) ), b );
return LinearCombinationOfMorphisms( cat, a, coeffs, basis, b );

end
] :
Expand Down
2 changes: 1 addition & 1 deletion FreydCategoriesForCAP/gap/LinearClosure.gi
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ InstallMethodWithCache( ExtendFunctorToLinearClosureOfSource,

supp := List( supp, m -> ApplyFunctor( F, m ) );

return Sum( ListN( coeffs, supp, MultiplyWithElementOfCommutativeRingForMorphisms ) );
return LinearCombinationOfMorphisms( s, coeffs, supp, r );

end );

Expand Down
4 changes: 2 additions & 2 deletions LinearAlgebraForCAP/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SetPackageInfo( rec(

PackageName := "LinearAlgebraForCAP",
Subtitle := "Category of Matrices over a Field for CAP",
Version := "2023.08-01",
Version := "2023.08-02",
Date := (function ( ) if IsBound( GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE ) then return GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE; else return Concatenation( ~.Version{[ 1 .. 4 ]}, "-", ~.Version{[ 6, 7 ]}, "-01" ); fi; end)( ),
License := "GPL-2.0-or-later",

Expand Down Expand Up @@ -89,7 +89,7 @@ Dependencies := rec(
NeededOtherPackages := [ [ "ToolsForHomalg", ">= 2015.09.18" ],
[ "MatricesForHomalg", ">= 2023.01-01" ],
[ "GaussForHomalg", ">= 2021.04-02" ],
[ "CAP", ">= 2023.05-03" ],
[ "CAP", ">= 2023.08-07" ],
[ "MonoidalCategories", ">= 2023.02-04" ],
],
SuggestedOtherPackages := [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3501,6 +3501,21 @@ end

, 100 );

##
AddLinearCombinationOfMorphisms( cat,

########
function ( cat_1, source_1, list_of_ring_elements_1, list_of_morphisms_1, range_1 )
return CreateCapCategoryMorphismWithAttributes( cat_1, source_1, range_1, UnderlyingMatrix, Iterated( ListN( list_of_ring_elements_1, list_of_morphisms_1, function ( r_2, alpha_2 )
return r_2 * UnderlyingMatrix( alpha_2 );
end ), function ( alpha_2, beta_2 )
return alpha_2 + beta_2;
end, HomalgZeroMatrix( Dimension( source_1 ), Dimension( range_1 ), UnderlyingRing( cat_1 ) ) ) );
end
########

, 502 : IsPrecompiledDerivation := true );

##
AddMereExistenceOfSolutionOfLinearSystemInAbCategory( cat,

Expand Down

0 comments on commit 83500f6

Please sign in to comment.