| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Symmetric interior of a binary relation |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Relation.Binary.Construct.Interior.Symmetric where |
| 10 |
|
| 11 |
open import Data.Bool.Base using (_∧_) |
| 12 |
open import Function.Base using (flip; _∘_) |
| 13 |
open import Level using (Level) |
| 14 |
open import Relation.Binary.Core using (Rel; _⇒_) |
| 15 |
open import Relation.Binary.Definitions |
| 16 |
using (Reflexive; Symmetric; Transitive; Trans; Asymmetric; Empty; Decidable) |
| 17 |
open import Relation.Binary.Structures |
| 18 |
using (IsEquivalence; IsPreorder; IsPartialOrder; IsDecPartialOrder |
| 19 |
; IsDecEquivalence) |
| 20 |
open import Relation.Binary.Bundles using (Poset; DecPoset) |
| 21 |
open import Relation.Nullary.Decidable.Core |
| 22 |
open import Relation.Nullary.Reflects |
| 23 |
|
| 24 |
private |
| 25 |
variable |
| 26 |
a ℓ : Level |
| 27 |
A : Set a |
| 28 |
R S T : Rel A ℓ |
| 29 |
|
| 30 |
------------------------------------------------------------------------ |
| 31 |
-- Definition |
| 32 |
|
| 33 |
infixr 4 _,_ |
| 34 |
|
| 35 |
record SymInterior (R : Rel A ℓ) (x y : A) : Set ℓ where |
| 36 |
constructor _,_ |
| 37 |
field |
| 38 |
lhs≤rhs : R x y |
| 39 |
rhs≤lhs : R y x |
| 40 |
|
| 41 |
open SymInterior public |
| 42 |
|
| 43 |
------------------------------------------------------------------------ |
| 44 |
-- Properties |
| 45 |
|
| 46 |
-- The symmetric interior is symmetric. |
| 47 |
symmetric : Symmetric (SymInterior R) |
| 48 |
symmetric (r , r′) = r′ , r |
| 49 |
|
| 50 |
-- The symmetric interior of R is greater than (or equal to) any other symmetric |
| 51 |
-- relation contained by R. |
| 52 |
unfold : Symmetric S → S ⇒ R → S ⇒ SymInterior R |
| 53 |
unfold sym f s = f s , f (sym s) |
| 54 |
|
| 55 |
-- SymInterior preserves various properties. |
| 56 |
reflexive : Reflexive R → Reflexive (SymInterior R) |
| 57 |
reflexive refl = refl , refl |
| 58 |
|
| 59 |
trans : Trans R S T → Trans S R T → |
| 60 |
Trans (SymInterior R) (SymInterior S) (SymInterior T) |
| 61 |
trans trans-rs trans-sr (r , r′) (s , s′) = trans-rs r s , trans-sr s′ r′ |
| 62 |
|
| 63 |
transitive : Transitive R → Transitive (SymInterior R) |
| 64 |
transitive tr = trans tr tr |
| 65 |
|
| 66 |
-- The symmetric interior of a strict relation is empty. |
| 67 |
asymmetric⇒empty : Asymmetric R → Empty (SymInterior R) |
| 68 |
asymmetric⇒empty asym (r , r′) = asym r r′ |
| 69 |
|
| 70 |
-- Decidability |
| 71 |
decidable : Decidable R → Decidable (SymInterior R) |
| 72 |
does (decidable R? x y) = does (R? x y) ∧ does (R? y x) |
| 73 |
proof (decidable R? x y) = proof (R? x y) reflects proof (R? y x) |
| 74 |
where |
| 75 |
_reflects_ : ∀ {bxy byx} → Reflects (R x y) bxy → Reflects (R y x) byx → |
| 76 |
Reflects (SymInterior R x y) (bxy ∧ byx) |
| 77 |
ofʸ rxy reflects ofʸ ryx = of (rxy , ryx) |
| 78 |
ofʸ rxy reflects ofⁿ ¬ryx = of (¬ryx ∘ rhs≤lhs) |
| 79 |
ofⁿ ¬rxy reflects _ = of (¬rxy ∘ lhs≤rhs) |
| 80 |
|
| 81 |
-- A reflexive transitive relation _≤_ gives rise to a poset in which the |
| 82 |
-- equivalence relation is SymInterior _≤_. |
| 83 |
|
| 84 |
module _ {R : Rel A ℓ} (refl : Reflexive R) (trans : Transitive R) where |
| 85 |
|
| 86 |
isEquivalence : IsEquivalence (SymInterior R) |
| 87 |
isEquivalence = record |
| 88 |
{ refl = reflexive refl |
| 89 |
; sym = symmetric |
| 90 |
; trans = transitive trans |
| 91 |
} |
| 92 |
|
| 93 |
isPreorder : IsPreorder (SymInterior R) R |
| 94 |
isPreorder = record |
| 95 |
{ isEquivalence = isEquivalence |
| 96 |
; reflexive = lhs≤rhs |
| 97 |
; trans = trans |
| 98 |
} |
| 99 |
|
| 100 |
isPartialOrder : IsPartialOrder (SymInterior R) R |
| 101 |
isPartialOrder = record |
| 102 |
{ isPreorder = isPreorder |
| 103 |
; antisym = _,_ |
| 104 |
} |
| 105 |
|
| 106 |
poset : Poset _ ℓ ℓ |
| 107 |
poset = record { isPartialOrder = isPartialOrder } |
| 108 |
|
| 109 |
module _ (R? : Decidable R) where |
| 110 |
|
| 111 |
isDecPartialOrder : IsDecPartialOrder (SymInterior R) R |
| 112 |
isDecPartialOrder = record |
| 113 |
{ isPartialOrder = isPartialOrder |
| 114 |
; _≟_ = decidable R? |
| 115 |
; _≤?_ = R? |
| 116 |
} |
| 117 |
|
| 118 |
decPoset : DecPoset _ ℓ ℓ |
| 119 |
decPoset = record { isDecPartialOrder = isDecPartialOrder } |
| 120 |
|
| 121 |
open DecPoset public |
| 122 |
using (isDecPreorder; decPreorder) |
| 123 |
|
| 124 |
isDecEquivalence : IsDecEquivalence (SymInterior R) |
| 125 |
isDecEquivalence = DecPoset.Eq.isDecEquivalence decPoset |
| 126 |
|