-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnominal.v
1853 lines (1674 loc) · 47.8 KB
/
nominal.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
(* Copyright (c) 2014, Robert Dockins *)
Require Import Setoid.
Require Import basics.
Require Import categories.
Require Import preord.
Require Import sets.
Require Import finsets.
Require Import atoms.
Require Import permutations.
(** * The category of nominal types
*)
Obligation Tactic := intuition.
Require Import List.
Module Nominal.
Record mixin_of (A:Type) (eq_mixin:Eq.mixin_of A) :=
Mixin
{ Aeq := Eq.Pack A eq_mixin
; papp : perm -> Aeq -> Aeq
; support : Aeq -> finset atom
; nom_ident : forall a, papp id a ≈ a
; nom_comp : forall a p1 p2,
papp p1 (papp p2 a) ≈ papp (p1 ∘ p2) a
; papp_respects : forall p p' a a',
p ≈ p' -> a ≈ a' -> papp p a ≈ papp p' a'
; support_axiom : forall (p:perm) a,
(forall v, v ∈ support a -> v ∈ Perm.support p -> False) ->
papp p a ≈ a
; support_papp : forall (p:perm) x v,
v ∈ support x <-> p v ∈ support (papp p x)
}.
Record ob :=
Ob
{ carrier :> Type
; eq_mixin : Eq.mixin_of carrier
; nominal_mixin : mixin_of carrier eq_mixin
}.
Definition papp_op (A:ob) : perm -> A -> A :=
papp (carrier A) (eq_mixin A) (nominal_mixin A).
Definition support_op (A:ob) : A -> finset atom :=
support (carrier A) (eq_mixin A) (nominal_mixin A).
Canonical Structure nom_support (A:ob) : supported :=
Supported A (support_op A).
Canonical Structure ob_eq (A:ob) : Eq.type :=
Eq.Pack (carrier A) (eq_mixin A).
Record hom (A B:ob) :=
Hom
{ map :> carrier A -> carrier B
; eq_axiom : forall x y, x ≈ y -> map x ≈ map y
; equivariant : forall x (p:perm),
map (papp_op A p x) ≈ papp_op B p (map x)
}.
Program Definition ident (A:ob) :=
Hom A A (fun x => x) _ _.
Program Definition compose (A B C:ob) (f:hom B C) (g:hom A B) :=
Hom A C (fun x => f (g x)) _ _.
Next Obligation.
apply eq_axiom.
apply eq_axiom.
auto.
Qed.
Next Obligation.
transitivity (f (papp_op B p (g x))).
apply eq_axiom.
apply equivariant.
apply equivariant.
Qed.
Definition comp_mixin : Comp.mixin_of ob hom :=
Comp.Mixin ob hom ident compose.
Canonical Structure comp := Comp.Pack ob hom comp_mixin.
Program Definition hom_eq_mixin (A B:ob) : Eq.mixin_of (hom A B) :=
Eq.Mixin (hom A B) (fun f g => forall x, f x ≈ g x) _ _ _.
Next Obligation.
simpl; intros; rewrite H; auto.
Qed.
Lemma category_axioms : Category.axioms ob hom hom_eq_mixin comp_mixin.
Proof.
constructor.
repeat intro. simpl; auto.
repeat intro. simpl; auto.
repeat intro. simpl; auto.
repeat intro. simpl; auto.
transitivity (f (g' x)).
apply eq_axiom. apply H0.
apply H.
Qed.
Canonical Structure NOMINAL : category :=
Category ob hom hom_eq_mixin comp_mixin category_axioms.
Canonical Structure eq (A:ob) : Eq.type := Eq.Pack (carrier A) (eq_mixin A).
Canonical Structure hom_eq (A B:ob) : Eq.type := Eq.Pack (hom A B) (hom_eq_mixin A B).
End Nominal.
Notation NOMINAL := Nominal.NOMINAL.
Notation nominal := Nominal.ob.
Canonical Structure NOMINAL.
Canonical Structure Nominal.nom_support.
Canonical Structure Nominal.eq.
Canonical Structure Nominal.hom_eq.
Canonical Structure Nominal.comp.
Coercion Nominal.carrier : Nominal.ob >-> Sortclass.
Coercion Nominal.map : Nominal.hom >-> Funclass.
Notation "p · x" := (Nominal.papp_op _ p x) (at level 35, right associativity).
Add Parametric Morphism (A B:nominal) :
(Nominal.map A B)
with signature (eq_op (Nominal.hom_eq A B)) ==>
(eq_op (Nominal.eq A)) ==>
(eq_op (Nominal.eq B))
as nom_map_morphism.
Proof.
intros.
transitivity (x y0).
apply Nominal.eq_axiom. auto.
apply H.
Qed.
Add Parametric Morphism (A:nominal) :
(Nominal.papp_op A)
with signature (@eq_op (Perm.eq tt tt)) ==>
(@eq_op (Nominal.eq A)) ==>
(@eq_op (Nominal.eq A))
as papp_morphism.
Proof.
intros. apply Nominal.papp_respects; auto.
Qed.
Lemma nom_compose (A:nominal) (p1 p2:perm) (x:A) :
p1 · p2 · x ≈ (p1 ∘ p2) · x.
Proof.
apply Nominal.nom_comp.
Qed.
Lemma nom_compose' (A:nominal) (p p1 p2:perm) (x:A) :
p1 ∘ p2 ≈ p ->
p1 · p2 · x ≈ p · x.
Proof.
intros. rewrite nom_compose. rewrite H. auto.
Qed.
Lemma nom_ident (A:nominal) (x:A) :
id·x ≈ x.
Proof.
apply Nominal.nom_ident.
Qed.
Lemma nom_ident' (A:nominal) (p:perm) (x:A) :
p ≈ id(tt) ->
p·x ≈ x.
Proof.
intros. rewrite H.
apply Nominal.nom_ident.
Qed.
Lemma support_axiom (A:nominal) (p:perm) (x:A) :
x♯p -> p·x ≈ x.
Proof.
intros. apply Nominal.support_axiom. auto.
Qed.
Lemma support_axiom' (A:nominal) (p:perm) (x:A) :
x♯p -> x ≈ p·x.
Proof.
intros. symmetry. apply support_axiom. auto.
Qed.
Lemma support_papp (A:nominal) (p:perm) (x:A) (v:atom) :
v ∈ ‖x‖ <-> p v ∈ ‖p·x‖.
Proof.
intros. apply Nominal.support_papp.
Qed.
Lemma papp_inj (A:nominal) (p:perm) (x y:A) :
p·x ≈ p·y -> x ≈ y.
Proof.
intros.
cut ((p⁻¹ ∘ p) · x ≈ (p⁻¹ ∘ p) · y).
intros.
rewrite Perm.inv_id2 in H0.
rewrite nom_ident in H0.
rewrite nom_ident in H0.
auto.
rewrite <- nom_compose.
rewrite <- nom_compose.
rewrite H. auto.
Qed.
(** NOMINAL is an initialized category. *)
Program Definition initius_eq_mixin :=
Eq.Mixin False (fun _ _ => False) _ _ _.
Program Definition initius_mixin :=
Nominal.Mixin
False initius_eq_mixin
(fun p x => False_rect _ x)
(fun x => False_rect _ x)
_ _ _ _ _.
Next Obligation.
elim x. elim x.
Qed.
Canonical Structure initius :=
Nominal.Ob False initius_eq_mixin initius_mixin.
Program Definition initiate (A:nominal) : initius → A :=
Nominal.Hom initius A (fun x => False_rect _ x) _ _.
Next Obligation.
elim x.
Qed.
Next Obligation.
elim x.
Qed.
Program Definition initialized_mixin :=
Initialized.Mixin
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
initius initiate
_.
Next Obligation.
hnf. intro x. elim x.
Qed.
Canonical Structure initialized_nominal : initialized :=
Initialized
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
Nominal.comp_mixin
Nominal.category_axioms
initialized_mixin.
(** NOMINAL has binary coproducts. *)
Section nom_sum.
Variables A B:nominal.
Definition nom_sum_equiv (x y:A+B) :=
match x, y with
| inl a, inl a' => a ≈ a'
| inr b, inr b' => b ≈ b'
| _, _ => False
end.
Definition nom_sum_papp (p:perm) (x:A+B) :=
match x with
| inl a => inl (p · a)
| inr b => inr (p · b)
end.
Definition nom_sum_support (x:A+B) : finset atom :=
match x with
| inl a => ‖a‖
| inr b => ‖b‖
end.
Program Definition nom_sum_eq_mixin :=
Eq.Mixin (A+B) nom_sum_equiv _ _ _.
Next Obligation.
simpl. auto.
simpl. auto.
Qed.
Next Obligation.
simpl in *. destruct y; simpl in *; auto.
destruct y; simpl in *; auto.
Qed.
Next Obligation.
destruct z; simpl in *; eauto.
destruct z; simpl in *; eauto.
elim H.
destruct z; simpl in *; eauto.
elim H.
destruct z; simpl in *; eauto.
Qed.
Program Definition nom_sum_mixin :=
Nominal.Mixin (A+B) nom_sum_eq_mixin nom_sum_papp nom_sum_support
_ _ _ _ _.
Next Obligation.
destruct a; red; simpl; auto.
apply nom_ident.
apply nom_ident.
Qed.
Next Obligation.
destruct a; red; simpl; auto.
apply nom_compose.
apply nom_compose.
Qed.
Next Obligation.
destruct a; destruct a'; simpl in *.
red in H0; simpl in H0.
red; simpl. apply papp_morphism; auto.
red in H0; simpl in H0. elim H0.
red in H0; simpl in H0. elim H0.
red in H0; simpl in H0.
red; simpl. apply papp_morphism; auto.
Qed.
Next Obligation.
destruct a; red; simpl.
apply support_axiom.
red; simpl; intros. apply (H v); auto.
apply support_axiom.
red; simpl; intros. apply (H v); auto.
Qed.
Next Obligation.
destruct x; apply support_papp; auto.
destruct x; simpl in H;
apply support_papp in H; auto.
Qed.
Canonical Structure nom_sum : nominal :=
Nominal.Ob (A+B) nom_sum_eq_mixin nom_sum_mixin.
End nom_sum.
(** NOMINAL has colimits for directed systems. *)
Require Import directed.
Require Import cont_functors.
Section nominal_directed_colimits.
Variable I:directed_preord.
Variable DS:directed_system I NOMINAL.
Record nom_colimit_type :=
NomColim
{ nom_colim_idx : I
; nom_colim_elem : ds_F DS nom_colim_idx
}.
Definition nom_colimit_equiv (x y:nom_colimit_type) :=
exists k
(Hxk:nom_colim_idx x ≤ k)
(Hyk:nom_colim_idx y ≤ k),
ds_hom DS _ _ Hxk (nom_colim_elem x) ≈
ds_hom DS _ _ Hyk (nom_colim_elem y).
Program Definition nom_colimit_eq_mixin :=
Eq.Mixin nom_colimit_type nom_colimit_equiv _ _ _ .
Next Obligation.
exists (nom_colim_idx x).
exists (ord_refl I (nom_colim_idx x)).
exists (ord_refl I (nom_colim_idx x)).
auto.
Qed.
Next Obligation.
destruct H as [k [Hxk [Hyk ?]]].
exists k. exists Hyk. exists Hxk. symmetry.
auto.
Qed.
Next Obligation.
destruct H as [i [Hxi [Hyi ?]]].
destruct H0 as [j [Hyj [Hzj ?]]].
destruct (choose_ub I i j) as [k [Hik Hjk]].
assert (Hxk : nom_colim_idx x ≤ k). etransitivity; eauto.
assert (Hyk : nom_colim_idx y ≤ k). etransitivity; eauto.
assert (Hzk : nom_colim_idx z ≤ k). etransitivity; eauto.
exists k. exists Hxk. exists Hzk.
rewrite <- (ds_compose DS (nom_colim_idx x) i k Hxi Hik Hxk).
rewrite <- (ds_compose DS (nom_colim_idx z) j k Hzj Hjk Hzk).
simpl.
rewrite H. rewrite <- H0.
change ((ds_hom DS i k Hik ∘ ds_hom DS (nom_colim_idx y) i Hyi) (nom_colim_elem y)
≈ ((ds_hom DS j k Hjk ∘ ds_hom DS (nom_colim_idx y) j Hyj) (nom_colim_elem y))).
rewrite (ds_compose DS (nom_colim_idx y) i k Hyi Hik Hyk).
rewrite (ds_compose DS (nom_colim_idx y) j k Hyj Hjk Hyk).
auto.
Qed.
Definition nom_colimit_papp (p:perm) (x:nom_colimit_type) :=
match x with
| NomColim i x' => NomColim i (p · x')
end.
Program Definition nom_colimit_mixin :=
Nominal.Mixin
nom_colimit_type
nom_colimit_eq_mixin
nom_colimit_papp
(fun x => ‖ nom_colim_elem x ‖)
_ _ _ _ _.
Next Obligation.
destruct a as [i a]. exists i. simpl.
exists (ord_refl _ _).
exists (ord_refl _ _).
apply Nominal.eq_axiom.
apply nom_ident.
Qed.
Next Obligation.
destruct a as [i a]. exists i. simpl.
exists (ord_refl _ _).
exists (ord_refl _ _).
apply Nominal.eq_axiom.
apply nom_compose.
Qed.
Next Obligation.
destruct H0 as [k [Hk1 [Hk2 ?]]].
destruct a as [i a].
destruct a' as [j b].
simpl in *.
exists k. simpl. exists Hk1. exists Hk2.
rewrite Nominal.equivariant.
rewrite Nominal.equivariant.
apply papp_morphism; auto.
Qed.
Next Obligation.
destruct a as [i a]. simpl.
exists i.
exists (ord_refl _ _).
exists (ord_refl _ _).
simpl.
apply Nominal.eq_axiom.
apply support_axiom; auto.
Qed.
Next Obligation.
destruct x as [i x]; simpl in *.
apply support_papp. auto.
destruct x as [i x]; simpl in *.
apply support_papp in H. auto.
Qed.
Canonical Structure nom_colimit : nominal :=
Nominal.Ob nom_colimit_type nom_colimit_eq_mixin nom_colimit_mixin.
Program Definition nom_colimit_spoke (i:I) : ds_F DS i → nom_colimit :=
Nominal.Hom (ds_F DS i) nom_colimit (NomColim i) _ _.
Next Obligation.
exists i. simpl. exists (ord_refl _ _). exists (ord_refl _ _).
apply Nominal.eq_axiom. auto.
Qed.
Program Definition nom_colimit_cocone : cocone DS :=
Cocone DS nom_colimit nom_colimit_spoke _.
Next Obligation.
red; simpl. intro x.
destruct (choose_ub I i j) as [k [??]].
exists k. simpl. exists H. exists H0.
symmetry.
apply (ds_compose DS i j k Hij H0 H x).
Qed.
Section nom_colimit_univ.
Variable YC:cocone DS.
Definition nom_colimit_univ_defn (x:nom_colimit) : cocone_point YC :=
match x with
| NomColim i x' => cocone_spoke YC i x'
end.
Program Definition nom_colimit_univ : nom_colimit → cocone_point YC :=
Nominal.Hom nom_colimit (cocone_point YC) nom_colimit_univ_defn _ _.
Next Obligation.
destruct x as [i x].
destruct y as [j y].
destruct H as [k [Hk1 [Hk2 ?]]]. simpl in *.
rewrite (cocone_commute YC i k Hk1).
rewrite (cocone_commute YC j k Hk2).
simpl. apply Nominal.eq_axiom. auto.
Qed.
Next Obligation.
destruct x as [i x]. simpl.
apply Nominal.equivariant.
Qed.
Lemma nom_colimit_commute : forall i,
cocone_spoke YC i ≈ nom_colimit_univ ∘ nom_colimit_spoke i.
Proof.
intro. intro. simpl. auto.
Qed.
Lemma nom_colimit_uniq : forall (f:nom_colimit → YC),
(forall i, cocone_spoke YC i ≈ f ∘ nom_colimit_spoke i) ->
f ≈ nom_colimit_univ.
Proof.
simpl; intros. intro x.
destruct x as [i x]. simpl.
symmetry. apply H.
Qed.
End nom_colimit_univ.
Definition nom_has_colimits : directed_colimit DS nom_colimit_cocone
:= DirectedColimit DS nom_colimit_cocone
nom_colimit_univ nom_colimit_commute nom_colimit_uniq.
End nominal_directed_colimits.
(** NOMINAL has least fixpoints of continuous functors. *)
Section nominal_fixpoint.
Variable F : functor NOMINAL NOMINAL.
Variable HF : continuous_functor F.
Definition fixpoint : ob NOMINAL :=
(cont_functors.fixpoint initialized_nominal F nom_colimit_cocone).
Definition fixpoint_initial : Alg.initial_alg NOMINAL F :=
(cont_functors.fixpoint_initial
initialized_nominal F nom_colimit_cocone nom_has_colimits HF).
Definition fixpoint_iso : F fixpoint ↔ fixpoint :=
(cont_functors.fixpoint_iso
initialized_nominal F nom_colimit_cocone nom_has_colimits HF).
End nominal_fixpoint.
(** NOMINAL is a terminated category. *)
Program Definition nom_terminus_eq_mixin :=
Eq.Mixin unit (fun _ _ => True) _ _ _.
Program Definition nom_terminus_mixin :=
Nominal.Mixin unit nom_terminus_eq_mixin (fun p u => u) (fun _ => nil) _ _ _ _ _.
Next Obligation.
apply nil_elem in H. elim H.
apply nil_elem in H. elim H.
Qed.
Canonical Structure nom_terminus : nominal :=
Nominal.Ob unit nom_terminus_eq_mixin nom_terminus_mixin.
Program Definition nom_terminate (A:nominal) : A → nom_terminus :=
Nominal.Hom A nom_terminus (fun _ => tt) _ _.
Program Definition nom_terminated_mixin :=
Terminated.Mixin
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
nom_terminus nom_terminate _.
Next Obligation.
red. simpl. intros. destruct (f x). auto.
Qed.
Canonical Structure nom_terminated :=
Terminated
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
Nominal.comp_mixin
Nominal.category_axioms
nom_terminated_mixin.
(** NOMINAL is a cartesian category. *)
Program Definition nom_prod_eq_mixin (A B :nominal) :=
Eq.Mixin (A*B) (fun x y => fst x ≈ fst y /\ snd x ≈ snd y) _ _ _.
Solve Obligations with intuition eauto.
Program Definition nom_prod_mixin (A B:nominal) :=
Nominal.Mixin (A*B) (nom_prod_eq_mixin A B)
(fun p xy => (p · fst xy, p · snd xy))
(fun xy => ‖fst xy‖ ++ ‖snd xy‖)
_ _ _ _ _.
Next Obligation.
destruct a; split; simpl; apply nom_ident.
Qed.
Next Obligation.
destruct a; split; simpl; apply nom_compose.
Qed.
Next Obligation.
destruct a; destruct a'; destruct H0; split; simpl in *.
rewrite H. rewrite H0. auto.
rewrite H. rewrite H1. auto.
Qed.
Next Obligation.
destruct a; split; simpl.
apply support_axiom.
red; simpl; intros.
apply (H v); simpl; auto.
apply app_elem; auto.
apply support_axiom.
red; simpl; intros.
apply (H v); simpl; auto.
apply app_elem; auto.
Qed.
Next Obligation.
simpl.
apply app_elem in H. apply app_elem.
destruct H; [ left | right ].
apply support_papp; auto.
apply support_papp; auto.
simpl in H.
apply app_elem in H. apply app_elem.
destruct H; [ left | right ].
apply support_papp in H; auto.
apply support_papp in H; auto.
Qed.
Canonical Structure nom_prod (A B:nominal) : nominal :=
Nominal.Ob (A*B) (nom_prod_eq_mixin A B) (nom_prod_mixin A B).
Program Definition nom_pi1 (A B:nominal) : nom_prod A B → A :=
Nominal.Hom (nom_prod A B) A (fun x => fst x) _ _.
Next Obligation.
destruct H; auto.
Qed.
Program Definition nom_pi2 (A B:nominal) : nom_prod A B → B :=
Nominal.Hom (nom_prod A B) B (fun x => snd x) _ _.
Next Obligation.
destruct H; auto.
Qed.
Program Definition nom_pairing (C A B:nominal) (f:C → A) (g:C → B) : C → nom_prod A B
:= Nominal.Hom C (nom_prod A B) (fun c => (f c, g c)) _ _.
Next Obligation.
split; simpl; apply Nominal.eq_axiom; auto.
Qed.
Next Obligation.
split; simpl; apply Nominal.equivariant.
Qed.
Program Definition nom_cartesian_mixin :=
Cartesian.Mixin
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
Nominal.comp_mixin
nom_prod nom_pi1 nom_pi2 nom_pairing
_.
Next Obligation.
constructor; simpl; intros.
red; simpl; auto.
red; simpl; auto.
red; simpl; intro.
split; simpl.
rewrite <- (H x); auto.
rewrite <- (H0 x); auto.
Qed.
Canonical Structure nom_cartesian : cartesian :=
Cartesian
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
Nominal.comp_mixin
Nominal.category_axioms
nom_terminated_mixin
nom_cartesian_mixin.
(** NOMINAL is a cartesian closed category. *)
Record nom_exp_type (A B:nominal) :=
NomExp
{ exp_map :> A -> B
; exp_support : finset atom
; exp_eq_axiom : forall x y, x ≈ y -> exp_map x ≈ exp_map y
; exp_support_axiom : forall (p:perm),
(forall v, v ∈ exp_support -> v ∈ ‖p‖ -> False) ->
(forall x, p · exp_map (p⁻¹ · x) ≈ exp_map x)
}.
Program Definition exp_papp (A B:nominal) (p:perm) (f:nom_exp_type A B) :
nom_exp_type A B :=
NomExp A B
(fun x => p · f (p⁻¹ · x))
(List.map p (exp_support A B f))
_ _.
Next Obligation.
apply papp_morphism; auto.
apply exp_eq_axiom.
apply papp_morphism; auto.
Qed.
Next Obligation.
cut (forall v, v ∈ (List.map p (exp_support A B f) : finset atom) -> p0 v = v).
clear H.
induction p0 using swap_induction'; intros.
etransitivity. etransitivity. 2: apply IHp0.
apply papp_morphism; auto.
apply papp_morphism; auto.
apply exp_eq_axiom.
apply papp_morphism; auto.
apply papp_morphism; auto.
apply inv_eq; auto.
intros. rewrite H.
apply (H0 v); auto.
apply papp_morphism; auto.
rewrite nom_ident.
apply papp_morphism; auto.
apply exp_eq_axiom.
rewrite nom_compose.
apply papp_morphism; auto.
hnf; simpl; auto.
rewrite nom_compose.
rewrite <- Perm.assoc.
rewrite <- nom_compose.
rewrite swap_commute'.
rewrite <- nom_compose.
set (p' := Perm.g p u ⇋ Perm.g p v).
transitivity
(p0 · p · p' · f (p'⁻¹ · p⁻¹ · p0⁻¹ · x)).
apply papp_morphism. auto.
apply papp_morphism. auto.
apply papp_morphism. auto.
apply exp_eq_axiom.
rewrite (inv_compose _ _ _ _ p0).
rewrite <- nom_compose.
rewrite nom_compose.
symmetry.
rewrite nom_compose .
apply papp_morphism; auto.
hnf; simpl; intros.
destruct (string_dec u x0).
subst x0.
destruct (string_dec (Perm.g p u) (Perm.g p u)); auto.
elim n; auto.
destruct (string_dec (Perm.g p u) (Perm.g p x0)); auto.
apply Perm.g_inj in e. contradiction.
destruct (string_dec v x0).
destruct (string_dec (Perm.g p v) (Perm.g p x0)); auto.
elim n1. rewrite e; auto.
destruct (string_dec (Perm.g p v) (Perm.g p x0)); auto.
apply Perm.g_inj in e. contradiction.
rewrite exp_support_axiom.
apply IHp0.
intros.
apply H1 in H2.
simpl in H2.
destruct (string_dec u v0). subst v0. auto.
destruct (string_dec v v0). subst v0.
rewrite H in H2. contradiction.
auto.
simpl; intros.
unfold Support.support in H3. simpl in H3.
apply cons_elem in H3.
destruct H3.
apply atom_strong_eq in H3.
subst v0.
assert (u ∈ (List.map p (exp_support A B f) : finset atom)).
revert H2. generalize (exp_support A B f). induction c.
intros. apply nil_elem in H2. elim H2.
intros. apply cons_elem in H2. destruct H2.
apply atom_strong_eq in H2. subst a.
simpl. apply cons_elem. left.
rewrite Perm.fg. auto.
simpl. apply cons_elem. right.
apply IHc; auto.
apply H1 in H3.
simpl in H3.
destruct (string_dec u u).
rewrite <- H in H3.
apply Perm.f_inj in H3. elim H0; auto.
elim n; auto.
apply cons_elem in H3.
destruct H3.
apply atom_strong_eq in H3. subst v0.
assert (v ∈ (List.map p (exp_support A B f) : finset atom)).
revert H2. generalize (exp_support A B f). induction c.
intros. apply nil_elem in H2. elim H2.
intros. apply cons_elem in H2. destruct H2.
apply atom_strong_eq in H2. subst a.
simpl. apply cons_elem. left.
rewrite Perm.fg. auto.
simpl. apply cons_elem. right.
apply IHc; auto.
apply H1 in H3.
simpl in H3.
destruct (string_dec u v); auto.
destruct (string_dec v v); auto.
rewrite H in H3.
elim n; auto.
apply nil_elem in H3. auto.
intros.
destruct (Perm.support_axiom p0 v); auto.
elim (H v); auto.
Qed.
Program Definition nom_exp_eq_mixin (A B:nominal) :=
Eq.Mixin (nom_exp_type A B) (fun f g => forall x, f x ≈ g x) _ _ _.
Next Obligation.
simpl; intros; rewrite H; auto.
Qed.
Canonical Structure nom_exp_eq (A B:nominal) :=
Eq.Pack (nom_exp_type A B) (nom_exp_eq_mixin A B).
Add Parametric Morphism (A B:nominal) :
(exp_map A B)
with signature (eq_op (nom_exp_eq A B)) ==>
(eq_op (Nominal.ob_eq A)) ==>
(eq_op (Nominal.ob_eq B))
as exp_map_morphism.
Proof.
intros.
transitivity (x y0).
apply exp_eq_axiom. auto.
apply H.
Qed.
Program Definition nom_exp_mixin (A B:nominal) :=
Nominal.Mixin
(nom_exp_type A B)
(nom_exp_eq_mixin A B)
(exp_papp A B)
(exp_support A B)
_ _ _ _ _.
Next Obligation.
hnf. simpl; intros.
rewrite nom_ident.
apply exp_eq_axiom.
transitivity (id · x).
apply papp_morphism.
hnf; simpl; auto. auto.
rewrite nom_ident. auto.
Qed.
Next Obligation.
hnf; simpl; intro; auto.
rewrite nom_compose.
apply papp_morphism; auto.
apply exp_eq_axiom.
rewrite nom_compose.
apply papp_morphism; auto.
symmetry. apply inv_compose.
Qed.
Next Obligation.
hnf; simpl. intros.
apply papp_morphism; auto.
etransitivity.
apply H0.
apply exp_eq_axiom.
apply papp_morphism; auto.
apply inv_eq. auto.
Qed.
Next Obligation.
hnf. simpl; intros.
apply exp_support_axiom. auto.
Qed.
Next Obligation.
simpl in *.
revert H. generalize (exp_support A B x). induction c.
intros. apply nil_elem in H. elim H.
intros. apply cons_elem in H. destruct H.
apply atom_strong_eq in H. subst a.
simpl. apply cons_elem. left. auto.
simpl. apply cons_elem. right.
apply IHc; auto.
simpl in *.
revert H. generalize (exp_support A B x). induction c.
intros. apply nil_elem in H. elim H.
intros. apply cons_elem in H. destruct H.
apply atom_strong_eq in H.
apply Perm.f_inj in H. subst v.
simpl. apply cons_elem. left. auto.
simpl. apply cons_elem. right.
apply IHc; auto.
Qed.
Canonical Structure nom_exp (A B:nominal) : nominal :=
Nominal.Ob
(nom_exp_type A B)
(nom_exp_eq_mixin A B)
(nom_exp_mixin A B).
Program Definition nom_curry (C A B:nominal) (f:C×A → B) : C → nom_exp A B :=
Nominal.Hom C (nom_exp A B)
(fun c => NomExp A B (fun a => f (c,a)) (‖c‖) _ _) _ _.
Next Obligation.
apply Nominal.eq_axiom. split; auto.
Qed.
Next Obligation.
rewrite <- Nominal.equivariant.
apply Nominal.eq_axiom.
split. simpl.
apply support_axiom. auto.
simpl.
rewrite nom_compose.
rewrite Perm.inv_id1.
apply nom_ident.
Qed.
Next Obligation.
hnf; simpl. intro.
apply Nominal.eq_axiom.
split; auto.
Qed.
Next Obligation.
hnf; simpl. intro.
rewrite <- Nominal.equivariant.
apply Nominal.eq_axiom.
split; simpl; auto.
rewrite nom_compose.
rewrite Perm.inv_id1.
symmetry. apply nom_ident.
Qed.
Program Definition nom_apply (A B:nominal) : nom_exp A B × A → B :=
Nominal.Hom (nom_exp A B × A) B (fun fx => fst fx (snd fx)) _ _.
Next Obligation.
destruct x; destruct y; destruct H; simpl in *.
etransitivity.
apply H.
apply exp_eq_axiom. auto.
Qed.
Next Obligation.
simpl.
apply papp_morphism. auto.
apply exp_eq_axiom.
rewrite nom_compose.
rewrite Perm.inv_id2.
apply nom_ident.
Qed.
Program Definition nom_ccc_mixin :=
CartesianClosed.Mixin
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
Nominal.comp_mixin
Nominal.category_axioms
nom_terminated_mixin
nom_cartesian_mixin
nom_exp nom_curry nom_apply
_.
Next Obligation.
constructor; simpl; intros.
red; simpl; intros.
destruct x; simpl. auto.
red; simpl; intros.
red. simpl. intros.
etransitivity. 2: apply H.
simpl. auto.
Qed.
Canonical Structure nom_ccc : cartesian_closed :=
CartesianClosed
Nominal.ob Nominal.hom
Nominal.hom_eq_mixin
Nominal.comp_mixin
Nominal.category_axioms
nom_cartesian_mixin
nom_terminated_mixin
nom_ccc_mixin.
(** Atom binding construct. *)
Inductive binding_ty (A:nominal) :=
| bind : atom -> A -> binding_ty A.
Notation "'ν' x , t" := (bind _ x t) (at level 50, format "'ν' x , t").
Definition binding_equiv (A:nominal) (x y:binding_ty A) :=
let (v, x') := x in
let (w, y') := y in
exists u:atom, u ∉ (v :: w :: ‖x'‖ ++ ‖y'‖ : finset atom) /\
u ⇋ v · x' ≈ u ⇋ w · y'.
Lemma binding_equiv_forall (A:nominal) (x y:binding_ty A) (avoid : finset atom):
binding_equiv A x y <->
let (v,x') := x in
let (w,y') := y in
forall u,
u ∉ (v :: w :: ‖x'‖ ++ ‖y'‖ : finset atom) ->
u ∉ avoid ->
u ⇋ v · x' ≈ u ⇋ w · y'.
Proof.
split; intros.
destruct x as [v x].
destruct y as [w y].
intros.
destruct H as [q [??]].
destruct (string_dec q u). subst q.
auto.
rewrite <- (support_axiom A (u ⇋ q) x).
rewrite <- (support_axiom A (u ⇋ q) y).
rewrite (Perm.swap_swap u v).
rewrite (Perm.swap_swap u w).
repeat rewrite nom_compose.
rewrite Perm.swap_swizzle; auto.
rewrite <- nom_compose.
rewrite Perm.swap_swizzle; auto.
rewrite <- nom_compose.
rewrite (Perm.swap_swap v q).
apply papp_morphism; auto.
rewrite (Perm.swap_swap w q).