#
#--> PrimeExponentVector(x:list(name))
#
# Prime exponent vector representation -- list(prime powers)
# Author MBM: 1989
#
PrimeExponentVector := proc(x) local P,i,f,n,env; option remember;

	P := ExponentVector(x);
	P[DomainName] := PrimeExponentVector;
	n := nops(x);

	# Rep := integer of the form 2^e[1] 3^e[2] ... p[n]^e[n]
	f := [seq(ithprime(i),i=1..n)];
	env := ['D' = P, 'F'=f, 'N'=n];
	P[List2Vect] := subs(env, proc(x) local i;
		convert([seq(F[i]^x[i], i=1..N)],`*`)
	    end);
	P[Vect2List] := subs(env, proc() local i,j,l,n,p,q;
		n := args[1];
		l := NULL;
		for i to N do
		    p := F[i];
		    for j from 0 while irem(n,p,'q') = 0 do n := q od;
		    l := l,j;
		od;
		[ l ]
	    end);

	P[0] := 1;
	P[`+`] := `*`;
	P[`-`] := iquo;
	P[Div] := proc(a,b) local q;
	    if irem(a,b,q) > 0 then FAIL else q fi
	end;
	P[Degree] := subs(env, proc(a,n) local b,d,p;
	    p := F[n];
	    b := a;
	    for d from 0 while irem(b,p,'b') = 0 do od;
	    d
	end);
	P[Gcd] := igcd:
	P[Lcm] := ilcm:
	P[`=`] := `=`;
	P[`<>=`] := proc(a,b) if a = b then 0 elif a < b then -1 else 1 fi end;
	P[Type] := proc(n) type(n,nonnegint) end;
	op(P)
end:

save `Prime.m`;
quit
