Ticket #14564: trac_14564-trivial-binary-tree.patch

File trac_14564-trivial-binary-tree.patch, 1.5 KB (added by darij, 6 years ago)

Fixes graph() function. This automatically fixes show(). I have not checked all the other functions, though...

  • sage/combinat/binary_tree.py

    # HG changeset patch
    # User darij grinberg <darijgrinberg@gmail.com>
    # Date 1368238886 25200
    # Node ID 4126ffac76e30af679d33fbb0d0668ff85136091
    # Parent  66f7fe5ef9568b61774b2b8f5d99fb5175aeb232
    trac 14564 patch for trivial binary tree misbehaviour
    
    diff --git a/sage/combinat/binary_tree.py b/sage/combinat/binary_tree.py
    a b class BinaryTree(AbstractClonableTree, C 
    225225            Digraph on 9 vertices
    226226            sage: t1.graph().edges()
    227227            [(0, 1, None), (0, 4, None), (1, 2, None), (1, 3, None), (4, 5, None), (4, 8, None), (5, 6, None), (5, 7, None)]
     228           
     229            sage: t1 = BinaryTree()
     230            sage: t1.graph()
     231            Digraph on 1 vertex
    228232        """
    229233        from sage.graphs.graph import DiGraph
    230234        res = DiGraph()
     235        # The edge set of res will be built up step by step using the
     236        # following function:
    231237        def rec(tr, idx):
    232238            if not tr:
    233239                return
    class BinaryTree(AbstractClonableTree, C 
    236242                res.add_edges([[idx,idx+1], [idx,idx+1+nbl]])
    237243                rec(tr[0], idx + 1)
    238244                rec(tr[1], idx + nbl + 1)
     245        # Special treatment for the case when self has only 1 vertex.
     246        # In this case, rec(self, 0) would give a false result.
     247        if not self:
     248            return DiGraph([[0], lambda i,j: False])
    239249        rec(self, 0)
    240250        return res
    241251