Ticket #14427: trac_14427-key_tableau-rebased.patch

File trac_14427-key_tableau-rebased.patch, 6.6 KB (added by tscrim, 9 years ago)
  • sage/combinat/tableau.py

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