Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
18075: added inversion number to AlternatingSignMatrices
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicapalencia committed Mar 27, 2015
1 parent 52db42b commit 8827ffe
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sage/combinat/alternating_sign_matrix.py
Expand Up @@ -286,6 +286,27 @@ def rotate_ccw(self):
l.reverse()
return AlternatingSignMatrix(matrix(l))

def inversion_number(self):
r"""
Return the inversion number of ``self``.
EXAMPLES::
sage: A = AlternatingSignMatrices(3)
sage: A([[1, 0, 0],[0, 1, 0],[0, 0, 1]]).inversion_number()
0
sage: asm = A([[0, 0, 1],[1, 0, 0],[0, 1, 0]])
sage: asm.inversion_number()
2
"""
inversion_num = 0
asm_matrix = self.to_matrix()
for (i,j) in asm_matrix.nonzero_positions():
for (k,l) in asm_matrix.nonzero_positions():
if i>k and j<l:
inversion_num = inversion_num + asm_matrix[i][j]*asm_matrix[k][l]
return inversion_num

@combinatorial_map(name='rotate clockwise')
def rotate_cw(self):
r"""
Expand Down

0 comments on commit 8827ffe

Please sign in to comment.