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

root / profinite_adj.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
(* Copyright (c) 2014, Robert Dockins *)

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 plotkin.
Require Import joinable.
Require Import approx_rels.
Require Import profinite.
Require Import cpo.

(**  * Adjoint relation between the pointed and unpointed domains.

     Here we define the lifing and forgetful functors between pointed
     and unpointed domains, and show that they are adjoint.

     In addition, I show the counit of this adjunction has a partial inverse,
     which is a useful operation for "strictifying" a nonstrict hom.

     NOTE!! The naming convention here is opposite that of the companion
     paper.  Here the forgetful functor goes from unpointed domains to pointed
     domains, and the lifing functor goes from pointed domains to unpointed
     domains.
  *)

Program Definition plotkin_forget (A:preord)
  (Heff:effective_order A)
  (HA:plotkin_order false A) : plotkin_order true A

    := norm_plt A Heff true _.
Next Obligation.
  repeat intro. exists (mub_closure HA X).
  split.
  intros. apply mub_clos_incl; auto.
  split.
  hnf. hnf in Hinh.
  destruct Hinh as [x ?].
  exists x. apply mub_clos_incl; auto.
  repeat intro.
  generalize (mub_clos_mub HA X M).
  intros. 
  destruct (mub_complete HA M z).
  hnf; auto.
  hnf; intros.
  apply H in H1.
  apply finsubset_elem in H1. destruct H1; auto.
  intros. rewrite <- H2; auto.
  destruct H1.
  exists x. split.
  destruct H1; auto.
  apply finsubset_elem.
  intros. rewrite <- H3; auto.
  split; auto.
  apply H0; auto.
  hnf; auto.
  hnf; intros.
  apply H in H3.
  apply finsubset_elem in H3.
  destruct H3; auto.
  intros. rewrite <- H4; auto.
Qed.

Definition forgetPLT_ob (X:ob PLT) : ob ∂PLT :=
  PLT.Ob _ (PLT.carrier _ X) (PLT.Class _ _
    (Preord.mixin (PLT.ord X))
    (PLT.effective X)
    (plotkin_forget _ (PLT.effective X) (PLT.plotkin X))).

Program Definition forgetPLT_map (X Y:ob PLT) (f:X → Y) 
  : forgetPLT_ob X → forgetPLT_ob Y :=

  PLT.Hom _ (forgetPLT_ob X) (forgetPLT_ob Y) 
    (@PLT.hom_rel _ X Y f) (PLT.hom_order _ X Y f) _.
Next Obligation.
  repeat intro. apply (PLT.hom_directed _ _ _ f); hnf; auto.
Qed.

Program Definition forgetPLT : functor PLT ∂PLT :=
  Functor PLT ∂PLT forgetPLT_ob forgetPLT_map _ _ _.
Solve Obligations of forgetPLT using auto.

Definition liftPPLT_ob (X:ob ∂PLT) : ob PLT :=
  PLT.Ob _ (option (PLT.carrier _ X)) (PLT.Class _ _
    (lift_mixin (PLT.ord X)) 
    (effective_lift (PLT.effective X)) 
    (lift_plotkin _ _ _  (PLT.plotkin X) (PLT.effective X))).

Definition liftPPLT_rel (X Y:preord) (HX:effective_order X) (f:erel X Y)
  : erel (lift X) (lift Y) :=
  union2 (union2 (single (None,None))
    (image (mk_pair (liftup X) (const (@None Y))) (eff_enum X HX)))
    (image (pair_map (liftup X) (liftup Y)) f).

Lemma liftPPLT_rel_elem X Y HX f :
  forall x y, (x,y) ∈ liftPPLT_rel X Y HX f <->
    (y ≈ None \/ exists a b, (a,b) ∈ f /\ x ≈ Some a /\ y ≈ Some b).
Proof.
  unfold liftPPLT_rel.
  intuition.
  apply union2_elem in H. destruct H.
  apply union2_elem in H. destruct H.
  apply single_axiom in H.
  left.
  destruct H as [[??][??]]; split; auto.
  apply image_axiom2 in H.
  destruct H as [q [??]].
  simpl in H0.
  left.
  destruct H0 as [[??][??]]; split; auto.
  apply image_axiom2 in H.
  destruct H as [[p q] [??]].
  right.
  simpl in H0.
  exists p. exists q.
  split; auto.
  destruct H0 as [[??][??]]; split; split; auto.
  apply union2_elem.
  left.
  apply union2_elem.
  destruct x.
  right.
  apply image_axiom1'.
  simpl. exists c. split; auto.
  split; split; auto.
  apply eff_complete.
  left.
  apply single_axiom.
  split; split; auto.
  destruct H0 as [a [b [?[??]]]].
  apply union2_elem. right.
  apply image_axiom1'.
  exists (a,b). split; auto.
  simpl.
  split; split; auto.
Qed.  

Program Definition liftPPLT_map (X Y:ob ∂PLT) (f:X → Y) 
  : liftPPLT_ob X → liftPPLT_ob Y :=

  PLT.Hom _ (liftPPLT_ob X) (liftPPLT_ob Y)
     (liftPPLT_rel (PLT.ord X) (PLT.ord Y) (PLT.effective X) (@PLT.hom_rel _ X Y f))
      _ _.
Next Obligation.
  intros. simpl in *.
  apply liftPPLT_rel_elem.
  apply (liftPPLT_rel_elem (PLT.ord X) (PLT.ord Y)) in H1.
  destruct H1. left.
  rewrite H1 in H0.
  split; auto. red; simpl; auto.
  destruct H1 as [a [b [?[??]]]].
  destruct y'.
  right.
  rewrite H2 in H.
  destruct x'.
  exists c0. exists c.
  split; auto.
  apply PLT.hom_order with a b; auto.
  rewrite H3 in H0. auto.
  elim H.
  left; auto.
Qed.
Next Obligation.
  repeat intro.
  set (M' := unlift_list M).
  case_eq M'; intros.
  exists None.
  split.
  red; intros.
  destruct x0; auto.
  destruct H1 as [q [??]].
  destruct q.
  assert (List.In c0 M').
  apply in_unlift. auto.
  rewrite H0 in H3. elim H3.
  auto.
  apply erel_image_elem.
  apply liftPPLT_rel_elem.
  auto.
  destruct x.
  destruct (PLT.hom_directed _ _ _ f c0 M').
  exists c. rewrite H0. apply cons_elem; auto.
  red; intros.
  destruct H1 as [q [??]].
  apply in_unlift in H1.
  assert (Some a ∈ M).
  exists (Some q); split; auto.
  apply H in H3.
  apply erel_image_elem in H3.
  apply (liftPPLT_rel_elem (PLT.ord X) (PLT.ord Y)) in H3.
  destruct H3.
  destruct H3. elim H3.
  destruct H3 as [m [n [?[??]]]].
  apply erel_image_elem.
  apply PLT.hom_order with m n; auto.
  destruct H1.
  exists (Some x).
  split.
  red; intros.
  destruct x0.
  apply erel_image_elem in H2.
  apply H1.
  destruct H3 as [q [??]].
  destruct q.
  exists c2; split; auto.
  apply in_unlift; auto.
  destruct H4. elim H4.
  red; auto.
  apply erel_image_elem in H2.  
  apply erel_image_elem.  
  apply liftPPLT_rel_elem.
  right; eauto.
  assert (Some c ∈ M).
  exists (Some c). split; auto.
  apply in_unlift.
  fold M'. rewrite H0. simpl; auto.
  apply H in H1.
  apply erel_image_elem in H1.
  apply (liftPPLT_rel_elem (PLT.ord X) (PLT.ord Y)) in H1.
  destruct H1.
  destruct H1. elim H1.
  destruct H1 as [a [b [?[??]]]].
  destruct H2. elim H4.
Qed.

Program Definition liftPPLT : functor ∂PLT PLT :=
  Functor ∂PLT PLT liftPPLT_ob liftPPLT_map _ _ _.
Next Obligation.
  simpl; intros.
  split; hnf; simpl; intros.
  destruct a as [a a'].
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)) in H0.
  destruct H0.
  apply ident_elem. rewrite H0. red; simpl; auto.
  apply ident_elem. 
  destruct H0 as [p [q [?[??]]]].
  rewrite H1. rewrite H2.  
  destruct H. red in H. simpl in H.
  apply H in H0.
  apply ident_elem in H0. auto.
  destruct a as [a a'].
  apply ident_elem in H0.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)).
  destruct a'; auto.
  right.
  destruct a. 2: elim H0.
  exists c0. exists c.  
  split; auto.
  destruct H. apply H1.
  simpl. apply ident_elem. auto.
Qed.
Next Obligation.
  intros.
  split; hnf; simpl; intros.
  destruct a as [a c].
  apply compose_elem.
  apply liftPPLT_map_obligation_1.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel h)) in H0.
  destruct H0.
  exists None.
  split.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel g)).
  auto.
  apply (liftPPLT_rel_elem _ _ (PLT.effective B) (PLT.hom_rel f)).
  auto.
  destruct H0 as [a' [c' [?[??]]]].  
  destruct H.
  apply H in H0.
  apply PLT.compose_hom_rel in H0.
  destruct H0 as [b' [??]].
  exists (Some b').
  split.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel g)).
  right.
  eauto.
  apply (liftPPLT_rel_elem _ _ (PLT.effective B) (PLT.hom_rel f)).
  right. eauto.

  destruct a as [a c].
  apply PLT.compose_hom_rel in H0.
  destruct H0 as [b [??]]. simpl in b.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel g)) in H0.
  apply (liftPPLT_rel_elem _ _ (PLT.effective B) (PLT.hom_rel f)) in H1.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel h)).
  destruct H1; auto.
  destruct H0.
  destruct H1 as [?[?[?[??]]]].
  rewrite H0 in H2. destruct H2. elim H4.
  right.  
  destruct H0 as [x [y [?[??]]]].
  destruct H1 as [x' [y' [?[??]]]].
  rewrite H3 in H4.
  exists x. exists y'.
  split; auto.
  destruct H. apply H6.
  simpl. apply compose_elem.
  apply PLT.hom_order.
  exists y.
  split; auto.
  apply PLT.hom_order with x' y'; auto.
Qed.
Next Obligation.
  intros.  
  split; hnf; simpl; intros.
  destruct a as [a b].
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)) in H0.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel g)).
  destruct H0; auto.    
  right.
  destruct H0 as [p [q [?[??]]]].
  exists p. exists q. split; auto.
  destruct H. apply H; auto.
  destruct a as [a b].
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel g)) in H0.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)).
  destruct H0; auto.    
  right.
  destruct H0 as [p [q [?[??]]]].
  exists p. exists q. split; auto.
  destruct H. apply H3; auto.
Qed.

Definition adj_unit_rel (X:preord) (HX:effective_order X) : erel X (lift X) :=
 union2
    (image (mk_pair (id(X)) (const None)) (eff_enum X HX))
    (image (pair_map (id(X)) (liftup X))
      (esubset_dec _ (fun q => fst q ≥ snd q)
                  (fun q => eff_ord_dec X HX (snd q) (fst q))
                  (eprod (eff_enum X HX)
                         (eff_enum X HX)))).

Lemma adj_unit_rel_elem X HX x x' :
  (x,x') ∈ adj_unit_rel X HX <-> Some x ≥ x'.
Proof.
  unfold adj_unit_rel.
  split; intros.
  apply union2_elem in H.
  destruct H.
  apply image_axiom2 in H.
  destruct H as [y [??]].
  simpl in H0.
  destruct H0. destruct H0.
  transitivity (@None X); auto.
  red; simpl; auto.
  apply image_axiom2 in H.
  destruct H as [y [??]].
  simpl in H0.
  apply esubset_dec_elem in H.
  destruct H.
  destruct H0. destruct H0.
  transitivity (Some (snd y)); auto.
  transitivity (Some (fst y)); auto.
  destruct H2. auto.
  intros.
  destruct H1 as [[??][??]].
  transitivity (snd x0); auto.
  transitivity (fst x0); auto.
  apply union2_elem.
  destruct x'.
  right.
  apply image_axiom1'.
  simpl. exists (x,c).
  split; auto.
  apply esubset_dec_elem.
  intros.
  destruct H0 as [[??][??]].
  transitivity (snd x0); auto.
  transitivity (fst x0); auto.
  split; auto.
  apply eprod_elem. split; apply eff_complete.
  left.
  apply image_axiom1'.
  simpl. exists x. split; auto. apply eff_complete.
Qed.

Program Definition adj_unit_hom (X:ob PLT) 
  : X → (liftPPLT (forgetPLT X))

  := PLT.Hom _ X (liftPPLT (forgetPLT X)) (adj_unit_rel (PLT.ord X) (PLT.effective X)) _ _.
Next Obligation.
  intros.
  apply adj_unit_rel_elem in H1.
  apply adj_unit_rel_elem.
  transitivity y; auto.
  transitivity (Some x); auto.
Qed.
Next Obligation.
  repeat intro.
  exists (Some x).
  split.
  red; intros.
  apply H in H0.
  apply erel_image_elem in H0.
  apply adj_unit_rel_elem in H0. auto.
  apply erel_image_elem.
  apply adj_unit_rel_elem.
  auto.
Qed.

Program Definition adj_unit : nt id(PLT) (liftPPLT ∘ forgetPLT)
  := NT id(PLT) (liftPPLT ∘ forgetPLT) adj_unit_hom _.
Next Obligation.
  simpl; intros.
  split; hnf; simpl; intros.
  destruct a as [a b].
  apply PLT.compose_hom_rel in H.
  destruct H as [b' [??]].
  simpl in H0.
  apply adj_unit_rel_elem in H0.
  apply PLT.compose_hom_rel.
  simpl.
  exists (Some a).
  split.
  apply adj_unit_rel_elem. auto.
  rewrite (liftPPLT_rel_elem _ _ _ (PLT.hom_rel f)).
  destruct b; auto.
  right.
  exists a. exists c.
  split; auto.
  apply PLT.hom_order with a b'; auto.
  
  destruct a as [a b].
  apply PLT.compose_hom_rel in H.
  simpl in H.
  destruct H as [a' [??]].
  apply adj_unit_rel_elem in H.
  apply PLT.compose_hom_rel.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)) in H0.
  destruct H0.
  destruct (PLT.hom_directed _ _ _ f a nil).  
  red; simpl; auto.
  red; simpl; intros. apply nil_elem in H1. elim H1.
  destruct H1. apply erel_image_elem in H2.
  exists x. split; auto.
  apply adj_unit_rel_elem; auto.
  rewrite H0. red; simpl; auto.
  destruct H0 as [p [q [?[??]]]].
  exists q. split; auto.
  apply PLT.hom_order with p q; auto.
  rewrite H1 in H. auto.
  apply adj_unit_rel_elem. auto.
Qed.

Definition adj_counit_rel (Y:ob ∂PLT) 
  : erel (forgetPLT (liftPPLT Y)) Y :=

    (image (pair_map (liftup Y) (id(PLT.ord Y)))
      (esubset_dec _ (fun q => fst q ≥ snd q)
                  (fun q => eff_ord_dec Y (PLT.effective Y) (snd q) (fst q))
                  (eprod (eff_enum Y (PLT.effective Y))
                         (eff_enum Y (PLT.effective Y))))).

Lemma adj_counit_rel_elem Y : forall y y',
  (y,y') ∈ adj_counit_rel Y <-> y ≥ Some y'.
Proof.
  unfold adj_counit_rel.
  intuition.
  apply image_axiom2 in H.
  destruct H as [[p q] [??]].
  apply esubset_dec_elem in H. destruct H.
  simpl in H0.
  destruct H0 as [[??][??]]. simpl in *.
  transitivity (Some q); auto.
  transitivity (Some p); auto.
  intros. destruct H1 as [[??][??]].
  transitivity (snd x); auto.  
  transitivity (fst x); auto.  
  
  apply image_axiom1'.
  destruct y.
  exists (c,y'). split; simpl; auto.
  apply esubset_dec_elem.
  intros. destruct H0 as [[??][??]].
  transitivity (snd x); auto.  
  transitivity (fst x); auto.  
  split; auto.
  apply eprod_elem. split; apply eff_complete.
  elim H.
Qed.

Program Definition adj_counit_hom Y : forgetPLT (liftPPLT Y) → Y :=
  PLT.Hom _ (forgetPLT (liftPPLT Y)) Y (adj_counit_rel Y) _ _.
Next Obligation.
  intros.
  apply adj_counit_rel_elem in H1.
  apply adj_counit_rel_elem.
  transitivity (Some y); auto.
  transitivity x; auto.  
Qed.  
Next Obligation.
  repeat intro.
  destruct x.
  exists c.
  split.
  red; intros.
  apply H in H0.
  apply image_axiom2 in H0.
  destruct H0 as [[p q] [??]].
  apply esubset_dec_elem in H0.
  destruct H0.
  simpl in H1, H2. 
  rewrite H1.
  apply adj_counit_rel_elem in H0.
  rewrite H2 in H0. auto.
  simpl; intros.
  destruct H2 as [[??][??]]; auto.
  transitivity (fst x0); auto.
  apply erel_image_elem.
  apply adj_counit_rel_elem. auto.

  destruct Hinh as [q ?].
  apply H in H0.
  apply erel_image_elem in H0.
  apply adj_counit_rel_elem in H0.
  elim H0.
Qed.

Program Definition adj_counit : nt (forgetPLT ∘ liftPPLT) id(∂PLT)
  := NT (forgetPLT ∘ liftPPLT) id(∂PLT) adj_counit_hom _.
Next Obligation.
  intros.
  split; hnf; simpl; intros.
  destruct a as [a b].
  apply PLT.compose_hom_rel in H; simpl.
  simpl in H.
  destruct H as [b' [??]].
  apply (adj_counit_rel_elem B) in H0.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)) in H.
  destruct H.
  rewrite H in H0. elim H0.
  destruct H as [p [q [?[??]]]].  
  apply PLT.compose_hom_rel.
  rewrite H2 in H0.
  exists p.
  split.
  apply adj_counit_rel_elem.
  rewrite H1; auto.
  apply PLT.hom_order with p q; auto.

  destruct a as [a b].
  apply PLT.compose_hom_rel in H; simpl.
  destruct H as [a' [??]].  
  apply adj_counit_rel_elem in H.
  destruct a. 2: elim H.
  apply PLT.compose_hom_rel. simpl.
  exists (Some b).
  split.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)).
  right.
  exists c. exists b. split; auto.
  apply (PLT.hom_order _ _ _ f) with a' b; auto.
  apply adj_counit_rel_elem. auto.
Qed.

Program Definition adj_counit_inv_hom Y : Y → forgetPLT (liftPPLT Y) :=
  PLT.Hom _ Y (forgetPLT (liftPPLT Y)) (adj_unit_rel (PLT.ord Y) (PLT.effective Y)) _ _.
Next Obligation.
  intros.
  apply adj_unit_rel_elem in H1.
  apply adj_unit_rel_elem.
  transitivity y; auto.
  transitivity (Some x); auto.
Qed.
Next Obligation.
  repeat intro.
  exists (Some x).
  split.
  red; intros.
  apply H in H0.
  apply erel_image_elem in H0.
  apply adj_unit_rel_elem in H0. auto.
  apply erel_image_elem.
  apply adj_unit_rel_elem.
  auto.
Qed.

Lemma adj_counit_inv_ntish : forall A B f,
  adj_counit_inv_hom B ∘ f ≤ forgetPLT·liftPPLT·f ∘ adj_counit_inv_hom A.
Proof.
  intros. hnf; simpl; intros.
  destruct a as [a b].
  apply PLT.compose_hom_rel in H.
  apply PLT.compose_hom_rel. simpl.
  exists (Some a). split.
  apply adj_unit_rel_elem; auto.
  apply (liftPPLT_rel_elem _ _ (PLT.effective A) (PLT.hom_rel f)).
  destruct H as [y [??]].
  simpl in H0.
  apply adj_unit_rel_elem in H0.
  destruct b; auto.
  right.
  exists a. exists c. split; auto.
  apply PLT.hom_order with a y; auto.
Qed.

Lemma adj_counit_inv_le Y : adj_counit_inv_hom Y ∘ adj_counit Y ≤ id.
Proof.
  hnf; simpl; intros.
  destruct a as [y y'].
  apply PLT.compose_hom_rel in H.
  destruct H as [y'' [??]].
  apply adj_counit_rel_elem in H.
  simpl in H0.
  apply adj_unit_rel_elem in H0. 
  apply ident_elem.
  transitivity (Some y''); auto.
Qed.

Lemma adj_counit_inv_largest Y : forall f,
  f ∘ adj_counit Y ≤ id -> f ≤ adj_counit_inv_hom Y.
Proof.
  repeat intro; simpl in *.
  destruct a.
  apply adj_unit_rel_elem.
  assert ((Some c, o) ∈ PLT.hom_rel (f ∘ adj_counit_hom Y)).
  apply (PLT.compose_hom_rel _ _ _ _ (adj_counit_hom Y) f).
  exists c. split; auto.
  apply adj_counit_rel_elem. auto.
  apply H in H1.
  simpl in H1.
  apply ident_elem in H1. auto.
Qed.

Lemma adj_counit_inv_eq Y : adj_counit Y ∘ adj_counit_inv_hom Y ≈ id.
Proof.
  split; hnf; simpl; intros.
  destruct a as [y y'].
  apply PLT.compose_hom_rel in H.
  simpl in H.
  destruct H as  [y'' [??]].
  apply adj_unit_rel_elem in H.
  apply ident_elem.
  rewrite (adj_counit_rel_elem Y) in H0.
  destruct y''.
  transitivity c; auto.
  elim H0.

  destruct a as [y y'].
  apply ident_elem in H.
  apply PLT.compose_hom_rel.
  exists (Some y').
  split.
  apply adj_unit_rel_elem. auto.
  apply adj_counit_rel_elem; auto.
Qed.


Lemma adj_inv_eq : forall A B (f:A → liftPPLT B),
  (forall a, exists b, (a, Some b) ∈ PLT.hom_rel f) ->
  adj_counit_inv_hom B ∘ adj_counit B ∘ forgetPLT·f ≈ forgetPLT·f.
Proof.
  intros. split.
  transitivity (id ∘ forgetPLT·f).
  apply PLT.compose_mono. auto.
  apply adj_counit_inv_le.
  rewrite (cat_ident2 ∂PLT). auto.
  hnf. intros [x y] H0.
  apply PLT.compose_hom_rel.
  destruct y.
  exists (Some c). split; auto.
  apply PLT.compose_hom_rel.
  exists c. split.
  apply adj_counit_rel_elem. auto.
  apply adj_unit_rel_elem. auto.
  destruct (H x) as [y ?].
  exists (Some y). split; auto.
  apply PLT.compose_hom_rel.
  exists y. split.
  apply adj_counit_rel_elem. auto.
  apply adj_unit_rel_elem. hnf. auto.
Qed.

Lemma adj_inv_eq_converse : forall A B (f:A → liftPPLT B),
  adj_counit_inv_hom B ∘ adj_counit B ∘ forgetPLT·f ≥ forgetPLT·f ->
  (forall a, exists b, (a, Some b) ∈ PLT.hom_rel f).
Proof.
  repeat intro.
  destruct (PLT.hom_directed false A (liftPPLT B) f a nil).
  hnf; auto.
  red; intros. apply nil_elem in H0. elim H0.
  destruct H0 as [_ ?].
  apply erel_image_elem in H0.
  generalize (H _ H0).
  intros.
  rewrite (PLT.compose_hom_rel true _ _ _
    (forgetPLT·f) 
    (adj_counit_inv_hom B ∘ adj_counit B)
    a x) in H1.
  destruct H1 as [q [??]].
  simpl in H1.
  apply PLT.compose_hom_rel in H2.
  destruct H2 as [y [??]].
  simpl in H2.
  apply adj_counit_rel_elem in H2.
  destruct q.
  eauto.
  elim H2.
Qed.


Program Definition PLT_adjoint : adjunction forgetPLT liftPPLT :=
  Adjunction forgetPLT liftPPLT adj_unit adj_counit _ _.
Next Obligation.
  split; hnf; simpl; intros.
  destruct a as [a a'].
  apply ident_elem. 
  apply PLT.compose_hom_rel in H; simpl in *.
  destruct H as [y [??]].  
  apply adj_unit_rel_elem in H.
  apply (adj_counit_rel_elem (forgetPLT_ob A)) in H0.
  change (Some a' ≤ Some a).
  transitivity y; auto.

  destruct a as [a a'].
  apply ident_elem in H.
  apply PLT.compose_hom_rel; simpl in *.
  exists (Some a).
  split.
  apply adj_unit_rel_elem. auto.
  apply (adj_counit_rel_elem (forgetPLT_ob A)).
  auto.  
Qed.
Next Obligation.
  split; hnf; simpl; intros.
  destruct a as [a a'].
  apply ident_elem. 
  apply PLT.compose_hom_rel in H; simpl in *.
  destruct H as [y [??]].  
  apply adj_unit_rel_elem in H.
  apply (liftPPLT_rel_elem _ _ (PLT.effective _) (adj_counit_rel A)) in H0.
  destruct H0.
  rewrite H0. red; simpl; auto.
  destruct H0 as [p [q [?[??]]]].
  rewrite H2.
  apply (adj_counit_rel_elem A) in H0.
  transitivity p; auto.
  rewrite H1 in H. auto.
  
  destruct a as [a a'].
  apply ident_elem in H.  
  apply PLT.compose_hom_rel; simpl in *.
  exists (Some a).  
  split.
  apply adj_unit_rel_elem. auto.
  apply (liftPPLT_rel_elem _ _ (PLT.effective _) (adj_counit_rel A)).
  destruct a'; auto.
  right.
  destruct a.
  simpl.
  exists (Some c0). exists c.
  split; auto.
  apply (adj_counit_rel_elem A). auto.
  elim H.  
Qed.

Notation U := liftPPLT.
Notation L := forgetPLT.
Notation ε := (adj_counit _).
Notation η := (adj_unit _).
Notation γ := (adj_counit_inv_hom _).

Definition plt_hom_adj (X:PLT) (Y:∂PLT) (f:X → U Y) : L X → Y 
  := ε ∘ L·f.
 
Definition plt_hom_adj' (X:PLT) (Y:∂PLT) (f:L X → Y) : X → U Y
  := U·f ∘ η.

Arguments plt_hom_adj [X Y] f.
Arguments plt_hom_adj' [X Y] f.

Notation Ψ := plt_hom_adj.
Notation "Ψ⁻¹" := plt_hom_adj'.

Lemma plt_hom_adj1 (X:PLT) (Y:∂PLT) (f:X → U Y) : Ψ⁻¹ (Ψ f) ≈ f.
Proof.
  unfold plt_hom_adj, plt_hom_adj'.
  rewrite (Functor.compose U). 2: reflexivity.
  rewrite <- (cat_assoc PLT).
  rewrite <- (NT.axiom adj_unit f).
  rewrite (cat_assoc PLT).
  generalize (Adjunction.adjoint_axiom2 PLT_adjoint Y); simpl; intros.
  rewrite H. apply cat_ident2.
Qed.

Lemma plt_hom_adj2 (X:PLT) (Y:∂PLT) (f:L X → Y) : Ψ (Ψ⁻¹ f) ≈ f.
Proof.
  unfold plt_hom_adj, plt_hom_adj'.
  rewrite (Functor.compose L). 2: reflexivity.
  rewrite (cat_assoc ∂PLT).
  rewrite (NT.axiom adj_counit f).
  rewrite <- (cat_assoc ∂PLT).
  generalize (Adjunction.adjoint_axiom1 PLT_adjoint X); simpl; intros.
  rewrite H. apply cat_ident1.
Qed.

Lemma U_mono : forall (X Y:ob ∂PLT) (f f':X → Y),
  f ≤ f' -> U·f ≤ U·f'.
Proof.
  repeat intro; simpl in *.
  destruct a as [x y].
  apply (liftPPLT_rel_elem _ _ _ (PLT.hom_rel f)) in H0.
  apply (liftPPLT_rel_elem _ _ _ (PLT.hom_rel f')).
  destruct H0; auto. right.
  destruct H0 as [a [b [?[??]]]].
  exists a. exists b. split; auto.
Qed.  

Lemma U_reflects : forall (X Y:ob ∂PLT) (f f':X → Y),
  U·f ≤ U·f' -> f ≤ f'.
Proof.
  repeat intro; simpl in *.
  destruct a as [x y].
  assert ((Some x, Some y) ∈ (PLT.hom_rel (liftPPLT_map X Y f))).
  simpl.
  apply (liftPPLT_rel_elem _ _ _ (PLT.hom_rel f)).
  right. exists x. exists y. split; auto.
  apply H in H1.
  simpl in H1.
  apply (liftPPLT_rel_elem _ _ _ (PLT.hom_rel f')) in H1.
  destruct H1.
  destruct H1. elim H1.
  destruct H1 as [a [b [?[??]]]].
  apply member_eq with (a,b); auto.
  split; split; auto.
Qed.

Lemma L_mono : forall (X Y:ob PLT) (f f':X → Y),
  f ≤ f' -> L·f ≤ L·f'.
Proof.
  auto.
Qed.

Lemma L_reflects : forall (X Y:ob PLT) (f f':X → Y),
  L·f ≤ L·f' -> f ≤ f'.
Proof.
  auto.
Qed.

Lemma Psi_mono (X:PLT) (Y:∂PLT) (f g:X → U Y) :
  f ≤ g -> Ψ f ≤ Ψ g.
Proof.
  unfold plt_hom_adj. intros.
  apply PLT.compose_mono; auto.
Qed.


Lemma Psi_inv_mono (X:PLT) (Y:∂PLT) (f g:L X → Y) :
  f ≤ g -> Ψ⁻¹ f ≤ Ψ⁻¹ g.
Proof.
  unfold plt_hom_adj'. intros.
  apply PLT.compose_mono; auto.
  apply U_mono. auto.
Qed.

Lemma Psi_reflects (X:PLT) (Y:∂PLT) (f g:X → U Y) :
  Ψ f ≤ Ψ g -> f ≤ g.
Proof.
  intros.
  rewrite <- (plt_hom_adj1 X Y f).
  rewrite <- (plt_hom_adj1 X Y g).
  apply Psi_inv_mono; auto.
Qed.

Lemma Psi_inv_reflects (X:PLT) (Y:∂PLT) (f g:L X → Y) :
  Ψ⁻¹ f ≤ Ψ⁻¹ g -> f ≤ g.
Proof.
  intros.
  rewrite <- (plt_hom_adj2 X Y f).
  rewrite <- (plt_hom_adj2 X Y g).
  apply Psi_mono; auto.
Qed.

Lemma U_bottom_least (X:PLT) (Y:∂PLT) (f:X → U Y) :
  Ψ⁻¹ ⊥ ≤ f.
Proof.
  intros.
  apply Psi_reflects.
  rewrite plt_hom_adj2.
  apply bottom_least.
Qed.

Instance lift_plt_pointed (X:PLT) (Y:∂PLT) : 
  pointed (PLT.homset_cpo _ X (liftPPLT Y)) :=
  { bottom := Ψ⁻¹ ⊥
  ; bottom_least := U_bottom_least X Y
  }.

Program Definition lift_unit : 1 → L 1
  := PLT.Hom true 1 (L 1) (ident_rel effective_unit) _ _.
Next Obligation.        
  intros. eapply ident_ordering; eauto.
Qed.
Next Obligation.
  intros. apply ident_image_dir.
Qed.
 
Program Definition lift_unit' : L 11
  := PLT.Hom true (L 1) 1 (ident_rel effective_unit) _ _.
Next Obligation.        
  intros. eapply ident_ordering; eauto.
Qed.
Next Obligation.
  intros. apply ident_image_dir.
Qed.

Lemma lift_unit_id1 : lift_unit ∘ lift_unit' ≈ id.
Proof.
  split; hnf; intros.
  destruct a. destruct c. destruct c0.
  simpl. apply ident_elem. auto.
  destruct a. destruct c. destruct c0.
  apply PLT.compose_hom_rel. exists tt.
  split; simpl; apply ident_elem; auto.
Qed.

Lemma lift_unit_id2 : lift_unit' ∘ lift_unit ≈ id.
Proof.
  split; hnf; intros.
  destruct a. destruct c. destruct c0.
  simpl. apply ident_elem. auto.
  destruct a. destruct c. destruct c0.
  apply PLT.compose_hom_rel. exists tt.
  split; simpl; apply ident_elem; auto.
Qed.

Program Definition lift_prod (A B:PLT) : (L A ⊗ L B) → L (A × B)
  := PLT.Hom true (L A ⊗ L B) (L (A × B))
          (ident_rel (effective_prod (PLT.effective A) (PLT.effective B)))
          _ _.
Next Obligation.  
  intros. eapply ident_ordering; eauto.
Qed.
Next Obligation.
  intros. apply ident_image_dir.
Qed.

Program Definition lift_prod' (A B:PLT) : L (A × B) → L A ⊗ L B 
  := PLT.Hom true (L (A × B)) (L A ⊗ L B)
          (ident_rel (effective_prod (PLT.effective A) (PLT.effective B)))
          _ _.
Next Obligation.  
  intros. eapply ident_ordering; eauto.
Qed.
Next Obligation.
  intros. apply ident_image_dir.
Qed.

Lemma lift_prod_id1 A B : lift_prod A B ∘ lift_prod' A B ≈ id.
Proof.
  split; hnf; intros.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]].
  simpl in *. apply ident_elem in H. apply ident_elem in H0.
  apply ident_elem. transitivity q; auto.
  destruct a.
  apply PLT.compose_hom_rel.
  simpl. exists c0.
  simpl in *. apply ident_elem in H.
  split; apply ident_elem; auto.
Qed.

Lemma lift_prod_id2 A B : lift_prod' A B ∘ lift_prod A B ≈ id.
Proof.
  split; hnf; intros.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]].
  simpl in *. apply ident_elem in H. apply ident_elem in H0.
  apply ident_elem. transitivity q; auto.
  destruct a.
  apply PLT.compose_hom_rel.
  simpl. exists c0.
  simpl in *. apply ident_elem in H.
  split; apply ident_elem; auto.
Qed.

Local Transparent PLT.pair.

Lemma lift_prod_pair C A B (f:C → A) (g:C → B) :
  lift_prod A B ∘ 《L·f, L·g》 ≈ L·〈f, g〉.
Proof.
  split; hnf; intros.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]].
  simpl in H0.
  apply ident_elem in H0.
  revert H. simpl.
  simpl.
  apply pair_rel_ordering; auto.
  apply PLT.hom_order.
  apply PLT.hom_order.
  destruct a.
  apply PLT.compose_hom_rel.
  exists c0.  
  split. auto.
  simpl. apply ident_elem. auto.
Qed.

Lemma lift_prod_pair' C A B (f:C → A) (g:C → B) :
  《L·f, L·g》 ≈ lift_prod' A B ∘ L·〈f, g〉.
Proof.
  split; hnf; intros.
  destruct a.
  apply PLT.compose_hom_rel.
  exists c0.  
  split. auto.
  simpl. apply ident_elem. auto.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]].
  simpl in H0.
  apply ident_elem in H0.
  simpl.
  destruct c0. destruct q.
  apply (pair_rel_elem _ _ _ _ _ _ c c0 c1).
  simpl in H.
  rewrite (pair_rel_elem _ _ _ _ _ _ c c2 c3) in H.
  destruct H. destruct H0. simpl in *. split.
  eapply (PLT.hom_order _ _ _ f); eauto.
  eapply (PLT.hom_order _ _ _ g); eauto.
Qed.

Lemma lift_prod_natural A B C D (f:A → B) (g:C → D) :
  lift_prod B D ∘ PLT.pair_map (L·f) (L·g) ≈ L·(PLT.pair_map f g) ∘ lift_prod A C.
Proof.
  split; hnf; intros.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]]. destruct q.
  apply PLT.compose_hom_rel.
  exists c. split.
  simpl. apply ident_elem. auto.
  simpl in H0.
  apply ident_elem in H0.
  apply PLT.hom_order with c (c1,c2); auto.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]]. 
  apply PLT.compose_hom_rel.
  exists c0. split.
  apply PLT.hom_order with q c0; auto.
  simpl in H. apply ident_elem in H. auto.
  simpl. apply ident_elem. auto.
Qed.

Lemma lift_prod'_natural A B C D (f:A → B) (g:C → D) :
   PLT.pair_map (L·f) (L·g) ∘ lift_prod' _ _ ≈ lift_prod' _ _ ∘ L·(PLT.pair_map f g).
Proof.
  split; hnf; intros.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]]. destruct q.
  apply PLT.compose_hom_rel.
  exists c0. split.
  simpl in H. apply ident_elem in H.
  apply PLT.hom_order with (c1,c2) c0; auto.
  simpl. apply ident_elem. auto.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]]. 
  apply PLT.compose_hom_rel.
  exists c. split.
  simpl. apply ident_elem; auto.
  apply PLT.hom_order with c q; auto.
  simpl in H0. apply ident_elem in H0. auto.
Qed.

Arguments lift_prod [A B].
Arguments lift_prod' [A B].



Section strictify.
  Variables X Y:ob ∂PLT.
  Variable f: U X → U Y.  

  Definition strictify := ε ∘ L·f ∘ γ.

  Lemma f_explode : U·(ε ∘ L·f) ∘ η ≈ f.
  Proof.
    apply plt_hom_adj1.
  Qed.

  Lemma strictify_le : U·strictify ≤ f.
  Proof.  
    unfold strictify.
    rewrite Functor.compose. 2: reflexivity.
    rewrite <- f_explode at 2.
    apply PLT.compose_mono.

    generalize (Adjunction.adjoint_axiom2 PLT_adjoint).
    intro.
    generalize (H X).
    intros.
    transitivity (U·adj_counit_inv_hom X ∘ id (U X)).
    rewrite (cat_ident1 _ _ _ (U·adj_counit_inv_hom X)). auto.
    rewrite <- H0.
    simpl.
    rewrite (cat_assoc _ _ _ _ _ (U·adj_counit_inv_hom X)).
    rewrite <- (Functor.compose U). 2: reflexivity.
    transitivity (id ∘ adj_unit_hom (U X)).
    apply PLT.compose_mono. auto.
    transitivity (U·(id (L(U(X))))).
    apply U_mono.
    apply adj_counit_inv_le.
    rewrite Functor.ident; auto.
    rewrite (cat_ident2 _ _ _ (adj_unit_hom _)). auto.
    auto.        
  Qed.    

  Lemma strictify_largest : forall q, U·q ≤ f -> q ≤ strictify.
  Proof.
    intros.
    unfold strictify.
    transitivity (adj_counit Y ∘ L·U·q ∘ adj_counit_inv_hom X).
    transitivity (adj_counit Y ∘ adj_counit_inv_hom Y ∘ q).
    rewrite (adj_counit_inv_eq Y).
    rewrite (cat_ident2 _ _ _ q). auto.
    rewrite <- (cat_assoc _ _ _ _ _ (adj_counit Y)).
    rewrite <- (cat_assoc _ _ _ _ _ (adj_counit Y)).
    apply PLT.compose_mono; auto.
    apply adj_counit_inv_ntish. 
    rewrite <- (cat_assoc _ _ _ _ _ (adj_counit Y)).
    rewrite <- (cat_assoc _ _ _ _ _ (adj_counit Y)).
    apply PLT.compose_mono; auto.
    apply PLT.compose_mono; auto.
  Qed.
End strictify.

Lemma U_hom_rel (A B:∂PLT) (f:A → B) (a:U A) (b:U B) :
  (a,b) ∈ PLT.hom_rel (U·f) <->
  (b = None \/ exists a' b', (a',b') ∈ PLT.hom_rel f /\ a = Some a' /\ b = Some b').
Proof.
  simpl. split; intros.
  rewrite  (liftPPLT_rel_elem _ _ _ _ a b) in H.
  destruct H.
  destruct b; auto.
  destruct H. elim H.
  destruct H as [p [q [?[??]]]].
  right.
  destruct a.
  destruct b.
  exists c. exists c0. split; auto.
  revert H. apply PLT.hom_order; auto.
  destruct H1. elim H2.
  destruct H0. elim H2.
  apply liftPPLT_rel_elem.
  destruct H. subst b; auto.
  destruct H as [p [q [?[??]]]].
  subst a b.
  right.   eauto.
Qed.

Lemma L_hom_rel (A B:PLT) (f:A → B) (a:L A) (b:L B) :
  (a,b) ∈ PLT.hom_rel (L·f) <-> (a,b) ∈ PLT.hom_rel f.
Proof.
  split; auto.
Qed.

Definition lift (X:PLT) : PLT := U (L X).
Definition colift (X:∂PLT) : ∂PLT := L (U X).

Definition smash_prod (A B:∂PLT) : U A × U B → U (A ⊗ B)
  := U·(PLT.pair_map ε ε ∘ lift_prod') ∘ η.

Definition unsmash_prod (A B:∂PLT) : U (A ⊗ B) → U A × U B
  := 〈 U·π₁, U·π₂ 〉.


Inductive smash_prod_spec (A B:∂PLT) :  U A × U B -> U (A ⊗ B) -> Prop :=
  | smash_some : forall x x' y y',
         x' ≤ x -> y' ≤ y ->
         smash_prod_spec A B (Some x, Some y) (Some (x',y'))
  | smash_none : forall m, smash_prod_spec A B m None.


Lemma smash_prod_iff (A B:∂PLT) m n :
  (m,n) ∈ PLT.hom_rel (smash_prod A B) <-> smash_prod_spec A B m n.
Proof.
  unfold smash_prod. split; intro.
  apply PLT.compose_hom_rel in H.
  destruct H as [y [??]].
  simpl in H. apply adj_unit_rel_elem in H.
  apply U_hom_rel in H0.
  destruct H0.
  subst n.
  apply smash_none.
  destruct H0 as [a' [b' [?[??]]]]. subst y n.
  apply PLT.compose_hom_rel in H0.
  destruct H0 as [q [??]].
  unfold PLT.pair_map in H1.
  destruct b'.
  rewrite (PLT.pair_hom_rel true _ _ _ _ _ q c c0) in H1.
  destruct H1.
  destruct m.
  destruct H. simpl in *.
  destruct a'. simpl in *.
  apply ident_elem in H0.
  apply PLT.compose_hom_rel in H1.
  apply PLT.compose_hom_rel in H2.
  destruct H1 as [q1 [??]].
  destruct H2 as [q2 [??]].
  simpl in H4. simpl in H5.
  apply adj_counit_rel_elem in H4.
  apply adj_counit_rel_elem in H5.
  destruct q.
  simpl in *.
  apply (pi1_rel_elem  _ _ _ _ o1 o2 q1) in H1.
  apply (pi2_rel_elem  _ _ _ _ o1 o2 q2) in H2.
  destruct H0. simpl in *.
  assert (Some c ≤ c1).  
  rewrite H4. rewrite H1. rewrite H0. auto.
  assert (Some c0 ≤ c2).
  rewrite H5. rewrite H2. rewrite H6. auto.
  destruct c1. destruct c2.
  apply smash_some; auto.
  elim H8. elim H7.
  
  inversion H. subst.
  apply PLT.compose_hom_rel.
  exists (Some (Some x, Some y)).
  split. simpl.
  apply adj_unit_rel_elem. auto.
  apply U_hom_rel. right.
  exists (Some x, Some y).
  exists (x',y'). split; auto.
  apply PLT.compose_hom_rel.
  simpl.
  exists (Some x, Some y).
  split. apply ident_elem. auto.
  apply PLT.pair_hom_rel. split.
  apply PLT.compose_hom_rel.
  exists (Some x). split.
  simpl. apply pi1_rel_elem. auto.
  simpl. apply adj_counit_rel_elem. auto.
  apply PLT.compose_hom_rel.
  exists (Some y). split.
  simpl. apply pi2_rel_elem. auto.
  simpl. apply adj_counit_rel_elem. auto.
  subst m0 n.
  apply PLT.compose_hom_rel.
  exists None.
  split. simpl.
  apply adj_unit_rel_elem. hnf. auto.
  apply U_hom_rel. auto.
Qed.


Lemma smash_unsmash (A B:∂PLT) :
  smash_prod A B ∘ unsmash_prod A B ≈ id.
Proof.
  split; hnf; intros.
  destruct a.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]].
  rewrite smash_prod_iff in H0.
  destruct q.
  unfold unsmash_prod in H.
  rewrite (PLT.pair_hom_rel _ _ _ _ _ _ c c1 c2) in H. destruct H.
  apply U_hom_rel in H.
  apply U_hom_rel in H1.
  simpl. apply ident_elem.
  inversion H0; subst.
  destruct H1. discriminate.
  destruct H. discriminate.
  destruct H1 as [?[?[?[??]]]].
  destruct H as [?[?[?[??]]]].
  rewrite H2 in H5. inversion H5. subst x0.
  inversion H3.   subst x1.
  subst c.
  destruct x2.
  inversion H7. subst x3.
  simpl in H.
  apply (pi1_rel_elem _ _ _ _ c c0 x) in H.
  simpl in H1.
  apply (pi2_rel_elem _ _ _ _ c c0 y) in H1.
  split; simpl.
  rewrite H4. auto.
  rewrite H6. auto.
  hnf. auto.

  destruct a.
  simpl in H. apply ident_elem in H.
  apply PLT.compose_hom_rel.
  destruct c.
  destruct c.
  exists (Some c, Some c1).
  split.
  unfold unsmash_prod.
  apply PLT.pair_hom_rel.
  split.
  apply U_hom_rel.
  right.
  exists (c,c1). exists c.
  split; auto.
  simpl. apply pi1_rel_elem. auto.
  apply U_hom_rel.
  right.
  exists (c,c1). exists c1.
  split; auto.
  simpl. apply pi2_rel_elem. auto.
  apply smash_prod_iff.
  destruct c0.
  destruct c0.
  destruct H. apply smash_some; auto.
  apply smash_none.
  destruct c0. elim H.
  exists (None,None).
  split.
  unfold unsmash_prod.
  apply PLT.pair_hom_rel.
  split; apply U_hom_rel; auto.
  apply smash_prod_iff.
  apply smash_none.  
Qed.

Lemma unsmash_smash (A B:∂PLT) :
  unsmash_prod A B ∘ smash_prod A B ≤ id.
Proof.
  hnf; intros. destruct a. simpl. apply ident_elem.
  apply PLT.compose_hom_rel in H.
  destruct H as [q [??]].
  apply smash_prod_iff in H.
  unfold unsmash_prod in H0.
  destruct c0.
  apply (PLT.pair_hom_rel _ _ _ _ _ _ q c0 c1) in H0.
  destruct H0.
  apply U_hom_rel in H0.
  apply U_hom_rel in H1.
  destruct c.
  destruct H0. destruct H1. subst.
  split; hnf; auto.
  subst c0. split; simpl. hnf; auto.
  destruct H1 as [?[?[?[??]]]].
  subst.
  inversion H; subst.
  simpl in H0.
  rewrite (pi2_rel_elem _ _ _ _ x' y' x0) in H0.
  transitivity (Some y'); auto.
  destruct H1. subst c1.
  split; simpl. 2: hnf; auto.
  destruct H0 as [?[?[?[??]]]].
  subst. inversion H; subst.
  simpl in H0.
  rewrite (pi1_rel_elem _ _ _ _ x' y' x0) in H0.
  transitivity (Some x'); auto.
  destruct H0 as [?[?[?[??]]]].
  destruct H1 as [?[?[?[??]]]].
  subst.
  inversion H4; subst.
  inversion H; subst.
  simpl in *.
  rewrite (pi1_rel_elem _ _ _ _ x' y' x0) in H0.
  rewrite (pi2_rel_elem _ _ _ _ x' y' x2) in H1.
  split; simpl.
  transitivity (Some x'); auto.
  transitivity (Some y'); auto.
Qed.


Global Opaque liftPPLT.
Global Opaque forgetPLT.