Skip to content

Commit

Permalink
Trac #18075: Add inversion number method to AlternatingSignMatrices
Browse files Browse the repository at this point in the history
Add inversion number method to !AlternatingSignMatrices

URL: http://trac.sagemath.org/18075
Reported by: jessicapalencia
Ticket author(s): Jessica Striker
Reviewer(s): Darij Grinberg
  • Loading branch information
Release Manager authored and vbraun committed Apr 15, 2015
2 parents bf3de47 + 82c96d7 commit f4ee46d
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions src/sage/combinat/alternating_sign_matrix.py
Expand Up @@ -45,7 +45,6 @@
from sage.rings.integer import Integer
from sage.combinat.posets.lattices import LatticePoset
from sage.combinat.gelfand_tsetlin_patterns import GelfandTsetlinPatternsTopRow
from sage.sets.set import Set
from sage.combinat.combinatorial_map import combinatorial_map
from sage.combinat.non_decreasing_parking_function import NonDecreasingParkingFunction
from sage.combinat.permutation import Permutation
Expand All @@ -57,6 +56,16 @@ class AlternatingSignMatrix(Element):
An alternating sign matrix is a square matrix of `0`'s, `1`'s and `-1`'s
such that the sum of each row and column is `1` and the non-zero
entries in each row and column alternate in sign.
These were introduced in [MiRoRu]_.
REFERENCES:
.. [MiRoRu] W. H. Mills, David P Robbins, Howard Rumsey Jr.,
*Alternating sign matrices and descending plane partitions*,
Journal of Combinatorial Theory, Series A,
Volume 34, Issue 3, May 1983, Pages 340--359.
http://www.sciencedirect.com/science/article/pii/0097316583900687
"""
__metaclass__ = ClasscallMetaclass

Expand Down Expand Up @@ -287,6 +296,41 @@ def rotate_ccw(self):
l.reverse()
return AlternatingSignMatrix(matrix(l))

def inversion_number(self):
r"""
Return the inversion number of ``self``.
If we denote the entries of the alternating sign matrix as `a_{i,j}`,
the inversion number is defined as `\sum_{i>k}\sum_{j<l}a_{i,j}a_{k,l}`.
When restricted to permutation matrices, this gives the usual inversion
number of the permutation.
This definition is equivalent to the one given in [MiRoRu]_.
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
sage: asm = A([[0, 1, 0],[1, -1, 1],[0, 1, 0]])
sage: asm.inversion_number()
2
sage: P=Permutations(5)
sage: all(p.number_of_inversions()==AlternatingSignMatrix(p.to_matrix()).inversion_number() for p in P)
True
"""
inversion_num = 0
asm_matrix = self.to_matrix()
nonzero_cells = asm_matrix.nonzero_positions()
for (i,j) in nonzero_cells:
for (k,l) in nonzero_cells:
if i > k and j < l:
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 Expand Up @@ -773,7 +817,7 @@ def to_semistandard_tableau(self):
sage: parent(t)
Semistandard tableaux
"""
from sage.combinat.tableau import SemistandardTableau, SemistandardTableaux
from sage.combinat.tableau import SemistandardTableau
mt = self.to_monotone_triangle()
ssyt = [[0]*(len(mt) - j) for j in range(len(mt))]
for i in range(len(mt)):
Expand Down Expand Up @@ -815,8 +859,7 @@ def left_key(self):
[0 1 0]
sage: parent(t)
Alternating sign matrices of size 3
"""
from sage.combinat.tableau import SemistandardTableau, SemistandardTableaux
"""
lkey = self.to_semistandard_tableau().left_key_tableau()
mt = [[0]*(len(lkey) - j) for j in range(len(lkey))]
for i in range(len(lkey)):
Expand Down Expand Up @@ -1156,6 +1199,15 @@ def __iter__(self):
else:
for c in ContreTableaux(self._n):
yield from_contre_tableau(c)
# This is broken!
# sage: A = AlternatingSignMatrices(3, use_monotone_triangles=False)
# sage: list(A)
# ---------------------------------------------------------------------------
# NameError Traceback (most recent call last)
# ...
# NameError: global name 'from_contre_tableau' is not defined
# If this is really obsolete, the else-branch should be
# removed and the doc modified accordingly.

def _lattice_initializer(self):
r"""
Expand Down

0 comments on commit f4ee46d

Please sign in to comment.