Skip to content

Commit

Permalink
Allow function-call syntax for general mappings. (#3901)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevelinton authored Mar 2, 2020
1 parent 9f22a72 commit b068bb1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/mapping.gd
Original file line number Diff line number Diff line change
Expand Up @@ -882,21 +882,27 @@ DeclareOperation( "ImageElm", [ IsMapping, IsObject ] );
## <A>elm</A> of the source of the mapping <A>map</A> under <A>map</A>,
## i.e., the unique element of the range to which <A>map</A> maps
## <A>elm</A>.
## This can also be expressed as <A>elm</A><C>^</C><A>map</A>.
## This can also be expressed as <A>elm</A><C>^</C><A>map</A> or as
## Note that <A>map</A> must be total and single valued,
## a multi valued general mapping is not allowed
## (see&nbsp;<Ref Func="Images" Label="set of images of the source of a general mapping"/>).
## <P/>
## <C>Image( <A>map</A>, <A>coll</A> )</C> is the image of the subset
## <A>coll</A> of the source of the mapping <A>map</A> under <A>map</A>,
## i.e., the subset of the range to which <A>map</A> maps elements of
## <A>coll</A>.
## <A>coll</A>. <P/>
## <A>coll</A> may be a proper set or a domain.
## The result will be either a proper set or a domain.
## Note that in this case <A>map</A> may also be multi-valued.
## (If <A>coll</A> and the result are lists then the positions of
## entries do in general <E>not</E> correspond.)
## <P/>
## <C>Image( <A>map</A>, <A>coll</A> )</C> can also be expressed as <C><A>map</A>(<A>coll</A>)</C> and
## <C>Image( <A>map</A>, <A>elm</A> )</C> as <C><A>map</A>(<A>elm</A>)</C>.
## Those using this notation should remember that composition of mappings in &GAP;
## still follows the conventions appropriate for mapping acting from the right, so that
## <C>(<A>map1</A>*<A>map2</A>)(<A>x</A>)</C> is equivalent to
## <C><A>map2</A>(<A>map1</A>(<A>x</A>))</C> <P/>
## <Ref Func="Image" Label="set of images of the source of a general mapping"/>
## delegates to <Ref Attr="ImagesSource"/> when called
## with one argument, and to <Ref Oper="ImageElm"/> resp.
Expand Down
15 changes: 15 additions & 0 deletions lib/mapping.gi
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ InstallGlobalFunction( Image, function ( arg )
"Image(<map>,<coll>)" );
end );

#############################################################################
##
#M <map>(<elm>)
#M <map>(<coll>)
##
## Method to alow mappings to be used like functions when appropriate

InstallMethod(CallFuncList, [IsGeneralMapping, IsList],
function(map, lst)
if Length(lst) <> 1 then
TryNextMethod();
fi;
return Image(map, lst[1]);
end);


#############################################################################
##
Expand Down
16 changes: 16 additions & 0 deletions tst/testinstall/mapping.tst
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,14 @@ gap> IsTotal( map );
true
gap> Image( map, Z(3) );
0*Z(3)
gap> map(Z(3));
0*Z(3)
gap> ImageElm( map, Z(3) );
0*Z(3)
gap> Image( map, [ Z(3) ] );
[ 0*Z(3) ]
gap> map( [ Z(3) ] );
[ 0*Z(3) ]
gap> ImagesElm( map, Z(3) );
[ 0*Z(3) ]
gap> ImagesSet( map, [ 0*Z(3), Z(3) ] );
Expand Down Expand Up @@ -346,6 +350,18 @@ Error, <elm> must be an element of Source(<map>)
gap> Image(map, [Z(3), Z(9)]);
Error, the collection <elm> must be contained in Source(<map>)
# Image in alternative syntax
gap> map(0*Z(3));
Error, <map> must be single-valued and total
gap> mapBijective(Z(5));
Error, the families of the element or collection <elm> and Source(<map>) don't\
match, maybe <elm> is not contained in Source(<map>) or is not a homogeneous \
list or collection
gap> mapBijective(Z(9));
Error, <elm> must be an element of Source(<map>)
gap> map([Z(3), Z(9)]);
Error, the collection <elm> must be contained in Source(<map>)

# Images
gap> Images(x -> x, 1);
Error, <map> must be a general mapping
Expand Down

0 comments on commit b068bb1

Please sign in to comment.