2 | module Control.Relation.ReflexiveClosure
4 | import public Control.Order
5 | import public Control.Relation
16 | data ReflexiveClosure : (rel : a -> a -> Type) -> (x,y : a) -> Type where
17 | Rel : {0 rel : _} -> (0 prf : rel x y) -> ReflexiveClosure rel x y
18 | Refl : {0 rel : _} -> ReflexiveClosure rel x x
21 | Reflexive a (ReflexiveClosure rel) where
25 | Transitive a rel => Transitive a (ReflexiveClosure rel) where
26 | transitive (Rel x) (Rel y) = Rel $
transitive x y
27 | transitive (Rel x) Refl = Rel x
28 | transitive Refl y = y
31 | fromEq : {0 rel : _} -> (0 p : x === y) -> ReflexiveClosure rel x y
39 | 0 strictLeft : Transitive a rel => rel x y -> ReflexiveClosure rel y z -> rel x z
40 | strictLeft w (Rel prf) = transitive w prf
41 | strictLeft w Refl = w
44 | 0 strictRight : Transitive a rel => ReflexiveClosure rel x y -> rel y z -> rel x z
45 | strictRight (Rel prf) w = transitive prf w
46 | strictRight Refl w = w
54 | data Chain : (rel : a -> a -> Type) -> (x,y : a) -> Type where
55 | Nil : {0 rel : a -> a -> Type} -> Chain rel x x
57 | {0 rel : a -> a -> Type}
59 | -> (c : Chain rel y z)
60 | -> {auto 0 p : ReflexiveClosure rel x y}
74 | data IsStrict : {rel : _} -> Chain rel x y -> Type where
75 | Here : IsStrict ((::) x c @{Rel p})
76 | There : IsStrict c -> IsStrict ((::) x c @{p})
81 | 0 chain : Preorder a rel => Chain rel x y -> rel x y
82 | chain [] = reflexive
83 | chain ((::) _ c @{Rel x}) = transitive x (chain c)
84 | chain ((::) _ c @{Refl}) = chain c
89 | 0 weak : Transitive a rel => Chain rel x y -> ReflexiveClosure rel x y
91 | weak ((::) _ c @{p}) = transitive p $
weak c
98 | {auto _ : Transitive a rel}
99 | -> (c : Chain rel x y)
100 | -> {auto p : IsStrict c}
102 | strict ((::) _ c @{Rel q}) {p = Here} = strictLeft q $
weak c
103 | strict ((::) _ c @{Rel q}) {p = There _} = transitive q $
strict c
104 | strict ((::) _ c @{Refl}) {p = There _} = strict c