Skip to content

Commit 0663c50

Browse files
authored
Merge pull request #701 from zickgraf/WithGiven
Support WithGiven operations with both source and range given
2 parents 83cccba + 8f3d33a commit 0663c50

17 files changed

+729
-344
lines changed

CAP/PackageInfo.g

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SetPackageInfo( rec(
1010

1111
PackageName := "CAP",
1212
Subtitle := "Categories, Algorithms, Programming",
13-
Version := "2021.08-01",
13+
Version := "2021.08-02",
1414
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
1515
License := "GPL-2.0-or-later",
1616

@@ -98,7 +98,7 @@ PackageDoc := rec(
9898
Dependencies := rec(
9999
GAP := ">= 4.9.1",
100100
NeededOtherPackages := [ [ "AutoDoc", ">= 2016.02.16" ],
101-
[ "ToolsForHomalg", ">= 2021.05-02" ],
101+
[ "ToolsForHomalg", ">= 2021.08-01" ],
102102
[ "io", ">=0" ],
103103
],
104104
SuggestedOtherPackages := [ [ "Browse", ">=0" ],

CAP/doc/AddFunctions.autodoc

Lines changed: 64 additions & 51 deletions
Large diffs are not rendered by default.

CAP/gap/CategoryMorphisms.gd

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,25 @@ DeclareOperation( "AddHomomorphismStructureOnObjects",
19411941
DeclareOperation( "HomomorphismStructureOnMorphisms",
19421942
[ IsCapCategoryMorphism, IsCapCategoryMorphism ] );
19431943

1944+
#! @Description
1945+
#! The arguments are a category $C$ and a function $F$.
1946+
#! This operation adds the given function $F$
1947+
#! to the category for the basic operation <C>HomomorphismStructureOnMorphisms</C>.
1948+
#! $F: ( \alpha: a \rightarrow a', \beta: b \rightarrow b' ) \mapsto H( \alpha, \beta )$.
1949+
#! @Returns nothing
1950+
#! @Arguments C, F
1951+
DeclareOperation( "AddHomomorphismStructureOnMorphisms",
1952+
[ IsCapCategory, IsFunction ] );
1953+
1954+
DeclareOperation( "AddHomomorphismStructureOnMorphisms",
1955+
[ IsCapCategory, IsFunction, IsInt ] );
1956+
1957+
DeclareOperation( "AddHomomorphismStructureOnMorphisms",
1958+
[ IsCapCategory, IsList, IsInt ] );
1959+
1960+
DeclareOperation( "AddHomomorphismStructureOnMorphisms",
1961+
[ IsCapCategory, IsList ] );
1962+
19441963
#! @Description
19451964
#! The arguments are an object $s = H(a',b)$ in $D$,
19461965
#! two morphisms $\alpha: a \rightarrow a', \beta: b \rightarrow b'$ in $C$,
@@ -2025,6 +2044,34 @@ DeclareOperation( "AddInterpretMorphismAsMorphismFromDistinguishedObjectToHomomo
20252044
DeclareOperation( "AddInterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructure",
20262045
[ IsCapCategory, IsList ] );
20272046

2047+
#! @Description
2048+
#! The arguments are the distinguished object $1$, a morphism $\alpha: a \rightarrow a'$, and the object $r = H(a,a')$.
2049+
#! The output is the corresponding morphism
2050+
#! $\nu( \alpha ): 1 \rightarrow r$ in $D$ of the homomorphism structure.
2051+
#! @Returns a morphism in $\mathrm{Hom}_{D}(1, r)$
2052+
#! @Arguments alpha
2053+
DeclareOperation( "InterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructureWithGivenObjects",
2054+
[ IsCapCategoryObject, IsCapCategoryMorphism, IsCapCategoryObject ] );
2055+
2056+
#! @Description
2057+
#! The arguments are a category $C$ and a function $F$.
2058+
#! This operation adds the given function $F$
2059+
#! to the category for the basic operation <C>InterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructureWithGivenObjects</C>.
2060+
#! $F: (1, \alpha: a \rightarrow a', r) \mapsto (\nu(\alpha):1 \rightarrow r)$.
2061+
#! @Returns nothing
2062+
#! @Arguments C, F
2063+
DeclareOperation( "AddInterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructureWithGivenObjects",
2064+
[ IsCapCategory, IsFunction ] );
2065+
2066+
DeclareOperation( "AddInterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructureWithGivenObjects",
2067+
[ IsCapCategory, IsFunction, IsInt ] );
2068+
2069+
DeclareOperation( "AddInterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructureWithGivenObjects",
2070+
[ IsCapCategory, IsList, IsInt ] );
2071+
2072+
DeclareOperation( "AddInterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructureWithGivenObjects",
2073+
[ IsCapCategory, IsList ] );
2074+
20282075
#! @Description
20292076
#! The arguments are
20302077
#! objects $a,a'$ in $C$

CAP/gap/CategoryMorphisms.gi

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -524,31 +524,6 @@ InstallMethod( PostCompose,
524524

525525
end );
526526

527-
##
528-
InstallMethod( HomomorphismStructureOnMorphisms,
529-
[ IsCapCategoryMorphism, IsCapCategoryMorphism ],
530-
531-
function( alpha, beta )
532-
533-
return HomomorphismStructureOnMorphisms( CapCategory( alpha ), alpha, beta );
534-
535-
end );
536-
537-
##
538-
InstallOtherMethodForCompilerForCAP( HomomorphismStructureOnMorphisms,
539-
[ IsCapCategory, IsCapCategoryMorphism, IsCapCategoryMorphism ],
540-
541-
function( cat, alpha, beta )
542-
543-
return HomomorphismStructureOnMorphismsWithGivenObjects(
544-
cat,
545-
HomomorphismStructureOnObjects( cat, Range( alpha ), Source( beta ) ),
546-
alpha, beta,
547-
HomomorphismStructureOnObjects( cat, Source( alpha ), Range( beta ) )
548-
);
549-
550-
end );
551-
552527
##
553528
InstallMethod( HomStructure,
554529
[ IsCapCategoryMorphism, IsCapCategoryMorphism ],

CAP/gap/InstallAdds.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
#
44
# Declarations
55
#
6+
7+
#! @Chapter Add Functions
8+
9+
#! @Section InstallAdd Function
10+
11+
#! @Description
12+
#! See <Ref Sect="Section_CapInternalInstallAdd" />.
13+
#! @Arguments record
614
DeclareGlobalFunction( "CapInternalInstallAdd" );
715

816
DeclareGlobalFunction( "CAP_INTERNAL_INSTALL_ADDS_FROM_RECORD" );

CAP/gap/InstallAdds.gi

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -208,29 +208,24 @@ InstallGlobalFunction( CapInternalInstallAdd,
208208
without_given_weight := CurrentOperationWeight( category!.derivations_weight_list, without_given_name );
209209
with_given_weight := CurrentOperationWeight( category!.derivations_weight_list, with_given_name );
210210

211-
if record.is_with_given = false then
211+
# take the weight of the currently added function into account
212+
if record.is_with_given then
212213

213-
if with_given_weight <= weight then
214-
215-
category!.redirects.( without_given_name ) := true;
216-
217-
else
218-
219-
category!.redirects.( without_given_name ) := false;
220-
221-
fi;
214+
with_given_weight := weight;
222215

223216
else
224217

225-
if weight <= without_given_weight then
226-
227-
category!.redirects.( without_given_name ) := true;
228-
229-
else
230-
231-
category!.redirects.( without_given_name ) := false;
232-
233-
fi;
218+
without_given_weight := weight;
219+
220+
fi;
221+
222+
if with_given_weight <= without_given_weight then
223+
224+
category!.redirects.( without_given_name ) := true;
225+
226+
else
227+
228+
category!.redirects.( without_given_name ) := false;
234229

235230
fi;
236231

@@ -579,10 +574,16 @@ InstallGlobalFunction( CapInternalInstallAdd,
579574

580575
end );
581576

582-
BindGlobal( "CAP_INTERNAL_INSTALL_WITH_GIVEN_DERIVATION_PAIR", function( without_given_name, with_given_name, object_name, with_given_arguments_names, object_arguments_positions )
583-
local without_given_arguments_names, with_given_via_without_given_function, without_given_via_with_given_function;
577+
BindGlobal( "CAP_INTERNAL_INSTALL_WITH_GIVEN_DERIVATION_PAIR", function( without_given_rec, with_given_rec )
578+
local without_given_name, with_given_name, without_given_arguments_names, with_given_arguments_names, with_given_object_position, with_given_via_without_given_function, with_given_arguments_strings, without_given_via_with_given_function;
579+
580+
without_given_name := without_given_rec.function_name;
581+
with_given_name := with_given_rec.function_name;
582+
583+
without_given_arguments_names := without_given_rec.input_arguments_names;
584+
with_given_arguments_names := with_given_rec.input_arguments_names;
584585

585-
without_given_arguments_names := with_given_arguments_names{[ 1 .. Length( with_given_arguments_names ) - 1 ]};
586+
with_given_object_position := without_given_rec.with_given_object_position;
586587

587588
with_given_via_without_given_function := EvalString( ReplacedStringViaRecord(
588589
"""
@@ -599,78 +600,74 @@ BindGlobal( "CAP_INTERNAL_INSTALL_WITH_GIVEN_DERIVATION_PAIR", function( without
599600
)
600601
) );
601602

603+
if with_given_object_position = "Source" then
604+
605+
with_given_arguments_strings := Concatenation( without_given_arguments_names, [ without_given_rec.output_source_getter_string ] );
606+
607+
elif with_given_object_position = "Range" then
608+
609+
with_given_arguments_strings := Concatenation( without_given_arguments_names, [ without_given_rec.output_range_getter_string ] );
610+
611+
elif with_given_object_position = "both" then
612+
613+
with_given_arguments_strings := Concatenation(
614+
[ without_given_arguments_names[1] ],
615+
[ without_given_rec.output_source_getter_string ],
616+
without_given_arguments_names{[ 2 .. Length( without_given_arguments_names ) ]},
617+
[ without_given_rec.output_range_getter_string ]
618+
);
619+
620+
else
621+
622+
Error( "this should never happen" );
623+
624+
fi;
625+
602626
without_given_via_with_given_function := EvalString( ReplacedStringViaRecord(
603627
"""
604628
function( without_given_arguments )
605629
606-
return with_given_name( without_given_arguments, object_name( object_arguments ) );
630+
return with_given_name( with_given_arguments );
607631
608632
end
609633
""",
610634
rec(
611635
without_given_arguments := without_given_arguments_names,
636+
with_given_arguments := with_given_arguments_strings,
612637
with_given_name := with_given_name,
613-
object_name := object_name,
614-
object_arguments := without_given_arguments_names{object_arguments_positions},
615638
)
616639
) );
617640

618641
AddDerivationToCAP( ValueGlobal( with_given_name ),
619-
[ [ ValueGlobal( without_given_name ), 1 ] ],
620642
with_given_via_without_given_function
621-
: Description := Concatenation( with_given_name, " by calling ", without_given_name, " with the last argument dropped" ) );
643+
: Description := Concatenation( with_given_name, " by calling ", without_given_name, " with the WithGiven argument(s) dropped" ) );
622644

623645
AddDerivationToCAP( ValueGlobal( without_given_name ),
624-
[ [ ValueGlobal( with_given_name ), 1 ],
625-
[ ValueGlobal( object_name ), 1 ] ],
626646
without_given_via_with_given_function
627-
: Description := Concatenation( without_given_name, " by calling ", with_given_name, " with ", object_name, " as last argument" ) );
647+
: Description := Concatenation( without_given_name, " by calling ", with_given_name, " with the WithGiven object(s)" ) );
628648

629649
end );
630650

631651
BindGlobal( "CAP_INTERNAL_INSTALL_WITH_GIVEN_DERIVATIONS", function( record )
632-
local recnames, current_recname, current_rec, without_given_name, with_given_name, object_name, with_given_arguments_names, object_arguments_positions;
652+
local recnames, current_rec, without_given_rec, with_given_rec, current_recname;
633653

634654
recnames := RecNames( record );
635655

636656
for current_recname in recnames do
637657

638658
current_rec := record.(current_recname);
639-
659+
640660
if current_rec.is_with_given then
641661

642-
without_given_name := current_rec.with_given_without_given_name_pair[1];
643-
with_given_name := current_rec.with_given_without_given_name_pair[2];
644-
object_name := current_rec.with_given_object_name;
645-
with_given_arguments_names := current_rec.input_arguments_names;
646-
object_arguments_positions := record.( without_given_name ).object_arguments_positions;
662+
without_given_rec := record.(current_rec.with_given_without_given_name_pair[1]);
663+
with_given_rec := record.(current_rec.with_given_without_given_name_pair[2]);
647664

648-
if record.( without_given_name ).filter_list[1] <> "category" or record.( object_name ).filter_list[1] <> "category" or record.( with_given_name ).filter_list[1] <> "category" then
649-
650-
Display( Concatenation(
651-
"WARNING: You seem to be relying on automatically installed WithGiven derivations but the first arguments of the functions involved are not the category. ",
652-
"The automatic WithGiven derivation will not be installed. ",
653-
"To prevent this warning, add the category as the first argument to all functions involved. ",
654-
"Search for `category_as_first_argument` in the documentation for more details."
655-
) );
656-
657-
elif Length( record.( without_given_name ).filter_list ) + 1 <> Length( record.( with_given_name ).filter_list ) then
658-
659-
Display( Concatenation(
660-
"WARNING: You seem to be relying on automatically installed WithGiven derivations. ",
661-
"For this, the with given method must have exactly one additional argument compared to the without given method. ",
662-
"This is not the case, so no automatic WithGiven derivation will be installed."
663-
) );
664-
665-
else
666-
667-
CAP_INTERNAL_INSTALL_WITH_GIVEN_DERIVATION_PAIR( without_given_name, with_given_name, object_name, with_given_arguments_names, object_arguments_positions );
668-
669-
fi;
665+
CAP_INTERNAL_INSTALL_WITH_GIVEN_DERIVATION_PAIR( without_given_rec, with_given_rec );
670666

671667
fi;
672668

673669
od;
670+
674671
end );
675672

676673
InstallGlobalFunction( CAP_INTERNAL_INSTALL_ADDS_FROM_RECORD,

CAP/gap/LimitConvenience.gi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
InstallGlobalFunction( "CAP_INTERNAL_GENERATE_CONVENIENCE_METHODS_FOR_LIMITS",
88
function ( package_name, method_name_record, limits )
9-
local output_string, generate_universal_morphism_convenience, generate_functorial_convenience_method, number_of_diagram_arguments, functorial_record, filter_list, input_type, replaced_filter_list, replaced_filter_list_string, arguments_string, source_diagram_arguments_string, range_diagram_arguments_string, source_diagram_input_type, range_diagram_input_type, call_arguments_string, limit, existing_string, output_path;
9+
local output_string, generate_universal_morphism_convenience, generate_functorial_convenience_method, number_of_diagram_arguments, functorial_record, filter_list, input_type, replaced_filter_list, replaced_filter_list_string, arguments_string, source_diagram_arguments_string, range_diagram_arguments_string, source_diagram_input_type, range_diagram_input_type, call_arguments_string, limit, output_path;
1010

1111
output_string :=
1212
"""# SPDX-License-Identifier: GPL-2.0-or-later
@@ -562,9 +562,7 @@ InstallGlobalFunction( "CAP_INTERNAL_GENERATE_CONVENIENCE_METHODS_FOR_LIMITS",
562562

563563
od;
564564

565-
existing_string := ReadFileFromPackageForHomalg( package_name, "LimitConvenienceOutput.gi" );
566-
567-
if output_string <> existing_string then
565+
if not IsExistingFileInPackageForHomalg( package_name, "LimitConvenienceOutput.gi" ) or output_string <> ReadFileFromPackageForHomalg( package_name, "LimitConvenienceOutput.gi" ) then
568566

569567
output_path := Filename( DirectoryTemporary( ), "LimitConvenienceOutput.gi" );
570568

0 commit comments

Comments
 (0)