~ubuntu-branches/ubuntu/saucy/agda-stdlib/saucy-proposed

« back to all changes in this revision

Viewing changes to src/Relation/Binary/Product/NonStrictLex.agda

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-01-08 23:35:09 UTC
  • Revision ID: james.westby@ubuntu.com-20100108233509-l6ejt9xji64xysfb
Tags: upstream-0.3
Import upstream version 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
------------------------------------------------------------------------
 
2
-- Lexicographic products of binary relations
 
3
------------------------------------------------------------------------
 
4
 
 
5
-- The definition of lexicographic product used here is suitable if
 
6
-- the left-hand relation is a (non-strict) partial order.
 
7
 
 
8
module Relation.Binary.Product.NonStrictLex where
 
9
 
 
10
open import Data.Product
 
11
open import Data.Sum
 
12
open import Level
 
13
open import Relation.Binary
 
14
open import Relation.Binary.Consequences
 
15
import Relation.Binary.NonStrictToStrict as Conv
 
16
open import Relation.Binary.Product.Pointwise as Pointwise
 
17
  using (_×-Rel_)
 
18
import Relation.Binary.Product.StrictLex as Strict
 
19
 
 
20
private
 
21
 module Dummy {a₁ a₂ : Set} where
 
22
 
 
23
  ×-Lex : (≈₁ ≤₁ : Rel a₁ zero) → (≤₂ : Rel a₂ zero) →
 
24
          Rel (a₁ × a₂) zero
 
25
  ×-Lex ≈₁ ≤₁ ≤₂ = Strict.×-Lex ≈₁ (Conv._<_ ≈₁ ≤₁) ≤₂
 
26
 
 
27
  -- Some properties which are preserved by ×-Lex (under certain
 
28
  -- assumptions).
 
29
 
 
30
  ×-reflexive : ∀ ≈₁ ≤₁ {≈₂} ≤₂ →
 
31
                ≈₂ ⇒ ≤₂ → (≈₁ ×-Rel ≈₂) ⇒ (×-Lex ≈₁ ≤₁ ≤₂)
 
32
  ×-reflexive ≈₁ ≤₁ ≤₂ refl₂ {x} {y} =
 
33
    Strict.×-reflexive ≈₁ (Conv._<_ ≈₁ ≤₁) ≤₂ refl₂ {x} {y}
 
34
 
 
35
  ×-transitive : ∀ {≈₁ ≤₁} → IsPartialOrder ≈₁ ≤₁ →
 
36
                 ∀ {≤₂} → Transitive ≤₂ →
 
37
                 Transitive (×-Lex ≈₁ ≤₁ ≤₂)
 
38
  ×-transitive {≈₁ = ≈₁} {≤₁ = ≤₁} po₁ {≤₂ = ≤₂} trans₂
 
39
               {x} {y} {z} =
 
40
    Strict.×-transitive
 
41
      {<₁ = Conv._<_ ≈₁ ≤₁}
 
42
      isEquivalence (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈)
 
43
      (Conv.trans _ _ po₁)
 
44
      {≤₂ = ≤₂} trans₂ {x} {y} {z}
 
45
    where open IsPartialOrder po₁
 
46
 
 
47
  ×-antisymmetric : ∀ {≈₁ ≤₁} → IsPartialOrder ≈₁ ≤₁ →
 
48
                    ∀ {≈₂ ≤₂} → Antisymmetric ≈₂ ≤₂ →
 
49
                    Antisymmetric (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ ≤₁ ≤₂)
 
50
  ×-antisymmetric {≈₁ = ≈₁} {≤₁ = ≤₁} po₁ {≤₂ = ≤₂} antisym₂
 
51
                  {x} {y} =
 
52
    Strict.×-antisymmetric {<₁ = Conv._<_ ≈₁ ≤₁} ≈-sym₁ irrefl₁ asym₁
 
53
                           {≤₂ = ≤₂} antisym₂ {x} {y}
 
54
    where
 
55
    open IsPartialOrder po₁
 
56
    open Eq renaming (refl to ≈-refl₁; sym to ≈-sym₁)
 
57
 
 
58
    irrefl₁ : Irreflexive ≈₁ (Conv._<_ ≈₁ ≤₁)
 
59
    irrefl₁ = Conv.irrefl ≈₁ ≤₁
 
60
 
 
61
    asym₁ : Asymmetric (Conv._<_ ≈₁ ≤₁)
 
62
    asym₁ = trans∧irr⟶asym {≈ = ≈₁}
 
63
                           ≈-refl₁ (Conv.trans _ _ po₁) irrefl₁
 
64
 
 
65
  ×-≈-respects₂ : ∀ {≈₁ ≤₁} → IsEquivalence ≈₁ → ≤₁ Respects₂ ≈₁ →
 
66
                  ∀ {≈₂ ≤₂} → ≤₂ Respects₂ ≈₂ →
 
67
                  (×-Lex ≈₁ ≤₁ ≤₂) Respects₂ (≈₁ ×-Rel ≈₂)
 
68
  ×-≈-respects₂ eq₁ resp₁ resp₂ =
 
69
    Strict.×-≈-respects₂ eq₁ (Conv.<-resp-≈ _ _ eq₁ resp₁) resp₂
 
70
 
 
71
  ×-decidable : ∀ {≈₁ ≤₁} → Decidable ≈₁ → Decidable ≤₁ →
 
72
                ∀ {≤₂} → Decidable ≤₂ →
 
73
                Decidable (×-Lex ≈₁ ≤₁ ≤₂)
 
74
  ×-decidable dec-≈₁ dec-≤₁ dec-≤₂ =
 
75
    Strict.×-decidable dec-≈₁ (Conv.decidable _ _ dec-≈₁ dec-≤₁)
 
76
                       dec-≤₂
 
77
 
 
78
  ×-total : ∀ {≈₁ ≤₁} → Symmetric ≈₁ → Decidable ≈₁ →
 
79
                        Antisymmetric ≈₁ ≤₁ → Total ≤₁ →
 
80
            ∀ {≤₂} → Total ≤₂ →
 
81
            Total (×-Lex ≈₁ ≤₁ ≤₂)
 
82
  ×-total {≈₁ = ≈₁} {≤₁ = ≤₁} sym₁ dec₁ antisym₁ total₁
 
83
                    {≤₂ = ≤₂} total₂ = total
 
84
    where
 
85
    tri₁ : Trichotomous ≈₁ (Conv._<_ ≈₁ ≤₁)
 
86
    tri₁ = Conv.trichotomous _ _ sym₁ dec₁ antisym₁ total₁
 
87
 
 
88
    total : Total (×-Lex ≈₁ ≤₁ ≤₂)
 
89
    total x y with tri₁ (proj₁ x) (proj₁ y)
 
90
    ... | tri< x₁<y₁ x₁≉y₁ x₁≯y₁ = inj₁ (inj₁ x₁<y₁)
 
91
    ... | tri> x₁≮y₁ x₁≉y₁ x₁>y₁ = inj₂ (inj₁ x₁>y₁)
 
92
    ... | tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁ with total₂ (proj₂ x) (proj₂ y)
 
93
    ...   | inj₁ x₂≤y₂ = inj₁ (inj₂ (x₁≈y₁ , x₂≤y₂))
 
94
    ...   | inj₂ x₂≥y₂ = inj₂ (inj₂ (sym₁ x₁≈y₁ , x₂≥y₂))
 
95
 
 
96
  -- Some collections of properties which are preserved by ×-Lex
 
97
  -- (under certain assumptions).
 
98
 
 
99
  _×-isPartialOrder_ : ∀ {≈₁ ≤₁} → IsPartialOrder ≈₁ ≤₁ →
 
100
                       ∀ {≈₂ ≤₂} → IsPartialOrder ≈₂ ≤₂ →
 
101
                       IsPartialOrder (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ ≤₁ ≤₂)
 
102
  _×-isPartialOrder_ {≈₁ = ≈₁} {≤₁ = ≤₁} po₁ {≤₂ = ≤₂} po₂ = record
 
103
    { isPreorder = record
 
104
        { isEquivalence = Pointwise._×-isEquivalence_
 
105
                            (isEquivalence po₁)
 
106
                            (isEquivalence po₂)
 
107
        ; reflexive     = λ {x y} →
 
108
                          ×-reflexive ≈₁ ≤₁ ≤₂ (reflexive po₂) {x} {y}
 
109
        ; trans         = λ {x y z} →
 
110
                          ×-transitive po₁ {≤₂ = ≤₂} (trans po₂)
 
111
                                       {x} {y} {z}
 
112
        ; ∼-resp-≈      = ×-≈-respects₂ (isEquivalence po₁)
 
113
                                        (≤-resp-≈ po₁)
 
114
                                        (≤-resp-≈ po₂)
 
115
        }
 
116
    ; antisym = λ {x y} →
 
117
                ×-antisymmetric {≤₁ = ≤₁} po₁
 
118
                                {≤₂ = ≤₂} (antisym po₂) {x} {y}
 
119
    }
 
120
    where open IsPartialOrder
 
121
 
 
122
  ×-isTotalOrder : ∀ {≈₁ ≤₁} → Decidable ≈₁ → IsTotalOrder ≈₁ ≤₁ →
 
123
                   ∀ {≈₂ ≤₂} → IsTotalOrder ≈₂ ≤₂ →
 
124
                   IsTotalOrder (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ ≤₁ ≤₂)
 
125
  ×-isTotalOrder {≤₁ = ≤₁} ≈₁-dec to₁ {≤₂ = ≤₂} to₂ = record
 
126
    { isPartialOrder = isPartialOrder to₁ ×-isPartialOrder
 
127
                       isPartialOrder to₂
 
128
    ; total          = ×-total {≤₁ = ≤₁} (Eq.sym to₁) ≈₁-dec
 
129
                                         (antisym to₁) (total to₁)
 
130
                               {≤₂ = ≤₂} (total to₂)
 
131
    }
 
132
    where open IsTotalOrder
 
133
 
 
134
  _×-isDecTotalOrder_ : ∀ {≈₁ ≤₁} → IsDecTotalOrder ≈₁ ≤₁ →
 
135
                        ∀ {≈₂ ≤₂} → IsDecTotalOrder ≈₂ ≤₂ →
 
136
                        IsDecTotalOrder (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ ≤₁ ≤₂)
 
137
  _×-isDecTotalOrder_ {≤₁ = ≤₁} to₁ {≤₂ = ≤₂} to₂ = record
 
138
    { isTotalOrder = ×-isTotalOrder (_≟_ to₁)
 
139
                                    (isTotalOrder to₁)
 
140
                                    (isTotalOrder to₂)
 
141
    ; _≟_          = Pointwise._×-decidable_ (_≟_ to₁) (_≟_ to₂)
 
142
    ; _≤?_         = ×-decidable (_≟_ to₁) (_≤?_ to₁) (_≤?_ to₂)
 
143
    }
 
144
    where open IsDecTotalOrder
 
145
 
 
146
open Dummy public
 
147
 
 
148
-- "Packages" (e.g. posets) can also be combined.
 
149
 
 
150
_×-poset_ : Poset _ _ _ → Poset _ _ _ → Poset _ _ _
 
151
p₁ ×-poset p₂ = record
 
152
  { isPartialOrder = isPartialOrder p₁ ×-isPartialOrder
 
153
                     isPartialOrder p₂
 
154
  } where open Poset
 
155
 
 
156
_×-totalOrder_ :
 
157
  DecTotalOrder _ _ _ → TotalOrder _ _ _ → TotalOrder _ _ _
 
158
t₁ ×-totalOrder t₂ = record
 
159
  { isTotalOrder = ×-isTotalOrder T₁._≟_ T₁.isTotalOrder T₂.isTotalOrder
 
160
  }
 
161
  where
 
162
  module T₁ = DecTotalOrder t₁
 
163
  module T₂ =    TotalOrder t₂
 
164
 
 
165
_×-decTotalOrder_ :
 
166
  DecTotalOrder _ _ _ → DecTotalOrder _ _ _ → DecTotalOrder _ _ _
 
167
t₁ ×-decTotalOrder t₂ = record
 
168
  { isDecTotalOrder = isDecTotalOrder t₁ ×-isDecTotalOrder
 
169
                      isDecTotalOrder t₂
 
170
  } where open DecTotalOrder