Skip to content

Instantly share code, notes, and snippets.

@dorman99
Forked from Eckankar/hasse.nb
Created January 20, 2019 14:33
Show Gist options
  • Save dorman99/bbb624e7cfb9be0552cc486e75b1458c to your computer and use it in GitHub Desktop.
Save dorman99/bbb624e7cfb9be0552cc486e75b1458c to your computer and use it in GitHub Desktop.
Generating Hasse diagrams in Mathematica
(* Combinatorica contains HasseDiagram,so we need to load it. *)
<<Combinatorica`;
(* 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}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment