*****************************************************************************
*       www.FindStat.org - The Combinatorial Statistic Finder               *
*                                                                           *
*       Copyright (C) 2019 The FindStatCrew <info@findstat.org>             *
*                                                                           *
*    This information is distributed in the hope that it will be useful,    *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of         *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                   *
*****************************************************************************

-----------------------------------------------------------------------------
Statistic identifier: St000046

-----------------------------------------------------------------------------
Collection: Integer partitions

-----------------------------------------------------------------------------
Description: The largest eigenvalue of the random to random operator acting on the simple module corresponding to the given partition.

-----------------------------------------------------------------------------
References: [1]   Reyes, J.-C. U. Random walk, semi-direct products, and card shuffling [[MathSciNet:2703300]]

-----------------------------------------------------------------------------
Code:
class RandomToRandom:
    def __init__(self, n):
        self._n = n

    @cached_method
    def W(self):
        return SymmetricGroup(self._n)

    def cycle(self, i,j):
        """
        EXAMPLES::

            sage: RandomToRandom(5).cycle(2,4)
            (2,3,4)
        """
        return self.W()([tuple(range(i,j+1))])

    def r2r(self, i,j):
        """
        EXAMPLES::

            sage: R = RandomToRandom(4)
            sage: R.r2r(1,3,4)
            (1,2,4)
            sage: R.r2r(3,1,4)
            (1,4,2)
            sage: r2r(1,2,4)
            (1,4)

            sage: RandomToRandom(3).r2r(1,2,3)
            (1,3)
        """
        return self.cycle(i,self._n) * (~self.cycle(j,self._n))

    def operator(self, representation):
        """
        EXAMPLES::

            sage: R = RandomToRandom(3)
            sage: representation = attrcall("matrix") # emulates the natural representation
            sage: R.operator(representation)
            [5 1 3]
            [1 5 3]
            [3 3 3]

            sage: representation = R.W().algebra(QQ).monomial         # emulates the regular representation

            sage: R.operator(representation)
            3*B[()] + 2*B[(2,3)] + B[(1,2,3)] + B[(1,3,2)] + 2*B[(1,3)]

            sage: R.operator(Partition([2,1]))
            [2 2]
            [2 2]
        """
        if isinstance(representation, Partition):
            assert representation.size() == self._n
            representation = SymmetricGroupRepresentation(representation)
        E = self.W().domain()
        return sum(representation(self.r2r(i,j)) for i in E for j in E)

    def max_eigenvalue_on_simple_representation(self, p):
        return max(self.operator(p).eigenvalues())

    def max_eigenvalue_on_simple_representations(self):
        """
        EXAMPLES::

            sage: R = RandomToRandom(4)
            sage: dict(R.max_eigenvalue_on_simple_representations())
            {[1, 1, 1, 1]: 0, [2, 1, 1]: 6, [2, 2]: 4, [3, 1]: 10, [4]: 16}

            sage: R = RandomToRandom(5)
            sage: dict(R.max_eigenvalue_on_simple_representations())
            {[1, 1, 1, 1]: 0, [2, 1, 1]: 6, [2, 2]: 4, [3, 1]: 10, [4]: 16}
        """
        from sage.sets.family import Family
        return Family(Partitions(self._n), self.max_eigenvalue_on_simple_representation)

@cached_function
def getRandomToRandom(n):
    return RandomToRandom(n)

def statistic(L):
    n = sum(L)
    R = getRandomToRandom(n)
    d = R.max_eigenvalue_on_simple_representations()
    return d[L]

-----------------------------------------------------------------------------
Statistic values:

[1]               => 1
[2]               => 4
[1,1]             => 0
[3]               => 9
[2,1]             => 4
[1,1,1]           => 1
[4]               => 16
[3,1]             => 10
[2,2]             => 4
[2,1,1]           => 6
[1,1,1,1]         => 0
[5]               => 25
[4,1]             => 18
[3,2]             => 11
[3,1,1]           => 13
[2,2,1]           => 7
[2,1,1,1]         => 6
[1,1,1,1,1]       => 1
[6]               => 36
[5,1]             => 28
[4,2]             => 20
[4,1,1]           => 22
[3,3]             => 12
[3,2,1]           => 15
[3,1,1,1]         => 14
[2,2,2]           => 8
[2,2,1,1]         => 8
[2,1,1,1,1]       => 8
[1,1,1,1,1,1]     => 0
[7]               => 49
[6,1]             => 40
[5,2]             => 31
[5,1,1]           => 33
[4,3]             => 22
[4,2,1]           => 25
[4,1,1,1]         => 24
[3,3,1]           => 17
[3,2,2]           => 17
[3,2,1,1]         => 17
[3,1,1,1,1]       => 17
[2,2,2,1]         => 9
[2,2,1,1,1]       => 9
[2,1,1,1,1,1]     => 8
[1,1,1,1,1,1,1]   => 1
[8]               => 64
[7,1]             => 54
[6,2]             => 44
[6,1,1]           => 46
[5,3]             => 34
[5,2,1]           => 37
[5,1,1,1]         => 36
[4,4]             => 24
[4,3,1]           => 28
[4,2,2]           => 28
[4,2,1,1]         => 28
[4,1,1,1,1]       => 28
[3,3,2]           => 19
[3,3,1,1]         => 19
[3,2,2,1]         => 19
[3,2,1,1,1]       => 19
[3,1,1,1,1,1]     => 18
[2,2,2,2]         => 10
[2,2,2,1,1]       => 10
[2,2,1,1,1,1]     => 10
[2,1,1,1,1,1,1]   => 10
[1,1,1,1,1,1,1,1] => 0
[9]               => 81
[8,1]             => 70
[7,2]             => 59
[7,1,1]           => 61
[6,3]             => 48
[6,2,1]           => 51
[6,1,1,1]         => 50
[5,4]             => 37
[5,3,1]           => 41
[5,2,2]           => 41

-----------------------------------------------------------------------------
Created: Mar 22, 2013 at 22:05 by Nicolas M. Thiéry

-----------------------------------------------------------------------------
Last Updated: Dec 29, 2016 at 09:25 by Christian Stump