-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodensecat.v
148 lines (121 loc) · 3.16 KB
/
codensecat.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
#[global]
Set Primitive Projections.
#[global]
Unset Printing Primitive Projection Parameters.
#[global]
Set Universe Polymorphism.
#[global]
Set Default Goal Selector "!".
Require Import Coq.Unicode.Utf8.
Require Import Coq.Program.Tactics.
Require Import Coq.Strings.String.
Require Import Coq.Lists.List.
Import IfNotations.
Import ListNotations.
#[universes(cumulative)]
Record span A B := {
s: Type ;
π1: s → A ;
π2: s → B ;
}.
Arguments s {A B}.
Arguments π1 {A B}.
Arguments π2 {A B}.
Definition id A: span A A :=
{|
s := A ;
π1 x := x ;
π2 x := x ;
|}.
Definition compose {A B C} (f: span B C) (g: span A B): span A C :=
{|
s := { xy | π1 f (fst xy) = π2 g (snd xy) } ;
π1 xy := π1 g (snd (proj1_sig xy)) ;
π2 xy := π2 f (fst (proj1_sig xy)) ;
|}.
Infix "∘" := compose (at level 30).
Inductive ext {A B} (F: span A B): A → B → Type :=
| sup (x: s F): ext F (π1 F x) (π2 F x).
Definition tag {A B} {F: span A B} {C D} (e: ext F C D) :=
let '(sup _ x) := e in
x.
(* dependent product basically
should be like Ran P Q A B = forall x, P(x, A) → Q(x, B)
x <- P -> A
———-
x <- Q -> B
*)
Record Ran {C D E} (F: span C D) (G: span C E) := {
x: D ;
y: E ;
p A: ext F A x → ext G A y ;
}.
Arguments x {C D E F G}.
Arguments y {C D E F G}.
Arguments p {C D E F G}.
#[program]
Definition ran {C D E} (F: span C D) (G: span C E): span D E :=
{|
s := Ran F G ;
π1 r := x r ;
π2 r := y r ;
|}.
Notation "[ A , B ]" := (ran A B).
Definition codensity {A B} (F: span A B) := [F, F].
Definition codensity_id {A B} (F: span A B) (x: B): ext (codensity F) x x.
Proof.
cbn in *.
refine (sup (codensity F) {| x := x ; y := x |}).
intros.
apply X.
Defined.
Definition codensity_compose {K L} {F: span K L} {A B C}: ext (codensity F) B C → ext (codensity F) A B → ext (codensity F) A C.
Proof.
intros f g.
destruct f as [f].
cbn in *.
(* A little odd finagling here is required *)
remember (x f) as B'.
destruct g as [g].
cbn in *.
refine (sup (codensity F) {| x := x g ; y := y f |}).
intros.
apply (p f).
rewrite <- HeqB'.
apply (p g).
auto.
Defined.
Definition eval {A B} (F: span A B) (G: span A B): s ([ F , G ] ∘ F) → s G.
Proof.
cbn in *.
intros [[[?] ?] ?].
cbn in *.
refine (tag (p0 _ _)).
Unshelve.
2: {
apply (π1 F s0).
}
subst.
apply (sup F s0).
Defined.
(* Garbage prototype *)
Inductive term :=
| var (x: string)
| lam (x: string) (e: term)
| app (e0 e1: term).
Inductive rule :=
| var_rule (n: nat) (x: string)
| lam_rule (n: nat) (x: string) (e: term)
| app_rule (n: nat) (e0 e1: term)
.
Definition vars (r: rule): nat * term :=
match r with
| var_rule n x => (S n, var x)
| lam_rule n x e => (n, lam x e)
| app_rule n e0 e1 => (n, app e0 e1)
end.
Definition Vars := {| π1 x := fst (vars x) ; π2 x := snd (vars x) |}.
Definition VARS := ext (codensity Vars).
Definition VARS_id: ∀ x, VARS x x := codensity_id Vars.
Definition VARS_compose {A B C}: VARS B C → VARS A B → VARS A C := @codensity_compose _ _ Vars _ _ _.
Definition VARS_rule {x y} (p: ∀ A, ext Vars A x → ext Vars A y): VARS _ _ := sup (codensity Vars) {| p := p |}.