-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAF.v
More file actions
393 lines (322 loc) · 13.1 KB
/
LAF.v
File metadata and controls
393 lines (322 loc) · 13.1 KB
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
Set Implicit Arguments.
Unset Strict Implicit.
Set Maximal Implicit Insertion.
Open Scope type_scope.
Require Import ssreflect List Basic Equality.
Section QuantifyingStructure.
(*************************)
(* Quantifying Structure *)
(*************************)
Record QuantifyingStructures :=
{
Sorts : Type;
QWorld: Type;
Terms : QWorld -> Type;
SoContexts: QWorld -> Type;
SortingRel qLab : SoContexts qLab -> Terms qLab -> Sorts -> Prop
}.
(* We now assume we have a quantifying structure *)
Variable QS: QuantifyingStructures.
(**************************************)
(* Useful definitions for types *)
(* (types are parameterised by terms) *)
(**************************************)
Inductive AList A : list QS.(Sorts) -> Type :=
| TermNil : AList A nil
| TermCons s: A -> forall l, AList A l -> AList A (s::l).
Definition TList (qLab:QS.(QWorld)) := AList (Terms qLab).
Definition DPair A := {l: list QS.(Sorts) & A l}.
Definition ex1 A (a:DPair A) :=
match a with
| existS l _ => l
end.
Definition ex2 A (a:DPair A): A (ex1 a) :=
match a with
| existS _ araw => araw
end.
Definition Inst A (qLab:QS.(QWorld)) := DPair (fun l => A l * TList qLab l).
Definition getA A qLab (a:Inst A qLab) := let (b,_) := ex2 a in b.
Definition getTerms A qLab (a:Inst A qLab) := let (_,b) := ex2 a in b.
End QuantifyingStructure.
Notation "[ x , y ]" := (existS (fun l => _ l * TList _ l) _ (x,y)).
(*****************)
(* Decomposition *)
(*****************)
(* Dec Squeleton *)
Inductive DecStruct :=
| sleafP : DecStruct
| sleafN : DecStruct
| sdummy : DecStruct
| snode : DecStruct -> DecStruct -> DecStruct
| sqnode : DecStruct -> DecStruct.
(* Generic Decomposition type, with two kinds of leaves A and B *)
Inductive Dec {C A B: Type}: DecStruct -> Type :=
| leafP : A -> Dec sleafP
| leafN : B -> Dec sleafN
| dummy : Dec sdummy
| node : forall {s1 s2}, Dec s1 -> Dec s2 -> Dec (snode s1 s2)
| qnode : forall {s}, C -> Dec s -> Dec (sqnode s).
(* Lifting three relations RelQ, RelP and RelN, respectively between E
and F, between A and C and between B and D, into a relation between
Decs E A B and Decs F C D *)
Definition Declift (E F A B C D: Type)
(RelQ: E -> F -> Prop)
(RelP: A -> C -> Prop)
(RelN: B -> D -> Prop)
{st}
: @Dec E A B st -> @Dec F C D st -> Prop.
Proof.
induction st; move => v Delta ; inversion v ; inversion Delta.
exact (RelP X X0).
exact (RelN X X0).
exact True.
exact ((IHst1 X X1)/\(IHst2 X0 X2)).
exact ((RelQ X X1)/\(IHst X0 X2)).
Defined.
Global Arguments Declift {E F A B C D} RelQ RelP RelN [st] _ _.
Lemma Decstruct {C A B: Type} st:
match st with
| sleafP => forall (v:Dec (C := C) (A := A) (B := B) sleafP), exists a, v = leafP a
| sleafN => forall (v:Dec (C := C) (A := A) (B := B) sleafN), exists a, v = leafN a
| sdummy => forall (v:Dec (C := C) (A := A) (B := B) sdummy), v = dummy
| snode s1 s2 => forall (v:Dec (C := C) (A := A) (B := B) (snode s1 s2)),
exists (v1:Dec s1)(v2:Dec s2), v = node v1 v2
| sqnode s0 => forall (v:Dec (C := C) (A := A) (B := B) (sqnode s0)),
exists (v0:Dec s0) t, v = qnode t v0
end.
Proof.
assert
(forall (v:Dec (C := C) (A := A) (B := B) st),
match st with
| sleafP => exists a, JMeq v (leafP (C := C) (A := A) (B := B) a)
| sleafN => exists a, JMeq v (leafN (C := C) (A := A) (B := B) a)
| sdummy => JMeq v (dummy (C := C) (A := A) (B := B) )
| snode s1 s2 => exists (v1:Dec s1)(v2:Dec s2), JMeq v (node (C := C) (A := A) (B := B) v1 v2)
| sqnode s0 => exists (v0:Dec s0) t, JMeq v (qnode (C := C) (A := A) (B := B) t v0)
end
).
move => v.
by case v;
[
move => a; exists a
| move => b; exists b
|
| move => s1 s2 v1 v2; exists v1; exists v2; apply JMeq_refl
| move => s t v0; exists v0; exists t; apply JMeq_refl
].
by move:H; case st
=> [ | | | s1 s2 | s ];
move => H v; move:(H v); clear H;
[ move => [a H]; exists a
| move => [b H]; exists b
| move => H
| move => [v1 [v2 H]]; exists v1; exists v2
| move => [v0 [t H]]; exists v0; exists t
]
;
apply JMeq_eq.
Qed.
Section LAF.
(*********)
(* TYPES *)
(*********)
(* The language of types is given by
- Sorts: sorts for terms
- Atom: type of atoms
- Molecule: type of molecules *)
Record QSTypes :=
{
QS :> QuantifyingStructures;
Atom : list QS.(Sorts) -> Type;
Molecule : list QS.(Sorts) -> Type;
is_eq {qLab}: (Inst Atom qLab) -> (Inst Atom qLab) -> Prop
}.
Inductive TypingDec (QST: QSTypes): DecStruct -> list QST.(Sorts) -> Type :=
| TleafP : forall {l}, Atom l -> TypingDec sleafP l
| TleafN : forall {l}, Molecule l -> TypingDec sleafN l
| Tdummy : forall {l}, TypingDec sdummy l
| Tnode : forall {l s1 s2}, TypingDec s1 l -> TypingDec s2 l -> TypingDec (snode s1 s2) l
| Tqnode : forall {l s} so, TypingDec s (so::l) -> TypingDec (sqnode s) l.
(************)
(* Contexts *)
(************)
(* Axiomatic specification for the implementation of contexts:
Contexts can be typing contexts (variables are mapped to "types"), or
substitutions (variables are mapped to "terms").
Contexts map quantifiable, positive and negative variables to elements
of C, A and B, respectively.
readq, readp and readn are for reading the values.
*)
Record World (QS:QuantifyingStructures) :=
{
PLab:Type;
NLab:Type;
QLab:QS.(QWorld)
}.
Record Contexts {QS:QuantifyingStructures}
(wextends: DecStruct -> World QS -> World QS)
(A B C:Type)(D:QS.(QWorld) -> Type) :=
{
Csupport w :> Type;
readp w : Csupport w -> w.(PLab) -> A;
readn w : Csupport w -> w.(NLab) -> B;
readE w : Csupport w -> D w.(QLab);
extends w st:
forall v : @Dec C A B st, @Csupport w -> @Csupport (wextends st w)
}.
(* A typing context maps positive variables atoms and negative variables to molecules *)
Record TypingContexts (QST:QSTypes)(wextends: DecStruct -> World QST -> World QST) :=
{
TCsupport w :> Type;
Treadp w : TCsupport w -> w.(PLab) -> Inst Atom w.(QLab);
Treadn w : TCsupport w -> w.(NLab) -> Inst Molecule w.(QLab);
TreadE w : TCsupport w -> SoContexts w.(QLab);
Textends w st:
forall v : Inst (TypingDec st) w.(QLab), TCsupport w -> TCsupport (wextends st w)
}.
(* The language of proof-terms is parameterised by:
- Patterns: type of elements that can be thought as patterns
To each pattern p is associated a tree skeleton PatDec p
*)
Record LAFs :=
{
QST:> QSTypes;
wextends : DecStruct -> World QST -> World QST;
TContext : TypingContexts wextends;
Patterns : Type;
PatDec : Patterns -> DecStruct;
PatternsTyped (p:Patterns) l : @TypingDec QST (PatDec p) l -> Molecule l -> Prop
}.
Global Arguments TContext {_}.
Global Arguments PatternsTyped {_} p {_} _ _.
(* We assume we have an instance of LAF *)
Variable LAF:LAFs.
(***************)
(* PROOF-TERMS *)
(***************)
(* The language of proof-terms has 5 syntactic categories:
- commands
(negative term+positive term)
- negative terms
(reification of a meta-level partial function from patterns to commands,
represented as a total function to option commands)
- positive terms
(pattern + prof-term tree)
- proof-term trees
("a way to fill the pattern's holes")
- option commands
(the result of a partial function to commands)
*)
Inductive Pos (w: World LAF):Type :=
| pos: forall p: LAF.(Patterns), TermDec w (PatDec p) -> Pos w
with TermDec (w: World LAF): DecStruct -> Type :=
| tleafP: w.(PLab) -> TermDec w sleafP
| tleafN: Neg w -> TermDec w sleafN
| tdummy: TermDec w sdummy
| tnode {s1 s2}: TermDec w s1 -> TermDec w s2 -> TermDec w (snode s1 s2)
| tqnode {s}: Terms w.(QLab) -> TermDec w s -> TermDec w (sqnode s)
with Neg (w: World LAF):Type :=
| rei : (forall p:LAF.(Patterns), OptionCommand (wextends (PatDec p) w)) -> Neg w
with OptionCommand (w: World LAF): Type :=
| some: Command w -> OptionCommand w
| none
with Command (w: World LAF): Type :=
| cut : Neg w -> Pos w -> Command w
| select: w.(NLab) -> Pos w -> Command w.
Global Arguments pos {w} p _.
Scheme pos_ind :=
Induction for Pos Sort Prop
with termtree_ind :=
Induction for TermDec Sort Prop
with neg_ind :=
Induction for Neg Sort Prop
with ocommand_ind :=
Induction for OptionCommand Sort Prop
with command_ind :=
Induction for Command Sort Prop.
Combined Scheme term_ind from pos_ind, termtree_ind, neg_ind, ocommand_ind, command_ind.
(*****************)
(* Abbreviations *)
(*****************)
Definition Reifiable w := forall p:Patterns LAF, OptionCommand (wextends (PatDec p) w).
(* Notation "x + y" := (sum x y). *)
(* Definition NegVar w := @Neg w + w.(NLab). *)
Inductive cexists_as {w} : OptionCommand w -> Command w -> Prop :=
cnotnone: forall o, cexists_as (some o) o
.
Notation "x =cis= y" := (cexists_as x y) (at level 30, right associativity).
Lemma somecis {w u} {c: Command w} : u =cis= c -> u = some c.
Proof.
by elim.
Qed.
(**********)
(* TYPING *)
(**********)
(* This is the parameter that integrates the logical connectives.
It is a relation expressing:
"A formula can be decomposed into a TypingDec according to a pattern."
Example:
(A\/(B/\C)) can be decomposed into B,C according to the pattern inj2(_,_)
*)
(* Here is the typing system *)
Inductive PosTyping {w} (Gamma: TContext w): Pos w -> Inst Molecule w.(QLab) -> Prop :=
| typingpos: forall p l v Delta A (tl:TList w.(QLab) l),
PatternsTyped p Delta A
-> DecTyping Gamma v Delta tl
-> PosTyping Gamma (pos p v) [A,tl]
with DecTyping {w} (Gamma: TContext w)
: forall l {st}, TermDec w st -> TypingDec st l -> TList w.(QLab) l -> Prop :=
| typingsub_leafl: forall l xp x (tl:TList w.(QLab) l),
is_eq (Treadp Gamma xp) [x,tl]
-> DecTyping Gamma (tleafP xp) (TleafP x) tl
| typingsub_leafr: forall l nt A (tl:TList w.(QLab) l),
NegTyping Gamma nt [A,tl] ->
DecTyping Gamma (tleafN nt) (TleafN A) tl
| typingsub_dummy: forall l (tl:TList w.(QLab) l),
DecTyping Gamma (tdummy w) Tdummy tl
| typingsub_node: forall l s1 s2 (v1:TermDec w s1) (v2:TermDec w s2)
Delta1 Delta2 (tl:TList w.(QLab) l),
DecTyping Gamma v1 Delta1 tl
-> DecTyping Gamma v2 Delta2 tl
-> DecTyping Gamma (tnode v1 v2) (Tnode Delta1 Delta2) tl
| typingsub_qnode: forall l s (v:TermDec w s) so Delta r (tl:TList w.(QLab) l),
SortingRel (TreadE Gamma) r so
-> DecTyping Gamma v Delta (TermCons so r tl)
-> DecTyping Gamma (tqnode r v) (Tqnode Delta) tl
with NegTyping {w} (Gamma: TContext w) : Neg w -> Inst Molecule w.(QLab) -> Prop :=
| typingneg: forall f l A tl,
(forall p c, f p =cis= c -> exists Delta, PatternsTyped p Delta A)
->
(forall p (Delta:TypingDec _ l), (PatternsTyped p Delta A)
-> OptionCommandTyping
(w := wextends (PatDec p) w)
(Textends [Delta,tl] Gamma)
(f p))
-> NegTyping Gamma (rei f) [A,tl]
with OptionCommandTyping {w} (Gamma: TContext w): OptionCommand w -> Prop :=
| typingoption: forall c,
CommandTyping Gamma c
-> OptionCommandTyping Gamma (some c)
with CommandTyping {w} (Gamma: TContext w): Command w -> Prop :=
| typingcut: forall nt pt A,
NegTyping Gamma nt A
-> PosTyping Gamma pt A
-> CommandTyping Gamma (cut nt pt)
| typingselect: forall xn pt,
PosTyping Gamma pt (Treadn Gamma xn)
-> CommandTyping Gamma (select xn pt)
.
(* We create the induction principle on typing trees *)
Scheme typingPos_ind :=
Induction for PosTyping Sort Prop
with typingSub_ind :=
Induction for DecTyping Sort Prop
with typingNeg_ind :=
Induction for NegTyping Sort Prop
with typingOptionCommand_ind :=
Induction for OptionCommandTyping Sort Prop
with typingCommand_ind := Induction for CommandTyping Sort Prop
.
Combined Scheme typing_ind from typingPos_ind, typingSub_ind, typingNeg_ind, typingOptionCommand_ind, typingCommand_ind.
End LAF.
Notation "x =cis= y" := (cexists_as x y) (at level 30, right associativity).