In connection with tensors, I would like to be able to treat arbitrary symmetries (positive permutations) and antisymmetries (negative permutations) of the entries of an Array.

An example is the Riemannian curvature tensor which has the following positive and negative permutations:

pPerms := {[3,4,1,2]};
nPerms := {[2,1,3,4],[1,2,4,3]};

In order to create an indexing function which, among other things, must determine whether or not an entry [a,b,c,d] can be assigned some (nonzero) number, it seems necessary first to figure out what are the positive and negative permutations of [a,b,c,d]. For that purpose I have come up with the following procedure (which is valid for any rank of the tensor, and any sets of symmetries and antisymmetries):

permsPosNeg := proc(
	ind::list,posPerms::'set'(list),negPerms::'set'(list)
)
	local perms,posMaps,negMaps,posInds,negInds,posInds_,negInds_;
	posMaps,negMaps := seq(map((perm::list) ->
		(x::list) -> [seq(op(perm[i],x),i=1..nops(perm))]
	,perms),perms in [posPerms,negPerms]);
	posInds ,negInds  := {ind},{};
	posInds_,negInds_ := {}   ,{};
	while (posInds <> posInds_) or (negInds <> negInds_) do
		posInds_ := posInds;
		negInds_ := negInds;
		posInds := posInds
			union map(posMaps,posInds)[]
			union map(negMaps,negInds)[];
		negInds := negInds
			union map(posMaps,negInds)[]
			union map(negMaps,posInds)[];
	end do;
	posInds,negInds
end proc:

which is used as in the following two examples:

  • An assignable entry, because p and n has empty intersection:
    p,n := permsPosNeg([1,2,3,4],pPerms,nPerms);
    p intersect n;
    
  • A non-assignable entry (in the sense that only 0 may be assigned), because p and n has nonempty intersection:
    p,n := permsPosNeg([1,1,3,4],pPerms,nPerms);
    p intersect n;
    

My question, at long last, is: can permsPosNeg be improved upon, or is there some altogether different method that is better?


Please Wait...