code stringlengths 17 6.64M |
|---|
@cached_function
def q_stirling_number2(n, k, q=None):
'\n Return the (unsigned) `q`-Stirling number of the second kind.\n\n This is a `q`-analogue of :func:`sage.combinat.combinat.stirling_number2`.\n\n INPUT:\n\n - ``n``, ``k`` -- integers with ``1 <= k <= n``\n\n - ``q`` -- optional variable (default `q`)\n\n OUTPUT: a polynomial in the variable `q`\n\n These polynomials satisfy the recurrence\n\n .. MATH::\n\n S_{n,k} = q^{k-1} S_{n-1,k-1} + [k]_q s_{n-1, k}.\n\n EXAMPLES::\n\n sage: from sage.combinat.q_analogues import q_stirling_number2\n sage: q_stirling_number2(4,2)\n q^3 + 3*q^2 + 3*q\n\n sage: all(stirling_number2(6,k) == q_stirling_number2(6,k)(1)\n ....: for k in range(7))\n True\n\n\n TESTS::\n\n sage: q_stirling_number2(-1,2)\n Traceback (most recent call last):\n ...\n ValueError: q-Stirling numbers are not defined for n < 0\n\n We check that :trac:`25715` is fixed::\n\n sage: q_stirling_number2(1,0).parent()\n Univariate Polynomial Ring in q over Integer Ring\n sage: q_stirling_number2(2,1,3r)\n 1\n\n REFERENCES:\n\n - [Mil1978]_\n '
if (q is None):
q = ZZ['q'].gen()
if (n < 0):
raise ValueError('q-Stirling numbers are not defined for n < 0')
if (n == 0 == k):
return parent(q)(1)
if ((k > n) or (k <= 0)):
return parent(q)(0)
return (((q ** (k - 1)) * q_stirling_number2((n - 1), (k - 1), q=q)) + (q_int(k, q=q) * q_stirling_number2((n - 1), k, q=q)))
|
def from_list(l):
'\n Returns a ranker from the list l.\n\n INPUT:\n\n - ``l`` - a list\n\n OUTPUT:\n\n - ``[rank, unrank]`` - functions\n\n EXAMPLES::\n\n sage: import sage.combinat.ranker as ranker\n sage: l = [1,2,3]\n sage: r,u = ranker.from_list(l)\n sage: r(1)\n 0\n sage: r(3)\n 2\n sage: u(2)\n 3\n sage: u(0)\n 1\n '
return [rank_from_list(l), unrank_from_list(l)]
|
def rank_from_list(l):
"\n Return a rank function for the elements of ``l``.\n\n INPUT:\n\n - ``l`` -- a duplicate free list (or iterable) of hashable objects\n\n OUTPUT:\n\n - a function from the elements of ``l`` to ``0,...,len(l)``\n\n EXAMPLES::\n\n sage: import sage.combinat.ranker as ranker\n sage: l = ['a', 'b', 'c']\n sage: r = ranker.rank_from_list(l)\n sage: r('a')\n 0\n sage: r('c')\n 2\n\n For non elements a :class:`ValueError` is raised, as with the usual\n ``index`` method of lists::\n\n sage: r('blah')\n Traceback (most recent call last):\n ...\n ValueError: 'blah' is not in dict\n\n Currently, the rank function is a\n :class:`~sage.misc.callable_dict.CallableDict`; but this is an\n implementation detail::\n\n sage: type(r)\n <class 'sage.misc.callable_dict.CallableDict'>\n sage: r\n {'a': 0, 'b': 1, 'c': 2}\n\n With the current implementation, no error is issued in case of\n duplicate value in ``l``. Instead, the rank function returns the\n position of some of the duplicates::\n\n sage: r = ranker.rank_from_list(['a', 'b', 'a', 'c'])\n sage: r('a')\n 2\n\n Constructing the rank function itself is of complexity\n ``O(len(l))``. Then, each call to the rank function consists of an\n essentially constant time dictionary lookup.\n\n TESTS::\n\n sage: TestSuite(r).run()\n "
return CallableDict(((x, i) for (i, x) in enumerate(l)))
|
def unrank_from_list(l):
'\n Returns an unrank function from a list.\n\n EXAMPLES::\n\n sage: import sage.combinat.ranker as ranker\n sage: l = [1,2,3]\n sage: u = ranker.unrank_from_list(l)\n sage: u(2)\n 3\n sage: u(0)\n 1\n '
unrank = (lambda j: l[j])
return unrank
|
def on_fly():
"\n Returns a pair of enumeration functions rank / unrank.\n\n rank assigns on the fly an integer, starting from 0, to any object\n passed as argument. The object should be hashable. unrank is the\n inverse function; it returns None for indices that have not yet\n been assigned.\n\n EXAMPLES::\n\n sage: [rank, unrank] = sage.combinat.ranker.on_fly()\n sage: rank('a')\n 0\n sage: rank('b')\n 1\n sage: rank('c')\n 2\n sage: rank('a')\n 0\n sage: unrank(2)\n 'c'\n sage: unrank(3)\n sage: rank('d')\n 3\n sage: unrank(3)\n 'd'\n\n .. TODO:: add tests as in combinat::rankers\n "
def count():
i = 0
while True:
(yield i)
i += 1
counter = count()
@cached_function
def rank(x):
i = next(counter)
unrank.set_cache(x, i)
return i
@cached_function
def unrank(i):
return None
return [rank, unrank]
|
def unrank(L, i):
"\n Return the `i`-th element of `L`.\n\n INPUT:\n\n - ``L`` -- a list, tuple, finite enumerated set, ...\n - ``i`` -- an int or :class:`Integer`\n\n The purpose of this utility is to give a uniform idiom to recover\n the `i`-th element of an object ``L``, whether ``L`` is a list,\n tuple (or more generally a :class:`collections.abc.Sequence`), an\n enumerated set, some old parent of Sage still implementing\n unranking in the method ``__getitem__``, or an iterable (see\n :class:`collections.abc.Iterable`). See :trac:`15919`.\n\n EXAMPLES:\n\n Lists, tuples, and other :class:`sequences <collections.abc.Sequence>`::\n\n sage: from sage.combinat.ranker import unrank\n sage: unrank(['a','b','c'], 2)\n 'c'\n sage: unrank(('a','b','c'), 1)\n 'b'\n sage: unrank(range(3,13,2), 1)\n 5\n\n Enumerated sets::\n\n sage: unrank(GF(7), 2)\n 2\n sage: unrank(IntegerModRing(29), 10)\n 10\n\n An iterable::\n\n sage: unrank(NN,4)\n 4\n\n An iterator::\n\n sage: unrank(('a{}'.format(i) for i in range(20)), 0)\n 'a0'\n sage: unrank(('a{}'.format(i) for i in range(20)), 2)\n 'a2'\n\n .. WARNING::\n\n When unranking an iterator, it returns the ``i``-th element\n beyond where it is currently at::\n\n sage: from sage.combinat.ranker import unrank\n sage: it = iter(range(20))\n sage: unrank(it, 2)\n 2\n sage: unrank(it, 2)\n 5\n\n TESTS::\n\n sage: from sage.combinat.ranker import unrank\n sage: unrank(list(range(3)), 10)\n Traceback (most recent call last):\n ...\n IndexError: list index out of range\n\n sage: unrank(('a{}'.format(i) for i in range(20)), 22)\n Traceback (most recent call last):\n ...\n IndexError: index out of range\n "
if (L in EnumeratedSets()):
return L.unrank(i)
if isinstance(L, Sequence):
return L[i]
if isinstance(L, Parent):
try:
return L[i]
except (AttributeError, TypeError, ValueError):
pass
if isinstance(L, Iterable):
try:
it = iter(L)
for _ in range(i):
next(it)
return next(it)
except StopIteration:
raise IndexError('index out of range')
raise ValueError('do not know how to unrank on {}'.format(L))
|
class PrefixClosedSet():
def __init__(self, words):
'\n A prefix-closed set.\n\n Creation of this prefix-closed set is interactive\n iteratively.\n\n INPUT:\n\n - ``words`` -- a class of words\n (instance of :class:`~sage.combinat.words.words.Words`)\n\n EXAMPLES::\n\n sage: from sage.combinat.recognizable_series import PrefixClosedSet\n sage: P = PrefixClosedSet(Words([0, 1], infinite=False)); P\n [word: ]\n\n sage: P = PrefixClosedSet.create_by_alphabet([0, 1]); P\n [word: ]\n\n See :meth:`iterate_possible_additions` for further examples.\n '
self.words = words
self.elements = [self.words([])]
@classmethod
def create_by_alphabet(cls, alphabet):
'\n A prefix-closed set\n\n This is a convenience method for the\n creation of prefix-closed sets by specifying an alphabet.\n\n INPUT:\n\n - ``alphabet`` -- finite words over this ``alphabet``\n will used\n\n EXAMPLES::\n\n sage: from sage.combinat.recognizable_series import PrefixClosedSet\n sage: P = PrefixClosedSet.create_by_alphabet([0, 1]); P\n [word: ]\n '
from sage.combinat.words.words import Words
return cls(Words(alphabet, infinite=False))
def __repr__(self):
"\n A representation string of this prefix-closed set\n\n OUTPUT:\n\n A string\n\n EXAMPLES::\n\n sage: from sage.combinat.recognizable_series import PrefixClosedSet\n sage: P = PrefixClosedSet.create_by_alphabet([0, 1])\n sage: repr(P) # indirect doctest\n '[word: ]'\n "
return repr(self.elements)
def add(self, w, check=True):
'\n Add a word to this prefix-closed set.\n\n INPUT:\n\n - ``w`` -- a word\n\n - ``check`` -- boolean (default: ``True``). If set, then it is verified\n whether all proper prefixes of ``w`` are already in this\n prefix-closed set.\n\n OUTPUT:\n\n Nothing, but a\n :python:`RuntimeError<library/exceptions.html#exceptions.ValueError>`\n is raised if the check fails.\n\n EXAMPLES::\n\n sage: from sage.combinat.recognizable_series import PrefixClosedSet\n sage: P = PrefixClosedSet.create_by_alphabet([0, 1])\n sage: W = P.words\n sage: P.add(W([0])); P\n [word: , word: 0]\n sage: P.add(W([0, 1])); P\n [word: , word: 0, word: 01]\n sage: P.add(W([1, 1]))\n Traceback (most recent call last):\n ...\n ValueError: cannot add as not all prefixes of 11 are included yet\n '
if (check and any(((p not in self.elements) for p in w.prefixes_iterator() if (p != w)))):
raise ValueError('cannot add as not all prefixes of {} are included yet'.format(w))
self.elements.append(w)
def iterate_possible_additions(self):
"\n Return an iterator over all elements including possible new elements.\n\n OUTPUT:\n\n An iterator\n\n EXAMPLES::\n\n sage: from sage.combinat.recognizable_series import PrefixClosedSet\n sage: P = PrefixClosedSet.create_by_alphabet([0, 1]); P\n [word: ]\n sage: for n, p in enumerate(P.iterate_possible_additions()):\n ....: print('{}?'.format(p))\n ....: if n in (0, 2, 3, 5):\n ....: P.add(p)\n ....: print('...added')\n 0?\n ...added\n 1?\n 00?\n ...added\n 01?\n ...added\n 000?\n 001?\n ...added\n 010?\n 011?\n 0010?\n 0011?\n sage: P.elements\n [word: , word: 0, word: 00, word: 01, word: 001]\n\n Calling the iterator once more, returns all elements::\n\n sage: list(P.iterate_possible_additions())\n [word: 0,\n word: 1,\n word: 00,\n word: 01,\n word: 000,\n word: 001,\n word: 010,\n word: 011,\n word: 0010,\n word: 0011]\n\n The method :meth:`iterate_possible_additions` is roughly equivalent to\n ::\n\n sage: list(p + a\n ....: for p in P.elements\n ....: for a in P.words.iterate_by_length(1))\n [word: 0,\n word: 1,\n word: 00,\n word: 01,\n word: 000,\n word: 001,\n word: 010,\n word: 011,\n word: 0010,\n word: 0011]\n\n However, the above does not allow to add elements during iteration,\n whereas :meth:`iterate_possible_additions` does.\n "
n = 0
it = self.words.iterate_by_length(1)
while (n < len(self.elements)):
try:
nn = next(it)
(yield (self.elements[n] + nn))
except StopIteration:
n += 1
it = self.words.iterate_by_length(1)
def prefix_set(self):
'\n Return the set of minimal (with respect to prefix ordering) elements\n of the complement of this prefix closed set.\n\n See also Proposition 2.3.1 of [BR2010a]_.\n\n OUTPUT:\n\n A list\n\n EXAMPLES::\n\n sage: from sage.combinat.recognizable_series import PrefixClosedSet\n sage: P = PrefixClosedSet.create_by_alphabet([0, 1]); P\n [word: ]\n sage: for n, p in enumerate(P.iterate_possible_additions()):\n ....: if n in (0, 1, 2, 4, 6):\n ....: P.add(p)\n sage: P\n [word: , word: 0, word: 1, word: 00, word: 10, word: 000]\n sage: P.prefix_set()\n [word: 01, word: 11, word: 001, word: 100,\n word: 101, word: 0000, word: 0001]\n '
return [(p + a) for p in self.elements for a in self.words.iterate_by_length(1) if ((p + a) not in self.elements)]
|
def minimize_result(operation):
"\n A decorator for operations that enables control of\n automatic minimization on the result.\n\n INPUT:\n\n - ``operation`` -- a method\n\n OUTPUT:\n\n A method with the following additional argument:\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n .. NOTE::\n\n If the result of ``operation`` is ``self``, then minimization is\n not applied unless ``minimize=True`` is explicitly set,\n in particular, independent of the parent's ``minimize_results``.\n\n TESTS::\n\n sage: from sage.combinat.recognizable_series import minimize_result\n sage: class P():\n ....: pass\n sage: p = P()\n sage: class S():\n ....: def __init__(self, s):\n ....: self.s = s\n ....: def __repr__(self):\n ....: return self.s\n ....: def parent(self):\n ....: return p\n ....: def minimized(self):\n ....: return S(self.s + ' minimized')\n ....: @minimize_result\n ....: def operation(self):\n ....: return S(self.s + ' result')\n\n sage: p.minimize_results = True\n sage: S('some').operation()\n some result minimized\n sage: S('some').operation(minimize=True)\n some result minimized\n sage: S('some').operation(minimize=False)\n some result\n\n sage: p.minimize_results = False\n sage: S('some').operation()\n some result\n sage: S('some').operation(minimize=True)\n some result minimized\n sage: S('some').operation(minimize=False)\n some result\n\n ::\n\n sage: class T(S):\n ....: @minimize_result\n ....: def nooperation(self):\n ....: return self\n sage: t = T('some')\n sage: p.minimize_results = True\n sage: t.nooperation() is t\n True\n sage: t.nooperation(minimize=True) is t\n False\n sage: t.nooperation(minimize=False) is t\n True\n sage: p.minimize_results = False\n sage: t.nooperation() is t\n True\n sage: t.nooperation(minimize=True) is t\n False\n sage: t.nooperation(minimize=False) is t\n True\n "
@wraps(operation)
def minimized(self, *args, **kwds):
minimize = kwds.pop('minimize', None)
result = operation(self, *args, **kwds)
if ((minimize is not True) and (result is self)):
return result
if (minimize is None):
minimize = self.parent().minimize_results
if minimize:
result = result.minimized()
return result
return minimized
|
class RecognizableSeries(ModuleElement):
def __init__(self, parent, mu, left, right):
'\n A recognizable series.\n\n - ``parent`` -- an instance of :class:`RecognizableSeriesSpace`\n\n - ``mu`` -- a family of square matrices, all of which have the\n same dimension.\n The indices of this family are the elements of the alphabet.\n ``mu`` may be a list or tuple of the same cardinality as the\n alphabet as well. See also :meth:`mu <mu>`.\n\n - ``left`` -- a vector. When evaluating a\n coefficient, this vector is multiplied from the left to the\n matrix obtained from :meth:`mu <mu>` applying on a word.\n See also :meth:`left <left>`.\n\n - ``right`` -- a vector. When evaluating a\n coefficient, this vector is multiplied from the right to the\n matrix obtained from :meth:`mu <mu>` applying on a word.\n See also :meth:`right <right>`.\n\n When created via the parent :class:`RecognizableSeriesSpace`, then\n the following option is available.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])).transposed(); S\n [1] + 3*[01] + [10] + 5*[11] + 9*[001] + 3*[010] + ...\n\n We can access coefficients by\n ::\n\n sage: W = Rec.indices()\n sage: S[W([0, 0, 1])]\n 9\n\n .. SEEALSO::\n\n :doc:`recognizable series <recognizable_series>`,\n :class:`RecognizableSeriesSpace`.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, (0,1))\n sage: M0 = Matrix([[1, 0], [0, 1]])\n sage: M1 = Matrix([[0, -1], [1, 2]])\n sage: Rec((M0, M1), (0, 1), (1, 1))\n [] + [0] + 3*[1] + [00] + 3*[01] + 3*[10] + 5*[11] + [000] + 3*[001] + 3*[010] + ...\n\n sage: M0 = Matrix([[3, 6], [0, 1]])\n sage: M1 = Matrix([[0, -6], [1, 5]])\n sage: L = vector([0, 1])\n sage: R = vector([1, 0])\n sage: S = Rec((M0, M1), L, R)\n sage: S.mu[0] is M0, S.mu[1] is M1, S.left is L, S.right is R\n (False, False, False, False)\n sage: S.mu[0].is_immutable(), S.mu[1].is_immutable(), S.left.is_immutable(), S.right.is_immutable()\n (True, True, True, True)\n sage: M0.set_immutable()\n sage: M1.set_immutable()\n sage: L.set_immutable()\n sage: R.set_immutable()\n sage: S = Rec((M0, M1), L, R)\n sage: S.mu[0] is M0, S.mu[1] is M1, S.left is L, S.right is R\n (True, True, True, True)\n '
super().__init__(parent=parent)
from copy import copy
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
from sage.sets.family import Family
A = self.parent().alphabet()
if isinstance(mu, (list, tuple)):
mu = dict(zip(A, mu))
def immutable(m):
if m.is_immutable():
return m
m = copy(m)
m.set_immutable()
return m
if isinstance(mu, dict):
mu = {a: Matrix(M, immutable=True) for (a, M) in mu.items()}
mu = Family(mu)
if (not mu.is_finite()):
raise NotImplementedError('mu is not a finite family of matrices')
self._left_ = immutable(vector(left))
self._mu_ = mu
self._right_ = immutable(vector(right))
@property
def mu(self):
"\n When evaluating a coefficient, this is applied on each letter\n of a word; the result is a matrix.\n This extends :meth:`mu <mu>` to words over the parent's\n :meth:`~RecognizableSeriesSpace.alphabet`.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: M0 = Matrix([[1, 0], [0, 1]])\n sage: M1 = Matrix([[0, -1], [1, 2]])\n sage: S = Rec((M0, M1), vector([0, 1]), vector([1, 1]))\n sage: S.mu[0] == M0 and S.mu[1] == M1\n True\n "
return self._mu_
@property
def left(self):
'\n When evaluating a coefficient, this vector is multiplied from\n the left to the matrix obtained from :meth:`mu <mu>` applied on a\n word.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])).transposed().left\n (1, 0)\n '
return self._left_
@property
def right(self):
'\n When evaluating a coefficient, this vector is multiplied from\n the right to the matrix obtained from :meth:`mu <mu>` applied on a\n word.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])).transposed().right\n (0, 1)\n '
return self._right_
def linear_representation(self):
'\n Return the linear representation of this series.\n\n OUTPUT:\n\n A triple ``(left, mu, right)`` containing\n the vectors :meth:`left <left>` and :meth:`right <right>`,\n and the family of matrices :meth:`mu <mu>`.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])\n ....: ).transposed().linear_representation()\n ((1, 0),\n Finite family {0: [3 0]\n [6 1],\n 1: [ 0 1]\n [-6 5]},\n (0, 1))\n '
return (self.left, self.mu, self.right)
def _repr_(self, latex=False):
"\n A representation string for this recognizable series.\n\n INPUT:\n\n - ``latex`` -- (default: ``False``) a boolean. If set, then\n LaTeX-output is returned.\n\n OUTPUT:\n\n A string\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])).transposed()\n sage: repr(S) # indirect doctest\n '[1] + 3*[01] + [10] + 5*[11] + 9*[001] + 3*[010] + ...'\n\n TESTS::\n\n sage: S = Rec((Matrix([[0]]), Matrix([[0]])),\n ....: vector([1]), vector([1]))\n sage: repr(S) # indirect doctest\n '[] + ...'\n\n sage: S = Rec((Matrix([[0, 1], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: vector([0, 1]), vector([1, 0]))\n sage: repr(S) # indirect doctest\n '0 + ...'\n "
if self.is_trivial_zero():
return '0'
from itertools import islice
if latex:
from sage.misc.latex import latex as latex_repr
fr = latex_repr
fs = latex_repr
times = ' '
else:
fr = repr
fs = str
times = '*'
def summand(w, c):
if (c == 1):
return '[{w}]'.format(w=fs(w))
return '{c}{times}[{w}]'.format(c=fr(c), times=times, w=fs(w))
def all_coefficients():
number_of_zeros = 0
for w in self.parent().indices():
c = self[w]
if (c != 0):
number_of_zeros = 0
(yield (w, self[w]))
else:
number_of_zeros += 1
if (number_of_zeros >= 100):
return
coefficients = islice(all_coefficients(), 10)
s = ' + '.join((summand(w, c) for (w, c) in coefficients))
s = s.replace('+ -', '- ')
if (not s):
s = '0'
return (s + ' + ...')
def _latex_(self):
'\n A LaTeX-representation string for this recognizable series.\n\n OUTPUT:\n\n A string\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])).transposed()\n sage: latex(S) # indirect doctest\n [1] + 3 [01] + [10] + 5 [11] + 9 [001] + 3 [010]\n + 15 [011] + [100] + 11 [101] + 5 [110] + ...\n '
return self._repr_(latex=True)
@cached_method
def coefficient_of_word(self, w, multiply_left=True, multiply_right=True):
"\n Return the coefficient to word `w` of this series.\n\n INPUT:\n\n - ``w`` -- a word over the parent's\n :meth:`~RecognizableSeriesSpace.alphabet`\n\n - ``multiply_left`` -- (default: ``True``) a boolean. If ``False``,\n then multiplication by :meth:`left <left>` is skipped.\n\n - ``multiply_right`` -- (default: ``True``) a boolean. If ``False``,\n then multiplication by :meth:`right <right>` is skipped.\n\n OUTPUT:\n\n An element in the parent's\n :meth:`~RecognizableSeriesSpace.coefficient_ring`\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: W = Rec.indices()\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[0, -1], [1, 2]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: S[W(7.digits(2))] # indirect doctest\n 3\n\n TESTS::\n\n sage: w = W(6.digits(2))\n sage: S.coefficient_of_word(w)\n 2\n sage: S.coefficient_of_word(w, multiply_left=False)\n (-1, 2)\n sage: S.coefficient_of_word(w, multiply_right=False)\n (2, 3)\n sage: S.coefficient_of_word(w, multiply_left=False, multiply_right=False)\n [-1 -2]\n [ 2 3]\n "
result = self._mu_of_word_(w)
if multiply_left:
result = (self.left * result)
if multiply_right:
result = (result * self.right)
return result
__getitem__ = coefficient_of_word
@cached_method
def _mu_of_empty_word_(self):
'\n Return :meth:`mu <mu>` applied on the empty word.\n\n OUTPUT:\n\n A matrix\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: W = Rec.indices()\n sage: M0 = Matrix([[1, 0], [0, 1]])\n sage: M1 = Matrix([[0, -1], [1, 2]])\n sage: S = Rec({W([0]): M0, W([1]): M1}, vector([0, 1]), vector([1, 1]))\n sage: S._mu_of_empty_word_()\n [1 0]\n [0 1]\n sage: I = Matrix([[1, 0], [0, 1]]); I.set_immutable()\n sage: T = Rec({W([]): I, W([0]): M0, W([1]): M1}, vector([0, 1]), vector([1, 1]))\n sage: T._mu_of_empty_word_()\n [1 0]\n [0 1]\n sage: _ is I\n True\n '
eps = self.parent().indices()()
try:
return self.mu[eps]
except KeyError:
return next(iter(self.mu)).parent().one()
@cached_method
def _mu_of_word_(self, w):
"\n Return :meth:`mu <mu>` applied on the word `w`.\n\n INPUT:\n\n - ``w`` -- a word over the parent's\n :meth:`~RecognizableSeriesSpace.alphabet`\n\n OUTPUT:\n\n A matrix\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: W = Rec.indices()\n sage: M0 = Matrix([[1, 0], [0, 1]])\n sage: M1 = Matrix([[0, -1], [1, 2]])\n sage: S = Rec((M0, M1), vector([0, 1]), vector([1, 1]))\n sage: S._mu_of_word_(W([0])) == M0\n True\n sage: S._mu_of_word_(W([1])) == M1\n True\n sage: S._mu_of_word_(W(3.digits(2))) == M1^2\n True\n\n ::\n\n sage: S._mu_of_word_(-1)\n Traceback (most recent call last):\n ...\n ValueError: index -1 is not in Finite words over {0, 1}\n "
W = self.parent().indices()
if (w not in W):
raise ValueError('index {} is not in {}'.format(w, W))
from sage.misc.misc_c import prod
return prod((self.mu[a] for a in w), z=self._mu_of_empty_word_())
def __iter__(self):
'\n Return an iterator over pairs ``(index, coefficient)``.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[0, -1], [1, 2]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: from itertools import islice\n sage: list(islice(S, 10))\n [(word: , 0),\n (word: 0, 0),\n (word: 1, 1),\n (word: 00, 0),\n (word: 01, 1),\n (word: 10, 1),\n (word: 11, 2),\n (word: 000, 0),\n (word: 001, 1),\n (word: 010, 1)]\n sage: list(islice((s for s in S if s[1] != 0), 10))\n [(word: 1, 1),\n (word: 01, 1),\n (word: 10, 1),\n (word: 11, 2),\n (word: 001, 1),\n (word: 010, 1),\n (word: 011, 2),\n (word: 100, 1),\n (word: 101, 2),\n (word: 110, 2)]\n\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[0, -1], [1, 2]])),\n ....: left=vector([1, 0]), right=vector([1, 0]))\n sage: list(islice((s for s in S if s[1] != 0), 10))\n [(word: , 1),\n (word: 0, 1),\n (word: 00, 1),\n (word: 11, -1),\n (word: 000, 1),\n (word: 011, -1),\n (word: 101, -1),\n (word: 110, -1),\n (word: 111, -2),\n (word: 0000, 1)]\n\n TESTS::\n\n sage: it = iter(S)\n sage: iter(it) is it\n True\n sage: iter(S) is not it\n True\n '
return iter(((w, self[w]) for w in self.parent().indices()))
def is_trivial_zero(self):
'\n Return whether this recognizable series is trivially equal to\n zero (without any :meth:`minimization <minimized>`).\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0])).is_trivial_zero()\n False\n sage: Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 0]), right=vector([1, 0])).is_trivial_zero()\n True\n sage: Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([0, 0])).is_trivial_zero()\n True\n\n The following two differ in the coefficient of the empty word::\n\n sage: Rec((Matrix([[0, 0], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: left=vector([0, 1]), right=vector([1, 0])).is_trivial_zero()\n True\n sage: Rec((Matrix([[0, 0], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: left=vector([1, 1]), right=vector([1, 1])).is_trivial_zero()\n False\n\n TESTS::\n\n sage: Rec.zero().is_trivial_zero()\n True\n\n The following is zero, but not trivially zero::\n\n sage: S = Rec((Matrix([[1, 0], [0, 0]]), Matrix([[1, 0], [0, 0]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: S.is_trivial_zero()\n False\n sage: S.is_zero()\n True\n '
return ((not self.left) or (not self.right) or (all(((not self.mu[a]) for a in self.parent().alphabet())) and (not self[self.parent().indices()()])))
def __bool__(self):
'\n Return whether this recognizable series is nonzero.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: bool(Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0])))\n False\n sage: bool(Rec((Matrix([[0, 0], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: left=vector([0, 1]), right=vector([1, 0])))\n False\n sage: bool(Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 0]), right=vector([1, 0])))\n False\n sage: bool(Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([0, 0])))\n False\n\n ::\n\n sage: S = Rec((Matrix([[1, 0], [0, 0]]), Matrix([[1, 0], [0, 0]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: bool(S)\n False\n '
if self.is_trivial_zero():
return False
try:
M = self.minimized()
except ValueError:
pass
else:
if M.is_trivial_zero():
return False
return True
def __hash__(self):
'\n A hash value of this recognizable series.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: hash(S) # random\n 42\n '
return hash((self.mu, self.left, self.right))
def __eq__(self, other):
'\n Return whether this recognizable series is equal to ``other``.\n\n INPUT:\n\n - ``other`` -- an object\n\n OUTPUT:\n\n A boolean\n\n .. NOTE::\n\n This function uses the coercion model to find a common\n parent for the two operands.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([1, 1]), right=vector([1, 0]))\n sage: S\n [] + [0] + [1] + [00] + [01] + [10]\n + [11] + [000] + [001] + [010] + ...\n sage: Z1 = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: Z1\n 0 + ...\n sage: Z2 = Rec((Matrix([[0, 0], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: Z2\n 0\n sage: S == Z1\n False\n sage: S == Z2\n False\n sage: Z1 == Z2\n True\n\n TESTS::\n\n sage: S == S\n True\n sage: S == None\n False\n '
if (other is None):
return False
try:
return (not bool((self - other)))
except (TypeError, ValueError):
return False
def __ne__(self, other):
'\n Return whether this recognizable series is not equal to ``other``.\n\n INPUT:\n\n - ``other`` -- an object\n\n OUTPUT:\n\n A boolean\n\n .. NOTE::\n\n This function uses the coercion model to find a common\n parent for the two operands.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Z1 = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: Z2 = Rec((Matrix([[0, 0], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: Z1 != Z2\n False\n sage: Z1 != Z1\n False\n '
return (not (self == other))
def transposed(self):
'\n Return the transposed series.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n Each of the matrices in :meth:`mu <mu>` is transposed. Additionally\n the vectors :meth:`left <left>` and :meth:`right <right>` are switched.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])).transposed()\n sage: S\n [1] + 3*[01] + [10] + 5*[11] + 9*[001] + 3*[010]\n + 15*[011] + [100] + 11*[101] + 5*[110] + ...\n sage: S.mu[0], S.mu[1], S.left, S.right\n (\n [3 0] [ 0 1]\n [6 1], [-6 5], (1, 0), (0, 1)\n )\n sage: T = S.transposed()\n sage: T\n [1] + [01] + 3*[10] + 5*[11] + [001] + 3*[010]\n + 5*[011] + 9*[100] + 11*[101] + 15*[110] + ...\n sage: T.mu[0], T.mu[1], T.left, T.right\n (\n [3 6] [ 0 -6]\n [0 1], [ 1 5], (0, 1), (1, 0)\n )\n\n TESTS::\n\n sage: T.mu[0].is_immutable(), T.mu[1].is_immutable(), T.left.is_immutable(), T.right.is_immutable()\n (True, True, True, True)\n '
def tr(M):
T = M.transpose()
T.set_immutable()
return T
P = self.parent()
return P.element_class(P, self.mu.map(tr), left=self.right, right=self.left)
@cached_method
def minimized(self):
'\n Return a recognizable series equivalent to this series, but\n with a minimized linear representation.\n\n The coefficients of the involved matrices need be in a field.\n If this is not the case, then the coefficients are\n automatically coerced to their fraction field.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n ALGORITHM:\n\n This method implements the minimization algorithm presented in\n Chapter 2 of [BR2010a]_.\n\n .. NOTE::\n\n Due to the algorithm, the left vector of the result\n is always `(1, 0, \\ldots, 0)`, i.e., the first vector of the\n standard basis.\n\n EXAMPLES::\n\n sage: from itertools import islice\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n\n sage: S = Rec((Matrix([[3, 6], [0, 1]]), Matrix([[0, -6], [1, 5]])),\n ....: vector([0, 1]), vector([1, 0])).transposed()\n sage: S\n [1] + 3*[01] + [10] + 5*[11] + 9*[001] + 3*[010]\n + 15*[011] + [100] + 11*[101] + 5*[110] + ...\n sage: M = S.minimized()\n sage: M.mu[0], M.mu[1], M.left, M.right\n (\n [3 0] [ 0 1]\n [6 1], [-6 5], (1, 0), (0, 1)\n )\n sage: M.left == vector([1, 0])\n True\n sage: all(c == d and v == w\n ....: for (c, v), (d, w) in islice(zip(iter(S), iter(M)), 20))\n True\n\n sage: S = Rec((Matrix([[2, 0], [1, 1]]), Matrix([[2, 0], [2, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: S\n [] + 2*[0] + 2*[1] + 4*[00] + 4*[01] + 4*[10] + 4*[11]\n + 8*[000] + 8*[001] + 8*[010] + ...\n sage: M = S.minimized()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([2], [2], (1), (1))\n sage: all(c == d and v == w\n ....: for (c, v), (d, w) in islice(zip(iter(S), iter(M)), 20))\n True\n\n TESTS::\n\n sage: Rec((Matrix([[0]]), Matrix([[0]])),\n ....: vector([1]), vector([0])).minimized().linear_representation()\n ((), Finite family {0: [], 1: []}, ())\n '
return self._minimized_right_()._minimized_left_()
def _minimized_right_(self):
'\n Return a recognizable series equivalent to this series, but\n with a right minimized linear representation.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n See :meth:`minimized` for details.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[0, 0], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: vector([1, 1]), vector([1, 1]))\n sage: M = S._minimized_right_()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([0], [0], (2), (1))\n '
return self.transposed()._minimized_left_().transposed()
def _minimized_left_(self):
'\n Return a recognizable series equivalent to this series, but\n with a left minimized linear representation.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n See :meth:`minimized` for details.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: S = Rec((Matrix([[0, 0], [0, 0]]), Matrix([[0, 0], [0, 0]])),\n ....: vector([1, 1]), vector([1, 1]))\n sage: M = S._minimized_left_()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([0], [0], (1), (2))\n sage: M = S.minimized()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([0], [0], (1), (2))\n\n ::\n\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: vector([1, -1]), vector([1, 1]))._minimized_left_()\n sage: S.mu[0], S.mu[1], S.left, S.right\n ([1], [1], (1), (0))\n sage: M = S.minimized()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([], [], (), ())\n\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: vector([1, 1]), vector([1, -1]))\n sage: M = S._minimized_left_()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([1], [1], (1), (0))\n sage: M = S.minimized()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([], [], (), ())\n\n sage: S = Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: M = S._minimized_left_()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([1], [1], (1), (0))\n sage: M = S.minimized()\n sage: M.mu[0], M.mu[1], M.left, M.right\n ([], [], (), ())\n '
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
from sage.rings.integer_ring import ZZ
pcs = PrefixClosedSet(self.parent().indices())
left = self.coefficient_of_word(pcs.elements[0], multiply_right=False)
if left.is_zero():
return self.parent().zero()
Left = [left]
for p in pcs.iterate_possible_additions():
left = self.coefficient_of_word(p, multiply_left=True, multiply_right=False)
try:
Matrix(Left).solve_left(left)
except ValueError:
pcs.add(p)
Left.append(left)
P = pcs.elements
C = pcs.prefix_set()
ML = Matrix(Left)
def alpha(c):
return ML.solve_left(self.coefficient_of_word(c, multiply_right=False))
mu_prime = []
for a in self.parent().alphabet():
a = self.parent().indices()([a])
M = Matrix([(alpha(c) if (c in C) else tuple((ZZ((c == q)) for q in P))) for c in ((p + a) for p in P)])
mu_prime.append(M)
left_prime = vector(([ZZ.one()] + ((len(P) - 1) * [ZZ.zero()])))
right_prime = vector((self.coefficient_of_word(p) for p in P))
P = self.parent()
return P.element_class(P, mu_prime, left_prime, right_prime)
def dimension(self):
'\n Return the dimension of this recognizable series.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [0, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0])).dimension()\n 2\n '
return self.mu.first().nrows()
@minimize_result
def _add_(self, other):
"\n Return the sum of this recognizable series and the ``other``\n recognizable series.\n\n INPUT:\n\n - ``other`` -- a :class:`RecognizableSeries` with the same parent\n as this recognizable series\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: E\n 2-regular sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...\n sage: O = Seq2((Matrix([[0, 0], [0, 1]]), Matrix([[0, 1], [0, 1]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: O\n 2-regular sequence 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, ...\n sage: I = E + O # indirect doctest\n sage: I\n 2-regular sequence 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n sage: I.linear_representation()\n ((1),\n Finite family {0: [1],\n 1: [1]},\n (1))\n "
from sage.modules.free_module_element import vector
P = self.parent()
result = P.element_class(P, {a: self.mu[a].block_sum(other.mu[a]) for a in P.alphabet()}, vector((tuple(self.left) + tuple(other.left))), vector((tuple(self.right) + tuple(other.right))))
return result
def _neg_(self):
'\n Return the additive inverse of this recognizable series.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: -E\n 2-regular sequence -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, ...\n sage: Z = E - E\n sage: Z.is_trivial_zero()\n True\n '
P = self.parent()
return P.element_class(P, self.mu, (- self.left), self.right)
def _rmul_(self, other):
'\n Multiply this recognizable series from the right\n by an element ``other`` of its coefficient (semi-)ring.\n\n INPUT:\n\n - ``other`` -- an element of the coefficient (semi-)ring\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: M = 2 * E # indirect doctest\n sage: M\n 2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...\n sage: M.linear_representation()\n ((2, 0),\n Finite family {0: [0 1]\n [0 1],\n 1: [0 0]\n [0 1]},\n (1, 1))\n\n TESTS::\n\n sage: 1 * E is E\n True\n\n ::\n\n sage: 0 * E is Seq2.zero()\n True\n\n We test that ``_rmul_`` and ``_lmul_`` are actually called::\n\n sage: def print_name(f):\n ....: def f_with_printed_name(*args, **kwds):\n ....: print(f.__name__)\n ....: return f(*args, **kwds)\n ....: return f_with_printed_name\n\n sage: E._rmul_ = print_name(E._rmul_)\n sage: E._lmul_ = print_name(E._lmul_)\n sage: 2 * E\n _rmul_\n 2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...\n sage: E * 2\n _lmul_\n _lmul_\n 2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...\n '
P = self.parent()
if other.is_zero():
return P._zero_()
if other.is_one():
return self
return P.element_class(P, self.mu, (other * self.left), self.right)
def _lmul_(self, other):
'\n Multiply this recognizable series from the left\n by an element ``other`` of its coefficient (semi-)ring.\n\n INPUT:\n\n - ``other`` -- an element of the coefficient (semi-)ring\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: M = E * 2 # indirect doctest\n sage: M\n 2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...\n sage: M.linear_representation()\n ((1, 0),\n Finite family {0: [0 1]\n [0 1],\n 1: [0 0]\n [0 1]},\n (2, 2))\n\n TESTS::\n\n sage: E * 1 is E\n True\n\n ::\n\n sage: E * 0 is Seq2.zero()\n True\n\n The following is not tested, as `MS^i` for integers `i` does\n not work, thus ``vector([m])`` fails. (See :trac:`21317` for\n details.)\n\n ::\n\n sage: MS = MatrixSpace(ZZ,2,2)\n sage: Rec = RecognizableSeriesSpace(MS, [0, 1])\n sage: m = MS.an_element()\n sage: S = Rec((Matrix([[m]]), Matrix([[m]])), # not tested\n ....: vector([m]), vector([m]))\n sage: S # not tested\n sage: M = m * S # not tested indirect doctest\n sage: M # not tested\n sage: M.linear_representation() # not tested\n '
P = self.parent()
if other.is_zero():
return P._zero_()
if other.is_one():
return self
return P.element_class(P, self.mu, self.left, (self.right * other))
@minimize_result
def hadamard_product(self, other):
"\n Return the Hadamard product of this recognizable series\n and the ``other`` recognizable series, i.e., multiply the two\n series coefficient-wise.\n\n INPUT:\n\n - ``other`` -- a :class:`RecognizableSeries` with the same parent\n as this recognizable series\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: E\n 2-regular sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...\n\n sage: O = Seq2((Matrix([[0, 0], [0, 1]]), Matrix([[0, 1], [0, 1]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: O\n 2-regular sequence 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, ...\n\n sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: C\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n\n ::\n\n sage: CE = C.hadamard_product(E)\n sage: CE\n 2-regular sequence 0, 0, 2, 0, 4, 0, 6, 0, 8, 0, ...\n sage: CE.linear_representation()\n ((1, 0, 0),\n Finite family {0: [0 1 0]\n [0 2 0]\n [0 2 1],\n 1: [ 0 0 0]\n [ 0 0 1]\n [ 0 -2 3]},\n (0, 0, 2))\n\n sage: Z = E.hadamard_product(O)\n sage: Z\n 2-regular sequence 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...\n sage: Z.linear_representation()\n ((),\n Finite family {0: [],\n 1: []},\n ())\n\n TESTS::\n\n sage: EC = E.hadamard_product(C, minimize=False)\n sage: EC\n 2-regular sequence 0, 0, 2, 0, 4, 0, 6, 0, 8, 0, ...\n sage: EC.linear_representation()\n ((1, 0, 0, 0),\n Finite family {0: [0 0 2 0]\n [0 0 2 1]\n [0 0 2 0]\n [0 0 2 1],\n 1: [ 0 0 0 0]\n [ 0 0 0 0]\n [ 0 0 0 1]\n [ 0 0 -2 3]},\n (0, 1, 0, 1))\n sage: MEC = EC.minimized()\n sage: MEC\n 2-regular sequence 0, 0, 2, 0, 4, 0, 6, 0, 8, 0, ...\n sage: MEC.linear_representation()\n ((1, 0, 0),\n Finite family {0: [0 1 0]\n [0 2 0]\n [0 2 1],\n 1: [ 0 0 0]\n [ 0 0 1]\n [ 0 -2 3]},\n (0, 0, 2))\n "
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
P = self.parent()
def tensor_product(left, right):
T = left.tensor_product(right)
T.subdivide()
return T
result = P.element_class(P, {a: tensor_product(self.mu[a], other.mu[a]) for a in P.alphabet()}, vector(tensor_product(Matrix(self.left), Matrix(other.left))), vector(tensor_product(Matrix(self.right), Matrix(other.right))))
return result
|
def _pickle_RecognizableSeriesSpace(coefficients, indices, category):
'\n Pickle helper.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: from sage.combinat.recognizable_series import _pickle_RecognizableSeriesSpace\n sage: _pickle_RecognizableSeriesSpace(\n ....: Rec.coefficient_ring(), Rec.indices(), Rec.category())\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n '
return RecognizableSeriesSpace(coefficients, indices=indices, category=category)
|
class RecognizableSeriesSpace(UniqueRepresentation, Parent):
'\n The space of recognizable series on the given alphabet and\n with the given coefficients.\n\n INPUT:\n\n - ``coefficient_ring`` -- a (semi-)ring\n\n - ``alphabet`` -- a tuple, list or\n :class:`~sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet`.\n If specified, then the ``indices`` are the\n finite words over this ``alphabet``.\n ``alphabet`` and ``indices`` cannot be specified\n at the same time.\n\n - ``indices`` -- a SageMath-parent of finite words over an alphabet.\n ``alphabet`` and ``indices`` cannot be specified\n at the same time.\n\n - ``category`` -- (default: ``None``) the category of this\n space\n\n EXAMPLES:\n\n We create a recognizable series that counts the number of ones in each word::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n sage: Rec((Matrix([[1, 0], [0, 1]]), Matrix([[1, 1], [0, 1]])),\n ....: vector([1, 0]), vector([0, 1]))\n [1] + [01] + [10] + 2*[11] + [001] + [010] + 2*[011] + [100] + 2*[101] + 2*[110] + ...\n\n All of the following examples create the same space::\n\n sage: Rec1 = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec1\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n sage: Rec2 = RecognizableSeriesSpace(coefficient_ring=ZZ, alphabet=[0, 1])\n sage: Rec2\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n sage: Rec3 = RecognizableSeriesSpace(ZZ, indices=Words([0, 1], infinite=False))\n sage: Rec3\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n\n .. SEEALSO::\n\n :doc:`recognizable series <recognizable_series>`,\n :class:`RecognizableSeries`.\n '
Element = RecognizableSeries
@staticmethod
def __classcall__(cls, *args, **kwds):
'\n Prepare normalizing the input in order to ensure a\n unique representation.\n\n For more information see :class:`RecognizableSeriesSpace`\n and :meth:`__normalize__`.\n\n TESTS::\n\n sage: Rec1 = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec1\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n sage: Rec2 = RecognizableSeriesSpace(coefficient_ring=ZZ, alphabet=[0, 1])\n sage: Rec2\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n sage: Rec3 = RecognizableSeriesSpace(ZZ, indices=Words([0, 1], infinite=False))\n sage: Rec3\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n sage: Rec1 is Rec2 is Rec3\n True\n '
return super().__classcall__(cls, *cls.__normalize__(*args, **kwds))
@classmethod
def __normalize__(cls, coefficient_ring=None, alphabet=None, indices=None, category=None, minimize_results=True):
"\n Normalizes the input in order to ensure a unique\n representation.\n\n For more information see :class:`RecognizableSeriesSpace`.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1]) # indirect doctest\n sage: Rec.category()\n Category of modules over Integer Ring\n sage: RecognizableSeriesSpace([0, 1], [0, 1])\n Traceback (most recent call last):\n ...\n ValueError: coefficient ring [0, 1] is not a semiring\n\n ::\n\n sage: W = Words([0, 1], infinite=False)\n sage: RecognizableSeriesSpace(ZZ)\n Traceback (most recent call last):\n ...\n ValueError: specify either 'alphabet' or 'indices'\n sage: RecognizableSeriesSpace(ZZ, alphabet=[0, 1], indices=W)\n Traceback (most recent call last):\n ...\n ValueError: specify either 'alphabet' or 'indices'\n sage: RecognizableSeriesSpace(alphabet=[0, 1])\n Traceback (most recent call last):\n ...\n ValueError: no coefficient ring specified\n sage: RecognizableSeriesSpace(ZZ, indices=Words(ZZ))\n Traceback (most recent call last):\n ...\n NotImplementedError: alphabet is not finite\n "
if ((alphabet is None) == (indices is None)):
raise ValueError("specify either 'alphabet' or 'indices'")
if (indices is None):
from sage.combinat.words.words import Words
indices = Words(alphabet, infinite=False)
if (not indices.alphabet().is_finite()):
raise NotImplementedError('alphabet is not finite')
if (coefficient_ring is None):
raise ValueError('no coefficient ring specified')
from sage.categories.semirings import Semirings
if (coefficient_ring not in Semirings()):
raise ValueError('coefficient ring {} is not a semiring'.format(coefficient_ring))
from sage.categories.modules import Modules
category = (category or Modules(coefficient_ring))
return (coefficient_ring, indices, category, minimize_results)
def __init__(self, coefficient_ring, indices, category, minimize_results):
'\n See :class:`RecognizableSeriesSpace` for details.\n\n INPUT:\n\n - ``coefficients`` -- a (semi-)ring\n\n - ``indices`` -- a SageMath-parent of finite words over an alphabet\n\n - ``category`` -- (default: ``None``) the category of this\n space\n\n - ``minimize_results`` -- (default: ``True``) a boolean. If set, then\n :meth:`RecognizableSeries.minimized` is automatically called\n after performing operations.\n\n TESTS::\n\n sage: RecognizableSeriesSpace(ZZ, [0, 1])\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n\n ::\n\n sage: from itertools import islice\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: TestSuite(Rec).run( # long time\n ....: verbose=True,\n ....: elements=tuple(islice(Rec.some_elements(), 4)))\n running ._test_additive_associativity() . . . pass\n running ._test_an_element() . . . pass\n running ._test_cardinality() . . . pass\n running ._test_category() . . . pass\n running ._test_construction() . . . pass\n running ._test_elements() . . .\n Running the test suite of self.an_element()\n running ._test_category() . . . pass\n running ._test_eq() . . . pass\n running ._test_new() . . . pass\n running ._test_nonzero_equal() . . . pass\n running ._test_not_implemented_methods() . . . pass\n running ._test_pickling() . . . pass\n pass\n running ._test_elements_eq_reflexive() . . . pass\n running ._test_elements_eq_symmetric() . . . pass\n running ._test_elements_eq_transitive() . . . pass\n running ._test_elements_neq() . . . pass\n running ._test_eq() . . . pass\n running ._test_new() . . . pass\n running ._test_not_implemented_methods() . . . pass\n running ._test_pickling() . . . pass\n running ._test_some_elements() . . . pass\n running ._test_zero() . . . pass\n '
self._indices_ = indices
self._minimize_results_ = minimize_results
super().__init__(category=category, base=coefficient_ring)
def __reduce__(self):
'\n Pickling support.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: loads(dumps(Rec)) # indirect doctest\n Space of recognizable series on {0, 1} with coefficients in Integer Ring\n '
return (_pickle_RecognizableSeriesSpace, (self.coefficient_ring(), self.indices(), self.category()))
def alphabet(self):
"\n Return the alphabet of this recognizable series space.\n\n OUTPUT:\n\n A totally ordered set\n\n EXAMPLES::\n\n sage: RecognizableSeriesSpace(ZZ, [0, 1]).alphabet()\n {0, 1}\n\n TESTS::\n\n sage: type(RecognizableSeriesSpace(ZZ, [0, 1]).alphabet())\n <class 'sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet_with_category'>\n "
return self.indices().alphabet()
def indices(self):
'\n Return the indices of the recognizable series.\n\n OUTPUT:\n\n The set of finite words over the alphabet\n\n EXAMPLES::\n\n sage: RecognizableSeriesSpace(ZZ, [0, 1]).indices()\n Finite words over {0, 1}\n '
return self._indices_
def coefficient_ring(self):
'\n Return the coefficients of this recognizable series space.\n\n OUTPUT:\n\n A (semi-)ring\n\n EXAMPLES::\n\n sage: RecognizableSeriesSpace(ZZ, [0, 1]).coefficient_ring()\n Integer Ring\n '
return self.base()
@property
def minimize_results(self):
'\n A boolean indicating whether\n :meth:`RecognizableSeries.minimized` is automatically called\n after performing operations.\n\n TESTS::\n\n sage: RecognizableSeriesSpace(ZZ, [0, 1]).minimize_results\n True\n sage: RecognizableSeriesSpace(ZZ, [0, 1], minimize_results=True).minimize_results\n True\n sage: RecognizableSeriesSpace(ZZ, [0, 1], minimize_results=False).minimize_results\n False\n '
return self._minimize_results_
def _repr_(self):
"\n Return a representation string of this recognizable sequence\n space.\n\n OUTPUT:\n\n A string\n\n TESTS::\n\n sage: repr(RecognizableSeriesSpace(ZZ, [0, 1])) # indirect doctest\n 'Space of recognizable series on {0, 1} with coefficients in Integer Ring'\n "
return 'Space of recognizable series on {} with coefficients in {}'.format(self.alphabet(), self.coefficient_ring())
def _an_element_(self):
'\n Return an element of this recognizable series space.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n EXAMPLES::\n\n sage: RecognizableSeriesSpace(ZZ, [0, 1]).an_element() # indirect doctest\n [1] + [01] + [10] + 2*[11] + [001] + [010]\n + 2*[011] + [100] + 2*[101] + 2*[110] + ...\n '
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
z = self.coefficient_ring().zero()
o = self.coefficient_ring().one()
e = self.coefficient_ring().an_element()
return self(list((Matrix([[o, z], [(i * o), o]]) for (i, _) in enumerate(self.alphabet()))), vector([z, e]), right=vector([e, z]))
def some_elements(self, **kwds):
'\n Return some elements of this recognizable series space.\n\n See :class:`TestSuite` for a typical use case.\n\n INPUT:\n\n - ``kwds`` are passed on to the element constructor\n\n OUTPUT:\n\n An iterator\n\n EXAMPLES::\n\n sage: tuple(RecognizableSeriesSpace(ZZ, [0, 1]).some_elements())\n ([1] + [01] + [10] + 2*[11] + [001] + [010]\n + 2*[011] + [100] + 2*[101] + 2*[110] + ...,\n [] + [1] + [11] + [111] + [1111] + [11111] + [111111] + ...,\n [] + [0] + [1] + [00] + [10] + [11]\n + [000] - 1*[001] + [100] + [110] + ...,\n 2*[] - 1*[1] + 2*[10] - 1*[101]\n + 2*[1010] - 1*[10101] + 2*[101010] + ...,\n [] + [1] + 6*[00] + [11] - 39*[000] + 5*[001] + 6*[100] + [111]\n + 288*[0000] - 33*[0001] + ...,\n -5*[] + ...,\n ...\n 210*[] + ...,\n 2210*[] - 170*[0] + 170*[1] + ...)\n '
from itertools import islice
from sage.matrix.matrix_space import MatrixSpace
from sage.modules.free_module import FreeModule
(yield self.an_element())
C = self.coefficient_ring()
k = len(self.alphabet())
for dim in range(1, 11):
elements_M = MatrixSpace(C, dim).some_elements()
elements_V = FreeModule(C, dim).some_elements()
for _ in range(3):
mu = list(islice(elements_M, k))
LR = list(islice(elements_V, 2))
if ((len(mu) != k) or (len(LR) != 2)):
break
(yield self(mu, *LR, **kwds))
@cached_method
def _zero_(self):
'\n Return the zero element of this :class:`RecognizableSeriesSpace`,\n i.e. the unique neutral element for `+`.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Z = Rec._zero_(); Z\n 0\n sage: Z.linear_representation()\n ((), Finite family {0: [], 1: []}, ())\n '
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
from sage.sets.family import Family
return self.element_class(self, Family(self.alphabet(), (lambda a: Matrix())), vector([]), vector([]))
@cached_method
def one(self):
'\n Return the one element of this :class:`RecognizableSeriesSpace`,\n i.e. the embedding of the one of the coefficient ring into\n this :class:`RecognizableSeriesSpace`.\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: O = Rec.one(); O\n [] + ...\n sage: O.linear_representation()\n ((1), Finite family {0: [0], 1: [0]}, (1))\n\n TESTS::\n\n sage: Rec.one() is Rec.one()\n True\n '
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
R = self.coefficient_ring()
one = R.one()
zero = R.zero()
return self.element_class(self, (len(self.alphabet()) * [Matrix([[zero]])]), vector([one]), vector([one]))
@cached_method
def one_hadamard(self):
'\n Return the identity with respect to the\n :meth:`~RecognizableSeries.hadamard_product`, i.e. the\n coefficient-wise multiplication.\n\n OUTPUT:\n\n A :class:`RecognizableSeries`\n\n EXAMPLES::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n sage: Rec.one_hadamard()\n [] + [0] + [1] + [00] + [01] + [10]\n + [11] + [000] + [001] + [010] + ...\n\n TESTS::\n\n sage: Rec.one_hadamard() is Rec.one_hadamard()\n True\n '
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
one = self.coefficient_ring()(1)
return self({a: Matrix([[one]]) for a in self.alphabet()}, vector([one]), vector([one]))
def _element_constructor_(self, data, left=None, right=None):
"\n Return a recognizable series.\n\n See :class:`RecognizableSeriesSpace` for details.\n\n TESTS::\n\n sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])\n\n sage: Rec.zero()\n 0\n sage: type(_)\n <class 'sage.combinat.recognizable_series.RecognizableSeriesSpace_with_category.element_class'>\n\n ::\n\n sage: M0 = Matrix([[1, 0], [0, 1]])\n sage: M1 = Matrix([[0, -1], [1, 2]])\n sage: S = Rec((M0, M1), vector([0, 1]), vector([1, 1]))\n sage: Rec(S) is S\n True\n\n ::\n\n sage: A = Rec(42); A\n 42*[] + ...\n sage: A.linear_representation()\n ((42), Finite family {0: [0], 1: [0]}, (1))\n sage: Z = Rec(0); Z\n 0\n sage: Z.linear_representation()\n ((), Finite family {0: [], 1: []}, ())\n\n ::\n\n sage: Rec((M0, M1))\n Traceback (most recent call last):\n ...\n ValueError: left or right vector is None\n sage: Rec((M0, M1), [0, 1])\n Traceback (most recent call last):\n ...\n ValueError: left or right vector is None\n sage: Rec((M0, M1), left=[0, 1])\n Traceback (most recent call last):\n ...\n ValueError: left or right vector is None\n sage: Rec((M0, M1), right=[0, 1])\n Traceback (most recent call last):\n ...\n ValueError: left or right vector is None\n "
if (isinstance(data, int) and (data == 0)):
return self._zero_()
if (isinstance(data, self.element_class) and (data.parent() == self)):
element = data
elif isinstance(data, RecognizableSeries):
element = self.element_class(self, data.mu, data.left, data.right)
elif (data in self.coefficient_ring()):
c = self.coefficient_ring()(data)
return (c * self.one())
else:
mu = data
if ((left is None) or (right is None)):
raise ValueError('left or right vector is None')
element = self.element_class(self, mu, left, right)
return element
|
def pad_right(T, length, zero=0):
'\n Pad ``T`` to the right by using ``zero`` to have\n at least the given ``length``.\n\n INPUT:\n\n - ``T`` -- A tuple, list or other iterable\n\n - ``length`` -- a nonnegative integer\n\n - ``zero`` -- (default: ``0``) the elements to pad with\n\n OUTPUT:\n\n An object of the same type as ``T``\n\n EXAMPLES::\n\n sage: from sage.combinat.regular_sequence import pad_right\n sage: pad_right((1, 2, 3), 10)\n (1, 2, 3, 0, 0, 0, 0, 0, 0, 0)\n sage: pad_right((1, 2, 3), 2)\n (1, 2, 3)\n sage: pad_right([(1, 2), (3, 4)], 4, (0, 0))\n [(1, 2), (3, 4), (0, 0), (0, 0)]\n\n TESTS::\n\n sage: pad_right([1, 2, 3], 10)\n [1, 2, 3, 0, 0, 0, 0, 0, 0, 0]\n '
return (T + type(T)((zero for _ in range((length - len(T))))))
|
def value(D, k):
'\n Return the value of the expansion with digits `D` in base `k`, i.e.\n\n .. MATH::\n\n \\sum_{0\\leq j < \\operatorname{len}D} D[j] k^j.\n\n INPUT:\n\n - ``D`` -- a tuple or other iterable\n\n - ``k`` -- the base\n\n OUTPUT:\n\n An element in the common parent of the base `k` and of the entries\n of `D`\n\n EXAMPLES::\n\n sage: from sage.combinat.regular_sequence import value\n sage: value(42.digits(7), 7)\n 42\n '
return sum(((d * (k ** j)) for (j, d) in enumerate(D)))
|
class DegeneratedSequenceError(RuntimeError):
"\n Exception raised if a degenerated sequence\n (see :meth:`~RegularSequence.is_degenerated`) is detected.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))\n Traceback (most recent call last):\n ...\n DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.\n Using such a sequence might lead to wrong results.\n You can use 'allow_degenerated_sequence=True' followed\n by a call of method .regenerated() for correcting this.\n "
pass
|
class RegularSequence(RecognizableSeries):
def __init__(self, parent, mu, left=None, right=None):
'\n A `k`-regular sequence.\n\n INPUT:\n\n - ``parent`` -- an instance of :class:`RegularSequenceRing`\n\n - ``mu`` -- a family of square matrices, all of which have the\n same dimension. The indices of this family are `0,...,k-1`.\n ``mu`` may be a list or tuple of cardinality `k`\n as well. See also\n :meth:`~sage.combinat.recognizable_series.RecognizableSeries.mu`.\n\n - ``left`` -- (default: ``None``) a vector.\n When evaluating the sequence, this vector is multiplied\n from the left to the matrix product. If ``None``, then this\n multiplication is skipped.\n\n - ``right`` -- (default: ``None``) a vector.\n When evaluating the sequence, this vector is multiplied\n from the right to the matrix product. If ``None``, then this\n multiplication is skipped.\n\n When created via the parent :class:`RegularSequenceRing`, then\n the following option is available.\n\n - ``allow_degenerated_sequence`` -- (default: ``False``) a boolean. If set, then\n there will be no check if the input is a degenerated sequence\n (see :meth:`is_degenerated`).\n Otherwise the input is checked and a :class:`DegeneratedSequenceError`\n is raised if such a sequence is detected.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: S = Seq2((Matrix([[3, 0], [6, 1]]), Matrix([[0, 1], [-6, 5]])),\n ....: vector([1, 0]), vector([0, 1])); S\n 2-regular sequence 0, 1, 3, 5, 9, 11, 15, 19, 27, 29, ...\n\n We can access the coefficients of a sequence by\n ::\n\n sage: S[5]\n 11\n\n or iterating over the first, say `10`, by\n ::\n\n sage: from itertools import islice\n sage: list(islice(S, 10))\n [0, 1, 3, 5, 9, 11, 15, 19, 27, 29]\n\n .. SEEALSO::\n\n :doc:`k-regular sequence <regular_sequence>`,\n :class:`RegularSequenceRing`.\n\n TESTS::\n\n sage: Seq2(([[1, 0], [0, 1]], [[1, 1], [0, 1]]), (1, 0), (0, 1))\n 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...\n '
super().__init__(parent=parent, mu=mu, left=left, right=right)
def _repr_(self):
"\n Return a representation string of this `k`-regular sequence.\n\n OUTPUT: a string\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: s = Seq2((Matrix([[3, 0], [6, 1]]), Matrix([[0, 1], [-6, 5]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: repr(s) # indirect doctest\n '2-regular sequence 0, 1, 3, 5, 9, 11, 15, 19, 27, 29, ...'\n "
from sage.misc.lazy_list import lazy_list_formatter
return lazy_list_formatter(self, name='{}-regular sequence'.format(self.parent().k), opening_delimiter='', closing_delimiter='', preview=10)
@cached_method
def coefficient_of_n(self, n, **kwds):
'\n Return the `n`-th entry of this sequence.\n\n INPUT:\n\n - ``n`` -- a nonnegative integer\n\n OUTPUT: an element of the universe of the sequence\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: S = Seq2((Matrix([[1, 0], [0, 1]]), Matrix([[0, -1], [1, 2]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: S[7]\n 3\n\n This is equivalent to::\n\n sage: S.coefficient_of_n(7)\n 3\n\n TESTS::\n\n sage: S[-1]\n Traceback (most recent call last):\n ...\n ValueError: value -1 of index is negative\n\n ::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: W = Seq2.indices()\n sage: M0 = Matrix([[1, 0], [0, 1]])\n sage: M1 = Matrix([[0, -1], [1, 2]])\n sage: S = Seq2((M0, M1), vector([0, 1]), vector([1, 1]))\n sage: S._mu_of_word_(W(0.digits(2))) == M0\n True\n sage: S._mu_of_word_(W(1.digits(2))) == M1\n True\n sage: S._mu_of_word_(W(3.digits(2))) == M1^2\n True\n '
return self.coefficient_of_word(self.parent()._n_to_index_(n), **kwds)
__getitem__ = coefficient_of_n
def __iter__(self):
'\n Return an iterator over the coefficients of this sequence.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: S = Seq2((Matrix([[1, 0], [0, 1]]), Matrix([[0, -1], [1, 2]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: from itertools import islice\n sage: tuple(islice(S, 10))\n (0, 1, 1, 2, 1, 2, 2, 3, 1, 2)\n\n TESTS::\n\n sage: it = iter(S)\n sage: iter(it) is it\n True\n sage: iter(S) is not it\n True\n '
from itertools import count
return iter((self[n] for n in count()))
@cached_method
def is_degenerated(self):
"\n Return whether this `k`-regular sequence is degenerated,\n i.e., whether this `k`-regular sequence does not satisfiy\n `\\mu[0] \\mathit{right} = \\mathit{right}`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1])) # indirect doctest\n Traceback (most recent call last):\n ...\n DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.\n Using such a sequence might lead to wrong results.\n You can use 'allow_degenerated_sequence=True' followed\n by a call of method .regenerated() for correcting this.\n sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True)\n sage: S\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n sage: S.is_degenerated()\n True\n\n ::\n\n sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: C.is_degenerated()\n False\n "
from sage.rings.integer_ring import ZZ
return ((self.mu[ZZ(0)] * self.right) != self.right)
def _error_if_degenerated_(self):
"\n Raise an error if this `k`-regular sequence is degenerated,\n i.e., if this `k`-regular sequence does not satisfiy\n `\\mu[0] \\mathit{right} = \\mathit{right}`.\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: Seq2((Matrix([[3, 2], [0, 1]]), Matrix([[2, 0], [1, 3]])), # indirect doctest\n ....: left=vector([0, 1]), right=vector([1, 0]))\n Traceback (most recent call last):\n ...\n DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.\n Using such a sequence might lead to wrong results.\n You can use 'allow_degenerated_sequence=True' followed\n by a call of method .regenerated() for correcting this.\n "
if self.is_degenerated():
raise DegeneratedSequenceError("degenerated sequence: mu[0]*right != right. Using such a sequence might lead to wrong results. You can use 'allow_degenerated_sequence=True' followed by a call of method .regenerated() for correcting this.")
@cached_method
@minimize_result
def regenerated(self):
"\n Return a `k`-regular sequence that satisfies\n `\\mu[0] \\mathit{right} = \\mathit{right}` with the same values as\n this sequence.\n\n INPUT:\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n ALGORITHM:\n\n Theorem B of [HKL2022]_ with `n_0 = 1`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n\n The following linear representation of `S` is chosen badly (is\n degenerated, see :meth:`is_degenerated`), as `\\mu(0)` applied on\n `\\mathit{right}` does not equal `\\mathit{right}`::\n\n sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True)\n sage: S\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n sage: S.is_degenerated()\n True\n\n However, we can regenerate the sequence `S`::\n\n sage: H = S.regenerated()\n sage: H\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n sage: H.linear_representation()\n ((1, 0),\n Finite family {0: [ 0 1]\n [-2 3],\n 1: [3 0]\n [6 0]},\n (1, 1))\n sage: H.is_degenerated()\n False\n\n TESTS::\n\n sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True)\n sage: H = S.regenerated(minimize=False)\n sage: H.linear_representation()\n ((1, 0),\n Finite family {0: [ 2|-1]\n [--+--]\n [ 0| 1],\n 1: [3|0]\n [-+-]\n [0|0]},\n (1, 1))\n sage: H.is_degenerated()\n False\n "
if (not self.is_degenerated()):
return self
from sage.matrix.constructor import Matrix
from sage.matrix.special import zero_matrix, identity_matrix
from sage.modules.free_module_element import vector
P = self.parent()
dim = self.dimension()
Zc = zero_matrix(dim, 1)
Zr = zero_matrix(1, dim)
I = identity_matrix(dim)
itA = iter(P.alphabet())
z = next(itA)
W0 = Matrix(dim, 1, ((I - self.mu[z]) * self.right))
mu = {z: Matrix.block([[self.mu[z], W0], [Zr, 1]])}
mu.update(((r, Matrix.block([[self.mu[r], Zc], [Zr, 0]])) for r in itA))
return P.element_class(P, mu, vector((tuple(self.left) + (0,))), vector((tuple(self.right) + (1,))))
def transposed(self, allow_degenerated_sequence=False):
"\n Return the transposed sequence.\n\n INPUT:\n\n - ``allow_degenerated_sequence`` -- (default: ``False``) a boolean. If set, then\n there will be no check if the transposed sequence is a degenerated sequence\n (see :meth:`is_degenerated`).\n Otherwise the transposed sequence is checked and a :class:`DegeneratedSequenceError`\n is raised if such a sequence is detected.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n Each of the matrices in :meth:`mu <mu>` is transposed. Additionally\n the vectors :meth:`left <left>` and :meth:`right <right>` are switched.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: U = Seq2((Matrix([[3, 2], [0, 1]]), Matrix([[2, 0], [1, 3]])),\n ....: left=vector([0, 1]), right=vector([1, 0]),\n ....: allow_degenerated_sequence=True)\n sage: U.is_degenerated()\n True\n sage: Ut = U.transposed()\n sage: Ut.linear_representation()\n ((1, 0),\n Finite family {0: [3 0]\n [2 1],\n 1: [2 1]\n [0 3]},\n (0, 1))\n sage: Ut.is_degenerated()\n False\n\n sage: Ut.transposed()\n Traceback (most recent call last):\n ...\n DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.\n Using such a sequence might lead to wrong results.\n You can use 'allow_degenerated_sequence=True' followed\n by a call of method .regenerated() for correcting this.\n sage: Utt = Ut.transposed(allow_degenerated_sequence=True)\n sage: Utt.is_degenerated()\n True\n\n .. SEEALSO::\n\n :meth:`RecognizableSeries.transposed <sage.combinat.recognizable_series.RecognizableSeries.transposed>`\n "
element = super().transposed()
if (not allow_degenerated_sequence):
element._error_if_degenerated_()
return element
def _minimized_right_(self):
'\n Return a regular sequence equivalent to this series, but\n with a right minimized linear representation.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n .. SEEALSO::\n\n :meth:`RecognizableSeries._minimized_right_ <sage.combinat.recognizable_series.RecognizableSeries._minimized_right_>`\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: Seq2((Matrix([[3, 0], [2, 1]]), Matrix([[2, 1], [0, 3]])), # indirect doctest\n ....: left=vector([1, 0]), right=vector([0, 1])).minimized()\n 2-regular sequence 0, 1, 3, 5, 9, 11, 15, 19, 27, 29, ...\n '
return self.transposed(allow_degenerated_sequence=True)._minimized_left_().transposed(allow_degenerated_sequence=True)
@minimize_result
def subsequence(self, a, b):
"\n Return the subsequence with indices `an+b` of this\n `k`-regular sequence.\n\n INPUT:\n\n - ``a`` -- a nonnegative integer\n\n - ``b`` -- an integer\n\n Alternatively, this is allowed to be a dictionary\n `b_j \\mapsto c_j`. If so and applied on `f(n)`,\n the result will be the sum of all `c_j \\cdot f(an+b_j)`.\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n .. NOTE::\n\n If `b` is negative (i.e., right-shift), then the\n coefficients when accessing negative indices are `0`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n\n We consider the sequence `C` with `C(n) = n` and\n the following linear representation\n corresponding to the vector `(n, 1)`::\n\n sage: C = Seq2((Matrix([[2, 0], [0, 1]]), Matrix([[2, 1], [0, 1]])),\n ....: vector([1, 0]), vector([0, 1])); C\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n\n We now extract various subsequences of `C`::\n\n sage: C.subsequence(2, 0)\n 2-regular sequence 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, ...\n\n sage: S31 = C.subsequence(3, 1); S31\n 2-regular sequence 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, ...\n sage: S31.linear_representation()\n ((1, 0),\n Finite family {0: [ 0 1]\n [-2 3],\n 1: [ 6 -2]\n [10 -3]},\n (1, 1))\n\n sage: C.subsequence(3, 2)\n 2-regular sequence 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, ...\n\n ::\n\n sage: Srs = C.subsequence(1, -1); Srs\n 2-regular sequence 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, ...\n sage: Srs.linear_representation()\n ((1, 0, 0),\n Finite family {0: [ 0 1 0]\n [-2 3 0]\n [-4 4 1],\n 1: [ -2 2 0]\n [ 0 0 1]\n [ 12 -12 5]},\n (0, 0, 1))\n\n We can build :meth:`backward_differences` manually by passing\n a dictionary for the parameter ``b``::\n\n sage: Sbd = C.subsequence(1, {0: 1, -1: -1}); Sbd\n 2-regular sequence 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n\n TESTS:\n\n We check if the linear representation of the subsequences above\n indeed represent the correct vector valued sequences::\n\n sage: var('n')\n n\n\n sage: def v(n):\n ....: return vector([3*n + 1, 6*n + 1])\n sage: S31.mu[0] * v(n) == v(2*n)\n True\n sage: S31.mu[1] * v(n) == v(2*n + 1)\n True\n\n sage: function('delta_0')\n delta_0\n\n sage: def simplify_delta(expr):\n ....: return expr.subs({delta_0(2*n): delta_0(n), delta_0(2*n + 1): 0})\n\n sage: def v(n):\n ....: return vector([n -1 + delta_0(n), 2*n - 1 + delta_0(n), 4*n + 1])\n sage: simplify_delta(v(2*n) - Srs.mu[0]*v(n)).is_zero()\n True\n sage: simplify_delta(v(2*n + 1) - Srs.mu[1]*v(n)).is_zero()\n True\n\n sage: def v(n):\n ....: return vector([1 - delta_0(n), 1])\n\n sage: simplify_delta(v(2*n) - Sbd.mu[0]*v(n)).is_zero()\n True\n sage: simplify_delta(v(2*n + 1) - Sbd.mu[1]*v(n)).is_zero()\n True\n\n We check some corner-cases::\n\n sage: C.subsequence(0, 4)\n 2-regular sequence 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ...\n\n ::\n\n sage: C.subsequence(1, 0, minimize=False) is C\n True\n\n The following test that the range for `c` in the code\n is sufficient::\n\n sage: C.subsequence(1, -1, minimize=False)\n 2-regular sequence 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, ...\n sage: C.subsequence(1, -2, minimize=False)\n 2-regular sequence 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, ...\n sage: C.subsequence(2, -1, minimize=False)\n 2-regular sequence 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, ...\n sage: C.subsequence(2, -2, minimize=False)\n 2-regular sequence 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, ...\n\n sage: C.subsequence(2, 21, minimize=False)\n 2-regular sequence 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, ...\n sage: C.subsequence(2, 20, minimize=False)\n 2-regular sequence 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, ...\n sage: C.subsequence(2, 19, minimize=False)\n 2-regular sequence 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, ...\n sage: C.subsequence(2, -9, minimize=False)\n 2-regular sequence 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, ...\n\n sage: C.subsequence(3, 21, minimize=False)\n 2-regular sequence 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, ...\n sage: C.subsequence(3, 20, minimize=False)\n 2-regular sequence 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, ...\n sage: C.subsequence(3, 19, minimize=False)\n 2-regular sequence 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, ...\n sage: C.subsequence(3, 18, minimize=False)\n 2-regular sequence 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, ...\n\n sage: C.subsequence(10, 2, minimize=False)\n 2-regular sequence 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, ...\n sage: C.subsequence(10, 1, minimize=False)\n 2-regular sequence 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, ...\n sage: C.subsequence(10, 0, minimize=False)\n 2-regular sequence 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, ...\n sage: C.subsequence(10, -1, minimize=False)\n 2-regular sequence 0, 9, 19, 29, 39, 49, 59, 69, 79, 89, ...\n sage: C.subsequence(10, -2, minimize=False)\n 2-regular sequence 0, 8, 18, 28, 38, 48, 58, 68, 78, 88, ...\n\n ::\n\n sage: C.subsequence(-1, 0)\n Traceback (most recent call last):\n ...\n ValueError: a=-1 is not nonnegative.\n\n The following linear representation of `S` is chosen badly (is\n degenerated, see :meth:`is_degenerated`), as `\\mu(0)` applied on\n `\\mathit{right}` does not equal `\\mathit{right}`::\n\n sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True)\n sage: S\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n\n This leads to the wrong result\n ::\n\n sage: S.subsequence(1, -4)\n 2-regular sequence 0, 0, 0, 0, 8, 12, 12, 18, 24, 36, ...\n\n We get the correct result by\n ::\n\n sage: S.regenerated().subsequence(1, -4)\n 2-regular sequence 0, 0, 0, 0, 1, 3, 6, 9, 12, 18, ...\n "
from itertools import chain
from sage.rings.integer_ring import ZZ
zero = ZZ(0)
a = ZZ(a)
if (not isinstance(b, dict)):
b = {ZZ(b): ZZ(1)}
if (a == 0):
return sum((((c_j * self[b_j]) * self.parent().one_hadamard()) for (b_j, c_j) in b.items()))
elif ((a == 1) and (len(b) == 1) and (zero in b)):
return (b[zero] * self)
elif (a < 0):
raise ValueError('a={} is not nonnegative.'.format(a))
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
P = self.parent()
A = P.alphabet()
k = P.k
kernel = list(b)
zero_M = self.mu[0].parent().zero()
zero_R = self.right.parent().zero()
rule = {}
ci = 0
while (ci < len(kernel)):
c = kernel[ci]
for r in A:
(d, f) = ((a * r) + c).quo_rem(k)
if (d not in kernel):
kernel.append(d)
rule[(r, c)] = (d, f)
ci += 1
def matrix_row(r, c):
(d, f) = rule[(r, c)]
return [(self.mu[f] if (d == j) else zero_M) for j in kernel]
result = P.element_class(P, {r: Matrix.block([matrix_row(r, c) for c in kernel]) for r in A}, vector(chain.from_iterable(((b.get(c, 0) * self.left) for c in kernel))), vector(chain.from_iterable(((self.coefficient_of_n(c, multiply_left=False) if (c >= 0) else zero_R) for c in kernel))))
return result
def shift_left(self, b=1, **kwds):
"\n Return the sequence obtained by shifting\n this `k`-regular sequence `b` steps to the left.\n\n INPUT:\n\n - ``b`` -- an integer\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n .. NOTE::\n\n If `b` is negative (i.e., actually a right-shift), then the\n coefficients when accessing negative indices are `0`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: C = Seq2((Matrix([[2, 0], [0, 1]]), Matrix([[2, 1], [0, 1]])),\n ....: vector([1, 0]), vector([0, 1])); C\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n\n sage: C.shift_left()\n 2-regular sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...\n sage: C.shift_left(3)\n 2-regular sequence 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ...\n sage: C.shift_left(-2)\n 2-regular sequence 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, ...\n\n TESTS::\n\n sage: C.shift_left(0) == C\n True\n sage: C.shift_left(2).shift_right(2)\n 2-regular sequence 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, ...\n "
return self.subsequence(1, b, **kwds)
def shift_right(self, b=1, **kwds):
"\n Return the sequence obtained by shifting\n this `k`-regular sequence `b` steps to the right.\n\n INPUT:\n\n - ``b`` -- an integer\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n .. NOTE::\n\n If `b` is positive (i.e., indeed a right-shift), then the\n coefficients when accessing negative indices are `0`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: C = Seq2((Matrix([[2, 0], [0, 1]]), Matrix([[2, 1], [0, 1]])),\n ....: vector([1, 0]), vector([0, 1])); C\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n\n sage: C.shift_right()\n 2-regular sequence 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, ...\n sage: C.shift_right(3)\n 2-regular sequence 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, ...\n sage: C.shift_right(-2)\n 2-regular sequence 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...\n\n TESTS::\n\n sage: C.shift_right(0) == C\n True\n sage: C.shift_right().shift_left()\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n sage: C.shift_right(2).shift_left(2)\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n sage: _ == C\n True\n "
return self.subsequence(1, (- b), **kwds)
def backward_differences(self, **kwds):
"\n Return the sequence of backward differences of this\n `k`-regular sequence.\n\n INPUT:\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n .. NOTE::\n\n The coefficient to the index `-1` is `0`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: C\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n sage: C.backward_differences()\n 2-regular sequence 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n\n ::\n\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: E\n 2-regular sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...\n sage: E.backward_differences()\n 2-regular sequence 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, ...\n "
return self.subsequence(1, {0: 1, (- 1): (- 1)}, **kwds)
def forward_differences(self, **kwds):
"\n Return the sequence of forward differences of this\n `k`-regular sequence.\n\n INPUT:\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: C\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n sage: C.forward_differences()\n 2-regular sequence 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n\n ::\n\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: E\n 2-regular sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...\n sage: E.forward_differences()\n 2-regular sequence -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, ...\n "
return self.subsequence(1, {1: 1, 0: (- 1)}, **kwds)
@minimize_result
def _mul_(self, other):
"\n Return the product of this `k`-regular sequence with ``other``,\n where the multiplication is convolution of power series.\n\n The operator `*` is mapped to :meth:`convolution`.\n\n INPUT:\n\n - ``other`` -- a :class:`RegularSequence`\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n ALGORITHM:\n\n See pdf attached to\n `github pull request #35894 <https://github.com/sagemath/sage/pull/35894>`_\n which contains a draft describing the details of the used algorithm.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: E\n 2-regular sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...\n\n We can build the convolution (in the sense of power-series) of `E` by\n itself via::\n\n sage: E.convolution(E)\n 2-regular sequence 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, ...\n\n This is the same as using multiplication operator::\n\n sage: E * E\n 2-regular sequence 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, ...\n\n Building :meth:`partial_sums` can also be seen as a convolution::\n\n sage: o = Seq2.one_hadamard()\n sage: E * o\n 2-regular sequence 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, ...\n sage: E * o == E.partial_sums(include_n=True)\n True\n\n TESTS::\n\n sage: E * o == o * E\n True\n "
from sage.arith.srange import srange
from sage.matrix.constructor import Matrix
from sage.matrix.special import zero_matrix
from sage.modules.free_module_element import vector
P = self.parent()
k = P.k
def tensor_product(left, right):
T = left.tensor_product(right)
T.subdivide()
return T
matrices_0 = {r: sum((tensor_product(self.mu[s], other.mu[(r - s)]) for s in srange(0, (r + 1)))) for r in P.alphabet()}
matrices_1 = {r: sum((tensor_product(self.mu[s], other.mu[((k + r) - s)]) for s in srange((r + 1), k))) for r in P.alphabet()}
left = vector(tensor_product(Matrix(self.left), Matrix(other.left)))
right = vector(tensor_product(Matrix(self.right), Matrix(other.right)))
def linear_representation_morphism_recurrence_order_1(C, D):
'\n Return the morphism of a linear representation\n for the sequence `z_n` satisfying\n `z_{kn+r} = C_r z_n + D_r z_{n-1}`.\n '
Z = zero_matrix(C[0].dimensions()[0])
def blocks(r):
upper = list(([C[s], D[s], Z] for s in reversed(srange(max(0, (r - 2)), (r + 1)))))
lower = list(([Z, C[s], D[s]] for s in reversed(srange(((k - 3) + len(upper)), k))))
return (upper + lower)
return {r: Matrix.block(blocks(r)) for r in P.alphabet()}
result = P.element_class(P, linear_representation_morphism_recurrence_order_1(matrices_0, matrices_1), vector((list(left) + ((2 * len(list(left))) * [0]))), vector((list(right) + ((2 * len(list(right))) * [0]))))
return result
convolution = _mul_
@minimize_result
def partial_sums(self, include_n=False):
"\n Return the sequence of partial sums of this\n `k`-regular sequence. That is, the `n`-th entry of the result\n is the sum of the first `n` entries in the original sequence.\n\n INPUT:\n\n - ``include_n`` -- (default: ``False``) a boolean. If set, then\n the `n`-th entry of the result is the sum of the entries up\n to index `n` (included).\n\n - ``minimize`` -- (default: ``None``) a boolean or ``None``.\n If ``True``, then :meth:`~RecognizableSeries.minimized` is called after the operation,\n if ``False``, then not. If this argument is ``None``, then\n the default specified by the parent's ``minimize_results`` is used.\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n\n sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),\n ....: vector([1, 0]), vector([1, 1]))\n sage: E\n 2-regular sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...\n sage: E.partial_sums()\n 2-regular sequence 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, ...\n sage: E.partial_sums(include_n=True)\n 2-regular sequence 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, ...\n\n ::\n\n sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])),\n ....: vector([1, 0]), vector([0, 1]))\n sage: C\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n sage: C.partial_sums()\n 2-regular sequence 0, 0, 1, 3, 6, 10, 15, 21, 28, 36, ...\n sage: C.partial_sums(include_n=True)\n 2-regular sequence 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, ...\n\n The following linear representation of `S` is chosen badly (is\n degenerated, see :meth:`is_degenerated`), as `\\mu(0)` applied on\n `\\mathit{right}` does not equal `\\mathit{right}`::\n\n sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True)\n sage: S\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n\n Therefore, building partial sums produces a wrong result::\n\n sage: H = S.partial_sums(include_n=True, minimize=False)\n sage: H\n 2-regular sequence 1, 5, 16, 25, 62, 80, 98, 125, 274, 310, ...\n sage: H = S.partial_sums(minimize=False)\n sage: H\n 2-regular sequence 0, 2, 10, 16, 50, 62, 80, 98, 250, 274, ...\n\n We can :meth:`~RegularSequenceRing.guess` the correct representation::\n\n sage: from itertools import islice\n sage: L = []; ps = 0\n sage: for s in islice(S, 110):\n ....: ps += s\n ....: L.append(ps)\n sage: G = Seq2.guess(lambda n: L[n])\n sage: G\n 2-regular sequence 1, 4, 10, 19, 31, 49, 67, 94, 118, 154, ...\n sage: G.linear_representation()\n ((1, 0, 0, 0),\n Finite family {0: [ 0 1 0 0]\n [ 0 0 0 1]\n [ -5 5 1 0]\n [ 10 -17 0 8],\n 1: [ 0 0 1 0]\n [ -5 3 3 0]\n [ -5 0 6 0]\n [-30 21 10 0]},\n (1, 1, 4, 1))\n sage: G.minimized().dimension() == G.dimension()\n True\n\n Or we regenerate the sequence `S` first::\n\n sage: S.regenerated().partial_sums(include_n=True, minimize=False)\n 2-regular sequence 1, 4, 10, 19, 31, 49, 67, 94, 118, 154, ...\n sage: S.regenerated().partial_sums(minimize=False)\n 2-regular sequence 0, 1, 4, 10, 19, 31, 49, 67, 94, 118, ...\n\n TESTS::\n\n sage: E.linear_representation()\n ((1, 0),\n Finite family {0: [0 1]\n [0 1],\n 1: [0 0]\n [0 1]},\n (1, 1))\n\n sage: P = E.partial_sums(minimize=False)\n sage: P.linear_representation()\n ((1, 0, 0, 0),\n Finite family {0: [0 1|0 0]\n [0 2|0 0]\n [---+---]\n [0 0|0 1]\n [0 0|0 1],\n 1: [0 1|0 1]\n [0 2|0 1]\n [---+---]\n [0 0|0 0]\n [0 0|0 1]},\n (0, 0, 1, 1))\n\n sage: P = E.partial_sums(include_n=True, minimize=False)\n sage: P.linear_representation()\n ((1, 0, 1, 0),\n Finite family {0: [0 1|0 0]\n [0 2|0 0]\n [---+---]\n [0 0|0 1]\n [0 0|0 1],\n 1: [0 1|0 1]\n [0 2|0 1]\n [---+---]\n [0 0|0 0]\n [0 0|0 1]},\n (0, 0, 1, 1))\n "
from itertools import chain
from sage.matrix.constructor import Matrix
from sage.matrix.special import zero_matrix
from sage.modules.free_module_element import vector
P = self.parent()
A = P.alphabet()
k = P.k
dim = self.dimension()
Z = zero_matrix(dim)
z = A[0]
assert (z == 0)
B = {z: Z}
for r in A:
B[(r + 1)] = (B[r] + self.mu[r])
C = B[k]
result = P.element_class(P, {r: Matrix.block([[C, B[r]], [Z, self.mu[r]]]) for r in A}, vector(chain(self.left, ((dim * (0,)) if (not include_n) else self.left))), vector(chain((dim * (0,)), self.right)))
return result
|
def _pickle_RegularSequenceRing(k, coefficients, category):
'\n Pickle helper.\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: from sage.combinat.regular_sequence import _pickle_RegularSequenceRing\n sage: _pickle_RegularSequenceRing(\n ....: Seq2.k, Seq2.coefficient_ring(), Seq2.category())\n Space of 2-regular sequences over Integer Ring\n '
return RegularSequenceRing(k, coefficients, category=category)
|
class RegularSequenceRing(RecognizableSeriesSpace):
'\n The space of `k`-regular Sequences over the given ``coefficient_ring``.\n\n INPUT:\n\n - ``k`` -- an integer at least `2` specifying the base\n\n - ``coefficient_ring`` -- a (semi-)ring\n\n - ``category`` -- (default: ``None``) the category of this\n space\n\n EXAMPLES::\n\n sage: RegularSequenceRing(2, ZZ)\n Space of 2-regular sequences over Integer Ring\n sage: RegularSequenceRing(3, ZZ)\n Space of 3-regular sequences over Integer Ring\n\n .. SEEALSO::\n\n :doc:`k-regular sequence <regular_sequence>`,\n :class:`RegularSequence`.\n '
Element = RegularSequence
@classmethod
def __normalize__(cls, k, coefficient_ring, category=None, **kwds):
'\n Normalizes the input in order to ensure a unique\n representation.\n\n For more information see :class:`RegularSequenceRing`.\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: Seq2.category()\n Category of algebras over Integer Ring\n sage: Seq2.alphabet()\n {0, 1}\n '
from sage.arith.srange import srange
from sage.categories.algebras import Algebras
category = (category or Algebras(coefficient_ring))
nargs = super().__normalize__(coefficient_ring, alphabet=srange(k), category=category, **kwds)
return ((k,) + nargs)
def __init__(self, k, *args, **kwds):
'\n See :class:`RegularSequenceRing` for details.\n\n INPUT:\n\n - ``k`` -- an integer at least `2` specifying the base\n\n Other input arguments are passed on to\n :meth:`~sage.combinat.recognizable_series.RecognizableSeriesSpace.__init__`.\n\n TESTS::\n\n sage: RegularSequenceRing(2, ZZ)\n Space of 2-regular sequences over Integer Ring\n sage: RegularSequenceRing(3, ZZ)\n Space of 3-regular sequences over Integer Ring\n\n ::\n\n sage: from itertools import islice\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: TestSuite(Seq2).run( # long time\n ....: elements=tuple(islice(Seq2.some_elements(), 4)))\n\n .. SEEALSO::\n\n :doc:`k-regular sequence <regular_sequence>`,\n :class:`RegularSequence`.\n '
self.k = k
super().__init__(*args, **kwds)
def __reduce__(self):
'\n Pickling support.\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: loads(dumps(Seq2)) # indirect doctest\n Space of 2-regular sequences over Integer Ring\n '
return (_pickle_RegularSequenceRing, (self.k, self.coefficient_ring(), self.category()))
def _repr_(self):
"\n Return a representation string of this `k`-regular sequence space.\n\n OUTPUT: a string\n\n TESTS::\n\n sage: repr(RegularSequenceRing(2, ZZ)) # indirect doctest\n 'Space of 2-regular sequences over Integer Ring'\n "
return 'Space of {}-regular sequences over {}'.format(self.k, self.base())
def _n_to_index_(self, n):
'\n Convert `n` to an index usable by the underlying\n recognizable series.\n\n INPUT:\n\n - ``n`` -- a nonnegative integer\n\n OUTPUT: a word\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: Seq2._n_to_index_(6)\n word: 011\n sage: Seq2._n_to_index_(-1)\n Traceback (most recent call last):\n ...\n ValueError: value -1 of index is negative\n '
from sage.rings.integer_ring import ZZ
n = ZZ(n)
W = self.indices()
try:
return W(n.digits(self.k))
except OverflowError:
raise ValueError('value {} of index is negative'.format(n)) from None
@cached_method
def one(self):
'\n Return the one element of this :class:`RegularSequenceRing`,\n i.e. the unique neutral element for `*` and also\n the embedding of the one of the coefficient ring into\n this :class:`RegularSequenceRing`.\n\n EXAMPLES::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: O = Seq2.one(); O\n 2-regular sequence 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...\n sage: O.linear_representation()\n ((1), Finite family {0: [1], 1: [0]}, (1))\n\n TESTS::\n\n sage: Seq2.one() is Seq2.one()\n True\n '
from sage.matrix.constructor import Matrix
from sage.modules.free_module_element import vector
R = self.coefficient_ring()
one = R.one()
zero = R.zero()
return self.element_class(self, ([Matrix([[one]])] + ((self.k - 1) * [Matrix([[zero]])])), vector([one]), vector([one]))
def some_elements(self):
'\n Return some elements of this `k`-regular sequence.\n\n See :class:`TestSuite` for a typical use case.\n\n OUTPUT:\n\n An iterator\n\n EXAMPLES::\n\n sage: tuple(RegularSequenceRing(2, ZZ).some_elements())\n (2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...,\n 2-regular sequence 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, ...,\n 2-regular sequence 1, 1, 0, 1, -1, 0, 0, 1, -2, -1, ...,\n 2-regular sequence 2, -1, 0, 0, 0, -1, 0, 0, 0, 0, ...,\n 2-regular sequence 1, 1, 0, 1, 5, 0, 0, 1, -33, 5, ...,\n 2-regular sequence -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...,\n 2-regular sequence -59, -20, 0, -20, 0, 0, 0, -20, 0, 0, ...,\n ...\n 2-regular sequence 2210, 170, 0, 0, 0, 0, 0, 0, 0, 0, ...)\n '
return iter((element.regenerated() for element in super().some_elements(allow_degenerated_sequence=True)))
def _element_constructor_(self, *args, **kwds):
"\n Return a `k`-regular sequence.\n\n See :class:`RegularSequenceRing` for details.\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]))\n Traceback (most recent call last):\n ...\n DegeneratedSequenceError: degenerated sequence: mu[0]*right != right.\n Using such a sequence might lead to wrong results.\n You can use 'allow_degenerated_sequence=True' followed\n by a call of method .regenerated() for correcting this.\n sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True)\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n sage: Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True).regenerated()\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n "
allow_degenerated_sequence = kwds.pop('allow_degenerated_sequence', False)
element = super()._element_constructor_(*args, **kwds)
if (not allow_degenerated_sequence):
element._error_if_degenerated_()
return element
def guess(self, f, n_verify=100, max_exponent=10, sequence=None):
'\n Guess a `k`-regular sequence whose first terms coincide with `(f(n))_{n\\geq0}`.\n\n INPUT:\n\n - ``f`` -- a function (callable) which determines the sequence.\n It takes nonnegative integers as an input\n\n - ``n_verify`` -- (default: ``100``) a positive integer. The resulting\n `k`-regular sequence coincides with `f` on the first ``n_verify``\n terms.\n\n - ``max_exponent`` -- (default: ``10``) a positive integer specifying\n the maximum exponent of `k` which is tried when guessing the sequence,\n i.e., relations between `f(k^t n+r)` are used for\n `0\\le t\\le \\mathtt{max\\_exponent}` and `0\\le r < k^j`\n\n - ``sequence`` -- (default: ``None``) a `k`-regular sequence used\n for bootstrapping the guessing by adding information of the\n linear representation of ``sequence`` to the guessed representation\n\n OUTPUT:\n\n A :class:`RegularSequence`\n\n ALGORITHM:\n\n For the purposes of this description, the right vector valued sequence\n associated with a regular sequence consists of the\n corresponding matrix product multiplied by the right vector,\n but without the left vector of the regular sequence.\n\n The algorithm maintains a right vector valued sequence consisting\n of the right vector valued sequence of the argument ``sequence``\n (replaced by an empty tuple if ``sequence`` is ``None``) plus several\n components of the shape `m \\mapsto f(k^t\\cdot m +r)` for suitable\n ``t`` and ``r``.\n\n Implicitly, the algorithm also maintains a `d \\times n_\\mathrm{verify}` matrix ``A``\n (where ``d`` is the dimension of the right vector valued sequence)\n whose columns are the current right vector valued sequence evaluated at\n the non-negative integers less than `n_\\mathrm{verify}` and ensures that this\n matrix has full row rank.\n\n EXAMPLES:\n\n Binary sum of digits::\n\n sage: @cached_function\n ....: def s(n):\n ....: if n == 0:\n ....: return 0\n ....: return s(n//2) + ZZ(is_odd(n))\n sage: all(s(n) == sum(n.digits(2)) for n in srange(10))\n True\n sage: [s(n) for n in srange(10)]\n [0, 1, 1, 2, 1, 2, 2, 3, 1, 2]\n\n Let us guess a `2`-linear representation for `s(n)`::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: import logging\n sage: logging.getLogger().setLevel(logging.INFO)\n sage: S1 = Seq2.guess(s); S1\n INFO:...:including f_{1*m+0}\n INFO:...:including f_{2*m+1}\n 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...\n sage: S1.linear_representation()\n ((1, 0),\n Finite family {0: [1 0]\n [0 1],\n 1: [ 0 1]\n [-1 2]},\n (0, 1))\n\n The ``INFO`` messages mean that the right vector valued sequence is the sequence `(s(n), s(2n+1))^\\top`.\n\n We guess again, but this time, we use a constant sequence\n for bootstrapping the guessing process::\n\n sage: C = Seq2.one_hadamard(); C\n 2-regular sequence 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n sage: S2 = Seq2.guess(s, sequence=C); S2\n INFO:...:including 2-regular sequence 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n INFO:...:including f_{1*m+0}\n 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...\n sage: S2.linear_representation()\n ((0, 1),\n Finite family {0: [1 0]\n [0 1],\n 1: [1 0]\n [1 1]},\n (1, 0))\n sage: S1 == S2\n True\n\n The sequence of all natural numbers::\n\n sage: S = Seq2.guess(lambda n: n); S\n INFO:...:including f_{1*m+0}\n INFO:...:including f_{2*m+1}\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n sage: S.linear_representation()\n ((1, 0),\n Finite family {0: [2 0]\n [2 1],\n 1: [ 0 1]\n [-2 3]},\n (0, 1))\n\n The indicator function of the even integers::\n\n sage: S = Seq2.guess(lambda n: ZZ(is_even(n))); S\n INFO:...:including f_{1*m+0}\n INFO:...:including f_{2*m+0}\n 2-regular sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...\n sage: S.linear_representation()\n ((1, 0),\n Finite family {0: [0 1]\n [0 1],\n 1: [0 0]\n [0 1]},\n (1, 1))\n\n The indicator function of the odd integers::\n\n sage: S = Seq2.guess(lambda n: ZZ(is_odd(n))); S\n INFO:...:including f_{1*m+0}\n INFO:...:including f_{2*m+1}\n 2-regular sequence 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, ...\n sage: S.linear_representation()\n ((1, 0),\n Finite family {0: [0 0]\n [0 1],\n 1: [0 1]\n [0 1]},\n (0, 1))\n sage: logging.getLogger().setLevel(logging.WARN)\n\n The following linear representation of `S` is chosen badly (is\n degenerated, see :meth:`is_degenerated`), as `\\mu(0)` applied on\n `\\mathit{right}` does not equal `\\mathit{right}`::\n\n sage: S = Seq2((Matrix([2]), Matrix([3])), vector([1]), vector([1]),\n ....: allow_degenerated_sequence=True)\n sage: S\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n sage: S.is_degenerated()\n True\n\n However, we can :meth:`~RegularSequenceRing.guess` a `2`-regular sequence of dimension `2`::\n\n sage: G = Seq2.guess(lambda n: S[n])\n sage: G\n 2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...\n sage: G.linear_representation()\n ((1, 0),\n Finite family {0: [ 0 1]\n [-2 3],\n 1: [3 0]\n [6 0]},\n (1, 1))\n\n sage: G == S.regenerated()\n True\n\n TESTS::\n\n sage: from importlib import reload\n sage: logging.shutdown(); _ = reload(logging)\n sage: logging.basicConfig(level=logging.DEBUG)\n sage: Seq2.guess(s)\n INFO:...:including f_{1*m+0}\n DEBUG:...:M_0: f_{2*m+0} = (1) * F_m\n INFO:...:including f_{2*m+1}\n DEBUG:...:M_1: f_{2*m+1} = (0, 1) * F_m\n DEBUG:...:M_0: f_{4*m+1} = (0, 1) * F_m\n DEBUG:...:M_1: f_{4*m+3} = (-1, 2) * F_m\n 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...\n sage: from importlib import reload\n sage: logging.shutdown(); _ = reload(logging)\n\n ::\n\n sage: S = Seq2.guess(lambda n: 2, sequence=C)\n sage: S\n 2-regular sequence 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ...\n sage: S.linear_representation()\n ((2),\n Finite family {0: [1],\n 1: [1]},\n (1))\n\n We :meth:`~RegularSequenceRing.guess` some partial sums sequences::\n\n sage: S = Seq2((Matrix([1]), Matrix([2])), vector([1]), vector([1]))\n sage: S\n 2-regular sequence 1, 2, 2, 4, 2, 4, 4, 8, 2, 4, ...\n sage: from itertools import islice\n sage: L = []; ps = 0\n sage: for j in islice(S, 110):\n ....: ps += j\n ....: L.append(ps)\n sage: G = Seq2.guess(lambda n: L[n])\n sage: G\n 2-regular sequence 1, 3, 5, 9, 11, 15, 19, 27, 29, 33, ...\n sage: G.linear_representation()\n ((1, 0),\n Finite family {0: [ 0 1]\n [-3 4],\n 1: [3 0]\n [3 2]},\n (1, 1))\n sage: G == S.partial_sums(include_n=True)\n True\n\n ::\n\n sage: Seq3 = RegularSequenceRing(3, QQ)\n sage: S = Seq3((Matrix([1]), Matrix([3]), Matrix([2])), vector([1]), vector([1]))\n sage: S\n 3-regular sequence 1, 3, 2, 3, 9, 6, 2, 6, 4, 3, ...\n sage: from itertools import islice\n sage: L = []; ps = 0\n sage: for j in islice(S, 110):\n ....: ps += j\n ....: L.append(ps)\n sage: G = Seq3.guess(lambda n: L[n])\n sage: G\n 3-regular sequence 1, 4, 6, 9, 18, 24, 26, 32, 36, 39, ...\n sage: G.linear_representation()\n ((1, 0),\n Finite family {0: [ 0 1]\n [-6 7],\n 1: [18/5 2/5]\n [18/5 27/5],\n 2: [ 6 0]\n [24 2]},\n (1, 1))\n sage: G == S.partial_sums(include_n=True)\n True\n\n ::\n\n sage: Seq2.guess(s, max_exponent=1)\n Traceback (most recent call last):\n ...\n RuntimeError: aborting as exponents would be larger than max_exponent=1\n\n ::\n\n sage: R = RegularSequenceRing(2, QQ)\n sage: one = R.one_hadamard()\n sage: S = R.guess(lambda n: sum(n.bits()), sequence=one) + one\n sage: T = R.guess(lambda n: n*n, sequence=S, n_verify=4); T\n 2-regular sequence 0, 1, 4, 9, 16, 25, 36, 163/3, 64, 89, ...\n sage: T.linear_representation()\n ((0, 0, 1),\n Finite family {0: [1 0 0]\n [0 1 0]\n [0 0 4],\n 1: [ 0 1 0]\n [ -1 2 0]\n [13/3 -5/3 16/3]},\n (1, 2, 0))\n\n ::\n\n sage: two = Seq2.one_hadamard() * 2\n sage: two.linear_representation()\n ((1), Finite family {0: [1], 1: [1]}, (2))\n sage: two_again = Seq2.guess(lambda n: 2, sequence=two)\n sage: two_again.linear_representation()\n ((1), Finite family {0: [1], 1: [1]}, (2))\n\n ::\n\n sage: def s(k):\n ....: return k\n sage: S1 = Seq2.guess(s)\n sage: S2 = Seq2.guess(s, sequence=S1)\n sage: S1\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n sage: S2\n 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...\n\n ::\n\n sage: A = Seq2(\n ....: (Matrix([[1, 1], [1, 1]]), Matrix([[1, 1], [1, 1]])),\n ....: left=(1, 1), right=(1, 1),\n ....: allow_degenerated_sequence=True)\n sage: Seq2.guess(lambda n: n, sequence=A, n_verify=5)\n Traceback (most recent call last):\n ...\n RuntimeError: no invertible submatrix found\n '
import logging
logger = logging.getLogger(__name__)
from sage.arith.srange import srange, xsrange
from sage.matrix.constructor import Matrix
from sage.misc.mrange import cantor_product
from sage.modules.free_module_element import vector
k = self.k
domain = self.coefficient_ring()
if (sequence is None):
mu = [[] for _ in srange(k)]
seq = (lambda m: vector([]))
else:
mu = [M.rows() for M in sequence.mu]
seq = (lambda m: sequence.coefficient_of_n(m, multiply_left=False))
logger.info('including %s', sequence)
zero = domain(0)
one = domain(1)
def values(m, lines):
'\n Return current (as defined by ``lines``) right vector valued\n sequence for argument ``m``.\n '
return (tuple(seq(m)) + tuple((f((((k ** t_R) * m) + r_R)) for (t_R, r_R) in lines)))
@cached_function(key=(lambda lines: len(lines)))
def some_inverse_U_matrix(lines):
'\n Find an invertible `d \\times d` submatrix of the matrix\n ``A`` described in the algorithm section of the docstring.\n\n The output is the inverse of the invertible submatrix and\n the corresponding list of column indices (i.e., arguments to\n the current right vector valued sequence).\n '
d = (len(seq(0)) + len(lines))
for m_indices in cantor_product(xsrange(n_verify), repeat=d, min_slope=1):
U = Matrix(domain, d, d, [values(m, lines) for m in m_indices]).transpose()
try:
return (U.inverse(), m_indices)
except ZeroDivisionError:
pass
else:
raise RuntimeError('no invertible submatrix found')
def linear_combination_candidate(t_L, r_L, lines):
'\n Based on an invertible submatrix of ``A`` as described in the\n algorithm section of the docstring, find a candidate for a\n linear combination of the rows of ``A`` yielding the subsequence\n with parameters ``t_L`` and ``r_L``, i.e.,\n `m \\mapsto f(k**t_L * m + r_L)`.\n '
(iU, m_indices) = some_inverse_U_matrix(lines)
X_L = vector((f((((k ** t_L) * m) + r_L)) for m in m_indices))
return (X_L * iU)
def verify_linear_combination(t_L, r_L, linear_combination, lines):
'\n Determine whether the subsequence with parameters ``t_L`` and\n ``r_L``, i.e., `m \\mapsto f(k**t_L * m + r_L)`, is the linear\n combination ``linear_combination`` of the current vector valued\n sequence.\n\n Note that we only evaluate the subsequence of ``f`` where arguments\n of ``f`` are at most ``n_verify``. This might lead to detection of\n linear dependence which would not be true for higher values, but this\n coincides with the documentation of ``n_verify``.\n However, this is not a guarantee that the given function will never\n be evaluated beyond ``n_verify``, determining an invertible submatrix\n in ``some_inverse_U_matrix`` might require us to do so.\n '
return all(((f((((k ** t_L) * m) + r_L)) == (linear_combination * vector(values(m, lines)))) for m in xsrange(0, (((n_verify - r_L) // (k ** t_L)) + 1))))
class NoLinearCombination(RuntimeError):
pass
def find_linear_combination(t_L, r_L, lines):
linear_combination = linear_combination_candidate(t_L, r_L, lines)
if (not verify_linear_combination(t_L, r_L, linear_combination, lines)):
raise NoLinearCombination
return linear_combination
if seq(0).is_zero():
left = None
else:
try:
left = vector(find_linear_combination(0, 0, []))
except NoLinearCombination:
left = None
to_branch = []
lines = []
def include(t, r):
to_branch.append((t, r))
lines.append((t, r))
logger.info('including f_{%s*m+%s}', (k ** t), r)
if (left is None):
include(0, 0)
assert (len(lines) == 1)
left = vector(((len(seq(0)) * (zero,)) + (one,)))
while to_branch:
(t_R, r_R) = to_branch.pop(0)
if (t_R >= max_exponent):
raise RuntimeError(f'aborting as exponents would be larger than max_exponent={max_exponent}')
t_L = (t_R + 1)
for s_L in srange(k):
r_L = (((k ** t_R) * s_L) + r_R)
try:
linear_combination = find_linear_combination(t_L, r_L, lines)
except NoLinearCombination:
include(t_L, r_L)
linear_combination = (((len(lines) - 1) * (zero,)) + (one,))
logger.debug('M_%s: f_{%s*m+%s} = %s * F_m', s_L, (k ** t_L), r_L, linear_combination)
mu[s_L].append(linear_combination)
d = (len(seq(0)) + len(lines))
mu = tuple((Matrix(domain, [pad_right(tuple(row), d, zero=zero) for row in M]) for M in mu))
right = vector(values(0, lines))
left = vector(pad_right(tuple(left), d, zero=zero))
return self(mu, left, right)
def from_recurrence(self, *args, **kwds):
"\n Construct the unique `k`-regular sequence which fulfills the given\n recurrence relations and initial values. The recurrence relations have to\n have the specific shape of `k`-recursive sequences as described in [HKL2022]_,\n and are either given as symbolic equations, e.g.,\n\n ::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: var('n')\n n\n sage: function('f')\n f\n sage: Seq2.from_recurrence([\n ....: f(2*n) == 2*f(n), f(2*n + 1) == 3*f(n) + 4*f(n - 1),\n ....: f(0) == 0, f(1) == 1], f, n)\n 2-regular sequence 0, 0, 0, 1, 2, 3, 4, 10, 6, 17, ...\n\n or via the parameters of the `k`-recursive sequence as described in the input\n block below::\n\n sage: Seq2.from_recurrence(M=1, m=0,\n ....: coeffs={(0, 0): 2, (1, 0): 3, (1, -1): 4},\n ....: initial_values={0: 0, 1: 1})\n 2-regular sequence 0, 0, 0, 1, 2, 3, 4, 10, 6, 17, ...\n\n INPUT:\n\n Positional arguments:\n\n If the recurrence relations are represented by symbolic equations, then\n the following arguments are required:\n\n - ``equations`` -- A list of equations where the elements have\n either the form\n\n - `f(k^M n + r) = c_{r,l} f(k^m n + l) + c_{r,l + 1} f(k^m n\n + l + 1) + ... + c_{r,u} f(k^m n + u)` for some integers\n `0 \\leq r < k^M`, `M > m \\geq 0` and `l \\leq u`, and some\n coefficients `c_{r,j}` from the (semi)ring ``coefficients``\n of the corresponding :class:`RegularSequenceRing`, valid\n for all integers `n \\geq \\text{offset}` for some integer\n `\\text{offset} \\geq \\max(-l/k^m, 0)` (default: ``0``), and\n there is an equation of this form (with the same\n parameters `M` and `m`) for all `r`\n\n or the form\n\n - ``f(k) == t`` for some integer ``k`` and some ``t`` from the (semi)ring\n ``coefficient_ring``.\n\n The recurrence relations above uniquely determine a `k`-regular sequence;\n see [HKL2022]_ for further information.\n\n - ``function`` -- symbolic function ``f`` occurring in the equations\n\n - ``var`` -- symbolic variable (``n`` in the above description of\n ``equations``)\n\n The following second representation of the recurrence relations is\n particularly useful for cases where ``coefficient_ring`` is not\n compatible with :class:`sage.symbolic.ring.SymbolicRing`. Then the\n following arguments are required:\n\n - ``M`` -- parameter of the recursive sequences,\n see [HKL2022]_, Definition 3.1, as well as in the description of\n ``equations`` above\n\n - ``m`` -- parameter of the recursive sequences,\n see [HKL2022]_, Definition 3.1, as well as in the description of\n ``equations`` above\n\n - ``coeffs`` -- a dictionary where ``coeffs[(r, j)]`` is the\n coefficient `c_{r,j}` as given in the description of ``equations`` above.\n If ``coeffs[(r, j)]`` is not given for some ``r`` and ``j``, then it is\n assumed to be zero.\n\n - ``initial_values`` -- a dictionary mapping integers ``n`` to the\n ``n``-th value of the sequence\n\n Optional keyword-only argument:\n\n - ``offset`` -- (default: ``0``) an integer. See explanation of\n ``equations`` above.\n\n - ``inhomogeneities`` -- (default: ``{}``) a dictionary\n mapping integers ``r`` to the inhomogeneity `g_r` as given\n in [HKL2022]_, Corollary D. All inhomogeneities have to be\n regular sequences from ``self`` or elements of ``coefficient_ring``.\n\n OUTPUT: a :class:`RegularSequence`\n\n EXAMPLES:\n\n Stern--Brocot Sequence::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: var('n')\n n\n sage: function('f')\n f\n sage: SB = Seq2.from_recurrence([\n ....: f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1),\n ....: f(0) == 0, f(1) == 1], f, n)\n sage: SB\n 2-regular sequence 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, ...\n\n Number of Odd Entries in Pascal's Triangle::\n\n sage: Seq2.from_recurrence([\n ....: f(2*n) == 3*f(n), f(2*n + 1) == 2*f(n) + f(n + 1),\n ....: f(0) == 0, f(1) == 1], f, n)\n 2-regular sequence 0, 1, 3, 5, 9, 11, 15, 19, 27, 29, ...\n\n Number of Unbordered Factors in the Thue--Morse Sequence::\n\n sage: UB = Seq2.from_recurrence([\n ....: f(8*n) == 2*f(4*n),\n ....: f(8*n + 1) == f(4*n + 1),\n ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3),\n ....: f(8*n + 3) == -f(4*n + 1) + f(4*n + 2),\n ....: f(8*n + 4) == 2*f(4*n + 2),\n ....: f(8*n + 5) == f(4*n + 3),\n ....: f(8*n + 6) == -f(4*n + 1) + f(4*n + 2) + f(4*n + 3),\n ....: f(8*n + 7) == 2*f(4*n + 1) + f(4*n + 3),\n ....: f(0) == 1, f(1) == 2, f(2) == 2, f(3) == 4, f(4) == 2,\n ....: f(5) == 4, f(6) == 6, f(7) == 0, f(8) == 4, f(9) == 4,\n ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4,\n ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0,\n ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3)\n sage: UB\n 2-regular sequence 1, 2, 2, 4, 2, 4, 6, 0, 4, 4, ...\n\n Binary sum of digits `S(n)`, characterized by the recurrence relations\n `S(4n) = S(2n)`, `S(4n + 1) = S(2n + 1)`, `S(4n + 2) = S(2n + 1)` and\n `S(4n + 3) = -S(2n) + 2S(2n + 1)`::\n\n sage: S = Seq2.from_recurrence([\n ....: f(4*n) == f(2*n),\n ....: f(4*n + 1) == f(2*n + 1),\n ....: f(4*n + 2) == f(2*n + 1),\n ....: f(4*n + 3) == -f(2*n) + 2*f(2*n + 1),\n ....: f(0) == 0, f(1) == 1], f, n)\n sage: S\n 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...\n\n In order to check if this sequence is indeed the binary sum of digits,\n we construct it directly via its linear representation and compare it\n with ``S``::\n\n sage: S2 = Seq2(\n ....: (Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [1, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: (S - S2).is_trivial_zero()\n True\n\n Alternatively, we can also use the simpler but inhomogeneous recurrence relations\n `S(2n) = S(n)` and `S(2n+1) = S(n) + 1` via direct parameters::\n\n sage: S3 = Seq2.from_recurrence(M=1, m=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1},\n ....: initial_values={0: 0, 1: 1},\n ....: inhomogeneities={1: 1})\n sage: S3\n 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...\n sage: (S3 - S2).is_trivial_zero()\n True\n\n Number of Non-Zero Elements in the Generalized Pascal's Triangle (see [LRS2017]_)::\n\n sage: Seq2 = RegularSequenceRing(2, QQ)\n sage: P = Seq2.from_recurrence([\n ....: f(4*n) == 5/3*f(2*n) - 1/3*f(2*n + 1),\n ....: f(4*n + 1) == 4/3*f(2*n) + 1/3*f(2*n + 1),\n ....: f(4*n + 2) == 1/3*f(2*n) + 4/3*f(2*n + 1),\n ....: f(4*n + 3) == -1/3*f(2*n) + 5/3*f(2*n + 1),\n ....: f(0) == 1, f(1) == 2], f, n)\n sage: P\n 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ...\n\n Finally, the same sequence can also be obtained via direct parameters\n without symbolic equations::\n\n sage: Seq2.from_recurrence(M=2, m=1,\n ....: coeffs={(0, 0): 5/3, (0, 1): -1/3,\n ....: (1, 0): 4/3, (1, 1): 1/3,\n ....: (2, 0): 1/3, (2, 1): 4/3,\n ....: (3, 0): -1/3, (3, 1): 5/3},\n ....: initial_values={0: 1, 1: 2})\n 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ...\n\n TESTS::\n\n sage: Seq2.from_recurrence([ # long time\n ....: f(4*n) == f(2*n),\n ....: f(4*n + 1) == f(2*n),\n ....: f(4*n + 2) == f(2*n),\n ....: f(4*n + 3) == f(2*n + 1024),\n ....: f(0) == 1, f(1) == 1], f, n, offset=2)\n Traceback (most recent call last):\n ...\n ValueError: Initial values for arguments in [2, ..., 2044] are missing.\n\n ::\n\n sage: S = Seq2.from_recurrence([\n ....: f(4*n) == f(2*n),\n ....: f(4*n + 1) == f(2*n),\n ....: f(4*n + 2) == f(2*n),\n ....: f(4*n + 3) == f(2*n + 16),\n ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3, f(4) == 4,\n ....: f(5) == 5, f(6) == 6, f(7) == 7, f(16) == 4, f(18) == 4,\n ....: f(20) == 4, f(22) == 4, f(24) == 6, f(26) == 6, f(28) == 6],\n ....: f, n, offset=2)\n sage: all([S[4*i] == S[2*i] and\n ....: S[4*i + 1] == S[2*i] and\n ....: S[4*i + 2] == S[2*i] and\n ....: S[4*i + 3] == S[2*i + 16] for i in srange(2, 100)])\n True\n\n ::\n\n sage: S = Seq2.from_recurrence([\n ....: f(4*n) == f(2*n),\n ....: f(4*n + 1) == f(2*n),\n ....: f(4*n + 2) == f(2*n),\n ....: f(4*n + 3) == f(2*n - 16),\n ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3, f(4) == 4,\n ....: f(5) == 5, f(6) == 6, f(7) == 7, f(8) == 8, f(9) == 9,\n ....: f(10) == 10, f(11) == 11, f(12) == 12, f(13) == 13,\n ....: f(14) == 14, f(15) == 15, f(16) == 16, f(17) == 17,\n ....: f(18) == 18, f(19) == 19, f(20) == 20, f(21) == 21,\n ....: f(22) == 22, f(23) == 23, f(24) == 24, f(25) == 25,\n ....: f(26) == 26, f(27) == 27, f(28) == 28, f(29) == 29,\n ....: f(30) == 30, f(31) == 31], f, n, offset=8)\n sage: all([S[4*i] == S[2*i] and\n ....: S[4*i + 1] == S[2*i] and\n ....: S[4*i + 2] == S[2*i] and\n ....: S[4*i + 3] == S[2*i - 16] for i in srange(8, 100)])\n True\n\n Same test with different variable and function names::\n\n sage: var('m')\n m\n sage: function('g')\n g\n sage: T = Seq2.from_recurrence([\n ....: g(4*m) == g(2*m),\n ....: g(4*m + 1) == g(2*m),\n ....: g(4*m + 2) == g(2*m),\n ....: g(4*m + 3) == g(2*m - 16),\n ....: g(0) == 1, g(1) == 1, g(2) == 2, g(3) == 3, g(4) == 4,\n ....: g(5) == 5, g(6) == 6, g(7) == 7, g(8) == 8, g(9) == 9,\n ....: g(10) == 10, g(11) == 11, g(12) == 12, g(13) == 13,\n ....: g(14) == 14, g(15) == 15, g(16) == 16, g(17) == 17,\n ....: g(18) == 18, g(19) == 19, g(20) == 20, g(21) == 21,\n ....: g(22) == 22, g(23) == 23, g(24) == 24, g(25) == 25,\n ....: g(26) == 26, g(27) == 27, g(28) == 28, g(29) == 29,\n ....: g(30) == 30, g(31) == 31], g, m, offset=8)\n sage: (S - T).is_trivial_zero() # long time\n True\n\n Zero-sequence with non-zero initial values::\n\n sage: Seq2.from_recurrence([\n ....: f(2*n) == 0, f(2*n + 1) == 0,\n ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Initial value for argument 0 does not match with the given recurrence relations.\n\n ::\n\n sage: Seq2.from_recurrence([\n ....: f(2*n) == 0, f(2*n + 1) == 0,\n ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n, offset=2)\n 2-regular sequence 1, 1, 2, 3, 0, 0, 0, 0, 0, 0, ...\n\n Check if inhomogeneities `0` do not change the sequence::\n\n sage: Seq2.from_recurrence([\n ....: f(2*n) == 0, f(2*n + 1) == 0,\n ....: f(0) == 1, f(1) == 1, f(2) == 2, f(3) == 3], f, n, offset=2,\n ....: inhomogeneities={0: 0, 1: Seq2.zero()})\n 2-regular sequence 1, 1, 2, 3, 0, 0, 0, 0, 0, 0, ...\n\n ::\n\n sage: S = Seq2([matrix([[3/2, -1, 1], [0, 1/2, 1/2], [0, -1, 2]]),\n ....: matrix([[-1, 0, 1], [1, 5, -5], [-4, 0, 0]])],\n ....: left=vector([1, 2, 3]),\n ....: right=vector([0, 1, 1]))\n sage: T = Seq2.from_recurrence(M=3, m=2,\n ....: coeffs={},\n ....: initial_values={0: S[0]},\n ....: inhomogeneities={i: S.subsequence(2**3, i) for i in srange(2**3)})\n sage: (S - T).is_trivial_zero()\n True\n\n Connection between the Stern--Brocot sequence and the number\n of non-zero elements in the generalized Pascal's triangle (see\n [LRS2017]_)::\n\n sage: U = Seq2.from_recurrence(M=1, m=0,\n ....: coeffs={(0, 0): 1},\n ....: initial_values={0: 0, 1: 1},\n ....: inhomogeneities={1: P})\n sage: (U - Seq2(SB)).is_trivial_zero()\n True\n\n ::\n\n sage: U = Seq2.from_recurrence(M=1, m=0,\n ....: coeffs={},\n ....: initial_values={0: 0, 1: 1},\n ....: inhomogeneities={0: SB, 1: P})\n sage: (U - Seq2(SB)).is_trivial_zero()\n True\n\n Number of Unbordered Factors in the Thue--Morse Sequence, but partly\n encoded with inhomogeneities::\n\n sage: UB2 = Seq2.from_recurrence([\n ....: f(8*n) == 2*f(4*n),\n ....: f(8*n + 1) == f(4*n + 1),\n ....: f(8*n + 2) == f(4*n + 1),\n ....: f(8*n + 3) == f(4*n + 2),\n ....: f(8*n + 4) == 2*f(4*n + 2),\n ....: f(8*n + 5) == f(4*n + 3),\n ....: f(8*n + 6) == -f(4*n + 1),\n ....: f(8*n + 7) == 2*f(4*n + 1) + f(4*n + 3),\n ....: f(0) == 1, f(1) == 2, f(2) == 2, f(3) == 4, f(4) == 2,\n ....: f(5) == 4, f(6) == 6, f(7) == 0, f(8) == 4, f(9) == 4,\n ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4,\n ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0,\n ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3,\n ....: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1),\n ....: 6: UB.subsequence(4, 2) + UB.subsequence(4, 3)})\n sage: (UB2 - Seq2(UB)).is_trivial_zero()\n True\n "
RP = RecurrenceParser(self.k, self.coefficient_ring())
(mu, left, right) = RP(*args, **kwds)
return self(mu, left, right)
|
class RecurrenceParser():
'\n A parser for recurrence relations that allow\n the construction of a `k`-linear representation\n for the sequence satisfying these recurrence relations.\n\n This is used by :meth:`RegularSequenceRing.from_recurrence`\n to construct a :class:`RegularSequence`.\n '
def __init__(self, k, coefficient_ring):
'\n See :class:`RecurrenceParser`.\n\n INPUT:\n\n - ``k`` -- an integer at least `2` specifying the base\n\n - ``coefficient_ring`` -- a ring.\n\n These are the same parameters used when creating\n a :class:`RegularSequenceRing`.\n\n TESTS::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RecurrenceParser(2, ZZ)\n <sage.combinat.regular_sequence.RecurrenceParser object at 0x...>\n '
self.k = k
self.coefficient_ring = coefficient_ring
def parse_recurrence(self, equations, function, var):
"\n Parse recurrence relations as admissible in :meth:`RegularSequenceRing.from_recurrence`.\n\n INPUT:\n\n All parameters are explained in the high-level method\n :meth:`RegularSequenceRing.from_recurrence`.\n\n OUTPUT: a tuple consisting of\n\n - ``M``, ``m`` -- see :meth:`RegularSequenceRing.from_recurrence`\n\n - ``coeffs`` -- see :meth:`RegularSequenceRing.from_recurrence`\n\n - ``initial_values`` -- see :meth:`RegularSequenceRing.from_recurrence`\n\n EXAMPLES::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: var('n')\n n\n sage: function('f')\n f\n sage: RP.parse_recurrence([\n ....: f(4*n) == f(2*n) + 2*f(2*n + 1) + 3*f(2*n - 2),\n ....: f(4*n + 1) == 4*f(2*n) + 5*f(2*n + 1) + 6*f(2*n - 2),\n ....: f(4*n + 2) == 7*f(2*n) + 8*f(2*n + 1) + 9*f(2*n - 2),\n ....: f(4*n + 3) == 10*f(2*n) + 11*f(2*n + 1) + 12*f(2*n - 2),\n ....: f(0) == 1, f(1) == 2, f(2) == 1], f, n)\n (2, 1, {(0, -2): 3, (0, 0): 1, (0, 1): 2, (1, -2): 6, (1, 0): 4,\n (1, 1): 5, (2, -2): 9, (2, 0): 7, (2, 1): 8, (3, -2): 12, (3, 0): 10,\n (3, 1): 11}, {0: 1, 1: 2, 2: 1})\n\n Stern--Brocot Sequence::\n\n sage: RP.parse_recurrence([\n ....: f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1),\n ....: f(0) == 0, f(1) == 1], f, n)\n (1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, {0: 0, 1: 1})\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n\n TESTS:\n\n The following tests check that the equations are well-formed::\n\n sage: RP.parse_recurrence([], f, n)\n Traceback (most recent call last):\n ...\n ValueError: List of recurrence equations is empty.\n\n ::\n\n sage: RP.parse_recurrence([f(4*n + 1)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: f(4*n + 1) is not an equation with ==.\n\n ::\n\n sage: RP.parse_recurrence([42], f, n)\n Traceback (most recent call last):\n ...\n ValueError: 42 is not a symbolic expression.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) + 1 == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n) + 1 in the equation f(2*n) + 1 == f(n) is\n not an evaluation of f.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n, 5) == 3], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n, 5) in the equation f(2*n, 5) == 3 does not\n have one argument.\n\n ::\n\n sage: RP.parse_recurrence([f() == 3], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f() in the equation f() == 3 does not have one\n argument.\n\n ::\n\n sage: RP.parse_recurrence([f(1/n + 1) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(1/n + 1) in the equation f(1/n + 1) == f(n):\n 1/n + 1 is not a polynomial in n with integer coefficients.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n + 1/2) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n + 1/2) in the equation f(2*n + 1/2) == f(n):\n 2*n + 1/2 is not a polynomial in n with integer coefficients.\n\n ::\n\n sage: RP.parse_recurrence([f(4*n^2) == f(2*n^2)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(4*n^2) in the equation f(4*n^2) == f(2*n^2):\n 4*n^2 is not a polynomial in n of degree smaller than 2.\n\n ::\n\n sage: RP.parse_recurrence([f(42) == 1/2], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Initial value 1/2 given by the equation f(42) == (1/2)\n is not in Integer Ring.\n\n ::\n\n sage: RP.parse_recurrence([f(42) == 0, f(42) == 1], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Initial value f(42) is given twice.\n\n ::\n\n sage: RP.parse_recurrence([f(42) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Initial value f(n) given by the equation f(42) == f(n)\n is not in Integer Ring.\n\n ::\n\n sage: RP.parse_recurrence([f(4*n) == f(n), f(2*n) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n) in the equation f(2*n) == f(n): 2 does not\n equal 4. Expected subsequence modulo 4 as in another equation, got\n subsequence modulo 2.\n\n ::\n\n sage: RP.parse_recurrence([f(3*n + 1) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(3*n + 1) in the equation f(3*n + 1) == f(n):\n 3 is not a power of 2.\n\n ::\n\n sage: RP.parse_recurrence([f(n + 1) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(n + 1) in the equation f(n + 1) == f(n):\n 1 is less than 2. Modulus must be at least 2.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(n), f(2*n) == 0], f, n)\n Traceback (most recent call last):\n ...\n ValueError: There are more than one recurrence relation for f(2*n).\n\n ::\n\n sage: RP.parse_recurrence([f(2*n + 2) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n + 2) in the equation f(2*n + 2) == f(n):\n remainder 2 is not smaller than modulus 2.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n - 1) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n - 1) in the equation f(2*n - 1) == f(n):\n remainder -1 is smaller than 0.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 2*n], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term 2*n in the equation f(2*n) == 2*n does not\n contain f.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 1/2*f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term 1/2*f(n) in the equation f(2*n) == 1/2*f(n):\n 1/2 is not a valid coefficient since it is not in Integer Ring.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 1/f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: 1/f(n) is not a valid right hand side.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 2*n*f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: 2*n*f(n) is not a valid right hand side.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 2*f(n, 5)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(n, 5) in the equation f(2*n) == 2*f(n, 5)\n has more than one argument.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 2*f()], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f() in the equation f(2*n) == 2*f() has no argument.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 1/f(n) + 2*f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term 1/f(n) in the equation f(2*n) == 1/f(n) + 2*f(n)\n is not a valid summand.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == 2*f(1/n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(1/n) in the equation f(2*n) == 2*f(1/n):\n 1/n is not a polynomial in n with integer coefficients.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(n + 1/2)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(n + 1/2) in the equation f(2*n) == f(n + 1/2):\n n + 1/2 is not a polynomial in n with integer coefficients.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(1/2*n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(1/2*n) in the equation f(2*n) == f(1/2*n):\n 1/2*n is not a polynomial in n with integer coefficients.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(n^2 + 1)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(n^2 + 1) in the equation f(2*n) == f(n^2 + 1):\n polynomial n^2 + 1 does not have degree 1.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(1)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(1) in the equation f(2*n) == f(1):\n polynomial 1 does not have degree 1.\n\n ::\n\n sage: RP.parse_recurrence([f(4*n) == f(2*n) + f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(n) in the equation f(4*n) == f(2*n) + f(n):\n 1 does not equal 2. Expected subsequence modulo 2 as in another\n summand or equation, got subsequence modulo 1.\n\n ::\n\n sage: RP.parse_recurrence([f(4*n) == f(2*n), f(4*n + 1) == f(n)],\n ....: f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(n) in the equation f(4*n + 1) == f(n): 1 does not\n equal 2. Expected subsequence modulo 2 as in another summand or\n equation, got subsequence modulo 1.\n\n ::\n\n sage: RP.parse_recurrence([f(4*n) == f(3*n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(3*n) in the equation f(4*n) == f(3*n): 3 is not\n a power of 2.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(4*n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(4*n) in the equation f(2*n) == f(4*n):\n 4 is not smaller than 2.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(2*n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n) in the equation f(2*n) == f(2*n):\n 2 is not smaller than 2.\n\n ::\n\n sage: RP.parse_recurrence([f(2*n) == f(n)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Recurrence relations for [f(2*n + 1)] are missing.\n\n ::\n\n sage: RP.parse_recurrence([f(4*n) == f(n), f(4*n + 3) == 0], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Recurrence relations for [f(4*n + 1), f(4*n + 2)]\n are missing.\n\n ::\n\n sage: RP.parse_recurrence([f(42) == 0], f, n)\n Traceback (most recent call last):\n ...\n ValueError: No recurrence relations are given.\n\n ::\n\n sage: RP.parse_recurrence(\n ....: [f(4*n + r) == f(n) for r in srange(4)], f, n)\n (2, 0, {(0, 0): 1, (1, 0): 1, (2, 0): 1, (3, 0): 1}, {})\n\n ::\n\n sage: RP.parse_recurrence(\n ....: [f(8*n) == f(n)] +\n ....: [f(8*n + r) == f(2*n) for r in srange(1,8)], f, n)\n Traceback (most recent call last):\n ...\n ValueError: Term f(2*n) in the equation f(8*n + 1) == f(2*n):\n 2 does not equal 1. Expected subsequence modulo 1 as in another\n summand or equation, got subsequence modulo 2.\n\n Finally, also for the zero-sequence the output is as expected::\n\n sage: RP.parse_recurrence([f(2*n) == 0, f(2*n + 1) == 0], f, n)\n (1, 0, {}, {})\n\n We check that the output is of the correct type (:trac:`33158`)::\n\n sage: RP = RecurrenceParser(2, QQ)\n sage: equations = [\n ....: f(4*n) == 5/3*f(2*n) - 1/3*f(2*n + 1),\n ....: f(4*n + 1) == 4/3*f(2*n) + 1/3*f(2*n + 1),\n ....: f(4*n + 2) == 1/3*f(2*n) + 4/3*f(2*n + 1),\n ....: f(4*n + 3) == -1/3*f(2*n) + 5/3*f(2*n + 1),\n ....: f(0) == 1, f(1) == 2]\n sage: M, m, coeffs, initial_values = RP.parse_recurrence(equations, f, n)\n sage: M.parent()\n Integer Ring\n sage: m.parent()\n Integer Ring\n sage: all(v.parent() == QQ for v in coeffs.values())\n True\n sage: all(v.parent() == QQ for v in initial_values.values())\n True\n\n This results in giving the correct (see :trac:`33158`) minimization in::\n\n sage: Seq2 = RegularSequenceRing(2, QQ)\n sage: P = Seq2.from_recurrence(equations, f, n)\n sage: P\n 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ...\n sage: P.minimized()\n 2-regular sequence 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, ...\n "
from sage.arith.srange import srange
from sage.functions.log import log
from sage.rings.integer_ring import ZZ
from sage.symbolic.operators import add_vararg, mul_vararg, operator
k = self.k
coefficient_ring = self.coefficient_ring
M = None
m = None
coeffs = {}
initial_values = {}
remainders = set()
def parse_multiplication(op, eq):
operands = op.operands()
assert ((op.operator() == mul_vararg) and (len(operands) == 2))
if (operands[1].operator() == function):
return [operands[0], operands[1]]
elif (operands[0].operator() == function):
return [operands[1], operands[0]]
else:
raise ValueError(('Term %s in the equation %s does not contain %s.' % (op, eq, function)))
def parse_one_summand(summand, eq):
if (summand.operator() == mul_vararg):
(coeff, op) = parse_multiplication(summand, eq)
elif (summand.operator() == function):
(coeff, op) = (1, summand)
else:
raise ValueError(('Term %s in the equation %s is not a valid summand.' % (summand, eq)))
try:
coeff = coefficient_ring(coeff)
except (TypeError, ValueError):
raise ValueError(('Term %s in the equation %s: %s is not a valid coefficient since it is not in %s.' % (summand, eq, coeff, coefficient_ring))) from None
if (len(op.operands()) > 1):
raise ValueError(('Term %s in the equation %s has more than one argument.' % (op, eq)))
elif (len(op.operands()) == 0):
raise ValueError(('Term %s in the equation %s has no argument.' % (op, eq)))
try:
poly = ZZ[var](op.operands()[0])
except TypeError:
raise ValueError(('Term %s in the equation %s: %s is not a polynomial in %s with integer coefficients.' % (op, eq, op.operands()[0], var))) from None
if (poly.degree() != 1):
raise ValueError(('Term %s in the equation %s: polynomial %s does not have degree 1.' % (op, eq, poly)))
(d, base_power_m) = list(poly)
m = log(base_power_m, base=k)
try:
m = ZZ(m)
except (TypeError, ValueError):
raise ValueError(('Term %s in the equation %s: %s is not a power of %s.' % (summand, eq, (k ** m), k))) from None
return [coeff, m, d]
if (not equations):
raise ValueError('List of recurrence equations is empty.')
for eq in equations:
try:
if (eq.operator() != operator.eq):
raise ValueError(('%s is not an equation with ==.' % eq))
except AttributeError:
raise ValueError(('%s is not a symbolic expression.' % eq)) from None
(left_side, right_side) = eq.operands()
if (left_side.operator() != function):
raise ValueError(('Term %s in the equation %s is not an evaluation of %s.' % (left_side, eq, function)))
if (len(left_side.operands()) != 1):
raise ValueError(('Term %s in the equation %s does not have one argument.' % (left_side, eq)))
try:
polynomial_left = ZZ[var](left_side.operands()[0])
except TypeError:
raise ValueError(('Term %s in the equation %s: %s is not a polynomial in %s with integer coefficients.' % (left_side, eq, left_side.operands()[0], var))) from None
if (polynomial_left.degree() > 1):
raise ValueError(('Term %s in the equation %s: %s is not a polynomial in %s of degree smaller than 2.' % (left_side, eq, polynomial_left, var)))
if (polynomial_left in ZZ):
try:
right_side = coefficient_ring(right_side)
except (TypeError, ValueError):
raise ValueError(('Initial value %s given by the equation %s is not in %s.' % (right_side, eq, coefficient_ring))) from None
if ((polynomial_left in initial_values.keys()) and (initial_values[polynomial_left] != right_side)):
raise ValueError(('Initial value %s is given twice.' % function(polynomial_left)))
initial_values.update({polynomial_left: right_side})
else:
[r, base_power_M] = list(polynomial_left)
M_new = log(base_power_M, base=k)
try:
M_new = ZZ(M_new)
except (TypeError, ValueError):
raise ValueError(('Term %s in the equation %s: %s is not a power of %s.' % (left_side, eq, base_power_M, k))) from None
if ((M is not None) and (M != M_new)):
raise ValueError('Term {0} in the equation {1}: {2} does not equal {3}. Expected subsequence modulo {3} as in another equation, got subsequence modulo {2}.'.format(left_side, eq, base_power_M, (k ** M)))
elif (M is None):
M = M_new
if (M < 1):
raise ValueError('Term {0} in the equation {1}: {2} is less than {3}. Modulus must be at least {3}.'.format(left_side, eq, base_power_M, k))
if (r in remainders):
raise ValueError(('There are more than one recurrence relation for %s.' % (left_side,)))
if (r >= (k ** M)):
raise ValueError(('Term %s in the equation %s: remainder %s is not smaller than modulus %s.' % (left_side, eq, r, (k ** M))))
elif (r < 0):
raise ValueError(('Term %s in the equation %s: remainder %s is smaller than 0.' % (left_side, eq, r)))
else:
remainders.add(r)
if (right_side != 0):
if (((len(right_side.operands()) == 1) and (right_side.operator() == function)) or ((right_side.operator() == mul_vararg) and (len(right_side.operands()) == 2))):
summands = [right_side]
elif (right_side.operator() == add_vararg):
summands = right_side.operands()
else:
raise ValueError(('%s is not a valid right hand side.' % (right_side,)))
for summand in summands:
(coeff, new_m, d) = parse_one_summand(summand, eq)
if ((m is not None) and (m != new_m)):
raise ValueError('Term {0} in the equation {1}: {2} does not equal {3}. Expected subsequence modulo {3} as in another summand or equation, got subsequence modulo {2}.'.format(summand, eq, (k ** new_m), (k ** m)))
elif (m is None):
m = new_m
if (M <= m):
raise ValueError(('Term %s in the equation %s: %s is not smaller than %s.' % (summand, eq, (k ** m), (k ** M))))
coeffs.update({(r, d): coeff})
if (not M):
raise ValueError('No recurrence relations are given.')
elif (M and (m is None)):
m = (M - 1)
missing_remainders = [rem for rem in srange((k ** M)) if (rem not in remainders)]
if missing_remainders:
raise ValueError(('Recurrence relations for %s are missing.' % ([function((((k ** M) * var) + rem)) for rem in missing_remainders],)))
return (M, m, coeffs, initial_values)
def parse_direct_arguments(self, M, m, coeffs, initial_values):
'\n Check whether the direct arguments as admissible in\n :meth:`RegularSequenceRing.from_recurrence` are valid.\n\n INPUT:\n\n All parameters are explained in the high-level method\n :meth:`RegularSequenceRing.from_recurrence`.\n\n OUTPUT: a tuple consisting of the input parameters\n\n EXAMPLES::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: RP.parse_direct_arguments(2, 1,\n ....: {(0, -2): 3, (0, 0): 1, (0, 1): 2,\n ....: (1, -2): 6, (1, 0): 4, (1, 1): 5,\n ....: (2, -2): 9, (2, 0): 7, (2, 1): 8,\n ....: (3, -2): 12, (3, 0): 10, (3, 1): 11},\n ....: {0: 1, 1: 2, 2: 1})\n (2, 1, {(0, -2): 3, (0, 0): 1, (0, 1): 2,\n (1, -2): 6, (1, 0): 4, (1, 1): 5,\n (2, -2): 9, (2, 0): 7, (2, 1): 8,\n (3, -2): 12, (3, 0): 10, (3, 1): 11},\n {0: 1, 1: 2, 2: 1})\n\n Stern--Brocot Sequence::\n\n sage: RP.parse_direct_arguments(1, 0,\n ....: {(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: {0: 0, 1: 1})\n (1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, {0: 0, 1: 1})\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n\n TESTS:\n\n The following tests check that the equations are well-formed::\n\n sage: RP.parse_direct_arguments(1/2, 0, {}, {})\n Traceback (most recent call last):\n ...\n ValueError: 1/2 is not a positive integer.\n\n ::\n\n sage: RP.parse_direct_arguments(0, 0, {}, {})\n Traceback (most recent call last):\n ....\n ValueError: 0 is not a positive integer.\n\n ::\n\n sage: RP.parse_direct_arguments(1, 1/2, {}, {})\n Traceback (most recent call last):\n ...\n ValueError: 1/2 is not a non-negative integer.\n\n ::\n\n sage: RP.parse_direct_arguments(1, -1, {}, {})\n Traceback (most recent call last):\n ...\n ValueError: -1 is not a non-negative integer.\n\n ::\n\n sage: RP.parse_direct_arguments(1, 1, {}, {})\n Traceback (most recent call last):\n ...\n ValueError: 1 is not larger than 1.\n\n ::\n\n sage: RP.parse_direct_arguments(1, 42, {}, {})\n Traceback (most recent call last):\n ...\n ValueError: 1 is not larger than 42.\n\n ::\n\n sage: RP.parse_direct_arguments(2, 1, {(0, 0): 1/2, (1, 0): i}, {})\n Traceback (most recent call last):\n ...\n ValueError: Coefficients [1/2, I] are not valid since they are not\n in Integer Ring.\n\n ::\n\n sage: RP.parse_direct_arguments(2, 1, {(i, 0): 0, (0, 1/2): 0}, {})\n Traceback (most recent call last):\n ...\n ValueError: Keys [(I, 0), (0, 1/2)] for coefficients are not valid\n since one of their components is no integer.\n\n ::\n\n sage: RP.parse_direct_arguments(2, 1, {(-1, 0): 0, (42, 0): 0}, {})\n Traceback (most recent call last):\n ...\n ValueError: Keys [(-1, 0), (42, 0)] for coefficients are not valid since\n their first component is either smaller than 0 or larger than\n or equal to 4.\n\n ::\n\n sage: RP.parse_direct_arguments(2, 1, {}, {0: 1/2, 1: i})\n Traceback (most recent call last):\n ...\n ValueError: Initial values [1/2, I] are not valid since they are\n not in Integer Ring.\n\n ::\n\n sage: RP.parse_direct_arguments(2, 1, {}, {1/2: 0, i: 0})\n Traceback (most recent call last):\n ...\n ValueError: Keys [1/2, I] for the initial values are not valid since\n they are no integers.\n '
from sage.rings.integer_ring import ZZ
if ((M not in ZZ) or (M < 1)):
raise ValueError(('%s is not a positive integer.' % (M,))) from None
if ((m not in ZZ) or (m < 0)):
raise ValueError(('%s is not a non-negative integer.' % (m,))) from None
if (M <= m):
raise ValueError(('%s is not larger than %s.' % (M, m))) from None
coefficient_ring = self.coefficient_ring
k = self.k
invalid_coeffs = [coeff for coeff in coeffs.values() if (coeff not in coefficient_ring)]
if invalid_coeffs:
raise ValueError(('Coefficients %s are not valid since they are not in %s.' % (invalid_coeffs, coefficient_ring))) from None
coeffs_keys = coeffs.keys()
invalid_coeffs_keys = [key for key in coeffs_keys if ((key[0] not in ZZ) or (key[1] not in ZZ))]
if invalid_coeffs_keys:
raise ValueError(('Keys %s for coefficients are not valid since one of their components is no integer.' % (invalid_coeffs_keys,))) from None
invalid_coeffs_keys = [key for key in coeffs_keys if ((key[0] < 0) or (key[0] >= (k ** M)))]
if invalid_coeffs_keys:
raise ValueError(('Keys %s for coefficients are not valid since their first component is either smaller than 0 or larger than or equal to %s.' % (invalid_coeffs_keys, (k ** M)))) from None
invalid_initial_values = [value for value in initial_values.values() if (value not in coefficient_ring)]
if invalid_initial_values:
raise ValueError(('Initial values %s are not valid since they are not in %s.' % (invalid_initial_values, coefficient_ring))) from None
invalid_initial_keys = [key for key in initial_values.keys() if (key not in ZZ)]
if invalid_initial_keys:
raise ValueError(('Keys %s for the initial values are not valid since they are no integers.' % (invalid_initial_keys,))) from None
return (M, m, coeffs, initial_values)
def parameters(self, M, m, coeffs, initial_values, offset=0, inhomogeneities={}):
"\n Determine parameters from recurrence relations as admissible in\n :meth:`RegularSequenceRing.from_recurrence`.\n\n INPUT:\n\n All parameters are explained in the high-level method\n :meth:`RegularSequenceRing.from_recurrence`.\n\n OUTPUT: a namedtuple ``recurrence_rules`` consisting of\n\n - ``M``, ``m``, ``l``, ``u``, ``offset`` -- parameters of the recursive\n sequences, see [HKL2022]_, Definition 3.1\n\n - ``ll``, ``uu``, ``n1``, ``dim`` -- parameters and dimension of the\n resulting linear representation, see [HKL2022]_, Theorem A\n\n - ``coeffs`` -- a dictionary mapping ``(r, j)`` to the coefficients\n `c_{r, j}` as given in [HKL2022]_, Equation (3.1).\n If ``coeffs[(r, j)]`` is not given for some ``r`` and ``j``,\n then it is assumed to be zero.\n\n - ``initial_values`` -- a dictionary mapping integers ``n`` to the\n ``n``-th value of the sequence\n\n - ``inhomogeneities`` -- a dictionary mapping integers ``r``\n to the inhomogeneity `g_r` as given in [HKL2022]_, Corollary D.\n\n EXAMPLES::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: RP.parameters(2, 1,\n ....: {(0, -2): 3, (0, 0): 1, (0, 1): 2, (1, -2): 6, (1, 0): 4,\n ....: (1, 1): 5, (2, -2): 9, (2, 0): 7, (2, 1): 8, (3, -2): 12,\n ....: (3, 0): 10, (3, 1): 11}, {0: 1, 1: 2, 2: 1, 3: 4}, 0, {0: 1})\n recurrence_rules(M=2, m=1, l=-2, u=1, ll=-6, uu=3, dim=14,\n coeffs={(0, -2): 3, (0, 0): 1, (0, 1): 2, (1, -2): 6, (1, 0): 4,\n (1, 1): 5, (2, -2): 9, (2, 0): 7, (2, 1): 8, (3, -2): 12,\n (3, 0): 10, (3, 1): 11}, initial_values={0: 1, 1: 2, 2: 1, 3: 4,\n 4: 13, 5: 30, 6: 48, 7: 66, 8: 77, 9: 208, 10: 340, 11: 472,\n 12: 220, 13: 600, -6: 0, -5: 0, -4: 0, -3: 0, -2: 0, -1: 0},\n offset=1, n1=3, inhomogeneities={0: 2-regular sequence 1, 1, 1, 1,\n 1, 1, 1, 1, 1, 1, ...})\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n\n TESTS::\n\n sage: var('n')\n n\n sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0,\n ....: {-1: 0, 1: 0, 10: 0, I: 0, n: 0})\n Traceback (most recent call last):\n ...\n ValueError: Indices [-1, 10, I, n] for inhomogeneities are\n no integers between 0 and 1.\n\n ::\n\n sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0,\n ....: {0: n})\n Traceback (most recent call last):\n ...\n ValueError: Inhomogeneities {0: n} are neither 2-regular sequences\n nor elements of Integer Ring.\n\n ::\n\n sage: Seq3 = RegularSequenceRing(3, ZZ)\n sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0,\n ....: {0: Seq3.zero()})\n Traceback (most recent call last):\n ...\n ValueError: Inhomogeneities {0: 3-regular sequence 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, ...} are neither 2-regular sequences nor elements of\n Integer Ring.\n\n ::\n\n sage: RP.parameters(1, 0, {(0, 0): 1}, {}, 0)\n Traceback (most recent call last):\n ...\n ValueError: No initial values are given.\n\n ::\n\n sage: RP.parameters(1, 0,\n ....: {(0, 0): 1, (1, 0): 1, (1, 1): 1}, {0: 1/2, 1: 2*i}, 0)\n Traceback (most recent call last):\n ...\n ValueError: Initial values for arguments in [0, 1] are not in Integer Ring.\n\n ::\n\n sage: RP.parameters(1, 0, {(0, 0): 1},\n ....: {0: 1, 1: 0}, 0)\n recurrence_rules(M=1, m=0, l=0, u=0, ll=0, uu=0, dim=1,\n coeffs={(0, 0): 1}, initial_values={0: 1, 1: 0}, offset=0, n1=0,\n inhomogeneities={})\n\n Finally, also for the zero-sequence the output is as expected::\n\n sage: RP.parameters(1, 0, {}, {0: 0}, 0)\n recurrence_rules(M=1, m=0, l=0, u=0, ll=0, uu=0, dim=1,\n coeffs={}, initial_values={0: 0}, offset=0, n1=0, inhomogeneities={})\n\n ::\n\n sage: RP.parameters(1, 0,\n ....: {(0, 0): 0, (1, 1): 0}, {0: 0}, 0)\n recurrence_rules(M=1, m=0, l=0, u=0, ll=0, uu=0, dim=1,\n coeffs={(0, 0): 0, (1, 1): 0}, initial_values={0: 0},\n offset=0, n1=0, inhomogeneities={})\n "
from collections import namedtuple
from sage.arith.srange import srange
from sage.functions.other import ceil, floor
coefficient_ring = self.coefficient_ring
k = self.k
keys_coeffs = coeffs.keys()
indices_right = [key[1] for key in keys_coeffs if coeffs[key]]
if (not indices_right):
l = 0
u = 0
else:
l = min(indices_right)
u = max(indices_right)
if (offset < max(0, ((- l) / (k ** m)))):
offset = max(0, ceil(((- l) / (k ** m))))
ll = ((floor(((((l * (k ** (M - m))) - (k ** M)) + 1) / ((k ** (M - m)) - 1))) + 1) * (l < 0))
uu = max([(ceil(((((u * (k ** (M - m))) + (k ** M)) - (k ** m)) / ((k ** (M - m)) - 1))) - 1), ((k ** m) - 1)])
n1 = (offset - floor((ll / (k ** M))))
dim = (((((k ** M) - 1) / (k - 1)) + ((M - m) * (((uu - ll) - (k ** m)) + 1))) + n1)
if inhomogeneities:
invalid_indices = [i for i in inhomogeneities if (i not in srange((k ** M)))]
if invalid_indices:
raise ValueError(f'Indices {invalid_indices} for inhomogeneities are no integers between 0 and {((k ** M) - 1)}.')
Seq = RegularSequenceRing(k, coefficient_ring)
inhomogeneities.update({i: (inhomogeneities[i] * Seq.one_hadamard()) for i in inhomogeneities if (inhomogeneities[i] in coefficient_ring)})
invalid = {i: inhomogeneities[i] for i in inhomogeneities if (not (isinstance(inhomogeneities[i].parent(), RegularSequenceRing) and (inhomogeneities[i].parent().k == k)))}
if invalid:
raise ValueError(f'Inhomogeneities {invalid} are neither {k}-regular sequences nor elements of {coefficient_ring}.')
if (not initial_values):
raise ValueError('No initial values are given.')
keys_initial = initial_values.keys()
values_not_in_ring = []
def converted_value(n, v):
try:
return coefficient_ring(v)
except (TypeError, ValueError):
values_not_in_ring.append(n)
initial_values = {n: converted_value(n, v) for (n, v) in initial_values.items()}
if values_not_in_ring:
raise ValueError(('Initial values for arguments in %s are not in %s.' % (values_not_in_ring, coefficient_ring)))
last_value_needed = max(((((k ** (M - 1)) - (k ** m)) + uu) + (((n1 > 0) * (k ** (M - 1))) * (((k * (n1 - 1)) + k) - 1))), (((k ** m) * offset) + u), max(keys_initial))
initial_values = self.values(M=M, m=m, l=l, u=u, ll=ll, coeffs=coeffs, initial_values=initial_values, last_value_needed=last_value_needed, offset=offset, inhomogeneities=inhomogeneities)
recurrence_rules = namedtuple('recurrence_rules', ['M', 'm', 'l', 'u', 'll', 'uu', 'dim', 'coeffs', 'initial_values', 'offset', 'n1', 'inhomogeneities'])
return recurrence_rules(M=M, m=m, l=l, u=u, ll=ll, uu=uu, dim=dim, coeffs=coeffs, initial_values=initial_values, offset=offset, n1=n1, inhomogeneities=inhomogeneities)
def values(self, *, M, m, l, u, ll, coeffs, initial_values, last_value_needed, offset, inhomogeneities):
'\n Determine enough values of the corresponding recursive sequence by\n applying the recurrence relations given in :meth:`RegularSequenceRing.from_recurrence`\n to the values given in ``initial_values``.\n\n INPUT:\n\n - ``M``, ``m``, ``l``, ``u``, ``offset`` -- parameters of the\n recursive sequences, see [HKL2022]_, Definition 3.1\n\n - ``ll`` -- parameter of the resulting linear representation,\n see [HKL2022]_, Theorem A\n\n - ``coeffs`` -- a dictionary where ``coeffs[(r, j)]`` is the\n coefficient `c_{r,j}` as given in :meth:`RegularSequenceRing.from_recurrence`.\n If ``coeffs[(r, j)]`` is not given for some ``r`` and ``j``,\n then it is assumed to be zero.\n\n - ``initial_values`` -- a dictionary mapping integers ``n`` to the\n ``n``-th value of the sequence\n\n - ``last_value_needed`` -- last initial value which is needed to\n determine the linear representation\n\n - ``inhomogeneities`` -- a dictionary mapping integers ``r``\n to the inhomogeneity `g_r` as given in [HKL2022]_, Corollary D.\n\n OUTPUT:\n\n A dictionary mapping integers ``n`` to the ``n``-th value of the\n sequence for all ``n`` up to ``last_value_needed``.\n\n EXAMPLES:\n\n Stern--Brocot Sequence::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: RP.values(M=1, m=0, l=0, u=1, ll=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: initial_values={0: 0, 1: 1, 2: 1}, last_value_needed=20,\n ....: offset=0, inhomogeneities={})\n {0: 0, 1: 1, 2: 1, 3: 2, 4: 1, 5: 3, 6: 2, 7: 3, 8: 1, 9: 4, 10: 3,\n 11: 5, 12: 2, 13: 5, 14: 3, 15: 4, 16: 1, 17: 5, 18: 4, 19: 7, 20: 3}\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n\n TESTS:\n\n For the equations `f(2n) = f(n)` and `f(2n + 1) = f(n) + f(n + 1)`::\n\n sage: RP.values(M=1, m=0, l=0, u=1, ll=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: initial_values={0: 0, 1: 2}, last_value_needed=20,\n ....: offset=0, inhomogeneities={})\n {0: 0, 1: 2, 2: 2, 3: 4, 4: 2, 5: 6, 6: 4, 7: 6, 8: 2, 9: 8, 10: 6,\n 11: 10, 12: 4, 13: 10, 14: 6, 15: 8, 16: 2, 17: 10, 18: 8, 19: 14,\n 20: 6}\n\n ::\n\n sage: RP.values(M=1, m=0, l=0, u=1, ll=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: initial_values={}, last_value_needed=20, offset=0,\n ....: inhomogeneities={})\n Traceback (most recent call last):\n ...\n ValueError: Initial values for arguments in [0, 1] are missing.\n\n ::\n\n sage: RP.values(M=1, m=0, l=0, u=1, ll=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: initial_values={0: 0}, last_value_needed=20, offset=0,\n ....: inhomogeneities={})\n Traceback (most recent call last):\n ...\n ValueError: Initial values for arguments in [1] are missing.\n\n ::\n\n sage: RP.values(M=1, m=0, l=0, u=1, ll=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: initial_values={0: 0, 2: 1}, last_value_needed=20,\n ....: offset=0, inhomogeneities={})\n Traceback (most recent call last):\n ...\n ValueError: Initial values for arguments in [1] are missing.\n\n ::\n\n sage: RP.values(M=1, m=0, l=0, u=1, ll=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: initial_values={0: 0, 1: 2, 2:0}, last_value_needed=20,\n ....: offset=0, inhomogeneities={})\n Traceback (most recent call last):\n ...\n ValueError: Initial value for argument 2 does not match with the given\n recurrence relations.\n\n ::\n\n sage: RP.values(M=1, m=0, l=-2, u=2, ll=-2,\n ....: coeffs={(0, -2): 1, (0, 2): 1, (1, -2): 1, (1, 2): 1},\n ....: initial_values={0: 0, 1: 2, 2: 4, 3: 3, 4: 2},\n ....: last_value_needed=20, offset=2, inhomogeneities={})\n {-2: 0, -1: 0, 0: 0, 1: 2, 2: 4, 3: 3, 4: 2, 5: 2, 6: 4, 7: 4,\n 8: 8, 9: 8, 10: 7, 11: 7, 12: 10, 13: 10, 14: 10, 15: 10, 16: 11,\n 17: 11, 18: 11, 19: 11, 20: 18}\n\n Finally, also for the zero-sequence the output is as expected::\n\n sage: RP.values(M=1, m=0, l=0, u=0, ll=0,\n ....: coeffs={}, initial_values={}, last_value_needed=10,\n ....: offset=0, inhomogeneities={})\n {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0}\n\n ::\n\n sage: RP.values(M=1, m=0, l=0, u=0, ll=0,\n ....: coeffs={(0, 0): 0, (1, 1): 0}, initial_values={},\n ....: last_value_needed=10, offset=0, inhomogeneities={})\n {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0}\n\n ::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: RP.values(M=1, m=0, l=0, u=0, ll=0,\n ....: coeffs={(0, 0): 0, (1, 1): 0}, initial_values={},\n ....: last_value_needed=10, offset=0,\n ....: inhomogeneities={0: Seq2.one_hadamard()})\n {0: 1, 1: 0, 2: 1, 3: 0, 4: 1, 5: 0, 6: 1, 7: 0, 8: 1, 9: 0, 10: 1}\n '
from sage.arith.srange import srange
from sage.rings.integer_ring import ZZ
k = self.k
keys_initial = initial_values.keys()
values = {n: (None if (n not in keys_initial) else initial_values[n]) for n in srange((last_value_needed + 1))}
missing_values = []
@cached_function
def coeff(r, k):
try:
return coeffs[(r, k)]
except KeyError:
return 0
@cached_function
def inhomogeneity(r, n):
try:
return inhomogeneities[r][n]
except KeyError:
return 0
def f(n):
f_n = values[n]
if ((f_n is not None) and (f_n != 'pending')):
return f_n
elif (f_n == 'pending'):
missing_values.append(n)
return 0
else:
values.update({n: 'pending'})
(q, r) = ZZ(n).quo_rem((k ** M))
if (q < offset):
missing_values.append(n)
return (sum([(coeff(r, j) * f((((k ** m) * q) + j))) for j in srange(l, (u + 1)) if coeff(r, j)]) + inhomogeneity(r, q))
for n in srange((last_value_needed + 1)):
values.update({n: f(n)})
if missing_values:
raise ValueError(('Initial values for arguments in %s are missing.' % (list(set(missing_values)),)))
for n in keys_initial:
(q, r) = ZZ(n).quo_rem((k ** M))
if ((q >= offset) and (values[n] != (sum([(coeff(r, j) * values[(((k ** m) * q) + j)]) for j in srange(l, (u + 1))]) + inhomogeneity(r, q)))):
raise ValueError(('Initial value for argument %s does not match with the given recurrence relations.' % (n,)))
values.update({n: 0 for n in srange(ll, 0)})
return values
@cached_method
def ind(self, M, m, ll, uu):
'\n Determine the index operator corresponding to the recursive\n sequence as defined in [HKL2022]_.\n\n INPUT:\n\n - ``M``, ``m`` -- parameters of the recursive sequences,\n see [HKL2022]_, Definition 3.1\n\n - ``ll``, ``uu`` -- parameters of the resulting linear representation,\n see [HKL2022]_, Theorem A\n\n OUTPUT:\n\n A dictionary which maps both row numbers to subsequence parameters and\n vice versa, i.e.,\n\n - ``ind[i]`` -- a pair ``(j, d)`` representing the sequence `x(k^j n + d)`\n in the `i`-th component (0-based) of the resulting linear representation,\n\n - ``ind[(j, d)]`` -- the (0-based) row number of the sequence\n `x(k^j n + d)` in the linear representation.\n\n EXAMPLES::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: RP.ind(3, 1, -3, 3)\n {(0, 0): 0, (1, -1): 3, (1, -2): 2, (1, -3): 1,\n (1, 0): 4, (1, 1): 5, (1, 2): 6, (1, 3): 7, (2, -1): 10,\n (2, -2): 9, (2, -3): 8, (2, 0): 11, (2, 1): 12, (2, 2): 13,\n (2, 3): 14, (2, 4): 15, (2, 5): 16, 0: (0, 0), 1: (1, -3),\n 10: (2, -1), 11: (2, 0), 12: (2, 1), 13: (2, 2), 14: (2, 3),\n 15: (2, 4), 16: (2, 5), 2: (1, -2), 3: (1, -1), 4: (1, 0),\n 5: (1, 1), 6: (1, 2), 7: (1, 3), 8: (2, -3), 9: (2, -2)}\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n '
from sage.arith.srange import srange
k = self.k
ind = {}
pos = 0
for j in srange(m):
for d in srange((k ** j)):
ind.update({(j, d): pos, pos: (j, d)})
pos += 1
for j in srange(m, M):
for d in srange(ll, ((((k ** j) - (k ** m)) + uu) + 1)):
ind.update({(j, d): pos, pos: (j, d)})
pos += 1
return ind
@cached_method(key=(lambda self, recurrence_rules: (recurrence_rules.M, recurrence_rules.m, recurrence_rules.ll, recurrence_rules.uu, tuple(recurrence_rules.inhomogeneities.items()))))
def shifted_inhomogeneities(self, recurrence_rules):
"\n Return a dictionary of all needed shifted inhomogeneities as described\n in the proof of Corollary D in [HKL2022]_.\n\n INPUT:\n\n - ``recurrence_rules`` -- a namedtuple generated by\n :meth:`parameters`\n\n OUTPUT:\n\n A dictionary mapping `r` to the regular sequence\n `\\sum_i g_r(n + i)` for `g_r` as given in [HKL2022]_, Corollary D,\n and `i` between `\\lfloor\\ell'/k^{M}\\rfloor` and\n `\\lfloor (k^{M-1} - k^{m} + u')/k^{M}\\rfloor + 1`; see [HKL2022]_,\n proof of Corollary D. The first blocks of the corresponding\n vector-valued sequence (obtained from its linear\n representation) correspond to the sequences `g_r(n + i)` where\n `i` is as in the sum above; the remaining blocks consist of\n other shifts which are required for the regular sequence.\n\n EXAMPLES::\n\n sage: from collections import namedtuple\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: S = Seq2((Matrix([[1, 0], [0, 1]]), Matrix([[1, 0], [1, 1]])),\n ....: left=vector([0, 1]), right=vector([1, 0]))\n sage: S\n 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ...\n sage: RR = namedtuple('recurrence_rules',\n ....: ['M', 'm', 'll', 'uu', 'inhomogeneities'])\n sage: recurrence_rules = RR(M=3, m=0, ll=-14, uu=14,\n ....: inhomogeneities={0: S, 1: S})\n sage: SI = RP.shifted_inhomogeneities(recurrence_rules)\n sage: SI\n {0: 2-regular sequence 4, 5, 7, 9, 11, 11, 11, 12, 13, 13, ...,\n 1: 2-regular sequence 4, 5, 7, 9, 11, 11, 11, 12, 13, 13, ...}\n\n The first blocks of the corresponding vector-valued sequence correspond\n to the corresponding shifts of the inhomogeneity. In this particular\n case, there are no other blocks::\n\n sage: lower = -2\n sage: upper = 3\n sage: SI[0].dimension() == S.dimension() * (upper - lower + 1)\n True\n sage: all(\n ....: Seq2(\n ....: SI[0].mu,\n ....: vector((i - lower)*[0, 0] + list(S.left) + (upper - i)*[0, 0]),\n ....: SI[0].right)\n ....: == S.subsequence(1, i)\n ....: for i in range(lower, upper+1))\n True\n\n TESTS::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: var('n')\n n\n sage: function('f')\n f\n sage: UB = Seq2.from_recurrence([\n ....: f(8*n) == 2*f(4*n),\n ....: f(8*n + 1) == f(4*n + 1),\n ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3),\n ....: f(8*n + 3) == -f(4*n + 1) + f(4*n + 2),\n ....: f(8*n + 4) == 2*f(4*n + 2),\n ....: f(8*n + 5) == f(4*n + 3),\n ....: f(8*n + 6) == -f(4*n + 1) + f(4*n + 2) + f(4*n + 3),\n ....: f(8*n + 7) == 2*f(4*n + 1) + f(4*n + 3),\n ....: f(0) == 1, f(1) == 2, f(2) == 2, f(3) == 4, f(4) == 2,\n ....: f(5) == 4, f(6) == 6, f(7) == 0, f(8) == 4, f(9) == 4,\n ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4,\n ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0,\n ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n, offset=3)\n sage: inhomogeneities={2: UB.subsequence(4, 3), 3: -UB.subsequence(4, 1),\n ....: 6: UB.subsequence(4, 2) + UB.subsequence(4, 3)}\n sage: recurrence_rules_UB = RR(M=3, m=2, ll=0, uu=9,\n ....: inhomogeneities=inhomogeneities)\n sage: shifted_inhomog = RP.shifted_inhomogeneities(recurrence_rules_UB)\n sage: shifted_inhomog\n {2: 2-regular sequence 8, 8, 8, 12, 12, 16, 12, 16, 12, 24, ...,\n 3: 2-regular sequence -10, -8, -8, -8, -8, -8, -8, -8, -8, -12, ...,\n 6: 2-regular sequence 20, 22, 24, 28, 28, 32, 28, 32, 32, 48, ...}\n sage: shifted_inhomog[2].mu[0].ncols() == 3*inhomogeneities[2].mu[0].ncols()\n True\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n "
from sage.arith.srange import srange
from sage.functions.other import floor
k = self.k
M = recurrence_rules.M
m = recurrence_rules.m
ll = recurrence_rules.ll
uu = recurrence_rules.uu
inhomogeneities = recurrence_rules.inhomogeneities
lower = floor((ll / (k ** M)))
upper = (floor(((((k ** (M - 1)) - (k ** m)) + uu) / (k ** M))) + 1)
return {i: inhomogeneities[i].subsequence(1, {b: 1 for b in srange(lower, (upper + 1))}, minimize=False) for i in inhomogeneities}
def v_eval_n(self, recurrence_rules, n):
'\n Return the vector `v(n)` as given in [HKL2022]_, Theorem A.\n\n INPUT:\n\n - ``recurrence_rules`` -- a namedtuple generated by\n :meth:`parameters`\n\n - ``n`` -- an integer\n\n OUTPUT: a vector\n\n EXAMPLES:\n\n Stern--Brocot Sequence::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: SB_rules = RP.parameters(\n ....: 1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: {0: 0, 1: 1, 2: 1}, 0)\n sage: RP.v_eval_n(SB_rules, 0)\n (0, 1, 1)\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n '
from itertools import chain
from sage.arith.srange import srange
from sage.modules.free_module_element import vector
from sage.rings.integer_ring import ZZ
k = self.k
M = recurrence_rules.M
m = recurrence_rules.m
ll = recurrence_rules.ll
uu = recurrence_rules.uu
dim = (recurrence_rules.dim - recurrence_rules.n1)
initial_values = recurrence_rules.initial_values
inhomogeneities = recurrence_rules.inhomogeneities
ind = self.ind(M, m, ll, uu)
v = vector([initial_values[(((k ** ind[i][0]) * n) + ind[i][1])] for i in srange(dim)])
if (not all((S.is_trivial_zero() for S in inhomogeneities.values()))):
Seq = list(inhomogeneities.values())[0].parent()
W = Seq.indices()
shifted_inhomogeneities = self.shifted_inhomogeneities(recurrence_rules)
vv = [S.coefficient_of_word(W(ZZ(n).digits(k)), multiply_left=False) for S in shifted_inhomogeneities.values()]
v = vector(chain(v, *vv))
return v
def matrix(self, recurrence_rules, rem, correct_offset=True):
"\n Construct the matrix for remainder ``rem`` of the linear\n representation of the sequence represented by ``recurrence_rules``.\n\n INPUT:\n\n - ``recurrence_rules`` -- a namedtuple generated by\n :meth:`parameters`\n\n - ``rem`` -- an integer between ``0`` and ``k - 1``\n\n - ``correct_offset`` -- (default: ``True``) a boolean. If\n ``True``, then the resulting linear representation has no\n offset. See [HKL2022]_ for more information.\n\n OUTPUT: a matrix\n\n EXAMPLES:\n\n The following example illustrates how the coefficients in the\n right-hand sides of the recurrence relations correspond to the entries of\n the matrices. ::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: var('n')\n n\n sage: function('f')\n f\n sage: M, m, coeffs, initial_values = RP.parse_recurrence([\n ....: f(8*n) == -1*f(2*n - 1) + 1*f(2*n + 1),\n ....: f(8*n + 1) == -11*f(2*n - 1) + 10*f(2*n) + 11*f(2*n + 1),\n ....: f(8*n + 2) == -21*f(2*n - 1) + 20*f(2*n) + 21*f(2*n + 1),\n ....: f(8*n + 3) == -31*f(2*n - 1) + 30*f(2*n) + 31*f(2*n + 1),\n ....: f(8*n + 4) == -41*f(2*n - 1) + 40*f(2*n) + 41*f(2*n + 1),\n ....: f(8*n + 5) == -51*f(2*n - 1) + 50*f(2*n) + 51*f(2*n + 1),\n ....: f(8*n + 6) == -61*f(2*n - 1) + 60*f(2*n) + 61*f(2*n + 1),\n ....: f(8*n + 7) == -71*f(2*n - 1) + 70*f(2*n) + 71*f(2*n + 1),\n ....: f(0) == 0, f(1) == 1, f(2) == 2, f(3) == 3, f(4) == 4,\n ....: f(5) == 5, f(6) == 6, f(7) == 7], f, n)\n sage: rules = RP.parameters(\n ....: M, m, coeffs, initial_values, 0)\n sage: RP.matrix(rules, 0, False)\n [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0]\n [ 0 -51 50 51 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 -61 60 61 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 -71 70 71 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -11 10 11 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -21 20 21 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -31 30 31 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -41 40 41 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -51 50 51 0 0 0 0 0 0 0 0 0 0 0]\n sage: RP.matrix(rules, 1, False)\n [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]\n [ 0 0 0 -11 10 11 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -21 20 21 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -31 30 31 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -41 40 41 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -51 50 51 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -61 60 61 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 -71 70 71 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 -1 0 1 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 -11 10 11 0 0 0 0 0 0 0 0 0]\n\n Stern--Brocot Sequence::\n\n sage: SB_rules = RP.parameters(\n ....: 1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: {0: 0, 1: 1, 2: 1}, 0)\n sage: RP.matrix(SB_rules, 0)\n [1 0 0]\n [1 1 0]\n [0 1 0]\n sage: RP.matrix(SB_rules, 1)\n [1 1 0]\n [0 1 0]\n [0 1 1]\n\n Number of Unbordered Factors in the Thue--Morse Sequence::\n\n sage: M, m, coeffs, initial_values = RP.parse_recurrence([\n ....: f(8*n) == 2*f(4*n),\n ....: f(8*n + 1) == f(4*n + 1),\n ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3),\n ....: f(8*n + 3) == -f(4*n + 1) + f(4*n + 2),\n ....: f(8*n + 4) == 2*f(4*n + 2),\n ....: f(8*n + 5) == f(4*n + 3),\n ....: f(8*n + 6) == -f(4*n + 1) + f(4*n + 2) + f(4*n + 3),\n ....: f(8*n + 7) == 2*f(4*n + 1) + f(4*n + 3),\n ....: f(0) == 1, f(1) == 2, f(2) == 2, f(3) == 4, f(4) == 2,\n ....: f(5) == 4, f(6) == 6, f(7) == 0, f(8) == 4, f(9) == 4,\n ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4,\n ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0,\n ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n)\n sage: UB_rules = RP.parameters(\n ....: M, m, coeffs, initial_values, 3)\n sage: RP.matrix(UB_rules, 0)\n [ 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 2 0 0 0 0 0 0 0 0 0 -1 0 0]\n [ 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 1 0 1 0 0 0 0 0 0 -4 0 0]\n [ 0 0 0 0 -1 1 0 0 0 0 0 0 0 4 2 0]\n [ 0 0 0 0 0 2 0 0 0 0 0 0 0 -2 0 0]\n [ 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 -1 1 1 0 0 0 0 0 0 2 2 0]\n [ 0 0 0 0 2 0 1 0 0 0 0 0 0 -8 -4 -4]\n [ 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0]\n [ 0 0 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 1 0]\n sage: RP.matrix(UB_rules, 1)\n [ 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 2 0 0 0 0 0 0 0 -2 0 0]\n [ 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 -1 1 1 0 0 0 0 0 0 2 2 0]\n [ 0 0 0 0 2 0 1 0 0 0 0 0 0 -8 -4 -4]\n [ 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 -1 1 0 0 0 2 0 0]\n [ 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0]\n [ 0 0 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 1 0 0]\n [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n "
from itertools import chain
from sage.arith.srange import srange
from sage.functions.other import floor
from sage.matrix.constructor import Matrix
from sage.matrix.special import block_matrix, block_diagonal_matrix, zero_matrix
from sage.modules.free_module_element import vector
coefficient_ring = self.coefficient_ring
k = self.k
M = recurrence_rules.M
m = recurrence_rules.m
l = recurrence_rules.l
ll = recurrence_rules.ll
uu = recurrence_rules.uu
dim = recurrence_rules.dim
n1 = recurrence_rules.n1
dim_without_corr = (dim - n1)
coeffs = recurrence_rules.coeffs
inhomogeneities = recurrence_rules.inhomogeneities
ind = self.ind(M, m, ll, uu)
@cached_function
def coeff(r, k):
try:
return coeffs[(r, k)]
except KeyError:
return 0
def entry(i, kk):
(j, d) = ind[i]
if (j < (M - 1)):
return int((kk == ind[((j + 1), (((k ** j) * rem) + d))]))
else:
rem_d = (((k ** (M - 1)) * rem) + (d % (k ** M)))
dd = (d // (k ** M))
if (rem_d < (k ** M)):
lambd = (l - ind[(m, (((k ** m) * dd) + l))])
return coeff(rem_d, (kk + lambd))
else:
lambd = (l - ind[(m, ((((k ** m) * dd) + (k ** m)) + l))])
return coeff((rem_d - (k ** M)), (kk + lambd))
mat = Matrix(coefficient_ring, dim_without_corr, dim_without_corr, entry)
if (not all((S.is_trivial_zero() for S in inhomogeneities.values()))):
shifted_inhomogeneities = self.shifted_inhomogeneities(recurrence_rules)
lower = floor((ll / (k ** M)))
upper = (floor(((((k ** (M - 1)) - (k ** m)) + uu) / (k ** M))) + 1)
def wanted_inhomogeneity(row):
(j, d) = ind[row]
if (j != (M - 1)):
return (None, None)
rem_d = (((k ** (M - 1)) * rem) + (d % (k ** M)))
dd = (d // (k ** M))
if (rem_d < (k ** M)):
return (rem_d, dd)
elif (rem_d >= (k ** M)):
return ((rem_d - (k ** M)), (dd + 1))
else:
return (None, None)
def left_for_inhomogeneity(wanted):
return list(chain(*[((wanted == (r, i)) * inhomogeneity.left) for (r, inhomogeneity) in inhomogeneities.items() for i in srange(lower, (upper + 1))]))
def matrix_row(row):
wanted = wanted_inhomogeneity(row)
return left_for_inhomogeneity(wanted)
mat_upper_right = Matrix([matrix_row(row) for row in srange(dim_without_corr)])
mat_inhomog = block_diagonal_matrix([S.mu[rem] for S in shifted_inhomogeneities.values()], subdivide=False)
mat = block_matrix([[mat, mat_upper_right], [zero_matrix(mat_inhomog.nrows(), dim_without_corr), mat_inhomog]], subdivide=False)
dim_without_corr = mat.ncols()
dim = (dim_without_corr + n1)
if ((n1 > 0) and correct_offset):
W = Matrix(coefficient_ring, dim_without_corr, 0)
for i in srange(n1):
W = W.augment((self.v_eval_n(recurrence_rules, ((k * i) + rem)) - (mat * self.v_eval_n(recurrence_rules, i))))
J = Matrix(coefficient_ring, 0, n1)
for i in srange(n1):
J = J.stack(vector([int(((j * k) == (i - rem))) for j in srange(n1)]))
Z = zero_matrix(coefficient_ring, n1, dim_without_corr)
mat = block_matrix([[mat, W], [Z, J]], subdivide=False)
return mat
def left(self, recurrence_rules):
"\n Construct the vector ``left`` of the linear representation of\n recursive sequences.\n\n INPUT:\n\n - ``recurrence_rules`` -- a namedtuple generated by\n :meth:`parameters`; it only needs to contain a field\n ``dim`` (a positive integer)\n\n OUTPUT: a vector\n\n EXAMPLES::\n\n sage: from collections import namedtuple\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: RRD = namedtuple('recurrence_rules_dim',\n ....: ['dim', 'inhomogeneities'])\n sage: recurrence_rules = RRD(dim=5, inhomogeneities={})\n sage: RP.left(recurrence_rules)\n (1, 0, 0, 0, 0)\n\n ::\n\n sage: Seq2 = RegularSequenceRing(2, ZZ)\n sage: RRD = namedtuple('recurrence_rules_dim',\n ....: ['M', 'm', 'll', 'uu', 'dim', 'inhomogeneities'])\n sage: recurrence_rules = RRD(M=3, m=2, ll=0, uu=9, dim=5,\n ....: inhomogeneities={0: Seq2.one_hadamard()})\n sage: RP.left(recurrence_rules)\n (1, 0, 0, 0, 0, 0, 0, 0)\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n "
from sage.modules.free_module_element import vector
dim = recurrence_rules.dim
inhomogeneities = recurrence_rules.inhomogeneities
if (not all((S.is_trivial_zero() for S in inhomogeneities.values()))):
shifted_inhomogeneities = self.shifted_inhomogeneities(recurrence_rules)
dim += sum((shifted_inhomogeneities[i].mu[0].ncols() for i in shifted_inhomogeneities))
return vector(([1] + ((dim - 1) * [0])))
def right(self, recurrence_rules):
"\n Construct the vector ``right`` of the linear\n representation of the sequence induced by ``recurrence_rules``.\n\n INPUT:\n\n - ``recurrence_rules`` -- a namedtuple generated by\n :meth:`parameters`\n\n OUTPUT: a vector\n\n .. SEEALSO::\n\n :meth:`RegularSequenceRing.from_recurrence`\n\n TESTS:\n\n Stern--Brocot Sequence::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: var('n')\n n\n sage: function('f')\n f\n sage: SB_rules = RP.parameters(\n ....: 1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: {0: 0, 1: 1, 2: 1}, 0)\n sage: RP.right(SB_rules)\n (0, 1, 1)\n\n Number of Unbordered Factors in the Thue--Morse Sequence::\n\n sage: M, m, coeffs, initial_values = RP.parse_recurrence([\n ....: f(8*n) == 2*f(4*n),\n ....: f(8*n + 1) == f(4*n + 1),\n ....: f(8*n + 2) == f(4*n + 1) + f(4*n + 3),\n ....: f(8*n + 3) == -f(4*n + 1) + f(4*n + 2),\n ....: f(8*n + 4) == 2*f(4*n + 2),\n ....: f(8*n + 5) == f(4*n + 3),\n ....: f(8*n + 6) == -f(4*n + 1) + f(4*n + 2) + f(4*n + 3),\n ....: f(8*n + 7) == 2*f(4*n + 1) + f(4*n + 3),\n ....: f(0) == 1, f(1) == 2, f(2) == 2, f(3) == 4, f(4) == 2,\n ....: f(5) == 4, f(6) == 6, f(7) == 0, f(8) == 4, f(9) == 4,\n ....: f(10) == 4, f(11) == 4, f(12) == 12, f(13) == 0, f(14) == 4,\n ....: f(15) == 4, f(16) == 8, f(17) == 4, f(18) == 8, f(19) == 0,\n ....: f(20) == 8, f(21) == 4, f(22) == 4, f(23) == 8], f, n)\n sage: UB_rules = RP.parameters(\n ....: M, m, coeffs, initial_values, 3)\n sage: RP.right(UB_rules)\n (1, 1, 2, 1, 2, 2, 4, 2, 4, 6, 0, 4, 4, 1, 0, 0)\n "
from sage.modules.free_module_element import vector
n1 = recurrence_rules.n1
right = self.v_eval_n(recurrence_rules, 0)
if (n1 >= 1):
right = vector(((list(right) + [1]) + ((n1 - 1) * [0])))
return right
def __call__(self, *args, **kwds):
"\n Construct a `k`-linear representation that fulfills the recurrence relations\n given in ``equations``.\n\n This is the main method of :class:`RecurrenceParser` and\n is called by :meth:`RegularSequenceRing.from_recurrence`\n to construct a :class:`RegularSequence`.\n\n INPUT:\n\n All parameters are explained in the high-level method\n :meth:`RegularSequenceRing.from_recurrence`.\n\n OUTPUT: a linear representation ``(left, mu, right)``\n\n Many examples can be found in\n :meth:`RegularSequenceRing.from_recurrence`.\n\n TESTS::\n\n sage: from sage.combinat.regular_sequence import RecurrenceParser\n sage: RP = RecurrenceParser(2, ZZ)\n sage: var('n')\n n\n sage: function('f')\n f\n\n sage: RP([f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1),\n ....: f(0) == 0, f(1) == 1], f, n)\n ([\n [1 0 0] [1 1 0]\n [1 1 0] [0 1 0]\n [0 1 0], [0 1 1]\n ],\n (1, 0, 0),\n (0, 1, 1))\n\n sage: RP(equations=[f(2*n) == f(n), f(2*n + 1) == f(n) + f(n + 1),\n ....: f(0) == 0, f(1) == 1], function=f, var=n)\n ([\n [1 0 0] [1 1 0]\n [1 1 0] [0 1 0]\n [0 1 0], [0 1 1]\n ],\n (1, 0, 0),\n (0, 1, 1))\n\n sage: RP(1, 0, {(0, 0): 1, (1, 0): 1, (1, 1): 1}, {0: 0, 1: 1})\n ([\n [1 0 0] [1 1 0]\n [1 1 0] [0 1 0]\n [0 1 0], [0 1 1]\n ],\n (1, 0, 0),\n (0, 1, 1))\n\n sage: RP(M=1, m=0,\n ....: coeffs={(0, 0): 1, (1, 0): 1, (1, 1): 1},\n ....: initial_values={0: 0, 1: 1})\n ([\n [1 0 0] [1 1 0]\n [1 1 0] [0 1 0]\n [0 1 0], [0 1 1]\n ],\n (1, 0, 0),\n (0, 1, 1))\n "
from sage.arith.srange import srange
k = self.k
if (len(args) == 3):
(M, m, coeffs, initial_values) = self.parse_recurrence(*args)
elif ((len(args) == 0) and all(((kwd in kwds) for kwd in ['equations', 'function', 'var']))):
args = (kwds.pop('equations'), kwds.pop('function'), kwds.pop('var'))
(M, m, coeffs, initial_values) = self.parse_recurrence(*args)
elif (len(args) == 4):
(M, m, coeffs, initial_values) = self.parse_direct_arguments(*args)
elif ((len(args) == 0) and all(((kwd in kwds) for kwd in ['M', 'm', 'coeffs', 'initial_values']))):
args = (kwds.pop('M'), kwds.pop('m'), kwds.pop('coeffs'), kwds.pop('initial_values'))
(M, m, coeffs, initial_values) = self.parse_direct_arguments(*args)
else:
raise ValueError('Number of positional arguments must be three or four or all arguments provided as keywords.')
recurrence_rules = self.parameters(M, m, coeffs, initial_values, **kwds)
mu = [self.matrix(recurrence_rules, rem) for rem in srange(k)]
left = self.left(recurrence_rules)
right = self.right(recurrence_rules)
return (mu, left, right)
|
class RestrictedGrowthArrays(UniqueRepresentation, Parent):
def __init__(self, n):
"\n EXAMPLES::\n\n sage: from sage.combinat.restricted_growth import RestrictedGrowthArrays\n sage: R = RestrictedGrowthArrays(3)\n sage: R == loads(dumps(R))\n True\n sage: TestSuite(R).run(skip=['_test_an_element', # needs sage.libs.flint\n ....: '_test_enumerated_set_contains', '_test_some_elements'])\n "
self._n = n
self._name = ('Restricted growth arrays of size %s' % n)
Parent.__init__(self, category=FiniteEnumeratedSets())
def __iter__(self):
'\n EXAMPLES::\n\n sage: from sage.combinat.restricted_growth import RestrictedGrowthArrays\n sage: R = RestrictedGrowthArrays(3)\n sage: R.list()\n [[1, 0, 0], [2, 0, 1], [2, 1, 0], [2, 1, 1], [3, 1, 2]]\n '
n = self._n
a = ([1] + ([0] * (n - 1)))
m = ([0] + ([1] * (n - 1)))
while True:
(yield copy.copy(a))
i = (n - 1)
while ((a[i] == m[i]) and (i >= 0)):
i -= 1
if (i == 0):
break
a[i] += 1
a[0] = ((a[i] + 1) if (a[i] == m[i]) else m[i])
mi = a[0]
for j in range((i + 1), n):
a[j] = 0
m[j] = mi
def cardinality(self):
'\n EXAMPLES::\n\n sage: from sage.combinat.restricted_growth import RestrictedGrowthArrays\n sage: R = RestrictedGrowthArrays(6)\n sage: R.cardinality() # needs sage.libs.flint\n 203\n '
return bell_number(self._n)
|
class RibbonShapedTableau(SkewTableau):
'\n A ribbon shaped tableau.\n\n For the purposes of this class, a ribbon shaped tableau is a skew\n tableau whose shape is a skew partition which:\n\n - has at least one cell in row `1`;\n\n - has at least one cell in column `1`;\n\n - has exactly one cell in each of `q` consecutive diagonals, for\n some nonnegative integer `q`.\n\n A ribbon is given by a list of the rows from top to bottom.\n\n EXAMPLES::\n\n sage: x = RibbonShapedTableau([[None, None, None, 2, 3], [None, 1, 4, 5], [3, 2]]); x\n [[None, None, None, 2, 3], [None, 1, 4, 5], [3, 2]]\n sage: x.pp()\n . . . 2 3\n . 1 4 5\n 3 2\n sage: x.shape()\n [5, 4, 2] / [3, 1]\n\n The entries labeled by ``None`` correspond to the inner partition.\n Using ``None`` is optional; the entries will be shifted accordingly. ::\n\n sage: x = RibbonShapedTableau([[2,3],[1,4,5],[3,2]]); x.pp()\n . . . 2 3\n . 1 4 5\n 3 2\n\n TESTS::\n\n sage: r = RibbonShapedTableau([[1], [2,3], [4, 5, 6]])\n sage: r.to_permutation()\n [4, 5, 6, 2, 3, 1]\n\n sage: RibbonShapedTableau([[1,2],[3,4]]).evaluation()\n [1, 1, 1, 1]\n '
@staticmethod
def __classcall_private__(cls, rows):
'\n Return a ribbon shaped tableau object.\n\n EXAMPLES::\n\n sage: RibbonShapedTableau([[2,3],[1,4,5]])\n [[None, None, 2, 3], [1, 4, 5]]\n\n TESTS::\n\n sage: RibbonShapedTableau([4,5])\n Traceback (most recent call last):\n ...\n TypeError: rows must be lists of positive integers\n\n sage: RibbonShapedTableau([[2,3],[-4,5]])\n Traceback (most recent call last):\n ...\n TypeError: r must be a list of positive integers\n '
try:
r = [tuple(r) for r in rows]
except TypeError:
raise TypeError('rows must be lists of positive integers')
if (not r):
return StandardRibbonShapedTableaux()(r)
if all((((j is None) or (isinstance(j, (int, Integer)) and (j > 0))) for i in r for j in i)):
return StandardRibbonShapedTableaux()(r)
raise TypeError('r must be a list of positive integers')
def __init__(self, parent, t):
'\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: R = RibbonShapedTableau([[2,3],[1,4,5]])\n sage: TestSuite(R).run()\n '
if (not isinstance(t, SkewTableau)):
t = [[i for i in row if (i is not None)] for row in t]
st = []
space_count = 0
for row in reversed(t):
st.append((([None] * space_count) + row))
space_count += (len(row) - 1)
st.reverse()
t = st
else:
t = list(t)
SkewTableau.__init__(self, parent, t)
def height(self):
'\n Return the height of ``self``.\n\n The height is given by the number of rows in the outer partition.\n\n EXAMPLES::\n\n sage: RibbonShapedTableau([[2,3],[1,4,5]]).height()\n 2\n '
return len(self.outer_shape())
def spin(self):
'\n Return the spin of ``self``.\n\n EXAMPLES::\n\n sage: RibbonShapedTableau([[2,3],[1,4,5]]).spin()\n 1/2\n '
return (Integer((self.height() - 1)) / 2)
def width(self):
'\n Return the width of the ribbon.\n\n This is given by the length of the longest row in the outer partition.\n\n EXAMPLES::\n\n sage: RibbonShapedTableau([[2,3],[1,4,5]]).width()\n 4\n sage: RibbonShapedTableau([]).width()\n 0\n '
return (len(self[0]) if self else 0)
|
class RibbonShapedTableaux(SkewTableaux):
'\n The set of all ribbon shaped tableaux.\n '
@staticmethod
def __classcall_private__(cls, shape=None, **kwds):
'\n Normalize input to ensure a unique representation and pick the correct\n class based on input.\n\n The ``shape`` parameter is currently ignored.\n\n EXAMPLES::\n\n sage: S1 = RibbonShapedTableaux([4, 2, 2, 1])\n sage: S2 = RibbonShapedTableaux((4, 2, 2, 1))\n sage: S1 is S2\n True\n '
return super().__classcall__(cls, **kwds)
def __init__(self, category=None):
'\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: S = RibbonShapedTableaux() # needs sage.graphs\n sage: TestSuite(S).run() # needs sage.graphs\n '
if (category is None):
category = Sets()
SkewTableaux.__init__(self, category=category)
def _repr_(self):
"\n TESTS::\n\n sage: repr(RibbonShapedTableaux()) # indirect doctest\n 'Ribbon shaped tableaux'\n "
return 'Ribbon shaped tableaux'
Element = RibbonShapedTableau
options = Tableaux.options
def from_shape_and_word(self, shape, word):
'\n Return the ribbon corresponding to the given ribbon shape and word.\n\n EXAMPLES::\n\n sage: RibbonShapedTableaux().from_shape_and_word([1,3],[1,3,3,7])\n [[None, None, 1], [3, 3, 7]]\n '
pos = 0
r = []
for l in shape:
r.append(word[pos:(pos + l)])
pos += l
return self.element_class(self, r)
|
class StandardRibbonShapedTableaux(StandardSkewTableaux):
'\n The set of all standard ribbon shaped tableaux.\n\n INPUT:\n\n - ``shape`` -- (optional) the composition shape of the rows\n '
@staticmethod
def __classcall_private__(cls, shape=None, **kwds):
'\n Normalize input to ensure a unique representation and pick the correct\n class based on input.\n\n EXAMPLES::\n\n sage: S1 = StandardRibbonShapedTableaux([4, 2, 2, 1])\n sage: S2 = StandardRibbonShapedTableaux((4, 2, 2, 1))\n sage: S1 is S2\n True\n '
if (shape is not None):
from sage.combinat.partition import Partition
return StandardRibbonShapedTableaux_shape(Partition(shape))
return super().__classcall__(cls, **kwds)
def __init__(self, category=None):
'\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: # needs sage.graphs sage.modules\n sage: S = StandardRibbonShapedTableaux()\n sage: TestSuite(S).run()\n '
if (category is None):
category = InfiniteEnumeratedSets()
StandardSkewTableaux.__init__(self, category=category)
def _repr_(self):
"\n TESTS::\n\n sage: repr(StandardRibbonShapedTableaux()) # indirect doctest\n 'Standard ribbon shaped tableaux'\n "
return 'Standard ribbon shaped tableaux'
def __iter__(self):
'\n Iterate through ``self``.\n\n EXAMPLES::\n\n sage: # needs sage.graphs sage.modules\n sage: it = StandardRibbonShapedTableaux().__iter__()\n sage: [next(it) for x in range(10)]\n [[],\n [[1]],\n [[1, 2]],\n [[1], [2]],\n [[1, 2, 3]],\n [[None, 1], [2, 3]],\n [[None, 2], [1, 3]],\n [[1], [2], [3]],\n [[1, 2, 3, 4]],\n [[None, None, 1], [2, 3, 4]]]\n '
from sage.combinat.partition import _Partitions
for p in _Partitions:
for r in StandardRibbonShapedTableaux_shape(p):
(yield self.element_class(self, r))
Element = RibbonShapedTableau
options = Tableaux.options
def from_shape_and_word(self, shape, word):
'\n Return the ribbon corresponding to the given ribbon shape and word.\n\n EXAMPLES::\n\n sage: StandardRibbonShapedTableaux().from_shape_and_word([2,3],[1,2,3,4,5])\n [[None, None, 1, 2], [3, 4, 5]]\n '
pos = 0
r = []
for l in shape:
r.append(word[pos:(pos + l)])
pos += l
return self.element_class(self, r)
def from_permutation(self, p):
'\n Return a standard ribbon of size ``len(p)`` from a permutation ``p``. The\n lengths of each row are given by the distance between the descents\n of the permutation ``p``.\n\n EXAMPLES::\n\n sage: import sage.combinat.ribbon_shaped_tableau as rst\n sage: [StandardRibbonShapedTableaux().from_permutation(p) for p in Permutations(3)]\n [[[1, 2, 3]],\n [[None, 2], [1, 3]],\n [[1, 3], [2]],\n [[None, 1], [2, 3]],\n [[1, 2], [3]],\n [[1], [2], [3]]]\n '
if (p == []):
return self.element_class(self, [])
comp = p.descents()
if (comp == []):
return self.element_class(self, [p[:]])
r = []
r.append([p[j] for j in range(comp[0])])
for i in range((len(comp) - 1)):
r.append([p[j] for j in range(comp[i], comp[(i + 1)])])
r.append([p[j] for j in range(comp[(- 1)], len(p))])
r.reverse()
return self.element_class(self, r)
|
class StandardRibbonShapedTableaux_shape(StandardRibbonShapedTableaux):
'\n Class of standard ribbon shaped tableaux of ribbon shape ``shape``.\n\n EXAMPLES::\n\n sage: StandardRibbonShapedTableaux([2,2])\n Standard ribbon shaped tableaux of shape [2, 2]\n sage: StandardRibbonShapedTableaux([2,2]).first()\n [[None, 2, 4], [1, 3]]\n sage: StandardRibbonShapedTableaux([2,2]).last()\n [[None, 1, 2], [3, 4]]\n\n sage: # needs sage.graphs sage.modules\n sage: StandardRibbonShapedTableaux([2,2]).cardinality()\n 5\n sage: StandardRibbonShapedTableaux([2,2]).list()\n [[[None, 1, 3], [2, 4]],\n [[None, 1, 2], [3, 4]],\n [[None, 2, 3], [1, 4]],\n [[None, 2, 4], [1, 3]],\n [[None, 1, 4], [2, 3]]]\n sage: StandardRibbonShapedTableaux([3,2,2]).cardinality()\n 155\n '
@staticmethod
def __classcall_private__(cls, shape):
'\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: S = StandardRibbonShapedTableaux([2,2])\n sage: S2 = StandardRibbonShapedTableaux((2,2))\n sage: S is S2\n True\n '
return super(StandardRibbonShapedTableaux, cls).__classcall__(cls, tuple(shape))
def __init__(self, shape):
'\n TESTS::\n\n sage: S = StandardRibbonShapedTableaux([2,2])\n sage: TestSuite(S).run() # needs sage.graphs\n '
self.shape = shape
StandardRibbonShapedTableaux.__init__(self, FiniteEnumeratedSets())
def _repr_(self):
'\n TESTS::\n\n sage: StandardRibbonShapedTableaux([2,2])\n Standard ribbon shaped tableaux of shape [2, 2]\n '
return ('Standard ribbon shaped tableaux of shape %s' % list(self.shape))
def first(self):
'\n Return the first standard ribbon of ``self``.\n\n EXAMPLES::\n\n sage: StandardRibbonShapedTableaux([2,2]).first()\n [[None, 2, 4], [1, 3]]\n '
return self.from_permutation(descents_composition_first(self.shape))
def last(self):
'\n Return the last standard ribbon of ``self``.\n\n EXAMPLES::\n\n sage: StandardRibbonShapedTableaux([2,2]).last()\n [[None, 1, 2], [3, 4]]\n '
return self.from_permutation(descents_composition_last(self.shape))
def __iter__(self):
'\n An iterator for the standard ribbon of ``self``.\n\n EXAMPLES::\n\n sage: [t for t in StandardRibbonShapedTableaux([2,2])] # needs sage.graphs\n [[[None, 1, 3], [2, 4]],\n [[None, 1, 2], [3, 4]],\n [[None, 2, 3], [1, 4]],\n [[None, 2, 4], [1, 3]],\n [[None, 1, 4], [2, 3]]]\n\n '
for p in descents_composition_list(self.shape):
(yield self.from_permutation(p))
|
class Ribbon_class(RibbonShapedTableau):
'\n This exists solely for unpickling ``Ribbon_class`` objects.\n '
def __setstate__(self, state):
'\n Unpickle old ``Ribbon_class`` objects.\n\n EXAMPLES::\n\n sage: loads(b\'x\\x9ck`J.NLO\\xd5K\\xce\\xcfM\\xca\\xccK,\\xd1+\\xcaLJ\\xca\\xcf\\xe3\\n\\x02S\\xf1\\xc99\\x89\\xc5\\xc5\\\\\\x85\\x8c\\x9a\\x8d\\x85L\\xb5\\x85\\xcc\\x1a\\xa1\\xac\\xf1\\x19\\x89\\xc5\\x19\\x85,~@VNfqI!kl!\\x9bFl!\\xbb\\x06\\xc4\\x9c\\xa2\\xcc\\xbc\\xf4b\\xbd\\xcc\\xbc\\x92\\xd4\\xf4\\xd4"\\xae\\xdc\\xc4\\xec\\xd4x\\x18\\xa7\\x90#\\x94\\xd1\\xb05\\xa8\\x903\\x03\\xc80\\x022\\xb8Rc\\x0b\\xb95@<c \\x8f\\x07\\xc40\\x012xSSK\\x93\\xf4\\x00l\\x811\\x17\')\n [[None, 1, 2], [3, 4]]\n sage: loads(dumps( RibbonShapedTableau([[3,2,1], [1,1]]) )) # indirect doctest\n [[None, 3, 2, 1], [1, 1]]\n '
self.__class__ = RibbonShapedTableau
self.__init__(RibbonShapedTableaux(), state['_list'])
|
class RibbonTableau(SkewTableau):
'\n A ribbon tableau.\n\n A ribbon is a connected skew shape which does not contain any\n `2 \\times 2` boxes. A ribbon tableau is a skew tableau\n whose shape is partitioned into ribbons, each of which is filled\n with identical entries.\n\n EXAMPLES::\n\n sage: rt = RibbonTableau([[None, 1],[2,3]]); rt\n [[None, 1], [2, 3]]\n sage: rt.inner_shape()\n [1]\n sage: rt.outer_shape()\n [2, 2]\n\n sage: rt = RibbonTableau([[None, None, 0, 0, 0], [None, 0, 0, 2], [1, 0, 1]]); rt.pp()\n . . 0 0 0\n . 0 0 2\n 1 0 1\n\n In the previous example, each ribbon is uniquely determined by a\n non-zero entry. The 0 entries are used to fill in the rest of the\n skew shape.\n\n .. NOTE::\n\n Sanity checks are not performed; lists can contain any object.\n\n ::\n\n sage: RibbonTableau(expr=[[1,1],[[5],[3,4],[1,2]]])\n [[None, 1, 2], [None, 3, 4], [5]]\n\n TESTS::\n\n sage: RibbonTableau([[0, 0, 3, 0], [1, 1, 0], [2, 0, 4]]).evaluation()\n [2, 1, 1, 1]\n '
@staticmethod
def __classcall_private__(cls, rt=None, expr=None):
'\n Return a ribbon tableau object.\n\n EXAMPLES::\n\n sage: rt = RibbonTableau([[None, 1],[2,3]]); rt\n [[None, 1], [2, 3]]\n sage: TestSuite(rt).run()\n '
if (expr is not None):
return RibbonTableaux().from_expr(expr)
try:
rt = [tuple(row) for row in rt]
except TypeError:
raise TypeError('each element of the ribbon tableau must be an iterable')
if (not all((row for row in rt))):
raise TypeError('a ribbon tableau cannot have empty rows')
return RibbonTableaux()(rt)
def length(self):
'\n Return the length of the ribbons into a ribbon tableau.\n\n EXAMPLES::\n\n sage: RibbonTableau([[None, 1],[2,3]]).length()\n 1\n sage: RibbonTableau([[1,0],[2,0]]).length()\n 2\n '
if (self.to_expr() == [[], []]):
return 0
tableau = self.to_expr()[1]
l = 0
t = 0
for k in range(len(tableau)):
t += len([x for x in tableau[k] if ((x is not None) and (x > (- 1)))])
l += len([x for x in tableau[k] if ((x is not None) and (x > 0))])
if (l == 0):
return t
else:
return (t // l)
def to_word(self):
'\n Return a word obtained from a row reading of ``self``.\n\n .. WARNING::\n\n Unlike the ``to_word`` method on skew tableaux (which are a\n superclass of this), this method does not filter out\n ``None`` entries.\n\n EXAMPLES::\n\n sage: R = RibbonTableau([[0, 0, 3, 0], [1, 1, 0], [2, 0, 4]])\n sage: R.to_word()\n word: 2041100030\n '
from sage.combinat.words.word import Word
return Word([letter for row in reversed(self) for letter in row])
|
class RibbonTableaux(UniqueRepresentation, Parent):
'\n Ribbon tableaux.\n\n A ribbon tableau is a skew tableau whose skew shape ``shape`` is\n tiled by ribbons of length ``length``. The weight ``weight`` is\n calculated from the labels on the ribbons.\n\n .. NOTE::\n\n Here we impose the condition that the ribbon tableaux are semistandard.\n\n INPUT(Optional):\n\n - ``shape`` -- skew shape as a list of lists or an object of type\n SkewPartition\n\n - ``length`` -- integer, ``shape`` is partitioned into ribbons of\n length ``length``\n\n - ``weight`` -- list of integers, computed from the values of\n non-zero entries labeling the ribbons\n\n EXAMPLES::\n\n sage: RibbonTableaux([[2,1],[]], [1,1,1], 1)\n Ribbon tableaux of shape [2, 1] / [] and weight [1, 1, 1] with 1-ribbons\n\n sage: R = RibbonTableaux([[5,4,3],[2,1]], [2,1], 3)\n sage: for i in R: i.pp(); print("\\n")\n . . 0 0 0\n . 0 0 2\n 1 0 1\n <BLANKLINE>\n . . 1 0 0\n . 0 0 0\n 1 0 2\n <BLANKLINE>\n . . 0 0 0\n . 1 0 1\n 2 0 0\n <BLANKLINE>\n\n REFERENCES:\n\n .. [vanLeeuwen91] Marc. A. A. van Leeuwen, *Edge sequences, ribbon tableaux,\n and an action of affine permutations*. Europe J. Combinatorics. **20**\n (1999). http://wwwmathlabo.univ-poitiers.fr/~maavl/pdf/edgeseqs.pdf\n '
@staticmethod
def __classcall_private__(cls, shape=None, weight=None, length=None):
'\n Return the correct parent object.\n\n EXAMPLES::\n\n sage: R = RibbonTableaux([[2,1],[]],[1,1,1],1)\n sage: R2 = RibbonTableaux(SkewPartition([[2,1],[]]),(1,1,1),1)\n sage: R is R2\n True\n '
if ((shape is None) and (weight is None) and (length is None)):
return super().__classcall__(cls)
return RibbonTableaux_shape_weight_length(shape, weight, length)
def __init__(self):
'\n EXAMPLES::\n\n sage: R = RibbonTableaux()\n sage: TestSuite(R).run()\n '
Parent.__init__(self, category=Sets())
def _repr_(self):
'\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: RibbonTableaux()\n Ribbon tableaux\n '
return 'Ribbon tableaux'
def _element_constructor_(self, rt):
'\n Construct an element of ``self`` from ``rt``.\n\n EXAMPLES::\n\n sage: R = RibbonTableaux()\n sage: elt = R([[0, 0, 3, 0], [1, 1, 0], [2, 0, 4]]); elt\n [[0, 0, 3, 0], [1, 1, 0], [2, 0, 4]]\n sage: elt.parent() is R\n True\n '
return self.element_class(self, rt)
def from_expr(self, l):
'\n Return a :class:`RibbonTableau` from a MuPAD-Combinat expr for a skew\n tableau. The first list in ``expr`` is the inner shape of the skew\n tableau. The second list are the entries in the rows of the skew\n tableau from bottom to top.\n\n Provided primarily for compatibility with MuPAD-Combinat.\n\n EXAMPLES::\n\n sage: RibbonTableaux().from_expr([[1,1],[[5],[3,4],[1,2]]])\n [[None, 1, 2], [None, 3, 4], [5]]\n '
return self.element_class(self, SkewTableaux().from_expr(l))
Element = RibbonTableau
options = Tableaux.options
|
class RibbonTableaux_shape_weight_length(RibbonTableaux):
'\n Ribbon tableaux of a given shape, weight, and length.\n '
@staticmethod
def __classcall_private__(cls, shape, weight, length):
'\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: R = RibbonTableaux([[2,1],[]],[1,1,1],1)\n sage: R2 = RibbonTableaux(SkewPartition([[2,1],[]]),(1,1,1),1)\n sage: R is R2\n True\n '
if (shape in _Partitions):
shape = _Partitions(shape)
shape = SkewPartition([shape, shape.core(length)])
else:
shape = SkewPartition(shape)
if (shape.size() != (length * sum(weight))):
raise ValueError('incompatible shape and weight')
return super().__classcall__(cls, shape, tuple(weight), length)
def __init__(self, shape, weight, length):
'\n EXAMPLES::\n\n sage: R = RibbonTableaux([[2,1],[]],[1,1,1],1)\n sage: TestSuite(R).run()\n '
self._shape = shape
self._weight = weight
self._length = length
Parent.__init__(self, category=FiniteEnumeratedSets())
def __iter__(self):
'\n EXAMPLES::\n\n sage: RibbonTableaux([[2,1],[]],[1,1,1],1).list()\n [[[1, 3], [2]], [[1, 2], [3]]]\n sage: RibbonTableaux([[2,2],[]],[1,1],2).list()\n [[[0, 0], [1, 2]], [[1, 0], [2, 0]]]\n '
for x in graph_implementation_rec(self._shape, self._weight, self._length, list_rec):
(yield self.from_expr(x))
def _repr_(self):
'\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: RibbonTableaux([[2,1],[]], [1,1,1], 1)\n Ribbon tableaux of shape [2, 1] / [] and weight [1, 1, 1] with 1-ribbons\n '
return ('Ribbon tableaux of shape %s and weight %s with %s-ribbons' % (repr(self._shape), list(self._weight), self._length))
def __contains__(self, x):
'\n Note that this just checks to see if ``x`` appears in ``self``.\n\n This should be improved to provide actual checking.\n\n EXAMPLES::\n\n sage: r = RibbonTableaux([[2,2],[]],[1,1],2)\n sage: [[0, 0], [1, 2]] in r\n True\n sage: [[1, 0], [2, 0]] in r\n True\n sage: [[0, 1], [2, 0]] in r\n False\n '
try:
x = RibbonTableau(x)
except (ValueError, TypeError):
return False
return (x in self.list())
def cardinality(self):
'\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: RibbonTableaux([[2,1],[]],[1,1,1],1).cardinality()\n 2\n sage: RibbonTableaux([[2,2],[]],[1,1],2).cardinality()\n 2\n sage: RibbonTableaux([[4,3,3],[]],[2,1,1,1],2).cardinality()\n 5\n\n TESTS::\n\n sage: RibbonTableaux([6,6,6], [4,2], 3).cardinality()\n 6\n sage: RibbonTableaux([3,3,3,2,1], [3,1], 3).cardinality()\n 1\n sage: RibbonTableaux([3,3,3,2,1], [2,2], 3).cardinality()\n 2\n sage: RibbonTableaux([3,3,3,2,1], [2,1,1], 3).cardinality()\n 5\n sage: RibbonTableaux([3,3,3,2,1], [1,1,1,1], 3).cardinality()\n 12\n sage: RibbonTableaux([5,4,3,2,1], [2,2,1], 3).cardinality()\n 10\n\n ::\n\n sage: RibbonTableaux([8,7,6,5,1,1], [3,2,2,1], 3).cardinality()\n 85\n sage: RibbonTableaux([5,4,3,2,1,1,1], [2,2,1], 3).cardinality()\n 10\n\n ::\n\n sage: RibbonTableaux([7,7,7,2,1,1], [3,2,0,1,1], 3).cardinality()\n 25\n\n Weights with some zeros in the middle and end::\n\n sage: RibbonTableaux([3,3,3], [0,1,0,2,0], 3).cardinality()\n 3\n sage: RibbonTableaux([3,3,3], [1,0,1,0,1,0,0,0], 3).cardinality()\n 6\n '
wt = [i for i in self._weight if (i != 0)]
return Integer(graph_implementation_rec(self._shape, wt, self._length, count_rec)[0])
|
def insertion_tableau(skp, perm, evaluation, tableau, length):
'\n INPUT:\n\n - ``skp`` -- skew partitions\n\n - ``perm, evaluation`` -- non-negative integers\n\n - ``tableau`` -- skew tableau\n\n - ``length`` -- integer\n\n TESTS::\n\n sage: from sage.combinat.ribbon_tableau import insertion_tableau\n sage: insertion_tableau([[1], []], [1], 1, [[], []], 1)\n [[], [[1]]]\n sage: insertion_tableau([[2, 1], []], [1, 1], 2, [[], [[1]]], 1)\n [[], [[2], [1, 2]]]\n sage: insertion_tableau([[2, 1], []], [0, 0], 3, [[], [[2], [1, 2]]], 1)\n [[], [[2], [1, 2]]]\n sage: insertion_tableau([[1, 1], []], [1], 2, [[], [[1]]], 1)\n [[], [[2], [1]]]\n sage: insertion_tableau([[2], []], [0, 1], 2, [[], [[1]]], 1)\n [[], [[1, 2]]]\n sage: insertion_tableau([[2, 1], []], [0, 1], 3, [[], [[2], [1]]], 1)\n [[], [[2], [1, 3]]]\n sage: insertion_tableau([[1, 1], []], [2], 1, [[], []], 2)\n [[], [[1], [0]]]\n sage: insertion_tableau([[2], []], [2, 0], 1, [[], []], 2)\n [[], [[1, 0]]]\n sage: insertion_tableau([[2, 2], []], [0, 2], 2, [[], [[1], [0]]], 2)\n [[], [[1, 2], [0, 0]]]\n sage: insertion_tableau([[2, 2], []], [2, 0], 2, [[], [[1, 0]]], 2)\n [[], [[2, 0], [1, 0]]]\n sage: insertion_tableau([[2, 2], [1]], [3, 0], 1, [[], []], 3)\n [[1], [[1, 0], [0]]]\n '
psave = Partition(skp[1])
partc = (skp[1] + ([0] * (len(skp[0]) - len(skp[1]))))
tableau = SkewTableau(expr=tableau).to_expr()[1]
for k in range(len(tableau)):
tableau[(- (k + 1))] += ([0] * ((skp[0][k] - partc[k]) - len(tableau[(- (k + 1))])))
tableau = ([([0] * (skp[0][k] - partc[k])) for k in reversed(range(len(tableau), len(skp[0])))] + tableau)
tableau = SkewTableaux().from_expr([skp[1], tableau]).conjugate()
tableau = tableau.to_expr()[1]
skp = SkewPartition(skp).conjugate().to_list()
skp[1].extend(([0] * (len(skp[0]) - len(skp[1]))))
if (len(perm) > len(skp[0])):
return None
lp = len(perm)
for k in range(lp):
if (perm[(- (k + 1))] != 0):
tableau[((len(tableau) - lp) + k)][((skp[0][(lp - (k + 1))] - skp[1][(lp - (k + 1))]) - 1)] = evaluation
return SkewTableau(expr=[psave.conjugate(), tableau]).conjugate().to_expr()
|
def count_rec(nexts, current, part, weight, length):
'\n INPUT:\n\n - ``nexts, current, part`` -- skew partitions\n\n - ``weight`` -- non-negative integer list\n\n - ``length`` -- integer\n\n TESTS::\n\n sage: from sage.combinat.ribbon_tableau import count_rec\n sage: count_rec([], [], [[2, 1, 1], []], [2], 2)\n [0]\n sage: count_rec([[0], [1]], [[[2, 1, 1], [0, 0, 2, 0]], [[4], [2, 0, 0, 0]]], [[4, 1, 1], []], [2, 1], 2)\n [1]\n sage: count_rec([], [[[], [2, 2]]], [[2, 2], []], [2], 2)\n [1]\n sage: count_rec([], [[[], [2, 0, 2, 0]]], [[4], []], [2], 2)\n [1]\n sage: count_rec([[1], [1]], [[[2, 2], [0, 0, 2, 0]], [[4], [2, 0, 0, 0]]], [[4, 2], []], [2, 1], 2)\n [2]\n sage: count_rec([[1], [1], [2]], [[[2, 2, 2], [0, 0, 2, 0]], [[4, 1, 1], [0, 2, 0, 0]], [[4, 2], [2, 0, 0, 0]]], [[4, 2, 2], []], [2, 1, 1], 2)\n [4]\n sage: count_rec([[4], [1]], [[[4, 2, 2], [0, 0, 2, 0]], [[4, 3, 1], [0, 2, 0, 0]]], [[4, 3, 3], []], [2, 1, 1, 1], 2)\n [5]\n '
if (not current):
return [0]
if nexts:
return [sum((j for i in nexts for j in i))]
else:
return [len(current)]
|
def list_rec(nexts, current, part, weight, length):
'\n INPUT:\n\n - ``nexts, current, part`` -- skew partitions\n\n - ``weight`` -- non-negative integer list\n\n - ``length`` -- integer\n\n TESTS::\n\n sage: from sage.combinat.ribbon_tableau import list_rec\n sage: list_rec([], [[[], [1]]], [[1], []], [1], 1)\n [[[], [[1]]]]\n sage: list_rec([[[[], [[1]]]]], [[[1], [1, 1]]], [[2, 1], []], [1, 2], 1)\n [[[], [[2], [1, 2]]]]\n sage: list_rec([], [[[1], [3, 0]]], [[2, 2], [1]], [1], 3)\n [[[1], [[1, 0], [0]]]]\n sage: list_rec([[[[], [[2]]]]], [[[1], [1, 1]]], [[2, 1], []], [0, 1, 2], 1)\n [[[], [[3], [2, 3]]]]\n sage: list_rec([], [[[], [2]]], [[1, 1], []], [1], 2)\n [[[], [[1], [0]]]]\n sage: list_rec([], [[[], [2, 0]]], [[2], []], [1], 2)\n [[[], [[1, 0]]]]\n sage: list_rec([[[[], [[1], [0]]]], [[[], [[1, 0]]]]], [[[1, 1], [0, 2]], [[2], [2, 0]]], [[2, 2], []], [1, 1], 2)\n [[[], [[1, 2], [0, 0]]], [[], [[2, 0], [1, 0]]]]\n sage: list_rec([], [[[], [2, 2]]], [[2, 2], []], [2], 2)\n [[[], [[1, 1], [0, 0]]]]\n sage: list_rec([], [[[], [1, 1]]], [[2], []], [2], 1)\n [[[], [[1, 1]]]]\n sage: list_rec([[[[], [[1, 1]]]]], [[[2], [1, 1]]], [[2, 2], []], [2, 2], 1)\n [[[], [[2, 2], [1, 1]]]]\n '
if ((current == []) and (nexts == []) and (weight == [])):
return [[part[1], []]]
if (not current):
return []
if nexts:
return [insertion_tableau(part, curr_i[1], len(weight), nexts_ij, length) for (nexts_i, curr_i) in zip(nexts, current) for nexts_ij in nexts_i]
return [insertion_tableau(part, curr_i[1], len(weight), [[], []], length) for curr_i in current]
|
def spin_rec(t, nexts, current, part, weight, length):
"\n Routine used for constructing the spin polynomial.\n\n INPUT:\n\n - ``weight`` -- list of non-negative integers\n\n - ``length`` -- the length of the ribbons we're tiling with\n\n - ``t`` -- the variable\n\n EXAMPLES::\n\n sage: from sage.combinat.ribbon_tableau import spin_rec\n sage: sp = SkewPartition\n sage: t = ZZ['t'].gen()\n sage: spin_rec(t, [], [[[], [3, 3]]], sp([[2, 2, 2], []]), [2], 3)\n [t^4]\n sage: spin_rec(t, [[0], [t^4]], [[[2, 1, 1, 1, 1], [0, 3]], [[2, 2, 2], [3, 0]]], sp([[2, 2, 2, 2, 1], []]), [2, 1], 3)\n [t^5]\n sage: spin_rec(t, [], [[[], [3, 3, 0]]], sp([[3, 3], []]), [2], 3)\n [t^2]\n sage: spin_rec(t, [[t^4], [t^3], [t^2]], [[[2, 2, 2], [0, 0, 3]], [[3, 2, 1], [0, 3, 0]], [[3, 3], [3, 0, 0]]], sp([[3, 3, 3], []]), [2, 1], 3)\n [t^6 + t^4 + t^2]\n sage: spin_rec(t, [[t^5], [t^4], [t^6 + t^4 + t^2]], [[[2, 2, 2, 2, 1], [0, 0, 3]], [[3, 3, 1, 1, 1], [0, 3, 0]], [[3, 3, 3], [3, 0, 0]]], sp([[3, 3, 3, 2, 1], []]), [2, 1, 1], 3)\n [2*t^7 + 2*t^5 + t^3]\n "
if (not current):
return [parent(t).zero()]
tmp = []
partp = part[0].conjugate()
ell = len(partp)
for val in current:
perms = val[1]
perm = [(((partp[i] + ell) - (i + 1)) - perms[i]) for i in reversed(range(ell))]
perm = to_standard(perm)
tmp.append(((weight[(- 1)] * (length - 1)) - perm.number_of_inversions()))
if nexts:
return [sum((sum((((t ** tval) * nval) for nval in nexts[i])) for (i, tval) in enumerate(tmp)))]
return [sum(((t ** val) for val in tmp))]
|
def spin_polynomial_square(part, weight, length):
'\n Returns the spin polynomial associated with ``part``, ``weight``, and\n ``length``, with the substitution `t \\to t^2` made.\n\n EXAMPLES::\n\n sage: from sage.combinat.ribbon_tableau import spin_polynomial_square\n sage: spin_polynomial_square([6,6,6],[4,2],3)\n t^12 + t^10 + 2*t^8 + t^6 + t^4\n sage: spin_polynomial_square([6,6,6],[4,1,1],3)\n t^12 + 2*t^10 + 3*t^8 + 2*t^6 + t^4\n sage: spin_polynomial_square([3,3,3,2,1], [2,2], 3)\n t^7 + t^5\n sage: spin_polynomial_square([3,3,3,2,1], [2,1,1], 3)\n 2*t^7 + 2*t^5 + t^3\n sage: spin_polynomial_square([3,3,3,2,1], [1,1,1,1], 3)\n 3*t^7 + 5*t^5 + 3*t^3 + t\n sage: spin_polynomial_square([5,4,3,2,1,1,1], [2,2,1], 3)\n 2*t^9 + 6*t^7 + 2*t^5\n sage: spin_polynomial_square([[6]*6, [3,3]], [4,4,2], 3)\n 3*t^18 + 5*t^16 + 9*t^14 + 6*t^12 + 3*t^10\n '
R = ZZ['t']
if (part in _Partitions):
part = SkewPartition([part, _Partitions([])])
elif (part in SkewPartitions()):
part = SkewPartition(part)
if ((part == [[], []]) and (not weight)):
return R.one()
t = R.gen()
return R(graph_implementation_rec(part, weight, length, functools.partial(spin_rec, t))[0])
|
def spin_polynomial(part, weight, length):
'\n Returns the spin polynomial associated to ``part``, ``weight``, and\n ``length``.\n\n EXAMPLES::\n\n sage: # needs sage.symbolic\n sage: from sage.combinat.ribbon_tableau import spin_polynomial\n sage: spin_polynomial([6,6,6],[4,2],3)\n t^6 + t^5 + 2*t^4 + t^3 + t^2\n sage: spin_polynomial([6,6,6],[4,1,1],3)\n t^6 + 2*t^5 + 3*t^4 + 2*t^3 + t^2\n sage: spin_polynomial([3,3,3,2,1], [2,2], 3)\n t^(7/2) + t^(5/2)\n sage: spin_polynomial([3,3,3,2,1], [2,1,1], 3)\n 2*t^(7/2) + 2*t^(5/2) + t^(3/2)\n sage: spin_polynomial([3,3,3,2,1], [1,1,1,1], 3)\n 3*t^(7/2) + 5*t^(5/2) + 3*t^(3/2) + sqrt(t)\n sage: spin_polynomial([5,4,3,2,1,1,1], [2,2,1], 3)\n 2*t^(9/2) + 6*t^(7/2) + 2*t^(5/2)\n sage: spin_polynomial([[6]*6, [3,3]], [4,4,2], 3)\n 3*t^9 + 5*t^8 + 9*t^7 + 6*t^6 + 3*t^5\n '
from sage.symbolic.ring import SR
sp = spin_polynomial_square(part, weight, length)
t = SR.var('t')
coeffs = sp.list()
return sum(((c * (t ** (ZZ(i) / 2))) for (i, c) in enumerate(coeffs)))
|
def cospin_polynomial(part, weight, length):
'\n Return the cospin polynomial associated to ``part``, ``weight``, and\n ``length``.\n\n EXAMPLES::\n\n sage: from sage.combinat.ribbon_tableau import cospin_polynomial\n sage: cospin_polynomial([6,6,6],[4,2],3)\n t^4 + t^3 + 2*t^2 + t + 1\n sage: cospin_polynomial([3,3,3,2,1], [3,1], 3)\n 1\n sage: cospin_polynomial([3,3,3,2,1], [2,2], 3)\n t + 1\n sage: cospin_polynomial([3,3,3,2,1], [2,1,1], 3)\n t^2 + 2*t + 2\n sage: cospin_polynomial([3,3,3,2,1], [1,1,1,1], 3)\n t^3 + 3*t^2 + 5*t + 3\n sage: cospin_polynomial([5,4,3,2,1,1,1], [2,2,1], 3)\n 2*t^2 + 6*t + 2\n sage: cospin_polynomial([[6]*6, [3,3]], [4,4,2], 3)\n 3*t^4 + 6*t^3 + 9*t^2 + 5*t + 3\n '
R = ZZ['t']
sp = spin_polynomial_square(part, weight, length)
if (sp == 0):
return R.zero()
coeffs = [c for c in sp.list() if c]
d = (len(coeffs) - 1)
t = R.gen()
return R(sum(((c * (t ** (d - i))) for (i, c) in enumerate(coeffs))))
|
def graph_implementation_rec(skp, weight, length, function):
'\n TESTS::\n\n sage: from sage.combinat.ribbon_tableau import graph_implementation_rec, list_rec\n sage: graph_implementation_rec(SkewPartition([[1], []]), [1], 1, list_rec)\n [[[], [[1]]]]\n sage: graph_implementation_rec(SkewPartition([[2, 1], []]), [1, 2], 1, list_rec)\n [[[], [[2], [1, 2]]]]\n sage: graph_implementation_rec(SkewPartition([[], []]), [0], 1, list_rec)\n [[[], []]]\n '
if (sum(weight) == 0):
weight = []
partp = skp[0].conjugate()
ell = len(partp)
outer = skp[1]
outer_len = len(outer)
if (weight and (weight[(- 1)] <= len(partp))):
perms = permutation.Permutations((([0] * (len(partp) - weight[(- 1)])) + ([length] * weight[(- 1)]))).list()
else:
return function([], [], skp, weight, length)
selection = []
for j in range(len(perms)):
retire = [(((val + ell) - (i + 1)) - perms[j][i]) for (i, val) in enumerate(partp)]
retire.sort(reverse=True)
retire = [((val - ell) + (i + 1)) for (i, val) in enumerate(retire)]
if ((retire[(- 1)] >= 0) and (retire == sorted(retire, reverse=True))):
retire = Partition(retire).conjugate()
if (len(retire) >= outer_len):
append = True
for k in range(outer_len):
if ((retire[k] - outer[k]) < 0):
append = False
break
if append:
selection.append([retire, perms[j]])
if (len(weight) == 1):
return function([], selection, skp, weight, length)
else:
a = [graph_implementation_rec([p[0], outer], weight[:(- 1)], length, function) for p in selection]
return function(a, selection, skp, weight, length)
|
class MultiSkewTableau(CombinatorialElement):
'\n A multi skew tableau which is a tuple of skew tableaux.\n\n EXAMPLES::\n\n sage: s = MultiSkewTableau([ [[None,1],[2,3]], [[1,2],[2]] ])\n sage: s.size()\n 6\n sage: s.weight()\n [2, 3, 1]\n sage: s.shape()\n [[2, 2] / [1], [2, 1] / []]\n\n TESTS::\n\n sage: mst = MultiSkewTableau([ [[None,1],[2,3]], [[1,2],[2]] ])\n sage: TestSuite(mst).run()\n '
@staticmethod
def __classcall_private__(cls, x):
'\n Construct a multi skew tableau.\n\n EXAMPLES::\n\n sage: s = MultiSkewTableau([ [[None,1],[2,3]], [[1,2],[2]] ])\n '
if isinstance(x, MultiSkewTableau):
return x
return MultiSkewTableaux()([SkewTableau(i) for i in x])
def size(self):
'\n Return the size of ``self``.\n\n This is the sum of the sizes of the skew\n tableaux in ``self``.\n\n EXAMPLES::\n\n sage: s = SemistandardSkewTableaux([[2,2],[1]]).list()\n sage: a = MultiSkewTableau([s[0],s[1],s[2]])\n sage: a.size()\n 9\n '
return sum((x.size() for x in self))
def weight(self):
'\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: s = SemistandardSkewTableaux([[2,2],[1]]).list()\n sage: a = MultiSkewTableau([s[0],s[1],s[2]])\n sage: a.weight()\n [5, 3, 1]\n '
weights = [x.weight() for x in self]
m = max([len(x) for x in weights])
weight = ([0] * m)
for w in weights:
for i in range(len(w)):
weight[i] += w[i]
return weight
def shape(self):
'\n Return the shape of ``self``.\n\n EXAMPLES::\n\n sage: s = SemistandardSkewTableaux([[2,2],[1]]).list()\n sage: a = MultiSkewTableau([s[0],s[1],s[2]])\n sage: a.shape()\n [[2, 2] / [1], [2, 2] / [1], [2, 2] / [1]]\n '
return [x.shape() for x in self]
def inversion_pairs(self):
'\n Return a list of the inversion pairs of ``self``.\n\n EXAMPLES::\n\n sage: s = MultiSkewTableau([ [[2,3],[5,5]], [[1,1],[3,3]], [[2],[6]] ])\n sage: s.inversion_pairs()\n [((0, (0, 0)), (1, (0, 0))),\n ((0, (1, 0)), (1, (0, 1))),\n ((0, (1, 1)), (1, (0, 0))),\n ((0, (1, 1)), (1, (1, 1))),\n ((0, (1, 1)), (2, (0, 0))),\n ((1, (0, 1)), (2, (0, 0))),\n ((1, (1, 1)), (2, (0, 0)))]\n '
inv = []
for k in range(len(self)):
for b in self[k].cells():
inv += self._inversion_pairs_from_position(k, b)
return inv
def inversions(self):
'\n Return the number of inversion pairs of ``self``.\n\n EXAMPLES::\n\n sage: t1 = SkewTableau([[1]])\n sage: t2 = SkewTableau([[2]])\n sage: MultiSkewTableau([t1,t1]).inversions()\n 0\n sage: MultiSkewTableau([t1,t2]).inversions()\n 0\n sage: MultiSkewTableau([t2,t2]).inversions()\n 0\n sage: MultiSkewTableau([t2,t1]).inversions()\n 1\n sage: s = MultiSkewTableau([ [[2,3],[5,5]], [[1,1],[3,3]], [[2],[6]] ])\n sage: s.inversions()\n 7\n '
return len(self.inversion_pairs())
def _inversion_pairs_from_position(self, k, ij):
'\n Return the number of inversions at the cell position `(i,j)` in the\n ``k``-th tableaux in ``self``.\n\n EXAMPLES::\n\n sage: s = MultiSkewTableau([ [[2,3],[5,5]], [[1,1],[3,3]], [[2],[6]] ])\n sage: s._inversion_pairs_from_position(0, (1,1))\n [((0, (1, 1)), (1, (0, 0))),\n ((0, (1, 1)), (1, (1, 1))),\n ((0, (1, 1)), (2, (0, 0)))]\n sage: s._inversion_pairs_from_position(1, (0,1))\n [((1, (0, 1)), (2, (0, 0)))]\n '
pk = k
(pi, pj) = ij
c = (pi - pj)
value = self[pk][pi][pj]
pk_cells = self[pk].cells_by_content(c)
same_diagonal = [t.cells_by_content(c) for t in self[(pk + 1):]]
above_diagonal = [t.cells_by_content((c + 1)) for t in self[(pk + 1):]]
res = []
for (i, j) in pk_cells:
if ((pi < i) and (value > self[pk][i][j])):
res.append(((pk, (pi, pj)), (pk, (i, j))))
for k in range(len(same_diagonal)):
for (i, j) in same_diagonal[k]:
if (value > self[((pk + k) + 1)][i][j]):
res.append(((pk, (pi, pj)), (((pk + k) + 1), (i, j))))
for k in range(len(above_diagonal)):
for (i, j) in above_diagonal[k]:
if (value < self[((pk + k) + 1)][i][j]):
res.append(((pk, (pi, pj)), (((pk + k) + 1), (i, j))))
return res
|
class MultiSkewTableaux(UniqueRepresentation, Parent):
'\n Multiskew tableaux.\n '
def __init__(self, category=None):
'\n EXAMPLES::\n\n sage: R = MultiSkewTableaux()\n sage: TestSuite(R).run()\n '
if (category is None):
category = Sets()
Parent.__init__(self, category=category)
def _repr_(self):
'\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: MultiSkewTableaux()\n Multi Skew Tableaux tableaux\n '
return 'Multi Skew Tableaux tableaux'
def _element_constructor_(self, rt):
'\n Construct an element of ``self`` from ``rt``.\n\n EXAMPLES::\n\n sage: R = MultiSkewTableaux()\n sage: R([[[1, 1], [2]], [[None, 2], [3, 3]]])\n [[[1, 1], [2]], [[None, 2], [3, 3]]]\n '
return self.element_class(self, rt)
Element = MultiSkewTableau
|
class SemistandardMultiSkewTableaux(MultiSkewTableaux):
'\n Semistandard multi skew tableaux.\n\n A multi skew tableau is a `k`-tuple of skew tableaux of\n given shape with a specified total weight.\n\n EXAMPLES::\n\n sage: S = SemistandardMultiSkewTableaux([ [[2,1],[]], [[2,2],[1]] ], [2,2,2]); S\n Semistandard multi skew tableaux of shape [[2, 1] / [], [2, 2] / [1]] and weight [2, 2, 2]\n sage: S.list()\n [[[[1, 1], [2]], [[None, 2], [3, 3]]],\n [[[1, 2], [2]], [[None, 1], [3, 3]]],\n [[[1, 3], [2]], [[None, 2], [1, 3]]],\n [[[1, 3], [2]], [[None, 1], [2, 3]]],\n [[[1, 1], [3]], [[None, 2], [2, 3]]],\n [[[1, 2], [3]], [[None, 2], [1, 3]]],\n [[[1, 2], [3]], [[None, 1], [2, 3]]],\n [[[2, 2], [3]], [[None, 1], [1, 3]]],\n [[[1, 3], [3]], [[None, 1], [2, 2]]],\n [[[2, 3], [3]], [[None, 1], [1, 2]]]]\n '
@staticmethod
def __classcall_private__(cls, shape, weight):
'\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: S1 = SemistandardMultiSkewTableaux([ [[2,1],[]], [[2,2],[1]] ], [2,2,2])\n sage: shape_alt = ( SkewPartition([[2,1],[]]), SkewPartition([[2,2],[1]]) )\n sage: S2 = SemistandardMultiSkewTableaux(shape_alt, (2,2,2))\n sage: S1 is S2\n True\n '
shape = tuple((SkewPartition(x) for x in shape))
weight = Partition(weight)
if (sum(weight) != sum((s.size() for s in shape))):
raise ValueError('the sum of weight must be the sum of the sizes of shape')
return super().__classcall__(cls, shape, weight)
def __init__(self, shape, weight):
'\n TESTS::\n\n sage: S = SemistandardMultiSkewTableaux([ [[2,1],[]], [[2,2],[1]] ], [2,2,2])\n sage: TestSuite(S).run()\n '
self._shape = shape
self._weight = weight
MultiSkewTableaux.__init__(self, category=FiniteEnumeratedSets())
def _repr_(self):
'\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: SemistandardMultiSkewTableaux([ [[2,1],[]], [[2,2],[1]] ], [2,2,2])\n Semistandard multi skew tableaux of shape [[2, 1] / [], [2, 2] / [1]] and weight [2, 2, 2]\n '
return ('Semistandard multi skew tableaux of shape %s and weight %s' % (list(self._shape), self._weight))
def __contains__(self, x):
'\n TESTS::\n\n sage: s = SemistandardMultiSkewTableaux([ [[2,1],[]], [[2,2],[1]] ], [2,2,2])\n sage: all(i in s for i in s)\n True\n '
try:
x = MultiSkewTableau(x)
except TypeError:
return False
if (x.weight() != list(self._weight)):
return False
if (x.shape() != list(self._shape)):
return False
return all((xi.is_semistandard() for xi in x))
def __iter__(self):
'\n Iterate over ``self``.\n\n EXAMPLES::\n\n sage: sp = SkewPartitions(3).list()\n sage: SemistandardMultiSkewTableaux([SkewPartition([[1, 1, 1], []]), SkewPartition([[3], []])],[2,2,2]).list()\n [[[[1], [2], [3]], [[1, 2, 3]]]]\n\n sage: a = SkewPartition([[8,7,6,5,1,1],[2,1,1]])\n sage: weight = [3,3,2]\n sage: k = 3\n sage: s = SemistandardMultiSkewTableaux(a.quotient(k),weight)\n sage: len(s.list())\n 34\n sage: RibbonTableaux(a,weight,k).cardinality()\n 34\n\n TESTS:\n\n Check that :issue:`36196` is fixed::\n\n sage: shapes = [[[1], [0]], [[1], [0]], [[1], [0]]]\n sage: weight = [1, 1, 1]\n sage: SMST = SemistandardMultiSkewTableaux(shapes, weight)\n sage: list(SMST)\n [[[[1]], [[2]], [[3]]],\n [[[2]], [[1]], [[3]]],\n [[[1]], [[3]], [[2]]],\n [[[2]], [[3]], [[1]]],\n [[[3]], [[1]], [[2]]],\n [[[3]], [[2]], [[1]]]]\n '
parts = self._shape
mu = self._weight
s = [p.size() for p in parts]
parts = [p.to_list() for p in parts]
parttmp = parts[0]
for i in range(1, len(parts)):
trans = parttmp[0][0]
current_part = parts[i]
current_part[1] += ([0] * (len(current_part[0]) - len(current_part[1])))
inner_current = [(trans + j) for j in current_part[1]]
outer_current = [(trans + j) for j in current_part[0]]
parttmp = [(outer_current + parttmp[0]), (inner_current + parttmp[1])]
l = (st.to_word() for st in SemistandardSkewTableaux(parttmp, mu))
S = SkewTableaux()
for lk in l:
pos = 0
lk = list(lk)
w = lk[:s[0]]
restmp = [S.from_shape_and_word(parts[0], w)]
for i in range(1, len(parts)):
pos += s[(i - 1)]
w = lk[pos:(pos + s[i])]
restmp.append(S.from_shape_and_word(parts[i], w))
(yield self.element_class(self, restmp))
|
class RibbonTableau_class(RibbonTableau):
'\n This exists solely for unpickling ``RibbonTableau_class`` objects.\n '
def __setstate__(self, state):
'\n Unpickle old ``RibbonTableau_class`` objects.\n\n TESTS::\n\n sage: loads(b\'x\\x9c5\\xcc\\xbd\\x0e\\xc2 \\x14@\\xe1\\xb4Z\\x7f\\xd0\\x07\\xc1\\x85D}\\x8f\\x0e\\x8d\\x1d\\t\\xb9\\x90\\x1bJ\\xa44\\x17\\xe8h\\xa2\\x83\\xef-\\xda\\xb8\\x9do9\\xcf\\xda$\\xb0(\\xcc4j\\x17 \\x8b\\xe8\\xb4\\x9e\\x82\\xca\\xa0=\\xc2\\xcc\\xba\\x1fo\\x8b\\x94\\xf1\\x90\\x12\\xa3\\xea\\xf4\\xa2\\xfaA+\\xde7j\\x804\\xd0\\xba-\\xe5]\\xca\\xd4H\\xdapI[\\xde.\\xdf\\xe8\\x82M\\xc2\\x85\\x8c\\x16#\\x1b\\xe1\\x8e\\xea\\x0f\\xda\\xf5\\xd5\\xf9\\xdd\\xd1\\x1e%1>\\x14]\\x8a\\x0e\\xdf\\xb8\\x968"\\xceZ|\\x00x\\xef5\\x11\')\n [[None, 1], [2, 3]]\n sage: loads(dumps( RibbonTableau([[None, 1],[2,3]]) ))\n [[None, 1], [2, 3]]\n '
self.__class__ = RibbonTableau
self.__init__(RibbonTableaux(), state['_list'])
|
class KRTToRCBijectionAbstract():
'\n Root abstract class for the bijection from KR tableaux to rigged configurations.\n\n This class holds the state of the bijection and generates the next state.\n This class should never be created directly.\n '
def __init__(self, tp_krt):
"\n Initialize the bijection by obtaining the important information from\n the KR tableaux.\n\n INPUT:\n\n - ``parent`` -- The parent of tensor product of KR tableaux\n\n EXAMPLES::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import KRTToRCBijectionTypeA\n sage: bijection = KRTToRCBijectionTypeA(KRT(pathlist=[[3,1]]))\n sage: TestSuite(bijection).run()\n "
self.tp_krt = tp_krt
self.n = tp_krt.parent().cartan_type().classical().rank()
self.ret_rig_con = tp_krt.parent().rigged_configurations()(partition_list=([[]] * self.n))
self.ret_rig_con._set_mutable()
self.cur_dims = []
self.cur_path = []
def __eq__(self, rhs):
"\n Check equality.\n\n This is only here for pickling check. This is a temporary placeholder\n class, and as such, should never be compared.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import KRTToRCBijectionTypeA\n sage: bijection = KRTToRCBijectionTypeA(KRT(pathlist=[[5,3]]))\n sage: bijection2 = KRTToRCBijectionTypeA(KRT(pathlist=[[5,3]]))\n sage: bijection == bijection2\n True\n "
return isinstance(rhs, KRTToRCBijectionAbstract)
def run(self, verbose=False):
"\n Run the bijection from a tensor product of KR tableaux to a rigged\n configuration.\n\n INPUT:\n\n - ``tp_krt`` -- A tensor product of KR tableaux\n\n - ``verbose`` -- (Default: ``False``) Display each step in the\n bijection\n\n EXAMPLES::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import KRTToRCBijectionTypeA\n sage: KRTToRCBijectionTypeA(KRT(pathlist=[[5,2]])).run()\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 1[ ]1\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n "
if verbose:
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux_element import TensorProductOfKirillovReshetikhinTableauxElement
for cur_crystal in reversed(self.tp_krt):
target = cur_crystal.parent()._r
for (col_number, cur_column) in enumerate(reversed(cur_crystal.to_array(False))):
self.cur_path.insert(0, [])
self.cur_dims.insert(0, [0, 1])
for letter in reversed(cur_column):
self.cur_dims[0][0] = self._next_index(self.cur_dims[0][0], target)
val = letter.value
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
self.cur_path[0].insert(0, [letter])
self.next_state(val)
if (col_number > 0):
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
print('Applying column merge')
for (i, letter_singleton) in enumerate(self.cur_path[0]):
self.cur_path[1][i].insert(0, letter_singleton[0])
self.cur_dims[1][1] += 1
self.cur_path.pop(0)
self.cur_dims.pop(0)
for a in range(self.n):
self._update_vacancy_nums(a)
self.ret_rig_con.set_immutable()
return self.ret_rig_con
@abstract_method
def next_state(self, val):
"\n Build the next state in the bijection.\n\n INPUT:\n\n - ``val`` -- The value we are adding\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import KRTToRCBijectionTypeA\n sage: bijection = KRTToRCBijectionTypeA(KRT(pathlist=[[5,3]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [3])\n sage: bijection.next_state(3)\n sage: bijection.ret_rig_con\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n "
def _update_vacancy_nums(self, a):
"\n Update the vacancy numbers of a rigged partition.\n\n Helper function to (batch) update the vacancy numbers of the rigged\n partition at position `a` in the rigged configuration stored by this\n bijection.\n\n INPUT:\n\n - ``a`` -- The index of the partition to update\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_abstract_class import KRTToRCBijectionAbstract\n sage: bijection = KRTToRCBijectionAbstract(KRT(pathlist=[[3,2]]))\n sage: bijection._update_vacancy_nums(2)\n "
if (not self.ret_rig_con[a]):
return
block_len = self.ret_rig_con[a][0]
nu = self.ret_rig_con.nu()
vac_num = self.ret_rig_con.parent()._calc_vacancy_number(nu, a, nu[a][0], dims=self.cur_dims)
for (i, row_len) in enumerate(self.ret_rig_con[a]):
if (block_len != row_len):
vac_num = self.ret_rig_con.parent()._calc_vacancy_number(nu, a, row_len, dims=self.cur_dims)
block_len = row_len
self.ret_rig_con[a].vacancy_numbers[i] = vac_num
def _update_partition_values(self, a):
"\n Update the partition values of a rigged partition.\n\n Helper function to update the partition values of a given rigged\n partition row. This will go through all of our partition values and set\n them to our vacancy number if the corresponding row has been changed\n (indicated by being set to ``None``).\n\n INPUT:\n\n - ``a`` -- The index of the partition to update\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_abstract_class import KRTToRCBijectionAbstract\n sage: bijection = KRTToRCBijectionAbstract(KRT(pathlist=[[5,2]]))\n sage: bijection._update_partition_values(2)\n "
rigged_partition = self.ret_rig_con[a]
for (index, value) in enumerate(rigged_partition.rigging):
if (value is None):
rigged_partition.rigging[index] = rigged_partition.vacancy_numbers[index]
if ((index > 0) and (rigged_partition[(index - 1)] == rigged_partition[index]) and (rigged_partition.rigging[(index - 1)] < rigged_partition.rigging[index])):
pos = 0
width = rigged_partition[index]
val = rigged_partition.rigging[index]
for i in reversed(range((index - 1))):
if ((rigged_partition[i] > width) or (rigged_partition.rigging[i] >= val)):
pos = (i + 1)
break
rigged_partition.rigging.pop(index)
rigged_partition.rigging.insert(pos, val)
def _next_index(self, r, target):
"\n Return the next index after ``r`` when performing a step\n in the bijection going towards ``target``.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_abstract_class import KRTToRCBijectionAbstract\n sage: bijection = KRTToRCBijectionAbstract(KRT(pathlist=[[5,2]]))\n sage: bijection._next_index(1, 2)\n 2\n "
return (r + 1)
|
class RCToKRTBijectionAbstract():
'\n Root abstract class for the bijection from rigged configurations to\n tensor product of Kirillov-Reshetikhin tableaux.\n\n This class holds the state of the bijection and generates the next state.\n This class should never be created directly.\n '
def __init__(self, RC_element):
"\n Initialize the bijection helper.\n\n INPUT:\n\n - ``RC_element`` -- The rigged configuration\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_abstract_class import RCToKRTBijectionAbstract\n sage: bijection = RCToKRTBijectionAbstract(RC(partition_list=[[1],[1],[1],[1]]))\n sage: TestSuite(bijection).run()\n "
self.rigged_con = RC_element.__copy__()
self.n = RC_element.parent().cartan_type().classical().rank()
self.KRT = RC_element.parent().tensor_product_of_kirillov_reshetikhin_tableaux()
self.cur_dims = [list(x[:]) for x in self.rigged_con.parent().dims]
self.cur_partitions = deepcopy(list(self.rigged_con)[:])
cp = RC_element.__copy__()
cp.set_immutable()
self._graph = [[[], (cp, 0)]]
def __eq__(self, rhs):
"\n Check equality.\n\n This is only here for pickling check. This is a temporary placeholder\n class, and as such, should never be compared.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import RCToKRTBijectionTypeA\n sage: bijection = RCToKRTBijectionTypeA(RC(partition_list=[[1],[1],[1],[1]]))\n sage: bijection2 = RCToKRTBijectionTypeA(RC(partition_list=[[1],[1],[1],[1]]))\n sage: bijection == bijection2\n True\n "
return isinstance(rhs, RCToKRTBijectionAbstract)
def run(self, verbose=False, build_graph=False):
"\n Run the bijection from rigged configurations to tensor product of KR\n tableaux.\n\n INPUT:\n\n - ``verbose`` -- (default: ``False``) display each step in the\n bijection\n - ``build_graph`` -- (default: ``False``) build the graph of each\n step of the bijection\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: x = RC(partition_list=[[1],[1],[1],[1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import RCToKRTBijectionTypeA\n sage: RCToKRTBijectionTypeA(x).run()\n [[2], [5]]\n sage: bij = RCToKRTBijectionTypeA(x)\n sage: bij.run(build_graph=True)\n [[2], [5]]\n sage: bij._graph\n Digraph on 3 vertices\n "
from sage.combinat.crystals.letters import CrystalOfLetters
letters = CrystalOfLetters(self.rigged_con.parent()._cartan_type.classical())
ret_crystal_path = []
for dim in self.rigged_con.parent().dims:
ret_crystal_path.append([])
for dummy_var in range(dim[1]):
if (self.cur_dims[0][1] > 1):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying column split')
self.cur_dims[0][1] -= 1
self.cur_dims.insert(0, [dim[0], 1])
for a in range(self.n):
self._update_vacancy_numbers(a)
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), 'ls'])
while self.cur_dims[0][0]:
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
ht = self.cur_dims[0][0]
self.cur_dims[0][0] = self._next_index(ht)
b = self.next_state(ht)
ret_crystal_path[(- 1)].append(letters(b))
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), letters(b)])
self.cur_dims.pop(0)
if build_graph:
self._graph.pop(0)
from sage.graphs.digraph import DiGraph
from sage.graphs.dot2tex_utils import have_dot2tex
self._graph = DiGraph(self._graph, format='list_of_edges')
if have_dot2tex():
self._graph.set_latex_options(format='dot2tex', edge_labels=True)
return self.KRT(pathlist=ret_crystal_path)
@abstract_method
def next_state(self, height):
"\n Build the next state in the bijection.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import RCToKRTBijectionTypeA\n sage: bijection = RCToKRTBijectionTypeA(RC(partition_list=[[1],[1],[1],[1]]))\n sage: bijection.next_state(1)\n 5\n sage: bijection.cur_partitions\n [(/)\n , (/)\n , (/)\n , (/)\n ]\n "
def _update_vacancy_numbers(self, a):
"\n Update the vacancy numbers during the bijection.\n\n INPUT:\n\n - ``a`` -- The index of the partition to update\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_abstract_class import RCToKRTBijectionAbstract\n sage: bijection = RCToKRTBijectionAbstract(RC(partition_list=[[1],[1],[1],[1]]))\n sage: bijection._update_vacancy_numbers(2)\n "
if (not self.cur_partitions[a]):
return
partition = self.cur_partitions[a]
block_len = partition[0]
vac_num = self.rigged_con.parent()._calc_vacancy_number(self.cur_partitions, a, partition[0], dims=self.cur_dims)
for (i, row_len) in enumerate(self.cur_partitions[a]):
if (block_len != row_len):
vac_num = self.rigged_con.parent()._calc_vacancy_number(self.cur_partitions, a, row_len, dims=self.cur_dims)
block_len = row_len
partition.vacancy_numbers[i] = vac_num
def _find_singular_string(self, partition, last_size):
"\n Return the index of the singular string or ``None`` if not found.\n\n Helper method to find a singular string at least as long as\n ``last_size``.\n\n INPUT:\n\n - ``partition`` -- The partition to look in\n\n - ``last_size`` -- The last size found\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_abstract_class import RCToKRTBijectionAbstract\n sage: bijection = RCToKRTBijectionAbstract(RC(partition_list=[[1],[1],[1],[1]]))\n sage: bijection._find_singular_string(bijection.cur_partitions[2], 2)\n sage: bijection._find_singular_string(bijection.cur_partitions[2], 0)\n 0\n "
for i in reversed(range(len(partition))):
if ((partition[i] >= last_size) and (partition.vacancy_numbers[i] == partition.rigging[i])):
return i
def _next_index(self, r):
"\n Return the next index after ``r`` when performing a step\n in the bijection.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_abstract_class import RCToKRTBijectionAbstract\n sage: bijection = RCToKRTBijectionAbstract(RC(partition_list=[[1],[1],[1],[1]]))\n sage: bijection._next_index(2)\n 1\n "
return (r - 1)
|
class FromTableauIsomorphism(Morphism):
'\n Crystal isomorphism of `B(\\infty)` in the tableau model to the\n rigged configuration model.\n '
def _repr_type(self):
"\n Return the type of morphism of ``self``.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A',3])\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: phi = RC.coerce_map_from(T)\n sage: phi._repr_type()\n 'Crystal Isomorphism'\n "
return 'Crystal Isomorphism'
def __invert__(self):
"\n Return the inverse of ``self``.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A',3])\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: phi = RC.coerce_map_from(T)\n sage: ~phi\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 "
return FromRCIsomorphism(Hom(self.codomain(), self.domain()))
def _call_(self, x):
"\n Return the image of ``x`` in the rigged configuration model\n of `B(\\infty)`.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A',3])\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: phi = RC.coerce_map_from(T)\n sage: x = T.an_element().f_string([2,2,1,1,3,2,1,2,1,3])\n sage: y = phi(x); ascii_art(y)\n -4[ ][ ][ ][ ]-2 -3[ ][ ][ ]-1 -1[ ][ ]-1\n -2[ ]-1\n sage: (~phi)(y) == x\n True\n "
conj = x.to_tableau().conjugate()
ct = self.domain().cartan_type()
act = ct.affine()
TP = TensorProductOfKirillovReshetikhinTableaux(act, [[r, 1] for r in conj.shape()])
elt = TP(pathlist=[reversed(row) for row in conj])
if (ct.type() == 'A'):
bij = KRTToRCBijectionTypeA(elt)
elif (ct.type() == 'B'):
bij = MLTToRCBijectionTypeB(elt)
elif (ct.type() == 'C'):
bij = KRTToRCBijectionTypeC(elt)
elif (ct.type() == 'D'):
bij = MLTToRCBijectionTypeD(elt)
else:
raise NotImplementedError('bijection of type {} not yet implemented'.format(ct))
return self.codomain()(bij.run())
|
class FromRCIsomorphism(Morphism):
'\n Crystal isomorphism of `B(\\infty)` in the rigged configuration model\n to the tableau model.\n '
def _repr_type(self):
"\n Return the type of morphism of ``self``.\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: RC = crystals.infinity.RiggedConfigurations(['A',3])\n sage: phi = T.coerce_map_from(RC)\n sage: phi._repr_type()\n 'Crystal Isomorphism'\n "
return 'Crystal Isomorphism'
def __invert__(self):
"\n Return the inverse of ``self``.\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: RC = crystals.infinity.RiggedConfigurations(['A',3])\n sage: phi = T.coerce_map_from(RC)\n sage: ~phi\n Crystal Isomorphism morphism:\n From: The infinity crystal of tableaux of type ['A', 3]\n To: The infinity crystal of rigged configurations of type ['A', 3]\n "
return FromTableauIsomorphism(Hom(self.codomain(), self.domain()))
def _call_(self, x):
"\n Return the image of ``x`` in the tableau model of `B(\\infty)`.\n\n EXAMPLES::\n\n sage: T = crystals.infinity.Tableaux(['A',3])\n sage: RC = crystals.infinity.RiggedConfigurations(['A',3])\n sage: phi = T.coerce_map_from(RC)\n sage: x = RC.an_element().f_string([2,2,1,1,3,2,1,2,1,3])\n sage: y = phi(x); y.pp()\n 1 1 1 1 1 2 2 3 4\n 2 2 3 4\n 3\n sage: (~phi)(y) == x\n True\n "
lam = [(sum(nu) + 1) for nu in x]
ct = self.domain().cartan_type()
I = ct.index_set()
if (ct.type() == 'D'):
lam[(- 2)] = max(lam[(- 2)], lam[(- 1)])
lam.pop()
l = sum([([[(r + 1), 1]] * v) for (r, v) in enumerate(lam[:(- 1)])], [])
n = len(I)
l = (l + sum([[[n, 1], [(n - 1), 1]] for k in range(lam[(- 1)])], []))
else:
if (ct.type() == 'B'):
lam[(- 1)] *= 2
l = sum([([[r, 1]] * lam[i]) for (i, r) in enumerate(I)], [])
RC = RiggedConfigurations(ct.affine(), reversed(l))
elt = RC(x)
if (ct.type() == 'A'):
bij = RCToKRTBijectionTypeA(elt)
elif (ct.type() == 'B'):
bij = RCToMLTBijectionTypeB(elt)
elif (ct.type() == 'C'):
bij = RCToKRTBijectionTypeC(elt)
elif (ct.type() == 'D'):
bij = RCToMLTBijectionTypeD(elt)
else:
raise NotImplementedError('bijection of type {} not yet implemented'.format(ct))
y = bij.run()
y = [list(c) for c in y]
cur = []
L = CrystalOfLetters(ct)
for i in I:
cur.insert(0, L(i))
c = y.count(cur)
while (c > 1):
y.remove(cur)
c -= 1
return self.codomain()(*flatten(y))
|
class MLTToRCBijectionTypeB(KRTToRCBijectionTypeB):
def run(self):
"\n Run the bijection from a marginally large tableaux to a rigged\n configuration.\n\n EXAMPLES::\n\n sage: vct = CartanType(['B',4]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: T = crystals.infinity.Tableaux(['B',4])\n sage: Psi = T.crystal_morphism({T.module_generators[0]: RC.module_generators[0]})\n sage: TS = [x.value for x in T.subcrystal(max_depth=4)]\n sage: all(Psi(b) == RC(b) for b in TS) # long time # indirect doctest\n True\n "
for cur_crystal in reversed(self.tp_krt):
cur_column = list(cur_crystal)
self.cur_path.insert(0, [])
self.cur_dims.insert(0, [0, 1])
for letter in reversed(cur_column):
self.cur_dims[0][0] += 1
val = letter.value
self.cur_path[0].insert(0, [letter])
if (self.cur_dims[0][0] == self.n):
self.cur_dims.insert(1, [self.n, 1])
self.cur_path.insert(1, self.cur_path[0])
self.next_state(val)
self.ret_rig_con.set_immutable()
return self.ret_rig_con
|
class RCToMLTBijectionTypeB(RCToKRTBijectionTypeB):
def run(self):
"\n Run the bijection from rigged configurations to a marginally large\n tableau.\n\n EXAMPLES::\n\n sage: vct = CartanType(['B',4]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: T = crystals.infinity.Tableaux(['B',4])\n sage: Psi = RC.crystal_morphism({RC.module_generators[0]: T.module_generators[0]})\n sage: RCS = [x.value for x in RC.subcrystal(max_depth=4)]\n sage: all(Psi(nu) == T(nu) for nu in RCS) # long time # indirect doctest\n True\n "
letters = CrystalOfLetters(self.rigged_con.parent()._cartan_type.classical())
ret_crystal_path = []
while self.cur_dims:
dim = self.cur_dims[0]
ret_crystal_path.append([])
if (dim[0] == self.n):
self.cur_dims.pop(1)
while (dim[0] > 0):
dim[0] -= 1
b = self.next_state(dim[0])
ret_crystal_path[(- 1)].append(letters(b))
self.cur_dims.pop(0)
return ret_crystal_path
|
class MLTToRCBijectionTypeD(KRTToRCBijectionTypeD):
def run(self):
"\n Run the bijection from a marginally large tableaux to a rigged\n configuration.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['D',4])\n sage: T = crystals.infinity.Tableaux(['D',4])\n sage: Psi = T.crystal_morphism({T.module_generators[0]: RC.module_generators[0]})\n sage: TS = [x.value for x in T.subcrystal(max_depth=4)]\n sage: all(Psi(b) == RC(b) for b in TS) # long time # indirect doctest\n True\n "
for cur_crystal in reversed(self.tp_krt):
cur_column = list(cur_crystal)
self.cur_path.insert(0, [])
self.cur_dims.insert(0, [0, 1])
for letter in reversed(cur_column):
self.cur_dims[0][0] += 1
val = letter.value
self.cur_path[0].insert(0, [letter])
self.next_state(val)
if (self.cur_dims[0][0] == (self.n - 1)):
self.cur_dims.insert(1, [self.n, 1])
self.cur_path.insert(1, (self.cur_path[0] + [None]))
self.ret_rig_con.set_immutable()
return self.ret_rig_con
|
class RCToMLTBijectionTypeD(RCToKRTBijectionTypeD):
def run(self):
"\n Run the bijection from rigged configurations to a marginally large\n tableau.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['D',4])\n sage: T = crystals.infinity.Tableaux(['D',4])\n sage: Psi = RC.crystal_morphism({RC.module_generators[0]: T.module_generators[0]})\n sage: RCS = [x.value for x in RC.subcrystal(max_depth=4)]\n sage: all(Psi(nu) == T(nu) for nu in RCS) # long time # indirect doctest\n True\n "
letters = CrystalOfLetters(self.rigged_con.parent()._cartan_type.classical())
ret_crystal_path = []
while self.cur_dims:
dim = self.cur_dims[0]
ret_crystal_path.append([])
if (dim[0] == (self.n - 1)):
self.cur_dims.pop(1)
while (dim[0] > 0):
dim[0] -= 1
b = self.next_state(dim[0])
ret_crystal_path[(- 1)].append(letters(b))
self.cur_dims.pop(0)
return ret_crystal_path
|
class KRTToRCBijectionTypeA(KRTToRCBijectionAbstract):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `A_n^{(1)}`.\n '
def next_state(self, val):
"\n Build the next state for type `A_n^{(1)}`.\n\n EXAMPLES::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import KRTToRCBijectionTypeA\n sage: bijection = KRTToRCBijectionTypeA(KRT(pathlist=[[4,3]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [3])\n sage: bijection.next_state(3)\n "
tableau_height = (len(self.cur_path[0]) - 1)
n = self.n
if ((val - 1) > tableau_height):
if (len(self.ret_rig_con[(val - 2)]) > 0):
max_width = self.ret_rig_con[(val - 2)][0]
else:
max_width = 1
max_width = self.ret_rig_con[(val - 2)].insert_cell(max_width)
for a in reversed(range(tableau_height, (val - 2))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if ((val - 1) < n):
self._update_vacancy_nums((val - 1))
if (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
elif ((tableau_height - 1) < n):
if (tableau_height < n):
self._update_vacancy_nums(tableau_height)
if (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
|
class RCToKRTBijectionTypeA(RCToKRTBijectionAbstract):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `A_n^{(1)}`.\n '
def next_state(self, height):
"\n Build the next state for type `A_n^{(1)}`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A import RCToKRTBijectionTypeA\n sage: bijection = RCToKRTBijectionTypeA(RC(partition_list=[[1],[1],[1],[1]]))\n sage: bijection.next_state(1)\n 5\n "
height -= 1
n = self.n
ell = ([None] * n)
b = None
last_size = 0
a = height
for partition in self.cur_partitions[height:]:
ell[a] = self._find_singular_string(partition, last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = partition[ell[a]]
a += 1
if (b is None):
b = (n + 1)
row_num = self.cur_partitions[0].remove_cell(ell[0])
for a in range(1, n):
row_num_next = self.cur_partitions[a].remove_cell(ell[a])
self._update_vacancy_numbers((a - 1))
if (row_num is not None):
self.cur_partitions[(a - 1)].rigging[row_num] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num]
row_num = row_num_next
self._update_vacancy_numbers((n - 1))
if (row_num is not None):
self.cur_partitions[(n - 1)].rigging[row_num] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num]
return b
|
class KRTToRCBijectionTypeA2Dual(KRTToRCBijectionTypeC):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `A_{2n}^{(2)\\dagger}`.\n\n This inherits from type `C_n^{(1)}` because we use the same methods in\n some places.\n '
def next_state(self, val):
"\n Build the next state for type `A_{2n}^{(2)\\dagger}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(CartanType(['A', 4, 2]).dual(), [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A2_dual import KRTToRCBijectionTypeA2Dual\n sage: bijection = KRTToRCBijectionTypeA2Dual(KRT(pathlist=[[-1,2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [2])\n sage: bijection.next_state(2)\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
if (val > 0):
KRTToRCBijectionTypeA.next_state(self, val)
return
pos_val = (- val)
if (pos_val == 0):
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(n - 1)][0]
else:
max_width = 1
max_width = self.ret_rig_con[(n - 1)].insert_cell(max_width)
width_n = (max_width + 1)
for a in reversed(range(tableau_height, (n - 1))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
p = self.ret_rig_con[(n - 1)]
for i in range(len(p)):
if (p._list[i] == width_n):
p.rigging[i] = (p.rigging[i] - (QQ(1) / QQ(2)))
break
return
case_S = ([None] * n)
pos_val = (- val)
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(pos_val - 1)][0]
else:
max_width = 1
for a in range((pos_val - 1), (n - 1)):
max_width = self.ret_rig_con[a].insert_cell(max_width)
case_S[a] = max_width
partition = self.ret_rig_con[(n - 1)]
num_rows = len(partition)
case_QS = False
for i in range((num_rows + 1)):
if (i == num_rows):
max_width = 0
if case_QS:
partition._list.append(1)
partition.vacancy_numbers.append(None)
j = (len(partition._list) - 1)
while ((j >= 0) and (partition._list[j] == 1)):
j -= 1
partition.rigging.insert((j + 1), None)
width_n = 1
else:
j = (len(partition._list) - 1)
while ((j >= 0) and (partition._list[j] <= 2)):
j -= 1
partition._list.insert((j + 1), 2)
partition.vacancy_numbers.insert((j + 1), None)
partition.rigging.insert((j + 1), None)
break
elif (partition._list[i] <= max_width):
if (partition.vacancy_numbers[i] == partition.rigging[i]):
max_width = partition._list[i]
if case_QS:
partition._list[i] += 1
width_n = partition._list[i]
partition.rigging[i] = None
else:
j = (i - 1)
while ((j >= 0) and (partition._list[j] <= (max_width + 2))):
partition.rigging[(j + 1)] = partition.rigging[j]
j -= 1
partition._list.pop(i)
partition._list.insert((j + 1), (max_width + 2))
partition.rigging[(j + 1)] = None
break
elif (((partition.vacancy_numbers[i] - (QQ(1) / QQ(2))) == partition.rigging[i]) and (not case_QS)):
case_QS = True
partition._list[i] += 1
partition.rigging[i] = None
for a in reversed(range(tableau_height, (n - 1))):
if (case_S[a] == max_width):
self._insert_cell_case_S(self.ret_rig_con[a])
else:
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
if (tableau_height < n):
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
if case_QS:
num_rows = len(partition)
for i in range(num_rows):
if (partition._list[i] == width_n):
partition.rigging[i] = (partition.rigging[i] - (QQ(1) / QQ(2)))
break
|
class RCToKRTBijectionTypeA2Dual(RCToKRTBijectionTypeC):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `A_{2n}^{(2)\\dagger}`.\n '
def next_state(self, height):
"\n Build the next state for type `A_{2n}^{(2)\\dagger}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(CartanType(['A', 4, 2]).dual(), [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A2_dual import RCToKRTBijectionTypeA2Dual\n sage: bijection = RCToKRTBijectionTypeA2Dual(RC(partition_list=[[2],[2,2]]))\n sage: bijection.next_state(2)\n -1\n "
height -= 1
n = self.n
ell = ([None] * (2 * n))
case_S = ([False] * n)
case_Q = False
b = None
last_size = 0
for a in range(height, (n - 1)):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if (b is None):
partition = self.cur_partitions[(n - 1)]
for i in reversed(range(len(partition))):
if (partition[i] >= last_size):
if (partition.vacancy_numbers[i] == partition.rigging[i]):
last_size = partition[i]
case_S[(n - 1)] = True
ell[((2 * n) - 1)] = i
break
elif (((partition.vacancy_numbers[i] - (QQ(1) / QQ(2))) == partition.rigging[i]) and (not case_Q)):
case_Q = True
last_size = (partition[i] + 1)
ell[(n - 1)] = i
if (ell[((2 * n) - 1)] is None):
if (not case_Q):
b = n
else:
b = 0
if (b is None):
for a in reversed(range((n - 1))):
if ((a >= height) and (self.cur_partitions[a][ell[a]] == last_size)):
ell[(n + a)] = ell[a]
case_S[a] = True
else:
ell[(n + a)] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[(n + a)] is None):
b = (- (a + 2))
break
else:
last_size = self.cur_partitions[a][ell[(n + a)]]
if (b is None):
b = (- 1)
if (n > 1):
if case_S[0]:
row_num = None
row_num_bar = self.cur_partitions[0].remove_cell(ell[n], 2)
else:
row_num = self.cur_partitions[0].remove_cell(ell[0])
row_num_bar = self.cur_partitions[0].remove_cell(ell[n])
for a in range(1, (n - 1)):
if case_S[a]:
row_num_next = None
row_num_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)], 2)
else:
row_num_next = self.cur_partitions[a].remove_cell(ell[a])
row_num_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)])
self._update_vacancy_numbers((a - 1))
if (row_num is not None):
self.cur_partitions[(a - 1)].rigging[row_num] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(a - 1)].rigging[row_num_bar] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num_bar]
row_num = row_num_next
row_num_bar = row_num_bar_next
if case_Q:
row_num_next = self.cur_partitions[(n - 1)].remove_cell(ell[(n - 1)])
if case_S[(n - 1)]:
row_num_bar_next = self.cur_partitions[(n - 1)].remove_cell(ell[((2 * n) - 1)])
else:
row_num_bar_next = None
elif case_S[(n - 1)]:
row_num_next = None
row_num_bar_next = self.cur_partitions[(n - 1)].remove_cell(ell[((2 * n) - 1)], 2)
else:
row_num_next = None
row_num_bar_next = None
if (n > 1):
self._update_vacancy_numbers((n - 2))
if (row_num is not None):
self.cur_partitions[(n - 2)].rigging[row_num] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(n - 2)].rigging[row_num_bar] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num_bar]
self._update_vacancy_numbers((n - 1))
if (row_num_next is not None):
self.cur_partitions[(n - 1)].rigging[row_num_next] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_next]
if (row_num_bar_next is not None):
if case_Q:
self.cur_partitions[(n - 1)].rigging[row_num_bar_next] = (self.cur_partitions[(n - 1)].vacancy_numbers[row_num_bar_next] - (QQ(1) / QQ(2)))
else:
self.cur_partitions[(n - 1)].rigging[row_num_bar_next] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_bar_next]
return b
|
class KRTToRCBijectionTypeA2Even(KRTToRCBijectionTypeC):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `A_{2n}^{(2)}`.\n\n This inherits from type `C_n^{(1)}` because we use the same methods in\n some places.\n '
def next_state(self, val):
"\n Build the next state for type `A_{2n}^{(2)}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 2], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A2_even import KRTToRCBijectionTypeA2Even\n sage: bijection = KRTToRCBijectionTypeA2Even(KRT(pathlist=[[-1,-2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [-2])\n sage: bijection.next_state(-2)\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
if ((val != 'E') and (val > 0)):
KRTToRCBijectionTypeA.next_state(self, val)
return
case_S = ([None] * n)
if (val == 'E'):
pos_val = n
max_width = self.ret_rig_con[(n - 1)].insert_cell(0)
else:
pos_val = (- val)
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(pos_val - 1)][0]
else:
max_width = 1
for a in range((pos_val - 1), n):
max_width = self.ret_rig_con[a].insert_cell(max_width)
case_S[a] = max_width
self._insert_cell_case_S(self.ret_rig_con[(n - 1)])
for a in reversed(range(tableau_height, (n - 1))):
if (case_S[a] == max_width):
self._insert_cell_case_S(self.ret_rig_con[a])
else:
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
if (tableau_height < n):
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
|
class RCToKRTBijectionTypeA2Even(RCToKRTBijectionTypeC):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `A_{2n}^{(2)}`.\n '
def next_state(self, height):
"\n Build the next state for type `A_{2n}^{(2)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 2], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A2_even import RCToKRTBijectionTypeA2Even\n sage: bijection = RCToKRTBijectionTypeA2Even(RC(partition_list=[[2],[2,2]]))\n sage: bijection.next_state(2)\n -1\n "
height -= 1
n = self.n
ell = ([None] * (2 * n))
case_S = ([False] * n)
b = None
last_size = 0
for a in range(height, n):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if ((b is None) and (last_size == 1)):
b = 'E'
case_S[(n - 1)] = True
if (b is None):
ell[((2 * n) - 1)] = ell[(n - 1)]
case_S[(n - 1)] = True
for a in reversed(range((n - 1))):
if ((a >= height) and (self.cur_partitions[a][ell[a]] == last_size)):
ell[(n + a)] = ell[a]
case_S[a] = True
else:
ell[(n + a)] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[(n + a)] is None):
b = (- (a + 2))
break
else:
last_size = self.cur_partitions[a][ell[(n + a)]]
if (b is None):
b = (- 1)
if case_S[0]:
row_num = self.cur_partitions[0].remove_cell(ell[0], 2)
row_num_bar = None
else:
row_num = self.cur_partitions[0].remove_cell(ell[0])
row_num_bar = self.cur_partitions[0].remove_cell(ell[n])
for a in range(1, n):
if case_S[a]:
row_num_next = self.cur_partitions[a].remove_cell(ell[a], 2)
row_num_bar_next = None
else:
row_num_next = self.cur_partitions[a].remove_cell(ell[a])
row_num_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)])
self._update_vacancy_numbers((a - 1))
if (row_num is not None):
self.cur_partitions[(a - 1)].rigging[row_num] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(a - 1)].rigging[row_num_bar] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num_bar]
row_num = row_num_next
row_num_bar = row_num_bar_next
self._update_vacancy_numbers((n - 1))
if (row_num is not None):
self.cur_partitions[(n - 1)].rigging[row_num] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(n - 1)].rigging[row_num_bar] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_bar]
return b
|
class KRTToRCBijectionTypeA2Odd(KRTToRCBijectionTypeA):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `A_{2n-1}^{(2)}`.\n\n This inherits from type `A_n^{(1)}` because we use the same methods in\n some places.\n '
def next_state(self, val):
"\n Build the next state for type `A_{2n-1}^{(2)}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 5, 2], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A2_odd import KRTToRCBijectionTypeA2Odd\n sage: bijection = KRTToRCBijectionTypeA2Odd(KRT(pathlist=[[-2,3]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [3])\n sage: bijection.next_state(3)\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
if (val > 0):
KRTToRCBijectionTypeA.next_state(self, val)
return
pos_val = (- val)
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(pos_val - 1)][0]
else:
max_width = 1
for a in range((pos_val - 1), n):
max_width = self.ret_rig_con[a].insert_cell(max_width)
for a in reversed(range(tableau_height, (n - 1))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
if (tableau_height < n):
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
|
class RCToKRTBijectionTypeA2Odd(RCToKRTBijectionTypeA):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `A_{2n-1}^{(2)}`.\n '
def next_state(self, height):
"\n Build the next state for type `A_{2n-1}^{(2)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 5, 2], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_A2_odd import RCToKRTBijectionTypeA2Odd\n sage: bijection = RCToKRTBijectionTypeA2Odd(RC(partition_list=[[1],[2,1],[2]]))\n sage: bijection.next_state(1)\n -2\n "
height -= 1
n = self.n
ell = ([None] * (2 * n))
b = None
last_size = 0
for a in range(height, n):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if (b is None):
for a in reversed(range((n - 1))):
end = ell[a]
if (a < height):
end = len(self.cur_partitions[a])
for i in reversed(range(end)):
if ((self.cur_partitions[a][i] >= last_size) and (self.cur_partitions[a].vacancy_numbers[i] == self.cur_partitions[a].rigging[i])):
ell[(n + a)] = i
break
if (ell[(n + a)] is None):
b = (- (a + 2))
break
else:
last_size = self.cur_partitions[a][ell[(n + a)]]
if (b is None):
b = (- 1)
ret_row = self.cur_partitions[0].remove_cell(ell[0])
ret_row_bar = self.cur_partitions[0].remove_cell(ell[n])
for a in range(1, (n - 1)):
ret_row_next = self.cur_partitions[a].remove_cell(ell[a])
ret_row_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)])
self._update_vacancy_numbers((a - 1))
if (ret_row is not None):
self.cur_partitions[(a - 1)].rigging[ret_row] = self.cur_partitions[(a - 1)].vacancy_numbers[ret_row]
if (ret_row_bar is not None):
self.cur_partitions[(a - 1)].rigging[ret_row_bar] = self.cur_partitions[(a - 1)].vacancy_numbers[ret_row_bar]
ret_row = ret_row_next
ret_row_bar = ret_row_bar_next
ret_row_next = self.cur_partitions[(n - 1)].remove_cell(ell[(n - 1)])
self._update_vacancy_numbers((n - 2))
if (ret_row is not None):
self.cur_partitions[(n - 2)].rigging[ret_row] = self.cur_partitions[(n - 2)].vacancy_numbers[ret_row]
if (ret_row_bar is not None):
self.cur_partitions[(n - 2)].rigging[ret_row_bar] = self.cur_partitions[(n - 2)].vacancy_numbers[ret_row_bar]
self._update_vacancy_numbers((n - 1))
if (ret_row_next is not None):
self.cur_partitions[(n - 1)].rigging[ret_row_next] = self.cur_partitions[(n - 1)].vacancy_numbers[ret_row_next]
return b
|
class KRTToRCBijectionTypeB(KRTToRCBijectionTypeC):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `B_n^{(1)}`.\n '
def run(self, verbose=False):
"\n Run the bijection from a tensor product of KR tableaux to a rigged\n configuration.\n\n INPUT:\n\n - ``tp_krt`` -- A tensor product of KR tableaux\n\n - ``verbose`` -- (Default: ``False``) Display each step in the\n bijection\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.bij_type_B import KRTToRCBijectionTypeB\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['B', 3, 1], [[2, 1]])\n sage: KRTToRCBijectionTypeB(KRT(pathlist=[[0,3]])).run()\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -1[ ]-1\n -1[ ]-1\n <BLANKLINE>\n 0[]0\n <BLANKLINE>\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['B', 3, 1], [[3, 1]])\n sage: KRTToRCBijectionTypeB(KRT(pathlist=[[-2,3,1]])).run()\n <BLANKLINE>\n (/)\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 0[]0\n <BLANKLINE>\n\n TESTS:\n\n Check that :trac:`19384` is fixed::\n\n sage: RC = RiggedConfigurations(['B',3,1], [[3,1],[3,1]])\n sage: RC._test_bijection()\n sage: RC = RiggedConfigurations(['B',3,1], [[1,1],[3,1],[1,1]])\n sage: RC._test_bijection()\n "
if verbose:
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux_element import TensorProductOfKirillovReshetikhinTableauxElement
for cur_crystal in reversed(self.tp_krt):
r = cur_crystal.parent().r()
if (r == self.n):
from sage.combinat.rigged_configurations.bij_type_A2_odd import KRTToRCBijectionTypeA2Odd
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
from sage.combinat.rigged_configurations.rigged_partition import RiggedPartition
if verbose:
print('====================')
if (len(self.cur_path) == 0):
print(repr([]))
else:
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
print('Applying doubling map')
dims = self.cur_dims[:]
dims.insert(0, [r, cur_crystal.parent().s()])
KRT = TensorProductOfKirillovReshetikhinTableaux(['A', ((2 * self.n) - 1), 2], dims)
self.ret_rig_con[(- 1)] = RiggedPartition(self.ret_rig_con[(- 1)]._list, self.ret_rig_con[(- 1)].rigging, self.ret_rig_con[(- 1)].vacancy_numbers)
elt = KRT(*[C.module_generators[0] for C in KRT.crystals])
bij = KRTToRCBijectionTypeA2Odd(elt)
bij.ret_rig_con = KRT.rigged_configurations()(*self.ret_rig_con, use_vacancy_numbers=True)
bij.cur_path = self.cur_path
bij.cur_dims = self.cur_dims
for i in range(len(self.cur_dims)):
if (bij.cur_dims[i][0] != self.n):
bij.cur_dims[i][1] *= 2
for i in range((self.n - 1)):
for j in range(len(bij.ret_rig_con[i])):
bij.ret_rig_con[i]._list[j] *= 2
bij.ret_rig_con[i].rigging[j] *= 2
bij.ret_rig_con[i].vacancy_numbers[j] *= 2
r = cur_crystal.parent().r()
for (col_number, cur_column) in enumerate(reversed(cur_crystal.to_array(False))):
bij.cur_path.insert(0, [])
bij.cur_dims.insert(0, [0, 1])
for letter in reversed(cur_column):
bij.cur_dims[0][0] += 1
val = letter.value
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), bij.cur_path)))
print('--------------------')
print(repr(bij.ret_rig_con))
print('--------------------\n')
bij.cur_path[0].insert(0, [letter])
bij.next_state(val)
if (col_number > 0):
for (i, letter_singleton) in enumerate(self.cur_path[0]):
bij.cur_path[1][i].insert(0, letter_singleton[0])
bij.cur_dims[1][1] += 1
bij.cur_path.pop(0)
bij.cur_dims.pop(0)
for a in range(self.n):
bij._update_vacancy_nums(a)
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), bij.cur_path)))
print('--------------------')
print(repr(bij.ret_rig_con))
print('--------------------\n')
print('Applying halving map')
for i in range(len(self.cur_dims)):
if (bij.cur_dims[i][0] != self.n):
bij.cur_dims[i][1] //= 2
for i in range((self.n - 1)):
for j in range(len(bij.ret_rig_con[i])):
bij.ret_rig_con[i]._list[j] //= 2
bij.ret_rig_con[i].rigging[j] //= 2
bij.ret_rig_con[i].vacancy_numbers[j] //= 2
self.ret_rig_con = self.tp_krt.parent().rigged_configurations()(*bij.ret_rig_con, use_vacancy_numbers=True)
self.ret_rig_con._set_mutable()
else:
for (col_number, cur_column) in enumerate(reversed(cur_crystal.to_array(False))):
self.cur_path.insert(0, [])
self.cur_dims.insert(0, [0, 1])
for letter in reversed(cur_column):
self.cur_dims[0][0] += 1
val = letter.value
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
self.cur_path[0].insert(0, [letter])
self.next_state(val)
if (col_number > 0):
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
print('Applying column merge')
for (i, letter_singleton) in enumerate(self.cur_path[0]):
self.cur_path[1][i].insert(0, letter_singleton[0])
self.cur_dims[1][1] += 1
self.cur_path.pop(0)
self.cur_dims.pop(0)
for a in range(self.n):
self._update_vacancy_nums(a)
self.ret_rig_con.set_immutable()
return self.ret_rig_con
def next_state(self, val):
"\n Build the next state for type `B_n^{(1)}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['B', 3, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_B import KRTToRCBijectionTypeB\n sage: bijection = KRTToRCBijectionTypeB(KRT(pathlist=[[-1,2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [3])\n sage: bijection.next_state(3)\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
if (val > 0):
KRTToRCBijectionTypeA.next_state(self, val)
return
pos_val = (- val)
if (pos_val == 0):
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(n - 1)][0]
else:
max_width = 1
max_width = self.ret_rig_con[(n - 1)].insert_cell(max_width)
width_n = (max_width + 1)
max_width = (max_width // 2)
if (tableau_height != (n - 1)):
max_width = self.ret_rig_con[(n - 2)].insert_cell(max_width)
else:
max_width = (- 1)
self._update_vacancy_nums((n - 1))
self._update_partition_values((n - 1))
p = self.ret_rig_con[(n - 1)]
num_rows = len(p)
if (((max_width * 2) + 1) != width_n):
for i in range(num_rows):
if (p._list[i] == width_n):
j = (i + 1)
while ((j < num_rows) and (p._list[j] == width_n) and (p.vacancy_numbers[j] == p.rigging[j])):
j += 1
p.rigging[(j - 1)] -= 1
break
for a in reversed(range(tableau_height, (n - 2))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
return
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = (self.ret_rig_con[(pos_val - 1)][0] + 1)
else:
max_width = 0
for a in range((pos_val - 1), (n - 1)):
max_width = self.ret_rig_con[a].insert_cell(max_width)
if (pos_val != n):
max_width = (max_width * 2)
singular_max_width = False
case_QS = False
p = self.ret_rig_con[(n - 1)]
num_rows = len(p)
width_n = 0
for i in range((num_rows + 1)):
if (i == num_rows):
if case_QS:
p._list.append(1)
p.vacancy_numbers.append(None)
p.rigging.append(None)
width_n = 1
max_width = 0
elif (not singular_max_width):
j = (len(p._list) - 1)
while ((j >= 0) and (p._list[j] <= 2)):
j -= 1
p._list.insert((j + 1), 2)
p.vacancy_numbers.insert((j + 1), None)
p.rigging.insert((j + 1), None)
max_width = 0
break
elif (p.vacancy_numbers[i] == p.rigging[i]):
if (p._list[i] < max_width):
if singular_max_width:
width_n = p._list[i]
break
max_width = p._list[i]
if case_QS:
p._list[i] += 1
p.rigging[i] = None
width_n = (max_width + 1)
else:
j = (i - 1)
while ((j >= 0) and (p._list[j] <= (max_width + 2))):
p.rigging[(j + 1)] = p.rigging[j]
j -= 1
p._list.pop(i)
p._list.insert((j + 1), (max_width + 2))
p.rigging[(j + 1)] = None
break
if ((p._list[i] == max_width) and (not singular_max_width)):
p._list[i] += 1
p.rigging[i] = None
if case_QS:
width_n = p._list[i]
break
singular_max_width = True
elif ((p._list[i] == (max_width + 1)) and (not case_QS)):
p._list[i] += 1
p.rigging[i] = None
width_n = max_width
case_QS = True
elif (((p.vacancy_numbers[i] - 1) == p.rigging[i]) and (not case_QS) and (not singular_max_width) and (p._list[i] <= max_width)):
case_QS = True
max_width = p._list[i]
p._list[i] += 1
p.rigging[i] = None
if singular_max_width:
cp = self.ret_rig_con.__copy__()
for (i, rp) in enumerate(cp):
cp[i] = rp._clone()
self._insert_cell_case_S(p)
max_width = (max_width // 2)
if (tableau_height != (n - 1)):
max_width = self.ret_rig_con[(n - 2)].insert_cell(max_width)
else:
max_width = (- 1)
self._update_vacancy_nums((n - 1))
self._update_partition_values((n - 1))
if (case_QS and (((max_width * 2) + 1) != width_n)):
for i in range(num_rows):
if (p._list[i] == width_n):
j = (i + 1)
while ((j < num_rows) and (p._list[j] == width_n) and (p.vacancy_numbers[j] == p.rigging[j])):
j += 1
p.rigging[(j - 1)] -= 1
break
for a in reversed(range(tableau_height, (n - 2))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
if (tableau_height < n):
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
assert (pos_val > 0)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
if singular_max_width:
try:
self.ret_rig_con.check()
except Exception:
self.other_outcome(cp, pos_val, width_n)
def other_outcome(self, rc, pos_val, width_n):
"\n Do the other case `(QS)` possibility.\n\n This arises from the ambiguity when we found a singular string at the\n max width in `\\nu^{(n)}`. We had first attempted case `(S)`, and if\n that resulted in an invalid rigged configuration, we now\n finish the bijection using case `(QS)`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['B',3,1], [[2,1],[1,2]])\n sage: rc = RC(partition_list=[[2,1], [2,1,1], [5,1]])\n sage: t = rc.to_tensor_product_of_kirillov_reshetikhin_tableaux()\n sage: t.to_rigged_configuration() == rc # indirect doctest\n True\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
self.ret_rig_con = rc
max_width = self.ret_rig_con[(n - 2)].insert_cell((width_n // 2))
case_QS = False
p = self.ret_rig_con[(n - 1)]
num_rows = len(p)
for i in range(len(p._list)):
if (p._list[i] == width_n):
p._list[i] += 1
p.rigging[i] = None
case_QS = True
break
if (not case_QS):
p._list.append(1)
p.rigging.append(None)
p.vacancy_numbers.append(None)
case_QS = True
width_n += 1
self._update_vacancy_nums((n - 1))
self._update_partition_values((n - 1))
if (case_QS and (((max_width * 2) + 1) != width_n)):
for i in range(num_rows):
if (p._list[i] == width_n):
j = (i + 1)
while ((j < num_rows) and (p._list[j] == width_n) and (p.vacancy_numbers[j] == p.rigging[j])):
j += 1
p.rigging[(j - 1)] -= 1
break
for a in reversed(range(tableau_height, (n - 2))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
if (tableau_height < n):
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
assert (pos_val > 0)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
|
class RCToKRTBijectionTypeB(RCToKRTBijectionTypeC):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `B_n^{(1)}`.\n '
def run(self, verbose=False, build_graph=False):
"\n Run the bijection from rigged configurations to tensor product of KR\n tableaux for type `B_n^{(1)}`.\n\n INPUT:\n\n - ``verbose`` -- (default: ``False``) display each step in the\n bijection\n - ``build_graph`` -- (default: ``False``) build the graph of each\n step of the bijection\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['B', 3, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_B import RCToKRTBijectionTypeB\n sage: RCToKRTBijectionTypeB(RC(partition_list=[[1],[1,1],[1]])).run()\n [[3], [0]]\n\n sage: RC = RiggedConfigurations(['B', 3, 1], [[3, 1]])\n sage: x = RC(partition_list=[[],[1],[1]])\n sage: RCToKRTBijectionTypeB(x).run()\n [[1], [3], [-2]]\n sage: bij = RCToKRTBijectionTypeB(x)\n sage: bij.run(build_graph=True)\n [[1], [3], [-2]]\n sage: bij._graph\n Digraph on 6 vertices\n "
from sage.combinat.crystals.letters import CrystalOfLetters
letters = CrystalOfLetters(self.rigged_con.parent()._cartan_type.classical())
ret_crystal_path = []
for dim in self.rigged_con.parent().dims:
ret_crystal_path.append([])
if (dim[0] == self.n):
from sage.combinat.rigged_configurations.bij_type_A2_odd import RCToKRTBijectionTypeA2Odd
from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations
from sage.combinat.rigged_configurations.rigged_partition import RiggedPartition, RiggedPartitionTypeB
RC = RiggedConfigurations(['A', ((2 * self.n) - 1), 2], self.cur_dims)
if verbose:
print('====================')
print(repr(RC(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying doubling map\n')
self.cur_partitions[(- 1)] = RiggedPartition(self.cur_partitions[(- 1)]._list, self.cur_partitions[(- 1)].rigging, self.cur_partitions[(- 1)].vacancy_numbers)
bij = RCToKRTBijectionTypeA2Odd(RC(*self.cur_partitions, use_vacancy_numbers=True))
for i in range(len(self.cur_dims)):
if (bij.cur_dims[i][0] != self.n):
bij.cur_dims[i][1] *= 2
for i in range((self.n - 1)):
for j in range(len(bij.cur_partitions[i])):
bij.cur_partitions[i]._list[j] *= 2
bij.cur_partitions[i].rigging[j] *= 2
bij.cur_partitions[i].vacancy_numbers[j] *= 2
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), '2x'])
for dummy_var in range(dim[1]):
if (bij.cur_dims[0][1] > 1):
bij.cur_dims[0][1] -= 1
bij.cur_dims.insert(0, [dim[0], 1])
for a in range(self.n):
bij._update_vacancy_numbers(a)
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), 'ls'])
while bij.cur_dims[0][0]:
if verbose:
print('====================')
print(repr(RC(*bij.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
ht = bij.cur_dims[0][0]
bij.cur_dims[0][0] = bij._next_index(ht)
b = bij.next_state(ht)
ret_crystal_path[(- 1)].append(letters(b))
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), letters(b)])
bij.cur_dims.pop(0)
self.cur_dims.pop(0)
self.cur_partitions = bij.cur_partitions
self.cur_partitions[(- 1)] = RiggedPartitionTypeB(self.cur_partitions[(- 1)])
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*bij.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying halving map\n')
for i in range((self.n - 1)):
for j in range(len(self.cur_partitions[i])):
self.cur_partitions[i]._list[j] //= 2
self.cur_partitions[i].rigging[j] //= 2
self.cur_partitions[i].vacancy_numbers[j] //= 2
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), '1/2x'])
else:
for dummy_var in range(dim[1]):
if (self.cur_dims[0][1] > 1):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying column split')
self.cur_dims[0][1] -= 1
self.cur_dims.insert(0, [dim[0], 1])
for a in range(self.n):
self._update_vacancy_numbers(a)
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), '2x'])
while self.cur_dims[0][0]:
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
self.cur_dims[0][0] -= 1
b = self.next_state(self.cur_dims[0][0])
ret_crystal_path[(- 1)].append(letters(b))
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), letters(b)])
self.cur_dims.pop(0)
if build_graph:
self._graph.pop(0)
from sage.graphs.digraph import DiGraph
from sage.graphs.dot2tex_utils import have_dot2tex
self._graph = DiGraph(self._graph)
if have_dot2tex():
self._graph.set_latex_options(format='dot2tex', edge_labels=True)
return self.KRT(pathlist=ret_crystal_path)
def next_state(self, height):
"\n Build the next state for type `B_n^{(1)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['B', 3, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_B import RCToKRTBijectionTypeB\n sage: bijection = RCToKRTBijectionTypeB(RC(partition_list=[[1],[1,1],[1]]))\n sage: bijection.next_state(0)\n 0\n "
n = self.n
ell = ([None] * (2 * n))
case_S = False
case_Q = False
b = None
last_size = 0
for a in range(height, (n - 1)):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if (b is None):
last_size = ((2 * last_size) - 1)
partition = self.cur_partitions[(n - 1)]
for i in reversed(range(len(partition))):
if ((partition[i] == last_size) and (partition.vacancy_numbers[i] == partition.rigging[i])):
case_Q = True
ell[(n - 1)] = i
elif (partition[i] > last_size):
if ((not case_Q) and ((partition.vacancy_numbers[i] - 1) == partition.rigging[i])):
case_Q = True
block_size = partition[i]
for j in reversed(range(i)):
if (partition[j] != block_size):
break
elif (partition.vacancy_numbers[j] == partition.rigging[j]):
case_Q = False
ell[((2 * n) - 1)] = j
last_size = partition[j]
case_S = True
break
if (not case_Q):
break
ell[(n - 1)] = i
last_size = partition[i]
elif (partition.vacancy_numbers[i] == partition.rigging[i]):
ell[((2 * n) - 1)] = i
last_size = partition[i]
case_S = True
break
if (ell[((2 * n) - 1)] is None):
if (not case_Q):
b = n
else:
b = 0
if (b is None):
last_size = ((last_size + 1) // 2)
for a in reversed(range((n - 1))):
end = ell[a]
if (a < height):
end = len(self.cur_partitions[a])
for i in reversed(range(end)):
if ((self.cur_partitions[a][i] >= last_size) and (self.cur_partitions[a].vacancy_numbers[i] == self.cur_partitions[a].rigging[i])):
ell[(n + a)] = i
break
if (ell[(n + a)] is None):
b = (- (a + 2))
break
else:
last_size = self.cur_partitions[a][ell[(n + a)]]
if (b is None):
b = (- 1)
make_quasisingular = (case_Q and case_S and ((ell[((2 * n) - 2)] is None) or (self.cur_partitions[(n - 1)][ell[((2 * n) - 1)]] < (2 * self.cur_partitions[(n - 2)][ell[((2 * n) - 2)]]))))
row_num = self.cur_partitions[0].remove_cell(ell[0])
row_num_bar = self.cur_partitions[0].remove_cell(ell[n])
for a in range(1, (n - 1)):
row_num_next = self.cur_partitions[a].remove_cell(ell[a])
row_num_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)])
self._update_vacancy_numbers((a - 1))
if (row_num is not None):
self.cur_partitions[(a - 1)].rigging[row_num] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(a - 1)].rigging[row_num_bar] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num_bar]
row_num = row_num_next
row_num_bar = row_num_bar_next
if case_Q:
if case_S:
row_num_next = self.cur_partitions[(n - 1)].remove_cell(ell[(n - 1)])
row_num_bar_next = self.cur_partitions[(n - 1)].remove_cell(ell[((2 * n) - 1)])
else:
row_num_next = self.cur_partitions[(n - 1)].remove_cell(ell[(n - 1)])
row_num_bar_next = None
elif case_S:
row_num_next = self.cur_partitions[(n - 1)].remove_cell(ell[((2 * n) - 1)], 2)
row_num_bar_next = None
else:
row_num_next = None
row_num_bar_next = None
self._update_vacancy_numbers((n - 2))
if (row_num is not None):
self.cur_partitions[(n - 2)].rigging[row_num] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(n - 2)].rigging[row_num_bar] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num_bar]
self._update_vacancy_numbers((n - 1))
if (row_num_next is not None):
self.cur_partitions[(n - 1)].rigging[row_num_next] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_next]
if (row_num_bar_next is not None):
vac_num = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_bar_next]
self.cur_partitions[(n - 1)].rigging[row_num_bar_next] = vac_num
if make_quasisingular:
block_len = self.cur_partitions[(n - 1)][row_num_bar_next]
j = (row_num_bar_next + 1)
length = len(self.cur_partitions[(n - 1)])
while ((j < length) and (self.cur_partitions[(n - 1)][j] == block_len) and (self.cur_partitions[(n - 1)].rigging[j] == vac_num)):
j += 1
self.cur_partitions[(n - 1)].rigging[(j - 1)] = (vac_num - 1)
return b
|
class KRTToRCBijectionTypeC(KRTToRCBijectionTypeA):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `C_n^{(1)}`.\n\n This inherits from type `A_n^{(1)}` because we use the same methods in\n some places.\n '
def next_state(self, val):
"\n Build the next state for type `C_n^{(1)}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['C', 3, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_C import KRTToRCBijectionTypeC\n sage: bijection = KRTToRCBijectionTypeC(KRT(pathlist=[[-1,2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [2])\n sage: bijection.next_state(2)\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
if (val > 0):
KRTToRCBijectionTypeA.next_state(self, val)
return
pos_val = (- val)
case_S = ([None] * n)
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(pos_val - 1)][0]
else:
max_width = 1
if (pos_val == n):
max_width *= 2
for a in range((pos_val - 1), (n - 1)):
max_width = self.ret_rig_con[a].insert_cell(max_width)
case_S[a] = max_width
max_width = (self.ret_rig_con[(n - 1)].insert_cell((max_width // 2)) * 2)
for a in reversed(range(tableau_height, (n - 1))):
if (case_S[a] == max_width):
self._insert_cell_case_S(self.ret_rig_con[a])
else:
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
if (tableau_height < n):
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
def _insert_cell_case_S(self, partition):
"\n Insert a cell when case `(S)` holds.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['C', 2, 1], [[2, 2]])\n sage: RP = RC(partition_list=[[2],[2,2]])[1]\n sage: RP\n -4[ ][ ]-4\n -4[ ][ ]-4\n <BLANKLINE>\n sage: RP.rigging[0] = None\n sage: from sage.combinat.rigged_configurations.bij_type_C import KRTToRCBijectionTypeC\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['C', 3, 1], [[2,1]])\n sage: bijection = KRTToRCBijectionTypeC(KRT(pathlist=[[-1,2]]))\n sage: bijection._insert_cell_case_S(RP)\n sage: RP\n -4[ ][ ][ ]None\n -4[ ][ ]-4\n <BLANKLINE>\n "
if (partition.rigging[0] is None):
partition._list[0] += 1
return
num_rows = len(partition)
for i in reversed(range(1, num_rows)):
if (partition.rigging[i] is None):
j = (i - 1)
while ((j >= 0) and (partition._list[j] == partition._list[i])):
partition.rigging[(j + 1)] = partition.rigging[j]
j -= 1
partition._list[(j + 1)] += 1
partition.rigging[(j + 1)] = None
return
|
class RCToKRTBijectionTypeC(RCToKRTBijectionTypeA):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `C_n^{(1)}`.\n '
def next_state(self, height):
"\n Build the next state for type `C_n^{(1)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['C', 3, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_C import RCToKRTBijectionTypeC\n sage: bijection = RCToKRTBijectionTypeC(RC(partition_list=[[2],[2],[1]]))\n sage: bijection.next_state(1)\n -1\n "
height -= 1
n = self.n
ell = ([None] * (2 * n))
case_S = ([False] * n)
b = None
last_size = 0
for a in range(height, (n - 1)):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if (b is None):
ell[(n - 1)] = self._find_singular_string(self.cur_partitions[(n - 1)], ((last_size // 2) + (last_size % 2)))
if (ell[(n - 1)] is None):
b = n
else:
last_size = (self.cur_partitions[(n - 1)][ell[(n - 1)]] * 2)
if (b is None):
ell[((2 * n) - 1)] = ell[(n - 1)]
case_S[(n - 1)] = True
for a in reversed(range((n - 1))):
if ((a >= height) and (self.cur_partitions[a][ell[a]] == last_size)):
ell[(n + a)] = ell[a]
case_S[a] = True
else:
ell[(n + a)] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[(n + a)] is None):
b = (- (a + 2))
break
else:
last_size = self.cur_partitions[a][ell[(n + a)]]
if (b is None):
b = (- 1)
if case_S[0]:
row_num = self.cur_partitions[0].remove_cell(ell[0], 2)
row_num_bar = None
else:
row_num = self.cur_partitions[0].remove_cell(ell[0])
row_num_bar = self.cur_partitions[0].remove_cell(ell[n])
for a in range(1, (n - 1)):
if case_S[a]:
row_num_next = self.cur_partitions[a].remove_cell(ell[a], 2)
row_num_bar_next = None
else:
row_num_next = self.cur_partitions[a].remove_cell(ell[a])
row_num_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)])
self._update_vacancy_numbers((a - 1))
if (row_num is not None):
self.cur_partitions[(a - 1)].rigging[row_num] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(a - 1)].rigging[row_num_bar] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num_bar]
row_num = row_num_next
row_num_bar = row_num_bar_next
row_num_next = self.cur_partitions[(n - 1)].remove_cell(ell[(n - 1)])
self._update_vacancy_numbers((n - 2))
if (row_num is not None):
self.cur_partitions[(n - 2)].rigging[row_num] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(n - 2)].rigging[row_num_bar] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num_bar]
self._update_vacancy_numbers((n - 1))
if (row_num_next is not None):
self.cur_partitions[(n - 1)].rigging[row_num_next] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_next]
return b
|
class KRTToRCBijectionTypeD(KRTToRCBijectionTypeA):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `D_n^{(1)}`.\n\n This inherits from type `A_n^{(1)}` because we use the same methods in\n some places.\n '
def run(self, verbose=False):
"\n Run the bijection from a tensor product of KR tableaux to a rigged\n configuration for type `D_n^{(1)}`.\n\n INPUT:\n\n - ``tp_krt`` -- A tensor product of KR tableaux\n\n - ``verbose`` -- (Default: ``False``) Display each step in the\n bijection\n\n EXAMPLES::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import KRTToRCBijectionTypeD\n sage: KRTToRCBijectionTypeD(KRT(pathlist=[[-3,2]])).run()\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 2[ ]2\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n "
if verbose:
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux_element import TensorProductOfKirillovReshetikhinTableauxElement
for cur_crystal in reversed(self.tp_krt):
r = cur_crystal.parent().r()
for (col_number, cur_column) in enumerate(reversed(cur_crystal.to_array(False))):
self.cur_path.insert(0, [])
if (r >= (self.n - 1)):
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
print('Applying doubling map')
self.doubling_map()
self.cur_dims.insert(0, [0, 1])
for letter in reversed(cur_column):
if (self.cur_dims[0][0] < r):
self.cur_dims[0][0] += 1
val = letter.value
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
self.cur_path[0].insert(0, [letter])
self.next_state(val)
if (r >= (self.n - 1)):
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
print('Applying halving map')
self.halving_map()
if (col_number > 0):
for (i, letter_singleton) in enumerate(self.cur_path[0]):
self.cur_path[1][i].insert(0, letter_singleton[0])
self.cur_dims[1][1] += 1
self.cur_path.pop(0)
self.cur_dims.pop(0)
for a in range(self.n):
self._update_vacancy_nums(a)
self.ret_rig_con.set_immutable()
return self.ret_rig_con
def next_state(self, val):
"\n Build the next state for type `D_n^{(1)}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import KRTToRCBijectionTypeD\n sage: bijection = KRTToRCBijectionTypeD(KRT(pathlist=[[5,3]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [3])\n sage: bijection.next_state(3)\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
if (val > 0):
KRTToRCBijectionTypeA.next_state(self, val)
if (val == (n - 1)):
self._update_vacancy_nums(val)
if (tableau_height >= (n - 2)):
self._correct_vacancy_nums()
return
pos_val = (- val)
if (pos_val == n):
if ((self.cur_dims[0][0] == (n - 1)) and (tableau_height == (n - 1))):
self._update_vacancy_nums((n - 2))
self._update_vacancy_nums((n - 1))
self._correct_vacancy_nums()
return
if (len(self.ret_rig_con[(n - 1)]) > 0):
max_width = (self.ret_rig_con[(n - 1)][0] + 1)
else:
max_width = 1
max_width = self.ret_rig_con[(n - 1)].insert_cell(max_width)
for a in reversed(range(tableau_height, (n - 2))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
self._update_vacancy_nums((n - 1))
if (tableau_height >= (n - 2)):
self._correct_vacancy_nums()
self._update_partition_values((n - 1))
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
self._update_vacancy_nums((n - 2))
return
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = (self.ret_rig_con[(pos_val - 1)][0] + 1)
else:
max_width = 1
if ((pos_val == (n - 1)) and (len(self.ret_rig_con[(n - 1)]) > 0) and ((self.ret_rig_con[(n - 1)][0] + 1) > max_width)):
max_width = (self.ret_rig_con[(n - 1)][0] + 1)
for a in range((pos_val - 1), (n - 2)):
max_width = self.ret_rig_con[a].insert_cell(max_width)
if (tableau_height <= (n - 2)):
max_width2 = self.ret_rig_con[(n - 2)].insert_cell(max_width)
max_width = self.ret_rig_con[(n - 1)].insert_cell(max_width)
if (max_width2 < max_width):
max_width = max_width2
elif (pos_val <= self.cur_dims[0][0]):
max_width = self.ret_rig_con[(self.cur_dims[0][0] - 1)].insert_cell(max_width)
if (tableau_height <= (n - 3)):
max_width = self.ret_rig_con[(n - 3)].insert_cell(max_width)
self._update_vacancy_nums((n - 2))
self._update_vacancy_nums((n - 1))
if (tableau_height >= (n - 2)):
self._correct_vacancy_nums()
self._update_partition_values((n - 2))
self._update_partition_values((n - 1))
for a in reversed(range(tableau_height, (n - 3))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
if (tableau_height < (n - 2)):
self._update_vacancy_nums(tableau_height)
self._update_partition_values(tableau_height)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (0 < tableau_height):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
elif (pos_val <= (n - 1)):
for a in range((pos_val - 1), (n - 2)):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
def _correct_vacancy_nums(self):
"\n Correct the vacancy numbers with special considerations for spinor\n columns.\n\n This should only be called when we are going to have a (left-most)\n spinor column of height `n-1` or `n` in type `D^{(1)_n`.\n\n This is a correction for the spinor column where we consider the\n weight `\\overline{\\Lambda_k}` where `k = n-1,n` during the spinor\n bijection. This adds 1 to each of the respective vacancy numbers\n to account for this.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import KRTToRCBijectionTypeD\n sage: bijection = KRTToRCBijectionTypeD(KRT(pathlist=[[-1,4,3,2]]))\n sage: bijection.doubling_map()\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [2])\n sage: bijection.next_state(2) # indirect doctest\n sage: bijection.ret_rig_con\n <BLANKLINE>\n -2[ ]-2\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n "
pos = (self.n - 2)
if (self.cur_dims[0][0] == len(self.cur_path[0])):
pos += 1
for i in range(len(self.ret_rig_con[pos]._list)):
self.ret_rig_con[pos].vacancy_numbers[i] += 1
def doubling_map(self):
"\n Perform the doubling map of the rigged configuration at the current\n state of the bijection.\n\n This is the map `B(\\Lambda) \\hookrightarrow B(2 \\Lambda)` which\n doubles each of the rigged partitions and updates the vacancy numbers\n accordingly.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 1], [[4,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import KRTToRCBijectionTypeD\n sage: bijection = KRTToRCBijectionTypeD(KRT(pathlist=[[-1,4,3,2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [2])\n sage: bijection.next_state(2)\n sage: bijection.ret_rig_con\n <BLANKLINE>\n -2[ ]-2\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: bijection.cur_dims\n [[0, 1]]\n sage: bijection.doubling_map()\n sage: bijection.ret_rig_con\n <BLANKLINE>\n -4[ ][ ]-4\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: bijection.cur_dims\n [[0, 2]]\n "
for i in range(len(self.cur_dims)):
self.cur_dims[i][1] *= 2
for i in range(len(self.ret_rig_con)):
for j in range(len(self.ret_rig_con[i])):
self.ret_rig_con[i]._list[j] *= 2
self.ret_rig_con[i].rigging[j] *= 2
self.ret_rig_con[i].vacancy_numbers[j] *= 2
def halving_map(self):
"\n Perform the halving map of the rigged configuration at the current\n state of the bijection.\n\n This is the inverse map to `B(\\Lambda) \\hookrightarrow B(2 \\Lambda)`\n which halves each of the rigged partitions and updates the vacancy\n numbers accordingly.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 1], [[4,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import KRTToRCBijectionTypeD\n sage: bijection = KRTToRCBijectionTypeD(KRT(pathlist=[[-1,4,3,2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [2])\n sage: bijection.next_state(2)\n sage: test = bijection.ret_rig_con\n sage: bijection.doubling_map()\n sage: bijection.halving_map()\n sage: test == bijection.ret_rig_con\n True\n "
for i in range(1, len(self.cur_dims)):
self.cur_dims[i][1] //= 2
for i in range(len(self.ret_rig_con)):
for j in range(len(self.ret_rig_con[i])):
self.ret_rig_con[i]._list[j] //= 2
self.ret_rig_con[i].rigging[j] //= 2
self.ret_rig_con[i].vacancy_numbers[j] //= 2
|
class RCToKRTBijectionTypeD(RCToKRTBijectionTypeA):
'\n Specific implementation of the bijection from rigged configurations to tensor products of KR tableaux for type `D_n^{(1)}`.\n '
def run(self, verbose=False, build_graph=False):
"\n Run the bijection from rigged configurations to tensor product of KR\n tableaux for type `D_n^{(1)}`.\n\n INPUT:\n\n - ``verbose`` -- (default: ``False``) display each step in the\n bijection\n - ``build_graph`` -- (default: ``False``) build the graph of each\n step of the bijection\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 1]])\n sage: x = RC(partition_list=[[1],[1],[1],[1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import RCToKRTBijectionTypeD\n sage: RCToKRTBijectionTypeD(x).run()\n [[2], [-3]]\n sage: bij = RCToKRTBijectionTypeD(x)\n sage: bij.run(build_graph=True)\n [[2], [-3]]\n sage: bij._graph\n Digraph on 3 vertices\n "
from sage.combinat.crystals.letters import CrystalOfLetters
letters = CrystalOfLetters(self.rigged_con.parent()._cartan_type.classical())
ret_crystal_path = []
for dim in self.rigged_con.parent().dims:
ret_crystal_path.append([])
for dummy_var in range(dim[1]):
if (self.cur_dims[0][1] > 1):
self.cur_dims[0][1] -= 1
self.cur_dims.insert(0, [dim[0], 1])
for a in range(self.n):
self._update_vacancy_numbers(a)
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), 'ls'])
if (dim[0] >= (self.n - 1)):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying doubling map')
self.doubling_map()
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), '2x'])
if (dim[0] == (self.n - 1)):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
b = self.next_state(self.n)
if (b == self.n):
b = (- self.n)
ret_crystal_path[(- 1)].append(letters(b))
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), letters(b)])
while (self.cur_dims[0][0] > 0):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
self.cur_dims[0][0] -= 1
b = self.next_state(self.cur_dims[0][0])
if ((dim[0] == self.n) and (b == (- self.n)) and (self.cur_dims[0][0] == (self.n - 1))):
b = (- (self.n - 1))
ret_crystal_path[(- 1)].append(letters(b))
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), letters(b)])
self.cur_dims.pop(0)
if (dim[0] >= (self.n - 1)):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying halving map')
self.halving_map()
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), '1/2x'])
if build_graph:
self._graph.pop(0)
from sage.graphs.digraph import DiGraph
from sage.graphs.dot2tex_utils import have_dot2tex
self._graph = DiGraph(self._graph, format='list_of_edges')
if have_dot2tex():
self._graph.set_latex_options(format='dot2tex', edge_labels=True)
return self.KRT(pathlist=ret_crystal_path)
def next_state(self, height):
"\n Build the next state for type `D_n^{(1)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import RCToKRTBijectionTypeD\n sage: bijection = RCToKRTBijectionTypeD(RC(partition_list=[[],[1,1],[1],[1]]))\n sage: bijection.next_state(0)\n 1\n "
n = self.n
ell = ([None] * ((2 * n) - 2))
b = None
last_size = 0
for a in range(height, (n - 2)):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if (height == n):
ell[(n - 2)] = self._find_singular_string(self.cur_partitions[(n - 2)], last_size)
if (ell[(n - 2)] is not None):
last_size = self.cur_partitions[(n - 2)][ell[(n - 2)]]
else:
b = (- n)
elif (height == (n - 1)):
ell[(n - 1)] = self._find_singular_string(self.cur_partitions[(n - 1)], last_size)
if (ell[(n - 1)] is not None):
last_size = self.cur_partitions[(n - 1)][ell[(n - 1)]]
else:
b = n
elif (b is None):
ell[(n - 2)] = self._find_singular_string(self.cur_partitions[(n - 2)], last_size)
ell[(n - 1)] = self._find_singular_string(self.cur_partitions[(n - 1)], last_size)
if (ell[(n - 2)] is not None):
temp_size = self.cur_partitions[(n - 2)][ell[(n - 2)]]
if (ell[(n - 1)] is not None):
last_size = self.cur_partitions[(n - 1)][ell[(n - 1)]]
if (temp_size > last_size):
last_size = temp_size
else:
b = n
elif (ell[(n - 1)] is not None):
b = (- n)
else:
b = (n - 1)
if (b is None):
for a in reversed(range((n - 2))):
end = ell[a]
if (a < height):
end = len(self.cur_partitions[a])
for i in reversed(range(end)):
if ((self.cur_partitions[a][i] >= last_size) and (self.cur_partitions[a].vacancy_numbers[i] == self.cur_partitions[a].rigging[i])):
ell[(n + a)] = i
break
if (ell[(n + a)] is None):
b = (- (a + 2))
break
else:
last_size = self.cur_partitions[a][ell[(n + a)]]
if (b is None):
b = (- 1)
ret_row = self.cur_partitions[0].remove_cell(ell[0])
ret_row_bar = self.cur_partitions[0].remove_cell(ell[n])
for a in range(1, (n - 2)):
ret_row_next = self.cur_partitions[a].remove_cell(ell[a])
ret_row_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)])
self._update_vacancy_numbers((a - 1))
if (ret_row is not None):
self.cur_partitions[(a - 1)].rigging[ret_row] = self.cur_partitions[(a - 1)].vacancy_numbers[ret_row]
if (ret_row_bar is not None):
self.cur_partitions[(a - 1)].rigging[ret_row_bar] = self.cur_partitions[(a - 1)].vacancy_numbers[ret_row_bar]
ret_row = ret_row_next
ret_row_bar = ret_row_bar_next
ret_row_next = self.cur_partitions[(n - 2)].remove_cell(ell[(n - 2)])
ret_row_bar_next = self.cur_partitions[(n - 1)].remove_cell(ell[(n - 1)])
self._update_vacancy_numbers((n - 3))
if (ret_row is not None):
self.cur_partitions[(n - 3)].rigging[ret_row] = self.cur_partitions[(n - 3)].vacancy_numbers[ret_row]
if (ret_row_bar is not None):
self.cur_partitions[(n - 3)].rigging[ret_row_bar] = self.cur_partitions[(n - 3)].vacancy_numbers[ret_row_bar]
self._update_vacancy_numbers((n - 2))
if (ret_row_next is not None):
self.cur_partitions[(n - 2)].rigging[ret_row_next] = self.cur_partitions[(n - 2)].vacancy_numbers[ret_row_next]
self._update_vacancy_numbers((n - 1))
if (height >= (n - 1)):
self._correct_vacancy_nums()
if (ret_row_bar_next is not None):
self.cur_partitions[(n - 1)].rigging[ret_row_bar_next] = self.cur_partitions[(n - 1)].vacancy_numbers[ret_row_bar_next]
return b
def doubling_map(self):
"\n Perform the doubling map of the rigged configuration at the current\n state of the bijection.\n\n This is the map `B(\\Lambda) \\hookrightarrow B(2 \\Lambda)` which\n doubles each of the rigged partitions and updates the vacancy numbers\n accordingly.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[4, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import RCToKRTBijectionTypeD\n sage: bijection = RCToKRTBijectionTypeD(RC(partition_list=[[],[],[],[1]]))\n sage: bijection.cur_partitions\n [(/)\n , (/)\n , (/)\n , -1[ ]-1\n ]\n sage: bijection.doubling_map()\n sage: bijection.cur_partitions\n [(/)\n , (/)\n , (/)\n , -2[ ][ ]-2\n ]\n "
for i in range(1, len(self.cur_dims)):
self.cur_dims[i][1] *= 2
for partition in self.cur_partitions:
for j in range(len(partition)):
partition._list[j] *= 2
partition.rigging[j] *= 2
partition.vacancy_numbers[j] *= 2
def halving_map(self):
"\n Perform the halving map of the rigged configuration at the current\n state of the bijection.\n\n This is the inverse map to `B(\\Lambda) \\hookrightarrow B(2 \\Lambda)`\n which halves each of the rigged partitions and updates the vacancy\n numbers accordingly.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[4, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import RCToKRTBijectionTypeD\n sage: bijection = RCToKRTBijectionTypeD(RC(partition_list=[[],[],[],[1]]))\n sage: test = bijection.cur_partitions\n sage: bijection.doubling_map()\n sage: bijection.halving_map()\n sage: test == bijection.cur_partitions\n True\n "
for i in range(len(self.cur_dims)):
self.cur_dims[i][1] //= 2
for partition in self.cur_partitions:
for j in range(len(partition)):
partition._list[j] //= 2
partition.rigging[j] //= 2
partition.vacancy_numbers[j] //= 2
def _correct_vacancy_nums(self):
"\n Correct the vacancy numbers with special considerations for spinor\n columns.\n\n This should only be called when we are going to have a (left-most)\n spinor column of height `n-1` or `n`.\n\n This is a correction for the spinor column where we consider the\n weight `\\overline{\\Lambda_k}` where `k = n-1,n` during the spinor\n bijection. This adds 1 to each of the respective vacancy numbers\n to account for this.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[4, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D import RCToKRTBijectionTypeD\n sage: bijection = RCToKRTBijectionTypeD(RC(partition_list=[[],[],[],[1]]))\n sage: bijection.doubling_map()\n sage: bijection.next_state(4) # indirect doctest\n -4\n "
n = self.n
for i in range(len(self.cur_partitions[(n - 1)]._list)):
self.cur_partitions[(n - 1)].vacancy_numbers[i] += 1
|
class KRTToRCBijectionTypeDTri(KRTToRCBijectionTypeA):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `D_4^{(3)}`.\n\n This inherits from type `A_n^{(1)}` because we use the same methods in\n some places.\n '
def next_state(self, val):
"\n Build the next state for type `D_4^{(3)}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 3], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D_tri import KRTToRCBijectionTypeDTri\n sage: bijection = KRTToRCBijectionTypeDTri(KRT(pathlist=[[-1,2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [2])\n sage: bijection.next_state(2)\n "
tableau_height = (len(self.cur_path[0]) - 1)
if (val == 'E'):
self.ret_rig_con[0].insert_cell(0)
self.ret_rig_con[1].insert_cell(0)
if (tableau_height == 0):
self.ret_rig_con[0].insert_cell(0)
self._update_vacancy_nums(0)
self._update_vacancy_nums(1)
self._update_partition_values(0)
self._update_partition_values(1)
return
if (val > 0):
KRTToRCBijectionTypeA.next_state(self, val)
return
pos_val = (- val)
if (pos_val == 0):
if (len(self.ret_rig_con[0]) > 0):
max_width = self.ret_rig_con[0][0]
else:
max_width = 1
max_width = self.ret_rig_con[0].insert_cell(max_width)
width_n = (max_width + 1)
for a in reversed(range(tableau_height, 2)):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums(0)
self._update_partition_values(0)
self._update_vacancy_nums(1)
self._update_partition_values(1)
p = self.ret_rig_con[0]
num_rows = len(p)
for i in range(num_rows):
if (p._list[i] == width_n):
j = (i + 1)
while ((j < num_rows) and (p._list[j] == width_n) and (p.vacancy_numbers[j] == p.rigging[j])):
j += 1
p.rigging[(j - 1)] -= 1
break
return
case_S = ([None] * 2)
pos_val = (- val)
if (pos_val < 3):
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(pos_val - 1)][0]
else:
max_width = 1
for a in range((pos_val - 1), 2):
max_width = self.ret_rig_con[a].insert_cell(max_width)
case_S[a] = max_width
elif (len(self.ret_rig_con[0]) > 0):
max_width = self.ret_rig_con[0][0]
else:
max_width = 1
P = self.ret_rig_con[0]
num_rows = len(P)
case_QS = False
for i in range((num_rows + 1)):
if (i == num_rows):
max_width = 0
if case_QS:
P._list.append(1)
P.vacancy_numbers.append(None)
j = (len(P._list) - 1)
while ((j >= 0) and (P._list[j] == 1)):
j -= 1
P.rigging.insert((j + 1), None)
width_n = 1
else:
j = (len(P._list) - 1)
while ((j >= 0) and (P._list[j] <= 2)):
j -= 1
P._list.insert((j + 1), 2)
P.vacancy_numbers.insert((j + 1), None)
P.rigging.insert((j + 1), None)
break
elif (P._list[i] <= max_width):
if (P.vacancy_numbers[i] == P.rigging[i]):
max_width = P._list[i]
if case_QS:
P._list[i] += 1
width_n = P._list[i]
P.rigging[i] = None
else:
j = (i - 1)
while ((j >= 0) and (P._list[j] <= (max_width + 2))):
P.rigging[(j + 1)] = P.rigging[j]
j -= 1
P._list.pop(i)
P._list.insert((j + 1), (max_width + 2))
P.rigging[(j + 1)] = None
break
elif (((P.vacancy_numbers[i] - 1) == P.rigging[i]) and (not case_QS)):
case_QS = True
P._list[i] += 1
P.rigging[i] = None
if (case_S[1] == max_width):
P = self.ret_rig_con[1]
if (P.rigging[0] is None):
P._list[0] += 1
else:
for i in reversed(range(1, len(P))):
if (P.rigging[i] is None):
j = (i - 1)
while ((j >= 0) and (P._list[j] == P._list[i])):
P.rigging[(j + 1)] = P.rigging[j]
j -= 1
P._list[(j + 1)] += 1
P.rigging[(j + 1)] = None
break
else:
max_width = self.ret_rig_con[1].insert_cell(max_width)
if (tableau_height == 0):
if (case_S[0] == max_width):
P = self.ret_rig_con[0]
for i in reversed(range(1, len(P))):
if (P.rigging[i] is None):
j = (i - 1)
while ((j >= 0) and (P._list[j] == P._list[i])):
P.rigging[(j + 1)] = P.rigging[j]
j -= 1
P._list[(j + 1)] += 1
P.rigging[(j + 1)] = None
break
else:
max_width = self.ret_rig_con[0].insert_cell(max_width)
self._update_vacancy_nums(0)
self._update_partition_values(0)
self._update_vacancy_nums(1)
self._update_partition_values(1)
if case_QS:
num_rows = len(P)
for i in range(num_rows):
if (P._list[i] == width_n):
j = (i + 1)
while ((j < num_rows) and (P._list[j] == width_n) and (P.vacancy_numbers[j] == P.rigging[j])):
j += 1
P.rigging[(j - 1)] -= 1
break
|
class RCToKRTBijectionTypeDTri(RCToKRTBijectionTypeA):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `D_4^{(3)}`.\n '
def next_state(self, height):
"\n Build the next state for type `D_4^{(3)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['D', 4, 3], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D_tri import RCToKRTBijectionTypeDTri\n sage: bijection = RCToKRTBijectionTypeDTri(RC(partition_list=[[3],[2]]))\n sage: bijection.next_state(2)\n -3\n "
height -= 1
ell = ([None] * 6)
case_S = ([False] * 3)
case_Q = False
b = None
last_size = 0
for a in range(height, 2):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if (b is None):
partition = self.cur_partitions[0]
for i in reversed(range(len(partition))):
if (partition[i] >= last_size):
if ((partition.vacancy_numbers[i] == partition.rigging[i]) and (i != ell[0])):
if (partition[i] == 1):
b = 'E'
else:
last_size = partition[i]
case_S[2] = True
ell[3] = i
break
elif (((partition.vacancy_numbers[i] - 1) == partition.rigging[i]) and (not case_Q)):
case_Q = True
block_size = partition[i]
for j in reversed(range(i)):
if (partition[j] != block_size):
break
elif ((partition.vacancy_numbers[j] == partition.rigging[j]) and (j != ell[0])):
case_Q = False
break
if case_Q:
last_size = (partition[i] + 1)
ell[2] = i
if (ell[3] is None):
if (not case_Q):
b = 3
else:
b = 0
if (b is None):
if (self.cur_partitions[1][ell[1]] == last_size):
ell[4] = ell[1]
case_S[1] = True
else:
ell[4] = self._find_singular_string(self.cur_partitions[1], last_size)
if (ell[4] is None):
b = (- 3)
else:
last_size = self.cur_partitions[1][ell[4]]
if (b is None):
P = self.cur_partitions[0]
if ((ell[0] is not None) and (P[ell[0]] == last_size)):
ell[5] = ell[0]
case_S[0] = True
else:
end = ell[3]
for i in reversed(range(end)):
if ((P[i] >= last_size) and (P.vacancy_numbers[i] == P.rigging[i])):
ell[5] = i
break
if (ell[5] is None):
b = (- 2)
if (b is None):
b = (- 1)
if case_S[1]:
row1 = [self.cur_partitions[1].remove_cell(ell[4], 2)]
else:
row1 = [self.cur_partitions[1].remove_cell(ell[1]), self.cur_partitions[1].remove_cell(ell[4])]
if case_S[0]:
row0 = [self.cur_partitions[0].remove_cell(ell[5], 2)]
row0.append(self.cur_partitions[0].remove_cell(ell[3], 2))
else:
if case_Q:
if ((ell[0] is None) or (ell[0] < ell[2])):
row0 = [self.cur_partitions[0].remove_cell(ell[2]), self.cur_partitions[0].remove_cell(ell[0])]
else:
row0 = [self.cur_partitions[0].remove_cell(ell[0]), self.cur_partitions[0].remove_cell(ell[2])]
if case_S[2]:
quasi = self.cur_partitions[0].remove_cell(ell[3])
else:
row0 = [self.cur_partitions[0].remove_cell(ell[0])]
if case_S[2]:
row0.append(self.cur_partitions[0].remove_cell(ell[3], 2))
row0.append(self.cur_partitions[0].remove_cell(ell[5]))
self._update_vacancy_numbers(0)
self._update_vacancy_numbers(1)
for l in row1:
if (l is not None):
self.cur_partitions[1].rigging[l] = self.cur_partitions[1].vacancy_numbers[l]
for l in row0:
if (l is not None):
self.cur_partitions[0].rigging[l] = self.cur_partitions[0].vacancy_numbers[l]
if (case_Q and case_S[2]):
P = self.cur_partitions[0]
vac_num = P.vacancy_numbers[quasi]
P.rigging[quasi] = vac_num
block_len = P[quasi]
j = (quasi + 1)
length = len(P)
while ((j < length) and (P[j] == block_len) and (P.rigging[j] == vac_num)):
j += 1
P.rigging[(j - 1)] = (vac_num - 1)
return b
|
class KRTToRCBijectionTypeDTwisted(KRTToRCBijectionTypeD, KRTToRCBijectionTypeA2Even):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `D_{n+1}^{(2)}`.\n\n This inherits from type `C_n^{(1)}` and `D_n^{(1)}` because we use the\n same methods in some places.\n '
def run(self, verbose=False):
"\n Run the bijection from a tensor product of KR tableaux to a rigged\n configuration for type `D_{n+1}^{(2)}`.\n\n INPUT:\n\n - ``tp_krt`` -- A tensor product of KR tableaux\n\n - ``verbose`` -- (Default: ``False``) Display each step in the\n bijection\n\n EXAMPLES::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 2], [[3,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D_twisted import KRTToRCBijectionTypeDTwisted\n sage: KRTToRCBijectionTypeDTwisted(KRT(pathlist=[[-1,3,2]])).run()\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 1[ ]1\n <BLANKLINE>\n "
if verbose:
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux_element import TensorProductOfKirillovReshetikhinTableauxElement
for cur_crystal in reversed(self.tp_krt):
r = cur_crystal.parent().r()
for (col_number, cur_column) in enumerate(reversed(cur_crystal.to_array(False))):
self.cur_path.insert(0, [])
if (r == self.n):
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
print('Applying doubling map')
self.doubling_map()
self.cur_dims.insert(0, [0, 1])
for letter in reversed(cur_column):
self.cur_dims[0][0] += 1
val = letter.value
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
self.cur_path[0].insert(0, [letter])
self.next_state(val)
if (r == self.n):
if verbose:
print('====================')
print(repr(TensorProductOfKirillovReshetikhinTableauxElement(self.tp_krt.parent(), self.cur_path)))
print('--------------------')
print(repr(self.ret_rig_con))
print('--------------------\n')
print('Applying halving map')
self.halving_map()
if (col_number > 0):
for (i, letter_singleton) in enumerate(self.cur_path[0]):
self.cur_path[1][i].insert(0, letter_singleton[0])
self.cur_dims[1][1] += 1
self.cur_path.pop(0)
self.cur_dims.pop(0)
for a in range(self.n):
self._update_vacancy_nums(a)
self.ret_rig_con.set_immutable()
return self.ret_rig_con
def next_state(self, val):
"\n Build the next state for type `D_{n+1}^{(2)}`.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['D', 4, 2], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D_twisted import KRTToRCBijectionTypeDTwisted\n sage: bijection = KRTToRCBijectionTypeDTwisted(KRT(pathlist=[[-1,2]]))\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [0, 1])\n sage: bijection.cur_path[0].insert(0, [2])\n sage: bijection.next_state(2)\n "
n = self.n
tableau_height = (len(self.cur_path[0]) - 1)
if (val == 'E'):
KRTToRCBijectionTypeA2Even.next_state(self, val)
return
elif (val > 0):
KRTToRCBijectionTypeA.next_state(self, val)
if (tableau_height >= (n - 1)):
self._correct_vacancy_nums()
return
pos_val = (- val)
if (pos_val == 0):
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(n - 1)][0]
else:
max_width = 1
max_width = self.ret_rig_con[(n - 1)].insert_cell(max_width)
width_n = (max_width + 1)
for a in reversed(range(tableau_height, (n - 1))):
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
self._update_vacancy_nums(tableau_height)
if (tableau_height >= (n - 1)):
self._correct_vacancy_nums()
self._update_partition_values(tableau_height)
if (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
p = self.ret_rig_con[(n - 1)]
num_rows = len(p)
for i in range(num_rows):
if (p._list[i] == width_n):
j = (i + 1)
while ((j < num_rows) and (p._list[j] == width_n) and (p.vacancy_numbers[j] == p.rigging[j])):
j += 1
p.rigging[(j - 1)] -= 1
break
return
case_S = ([None] * n)
pos_val = (- val)
if (len(self.ret_rig_con[(pos_val - 1)]) > 0):
max_width = self.ret_rig_con[(pos_val - 1)][0]
else:
max_width = 1
for a in range((pos_val - 1), (n - 1)):
max_width = self.ret_rig_con[a].insert_cell(max_width)
case_S[a] = max_width
partition = self.ret_rig_con[(n - 1)]
num_rows = len(partition)
case_QS = False
for i in range((num_rows + 1)):
if (i == num_rows):
max_width = 0
if case_QS:
partition._list.append(1)
partition.vacancy_numbers.append(None)
j = (len(partition._list) - 1)
while ((j >= 0) and (partition._list[j] == 1)):
j -= 1
partition.rigging.insert((j + 1), None)
width_n = 1
else:
j = (len(partition._list) - 1)
while ((j >= 0) and (partition._list[j] <= 2)):
j -= 1
partition._list.insert((j + 1), 2)
partition.vacancy_numbers.insert((j + 1), None)
partition.rigging.insert((j + 1), None)
break
elif (partition._list[i] <= max_width):
if (partition.vacancy_numbers[i] == partition.rigging[i]):
max_width = partition._list[i]
if case_QS:
partition._list[i] += 1
width_n = partition._list[i]
partition.rigging[i] = None
else:
j = (i - 1)
while ((j >= 0) and (partition._list[j] <= (max_width + 2))):
partition.rigging[(j + 1)] = partition.rigging[j]
j -= 1
partition._list.pop(i)
partition._list.insert((j + 1), (max_width + 2))
partition.rigging[(j + 1)] = None
break
elif (((partition.vacancy_numbers[i] - 1) == partition.rigging[i]) and (not case_QS)):
case_QS = True
partition._list[i] += 1
partition.rigging[i] = None
for a in reversed(range(tableau_height, (n - 1))):
if (case_S[a] == max_width):
self._insert_cell_case_S(self.ret_rig_con[a])
else:
max_width = self.ret_rig_con[a].insert_cell(max_width)
self._update_vacancy_nums((a + 1))
self._update_partition_values((a + 1))
self._update_vacancy_nums(tableau_height)
if (tableau_height >= (n - 1)):
self._correct_vacancy_nums()
self._update_partition_values(tableau_height)
if (pos_val <= tableau_height):
for a in range((pos_val - 1), tableau_height):
self._update_vacancy_nums(a)
self._update_partition_values(a)
if (pos_val > 1):
self._update_vacancy_nums((pos_val - 2))
self._update_partition_values((pos_val - 2))
elif (tableau_height > 0):
self._update_vacancy_nums((tableau_height - 1))
self._update_partition_values((tableau_height - 1))
if case_QS:
num_rows = len(partition)
for i in range(num_rows):
if (partition._list[i] == width_n):
j = (i + 1)
while ((j < num_rows) and (partition._list[j] == width_n) and (partition.vacancy_numbers[j] == partition.rigging[j])):
j += 1
partition.rigging[(j - 1)] -= 1
break
|
class RCToKRTBijectionTypeDTwisted(RCToKRTBijectionTypeD, RCToKRTBijectionTypeA2Even):
'\n Specific implementation of the bijection from rigged configurations to\n tensor products of KR tableaux for type `D_{n+1}^{(2)}`.\n '
def run(self, verbose=False, build_graph=False):
"\n Run the bijection from rigged configurations to tensor product of KR\n tableaux for type `D_{n+1}^{(2)}`.\n\n INPUT:\n\n - ``verbose`` -- (default: ``False``) display each step in the\n bijection\n - ``build_graph`` -- (default: ``False``) build the graph of each\n step of the bijection\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 2], [[3, 1]])\n sage: x = RC(partition_list=[[],[1],[1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D_twisted import RCToKRTBijectionTypeDTwisted\n sage: RCToKRTBijectionTypeDTwisted(x).run()\n [[1], [3], [-2]]\n sage: bij = RCToKRTBijectionTypeDTwisted(x)\n sage: bij.run(build_graph=True)\n [[1], [3], [-2]]\n sage: bij._graph\n Digraph on 6 vertices\n "
from sage.combinat.crystals.letters import CrystalOfLetters
letters = CrystalOfLetters(self.rigged_con.parent()._cartan_type.classical())
ret_crystal_path = []
for dim in self.rigged_con.parent().dims:
ret_crystal_path.append([])
for dummy_var in range(dim[1]):
if (self.cur_dims[0][1] > 1):
self.cur_dims[0][1] -= 1
self.cur_dims.insert(0, [dim[0], 1])
for a in range(self.n):
self._update_vacancy_numbers(a)
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), 'ls'])
if (dim[0] == self.n):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying doubling map')
self.doubling_map()
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), '2x'])
while (self.cur_dims[0][0] > 0):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions, use_vacancy_numbers=True)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
self.cur_dims[0][0] -= 1
b = self.next_state(self.cur_dims[0][0])
ret_crystal_path[(- 1)].append(letters(b))
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), letters(b)])
self.cur_dims.pop(0)
if (dim[0] == self.n):
if verbose:
print('====================')
print(repr(self.rigged_con.parent()(*self.cur_partitions)))
print('--------------------')
print(ret_crystal_path)
print('--------------------\n')
print('Applying halving map')
self.halving_map()
if build_graph:
y = self.rigged_con.parent()(*[x._clone() for x in self.cur_partitions], use_vacancy_numbers=True)
self._graph.append([self._graph[(- 1)][1], (y, len(self._graph)), '1/2x'])
if build_graph:
self._graph.pop(0)
from sage.graphs.digraph import DiGraph
from sage.graphs.dot2tex_utils import have_dot2tex
self._graph = DiGraph(self._graph)
if have_dot2tex():
self._graph.set_latex_options(format='dot2tex', edge_labels=True)
return self.KRT(pathlist=ret_crystal_path)
def next_state(self, height):
"\n Build the next state for type `D_{n+1}^{(2)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['D', 4, 2], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_D_twisted import RCToKRTBijectionTypeDTwisted\n sage: bijection = RCToKRTBijectionTypeDTwisted(RC(partition_list=[[2],[2,2],[2,2]]))\n sage: bijection.next_state(0)\n -1\n "
n = self.n
ell = ([None] * (2 * n))
case_S = ([False] * n)
case_Q = False
b = None
last_size = 0
for a in range(height, (n - 1)):
ell[a] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[a] is None):
b = (a + 1)
break
else:
last_size = self.cur_partitions[a][ell[a]]
if (b is None):
partition = self.cur_partitions[(n - 1)]
for i in reversed(range(len(partition))):
if (partition[i] >= last_size):
if (partition.vacancy_numbers[i] == partition.rigging[i]):
if (partition[i] == 1):
b = 'E'
else:
last_size = partition[i]
case_S[(n - 1)] = True
ell[((2 * n) - 1)] = i
break
elif (((partition.vacancy_numbers[i] - 1) == partition.rigging[i]) and (not case_Q)):
case_Q = True
block_size = partition[i]
for j in reversed(range(i)):
if (partition[j] != block_size):
break
elif (partition.vacancy_numbers[j] == partition.rigging[j]):
case_Q = False
break
if case_Q:
last_size = (partition[i] + 1)
ell[(n - 1)] = i
if (ell[((2 * n) - 1)] is None):
if (not case_Q):
b = n
else:
b = 0
if (b is None):
for a in reversed(range((n - 1))):
if ((a >= height) and (self.cur_partitions[a][ell[a]] == last_size)):
ell[(n + a)] = ell[a]
case_S[a] = True
else:
ell[(n + a)] = self._find_singular_string(self.cur_partitions[a], last_size)
if (ell[(n + a)] is None):
b = (- (a + 2))
break
else:
last_size = self.cur_partitions[a][ell[(n + a)]]
if (b is None):
b = (- 1)
if case_S[0]:
row_num = None
row_num_bar = self.cur_partitions[0].remove_cell(ell[n], 2)
else:
row_num = self.cur_partitions[0].remove_cell(ell[0])
row_num_bar = self.cur_partitions[0].remove_cell(ell[n])
for a in range(1, (n - 1)):
if case_S[a]:
row_num_next = None
row_num_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)], 2)
else:
row_num_next = self.cur_partitions[a].remove_cell(ell[a])
row_num_bar_next = self.cur_partitions[a].remove_cell(ell[(n + a)])
self._update_vacancy_numbers((a - 1))
if (row_num is not None):
self.cur_partitions[(a - 1)].rigging[row_num] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(a - 1)].rigging[row_num_bar] = self.cur_partitions[(a - 1)].vacancy_numbers[row_num_bar]
row_num = row_num_next
row_num_bar = row_num_bar_next
if case_Q:
row_num_next = self.cur_partitions[(n - 1)].remove_cell(ell[(n - 1)])
if case_S[(n - 1)]:
row_num_bar_next = self.cur_partitions[(n - 1)].remove_cell(ell[((2 * n) - 1)])
else:
row_num_bar_next = None
elif case_S[(n - 1)]:
row_num_next = None
row_num_bar_next = self.cur_partitions[(n - 1)].remove_cell(ell[((2 * n) - 1)], 2)
else:
row_num_next = None
row_num_bar_next = None
self._update_vacancy_numbers((n - 2))
if (row_num is not None):
self.cur_partitions[(n - 2)].rigging[row_num] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num]
if (row_num_bar is not None):
self.cur_partitions[(n - 2)].rigging[row_num_bar] = self.cur_partitions[(n - 2)].vacancy_numbers[row_num_bar]
self._update_vacancy_numbers((n - 1))
if (height == n):
self._correct_vacancy_nums()
if (row_num_next is not None):
self.cur_partitions[(n - 1)].rigging[row_num_next] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_next]
if (row_num_bar_next is not None):
if case_Q:
vac_num = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_bar_next]
self.cur_partitions[(n - 1)].rigging[row_num_bar_next] = vac_num
block_len = self.cur_partitions[(n - 1)][row_num_bar_next]
j = (row_num_bar_next + 1)
length = len(self.cur_partitions[(n - 1)])
while ((j < length) and (self.cur_partitions[(n - 1)][j] == block_len) and (self.cur_partitions[(n - 1)].rigging[j] == vac_num)):
j += 1
self.cur_partitions[(n - 1)].rigging[(j - 1)] = (vac_num - 1)
else:
self.cur_partitions[(n - 1)].rigging[row_num_bar_next] = self.cur_partitions[(n - 1)].vacancy_numbers[row_num_bar_next]
return b
|
class KRTToRCBijectionTypeE67(KRTToRCBijectionAbstract):
'\n Specific implementation of the bijection from KR tableaux to rigged\n configurations for type `E_{6,7}^{(1)}`.\n '
def next_state(self, val):
"\n Build the next state for type `E_{6,7}^{(1)}`.\n\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import KRTToRCBijectionTypeE67\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['E', 6, 1], [[3,1]])\n sage: bijection = KRTToRCBijectionTypeE67(KRT.module_generators[0])\n sage: bijection.cur_path.insert(0, [])\n sage: bijection.cur_dims.insert(0, [1, 1])\n sage: bijection.cur_path[0].insert(0, [(-3,4)])\n sage: bijection.next_state((-3,4))\n "
def find_singular_string(p, max_width):
max_pos = (- 1)
if (max_width > 0):
for (i, vac_num) in enumerate(p.vacancy_numbers):
if ((p[i] <= max_width) and (vac_num == p.rigging[i])):
max_pos = i
break
if (max_pos == (- 1)):
return 0
return p[max_pos]
b = self.tp_krt.parent().letters(val)
end = self._endpoint(self.cur_dims[0][0])
if (b == end):
for a in range(len(self.ret_rig_con)):
self._update_vacancy_nums(a)
return
max_width = (max(((nu[0] if nu else 0) for nu in self.ret_rig_con)) + 1)
found = True
while found:
found = False
data = [((- a), find_singular_string(self.ret_rig_con[((- a) - 1)], max_width)) for a in b.value if (a < 0)]
if (not data):
break
max_val = max((l for (a, l) in data))
for (a, l) in data:
if (l == max_val):
self.ret_rig_con[(a - 1)].insert_cell(max_width)
max_width = l
b = b.e(a)
found = (b != self._top)
break
for a in end.to_highest_weight()[1]:
p = self.ret_rig_con[(a - 1)]
for i in range((len(p) - 1), (- 1), (- 1)):
if (p.rigging[i] is None):
assert (p[i] == 1)
p._list.pop(i)
p.vacancy_numbers.pop(i)
p.rigging.pop(i)
break
for a in range(len(self.ret_rig_con)):
self._update_vacancy_nums(a)
self._update_partition_values(a)
def _next_index(self, r, target):
"\n Return the next index after ``r`` when performing a step\n in the bijection going towards ``target``.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['E', 6, 1], [[5,1]])\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import KRTToRCBijectionTypeE67\n sage: bijection = KRTToRCBijectionTypeE67(KRT.module_generators[0])\n sage: bijection._next_index(3, 5)\n 2\n sage: bijection._next_index(2, 5)\n 5\n sage: bijection._next_index(3, 4)\n 4\n sage: bijection._next_index(1, 5)\n 3\n sage: bijection._next_index(1, 4)\n 3\n sage: bijection._next_index(1, 6)\n 6\n "
if (self.tp_krt.cartan_type().classical().rank() == 6):
if (r == 0):
return 1
if (r == 1):
if (target == 6):
return 6
return 3
if (r == 3):
if (target == 4):
return 4
return 2
if (r == 2):
return 5
else:
if (r == 0):
return 7
if (r == 7):
if (target <= 3):
return 1
return 6
if (r <= 3):
return (r + 1)
return (r - 1)
@lazy_attribute
def _top(self):
"\n Return the highest weight element in the basic crystal used\n in the bijection ``self``.\n\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import KRTToRCBijectionTypeE67\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['E', 6, 1], [[3,1]])\n sage: bijection = KRTToRCBijectionTypeE67(KRT.module_generators[0])\n sage: bijection._top\n (1,)\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['E', 7, 1], [[6,1]])\n sage: bijection = KRTToRCBijectionTypeE67(KRT.module_generators[0])\n sage: bijection._top\n (7,)\n "
if (self.tp_krt.cartan_type().classical().rank() == 6):
return endpoint6(1)
else:
return endpoint7(7)
@cached_method
def _endpoint(self, r):
"\n Return the endpoint for the bijection in type `E_6^{(1)}`.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import KRTToRCBijectionTypeE67, endpoint6, endpoint7\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['E', 6, 1], [[3,1]])\n sage: bijection = KRTToRCBijectionTypeE67(KRT.module_generators[0])\n sage: all(bijection._endpoint(r) == endpoint6(r) for r in range(1,7))\n True\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['E', 7, 1], [[6,1]])\n sage: bijection = KRTToRCBijectionTypeE67(KRT.module_generators[0])\n sage: all(bijection._endpoint(r) == endpoint7(r) for r in range(1,8))\n True\n "
if (self.tp_krt.cartan_type().classical().rank() == 6):
return endpoint6(r)
else:
return endpoint7(r)
|
class RCToKRTBijectionTypeE67(RCToKRTBijectionAbstract):
'\n Specific implementation of the bijection from rigged configurations\n to tensor products of KR tableaux for type `E_{6,7}^{(1)}`.\n '
def next_state(self, r):
"\n Build the next state for type `E_{6,7}^{(1)}`.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['E', 6, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import RCToKRTBijectionTypeE67\n sage: bijection = RCToKRTBijectionTypeE67(RC(partition_list=[[1],[1,1],[1,1],[1,1,1],[1,1],[1]]))\n sage: bijection.next_state(1)\n (-2, 1)\n "
last_size = 0
found = True
b = self._endpoint(r)
while found:
found = False
data = [(a, self._find_singular_string(self.cur_partitions[(a - 1)], last_size)) for a in b.value if (a > 0)]
data = [(val, a, self.cur_partitions[(a - 1)][val]) for (a, val) in data if (val is not None)]
if (not data):
break
min_val = min((l for (i, a, l) in data))
for (i, a, l) in data:
if (l == min_val):
found = True
last_size = l
self.cur_partitions[(a - 1)].remove_cell(i)
b = b.f(a)
break
for (a, p) in enumerate(self.cur_partitions):
self._update_vacancy_numbers(a)
for i in range(len(p)):
if (p.rigging[i] is None):
p.rigging[i] = p.vacancy_numbers[i]
return b
def _next_index(self, r):
"\n Return the next index after ``r`` when performing a step\n in the bijection.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['E', 6, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import RCToKRTBijectionTypeE67\n sage: bijection = RCToKRTBijectionTypeE67(RC(partition_list=[[1],[1,1],[1,1],[1,1,1], [1,1],[1]]))\n sage: bijection._next_index(2)\n 3\n "
if (self.KRT.cartan_type().classical().rank() == 6):
if (r == 1):
return 0
if (r == 2):
return 3
if (r == 3):
return 1
if (r == 4):
return 3
if (r == 5):
return 2
if (r == 6):
return 1
else:
if (r == 1):
return 7
if (r == 7):
return 0
if (r <= 3):
return (r - 1)
return (r + 1)
@cached_method
def _endpoint(self, r):
"\n Return the endpoint for the bijection in type `E_{6,7}^{(1)}`.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import RCToKRTBijectionTypeE67, endpoint6, endpoint7\n sage: RC = RiggedConfigurations(['E', 6, 1], [[2, 1]])\n sage: bijection = RCToKRTBijectionTypeE67(RC(partition_list=[[1],[1,1],[1,1],[1,1,1], [1,1],[1]]))\n sage: all(bijection._endpoint(r) == endpoint6(r) for r in range(1,7))\n True\n sage: RC = RiggedConfigurations(['E', 7, 1], [[6, 1]])\n sage: bijection = RCToKRTBijectionTypeE67(RC(partition_list=[[1],[1,1],[1,1],[1,1],[1],[1],[]]))\n sage: all(bijection._endpoint(r) == endpoint7(r) for r in range(1,8))\n True\n "
if (self.KRT.cartan_type().classical().rank() == 6):
return endpoint6(r)
else:
return endpoint7(r)
|
def endpoint6(r):
'\n Return the endpoint for `B^{r,1}` in type `E_6^{(1)}`.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import endpoint6\n sage: endpoint6(1)\n (1,)\n sage: endpoint6(2)\n (-3, 2)\n sage: endpoint6(3)\n (-1, 3)\n sage: endpoint6(4)\n (-3, 4)\n sage: endpoint6(5)\n (-2, 5)\n sage: endpoint6(6)\n (-1, 6)\n '
C = CrystalOfLetters(['E', 6])
if (r == 1):
return C.module_generators[0]
elif (r == 2):
return C(((- 3), 2))
elif (r == 3):
return C(((- 1), 3))
elif (r == 4):
return C(((- 3), 4))
elif (r == 5):
return C(((- 2), 5))
elif (r == 6):
return C(((- 1), 6))
|
def endpoint7(r):
'\n Return the endpoint for `B^{r,1}` in type `E_7^{(1)}`.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.bij_type_E67 import endpoint7\n sage: endpoint7(1)\n (-7, 1)\n sage: endpoint7(2)\n (-1, 2)\n sage: endpoint7(3)\n (-2, 3)\n sage: endpoint7(4)\n (-5, 4)\n sage: endpoint7(5)\n (-6, 5)\n sage: endpoint7(6)\n (-7, 6)\n sage: endpoint7(7)\n (7,)\n '
C = CrystalOfLetters(['E', 7])
if (r == 1):
return C(((- 7), 1))
elif (r == 2):
return C(((- 1), 2))
elif (r == 3):
return C(((- 2), 3))
elif (r == 4):
return C(((- 5), 4))
elif (r == 5):
return C(((- 6), 5))
elif (r == 6):
return C(((- 7), 6))
elif (r == 7):
return C.module_generators[0]
|
def KRTToRCBijection(tp_krt):
"\n Return the correct KR tableaux to rigged configuration bijection helper class.\n\n TESTS::\n\n sage: KRT = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 4, 1], [[2,1]])\n sage: from sage.combinat.rigged_configurations.bijection import KRTToRCBijection\n sage: bijection = KRTToRCBijection(KRT(pathlist=[[5,2]]))\n "
ct = tp_krt.cartan_type()
typ = ct.type()
if ct.is_untwisted_affine():
if (typ == 'A'):
return KRTToRCBijectionTypeA(tp_krt)
if (typ == 'B'):
return KRTToRCBijectionTypeB(tp_krt)
if (typ == 'C'):
return KRTToRCBijectionTypeC(tp_krt)
if (typ == 'D'):
return KRTToRCBijectionTypeD(tp_krt)
if (typ == 'E'):
if (ct.classical().rank() < 8):
return KRTToRCBijectionTypeE67(tp_krt)
else:
if (typ == 'BC'):
return KRTToRCBijectionTypeA2Even(tp_krt)
typ = ct.dual().type()
if (typ == 'BC'):
return KRTToRCBijectionTypeA2Dual(tp_krt)
if (typ == 'B'):
return KRTToRCBijectionTypeA2Odd(tp_krt)
if (typ == 'C'):
return KRTToRCBijectionTypeDTwisted(tp_krt)
if (typ == 'G'):
return KRTToRCBijectionTypeDTri(tp_krt)
raise NotImplementedError
|
def RCToKRTBijection(rigged_configuration_elt):
"\n Return the correct rigged configuration to KR tableaux bijection helper class.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: from sage.combinat.rigged_configurations.bijection import RCToKRTBijection\n sage: bijection = RCToKRTBijection(RC(partition_list=[[1],[1],[1],[1]]))\n "
ct = rigged_configuration_elt.cartan_type()
typ = ct.type()
if ((not ct.is_affine()) or ct.is_untwisted_affine()):
if (typ == 'A'):
return RCToKRTBijectionTypeA(rigged_configuration_elt)
if (typ == 'B'):
return RCToKRTBijectionTypeB(rigged_configuration_elt)
if (typ == 'C'):
return RCToKRTBijectionTypeC(rigged_configuration_elt)
if (typ == 'D'):
return RCToKRTBijectionTypeD(rigged_configuration_elt)
if (typ == 'E'):
if (ct.classical().rank() < 8):
return RCToKRTBijectionTypeE67(rigged_configuration_elt)
else:
if (typ == 'BC'):
return RCToKRTBijectionTypeA2Even(rigged_configuration_elt)
typ = ct.dual().type()
if (typ == 'BC'):
return RCToKRTBijectionTypeA2Dual(rigged_configuration_elt)
if (typ == 'B'):
return RCToKRTBijectionTypeA2Odd(rigged_configuration_elt)
if (typ == 'C'):
return RCToKRTBijectionTypeDTwisted(rigged_configuration_elt)
if (typ == 'G'):
return RCToKRTBijectionTypeDTri(rigged_configuration_elt)
raise NotImplementedError
|
def _draw_tree(tree_node, node_label=True, style_point=None, style_node='fill=white', style_line=None, hspace=2.5, vspace=(- 2.5), start=None, rpos=None, node_id=0, node_prefix='T', edge_labels=True, use_vector_notation=False):
"\n Return the tikz latex for drawing the Kleber tree.\n\n AUTHORS:\n\n - Viviane Pons (2013-02-13): Initial version\n - Travis Scrimshaw (2013-03-02): Modified to work with Kleber tree output\n\n .. WARNING::\n\n Internal latex function.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A',3,1], [[3,2],[1,1]])\n sage: latex(KT) # indirect doctest\n \\begin{tikzpicture}\n \\node[fill=white] (T0) at (0.000, 0.000){$V_{\\omega_{1}+2\\omega_{3}}$};\n \\node (T00) at (0.000, -2.500){$V_{\\omega_{3}}$};\n \\draw (T0) to node[sloped,above]{\\tiny $\\alpha_{1} + \\alpha_{2} + \\alpha_{3}$} (T00);\n \\end{tikzpicture}\n "
if (start is None):
start = [0.0, 0.0]
if (rpos is None):
rpos = [0.0, 0.0]
draw_point = (lambda point: ('(%.3f, %.3f)' % (point[0], point[1])))
if (not tree_node.children):
r = ''
node_name = (node_prefix + str(node_id))
r = ('\\node (%s) at %s' % (node_name, draw_point(start)))
if node_label:
r += ('{$%s$};\n' % tree_node._latex_())
else:
r += '{};\n'
rpos[0] = start[0]
rpos[1] = start[1]
start[0] += hspace
return r
node_name = (node_prefix + str(node_id))
if (style_line is None):
style_line_str = ''
else:
style_line_str = ('[%s]' % style_line)
if node_label:
node_place_str = ''
else:
node_place_str = '.center'
nb_children = len(tree_node.children)
half = (nb_children // 2)
children_str = ''
pos = [start[0], start[1]]
start[1] += vspace
lines_str = ''
for i in range(nb_children):
if ((i == half) and ((nb_children % 2) == 0)):
pos[0] = start[0]
start[0] += hspace
if ((i == (half + 1)) and ((nb_children % 2) == 1)):
pos[0] = rpos[0]
child = tree_node.children[i]
children_str += _draw_tree(child, node_label=node_label, style_node=style_node, style_point=style_point, style_line=style_line, hspace=hspace, vspace=vspace, start=start, rpos=rpos, node_id=i, node_prefix=node_name, edge_labels=edge_labels, use_vector_notation=use_vector_notation)
if edge_labels:
if use_vector_notation:
edge_str = latex(child.up_root.to_vector())
else:
edge_str = latex(child.up_root)
lines_str += ('\\draw%s (%s%s) to node[sloped,above]{\\tiny $%s$} (%s%s%s);\n' % (style_line_str, node_name, node_place_str, edge_str, node_name, i, node_place_str))
else:
lines_str += ('\\draw%s (%s%s) -- (%s%s%s);\n' % (style_line_str, node_name, node_place_str, node_name, i, node_place_str))
if (style_node is None):
style_node = ''
else:
style_node = ('[%s]' % style_node)
if (style_point is None):
style_point = ''
else:
style_point = ('[%s]' % style_point)
start[1] -= vspace
rpos[0] = pos[0]
rpos[1] = pos[1]
point_str = ''
node_str = ('\\node%s (%s) at %s' % (style_node, node_name, draw_point(pos)))
if node_label:
node_str += ('{$%s$};\n' % tree_node._latex_())
else:
node_str += '{};\n'
point_str = ('\\draw%s (%s) circle;\n' % (style_point, node_name))
res = node_str
res += children_str
res += lines_str
res += point_str
return res
|
class KleberTreeNode(Element):
"\n A node in the Kleber tree.\n\n This class is meant to be used internally by the Kleber tree class and\n should not be created directly by the user.\n\n For more on the Kleber tree and the nodes, see :class:`KleberTree`.\n\n The dominating root is the ``up_root`` which is the difference\n between the parent node's weight and this node's weight.\n\n INPUT:\n\n - ``parent_obj`` -- The parent object of this element\n - ``node_weight`` -- The weight of this node\n - ``dominant_root`` -- The dominating root\n - ``parent_node`` -- (default:None) The parent node of this node\n "
def __init__(self, parent_obj, node_weight, dominant_root, parent_node=None):
"\n Initialize the tree node.\n\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: RS = RootSystem(['A', 2])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = KleberTree(['A', 2, 1], [[1,1]])\n sage: parent = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero())\n sage: parent\n Kleber tree node with weight [5, 2] and upwards edge root [0, 0]\n sage: parent.parent_node\n sage: child = KT(WS.sum_of_terms([(1,3), (2,1)]), R.sum_of_terms([(1,1), (2,2)]), parent)\n sage: child\n Kleber tree node with weight [3, 1] and upwards edge root [1, 2]\n sage: child.parent_node\n Kleber tree node with weight [5, 2] and upwards edge root [0, 0]\n sage: TestSuite(parent).run()\n "
self.parent_node = parent_node
self.children = []
self.weight = node_weight
self.up_root = dominant_root
Element.__init__(self, parent_obj)
@lazy_attribute
def depth(self):
"\n Return the depth of this node in the tree.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: RS = RootSystem(['A', 2])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = KleberTree(['A', 2, 1], [[1,1]])\n sage: n = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero())\n sage: n.depth\n 0\n sage: n2 = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero(), n)\n sage: n2.depth\n 1\n "
depth = (- 1)
cur = self
while (cur is not None):
depth += 1
cur = cur.parent_node
return depth
@cached_method
def multiplicity(self):
"\n Return the multiplicity of ``self``.\n\n The multiplicity of a node `x` of depth `d` weight `\\lambda` in a\n simply-laced Kleber tree is equal to:\n\n .. MATH::\n\n \\prod_{i > 0} \\prod_{a \\in \\overline{I}}\n \\binom{p_i^{(a)} + m_i^{(a)}}{p_i^{(a)}}\n\n Recall that\n\n .. MATH::\n\n m_i^{(a)} = \\left( \\lambda^{(i-1)} - 2 \\lambda^{(i)} +\n \\lambda^{(i+1)} \\mid \\overline{\\Lambda}_a \\right),\n\n p_i^{(a)} = \\left( \\alpha_a \\mid \\lambda^{(i)} \\right)\n - \\sum_{j > i} (j - i) L_j^{(a)},\n\n where `\\lambda^{(i)}` is the weight node at depth `i` in the path\n to `x` from the root and we set `\\lambda^{(j)} = \\lambda` for all\n `j \\geq d`.\n\n Note that `m_i^{(a)} = 0` for all `i > d`.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A',3,1], [[3,2],[2,1],[1,1],[1,1]])\n sage: for x in KT: x, x.multiplicity()\n (Kleber tree node with weight [2, 1, 2] and upwards edge root [0, 0, 0], 1)\n (Kleber tree node with weight [3, 0, 1] and upwards edge root [0, 1, 1], 1)\n (Kleber tree node with weight [0, 2, 2] and upwards edge root [1, 0, 0], 1)\n (Kleber tree node with weight [1, 0, 3] and upwards edge root [1, 1, 0], 2)\n (Kleber tree node with weight [1, 1, 1] and upwards edge root [1, 1, 1], 4)\n (Kleber tree node with weight [0, 0, 2] and upwards edge root [2, 2, 1], 2)\n (Kleber tree node with weight [2, 0, 0] and upwards edge root [0, 1, 1], 2)\n (Kleber tree node with weight [0, 0, 2] and upwards edge root [1, 1, 0], 1)\n (Kleber tree node with weight [0, 1, 0] and upwards edge root [1, 1, 1], 2)\n (Kleber tree node with weight [0, 1, 0] and upwards edge root [0, 0, 1], 1)\n\n TESTS:\n\n We check that :trac:`16057` is fixed::\n\n sage: RC = RiggedConfigurations(['D',4,1], [[1,3],[3,3],[4,3]])\n sage: sum(x.multiplicity() for x in RC.kleber_tree()) == len(RC.module_generators)\n True\n "
if (self.parent_node is None):
return Integer(1)
mult = Integer(1)
for (a, m) in self.up_root:
p = self.weight[a]
for (r, s) in self.parent().B:
if ((r == a) and (s > self.depth)):
p -= (s - self.depth)
mult *= binomial((m + p), m)
prev_up_root = self.up_root
cur = self.parent_node
while (cur.parent_node is not None):
root_diff = (cur.up_root - prev_up_root)
for (a, m) in root_diff:
p = cur.weight[a]
for (r, s) in self.parent().B:
if ((r == a) and (s > cur.depth)):
p -= (s - cur.depth)
mult *= binomial((m + p), m)
prev_up_root = cur.up_root
cur = cur.parent_node
return mult
def __hash__(self):
"\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: RS = RootSystem(['A', 2])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = KleberTree(['A', 2, 1], [[1,1]])\n sage: n = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero())\n sage: n2 = KT(WS.sum_of_terms([(2,2), (1,5)]), R.zero())\n sage: hash(n) == hash(n2)\n True\n sage: hash(n) == hash(R.zero())\n False\n "
return (hash(self.depth) ^ hash(self.weight))
def _richcmp_(self, rhs, op):
"\n Check whether two nodes are equal.\n\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: RS = RootSystem(['A', 2])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = KleberTree(['A', 2, 1], [[1,1]])\n sage: n = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero())\n sage: n2 = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero(), n)\n sage: n2 > n\n True\n sage: n3 = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero(), n)\n sage: n2 == n3\n True\n sage: n3 = KT(WS.sum_of_terms([(1,5), (2,3)]), R.zero(), n)\n sage: n2 < n3\n True\n "
lx = self.depth
rx = rhs.depth
if (lx != rx):
return richcmp_not_equal(lx, rx, op)
lx = self.parent_node
rx = rhs.parent_node
if (lx != rx):
return richcmp_not_equal(lx, rx, op)
return richcmp(self.weight, rhs.weight, op)
def _repr_(self):
"\n Return the string representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: RS = RootSystem(['A', 3])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = KleberTree(['A', 2, 1], [[1,1]])\n sage: node = KT(WS.sum_of_terms([(1,2), (2,1), (3,1)]), R.sum_of_terms([(1,3), (3,3)])); node\n Kleber tree node with weight [2, 1, 1] and upwards edge root [3, 0, 3]\n\n With virtual nodes::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['A',6,2], [[2,2]])\n sage: KT.root\n Kleber tree node with weight [0, 2, 0, 2, 0] and upwards edge root [0, 0, 0, 0, 0]\n "
return ('Kleber tree node with weight %s and upwards edge root %s' % (list(self.weight.to_vector()), list(self.up_root.to_vector())))
def _latex_(self):
"\n Return latex representation of ``self``.\n\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: RS = RootSystem(['A', 3])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = KleberTree(['A', 3, 1], [[3,2], [1,1]])\n sage: node = KT(WS.sum_of_terms([(1,4), (3,1)]), R.zero())\n sage: latex(node)\n V_{4\\omega_{1}+\\omega_{3}}\n sage: node = KT(WS.zero(), R.zero())\n sage: latex(node)\n V_{0}\n sage: node = KT(WS.sum_of_terms([(1,2)]), R.zero())\n sage: latex(node)\n V_{2\\omega_{1}}\n\n With virtual nodes::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['C',3,1], [[2,2]])\n sage: latex(KT.root)\n [V_{2\\omega_{2}+2\\omega_{4}}]\n sage: KT = VirtualKleberTree(['A',6,2], [[2,2]])\n sage: latex(KT.root)\n [V_{2\\omega_{2}+2\\omega_{4}}]\n "
ret_str = 'V_{'
if (self.multiplicity() != 1):
ret_str = (repr(self.multiplicity()) + ret_str)
for pair in self.weight:
if (pair[1] > 1):
ret_str += (((repr(pair[1]) + '\\omega_{') + repr(pair[0])) + '}+')
elif (pair[1] == 1):
ret_str += (('\\omega_{' + repr(pair[0])) + '}+')
if (ret_str[(- 1)] == '{'):
ret_str += '0}'
else:
ret_str = (ret_str[:(- 1)] + '}')
ct = self.parent()._cartan_type
if ((ct.type() == 'BC') or (ct.dual().type() == 'BC')):
return (('[' + ret_str) + ']')
elif (not ct.is_simply_laced()):
s_factors = self.parent()._folded_ct.scaling_factors()
gamma = max(s_factors)
if (gamma > 1):
L = [self.parent()._folded_ct.folding_orbit()[a][0] for a in range(1, len(s_factors)) if (s_factors[a] == gamma)]
else:
L = []
if (((self.depth % gamma) == 0) or all(((self.up_root[a] == 0) for a in L))):
return (('[' + ret_str) + ']')
return ret_str
|
class KleberTree(UniqueRepresentation, Parent):
"\n The tree that is generated by Kleber's algorithm.\n\n A Kleber tree is a tree of weights generated by Kleber's algorithm\n [Kleber1]_. It is used to generate the set of all admissible rigged\n configurations for the simply-laced affine types `A_n^{(1)}`,\n `D_n^{(1)}`, `E_6^{(1)}`, `E_7^{(1)}`, and `E_8^{(1)}`.\n\n .. SEEALSO::\n\n There is a modified version for non-simply-laced affine types at\n :class:`VirtualKleberTree`.\n\n The nodes correspond to the weights in the positive Weyl chamber obtained\n by subtracting a (non-zero) positive root. The edges are labeled by the\n coefficients of the roots, and `X` is a child of `Y` if `Y` is the root\n else if the edge label of `Y` to its parent `Z` is greater (in every\n component) than the label from `X` to `Y`.\n\n For a Kleber tree, one needs to specify an affine (simply-laced)\n Cartan type and a sequence of pairs `(r,s)`, where `s` is any positive\n integer and `r` is a node in the Dynkin diagram. Each `(r,s)` can be\n viewed as a rectangle of width `s` and height `r`.\n\n INPUT:\n\n - ``cartan_type`` -- an affine simply-laced Cartan type\n\n - ``B`` -- a list of dimensions of rectangles by `[r, c]`\n where `r` is the number of rows and `c` is the number of columns\n\n REFERENCES:\n\n .. [Kleber1] Michael Kleber.\n *Combinatorial structure of finite dimensional representations of\n Yangians: the simply-laced case*.\n Internat. Math. Res. Notices. (1997) no. 4. 187-201.\n\n .. [Kleber2] Michael Kleber.\n *Finite dimensional representations of quantum affine algebras*.\n Ph.D. dissertation at University of California Berkeley. (1998).\n :arxiv:`math.QA/9809087`.\n\n EXAMPLES:\n\n Simply-laced example::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A', 3, 1], [[3,2], [1,1]])\n sage: KT.list()\n [Kleber tree node with weight [1, 0, 2] and upwards edge root [0, 0, 0],\n Kleber tree node with weight [0, 0, 1] and upwards edge root [1, 1, 1]]\n sage: KT = KleberTree(['A', 3, 1], [[3,2], [2,1], [1,1], [1,1]])\n sage: KT.cardinality()\n 10\n sage: KT = KleberTree(['D', 4, 1], [[2,2]])\n sage: KT.cardinality()\n 3\n sage: KT = KleberTree(['D', 4, 1], [[4,5]])\n sage: KT.cardinality()\n 1\n\n From [Kleber2]_::\n\n sage: KT = KleberTree(['E', 6, 1], [[4, 2]]) # long time (9s on sage.math, 2012)\n sage: KT.cardinality() # long time\n 12\n\n We check that relabelled types work (:trac:`16876`)::\n\n sage: ct = CartanType(['A',3,1]).relabel(lambda x: x+2)\n sage: kt = KleberTree(ct, [[3,1],[5,1]])\n sage: list(kt)\n [Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 0, 0],\n Kleber tree node with weight [0, 0, 0] and upwards edge root [1, 1, 1]]\n sage: kt = KleberTree(['A',3,1], [[1,1],[3,1]])\n sage: list(kt)\n [Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 0, 0],\n Kleber tree node with weight [0, 0, 0] and upwards edge root [1, 1, 1]]\n "
@staticmethod
def __classcall_private__(cls, cartan_type, B, classical=None):
"\n Normalize the input arguments to ensure unique representation.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT1 = KleberTree(CartanType(['A',3,1]), [[2,2]])\n sage: KT2 = KleberTree(['A',3,1], [(2,2)])\n sage: KT3 = KleberTree(['A',3,1], ((2,2),))\n sage: KT2 is KT1, KT3 is KT1\n (True, True)\n "
cartan_type = CartanType(cartan_type)
if (not cartan_type.is_affine()):
raise ValueError('The Cartan type must be affine')
if (not cartan_type.classical().is_simply_laced()):
raise ValueError('use VirtualKleberTree for non-simply-laced types')
B = tuple([tuple(rs) for rs in B])
if (classical is None):
classical = cartan_type.classical()
else:
classical = CartanType(classical)
return super().__classcall__(cls, cartan_type, B, classical)
def __init__(self, cartan_type, B, classical_ct):
'\n Construct a Kleber tree.\n\n The input ``classical_ct`` is the classical Cartan type to run the\n algorithm on and is only meant to be used internally.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree([\'D\', 3, 1], [[1,1], [1,1]]); KT\n Kleber tree of Cartan type [\'D\', 3, 1] and B = ((1, 1), (1, 1))\n sage: TestSuite(KT).run(skip="_test_elements")\n '
Parent.__init__(self, category=FiniteEnumeratedSets())
self._cartan_type = cartan_type
self.B = B
self._classical_ct = classical_ct
self._CM = self._classical_ct.cartan_matrix().dense_matrix()
self._build_tree()
self._latex_options = dict(edge_labels=True, use_vector_notation=False, hspace=2.5, vspace=min((- 2.5), ((- 0.75) * self._classical_ct.rank())))
def latex_options(self, **options):
"\n Return the current latex options if no arguments are passed, otherwise\n set the corresponding latex option.\n\n OPTIONS:\n\n - ``hspace`` -- (default: `2.5`) the horizontal spacing of the\n tree nodes\n - ``vspace`` -- (default: ``x``) the vertical spacing of the tree\n nodes, here ``x`` is the minimum of `-2.5` or `-.75n` where `n` is\n the rank of the classical type\n - ``edge_labels`` -- (default: ``True``) display edge labels\n - ``use_vector_notation`` -- (default: ``False``) display edge labels\n using vector notation instead of a linear combination\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['D', 3, 1], [[2,1], [2,1]])\n sage: KT.latex_options(vspace=-4, use_vector_notation=True)\n sage: sorted(KT.latex_options().items())\n [('edge_labels', True), ('hspace', 2.5), ('use_vector_notation', True), ('vspace', -4)]\n "
if (not options):
from copy import copy
return copy(self._latex_options)
for k in options:
self._latex_options[k] = options[k]
def _latex_(self):
"\n Return a latex representation of this Kleber tree.\n\n .. SEEALSO::\n\n :meth:`latex_options()`\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['D', 3, 1], [[2,1], [2,1]])\n sage: KT._latex_()\n '\\\\begin{tikzpicture}...\\\\end{tikzpicture}'\n "
from sage.graphs.graph_latex import setup_latex_preamble
setup_latex_preamble()
return (('\\begin{tikzpicture}\n' + _draw_tree(self.root, **self._latex_options)) + '\\end{tikzpicture}')
def _build_tree(self):
"\n Build the Kleber tree.\n\n TESTS:\n\n This is called from the constructor::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A',3,1], [[2,2]]) # indirect doctest\n "
P = self._classical_ct.root_system().weight_lattice()
self.root = KleberTreeNode(self, P.zero(), self._classical_ct.root_system().root_lattice().zero())
full_list = [self.root]
n = self._classical_ct.rank()
L = []
I = self._classical_ct.index_set()
for i in range(n):
L.append([0])
for (r, s) in self.B:
while (len(L[0]) < s):
for row in L:
row.append(0)
L[I.index(r)][(s - 1)] += 1
weight_basis = P.basis()
for a in range(n):
self.root.weight += (sum(L[a]) * weight_basis[I[a]])
new_children = []
for new_child in self._children_iter(self.root):
if (not self._prune(new_child, 1)):
new_children.append(new_child)
self.root.children.append(new_child)
full_list.append(new_child)
depth = 1
growth = True
if ((self._classical_ct.rank() >= 7) or self._has_normaliz):
child_itr = self._children_iter
else:
child_itr = self._children_iter_vector
while growth:
growth = False
depth += 1
leaves = new_children
if (depth <= len(L[0])):
new_children = []
for x in full_list:
growth = True
for a in range(n):
for i in range((depth - 1), len(L[a])):
x.weight += (L[a][i] * weight_basis[I[a]])
new_children = [new_child for x in leaves for new_child in child_itr(x) if (not self._prune(new_child, depth))]
if new_children:
growth = True
for new_child in new_children:
new_child.parent_node.children.append(new_child)
full_list.append(new_child)
self._set = full_list
def _children_iter(self, node):
"\n Iterate over the children of ``node``.\n\n Helper iterator to iterate over all children, by generating and/or\n computing them, of the Kleber tree node.\n\n We compute the children by computing integral points (expressed as\n simple roots) in the polytope given by the intersection of the\n negative root cone and shifted positive weight cone. More precisely,\n we rewrite the condition `\\lambda - \\mu \\in Q^+`, for `\\mu \\in P^+`,\n as `\\lambda - Q^+ = \\mu \\in P^+`.\n\n INPUT:\n\n - ``node`` -- the current node in the tree whose children we want\n to generate\n\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['D', 3, 1], [[1,1], [1,1]])\n sage: for x in KT: x # indirect doctest\n Kleber tree node with weight [2, 0, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [0, 1, 1] and upwards edge root [1, 0, 0]\n Kleber tree node with weight [0, 0, 0] and upwards edge root [2, 1, 1]\n\n sage: KT = KleberTree(['D', 4, 1], [[2,2]])\n sage: KT[1]\n Kleber tree node with weight [0, 1, 0, 0] and upwards edge root [1, 2, 1, 1]\n sage: for x in KT: x\n Kleber tree node with weight [0, 2, 0, 0] and upwards edge root [0, 0, 0, 0]\n Kleber tree node with weight [0, 1, 0, 0] and upwards edge root [1, 2, 1, 1]\n Kleber tree node with weight [0, 0, 0, 0] and upwards edge root [1, 2, 1, 1]\n sage: for x in KT._children_iter(KT[1]): x\n Kleber tree node with weight [0, 0, 0, 0] and upwards edge root [1, 2, 1, 1]\n "
if ((node != self.root) and (prod(((val + 1) for val in node.up_root.coefficients())) < 1000)):
(yield from self._children_iter_vector(node))
return
n = self._classical_ct.rank()
I = self._classical_ct.index_set()
Q = self._classical_ct.root_system().root_lattice()
P = self._classical_ct.root_system().weight_lattice()
from sage.geometry.polyhedron.constructor import Polyhedron
root_weight = node.weight.to_vector()
ieqs = [([root_weight[i]] + list(col)) for (i, col) in enumerate(self._CM.columns())]
for i in range(n):
v = ([0] * (n + 1))
v[(i + 1)] = (- 1)
ieqs.append(v)
ieqs.append(([(- 1)] * (n + 1)))
if (node != self.root):
for (i, c) in enumerate(node.up_root.to_vector()):
v = ([0] * (n + 1))
v[0] = c
v[(i + 1)] = 1
ieqs.append(v)
try:
poly = Polyhedron(ieqs=ieqs, backend='normaliz')
self._has_normaliz = True
except FeatureNotPresentError:
poly = Polyhedron(ieqs=ieqs)
self._has_normaliz = False
for pt in sorted(poly.integral_points(), reverse=True):
up_root = Q._from_dict({I[i]: (- val) for (i, val) in enumerate(pt) if (val != 0)}, remove_zeros=False)
wt = (node.weight + sum(((val * P.simple_root(I[i])) for (i, val) in enumerate(pt))))
(yield KleberTreeNode(self, wt, up_root, node))
def _children_iter_vector(self, node):
"\n Iterate over the children of ``node``.\n\n Helper iterator to iterate over all children, by generating and/or\n computing them, of the Kleber tree node. This implementation\n iterates over all possible uproot vectors.\n\n .. SEEALSO::\n\n :meth:`_children_iter`\n\n INPUT:\n\n - ``node`` -- the current node in the tree whose children we want\n to generate\n\n TESTS::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['D', 4, 1], [[2,2]])\n sage: KT[1]\n Kleber tree node with weight [0, 1, 0, 0] and upwards edge root [1, 2, 1, 1]\n sage: for x in KT._children_iter(KT[1]): x\n Kleber tree node with weight [0, 0, 0, 0] and upwards edge root [1, 2, 1, 1]\n "
Q = self._classical_ct.root_system().root_lattice()
P = self._classical_ct.root_system().weight_lattice()
I = self._classical_ct.index_set()
wt = node.weight.to_vector()
cols = self._CM.columns()
L = [range((val + 1)) for val in node.up_root.to_vector()]
it = itertools.product(*L)
next(it)
for root in it:
converted_root = sum(((cols[i] * c) for (i, c) in enumerate(root) if (c != 0)))
if all(((wt[i] >= val) for (i, val) in enumerate(converted_root))):
wd = {I[i]: (wt[i] - val) for (i, val) in enumerate(converted_root)}
rd = {I[i]: val for (i, val) in enumerate(root) if (val != 0)}
(yield KleberTreeNode(self, P._from_dict(wd), Q._from_dict(rd, remove_zeros=False), node))
def _prune(self, new_child, depth):
"\n Return ``True`` if we are to prune the tree at ``new_child``.\n\n This always returns ``False`` since we do not do any pruning.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A', 2, 1], [[1,1]])\n sage: KT._prune(KT.root, 0)\n False\n "
return False
def breadth_first_iter(self):
"\n Iterate over all nodes in the tree following a breadth-first traversal.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A', 3, 1], [[2, 2], [2, 3]])\n sage: for x in KT.breadth_first_iter(): x\n Kleber tree node with weight [0, 5, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 3, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 3, 0] and upwards edge root [1, 2, 1]\n Kleber tree node with weight [2, 1, 2] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [1, 1, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 1, 0] and upwards edge root [1, 2, 1]\n "
cur = []
next = [self.root]
while next:
cur = next
next = []
for node in cur:
(yield node)
next.extend(node.children)
def depth_first_iter(self):
"\n Iterate (recursively) over the nodes in the tree following a\n depth-first traversal.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A', 3, 1], [[2, 2], [2, 3]])\n sage: for x in KT.depth_first_iter(): x\n Kleber tree node with weight [0, 5, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 3, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [2, 1, 2] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 3, 0] and upwards edge root [1, 2, 1]\n Kleber tree node with weight [1, 1, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 1, 0] and upwards edge root [1, 2, 1]\n "
return self._depth_first_iter(None)
def _depth_first_iter(self, cur):
"\n Helper recursive function used in depth-first iteration.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A', 3, 1], [[2, 2], [2, 3]])\n sage: for x in KT._depth_first_iter(None): x\n Kleber tree node with weight [0, 5, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 3, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [2, 1, 2] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 3, 0] and upwards edge root [1, 2, 1]\n Kleber tree node with weight [1, 1, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 1, 0] and upwards edge root [1, 2, 1]\n "
if (cur is None):
cur = self.root
(yield cur)
for child in cur.children:
(yield from self._depth_first_iter(child))
__iter__ = breadth_first_iter
def _repr_(self):
"\n Return a text representation of this Kleber tree.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KleberTree(['D', 4, 1], [[2, 2]]) # indirect doctest\n Kleber tree of Cartan type ['D', 4, 1] and B = ((2, 2),)\n "
return ('Kleber tree of Cartan type %s and B = %s' % (repr(self._cartan_type), self.B))
def cartan_type(self):
"\n Return the Cartan type of this Kleber tree.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['A', 3, 1], [[1,1]])\n sage: KT.cartan_type()\n ['A', 3, 1]\n "
return self._cartan_type
def digraph(self):
"\n Return a DiGraph representation of this Kleber tree.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['D', 4, 1], [[2, 2]])\n sage: KT.digraph()\n Digraph on 3 vertices\n "
d = {}
for x in self.breadth_first_iter():
d[x] = {}
if (x.parent_node is None):
continue
d[x][x.parent_node] = tuple(x.up_root.to_vector())
G = DiGraph(d)
if have_dot2tex():
G.set_latex_options(format='dot2tex', edge_labels=True)
return G
def plot(self, **options):
"\n Return the plot of self as a directed graph.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: KT = KleberTree(['D', 4, 1], [[2, 2]])\n sage: print(KT.plot()) # needs sage.plot\n Graphics object consisting of 8 graphics primitives\n "
return self.digraph().plot(edge_labels=True, vertex_size=0, **options)
def _element_constructor_(self, node_weight, dominant_root, parent_node=None):
"\n Construct a Kleber tree node.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree\n sage: RS = RootSystem(['A', 2])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = KleberTree(['A', 2, 1], [[1,1]])\n sage: root = KT(WS.sum_of_terms([(1,5), (2,2)]), R.zero()); root # indirect doctest\n Kleber tree node with weight [5, 2] and upwards edge root [0, 0]\n sage: child = KT(WS.sum_of_terms([(1,5), (2,1)]), R.zero(), root); child # indirect doctest\n Kleber tree node with weight [5, 1] and upwards edge root [0, 0]\n sage: child.parent_node\n Kleber tree node with weight [5, 2] and upwards edge root [0, 0]\n "
return self.element_class(self, node_weight, dominant_root, parent_node)
Element = KleberTreeNode
|
class VirtualKleberTree(KleberTree):
"\n A virtual Kleber tree.\n\n We can use a modified version of the Kleber algorithm called the virtual\n Kleber algorithm [OSS03]_ to compute all admissible rigged configurations\n for non-simply-laced types. This uses the following embeddings\n into the simply-laced types:\n\n .. MATH::\n\n C_n^{(1)}, A_{2n}^{(2)}, A_{2n}^{(2)\\dagger}, D_{n+1}^{(2)}\n \\hookrightarrow A_{2n-1}^{(1)}\n\n A_{2n-1}^{(2)}, B_n^{(1)} \\hookrightarrow D_{n+1}^{(1)}\n\n E_6^{(2)}, F_4^{(1)} \\hookrightarrow E_6^{(1)}\n\n D_4^{(3)}, G_2^{(1)} \\hookrightarrow D_4^{(1)}\n\n One then selects the subset of admissible nodes which are translates of\n the virtual requirements. In the graph, the selected nodes are indicated\n by brackets `[]`.\n\n .. NOTE::\n\n Because these are virtual nodes, all information is given\n in the corresponding simply-laced type.\n\n .. SEEALSO::\n\n For more on the Kleber algorithm, see :class:`KleberTree`.\n\n REFERENCES:\n\n .. [OSS03] Masato Okado, Anne Schilling, and Mark Shimozono.\n *Virtual crystals and Klebers algorithm*. Commun. Math. Phys. **238**\n (2003). 187-209. :arxiv:`math.QA/0209082`.\n\n INPUT:\n\n - ``cartan_type`` -- an affine non-simply-laced Cartan type\n\n - ``B`` -- a list of dimensions of rectangles by `[r, c]`\n where `r` is the number of rows and `c` is the number of columns\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['C', 4, 1], [[2,2]])\n sage: KT.cardinality()\n 3\n sage: KT.base_tree().cardinality()\n 6\n sage: KT = VirtualKleberTree(['C', 4, 1], [[4,5]])\n sage: KT.cardinality()\n 1\n sage: KT = VirtualKleberTree(['D', 5, 2], [[2,1], [1,1]])\n sage: KT.cardinality()\n 8\n sage: KT = VirtualKleberTree(CartanType(['A', 4, 2]).dual(), [[1,1], [2,2]])\n sage: KT.cardinality()\n 15\n "
@staticmethod
def __classcall_private__(cls, cartan_type, B):
"\n Normalize the input arguments to ensure unique representation.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT1 = VirtualKleberTree(CartanType(['C',3,1]).as_folding(), [[2,2]])\n sage: KT2 = VirtualKleberTree(CartanType(['C',3,1]), [(2,2)])\n sage: KT3 = VirtualKleberTree(['C',3,1], ((2,2),))\n sage: KT2 is KT1, KT3 is KT1\n (True, True)\n "
cartan_type = CartanType(cartan_type)
B = tuple(map(tuple, B))
if ((cartan_type.type() == 'BC') or (cartan_type.dual().type() == 'BC')):
return KleberTreeTypeA2Even(cartan_type, B)
if cartan_type.classical().is_simply_laced():
raise ValueError('use KleberTree for simply-laced types')
return super().__classcall__(cls, cartan_type, B)
def __init__(self, cartan_type, B):
'\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree([\'C\',4,1], [[2,2]])\n sage: TestSuite(KT).run(skip="_test_elements")\n '
self._folded_ct = cartan_type.as_folding()
virtual_dims = []
self.base_dims = B
sigma = self._folded_ct.folding_orbit()
gamma = self._folded_ct.scaling_factors()
classical_ct = self._folded_ct.folding_of().classical()
for (r, s) in B:
for i in sigma[r]:
virtual_dims.append([i, (s * gamma[r])])
KleberTree.__init__(self, cartan_type, virtual_dims, classical_ct)
def _repr_(self):
"\n Return a text representation of this Kleber tree.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: VirtualKleberTree(['C', 4, 1], [[2, 2]])\n Virtual Kleber tree of Cartan type ['C', 4, 1] and B = ((2, 2),)\n "
return ('Virtual Kleber tree of Cartan type %s and B = %s' % (repr(self._cartan_type), self.base_dims))
def _prune(self, new_child, depth):
"\n Return ``True`` if we are to prune the tree at ``new_child``.\n\n Suppose `\\lambda` is the weight of the child we want to add at depth\n `\\ell`. We prune ``new_child`` if either of the following conditions\n are not satisfied:\n\n 1. `(\\lambda \\mid \\alpha_a) = (\\lambda \\mid \\alpha_b)` if `a` and `b`\n are in the same `\\sigma`-orbit.\n 2. If `\\ell - 1 \\notin \\gamma_a \\ZZ`, then the `a`-th component of\n ``up_root`` of ``new_child`` must equal the `a`-th component of\n ``up_root`` of its ``parent_node``. Note that from condition 1,\n we only need to check one such `a` from each `\\sigma`-orbit.\n\n These conditions are equivalent to Definition 4.1 in [OSS03]_.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: RS = RootSystem(['A', 3])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = VirtualKleberTree(['C',2,1], [[1,2],[1,1],[2,1]])\n sage: x = KT(WS.sum_of_terms([(1,1), (2,1), (3,3)]), R.sum_of_terms([(1,2),(2,2),(3,1)]), KT.root)\n sage: KT._prune(x, 1)\n True\n "
sigma = self._folded_ct._orbit
for orbit in sigma[1:]:
start = new_child.weight[orbit[0]]
if any(((new_child.weight[i] != start) for i in orbit[1:])):
return True
gamma = self._folded_ct.scaling_factors()
for a in range(1, len(gamma)):
if ((((depth - 1) % gamma[a]) != 0) and (new_child.up_root[sigma[a][0]] != new_child.parent_node.up_root[sigma[a][0]])):
return True
return False
def breadth_first_iter(self, all_nodes=False):
"\n Iterate over all nodes in the tree following a breadth-first traversal.\n\n INPUT:\n\n - ``all_nodes`` -- (default: ``False``) if ``True``, output all\n nodes in the tree\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['C', 2, 1], [[1,1], [2,1]])\n sage: for x in KT.breadth_first_iter(): x\n Kleber tree node with weight [1, 2, 1] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n sage: for x in KT.breadth_first_iter(True): x\n Kleber tree node with weight [1, 2, 1] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [0, 2, 0] and upwards edge root [1, 1, 1]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n "
s_factors = self._folded_ct.scaling_factors()
gamma = max(s_factors)
if (gamma > 1):
sigma = self._folded_ct.folding_orbit()
L = [sigma[a][0] for a in range(1, len(s_factors)) if (s_factors[a] == gamma)]
else:
L = []
for x in KleberTree.breadth_first_iter(self):
if (all_nodes or ((x.depth % gamma) == 0) or all(((x.up_root[a] == 0) for a in L))):
(yield x)
def depth_first_iter(self, all_nodes=False):
"\n Iterate (recursively) over the nodes in the tree following a\n depth-first traversal.\n\n INPUT:\n\n - ``all_nodes`` -- (default: ``False``) if ``True``, output all\n nodes in the tree\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['C', 2, 1], [[1,1], [2,1]])\n sage: for x in KT.depth_first_iter(): x\n Kleber tree node with weight [1, 2, 1] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n sage: for x in KT.depth_first_iter(True): x\n Kleber tree node with weight [1, 2, 1] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [0, 2, 0] and upwards edge root [1, 1, 1]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n "
s_factors = self._folded_ct.scaling_factors()
gamma = max(s_factors)
if (gamma > 1):
sigma = self._folded_ct.folding_orbit()
L = [sigma[a][0] for a in range(1, len(s_factors)) if (s_factors[a] == gamma)]
else:
L = []
for x in self._depth_first_iter(None):
if (all_nodes or ((x.depth % gamma) == 0) or all(((x.up_root[a] == 0) for a in L))):
(yield x)
__iter__ = breadth_first_iter
def base_tree(self):
"\n Return the underlying virtual Kleber tree associated to ``self``.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['C', 4, 1], [[2,2]])\n sage: KT.base_tree()\n Kleber tree of Cartan type ['A', 7, 1] and B = ((2, 2), (6, 2))\n "
return KleberTree(self._folded_ct.folding_of(), self.B)
|
class KleberTreeTypeA2Even(VirtualKleberTree):
'\n Kleber tree for types `A_{2n}^{(2)}` and `A_{2n}^{(2)\\dagger}`.\n\n Note that here for `A_{2n}^{(2)}` we use `\\tilde{\\gamma}_a` in place of\n `\\gamma_a` in constructing the virtual Kleber tree, and so we end up\n selecting all nodes since `\\tilde{\\gamma}_a = 1` for all `a \\in\n \\overline{I}`. For type `A_{2n}^{(2)\\dagger}`, we have `\\gamma_a = 1`\n for all `a \\in \\overline{I}`.\n\n .. SEEALSO::\n\n :class:`VirtualKleberTree`\n '
@staticmethod
def __classcall_private__(cls, cartan_type, B):
"\n Normalize the input arguments to ensure unique representation.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT1 = VirtualKleberTree(CartanType(['A',6,2]), [[2,2]])\n sage: KT2 = VirtualKleberTree(['A',6,2], [(2,2)])\n sage: KT3 = VirtualKleberTree(['A',6,2], ((2,2),))\n sage: KT2 is KT1, KT3 is KT1\n (True, True)\n "
cartan_type = CartanType(cartan_type)
B = tuple(map(tuple, B))
return super().__classcall__(cls, cartan_type, B)
def __init__(self, cartan_type, B):
'\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree([\'A\',6,2], [[2,2]]); KT\n Virtual Kleber tree of Cartan type [\'BC\', 3, 2] and B = ((2, 2),)\n sage: TestSuite(KT).run(skip="_test_elements")\n '
self._folded_ct = cartan_type.as_folding()
virtual_dims = []
n = cartan_type.classical().rank()
self.base_dims = B
sigma = self._folded_ct.folding_orbit()
classical_ct = self._folded_ct.folding_of().classical()
for (r, s) in B:
if (r == n):
virtual_dims.extend([[n, s], [n, s]])
else:
for i in sigma[r]:
virtual_dims.append([i, s])
KleberTree.__init__(self, cartan_type, virtual_dims, classical_ct)
def __iter__(self):
"\n Iterate over all of the nodes.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['A',6,2], [[2,2]])\n sage: L = [x for x in KT]\n sage: len(L) == KT.cardinality()\n True\n "
return KleberTree.__iter__(self)
def _prune(self, new_child, depth):
"\n Return ``True`` if we are to prune the tree at ``new_child``.\n\n Suppose `\\lambda` is the weight of the child we want to add at\n depth `\\ell`. We prune ``new_child`` if `(\\lambda \\mid \\alpha_a)\n \\neq (\\lambda \\mid \\alpha_b)` if `a` and `b` are in the same\n `\\sigma`-orbit.\n\n These conditions are equivalent to Definition 4.1 in [OSS03]_ by using\n `\\tilde{\\gamma}`, and since `\\tilde{\\gamma}_a = 1` for all `a`, the\n second condition becomes vacuous.\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: RS = RootSystem(['A', 5])\n sage: WS = RS.weight_lattice()\n sage: R = RS.root_lattice()\n sage: KT = VirtualKleberTree(['A',6,2], [[2,2]])\n sage: x = KT(WS.sum_of_terms([(2,1), (4,1)]), R.sum_of_terms([(1,1),(2,2),(3,2),(4,2),(5,1)]), KT.root)\n sage: KT._prune(x, 1)\n False\n "
sigma = self._folded_ct._orbit
for orbit in sigma[1:]:
start = new_child.weight[orbit[0]]
for i in orbit[1:]:
if (new_child.weight[i] != start):
return True
return False
def breadth_first_iter(self, all_nodes=False):
"\n Iterate over all nodes in the tree following a breadth-first traversal.\n\n INPUT:\n\n - ``all_nodes`` -- (default: ``False``) if ``True``, output all\n nodes in the tree\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['A', 4, 2], [[2,1]])\n sage: for x in KT.breadth_first_iter(): x\n Kleber tree node with weight [0, 2, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 0, 0] and upwards edge root [1, 2, 1]\n sage: for x in KT.breadth_first_iter(True): x\n Kleber tree node with weight [0, 2, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 0, 0] and upwards edge root [1, 2, 1]\n "
return KleberTree.breadth_first_iter(self)
def depth_first_iter(self, all_nodes=False):
"\n Iterate (recursively) over the nodes in the tree following a\n depth-first traversal.\n\n INPUT:\n\n - ``all_nodes`` -- (default: ``False``) if ``True``, output all\n nodes in the tree\n\n EXAMPLES::\n\n sage: from sage.combinat.rigged_configurations.kleber_tree import VirtualKleberTree\n sage: KT = VirtualKleberTree(['A', 4, 2], [[2,1]])\n sage: for x in KT.depth_first_iter(): x\n Kleber tree node with weight [0, 2, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 0, 0] and upwards edge root [1, 2, 1]\n sage: for x in KT.depth_first_iter(True): x\n Kleber tree node with weight [0, 2, 0] and upwards edge root [0, 0, 0]\n Kleber tree node with weight [1, 0, 1] and upwards edge root [0, 1, 0]\n Kleber tree node with weight [0, 0, 0] and upwards edge root [1, 2, 1]\n "
return KleberTree.depth_first_iter(self)
|
class KirillovReshetikhinTableaux(CrystalOfWords):
"\n Kirillov-Reshetikhin tableaux.\n\n Kirillov-Reshetikhin tableaux are rectangular tableaux with `r` rows and\n `s` columns that naturally arise under the bijection between rigged\n configurations and tableaux [RigConBijection]_. They are in bijection with\n the elements of the Kirillov-Reshetikhin crystal `B^{r,s}` under the\n (inverse) filling map.\n\n Whenever `B^{r,s} \\cong B(s\\Lambda_r)` as a classical crystal (which is\n the case for `B^{r,s}` in type `A_n^{(1)}`, `B^{n,s}` in type `C_n^{(1)}`\n and `D_{n+1}^{(2)}`, `B^{n,s}` and `B^{n-1,s}` in type `D_n^{(1)}`) then\n the filling map is trivial.\n\n For `B^{r,s}` in:\n\n - type `D_n^{(1)}` when `r \\leq n-2`,\n - type `B_n^{(1)}` when `r < n`,\n - type `A_{2n-1}^{(2)}` for all `r`,\n\n the filling map is defined in [OSS2011]_.\n\n For the spinor cases in type `D_n^{(1)}`, the crystal `B^{k,s}` where\n `k = n-1, n`, is isomorphic as a classical crystal to `B(s\\Lambda_k)`,\n and here we consider the Kirillov-Reshetikhin tableaux as living in\n `B(2s \\Lambda_k)` under the natural doubling map. In this case, the\n crystal operators `e_i` and `f_i` act as `e_i^2` and `f_i^2` respectively.\n See [BijectionDn]_.\n\n For the spinor case in type `B_n^{(1)}`, the crystal `B^{n,s}`, we\n consider the images under the natural doubling map into `B^{n,2s}`.\n The classical components of this crystal are now given by\n removing `2 \\times 2` boxes. The filling map is the same as below\n (see the non-spin type `C_n^{(1)}`).\n\n For `B^{r,s}` in:\n\n - type `C_n^{(1)}` when `r < n`,\n - type `A_{2n}^{(2)\\dagger}` for all `r`,\n\n the filling map is given as follows. Suppose we are considering the\n (classically) highest weight element in the classical component\n `B(\\lambda)`. Then we fill it in with the horizontal dominoes\n `[\\bar{\\imath}, i]` in the `i`-th row from the top (in English notation)\n and reordering the columns so that they are increasing. Recall from above\n that `B^{n,s} \\cong B(s\\Lambda_n)` in type `C^{(1)}_n`.\n\n For `B^{r,s}` in:\n\n - type `A_{2n}^{(2)}` for all `r`,\n - type `D_{n+1}^{(2)}` when `r < n`,\n - type `D_4^{(3)}` when `r = 1`,\n\n the filling map is the same as given in [OSS2011]_ except for\n the rightmost column which is given by the column `[1, 2, \\ldots, k,\n \\emptyset, \\ldots \\emptyset]` where `k = (r+x-1)/2` in Step 3 of\n [OSS2011]_.\n\n For the spinor case in type `D_{n+1}^{(2)}`, the crystal `B^{n,s}`, we\n define the filling map in the same way as in type `D_n^{(1)}`.\n\n .. NOTE::\n\n The filling map and classical decompositions in non-spinor cases can\n be classified by how the special node `0` connects with the\n corresponding classical diagram.\n\n The classical crystal structure is given by the usual Kashiwara-Nakashima\n tableaux rules. That is to embed this into `B(\\Lambda_1)^{\\otimes n s}`\n by using the reading word and then applying the classical crystal\n operator. The affine crystal structure is given by converting to\n the corresponding KR crystal element, performing the affine crystal\n operator, and pulling back to a KR tableau.\n\n For more information about the bijection between rigged configurations\n and tensor products of Kirillov-Reshetikhin tableaux, see\n :class:`~sage.combinat.rigged_configurations.tensor_product_kr_tableaux.TensorProductOfKirillovReshetikhinTableaux`.\n\n .. NOTE::\n\n The tableaux for all non-simply-laced types are provably correct if the\n bijection with :class:`rigged configurations\n <sage.combinat.rigged_configurations.rigged_configurations.RiggedConfigurations>`\n holds. Therefore this is currently only proven for `B^{r,1}` or\n `B^{1,s}` and in general for types `A_n^{(1)}` and `D_n^{(1)}`.\n\n INPUT:\n\n - ``cartan_type`` -- the Cartan type\n\n - ``r`` -- the Dynkin diagram index (typically the number of rows)\n\n - ``s`` -- the number of columns\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: elt = KRT(4, 3); elt\n [[3], [4]]\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 2, 1, model='KR')\n sage: elt = KRT(-1, 1); elt\n [[1], [-1]]\n\n We can create highest weight crystals from a given shape or weight::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KR')\n sage: KRT.module_generator(shape=[1,1])\n [[1, 1], [2, -1]]\n sage: KRT.module_generator(column_shape=[2])\n [[1, 1], [2, -1]]\n sage: WS = RootSystem(['D',4,1]).weight_space()\n sage: KRT.module_generator(weight=WS.sum_of_terms([[0,-2],[2,1]]))\n [[1, 1], [2, -1]]\n sage: WSC = RootSystem(['D',4]).weight_space()\n sage: KRT.module_generator(classical_weight=WSC.fundamental_weight(2))\n [[1, 1], [2, -1]]\n\n We can go between\n :func:`~sage.combinat.crystals.kirillov_reshetikhin.KashiwaraNakashimaTableaux`\n and\n :class:`~sage.combinat.rigged_configurations.kr_tableaux.KirillovReshetikhinTableaux`\n elements::\n\n sage: KRCrys = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KN')\n sage: KRTab = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KR')\n sage: elt = KRCrys(3, 2); elt\n [[2], [3]]\n sage: k = KRTab(elt); k\n [[2, 1], [3, -1]]\n sage: KRCrys(k)\n [[2], [3]]\n\n We check that the classical weights in the classical decompositions\n agree in a few different type::\n\n sage: KRCrys = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KN')\n sage: KRTab = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KR')\n sage: all(t.classical_weight() == KRCrys(t).classical_weight() for t in KRTab)\n True\n sage: KRCrys = crystals.KirillovReshetikhin(['B', 3, 1], 2, 2, model='KN')\n sage: KRTab = crystals.KirillovReshetikhin(['B', 3, 1], 2, 2, model='KR')\n sage: all(t.classical_weight() == KRCrys(t).classical_weight() for t in KRTab)\n True\n sage: KRCrys = crystals.KirillovReshetikhin(['C', 3, 1], 2, 2, model='KN')\n sage: KRTab = crystals.KirillovReshetikhin(['C', 3, 1], 2, 2, model='KR')\n sage: all(t.classical_weight() == KRCrys(t).classical_weight() for t in KRTab)\n True\n sage: KRCrys = crystals.KirillovReshetikhin(['D', 4, 2], 2, 2, model='KN')\n sage: KRTab = crystals.KirillovReshetikhin(['D', 4, 2], 2, 2, model='KR')\n sage: all(t.classical_weight() == KRCrys(t).classical_weight() for t in KRTab)\n True\n sage: KRCrys = crystals.KirillovReshetikhin(['A', 4, 2], 2, 2, model='KN')\n sage: KRTab = crystals.KirillovReshetikhin(['A', 4, 2], 2, 2, model='KR')\n sage: all(t.classical_weight() == KRCrys(t).classical_weight() for t in KRTab)\n True\n "
@staticmethod
def __classcall_private__(cls, cartan_type, r, s):
"\n Normalize the input arguments to ensure unique representation.\n\n EXAMPLES::\n\n sage: KRT1 = crystals.KirillovReshetikhin(CartanType(['A',3,1]), 2, 3, model='KR')\n sage: KRT2 = crystals.KirillovReshetikhin(['A',3,1], 2, 3, model='KR')\n sage: KRT1 is KRT2\n True\n "
ct = CartanType(cartan_type)
if (not ct.is_affine()):
raise ValueError('The Cartan type must be affine')
typ = ct.type()
if ct.is_untwisted_affine():
if (typ == 'A'):
return KRTableauxRectangle(ct, r, s)
if (typ == 'B'):
if (r == ct.classical().rank()):
return KRTableauxBn(ct, r, s)
return KRTableauxTypeVertical(ct, r, s)
if (typ == 'C'):
if (r == ct.classical().rank()):
return KRTableauxRectangle(ct, r, s)
return KRTableauxTypeHorizonal(ct, r, s)
if (typ == 'D'):
if ((r == ct.classical().rank()) or (r == (ct.classical().rank() - 1))):
return KRTableauxSpin(ct, r, s)
return KRTableauxTypeVertical(ct, r, s)
if (typ == 'E'):
return KRTableauxTypeFromRC(ct, r, s)
else:
if (typ == 'BC'):
return KRTableauxTypeBox(ct, r, s)
typ = ct.dual().type()
if (typ == 'BC'):
return KRTableauxTypeHorizonal(ct, r, s)
if (typ == 'B'):
return KRTableauxTypeVertical(ct, r, s)
if (typ == 'C'):
if (r == ct.dual().classical().rank()):
return KRTableauxDTwistedSpin(ct, r, s)
return KRTableauxTypeBox(ct, r, s)
if (typ == 'G'):
if (r == 1):
return KRTableauxTypeBox(ct, r, s)
return KRTableauxTypeFromRC(ct, r, s)
raise NotImplementedError
def __init__(self, cartan_type, r, s):
"\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 2, model='KR')\n sage: TestSuite(KRT).run()\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KR')\n sage: TestSuite(KRT).run() # long time\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 4, 1, model='KR'); KRT\n Kirillov-Reshetikhin tableaux of type ['D', 4, 1] and shape (4, 1)\n sage: TestSuite(KRT).run()\n "
self._r = r
self._s = s
self._cartan_type = cartan_type
Parent.__init__(self, category=KirillovReshetikhinCrystals())
self.letters = CrystalOfLetters(cartan_type.classical())
self.module_generators = self._build_module_generators()
def _repr_(self):
"\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.KirillovReshetikhin(['A', 4, 1], 2, 3, model='KR')\n Kirillov-Reshetikhin tableaux of type ['A', 4, 1] and shape (2, 3)\n "
return 'Kirillov-Reshetikhin tableaux of type {} and shape ({}, {})'.format(self._cartan_type, self._r, self._s)
def __iter__(self):
"\n Return the iterator of ``self``.\n\n EXAMPLES::\n\n sage: KR = crystals.KirillovReshetikhin(['A', 5, 2], 2, 1, model='KR')\n sage: L = [x for x in KR]\n sage: len(L)\n 15\n "
index_set = self._cartan_type.classical().index_set()
from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet
return RecursivelyEnumeratedSet(self.module_generators, (lambda x: [x.f(i) for i in index_set]), structure='graded').breadth_first_search_iterator()
def module_generator(self, i=None, **options):
"\n Return the specified module generator.\n\n INPUT:\n\n - ``i`` -- the index of the module generator\n\n We can also get a module generator by using one of the following\n optional arguments:\n\n - ``shape`` -- the associated shape\n - ``column_shape`` -- the shape given as columns (a column of length\n `k` correspond to a classical weight `\\omega_k`)\n - ``weight`` -- the weight\n - ``classical_weight`` -- the classical weight\n\n If no arguments are specified, then return the unique module generator\n of classical weight `s \\Lambda_r`.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KR')\n sage: KRT.module_generator(1)\n [[1, 1], [2, -1]]\n sage: KRT.module_generator(shape=[1,1])\n [[1, 1], [2, -1]]\n sage: KRT.module_generator(column_shape=[2])\n [[1, 1], [2, -1]]\n sage: WS = RootSystem(['D',4,1]).weight_space()\n sage: KRT.module_generator(weight=WS.sum_of_terms([[0,-2],[2,1]]))\n [[1, 1], [2, -1]]\n sage: WSC = RootSystem(['D',4]).weight_space()\n sage: KRT.module_generator(classical_weight=WSC.fundamental_weight(2))\n [[1, 1], [2, -1]]\n sage: KRT.module_generator()\n [[1, 1], [2, 2]]\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 3, 1], 2, 2, model='KR')\n sage: KRT.module_generator()\n [[1, 1], [2, 2]]\n "
if (i is not None):
return self.module_generators[i]
n = self._cartan_type.classical().rank()
if ('shape' in options):
shape = list(options['shape'])
if (len(shape) < n):
shape.extend(([0] * (n - len(shape))))
for mg in self.module_generators:
if (list(mg.classical_weight().to_vector()) == shape):
return mg
return None
if ('column_shape' in options):
shape = list(Partition(options['column_shape']).conjugate())
if (len(shape) < n):
shape.extend(([0] * (n - len(shape))))
for mg in self.module_generators:
if (list(mg.classical_weight().to_vector()) == shape):
return mg
return None
if ('weight' in options):
wt = options['weight']
for mg in self.module_generators:
if (mg.weight() == wt):
return mg
return None
if ('classical_weight' in options):
wt = options['classical_weight']
for mg in self.module_generators:
if (mg.classical_weight() == wt):
return mg
return None
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()))
for b in self.module_generators:
if (b.weight() == weight):
return b
assert False
@abstract_method
def _build_module_generators(self):
"\n Build the module generators.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 3, model='KR')\n sage: KRT._build_module_generators()\n ([[1, 1, 1], [2, 2, 2]],)\n "
@abstract_method(optional=True)
def from_kirillov_reshetikhin_crystal(self, krc):
"\n Construct an element of ``self`` from the Kirillov-Reshetikhin\n crystal element ``krc``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: C = crystals.KirillovReshetikhin(['A',4,1], 2, 1, model='KN')\n sage: krc = C(4,3); krc\n [[3], [4]]\n sage: KRT.from_kirillov_reshetikhin_crystal(krc)\n [[3], [4]]\n "
def _element_constructor_(self, *lst, **options):
"\n Construct a\n :class:`~sage.combinat.rigged_configurations.kr_tableaux.KirillovReshetikhinTableauxElement`.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: KRT(3, 4) # indirect doctest\n [[4], [3]]\n sage: KRT(4, 3)\n [[3], [4]]\n "
if isinstance(lst[0], KirillovReshetikhinGenericCrystalElement):
if ((lst[0].cartan_type() != self.cartan_type()) or (lst[0].parent().r() != self._r) or (lst[0].parent().s() != self._s)):
raise ValueError('the Kirillov-Reshetikhin crystal must have the same Cartan type and (r,s)')
return self.from_kirillov_reshetikhin_crystal(lst[0])
return self.element_class(self, list(lst), **options)
def r(self):
"\n Return the value `r` for this tableaux class which corresponds to the\n number of rows.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: KRT.r()\n 2\n "
return self._r
def s(self):
"\n Return the value `s` for this tableaux class which corresponds to the\n number of columns.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: KRT.s()\n 1\n "
return self._s
@cached_method
def kirillov_reshetikhin_crystal(self):
"\n Return the corresponding KR crystal in the\n :func:`Kashiwara-Nakashima model\n <sage.combinat.crystals.kirillov_reshetikhin.KashiwaraNakashimaTableaux>`.\n\n EXAMPLES::\n\n sage: crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR').kirillov_reshetikhin_crystal()\n Kirillov-Reshetikhin crystal of type ['A', 4, 1] with (r,s)=(2,1)\n "
return KashiwaraNakashimaTableaux(self._cartan_type, self._r, self._s)
def classical_decomposition(self):
"\n Return the classical crystal decomposition of ``self``.\n\n EXAMPLES::\n\n sage: crystals.KirillovReshetikhin(['D', 4, 1], 2, 2, model='KR').classical_decomposition()\n The crystal of tableaux of type ['D', 4] and shape(s) [[], [1, 1], [2, 2]]\n "
return self.kirillov_reshetikhin_crystal().classical_decomposition()
def tensor(self, *crystals, **options):
"\n Return the tensor product of ``self`` with ``crystals``.\n\n If ``crystals`` is a list of (a tensor product of) KR tableaux, this\n returns a\n :class:`~sage.combinat.rigged_configurations.tensor_product_kr_tableaux.TensorProductOfKirillovReshetikhinTableaux`.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A', 3, 1], 2, 2, model='KR')\n sage: TP = crystals.TensorProductOfKirillovReshetikhinTableaux(['A', 3, 1], [[1,3],[3,1]])\n sage: K.tensor(TP, K)\n Tensor product of Kirillov-Reshetikhin tableaux of type ['A', 3, 1]\n and factor(s) ((2, 2), (1, 3), (3, 1), (2, 2))\n\n sage: C = crystals.KirillovReshetikhin(['A',3,1], 3, 1, model='KN')\n sage: K.tensor(K, C)\n Full tensor product of the crystals\n [Kirillov-Reshetikhin tableaux of type ['A', 3, 1] and shape (2, 2),\n Kirillov-Reshetikhin tableaux of type ['A', 3, 1] and shape (2, 2),\n Kirillov-Reshetikhin crystal of type ['A', 3, 1] with (r,s)=(3,1)]\n "
ct = self._cartan_type
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
if all(((isinstance(B, (KirillovReshetikhinTableaux, TensorProductOfKirillovReshetikhinTableaux)) and (B.cartan_type() == ct)) for B in crystals)):
dims = [[self._r, self._s]]
for B in crystals:
if isinstance(B, TensorProductOfKirillovReshetikhinTableaux):
dims += B.dims
elif isinstance(B, KirillovReshetikhinTableaux):
dims.append([B._r, B._s])
return TensorProductOfKirillovReshetikhinTableaux(ct, dims)
return super().tensor(*crystals, **options)
@lazy_attribute
def _tableau_height(self):
"\n The height of the tableaux in ``self``.\n\n EXAMPLES::\n\n sage: K = crystals.KirillovReshetikhin(['A', 3, 1], 3, 2, model='KR')\n sage: K._tableau_height\n 3\n "
return self._r
|
class KRTableauxRectangle(KirillovReshetikhinTableaux):
"\n Kirillov-Reshetkhin tableaux `B^{r,s}` whose module generator is a single\n `r \\times s` rectangle.\n\n These are Kirillov-Reshetkhin tableaux `B^{r,s}` of type:\n\n - `A_n^{(1)}` for all `1 \\leq r \\leq n`,\n - `C_n^{(1)}` when `r = n`.\n\n TESTS::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 3, 1], 2, 2, model='KR')\n sage: TestSuite(KRT).run()\n sage: KRT = crystals.KirillovReshetikhin(['C', 3, 1], 3, 2, model='KR')\n sage: TestSuite(KRT).run() # long time\n "
def _build_module_generators(self):
"\n Build the module generators.\n\n There is only one module generator which corresponds to a single\n `r \\times s` rectangle.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 3, model='KR')\n sage: KRT._build_module_generators()\n ([[1, 1, 1], [2, 2, 2]],)\n "
tableau = []
for i in range(self._s):
tableau.append([(self._r - j) for j in range(self._r)])
return (self.element_class(self, [self.letters(x) for x in flatten(tableau)]),)
def from_kirillov_reshetikhin_crystal(self, krc):
"\n Construct a\n :class:`~sage.combinat.rigged_configurations.kr_tableaux.KirillovReshetikhinTableauxElement`.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: C = crystals.KirillovReshetikhin(['A',4,1], 2, 1, model='KN')\n sage: krc = C(4,3); krc\n [[3], [4]]\n sage: KRT.from_kirillov_reshetikhin_crystal(krc)\n [[3], [4]]\n "
f_str = reversed(krc.lift().to_highest_weight()[1])
return self.module_generators[0].f_string(f_str)
|
class KRTableauxTypeVertical(KirillovReshetikhinTableaux):
"\n Kirillov-Reshetkihn tableaux `B^{r,s}` of type:\n\n - `D_n^{(1)}` for all `1 \\leq r < n-1`,\n - `B_n^{(1)}` for all `1 \\leq r < n`,\n - `A_{2n-1}^{(2)}` for all `1 \\leq r \\leq n`.\n\n TESTS::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 1, 1, model='KR')\n sage: TestSuite(KRT).run()\n sage: KRT = crystals.KirillovReshetikhin(['B', 3, 1], 2, 2, model='KR')\n sage: TestSuite(KRT).run() # long time\n sage: KRT = crystals.KirillovReshetikhin(['A', 5, 2], 2, 2, model='KR')\n sage: TestSuite(KRT).run() # long time\n "
def _fill(self, weight):
"\n Return the highest weight KR tableau of weight ``weight``.\n\n INPUT:\n\n - ``weight`` -- The weight of the highest weight KR tableau (the\n conjugate of the shape of the KR crystal's tableau)\n\n OUTPUT:\n\n - A `r \\times s` tableau\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 2, 1, model='KR')\n sage: KRT._fill([])\n [[1], [-1]]\n sage: KRT = crystals.KirillovReshetikhin(['D', 14, 1], 12, 7, model='KR')\n sage: KRT._fill([10,10,8,2,2,2])\n [[1, 1, 1, 1, 1, 7, 1], [2, 2, 2, 2, 2, 8, 2], [3, 3, 7, 9, 7, 9, 3], [4, 4, 8, 10, 8, 10, 4], [5, 5, 9, 11, 9, 11, 5], [6, 6, 10, 12, 10, 12, 6], [7, 7, 11, -12, 11, -12, 7], [8, 8, 12, -11, 12, -11, 8], [9, 9, -12, -10, -12, -10, 9], [10, 10, -11, -9, -11, -9, -9], [-12, 11, -10, -8, -10, -8, -8], [-11, 12, -9, -7, -9, -7, -7]]\n sage: KRT._fill([10,10,6,2,2,2])\n [[1, 1, 1, 1, 1, 5, 1], [2, 2, 2, 2, 2, 6, 2], [3, 3, 9, 7, 9, 7, 3], [4, 4, 10, 8, 10, 8, 4], [5, 5, 11, 9, 11, 9, 5], [6, 6, 12, 10, 12, 10, 6], [7, 7, -12, 11, -12, 11, 7], [8, 8, -11, 12, -11, 12, 8], [9, 9, -10, -12, -10, -12, -8], [10, 10, -9, -11, -9, -11, -7], [-12, 11, -8, -10, -8, -10, -6], [-11, 12, -7, -9, -7, -9, -5]]\n "
weight_list = list(weight)
while (len(weight_list) != self._s):
weight_list.append(0)
tableau = []
i = 0
while ((i < self._s) and (weight_list[i] == self._r)):
tableau.append([(self._r - j) for j in range(self._r)])
i += 1
c = (- 1)
while (i < self._s):
if ((i == (self._s - 1)) or (weight_list[i] != weight_list[(i + 1)])):
c = weight_list[i]
i += 1
break
temp_list = [(- ((weight_list[i] + j) + 1)) for j in range((self._r - weight_list[i]))]
for j in range(weight_list[i]):
temp_list.append((weight_list[i] - j))
tableau.append(temp_list)
tableau.append([(self._r - j) for j in range(self._r)])
i += 2
x = (c + 1)
while (i < self._s):
temp_list = [((- x) - j) for j in range(((self._r - x) + 1))]
for j in range(((x - weight_list[i]) - 1)):
temp_list.append((self._r - j))
x = temp_list[(- 1)]
for j in range(weight_list[i]):
temp_list.append((weight_list[i] - j))
tableau.append(temp_list)
i += 1
if (c > (- 1)):
val = (((self._r + x) - 1) // 2)
temp_list = [((- x) - j) for j in range((self._r - val))]
for j in range(val):
temp_list.append((val - j))
tableau.append(temp_list)
return self.element_class(self, [self.letters(x) for x in flatten(tableau)])
def _build_module_generators(self):
"\n Build the module generators.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 3, model='KR')\n sage: KRT._build_module_generators()\n ([[-2, 1, 1], [-1, 2, -1]], [[1, -2, 1], [2, -1, 2]],\n [[1, 1, 1], [2, 2, -1]], [[1, 1, 1], [2, 2, 2]])\n "
return tuple((self._fill(weight) for weight in horizontal_dominoes_removed(self._s, self._r)))
def from_kirillov_reshetikhin_crystal(self, krc):
"\n Construct an element of ``self`` from the Kirillov-Reshetikhin\n crystal element ``krc``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 3, model='KR')\n sage: C = crystals.KirillovReshetikhin(['D',4,1], 2, 3, model='KN')\n sage: krc = C(4,3); krc\n [[3], [4]]\n sage: KRT.from_kirillov_reshetikhin_crystal(krc)\n [[3, -2, 1], [4, -1, 2]]\n "
lifted = krc.lift()
weight = lifted.to_tableau().shape().conjugate()
f_str = reversed(lifted.to_highest_weight()[1])
return self._fill(weight).f_string(f_str)
|
class KRTableauxTypeHorizonal(KirillovReshetikhinTableaux):
"\n Kirillov-Reshetikhin tableaux `B^{r,s}` of type:\n\n - `C_n^{(1)}` for `1 \\leq r < n`,\n - `A_{2n}^{(2)\\dagger}` for `1 \\leq r \\leq n`.\n\n TESTS::\n\n sage: KRT = crystals.KirillovReshetikhin(['C', 3, 1], 2, 2, model='KR')\n sage: TestSuite(KRT).run() # long time\n sage: KRT = crystals.KirillovReshetikhin(CartanType(['A', 4, 2]).dual(), 2, 2, model='KR')\n sage: TestSuite(KRT).run()\n "
def _fill(self, shape):
"\n Return the highest weight KR tableau of weight ``shape``.\n\n INPUT:\n\n - ``shape`` -- The shape of the KR crystal's tableau\n\n OUTPUT:\n\n - A `r \\times s` tableau\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['C', 5, 1], 3, 5, model='KR')\n sage: KRT._fill([3,3,1])\n [[1, 1, 1, -3, 1], [2, 2, 2, -2, 2], [3, -3, 3, -1, 3]]\n sage: KRT = crystals.KirillovReshetikhin(['C', 10, 1], 5, 6, model='KR')\n sage: KRT._fill([6,4,2,2])\n [[1, 1, 1, 1, 1, 1], [2, 2, 2, 2, -5, 2], [3, 3, -5, 3, -4, 3], [4, 4, -4, 4, -3, 4], [-5, 5, -3, 5, -2, 5]]\n sage: KRT._fill([6,4])\n [[1, 1, 1, 1, 1, 1], [2, 2, 2, 2, -5, 2], [-5, 3, -5, 3, -4, 3], [-4, 4, -4, 4, -3, 4], [-3, 5, -3, 5, -2, 5]]\n "
shape_list = list(shape)
while (len(shape_list) != self._r):
shape_list.append(0)
lst = []
for col in range(1, (self._s + 1)):
if (((self._s - col) % 2) == 0):
lst.extend([self.letters((self._r - x)) for x in range(self._r)])
else:
m = self._r
for (j, val) in enumerate(shape_list):
if (col >= val):
m = j
break
lst.extend([self.letters((- x)) for x in range((m + 1), (self._r + 1))])
lst.extend([self.letters((m - x)) for x in range(m)])
return self.element_class(self, lst)
def _build_module_generators(self):
"\n Build the module generators.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['C',4,1], 2, 3, model='KR')\n sage: KRT._build_module_generators()\n ([[1, -2, 1], [2, -1, 2]], [[1, 1, 1], [2, -2, 2]], [[1, 1, 1], [2, 2, 2]])\n "
return tuple((self._fill(shape) for shape in horizontal_dominoes_removed(self._r, self._s)))
def from_kirillov_reshetikhin_crystal(self, krc):
"\n Construct an element of ``self`` from the Kirillov-Reshetikhin\n crystal element ``krc``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['C',4,1], 2, 3, model='KR')\n sage: C = crystals.KirillovReshetikhin(['C',4,1], 2, 3, model='KN')\n sage: krc = C(4,3); krc\n [[3], [4]]\n sage: KRT.from_kirillov_reshetikhin_crystal(krc)\n [[3, -2, 1], [4, -1, 2]]\n "
lifted = krc.lift()
shape = lifted.to_tableau().shape()
f_str = reversed(lifted.to_highest_weight()[1])
return self._fill(shape).f_string(f_str)
|
class KRTableauxTypeBox(KRTableauxTypeVertical):
"\n Kirillov-Reshetikhin tableaux `B^{r,s}` of type:\n\n - `A_{2n}^{(2)}` for all `r \\leq n`,\n - `D_{n+1}^{(2)}` for all `r < n`,\n - `D_4^{(3)}` for `r = 1`.\n\n TESTS::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 2], 2, 2, model='KR')\n sage: TestSuite(KRT).run()\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 2], 2, 2, model='KR')\n sage: TestSuite(KRT).run() # long time\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 3], 1, 2, model='KR')\n sage: TestSuite(KRT).run() # long time\n "
def _fill(self, weight):
"\n Return the highest weight KR tableau of weight ``weight``.\n\n INPUT:\n\n - ``weight`` -- The weight of the highest weight KR tableau (the\n conjugate of the shape of the KR crystal's tableau)\n\n OUTPUT:\n\n - A `r \\times s` tableau\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 2, 1, model='KR')\n sage: KRT._fill([])\n [[1], [-1]]\n sage: KRT = crystals.KirillovReshetikhin(['D', 14, 1], 12, 7, model='KR')\n sage: KRT._fill([10,10,8,2,2,2])\n [[1, 1, 1, 1, 1, 7, 1], [2, 2, 2, 2, 2, 8, 2], [3, 3, 7, 9, 7, 9, 3], [4, 4, 8, 10, 8, 10, 4], [5, 5, 9, 11, 9, 11, 5], [6, 6, 10, 12, 10, 12, 6], [7, 7, 11, -12, 11, -12, 7], [8, 8, 12, -11, 12, -11, 8], [9, 9, -12, -10, -12, -10, 9], [10, 10, -11, -9, -11, -9, -9], [-12, 11, -10, -8, -10, -8, -8], [-11, 12, -9, -7, -9, -7, -7]]\n sage: KRT._fill([10,10,6,2,2,2])\n [[1, 1, 1, 1, 1, 5, 1], [2, 2, 2, 2, 2, 6, 2], [3, 3, 9, 7, 9, 7, 3], [4, 4, 10, 8, 10, 8, 4], [5, 5, 11, 9, 11, 9, 5], [6, 6, 12, 10, 12, 10, 6], [7, 7, -12, 11, -12, 11, 7], [8, 8, -11, 12, -11, 12, 8], [9, 9, -10, -12, -10, -12, -8], [10, 10, -9, -11, -9, -11, -7], [-12, 11, -8, -10, -8, -10, -6], [-11, 12, -7, -9, -7, -9, -5]]\n "
weight_list = list(weight)
while (len(weight_list) != self._s):
weight_list.append(0)
tableau = []
i = 0
while ((i < self._s) and (weight_list[i] == self._r)):
tableau.append([(self._r - j) for j in range(self._r)])
i += 1
c = (- 1)
while (i < self._s):
if ((i == (self._s - 1)) or (weight_list[i] != weight_list[(i + 1)])):
c = weight_list[i]
i += 1
break
temp_list = [(- ((weight_list[i] + j) + 1)) for j in range((self._r - weight_list[i]))]
for j in range(weight_list[i]):
temp_list.append((weight_list[i] - j))
tableau.append(temp_list)
tableau.append([(self._r - j) for j in range(self._r)])
i += 2
x = (c + 1)
while (i < self._s):
temp_list = [((- x) - j) for j in range(((self._r - x) + 1))]
for j in range(((x - weight_list[i]) - 1)):
temp_list.append((self._r - j))
x = temp_list[(- 1)]
for j in range(weight_list[i]):
temp_list.append((weight_list[i] - j))
tableau.append(temp_list)
i += 1
if (c > (- 1)):
val = (x - 1)
temp_list = ['E' for j in range((self._r - val))]
for j in range(val):
temp_list.append((val - j))
tableau.append(temp_list)
return self.element_class(self, [self.letters(x) for x in flatten(tableau)])
def _build_module_generators(self):
"\n Build the module generators.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A',4,2], 2, 2, model='KR')\n sage: KRT._build_module_generators()\n ([[-2, 1], [-1, 2]], [[2, 1], [-2, E]], [[1, E], [2, E]],\n [[1, 1], [-2, 2]], [[1, 1], [2, E]], [[1, 1], [2, 2]])\n "
return tuple((self._fill(weight) for weight in partitions_in_box(self._s, self._r)))
|
class KRTableauxSpin(KRTableauxRectangle):
"\n Kirillov-Reshetikhin tableaux `B^{r,s}` of type `D_n^{(1)}` with\n `r = n, n-1`.\n\n TESTS::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 3, 2, model='KR')\n sage: TestSuite(KRT).run()\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 4, 2, model='KR')\n sage: TestSuite(KRT).run()\n "
def _build_module_generators(self):
"\n Build the module generators.\n\n There is only one module generator which corresponds to a single\n `n \\times s` rectangle.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 3, 3, model='KR')\n sage: KRT._build_module_generators()\n ([[1, 1, 1], [2, 2, 2], [3, 3, 3], [-4, -4, -4]],)\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 4, 3, model='KR')\n sage: KRT._build_module_generators()\n ([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]],)\n "
n = self.cartan_type().classical().rank()
if (self._r == n):
return KRTableauxRectangle._build_module_generators(self)
tableau = []
for i in range(self._s):
tableau.append(([(- n)] + [(self._r - j) for j in range(self._r)]))
return (self.element_class(self, [self.letters(x) for x in flatten(tableau)]),)
|
class KRTableauxBn(KRTableauxTypeHorizonal):
"\n Kirillov-Reshetkhin tableaux `B^{n,s}` of type `B_n^{(1)}`.\n\n TESTS::\n\n sage: KRT = crystals.KirillovReshetikhin(['B', 2, 1], 2, 3, model='KR')\n sage: TestSuite(KRT).run()\n "
def _build_module_generators(self):
"\n Build the module generators.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['B', 2, 1], 2, 2, model='KR')\n sage: KRT._build_module_generators()\n ([[-2, 1], [-1, 2]], [[1, 1], [2, 2]])\n "
odd = int((self._s % 2))
shapes = [[int(((x * 2) + odd)) for x in sh] for sh in vertical_dominoes_removed(self._r, (self._s // 2))]
return tuple((self._fill(sh) for sh in shapes))
def from_kirillov_reshetikhin_crystal(self, krc):
"\n Construct an element of ``self`` from the Kirillov-Reshetikhin\n crystal element ``krc``.\n\n EXAMPLES::\n\n sage: KR = crystals.KirillovReshetikhin(['B',3,1], 3, 3, model='KR')\n sage: C = crystals.KirillovReshetikhin(['B',3,1], 3, 3, model='KN')\n sage: krc = C.module_generators[1].f_string([3,2,3,1,3,3]); krc\n [++-, [[2], [0], [-3]]]\n sage: KR.from_kirillov_reshetikhin_crystal(krc)\n [[1, 1, 2], [2, 2, -3], [-3, -3, -1]]\n "
lifted = krc.lift()
to_hw = lifted.to_highest_weight()
f_str = reversed(to_hw[1])
wt = to_hw[0].weight()
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')
|
class KirillovReshetikhinTableauxElement(TensorProductOfRegularCrystalsElement):
'\n A Kirillov-Reshetikhin tableau.\n\n For more information, see\n :class:`~sage.combinat.rigged_configurations.kr_tableaux.KirillovReshetikhinTableaux`\n and\n :class:`~sage.combinat.rigged_configurations.tensor_product_kr_tableaux.TensorProductOfKirillovReshetikhinTableaux`.\n '
def __init__(self, parent, list, **options):
"\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: elt = KRT(4, 3); elt\n [[3], [4]]\n sage: TestSuite(elt).run()\n "
if (list and (not isinstance(list[0], (parent.letters.element_class, EmptyLetter)))):
list = [parent.letters(x) for x in list]
TensorProductOfRegularCrystalsElement.__init__(self, parent, list)
def _repr_(self):
"\n Return the string representation of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 1, model='KR')\n sage: KRT(3,2)\n [[2], [3]]\n "
return repr(self.to_array())
def _repr_diagram(self):
"\n Return a string representation of ``self`` as a diagram.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A',4,1], 2, 2, model='KR')\n sage: elt = KRT(2,1,4,3)\n sage: print(elt._repr_diagram())\n 1 3\n 2 4\n "
return self.to_tableau()._repr_diagram()
def _latex_(self):
"\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 3, model='KR')\n sage: latex(KRT(3,2,4,2,4,3))\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{2}&\\lr{2}&\\lr{3}\\\\\\cline{1-3}\n \\lr{3}&\\lr{4}&\\lr{4}\\\\\\cline{1-3}\n \\end{array}$}\n }\n "
from sage.combinat.output import tex_from_array
return tex_from_array([[val._latex_() for val in row] for row in self.to_array()])
def _ascii_art_(self):
"\n Return an ASCII art representation of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A',4,1], 2, 2, model='KR')\n sage: ascii_art(KRT(2,1,4,3))\n 1 3\n 2 4\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 EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: unicode_art(KRT(2,1,-4,3))\n ┌───┬───┐\n │ 1 │ 3 │\n ├───┼───┤\n │ 2 │ 4̄ │\n └───┴───┘\n "
return self.to_tableau()._unicode_art_()
def to_kirillov_reshetikhin_crystal(self):
"\n Construct a\n :func:`~sage.combinat.crystals.kirillov_reshetihkin.KashiwaraNakashimaTableaux`\n element from ``self``.\n\n We construct the Kirillov-Reshetikhin crystal element as follows:\n\n 1. Determine the shape `\\lambda` of the KR crystal from the weight.\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 crystal of shape `\\lambda`.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: elt = KRT(3,2,-1,1); elt\n [[2, 1], [3, -1]]\n sage: elt.to_kirillov_reshetikhin_crystal()\n [[2], [3]]\n\n TESTS:\n\n Spinor tests::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 4, 3, model='KR')\n sage: KRC = crystals.KirillovReshetikhin(['D',4,1], 4, 3, model='KN')\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: ret = elt.to_kirillov_reshetikhin_crystal(); ret\n [++--, [[1], [3], [-4], [-3]]]\n sage: test = KRT(ret); test\n [[1, 1, 1], [2, 2, 3], [-4, -4, -4], [-3, -3, -2]]\n sage: test == elt\n True\n "
return self.parent().kirillov_reshetikhin_crystal()(self)
@cached_method
def to_array(self, rows=True):
"\n Return a 2-dimensional array representation of this\n Kirillov-Reshetikhin element.\n\n If the output is in rows, then it outputs the top row first (in the\n English convention) from left to right.\n\n For example: if the reading word is `[2, 1, 4, 3]`, so as a\n `2 \\times 2` tableau::\n\n 1 3\n 2 4\n\n we output ``[[1, 3], [2, 4]]``.\n\n If the output is in columns, then it outputs the leftmost column first\n with the bottom element first. In other words this parses the reading\n word into its columns.\n\n Continuing with the previous example, the output would be\n ``[[2, 1], [4, 3]]``.\n\n INPUT:\n\n - ``rows`` -- (Default: ``True``) Set to ``True`` if the resulting\n array is by row, otherwise it is by column.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 2, model='KR')\n sage: elt = KRT(2, 1, 4, 3)\n sage: elt.to_array()\n [[1, 3], [2, 4]]\n sage: elt.to_array(False)\n [[2, 1], [4, 3]]\n "
ret_list = []
h = self.parent()._tableau_height
s = self.parent()._s
if rows:
for i in reversed(range(h)):
row = []
for j in range(s):
row.append(self[((j * h) + i)])
ret_list.append(row)
else:
for j in range(s):
col = []
for i in range(h):
col.append(self[((j * h) + i)])
ret_list.append(col)
return ret_list
@cached_method
def to_tableau(self):
"\n Return a :class:`Tableau` object of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 2, model='KR')\n sage: elt = KRT(2, 1, 4, 3); elt\n [[1, 3], [2, 4]]\n sage: t = elt.to_tableau(); t\n [[1, 3], [2, 4]]\n sage: type(t)\n <class 'sage.combinat.tableau.Tableaux_all_with_category.element_class'>\n "
return Tableau(self.to_array())
def pp(self):
"\n Pretty print ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['A', 4, 1], 2, 2, model='KR')\n sage: elt = KRT(2, 1, 4, 3); elt\n [[1, 3], [2, 4]]\n sage: elt.pp()\n 1 3\n 2 4\n "
self.to_tableau().pp()
def to_classical_highest_weight(self, index_set=None):
"\n Return the classical highest weight element corresponding to ``self``.\n\n INPUT:\n\n - ``index_set`` -- (Default: ``None``) Return the highest weight\n with respect to the index set. If ``None`` is passed in, then this\n uses the classical index set.\n\n OUTPUT:\n\n A pair ``[H, f_str]`` where ``H`` is the highest weight element and\n ``f_str`` is a list of `a_i` of `f_{a_i}` needed to reach ``H``.\n\n EXAMPLES::\n\n sage: KRTab = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: elt = KRTab(3,2,-1,1); elt\n [[2, 1], [3, -1]]\n sage: elt.to_classical_highest_weight()\n [[[1, 1], [2, -1]], [1, 2]]\n "
if (index_set is None):
index_set = self.parent()._cartan_type.classical().index_set()
for i in index_set:
next = self.e(i)
if (next is not None):
hw = next.to_classical_highest_weight(index_set=index_set)
return [hw[0], ([i] + hw[1])]
return [self, []]
def weight(self):
"\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: KR = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: KR.module_generators[1].weight()\n -2*Lambda[0] + Lambda[2]\n "
return (self.Phi() - self.Epsilon())
@cached_method
def classical_weight(self):
"\n Return the classical weight of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: elt = KRT(3,2,-1,1); elt\n [[2, 1], [3, -1]]\n sage: elt.classical_weight()\n (0, 1, 1, 0)\n "
F = self.cartan_type().classical().root_system()
if (F.ambient_space() is None):
WLR = F.weight_lattice()
else:
WLR = F.ambient_space()
return sum((self[j].weight() for j in range(len(self))), WLR.zero())
def e(self, i):
"\n Perform the action of `e_i` on ``self``.\n\n .. TODO::\n\n Implement a direct action of `e_0` without moving to KR crystals.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: KRT.module_generators[0].e(0)\n [[-2, 1], [-1, -1]]\n "
if (i == self.parent()._cartan_type.special_node()):
ret = self.to_kirillov_reshetikhin_crystal().e0()
if (ret is None):
return None
return ret.to_kirillov_reshetikhin_tableau()
return TensorProductOfRegularCrystalsElement.e(self, i)
def f(self, i):
"\n Perform the action of `f_i` on ``self``.\n\n .. TODO::\n\n Implement a direct action of `f_0` without moving to KR crystals.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: KRT.module_generators[0].f(0)\n [[1, 1], [2, -1]]\n "
if (i == self.parent()._cartan_type.special_node()):
ret = self.to_kirillov_reshetikhin_crystal().f0()
if (ret is None):
return None
return ret.to_kirillov_reshetikhin_tableau()
return TensorProductOfRegularCrystalsElement.f(self, i)
def epsilon(self, i):
"\n Compute `\\varepsilon_i` of ``self``.\n\n .. TODO::\n\n Implement a direct action of `\\varepsilon_0` without moving to\n KR crystals.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: KRT.module_generators[0].epsilon(0)\n 2\n "
if (i == self.parent()._cartan_type.special_node()):
return self.to_kirillov_reshetikhin_crystal().epsilon0()
return TensorProductOfRegularCrystalsElement.epsilon(self, i)
def phi(self, i):
"\n Compute `\\varphi_i` of ``self``.\n\n .. TODO::\n\n Compute `\\varphi_0` without moving to KR crystals.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 2, model='KR')\n sage: KRT.module_generators[0].phi(0)\n 2\n "
if (i == self.parent()._cartan_type.special_node()):
return self.to_kirillov_reshetikhin_crystal().phi0()
return TensorProductOfRegularCrystalsElement.phi(self, i)
def left_split(self):
"\n Return the image of ``self`` under the left column splitting map.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 3, model='KR')\n sage: mg = KRT.module_generators[1]; mg.pp()\n 1 -2 1\n 2 -1 2\n sage: ls = mg.left_split(); ls.pp()\n 1 (X) -2 1\n 2 -1 2\n sage: ls.parent()\n Tensor product of Kirillov-Reshetikhin tableaux of type ['D', 4, 1] and factor(s) ((2, 1), (2, 2))\n "
P = self.parent()
if (P._s == 1):
raise ValueError('cannot split a single column')
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
r = P._r
TP = TensorProductOfKirillovReshetikhinTableaux(P._cartan_type, [[r, 1], [r, (P._s - 1)]])
lf = TP.crystals[0](*self[:r])
rf = TP.crystals[1](*self[r:])
return TP(lf, rf)
def right_split(self):
"\n Return the image of ``self`` under the right column splitting map.\n\n Let `\\ast` denote the :meth:`Lusztig involution<lusztig_involution>`,\n and `\\mathrm{ls}` as the :meth:`left splitting map<left_split>`.\n The right splitting map is defined as\n `\\mathrm{rs} := \\ast \\circ \\mathrm{ls} \\circ \\ast`.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 2, 3, model='KR')\n sage: mg = KRT.module_generators[1]; mg.pp()\n 1 -2 1\n 2 -1 2\n sage: ls = mg.right_split(); ls.pp()\n -2 1 (X) 1\n -1 2 2\n sage: ls.parent()\n Tensor product of Kirillov-Reshetikhin tableaux of type ['D', 4, 1] and factor(s) ((2, 2), (2, 1))\n "
return self.lusztig_involution().left_split().lusztig_involution()
|
class KRTableauxSpinElement(KirillovReshetikhinTableauxElement):
'\n Kirillov-Reshetikhin tableau for spinors.\n\n Here we are in the embedding `B(\\Lambda_n) \\hookrightarrow\n B(2 \\Lambda_n)`, so `e_i` and `f_i` act by `e_i^2` and `f_i^2`\n respectively for all `i \\neq 0`. We do this so our columns are full\n width (as opposed to half width and/or uses a `\\pm` representation).\n '
def e(self, i):
"\n Calculate the action of `e_i` on ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 4, 1, model='KR')\n sage: KRT(-1, -4, 3, 2).e(1)\n [[1], [3], [-4], [-2]]\n sage: KRT(-1, -4, 3, 2).e(3)\n "
if (i == self.parent()._cartan_type.special_node()):
return KirillovReshetikhinTableauxElement.e(self, i)
half = KirillovReshetikhinTableauxElement.e(self, i)
if (half is None):
return None
return KirillovReshetikhinTableauxElement.e(half, i)
def f(self, i):
"\n Calculate the action of `f_i` on ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 4, 1, model='KR')\n sage: KRT(-1, -4, 3, 2).f(1)\n sage: KRT(-1, -4, 3, 2).f(3)\n [[2], [4], [-3], [-1]]\n "
if (i == self.parent()._cartan_type.special_node()):
return KirillovReshetikhinTableauxElement.f(self, i)
half = KirillovReshetikhinTableauxElement.f(self, i)
if (half is None):
return None
return KirillovReshetikhinTableauxElement.f(half, i)
def epsilon(self, i):
"\n Compute `\\varepsilon_i` of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 4, 1, model='KR')\n sage: KRT(-1, -4, 3, 2).epsilon(1)\n 1\n sage: KRT(-1, -4, 3, 2).epsilon(3)\n 0\n "
if (i == self.parent()._cartan_type.special_node()):
return KirillovReshetikhinTableauxElement.epsilon(self, i)
return (KirillovReshetikhinTableauxElement.epsilon(self, i) // 2)
def phi(self, i):
"\n Compute `\\varphi_i` of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,1], 4, 1, model='KR')\n sage: KRT(-1, -4, 3, 2).phi(1)\n 0\n sage: KRT(-1, -4, 3, 2).phi(3)\n 1\n "
if (i == self.parent()._cartan_type.special_node()):
return KirillovReshetikhinTableauxElement.phi(self, i)
return (KirillovReshetikhinTableauxElement.phi(self, i) // 2)
@cached_method
def to_array(self, rows=True):
"\n Return a 2-dimensional array representation of this\n Kirillov-Reshetikhin element.\n\n If the output is in rows, then it outputs the top row first (in the\n English convention) from left to right.\n\n For example: if the reading word is `[2, 1, 4, 3]`, so as a\n `2 \\times 2` tableau::\n\n 1 3\n 2 4\n\n we output ``[[1, 3], [2, 4]]``.\n\n If the output is in columns, then it outputs the leftmost column first\n with the bottom element first. In other words this parses the reading\n word into its columns.\n\n Continuing with the previous example, the output would be\n ``[[2, 1], [4, 3]]``.\n\n INPUT:\n\n - ``rows`` -- (Default: ``True``) Set to ``True`` if the resulting\n array is by row, otherwise it is by column.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 4, 3, model='KR')\n sage: elt = KRT(-3,-4,2,1,-3,-4,2,1,-2,-4,3,1)\n sage: elt.to_array()\n [[1, 1, 1], [2, 2, 3], [-4, -4, -4], [-3, -3, -2]]\n sage: elt.to_array(False)\n [[-3, -4, 2, 1], [-3, -4, 2, 1], [-2, -4, 3, 1]]\n "
ret_list = []
h = self.parent()._cartan_type.classical().rank()
s = self.parent()._s
if rows:
for i in reversed(range(h)):
row = []
for j in range(s):
row.append(self[((j * h) + i)])
ret_list.append(row)
else:
for j in range(s):
col = []
for i in range(h):
col.append(self[((j * h) + i)])
ret_list.append(col)
return ret_list
def left_split(self):
"\n Return the image of ``self`` under the left column splitting map.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 4, 3, model='KR')\n sage: elt = KRT(-3,-4,2,1,-3,-4,2,1,-2,-4,3,1); elt.pp()\n 1 1 1\n 2 2 3\n -4 -4 -4\n -3 -3 -2\n sage: elt.left_split().pp()\n 1 (X) 1 1\n 2 2 3\n -4 -4 -4\n -3 -3 -2\n "
P = self.parent()
if (P._s == 1):
raise ValueError('cannot split a single column')
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
h = P._cartan_type.classical().rank()
TP = TensorProductOfKirillovReshetikhinTableaux(P._cartan_type, [[P._r, 1], [P._r, (P._s - 1)]])
lf = TP.crystals[0](*self[:h])
rf = TP.crystals[1](*self[h:])
return TP(lf, rf)
@cached_method
def classical_weight(self):
"\n Return the classical weight of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 1], 4, 1, model='KR')\n sage: KRT.module_generators[0].classical_weight()\n (1/2, 1/2, 1/2, 1/2)\n "
F = self.cartan_type().classical().root_system()
if (F.ambient_space() is None):
WLR = F.weight_lattice()
else:
WLR = F.ambient_space()
return (sum((self[j].weight() for j in range(len(self))), WLR.zero()) / 2)
|
class KRTableauxDTwistedSpin(KRTableauxRectangle):
"\n Kirillov-Reshetikhin tableaux `B^{r,s}` of type `D_n^{(2)}` with `r = n`.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 2], 1, 1, model='KR')\n sage: KRT.cardinality()\n 8\n sage: KRC = crystals.KirillovReshetikhin(['D', 4, 2], 1, 1, model='KN')\n sage: KRT.cardinality() == KRC.cardinality()\n True\n "
Element = KRTableauxSpinElement
|
class KRTableauxTypeFromRCElement(KirillovReshetikhinTableauxElement):
'\n A Kirillov-Reshetikhin tableau constructed from rigged configurations\n under the bijection `\\Phi`.\n '
def e(self, i):
"\n Perform the action of `e_i` on ``self``.\n\n .. TODO::\n\n Implement a direct action of `e_0` without moving to\n rigged configurations.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,3], 2, 1, model='KR')\n sage: KRT.module_generators[0].e(0)\n [[2], [E]]\n "
if (i == self.parent().cartan_type().special_node()):
P = self.parent()
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
K = TensorProductOfKirillovReshetikhinTableaux(P.cartan_type(), [[2, P.s()]])
ret = K(self).to_rigged_configuration()
RC = ret.parent()
ret = ret.to_virtual_configuration().e(0)
if (ret is None):
return None
ret = RC.from_virtual(ret)
return ret.to_tensor_product_of_kirillov_reshetikhin_tableaux()[0]
return TensorProductOfRegularCrystalsElement.e(self, i)
def f(self, i):
"\n Perform the action of `f_i` on ``self``.\n\n .. TODO::\n\n Implement a direct action of `f_0` without moving to\n rigged configurations.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,3], 2, 1, model='KR')\n sage: KRT.module_generators[0].f(0)\n sage: KRT.module_generators[3].f(0)\n [[1], [0]]\n "
if (i == self.parent().cartan_type().special_node()):
P = self.parent()
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
K = TensorProductOfKirillovReshetikhinTableaux(P.cartan_type(), [[2, P.s()]])
ret = K(self).to_rigged_configuration()
RC = ret.parent()
ret = ret.to_virtual_configuration().f(0)
if (ret is None):
return None
ret = RC.from_virtual(ret)
return ret.to_tensor_product_of_kirillov_reshetikhin_tableaux()[0]
return TensorProductOfRegularCrystalsElement.f(self, i)
def epsilon(self, i):
"\n Compute `\\varepsilon_i` of ``self``.\n\n .. TODO::\n\n Implement a direct action of `\\epsilon_0` without moving to\n KR crystals.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,3], 2, 2, model='KR')\n sage: KRT.module_generators[0].epsilon(0)\n 6\n "
if (i == self.parent().cartan_type().special_node()):
P = self.parent()
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
K = TensorProductOfKirillovReshetikhinTableaux(P.cartan_type(), [[2, P.s()]])
rc = K(self).to_rigged_configuration().to_virtual_configuration()
return rc.epsilon(0)
return TensorProductOfRegularCrystalsElement.epsilon(self, i)
def phi(self, i):
"\n Compute `\\varphi_i` of ``self``.\n\n .. TODO::\n\n Compute `\\phi_0` without moving to KR crystals.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,3], 2, 2, model='KR')\n sage: KRT.module_generators[0].phi(0)\n 0\n "
if (i == self.parent().cartan_type().special_node()):
P = self.parent()
from sage.combinat.rigged_configurations.tensor_product_kr_tableaux import TensorProductOfKirillovReshetikhinTableaux
K = TensorProductOfKirillovReshetikhinTableaux(P.cartan_type(), [[2, P.s()]])
rc = K(self).to_rigged_configuration().to_virtual_configuration()
return rc.phi(0)
return TensorProductOfRegularCrystalsElement.phi(self, i)
|
class KRTableauxTypeFromRC(KirillovReshetikhinTableaux):
'\n Kirillov-Reshetikhin tableaux `B^{r,s}` constructed from rigged\n configurations under the bijection `\\Phi`.\n\n .. WARNING::\n\n The Kashiwara-Nakashima version is not implemented due to the\n non-trivial multiplicities of classical components, so\n :meth:`classical_decomposition` does not work.\n '
def __init__(self, cartan_type, r, s):
"\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D', 4, 3], 2, 1, model='KR')\n sage: TestSuite(KRT).run() # long time\n "
self._r = r
self._s = s
self._cartan_type = cartan_type
Parent.__init__(self, category=KirillovReshetikhinCrystals())
self.letters = CrystalOfLetters(cartan_type.classical())
@lazy_attribute
def module_generators(self):
"\n The module generators of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,3], 2, 1, model='KR')\n sage: KRT.module_generators\n ([[1], [2]], [[1], [0]], [[1], [E]], [[E], [E]])\n "
return self._build_module_generators()
def _build_module_generators(self):
"\n Return the module generators of ``self``.\n\n EXAMPLES::\n\n sage: KRT = crystals.KirillovReshetikhin(['D',4,3], 2, 1, model='KR')\n sage: KRT._build_module_generators()\n ([[1], [2]], [[1], [0]], [[1], [E]], [[E], [E]])\n "
from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations
RC = RiggedConfigurations(self._cartan_type, [[self._r, self._s]])
return tuple((mg.to_tensor_product_of_kirillov_reshetikhin_tableaux()[0] for mg in RC.module_generators))
@lazy_attribute
def _tableau_height(self):
"\n The height of the tableaux in ``self``.\n\n EXAMPLES::\n\n sage: ct = CartanType(['E',6,1])\n sage: [crystals.KirillovReshetikhin(ct, r, 1, model='KR')._tableau_height\n ....: for r in ct.classical().index_set()]\n [1, 3, 2, 3, 4, 2]\n "
if (self._cartan_type.type() == 'E'):
if (self._cartan_type.classical().rank() == 6):
if (self._r == 1):
return 1
if (self._r == [3, 6]):
return 2
if (self._r in [2, 4]):
return 3
if (self._r == 5):
return 4
if (self._cartan_type.classical().rank() == 7):
if (self._r <= 3):
return (self._r + 1)
return (8 - self._r)
if (self._cartan_type.classical().rank() == 8):
if (self._r <= 3):
return (self._r + 1)
return (9 - self._r)
if (not self._cartan_type.is_untwisted_affine()):
if (self._cartan_type.dual().type() == 'G'):
return self._r
return (len(self.module_generators[0]) // self._s)
Element = KRTableauxTypeFromRCElement
|
class CrystalOfRiggedConfigurations(UniqueRepresentation, Parent):
"\n A highest weight crystal of rigged configurations.\n\n The crystal structure for finite simply-laced types is given\n in [CrysStructSchilling06]_. These were then shown to be the crystal\n operators in all finite types in [SS2015]_, all simply-laced and\n a large class of foldings of simply-laced types in [SS2015II]_,\n and all symmetrizable types (uniformly) in [SS2017]_.\n\n INPUT:\n\n - ``cartan_type`` -- (optional) a Cartan type or a Cartan type\n given as a folding\n\n - ``wt`` -- the highest weight vector in the weight lattice\n\n EXAMPLES:\n\n For simplicity, we display the rigged configurations horizontally::\n\n sage: RiggedConfigurations.options.display='horizontal'\n\n We start with a simply-laced finite type::\n\n sage: La = RootSystem(['A', 2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1] + La[2])\n sage: mg = RC.highest_weight_vector()\n sage: mg.f_string([1,2])\n 0[ ]0 0[ ]-1\n sage: mg.f_string([1,2,2])\n 0[ ]0 -2[ ][ ]-2\n sage: mg.f_string([1,2,2,2])\n sage: mg.f_string([2,1,1,2])\n -1[ ][ ]-1 -1[ ][ ]-1\n sage: RC.cardinality()\n 8\n sage: T = crystals.Tableaux(['A', 2], shape=[2,1])\n sage: RC.digraph().is_isomorphic(T.digraph(), edge_labels=True)\n True\n\n We construct a non-simply-laced affine type::\n\n sage: La = RootSystem(['C', 3]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[2])\n sage: mg = RC.highest_weight_vector()\n sage: mg.f_string([2,3])\n (/) 1[ ]1 -1[ ]-1\n sage: T = crystals.Tableaux(['C', 3], shape=[1,1])\n sage: RC.digraph().is_isomorphic(T.digraph(), edge_labels=True)\n True\n\n We can construct rigged configurations using a diagram folding of\n a simply-laced type. This yields an equivalent but distinct crystal::\n\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[2])\n sage: mg = RC.highest_weight_vector()\n sage: mg.f_string([2,3])\n (/) 0[ ]0 -1[ ]-1\n sage: T = crystals.Tableaux(['C', 3], shape=[1,1])\n sage: RC.digraph().is_isomorphic(T.digraph(), edge_labels=True)\n True\n\n We reset the global options::\n\n sage: RiggedConfigurations.options._reset()\n\n REFERENCES:\n\n - [SS2015]_\n - [SS2015II]_\n - [SS2017]_\n "
@staticmethod
def __classcall_private__(cls, cartan_type, wt=None, WLR=None):
"\n Normalize the input arguments to ensure unique representation.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A', 2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1])\n sage: RC2 = crystals.RiggedConfigurations(['A', 2], La[1])\n sage: RC3 = crystals.RiggedConfigurations(['A', 2], La[1], La[1].parent())\n sage: RC is RC2 and RC2 is RC3\n True\n\n sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()\n sage: LaE = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1])\n sage: RCE = crystals.RiggedConfigurations(LaE[1])\n sage: RC is RCE\n False\n "
from sage.combinat.root_system.type_folded import CartanTypeFolded
if (wt is None):
wt = cartan_type
cartan_type = wt.parent().cartan_type()
elif (not isinstance(cartan_type, CartanTypeFolded)):
cartan_type = CartanType(cartan_type)
if (WLR is None):
WLR = wt.parent()
else:
wt = WLR(wt)
if isinstance(cartan_type, CartanTypeFolded):
return CrystalOfNonSimplyLacedRC(cartan_type, wt, WLR)
return super().__classcall__(cls, wt, WLR=WLR)
def __init__(self, wt, WLR):
"\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A', 2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1] + La[2])\n sage: TestSuite(RC).run()\n\n sage: La = RootSystem(['A', 2, 1]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[0])\n sage: TestSuite(RC).run() # long time\n "
self._cartan_type = WLR.cartan_type()
self._wt = wt
self._rc_index = self._cartan_type.index_set()
self._rc_index_inverse = {i: ii for (ii, i) in enumerate(self._rc_index)}
self._cartan_matrix = self._cartan_type.cartan_matrix()
if self._cartan_type.is_finite():
category = ClassicalCrystals()
else:
category = (RegularCrystals(), HighestWeightCrystals(), InfiniteEnumeratedSets())
Parent.__init__(self, category=category)
n = self._cartan_type.rank()
self.module_generators = (self.element_class(self, partition_list=[[] for _ in repeat(None, n)]),)
options = RiggedConfigurations.options
def _repr_(self):
"\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A', 3]).weight_lattice().fundamental_weights()\n sage: crystals.RiggedConfigurations(La[1])\n Crystal of rigged configurations of type ['A', 3] and weight Lambda[1]\n "
return 'Crystal of rigged configurations of type {0} and weight {1}'.format(self._cartan_type, self._wt)
def _element_constructor_(self, *lst, **options):
"\n Construct a ``RiggedConfigurationElement``.\n\n Typically the user should not call this method since it does not check\n if it is an actual configuration in the crystal. Instead the user\n should use the iterator.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A', 2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1] + La[2])\n sage: RC(partition_list=[[1],[1]], rigging_list=[[0],[-1]])\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]-1\n <BLANKLINE>\n sage: RC(partition_list=[[1],[2]])\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -2[ ][ ]-2\n <BLANKLINE>\n\n TESTS:\n\n Check that :trac:`17054` is fixed::\n\n sage: La = RootSystem(['A', 2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(4*La[1] + 4*La[2])\n sage: B = crystals.infinity.RiggedConfigurations(['A',2])\n sage: x = B.an_element().f_string([2,2,1,1,2,1,2,1])\n sage: ascii_art(x)\n -4[ ][ ][ ][ ]-4 -4[ ][ ][ ][ ]0\n sage: ascii_art(RC(x.nu()))\n 0[ ][ ][ ][ ]-4 0[ ][ ][ ][ ]0\n sage: x == B.an_element().f_string([2,2,1,1,2,1,2,1])\n True\n "
if isinstance(lst[0], (list, tuple)):
lst = lst[0]
if isinstance(lst[0], RiggedPartition):
lst = [p._clone() for p in lst]
elif isinstance(lst[0], RiggedConfigurationElement):
lst = [p._clone() for p in lst[0]]
return self.element_class(self, list(lst), **options)
def _calc_vacancy_number(self, partitions, a, i, **options):
"\n Calculate the vacancy number `p_i^{(a)}(\\nu)` in ``self``.\n\n This assumes that `\\gamma_a = 1` for all `a` and\n `(\\alpha_a | \\alpha_b ) = A_{ab}`.\n\n INPUT:\n\n - ``partitions`` -- the list of rigged partitions we are using\n\n - ``a`` -- the rigged partition index\n\n - ``i`` -- the row length\n\n TESTS::\n\n sage: La = RootSystem(['A', 2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1] + La[2])\n sage: elt = RC(partition_list=[[1],[2]])\n sage: RC._calc_vacancy_number(elt.nu(), 1, 2)\n -2\n "
vac_num = self._wt[self.index_set()[a]]
for (b, nu) in enumerate(partitions):
val = self._cartan_matrix[(a, b)]
if val:
if (i == float('inf')):
vac_num -= (val * sum(nu))
else:
vac_num -= (val * nu.get_num_cells_to_column(i))
return vac_num
def weight_lattice_realization(self):
"\n Return the weight lattice realization used to express the weights\n of elements in ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A', 2, 1]).weight_lattice(extended=True).fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[0])\n sage: RC.weight_lattice_realization()\n Extended weight lattice of the Root system of type ['A', 2, 1]\n "
return self._wt.parent()
Element = RCHighestWeightElement
|
class CrystalOfNonSimplyLacedRC(CrystalOfRiggedConfigurations):
'\n Highest weight crystal of rigged configurations in non-simply-laced type.\n '
def __init__(self, vct, wt, WLR):
"\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['C', 3]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1])\n sage: TestSuite(RC).run()\n "
self._folded_ct = vct
CrystalOfRiggedConfigurations.__init__(self, wt, WLR)
@lazy_attribute
def virtual(self):
"\n Return the corresponding virtual crystal.\n\n EXAMPLES::\n\n sage: La = RootSystem(['C', 2, 1]).weight_lattice().fundamental_weights()\n sage: vct = CartanType(['C', 2, 1]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[0])\n sage: RC\n Crystal of rigged configurations of type ['C', 2, 1] and weight Lambda[0]\n sage: RC.virtual\n Crystal of rigged configurations of type ['A', 3, 1] and weight 2*Lambda[0]\n "
P = self._folded_ct._folding.root_system().weight_lattice()
gamma = self._folded_ct.scaling_factors()
sigma = self._folded_ct.folding_orbit()
vwt = P.sum_of_terms(((b, (gamma[a] * c)) for (a, c) in self._wt for b in sigma[a]))
return CrystalOfRiggedConfigurations(vwt)
def _calc_vacancy_number(self, partitions, a, i, **options):
"\n Calculate the vacancy number `p_i^{(a)}(\\nu)` in ``self``.\n\n INPUT:\n\n - ``partitions`` -- the list of rigged partitions we are using\n\n - ``a`` -- the rigged partition index\n\n - ``i`` -- the row length\n\n TESTS::\n\n sage: La = RootSystem(['C', 3]).weight_lattice().fundamental_weights()\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[2])\n sage: elt = RC(partition_list=[[], [1], [1]])\n sage: RC._calc_vacancy_number(elt.nu(), 1, 1)\n 0\n sage: RC._calc_vacancy_number(elt.nu(), 2, 1)\n -1\n "
I = self.index_set()
ia = I[a]
vac_num = self._wt[ia]
if (i == float('inf')):
return (vac_num - sum(((self._cartan_matrix[(a, b)] * sum(nu)) for (b, nu) in enumerate(partitions))))
gamma = self._folded_ct.scaling_factors()
g = gamma[ia]
for (b, nu) in enumerate(partitions):
ib = I[b]
q = nu.get_num_cells_to_column((g * i), gamma[ib])
vac_num -= ((self._cartan_matrix[(a, b)] * q) / gamma[ib])
return vac_num
def to_virtual(self, rc):
"\n Convert ``rc`` into a rigged configuration in the virtual crystal.\n\n INPUT:\n\n - ``rc`` -- a rigged configuration element\n\n EXAMPLES::\n\n sage: La = RootSystem(['C', 3]).weight_lattice().fundamental_weights()\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[2])\n sage: elt = RC(partition_list=[[], [1], [1]]); elt\n <BLANKLINE>\n (/)\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n sage: RC.to_virtual(elt)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -2[ ][ ]-2\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n (/)\n <BLANKLINE>\n "
gamma = [int(f) for f in self._folded_ct.scaling_factors()]
sigma = self._folded_ct._orbit
n = self._folded_ct._folding.rank()
vindex = self._folded_ct._folding.index_set()
partitions = ([None] * n)
riggings = ([None] * n)
for (a, rp) in enumerate(rc):
for i in sigma[a]:
k = vindex.index(i)
partitions[k] = [(row_len * gamma[a]) for row_len in rp._list]
riggings[k] = [(rig_val * gamma[a]) for rig_val in rp.rigging]
return self.virtual.element_class(self.virtual, partition_list=partitions, rigging_list=riggings)
def from_virtual(self, vrc):
"\n Convert ``vrc`` in the virtual crystal into a rigged configuration of\n the original Cartan type.\n\n INPUT:\n\n - ``vrc`` -- a virtual rigged configuration\n\n EXAMPLES::\n\n sage: La = RootSystem(['C', 3]).weight_lattice().fundamental_weights()\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[2])\n sage: elt = RC(partition_list=[[0], [1], [1]])\n sage: elt == RC.from_virtual(RC.to_virtual(elt))\n True\n "
gamma = list(self._folded_ct.scaling_factors())
sigma = self._folded_ct._orbit
n = self._cartan_type.rank()
partitions = ([None] * n)
riggings = ([None] * n)
vindex = self._folded_ct._folding.index_set()
for a in range(n):
index = vindex.index(sigma[a][0])
partitions[a] = [(row_len // gamma[a]) for row_len in vrc[index]._list]
riggings[a] = [(rig_val / gamma[a]) for rig_val in vrc[index].rigging]
return self.element_class(self, partition_list=partitions, rigging_list=riggings)
Element = RCHWNonSimplyLacedElement
|
class InfinityCrystalOfRiggedConfigurations(UniqueRepresentation, Parent):
"\n Rigged configuration model for `\\mathcal{B}(\\infty)`.\n\n The crystal is generated by the empty rigged configuration with the same\n crystal structure given by the :class:`highest weight model\n <sage.combinat.rigged_configurations.rc_crystal.CrystalOfRiggedConfigurations>`\n except we remove the condition that the resulting rigged configuration\n needs to be valid when applying `f_a`.\n\n INPUT:\n\n - ``cartan_type`` -- a Cartan type\n\n EXAMPLES:\n\n For simplicity, we display all of the rigged configurations\n horizontally::\n\n sage: RiggedConfigurations.options(display='horizontal')\n\n We begin with a simply-laced finite type::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 3]); RC\n The infinity crystal of rigged configurations of type ['A', 3]\n\n sage: RC.options(display='horizontal')\n\n sage: mg = RC.highest_weight_vector(); mg\n (/) (/) (/)\n sage: elt = mg.f_string([2,1,3,2]); elt\n 0[ ]0 -2[ ]-1 0[ ]0\n -2[ ]-1\n sage: elt.e(1)\n sage: elt.e(3)\n sage: mg.f_string([2,1,3,2]).e(2)\n -1[ ]-1 0[ ]1 -1[ ]-1\n sage: mg.f_string([2,3,2,1,3,2])\n 0[ ]0 -3[ ][ ]-1 -1[ ][ ]-1\n -2[ ]-1\n\n Next we consider a non-simply-laced finite type::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['C', 3])\n sage: mg = RC.highest_weight_vector()\n sage: mg.f_string([2,1,3,2])\n 0[ ]0 -1[ ]0 0[ ]0\n -1[ ]-1\n sage: mg.f_string([2,3,2,1,3,2])\n 0[ ]-1 -1[ ][ ]-1 -1[ ][ ]0\n -1[ ]0\n\n We can construct rigged configurations using a diagram folding of\n a simply-laced type. This yields an equivalent but distinct crystal::\n\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: VRC = crystals.infinity.RiggedConfigurations(vct)\n sage: mg = VRC.highest_weight_vector()\n sage: mg.f_string([2,1,3,2])\n 0[ ]0 -2[ ]-1 0[ ]0\n -2[ ]-1\n sage: mg.f_string([2,3,2,1,3,2])\n -1[ ]-1 -2[ ][ ][ ]-1 -1[ ][ ]0\n\n sage: G = RC.subcrystal(max_depth=5).digraph()\n sage: VG = VRC.subcrystal(max_depth=5).digraph()\n sage: G.is_isomorphic(VG, edge_labels=True)\n True\n\n We can also construct `B(\\infty)` using rigged configurations in\n affine types::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 3, 1])\n sage: mg = RC.highest_weight_vector()\n sage: mg.f_string([0,1,2,3,0,1,3])\n -1[ ]0 -1[ ]-1 1[ ]1 -1[ ][ ]-1\n -1[ ]0 -1[ ]-1\n\n sage: RC = crystals.infinity.RiggedConfigurations(['C', 3, 1])\n sage: mg = RC.highest_weight_vector()\n sage: mg.f_string([1,2,3,0,1,2,3,3,0])\n -2[ ][ ]-1 0[ ]1 0[ ]0 -4[ ][ ][ ]-2\n 0[ ]0 0[ ]-1\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 6, 2])\n sage: mg = RC.highest_weight_vector()\n sage: mg.f_string([1,2,3,0,1,2,3,3,0])\n 0[ ]-1 0[ ]1 0[ ]0 -4[ ][ ][ ]-2\n 0[ ]-1 0[ ]1 0[ ]-1\n\n We reset the global options::\n\n sage: RiggedConfigurations.options._reset()\n "
@staticmethod
def __classcall_private__(cls, cartan_type):
"\n Normalize the input arguments to ensure unique representation.\n\n EXAMPLES::\n\n sage: RC1 = crystals.infinity.RiggedConfigurations(CartanType(['A',3]))\n sage: RC2 = crystals.infinity.RiggedConfigurations(['A',3])\n sage: RC2 is RC1\n True\n "
from sage.combinat.root_system.type_folded import CartanTypeFolded
if isinstance(cartan_type, CartanTypeFolded):
return InfinityCrystalOfNonSimplyLacedRC(cartan_type)
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: RC = crystals.infinity.RiggedConfigurations(['A', 2])\n sage: TestSuite(RC).run()\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 2, 1])\n sage: TestSuite(RC).run() # long time\n sage: RC = crystals.infinity.RiggedConfigurations(['C', 2])\n sage: TestSuite(RC).run() # long time\n sage: RC = crystals.infinity.RiggedConfigurations(['C', 2, 1])\n sage: TestSuite(RC).run() # long time\n "
self._cartan_type = cartan_type
Parent.__init__(self, category=HighestWeightCrystals().Infinite())
self._rc_index = self._cartan_type.index_set()
self._rc_index_inverse = {i: ii for (ii, i) in enumerate(self._rc_index)}
self._cartan_matrix = self._cartan_type.cartan_matrix()
self.module_generators = (self.element_class(self, rigging_list=([[]] * cartan_type.rank())),)
options = RiggedConfigurations.options
def _repr_(self):
"\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: crystals.infinity.RiggedConfigurations(['A', 3])\n The infinity crystal of rigged configurations of type ['A', 3]\n "
return 'The infinity crystal of rigged configurations of type {}'.format(self._cartan_type)
def _element_constructor_(self, lst=None, **options):
"\n Construct an element of ``self`` from ``lst``.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 3, 1])\n sage: ascii_art(RC(partition_list=[[1,1]]*4, rigging_list=[[1,1], [0,0], [0,0], [-1,-1]]))\n 0[ ]1 0[ ]0 0[ ]0 0[ ]-1\n 0[ ]1 0[ ]0 0[ ]0 0[ ]-1\n\n sage: RC = crystals.infinity.RiggedConfigurations(['C', 3])\n sage: ascii_art(RC(partition_list=[[1],[1,1],[1]], rigging_list=[[0],[0,-1],[0]]))\n 0[ ]0 -1[ ]0 0[ ]0\n -1[ ]-1\n\n TESTS:\n\n Check that :trac:`17054` is fixed::\n\n sage: RC = RiggedConfigurations(['A',2,1], [[1,1]]*4 + [[2,1]]*4)\n sage: B = crystals.infinity.RiggedConfigurations(['A',2])\n sage: x = RC().f_string([2,2,1,1,2,1,2,1])\n sage: ascii_art(x)\n 0[ ][ ][ ][ ]-4 0[ ][ ][ ][ ]0\n sage: ascii_art(B(x))\n -4[ ][ ][ ][ ]-4 -4[ ][ ][ ][ ]0\n sage: x == RC().f_string([2,2,1,1,2,1,2,1])\n True\n "
if isinstance(lst, RiggedConfigurationElement):
lst = [p._clone() for p in lst]
elif (isinstance(lst, list) and bool(lst) and isinstance(lst[0], RiggedPartition)):
lst = [p._clone() for p in lst]
return self.element_class(self, lst, **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: RC._coerce_map_from_(T)\n Crystal Isomorphism morphism:\n From: The infinity crystal of tableaux of type ['A', 3]\n To: The infinity crystal of rigged configurations of type ['A', 3]\n "
if self.cartan_type().is_finite():
from sage.combinat.crystals.infinity_crystals import InfinityCrystalOfTableaux
if (isinstance(P, InfinityCrystalOfTableaux) and self.cartan_type().is_simply_laced()):
from sage.combinat.rigged_configurations.bij_infinity import FromTableauIsomorphism
return FromTableauIsomorphism(Hom(P, self))
return super()._coerce_map_from_(P)
def _calc_vacancy_number(self, partitions, a, i, **options):
"\n Calculate the vacancy number `p_i^{(a)}(\\nu)` in ``self``.\n\n This assumes that `\\gamma_a = 1` for all `a` and `(\\alpha_a \\mid\n \\alpha_b ) = A_{ab}`.\n\n INPUT:\n\n - ``partitions`` -- the list of rigged partitions we are using\n\n - ``a`` -- the rigged partition index\n\n - ``i`` -- the row length\n\n TESTS::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 4])\n sage: elt = RC(partition_list=[[1], [1], [], []])\n sage: RC._calc_vacancy_number(elt.nu(), 0, 1)\n -1\n "
if (i == float('inf')):
return (- sum(((self._cartan_matrix[(a, b)] * sum(nu)) for (b, nu) in enumerate(partitions))))
return (- sum(((self._cartan_matrix[(a, b)] * nu.get_num_cells_to_column(i)) for (b, nu) in enumerate(partitions))))
def weight_lattice_realization(self):
"\n Return the weight lattice realization used to express the weights\n of elements in ``self``.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 2, 1])\n sage: RC.weight_lattice_realization()\n Extended weight lattice of the Root system of type ['A', 2, 1]\n "
R = self._cartan_type.root_system()
if self._cartan_type.is_affine():
return R.weight_lattice(extended=True)
if (self._cartan_type.is_finite() and R.ambient_space()):
return R.ambient_space()
return R.weight_lattice()
class Element(RiggedConfigurationElement):
"\n A rigged configuration in `\\mathcal{B}(\\infty)` in simply-laced types.\n\n TESTS::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 3, 1])\n sage: elt = RC(partition_list=[[1,1]]*4, rigging_list=[[1,1], [0,0], [0,0], [-1,-1]])\n sage: TestSuite(elt).run()\n "
def weight(self):
"\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 3, 1])\n sage: elt = RC(partition_list=[[1,1]]*4, rigging_list=[[1,1], [0,0], [0,0], [-1,-1]])\n sage: elt.weight()\n -2*delta\n "
P = self.parent().weight_lattice_realization()
alpha = list(P.simple_roots())
return (- sum(((sum(x) * alpha[i]) for (i, x) in enumerate(self))))
|
class InfinityCrystalOfNonSimplyLacedRC(InfinityCrystalOfRiggedConfigurations):
'\n Rigged configurations for `\\mathcal{B}(\\infty)` in non-simply-laced types.\n '
def __init__(self, vct):
"\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: vct = CartanType(['C', 2]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: TestSuite(RC).run() # long time\n sage: vct = CartanType(['C', 2, 1]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: TestSuite(RC).run() # long time\n "
self._folded_ct = vct
InfinityCrystalOfRiggedConfigurations.__init__(self, vct._cartan_type)
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(['C',3])\n sage: vct = CartanType(['C',3]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: RC._coerce_map_from_(T)\n Crystal Isomorphism morphism:\n From: The infinity crystal of tableaux of type ['C', 3]\n To: The infinity crystal of rigged configurations of type ['C', 3]\n "
if self.cartan_type().is_finite():
from sage.combinat.crystals.infinity_crystals import InfinityCrystalOfTableaux
if isinstance(P, InfinityCrystalOfTableaux):
from sage.combinat.rigged_configurations.bij_infinity import FromTableauIsomorphism
return FromTableauIsomorphism(Hom(P, self))
return super()._coerce_map_from_(P)
def _calc_vacancy_number(self, partitions, a, i):
"\n Calculate the vacancy number `p_i^{(a)}(\\nu)` in ``self``.\n\n INPUT:\n\n - ``partitions`` -- the list of rigged partitions we are using\n\n - ``a`` -- the rigged partition index\n\n - ``i`` -- the row length\n\n TESTS::\n\n sage: La = RootSystem(['C', 2]).weight_lattice().fundamental_weights()\n sage: vct = CartanType(['C', 2]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[1])\n sage: elt = RC(partition_list=[[1], [1]])\n sage: RC._calc_vacancy_number(elt.nu(), 0, 1)\n 0\n sage: RC._calc_vacancy_number(elt.nu(), 1, 1)\n -1\n "
I = self.index_set()
ia = I[a]
vac_num = 0
if (i == float('inf')):
return (- sum(((self._cartan_matrix[(a, b)] * sum(nu)) for (b, nu) in enumerate(partitions))))
gamma = self._folded_ct.scaling_factors()
g = gamma[ia]
for b in range(self._cartan_matrix.ncols()):
ib = I[b]
q = partitions[b].get_num_cells_to_column((g * i), gamma[ib])
vac_num -= ((self._cartan_matrix[(a, b)] * q) // gamma[ib])
return vac_num
@lazy_attribute
def virtual(self):
"\n Return the corresponding virtual crystal.\n\n EXAMPLES::\n\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: RC\n The infinity crystal of rigged configurations of type ['C', 3]\n sage: RC.virtual\n The infinity crystal of rigged configurations of type ['A', 5]\n "
return InfinityCrystalOfRiggedConfigurations(self._folded_ct._folding)
def to_virtual(self, rc):
"\n Convert ``rc`` into a rigged configuration in the virtual crystal.\n\n INPUT:\n\n - ``rc`` -- a rigged configuration element\n\n EXAMPLES::\n\n sage: vct = CartanType(['C', 2]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: mg = RC.highest_weight_vector()\n sage: elt = mg.f_string([1,2,2,1,1]); elt\n <BLANKLINE>\n -3[ ][ ][ ]-2\n <BLANKLINE>\n -1[ ][ ]0\n <BLANKLINE>\n sage: velt = RC.to_virtual(elt); velt\n <BLANKLINE>\n -3[ ][ ][ ]-2\n <BLANKLINE>\n -2[ ][ ][ ][ ]0\n <BLANKLINE>\n -3[ ][ ][ ]-2\n <BLANKLINE>\n sage: velt.parent()\n The infinity crystal of rigged configurations of type ['A', 3]\n "
gamma = [int(f) for f in self._folded_ct.scaling_factors()]
sigma = self._folded_ct._orbit
n = self._folded_ct._folding.rank()
vindex = self._folded_ct._folding.index_set()
partitions = ([None] * n)
riggings = ([None] * n)
for (a, rp) in enumerate(rc):
for i in sigma[a]:
k = vindex.index(i)
partitions[k] = [(row_len * gamma[a]) for row_len in rp._list]
riggings[k] = [(rig_val * gamma[a]) for rig_val in rp.rigging]
return self.virtual.element_class(self.virtual, partition_list=partitions, rigging_list=riggings)
def from_virtual(self, vrc):
"\n Convert ``vrc`` in the virtual crystal into a rigged configuration of\n the original Cartan type.\n\n INPUT:\n\n - ``vrc`` -- a virtual rigged configuration\n\n EXAMPLES::\n\n sage: vct = CartanType(['C', 2]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: elt = RC(partition_list=[[3],[2]], rigging_list=[[-2],[0]])\n sage: vrc_elt = RC.to_virtual(elt)\n sage: ret = RC.from_virtual(vrc_elt); ret\n <BLANKLINE>\n -3[ ][ ][ ]-2\n <BLANKLINE>\n -1[ ][ ]0\n <BLANKLINE>\n sage: ret == elt\n True\n "
gamma = list(self._folded_ct.scaling_factors())
sigma = self._folded_ct._orbit
n = self._cartan_type.rank()
partitions = ([None] * n)
riggings = ([None] * n)
vindex = self._folded_ct._folding.index_set()
for a in range(n):
index = vindex.index(sigma[a][0])
partitions[a] = [(row_len // gamma[a]) for row_len in vrc[index]._list]
riggings[a] = [(rig_val / gamma[a]) for rig_val in vrc[index].rigging]
return self.element_class(self, partition_list=partitions, rigging_list=riggings)
class Element(RCNonSimplyLacedElement):
"\n A rigged configuration in `\\mathcal{B}(\\infty)` in\n non-simply-laced types.\n\n TESTS::\n\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: elt = RC(partition_list=[[1],[1,1],[1]])\n sage: TestSuite(elt).run()\n "
def weight(self):
"\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: vct = CartanType(['C', 3]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: elt = RC(partition_list=[[1],[1,1],[1]], rigging_list=[[0],[-1,-1],[0]])\n sage: elt.weight()\n (-1, -1, 0)\n\n sage: vct = CartanType(['F', 4, 1]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: mg = RC.highest_weight_vector()\n sage: elt = mg.f_string([1,0,3,4,2,2]); ascii_art(elt)\n -1[ ]-1 0[ ]1 -2[ ][ ]-2 0[ ]1 -1[ ]-1\n sage: wt = elt.weight(); wt\n -Lambda[0] + Lambda[1] - 2*Lambda[2] + 3*Lambda[3] - Lambda[4] - delta\n sage: al = RC.weight_lattice_realization().simple_roots()\n sage: wt == -(al[0] + al[1] + 2*al[2] + al[3] + al[4])\n True\n "
P = self.parent().weight_lattice_realization()
alpha = list(P.simple_roots())
return (- sum(((sum(x) * alpha[i]) for (i, x) in enumerate(self))))
|
class RiggedConfigurationElement(ClonableArray):
"\n A rigged configuration for simply-laced types.\n\n For more information on rigged configurations, see\n :class:`RiggedConfigurations`. For rigged configurations for\n non-simply-laced types, use :class:`RCNonSimplyLacedElement`.\n\n Typically to create a specific rigged configuration, the user will pass in\n the optional argument ``partition_list`` and if the user wants to specify\n the rigging values, give the optional argument ``rigging_list`` as well.\n If ``rigging_list`` is not passed, the rigging values are set to the\n corresponding vacancy numbers.\n\n INPUT:\n\n - ``parent`` -- the parent of this element\n\n - ``rigged_partitions`` -- a list of rigged partitions\n\n There are two optional arguments to explicitly construct a rigged\n configuration. The first is ``partition_list`` which gives a list of\n partitions, and the second is ``rigging_list`` which is a list of\n corresponding lists of riggings. If only partition_list is specified,\n then it sets the rigging equal to the calculated vacancy numbers.\n\n If we are constructing a rigged configuration from a rigged configuration\n (say of another type) and we don't want to recompute the vacancy numbers,\n we can use the ``use_vacancy_numbers`` to avoid the recomputation.\n\n EXAMPLES:\n\n Type `A_n^{(1)}` examples::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 2]])\n sage: RC(partition_list=[[2], [2, 2], [2], [2]])\n <BLANKLINE>\n 0[ ][ ]0\n <BLANKLINE>\n -2[ ][ ]-2\n -2[ ][ ]-2\n <BLANKLINE>\n 2[ ][ ]2\n <BLANKLINE>\n -2[ ][ ]-2\n <BLANKLINE>\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[1, 1], [1, 1]])\n sage: RC(partition_list=[[], [], [], []])\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n\n Type `D_n^{(1)}` examples::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: RC(partition_list=[[3], [3,2], [4], [3]])\n <BLANKLINE>\n -1[ ][ ][ ]-1\n <BLANKLINE>\n 1[ ][ ][ ]1\n 0[ ][ ]0\n <BLANKLINE>\n -3[ ][ ][ ][ ]-3\n <BLANKLINE>\n -1[ ][ ][ ]-1\n <BLANKLINE>\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[1, 1], [2, 1]])\n sage: RC(partition_list=[[1], [1,1], [1], [1]])\n <BLANKLINE>\n 1[ ]1\n <BLANKLINE>\n 0[ ]0\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n sage: elt = RC(partition_list=[[1], [1,1], [1], [1]], rigging_list=[[0], [0,0], [0], [0]]); elt\n <BLANKLINE>\n 1[ ]0\n <BLANKLINE>\n 0[ ]0\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n\n sage: from sage.combinat.rigged_configurations.rigged_partition import RiggedPartition\n sage: RC2 = RiggedConfigurations(['D', 5, 1], [[2, 1], [3, 1]])\n sage: l = [RiggedPartition()] + list(elt)\n sage: ascii_art(RC2(*l))\n (/) 1[ ]0 0[ ]0 0[ ]0 0[ ]0\n 0[ ]0\n sage: ascii_art(RC2(*l, use_vacancy_numbers=True))\n (/) 1[ ]0 0[ ]0 0[ ]0 0[ ]0\n 0[ ]0\n "
def __init__(self, parent, rigged_partitions=[], **options):
"\n Construct a rigged configuration element.\n\n .. WARNING::\n\n This changes the vacancy numbers of the rigged partitions, so\n if the rigged partitions comes from another rigged configuration,\n a deep copy should be made before being passed here. We do not\n make a deep copy here because the crystal operators generate\n their own rigged partitions. See :trac:`17054`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: RC(partition_list=[[], [], [], []])\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: RC(partition_list=[[1], [1], [], []])\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: elt = RC(partition_list=[[1], [1], [], []], rigging_list=[[-1], [0], [], []]); elt\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: TestSuite(elt).run()\n "
n = options.get('n', parent._cartan_type.rank())
if ('partition_list' in options):
data = options['partition_list']
if (len(data) == 0):
nu = []
for i in range(n):
nu.append(RiggedPartition())
else:
if (len(data) != n):
raise ValueError('incorrect number of partitions')
nu = []
if ('rigging_list' in options):
rigging_data = options['rigging_list']
if (len(rigging_data) != n):
raise ValueError('incorrect number of riggings')
for i in range(n):
nu.append(RiggedPartition(tuple(data[i]), list(rigging_data[i])))
else:
for partition_data in data:
nu.append(RiggedPartition(tuple(partition_data)))
elif ((n == len(rigged_partitions)) and isinstance(rigged_partitions[0], RiggedPartition)):
if options.get('use_vacancy_numbers', False):
ClonableArray.__init__(self, parent, rigged_partitions)
return
nu = rigged_partitions
else:
nu = []
for i in range(n):
nu.append(RiggedPartition())
for (a, partition) in enumerate(nu):
if (len(partition) <= 0):
continue
block_len = partition[0]
vac_num = parent._calc_vacancy_number(nu, a, block_len)
for (i, row_len) in enumerate(partition):
if (block_len != row_len):
vac_num = parent._calc_vacancy_number(nu, a, row_len)
block_len = row_len
partition.vacancy_numbers[i] = vac_num
if (partition.rigging[i] is None):
partition.rigging[i] = partition.vacancy_numbers[i]
ClonableArray.__init__(self, parent, nu)
def check(self):
"\n Check the rigged configuration is properly defined.\n\n There is nothing to check here.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 4])\n sage: b = RC.module_generators[0].f_string([1,2,1,1,2,4,2,3,3,2])\n sage: b.check()\n "
pass
def _repr_(self):
"\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: elt = RC(partition_list=[[2], [3,1], [3], [3]]); elt\n <BLANKLINE>\n -1[ ][ ]-1\n <BLANKLINE>\n 2[ ][ ][ ]2\n 0[ ]0\n <BLANKLINE>\n -2[ ][ ][ ]-2\n <BLANKLINE>\n -2[ ][ ][ ]-2\n <BLANKLINE>\n sage: RC.options(display='horizontal')\n sage: elt\n -1[ ][ ]-1 2[ ][ ][ ]2 -2[ ][ ][ ]-2 -2[ ][ ][ ]-2\n 0[ ]0\n sage: RC.options._reset()\n "
return self.parent().options._dispatch(self, '_repr_', 'display')
def _repr_vertical(self):
"\n Return the string representation of ``self`` vertically.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: print(RC(partition_list=[[2], [3,1], [3], [3]])._repr_vertical())\n <BLANKLINE>\n -1[ ][ ]-1\n <BLANKLINE>\n 2[ ][ ][ ]2\n 0[ ]0\n <BLANKLINE>\n -2[ ][ ][ ]-2\n <BLANKLINE>\n -2[ ][ ][ ]-2\n <BLANKLINE>\n sage: print(RC(partition_list=[[],[],[],[]])._repr_vertical())\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n "
ret_str = ''
for tableau in self:
ret_str += ('\n' + repr(tableau))
return ret_str
def _repr_horizontal(self):
"\n Return the string representation of ``self`` horizontally.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: print(RC(partition_list=[[2], [3,1], [3], [3]])._repr_horizontal())\n -1[ ][ ]-1 2[ ][ ][ ]2 -2[ ][ ][ ]-2 -2[ ][ ][ ]-2\n 0[ ]0\n sage: print(RC(partition_list=[[],[],[],[]])._repr_horizontal())\n (/) (/) (/) (/)\n "
tab_str = [repr(x).splitlines() for x in self]
height = max((len(t) for t in tab_str))
widths = [max((len(x) for x in t)) for t in tab_str]
ret_str = ''
for i in range(height):
if (i != 0):
ret_str += '\n'
for (j, t) in enumerate(tab_str):
if (j != 0):
ret_str += ' '
if (i < len(t)):
ret_str += (t[i] + (' ' * (widths[j] - len(t[i]))))
else:
ret_str += (' ' * widths[j])
return ret_str
def _latex_(self):
"\n Return the LaTeX representation of ``self``.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: latex(RC(partition_list=[[2], [3,1], [3], [3]]))\n {\n \\begin{array}[t]{r|c|c|l}\n \\cline{2-3} -1 &\\phantom{|}&\\phantom{|}& -1 \\\\\n \\cline{2-3}\n \\end{array}\n }\n \\quad\n {\n \\begin{array}[t]{r|c|c|c|l}\n \\cline{2-4} 2 &\\phantom{|}&\\phantom{|}&\\phantom{|}& 2 \\\\\n \\cline{2-4} 0 &\\phantom{|}& \\multicolumn{3 }{l}{ 0 } \\\\\n \\cline{2-2}\n \\end{array}\n }\n \\quad\n {\n \\begin{array}[t]{r|c|c|c|l}\n \\cline{2-4} -2 &\\phantom{|}&\\phantom{|}&\\phantom{|}& -2 \\\\\n \\cline{2-4}\n \\end{array}\n }\n \\quad\n {\n \\begin{array}[t]{r|c|c|c|l}\n \\cline{2-4} -2 &\\phantom{|}&\\phantom{|}&\\phantom{|}& -2 \\\\\n \\cline{2-4}\n \\end{array}\n }\n sage: latex(RC(partition_list=[[],[],[],[]]))\n {\\emptyset}\n \\quad\n {\\emptyset}\n \\quad\n {\\emptyset}\n \\quad\n {\\emptyset}\n "
ret_string = self[0]._latex_()
for partition in self[1:]:
ret_string += ('\n\\quad\n' + partition._latex_())
return ret_string
def _ascii_art_(self):
"\n Return an ASCII art representation of ``self``.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: ascii_art(RC(partition_list=[[2], [3,1], [3], [3]]))\n -1[ ][ ]-1 2[ ][ ][ ]2 -2[ ][ ][ ]-2 -2[ ][ ][ ]-2\n 0[ ]0\n sage: ascii_art(RC(partition_list=[[],[],[],[]]))\n (/) (/) (/) (/)\n sage: RC = RiggedConfigurations(['D', 7, 1], [[3,3],[5,2],[4,3],[2,3],[4,4],[3,1],[1,4],[2,2]])\n sage: elt = RC(partition_list=[[2],[3,2,1],[2,2,1,1],[2,2,1,1,1,1],[3,2,1,1,1,1],[2,1,1],[2,2]],\n ....: rigging_list=[[2],[1,0,0],[4,1,2,1],[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,0],[0,0]])\n sage: ascii_art(elt)\n 3[ ][ ]2 1[ ][ ][ ]1 4[ ][ ]4 2[ ][ ]1 0[ ][ ][ ]0 0[ ][ ]0 0[ ][ ]0\n 2[ ][ ]0 4[ ][ ]1 2[ ][ ]0 2[ ][ ]1 0[ ]0 0[ ][ ]0\n 1[ ]0 3[ ]2 0[ ]0 0[ ]0 0[ ]0\n 3[ ]1 0[ ]0 0[ ]0\n 0[ ]0 0[ ]0\n 0[ ]0 0[ ]0\n sage: Partitions.options(convention='French')\n sage: ascii_art(elt)\n 0[ ]0 0[ ]0\n 0[ ]0 0[ ]0\n 3[ ]1 0[ ]0 0[ ]0\n 1[ ]0 3[ ]2 0[ ]0 0[ ]0 0[ ]0\n 2[ ][ ]0 4[ ][ ]1 2[ ][ ]0 2[ ][ ]1 0[ ]0 0[ ][ ]0\n 3[ ][ ]2 1[ ][ ][ ]1 4[ ][ ]4 2[ ][ ]1 0[ ][ ][ ]0 0[ ][ ]0 0[ ][ ]0\n sage: Partitions.options._reset()\n "
from sage.combinat.partition import Partitions
if (Partitions.options.convention == 'French'):
baseline = (lambda s: 0)
else:
baseline = len
from sage.typeset.ascii_art import AsciiArt
s = repr(self[0]).splitlines()
ret = AsciiArt(s, baseline=baseline(s))
for tableau in self[1:]:
s = repr(tableau).splitlines()
ret += (AsciiArt([' '], baseline=baseline(s)) + AsciiArt(s, baseline=baseline(s)))
return ret
def nu(self):
"\n Return the list `\\nu` of rigged partitions of this rigged\n configuration element.\n\n OUTPUT:\n\n The `\\nu` array as a list.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 2]])\n sage: RC(partition_list=[[2], [2,2], [2], [2]]).nu()\n [0[ ][ ]0\n , -2[ ][ ]-2\n -2[ ][ ]-2\n , 2[ ][ ]2\n , -2[ ][ ]-2\n ]\n "
return list(self)
def e(self, a):
"\n Return the action of the crystal operator `e_a` on ``self``.\n\n This implements the method defined in [CrysStructSchilling06]_ which\n finds the value `k` which is the length of the string with the\n smallest negative rigging of smallest length. Then it removes a box\n from a string of length `k` in the `a`-th rigged partition, keeping all\n colabels fixed and increasing the new label by one. If no such string\n exists, then `e_a` is undefined.\n\n This method can also be used when the underlying Cartan matrix is a\n Borcherds-Cartan matrix. In this case, then method of [SS2018]_ is\n used, where the new label is increased by half of the `a`-th diagonal\n entry of the underlying Borcherds-Cartan matrix. This method will also\n return ``None`` if `a` is imaginary and the smallest rigging in the\n `a`-th rigged partition is not exactly half of the `a`-th diagonal entry\n of the Borcherds-Cartan matrix.\n\n INPUT:\n\n - ``a`` -- the index of the partition to remove a box\n\n OUTPUT:\n\n The resulting rigged configuration element.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2,1]])\n sage: elt = RC(partition_list=[[1], [1], [1], [1]])\n sage: elt.e(3)\n sage: elt.e(1)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n\n sage: A = CartanMatrix([[-2,-1],[-1,-2]], borcherds=True)\n sage: RC = crystals.infinity.RiggedConfigurations(A)\n sage: nu0 = RC(partition_list=[[],[]])\n sage: nu = nu0.f_string([1,0,0,0])\n sage: ascii_art(nu.e(0))\n 5[ ]3 4[ ]3\n 5[ ]1\n "
if (a not in self.parent()._rc_index_inverse):
raise ValueError('{} is not in the index set'.format(a))
a = self.parent()._rc_index_inverse[a]
M = self.parent()._cartan_matrix
new_list = self[a][:]
new_vac_nums = self[a].vacancy_numbers[:]
new_rigging = self[a].rigging[:]
if (M[(a, a)] != 2):
k = None
set_vac_num = True
if (new_rigging[(- 1)] != ((- M[(a, a)]) // 2)):
return None
new_list.pop()
new_vac_nums.pop()
new_rigging.pop()
else:
k = None
num_rows = len(new_list)
cur_rigging = (- 1)
rigging_index = None
for i in range(num_rows):
if (new_rigging[i] <= cur_rigging):
cur_rigging = new_rigging[i]
rigging_index = i
if (rigging_index is None):
return None
k = new_list[rigging_index]
set_vac_num = False
if (k == 1):
new_list.pop()
new_vac_nums.pop()
new_rigging.pop()
else:
new_list[rigging_index] -= 1
cur_rigging += (M[(a, a)] // 2)
j = (rigging_index + 1)
if ((j < num_rows) and (new_list[j] == new_list[rigging_index])):
new_vac_nums[rigging_index] = new_vac_nums[j]
set_vac_num = True
while ((j < num_rows) and (new_list[j] == new_list[rigging_index]) and (new_rigging[j] > cur_rigging)):
new_rigging[(j - 1)] = new_rigging[j]
j += 1
new_rigging[(j - 1)] = cur_rigging
new_partitions = []
for b in range(len(self)):
if (b != a):
new_partitions.append(self._generate_partition_e(a, b, k))
else:
for i in range(len(new_vac_nums)):
if ((k is not None) and (new_list[i] < k)):
break
new_vac_nums[i] += M[(a, b)]
new_rigging[i] += M[(a, b)]
if ((k != 1) and (not set_vac_num)):
new_vac_nums[rigging_index] += 2
new_partitions.append(RiggedPartition(new_list, new_rigging, new_vac_nums))
ret_RC = self.__class__(self.parent(), new_partitions, use_vacancy_numbers=True)
nu = ret_RC.nu()
if ((k != 1) and (not set_vac_num)):
ret_RC[a].vacancy_numbers[rigging_index] = self.parent()._calc_vacancy_number(nu, a, nu[a][rigging_index])
return ret_RC
def _generate_partition_e(self, a, b, k):
"\n Generate a new partition for a given value of `a` by updating the\n vacancy numbers and preserving co-labels for the map `e_a`.\n\n INPUT:\n\n - ``a`` -- the index of the partition we operated on\n - ``b`` -- the index of the partition to generate\n - ``k`` -- the length of the string with the smallest negative\n rigging of smallest length\n\n OUTPUT:\n\n The constructed rigged partition.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2,1]])\n sage: RC(partition_list=[[1], [1], [1], [1]])._generate_partition_e(1, 2, 1)\n -1[ ]-1\n <BLANKLINE>\n "
if (not self.parent()._cartan_matrix[(a, b)]):
return self[b]
new_list = self[b]._list
new_vac_nums = self[b].vacancy_numbers[:]
new_rigging = self[b].rigging[:]
value = self.parent()._cartan_matrix[(b, a)]
for i in range(len(new_vac_nums)):
if ((k is not None) and (new_list[i] < k)):
break
new_vac_nums[i] += value
new_rigging[i] += value
return RiggedPartition(new_list, new_rigging, new_vac_nums)
def f(self, a):
"\n Return the action of the crystal operator `f_a` on ``self``.\n\n This implements the method defined in [CrysStructSchilling06]_ which\n finds the value `k` which is the length of the string with the\n smallest nonpositive rigging of largest length. Then it adds a box from\n a string of length `k` in the `a`-th rigged partition, keeping all\n colabels fixed and decreasing the new label by one. If no such string\n exists, then it adds a new string of length 1 with label `-1`. However\n we need to modify the definition to work for `B(\\infty)` by removing\n the condition that the resulting rigged configuration is valid.\n\n This method can also be used when the underlying Cartan matrix is a\n Borcherds-Cartan matrix. In this case, then method of [SS2018]_ is\n used, where the new label is decreased by half of the `a`-th diagonal\n entry of the underlying Borcherds-Cartan matrix.\n\n INPUT:\n\n - ``a`` -- the index of the partition to add a box\n\n OUTPUT:\n\n The resulting rigged configuration element.\n\n EXAMPLES::\n\n sage: RC = crystals.infinity.RiggedConfigurations(['A', 3])\n sage: nu0 = RC.module_generators[0]\n sage: nu0.f(2)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n -2[ ]-1\n <BLANKLINE>\n (/)\n <BLANKLINE>\n\n sage: A = CartanMatrix([[-2,-1],[-1,-2]], borcherds=True)\n sage: RC = crystals.infinity.RiggedConfigurations(A)\n sage: nu0 = RC(partition_list=[[],[]])\n sage: nu = nu0.f_string([1,0,0,0])\n sage: ascii_art(nu.f(0))\n 9[ ]7 6[ ]5\n 9[ ]5\n 9[ ]3\n 9[ ]1\n "
if (a not in self.parent()._rc_index_inverse):
raise ValueError('{} is not in the index set'.format(a))
a = self.parent()._rc_index_inverse[a]
M = self.parent()._cartan_matrix
new_list = self[a][:]
new_vac_nums = self[a].vacancy_numbers[:]
new_rigging = self[a].rigging[:]
k = None
add_index = (- 1)
rigging_index = None
cur_rigging = ZZ.zero()
num_rows = len(new_list)
for i in reversed(range(num_rows)):
if ((add_index is None) and (new_list[i] != new_list[rigging_index])):
add_index = (i + 1)
if (new_rigging[i] <= cur_rigging):
cur_rigging = new_rigging[i]
k = new_list[i]
rigging_index = i
add_index = None
if (k is None):
new_list.append(1)
new_rigging.append(((- M[(a, a)]) // 2))
new_vac_nums.append(None)
k = 0
add_index = num_rows
num_rows += 1
else:
if (add_index is None):
add_index = 0
new_list[add_index] += 1
new_rigging.insert(add_index, (new_rigging[rigging_index] - (M[(a, a)] // 2)))
new_vac_nums.insert(add_index, None)
new_rigging.pop((rigging_index + 1))
new_vac_nums.pop((rigging_index + 1))
new_partitions = []
for b in range(len(self)):
if (b != a):
new_partitions.append(self._generate_partition_f(a, b, k))
else:
for i in range(num_rows):
if (new_list[i] <= k):
break
if (i != add_index):
new_vac_nums[i] -= M[(a, b)]
new_rigging[i] -= M[(a, b)]
new_partitions.append(RiggedPartition(new_list, new_rigging, new_vac_nums))
new_partitions[a].vacancy_numbers[add_index] = self.parent()._calc_vacancy_number(new_partitions, a, new_partitions[a][add_index])
return self.__class__(self.parent(), new_partitions, use_vacancy_numbers=True)
def _generate_partition_f(self, a, b, k):
"\n Generate a new partition for a given value of `a` by updating the\n vacancy numbers and preserving co-labels for the map `f_a`.\n\n INPUT:\n\n - ``a`` -- the index of the partition we operated on\n - ``b`` -- the index of the partition to generate\n - ``k`` -- the length of the string with smallest nonpositive rigging\n of largest length\n\n OUTPUT:\n\n The constructed rigged partition.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2,1]])\n sage: RC(partition_list=[[1], [1], [1], [1]])._generate_partition_f(1, 2, 1)\n 0[ ]0\n <BLANKLINE>\n "
if (not self.parent()._cartan_matrix[(a, b)]):
return self[b]
new_list = self[b]._list
new_vac_nums = self[b].vacancy_numbers[:]
new_rigging = self[b].rigging[:]
value = self.parent()._cartan_matrix[(b, a)]
for i in range(len(new_vac_nums)):
if (new_list[i] <= k):
break
new_vac_nums[i] -= value
new_rigging[i] -= value
return RiggedPartition(new_list, new_rigging, new_vac_nums)
def epsilon(self, a):
"\n Return `\\varepsilon_a` of ``self``.\n\n Let `x_{\\ell}` be the smallest string of `\\nu^{(a)}` or `0` if\n `\\nu^{(a)} = \\emptyset`, then we have\n `\\varepsilon_a = -\\min(0, x_{\\ell})`.\n\n EXAMPLES::\n\n sage: La = RootSystem(['B',2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1]+La[2])\n sage: I = RC.index_set()\n sage: matrix([[rc.epsilon(i) for i in I] for rc in RC[:4]])\n [0 0]\n [1 0]\n [0 1]\n [0 2]\n "
a = self.parent()._rc_index_inverse[a]
if (not self[a]):
return ZZ.zero()
return Integer((- min(0, min(self[a].rigging))))
def phi(self, a):
"\n Return `\\varphi_a` of ``self``.\n\n Let `x_{\\ell}` be the smallest string of `\\nu^{(a)}` or `0` if\n `\\nu^{(a)} = \\emptyset`, then we have\n `\\varepsilon_a = p_{\\infty}^{(a)} - \\min(0, x_{\\ell})`.\n\n EXAMPLES::\n\n sage: La = RootSystem(['B',2]).weight_lattice().fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(La[1]+La[2])\n sage: I = RC.index_set()\n sage: matrix([[rc.phi(i) for i in I] for rc in RC[:4]])\n [1 1]\n [0 3]\n [0 2]\n [1 1]\n "
a = self.parent()._rc_index_inverse[a]
p_inf = self.parent()._calc_vacancy_number(self, a, float('inf'))
if (not self[a]):
return Integer(p_inf)
return Integer((p_inf - min(0, min(self[a].rigging))))
def vacancy_number(self, a, i):
"\n Return the vacancy number `p_i^{(a)}`.\n\n INPUT:\n\n - ``a`` -- the index of the rigged partition\n\n - ``i`` -- the row of the rigged partition\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 2]])\n sage: elt = RC(partition_list=[[1], [2,1], [1], []])\n sage: elt.vacancy_number(2, 3)\n -2\n sage: elt.vacancy_number(2, 2)\n -2\n sage: elt.vacancy_number(2, 1)\n -1\n\n sage: RC = RiggedConfigurations(['D',4,1], [[2,1], [2,1]])\n sage: x = RC(partition_list=[[3], [3,1,1], [2], [3,1]]); ascii_art(x)\n -1[ ][ ][ ]-1 1[ ][ ][ ]1 0[ ][ ]0 -3[ ][ ][ ]-3\n 0[ ]0 -1[ ]-1\n 0[ ]0\n sage: x.vacancy_number(2,2)\n 1\n "
a = self.parent()._rc_index_inverse[a]
return self.parent()._calc_vacancy_number(self, a, i)
def partition_rigging_lists(self):
"\n Return the list of partitions and the associated list of riggings\n of ``self``.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A',3,1], [[1,2],[2,2]])\n sage: rc = RC(partition_list=[[2],[1],[1]], rigging_list=[[-1],[0],[-1]]); rc\n <BLANKLINE>\n -1[ ][ ]-1\n <BLANKLINE>\n 1[ ]0\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n sage: rc.partition_rigging_lists()\n [[[2], [1], [1]], [[-1], [0], [-1]]]\n "
partitions = []
riggings = []
for p in self:
partitions.append(list(p))
riggings.append(list(p.rigging))
return [partitions, riggings]
|
class RCNonSimplyLacedElement(RiggedConfigurationElement):
"\n Rigged configuration elements for non-simply-laced types.\n\n TESTS::\n\n sage: vct = CartanType(['C',2,1]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: elt = RC.module_generators[0].f_string([1,0,2,2,0,1]); elt\n <BLANKLINE>\n -2[ ][ ]-1\n <BLANKLINE>\n -2[ ]-1\n -2[ ]-1\n <BLANKLINE>\n -2[ ][ ]-1\n <BLANKLINE>\n sage: TestSuite(elt).run()\n "
def to_virtual_configuration(self):
"\n Return the corresponding rigged configuration in the virtual crystal.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['C',2,1], [[1,2],[1,1],[2,1]])\n sage: elt = RC(partition_list=[[3],[2]]); elt\n <BLANKLINE>\n 0[ ][ ][ ]0\n <BLANKLINE>\n 0[ ][ ]0\n sage: elt.to_virtual_configuration()\n <BLANKLINE>\n 0[ ][ ][ ]0\n <BLANKLINE>\n 0[ ][ ][ ][ ]0\n <BLANKLINE>\n 0[ ][ ][ ]0\n "
return self.parent().to_virtual(self)
def e(self, a):
"\n Return the action of `e_a` on ``self``.\n\n This works by lifting into the virtual configuration, then applying\n\n .. MATH::\n\n e^v_a = \\prod_{j \\in \\iota(a)} \\hat{e}_j^{\\gamma_j}\n\n and pulling back.\n\n EXAMPLES::\n\n sage: vct = CartanType(['C',2,1]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: elt = RC(partition_list=[[2],[1,1],[2]], rigging_list=[[-1],[-1,-1],[-1]])\n sage: ascii_art(elt.e(0))\n 0[ ]0 -2[ ]-1 -2[ ][ ]-1\n -2[ ]-1\n sage: ascii_art(elt.e(1))\n -3[ ][ ]-2 0[ ]1 -3[ ][ ]-2\n sage: ascii_art(elt.e(2))\n -2[ ][ ]-1 -2[ ]-1 0[ ]0\n -2[ ]-1\n "
vct = self.parent()._folded_ct
L = []
gamma = vct.scaling_factors()
for i in vct.folding_orbit()[a]:
L.extend(([i] * gamma[a]))
virtual_rc = self.parent().to_virtual(self).e_string(L)
if (virtual_rc is None):
return None
return self.parent().from_virtual(virtual_rc)
def f(self, a):
"\n Return the action of `f_a` on ``self``.\n\n This works by lifting into the virtual configuration, then applying\n\n .. MATH::\n\n f^v_a = \\prod_{j \\in \\iota(a)} \\hat{f}_j^{\\gamma_j}\n\n and pulling back.\n\n EXAMPLES::\n\n sage: vct = CartanType(['C',2,1]).as_folding()\n sage: RC = crystals.infinity.RiggedConfigurations(vct)\n sage: elt = RC(partition_list=[[2],[1,1],[2]], rigging_list=[[-1],[-1,-1],[-1]])\n sage: ascii_art(elt.f(0))\n -4[ ][ ][ ]-2 -2[ ]-1 -2[ ][ ]-1\n -2[ ]-1\n sage: ascii_art(elt.f(1))\n -1[ ][ ]0 -2[ ][ ]-2 -1[ ][ ]0\n -2[ ]-1\n sage: ascii_art(elt.f(2))\n -2[ ][ ]-1 -2[ ]-1 -4[ ][ ][ ]-2\n -2[ ]-1\n "
vct = self.parent()._folded_ct
L = []
gamma = vct.scaling_factors()
for i in vct.folding_orbit()[a]:
L.extend(([i] * gamma[a]))
virtual_rc = self.parent().to_virtual(self).f_string(L)
if (virtual_rc is None):
return None
return self.parent().from_virtual(virtual_rc)
|
class RCHighestWeightElement(RiggedConfigurationElement):
"\n Rigged configurations in highest weight crystals.\n\n TESTS::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(['A',2,1], La[0])\n sage: elt = RC(partition_list=[[1,1],[1],[2]]); elt\n <BLANKLINE>\n -1[ ]-1\n -1[ ]-1\n <BLANKLINE>\n 1[ ]1\n <BLANKLINE>\n -1[ ][ ]-1\n <BLANKLINE>\n sage: TestSuite(elt).run()\n "
def check(self):
"\n Make sure all of the riggings are less than or equal to the\n vacancy number.\n\n TESTS::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(['A',2,1], La[0])\n sage: elt = RC(partition_list=[[1,1],[1],[2]])\n sage: elt.check()\n "
for (a, partition) in enumerate(self):
for (i, vac_num) in enumerate(partition.vacancy_numbers):
if (vac_num < partition.rigging[i]):
raise ValueError('rigging can be at most the vacancy number')
def f(self, a):
"\n Return the action of the crystal operator `f_a` on ``self``.\n\n This implements the method defined in [CrysStructSchilling06]_ which\n finds the value `k` which is the length of the string with the\n smallest nonpositive rigging of largest length. Then it adds a box\n from a string of length `k` in the `a`-th rigged partition, keeping\n all colabels fixed and decreasing the new label by one. If no such\n string exists, then it adds a new string of length 1 with label `-1`.\n If any of the resulting vacancy numbers are larger than the labels\n (i.e. it is an invalid rigged configuration), then `f_a` is\n undefined.\n\n INPUT:\n\n - ``a`` -- the index of the partition to add a box\n\n OUTPUT:\n\n The resulting rigged configuration element.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: RC = crystals.RiggedConfigurations(['A',2,1], La[0])\n sage: elt = RC(partition_list=[[1,1],[1],[2]])\n sage: elt.f(0)\n <BLANKLINE>\n -2[ ][ ]-2\n -1[ ]-1\n <BLANKLINE>\n 1[ ]1\n <BLANKLINE>\n 0[ ][ ]0\n <BLANKLINE>\n sage: elt.f(1)\n <BLANKLINE>\n 0[ ]0\n 0[ ]0\n <BLANKLINE>\n -1[ ]-1\n -1[ ]-1\n <BLANKLINE>\n 0[ ][ ]0\n <BLANKLINE>\n sage: elt.f(2)\n "
if (not self.phi(a)):
return None
return RiggedConfigurationElement.f(self, a)
def weight(self):
"\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: B = crystals.RiggedConfigurations(['A',2,1], La[0])\n sage: mg = B.module_generators[0]\n sage: mg.f_string([0,1,2,0]).weight()\n -Lambda[0] + Lambda[1] + Lambda[2] - 2*delta\n "
P = self.parent().weight_lattice_realization()
alpha = list(P.simple_roots())
return (self.parent()._wt - sum(((sum(x) * alpha[i]) for (i, x) in enumerate(self))))
|
class RCHWNonSimplyLacedElement(RCNonSimplyLacedElement):
"\n Rigged configurations in highest weight crystals.\n\n TESTS::\n\n sage: La = RootSystem(['C',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: vct = CartanType(['C',2,1]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[0])\n sage: elt = RC(partition_list=[[1,1],[2],[2]]); ascii_art(elt)\n -1[ ]-1 2[ ][ ]2 -2[ ][ ]-2\n -1[ ]-1\n sage: TestSuite(elt).run()\n "
def check(self):
"\n Make sure all of the riggings are less than or equal to the\n vacancy number.\n\n TESTS::\n\n sage: La = RootSystem(['C',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: vct = CartanType(['C',2,1]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[0])\n sage: elt = RC(partition_list=[[1,1],[2],[2]])\n sage: elt.check()\n "
for partition in self:
for (i, vac_num) in enumerate(partition.vacancy_numbers):
if (vac_num < partition.rigging[i]):
raise ValueError('rigging can be at most the vacancy number')
def f(self, a):
"\n Return the action of `f_a` on ``self``.\n\n This works by lifting into the virtual configuration, then applying\n\n .. MATH::\n\n f^v_a = \\prod_{j \\in \\iota(a)} \\hat{f}_j^{\\gamma_j}\n\n and pulling back.\n\n EXAMPLES::\n\n sage: La = RootSystem(['C',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: vct = CartanType(['C',2,1]).as_folding()\n sage: RC = crystals.RiggedConfigurations(vct, La[0])\n sage: elt = RC(partition_list=[[1,1],[2],[2]])\n sage: elt.f(0)\n sage: ascii_art(elt.f(1))\n 0[ ]0 0[ ][ ]0 -1[ ][ ]-1\n 0[ ]0 -1[ ]-1\n sage: elt.f(2)\n "
if (not self.phi(a)):
return None
return RCNonSimplyLacedElement.f(self, a)
def weight(self):
"\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: La = RootSystem(['C',2,1]).weight_lattice(extended=True).fundamental_weights()\n sage: vct = CartanType(['C',2,1]).as_folding()\n sage: B = crystals.RiggedConfigurations(vct, La[0])\n sage: mg = B.module_generators[0]\n sage: mg.f_string([0,1,2]).weight()\n 2*Lambda[1] - Lambda[2] - delta\n "
P = self.parent().weight_lattice_realization()
alpha = list(P.simple_roots())
return (self.parent()._wt - sum(((sum(x) * alpha[i]) for (i, x) in enumerate(self))))
|
class KRRiggedConfigurationElement(RiggedConfigurationElement):
"\n `U_q^{\\prime}(\\mathfrak{g})` rigged configurations.\n\n EXAMPLES:\n\n We can go between :class:`rigged configurations <RiggedConfigurations>`\n and tensor products of :class:`tensor products of KR tableaux\n <sage.combinat.rigged_configurations.tensor_product_kr_tableaux.TensorProductOfKirillovReshetikhinTableaux>`::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[1,1], [2,1]])\n sage: rc_elt = RC(partition_list=[[1], [1,1], [1], [1]])\n sage: tp_krtab = rc_elt.to_tensor_product_of_kirillov_reshetikhin_tableaux(); tp_krtab\n [[-2]] (X) [[1], [2]]\n sage: tp_krcrys = rc_elt.to_tensor_product_of_kirillov_reshetikhin_crystals(); tp_krcrys\n [[[-2]], [[1], [2]]]\n sage: tp_krcrys == tp_krtab.to_tensor_product_of_kirillov_reshetikhin_crystals()\n True\n sage: RC(tp_krcrys) == rc_elt\n True\n sage: RC(tp_krtab) == rc_elt\n True\n sage: tp_krtab.to_rigged_configuration() == rc_elt\n True\n "
def __init__(self, parent, rigged_partitions=[], **options):
"\n Construct a rigged configuration element.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: RC(partition_list=[[], [], [], []])\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: RC(partition_list=[[1], [1], [], []])\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: elt = RC(partition_list=[[1], [1], [], []], rigging_list=[[-1], [0], [], []]); elt\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n (/)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: TestSuite(elt).run()\n "
n = len(parent._rc_index)
if ('KT_constructor' in options):
data = options['KT_constructor']
shape_data = data[0]
rigging_data = data[1]
vac_data = data[2]
nu = []
for i in range(n):
nu.append(RiggedPartition(shape_data[i], rigging_data[i], vac_data[i]))
if (parent.cartan_type().type() == 'B'):
nu[(- 1)] = RiggedPartitionTypeB(nu[(- 1)])
ClonableArray.__init__(self, parent, nu)
return
RiggedConfigurationElement.__init__(self, parent, rigged_partitions, n=n, **options)
if (parent.cartan_type().type() == 'B'):
self._set_mutable()
self[(- 1)] = RiggedPartitionTypeB(self[(- 1)])
self.set_immutable()
def check(self):
"\n Make sure all of the riggings are less than or equal to the\n vacancy number.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 1]])\n sage: elt = RC(partition_list=[[1], [1], [], []])\n sage: elt.check()\n "
for partition in self:
for (i, vac_num) in enumerate(partition.vacancy_numbers):
if (vac_num < partition.rigging[i]):
raise ValueError('rigging can be at most the vacancy number')
def e(self, a):
"\n Return the action of the crystal operator `e_a` on ``self``.\n\n For the classical operators, this implements the method defined\n in [CrysStructSchilling06]_. For `e_0`, this converts the class to\n a tensor product of KR tableaux and does the corresponding `e_0`\n and pulls back.\n\n .. TODO::\n\n Implement `e_0` without appealing to tensor product of\n KR tableaux.\n\n INPUT:\n\n - ``a`` -- the index of the partition to remove a box\n\n OUTPUT:\n\n The resulting rigged configuration element.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2,1]])\n sage: elt = RC(partition_list=[[1], [1], [1], [1]])\n sage: elt.e(3)\n sage: elt.e(1)\n <BLANKLINE>\n (/)\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n "
if (a not in self.parent()._cartan_type.index_set()):
raise ValueError('{} is not in the index set'.format(a))
if (a == self.parent()._cartan_type.special_node()):
try:
ret = self.to_tensor_product_of_kirillov_reshetikhin_tableaux().e(a)
if (ret is None):
return None
return ret.to_rigged_configuration()
except NotImplementedError:
return None
return RiggedConfigurationElement.e(self, a)
def f(self, a):
"\n Return the action of the crystal operator `f_a` on ``self``.\n\n For the classical operators, this implements the method defined\n in [CrysStructSchilling06]_. For `f_0`, this converts the class to\n a tensor product of KR tableaux and does the corresponding `f_0`\n and pulls back.\n\n .. TODO::\n\n Implement `f_0` without appealing to tensor product of\n KR tableaux.\n\n INPUT:\n\n - ``a`` -- the index of the partition to add a box\n\n OUTPUT:\n\n The resulting rigged configuration element.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2,1]])\n sage: elt = RC(partition_list=[[1], [1], [1], [1]])\n sage: elt.f(1)\n sage: elt.f(2)\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -1[ ]-1\n -1[ ]-1\n <BLANKLINE>\n 1[ ]1\n <BLANKLINE>\n -1[ ]-1\n <BLANKLINE>\n "
ct = self.parent()._cartan_type
if (a not in ct.index_set()):
raise ValueError('{} is not in the index set'.format(a))
if (a == ct.special_node()):
try:
ret = self.to_tensor_product_of_kirillov_reshetikhin_tableaux().f(a)
if (ret is None):
return None
return ret.to_rigged_configuration()
except NotImplementedError:
return None
if (not self.phi(a)):
return None
return RiggedConfigurationElement.f(self, a)
def epsilon(self, a):
"\n Return `\\varepsilon_a` of ``self``.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: I = RC.index_set()\n sage: matrix([[mg.epsilon(i) for i in I] for mg in RC.module_generators])\n [4 0 0 0 0]\n [3 0 0 0 0]\n [2 0 0 0 0]\n "
if (a == self.parent()._cartan_type.special_node()):
return self.to_tensor_product_of_kirillov_reshetikhin_tableaux().epsilon(a)
return RiggedConfigurationElement.epsilon(self, a)
def phi(self, a):
"\n Return `\\varphi_a` of ``self``.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: I = RC.index_set()\n sage: matrix([[mg.phi(i) for i in I] for mg in RC.module_generators])\n [0 0 2 0 0]\n [1 0 1 0 0]\n [2 0 0 0 0]\n "
if (a == self.parent()._cartan_type.special_node()):
return self.to_tensor_product_of_kirillov_reshetikhin_tableaux().phi(a)
return RiggedConfigurationElement.phi(self, a)
def weight(self):
"\n Return the weight of ``self``.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['E', 6, 1], [[2,2]])\n sage: [x.weight() for x in RC.module_generators]\n [-4*Lambda[0] + 2*Lambda[2], -2*Lambda[0] + Lambda[2], 0]\n sage: KR = crystals.KirillovReshetikhin(['E',6,1], 2,2)\n sage: [x.weight() for x in KR.module_generators] # long time\n [0, -2*Lambda[0] + Lambda[2], -4*Lambda[0] + 2*Lambda[2]]\n\n sage: RC = RiggedConfigurations(['D', 6, 1], [[4,2]])\n sage: [x.weight() for x in RC.module_generators]\n [-4*Lambda[0] + 2*Lambda[4], -4*Lambda[0] + Lambda[2] + Lambda[4],\n -2*Lambda[0] + Lambda[4], -4*Lambda[0] + 2*Lambda[2],\n -2*Lambda[0] + Lambda[2], 0]\n "
WLR = self.parent().weight_lattice_realization()
La = WLR.fundamental_weights()
cl_index = self.parent()._rc_index
wt = WLR.sum((((self.phi(i) - self.epsilon(i)) * La[i]) for i in cl_index))
return (((- wt.level()) * La[0]) + wt)
@cached_method
def classical_weight(self):
"\n Return the classical weight of ``self``.\n\n The classical weight `\\Lambda` of a rigged configuration is\n\n .. MATH::\n\n \\Lambda = \\sum_{a \\in \\overline{I}} \\sum_{i > 0}\n i L_i^{(a)} \\Lambda_a - \\sum_{a \\in \\overline{I}} \\sum_{i > 0}\n i m_i^{(a)} \\alpha_a.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D',4,1], [[2,2]])\n sage: elt = RC(partition_list=[[2],[2,1],[1],[1]])\n sage: elt.classical_weight()\n (0, 1, 1, 0)\n\n This agrees with the corresponding classical weight as KR tableaux::\n\n sage: krt = elt.to_tensor_product_of_kirillov_reshetikhin_tableaux(); krt\n [[2, 1], [3, -1]]\n sage: krt.classical_weight() == elt.classical_weight()\n True\n\n TESTS:\n\n We check the classical weights agree in an entire crystal::\n\n sage: RC = RiggedConfigurations(['A',2,1], [[2,1], [1,1]])\n sage: for x in RC:\n ....: y = x.to_tensor_product_of_kirillov_reshetikhin_tableaux()\n ....: assert x.classical_weight() == y.classical_weight()\n "
F = self.cartan_type().classical().root_system()
if (F.ambient_space() is None):
WLR = F.weight_lattice()
else:
WLR = F.ambient_space()
La = WLR.fundamental_weights()
wt = WLR.sum(((La[r] * s) for (r, s) in self.parent().dims))
alpha = WLR.simple_roots()
rc_index = self.parent()._rc_index
for (a, nu) in enumerate(self):
wt -= (sum(nu) * alpha[rc_index[a]])
return wt
def to_tensor_product_of_kirillov_reshetikhin_tableaux(self, display_steps=False, build_graph=False):
"\n Perform the bijection from this rigged configuration to a tensor\n product of Kirillov-Reshetikhin tableaux given in [RigConBijection]_\n for single boxes and with [BijectionLRT]_ and [BijectionDn]_ for\n multiple columns and rows.\n\n .. NOTE::\n\n This is only proven to be a bijection in types `A_n^{(1)}`\n and `D_n^{(1)}`, as well as `\\bigotimes_i B^{r_i,1}` and\n `\\bigotimes_i B^{1,s_i}` for general affine types.\n\n INPUT:\n\n - ``display_steps`` -- (default: ``False``) boolean which indicates\n if we want to print each step in the algorithm\n - ``build_graph`` -- (default: ``False``) boolean which indicates\n if we want to construct and return a graph of the bijection whose\n vertices are rigged configurations obtained at each step and edges\n are labeled by either the return value of `\\delta` or the\n doubling/halving map\n\n OUTPUT:\n\n - The tensor product of KR tableaux element corresponding to this\n rigged configuration.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 4, 1], [[2, 2]])\n sage: RC(partition_list=[[2], [2,2], [2], [2]]).to_tensor_product_of_kirillov_reshetikhin_tableaux()\n [[3, 3], [5, 5]]\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: elt = RC(partition_list=[[2], [2,2], [1], [1]])\n sage: tp_krt = elt.to_tensor_product_of_kirillov_reshetikhin_tableaux(); tp_krt\n [[2, 3], [3, -2]]\n\n This is invertible by calling\n :meth:`~sage.combinat.rigged_configurations.tensor_product_kr_tableaux_element.TensorProductOfKirillovReshetikhinTableauxElement.to_rigged_configuration()`::\n\n sage: ret = tp_krt.to_rigged_configuration(); ret\n <BLANKLINE>\n 0[ ][ ]0\n <BLANKLINE>\n -2[ ][ ]-2\n -2[ ][ ]-2\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n sage: elt == ret\n True\n\n To view the steps of the bijection in the output, run with\n the ``display_steps=True`` option::\n\n sage: elt.to_tensor_product_of_kirillov_reshetikhin_tableaux(True)\n ====================\n ...\n ====================\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n -2[ ][ ]-2\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n --------------------\n [[3, 2]]\n --------------------\n ...\n [[2, 3], [3, -2]]\n\n We can also construct and display a graph of the bijection\n as follows::\n\n sage: ret, G = elt.to_tensor_product_of_kirillov_reshetikhin_tableaux(build_graph=True)\n sage: view(G) # not tested\n "
from sage.combinat.rigged_configurations.bijection import RCToKRTBijection
bij = RCToKRTBijection(self)
ret = bij.run(display_steps, build_graph)
if build_graph:
return (ret, bij._graph)
return ret
def to_tensor_product_of_kirillov_reshetikhin_crystals(self, display_steps=False, build_graph=False):
"\n Return the corresponding tensor product of Kirillov-Reshetikhin\n crystals.\n\n This is a composition of the map to a tensor product of KR tableaux,\n and then to a tensor product of KR crystals.\n\n INPUT:\n\n - ``display_steps`` -- (default: ``False``) boolean which indicates\n if we want to print each step in the algorithm\n - ``build_graph`` -- (default: ``False``) boolean which indicates\n if we want to construct and return a graph of the bijection whose\n vertices are rigged configurations obtained at each step and edges\n are labeled by either the return value of `\\delta` or the\n doubling/halving map\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])\n sage: elt = RC(partition_list=[[2], [2,2], [1], [1]])\n sage: krc = elt.to_tensor_product_of_kirillov_reshetikhin_crystals(); krc\n [[[2, 3], [3, -2]]]\n\n We can recover the rigged configuration::\n\n sage: ret = RC(krc); ret\n <BLANKLINE>\n 0[ ][ ]0\n <BLANKLINE>\n -2[ ][ ]-2\n -2[ ][ ]-2\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n sage: elt == ret\n True\n\n We can also construct and display a graph of the bijection\n as follows::\n\n sage: ret, G = elt.to_tensor_product_of_kirillov_reshetikhin_crystals(build_graph=True)\n sage: view(G) # not tested\n "
if build_graph:
(kr_tab, G) = self.to_tensor_product_of_kirillov_reshetikhin_tableaux(display_steps, build_graph)
return (kr_tab.to_tensor_product_of_kirillov_reshetikhin_crystals(), G)
kr_tab = self.to_tensor_product_of_kirillov_reshetikhin_tableaux(display_steps)
return kr_tab.to_tensor_product_of_kirillov_reshetikhin_crystals()
def left_split(self):
"\n Return the image of ``self`` under the left column splitting\n map `\\beta`.\n\n Consider the map `\\beta : RC(B^{r,s} \\otimes B) \\to RC(B^{r,1}\n \\otimes B^{r,s-1} \\otimes B)` for `s > 1` which is a natural classical\n crystal injection. On rigged configurations, the map `\\beta` does\n nothing (except possibly changing the vacancy numbers).\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['C',4,1], [[3,3]])\n sage: mg = RC.module_generators[-1]\n sage: ascii_art(mg)\n 0[ ][ ]0 0[ ][ ]0 0[ ][ ]0 0[ ]0\n 0[ ][ ]0 0[ ][ ]0 0[ ]0\n 0[ ][ ]0 0[ ]0\n sage: ascii_art(mg.left_split())\n 0[ ][ ]0 0[ ][ ]0 1[ ][ ]0 0[ ]0\n 0[ ][ ]0 1[ ][ ]0 0[ ]0\n 1[ ][ ]0 0[ ]0\n "
P = self.parent()
if (P.dims[0][1] == 1):
raise ValueError('cannot split a single column')
(r, s) = P.dims[0]
B = [[r, 1], [r, (s - 1)]]
B.extend(P.dims[1:])
from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations
RC = RiggedConfigurations(P._cartan_type, B)
return RC(*[x._clone() for x in self])
def right_split(self):
"\n Return the image of ``self`` under the right column splitting\n map `\\beta^*`.\n\n Let `\\theta` denote the\n :meth:`complement rigging map<complement_rigging>` which reverses\n the tensor factors and `\\beta` denote the\n :meth:`left splitting map<left_split>`, we define the right\n splitting map by `\\beta^* := \\theta \\circ \\beta \\circ \\theta`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['C',4,1], [[3,3]])\n sage: mg = RC.module_generators[-1]\n sage: ascii_art(mg)\n 0[ ][ ]0 0[ ][ ]0 0[ ][ ]0 0[ ]0\n 0[ ][ ]0 0[ ][ ]0 0[ ]0\n 0[ ][ ]0 0[ ]0\n sage: ascii_art(mg.right_split())\n 0[ ][ ]0 0[ ][ ]0 1[ ][ ]1 0[ ]0\n 0[ ][ ]0 1[ ][ ]1 0[ ]0\n 1[ ][ ]1 0[ ]0\n\n sage: RC = RiggedConfigurations(['D',4,1], [[2,2],[1,2]])\n sage: elt = RC(partition_list=[[3,1], [2,2,1], [2,1], [2]])\n sage: ascii_art(elt)\n -1[ ][ ][ ]-1 0[ ][ ]0 -1[ ][ ]-1 1[ ][ ]1\n 0[ ]0 0[ ][ ]0 -1[ ]-1\n 0[ ]0\n sage: ascii_art(elt.right_split())\n -1[ ][ ][ ]-1 0[ ][ ]0 -1[ ][ ]-1 1[ ][ ]1\n 1[ ]0 0[ ][ ]0 -1[ ]-1\n 0[ ]0\n\n We check that the bijection commutes with the right splitting map::\n\n sage: RC = RiggedConfigurations(['A', 3, 1], [[1,1], [2,2]])\n sage: all(rc.right_split().to_tensor_product_of_kirillov_reshetikhin_tableaux()\n ....: == rc.to_tensor_product_of_kirillov_reshetikhin_tableaux().right_split() for rc in RC)\n True\n "
return self.complement_rigging(True).left_split().complement_rigging(True)
def left_box(self, return_b=False):
"\n Return the image of ``self`` under the left box removal map `\\delta`.\n\n The map `\\delta : RC(B^{r,1} \\otimes B) \\to RC(B^{r-1,1}\n \\otimes B)` (if `r = 1`, then we remove the left-most factor) is the\n basic map in the bijection `\\Phi` between rigged configurations and\n tensor products of Kirillov-Reshetikhin tableaux. For more\n information, see\n :meth:`to_tensor_product_of_kirillov_reshetikhin_tableaux()`.\n We can extend `\\delta` when the left-most factor is not a single\n column by precomposing with a :meth:`left_split()`.\n\n .. NOTE::\n\n Due to the special nature of the bijection for the spinor cases in\n types `D_n^{(1)}`, `B_n^{(1)}`, and `A_{2n-1}^{(2)}`, this map is\n not defined in these cases.\n\n INPUT:\n\n - ``return_b`` -- (default: ``False``) whether to return the\n resulting letter from `\\delta`\n\n OUTPUT:\n\n The resulting rigged configuration or if ``return_b`` is ``True``,\n then a tuple of the resulting rigged configuration and the letter.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['C',4,1], [[3,2]])\n sage: mg = RC.module_generators[-1]\n sage: ascii_art(mg)\n 0[ ][ ]0 0[ ][ ]0 0[ ][ ]0 0[ ]0\n 0[ ][ ]0 0[ ][ ]0 0[ ]0\n 0[ ][ ]0 0[ ]0\n sage: ascii_art(mg.left_box())\n 0[ ]0 0[ ][ ]0 0[ ][ ]0 0[ ]0\n 0[ ]0 0[ ][ ]0 0[ ]0\n sage: x,b = mg.left_box(True)\n sage: b\n -1\n sage: b.parent()\n The crystal of letters for type ['C', 4]\n "
P = self.parent()
ct = P.cartan_type()
if (ct.type() == 'D'):
if (P.dims[0][0] >= (ct.rank() - 2)):
raise ValueError('only for non-spinor cases')
elif ((ct.type() == 'B') or (ct.dual().type() == 'B')):
if (P.dims[0][0] == (ct.rank() - 1)):
raise ValueError('only for non-spinor cases')
from sage.combinat.rigged_configurations.bijection import RCToKRTBijection
rc = self
if (P.dims[0][1] != 1):
rc = self.left_split()
bij = RCToKRTBijection(rc)
ht = bij.cur_dims[0][0]
bij.cur_dims[0][0] = bij._next_index(ht)
b = bij.next_state(ht)
if (bij.cur_dims[0][0] == 0):
bij.cur_dims.pop(0)
from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations
RC = RiggedConfigurations(ct, bij.cur_dims)
rc = RC(*bij.cur_partitions)
if return_b:
from sage.combinat.crystals.letters import CrystalOfLetters
L = CrystalOfLetters(self.parent()._cartan_type.classical())
return (rc, L(b))
return rc
delta = left_box
def left_column_box(self):
"\n Return the image of ``self`` under the left column box splitting\n map `\\gamma`.\n\n Consider the map `\\gamma : RC(B^{r,1} \\otimes B) \\to RC(B^{1,1}\n \\otimes B^{r-1,1} \\otimes B)` for `r > 1`, which is a natural strict\n classical crystal injection. On rigged configurations, the map\n `\\gamma` adds a singular string of length `1` to `\\nu^{(a)}`.\n\n We can extend `\\gamma` when the left-most factor is not a single\n column by precomposing with a :meth:`left_split()`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['C',3,1], [[3,1], [2,1]])\n sage: mg = RC.module_generators[-1]\n sage: ascii_art(mg)\n 0[ ]0 0[ ][ ]0 0[ ]0\n 0[ ]0 0[ ]0\n sage: ascii_art(mg.left_column_box())\n 0[ ]0 0[ ][ ]0 0[ ]0\n 0[ ]0 0[ ]0 0[ ]0\n 0[ ]0\n\n sage: RC = RiggedConfigurations(['C',3,1], [[2,1], [1,1], [3,1]])\n sage: mg = RC.module_generators[7]\n sage: ascii_art(mg)\n 1[ ]0 0[ ][ ]0 0[ ]0\n 0[ ]0 0[ ]0\n sage: ascii_art(mg.left_column_box())\n 1[ ]1 0[ ][ ]0 0[ ]0\n 1[ ]0 0[ ]0 0[ ]0\n "
P = self.parent()
r = P.dims[0][0]
if (r == 1):
raise ValueError('cannot split a single box')
ct = P.cartan_type()
if (ct.type() == 'D'):
if (P.dims[0][0] >= (ct.rank() - 2)):
raise ValueError('only for non-spinor cases')
elif ((ct.type() == 'B') or (ct.dual().type() == 'B')):
if (P.dims[0][0] == (ct.rank() - 1)):
raise ValueError('only for non-spinor cases')
if (P.dims[0][1] > 1):
return self.left_split().left_column_box()
B = [[1, 1], [(r - 1), 1]]
B.extend(P.dims[1:])
from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations
RC = RiggedConfigurations(P._cartan_type, B)
parts = [x._clone() for x in self]
for nu in parts[:(r - 1)]:
nu._list.append(1)
for (a, nu) in enumerate(parts[:(r - 1)]):
vac_num = RC._calc_vacancy_number(parts, a, 1)
i = nu._list.index(1)
nu.vacancy_numbers.insert(i, vac_num)
nu.rigging.insert(i, vac_num)
return RC(*parts)
def right_column_box(self):
"\n Return the image of ``self`` under the right column box splitting\n map `\\gamma^*`.\n\n Consider the map `\\gamma^* : RC(B \\otimes B^{r,1}) \\to RC(B \\otimes\n B^{r-1,1} \\otimes B^{1,1})` for `r > 1`, which is a natural strict\n classical crystal injection. On rigged configurations, the map\n `\\gamma` adds a string of length `1` with rigging 0 to `\\nu^{(a)}`\n for all `a < r` to a classically highest weight element and extended\n as a classical crystal morphism.\n\n We can extend `\\gamma^*` when the right-most factor is not a single\n column by precomposing with a :meth:`right_split()`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['C',3,1], [[2,1], [1,1], [3,1]])\n sage: mg = RC.module_generators[7]\n sage: ascii_art(mg)\n 1[ ]0 0[ ][ ]0 0[ ]0\n 0[ ]0 0[ ]0\n sage: ascii_art(mg.right_column_box())\n 1[ ]0 0[ ][ ]0 0[ ]0\n 1[ ]0 0[ ]0 0[ ]0\n 0[ ]0\n "
P = self.parent()
r = P.dims[(- 1)][0]
if (r == 1):
raise ValueError('cannot split a single box')
ct = P.cartan_type()
if (ct.type() == 'D'):
if (P.dims[(- 1)][0] >= (ct.rank() - 2)):
raise ValueError('only for non-spinor cases')
elif ((ct.type() == 'B') or (ct.dual().type() == 'B')):
if (P.dims[(- 1)][0] == (ct.rank() - 1)):
raise ValueError('only for non-spinor cases')
if (P.dims[(- 1)][1] > 1):
return self.right_split().right_column_box()
(rc, e_string) = self.to_highest_weight(P._rc_index)
B = (P.dims[:(- 1)] + ([(r - 1), 1], [1, 1]))
from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations
RC = RiggedConfigurations(P._cartan_type, B)
parts = [x._clone() for x in rc]
for nu in parts[:(r - 1)]:
nu._list.append(1)
for (a, nu) in enumerate(parts[:(r - 1)]):
vac_num = RC._calc_vacancy_number(parts, a, (- 1))
nu.vacancy_numbers.append(vac_num)
nu.rigging.append(0)
return RC(*parts).f_string(reversed(e_string))
def complement_rigging(self, reverse_factors=False):
"\n Apply the complement rigging morphism `\\theta` to ``self``.\n\n Consider a highest weight rigged configuration `(\\nu, J)`, the\n complement rigging morphism `\\theta : RC(L) \\to RC(L)` is given by\n sending `(\\nu, J) \\mapsto (\\nu, J')`, where `J'` is obtained by\n taking the coriggings `x' = p_i^{(a)} - x`, and then extending as\n a crystal morphism. (The name comes from taking the complement\n partition for the riggings in a `m_i^{(a)} \\times p_i^{(a)}` box.)\n\n INPUT:\n\n - ``reverse_factors`` -- (default: ``False``) if ``True``, then this\n returns an element in `RC(B')` where `B'` is the tensor factors\n of ``self`` in reverse order\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['D',4,1], [[1,1],[2,2]])\n sage: mg = RC.module_generators[-1]\n sage: ascii_art(mg)\n 1[ ][ ]1 0[ ][ ]0 0[ ][ ]0 0[ ][ ]0\n 0[ ][ ]0\n sage: ascii_art(mg.complement_rigging())\n 1[ ][ ]0 0[ ][ ]0 0[ ][ ]0 0[ ][ ]0\n 0[ ][ ]0\n\n sage: lw = mg.to_lowest_weight([1,2,3,4])[0]\n sage: ascii_art(lw)\n -1[ ][ ]-1 0[ ][ ]0 0[ ][ ]0 0[ ][ ]0\n -1[ ]-1 0[ ][ ]0 0[ ]0 0[ ]0\n -1[ ]-1 0[ ]0\n 0[ ]0\n sage: ascii_art(lw.complement_rigging())\n -1[ ][ ][ ]-1 0[ ][ ][ ]0 0[ ][ ][ ]0 0[ ][ ][ ]0\n -1[ ]-1 0[ ][ ][ ]0\n sage: lw.complement_rigging() == mg.complement_rigging().to_lowest_weight([1,2,3,4])[0]\n True\n\n sage: mg.complement_rigging(True).parent()\n Rigged configurations of type ['D', 4, 1] and factor(s) ((2, 2), (1, 1))\n\n We check that the Lusztig involution (under the modification of also\n mapping to the highest weight element) intertwines with the\n complement map `\\theta` (that reverses the tensor factors)\n under the bijection `\\Phi`::\n\n sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2], [2, 1], [1, 2]])\n sage: for mg in RC.module_generators: # long time\n ....: y = mg.to_tensor_product_of_kirillov_reshetikhin_tableaux()\n ....: hw = y.lusztig_involution().to_highest_weight([1,2,3,4])[0]\n ....: c = mg.complement_rigging(True)\n ....: hwc = c.to_tensor_product_of_kirillov_reshetikhin_tableaux()\n ....: assert hw == hwc\n\n TESTS:\n\n We check that :trac:`18898` is fixed::\n\n sage: RC = RiggedConfigurations(['D',4,1], [[2,1], [2,1], [2,3]])\n sage: x = RC(partition_list=[[1], [1,1], [1], [1]], rigging_list=[[0], [2,1], [0], [0]])\n sage: ascii_art(x)\n 0[ ]0 2[ ]2 0[ ]0 0[ ]0\n 2[ ]1\n sage: ascii_art(x.complement_rigging())\n 0[ ]0 2[ ]1 0[ ]0 0[ ]0\n 2[ ]0\n "
P = self.parent()
if reverse_factors:
from sage.combinat.rigged_configurations.rigged_configurations import RiggedConfigurations
P = RiggedConfigurations(P._cartan_type, reversed(P.dims))
(mg, e_str) = self.to_highest_weight(P._rc_index)
nu = []
rig = []
for (a, p) in enumerate(mg):
nu.append(list(p))
vac_nums = p.vacancy_numbers
riggings = [(vac - p.rigging[i]) for (i, vac) in enumerate(vac_nums)]
block = 0
for (j, i) in enumerate(p):
if (p[block] != i):
riggings[block:j] = sorted(riggings[block:j], reverse=True)
block = j
riggings[block:] = sorted(riggings[block:], reverse=True)
rig.append(riggings)
rc = P(partition_list=nu, rigging_list=rig)
return rc.f_string(reversed(e_str))
|
class KRRCSimplyLacedElement(KRRiggedConfigurationElement):
"\n `U_q^{\\prime}(\\mathfrak{g})` rigged configurations in simply-laced types.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['A', 3, 1], [[3, 2], [2,1], [1,1]])\n sage: elt = RC(partition_list=[[1], [1], []]); elt\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n 0[ ]0\n <BLANKLINE>\n (/)\n <BLANKLINE>\n sage: TestSuite(elt).run()\n "
@cached_method
def cocharge(self):
"\n Compute the cocharge statistic of ``self``.\n\n Computes the cocharge statistic [CrysStructSchilling06]_ on this\n rigged configuration `(\\nu, J)`. The cocharge statistic is defined as:\n\n .. MATH::\n\n cc(\\nu, J) = \\frac{1}{2} \\sum_{a, b \\in I_0}\n \\sum_{j,k > 0} \\left( \\alpha_a \\mid \\alpha_b \\right)\n \\min(j, k) m_j^{(a)} m_k^{(b)}\n + \\sum_{a \\in I} \\sum_{i > 0} \\left\\lvert J^{(a, i)} \\right\\rvert.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 3, 1], [[3, 2], [2,1], [1,1]])\n sage: RC(partition_list=[[1], [1], []]).cocharge()\n 1\n "
cc = 0
rigging_sum = 0
for (a, p) in enumerate(self):
for (pos, i) in enumerate(p._list):
rigging_sum += p.rigging[pos]
for dim in self.parent().dims:
if (dim[0] == (a + 1)):
cc += min(dim[1], i)
cc -= p.vacancy_numbers[pos]
return ((cc // 2) + rigging_sum)
cc = cocharge
@cached_method
def charge(self):
"\n Compute the charge statistic of ``self``.\n\n Let `B` denote a set of rigged configurations. The *charge* `c` of\n a rigged configuration `b` is computed as\n\n .. MATH::\n\n c(b) = \\max(cc(b) \\mid b \\in B) - cc(b).\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A', 3, 1], [[3, 2], [2,1], [1,1]])\n sage: RC(partition_list=[[],[],[]]).charge()\n 2\n sage: RC(partition_list=[[1], [1], []]).charge()\n 1\n "
B = self.parent()
if (not hasattr(B, '_max_charge')):
B._max_charge = max((b.cocharge() for b in B.module_generators))
return (B._max_charge - self.cocharge())
|
class KRRCNonSimplyLacedElement(KRRiggedConfigurationElement, RCNonSimplyLacedElement):
"\n `U_q^{\\prime}(\\mathfrak{g})` rigged configurations in non-simply-laced\n types.\n\n TESTS::\n\n sage: RC = RiggedConfigurations(['C',2,1], [[1,2],[1,1],[2,1]])\n sage: elt = RC(partition_list=[[3],[2]]); elt\n <BLANKLINE>\n 0[ ][ ][ ]0\n <BLANKLINE>\n 0[ ][ ]0\n sage: TestSuite(elt).run()\n "
def e(self, a):
"\n Return the action of `e_a` on ``self``.\n\n This works by lifting into the virtual configuration, then applying\n\n .. MATH::\n\n e^v_a = \\prod_{j \\in \\iota(a)} \\hat{e}_j^{\\gamma_j}\n\n and pulling back.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A',6,2], [[1,1]]*7)\n sage: elt = RC(partition_list=[[1]*5,[2,1,1],[3,2]])\n sage: elt.e(3)\n <BLANKLINE>\n 0[ ]0\n 0[ ]0\n 0[ ]0\n 0[ ]0\n 0[ ]0\n <BLANKLINE>\n 0[ ][ ]0\n 1[ ]1\n 1[ ]1\n <BLANKLINE>\n 1[ ][ ]1\n 1[ ]0\n <BLANKLINE>\n "
if (a == self.parent()._cartan_type.special_node()):
try:
ret = self.to_tensor_product_of_kirillov_reshetikhin_tableaux().e(a)
if (ret is None):
return None
return ret.to_rigged_configuration()
except (NotImplementedError, TypeError):
return RCNonSimplyLacedElement.e(self, a)
if (not self.epsilon(a)):
return None
return RCNonSimplyLacedElement.e(self, a)
def f(self, a):
"\n Return the action of `f_a` on ``self``.\n\n This works by lifting into the virtual configuration, then applying\n\n .. MATH::\n\n f^v_a = \\prod_{j \\in \\iota(a)} \\hat{f}_j^{\\gamma_j}\n\n and pulling back.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['A',6,2], [[1,1]]*7)\n sage: elt = RC(partition_list=[[1]*5,[2,1,1],[2,1]], rigging_list=[[0]*5,[0,1,1],[1,0]])\n sage: elt.f(3)\n <BLANKLINE>\n 0[ ]0\n 0[ ]0\n 0[ ]0\n 0[ ]0\n 0[ ]0\n <BLANKLINE>\n 1[ ][ ]1\n 1[ ]1\n 1[ ]1\n <BLANKLINE>\n -1[ ][ ][ ]-1\n 0[ ][ ]0\n <BLANKLINE>\n "
if (a == self.parent()._cartan_type.special_node()):
try:
ret = self.to_tensor_product_of_kirillov_reshetikhin_tableaux().f(a)
if (ret is None):
return None
return ret.to_rigged_configuration()
except (NotImplementedError, TypeError):
return RCNonSimplyLacedElement.f(self, a)
if (not self.phi(a)):
return None
return RCNonSimplyLacedElement.f(self, a)
@cached_method
def cocharge(self):
"\n Compute the cocharge statistic.\n\n Computes the cocharge statistic [OSS03]_ on this\n rigged configuration `(\\nu, J)` by computing the cocharge as a virtual\n rigged configuration `(\\hat{\\nu}, \\hat{J})` and then using the\n identity `cc(\\hat{\\nu}, \\hat{J}) = \\gamma_0 cc(\\nu, J)`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(['C', 3, 1], [[2,1], [1,1]])\n sage: RC(partition_list=[[1,1],[2,1],[1,1]]).cocharge()\n 1\n "
vct = self.parent()._folded_ct
cc = ZZ.zero()
rigging_sum = ZZ.zero()
sigma = vct.folding_orbit()
gamma = vct.scaling_factors()
for (a, p) in enumerate(self):
t_check = ((len(sigma[(a + 1)]) * gamma[(a + 1)]) // gamma[0])
for (pos, i) in enumerate(p._list):
rigging_sum += (t_check * p.rigging[pos])
for dim in self.parent().dims:
if (dim[0] == (a + 1)):
cc += (t_check * min(dim[1], i))
cc -= (t_check * p.vacancy_numbers[pos])
return ((cc // 2) + rigging_sum)
cc = cocharge
|
class KRRCTypeA2DualElement(KRRCNonSimplyLacedElement):
'\n `U_q^{\\prime}(\\mathfrak{g})` rigged configurations in type\n `A_{2n}^{(2)\\dagger}`.\n '
def epsilon(self, a):
"\n Return the value of `\\varepsilon_a` of ``self``.\n\n Here we need to modify the usual definition by\n `\\varepsilon_n^{\\prime} := 2 \\varepsilon_n`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(CartanType(['A',4,2]).dual(), [[1,1], [2,2]])\n sage: def epsilon(x, i):\n ....: x = x.e(i)\n ....: eps = 0\n ....: while x is not None:\n ....: x = x.e(i)\n ....: eps = eps + 1\n ....: return eps\n sage: all(epsilon(rc, 2) == rc.epsilon(2) for rc in RC)\n True\n "
if (a == self.parent()._cartan_type.special_node()):
return self.to_tensor_product_of_kirillov_reshetikhin_tableaux().epsilon(a)
a = self.parent()._rc_index_inverse[a]
if (not self[a]):
epsilon = 0
else:
epsilon = (- min(0, min(self[a].rigging)))
n = len(self.parent()._rc_index)
if (a == (n - 1)):
epsilon *= 2
return Integer(epsilon)
def phi(self, a):
"\n Return the value of `\\varphi_a` of ``self``.\n\n Here we need to modify the usual definition by\n `\\varphi_n^{\\prime} := 2 \\varphi_n`.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(CartanType(['A',4,2]).dual(), [[1,1], [2,2]])\n sage: def phi(x, i):\n ....: x = x.f(i)\n ....: ph = 0\n ....: while x is not None:\n ....: x = x.f(i)\n ....: ph = ph + 1\n ....: return ph\n sage: all(phi(rc, 2) == rc.phi(2) for rc in RC)\n True\n "
if (a == self.parent()._cartan_type.special_node()):
return self.to_tensor_product_of_kirillov_reshetikhin_tableaux().phi(a)
a = self.parent()._rc_index_inverse[a]
p_inf = self.parent()._calc_vacancy_number(self, a, float('inf'))
if (not self[a]):
phi = p_inf
else:
phi = (p_inf - min(0, min(self[a].rigging)))
n = len(self.parent()._rc_index)
if (a == (n - 1)):
phi *= 2
return Integer(phi)
@cached_method
def cocharge(self):
"\n Compute the cocharge statistic.\n\n Computes the cocharge statistic [RigConBijection]_ on this\n rigged configuration `(\\nu, J)`. The cocharge statistic is\n computed as:\n\n .. MATH::\n\n cc(\\nu, J) = \\frac{1}{2} \\sum_{a \\in I_0} \\sum_{i > 0}\n t_a^{\\vee} m_i^{(a)} \\left( \\sum_{j > 0} \\min(i, j) L_j^{(a)}\n - p_i^{(a)} \\right) + \\sum_{a \\in I} t_a^{\\vee} \\sum_{i > 0}\n \\left\\lvert J^{(a, i)} \\right\\rvert.\n\n EXAMPLES::\n\n sage: RC = RiggedConfigurations(CartanType(['A',4,2]).dual(), [[1,1],[2,2]])\n sage: sc = RC.cartan_type().as_folding().scaling_factors()\n sage: all(mg.cocharge() * sc[0] == mg.to_virtual_configuration().cocharge()\n ....: for mg in RC.module_generators)\n True\n "
cc = ZZ.zero()
rigging_sum = ZZ.zero()
for (a, p) in enumerate(self):
t_check = 1
for (pos, i) in enumerate(p._list):
rigging_sum += (t_check * p.rigging[pos])
for dim in self.parent().dims:
if (dim[0] == (a + 1)):
cc += (t_check * min(dim[1], i))
cc -= (t_check * p.vacancy_numbers[pos])
return ((cc / ZZ(2)) + rigging_sum)
cc = cocharge
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.