-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguageModel.v
279 lines (233 loc) · 9.03 KB
/
LanguageModel.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
Set Implicit Arguments.
Require Import TraceModel.
Require Import Properties.
Require Import ClassicalExtras.
Require Import MyNotation.
Record Language := {
prg : Type; (* Whole programs *)
par : Type; (* Partial programs *)
ctx : Type; (* Contexts *)
plug : par -> ctx -> prg (* Linking operation *)
}.
(* semantics of a language can be defined over an arbitrary set *)
Structure Semantics (L : Language) (trace_set : Type) := {
sem : prg L -> trace_set -> Prop;
non_empty_sem : forall W, exists t, sem W t
}.
(* in case we have usual traces over events we can also have W ⇝* m for m finite prefix *)
Structure EventTraceSemantics (L : Language) (Ev : Events) (Es : Endstates) := {
ev_semantics : Semantics L (@trace Ev Es);
psem W (m : @finpref Ev Es) := exists t, prefix m t /\ sem ev_semantics W t
}.
Coercion ev_semantics : EventTraceSemantics >-> Semantics.
Definition input_totality {L : Language} {Ev : Events} {Es : Endstates}
(is_input : (ev Ev) -> bool)
(event_semantics : EventTraceSemantics L Ev Es) : Prop :=
forall (W : prg L) (l : list (ev Ev)) (i1 i2: (ev Ev)),
(is_input i1 = true) ->
(is_input i1 = true) ->
psem event_semantics W (ftbd (snoc l i1 )) ->
psem event_semantics W (ftbd (snoc l i2 )).
Definition determinacy {L : Language} {Ev : Events} {Es : Endstates}
(is_input : (ev Ev) -> bool)
(event_semantics : EventTraceSemantics L Ev Es) : Prop :=
forall (W : prg L) (t1 t2 : @trace Ev Es),
sem (ev_semantics event_semantics) W t1 ->
sem (ev_semantics event_semantics) W t2 ->
t1 = t2 \/ (exists l i1 i2, i1 <> i2 /\ prefix (ftbd (snoc l i1)) t1 /\ prefix (ftbd (snoc l i2)) t2).
Definition beh {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W : prg L) : prop trace_set :=
fun t => sem S W t.
Definition sat {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W : prg L) (π : prop trace_set) : Prop :=
forall t, sem S W t -> π t.
Lemma sat_upper_closed {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W : prg L ) (π1 π2 : prop trace_set) :
sat S W π1 -> π1 ⊆ π2 -> sat S W π2.
Proof.
intros Hsat1 Hsuper t Hsem.
apply Hsuper.
now apply (Hsat1 t).
Qed.
Definition hsat{L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W : prg L) (H : hprop trace_set) : Prop :=
H (beh S W).
Lemma hsat_upper_closed {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W : prg L ) (H1 H2 : hprop trace_set) :
hsat S W H1 -> H1 ⊆ H2 -> hsat S W H2.
Proof.
intros Hsat1 Hsuper.
apply Hsuper.
now apply Hsat1.
Qed.
Definition rsat {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P : par L) (π : prop trace_set) : Prop :=
forall C, sat S (plug L P C) π.
Lemma rsat_upper_closed {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P : par L ) (π1 π2 : prop trace_set) :
rsat S P π1 -> π1 ⊆ π2 -> rsat S P π2.
Proof.
intros Hsat1 Hsuper C t Hsem.
apply Hsuper.
now apply (Hsat1 C t).
Qed.
Definition rhsat {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P : par L) (H : hprop trace_set) : Prop :=
forall C, hsat S (plug L P C) H.
Lemma neg_sat {L : Language}
{trace_set : Type}
{S : Semantics L trace_set} :
forall (W : prg L) (π : prop trace_set),
~ sat S W π <-> exists t, sem S W t /\ ~ π t.
Proof.
intros W π. unfold sat.
rewrite not_forall_ex_not.
split; intros [t H]; exists t; [now rewrite not_imp in H
| now rewrite not_imp].
Qed.
(* Considering moving these two lemmas to a separate module *)
Lemma neg_rsat {L : Language}
{trace_set : Type}
(S : Semantics L trace_set) :
forall (P : par L) (π : prop trace_set),
(~ rsat S P π <->
(exists C t, sem S (plug L P C) t /\ ~ π t)).
Proof.
intros P π.
split; unfold rsat; intros H.
- rewrite not_forall_ex_not in H.
destruct H as [C H]; exists C.
unfold sat in H; rewrite not_forall_ex_not in H.
destruct H as [t H]; exists t.
now rewrite not_imp in H.
- firstorder.
Qed.
Lemma neg_rhsat {L : Language}
{trace_set : Type}
(S : Semantics L trace_set) :
forall P H, (~ rhsat S P H <-> ( exists (C : ctx L), ~ H (beh S ( plug L P C )))).
Proof.
intros P H.
split; unfold rhsat; intro H0;
[now rewrite <- not_forall_ex_not | now rewrite not_forall_ex_not].
Qed.
Lemma rhsat_upper_closed {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P : par L ) (H1 H2 : hprop trace_set) :
rhsat S P H1 -> H1 ⊆ H2 -> rhsat S P H2.
Proof.
intros rsat1 Hsuper C.
apply Hsuper.
now apply (rsat1 C).
Qed.
Definition sat2 {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W1 W2 : prg L) (R : trace_set * trace_set -> Prop) : Prop :=
forall t1 t2, sem S W1 t1 -> sem S W2 t2 -> R (t1, t2).
Definition rsat2 {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P1 P2 : par L) (R : trace_set * trace_set -> Prop) : Prop :=
forall C t1 t2, sem S (plug L P1 C) t1 -> sem S (plug L P2 C) t2 -> R (t1, t2).
Lemma sat2_upper_closed {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W1 W2 : prg L ) (R1 R2 : trace_set * trace_set -> Prop) :
sat2 S W1 W2 R1 -> R1 ⊆ R2 -> sat2 S W1 W2 R2.
Proof.
intros Hsat1 Hsuper t1 t2 Hsem1 Hsem2.
apply Hsuper.
now apply (Hsat1 t1).
Qed.
Lemma rsat2_upper_closed {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P1 P2 : par L ) (R1 R2 : trace_set * trace_set -> Prop) :
rsat2 S P1 P2 R1 -> R1 ⊆ R2 -> rsat2 S P1 P2 R2.
Proof.
intros Hsat1 Hsuper C t1 t2 Hsem1 Hsem2.
apply Hsuper.
now apply (Hsat1 C t1).
Qed.
Lemma neg_sat2 {L : Language}
{trace_set : Type}
{S : Semantics L trace_set} :
forall (W1 W2 : prg L) (R : trace_set * trace_set -> Prop),
~ sat2 S W1 W2 R <-> exists t1 t2, sem S W1 t1 /\ sem S W2 t2 /\ ~ R (t1, t2).
Proof.
intros W1 W2 R. unfold sat2.
rewrite not_forall_ex_not.
split.
+ intros [t1 H]. rewrite not_forall_ex_not in H.
destruct H as [t2 H]. rewrite not_imp in H. destruct H as [H1 H].
rewrite not_imp in H. destruct H as [H2 H].
now exists t1, t2.
+ intros [t1 [t2 [H1 [H2 H]]]].
exists t1. rewrite not_forall_ex_not. exists t2. firstorder.
Qed.
Lemma neg_rsat2 {L : Language}
{trace_set : Type}
(S : Semantics L trace_set) :
forall (P1 P2 : par L) (R: trace_set * trace_set -> Prop),
(~ rsat2 S P1 P2 R <->
(exists C t1 t2, sem S (plug L P1 C) t1 /\ sem S (plug L P2 C) t2 /\ ~ R (t1,t2))).
Proof.
intros P1 P2 R.
split; unfold rsat2; intros H.
- rewrite not_forall_ex_not in H.
destruct H as [C H]; exists C.
unfold sat2 in H; rewrite not_forall_ex_not in H.
destruct H as [t1 H]; exists t1.
rewrite not_forall_ex_not in H.
destruct H as [t2 H]; exists t2.
now rewrite !not_imp in H.
- firstorder.
Qed.
Definition hsat2 {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(W1 W2 : prg L) (R : (prop trace_set) * (prop trace_set) -> Prop) : Prop :=
R ((beh S W1), (beh S W2)).
Definition rhsat2 {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P1 P2 : par L) (R : (prop trace_set) * (prop trace_set) -> Prop) : Prop :=
forall C, hsat2 S (plug L P1 C) (plug L P2 C) R.
Lemma neg_rhsat2 {L : Language}
{trace_set : Type}
(S : Semantics L trace_set) :
forall P1 P2 R, (~ rhsat2 S P1 P2 R <-> ( exists (C : ctx L),
~ R ((beh S (plug L P1 C )),(beh S (plug L P2 C))))).
Proof.
intros P1 P2 R.
split; unfold rhsat2; intro H0;
[now rewrite <- not_forall_ex_not | now rewrite not_forall_ex_not].
Qed.
Lemma rhsat2_upper_closed {L : Language}
{trace_set : Type}
(S : Semantics L trace_set)
(P1 P2 : par L ) (R1 R2 : (prop trace_set) * (prop trace_set) -> Prop) :
rhsat2 S P1 P2 R1 -> R1 ⊆ R2 -> rhsat2 S P1 P2 R2.
Proof.
intros rsat_one Hsuper C.
apply Hsuper.
now apply (rsat_one C).
Qed.