#
# DenseExponentVector(x:list(name), ordering:{plex,tdeg})
# Dense exponent vector representation -- Rep is Maple list(integer)
# Author MBM: 1989
#
DenseExponentVector := proc(x, ordering) local n,P,env; option remember;

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

	# Rep := vector(integer)
	P[0] := [0$n];
 	P[`+`] := subs( 'N' = n, proc(a,b) local i;
		[seq(a[i]+b[i], i=1..N)]
	    end);
	P[`-`] := subs( 'N' = n, proc(a,b) local i;
		[seq(a[i]-b[i], i=1..N)]
	    end);
	P[`=`] := `=`;
	
	if nargs = 1 or ordering = `tdeg` then
	    P[`<>=`] := proc(a,b) local i, m, n;
	        m := convert(a,`+`); n := convert(b, `+`);
	        if m < n then RETURN(-1) elif m > n then RETURN(1) fi;
	        for i to nops(a) while a[i] = b[i] do od;
	        if i > nops(a) then 0 elif a[i] < b[i] then -1 else 1 fi
	    end;
	elif ordering = `plex` then
	    P[`<>=`] := proc(a,b) local i;
	    	for i to nops(a) while a[i] = b[i] do od;
	    	if i > nops(a) then 0 elif a[i] < b[i] then -1 else 1 fi
	    end;
	elif ordering = `tdeginv` then
	    P[`<>=`] := proc(a,b) local i, m, n;
	        m := convert(a,`+`); n := convert(b, `+`);
	        if m < n then RETURN(-1) elif m > n then RETURN(1) fi;
	        for i from nops(a) by -1 to 1 while a[i] = b[i] do od;
	        if i = 0 then 0 elif a[i] < b[i] then 1 else -1 fi
	    end;
	else ERROR(`unknown ordering: `,ordering)
	fi;

	P[Type] := subs( 'N' = n, proc(x)
		type(x,list(nonnegint)) and nops(x) = N
	    end);
	P[List2Vect] := x -> x;
	P[Vect2List] := x -> x;

	op(P)
end:

save `Dense.m`;
quit
