Skip to content

Commit

Permalink
Add subset_lattice
Browse files Browse the repository at this point in the history
  • Loading branch information
scheinerman committed Aug 6, 2024
1 parent da878c5 commit 8ed47e8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ different from `standard_example(3)`.
random order.
* `random_poset(n,d=2)`: Create a random `d`-dimensional poset by intersecting `d` random linear orders,
each with `n` elements.
* `subset_lattice(d)`: Create the poset corresponding to the `2^d` subsets of `{1,2,...,d}` ordered by
inclusion. For `a` between `1` and `2^d`, element `a` corresponds to a subset of `{1,2,...,d}` as follows: Write `a-1` in binary and view the bits as the characteristic vector indicating the members of the set. For example, if `a` equals `12`, then `a-1` is `1011` in binary. Reading off the digits from the right, this gives the set `{1,2,4}`.



Expand Down
11 changes: 9 additions & 2 deletions extras/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ Function provided:
`v < w` and `w` covers `v`. Use `pplot(p, nodelable=1:nv(p))` to have the nodes labeled.


## `interval_orders.jl`
## `interval-orders.jl`

* `semiorder(xs)` creates a semiorder. Here `xs` is a list of `n` real numbers.
The result is a poset with `n` elements in which `i<j` when `x[i] ≤ x[j] - 1`.
More generally, use `semiorder(xs,t)` in which case `i<j` when `x[i] ≤ x[j] - t`.
Setting `t=0` gives a total order (if the values in `xs` are distinct).
If `t` is negative, errors may be thrown.
If `t` is negative, errors may be thrown.

* `interval_order(JJ)` creates an interval order. Here `JJ` is a vector of
`ClosedInterval`s. In this poset we have `a < b` provided `JJ[a]` lies entirely
to the left of `JJ[b]`.

* `random_interval_order(n)` creates a random interval order with `n` elements. This is done by
creating `n` random intervals and invoking `interval_order`.
34 changes: 33 additions & 1 deletion extras/interval-orders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Posets, Graphs, ClosedIntervals
Create a semi-order from a list of numbers. In this poset we have `a<b`
exactly when `values[a] ≤ values[b] - thresh`.
"""
function semiorder(values::Vector{T}, thresh=1) where {T<:Real}
function semiorder(values::Vector{T}, thresh=1)::Poset where {T<:Real}
n = length(values)
g = DiGraph(n)
for a in 1:n
Expand All @@ -19,4 +19,36 @@ function semiorder(values::Vector{T}, thresh=1) where {T<:Real}
return Poset(g)
end

"""
interval_order(JJ::Vector{ClosedInterval})
Create an interval order from a list of closed intervals. In this poset
we have `a < b` provided `JJ[a]` lies entirely to the left of `JJ[b]`.
"""
function interval_order(JJ::Vector{ClosedInterval{T}})::Poset where {T}
n = length(JJ)
g = DiGraph(n)

for a in 1:n
for b in 1:n
if JJ[a] << JJ[b]
add_edge!(g, a, b)
end
end
end

return Poset(g)
end

"""
random_interval_order(n::Integer)
Create a random interval order. To do this, we generate `n`
random intervals joining pairs of iid uniform [0,1] random variables.
"""
function random_interval_order(n::Integer)
JJ = [ClosedInterval(rand(), rand()) for _ in 1:n]
return interval_order(JJ)
end

nothing
1 change: 1 addition & 0 deletions src/Posets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export Poset,
src,
src,
standard_example,
subset_lattice,
vertex_edge_incidence_poset,
width,
zeta_matrix
Expand Down
22 changes: 22 additions & 0 deletions src/standard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,25 @@ function chevron()

return p
end

"""
subset_lattice(d::Integer)
Create the poset corresponding to the subsets of a `d`-element set
ordered by inclusion.
"""
function subset_lattice(d::Integer)::Poset
codes = collect(UInt64(0):(UInt64(1) << d - 1))
n = length(codes)
g = DiGraph(n)

for a in 1:n
for b in 1:n
if codes[a] & codes[b] == codes[a]
add_edge!(g, a, b)
end
end
end

return Poset(g)
end

0 comments on commit 8ed47e8

Please sign in to comment.