#
#--> Rational();
# Creates the domain or rational numbers Q
# Author: MBM 1989
#

Rational := proc() local Q,Z; option remember;
	Q := OrderedSet( QuotientField( Integer() ) );
	Q[DomainName] := Rational;
	# Rep := Maple Rational
	Q[Type] := <type(x,rational)|x>;
	addProperty(Q,UniquelyRepresented);
	Q[Input] := proc(x) if type(x,rational) then x else FAIL fi end;
	Q[Output] := proc(x) x end;
	Q[Type] := <type(x,rational)|x>;
	Q[`=`] := `=`;
	Q[`<`] := `<`;
	Q[Min] := min;
	Q[Max] := max;
	Q[0] := 0;
	Q[`+`] := `+`;
	Q[`-`] := `-`;
	Q[1] := 1;
	Q[`*`] := `*`;
	Q[`^`] := `^`;
	Q[`/`] := `/`;
	Q[Inv] := <1/x>;
	Q[Coerce] := <x|x>;
	Q[Numer] := numer;
	Q[Denom] := denom;
	Q[Sign] := proc(x) if x = 0 then 0 else sign(x) fi end;
	Q[Slash] := Q[`/`];
	Q[ModularHomomorphism] := proc()
		proc(x) local i;
			i := traperror(modp(x,9973));
			if i = lasterror then FAIL else i fi
		    end, 9973
	    end;
	op(Q)
end:

save `Q.m`;
quit
