#C7.txt, Sept. 29, 2016, starting the Algebraic ansatz Help:=proc(): print(` BT(n), bt(n), De(T) , PlotT(T,Rx,Ry,dx,dy,eps)`): end: with(plots): #BT(n): the SET of complete binary trees on n leaves #T is either [] or [T1,T2] with smaller T1,T2 BT:=proc(n) local S,S1,S2,i,t1,t2: option remember: if n=0 then RETURN({}): elif n=1 then RETURN({[]}): fi: S:={}: for i from 1 to n-1 do S1:=BT(i): S2:=BT(n-i): S:=S union { seq(seq([t1,t2],t1 in S1),t2 in S2)}: od: S: end: #bt(n): nops(BT(n)) (w/o computing BT(n)) bt:=proc(n) local i: option remember: if n<=0 then RETURN(0): elif n=1 then RETURN(1): else add(bt(i)*bt(n-i),i=1..n-1): fi: end: #De(T): the depth of the complete binary tree T De:=proc(T): if T=[] then RETURN(0): else max(De(T[1]),De(T[2])) +1: fi: end: PlotT:=proc(T,Rx,Ry,dx,dy,eps): display(PlotT1(T,Rx,Ry,dx,dy,eps)): end: #PlotT1(T,Rx,Ry,dx,dy,eps): outputs a plot structure for the complete binary #tree T, whose coordinates of the root are [Rx,Ry], and dx is the horizntal #distance to the left and right of the two branches, and eps is a small #parameter enuring that these two branches do not meet PlotT1:=proc(T,Rx,Ry,dx,dy,eps) local pic,pic1,pic2: pic:=plot({[Rx,Ry]},style=point,symbol=circle, color=red,axes=none): if T=[] then RETURN(pic): fi: pic1:=PlotT1(T[1],Rx-dx-eps*De(T),Ry-dy,dx,dy,eps): pic2:=PlotT1(T[2],Rx+dx+eps*De(T) ,Ry-dy,dx,dy,eps): pic:=pic,pic1,pic2: pic:=pic,plot([[Rx,Ry],[Rx-dx-eps*De(T),Ry-dy]]),plot([[Rx,Ry],[Rx+dx+eps*De(T),Ry-dy]]): pic: end: