definition example theorem

Level shifting (7 Sketches §1.4.5): for any Set there is a Preorder of all binary relations on , ordered by inclusion . There is also a set of all preorder relations on , itself a preorder under inclusion (iff implies ) — “a preorder of preorder structures: that’s what we mean by a level shift”.

Sources: 7 Sketches §1.4.5, Exercises 1.124, 1.125; CTfS Example 3.4.1.13, Exercise 3.4.1.14

Every preorder relation is a relation, giving an inclusion . This is the right adjoint of a Galois Connection whose left adjoint

takes a relation to its reflexive and transitive closure: add for every and whenever and . The adjunction says iff : a preorder contains the closure of exactly when it contains (7S Exercise 1.125). The composite is a Closure Operator on .

Example. has two elements ; has 16 (7S Exercise 1.124).

Computing it (CTfS Example 3.4.1.13): add the diagonal, then add whenever are present — and repeat until nothing changes; a single round of composition is not enough in general (for one round adds and but not ). Over a Quantale this iteration is the stabilizing matrix power of Matrix Multiplication in a Quantale. The preorder generated by ” is a child of ” is ” is a descendant of (or )“.

This is the preorder analogue of the Free Category on a Graph (the reflexive-transitive closure with named paths), of the Free Monoid, and of the Hasse Diagram construction: a graph presents the preorder .

Docs: Vignette: preorders

# reflexive transitive closure of a relation on {1..n} given as a BitMatrix (Warshall)
function refl_trans_closure(R::BitMatrix)
  n = size(R, 1); C = copy(R)
  for i in 1:n; C[i,i] = true; end
  for k in 1:n, i in 1:n, j in 1:n
    C[i,j] |= C[i,k] && C[k,j]
  end
  C
end
R = BitMatrix([0 1 0; 0 0 1; 0 0 0])
refl_trans_closure(R)      # the chain 1 ≤ 2 ≤ 3
#check @Relation.ReflTransGen      -- inductive reflexive-transitive closure
#check @Relation.ReflTransGen.mono
-- the adjunction: ReflTransGen r ≤ s ↔ r ≤ s for a preorder s (transitive & reflexive)
#check @Relation.reflTransGen_eq_self
-- closure of a finite relation (as a list of pairs) on a finite carrier
reflTransClosure :: Eq a => [a] -> [(a, a)] -> [(a, a)]
reflTransClosure xs r = fixpoint step (r ++ [(x, x) | x <- xs])
  where
    step s = foldr addNew s [ (a, c) | (a, b) <- s, (b', c) <- s, b == b' ]
    addNew p s = if p `elem` s then s else p : s
    fixpoint f s = let s' = f s in if length s' == length s then s else fixpoint f s'