code
stringlengths
17
6.64M
def _to_reduced_word(P): '\n Return a reduced word associated to skew partition ``P``.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _to_reduced_word\n sage: P = SkewPartition([[2, 2], [1]])\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _to_reduced_word\n sage: _to_reduced_word(P)\n [2, 1, 3]\n\n sage: P = SkewPartition([[], []])\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _to_reduced_word\n sage: _to_reduced_word(P)\n []\n\n sage: P = SkewPartition([[2, 1], []])\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _to_reduced_word\n sage: _to_reduced_word(P)\n [1, 3, 2]\n ' cells = P.cells() if (not cells): return [] m = (max((cell[0] for cell in cells)) + 1) n = (max((cell[1] for cell in cells)) + 1) L = [] for i in range(m, (- 1), (- 1)): for j in range(n, (- 1), (- 1)): if ((i, j) in cells): L += [((j - i) + m)] return L
def _lowest_weights(w, factors, ex, parent=None): '\n Generate all decreasing factorizations in the 0-Hecke monoid that correspond\n to some valid semistandard Young tableaux.\n\n The semistandard Young tableaux should have at most ``factors`` columns and their\n column reading words should be equivalent to ``w`` in a 0-Hecke monoid.\n\n INPUT:\n\n - ``w`` -- a fully commutative reduced word, expressed as an iterable\n\n - ``factors`` -- number of factors for each decreasing factorization\n\n - ``ex`` -- number of extra letters in each decreasing factorizations\n\n - ``parent`` -- (default: None) parent of the decreasing factorizations, automatically assigned if it is None\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _lowest_weights\n sage: _lowest_weights([1, 2, 1], 3, 1)\n Traceback (most recent call last):\n ...\n ValueError: the word w should be fully commutative\n\n sage: _lowest_weights([2, 1, 3, 2], 4, 3)\n [(2, 1)(3, 1)(3, 1)(2), (2, 1)(3, 1)(3, 2)(2)]\n\n sage: _lowest_weights([2, 1, 3, 2], 5, 3)\n [(2, 1)(3, 1)(3, 1)(2)(),\n (2, 1)(3, 1)(3, 2)(2)(),\n (2, 1)(3, 1)(1)(1)(2),\n (2, 1)(3, 1)(1)(2)(2),\n (2, 1)(3, 1)(2)(2)(2),\n (2, 1)(3, 2)(2)(2)(2)]\n\n sage: _lowest_weights([1, 3], 3, 1)\n [(3, 1)(1)(), (3, 1)(3)(), (1)(1)(3), (1)(3)(3)]\n\n sage: _lowest_weights([3, 2, 1], 5, 2)\n [(3, 2, 1)(1)(1)()()]\n ' p = permutation.from_reduced_word(w) if p.has_pattern([3, 2, 1]): raise ValueError('the word w should be fully commutative') if (parent is None): k = max(w) S = SymmetricGroup((k + 1)) word = S.from_reduced_word(w) parent = FullyCommutativeStableGrothendieckCrystal(word, factors, ex) _canonical_word = (lambda w, ex: (([list(w)[0]] * ex) + list(w))) L = _list_equivalent_words(_canonical_word(w, ex)) M = [] for v in L: if _is_valid_column_word(v, factors): J = (([0] + _jumps(v)) + [len(v)]) t = [v[J[i]:J[(i + 1)]] for i in range((len(J) - 1))] if (len(J) < (factors + 1)): t += ([()] * ((factors + 1) - len(J))) M.append(parent.element_class(parent, t)) return sorted(M)
def _jumps(w): '\n Detect all positions where letters weakly increase in ``w``.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _jumps\n sage: w = [4, 1, 2, 1, 4, 3, 2, 1, 3, 2, 2]\n sage: _jumps(w)\n [2, 4, 8, 10]\n ' return [(i + 1) for i in range((len(w) - 1)) if (w[i] <= w[(i + 1)])]
def _is_valid_column_word(w, m=None): '\n Determine if ``w`` is actually a valid column reading word of some\n semistandard Young tableau with at most ``m`` columns.\n\n If ``m`` is None, then we determine if ``w`` is a valid column reading word\n of some semistandard Young tableau.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _is_valid_column_word\n sage: w = [3, 2, 2, 1, 1]\n sage: _is_valid_column_word(w)\n False\n\n sage: w = [3, 2, 1, 1, 1]\n sage: _is_valid_column_word(w,3)\n True\n\n sage: w = [3, 2, 1, 1, 1]\n sage: _is_valid_column_word(w,2)\n False\n\n sage: w = [3, 2, 1, 3, 1]\n sage: _is_valid_column_word(w,2)\n True\n ' J = (([0] + _jumps(w)) + [len(w)]) L = [w[(J[(i + 1)] - 1):J[i]:(- 1)] for i in range((len(J) - 1))] if all(((len(L[i]) >= len(L[(i + 1)])) for i in range((len(L) - 1)))): if ((m is None) or (len(_jumps(w)) <= (m - 1))): return all(((L[(i + 1)][j] >= L[i][j]) for i in range((len(L) - 1)) for j in range(len(L[(i + 1)])))) return False
def _list_equivalent_words(w): '\n List all words equivalent to ``w`` in a 0-Hecke monoid.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _list_equivalent_words\n sage: _list_equivalent_words([1, 1, 2, 1])\n [(1, 1, 2, 1),\n (1, 2, 1, 1),\n (1, 2, 1, 2),\n (1, 2, 2, 1),\n (2, 1, 1, 2),\n (2, 1, 2, 1),\n (2, 1, 2, 2),\n (2, 2, 1, 2)]\n\n sage: _list_equivalent_words([2,1,3,1,2])\n [(2, 1, 1, 3, 2),\n (2, 1, 3, 1, 2),\n (2, 1, 3, 2, 2),\n (2, 1, 3, 3, 2),\n (2, 2, 1, 3, 2),\n (2, 2, 3, 1, 2),\n (2, 3, 1, 1, 2),\n (2, 3, 1, 2, 2),\n (2, 3, 1, 3, 2),\n (2, 3, 3, 1, 2)]\n ' if all((isinstance(i, (int, Integer)) for i in w)): u = w else: raise ValueError('w needs to be a tuple of integers') def _applicable_relations(word): '\n Return all positions where a relation can be applied on ``word``\n along with the type of relation.\n ' L = [] for i in range((len(word) - 2)): (p, q, r) = word[i:((i + 2) + 1)] if (abs((p - q)) > 1): L += [[i, 'pq=qp']] elif (abs((p - q)) == 1): if (p == r): L += [[i, 'pqp=qpq']] elif (r != p): L += [[i, 'ppq=pqq']] if ((q == r) and (r != p)): L += [[i, 'pqq=ppq']] if ((len(word) > 1) and (abs((word[(- 2)] - word[(- 1)])) > 1)): L += [[(len(word) - 2), 'pq=qp']] return L V = set() queue = [tuple(u)] while queue: v = queue.pop(0) if (tuple(v) not in V): V.add(tuple(v)) L = _applicable_relations(v) for pair in L: (position, move) = pair t = _apply_relations(v, position, move) queue += [tuple(t)] return sorted((v for v in list(V)))
def _apply_relations(word, position, move): '\n Apply a particular type of ``move`` on ``word`` at the specified\n ``position`` using a relation in a 0-Hecke monoid .\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.fully_commutative_stable_grothendieck import _apply_relations\n sage: w = [2, 1, 3, 4]\n sage: _apply_relations(w, position=1, move="pq=qp")\n [2, 3, 1, 4]\n\n sage: w = [1, 3, 2, 1, 2, 4]\n sage: _apply_relations(w, position=2, move="pqp=qpq")\n [1, 3, 1, 2, 1, 4]\n\n sage: w = [2, 3, 1, 2, 2, 3]\n sage: _apply_relations(w, position=3, move="pp=p")\n [2, 3, 1, 2, 3]\n\n sage: w = [2, 3, 1, 2, 3]\n sage: _apply_relations(w, position=3, move="p=pp")\n [2, 3, 1, 2, 2, 3]\n\n sage: w = [2, 3, 1, 2, 2, 3]\n sage: _apply_relations(w, position=2, move="pqq=ppq")\n [2, 3, 1, 1, 2, 3]\n\n sage: w = [2, 3, 1, 1, 2, 3]\n sage: _apply_relations(w, position=2, move="ppq=pqq")\n [2, 3, 1, 2, 2, 3]\n ' w = list(word) if (move == 'pq=qp'): p = w[position] q = w[(position + 1)] w[position] = q w[(position + 1)] = p elif (move == 'pqp=qpq'): p = w[position] q = w[(position + 1)] w[position] = q w[(position + 1)] = p w[(position + 2)] = q elif (move == 'pqq=ppq'): p = w[position] q = w[(position + 2)] w[(position + 1)] = p elif (move == 'ppq=pqq'): p = w[position] q = w[(position + 2)] w[(position + 1)] = q elif (move == 'pp=p'): p = w[position] w = (w[:(position + 1)] + w[(position + 2):]) elif (move == 'p=pp'): p = w[position] w = ((w[:(position + 1)] + [p]) + w[(position + 1):]) return w
class GeneralizedYoungWall(CombinatorialElement): '\n A generalized Young wall.\n\n For more information, see\n :class:`~sage.combinat.crystals.generalized_young_walls.InfinityCrystalOfGeneralizedYoungWalls`.\n\n EXAMPLES::\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(4)\n sage: mg = Y.module_generators[0]; mg.pp()\n 0\n sage: mg.f_string([1,2,0,1]).pp()\n 1|2|\n 0|1|\n |\n ' def __init__(self, parent, data): '\n EXAMPLES::\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(2)\n sage: mg = Y.module_generators[0]\n sage: TestSuite(mg).run()\n ' i = (len(data) - 1) while ((i >= 0) and (not data[i])): data.pop() i -= 1 self.rows = len(data) if (not data): self.cols = 0 else: self.cols = max((len(r) for r in data)) self.data = data CombinatorialElement.__init__(self, parent, data) def _repr_(self): '\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[0],[1,0,3,2],[2,1],[3,2,1,0,3,2],[0],[],[2]])\n sage: y\n [[0], [1, 0, 3, 2], [2, 1], [3, 2, 1, 0, 3, 2], [0], [], [2]]\n ' return repr(self.data) def _repr_diagram(self): '\n Return a string representation of the diagram of ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0,2,1],[1,0,2,1,0],[],[0],[1,0,2],[],[],[1]])\n sage: print(y._repr_diagram())\n 1|\n |\n |\n 2|0|1|\n 0|\n |\n 0|1|2|0|1|\n 1|2|0|\n ' if (not self.data): return '0' ret = '' for row in reversed(self.data): wall = '' for elem in reversed(row): wall += str(elem) wall += '|' if (row == []): wall += '|' ret += (wall.rjust(((2 * self.cols) + 1)) + '\n') return ret def _ascii_art_(self): '\n Return an ascii art representation of ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0,2,1],[1,0,2,1,0],[],[0],[1,0,2],[],[],[1]])\n sage: ascii_art(y)\n 1|\n |\n |\n 2|0|1|\n 0|\n |\n 0|1|2|0|1|\n 1|2|0|\n ' from sage.typeset.ascii_art import AsciiArt return AsciiArt(self._repr_diagram().splitlines()) def _unicode_art_(self): '\n Return a unicode art representation of ``self``.\n\n TESTS::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0,2,1],[1,0,2,1,0],[],[0],[1,0,2],[],[],[1]])\n sage: unicode_art(y)\n β”Œβ”€β”€β”€β”\n β”‚ 1 β”‚\n β””β”€β”€β”€β”˜\n β”‚\n ─\n β”‚\n β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”\n β”‚ 1 β”‚ 0 β”‚ 2 β”‚\n └───┴───┼────\n β”‚ 0 β”‚\n β””β”€β”€β”€β”˜\n β”‚\n β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”\n β”‚ 1 β”‚ 0 β”‚ 2 β”‚ 1 β”‚ 0 β”‚\n └───┴───┼───┼───┼────\n β”‚ 0 β”‚ 2 β”‚ 1 β”‚\n β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”˜\n ' from sage.typeset.unicode_art import UnicodeArt if (not self.data): return UnicodeArt(['0']) from sage.combinat.output import ascii_art_table import unicodedata v = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL') vl = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL AND LEFT') table = [(([None] * (self.cols - len(row))) + row) for row in reversed(self)] ret = [] for (i, row) in enumerate(ascii_art_table(table, use_unicode=True).splitlines()): if (row[(- 1)] == ' '): if ((i % 2) == 0): ret.append((row[:(- 1)] + vl)) else: ret.append((row[:(- 1)] + v)) else: ret.append(row) return UnicodeArt(ret) def __eq__(self, other): '\n EXAMPLES::\n\n sage: GYW = crystals.infinity.GeneralizedYoungWalls(2)\n sage: y = GYW([[],[1,0],[2,1]])\n sage: x = GYW([[],[1,0],[2,1]])\n sage: z = GYW([[],[1],[2]])\n sage: x == y\n True\n sage: x == z\n False\n ' if isinstance(other, GeneralizedYoungWall): return (self.data == other.data) return (self.data == other) def __hash__(self): '\n Return the hash of ``self``.\n\n EXAMPLES::\n\n sage: GYW = crystals.infinity.GeneralizedYoungWalls(2)\n sage: h = hash(GYW)\n ' return hash(tuple((tuple(u) for u in self.data))) def raw_signature(self, i): "\n Return the sequence from `\\{+,-\\}` obtained from all `i`-admissible\n slots and removable `i`-boxes without canceling any `(+,-)`-pairs.\n The result also notes the row and column of the sign.\n\n EXAMPLES::\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x.raw_signature(2)\n [['-', 3, 6], ['-', 1, 4], ['-', 6, 1]]\n " sig = [] rank = self.parent().cartan_type().rank() for row in range(self.rows): if ((self.data[row] == []) and (i == (row % rank))): sig.append(['+', row, 0]) elif (self.data[row] == []): continue elif (self.data[row][(- 1)] == ((i + 1) % rank)): sig.append(['+', row, (len(self.data[row]) + 1)]) elif (self.data[row][(- 1)] == i): sig.append(['-', row, len(self.data[row])]) return sorted(sig, key=self._sig_sort) def _sig_sort(self, a): "\n Internal command used to appropriately sort the output\n from :meth:`raw_signature()`.\n\n INPUT:\n\n - `a` -- list of the form ``['s',j,k]`` where `s` is a string, `j` is an integer\n and `k` is an integer\n\n EXAMPLES::\n\n sage: hw = crystals.infinity.GeneralizedYoungWalls(5)([])\n sage: hw._sig_sort(['+',1,0])\n (0, 1)\n " return ((- a[2]), a[1]) def generate_signature(self, i): "\n The `i`-signature of ``self`` (with whitespace where cancellation\n occurs) together with the unreduced sequence from `\\{+,-\\}`. The\n result also records to the row and column position of the sign.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0],[1,0],[2,1,0,2],[],[1]])\n sage: y.generate_signature(1)\n ([['+', 2, 5], ['-', 4, 1]], ' ')\n " sig = [] rank = self.parent().cartan_type().classical().rank() for row in range(self.rows): if ((self.data[row] == []) and (i == (row % (rank + 1)))): sig.append(['+', row, 0]) elif (self.data[row] == []): continue elif (self.data[row][(- 1)] == ((i + 1) % (rank + 1))): sig.append(['+', row, (len(self.data[row]) + 1)]) elif (self.data[row][(- 1)] == i): sig.append(['-', row, len(self.data[row])]) sig = sorted(sig, key=self._sig_sort) strsig = ''.join((x[0] for x in sig)) reducedsig = strsig while re.search('\\+\\s*-', reducedsig): reducedsig = re.sub('\\+\\s*-', (lambda match: ''.ljust(len(match.group(0)))), reducedsig) return (sig, reducedsig) def signature(self, i): "\n Return the `i`-signature of ``self``.\n\n The signature is obtained by reading ``self`` in columns bottom to top starting from the left.\n Then add a `-` at every `i`-box which may be removed from ``self`` and still obtain a legal\n generalized Young wall, and add a `+` at each site for which an `i`-box may be added and still\n obtain a valid generalized Young wall. Then successively cancel any `(+,-)`-pair to obtain a\n sequence of the form `- \\cdots -+ \\cdots +`. This resulting sequence is the output.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0],[1,0],[2,1,0,2],[],[1]])\n sage: y.signature(1)\n ''\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x.signature(2)\n '---'\n " return self.generate_signature(i)[1].strip() def pp(self): '\n Pretty print ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0,2,1],[1,0,2,1,0],[],[0],[1,0,2],[],[],[1]])\n sage: y.pp()\n 1|\n |\n |\n 2|0|1|\n 0|\n |\n 0|1|2|0|1|\n 1|2|0|\n ' print(self._repr_diagram()) def content(self): '\n Return total number of blocks in ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0],[1,0],[2,1,0,2],[],[1]])\n sage: y.content()\n 8\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x.content()\n 13\n ' return sum((len(r) for r in self.data)) def number_of_parts(self): "\n Return the value of `\\mathscr{N}` on ``self``.\n\n In [KLRS2016]_, the statistic `\\mathscr{N}` was defined on elements in\n `\\mathcal{Y}(\\infty)` which counts how many parts are in the\n corresponding Kostant partition. Specifically, the computation of\n `\\mathscr{N}(Y)` is done using the following algorithm:\n\n - If `Y` has no rows whose right-most box is colored `n` and such that\n the length of this row is a multiple of `n+1`, then `\\mathscr{N}(Y)`\n is the total number of distinct rows in `Y`, not counting multiplicity.\n\n - Otherwise, search `Y` for the longest row such that the right-most box\n is colored `n` and such that the total number of boxes in the row is\n `k(n+1)` for some `k\\ge 1`. Replace this row by `n+1` distinct rows\n of length `k`, reordering all rows, if necessary, so that the result\n is a proper wall. (Note that the resulting wall may no longer be\n reduced.) Repeat the search and replace process for all other rows of\n the above form for each `k' < k`. Then `\\mathscr{N}(Y)` is the number\n of distinct rows, not counting multiplicity, in the wall resulting\n from this process.\n\n EXAMPLES::\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(3)\n sage: y = Y([[0],[],[],[],[0],[],[],[],[0]])\n sage: y.number_of_parts()\n 1\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(3)\n sage: y = Y([[0,3,2],[1,0],[],[],[0,3],[1,0],[],[],[0]])\n sage: y.number_of_parts()\n 4\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(2)\n sage: y = Y([[0,2,1],[1,0],[2,1,0,2,1,0,2,1,0],[],[2,1,0,2,1,0]])\n sage: y.number_of_parts()\n 8\n " n = (self.parent().cartan_type().rank() - 1) new = self.data[:] i = 0 while (i < len(new)): r = new[i] if ((r == []) or (r in new[(i + 1):])): new.pop(i) elif ((r[0] == n) and ((len(r) % (n + 1)) == 0)): for j in range((n + 1)): temp = [(k % (n + 1)) for k in range(((j + (len(r) / (n + 1))) - 1), (j - 1), (- 1))] if (temp not in new): new.insert((i + 1), temp) new.pop(i) else: i += 1 return len(new) def sum_of_weighted_row_lengths(self): '\n Return the value of `\\mathscr{M}` on ``self``.\n\n Let `\\mathcal{Y}_0 \\subset \\mathcal{Y}(\\infty)` be the set of\n generalized Young walls which have no rows whose right-most box is\n colored `n`. For `Y \\in \\mathcal{Y}_0`,\n\n .. MATH::\n\n \\mathscr{M}(Y) = \\sum_{i=1}^n (i+1)M_i(Y),\n\n where `M_i(Y)` is the number of nonempty rows in `Y` whose right-most\n box is colored `i-1`.\n\n EXAMPLES::\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(2)\n sage: y = Y([[0,2,1,0,2],[1,0,2],[],[0,2],[1,0],[],[0],[1,0]])\n sage: y.sum_of_weighted_row_lengths()\n 15\n ' n = (self.parent().cartan_type().rank() - 1) m = (lambda i: len([1 for r in self.data if (r and (r[0] == ((i - 1) % (n + 1))))])) for r in self.data: if (r and (r[0] == n)): raise ValueError('Statistic only valid for generalized Young walls in Y_0') return sum((((i + 1) * m(i)) for i in range(1, (n + 1)))) def e(self, i): '\n Return the application of the Kashiwara raising operator\n `e_i` on ``self``.\n\n This will remove the `i`-colored box corresponding to the\n rightmost `+` in ``self.signature(i)``.\n\n EXAMPLES::\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x.e(2)\n [[], [1, 0, 3, 2], [2, 1], [3, 2, 1, 0, 3, 2]]\n sage: _.e(2)\n [[], [1, 0, 3], [2, 1], [3, 2, 1, 0, 3, 2]]\n sage: _.e(2)\n [[], [1, 0, 3], [2, 1], [3, 2, 1, 0, 3]]\n sage: _.e(2)\n ' signature = self.generate_signature(i) raw_signature = signature[0] lastminus = signature[1].rfind('-') newdata = [] if (lastminus > (- 1)): deletionrow = raw_signature[lastminus][1] for r in range(self.rows): if (r == deletionrow): newdata.append(list(self.data[r][:(- 1)])) else: newdata.append(list(self.data[r])) return self.__class__(self.parent(), newdata) else: return None def f(self, i): '\n Return the application of the Kashiwara lowering operator\n `f_i` on ``self``.\n\n This will add an `i`-colored colored box to the site corresponding\n to the leftmost plus in ``self.signature(i)``.\n\n EXAMPLES::\n\n sage: hw = crystals.infinity.GeneralizedYoungWalls(2)([])\n sage: hw.f(1)\n [[], [1]]\n sage: _.f(2)\n [[], [1], [2]]\n sage: _.f(0)\n [[], [1, 0], [2]]\n sage: _.f(0)\n [[0], [1, 0], [2]]\n ' signature = self.generate_signature(i) raw_signature = signature[0] firstplus = signature[1].find('+') newdata = deepcopy(self.data) if (firstplus > (- 1)): additionrow = raw_signature[firstplus][1] newdata[additionrow].append(i) else: while ((len(newdata) % self.cartan_type().rank()) != i): newdata.append([]) newdata.append([i]) return self.__class__(self.parent(), newdata) def latex_large(self): "\n Generate LaTeX code for ``self`` but the output is larger.\n Requires TikZ.\n\n EXAMPLES::\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x.latex_large()\n '\\\\begin{tikzpicture}[baseline=5,scale=.45] \\n \\\\foreach \\\\x [count=\\\\s from 0] in \\n{{},{1,0,3,2},{2,1},{3,2,1,0,3,2},{},{},{2}} \\n{\\\\foreach \\\\y [count=\\\\t from 0] in \\\\x { \\\\node[font=\\\\scriptsize] at (-\\\\t,\\\\s) {$\\\\y$}; \\n \\\\draw (-\\\\t+.5,\\\\s+.5) to (-\\\\t-.5,\\\\s+.5); \\n \\\\draw (-\\\\t+.5,\\\\s-.5) to (-\\\\t-.5,\\\\s-.5); \\n \\\\draw (-\\\\t-.5,\\\\s-.5) to (-\\\\t-.5,\\\\s+.5); } \\n \\\\draw[-,thick] (.5,\\\\s+1) to (.5,-.5) to (-\\\\t-1,-.5); } \\n \\\\end{tikzpicture} \\n'\n " s = '' if (self.data == []): s += '\\emptyset' else: s += '\\begin{tikzpicture}[baseline=5,scale=.45] \n \\foreach \\x [count=\\s from 0] in \n' s += (('{' + ','.join(((('{' + ','.join((str(i) for i in r))) + '}') for r in self.data))) + '} \n') s += '{\\foreach \\y [count=\\t from 0] in \\x { \\node[font=\\scriptsize] at (-\\t,\\s) {$\\y$}; \n \\draw (-\\t+.5,\\s+.5) to (-\\t-.5,\\s+.5); \n \\draw (-\\t+.5,\\s-.5) to (-\\t-.5,\\s-.5); \n \\draw (-\\t-.5,\\s-.5) to (-\\t-.5,\\s+.5); } \n \\draw[-,thick] (.5,\\s+1) to (.5,-.5) to (-\\t-1,-.5); } \n \\end{tikzpicture} \n' return s def _latex_(self): "\n Generate LaTeX code for ``self``. Requires TikZ.\n\n EXAMPLES::\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x._latex_()\n '\\\\begin{tikzpicture}[baseline=5,scale=.25] \\\\foreach \\\\x [count=\\\\s from 0] in \\n{{},{1,0,3,2},{2,1},{3,2,1,0,3,2},{},{},{2}} \\n{\\\\foreach \\\\y [count=\\\\t from 0] in \\\\x { \\\\node[font=\\\\tiny] at (-\\\\t,\\\\s) {$\\\\y$}; \\n \\\\draw (-\\\\t+.5,\\\\s+.5) to (-\\\\t-.5,\\\\s+.5); \\n \\\\draw (-\\\\t+.5,\\\\s-.5) to (-\\\\t-.5,\\\\s-.5); \\n \\\\draw (-\\\\t-.5,\\\\s-.5) to (-\\\\t-.5,\\\\s+.5); } \\n \\\\draw[-] (.5,\\\\s+1) to (.5,-.5) to (-\\\\t-1,-.5); } \\n \\\\end{tikzpicture} \\n'\n " s = '' if (self.data == []): s += '\\emptyset' else: s += '\\begin{tikzpicture}[baseline=5,scale=.25] \\foreach \\x [count=\\s from 0] in \n' s += (('{' + ','.join(((('{' + ','.join((str(i) for i in r))) + '}') for r in self.data))) + '} \n') s += '{\\foreach \\y [count=\\t from 0] in \\x { \\node[font=\\tiny] at (-\\t,\\s) {$\\y$}; \n \\draw (-\\t+.5,\\s+.5) to (-\\t-.5,\\s+.5); \n \\draw (-\\t+.5,\\s-.5) to (-\\t-.5,\\s-.5); \n \\draw (-\\t-.5,\\s-.5) to (-\\t-.5,\\s+.5); } \n \\draw[-] (.5,\\s+1) to (.5,-.5) to (-\\t-1,-.5); } \n \\end{tikzpicture} \n' return s def weight(self, root_lattice=False): '\n Return the weight of ``self``.\n\n INPUT:\n\n - ``root_lattice`` -- boolean determining whether weight should appear\n in root lattice or not in extended affine weight lattice.\n\n EXAMPLES::\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x.weight()\n 2*Lambda[0] + Lambda[1] - 4*Lambda[2] + Lambda[3] - 2*delta\n sage: x.weight(root_lattice=True)\n -2*alpha[0] - 3*alpha[1] - 5*alpha[2] - 3*alpha[3]\n ' W = [] E = self.cartan_type().root_system().weight_lattice(extended=True) L = self.cartan_type().root_system().root_lattice() alpha = L.simple_roots() for r in self.data: for i in r: W.append(((- 1) * alpha[i])) if (not root_lattice): return E(sum(W)) return L(sum(W)) def epsilon(self, i): '\n Return the number of `i`-colored arrows in the `i`-string above\n ``self`` in the crystal graph.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: y.epsilon(1)\n 0\n sage: y.epsilon(2)\n 3\n sage: y.epsilon(0)\n 0\n ' if (i not in self.index_set()): raise ValueError('i must be in the index set') eps = 0 while True: self = self.e(i) if (self is None): break eps = (eps + 1) return eps def Epsilon(self): '\n Return `\\sum_{i=0}^n \\varepsilon_i(Y) \\Lambda_i` where `Y` is ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[0],[1,0,3,2],[2,1],[3,2,1,0,3,2],[0],[],[2]])\n sage: y.Epsilon()\n Lambda[0] + 3*Lambda[2]\n ' La = self.cartan_type().root_system().weight_lattice().fundamental_weights() return sum(((self.epsilon(i) * La[i]) for i in self.index_set())) def phi(self, i): '\n Return the value `\\varepsilon_i(Y) + \\langle h_i,\n \\mathrm{wt}(Y)\\rangle`, where `h_i` is the `i`-th simple\n coroot and `Y` is ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[0],[1,0,3,2],[2,1],[3,2,1,0,3,2],[0],[],[2]])\n sage: y.phi(1)\n 3\n sage: y.phi(2)\n -1\n ' h = self.parent().weight_lattice_realization().simple_coroots() return (self.epsilon(i) + self.weight(root_lattice=False).scalar(h[i])) def Phi(self): '\n Return `\\sum_{i=0}^n \\varphi_i(Y) \\Lambda_i` where `Y` is ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[0],[1,0,3,2],[2,1],[3,2,1,0,3,2],[0],[],[2]])\n sage: y.Phi()\n -Lambda[0] + 3*Lambda[1] - Lambda[2] + 3*Lambda[3]\n\n sage: x = crystals.infinity.GeneralizedYoungWalls(3)([[],[1,0,3,2],[2,1],[3,2,1,0,3,2],[],[],[2]])\n sage: x.Phi()\n 2*Lambda[0] + Lambda[1] - Lambda[2] + Lambda[3]\n ' La = self.cartan_type().root_system().weight_lattice(extended=True).fundamental_weights() return sum(((self.phi(i) * La[i]) for i in self.index_set())) def column(self, k): '\n Return the list of boxes from the ``k``-th column of ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[0],[1,0,3,2],[2,1],[3,2,1,0,3,2],[0],[],[2]])\n sage: y.column(2)\n [None, 0, 1, 2, None, None, None]\n\n sage: hw = crystals.infinity.GeneralizedYoungWalls(5)([])\n sage: hw.column(1)\n []\n ' C = [] for row in self.data: if ((k - 1) < len(row)): C.append(row[(k - 1)]) else: C.append(None) return C def a(self, i, k): '\n Return the number `a_i(k)` of `i`-colored boxes in the ``k``-th\n column of ``self``.\n\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[0],[1,0,3,2],[2,1],[3,2,1,0,3,2],[0],[],[2]])\n sage: y.a(1,2)\n 1\n sage: y.a(0,2)\n 1\n sage: y.a(3,2)\n 0\n ' A = [] for c in range(len(self.column(k))): if (self.column(k)[c] == i): A.append(self.column(k)[c]) return len(A) def in_highest_weight_crystal(self, La): "\n Return a boolean indicating if the generalized Young wall element\n is in the highest weight crystal cut out by the given highest weight\n ``La``.\n\n By Theorem 4.1 of [KS2010]_, a generalized Young wall `Y` represents a\n vertex in the highest weight crystal `Y(\\lambda)`, with\n `\\lambda = \\Lambda_{i_1} + \\Lambda_{i_2} + \\cdots + \\Lambda_{i_\\ell}`\n a dominant integral weight of level `\\ell > 0`, if it satisfies the\n following condition. For each positive integer `k`, if there exists\n `j \\in I` such that `a_j(k) - a_{j-1}(k) > 0`, then for some\n `p = 1, \\ldots, \\ell`,\n\n .. MATH::\n\n j + k \\equiv i_p + 1 \\bmod n+1 \\text{ and } a_j(k) - a_{j-1}(k)\n \\le \\lambda(h_{i_p}),\n\n where `\\{h_0, h_1, \\ldots, h_n\\}` is the set of simple coroots attached\n to `A_n^{(1)}`.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()[1]\n sage: GYW = crystals.infinity.GeneralizedYoungWalls(2)\n sage: y = GYW([[],[1,0],[2,1]])\n sage: y.in_highest_weight_crystal(La)\n True\n sage: x = GYW([[],[1],[2],[],[],[2],[],[],[2]])\n sage: x.in_highest_weight_crystal(La)\n False\n " if (La not in self.parent().weight_lattice_realization()): raise TypeError('Must be an element in the weight lattice realization') ac = self.parent().weight_lattice_realization().simple_coroots() n = self.cartan_type().classical().rank() index_set = self.index_set() for k in range(1, (self.cols + 1)): for j in index_set: if ((self.a(j, k) - self.a(((j - 1) % (n + 1)), k)) <= 0): continue else: p_not_found = True for p in index_set: if ((((j + k) % (n + 1)) == ((p + 1) % (n + 1))) and ((self.a(j, k) - self.a(((j - 1) % (n + 1)), k)) <= La.scalar(ac[p]))): p_not_found = False continue else: continue if p_not_found: return False return True
class InfinityCrystalOfGeneralizedYoungWalls(UniqueRepresentation, Parent): '\n The crystal `\\mathcal{Y}(\\infty)` of generalized Young walls of\n type `A_n^{(1)}` as defined in [KS2010]_.\n\n A generalized Young wall is a collection of boxes stacked on a fixed board,\n such that color of the box at the site located in the `j`-th row from the\n bottom and the `i`-th column from the right is `j-1 \\bmod n+1`. There are\n several growth conditions on elements in `Y \\in \\mathcal{Y}(\\infty)`:\n\n - Walls grow in rows from right to left. That is, for every box `y\\in Y`\n that is not in the rightmost column, there must be a box immediately to\n the right of `y`.\n\n - For all `p>q` such that `p-q \\equiv 0 \\bmod n+1`, the `p`-th row has\n most as many boxes as the `q`-th row.\n\n - There does not exist a column in the wall such that if one `i`-colored\n box, for every `i = 0,1,\\ldots,n`, is removed from that column, then the\n result satisfies the above conditions.\n\n There is a crystal structure on `\\mathcal{Y}(\\infty)` defined as follows.\n Define maps\n\n .. MATH::\n\n e_i,\\ f_i \\colon \\mathcal{Y}(\\infty)\n \\longrightarrow \\mathcal{Y}(\\infty) \\sqcup \\{0\\}, \\qquad\n \\varepsilon_i,\\ \\varphi_i \\colon \\mathcal{Y}(\\infty)\n \\longrightarrow \\ZZ, \\qquad\n \\mathrm{wt}\\colon \\mathcal{Y}(\\infty) \\longrightarrow\n \\bigoplus_{i=0}^n \\ZZ \\Lambda_i \\oplus \\ZZ \\delta,\n\n by\n\n .. MATH::\n\n \\mathrm{wt}(Y) = -\\sum_{i=0}^n m_i(Y) \\alpha_i,\n\n where `m_i(Y)` is the number of `i`-boxes in `Y`, `\\varepsilon_i(Y)`\n is the number of `-` in the `i`-signature of `Y`, and\n\n .. MATH::\n\n \\varphi_i(Y) = \\varepsilon_i(Y) + \\langle h_i, \\mathrm{wt}(Y) \\rangle.\n\n See :meth:`GeneralizedYoungWall.e()`, :meth:`GeneralizedYoungWall.f()`,\n and :meth:`GeneralizedYoungWall.signature()` for more about\n `e_i`, `f_i`, and `i`-signatures.\n\n\n INPUT:\n\n - ``n`` -- type `A_n^{(1)}`\n\n EXAMPLES::\n\n sage: Yinf = crystals.infinity.GeneralizedYoungWalls(3)\n sage: y = Yinf([[0],[1,0,3,2],[],[3,2,1],[0],[1,0]])\n sage: y.pp()\n 0|1|\n 0|\n 1|2|3|\n |\n 2|3|0|1|\n 0|\n sage: y.weight(root_lattice=True)\n -4*alpha[0] - 3*alpha[1] - 2*alpha[2] - 2*alpha[3]\n sage: y.f(0)\n [[0], [1, 0, 3, 2], [], [3, 2, 1], [0], [1, 0], [], [], [0]]\n sage: y.e(0).pp()\n 0|1|\n |\n 1|2|3|\n |\n 2|3|0|1|\n 0|\n\n To display the crystal down to depth 3::\n\n sage: S = Yinf.subcrystal(max_depth=3)\n sage: G = Yinf.digraph(subset=S) # long time\n sage: view(G) # not tested\n ' @staticmethod def __classcall_private__(cls, n, category=None): '\n Normalize input to ensure a unique representation.\n\n INPUT:\n\n - ``n`` -- type `A_n^{(1)}`\n\n EXAMPLES::\n\n sage: Yinf = crystals.infinity.GeneralizedYoungWalls(3)\n sage: Yinf2 = crystals.infinity.GeneralizedYoungWalls(int(3))\n sage: Yinf is Yinf2\n True\n ' return super().__classcall__(cls, n, category) def __init__(self, n, category): '\n EXAMPLES::\n\n sage: Yinf = crystals.infinity.GeneralizedYoungWalls(3)\n sage: TestSuite(Yinf).run()\n ' self._cartan_type = CartanType(['A', n, 1]) if (category is None): category = (HighestWeightCrystals(), InfiniteEnumeratedSets()) Parent.__init__(self, category=category) self.module_generators = (self.element_class(self, []),) Element = GeneralizedYoungWall def _element_constructor_(self, data): '\n Construct an element of ``self`` from ``data``.\n\n INPUT:\n\n - ``data`` -- a multilist\n\n EXAMPLES::\n\n sage: GYW = crystals.infinity.GeneralizedYoungWalls(2)\n sage: y = GYW([[],[1,0],[2,1]]) # indirect doctest\n sage: y\n [[], [1, 0], [2, 1]]\n ' return self.element_class(self, data) def _repr_(self): "\n EXAMPLES::\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(4)\n sage: Y\n Crystal of generalized Young walls of type ['A', 4, 1]\n " return 'Crystal of generalized Young walls of type {}'.format(self._cartan_type)
class CrystalOfGeneralizedYoungWallsElement(GeneralizedYoungWall): '\n Element of the highest weight crystal of generalized Young walls.\n ' def e(self, i): "\n Compute the action of `e_i` restricted to the highest weight crystal.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()[1]\n sage: hwy = crystals.GeneralizedYoungWalls(2,La)([[],[1,0],[2,1]])\n sage: hwy.e(1)\n [[], [1, 0], [2]]\n sage: hwy.e(2)\n sage: hwy.e(3)\n " ret = GeneralizedYoungWall.e(self, i) if (ret is None): return None if ret.in_highest_weight_crystal(self.parent().hw): return self.__class__(self.parent(), ret.data) return None def f(self, i): "\n Compute the action of `f_i` restricted to the highest weight crystal.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()[1]\n sage: GYW = crystals.infinity.GeneralizedYoungWalls(2)\n sage: y = GYW([[],[1,0],[2,1]])\n sage: y.f(1)\n [[], [1, 0], [2, 1], [], [1]]\n sage: hwy = crystals.GeneralizedYoungWalls(2,La)([[],[1,0],[2,1]])\n sage: hwy.f(1)\n " ret = GeneralizedYoungWall.f(self, i) if ret.in_highest_weight_crystal(self.parent().hw): return self.__class__(self.parent(), ret.data) return None def weight(self): "\n Return the weight of ``self`` in the highest weight crystal as an\n element of the weight lattice `\\bigoplus_{i=0}^n \\ZZ \\Lambda_i`.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()[1]\n sage: hwy = crystals.GeneralizedYoungWalls(2,La)([[],[1,0],[2,1]])\n sage: hwy.weight()\n Lambda[0] - Lambda[1] + Lambda[2] - delta\n " return self.parent().weight_lattice_realization()((self.parent().hw + GeneralizedYoungWall.weight(self))) def phi(self, i): "\n Return the value `\\varepsilon_i(Y) + \\langle h_i,\n \\mathrm{wt}(Y)\\rangle`, where `h_i` is the `i`-th simple\n coroot and `Y` is ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',3,1]).weight_lattice(extended=True).fundamental_weights()\n sage: y = crystals.GeneralizedYoungWalls(3,La[0])([])\n sage: y.phi(1)\n 0\n sage: y.phi(2)\n 0\n " h = self.parent().weight_lattice_realization().simple_coroots() return (self.epsilon(i) + self.weight().scalar(h[i]))
class CrystalOfGeneralizedYoungWalls(InfinityCrystalOfGeneralizedYoungWalls): "\n The crystal `\\mathcal{Y}(\\lambda)` of generalized Young walls of the given\n type with highest weight `\\lambda`.\n\n These were characterized in Theorem 4.1 of [KS2010]_.\n See :meth:`GeneralizedYoungWall.in_highest_weight_crystal()`.\n\n INPUT:\n\n - ``n`` -- type `A_n^{(1)}`\n\n - ``weight`` -- dominant integral weight\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',3,1]).weight_lattice(extended=True).fundamental_weights()[1]\n sage: YLa = crystals.GeneralizedYoungWalls(3,La)\n sage: y = YLa([[0],[1,0,3,2,1],[2,1,0],[3]])\n sage: y.pp()\n 3|\n 0|1|2|\n 1|2|3|0|1|\n 0|\n sage: y.weight()\n -Lambda[0] + Lambda[2] + Lambda[3] - 3*delta\n sage: y.in_highest_weight_crystal(La)\n True\n sage: y.f(1)\n [[0], [1, 0, 3, 2, 1], [2, 1, 0], [3], [], [1]]\n sage: y.f(1).f(1)\n sage: yy = crystals.infinity.GeneralizedYoungWalls(3)([[0], [1, 0, 3, 2, 1], [2, 1, 0], [3], [], [1]])\n sage: yy.f(1)\n [[0], [1, 0, 3, 2, 1], [2, 1, 0], [3], [], [1], [], [], [], [1]]\n sage: yyy = yy.f(1)\n sage: yyy.in_highest_weight_crystal(La)\n False\n\n sage: LS = crystals.LSPaths(['A',3,1],[1,0,0,0])\n sage: C = LS.subcrystal(max_depth=4)\n sage: G = LS.digraph(subset=C)\n sage: P = RootSystem(['A',3,1]).weight_lattice(extended=True)\n sage: La = P.fundamental_weights()\n sage: YW = crystals.GeneralizedYoungWalls(3,La[0])\n sage: CW = YW.subcrystal(max_depth=4)\n sage: GW = YW.digraph(subset=CW)\n sage: GW.is_isomorphic(G,edge_labels=True)\n True\n\n To display the crystal down to a specified depth::\n\n sage: S = YLa.subcrystal(max_depth=4)\n sage: G = YLa.digraph(subset=S)\n sage: view(G) # not tested\n " @staticmethod def __classcall_private__(cls, n, La): "\n EXAMPLES::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()[2]\n sage: Al = RootSystem(['A',2,1]).weight_lattice(extended=True).monomial(2)\n sage: Y = crystals.GeneralizedYoungWalls(2,La)\n sage: Y1 = crystals.GeneralizedYoungWalls(int(2),Al)\n sage: Y is Y1\n True\n " La = RootSystem(['A', n, 1]).weight_lattice(extended=True)(La) return super().__classcall__(cls, n, La) def __init__(self, n, La): '\n EXAMPLES::\n\n sage: La = RootSystem([\'A\',2,1]).weight_lattice(extended=True).fundamental_weights()[1]\n sage: YLa = crystals.GeneralizedYoungWalls(2,La)\n\n We skip the two tests because they take a very long time::\n\n sage: TestSuite(YLa).run(skip=["_test_enumerated_set_contains","_test_stembridge_local_axioms"]) # long time\n ' InfinityCrystalOfGeneralizedYoungWalls.__init__(self, n, category=(RegularCrystals(), HighestWeightCrystals(), InfiniteEnumeratedSets())) self.hw = La Element = CrystalOfGeneralizedYoungWallsElement def _repr_(self): "\n EXAMPLES::\n\n sage: La = RootSystem(['A',5,1]).weight_lattice(extended=True).fundamental_weights()[2]\n sage: Y = crystals.GeneralizedYoungWalls(5,La)\n sage: Y\n Highest weight crystal of generalized Young walls of Cartan type ['A', 5, 1] and highest weight Lambda[2]\n " return 'Highest weight crystal of generalized Young walls of Cartan type {1!s} and highest weight {0!s}'.format(self.hw, self._cartan_type) def __iter__(self): '\n EXAMPLES::\n\n sage: y = crystals.infinity.GeneralizedYoungWalls(3)([[0],[1,0,3,2],[2,1],[3,2,1,0,3,2],[0],[],[2]])\n sage: x = y.__iter__()\n sage: next(x)\n [0]\n ' for c in super().__iter__(): if c.in_highest_weight_crystal(self.hw): (yield c)
def HighestWeightCrystal(dominant_weight, model=None): '\n Return the highest weight crystal of highest weight ``dominant_weight``\n of the given ``model``.\n\n INPUT:\n\n - ``dominant_weight`` -- a dominant weight\n - ``model`` -- (optional) if not specified, then we have the following\n default models:\n\n * types `A_n, B_n, C_n, D_n, G_2` - :class:`tableaux\n <sage.combinat.crystals.tensor_product.CrystalOfTableaux>`\n * types `E_{6,7}` - :class:`type E finite dimensional crystal\n <FiniteDimensionalHighestWeightCrystal_TypeE>`\n * all other types - :class:`LS paths\n <sage.combinat.crystals.littelmann_path.CrystalOfLSPaths>`\n\n otherwise can be one of the following:\n\n * ``\'Tableaux\'`` - :class:`KN tableaux\n <sage.combinat.crystals.tensor_product.CrystalOfTableaux>`\n * ``\'TypeE\'`` - :class:`type E finite dimensional crystal\n <FiniteDimensionalHighestWeightCrystal_TypeE>`\n * ``\'NakajimaMonomials\'`` - :class:`Nakajima monomials\n <sage.combinat.crystals.monomial_crystals.CrystalOfNakajimaMonomials>`\n * ``\'LSPaths\'`` - :class:`LS paths\n <sage.combinat.crystals.littelmann_path.CrystalOfLSPaths>`\n * ``\'AlcovePaths\'`` - :class:`alcove paths\n <sage.combinat.crystals.alcove_path.CrystalOfAlcovePaths>`\n * ``\'GeneralizedYoungWalls\'`` - :class:`generalized Young walls\n <sage.combinat.crystals.generalized_young_walls.CrystalOfGeneralizedYoungWalls>`\n * ``\'RiggedConfigurations\'`` - :class:`rigged configurations\n <sage.combinat.rigged_configurations.rc_crystal.CrystalOfRiggedConfigurations>`\n\n EXAMPLES::\n\n sage: La = RootSystem([\'A\',2]).weight_lattice().fundamental_weights()\n sage: wt = La[1] + La[2]\n sage: crystals.HighestWeight(wt)\n The crystal of tableaux of type [\'A\', 2] and shape(s) [[2, 1]]\n\n sage: La = RootSystem([\'C\',2]).weight_lattice().fundamental_weights()\n sage: wt = 5*La[1] + La[2]\n sage: crystals.HighestWeight(wt)\n The crystal of tableaux of type [\'C\', 2] and shape(s) [[6, 1]]\n\n sage: La = RootSystem([\'B\',2]).weight_lattice().fundamental_weights()\n sage: wt = La[1] + La[2]\n sage: crystals.HighestWeight(wt)\n The crystal of tableaux of type [\'B\', 2] and shape(s) [[3/2, 1/2]]\n\n Some type `E` examples::\n\n sage: C = CartanType([\'E\',6])\n sage: La = C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(La[1])\n sage: T.cardinality()\n 27\n sage: T = crystals.HighestWeight(La[6])\n sage: T.cardinality()\n 27\n sage: T = crystals.HighestWeight(La[2])\n sage: T.cardinality()\n 78\n sage: T = crystals.HighestWeight(La[4])\n sage: T.cardinality()\n 2925\n sage: T = crystals.HighestWeight(La[3])\n sage: T.cardinality()\n 351\n sage: T = crystals.HighestWeight(La[5])\n sage: T.cardinality()\n 351\n\n sage: C = CartanType([\'E\',7])\n sage: La = C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(La[1])\n sage: T.cardinality()\n 133\n sage: T = crystals.HighestWeight(La[2])\n sage: T.cardinality()\n 912\n sage: T = crystals.HighestWeight(La[3])\n sage: T.cardinality()\n 8645\n sage: T = crystals.HighestWeight(La[4])\n sage: T.cardinality()\n 365750\n sage: T = crystals.HighestWeight(La[5])\n sage: T.cardinality()\n 27664\n sage: T = crystals.HighestWeight(La[6])\n sage: T.cardinality()\n 1539\n sage: T = crystals.HighestWeight(La[7])\n sage: T.cardinality()\n 56\n\n An example with an affine type::\n\n sage: C = CartanType([\'C\',2,1])\n sage: La = C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(La[1])\n sage: sorted(T.subcrystal(max_depth=3), key=str)\n [(-Lambda[0] + 3*Lambda[1] - Lambda[2] - delta,),\n (-Lambda[0] + Lambda[1] + Lambda[2] - delta,),\n (-Lambda[1] + 2*Lambda[2] - delta,),\n (2*Lambda[0] - Lambda[1],),\n (Lambda[0] + Lambda[1] - Lambda[2],),\n (Lambda[0] - Lambda[1] + Lambda[2],),\n (Lambda[1],)]\n\n Using the various models::\n\n sage: La = RootSystem([\'F\',4]).weight_lattice().fundamental_weights()\n sage: wt = La[1] + La[4]\n sage: crystals.HighestWeight(wt)\n The crystal of LS paths of type [\'F\', 4] and weight Lambda[1] + Lambda[4]\n sage: crystals.HighestWeight(wt, model=\'NakajimaMonomials\')\n Highest weight crystal of modified Nakajima monomials of\n Cartan type [\'F\', 4] and highest weight Lambda[1] + Lambda[4]\n sage: crystals.HighestWeight(wt, model=\'AlcovePaths\')\n Highest weight crystal of alcove paths of type [\'F\', 4] and weight Lambda[1] + Lambda[4]\n sage: crystals.HighestWeight(wt, model=\'RiggedConfigurations\')\n Crystal of rigged configurations of type [\'F\', 4] and weight Lambda[1] + Lambda[4]\n sage: La = RootSystem([\'A\',3,1]).weight_lattice().fundamental_weights()\n sage: wt = La[0] + La[2]\n sage: crystals.HighestWeight(wt, model=\'GeneralizedYoungWalls\')\n Highest weight crystal of generalized Young walls of\n Cartan type [\'A\', 3, 1] and highest weight Lambda[0] + Lambda[2]\n\n TESTS:\n\n Check that the correct crystal is constructed for the fundamental weights::\n\n sage: for ct in CartanType.samples(finite=True, crystallographic=True): # long time\n ....: L = ct.root_system().weight_lattice()\n ....: La = L.fundamental_weights()\n ....: for model in [\'Tableaux\', \'NakajimaMonomials\', \'AlcovePaths\', \'RiggedConfigurations\']:\n ....: if model == \'Tableaux\' and ct.type() in ["E", "F"]:\n ....: continue\n ....: for wt in La:\n ....: C = crystals.HighestWeight(wt, model=model)\n ....: assert L.weyl_dimension(wt) == C.cardinality(), "wrong cardinality in %s, weight %s" % (ct, wt)\n ....: assert C.highest_weight_vector().weight() == wt, "wrong weight in %s, weight %s" % (ct, wt)\n\n Same thing for weights constructed from the simple roots::\n\n sage: for ct in CartanType.samples(finite=True, crystallographic=True):\n ....: L = ct.root_system().root_space()\n ....: La = L.fundamental_weights_from_simple_roots()\n ....: for model in [\'Tableaux\', \'NakajimaMonomials\', \'AlcovePaths\', \'RiggedConfigurations\']:\n ....: if model == \'Tableaux\' and ct.type() in ["E", "F"]:\n ....: continue\n ....: for wt in La:\n ....: C1 = crystals.HighestWeight(wt.to_ambient().to_weight_space(ZZ), model=model)\n ....: C2 = crystals.HighestWeight(wt, model=model)\n ....: assert C1 == C2\n\n ' cartan_type = dominant_weight.parent().cartan_type() if (model is None): if cartan_type.is_finite(): if (cartan_type.type() == 'E'): model = 'TypeE' elif (cartan_type.type() in ['A', 'B', 'C', 'D', 'G']): model = 'Tableaux' else: model = 'LSPaths' else: model = 'LSPaths' if cartan_type.is_finite(): dominant_weight = dominant_weight.to_ambient().to_weight_space(ZZ) if (model == 'Tableaux'): sh = dominant_weight.to_ambient().to_vector() if (cartan_type.type() == 'G'): sh = (- sh)[2:0:(- 1)] return CrystalOfTableaux(cartan_type, shape=sh) if (model == 'TypeE'): if ((not cartan_type.is_finite()) or (cartan_type.type() != 'E')): raise ValueError('only for finite type E') if (cartan_type.rank() == 6): return FiniteDimensionalHighestWeightCrystal_TypeE6(dominant_weight) elif (cartan_type.rank() == 7): return FiniteDimensionalHighestWeightCrystal_TypeE7(dominant_weight) raise NotImplementedError if (model == 'NakajimaMonomials'): return CrystalOfNakajimaMonomials(cartan_type, dominant_weight) if (model == 'LSPaths'): if cartan_type.is_affine(): P = dominant_weight.parent().root_system.weight_space(extended=True) else: P = dominant_weight.parent().root_system.weight_space() wt = P.sum_of_terms(((i, c) for (i, c) in dominant_weight)) return CrystalOfLSPaths(wt) if (model == 'AlcovePaths'): return CrystalOfAlcovePaths(dominant_weight, highest_weight_crystal=True) if (model == 'GeneralizedYoungWalls'): if (not cartan_type.is_affine()): raise ValueError('only for affine types') if (cartan_type.type() != 'A'): raise NotImplementedError('only for affine type A') P = dominant_weight.parent().root_system.weight_lattice(extended=True) wt = P.sum_of_terms(((i, c) for (i, c) in dominant_weight)) return CrystalOfGeneralizedYoungWalls((cartan_type.rank() - 1), wt) if (model == 'RiggedConfigurations'): return CrystalOfRiggedConfigurations(cartan_type, dominant_weight) raise ValueError('invalid model')
class FiniteDimensionalHighestWeightCrystal_TypeE(TensorProductOfCrystals): '\n Commonalities for all finite dimensional type `E` highest weight crystals.\n\n Subclasses should setup an attribute column_crystal in their\n ``__init__`` method before calling the ``__init__`` method of this class.\n ' def __init__(self, dominant_weight): "\n EXAMPLES::\n\n sage: C = CartanType(['E',6])\n sage: La = C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(2*La[2])\n sage: T.cartan_type()\n ['E', 6]\n sage: T.module_generators\n [[[(2, -1), (1,)], [(2, -1), (1,)]]]\n sage: T.cardinality()\n 2430\n sage: T = crystals.HighestWeight(La[2])\n sage: T.cardinality()\n 78\n " self._cartan_type = dominant_weight.parent().cartan_type() self._highest_weight = dominant_weight assert dominant_weight.is_dominant() self.rename() Parent.__init__(self, category=ClassicalCrystals()) self.module_generators = [self.module_generator()] def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: C = CartanType(['E',6])\n sage: La = C.root_system().weight_lattice().fundamental_weights()\n sage: crystals.HighestWeight(2*La[2])\n Finite dimensional highest weight crystal of type ['E', 6] and highest weight 2*Lambda[2]\n " return 'Finite dimensional highest weight crystal of type {} and highest weight {}'.format(self._cartan_type, self._highest_weight) Element = TensorProductOfRegularCrystalsElement def module_generator(self): "\n This yields the module generator (or highest weight element) of the classical\n crystal of given dominant weight in self.\n\n EXAMPLES::\n\n sage: C=CartanType(['E',6])\n sage: La=C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(La[2])\n sage: T.module_generator()\n [[(2, -1), (1,)]]\n sage: T = crystals.HighestWeight(0*La[2])\n sage: T.module_generator()\n []\n\n sage: C=CartanType(['E',7])\n sage: La=C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(La[1])\n sage: T.module_generator()\n [[(-7, 1), (7,)]]\n " dominant_weight = self._highest_weight tensor = sum((([self.column_crystal[i]] * dominant_weight.coefficient(i)) for i in dominant_weight.support()), []) return self._element_constructor_(*[B.module_generators[0] for B in tensor])
class FiniteDimensionalHighestWeightCrystal_TypeE6(FiniteDimensionalHighestWeightCrystal_TypeE): "\n Class of finite dimensional highest weight crystals of type `E_6`.\n\n EXAMPLES::\n\n sage: C=CartanType(['E',6])\n sage: La=C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(La[2]); T\n Finite dimensional highest weight crystal of type ['E', 6] and highest weight Lambda[2]\n sage: B1 = T.column_crystal[1]; B1\n The crystal of letters for type ['E', 6]\n sage: B6 = T.column_crystal[6]; B6\n The crystal of letters for type ['E', 6] (dual)\n sage: t = T(B6([-1]),B1([-1,3])); t\n [(-1,), (-1, 3)]\n sage: [t.epsilon(i) for i in T.index_set()]\n [2, 0, 0, 0, 0, 0]\n sage: [t.phi(i) for i in T.index_set()]\n [0, 0, 1, 0, 0, 0]\n sage: TestSuite(t).run()\n " def __init__(self, dominant_weight): "\n EXAMPLES::\n\n sage: C=CartanType(['E',6])\n sage: La=C.root_system().weight_lattice().fundamental_weights()\n sage: p2=2*La[2]\n sage: p1=La[2]\n sage: p0=0*La[2]\n sage: T = crystals.HighestWeight(0*La[2])\n sage: T.cardinality()\n 1\n sage: T = crystals.HighestWeight(La[2])\n sage: T.cardinality()\n 78\n sage: T = crystals.HighestWeight(2*La[2])\n sage: T.cardinality()\n 2430\n " B1 = CrystalOfLetters(['E', 6]) B6 = CrystalOfLetters(['E', 6], dual=True) self.column_crystal = {1: B1, 6: B6, 4: TensorProductOfCrystals(B1, B1, B1, generators=[[B1([(- 3), 4]), B1([(- 1), 3]), B1([1])]]), 3: TensorProductOfCrystals(B1, B1, generators=[[B1([(- 1), 3]), B1([1])]]), 5: TensorProductOfCrystals(B6, B6, generators=[[B6([5, (- 6)]), B6([6])]]), 2: TensorProductOfCrystals(B6, B1, generators=[[B6([2, (- 1)]), B1([1])]])} FiniteDimensionalHighestWeightCrystal_TypeE.__init__(self, dominant_weight)
class FiniteDimensionalHighestWeightCrystal_TypeE7(FiniteDimensionalHighestWeightCrystal_TypeE): "\n Class of finite dimensional highest weight crystals of type `E_7`.\n\n EXAMPLES::\n\n sage: C=CartanType(['E',7])\n sage: La=C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(La[1])\n sage: T.cardinality()\n 133\n sage: B7 = T.column_crystal[7]; B7\n The crystal of letters for type ['E', 7]\n sage: t = T(B7([-5, 6]), B7([-2, 3])); t\n [(-5, 6), (-2, 3)]\n sage: [t.epsilon(i) for i in T.index_set()]\n [0, 1, 0, 0, 1, 0, 0]\n sage: [t.phi(i) for i in T.index_set()]\n [0, 0, 1, 0, 0, 1, 0]\n sage: TestSuite(t).run()\n " def __init__(self, dominant_weight): "\n EXAMPLES::\n\n sage: C=CartanType(['E',7])\n sage: La=C.root_system().weight_lattice().fundamental_weights()\n sage: T = crystals.HighestWeight(0*La[1])\n sage: T.cardinality()\n 1\n sage: T = crystals.HighestWeight(La[1])\n sage: T.cardinality()\n 133\n sage: T = crystals.HighestWeight(2*La[1])\n sage: T.cardinality()\n 7371\n " B = CrystalOfLetters(['E', 7]) self.column_crystal = {7: B, 1: TensorProductOfCrystals(B, B, generators=[[B([(- 7), 1]), B([7])]]), 2: TensorProductOfCrystals(B, B, B, generators=[[B([(- 1), 2]), B([(- 7), 1]), B([7])]]), 3: TensorProductOfCrystals(B, B, B, B, generators=[[B([(- 2), 3]), B([(- 1), 2]), B([(- 7), 1]), B([7])]]), 4: TensorProductOfCrystals(B, B, B, B, generators=[[B([(- 5), 4]), B([(- 6), 5]), B([(- 7), 6]), B([7])]]), 5: TensorProductOfCrystals(B, B, B, generators=[[B([(- 6), 5]), B([(- 7), 6]), B([7])]]), 6: TensorProductOfCrystals(B, B, generators=[[B([(- 7), 6]), B([7])]])} FiniteDimensionalHighestWeightCrystal_TypeE.__init__(self, dominant_weight)
class InducedCrystal(UniqueRepresentation, Parent): "\n A crystal induced from an injection.\n\n Let `X` be a set and let `C` be crystal and consider any injection\n `\\Phi : X \\to C`. We induce a crystal structure on `X` by considering\n `\\Phi` to be a crystal morphism.\n\n Alternatively we can induce a crystal structure on some (sub)set of `X`\n by considering an injection `\\Phi : C \\to X` considered as a crystal\n morphism. This form is also useful when the set `X` is not explicitly\n known.\n\n INPUT:\n\n - ``X`` -- the base set\n - ``phi`` -- the map `\\Phi`\n - ``inverse`` -- (optional) the inverse map `\\Phi^{-1}`\n - ``from_crystal`` -- (default: ``False``) if the induced structure is\n of the second type `\\Phi : C \\to X`\n\n EXAMPLES:\n\n We construct a crystal structure of Gelfand-Tsetlin patterns by going\n through their bijection with semistandard tableaux::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,3))\n sage: G = GelfandTsetlinPatterns(4, 3)\n sage: phi = lambda x: D(x.to_tableau())\n sage: phi_inv = lambda x: G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: I.digraph().is_isomorphic(D.digraph(), edge_labels=True)\n True\n\n Now we construct the above example but inducing the structure going the\n other way (from tableaux to Gelfand-Tsetlin patterns). This can also\n give us more information coming from the crystal. ::\n\n sage: D2 = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G2 = GelfandTsetlinPatterns(4, 1)\n sage: phi2 = lambda x: D2(x.to_tableau())\n sage: phi2_inv = lambda x: G2(x.to_tableau())\n sage: I2 = crystals.Induced(D2, phi2_inv, phi2, from_crystal=True)\n sage: I2.module_generators\n ([[0, 0, 0, 0], [0, 0, 0], [0, 0], [0]],\n [[1, 0, 0, 0], [1, 0, 0], [1, 0], [1]],\n [[1, 1, 0, 0], [1, 1, 0], [1, 1], [1]],\n [[1, 1, 1, 0], [1, 1, 1], [1, 1], [1]],\n [[1, 1, 1, 1], [1, 1, 1], [1, 1], [1]])\n\n We check an example when the codomain is larger than the domain\n (although here the crystal structure is trivial)::\n\n sage: P = Permutations(4)\n sage: D = crystals.Tableaux(['A',3], shapes=Partitions(4))\n sage: T = crystals.TensorProduct(D, D)\n sage: phi = lambda p: T(D(RSK(p)[0]), D(RSK(p)[1]))\n sage: phi_inv = lambda d: RSK_inverse(d[0].to_tableau(), d[1].to_tableau(), output='permutation')\n sage: all(phi_inv(phi(p)) == p for p in P) # Check it really is the inverse\n True\n sage: I = crystals.Induced(P, phi, phi_inv)\n sage: I.digraph()\n Digraph on 24 vertices\n\n We construct an example without a specified inverse map::\n\n sage: X = Words(2,4)\n sage: L = crystals.Letters(['A',1])\n sage: T = crystals.TensorProduct(*[L]*4)\n sage: Phi = lambda x : T(*[L(i) for i in x])\n sage: I = crystals.Induced(X, Phi)\n sage: I.digraph()\n Digraph on 16 vertices\n " @staticmethod def __classcall_private__(cls, X, phi, inverse=None, from_crystal=False): "\n Normalize input to ensure a unique representation.\n\n TESTS::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,3))\n sage: G = GelfandTsetlinPatterns(4, 3)\n sage: phi = lambda x: D(x.to_tableau())\n sage: phi_inv = lambda x: G(x.to_tableau())\n sage: I1 = crystals.Induced(G, phi, phi_inv)\n sage: I2 = crystals.Induced(G, phi, phi_inv)\n sage: I1 is I2\n True\n " if from_crystal: return InducedFromCrystal(X, phi, inverse) return super().__classcall__(cls, X, phi, inverse) def __init__(self, X, phi, inverse): "\n Initialize ``self``.\n\n TESTS:\n\n Note that pickling only works when the input functions\n can be pickled::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return D(x.to_tableau())\n sage: def phi_inv(x): return G(x.to_tableau())\n sage: import __main__\n sage: __main__.phi = phi\n sage: __main__.phi_inv = phi_inv\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: TestSuite(I).run()\n " try: codomain = phi.codomain() except AttributeError: codomain = phi(X.an_element()).parent() self._set = X self._phi = phi if (inverse is None): try: inverse = (~ self._phi) except (TypeError, ValueError): try: inverse = self._phi.section() except AttributeError: if (X.cardinality() == float('inf')): raise ValueError('the inverse map must be defined for infinite sets') self._preimage = {} for x in X: y = phi(x) if (y in self._preimage): raise ValueError('the map is not injective') self._preimage[y] = x inverse = self._preimage.__getitem__ self._inverse = inverse self._cartan_type = codomain.cartan_type() Parent.__init__(self, category=codomain.category()) self.module_generators = self def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return D(x.to_tableau())\n sage: def phi_inv(x): return G(x.to_tableau())\n sage: crystals.Induced(G, phi, phi_inv)\n Crystal of Gelfand-Tsetlin patterns of width 4 and max value 1\n induced by <function phi at 0x...>\n " return 'Crystal of {} induced by {}'.format(self._set, self._phi) def _element_constructor_(self, x): "\n Construct an element of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return D(x.to_tableau())\n sage: def phi_inv(x): return G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: I([[1,1,0,0],[1,0,0],[1,0],[1]])\n [[1, 1, 0, 0], [1, 0, 0], [1, 0], [1]]\n sage: I(D(3,2,1))\n [[1, 1, 1, 0], [1, 1, 1], [1, 1], [1]]\n sage: I([[1,1,0,0],[1,0,0],[0,1],[1]])\n Traceback (most recent call last):\n ...\n TypeError: unable to convert [[1, 1, 0, 0], [1, 0, 0], [0, 1], [1]] to Crystal of Gelfand-Tsetlin patterns of width 4 and max value 1 induced by <function phi at 0x...>\n " if (x in self._set): return self.element_class(self, self._set(x)) try: return self.element_class(self, self._inverse(x)) except (TypeError, ValueError, AttributeError): raise TypeError('unable to convert {!r} to {}'.format(x, self)) def __contains__(self, x): "\n Check if ``x`` is in ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return D(x.to_tableau())\n sage: def phi_inv(x): return G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: all(g in I for g in G)\n True\n sage: [[1,1,0,0],[1,0,0],[1,0],[1]] in I\n True\n sage: [[1,1,0,0],[1,0,0],[0,1],[1]] in I\n False\n " if isinstance(x, InducedCrystal.Element): return (x.parent() == self) return (x in self._set) def __iter__(self): "\n Iterate over ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return D(x.to_tableau())\n sage: def phi_inv(x): return G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: sorted([x for x in I])\n [[[0, 0, 0, 0], [0, 0, 0], [0, 0], [0]],\n [[1, 0, 0, 0], [0, 0, 0], [0, 0], [0]],\n [[1, 0, 0, 0], [1, 0, 0], [0, 0], [0]],\n [[1, 0, 0, 0], [1, 0, 0], [1, 0], [0]],\n [[1, 0, 0, 0], [1, 0, 0], [1, 0], [1]],\n [[1, 1, 0, 0], [1, 0, 0], [0, 0], [0]],\n [[1, 1, 0, 0], [1, 0, 0], [1, 0], [0]],\n [[1, 1, 0, 0], [1, 0, 0], [1, 0], [1]],\n [[1, 1, 0, 0], [1, 1, 0], [1, 0], [0]],\n [[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]],\n [[1, 1, 0, 0], [1, 1, 0], [1, 1], [1]],\n [[1, 1, 1, 0], [1, 1, 0], [1, 0], [0]],\n [[1, 1, 1, 0], [1, 1, 0], [1, 0], [1]],\n [[1, 1, 1, 0], [1, 1, 0], [1, 1], [1]],\n [[1, 1, 1, 0], [1, 1, 1], [1, 1], [1]],\n [[1, 1, 1, 1], [1, 1, 1], [1, 1], [1]]]\n " for x in self._set: (yield self.element_class(self, x)) def cardinality(self): "\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: P = Permutations(4)\n sage: D = crystals.Tableaux(['A',3], shapes=Partitions(4))\n sage: T = crystals.TensorProduct(D, D)\n sage: phi = lambda p: T(D(RSK(p)[0]), D(RSK(p)[1]))\n sage: phi_inv = lambda d: RSK_inverse(d[0].to_tableau(), d[1].to_tableau(), output='permutation')\n sage: I = crystals.Induced(P, phi, phi_inv)\n sage: I.cardinality() == factorial(4)\n True\n " return self._set.cardinality() class Element(ElementWrapper): '\n An element of an induced crystal.\n ' def e(self, i): "\n Return `e_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,3))\n sage: G = GelfandTsetlinPatterns(4, 3)\n sage: phi = lambda x: D(x.to_tableau())\n sage: phi_inv = lambda x: G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: elt.e(1)\n sage: elt.e(2)\n [[1, 1, 0, 0], [1, 1, 0], [1, 1], [1]]\n sage: elt.e(3)\n " P = self.parent() ret = P._phi(self.value).e(i) if (ret is None): return None try: return self.__class__(P, P._inverse(ret)) except (ValueError, TypeError, AttributeError): return None def f(self, i): "\n Return `f_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,3))\n sage: G = GelfandTsetlinPatterns(4, 3)\n sage: phi = lambda x: D(x.to_tableau())\n sage: phi_inv = lambda x: G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: elt.f(1)\n [[1, 1, 0, 0], [1, 1, 0], [1, 0], [0]]\n sage: elt.f(2)\n sage: elt.f(3)\n [[1, 1, 0, 0], [1, 0, 0], [1, 0], [1]]\n " P = self.parent() ret = P._phi(self.value).f(i) if (ret is None): return None try: return self.__class__(P, P._inverse(ret)) except (ValueError, TypeError, AttributeError): return None def epsilon(self, i): "\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,3))\n sage: G = GelfandTsetlinPatterns(4, 3)\n sage: phi = lambda x: D(x.to_tableau())\n sage: phi_inv = lambda x: G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: [elt.epsilon(i) for i in I.index_set()]\n [0, 1, 0]\n " return self.parent()._phi(self.value).epsilon(i) def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,3))\n sage: G = GelfandTsetlinPatterns(4, 3)\n sage: phi = lambda x: D(x.to_tableau())\n sage: phi_inv = lambda x: G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: [elt.phi(i) for i in I.index_set()]\n [1, 0, 1]\n " return self.parent()._phi(self.value).phi(i) def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,3))\n sage: G = GelfandTsetlinPatterns(4, 3)\n sage: phi = lambda x: D(x.to_tableau())\n sage: phi_inv = lambda x: G(x.to_tableau())\n sage: I = crystals.Induced(G, phi, phi_inv)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: elt.weight()\n (1, 0, 1, 0)\n " return self.parent()._phi(self.value).weight()
class InducedFromCrystal(UniqueRepresentation, Parent): "\n A crystal induced from an injection.\n\n Alternatively we can induce a crystal structure on some (sub)set of `X`\n by considering an injection `\\Phi : C \\to X` considered as a crystal\n morphism.\n\n .. SEEALSO::\n\n :class:`InducedCrystal`\n\n INPUT:\n\n - ``X`` -- the base set\n - ``phi`` -- the map `\\Phi`\n - ``inverse`` -- (optional) the inverse map `\\Phi^{-1}`\n\n EXAMPLES:\n\n We construct a crystal structure on generalized permutations with a\n fixed first row by using RSK::\n\n sage: C = crystals.Tableaux(['A',3], shape=[2,1])\n sage: def psi(x):\n ....: ret = RSK_inverse(x.to_tableau(), Tableau([[1,1],[2]]))\n ....: return (tuple(ret[0]), tuple(ret[1]))\n sage: psi_inv = lambda x: C(RSK(*x)[0])\n sage: I = crystals.Induced(C, psi, psi_inv, from_crystal=True)\n " def __init__(self, X, phi, inverse): "\n Initialize ``self``.\n\n TESTS:\n\n Note that pickling only works when the input functions\n can be pickled::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return D(x.to_tableau())\n sage: def phi_inv(x): return G(x.to_tableau())\n sage: import __main__\n sage: __main__.phi = phi\n sage: __main__.phi_inv = phi_inv\n sage: I = crystals.Induced(D, phi_inv, phi, from_crystal=True)\n sage: TestSuite(I).run()\n " self._crystal = X self._phi = phi if (inverse is None): try: inverse = (~ self._phi) except (TypeError, ValueError): try: inverse = self._phi.section() except AttributeError: if (X.cardinality() == float('inf')): raise ValueError('the inverse map must be defined for infinite sets') self._preimage = {} for x in X: y = phi(x) if (y in self._preimage): raise ValueError('the map is not injective') self._preimage[y] = x inverse = self._preimage.__getitem__ self._inverse = inverse self._cartan_type = X.cartan_type() Parent.__init__(self, category=X.category()) self.module_generators = tuple((self.element_class(self, phi(mg)) for mg in X.module_generators)) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return D(x.to_tableau())\n sage: def phi_inv(x): return G(x.to_tableau())\n sage: crystals.Induced(D, phi_inv, phi, from_crystal=True)\n Crystal induced by <function phi_inv at 0x...> from\n The crystal of tableaux of type ['A', 3] and shape(s)\n [[], [1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]\n " return 'Crystal induced by {} from {}'.format(self._phi, self._crystal) def _element_constructor_(self, x): "\n Construct an element of ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.Tableaux(['A',3], shape=[2,1])\n sage: def psi(x):\n ....: ret = RSK_inverse(x.to_tableau(), Tableau([[1,1],[2]]))\n ....: return (tuple(ret[0]), tuple(ret[1]))\n sage: psi_inv = lambda x: C(RSK(*x)[0])\n sage: I = crystals.Induced(C, psi, psi_inv, from_crystal=True)\n sage: I([[1, 1, 2], [2, 2, 1]])\n ((1, 1, 2), (2, 2, 1))\n sage: I(C(2,1,3))\n ((1, 1, 2), (2, 3, 1))\n " if (x in self._crystal): return self.element_class(self, self._phi(self._crystal(x))) try: return self.element_class(self, self._phi(self._inverse(x))) except (TypeError, ValueError, AttributeError): raise TypeError('unable to convert {!r} to {}'.format(x, self)) def __contains__(self, x): "\n Check if ``x`` is in ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.Tableaux(['A',3], shape=[2,1])\n sage: def psi(x):\n ....: ret = RSK_inverse(x.to_tableau(), Tableau([[1,1],[2]]))\n ....: return (tuple(ret[0]), tuple(ret[1]))\n sage: psi_inv = lambda x: C(RSK(*x)[0])\n sage: I = crystals.Induced(C, psi, psi_inv, from_crystal=True)\n sage: ((1, 1, 2), (2, 2, 1)) in I\n True\n sage: ((1, 2, 2), (1, 1, 2)) in I\n False\n sage: ((1, 2, 3), (1, 2, 3)) in I\n False\n sage: ((1, 2, 2), (1, 3, 2)) in I\n False\n " if isinstance(x, InducedFromCrystal.Element): return (x.parent() == self) try: y = self._inverse(x) return ((y in self._crystal) and (self._phi(y) == x)) except (ValueError, TypeError): return False def __iter__(self): "\n Iterate over ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.Tableaux(['A',2], shape=[2,1])\n sage: def psi(x):\n ....: ret = RSK_inverse(x.to_tableau(), Tableau([[1,1],[2]]))\n ....: return (tuple(ret[0]), tuple(ret[1]))\n sage: psi_inv = lambda x: C(RSK(*x)[0])\n sage: I = crystals.Induced(C, psi, psi_inv, from_crystal=True)\n sage: sorted(x for x in I)\n [((1, 1, 2), (1, 2, 1)),\n ((1, 1, 2), (2, 2, 1)),\n ((1, 1, 2), (2, 3, 1)),\n ((1, 1, 2), (3, 3, 1)),\n ((1, 1, 2), (3, 3, 2)),\n ((1, 1, 2), (1, 3, 1)),\n ((1, 1, 2), (1, 3, 2)),\n ((1, 1, 2), (2, 3, 2))]\n " for x in self._crystal: (yield self.element_class(self, self._phi(x))) def cardinality(self): "\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.Tableaux(['A',3], shape=[2,1])\n sage: def psi(x):\n ....: ret = RSK_inverse(x.to_tableau(), Tableau([[1,1],[2]]))\n ....: return (tuple(ret[0]), tuple(ret[1]))\n sage: psi_inv = lambda x: C(RSK(*x)[0])\n sage: I = crystals.Induced(C, psi, psi_inv, from_crystal=True)\n sage: I.cardinality() == C.cardinality()\n True\n " return self._crystal.cardinality() class Element(ElementWrapper): '\n An element of an induced crystal.\n ' def e(self, i): "\n Return `e_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return G(x.to_tableau())\n sage: def phi_inv(x): return D(G(x).to_tableau())\n sage: I = crystals.Induced(D, phi, phi_inv, from_crystal=True)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: elt.e(1)\n sage: elt.e(2)\n [[1, 1, 0, 0], [1, 1, 0], [1, 1], [1]]\n sage: elt.e(3)\n " P = self.parent() ret = P._inverse(self.value).e(i) if (ret is None): return None return self.__class__(P, P._phi(ret)) def f(self, i): "\n Return `f_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return G(x.to_tableau())\n sage: def phi_inv(x): return D(G(x).to_tableau())\n sage: I = crystals.Induced(D, phi, phi_inv, from_crystal=True)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: elt.f(1)\n [[1, 1, 0, 0], [1, 1, 0], [1, 0], [0]]\n sage: elt.f(2)\n sage: elt.f(3)\n [[1, 1, 0, 0], [1, 0, 0], [1, 0], [1]]\n " P = self.parent() ret = P._inverse(self.value).f(i) if (ret is None): return None return self.__class__(P, P._phi(ret)) def epsilon(self, i): "\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return G(x.to_tableau())\n sage: def phi_inv(x): return D(G(x).to_tableau())\n sage: I = crystals.Induced(D, phi, phi_inv, from_crystal=True)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: [elt.epsilon(i) for i in I.index_set()]\n [0, 1, 0]\n " return self.parent()._inverse(self.value).epsilon(i) def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return G(x.to_tableau())\n sage: def phi_inv(x): return D(G(x).to_tableau())\n sage: I = crystals.Induced(D, phi, phi_inv, from_crystal=True)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: [elt.epsilon(i) for i in I.index_set()]\n [0, 1, 0]\n " return self.parent()._inverse(self.value).phi(i) def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: D = crystals.Tableaux(['A',3], shapes=PartitionsInBox(4,1))\n sage: G = GelfandTsetlinPatterns(4, 1)\n sage: def phi(x): return G(x.to_tableau())\n sage: def phi_inv(x): return D(G(x).to_tableau())\n sage: I = crystals.Induced(D, phi, phi_inv, from_crystal=True)\n sage: elt = I([[1, 1, 0, 0], [1, 1, 0], [1, 0], [1]])\n sage: elt.weight()\n (1, 0, 1, 0)\n " return self.parent()._inverse(self.value).weight()
class InfinityCrystalOfTableaux(CrystalOfWords): "\n `\\mathcal{B}(\\infty)` crystal of tableaux.\n\n A tableaux model `\\mathcal{T}(\\infty)` for the crystal\n `\\mathcal{B}(\\infty)` is introduced by Hong and Lee in [HL2008]_. This model\n is currently valid for types `A_n`, `B_n`, `C_n`, `D_n`, and `G_2`, and\n builds on the tableaux model given by Kashiwara and Nakashima [KN1994]_ in\n types `A_n`, `B_n`, `C_n`, and `D_n`, and by Kang and Misra [KM1994]_ in\n type `G_2`.\n\n .. NOTE::\n\n We are using the English convention for our tableaux.\n\n We say a tableau `T` is *marginally large* if:\n\n - for each `1 \\leq i \\leq n`, the leftmost box in the `i`-th row\n from the top in `T` is an `i`-box,\n\n - for each `1 \\leq i \\leq n`, the number of `i`-boxes in the `i`-th row\n from the top in `T` is greater than the total number of boxes in the\n `(i+1)`-th row by exactly one.\n\n We now will describe this tableaux model type-by-type.\n\n .. rubric:: Type `A_n`\n\n `\\mathcal{T}(\\infty)` is the set of marginally large semistandard\n tableaux with exactly `n` rows over the alphabet `\\{1 \\prec 2 \\prec\n \\cdots \\prec n+1 \\}`.\n\n .. rubric:: Type `B_n`\n\n `\\mathcal{T}(\\infty)` is the set of marginally large semistandard\n tableaux with exactly `n` rows over the alphabet `\\{1 \\prec \\cdots\n \\prec n \\prec 0 \\prec \\overline{n} \\prec \\cdots \\prec \\overline{1} \\}`\n and subject to the following constraints:\n\n - for each `1 \\le i \\le n`, the contents of the boxes in the\n `i`-th row are `\\preceq \\overline{i}`,\n\n - the entry `0` can appear at most once in a single row.\n\n .. rubric:: Type `C_n`\n\n `\\mathcal{T}(\\infty)` is the set of marginally large semistandard\n tableaux with exactly `n` rows over the alphabet `\\{1 \\prec \\cdots\n \\prec n \\prec \\overline{n} \\prec \\cdots \\prec \\overline{1} \\}` and\n for each `1 \\leq i \\leq n`, the contents of the boxes in the `i`-th\n row are `\\preceq \\overline{i}`.\n\n .. rubric:: Type `D_n`\n\n `\\mathcal{T}(\\infty)` is the set of marginally large semistandard\n tableaux with exactly `n-1` rows over the alphabet `\\{1 \\prec \\cdots\n \\prec n, \\overline{n} \\prec \\cdots \\prec \\overline{1} \\}` and subject\n to the following constraints:\n\n - for each `1 \\le i \\le n`, the contents of the boxes in the `i`-th\n row are `\\preceq \\overline{i}`,\n\n - the entries `n` and `\\overline{n}` may not appear simultaneously in\n a single row.\n\n .. rubric:: Type `G_2`\n\n `\\mathcal{T}(\\infty)` is the set of marginally large semistandard\n tableaux with exactly `2` rows over the ordered alphabet `\\{1 \\prec\n 2 \\prec 3 \\prec 0 \\prec \\overline{3} \\prec \\overline{2} \\prec\n \\overline{1}\\}` and subject to the following constraints:\n\n - the contents of the boxes in the first row are `\\preceq \\overline{i}`,\n\n - the contents of the boxes in the second row are `\\preceq 3`,\n\n - the entry `0` can appear at most once in the first row and not at\n all in the second row.\n\n In particular, the shape of the tableaux is not fixed in any instance of\n `\\mathcal{T}(\\infty)`; the row lengths of a tableau can be arbitrarily long.\n\n INPUT:\n\n - ``cartan_type`` -- One of ``['A',n]``, ``['B',n]``, ``['C',n]``,\n ``['D',n]``, or ``['G',2]``, where ``n`` is a positive integer\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: b = B.highest_weight_vector(); b.pp()\n 1 1\n 2\n sage: b.f_string([2,1,1,2,2,2]).pp()\n 1 1 1 1 1 2 3\n 2 3 3 3\n\n sage: B = crystals.infinity.Tableaux(['G',2])\n sage: b = B(rows=[[1,1,1,1,1,2,3,3,0,-3,-1,-1,-1],[2,3,3,3]])\n sage: b.e_string([2,1,1,1,1,1,1]).pp()\n 1 1 1 1 2 3 3 3 3 -2 -2 -2\n 2 3 3\n sage: b.e_string([2,1,1,1,1,1,1,1])\n\n We check that a few classical crystals embed into `\\mathcal{T}(\\infty)`::\n\n sage: def crystal_test(B, C):\n ....: T = crystals.elementary.T(C.cartan_type(), C.module_generators[0].weight())\n ....: TP = crystals.TensorProduct(T, B)\n ....: mg = TP(T[0], B.module_generators[0])\n ....: g = {C.module_generators[0]: mg}\n ....: f = C.crystal_morphism(g, category=HighestWeightCrystals())\n ....: G = B.digraph(subset=[f(x) for x in C])\n ....: return G.is_isomorphic(C.digraph(), edge_labels=True)\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: C = crystals.Tableaux(['A',2], shape=[2,1])\n sage: crystal_test(B, C)\n True\n sage: C = crystals.Tableaux(['A',2], shape=[6,2])\n sage: crystal_test(B, C)\n True\n sage: B = crystals.infinity.Tableaux(['B',2])\n sage: C = crystals.Tableaux(['B',2], shape=[3])\n sage: crystal_test(B, C)\n True\n sage: C = crystals.Tableaux(['B',2], shape=[2,1])\n sage: crystal_test(B, C)\n True\n sage: B = crystals.infinity.Tableaux(['C',3])\n sage: C = crystals.Tableaux(['C',3], shape=[2,1])\n sage: crystal_test(B, C)\n True\n sage: B = crystals.infinity.Tableaux(['D',4])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: crystal_test(B, C)\n True\n sage: C = crystals.Tableaux(['D',4], shape=[1,1,1,1])\n sage: crystal_test(B, C)\n True\n sage: B = crystals.infinity.Tableaux(['G',2])\n sage: C = crystals.Tableaux(['G',2], shape=[3])\n sage: crystal_test(B, C)\n True\n " @staticmethod def __classcall_private__(cls, cartan_type): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',4])\n sage: B2 = crystals.infinity.Tableaux(CartanType(['A',4]))\n sage: B is B2\n True\n " cartan_type = CartanType(cartan_type) if (cartan_type.type() == 'D'): return InfinityCrystalOfTableauxTypeD(cartan_type) if (cartan_type.type() == 'Q'): return DualInfinityQueerCrystalOfTableaux(cartan_type) return super().__classcall__(cls, cartan_type) def __init__(self, cartan_type): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: TestSuite(B).run() # long time\n " Parent.__init__(self, category=(HighestWeightCrystals(), InfiniteEnumeratedSets())) self._cartan_type = cartan_type self.letters = CrystalOfLetters(cartan_type) self.module_generators = (self.module_generator(),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',4]); B\n The infinity crystal of tableaux of type ['A', 4]\n " return ('The infinity crystal of tableaux of type %s' % self._cartan_type) @cached_method def module_generator(self): "\n Return the module generator (or highest weight element) of ``self``.\n\n The module generator is the unique tableau of shape `(n, n-1, \\ldots,\n 2, 1)` with weight `0`.\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: T.module_generator()\n [[1, 1, 1], [2, 2], [3]]\n " n = self._cartan_type.rank() p = Partition([x for x in reversed(range(1, (n + 1)))]) module_generator = flatten([[(p[j] - i) for i in range(p[j])] for j in range(n)]) return self(list=[self.letters(x) for x in module_generator]) def _element_constructor_(self, *args, **options): "\n Construct an element of ``self`` from the input data.\n\n EXAMPLES::\n\n sage: T = crystals.Tableaux(['A',3], shape = [2,2])\n sage: T(rows=[[1,2],[3,4]])\n [[1, 2], [3, 4]]\n sage: T(columns=[[3,1],[4,2]])\n [[1, 2], [3, 4]]\n " return self.element_class(self, *args, **options) def _coerce_map_from_(self, P): "\n Return ``True`` or the coerce map from ``P`` if a map exists.\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: RC = crystals.infinity.RiggedConfigurations(['A',3])\n sage: T._coerce_map_from_(RC)\n Crystal Isomorphism morphism:\n From: The infinity crystal of rigged configurations of type ['A', 3]\n To: The infinity crystal of tableaux of type ['A', 3]\n " from sage.combinat.rigged_configurations.rc_infinity import InfinityCrystalOfRiggedConfigurations, InfinityCrystalOfNonSimplyLacedRC if (isinstance(P, InfinityCrystalOfRiggedConfigurations) and (self.cartan_type().is_simply_laced() or isinstance(P, InfinityCrystalOfNonSimplyLacedRC))): from sage.combinat.rigged_configurations.bij_infinity import FromRCIsomorphism return FromRCIsomorphism(Hom(P, self)) return super()._coerce_map_from_(P) class Element(InfinityCrystalOfTableauxElement): '\n Elements in `\\mathcal{B}(\\infty)` crystal of tableaux.\n ' def phi(self, i): '\n Return `\\varphi_i` of ``self``.\n\n Let `T \\in \\mathcal{B}(\\infty)` Define `\\varphi_i(T) :=\n \\varepsilon_i(T) + \\langle h_i, \\mathrm{wt}(T) \\rangle`, where `h_i`\n is the `i`-th simple coroot and `\\mathrm{wt}(T)` is the :meth:`weight`\n of `T`.\n\n INPUT:\n\n - ``i`` -- An element of the index set\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux("A3")\n sage: [B.highest_weight_vector().f_string([1,3,2,3,1,3,2,1]).phi(i) for i in B.index_set()]\n [-3, 4, -3]\n\n sage: B = crystals.infinity.Tableaux("G2")\n sage: [B.highest_weight_vector().f_string([2,2,1,2,1,1,1,2]).phi(i) for i in B.index_set()]\n [5, -3]\n ' P = self.parent().weight_lattice_realization() h = P.simple_coroots() return (self.epsilon(i) + P(self.weight()).scalar(h[i])) @cached_method def weight(self): '\n Return the weight of ``self``.\n\n From the definition of a crystal and that the highest weight\n element `b_{\\infty}` of `\\mathcal{B}(\\infty)` is `0`, the weight of\n `T \\in \\mathcal{B}(\\infty)` can be defined as `\\mathrm{wt}(T)\n := -\\sum_j \\alpha_{i_j}` where `\\widetilde{e}_{i_1} \\cdots\n \\widetilde{e}_{i_{\\ell}} T = b_{\\infty}` and `\\{\\alpha_i\\}` is the\n set of simple roots. (Note that the weight is independent of the\n path chosen to get to the highest weight.)\n\n However we can also take advantage of the fact that\n `\\rho \\colon R_{\\lambda} \\otimes \\mathcal{B}(\\infty) \\longrightarrow\n B(\\lambda)`, where `\\lambda` is the shape of `T`, preserves the\n tableau representation of `T`. Therefore\n\n .. MATH::\n\n \\mathrm{wt}(T) = \\mathrm{wt}\\bigl( \\rho(T) \\bigr) - \\lambda\n\n where `\\mathrm{wt}\\bigl( \\rho(T) \\bigr)` is just the usual weight of\n the tableau `T`.\n\n Let `\\Lambda_i` be the `i`-th fundamental weight. In type `D`, the\n height `n-1` columns corresponds to `\\Lambda_{n-1} + \\Lambda_n` and\n the in type `B`, the height `n` columns corresponds to\n `2 \\Lambda_n`.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux("C7")\n sage: b = B.highest_weight_vector().f_string([1,6,4,7,4,2,4,6,2,4,6,7,1,2,4,7])\n sage: b.weight()\n (-2, -1, 3, -5, 5, -3, -3)\n\n Check that the definitions agree::\n\n sage: P = B.weight_lattice_realization()\n sage: alpha = P.simple_roots()\n sage: b.weight() == -2*alpha[1] - 3*alpha[2] - 5*alpha[4] - 3*alpha[6] - 3*alpha[7]\n True\n\n Check that it works for type `B`::\n\n sage: B = crystals.infinity.Tableaux("B2")\n sage: B.highest_weight_vector().weight()\n (0, 0)\n sage: b = B.highest_weight_vector().f_string([1,2,2,2,1,2])\n sage: P = B.weight_lattice_realization()\n sage: alpha = P.simple_roots()\n sage: b.weight() == -2*alpha[1] - 4*alpha[2]\n True\n\n Check that it works for type `D`::\n\n sage: B = crystals.infinity.Tableaux("D4")\n sage: B.highest_weight_vector().weight()\n (0, 0, 0, 0)\n sage: b = B.highest_weight_vector().f_string([1,4,4,2,4,3,2,4,1,3,2,4])\n sage: P = B.weight_lattice_realization()\n sage: alpha = P.simple_roots()\n sage: b.weight() == -2*alpha[1] - 3*alpha[2] - 2*alpha[3] - 5*alpha[4]\n True\n ' P = self.parent().weight_lattice_realization() La = P.fundamental_weights() cur_col_len = 1 shape_wt = P.zero() n = self.cartan_type().rank() ty = self.cartan_type().type() for i in range(1, len(self)): if ((self[(i - 1)] < self[i]) or ((self[(i - 1)].value != 0) and (self[(i - 1)] == self[i]))): if (((cur_col_len == (n - 1)) and (ty == 'D')) or ((cur_col_len == n) and (ty == 'B'))): shape_wt += La[n] shape_wt += La[cur_col_len] cur_col_len = 1 else: cur_col_len += 1 shape_wt += La[1] return (CrystalOfTableauxElement.weight(self) - shape_wt) def reduced_form(self): "\n Return the reduced form of ``self``.\n\n The reduced form of a tableaux `T \\in \\mathcal{T}(\\infty)` is the\n (not necessarily semistandard) tableaux obtained from `T` by\n removing all `i`-boxes in the `i`-th row, subject to the condition\n that if the row is empty, a `\\ast` is put as a placeholder.\n This is described in [BN2010]_ and [LS2012]_.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',3])\n sage: b = B.highest_weight_vector().f_string([2,2,2,3,3,3,3,3])\n sage: b.pp()\n 1 1 1 1 1 1 1 1\n 2 2 2 2 4 4 4\n 3 4 4\n sage: b.reduced_form()\n [['*'], [4, 4, 4], [4, 4]]\n " oldtab = self.to_tableau() newtab = [] for (i, row) in enumerate(oldtab): j = 0 row = list(row) while (j < len(row)): if (row[j] == (i + 1)): row.pop(j) if (not row): row.append('*') else: j += 1 newtab.append(row) from sage.misc.stopgap import stopgap stopgap('Return value is no longer a Tableau.', 17997) return newtab def seg(self): "\n Returns the statistic `\\mathrm{seg}` of ``self.``\n\n More precisely, following [LS2012]_, define a `k`-segment of a\n tableau `T` in `\\mathcal{B}(\\infty)` to be a maximal string\n of `k`-boxes in a single row of `T`. Set `\\mathrm{seg}^{\\prime}(T)`\n to be the number of `k`-segments in `T`, as `k` varies over\n all possible values. Then `\\mathrm{seg}(T)` is determined\n type-by-type.\n\n - In types `A_n` and `C_n`, define `\\mathrm{seg}(T) :=\n \\mathrm{seg}^{\\prime}(T)`.\n\n - In types `B_n` and `G_2`, set `e(T)` to be the number of rows in\n `T` which contain both a `0`-box and an `\\overline{\\imath}`-box.\n Define `\\mathrm{seg}(T) := \\mathrm{seg}^{\\prime}(T) - e(T)`.\n\n - In type `D_n`, set `d(T)` to be the number of rows in `T` which\n contain an `\\overline{\\imath}`-box, but no `n`-box nor\n `\\overline{n}`-box. Define `\\mathrm{seg}(T) :=\n \\mathrm{seg}^{\\prime}(T) + d(T)`.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',3])\n sage: b = B.highest_weight_vector().f_string([1,3,2,2,3,1,1,3])\n sage: b.pp()\n 1 1 1 1 1 1 2 2 4\n 2 2 2 2 3\n 3 4 4\n sage: b.seg()\n 4\n\n sage: B = crystals.infinity.Tableaux(['D',4])\n sage: b = B(rows=[[1,1,1,1,1,1,3,-2,-1],[2,2,2,4,-2],[3,3],[4]])\n sage: b.pp()\n 1 1 1 1 1 1 3 -2 -1\n 2 2 2 4 -2\n 3 3\n 4\n sage: b.seg()\n 6\n\n sage: B = crystals.infinity.Tableaux(['G',2])\n sage: b = B.highest_weight_vector().f_string([2,1,1,1,2,1,2,2,1,2,2,2,1,2,2,1])\n sage: b.pp()\n 1 1 1 1 1 1 1 1 2 3 0 -3\n 2 3 3 3 3 3 3\n sage: b.seg()\n 5\n " tab = self.to_tableau() segments = [] for r in range(len(tab)): for c in range(len(tab[r])): if (tab[r][c] != (r + 1)): if ([r, tab[r][c]] not in segments): segments.append([r, tab[r][c]]) if (self.parent().cartan_type().type() == 'B'): for r in range(len(tab)): for c in range(len(tab[r])): if ((tab[r][c] == 0) and (tab[r][(- 1)] == ((- r) - 1))): segments.remove([r, tab[r][c]]) if (self.parent().cartan_type().type() == 'D'): n = self.parent().cartan_type().rank() add = [] for r in range(len(tab)): if (tab[r][(- 1)] == ((- 1) * (r + 1))): for c in range(len(tab[r])): if ((tab[r][c] != n) and (tab[r][c] != (- n))): if ([r, n] not in add): add.append([r, n]) if (len(add) > 0): segments.append([r, n]) if (self.parent().cartan_type().type() == 'G'): for c in range(len(tab[0])): if ((tab[0][c] == 0) and (tab[0][(- 1)] == (- 1))): segments.remove([0, tab[0][c]]) return len(segments) def content(self): '\n Return the content of ``self``.\n\n The content `|T|` of `T \\in \\mathcal{B}(\\infty)` is the number of\n blocks added to the highest weight to obtain `T` with any\n `\\overline{\\imath}`-boxes in the `i`-th row counted with\n multiplicity `2` provided the underlying Cartan type is of type\n `B`, `D`, or `G`.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux("D5")\n sage: b = B.highest_weight_vector().f_string([5,4,3,1,1,3,4,5,3,4,5,1,4,5,2,3,5,3,2,4])\n sage: b.content()\n 13\n\n sage: B = crystals.infinity.Tableaux("B2")\n sage: b = B(rows=[[1,1,1,1,1,1,2,2,2,-2,-2],[2,0,-2,-2,-2]])\n sage: b.content()\n 12\n\n sage: B = crystals.infinity.Tableaux("C2")\n sage: b = B(rows=[[1,1,1,1,1,1,2,2,2,-2,-2],[2,-2,-2,-2]])\n sage: b.content()\n 8\n ' tab = self.to_tableau() count = 0 ct = self.parent().cartan_type().type() for (i, row) in enumerate(tab): for entry in row: if ((entry == ((- i) - 1)) and (ct in ('B', 'D', 'G'))): count += 2 elif (entry != (i + 1)): count += 1 return count
class InfinityCrystalOfTableauxTypeD(InfinityCrystalOfTableaux): '\n `\\mathcal{B}(\\infty)` crystal of tableaux for type `D_n`.\n\n This is the set `\\mathcal{T}(\\infty)` of marginally large semistandard\n tableaux with exactly `n-1` rows over the alphabet `\\{1 \\prec \\cdots\n \\prec n, \\overline{n} \\prec \\cdots \\prec \\overline{1} \\}` and subject\n to the following constraints:\n\n - for each `1 \\le i \\le n`, the contents of the boxes in the `i`-th\n row are `\\preceq \\overline{i}`,\n\n - the entries `n` and `\\overline{n}` may not appear simultaneously in\n a single row.\n\n For more information, see\n :class:`~sage.combinat.crystals.infinity_crystals.InfinityCrystalOfTableaux`.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux("D4")\n sage: b = B.highest_weight_vector().f_string([4,3,2,1,4])\n sage: b.pp()\n 1 1 1 1 1 1 2\n 2 2 2 2 3\n 3 -4 -3\n sage: b.weight()\n (-1, 0, -2, -1)\n ' @staticmethod def __classcall_private__(cls, cartan_type): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['D',4])\n sage: B2 = crystals.infinity.Tableaux(CartanType(['D',4]))\n sage: B is B2\n True\n " return super().__classcall__(cls, CartanType(cartan_type)) @cached_method def module_generator(self): "\n Return the module generator (or highest weight element) of ``self``.\n\n The module generator is the unique tableau of shape `(n-1, \\ldots, 2,\n 1)` with weight `0`.\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux(['D',4])\n sage: T.module_generator()\n [[1, 1, 1], [2, 2], [3]]\n " n = self._cartan_type.rank() p = Partition([x for x in reversed(range(1, n))]) module_generator = flatten([[(p[j] - i) for i in range(p[j])] for j in range((n - 1))]) return self(list=[self.letters(x) for x in module_generator]) class Element(InfinityCrystalOfTableauxElementTypeD, InfinityCrystalOfTableaux.Element): '\n Elements in `\\mathcal{B}(\\infty)` crystal of tableaux for type `D_n`.\n ' pass
class DualInfinityQueerCrystalOfTableaux(CrystalOfWords): @staticmethod def __classcall_private__(cls, cartan_type): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',4])\n sage: B2 = crystals.infinity.Tableaux(CartanType(['A',4]))\n sage: B is B2\n True\n " cartan_type = CartanType(cartan_type) return super().__classcall__(cls, cartan_type) def __init__(self, cartan_type): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: TestSuite(B).run() # long time\n " Parent.__init__(self, category=(SuperCrystals(), InfiniteEnumeratedSets())) self._cartan_type = cartan_type self.letters = CrystalOfLetters(cartan_type) self.module_generators = (self.module_generator(),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',4]); B\n The infinity crystal of tableaux of type ['A', 4]\n " return ('The dual infinity crystal of tableaux of type %s' % self._cartan_type) @cached_method def module_generator(self): '\n Return the module generator (or highest weight element) of ``self``.\n\n The module generator is the unique semistandard hook tableau of shape\n `(n, n-1, \\ldots,2, 1)` with weight `0`.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(["Q",5])\n sage: B.module_generator()\n [[5, 5, 5, 5, 5], [4, 4, 4, 4], [3, 3, 3], [2, 2], [1]]\n ' n = (self._cartan_type.rank() + 1) row_lens = list(reversed(range(1, (n + 1)))) module_generator = flatten([([val] * val) for val in row_lens]) return self.element_class(self, [self.letters(x) for x in module_generator], row_lens) @cached_method def index_set(self): '\n Return the index set of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(["Q",3])\n sage: B.index_set()\n (1, 2, -1)\n ' n = self._cartan_type.rank() return (tuple(range(1, (n + 1))) + ((- 1),)) def _element_constructor_(self, *args, **options): '\n Construct an element of ``self`` from the input data.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(["Q",4])\n sage: t = B([[4,4,4,4,2,1],[3,3,3],[2,2],[1]])\n sage: t\n [[4, 4, 4, 4, 2, 1], [3, 3, 3], [2, 2], [1]]\n ' return self.element_class(self, *args, **options) class Element(InfinityQueerCrystalOfTableauxElement): pass
class CrystalOfOddNegativeRoots(UniqueRepresentation, Parent): "\n Crystal of the set of odd negative roots.\n\n Let `\\mathfrak{g}` be the general-linear Lie superalgebra\n `\\mathfrak{gl}(m|n)`. This is the crystal structure on the set of\n negative roots as given by [Kwon2012]_.\n\n More specifically, this is the crystal basis of the subalgebra\n of `U_q^-(\\mathfrak{g})` generated by `f_{\\alpha}`, where `\\alpha`\n ranges over all odd positive roots. As `\\QQ(q)`-modules, we have\n\n .. MATH::\n\n U_q^-(\\mathfrak{g}) \\cong\n K \\otimes U^-_q(\\mathfrak{gl}_m \\oplus \\mathfrak{gl}_n).\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,1]])\n sage: mg = S.module_generator(); mg\n {}\n sage: mg.f(0)\n {-e[-1]+e[1]}\n sage: mg.f_string([0,-1,0,1,2,1,0])\n {-e[-2]+e[3], -e[-1]+e[1], -e[-1]+e[2]}\n " @staticmethod def __classcall_private__(cls, cartan_type): "\n Normalize input to ensure a unique representation.\n\n TESTS::\n\n sage: S1 = crystals.OddNegativeRoots(['A', [2,1]])\n sage: S2 = crystals.OddNegativeRoots(CartanType(['A', [2,1]]))\n sage: S1 is S2\n True\n " return super().__classcall__(cls, CartanType(cartan_type)) def __init__(self, cartan_type): "\n Initialize ``self``.\n\n TESTS::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,1]])\n sage: TestSuite(S).run()\n " self._cartan_type = cartan_type Parent.__init__(self, category=RegularSuperCrystals()) self.module_generators = (self.element_class(self, frozenset()),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.OddNegativeRoots(['A', [2,1]])\n Crystal of odd negative roots of type ['A', [2, 1]]\n " return 'Crystal of odd negative roots of type {}'.format(self._cartan_type) def module_generator(self): "\n Return the module generator of ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,1]])\n sage: S.module_generator()\n {}\n " return self.module_generators[0] class Element(ElementWrapper): "\n An element of the crystal of odd negative roots.\n\n TESTS:\n\n Check that `e_i` and `f_i` are psuedo-inverses::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,1]])\n sage: for x in S:\n ....: for i in S.index_set():\n ....: y = x.f(i)\n ....: assert y is None or y.e(i) == x\n\n Check that we obtain the entire powerset of negative odd roots::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,3]])\n sage: S.cardinality()\n 4096\n sage: 2^len(S.weight_lattice_realization().positive_odd_roots())\n 4096\n " def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,2]])\n sage: mg = S.module_generator(); mg\n {}\n sage: mg.f(0)\n {-e[-1]+e[1]}\n sage: mg.f_string([0,-1,0])\n {-e[-2]+e[1], -e[-1]+e[1]}\n " return (('{' + ', '.join(('-e[{}]+e[{}]'.format(*i) for i in sorted(self.value)))) + '}') def _latex_(self): "\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,2]])\n sage: mg = S.module_generator()\n sage: latex(mg)\n \\{\\}\n sage: latex(mg.f(0))\n \\{-e_{-1}+e_{1}\\}\n sage: latex(mg.f_string([0,-1,0]))\n \\{-e_{-2}+e_{1}, -e_{-1}+e_{1}\\}\n " return (('\\{' + ', '.join(('-e_{{{}}}+e_{{{}}}'.format(*i) for i in sorted(self.value)))) + '\\}') def e(self, i): "\n Return the action of the crystal operator `e_i` on ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,2]])\n sage: mg = S.module_generator()\n sage: mg.e(0)\n sage: mg.e(1)\n sage: b = mg.f_string([0,1,2,-1,0])\n sage: b.e(-1)\n sage: b.e(0)\n {-e[-2]+e[3]}\n sage: b.e(1)\n sage: b.e(2)\n {-e[-2]+e[2], -e[-1]+e[1]}\n sage: b.e_string([2,1,0,-1,0])\n {}\n " if (i == 0): if (((- 1), 1) not in self.value): return None return type(self)(self.parent(), self.value.difference([((- 1), 1)])) count = 0 act_val = None if (i < 0): lst = sorted(self.value, key=(lambda x: (x[1], (- x[0])))) for val in lst: if (val[0] == (i - 1)): if (count == 0): act_val = val else: count -= 1 elif (val[0] == i): count += 1 if (act_val is None): return None ret = self.value.difference([act_val]).union([(i, act_val[1])]) return type(self)(self.parent(), ret) lst = sorted(self.value, key=(lambda x: ((- x[0]), (- x[1])))) for val in reversed(lst): if (val[1] == (i + 1)): if (count == 0): act_val = val else: count -= 1 elif (val[1] == i): count += 1 if (act_val is None): return None ret = self.value.difference([act_val]).union([(act_val[0], i)]) return type(self)(self.parent(), ret) def f(self, i): "\n Return the action of the crystal operator `f_i` on ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,2]])\n sage: mg = S.module_generator()\n sage: mg.f(0)\n {-e[-1]+e[1]}\n sage: mg.f(1)\n sage: b = mg.f_string([0,1,2,-1,0]); b\n {-e[-2]+e[3], -e[-1]+e[1]}\n sage: b.f(-2)\n {-e[-3]+e[3], -e[-1]+e[1]}\n sage: b.f(-1)\n sage: b.f(0)\n sage: b.f(1)\n {-e[-2]+e[3], -e[-1]+e[2]}\n " if (i == 0): if (((- 1), 1) in self.value): return None return type(self)(self.parent(), self.value.union([((- 1), 1)])) count = 0 act_val = None if (i < 0): lst = sorted(self.value, key=(lambda x: (x[1], (- x[0])))) for val in reversed(lst): if (val[0] == i): if (count == 0): act_val = val else: count -= 1 elif (val[0] == (i - 1)): count += 1 if (act_val is None): return None ret = self.value.difference([act_val]).union([((i - 1), act_val[1])]) return type(self)(self.parent(), ret) lst = sorted(self.value, key=(lambda x: ((- x[0]), (- x[1])))) for val in lst: if (val[1] == i): if (count == 0): act_val = val else: count -= 1 elif (val[1] == (i + 1)): count += 1 if (act_val is None): return None ret = self.value.difference([act_val]).union([(act_val[0], (i + 1))]) return type(self)(self.parent(), ret) def epsilon(self, i): "\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,2]])\n sage: mg = S.module_generator()\n sage: [mg.epsilon(i) for i in S.index_set()]\n [0, 0, 0, 0, 0]\n sage: b = mg.f_string([0,1,0,-1,0,-1,-2,-2]); b\n {-e[-3]+e[1], -e[-3]+e[2], -e[-1]+e[1]}\n sage: [b.epsilon(i) for i in S.index_set()]\n [2, 0, 1, 0, 0]\n sage: b = mg.f_string([0,1,0,-1,0,-1,-2,-2,2,-1,0]); b\n {-e[-3]+e[1], -e[-3]+e[3], -e[-2]+e[1], -e[-1]+e[1]}\n sage: [b.epsilon(i) for i in S.index_set()]\n [1, 0, 1, 0, 1]\n\n TESTS::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,1]])\n sage: def count_e(x, i):\n ....: ret = -1\n ....: while x is not None:\n ....: x = x.e(i)\n ....: ret += 1\n ....: return ret\n sage: for x in S:\n ....: for i in S.index_set():\n ....: assert x.epsilon(i) == count_e(x, i)\n " if (i == 0): return (ZZ.one() if (((- 1), 1) in self.value) else ZZ.zero()) count = 0 ret = 0 if (i < 0): lst = sorted(self.value, key=(lambda x: (x[1], (- x[0])))) for val in lst: if (val[0] == (i - 1)): if (count == 0): ret += 1 else: count -= 1 elif (val[0] == i): count += 1 else: lst = sorted(self.value, key=(lambda x: ((- x[0]), (- x[1])))) for val in reversed(lst): if (val[1] == (i + 1)): if (count == 0): ret += 1 else: count -= 1 elif (val[1] == i): count += 1 return ret def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,2]])\n sage: mg = S.module_generator()\n sage: [mg.phi(i) for i in S.index_set()]\n [0, 0, 1, 0, 0]\n sage: b = mg.f(0)\n sage: [b.phi(i) for i in S.index_set()]\n [0, 1, 0, 1, 0]\n sage: b = mg.f_string([0,1,0,-1,0,-1]); b\n {-e[-2]+e[1], -e[-2]+e[2], -e[-1]+e[1]}\n sage: [b.phi(i) for i in S.index_set()]\n [2, 0, 0, 1, 1]\n\n TESTS::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,1]])\n sage: def count_f(x, i):\n ....: ret = -1\n ....: while x is not None:\n ....: x = x.f(i)\n ....: ret += 1\n ....: return ret\n sage: for x in S:\n ....: for i in S.index_set():\n ....: assert x.phi(i) == count_f(x, i)\n " if (i == 0): return (ZZ.zero() if (((- 1), 1) in self.value) else ZZ.one()) count = 0 ret = 0 if (i < 0): lst = sorted(self.value, key=(lambda x: (x[1], (- x[0])))) for val in reversed(lst): if (val[0] == i): if (count == 0): ret += 1 else: count -= 1 elif (val[0] == (i - 1)): count += 1 else: lst = sorted(self.value, key=(lambda x: ((- x[0]), (- x[1])))) for val in lst: if (val[1] == i): if (count == 0): ret += 1 else: count -= 1 elif (val[1] == (i + 1)): count += 1 return ret def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,2]])\n sage: mg = S.module_generator()\n sage: mg.weight()\n (0, 0, 0, 0, 0, 0)\n sage: mg.f_string([0,1,2,-1,-2]).weight()\n (-1, 0, 0, 0, 0, 1)\n sage: mg.f_string([0,1,2,-1,-2,0,1,0,2]).weight()\n (-1, 0, -2, 1, 0, 2)\n\n TESTS::\n\n sage: S = crystals.OddNegativeRoots(['A', [2,1]])\n sage: al = S.weight_lattice_realization().simple_roots()\n sage: for x in S:\n ....: for i in S.index_set():\n ....: y = x.f(i)\n ....: assert y is None or x.weight() - al[i] == y.weight()\n " WLR = self.parent().weight_lattice_realization() e = WLR.basis() return WLR.sum((((- e[i]) + e[j]) for (i, j) in self.value))
class CrystalOfKacModule(UniqueRepresentation, Parent): "\n Crystal of a Kac module.\n\n Let `\\mathfrak{g}` be the general linear Lie superalgebra\n `\\mathfrak{gl}(m|n)`. Let `\\lambda` and `\\mu` be dominant weights\n for `\\mathfrak{gl}_m` and `\\mathfrak{gl}_n`, respectively.\n Let `K` be the module `K = \\langle f_{\\alpha} \\rangle`,\n where `\\alpha` ranges over all odd positive roots. A *Kac module*\n is the `U_q(\\mathfrak{g})`-module constructed from the highest\n weight `U_q(\\mathfrak{gl}_m \\oplus \\mathfrak{gl}_n)`-module\n `V(\\lambda, \\mu)` (induced to a `U_q(\\mathfrak{g})`-module in\n the natural way) by\n\n .. MATH::\n\n K(\\lambda, \\mu) := K \\otimes_L V(\\lambda, \\mu),\n\n where `L` is the subalgebra generated by `e_0` and\n `U_q(\\mathfrak{gl}_m \\oplus \\mathfrak{gl}_n)`.\n\n The Kac module admits a `U_q(\\mathfrak{g})`-crystal structure\n by taking the crystal structure of `K` as given by\n :class:`~sage.combinat.crystals.kac_modules.CrystalOfOddNegativeRoots`\n and the crystal `B(\\lambda, \\mu)` (the natural crystal structure\n of `V(\\lambda, \\mu)`).\n\n .. NOTE::\n\n Our notation differs slightly from [Kwon2012]_ in that our\n last tableau is transposed.\n\n EXAMPLES::\n\n sage: K = crystals.KacModule(['A', [1,2]], [2], [1,1])\n sage: K.cardinality()\n 576\n sage: K.cardinality().factor()\n 2^6 * 3^2\n sage: len(K.cartan_type().root_system().ambient_space().positive_odd_roots())\n 6\n sage: mg = K.module_generator()\n sage: mg\n ({}, [[-2, -2]], [[1], [2]])\n sage: mg.weight()\n (2, 0, 1, 1, 0)\n sage: mg.f(-1)\n ({}, [[-2, -1]], [[1], [2]])\n sage: mg.f(0)\n ({-e[-1]+e[1]}, [[-2, -2]], [[1], [2]])\n sage: mg.f(1)\n sage: mg.f(2)\n ({}, [[-2, -2]], [[1], [3]])\n\n sage: sorted(K.highest_weight_vectors(), key=str)\n [({-e[-1]+e[3]}, [[-2, -1]], [[1], [2]]),\n ({-e[-1]+e[3]}, [[-2, -2]], [[1], [2]]),\n ({}, [[-2, -2]], [[1], [2]])]\n\n ::\n\n sage: K = crystals.KacModule(['A', [1,1]], [2], [1])\n sage: K.cardinality()\n 96\n sage: K.cardinality().factor()\n 2^5 * 3\n sage: len(K.cartan_type().root_system().ambient_space().positive_odd_roots())\n 4\n\n sage: sorted(K.highest_weight_vectors(), key=str)\n [({-e[-1]+e[2]}, [[-2, -1]], [[1]]),\n ({-e[-1]+e[2]}, [[-2, -2]], [[1]]),\n ({}, [[-2, -2]], [[1]])]\n sage: K.genuine_lowest_weight_vectors()\n (({-e[-2]+e[1], -e[-2]+e[2], -e[-1]+e[1], -e[-1]+e[2]}, [[-1, -1]], [[2]]),)\n sage: sorted(K.lowest_weight_vectors(), key=str)\n [({-e[-1]+e[1], -e[-1]+e[2]}, [[-1, -1]], [[2]]),\n ({-e[-2]+e[1], -e[-2]+e[2], -e[-1]+e[1], -e[-1]+e[2]}, [[-1, -1]], [[2]]),\n ({-e[-2]+e[2], -e[-1]+e[1], -e[-1]+e[2]}, [[-1, -1]], [[1]]),\n ({-e[-2]+e[2], -e[-1]+e[1], -e[-1]+e[2]}, [[-1, -1]], [[2]])]\n\n REFERENCES:\n\n - [Kwon2012]_\n " @staticmethod def __classcall_private__(cls, cartan_type, la, mu): "\n Normalize input to ensure a unique representation.\n\n TESTS::\n\n sage: K1 = crystals.KacModule(['A', [2,1]], [2,1], [1])\n sage: K2 = crystals.KacModule(CartanType(['A', [2,1]]), (2,1), (1,))\n sage: K1 is K2\n True\n " cartan_type = CartanType(cartan_type) la = _Partitions(la) mu = _Partitions(mu) return super().__classcall__(cls, cartan_type, la, mu) def __init__(self, cartan_type, la, mu): "\n Initialize ``self``.\n\n TESTS::\n\n sage: K = crystals.KacModule(['A', [2,1]], [2,1], [1])\n sage: TestSuite(K).run()\n " self._cartan_type = cartan_type self._la = la self._mu = mu Parent.__init__(self, category=RegularSuperCrystals()) self._S = CrystalOfOddNegativeRoots(self._cartan_type) self._dual = CrystalOfTableaux(['A', self._cartan_type.m], shape=la) self._reg = CrystalOfTableaux(['A', self._cartan_type.n], shape=mu) data = (self._S.module_generators[0], self._dual.module_generators[0], self._reg.module_generators[0]) self.module_generators = (self.element_class(self, data),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.KacModule(['A', [2,1]], [3,1], [1])\n Crystal of Kac module K([3, 1], [1]) of type ['A', [2, 1]]\n " return 'Crystal of Kac module K({}, {}) of type {}'.format(self._la, self._mu, self._cartan_type) def module_generator(self): "\n Return the module generator of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KacModule(['A', [2,1]], [2,1], [1])\n sage: K.module_generator()\n ({}, [[-3, -3], [-2]], [[1]])\n " return self.module_generators[0] class Element(ElementWrapper): "\n An element of a Kac module crystal.\n\n TESTS:\n\n Check that `e_i` and `f_i` are psuedo-inverses::\n\n sage: K = crystals.KacModule(['A', [2,1]], [2,1], [1])\n sage: for x in K:\n ....: for i in K.index_set():\n ....: y = x.f(i)\n ....: assert y is None or y.e(i) == x\n " def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KacModule(['A', [2,1]], [2,1], [1])\n sage: mg = K.module_generator(); mg\n ({}, [[-3, -3], [-2]], [[1]])\n sage: mg.f_string([0,1,-2,1,-1,0,-1,-1,1,-2,-2])\n ({-e[-3]+e[2], -e[-1]+e[2]}, [[-2, -1], [-1]], [[2]])\n " return repr((self.value[0], to_dual_tableau(self.value[1]), self.value[2])) def _latex_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KacModule(['A', [2,1]], [2,1], [1])\n sage: mg = K.module_generator()\n sage: latex(mg)\n \\{\\}\n \\otimes {\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n \\raisebox{-.6ex}{$\\begin{array}[b]{*{2}c}\\cline{1-2}\n \\lr{\\overline{3}}&\\lr{\\overline{3}}\\\\\\cline{1-2}\n \\lr{\\overline{2}}\\\\\\cline{1-1}\n \\end{array}$}\n } \\otimes {\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n \\raisebox{-.6ex}{$\\begin{array}[b]{*{1}c}\\cline{1-1}\n \\lr{1}\\\\\\cline{1-1}\n \\end{array}$}\n }\n sage: latex(mg.f_string([0,1,-2,1,-1,0,-1,-1,1,-2,-2]))\n \\{-e_{-3}+e_{2}, -e_{-1}+e_{2}\\}\n \\otimes {\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n \\raisebox{-.6ex}{$\\begin{array}[b]{*{2}c}\\cline{1-2}\n \\lr{\\overline{2}}&\\lr{\\overline{1}}\\\\\\cline{1-2}\n \\lr{\\overline{1}}\\\\\\cline{1-1}\n \\end{array}$}\n } \\otimes {\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n \\raisebox{-.6ex}{$\\begin{array}[b]{*{1}c}\\cline{1-1}\n \\lr{2}\\\\\\cline{1-1}\n \\end{array}$}\n }\n " from sage.misc.latex import latex return ' \\otimes '.join([latex(self.value[0]), latex_dual(self.value[1]), latex(self.value[2])]) def e(self, i): "\n Return the action of the crystal operator `e_i` on ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KacModule(['A', [2,2]], [2,1], [1])\n sage: mg = K.module_generator()\n sage: mg.e(0)\n sage: mg.e(1)\n sage: mg.e(-1)\n sage: b = mg.f_string([1,0,1,-1,-2,0,1,2,0,-2,-1,-1,-1]); b\n ({-e[-3]+e[2], -e[-2]+e[1], -e[-2]+e[2]}, [[-3, -1], [-2]], [[3]])\n sage: b.e(-2)\n sage: b.e(-1)\n ({-e[-3]+e[2], -e[-2]+e[1], -e[-2]+e[2]}, [[-3, -2], [-2]], [[3]])\n sage: b.e(0)\n sage: b.e(1)\n ({-e[-3]+e[1], -e[-2]+e[1], -e[-2]+e[2]}, [[-3, -1], [-2]], [[3]])\n sage: b.e(2)\n ({-e[-3]+e[2], -e[-2]+e[1], -e[-2]+e[2]}, [[-3, -1], [-2]], [[2]])\n " if (i == 0): x = self.value[0].e(i) if (x is None): return None return type(self)(self.parent(), (x, self.value[1], self.value[2])) if (i > 0): if (self.value[0].epsilon(i) > self.value[2].phi(i)): x = self.value[0].e(i) if (x is None): return None return type(self)(self.parent(), (x, self.value[1], self.value[2])) else: x = self.value[2].e(i) if (x is None): return None return type(self)(self.parent(), (self.value[0], self.value[1], x)) M = (self.parent()._cartan_type.m + 1) if (self.value[0].phi(i) < self.value[1].epsilon((M + i))): x = self.value[1].e((M + i)) if (x is None): return None return type(self)(self.parent(), (self.value[0], x, self.value[2])) else: x = self.value[0].e(i) if (x is None): return None return type(self)(self.parent(), (x, self.value[1], self.value[2])) def f(self, i): "\n Return the action of the crystal operator `f_i` on ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KacModule(['A', [2,2]], [2,1], [1])\n sage: mg = K.module_generator()\n sage: mg.f(-2)\n ({}, [[-3, -2], [-2]], [[1]])\n sage: mg.f(-1)\n ({}, [[-3, -3], [-1]], [[1]])\n sage: mg.f(0)\n ({-e[-1]+e[1]}, [[-3, -3], [-2]], [[1]])\n sage: mg.f(1)\n ({}, [[-3, -3], [-2]], [[2]])\n sage: mg.f(2)\n sage: b = mg.f_string([1,0,1,-1,-2,0,1,2,0,-2,-1,2,0]); b\n ({-e[-3]+e[3], -e[-2]+e[1], -e[-1]+e[1], -e[-1]+e[2]},\n [[-3, -2], [-2]], [[3]])\n " if (i == 0): x = self.value[0].f(i) if (x is None): return None return type(self)(self.parent(), (x, self.value[1], self.value[2])) if (i > 0): if (self.value[0].epsilon(i) < self.value[2].phi(i)): x = self.value[2].f(i) if (x is None): return None return type(self)(self.parent(), (self.value[0], self.value[1], x)) else: x = self.value[0].f(i) if (x is None): return None return type(self)(self.parent(), (x, self.value[1], self.value[2])) M = (self.parent()._cartan_type.m + 1) if (self.value[0].phi(i) > self.value[1].epsilon((M + i))): x = self.value[0].f(i) if (x is None): return None return type(self)(self.parent(), (x, self.value[1], self.value[2])) else: x = self.value[1].f((M + i)) if (x is None): return None return type(self)(self.parent(), (self.value[0], x, self.value[2])) def weight(self): "\n Return weight of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KacModule(['A', [3,2]], [2,1], [5,1])\n sage: mg = K.module_generator()\n sage: mg.weight()\n (2, 1, 0, 0, 5, 1, 0)\n sage: mg.weight().is_dominant()\n True\n sage: mg.f(0).weight()\n (2, 1, 0, -1, 6, 1, 0)\n sage: b = mg.f_string([2,1,-3,-2,-1,1,1,0,-2,-1,2,1,1,1,0,2,-3,-2,-1])\n sage: b.weight()\n (0, 0, 0, 1, 1, 4, 3)\n " e = self.parent().weight_lattice_realization().basis() M = (self.parent()._cartan_type.m + 1) wt = self.value[0].weight() wt += sum(((c * e[(i - M)]) for (i, c) in self.value[1].weight())) wt += sum(((c * e[(i + 1)]) for (i, c) in self.value[2].weight())) return wt
def to_dual_tableau(elt): "\n Return a type `A_n` crystal tableau ``elt`` as a tableau expressed\n in terms of dual letters.\n\n The dual letter of `k` is expressed as `\\overline{n+2-k}` represented\n as `-(n+2-k)`.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kac_modules import to_dual_tableau\n sage: T = crystals.Tableaux(['A',2], shape=[2,1])\n sage: ascii_art([to_dual_tableau(t) for t in T])\n [ -3 -3 -3 -2 -3 -1 -3 -1 -2 -1 -3 -3 -3 -2 -2 -2 ]\n [ -2 , -2 , -2 , -1 , -1 , -1 , -1 , -1 ]\n\n TESTS:\n\n Check that :trac:`23935` is fixed::\n\n sage: from sage.combinat.crystals.kac_modules import to_dual_tableau\n sage: T = crystals.Tableaux(['A',2], shape=[])\n sage: to_dual_tableau(T[0])\n []\n\n sage: Ktriv = crystals.KacModule(['A',[1,1]], [], [])\n sage: Ktriv.module_generator()\n ({}, [], [])\n " from sage.combinat.tableau import Tableau M = (elt.parent().cartan_type().rank() + 2) if (not elt): return Tableau([]) tab = [[(elt[0].value - M)]] for i in range(1, len(elt)): if ((elt[(i - 1)] < elt[i]) or ((elt[(i - 1)].value != 0) and (elt[(i - 1)] == elt[i]))): tab.append([(elt[i].value - M)]) else: tab[(len(tab) - 1)].append((elt[i].value - M)) for x in tab: x.reverse() return Tableau(tab).conjugate()
def latex_dual(elt): "\n Return a latex representation of a type `A_n` crystal tableau ``elt``\n expressed in terms of dual letters.\n\n The dual letter of `k` is expressed as `\\overline{n+2-k}`.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kac_modules import latex_dual\n sage: T = crystals.Tableaux(['A',2], shape=[2,1])\n sage: print(latex_dual(T[0]))\n {\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n \\raisebox{-.6ex}{$\\begin{array}[b]{*{2}c}\\cline{1-2}\n \\lr{\\overline{3}}&\\lr{\\overline{3}}\\\\\\cline{1-2}\n \\lr{\\overline{2}}\\\\\\cline{1-1}\n \\end{array}$}\n }\n " M = (elt.parent().cartan_type().rank() + 2) from sage.combinat.tableau import Tableau from sage.combinat.output import tex_from_array if (not elt): return '{\\emptyset}' tab = [['\\overline{{{}}}'.format((M - elt[0].value))]] for i in range(1, len(elt)): if ((elt[(i - 1)] < elt[i]) or ((elt[(i - 1)].value != 0) and (elt[(i - 1)] == elt[i]))): tab.append(['\\overline{{{}}}'.format((M - elt[i].value))]) else: l = (len(tab) - 1) tab[l].append('\\overline{{{}}}'.format((M - elt[i].value))) for x in tab: x.reverse() T = Tableau(tab).conjugate() return tex_from_array([list(row) for row in T])
def KirillovReshetikhinCrystalFromLSPaths(cartan_type, r, s=1): "\n Single column Kirillov-Reshetikhin crystals.\n\n This yields the single column Kirillov-Reshetikhin crystals\n from the projected level zero LS paths, see\n :class:`~sage.combinat.crystals.littelmann_path.CrystalOfLSPaths`.\n This works for all types (even exceptional types).\n The weight of the canonical element in this crystal is `\\Lambda_r`.\n For other implementation see\n :func:`~sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinCrystal`.\n\n EXAMPLES::\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['A',2,1],2) # indirect doctest\n sage: KR = crystals.KirillovReshetikhin(['A',2,1],2,1)\n sage: G = K.digraph()\n sage: GR = KR.digraph()\n sage: G.is_isomorphic(GR, edge_labels = True)\n True\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['C',3,1],2)\n sage: KR = crystals.KirillovReshetikhin(['C',3,1],2,1)\n sage: G = K.digraph()\n sage: GR = KR.digraph()\n sage: G.is_isomorphic(GR, edge_labels = True)\n True\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['E',6,1],1)\n sage: KR = crystals.KirillovReshetikhin(['E',6,1],1,1)\n sage: G = K.digraph()\n sage: GR = KR.digraph()\n sage: G.is_isomorphic(GR, edge_labels = True)\n True\n sage: K.cardinality()\n 27\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['G',2,1],1)\n sage: K.cardinality()\n 7\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['B',3,1],2)\n sage: KR = crystals.KirillovReshetikhin(['B',3,1],2,1)\n sage: KR.cardinality()\n 22\n sage: K.cardinality()\n 22\n sage: G = K.digraph()\n sage: GR = KR.digraph()\n sage: G.is_isomorphic(GR, edge_labels = True)\n True\n\n TESTS::\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['G',2,1],2)\n sage: K.cardinality()\n 15\n\n For `s > 1` these crystals yield `s`-fold tensor products of\n Kirillov-Reshetikhin crystals::\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['A',1,1],1,3)\n sage: B = crystals.KirillovReshetikhin(['A',1,1],1,1)\n sage: T = crystals.TensorProduct(B,B,B)\n sage: G = K.digraph()\n sage: GT = T.digraph()\n sage: G.is_isomorphic(GT, edge_labels = True)\n True\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['B',2,1],1,2)\n sage: B = crystals.KirillovReshetikhin(['B',2,1],1,1)\n sage: T = crystals.TensorProduct(B,B)\n sage: G = K.digraph()\n sage: GT = T.digraph()\n sage: G.is_isomorphic(GT, edge_labels = True)\n True\n\n sage: K = crystals.kirillov_reshetikhin.LSPaths(['B',2,1],2,3)\n sage: B = crystals.KirillovReshetikhin(['B',2,1],2,1)\n sage: T = crystals.TensorProduct(B,B,B)\n sage: GT = T.digraph()\n sage: G = K.digraph()\n sage: G.is_isomorphic(GT, edge_labels = True)\n True\n " R = RootSystem(cartan_type) La = R.weight_space().basis() weight = (s * La[r]) return CrystalOfProjectedLevelZeroLSPaths(weight)
def KirillovReshetikhinCrystal(cartan_type, r, s, model='KN'): "\n Return the Kirillov-Reshetikhin crystal `B^{r,s}` of the given type\n in the given model.\n\n For more information about general crystals see\n :mod:`sage.combinat.crystals.crystals`.\n\n There are a variety of models for Kirillov-Reshetikhin crystals. There is\n one using the classical crystal with :func:`Kashiwara-Nakashima tableaux\n <sage.combinat.crystals.kirillov_reshetikhin.KashiwaraNakashimaTableaux>`.\n There is one using :class:`rigged configurations <RiggedConfigurations>`.\n Another tableaux model comes from the bijection between rigged configurations\n and tensor products of tableaux called :class:`Kirillov-Reshetikhin tableaux\n <sage.combinat.rigged_configurations.kr_tableaux.KirillovReshetikhinTableaux>`\n Lastly there is a model of Kirillov-Reshetikhin crystals for `s = 1` from\n crystals of :func:`LS paths\n <sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinCrystalFromLSPaths>`.\n\n INPUT:\n\n - ``cartan_type`` -- an affine Cartan type\n\n - ``r`` -- a label of finite Dynkin diagram\n\n - ``s`` -- a positive integer\n\n - ``model`` -- (default: ``'KN'``) can be one of the following:\n\n * ``'KN'`` or ``'KashiwaraNakashimaTableaux'`` - use the\n Kashiwara-Nakashima tableaux model\n * ``'KR'`` or ``'KirillovReshetkihinTableaux'`` - use the\n Kirillov-Reshetkihin tableaux model\n * ``'RC'`` or ``'RiggedConfiguration'`` - use the rigged\n configuration model\n * ``'LSPaths'`` - use the LS path model\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2, 1)\n sage: K.index_set()\n (0, 1, 2, 3)\n sage: K.list()\n [[[1], [2]], [[1], [3]], [[2], [3]], [[1], [4]], [[2], [4]], [[3], [4]]]\n sage: b=K(rows=[[1],[2]])\n sage: b.weight()\n -Lambda[0] + Lambda[2]\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: K.automorphism(K.module_generators[0])\n [[2, 2], [3, 3]]\n sage: K.module_generators[0].e(0)\n [[1, 2], [2, 4]]\n sage: K.module_generators[0].f(2)\n [[1, 1], [2, 3]]\n sage: K.module_generators[0].f(1)\n sage: K.module_generators[0].phi(0)\n 0\n sage: K.module_generators[0].phi(1)\n 0\n sage: K.module_generators[0].phi(2)\n 2\n sage: K.module_generators[0].epsilon(0)\n 2\n sage: K.module_generators[0].epsilon(1)\n 0\n sage: K.module_generators[0].epsilon(2)\n 0\n sage: b = K(rows=[[1,2],[2,3]])\n sage: b\n [[1, 2], [2, 3]]\n sage: b.f(2)\n [[1, 2], [3, 3]]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2, 1)\n sage: K.cartan_type()\n ['D', 4, 1]\n sage: type(K.module_generators[0])\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_vertical_with_category.element_class'>\n\n The following gives some tests with regards to Lemma 3.11 in [LOS2012]_.\n\n TESTS::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2],2,1)\n sage: Lambda = K.weight_lattice_realization().fundamental_weights()\n sage: [b for b in K if b.Epsilon() == Lambda[0]]\n [[]]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],1,2)\n sage: Lambda = K.weight_lattice_realization().fundamental_weights()\n sage: [b for b in K if b.Epsilon() == 2*Lambda[0]]\n [[]]\n sage: [b for b in K if b.Epsilon() == 2*Lambda[3]]\n [[[3, -3]]]\n sage: K = crystals.KirillovReshetikhin(['D',4,2],1,1)\n sage: [b for b in K if b.Epsilon() == Lambda[3]]\n [[[0]]]\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],2,1)\n sage: Lambda = K.weight_lattice_realization().fundamental_weights()\n sage: [b for b in K if b.Epsilon() == Lambda[0]]\n [[]]\n sage: [b for b in K if b.Epsilon() == Lambda[1]]\n [[[2], [-2]]]\n sage: K = crystals.KirillovReshetikhin(['B',3,1],2,2)\n sage: [b for b in K if b.Epsilon() == 2*Lambda[0]]\n [[]]\n sage: [b for b in K if b.Epsilon() == 2*Lambda[1]]\n [[[1, 2], [-2, -1]]]\n sage: K = crystals.KirillovReshetikhin(['B',3,1],2,3)\n sage: [b for b in K if b.Epsilon() == 3*Lambda[1]] # long time\n [[[1, 2, 2], [-2, -2, -1]]]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],2,2)\n sage: Lambda = K.weight_lattice_realization().fundamental_weights()\n sage: [b for b in K if b.Epsilon() == 2*Lambda[0]] # long time\n [[]]\n sage: [b for b in K if b.Epsilon() == 2*Lambda[4]] # long time\n [[[3, -4], [4, -3]]]\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,1)\n sage: Lambda = K.weight_lattice_realization().fundamental_weights()\n sage: [b for b in K if b.Epsilon() == Lambda[0]]\n [[+++, []]]\n sage: [b for b in K if b.Epsilon() == Lambda[1]]\n [[-++, []]]\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,3)\n sage: [b for b in K if b.Epsilon() == 2*Lambda[0]] # long time\n [[+++, [[1]]]]\n sage: [b for b in K if b.Epsilon() == 2*Lambda[1]] # long time\n [[-++, [[-1]]]]\n\n sage: K = crystals.KirillovReshetikhin(['B',4,1],4,1)\n sage: Lambda = K.weight_lattice_realization().fundamental_weights()\n sage: [b for b in K if b.Epsilon() == Lambda[0]]\n [[++++, []]]\n sage: [b for b in K if b.Epsilon() == Lambda[1]]\n [[-+++, []]]\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1],1,1)\n sage: Lambda = K.weight_lattice_realization().fundamental_weights()\n sage: [b for b in K if b.Epsilon() == Lambda[0]]\n [[[1]]]\n sage: [b for b in K if b.Epsilon() == Lambda[3]]\n [[[-3]]]\n sage: K = crystals.KirillovReshetikhin(['C',3,1],1,3)\n sage: [b for b in K if b.Epsilon() == 2*Lambda[3]] # long time\n [[[3, -3, -3]]]\n sage: [b for b in K if b.Epsilon() == 2*Lambda[0]] # long time\n [[[1]]]\n\n We check the various models agree::\n\n sage: KN = crystals.KirillovReshetikhin(['D',4,1], 2, 1)\n sage: KR = crystals.KirillovReshetikhin(['D',4,1], 2, 1, model='KR')\n sage: RC = crystals.KirillovReshetikhin(['D',4,1], 2, 1, model='RC')\n sage: LS = crystals.KirillovReshetikhin(['D',4,1], 2, 1, model='LSPaths')\n sage: G = KN.digraph()\n sage: G.is_isomorphic(KR.digraph(), edge_labels=True)\n True\n sage: G.is_isomorphic(RC.digraph(), edge_labels=True)\n True\n sage: G.is_isomorphic(LS.digraph(), edge_labels=True)\n True\n\n sage: KN = crystals.KirillovReshetikhin(['D',4,1], 2, 1)\n sage: KN2 = crystals.KirillovReshetikhin(['D',4,1], 2, 1, model='KN')\n sage: KN3 = crystals.KirillovReshetikhin(['D',4,1], 2, 1, model='KashiwaraNakashimaTableaux')\n sage: KN is KN2 and KN is KN3\n True\n\n REFERENCES:\n\n - [Shi2002]_\n\n - [Sch2008]_\n\n - [JS2010]_\n\n - [FOS2009]_\n\n - [LOS2012]_\n " if (model in ['KN', 'KashiwaraNakashimaTableaux']): return KashiwaraNakashimaTableaux(cartan_type, r, s) if (model in ['KR', 'KirillovReshetikhinTableaux']): from sage.combinat.rigged_configurations.kr_tableaux import KirillovReshetikhinTableaux return KirillovReshetikhinTableaux(cartan_type, r, s) if (model in ['RC', 'RiggedConfigurations']): from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations return RiggedConfigurations(cartan_type, [[r, s]]) if (model == 'LSPaths'): return KirillovReshetikhinCrystalFromLSPaths(cartan_type, r, s) raise ValueError('invalid model')
def KashiwaraNakashimaTableaux(cartan_type, r, s): "\n Return the Kashiwara-Nakashima model for the Kirillov-Reshetikhin crystal\n `B^{r,s}` in the given type.\n\n The Kashiwara-Nakashima (KN) model constructs the KR crystal from the\n KN tableaux model for the corresponding classical crystals. This model\n is named for the underlying KN tableaux.\n\n Many Kirillov-Reshetikhin crystals are constructed from a\n classical crystal together with an automorphism `p` on the level of\n crystals which corresponds to a Dynkin diagram automorphism mapping\n node 0 to some other node `i`. The action of `f_0` and `e_0` is then\n constructed using `f_0 = p^{-1} \\circ f_i \\circ p`.\n\n For example, for type `A_n^{(1)}` the Kirillov-Reshetikhin crystal `B^{r,s}`\n is obtained from the classical crystal `B(s \\omega_r)` using the\n promotion operator. For other types, see [Shi2002]_, [Sch2008]_,\n and [JS2010]_.\n\n Other Kirillov-Reshetikhin crystals are constructed using similarity methods.\n See Section 4 of [FOS2009]_.\n\n For more information on Kirillov-Reshetikhin crystals, see\n :func:`~sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinCrystal`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2, 1)\n sage: K2 = crystals.kirillov_reshetikhin.KashiwaraNakashimaTableaux(['A',3,1], 2, 1)\n sage: K is K2\n True\n " ct = CartanType(cartan_type) assert ct.is_affine() if ct.is_untwisted_affine(): if (ct.type() == 'A'): return KR_type_A(ct, r, s) elif (ct.type() == 'D'): if (r < (ct.rank() - 2)): return KR_type_vertical(ct, r, s) elif (r in {(ct.rank() - 2), (ct.rank() - 1)}): return KR_type_spin(ct, r, s) else: raise ValueError('wrong range of parameters') elif (ct.type() == 'B'): if (r < (ct.rank() - 1)): return KR_type_vertical(ct, r, s) elif (r == (ct.rank() - 1)): return KR_type_Bn(ct, r, s) else: raise ValueError('wrong range of parameters') elif (ct.type() == 'C'): if (r < (ct.rank() - 1)): return KR_type_C(ct, r, s) elif (r == (ct.rank() - 1)): return KR_type_Cn(ct, r, s) else: raise ValueError('wrong range of parameters') elif ((ct == CartanType(['E', 6, 1])) and (r in [1, 6, 2])): return KR_type_E6(ct, r, s) elif ((ct == CartanType(['E', 7, 1])) and (r in [7])): return KR_type_E7(ct, r, s) else: raise NotImplementedError elif (ct.dual().type() == 'B'): return KR_type_vertical(ct, r, s) elif (ct.type() == 'BC'): return KR_type_box(ct, r, s) elif (ct.dual().type() == 'BC'): return KR_type_A2(ct, r, s) elif (ct.dual().type() == 'C'): if (r < (ct.rank() - 1)): return KR_type_box(ct, r, s) elif (r == (ct.rank() - 1)): return KR_type_Dn_twisted(ct, r, s) else: raise ValueError('wrong range of parameters') elif (ct.dual().type() == 'G'): if (r == 1): return KR_type_D_tri1(ct, s) raise NotImplementedError else: raise NotImplementedError
class KirillovReshetikhinGenericCrystal(AffineCrystalFromClassical): '\n Generic class for Kirillov-Reshetikhin crystal `B^{r,s}` of the given type.\n\n Input is a Dynkin node ``r``, a positive integer ``s``, and a Cartan type\n ``cartan_type``.\n ' def __init__(self, cartan_type, r, s, dual=None): "\n Initializes a generic Kirillov-Reshetikhin crystal.\n\n TESTS::\n\n sage: K = crystals.KirillovReshetikhin(CartanType(['A',2,1]), 1, 1)\n sage: K\n Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1)\n sage: K.r()\n 1\n sage: K.s()\n 1\n " Parent.__init__(self, category=KirillovReshetikhinCrystals()) if (dual is None): self._cartan_type = cartan_type else: self._cartan_type = CartanType(cartan_type).dual() self._r = r self._s = s self._dual = dual AffineCrystalFromClassical.__init__(self, cartan_type, self.classical_decomposition(), KirillovReshetikhinCrystals()) def _repr_(self): "\n EXAMPLES::\n\n sage: crystals.KirillovReshetikhin(CartanType(['A',2,1]), 1, 1) # indirect doctest\n Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1)\n " return ('Kirillov-Reshetikhin crystal of type %s with (r,s)=(%d,%d)' % (self.cartan_type(), self.r(), self.s())) def _element_constructor_(self, *args, **options): "\n Construct an element of ``self`` from the input.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1)\n sage: K(columns=[[2,1]])\n [[1], [2]]\n " from sage.combinat.rigged_configurations.kr_tableaux import KirillovReshetikhinTableauxElement if isinstance(args[0], KirillovReshetikhinTableauxElement): elt = args[0] if ((elt.cartan_type() != self.cartan_type()) or (elt.parent().r() != self._r) or (elt.parent().s() != self._s)): raise ValueError('the Kirillov-Reshetikhin tableau must have the same Cartan type and shape') to_hw = elt.to_classical_highest_weight() rows = [] letters = elt.parent().letters for (i, mult) in sorted(to_hw[0].classical_weight()): rows.append(([letters((i + 1))] * int(mult))) hw_elt = self(rows=rows) f_str = reversed(to_hw[1]) return hw_elt.f_string(f_str) return AffineCrystalFromClassical._element_constructor_(self, *args, **options) def module_generator(self): "\n Return the unique module generator of classical weight\n `s \\Lambda_r` of a Kirillov-Reshetikhin crystal `B^{r,s}`\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',2,1],1,2)\n sage: K.module_generator()\n [[1, 1]]\n sage: K = crystals.KirillovReshetikhin(['E',6,1],1,1)\n sage: K.module_generator()\n [(1,)]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],2,1)\n sage: K.module_generator()\n [[1], [2]]\n " R = self.weight_lattice_realization() Lambda = R.fundamental_weights() r = self.r() s = self.s() weight = ((s * Lambda[r]) - (((s * Lambda[0]) * Lambda[r].level()) / Lambda[0].level())) return [b for b in self.module_generators if (b.weight() == weight)][0] def r(self): "\n Return `r` of the underlying Kirillov-Reshetikhin crystal `B^{r,s}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2, 1)\n sage: K.r()\n 2\n " return self._r def s(self): "\n Return `s` of the underlying Kirillov-Reshetikhin crystal `B^{r,s}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2, 1)\n sage: K.s()\n 1\n " return self._s @cached_method def classically_highest_weight_vectors(self): "\n Return the classically highest weight vectors of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2)\n sage: K.classically_highest_weight_vectors()\n ([], [[1], [2]], [[1, 1], [2, 2]])\n " return tuple([self.retract(mg) for mg in self.classical_decomposition().module_generators]) def kirillov_reshetikhin_tableaux(self): "\n Return the corresponding set of\n :class:`~sage.combinat.rigged_configurations.kr_tableaux.KirillovReshetikhinTableaux`.\n\n EXAMPLES::\n\n sage: KRC = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2)\n sage: KRC.kirillov_reshetikhin_tableaux()\n Kirillov-Reshetikhin tableaux of type ['D', 4, 1] and shape (2, 2)\n " from sage.combinat.rigged_configurations.kr_tableaux import KirillovReshetikhinTableaux return KirillovReshetikhinTableaux(self.cartan_type(), self._r, self._s)
class KirillovReshetikhinGenericCrystalElement(AffineCrystalFromClassicalElement): '\n Abstract class for all Kirillov-Reshetikhin crystal elements.\n ' def _repr_diagram(self): "\n Return a string representation of ``self`` as a diagram.\n\n EXAMPLES::\n\n sage: C = crystals.KirillovReshetikhin(['D',4,1], 2,1)\n sage: print(C(2,1)._repr_diagram())\n 1\n 2\n " return self.lift()._repr_diagram() def pp(self): "\n Pretty print ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.KirillovReshetikhin(['D',4,1], 2,1)\n sage: C(2,1).pp()\n 1\n 2\n sage: C = crystals.KirillovReshetikhin(['B',3,1], 3,3)\n sage: C.module_generators[0].pp()\n + (X) 1\n +\n +\n " print(self._repr_diagram()) @cached_method def to_kirillov_reshetikhin_tableau(self): "\n Construct the corresponding\n :class:`~sage.combinat.rigged_configurations.kr_tableaux.KirillovReshetikhinTableauxElement`\n from ``self``.\n\n We construct the Kirillov-Reshetikhin tableau element as follows:\n\n 1. Let `\\lambda` be the shape of ``self``.\n 2. Determine a path `e_{i_1} e_{i_2} \\cdots e_{i_k}` to the highest\n weight.\n 3. Apply `f_{i_k} \\cdots f_{i_2} f_{i_1}` to a highest weight KR\n tableau from filling the shape `\\lambda`.\n\n EXAMPLES::\n\n sage: KRC = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1)\n sage: KRC(columns=[[2,1]]).to_kirillov_reshetikhin_tableau()\n [[1], [2]]\n sage: KRC = crystals.KirillovReshetikhin(['D', 4, 1], 2, 1)\n sage: KRC(rows=[]).to_kirillov_reshetikhin_tableau()\n [[1], [-1]]\n " return self.parent().kirillov_reshetikhin_tableaux()(self) @cached_method def to_tableau(self): "\n Return the :class:`Tableau` corresponding to ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.KirillovReshetikhin(['D',4,1], 2,1)\n sage: t = C(2,1).to_tableau(); t\n [[1], [2]]\n sage: type(t)\n <class 'sage.combinat.tableau.Tableaux_all_with_category.element_class'>\n " return self.lift().to_tableau() def lusztig_involution(self): "\n Return the classical Lusztig involution on ``self``.\n\n EXAMPLES::\n\n sage: KRC = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: elt = KRC(-1,2); elt\n [[2], [-1]]\n sage: elt.lusztig_involution()\n [[1], [-2]]\n " li = self.lift().lusztig_involution() return self.parent().retract(li)
class KirillovReshetikhinCrystalFromPromotion(KirillovReshetikhinGenericCrystal, AffineCrystalFromClassicalAndPromotion): '\n This generic class assumes that the Kirillov-Reshetikhin crystal is\n constructed from a classical crystal using the\n ``classical_decomposition`` and an automorphism ``promotion``\n and its inverse, which corresponds to a Dynkin diagram automorphism\n ``dynkin_diagram_automorphism``.\n\n Each instance using this class needs to implement the methods:\n\n - ``classical_decomposition``\n - ``promotion``\n - ``promotion_inverse``\n - ``dynkin_diagram_automorphism``\n ' def __init__(self, cartan_type, r, s): "\n TESTS::\n\n sage: K = crystals.KirillovReshetikhin(['B',2,1], 1, 1)\n sage: K\n Kirillov-Reshetikhin crystal of type ['B', 2, 1] with (r,s)=(1,1)\n sage: TestSuite(K).run()\n " KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r, s) AffineCrystalFromClassicalAndPromotion.__init__(self, cartan_type, self.classical_decomposition(), self.promotion(), self.promotion_inverse(), self.dynkin_diagram_automorphism(0), KirillovReshetikhinCrystals())
class KirillovReshetikhinCrystalFromPromotionElement(AffineCrystalFromClassicalAndPromotionElement, KirillovReshetikhinGenericCrystalElement): '\n Element for a Kirillov-Reshetikhin crystal from promotion.\n ' pass
class KR_type_A(KirillovReshetikhinCrystalFromPromotion): "\n Class of Kirillov-Reshetikhin crystals of type `A_n^{(1)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: b = K(rows=[[1,2],[2,4]])\n sage: b.f(0)\n [[1, 1], [2, 2]]\n " def classical_decomposition(self): "\n Specifies the classical crystal underlying the KR crystal of type A.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['A', 3] and shape(s) [[2, 2]]\n " return CrystalOfTableaux(self.cartan_type().classical(), shape=([self.s()] * self.r())) @cached_method def promotion(self): "\n Specifies the promotion operator used to construct the affine\n type `A` crystal.\n\n For type `A` this corresponds to the Dynkin diagram automorphism\n which `i \\mapsto i+1 \\mod n+1`, where `n` is the rank.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: b = K.classical_decomposition()(rows=[[1,2],[3,4]])\n sage: K.promotion()(b)\n [[1, 3], [2, 4]]\n " T = self.classical_crystal return CrystalDiagramAutomorphism(T, (lambda x: T(x.to_tableau().promotion(self._cartan_type[1]))), cache=False) @cached_method def promotion_inverse(self): "\n Specifies the inverse promotion operator used to construct the\n affine type `A` crystal.\n\n For type `A` this corresponds to the Dynkin diagram automorphism\n which `i \\mapsto i-1 \\mod n+1`, where `n` is the rank.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: b = K.classical_decomposition()(rows=[[1,3],[2,4]])\n sage: K.promotion_inverse()(b)\n [[1, 2], [3, 4]]\n sage: b = K.classical_decomposition()(rows=[[1,2],[3,3]])\n sage: K.promotion_inverse()(K.promotion()(b))\n [[1, 2], [3, 3]]\n " T = self.classical_crystal return CrystalDiagramAutomorphism(T, (lambda x: T(x.to_tableau().promotion_inverse(self._cartan_type[1]))), cache=False) def dynkin_diagram_automorphism(self, i): "\n Specifies the Dynkin diagram automorphism underlying the promotion\n action on the crystal elements. The automorphism needs to map node\n 0 to some other Dynkin node.\n\n For type `A` we use the Dynkin diagram automorphism which\n `i \\mapsto i+1 \\mod n+1`, where `n` is the rank.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: K.dynkin_diagram_automorphism(0)\n 1\n sage: K.dynkin_diagram_automorphism(3)\n 0\n " aut = (list(range(1, self.cartan_type().rank())) + [0]) return aut[i]
class KR_type_vertical(KirillovReshetikhinCrystalFromPromotion): "\n Class of Kirillov-Reshetikhin crystals `B^{r,s}` of type\n `D_n^{(1)}` for `r \\le n-2`, `B_n^{(1)}` for `r < n`, and\n `A_{2n-1}^{(2)}` for `r \\le n`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: b = K(rows=[])\n sage: b.f(0)\n [[1], [2]]\n sage: b.f(0).f(0)\n [[1, 1], [2, 2]]\n sage: b.e(0)\n [[-2], [-1]]\n sage: b.e(0).e(0)\n [[-2, -2], [-1, -1]]\n\n sage: K = crystals.KirillovReshetikhin(['D',5,1], 3,1)\n sage: b = K(rows=[[1]])\n sage: b.e(0)\n [[3], [-3], [-2]]\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1], 1,1)\n sage: [[b,b.f(0)] for b in K]\n [[[[1]], None], [[[2]], None], [[[3]], None], [[[0]], None],\n [[[-3]], None], [[[-2]], [[1]]], [[[-1]], [[2]]]]\n\n sage: K = crystals.KirillovReshetikhin(['A',5,2], 1,1)\n sage: [[b,b.f(0)] for b in K]\n [[[[1]], None], [[[2]], None], [[[3]], None], [[[-3]], None],\n [[[-2]], [[1]]], [[[-1]], [[2]]]]\n " def classical_decomposition(self): "\n Specifies the classical crystal underlying the Kirillov-Reshetikhin\n crystal of type `D_n^{(1)}`, `B_n^{(1)}`, and `A_{2n-1}^{(2)}`.\n\n It is given by `B^{r,s} \\cong \\bigoplus_\\Lambda B(\\Lambda)`,\n where `\\Lambda` are weights obtained from a rectangle of width `s`\n and height `r` by removing vertical dominoes. Here we identify\n the fundamental weight `\\Lambda_i` with a column of height `i`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['D', 4] and shape(s) [[], [1, 1], [2, 2]]\n " return CrystalOfTableaux(self.cartan_type().classical(), shapes=vertical_dominoes_removed(self.r(), self.s())) @cached_method def promotion(self): "\n Specifies the promotion operator used to construct the affine\n type `D_n^{(1)}` etc. crystal.\n\n This corresponds to the Dynkin diagram automorphism which\n interchanges nodes 0 and 1, and leaves all other nodes unchanged.\n On the level of crystals it is constructed using `\\pm` diagrams.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: promotion = K.promotion()\n sage: b = K.classical_decomposition()(rows=[])\n sage: promotion(b)\n [[1, 2], [-2, -1]]\n sage: b = K.classical_decomposition()(rows=[[1,3],[2,-1]])\n sage: promotion(b)\n [[1, 3], [2, -1]]\n sage: b = K.classical_decomposition()(rows=[[1],[-3]])\n sage: promotion(b)\n [[2, -3], [-2, -1]]\n " T = self.classical_decomposition() ind = list(T.index_set()) ind.remove(1) return CrystalDiagramAutomorphism(T, self.promotion_on_highest_weight_vector, ind) def promotion_inverse(self): "\n Return inverse of promotion.\n\n In this case promotion is an involution, so promotion\n inverse equals promotion.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: promotion = K.promotion()\n sage: promotion_inverse = K.promotion_inverse()\n sage: all( promotion_inverse(promotion(b.lift())) == b.lift() for b in K )\n True\n " return self.promotion() def dynkin_diagram_automorphism(self, i): "\n Specifies the Dynkin diagram automorphism underlying the promotion\n action on the crystal elements. The automorphism needs to map\n node 0 to some other Dynkin node.\n\n Here we use the Dynkin diagram automorphism which interchanges\n nodes 0 and 1 and leaves all other nodes unchanged.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],1,1)\n sage: K.dynkin_diagram_automorphism(0)\n 1\n sage: K.dynkin_diagram_automorphism(1)\n 0\n sage: K.dynkin_diagram_automorphism(4)\n 4\n " aut = ([1, 0] + list(range(2, self.cartan_type().rank()))) return aut[i] def promotion_on_highest_weight_vector(self, b): "\n Calculates promotion on a `{2,3,...,n}` highest weight vector ``b``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: T = K.classical_decomposition()\n sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3,4]) ]\n sage: [K.promotion_on_highest_weight_vector(b) for b in hw]\n [[[1, 2], [-2, -1]], [[2, 2], [-2, -1]], [[1, 2], [3, -1]],\n [[2], [-2]], [[1, 2], [2, -2]], [[2, 2], [-1, -1]],\n [[2, 2], [3, -1]], [[2, 2], [3, 3]], [], [[1], [2]],\n [[1, 1], [2, 2]], [[2], [-1]], [[1, 2], [2, -1]],\n [[2], [3]], [[1, 2], [2, 3]]]\n " return self.from_pm_diagram_to_highest_weight_vector(self.from_highest_weight_vector_to_pm_diagram(b).sigma()) def from_highest_weight_vector_to_pm_diagram(self, b): "\n This gives the bijection between an element ``b`` in the classical\n decomposition of the KR crystal that is `{2, 3, \\ldots, n}`-highest\n weight and `\\pm` diagrams.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: T = K.classical_decomposition()\n sage: b = T(rows=[[2],[-2]])\n sage: pm = K.from_highest_weight_vector_to_pm_diagram(b); pm\n [[1, 1], [0, 0], [0]]\n sage: pm.pp()\n +\n -\n sage: b = T(rows=[])\n sage: pm=K.from_highest_weight_vector_to_pm_diagram(b); pm\n [[0, 2], [0, 0], [0]]\n sage: pm.pp()\n\n sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3,4]) ]\n sage: all(K.from_pm_diagram_to_highest_weight_vector(K.from_highest_weight_vector_to_pm_diagram(b)) == b for b in hw)\n True\n " n = (self.cartan_type().rank() - 1) inner = Partition([Integer(b.weight()[i]) for i in range(1, (n + 1))]) inter = Partition([len([i for i in r if (i > 0)]) for r in b.to_tableau()]) outer = b.to_tableau().shape() return PMDiagram([self.r(), self.s(), outer, inter, inner], from_shapes=True) def from_pm_diagram_to_highest_weight_vector(self, pm): "\n This gives the bijection between a `\\pm` diagram and an element\n ``b`` in the classical decomposition of the KR crystal that\n is `{2, 3, \\ldots, n}`-highest weight.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,2)\n sage: pm = sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1, 1], [0, 0], [0]])\n sage: K.from_pm_diagram_to_highest_weight_vector(pm)\n [[2], [-2]]\n " u = [b for b in self.classical_decomposition().module_generators if (b.to_tableau().shape() == pm.outer_shape())][0] ct = self.cartan_type() rank = (ct.rank() - 1) ct_type = ct.classical().type() assert (ct_type in ['B', 'C', 'D']) ulist = [] for h in pm.heights_of_addable_plus(): ulist += list(range(1, (h + 1))) for h in pm.heights_of_minus(): if (ct_type == 'D'): ulist += (list(range(1, (rank + 1))) + [((rank - 2) - k) for k in range(((rank - 1) - h))]) elif (ct_type == 'B'): ulist += (list(range(1, (rank + 1))) + [(rank - k) for k in range(((rank + 1) - h))]) else: ulist += (list(range(1, (rank + 1))) + [((rank - 1) - k) for k in range((rank - h))]) for i in reversed(ulist): u = u.f(i) return u
class KR_type_E6(KirillovReshetikhinCrystalFromPromotion): "\n Class of Kirillov-Reshetikhin crystals of type `E_6^{(1)}` for `r=1,2,6`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: K.module_generator().e(0)\n []\n sage: K.module_generator().e(0).f(0)\n [[(2, -1), (1,)]]\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 1,1)\n sage: b = K.module_generator()\n sage: b\n [(1,)]\n sage: b.e(0)\n [(-2, 1)]\n sage: b = [t for t in K if t.epsilon(1) == 1 and t.phi(3) == 1 and t.phi(2) == 0 and t.epsilon(2) == 0][0]\n sage: b\n [(-1, 3)]\n sage: b.e(0)\n [(-1, -2, 3)]\n\n The elements of the Kirillov-Reshetikhin crystals can be constructed from\n a classical crystal element using\n :meth:`~sage.combinat.crystals.affine.AffineCrystalFromClassical.retract()`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: La = K.cartan_type().classical().root_system().weight_lattice().fundamental_weights()\n sage: H = crystals.HighestWeight(La[2])\n sage: t = H.module_generator()\n sage: t\n [[(2, -1), (1,)]]\n sage: type(K.retract(t))\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_E6_with_category.element_class'>\n sage: K.retract(t).e(0)\n []\n\n TESTS::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 2,1)\n sage: La = K.weight_lattice_realization().fundamental_weights()\n sage: all(b.weight() == sum( (K.affine_weight(b.lift())[i] * La[i] for i in K.index_set()), 0*La[0]) for b in K) # long time (26s on sage.math, 2011)\n True\n " def classical_decomposition(self): "\n Specifies the classical crystal underlying the KR crystal\n of type `E_6^{(1)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 2,2)\n sage: K.classical_decomposition()\n Direct sum of the crystals Family\n (Finite dimensional highest weight crystal of type ['E', 6] and highest weight 0,\n Finite dimensional highest weight crystal of type ['E', 6] and highest weight Lambda[2],\n Finite dimensional highest weight crystal of type ['E', 6] and highest weight 2*Lambda[2])\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 1,2)\n sage: K.classical_decomposition()\n Direct sum of the crystals Family\n (Finite dimensional highest weight crystal of type ['E', 6] and highest weight 2*Lambda[1],)\n " La = self.cartan_type().classical().root_system().weight_lattice().fundamental_weights() if (self.r() in [1, 6]): dw = [(self.s() * La[self.r()])] elif (self.r() == 2): dw = [(k * La[2]) for k in range((self.s() + 1))] else: raise NotImplementedError return DirectSumOfCrystals([HighestWeightCrystal(dominant_weight) for dominant_weight in dw], keepkey=False) def dynkin_diagram_automorphism(self, i): "\n Specifies the Dynkin diagram automorphism underlying the promotion\n action on the crystal elements.\n\n Here we use the Dynkin diagram automorphism of order 3 which maps\n node 0 to node 1.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: [K.dynkin_diagram_automorphism(i) for i in K.index_set()]\n [1, 6, 3, 5, 4, 2, 0]\n " aut = [1, 6, 3, 5, 4, 2, 0] return aut[i] def affine_weight(self, b): "\n Return the affine level zero weight corresponding to the element\n ``b`` of the classical crystal underlying ``self``.\n\n For the coefficients to calculate the level, see Table Aff 1\n in [Ka1990]_.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: [K.affine_weight(x.lift()) for x in K\n ....: if all(x.epsilon(i) == 0 for i in [2,3,4,5])]\n [(0, 0, 0, 0, 0, 0, 0),\n (-2, 0, 1, 0, 0, 0, 0),\n (-1, -1, 0, 0, 0, 1, 0),\n (0, 0, 0, 0, 0, 0, 0),\n (0, 0, 0, 0, 0, 1, -2),\n (0, -1, 1, 0, 0, 0, -1),\n (-1, 0, 0, 1, 0, 0, -1),\n (-1, -1, 0, 0, 1, 0, -1),\n (0, 0, 0, 0, 0, 0, 0),\n (0, -2, 0, 1, 0, 0, 0)]\n " cl = self.cartan_type().classical() simple_roots = cl.root_system().ambient_space().simple_roots() index_set = cl.index_set() weight = [Integer(b.weight().scalar(simple_roots[i])) for i in index_set] E6_coeffs = [1, 2, 2, 3, 2, 1] return tuple(([(- sum(((weight[i] * coeff) for (i, coeff) in enumerate(E6_coeffs))))] + weight)) @cached_method def hw_auxiliary(self): "\n Return the `{2,3,4,5}` highest weight elements of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: K.hw_auxiliary()\n ([], [[(2, -1), (1,)]],\n [[(5, -3), (-1, 3)]],\n [[(6, -2), (-6, 2)]],\n [[(5, -2, -6), (-6, 2)]],\n [[(-1,), (-6, 2)]],\n [[(3, -1, -6), (1,)]],\n [[(4, -3, -6), (-1, 3)]],\n [[(1, -3), (-1, 3)]],\n [[(-1,), (-1, 3)]])\n " return tuple([x for x in self.classical_decomposition() if all(((x.epsilon(i) == 0) for i in [2, 3, 4, 5]))]) @cached_method def highest_weight_dict(self): "\n Return a dictionary between `\\{1,2,3,4,5\\}`-highest weight elements,\n and a tuple of affine weights and its classical component.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: sorted(K.highest_weight_dict().items(), key=str)\n [([[(2, -1), (1,)]], ((-2, 0, 1, 0, 0, 0, 0), 1)),\n ([[(3, -1, -6), (1,)]], ((-1, 0, 0, 1, 0, 0, -1), 1)),\n ([[(5, -2, -6), (-6, 2)]], ((0, 0, 0, 0, 0, 1, -2), 1)),\n ([[(6, -2), (-6, 2)]], ((0, 0, 0, 0, 0, 0, 0), 1)),\n ([], ((0, 0, 0, 0, 0, 0, 0), 0))]\n " hw = [x for x in self.hw_auxiliary() if (x.epsilon(1) == 0)] dic = {x: (self.affine_weight(x), len(x)) for x in hw} assert (len(hw) == len(dic)) return dic @cached_method def highest_weight_dict_inv(self): "\n Return a dictionary between a tuple of affine weights and a classical\n component, and `\\{2,3,4,5,6\\}`-highest weight elements.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: K.highest_weight_dict_inv()\n {((-2, 0, 1, 0, 0, 0, 0), 1): [[(2, -1), (1,)]],\n ((-1, -1, 0, 0, 0, 1, 0), 1): [[(5, -3), (-1, 3)]],\n ((0, -2, 0, 1, 0, 0, 0), 1): [[(-1,), (-1, 3)]],\n ((0, 0, 0, 0, 0, 0, 0), 0): [],\n ((0, 0, 0, 0, 0, 0, 0), 1): [[(1, -3), (-1, 3)]]}\n " hw = [x for x in self.hw_auxiliary() if (x.epsilon(6) == 0)] dic = {(self.affine_weight(x), len(x)): x for x in hw} assert (len(hw) == len(dic)) return dic def automorphism_on_affine_weight(self, weight): "\n Act with the Dynkin diagram automorphism on affine weights\n as outputted by the ``affine_weight`` method.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1],2,1)\n sage: sorted([x[0], K.automorphism_on_affine_weight(x[0])]\n ....: for x in K.highest_weight_dict().values())\n [[(-2, 0, 1, 0, 0, 0, 0), (0, -2, 0, 1, 0, 0, 0)],\n [(-1, 0, 0, 1, 0, 0, -1), (-1, -1, 0, 0, 0, 1, 0)],\n [(0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0)],\n [(0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0, 0)],\n [(0, 0, 0, 0, 0, 1, -2), (-2, 0, 1, 0, 0, 0, 0)]]\n " f = self.dynkin_diagram_automorphism return tuple([weight[f(f(i))] for i in self.index_set()]) @cached_method def promotion_on_highest_weight_vectors(self): "\n Return a dictionary of the promotion map on `\\{1,2,3,4,5\\}`-highest\n weight elements to `\\{2,3,4,5,6\\}`-highest weight elements\n in ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 2, 1)\n sage: dic = K.promotion_on_highest_weight_vectors()\n sage: sorted(dic.items(), key=str)\n [([[(2, -1), (1,)]], [[(-1,), (-1, 3)]]),\n ([[(3, -1, -6), (1,)]], [[(5, -3), (-1, 3)]]),\n ([[(5, -2, -6), (-6, 2)]], [[(2, -1), (1,)]]),\n ([[(6, -2), (-6, 2)]], []),\n ([], [[(1, -3), (-1, 3)]])]\n " dic = self.highest_weight_dict() dic_inv = self.highest_weight_dict_inv() dic_weight = {} for (weight, i) in dic.values(): dic_weight[weight] = (dic_weight.get(weight, []) + [i]) map_index = (lambda i_list: ((max(i_list[1]) + min(i_list[1])) - i_list[0])) map_element = (lambda x: (self.automorphism_on_affine_weight(dic[x][0]), map_index((dic[x][1], dic_weight[dic[x][0]])))) return {x: dic_inv[map_element(x)] for x in dic} @cached_method def promotion_on_highest_weight_vectors_function(self): "\n Return a lambda function on ``x`` defined by\n ``self.promotion_on_highest_weight_vectors()[x]``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 2, 1)\n sage: f = K.promotion_on_highest_weight_vectors_function()\n sage: f(K.module_generator().lift())\n [[(-1,), (-1, 3)]]\n " return self.promotion_on_highest_weight_vectors().__getitem__ @cached_method def promotion(self): "\n Specifies the promotion operator used to construct the\n affine type `E_6^{(1)}` crystal.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 2,1)\n sage: promotion = K.promotion()\n sage: all(promotion(promotion(promotion(b))) == b for b in K.classical_decomposition())\n True\n sage: K = crystals.KirillovReshetikhin(['E',6,1],1,1)\n sage: promotion = K.promotion()\n sage: all(promotion(promotion(promotion(b))) == b for b in K.classical_decomposition())\n True\n " T = self.classical_decomposition() ind = [1, 2, 3, 4, 5] return CrystalDiagramAutomorphism(T, self.promotion_on_highest_weight_vectors(), ind, automorphism=self.dynkin_diagram_automorphism) @cached_method def promotion_inverse(self): "\n Return the inverse promotion. Since promotion is of order 3,\n the inverse promotion is the same as promotion applied twice.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',6,1], 2,1)\n sage: p = K.promotion()\n sage: p_inv = K.promotion_inverse()\n sage: all(p_inv(p(b)) == b for b in K.classical_decomposition())\n True\n " p = self.promotion() return (p * p)
class KR_type_C(KirillovReshetikhinGenericCrystal): "\n Class of Kirillov-Reshetikhin crystals `B^{r,s}` of type `C_n^{(1)}`\n for `r < n`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',2,1], 1,2)\n sage: K\n Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(1,2)\n sage: b = K(rows=[])\n sage: b.f(0)\n [[1, 1]]\n sage: b.e(0)\n [[-1, -1]]\n " def classical_decomposition(self): "\n Return the classical crystal underlying the Kirillov-Reshetikhin\n crystal of type `C_n^{(1)}`.\n\n It is given by `B^{r,s} \\cong \\bigoplus_{\\Lambda} B(\\Lambda)`,\n where `\\Lambda` are weights obtained from a rectangle of width `s`\n and height `r` by removing horizontal dominoes. Here we identify\n the fundamental weight `\\Lambda_i` with a column of height `i`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['C', 3] and shape(s) [[], [2], [2, 2]]\n " return CrystalOfTableaux(self.cartan_type().classical(), shapes=horizontal_dominoes_removed(self.r(), self.s())) def ambient_crystal(self): "\n Return the ambient crystal `B^{r,s}` of type `A_{2n+1}^{(2)}`\n associated to the Kirillov-Reshetikhin crystal of type `C_n^{(1)}`.\n\n This ambient crystal is used to construct the zero arrows.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,3)\n sage: K.ambient_crystal()\n Kirillov-Reshetikhin crystal of type ['B', 4, 1]^* with (r,s)=(2,3)\n " return KashiwaraNakashimaTableaux(['A', ((2 * self.cartan_type().classical().rank()) + 1), 2], self.r(), self.s()) @cached_method def ambient_dict_pm_diagrams(self): "\n Return a dictionary of all self-dual `\\pm` diagrams for the\n ambient crystal whose keys are their inner shape.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',2,1], 1,2)\n sage: K.ambient_dict_pm_diagrams()\n {[]: [[1, 1], [0]], [2]: [[0, 0], [2]]}\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2)\n sage: K.ambient_dict_pm_diagrams()\n {[]: [[1, 1], [0, 0], [0]],\n [2]: [[0, 0], [1, 1], [0]],\n [2, 2]: [[0, 0], [0, 0], [2]]}\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,3)\n sage: K.ambient_dict_pm_diagrams()\n {[1, 1]: [[1, 1], [0, 0], [1]],\n [3, 1]: [[0, 0], [1, 1], [1]],\n [3, 3]: [[0, 0], [0, 0], [3]]}\n " ulist = [] s = self.s() r = self.r() m = (s // 2) for i in range((m + 1)): for la in IntegerVectors((m - i), min_length=r, max_length=r): ulist.append(PMDiagram(([[j, j] for j in la] + [[((s - (2 * m)) + (2 * i))]]))) return {x.inner_shape(): x for x in ulist} @cached_method def ambient_highest_weight_dict(self): "\n Return a dictionary of all `\\{2,\\ldots,n+1\\}`-highest weight vectors\n in the ambient crystal.\n\n The key is the inner shape of their corresponding `\\pm` diagram,\n or equivalently, their `\\{2,\\ldots,n+1\\}` weight.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2)\n sage: K.ambient_highest_weight_dict()\n {[]: [[2], [-2]], [2]: [[1, 2], [2, -1]], [2, 2]: [[2, 2], [3, 3]]}\n " A = self.ambient_dict_pm_diagrams() ambient = self.ambient_crystal() return {key: ambient.retract(ambient.from_pm_diagram_to_highest_weight_vector(A[key])) for key in A} @cached_method def highest_weight_dict(self): "\n Return a dictionary of the classical highest weight vectors of\n ``self`` whose keys are their shape.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2)\n sage: K.highest_weight_dict()\n {[]: [], [2]: [[1, 1]], [2, 2]: [[1, 1], [2, 2]]}\n " return {x.lift().to_tableau().shape(): x for x in self.module_generators} @cached_method def to_ambient_crystal(self): "\n Return a map from the Kirillov-Reshetikhin crystal of type\n `C_n^{(1)}` to the ambient crystal of type `A_{2n+1}^{(2)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2)\n sage: b=K(rows=[[1,1]])\n sage: K.to_ambient_crystal()(b)\n [[1, 2], [2, -1]]\n sage: b=K(rows=[])\n sage: K.to_ambient_crystal()(b)\n [[2], [-2]]\n sage: K.to_ambient_crystal()(b).parent()\n Kirillov-Reshetikhin crystal of type ['B', 4, 1]^* with (r,s)=(2,2)\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict = {hwd[key]: ahwd[key] for key in hwd} classical = self.cartan_type().classical() return self.crystal_morphism(pdict, index_set=classical.index_set(), automorphism=(lambda i: (i + 1)), cartan_type=classical, check=False) @cached_method def from_ambient_crystal(self): "\n Return a map from the ambient crystal of type `A_{2n+1}^{(2)}` to\n the Kirillov-Reshetikhin crystal of type `C_n^{(1)}`.\n\n Note that this map is only well-defined on type `C_n^{(1)}` elements\n that are in the image under :meth:`to_ambient_crystal`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1], 2,2)\n sage: b = K.ambient_crystal()(rows=[[2,2],[3,3]])\n sage: K.from_ambient_crystal()(b)\n [[1, 1], [2, 2]]\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict_inv = {ahwd[key]: hwd[key] for key in hwd} ind = [(j + 1) for j in self.cartan_type().classical().index_set()] return AmbientRetractMap(self, self.ambient_crystal(), pdict_inv, index_set=ind, automorphism=(lambda i: (i - 1)))
class KR_type_CElement(KirillovReshetikhinGenericCrystalElement): "\n Class for the elements in the Kirillov-Reshetikhin crystals `B^{r,s}`\n of type `C_n^{(1)}` for `r<n`.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['C',3,1],1,2)\n sage: type(K.module_generators[0])\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_C_with_category.element_class'>\n " def e0(self): "\n Return `e_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `e_1 e_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['C',3,1],1,2)\n sage: b = K(rows=[])\n sage: b.e(0) # indirect doctest\n [[-1, -1]]\n " b = self.parent().to_ambient_crystal()(self).e(1) if (b is None): return None b = b.e(0) return self.parent().from_ambient_crystal()(b) def f0(self): "\n Return `f_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `f_1 f_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['C',3,1],1,2)\n sage: b = K(rows=[])\n sage: b.f(0) # indirect doctest\n [[1, 1]]\n " b = self.parent().to_ambient_crystal()(self).f(1) if (b is None): return None b = b.f(0) return self.parent().from_ambient_crystal()(b) def epsilon0(self): "\n Calculate `\\varepsilon_0` of ``self`` by mapping the element to\n the ambient crystal and calculating `\\varepsilon_1` there.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',2,1], 1,2)\n sage: b=K(rows=[[1,1]])\n sage: b.epsilon(0) # indirect doctest\n 2\n " b = self.parent().to_ambient_crystal()(self) return b.epsilon(1) def phi0(self): "\n Calculate `\\varphi_0` of ``self`` by mapping the element to\n the ambient crystal and calculating `\\varphi_1` there.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',2,1], 1,2)\n sage: b=K(rows=[[-1,-1]])\n sage: b.phi(0) # indirect doctest\n 2\n " b = self.parent().to_ambient_crystal()(self) return b.phi(1)
class KR_type_A2(KirillovReshetikhinGenericCrystal): "\n Class of Kirillov-Reshetikhin crystals `B^{r,s}` of type `A_{2n}^{(2)}`\n for `1 \\leq r \\leq n` in the realization with classical subalgebra `B_n`.\n The Cartan type in this case is inputted as the dual of `A_{2n}^{(2)}`.\n\n This is an alternative implementation to :class:`KR_type_box` that uses\n the classical decomposition into type `C_n` crystals.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 1)\n sage: K\n Kirillov-Reshetikhin crystal of type ['BC', 2, 2]^* with (r,s)=(1,1)\n sage: b = K(rows=[[-1]])\n sage: b.f(0)\n [[1]]\n sage: b.e(0)\n\n We can now check whether the two KR crystals of type `A_4^{(2)}`\n (namely the KR crystal and its dual construction) are isomorphic\n up to relabelling of the edges::\n\n sage: C = CartanType(['A',4,2])\n sage: K = crystals.KirillovReshetikhin(C,1,1)\n sage: Kdual = crystals.KirillovReshetikhin(C.dual(),1,1)\n sage: G = K.digraph()\n sage: Gdual = Kdual.digraph()\n sage: f = {0:2, 1:1, 2:0}\n sage: Gnew = DiGraph(); Gnew.add_vertices(Gdual.vertices(sort=True)); Gnew.add_edges([(u,v,f[i]) for (u,v,i) in Gdual.edges(sort=True)])\n sage: G.is_isomorphic(Gnew, edge_labels = True)\n True\n " def module_generator(self): "\n Return the unique module generator of classical weight\n `s \\Lambda_r` of a Kirillov-Reshetikhin crystal `B^{r,s}`.\n\n EXAMPLES::\n\n sage: ct = CartanType(['A',8,2]).dual()\n sage: K = crystals.KirillovReshetikhin(ct, 3, 5)\n sage: K.module_generator()\n [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3]]\n\n TESTS:\n\n Check that :trac:`23028` is fixed::\n\n sage: ct = CartanType(['A',8,2]).dual()\n sage: K = crystals.KirillovReshetikhin(ct, 4, 3)\n sage: K.module_generator()\n [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]\n sage: K = crystals.KirillovReshetikhin(ct, 4, 1)\n sage: K.module_generator()\n [[1], [2], [3], [4]]\n " R = self.weight_lattice_realization() Lambda = R.fundamental_weights() r = self.r() s = self.s() weight = ((s * Lambda[r]) - (s * Lambda[0])) if (r == (self.cartan_type().rank() - 1)): weight += (s * Lambda[r]) return [b for b in self.module_generators if (b.weight() == weight)][0] def classical_decomposition(self): "\n Return the classical crystal underlying the Kirillov-Reshetikhin\n crystal of type `A_{2n}^{(2)}` with `B_n` as classical subdiagram.\n\n It is given by `B^{r,s} \\cong \\bigoplus_{\\Lambda} B(\\Lambda)`,\n where `B(\\Lambda)` is a highest weight crystal of type `B_n`\n of highest weight `\\Lambda`. The sum is over all weights `\\Lambda`\n obtained from a rectangle of width `s` and height `r` by removing\n horizontal dominoes. Here we identify the fundamental weight\n `\\Lambda_i` with a column of height `i`.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 2, 2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['B', 2] and shape(s) [[], [2], [2, 2]]\n " return CrystalOfTableaux(['B', (self.cartan_type().rank() - 1)], shapes=horizontal_dominoes_removed(self.r(), self.s())) def ambient_crystal(self): "\n Return the ambient crystal `B^{r,s}` of type `B_{n+1}^{(1)}`\n associated to the Kirillov-Reshetikhin crystal of type\n `A_{2n}^{(2)}` dual.\n\n This ambient crystal is used to construct the zero arrows.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 2, 3)\n sage: K.ambient_crystal()\n Kirillov-Reshetikhin crystal of type ['B', 3, 1] with (r,s)=(2,3)\n " return KR_type_vertical(['B', self.cartan_type().rank(), 1], self.r(), self.s()) @cached_method def ambient_dict_pm_diagrams(self): "\n Return a dictionary of all self-dual `\\pm` diagrams for the\n ambient crystal whose keys are their inner shape.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 1)\n sage: K.ambient_dict_pm_diagrams()\n {[1]: [[0, 0], [1]]}\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 2)\n sage: K.ambient_dict_pm_diagrams()\n {[]: [[1, 1], [0]], [2]: [[0, 0], [2]]}\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 2, 2)\n sage: K.ambient_dict_pm_diagrams()\n {[]: [[1, 1], [0, 0], [0]],\n [2]: [[0, 0], [1, 1], [0]],\n [2, 2]: [[0, 0], [0, 0], [2]]}\n " ulist = [] s = self.s() r = self.r() m = (s // 2) for i in range((m + 1)): for la in IntegerVectors((m - i), min_length=r, max_length=r): ulist.append(PMDiagram(([[j, j] for j in la] + [[((s - (2 * m)) + (2 * i))]]))) return {x.inner_shape(): x for x in ulist} @cached_method def ambient_highest_weight_dict(self): "\n Return a dictionary of all `\\{2,\\ldots,n+1\\}`-highest weight vectors\n in the ambient crystal.\n\n The key is the inner shape of their corresponding `\\pm` diagram,\n or equivalently, their `\\{2,\\ldots,n+1\\}` weight.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 2)\n sage: K.ambient_highest_weight_dict()\n {[]: [[1, -1]], [2]: [[2, 2]]}\n " A = self.ambient_dict_pm_diagrams() ambient = self.ambient_crystal() return {key: ambient.retract(ambient.from_pm_diagram_to_highest_weight_vector(A[key])) for key in A} @cached_method def highest_weight_dict(self): "\n Return a dictionary of the classical highest weight vectors\n of ``self`` whose keys are their shape.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 2)\n sage: K.highest_weight_dict()\n {[]: [], [2]: [[1, 1]]}\n " return {x.lift().to_tableau().shape(): x for x in self.module_generators} @cached_method def to_ambient_crystal(self): "\n Return a map from the Kirillov-Reshetikhin crystal of type\n `A_{2n}^{(2)}` to the ambient crystal of type `B_{n+1}^{(1)}`.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 2)\n sage: b=K(rows=[[1,1]])\n sage: K.to_ambient_crystal()(b)\n [[2, 2]]\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 2, 2)\n sage: b=K(rows=[[1,1]])\n sage: K.to_ambient_crystal()(b)\n [[1, 2], [2, -1]]\n sage: K.to_ambient_crystal()(b).parent()\n Kirillov-Reshetikhin crystal of type ['B', 3, 1] with (r,s)=(2,2)\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict = {hwd[key]: ahwd[key] for key in hwd} classical = self.cartan_type().classical() return self.crystal_morphism(pdict, index_set=classical.index_set(), automorphism=(lambda i: (i + 1)), cartan_type=classical, check=False) @cached_method def from_ambient_crystal(self): "\n Return a map from the ambient crystal of type `B_{n+1}^{(1)}` to\n the Kirillov-Reshetikhin crystal of type `A_{2n}^{(2)}`.\n\n Note that this map is only well-defined on type `A_{2n}^{(2)}`\n elements that are in the image under :meth:`to_ambient_crystal`.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 2)\n sage: b = K.ambient_crystal()(rows=[[2,2]])\n sage: K.from_ambient_crystal()(b)\n [[1, 1]]\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict_inv = {ahwd[key]: hwd[key] for key in hwd} ind = [(j + 1) for j in self.cartan_type().classical().index_set()] return AmbientRetractMap(self, self.ambient_crystal(), pdict_inv, index_set=ind, automorphism=(lambda i: (i - 1)))
class KR_type_A2Element(KirillovReshetikhinGenericCrystalElement): "\n Class for the elements in the Kirillov-Reshetikhin crystals `B^{r,s}` of\n type `A_{2n}^{(2)}` for `r<n` with underlying classical algebra `B_n`.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 2)\n sage: type(K.module_generators[0])\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2_with_category.element_class'>\n " def e0(self): "\n Return `e_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `e_1 e_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 1)\n sage: b = K(rows=[[1]])\n sage: b.e(0) # indirect doctest\n [[-1]]\n " b = self.parent().to_ambient_crystal()(self).e(1) if (b is None): return None b = b.e(0) return self.parent().from_ambient_crystal()(b) def f0(self): "\n Return `f_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `f_1 f_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 1)\n sage: b = K(rows=[[-1]])\n sage: b.f(0) # indirect doctest\n [[1]]\n " b = self.parent().to_ambient_crystal()(self).f(1) if (b is None): return None b = b.f(0) return self.parent().from_ambient_crystal()(b) def epsilon0(self): "\n Calculate `\\varepsilon_0` of ``self`` by mapping the element to\n the ambient crystal and calculating ``\\varepsilon_1`` there.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 1)\n sage: b=K(rows=[[1]])\n sage: b.epsilon(0) # indirect doctest\n 1\n " b = self.parent().to_ambient_crystal()(self) return b.epsilon(1) def phi0(self): "\n Calculate `\\varphi_0` of ``self`` by mapping the element to\n the ambient crystal and calculating `\\varphi_1` there.\n\n EXAMPLES::\n\n sage: C = CartanType(['A',4,2]).dual()\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_A2(C, 1, 1)\n sage: b = K(rows=[[-1]])\n sage: b.phi(0) # indirect doctest\n 1\n " b = self.parent().to_ambient_crystal()(self) return b.phi(1)
class KR_type_box(KirillovReshetikhinGenericCrystal, AffineCrystalFromClassical): "\n Class of Kirillov-Reshetikhin crystals `B^{r,s}` of type `A_{2n}^{(2)}`\n for `r\\le n` and type `D_{n+1}^{(2)}` for `r<n`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2], 1,1)\n sage: K\n Kirillov-Reshetikhin crystal of type ['BC', 2, 2] with (r,s)=(1,1)\n sage: b = K(rows=[])\n sage: b.f(0)\n [[1]]\n sage: b.e(0)\n [[-1]]\n " def __init__(self, cartan_type, r, s): "\n Initializes a Kirillov-Reshetikhin crystal ``self``.\n\n TESTS::\n\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_box(['A',4,2], 1, 1)\n sage: K\n Kirillov-Reshetikhin crystal of type ['BC', 2, 2] with (r,s)=(1,1)\n sage: K = sage.combinat.crystals.kirillov_reshetikhin.KR_type_box(['D',4,2], 1, 1)\n sage: K\n Kirillov-Reshetikhin crystal of type ['C', 3, 1]^* with (r,s)=(1,1)\n sage: TestSuite(K).run()\n " KirillovReshetikhinGenericCrystal.__init__(self, cartan_type, r, s) AffineCrystalFromClassical.__init__(self, cartan_type, self.classical_decomposition(), KirillovReshetikhinCrystals()) def classical_decomposition(self): "\n Return the classical crystal underlying the Kirillov-Reshetikhin\n crystal of type `A_{2n}^{(2)}` and `D_{n+1}^{(2)}`.\n\n It is given by `B^{r,s} \\cong \\bigoplus_{\\Lambda} B(\\Lambda)`,\n where `\\Lambda` are weights obtained from a rectangle of width `s`\n and height `r` by removing boxes. Here we identify the fundamental\n weight `\\Lambda_i` with a column of height `i`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2], 2,2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['C', 2] and shape(s) [[], [1], [2], [1, 1], [2, 1], [2, 2]]\n sage: K = crystals.KirillovReshetikhin(['D',4,2], 2,3)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['B', 3] and shape(s) [[], [1], [2], [1, 1], [3], [2, 1], [3, 1], [2, 2], [3, 2], [3, 3]]\n " return CrystalOfTableaux(self.cartan_type().classical(), shapes=partitions_in_box(self.r(), self.s())) def ambient_crystal(self): "\n Return the ambient crystal `B^{r,2s}` of type `C_n^{(1)}`\n associated to the Kirillov-Reshetikhin crystal.\n\n The ambient crystal is used to construct the zero arrows.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2], 2,2)\n sage: K.ambient_crystal()\n Kirillov-Reshetikhin crystal of type ['C', 2, 1] with (r,s)=(2,4)\n " return KR_type_C(['C', self.cartan_type().classical().rank(), 1], self.r(), (2 * self.s())) @cached_method def highest_weight_dict(self): "\n Return a dictionary of the classical highest weight vectors\n of ``self`` whose keys are 2 times their shape.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',6,2], 2,2)\n sage: K.highest_weight_dict()\n {[]: [],\n [2]: [[1]],\n [2, 2]: [[1], [2]],\n [4]: [[1, 1]],\n [4, 2]: [[1, 1], [2]],\n [4, 4]: [[1, 1], [2, 2]]}\n " return {Partition([(2 * i) for i in x.lift().to_tableau().shape()]): x for x in self.module_generators} @cached_method def ambient_highest_weight_dict(self): "\n Return a dictionary of the classical highest weight vectors of\n the ambient crystal of ``self`` whose keys are their shape.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',6,2], 2,2)\n sage: K.ambient_highest_weight_dict()\n {[]: [],\n [2]: [[1, 1]],\n [2, 2]: [[1, 1], [2, 2]],\n [4]: [[1, 1, 1, 1]],\n [4, 2]: [[1, 1, 1, 1], [2, 2]],\n [4, 4]: [[1, 1, 1, 1], [2, 2, 2, 2]]}\n " return {x.lift().to_tableau().shape(): x for x in self.ambient_crystal().module_generators} def similarity_factor(self): "\n Sets the similarity factor used to map to the ambient crystal.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',6,2], 2,2)\n sage: K.similarity_factor()\n {1: 2, 2: 2, 3: 2}\n sage: K = crystals.KirillovReshetikhin(['D',5,2], 1,1)\n sage: K.similarity_factor()\n {1: 2, 2: 2, 3: 2, 4: 1}\n " C = self.cartan_type().classical() p = {i: 2 for i in C.index_set()} if (C.type() == 'B'): p[C.rank()] = 1 return p @cached_method def to_ambient_crystal(self): "\n Return a map from ``self`` to the ambient crystal of type `C_n^{(1)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2], 1,1)\n sage: [K.to_ambient_crystal()(b) for b in K]\n [[], [[1, 1]], [[2, 2]], [[3, 3]], [[3, -3]], [[-3, -3]], [[-2, -2]], [[-1, -1]]]\n sage: K = crystals.KirillovReshetikhin(['A',4,2], 1,1)\n sage: [K.to_ambient_crystal()(b) for b in K]\n [[], [[1, 1]], [[2, 2]], [[-2, -2]], [[-1, -1]]]\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict = {hwd[key]: ahwd[key] for key in hwd} classical = self.cartan_type().classical() return self.crystal_morphism(pdict, codomain=self.ambient_crystal(), index_set=classical.index_set(), scaling_factors=self.similarity_factor(), cartan_type=classical, check=False) @cached_method def from_ambient_crystal(self): "\n Return a map from the ambient crystal of type `C_n^{(1)}` to the\n Kirillov-Reshetikhin crystal ``self``.\n\n Note that this map is only well-defined on elements that are in the\n image under :meth:`to_ambient_crystal`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2], 1,1)\n sage: b = K.ambient_crystal()(rows=[[3,-3]])\n sage: K.from_ambient_crystal()(b)\n [[0]]\n sage: K = crystals.KirillovReshetikhin(['A',4,2], 1,1)\n sage: b = K.ambient_crystal()(rows=[])\n sage: K.from_ambient_crystal()(b)\n []\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict_inv = {ahwd[key]: hwd[key] for key in hwd} return AmbientRetractMap(self, self.ambient_crystal(), pdict_inv, index_set=self.cartan_type().classical().index_set(), similarity_factor_domain=self.similarity_factor())
class KR_type_boxElement(KirillovReshetikhinGenericCrystalElement): "\n Class for the elements in the Kirillov-Reshetikhin crystals `B^{r,s}` of\n type `A_{2n}^{(2)}` for `r \\leq n` and type `D_{n+1}^{(2)}` for `r < n`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2],1,2)\n sage: type(K.module_generators[0])\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_box_with_category.element_class'>\n " def e0(self): "\n Return `e_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `e_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2],1,1)\n sage: b = K(rows=[])\n sage: b.e(0) # indirect doctest\n [[-1]]\n " b = self.parent().to_ambient_crystal()(self).e(0) if (b is None): return None return self.parent().from_ambient_crystal()(b) def f0(self): "\n Return `f_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `f_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2],1,1)\n sage: b = K(rows=[])\n sage: b.f(0) # indirect doctest\n [[1]]\n " b = self.parent().to_ambient_crystal()(self).f(0) if (b is None): return None return self.parent().from_ambient_crystal()(b) def epsilon0(self): "\n Return `\\varepsilon_0` of ``self`` by mapping the element\n to the ambient crystal and calculating `\\varepsilon_0` there.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',4,2], 1,1)\n sage: b = K(rows=[[1]])\n sage: b.epsilon(0) # indirect doctest\n 2\n " b = self.parent().to_ambient_crystal()(self) return b.epsilon(0) def phi0(self): "\n Return `\\varphi_0` of ``self`` by mapping the element to\n the ambient crystal and calculating `\\varphi_0` there.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',3,2], 1,1)\n sage: b = K(rows=[[-1]])\n sage: b.phi(0) # indirect doctest\n 2\n " b = self.parent().to_ambient_crystal()(self) return b.phi(0)
class KR_type_Bn(KirillovReshetikhinGenericCrystal): "\n Class of Kirillov-Reshetikhin crystals `B^{n,s}` of type `B_{n}^{(1)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,2)\n sage: K\n Kirillov-Reshetikhin crystal of type ['B', 3, 1] with (r,s)=(3,2)\n sage: b = K(rows=[[1],[2],[3]])\n sage: b.f(0)\n sage: b.e(0)\n [[3]]\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,2)\n sage: [b.weight() for b in K if b.is_highest_weight([1,2,3])]\n [-Lambda[0] + Lambda[1], -2*Lambda[0] + 2*Lambda[3]]\n sage: [b.weight() for b in K if b.is_highest_weight([0,2,3])]\n [Lambda[0] - Lambda[1], -2*Lambda[1] + 2*Lambda[3]]\n " def _element_constructor_(self, *args, **options): "\n Construct an element of ``self``.\n\n TESTS::\n\n sage: KRC = crystals.KirillovReshetikhin(['B',3,1], 3, 3)\n sage: KRT = crystals.KirillovReshetikhin(['B',3,1], 3, 3, model='KR')\n sage: elt = KRC.module_generators[1].f_string([3,2,3,1,3,3]); elt\n [++-, [[2], [0], [-3]]]\n sage: ret = KRT(elt); ret\n [[1, 1, 2], [2, 2, -3], [-3, -3, -1]]\n sage: test = KRC(ret); test\n [++-, [[2], [0], [-3]]]\n sage: test == elt\n True\n " from sage.combinat.rigged_configurations.kr_tableaux import KirillovReshetikhinTableauxElement if isinstance(args[0], KirillovReshetikhinTableauxElement): elt = args[0] if ((elt.cartan_type() != self.cartan_type()) or (elt.parent().r() != self._r) or (elt.parent().s() != self._s)): raise ValueError('the Kirillov-Reshetikhin tableau must have the same Cartan type and shape') to_hw = elt.to_classical_highest_weight() wt = to_hw[0].classical_weight() f_str = reversed(to_hw[1]) for x in self.module_generators: if (x.classical_weight() == wt): return x.f_string(f_str) raise ValueError('no matching highest weight element found') return KirillovReshetikhinGenericCrystal._element_constructor_(self, *args, **options) def classical_decomposition(self): "\n Return the classical crystal underlying the Kirillov-Reshetikhin\n crystal `B^{n,s}` of type `B_n^{(1)}`.\n\n It is the same as for `r < n`, given by\n `B^{n,s} \\cong \\bigoplus_{\\Lambda} B(\\Lambda)`, where `\\Lambda` are\n weights obtained from a rectangle of width `s/2` and height `n` by\n removing horizontal dominoes. Here we identify the fundamental weight\n `\\Lambda_i` with a column of height `i` for `i<n` and a column of\n width `1/2` for `i=n`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1], 3, 2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['B', 3] and shape(s) [[1], [1, 1, 1]]\n sage: K = crystals.KirillovReshetikhin(['B',3,1], 3, 3)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['B', 3] and shape(s) [[3/2, 1/2, 1/2], [3/2, 3/2, 3/2]]\n " s = self.s() r = self.r() shapes = vertical_dominoes_removed(r, (s // 2)) if is_odd(s): shapes = [([(i + (QQ(1) / QQ(2))) for i in sh] + ([(QQ(1) / QQ(2))] * (r - len(sh)))) for sh in shapes] return CrystalOfTableaux(self.cartan_type().classical(), shapes=shapes) def ambient_crystal(self): "\n Return the ambient crystal `B^{n,s}` of type `A_{2n-1}^{(2)}`\n associated to the Kirillov-Reshetikhin crystal.\n\n The ambient crystal is used to construct the zero arrows.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,2)\n sage: K.ambient_crystal()\n Kirillov-Reshetikhin crystal of type ['B', 3, 1]^* with (r,s)=(3,2)\n " return KashiwaraNakashimaTableaux(['A', ((2 * self.cartan_type().classical().rank()) - 1), 2], self.r(), self.s()) @cached_method def highest_weight_dict(self): "\n Return a dictionary of the classical highest weight vectors\n of ``self`` whose keys are 2 times their shape.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,2)\n sage: K.highest_weight_dict()\n {(2,): [[1]], (2, 2, 2): [[1], [2], [3]]}\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,3)\n sage: K.highest_weight_dict()\n {(3, 1, 1): [+++, [[1]]], (3, 3, 3): [+++, [[1], [2], [3]]]}\n " return {tuple([(2 * i[1]) for i in sorted(x.classical_weight())]): x for x in self.module_generators} @cached_method def ambient_highest_weight_dict(self): "\n Return a dictionary of the classical highest weight vectors of\n the ambient crystal of ``self`` whose keys are their shape.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,2)\n sage: K.ambient_highest_weight_dict()\n {(2,): [[1, 1]], (2, 1, 1): [[1, 1], [2], [3]], (2, 2, 2): [[1, 1], [2, 2], [3, 3]]}\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,3)\n sage: K.ambient_highest_weight_dict()\n {(3,): [[1, 1, 1]],\n (3, 1, 1): [[1, 1, 1], [2], [3]],\n (3, 2, 2): [[1, 1, 1], [2, 2], [3, 3]],\n (3, 3, 3): [[1, 1, 1], [2, 2, 2], [3, 3, 3]]}\n " return {tuple([i[1] for i in sorted(x.classical_weight())]): x for x in self.ambient_crystal().module_generators} def similarity_factor(self): "\n Sets the similarity factor used to map to the ambient crystal.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,2)\n sage: K.similarity_factor()\n {1: 2, 2: 2, 3: 1}\n " C = self.cartan_type().classical() p = {i: 2 for i in C.index_set()} p[C.rank()] = 1 return p @cached_method def to_ambient_crystal(self): "\n Return a map from self to the ambient crystal of type `A_{2n-1}^{(2)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,1)\n sage: [K.to_ambient_crystal()(b) for b in K]\n [[[1], [2], [3]], [[1], [2], [-3]], [[1], [3], [-2]], [[2], [3], [-1]], [[1], [-3], [-2]],\n [[2], [-3], [-1]], [[3], [-2], [-1]], [[-3], [-2], [-1]]]\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict = {hwd[key]: ahwd[key] for key in hwd} classical = self.cartan_type().classical() return self.crystal_morphism(pdict, codomain=self.ambient_crystal(), index_set=classical.index_set(), scaling_factors=self.similarity_factor(), cartan_type=classical, check=False) @cached_method def from_ambient_crystal(self): "\n Return a map from the ambient crystal of type `A_{2n-1}^{(2)}` to\n the Kirillov-Reshetikhin crystal ``self``.\n\n Note that this map is only well-defined on elements that are in the\n image under :meth:`to_ambient_crystal`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,1)\n sage: [b == K.from_ambient_crystal()(K.to_ambient_crystal()(b)) for b in K]\n [True, True, True, True, True, True, True, True]\n sage: b = K.ambient_crystal()(rows=[[1],[2],[-3]])\n sage: K.from_ambient_crystal()(b)\n [++-, []]\n " hwd = self.highest_weight_dict() ahwd = self.ambient_highest_weight_dict() pdict_inv = {ahwd[key]: hwd[key] for key in hwd} return AmbientRetractMap(self, self.ambient_crystal(), pdict_inv, index_set=self.cartan_type().classical().index_set(), similarity_factor_domain=self.similarity_factor())
class KR_type_BnElement(KirillovReshetikhinGenericCrystalElement): "\n Class for the elements in the Kirillov-Reshetikhin crystals `B^{n,s}`\n of type `B_n^{(1)}`.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['B',3,1],3,2)\n sage: type(K.module_generators[0])\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_Bn_with_category.element_class'>\n " def e0(self): "\n Return `e_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `e_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1],3,1)\n sage: b = K.module_generators[0]\n sage: b.e(0) # indirect doctest\n [--+, []]\n " b = self.parent().to_ambient_crystal()(self).e_string([0, 0]) if (b is None): return None return self.parent().from_ambient_crystal()(b) def f0(self): "\n Return `f_0` on ``self`` by mapping ``self`` to the ambient crystal,\n calculating `f_0` there and pulling the element back.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['B',3,1],3,1)\n sage: b = K.module_generators[0]\n sage: b.f(0) # indirect doctest\n\n " b = self.parent().to_ambient_crystal()(self).f_string([0, 0]) if (b is None): return None return self.parent().from_ambient_crystal()(b) def epsilon0(self): "\n Calculate `\\varepsilon_0` of ``self`` by mapping the element\n to the ambient crystal and calculating `\\varepsilon_0` there.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['B',3,1],3,1)\n sage: b = K.module_generators[0]\n sage: b.epsilon(0) # indirect doctest\n 1\n " b = self.parent().to_ambient_crystal()(self) return (b.epsilon(0) // 2) def phi0(self): "\n Calculate `\\varphi_0` of ``self`` by mapping the element to\n the ambient crystal and calculating `\\varphi_0` there.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['B',3,1],3,1)\n sage: b = K.module_generators[0]\n sage: b.phi(0) # indirect doctest\n 0\n " b = self.parent().to_ambient_crystal()(self) return (b.phi(0) // 2)
class KR_type_Cn(KirillovReshetikhinGenericCrystal): "\n Class of Kirillov-Reshetikhin crystals `B^{n,s}` of type `C_n^{(1)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1],3,1)\n sage: [[b,b.f(0)] for b in K]\n [[[[1], [2], [3]], None], [[[1], [2], [-3]], None],\n [[[1], [3], [-3]], None], [[[2], [3], [-3]], None],\n [[[1], [3], [-2]], None], [[[2], [3], [-2]], None],\n [[[2], [3], [-1]], [[1], [2], [3]]], [[[1], [-3], [-2]], None],\n [[[2], [-3], [-2]], None], [[[2], [-3], [-1]], [[1], [2], [-3]]],\n [[[3], [-3], [-2]], None], [[[3], [-3], [-1]], [[1], [3], [-3]]],\n [[[3], [-2], [-1]], [[1], [3], [-2]]],\n [[[-3], [-2], [-1]], [[1], [-3], [-2]]]]\n " def classical_decomposition(self): "\n Specifies the classical crystal underlying the Kirillov-Reshetikhin\n crystal `B^{n,s}` of type `C_n^{(1)}`.\n\n The classical decomposition is given by\n `B^{n,s} \\cong B(s \\Lambda_n)`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1],3,2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['C', 3] and shape(s) [[2, 2, 2]]\n " return CrystalOfTableaux(self.cartan_type().classical(), shape=([self.s()] * self.r())) def from_highest_weight_vector_to_pm_diagram(self, b): "\n This gives the bijection between an element ``b`` in the classical\n decomposition of the KR crystal that is `{2,3,..,n}`-highest weight\n and `\\pm` diagrams.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1],3,2)\n sage: T = K.classical_decomposition()\n sage: b = T(rows=[[2, 2], [3, 3], [-3, -1]])\n sage: pm = K.from_highest_weight_vector_to_pm_diagram(b); pm\n [[0, 0], [1, 0], [0, 1], [0]]\n sage: pm.pp()\n . .\n . +\n - -\n\n sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3]) ]\n sage: all(K.from_pm_diagram_to_highest_weight_vector(K.from_highest_weight_vector_to_pm_diagram(b)) == b for b in hw)\n True\n " n = (self.cartan_type().rank() - 1) inner = Partition([Integer(b.weight()[i]) for i in range(1, (n + 1))]) inter = Partition([len([i for i in r if (i > 0)]) for r in b.to_tableau()]) outer = b.to_tableau().shape() return PMDiagram([self.r(), self.s(), outer, inter, inner], from_shapes=True) def from_pm_diagram_to_highest_weight_vector(self, pm): "\n This gives the bijection between a `\\pm` diagram and an element ``b``\n in the classical decomposition of the KR crystal that is\n `\\{2,3,..,n\\}`-highest weight.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1],3,2)\n sage: pm = sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0, 0], [1, 0], [0, 1], [0]])\n sage: K.from_pm_diagram_to_highest_weight_vector(pm)\n [[2, 2], [3, 3], [-3, -1]]\n " u = [b for b in self.classical_decomposition().module_generators if (b.to_tableau().shape() == pm.outer_shape())][0] ct = self.cartan_type() rank = (ct.rank() - 1) ct_type = ct.classical().type() assert (ct_type in ['C']) ulist = [] for h in pm.heights_of_addable_plus(): ulist += list(range(1, (h + 1))) for h in pm.heights_of_minus(): ulist += (list(range(1, (rank + 1))) + [((rank - 1) - k) for k in range((rank - h))]) for i in reversed(ulist): u = u.f(i) return u
class KR_type_CnElement(KirillovReshetikhinGenericCrystalElement): "\n Class for the elements in the Kirillov-Reshetikhin crystals `B^{n,s}`\n of type `C_n^{(1)}`.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['C',3,1],3,2)\n sage: type(K.module_generators[0])\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_Cn_with_category.element_class'>\n " def e0(self): "\n Return `e_0` on ``self`` by going to the `\\pm`-diagram corresponding\n to the `\\{2,...,n\\}`-highest weight vector in the component of\n ``self``, then applying [Definition 6.1, 4], and pulling back from\n `\\pm`-diagrams.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['C',3,1],3,2)\n sage: b = K.module_generators[0]\n sage: b.e(0) # indirect doctest\n [[1, 2], [2, 3], [3, -1]]\n sage: b = K(rows=[[1,2],[2,3],[3,-1]])\n sage: b.e(0)\n [[2, 2], [3, 3], [-1, -1]]\n sage: b=K(rows=[[1, -3], [3, -2], [-3, -1]])\n sage: b.e(0)\n [[3, -3], [-3, -2], [-1, -1]]\n " n = self.parent().cartan_type().n [b, l] = self.lift().to_highest_weight(index_set=list(range(2, (n + 1)))) pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) [l1, l2] = pm.pm_diagram[(n - 1)] if (l1 == 0): return None pm.pm_diagram[(n - 1)] = [(l1 - 1), (l2 + 1)] pm = PMDiagram(pm.pm_diagram) b = self.parent().from_pm_diagram_to_highest_weight_vector(pm) b = b.f_string(reversed(l)) return self.parent().retract(b) def f0(self): "\n Return `e_0` on ``self`` by going to the `\\pm`-diagram corresponding\n to the `\\{2,...,n\\}`-highest weight vector in the component of\n ``self``, then applying [Definition 6.1, 4], and pulling back from\n `\\pm`-diagrams.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['C',3,1],3,1)\n sage: b = K.module_generators[0]\n sage: b.f(0) # indirect doctest\n " n = self.parent().cartan_type().n [b, l] = self.lift().to_highest_weight(index_set=list(range(2, (n + 1)))) pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) [l1, l2] = pm.pm_diagram[(n - 1)] if (l2 == 0): return None pm.pm_diagram[(n - 1)] = [(l1 + 1), (l2 - 1)] pm = PMDiagram(pm.pm_diagram) b = self.parent().from_pm_diagram_to_highest_weight_vector(pm) b = b.f_string(reversed(l)) return self.parent().retract(b) def epsilon0(self): "\n Calculate `\\varepsilon_0` of ``self`` using Lemma 6.1 of [4].\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['C',3,1],3,1)\n sage: b = K.module_generators[0]\n sage: b.epsilon(0) # indirect doctest\n 1\n " n = self.parent().cartan_type().n b = self.lift().to_highest_weight(index_set=list(range(2, (n + 1))))[0] pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) [l1, l2] = pm.pm_diagram[(n - 1)] return l1 def phi0(self): "\n Calculate `\\varphi_0` of ``self``.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['C',3,1],3,1)\n sage: b = K.module_generators[0]\n sage: b.phi(0) # indirect doctest\n 0\n " n = self.parent().cartan_type().n b = self.lift().to_highest_weight(index_set=list(range(2, (n + 1))))[0] pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) [l1, l2] = pm.pm_diagram[(n - 1)] return l2
class KR_type_Dn_twisted(KirillovReshetikhinGenericCrystal): "\n Class of Kirillov-Reshetikhin crystals `B^{n,s}` of type `D_{n+1}^{(2)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,1)\n sage: [[b,b.f(0)] for b in K]\n [[[+++, []], None], [[++-, []], None], [[+-+, []], None], [[-++, []],\n [+++, []]], [[+--, []], None], [[-+-, []], [++-, []]], [[--+, []], [+-+, []]],\n [[---, []], [+--, []]]]\n " def _element_constructor_(self, *args, **options): "\n Construct an element of ``self``.\n\n TESTS::\n\n sage: KRC = crystals.KirillovReshetikhin(['D',4,1], 3, 3)\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 3, 3, model='KR')\n sage: elt = KRC.module_generators[0].f_string([3,2,3,1,2,3]); elt\n [++-+, [[2], [3], [4], [-2]]]\n sage: ret = KRT(elt); ret\n [[1, 1, 2], [2, 3, 3], [4, 4, 4], [-3, -2, -1]]\n sage: test = KRC(ret); test\n [++-+, [[2], [3], [4], [-2]]]\n sage: test == elt\n True\n " from sage.combinat.rigged_configurations.kr_tableaux import KirillovReshetikhinTableauxElement if isinstance(args[0], KirillovReshetikhinTableauxElement): elt = args[0] if ((elt.cartan_type() != self.cartan_type()) or (elt.parent().r() != self._r) or (elt.parent().s() != self._s)): raise ValueError('the Kirillov-Reshetikhin tableau must have the same Cartan type and shape') to_hw = elt.to_classical_highest_weight() wt = to_hw[0].classical_weight() f_str = reversed(to_hw[1]) for x in self.module_generators: if (x.classical_weight() == wt): return x.f_string(f_str) raise ValueError('no matching highest weight element found') return KirillovReshetikhinGenericCrystal._element_constructor_(self, *args, **options) def classical_decomposition(self): "\n Return the classical crystal underlying the Kirillov-Reshetikhin\n crystal `B^{n,s}` of type `D_{n+1}^{(2)}`.\n\n The classical decomposition is given by\n `B^{n,s} \\cong B(s \\Lambda_n)`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,1)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['B', 3] and shape(s) [[1/2, 1/2, 1/2]]\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['B', 3] and shape(s) [[1, 1, 1]]\n " s = self.s() if is_even(s): s = (s // 2) else: s = (s / 2) return CrystalOfTableaux(self.cartan_type().classical(), shape=([s] * self.r())) def from_highest_weight_vector_to_pm_diagram(self, b): "\n This gives the bijection between an element ``b`` in the\n classical decomposition of the KR crystal that is\n `\\{2,3,\\ldots,n\\}`-highest weight and `\\pm` diagrams.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,1)\n sage: T = K.classical_decomposition()\n sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3]) ]\n sage: [K.from_highest_weight_vector_to_pm_diagram(b) for b in hw]\n [[[0, 0], [0, 0], [1, 0], [0]], [[0, 0], [0, 0], [0, 1], [0]]]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,2)\n sage: T = K.classical_decomposition()\n sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3]) ]\n sage: [K.from_highest_weight_vector_to_pm_diagram(b) for b in hw]\n [[[0, 0], [0, 0], [2, 0], [0]], [[0, 0], [0, 0], [0, 0], [2]],\n [[0, 0], [2, 0], [0, 0], [0]], [[0, 0], [0, 0], [0, 2], [0]]]\n\n Note that, since the classical decomposition of this crystal is of\n type `B_n`, there can be (at most one) entry `0` in the\n `\\{2,3,\\ldots,n\\}`-highest weight elements at height `n`.\n In the following implementation this is realized as an empty\n column of height `n` since this uniquely specifies the existence\n of the `0`.\n\n EXAMPLES::\n\n sage: b = hw[1]\n sage: pm = K.from_highest_weight_vector_to_pm_diagram(b)\n sage: pm.pp()\n . .\n . .\n . .\n\n TESTS::\n\n sage: all(K.from_pm_diagram_to_highest_weight_vector(K.from_highest_weight_vector_to_pm_diagram(b)) == b for b in hw)\n True\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,2)\n sage: T = K.classical_decomposition()\n sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3]) ]\n sage: all(K.from_pm_diagram_to_highest_weight_vector(K.from_highest_weight_vector_to_pm_diagram(b)) == b for b in hw)\n True\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,3)\n sage: T = K.classical_decomposition()\n sage: hw = [ b for b in T if all(b.epsilon(i)==0 for i in [2,3]) ]\n sage: all(K.from_pm_diagram_to_highest_weight_vector(K.from_highest_weight_vector_to_pm_diagram(b)) == b for b in hw)\n True\n\n " n = (self.cartan_type().rank() - 1) s = self.s() if is_odd(s): t = b[0] b = b[1] else: t = b.parent()(rows=[]) inner = [Integer(((2 * b.weight()[i]) + (2 * t.weight()[i]))) for i in range(1, (n + 1))] inter1 = Partition([len([i for i in r if (i > 0)]) for r in b.to_tableau()]) inter = Partition([len([i for i in r if (i >= 0)]) for r in b.to_tableau()]) if (inter != inter1): inner[(n - 1)] += 2 inner = Partition(inner) inter = ([(2 * i) for i in inter] + ([0] * (n - len(inter)))) w = t.weight() if ((w[0] == 0) and (w[(n - 1)] == 0)): v = ([0] * n) else: v = ([1] * n) if ((w[0] < 0) and (w[(n - 1)] > 0)): v[(n - 1)] = 0 elif ((w[0] > 0) and (w[(n - 1)] < 0)): v[(n - 1)] = 0 v[(n - 2)] = (- 1) inter = Partition([(inter[i] + v[i]) for i in range(n)]) outer = Partition(([s] * n)) return PMDiagram([n, s, outer, inter, inner], from_shapes=True) def from_pm_diagram_to_highest_weight_vector(self, pm): "\n This gives the bijection between a `\\pm` diagram and an element\n ``b`` in the classical decomposition of the KR crystal that is\n `\\{2,3,\\ldots,n\\}`-highest weight.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,2)\n sage: pm = sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0, 0], [0, 0], [0, 0], [2]])\n sage: K.from_pm_diagram_to_highest_weight_vector(pm)\n [[2], [3], [0]]\n " u = self.classical_decomposition().module_generators[0] ct = self.cartan_type() rank = (ct.rank() - 1) assert (ct.classical().type() in ['B']) ulist = [] plus = pm.heights_of_addable_plus() minus = pm.heights_of_minus() l = len([i for i in plus if (i == (rank - 1))]) a = ((len(plus) + l) // 2) ulist += sum((([i] * a) for i in range(1, (rank + 1))), []) a = ((len(minus) - l) // 2) ulist += ((list(range(1, (rank + 1))) + [rank]) * a) for i in reversed(ulist): u = u.f(i) return u
class KR_type_Dn_twistedElement(KirillovReshetikhinGenericCrystalElement): "\n Class for the elements in the Kirillov-Reshetikhin crystals `B^{n,s}`\n of type `D_{n+1}^{(2)}`.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['D',4,2],3,2)\n sage: type(K.module_generators[0])\n <class 'sage.combinat.crystals.kirillov_reshetikhin.KR_type_Dn_twisted_with_category.element_class'>\n " def e0(self): "\n Return `e_0` on ``self`` by going to the `\\pm`-diagram corresponding\n to the `\\{2,\\ldots,n\\}`-highest weight vector in the component of\n ``self``, then applying [Definition 6.2, 4], and pulling back from\n `\\pm`-diagrams.\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['D',4,2],3,3)\n sage: b = K.module_generators[0]\n sage: b.e(0) # indirect doctest\n [+++, [[2], [3], [0]]]\n " n = (self.parent().cartan_type().rank() - 1) s = self.parent().s() [b, l] = self.lift().to_highest_weight(index_set=list(range(2, (n + 1)))) pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) [l1, l2] = pm.pm_diagram[(n - 1)] l3 = pm.pm_diagram[(n - 2)][0] if ((((l1 + l2) + l3) == s) and (l1 == 0)): return None if (((l1 + l2) + l3) < s): pm.pm_diagram[(n - 1)][1] = (l2 + 2) pm.pm_diagram[n][0] -= 2 elif (l1 > 1): pm.pm_diagram[(n - 1)][0] = (l1 - 2) pm.pm_diagram[n][0] += 2 elif (l1 == 1): pm.pm_diagram[(n - 1)][0] = 0 pm.pm_diagram[(n - 1)][1] = (l2 + 1) pm = PMDiagram(pm.pm_diagram) b = self.parent().from_pm_diagram_to_highest_weight_vector(pm) b = b.f_string(reversed(l)) return self.parent().retract(b) def f0(self): "\n Return `e_0` on ``self`` by going to the `\\pm`-diagram corresponding\n to the `\\{2,\\ldots,n\\}`-highest weight vector in the component of\n ``self``, then applying [Definition 6.2, 4], and pulling back from\n `\\pm`-diagrams.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,2)\n sage: b = K.module_generators[0]\n sage: b.f(0) # indirect doctest\n " n = (self.parent().cartan_type().rank() - 1) s = self.parent().s() [b, l] = self.lift().to_highest_weight(index_set=list(range(2, (n + 1)))) pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) [l1, l2] = pm.pm_diagram[(n - 1)] l3 = pm.pm_diagram[(n - 2)][0] if ((((l1 + l2) + l3) == s) and (l2 == 0)): return None if (((l1 + l2) + l3) < s): pm.pm_diagram[(n - 1)][0] = (l1 + 2) pm.pm_diagram[n][0] -= 2 elif (l2 > 1): pm.pm_diagram[(n - 1)][1] = (l2 - 2) pm.pm_diagram[n][0] += 2 elif (l2 == 1): pm.pm_diagram[(n - 1)][1] = 0 pm.pm_diagram[(n - 1)][0] = (l1 + 1) pm = PMDiagram(pm.pm_diagram) b = self.parent().from_pm_diagram_to_highest_weight_vector(pm) b = b.f_string(reversed(l)) return self.parent().retract(b) def epsilon0(self): "\n Calculate `\\varepsilon_0` of ``self`` using Lemma 6.2 of [4].\n\n EXAMPLES::\n\n sage: K=crystals.KirillovReshetikhin(['D',4,2],3,1)\n sage: b = K.module_generators[0]\n sage: b.epsilon(0) # indirect doctest\n 1\n\n TESTS:\n\n Check that :trac:`19982` is fixed::\n\n sage: K = crystals.KirillovReshetikhin(['D',3,2], 2,3)\n sage: def eps0_defn(elt):\n ....: x = elt.e(0)\n ....: eps = 0\n ....: while x is not None:\n ....: x = x.e(0)\n ....: eps = eps + 1\n ....: return eps\n sage: all(eps0_defn(x) == x.epsilon0() for x in K)\n True\n " n = (self.parent().cartan_type().rank() - 1) [b, l] = self.lift().to_highest_weight(index_set=list(range(2, (n + 1)))) pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) l1 = pm.pm_diagram[(n - 1)][0] l4 = pm.pm_diagram[n][0] return (l1 + (l4 // 2)) def phi0(self): "\n Calculate `\\varphi_0` of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2],3,1)\n sage: b = K.module_generators[0]\n sage: b.phi(0) # indirect doctest\n 0\n\n TESTS:\n\n Check that :trac:`19982` is fixed::\n\n sage: K = crystals.KirillovReshetikhin(['D',3,2], 2,3)\n sage: def phi0_defn(elt):\n ....: x = elt.f(0)\n ....: phi = 0\n ....: while x is not None:\n ....: x = x.f(0)\n ....: phi = phi + 1\n ....: return phi\n sage: all(phi0_defn(x) == x.phi0() for x in K)\n True\n " n = (self.parent().cartan_type().rank() - 1) (b, l) = self.lift().to_highest_weight(index_set=list(range(2, (n + 1)))) pm = self.parent().from_highest_weight_vector_to_pm_diagram(b) l2 = pm.pm_diagram[(n - 1)][1] l4 = pm.pm_diagram[n][0] return (l2 + (l4 // 2))
class KR_type_spin(KirillovReshetikhinCrystalFromPromotion): "\n Class of Kirillov-Reshetikhin crystals `B^{n,s}` of type `D_n^{(1)}`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],4,1); K\n Kirillov-Reshetikhin crystal of type ['D', 4, 1] with (r,s)=(4,1)\n sage: [[b,b.f(0)] for b in K]\n [[[++++, []], None], [[++--, []], None], [[+-+-, []], None],\n [[-++-, []], None], [[+--+, []], None], [[-+-+, []], None],\n [[--++, []], [++++, []]], [[----, []], [++--, []]]]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],4,2); K\n Kirillov-Reshetikhin crystal of type ['D', 4, 1] with (r,s)=(4,2)\n sage: [[b,b.f(0)] for b in K]\n [[[[1], [2], [3], [4]], None], [[[1], [2], [-4], [4]], None],\n [[[1], [3], [-4], [4]], None], [[[2], [3], [-4], [4]], None],\n [[[1], [4], [-4], [4]], None], [[[2], [4], [-4], [4]], None],\n [[[3], [4], [-4], [4]], [[1], [2], [3], [4]]],\n [[[-4], [4], [-4], [4]], [[1], [2], [-4], [4]]],\n [[[-4], [4], [-4], [-3]], [[1], [2], [-4], [-3]]],\n [[[-4], [4], [-4], [-2]], [[1], [3], [-4], [-3]]],\n [[[-4], [4], [-4], [-1]], [[2], [3], [-4], [-3]]],\n [[[-4], [4], [-3], [-2]], [[1], [4], [-4], [-3]]],\n [[[-4], [4], [-3], [-1]], [[2], [4], [-4], [-3]]],\n [[[-4], [4], [-2], [-1]], [[-4], [4], [-4], [4]]],\n [[[-4], [-3], [-2], [-1]], [[-4], [4], [-4], [-3]]],\n [[[1], [2], [-4], [-3]], None], [[[1], [3], [-4], [-3]], None],\n [[[2], [3], [-4], [-3]], None], [[[1], [3], [-4], [-2]], None],\n [[[2], [3], [-4], [-2]], None], [[[2], [3], [-4], [-1]], None],\n [[[1], [4], [-4], [-3]], None], [[[2], [4], [-4], [-3]], None],\n [[[3], [4], [-4], [-3]], None],\n [[[3], [4], [-4], [-2]], [[1], [3], [-4], [4]]],\n [[[3], [4], [-4], [-1]], [[2], [3], [-4], [4]]],\n [[[1], [4], [-4], [-2]], None], [[[2], [4], [-4], [-2]], None],\n [[[2], [4], [-4], [-1]], None], [[[1], [4], [-3], [-2]], None],\n [[[2], [4], [-3], [-2]], None], [[[2], [4], [-3], [-1]], None],\n [[[3], [4], [-3], [-2]], [[1], [4], [-4], [4]]],\n [[[3], [4], [-3], [-1]], [[2], [4], [-4], [4]]],\n [[[3], [4], [-2], [-1]], [[3], [4], [-4], [4]]]]\n\n TESTS::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],3,1)\n sage: all(b.e(0).f(0) == b for b in K if b.epsilon(0)>0)\n True\n\n sage: K = crystals.KirillovReshetikhin(['D',5,1],5,2)\n sage: all(b.f(0).e(0) == b for b in K if b.phi(0)>0)\n True\n " def _element_constructor_(self, *args, **options): "\n Construct an element of ``self`` from the input.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 4, 3, model='KR')\n sage: KRC = crystals.KirillovReshetikhin(['D',4,1], 4, 3)\n sage: elt = KRT(-3,-4,2,1,-3,-4,2,1,-2,-4,3,1); elt\n [[1, 1, 1], [2, 2, 3], [-4, -4, -4], [-3, -3, -2]]\n sage: KRC(elt) # indirect doctest\n [++--, [[1], [3], [-4], [-3]]]\n\n TESTS:\n\n Spinor test::\n\n sage: KRC = crystals.KirillovReshetikhin(['D',4,1], 4, 3)\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 4, 3, model='KR')\n sage: elt = KRC.module_generator().f_string([4,2,4,3,4,1]); elt\n [++--, [[2], [4], [-4], [-3]]]\n sage: ret = KRT(elt); ret\n [[1, 1, 2], [2, 2, 4], [-4, -4, -3], [-3, -3, -1]]\n sage: test = KRC(ret); test\n [++--, [[2], [4], [-4], [-3]]]\n sage: test == elt\n True\n " from sage.combinat.rigged_configurations.kr_tableaux import KirillovReshetikhinTableauxElement if isinstance(args[0], KirillovReshetikhinTableauxElement): elt = args[0] if ((elt.cartan_type() != self.cartan_type()) or (elt.parent().r() != self._r) or (elt.parent().s() != self._s)): raise ValueError('the Kirillov-Reshetikhin tableau must have the same Cartan type and shape') to_hw = elt.to_classical_highest_weight() f_str = reversed(to_hw[1]) return self.maximal_vector().f_string(f_str) return KirillovReshetikhinCrystalFromPromotion._element_constructor_(self, *args, **options) def classical_decomposition(self): "\n Return the classical crystal underlying the Kirillov-Reshetikhin\n crystal `B^{r,s}` of type `D_n^{(1)}` for `r=n-1,n`.\n\n The classical decomposition is given by\n `B^{n,s} \\cong B(s \\Lambda_r)`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],4,1)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['D', 4] and shape(s) [[1/2, 1/2, 1/2, 1/2]]\n sage: K = crystals.KirillovReshetikhin(['D',4,1],3,1)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['D', 4] and shape(s) [[1/2, 1/2, 1/2, -1/2]]\n sage: K = crystals.KirillovReshetikhin(['D',4,1],3,2)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['D', 4] and shape(s) [[1, 1, 1, -1]]\n\n TESTS:\n\n Check that this is robust against python ints::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 4, int(1))\n sage: K.classical_crystal\n The crystal of tableaux of type ['D', 4] and shape(s) [[1/2, 1/2, 1/2, 1/2]]\n " C = self.cartan_type().classical() s = QQ(self.s()) if (self.r() == C.n): c = ([(s / QQ(2))] * C.n) else: c = (([(s / QQ(2))] * (C.n - 1)) + [((- s) / QQ(2))]) return CrystalOfTableaux(C, shape=c) def dynkin_diagram_automorphism(self, i): "\n Specifies the Dynkin diagram automorphism underlying the promotion\n action on the crystal elements.\n\n Here we use the Dynkin diagram automorphism which interchanges\n nodes 0 and 1 and leaves all other nodes unchanged.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],4,1)\n sage: K.dynkin_diagram_automorphism(0)\n 1\n sage: K.dynkin_diagram_automorphism(1)\n 0\n sage: K.dynkin_diagram_automorphism(4)\n 4\n " aut = ([1, 0] + list(range(2, self.cartan_type().rank()))) return aut[i] @cached_method def promotion_on_highest_weight_vectors(self): '\n Return the promotion operator on `\\{2,3,\\ldots,n\\}`-highest\n weight vectors.\n\n A `\\{2,3,\\ldots,n\\}`-highest weight vector in `B(s\\Lambda_n)` of\n weight `w = (w_1,\\ldots,w_n)` is mapped to a\n `\\{2,3,\\ldots,n\\}`-highest weight vector in `B(s\\Lambda_{n-1})`\n of weight `(-w_1,w_2,\\ldots,w_n)` and vice versa.\n\n .. SEEALSO::\n\n - :meth:`promotion_on_highest_weight_vectors_inverse`\n - :meth:`promotion`\n\n EXAMPLES::\n\n sage: KR = crystals.KirillovReshetikhin([\'D\',4,1],4,2)\n sage: prom = KR.promotion_on_highest_weight_vectors()\n sage: T = KR.classical_decomposition()\n sage: HW = [t for t in T if t.is_highest_weight([2,3,4])]\n sage: for t in HW:\n ....: print("{} {}".format(t, prom[t]))\n [[1], [2], [3], [4]] [[2], [3], [4], [-1]]\n [[2], [3], [-4], [4]] [[2], [3], [4], [-4]]\n [[2], [3], [-4], [-1]] [[1], [2], [3], [-4]]\n\n sage: KR = crystals.KirillovReshetikhin([\'D\',4,1],4,1)\n sage: prom = KR.promotion_on_highest_weight_vectors()\n sage: T = KR.classical_decomposition()\n sage: HW = [t for t in T if t.is_highest_weight([2,3,4])]\n sage: for t in HW:\n ....: print("{} {}".format(t, prom[t]))\n [++++, []] [-+++, []]\n [-++-, []] [+++-, []]\n ' T = self.classical_decomposition() ind = list(T.index_set()) ind.remove(1) C = T.cartan_type() n = C.n sh = [i for i in T.shapes[0]] sh[(n - 1)] = (- sh[(n - 1)]) T_dual = CrystalOfTableaux(C, shape=sh) hw = [t for t in T if t.is_highest_weight(index_set=ind)] hw_dual = [t for t in T_dual if t.is_highest_weight(index_set=ind)] dic_weight = {tuple(t.weight().to_vector()): t for t in hw} dic_weight_dual = {tuple(t.weight().to_vector()): t for t in hw_dual} def neg(x): y = list(x) y[0] = (- y[0]) return tuple(y) return {dic_weight[w]: dic_weight_dual[neg(w)] for w in dic_weight} @cached_method def promotion_on_highest_weight_vectors_inverse(self): "\n Return the inverse promotion operator on\n `\\{2,3,\\ldots,n\\}`-highest weight vectors.\n\n .. SEEALSO::\n\n - :meth:`promotion_on_highest_weight_vectors`\n - :meth:`promotion_inverse`\n\n EXAMPLES::\n\n sage: KR = crystals.KirillovReshetikhin(['D',4,1],3,2)\n sage: prom = KR.promotion_on_highest_weight_vectors()\n sage: prom_inv = KR.promotion_on_highest_weight_vectors_inverse()\n sage: T = KR.classical_decomposition()\n sage: HW = [t for t in T if t.is_highest_weight([2,3,4])]\n sage: all(prom_inv[prom[t]] == t for t in HW)\n True\n " D = self.promotion_on_highest_weight_vectors() return {Dt: t for (t, Dt) in D.items()} @cached_method def promotion(self): '\n Return the promotion operator on `B^{r,s}` of type\n `D_n^{(1)}` for `r = n-1,n`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin([\'D\',4,1],3,1)\n sage: T = K.classical_decomposition()\n sage: promotion = K.promotion()\n sage: for t in T:\n ....: print("{} {}".format(t, promotion(t)))\n [+++-, []] [-++-, []]\n [++-+, []] [-+-+, []]\n [+-++, []] [--++, []]\n [-+++, []] [++++, []]\n [+---, []] [----, []]\n [-+--, []] [++--, []]\n [--+-, []] [+-+-, []]\n [---+, []] [+--+, []]\n ' T = self.classical_decomposition() ind = list(T.index_set()) ind.remove(1) return CrystalDiagramAutomorphism(T, self.promotion_on_highest_weight_vectors(), ind) @cached_method def promotion_inverse(self): "\n Return the inverse promotion operator on `B^{r,s}` of type\n `D_n^{(1)}` for `r=n-1,n`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,1],3,1)\n sage: T = K.classical_decomposition()\n sage: promotion = K.promotion()\n sage: promotion_inverse = K.promotion_inverse()\n sage: all(promotion_inverse(promotion(t)) == t for t in T)\n True\n " D = self.promotion_on_highest_weight_vectors_inverse() T = list(D)[0].parent() ind = list(T.index_set()) ind.remove(1) return CrystalDiagramAutomorphism(T, self.promotion_on_highest_weight_vectors_inverse(), ind)
class KR_type_D_tri1(KirillovReshetikhinGenericCrystal): '\n Class of Kirillov-Reshetikhin crystals `B^{1,s}` of type `D_4^{(3)}`.\n\n The crystal structure was defined in Section 4 of [KMOY2007]_ using\n the coordinate representation.\n ' def __init__(self, ct, s): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1, 2)\n sage: TestSuite(K).run()\n " KirillovReshetikhinGenericCrystal.__init__(self, ct, 1, s) def classical_decomposition(self): "\n Return the classical decomposition of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1, 5)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['G', 2]\n and shape(s) [[], [1], [2], [3], [4], [5]]\n " sh = [Partition([j]) for j in range((self._s + 1))] return CrystalOfTableaux(self.cartan_type().classical(), shapes=sh) def from_coordinates(self, coords): "\n Return an element of ``self`` from the coordinates ``coords``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1, 5)\n sage: K.from_coordinates((0, 2, 3, 1, 0, 1))\n [[2, 2, 3, 0, -1]]\n " C = self.classical_decomposition() if (not sum(coords)): return self.element_class(self, C.module_generators[0]) l = C.letters lst = ((((((([l(1)] * coords[0]) + ([l(2)] * coords[1])) + ([l(3)] * (coords[2] // 2))) + ([l(0)] * (coords[2] % 2))) + ([l((- 3))] * (coords[3] // 2))) + ([l((- 2))] * coords[4])) + ([l((- 1))] * coords[5])) return self.element_class(self, C(*lst)) def _element_constructor_(self, *args, **options): "\n Construct an element of ``self``.\n\n TESTS::\n\n sage: KRC = crystals.KirillovReshetikhin(['D',4,3], 1, 3)\n sage: KRT = crystals.KirillovReshetikhin(['D',4,3], 1, 3, model='KR')\n sage: elt = KRC.module_generators[2].f_string([1,1,2,1,2]); elt\n [[3, 0]]\n sage: ret = KRT(elt); ret\n [[3, 0, E]]\n sage: test = KRC(ret); test\n [[3, 0]]\n sage: test == elt\n True\n " from sage.combinat.rigged_configurations.kr_tableaux import KirillovReshetikhinTableauxElement if isinstance(args[0], KirillovReshetikhinTableauxElement): elt = args[0] if ((elt.cartan_type() != self.cartan_type()) or (elt.parent().r() != self._r) or (elt.parent().s() != self._s)): raise ValueError('the Kirillov-Reshetikhin tableau must have the same Cartan type and shape') to_hw = elt.to_classical_highest_weight() wt = sum((x.value for x in to_hw[0] if (x.value != 'E'))) letters = elt.parent().letters if wt: rows = [([letters(1)] * int(wt))] else: rows = [] hw_elt = self(rows=rows) f_str = reversed(to_hw[1]) return hw_elt.f_string(f_str) return KirillovReshetikhinGenericCrystal._element_constructor_(self, *args, **options) class Element(KirillovReshetikhinGenericCrystalElement): @cached_method def coordinates(self): "\n Return ``self`` as coordinates.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1, 3)\n sage: all(K.from_coordinates(x.coordinates()) == x for x in K)\n True\n " letters = self.parent().classical_decomposition().letters l = list(self.value) return (l.count(letters(1)), l.count(letters(2)), ((2 * l.count(letters(3))) + l.count(letters(0))), ((2 * l.count(letters((- 3)))) + l.count(letters(0))), l.count(letters((- 2))), l.count(letters((- 1)))) @lazy_attribute def _A(self): "\n Compute the vector `A = (0, z_1, z_1 + z_2, z_1 + z_2 + 3 z_4,\n z_1 + z_2 + z_3 + 3 z_4, 2 z_1 + z_2 + z_3 + 3 z_4)`, where\n `z_1 = \\bar{x}_1 - x_1`, `z_2 = \\bar{x}_2 - \\bar{x}_3`,\n `z_3 = x_3 - x_2`, and `z_4 = (\\bar{x}_3 - x_3) / 2`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1,1)\n sage: [mg._A for mg in K.module_generators]\n [(0, 0, 0, 0, 0, 0), (0, -1, -1, -1, -1, -2)]\n " coords = self.coordinates() z = [(coords[(- 1)] - coords[0]), (coords[(- 2)] - coords[(- 3)]), (coords[2] - coords[1]), ((coords[(- 3)] - coords[2]) // 2)] return (0, z[0], (z[0] + z[1]), ((z[0] + z[1]) + (3 * z[3])), (sum(z) + (2 * z[3])), ((sum(z) + z[0]) + (2 * z[3]))) def e0(self): "\n Return the action of `e_0` on ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1,1)\n sage: [x.e0() for x in K]\n [[[-1]], [], [[-3]], [[-2]], None, None, None, None]\n " A = self._A c = list(self.coordinates()) M = max(A) if (A[5] == M): if (((((c[0] + c[1]) + ((c[2] + c[3]) // 2)) + c[4]) + c[5]) == self.parent()._s): return None c[5] += 1 return self.parent().from_coordinates(c) if (A[4] == M): c[0] -= 1 c[2] += 1 c[3] += 1 return self.parent().from_coordinates(c) if (A[3] == M): c[1] -= 1 c[3] += 2 return self.parent().from_coordinates(c) if (A[2] == M): c[2] -= 2 c[4] += 1 return self.parent().from_coordinates(c) if (A[1] == M): c[2] -= 1 c[3] -= 1 c[5] += 1 return self.parent().from_coordinates(c) if (A[0] == M): c[0] -= 1 return self.parent().from_coordinates(c) def f0(self): "\n Return the action of `f_0` on ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1,1)\n sage: [x.f0() for x in K]\n [[[1]], None, None, None, None, [[2]], [[3]], []]\n " A = self._A c = list(self.coordinates()) M = max(A) if (A[0] == M): if (((((c[0] + c[1]) + ((c[2] + c[3]) // 2)) + c[4]) + c[5]) == self.parent()._s): return None c[0] += 1 return self.parent().from_coordinates(c) if (A[1] == M): c[2] += 1 c[3] += 1 c[5] -= 1 return self.parent().from_coordinates(c) if (A[2] == M): c[2] += 2 c[4] -= 1 return self.parent().from_coordinates(c) if (A[3] == M): c[1] += 1 c[3] -= 2 return self.parent().from_coordinates(c) if (A[4] == M): c[0] += 1 c[2] -= 1 c[3] -= 1 return self.parent().from_coordinates(c) if (A[5] == M): c[5] -= 1 return self.parent().from_coordinates(c) def epsilon0(self): "\n Return `\\varepsilon_0` of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1, 5)\n sage: [mg.epsilon0() for mg in K.module_generators]\n [5, 6, 7, 8, 9, 10]\n " c = self.coordinates() z = [(c[(- 1)] - c[0]), (c[(- 2)] - c[(- 3)]), (c[2] - c[1]), ((c[(- 3)] - c[2]) // 2)] s = ((((c[0] + c[1]) + ((c[2] + c[3]) // 2)) + c[4]) + c[5]) return (((self.parent()._s - s) + max(self._A)) - ((((2 * z[0]) + z[1]) + z[2]) + (3 * z[3]))) def phi0(self): "\n Return `\\varphi_0` of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1, 5)\n sage: [mg.phi0() for mg in K.module_generators]\n [5, 4, 3, 2, 1, 0]\n " c = self.coordinates() s = ((((c[0] + c[1]) + ((c[2] + c[3]) // 2)) + c[4]) + c[5]) return ((self.parent()._s - s) + max(self._A))
class CrystalOfTableaux_E7(CrystalOfTableaux): '\n The type `E_7` crystal `B(s\\Lambda_7)`.\n\n This is a helper class for the corresponding:class:`KR crystal\n <sage.combinat.crystals.kirillov_reshetikhin.KR_type_E7>` `B^{7,s}`.\n ' def module_generator(self, shape): "\n Return the module generator of ``self`` with shape ``shape``.\n\n .. NOTE::\n\n Only implemented for single rows (i.e., highest weight\n `s\\Lambda_7`).\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import CrystalOfTableaux_E7\n sage: T = CrystalOfTableaux_E7(CartanType(['E',7]), shapes=(Partition([5]),))\n sage: T.module_generator([5])\n [[(7,), (7,), (7,), (7,), (7,)]]\n " if (len(shape) != 1): raise NotImplementedError('only implemented for single row shapes') return self(*([self.letters.highest_weight_vector()] * shape[0]))
class KR_type_E7(KirillovReshetikhinGenericCrystal): '\n The Kirillov-Reshetikhin crystal `B^{7,s}` of type `E_7^{(1)}`.\n ' def __init__(self, ct, r, s): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 1)\n sage: TestSuite(K).run()\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 2)\n sage: TestSuite(K).run() # long time\n " assert (r == 7) KirillovReshetikhinGenericCrystal.__init__(self, ct, 7, s) def classical_decomposition(self): "\n Return the classical decomposition of ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 4)\n sage: K.classical_decomposition()\n The crystal of tableaux of type ['E', 7] and shape(s) [[4]]\n " return CrystalOfTableaux_E7(self.cartan_type().classical(), shapes=(Partition([self._s]),)) @cached_method def A7_decomposition(self): "\n Return the decomposition of ``self`` into `A_7` highest\n weight crystals.\n\n The `A_7` decomposition of `B^{7,s}` is given by\n the parameters `m_4, m_5, m_6, m_7 \\geq 0` such that\n `m_4 + m_5 \\leq m_7` and `s = m_4 + m_5 + m_6 + m_7`. The\n corresponding `A_7` highest weight crystal has highest weight\n `\\lambda = (m_7 - m_4 - m_5) \\Lambda_6 + m_5 \\Lambda_4\n + m_6 \\Lambda_2`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 3)\n sage: K.A7_decomposition()\n The crystal of tableaux of type ['A', 7] and shape(s)\n [[3, 3, 3, 3, 3, 3], [3, 3, 2, 2, 2, 2], [3, 3, 1, 1, 1, 1], [3, 3],\n [2, 2, 2, 2, 1, 1], [2, 2, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1]]\n " from sage.geometry.polyhedron.constructor import Polyhedron P = Polyhedron(ieqs=[[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1], [0, (- 1), (- 1), 0, 1]], eqns=[[(- self._s), 1, 1, 1, 1]]) shapes = [Partition(((([6] * ((p[3] - p[1]) - p[0])) + ([4] * p[1])) + ([2] * p[2]))).conjugate() for p in P.integral_points()] return CrystalOfTableaux(['A', 7], shapes=shapes) @lazy_attribute def _highest_weight_to_A7_elements(self): "\n Return a dictionary that maps the A6 highest weight elements of\n ``self`` to their corresponding element in the `A_7` decomposition.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 2)\n sage: sorted(K._highest_weight_to_A7_elements.items(), key=str)\n [([[(-1, -2, 4), (-2, 1)]], [[1], [2], [3], [4]]),\n ([[(-1, 2), (-2, 1)]], []),\n ([[(-2, 1), (-2, 1)]], [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]),\n ([[(-2, 3), (-2, 1)]], [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 8]]),\n ([[(-2, 3), (-2, 3)]], [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [8, 8]]),\n ([[(-2, 3), (-2, 6)]], [[1, 1], [2, 2], [3], [4], [5], [8]]),\n ([[(-2, 6), (-2, 1)]], [[1, 1], [2, 2], [3], [4], [5], [6]]),\n ([[(-2, 6), (-2, 6)]], [[1, 1], [2, 2]]),\n ([[(-6, 5), (-2, 6)]], [[1], [2], [3], [8]]),\n ([[(7,), (-2, 1)]], [[1, 1], [2, 8], [3], [4], [5], [6]]),\n ([[(7,), (-2, 3)]], [[1, 1], [2, 8], [3], [4], [5], [8]]),\n ([[(7,), (-2, 6)]], [[1, 1], [2, 8]]),\n ([[(7,), (7,)]], [[1, 1], [8, 8]])]\n " d = {} A7 = self.A7_decomposition() for b in self: if (not b.is_highest_weight([1, 3, 4, 5, 6, 7])): continue wt = [b.phi(i) for i in [7, 6, 5, 4, 3, 1]] la = Partition(((([6] * (wt[4] + wt[5])) + ([4] * (wt[2] + wt[3]))) + ([2] * (wt[0] + wt[1])))).conjugate() x = A7.module_generator(la) for i in range(wt[0]): x = x.f_string([2, 3, 4, 5, 6, 7]) for i in range(wt[2]): x = x.f_string([4, 5, 6, 7]) for i in range(wt[4]): x = x.f_string([6, 7]) d[b] = x return d @cached_method def to_A7_crystal(self): "\n Return the map decomposing the KR crystal `B^{7,s}` of\n type `E_7^{(1)}` into type `A_7` highest weight crystals.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 2)\n sage: K.to_A7_crystal()\n ['A', 6] relabelled by {1: 1, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7} -> ['A', 7] Virtual Crystal morphism:\n From: Kirillov-Reshetikhin crystal of type ['E', 7, 1] with (r,s)=(7,2)\n To: The crystal of tableaux of type ['A', 7] and shape(s)\n [[2, 2, 2, 2, 2, 2], [2, 2, 1, 1, 1, 1], [2, 2], [1, 1, 1, 1], []]\n Defn: ...\n " d = self._highest_weight_to_A7_elements return self.crystal_morphism(d, automorphism={1: 6, 3: 5, 4: 4, 5: 3, 6: 2, 7: 1}, index_set=[1, 3, 4, 5, 6, 7], check=False) @cached_method def from_A7_crystal(self): "\n Return the inclusion of the KR crystal `B^{7,s}` of\n type `E_7^{(1)}` into type `A_7` highest weight crystals.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 2)\n sage: K.from_A7_crystal()\n ['A', 6] -> ['E', 7, 1] Virtual Crystal morphism:\n From: The crystal of tableaux of type ['A', 7] and shape(s)\n [[2, 2, 2, 2, 2, 2], [2, 2, 1, 1, 1, 1], [2, 2], [1, 1, 1, 1], []]\n To: Kirillov-Reshetikhin crystal of type ['E', 7, 1] with (r,s)=(7,2)\n Defn: ...\n " A7 = self.A7_decomposition() d = self._highest_weight_to_A7_elements d_inv = {d[b]: b for b in d} return A7.crystal_morphism(d_inv, automorphism={6: 1, 5: 3, 4: 4, 3: 5, 2: 6, 1: 7}, index_set=[1, 2, 3, 4, 5, 6], check=False) class Element(KirillovReshetikhinGenericCrystalElement): def e0(self): "\n Return the action of `e_0` on ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 2)\n sage: mg = K.module_generator()\n sage: mg.e0()\n [[(7,), (-1, 7)]]\n sage: mg.e0().e0()\n [[(-1, 7), (-1, 7)]]\n sage: mg.e_string([0,0,0]) is None\n True\n " P = self.parent() x = P.to_A7_crystal()(self).e(7) if (x is None): return None return P.from_A7_crystal()(x) def f0(self): "\n Return the action of `f_0` on ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['E',7,1], 7, 2)\n sage: mg = K.module_generator()\n sage: x = mg.f_string([7,6,5,4,3,2,4,5,6,1,3,4,5,2,4,3,1])\n sage: x.f0()\n [[(7,), (7,)]]\n sage: mg.f0() is None\n True\n " P = self.parent() x = P.to_A7_crystal()(self).f(7) if (x is None): return None return P.from_A7_crystal()(x)
class PMDiagram(CombinatorialObject): '\n Class of `\\pm` diagrams. These diagrams are in one-to-one bijection with\n `X_{n-1}` highest weight vectors in an `X_n` highest weight crystal\n `X=B,C,D`. See Section 4.1 of [Sch2008]_.\n\n The input is a list `pm = [[a_0,b_0], [a_1,b_1], ...,\n [a_{n-1},b_{n-1}], [b_n]]` of pairs and a last 1-tuple (or list of\n length 1). The pair `[a_i,b_i]` specifies the number of `a_i` `+` and\n `b_i` `-` in the `i`-th row of the `\\pm` diagram if `n-i` is odd and the\n number of `a_i` `\\pm` pairs above row `i` and `b_i` columns of height `i`\n not containing any `+` or `-` if `n-i` is even.\n\n Setting the option ``from_shapes = True`` one can also input a `\\pm`\n diagram in terms of its outer, intermediate, and inner shape by\n specifying a list ``[n, s, outer, intermediate, inner]``\n where ``s`` is the width of the `\\pm` diagram, and ``outer``,\n ``intermediate``, and ``inner`` are the outer, intermediate, and inner\n shapes, respectively.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[0,1],[1,2],[1]])\n sage: pm.pm_diagram\n [[0, 1], [1, 2], [1]]\n sage: pm._list\n [1, 1, 2, 0, 1]\n sage: pm.n\n 2\n sage: pm.width\n 5\n sage: pm.pp()\n . . . .\n . + - -\n sage: PMDiagram([2,5,[4,4],[4,2],[4,1]], from_shapes=True)\n [[0, 1], [1, 2], [1]]\n\n TESTS::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])\n sage: PMDiagram([pm.n, pm.width, pm.outer_shape(), pm.intermediate_shape(), pm.inner_shape()], from_shapes=True) == pm\n True\n sage: pm = PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])\n sage: PMDiagram([pm.n, pm.width, pm.outer_shape(), pm.intermediate_shape(), pm.inner_shape()], from_shapes=True) == pm\n True\n ' def __init__(self, pm_diagram, from_shapes=None): '\n Initialize ``self``.\n\n TESTS::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[0,1],[1,2],[1]]); pm\n [[0, 1], [1, 2], [1]]\n sage: PMDiagram([2,5,[4,4],[4,2],[4,1]], from_shapes=True)\n [[0, 1], [1, 2], [1]]\n sage: TestSuite(pm).run()\n ' if from_shapes: n = pm_diagram[0] s = pm_diagram[1] outer = (([s] + list(pm_diagram[2])) + ([0] * n)) intermediate = (([s] + list(pm_diagram[3])) + ([0] * n)) inner = (([s] + list(pm_diagram[4])) + ([0] * n)) pm = [[inner[n]]] for i in range(((n + 1) // 2)): pm.append([(intermediate[(n - (2 * i))] - inner[(n - (2 * i))]), (inner[((n - (2 * i)) - 1)] - intermediate[(n - (2 * i))])]) pm.append([(outer[(n - (2 * i))] - inner[((n - (2 * i)) - 1)]), (inner[((n - (2 * i)) - 2)] - outer[(n - (2 * i))])]) if is_odd(n): pm.pop((n + 1)) pm_diagram = list(reversed(pm)) self.pm_diagram = pm_diagram self.n = (len(pm_diagram) - 1) self._list = [i for a in reversed(pm_diagram) for i in a] self.width = sum(self._list) def _repr_(self): '\n Turning on pretty printing allows to display the `\\pm` diagram as a\n tableau with the `+` and `-` displayed.\n\n EXAMPLES::\n\n sage: sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])\n [[1, 0], [0, 1], [2, 0], [0, 0], [0]]\n ' return repr(self.pm_diagram) def _repr_diagram(self): '\n Return a string representation of ``self`` as a diagram.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])\n sage: print(pm._repr_diagram())\n . . . +\n . . - -\n + +\n - -\n sage: pm = PMDiagram([[0,2], [0,0], [0]])\n sage: print(pm._repr_diagram())\n ' t = [] ish = (self.inner_shape() + ([0] * self.n)) msh = (self.intermediate_shape() + ([0] * self.n)) osh = (self.outer_shape() + ([0] * self.n)) for i in range(self.n): t.append((((['.'] * ish[i]) + (['+'] * (msh[i] - ish[i]))) + (['-'] * (osh[i] - msh[i])))) t = [i for i in t if i] return (Tableau(t)._repr_diagram() if t else '') def pp(self): '\n Pretty print ``self``.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])\n sage: pm.pp()\n . . . +\n . . - -\n + +\n - -\n sage: pm = PMDiagram([[0,2], [0,0], [0]])\n sage: pm.pp()\n ' print(self._repr_diagram()) def inner_shape(self): '\n Return the inner shape of the pm diagram\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[0,1],[1,2],[1]])\n sage: pm.inner_shape()\n [4, 1]\n sage: pm = PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.inner_shape()\n [7, 5, 3, 1]\n sage: pm = PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.inner_shape()\n [10, 7, 5, 3, 1]\n ' t = [] ll = self._list for i in range(self.n): t.append(sum(ll[0:((2 * i) + 1)])) return Partition(list(reversed(t))) def outer_shape(self): '\n Return the outer shape of the `\\pm` diagram\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[0,1],[1,2],[1]])\n sage: pm.outer_shape()\n [4, 4]\n sage: pm = PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.outer_shape()\n [8, 8, 4, 4]\n sage: pm = PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.outer_shape()\n [13, 8, 8, 4, 4]\n ' t = [] ll = self._list for i in range((self.n // 2)): t.append(sum(ll[0:((4 * i) + 4)])) t.append(sum(ll[0:((4 * i) + 4)])) if is_even((self.n + 1)): t.append(sum(ll[0:((2 * self.n) + 2)])) return Partition(list(reversed(t))) def intermediate_shape(self): '\n Return the intermediate shape of the pm diagram (inner shape plus positions of plusses)\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[0,1],[1,2],[1]])\n sage: pm.intermediate_shape()\n [4, 2]\n sage: pm = PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.intermediate_shape()\n [8, 6, 4, 2]\n sage: pm = PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.intermediate_shape()\n [11, 8, 6, 4, 2]\n sage: pm = PMDiagram([[1,0],[0,1],[2,0],[0,0],[0]])\n sage: pm.intermediate_shape()\n [4, 2, 2]\n sage: pm = PMDiagram([[1, 0], [0, 0], [0, 0], [0, 0], [0]])\n sage: pm.intermediate_shape()\n [1]\n ' p = self.inner_shape() p = (p + [0 for i in range(self.n)]) ll = list(reversed(self._list)) p = [(p[i] + ll[((2 * i) + 1)]) for i in range(self.n)] return Partition(p) def heights_of_minus(self): '\n Return a list with the heights of all minus in the `\\pm` diagram.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.heights_of_minus()\n [5, 5, 3, 3, 1, 1]\n sage: pm = PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.heights_of_minus()\n [4, 4, 2, 2]\n ' n = self.n heights = [] for i in range(((n + 1) // 2)): heights += ([(n - (2 * i))] * ((self.outer_shape() + ([0] * n))[((n - (2 * i)) - 1)] - (self.intermediate_shape() + ([0] * n))[((n - (2 * i)) - 1)])) return heights def heights_of_addable_plus(self): '\n Return a list with the heights of all addable plus in the `\\pm` diagram.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.kirillov_reshetikhin import PMDiagram\n sage: pm = PMDiagram([[1,2],[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.heights_of_addable_plus()\n [1, 1, 2, 3, 4, 5]\n sage: pm = PMDiagram([[1,2],[1,1],[1,1],[1,1],[1]])\n sage: pm.heights_of_addable_plus()\n [1, 2, 3, 4]\n ' heights = [] for i in range(1, (self.n + 1)): heights += ([i] * self.sigma().pm_diagram[i][0]) return heights def sigma(self): '\n Return sigma on pm diagrams as needed for the analogue of the Dynkin diagram automorphism\n that interchanges nodes `0` and `1` for type `D_n(1)`, `B_n(1)`, `A_{2n-1}(2)` for\n Kirillov-Reshetikhin crystals.\n\n EXAMPLES::\n\n sage: pm = sage.combinat.crystals.kirillov_reshetikhin.PMDiagram([[0,1],[1,2],[1]])\n sage: pm.sigma()\n [[1, 0], [2, 1], [1]]\n ' pm = self.pm_diagram return PMDiagram([list(reversed(a)) for a in pm])
def partitions_in_box(r, s): '\n Returns all partitions in a box of width s and height r.\n\n EXAMPLES::\n\n sage: sage.combinat.crystals.kirillov_reshetikhin.partitions_in_box(3,2)\n [[], [1], [2], [1, 1], [2, 1], [1, 1, 1], [2, 2], [2, 1, 1],\n [2, 2, 1], [2, 2, 2]]\n ' return [x for n in range(((r * s) + 1)) for x in Partitions(n, max_part=s, max_length=r)]
def vertical_dominoes_removed(r, s): '\n Returns all partitions obtained from a rectangle of width s and height r by removing\n vertical dominoes.\n\n EXAMPLES::\n\n sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(2,2)\n [[], [1, 1], [2, 2]]\n sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(3,2)\n [[2], [2, 1, 1], [2, 2, 2]]\n sage: sage.combinat.crystals.kirillov_reshetikhin.vertical_dominoes_removed(4,2)\n [[], [1, 1], [1, 1, 1, 1], [2, 2], [2, 2, 1, 1], [2, 2, 2, 2]]\n ' return [x.conjugate() for x in horizontal_dominoes_removed(s, r)]
def horizontal_dominoes_removed(r, s): '\n Returns all partitions obtained from a rectangle of width s and height r by removing\n horizontal dominoes.\n\n EXAMPLES::\n\n sage: sage.combinat.crystals.kirillov_reshetikhin.horizontal_dominoes_removed(2,2)\n [[], [2], [2, 2]]\n sage: sage.combinat.crystals.kirillov_reshetikhin.horizontal_dominoes_removed(3,2)\n [[], [2], [2, 2], [2, 2, 2]]\n ' ulist = [([y for y in x] + ([0] * (r - x.length()))) for x in partitions_in_box(r, (s // 2))] two = (lambda x: ((2 * (x - (s // 2))) + s)) return [Partition([two(y) for y in x]) for x in ulist]
class AmbientRetractMap(Map): '\n The retraction map from the ambient crystal.\n\n Consider a crystal embedding `\\phi : X \\to Y`, then the elements `X`\n can be considered as a subcrystal of the ambient crystal `Y`. The\n ambient retract is the partial map `\\tilde{\\phi} : Y \\to X` such that\n `\\tilde{\\phi} \\circ \\phi` is the identity on `X`.\n ' def __init__(self, base, ambient, pdict_inv, index_set, similarity_factor_domain=None, automorphism=None): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1], 3,1)\n sage: phi = K.from_ambient_crystal()\n sage: TestSuite(phi).run(skip=['_test_category', '_test_pickling'])\n " from sage.categories.sets_with_partial_maps import SetsWithPartialMaps Map.__init__(self, Hom(ambient, base, SetsWithPartialMaps())) if (similarity_factor_domain is None): similarity_factor_domain = {i: 1 for i in index_set} if (automorphism is None): automorphism = (lambda i: i) self._pdict_inv = pdict_inv self._automorphism = automorphism self._similarity_factor_domain = similarity_factor_domain self._index_set = index_set def _repr_type(self): "\n Return a string describing ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1], 3,1)\n sage: phi = K.from_ambient_crystal()\n sage: phi._repr_type()\n 'Ambient retract'\n " return 'Ambient retract' def _call_(self, x): "\n A fast map from the virtual image to the base crystal.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['B',3,1], 3,1)\n sage: phi = K.from_ambient_crystal()\n sage: b = K.ambient_crystal()(rows=[[1],[2],[-3]])\n sage: phi(b)\n [++-, []]\n " automorphism = self._automorphism sfd = self._similarity_factor_domain for i in self._index_set: c = x.e_string([i for k in range(sfd[i])]) if (c is not None): d = self(c).f(automorphism(i)) assert (d is not None) return d return self._pdict_inv[x]
class CrystalDiagramAutomorphism(CrystalMorphism): '\n The crystal automorphism induced from the diagram automorphism.\n\n For example, in type `A_n^{(1)}` this is the promotion operator and in\n type `D_n^{(1)}`, this corresponds to the automorphism induced from\n interchanging the `0` and `1` nodes in the Dynkin diagram.\n\n INPUT:\n\n - ``C`` -- a crystal\n - ``on_hw`` -- a function for the images of the ``index_set``-highest\n weight elements\n - ``index_set`` -- (default: the empty set) the index set\n - ``automorphism`` -- (default: the identity) the twisting automorphism\n - ``cache`` -- (default: True) cache the result\n ' def __init__(self, C, on_hw, index_set=None, automorphism=None, cache=True): "\n Construct the promotion operator.\n\n TESTS::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: p = K.promotion()\n sage: TestSuite(p).run(skip=['_test_category', '_test_pickling'])\n " if (automorphism is None): automorphism = (lambda i: i) if (index_set is None): index_set = () self._twist = automorphism if isinstance(on_hw, dict): self._on_hw = on_hw.__getitem__ else: self._on_hw = on_hw parent = Hom(C, C) self._cache = {} self._cache_result = bool(cache) if isinstance(cache, dict): self._cache = cache self._index_set = tuple(index_set) CrystalMorphism.__init__(self, parent, C.cartan_type()) def _call_(self, x): "\n Return the image of ``x`` under ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: p = K.promotion()\n sage: elt = K(3,1,3,1)\n sage: p(elt.lift())\n [[2, 2], [4, 4]]\n " if (x in self._cache): return self._cache[x] ind = self._index_set cur = x path = [] while (cur not in self._cache): n = None for i in ind: n = cur.e(i) if (n is not None): path.append(self._twist(i)) cur = n break if (n is None): break if (cur in self._cache): cur = self._cache[cur] else: cur = self._on_hw(cur) y = cur.f_string(reversed(path)) assert (y is not None) self._cache[x] = y return y def _repr_type(self): "\n Return a string describing ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: K.promotion()._repr_type()\n 'Diagram automorphism'\n " return 'Diagram automorphism' def is_isomorphism(self): "\n Return ``True`` as ``self`` is a crystal isomorphism.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A',3,1], 2,2)\n sage: K.promotion().is_isomorphism()\n True\n " return True is_surjective = is_isomorphism is_embedding = is_isomorphism is_strict = is_isomorphism __bool__ = is_isomorphism
class KyotoPathModel(TensorProductOfCrystals): "\n The Kyoto path model for an affine highest weight crystal.\n\n .. NOTE::\n\n Here we are using anti-Kashiwara notation and might differ from\n some of the literature.\n\n Consider a Kac--Moody algebra `\\mathfrak{g}` of affine Cartan type `X`,\n and we want to model the `U_q'(\\mathfrak{g})`-crystal `B(\\lambda)`.\n First we consider the set of fundamental weights `\\{\\Lambda_i\\}_{i \\in I}`\n of `\\mathfrak{g}` and let `\\{\\overline{\\Lambda}_i\\}_{i \\in I_0}` be the\n corresponding fundamental weights of the corresponding classical Lie\n algebra `\\mathfrak{g}_0`. To model `B(\\lambda)`, we start with a sequence\n of perfect `U_q'(\\mathfrak{g})`-crystals `(B^{(i)})_i` of level\n `l` such that\n\n .. MATH::\n\n \\lambda \\in \\overline{P}_l^+ = \\left\\{ \\mu \\in \\overline{P}^+ \\mid\n \\langle c, \\mu \\rangle = l \\right\\}\n\n where `c` is the canonical central element of `U_q'(\\mathfrak{g})`\n and `\\overline{P}^+` is the nonnegative weight lattice spanned by\n `\\{ \\overline{\\Lambda}_i \\mid i \\in I \\}`.\n\n Next we consider the crystal isomorphism `\\Phi_0 : B(\\lambda_0) \\to B^{(0)}\n \\otimes B(\\lambda_1)` defined by `u_{\\lambda_0} \\mapsto b^{(0)}_{\\lambda_0}\n \\otimes u_{\\lambda_1}` where `b^{(0)}_{\\lambda_0}` is the unique element in\n `B^{(0)}` such that `\\varphi\\left( b^{(0)}_{\\lambda_0} \\right) = \\lambda_0`\n and `\\lambda_1 = \\varepsilon\\left( b^{(0)}_{\\lambda_0} \\right)` and\n `u_{\\mu}` is the highest weight element in `B(\\mu)`. Iterating this, we\n obtain the following isomorphism:\n\n .. MATH::\n\n \\Phi_n : B(\\lambda) \\to B^{(0)} \\otimes B^{(1)} \\otimes \\cdots\n \\otimes B^{(N)} \\otimes B(\\lambda_{N+1}).\n\n We note by Lemma 10.6.2 in [HK2002]_ that for any `b \\in B(\\lambda)` there\n exists a finite `N` such that\n\n .. MATH::\n\n \\Phi_N(b) = \\left( \\bigotimes_{k=0}^{N-1} b^{(k)} \\right)\n \\otimes u_{\\lambda_N}.\n\n Therefore we can model elements `b \\in B(\\lambda)` as a\n `U_q'(\\mathfrak{g})`-crystal by considering an infinite list of\n elements `b^{(k)} \\in B^{(k)}` and defining the crystal structure by:\n\n .. MATH::\n\n \\begin{aligned}\n \\overline{\\mathrm{wt}}(b) & = \\lambda_N + \\sum_{k=0}^{N-1}\n \\overline{\\mathrm{wt}}\\left( b^{(k)} \\right)\n \\\\ e_i(b) & = e_i\\left( b^{\\prime} \\otimes b^{(N)} \\right) \\otimes\n u_{\\lambda_N},\n \\\\ f_i(b) & = f_i\\left( b^{\\prime} \\otimes b^{(N)} \\right) \\otimes\n u_{\\lambda_N},\n \\\\ \\varepsilon_i(b) & = \\max\\left( \\varepsilon_i(b^{\\prime}) -\n \\varphi_i\\left( b^{(N)} \\right), 0 \\right),\n \\\\ \\varphi_i(b) & = \\varphi_i(b^{\\prime}) + \\max\\left(\n \\varphi_i\\left( b^{(N)} \\right) - \\varepsilon_i(b^{\\prime}), 0 \\right),\n \\end{aligned}\n\n where `b^{\\prime} = b^{(0)} \\otimes \\cdots \\otimes b^{(N-1)}`. To\n translate this into a finite list, we consider a finite sequence\n `b^{(0)} \\otimes \\cdots \\otimes b^{(N-1)} \\otimes b^{(N)}_{\\lambda_N}`\n and if\n\n .. MATH::\n\n f_i\\left( b^{(0)} \\otimes \\cdots b^{(N-1)} \\otimes\n b^{(N)}_{\\lambda_N} \\right) = b_0 \\otimes \\cdots \\otimes b^{(N-1)}\n \\otimes f_i\\left( b^{(N)}_{\\lambda_N} \\right),\n\n then we take the image as `b^{(0)} \\otimes \\cdots \\otimes f_i\\left(\n b^{(N)}_{\\lambda_N}\\right) \\otimes b^{(N+1)}_{\\lambda_{N+1}}`. Similarly\n we remove `b^{(N)}_{\\lambda_{N}}` if we have `b_0 \\otimes \\cdots\n \\otimes b^{(N-1)} \\otimes b^{(N-1)}_{\\lambda_{N-1}} \\otimes\n b^{(N)}_{\\lambda_N}`. Additionally if\n\n .. MATH::\n\n e_i\\left( b^{(0)} \\otimes \\cdots \\otimes b^{(N-1)} \\otimes\n b^{(N)}_{\\lambda_N} \\right) = b^{(0)} \\otimes \\cdots \\otimes\n b^{(N-1)} \\otimes e_i\\left( b^{(N)}_{\\lambda_N} \\right),\n\n then we consider this to be `0`.\n\n We can then lift the `U_q'(\\mathfrak{g})`-crystal structure to a\n `U_q(\\mathfrak{g})`-crystal structure by using a tensor product of\n the :class:`affinization\n <sage.combinat.crystals.affinization.AffinizationOfCrystal>` of the\n of crystals `B^{(i)}` for all `i`.\n\n INPUT:\n\n - ``B`` -- a single or list of `U_q^{\\prime}` perfect crystal(s) of\n level `l`\n - ``weight`` -- a weight in `\\overline{P}_l^+`\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]; mg\n [[[3]]]\n sage: mg.f_string([0,1,2,2])\n [[[3]], [[3]], [[1]]]\n sage: x = mg.f_string([0,1,2]); x\n [[[2]], [[3]], [[1]]]\n sage: x.weight()\n Lambda[0]\n\n An example of type `A_5^{(2)}`::\n\n sage: B = crystals.KirillovReshetikhin(['A',5,2], 1,1)\n sage: La = RootSystem(['A',5,2]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]; mg\n [[[-1]]]\n sage: mg.f_string([0,2,1,3])\n [[[-3]], [[2]], [[-1]]]\n sage: mg.f_string([0,2,3,1])\n [[[-3]], [[2]], [[-1]]]\n\n An example of type `D_3^{(2)}`::\n\n sage: B = crystals.KirillovReshetikhin(['D',3,2], 1,1)\n sage: La = RootSystem(['D',3,2]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]; mg\n [[]]\n sage: mg.f_string([0,1,2,0])\n [[[0]], [[1]], []]\n\n An example using multiple crystals of the same level::\n\n sage: B1 = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: B2 = crystals.KirillovReshetikhin(['A',2,1], 2,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel([B1, B2, B1], La[0])\n sage: mg = C.module_generators[0]; mg\n [[[3]]]\n sage: mg.f_string([0,1,2,2])\n [[[3]], [[1], [3]], [[3]]]\n sage: mg.f_string([0,1,2,2,2])\n sage: mg.f_string([0,1,2,2,1,0])\n [[[3]], [[2], [3]], [[1]], [[2]]]\n sage: mg.f_string([0,1,2,2,1,0,0,2])\n [[[3]], [[1], [2]], [[1]], [[3]], [[1], [3]]]\n\n By using the extended weight lattice, the Kyoto path model lifts\n the perfect crystals to their affinizations::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: P = RootSystem(['A',2,1]).weight_lattice(extended=True)\n sage: La = P.fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]; mg\n [[[3]](0)]\n sage: x = mg.f_string([0,1,2]); x\n [[[2]](-1), [[3]](0), [[1]](0)]\n sage: x.weight()\n Lambda[0] - delta\n " @staticmethod def __classcall_private__(cls, crystals, weight, P=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: P = RootSystem(['A',2,1]).weight_lattice()\n sage: La = P.fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: C2 = crystals.KyotoPathModel((B,), La[0])\n sage: C3 = crystals.KyotoPathModel([B], La[0], P)\n sage: C is C2 and C2 is C3\n True\n " if isinstance(crystals, list): crystals = tuple(crystals) elif (not isinstance(crystals, tuple)): crystals = (crystals,) if any(((not B.is_perfect()) for B in crystals)): raise ValueError('all crystals must be perfect') level = crystals[0].level() if any(((B.level() != level) for B in crystals[1:])): raise ValueError('all crystals must have the same level') ct = crystals[0].cartan_type() if (P is None): P = weight.parent() if (sum(((ct.dual().c()[i] * weight.scalar(h)) for (i, h) in enumerate(P.simple_coroots()))) != level): raise ValueError('{} is not a level {} weight'.format(weight, level)) return super().__classcall__(cls, crystals, weight, P) def __init__(self, crystals, weight, P): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: TestSuite(C).run() # long time\n " Parent.__init__(self, category=(HighestWeightCrystals(), InfiniteEnumeratedSets())) self._cartan_type = crystals[0].cartan_type() self._weight = weight if weight.parent().is_extended(): self.crystals = tuple([C.affinization() for C in crystals]) self._epsilon_dicts = [{b.Epsilon(): self.crystals[i](b, 0) for b in B} for (i, B) in enumerate(crystals)] self._phi_dicts = [{b.Phi(): self.crystals[i](b, 0) for b in B} for (i, B) in enumerate(crystals)] else: self.crystals = tuple(crystals) self._epsilon_dicts = [{b.Epsilon(): b for b in B} for B in crystals] self._phi_dicts = [{b.Phi(): b for b in B} for B in crystals] self.module_generators = (self.element_class(self, [self._phi_dicts[0][weight]]),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: crystals.KyotoPathModel(B, La[0])\n Kyoto path realization of B(Lambda[0]) using\n [Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1)]\n " return 'Kyoto path realization of B({}) using {}'.format(self._weight, list(self.crystals)) def finite_tensor_product(self, k): "\n Return the finite tensor product of crystals of length ``k``\n from truncating ``self``.\n\n EXAMPLES::\n\n sage: B1 = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: B2 = crystals.KirillovReshetikhin(['A',2,1], 2,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel([B1,B2,B1], La[0])\n sage: C.finite_tensor_product(5)\n Full tensor product of the crystals\n [Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1),\n Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(2,1),\n Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1),\n Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(1,1),\n Kirillov-Reshetikhin crystal of type ['A', 2, 1] with (r,s)=(2,1)]\n " N = len(self.crystals) crystals = [self.crystals[(i % N)] for i in range(k)] return TensorProductOfCrystals(*crystals) def weight_lattice_realization(self): "\n Return the weight lattice realization used to express weights.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: C.weight_lattice_realization()\n Weight lattice of the Root system of type ['A', 2, 1]\n\n sage: P = RootSystem(['A',2,1]).weight_lattice(extended=True)\n sage: C = crystals.KyotoPathModel(B, P.fundamental_weight(0))\n sage: C.weight_lattice_realization()\n Extended weight lattice of the Root system of type ['A', 2, 1]\n " return self._weight.parent() class Element(TensorProductOfRegularCrystalsElement): '\n An element in the Kyoto path model.\n ' def epsilon(self, i): "\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]\n sage: [mg.epsilon(i) for i in C.index_set()]\n [0, 0, 0]\n sage: elt = mg.f(0)\n sage: [elt.epsilon(i) for i in C.index_set()]\n [1, 0, 0]\n sage: elt = mg.f_string([0,1,2])\n sage: [elt.epsilon(i) for i in C.index_set()]\n [0, 0, 1]\n sage: elt = mg.f_string([0,1,2,2])\n sage: [elt.epsilon(i) for i in C.index_set()]\n [0, 0, 2]\n " x = self.e(i) eps = 0 while (x is not None): x = x.e(i) eps = (eps + 1) return eps def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]\n sage: [mg.phi(i) for i in C.index_set()]\n [1, 0, 0]\n sage: elt = mg.f(0)\n sage: [elt.phi(i) for i in C.index_set()]\n [0, 1, 1]\n sage: elt = mg.f_string([0,1])\n sage: [elt.phi(i) for i in C.index_set()]\n [0, 0, 2]\n " x = self.f(i) phi = 0 while (x is not None): x = x.f(i) phi = (phi + 1) return phi def e(self, i): "\n Return the action of `e_i` on ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]\n sage: all(mg.e(i) is None for i in C.index_set())\n True\n sage: mg.f(0).e(0) == mg\n True\n " k = self.position_of_first_unmatched_plus(i) if (k is None): return None if (k == (len(self) - 1)): return None crystal = self[k].e(i) if ((k == (len(self) - 2)) and (crystal.Epsilon() == self[(- 1)].Phi())): l = self[:(- 1)] l[(- 1)] = crystal return self.__class__(self.parent(), l) return self._set_index(k, crystal) def f(self, i): "\n Return the action of `f_i` on ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]\n sage: mg.f(2)\n sage: mg.f(0)\n [[[1]], [[2]]]\n sage: mg.f_string([0,1,2])\n [[[2]], [[3]], [[1]]]\n " k = self.position_of_last_unmatched_minus(i) if (k is None): return None if (k == (len(self) - 1)): l = list(self) k = (len(l) % len(self.parent().crystals)) l.append(self.parent()._phi_dicts[k][l[(- 1)].Epsilon()]) l[(- 2)] = l[(- 2)].f(i) return self.__class__(self.parent(), l) return self._set_index(k, self[k].f(i)) def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: P = RootSystem(['A',2,1]).weight_lattice(extended=True)\n sage: La = P.fundamental_weights()\n sage: C = crystals.KyotoPathModel(B, La[0])\n sage: mg = C.module_generators[0]\n sage: mg.weight()\n Lambda[0]\n sage: mg.f_string([0,1,2]).weight()\n Lambda[0] - delta\n " wt = TensorProductOfRegularCrystalsElement.weight(self) return (wt + self[(- 1)].Epsilon()) def truncate(self, k=None): "\n Truncate ``self`` to have length ``k`` and return as an element\n in a (finite) tensor product of crystals.\n\n INPUT:\n\n - ``k`` -- (optional) the length to truncate to; if not specified,\n then returns one more than the current non-ground-state elements\n (i.e. the current list in ``self``)\n\n EXAMPLES::\n\n sage: B1 = crystals.KirillovReshetikhin(['A',2,1], 1,1)\n sage: B2 = crystals.KirillovReshetikhin(['A',2,1], 2,1)\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: C = crystals.KyotoPathModel([B1,B2,B1], La[0])\n sage: mg = C.highest_weight_vector()\n sage: elt = mg.f_string([0,1,2,2,1,0]); elt\n [[[3]], [[2], [3]], [[1]], [[2]]]\n sage: t = elt.truncate(); t\n [[[3]], [[2], [3]], [[1]], [[2]]]\n sage: t.parent() is C.finite_tensor_product(4)\n True\n sage: elt.truncate(2)\n [[[3]], [[2], [3]]]\n sage: elt.truncate(10)\n [[[3]], [[2], [3]], [[1]], [[2]], [[1], [3]],\n [[2]], [[1]], [[2], [3]], [[1]], [[3]]]\n " if (k is None): k = len(self) P = self.parent().finite_tensor_product(k) if (k <= len(self)): l = self[:k] else: l = list(self) N = len(self.parent().crystals) while (len(l) < k): i = (len(l) % N) l.append(self.parent()._phi_dicts[i][l[(- 1)].Epsilon()]) return P(*l)
class CrystalOfLSPaths(UniqueRepresentation, Parent): "\n Crystal graph of LS paths generated from the straight-line path to a given weight.\n\n INPUT:\n\n - ``cartan_type`` -- (optional) the Cartan type of a finite or affine root system\n - ``starting_weight`` -- a weight; if ``cartan_type`` is given, then the weight should\n be given as a list of coefficients of the fundamental weights, otherwise it should\n be given in the ``weight_space`` basis; for affine highest weight crystals, one needs\n to use the extended weight space.\n\n The crystal class of piecewise linear paths in the weight space,\n generated from a straight-line path from the origin to a given\n element of the weight lattice.\n\n OUTPUT:\n\n - a tuple of weights defining the directions of the piecewise linear segments\n\n EXAMPLES::\n\n sage: R = RootSystem(['A',2,1])\n sage: La = R.weight_space(extended = True).basis()\n sage: B = crystals.LSPaths(La[2]-La[0]); B\n The crystal of LS paths of type ['A', 2, 1] and weight -Lambda[0] + Lambda[2]\n\n sage: C = crystals.LSPaths(['A',2,1],[-1,0,1]); C\n The crystal of LS paths of type ['A', 2, 1] and weight -Lambda[0] + Lambda[2]\n sage: B == C\n True\n sage: c = C.module_generators[0]; c\n (-Lambda[0] + Lambda[2],)\n sage: [c.f(i) for i in C.index_set()]\n [None, None, (Lambda[1] - Lambda[2],)]\n\n sage: R = C.R; R\n Root system of type ['A', 2, 1]\n sage: Lambda = R.weight_space().basis(); Lambda\n Finite family {0: Lambda[0], 1: Lambda[1], 2: Lambda[2]}\n sage: b=C(tuple([-Lambda[0]+Lambda[2]]))\n sage: b==c\n True\n sage: b.f(2)\n (Lambda[1] - Lambda[2],)\n\n For classical highest weight crystals we can also compare the results with the tableaux implementation::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: sorted(C, key=str)\n [(-2*Lambda[1] + Lambda[2],), (-Lambda[1] + 1/2*Lambda[2], Lambda[1] - 1/2*Lambda[2]),\n (-Lambda[1] + 2*Lambda[2],), (-Lambda[1] - Lambda[2],),\n (1/2*Lambda[1] - Lambda[2], -1/2*Lambda[1] + Lambda[2]), (2*Lambda[1] - Lambda[2],),\n (Lambda[1] + Lambda[2],), (Lambda[1] - 2*Lambda[2],)]\n sage: C.cardinality()\n 8\n sage: B = crystals.Tableaux(['A',2],shape=[2,1])\n sage: B.cardinality()\n 8\n sage: B.digraph().is_isomorphic(C.digraph())\n True\n\n Make sure you use the weight space and not the weight lattice for your weights::\n\n sage: R = RootSystem(['A',2,1])\n sage: La = R.weight_lattice(extended = True).basis()\n sage: B = crystals.LSPaths(La[2]); B\n Traceback (most recent call last):\n ...\n ValueError: Please use the weight space, rather than weight lattice for your weights\n\n REFERENCES:\n\n .. [Li1995b]_\n " @staticmethod def __classcall_private__(cls, starting_weight, cartan_type=None, starting_weight_parent=None): "\n Classcall to mend the input.\n\n Internally, the\n :class:`~sage.combinat.crystals.littelmann_path.CrystalOfLSPaths` code\n works with a ``starting_weight`` that is in the weight space associated\n to the crystal. The user can, however, also input a ``cartan_type``\n and the coefficients of the fundamental weights as\n ``starting_weight``. This code transforms the input into the right\n format (also necessary for UniqueRepresentation).\n\n TESTS::\n\n sage: crystals.LSPaths(['A',2,1],[-1,0,1])\n The crystal of LS paths of type ['A', 2, 1] and weight -Lambda[0] + Lambda[2]\n\n sage: R = RootSystem(['B',2,1])\n sage: La = R.weight_space(extended=True).basis()\n sage: C = crystals.LSPaths(['B',2,1],[0,0,1])\n sage: B = crystals.LSPaths(La[2])\n sage: B is C\n True\n " if (cartan_type is not None): (cartan_type, starting_weight) = (CartanType(starting_weight), cartan_type) extended = cartan_type.is_affine() R = RootSystem(cartan_type) P = R.weight_space(extended=extended) Lambda = P.basis() offset = R.index_set()[Integer(0)] starting_weight = P.sum(((starting_weight[(j - offset)] * Lambda[j]) for j in R.index_set())) if (starting_weight_parent is None): starting_weight_parent = starting_weight.parent() elif (starting_weight.parent() != starting_weight_parent): raise ValueError('The passed parent is not equal to parent of the inputted weight!') return super().__classcall__(cls, starting_weight, starting_weight_parent=starting_weight_parent) def __init__(self, starting_weight, starting_weight_parent): "\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2,1],[-1,0,1]); C\n The crystal of LS paths of type ['A', 2, 1] and weight -Lambda[0] + Lambda[2]\n sage: C.R\n Root system of type ['A', 2, 1]\n sage: C.weight\n -Lambda[0] + Lambda[2]\n sage: C.weight.parent()\n Extended weight space over the Rational Field of the Root system of type ['A', 2, 1]\n sage: C.module_generators\n ((-Lambda[0] + Lambda[2],),)\n\n TESTS::\n\n sage: C = crystals.LSPaths(['A',2,1], [-1,0,1])\n sage: TestSuite(C).run() # long time\n sage: C = crystals.LSPaths(['E',6], [1,0,0,0,0,0])\n sage: TestSuite(C).run()\n\n sage: R = RootSystem(['C',3,1])\n sage: La = R.weight_space().basis()\n sage: LaE = R.weight_space(extended=True).basis()\n sage: B = crystals.LSPaths(La[0])\n sage: BE = crystals.LSPaths(LaE[0])\n sage: B is BE\n False\n sage: B.weight_lattice_realization()\n Weight space over the Rational Field of the Root system of type ['C', 3, 1]\n sage: BE.weight_lattice_realization()\n Extended weight space over the Rational Field of the Root system of type ['C', 3, 1]\n " cartan_type = starting_weight.parent().cartan_type() self.R = RootSystem(cartan_type) self.weight = starting_weight if (not self.weight.parent().base_ring().has_coerce_map_from(QQ)): raise ValueError('Please use the weight space, rather than weight lattice for your weights') self._cartan_type = cartan_type self._name = ('The crystal of LS paths of type %s and weight %s' % (cartan_type, starting_weight)) if cartan_type.is_affine(): if all(((i >= 0) for i in starting_weight.coefficients())): Parent.__init__(self, category=(RegularCrystals(), HighestWeightCrystals(), InfiniteEnumeratedSets())) elif starting_weight.parent().is_extended(): Parent.__init__(self, category=(RegularCrystals(), InfiniteEnumeratedSets())) else: cl = self._cartan_type.classical().index_set() if (sum((self.weight[i] for i in cl)) == 1): cat = KirillovReshetikhinCrystals() else: cat = RegularLoopCrystals().Finite() Parent.__init__(self, category=cat) else: Parent.__init__(self, category=ClassicalCrystals()) if (starting_weight == starting_weight.parent().zero()): initial_element = self(()) else: initial_element = self((starting_weight,)) self.module_generators = (initial_element,) def _repr_(self): "\n EXAMPLES::\n\n sage: crystals.LSPaths(['B',3],[1,1,0]) # indirect doctest\n The crystal of LS paths of type ['B', 3] and weight Lambda[1] + Lambda[2]\n " return self._name def weight_lattice_realization(self): "\n Return weight lattice realization of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.LSPaths(['B',3],[1,1,0])\n sage: B.weight_lattice_realization()\n Weight space over the Rational Field of the Root system of type ['B', 3]\n sage: B = crystals.LSPaths(['B',3,1],[1,1,1,0])\n sage: B.weight_lattice_realization()\n Extended weight space over the Rational Field of the Root system of type ['B', 3, 1]\n " return self.weight.parent() class Element(ElementWrapper): "\n TESTS::\n\n sage: C = crystals.LSPaths(['E',6],[1,0,0,0,0,0])\n sage: c = C.an_element()\n sage: TestSuite(c).run()\n " def endpoint(self): "\n Computes the endpoint of the path.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: b = C.module_generators[0]\n sage: b.endpoint()\n Lambda[1] + Lambda[2]\n sage: b.f_string([1,2,2,1])\n (-Lambda[1] - Lambda[2],)\n sage: b.f_string([1,2,2,1]).endpoint()\n -Lambda[1] - Lambda[2]\n sage: b.f_string([1,2])\n (1/2*Lambda[1] - Lambda[2], -1/2*Lambda[1] + Lambda[2])\n sage: b.f_string([1,2]).endpoint()\n 0\n sage: b = C([])\n sage: b.endpoint()\n 0\n " if (len(self.value) > 0): return sum(self.value) return self.parent().weight.parent().zero() def compress(self): "\n Merges consecutive positively parallel steps present in the path.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: Lambda = C.R.weight_space().fundamental_weights(); Lambda\n Finite family {1: Lambda[1], 2: Lambda[2]}\n sage: c = C(tuple([1/2*Lambda[1]+1/2*Lambda[2], 1/2*Lambda[1]+1/2*Lambda[2]]))\n sage: c.compress()\n (Lambda[1] + Lambda[2],)\n " if (not self.value): return self q = [] curr = self.value[0] for v in self.value[1:]: if positively_parallel_weights(curr, v): curr = (curr + v) else: q.append(curr) curr = v q.append(curr) return self.parent()(tuple(q)) def split_step(self, which_step, r): "\n Splits indicated step into two parallel steps of relative lengths `r` and `1-r`.\n\n INPUT:\n\n - ``which_step`` -- a position in the tuple ``self``\n - ``r`` -- a rational number between 0 and 1\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: b = C.module_generators[0]\n sage: b.split_step(0,1/3)\n (1/3*Lambda[1] + 1/3*Lambda[2], 2/3*Lambda[1] + 2/3*Lambda[2])\n " assert (0 <= which_step <= len(self.value)) v = self.value[which_step] return self.parent()(((self.value[:which_step] + ((r * v), ((1 - r) * v))) + self.value[(which_step + 1):])) def reflect_step(self, which_step, i): "\n Apply the `i`-th simple reflection to the indicated step in ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: b = C.module_generators[0]\n sage: b.reflect_step(0,1)\n (-Lambda[1] + 2*Lambda[2],)\n sage: b.reflect_step(0,2)\n (2*Lambda[1] - Lambda[2],)\n " assert (i in self.index_set()) assert ((0 <= which_step) and (which_step <= len(self.value))) return self.parent()(((self.value[:which_step] + tuple([self.value[which_step].simple_reflection(i)])) + self.value[(which_step + 1):])) def _string_data(self, i): "\n Computes the `i`-string data of ``self``.\n\n TESTS::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: b = C.module_generators[0]\n sage: b._string_data(1)\n ()\n sage: b._string_data(2)\n ()\n sage: b.f(1)._string_data(1)\n ((0, -1, -1),)\n sage: b.f(1).f(2)._string_data(2)\n ((0, -1, -1),)\n " if (not self.value): return () alv = self.value[0].parent().alphacheck()[i] steps = [v.scalar(alv) for v in self.value] minima_pos = [] ps = 0 psmin = 0 for (ix, step) in enumerate(steps): ps = (ps + step) if (ps < psmin): minima_pos.append((ix, ps, step)) psmin = ps return tuple(minima_pos) def epsilon(self, i): "\n Returns the distance to the beginning of the `i`-string.\n\n This method overrides the generic implementation in the category of crystals\n since this computation is more efficient.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: [c.epsilon(1) for c in C]\n [0, 1, 0, 0, 1, 0, 1, 2]\n sage: [c.epsilon(2) for c in C]\n [0, 0, 1, 2, 1, 1, 0, 0]\n " return self.e(i, length_only=True) def phi(self, i): "\n Returns the distance to the end of the `i`-string.\n\n This method overrides the generic implementation in the category of crystals\n since this computation is more efficient.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: [c.phi(1) for c in C]\n [1, 0, 0, 1, 0, 2, 1, 0]\n sage: [c.phi(2) for c in C]\n [1, 2, 1, 0, 0, 0, 0, 1]\n " return self.f(i, length_only=True) def e(self, i, power=1, to_string_end=False, length_only=False): "\n Returns the `i`-th crystal raising operator on ``self``.\n\n INPUT:\n\n - ``i`` -- element of the index set of the underlying root system\n - ``power`` -- positive integer; specifies the power of the raising operator\n to be applied (default: 1)\n - ``to_string_end`` -- boolean; if set to True, returns the dominant end of the\n `i`-string of ``self``. (default: False)\n - ``length_only`` -- boolean; if set to True, returns the distance to the dominant\n end of the `i`-string of ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: c = C[2]; c\n (1/2*Lambda[1] - Lambda[2], -1/2*Lambda[1] + Lambda[2])\n sage: c.e(1)\n sage: c.e(2)\n (-Lambda[1] + 2*Lambda[2],)\n sage: c.e(2,to_string_end=True)\n (-Lambda[1] + 2*Lambda[2],)\n sage: c.e(1,to_string_end=True)\n (1/2*Lambda[1] - Lambda[2], -1/2*Lambda[1] + Lambda[2])\n sage: c.e(1,length_only=True)\n 0\n " assert (i in self.index_set()) data = self._string_data(i) if (not data): M = 0 else: M = data[(- 1)][1] max_raisings = floor((- M)) if length_only: return max_raisings if to_string_end: p = max_raisings else: p = power if (p > max_raisings): return None ws = self.parent()(self.value) ix = (len(data) - 1) while ((ix >= 0) and (data[ix][1] < (M + p))): j = data[ix][0] if (ix == 0): prev_ht = (M + p) else: prev_ht = min(data[(ix - 1)][1], (M + p)) if ((data[ix][1] - data[ix][2]) > prev_ht): ws = ws.split_step(j, (1 - ((prev_ht - data[ix][1]) / (- data[ix][2])))) ws = ws.reflect_step((j + 1), i) else: ws = ws.reflect_step(j, i) ix = (ix - 1) return self.parent()(ws.compress()) def dualize(self): '\n Returns dualized path.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths([\'A\',2],[1,1])\n sage: for c in C:\n ....: print("{} {}".format(c, c.dualize()))\n (Lambda[1] + Lambda[2],) (-Lambda[1] - Lambda[2],)\n (-Lambda[1] + 2*Lambda[2],) (Lambda[1] - 2*Lambda[2],)\n (1/2*Lambda[1] - Lambda[2], -1/2*Lambda[1] + Lambda[2]) (1/2*Lambda[1] - Lambda[2], -1/2*Lambda[1] + Lambda[2])\n (Lambda[1] - 2*Lambda[2],) (-Lambda[1] + 2*Lambda[2],)\n (-Lambda[1] - Lambda[2],) (Lambda[1] + Lambda[2],)\n (2*Lambda[1] - Lambda[2],) (-2*Lambda[1] + Lambda[2],)\n (-Lambda[1] + 1/2*Lambda[2], Lambda[1] - 1/2*Lambda[2]) (-Lambda[1] + 1/2*Lambda[2], Lambda[1] - 1/2*Lambda[2])\n (-2*Lambda[1] + Lambda[2],) (2*Lambda[1] - Lambda[2],)\n ' if (not self.value): return self dual_path = [(- v) for v in reversed(self.value)] return self.parent()(tuple(dual_path)) def f(self, i, power=1, to_string_end=False, length_only=False): "\n Returns the `i`-th crystal lowering operator on ``self``.\n\n INPUT:\n\n - ``i`` -- element of the index set of the underlying root system\n - ``power`` -- positive integer; specifies the power of the lowering operator\n to be applied (default: 1)\n - ``to_string_end`` -- boolean; if set to True, returns the anti-dominant end of the\n `i`-string of ``self``. (default: False)\n - ``length_only`` -- boolean; if set to True, returns the distance to the anti-dominant\n end of the `i`-string of ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: c = C.module_generators[0]\n sage: c.f(1)\n (-Lambda[1] + 2*Lambda[2],)\n sage: c.f(1,power=2)\n sage: c.f(2)\n (2*Lambda[1] - Lambda[2],)\n sage: c.f(2,to_string_end=True)\n (2*Lambda[1] - Lambda[2],)\n sage: c.f(2,length_only=True)\n 1\n\n sage: C = crystals.LSPaths(['A',2,1],[-1,-1,2])\n sage: c = C.module_generators[0]\n sage: c.f(2,power=2)\n (Lambda[0] + Lambda[1] - 2*Lambda[2],)\n " dual_path = self.dualize() dual_path = dual_path.e(i, power, to_string_end, length_only) if length_only: return dual_path if (dual_path is None): return None return dual_path.dualize() def s(self, i): "\n Computes the reflection of ``self`` along the `i`-string.\n\n This method is more efficient than the generic implementation since it uses\n powers of `e` and `f` in the Littelmann model directly.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: c = C.module_generators[0]\n sage: c.s(1)\n (-Lambda[1] + 2*Lambda[2],)\n sage: c.s(2)\n (2*Lambda[1] - Lambda[2],)\n\n sage: C = crystals.LSPaths(['A',2,1],[-1,0,1])\n sage: c = C.module_generators[0]; c\n (-Lambda[0] + Lambda[2],)\n sage: c.s(2)\n (Lambda[1] - Lambda[2],)\n sage: c.s(1)\n (-Lambda[0] + Lambda[2],)\n sage: c.f(2).s(1)\n (Lambda[0] - Lambda[1],)\n " ph = self.phi(i) ep = self.epsilon(i) diff = (ph - ep) if (diff >= 0): return self.f(i, power=diff) else: return self.e(i, power=(- diff)) def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.LSPaths(['A',1,1],[1,0])\n sage: b = B.highest_weight_vector()\n sage: b.f(0).weight()\n -Lambda[0] + 2*Lambda[1] - delta\n " P = self.parent().weight_lattice_realization() return sum([p for p in self.value], P.zero()) def _latex_(self): "\n Latex method for ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.LSPaths(['A',2],[1,1])\n sage: c = C.module_generators[0]\n sage: c._latex_()\n [\\Lambda_{1} + \\Lambda_{2}]\n " return [latex(p) for p in self.value]
class CrystalOfProjectedLevelZeroLSPaths(CrystalOfLSPaths): "\n Crystal of projected level zero LS paths.\n\n INPUT:\n\n - ``weight`` -- a dominant weight of the weight space of an affine\n Kac-Moody root system\n\n When ``weight`` is just a single fundamental weight `\\Lambda_r`, this\n crystal is isomorphic to a Kirillov-Reshetikhin (KR) crystal, see also\n :meth:`sage.combinat.crystals.kirillov_reshetikhin.KirillovReshetikhinFromLSPaths`.\n For general weights, it is isomorphic to a tensor product of\n single-column KR crystals.\n\n EXAMPLES::\n\n sage: R = RootSystem(['C',3,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[3])\n sage: LS.cardinality()\n 84\n sage: GLS = LS.digraph()\n\n sage: K1 = crystals.KirillovReshetikhin(['C',3,1],1,1)\n sage: K3 = crystals.KirillovReshetikhin(['C',3,1],3,1)\n sage: T = crystals.TensorProduct(K3,K1)\n sage: T.cardinality()\n 84\n sage: GT = T.digraph() # long time\n sage: GLS.is_isomorphic(GT, edge_labels = True) # long time\n True\n\n TESTS::\n\n sage: ct = CartanType(['A',4,2]).dual()\n sage: P = RootSystem(ct).weight_space()\n sage: La = P.fundamental_weights()\n sage: C = crystals.ProjectedLevelZeroLSPaths(La[1])\n sage: sorted(C, key=str)\n [(-Lambda[0] + Lambda[1],),\n (-Lambda[1] + 2*Lambda[2],),\n (1/2*Lambda[1] - Lambda[2], -1/2*Lambda[1] + Lambda[2]),\n (Lambda[0] - Lambda[1],),\n (Lambda[1] - 2*Lambda[2],)]\n " @staticmethod def __classcall_private__(cls, weight): "\n Classcall to mend the input.\n\n Internally, the\n :class:`~sage.combinat.crystals.littelmann_path.CrystalOfProjectedLevelZeroLSPaths`\n uses a level zero weight, which is passed on to\n :class:`~sage.combinat.crystals.littelmann_path.CrystalOfLSPaths`.\n ``weight`` is first coerced to a level zero weight.\n\n TESTS::\n\n sage: R = RootSystem(['C',3,1])\n sage: La = R.weight_space().basis()\n sage: C = crystals.ProjectedLevelZeroLSPaths(La[1] + La[2])\n sage: C2 = crystals.ProjectedLevelZeroLSPaths(La[1] + La[2])\n sage: C is C2\n True\n\n sage: R = RootSystem(['C',3,1])\n sage: La = R.weight_space(extended = True).basis()\n sage: crystals.ProjectedLevelZeroLSPaths(La[1] + La[2])\n Traceback (most recent call last):\n ...\n ValueError: The weight should be in the non-extended weight lattice!\n " if weight.parent().is_extended(): raise ValueError('The weight should be in the non-extended weight lattice!') La = weight.parent().basis() weight = (weight - ((weight.level() * La[0]) / La[0].level())) return super().__classcall__(cls, weight, starting_weight_parent=weight.parent()) @cached_method def maximal_vector(self): "\n Return the maximal vector of ``self``.\n\n EXAMPLES::\n\n sage: R = RootSystem(['A',2,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]+La[2])\n sage: LS.maximal_vector()\n (-3*Lambda[0] + 2*Lambda[1] + Lambda[2],)\n " return self.module_generators[0] @cached_method def classically_highest_weight_vectors(self): "\n Return the classically highest weight vectors of ``self``.\n\n EXAMPLES::\n\n sage: R = RootSystem(['A',2,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1])\n sage: LS.classically_highest_weight_vectors()\n ((-2*Lambda[0] + 2*Lambda[1],),\n (-Lambda[0] + Lambda[1], -Lambda[1] + Lambda[2]))\n " I0 = self.cartan_type().classical().index_set() return tuple([x for x in self.list() if x.is_highest_weight(I0)]) def one_dimensional_configuration_sum(self, q=None, group_components=True): "\n Compute the one-dimensional configuration sum.\n\n INPUT:\n\n - ``q`` -- (default: ``None``) a variable or ``None``; if ``None``,\n a variable ``q`` is set in the code\n - ``group_components`` -- (default: ``True``) boolean; if ``True``,\n then the terms are grouped by classical component\n\n The one-dimensional configuration sum is the sum of the weights\n of all elements in the crystal weighted by the energy function.\n For untwisted types it uses the parabolic quantum Bruhat graph,\n see [LNSSS2013]_. In the dual-of-untwisted case, the parabolic\n quantum Bruhat graph is defined by exchanging the roles of roots\n and coroots (which is still conjectural at this point).\n\n EXAMPLES::\n\n sage: R = RootSystem(['A',2,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1])\n sage: LS.one_dimensional_configuration_sum() # long time\n B[-2*Lambda[1] + 2*Lambda[2]] + (q+1)*B[-Lambda[1]]\n + (q+1)*B[Lambda[1] - Lambda[2]] + B[2*Lambda[1]]\n + B[-2*Lambda[2]] + (q+1)*B[Lambda[2]]\n sage: R.<t> = ZZ[]\n sage: LS.one_dimensional_configuration_sum(t, False) # long time\n B[-2*Lambda[1] + 2*Lambda[2]] + (t+1)*B[-Lambda[1]]\n + (t+1)*B[Lambda[1] - Lambda[2]] + B[2*Lambda[1]]\n + B[-2*Lambda[2]] + (t+1)*B[Lambda[2]]\n\n TESTS::\n\n sage: R = RootSystem(['B',3,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[2])\n sage: LS.one_dimensional_configuration_sum() == LS.one_dimensional_configuration_sum(group_components=False) # long time\n True\n sage: K1 = crystals.KirillovReshetikhin(['B',3,1],1,1)\n sage: K2 = crystals.KirillovReshetikhin(['B',3,1],2,1)\n sage: T = crystals.TensorProduct(K2,K1)\n sage: T.one_dimensional_configuration_sum() == LS.one_dimensional_configuration_sum() # long time\n True\n\n sage: R = RootSystem(['D',4,2])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[2])\n sage: K1 = crystals.KirillovReshetikhin(['D',4,2],1,1)\n sage: K2 = crystals.KirillovReshetikhin(['D',4,2],2,1)\n sage: T = crystals.TensorProduct(K2,K1)\n sage: T.one_dimensional_configuration_sum() == LS.one_dimensional_configuration_sum() # long time\n True\n\n sage: R = RootSystem(['A',5,2])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(3*La[1])\n sage: K1 = crystals.KirillovReshetikhin(['A',5,2],1,1)\n sage: T = crystals.TensorProduct(K1,K1,K1)\n sage: T.one_dimensional_configuration_sum() == LS.one_dimensional_configuration_sum() # long time\n True\n " if (q is None): from sage.rings.rational_field import QQ q = QQ['q'].gens()[0] P0 = RootSystem(self.cartan_type().classical()).weight_lattice() B = P0.algebra(q.parent()) def weight(x): w = x.weight() return P0.sum(((int(c) * P0.basis()[i]) for (i, c) in w if (i in P0.index_set()))) if group_components: G = self.digraph(index_set=self.cartan_type().classical().index_set()) C = G.connected_components(sort=False) return sum((((q ** c[0].energy_function()) * B.sum((B(weight(b)) for b in c))) for c in C)) return B.sum((((q ** b.energy_function()) * B(weight(b))) for b in self)) def is_perfect(self, level=1): "\n Check whether the crystal ``self`` is perfect (of level ``level``).\n\n INPUT:\n\n - ``level`` -- (default: 1) positive integer\n\n A crystal `\\mathcal{B}` is perfect of level `\\ell` if:\n\n #. `\\mathcal{B}` is isomorphic to the crystal graph of a\n finite-dimensional `U_q^{'}(\\mathfrak{g})`-module.\n #. `\\mathcal{B}\\otimes \\mathcal{B}` is connected.\n #. There exists a `\\lambda\\in X`, such that\n `\\mathrm{wt}(\\mathcal{B}) \\subset \\lambda + \\sum_{i\\in I} \\ZZ_{\\le 0} \\alpha_i`\n and there is a unique element in\n `\\mathcal{B}` of classical weight `\\lambda`.\n #. For all `b \\in \\mathcal{B}`,\n `\\mathrm{level}(\\varepsilon (b)) \\geq \\ell`.\n #. For all `\\Lambda` dominant weights of level `\\ell`, there exist\n unique elements `b_{\\Lambda}, b^{\\Lambda} \\in \\mathcal{B}`, such\n that `\\varepsilon (b_{\\Lambda}) = \\Lambda = \\varphi(b^{\\Lambda})`.\n\n Points (1)-(3) are known to hold. This method checks points (4) and (5).\n\n EXAMPLES::\n\n sage: C = CartanType(['C',2,1])\n sage: R = RootSystem(C)\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1])\n sage: LS.is_perfect()\n False\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[2])\n sage: LS.is_perfect()\n True\n\n sage: C = CartanType(['E',6,1])\n sage: R = RootSystem(C)\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1])\n sage: LS.is_perfect()\n True\n sage: LS.is_perfect(2)\n False\n\n sage: C = CartanType(['D',4,1])\n sage: R = RootSystem(C)\n sage: La = R.weight_space().basis()\n sage: all(crystals.ProjectedLevelZeroLSPaths(La[i]).is_perfect() for i in [1,2,3,4])\n True\n\n sage: C = CartanType(['A',6,2])\n sage: R = RootSystem(C)\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[2])\n sage: LS.is_perfect()\n True\n sage: LS.is_perfect(2)\n False\n " MPhi = [] for b in self: p = b.Phi().level() assert (p == b.Epsilon().level()) if (p < level): return False if (p == level): MPhi += [b] weights = [] I = self.index_set() rank = len(I) La = self.weight_lattice_realization().basis() from sage.combinat.integer_vector import IntegerVectors for n in range(1, (level + 1)): for c in IntegerVectors(n, rank): w = sum(((c[i] * La[i]) for i in I)) if (w.level() == level): weights.append(w) return (sorted([b.Phi() for b in MPhi]) == sorted(weights)) class Element(CrystalOfLSPaths.Element): '\n Element of a crystal of projected level zero LS paths.\n ' @cached_in_parent_method def scalar_factors(self): "\n Obtain the scalar factors for ``self``.\n\n Each LS path (or ``self``) can be written as a piecewise linear map\n\n .. MATH::\n\n \\pi(t) = \\sum_{u'=1}^{u-1} (\\sigma_{u'} - \\sigma_{u'-1}) \\nu_{u'}\n + (t-\\sigma_{u-1}) \\nu_{u}\n\n for `0 < \\sigma_1 < \\sigma_2 < \\cdots < \\sigma_s=1` and\n `\\sigma_{u-1} \\le t \\le \\sigma_{u}` and `1 \\le u \\le s`.\n This method returns the tuple of `(\\sigma_1,\\ldots,\\sigma_s)`.\n\n EXAMPLES::\n\n sage: R = RootSystem(['C',3,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[3])\n sage: b = LS.module_generators[0]\n sage: b.scalar_factors()\n [1]\n sage: c = b.f(1).f(3).f(2)\n sage: c.scalar_factors()\n [1/3, 1]\n " weight = self.parent().weight l = [] s = 0 for c in self.value: supp = c.support() if supp: i = supp[0] for w in weight._orbit_iter(): if (((c[i] * w[i]) > 0) and ((c[i] * w) == (w[i] * c))): s += (c[i] / w[i]) l += [s] break return l @cached_in_parent_method def weyl_group_representation(self): "\n Transform the weights in the LS path ``self`` to elements\n in the Weyl group.\n\n Each LS path can be written as the piecewise linear map:\n\n .. MATH::\n\n \\pi(t) = \\sum_{u'=1}^{u-1} (\\sigma_{u'} - \\sigma_{u'-1}) \\nu_{u'}\n + (t-\\sigma_{u-1}) \\nu_{u}\n\n for `0 < \\sigma_1 < \\sigma_2 < \\cdots < \\sigma_s = 1` and\n `\\sigma_{u-1} \\le t \\le \\sigma_{u}` and `1 \\le u \\le s`.\n Each weight `\\nu_u` is also associated to a Weyl group element.\n This method returns the list of Weyl group elements associated\n to the `\\nu_u` for `1\\le u\\le s`.\n\n EXAMPLES::\n\n sage: R = RootSystem(['C',3,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[3])\n sage: b = LS.module_generators[0]\n sage: c = b.f(1).f(3).f(2)\n sage: c.weyl_group_representation()\n [s2*s1*s3, s1*s3]\n " cartan = self.parent().weight.parent().cartan_type().classical() I = cartan.index_set() W = WeylGroup(cartan, prefix='s', implementation='permutation') return [W.from_reduced_word(x.to_dominant_chamber(index_set=I, reduced_word=True)[1]) for x in self.value] @cached_in_parent_method def energy_function(self): '\n Return the energy function of ``self``.\n\n The energy function `D(\\pi)` of the level zero LS path\n `\\pi \\in \\mathbb{B}_\\mathrm{cl}(\\lambda)` requires a series\n of definitions; for simplicity the root system is assumed to\n be untwisted affine.\n\n The LS path `\\pi` is a piecewise linear map from the unit\n interval `[0,1]` to the weight lattice. It is specified by\n "times" `0 = \\sigma_0 < \\sigma_1 < \\dotsm < \\sigma_s = 1` and\n "direction vectors" `x_u \\lambda` where `x_u \\in W / W_J` for\n `1 \\le u \\le s`, and `W_J` is the stabilizer of `\\lambda` in\n the finite Weyl group `W`. Precisely,\n\n .. MATH::\n\n \\pi(t) = \\sum_{u\'=1}^{u-1} (\\sigma_{u\'}-\\sigma_{u\'-1})\n x_{u\'} \\lambda + (t-\\sigma_{u-1}) x_{u} \\lambda\n\n for `1 \\le u \\le s` and `\\sigma_{u-1} \\le t \\le \\sigma_{u}`.\n\n For any `x,y \\in W / W_J`, let\n\n .. MATH::\n\n d: x = w_{0} \\stackrel{\\beta_{1}}{\\leftarrow}\n w_{1} \\stackrel{\\beta_{2}}{\\leftarrow} \\cdots\n \\stackrel{\\beta_{n}}{\\leftarrow} w_{n}=y\n\n be a shortest directed path in the parabolic quantum\n Bruhat graph. Define\n\n .. MATH::\n\n \\mathrm{wt}(d) := \\sum_{\\substack{1 \\le k \\le n\n \\\\ \\ell(w_{k-1}) < \\ell(w_k)}}\n \\beta_{k}^{\\vee}.\n\n It can be shown that `\\mathrm{wt}(d)` depends only on `x,y`;\n call its value `\\mathrm{wt}(x,y)`. The energy function `D(\\pi)`\n is defined by\n\n .. MATH::\n\n D(\\pi) = -\\sum_{u=1}^{s-1} (1-\\sigma_{u}) \\langle \\lambda,\n \\mathrm{wt}(x_u,x_{u+1}) \\rangle.\n\n For more information, see [LNSSS2013]_.\n\n .. NOTE::\n\n In the dual-of-untwisted case the parabolic quantum\n Bruhat graph that is used is obtained by exchanging the\n roles of roots and coroots. Moreover, in the computation\n of the pairing the short roots must be doubled (or tripled\n for type `G`). This factor is determined by the translation\n factor of the corresponding root. Type `BC` is viewed as\n untwisted type, whereas the dual of `BC` is viewed as twisted.\n Except for the untwisted cases, these formulas are\n currently still conjectural.\n\n EXAMPLES::\n\n sage: R = RootSystem([\'C\',3,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[3])\n sage: b = LS.module_generators[0]\n sage: c = b.f(1).f(3).f(2)\n sage: c.energy_function()\n 0\n sage: c=b.e(0)\n sage: c.energy_function()\n 1\n\n sage: R = RootSystem([\'A\',2,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1])\n sage: b = LS.module_generators[0]\n sage: c = b.e(0)\n sage: c.energy_function()\n 1\n sage: for c in sorted(LS, key=str):\n ....: print("{} {}".format(c,c.energy_function()))\n (-2*Lambda[0] + 2*Lambda[1],) 0\n (-2*Lambda[1] + 2*Lambda[2],) 0\n (-Lambda[0] + Lambda[1], -Lambda[1] + Lambda[2]) 1\n (-Lambda[0] + Lambda[1], Lambda[0] - Lambda[2]) 1\n (-Lambda[1] + Lambda[2], -Lambda[0] + Lambda[1]) 0\n (-Lambda[1] + Lambda[2], Lambda[0] - Lambda[2]) 1\n (2*Lambda[0] - 2*Lambda[2],) 0\n (Lambda[0] - Lambda[2], -Lambda[0] + Lambda[1]) 0\n (Lambda[0] - Lambda[2], -Lambda[1] + Lambda[2]) 0\n\n The next test checks that the energy function is constant\n on classically connected components::\n\n sage: R = RootSystem([\'A\',2,1])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]+La[2])\n sage: G = LS.digraph(index_set=[1,2])\n sage: C = G.connected_components(sort=False)\n sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C]\n [True, True, True, True]\n\n sage: R = RootSystem([\'D\',4,2])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[2])\n sage: J = R.cartan_type().classical().index_set()\n sage: hw = [x for x in LS if x.is_highest_weight(J)]\n sage: [(x.weight(), x.energy_function()) for x in hw]\n [(-2*Lambda[0] + Lambda[2], 0), (-2*Lambda[0] + Lambda[1], 1), (0, 2)]\n sage: G = LS.digraph(index_set=J)\n sage: C = G.connected_components(sort=False)\n sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C]\n [True, True, True]\n\n sage: R = RootSystem(CartanType([\'G\',2,1]).dual())\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[2])\n sage: G = LS.digraph(index_set=[1,2])\n sage: C = G.connected_components(sort=False)\n sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C] # long time\n [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n\n sage: ct = CartanType([\'BC\',2,2]).dual()\n sage: R = RootSystem(ct)\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]+La[2])\n sage: G = LS.digraph(index_set=R.cartan_type().classical().index_set())\n sage: C = G.connected_components(sort=False)\n sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C] # long time\n [True, True, True, True, True, True, True, True, True, True, True]\n\n sage: R = RootSystem([\'BC\',2,2])\n sage: La = R.weight_space().basis()\n sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]+La[2])\n sage: G = LS.digraph(index_set=R.cartan_type().classical().index_set())\n sage: C = G.connected_components(sort=False)\n sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C] # long time\n [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True,\n True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n ' weight = self.parent().weight P = weight.parent() c_weight = P.classical()(weight) ct = P.cartan_type() cartan = ct.classical() Qv = RootSystem(cartan).coroot_lattice() W = WeylGroup(cartan, prefix='s', implementation='permutation') J = tuple(weight.weyl_stabilizer()) L = self.weyl_group_representation() if (ct.is_untwisted_affine() or (ct.type() == 'BC')): untwisted = True G = W.quantum_bruhat_graph(J) else: untwisted = False cartan_dual = cartan.dual() Wd = WeylGroup(cartan_dual, prefix='s', implementation='permutation') G = Wd.quantum_bruhat_graph(J) Qd = RootSystem(cartan_dual).root_lattice() def dualize(x): return Qv.from_vector(x.to_vector()) L = [Wd.from_reduced_word(x.reduced_word()) for x in L] def stretch_short_root(a): if (ct.dual().type() == 'BC'): return (ct.c()[a.to_simple_root()] * a) return (ct.dual().c()[a.to_simple_root()] * a) paths = [G.shortest_path(L[(i + 1)], L[i]) for i in range((len(L) - 1))] paths_labels = [[G.edge_label(p[i], p[(i + 1)]) for i in range((len(p) - 1)) if ((p[i].length() + 1) != p[(i + 1)].length())] for p in paths] scalars = self.scalar_factors() if untwisted: s = sum((((1 - scalars[i]) * c_weight.scalar(Qv.sum((root.associated_coroot() for root in paths_labels[i])))) for i in range(len(paths_labels)))) if (ct.type() == 'BC'): return (2 * s) else: return s else: s = sum((((1 - scalars[i]) * c_weight.scalar(dualize(Qd.sum((stretch_short_root(root) for root in paths_labels[i]))))) for i in range(len(paths_labels)))) if (ct.dual().type() == 'BC'): return (s / 2) else: return s
class InfinityCrystalOfLSPaths(UniqueRepresentation, Parent): '\n LS path model for `\\mathcal{B}(\\infty)`.\n\n Elements of `\\mathcal{B}(\\infty)` are equivalence classes of paths `[\\pi]`\n in `\\mathcal{B}(k\\rho)` for `k\\gg 0`, where `\\rho` is the Weyl vector. A\n canonical representative for an element of `\\mathcal{B}(\\infty)` is chosen\n by taking `k` to be minimal such that the endpoint of `\\pi` is strictly\n dominant but its representative in `\\mathcal{B}((k-1)\\rho)` is on the wall\n of the dominant chamber.\n\n REFERENCES:\n\n - [LZ2011]_\n ' @staticmethod def __classcall_private__(cls, cartan_type): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B1 = crystals.infinity.LSPaths(['A',4])\n sage: B2 = crystals.infinity.LSPaths('A4')\n sage: B3 = crystals.infinity.LSPaths(CartanType(['A',4]))\n sage: B1 is B2 and B2 is B3\n True\n " cartan_type = CartanType(cartan_type) return super().__classcall__(cls, cartan_type) def __init__(self, cartan_type): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.LSPaths(['D',4,3])\n sage: TestSuite(B).run(max_runs=500)\n sage: B = crystals.infinity.LSPaths(['B',3])\n sage: TestSuite(B).run() # long time\n " Parent.__init__(self, category=(HighestWeightCrystals(), InfiniteEnumeratedSets())) self._cartan_type = cartan_type self.module_generators = (self.module_generator(),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.infinity.LSPaths(['A',4])\n The infinity crystal of LS paths of type ['A', 4]\n " return ('The infinity crystal of LS paths of type %s' % self._cartan_type) @cached_method def module_generator(self): "\n Return the module generator (or highest weight element) of ``self``.\n\n The module generator is the unique path\n `\\pi_\\infty\\colon t \\mapsto t\\rho`, for `t \\in [0,\\infty)`.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.LSPaths(['A',6,2])\n sage: mg = B.module_generator(); mg\n (Lambda[0] + Lambda[1] + Lambda[2] + Lambda[3],)\n sage: mg.weight()\n 0\n " rho = self.weight_lattice_realization().rho() return self((rho,)) def weight_lattice_realization(self): "\n Return the weight lattice realization of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.LSPaths(['C',4])\n sage: B.weight_lattice_realization()\n Weight space over the Rational Field of the Root system of type ['C', 4]\n " if self._cartan_type.is_affine(): return self._cartan_type.root_system().weight_space(extended=True) return self._cartan_type.root_system().weight_space() class Element(CrystalOfLSPaths.Element): def e(self, i, power=1, length_only=False): "\n Return the `i`-th crystal raising operator on ``self``.\n\n INPUT:\n\n - ``i`` -- element of the index set\n - ``power`` -- (default: 1) positive integer; specifies the\n power of the lowering operator to be applied\n - ``length_only`` -- (default: ``False``) boolean; if ``True``,\n then return the distance to the anti-dominant end of the\n `i`-string of ``self``\n\n EXAMPLES::\n\n sage: B = crystals.infinity.LSPaths(['B',3,1])\n sage: mg = B.module_generator()\n sage: mg.e(0)\n sage: mg.e(1)\n sage: mg.e(2)\n sage: x = mg.f_string([1,0,2,1,0,2,1,1,0])\n sage: all(x.f(i).e(i) == x for i in B.index_set())\n True\n sage: all(x.e(i).f(i) == x for i in B.index_set() if x.epsilon(i) > 0)\n True\n\n TESTS:\n\n Check that this works in affine types::\n\n sage: B = crystals.infinity.LSPaths(['A',3,1])\n sage: mg = B.highest_weight_vector()\n sage: x = mg.f_string([0,1,2,3])\n sage: x.e_string([3,2,1,0]) == mg\n True\n\n We check that :meth:`epsilon` works::\n\n sage: B = crystals.infinity.LSPaths(['D',4])\n sage: mg = B.highest_weight_vector()\n sage: x = mg.f_string([1,3,4,2,4,3,2,1,4])\n sage: [x.epsilon(i) for i in B.index_set()]\n [1, 1, 0, 1]\n\n Check that :trac:`21671` is fixed::\n\n sage: B = crystals.infinity.LSPaths(['G',2])\n sage: len(B.subcrystal(max_depth=7))\n 116\n " ret = super().e(i, power=power, length_only=length_only) if (ret is None): return None if length_only: return ret WLR = self.parent().weight_lattice_realization() value = list(ret.value) endpoint = sum(value) rho = WLR.rho() h = WLR.simple_coroots() if (not positively_parallel_weights(value[(- 1)], rho)): value.append(rho) endpoint += rho while any(((endpoint.scalar(alc) < 1) for alc in h)): value[(- 1)] += rho endpoint += rho while (all(((endpoint.scalar(alc) > 1) for alc in h)) and (value[(- 1)] != WLR.zero())): value[(- 1)] -= rho endpoint -= rho while (value[(- 1)] == WLR.zero()): value.pop() ret.value = tuple(value) return ret def f(self, i, power=1, length_only=False): "\n Return the `i`-th crystal lowering operator on ``self``.\n\n INPUT:\n\n - ``i`` -- element of the index set\n - ``power`` -- (default: 1) positive integer; specifies the\n power of the lowering operator to be applied\n - ``length_only`` -- (default: ``False``) boolean; if ``True``,\n then return the distance to the anti-dominant end of the\n `i`-string of ``self``\n\n EXAMPLES::\n\n sage: B = crystals.infinity.LSPaths(['D',3,2])\n sage: mg = B.highest_weight_vector()\n sage: mg.f(1)\n (3*Lambda[0] - Lambda[1] + 3*Lambda[2],\n 2*Lambda[0] + 2*Lambda[1] + 2*Lambda[2])\n sage: mg.f(2)\n (Lambda[0] + 2*Lambda[1] - Lambda[2],\n 2*Lambda[0] + 2*Lambda[1] + 2*Lambda[2])\n sage: mg.f(0)\n (-Lambda[0] + 2*Lambda[1] + Lambda[2] - delta,\n 2*Lambda[0] + 2*Lambda[1] + 2*Lambda[2])\n " dual_path = self.dualize() dual_path = super(InfinityCrystalOfLSPaths.Element, dual_path).e(i, power, length_only=length_only) if length_only: return dual_path if (dual_path is None): return None ret = dual_path.dualize() WLR = self.parent().weight_lattice_realization() value = list(ret.value) endpoint = sum(value) rho = WLR.rho() h = WLR.simple_coroots() if (not positively_parallel_weights(value[(- 1)], rho)): value.append(rho) endpoint += rho while any(((endpoint.scalar(alc) < 1) for alc in h)): value[(- 1)] += rho endpoint += rho while (all(((endpoint.scalar(alc) > 1) for alc in h)) and (value[(- 1)] != WLR.zero())): value[(- 1)] -= rho endpoint -= rho while (value[(- 1)] == WLR.zero()): value.pop() ret.value = tuple(value) return ret @cached_method def weight(self): "\n Return the weight of ``self``.\n\n .. TODO::\n\n This is a generic algorithm. We should find a better\n description and implement it.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.LSPaths(['E',6])\n sage: mg = B.highest_weight_vector()\n sage: f_seq = [1,4,2,6,4,2,3,1,5,5]\n sage: x = mg.f_string(f_seq)\n sage: x.weight()\n -3*Lambda[1] - 2*Lambda[2] + 2*Lambda[3] + Lambda[4] - Lambda[5]\n\n sage: al = B.cartan_type().root_system().weight_space().simple_roots()\n sage: x.weight() == -sum(al[i] for i in f_seq)\n True\n " WLR = self.parent().weight_lattice_realization() alpha = WLR.simple_roots() return (- WLR.sum((alpha[i] for i in self.to_highest_weight()[1]))) def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n Let `\\pi \\in \\mathcal{B}(\\infty)`. Define\n\n .. MATH::\n\n \\varphi_i(\\pi) := \\varepsilon_i(\\pi) + \\langle h_i,\n \\mathrm{wt}(\\pi) \\rangle,\n\n where `h_i` is the `i`-th simple coroot and `\\mathrm{wt}(\\pi)`\n is the :meth:`weight` of `\\pi`.\n\n INPUT:\n\n - ``i`` -- element of the index set\n\n EXAMPLES::\n\n sage: B = crystals.infinity.LSPaths(['D',4])\n sage: mg = B.highest_weight_vector()\n sage: x = mg.f_string([1,3,4,2,4,3,2,1,4])\n sage: [x.phi(i) for i in B.index_set()]\n [-1, 4, -2, -3]\n " WLR = self.parent().weight_lattice_realization() h = WLR.simple_coroots() return (self.epsilon(i) + WLR(self.weight()).scalar(h[i]))
def positively_parallel_weights(v, w): "\n Check whether the vectors ``v`` and ``w`` are positive scalar\n multiples of each other.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.littelmann_path import positively_parallel_weights\n sage: La = RootSystem(['A',5,2]).weight_space(extended=True).fundamental_weights()\n sage: rho = sum(La)\n sage: positively_parallel_weights(rho, 4*rho)\n True\n sage: positively_parallel_weights(4*rho, rho)\n True\n sage: positively_parallel_weights(rho, -rho)\n False\n sage: positively_parallel_weights(rho, La[1] + La[2])\n False\n " supp = v.support() if (len(supp) > 0): i = supp[0] if (((v[i] * w[i]) > 0) and ((v[i] * w) == (w[i] * v))): return True return False
class NakajimaMonomial(Element): '\n An element of the monomial crystal.\n\n Monomials of the form `Y_{i_1,k_1}^{y_1} \\cdots Y_{i_t,k_t}^{y_t}`,\n where `i_1, \\dots, i_t` are elements of the index set, `k_1, \\dots, k_t`\n are nonnegative integers, and `y_1, \\dots, y_t` are integers.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials([\'B\',3,1])\n sage: mg = M.module_generators[0]\n sage: mg\n 1\n sage: mg.f_string([1,3,2,0,1,2,3,0,0,1])\n Y(0,0)^-1 Y(0,1)^-1 Y(0,2)^-1 Y(0,3)^-1 Y(1,0)^-3\n Y(1,1)^-2 Y(1,2) Y(2,0)^3 Y(2,2) Y(3,0) Y(3,2)^-1\n\n An example using the `A` variables::\n\n sage: M = crystals.infinity.NakajimaMonomials("A3")\n sage: M.set_variables(\'A\')\n sage: mg = M.module_generators[0]\n sage: mg.f_string([1,2,3,2,1])\n A(1,0)^-1 A(1,1)^-1 A(2,0)^-2 A(3,0)^-1\n sage: mg.f_string([3,2,1])\n A(1,2)^-1 A(2,1)^-1 A(3,0)^-1\n sage: M.set_variables(\'Y\')\n ' def __init__(self, parent, Y, A): '\n INPUT:\n\n - ``d`` -- a dictionary of with pairs of the form ``{(i,k): y}``\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials("C5")\n sage: mg = M.module_generators[0]\n sage: TestSuite(mg).run()\n ' self._Y = Y self._A = A Element.__init__(self, parent) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['A',5,2])\n sage: x = M({(1,0):1, (2,2):-2, (0,5):10}); x\n Y(0,5)^10 Y(1,0) Y(2,2)^-2\n sage: M.set_variables('A')\n sage: x\n A(1,0)^-2 A(1,1)^-2 A(2,0)^-4 A(2,1)^-2 A(3,0)^-2\n sage: M.set_variables('Y')\n " return getattr(self, ('_repr_' + self.parent()._variable))() def _repr_Y(self): "\n Return a string representation of ``self`` in the `Y` variables.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['A',5,2])\n sage: M({(1,0):1,(2,2):-2,(0,5):10})\n Y(0,5)^10 Y(1,0) Y(2,2)^-2\n " if (not self._Y): return '1' L = sorted(self._Y.items(), key=(lambda x: (x[0][0], x[0][1]))) exp = (lambda e: ('^{}'.format(e) if (e != 1) else '')) return ' '.join((('Y({},{})'.format(mon[0][0], mon[0][1]) + exp(mon[1])) for mon in L)) def _repr_A(self): "\n Return a string representation of ``self`` in the `A` variables.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['B',4,1])\n sage: m = M.module_generators[0].f_string([4,2,1])\n sage: m._repr_A()\n 'A(1,1)^-1 A(2,0)^-1 A(4,0)^-1'\n " try: Y = {(i, 0): c for (i, c) in self.parent().hw} except Exception: Y = {} if ((not Y) and (not self._A)): return '1' L = sorted(Y.items(), key=(lambda x: (x[0][0], x[0][1]))) exp = (lambda e: ('^{}'.format(e) if (e != 1) else '')) ret = ' '.join((('Y({},{})'.format(mon[0][0], mon[0][1]) + exp(mon[1])) for mon in L)) if (not self._A): return ret if Y: ret += ' ' L = sorted(self._A.items(), key=(lambda x: (x[0][0], x[0][1]))) return (ret + ' '.join((('A({},{})'.format(mon[0][0], mon[0][1]) + exp(mon[1])) for mon in L))) def __hash__(self): "\n TESTS::\n\n sage: M = crystals.infinity.NakajimaMonomials(['C',5])\n sage: m1 = M.module_generators[0].f(1)\n sage: m2 = M.module_generators[0].f(2)\n sage: hash(m1) != hash(m2)\n True\n " return hash(frozenset(tuple(self._Y.items()))) def __eq__(self, other): "\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['C',5])\n sage: m1 = M.module_generators[0].f(1)\n sage: m2 = M.module_generators[0].f(2)\n sage: m1.__eq__(m2)\n False\n sage: m1.__eq__(m1)\n True\n " if isinstance(other, NakajimaMonomial): return (self._Y == other._Y) return (self._Y == other) def __ne__(self, other): "\n EXAMPLES::\n\n sage: La = RootSystem(['A',2]).weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['A',2],La[1]+La[2])\n sage: m0 = M.module_generators[0]\n sage: m = M.module_generators[0].f(1).f(2).f(2).f(1)\n sage: m.__ne__(m0)\n True\n sage: m.__ne__(m)\n False\n " return (not (self == other)) def __lt__(self, other): "\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['F',4])\n sage: mg = M.module_generators[0]\n sage: m = mg.f(4)\n sage: m.__lt__(mg)\n False\n sage: mg.__lt__(m)\n False\n " return False def _latex_(self): "\n Return a `\\LaTeX` representation of ``self``.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['G',2,1])\n sage: x = M.module_generators[0].f_string([1,0,2])\n sage: latex(x)\n Y_{0,0}^{-1} Y_{1,0}^{-1} Y_{1,1}^{2} Y_{2,0} Y_{2,1}^{-1}\n sage: M.set_variables('A')\n sage: latex(x)\n A_{0,0}^{-1} A_{1,0}^{-1} A_{2,0}^{-1}\n sage: M.set_variables('Y')\n " return getattr(self, ('_latex_' + self.parent()._variable))() def _latex_Y(self): "\n Return a `\\LaTeX` representation of ``self`` in the `Y` variables.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['G',2,1])\n sage: M.module_generators[0].f_string([1,0,2])._latex_Y()\n 'Y_{0,0}^{-1} Y_{1,0}^{-1} Y_{1,1}^{2} Y_{2,0} Y_{2,1}^{-1} '\n " if (not self._Y): return '\\boldsymbol{1}' L = sorted(self._Y.items(), key=(lambda x: (x[0][0], x[0][1]))) return_str = '' for x in L: if (x[1] != 1): return_str += (('Y_{%s,%s}' % (x[0][0], x[0][1])) + ('^{%s} ' % x[1])) else: return_str += ('Y_{%s,%s} ' % (x[0][0], x[0][1])) return return_str def _latex_A(self): "\n Return a `\\LaTeX` representation of ``self`` in the `A` variables.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['C',4,1])\n sage: m = M.module_generators[0].f_string([4,2,3])\n sage: m._latex_A()\n 'A_{2,0}^{-1} A_{3,1}^{-1} A_{4,0}^{-1} '\n " try: Y = {(i, 0): c for (i, c) in self.parent().hw} except Exception: Y = {} if ((not Y) and (not self._A)): return '\\boldsymbol{1}' L = sorted(Y.items(), key=(lambda x: (x[0][0], x[0][1]))) return_str = '' for x in L: if (x[1] != 1): return_str += (('Y_{%s,%s}' % (x[0][0], x[0][1])) + ('^{%s} ' % x[1])) else: return_str += ('Y_{%s,%s} ' % (x[0][0], x[0][1])) L = sorted(self._A.items(), key=(lambda x: (x[0][0], x[0][1]))) for x in L: if (x[1] != 1): return_str += (('A_{%s,%s}' % (x[0][0], x[0][1])) + ('^{%s} ' % x[1])) else: return_str += ('A_{%s,%s} ' % (x[0][0], x[0][1])) return return_str def _classical_weight(self): "\n Return the weight of ``self`` as an element of the classical version of\n ``self.parent().weight_lattice_realization``.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['D',4,2])\n sage: m = M.module_generators[0].f_string([0,3,2,0,1])\n sage: m._classical_weight()\n -2*Lambda[0] + Lambda[1]\n\n sage: M = crystals.infinity.NakajimaMonomials(['E',6])\n sage: m = M.module_generators[0].f_string([1,5,2,6,3])\n sage: m._classical_weight()\n (-1/2, -3/2, 3/2, 1/2, -1/2, 1/2, 1/2, -1/2)\n " P = self.parent().weight_lattice_realization() La = P.fundamental_weights() return P(sum(((v * La[k[0]]) for (k, v) in self._Y.items()))) def weight_in_root_lattice(self): "\n Return the weight of ``self`` as an element of the root lattice.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['F',4])\n sage: m = M.module_generators[0].f_string([3,3,1,2,4])\n sage: m.weight_in_root_lattice()\n -alpha[1] - alpha[2] - 2*alpha[3] - alpha[4]\n\n sage: M = crystals.infinity.NakajimaMonomials(['B',3,1])\n sage: mg = M.module_generators[0]\n sage: m = mg.f_string([1,3,2,0,1,2,3,0,0,1])\n sage: m.weight_in_root_lattice()\n -3*alpha[0] - 3*alpha[1] - 2*alpha[2] - 2*alpha[3]\n\n sage: M = crystals.infinity.NakajimaMonomials(['C',3,1])\n sage: m = M.module_generators[0].f_string([3,0,1,2,0])\n sage: m.weight_in_root_lattice()\n -2*alpha[0] - alpha[1] - alpha[2] - alpha[3]\n " Q = RootSystem(self.parent().cartan_type()).root_lattice() al = Q.simple_roots() return Q.sum(((e * al[k[0]]) for (k, e) in self._A.items())) def weight(self): "\n Return the weight of ``self`` as an element of the weight lattice.\n\n EXAMPLES::\n\n sage: C = crystals.infinity.NakajimaMonomials(['A',1,1])\n sage: v = C.highest_weight_vector()\n sage: v.f(1).weight() + v.f(0).weight()\n -delta\n\n sage: M = crystals.infinity.NakajimaMonomials(['A',4,2])\n sage: m = M.highest_weight_vector().f_string([1,2,0,1])\n sage: m.weight()\n 2*Lambda[0] - Lambda[1] - delta\n " P = self.parent().weight_lattice_realization() return P(self.weight_in_root_lattice()) def epsilon(self, i): "\n Return the value of `\\varepsilon_i` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['G',2,1])\n sage: m = M.module_generators[0].f(2)\n sage: [m.epsilon(i) for i in M.index_set()]\n [0, 0, 1]\n\n sage: M = crystals.infinity.NakajimaMonomials(['C',4,1])\n sage: m = M.module_generators[0].f_string([4,2,3])\n sage: [m.epsilon(i) for i in M.index_set()]\n [0, 0, 0, 1, 0]\n " if (i not in self.parent().index_set()): raise ValueError('i must be an element of the index set') h = self.parent().weight_lattice_realization().simple_coroots() return (self.phi(i) - self._classical_weight().scalar(h[i])) def phi(self, i): "\n Return the value of `\\varphi_i` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['D',4,3])\n sage: m = M.module_generators[0].f(1)\n sage: [m.phi(i) for i in M.index_set()]\n [1, -1, 1]\n\n sage: M = crystals.infinity.NakajimaMonomials(['C',4,1])\n sage: m = M.module_generators[0].f_string([4,2,3])\n sage: [m.phi(i) for i in M.index_set()]\n [0, 1, -1, 2, -1]\n " if (i not in self.parent().index_set()): raise ValueError('i must be an element of the index set') if ((not self._Y) or all(((x[0] != i) for x in self._Y))): return ZZ.zero() d = copy(self._Y) K = max((x[1] for x in d if (x[0] == i))) for a in range(K): if ((i, a) in d): continue else: d[(i, a)] = 0 S = sorted((x for x in d.items() if (x[0][0] == i)), key=(lambda x: x[0][1])) return max((sum((S[k][1] for k in range(s))) for s in range(1, (len(S) + 1)))) def _ke(self, i): "\n Return the value `k_e` with respect to ``i`` and ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['D',4,3])\n sage: m = M.module_generators[0].f(1)\n sage: [m._ke(i) for i in M.index_set()]\n [+Infinity, 0, +Infinity]\n " h = self.parent().weight_lattice_realization().simple_coroots() phi = self.phi(i) if (phi == self._classical_weight().scalar(h[i])): return Infinity d = copy(self._Y) K = max((x[1] for x in d if (x[0] == i))) for a in range(K): if ((i, a) in d): continue else: d[(i, a)] = 0 total = ZZ.zero() L = [] S = sorted((x for x in d.items() if (x[0][0] == i)), key=(lambda x: x[0][1])) for (var, exp) in S: total += exp if (total == phi): L.append(var[1]) return (max(L) if L else ZZ.zero()) def _kf(self, i): "\n Return the value `k_f` with respect to ``i`` and ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['F',4,1])\n sage: m = M.module_generators[0].f_string([0,1,4,3])\n sage: [m._kf(i) for i in M.index_set()]\n [0, 0, 2, 0, 0]\n " if all(((i != x[0]) for x in self._Y)): return ZZ.zero() d = copy(self._Y) K = max((key[1] for key in d if (key[0] == i))) for a in range(K): if ((i, a) in d): continue else: d[(i, a)] = 0 S = sorted((x for x in d.items() if (x[0][0] == i)), key=(lambda x: x[0][1])) sum = 0 phi = self.phi(i) for (var, exp) in S: sum += exp if (sum == phi): return var[1] def e(self, i): '\n Return the action of `e_i` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials([\'E\',7,1])\n sage: m = M.module_generators[0].f_string([0,1,4,3])\n sage: [m.e(i) for i in M.index_set()]\n [None,\n None,\n None,\n Y(0,0)^-1 Y(1,1)^-1 Y(2,1) Y(3,0) Y(3,1) Y(4,0)^-1 Y(4,1)^-1 Y(5,0),\n None,\n None,\n None,\n None]\n\n sage: M = crystals.infinity.NakajimaMonomials("C5")\n sage: m = M.module_generators[0].f_string([1,3])\n sage: [m.e(i) for i in M.index_set()]\n [Y(2,1) Y(3,0)^-1 Y(3,1)^-1 Y(4,0),\n None,\n Y(1,0)^-1 Y(1,1)^-1 Y(2,0),\n None,\n None]\n\n sage: M = crystals.infinity.NakajimaMonomials([\'D\',4,1])\n sage: M.set_variables(\'A\')\n sage: m = M.module_generators[0].f_string([4,2,3,0])\n sage: [m.e(i) for i in M.index_set()]\n [A(2,1)^-1 A(3,1)^-1 A(4,0)^-1,\n None,\n None,\n A(0,2)^-1 A(2,1)^-1 A(4,0)^-1,\n None]\n sage: M.set_variables(\'Y\')\n ' if (i not in self.parent().index_set()): raise ValueError('i must be an element of the index set') if (self.epsilon(i) == 0): return None newdict = copy(self._Y) ke = self._ke(i) Aik = {(i, ke): 1, (i, (ke + 1)): 1} ct = self.parent().cartan_type() cm = ct.cartan_matrix() shift = 0 if self.parent().cartan_type().is_finite(): shift = 1 for (j_index, j) in enumerate(self.parent().index_set()): if (i == j): continue c = self.parent()._c[(j_index, (i - shift))] if (cm[(j_index, (i - shift))] != 0): Aik[(j, (ke + c))] = cm[(j_index, (i - shift))] for (key, value) in Aik.items(): if (key in newdict): if (newdict[key] == (- value)): del newdict[key] else: newdict[key] += value else: newdict[key] = value A = copy(self._A) A[(i, ke)] = (A.get((i, ke), 0) + 1) if (not A[(i, ke)]): del A[(i, ke)] return self.__class__(self.parent(), newdict, A) def f(self, i): '\n Return the action of `f_i` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials("B4")\n sage: m = M.module_generators[0].f_string([1,3,4])\n sage: [m.f(i) for i in M.index_set()]\n [Y(1,0)^-2 Y(1,1)^-2 Y(2,0)^2 Y(2,1) Y(3,0)^-1 Y(4,0) Y(4,1)^-1,\n Y(1,0)^-1 Y(1,1)^-1 Y(1,2) Y(2,0) Y(2,2)^-1 Y(3,0)^-1 Y(3,1) Y(4,0) Y(4,1)^-1,\n Y(1,0)^-1 Y(1,1)^-1 Y(2,0) Y(2,1)^2 Y(3,0)^-2 Y(3,1)^-1 Y(4,0)^3 Y(4,1)^-1,\n Y(1,0)^-1 Y(1,1)^-1 Y(2,0) Y(2,1) Y(3,0)^-1 Y(3,1) Y(4,1)^-2]\n ' if (i not in self.parent().index_set()): raise ValueError('i must be an element of the index set') newdict = copy(self._Y) kf = self._kf(i) Aik = {(i, kf): (- 1), (i, (kf + 1)): (- 1)} ct = self.parent().cartan_type() cm = ct.cartan_matrix() shift = 0 if ct.is_finite(): shift = 1 for (j_index, j) in enumerate(self.parent().index_set()): if (i == j): continue c = self.parent()._c[(j_index, (i - shift))] if (cm[(j_index, (i - shift))] != 0): Aik[(j, (kf + c))] = (- cm[(j_index, (i - shift))]) for (key, value) in Aik.items(): if (key in newdict): if (newdict[key] == (- value)): del newdict[key] else: newdict[key] += value else: newdict[key] = value A = copy(self._A) A[(i, kf)] = (A.get((i, kf), 0) - 1) if (not A[(i, kf)]): del A[(i, kf)] return self.__class__(self.parent(), newdict, A)
class InfinityCrystalOfNakajimaMonomials(UniqueRepresentation, Parent): '\n Crystal `B(\\infty)` in terms of (modified) Nakajima monomials.\n\n Let `Y_{i,k}`, for `i \\in I` and `k \\in \\ZZ`, be a commuting set of\n variables, and let `\\boldsymbol{1}` be a new variable which commutes\n with each `Y_{i,k}`. (Here, `I` represents the index set of a Cartan\n datum.) One may endow the structure of a crystal on the\n set `\\widehat{\\mathcal{M}}` of monomials of the form\n\n .. MATH::\n\n M = \\prod_{(i,k) \\in I\\times \\ZZ_{\\ge0}} Y_{i,k}^{y_i(k)}\\boldsymbol{1}.\n\n Elements of `\\widehat{\\mathcal{M}}` are called\n *modified Nakajima monomials*. We will omit the `\\boldsymbol{1}`\n from the end of a monomial if there exists at least one `y_i(k) \\neq 0`.\n The crystal structure on this set is defined by\n\n .. MATH::\n\n \\begin{aligned}\n \\mathrm{wt}(M) & = \\sum_{i\\in I} \\Bigl( \\sum_{k \\ge 0}\n y_i(k) \\Bigr) \\Lambda_i, \\\\\n \\varphi_i(M) & = \\max\\Bigl\\{ \\sum_{0 \\le j \\le k} y_i(j) :\n k \\ge 0 \\Bigr\\}, \\\\\n \\varepsilon_i(M) & = \\varphi_i(M) -\n \\langle h_i, \\mathrm{wt}(M) \\rangle, \\\\\n k_f = k_f(M) & = \\min\\Bigl\\{ k \\ge 0 :\n \\varphi_i(M) = \\sum_{0 \\le j \\le k} y_i(j) \\Bigr\\}, \\\\\n k_e = k_e(M) & = \\max\\Bigl\\{ k \\ge 0 :\n \\varphi_i(M) = \\sum_{0 \\le j \\le k} y_i(j) \\Bigr\\},\n \\end{aligned}\n\n where `\\{h_i : i \\in I\\}` and `\\{\\Lambda_i : i \\in I \\}` are the simple\n coroots and fundamental weights, respectively. With a chosen set of\n non-negative integers `C = (c_{ij})_{i\\neq j}` such that\n `c_{ij} + c_{ji} = 1`, one defines\n\n .. MATH::\n\n A_{i,k} = Y_{i,k} Y_{i,k+1} \\prod_{j\\neq i} Y_{j,k+c_{ji}}^{a_{ji}},\n\n where `(a_{ij})_{i,j \\in I}` is a Cartan matrix. Then\n\n .. MATH::\n\n \\begin{aligned}\n e_iM &= \\begin{cases} 0 & \\text{if } \\varepsilon_i(M) = 0, \\\\\n A_{i,k_e}M & \\text{if } \\varepsilon_i(M) > 0, \\end{cases} \\\\\n f_iM &= A_{i,k_f}^{-1} M.\n \\end{aligned}\n\n It is shown in [KKS2007]_ that the connected component of\n `\\widehat{\\mathcal{M}}` containing the element `\\boldsymbol{1}`,\n which we denote by `\\mathcal{M}(\\infty)`, is crystal isomorphic\n to the crystal `B(\\infty)`.\n\n INPUT:\n\n - ``cartan_type`` -- a Cartan type\n\n - ``c`` -- (optional) the matrix `(c_{ij})_{i,j \\in I}` such that\n `c_{ii} = 0` for all `i \\in I`, `c_{ij} \\in \\ZZ_{>0}` for all\n `i,j \\in I`, and `c_{ij} + c_{ji} = 1` for all `i \\neq j`; the\n default is `c_{ij} = 0` if `i < j` and `0` otherwise\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux("C3")\n sage: S = B.subcrystal(max_depth=4)\n sage: G = B.digraph(subset=S) # long time\n sage: M = crystals.infinity.NakajimaMonomials("C3") # long time\n sage: T = M.subcrystal(max_depth=4) # long time\n sage: H = M.digraph(subset=T) # long time\n sage: G.is_isomorphic(H,edge_labels=True) # long time\n True\n\n sage: M = crystals.infinity.NakajimaMonomials([\'A\',2,1])\n sage: T = M.subcrystal(max_depth=3)\n sage: H = M.digraph(subset=T) # long time\n sage: Y = crystals.infinity.GeneralizedYoungWalls(2)\n sage: YS = Y.subcrystal(max_depth=3)\n sage: YG = Y.digraph(subset=YS) # long time\n sage: YG.is_isomorphic(H,edge_labels=True) # long time\n True\n\n sage: M = crystals.infinity.NakajimaMonomials("D4")\n sage: B = crystals.infinity.Tableaux("D4")\n sage: MS = M.subcrystal(max_depth=3)\n sage: BS = B.subcrystal(max_depth=3)\n sage: MG = M.digraph(subset=MS) # long time\n sage: BG = B.digraph(subset=BS) # long time\n sage: BG.is_isomorphic(MG,edge_labels=True) # long time\n True\n ' @staticmethod def _normalize_c(c, n): "\n Normalize the input ``c``.\n\n EXAMPLES::\n\n sage: from sage.combinat.crystals.monomial_crystals import InfinityCrystalOfNakajimaMonomials\n sage: InfinityCrystalOfNakajimaMonomials._normalize_c(None, 4)\n [0 1 1 1]\n [0 0 1 1]\n [0 0 0 1]\n [0 0 0 0]\n sage: c = matrix([[0,1,1],[0,0,0],[0,1,0]]); c\n [0 1 1]\n [0 0 0]\n [0 1 0]\n sage: c.is_mutable()\n True\n sage: C = InfinityCrystalOfNakajimaMonomials._normalize_c(c, 3); C\n [0 1 1]\n [0 0 0]\n [0 1 0]\n sage: C.is_mutable()\n False\n\n TESTS::\n\n sage: c = matrix([[0,1],[0,1]])\n sage: C = InfinityCrystalOfNakajimaMonomials._normalize_c(c, 2)\n Traceback (most recent call last):\n ...\n ValueError: the c matrix must have 0's on the diagonal\n sage: c = matrix([[0,2],[-1,0]])\n sage: C = InfinityCrystalOfNakajimaMonomials._normalize_c(c, 2)\n Traceback (most recent call last):\n ...\n ValueError: the c matrix must have non-negative entries\n sage: c = matrix([[0,1],[1,0]])\n sage: C = InfinityCrystalOfNakajimaMonomials._normalize_c(c, 2)\n Traceback (most recent call last):\n ...\n ValueError: transpose entries do not sum to 1\n " if (c is None): c = [[(1 if (i < j) else 0) for j in range(n)] for i in range(n)] MS = MatrixSpace(ZZ, n, n) c = MS(c) c.set_immutable() if any(((c[(i, i)] != 0) for i in range(n))): raise ValueError("the c matrix must have 0's on the diagonal") if any((((c[(i, j)] + c[(j, i)]) != 1) for i in range(n) for j in range(i))): raise ValueError('transpose entries do not sum to 1') if any((((c[(i, j)] < 0) or (c[(j, i)] < 0)) for i in range(n) for j in range(i))): raise ValueError('the c matrix must have non-negative entries') return c @staticmethod def __classcall_private__(cls, ct, c=None): '\n Normalize input to ensure a unique representation.\n\n INPUT:\n\n - ``ct`` -- a Cartan type\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials("E8")\n sage: M1 = crystals.infinity.NakajimaMonomials([\'E\',8])\n sage: M2 = crystals.infinity.NakajimaMonomials(CartanType([\'E\',8]))\n sage: M is M1 is M2\n True\n ' cartan_type = CartanType(ct) n = len(cartan_type.index_set()) c = InfinityCrystalOfNakajimaMonomials._normalize_c(c, n) M = super().__classcall__(cls, cartan_type, c) M.set_variables('Y') return M def __init__(self, ct, c, category=None): "\n EXAMPLES::\n\n sage: Minf = crystals.infinity.NakajimaMonomials(['A',3])\n sage: TestSuite(Minf).run() # long time\n " self._cartan_type = ct self._c = c self._variable = 'Y' if (category is None): category = (HighestWeightCrystals(), InfiniteEnumeratedSets()) Parent.__init__(self, category=category) self.module_generators = (self.element_class(self, {}, {}),) def _element_constructor_(self, Y=None, A=None): "\n Construct an element of ``self`` from ``Y``.\n\n INPUT:\n\n - ``Y`` -- a dictionary whose key is a pair and whose value\n is an integer\n - ``A`` -- a dictionary whose key is a pair and whose value\n is an integer\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['D',4,1])\n sage: m = M({(1,0):-1,(1,1):-1,(2,0):1})\n sage: m\n Y(1,0)^-1 Y(1,1)^-1 Y(2,0)\n\n sage: M = crystals.infinity.NakajimaMonomials(['A',2,1])\n sage: m = M(A={(0,1): -1, (1,1): -2, (2,0): -1, (2,1): -1})\n sage: m._repr_A()\n 'A(0,1)^-1 A(1,1)^-2 A(2,0)^-1 A(2,1)^-1'\n sage: m\n Y(0,2)^2 Y(1,2)^-1 Y(2,0)^-1 Y(2,1) Y(2,2)^-1\n sage: m == M.highest_weight_vector().f_string([2,0,1,2,1])\n True\n " if (A is None): if (Y is None): return self.module_generators[0] (hw, path) = self.element_class(self, Y, {}).to_highest_weight() hw._A = {} return hw.f_string(reversed(path)) elif ((Y is None) or (Y == 0)): ct = self.cartan_type() cm = ct.cartan_matrix() I = self.index_set() shift = 0 if ct.is_finite(): shift = 1 Y = {} for (k, v) in A.items(): Y[k] = (Y.get(k, 0) + v) Y[(k[0], (k[1] + 1))] = (Y.get((k[0], (k[1] + 1)), 0) + v) for (j_index, j) in enumerate(I): if (k[0] == j): continue c = self._c[(j_index, (k[0] - shift))] if (cm[(j_index, (k[0] - shift))] != 0): Y[(j, (k[1] + c))] = (Y.get((j, (k[1] + c)), 0) + (v * cm[(j_index, (k[0] - shift))])) for k in list(Y): if (Y[k] == 0): del Y[k] return self.element_class(self, Y, A) def _repr_(self): "\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['D',4,1])\n sage: m = M({(1,0):-1,(1,1):-1,(2,0):1})\n sage: m\n Y(1,0)^-1 Y(1,1)^-1 Y(2,0)\n " return 'Infinity Crystal of modified Nakajima monomials of type {}'.format(self._cartan_type) def c(self): "\n Return the matrix `c_{ij}` of ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['B',3]).weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials(La[1]+La[2])\n sage: M.c()\n [0 1 1]\n [0 0 1]\n [0 0 0]\n\n sage: c = Matrix([[0,0,1],[1,0,0],[0,1,0]])\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials(2*La[1], c=c)\n sage: M.c() == c\n True\n " return self._c def cardinality(self): "\n Return the cardinality of ``self``, which is always `\\infty`.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['A',5,2])\n sage: M.cardinality()\n +Infinity\n " return Infinity def set_variables(self, letter): "\n Set the type of monomials to use for the element output.\n\n If the `A` variables are used, the output is written as\n `\\prod_{i\\in I} Y_{i,0}^{\\lambda_i} \\prod_{i,k} A_{i,k}^{c_{i,k}}`, where\n `\\sum_{i \\in I} \\lambda_i \\Lambda_i` is the corresponding\n dominant weight.\n\n INPUT:\n\n - ``letter`` -- can be one of the following:\n\n * ``'Y'`` - use `Y_{i,k}`, corresponds to fundamental weights\n * ``'A'`` - use `A_{i,k}`, corresponds to simple roots\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['A', 4])\n sage: elt = M.highest_weight_vector().f_string([2,1,3,2,3,2,4,3])\n sage: elt\n Y(1,2) Y(2,0)^-1 Y(2,2)^-1 Y(3,0)^-1 Y(3,2)^-1 Y(4,0)\n sage: M.set_variables('A')\n sage: elt\n A(1,1)^-1 A(2,0)^-1 A(2,1)^-2 A(3,0)^-2 A(3,1)^-1 A(4,0)^-1\n sage: M.set_variables('Y')\n\n ::\n\n sage: La = RootSystem(['A',2]).weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials(La[1]+La[2])\n sage: lw = M.lowest_weight_vectors()[0]\n sage: lw\n Y(1,2)^-1 Y(2,1)^-1\n sage: M.set_variables('A')\n sage: lw\n Y(1,0) Y(2,0) A(1,0)^-1 A(1,1)^-1 A(2,0)^-2\n sage: M.set_variables('Y')\n " if (letter not in ['Y', 'A']): raise ValueError('invalid monomial type') self._variable = letter def get_variables(self): "\n Return the type of monomials to use for the element output.\n\n EXAMPLES::\n\n sage: M = crystals.infinity.NakajimaMonomials(['A', 4])\n sage: M.get_variables()\n 'Y'\n " return self._variable Element = NakajimaMonomial
class CrystalOfNakajimaMonomialsElement(NakajimaMonomial): "\n Element class for\n :class:`~sage.combinat.crystals.monomial_crystals.CrystalOfNakajimaMonomials`.\n\n The `f_i` operators need to be modified from the version in\n :class:`~sage.combinat.crystals.monomial_crystalsNakajimaMonomial`\n in order to create irreducible highest weight realizations.\n This modified `f_i` is defined as\n\n .. MATH::\n\n f_iM = \\begin{cases} 0 & \\text{if } \\varphi_i(M) = 0, \\\\\n A_{i,k_f}^{-1}M & \\text{if } \\varphi_i(M) > 0. \\end{cases}\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',5,2]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['A',5,2],3*La[0])\n sage: m = M.module_generators[0].f(0); m\n Y(0,0)^2 Y(0,1)^-1 Y(2,0)\n sage: TestSuite(m).run()\n " def f(self, i): '\n Return the action of `f_i` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: La = RootSystem([\'A\',5,2]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials([\'A\',5,2],3*La[0])\n sage: m = M.module_generators[0]\n sage: [m.f(i) for i in M.index_set()]\n [Y(0,0)^2 Y(0,1)^-1 Y(2,0), None, None, None]\n\n ::\n\n sage: M = crystals.infinity.NakajimaMonomials("E8")\n sage: M.set_variables(\'A\')\n sage: m = M.module_generators[0].f_string([4,2,3,8])\n sage: m\n A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(8,0)^-1\n sage: [m.f(i) for i in M.index_set()]\n [A(1,2)^-1 A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(8,0)^-1,\n A(2,0)^-1 A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(8,0)^-1,\n A(2,1)^-1 A(3,0)^-1 A(3,1)^-1 A(4,0)^-1 A(8,0)^-1,\n A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(4,1)^-1 A(8,0)^-1,\n A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(5,0)^-1 A(8,0)^-1,\n A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(6,0)^-1 A(8,0)^-1,\n A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(7,1)^-1 A(8,0)^-1,\n A(2,1)^-1 A(3,1)^-1 A(4,0)^-1 A(8,0)^-2]\n sage: M.set_variables(\'Y\')\n ' if (self.phi(i) == 0): return None return super().f(i) def weight(self): '\n Return the weight of ``self`` as an element of the weight lattice.\n\n EXAMPLES::\n\n sage: La = RootSystem("A2").weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials("A2",La[1]+La[2])\n sage: M.module_generators[0].weight()\n (2, 1, 0)\n ' P = self.parent().weight_lattice_realization() return (P(self.weight_in_root_lattice()) + P(self.parent().hw))
class CrystalOfNakajimaMonomials(InfinityCrystalOfNakajimaMonomials): '\n Let `\\widetilde{\\mathcal{M}}` be `\\widehat{\\mathcal{M}}` as a set, and with\n crystal structure defined as on `\\widehat{\\mathcal{M}}` with the exception\n that\n\n .. MATH::\n\n f_iM = \\begin{cases} 0 & \\text{if } \\varphi_i(M) = 0, \\\\\n A_{i,k_f}^{-1}M & \\text{if } \\varphi_i(M) > 0. \\end{cases}\n\n Then Kashiwara [Ka2003]_ showed that the connected component in\n `\\widetilde{\\mathcal{M}}` containing a monomial `M` such that `e_iM = 0`,\n for all `i \\in I`, is crystal isomorphic to the irreducible highest weight\n crystal `B(\\mathrm{wt}(M))`.\n\n INPUT:\n\n - ``ct`` -- a Cartan type\n\n - ``La`` -- an element of the weight lattice\n\n EXAMPLES::\n\n sage: La = RootSystem("A2").weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials("A2",La[1]+La[2])\n sage: B = crystals.Tableaux("A2",shape=[2,1])\n sage: GM = M.digraph()\n sage: GB = B.digraph()\n sage: GM.is_isomorphic(GB,edge_labels=True)\n True\n\n sage: La = RootSystem("G2").weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials("G2",La[1]+La[2])\n sage: B = crystals.Tableaux("G2",shape=[2,1])\n sage: GM = M.digraph()\n sage: GB = B.digraph()\n sage: GM.is_isomorphic(GB,edge_labels=True)\n True\n\n sage: La = RootSystem("B2").weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials([\'B\',2],La[1]+La[2])\n sage: B = crystals.Tableaux("B2",shape=[3/2,1/2])\n sage: GM = M.digraph()\n sage: GB = B.digraph()\n sage: GM.is_isomorphic(GB,edge_labels=True)\n True\n\n sage: La = RootSystem([\'A\',3,1]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials([\'A\',3,1],La[0]+La[2])\n sage: B = crystals.GeneralizedYoungWalls(3,La[0]+La[2])\n sage: SM = M.subcrystal(max_depth=4)\n sage: SB = B.subcrystal(max_depth=4)\n sage: GM = M.digraph(subset=SM) # long time\n sage: GB = B.digraph(subset=SB) # long time\n sage: GM.is_isomorphic(GB,edge_labels=True) # long time\n True\n\n sage: La = RootSystem([\'A\',5,2]).weight_lattice(extended=True).fundamental_weights()\n sage: LA = RootSystem([\'A\',5,2]).weight_space().fundamental_weights()\n sage: M = crystals.NakajimaMonomials([\'A\',5,2],3*La[0])\n sage: B = crystals.LSPaths(3*LA[0])\n sage: SM = M.subcrystal(max_depth=4)\n sage: SB = B.subcrystal(max_depth=4)\n sage: GM = M.digraph(subset=SM)\n sage: GB = B.digraph(subset=SB)\n sage: GM.is_isomorphic(GB,edge_labels=True)\n True\n\n sage: c = matrix([[0,1,0],[0,0,1],[1,0,0]])\n sage: La = RootSystem([\'A\',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials(2*La[1], c=c)\n sage: sorted(M.subcrystal(max_depth=3), key=str)\n [Y(0,0) Y(0,1) Y(1,0) Y(2,1)^-1,\n Y(0,0) Y(0,1)^2 Y(1,1)^-1 Y(2,0) Y(2,1)^-1,\n Y(0,0) Y(0,2)^-1 Y(1,0) Y(1,1) Y(2,1)^-1 Y(2,2),\n Y(0,1) Y(0,2)^-1 Y(1,1)^-1 Y(2,0)^2 Y(2,2),\n Y(0,1) Y(1,0) Y(1,1)^-1 Y(2,0),\n Y(0,1)^2 Y(1,1)^-2 Y(2,0)^2,\n Y(0,2)^-1 Y(1,0) Y(2,0) Y(2,2),\n Y(1,0) Y(1,3) Y(2,0) Y(2,3)^-1,\n Y(1,0)^2]\n ' @staticmethod def __classcall_private__(cls, cartan_type, La=None, c=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: La = RootSystem(['E',8,1]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['E',8,1],La[0]+La[8])\n sage: M1 = crystals.NakajimaMonomials(CartanType(['E',8,1]),La[0]+La[8])\n sage: M2 = crystals.NakajimaMonomials(['E',8,1],M.Lambda()[0] + M.Lambda()[8])\n sage: M is M1 is M2\n True\n " if (La is None): La = cartan_type cartan_type = La.parent().cartan_type() cartan_type = CartanType(cartan_type) if cartan_type.is_affine(): La = RootSystem(cartan_type).weight_lattice(extended=True)(La) else: La = RootSystem(cartan_type).weight_lattice()(La) n = len(cartan_type.index_set()) c = InfinityCrystalOfNakajimaMonomials._normalize_c(c, n) return super().__classcall__(cls, cartan_type, La, c) def __init__(self, ct, La, c): "\n EXAMPLES::\n\n sage: La = RootSystem(['A',2]).weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['A',2], La[1]+La[2])\n sage: TestSuite(M).run()\n\n sage: La = RootSystem(['C',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['C',2,1], La[0])\n sage: TestSuite(M).run(max_runs=100)\n " if ct.is_finite(): cat = ClassicalCrystals() else: cat = (RegularCrystals(), HighestWeightCrystals(), InfiniteEnumeratedSets()) InfinityCrystalOfNakajimaMonomials.__init__(self, ct, c, cat) self._cartan_type = ct self.hw = La gen = {(i, 0): c for (i, c) in La} self.module_generators = (self.element_class(self, gen, {}),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['C',3,1]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['C',3,1],La[0]+5*La[3])\n sage: M\n Highest weight crystal of modified Nakajima monomials of Cartan type ['C', 3, 1] and highest weight Lambda[0] + 5*Lambda[3]\n " return 'Highest weight crystal of modified Nakajima monomials of Cartan type {1!s} and highest weight {0!s}'.format(self.hw, self._cartan_type) def cardinality(self): "\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',2]).weight_lattice().fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['A',2], La[1])\n sage: M.cardinality()\n 3\n\n sage: La = RootSystem(['D',4,2]).weight_lattice(extended=True).fundamental_weights()\n sage: M = crystals.NakajimaMonomials(['D',4,2], La[1])\n sage: M.cardinality()\n +Infinity\n " if (not self.cartan_type().is_finite()): return Infinity return super(InfinityCrystalOfNakajimaMonomials, self).cardinality() Element = CrystalOfNakajimaMonomialsElement
class InfinityCrystalOfMultisegments(Parent, UniqueRepresentation): '\n The type `A_n^{(1)}` crystal `B(\\infty)` realized using\n Bernstein-Zelevinsky (BZ) multisegments.\n\n Using (a modified version of the) notation from [JL2009]_, for `\\ell \\in\n \\ZZ_{>0}` and `i \\in \\ZZ / (n+1)\\ZZ`, a segment of length `\\ell` and head\n `i` is the sequence of consecutive residues `[i,i+1,\\dots,i+\\ell-1]`. The\n notation for a segment of length `\\ell` and head `i` is simplified to\n `[i; \\ell)`. Similarly, a segment of length `\\ell` and tail `i` is the\n sequence of consecutive residues `[i-\\ell+1, \\ldots, i-1, i]`. The latter\n is denoted simply by `(\\ell;i]`. Finally, a multisegment is a formal\n linear combination of segments, usually written in the form\n\n .. MATH::\n\n \\psi =\n \\sum_{\\substack{i \\in \\ZZ/(n+1)\\ZZ \\\\ \\ell \\in \\ZZ_{>0}}}\n m_{(\\ell;i]} (\\ell; i].\n\n Such a multisegment is called aperiodic if, for every `\\ell > 0`, there\n exists some `i \\in \\ZZ / (n+1)\\ZZ` such that `(\\ell; i]` does not appear\n in `\\psi`. Denote the set of all periodic multisegments, together with\n the empty multisegment `\\varnothing`, by `\\Psi`. We define a crystal\n structure on multisegments as follows. Set `S_{\\ell,i} = \\sum_{k \\ge \\ell}\n (m_{(k;i-1]} - m_{(k;i]})` and let `\\ell_f` be the minimal `\\ell` that\n attains the value `\\min_{\\ell > 0} S_{\\ell,i}`. Then we have\n\n .. MATH::\n\n f_i \\psi =\n \\begin{cases}\n \\psi + (1;i] & \\text{ if } \\ell_f = 1,\\\\\n \\psi + (\\ell_f;i] - (\\ell_f-1;i-1] & \\text{ if } \\ell_f > 1.\n \\end{cases}\n\n Similarly, let `\\ell_e` be the maximal `\\ell` that attains the value\n `\\min_{\\ell > 0} S_{\\ell,i}`. Then we have\n\n .. MATH::\n\n e_i \\psi =\n \\begin{cases}\n 0 & \\text{ if } \\min_{\\ell > 0} S_{\\ell,i} = 0, \\\\\n \\psi + (1; i] & \\text{ if } \\ell_e = 1,\\\\\n \\psi - (\\ell_e; i] + (\\ell_e-1; i-1] & \\text{ if } \\ell_e > 1.\n \\end{cases}\n\n Alternatively, the crystal operators may be defined using a signature\n rule, as detailed in Section 4 of [JL2009]_ (following [AJL2011]_). For\n `\\psi \\in \\Psi` and `i \\in \\ZZ/(n+1)\\ZZ`, encode all segments in `\\psi`\n with tail `i` by the symbol `R` and all segments in `\\psi` with tail\n `i-1` by `A`. For `\\ell > 0`, set\n `w_{i,\\ell} = R^{m_{(\\ell;i]}} A^{m_{(\\ell;i-1]}}` and\n `w_i = \\prod_{\\ell\\ge 1} w_{i,\\ell}`. By successively canceling out\n as many `RA` factors as possible, set\n `\\widetilde{w}_i = A^{a_i(\\psi)} R^{r_i(\\psi)}`. If `a_i(\\psi) > 0`,\n denote by `\\ell_f > 0` the length of the rightmost segment `A` in\n `\\widetilde{w}_i`. If `a_i(\\psi) = 0`, set `\\ell_f = 0`. Then\n\n .. MATH::\n\n f_i \\psi =\n \\begin{cases}\n \\psi + (1; i] & \\text{ if } a_i(\\psi) = 0,\\\\\n \\psi + (\\ell_f; i] - (\\ell_f-1; i-1] & \\text{ if } a_i(\\psi) > 0.\n \\end{cases}\n\n The rule for computing `e_i \\psi` is similar.\n\n INPUT:\n\n - ``n`` -- for type `A_n^{(1)}`\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: x = B([(8,1),(6,0),(5,1),(5,0),(4,0),(4,1),(4,1),(3,0),(3,0),(3,1),(3,1),(1,0),(1,2),(1,2)]); x\n (8; 1] + (6; 0] + (5; 0] + (5; 1] + (4; 0] + 2 * (4; 1]\n + 2 * (3; 0] + 2 * (3; 1] + (1; 0] + 2 * (1; 2]\n sage: x.f(1)\n (8; 1] + (6; 0] + (5; 0] + (5; 1] + (4; 0] + 2 * (4; 1]\n + 2 * (3; 0] + 2 * (3; 1] + (2; 1] + 2 * (1; 2]\n sage: x.f(1).f(1)\n (8; 1] + (6; 0] + (5; 0] + (5; 1] + (4; 0] + 2 * (4; 1]\n + 2 * (3; 0] + 2 * (3; 1] + (2; 1] + (1; 1] + 2 * (1; 2]\n sage: x.e(1)\n (7; 0] + (6; 0] + (5; 0] + (5; 1] + (4; 0] + 2 * (4; 1]\n + 2 * (3; 0] + 2 * (3; 1] + (1; 0] + 2 * (1; 2]\n sage: x.e(1).e(1)\n sage: x.f(0)\n (8; 1] + (6; 0] + (5; 0] + (5; 1] + (4; 0] + 2 * (4; 1]\n + 2 * (3; 0] + 2 * (3; 1] + (2; 0] + (1; 0] + (1; 2]\n\n We check an `\\widehat{\\mathfrak{sl}}_2` example against the generalized\n Young walls::\n\n sage: B = crystals.infinity.Multisegments(1)\n sage: G = B.subcrystal(max_depth=4).digraph()\n sage: C = crystals.infinity.GeneralizedYoungWalls(1)\n sage: GC = C.subcrystal(max_depth=4).digraph()\n sage: G.is_isomorphic(GC, edge_labels=True)\n True\n\n REFERENCES:\n\n - [AJL2011]_\n - [JL2009]_\n - [LTV1999]_\n ' def __init__(self, n): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: TestSuite(B).run()\n ' self._cartan_type = CartanType(['A', n, 1]) self._Zn = IntegerModRing((n + 1)) Parent.__init__(self, category=(HighestWeightCrystals(), InfiniteEnumeratedSets())) self.module_generators = (self.highest_weight_vector(),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.infinity.Multisegments(2)\n Infinity crystal of multisegments of type ['A', 2, 1]\n " return 'Infinity crystal of multisegments of type {}'.format(self._cartan_type) @cached_method def highest_weight_vector(self): '\n Return the highest weight vector of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: B.highest_weight_vector()\n 0\n ' return self.element_class(self, ()) def weight_lattice_realization(self): "\n Return a realization of the weight lattice of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: B.weight_lattice_realization()\n Extended weight lattice of the Root system of type ['A', 2, 1]\n " return self._cartan_type.root_system().weight_lattice(extended=True) class Element(ElementWrapper): '\n An element in a BZ multisegments crystal.\n ' def __init__(self, parent, value): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: mg = B.highest_weight_vector()\n sage: TestSuite(mg).run()\n ' def sort_key(x): return ((- x[0]), ZZ(x[1])) ZM = parent._Zn value = [(k, ZM(i)) for (k, i) in value] ElementWrapper.__init__(self, parent, tuple(sorted(value, key=sort_key))) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: B.highest_weight_vector()\n 0\n sage: B([(4,2), (3,0), (3,1), (3,1), (1,1), (1,0)])\n (4; 2] + (3; 0] + 2 * (3; 1] + (1; 0] + (1; 1]\n ' if (not self.value): return '0' def sort_key(mc): x = mc[0] return ((- x[0]), ZZ(x[1])) def seg(x): (m, c) = x if (c != 1): return '{} * ({}; {}]'.format(c, m[0], m[1]) return '({}; {}]'.format(m[0], m[1]) d = {} for x in self.value: d[x] = (d.get(x, 0) + 1) return ' + '.join((seg(x) for x in sorted(d.items(), key=sort_key))) def _latex_(self): '\n Return a LaTeX representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: latex(B.highest_weight_vector())\n 0\n sage: latex(B([(4,2), (3,0), (3,1), (3,1), (1,1), (1,0)]))\n (4; 2] + (3; 0] + 2 (3; 1] + (1; 0] + (1; 1]\n ' if (not self.value): return '0' def sort_key(mc): x = mc[0] return ((- x[0]), ZZ(x[1])) def seg(x): (m, c) = x if (c != 1): return '{} ({}; {}]'.format(c, m[0], m[1]) return '({}; {}]'.format(m[0], m[1]) d = {} for x in self.value: d[x] = (d.get(x, 0) + 1) return ' + '.join((seg(x) for x in sorted(d.items(), key=sort_key))) def _sig(self, i): '\n Return an `i`-signature of ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the indexing set\n\n OUTPUT:\n\n A pair ``(m, p, ep)`` where ``m`` and ``p`` correspond to the\n block length of the unmatched `-` and `+` respectively or ``None``\n if there is no such block and ``ep`` is the number of unmatched\n `-`.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: b = B([(4,2), (3,0), (3,1), (1,1), (1,0)])\n sage: b._sig(0)\n (1, None, 1)\n sage: b._sig(1)\n (None, None, 0)\n\n TESTS:\n\n Check that :trac:`23439` is fixed::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: b = B.highest_weight_vector()\n sage: b._sig(1)\n (None, None, 0)\n sage: b.epsilon(1)\n 0\n ' if (not self.value): return (None, None, 0) pos = [] block = self.value[0][0] cur = 0 for (k, j) in self.value: if (k != block): if (cur != 0): pos.append((block, cur)) cur = 0 block = k if ((j + 1) == i): cur += 1 elif (j == i): cur -= 1 if (cur != 0): pos.append((block, cur)) cur = 0 m = None p = None ep = 0 for (k, c) in pos: old = cur cur += c if (cur < 0): m = k p = None ep -= cur cur = 0 elif (not cur): p = None elif ((cur > 0) and (old <= 0)): p = k return (m, p, ep) def e(self, i): '\n Return the action of `e_i` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: b = B([(4,2), (3,0), (3,1), (1,1), (1,0)])\n sage: b.e(0)\n (4; 2] + (3; 0] + (3; 1] + (1; 1]\n sage: b.e(1)\n sage: b.e(2)\n (3; 0] + 2 * (3; 1] + (1; 0] + (1; 1]\n ' i = self.parent()._Zn(i) m = self._sig(i)[0] if (m is None): return None M = self.value a = M.index((m, i)) k = M[a][0] if (k == 1): return self.__class__(self.parent(), (M[:a] + M[(a + 1):])) return self.__class__(self.parent(), ((M[:a] + (((k - 1), (i - 1)),)) + M[(a + 1):])) def f(self, i): '\n Return the action of `f_i` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: b = B([(4,2), (3,0), (3,1), (1,1), (1,0)])\n sage: b.f(0)\n (4; 2] + (3; 0] + (3; 1] + 2 * (1; 0] + (1; 1]\n sage: b.f(1)\n (4; 2] + (3; 0] + (3; 1] + (1; 0] + 2 * (1; 1]\n sage: b.f(2)\n 2 * (4; 2] + (3; 0] + (1; 0] + (1; 1]\n ' i = self.parent()._Zn(i) p = self._sig(i)[1] M = self.value if (p is None): return self.__class__(self.parent(), (((1, i),) + M)) a = M.index((p, (i - 1))) return self.__class__(self.parent(), ((M[:a] + (((M[a][0] + 1), i),)) + M[(a + 1):])) def epsilon(self, i): '\n Return `\\varepsilon_i` of ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: b = B([(4,2), (3,0), (3,1), (1,1), (1,0)])\n sage: b.epsilon(0)\n 1\n sage: b.epsilon(1)\n 0\n sage: b.epsilon(2)\n 1\n ' i = self.parent()._Zn(i) return self._sig(i)[2] def phi(self, i): '\n Return `\\varphi_i` of ``self``.\n\n Let `\\psi \\in \\Psi`. Define `\\varphi_i(\\psi) :=\n \\varepsilon_i(\\psi) + \\langle h_i, \\mathrm{wt}(\\psi) \\rangle`,\n where `h_i` is the `i`-th simple coroot and `\\mathrm{wt}(\\psi)` is the\n :meth:`weight` of `\\psi`.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: b = B([(4,2), (3,0), (3,1), (1,1), (1,0)])\n sage: b.phi(0)\n 1\n sage: b.phi(1)\n 0\n sage: mg = B.highest_weight_vector()\n sage: mg.f(1).phi(0)\n 1\n ' h = self.parent().weight_lattice_realization().simple_coroots() return (self.epsilon(i) + self.weight().scalar(h[i])) def weight(self): '\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Multisegments(2)\n sage: b = B([(4,2), (3,0), (3,1), (1,1), (1,0)])\n sage: b.weight()\n -4*delta\n ' WLR = self.parent().weight_lattice_realization() alpha = WLR.simple_roots() n = self.parent()._cartan_type.rank() return WLR.sum((((- 1) * alpha[(j % n)]) for (k, i) in self.value for j in range(ZZ(i), (ZZ(i) + k))))
class MVPolytope(PBWCrystalElement): "\n A Mirković-Vilonen (MV) polytope.\n\n EXAMPLES:\n\n We can create an animation showing how the MV polytope changes\n under a string of crystal operators::\n\n sage: MV = crystals.infinity.MVPolytopes(['C', 2])\n sage: u = MV.highest_weight_vector()\n sage: L = RootSystem(['C',2,1]).ambient_space()\n sage: s = [1,2,1,2,2,2,1,1,1,1,2,1,2,2,1,2]\n sage: BB = [[-9, 2], [-10, 2]]\n sage: p = L.plot(reflection_hyperplanes=False, bounding_box=BB) # long time\n sage: frames = [p + L.plot_mv_polytope(u.f_string(s[:i]), # long time\n ....: circle_size=0.1,\n ....: wireframe='green',\n ....: fill='purple',\n ....: bounding_box=BB)\n ....: for i in range(len(s))]\n sage: for f in frames: # long time\n ....: f.axes(False)\n sage: animate(frames).show(delay=60) # optional -- ImageMagick # long time\n " def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['E', 6])\n sage: b = MV.module_generators[0].f_string([1,2,6,4,3,2,5,2])\n sage: b\n MV polytope with Lusztig datum (0, 1, ..., 1, 0, 0, 0, 0, 0, 0, 3, 1)\n " pbw_datum = self._pbw_datum.convert_to_new_long_word(self.parent()._default_word) return 'MV polytope with Lusztig datum {}'.format(pbw_datum.lusztig_datum) def _latex_(self): "\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['C', 2])\n sage: b = MV.module_generators[0].f_string([1,2,1,2])\n sage: latex(b)\n \\begin{tikzpicture}\n \\draw (0, 0) -- (0, -2) -- (-1, -3) -- (-1, -3) -- (-2, -2);\n \\draw (0, 0) -- (-1, 1) -- (-1, 1) -- (-2, 0) -- (-2, -2);\n \\draw[fill=black] (0, 0) circle (0.1);\n \\draw[fill=black] (-2, -2) circle (0.1);\n \\end{tikzpicture}\n sage: MV = crystals.infinity.MVPolytopes(['D',4])\n sage: b = MV.module_generators[0].f_string([1,2,1,2])\n sage: latex(b)\n \\text{\\texttt{MV{ }polytope{ }...}}\n\n TESTS::\n\n sage: MV = crystals.infinity.MVPolytopes(['A',2])\n sage: u = MV.highest_weight_vector()\n sage: b = u.f_string([1,2,2,1])\n sage: latex(b) # needs sage.symbolic\n \\begin{tikzpicture}\n \\draw (0, 0) -- (3/2, -989/1142) -- (3/2, -2967/1142) -- (0, -1978/571);\n \\draw (0, 0) -- (-3/2, -989/1142) -- (-3/2, -2967/1142) -- (0, -1978/571);\n \\draw[fill=black] (0, 0) circle (0.1);\n \\draw[fill=black] (0, -1978/571) circle (0.1);\n \\end{tikzpicture}\n " latex_options = self.parent()._latex_options P = latex_options['P'] plot_options = P.plot_parse_options(projection=latex_options['projection']) proj = plot_options.projection if (proj(P.zero()).parent().dimension() != 2): from sage.misc.latex import latex return latex(repr(self)) from sage.graphs.graph_latex import setup_latex_preamble setup_latex_preamble() pbw_data = self._pbw_datum.parent W = pbw_data.weyl_group w0 = W.long_element() al = P.simple_roots() ret = '\\begin{tikzpicture}\n' final = None for red in sorted(w0.reduced_words()): ret += '\\draw ' cur = proj(P.zero()) red = tuple(red) ret += str(cur) roots = [proj(P.sum(((c * al[a]) for (a, c) in root))) for root in pbw_data._root_list_from(red)] datum = pbw_data.convert_to_new_long_word(self._pbw_datum, red) for i in reversed(range(len(datum.lusztig_datum))): cur -= (roots[i] * datum.lusztig_datum[i]) ret += (' -- ' + str(cur)) final = cur ret += ';\n' if latex_options['mark_endpoints']: circle_size = latex_options['circle_size'] ret += '\\draw[fill=black] {} circle ({});\n'.format(proj(P.zero()), circle_size) ret += '\\draw[fill=black] {} circle ({});\n'.format(final, circle_size) ret += '\\end{tikzpicture}' return ret def _polytope_vertices(self, P): "\n Return a list of the vertices of ``self`` in ``P``.\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['C', 3])\n sage: b = MV.module_generators[0].f_string([1,2,1,2])\n sage: sorted(b._polytope_vertices(MV.weight_lattice_realization()), key=attrcall('to_vector'))\n [(0, 0, 0), (0, 2, -2), (2, 0, -2)]\n\n sage: MV = crystals.infinity.MVPolytopes(['D', 4])\n sage: b = MV.module_generators[0].f_string([1,2,3,4])\n sage: P = RootSystem(['D',4]).weight_lattice()\n sage: sorted(b._polytope_vertices(P), key=attrcall('to_vector')) # long time\n [-Lambda[1] + Lambda[3] + Lambda[4],\n -2*Lambda[2] + 2*Lambda[3] + 2*Lambda[4],\n -Lambda[2] + 2*Lambda[4],\n -Lambda[2] + 2*Lambda[3],\n 0,\n Lambda[1] - Lambda[2] + Lambda[3] + Lambda[4]]\n " pbw_data = self._pbw_datum.parent W = pbw_data.weyl_group w0 = W.long_element() al = P.simple_roots() vertices = set([P.zero()]) for red in sorted(w0.reduced_words()): cur = P.zero() red = tuple(red) roots = [P.sum(((c * al[a]) for (a, c) in root)) for root in pbw_data._root_list_from(red)] datum = pbw_data.convert_to_new_long_word(self._pbw_datum, red) for (i, c) in enumerate(datum.lusztig_datum): cur = (cur + (roots[i] * c)) vertices.add(cur) return list(vertices) def polytope(self, P=None): "\n Return a polytope of ``self``.\n\n INPUT:\n\n - ``P`` -- (optional) a space to realize the polytope; default is\n the weight lattice realization of the crystal\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['C', 3])\n sage: b = MV.module_generators[0].f_string([3,2,3,2,1])\n sage: P = b.polytope(); P\n A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 6 vertices\n sage: P.vertices()\n (A vertex at (0, 0, 0),\n A vertex at (0, 1, -1),\n A vertex at (0, 1, 1),\n A vertex at (1, -1, 0),\n A vertex at (1, 1, -2),\n A vertex at (1, 1, 2))\n " if (P is None): P = self.parent().weight_lattice_realization() from sage.geometry.polyhedron.constructor import Polyhedron return Polyhedron([v.to_vector() for v in self._polytope_vertices(P)]) def plot(self, P=None, **options): "\n Plot ``self``.\n\n INPUT:\n\n - ``P`` -- (optional) a space to realize the polytope; default is\n the weight lattice realization of the crystal\n\n .. SEEALSO::\n\n :meth:`~sage.combinat.root_system.root_lattice_realizations.RootLatticeRealizations.ParentMethods.plot_mv_polytope`\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['C', 2])\n sage: b = MV.highest_weight_vector().f_string([1,2,1,2,2,2,1,1,1,1,2,1])\n sage: b.plot() # needs sage.plot\n Graphics object consisting of 12 graphics primitives\n\n Here is the above example placed inside the ambient space\n of type `C_2`:\n\n .. PLOT::\n :width: 300 px\n\n MV = crystals.infinity.MVPolytopes(['C', 2])\n b = MV.highest_weight_vector().f_string([1,2,1,2,2,2,1,1,1,1,2,1])\n L = RootSystem(['C', 2, 1]).ambient_space()\n p = L.plot(reflection_hyperplanes=False, bounding_box=[[-8,2], [-8,2]])\n p += b.plot()\n p.axes(False)\n sphinx_plot(p)\n " if (P is None): P = self.parent().weight_lattice_realization() return P.plot_mv_polytope(self, **options)
class MVPolytopes(PBWCrystal): "\n The crystal of Mirković-Vilonen (MV) polytopes.\n\n Let `W` denote the corresponding Weyl group and `P_{\\RR} = \\RR \\otimes P`.\n Let `\\Gamma = \\{ w \\Lambda_i \\mid w \\in W, i \\in I \\}`. Consider\n `M = (M_{\\gamma} \\in \\ZZ)_{\\gamma \\in \\Gamma}` that satisfy the\n *tropical Plücker relations* (see Proposition 7.1 of [BZ01]_).\n The *MV polytope* is defined as\n\n .. MATH::\n\n P(M) = \\{ \\alpha \\in P_{\\RR} \\mid\n \\langle \\alpha, \\gamma \\rangle \\geq M_{\\gamma}\n \\text{ for all } \\gamma \\in \\Gamma \\}.\n\n The vertices `\\{\\mu_w\\}_{w \\in W}` are given by\n\n .. MATH::\n\n \\langle \\mu_w, \\gamma \\rangle = M_{\\gamma}\n\n and are known as the GGMS datum of the MV polytope.\n\n Each path from `\\mu_e` to `\\mu_{w_0}` corresponds to a reduced\n expression `\\mathbf{i} = (i_1, \\ldots, i_m)` for `w_0` and the\n corresponding edge lengths `(n_k)_{k=1}^m` from the Lusztig datum\n with respect to `\\mathbf{i}`. Explicitly, we have\n\n .. MATH::\n\n \\begin{aligned}\n n_k & = -M_{w_{k-1} \\Lambda_{i_k}} - M_{w_k \\Lambda_{i_k}}\n - \\sum_{j \\neq i} a_{ji} M_{w_k \\Lambda_j},\n \\\\ \\mu_{w_k} - \\mu_{w_{k-1}} & = n_k w_{k-1} \\alpha_{i_k},\n \\end{aligned}\n\n where `w_k = s_{i_1} \\cdots s_{i_k}` and `(a_{ji})` is the Cartan matrix.\n\n MV polytopes have a crystal structure that corresponds to the\n crystal structure, which is isomorphic to `\\mathcal{B}(\\infty)`\n with `\\mu_{w_0} = 0`, on\n :class:`PBW data <sage.combinat.crystals.pbw_crystal.PBWCrystal>`.\n Specifically, we have `f_j P(M)` as being the unique MV polytope\n given by shifting `\\mu_e` by `-\\alpha_j` and fixing the vertices\n `\\mu_w` when `s_j w < w` (in Bruhat order) and the weight is given by\n `\\mu_e`. Furthermore, the `*`-involution is given by negating `P(M)`.\n\n INPUT:\n\n - ``cartan_type`` -- a Cartan type\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['B', 3])\n sage: hw = MV.highest_weight_vector()\n sage: x = hw.f_string([1,2,2,3,3,1,3,3,2,3,2,1,3,1,2,3,1,2,1,3,2]); x\n MV polytope with Lusztig datum (1, 1, 1, 3, 1, 0, 0, 1, 1)\n\n Elements are expressed in terms of Lusztig datum for a fixed\n reduced expression of `w_0`::\n\n sage: MV.default_long_word()\n [1, 3, 2, 3, 1, 2, 3, 1, 2]\n sage: MV.set_default_long_word([2,1,3,2,1,3,2,3,1])\n sage: x\n MV polytope with Lusztig datum (3, 1, 1, 0, 1, 0, 1, 3, 4)\n sage: MV.set_default_long_word([1, 3, 2, 3, 1, 2, 3, 1, 2])\n\n We can construct elements by giving it Lusztig data (with respect\n to the default long word reduced expression)::\n\n sage: MV([1,1,1,3,1,0,0,1,1])\n MV polytope with Lusztig datum (1, 1, 1, 3, 1, 0, 0, 1, 1)\n\n We can also construct elements by passing in a reduced expression\n for a long word::\n\n sage: x = MV([1,1,1,3,1,0,0,1,1], [3,2,1,3,2,3,2,1,2]); x\n MV polytope with Lusztig datum (1, 1, 1, 0, 1, 0, 5, 1, 1)\n sage: x.to_highest_weight()[1]\n [1, 2, 2, 2, 2, 2, 1, 3, 3, 3, 3, 2, 3, 2, 3, 3, 2, 3, 3, 2, 1, 3]\n\n The highest weight crystal `B(\\lambda) \\subseteq B(\\infty)` is\n characterized by the MV polytopes that sit inside of `W \\lambda`\n (translating `\\mu_{w_0} \\mapsto \\lambda`)::\n\n sage: MV = crystals.infinity.MVPolytopes(['A',2])\n sage: La = MV.weight_lattice_realization().fundamental_weights()\n sage: R = crystals.elementary.R(La[1]+La[2])\n sage: T = tensor([R, MV])\n sage: x = T(R.module_generators[0], MV.highest_weight_vector())\n sage: lw = x.to_lowest_weight()[0]; lw\n [(2, 1, 0), MV polytope with Lusztig datum (1, 1, 1)]\n sage: lw[1].polytope().vertices()\n (A vertex at (0, 0, 0),\n A vertex at (0, 1, -1),\n A vertex at (1, -1, 0),\n A vertex at (1, 1, -2),\n A vertex at (2, -1, -1),\n A vertex at (2, 0, -2))\n\n .. PLOT::\n :width: 300 px\n\n MV = crystals.infinity.MVPolytopes(['A',2])\n x = MV.module_generators[0].f_string([1,2,2,1])\n L = RootSystem(['A',2,1]).ambient_space()\n p = L.plot(bounding_box=[[-2,2],[-4,2]]) + x.plot()\n p.axes(False)\n sphinx_plot(x.plot())\n\n REFERENCES:\n\n - [Kam2007]_\n - [Kam2010]_\n " def __init__(self, cartan_type): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['B', 2])\n sage: TestSuite(MV).run()\n " PBWCrystal.__init__(self, cartan_type) self._latex_options = {'projection': True, 'mark_endpoints': True, 'P': self.weight_lattice_realization(), 'circle_size': 0.1} def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.infinity.MVPolytopes(['F', 4])\n MV polytopes of type ['F', 4]\n " return 'MV polytopes of type {}'.format(self._cartan_type) def set_latex_options(self, **kwds): "\n Set the latex options for the elements of ``self``.\n\n INPUT:\n\n - ``projection`` -- the projection; set to ``True`` to use the\n default projection of the specified weight lattice realization\n (initial: ``True``)\n - ``P`` -- the weight lattice realization to use (initial: the\n weight lattice realization of ``self``)\n - ``mark_endpoints`` -- whether to mark the endpoints (initial: ``True``)\n - ``circle_size`` -- the size of the endpoint circles (initial: 0.1)\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['C', 2])\n sage: P = RootSystem(['C', 2]).weight_lattice()\n sage: b = MV.highest_weight_vector().f_string([1,2,1,2])\n sage: latex(b)\n \\begin{tikzpicture}\n \\draw (0, 0) -- (0, -2) -- (-1, -3) -- (-1, -3) -- (-2, -2);\n \\draw (0, 0) -- (-1, 1) -- (-1, 1) -- (-2, 0) -- (-2, -2);\n \\draw[fill=black] (0, 0) circle (0.1);\n \\draw[fill=black] (-2, -2) circle (0.1);\n \\end{tikzpicture}\n sage: MV.set_latex_options(P=P, circle_size=float(0.2))\n sage: latex(b)\n \\begin{tikzpicture}\n \\draw (0, 0) -- (2, -2) -- (2, -3) -- (2, -3) -- (0, -2);\n \\draw (0, 0) -- (-2, 1) -- (-2, 1) -- (-2, 0) -- (0, -2);\n \\draw[fill=black] (0, 0) circle (0.2);\n \\draw[fill=black] (0, -2) circle (0.2);\n \\end{tikzpicture}\n sage: MV.set_latex_options(mark_endpoints=False)\n sage: latex(b)\n \\begin{tikzpicture}\n \\draw (0, 0) -- (2, -2) -- (2, -3) -- (2, -3) -- (0, -2);\n \\draw (0, 0) -- (-2, 1) -- (-2, 1) -- (-2, 0) -- (0, -2);\n \\end{tikzpicture}\n sage: MV.set_latex_options(P=MV.weight_lattice_realization(),\n ....: circle_size=0.2,\n ....: mark_endpoints=True)\n " if ('projection' in kwds): self._latex_options['projection'] = True del kwds['projection'] if ('P' in kwds): self._latex_options['P'] = kwds['P'] del kwds['P'] if ('mark_endpoints' in kwds): self._latex_options['mark_endpoints'] = kwds['mark_endpoints'] del kwds['mark_endpoints'] if ('circle_size' in kwds): self._latex_options['circle_size'] = kwds['circle_size'] del kwds['circle_size'] if kwds: raise ValueError('invalid latex option') def latex_options(self): "\n Return the latex options of ``self``.\n\n EXAMPLES::\n\n sage: MV = crystals.infinity.MVPolytopes(['F', 4])\n sage: MV.latex_options()\n {'P': Ambient space of the Root system of type ['F', 4],\n 'circle_size': 0.1,\n 'mark_endpoints': True,\n 'projection': True}\n " from copy import copy return copy(self._latex_options) Element = MVPolytope
class PBWCrystalElement(Element): '\n A crystal element in the PBW model.\n ' def __init__(self, parent, lusztig_datum, long_word=None): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['F', 4])\n sage: u = B.highest_weight_vector()\n sage: b = u.f_string([1,2,3,4,2,3,2,3,4,1,2])\n sage: TestSuite(b).run()\n " Element.__init__(self, parent) if (long_word is None): long_word = parent._default_word self._pbw_datum = PBWDatum(parent._pbw_datum_parent, long_word, lusztig_datum) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['B', 4])\n sage: u = B.highest_weight_vector()\n sage: u.f_string([1,2,3,4,2,3,2,3,4,1,2])\n PBW monomial with Lusztig datum\n (0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 1, 2)\n " pbw_datum = self._pbw_datum.convert_to_new_long_word(self.parent()._default_word) return 'PBW monomial with Lusztig datum {}'.format(pbw_datum.lusztig_datum) def _latex_(self): "\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['F', 4])\n sage: u = B.highest_weight_vector()\n sage: b = u.f_string([1,2,3,4,2,3,2,3,4,1,2])\n sage: latex(b)\n f_{\\alpha_{4}}^{2}\n f_{\\alpha_{3}}\n f_{\\alpha_{1} + \\alpha_{2} + 2 \\alpha_{3}}\n f_{\\alpha_{1} + \\alpha_{2}}\n f_{\\alpha_{2}}^{2}\n " pbw_datum = self._pbw_datum.convert_to_new_long_word(self.parent()._default_word) lusztig_datum = list(pbw_datum.lusztig_datum) al = self.parent()._pbw_datum_parent._root_list_from(self.parent()._default_word) from sage.misc.latex import latex ret_str = ' '.join((('f_{%s}%s' % (latex(al[i]), (('^{%s}' % latex(exp)) if (exp > 1) else ''))) for (i, exp) in enumerate(lusztig_datum) if exp)) if (ret_str == ''): return '1' return ret_str def lusztig_datum(self, word=None): "\n Return the Lusztig datum of ``self`` with respect to the reduced\n expression of the long word ``word``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 2])\n sage: u = B.highest_weight_vector()\n sage: b = u.f_string([2,1,2,2,2,2,1,1,2,1,2,1,2,1,2,2])\n sage: b.lusztig_datum()\n (6, 0, 10)\n sage: b.lusztig_datum(word=[2,1,2])\n (4, 6, 0)\n " if (word is None): word = self.parent()._default_word else: self.parent()._check_is_long_word(word) word = tuple(word) pbw_datum = self._pbw_datum.convert_to_new_long_word(word) return tuple(pbw_datum.lusztig_datum) def __eq__(self, other): "\n Check equality of ``self`` with ``other``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 2])\n sage: u = B.highest_weight_vector()\n sage: b = u.f_string([2,1,2,2,2,2,1,1,2,1,2,1,2,1,2,2])\n sage: bp = u.f_string([2,1,2,2,1,1,2,2,2,1,2,1,2,2,1,2])\n sage: b == bp\n True\n " if (other not in self.parent()): return False other_long_word = other._pbw_datum.long_word other_lusztig_datum = other._pbw_datum.lusztig_datum equiv_pbw_datum = self._pbw_datum.convert_to_new_long_word(other_long_word) return (equiv_pbw_datum.lusztig_datum == other_lusztig_datum) def __ne__(self, other): "\n Check inequality of ``self`` with ``other``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 2])\n sage: u = B.highest_weight_vector()\n sage: b = u.f_string([2,1,2,2,2,2,1,1,2,1,2,1,2,1,2,2])\n sage: bp = u.f_string([2,1,2,2,1,1,2,2,2,1,2,1,2,2,1,2])\n sage: b != bp\n False\n " return (not (self == other)) def _richcmp_(self, other, op): "\n Return comparison of ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 2])\n sage: u = B.highest_weight_vector()\n sage: b = u.f_string([2,1,2,2,2,2,1,1,2,1,2,1,2,1,2,2])\n sage: bp = u.f_string([2,1,2,2,1,1,2,2,2,1,2,1,2])\n sage: w = [1, 2, 1]\n sage: (b < bp) == (b.lusztig_datum(w) < bp.lusztig_datum(w))\n True\n sage: (b > bp) == (b.lusztig_datum(w) > bp.lusztig_datum(w))\n True\n " i = self.parent().index_set()[0] word = self.parent()._pbw_datum_parent._long_word_begin_with(i) lusztig_datum = tuple(self._pbw_datum.convert_to_new_long_word(word).lusztig_datum) other_lusztig_datum = tuple(other._pbw_datum.convert_to_new_long_word(word).lusztig_datum) return richcmp(lusztig_datum, other_lusztig_datum, op) @cached_method def __hash__(self): "\n Return the hash of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 2])\n sage: u = B.highest_weight_vector()\n sage: b = u.f_string([2,1,2,2,2,2,1,1,2,1,2,1,2,1,2,2])\n sage: bp = u.f_string([2,1,2,2,1,1,2,2,2,1,2,1,2,2,1,2])\n sage: hash(b) == hash(bp)\n True\n " i = self.parent().index_set()[0] word = self.parent()._pbw_datum_parent._long_word_begin_with(i) pbw_datum = self._pbw_datum.convert_to_new_long_word(word) return hash(tuple(pbw_datum.lusztig_datum)) def e(self, i): "\n Return the action of `e_i` on ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['B', 3])\n sage: b = B.highest_weight_vector()\n sage: c = b.f_string([2,1,3,2,1,3,2,2]); c\n PBW monomial with Lusztig datum (0, 1, 0, 1, 0, 0, 0, 1, 2)\n sage: c.e(2)\n PBW monomial with Lusztig datum (0, 1, 0, 1, 0, 0, 0, 1, 1)\n sage: c.e_string([2,2,1,3,2,1,3,2]) == b\n True\n " equiv_pbw_datum = self._pbw_datum.convert_to_long_word_with_first_letter(i) new_long_word = equiv_pbw_datum.long_word new_lusztig_datum = list(equiv_pbw_datum.lusztig_datum) if (new_lusztig_datum[0] == 0): return None new_lusztig_datum[0] -= 1 return type(self)(self.parent(), tuple(new_lusztig_datum), new_long_word) def f(self, i): '\n Return the action of `f_i` on ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW("D4")\n sage: b = B.highest_weight_vector()\n sage: c = b.f_string([1,2,3,1,2,3,4]); c\n PBW monomial with Lusztig datum (0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0)\n sage: c == b.f_string([1,2,4,1,2,3,3])\n True\n ' equiv_PBWDatum = self._pbw_datum.convert_to_long_word_with_first_letter(i) new_long_word = equiv_PBWDatum.long_word new_lusztig_datum = list(equiv_PBWDatum.lusztig_datum) new_lusztig_datum[0] += 1 return type(self)(self.parent(), tuple(new_lusztig_datum), new_long_word) def epsilon(self, i): '\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(["A2"])\n sage: s = B((3,0,0), (1,2,1))\n sage: s.epsilon(1)\n 3\n sage: s.epsilon(2)\n 0\n ' equiv_pbw_datum = self._pbw_datum.convert_to_long_word_with_first_letter(i) return equiv_pbw_datum.lusztig_datum[0] def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 2])\n sage: s = B((3,0,0), (1,2,1))\n sage: s.phi(1)\n -3\n sage: s.phi(2)\n 3\n " WLR = self.parent().weight_lattice_realization() h = WLR.simple_coroots() return (self.epsilon(i) + self.weight().scalar(h[i])) def weight(self): "\n Return weight of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 2])\n sage: s = B((2,2,2), (1,2,1))\n sage: s.weight()\n (-4, 0, 4)\n " WLR = self.parent().weight_lattice_realization() al = WLR.simple_roots() return WLR.sum(((c * al[i]) for (i, c) in self._pbw_datum.weight())) def star(self): "\n Return the starred crystal element corresponding\n to ``self``.\n\n Let `b` be an element of ``self`` with Lusztig datum\n `(b_1, \\ldots, b_N)` with respect to `w_0 = s_{i_1} \\cdots s_{i_N}`.\n Then `b^*` is the element with Lusztig datum `(b_N, \\ldots, b_1)`\n with respect to `w_0 = s_{i_N^*} \\cdots s_{i_1^*}`, where\n `i_j^* = \\omega(i_j)` with `\\omega` being the :meth:`automorphism\n <sage.combinat.root_system.cartan_type.CartanType_standard_finite.opposition_automorphism>`\n given by the action of `w_0` on the simple roots.\n\n EXAMPLES::\n\n sage: P = crystals.infinity.PBW(['A', 2])\n sage: P((1,2,3), (1,2,1)).star() == P((3,2,1), (2,1,2))\n True\n\n sage: B = crystals.infinity.PBW(['E', 6])\n sage: b = B.highest_weight_vector()\n sage: c = b.f_string([1,2,6,3,4,2,5,2,3,4,1,6])\n sage: c == c.star().star()\n True\n\n TESTS::\n\n sage: from itertools import product\n sage: def test_star(PBW, depth):\n ....: S = crystals.infinity.Star(PBW)\n ....: for f_str in product(*([PBW.index_set()]*depth)):\n ....: x = PBW.highest_weight_vector().f_string(f_str).star()\n ....: y = S.highest_weight_vector().f_string(f_str)\n ....: assert x.lusztig_datum() == y.value.lusztig_datum()\n sage: P = crystals.infinity.PBW(['A', 2])\n sage: test_star(P, 5)\n sage: P = crystals.infinity.PBW(['A', 3])\n sage: test_star(P, 5)\n sage: P = crystals.infinity.PBW(['B', 3])\n sage: test_star(P, 5)\n sage: P = crystals.infinity.PBW(['C', 3])\n sage: test_star(P, 5)\n sage: P = crystals.infinity.PBW(['D', 4])\n sage: test_star(P, 5) # long time\n sage: P = crystals.infinity.PBW(['D', 5])\n sage: test_star(P, 4) # long time\n sage: P = crystals.infinity.PBW(['E', 6])\n sage: test_star(P, 4) # long time\n sage: P = crystals.infinity.PBW(['F', 4])\n sage: test_star(P, 4) # long time\n sage: P = crystals.infinity.PBW(['G', 2])\n sage: test_star(P, 5)\n " starred_pbw_datum = self._pbw_datum.star() return type(self)(self.parent(), starred_pbw_datum.lusztig_datum, starred_pbw_datum.long_word)
class PBWCrystal(Parent, UniqueRepresentation): "\n Crystal of `\\mathcal{B}(\\infty)` given by PBW monomials.\n\n A model of the crystal `\\mathcal{B}(\\infty)` whose elements are\n PBW datum up to equivalence by the tropical PlΓΌcker relations.\n The crystal structure on Lusztig data `x = (x_1, \\ldots, x_m)`\n for the reduced word `s_{i_1} \\cdots s_{i_m} = w_0` is given as\n follows. Suppose `i_1 = j`, then `f_j x = (x_1 + 1, x_2, \\ldots, x_m)`.\n If `i_1 \\neq j`, then we use the tropical PlΓΌcker relations to\n change the reduced expression such that `i_1' = j` and then we\n change back to the original word.\n\n EXAMPLES::\n\n sage: PBW = crystals.infinity.PBW(['B', 3])\n sage: hw = PBW.highest_weight_vector()\n sage: x = hw.f_string([1,2,2,3,3,1,3,3,2,3,2,1,3,1,2,3,1,2,1,3,2]); x\n PBW monomial with Lusztig datum (1, 1, 1, 3, 1, 0, 0, 1, 1)\n\n Elements are expressed in terms of Lusztig datum for a fixed\n reduced expression of `w_0`::\n\n sage: PBW.default_long_word()\n [1, 3, 2, 3, 1, 2, 3, 1, 2]\n sage: PBW.set_default_long_word([2,1,3,2,1,3,2,3,1])\n sage: x\n PBW monomial with Lusztig datum (3, 1, 1, 0, 1, 0, 1, 3, 4)\n sage: PBW.set_default_long_word([1, 3, 2, 3, 1, 2, 3, 1, 2])\n\n We can construct elements by giving it Lusztig data (with respect\n to the default long word)::\n\n sage: PBW([1,1,1,3,1,0,0,1,1])\n PBW monomial with Lusztig datum (1, 1, 1, 3, 1, 0, 0, 1, 1)\n\n We can also construct elements by passing in a reduced expression\n for a long word::\n\n sage: x = PBW([1,1,1,3,1,0,0,1,1], [3,2,1,3,2,3,2,1,2]); x\n PBW monomial with Lusztig datum (1, 1, 1, 0, 1, 0, 5, 1, 1)\n sage: x.to_highest_weight()[1]\n [1, 2, 2, 2, 2, 2, 1, 3, 3, 3, 3, 2, 3, 2, 3, 3, 2, 3, 3, 2, 1, 3]\n " @staticmethod def __classcall__(cls, cartan_type): '\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B1 = crystals.infinity.PBW([\'A\', 2])\n sage: B2 = crystals.infinity.PBW("A2")\n sage: B3 = crystals.infinity.PBW(CartanType("A2"))\n sage: B1 is B2 and B2 is B3\n True\n ' cartan_type = CartanType(cartan_type) if (not cartan_type.is_finite()): raise NotImplementedError('only implemented for finite types') return super().__classcall__(cls, cartan_type) def __init__(self, cartan_type): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['B', 2])\n sage: TestSuite(B).run()\n " self._cartan_type = cartan_type self._pbw_datum_parent = PBWData(self._cartan_type) category = (HighestWeightCrystals(), InfiniteEnumeratedSets()) Parent.__init__(self, category=category) i = self._cartan_type.index_set()[0] self._default_word = self._pbw_datum_parent._long_word_begin_with(i) zero_lusztig_datum = ([0] * len(self._default_word)) self.module_generators = (self.element_class(self, zero_lusztig_datum, self._default_word),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.infinity.PBW(['C', 3])\n Crystal of PBW data of type ['C', 3]\n " return 'Crystal of PBW data of type {}'.format(self._cartan_type) def default_long_word(self): "\n Return the default long word used to express elements of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['E', 6])\n sage: B.default_long_word()\n [1, 3, 4, 5, 6, 2, 4, 5, 3, 4, 1, 3, 2, 4, 5, 6, 2, 4,\n 5, 3, 4, 1, 3, 2, 4, 5, 3, 4, 1, 3, 2, 4, 1, 3, 2, 1]\n " return list(self._default_word) def _check_is_long_word(self, word): "\n Check if ``word`` is a reduced expression of the long of the\n Coxeter group of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['A', 3])\n sage: B._check_is_long_word([1,2,1,3,2,1])\n sage: B._check_is_long_word([1,3,2,3,2,1])\n Traceback (most recent call last):\n ...\n ValueError: not a reduced word of the long element\n sage: B._check_is_long_word([1,2,1,3,2])\n Traceback (most recent call last):\n ...\n ValueError: not a reduced word of the long element\n sage: B._check_is_long_word([1,2,1,3,2,1,2])\n Traceback (most recent call last):\n ...\n ValueError: not a reduced word of the long element\n " W = self._pbw_datum_parent.weyl_group if ((len(word) != len(self._default_word)) or (W.from_reduced_word(word) != W.long_element())): raise ValueError('not a reduced word of the long element') def set_default_long_word(self, word): "\n Set the default long word used to express elements of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PBW(['C', 3])\n sage: B.default_long_word()\n [1, 3, 2, 3, 1, 2, 3, 1, 2]\n sage: x = B.highest_weight_vector().f_string([2,1,3,2,3,1,2,3,3,1])\n sage: x\n PBW monomial with Lusztig datum (1, 2, 2, 0, 0, 0, 0, 0, 1)\n sage: B.set_default_long_word([2,1,3,2,1,3,2,3,1])\n sage: B.default_long_word()\n [2, 1, 3, 2, 1, 3, 2, 3, 1]\n sage: x\n PBW monomial with Lusztig datum (2, 0, 0, 0, 0, 0, 1, 3, 2)\n\n TESTS::\n\n sage: B = crystals.infinity.PBW(['A', 3])\n sage: B._check_is_long_word([1,2,1,3,2,1,2])\n Traceback (most recent call last):\n ...\n ValueError: not a reduced word of the long element\n " self._check_is_long_word(word) self._default_word = tuple(word) Element = PBWCrystalElement
class InfinityCrystalAsPolyhedralRealization(TensorProductOfCrystals): "\n The polyhedral realization of `B(\\infty)`.\n\n .. NOTE::\n\n Here we are using anti-Kashiwara notation and might differ from\n some of the literature.\n\n Consider a Kac-Moody algebra `\\mathfrak{g}` of Cartan type `X` with\n index set `I`, and consider a finite sequence `J = (j_1, j_2, \\ldots, j_m)`\n whose support equals `I`. We extend this to an infinite sequence\n by taking `\\bar{J} = J \\cdot J \\cdot J \\cdots`, where `\\cdot` denotes\n concatenation of sequences. Let\n\n .. MATH::\n\n B_J = B_{j_m} \\otimes \\cdots \\otimes B_{j_2} \\otimes B_{j_1},\n\n where `B_i` is an\n :class:`~sage.combinat.crystals.elementary_crystals.ElementaryCrystal`.\n\n As given in Theorem 2.1.1 of [Ka1993]_, there exists a strict crystal embedding\n `\\Psi_i \\colon B(\\infty) \\to B_i \\otimes B(\\infty)` defined by `u_{\\infty}\n \\mapsto b_i(0) \\otimes u_{\\infty}`, where `b_i(0) \\in B_i` and `u_{\\infty}`\n is the (unique) highest weight element in `B(\\infty)`. This is sometimes\n known as the *Kashiwara embedding* [NZ1997]_ (though, in [NZ1997]_, the target\n of this map is denoted by `\\ZZ_J^\\infty`). By iterating this embedding by\n taking `\\Psi_J = \\Psi_{j_n} \\circ \\Psi_{j_{n-1}} \\circ \\cdots \\circ\n \\Psi_{j_1}`, we obtain the following strict crystal embedding:\n\n .. MATH::\n\n \\Psi_J^n \\colon B(\\infty) \\to B_J^{\\otimes n} \\otimes B(\\infty).\n\n We note there is a natural analog of Lemma 10.6.2 in [HK2002]_ that\n for any `b \\in B(\\infty)`, there exists a positive integer `N` such that\n\n .. MATH::\n\n \\Psi^N_J(b) = \\left( \\bigotimes_{k=1}^N b^{(k)} \\right)\n \\otimes u_{\\infty}.\n\n Therefore we can model elements `b \\in B(\\infty)` by considering\n an infinite list of elements `b^{(k)} \\in B_J` and defining the crystal\n structure by:\n\n .. MATH::\n\n \\begin{aligned}\n \\mathrm{wt}(b) & = \\sum_{k=1}^N \\mathrm{wt}(b^{(k)})\n \\\\ e_i(b) & = e_i\\left( \\left( \\bigotimes_{k=1}^N b^{(k)} \\right)\n \\right) \\otimes u_{\\infty},\n \\\\ f_i(b) & = f_i\\left( \\left( \\bigotimes_{k=1}^N b^{(k)} \\right)\n \\right) \\otimes u_{\\infty},\n \\\\ \\varepsilon_i(b) & = \\max_{ e_i^k(b) \\neq 0 } k,\n \\\\ \\varphi_i(b) & = \\varepsilon_i(b) - \\langle \\mathrm{wt}(b),\n h_i^{\\vee} \\rangle.\n \\end{aligned}\n\n To translate this into a finite list, we consider a finite sequence\n `b_1 \\otimes \\cdots \\otimes b_N` and if\n\n .. MATH::\n\n f_i\\left( b^{(1)} \\otimes \\cdots b^{(N-1)} \\otimes b^{(N)} \\right)\n = b^{(1)} \\otimes \\cdots \\otimes b^{(N-1)} \\otimes\n f_i\\left( b^{(N)} \\right),\n\n then we take the image as `b^{(1)} \\otimes \\cdots \\otimes f_i\\left(\n b^{(N)} \\right) \\otimes b^{(N+1)}`. Similarly we remove `b^{(N)}` if\n we have `b^{(N)} = \\bigotimes_{k=1}^m b_{j_k}(0)`. Additionally if\n\n .. MATH::\n\n e_i\\left( b^{(1)} \\otimes \\cdots \\otimes b^{(N-1)} \\otimes\n b^{(N)} \\right) = b^{(1)} \\otimes \\cdots \\otimes b^{(N-1)}\n \\otimes e_i\\left( b^{(N)} \\right),\n\n then we consider this to be `0`.\n\n INPUT:\n\n - ``cartan_type`` -- a Cartan type\n - ``seq`` -- (default: ``None``) a finite sequence whose support\n equals the index set of the Cartan type; if ``None``, then this\n is the index set\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2])\n sage: mg = B.module_generators[0]; mg\n [0, 0]\n sage: mg.f_string([2,1,2,2])\n [0, -3, -1, 0, 0, 0]\n\n An example of type `B_2`::\n\n sage: B = crystals.infinity.PolyhedralRealization(['B',2])\n sage: mg = B.module_generators[0]; mg\n [0, 0]\n sage: mg.f_string([2,1,2,2])\n [0, -2, -1, -1, 0, 0]\n\n An example of type `G_2`::\n\n sage: B = crystals.infinity.PolyhedralRealization(['G',2])\n sage: mg = B.module_generators[0]; mg\n [0, 0]\n sage: mg.f_string([2,1,2,2])\n [0, -3, -1, 0, 0, 0]\n " @staticmethod def __classcall_private__(cls, cartan_type, seq=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B1 = crystals.infinity.PolyhedralRealization(['A',2])\n sage: B2 = crystals.infinity.PolyhedralRealization(['A',2], [1,2])\n sage: B1 is B2\n True\n " cartan_type = CartanType(cartan_type) if (seq is None): seq = cartan_type.index_set() else: seq = tuple(seq) if (set(seq) != set(cartan_type.index_set())): raise ValueError('the support of seq is not the index set') return super().__classcall__(cls, cartan_type, seq) def __init__(self, cartan_type, seq): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2])\n sage: TestSuite(B).run() # long time\n " cat = (HighestWeightCrystals(), InfiniteEnumeratedSets()) Parent.__init__(self, category=cat) self._cartan_type = cartan_type self._seq = seq self._factors = tuple([ElementaryCrystal(cartan_type, i) for i in seq]) self.crystals = self._factors self._tp = [C.module_generators[0] for C in self.crystals] self.module_generators = (self.element_class(self, self._tp),) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.infinity.PolyhedralRealization(['A',2])\n Polyhedral realization of B(oo) of type ['A', 2] using (1, 2)\n " return 'Polyhedral realization of B(oo) of type {} using {}'.format(self._cartan_type, self._seq) def finite_tensor_product(self, k): "\n Return the finite tensor product of crystals of length ``k``\n by truncating ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2])\n sage: B.finite_tensor_product(5)\n Full tensor product of the crystals\n [The 1-elementary crystal of type ['A', 2],\n The 2-elementary crystal of type ['A', 2],\n The 1-elementary crystal of type ['A', 2],\n The 2-elementary crystal of type ['A', 2],\n The 1-elementary crystal of type ['A', 2]]\n " N = len(self._factors) crystals = [self._factors[(i % N)] for i in range(k)] return TensorProductOfCrystals(*crystals) class Element(TensorProductOfCrystalsElement): '\n An element in the polyhedral realization of `B(\\infty)`.\n ' def epsilon(self, i): "\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2,1])\n sage: mg = B.module_generators[0]\n sage: [mg.epsilon(i) for i in B.index_set()]\n [0, 0, 0]\n sage: elt = mg.f(0)\n sage: [elt.epsilon(i) for i in B.index_set()]\n [1, 0, 0]\n sage: elt = mg.f_string([0,1,2])\n sage: [elt.epsilon(i) for i in B.index_set()]\n [0, 0, 1]\n sage: elt = mg.f_string([0,1,2,2])\n sage: [elt.epsilon(i) for i in B.index_set()]\n [0, 0, 2]\n " x = self.e(i) eps = 0 while (x is not None): x = x.e(i) eps = (eps + 1) return eps def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2,1])\n sage: mg = B.module_generators[0]\n sage: [mg.phi(i) for i in B.index_set()]\n [0, 0, 0]\n sage: elt = mg.f(0)\n sage: [elt.phi(i) for i in B.index_set()]\n [-1, 1, 1]\n sage: elt = mg.f_string([0,1])\n sage: [elt.phi(i) for i in B.index_set()]\n [-1, 0, 2]\n sage: elt = mg.f_string([0,1,2,2])\n sage: [elt.phi(i) for i in B.index_set()]\n [1, 1, 0]\n " P = self.parent().weight_lattice_realization() h = P.simple_coroots() omega = P(self.weight()).scalar(h[i]) return (self.epsilon(i) + omega) def e(self, i): "\n Return the action of `e_i` on ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2])\n sage: mg = B.module_generators[0]\n sage: all(mg.e(i) is None for i in B.index_set())\n True\n sage: mg.f(1).e(1) == mg\n True\n " N = (len(self) + 1) pos = None for k in range(1, N): if (all(((self._sig(i, k) > self._sig(i, j)) for j in range(1, k))) and all(((self._sig(i, k) >= self._sig(i, j)) for j in range((k + 1), N)))): crystal = self[(- k)].e(i) pos = k break nf = len(self.parent()._factors) if ((pos is None) or (pos <= nf)): return None l = list(self) l[(- pos)] = crystal if ((pos <= (2 * nf)) and all(((b._m == 0) for b in l[((- 2) * nf):(- nf)]))): return self.__class__(self.parent(), l[:(- nf)]) return self.__class__(self.parent(), l) def f(self, i): "\n Return the action of `f_i` on ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2])\n sage: mg = B.module_generators[0]\n sage: mg.f(1)\n [-1, 0, 0, 0]\n sage: mg.f_string([1,2,2,1])\n [-1, -2, -1, 0, 0, 0]\n " N = (len(self) + 1) pos = None for k in range(1, N): if (all(((self._sig(i, k) >= self._sig(i, j)) for j in range(1, k))) and all(((self._sig(i, k) > self._sig(i, j)) for j in range((k + 1), N)))): crystal = self[(- k)].f(i) pos = k break nf = len(self.parent()._factors) if (pos <= nf): l = list(self) l[(- pos)] = l[(- pos)].f(i) return self.__class__(self.parent(), (l + self.parent()._tp)) return self._set_index((- pos), crystal) def truncate(self, k=None): "\n Truncate ``self`` to have length ``k`` and return as an element\n in a (finite) tensor product of crystals.\n\n INPUT:\n\n - ``k`` -- (optional) the length of the truncation; if not\n specified, then returns one more than the current non-ground-state\n elements (i.e. the current list in ``self``)\n\n EXAMPLES::\n\n sage: B = crystals.infinity.PolyhedralRealization(['A',2])\n sage: mg = B.module_generators[0]\n sage: elt = mg.f_string([1,2,2,1]); elt\n [-1, -2, -1, 0, 0, 0]\n sage: t = elt.truncate(); t\n [-1, -2, -1, 0, 0, 0]\n sage: t.parent() is B.finite_tensor_product(6)\n True\n sage: elt.truncate(2)\n [-1, -2]\n sage: elt.truncate(10)\n [-1, -2, -1, 0, 0, 0, 0, 0, 0, 0]\n " if (k is None): k = len(self) P = self.parent().finite_tensor_product(k) if (k <= len(self)): l = self[:k] else: l = list(self) N = len(self.parent()._tp) while (len(l) < k): i = (len(l) % N) l.append(self.parent()._tp[i]) return P(*l)
class StarCrystal(UniqueRepresentation, Parent): "\n The star-crystal or `*`-crystal version of a highest weight crystal.\n\n The `*`-crystal structure on `B(\\infty)` is the structure induced by\n the algebra antiautomorphism `* \\colon U_q(\\mathfrak{g}) \\longrightarrow\n U_q(\\mathfrak{g})` that stabilizes the negative half `U_q^-(\\mathfrak{g})`.\n It is defined by\n\n .. MATH::\n\n E_i^* = E_i , \\ \\ \\\n F_i^* = F_i , \\ \\ \\\n q^* = q, \\ \\ \\\n (q^h)^* = q^{-h},\n\n where `E_i` and `F_i` are the Chevalley generators of `U_q(\\mathfrak{g})`\n and `h` is an element of the Cartan subalgebra.\n\n The induced operation on the crystal `B(\\infty)` is called the\n *Kashiwara involution*. Its implementation here is based on the\n recursive algorithm from Theorem 2.2.1 of [Ka1993]_, which states\n that for any `i \\in I` there is a unique strict crystal embedding\n\n .. MATH::\n\n \\Psi_i\\colon B(\\infty) \\longrightarrow B_i \\otimes B(\\infty)\n\n such that\n\n - `u_{\\infty} \\mapsto b_i(0) \\otimes u_{\\infty}`, where `u_{\\infty}`\n is the highest weight vector in `B(\\infty)`;\n\n - if `\\Psi_i(b) = f_i^mb_i(0) \\otimes b_0`, then\n `\\Psi_i(f_i^*b) =f_i^{m+1}b_i(0) \\otimes b_0`\n and `\\varepsilon_i(b^*) = m`;\n\n - the image of `\\Psi_i` is `\\{f_i^mb_i(0)\\otimes b :\n \\varepsilon_i(b^*) = 0, \\ m\\ge 0\\}`.\n\n Here, `B_i` is the `i`-th elementary crystal. See\n :class:`~sage.combinat.crystals.elementary_crystals.ElementaryCrystal`\n for more information.\n\n INPUT:\n\n - ``Binf`` -- a crystal from\n :class:`~sage.combinat.crystals.catalog_infinity_crystals`\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: Bstar = crystals.infinity.Star(B)\n sage: mg = Bstar.highest_weight_vector()\n sage: mg\n [[1, 1], [2]]\n sage: mg.f_string([1,2,1,2,2])\n [[1, 1, 1, 1, 1, 2, 2], [2, 3, 3, 3]]\n " def __init__(self, Binf): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: Bstar = crystals.infinity.Star(B)\n sage: TestSuite(Bstar).run(max_runs=40)\n sage: TestSuite(Bstar).run(max_runs=1000) # long time\n " self._Binf = Binf self._cartan_type = Binf.cartan_type() Parent.__init__(self, category=HighestWeightCrystals().Infinite()) self.module_generators = (self(self._Binf.module_generators[0]),) t0 = Binf.highest_weight_vector() B = {i: ElementaryCrystal(Binf.cartan_type(), i) for i in self.index_set()} self._tens = {i: B[i].tensor(Binf) for i in self.index_set()} gens = {i: self._tens[i](B[i](0), t0) for i in self.index_set()} self._embedding = {i: Binf.crystal_morphism({t0: gens[i]}) for i in self.index_set()} self._pullback = {i: self._tens[i].crystal_morphism({gens[i]: t0}) for i in self.index_set()} def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(3)\n sage: Ystar = crystals.infinity.Star(Y)\n sage: Ystar\n Star-crystal version of Crystal of generalized Young walls of type ['A', 3, 1]\n " return ('Star-crystal version of %s' % self._Binf) class Element(ElementWrapper): def e(self, i): "\n Return the action of `e_i^*` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['E',6,1])\n sage: RCstar = crystals.infinity.Star(RC)\n sage: nuJ = RCstar.module_generators[0].f_string([0,4,6,1,2])\n sage: ascii_art(nuJ.e(1))\n -1[ ]-1 (/) 0[ ]1 (/) -1[ ]-1 (/) -2[ ]-1\n\n sage: M = crystals.infinity.NakajimaMonomials(['B',2,1])\n sage: Mstar = crystals.infinity.Star(M)\n sage: m = Mstar.module_generators[0].f_string([0,1,2,2,1,0])\n sage: m.e(1)\n Y(0,0)^-1 Y(0,2)^-1 Y(1,1) Y(1,2)^-1 Y(2,1)^2\n " P = self.parent() image = P._embedding[i](self.value) if (image[0].e(i)._m > 0): return None return P(P._pullback[i](P._tens[i](image[0].e(i), image[1]))) def f(self, i): '\n Return the action of `f_i^*` on ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux("G2")\n sage: Tstar = crystals.infinity.Star(T)\n sage: t = Tstar.module_generators[0].f_string([1,2,1,1,2])\n sage: t\n [[1, 1, 1, 2, 0], [2, 3]]\n\n sage: M = crystals.infinity.NakajimaMonomials([\'B\',2,1])\n sage: Mstar = crystals.infinity.Star(M)\n sage: m = Mstar.module_generators[0].f_string([0,1,2,2,1,0])\n sage: m\n Y(0,0)^-1 Y(0,2)^-1 Y(1,0)^-1 Y(1,2)^-1 Y(2,0)^2 Y(2,1)^2\n ' P = self.parent() image = P._embedding[i](self.value) return P(P._pullback[i](P._tens[i](image[0].f(i), image[1]))) def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['E',6,1])\n sage: RCstar = crystals.infinity.Star(RC)\n sage: nuJ = RCstar.module_generators[0].f_string([0,4,6,1,2])\n sage: nuJ.weight()\n -Lambda[0] - 2*Lambda[1] + 2*Lambda[3] - Lambda[4]\n + 2*Lambda[5] - 2*Lambda[6] - delta\n " return self.value.weight() def epsilon(self, i): "\n Return `\\varepsilon_i^*` of ``self``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: Y = crystals.infinity.GeneralizedYoungWalls(3)\n sage: Ystar = crystals.infinity.Star(Y)\n sage: y = Ystar.module_generators[0].f_string([0,1,3,2,1,0])\n sage: [y.epsilon(i) for i in y.index_set()]\n [1, 0, 1, 0]\n\n sage: RC = crystals.infinity.RiggedConfigurations(['E',6,1])\n sage: RCstar = crystals.infinity.Star(RC)\n sage: nuJ = RCstar.module_generators[0].f_string([0,4,6,1,2])\n sage: [nuJ.epsilon(i) for i in nuJ.index_set()]\n [0, 1, 1, 0, 0, 0, 1]\n " ep = (- 1) while (self is not None): ep += 1 self = self.e(i) return ep def phi(self, i): '\n Return `\\varphi_i^*` of ``self``.\n\n For `b \\in B(\\infty)`,\n\n .. MATH::\n\n \\varphi_i^*(b) = \\varepsilon_i^*(b) + \\langle h_i,\n \\mathrm{wt}(b) \\rangle,\n\n where `h_i` is a simple coroot.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux("A2")\n sage: Tstar = crystals.infinity.Star(T)\n sage: t = Tstar.module_generators[0].f_string([1,2,1,1,2])\n sage: [t.phi(i) for i in t.index_set()]\n [-3, 1]\n\n sage: M = crystals.infinity.NakajimaMonomials([\'B\',2,1])\n sage: Mstar = crystals.infinity.Star(M)\n sage: m = Mstar.module_generators[0].f_string([0,1,2,2,1,0])\n sage: [m.phi(i) for i in m.index_set()]\n [-1, -1, 4]\n ' P = self.parent().weight_lattice_realization() ac = P.simple_coroot(i) return (P(self.weight()).scalar(ac) + self.epsilon(i)) def jump(self, i): '\n Return the `i`-jump of ``self``.\n\n For `b \\in B(\\infty)`,\n\n .. MATH::\n\n \\operatorname{jump}_i(b) = \\varepsilon_i(b) + \\varepsilon_i^*(b)\n + \\langle h_i, \\mathrm{wt}(b) \\rangle,\n\n where `h_i` is a simple coroot.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations("D4")\n sage: RCstar = crystals.infinity.Star(RC)\n sage: nu0star = RCstar.module_generators[0]\n sage: nustar = nu0star.f_string([2,1,3,4,2])\n sage: [nustar.jump(i) for i in RC.index_set()]\n [0, 1, 0, 0]\n sage: nustar = nu0star.f_string([2,1,3,4,2,2,1,3,2]) # long time\n sage: [nustar.jump(i) for i in RC.index_set()] # long time\n [1, 0, 1, 2]\n ' P = self.parent().weight_lattice_realization() ac = P.simple_coroot(i) return ((P(self.value.weight()).scalar(ac) + self.epsilon(i)) + self.value.epsilon(i))
class Subcrystal(UniqueRepresentation, Parent): "\n A subcrystal `X` of an ambient crystal `Y` is a crystal formed by taking a\n subset of `Y` and whose crystal structure is induced by `Y`.\n\n INPUT:\n\n - ``ambient`` -- the ambient crystal\n - ``contained`` -- (optional) a set (or function) which specifies when an\n element is contained in the subcrystal; the default is everything\n possible is included\n - ``generators`` -- (optional) the generators for the subcrystal; the\n default is the generators for the ambient crystal\n - ``virtualization``, ``scaling_factors`` -- (optional)\n dictionaries whose key `i` corresponds to the sets `\\sigma_i`\n and `\\gamma_i` respectively used to define virtual crystals; see\n :class:`~sage.combinat.crystals.virtual_crystal.VirtualCrystal`\n - ``cartan_type`` -- (optional) the Cartan type for the subcrystal; the\n default is the Cartan type for the ambient crystal\n - ``index_set`` -- (optional) the index set for the subcrystal; the\n default is the index set for the Cartan type\n - ``category`` -- (optional) the category for the subcrystal; the\n default is the :class:`~sage.categories.crystals.Crystals` category\n\n .. SEEALSO::\n\n :meth:`~sage.categories.crystals.Crystals.ParentMethods.subcrystal`\n\n EXAMPLES:\n\n We build out a subcrystal starting from an element and only going\n to the lowest weight::\n\n sage: B = crystals.Tableaux(['A',3], shape=[2,1])\n sage: S = B.subcrystal(generators=[B(3,1,2)], direction='lower')\n sage: S.cardinality()\n 11\n\n Here we build out in both directions starting from an element, but we\n also have restricted ourselves to type `A_2`::\n\n sage: T = B.subcrystal(index_set=[1,2], generators=[B(3,1,1)])\n sage: T.cardinality()\n 8\n sage: list(T)\n [[[1, 1], [3]],\n [[1, 2], [3]],\n [[1, 1], [2]],\n [[2, 2], [3]],\n [[1, 2], [2]],\n [[2, 3], [3]],\n [[1, 3], [2]],\n [[1, 3], [3]]]\n\n Now we take the crystal corresponding to the intersection of\n the previous two subcrystals::\n\n sage: U = B.subcrystal(contained=lambda x: x in S and x in T, generators=B)\n sage: list(U)\n [[[2, 3], [3]], [[1, 2], [3]], [[2, 2], [3]]]\n\n .. TODO::\n\n Include support for subcrystals which only contains certain arrows.\n\n TESTS:\n\n Check that the subcrystal respects being in the category\n of supercrystals (:trac:`27368`)::\n\n sage: T = crystals.Tableaux(['A',[1,1]], [2,1])\n sage: S = T.subcrystal(max_depth=3)\n sage: S.category()\n Category of finite super crystals\n " @staticmethod def __classcall_private__(cls, ambient, contained=None, generators=None, virtualization=None, scaling_factors=None, cartan_type=None, index_set=None, category=None): "\n Normalize arguments to ensure a (relatively) unique representation.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S1 = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: S2 = B.subcrystal(generators=[B(2,1,1), B(5,2,4)], cartan_type=['A',4], index_set=(1,2))\n sage: S1 is S2\n True\n " if isinstance(contained, (collections.abc.Sequence, collections.abc.Set)): contained = frozenset(contained) if (cartan_type is None): cartan_type = ambient.cartan_type() else: cartan_type = CartanType(cartan_type) if (index_set is None): index_set = cartan_type.index_set if (generators is None): generators = ambient.module_generators category = Crystals().or_subcategory(category) if (ambient in SuperCrystals()): category = (category & SuperCrystals()) if ((ambient in FiniteCrystals()) or isinstance(contained, frozenset)): category = category.Finite() if (virtualization is not None): if (scaling_factors is None): scaling_factors = {i: 1 for i in index_set} from sage.combinat.crystals.virtual_crystal import VirtualCrystal return VirtualCrystal(ambient, virtualization, scaling_factors, contained, generators, cartan_type, index_set, category) if (scaling_factors is not None): virtualization = {i: (i,) for i in index_set} from sage.combinat.crystals.virtual_crystal import VirtualCrystal return VirtualCrystal(ambient, virtualization, scaling_factors, contained, generators, cartan_type, index_set, category) return super().__classcall__(cls, ambient, contained, tuple(generators), cartan_type=cartan_type, index_set=tuple(index_set), category=category) def __init__(self, ambient, contained, generators, cartan_type, index_set, category): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: TestSuite(S).run()\n " self._ambient = ambient self._contained = contained self._cardinality = None self._cartan_type = cartan_type self._index_set = tuple(index_set) Parent.__init__(self, category=category) self.module_generators = tuple((self.element_class(self, g) for g in generators if self._containing(g))) if isinstance(contained, frozenset): self._cardinality = Integer(len(contained)) self._list = [self.element_class(self, x) for x in contained] def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n Subcrystal of The crystal of tableaux of type ['A', 4] and shape(s) [[2, 1]]\n " return 'Subcrystal of {}'.format(self._ambient) @lazy_attribute def _containing(self): "\n Check if ``x`` is contained in ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: S._containing(B(5,2,4))\n True\n sage: S._containing(B(4,2,4))\n True\n " if (self._contained is None): return (lambda x: True) if isinstance(self._contained, frozenset): return self._contained.__contains__ return self._contained def __contains__(self, x): "\n Check if ``x`` is in ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: B(5,2,4) in S\n True\n sage: mg = B.module_generators[0]\n sage: mg in S\n True\n sage: mg.f(2).f(3) in S\n False\n " if (isinstance(x, Subcrystal.Element) and (x.parent() == self)): return True if (x in self._ambient): if (not self._containing(x)): return False x = self.element_class(self, x) if (self in FiniteCrystals()): return (x in self.list()) import warnings warnings.warn('Testing containment in an infinite crystal defaults to returning True') return True def cardinality(self): "\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=[B(2,1,1)], index_set=[1,2])\n sage: S.cardinality()\n 8\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: S = B.subcrystal(max_depth=4)\n sage: S.cardinality()\n 22\n\n TESTS:\n\n Check that :trac:`19481` is fixed::\n\n sage: from sage.combinat.crystals.virtual_crystal import VirtualCrystal\n sage: A = crystals.infinity.Tableaux(['A',3])\n sage: V = VirtualCrystal(A, {1:(1,3), 2:(2,)}, {1:1, 2:2}, cartan_type=['C',2])\n sage: V.cardinality()\n Traceback (most recent call last):\n ...\n NotImplementedError: unknown cardinality\n " if (self._cardinality is not None): return self._cardinality try: card = Integer(len(self._list)) self._cardinality = card return self._cardinality except AttributeError: if (self in FiniteCrystals()): return Integer(len(self.list())) try: card = super().cardinality() except AttributeError: raise NotImplementedError('unknown cardinality') if (card == infinity): self._cardinality = card return card self._cardinality = Integer(len(self.list())) return self._cardinality def index_set(self): "\n Return the index set of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: S.index_set()\n (1, 2)\n " return self._index_set class Element(ElementWrapper): '\n An element of a subcrystal. Wraps an element in the ambient crystal.\n ' def _richcmp_(self, other, op): "\n EXAMPLES:\n\n For == operator::\n\n sage: A = crystals.KirillovReshetikhin(['C',2,1], 1,2).affinization()\n sage: S = A.subcrystal(max_depth=2)\n sage: sorted(S)\n [[[1, 1]](-1),\n [[1, 2]](-1),\n [](0),\n [[1, 1]](0),\n [[1, 2]](0),\n [[1, -2]](0),\n [[2, 2]](0),\n [](1),\n [[2, -1]](1),\n [[-2, -1]](1),\n [[-1, -1]](1),\n [[-1, -1]](2)]\n\n For != operator::\n\n sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]!=S[j]]\n ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if\n ....: S[i].value!=S[j].value])\n True\n\n For < operator::\n\n sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]<S[j]]\n ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if\n ....: S[i].value<S[j].value])\n True\n\n For <= operator::\n\n sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]<=S[j]]\n ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if\n ....: S[i].value<=S[j].value])\n True\n\n For > operator::\n\n sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]>S[j]]\n ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if\n ....: S[i].value>S[j].value])\n True\n\n For >= operator::\n\n sage: ([(i,j) for i in range(len(S)) for j in range(len(S)) if S[i]>=S[j]]\n ....: == [(i,j) for i in range(len(S)) for j in range(len(S)) if\n ....: S[i].value>=S[j].value])\n True\n " return richcmp(self.value, other.value, op) def e(self, i): "\n Return `e_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: mg = S.module_generators[1]\n sage: mg.e(2)\n sage: mg.e(1)\n [[1, 4], [5]]\n " ret = self.value.e(i) if ((ret is None) or (not self.parent()._containing(ret))): return None return self.__class__(self.parent(), ret) def f(self, i): "\n Return `f_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: mg = S.module_generators[1]\n sage: mg.f(1)\n sage: mg.f(2)\n [[3, 4], [5]]\n " ret = self.value.f(i) if ((ret is None) or (not self.parent()._containing(ret))): return None return self.__class__(self.parent(), ret) def epsilon(self, i): "\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: mg = S.module_generators[1]\n sage: mg.epsilon(1)\n 1\n sage: mg.epsilon(2)\n 0\n " return self.value.epsilon(i) def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: mg = S.module_generators[1]\n sage: mg.phi(1)\n 0\n sage: mg.phi(2)\n 1\n " return self.value.phi(i) def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['A',4], shape=[2,1])\n sage: S = B.subcrystal(generators=(B(2,1,1), B(5,2,4)), index_set=[1,2])\n sage: mg = S.module_generators[1]\n sage: mg.weight()\n (0, 1, 0, 1, 1)\n " return self.value.weight()
class CrystalOfWords(UniqueRepresentation, Parent): '\n Auxiliary class to provide a call method to create tensor product elements.\n This class is shared with several tensor product classes and is also used\n in :class:`~sage.combinat.crystals.tensor_product.CrystalOfTableaux`\n to allow tableaux of different tensor product structures in\n column-reading (and hence different shapes) to be considered elements\n in the same crystal.\n ' def _element_constructor_(self, *crystalElements): "\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: T(1,1)\n [1, 1]\n sage: _.parent()\n Full tensor product of the crystals [The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2]]\n sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)]])\n sage: T(C(2), C(1), C(1))\n [2, 1, 1]\n " return self.element_class(self, list(crystalElements)) class Element(TensorProductOfCrystalsElement): pass
class TensorProductOfCrystals(CrystalOfWords): '\n Tensor product of crystals.\n\n Given two crystals `B` and `B\'` of the same Cartan type,\n one can form the tensor product `B \\otimes B^{\\prime}`. As a set\n `B \\otimes B^{\\prime}` is the Cartesian product\n `B \\times B^{\\prime}`. The crystal operators `f_i` and\n `e_i` act on `b \\otimes b^{\\prime} \\in B \\otimes B^{\\prime}` as\n follows:\n\n .. MATH::\n\n f_i(b \\otimes b^{\\prime}) = \\begin{cases}\n f_i(b) \\otimes b^{\\prime} & \\text{if } \\varepsilon_i(b) \\geq\n \\varphi_i(b^{\\prime}) \\\\\n b \\otimes f_i(b^{\\prime}) & \\text{otherwise}\n \\end{cases}\n\n and\n\n .. MATH::\n\n e_i(b \\otimes b\') = \\begin{cases}\n e_i(b) \\otimes b\' & \\text{if } \\varepsilon_i(b) >\n \\varphi_i(b\') \\\\ b \\otimes e_i(b\') & \\text{otherwise.}\n \\end{cases}\n\n We also define:\n\n .. MATH::\n\n \\begin{aligned}\n \\varphi_i(b \\otimes b\') & = \\max\\left( \\varphi_i(b),\n \\varphi_i(b\') + \\langle \\alpha_i^{\\vee}, \\mathrm{wt}(b) \\rangle\n \\right),\n \\\\ \\varepsilon_i(b \\otimes b\') & = \\max\\left( \\varepsilon_i(b\'),\n \\varepsilon_i(b) - \\langle \\alpha_i^{\\vee}, \\mathrm{wt}(b\') \\rangle\n \\right).\n \\end{aligned}\n\n .. NOTE::\n\n This is the opposite of Kashiwara\'s convention for tensor\n products of crystals.\n\n Since tensor products are associative `(\\mathcal{B} \\otimes \\mathcal{C})\n \\otimes \\mathcal{D} \\cong \\mathcal{B} \\otimes (\\mathcal{C} \\otimes\n \\mathcal{D})` via the natural isomorphism `(b \\otimes c) \\otimes d \\mapsto\n b \\otimes (c \\otimes d)`, we can generalizing this to arbitrary tensor\n products. Thus consider `B_N \\otimes \\cdots \\otimes B_1`, where each\n `B_k` is an abstract crystal. The underlying set of the tensor product is\n `B_N \\times \\cdots \\times B_1`, while the crystal structure is given\n as follows. Let `I` be the index set, and fix some `i \\in I` and `b_N\n \\otimes \\cdots \\otimes b_1 \\in B_N \\otimes \\cdots \\otimes B_1`. Define\n\n .. MATH::\n\n a_i(k) := \\varepsilon_i(b_k) - \\sum_{j=1}^{k-1} \\langle\n \\alpha_i^{\\vee}, \\mathrm{wt}(b_j) \\rangle.\n\n Then\n\n .. MATH::\n\n \\begin{aligned}\n \\mathrm{wt}(b_N \\otimes \\cdots \\otimes b_1) &=\n \\mathrm{wt}(b_N) + \\cdots + \\mathrm{wt}(b_1),\n \\\\ \\varepsilon_i(b_N \\otimes \\cdots \\otimes b_1) &= \\max_{1 \\leq k\n \\leq n}\\left( \\sum_{j=1}^k \\varepsilon_i(b_j) - \\sum_{j=1}^{k-1}\n \\varphi_i(b_j) \\right)\n \\\\ & = \\max_{1 \\leq k \\leq N}\\bigl( a_i(k) \\bigr),\n \\\\ \\varphi_i(b_N \\otimes \\cdots \\otimes b_1) &= \\max_{1 \\leq k \\leq N}\n \\left( \\varphi_i(b_N) + \\sum_{j=k}^{N-1} \\big( \\varphi_i(b_j) -\n \\varepsilon_i(b_{j+1}) \\big) \\right)\n \\\\ & = \\max_{1 \\leq k \\leq N}\\bigl( \\lambda_i + a_i(k) \\bigr)\n \\end{aligned}\n\n where `\\lambda_i = \\langle \\alpha_i^{\\vee}, \\mathrm{wt}(b_N \\otimes \\cdots\n \\otimes b_1) \\rangle`. Then for `k = 1, \\ldots, N` the action of the\n Kashiwara operators is determined as follows.\n\n - If `a_i(k) > a_i(j)` for `1 \\leq j < k` and `a_i(k) \\geq a_i(j)`\n for `k < j \\leq N`:\n\n .. MATH::\n\n e_i(b_N \\otimes \\cdots \\otimes b_1) = b_N \\otimes \\cdots \\otimes\n e_i b_k \\otimes \\cdots \\otimes b_1.\n\n - If `a_i(k) \\geq a_i(j)` for `1 \\leq j < k` and `a_i(k) > a_i(j)`\n for `k < j \\leq N`:\n\n .. MATH::\n\n f_i(b_N \\otimes \\cdots \\otimes b_1) = b_N \\otimes \\cdots \\otimes\n f_i b_k \\otimes \\cdots \\otimes b_1.\n\n Note that this is just recursively applying the definition of the tensor\n product on two crystals. Recall that `\\langle \\alpha_i^{\\vee},\n \\mathrm{wt}(b_j) \\rangle = \\varphi_i(b_j) - \\varepsilon_i(b_j)` by the\n definition of a crystal.\n\n .. RUBRIC:: Regular crystals\n\n Now if all crystals `B_k` are regular crystals, all `\\varepsilon_i` and\n `\\varphi_i` are non-negative and we can\n define tensor product by the *signature rule*. We start by writing a word\n in `+` and `-` as follows:\n\n .. MATH::\n\n \\underbrace{- \\cdots -}_{\\varphi_i(b_N) \\text{ times}} \\quad\n \\underbrace{+ \\cdots +}_{\\varepsilon_i(b_N) \\text{ times}}\n \\quad \\cdots \\quad\n \\underbrace{- \\cdots -}_{\\varphi_i(b_1) \\text{ times}} \\quad\n \\underbrace{+ \\cdots +}_{\\varepsilon_i(b_1) \\text{ times}},\n\n and then canceling ordered pairs of `+-` until the word is in the reduced\n form:\n\n .. MATH::\n\n \\underbrace{- \\cdots -}_{\\varphi_i \\text{ times}} \\quad\n \\underbrace{+ \\cdots +}_{\\varepsilon_i \\text{ times}}.\n\n Here `e_i` acts on the factor corresponding to the leftmost `+` and `f_i`\n on the factor corresponding to the rightmost `-`. If there is no `+` or\n `-` respectively, then the result is `0` (``None``).\n\n EXAMPLES:\n\n We construct the type `A_2`-crystal generated by `2 \\otimes 1 \\otimes 1`::\n\n sage: C = crystals.Letters([\'A\',2])\n sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)]])\n\n It has `8` elements::\n\n sage: T.list()\n [[2, 1, 1], [2, 1, 2], [2, 1, 3], [3, 1, 3],\n [3, 2, 3], [3, 1, 1], [3, 1, 2], [3, 2, 2]]\n\n One can also check the Cartan type of the crystal::\n\n sage: T.cartan_type()\n [\'A\', 2]\n\n Other examples include crystals of tableaux (which internally are\n represented as tensor products obtained by reading the tableaux\n columnwise)::\n\n sage: C = crystals.Tableaux([\'A\',3], shape=[1,1,0])\n sage: D = crystals.Tableaux([\'A\',3], shape=[1,0,0])\n sage: T = crystals.TensorProduct(C,D, generators=[[C(rows=[[1], [2]]), D(rows=[[1]])], [C(rows=[[2], [3]]), D(rows=[[1]])]])\n sage: T.cardinality()\n 24\n sage: TestSuite(T).run()\n sage: T.module_generators\n ([[[1], [2]], [[1]]], [[[2], [3]], [[1]]])\n sage: [x.weight() for x in T.module_generators]\n [(2, 1, 0, 0), (1, 1, 1, 0)]\n\n If no module generators are specified, we obtain the full tensor\n product::\n\n sage: C = crystals.Letters([\'A\',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: T.list()\n [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]\n sage: T.cardinality()\n 9\n\n For a tensor product of crystals without module generators, the\n default implementation of ``module_generators`` contains all elements\n in the tensor product of the crystals. If there is a subset of\n elements in the tensor product that still generates the crystal,\n this needs to be implemented for the specific crystal separately::\n\n sage: T.module_generators.list()\n [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]\n\n For classical highest weight crystals, it is also possible to list\n all highest weight elements::\n\n sage: C = crystals.Letters([\'A\',2])\n sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)],[C(1),C(2),C(1)]])\n sage: T.highest_weight_vectors()\n ([2, 1, 1], [1, 2, 1])\n\n Examples with non-regular and infinite crystals (these did not work\n before :trac:`14402`)::\n\n sage: B = crystals.infinity.Tableaux([\'D\',10])\n sage: T = crystals.TensorProduct(B,B)\n sage: T\n Full tensor product of the crystals\n [The infinity crystal of tableaux of type [\'D\', 10],\n The infinity crystal of tableaux of type [\'D\', 10]]\n\n sage: B = crystals.infinity.GeneralizedYoungWalls(15)\n sage: T = crystals.TensorProduct(B,B,B)\n sage: T\n Full tensor product of the crystals\n [Crystal of generalized Young walls of type [\'A\', 15, 1],\n Crystal of generalized Young walls of type [\'A\', 15, 1],\n Crystal of generalized Young walls of type [\'A\', 15, 1]]\n\n sage: La = RootSystem([\'A\',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: B = crystals.GeneralizedYoungWalls(2,La[0]+La[1])\n sage: C = crystals.GeneralizedYoungWalls(2,2*La[2])\n sage: D = crystals.GeneralizedYoungWalls(2,3*La[0]+La[2])\n sage: T = crystals.TensorProduct(B,C,D)\n sage: T\n Full tensor product of the crystals\n [Highest weight crystal of generalized Young walls of Cartan type [\'A\', 2, 1] and highest weight Lambda[0] + Lambda[1],\n Highest weight crystal of generalized Young walls of Cartan type [\'A\', 2, 1] and highest weight 2*Lambda[2],\n Highest weight crystal of generalized Young walls of Cartan type [\'A\', 2, 1] and highest weight 3*Lambda[0] + Lambda[2]]\n\n There is also a global option for setting the convention (by default Sage\n uses anti-Kashiwara)::\n\n sage: C = crystals.Letters([\'A\',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: elt = T(C(1), C(2)); elt\n [1, 2]\n sage: crystals.TensorProduct.options.convention = "Kashiwara"\n sage: elt\n [2, 1]\n sage: crystals.TensorProduct.options._reset()\n ' @staticmethod def __classcall_private__(cls, *crystals, **options): "\n Create the correct parent object.\n\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: T = crystals.TensorProduct(C, C)\n sage: T2 = crystals.TensorProduct(C, C, cartan_type=['A',2])\n sage: T is T2\n True\n sage: T.category()\n Category of tensor products of classical crystals\n\n sage: T3 = crystals.TensorProduct(C, C, C)\n sage: T3p = crystals.TensorProduct(T, C)\n sage: T3 is T3p\n True\n sage: B1 = crystals.TensorProduct(T, C)\n sage: B2 = crystals.TensorProduct(C, T)\n sage: B3 = crystals.TensorProduct(C, C, C)\n sage: B1 is B2 and B2 is B3\n True\n\n sage: B = crystals.infinity.Tableaux(['A',2])\n sage: T = crystals.TensorProduct(B, B)\n sage: T.category()\n Category of infinite tensor products of highest weight crystals\n\n Check that we get a tensor product of super crystals when given\n a super Cartan type (:trac:`33518`)::\n\n sage: L = crystals.Letters(['A',[1,2]])\n sage: type(crystals.TensorProduct(L, L))\n <class 'sage.combinat.crystals.tensor_product.FullTensorProductOfSuperCrystals_with_category'>\n\n sage: L = crystals.Letters(['Q',2])\n sage: type(crystals.TensorProduct(L, L))\n <class 'sage.combinat.crystals.tensor_product.FullTensorProductOfQueerSuperCrystals_with_category'>\n\n TESTS:\n\n Check that mismatched Cartan types raise an error::\n\n sage: A2 = crystals.Letters(['A', 2])\n sage: A3 = crystals.Letters(['A', 3])\n sage: crystals.TensorProduct(A2, A3)\n Traceback (most recent call last):\n ...\n ValueError: all crystals must be of the same Cartan type\n " crystals = tuple(crystals) if ('cartan_type' in options): cartan_type = CartanType(options.pop('cartan_type')) elif (not crystals): raise ValueError('you need to specify the Cartan type if the tensor product list is empty') else: cartan_type = crystals[0].cartan_type() if any(((c.cartan_type() != cartan_type) for c in crystals)): raise ValueError('all crystals must be of the same Cartan type') if (cartan_type.type() == 'Q'): return FullTensorProductOfQueerSuperCrystals(crystals, **options) if isinstance(cartan_type, SuperCartanType_standard): return FullTensorProductOfSuperCrystals(crystals, **options) if ('generators' in options): generators = tuple(((tuple(x) if isinstance(x, list) else x) for x in options['generators'])) if all(((c in RegularCrystals()) for c in crystals)): return TensorProductOfRegularCrystalsWithGenerators(crystals, generators, cartan_type) return TensorProductOfCrystalsWithGenerators(crystals, generators, cartan_type) tp = sum([(B.crystals if isinstance(B, FullTensorProductOfCrystals) else (B,)) for B in crystals], ()) if all(((c in RegularCrystals()) for c in crystals)): return FullTensorProductOfRegularCrystals(tp, cartan_type=cartan_type) return FullTensorProductOfCrystals(tp, cartan_type=cartan_type) class options(GlobalOptions): '\n Sets the global options for tensor products of crystals. The default is to\n use the anti-Kashiwara convention.\n\n There are two conventions for how `e_i` and `f_i` act on tensor products,\n and the difference between the two is the order of the tensor factors\n are reversed. This affects both the input and output. See the example\n below.\n\n @OPTIONS@\n\n .. NOTE::\n\n Changing the ``convention`` also changes how the input is handled.\n\n .. WARNING::\n\n Internally, the crystals are always stored using the anti-Kashiwara\n convention.\n\n If no parameters are set, then the function returns a copy of the\n options dictionary.\n\n EXAMPLES::\n\n sage: C = crystals.Letters([\'A\',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: elt = T(C(1), C(2)); elt\n [1, 2]\n sage: crystals.TensorProduct.options.convention = "Kashiwara"\n sage: elt\n [2, 1]\n sage: T(C(1), C(2)) == elt\n False\n sage: T(C(2), C(1)) == elt\n True\n sage: crystals.TensorProduct.options._reset()\n ' NAME = 'TensorProductOfCrystals' module = 'sage.combinat.crystals' convention = dict(default='antiKashiwara', description='Sets the convention used for displaying/inputting tensor product of crystals', values=dict(antiKashiwara='use the anti-Kashiwara convention', Kashiwara='use the Kashiwara convention'), alias=dict(anti='antiKashiwara', opposite='antiKashiwara'), case_sensitive=False) def _element_constructor_(self, *crystalElements): "\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: T(1,1)\n [1, 1]\n sage: _.parent()\n Full tensor product of the crystals [The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2]]\n sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)]])\n sage: T(C(2), C(1), C(1))\n [2, 1, 1]\n " if (self.options.convention == 'Kashiwara'): crystalElements = reversed(crystalElements) return self.element_class(self, list(crystalElements))
class TensorProductOfCrystalsWithGenerators(TensorProductOfCrystals): '\n Tensor product of crystals with a generating set.\n\n .. TODO::\n\n Deprecate this class in favor of using\n :meth:`~sage.categories.crystals.Crystals.ParentMethods.subcrystal`.\n ' def __init__(self, crystals, generators, cartan_type): "\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)]])\n sage: TestSuite(T).run()\n " assert isinstance(crystals, tuple) assert isinstance(generators, tuple) category = Category.meet([crystal.category() for crystal in crystals]) Parent.__init__(self, category=category) self.crystals = crystals self._cartan_type = cartan_type self.module_generators = tuple([self(*x) for x in generators]) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: crystals.TensorProduct(C,C,generators=[[C(2),C(1)]])\n The tensor product of the crystals [The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2]]\n " if (self.options.convention == 'Kashiwara'): st = repr(list(reversed(self.crystals))) else: st = repr(list(self.crystals)) return 'The tensor product of the crystals {}'.format(st)
class FullTensorProductOfCrystals(TensorProductOfCrystals): '\n Full tensor product of crystals.\n\n .. TODO::\n\n Merge this into :class:`TensorProductOfCrystals`.\n ' def __init__(self, crystals, **options): "\n TESTS::\n\n sage: from sage.combinat.crystals.tensor_product import FullTensorProductOfCrystals\n sage: C = crystals.Letters(['A',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: isinstance(T, FullTensorProductOfCrystals)\n True\n sage: TestSuite(T).run()\n " category = Category.meet([crystal.category() for crystal in crystals]) category = category.TensorProducts() if any(((c in Sets().Infinite()) for c in crystals)): category = category.Infinite() Parent.__init__(self, category=category) self.crystals = crystals if ('cartan_type' in options): self._cartan_type = CartanType(options['cartan_type']) elif (not crystals): raise ValueError('you need to specify the Cartan type if the tensor product list is empty') else: self._cartan_type = crystals[0].cartan_type() self.cartesian_product = cartesian_product(self.crystals) self.module_generators = self def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: crystals.TensorProduct(C,C)\n Full tensor product of the crystals [The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2]]\n " if (self.options.convention == 'Kashiwara'): st = repr(list(reversed(self.crystals))) else: st = repr(list(self.crystals)) return 'Full tensor product of the crystals {}'.format(st) def __iter__(self): "\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: list(T)\n [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]\n sage: _[0].parent()\n Full tensor product of the crystals [The crystal of letters for type ['A', 2], The crystal of letters for type ['A', 2]]\n " for x in self.cartesian_product: (yield self(*x)) def cardinality(self): "\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: C = crystals.Letters(['A',2])\n sage: T = crystals.TensorProduct(C,C)\n sage: T.cardinality()\n 9\n " return self.cartesian_product.cardinality() @cached_method def weight_lattice_realization(self): "\n Return the weight lattice realization used to express weights.\n\n The weight lattice realization is the common parent which all\n weight lattice realizations of the crystals of ``self`` coerce\n into.\n\n EXAMPLES::\n\n sage: B = crystals.elementary.B(['A',4], 2)\n sage: B.weight_lattice_realization()\n Root lattice of the Root system of type ['A', 4]\n sage: T = crystals.infinity.Tableaux(['A',4])\n sage: T.weight_lattice_realization()\n Ambient space of the Root system of type ['A', 4]\n sage: TP = crystals.TensorProduct(B, T)\n sage: TP.weight_lattice_realization()\n Ambient space of the Root system of type ['A', 4]\n " cm = get_coercion_model() return cm.common_parent(*[crystal.weight_lattice_realization() for crystal in self.crystals])
class FullTensorProductOfRegularCrystals(FullTensorProductOfCrystals): '\n Full tensor product of regular crystals.\n ' class Element(TensorProductOfRegularCrystalsElement): pass
class TensorProductOfRegularCrystalsWithGenerators(TensorProductOfCrystalsWithGenerators): '\n Tensor product of regular crystals with a generating set.\n ' class Element(TensorProductOfRegularCrystalsElement): pass
class FullTensorProductOfSuperCrystals(FullTensorProductOfCrystals): "\n Tensor product of super crystals.\n\n EXAMPLES::\n\n sage: L = crystals.Letters(['A', [1,1]])\n sage: T = tensor([L,L,L])\n sage: T.cardinality()\n 64\n " class Element(TensorProductOfSuperCrystalsElement): pass
class QueerSuperCrystalsMixin(): '\n Mixin class with methods for a finite queer supercrystal.\n ' @cached_method def index_set(self): "\n Return the enlarged index set.\n\n EXAMPLES::\n\n sage: Q = crystals.Letters(['Q',3])\n sage: T = tensor([Q,Q])\n sage: T.index_set()\n (-4, -3, -2, -1, 1, 2)\n " n = self.cartan_type().n return (tuple(range(((- 2) * n), 0)) + tuple(range(1, (n + 1)))) @cached_method def _long_element(self): "\n Return the long element in `S_n`.\n\n This method is used in the construction of the crystal operators\n `e_i` and `f_i`.\n\n EXAMPLES::\n\n sage: Q = crystals.Letters(['Q', 4])\n sage: T = tensor([Q,Q,Q,Q])\n sage: T._long_element()\n (3, 2, 1, 3, 2, 3)\n " from sage.combinat.permutation import Permutations n = self.cartan_type().n return tuple(Permutations((n + 1)).long_element().reduced_word())
class FullTensorProductOfQueerSuperCrystals(FullTensorProductOfCrystals, QueerSuperCrystalsMixin): '\n Tensor product of queer super crystals.\n ' class Element(TensorProductOfQueerSuperCrystalsElement): pass
class CrystalOfTableaux(CrystalOfWords): "\n A class for crystals of tableaux with integer valued shapes\n\n INPUT:\n\n - ``cartan_type`` -- a Cartan type\n - ``shape`` -- a partition of length at most ``cartan_type.rank()``\n - ``shapes`` -- a list of such partitions\n\n This constructs a classical crystal with the given Cartan type and\n highest weight(s) corresponding to the given shape(s).\n\n If the type is `D_r`, the shape is permitted to have a negative\n value in the `r`-th position. Thus if the shape equals `[s_1,\\ldots,s_r]`,\n then `s_r` may be negative but in any case `s_1 \\geq \\cdots \\geq s_{r-1}\n \\geq |s_r|`. This crystal is related to that of shape\n `[s_1,\\ldots,|s_r|]` by the outer automorphism of `SO(2r)`.\n\n If the type is `D_r` or `B_r`, the shape is permitted to be of\n length `r` with all parts of half integer value. This corresponds\n to having one spin column at the beginning of the tableau. If\n several shapes are provided, they currently should all or none\n have this property.\n\n Crystals of tableaux are constructed using an embedding into\n tensor products following Kashiwara and Nakashima [KN1994]_. Sage's tensor\n product rule for crystals differs from that of Kashiwara and Nakashima\n by reversing the order of the tensor factors. Sage produces the same\n crystals of tableaux as Kashiwara and Nakashima. With Sage's convention,\n the tensor product of crystals is the same as the monoid operation on\n tableaux and hence the plactic monoid.\n\n .. SEEALSO::\n\n :mod:`sage.combinat.crystals.crystals` for general help on\n crystals, and in particular plotting and `\\LaTeX` output.\n\n EXAMPLES:\n\n We create the crystal of tableaux for type `A_2`, with\n highest weight given by the partition `[2,1,1]`::\n\n sage: T = crystals.Tableaux(['A',3], shape = [2,1,1])\n\n Here is the list of its elements::\n\n sage: T.list()\n [[[1, 1], [2], [3]], [[1, 2], [2], [3]], [[1, 3], [2], [3]],\n [[1, 4], [2], [3]], [[1, 4], [2], [4]], [[1, 4], [3], [4]],\n [[2, 4], [3], [4]], [[1, 1], [2], [4]], [[1, 2], [2], [4]],\n [[1, 3], [2], [4]], [[1, 3], [3], [4]], [[2, 3], [3], [4]],\n [[1, 1], [3], [4]], [[1, 2], [3], [4]], [[2, 2], [3], [4]]]\n\n Internally, a tableau of a given Cartan type is represented as a\n tensor product of letters of the same type. The order in which the\n tensor factors appear is by reading the columns of the tableaux\n left to right, top to bottom (in French notation). As an example::\n\n sage: T = crystals.Tableaux(['A',2], shape = [3,2])\n sage: T.module_generators[0]\n [[1, 1, 1], [2, 2]]\n sage: list(T.module_generators[0])\n [2, 1, 2, 1, 1]\n\n To create a tableau, one can use::\n\n sage: Tab = crystals.Tableaux(['A',3], shape = [2,2])\n sage: Tab(rows=[[1,2],[3,4]])\n [[1, 2], [3, 4]]\n sage: Tab(columns=[[3,1],[4,2]])\n [[1, 2], [3, 4]]\n\n .. TODO::\n\n FIXME:\n\n - Do we want to specify the columns increasingly or\n decreasingly? That is, should this be\n ``Tab(columns = [[1,3],[2,4]])``?\n - Make this fully consistent with\n :func:`~sage.combinat.tableau.Tableau`!\n\n We illustrate the use of a shape with a negative last entry in\n type `D`::\n\n sage: T = crystals.Tableaux(['D',4],shape=[1,1,1,-1])\n sage: T.cardinality()\n 35\n sage: TestSuite(T).run()\n\n We illustrate the construction of crystals of spin tableaux when\n the partitions have half integer values in type `B` and `D`::\n\n sage: T = crystals.Tableaux(['B',3],shape=[3/2,1/2,1/2]); T\n The crystal of tableaux of type ['B', 3] and shape(s) [[3/2, 1/2, 1/2]]\n sage: T.cardinality()\n 48\n sage: T.module_generators\n ([+++, [[1]]],)\n sage: TestSuite(T).run()\n\n sage: T = crystals.Tableaux(['D',3],shape=[3/2,1/2,-1/2]); T\n The crystal of tableaux of type ['D', 3] and shape(s) [[3/2, 1/2, -1/2]]\n sage: T.cardinality()\n 20\n sage: T.module_generators\n ([++-, [[1]]],)\n sage: TestSuite(T).run()\n\n We can also construct the tableaux for `\\mathfrak{gl}(m|n)` as\n given by [BKK2000]_::\n\n sage: T = crystals.Tableaux(['A', [1,2]], shape=[4,2,1,1,1])\n sage: T.cardinality()\n 1392\n\n We can also construct the tableaux for `\\mathfrak{q}(n)` as\n given by [GJK+2014]_::\n\n sage: T = crystals.Tableaux(['Q', 3], shape=[3,1])\n sage: T.cardinality()\n 24\n\n TESTS:\n\n Base cases::\n\n sage: T = crystals.Tableaux(['A',2], shape = [])\n sage: T.list()\n [[]]\n sage: TestSuite(T).run()\n\n sage: T = crystals.Tableaux(['C',2], shape = [1])\n sage: T.list()\n [[[1]], [[2]], [[-2]], [[-1]]]\n sage: TestSuite(T).run()\n\n sage: T = crystals.Tableaux(['A',2], shapes = [[],[1],[2]])\n sage: T.list()\n [[], [[1]], [[2]], [[3]], [[1, 1]], [[1, 2]], [[2, 2]], [[1, 3]], [[2, 3]], [[3, 3]]]\n sage: T.module_generators\n ([], [[1]], [[1, 1]])\n\n sage: T = crystals.Tableaux(['B',2], shape=[3])\n sage: T(rows=[[1,1,0]])\n [[1, 1, 0]]\n\n Input tests::\n\n sage: T = crystals.Tableaux(['A',3], shape = [2,2])\n sage: C = T.letters\n sage: list(Tab(rows = [[1,2],[3,4]])) == [C(3),C(1),C(4),C(2)]\n True\n sage: list(Tab(columns = [[3,1],[4,2]])) == [C(3),C(1),C(4),C(2)]\n True\n\n For compatibility with\n :func:`~sage.combinat.crystals.tensor_product.TensorProductOfCrystals` we\n need to accept as input the internal list or sequence of elements::\n\n sage: list(Tab(list = [3,1,4,2])) == [C(3),C(1),C(4),C(2)]\n True\n sage: list(Tab(3,1,4,2)) == [C(3),C(1),C(4),C(2)]\n True\n\n The next example checks whether a given tableau is in fact a valid\n type `C` tableau or not::\n\n sage: T = crystals.Tableaux(['C',3], shape = [2,2,2])\n sage: Tab = T(rows=[[1,3],[2,-3],[3,-1]])\n sage: Tab in T.list()\n True\n sage: Tab = T(rows=[[2,3],[3,-3],[-3,-2]])\n sage: Tab in T.list()\n False\n\n Check that entries are weakly decreasing also in the spin case::\n\n sage: crystals.Tableaux(['D',4], shape=[-1/2,1/2,1/2,-1/2])\n Traceback (most recent call last):\n ...\n ValueError: entries of each shape must be weakly decreasing\n\n " @staticmethod def __classcall_private__(cls, cartan_type, shapes=None, shape=None): "\n Normalizes the input arguments to ensure unique representation,\n and to delegate the construction of spin tableaux.\n\n EXAMPLES::\n\n sage: T1 = crystals.Tableaux(CartanType(['A',3]), shape = [2,2])\n sage: T2 = crystals.Tableaux(['A',3], shape = (2,2))\n sage: T3 = crystals.Tableaux(['A',3], shapes = ([2,2],))\n sage: T2 is T1, T3 is T1\n (True, True)\n\n sage: T1 = crystals.Tableaux(['A', [1,1]], shape=[3,1,1,1])\n sage: T1\n Crystal of BKK tableaux of shape [3, 1, 1, 1] of gl(2|2)\n sage: T2 = crystals.Tableaux(['A', [1,1]], [3,1,1,1])\n sage: T1 is T2\n True\n\n " cartan_type = CartanType(cartan_type) if ((cartan_type.letter == 'A') and isinstance(cartan_type, SuperCartanType_standard)): if (shape is None): shape = shapes shape = _Partitions(shape) from sage.combinat.crystals.bkk_crystals import CrystalOfBKKTableaux return CrystalOfBKKTableaux(cartan_type, shape=shape) if (cartan_type.letter == 'Q'): if any(((shape[i] == shape[(i + 1)]) for i in range((len(shape) - 1)))): raise ValueError('not a strict partition') shape = _Partitions(shape) return CrystalOfQueerTableaux(cartan_type, shape=shape) n = cartan_type.rank() assert operator.xor((shape is not None), (shapes is not None)) if (shape is not None): shapes = (shape,) if (cartan_type.type() == 'A'): n1 = (n + 1) else: n1 = n if (not all(((i == 0) for shape in shapes for i in shape[n1:]))): raise ValueError('shapes should all have length at most equal to the rank or the rank + 1 in type A') spin_shapes = tuple(((tuple(shape) + ((0,) * (n1 - len(shape))))[:n1] for shape in shapes)) try: shapes = tuple((tuple((trunc(i) for i in shape)) for shape in spin_shapes)) except Exception: raise ValueError('shapes should all be partitions or half-integer partitions') if (spin_shapes == shapes): shapes = tuple(((_Partitions(shape) if (shape[(n1 - 1)] in NN) else shape) for shape in shapes)) return super().__classcall__(cls, cartan_type, shapes) if any(((len(sh) != n) for sh in shapes)): raise ValueError('the length of all half-integer partition shapes should be the rank') if any(((((2 * i) % 2) != 1) for shape in spin_shapes for i in shape)): raise ValueError('shapes should be either all partitions or all half-integer partitions') if any((any(((i < j) for (i, j) in zip(shape, (shape[1:(- 1)] + (abs(shape[(- 1)]),))))) for shape in spin_shapes)): raise ValueError('entries of each shape must be weakly decreasing') if (cartan_type.type() == 'D'): if all(((i >= 0) for shape in spin_shapes for i in shape)): S = CrystalOfSpinsPlus(cartan_type) elif all(((shape[(- 1)] < 0) for shape in spin_shapes)): S = CrystalOfSpinsMinus(cartan_type) else: raise ValueError('in type D spins should all be positive or negative') else: if any(((i < 0) for shape in spin_shapes for i in shape)): raise ValueError('shapes should all be partitions') S = CrystalOfSpins(cartan_type) B = CrystalOfTableaux(cartan_type, shapes=shapes) T = TensorProductOfCrystals(S, B, generators=[[S.module_generators[0], x] for x in B.module_generators]) T.rename(('The crystal of tableaux of type %s and shape(s) %s' % (cartan_type, list((list(shape) for shape in spin_shapes))))) T.shapes = spin_shapes return T def __init__(self, cartan_type, shapes): "\n Construct the crystal of all tableaux of the given shapes.\n\n INPUT:\n\n - ``cartan_type`` -- (data coercible into) a Cartan type\n - ``shapes`` -- a list (or iterable) of shapes\n - ``shape`` -- a shape\n\n Shapes themselves are lists (or iterable) of integers.\n\n EXAMPLES::\n\n sage: T = crystals.Tableaux(['A',3], shape = [2,2])\n sage: TestSuite(T).run()\n " Parent.__init__(self, category=ClassicalCrystals()) self.letters = CrystalOfLetters(cartan_type) self.shapes = shapes self.module_generators = tuple((self.module_generator(la) for la in shapes)) self.rename(('The crystal of tableaux of type %s and shape(s) %s' % (cartan_type, list((list(shape) for shape in shapes))))) def cartan_type(self): "\n Returns the Cartan type of the associated crystal\n\n EXAMPLES::\n\n sage: T = crystals.Tableaux(['A',3], shape = [2,2])\n sage: T.cartan_type()\n ['A', 3]\n " return self.letters.cartan_type() def module_generator(self, shape): "\n This yields the module generator (or highest weight element) of a classical\n crystal of given shape. The module generator is the unique tableau with equal\n shape and content.\n\n EXAMPLES::\n\n sage: T = crystals.Tableaux(['D',3], shape = [1,1])\n sage: T.module_generator([1,1])\n [[1], [2]]\n\n sage: T = crystals.Tableaux(['D',4],shape=[2,2,2,-2])\n sage: T.module_generator(tuple([2,2,2,-2]))\n [[1, 1], [2, 2], [3, 3], [-4, -4]]\n sage: T.cardinality()\n 294\n sage: T = crystals.Tableaux(['D',4],shape=[2,2,2,2])\n sage: T.module_generator(tuple([2,2,2,2]))\n [[1, 1], [2, 2], [3, 3], [4, 4]]\n sage: T.cardinality()\n 294\n " type = self.cartan_type() if ((type[0] == 'D') and (len(shape) == type[1]) and (shape[(type[1] - 1)] < 0)): invert = True shape = (shape[:(- 1)] + ((- shape[(type[1] - 1)]),)) else: invert = False p = _Partitions(shape).conjugate() module_generator = flatten([[(val - i) for i in range(val)] for val in p]) if invert: module_generator = [((- x) if (x == type[1]) else x) for x in module_generator] return self(list=[self.letters(x) for x in module_generator]) def _element_constructor_(self, *args, **options): "\n Return a\n :class:`~sage.combinat.crystals.tensor_product.CrystalOfTableauxElement`.\n\n EXAMPLES::\n\n sage: T = crystals.Tableaux(['A',3], shape = [2,2])\n sage: T(rows=[[1,2],[3,4]])\n [[1, 2], [3, 4]]\n sage: T(columns=[[3,1],[4,2]])\n [[1, 2], [3, 4]]\n " return self.element_class(self, *args, **options) class Element(CrystalOfTableauxElement): pass
class CrystalOfQueerTableaux(CrystalOfWords, QueerSuperCrystalsMixin): '\n A queer crystal of the semistandard decomposition tableaux of a given shape.\n\n INPUT:\n\n - ``cartan_type`` -- a Cartan type\n - ``shape`` -- a shape\n ' def __init__(self, cartan_type, shape): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: T = crystals.Tableaux(['Q',3], shape=[4,2])\n sage: TestSuite(T).run()\n sage: T = crystals.Tableaux(['Q',4], shape=[4,1])\n sage: TestSuite(T).run() # long time\n " from sage.categories.regular_supercrystals import RegularSuperCrystals from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets Parent.__init__(self, category=(RegularSuperCrystals(), FiniteEnumeratedSets())) self.shape = shape self._cartan_type = cartan_type self.letters = CrystalOfLetters(cartan_type) n = (cartan_type.rank() + 1) data = sum((([self.letters((n - i))] * row_len) for (i, row_len) in enumerate(shape)), []) mg = self.element_class(self, list=data) self.module_generators = (mg,) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.Tableaux(['Q',3], shape=[4,2])\n The crystal of tableaux of type ['Q', 3] and shape [4, 2]\n " return 'The crystal of tableaux of type {} and shape {}'.format(self._cartan_type, self.shape) class Element(TensorProductOfQueerSuperCrystalsElement): def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['Q',3], shape=[3,2,1])\n sage: B.an_element()\n [[3, 3, 3], [2, 2], [1]]\n " return repr([list(reversed(row)) for row in self.rows()]) def _ascii_art_(self): "\n Return an ASCII art representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['Q',3], shape=[3,2,1])\n sage: t = B.an_element()\n sage: t._ascii_art_()\n 3 3 3\n 2 2\n 1\n " from sage.typeset.ascii_art import AsciiArt ret = [((' ' * (3 * i)) + ''.join((('%3s' % str(x)) for x in reversed(row)))) for (i, row) in enumerate(self.rows())] return AsciiArt(ret) def _latex_(self): "\n Return latex code for ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['Q',3], shape=[3,2,1])\n sage: t = B.an_element()\n sage: latex(t)\n {\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n \\raisebox{-.6ex}{$\\begin{array}[b]{*{3}c}\\cline{1-3}\n \\lr{3}&\\lr{3}&\\lr{3}\\\\\\cline{1-3}\n &\\lr{2}&\\lr{2}\\\\\\cline{2-3}\n &&\\lr{1}\\\\\\cline{3-3}\n \\end{array}$}\n }\n " from sage.combinat.output import tex_from_array return tex_from_array([(([None] * i) + list(reversed(row))) for (i, row) in enumerate(self.rows())]) def rows(self): "\n Return the list of rows of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['Q',3], shape=[3,2,1])\n sage: t = B.an_element()\n sage: t.rows()\n [[3, 3, 3], [2, 2], [1]]\n " ret = [] pos = 0 for l in self.parent().shape: ret.append(self[pos:(pos + l)]) pos += l return ret
class VirtualCrystal(Subcrystal): "\n A virtual crystal `V` of an ambient crystal `\\widehat{B}` is a crystal\n formed by taking a subset of `\\widehat{B}` and whose crystal structure\n is given by\n\n .. MATH::\n\n e_i = \\prod_{j \\in \\sigma_i} \\widehat{e}_j^{\\gamma_i}, \\quad\n f_i = \\prod_{j \\in \\sigma_i} \\widehat{f}_j^{\\gamma_i},\n\n .. MATH::\n\n \\varepsilon_i = \\frac{\\widehat{\\varepsilon}_j}{\\gamma_j}, \\quad\n \\varphi_i = \\frac{\\widehat{\\varphi}_j}{\\gamma_j}, \\quad\n \\operatorname{wt} = \\Psi^{-1} \\circ \\widehat{\\operatorname{wt}}\n\n where `\\sigma_i` is a subset of the index set of `B`, `\\gamma_i \\in \\ZZ`\n are the *scaling factors*, and `\\Psi : P \\to \\widehat{P}` is an embedding\n of the weight lattices. We note that for the crystal to be well-defined,\n we must have\n\n .. MATH::\n\n \\widehat{\\varepsilon}_j = \\widehat{\\varepsilon|j^{\\prime}},\n \\quad \\widehat{\\varphi}_j = \\widehat{\\varphi}_{j^{\\prime}}\n\n for all `j, j^{\\prime} \\in \\sigma_i` and that the order that the Kashiwara\n operators in the ambient space are applied does not affect the result.\n\n INPUT:\n\n - ``ambient`` -- the ambient crystal\n - ``virtualization`` -- a dictionary whose key `i` corresponds\n to the set `\\sigma_i`\n - ``scaling_factors`` -- a dictionary whose key `i` corresponds to\n the scaling factor `\\gamma_i`\n - ``contained`` -- (optional) a set (or function) which specifies when an\n element is contained in the subcrystal; the default is everything\n possible is included\n - ``generators`` -- (optional) the generators for the virtual crystal; the\n default is the generators for the ambient crystal\n - ``cartan_type`` -- (optional) the Cartan type for the virtual crystal;\n the default is the Cartan type for the ambient crystal\n - ``index_set`` -- (optional) the index set for the virtual crystal; the\n default is the index set for the Cartan type\n - ``category`` -- (optional) the category for the virtual crystal; the\n default is the :class:`~sage.categories.crystals.Crystals` category\n\n EXAMPLES:\n\n We construct an example from a natural virtualization map of type `C_n`\n in type `A_{2n-1}`::\n\n sage: C = crystals.Tableaux(['C',2], shape=[1])\n sage: A = crystals.Tableaux(['A',3], shape=[2,1,1])\n sage: psi = C.crystal_morphism(A.module_generators)\n sage: V = psi.image()\n sage: list(V)\n [[[1, 1], [2], [3]],\n [[1, 2], [2], [4]],\n [[1, 3], [3], [4]],\n [[2, 4], [3], [4]]]\n sage: V.digraph().is_isomorphic(C.digraph(), edge_labels=True)\n True\n\n We construct the virtualization of a `U_q'(\\mathfrak{g})`-crystal\n `B^{r,s}` of type `C_n^{(1)}` in type `A_{2n+1}^{(2)}`. Here it is not\n a default folding known to Sage, so we have to explicitly state the\n folding (since the scaling factors are not specified, they are all\n assumed to be 1)::\n\n sage: K = crystals.KirillovReshetikhin(['C',2,1], 1,1)\n sage: VK = crystals.KirillovReshetikhin(['A',5,2], 1,1)\n sage: target = VK.module_generator().f(1); target\n [[2]]\n sage: psi = K.crystal_morphism({K.module_generator(): target},\n ....: virtualization={0:[0,1], 1:[2], 2:[3]})\n sage: V = psi.image()\n sage: list(V)\n [[[2]], [[3]], [[-2]], [[-3]]]\n sage: V.digraph().is_isomorphic(K.digraph(), edge_labels=True)\n True\n\n We create an example of `B(\\Lambda_n)` of type `B_n` inside\n of `B(2\\Lambda_n)` using the doubling map through the (virtual)\n subcrystal method::\n\n sage: BB = crystals.Tableaux(['B',3], shape=[1,1,1])\n sage: S = BB.subcrystal(scaling_factors={1:2, 2:2, 3:2})\n sage: B = crystals.Tableaux(['B',3], shape=[1/2,1/2,1/2])\n sage: S.digraph().is_isomorphic(B.digraph(), edge_labels=True)\n True\n\n We can also directly construct a virtual crystal using\n :class:`VirtualCrystal` (however it is recommended to use either\n :meth:`~sage.categories.crystals.Crystals.ParentMethods.crystal_morphism`\n or :meth:`~sage.categories.crystals.Crystals.ParentMethods.subcrystal`)::\n\n sage: from sage.combinat.crystals.virtual_crystal import VirtualCrystal\n sage: A = crystals.Tableaux(['A',3], shape=[2,1,1])\n sage: V = VirtualCrystal(A, {1:(1,3), 2:(2,)}, {1:1, 2:2}, cartan_type=['C',2])\n sage: G = crystals.Tableaux(['C',2], shape=[1]).digraph()\n sage: V.digraph().is_isomorphic(G, edge_labels=True)\n True\n\n sage: C1 = crystals.Tableaux(['A',3], shape=[1])\n sage: C2 = crystals.Tableaux(['A',3], shape=[1,1,1])\n sage: T = C1.tensor(C2)\n sage: mg = T(C1.module_generators[0], C2.module_generators[0])\n sage: V = VirtualCrystal(A, {1:(1,3), 2:(2,)}, {1:1, 2:2},\n ....: cartan_type=['C',2], generators=[mg])\n sage: V.digraph().is_isomorphic(G, edge_labels=True)\n True\n\n REFERENCES:\n\n - [FOS2009]_\n - [OSS03]_\n - [OSS2003]_\n " @staticmethod def __classcall_private__(cls, ambient, virtualization, scaling_factors, contained=None, generators=None, cartan_type=None, index_set=None, category=None): "\n Normalize arguments to ensure a unique representation.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi1 = B.crystal_morphism(C.module_generators)\n sage: V1 = psi1.image()\n sage: psi2 = B.crystal_morphism(C.module_generators, index_set=[1,2,3])\n sage: V2 = psi2.image()\n sage: V1 is V2\n True\n\n TESTS:\n\n Check that :trac:`19481` is fixed::\n\n sage: from sage.combinat.crystals.virtual_crystal import VirtualCrystal\n sage: A = crystals.Tableaux(['A',3], shape=[2,1,1])\n sage: V = VirtualCrystal(A, {1:(1,3), 2:(2,)}, {1:1, 2:2}, cartan_type=['C',2])\n sage: V.category()\n Category of finite crystals\n " if (cartan_type is None): cartan_type = ambient.cartan_type() else: cartan_type = CartanType(cartan_type) if (index_set is None): index_set = cartan_type.index_set() if (generators is None): generators = ambient.module_generators virtualization = Family(virtualization) scaling_factors = Family(scaling_factors) category = Crystals().or_subcategory(category) if ((ambient in FiniteCrystals()) or isinstance(contained, frozenset)): category = category.Finite() return super().__classcall__(cls, ambient, virtualization, scaling_factors, contained, tuple(generators), cartan_type, tuple(index_set), category) def __init__(self, ambient, virtualization, scaling_factors, contained, generators, cartan_type, index_set, category): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: TestSuite(V).run()\n " self._virtualization = virtualization self._scaling_factors = scaling_factors Subcrystal.__init__(self, ambient, contained, generators, cartan_type, index_set, category) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: psi.image()\n Virtual crystal of The crystal of tableaux of type ['D', 4] and shape(s) [[2]] of type ['B', 3]\n " return 'Virtual crystal of {} of type {}'.format(self._ambient, self._cartan_type) def __contains__(self, x): "\n Check if ``x`` is in ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: mg = C.module_generators[0]\n sage: mg in V\n True\n sage: mg.f(1) in V\n False\n sage: mg.f(1).f(1) in V\n True\n " if (not Subcrystal.__contains__(self, x)): return False if (self in FiniteCrystals()): if isinstance(x, self._ambient.element_class): if (x.parent() == self): x = self.element_class(self, self._ambient(x)) elif (x.parent() == self._ambient): x = self.element_class(self, self._ambient(x)) elif (isinstance(x, self.element_class) and (x.parent() != self)): x = self.element_class(self, x.value) return (x in self.list()) return True def virtualization(self): "\n Return the virtualization sets `\\sigma_i`.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: V.virtualization()\n Finite family {1: (1,), 2: (2,), 3: (3, 4)}\n " return self._virtualization def scaling_factors(self): "\n Return the scaling factors `\\gamma_i`.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: V.scaling_factors()\n Finite family {1: 2, 2: 2, 3: 1}\n " return self._scaling_factors class Element(Subcrystal.Element): '\n An element of a virtual (sub)crystal. Wraps an element in the\n ambient crystal.\n ' def e(self, i): "\n Return `e_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: mg = V.module_generators[0]\n sage: mg.e(1)\n sage: b = psi(B.module_generators[0].f(1))\n sage: V(b).e(1)\n [[1, 1]]\n " s = [] P = self.parent() sf = P._scaling_factors[i] for j in P._virtualization[i]: s += ([j] * sf) ret = self.value.e_string(s) if (ret is None): return None return self.__class__(P, ret) def f(self, i): "\n Return `f_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: mg = V.module_generators[0]\n sage: mg.f(1)\n [[2, 2]]\n sage: mg.f(2)\n " s = [] P = self.parent() sf = P._scaling_factors[i] for j in P._virtualization[i]: s += ([j] * sf) ret = self.value.f_string(s) if (ret is None): return None return self.__class__(P, ret) def epsilon(self, i): "\n Return `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: mg = V.module_generators[0]\n sage: mg.epsilon(2)\n 0\n sage: mg.f(1).epsilon(1)\n 1\n " P = self.parent() return (self.value.epsilon(P._virtualization[i][0]) // P._scaling_factors[i]) def phi(self, i): "\n Return `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: mg = V.module_generators[0]\n sage: mg.phi(1)\n 1\n sage: mg.phi(2)\n 0\n " P = self.parent() return (self.value.phi(P._virtualization[i][0]) // P._scaling_factors[i]) def weight(self): "\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: B = crystals.Tableaux(['B',3], shape=[1])\n sage: C = crystals.Tableaux(['D',4], shape=[2])\n sage: psi = B.crystal_morphism(C.module_generators)\n sage: V = psi.image()\n sage: mg = V.module_generators[0]\n sage: mg.weight()\n (1, 0, 0)\n sage: mg.f(1).weight()\n (0, 1, 0)\n sage: all(V(psi(x)).weight() == x.weight() for x in B)\n True\n " P = self.parent() WLR = P.weight_lattice_realization() wt = self.value.weight() ac = P._ambient.weight_lattice_realization().simple_coroots() La = WLR.fundamental_weights() v = P._virtualization sf = P._scaling_factors return WLR.sum((((wt.scalar(ac[v[i][0]]) // sf[i]) * La[i]) for i in self.index_set()))
def CyclicSievingPolynomial(L, cyc_act=None, order=None, get_order=False): '\n Return the unique polynomial ``p`` of degree smaller than ``order`` such\n that the triple ``(L, cyc_act, p)`` exhibits the Cyclic Sieving Phenomenon.\n\n If ``cyc_act`` is None, ``L`` is expected to contain the orbit lengths.\n\n INPUT:\n\n - ``L`` -- if ``cyc_act`` is ``None``: list of orbit sizes,\n otherwise list of objects\n\n - ``cyc_act`` -- (default:``None``) bijective function from ``L`` to ``L``\n\n - ``order`` -- (default:``None``) if set to an integer, this\n cyclic order of ``cyc_act`` is used (must be an integer multiple\n of the order of ``cyc_act``) otherwise, the order of ``cyc_action`` is\n used\n\n - ``get_order`` -- (default:``False``) if ``True``, a tuple ``[p,n]``\n is returned where ``p`` is as above, and ``n`` is the order\n\n EXAMPLES::\n\n sage: from sage.combinat.cyclic_sieving_phenomenon import CyclicSievingPolynomial\n sage: S42 = Subsets([1,2,3,4], 2)\n sage: def cyc_act(S): return Set(i.mod(4) + 1 for i in S)\n sage: cyc_act([1,3])\n {2, 4}\n sage: cyc_act([1,4])\n {1, 2}\n sage: CyclicSievingPolynomial(S42, cyc_act)\n q^3 + 2*q^2 + q + 2\n sage: CyclicSievingPolynomial(S42, cyc_act, get_order=True)\n [q^3 + 2*q^2 + q + 2, 4]\n sage: CyclicSievingPolynomial(S42, cyc_act, order=8)\n q^6 + 2*q^4 + q^2 + 2\n sage: CyclicSievingPolynomial([4,2])\n q^3 + 2*q^2 + q + 2\n\n TESTS:\n\n We check that :trac:`13997` is handled::\n\n sage: CyclicSievingPolynomial(S42, cyc_act, order=8, get_order=True)\n [q^6 + 2*q^4 + q^2 + 2, 8]\n sage: CyclicSievingPolynomial(S42, cyc_act, order=11)\n Traceback (most recent call last):\n ...\n ValueError: order is not a multiple of the order of the cyclic action\n ' if cyc_act: orbits = orbit_decomposition(L, cyc_act) else: orbits = [list(range(k)) for k in L] R = PolynomialRing(ZZ, 'q') q = R.gen() p = R.zero() orbit_sizes = {} for orbit in orbits: length = len(orbit) if (length in orbit_sizes): orbit_sizes[length] += 1 else: orbit_sizes[length] = 1 n = lcm(orbit_sizes) if order: if order.mod(n): raise ValueError('order is not a multiple of the order of the cyclic action') else: order = n for i in range(n): if (i == 0): j = sum(orbit_sizes.values()) else: j = sum((orb for (l, orb) in orbit_sizes.items() if (not ZZ(i).mod((n // l))))) p += (j * (q ** i)) p = p((q ** (order // n))) return ([p, order] if get_order else p)
def CyclicSievingCheck(L, cyc_act, f, order=None) -> bool: '\n Return whether the triple ``(L, cyc_act, f)`` exhibits\n the cyclic sieving phenomenon.\n\n If ``cyc_act`` is None, ``L`` is expected to contain the orbit lengths.\n\n INPUT:\n\n - ``L`` -- if ``cyc_act`` is ``None``: list of orbit sizes,\n otherwise list of objects\n\n - ``cyc_act`` -- (default:``None``) bijective function from ``L`` to ``L``\n\n - ``order`` -- (default:``None``) if set to an integer, this\n cyclic order of ``cyc_act`` is used (must be an integer\n multiple of the order of ``cyc_act``) otherwise, the order of\n ``cyc_action`` is used\n\n EXAMPLES::\n\n sage: from sage.combinat.cyclic_sieving_phenomenon import *\n sage: from sage.combinat.q_analogues import q_binomial\n sage: S42 = Subsets([1,2,3,4], 2)\n sage: def cyc_act(S): return Set(i.mod(4) + 1 for i in S)\n sage: cyc_act([1,3])\n {2, 4}\n sage: cyc_act([1,4])\n {1, 2}\n sage: p = q_binomial(4,2); p\n q^4 + q^3 + 2*q^2 + q + 1\n sage: CyclicSievingPolynomial( S42, cyc_act )\n q^3 + 2*q^2 + q + 2\n sage: CyclicSievingCheck( S42, cyc_act, p )\n True\n ' (p1, n) = CyclicSievingPolynomial(L, cyc_act=cyc_act, order=order, get_order=True) R = p1.parent() q = R.gen() return (p1 == R(f).mod(((q ** n) - 1)))
def orbit_decomposition(L, cyc_act) -> list[list]: '\n Return the orbit decomposition of ``L`` by the action of ``cyc_act``.\n\n INPUT:\n\n - ``L`` -- list\n\n - ``cyc_act`` -- bijective function from ``L`` to ``L``\n\n OUTPUT:\n\n - a list of lists, the orbits under the cyc_act acting on ``L``\n\n EXAMPLES::\n\n sage: from sage.combinat.cyclic_sieving_phenomenon import *\n sage: S42 = Subsets([1,2,3,4], 2); S42\n Subsets of {1, 2, 3, 4} of size 2\n sage: def cyc_act(S): return Set(i.mod(4) + 1 for i in S)\n sage: cyc_act([1,3])\n {2, 4}\n sage: cyc_act([1,4])\n {1, 2}\n sage: orbits = orbit_decomposition(S42, cyc_act)\n sage: sorted([sorted(orb, key=sorted) for orb in orbits], key=len)\n [[{1, 3}, {2, 4}], [{1, 2}, {1, 4}, {2, 3}, {3, 4}]]\n ' orbits = [] L_prime = set(L) while L_prime: obj = L_prime.pop() orbit = [obj] obj = cyc_act(obj) while (obj in L_prime): orbit.append(obj) L_prime.remove(obj) obj = cyc_act(obj) orbits.append(orbit) return orbits
class DecoratedPermutation(ClonableArray, metaclass=InheritComparisonClasscallMetaclass): '\n A decorated permutation.\n\n A decorated permutation is a signed permutation where all\n non-fixed points have positive sign.\n ' @staticmethod def __classcall_private__(cls, pi): '\n Create a decorated permutation.\n\n EXAMPLES::\n\n sage: DecoratedPermutation([2, 1, 3])\n [2, 1, 3]\n\n sage: DecoratedPermutation([2, 1, -3])\n [2, 1, -3]\n\n TESTS:\n\n Check that hashing and comparison works::\n\n sage: S = DecoratedPermutations(3)\n sage: elt1 = S([2, 1, -3])\n sage: elt2 = DecoratedPermutation([2, 1, -3])\n sage: elt1 == elt2\n True\n\n sage: elt1 == [2, 1, -3]\n False\n\n sage: elt2 = DecoratedPermutation([2, 1, 3])\n sage: elt1 != elt2\n True\n\n sage: hash(elt1) # random\n 915443076393556996\n\n ' pi = list(pi) return DecoratedPermutations(len(pi))(pi) def __init__(self, parent, pi, check=True): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: S = DecoratedPermutations(3)\n sage: elt = S([2, 1, -3])\n sage: TestSuite(elt).run()\n ' ClonableArray.__init__(self, parent, pi, check=check) def check(self): '\n Check that ``self`` is a valid decorated permutation.\n\n EXAMPLES::\n\n sage: S = DecoratedPermutations(3)\n sage: elt = S([2, 1, -3])\n sage: elt.check()\n sage: elt = S([2, -1, 3])\n Traceback (most recent call last):\n ...\n ValueError: invalid decorated permutation\n ' if (self not in self.parent()): raise ValueError('{} is not a decorated permutation'.format(self)) def size(self): '\n Return the size of the decorated permutation.\n\n EXAMPLES::\n\n sage: DecoratedPermutation([2, 1, -3]).size()\n 3\n ' return len(self) def to_signed_permutation(self): '\n Return ``self`` as a signed permutation.\n\n EXAMPLES::\n\n sage: DecoratedPermutation([2, 1, -3]).to_signed_permutation()\n [2, 1, -3]\n ' return SignedPermutations(len(self))(list(self))
class DecoratedPermutations(UniqueRepresentation, Parent): '\n Class of all decorated permutations of `n`.\n\n A decorated permutation is a signed permutation where all\n non-fixed points have positive sign.\n\n INPUT:\n\n - `n` -- an integer, the size of the decorated permutations.\n\n EXAMPLES:\n\n This will create an instance to manipulate the decorated\n permutations of size 3::\n\n sage: S = DecoratedPermutations(3); S\n Decorated permutations of size 3\n sage: S.cardinality()\n 16\n\n ' def __init__(self, n): '\n Initialize ``self``.\n\n TESTS::\n\n sage: S = DecoratedPermutations(4)\n sage: TestSuite(S).run()\n ' self._n = n Parent.__init__(self, category=FiniteEnumeratedSets()) def _repr_(self): '\n Return a string representation of ``self``.\n\n TESTS::\n\n sage: DecoratedPermutations(4)\n Decorated permutations of size 4\n ' return ('Decorated permutations of size %s' % self._n) def __contains__(self, pi): '\n Check if ``pi`` is in ``self``.\n\n TESTS::\n\n sage: S = DecoratedPermutations(3)\n sage: [2, 1, -3] in S\n True\n sage: [2, -1, 3] in S\n False\n ' if isinstance(pi, DecoratedPermutation): return (len(pi) == self._n) values = [v for v in pi] if (len(values) != self._n): return False abs_values = [abs(v) for v in values] for (i, (v, abs_v)) in enumerate(zip(values, abs_values), 1): if ((i != abs_v) and (v < 0)): return False return (sorted(abs_values) == list(range(1, (self._n + 1)))) def _element_constructor_(self, pi, check=True): '\n Construct an element of ``self``.\n\n EXAMPLES::\n\n sage: S = DecoratedPermutations(3)\n sage: elt = S([2, 1, -3])\n sage: elt.parent() is S\n True\n ' if isinstance(pi, DecoratedPermutation): if (pi.parent() is self): return pi raise ValueError('cannot convert between decorated permutations of different sizes') pi = tuple(pi) if (check and (pi not in self)): raise ValueError('invalid decorated permutation') return self.element_class(self, pi) Element = DecoratedPermutation def _an_element_(self): '\n Return an element of ``self``.\n\n EXAMPLES::\n\n sage: S = DecoratedPermutations(3)\n sage: S._an_element_()\n [1, 2, 3]\n\n ' return self.element_class(self, list(range(1, (self._n + 1)))) def cardinality(self): '\n Return the cardinality of ``self``.\n\n The number of decorated permutations of size `n` is equal to\n\n .. MATH::\n\n \\sum_{k=0^n} \\frac{n!}{k!}\n\n EXAMPLES::\n\n sage: [DecoratedPermutations(n).cardinality() for n in range(11)]\n [1, 2, 5, 16, 65, 326, 1957, 13700, 109601, 986410, 9864101]\n ' return Integer(sum(((factorial(self._n) // factorial(k)) for k in range((self._n + 1))))) def __iter__(self): '\n Iterator on the decorated permutations of size `n`.\n\n TESTS::\n\n sage: S = DecoratedPermutations(2); S.list()\n [[1, 2], [-1, 2], [1, -2], [-1, -2], [2, 1]]\n sage: sum(1 for a in S)\n 5\n ' for sigma in Permutations(self._n): F = sigma.fixed_points() for X in Subsets(F): tau = list(sigma) for i in X: tau[(i - 1)] = (- tau[(i - 1)]) (yield DecoratedPermutations(self._n)(tau))
class Derangement(CombinatorialElement): '\n A derangement.\n\n A derangement on a set `S` is a permutation `\\sigma` such that `\\sigma(x)\n \\neq x` for all `x \\in S`, i.e. `\\sigma` is a permutation of `S` with no\n fixed points.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: elt = D([4,3,2,1])\n sage: TestSuite(elt).run()\n ' def to_permutation(self): "\n Return the permutation corresponding to ``self``.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: p = D([4,3,2,1]).to_permutation(); p\n [4, 3, 2, 1]\n sage: type(p)\n <class 'sage.combinat.permutation.StandardPermutations_all_with_category.element_class'>\n sage: D = Derangements([1, 3, 3, 4])\n sage: D[0].to_permutation()\n Traceback (most recent call last):\n ...\n ValueError: can only convert to a permutation for derangements of [1, 2, ..., n]\n " if (self.parent()._set != tuple(range(1, (len(self) + 1)))): raise ValueError('can only convert to a permutation for derangements of [1, 2, ..., n]') return Permutation(list(self))
class Derangements(UniqueRepresentation, Parent): '\n The class of all derangements of a set or multiset.\n\n A derangement on a set `S` is a permutation `\\sigma` such that `\\sigma(x)\n \\neq x` for all `x \\in S`, i.e. `\\sigma` is a permutation of `S` with no\n fixed points.\n\n For an integer, or a list or string with all elements\n distinct, the derangements are obtained by a standard result described\n in [BV2004]_. For a list or string with repeated elements, the derangements\n are formed by computing all permutations of the input and discarding all\n non-derangements.\n\n INPUT:\n\n - ``x`` -- Can be an integer which corresponds to derangements of\n `\\{1, 2, 3, \\ldots, x\\}`, a list, or a string\n\n REFERENCES:\n\n - [BV2004]_\n - :wikipedia:`Derangement`\n\n EXAMPLES::\n\n sage: D1 = Derangements([2,3,4,5])\n sage: D1.list()\n [[3, 4, 5, 2],\n [5, 4, 2, 3],\n [3, 5, 2, 4],\n [4, 5, 3, 2],\n [4, 2, 5, 3],\n [5, 2, 3, 4],\n [5, 4, 3, 2],\n [4, 5, 2, 3],\n [3, 2, 5, 4]]\n sage: D1.cardinality()\n 9\n sage: D1.random_element() # random\n [4, 2, 5, 3]\n sage: D2 = Derangements([1,2,3,1,2,3])\n sage: D2.cardinality()\n 10\n sage: D2.list()\n [[2, 1, 1, 3, 3, 2],\n [2, 1, 2, 3, 3, 1],\n [2, 3, 1, 2, 3, 1],\n [2, 3, 1, 3, 1, 2],\n [2, 3, 2, 3, 1, 1],\n [3, 1, 1, 2, 3, 2],\n [3, 1, 2, 2, 3, 1],\n [3, 1, 2, 3, 1, 2],\n [3, 3, 1, 2, 1, 2],\n [3, 3, 2, 2, 1, 1]]\n sage: D2.random_element() # random\n [2, 3, 1, 3, 1, 2]\n ' @staticmethod def __classcall_private__(cls, x): '\n Normalize ``x`` to ensure a unique representation.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: D2 = Derangements([1, 2, 3, 4])\n sage: D3 = Derangements((1, 2, 3, 4))\n sage: D is D2\n True\n sage: D is D3\n True\n ' if (x in ZZ): x = tuple(range(1, (x + 1))) return super().__classcall__(cls, tuple(x)) def __init__(self, x): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: TestSuite(D).run()\n sage: D = Derangements('abcd')\n sage: TestSuite(D).run()\n sage: D = Derangements([2, 2, 1, 1])\n sage: TestSuite(D).run()\n " Parent.__init__(self, category=FiniteEnumeratedSets()) self._set = x self.__multi = (len(set(x)) < len(x)) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: Derangements(4)\n Derangements of the set [1, 2, 3, 4]\n sage: Derangements('abcd')\n Derangements of the set ['a', 'b', 'c', 'd']\n sage: Derangements([2,2,1,1])\n Derangements of the multiset [2, 2, 1, 1]\n " if self.__multi: return ('Derangements of the multiset %s' % list(self._set)) return ('Derangements of the set %s' % list(self._set)) def _element_constructor_(self, der): '\n Construct an element of ``self`` from ``der``.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: elt = D([3,1,4,2]); elt\n [3, 1, 4, 2]\n sage: elt.parent() is D\n True\n ' if isinstance(der, Derangement): if (der.parent() is self): return der raise ValueError(('cannot convert %s to an element of %s' % (der, self))) return self.element_class(self, der) Element = Derangement def __iter__(self): "\n Iterate through ``self``.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: D.list() # indirect doctest\n [[2, 3, 4, 1],\n [4, 3, 1, 2],\n [2, 4, 1, 3],\n [3, 4, 2, 1],\n [3, 1, 4, 2],\n [4, 1, 2, 3],\n [4, 3, 2, 1],\n [3, 4, 1, 2],\n [2, 1, 4, 3]]\n sage: D = Derangements([1,44,918,67])\n sage: D.list()\n [[44, 918, 67, 1],\n [67, 918, 1, 44],\n [44, 67, 1, 918],\n [918, 67, 44, 1],\n [918, 1, 67, 44],\n [67, 1, 44, 918],\n [67, 918, 44, 1],\n [918, 67, 1, 44],\n [44, 1, 67, 918]]\n sage: D = Derangements(['A','AT','CAT','CATS'])\n sage: D.list()\n [['AT', 'CAT', 'CATS', 'A'],\n ['CATS', 'CAT', 'A', 'AT'],\n ['AT', 'CATS', 'A', 'CAT'],\n ['CAT', 'CATS', 'AT', 'A'],\n ['CAT', 'A', 'CATS', 'AT'],\n ['CATS', 'A', 'AT', 'CAT'],\n ['CATS', 'CAT', 'AT', 'A'],\n ['CAT', 'CATS', 'A', 'AT'],\n ['AT', 'A', 'CATS', 'CAT']]\n sage: D = Derangements('CART')\n sage: D.list()\n [['A', 'R', 'T', 'C'],\n ['T', 'R', 'C', 'A'],\n ['A', 'T', 'C', 'R'],\n ['R', 'T', 'A', 'C'],\n ['R', 'C', 'T', 'A'],\n ['T', 'C', 'A', 'R'],\n ['T', 'R', 'A', 'C'],\n ['R', 'T', 'C', 'A'],\n ['A', 'C', 'T', 'R']]\n sage: D = Derangements([1,1,2,2,3,3])\n sage: D.list()\n [[2, 2, 3, 3, 1, 1],\n [2, 3, 1, 3, 1, 2],\n [2, 3, 1, 3, 2, 1],\n [2, 3, 3, 1, 1, 2],\n [2, 3, 3, 1, 2, 1],\n [3, 2, 1, 3, 1, 2],\n [3, 2, 1, 3, 2, 1],\n [3, 2, 3, 1, 1, 2],\n [3, 2, 3, 1, 2, 1],\n [3, 3, 1, 1, 2, 2]]\n sage: D = Derangements('SATTAS')\n sage: D.list()\n [['A', 'S', 'S', 'A', 'T', 'T'],\n ['A', 'S', 'A', 'S', 'T', 'T'],\n ['A', 'T', 'S', 'S', 'T', 'A'],\n ['A', 'T', 'S', 'A', 'S', 'T'],\n ['A', 'T', 'A', 'S', 'S', 'T'],\n ['T', 'S', 'S', 'A', 'T', 'A'],\n ['T', 'S', 'A', 'S', 'T', 'A'],\n ['T', 'S', 'A', 'A', 'S', 'T'],\n ['T', 'T', 'S', 'A', 'S', 'A'],\n ['T', 'T', 'A', 'S', 'S', 'A']]\n sage: D = Derangements([1,1,2,2,2])\n sage: D.list()\n []\n " if self.__multi: for p in Permutations(self._set): if (not self._fixed_point(p)): (yield self.element_class(self, list(p))) else: for d in self._iter_der(len(self._set)): (yield self.element_class(self, [self._set[(i - 1)] for i in d])) def _iter_der(self, n): '\n Iterate through all derangements of the list `[1, 2, 3, \\ldots, n]`\n using the method given in [BV2004]_.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: list(D._iter_der(4))\n [[2, 3, 4, 1],\n [4, 3, 1, 2],\n [2, 4, 1, 3],\n [3, 4, 2, 1],\n [3, 1, 4, 2],\n [4, 1, 2, 3],\n [4, 3, 2, 1],\n [3, 4, 1, 2],\n [2, 1, 4, 3]]\n ' if (n <= 1): return elif (n == 2): (yield [2, 1]) elif (n == 3): (yield [2, 3, 1]) (yield [3, 1, 2]) elif (n >= 4): for d in self._iter_der((n - 1)): for i in range(1, n): s = d[:] ii = d.index(i) s[ii] = n (yield (s + [i])) for d in self._iter_der((n - 2)): for i in range(1, n): s = d[:] s = [(((x >= i) and (x + 1)) or x) for x in s] s.insert((i - 1), n) (yield (s + [i])) def _fixed_point(self, a): '\n Return ``True`` if ``a`` has a point in common with ``self._set``.\n\n EXAMPLES::\n\n sage: D = Derangements(5)\n sage: D._fixed_point([3,1,2,5,4])\n False\n sage: D._fixed_point([5,4,3,2,1])\n True\n ' return any(((x == y) for (x, y) in zip(a, self._set))) def _count_der(self, n): '\n Count the number of derangements of `n` using the recursion\n `D_2 = 1, D_3 = 2, D_n = (n-1) (D_{n-1} + D_{n-2})`.\n\n EXAMPLES::\n\n sage: D = Derangements(5)\n sage: D._count_der(2)\n 1\n sage: D._count_der(3)\n 2\n sage: D._count_der(5)\n 44\n ' if (n <= 1): return Integer(0) if (n == 2): return Integer(1) if (n == 3): return Integer(2) last = Integer(2) second_last = Integer(1) for i in range(4, (n + 1)): current = ((i - 1) * (last + second_last)) second_last = last last = current return last def cardinality(self): "\n Counts the number of derangements of a positive integer, a\n list, or a string. The list or string may contain repeated\n elements. If an integer `n` is given, the value returned\n is the number of derangements of `[1, 2, 3, \\ldots, n]`.\n\n For an integer, or a list or string with all elements\n distinct, the value is obtained by the standard result\n `D_2 = 1, D_3 = 2, D_n = (n-1) (D_{n-1} + D_{n-2})`.\n\n For a list or string with repeated elements, the number of\n derangements is computed by Macmahon's theorem. If the numbers\n of repeated elements are `a_1, a_2, \\ldots, a_k` then the number\n of derangements is given by the coefficient of `x_1 x_2 \\cdots\n x_k` in the expansion of `\\prod_{i=0}^k (S - s_i)^{a_i}` where\n `S = x_1 + x_2 + \\cdots + x_k`.\n\n EXAMPLES::\n\n sage: D = Derangements(5)\n sage: D.cardinality()\n 44\n sage: D = Derangements([1,44,918,67,254])\n sage: D.cardinality()\n 44\n sage: D = Derangements(['A','AT','CAT','CATS','CARTS'])\n sage: D.cardinality()\n 44\n sage: D = Derangements('UNCOPYRIGHTABLE')\n sage: D.cardinality()\n 481066515734\n sage: D = Derangements([1,1,2,2,3,3])\n sage: D.cardinality()\n 10\n sage: D = Derangements('SATTAS')\n sage: D.cardinality()\n 10\n sage: D = Derangements([1,1,2,2,2])\n sage: D.cardinality()\n 0\n " if self.__multi: sL = set(self._set) A = [self._set.count(i) for i in sL] R = PolynomialRing(QQ, 'x', len(A)) S = sum(R.gens()) e = prod((((S - x) ** y) for (x, y) in zip(R.gens(), A))) return Integer(e.coefficient(dict([(x, y) for (x, y) in zip(R.gens(), A)]))) return self._count_der(len(self._set)) def _rand_der(self): '\n Produces a random derangement of `[1, 2, \\ldots, n]`.\n\n This is an\n implementation of the algorithm described by Martinez et. al. in\n [MPP2008]_.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: d = D._rand_der()\n sage: d in D\n True\n ' n = len(self._set) A = list(range(1, (n + 1))) mark = [(x < 0) for x in A] (i, u) = (n, n) while (u >= 2): if (not mark[(i - 1)]): while True: j = randrange(1, i) if (not mark[(j - 1)]): (A[(i - 1)], A[(j - 1)]) = (A[(j - 1)], A[(i - 1)]) break p = random() if (p < (((u - 1) * self._count_der((u - 2))) // self._count_der(u))): mark[(j - 1)] = True u -= 1 u -= 1 i -= 1 return A def random_element(self): "\n Produce all derangements of a positive integer, a list, or\n a string. The list or string may contain repeated elements.\n If an integer `n` is given, then a random\n derangements of `[1, 2, 3, \\ldots, n]` is returned\n\n For an integer, or a list or string with all elements\n distinct, the value is obtained by an algorithm described in\n [MPP2008]_. For a list or string with repeated elements the\n derangement is formed by choosing an element at random from the list of\n all possible derangements.\n\n OUTPUT:\n\n A single list or string containing a derangement, or an\n empty list if there are no derangements.\n\n EXAMPLES::\n\n sage: D = Derangements(4)\n sage: D.random_element() # random\n [2, 3, 4, 1]\n sage: D = Derangements(['A','AT','CAT','CATS','CARTS','CARETS'])\n sage: D.random_element() # random\n ['AT', 'CARTS', 'A', 'CAT', 'CARETS', 'CATS']\n sage: D = Derangements('UNCOPYRIGHTABLE')\n sage: D.random_element() # random\n ['C', 'U', 'I', 'H', 'O', 'G', 'N', 'B', 'E', 'L', 'A', 'R', 'P', 'Y', 'T']\n sage: D = Derangements([1,1,1,1,2,2,2,2,3,3,3,3])\n sage: D.random_element() # random\n [3, 2, 2, 3, 1, 3, 1, 3, 2, 1, 1, 2]\n sage: D = Derangements('ESSENCES')\n sage: D.random_element() # random\n ['N', 'E', 'E', 'C', 'S', 'S', 'S', 'E']\n sage: D = Derangements([1,1,2,2,2])\n sage: D.random_element()\n []\n\n TESTS:\n\n Check that index error discovered in :trac:`29974` is fixed::\n\n sage: D = Derangements([1,1,2,2])\n sage: _ = [D.random_element() for _ in range(20)]\n " if self.__multi: L = list(self) if (len(L) == 0): return self.element_class(self, []) i = randrange(len(L)) return L[i] temp = self._rand_der() return self.element_class(self, [self._set[(ii - 1)] for ii in temp])
class DescentAlgebra(UniqueRepresentation, Parent): "\n Solomon's descent algebra.\n\n The descent algebra `\\Sigma_n` over a ring `R` is a subalgebra of the\n symmetric group algebra `R S_n`. (The product in the latter algebra\n is defined by `(pq)(i) = q(p(i))` for any two permutations `p` and\n `q` in `S_n` and every `i \\in \\{ 1, 2, \\ldots, n \\}`. The algebra\n `\\Sigma_n` inherits this product.)\n\n There are three bases currently implemented for `\\Sigma_n`:\n\n - the standard basis `D_S` of (sums of) descent classes, indexed by\n subsets `S` of `\\{1, 2, \\ldots, n-1\\}`,\n - the subset basis `B_p`, indexed by compositions `p` of `n`,\n - the idempotent basis `I_p`, indexed by compositions `p` of `n`,\n which is used to construct the mutually orthogonal idempotents\n of the symmetric group algebra.\n\n The idempotent basis is only defined when `R` is a `\\QQ`-algebra.\n\n We follow the notations and conventions in [GR1989]_, apart from the\n order of multiplication being different from the one used in that\n article. Schocker's exposition [Sch2004]_, in turn, uses the\n same order of multiplication as we are, but has different notations\n for the bases.\n\n INPUT:\n\n - ``R`` -- the base ring\n\n - ``n`` -- a nonnegative integer\n\n REFERENCES:\n\n - [GR1989]_\n\n - [At1992]_\n\n - [MR1995]_\n\n - [Sch2004]_\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: D = DA.D(); D\n Descent algebra of 4 over Rational Field in the standard basis\n sage: B = DA.B(); B\n Descent algebra of 4 over Rational Field in the subset basis\n sage: I = DA.I(); I\n Descent algebra of 4 over Rational Field in the idempotent basis\n sage: basis_B = B.basis()\n sage: elt = basis_B[Composition([1,2,1])] + 4*basis_B[Composition([1,3])]; elt\n B[1, 2, 1] + 4*B[1, 3]\n sage: D(elt)\n 5*D{} + 5*D{1} + D{1, 3} + D{3}\n sage: I(elt)\n 7/6*I[1, 1, 1, 1] + 2*I[1, 1, 2] + 3*I[1, 2, 1] + 4*I[1, 3]\n\n\n As syntactic sugar, one can use the notation ``D[i,...,l]`` to\n construct elements of the basis; note that for the empty set one\n must use ``D[[]]`` due to Python's syntax::\n\n sage: D[[]] + D[2] + 2*D[1,2]\n D{} + 2*D{1, 2} + D{2}\n\n The same syntax works for the other bases::\n\n sage: I[1,2,1] + 3*I[4] + 2*I[3,1]\n I[1, 2, 1] + 2*I[3, 1] + 3*I[4]\n\n TESTS:\n\n We check that we can go back and forth between our bases::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: D = DA.D()\n sage: B = DA.B()\n sage: I = DA.I()\n sage: all(D(B(b)) == b for b in D.basis())\n True\n sage: all(D(I(b)) == b for b in D.basis())\n True\n sage: all(B(D(b)) == b for b in B.basis())\n True\n sage: all(B(I(b)) == b for b in B.basis())\n True\n sage: all(I(D(b)) == b for b in I.basis())\n True\n sage: all(I(B(b)) == b for b in I.basis())\n True\n " def __init__(self, R, n): '\n EXAMPLES::\n\n sage: TestSuite(DescentAlgebra(QQ, 4)).run()\n ' self._n = n self._category = FiniteDimensionalAlgebrasWithBasis(R) Parent.__init__(self, base=R, category=self._category.WithRealizations()) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: DescentAlgebra(QQ, 4)\n Descent algebra of 4 over Rational Field\n ' return 'Descent algebra of {0} over {1}'.format(self._n, self.base_ring()) def a_realization(self): '\n Return a particular realization of ``self`` (the `B`-basis).\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: DA.a_realization()\n Descent algebra of 4 over Rational Field in the subset basis\n ' return self.B() class D(CombinatorialFreeModule, BindableClass): '\n The standard basis of a descent algebra.\n\n This basis is indexed by `S \\subseteq \\{1, 2, \\ldots, n-1\\}`,\n and the basis vector indexed by `S` is the sum of all permutations,\n taken in the symmetric group algebra `R S_n`, whose descent set is `S`.\n We denote this basis vector by `D_S`.\n\n Occasionally this basis appears in literature but indexed by\n compositions of `n` rather than subsets of\n `\\{1, 2, \\ldots, n-1\\}`. The equivalence between these two\n indexings is owed to the bijection from the power set of\n `\\{1, 2, \\ldots, n-1\\}` to the set of all compositions of `n`\n which sends every subset `\\{i_1, i_2, \\ldots, i_k\\}` of\n `\\{1, 2, \\ldots, n-1\\}` (with `i_1 < i_2 < \\cdots < i_k`) to\n the composition `(i_1, i_2-i_1, \\ldots, i_k-i_{k-1}, n-i_k)`.\n\n The basis element corresponding to a composition `p` (or to\n the subset of `\\{1, 2, \\ldots, n-1\\}`) is denoted `\\Delta^p`\n in [Sch2004]_.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: D = DA.D()\n sage: list(D.basis())\n [D{}, D{1}, D{2}, D{3}, D{1, 2}, D{1, 3}, D{2, 3}, D{1, 2, 3}]\n\n sage: DA = DescentAlgebra(QQ, 0)\n sage: D = DA.D()\n sage: list(D.basis())\n [D{}]\n ' def __init__(self, alg, prefix='D'): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: TestSuite(DescentAlgebra(QQ, 4).D()).run()\n ' self._prefix = prefix self._basis_name = 'standard' CombinatorialFreeModule.__init__(self, alg.base_ring(), SubsetsSorted(range(1, alg._n)), category=DescentAlgebraBases(alg), bracket='', prefix=prefix) B = alg.B() self.module_morphism(self.to_B_basis, codomain=B, category=self.category()).register_as_coercion() B.module_morphism(B.to_D_basis, codomain=self, category=self.category()).register_as_coercion() def _element_constructor_(self, x): '\n Construct an element of ``self``.\n\n EXAMPLES::\n\n sage: D = DescentAlgebra(QQ, 4).D()\n sage: D([1, 3])\n D{1, 3}\n ' if isinstance(x, (list, set)): x = tuple(x) if isinstance(x, tuple): return self.monomial(x) return CombinatorialFreeModule._element_constructor_(self, x) def _repr_term(self, S): "\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: DA.D()._repr_term((1, 3))\n 'D{1, 3}'\n " return (((self._prefix + '{') + repr(list(S))[1:(- 1)]) + '}') def product_on_basis(self, S, T): '\n Return `D_S D_T`, where `S` and `T` are subsets of `[n-1]`.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: D = DA.D()\n sage: D.product_on_basis((1, 3), (2,))\n D{} + D{1} + D{1, 2} + 2*D{1, 2, 3} + D{1, 3} + D{2} + D{2, 3} + D{3}\n ' return self((self.to_B_basis(S) * self.to_B_basis(T))) @cached_method def one_basis(self): '\n Return the identity element, as per\n ``AlgebrasWithBasis.ParentMethods.one_basis``.\n\n EXAMPLES::\n\n sage: DescentAlgebra(QQ, 4).D().one_basis()\n ()\n sage: DescentAlgebra(QQ, 0).D().one_basis()\n ()\n\n sage: all( U * DescentAlgebra(QQ, 3).D().one() == U\n ....: for U in DescentAlgebra(QQ, 3).D().basis() )\n True\n ' return tuple() @cached_method def to_B_basis(self, S): '\n Return `D_S` as a linear combination of `B_p`-basis elements.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: D = DA.D()\n sage: B = DA.B()\n sage: list(map(B, D.basis())) # indirect doctest\n [B[4],\n B[1, 3] - B[4],\n B[2, 2] - B[4],\n B[3, 1] - B[4],\n B[1, 1, 2] - B[1, 3] - B[2, 2] + B[4],\n B[1, 2, 1] - B[1, 3] - B[3, 1] + B[4],\n B[2, 1, 1] - B[2, 2] - B[3, 1] + B[4],\n B[1, 1, 1, 1] - B[1, 1, 2] - B[1, 2, 1] + B[1, 3]\n - B[2, 1, 1] + B[2, 2] + B[3, 1] - B[4]]\n ' B = self.realization_of().B() if (not S): return B.one() n = self.realization_of()._n C = Compositions(n) return B.sum_of_terms([(C.from_subset(T, n), ((- 1) ** (len(S) - len(T)))) for T in SubsetsSorted(S)]) def to_symmetric_group_algebra_on_basis(self, S): '\n Return `D_S` as a linear combination of basis elements in the\n symmetric group algebra.\n\n EXAMPLES::\n\n sage: D = DescentAlgebra(QQ, 4).D()\n sage: [D.to_symmetric_group_algebra_on_basis(tuple(b))\n ....: for b in Subsets(3)]\n [[1, 2, 3, 4],\n [2, 1, 3, 4] + [3, 1, 2, 4] + [4, 1, 2, 3],\n [1, 3, 2, 4] + [1, 4, 2, 3] + [2, 3, 1, 4]\n + [2, 4, 1, 3] + [3, 4, 1, 2],\n [1, 2, 4, 3] + [1, 3, 4, 2] + [2, 3, 4, 1],\n [3, 2, 1, 4] + [4, 2, 1, 3] + [4, 3, 1, 2],\n [2, 1, 4, 3] + [3, 1, 4, 2] + [3, 2, 4, 1]\n + [4, 1, 3, 2] + [4, 2, 3, 1],\n [1, 4, 3, 2] + [2, 4, 3, 1] + [3, 4, 2, 1],\n [4, 3, 2, 1]]\n ' n = self.realization_of()._n SGA = SymmetricGroupAlgebra(self.base_ring(), n) P = Permutations(descents=([(x - 1) for x in S], n)) return SGA.sum_of_terms([(p, 1) for p in P]) def __getitem__(self, S): '\n Return the basis element indexed by ``S``.\n\n INPUT:\n\n - ``S`` -- a subset of `[n-1]`\n\n EXAMPLES::\n\n sage: D = DescentAlgebra(QQ, 4).D()\n sage: D[3]\n D{3}\n sage: D[1, 3]\n D{1, 3}\n sage: D[[]]\n D{}\n\n TESTS::\n\n sage: D = DescentAlgebra(QQ, 0).D()\n sage: D[[]]\n D{}\n ' n = self.realization_of()._n if (S in ZZ): if ((S >= n) or (S <= 0)): raise ValueError('({0},) is not a subset of {{1, ..., {1}}}'.format(S, (n - 1))) return self.monomial((S,)) if (not S): return self.one() S = sorted(S) if ((S[(- 1)] >= n) or (S[0] <= 0)): raise ValueError('{0} is not a subset of {{1, ..., {1}}}'.format(S, (n - 1))) return self.monomial(tuple(S)) standard = D class B(CombinatorialFreeModule, BindableClass): '\n The subset basis of a descent algebra (indexed by compositions).\n\n The subset basis `(B_S)_{S \\subseteq \\{1, 2, \\ldots, n-1\\}}` of\n `\\Sigma_n` is formed by\n\n .. MATH::\n\n B_S = \\sum_{T \\subseteq S} D_T,\n\n where `(D_S)_{S \\subseteq \\{1, 2, \\ldots, n-1\\}}` is the\n :class:`standard basis <DescentAlgebra.D>`. However it is more\n natural to index the subset basis by compositions\n of `n` under the bijection `\\{i_1, i_2, \\ldots, i_k\\} \\mapsto\n (i_1, i_2 - i_1, i_3 - i_2, \\ldots, i_k - i_{k-1}, n - i_k)`\n (where `i_1 < i_2 < \\cdots < i_k`), which is what Sage uses to\n index the basis.\n\n The basis element `B_p` is denoted `\\Xi^p` in [Sch2004]_.\n\n By using compositions of `n`, the product `B_p B_q` becomes a\n sum over the non-negative-integer matrices `M` with row sum `p`\n and column sum `q`. The summand corresponding to `M` is `B_c`,\n where `c` is the composition obtained by reading `M` row-by-row\n from left-to-right and top-to-bottom and removing all zeroes.\n This multiplication rule is commonly called "Solomon\'s Mackey\n formula".\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: B = DA.B()\n sage: list(B.basis())\n [B[1, 1, 1, 1], B[1, 1, 2], B[1, 2, 1], B[1, 3],\n B[2, 1, 1], B[2, 2], B[3, 1], B[4]]\n ' def __init__(self, alg, prefix='B'): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: TestSuite(DescentAlgebra(QQ, 4).B()).run()\n ' self._prefix = prefix self._basis_name = 'subset' CombinatorialFreeModule.__init__(self, alg.base_ring(), Compositions(alg._n), category=DescentAlgebraBases(alg), bracket='', prefix=prefix) S = NonCommutativeSymmetricFunctions(alg.base_ring()).Complete() self.module_morphism(self.to_nsym, codomain=S, category=Algebras(alg.base_ring())).register_as_coercion() def product_on_basis(self, p, q): '\n Return `B_p B_q`, where `p` and `q` are compositions of `n`.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: B = DA.B()\n sage: p = Composition([1,2,1])\n sage: q = Composition([3,1])\n sage: B.product_on_basis(p, q)\n B[1, 1, 1, 1] + 2*B[1, 2, 1]\n ' IM = IntegerMatrices(list(p), list(q)) P = Compositions(self.realization_of()._n) def to_composition(m): return P([x for x in m.list() if (x != 0)]) return self.sum_of_monomials([to_composition(mat) for mat in IM]) @cached_method def one_basis(self): '\n Return the identity element which is the composition `[n]`, as per\n ``AlgebrasWithBasis.ParentMethods.one_basis``.\n\n EXAMPLES::\n\n sage: DescentAlgebra(QQ, 4).B().one_basis()\n [4]\n sage: DescentAlgebra(QQ, 0).B().one_basis()\n []\n\n sage: all( U * DescentAlgebra(QQ, 3).B().one() == U\n ....: for U in DescentAlgebra(QQ, 3).B().basis() )\n True\n ' n = self.realization_of()._n P = Compositions(n) if (not n): return P([]) return P([n]) @cached_method def to_I_basis(self, p): '\n Return `B_p` as a linear combination of `I`-basis elements.\n\n This is done using the formula\n\n .. MATH::\n\n B_p = \\sum_{q \\leq p} \\frac{1}{\\mathbf{k}!(q,p)} I_q,\n\n where `\\leq` is the refinement order and `\\mathbf{k}!(q,p)` is\n defined as follows: When `q \\leq p`, we can write `q` as a\n concatenation `q_{(1)} q_{(2)} \\cdots q_{(k)}` with each `q_{(i)}`\n being a composition of the `i`-th entry of `p`, and then\n we set `\\mathbf{k}!(q,p)` to be\n `l(q_{(1)})! l(q_{(2)})! \\cdots l(q_{(k)})!`, where `l(r)`\n denotes the number of parts of any composition `r`.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: B = DA.B()\n sage: I = DA.I()\n sage: list(map(I, B.basis())) # indirect doctest\n [I[1, 1, 1, 1],\n 1/2*I[1, 1, 1, 1] + I[1, 1, 2],\n 1/2*I[1, 1, 1, 1] + I[1, 2, 1],\n 1/6*I[1, 1, 1, 1] + 1/2*I[1, 1, 2] + 1/2*I[1, 2, 1] + I[1, 3],\n 1/2*I[1, 1, 1, 1] + I[2, 1, 1],\n 1/4*I[1, 1, 1, 1] + 1/2*I[1, 1, 2] + 1/2*I[2, 1, 1] + I[2, 2],\n 1/6*I[1, 1, 1, 1] + 1/2*I[1, 2, 1] + 1/2*I[2, 1, 1] + I[3, 1],\n 1/24*I[1, 1, 1, 1] + 1/6*I[1, 1, 2] + 1/6*I[1, 2, 1]\n + 1/2*I[1, 3] + 1/6*I[2, 1, 1] + 1/2*I[2, 2] + 1/2*I[3, 1] + I[4]]\n ' I = self.realization_of().I() def coeff(p, q): ret = QQ.one() last = 0 for val in p: count = 0 s = 0 while (s != val): s += q[(last + count)] count += 1 ret /= factorial(count) last += count return ret return I.sum_of_terms([(q, coeff(p, q)) for q in p.finer()]) @cached_method def to_D_basis(self, p): '\n Return `B_p` as a linear combination of `D`-basis elements.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: B = DA.B()\n sage: D = DA.D()\n sage: list(map(D, B.basis())) # indirect doctest\n [D{} + D{1} + D{1, 2} + D{1, 2, 3}\n + D{1, 3} + D{2} + D{2, 3} + D{3},\n D{} + D{1} + D{1, 2} + D{2},\n D{} + D{1} + D{1, 3} + D{3},\n D{} + D{1},\n D{} + D{2} + D{2, 3} + D{3},\n D{} + D{2},\n D{} + D{3},\n D{}]\n\n TESTS:\n\n Check to make sure the empty case is handled correctly::\n\n sage: DA = DescentAlgebra(QQ, 0)\n sage: B = DA.B()\n sage: D = DA.D()\n sage: list(map(D, B.basis()))\n [D{}]\n ' D = self.realization_of().D() if (not p): return D.one() return D.sum_of_terms([(tuple(sorted(s)), 1) for s in p.to_subset().subsets()]) def to_nsym(self, p): '\n Return `B_p` as an element in `NSym`, the non-commutative\n symmetric functions.\n\n This maps `B_p` to `S_p` where `S` denotes the Complete basis of\n `NSym`.\n\n EXAMPLES::\n\n sage: B = DescentAlgebra(QQ, 4).B()\n sage: S = NonCommutativeSymmetricFunctions(QQ).Complete()\n sage: list(map(S, B.basis())) # indirect doctest\n [S[1, 1, 1, 1],\n S[1, 1, 2],\n S[1, 2, 1],\n S[1, 3],\n S[2, 1, 1],\n S[2, 2],\n S[3, 1],\n S[4]]\n ' S = NonCommutativeSymmetricFunctions(self.base_ring()).Complete() return S.monomial(p) subset = B class I(CombinatorialFreeModule, BindableClass): '\n The idempotent basis of a descent algebra.\n\n The idempotent basis `(I_p)_{p \\models n}` is a basis for `\\Sigma_n`\n whenever the ground ring is a `\\QQ`-algebra. One way to compute it\n is using the formula (Theorem 3.3 in [GR1989]_)\n\n .. MATH::\n\n I_p = \\sum_{q \\leq p}\n \\frac{(-1)^{l(q)-l(p)}}{\\mathbf{k}(q,p)} B_q,\n\n where `\\leq` is the refinement order and `l(r)` denotes the number\n of parts of any composition `r`, and where `\\mathbf{k}(q,p)` is\n defined as follows: When `q \\leq p`, we can write `q` as a\n concatenation `q_{(1)} q_{(2)} \\cdots q_{(k)}` with each `q_{(i)}`\n being a composition of the `i`-th entry of `p`, and then\n we set `\\mathbf{k}(q,p)` to be the product\n `l(q_{(1)}) l(q_{(2)}) \\cdots l(q_{(k)})`.\n\n Let `\\lambda(p)` denote the partition obtained from a composition\n `p` by sorting. This basis is called the idempotent basis since for\n any `q` such that `\\lambda(p) = \\lambda(q)`, we have:\n\n .. MATH::\n\n I_p I_q = s(\\lambda) I_p\n\n where `\\lambda` denotes `\\lambda(p) = \\lambda(q)`, and where\n `s(\\lambda)` is the stabilizer of `\\lambda` in `S_n`. (This is\n part of Theorem 4.2 in [GR1989]_.)\n\n It is also straightforward to compute the idempotents `E_{\\lambda}`\n for the symmetric group algebra by the formula\n (Theorem 3.2 in [GR1989]_):\n\n .. MATH::\n\n E_{\\lambda} = \\frac{1}{k!} \\sum_{\\lambda(p) = \\lambda} I_p.\n\n .. NOTE::\n\n The basis elements are not orthogonal idempotents.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: I = DA.I()\n sage: list(I.basis())\n [I[1, 1, 1, 1], I[1, 1, 2], I[1, 2, 1], I[1, 3], I[2, 1, 1], I[2, 2], I[3, 1], I[4]]\n ' def __init__(self, alg, prefix='I'): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: TestSuite(DescentAlgebra(QQ, 4).B()).run()\n ' self._prefix = prefix self._basis_name = 'idempotent' CombinatorialFreeModule.__init__(self, alg.base_ring(), Compositions(alg._n), category=DescentAlgebraBases(alg), bracket='', prefix=prefix) B = alg.B() self.module_morphism(self.to_B_basis, codomain=B, category=self.category()).register_as_coercion() B.module_morphism(B.to_I_basis, codomain=self, category=self.category()).register_as_coercion() def product_on_basis(self, p, q): '\n Return `I_p I_q`, where `p` and `q` are compositions of `n`.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: I = DA.I()\n sage: p = Composition([1,2,1])\n sage: q = Composition([3,1])\n sage: I.product_on_basis(p, q)\n 0\n sage: I.product_on_basis(p, p)\n 2*I[1, 2, 1]\n ' return self((self.to_B_basis(p) * self.to_B_basis(q))) @cached_method def one(self): '\n Return the identity element, which is `B_{[n]}`, in the `I` basis.\n\n EXAMPLES::\n\n sage: DescentAlgebra(QQ, 4).I().one()\n 1/24*I[1, 1, 1, 1] + 1/6*I[1, 1, 2] + 1/6*I[1, 2, 1]\n + 1/2*I[1, 3] + 1/6*I[2, 1, 1] + 1/2*I[2, 2]\n + 1/2*I[3, 1] + I[4]\n sage: DescentAlgebra(QQ, 0).I().one()\n I[]\n\n TESTS::\n\n sage: all( U * DescentAlgebra(QQ, 3).I().one() == U\n ....: for U in DescentAlgebra(QQ, 3).I().basis() )\n True\n ' B = self.realization_of().B() return B.to_I_basis(B.one_basis()) def one_basis(self): '\n The element `1` is not (generally) a basis vector in the `I`\n basis, thus this raises a :class:`TypeError`.\n\n EXAMPLES::\n\n sage: DescentAlgebra(QQ, 4).I().one_basis()\n Traceback (most recent call last):\n ...\n TypeError: 1 is not a basis element in the I basis\n ' raise TypeError('1 is not a basis element in the I basis') @cached_method def to_B_basis(self, p): '\n Return `I_p` as a linear combination of `B`-basis elements.\n\n This is computed using the formula (Theorem 3.3 in [GR1989]_)\n\n .. MATH::\n\n I_p = \\sum_{q \\leq p}\n \\frac{(-1)^{l(q)-l(p)}}{\\mathbf{k}(q,p)} B_q,\n\n where `\\leq` is the refinement order and `l(r)` denotes the number\n of parts of any composition `r`, and where `\\mathbf{k}(q,p)` is\n defined as follows: When `q \\leq p`, we can write `q` as a\n concatenation `q_{(1)} q_{(2)} \\cdots q_{(k)}` with each `q_{(i)}`\n being a composition of the `i`-th entry of `p`, and then\n we set `\\mathbf{k}(q,p)` to be\n `l(q_{(1)}) l(q_{(2)}) \\cdots l(q_{(k)})`.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: B = DA.B()\n sage: I = DA.I()\n sage: list(map(B, I.basis())) # indirect doctest\n [B[1, 1, 1, 1],\n -1/2*B[1, 1, 1, 1] + B[1, 1, 2],\n -1/2*B[1, 1, 1, 1] + B[1, 2, 1],\n 1/3*B[1, 1, 1, 1] - 1/2*B[1, 1, 2] - 1/2*B[1, 2, 1] + B[1, 3],\n -1/2*B[1, 1, 1, 1] + B[2, 1, 1],\n 1/4*B[1, 1, 1, 1] - 1/2*B[1, 1, 2] - 1/2*B[2, 1, 1] + B[2, 2],\n 1/3*B[1, 1, 1, 1] - 1/2*B[1, 2, 1] - 1/2*B[2, 1, 1] + B[3, 1],\n -1/4*B[1, 1, 1, 1] + 1/3*B[1, 1, 2] + 1/3*B[1, 2, 1]\n - 1/2*B[1, 3] + 1/3*B[2, 1, 1] - 1/2*B[2, 2]\n - 1/2*B[3, 1] + B[4]]\n ' B = self.realization_of().B() def coeff(p, q): ret = QQ.one() last = 0 for val in p: count = 0 s = 0 while (s != val): s += q[(last + count)] count += 1 ret /= count last += count if ((len(q) - len(p)) % 2): ret = (- ret) return ret return B.sum_of_terms([(q, coeff(p, q)) for q in p.finer()]) def idempotent(self, la): '\n Return the idempotent corresponding to the partition ``la``\n of `n`.\n\n EXAMPLES::\n\n sage: I = DescentAlgebra(QQ, 4).I()\n sage: E = I.idempotent([3,1]); E\n 1/2*I[1, 3] + 1/2*I[3, 1]\n sage: E*E == E\n True\n sage: E2 = I.idempotent([2,1,1]); E2\n 1/6*I[1, 1, 2] + 1/6*I[1, 2, 1] + 1/6*I[2, 1, 1]\n sage: E2*E2 == E2\n True\n sage: E*E2 == I.zero()\n True\n ' from sage.combinat.permutation import Permutations k = len(la) C = Compositions(self.realization_of()._n) return self.sum_of_terms([(C(x), QQ((1, factorial(k)))) for x in Permutations(la)]) idempotent = I
class DescentAlgebraBases(Category_realization_of_parent): '\n The category of bases of a descent algebra.\n ' def __init__(self, base): '\n Initialize the bases of a descent algebra.\n\n INPUT:\n\n - ``base`` -- a descent algebra\n\n TESTS::\n\n sage: from sage.combinat.descent_algebra import DescentAlgebraBases\n sage: DA = DescentAlgebra(QQ, 4)\n sage: bases = DescentAlgebraBases(DA)\n sage: DA.B() in bases\n True\n ' Category_realization_of_parent.__init__(self, base) def _repr_(self): '\n Return the representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.combinat.descent_algebra import DescentAlgebraBases\n sage: DA = DescentAlgebra(QQ, 4)\n sage: DescentAlgebraBases(DA)\n Category of bases of Descent algebra of 4 over Rational Field\n ' return 'Category of bases of {}'.format(self.base()) def super_categories(self): '\n The super categories of ``self``.\n\n EXAMPLES::\n\n sage: from sage.combinat.descent_algebra import DescentAlgebraBases\n sage: DA = DescentAlgebra(QQ, 4)\n sage: bases = DescentAlgebraBases(DA)\n sage: bases.super_categories()\n [Category of finite dimensional algebras with basis over Rational Field,\n Category of realizations of Descent algebra of 4 over Rational Field]\n ' return [self.base()._category, Realizations(self.base())] class ParentMethods(): def _repr_(self): '\n Text representation of this basis of a descent algebra.\n\n EXAMPLES::\n\n sage: DA = DescentAlgebra(QQ, 4)\n sage: DA.B()\n Descent algebra of 4 over Rational Field in the subset basis\n sage: DA.D()\n Descent algebra of 4 over Rational Field in the standard basis\n sage: DA.I()\n Descent algebra of 4 over Rational Field in the idempotent basis\n ' return '{} in the {} basis'.format(self.realization_of(), self._basis_name) def __getitem__(self, p): '\n Return the basis element indexed by ``p``.\n\n INPUT:\n\n - ``p`` -- a composition\n\n EXAMPLES::\n\n sage: B = DescentAlgebra(QQ, 4).B()\n sage: B[Composition([4])]\n B[4]\n sage: B[1,2,1]\n B[1, 2, 1]\n sage: B[4]\n B[4]\n sage: B[[3,1]]\n B[3, 1]\n ' C = Compositions(self.realization_of()._n) if (p in C): return self.monomial(C(p)) if (not p): return self.one() if (not isinstance(p, tuple)): p = [p] return self.monomial(C(p)) def is_field(self, proof=True): '\n Return whether this descent algebra is a field.\n\n EXAMPLES::\n\n sage: B = DescentAlgebra(QQ, 4).B()\n sage: B.is_field()\n False\n sage: B = DescentAlgebra(QQ, 1).B()\n sage: B.is_field()\n True\n ' if (self.realization_of()._n <= 1): return self.base_ring().is_field() return False def is_commutative(self): '\n Return whether this descent algebra is commutative.\n\n EXAMPLES::\n\n sage: B = DescentAlgebra(QQ, 4).B()\n sage: B.is_commutative()\n False\n sage: B = DescentAlgebra(QQ, 1).B()\n sage: B.is_commutative()\n True\n ' return (self.base_ring().is_commutative() and (self.realization_of()._n <= 2)) @lazy_attribute def to_symmetric_group_algebra(self): '\n Morphism from ``self`` to the symmetric group algebra.\n\n EXAMPLES::\n\n sage: D = DescentAlgebra(QQ, 4).D()\n sage: D.to_symmetric_group_algebra(D[1,3])\n [2, 1, 4, 3] + [3, 1, 4, 2] + [3, 2, 4, 1] + [4, 1, 3, 2] + [4, 2, 3, 1]\n sage: B = DescentAlgebra(QQ, 4).B()\n sage: B.to_symmetric_group_algebra(B[1,2,1])\n [1, 2, 3, 4] + [1, 2, 4, 3] + [1, 3, 4, 2] + [2, 1, 3, 4]\n + [2, 1, 4, 3] + [2, 3, 4, 1] + [3, 1, 2, 4] + [3, 1, 4, 2]\n + [3, 2, 4, 1] + [4, 1, 2, 3] + [4, 1, 3, 2] + [4, 2, 3, 1]\n ' SGA = SymmetricGroupAlgebra(self.base_ring(), self.realization_of()._n) return self.module_morphism(self.to_symmetric_group_algebra_on_basis, codomain=SGA) def to_symmetric_group_algebra_on_basis(self, S): '\n Return the basis element index by ``S`` as a linear combination\n of basis elements in the symmetric group algebra.\n\n EXAMPLES::\n\n sage: B = DescentAlgebra(QQ, 3).B()\n sage: [B.to_symmetric_group_algebra_on_basis(c)\n ....: for c in Compositions(3)]\n [[1, 2, 3] + [1, 3, 2] + [2, 1, 3]\n + [2, 3, 1] + [3, 1, 2] + [3, 2, 1],\n [1, 2, 3] + [2, 1, 3] + [3, 1, 2],\n [1, 2, 3] + [1, 3, 2] + [2, 3, 1],\n [1, 2, 3]]\n sage: I = DescentAlgebra(QQ, 3).I()\n sage: [I.to_symmetric_group_algebra_on_basis(c)\n ....: for c in Compositions(3)]\n [[1, 2, 3] + [1, 3, 2] + [2, 1, 3] + [2, 3, 1]\n + [3, 1, 2] + [3, 2, 1],\n 1/2*[1, 2, 3] - 1/2*[1, 3, 2] + 1/2*[2, 1, 3]\n - 1/2*[2, 3, 1] + 1/2*[3, 1, 2] - 1/2*[3, 2, 1],\n 1/2*[1, 2, 3] + 1/2*[1, 3, 2] - 1/2*[2, 1, 3]\n + 1/2*[2, 3, 1] - 1/2*[3, 1, 2] - 1/2*[3, 2, 1],\n 1/3*[1, 2, 3] - 1/6*[1, 3, 2] - 1/6*[2, 1, 3]\n - 1/6*[2, 3, 1] - 1/6*[3, 1, 2] + 1/3*[3, 2, 1]]\n ' D = self.realization_of().D() return D.to_symmetric_group_algebra(D(self[S])) class ElementMethods(): def to_symmetric_group_algebra(self): '\n Return ``self`` in the symmetric group algebra.\n\n EXAMPLES::\n\n sage: B = DescentAlgebra(QQ, 4).B()\n sage: B[1,3].to_symmetric_group_algebra()\n [1, 2, 3, 4] + [2, 1, 3, 4] + [3, 1, 2, 4] + [4, 1, 2, 3]\n sage: I = DescentAlgebra(QQ, 4).I()\n sage: elt = I(B[1,3])\n sage: elt.to_symmetric_group_algebra()\n [1, 2, 3, 4] + [2, 1, 3, 4] + [3, 1, 2, 4] + [4, 1, 2, 3]\n ' return self.parent().to_symmetric_group_algebra(self)
def biplane(n, existence=False): '\n Return a biplane of order `n`.\n\n A biplane of order `n` is a symmetric `(1+\\frac {(n+1)(n+2)} {2}, n+2, 2)`-BIBD.\n A symmetric (or square) `(v,k,\\lambda)`-BIBD is a `(v,k,\\lambda)`-BIBD with `v` blocks.\n\n INPUT:\n\n - ``n`` -- (integer) order of the biplane\n\n - ``existence`` (boolean) -- instead of building the design, return:\n\n - ``True`` -- meaning that Sage knows how to build the design\n\n - ``Unknown`` -- meaning that Sage does not know how to build the\n design, but that the design may exist (see :mod:`sage.misc.unknown`).\n\n - ``False`` -- meaning that the design does not exist.\n\n .. SEEALSO::\n\n * :func:`balanced_incomplete_block_design`\n\n EXAMPLES::\n\n sage: designs.biplane(4) # needs sage.rings.finite_rings\n (16,6,2)-Balanced Incomplete Block Design\n sage: designs.biplane(7, existence=True) # needs sage.schemes\n True\n sage: designs.biplane(11) # needs sage.schemes\n (79,13,2)-Balanced Incomplete Block Design\n\n TESTS::\n\n sage: designs.biplane(9) # needs sage.libs.gap\n (56,11,2)-Balanced Incomplete Block Design\n\n Check all known biplanes::\n\n sage: [n for n in [0,1,2,3,4,7,9,11] # needs sage.schemes\n ....: if designs.biplane(n, existence=True) is True]\n [0, 1, 2, 3, 4, 7, 9, 11]\n ' k = (n + 2) v = (((k * (k - 1)) // 2) + 1) return balanced_incomplete_block_design(v, k, lambd=2, existence=existence)
def balanced_incomplete_block_design(v, k, lambd=1, existence=False, use_LJCR=False): "\n Return a BIBD of parameters `v,k, \\lambda`.\n\n A Balanced Incomplete Block Design of parameters `v,k,\\lambda` is a collection\n `\\mathcal C` of `k`-subsets of `V=\\{0,\\dots,v-1\\}` such that for any two\n distinct elements `x,y\\in V` there are `\\lambda` elements `S\\in \\mathcal C`\n such that `x,y\\in S`.\n\n For more information on BIBD, see the\n :wikipedia:`corresponding Wikipedia entry <Block_design#Definition_of_a_BIBD_.28or_2-design.29>`.\n\n INPUT:\n\n - ``v,k,lambd`` (integers)\n\n - ``existence`` (boolean) -- instead of building the design, return:\n\n - ``True`` -- meaning that Sage knows how to build the design\n\n - ``Unknown`` -- meaning that Sage does not know how to build the\n design, but that the design may exist (see :mod:`sage.misc.unknown`).\n\n - ``False`` -- meaning that the design does not exist.\n\n - ``use_LJCR`` (boolean) -- whether to query the La Jolla Covering\n Repository for the design when Sage does not know how to build it (see\n :func:`~sage.combinat.designs.covering_design.best_known_covering_design_www`). This\n requires internet.\n\n .. SEEALSO::\n\n * :func:`steiner_triple_system`\n * :func:`v_4_1_BIBD`\n * :func:`v_5_1_BIBD`\n\n .. TODO::\n\n Implement other constructions from the Handbook of Combinatorial\n Designs.\n\n EXAMPLES::\n\n sage: designs.balanced_incomplete_block_design(7, 3, 1).blocks() # needs sage.schemes\n [[0, 1, 3], [0, 2, 4], [0, 5, 6], [1, 2, 6], [1, 4, 5], [2, 3, 5], [3, 4, 6]]\n sage: B = designs.balanced_incomplete_block_design(66, 6, 1, # optional - internet\n ....: use_LJCR=True)\n sage: B # optional - internet\n (66,6,1)-Balanced Incomplete Block Design\n sage: B.blocks() # optional - internet\n [[0, 1, 2, 3, 4, 65], [0, 5, 22, 32, 38, 58], [0, 6, 21, 30, 43, 48], ...\n sage: designs.balanced_incomplete_block_design(216, 6, 1)\n Traceback (most recent call last):\n ...\n NotImplementedError: I don't know how to build a (216,6,1)-BIBD!\n\n TESTS::\n\n sage: designs.balanced_incomplete_block_design(85,5,existence=True)\n True\n sage: _ = designs.balanced_incomplete_block_design(85,5) # needs sage.libs.pari\n\n A BIBD from a Finite Projective Plane::\n\n sage: _ = designs.balanced_incomplete_block_design(21,5) # needs sage.schemes\n\n Some trivial BIBD::\n\n sage: designs.balanced_incomplete_block_design(10,10)\n (10,10,1)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(1,10)\n (1,0,1)-Balanced Incomplete Block Design\n\n Existence of BIBD with `k=3,4,5`::\n\n sage: [v for v in range(50) if designs.balanced_incomplete_block_design(v,3,existence=True)] # needs sage.schemes\n [1, 3, 7, 9, 13, 15, 19, 21, 25, 27, 31, 33, 37, 39, 43, 45, 49]\n sage: [v for v in range(100) if designs.balanced_incomplete_block_design(v,4,existence=True)] # needs sage.schemes\n [1, 4, 13, 16, 25, 28, 37, 40, 49, 52, 61, 64, 73, 76, 85, 88, 97]\n sage: [v for v in range(150) if designs.balanced_incomplete_block_design(v,5,existence=True)] # needs sage.schemes\n [1, 5, 21, 25, 41, 45, 61, 65, 81, 85, 101, 105, 121, 125, 141, 145]\n\n For `k > 5` there are currently very few constructions::\n\n sage: [v for v in range(300) if designs.balanced_incomplete_block_design(v,6,existence=True) is True] # needs sage.schemes\n [1, 6, 31, 66, 76, 91, 96, 106, 111, 121, 126, 136, 141, 151, 156, 171, 181, 186, 196, 201, 211, 241, 271]\n sage: [v for v in range(300) if designs.balanced_incomplete_block_design(v,6,existence=True) is Unknown] # needs sage.schemes\n [51, 61, 81, 166, 216, 226, 231, 246, 256, 261, 276, 286, 291]\n\n Here are some constructions with `k \\geq 7` and `v` a prime power::\n\n sage: # needs sage.libs.pari\n sage: designs.balanced_incomplete_block_design(169,7)\n (169,7,1)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(617,8)\n (617,8,1)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(433,9)\n (433,9,1)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(1171,10)\n (1171,10,1)-Balanced Incomplete Block Design\n\n And we know some nonexistence results::\n\n sage: designs.balanced_incomplete_block_design(21,6,existence=True)\n False\n\n Some BIBDs with `\\lambda \\neq 1`::\n\n sage: designs.balanced_incomplete_block_design(176, 50, 14, existence=True)\n True\n sage: designs.balanced_incomplete_block_design(64,28,12) # needs sage.libs.pari\n (64,28,12)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(37,9,8) # needs sage.libs.pari\n (37,9,8)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(15,7,3) # needs sage.schemes\n (15,7,3)-Balanced Incomplete Block Design\n\n Some BIBDs from the recursive construction ::\n\n sage: designs.balanced_incomplete_block_design(76,16,4) # needs sage.libs.pari\n (76,16,4)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(10,4,2) # needs sage.libs.pari\n (10,4,2)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(50,25,24) # needs sage.schemes\n (50,25,24)-Balanced Incomplete Block Design\n sage: designs.balanced_incomplete_block_design(29,15,15) # needs sage.libs.pari sage.schemes\n (29,15,15)-Balanced Incomplete Block Design\n " if (v == 1): if existence: return True return BIBD(v, [], check=False) if (k == v): if existence: return True return BIBD(v, [list(range(v)) for _ in range(lambd)], lambd=lambd, check=False, copy=False) if ((v < k) or (k < 2) or (((lambd * (v - 1)) % (k - 1)) != 0) or ((((lambd * v) * (v - 1)) % (k * (k - 1))) != 0) or ((k == 6) and (v in [36, 46])) or ((k == 7) and (v == 43)) or ((((lambd * v) * (v - 1)) / (k * (k - 1))) < v)): if existence: return False raise EmptySetError('There exists no ({},{},{})-BIBD'.format(v, k, lambd)) if (BruckRyserChowla_check(v, k, lambd) is False): if existence: return False raise EmptySetError('There exists no ({},{},{})-BIBD by Bruck-Ryser-Chowla Theorem'.format(v, k, lambd)) if (k == 2): if existence: return True return BIBD(v, [[x, y] for _ in range(lambd) for x in range(v) for y in range((x + 1), v) if (x != y)], lambd=lambd, check=False, copy=True) if ((k == 3) and (lambd == 1)): if existence: return (((v % 6) == 1) or ((v % 6) == 3)) return steiner_triple_system(v) if ((k == 4) and (lambd == 1)): if existence: return (((v % 12) == 1) or ((v % 12) == 4)) return BIBD(v, v_4_1_BIBD(v), copy=False) if ((k == 5) and (lambd == 1)): if existence: return (((v % 20) == 1) or ((v % 20) == 5)) return BIBD(v, v_5_1_BIBD(v), copy=False) from .difference_family import difference_family from .database import BIBD_constructions if ((v, k, lambd) in BIBD_constructions): if existence: return True return BIBD(v, BIBD_constructions[(v, k, lambd)](), lambd=lambd, copy=False) if ((lambd == 1) and BIBD_from_arc_in_desarguesian_projective_plane(v, k, existence=True)): if existence: return True B = BIBD_from_arc_in_desarguesian_projective_plane(v, k) return BIBD(v, B, copy=False) if ((lambd == 1) and (BIBD_from_TD(v, k, existence=True) is True)): if existence: return True return BIBD(v, BIBD_from_TD(v, k), copy=False) if ((lambd == 1) and (v == (((k - 1) ** 2) + k)) and is_prime_power((k - 1))): if existence: return True from .block_design import projective_plane return BIBD(v, projective_plane((k - 1)), copy=False) if (difference_family(v, k, l=lambd, existence=True) is True): if existence: return True (G, D) = difference_family(v, k, l=lambd) return BIBD(v, BIBD_from_difference_family(G, D, check=False), lambd=lambd, copy=False) if ((lambd == 1) and use_LJCR): from .covering_design import best_known_covering_design_www values_in_db = False try: B = best_known_covering_design_www(v, k, 2) values_in_db = True except ValueError: pass if values_in_db: expected_n_of_blocks = (binomial(v, 2) // binomial(k, 2)) if (B.low_bd() > expected_n_of_blocks): if existence: return False raise EmptySetError(f'there exists no ({v},{k},{lambd})-BIBD') B = B.incidence_structure() if (B.num_blocks() == expected_n_of_blocks): if existence: return True else: return BIBD(B.ground_set(), B.blocks(), k=k, lambd=1, copy=False) if ((((k + lambd) * ((k + lambd) - 1)) == (lambd * (((v + k) + lambd) - 1))) and (balanced_incomplete_block_design(((v + k) + lambd), (k + lambd), lambd, existence=True) is True)): if existence: return True D = balanced_incomplete_block_design(((v + k) + lambd), (k + lambd), lambd) Br = D.blocks()[0] blocks = D.blocks()[1:] blocks = [set(B).difference(Br) for B in blocks] points = set(D.ground_set()).difference(Br) return BalancedIncompleteBlockDesign(points, blocks, k=k, lambd=lambd, copy=False) if existence: return Unknown else: raise NotImplementedError("I don't know how to build a ({},{},{})-BIBD!".format(v, k, lambd))
def BruckRyserChowla_check(v, k, lambd): '\n Check whether the parameters passed satisfy the Bruck-Ryser-Chowla theorem.\n\n For more information on the theorem, see the\n :wikipedia:`corresponding Wikipedia entry <Bruck–Ryser–Chowla_theorem>`.\n\n INPUT:\n\n - ``v, k, lambd`` -- integers; parameters to check\n\n OUTPUT:\n\n - ``True`` -- the parameters satisfy the theorem\n\n - ``False`` -- the theorem fails for the given parameters\n\n - ``Unknown`` -- the preconditions of the theorem are not met\n\n EXAMPLES:\n\n sage: from sage.combinat.designs.bibd import BruckRyserChowla_check\n sage: BruckRyserChowla_check(22,7,2)\n False\n\n Nonexistence of projective planes of order 6 and 14\n\n sage: from sage.combinat.designs.bibd import BruckRyserChowla_check\n sage: BruckRyserChowla_check(43,7,1) # needs sage.schemes\n False\n sage: BruckRyserChowla_check(211,15,1) # needs sage.schemes\n False\n\n Existence of symmetric BIBDs with parameters `(79,13,2)` and `(56,11,2)`\n\n sage: from sage.combinat.designs.bibd import BruckRyserChowla_check\n sage: BruckRyserChowla_check(79,13,2) # needs sage.schemes\n True\n sage: BruckRyserChowla_check(56,11,2)\n True\n\n TESTS:\n\n Test some non-symmetric parameters::\n\n sage: from sage.combinat.designs.bibd import BruckRyserChowla_check\n sage: BruckRyserChowla_check(89,11,3)\n Unknown\n sage: BruckRyserChowla_check(25,23,2)\n Unknown\n\n Clearly wrong parameters satisfying the theorem::\n\n sage: from sage.combinat.designs.bibd import BruckRyserChowla_check\n sage: BruckRyserChowla_check(13,25,50) # needs sage.schemes\n True\n\n ' from sage.rings.rational_field import QQ if ((k * (k - 1)) != (lambd * (v - 1))): return Unknown if ((v % 2) == 0): return is_square((k - lambd)) g = (1 if ((v % 4) == 1) else (- 1)) C = Conic(QQ, [1, (lambd - k), ((- g) * lambd)]) (flag, sol) = C.has_rational_point(point=True) return flag
def steiner_triple_system(n): "\n Return a Steiner Triple System\n\n A Steiner Triple System (STS) of a set `\\{0,...,n-1\\}`\n is a family `S` of 3-sets such that for any `i \\not = j`\n there exists exactly one set of `S` in which they are\n both contained.\n\n It can alternatively be thought of as a factorization of\n the complete graph `K_n` with triangles.\n\n A Steiner Triple System of a `n`-set exists if and only if\n `n \\equiv 1 \\pmod 6` or `n \\equiv 3 \\pmod 6`, in which case\n one can be found through Bose's and Skolem's constructions,\n respectively [AndHonk97]_.\n\n INPUT:\n\n - ``n`` return a Steiner Triple System of `\\{0,...,n-1\\}`\n\n EXAMPLES:\n\n A Steiner Triple System on `9` elements ::\n\n sage: sts = designs.steiner_triple_system(9)\n sage: sts\n (9,3,1)-Balanced Incomplete Block Design\n sage: list(sts)\n [[0, 1, 5], [0, 2, 4], [0, 3, 6], [0, 7, 8], [1, 2, 3],\n [1, 4, 7], [1, 6, 8], [2, 5, 8], [2, 6, 7], [3, 4, 8],\n [3, 5, 7], [4, 5, 6]]\n\n As any pair of vertices is covered once, its parameters are ::\n\n sage: sts.is_t_design(return_parameters=True)\n (True, (2, 9, 3, 1))\n\n An exception is raised for invalid values of ``n`` ::\n\n sage: designs.steiner_triple_system(10)\n Traceback (most recent call last):\n ...\n EmptySetError: Steiner triple systems only exist for n = 1 mod 6 or n = 3 mod 6\n\n REFERENCE:\n\n .. [AndHonk97] A short course in Combinatorial Designs,\n Ian Anderson, Iiro Honkala,\n Internet Editions, Spring 1997,\n http://www.utu.fi/~honkala/designs.ps\n " name = (('Steiner Triple System on ' + str(n)) + ' elements') if ((n % 6) == 3): t = ((n - 3) // 6) Z = list(range(((2 * t) + 1))) T = (lambda x_y: (x_y[0] + (((2 * t) + 1) * x_y[1]))) sts = ([[(i, 0), (i, 1), (i, 2)] for i in Z] + [[(i, k), (j, k), ((((t + 1) * (i + j)) % ((2 * t) + 1)), ((k + 1) % 3))] for k in range(3) for i in Z for j in Z if (i != j)]) elif ((n % 6) == 1): t = ((n - 1) // 6) N = list(range((2 * t))) T = (lambda x_y: ((x_y[0] + ((x_y[1] * t) * 2)) if (x_y != ((- 1), (- 1))) else (n - 1))) L1 = (lambda i, j: ((i + j) % ((n - 1) // 3))) L = (lambda i, j: ((L1(i, j) // 2) if ((L1(i, j) % 2) == 0) else (t + ((L1(i, j) - 1) // 2)))) sts = (([[(i, 0), (i, 1), (i, 2)] for i in range(t)] + [[((- 1), (- 1)), (i, k), ((i - t), ((k + 1) % 3))] for i in range(t, (2 * t)) for k in [0, 1, 2]]) + [[(i, k), (j, k), (L(i, j), ((k + 1) % 3))] for k in [0, 1, 2] for i in N for j in N if (i < j)]) else: raise EmptySetError('Steiner triple systems only exist for n = 1 mod 6 or n = 3 mod 6') sts = set((frozenset((T(xx) for xx in x)) for x in sts)) return BIBD(n, sts, name=name, check=False)
def BIBD_from_TD(v, k, existence=False): '\n Return a BIBD through TD-based constructions.\n\n INPUT:\n\n - ``v,k`` -- (integers) computes a `(v,k,1)`-BIBD.\n\n - ``existence`` -- (boolean) instead of building the design, return:\n\n - ``True`` -- meaning that Sage knows how to build the design\n\n - ``Unknown`` -- meaning that Sage does not know how to build the\n design, but that the design may exist (see :mod:`sage.misc.unknown`)\n\n - ``False`` -- meaning that the design does not exist\n\n This method implements three constructions:\n\n - If there exists a `TD(k,v)` and a `(v,k,1)`-BIBD then there exists a\n `(kv,k,1)`-BIBD.\n\n The BIBD is obtained from all blocks of the `TD`, and from the blocks of\n the `(v,k,1)`-BIBDs defined over the `k` groups of the `TD`.\n\n - If there exists a `TD(k,v)` and a `(v+1,k,1)`-BIBD then there exists a\n `(kv+1,k,1)`-BIBD.\n\n The BIBD is obtained from all blocks of the `TD`, and from the blocks of\n the `(v+1,k,1)`-BIBDs defined over the sets `V_1\\cup \\infty,\\dots,V_k\\cup\n \\infty` where the `V_1,\\dots,V_k` are the groups of the TD.\n\n - If there exists a `TD(k,v)` and a `(v+k,k,1)`-BIBD then there exists a\n `(kv+k,k,1)`-BIBD.\n\n The BIBD is obtained from all blocks of the `TD`, and from the blocks of\n the `(v+k,k,1)`-BIBDs defined over the sets `V_1\\cup\n \\{\\infty_1,\\dots,\\infty_k\\},\\dots,V_k\\cup \\{\\infty_1,\\dots,\\infty_k\\}`\n where the `V_1,\\dots,V_k` are the groups of the TD. By making sure that\n all copies of the `(v+k,k,1)`-BIBD contain the block\n `\\{\\infty_1,\\dots,\\infty_k\\}`, the result is also a BIBD.\n\n These constructions can be found in\n `<http://www.argilo.net/files/bibd.pdf>`_.\n\n EXAMPLES:\n\n First construction::\n\n sage: from sage.combinat.designs.bibd import BIBD_from_TD\n sage: BIBD_from_TD(25,5,existence=True) # needs sage.schemes\n True\n sage: _ = BlockDesign(25,BIBD_from_TD(25,5)) # needs sage.schemes\n\n Second construction::\n\n sage: from sage.combinat.designs.bibd import BIBD_from_TD\n sage: BIBD_from_TD(21,5,existence=True) # needs sage.schemes\n True\n sage: _ = BlockDesign(21,BIBD_from_TD(21,5)) # needs sage.schemes\n\n Third construction::\n\n sage: from sage.combinat.designs.bibd import BIBD_from_TD\n sage: BIBD_from_TD(85,5,existence=True) # needs sage.schemes\n True\n sage: _ = BlockDesign(85,BIBD_from_TD(85,5)) # needs sage.schemes\n\n No idea::\n\n sage: from sage.combinat.designs.bibd import BIBD_from_TD\n sage: BIBD_from_TD(20,5,existence=True)\n Unknown\n sage: BIBD_from_TD(20,5)\n Traceback (most recent call last):\n ...\n NotImplementedError: I do not know how to build a (20,5,1)-BIBD!\n ' if (((v % k) == 0) and (balanced_incomplete_block_design((v // k), k, existence=True) is True) and (transversal_design(k, (v // k), existence=True) is True)): if existence: return True v = (v // k) BIBDvk = balanced_incomplete_block_design(v, k)._blocks TDkv = transversal_design(k, v, check=False) BIBD = TDkv._blocks for i in range(k): BIBD.extend([[(x + (i * v)) for x in B] for B in BIBDvk]) elif (((((v - 1) % k) == 0) and (balanced_incomplete_block_design((((v - 1) // k) + 1), k, existence=True) is True) and transversal_design(k, ((v - 1) // k), existence=True)) is True): if existence: return True v = ((v - 1) // k) BIBDv1k = balanced_incomplete_block_design((v + 1), k)._blocks TDkv = transversal_design(k, v, check=False)._blocks inf = (v * k) BIBD = TDkv for i in range(k): BIBD.extend([[(inf if (x == v) else (x + (i * v))) for x in B] for B in BIBDv1k]) elif ((((v - k) % k) == 0) and (balanced_incomplete_block_design((((v - k) // k) + k), k, existence=True) is True) and (transversal_design(k, ((v - k) // k), existence=True) is True)): if existence: return True v = ((v - k) // k) BIBDvpkk = balanced_incomplete_block_design((v + k), k) TDkv = transversal_design(k, v, check=False)._blocks inf = (v * k) BIBD = TDkv BIBDvpkk = _relabel_bibd(BIBDvpkk, (v + k)) BIBDvpkk = [B for B in BIBDvpkk if (min(B) < v)] for i in range(k): BIBD.extend([[(((x - v) + inf) if (x >= v) else (x + (i * v))) for x in B] for B in BIBDvpkk]) BIBD.append(list(range((k * v), ((v * k) + k)))) elif existence: return Unknown else: raise NotImplementedError('I do not know how to build a ({},{},1)-BIBD!'.format(v, k)) return BIBD
def BIBD_from_difference_family(G, D, lambd=None, check=True): '\n Return the BIBD associated to the difference family ``D`` on the group ``G``.\n\n Let `G` be a group. A `(G,k,\\lambda)`-*difference family* is a family `B =\n \\{B_1,B_2,\\ldots,B_b\\}` of `k`-subsets of `G` such that for each element of\n `G \\backslash \\{0\\}` there exists exactly `\\lambda` pairs of elements\n `(x,y)`, `x` and `y` belonging to the same block, such that `x - y = g` (or\n x y^{-1} = g` in multiplicative notation).\n\n If `\\{B_1, B_2, \\ldots, B_b\\}` is a `(G,k,\\lambda)`-difference family then\n its set of translates `\\{B_i \\cdot g; i \\in \\{1,\\ldots,b\\}, g \\in G\\}` is a\n `(v,k,\\lambda)`-BIBD where `v` is the cardinality of `G`.\n\n INPUT:\n\n - ``G`` - a finite additive Abelian group\n\n - ``D`` - a difference family on ``G`` (short blocks are allowed).\n\n - ``lambd`` - the `\\lambda` parameter (optional, only used if ``check`` is\n ``True``)\n\n - ``check`` - whether or not we check the output (default: ``True``)\n\n EXAMPLES::\n\n sage: G = Zmod(21)\n sage: D = [[0,1,4,14,16]]\n sage: sorted(G(x-y) for x in D[0] for y in D[0] if x != y)\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n\n sage: from sage.combinat.designs.bibd import BIBD_from_difference_family\n sage: BIBD_from_difference_family(G, D)\n [[0, 1, 4, 14, 16],\n [1, 2, 5, 15, 17],\n [2, 3, 6, 16, 18],\n [3, 4, 7, 17, 19],\n [4, 5, 8, 18, 20],\n [5, 6, 9, 19, 0],\n [6, 7, 10, 20, 1],\n [7, 8, 11, 0, 2],\n [8, 9, 12, 1, 3],\n [9, 10, 13, 2, 4],\n [10, 11, 14, 3, 5],\n [11, 12, 15, 4, 6],\n [12, 13, 16, 5, 7],\n [13, 14, 17, 6, 8],\n [14, 15, 18, 7, 9],\n [15, 16, 19, 8, 10],\n [16, 17, 20, 9, 11],\n [17, 18, 0, 10, 12],\n [18, 19, 1, 11, 13],\n [19, 20, 2, 12, 14],\n [20, 0, 3, 13, 15]]\n ' from .difference_family import group_law, block_stabilizer (identity, mul, inv) = group_law(G) bibd = [] Gset = set(G) p_to_i = {g: i for (i, g) in enumerate(Gset)} for b in D: b = [G(w) for w in b] S = block_stabilizer(G, b) GG = Gset.copy() while GG: g = GG.pop() if S: GG.difference_update((mul(s, g) for s in S)) bibd.append([p_to_i[mul(i, g)] for i in b]) if check: if (lambd is None): k = len(bibd[0]) v = G.cardinality() lambd = (((len(bibd) * k) * (k - 1)) // (v * (v - 1))) assert is_pairwise_balanced_design(bibd, G.cardinality(), [len(D[0])], lambd=lambd) return bibd
def v_4_1_BIBD(v, check=True): '\n Return a `(v,4,1)`-BIBD.\n\n A `(v,4,1)`-BIBD is an edge-decomposition of the complete graph `K_v` into\n copies of `K_4`. For more information, see\n :func:`balanced_incomplete_block_design`. It exists if and only if `v\\equiv 1,4\n \\pmod {12}`.\n\n See page 167 of [Stinson2004]_ for the construction details.\n\n .. SEEALSO::\n\n * :func:`balanced_incomplete_block_design`\n\n INPUT:\n\n - ``v`` (integer) -- number of points.\n\n - ``check`` (boolean) -- whether to check that output is correct before\n returning it. As this is expected to be useless (but we are cautious\n guys), you may want to disable it whenever you want speed. Set to ``True``\n by default.\n\n EXAMPLES::\n\n sage: from sage.combinat.designs.bibd import v_4_1_BIBD # long time\n sage: for n in range(13,100): # long time\n ....: if n%12 in [1,4]:\n ....: _ = v_4_1_BIBD(n, check = True)\n\n TESTS:\n\n Check that the `(25,4)` and `(37,4)`-difference family are available::\n\n sage: assert designs.difference_family(25,4,existence=True)\n sage: _ = designs.difference_family(25,4)\n sage: assert designs.difference_family(37,4,existence=True)\n sage: _ = designs.difference_family(37,4)\n\n Check some larger `(v,4,1)`-BIBD (see :trac:`17557`)::\n\n sage: for v in range(400): # long time\n ....: if v%12 in [1,4]:\n ....: _ = designs.balanced_incomplete_block_design(v,4)\n ' k = 4 if (v == 0): return [] if ((v <= 12) or ((v % 12) not in [1, 4])): raise EmptySetError('A K_4-decomposition of K_v exists iif v=2,4 mod 12, v>12 or v==0') if (v == 13): from .block_design import projective_plane return projective_plane(3)._blocks if (v == 16): from .block_design import AffineGeometryDesign from sage.rings.finite_rings.finite_field_constructor import FiniteField return AffineGeometryDesign(2, 1, FiniteField(4, 'x'))._blocks if ((v == 25) or (v == 37)): from .difference_family import difference_family (G, D) = difference_family(v, 4) return BIBD_from_difference_family(G, D, check=False) if (v == 28): return [[0, 1, 23, 26], [0, 2, 10, 11], [0, 3, 16, 18], [0, 4, 15, 20], [0, 5, 8, 9], [0, 6, 22, 25], [0, 7, 14, 21], [0, 12, 17, 27], [0, 13, 19, 24], [1, 2, 24, 27], [1, 3, 11, 12], [1, 4, 17, 19], [1, 5, 14, 16], [1, 6, 9, 10], [1, 7, 20, 25], [1, 8, 15, 22], [1, 13, 18, 21], [2, 3, 21, 25], [2, 4, 12, 13], [2, 5, 18, 20], [2, 6, 15, 17], [2, 7, 19, 22], [2, 8, 14, 26], [2, 9, 16, 23], [3, 4, 22, 26], [3, 5, 7, 13], [3, 6, 14, 19], [3, 8, 20, 23], [3, 9, 15, 27], [3, 10, 17, 24], [4, 5, 23, 27], [4, 6, 7, 8], [4, 9, 14, 24], [4, 10, 16, 21], [4, 11, 18, 25], [5, 6, 21, 24], [5, 10, 15, 25], [5, 11, 17, 22], [5, 12, 19, 26], [6, 11, 16, 26], [6, 12, 18, 23], [6, 13, 20, 27], [7, 9, 17, 18], [7, 10, 26, 27], [7, 11, 23, 24], [7, 12, 15, 16], [8, 10, 18, 19], [8, 11, 21, 27], [8, 12, 24, 25], [8, 13, 16, 17], [9, 11, 19, 20], [9, 12, 21, 22], [9, 13, 25, 26], [10, 12, 14, 20], [10, 13, 22, 23], [11, 13, 14, 15], [14, 17, 23, 25], [14, 18, 22, 27], [15, 18, 24, 26], [15, 19, 21, 23], [16, 19, 25, 27], [16, 20, 22, 24], [17, 20, 21, 26]] PBD = PBD_4_5_8_9_12(((v - 1) // (k - 1)), check=False) bibd = BIBD_from_PBD(PBD, v, k, check=False) if check: assert is_pairwise_balanced_design(bibd, v, [k]) return bibd