Skip to content

Commit 6117be5

Browse files
functional
1 parent 1a70ab7 commit 6117be5

13 files changed

+2088
-289
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#! @Chapter Precompilation
2+
3+
#! @Section Precompiling the category of skeletal finite sets
4+
5+
#! @Example
6+
7+
#! #@if ValueOption( "no_precompiled_code" ) <> true
8+
9+
LoadPackage( "FinSetsForCAP", false );
10+
#! true
11+
LoadPackage( "CompilerForCAP", false );
12+
#! true
13+
14+
ReadPackageOnce( "FinSetsForCAP", "gap/CompilerLogic.gi" );
15+
#! true
16+
17+
category_constructor :=
18+
{} -> CategoryOfSkeletalFinSetsWithMorphismsGivenByFunctions( );;
19+
given_arguments := [ ];;
20+
compiled_category_name :=
21+
"CategoryOfSkeletalFinSetsWithMorphismsGivenByFunctionsPrecompiled";;
22+
package_name := "FinSetsForCAP";;
23+
primitive_operations :=
24+
ListPrimitivelyInstalledOperationsOfCategory(
25+
category_constructor( : no_precompiled_code := true ) );;
26+
list_of_operations :=
27+
SortedList( Concatenation( primitive_operations, [
28+
#"HasPushoutComplement",
29+
"PushoutComplement",
30+
] ) );;
31+
32+
CapJitPrecompileCategoryAndCompareResult(
33+
category_constructor,
34+
given_arguments,
35+
package_name,
36+
compiled_category_name
37+
: operations := list_of_operations,
38+
number_of_objectified_objects_in_data_structure_of_object := 1,
39+
number_of_objectified_morphisms_in_data_structure_of_object := 0,
40+
number_of_objectified_objects_in_data_structure_of_morphism := 2,
41+
number_of_objectified_morphisms_in_data_structure_of_morphism := 1
42+
);;
43+
44+
CategoryOfSkeletalFinSetsWithMorphismsGivenByFunctionsPrecompiled( );
45+
#! SkeletalFinSets
46+
47+
cat := CategoryOfSkeletalFinSetsWithMorphismsGivenByFunctions( );
48+
#! SkeletalFinSets
49+
50+
cat!.precompiled_functions_added;
51+
#! true
52+
53+
#! #@fi
54+
55+
#! @EndExample

examples/PrecompileCategoryOfSkeletalFinSetsWithMorphismsGivenByLists.g

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ LoadPackage( "FinSetsForCAP", false );
1111
LoadPackage( "CompilerForCAP", false );
1212
#! true
1313

14-
ReadPackage( "FinSetsForCAP", "gap/CompilerLogic.gi" );
14+
ReadPackageOnce( "FinSetsForCAP", "gap/CompilerLogic.gi" );
1515
#! true
1616

17-
category_constructor := {} -> CategoryOfSkeletalFinSets( );;
17+
category_constructor :=
18+
{} -> CategoryOfSkeletalFinSetsWithMorphismsGivenByLists( );;
1819
given_arguments := [ ];;
1920
compiled_category_name :=
2021
"CategoryOfSkeletalFinSetsWithMorphismsGivenByListsPrecompiled";;
@@ -43,7 +44,7 @@ CapJitPrecompileCategoryAndCompareResult(
4344
CategoryOfSkeletalFinSetsWithMorphismsGivenByListsPrecompiled( );
4445
#! SkeletalFinSets
4546

46-
cat := CategoryOfSkeletalFinSets( );
47+
cat := CategoryOfSkeletalFinSetsWithMorphismsGivenByLists( );
4748
#! SkeletalFinSets
4849

4950
cat!.precompiled_functions_added;

examples/SkeletalWellDefined.g

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ s := FinSet( 7 );
77
#! |7|
88
t := FinSet( 4 );
99
#! |4|
10-
psi := MapOfFinSets( s, [ 0, 2, 1, 2, 1, 3 ], t );
11-
#! |7| → |4|
12-
IsWellDefined( psi );
13-
#! false
1410
psi := MapOfFinSets( s, [ 0, 2, 1, 2, 1, 3, -2 ], t );
1511
#! |7| → |4|
1612
IsWellDefined( psi );

gap/CompilerLogic.gi

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,51 @@ CapJitAddLogicFunction( function ( tree )
116116

117117
end );
118118

119+
## [ entry1, ... ]{[ ]} => [ ]
120+
CapJitAddLogicFunction( function ( tree )
121+
local pre_func;
122+
123+
Info( InfoCapJit, 1, "####" );
124+
Info( InfoCapJit, 1, "Apply logic for extracting the empty sublist of a given list" );
125+
126+
pre_func :=
127+
function ( tree, additional_arguments )
128+
local args, is_big_int, values;
129+
130+
if CapJitIsCallToGlobalFunction( tree, "{}" ) then
131+
132+
args := tree.args;
133+
134+
if args.2.type = "EXPR_LIST" and args.2.list.length = 0 then
135+
136+
if IsBound( args.1.list ) and IsBound( args.1.list.1 ) then
137+
138+
if IsBound( args.1.list.1.data_type ) then
139+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := args.1.list.1.data_type );
140+
elif IsBound( args.1.list.1.funcref ) and IsBound( args.1.list.1.funcref.data_type ) then
141+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := args.1.list.1.funcref.data_type.signature[2] );
142+
elif IsBound( args.1.list.1.funcref ) and CapJitIsCallToGlobalFunction( args.1.list.1, "Length" ) then
143+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := rec( filter := IsInt ) );
144+
fi;
145+
146+
elif CapJitIsCallToGlobalFunction( args.1, "ListWithIdenticalEntries" ) then
147+
148+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := args.1.args.2.funcref.data_type.signature[2] );
149+
150+
fi;
151+
152+
fi;
153+
154+
fi;
155+
156+
return tree;
157+
158+
end;
159+
160+
return CapJitIterateOverTree( tree, pre_func, CapJitResultFuncCombineChildren, ReturnTrue, true );
161+
162+
end );
163+
119164
## Product( [ ] ) => BigInt( 1 ) and Product( [ ], func ) => BigInt( 1 )
120165
CapJitAddLogicFunction( function ( tree )
121166
local pre_func;
@@ -171,6 +216,15 @@ CapJitAddTypeSignature( "List", [ IsObjectInCategoryOfSkeletalFinSets, IsFunctio
171216

172217
end );
173218

219+
##
220+
CapJitAddLogicTemplate(
221+
rec(
222+
variable_names := [ "list" ],
223+
src_template := "List( list, ID_FUNC )",
224+
dst_template := "list",
225+
)
226+
);
227+
174228
##
175229
CapJitAddLogicTemplate(
176230
rec(
@@ -326,6 +380,15 @@ CapJitAddLogicTemplate(
326380
)
327381
);
328382

383+
CapJitAddLogicTemplate(
384+
rec(
385+
variable_names := [ "number1", "number2" ],
386+
variable_filters := [ IsBigInt, IsBigInt ],
387+
src_template := "REM_INT( REM_INT( number1, number2 ), number2 )",
388+
dst_template := "REM_INT( number1, number2 )",
389+
)
390+
);
391+
329392
CapJitAddLogicTemplate(
330393
rec(
331394
variable_names := [ "list" ],
@@ -382,6 +445,14 @@ CapJitAddLogicTemplate(
382445
)
383446
);
384447

448+
CapJitAddLogicTemplate(
449+
rec(
450+
variable_names := [ "entry" ],
451+
src_template := "ListWithIdenticalEntries( BigInt( 1 ), entry )",
452+
dst_template := "[ entry ]",
453+
)
454+
);
455+
385456
CapJitAddLogicTemplate(
386457
rec(
387458
variable_names := [ "length", "constant", "pos" ],
@@ -467,3 +538,56 @@ CapJitAddLogicTemplate(
467538
dst_template := "entry in list",
468539
)
469540
);
541+
542+
CapJitAddLogicTemplate(
543+
rec(
544+
variable_names := [ "map" ],
545+
variable_filters := [ IsMorphismInCategoryOfSkeletalFinSets ],
546+
src_template := "List( [ 0 .. Length( Source( map ) ) - 1 ], i -> AsList( map )[1 + i] )",
547+
dst_template := "AsList( map )",
548+
)
549+
);
550+
551+
CapJitAddLogicTemplate(
552+
rec(
553+
variable_names := [ "map" ],
554+
variable_filters := [ IsMorphismInCategoryOfSkeletalFinSets ],
555+
src_template := "AsList( map ){[ 1 .. Length( Source( map ) ) ]}",
556+
dst_template := "AsList( map )",
557+
)
558+
);
559+
560+
CapJitAddLogicTemplate(
561+
rec(
562+
variable_names := [ "list", "number" ],
563+
variable_filters := [ IsList, IsBigInt ],
564+
src_template := "List( [ 0 .. number - 1 ], i -> list[1 + i] )",
565+
dst_template := "list{[ 1 .. number ]}",
566+
)
567+
);
568+
569+
CapJitAddLogicTemplate(
570+
rec(
571+
variable_names := [ "length", "offset" ],
572+
variable_filters := [ IsBigInt, IsBigInt ],
573+
src_template := "List( [ 0 .. length - 1 ], i -> offset + i )",
574+
dst_template := "[ offset .. offset + length - 1 ]",
575+
)
576+
);
577+
578+
CapJitAddLogicTemplate(
579+
rec(
580+
variable_names := [ "length" ],
581+
variable_filters := [ IsBigInt ],
582+
src_template := "Length( [ 0 .. length - 1 ] )",
583+
dst_template := "length",
584+
)
585+
);
586+
587+
CapJitAddLogicTemplate(
588+
rec(
589+
variable_names := [ "list", "index", "x" ],
590+
src_template := "List( list, map -> ( i -> AsList( map )[1 + i] ) )[index]( x )",
591+
dst_template := "List( list, AsList )[index][1 + x]",
592+
)
593+
);

gap/SkeletalFinSets.gd

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ DeclareCategory( "IsObjectInCategoryOfSkeletalFinSets",
2929
DeclareCategory( "IsMorphismInCategoryOfSkeletalFinSets",
3030
IsCapCategoryMorphism );
3131

32+
#! @Description
33+
#! The GAP category of categories
34+
#! of skeletal finite sets with morphisms given by functions.
35+
#! @Arguments object
36+
DeclareCategory( "IsCategoryOfSkeletalFinSetsWithMorphismsGivenByFunctions",
37+
IsCategoryOfSkeletalFinSets );
38+
39+
#! @Description
40+
#! The GAP category of objects in the category
41+
#! of skeletal finite sets with morphisms given by functions.
42+
#! @Arguments object
43+
DeclareCategory( "IsObjectInCategoryOfSkeletalFinSetsWithMorphismsGivenByFunctions",
44+
IsObjectInCategoryOfSkeletalFinSets );
45+
46+
#! @Description
47+
#! The GAP category of morphisms in the category
48+
#! of skeletal finite sets with morphisms given by functions.
49+
#! @Arguments object
50+
DeclareCategory( "IsMorphismInCategoryOfSkeletalFinSetsWithMorphismsGivenByFunctions",
51+
IsMorphismInCategoryOfSkeletalFinSets );
52+
3253
#! @Section Attributes
3354

3455
#! @Description
@@ -52,13 +73,23 @@ DeclareAttribute( "AsList",
5273
CapJitAddTypeSignature( "AsList", [ IsObjectInCategoryOfSkeletalFinSets ], rec( filter := IsList, element_type := rec( filter := IsBigInt ) ) );
5374

5475
#! @Description
55-
#! The graph defining the skeletal finite set morphism <A>phi</A>, see <Ref Oper="MapOfFinSets" Label="for IsObjectInCategoryOfSkeletalFinSets, IsList, IsObjectInCategoryOfSkeletalFinSets" />.
76+
#! The function defining the skeletal finite set morphism <A>phi</A>, see <Ref Oper="MapOfFinSets" Label="for IsObjectInCategoryOfSkeletalFinSets, IsFunction, IsObjectInCategoryOfSkeletalFinSets" />.
5677
#! @Arguments phi
57-
#! @Returns a list
58-
DeclareAttribute( "AsList",
78+
#! @Returns a function
79+
DeclareAttribute( "AsFunc",
5980
IsMorphismInCategoryOfSkeletalFinSets );
6081

61-
CapJitAddTypeSignature( "AsList", [ IsMorphismInCategoryOfSkeletalFinSets ], rec( filter := IsList, element_type := rec( filter := IsBigInt ) ) );
82+
BindGlobal( "SkeletalFinSets_func_type",
83+
rec( filter := IsFunction, signature := [ [ rec( filter := IsBigInt ) ], rec( filter := IsBigInt ) ] ) );
84+
85+
CapJitAddTypeSignature( "AsFunc", [ IsMorphismInCategoryOfSkeletalFinSets ], SkeletalFinSets_func_type );
86+
87+
#! @Description
88+
#! The list of images defining the skeletal finite set morphism <A>phi</A>, see <Ref Oper="MapOfFinSets" Label="for IsObjectInCategoryOfSkeletalFinSets, IsFunction, IsObjectInCategoryOfSkeletalFinSets" />.
89+
#! @Arguments phi
90+
#! @Returns a list
91+
DeclareAttribute( "ListOfImages",
92+
IsMorphismInCategoryOfSkeletalFinSets );
6293

6394
#! @Section Constructors
6495

@@ -72,6 +103,16 @@ DeclareOperation( "CategoryOfSkeletalFinSets", [ ] );
72103
#! It is automatically created while loading this package.
73104
DeclareGlobalName( "SkeletalFinSets" );
74105

106+
#! @Description
107+
#! Construct a category of skeletal finite sets with maps given by functions.
108+
#! @Returns a &CAP; category
109+
DeclareOperation( "CategoryOfSkeletalFinSetsWithMorphismsGivenByFunctions", [ ] );
110+
111+
#! @Description
112+
#! The default instance of the category of skeletal finite sets given by functions.
113+
#! It is automatically created while loading this package.
114+
DeclareGlobalName( "SkeletalFinSetsWithMorphismsGivenByFunctions" );
115+
75116
#! @Description
76117
#! Construct a skeletal finite set residing in
77118
#! the default instance of the category of skeletal finite sets <C>SkeletalFinSets</C>
@@ -92,13 +133,12 @@ KeyDependentOperation( "FinSet", IsCategoryOfSkeletalFinSets, IsBigInt, ReturnTr
92133

93134
#! @Description
94135
#! Construct a map $\phi:$<A>s</A>$\to$<A>t</A> of the skeletal finite sets <A>s</A> and <A>t</A>,
95-
#! i.e., a morphism in the &CAP; category of <A>s</A>, where <A>G</A>
96-
#! is a list of integers in <A>t</A> describing the graph of $\phi$.
97-
#! @Arguments s, G, t
136+
#! i.e., a morphism in the &CAP; category of <A>s</A>, where <A>f</A>
137+
#! is a function with values in <A>t</A> describing the graph of $\phi$.
138+
#! @Arguments s, f, t
98139
#! @Returns a &CAP; morphism
99140
DeclareOperation( "MapOfFinSets",
100-
[ IsObjectInCategoryOfSkeletalFinSets, IsList, IsObjectInCategoryOfSkeletalFinSets ] );
101-
#! @InsertChunk SkeletalMapOfFinSets
141+
[ IsObjectInCategoryOfSkeletalFinSets, IsFunction, IsObjectInCategoryOfSkeletalFinSets ] );
102142

103143
#! @Section Tools
104144

0 commit comments

Comments
 (0)