Skip to content

Commit

Permalink
Add Helpers (HPC-GAP version)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuspf committed Aug 18, 2017
1 parent 7a4e136 commit ae303d5
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 75 deletions.
72 changes: 72 additions & 0 deletions hpcgap/lib/filter.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
##
## Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
## (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
## Copyright (C) 2002 The GAP Group
##
## This software is licensed under the GPL 2 or later, please refer
## to the COPYRIGHT.md and LICENSE files for details.
##

#############################################################################
##
#V IdOfFilter
##
## <#GAPDoc Label="IdOfFilter">
## <ManSection>
## <Func Name="IdOfFilter" Arg="filter"/>
## <Func Name="IdOfFilterByName" Arg="name"/>
##
## <Description>
## finds the id of the filter <A>filter</A>, or the id of the filter
## with name <A>name</A> respectively.
## The id of a filter is equal to the
## position of this filter in the global FILTERS list.
## <P/>
## Note that not every <C>filter</C> for which <C>IsFilter(filter)</C>
## returns <C>true</C> has an ID, only elementary filters do.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
## Note that the filter ID is stored in FLAG1_FILTER for most filters,
## testers have the ID stored in FLAG2_FILTER, so the code below is
## more efficient than just iterating over the FILTERS list.
##
##
BIND_GLOBAL( "IdOfFilter",
function(filter)
local fid;
atomic readonly FILTER_REGION do
fid := FLAG1_FILTER(filter);
if fid > 0 and FILTERS[fid] = filter then
return fid;
fi;
fid := FLAG2_FILTER(filter);
if fid > 0 and FILTERS[fid] = filter then
return fid;
fi;
od;
return fail;
end);

BIND_GLOBAL( "IdOfFilterByName",
name -> PositionProperty(FILTERS, f -> NAME_FUNC(f) = name) );

#############################################################################
##
#V FilterByName
##
## <#GAPDoc Label="FilterByName">
## <ManSection>
## <Func Name="FilterByName" Arg="name"/>
##
## <Description>
## finds the filter with name <A>name</A> in the global FILTERS list. This
## is useful to find filters that were created but not bound to a global
## variable.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BIND_GLOBAL( "FilterByName",
name -> First(FILTERS, f -> NAME_FUNC(f) = name) );
75 changes: 0 additions & 75 deletions hpcgap/lib/function.g
Original file line number Diff line number Diff line change
Expand Up @@ -654,81 +654,6 @@ InstallMethod( ViewObj, "for a function", true, [IsFunction], 0,
Print(" ) ... end");
end);

BIND_GLOBAL( "VIEW_STRING_OPERATION", function ( op )
local class, flags, types, catok, repok, propok, seenprop,
t, res;
class := "Operation";
if IS_IDENTICAL_OBJ(op,IS_OBJECT) then
class := "Filter";
elif IS_CONSTRUCTOR(op) then
class := "Constructor";
elif IsFilter(op) then
class := "Filter";
flags := FLAGS_FILTER(op);
if flags <> false then
flags := TRUES_FLAGS(flags);
else
flags := [];
fi;
atomic readonly FILTER_REGION do
types := INFO_FILTERS{flags};
od;
catok := true;
repok := true;
propok := true;
seenprop := false;
for t in types do
if not t in FNUM_REPS then
repok := false;
fi;
if not t in FNUM_CATS then
catok := false;
fi;
if not t in FNUM_PROS and not t in FNUM_TPRS then
propok := false;
fi;
if t in FNUM_PROS then
seenprop := true;
fi;
od;
if seenprop and propok then
class := "Property";
elif catok then
class := "Category";
elif repok then
class := "Representation";
fi;
elif Tester(op) <> false then
# op is an attribute
class := "Attribute";
fi;

# Horrible.
res := "<";
APPEND_LIST(res, class);
APPEND_LIST(res, " \"");
APPEND_LIST(res, NAME_FUNC(op));
APPEND_LIST(res, "\">");
return res;
end);

BIND_GLOBAL( "PRINT_OPERATION",
function ( op )
Print(VIEW_STRING_OPERATION(op));
end);

InstallMethod( ViewObj,
"for an operation",
[ IsOperation ],
PRINT_OPERATION );

InstallMethod( ViewString,
"for an operation",
[ IsOperation ],
function(op)
return VIEW_STRING_OPERATION(op);
end);

#############################################################################
##
#E
1 change: 1 addition & 0 deletions hpcgap/lib/read1.g
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ReadLib( "permutat.g" );
ReadLib( "trans.g" );
ReadLib( "pperm.g" );

ReadLib( "filter.gi" );
ReadLib( "object.gi" );
ReadLib( "listcoef.gd" );
ReadLib( "info.gd" );
Expand Down
39 changes: 39 additions & 0 deletions hpcgap/tst/testinstall/type.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
gap> test := x -> List([IsFilter, IsCategory, IsRepresentation, IsAttribute, IsProperty, IsOperation], f -> f(x));;
gap> test(IsFinite);
[ true, false, false, false, true, true ]

#
gap> test(IsMagma);
[ true, true, false, false, false, true ]

#
gap> test(IsCommutative);
[ true, false, false, false, true, true ]

#
gap> test(Size);
[ false, false, false, true, false, true ]

#
gap> test(Group);
[ false, false, false, false, false, false ]

#
gap> test((1,2,3));
[ false, false, false, false, false, false ]

#
gap> test("hello, world");
[ false, false, false, false, false, false ]

#
gap> FilterByName("IsCommutative");
<Property "IsCommutative">
gap> CategoryByName("IsMagma");
<Category "IsMagma">

#
gap> f := function() atomic readonly FILTER_REGION do return ForAll([1..Length(FILTERS)], id -> id = IdOfFilter(FILTERS[id])); od; end;;
gap> f();
true

0 comments on commit ae303d5

Please sign in to comment.