Hasse diagram of a partial order in Mathematica
Posted on 26th October 2011 by SebastianIt’s that time of year again; the new students have started at DIKU and start their careers as computer science students with the course DiMS — Discrete Mathematical Structures, taught from the book by the same name.
Part of the curriculum is learning about Hasse diagrams, which in essence are a way of easily visualizing the relationships between different elements under a partial order.
Now, a student came and asked me about how to draw these diagrams in Mathematica, so I got some code working which did just that. The resulting diagram, is the picture used for this post.
In the spirit of sharing, here is the Mathematica-code I used to generate this picture:
(* Combinatorica contains HasseDiagram,so we need to load it. *)<< Combinatorica`
General::compat: Combinatorica Graph and Permutations functionality has been superseded by preloaded functionaliy. The package now being loaded may conflict with this. Please see the Compatibility Guide for details.
(* The set the partial order operates on. *)nums = {1, 2, 4, 7, 8, 14, 30};
(* Define our partial order. *)pOrder[x_, y_] := Divisible[y, x];
(* Generate a directed graph from the partial order. *)g = MakeGraph[nums, pOrder];
(* Now create our Hasse diagram *)h = HasseDiagram[g];
(* Finally, let's see the resulting graph. *)ShowGraph[h, VertexStyle -> PointSize[0.05], VertexLabel -> True, VertexLabelColor -> White, VertexLabelPosition -> {0.012, 0}]

