##############################################################################
##
#W  map2arg.gi                   XMOD Package                    Chris Wensley
##
##  Declaration file for functions of the XMOD package.
##
#H  @(#)$Id: map2arg.gi,v 2.007 2006/06/30 gap Exp $
## 
#Y  Copyright (C) 1999,2001 University of St. Andrews, North Haugh, 
#Y  St. Andrews, Fife KY16 9SS, Scotland
##
Revision.("xmod/gap/map2arg_gd") := 
   "@(#)$Id: map2arg.gi,v 2.007 2006/06/30 gap Exp $";

#############################################################################
##
#F  Mapping2ArgumentsByFunction( <D>, <E>, <fun> ) . create map from function
##
InstallGlobalFunction( Mapping2ArgumentsByFunction, function ( arg )
    local   map;        # mapping <map>, result

    if not ( Length( arg ) = 3 ) then
        # signal an error
        Error( "usage: Mapping2ArgumentsByFunction( <D>, <E>, <fun> )" );
    fi;
    # ensure that the entries in source and the range are domains
    if not ( IsList(arg[1]) and IsDomain(arg[1][1]) 
             and IsDomain(arg[1][2]) and IsDomain(arg[2]) ) then
	 Error("Mapping2ArgumentsByFunction: Source[1,2], Range not domains");
    fi;

    # make the general mapping
    map:= Objectify( TypeOfDefaultGeneralMapping( arg[1], arg[2],
                             IsNonSPMappingByFunctionRep
                         and IsSingleValued
                         and IsTotal ),
                       rec( fun:= arg[3] ) );
    SetIsMapping2ArgumentsByFunction( map, true );
    # deleted code re inverses

    return map;
end );

#############################################################################
##
#M  ImageElm( <map>, <elm> )  . . . . . . . . . . . . for mapping by function
##
InstallMethod( ImageElm, "for mapping by function", true, 
    [ IsMapping2ArgumentsByFunction, IsList ], 0,
    function ( map, elm )
    return map!.fun( elm );
    end );

#############################################################################
##
#E map2arg.gi ..................................................... ends here
