Skip to content

Commit 7fa1cd0

Browse files
authored
Merge pull request #79 from mohamed-barakat/DirectProduct
made two direct-product-related CAP operations purely functional for SkeletalFinSets
2 parents 21e4a20 + 3b1b8e3 commit 7fa1cd0

File tree

7 files changed

+76
-56
lines changed

7 files changed

+76
-56
lines changed

PackageInfo.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SetPackageInfo( rec(
1010

1111
PackageName := "FinSetsForCAP",
1212
Subtitle := "The elementary topos of (skeletal) finite sets",
13-
Version := "2021.12-04",
13+
Version := "2021.12-06",
1414

1515
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
1616
License := "GPL-2.0-or-later",

examples/PrecompileCategoryOfSkeletalFinSets.g

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,12 @@ given_arguments := [ ];;
1212
compiled_category_name := "CategoryOfSkeletalFinSetsPrecompiled";;
1313
package_name := "FinSetsForCAP";;
1414

15-
uncompiled_SkeletalFinSets :=
16-
CategoryOfSkeletalFinSets( : no_precompiled_code := true );;
17-
1815
CapJitPrecompileCategoryAndCompareResult(
1916
category_constructor,
2017
given_arguments,
2118
package_name,
2219
compiled_category_name
23-
: operations := Difference(
24-
ListPrimitivelyInstalledOperationsOfCategory(
25-
uncompiled_SkeletalFinSets
26-
),
27-
[
28-
"ProjectionInFactorOfDirectProduct", # uses CAP prepare functions
29-
"UniversalMorphismIntoDirectProduct", # uses CAP prepare functions
30-
]
31-
)
20+
: operations := "primitive"
3221
);;
3322

3423
CategoryOfSkeletalFinSetsPrecompiled( );

examples/SkeletalFiberProduct.g

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ n1 := FinSet( 3 );
1010
iota1 := EmbeddingOfFinSets( n1, m );
1111
#! <A monomorphism in SkeletalFinSets>
1212
Display( iota1 );
13-
#! [ 3, [ 1, 2, 3 ], 5 ]
13+
#! [ 3, [ 1 .. 3 ], 5 ]
1414
n2 := FinSet( 4 );
1515
#! <An object in SkeletalFinSets>
1616
iota2 := EmbeddingOfFinSets( n2, m );
1717
#! <A monomorphism in SkeletalFinSets>
1818
Display( iota2 );
19-
#! [ 4, [ 1, 2, 3, 4 ], 5 ]
19+
#! [ 4, [ 1 .. 4 ], 5 ]
2020
D := [ iota1, iota2 ];
2121
#! [ <A monomorphism in SkeletalFinSets>, <A monomorphism in SkeletalFinSets> ]
2222
Fib := FiberProduct( D );

examples/SkeletalPushout.g

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ N1 := FinSet( 3 );
1010
iota1 := EmbeddingOfFinSets( N1, M );
1111
#! <A monomorphism in SkeletalFinSets>
1212
Display( iota1 );
13-
#! [ 3, [ 1, 2, 3 ], 5 ]
13+
#! [ 3, [ 1 .. 3 ], 5 ]
1414
N2 := FinSet( 2 );
1515
#! <An object in SkeletalFinSets>
1616
iota2 := EmbeddingOfFinSets( N2, M );
1717
#! <A monomorphism in SkeletalFinSets>
1818
Display( iota2 );
19-
#! [ 2, [ 1, 2 ], 5 ]
19+
#! [ 2, [ 1 .. 2 ], 5 ]
2020
D := [ iota1, iota2 ];
2121
#! [ <A monomorphism in SkeletalFinSets>, <A monomorphism in SkeletalFinSets> ]
2222
Fib := FiberProduct( D );

gap/FinSetsForCAP.gi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,11 @@ end );
609609
##
610610
AddUniversalMorphismIntoDirectProductWithGivenDirectProduct( category_of_finite_sets,
611611
function ( category_of_finite_sets, D, test_object, tau, T )
612-
local S, Graph;
612+
local Graph;
613613

614-
S := Source( tau[1] );
614+
Graph := List( AsList( test_object ), x -> [ x, List( tau, f -> f(x) ) ] );
615615

616-
Graph := List( AsList( S ), x -> [ x, List( tau, f -> f(x) ) ] );
617-
618-
return MapOfFinSetsNC( S, Graph, T );
616+
return MapOfFinSetsNC( test_object, Graph, T );
619617

620618
end );
621619

gap/SkeletalFinSetsForCAP.gi

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ InstallMethod( EmbeddingOfFinSets,
104104
function ( s, t )
105105
local iota;
106106

107-
iota := MapOfFinSets( s, List( s, x -> x ), t );
107+
iota := MapOfFinSets( s, AsList( s ), t );
108108

109109
Assert( 3, IsMonomorphism( iota ) );
110110
SetIsMonomorphism( iota, true );
@@ -528,51 +528,36 @@ AddDirectProduct( SkeletalFinSets,
528528
end );
529529

530530
##
531-
AddProjectionInFactorOfDirectProduct( SkeletalFinSets, CAPOperationPrepareFunction( "ProjectionInFactorOfBinaryDirectProductToProjectionInFactorOfDirectProduct", SkeletalFinSets, function ( cat, M, N, pos )
532-
local S, T, n, imgs, i;
531+
AddProjectionInFactorOfDirectProductWithGivenDirectProduct( SkeletalFinSets,
532+
function ( cat, D, k, P )
533+
local T, l, a;
533534

534-
S := DirectProduct( [ M, N ] );
535-
if pos = 1 then
536-
T := M;
537-
else
538-
T := N;
539-
fi;
535+
T := D[k];
540536

541-
n := Length( N );
537+
l := Length( T );
542538

543-
imgs := [ ];
544-
545-
for i in AsList( S ) do
546-
if pos = 2 then
547-
Add( imgs, (i - 1) mod n );
548-
else
549-
Add( imgs, Int( (i - 1) / n ) );
550-
fi;
551-
od;
539+
a := Product( D{[ k + 1 .. Length( D ) ]}, M -> Length( M ) );
552540

553-
imgs := List( imgs, img -> img + 1 );
554-
555-
return MapOfFinSets( S, imgs, T );
556-
end ) );
541+
return MapOfFinSets( P, List( [ 0 .. Length( P ) - 1 ], i -> 1 + RemInt( QuoInt( i, a ), l ) ), T );
542+
543+
end );
557544

558545
##
559-
AddUniversalMorphismIntoDirectProduct( SkeletalFinSets, CAPOperationPrepareFunction( "UniversalMorphismIntoBinaryDirectProductToUniversalMorphismIntoDirectProduct", SkeletalFinSets, function ( cat, tau1, tau2 )
560-
local S, T, n, imgs, i;
546+
AddUniversalMorphismIntoDirectProductWithGivenDirectProduct( SkeletalFinSets,
547+
function ( cat, D, T, tau, P )
548+
local l, d, dd, taus;
561549

562-
S := Source( tau1 );
563-
T := DirectProduct( [ Range( tau1 ), Range( tau2 ) ] );
550+
l := Length( D );
564551

565-
n := Length( Range( tau2 ) );
552+
d := List( D, x -> Length( x ) );
566553

567-
imgs := [ ];
554+
dd := List( [ 1 .. l ], i -> Product( d{[ i + 1 .. l ]} ) );
568555

569-
for i in AsList( S ) do
570-
Add( imgs, (AsList( tau1 )[i] - 1) * n + AsList( tau2 )[i] );
571-
od;
556+
taus := List( tau, x -> AsList( x ) );
572557

573-
return MapOfFinSets( S, imgs, T );
558+
return MapOfFinSets( T, List( AsList( T ), i -> 1 + Sum( [ 1 .. l ], j -> ( taus[j][i] - 1 ) * dd[j] ) ), P );
574559

575-
end ) );
560+
end );
576561

577562
##
578563
AddEqualizer( SkeletalFinSets,

gap/precompiled_categories/CategoryOfSkeletalFinSetsPrecompiled.gi

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,25 @@ end
634634

635635
, 100 );
636636

637+
##
638+
AddProjectionInFactorOfDirectProductWithGivenDirectProduct( cat,
639+
640+
########
641+
function ( cat_1, objects_1, k_1, P_1 )
642+
local hoisted_1_1, hoisted_2_1, deduped_3_1;
643+
deduped_3_1 := objects_1[k_1];
644+
hoisted_2_1 := Length( deduped_3_1 );
645+
hoisted_1_1 := Product( objects_1{[ k_1 + 1 .. Length( objects_1 ) ]}, function ( M_2 )
646+
return Length( M_2 );
647+
end );
648+
return MapOfFinSets( P_1, List( [ 0 .. Length( P_1 ) - 1 ], function ( i_2 )
649+
return 1 + REM_INT( QUO_INT( i_2, hoisted_1_1 ), hoisted_2_1 );
650+
end ), deduped_3_1 );
651+
end
652+
########
653+
654+
, 100 );
655+
637656
##
638657
AddProjectionOntoCoequalizerWithGivenCoequalizer( cat,
639658

@@ -727,6 +746,35 @@ end
727746

728747
, 100 );
729748

749+
##
750+
AddUniversalMorphismIntoDirectProductWithGivenDirectProduct( cat,
751+
752+
########
753+
function ( cat_1, objects_1, T_1, tau_1, P_1 )
754+
local hoisted_1_1, hoisted_2_1, hoisted_3_1, hoisted_4_1, hoisted_5_1, deduped_6_1, deduped_7_1;
755+
deduped_7_1 := Length( objects_1 );
756+
deduped_6_1 := [ 1 .. deduped_7_1 ];
757+
hoisted_5_1 := deduped_6_1;
758+
hoisted_3_1 := List( objects_1, function ( x_2 )
759+
return Length( x_2 );
760+
end );
761+
hoisted_2_1 := deduped_7_1;
762+
hoisted_4_1 := List( deduped_6_1, function ( i_2 )
763+
return Product( hoisted_3_1{[ i_2 + 1 .. hoisted_2_1 ]} );
764+
end );
765+
hoisted_1_1 := List( tau_1, function ( x_2 )
766+
return AsList( x_2 );
767+
end );
768+
return MapOfFinSets( T_1, List( AsList( T_1 ), function ( i_2 )
769+
return 1 + Sum( hoisted_5_1, function ( j_3 )
770+
return (hoisted_1_1[j_3][i_2] - 1) * hoisted_4_1[j_3];
771+
end );
772+
end ), P_1 );
773+
end
774+
########
775+
776+
, 100 );
777+
730778
##
731779
AddUniversalMorphismIntoEqualizerWithGivenEqualizer( cat,
732780

0 commit comments

Comments
 (0)