Home > matgraph > @permutation > sign.m

sign

PURPOSE ^

sign of a permutation (1 for even, -1 for odd)

SYNOPSIS ^

function s = sign(p)

DESCRIPTION ^

 sign of a permutation (1 for even, -1 for odd)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function s = sign(p)
0002 % sign of a permutation (1 for even, -1 for odd)
0003 n = length(p);
0004 if (n==0)
0005     s = 1;
0006     return
0007 end
0008 
0009 c = cycles(p);
0010 s = 0;
0011 for k=1:length(c)
0012     s = s + length(c{k}) + 1;
0013 end
0014 
0015 s = mod(s,2);
0016 s = (-1)^s;

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003