def _ascii_art_(self): r""" Return an ascii art representation of ``self`` TESTS:: sage: t = path_tableaux.DyckPath([0,1,2,3,2,1,0]) sage: ascii_art(path_tableaux.CylindricalDiagram(t)) 0 1 2 3 2 1 0 0 1 2 1 0 1 0 0 1 0 1 2 1 0 0 1 2 3 2 1 0 0 1 2 1 0 1 0 0 1 0 1 2 1 0 0 1 2 3 2 1 0 sage: t = path_tableaux.FriezePattern([1,3,4,5,1]) sage: ascii_art(path_tableaux.CylindricalDiagram(t)) 0 1 3 4 5 1 0 0 1 5/3 7/3 2/3 1 0 0 1 2 1 3 1 0 0 1 1 4 5/3 1 0 0 1 5 7/3 2 1 0 0 1 2/3 1 1 1 0 0 1 3 4 5 1 0 """ from sage.typeset.ascii_art import ascii_art from sage.misc.misc_c import prod data = [[ascii_art(x) for x in row] for row in self.diagram] if not data[0]: data[0] = [ascii_art('')] # Put sometime there max_width = max(max(len(x) for x in row) for row in data if row) return prod((sum((ascii_art(' '*(max_width-len(x)+1)) + x for x in row), ascii_art('')) for row in data), ascii_art(''))
def _column_repr(self, b, vacuum_letter=None): """ Return a string representation of the column ``b``. EXAMPLES:: sage: B = SolitonCellularAutomata([[-2,1],[2,1],[-3,1],[-3,2]], ['D',4,2], 2) sage: K = crystals.KirillovReshetikhin(['D',4,2], 2,1, 'KR') sage: B._column_repr(K(-2,1)) -2 1 sage: B._column_repr(K.module_generator()) 2 1 sage: B._column_repr(K.module_generator(), 'x') x """ if vacuum_letter is not None and b == self._vacuum_elt: return ascii_art(vacuum_letter) if self._vacuum_elt.parent()._tableau_height == 1: s = str(b[0]) return ascii_art(s if s[0] != '-' else '_\n' + s[1:]) letter_str = [str(letter) for letter in b] max_width = max(len(s) for s in letter_str) return ascii_art('\n'.join(' ' * (max_width - len(s)) + s for s in letter_str))
def print_state_evolution(self, num): r""" Print the evolution process of the state ``num``. .. SEEALSO:: :meth:`state_evolution`, :meth:`latex_state_evolution` EXAMPLES:: sage: B = SolitonCellularAutomata('1113123', 3) sage: B.evolve(3) sage: B.evolve(3) sage: B.print_state_evolution(0) 1 1 1 3 1 2 3 | | | | | | | 111 --+-- 111 --+-- 111 --+-- 113 --+-- 112 --+-- 123 --+-- 113 --+-- 111 | | | | | | | 1 1 3 2 3 1 1 sage: B.print_state_evolution(1) 1 1 3 2 3 1 1 | | | | | | | 111 --+-- 113 --+-- 133 --+-- 123 --+-- 113 --+-- 111 --+-- 111 --+-- 111 | | | | | | | 3 3 2 1 1 1 1 """ u = self.state_evolution(num) # Also evolves as necessary final = self._states[num + 1] vacuum = self._vacuum_elt state = [vacuum] * (len(final) - len(self._states[num])) + list( self._states[num]) carrier = KirillovReshetikhinTableaux(self._cartan_type, *self._evolutions[num]) def simple_repr(x): return ''.join(repr(x).strip('[]').split(', ')) def carrier_repr(x): if carrier._tableau_height == 1: return sum((ascii_art(repr(b)) if repr(b)[0] != '-' else ascii_art("_" + '\n' + repr(b)[1:]) for b in x), ascii_art('')) return ascii_art(''.join(repr(x).strip('[]').split(', '))) def cross_repr(i): ret = ascii_art(""" {!s:^7} | --+-- | {!s:^7} """.format(simple_repr(state[i]), simple_repr(final[i]))) ret._baseline = 2 return ret art = sum((cross_repr(i) + carrier_repr(u[i + 1]) for i in range(len(state))), ascii_art('')) print(ascii_art(carrier_repr(u[0])) + art)
def _ascii_art_(self): """ ASCII art representation of the array. """ l = len(repr(self.n - 1)) fmt = '%{}d'.format(l) art = [("(%s, %s): " % (fmt % i, fmt % j), ascii_art(M)) for i, A in enumerate(self.A) for j, M in enumerate(A)] return ascii_art("\n".join(i + "\n"*a.height() for i, a in art)) + \ ascii_art("\n".join(sum([a._matrix + [""] for i, a in art], [])))
def _ascii_art_(self): """ ASCII art representation of the array. """ l = len(repr(self.n - 1)) fmt = '%{}d: '.format(l) art = [ascii_art(M) for M in self.A] return ascii_art("\n".join((fmt % i) + "\n"*a.height() for i, a in enumerate(art))) + \ ascii_art("\n".join(sum([a._matrix + [""] for a in art], [])))
def ascii_art_formatter(self, obj, **kwds): r""" Hook to override how ascii art is being formatted. INPUT: - ``obj`` -- anything. - ``**kwds`` -- optional keyword arguments to control the formatting. Supported are: * ``concatenate`` -- boolean (default: ``False``). If ``True``, the argument ``obj`` must be iterable and its entries will be concatenated. There is a single whitespace between entries. OUTPUT: Instance of :class:`~sage.repl.rich_output.output_basic.OutputAsciiArt` containing the ascii art string representation of the object. EXAMPLES:: sage: from sage.repl.rich_output.backend_base import BackendBase sage: backend = BackendBase() sage: out = backend.ascii_art_formatter(range(30)) sage: out OutputAsciiArt container sage: out.ascii_art buffer containing 114 bytes sage: print(out.ascii_art.get()) [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, <BLANKLINE> 22, 23, 24, 25, 26, 27, 28, 29 ] sage: backend.ascii_art_formatter([1,2,3], concatenate=False).ascii_art.get() '[ 1, 2, 3 ]' sage: backend.ascii_art_formatter([1,2,3], concatenate=True ).ascii_art.get() '1 2 3' """ from sage.typeset.ascii_art import ascii_art, empty_ascii_art if kwds.get("concatenate", False): result = ascii_art(*obj, sep=" ") else: result = ascii_art(obj) from sage.repl.rich_output.output_basic import OutputAsciiArt return OutputAsciiArt(str(result))
def _repr_(self): """ Return a string representation of ``self``. EXAMPLES:: sage: SolitonCellularAutomata('3411111122411112223', 4) Soliton cellular automata of type ['A', 3, 1] and vacuum = 1 initial state: 34......224....2223 evoltuions: [] current state: 34......224....2223 sage: SolitonCellularAutomata([[4,1],[2,1],[2,1],[3,1],[3,2]], 4, 2) Soliton cellular automata of type ['A', 3, 1] and vacuum = 2 initial state: 4 33 1..12 evoltuions: [] current state: 4 33 1..12 sage: SolitonCellularAutomata([[4,1],[2,1],[2,1],[3,1],[3,2]], ['C',4,1], 2) Soliton cellular automata of type ['C', 4, 1] and vacuum = 2 initial state: 4 33 1..12 evoltuions: [] current state: 4 33 1..12 sage: SolitonCellularAutomata([[4,3],[2,1],[-3,1],[-3,2]], ['B',4,1], 2) Soliton cellular automata of type ['B', 4, 1] and vacuum = 2 initial state: 4 -3-3 3 . 1 2 evoltuions: [] current state: 4 -3-3 3 . 1 2 """ ret = "Soliton cellular automata of type {} and vacuum = {}\n".format( self._cartan_type, self._vacuum) ret += " initial state:\n{}\n evoltuions: {}\n current state:\n{}".format( ascii_art(' ') + self._repr_state(self._states[0]), self._evolutions, ascii_art(' ') + self._repr_state(self._states[-1])) return ret
def _ascii_art_generator(self, m): r""" Return an ascii art representing the generator indexed by ``m``. TESTS:: sage: R = NonCommutativeSymmetricFunctions(QQ).R() sage: ascii_art(R[1,2,2,4]) R **** ** ** * sage: Partitions.options(diagram_str="#", convention="french") sage: ascii_art(R[1,2,2,4]) R # ## ## #### sage: Partitions.options._reset() """ from sage.typeset.ascii_art import AsciiArt, ascii_art pref = AsciiArt([self.prefix()]) r = pref * (AsciiArt([" "**Integer(len(pref))]) + ascii_art(m)) r._baseline = r._h - 1 return r
def _ascii_art_generator(self, m): r""" Return an ascii art representing the generator indexed by ``m``. TESTS:: sage: R = NonCommutativeSymmetricFunctions(QQ).R() sage: ascii_art(R[1,2,2,4]) R **** ** ** * sage: Partitions.global_options(diagram_str="#", convention="french") sage: ascii_art(R[1,2,2,4]) R # ## ## #### """ from sage.typeset.ascii_art import AsciiArt, ascii_art pref = AsciiArt([self.prefix()]) r = pref * (AsciiArt([" "**Integer(len(pref))]) + ascii_art(m)) r._baseline = r._h - 1 return r
def ascii_art_formatter(self, obj, **kwds): r""" Hook to override how ascii art is being formatted. INPUT: - ``obj`` -- anything. - ``**kwds`` -- optional keyword arguments to control the formatting. Supported are: * ``concatenate`` -- boolean (default: ``False``). If ``True``, the argument ``obj`` must be iterable and its entries will be concatenated. There is a single whitespace between entries. OUTPUT: Instance of :class:`~sage.repl.rich_output.output_basic.OutputAsciiArt` containing the ascii art string representation of the object. EXAMPLES:: sage: from sage.repl.rich_output.backend_base import BackendBase sage: backend = BackendBase() sage: out = backend.ascii_art_formatter(range(30)) sage: out OutputAsciiArt container sage: out.ascii_art buffer containing 114 bytes sage: print(out.ascii_art.get()) [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, <BLANKLINE> 22, 23, 24, 25, 26, 27, 28, 29 ] sage: backend.ascii_art_formatter([1,2,3], concatenate=False).ascii_art.get() '[ 1, 2, 3 ]' sage: backend.ascii_art_formatter([1,2,3], concatenate=True ).ascii_art.get() '1 2 3' """ from sage.typeset.ascii_art import ascii_art, empty_ascii_art if kwds.get('concatenate', False): result = ascii_art(*obj, sep=' ') else: result = ascii_art(obj) from sage.repl.rich_output.output_basic import OutputAsciiArt return OutputAsciiArt(str(result))
def _ascii_art_(self): r""" TESTS:: sage: from sage.combinat.shuffle import SetShuffleProduct sage: ascii_art(SetShuffleProduct([[BinaryTree()], [BinaryTree([]), BinaryTree([[],[]])]], ....: [[1,4]])) Set shuffle product of: [ [ o, o ] ] [ [ / \ ] ] [ [ ], [ o o ] ] and [ [ 1, 4 ] ] """ from sage.typeset.ascii_art import ascii_art return ascii_art("Set shuffle product of:") * \ (ascii_art(self._l1) + ascii_art(" and ") + ascii_art(self._l2))
def ascii_art_gen(m): if m[1] != 1: r = AsciiArt([" " ** Integer(len(pref))]) + ascii_art(m[1]) else: r = empty_ascii_art r = r * P._ascii_art_generator(m[0]) r._baseline = r._h - 2 return r
def ascii_art_gen(m): if m[1] != 1: r = (AsciiArt([" " * len(pref)]) + ascii_art(m[1])) else: r = empty_ascii_art r = r * P._ascii_art_generator(m[0]) r._baseline = r._h - 2 return r
def _repr_state(self, state, vacuum_letter='.'): """ Return a string representation of ``state``. EXAMPLES:: sage: B = SolitonCellularAutomata('3411111122411112223', 4) sage: B.evolve(number=10) sage: print(B._repr_state(B._states[0])) 34......224....2223 sage: print(B._repr_state(B._states[-1], '_')) ______2344_______222____23_______________________________ """ output = [self._column_repr(b, vacuum_letter) for b in state] max_width = max(cell.width() for cell in output) return sum( (ascii_art(' ' * (max_width - b.width())) + b for b in output), ascii_art(''))
def cross_repr(i): ret = ascii_art(""" {!s:^7} | --+-- | {!s:^7} """.format(simple_repr(state[i]), simple_repr(final[i]))) ret._baseline = 2 return ret
def _ascii_art_term(self, m): r""" Return ascii art for the basis element indexed by ``m``. EXAMPLES:: sage: C4 = graphs.CycleGraph(4) sage: A = groups.misc.RightAngledArtin(C4) sage: H = A.cohomology() sage: H._ascii_art_term((0,1,3)) e0/\e1/\e3 sage: w,x,y,z = H.algebra_generators() sage: ascii_art(y*w + 2*x*z) -e0/\e2 + 2*e1/\e3 """ if not m: return ascii_art('1') wedge = '/\\' return ascii_art(*['e' + str(i) for i in m], sep=wedge)
def __repr__(self): r""" Return string representation. OUTPUT: String. EXAMPLES:: sage: from sage.geometry.polyhedron.double_description import \ ....: DoubleDescriptionPair, StandardAlgorithm sage: A = matrix(QQ, [(1,0,1), (0,1,1), (-1,-1,1)]) sage: DD = StandardAlgorithm(A).run() sage: DD.__repr__() 'Double description pair (A, R) defined by\n [ 1 0 1] [ 2/3 -1/3 -1/3]\nA = [ 0 1 1], R = [-1/3 2/3 -1/3]\n [-1 -1 1] [ 1/3 1/3 1/3]' """ from sage.typeset.ascii_art import ascii_art from sage.matrix.constructor import matrix s = ascii_art('Double description pair (A, R) defined by') A = ascii_art(matrix(self.A)) A._baseline = (len(self.A) // 2) A = ascii_art('A = ') + A R = ascii_art(matrix(self.R).transpose()) if len(self.R) > 0: R._baseline = (len(self.R[0]) // 2) else: R._baseline = 0 R = ascii_art('R = ') + R return str(s * (A + ascii_art(', ') + R))
def __repr__(self): r""" Return string representation. OUTPUT: String. EXAMPLES:: sage: from sage.geometry.polyhedron.double_description import \ ....: DoubleDescriptionPair, StandardAlgorithm sage: A = matrix(QQ, [(1,0,1), (0,1,1), (-1,-1,1)]) sage: DD = StandardAlgorithm(A).run() sage: DD.__repr__() 'Double description pair (A, R) defined by\n [ 1 0 1] [ 2/3 -1/3 -1/3]\nA = [ 0 1 1], R = [-1/3 2/3 -1/3]\n [-1 -1 1] [ 1/3 1/3 1/3]' """ from sage.typeset.ascii_art import ascii_art from sage.matrix.constructor import matrix s = ascii_art('Double description pair (A, R) defined by') A = ascii_art(matrix(self.A)) A._baseline = (len(self.A) / 2) A = ascii_art('A = ') + A R = ascii_art(matrix(self.R).transpose()) if len(self.R) > 0: R._baseline = (len(self.R[0]) / 2) else: R._baseline = 0 R = ascii_art('R = ') + R return str(s * (A + ascii_art(', ') + R))
def _ascii_art_(self): r""" TESTS:: sage: from sage.combinat.shuffle import ShuffleProduct sage: ascii_art(ShuffleProduct([1,2,3],[4,5])) Shuffle product of: [ 1, 2, 3 ] and [ 4, 5 ] sage: B = BinaryTree sage: ascii_art(ShuffleProduct([B([]), B([[],[]])], ....: [B([[[],[]],[[],None]])])) Shuffle product of: [ __o__ ] [ / \ ] [ o, o ] [ o o ] [ / \ ] [ / \ / ] [ o o ] and [ o o o ] """ from sage.typeset.ascii_art import ascii_art return ascii_art("Shuffle product of:") * \ (ascii_art(self._l1) + ascii_art(" and ") + ascii_art(self._l2))
def _ascii_art_(self): r""" Return an ascii art representation of ``self``. EXAMPLES:: sage: G2 = AffineGroup(2, QQ) sage: g2 = G2([[1, 1], [0, 1]], [3,4]) sage: ascii_art(g2) x |-> [1 1] x + [3] [0 1] [4] sage: G3 = AffineGroup(3, QQ) sage: g3 = G3([[1,1,-1], [0,1,2], [0,10,2]], [3,4,5/2]) sage: ascii_art(g3) [ 1 1 -1] [ 3] x |-> [ 0 1 2] x + [ 4] [ 0 10 2] [5/2] """ from sage.typeset.ascii_art import ascii_art deg = self.parent().degree() A = ascii_art(self._A, baseline=deg // 2) b = ascii_art(self._b.column(), baseline=deg // 2) return ascii_art("x |-> ") + A + ascii_art(" x + ") + b
def _ascii_art_term(self, x): r""" Return an ascii art representation for ``x``. EXAMPLES:: sage: L = LieAlgebra(QQ, 'x,y') sage: H = L.Hall() sage: x,y = H.gens() sage: H._ascii_art_term(x.leading_support()) x sage: a = H([x, y]).leading_support() sage: H._ascii_art_term(a) [x, y] """ from sage.typeset.ascii_art import ascii_art return ascii_art(x)
def _ascii_art_term(self, m): """ Return an ascii art representation of the term indexed by ``m``. TESTS:: sage: C = CombinatorialFreeModule(QQ, Partitions()) sage: TA = TensorAlgebra(C) sage: s = TA([Partition([3,2,2,1]), Partition([3])]).leading_support() sage: TA._ascii_art_term(s) B # B *** *** ** ** * sage: s = TA([Partition([3,2,2,1])]*2 + [Partition([3])]*3 + [Partition([1])]*2).leading_support() sage: t = TA._ascii_art_term(s); t B # B # B # B # B # B # B *** *** *** *** *** * * ** ** ** ** * * sage: t._breakpoints [7, 14, 21, 28, 35, 40] sage: I = TA.indices() sage: TA._ascii_art_term(I.one()) '1' """ if len(m) == 0: return '1' from sage.typeset.ascii_art import AsciiArt, ascii_art symb = self._print_options['tensor_symbol'] if symb is None: symb = tensor.symbol M = self._base_module return ascii_art(*(M._ascii_art_term(k) for k, e in m._monomial for _ in range(e)), sep=AsciiArt([symb], breakpoints=[len(symb)]))
def _ascii_art_(self): """ Return an ascii art representation. Note that arrows go to the left so that composition of differentials is the usual matrix multiplication. EXAMPLES:: sage: F.<x,y> = FreeAlgebra(ZZ) sage: H = F.hochschild_complex(F) sage: a = H({0: x - y, ....: 1: H.module(1).basis().an_element(), ....: 2: H.module(2).basis().an_element()}) sage: ascii_art(a) d_0 d_1 d_2 d_3 0 <---- F - F <---- 1 # 1 <---- 1 # 1 # 1 <---- 0 x y """ from sage.typeset.ascii_art import AsciiArt, ascii_art if not self._vec: # 0 chain return AsciiArt(['0']) def arrow_art(d): d_str = [' d_{0} '.format(d)] arrow = ' <' + '-' * (len(d_str[0]) - 3) + ' ' d_str.append(arrow) return AsciiArt(d_str, baseline=0) result = AsciiArt(['0']) max_deg = max(self._vec) for deg in range(min(self._vec), max_deg + 1): A = ascii_art(self.vector(deg)) A._baseline = A.height() // 2 result += arrow_art(deg) + A return result + arrow_art(max_deg + 1) + AsciiArt(['0'])
def _ascii_art_(self): """ Return an ascii art representation. Note that arrows go to the left so that composition of differentials is the usual matrix multiplication. EXAMPLES:: sage: F.<x,y> = FreeAlgebra(ZZ) sage: H = F.hochschild_complex(F) sage: a = H({0: x - y, ....: 1: H.module(1).basis().an_element(), ....: 2: H.module(2).basis().an_element()}) sage: ascii_art(a) d_0 d_1 d_2 d_3 0 <---- F - F <---- 1 # 1 <---- 1 # 1 # 1 <---- 0 x y """ from sage.typeset.ascii_art import AsciiArt, ascii_art if not self._vec: # 0 chain return AsciiArt(['0']) def arrow_art(d): d_str = [' d_{0} '.format(d)] arrow = ' <' + '-'*(len(d_str[0])-3) + ' ' d_str.append(arrow) return AsciiArt(d_str, baseline=0) result = AsciiArt(['0']) max_deg = max(self._vec) for deg in range(min(self._vec), max_deg+1): A = ascii_art(self.vector(deg)) A._baseline = A.height() // 2 result += arrow_art(deg) + A return result + arrow_art(max_deg+1) + AsciiArt(['0'])
def carrier_repr(x): if carrier._tableau_height == 1: return sum((ascii_art(repr(b)) if repr(b)[0] != '-' else ascii_art("_" + '\n' + repr(b)[1:]) for b in x), ascii_art('')) return ascii_art(''.join(repr(x).strip('[]').split(', ')))
def evolve(self, carrier_capacity=None, carrier_index=None, number=None): """ Evolve ``self``. Time evolution `T_s` of a SCA state `p` is determined by .. MATH:: u_{r,s} \otimes T_s(p) = R(p \otimes u_{r,s}), where `u_{r,s}` is the maximal element of `B^{r,s}`. INPUT: - ``carrier_capacity`` -- (default: the number of balls in the system) the size `s` of carrier - ``carrier_index`` -- (default: the vacuum index) the index `r` of the carrier - ``number`` -- (optional) the number of times to perform the evolutions To perform multiple evolutions of the SCA, ``carrier_capacity`` and ``carrier_index`` may be lists of the same length. EXAMPLES:: sage: B = SolitonCellularAutomata('3411111122411112223', 4) sage: for k in range(10): ....: B.evolve() sage: B Soliton cellular automata of type ['A', 3, 1] and vacuum = 1 initial state: 34......224....2223 evoltuions: [(1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19)] current state: ......2344.......222....23............................... sage: B.reset() sage: B.evolve(number=10); B Soliton cellular automata of type ['A', 3, 1] and vacuum = 1 initial state: 34......224....2223 evoltuions: [(1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19), (1, 19)] current state: ......2344.......222....23............................... sage: B.reset() sage: B.evolve(carrier_capacity=[1,2,3,4,5,6,7,8,9,10]); B Soliton cellular automata of type ['A', 3, 1] and vacuum = 1 initial state: 34......224....2223 evoltuions: [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10)] current state: ........2344....222..23.............................. sage: B.reset() sage: B.evolve(carrier_index=[1,2,3]) Last carrier: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 4 4 sage: B Soliton cellular automata of type ['A', 3, 1] and vacuum = 1 initial state: 34......224....2223 evoltuions: [(1, 19), (2, 19), (3, 19)] current state: ..................................22......223...2222..... sage: B.reset() sage: B.evolve(carrier_capacity=[1,2,3], carrier_index=[1,2,3]) Last carrier: 1 1 3 4 Last carrier: 1 1 1 2 2 3 3 3 4 sage: B Soliton cellular automata of type ['A', 3, 1] and vacuum = 1 initial state: 34......224....2223 evoltuions: [(1, 1), (2, 2), (3, 3)] current state: .....22.......223....2222.. sage: B.reset() sage: B.evolve(1, 2, number=3) Last carrier: 1 3 Last carrier: 1 4 Last carrier: 1 3 sage: B Soliton cellular automata of type ['A', 3, 1] and vacuum = 1 initial state: 34......224....2223 evoltuions: [(2, 1), (2, 1), (2, 1)] current state: .24......222.....2222. """ if isinstance(carrier_capacity, (list, tuple)): if not isinstance(carrier_index, (list, tuple)): carrier_index = [carrier_index] * len(carrier_capacity) if len(carrier_index) != len(carrier_capacity): raise ValueError("carrier_index and carrier_capacity" " must have the same length") for i, r in zip(carrier_capacity, carrier_index): self.evolve(i, r) return if isinstance(carrier_index, (list, tuple)): # carrier_capacity must be not be a list/tuple if given for r in carrier_index: self.evolve(carrier_capacity, r) return if carrier_capacity is None: carrier_capacity = self._nballs if carrier_index is None: carrier_index = self._vacuum if number is not None: for k in range(number): self.evolve(carrier_capacity, carrier_index) return passed = False K = KirillovReshetikhinTableaux(self._cartan_type, carrier_index, carrier_capacity) try: # FIXME: the maximal_vector() does not work in type E and F empty_carrier = K.maximal_vector() except (ValueError, TypeError, AttributeError): empty_carrier = K.module_generators[0] carrier_factor = (carrier_index, carrier_capacity) last_final_carrier = empty_carrier state = self._states[-1] dims = state.parent().dims while not passed: KRT = TensorProductOfKirillovReshetikhinTableaux( self._cartan_type, dims + (carrier_factor, )) elt = KRT(*(list(state) + [empty_carrier])) RC = RiggedConfigurations(self._cartan_type, (carrier_factor, ) + dims) elt2 = RC(*elt.to_rigged_configuration() ).to_tensor_product_of_kirillov_reshetikhin_tableaux() # Back to an empty carrier or we are not getting any better if elt2[0] == empty_carrier or elt2[0] == last_final_carrier: passed = True KRT = TensorProductOfKirillovReshetikhinTableaux( self._cartan_type, dims) self._states.append(KRT(*elt2[1:])) self._evolutions.append(carrier_factor) if elt2[0] != empty_carrier: print("Last carrier:") print(ascii_art(last_final_carrier)) else: # We need to add more vacuum states last_final_carrier = elt2[0] dims = tuple([(self._vacuum, 1)] * carrier_capacity) + dims
def print_states(self, num=None, vacuum_letter='.'): r""" Print the first ``num`` states of ``self``. .. NOTE:: If the number of states computed for ``self`` is less than ``num``, then this evolves the system using the default time evolution. INPUT: - ``num`` -- the number of states to print EXAMPLES:: sage: B = SolitonCellularAutomata([[2],[-1],[1],[1],[1],[1],[2],[2],[3], ....: [-2],[1],[1],[2],[-1],[1],[1],[1],[1],[1],[1],[2],[3],[3],[-3],[-2]], ....: ['C',3,1]) sage: B.print_states(7) t: 0 _ _ _ __ .........................21....2232..21......23332 t: 1 _ _ _ __ ......................21...2232...21....23332..... t: 2 _ _ _ __ ...................21..2232....21..23332.......... t: 3 _ _ _ __ ...............221..232...2231..332............... t: 4 _ _ _ __ ...........221...232.2231....332.................. t: 5 _ __ __ .......221...2321223......332..................... t: 6 _ __ __ ..2221...321..223......332........................ sage: B = SolitonCellularAutomata([[2],[1],[1],[1],[3],[-2],[1],[1], ....: [1],[2],[2],[-3],[1],[1],[1],[1],[1],[1],[2],[3],[3],[-3]], ....: ['B',3,1]) sage: B.print_states(9, ' ') t: 0 _ _ _ 2 32 223 2333 t: 1 _ _ _ 2 32 223 2333 t: 2 _ _ _ 2 32 223 2333 t: 3 _ _ _ 23 2223 2333 t: 4 __ _ 23 213 2333 t: 5 _ _ _ 2233 222 333 t: 6 _ _ _ 2233 23223 3 t: 7 _ _ _ 2233 232 23 3 t: 8 _ _ _ 2233 232 23 3 sage: B = SolitonCellularAutomata([[2],[-2],[1],[1],[1],[1],[2],[0],[-3], ....: [1],[1],[1],[1],[1],[2],[2],[3],[-3],], ['D',4,2]) sage: B.print_states(10) t: 0 _ _ _ ....................................22....203.....2233 t: 1 _ _ _ ..................................22...203....2233.... t: 2 _ _ _ ................................22..203...2233........ t: 3 _ _ _ ..............................22.203..2233............ t: 4 _ _ _ ............................22203.2233................ t: 5 _ _ _ ........................220223.233.................... t: 6 _ _ _ ....................2202.223.33....................... t: 7 _ _ _ ................2202..223..33......................... t: 8 _ _ _ ............2202...223...33........................... t: 9 _ _ _ ........2202....223....33............................. Example 4.13 from [Yamada2007]_:: sage: B = SolitonCellularAutomata([[3],[3],[1],[1],[1],[1],[2],[2],[2]], ['D',4,3]) sage: B.print_states(15) t: 0 ....................................33....222 t: 1 ..................................33...222... t: 2 ................................33..222...... t: 3 ..............................33.222......... t: 4 ............................33222............ t: 5 ..........................3022............... t: 6 _ ........................332.................. t: 7 _ ......................03..................... t: 8 _ ....................3E....................... t: 9 _ .................21.......................... t: 10 ..............20E............................ t: 11 _ ...........233............................... t: 12 ........2302................................. t: 13 .....23322................................... t: 14 ..233.22..................................... Example 4.14 from [Yamada2007]_:: sage: B = SolitonCellularAutomata([[3],[1],[1],[1],[2],[3],[1],[1],[1],[2],[3],[3]], ['D',4,3]) sage: B.print_states(15) t: 0 ....................................3...23...233 t: 1 ...................................3..23..233... t: 2 ..................................3.23.233...... t: 3 .................................323233......... t: 4 ................................0033............ t: 5 _ ..............................313............... t: 6 ...........................30E.3................ t: 7 _ ........................333...3................. t: 8 .....................3302....3.................. t: 9 ..................33322.....3................... t: 10 ...............333.22......3.................... t: 11 ............333..22.......3..................... t: 12 .........333...22........3...................... t: 13 ......333....22.........3....................... t: 14 ...333.....22..........3........................ """ if num is None: num = len(self._states) if num > len(self._states): for _ in range(num - len(self._states)): self.evolve() vacuum = self._vacuum_elt num_factors = len(self._states[num - 1]) for i, state in enumerate(self._states[:num]): state = [vacuum] * (num_factors - len(state)) + list(state) output = [self._column_repr(b, vacuum_letter) for b in state] max_width = max(b.width() for b in output) start = ascii_art("t: %s \n" % i) start._baseline = -1 print(start + sum((ascii_art(' ' * (max_width - b.width())) + b for b in output), ascii_art('')))