Skip to content

Commit c812284

Browse files
author
Release Manager
committed
sagemathgh-40940: provide aliases for number_of_inversions and number_of_negative_ones fix sagemath#40935 in ASM as with sagemath#40939: we have to decide whether this does not pollute the name space too much. URL: sagemath#40940 Reported by: Martin Rubey Reviewer(s): Frédéric Chapoton
2 parents 453c85c + df6c5d7 commit c812284

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/sage/combinat/alternating_sign_matrix.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def rotate_ccw(self):
292292
li.reverse()
293293
return AlternatingSignMatrix(li)
294294

295-
def inversion_number(self):
295+
def number_of_inversions(self):
296296
r"""
297297
Return the inversion number of ``self``.
298298
@@ -306,16 +306,17 @@ def inversion_number(self):
306306
EXAMPLES::
307307
308308
sage: A = AlternatingSignMatrices(3)
309-
sage: A([[1, 0, 0],[0, 1, 0],[0, 0, 1]]).inversion_number()
309+
sage: A([[1, 0, 0],[0, 1, 0],[0, 0, 1]]).number_of_inversions()
310310
0
311311
sage: asm = A([[0, 0, 1],[1, 0, 0],[0, 1, 0]])
312-
sage: asm.inversion_number()
312+
sage: asm.number_of_inversions()
313313
2
314314
sage: asm = A([[0, 1, 0],[1, -1, 1],[0, 1, 0]])
315-
sage: asm.inversion_number()
315+
sage: asm.number_of_inversions()
316316
2
317317
sage: P = Permutations(5)
318-
sage: all(p.number_of_inversions()==AlternatingSignMatrix(p.to_matrix()).inversion_number() for p in P)
318+
sage: A = AlternatingSignMatrix
319+
sage: all(p.number_of_inversions() == A(p.to_matrix()).number_of_inversions() for p in P)
319320
True
320321
"""
321322
inversion_num = 0
@@ -327,6 +328,8 @@ def inversion_number(self):
327328
inversion_num += asm_matrix[i][j] * asm_matrix[k][l]
328329
return inversion_num
329330

331+
inversion_number = number_of_inversions
332+
330333
@combinatorial_map(name='rotate clockwise')
331334
def rotate_cw(self):
332335
r"""
@@ -870,23 +873,25 @@ def to_dyck_word(self, algorithm):
870873

871874
raise ValueError("unknown algorithm '%s'" % algorithm)
872875

873-
def number_negative_ones(self):
876+
def number_of_negative_ones(self):
874877
"""
875878
Return the number of entries in ``self`` equal to -1.
876879
877880
EXAMPLES::
878881
879882
sage: A = AlternatingSignMatrices(3)
880883
sage: asm = A([[0,1,0],[1,0,0],[0,0,1]])
881-
sage: asm.number_negative_ones()
884+
sage: asm.number_of_negative_ones()
882885
0
883886
sage: asm = A([[0,1,0],[1,-1,1],[0,1,0]])
884-
sage: asm.number_negative_ones()
887+
sage: asm.number_of_negative_ones()
885888
1
886889
"""
887890
a = self._matrix
888891
return ZZ((len(a.nonzero_positions()) - a.nrows()) // 2)
889892

893+
number_negative_ones = number_of_negative_ones
894+
890895
def is_permutation(self):
891896
"""
892897
Return ``True`` if ``self`` is a permutation matrix
@@ -902,7 +907,7 @@ def is_permutation(self):
902907
sage: asm.is_permutation()
903908
False
904909
"""
905-
return self.number_negative_ones() == 0
910+
return self.number_of_negative_ones() == 0
906911

907912
def to_permutation(self):
908913
"""
@@ -1241,7 +1246,7 @@ def random_element(self):
12411246
[ 0 0 0 1 0 0 0]
12421247
[ 0 1 0 0 0 0 0]
12431248
sage: a = AlternatingSignMatrices(5).random_element()
1244-
sage: bool(a.number_negative_ones()) or a.is_permutation()
1249+
sage: bool(a.number_of_negative_ones()) or a.is_permutation()
12451250
True
12461251
12471252
This is done using a modified version of Propp and Wilson's "coupling

0 commit comments

Comments
 (0)