Various bits of visualization code based on the diagrams library.
RemyVis.hs: generates an animation of Remy's algorithm for uniformly generating random binary trees:
Luka.hs: some routines for visualizing generalized Łukasiewicz paths:
*Luka> walkSVG' 1 "U2DU1DDU1DD"
*Luka> walkSVG' 1 "U1DU2DU1DDD"
*Luka> walkSVG' 0 "UUUD2UUD2UUUD2D2"
LukaTree.hs: visualizing trees as paths. (This uses routines for visualizing operadic trees from the LinLam library.)
Each tree is encoded as a Łukasiewicz path in four different ways, respectively via its preorder left-to-right, preorder right-to-left, postorder left-to-right, and postorder right-to-left traversals.
> t = bin (bin (bin zer (bin zer zer)) zer) (bin (bin (bin zer zer) zer) (bin zer zer))
> renderPretty "binwalk.svg" (mkWidth 2048) (treeWalksDiagram t)
> t = ter (bin zer zer) (ter zer zer (bin zer zer)) zer
> renderPretty "terwalk.svg" (mkWidth 1024) (treeWalksDiagram t)
> renderPretty "allbin3walk.svg" (mkWidth 1024) (vsep 1 [treeWalksDiagram t | t <- kTree 2 3])
We can also consider the reverse translation from walks to trees. Here we interpret a walk not touching the x-axis as a tree with free leaves, respectively via its preorder left-to-right and preorder right-to-left traversals:
> w = readWalk "U1U1U1D1U1D1D1U1U1D1"
> renderPretty "walk2tree.svg" (mkWidth 1024) (hsep 1 [gridWalk 1 w # centerXY, treeDiagram (unpreLR w) # centerXY, treeDiagram (unpreRL w) # centerXY] # pad 1.1)