Skip to content

noamz/diagrams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fun with diagrams

Various bits of visualization code based on the diagrams library.

RemyVis

RemyVis.hs: generates an animation of Remy's algorithm for uniformly generating random binary trees:

Remy's algorithm animation

Luka

Luka.hs: some routines for visualizing generalized Łukasiewicz paths:

*Luka> walkSVG' 1 "U2DU1DDU1DD"

U2DU1DDU1DD

*Luka> walkSVG' 1 "U1DU2DU1DDD"

U1DU2DU1DDD

*Luka> walkSVG' 0 "UUUD2UUD2UUUD2D2"

UUUD2UUD2UUUD2D2

LukaTree

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)

binwalk

> t = ter (bin zer zer) (ter zer zer (bin zer zer)) zer
> renderPretty "terwalk.svg" (mkWidth 1024) (treeWalksDiagram t)

terwalk

> renderPretty "allbin3walk.svg" (mkWidth 1024) (vsep 1 [treeWalksDiagram t | t <- kTree 2 3])

allbin3walk

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)

allbin3walk

About

Visualization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published