A Coq library for domain theory (http://rwd.rdockins.name/domains/)

root / fixes.v

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
(* Copyright (c) 2014, Robert Dockins *)

Require Import String.
Require Import List.
Require Import Setoid.

Require Import basics.
Require Import preord.
Require Import categories.
Require Import sets.
Require Import finsets.
Require Import esets.
Require Import effective.
Require Import directed.
Require Import plotkin.
Require Import joinable.
Require Import approx_rels.
Require Import cpo.
Require Import profinite.
Require Import profinite_adj.

(** * A fixpoint operator for nonstrict functions in PLT.
  *)

Program Definition precompose hf (A B C:PLT.PLT hf) (f:A → B) :
  (Preord.hom (PLT.hom_ord hf B C) (PLT.hom_ord hf A C)) := 
  Preord.Hom (PLT.hom_ord hf B C) (PLT.hom_ord hf A C) 
     (fun g => g ∘ f) _.
Next Obligation.
  intros. apply PLT.compose_mono; auto.
Qed.
Arguments precompose [hf A B] C f.

Program Definition postcompose hf (A B C:PLT.PLT hf) (g:B → C) :
  (Preord.hom (PLT.hom_ord hf A B) (PLT.hom_ord hf A C)) :=
  Preord.Hom (PLT.hom_ord hf A B) (PLT.hom_ord hf A C) 
      (fun f => g ∘ f) _.
Next Obligation.
  intros. apply PLT.compose_mono; auto.
Qed.
Arguments postcompose [hf] A [B C] g.

Lemma precompose_continuous hf (A B C:PLT.PLT hf) (f:A → B) :
  continuous (directed_hf_cl hf) (precompose C f).
Proof.
  apply CPO.continuous_sup.
  repeat intro. destruct a as [a c].
  unfold precompose in H.
  apply PLT.compose_hom_rel in H.
  destruct H as [y [??]].
  simpl in H0.
  apply union_axiom in H0. destruct H0 as [q [??]].
  apply image_axiom2 in H0. destruct H0 as [q' [??]].
  simpl in H2.
  apply union_axiom.
  exists (PLT.hom_rel (precompose C f q')).
  split. apply image_axiom1'.
  exists (precompose C f q').
  split; auto.
  apply image_axiom1'.
  exists q'. split; auto.
  unfold precompose.
  apply PLT.compose_hom_rel.
  exists y. split; auto.
  rewrite <- H2; auto.
Qed.

Lemma postcompose_continuous hf (A B C:PLT.PLT hf) (g:B → C) :
  continuous (directed_hf_cl hf) (postcompose A g).
Proof.
  apply CPO.continuous_sup.
  repeat intro. destruct a as [a c].
  unfold postcompose in H.
  apply PLT.compose_hom_rel in H.
  destruct H as [y [??]].
  simpl in H.
  apply union_axiom in H. destruct H as [q [??]].
  apply image_axiom2 in H. destruct H as [q' [??]].
  simpl in H2.
  apply union_axiom.
  exists (PLT.hom_rel (postcompose A g q')).
  split. apply image_axiom1'.
  exists (postcompose A g q').
  split; auto.
  apply image_axiom1'.
  exists q'. split; auto.
  unfold postcompose.
  apply PLT.compose_hom_rel.
  exists y. split; auto.
  rewrite <- H2; auto.
Qed.

Program Definition pair_right hf (A B C:PLT.PLT hf) (f:C → A) :
  (Preord.hom (PLT.hom_ord hf C B) (PLT.hom_ord hf C (PLT.prod A B))) := 
  Preord.Hom (PLT.hom_ord hf C B) (PLT.hom_ord hf C (PLT.prod A B)) 
  (fun g => PLT.pair f g) _.
Next Obligation.
  intros. apply PLT.pair_mono; auto.
Qed.
Arguments pair_right [hf A] B [C] f.

Program Definition pair_left hf (A B C:PLT.PLT hf) (g:C → B) :
  (Preord.hom (PLT.hom_ord hf C A) (PLT.hom_ord hf C (PLT.prod A B))) := 
  Preord.Hom (PLT.hom_ord hf C A) (PLT.hom_ord hf C (PLT.prod A B)) 
  (fun f => PLT.pair f g) _.
Next Obligation.
  intros. apply PLT.pair_mono; auto.
Qed.
Arguments pair_left [hf] A [B C] g.

Lemma pair_right_continuous hf (A B C:PLT.PLT hf) (f:C → A) :
  continuous (directed_hf_cl hf) (pair_right B f).
Proof.
  apply CPO.continuous_sup.
  repeat intro. destruct a as [c [a b]].
  unfold pair_right in H.  
  simpl in H.
  rewrite (PLT.pair_hom_rel _ _ _ _ _ _ c a b) in H.
  destruct H.
  simpl in H0.
  apply union_axiom in H0. destruct H0 as [q [??]].
  apply image_axiom2 in H0. destruct H0 as [q' [??]].
  simpl in H2.
  apply union_axiom.
  exists (PLT.hom_rel (pair_right B f q')).
  split.
  apply image_axiom1'. 
  exists (pair_right B f q'). split; auto.
  apply image_axiom1'.  exists q'. split; auto.
  simpl.
  apply PLT.pair_hom_rel. split; auto.
  rewrite <- H2; auto.
Qed.

Lemma pair_left_continuous hf (A B C:PLT.PLT hf) (g:C → B) :
  continuous (directed_hf_cl hf) (pair_left A g).
Proof.
  apply CPO.continuous_sup.
  repeat intro. destruct a as [c [a b]].
  unfold pair_right in H.  
  simpl in H.
  rewrite (PLT.pair_hom_rel _ _ _ _ _ _ c a b) in H.
  destruct H.
  simpl in H.
  apply union_axiom in H. destruct H as [q [??]].
  apply image_axiom2 in H. destruct H as [q' [??]].
  simpl in H2.
  apply union_axiom.
  exists (PLT.hom_rel (pair_left A g q')).
  split.
  apply image_axiom1'. 
  exists (pair_left A g q'). split; auto.
  apply image_axiom1'.  exists q'. split; auto.
  simpl.
  apply PLT.pair_hom_rel. split; auto.
  rewrite <- H2; auto.
Qed.

Section fixes.
  Variable Γ:PLT.
  Variable A:∂PLT.
  Variable f:Γ → U A ⇒ U A.

  Definition fixes_step
    (x:Γ → U A) : Γ → U A :=

    apply ∘ 〈f, x〉.

  Program Definition fixes_step' :
    PLT.homset_cpo _ Γ (U A) → PLT.homset_cpo _ Γ (U A) :=

    CPO.Hom _ (PLT.homset_cpo _ Γ (U A)) (PLT.homset_cpo _ Γ (U A)) 
    fixes_step _ _.
  Next Obligation.
    intros. unfold fixes_step.
    apply PLT.compose_mono; auto.
    apply PLT.pair_mono; auto.    
  Qed.    
  Next Obligation.
    red; intros.
    unfold fixes_step.
    apply continuous_equiv with
      (postcompose Γ PLT.app ∘ pair_right (U A) f); auto.
    hnf; simpl; intros. split; auto.
    apply continuous_sequence.
    apply postcompose_continuous.
    apply pair_right_continuous.
  Qed.

  Definition fixes : Γ → U A := lfp fixes_step'.

  Lemma fixes_unroll :
    fixes ≈ apply ∘ 〈f, fixes〉.
  Proof.
    unfold fixes at 1.
    rewrite <- lfp_fixpoint. simpl. unfold fixes_step.
    auto.
  Qed.

End fixes.
Arguments fixes [Γ A] f.


Lemma fixes_mono Γ A (f g:Γ → U A ⇒ U A) : 
  f ≤ g -> fixes f ≤ fixes g.
Proof.
  intro. unfold fixes at 1.
  apply scott_induction.
  red. split. apply bottom_least.
  intros. 
  apply CPO.sup_is_least.
  red; intros. apply H1; auto.
  intros. rewrite <- H0; auto.
  simpl; intros. unfold fixes_step.
  rewrite fixes_unroll.
  apply PLT.compose_mono; auto.
  apply PLT.pair_mono; auto.
Qed.

Lemma fixes_eq Γ A (f g:Γ → U A ⇒ U A) : 
  f ≈ g -> fixes f ≈ fixes g.
Proof.
  intros [??]; split; apply fixes_mono; auto.
Qed.

Add Parametric Morphism Γ A :
  (@fixes Γ A)
  with signature (Preord.ord_op _ ==> Preord.ord_op _)
  as fixes_le_morphism.
Proof.
  intros. apply fixes_mono. auto.
Qed.

Add Parametric Morphism Γ A :
  (@fixes Γ A)
  with signature (eq_op _ ==> eq_op _)
  as fixes_morphism.
Proof.
  intros. apply fixes_eq. auto.
Qed.

Lemma plt_bot_None A B x y :
  (x,y) ∈ PLT.hom_rel (⊥ : A → U B) <-> y = None.
Proof.
  split; intros.
  simpl in H.
  unfold plt_hom_adj' in H.
  apply PLT.compose_hom_rel in H.
  destruct H as [?[??]].
  simpl in H.
  apply adj_unit_rel_elem in H.
  apply U_hom_rel in H0.
  destruct H0; auto.
  destruct H0 as [?[?[??]]].
  simpl in H0.
  apply union_axiom in H0.
  destruct H0 as [?[??]].
  apply image_axiom2 in H0.
  destruct H0 as [?[??]].
  apply empty_elem in H0. elim H0.

  subst y.
  simpl.
  unfold plt_hom_adj'.
  apply PLT.compose_hom_rel.
  exists None.
  split. simpl.
  apply adj_unit_rel_elem.
  hnf; auto.
  apply U_hom_rel. auto.
Qed.

Lemma plt_bot_chomp A B C (g:A → B) :
  (⊥ : B → U C) ∘ g ≈ ⊥.
Proof.
  split. 2: apply bottom_least.
  hnf. intros.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [?[??]].
  apply plt_bot_None in H0.
  apply plt_bot_None. auto.
Qed.  

Lemma fixes_compose_commute Γ Γ' A (f:Γ → U A ⇒ U A) (g:Γ' → Γ) :
  fixes f ∘ g ≈ fixes (f ∘ g).
Proof.
  split; unfold fixes at 1; apply scott_induction.
  red; split.
  rewrite plt_bot_chomp.
  apply bottom_least.
  intros.
  transitivity (∐(image (precompose (U A) g) XS)).
  destruct (CPO.continuous_sup _ _ _ (precompose (U A) g)).
  apply H1.
  apply (precompose_continuous false _ _ (U A) g).
  apply CPO.sup_is_least.
  red; intros.
  apply image_axiom2 in H1.
  destruct H1 as [q [??]].
  rewrite H2. simpl.
  apply H0. auto.
  intros. rewrite <- H. auto.
  simpl; intros.
  unfold fixes_step.
  rewrite fixes_unroll.
  rewrite <- (cat_assoc PLT).
  apply PLT.compose_mono; auto.
  rewrite (PLT.pair_compose_commute false).
  apply PLT.pair_mono; auto.
  
  red; split.
  apply bottom_least.
  intros.
  apply CPO.sup_is_least.
  red; intros.
  apply H0; auto.
  intros.
  rewrite <- H; auto.
  simpl; intros.
  unfold fixes_step.
  rewrite fixes_unroll.
  rewrite <- (cat_assoc PLT).
  apply PLT.compose_mono; auto.
  rewrite (PLT.pair_compose_commute false).
  apply PLT.pair_mono; auto.
Qed.