Using the procedure permsPosNeg as given in the blog entry Positive and negative permutations, including the improvement obtained in the blog entry Refactoring Maple code, consider the following procedure:

addPermIndex := proc(
   indexName::string,posPerms::'set'(list),negPerms::'set'(list)
)
   local perms,ranks;
   perms := posPerms union negPerms;
   ranks := map(nops,perms);
   # Checking input
   if perms = {} or perms = {[]} then error
      "No permutations are provided"
   end if;
   if nops(ranks) > 1 then error
      "The permutations differ in rank"
   end if;
   if map(convert,perms,set)[] <> {$1..ranks[]} then error
      "A permutation must contain all integers from 1 to %1",ranks[]
   end if;
   # Creating indexing function
   assign(
      cat(`index/`,indexName),
      proc(ind::list,comps::Array,entry::list)
         local i,posInds,negInds;
         if nargs = 2 then comps[ind[]]
         else
            posInds,negInds := permsPosNeg(ind,posPerms,negPerms);
            if posInds intersect negInds <> {} and entry[] <> 0 then
               error "The entry cannot be nonzero"
            end if;
            for i in posInds do comps[i[]] := +entry[] end do;
            for i in negInds do comps[i[]] := -entry[] end do;
         end if
      end proc
   )
end proc:

It can be used to create an indexing function for an Array with arbitrary symmetries (positive permutations) and antisymmetries (negative permutations). A prominent example is the Riemann curvature tensor:

addPermIndex("riemann",{[3,4,1,2]},{[2,1,3,4],[1,2,4,3]}):
Riemann := Array(riemann,(1..4)$4):
Riemann[1,2,3,4] := 10:
Riemann[3,4,1,2],
Riemann[2,1,3,4],
Riemann[1,2,4,3];
                          10, -10, -10

Please feel free to suggest any improvements.


Please Wait...