#
#--> D :=  Maple(t)
#
# Creates a domain of Maple expressions of type t which will be treated
# as a field.  This allows Gauss to package up Maple computation with
# expressions into a domain.
#
# The operations
#
# D[Normalizer] can be assigned a normal function (default normal)
# D[ZeroTest] can be assigned a zero equivalence test (default testeq)
#
# Author: MBM 1991
#
Maple := proc(t) local C,env; option remember;

    # Rep := Maple Expression Tree
    env := ['D' = C, 'T' = t ];

    C := Field();
    C[DomainName] := Maple;
    C[Characteristic] := 0;
    C[Random] := proc() 1 end;

    defOperation( ZeroTest, C &-> Boolean, C );
    C[ZeroTest] := testeq;

    defOperation( Normalizer, C &-> C, C );
    C[Normalizer] := normal;

    C[Type] := subs(env, proc() type(args[1],T) end);
    C[Input] := subs( env, proc(x)
	    if not D[Type](x) then RETURN(FAIL) fi;
	    if D[ZeroTest](x) then 0 else D[Normalizer](x) fi
	end );

    C[0] := 0;
    C[1] := 1;
    C[`+`] := subs(env, proc() D[Input]( `+`(args) ) end);
    C[`*`] := subs(env, proc() D[Normalizer]( `*`(args) ) end);
    C[Inv] := subs(env, proc(x) D[Normalizer]( 1/x ) end);
    op(C)

end:

save `Maple.m`;
quit
