| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Consequences of a monomorphism between orders |
| 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 (IsOrderMonomorphism) |
| 14 |
|
| 15 |
module Relation.Binary.Morphism.OrderMonomorphism |
| 16 |
{a b ℓ₁ ℓ₂ ℓ₃ ℓ₄} {A : Set a} {B : Set b} |
| 17 |
{_≈₁_ : Rel A ℓ₁} {_≈₂_ : Rel B ℓ₃} |
| 18 |
{_≲₁_ : Rel A ℓ₂} {_≲₂_ : Rel B ℓ₄} |
| 19 |
{⟦_⟧ : A → B} |
| 20 |
(isOrderMonomorphism : IsOrderMonomorphism _≈₁_ _≈₂_ _≲₁_ _≲₂_ ⟦_⟧) |
| 21 |
where |
| 22 |
|
| 23 |
open import Function.Base using (flip; _∘_) |
| 24 |
open import Data.Product.Base using (_,_; map) |
| 25 |
open import Relation.Binary.Definitions |
| 26 |
using (Irreflexive; Antisymmetric; Trichotomous; tri<; tri≈; tri> |
| 27 |
; _Respectsˡ_; _Respectsʳ_; _Respects₂_) |
| 28 |
import Relation.Binary.Morphism.RelMonomorphism as RawRelation |
| 29 |
using (isEquivalence; trans; total; dec) |
| 30 |
open import Relation.Binary.Structures |
| 31 |
using (IsPreorder; IsPartialOrder; IsTotalOrder; IsDecTotalOrder |
| 32 |
; IsStrictPartialOrder; IsStrictTotalOrder) |
| 33 |
|
| 34 |
open IsOrderMonomorphism isOrderMonomorphism |
| 35 |
|
| 36 |
------------------------------------------------------------------------ |
| 37 |
-- Re-export equivalence proofs |
| 38 |
|
| 39 |
module EqM = RawRelation Eq.isRelMonomorphism |
| 40 |
|
| 41 |
open RawRelation isRelMonomorphism public |
| 42 |
|
| 43 |
------------------------------------------------------------------------ |
| 44 |
-- Properties |
| 45 |
|
| 46 |
reflexive : _≈₂_ ⇒ _≲₂_ → _≈₁_ ⇒ _≲₁_ |
| 47 |
reflexive refl x≈y = cancel (refl (cong x≈y)) |
| 48 |
|
| 49 |
irrefl : Irreflexive _≈₂_ _≲₂_ → Irreflexive _≈₁_ _≲₁_ |
| 50 |
irrefl irrefl x≈y x∼y = irrefl (cong x≈y) (mono x∼y) |
| 51 |
|
| 52 |
antisym : Antisymmetric _≈₂_ _≲₂_ → Antisymmetric _≈₁_ _≲₁_ |
| 53 |
antisym antisym x∼y y∼x = injective (antisym (mono x∼y) (mono y∼x)) |
| 54 |
|
| 55 |
compare : Trichotomous _≈₂_ _≲₂_ → Trichotomous _≈₁_ _≲₁_ |
| 56 |
compare compare x y with compare ⟦ x ⟧ ⟦ y ⟧ |
| 57 |
... | tri< a ¬b ¬c = tri< (cancel a) (¬b ∘ cong) (¬c ∘ mono) |
| 58 |
... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ mono) (injective b) (¬c ∘ mono) |
| 59 |
... | tri> ¬a ¬b c = tri> (¬a ∘ mono) (¬b ∘ cong) (cancel c) |
| 60 |
|
| 61 |
respˡ : _≲₂_ Respectsˡ _≈₂_ → _≲₁_ Respectsˡ _≈₁_ |
| 62 |
respˡ resp x≈y x∼z = cancel (resp (cong x≈y) (mono x∼z)) |
| 63 |
|
| 64 |
respʳ : _≲₂_ Respectsʳ _≈₂_ → _≲₁_ Respectsʳ _≈₁_ |
| 65 |
respʳ resp x≈y y∼z = cancel (resp (cong x≈y) (mono y∼z)) |
| 66 |
|
| 67 |
resp : _≲₂_ Respects₂ _≈₂_ → _≲₁_ Respects₂ _≈₁_ |
| 68 |
resp = map respʳ respˡ |
| 69 |
|
| 70 |
------------------------------------------------------------------------ |
| 71 |
-- Structures |
| 72 |
|
| 73 |
isPreorder : IsPreorder _≈₂_ _≲₂_ → IsPreorder _≈₁_ _≲₁_ |
| 74 |
isPreorder O = record |
| 75 |
{ isEquivalence = EqM.isEquivalence O.isEquivalence |
| 76 |
; reflexive = reflexive O.reflexive |
| 77 |
; trans = trans O.trans |
| 78 |
} where module O = IsPreorder O |
| 79 |
|
| 80 |
isPartialOrder : IsPartialOrder _≈₂_ _≲₂_ → IsPartialOrder _≈₁_ _≲₁_ |
| 81 |
isPartialOrder O = record |
| 82 |
{ isPreorder = isPreorder O.isPreorder |
| 83 |
; antisym = antisym O.antisym |
| 84 |
} where module O = IsPartialOrder O |
| 85 |
|
| 86 |
isTotalOrder : IsTotalOrder _≈₂_ _≲₂_ → IsTotalOrder _≈₁_ _≲₁_ |
| 87 |
isTotalOrder O = record |
| 88 |
{ isPartialOrder = isPartialOrder O.isPartialOrder |
| 89 |
; total = total O.total |
| 90 |
} where module O = IsTotalOrder O |
| 91 |
|
| 92 |
isDecTotalOrder : IsDecTotalOrder _≈₂_ _≲₂_ → IsDecTotalOrder _≈₁_ _≲₁_ |
| 93 |
isDecTotalOrder O = record |
| 94 |
{ isTotalOrder = isTotalOrder O.isTotalOrder |
| 95 |
; _≟_ = EqM.dec O._≟_ |
| 96 |
; _≤?_ = dec O._≤?_ |
| 97 |
} where module O = IsDecTotalOrder O |
| 98 |
|
| 99 |
isStrictPartialOrder : IsStrictPartialOrder _≈₂_ _≲₂_ → |
| 100 |
IsStrictPartialOrder _≈₁_ _≲₁_ |
| 101 |
isStrictPartialOrder O = record |
| 102 |
{ isEquivalence = EqM.isEquivalence O.isEquivalence |
| 103 |
; irrefl = irrefl O.irrefl |
| 104 |
; trans = trans O.trans |
| 105 |
; <-resp-≈ = resp O.<-resp-≈ |
| 106 |
} where module O = IsStrictPartialOrder O |
| 107 |
|
| 108 |
isStrictTotalOrder : IsStrictTotalOrder _≈₂_ _≲₂_ → |
| 109 |
IsStrictTotalOrder _≈₁_ _≲₁_ |
| 110 |
isStrictTotalOrder O = record |
| 111 |
{ isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder |
| 112 |
; compare = compare O.compare |
| 113 |
} where module O = IsStrictTotalOrder O |