Popular recipes tagged "determinants" but not "algebra"http://code.activestate.com/recipes/tags/determinants-algebra/2012-08-07T08:45:23-07:00ActiveState Code RecipesGenerate the parity or sign of a permutation (Python)
2012-07-28T07:21:49-07:00Paddy McCarthyhttp://code.activestate.com/recipes/users/398009/http://code.activestate.com/recipes/578227-generate-the-parity-or-sign-of-a-permutation/
<p style="color: grey">
Python
recipe 578227
by <a href="/recipes/users/398009/">Paddy McCarthy</a>
(<a href="/recipes/tags/determinants/">determinants</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/permutations/">permutations</a>).
</p>
<p>The <a href="http://en.wikipedia.org/wiki/Parity_of_a_permutation">parity</a> of a given permutation is whether an odd or even number of swaps between any two elements are needed to transform the given permutation to the first permutation.</p>
<p>The sign of the permutation is +1 for an even parity and -1 for an odd parity.</p>
<p>This python function returns the sign of a permutation of all the integers 0..N.
When the program is run it shows the sign of permutations as generated by the standard function itertools.permutations.</p>
<p>The function uses a modified <a href="http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort#Python">selection sort</a> to compute the parity.</p>
Alternatve generation of the parity or sign of a permutation (Python)
2012-08-07T08:45:23-07:00Paddy McCarthyhttp://code.activestate.com/recipes/users/398009/http://code.activestate.com/recipes/578236-alternatve-generation-of-the-parity-or-sign-of-a-p/
<p style="color: grey">
Python
recipe 578236
by <a href="/recipes/users/398009/">Paddy McCarthy</a>
(<a href="/recipes/tags/determinants/">determinants</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/permutations/">permutations</a>).
</p>
<p>Although <a href="http://code.activestate.com/recipes/578227/">Recipe 578227</a> was straight-forward to derive, I came across <a href="http://stackoverflow.com/questions/337664/counting-inversions-in-an-array/6424847#6424847">this Stack Overflow answer</a> that gives another method for generating the sign based on comparing the perm and the sorted perm.</p>