# 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 class BinaryTree(AbstractClonableTree, C Digraph on 9 vertices sage: t1.graph().edges() [(0, 1, None), (0, 4, None), (1, 2, None), (1, 3, None), (4, 5, None), (4, 8, None), (5, 6, None), (5, 7, None)] sage: t1 = BinaryTree() sage: t1.graph() Digraph on 1 vertex """ from sage.graphs.graph import DiGraph res = DiGraph() # The edge set of res will be built up step by step using the # following function: def rec(tr, idx): if not tr: return class BinaryTree(AbstractClonableTree, C res.add_edges([[idx,idx+1], [idx,idx+1+nbl]]) rec(tr[0], idx + 1) rec(tr[1], idx + nbl + 1) # Special treatment for the case when self has only 1 vertex. # In this case, rec(self, 0) would give a false result. if not self: return DiGraph([[0], lambda i,j: False]) rec(self, 0) return res