PartiallyOrderedSets
DrawGraph
displays the directed graph associated with a poset
Calling Sequence
Parameters
Options
Description
Layout algorithms
Examples
References
Compatibility
DrawGraph(P)
DrawGraph(P,dopts,dgopts)
P
-
PartiallyOrderedSet
dopts
(optional) zero or more options specific to the Draw command, of the form prefer=l, reduction=b, where l is low or high, and b is a boolean
dgopts
(optional) zero or more options to be passed to the GraphTheory:-DrawGraph command
reduction = truefalse
There are two (potentially) different graphs that this command can generate: the graph where the arrows form the transitive reduction of the ordering of P, and the graph where the arrows form the transitive closure of the ordering. By default, DrawGraph displays the transitive reduction graph (the Hasse diagram). When passed the option reduction = false, it displays the transitive closure graph. Passing the option reduction or reduction = true explicitly selects the default transitive reduction graph.
graded = truefalse
When laying out the vertices of a transitive reduction graph, Maple chooses between two different but similar algorithms; one applicable only to graded posets and a more general algorithm applicable to all posets. Both are described below. By default, Maple determines if the poset is graded if this is not known already, and then chooses the algorithm for graded posets if applicable and the general algorithm otherwise; except if the option prefer = high is used, then the general algorithm is used.
When passing the option graded = false, Maple will bypass this check and always use the algorithm appropriate for all posets.
The option graded = true explicitly selects the algorithm appropriate only for graded posets. If the poset is not graded, this option is ignored.
The graded option is not supported for drawing the transitive closure graph.
prefer = low or high
When using the algorithm appropriate for non-graded posets, the vertices are divided into groups, each group being placed at the same height. Some vertices have a fixed height, whereas for others, there are several possibilities. With the option prefer = low (the default), each vertex gets placed into the lowest group available to it. With the option prefer = high, each vertex gets placed into the highest group available to it.
This option is not supported for drawing the transitive closure graph and it is ignored by the algorithm for drawing graded posets. If the algorithm appropriate for non-graded posets is used to draw a graded poset, this option has no effect.
dgopts (not a literal option name)
If passing any extra options not mentioned before (represented by dgopts in the calling sequence above), they are passed on to the GraphTheory:-DrawGraph command.
The command DrawGraph(P) displays the vertices and edges of the partially ordered set P as the Maple plot of a graph using the command GraphTheory:-DrawGraph of the package GraphTheory.
Terminology
A partially ordered set, or poset for short, is a pair (P, <=) where P is a set and <= is a partial order on P. The poset (P, <=) defines a directed graph whose vertices are the elements of P and (a,b) is a directed edge whenever a <= b holds. Conversely, a poset can be defined from a directed graph, assuming that the defined binary relation is anti-symmetric, and transitive, and, either reflexive, or irreflexive.
From now on, we fix a poset (P, <=)
The element a of P is strictly less than the element b of P if a <= b and a \342\211\240 b both hold.
The element b of P covers the element a of P if a is strictly less than b and for no element c of P, distinct from both a and b, both a <= c and c <= b hold.
The relation b covers a defines a homogeneous binary relation on P which is the transitive reduction of (P, <=). This is also a directed acyclic graph on P often refers as the Hasse diagram of (P, <=).
In this section, we describe the algorithms for layout out the vertices of transitive reduction graphs. As described in the "Options" section, there are two algorithms: one appropriate for graded posets only, and one applicable more generally. We first describe the algorithm for graded posets:
First, the rank of all elements is determined (that is, their value under a rank function), which also determines the split of the elements into connected components. The rank determines the y-coordinate at which a vertex is placed; concretely, the y-coordinates of a vertex corresponding to an element of rank r, in a poset of rank n, is 2⁢rn+1.
To determine the x-coordinate, we proceed connected component by connected component (in arbitrary order), as follows.
First, order the elements of minimal rank in this component arbitrarily. If there are k elements of this rank, place them spaced equidistantly between 1−kk and k−1k.
Then we iterate over the ranks in ascending order. For each rank, order the elements by the average horizontal position of their immediate predecessors, using the same rule for spacing.
Finally, re-order the minimal rank entries by the average horizontal position of their successors.
If there are fewer than two connected components, we use these x-coordinates directly. Otherwise, we shift each connected component horizontally so that the first connected component has 0 as its left hand bound, and the space between each pair of subsequent connected components is one third of the maximal width of one connected component.
Note that Maple's algorithm for computing ranks sets the rank of the lowest-ranked elements of each connected component of the poset to 0. This can be seen if a poset has two connected components, each of which is ranked, but they have different rank: then this algorithm lays out the components so that their lowest-ranked elements align horizontally.
The more general algorithm proceeds as follows.
We compute all maximal chains and group these by the pair of their minimal and maximal elements. Let S be the set that consists of those chains within each such group of maximal cardinality within that group. For now, we consider only the covering relations within S; we call these the skeleton of the poset. We will find "ranks" for the elements of the chains in S in a straightforward manner, below. Note that some vertices may not be in any of these chains; we will find appropriate ranks for them later. Note furthermore that the elements of the chains in S in a single connected component, are still connected if we only consider the covering relations in S.
We now compute "ranks" for all elements of the chains in S, as follows. We initially color all these elements black. We pick one arbitrarily and set its "rank" to 0, coloring it gray. We then iteratively pick one gray element, color it white, and color its neighbors (both greater and smaller) gray, assigning their "ranks" as we do so. When we have no more gray elements, we have finished this connected component and we can again pick an arbitrary black element if any are left. After we are done with a connected component, we subtract either its minimal (if the prefer = low option is used) or its maximal (if the prefer = high option is used; the default is prefer = low) "rank" from all "ranks" in that component. As a consequence, with prefer = low, the lowest-ranked elements of each connected component will have the same "rank" (0), and with prefer = high, the highest-ranked elements of each connected component will have the same "rank" (0). During this step, we keep track of which of the elements in the chains in S are in which connected component.
Next, we assign "ranks" to the remaining elements of the poset and add them to the correct connected component.
If the prefer = low option is used, we iterate through these elements in an order that is compatible with the partial ordering. When processing an element e, we look at all its immediate predecessors in the partial ordering. There must be some, because otherwise e would be part of a chain in S; and its connected component and "rank" will have been assigned, either when assigning ranks for S or earlier in this loop. We put this element in the same connected component as its predecessors and assign it the maximum of the "ranks" of the predecessors, plus one.
If the prefer = high option is used, we do the same, except we iterate through these elements in the reverse of this order, look at the element's immediate successors rather than predecessors, and assign the minimum of the "ranks" of the successors, minus one.
Once these "ranks" have been assigned, we proceed exactly as in the algorithm for graded posets, except using the newly computed "ranks" instead of the actual ranks of the elements.
with⁡PartiallyOrderedSets:
leq≔`<=`:
Create a poset from a set and a non-strict partial order
S≔1,2,3,4,5:poset1≔PartiallyOrderedSet⁡S,leq
poset1≔< a poset with 5 elements >
Display this poset
DrawGraph⁡poset1
Create a poset from a set and a strict partial order
lneq≔`<`:poset1_1≔PartiallyOrderedSet⁡S,lneq
poset1_1≔< a poset with 5 elements >
DrawGraph⁡poset1_1
divisibility≔x,y↦irem⁡y,x=0:T≔3,4,5,6,7,8,9:
poset2≔PartiallyOrderedSet⁡T,divisibility
poset2≔< a poset with 7 elements >
DrawGraph⁡poset2
divisibNE≔x,y↦irem⁡y,x=0andy≠x:
poset2_1≔PartiallyOrderedSet⁡T,divisibNE,reflexive=checkfalse
poset2_1≔< a poset with 7 elements >
DrawGraph⁡poset2_1
U≔1,2,3:
poset3≔PartiallyOrderedSet⁡U,leq,reflexive=checktrue
poset3≔< a poset with 3 elements >
DrawGraph⁡poset3
poset3_1≔PartiallyOrderedSet⁡U,lneq,reflexive=useclosure
poset3_1≔< a poset with 3 elements >
DrawGraph⁡poset3_1
X≔4,5,6:poset3_2≔PartiallyOrderedSet⁡X,leq,reflexive=checktrue
poset3_2≔< a poset with 3 elements >
DrawGraph⁡poset3_2
Create a poset from a set and an adjacency matrix of a partial order regarded as a directed graph
adjMatrix4≔Matrix⁡1,1,1,1,1,0,1,1,1,1,0,0,1,1,1,0,0,0,1,1,0,0,0,0,1
adjMatrix4≔1111101111001110001100001
poset4≔PartiallyOrderedSet⁡convert⁡S,list,adjMatrix4
poset4≔< a poset with 5 elements >
DrawGraph⁡poset4
Create a poset from a set and an adjacency list of a partial order regarded as a directed graph
adjList5≔map2⁡map,`+`,Array⁡1,4,7,2,6,3,4,5,6,7,2
adjList5≔3,6,94,856789
poset5≔PartiallyOrderedSet⁡convert⁡T,list,adjList5
poset5≔< a poset with 7 elements >
DrawGraph⁡poset5
Create a poset from a set and a directed graph
G≔GraphTheory:-Graph⁡directed,1,2,3,4,5,6,1,1,1,2,1,3,1,4,1,5,1,6,2,2,2,4,2,6,3,3,3,5,3,6,4,4,4,6,5,5,5,6,6,6
G≔Graph 1: a directed graph with 6 vertices, 11 arcs, and 6 self-loops
poset6≔PartiallyOrderedSet⁡G
poset6≔< a poset with 6 elements >
DrawGraph⁡poset6
Create a poset from a set an adjacency matrix of the transitive reduction of a partial order on that set
poset7≔PartiallyOrderedSet⁡convert⁡U,list,1|1|0,0|1|1,0|0|1,input=transitivereduction
poset7≔< a poset with 3 elements >
DrawGraph⁡poset7
Create a poset from a set and an adjacency list of the transitive reduction of a partial order on that set
poset8≔PartiallyOrderedSet⁡1,2,3,4,5,6,Array⁡1,2,3,2,4,3,5,4,6,5,6,6,input=transitivereduction
poset8≔< a poset with 6 elements >
DrawGraph⁡poset8
Define a polyhedral set and get its dimension
t≔PolyhedralSets:-ExampleSets:-Octahedron⁡
t≔{Coordinates:x1,x2,x3Relations:−x1−x2−x3≤1,−x1−x2+x3≤1,−x1+x2−x3≤1,−x1+x2+x3≤1,x1−x2−x3≤1,x1−x2+x3≤1,x1+x2−x3≤1,x1+x2+x3≤1
d≔PolyhedralSets:-Dimension⁡t
d≔3
Collect the faces of this polyhedral set
t_faces≔seq⁡op⁡PolyhedralSets:-Faces⁡t,dimension=i,i=−0..d:
t_faces≔t_facesunionPolyhedralSets:-ExampleSets:-EmptySet⁡d:
FL≔convert⁡t_faces,list:
Construct the face lattice of that polyhedral set
inclusion := proc(x,y) PolyhedralSets:-`subset`(FL[x],FL[y]) end proc:
polyhedral_poset≔PartiallyOrderedSet⁡seq⁡i,i=1..nops⁡FL,inclusion
polyhedral_poset≔< a poset with 28 elements >
DrawGraph⁡polyhedral_poset
M≔Matrix⁡1,1,1,1,1,0,1,1,0,1,0,0,1,0,1,0,0,0,1,1,0,0,0,0,1:
poset9≔PartiallyOrderedSet⁡seq⁡1..5,M
poset9≔< a poset with 5 elements >
DrawGraph⁡poset9
Z≔1,2,3,4,5,6,10,12,15,20,30,60
poset10≔PartiallyOrderedSet⁡Z,divisibility
poset10≔< a poset with 12 elements >
Display the transitive reduction of this poset
DrawGraph⁡poset10,reduction=true
Display the transitive closure of this poset
DrawGraph⁡poset10,reduction=false
Display the transitive closure of this poset, passing extra options to GraphTheory:-DrawGraph
DrawGraph⁡poset10,reduction=false,showlabels=false
ZZ≔1,2,3,4,5,6,12,15,60
poset11≔PartiallyOrderedSet⁡ZZ,divisibility
poset11≔< a poset with 9 elements >
Display this poset using horizontal positions calculated by predecessor maximums
DrawGraph⁡poset11,prefer=low
Display this poset using horizontal positions calculated by sucessor minimums
DrawGraph⁡poset11,prefer=high
Display this poset using horizontal positions calculated by predecessor maximums, passing extra options to GraphTheory:-DrawGraph
DrawGraph⁡poset11,caption=Poset11,size=200,200
Richard P. Stanley: Enumerative Combinatorics 1. 1997, Cambridge Studies in Advanced Mathematics. Vol. 49. Cambridge University Press.
The PartiallyOrderedSets[DrawGraph] command was introduced in Maple 2025.
For more information on Maple 2025 changes, see Updates in Maple 2025.
See Also
PartiallyOrderedSets[ToGraph]
PartiallyOrderedSets[TransitiveClosure]
PartiallyOrderedSets[TransitiveReduction]
GraphTheory[DrawGraph]
Download Help Document