Skip to content

Commit d96ef23

Browse files
a first attempt for a functional coequalizer
1 parent 478e58a commit d96ef23

File tree

4 files changed

+218
-46
lines changed

4 files changed

+218
-46
lines changed

examples/PrecompileCategoryOfSkeletalFinSetsWithMorphismsGivenByLists.g

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,42 @@ CapJitPrecompileCategoryAndCompareResult(
4141
number_of_objectified_objects_in_data_structure_of_morphism := 2,
4242
number_of_objectified_morphisms_in_data_structure_of_morphism := 1
4343
);;
44+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
45+
#! Please write a bug report including this message.
46+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
47+
#! Please write a bug report including this message.
48+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
49+
#! Please write a bug report including this message.
50+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
51+
#! Please write a bug report including this message.
52+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
53+
#! Please write a bug report including this message.
54+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
55+
#! Please write a bug report including this message.
56+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
57+
#! Please write a bug report including this message.
58+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
59+
#! Please write a bug report including this message.
60+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
61+
#! Please write a bug report including this message.
62+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
63+
#! Please write a bug report including this message.
64+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
65+
#! Please write a bug report including this message.
66+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
67+
#! Please write a bug report including this message.
68+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
69+
#! Please write a bug report including this message.
70+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
71+
#! Please write a bug report including this message.
72+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
73+
#! Please write a bug report including this message.
74+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
75+
#! Please write a bug report including this message.
76+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
77+
#! Please write a bug report including this message.
78+
#! WARNING: Could not detect domain of function in call of PositionsProperty.
79+
#! Please write a bug report including this message.
4480

4581
SkeletalCategoryOfFiniteSetsWithMorphismsGivenByListsPrecompiled( );
4682
#! SkeletalFinSets

gap/SkeletalFinSets.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ DeclareOperation( "ImageObject",
138138
# Technical functions
139139
DeclareGlobalFunction( "INSTALL_FUNCTIONS_FOR_SKELETAL_FIN_SETS" );
140140

141-
DeclareGlobalFunction( "SKELETAL_FIN_SETS_ExplicitCoequalizer" );
142-
CapJitAddTypeSignature( "SKELETAL_FIN_SETS_ExplicitCoequalizer", [ IsObjectInSkeletalCategoryOfFiniteSets, IsList ], CapJitDataTypeOfListOf( CapJitDataTypeOfListOf( IsBigInt ) ) );
141+
DeclareOperation( "SKELETAL_FIN_SETS_ExplicitCoequalizer",
142+
[ IsSkeletalCategoryOfFiniteSets, IsObjectInSkeletalCategoryOfFiniteSets, IsList ] );
143+
#CapJitAddTypeSignature( "SKELETAL_FIN_SETS_ExplicitCoequalizer", [ IsObjectInSkeletalCategoryOfFiniteSets, IsList ], CapJitDataTypeOfListOf( CapJitDataTypeOfListOf( IsBigInt ) ) );
143144

144145
DeclareGlobalFunction( "SKELETAL_FIN_SETS_IsMonomorphism" );
145146
CapJitAddTypeSignature( "SKELETAL_FIN_SETS_IsMonomorphism", [ IsList, IsBigInt ], IsBool );

gap/SkeletalFinSets.gi

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -164,43 +164,84 @@ InstallMethod( CallFuncList,
164164
end );
165165

166166
##
167-
InstallGlobalFunction( SKELETAL_FIN_SETS_ExplicitCoequalizer,
168-
function ( s, D )
169-
local T, Cq, t, L, i;
167+
InstallMethodForCompilerForCAP( SKELETAL_FIN_SETS_ExplicitCoequalizer,
168+
[ IsSkeletalCategoryOfFiniteSets, IsObjectInSkeletalCategoryOfFiniteSets, IsList ],
169+
170+
function ( cat, target, D )
171+
local data, s, t, imgs, predicate_inner, func_inner, preidcate_outer, func_outer, initial_outer, Cq;
170172

171-
T := AsList( s );
173+
data := List( D, f -> AsList( f ) );
172174

173-
Cq := [ ];
175+
s := Length( data[1] );
176+
t := Length( target );
174177

175-
while not IsEmpty( T ) do
176-
t := T[1];
177-
t := Union( List( D, f_j -> List( Union( List( D, f_i -> Preimage( f_i, [ t ] ) ) ), f_j ) ) );
178-
if IsEmpty( t ) then
179-
t := [ T[1] ];
180-
fi;
181-
Add( Cq, t );
182-
T := Difference( T, t );
183-
od;
178+
imgs := List( [ 0 .. s - 1 ], x -> Set( List( data, f -> f[1 + x] ) ) );
184179

185-
T := AsList( s );
186-
187-
if Concatenation( Cq ) <> T then
188-
for t in T do
189-
L := [ ];
190-
for i in [ 1 .. Length( Cq ) ] do
191-
if t in Cq[i] then
192-
Add( L, Cq[i] );
193-
fi;
194-
od;
195-
if Length( L ) > 1 then
196-
Cq := Difference( Cq, L );
197-
Add( Cq, Set( Concatenation( L ) ) );
198-
fi;
199-
od;
200-
fi;
180+
predicate_inner :=
181+
function ( eq_class_old, eq_class )
182+
183+
return Length( eq_class_old[1] ) = Length( eq_class[1] );
184+
185+
end;
186+
187+
func_inner :=
188+
function ( eq_class )
189+
local Cy, imgs, l, pos;
190+
191+
Cy := eq_class[1];
192+
193+
imgs := eq_class[2];
194+
195+
l := Length( imgs );
196+
197+
pos := PositionsProperty( [ 1 .. l ], j -> Length( Intersection( Cy, imgs[j] ) ) > 0 );
198+
199+
return Pair( Set( Concatenation( Cy, Concatenation( imgs{pos} ) ) ),
200+
imgs{Difference( [ 1 .. l ], pos )} );
201+
202+
end;
203+
204+
preidcate_outer :=
205+
function ( coeq_old, coeq )
206+
207+
return Length( coeq[1] ) = t;
208+
209+
end;
210+
211+
func_outer :=
212+
function ( coeq )
213+
local covered, y, imgs, initial_inner, eq_class, Cy, eq_classes;
214+
215+
covered := coeq[1];
216+
217+
y := SafeFirst( [ coeq[2] + 1 .. t - 1 ], y -> not ( y in covered ) );
218+
219+
imgs := coeq[3];
220+
221+
initial_inner := Pair( [ y ], imgs );
222+
223+
eq_class := CapFixpoint( predicate_inner, func_inner, initial_inner );
224+
225+
Cy := eq_class[1];
226+
227+
eq_classes := Concatenation( coeq[4], [ Cy ] );
228+
229+
return NTuple( 4,
230+
Set( Concatenation( covered, Cy ) ),
231+
y,
232+
eq_class[2],
233+
eq_classes );
234+
235+
end;
236+
237+
initial_outer := NTuple( 4,
238+
[ ], #### list of points covered sofar
239+
-1, ##### smallest uncovered element
240+
imgs, ### list of pre-equivalence classes unused sofar
241+
[ ] ); ## list of equivalence classes found sofar
242+
243+
return CapFixpoint( preidcate_outer, func_outer, initial_outer )[4];
201244

202-
return Set( Cq );
203-
204245
end );
205246

206247
##
@@ -731,7 +772,7 @@ end );
731772
AddCoequalizer( SkeletalFinSets,
732773
function ( cat, s, D )
733774

734-
return ObjectConstructor( cat, BigInt( Length( SKELETAL_FIN_SETS_ExplicitCoequalizer( s, D ) ) ) );
775+
return ObjectConstructor( cat, BigInt( Length( SKELETAL_FIN_SETS_ExplicitCoequalizer( cat, s, D ) ) ) );
735776

736777
end );
737778

@@ -740,7 +781,7 @@ AddProjectionOntoCoequalizerWithGivenCoequalizer( SkeletalFinSets,
740781
function ( cat, s, D, C )
741782
local Cq, cmp;
742783

743-
Cq := SKELETAL_FIN_SETS_ExplicitCoequalizer( s, D );
784+
Cq := SKELETAL_FIN_SETS_ExplicitCoequalizer( cat, s, D );
744785

745786
cmp := List( s, x -> -1 + BigInt( SafeUniquePositionProperty( Cq, c -> x in c ) ) );
746787

@@ -753,7 +794,7 @@ AddUniversalMorphismFromCoequalizerWithGivenCoequalizer( SkeletalFinSets,
753794
function ( cat, s, D, test_object, tau, C )
754795
local Cq;
755796

756-
Cq := SKELETAL_FIN_SETS_ExplicitCoequalizer( s, D );
797+
Cq := SKELETAL_FIN_SETS_ExplicitCoequalizer( cat, s, D );
757798

758799
return MorphismConstructor( cat, C, List( Cq, x -> AsList( tau )[1 + x[1]] ), Range( tau ) );
759800

gap/precompiled_categories/SkeletalCategoryOfFiniteSetsWithMorphismsGivenByListsPrecompiled.gi

Lines changed: 103 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,39 @@ end
178178

179179
########
180180
function ( cat_1, Y_1, morphisms_1 )
181-
return CreateCapCategoryObjectWithAttributes( cat_1, Length, BigInt( Length( SKELETAL_FIN_SETS_ExplicitCoequalizer( Y_1, morphisms_1 ) ) ) );
181+
local hoisted_2_1, deduped_3_1, deduped_4_1;
182+
deduped_4_1 := [ ];
183+
deduped_3_1 := Length( Y_1 );
184+
hoisted_2_1 := deduped_3_1 - 1;
185+
return CreateCapCategoryObjectWithAttributes( cat_1, Length, BigInt( Length( CapFixpoint( function ( coeq_old_2, coeq_2 )
186+
return Length( coeq_2[1] ) = deduped_3_1;
187+
end, function ( coeq_2 )
188+
local deduped_2_2, deduped_3_2, deduped_4_2, deduped_5_2;
189+
deduped_5_2 := coeq_2[1];
190+
deduped_4_2 := SafeFirst( [ coeq_2[2] + 1 .. hoisted_2_1 ], function ( y_3 )
191+
return not y_3 in deduped_5_2;
192+
end );
193+
deduped_3_2 := CapFixpoint( function ( eq_class_old_3, eq_class_3 )
194+
return Length( eq_class_old_3[1] ) = Length( eq_class_3[1] );
195+
end, function ( eq_class_3 )
196+
local deduped_3_3, deduped_4_3, deduped_5_3, deduped_6_3;
197+
deduped_6_3 := eq_class_3[2];
198+
deduped_5_3 := eq_class_3[1];
199+
deduped_4_3 := [ 1 .. Length( deduped_6_3 ) ];
200+
deduped_3_3 := PositionsProperty( deduped_4_3, function ( j_4 )
201+
return Length( Intersection( deduped_5_3, deduped_6_3[j_4] ) ) > 0;
202+
end );
203+
return NTuple( 2, SSortedList( Concatenation( deduped_5_3, Concatenation( deduped_6_3{deduped_3_3} ) ) ), deduped_6_3{Difference( deduped_4_3, deduped_3_3 )} );
204+
end, NTuple( 2, [ deduped_4_2 ], coeq_2[3] ) );
205+
deduped_2_2 := deduped_3_2[1];
206+
return NTuple( 4, SSortedList( Concatenation( deduped_5_2, deduped_2_2 ) ), deduped_4_2, deduped_3_2[2], Concatenation( coeq_2[4], [ deduped_2_2 ] ) );
207+
end, NTuple( 4, deduped_4_1, -1, List( [ 0 .. CAP_JIT_INCOMPLETE_LOGIC( Length( AsList( CAP_JIT_INCOMPLETE_LOGIC( morphisms_1[1] ) ) ) ) - 1 ], function ( x_2 )
208+
local hoisted_1_2;
209+
hoisted_1_2 := 1 + x_2;
210+
return SSortedList( List( morphisms_1, function ( logic_new_func_x_3 )
211+
return AsList( logic_new_func_x_3 )[hoisted_1_2];
212+
end ) );
213+
end ), deduped_4_1 ) )[4] ) ) );
182214
end
183215
########
184216

@@ -726,10 +758,41 @@ end
726758

727759
########
728760
function ( cat_1, Y_1, morphisms_1, P_1 )
729-
local hoisted_1_1;
730-
hoisted_1_1 := SKELETAL_FIN_SETS_ExplicitCoequalizer( Y_1, morphisms_1 );
731-
return CreateCapCategoryMorphismWithAttributes( cat_1, Y_1, P_1, AsList, List( [ 0 .. Length( Y_1 ) - 1 ], function ( x_2 )
732-
return -1 + BigInt( SafeUniquePositionProperty( hoisted_1_1, function ( c_3 )
761+
local hoisted_2_1, hoisted_3_1, deduped_4_1, deduped_5_1;
762+
deduped_5_1 := [ ];
763+
deduped_4_1 := Length( Y_1 );
764+
hoisted_2_1 := deduped_4_1 - 1;
765+
hoisted_3_1 := CapFixpoint( function ( coeq_old_2, coeq_2 )
766+
return Length( coeq_2[1] ) = deduped_4_1;
767+
end, function ( coeq_2 )
768+
local deduped_2_2, deduped_3_2, deduped_4_2, deduped_5_2;
769+
deduped_5_2 := coeq_2[1];
770+
deduped_4_2 := SafeFirst( [ coeq_2[2] + 1 .. hoisted_2_1 ], function ( y_3 )
771+
return not y_3 in deduped_5_2;
772+
end );
773+
deduped_3_2 := CapFixpoint( function ( eq_class_old_3, eq_class_3 )
774+
return Length( eq_class_old_3[1] ) = Length( eq_class_3[1] );
775+
end, function ( eq_class_3 )
776+
local deduped_3_3, deduped_4_3, deduped_5_3, deduped_6_3;
777+
deduped_6_3 := eq_class_3[2];
778+
deduped_5_3 := eq_class_3[1];
779+
deduped_4_3 := [ 1 .. Length( deduped_6_3 ) ];
780+
deduped_3_3 := PositionsProperty( deduped_4_3, function ( j_4 )
781+
return Length( Intersection( deduped_5_3, deduped_6_3[j_4] ) ) > 0;
782+
end );
783+
return NTuple( 2, SSortedList( Concatenation( deduped_5_3, Concatenation( deduped_6_3{deduped_3_3} ) ) ), deduped_6_3{Difference( deduped_4_3, deduped_3_3 )} );
784+
end, NTuple( 2, [ deduped_4_2 ], coeq_2[3] ) );
785+
deduped_2_2 := deduped_3_2[1];
786+
return NTuple( 4, SSortedList( Concatenation( deduped_5_2, deduped_2_2 ) ), deduped_4_2, deduped_3_2[2], Concatenation( coeq_2[4], [ deduped_2_2 ] ) );
787+
end, NTuple( 4, deduped_5_1, -1, List( [ 0 .. CAP_JIT_INCOMPLETE_LOGIC( Length( AsList( CAP_JIT_INCOMPLETE_LOGIC( morphisms_1[1] ) ) ) ) - 1 ], function ( x_2 )
788+
local hoisted_1_2;
789+
hoisted_1_2 := 1 + x_2;
790+
return SSortedList( List( morphisms_1, function ( logic_new_func_x_3 )
791+
return AsList( logic_new_func_x_3 )[hoisted_1_2];
792+
end ) );
793+
end ), deduped_5_1 ) )[4];
794+
return CreateCapCategoryMorphismWithAttributes( cat_1, Y_1, P_1, AsList, List( Y_1, function ( x_2 )
795+
return -1 + BigInt( SafeUniquePositionProperty( hoisted_3_1, function ( c_3 )
733796
return (x_2 in c_3);
734797
end ) );
735798
end ) );
@@ -874,10 +937,41 @@ end
874937

875938
########
876939
function ( cat_1, Y_1, morphisms_1, T_1, tau_1, P_1 )
877-
local hoisted_1_1;
878-
hoisted_1_1 := AsList( tau_1 );
879-
return CreateCapCategoryMorphismWithAttributes( cat_1, P_1, Range( tau_1 ), AsList, List( SKELETAL_FIN_SETS_ExplicitCoequalizer( Y_1, morphisms_1 ), function ( x_2 )
880-
return hoisted_1_1[1 + x_2[1]];
940+
local hoisted_2_1, hoisted_3_1, deduped_4_1, deduped_5_1;
941+
deduped_5_1 := [ ];
942+
deduped_4_1 := Length( Y_1 );
943+
hoisted_3_1 := AsList( tau_1 );
944+
hoisted_2_1 := deduped_4_1 - 1;
945+
return CreateCapCategoryMorphismWithAttributes( cat_1, P_1, Range( tau_1 ), AsList, List( CapFixpoint( function ( coeq_old_2, coeq_2 )
946+
return Length( coeq_2[1] ) = deduped_4_1;
947+
end, function ( coeq_2 )
948+
local deduped_2_2, deduped_3_2, deduped_4_2, deduped_5_2;
949+
deduped_5_2 := coeq_2[1];
950+
deduped_4_2 := SafeFirst( [ coeq_2[2] + 1 .. hoisted_2_1 ], function ( y_3 )
951+
return not y_3 in deduped_5_2;
952+
end );
953+
deduped_3_2 := CapFixpoint( function ( eq_class_old_3, eq_class_3 )
954+
return Length( eq_class_old_3[1] ) = Length( eq_class_3[1] );
955+
end, function ( eq_class_3 )
956+
local deduped_3_3, deduped_4_3, deduped_5_3, deduped_6_3;
957+
deduped_6_3 := eq_class_3[2];
958+
deduped_5_3 := eq_class_3[1];
959+
deduped_4_3 := [ 1 .. Length( deduped_6_3 ) ];
960+
deduped_3_3 := PositionsProperty( deduped_4_3, function ( j_4 )
961+
return Length( Intersection( deduped_5_3, deduped_6_3[j_4] ) ) > 0;
962+
end );
963+
return NTuple( 2, SSortedList( Concatenation( deduped_5_3, Concatenation( deduped_6_3{deduped_3_3} ) ) ), deduped_6_3{Difference( deduped_4_3, deduped_3_3 )} );
964+
end, NTuple( 2, [ deduped_4_2 ], coeq_2[3] ) );
965+
deduped_2_2 := deduped_3_2[1];
966+
return NTuple( 4, SSortedList( Concatenation( deduped_5_2, deduped_2_2 ) ), deduped_4_2, deduped_3_2[2], Concatenation( coeq_2[4], [ deduped_2_2 ] ) );
967+
end, NTuple( 4, deduped_5_1, -1, List( [ 0 .. CAP_JIT_INCOMPLETE_LOGIC( Length( AsList( CAP_JIT_INCOMPLETE_LOGIC( morphisms_1[1] ) ) ) ) - 1 ], function ( x_2 )
968+
local hoisted_1_2;
969+
hoisted_1_2 := 1 + x_2;
970+
return SSortedList( List( morphisms_1, function ( logic_new_func_x_3 )
971+
return AsList( logic_new_func_x_3 )[hoisted_1_2];
972+
end ) );
973+
end ), deduped_5_1 ) )[4], function ( x_2 )
974+
return hoisted_3_1[1 + x_2[1]];
881975
end ) );
882976
end
883977
########

0 commit comments

Comments
 (0)