Breaking change in 0.2.0: The function stack is replaced by vcat.
This module defines a SimplePoset type for Julia. A poset is a
pair (X,<) where X is a set of elements and < is a relation on
X that is irreflexive, antisymmetric, and transitive.
Use SimplePoset(T) to create a new SimplePoset with elements
having type T (which defaults to Any).
Elements and relations can be added to or deleted from a poset using these functions:
add!(P,x)adds a new elementxto the ground set ofP.add!(P,x,y)inserts the relationx<yintoP. If one (or both) ofxandyis not inP, it is added as well.delete!(P,x)deletes elementxfrom this poset.delete!(P,x,y)delete the relationx<yfromPand for anyzwithx < z < y, also deletex<zandz<y.
More detail on element/relation addition/deletion can be found in the
document addition-deletion.pdf found in the doc folder.
elements(P)returns a list of the elements inPcard(P)returns the cardinality ofP(number of elements).relations(P)returns a list of all pairs(x,y)withx<yin this poset.incomparables(P)returns a list of all incomparable pairs. If(x,y)is listed, we do not also list(y,x).has(P,x)determine ifxis an element ofP.has(P,x,y)determine ifx<yin the posetP. Note: Callinghas(P,x,x)for an elementxof this poset returnsfalse. All our methods concern the strict relation<.above(P,x)returns a list of all elements abovexinP.below(P,x)returns a list of all elements belowxinP.interval(P,x,y)returns a list of all elementszthat satisfyx<z<y.maximals(P)returns a list of the maximal elements ofP.minimals(P)returns a list of the minimal elements ofP.components(P)returns the ground sets of the connected components ofPas aPartition.is_connected(P)determines if (the comparability graph of) the poset is connected.
The following functions are not likely to be called by the casual user.
-
check(P)returnstrueprovided the internal data structures ofPare valid andfalseotherwise. Note: There should be no reason to use this function if the poset is created and manipulated by the functions provided in this module. -
hash(P)computes a hash value for the poset. This enablesSimplePosetobjects to serve as keys in dictionaries, and so forth. -
eltype(P)returns the datatype of the elements in this poset. For example:julia> P = BooleanLattice(3); julia> eltype(P) String
Antichain(n)creates an antichain with elements1:n. The functionIntPoset(n)is a synonym.Antichain(list)creates an antichain with elements drawn fromlist, a one-dimensional array.BooleanLattice(n)creates the subsets of ann-set poset in which elements are named asn-long binary strings.Chain(n)creates a chain with elements1:nin which1<2<3<...<n.Chain(list)creates a chain with elements drawn fromlist(in that order) in.Divisors(n)creates the poset whose elements are the divisors ofnordered by divisibility.PartitionLattice(n)creates the poset whose elements are the partitions of{1,2,...,n}ordered by refinement.RandomPoset(n,d)creates a randomd-dimensional poset onnelements.SimplePoset(G::SimpleGraph)creates the vertex-edge poset ofG.StandardExample(n)creates the canonicaln-dimensional poset with2nelements in two layers. The lower layer elements are named from-1to-nand the upper layer from1ton. We have-i<jexactly wheni!=j.
-
inv(P)creates the inverse poset ofP, i.e., we havex<yinPiff we havey<xininv(P). We can useP'as a synonym forinv(P). -
intersect(P,Q)creates the intersection of the two posets (which must be of the same element type). Typically the two posets have the same elements, but this is not necessary. The resulting poset's elements is the intersection of the two element sets, and relations in the result are those relations common to bothPandQ. -
induce(P,A)forms the induced subposet ofPusing the elements in the setA. -
P*Qis the Cartesian product of the two posets (that may be of different types). -
P+Q(orhcat(P,Q))is the disjoint union of two (or more) posets. The posets must all be of the same type. Each summand's elements is extended with an integer (starting at 1) corresponding to its position in the sum. That is, ifxis an element of summand numberi, then in the sum it becomes the element(x,i). For example:julia> P = Chain(2)+Chain(3)+Chain(4) SimplePoset{(Int64,Int64)} (9 elements) julia> elements(P) 9-element Array{(Int64,Int64),1}: (1,1) (1,2) (1,3) (2,1) (2,2) (2,3) (3,2) (3,3) (4,3)
-
vcat(Plist...)creates a new poset from the ones in the argument list by stacking one atop the next. The first poset in the list is at the bottom. Element labeling is as in+. Note thatP/Qis equivalent tovcat(Q,P)andP\Qis equivalent tovcat(P,Q). -
relabel(P,labels)is used to create a new poset in which the elements have new names (as given by the dictionarylabels). Callingrelabel(P)gives a new poset in which the new element names are the integers1throughn. Here's an example:julia> P = Chain(3) + Chain(3) SimplePoset{(Int64,Int64)} (6 elements) julia> elements(P) 6-element Array{(Int64,Int64),1}: (1,1) (1,2) (2,1) (2,2) (3,1) (3,2) julia> Q = relabel(P) SimplePoset{Int64} (6 elements) julia> elements(Q) 6-element Array{Int64,1}: 1 2 3 4 5 6
ComparabilityGraph(P)returns aSimpleGraphwhose vertices are the elements ofPand in which two distinct vertices are adjacent iff they are comparable inP.CoverDigraph(P)returns a directed graph whose vertices are the elements ofPin which(x,y)is an edges provided bothx<yinPand there is nozfor whichx<z<y. These are the edges that would appear in a Hasse diagram ofP.mobius(P)creates the Mobius function for this poset (as a dictionary from pairs of elements toIntvalues).mobius_matrix(P)is the inverse ofzeta_matrix(P).zeta(P)creates the zeta function for this poset (as a dictionary from pairs of elements toIntvalues). We have(x,y) ==> 1providedx==yorx<y, and(x,y) ==> 0otherwise.zeta_matrix(P)produces the zeta matrix. Order of elements is the same as produced byelements(P).height(P)returns the maximum size of a chain.
linear_extension(P)finds one linear extension of the poset (as anArray).random_linear_extension(P)returns a random linear extension. See the help message for more detail.all_linear_extensions(P)returns aSetcontaining all the linear extensions of the poset. This is a very expensive operation in both time and memory. It is memoized to make it more efficient, but the memory it uses is not freed after use.
julia> P = Divisors(12)
SimplePoset{Int64} (6 elements)
julia> linear_extension(P)'
1×6 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}:
1 2 3 4 6 12
julia> random_linear_extension(P)'
1×6 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}:
1 3 2 6 4 12
julia> collect(all_linear_extensions(P))
5-element Array{Array{Int64,1},1}:
[1, 3, 2, 4, 6, 12]
[1, 3, 2, 6, 4, 12]
[1, 2, 3, 6, 4, 12]
[1, 2, 3, 4, 6, 12]
[1, 2, 4, 3, 6, 12]
A SimplePoset is a wrapper around a DirectedGraph object. The
functions for creating and manipulating a SimplePoset ensure that
the underlying digraph has directed edges (x,y) exactly for those
pairs of elements with x<y.