Skip to content

Instantly share code, notes, and snippets.

@chakravala
Last active October 22, 2017 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakravala/fbc1b1a34adaeb7fdac93b3d488c57a4 to your computer and use it in GitHub Desktop.
Save chakravala/fbc1b1a34adaeb7fdac93b3d488c57a4 to your computer and use it in GitHub Desktop.
Visualize dendriform grove sum commutativity using Tamari associahedron
using Dendriform, LightGraphs, GraphPlot, Colors
function highlight_sum(a::Grove,b::Grove)
d = a.degr + b.degr
g = DiGraph(Int(Cn(d)))
for i = 1:Int(Cn(d))
u = Dendriform.posetnext(PBTree(d,i))
for t in u
add_edge!(g,i,treeindex(t))
end
end
sum1 = a + b
sum2 = b + a
col = ones(Int,Cn(d))
for i ∈ 1:sum1.size
col[treeindex(sum1.Y[i,:])] += 1
end
for i ∈ 1:sum2.size
col[treeindex(sum2.Y[i,:])] += 2
end
nodecolor = [colorant"grey77", colorant"orange", colorant"lightseagreen", colorant"salmon"]
gplot(g,nodelabel=[1:Int(Cn(d))...],nodefillc=nodecolor[col])
end
function highlight_sum(a::Dendriform.NotGrove,b::Dendriform.NotGrove)
highlight_sum(convert(Grove,a),convert(Grove,b))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment