Ticket #14427: trac_14427_key_tableau.patch

File trac_14427_key_tableau.patch, 6.6 KB (added by jferreira, 9 years ago)
  • sage/combinat/tableau.py

    # HG changeset patch
    # User Jeffrey Ferreira <jeffpferreira@gmail.com>
    # Date 1366066671 14400
    # Node ID b714cd6d6eb0ea900e72978959f2597682e911a2
    # Parent  d0ce6901a0aa5968fa6e5c0f8c3ab86feabf5684
    Trac 14427: adds key tableau functions
    
    diff --git a/sage/combinat/tableau.py b/sage/combinat/tableau.py
    a b  
    21622162            return self.parent()([[w[entry-1] for entry in row] for row in self])
    21632163        except StandardError:
    21642164            return Tableau([[w[entry-1] for entry in row] for row in self])
     2165           
     2166    def is_key_tableau(self):
     2167        """
     2168        Return ``True`` if ``self`` is a key tableau or ``False`` otherwise.
     2169
     2170        A tableau is a *key tableau* if the set of entries in the `j`-th
     2171        column are a subset of the set of entries in the `(j-1)`-st column.
     2172
     2173        REFERENCES:
     2174
     2175        .. [LS90] A. Lascoux, M.-P. Schutzenberger.
     2176           Keys and standard bases, invariant theory and tableaux.
     2177           IMA Volumes in Math and its Applications (D. Stanton, ED.).
     2178           Southend on Sea, UK, 19 (1990). 125-144.
     2179           
     2180        .. [Willis10] M. Willis. A direct way to find the right key of
     2181           a semistandard Young tableau. :arxiv:`1110.6184v1`.
     2182
     2183        EXAMPLES::
     2184
     2185            sage: t = Tableau([[1,1,1],[2,3],[3]])
     2186            sage: t.is_key_tableau()
     2187            True
     2188
     2189            sage: t = Tableau([[1,1,2],[2,3],[3]])
     2190            sage: t.is_key_tableau()
     2191            False
     2192        """
     2193        itr = enumerate(self.conjugate()[1:],1)
     2194        return all(x in self.conjugate()[i-1] for i, col in itr for x in col)
     2195
     2196    def right_key_tableau(self):
     2197        """
     2198        Return the right key tableau of ``self``.
     2199
     2200        The right key tableau of a tableau `T` is a key tableau whose entries
     2201        are weakly greater than the corresponding entries in `T`, and whose column
     2202        reading word is subject to certain conditions. See [LS90]_ for the full definition.
     2203       
     2204        ALGORITHM:
     2205       
     2206        The following algorithm follows [Willis10]_. Note that if `T` is a key tableau
     2207        then the output of the algorithm is `T`.
     2208       
     2209        To compute the right key tableau `R` of a tableau `T` we iterate over the columns
     2210        of `T`. Let `T_j` be the `j`-th column of `T` and iterate over the entires
     2211        in `T_j` from bottom to top. Initialize the corresponding entry `k` in `R` to be
     2212        the largest entry in `T_j`. Scan the bottom of each column of `T` to the right of
     2213        `T_j`, updating `k` to be the scanned entry whenever the scanned entry is weakly
     2214        greater than `k`. Update `T_j` and all columns to the right by removing all
     2215        scanned entries.
     2216
     2217        .. SEEALSO::
     2218
     2219            - :meth:`is_key_tableau()`
     2220
     2221        EXAMPLES::
     2222
     2223            sage: t = Tableau([[1,2],[2,3]])
     2224            sage: t.right_key_tableau()
     2225            [[2, 2], [3, 3]]
     2226            sage: t = Tableau([[1,1,2,4],[2,3,3],[4],[5]])
     2227            sage: t.right_key_tableau()
     2228            [[2, 2, 2, 4], [3, 4, 4], [4], [5]]
     2229
     2230        TESTS:
     2231
     2232        We check that if we have a key tableau, we return the same tableau::
     2233
     2234            sage: t = Tableau([[1,1,1,2], [2,2,2], [4], [5]])
     2235            sage: t.is_key_tableau()
     2236            True
     2237            sage: t.right_key_tableau() == t
     2238            True
     2239        """
     2240        if self.is_key_tableau():
     2241            return self
     2242           
     2243        key = [[] for row in self.conjugate()]
     2244        cols_list = self.conjugate().to_list()
     2245
     2246        for i, col_a in enumerate(cols_list):
     2247            right_cols = cols_list[i+1:]
     2248            for elem in reversed(col_a):
     2249                key_val = elem
     2250                update = []
     2251                for col_b in right_cols:
     2252                    if col_b != [] and key_val <= col_b[-1]:
     2253                        key_val = col_b[-1]
     2254                        update.append(col_b[:-1])
     2255                    else:
     2256                        update.append(col_b)
     2257                key[i].insert(0,key_val)
     2258                right_cols = update
     2259        return Tableau(key).conjugate()
     2260               
     2261    def left_key_tableau(self):
     2262        """
     2263        Return the left key tableau of ``self``.
     2264
     2265        The left key tableau of a tableau `T` is the key tableau whose entries
     2266        are weakly lesser than the corresponding entries in `T`, and whose column
     2267        reading word is subject to certain conditions. See [LS90]_ for the full definition.
     2268       
     2269        ALGORITHM:
     2270       
     2271        The following algorithm follows [Willis10]_. Note that if `T` is a key tableau
     2272        then the output of the algorithm is `T`.
     2273       
     2274        To compute the left key tableau `L` of a tableau `T` we iterate over the columns
     2275        of `T`. Let `T_j` be the `j`-th column of `T` and iterate over the entires
     2276        in `T_j` from bottom to top. Initialize the corresponding entry `k` in `L` as the
     2277        largest entry in `T_j`. Scan the columns to the left of `T_j` and with each column
     2278        update `k` to be the lowest entry in that column which is weakly less than `k`.
     2279        Update `T_j` and all columns to the left by removing all scanned entries.
     2280
     2281        .. SEEALSO::
     2282
     2283            - :meth:`is_key_tableau()`
     2284
     2285        EXAMPLES::
     2286
     2287            sage: t = Tableau([[1,2],[2,3]])
     2288            sage: t.left_key_tableau()
     2289            [[1, 1], [2, 2]]
     2290            sage: t = Tableau([[1,1,2,4],[2,3,3],[4],[5]])
     2291            sage: t.left_key_tableau()
     2292            [[1, 1, 1, 2], [2, 2, 2], [4], [5]]
     2293
     2294        TESTS:
     2295
     2296        We check that if we have a key tableau, we return the same tableau::
     2297
     2298            sage: t = Tableau([[1,1,1,2], [2,2,2], [4], [5]])
     2299            sage: t.is_key_tableau()
     2300            True
     2301            sage: t.left_key_tableau() == t
     2302            True
     2303        """
     2304        if self.is_key_tableau():
     2305            return self
     2306           
     2307        key = [[] for row in self.conjugate()]
     2308        key[0] = self.conjugate()[0]
     2309        cols_list = self.conjugate().to_list()
     2310
     2311        from bisect import bisect_right
     2312        for i, col_a in enumerate(cols_list[1:],1):
     2313            left_cols = cols_list[:i]
     2314            for elem in reversed(col_a):
     2315                key_val = elem
     2316                update = []
     2317                for col_b in reversed(left_cols):
     2318                    j = bisect_right(col_b, key_val) - 1
     2319                    key_val = col_b[j]
     2320                    update.insert(0, col_b[:j])
     2321                left_cols = update
     2322                key[i].insert(0,key_val)
     2323        return Tableau(key).conjugate()
     2324
    21652325
    21662326class SemistandardTableau(Tableau):
    21672327    """