Help:=proc(): print(`Edges(n), Graphs(n), Neis(G,i), CC(G,Erdos) `): print(`IsCon(G,n), ConG(n) , NuCCSeqSlow(N) , NuCCSeqFast(N)`): print(`LabTrees(n) , NuLabTreesSlow(N) , NuLabTreesSeqFast(N)`): end: with(combinat): #Edges(n): the set of all edges of K_n Edges:=proc(n) local i,j: {seq(seq({i,j},i=1..j-1),j=2..n)}: end: #Graphs(n): ALL graphs on {1, ..., n} Graphs:=proc(n): powerset(Edges(n)):end: #Neis(G,i): inputs a graph G (given as a set of edges, #and every edge is given a 2-set) and outputs all #the vertices adjacent to it (i.e. all j such that #{i,j} is in G Neis:=proc(G,i) local N,e: option remember: N:={}: for e in G do if member(i,e) then N:=N union (e minus {i}): fi: od: N: end: #CC(G,Erdos): the connected component of vertex Erdos in graph G CC:=proc(G,Erdos) local C1,NewF,v: C1:={Erdos}: NewF:=Neis(G,Erdos): while NewF minus C1<>{} do C1:=C1 union NewF: NewF:= `union`(seq(Neis(G,v), v in NewF)): od: C1: end: #IsCon(G,n): Is the graph G on {1, ..., n} connected? IsCon:=proc(G,n): evalb(nops(CC(G,1))=n): end: #the set of all connected labelled graphs on {1, ..., n} ConG:=proc(n) local ConGraphs, AllGraphs, G: AllGraphs:=Graphs(n): ConGraphs:={}: for G in AllGraphs do if IsCon(G,n) then ConGraphs:=ConGraphs union {G}: fi: od: ConGraphs: end: #The first N terms of sequence A001187 by the SLOW way #(But slow is not always stupid) NuCCSeqSlow:=proc(N) local i: [seq(nops(ConG(i)),i=1..N)]: end: # NuCCSeqFast(N): #The first N terms of sequence A001187 by the FAST way #(using exponential generatingfunctionology) NuCCSeqFast:=proc(N) local i,x,F: F:=taylor(log(add(x^i*2^(binomial(i,2))/i!,i=0..N)), x=0, N+1): [ seq(coeff(F,x,i)*i!,i=1..N)]: end: #the set of all labelled trees on {1, ..., n} LabTrees:=proc(n) local ConGraphs, AllGraphs, G: AllGraphs:=choose(Edges(n),n-1) : ConGraphs:={}: for G in AllGraphs do if IsCon(G,n) then ConGraphs:=ConGraphs union {G}: fi: od: ConGraphs: end: #The first N terms of the number of labelled trees #sequence by the SLOW way #(But slow is not always stupid) NuLabTreesSlow:=proc(N) local i: [seq(nops(LabTrees(i)),i=1..N)]: end: # WtCCSeqFast(N,y): #The first N terms of the weight-enumerator of #all connected graphs according to the weight #y^(#edges) the FAST way #(using exponential generatingfunctionology) WtCCSeqFast:=proc(N,y) local i,x,F: F:=taylor(log(add(x^i*(1+y)^(binomial(i,2))/i!,i=0..N)), x=0, N+1): [ seq(coeff(F,x,i)*i!,i=1..N)]: end: