#
#--> Integer()
# Creates the domain of integers Z
# Author: MBM 1989
#
Integer := proc() local I; option remember;

	I := EuclideanDomain( OrderedDomain() );
	defOperations( {Abs}, I &-> I, I );
	defOperations( {Modp,Mods}, [I,I] &-> I, I );
	defOperation( Random, [] &-> I, I );
	defOperation( ModularHomomorphism, [] &-> [I &-> I,I], I );

	I[DomainName] := Integer;
	addProperties(I,{CannonicalForm,UniquelyRepresented});

	# Rep := Maple integer
	I[Type] := <type(x,integer)|x>;
	I[Characteristic] := 0;
	I[`=`] := <evalb(x=y)>;
	I[`<>`] := <evalb(x<>y)>;
	I[`<=`] := <evalb(x<=y)>;
	I[`<`] := <evalb(x<y)|x,y>;
	I[Min] := min;
	I[Max] := max;
	I[0] := 0;
	I[1] := 1;
	I[`+`] := `+`;
	I[`-`] := `-`;
	I[`*`] := `*`;
	I[`^`] := `^`;
	I[Rem] := irem;
	I[Quo] := iquo;
	I[Gcd] := igcd;
	I[Prime] := proc(n) isprime(n) end;
	I[Gcdex] := igcdex;
	I[Factor] := proc(x) readlib(ifactors)(x) end;
	I[Sqrfree] := proc(x) readlib(isqrfree)(x) end:
	I[Inv] := proc(x) if x = 1 or x = -1 then x else FAIL fi end;
	I[EuclideanNorm] := abs;
	I[Unit] := sign;
	I[Normal] := abs;
	I[UnitNormal] := proc(x) local s; s := sign(x); [s,s*x,s] end;
	I[Input] := proc(x) if type(x,integer) then x else FAIL fi end;
	I[Abs] := abs;
	I[Sign] := proc(x) if x = 0 then 0 else sign(x) fi end;
	I[Zero] := proc(x) evalb(x = 0) end;
	I[Modp] := modp;
	I[Mods] := mods;
	I[Random] := rand(-99..99);
	I[ModularHomomorphism] := proc() <modp(x,9973)>, 9973 end;
	op(I)

end:

save `Z.m`;
quit
