definition example

Given a Preorder , an upper set in is a Subset such that if and then : “if is an element then so is anything bigger”. Write for the set of upper sets, ordered by inclusion iff .

Sources: 7 Sketches Example 1.54, 1.64, Exercises 1.55, 1.57, 1.65, 1.66, 1.79, Proposition 1.78.

Example. For the Booleans, is ; is not an upper set since .

Upper sets are the preorder version of presheaves / co-presheaves valued in .

Docs: Vignette: preorders

# upper sets of a finite preorder given by a leq predicate on elements xs
is_upper(leq, xs, U) = all((p ∈ U && leq(p, q)) <= (q ∈ U) for p in xs, q in xs)
upper_sets(leq, xs) = [Set(U) for U in Iterators.map(collect, powerset(xs)) if is_upper(leq, xs, Set(U))]
principal_up(leq, xs, p) = Set(q for q in xs if leq(p, q))   # ↑p
# (powerset from Combinatorics.jl)
-- Mathlib: `UpperSet α` and `IsUpperSet`
#check @IsUpperSet          -- ∀ ⦃a b⦄, a ≤ b → a ∈ s → b ∈ s
#check (UpperSet ℕ)         -- bundled, a complete lattice
#check @UpperSet.Ici        -- the principal upper set ↑p = Set.Ici p
-- an upper set as a predicate closed upwards (law unenforced)
type UpperSet a = a -> Bool
 
principalUp :: Preorder a => a -> UpperSet a
principalUp p q = leq p q         -- ↑p
 
pullback :: (a -> b) -> UpperSet b -> UpperSet a
pullback f u = u . f              -- f^* U = f⁻¹(U)