# 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 
225  225  Digraph on 9 vertices 
226  226  sage: t1.graph().edges() 
227  227  [(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 
228  232  """ 
229  233  from sage.graphs.graph import DiGraph 
230  234  res = DiGraph() 
 235  # The edge set of res will be built up step by step using the 
 236  # following function: 
231  237  def rec(tr, idx): 
232  238  if not tr: 
233  239  return 
… 
… 
class BinaryTree(AbstractClonableTree, C 
236  242  res.add_edges([[idx,idx+1], [idx,idx+1+nbl]]) 
237  243  rec(tr[0], idx + 1) 
238  244  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]) 
239  249  rec(self, 0) 
240  250  return res 
241  251  