Mike,
This might be not so efficient, as it would involve a call to GAP,
etc...
One can instead just count (mod 2) the number of swaps the bubble sort
does to
sort your permutation in increasing order
def sig(p):
a = list(p)
ctr = 1
la = len(a) - 1
while True:
done = True
i = 0
while i < la:
if a[i]>a[i+1]:
a[i+1],a[i] = a[i],a[i+1]
ctr = -ctr
done = False
break
i += 1
if done:
return ctr
sage: sig([4, 3, 5, 1, 2])
-1
PS. needless to say, rewriting this in Cython would speed things up
even more.
HTH,
Dmitrii
On Feb 12, 9:14 pm, Dox <[email protected]> wrote:
> Thank you Mike! :-)
--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org