Exemple #1
0
    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.misc.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
Exemple #2
0
    def _ascii_art_(self):
        """
        Return Ascii Art

        OUTPUT:

        Ascii art of the constraint (in)equality.

        EXAMPLES::

            sage: mip.<x> = MixedIntegerLinearProgram()
            sage: ascii_art(x[0] * vector([1,2]) >= 0)
            (0.0, 0.0) <= (1.0, 2.0)*x_0
            sage: ascii_art(x[0] * matrix([[1,2],[3,4]]) >= 0)            
            [0 0] <= [x_0   2*x_0]
            [0 0]    [3*x_0 4*x_0]
        """
        from sage.misc.ascii_art import AsciiArt

        def matrix_art(m):
            lines = str(m).splitlines()
            return AsciiArt(lines, baseline=len(lines) / 2)

        comparator = AsciiArt([' == ' if self.is_equation() else ' <= '])
        return matrix_art(self.lhs()) + comparator + matrix_art(self.rhs())
Exemple #3
0
 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_(self):
        """
        Return an ASCII art representation of ``self``.

        EXAMPLES::

            sage: RC = RiggedConfigurations(['D', 4, 1], [[2, 2]])
            sage: ascii_art(RC(partition_list=[[2], [3,1], [3], [3]]))
            -1[ ][ ]-1  2[ ][ ][ ]2  -2[ ][ ][ ]-2  -2[ ][ ][ ]-2
                        0[ ]0
            sage: ascii_art(RC(partition_list=[[],[],[],[]]))
            (/)  (/)  (/)  (/)
            sage: RC = RiggedConfigurations(['D', 7, 1], [[3,3],[5,2],[4,3],[2,3],[4,4],[3,1],[1,4],[2,2]])
            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]],
            ....:          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]])
            sage: ascii_art(elt)
            3[ ][ ]2  1[ ][ ][ ]1  4[ ][ ]4  2[ ][ ]1  0[ ][ ][ ]0  0[ ][ ]0  0[ ][ ]0
                      2[ ][ ]0     4[ ][ ]1  2[ ][ ]0  2[ ][ ]1     0[ ]0     0[ ][ ]0
                      1[ ]0        3[ ]2     0[ ]0     0[ ]0        0[ ]0
                                   3[ ]1     0[ ]0     0[ ]0
                                             0[ ]0     0[ ]0
                                             0[ ]0     0[ ]0
            sage: Partitions.global_options(convention='French')
            sage: ascii_art(elt)
                                             0[ ]0     0[ ]0
                                             0[ ]0     0[ ]0
                                   3[ ]1     0[ ]0     0[ ]0
                      1[ ]0        3[ ]2     0[ ]0     0[ ]0        0[ ]0
                      2[ ][ ]0     4[ ][ ]1  2[ ][ ]0  2[ ][ ]1     0[ ]0     0[ ][ ]0
            3[ ][ ]2  1[ ][ ][ ]1  4[ ][ ]4  2[ ][ ]1  0[ ][ ][ ]0  0[ ][ ]0  0[ ][ ]0
            sage: Partitions.global_options.reset()
        """
        from sage.combinat.partition import PartitionOptions
        if PartitionOptions['convention'] == "French":
            baseline = lambda s: 0
        else:
            baseline = lambda s: len(s)
        from sage.misc.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
Exemple #5
0
    def _ascii_art_(self):
        r"""
        Return an ASCII art representation of ``self``.

        EXAMPLES::

            sage: F = FreeAbelianMonoid(index_set=ZZ)
            sage: a,b,c,d,e = [F.gen(i) for i in range(5)]
            sage: ascii_art(a*e*d)
            F *F *F
             0  3  4
            sage: ascii_art(a*b^2*e*d)
                2
            F *F *F *F
             0  1  3  4
        """
        from sage.misc.ascii_art import AsciiArt, ascii_art, empty_ascii_art

        if not self._monomial:
            return AsciiArt(["1"])

        monomial = self._sorted_items()
        P = self.parent()
        scalar_mult = P._print_options['scalar_mult']

        if all(x[1] == 1 for x in monomial):
            ascii_art_gen = lambda m: P._ascii_art_generator(m[0])
        else:
            pref = AsciiArt([P.prefix()])

            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

        b = ascii_art_gen(monomial[0])
        for x in monomial[1:]:
            b = b + AsciiArt([scalar_mult]) + ascii_art_gen(x)
        return b
Exemple #6
0
    def _ascii_art_(self):
        """
        TESTS::

            sage: ascii_art(RibbonTableaux([[2,1],[]],[1,1,1],1).list())
            [   1  3    1  2 ]
            [   2   ,   3    ]
        """
        from sage.misc.ascii_art import AsciiArt
        return AsciiArt(self._repr_diagram().splitlines())
Exemple #7
0
    def _ascii_art_(self):
        """
        TESTS::

            sage: ascii_art(SkewPartitions(3).list())
            [                        *   *   *    * ]
            [      **   **   *    *  *   *  *    *  ]
            [ ***, * , *  , **, ** , *, * , * , *   ]
            sage: Partitions.global_options(diagram_str='#', convention="French")
            sage: ascii_art(SkewPartitions(3).list())
            [                        #  #   #   #   ]
            [      #   #    ##  ##   #   #  #    #  ]
            [ ###, ##,  ##,  #,   #, #,  #,  #,   # ]
            sage: Partitions.global_options.reset()
        """
        from sage.misc.ascii_art import AsciiArt
        return AsciiArt(self.diagram().splitlines())
Exemple #8
0
    def _ascii_art_( self ):
        r"""
        TESTS::

            sage: ascii_art(BinaryTree())
            <BLANKLINE>
            sage: ascii_art(BinaryTree([]))
            o
            sage: for bt in BinaryTrees(3):
            ....:     print ascii_art(bt)
            o
             \
              o
               \
                o
            o
             \
              o
             /
            o
              o
             / \
            o   o
              o
             /
            o
             \
              o
                o
               /
              o
             /
            o
            sage: ascii_art(BinaryTree([None,[]]))
            o
             \
              o
            sage: ascii_art(BinaryTree([None,[None,[]]]))
            o
             \
              o
               \
                o
            sage: ascii_art(BinaryTree([None,[[],None]]))
            o
             \
              o
             /
            o
            sage: ascii_art(BinaryTree([None,[[[],[]],[]]]))
               o
                \
                _o_
               /   \
              o     o
             / \
            o   o
            sage: ascii_art(BinaryTree([None,[[None,[[],[]]],None]]))
            o
             \
              o
             /
            o
             \
              o
             / \
            o   o
            sage: ascii_art(BinaryTree([[],None]))
              o
             /
            o
            sage: ascii_art(BinaryTree([[[[],None], None],None]))
                  o
                 /
                o
               /
              o
             /
            o
            sage: ascii_art(BinaryTree([[[],[]],None]))
                o
               /
              o
             / \
            o   o
            sage: ascii_art(BinaryTree([[[None,[]],[[[],None],None]], None]))
                   o
                  /
              ___o___
             /       \
            o         o
             \       /
              o     o
                   /
                  o
            sage: ascii_art(BinaryTree([[None,[[],[]]],None]))
              o
             /
            o
             \
              o
             / \
            o   o
            sage: ascii_art(BinaryTree([[],[]]))
              o
             / \
            o   o
            sage: ascii_art(BinaryTree([[],[[],None]]))
              _o_
             /   \
            o     o
                 /
                o
            sage: ascii_art(BinaryTree([[None,[]],[[[],None],None]]))
              ___o___
             /       \
            o         o
             \       /
              o     o
                   /
                  o
            sage: ascii_art(BinaryTree([[[],[]],[[],None]]))
                __o__
               /     \
              o       o
             / \     /
            o   o   o
            sage: ascii_art(BinaryTree([[[],[]],[[],[]]]))
                __o__
               /     \
              o       o
             / \     / \
            o   o   o   o
            sage: ascii_art(BinaryTree([[[[],[]],[[],[]]],[]]))
                    ___o___
                   /       \
                __o__       o
               /     \
              o       o
             / \     / \
            o   o   o   o
            sage: ascii_art(BinaryTree([[],[[[[],[]],[[],[]]],[]]]))
              _____o______
             /            \
            o           ___o___
                       /       \
                    __o__       o
                   /     \
                  o       o
                 / \     / \
                o   o   o   o
        """
        node_to_str = lambda bt: str(bt.label()) if hasattr(bt, "label") else "o"

        if self.is_empty():
            from sage.misc.ascii_art import empty_ascii_art
            return empty_ascii_art

        from sage.misc.ascii_art import AsciiArt
        if self[0].is_empty() and self[1].is_empty():
            bt_repr = AsciiArt( [node_to_str(self)] )
            bt_repr._root = 1
            return bt_repr
        if self[0].is_empty():
            node = node_to_str(self)
            rr_tree = self[1]._ascii_art_()
            if rr_tree._root > 2:
                f_line = " " ** Integer( rr_tree._root - 3 ) + node
                s_line = " " ** Integer( len( node ) + rr_tree._root - 3 ) + "\\"
                t_repr = AsciiArt( [f_line, s_line] ) * rr_tree
                t_repr._root = rr_tree._root - 2
            else:
                f_line = node
                s_line = " " + "\\"
                t_line = " " ** Integer( len( node ) + 1 )
                t_repr = AsciiArt( [f_line, s_line] ) * ( AsciiArt( [t_line] ) + rr_tree )
                t_repr._root = rr_tree._root
            t_repr._baseline = t_repr._h - 1
            return t_repr
        if self[1].is_empty():
            node = node_to_str(self)
            lr_tree = self[0]._ascii_art_()
            f_line = " " ** Integer( lr_tree._root + 1 ) + node
            s_line = " " ** Integer( lr_tree._root ) + "/"
            t_repr = AsciiArt( [f_line, s_line] ) * lr_tree
            t_repr._root = lr_tree._root + 2
            t_repr._baseline = t_repr._h - 1
            return t_repr
        node = node_to_str(self)
        lr_tree = self[0]._ascii_art_()
        rr_tree = self[1]._ascii_art_()
        nb_ = lr_tree._l - lr_tree._root + rr_tree._root - 1
        nb_L = int( nb_ / 2 )
        nb_R = nb_L + ( 1 if nb_ % 2 == 1 else 0 )
        f_line = " " ** Integer( lr_tree._root + 1 ) + "_" ** Integer( nb_L ) + node
        f_line += "_" ** Integer( nb_R )
        s_line = " " ** Integer( lr_tree._root ) + "/" + " " ** Integer( len( node ) + rr_tree._root - 1 + ( lr_tree._l - lr_tree._root ) ) + "\\"
        t_repr = AsciiArt( [f_line, s_line] ) * ( lr_tree + AsciiArt( [" " ** Integer( len( node ) + 2 )] ) + rr_tree )
        t_repr._root = lr_tree._root + nb_L + 2
        t_repr._baseline = t_repr._h - 1
        return t_repr
 def matrix_art(m):
     lines = str(m).splitlines()
     return AsciiArt(lines, baseline=len(lines)/2)
Exemple #10
0
    def _ascii_art_(self):
        r"""
        TESTS::

            sage: t = OrderedTree([])
            sage: ascii_art(t)
            o
            sage: t = OrderedTree([[]])
            sage: aa = ascii_art(t);aa
            o
            |
            o
            sage: aa.get_baseline()
            2
            sage: tt1 = OrderedTree([[],[[],[],[[[[]]]]],[[[],[],[],[]]]])
            sage: ascii_art(tt1)
              _____o_______
             /    /       /
            o   _o__     o
               / / /     |
              o o o    __o___
                  |   / / / /
                  o  o o o o
                  |
                  o
                  |
                  o
            sage: ascii_art(tt1.canonical_labelling())
              ______1_______
             /    /        /
            2   _3__      10
               / / /      |
              4 5 6    ___11____
                  |   /  /  /  /
                  7  12 13 14 15
                  |
                  8
                  |
                  9
            sage: ascii_art(OrderedTree([[],[[]]]))
                  o_
                 / /
                o o
                  |
                  o
            sage: t = OrderedTree([[[],[[[],[]]],[[]]],[[[[[],[]]]]],[[],[]]])
            sage: ascii_art(t)
                  _____o_______
                 /       /    /
              __o____   o    o_
             /   /  /   |   / /
            o   o  o    o  o o
                |  |    |
                o_ o    o
               / /      |
              o o       o_
                       / /
                      o o
            sage: ascii_art(t.canonical_labelling())
                  ______1________
                 /       /      /
              __2____   10     16_
             /   /  /   |     /  /
            3   4  8    11   17 18
                |  |    |
                5_ 9    12
               / /      |
              6 7       13_
                       /  /
                      14 15
        """
        node_to_str = lambda t: str(t.label()) if hasattr(t, "label") else "o"

        if self.is_empty():
            from sage.misc.ascii_art import empty_ascii_art
            return empty_ascii_art

        from sage.misc.ascii_art import AsciiArt
        if len(self) == 0:
            t_repr = AsciiArt( [node_to_str(self)] )
            t_repr._root = 1
            return t_repr
        if len(self) == 1:
            repr_child = self[0]._ascii_art_()
            sep = AsciiArt( [" "*(repr_child._root-1)] )
            t_repr = AsciiArt( [node_to_str(self)] )
            t_repr._root = 1
            repr_root = (sep + t_repr)*(sep + AsciiArt( ["|"] ))
            t_repr = repr_root * repr_child
            t_repr._root = repr_child._root
            t_repr._baseline = t_repr._h - 1
            return t_repr
        # General case
        l_repr = [subtree._ascii_art_() for subtree in self]
        acc = l_repr.pop(0)
        whitesep = acc._root+1
        lf_sep = " "*(acc._root+1) + "_"*(acc._l-acc._root)
        ls_sep = " "*(acc._root) + "/" + " "*(acc._l-acc._root)
        while len(l_repr) > 0:
            t_repr = l_repr.pop(0)
            acc += AsciiArt([" "]) + t_repr
            if len(l_repr) == 0: lf_sep += "_"*(t_repr._root+1)
            else: lf_sep += "_"*(t_repr._l+1)
            ls_sep += " "*(t_repr._root) + "/" + " "*(t_repr._l-t_repr._root)
        mid = whitesep + int((len(lf_sep)-whitesep)/2)
        node = node_to_str( self )
        t_repr = AsciiArt([lf_sep[:mid-1] + node + lf_sep[mid+len(node)-1:], ls_sep]) * acc
        t_repr._root = mid
        t_repr._baseline = t_repr._h - 1
        return t_repr
Exemple #11
0
    def _ascii_art_(self):
        r"""
        TESTS::

            sage: t = OrderedTree([])
            sage: ascii_art(t)
            o
            sage: t = OrderedTree([[]])
            sage: aa = ascii_art(t);aa
            o
            |
            o
            sage: aa.get_baseline()
            2
            sage: tt1 = OrderedTree([[],[[],[],[[[[]]]]],[[[],[],[],[]]]])
            sage: ascii_art(tt1)
              _____o_______
             /    /       /
            o   _o__     o
               / / /     |
              o o o    __o___
                  |   / / / /
                  o  o o o o
                  |
                  o
                  |
                  o
            sage: ascii_art(tt1.canonical_labelling())
              ______1_______
             /    /        /
            2   _3__      10
               / / /      |
              4 5 6    ___11____
                  |   /  /  /  /
                  7  12 13 14 15
                  |
                  8
                  |
                  9
            sage: ascii_art(OrderedTree([[],[[]]]))
                  o_
                 / /
                o o
                  |
                  o
            sage: t = OrderedTree([[[],[[[],[]]],[[]]],[[[[[],[]]]]],[[],[]]])
            sage: ascii_art(t)
                  _____o_______
                 /       /    /
              __o____   o    o_
             /   /  /   |   / /
            o   o  o    o  o o
                |  |    |
                o_ o    o
               / /      |
              o o       o_
                       / /
                      o o
            sage: ascii_art(t.canonical_labelling())
                  ______1________
                 /       /      /
              __2____   10     16_
             /   /  /   |     /  /
            3   4  8    11   17 18
                |  |    |
                5_ 9    12
               / /      |
              6 7       13_
                       /  /
                      14 15
        """
        node_to_str = lambda t: str(t.label()) if hasattr(t, "label") else "o"

        if self.is_empty():
            from sage.misc.ascii_art import empty_ascii_art
            return empty_ascii_art

        from sage.misc.ascii_art import AsciiArt
        if len(self) == 0:
            t_repr = AsciiArt([node_to_str(self)])
            t_repr._root = 1
            return t_repr
        if len(self) == 1:
            repr_child = self[0]._ascii_art_()
            sep = AsciiArt([" " * (repr_child._root - 1)])
            t_repr = AsciiArt([node_to_str(self)])
            t_repr._root = 1
            repr_root = (sep + t_repr) * (sep + AsciiArt(["|"]))
            t_repr = repr_root * repr_child
            t_repr._root = repr_child._root
            t_repr._baseline = t_repr._h - 1
            return t_repr
        # General case
        l_repr = [subtree._ascii_art_() for subtree in self]
        acc = l_repr.pop(0)
        whitesep = acc._root + 1
        lf_sep = " " * (acc._root + 1) + "_" * (acc._l - acc._root)
        ls_sep = " " * (acc._root) + "/" + " " * (acc._l - acc._root)
        while len(l_repr) > 0:
            t_repr = l_repr.pop(0)
            acc += AsciiArt([" "]) + t_repr
            if len(l_repr) == 0: lf_sep += "_" * (t_repr._root + 1)
            else: lf_sep += "_" * (t_repr._l + 1)
            ls_sep += " " * (t_repr._root) + "/" + " " * (t_repr._l -
                                                          t_repr._root)
        mid = whitesep + int((len(lf_sep) - whitesep) / 2)
        node = node_to_str(self)
        t_repr = AsciiArt([
            lf_sep[:mid - 1] + node + lf_sep[mid + len(node) - 1:], ls_sep
        ]) * acc
        t_repr._root = mid
        t_repr._baseline = t_repr._h - 1
        return t_repr