-
Notifications
You must be signed in to change notification settings - Fork 0
/
coq_proof_semantics_equivalence.v
4040 lines (3737 loc) · 134 KB
/
coq_proof_semantics_equivalence.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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* =========================================================== *)
(**
* Coq Proof for the equivalence of three semantics defined on a formal language for modelling distributed systems
Erwan Mahe - 2021
We use Coq to:
- formally encode an Interaction Language for modelling the behavior of distributed systems
- define a formal semantics in denotational style on this language
- define another formal semantics, this time in operational style
- prove the equivalence between the denotational and operational semantics
- propose an algorithmization of the operational semantics that we call the execution semantics
- prove the equivalence between the execution and the operational semantics and therefore also w.r.t. the denotational semantics
This proof accompanies the manuscript of my thesis
** Context
The formal language that we consider is that of interactions.
Interactions can be described as a formalisation of graphical models such as Message Sequence Charts or UML Sequence Diagrams.
An interaction describes the behaviors that can be expressed by a distributed system.
Those behaviors take the form of sequences of obserable events (discrete events), that we call traces (traces of execution).
In a more practical setting, a trace can for instance correspond to a log file,
in which the occurence of some discrete events have been recorded progressively during an execution of the system.
The events that constitute traces are atomic communication actions that occur on the interfaces of the distributed
system's sub-systems.
Those atomic actions correspond to either the emission or the reception of
a given message on a given sub-system.
The semantic domain of interest is therefore that of traces. The semantics of a given interaction is a given set of traces.
In the following, we will propose three different manners to define the semantics of interactions, and we will prove the equivalence
of those definitions. Those three definitions correspond to:
- a _denotational-style_ semantics, which consists in constructing sets of accepted traces by _composition_ and using algebraic properties of some operators on sets of traces
- an _operational-style_ semantics, which consists in considering how can an interaction model be executed dynamically, and which behaviors it thus expresses. For a given interaction "i", it may be possible to transform it into interaction "i'" through the expression of an action. By considering all those possible transformations, we can construct the semantics of interaction "i" using _recursion_ on the semantics of those transformed "i'" interactions.
- an _execution_ semantics, which is an algorithmization of the _operational-style_ semantics that consists in separating the process described by the operational semantics into two parts. At first we identify which actions can be immediately executed in a given interaction. And then, we construct the interaction term that remains to be executed.
** Related works
*** Publications
- #<a href="https://link.springer.com/chapter/10.1007%2F978-3-030-45234-6_24">Revisiting Semantics of Interactions for Trace Validity Analysis</a>#
- #<a href="https://dl.acm.org/doi/10.1145/3412841.3442054">A small-step approach to multi-trace checking against interactions</a>#
*** Other Coq proves and tools
The coq file itself is hosted on the following repository:
- #<a href="https://github.com/erwanM974/coq_hibou_label_semantics_equivalence">https://github.com/erwanM974/coq_hibou_label_semantics_equivalence</a>#
A prototype tool, which implements some formal verification techniques using the execution semantics
is available on the following repository:
- #<a href="https://github.com/erwanM974/hibou_label">https://github.com/erwanM974/hibou_label</a>#
The nature of distributed systems makes so that it is often impossible to reorder globally the events that occured on distrinct sub-systems during an execution
of the system. Let us remark that this is related to the absence of a global clock.
In any case, what can be concretely logged during the execution of a distributed system is most oftentimes rather a set of locally defined log files.
In the semantic domain, this translates into having sets of locally observed traces, which we call multi-traces.
Another Coq proof, that is interested in the handling of multi-traces
and how one can test them w.r.t. the semantics (the Oracle problem for some form of a trace conformance relation / membership)
is available on the following repository:
- #<a href="https://github.com/erwanM974/coq_hibou_label_multi_trace_analysis">https://github.com/erwanM974/coq_hibou_label_multi_trace_analysis</a>#
** Dependencies
Below are listed the libraries required for this Coq proof.
- "Coq.Bool.Bool." provides utilities related to the manipulation of booleans
- "Coq.Lists.List." provides utilities on lists. I use lists - among other things - to represent traces.
- "Coq.Vectors.Fin." provides a means to represent finite sets indexed by {1,...,n}.
- "Psatz." is required for using the "lia" tactic to solve simple arithemtic problems.
- "Coq.Program.Equality." is required for using the "dependent induction" tactic with "generalizing", allowing the generalisation of some variables of the problem in the induction hypothesis.
- "Coq.Init.Logic." for (among other things) the "not_eq_sym" theorem
- "Coq.Init.Nat.", "Coq.Arith.PeanoNat." and "Coq.Arith.Peano_dec." for the manipulation of natural integers and the use of some lemmas
**)
Require Import Coq.Bool.Bool.
Require Import Coq.Lists.List.
Require Coq.Vectors.Fin.
Require Import Psatz.
Require Import Coq.Program.Equality.
Require Import Coq.Init.Logic.
Require Import Coq.Init.Nat.
Require Import Coq.Arith.PeanoNat.
Require Import Coq.Arith.Peano_dec.
(**
* Preliminaries
This section is dedicated to enoncing some basic types and properties on which the remainder of the proof will be based.
**)
Theorem cons_eq_app (A : Type) (l l1 l2:list A) (a:A) :
(a :: l = l1 ++ l2)
->
( (l1 = nil /\ l2 = a::l)
\/ (exists (l1':list A), l1 = a :: l1')
).
Proof.
intros H.
dependent induction l1.
- simpl in *.
left.
symmetry in H.
split.
+ reflexivity.
+ assumption.
- simpl in *.
right.
inversion H.
destruct H1.
exists l1.
reflexivity.
Qed.
(**
** Signature & Actions
The interaction language that I define depends on a signature that is composed of:
- a set of "lifelines" L, which elements represent the individual sub-systems that can be found in the disctributed system (or some groups of sub-systems via abstraction/refinement)
- a set of "messages" M, which elements represent the individual distinguishable messages that can be exchanged (via asynchronous communication) within (i.e. internally) or without (i.e externally) the distributed system
Given that I consider finitely many such lifelines and messages, I use finite vectors from "Coq.Vectors.Fin."
to model those sets.
**)
Parameter LCard : nat.
Parameter MCard : nat.
Definition L := Fin.t (S LCard).
Definition M := Fin.t (S MCard).
(**
Given that we will manipulate elements of "L" (lifelines)
for the proofs regarding the execution semantics,
we formulate the following three basic properties:
- "L_neqb", which states that the inequality "l <> l'" (as a proposition) is equivalent to the fact that the boolean "Fin.eqb l l'" is false
- "L_not_neq", which states that if a lifeline "l" is not different from a lifeline "l'" then "l=l'"
- "L_neq_or_not_neq", which is a Lemma on the decidability of the unequality of lifelines
**)
Lemma L_neqb :
forall (l l':L),
(l <> l') <-> (Fin.eqb l l' = false).
Proof.
Admitted.
Lemma L_not_neq :
forall (l l':L),
(~ (l <> l'))
-> (l = l').
Proof.
Admitted.
Lemma L_neq_or_not_neq (x y:L) :
(x <> y) \/ (not(x<>y)).
Proof.
pose proof (Fin.eq_dec x y).
destruct H.
- right. intro. contradiction.
- left. assumption.
Qed.
(**
We denote by "l!m" the emission of message "m" (element of "M") from lifeline "l" (element of "L").
We denote by "l?m" the reception of message "m" (element of "M") by lifeline "l" (element of "L").
To distinguish between emissions and receptions I encode the kind of action
({!,?}) with an inductive type "ActKind".
**)
Inductive ActKind : Set :=
|ak_snd:ActKind
|ak_rcv:ActKind.
(**
I can now define actions with the "Action" type via a cartesian product of types L, ActKind and M.
A utility function "lifeline" returns, for any action, the lifeline on which it occurs.
**)
Definition Action :Set:= L*ActKind*M.
Definition lifeline: Action -> L :=
fun '(_ as l,_,_) => l.
Lemma exists_action_on_lifeline (l:L) :
(exists a:Action, l = (lifeline a) ).
Proof.
Admitted.
(* =========================================================== *)
(**
* Trace Language (Semantic Domain)
This section is dedicated to the semantic domain of our interaction language i.e. the domain of definition of its semantics.
After defining this domain, I will study the properties of this domain,
notably how one can manipulate its elements through some operators and which are the properties of those operators.
As hinted at ealier, in this modelling framework:
- it is the expected behavior of distributed systems that is modelled
- this behavior is expressed in terms of accepted traces i.e. sequences of atomic actions that may be expressed
The semantic domain is therefore the universe of traces.
The "Trace" type is formally defined below as that of lists of actions ("Action" type).
**)
Definition Trace : Type := list Action.
(**
** Some consideration on the decidability of equalities
In the following I construct the decidability of the equality of traces in several steps:
- in "eq_or_not_eq_actkind" is proven the decidability of the equality for the "ActKind" type. It is immediate given the inductive nature of "ActKind"
- in "eq_or_not_eq_action" is proven the decidability of the equality for the "Action" type. It relies on that of its subtypes L, ActKind and M. We have proven the decidability property for ActKind juste before, and, for L and M, it is provided by the "eq_dec" Lemma from "Coq.Vectors.Fin.".
- finally, in "eq_or_not_eq_trace" it is proven for the "Trace" type
This last proof relies on a custom induction principle defined and checked in the "double_trace_induction" Lemma.
**)
Lemma eq_or_not_eq_actkind (x y:ActKind) :
(x = y) \/ (x <> y).
Proof.
induction x; induction y.
- left. reflexivity.
- right. intro. discriminate.
- right. intro. discriminate.
- left. reflexivity.
Qed.
Lemma eq_or_not_eq_action (x y:Action) :
(x = y) \/ (x <> y).
Proof.
destruct x ; destruct y.
destruct p ; destruct p0.
pose proof (Fin.eq_dec m m0) as Hm.
pose proof (Fin.eq_dec l l0) as Hl.
pose proof (eq_or_not_eq_actkind a a0) as Ha.
destruct Hm ; destruct Hl ; destruct Ha.
- destruct e ; destruct e0 ; destruct H.
left. reflexivity.
- right. intro. injection H0. intros. contradiction.
- right. intro. injection H0. intros. contradiction.
- right. intro. injection H0. intros. contradiction.
- right. intro. injection H0. intros. contradiction.
- right. intro. injection H0. intros. contradiction.
- right. intro. injection H0. intros. contradiction.
- right. intro. injection H0. intros. contradiction.
Qed.
Lemma double_trace_induction (P: Trace -> Trace -> Prop):
(P nil nil)
-> (forall t:Trace, (t<>nil) -> ((P t nil) /\ (P nil t)) )
-> (forall (a1 a2:Action) (t1 t2:Trace), P t1 t2 -> P (a1::t1) (a2::t2) ) ->
forall (t1 t2:Trace), P t1 t2.
Proof.
intros.
dependent induction t1.
- induction t2.
+ assumption.
+ specialize H0 with (t:=(a::t2)).
apply H0. intro. discriminate.
- dependent induction t2.
+ specialize H0 with (t:=(a::t1)).
apply H0. intro. discriminate.
+ apply H1. apply IHt1.
Qed.
Lemma eq_or_not_eq_trace (x y:Trace) :
(x = y) \/ (x <> y).
Proof.
pose proof double_trace_induction.
specialize H with (P:= (fun x y:Trace => (x = y) \/ (x <> y))).
apply H.
- left. reflexivity.
- intros. split.
+ right. assumption.
+ right. apply not_eq_sym. assumption.
- intros. destruct H0.
+ destruct H0.
pose proof (eq_or_not_eq_action a1 a2).
destruct H0.
* destruct H0. left. reflexivity.
* right. intro. inversion H1. contradiction.
+ right. intro. inversion H1. contradiction.
Qed.
(**
** Some operators on traces and some of their algebraic properties
In the following let us focus on four operators on traces:
- the classical concatenation of lists "++" which is extended to traces:
- for any two traces t1 and t2, there is a single traces t such that t = t1 ++ t2
- this traces t is defined as the concatenation of t1 and t2 as a single contiguous list
- an interleaving operator on traces
- for any two traces t1 and t2, there can exist may traces t such that (is_interleaving t1 t2 t)
- those traces correspond to potential interleavings of the actions from t1 and t2
- within such a t, one must find all the actions from t1 and all the actions from t2 in the order in which they are found in t1 and t2 respectively
- however actions from t1 can be put in any order w.r.t. the actions from t2
- a weak sequencing operator on traces:
- for any two traces t1 and t2, there can exist may traces t such that (is_weak_seq t1 t2 t)
- weak sequencing allows some interleaving between the actions from t1 and t2
- however it is a more restrictive operator than interleaving given that it onlt allows some interleavings and not all
- the definition of what is allowed or not is reliant upon a conflict operator
- in a certain prefix of the trace t:
- actions from t1 can be added freely
- actions from t2 can only be added if they do not enter into conflict with the actions from t1 that are waiting to be added
- the notion of conflict correspond to the fact, for two actions, to occur on the same lifeline
- a special merge operator which merges an ordered list of traces into a single merged trace.
I define this operator in such a way that is is configurable so as to act
as any of three different merge operators:
- the merging of traces using classical concatenation
- the merging of traces using the interleaving operator
- the merging of traces using the weak sequenceing operator
In this section, those four operators will be defined (except for the concatenation which is already provided by Coq)
and some of their properties stated and proven.
**)
(**
*** Concatenation
For the concatenation operator "++", most interesting properties are already shipped in with Coq
and can be used in proofs more or less direclty (with "simpl.", "inversion." and so on).
**)
Lemma concat_nil_prop0 (t1 t2:Trace) :
(t1 ++ t2 <> nil)
<-> ( (t1 <> nil) \/ (t2 <> nil) ).
Proof.
pose proof (eq_or_not_eq_trace t1 nil) as H1.
pose proof (eq_or_not_eq_trace t2 nil) as H2.
destruct H1 ; destruct H2.
- symmetry in H. destruct H.
symmetry in H0. destruct H0.
split ; intros.
+ simpl in H. contradiction.
+ destruct H ; contradiction.
- symmetry in H. destruct H. simpl.
split ; intros.
+ right. assumption.
+ assumption.
- symmetry in H0. destruct H0. simpl.
split ; intros.
+ left. assumption.
+ rewrite app_nil_r. assumption.
- split ; intros.
+ left. assumption.
+ intro. apply app_eq_nil in H2.
destruct H2. contradiction.
Qed.
(**
*** Interleaving
I formalise the interleaving operator in Coq using an inductive predicate
"is_interleaving" such that
"(is_interleaving t1 t2 t)" states the membership of a given trace t
into the set of interleavings between traces t1 and t2.
This inductive predicate can be inferred inductively using four construction rules:
- "interleaving_nil_left" which states that for any trace t, t is an interleaving of the empty trace and t
- "interleaving_nil_right" which states that for any trace t, t is an interleaving of t and the empty trace
- "interleaving_cons_left" which states that for any interleaving t of traces t1 and t2, (a::t) is an interleaving of (a::t1) and t2
- "interleaving_cons_right" which states that for any interleaving t of traces t1 and t2, (a::t) is an interleaving of t1 and (a::t2)
Those two last rules signify that, when constructing an interleaving, we can mix in actions from either traces in any order
**)
Inductive is_interleaving : Trace -> Trace -> Trace -> Prop :=
| interleaving_nil_left : forall (t:Trace),
(is_interleaving nil t t)
| interleaving_nil_right : forall (t:Trace),
(is_interleaving t nil t)
| interleaving_cons_left : forall (t t1 t2:Trace) (a:Action),
(is_interleaving t1 t2 t) -> (is_interleaving (a::t1) t2 (a::t))
| interleaving_cons_right : forall (t t1 t2:Trace) (a:Action),
(is_interleaving t1 t2 t) -> (is_interleaving t1 (a::t2) (a::t)).
(**
Interesting properties of the "is_interleaving" that will be useful later on
**)
Lemma is_interleaving_existence (t1 t2:Trace) :
exists t:Trace, is_interleaving t1 t2 t.
Proof.
dependent induction t1.
- exists t2. apply interleaving_nil_left.
- specialize IHt1 with (t2:=t2).
destruct IHt1.
exists (a::x).
apply interleaving_cons_left.
assumption.
Qed.
Lemma is_interleaving_nil_prop0 (t1 t2 t:Trace) :
(is_interleaving t1 t2 t)
-> (
(t <> nil)
<-> ( (t1 <> nil) \/ (t2 <> nil) )
).
Proof.
intros H.
dependent induction t generalizing t1 t2.
- inversion H.
+ destruct H0. destruct H1.
symmetry in H2. destruct H2.
split ; intros.
* left. assumption.
* destruct H0 ; assumption.
+ destruct H0. destruct H1.
symmetry in H2. destruct H2.
split ; intros.
* left. assumption.
* destruct H0 ; assumption.
- split ; intro.
+ inversion H.
* right. intro. discriminate.
* left. assumption.
* left. intro. discriminate.
* right. intro. discriminate.
+ intro. discriminate.
Qed.
Lemma is_interleaving_nil_prop1 (t1 t2: Trace) :
(is_interleaving t1 t2 nil)
-> ( (t1 = nil) /\ (t2 = nil) ).
Proof.
intros H.
inversion H ; split ; reflexivity.
Qed.
Lemma is_interleaving_nil_prop2 (t t2: Trace) :
(is_interleaving nil t2 t)
-> (t2 = t).
Proof.
intros H.
dependent induction H.
- reflexivity.
- reflexivity.
- assert (t2=t).
{ apply IHis_interleaving.
trivial.
}
destruct H0.
reflexivity.
Qed.
Lemma is_interleaving_nil_prop3 (t1 t: Trace) :
(is_interleaving t1 nil t)
-> (t1 = t).
Proof.
intros H.
dependent induction H.
- reflexivity.
- reflexivity.
- assert (t1=t).
{ apply IHis_interleaving.
trivial.
}
destruct H0.
reflexivity.
Qed.
Lemma is_interleaving_commutativity (t1 t2 t:Trace) :
(is_interleaving t1 t2 t) <-> (is_interleaving t2 t1 t).
Proof.
dependent induction t generalizing t1 t2.
- split ; intros ; apply is_interleaving_nil_prop1 in H
; destruct H ; symmetry in H ; destruct H ; symmetry in H0 ; destruct H0
; apply interleaving_nil_left.
- split ; intros.
+ inversion H.
* apply interleaving_nil_right.
* apply interleaving_nil_left.
* destruct H1. apply interleaving_cons_right.
apply IHt. assumption.
* destruct H2. apply interleaving_cons_left.
apply IHt. assumption.
+ inversion H.
* apply interleaving_nil_right.
* apply interleaving_nil_left.
* destruct H1. apply interleaving_cons_right.
apply IHt. assumption.
* destruct H2. apply interleaving_cons_left.
apply IHt. assumption.
Qed.
Lemma is_interleaving_assoc (t1 t2 t3 tmA tmB t:Trace):
(is_interleaving t1 t2 tmA)
-> (is_interleaving t2 t3 tmB)
-> ( (is_interleaving tmA t3 t) <-> (is_interleaving t1 tmB t)).
Proof.
Admitted.
(**
*** Weak Sequencing
As explained earlier, the weak sequencing operator on traces relies upon a notion of "conflict" between actions.
To encode it in code, I define the "no_conflict" inductive predicate such that (no_conflict t a)
states that there are not actions in t that occur on the same lifeline as action "a".
This predicate can be inferred inductively from the following two rules:
- "no_conflict_nil", which states that for any action "a", there can be no conflict between "a" and the empty trace
- "no_conflict_cons", which states that for any action "a" and trace (a'::t) which starts with action "a'" as its head, if "a" and "a'" occur on different lifelines and there is no conflict between "a" and "t" then there is no conflict between "a" and (a'::t)
**)
Inductive no_conflict : Trace -> Action -> Prop :=
| no_conflict_nil : forall (a:Action), (no_conflict nil a)
| no_conflict_cons : forall (a a':Action) (t:Trace),
(
(not ((lifeline a) = (lifeline a')))
/\ (no_conflict t a)
) -> (no_conflict (a'::t) a).
(**
As for the interleaving, I formalise the weak sequencing operator in Coq using an inductive predicate
"is_weak_seq" such that
"(is_weak_seq t1 t2 t)" states the membership of a given trace t
into the set of weakly sequenced traces between traces t1 and t2.
This inductive predicate can be inferred inductively using four construction rules:
- "weak_seq_nil_left" which states that for any trace t, t is a weak sequence of the empty trace and t
- "weak_seq_nil_right" which states that for any trace t, t is a weak sequence of t and the empty trace
- "weak_seq_cons_left" which states that for any weak sequence t of traces t1 and t2, (a::t) is a weak sequence of (a::t1) and t2
- "weak_seq_cons_right" which states that for any weak sequence t of traces t1 and t2, if there is no conflict between "a" and t1 then (a::t) is a weak sequence of t1 and (a::t2)
Those two last rules signify that, when constructing a weak sequence:
- we can freely add actions from the left-hand side trace t1
- but we only allow the addition of events from t2 if they are not preempted by the occurence of events from t1
**)
Inductive is_weak_seq : Trace -> Trace -> Trace -> Prop :=
| weak_seq_nil_left : forall (t:Trace),
(is_weak_seq nil t t)
| weak_seq_nil_right : forall (t:Trace),
(is_weak_seq t nil t)
| weak_seq_cons_left : forall (t t1 t2:Trace) (a:Action),
(is_weak_seq t1 t2 t) -> (is_weak_seq (a::t1) t2 (a::t))
| weak_seq_cons_right : forall (t t1 t2:Trace) (a:Action),
(is_weak_seq t1 t2 t)
-> (no_conflict t1 a)
-> (is_weak_seq t1 (a::t2) (a::t)).
(**
In a similar fashion to what I did for the interleaving operator, I state some properties of the weak sequencing operator
**)
Lemma is_weak_seq_existence (t1 t2:Trace) :
exists t:Trace, is_weak_seq t1 t2 t.
Proof.
dependent induction t1.
- exists t2. apply weak_seq_nil_left.
- specialize IHt1 with (t2:=t2).
destruct IHt1.
exists (a::x).
apply weak_seq_cons_left.
assumption.
Qed.
Lemma is_weak_seq_nil_prop0 (t1 t2 t:Trace) :
(is_weak_seq t1 t2 t)
-> (
(t <> nil)
<-> ( (t1 <> nil) \/ (t2 <> nil) )
).
Proof.
intros H.
dependent induction t generalizing t1 t2.
- inversion H.
+ destruct H0. destruct H1.
symmetry in H2. destruct H2.
split ; intros.
* left. assumption.
* destruct H0 ; assumption.
+ destruct H0. destruct H1.
symmetry in H2. destruct H2.
split ; intros.
* left. assumption.
* destruct H0 ; assumption.
- split ; intro.
+ inversion H.
* right. intro. discriminate.
* left. assumption.
* left. intro. discriminate.
* right. intro. discriminate.
+ intro. discriminate.
Qed.
Lemma is_weak_seq_nil_prop1 (t1 t2: Trace) :
(is_weak_seq t1 t2 nil)
-> ( (t1 = nil) /\ (t2 = nil) ).
Proof.
intros H.
inversion H ; split ; reflexivity.
Qed.
Lemma is_weak_seq_nil_prop2 (t1 t2: Trace) :
(is_weak_seq nil t1 t2)
-> (t1 = t2).
Proof.
intros H.
assert (H0:=H).
dependent induction H.
- reflexivity.
- reflexivity.
- assert (t2=t).
{ apply IHis_weak_seq.
- trivial.
- assumption.
}
destruct H2.
reflexivity.
Qed.
Lemma is_weak_seq_nil_prop3 (t1 t2: Trace) :
(is_weak_seq t1 nil t2)
-> (t1 = t2).
Proof.
intros H.
dependent induction H.
- reflexivity.
- reflexivity.
- assert (t1=t).
{ apply IHis_weak_seq.
trivial.
}
destruct H0.
reflexivity.
Qed.
Lemma is_weak_seq_assoc (t1 t2 t3 tmA tmB t:Trace):
(is_weak_seq t1 t2 tmA)
-> (is_weak_seq t2 t3 tmB)
-> ( (is_weak_seq tmA t3 t) <-> (is_weak_seq t1 tmB t)).
Proof.
Admitted.
(**
*** Remark on the notion of scheduling
The three previously mentioned operators...
- concatenation (also called strict sequencing)
- weak sequencing
- interleaving
... can be understood as scheduling operators i.e. they allow or disallow some reordering of
events from traces t1 and t2 in the construction of a merged trace t
I encode this notion of a type of scheduling into the inductive type "ScheduleKind" defined below.
**)
Inductive ScheduleKind : Set :=
|lstrict:ScheduleKind
|lseq:ScheduleKind
|lpar:ScheduleKind.
(**
*** Merge operator
The merge operator can be understood as a n-ary extension of the three previously defined scheduling operators.
For any list of traces [t1,t2,...,tn] and for any trace t_merge:
- saying that "t_merge is a merger of [t1,t2,...,tn] according to strict sequencing" signifies that t_merge is the concatenated trace t1++t2++...++tn
- saying that "t_merge is a merger of [t1,t2,...,tn] according to weak sequencing" signifies that t_merge verifies (is_weak_seq t1 t_remain t_merge) with t_remain being "a merger of [t2,...,tn] according to weak sequencing" and so on
- saying that "t_merge is a merger of [t1,t2,...,tn] according to interleaving" signifies that t_merge verifies (is_interleaving t1 t_remain t_merge) with t_remain being "a merger of [t2,...,tn] according to interleaving" and so on
I formalise the merge operator in Coq using an inductive predicate "n_merge_schedule"
such that for any schedule kind lk, for any list of non-empty traces "subs", and for any trace "t",
"(n_merge_schedule lk subs t)" states the membership of a given trace t into the set of mergers of traces from subs according to lk.
This inductive predicate can be inferred inductively using four construction rules:
- a construction rule "merge_zero" for the base case, which states that the empty trace is a merger of an empty list of traces
- and three construction rules, each dedicated to one of the three types of scheduling;
- "merge_strict", which states that for any strict-merger t of traces from remain (a list of traces), then t1++t is a strict-merger of t1::remain
- "merge_seq", which states that for any (weak) seq-merger t of traces from remain (a list of traces), then, for any trace t_merge verifying (is_weak_seq t1 t t_merge), we have that t_merge is a seq-merger of t1::remain
- "merge_par", which states that for any par-merger t of traces from remain (a list of traces), then, for any trace t_merge verifying (is_interleaving t1 t t_merge), we have that t_merge is a par-merger of t1::remain
- let us note that for all three rules, we only allow the addition of non-empty traces in the list of traces to be merged. This is a modelisation choice.
**)
Inductive n_merge_schedule :
ScheduleKind -> list Trace -> Trace -> Prop :=
| merge_zero : forall (lk:ScheduleKind),
(n_merge_schedule lk nil nil)
| merge_strict : forall (remain:list Trace) (t_first t_rep:Trace),
(t_first <> nil)
-> (n_merge_schedule lstrict remain t_rep)
-> (n_merge_schedule lstrict (t_first::remain) (t_first++t_rep))
| merge_seq : forall (remain:list Trace) (t_first t_rep t_merge:Trace),
(t_first <> nil)
-> (n_merge_schedule lseq remain t_rep)
-> (is_weak_seq t_first t_rep t_merge)
-> (n_merge_schedule lseq (t_first::remain) t_merge)
| merge_par : forall (remain:list Trace) (t_first t_rep t_merge:Trace),
(t_first <> nil)
-> (n_merge_schedule lpar remain t_rep)
-> (is_interleaving t_first t_rep t_merge)
-> (n_merge_schedule lpar (t_first::remain) t_merge).
(**
In a similar fashion to what was done for the three scheduling operators,
one can define an prove some properties for the merge operator
**)
Lemma n_merge_schedule_existence
(lk:ScheduleKind) (subs:list Trace) :
(forall t0:Trace, (In t0 subs) -> (t0<>nil) )
-> (exists t:Trace, (n_merge_schedule lk subs t)).
Proof.
intros.
dependent induction subs.
- exists nil. apply merge_zero.
- destruct IHsubs.
+ intros. apply H. simpl. right. assumption.
+ destruct lk.
{ exists (a ++ x).
apply merge_strict.
- apply H. simpl. left. reflexivity.
- assumption.
}
{ pose proof (is_weak_seq_existence a x).
destruct H1 as (t,H1).
exists t.
apply (merge_seq subs a x t).
- apply H. simpl. left. reflexivity.
- assumption.
- assumption.
}
{ pose proof (is_interleaving_existence a x).
destruct H1 as (t,H1).
exists t.
apply (merge_par subs a x t).
- apply H. simpl. left. reflexivity.
- assumption.
- assumption.
}
Qed.
Lemma n_merge_schedule_nil_prop0 (lk:ScheduleKind) (subs:list Trace) (t:Trace) :
(n_merge_schedule lk subs t)
-> (
(t <> nil)
<-> (exists t0:Trace, (In t0 subs) /\ (t0 <> nil))
).
Proof.
intros.
split ; intros.
- dependent induction subs.
+ inversion H.
destruct H3. contradiction.
+ inversion H.
* destruct H2. destruct H1. destruct H3.
destruct H5.
{ exists t_first.
split.
- simpl. left. reflexivity.
- assumption.
}
* destruct H2. destruct H1. destruct H4.
destruct H6.
{ exists t_first.
split.
- simpl. left. reflexivity.
- assumption.
}
* destruct H2. destruct H1. destruct H4.
destruct H6.
{ exists t_first.
split.
- simpl. left. reflexivity.
- assumption.
}
- destruct H0 as (t0,Ht0).
destruct Ht0 as (Hin,Ht0).
dependent induction subs.
+ inversion H. contradiction.
+ inversion H.
* destruct H1. destruct H0. destruct H2.
destruct H4.
simpl in *.
destruct Hin.
{ destruct H0.
apply (concat_nil_prop0 t_first t_rep).
left. assumption.
}
{ apply (concat_nil_prop0 t_first t_rep).
left. assumption.
}
* destruct H1. destruct H0. destruct H3.
destruct H5.
simpl in *.
destruct Hin.
{ destruct H0.
apply (is_weak_seq_nil_prop0 t_first t_rep).
- assumption.
- left. assumption.
}
{ apply (is_weak_seq_nil_prop0 t_first t_rep).
- assumption.
- left. assumption.
}
* destruct H1. destruct H0. destruct H3.
destruct H5.
simpl in *.
destruct Hin.
{ destruct H0.
apply (is_interleaving_nil_prop0 t_first t_rep).
- assumption.
- left. assumption.
}
{ apply (is_interleaving_nil_prop0 t_first t_rep).
- assumption.
- left. assumption.
}
Qed.
Lemma n_merge_schedule_nil_prop1 (lk:ScheduleKind) (subs:list Trace) :
(n_merge_schedule lk subs nil)
-> (subs=nil).
Proof.
intros.
inversion H.
- reflexivity.
- destruct H3. apply app_eq_nil in H0.
destruct H0. symmetry in H3. destruct H3.
rewrite app_nil_r in H1. contradiction.
- symmetry in H5. destruct H5. apply is_weak_seq_nil_prop1 in H2.
destruct H2.
symmetry in H2. destruct H2. contradiction.
- symmetry in H5. destruct H5. apply is_interleaving_nil_prop1 in H2.
destruct H2.
symmetry in H2. destruct H2. contradiction.
Qed.
Lemma n_merge_schedule_nil_prop2 (lk:ScheduleKind) (t_merge:Trace) :
(n_merge_schedule lk nil t_merge)
-> (t_merge=nil).
Proof.
intros.
dependent induction t_merge.
- reflexivity.
- inversion H.
Qed.
Lemma n_merge_schedule_nonil_prop0 (lk:ScheduleKind) (subs:list Trace) (t:Trace) :
(n_merge_schedule lk subs t)
-> (forall t0 : Trace, In t0 subs -> t0<>nil).
Proof.
intros.
dependent induction H.
- contradiction.
- inversion H1.
+ destruct H2. assumption.
+ apply IHn_merge_schedule. assumption.
- inversion H2.
+ destruct H3. assumption.
+ apply IHn_merge_schedule. assumption.
- inversion H2.
+ destruct H3. assumption.
+ apply IHn_merge_schedule. assumption.
Qed.
Lemma n_merge_schedule_single_merge (lk:ScheduleKind) (x t:Trace) :
(n_merge_schedule lk (t :: nil) x)
-> (t=x).
Proof.
Admitted.
Lemma n_merge_add_left (lk:ScheduleKind) (subs:list Trace) (t1 t:Trace) (a:Action):
(n_merge_schedule lk (t1 :: subs) t)
-> (n_merge_schedule lk ((a::t1) :: subs) (a::t)).
Proof.
Admitted.
Lemma n_merge_seq_reorder_prop1 (sub1 sub3 : list Trace) (t2 t : Trace) (a:Action):
(n_merge_schedule lseq (sub1 ++ (t2::sub3)) t)
-> (forall t1:Trace, (In t1 sub1) -> (no_conflict t1 a))
-> (n_merge_schedule lseq (sub1 ++ ((a::t2)::sub3)) (a::t)).
Proof.
intros.
dependent induction sub1.
- simpl in *.
apply n_merge_add_left. assumption.
- inversion H.
destruct H1.
symmetry in H6. destruct H6.
apply (merge_seq (sub1 ++ (a0::t2)::sub3) t_first (a0::t_rep)).
+ assumption.
+ apply IHsub1.
* assumption.
* intros. apply H0. simpl. right. assumption.
+ apply weak_seq_cons_right.
* assumption.
* apply H0. simpl. left. reflexivity.
Qed.
Lemma n_merge_lseq_bi_assoc (sub1 sub2 : list Trace) (t1 t2 t : Trace):
(n_merge_schedule lseq sub1 t1)
-> (n_merge_schedule lseq sub2 t2)
-> (is_weak_seq t1 t2 t)
-> (n_merge_schedule lseq (sub1++sub2) t).
Proof.
intros.
dependent induction H generalizing sub2 t2 t.
- simpl.
apply is_weak_seq_nil_prop2 in H1.
destruct H1. assumption.
- pose proof (is_weak_seq_existence t_rep t2).
destruct H4 as (t3,H4).
apply (merge_seq (remain++sub2) t_first t3 t).
+ assumption.
+ apply (IHn_merge_schedule sub2 t2 t3).
* reflexivity.
* assumption.
* assumption.
+ apply (is_weak_seq_assoc t_first t_rep t2 t_merge) ; assumption.
Qed.
Lemma n_merge_lseq_sandwich (sub1 sub3 : list Trace) (t1 t2 t3 tm t : Trace):
(*(t2<>nil)
->*) (n_merge_schedule lseq sub1 t1)
-> (n_merge_schedule lseq sub3 t3)
-> (is_weak_seq t2 t3 tm)
-> (is_weak_seq t1 tm t)
-> (n_merge_schedule lseq (sub1 ++ t2 :: sub3) t).
Proof.
intros.
apply (n_merge_lseq_bi_assoc sub1 (t2::sub3) t1 tm).
- assumption.
- apply (merge_seq sub3 t2 t3 tm).
+ admit.
+ assumption.
+ assumption.
- assumption.
Admitted.
Lemma n_merge_lpar_bi_assoc (sub1 sub2 : list Trace) (t1 t2 t : Trace):
(n_merge_schedule lpar sub1 t1)
-> (n_merge_schedule lpar sub2 t2)
-> (is_interleaving t1 t2 t)
-> (n_merge_schedule lpar (sub1++sub2) t).
Proof.
intros.
dependent induction H generalizing sub2 t2 t.
- simpl.
apply is_interleaving_nil_prop2 in H1.
destruct H1. assumption.
- pose proof (is_interleaving_existence t_rep t2).
destruct H4 as (t3,H4).
apply (merge_par (remain++sub2) t_first t3 t).
+ assumption.
+ apply (IHn_merge_schedule sub2 t2 t3).
* reflexivity.
* assumption.
* assumption.
+ apply (is_interleaving_assoc t_first t_rep t2 t_merge) ; assumption.
Qed.
(**
*** Some considerations on the distributivity of "no_conflict" w.r.t. the previous operators
In the following we demonstrate the distributive composition of the "no_conflict" function w.r.t.
the three scheduling operators and the merge operator
**)
Lemma no_conflict_concat (t1 t2:Trace) (a:Action) :
( (no_conflict t1 a) /\ (no_conflict t2 a) )
<-> (no_conflict (t1++t2) a).
Proof.
split ; intros H.
- destruct H.
dependent induction t1.
+ simpl. assumption.
+ simpl. apply no_conflict_cons.
inversion H.
destruct H4.
split.
* assumption.
* apply IHt1.
{ assumption. }
{ assumption. }
- dependent induction t1.
+ simpl in H.
split.
* apply no_conflict_nil.
* assumption.
+ simpl in H.
inversion H.
destruct H3.
apply IHt1 in H4.
destruct H4.
split.
* apply no_conflict_cons.
split.
{ assumption. }
{ assumption. }