# Boltzmann generator for binary trees with the specification T = E + ZT^2 # and generator for the pointed class. This improves the performance BoltzmannTree := proc(x) # set up u := evalf(rand()/10^12); # maple rand() gives a 12 digit nonneg int # handle union if u < 1/((1-sqrt(1-4*x))/(2*x)) then return E; end if; # handle product return [Z, BoltzmannTree(x), BoltzmannTree(x)]; end proc; BoltzmannPointedTree := proc(x) # set up T := (1-sqrt(1-4*z))/(2*z); pointedT := diff(T, z); T := subs(z=x, T); pointedT := subs(z=x, pointedT); u := evalf(rand()/10^12); # maple rand() gives a 12 digit nonneg int # handle union if u < x*T/pointedT then return [Z, BoltzmannTree(x), BoltzmannTree(x)]; end if; if u < x*T/pointedT + x*pointedT*T/pointedT then return [Z, BoltzmannPointedTree(x), BoltzmannTree(x)]; end if; return [Z, BoltzmannTree(x), BoltzmannPointedTree(x)]; end proc;