Skip to content

Commit 4677907

Browse files
functional
1 parent b3159d0 commit 4677907

13 files changed

+2074
-287
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: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,43 @@ 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 and IsBound( args.1.list.1 ) then
135+
136+
if IsBound( args.1.list.1.data_type ) then
137+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := args.1.list.1.data_type );
138+
elif IsBound( args.1.list.1.funcref ) and IsBound( args.1.list.1.funcref.data_type ) then
139+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := args.1.list.1.funcref.data_type.signature[2] );
140+
elif IsBound( args.1.list.1.funcref ) and CapJitIsCallToGlobalFunction( args.1.list.1, "Length" ) then
141+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := rec( filter := IsInt ) );
142+
fi;
143+
144+
fi;
145+
146+
fi;
147+
148+
return tree;
149+
150+
end;
151+
152+
return CapJitIterateOverTree( tree, pre_func, CapJitResultFuncCombineChildren, ReturnTrue, true );
153+
154+
end );
155+
119156
## Product( [ ] ) => BigInt( 1 ) and Product( [ ], func ) => BigInt( 1 )
120157
CapJitAddLogicFunction( function ( tree )
121158
local pre_func;
@@ -171,6 +208,15 @@ CapJitAddTypeSignature( "List", [ IsObjectInCategoryOfSkeletalFinSets, IsFunctio
171208

172209
end );
173210

211+
##
212+
CapJitAddLogicTemplate(
213+
rec(
214+
variable_names := [ "list" ],
215+
src_template := "List( list, ID_FUNC )",
216+
dst_template := "list",
217+
)
218+
);
219+
174220
##
175221
CapJitAddLogicTemplate(
176222
rec(
@@ -326,6 +372,15 @@ CapJitAddLogicTemplate(
326372
)
327373
);
328374

375+
CapJitAddLogicTemplate(
376+
rec(
377+
variable_names := [ "number1", "number2" ],
378+
variable_filters := [ IsBigInt, IsBigInt ],
379+
src_template := "REM_INT( REM_INT( number1, number2 ), number2 )",
380+
dst_template := "REM_INT( number1, number2 )",
381+
)
382+
);
383+
329384
CapJitAddLogicTemplate(
330385
rec(
331386
variable_names := [ "list" ],
@@ -382,6 +437,14 @@ CapJitAddLogicTemplate(
382437
)
383438
);
384439

440+
CapJitAddLogicTemplate(
441+
rec(
442+
variable_names := [ "entry" ],
443+
src_template := "ListWithIdenticalEntries( BigInt( 1 ), entry )",
444+
dst_template := "[ entry ]",
445+
)
446+
);
447+
385448
CapJitAddLogicTemplate(
386449
rec(
387450
variable_names := [ "length", "constant", "pos" ],
@@ -467,3 +530,56 @@ CapJitAddLogicTemplate(
467530
dst_template := "entry in list",
468531
)
469532
);
533+
534+
CapJitAddLogicTemplate(
535+
rec(
536+
variable_names := [ "map" ],
537+
variable_filters := [ IsMorphismInCategoryOfSkeletalFinSets ],
538+
src_template := "List( [ 0 .. Length( Source( map ) ) - 1 ], i -> AsList( map )[1 + i] )",
539+
dst_template := "AsList( map )",
540+
)
541+
);
542+
543+
CapJitAddLogicTemplate(
544+
rec(
545+
variable_names := [ "map" ],
546+
variable_filters := [ IsMorphismInCategoryOfSkeletalFinSets ],
547+
src_template := "AsList( map ){[ 1 .. Length( Source( map ) ) ]}",
548+
dst_template := "AsList( map )",
549+
)
550+
);
551+
552+
CapJitAddLogicTemplate(
553+
rec(
554+
variable_names := [ "list", "number" ],
555+
variable_filters := [ IsList, IsBigInt ],
556+
src_template := "List( [ 0 .. number - 1 ], i -> list[1 + i] )",
557+
dst_template := "list{[ 1 .. number ]}",
558+
)
559+
);
560+
561+
CapJitAddLogicTemplate(
562+
rec(
563+
variable_names := [ "length", "offset" ],
564+
variable_filters := [ IsBigInt, IsBigInt ],
565+
src_template := "List( [ 0 .. length - 1 ], i -> offset + i )",
566+
dst_template := "[ offset .. offset + length - 1 ]",
567+
)
568+
);
569+
570+
CapJitAddLogicTemplate(
571+
rec(
572+
variable_names := [ "length" ],
573+
variable_filters := [ IsBigInt ],
574+
src_template := "Length( [ 0 .. length - 1 ] )",
575+
dst_template := "length",
576+
)
577+
);
578+
579+
CapJitAddLogicTemplate(
580+
rec(
581+
variable_names := [ "list", "index", "x" ],
582+
src_template := "List( list, map -> ( i -> AsList( map )[1 + i] ) )[index]( x )",
583+
dst_template := "List( list, AsList )[index][1 + x]",
584+
)
585+
);

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)