*****************************************************************************
*       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: St000320

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

-----------------------------------------------------------------------------
Description: The dinv adjustment of an integer partition.

The Ferrers shape of an integer partition $\lambda = (\lambda_1,\ldots,\lambda_k)$ can be decomposed into border strips. For $0 \leq j < \lambda_1$ let $n_j$ be the length of the border strip starting at $(\lambda_1-j,0)$.
The dinv adjustment is then defined by
$$\sum_{j:n_j > 0}(\lambda_1-1-j).$$

The following example is taken from Appendix B in [2]: Let $\lambda=(5,5,4,4,2,1)$. Removing the border strips successively yields the sequence of partitions
$$(5,5,4,4,2,1),(4,3,3,1),(2,2),(1),(),$$
and we obtain $(n_0,\ldots,n_4) = (10,7,0,3,1)$.
The dinv adjustment is thus $4+3+1+0 = 8$.

-----------------------------------------------------------------------------
References: [1] ,  Loehr, N. A., Warrington, G. S. Nested quantum Dyck paths and $\nabla (s_\lambda )$ [[MathSciNet:2418288]] [[arXiv:0705.4608]]
[2]   Haglund, J. The $q$,$t$-Catalan numbers and the space of diagonal harmonics [[MathSciNet:2371044]]

-----------------------------------------------------------------------------
Code:
def remove_border_strip(L):
    return Partition( part-1 for part in L[1:] if part > 1 )

def border_strip_decomposition(L):
    decomp = []
    while len(L) > 0:
        decomp.append(L)
        L = remove_border_strip(L)
    return decomp

def length_seq(L):
    strip_seq = border_strip_decomposition(L) + [[]]
    len_seq = [0]*(L[0])
    for j in range(len(strip_seq)-1):
        len_seq[L[0]-strip_seq[j][0]] = sum(strip_seq[j])-sum(strip_seq[j+1])
    return len_seq

def statistic(L):
    len_seq = length_seq(L)
    return sum( L[0]-1-j for j in range(len(len_seq)) if len_seq[j] > 0 )

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

[1]                   => 0
[2]                   => 1
[1,1]                 => 0
[3]                   => 2
[2,1]                 => 1
[1,1,1]               => 0
[4]                   => 3
[3,1]                 => 2
[2,2]                 => 1
[2,1,1]               => 1
[1,1,1,1]             => 0
[5]                   => 4
[4,1]                 => 3
[3,2]                 => 2
[3,1,1]               => 2
[2,2,1]               => 1
[2,1,1,1]             => 1
[1,1,1,1,1]           => 0
[6]                   => 5
[5,1]                 => 4
[4,2]                 => 3
[4,1,1]               => 3
[3,3]                 => 3
[3,2,1]               => 2
[3,1,1,1]             => 2
[2,2,2]               => 1
[2,2,1,1]             => 1
[2,1,1,1,1]           => 1
[1,1,1,1,1,1]         => 0
[7]                   => 6
[6,1]                 => 5
[5,2]                 => 4
[5,1,1]               => 4
[4,3]                 => 4
[4,2,1]               => 3
[4,1,1,1]             => 3
[3,3,1]               => 3
[3,2,2]               => 2
[3,2,1,1]             => 2
[3,1,1,1,1]           => 2
[2,2,2,1]             => 1
[2,2,1,1,1]           => 1
[2,1,1,1,1,1]         => 1
[1,1,1,1,1,1,1]       => 0
[8]                   => 7
[7,1]                 => 6
[6,2]                 => 5
[6,1,1]               => 5
[5,3]                 => 5
[5,2,1]               => 4
[5,1,1,1]             => 4
[4,4]                 => 5
[4,3,1]               => 4
[4,2,2]               => 3
[4,2,1,1]             => 3
[4,1,1,1,1]           => 3
[3,3,2]               => 3
[3,3,1,1]             => 3
[3,2,2,1]             => 2
[3,2,1,1,1]           => 2
[3,1,1,1,1,1]         => 2
[2,2,2,2]             => 1
[2,2,2,1,1]           => 1
[2,2,1,1,1,1]         => 1
[2,1,1,1,1,1,1]       => 1
[1,1,1,1,1,1,1,1]     => 0
[9]                   => 8
[8,1]                 => 7
[7,2]                 => 6
[7,1,1]               => 6
[6,3]                 => 6
[6,2,1]               => 5
[6,1,1,1]             => 5
[5,4]                 => 6
[5,3,1]               => 5
[5,2,2]               => 4
[5,2,1,1]             => 4
[5,1,1,1,1]           => 4
[4,4,1]               => 5
[4,3,2]               => 4
[4,3,1,1]             => 4
[4,2,2,1]             => 3
[4,2,1,1,1]           => 3
[4,1,1,1,1,1]         => 3
[3,3,3]               => 3
[3,3,2,1]             => 3
[3,3,1,1,1]           => 3
[3,2,2,2]             => 2
[3,2,2,1,1]           => 2
[3,2,1,1,1,1]         => 2
[3,1,1,1,1,1,1]       => 2
[2,2,2,2,1]           => 1
[2,2,2,1,1,1]         => 1
[2,2,1,1,1,1,1]       => 1
[2,1,1,1,1,1,1,1]     => 1
[1,1,1,1,1,1,1,1,1]   => 0
[10]                  => 9
[9,1]                 => 8
[8,2]                 => 7
[8,1,1]               => 7
[7,3]                 => 7
[7,2,1]               => 6
[7,1,1,1]             => 6
[6,4]                 => 7
[6,3,1]               => 6
[6,2,2]               => 5
[6,2,1,1]             => 5
[6,1,1,1,1]           => 5
[5,5]                 => 7
[5,4,1]               => 6
[5,3,2]               => 5
[5,3,1,1]             => 5
[5,2,2,1]             => 4
[5,2,1,1,1]           => 4
[5,1,1,1,1,1]         => 4
[4,4,2]               => 5
[4,4,1,1]             => 5
[4,3,3]               => 4
[4,3,2,1]             => 4
[4,3,1,1,1]           => 4
[4,2,2,2]             => 3
[4,2,2,1,1]           => 3
[4,2,1,1,1,1]         => 3
[4,1,1,1,1,1,1]       => 3
[3,3,3,1]             => 3
[3,3,2,2]             => 3
[3,3,2,1,1]           => 3
[3,3,1,1,1,1]         => 3
[3,2,2,2,1]           => 2
[3,2,2,1,1,1]         => 2
[3,2,1,1,1,1,1]       => 2
[3,1,1,1,1,1,1,1]     => 2
[2,2,2,2,2]           => 1
[2,2,2,2,1,1]         => 1
[2,2,2,1,1,1,1]       => 1
[2,2,1,1,1,1,1,1]     => 1
[2,1,1,1,1,1,1,1,1]   => 1
[1,1,1,1,1,1,1,1,1,1] => 0

-----------------------------------------------------------------------------
Created: Dec 08, 2015 at 17:40 by Christian Stump

-----------------------------------------------------------------------------
Last Updated: Dec 17, 2015 at 12:53 by Christian Stump