Skip to content

Instantly share code, notes, and snippets.

@Eckankar
Created October 26, 2011 09:29
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Eckankar/1315879 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