sympy/sympy — pull request #1326 by pernici (2012-06-02 10:55:13+00:00)
Title: Portugal algorithm for tensors canonicalization

Implemented the Butler-Portugal algorithm for the canonicalization
of tensors with dummy indices.

For instance the tensor `T(d2,-d2,d1,-d1,a,b)` where `a,b` are free
indices, `d1,d2` are dummy indices (`-` stands for covariant)
is represented by `g = [4,5,2,3,0,1,6,7]`,
the last two indices referring to the sign, and
according to the ordering [a,b,d1,-d1,d2,-d2]

```
>>> from sympy.combinatorics.permutations import Permutation
>>> from sympy.combinatorics.perm_groups import PermutationGroup
>>> from sympy.combinatorics.perm_algorithms import canonicalization
>>> sgens = [Permutation(x) for x in [[2,1,0,3,4,5,7,6], [4,1,2,3,0,5,7,6]]]
>>> dummies = [2,3,4,5]
>>> g = [4,5,2,3,0,1,6,7]
>>> canonicalization(dummies, 0, sgens, g)
[0, 2, 3, 4, 5, 1, 6, 7]
```

so that the canonical form of the tensor is `T(a,d1,-d1,d2,-d2,b)`

This implementation is quite fast.