-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLinearLogic.v
213 lines (174 loc) · 7.21 KB
/
LinearLogic.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
(* Encode linear logic connectives and rules. (Combines Pfenning, Power/Webster, and Gwenn-Bosser's approaches.)
Defines the notation for them and for manipulating the environment
(multiset of linear props). *)
Require Export Coq.Sets.Multiset.
Require Import Coq.Arith.EqNat.
Set Implicit Arguments.
Definition Var : Type := nat.
(* ILL connectives -- combination of those given by Pfenning + AGB's encoding *)
Inductive LinProp : Type :=
(* Atomic *)
| LProp : Var -> LinProp
(* Multiplicative *)
| Implies : LinProp -> LinProp -> LinProp (* -o *)
| Times : LinProp -> LinProp -> LinProp (* (X) *)
| One : LinProp (* Multiplicative identity TODO *)
(* Additive *)
| With : LinProp -> LinProp -> LinProp (* & *)
| Plus : LinProp -> LinProp -> LinProp (* (+) *)
| Top : LinProp (* aka True? *)
| Zero : LinProp (* Additive identity TODO *)
(* Exponentials *)
| Bang : LinProp -> LinProp.
Notation "A -o B" := (Implies A B) (at level 98, left associativity).
Notation "A ** B" := (Times A B) (at level 98, left associativity).
Notation "A && B" := (With A B) (at level 40, left associativity).
Notation "A ++ B" := (Plus A B) (at level 60, right associativity). (* watch out *)
Notation "! A" := (Bang A) (at level 98, left associativity).
Definition env : Type := multiset LinProp.
(* Equality of LinProps (needed for multisets) *)
Fixpoint eqLPC (f1 f2 : LinProp) : bool :=
match f1, f2 with
| One, One => true
| Zero, Zero => true
| Top, Top => true
| LProp v1, LProp v2 => beq_nat v1 v2
| Bang f1_1, Bang f2_1 => eqLPC f1_1 f2_1
| Implies f1_1 f1_2, Implies f2_1 f2_2 =>
andb (eqLPC f1_1 f2_1) (eqLPC f1_2 f2_2)
| Times f1_1 f1_2, Times f2_1 f2_2 =>
andb (eqLPC f1_1 f2_1) (eqLPC f1_2 f2_2)
| With f1_1 f1_2, With f2_1 f2_2 =>
andb (eqLPC f1_1 f2_1) (eqLPC f1_2 f2_2)
| _, _ => false
end.
Definition eqLinProp (f1 f2 : LinProp) :=
eqLPC f1 f2 = true. (* lift computational into propositional *)
Lemma eq_neq_LinProp : forall (f1 f2 : LinProp),
{eqLinProp f1 f2} + {~ eqLinProp f1 f2}.
Proof.
Set Printing All.
intros.
(* SearchAbout sumbool. *)
(* Print eq_nat_decide. *)
(* Print sumbool. *)
destruct f1; destruct f2; try reflexivity; try auto.
(* TODO: might need to use the "remember as" trick. anyway this is decidable *)
Admitted.
(* Things about multisets of linear props, which is how the environment is represented *)
Definition singleton := SingletonBag eqLinProp eq_neq_LinProp.
Definition inSet {A : Type} (m : multiset A) (x : A) : Prop :=
multiplicity m x > 0.
Definition setMinus (m : multiset LinProp) (e : LinProp) : multiset LinProp :=
Bag (fun (x : LinProp) => if eq_neq_LinProp e x
then multiplicity m x - 1
else multiplicity m x).
Notation "{{ Z }}" := (singleton Z) (at level 5, Z at level 99, right associativity).
Notation "S == T" := (meq S T) (at level 1, left associativity).
Notation "g1 'U' g2" := (munion g1 g2) (at level 100, right associativity).
Notation "Z :: g" := (munion (singleton Z) g) (at level 60, right associativity).
Notation "x ∈ S" := (inSet S x) (at level 60, right associativity).
Notation "S \ x" := (setMinus S x) (at level 60, right associativity).
Reserved Notation "A '|-' B" (at level 3).
(* Here, (->) (Coq implication) denotes (--------) (logic "lines") *)
(* convention: env name lowercase, prop name uppercase *)
(* gamma = classical resources; delta = linear resources (after Pfenning)
can I encode this at the type level? TODO. right now there might be problems with (!) because it doesn't distinguish *)
Inductive LinProof : env -> LinProp -> Prop :=
| Id : forall (g : env) (A : LinProp),
(g == {{A}}) ->
g |- A
(* Multiplicative connectives *)
| Impl_R : forall (g : env) (A B : LinProp),
(A :: g) |- B ->
g |- (A -o B)
(* basically, if you can prove the assump A, then you can have the conclusion B *)
| Impl_L : forall (g d1 d2 : env) (A B C : LinProp),
(A -o B) ∈ g ->
(g \ (A -o B)) == (d1 U d2) ->
d1 |- A ->
(B :: d2) |- C ->
g |- C
| Times_R : forall (g d1 d2 : env) (A B : LinProp),
g == (d1 U d2) ->
d1 |- A ->
d2 |- B ->
g |- (A ** B)
| Times_L : forall (g : env) (A B C : LinProp),
(A ** B) ∈ g ->
(A :: B :: (g \ (A ** B))) |- C ->
g |- C
| One_R : forall (g : env),
g == (EmptyBag LinProp) ->
g |- One
| One_L : forall (g : env) (C : LinProp),
One ∈ g ->
(g \ One) |- C ->
g |- C
(* Additive connectives *)
(* With = internal choice *)
| With_R : forall (g : env) (A B : LinProp),
g |- A ->
g |- B ->
g |- (A && B)
| With_L1 : forall (g : env) (A B C : LinProp),
(A && B) ∈ g ->
(A :: (g \ (A && B))) |- C ->
g |- C
| With_L2 : forall (g : env) (A B C : LinProp),
(A && B) ∈ g ->
(B :: (g \ (A && B))) |- C ->
g |- C
| Top_R : forall (g : env),
g |- Top
(* (* Plus = external choice *) *)
| Plus_R1 : forall (g : env) (A B : LinProp),
g |- A ->
g |- (A ++ B)
| Plus_R2 : forall (g : env) (A B : LinProp),
g |- B ->
g |- (A ++ B)
| Plus_L : forall (g : env) (A B C : LinProp),
(A ++ B) ∈ g ->
(A :: (g \ (A ++ B))) |- C ->
(B :: (g \ (A ++ B))) |- C ->
g |- C
| Zero_L : forall (g : env) (C : LinProp),
Zero ∈ g ->
g |- C
(* Quantifiers: included in Coq *)
(* Exponentials *)
(* TODO: implication is included in Coq *)
(* Bang_R is a rule from Pfenning (Bang_L superseded by Bang_Replace) *)
(* NOTE: the linear context has to be empty here; everything in g needs to be classical *)
| Bang_R : forall (g : env) (A : LinProp),
g |- A ->
g |- !A
| Bang_Replace : forall (g : env) (A C : LinProp),
(!A) ∈ g ->
(A :: (g \ (!A))) |- C ->
g |- C
| Bang_Replicate : forall (g : env) (A C : LinProp),
(!A) ∈ g ->
((!A) :: g) |- C ->
g |- C
| Bang_Remove : forall (g : env) (A C : LinProp),
(!A) ∈ g ->
(g \ (!A)) |- C ->
g |- C
where "x |- y" := (LinProof x y).
(* Various other ILL axioms here *)
(* Linear cut:
gamma is eliminated from pfenning's version *)
(* Need to synthesize an A *)
Axiom cut : forall (g d1 d2 : env) (A C : LinProp),
g == (d1 U d2) ->
d1 |- A ->
(A :: d2) |- C ->
g |- C.
(* Factory cut -- note g' and d, not d1 and d2 *)
Axiom cut_fact : forall (g g' d : env) (A C : LinProp),
g == (g' U d) ->
g' |- A ->
((A :: g') U d) |- C ->
g |- C.