From 2cb5411af9ea4085291d4a6e729cbe53e29def84 Mon Sep 17 00:00:00 2001 From: Shriya M <25shriya@gmail.com> Date: Wed, 17 Aug 2022 11:02:16 +0530 Subject: [PATCH 1/5] Add multimajor index --- src/doc/en/reference/references/index.rst | 5 +++ src/sage/combinat/permutation.py | 37 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/doc/en/reference/references/index.rst b/src/doc/en/reference/references/index.rst index bb77d546810..1050f95f802 100644 --- a/src/doc/en/reference/references/index.rst +++ b/src/doc/en/reference/references/index.rst @@ -3321,6 +3321,11 @@ REFERENCES: *Combinatorics of symmetric designs*. Cambridge University Press, 2006. +.. [JS2000] \A. Joellenbeck, M. Schocker. + "Cyclic Characters of Symmetric Groups". + J. Algebraic Combin., **12** (2000), 155-161. + :doi:`10.1023/A:1026592027019`. + .. [JS2010] \B. Jones, A. Schilling. "Affine structures and a tableau model for `E_6` crystals", J. Algebra. **324** (2010). 2512-2542. diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index a2e7df2b130..9453cdb16f7 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -221,12 +221,18 @@ finite Weyl group to make it more uniform with :class:`SymmetricGroup`. Added ability to compute the conjugacy classes. +- Amrutha P, Shriya M, Divya Aggarwal (2022-08-16): Added Multimajor Index. + Classes and methods =================== """ # **************************************************************************** # Copyright (C) 2007 Mike Hansen +# 2022 Amrutha P +# 2022 Shriya M <25shriya@gmail.com> +# 2022 Divya Aggarwal +# # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -3365,6 +3371,37 @@ def major_index(self, final_descent=False) -> Integer: descents = self.descents(final_descent) return sum(descents) + def multi_major_index(self, composition): + r""" + Return the multimajor index of this permutation with respect to ``composition``. + + INPUT: + + - ``composition`` -- a :class:`Composition` of :meth:`size` + + EXAMPLES:: + + sage: Permutation([5, 6, 2, 1, 3, 7, 4]).multi_major_index(Composition([3, 2, 2])) + [2, 0, 1] + + REFERENCES: + + - [JS2000]_ + """ + if self.size() == composition.size(): + D = self.descents() + s = [0] + for i, qi in enumerate(q): + maj_qp = [0] * len(s) + s.append(s[i] + qi) + for j in range(len(s)): + for d in D: + if s[j - 1] < d < s[j]: + maj_qp[j - 1] += d - s[j - 1] + return maj_qp + raise ValueError("Invalid Input") + + def imajor_index(self, final_descent=False) -> Integer: """ Return the inverse major index of the permutation ``self``, which is From 5e55c77d938bea28af8f86b0e4ff1169a500bd6d Mon Sep 17 00:00:00 2001 From: Amrutha P Date: Tue, 23 Aug 2022 12:30:01 +0530 Subject: [PATCH 2/5] Speed up multimajor index --- src/sage/combinat/permutation.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 9453cdb16f7..027ab25c8b5 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -3388,18 +3388,20 @@ def multi_major_index(self, composition): - [JS2000]_ """ - if self.size() == composition.size(): - D = self.descents() - s = [0] - for i, qi in enumerate(q): - maj_qp = [0] * len(s) - s.append(s[i] + qi) - for j in range(len(s)): - for d in D: - if s[j - 1] < d < s[j]: - maj_qp[j - 1] += d - s[j - 1] - return maj_qp - raise ValueError("Invalid Input") + composition = Composition(composition) + if self.size() != composition.size(): + raise ValueError("size of the composition should be equal to length of the permutation") + descents = self.descents() + partial_sum = [0] + composition.partial_sums() + multimajor_index = [] + for j in range(1, len(partial_sum)): + a = partial_sum[j-1] + b = partial_sum[j] + from bisect import bisect_right, bisect_left + start = bisect_right(descents, a) + end = bisect_left(descents, b) + multimajor_index.append(sum(descents[start: end])-(end-start)*a) + return multimajor_index def imajor_index(self, final_descent=False) -> Integer: From 53cc12db10ba3deca505de659deda9ca54f71912 Mon Sep 17 00:00:00 2001 From: Shriya M <25shriya@gmail.com> Date: Tue, 23 Aug 2022 12:50:15 +0530 Subject: [PATCH 3/5] Add examples for multimajor index --- src/sage/combinat/permutation.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 027ab25c8b5..991f6d243a3 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -3377,12 +3377,19 @@ def multi_major_index(self, composition): INPUT: - - ``composition`` -- a :class:`Composition` of :meth:`size` + - ``composition`` -- a composition of :meth:`size` EXAMPLES:: - sage: Permutation([5, 6, 2, 1, 3, 7, 4]).multi_major_index(Composition([3, 2, 2])) + sage: p = Permutation([5, 6, 2, 1, 3, 7, 4]) + sage: p.multi_major_index([3, 2, 2]) [2, 0, 1] + sage: p.multi_major_index([7]) == [p.major_index()] + True + sage: p.multi_major_index([1]*7) + [0, 0, 0, 0, 0, 0, 0] + sage: Permutation([]).multi_major_index([]) + [] REFERENCES: From 1a468caa729117d650c9fd2b72ff1f947783ea6d Mon Sep 17 00:00:00 2001 From: aritra Date: Tue, 23 Aug 2022 13:03:03 +0530 Subject: [PATCH 4/5] Improve wording --- src/sage/combinat/permutation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 991f6d243a3..c7c9cb78661 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -3397,7 +3397,7 @@ def multi_major_index(self, composition): """ composition = Composition(composition) if self.size() != composition.size(): - raise ValueError("size of the composition should be equal to length of the permutation") + raise ValueError("size of the composition should be equal to size of the permutation") descents = self.descents() partial_sum = [0] + composition.partial_sums() multimajor_index = [] @@ -3410,7 +3410,6 @@ def multi_major_index(self, composition): multimajor_index.append(sum(descents[start: end])-(end-start)*a) return multimajor_index - def imajor_index(self, final_descent=False) -> Integer: """ Return the inverse major index of the permutation ``self``, which is From 9a93d1dacb6233b202b6d0adb1c5e1eacd467f89 Mon Sep 17 00:00:00 2001 From: aritra Date: Wed, 24 Aug 2022 11:12:21 +0530 Subject: [PATCH 5/5] Add doctest for multimajor index --- src/sage/combinat/permutation.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index c7c9cb78661..f6d802e2beb 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -3377,7 +3377,7 @@ def multi_major_index(self, composition): INPUT: - - ``composition`` -- a composition of :meth:`size` + - ``composition`` -- a composition of the :meth:`size` of this permutation EXAMPLES:: @@ -3391,6 +3391,13 @@ def multi_major_index(self, composition): sage: Permutation([]).multi_major_index([]) [] + TESTS:: + + sage: p.multi_major_index([1, 3, 3, 7]) + Traceback (most recent call last): + ... + ValueError: size of the composition should be equal to size of the permutation + REFERENCES: - [JS2000]_