| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Union of two binary relations |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Relation.Binary.Construct.Union where |
| 10 |
|
| 11 |
open import Data.Product.Base using (_,_; _×_; map; zip; <_,_>) |
| 12 |
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_]) |
| 13 |
open import Function.Base using (_∘_) |
| 14 |
open import Level using (Level; _⊔_) |
| 15 |
open import Relation.Binary.Core using (REL; Rel; _⇒_) |
| 16 |
open import Relation.Binary.Definitions |
| 17 |
using (Reflexive; Total; Minimum; Maximum; Symmetric; Irreflexive; Decidable; _Respects_; _Respectsˡ_; _Respectsʳ_; _Respects₂_) |
| 18 |
open import Relation.Nullary.Decidable using (yes; no; _⊎-dec_) |
| 19 |
|
| 20 |
private |
| 21 |
variable |
| 22 |
a b ℓ ℓ₁ ℓ₂ ℓ₃ : Level |
| 23 |
A : Set a |
| 24 |
B : Set b |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- Definition |
| 28 |
|
| 29 |
infixr 6 _∪_ |
| 30 |
|
| 31 |
_∪_ : REL A B ℓ₁ → REL A B ℓ₂ → REL A B (ℓ₁ ⊔ ℓ₂) |
| 32 |
L ∪ R = λ i j → L i j ⊎ R i j |
| 33 |
|
| 34 |
------------------------------------------------------------------------ |
| 35 |
-- Properties |
| 36 |
|
| 37 |
module _ (L : Rel A ℓ) (R : Rel A ℓ) where |
| 38 |
|
| 39 |
reflexive : Reflexive L ⊎ Reflexive R → Reflexive (L ∪ R) |
| 40 |
reflexive (inj₁ L-refl) = inj₁ L-refl |
| 41 |
reflexive (inj₂ R-refl) = inj₂ R-refl |
| 42 |
|
| 43 |
total : Total L ⊎ Total R → Total (L ∪ R) |
| 44 |
total (inj₁ L-total) x y = [ inj₁ ∘ inj₁ , inj₂ ∘ inj₁ ] (L-total x y) |
| 45 |
total (inj₂ R-total) x y = [ inj₁ ∘ inj₂ , inj₂ ∘ inj₂ ] (R-total x y) |
| 46 |
|
| 47 |
min : ∀ {⊤} → Minimum L ⊤ ⊎ Minimum R ⊤ → Minimum (L ∪ R) ⊤ |
| 48 |
min = [ inj₁ ∘_ , inj₂ ∘_ ] |
| 49 |
|
| 50 |
max : ∀ {⊥} → Maximum L ⊥ ⊎ Maximum R ⊥ → Maximum (L ∪ R) ⊥ |
| 51 |
max = [ inj₁ ∘_ , inj₂ ∘_ ] |
| 52 |
|
| 53 |
module _ {L : Rel A ℓ} {R : Rel A ℓ} where |
| 54 |
|
| 55 |
symmetric : Symmetric L → Symmetric R → Symmetric (L ∪ R) |
| 56 |
symmetric L-sym R-sym = [ inj₁ ∘ L-sym , inj₂ ∘ R-sym ] |
| 57 |
|
| 58 |
respects : ∀ {p} {P : A → Set p} → |
| 59 |
P Respects L → P Respects R → P Respects (L ∪ R) |
| 60 |
respects resp-L resp-R = [ resp-L , resp-R ] |
| 61 |
|
| 62 |
module _ {≈ : Rel A ℓ₁} (L : REL A B ℓ₂) (R : REL A B ℓ₃) where |
| 63 |
|
| 64 |
respˡ : L Respectsˡ ≈ → R Respectsˡ ≈ → (L ∪ R) Respectsˡ ≈ |
| 65 |
respˡ Lˡ Rˡ x≈y = Sum.map (Lˡ x≈y) (Rˡ x≈y) |
| 66 |
|
| 67 |
module _ {≈ : Rel B ℓ₁} (L : REL A B ℓ₂) (R : REL A B ℓ₃) where |
| 68 |
|
| 69 |
respʳ : L Respectsʳ ≈ → R Respectsʳ ≈ → (L ∪ R) Respectsʳ ≈ |
| 70 |
respʳ Lʳ Rʳ x≈y = Sum.map (Lʳ x≈y) (Rʳ x≈y) |
| 71 |
|
| 72 |
module _ {≈ : Rel A ℓ₁} {L : Rel A ℓ₂} {R : Rel A ℓ₃} where |
| 73 |
|
| 74 |
resp₂ : L Respects₂ ≈ → R Respects₂ ≈ → (L ∪ R) Respects₂ ≈ |
| 75 |
resp₂ (Lʳ , Lˡ) (Rʳ , Rˡ) = respʳ L R Lʳ Rʳ , respˡ L R Lˡ Rˡ |
| 76 |
|
| 77 |
module _ (≈ : REL A B ℓ₁) (L : REL A B ℓ₂) (R : REL A B ℓ₃) where |
| 78 |
|
| 79 |
implies : (≈ ⇒ L) ⊎ (≈ ⇒ R) → ≈ ⇒ (L ∪ R) |
| 80 |
implies = [ inj₁ ∘_ , inj₂ ∘_ ] |
| 81 |
|
| 82 |
irreflexive : Irreflexive ≈ L → Irreflexive ≈ R → Irreflexive ≈ (L ∪ R) |
| 83 |
irreflexive L-irrefl R-irrefl x≈y = [ L-irrefl x≈y , R-irrefl x≈y ] |
| 84 |
|
| 85 |
module _ {L : REL A B ℓ₁} {R : REL A B ℓ₂} where |
| 86 |
|
| 87 |
decidable : Decidable L → Decidable R → Decidable (L ∪ R) |
| 88 |
decidable L? R? x y = L? x y ⊎-dec R? x y |