Skip to content

Commit

Permalink
Merge pull request #1425 from TKuh/cat_first_integers
Browse files Browse the repository at this point in the history
Category as first argument for `IntegerCategory`
  • Loading branch information
zickgraf authored Aug 16, 2023
2 parents f369742 + 0da18c8 commit 6795a14
Showing 1 changed file with 50 additions and 64 deletions.
114 changes: 50 additions & 64 deletions CAP/examples/IntegerCategory.g
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@

LoadPackage( "CAP" );

DeclareRepresentation( "IsHomalgIntegerRep",
IsCapCategoryObjectRep,
[ ] );
DeclareCategory( "IsCategoryOfHomalgIntegers",
IsCapCategory );

BindGlobal( "TheTypeOfHomalgIntegers",
NewType( TheFamilyOfCapCategoryObjects,
IsHomalgIntegerRep ) );
DeclareCategory( "IsObjectInCategoryOfHomalgIntegers",
IsCapCategoryObject );

DeclareRepresentation( "IsHomalgIntegerMorphismRep",
IsCapCategoryMorphismRep,
[ ] );

BindGlobal( "TheTypeOfHomalgIntegerMorphism",
NewType( TheFamilyOfCapCategoryMorphisms,
IsHomalgIntegerMorphismRep ) );
DeclareCategory( "IsMorphismInCategoryOfHomalgIntegers",
IsCapCategoryMorphism );

############################
##
## Attributes
##
############################

DeclareAttribute( "AsInteger",
IsHomalgIntegerRep );
DeclareAttribute( "UnderlyingInteger",
IsObjectInCategoryOfHomalgIntegers );

############################
##
## Category
##
############################

integer_category := CreateCapCategory( "Integers" );
integer_category := CreateCapCategory( "HomalgIntegers",
IsCategoryOfHomalgIntegers,
IsObjectInCategoryOfHomalgIntegers,
IsMorphismInCategoryOfHomalgIntegers,
IsCapCategoryTwoCell );

integer_category!.category_as_first_argument := false;
integer_category!.category_as_first_argument := true;

#############################
##
Expand All @@ -50,14 +47,9 @@ InstallMethodWithCache( HomalgInteger,
[ IsInt ],

function( integer )
local homalg_integer;

homalg_integer := ObjectifyWithAttributes( rec( ), TheTypeOfHomalgIntegers,
AsInteger, integer );

Add( integer_category, homalg_integer );

return homalg_integer;
return CreateCapCategoryObjectWithAttributes( integer_category,
UnderlyingInteger, integer );

end );

Expand All @@ -70,51 +62,44 @@ InstallMethod( HomalgIntegerMorphism,

function( source, range )

if range < source then

Error( "such a morphism does not exist" );

fi;

return HomalgIntegerMorphism( HomalgInteger( source ), HomalgInteger( range ) );

end );

DeclareOperation( "HomalgIntegerMorphism",
[ IsHomalgIntegerRep, IsHomalgIntegerRep ] );
[ IsObjectInCategoryOfHomalgIntegers, IsObjectInCategoryOfHomalgIntegers ] );

##
InstallMethodWithCache( HomalgIntegerMorphism,
[ IsHomalgIntegerRep, IsHomalgIntegerRep ],
[ IsObjectInCategoryOfHomalgIntegers, IsObjectInCategoryOfHomalgIntegers ],

function( source, range )
local morphism;

if AsInteger( range ) < AsInteger( source ) then
if UnderlyingInteger( range ) < UnderlyingInteger( source ) then

Error( "such a morphism does not exist" );

fi;

morphism := ObjectifyWithAttributes( rec( ), TheTypeOfHomalgIntegerMorphism,
Source, source,
Range, range );

Add( integer_category, morphism );

return morphism;
return CreateCapCategoryMorphismWithAttributes( integer_category,
source,
range );

end );

##
AddIsCongruentForMorphisms( integer_category,

ReturnTrue );
function( cat, mor1, mor2 )

return true;

end );

##
AddIsZeroForMorphisms( integer_category,

function( a )
function( cat, a )

return true;

Expand All @@ -123,7 +108,7 @@ end );
##
AddAdditionForMorphisms( integer_category,

function( a, b )
function( cat, a, b )

return a;

Expand All @@ -132,12 +117,16 @@ end );
##
AddAdditiveInverseForMorphisms( integer_category,

IdFunc );
function( cat, mor )

return mor;

end );

##
AddZeroMorphism( integer_category,

function( a, b )
function( cat, a, b )

return HomalgIntegerMorphism( a, b );

Expand All @@ -146,7 +135,7 @@ end );
##
AddIdentityMorphism( integer_category,

function( obj )
function( cat, obj )

return HomalgIntegerMorphism( obj, obj );

Expand All @@ -155,7 +144,7 @@ end );
##
AddPreCompose( integer_category,

function( mor1, mor2 )
function( cat, mor1, mor2 )

return HomalgIntegerMorphism( Source( mor1 ), Range( mor2 ) );

Expand All @@ -164,10 +153,10 @@ end );
#
AddFiberProduct( integer_category,

function( product_mor )
function( cat, product_mor )
local pullback;

pullback := Gcd( List( product_mor, i -> AsInteger( Source( i ) ) ) );
pullback := Gcd( List( product_mor, i -> UnderlyingInteger( Source( i ) ) ) );

return HomalgInteger( pullback );

Expand All @@ -176,23 +165,22 @@ end );
##
AddProjectionInFactorOfFiberProductWithGivenFiberProduct( integer_category,

function( product_morx, coordinate, pullback )
function( cat, product_morx, coordinate, pullback )
local range;

range := Source( product_mor[ coordinate ] );
range := Source( product_morx[ coordinate ] );

return HomalgIntegerMorphism( pullback, range );

end );


##
AddPushout( integer_category,

function( product_mor )
function( cat, product_mor )
local pushout;

pushout := Lcm( List( product_mor, i -> AsInteger( Range( i ) ) ) );
pushout := Lcm( List( product_mor, i -> UnderlyingInteger( Range( i ) ) ) );

return HomalgInteger( pushout );

Expand All @@ -201,7 +189,7 @@ end );
##
AddInjectionOfCofactorOfPushoutWithGivenPushout( integer_category,

function( product_mor, coordinate, pushout )
function( cat, product_mor, coordinate, pushout )
local source;

source := Range( product_mor[ coordinate ] );
Expand All @@ -213,15 +201,12 @@ end );
##
AddLiftAlongMonomorphism( integer_category,

function( monomorphism, test_morphism )
function( cat, monomorphism, test_morphism )

return HomalgIntegerMorphism( Source( test_morphism ), Source( monomorphism ) );

end );

##


###################################
##
## View
Expand All @@ -230,20 +215,21 @@ end );

##
InstallMethod( ViewString,
[ IsHomalgIntegerRep ],
[ IsObjectInCategoryOfHomalgIntegers ],

function( integer_obj )

return Concatenation( "<The integer object representing ", String( AsInteger( integer_obj ) ), ">" );
return Concatenation( "<The integer object representing ", String( UnderlyingInteger( integer_obj ) ), ">" );

end );

##
InstallMethod( ViewString,
[ IsHomalgIntegerMorphismRep ],
[ IsMorphismInCategoryOfHomalgIntegers ],

function( integer_mor )

return Concatenation( "<", String( AsInteger( Source( integer_mor ) ) ), " -> ", String( AsInteger( Range( integer_mor ) ) ), ">" );
return Concatenation( "<", String( UnderlyingInteger( Source( integer_mor ) ) ), " -> ", String( UnderlyingInteger( Range( integer_mor ) ) ), ">" );

end );

0 comments on commit 6795a14

Please sign in to comment.