Ejemplo n.º 1
0
    def _unicode_art_term(self, t):
        r"""
        Return a unicode art representation of the term indexed by ``t``.

        TESTS::

            sage: Q = QSystem(QQ, ['A',4])
            sage: unicode_art(Q.an_element())
            1 + 2*Q₁⁽¹⁾ + (Q₁⁽¹⁾)²(Q₁⁽²⁾)²(Q₁⁽³⁾)³ + 3*Q₁⁽²⁾
        """
        from sage.typeset.unicode_art import UnicodeArt, unicode_subscript, unicode_superscript
        if t == self.one_basis():
            return UnicodeArt(["1"])

        ret = UnicodeArt("")
        for k, exp in t._sorted_items():
            a, m = k
            var = UnicodeArt([
                u"Q" + unicode_subscript(m) + u'⁽' + unicode_superscript(a) +
                u'⁾'
            ],
                             baseline=0)
            if exp > 1:
                var = (
                    UnicodeArt([u'('], baseline=0) + var +
                    UnicodeArt([u')' + unicode_superscript(exp)], baseline=0))
            ret += var
        return ret
Ejemplo n.º 2
0
    def _unicode_art_generator(self, m):
        r"""
        Return an unicode art representing the generator indexed by ``m``.

        TESTS::

            sage: R = NonCommutativeSymmetricFunctions(QQ).R()
            sage: unicode_art(R[1,2,2,4])
            R
               ┌┬┬┬┐
              ┌┼┼┴┴┘
             ┌┼┼┘
             ├┼┘
             └┘
            sage: Partitions.options.convention="french"
            sage: unicode_art(R[1,2,2,4])
            R
             ┌┐
             ├┼┐
             └┼┼┐
              └┼┼┬┬┐
               └┴┴┴┘
            sage: Partitions.options._reset()
        """
        from sage.typeset.unicode_art import UnicodeArt, unicode_art
        pref = UnicodeArt([self.prefix()])
        r = pref * (UnicodeArt([" "**Integer(len(pref))]) + unicode_art(m))
        r._baseline = r._h - 1
        return r
Ejemplo n.º 3
0
Archivo: glca.py Proyecto: yabirgb/sage
    def _unicode_art_(self, number=None):
        r"""
        Return a unicode art representation of ``self``.

        EXAMPLES::

            sage: G = cellular_automata.GraftalLace([5,1,2,5,4,5,5,0])
            sage: G.evolve(10)
            sage: unicode_art(G)
                                 ◾
                                 │
                                 ◾
                                ╱ ╲
                               ◾ ◾ ◾
                              ╱ ╲ ╱ ╲
                             ◾ ◾ ◾ ◾ ◾
                            ╱ ╲  │  ╱ ╲
                           ◾ ◾ ◾ ◾ ◾ ◾ ◾
                          ╱ ╲ ╱ ╳ ╳ ╲ ╱ ╲
                         ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾
                        ╱ ╲  │╱ ╲│╱ ╲│  ╱ ╲
                       ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾
                      ╱ ╲ ╱ ╲ ╲ ╱ ╲ ╱ ╱ ╲ ╱ ╲
                     ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾
                    ╱ ╲  │  ╱ ╲│   │╱ ╲  │  ╱ ╲
                   ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾
                  ╱ ╲ ╱ ╳ ╳ ╲ ╱     ╲ ╱ ╳ ╳ ╲ ╱ ╲
                 ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾
                ╱ ╲  │╱ ╲│╱ ╲│       │╱ ╲│╱ ╲│  ╱ ╲
               ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾
              ╱ ╲ ╱ ╲ ╲ ╱ ╲ ╱         ╲ ╱ ╲ ╱ ╱ ╲ ╱ ╲
             ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾ ◾
        """
        if number is None:
            number = len(self._states)

        space = len(self._states[:number]) * 2 - 1
        ret = UnicodeArt([u' ' * space + u'◾'])
        space += 1
        for i, state in enumerate(self._states[:number]):
            temp = u' ' * (space - 2)
            last = u' '
            for x in state:
                if x & 0x4:
                    if last == u'╱':
                        temp += u'╳'
                    else:
                        temp += u'╲'
                else:
                    temp += last
                temp += u'│' if x & 0x2 else ' '
                last = u'╱' if x & 0x1 else ' '
            ret *= UnicodeArt([temp + last])
            space -= 1
            ret *= UnicodeArt(
                [u' ' * space + u' '.join(u'◾' for dummy in range(2 * i + 1))])
            space -= 1
        return ret
Ejemplo n.º 4
0
    def _unicode_art_term(self, t):
        r"""
        Return a unicode art representation of the term indexed by ``t``.

        TESTS::

            sage: Q = QSystem(QQ, ['A',4])
            sage: unicode_art(Q.an_element())
            1 + 2*Q₁⁽¹⁾ + (Q₁⁽¹⁾)²(Q₁⁽²⁾)²(Q₁⁽³⁾)³ + 3*Q₁⁽²⁾
        """
        from sage.typeset.unicode_art import UnicodeArt
        if t == self.one_basis():
            return UnicodeArt(["1"])

        subs = {
            '0': u'₀',
            '1': u'₁',
            '2': u'₂',
            '3': u'₃',
            '4': u'₄',
            '5': u'₅',
            '6': u'₆',
            '7': u'₇',
            '8': u'₈',
            '9': u'₉'
        }
        sups = {
            '0': u'⁰',
            '1': u'¹',
            '2': u'²',
            '3': u'³',
            '4': u'⁴',
            '5': u'⁵',
            '6': u'⁶',
            '7': u'⁷',
            '8': u'⁸',
            '9': u'⁹'
        }

        def to_super(x):
            return u''.join(sups[i] for i in str(x))

        def to_sub(x):
            return u''.join(subs[i] for i in str(x))

        ret = UnicodeArt("")
        for k, exp in t._sorted_items():
            a, m = k
            var = UnicodeArt([u"Q" + to_sub(m) + u'⁽' + to_super(a) + u'⁾'],
                             baseline=0)
            if exp > 1:
                var = (UnicodeArt([u'('], baseline=0) + var +
                       UnicodeArt([u')' + to_super(exp)], baseline=0))
            ret += var
        return ret
Ejemplo n.º 5
0
    def _unicode_art_(self):
        """
        Return a unicode art representation of ``self``.

        TESTS::

            sage: y = crystals.infinity.GeneralizedYoungWalls(2)([[0,2,1],[1,0,2,1,0],[],[0],[1,0,2],[],[],[1]])
            sage: unicode_art(y)
                            ┌───┐
                            │ 1 │
                            └───┘
                                │
                                ┤
                                │
                    ┌───┬───┬───┐
                    │ 1 │ 0 │ 2 │
                    └───┴───┼───┤
                            │ 0 │
                            └───┘
                                │
            ┌───┬───┬───┬───┬───┐
            │ 1 │ 0 │ 2 │ 1 │ 0 │
            └───┴───┼───┼───┼───┤
                    │ 0 │ 2 │ 1 │
                    └───┴───┴───┘
        """
        from sage.typeset.unicode_art import UnicodeArt
        if not self.data:
            return UnicodeArt(["0"])

        from sage.combinat.output import ascii_art_table
        import unicodedata
        v = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL')
        vl = unicodedata.lookup('BOX DRAWINGS LIGHT VERTICAL AND LEFT')
        table = [[None] * (self.cols - len(row)) + row
                 for row in reversed(self)]
        ret = []
        for i, row in enumerate(
                ascii_art_table(table, use_unicode=True).splitlines()):
            if row[-1] == " ":
                if i % 2 == 0:
                    ret.append(row[:-1] + vl)
                else:
                    ret.append(row[:-1] + v)
            else:
                ret.append(row)
        return UnicodeArt(ret)
Ejemplo n.º 6
0
    def character_art(self, num_lines):
        """
        Return the unicode art of the symbol

        EXAMPLES::

            sage: from sage.typeset.symbols import *
            sage: unicode_left_curly_brace.character_art(3)
            ⎧
            ⎨
            ⎩
        """
        from sage.typeset.unicode_art import UnicodeArt
        return UnicodeArt(self(num_lines))
Ejemplo n.º 7
0
    def _unicode_art_(self):
        r"""
        Return a unicode art representation of ``self``.

        EXAMPLES::

            sage: ECA = cellular_automata.Elementary(22, width=30, initial_state=[1])
            sage: ECA.evolve(30)
            sage: unicode_art(ECA)
                                         █
                                        ██
                                       █
                                      ███
                                     █   █
                                    ███ ██
                                   █
                                  ███
                                 █   █
                                ███ ███
                               █       █
                              ███     ███
                             █   █   █   █
                            ███ ███ ███ ██
                           █
                          ███
                         █   █
                        ███ ███
                       █       █
                      ███     ███
                     █   █   █   █
                    ███ ███ ███ ███
                   █               █
                  ███             ███
                 █   █           █   █
                ███ ███         ███ ███
               █       █       █       █
              ███     ███     ███     ███
             █   █   █   █   █   █   █   █
            ███ ███ ███ ███ ███ ███ ███ ██
        """
        return UnicodeArt([
            u''.join(u'█' if x else u' ' for x in state)
            for state in self._states
        ])
Ejemplo n.º 8
0
    def _unicode_art_(self):
        r"""
        Return a unicode representation of ``self``.

        EXAMPLES::

            sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]])
            sage: unicode_art(PP)
                 ╱ ╲
                │╲ ╱│
                │╲│╱ ╲
               ╱ ╲│╲ ╱ ╲
              │╲ ╱│╲│╲ ╱│
             ╱ ╲│╱ ╲│╲│╱│
            │╲ ╱ ╲ ╱ ╲│╱ ╲
             ╲│╲ ╱│╲ ╱│╲ ╱│
               ╲│╱ ╲│╱ ╲│╱
        """
        from sage.typeset.unicode_art import UnicodeArt
        return UnicodeArt(self._repr_diagram(use_unicode=True).splitlines(), baseline=0)
Ejemplo n.º 9
0
    def _unicode_art_(self):
        """
        Return unicode art for the knot.

        INPUT:

        - a knot

        OUTPUT:

        - unicode art for the knot

        EXAMPLES::

            sage: W = Knots()
            sage: K = W.from_dowker_code([-4,-6,-2])
            sage: unicode_art(K)
             ╭─╮
            ╭──│╮
            │╰╮││
            │ ╰─╯
            ╰──╯

            sage: G = [-1, 2, -3, 4, 6, -7, 8, 1, -2, 3, -4, -5, 7, -8, 5, -6]
            sage: K = Knots().from_gauss_code(G)
            sage: unicode_art(K)
               ╭─────╮
               │╭─────╮
              ╭─│╮   ││
             ╭─╯││   ││
             │╰─╯│   ││
             │   ╰──╮││
             │     ╭│╯│
             │    ╭│╯ │
            ╭─────│╯  │
            │╰────╯   │
            ╰─────────╯

        TESTS::

            sage: W = Knots()
            sage: unicode_art(W.one())
            ╭╮
            ╰╯
        """
        style = 2  # among 0, 1, 2 (how to display crossings, see below)
        gauss = self.gauss_code()
        if not gauss:
            gauss = []
        else:
            gauss = gauss[0]

        graphe, (hori, vert) = rectangular_diagram(gauss)
        maxx, maxy = 0, 0
        for a, b in graphe:
            maxx = max(a, maxx)
            maxy = max(b, maxy)
        M = [[" " for a in range(maxy + 1)] for b in range(maxx + 1)]
        for a, b in graphe:
            (x, y), (xx, yy) = graphe.neighbors((a, b))
            if x != a:
                x, y, xx, yy = xx, yy, x, y
            if y < b:
                if xx < a:
                    M[a][b] = u"╯"
                else:
                    M[a][b] = u"╮"
            else:
                if xx < a:
                    M[a][b] = u"╰"
                else:
                    M[a][b] = u"╭"

        for ab, cd in graphe.edge_iterator(labels=False):
            a, b = ab
            c, d = cd
            if a == c:
                b, d = sorted((b, d))
                for i in range(b + 1, d):
                    M[a][i] = u"─"
            else:
                a, c = sorted((a, c))
                for i in range(a + 1, c):
                    M[i][b] = u"│"

        if style == 0:
            H = u"┿"
            V = u"╂"
        elif style == 1:
            H = u"━"
            V = u"┃"
        elif style == 2:
            H = u"─"
            V = u"│"

        for x, y in hori:
            M[x][y] = H
        for x, y in vert:
            M[x][y] = V

        from sage.typeset.unicode_art import UnicodeArt
        return UnicodeArt([''.join(ligne) for ligne in M])
Ejemplo n.º 10
0
# -*- coding: utf-8 -*-

# Ideally, we would put this in an ".ipy" file to be able to use magic
# commands, but this causes trouble with the unicode character below

# %run "code.py"
# %display unicode_art

tensor.symbol=u" ⊗ "
Partitions.options.convention = "french"
Partitions.options.display = "list"
from sage.typeset.unicode_art import UnicodeArt
Partition._unicode_art_ = lambda p: UnicodeArt([''.join(str(i) for i in p)])
SymmetricFunctions(QQ).inject_shorthands(verbose=False)