431
|
1 open import Level
|
|
2 open import Ordinals
|
|
3 module OrdUtil {n : Level} (O : Ordinals {n} ) where
|
|
4
|
|
5 open import logic
|
|
6 open import nat
|
|
7 open import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ )
|
|
8 open import Data.Empty
|
|
9 open import Relation.Binary.PropositionalEquality
|
|
10 open import Relation.Nullary
|
|
11 open import Relation.Binary hiding (_⇔_)
|
|
12
|
|
13 open Ordinals.Ordinals O
|
|
14 open Ordinals.IsOrdinals isOrdinal
|
|
15 open Ordinals.IsNext isNext
|
|
16
|
|
17 o<-dom : { x y : Ordinal } → x o< y → Ordinal
|
|
18 o<-dom {x} _ = x
|
|
19
|
|
20 o<-cod : { x y : Ordinal } → x o< y → Ordinal
|
|
21 o<-cod {_} {y} _ = y
|
|
22
|
|
23 o<-subst : {Z X z x : Ordinal } → Z o< X → Z ≡ z → X ≡ x → z o< x
|
|
24 o<-subst df refl refl = df
|
|
25
|
|
26 o<¬≡ : { ox oy : Ordinal } → ox ≡ oy → ox o< oy → ⊥
|
|
27 o<¬≡ {ox} {oy} eq lt with trio< ox oy
|
|
28 o<¬≡ {ox} {oy} eq lt | tri< a ¬b ¬c = ¬b eq
|
|
29 o<¬≡ {ox} {oy} eq lt | tri≈ ¬a b ¬c = ¬a lt
|
|
30 o<¬≡ {ox} {oy} eq lt | tri> ¬a ¬b c = ¬b eq
|
|
31
|
|
32 o<> : {x y : Ordinal } → y o< x → x o< y → ⊥
|
|
33 o<> {ox} {oy} lt tl with trio< ox oy
|
|
34 o<> {ox} {oy} lt tl | tri< a ¬b ¬c = ¬c lt
|
|
35 o<> {ox} {oy} lt tl | tri≈ ¬a b ¬c = ¬a tl
|
|
36 o<> {ox} {oy} lt tl | tri> ¬a ¬b c = ¬a tl
|
|
37
|
|
38 osuc-< : { x y : Ordinal } → y o< osuc x → x o< y → ⊥
|
|
39 osuc-< {x} {y} y<ox x<y with osuc-≡< y<ox
|
|
40 osuc-< {x} {y} y<ox x<y | case1 refl = o<¬≡ refl x<y
|
|
41 osuc-< {x} {y} y<ox x<y | case2 y<x = o<> x<y y<x
|
|
42
|
|
43 osucc : {ox oy : Ordinal } → oy o< ox → osuc oy o< osuc ox
|
|
44 osucc {ox} {oy} oy<ox with trio< (osuc oy) ox
|
|
45 osucc {ox} {oy} oy<ox | tri< a ¬b ¬c = ordtrans a <-osuc
|
|
46 osucc {ox} {oy} oy<ox | tri≈ ¬a refl ¬c = <-osuc
|
|
47 osucc {ox} {oy} oy<ox | tri> ¬a ¬b c with osuc-≡< c
|
|
48 osucc {ox} {oy} oy<ox | tri> ¬a ¬b c | case1 eq = ⊥-elim (o<¬≡ (sym eq) oy<ox)
|
|
49 osucc {ox} {oy} oy<ox | tri> ¬a ¬b c | case2 lt = ⊥-elim (o<> lt oy<ox)
|
|
50
|
|
51 osucprev : {ox oy : Ordinal } → osuc oy o< osuc ox → oy o< ox
|
|
52 osucprev {ox} {oy} oy<ox with trio< oy ox
|
|
53 osucprev {ox} {oy} oy<ox | tri< a ¬b ¬c = a
|
|
54 osucprev {ox} {oy} oy<ox | tri≈ ¬a b ¬c = ⊥-elim (o<¬≡ (cong (λ k → osuc k) b) oy<ox )
|
|
55 osucprev {ox} {oy} oy<ox | tri> ¬a ¬b c = ⊥-elim (o<> (osucc c) oy<ox )
|
|
56
|
653
|
57 ordtrans≤-< : {ox oy oz : Ordinal } → ox o< osuc oy → oy o< oz → ox o< oz
|
|
58 ordtrans≤-< {ox} {oy} {oz} x≤y y<z with osuc-≡< x≤y
|
|
59 ... | case1 x=y = subst ( λ k → k o< oz ) (sym x=y) y<z
|
|
60 ... | case2 x<y = ordtrans x<y y<z
|
|
61
|
431
|
62 open _∧_
|
|
63
|
|
64 osuc2 : ( x y : Ordinal ) → ( osuc x o< osuc (osuc y )) ⇔ (x o< osuc y)
|
|
65 proj2 (osuc2 x y) lt = osucc lt
|
|
66 proj1 (osuc2 x y) ox<ooy with osuc-≡< ox<ooy
|
|
67 proj1 (osuc2 x y) ox<ooy | case1 ox=oy = o<-subst <-osuc refl ox=oy
|
|
68 proj1 (osuc2 x y) ox<ooy | case2 ox<oy = ordtrans <-osuc ox<oy
|
|
69
|
538
|
70 o≡? : (x y : Ordinal) → Dec ( x ≡ y )
|
|
71 o≡? x y with trio< x y
|
|
72 ... | tri< a ¬b ¬c = no ¬b
|
|
73 ... | tri≈ ¬a b ¬c = yes b
|
|
74 ... | tri> ¬a ¬b c = no ¬b
|
|
75
|
431
|
76 _o≤_ : Ordinal → Ordinal → Set n
|
|
77 a o≤ b = a o< osuc b -- (a ≡ b) ∨ ( a o< b )
|
|
78
|
653
|
79 o<→≤ : {a b : Ordinal} → a o< b → a o≤ b
|
|
80 o<→≤ {a} {b} lt with trio< a (osuc b)
|
|
81 ... | tri< a₁ ¬b ¬c = a₁
|
|
82 ... | tri≈ ¬a b₁ ¬c = ⊥-elim (¬a (ordtrans lt <-osuc ) )
|
|
83 ... | tri> ¬a ¬b c = ⊥-elim (¬a (ordtrans lt <-osuc ) )
|
|
84
|
611
|
85 -- o<-irr : { x y : Ordinal } → { lt lt1 : x o< y } → lt ≡ lt1
|
431
|
86
|
|
87 xo<ab : {oa ob : Ordinal } → ( {ox : Ordinal } → ox o< oa → ox o< ob ) → oa o< osuc ob
|
|
88 xo<ab {oa} {ob} a→b with trio< oa ob
|
|
89 xo<ab {oa} {ob} a→b | tri< a ¬b ¬c = ordtrans a <-osuc
|
|
90 xo<ab {oa} {ob} a→b | tri≈ ¬a refl ¬c = <-osuc
|
|
91 xo<ab {oa} {ob} a→b | tri> ¬a ¬b c = ⊥-elim ( o<¬≡ refl (a→b c ) )
|
|
92
|
|
93 maxα : Ordinal → Ordinal → Ordinal
|
|
94 maxα x y with trio< x y
|
|
95 maxα x y | tri< a ¬b ¬c = y
|
|
96 maxα x y | tri> ¬a ¬b c = x
|
|
97 maxα x y | tri≈ ¬a refl ¬c = x
|
|
98
|
|
99 omin : Ordinal → Ordinal → Ordinal
|
|
100 omin x y with trio< x y
|
|
101 omin x y | tri< a ¬b ¬c = x
|
|
102 omin x y | tri> ¬a ¬b c = y
|
|
103 omin x y | tri≈ ¬a refl ¬c = x
|
|
104
|
|
105 min1 : {x y z : Ordinal } → z o< x → z o< y → z o< omin x y
|
|
106 min1 {x} {y} {z} z<x z<y with trio< x y
|
|
107 min1 {x} {y} {z} z<x z<y | tri< a ¬b ¬c = z<x
|
|
108 min1 {x} {y} {z} z<x z<y | tri≈ ¬a refl ¬c = z<x
|
|
109 min1 {x} {y} {z} z<x z<y | tri> ¬a ¬b c = z<y
|
|
110
|
|
111 --
|
|
112 -- max ( osuc x , osuc y )
|
|
113 --
|
|
114
|
|
115 omax : ( x y : Ordinal ) → Ordinal
|
|
116 omax x y with trio< x y
|
|
117 omax x y | tri< a ¬b ¬c = osuc y
|
|
118 omax x y | tri> ¬a ¬b c = osuc x
|
|
119 omax x y | tri≈ ¬a refl ¬c = osuc x
|
|
120
|
|
121 omax< : ( x y : Ordinal ) → x o< y → osuc y ≡ omax x y
|
|
122 omax< x y lt with trio< x y
|
|
123 omax< x y lt | tri< a ¬b ¬c = refl
|
|
124 omax< x y lt | tri≈ ¬a b ¬c = ⊥-elim (¬a lt )
|
|
125 omax< x y lt | tri> ¬a ¬b c = ⊥-elim (¬a lt )
|
|
126
|
|
127 omax≤ : ( x y : Ordinal ) → x o≤ y → osuc y ≡ omax x y
|
|
128 omax≤ x y le with trio< x y
|
|
129 omax≤ x y le | tri< a ¬b ¬c = refl
|
|
130 omax≤ x y le | tri≈ ¬a refl ¬c = refl
|
|
131 omax≤ x y le | tri> ¬a ¬b c with osuc-≡< le
|
|
132 omax≤ x y le | tri> ¬a ¬b c | case1 eq = ⊥-elim (¬b eq)
|
|
133 omax≤ x y le | tri> ¬a ¬b c | case2 x<y = ⊥-elim (¬a x<y)
|
|
134
|
|
135 omax≡ : ( x y : Ordinal ) → x ≡ y → osuc y ≡ omax x y
|
|
136 omax≡ x y eq with trio< x y
|
|
137 omax≡ x y eq | tri< a ¬b ¬c = ⊥-elim (¬b eq )
|
|
138 omax≡ x y eq | tri≈ ¬a refl ¬c = refl
|
|
139 omax≡ x y eq | tri> ¬a ¬b c = ⊥-elim (¬b eq )
|
|
140
|
|
141 omax-x : ( x y : Ordinal ) → x o< omax x y
|
|
142 omax-x x y with trio< x y
|
|
143 omax-x x y | tri< a ¬b ¬c = ordtrans a <-osuc
|
|
144 omax-x x y | tri> ¬a ¬b c = <-osuc
|
|
145 omax-x x y | tri≈ ¬a refl ¬c = <-osuc
|
|
146
|
|
147 omax-y : ( x y : Ordinal ) → y o< omax x y
|
|
148 omax-y x y with trio< x y
|
|
149 omax-y x y | tri< a ¬b ¬c = <-osuc
|
|
150 omax-y x y | tri> ¬a ¬b c = ordtrans c <-osuc
|
|
151 omax-y x y | tri≈ ¬a refl ¬c = <-osuc
|
|
152
|
|
153 omxx : ( x : Ordinal ) → omax x x ≡ osuc x
|
|
154 omxx x with trio< x x
|
|
155 omxx x | tri< a ¬b ¬c = ⊥-elim (¬b refl )
|
|
156 omxx x | tri> ¬a ¬b c = ⊥-elim (¬b refl )
|
|
157 omxx x | tri≈ ¬a refl ¬c = refl
|
|
158
|
|
159 omxxx : ( x : Ordinal ) → omax x (omax x x ) ≡ osuc (osuc x)
|
|
160 omxxx x = trans ( cong ( λ k → omax x k ) (omxx x )) (sym ( omax< x (osuc x) <-osuc ))
|
|
161
|
|
162 open _∧_
|
|
163
|
625
|
164 o≤-refl0 : { i j : Ordinal } → i ≡ j → i o≤ j
|
|
165 o≤-refl0 {i} {j} eq = subst (λ k → i o< osuc k ) eq <-osuc
|
|
166
|
|
167 o≤-refl : { i : Ordinal } → i o≤ i
|
|
168 o≤-refl {i} = subst (λ k → i o< osuc k ) refl <-osuc
|
|
169
|
431
|
170 OrdTrans : Transitive _o≤_
|
|
171 OrdTrans a≤b b≤c with osuc-≡< a≤b | osuc-≡< b≤c
|
|
172 OrdTrans a≤b b≤c | case1 refl | case1 refl = <-osuc
|
|
173 OrdTrans a≤b b≤c | case1 refl | case2 a≤c = ordtrans a≤c <-osuc
|
|
174 OrdTrans a≤b b≤c | case2 a≤c | case1 refl = ordtrans a≤c <-osuc
|
|
175 OrdTrans a≤b b≤c | case2 a<b | case2 b<c = ordtrans (ordtrans a<b b<c) <-osuc
|
|
176
|
|
177 OrdPreorder : Preorder n n n
|
|
178 OrdPreorder = record { Carrier = Ordinal
|
|
179 ; _≈_ = _≡_
|
|
180 ; _∼_ = _o≤_
|
|
181 ; isPreorder = record {
|
|
182 isEquivalence = record { refl = refl ; sym = sym ; trans = trans }
|
625
|
183 ; reflexive = o≤-refl0
|
431
|
184 ; trans = OrdTrans
|
|
185 }
|
|
186 }
|
|
187
|
|
188 FExists : {m l : Level} → ( ψ : Ordinal → Set m )
|
|
189 → {p : Set l} ( P : { y : Ordinal } → ψ y → ¬ p )
|
|
190 → (exists : ¬ (∀ y → ¬ ( ψ y ) ))
|
|
191 → ¬ p
|
|
192 FExists {m} {l} ψ {p} P = contra-position ( λ p y ψy → P {y} ψy p )
|
|
193
|
|
194 nexto∅ : {x : Ordinal} → o∅ o< next x
|
|
195 nexto∅ {x} with trio< o∅ x
|
|
196 nexto∅ {x} | tri< a ¬b ¬c = ordtrans a x<nx
|
|
197 nexto∅ {x} | tri≈ ¬a b ¬c = subst (λ k → k o< next x) (sym b) x<nx
|
|
198 nexto∅ {x} | tri> ¬a ¬b c = ⊥-elim ( ¬x<0 c )
|
|
199
|
|
200 next< : {x y z : Ordinal} → x o< next z → y o< next x → y o< next z
|
|
201 next< {x} {y} {z} x<nz y<nx with trio< y (next z)
|
|
202 next< {x} {y} {z} x<nz y<nx | tri< a ¬b ¬c = a
|
|
203 next< {x} {y} {z} x<nz y<nx | tri≈ ¬a b ¬c = ⊥-elim (¬nx<nx x<nz (subst (λ k → k o< next x) b y<nx)
|
|
204 (λ w nz=ow → o<¬≡ nz=ow (subst₂ (λ j k → j o< k ) (sym nz=ow) nz=ow (osuc<nx (subst (λ k → w o< k ) (sym nz=ow) <-osuc) ))))
|
|
205 next< {x} {y} {z} x<nz y<nx | tri> ¬a ¬b c = ⊥-elim (¬nx<nx x<nz (ordtrans c y<nx )
|
|
206 (λ w nz=ow → o<¬≡ (sym nz=ow) (osuc<nx (subst (λ k → w o< k ) (sym nz=ow) <-osuc ))))
|
|
207
|
|
208 osuc< : {x y : Ordinal} → osuc x ≡ y → x o< y
|
|
209 osuc< {x} {y} refl = <-osuc
|
|
210
|
|
211 nexto=n : {x y : Ordinal} → x o< next (osuc y) → x o< next y
|
|
212 nexto=n {x} {y} x<noy = next< (osuc<nx x<nx) x<noy
|
|
213
|
|
214 nexto≡ : {x : Ordinal} → next x ≡ next (osuc x)
|
|
215 nexto≡ {x} with trio< (next x) (next (osuc x) )
|
|
216 -- next x o< next (osuc x ) -> osuc x o< next x o< next (osuc x) -> next x ≡ osuc z -> z o o< next x -> osuc z o< next x -> next x o< next x
|
|
217 nexto≡ {x} | tri< a ¬b ¬c = ⊥-elim (¬nx<nx (osuc<nx x<nx ) a
|
|
218 (λ z eq → o<¬≡ (sym eq) (osuc<nx (osuc< (sym eq)))))
|
|
219 nexto≡ {x} | tri≈ ¬a b ¬c = b
|
|
220 -- next (osuc x) o< next x -> osuc x o< next (osuc x) o< next x -> next (osuc x) ≡ osuc z -> z o o< next (osuc x) ...
|
|
221 nexto≡ {x} | tri> ¬a ¬b c = ⊥-elim (¬nx<nx (ordtrans <-osuc x<nx) c
|
|
222 (λ z eq → o<¬≡ (sym eq) (osuc<nx (osuc< (sym eq)))))
|
|
223
|
|
224 next-is-limit : {x y : Ordinal} → ¬ (next x ≡ osuc y)
|
|
225 next-is-limit {x} {y} eq = o<¬≡ (sym eq) (osuc<nx y<nx) where
|
|
226 y<nx : y o< next x
|
|
227 y<nx = osuc< (sym eq)
|
|
228
|
|
229 omax<next : {x y : Ordinal} → x o< y → omax x y o< next y
|
|
230 omax<next {x} {y} x<y = subst (λ k → k o< next y ) (omax< _ _ x<y ) (osuc<nx x<nx)
|
|
231
|
|
232 x<ny→≡next : {x y : Ordinal} → x o< y → y o< next x → next x ≡ next y
|
|
233 x<ny→≡next {x} {y} x<y y<nx with trio< (next x) (next y)
|
|
234 x<ny→≡next {x} {y} x<y y<nx | tri< a ¬b ¬c = -- x < y < next x < next y ∧ next x = osuc z
|
|
235 ⊥-elim ( ¬nx<nx y<nx a (λ z eq → o<¬≡ (sym eq) (osuc<nx (subst (λ k → z o< k ) (sym eq) <-osuc ))))
|
|
236 x<ny→≡next {x} {y} x<y y<nx | tri≈ ¬a b ¬c = b
|
|
237 x<ny→≡next {x} {y} x<y y<nx | tri> ¬a ¬b c = -- x < y < next y < next x
|
|
238 ⊥-elim ( ¬nx<nx (ordtrans x<y x<nx) c (λ z eq → o<¬≡ (sym eq) (osuc<nx (subst (λ k → z o< k ) (sym eq) <-osuc ))))
|
|
239
|
|
240 ≤next : {x y : Ordinal} → x o≤ y → next x o≤ next y
|
|
241 ≤next {x} {y} x≤y with trio< (next x) y
|
|
242 ≤next {x} {y} x≤y | tri< a ¬b ¬c = ordtrans a (ordtrans x<nx <-osuc )
|
|
243 ≤next {x} {y} x≤y | tri≈ ¬a refl ¬c = (ordtrans x<nx <-osuc )
|
|
244 ≤next {x} {y} x≤y | tri> ¬a ¬b c with osuc-≡< x≤y
|
625
|
245 ≤next {x} {y} x≤y | tri> ¬a ¬b c | case1 refl = o≤-refl -- x = y < next x
|
|
246 ≤next {x} {y} x≤y | tri> ¬a ¬b c | case2 x<y = o≤-refl0 (x<ny→≡next x<y c) -- x ≤ y < next x
|
431
|
247
|
|
248 x<ny→≤next : {x y : Ordinal} → x o< next y → next x o≤ next y
|
|
249 x<ny→≤next {x} {y} x<ny with trio< x y
|
|
250 x<ny→≤next {x} {y} x<ny | tri< a ¬b ¬c = ≤next (ordtrans a <-osuc )
|
625
|
251 x<ny→≤next {x} {y} x<ny | tri≈ ¬a refl ¬c = o≤-refl
|
|
252 x<ny→≤next {x} {y} x<ny | tri> ¬a ¬b c = o≤-refl0 (sym ( x<ny→≡next c x<ny ))
|
431
|
253
|
|
254 omax<nomax : {x y : Ordinal} → omax x y o< next (omax x y )
|
|
255 omax<nomax {x} {y} with trio< x y
|
|
256 omax<nomax {x} {y} | tri< a ¬b ¬c = subst (λ k → osuc y o< k ) nexto≡ (osuc<nx x<nx )
|
|
257 omax<nomax {x} {y} | tri≈ ¬a refl ¬c = subst (λ k → osuc x o< k ) nexto≡ (osuc<nx x<nx )
|
|
258 omax<nomax {x} {y} | tri> ¬a ¬b c = subst (λ k → osuc x o< k ) nexto≡ (osuc<nx x<nx )
|
|
259
|
|
260 omax<nx : {x y z : Ordinal} → x o< next z → y o< next z → omax x y o< next z
|
|
261 omax<nx {x} {y} {z} x<nz y<nz with trio< x y
|
|
262 omax<nx {x} {y} {z} x<nz y<nz | tri< a ¬b ¬c = osuc<nx y<nz
|
|
263 omax<nx {x} {y} {z} x<nz y<nz | tri≈ ¬a refl ¬c = osuc<nx y<nz
|
|
264 omax<nx {x} {y} {z} x<nz y<nz | tri> ¬a ¬b c = osuc<nx x<nz
|
|
265
|
|
266 nn<omax : {x nx ny : Ordinal} → x o< next nx → x o< next ny → x o< next (omax nx ny)
|
|
267 nn<omax {x} {nx} {ny} xnx xny with trio< nx ny
|
|
268 nn<omax {x} {nx} {ny} xnx xny | tri< a ¬b ¬c = subst (λ k → x o< k ) nexto≡ xny
|
|
269 nn<omax {x} {nx} {ny} xnx xny | tri≈ ¬a refl ¬c = subst (λ k → x o< k ) nexto≡ xny
|
|
270 nn<omax {x} {nx} {ny} xnx xny | tri> ¬a ¬b c = subst (λ k → x o< k ) nexto≡ xnx
|
|
271
|
|
272 record OrdinalSubset (maxordinal : Ordinal) : Set (suc n) where
|
|
273 field
|
|
274 os→ : (x : Ordinal) → x o< maxordinal → Ordinal
|
|
275 os← : Ordinal → Ordinal
|
|
276 os←limit : (x : Ordinal) → os← x o< maxordinal
|
|
277 os-iso← : {x : Ordinal} → os→ (os← x) (os←limit x) ≡ x
|
|
278 os-iso→ : {x : Ordinal} → (lt : x o< maxordinal ) → os← (os→ x lt) ≡ x
|
|
279
|
|
280 module o≤-Reasoning {n : Level} (O : Ordinals {n} ) where
|
|
281
|
|
282 -- open inOrdinal O
|
|
283
|
|
284 resp-o< : _o<_ Respects₂ _≡_
|
|
285 resp-o< = resp₂ _o<_
|
|
286
|
|
287 trans1 : {i j k : Ordinal} → i o< j → j o< osuc k → i o< k
|
|
288 trans1 {i} {j} {k} i<j j<ok with osuc-≡< j<ok
|
|
289 trans1 {i} {j} {k} i<j j<ok | case1 refl = i<j
|
|
290 trans1 {i} {j} {k} i<j j<ok | case2 j<k = ordtrans i<j j<k
|
|
291
|
|
292 trans2 : {i j k : Ordinal} → i o< osuc j → j o< k → i o< k
|
|
293 trans2 {i} {j} {k} i<oj j<k with osuc-≡< i<oj
|
|
294 trans2 {i} {j} {k} i<oj j<k | case1 refl = j<k
|
|
295 trans2 {i} {j} {k} i<oj j<k | case2 i<j = ordtrans i<j j<k
|
|
296
|
|
297 open import Relation.Binary.Reasoning.Base.Triple
|
|
298 (Preorder.isPreorder OrdPreorder)
|
|
299 ordtrans --<-trans
|
|
300 (resp₂ _o<_) --(resp₂ _<_)
|
|
301 (λ x → ordtrans x <-osuc ) --<⇒≤
|
|
302 trans1 --<-transˡ
|
|
303 trans2 --<-transʳ
|
|
304 public
|
|
305 -- hiding (_≈⟨_⟩_)
|
|
306
|