| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Consequences of a monomorphism between binary relations |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- See Data.Nat.Binary.Properties for examples of how this and similar |
| 8 |
-- modules can be used to easily translate properties between types. |
| 9 |
|
| 10 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 11 |
|
| 12 |
open import Relation.Binary.Core using (Rel) |
| 13 |
open import Relation.Binary.Morphism using (IsRelMonomorphism) |
| 14 |
|
| 15 |
module Relation.Binary.Morphism.RelMonomorphism |
| 16 |
{a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} |
| 17 |
{_∼₁_ : Rel A ℓ₁} {_∼₂_ : Rel B ℓ₂} |
| 18 |
{⟦_⟧ : A → B} (isMonomorphism : IsRelMonomorphism _∼₁_ _∼₂_ ⟦_⟧) |
| 19 |
where |
| 20 |
|
| 21 |
open import Data.Sum.Base as Sum using (map) |
| 22 |
open import Function.Base using (flip; _∘_) |
| 23 |
open import Relation.Binary.Definitions |
| 24 |
using (Reflexive; Symmetric; Transitive; Total; Asymmetric; Decidable) |
| 25 |
open import Relation.Binary.Structures using (IsEquivalence; IsDecEquivalence) |
| 26 |
open import Relation.Nullary.Decidable.Core using (yes; no; map′) |
| 27 |
|
| 28 |
open IsRelMonomorphism isMonomorphism |
| 29 |
|
| 30 |
------------------------------------------------------------------------ |
| 31 |
-- Properties |
| 32 |
|
| 33 |
refl : Reflexive _∼₂_ → Reflexive _∼₁_ |
| 34 |
refl refl = injective refl |
| 35 |
|
| 36 |
sym : Symmetric _∼₂_ → Symmetric _∼₁_ |
| 37 |
sym sym x∼y = injective (sym (cong x∼y)) |
| 38 |
|
| 39 |
trans : Transitive _∼₂_ → Transitive _∼₁_ |
| 40 |
trans trans x∼y y∼z = injective (trans (cong x∼y) (cong y∼z)) |
| 41 |
|
| 42 |
total : Total _∼₂_ → Total _∼₁_ |
| 43 |
total total x y = Sum.map injective injective (total ⟦ x ⟧ ⟦ y ⟧) |
| 44 |
|
| 45 |
asym : Asymmetric _∼₂_ → Asymmetric _∼₁_ |
| 46 |
asym asym x∼y y∼x = asym (cong x∼y) (cong y∼x) |
| 47 |
|
| 48 |
dec : Decidable _∼₂_ → Decidable _∼₁_ |
| 49 |
dec _∼?_ x y = map′ injective cong (⟦ x ⟧ ∼? ⟦ y ⟧) |
| 50 |
|
| 51 |
------------------------------------------------------------------------ |
| 52 |
-- Structures |
| 53 |
|
| 54 |
isEquivalence : IsEquivalence _∼₂_ → IsEquivalence _∼₁_ |
| 55 |
isEquivalence isEq = record |
| 56 |
{ refl = refl E.refl |
| 57 |
; sym = sym E.sym |
| 58 |
; trans = trans E.trans |
| 59 |
} where module E = IsEquivalence isEq |
| 60 |
|
| 61 |
isDecEquivalence : IsDecEquivalence _∼₂_ → IsDecEquivalence _∼₁_ |
| 62 |
isDecEquivalence isDecEq = record |
| 63 |
{ isEquivalence = isEquivalence E.isEquivalence |
| 64 |
; _≟_ = dec E._≟_ |
| 65 |
} where module E = IsDecEquivalence isDecEq |