-
Notifications
You must be signed in to change notification settings - Fork 0
/
DescriptionInd.v
348 lines (293 loc) · 10.4 KB
/
DescriptionInd.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
Require Import Coq.Program.Equality.
Require Import Coq.Strings.String.
Require Import Coq.Lists.List.
Import ListNotations.
Require Export Parser.Structures.
Require Export Parser.Tactics.
Require Export Parser.HList.
Require Export Parser.Option.
Require Export Parser.Description.
(* Given an `Description`, we build the corresponding inductive predicate *)
Inductive descr_ind { G } (descr: Description G): forall A, Syntax A -> G A -> Prop :=
| EpsInd: forall A a R v,
In R (epsilon_descr descr a) ->
R HNil = Some v ->
descr_ind descr A (Epsilon a) v
| FailureInd: forall A R v,
In R (failure_descr descr A) ->
R HNil = Some v ->
descr_ind descr A (Failure A) v
| ElemInd: forall k R v,
In R (token_descr descr k) ->
R HNil = Some v ->
descr_ind descr token (Elem k) v
| MapInd0: forall A B (f: A -> B) g s R vB,
In R (map_descr descr f g s) ->
R (HCons None HNil) = Some vB ->
descr_ind descr B (Map f g s) vB
| MapInd1: forall A B (f: A -> B) g s R vA vB,
descr_ind descr A s vA ->
In R (map_descr descr f g s) ->
R (HCons (Some vA) HNil) = Some vB ->
descr_ind descr B (Map f g s) vB
| DisjInd0: forall A s1 s2 R v,
In R (disj_descr descr s1 s2) ->
R (HCons None (HCons None HNil)) = Some v ->
descr_ind descr A (Disjunction s1 s2) v
| DisjInd1: forall A s1 s2 R v1 v,
descr_ind descr A s1 v1 ->
In R (disj_descr descr s1 s2) ->
R (HCons (Some v1) (HCons None HNil)) = Some v ->
descr_ind descr A (Disjunction s1 s2) v
| DisjInd2: forall A s1 s2 R v2 v,
descr_ind descr A s2 v2 ->
In R (disj_descr descr s1 s2) ->
R (HCons None (HCons (Some v2) HNil)) = Some v ->
descr_ind descr A (Disjunction s1 s2) v
| DisjInd12: forall A s1 s2 R v1 v2 v,
descr_ind descr A s1 v1 ->
descr_ind descr A s2 v2 ->
In R (disj_descr descr s1 s2) ->
R (HCons (Some v1) (HCons (Some v2) HNil)) = Some v ->
descr_ind descr A (Disjunction s1 s2) v
| SeqInd0: forall A B s1 s2 R v,
In R (seq_descr descr s1 s2) ->
R (HCons None (HCons None HNil)) = Some v ->
descr_ind descr (A * B) (Sequence s1 s2) v
| SeqInd1: forall A B s1 s2 R v1 v,
descr_ind descr A s1 v1 ->
In R (seq_descr descr s1 s2) ->
R (HCons (Some v1) (HCons None HNil)) = Some v ->
descr_ind descr (A * B) (Sequence s1 s2) v
| SeqInd2: forall A B s1 s2 R v2 v,
descr_ind descr B s2 v2 ->
In R (seq_descr descr s1 s2) ->
R (HCons None (HCons (Some v2) HNil)) = Some v ->
descr_ind descr (A * B) (Sequence s1 s2) v
| SeqInd12: forall A B s1 s2 R v1 v2 v,
descr_ind descr A s1 v1 ->
descr_ind descr B s2 v2 ->
In R (seq_descr descr s1 s2) ->
R (HCons (Some v1) (HCons (Some v2) HNil)) = Some v ->
descr_ind descr (A * B) (Sequence s1 s2) v
| VarInd0: forall x R v',
In R (var_descr descr x (e x)) ->
R (HCons None HNil) = Some v' ->
descr_ind descr (get_type x) (Var x) v'
| VarInd1: forall x R v v',
descr_ind descr (get_type x) (e x) v ->
In R (var_descr descr x (e x)) ->
R (HCons (Some v) HNil) = Some v' ->
descr_ind descr (get_type x) (Var x) v'
.
Arguments descr_ind { G } descr { A }.
Hint Constructors descr_ind: descr_ind.
Lemma descr_same:
forall F (descr: Description F) A (s: Syntax A) v1 v2,
descr_ind descr s v1 ->
v1 = v2 ->
descr_ind descr s v2.
Proof.
intros; subst; auto.
Qed.
Program Definition descr_ind_epsilon_inversion G (descr: Description G) A (a: A) v
(H: descr_ind descr (Epsilon a) v) :=
match H in descr_ind _ s' v' return
match s' in Syntax A' return G A' -> Prop with
| Epsilon a => fun v'' =>
exists R,
In R (epsilon_descr descr a) /\
R HNil = Some v''
| _ => fun _ => True
end v'
with
| ElemInd _ _ _ _ _ _ => _
| _ => _
end.
Solve Obligations with eauto 10.
Fail Next Obligation. (* no more obligation for `descr_ind_epsilon_inversion` *)
Program Definition descr_ind_elem_inversion G (descr: Description G) k (v: G token)
(H: descr_ind descr (Elem k) v) :=
match H in descr_ind _ s' v' return
match s' in Syntax A' return G A' -> Prop with
| Elem k => fun v'' =>
exists R,
In R (token_descr descr k) /\
R HNil = Some v''
| _ => fun _ => True
end v'
with
| ElemInd _ _ _ _ _ _ => _
| _ => _
end.
Solve Obligations with eauto 10.
Fail Next Obligation. (* no more obligation for `descr_ind_elem_inversion` *)
Program Definition descr_ind_failure_inversion G (descr: Description G) A v
(H: descr_ind descr (Failure A) v) :=
match H in descr_ind _ s' v' return
match s' in Syntax A' return G A' -> Prop with
| Failure A => fun v'' =>
exists R,
In R (failure_descr descr A) /\
R HNil = Some v''
| _ => fun _ => True
end v'
with
| ElemInd _ _ _ _ _ _ => _
| _ => _
end.
Solve Obligations with eauto 10.
Fail Next Obligation. (* no more obligation for `descr_ind_failure_inversion` *)
Program Definition descr_ind_disj_inversion G (descr: Description G) A (s: Syntax A) (v: G A)
(H: descr_ind descr s v) :=
match H in descr_ind _ s' v' return
match s' in Syntax A' return G A' -> Prop with
| Disjunction s1' s2' =>
fun v'' =>
exists R, In R (disj_descr descr s1' s2') /\ (
(R (HCons None (HCons None HNil)) = Some v'') \/
(exists v1, descr_ind descr s1' v1 /\ R (HCons (Some v1) (HCons None HNil)) = Some v'') \/
(exists v2, descr_ind descr s2' v2 /\ R (HCons None (HCons (Some v2) HNil)) = Some v'') \/
(exists v1 v2,
descr_ind descr s1' v1 /\
descr_ind descr s2' v2 /\
R (HCons (Some v1) (HCons (Some v2) HNil)) = Some v''
)
)
| _ => fun _ => True
end v'
with
| SeqInd0 _ _ _ _ _ _ _ _ _ => _
| _ => _
end.
Solve Obligations with eauto 10.
Fail Next Obligation. (* no more obligation for `descr_ind_disj_inversion` *)
Program Definition descr_ind_seq_inversion G (descr: Description G) A (s: Syntax A) (v: G A)
(H: descr_ind descr s v) :=
match H in descr_ind _ s' v' return
match s' in Syntax A' return G A' -> Prop with
| Sequence s1' s2' =>
fun v'' =>
exists R, In R (seq_descr descr s1' s2') /\ (
(R (HCons None (HCons None HNil)) = Some v'') \/
(exists v1, descr_ind descr s1' v1 /\ R (HCons (Some v1) (HCons None HNil)) = Some v'') \/
(exists v2, descr_ind descr s2' v2 /\ R (HCons None (HCons (Some v2) HNil)) = Some v'') \/
(exists v1 v2,
descr_ind descr s1' v1 /\
descr_ind descr s2' v2 /\
R (HCons (Some v1) (HCons (Some v2) HNil)) = Some v''
)
)
| _ => fun _ => True
end v'
with
| SeqInd0 _ _ _ _ _ _ _ _ _ => _
| _ => _
end.
Solve Obligations with eauto 10.
Fail Next Obligation. (* no more obligations for `descr_ind_seq_inversion` *)
Program Definition descr_ind_map_inversion G (descr: Description G) A (s: Syntax A) (v: G A)
(H: descr_ind descr s v) :=
match H in descr_ind _ s' v' return
match s' in Syntax A' return G A' -> Prop with
| Map f g s' =>
fun v'' =>
exists R, In R (map_descr descr f g s') /\ (
(R (HCons None HNil) = Some v'') \/
(exists v', descr_ind descr s' v' /\ R (HCons (Some v') HNil) = Some v'')
)
| _ => fun _ => True
end v'
with
| SeqInd0 _ _ _ _ _ _ _ _ _ => _
| _ => _
end.
Solve Obligations with eauto 10.
Fail Next Obligation. (* no more obligations for `descr_ind_seq_inversion` *)
Program Definition descr_ind_var_inversion G (descr: Description G) x v
(H: descr_ind descr (Var x) v) :=
match H in descr_ind _ s' v' return
match s' in Syntax A' return G A' -> Prop with
| Var x' => fun v'' =>
exists R, In R (var_descr descr x' (e x')) /\ (
(R (HCons None HNil) = Some v'') \/
(exists v', descr_ind descr (e x') v' /\ R (HCons (Some v') HNil) = Some v'')
)
| _ => fun _ => True
end v'
with
| VarInd0 _ _ _ _ _ _ => _
| _ => _
end.
Solve Obligations with eauto 10.
Fail Next Obligation. (* no more obligations for `descr_ind_var_inversion` *)
Ltac descr_ind_inversion :=
match goal with
| H: descr_ind _ (Epsilon _) _ |- _ =>
poseNew (Mark H "descr_ind_inversion");
pose proof (descr_ind_epsilon_inversion _ _ _ _ _ H)
| H: descr_ind _ (Elem _) _ |- _ =>
poseNew (Mark H "descr_ind_inversion");
pose proof (descr_ind_elem_inversion _ _ _ _ H)
| H: descr_ind _ (Failure _) _ |- _ =>
poseNew (Mark H "descr_ind_inversion");
pose proof (descr_ind_failure_inversion _ _ _ _ H)
| H: descr_ind _ (Sequence _ _) _ |- _ =>
poseNew (Mark H "descr_ind_inversion");
pose proof (descr_ind_seq_inversion _ _ _ _ _ H)
| H: descr_ind _ (Disjunction _ _) _ |- _ =>
poseNew (Mark H "descr_ind_inversion");
pose proof (descr_ind_disj_inversion _ _ _ _ _ H)
| H: descr_ind _ (Map _ _ _) _ |- _ =>
poseNew (Mark H "descr_ind_inversion");
pose proof (descr_ind_map_inversion _ _ _ _ _ H)
| H: descr_ind _ (Var _) _ |- _ =>
poseNew (Mark H "descr_ind_inversion");
pose proof (descr_ind_var_inversion _ _ _ _ H)
end.
Lemma in_disj_descr:
forall A (s1 s2: Syntax A) G (descr: Description G) v r opt1 opt2,
In r (disj_descr descr s1 s2) ->
opt_forall opt1 (descr_ind descr s1) ->
opt_forall opt2 (descr_ind descr s2) ->
r (HCons opt1 (HCons opt2 HNil)) = Some v ->
descr_ind descr (Disjunction s1 s2) v.
Proof.
destruct opt1; destruct opt2;
repeat light;
eauto with descr_ind.
Qed.
Lemma in_seq_descr:
forall A1 A2 (s1: Syntax A1) (s2: Syntax A2) G (descr: Description G) v r opt1 opt2,
In r (seq_descr descr s1 s2) ->
opt_forall opt1 (descr_ind descr s1) ->
opt_forall opt2 (descr_ind descr s2) ->
r (HCons opt1 (HCons opt2 HNil)) = Some v ->
descr_ind descr (Sequence s1 s2) v.
Proof.
destruct opt1; destruct opt2;
repeat light;
eauto with descr_ind.
Qed.
Lemma in_map_descr:
forall A B (f: A -> B) g (s': Syntax A) G (descr: Description G) v r opt,
In r (map_descr descr f g s') ->
opt_forall opt (descr_ind descr s') ->
r (HCons opt HNil) = Some v ->
descr_ind descr (Map f g s') v.
Proof.
destruct opt;
repeat light;
eauto with descr_ind.
Qed.
Lemma in_var_descr:
forall x G (descr: Description G) v r opt,
In r (var_descr descr x (e x)) ->
opt_forall opt (descr_ind descr (e x)) ->
r (HCons opt HNil) = Some v ->
descr_ind descr (Var x) v.
Proof.
destruct opt;
repeat light;
eauto with descr_ind.
Qed.