-
Notifications
You must be signed in to change notification settings - Fork 1
/
coq_hibou_label_equivalent_terms.v
3290 lines (3087 loc) · 109 KB
/
coq_hibou_label_equivalent_terms.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 determination of equivalent interaction terms w.r.t. a denotational semantics
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 an equivalence relation on interaction terms
- prove that equivalent interaction terms as defined by this relation have the same semantics
This proof accompanies the manuscript of my thesis
The coq file itself is hosted on the following repository:
- #<a href="https://github.com/erwanM974/coq_hibou_label_equivalent_terms">https://github.com/erwanM974/coq_hibou_label_equivalent_terms</a>#
** Context
This formal semantics defines which are the behaviors that are specified by an interaction model
(akin to Message Sequence Charts or UML Sequence Diagrams).
Those behaviors are described by traces which are sequences of atomic actions that can be observed
on the interfaces of a distributed system's sub-systems.
Those atomic actions correspond to the occurence of communication events i.e. either the emission or the reception of
a given message on a given sub-system.
** Dependencies
Below are listed the libraries required for this Coq proof.
- "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.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.
** Substitutions and eliminations of elements in lists
In the following, I define some functions to manipulate lists.
To do so, I use Fixpoints and as a result those functions are checked by Coq's termination checker.
- "list_replace_nth" replaces the "n-th" element of a list by another element
- "list_remove_nth" removes the "n-th" element of a list
**)
Fixpoint list_replace_nth (A:Type) (n:nat) (l:list A) (x:A) {struct l} : list A :=
match n, l with
| O, e :: l' => x :: l'
| O, other => nil
| S m, nil => nil
| S m, e :: l' => e :: (list_replace_nth A m l' x)
end.
Fixpoint list_remove_nth (A:Type) (n:nat) (l:list A) {struct l} : list A :=
match n, l with
| O, e :: l' => l'
| O, other => nil
| S m, nil => nil
| S m, e :: l' => e :: (list_remove_nth A m l')
end.
(**
** 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).
(**
To distinguish between emissions "a!m" and receptions "b?m" 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.
(* =========================================================== *)
(**
* 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).
Functions "list_replace_nth" and "subs_remove" that were defined above to replace and remove elements in generic lists
are aliased and specialised for use in lists of traces as "subs_replace" and "subs_remove"
**)
Definition Trace : Type := list Action.
Definition subs_replace (n:nat) (subs:list Trace) (t:Trace) : list Trace
:= list_replace_nth Trace n subs t.
Definition subs_remove (n:nat) (subs:list Trace) : list Trace
:= list_remove_nth Trace n subs.
(**
** 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.
**)
(**
*** 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 include:
- the guarantee of the existence of an interleaving t (at least one) for any traces t1 and t2 "is_interleaving_existence"
- "is_interleaving_nil_prop1", which states that if the empty trace is an interleaving of t1 and t2, then both t1 and t2 must be empty
- "is_interleaving_nil_prop2", which states that if t is an interleaving of the empty trace and t2, then t=t2
- "is_interleaving_nil_prop3", which states that if t is an interleaving of t1 and the empty trace, then t=t1
- "is_interleaving_split", which states that if a trace of the form (a::t) is an interleaving of traces t1 and t2 then the head action "a" can be found in:
- either t1, which implies the existence of trace t3 such that t1=a::t3 and (is_interleaving t3 t2 t)
- or t2, which implies the existence of trace t3 such that t2=a::t3 and (is_interleaving t1 t3 t)
**)
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_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_split (a:Action) (t1 t2 t:Trace) :
(is_interleaving t1 t2 (a :: t))
-> (
(exists t3:Trace, (t2=a::t3)/\(is_interleaving t1 t3 t))
\/ (exists t3:Trace, (t1=a::t3)/\(is_interleaving t3 t2 t))
).
Proof.
intros.
dependent induction H.
- left. exists t. split.
+ reflexivity.
+ apply interleaving_nil_left.
- right. exists t. split.
+ reflexivity.
+ apply interleaving_nil_right.
- right. exists t1. split.
+ reflexivity.
+ assumption.
- left. exists t2. split.
+ reflexivity.
+ assumption.
Qed.
(**
Other interesting properties of the "is_interleaving" include:
- "is_interleaving_symmetry", which states that the operator is symmetric i.e. if t is an interleaving of t1 and t2 then it is also an interleaving of t2 and t1
- "is_interleaving_left_associativity", which states that if t is an interleaving of t1 and t2 and if t1 can be decomposed as an interleaving of t1A and t1B then t is an interleaving of t1A with a certain tm that is an interleaving of t1B and t2
- "is_interleaving_right_associativity", which states that if t is an interleaving of t1 and t2 and if t2 can be decomposed as an interleaving of t2A and t2B then t is an interleaving of a certain tm with t2B, with that certain tm an interleaving of t1 and t2A
**)
Lemma is_interleaving_symmetry (t1 t2 t:Trace) :
(is_interleaving t1 t2 t) <-> (is_interleaving t2 t1 t).
Proof.
split ; intros.
- dependent induction t generalizing t1 t2.
+ apply is_interleaving_nil_prop1 in H.
destruct H. symmetry in H. destruct H.
symmetry in H0. destruct H0.
apply interleaving_nil_left.
+ apply is_interleaving_split in H.
destruct H.
* destruct H as (t3,H).
destruct H.
symmetry in H. destruct H.
apply interleaving_cons_left.
apply IHt in H0.
assumption.
* destruct H as (t3,H).
destruct H.
symmetry in H. destruct H.
apply interleaving_cons_right.
apply IHt in H0.
assumption.
- dependent induction t generalizing t1 t2.
+ apply is_interleaving_nil_prop1 in H.
destruct H. symmetry in H. destruct H.
symmetry in H0. destruct H0.
apply interleaving_nil_left.
+ apply is_interleaving_split in H.
destruct H.
* destruct H as (t3,H).
destruct H.
symmetry in H. destruct H.
apply interleaving_cons_left.
apply IHt in H0.
assumption.
* destruct H as (t3,H).
destruct H.
symmetry in H. destruct H.
apply interleaving_cons_right.
apply IHt in H0.
assumption.
Qed.
Lemma is_interleaving_left_associativity (t1 t1A t1B t2 t:Trace) :
( (is_interleaving t1A t1B t1) /\ (is_interleaving t1 t2 t) )
-> (exists tm:Trace, (is_interleaving t1B t2 tm) /\ (is_interleaving t1A tm t) ).
Proof.
intros.
destruct H.
dependent induction t generalizing t1 t1A t1B t2.
- apply is_interleaving_nil_prop1 in H0.
destruct H0.
symmetry in H0. destruct H0.
symmetry in H1. destruct H1.
apply is_interleaving_nil_prop1 in H.
destruct H.
symmetry in H0. destruct H0.
symmetry in H. destruct H.
exists nil.
split ; apply interleaving_nil_left.
- inversion H0.
+ destruct H1.
symmetry in H2. destruct H2.
symmetry in H3. destruct H3.
clear H0.
apply is_interleaving_nil_prop1 in H.
destruct H.
symmetry in H0. destruct H0.
symmetry in H. destruct H.
exists (a::t).
split ; apply interleaving_nil_left.
+ destruct H2.
symmetry in H1. destruct H1.
symmetry in H3. destruct H3.
clear H0.
exists t1B.
split.
* apply interleaving_nil_right.
* assumption.
+ destruct H2.
symmetry in H3. destruct H3.
symmetry in H1. destruct H1.
symmetry in H5. destruct H5.
clear H0.
inversion H.
{ destruct H0. destruct H1.
symmetry in H2. destruct H2.
clear H.
exists (a::t).
split.
- apply interleaving_cons_left.
assumption.
- apply interleaving_nil_left.
}
{ destruct H0. destruct H1.
symmetry in H2. destruct H2.
clear H.
exists t2.
split.
- apply interleaving_nil_left.
- apply interleaving_cons_left.
assumption.
}
{ destruct H1.
symmetry in H0. destruct H0.
symmetry in H2. destruct H2.
symmetry in H5. destruct H5.
specialize IHt with (t1:=t3) (t1A:=t1) (t1B:=t1B) (t2:=t2).
assert (exists tm : Trace, is_interleaving t1B t2 tm /\ is_interleaving t1 tm t).
{ apply IHt ; assumption. }
destruct H0 as (tm,H0).
destruct H0.
exists tm.
split.
- assumption.
- apply interleaving_cons_left.
assumption.
}
{ symmetry in H1. destruct H1.
symmetry in H0. destruct H0.
destruct H5. destruct H2.
specialize IHt with (t1:=t0) (t1A:=t1A) (t1B:=t4) (t2:=t2).
assert (exists tm : Trace, is_interleaving t4 t2 tm /\ is_interleaving t1A tm t).
{ apply IHt ; assumption. }
destruct H0 as (tm,H0).
destruct H0.
exists (a::tm).
split.
- apply interleaving_cons_left. assumption.
- apply interleaving_cons_right. assumption.
}
+ destruct H3.
symmetry in H1. destruct H1.
symmetry in H2. destruct H2.
symmetry in H5. destruct H5.
clear H0.
specialize IHt with (t1:=t1) (t1A:=t1A) (t1B:=t1B) (t2:=t4).
assert (exists tm : Trace, is_interleaving t1B t4 tm /\ is_interleaving t1A tm t).
{ apply IHt ; assumption. }
destruct H0 as (tm,H0).
destruct H0.
exists (a::tm).
split.
{ apply interleaving_cons_right.
assumption. }
{ apply interleaving_cons_right.
assumption.
}
Qed.
Lemma is_interleaving_right_associativity (t1 t2 t2A t2B t:Trace) :
( (is_interleaving t2A t2B t2) /\ (is_interleaving t1 t2 t) )
-> (exists tm:Trace, (is_interleaving t1 t2A tm) /\ (is_interleaving tm t2B t) ).
Proof.
intros.
destruct H.
apply is_interleaving_symmetry in H0.
assert (exists tm : Trace, is_interleaving t2A t1 tm /\ is_interleaving t2B tm t).
{ apply (is_interleaving_left_associativity t2 t2B t2A t1 t).
split.
- apply is_interleaving_symmetry. assumption.
- assumption.
}
destruct H1 as (tm,H1).
destruct H1.
exists tm.
split.
- apply is_interleaving_symmetry. assumption.
- apply is_interleaving_symmetry. assumption.
Qed.
(**
*** 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 and prove in the following some properties on the weak sequencing operator:
- the guarantee of the existence of a weak sequence t (at least one) for any traces t1 and t2 "is_weak_seq_existence"
- "is_weak_seq_nil_prop1", which states that if the empty trace is a weak sequence of t1 and t2, then both t1 and t2 must be empty
- "is_weak_seq_nil_prop2", which states that if t is a weak sequence of the empty trace and t2, then t=t2
- "is_weak_seq_nil_prop3", which states that if t is a weak sequence of t1 and the empty trace, then t=t1
- "is_weak_seq_split", which states that if (a :: t) is a weak sequence of t1 and t2, then either t1 starts with "a" or t2 starts with "a" and there is no conflict between t1 and "a"
**)
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_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_split (a:Action) (t1 t2 t:Trace) :
(is_weak_seq t1 t2 (a :: t))
-> (
( (no_conflict t1 a) /\ (exists t3:Trace, (t2=a::t3)/\(is_weak_seq t1 t3 t)) )
\/ (exists t3:Trace, (t1=a::t3)/\(is_weak_seq t3 t2 t))
).
Proof.
intros.
dependent induction H.
- left. split.
+ apply no_conflict_nil.
+ exists t. split.
* reflexivity.
* apply weak_seq_nil_left.
- right. exists t. split.
+ reflexivity.
+ apply weak_seq_nil_right.
- right. exists t1. split.
+ reflexivity.
+ assumption.
- left. split.
+ assumption.
+ exists t2.
split.
* reflexivity.
* assumption.
Qed.
(**
Before stating and proving some properties concerning a weak form of associativity for the weak sequencing operator, let us digress on the
relationships of the "no_conflict" function w.r.t. the operators.
In particular, we introduce the following Lemmas:
- "no_conflict_concat", which states that the fact that t1 and t2 both have no conflict w.r.t. an action a equates to the fact that their concatenation t1++t2 has no conflict w.r.t. action a
- "no_conflict_interleaving", which is a similar lemma, but instead of considering the concatenation t1++t2, we consider any interleaving t of t1 and t2
- "no_conflict_weak_seq", which is also the same property, but instead of considering the concatenation t1++t2, we consider any weak sequence t of t1 and t2
In particular, the last Lemma "no_conflict_weak_seq" will be required to prove some further properties on the weak sequencing operator
given that its definition is tightly interlinked with that of no_conflict.
**)
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. }
* assumption.
Qed.
Lemma no_conflict_interleaving (t1 t2 t :Trace) (a:Action) :
(is_interleaving t1 t2 t)
-> (
( (no_conflict t1 a) /\ (no_conflict t2 a) )
<-> (no_conflict t a)
).
Proof.
split ; intros H1.
- destruct H1.
dependent induction H.
+ assumption.
+ assumption.
+ apply no_conflict_cons.
inversion H0. destruct H5.
split.
* assumption.
* apply IHis_interleaving ; assumption.
+ apply no_conflict_cons.
inversion H1. destruct H5.
split.
* assumption.
* apply IHis_interleaving ; assumption.
- dependent induction H.
+ split.
* apply no_conflict_nil.
* assumption.
+ split.
* assumption.
* apply no_conflict_nil.
+ inversion H1.
destruct H4.
apply IHis_interleaving in H5.
destruct H5.
split.
* apply no_conflict_cons.
split ; assumption.
* assumption.
+ inversion H1.
destruct H4.
apply IHis_interleaving in H5.
destruct H5.
split.
* assumption.
* apply no_conflict_cons.
split ; assumption.
Qed.
Lemma no_conflict_weak_seq (t1 t2 t :Trace) (a:Action) :
(is_weak_seq t1 t2 t)
-> (
( (no_conflict t1 a) /\ (no_conflict t2 a) )
<-> (no_conflict t a)
).
Proof.
split ; intros H1.
- destruct H1.
dependent induction H.
+ assumption.
+ assumption.
+ apply no_conflict_cons.
inversion H0. destruct H5.
split.
* assumption.
* apply IHis_weak_seq ; assumption.
+ apply no_conflict_cons.
inversion H2. destruct H6.
split.
* assumption.
* apply IHis_weak_seq ; assumption.
- dependent induction H.
+ split.
* apply no_conflict_nil.
* assumption.
+ split.
* assumption.
* apply no_conflict_nil.
+ inversion H1.
destruct H4.
apply IHis_weak_seq in H5.
destruct H5.
split.
* apply no_conflict_cons.
split ; assumption.
* assumption.
+ inversion H1.
destruct H5.
apply IHis_weak_seq in H6.
destruct H6.
split.
* assumption.
* apply no_conflict_cons.
split ; assumption.
Qed.
(**
Like what we did for the interleaving operator, let us now study some properties of associativity for the weak sequencing operator.
The Lemmas:
- "is_weak_seq_left_associativity" states that if t is a weak sequence of t1 and t2 and if t1 can be decomposed as a weak sequence of t1A and t1B then t is a weak sequence of t1A with a certain tm that is a weak sequence of t1B and t2. Let us remark that we need the additional Lemma "no_conflict_weak_seq" for this proof.
- "is_weak_seq_right_associativity" states that if t is a weak sequence of t1 and t2 and if t2 can be decomposed as a weak sequence of t2A and t2B then t is a weak sequence of a certain tm with t2B, with that certain tm a weak sequence of t1 and t2A. We also need "no_conflict_weak_seq" here.
**)
Lemma is_weak_seq_left_associativity (t1 t1A t1B t2 t:Trace) :
( (is_weak_seq t1A t1B t1) /\ (is_weak_seq t1 t2 t) )
-> (exists tm:Trace, (is_weak_seq t1B t2 tm) /\ (is_weak_seq t1A tm t) ).
Proof.
intros.
destruct H.
dependent induction t generalizing t1 t1A t1B t2.
- apply is_weak_seq_nil_prop1 in H0.
destruct H0.
symmetry in H0. destruct H0.
symmetry in H1. destruct H1.
apply is_weak_seq_nil_prop1 in H.
destruct H.
symmetry in H0. destruct H0.
symmetry in H. destruct H.
exists nil.
split ; apply weak_seq_nil_left.
- inversion H0.
+ destruct H1.
symmetry in H2. destruct H2.
symmetry in H3. destruct H3.
clear H0.
apply is_weak_seq_nil_prop1 in H.
destruct H.
symmetry in H0. destruct H0.
symmetry in H. destruct H.
exists (a::t).
split ; apply weak_seq_nil_left.
+ destruct H2.
symmetry in H1. destruct H1.
symmetry in H3. destruct H3.
clear H0.
exists t1B.
split.
* apply weak_seq_nil_right.
* assumption.
+ destruct H2.
symmetry in H3. destruct H3.
symmetry in H1. destruct H1.
symmetry in H5. destruct H5.
clear H0.
inversion H.
{ destruct H0. destruct H1.
symmetry in H2. destruct H2.
clear H.
exists (a::t).
split.
- apply weak_seq_cons_left.
assumption.
- apply weak_seq_nil_left.
}
{ destruct H0. destruct H1.
symmetry in H2. destruct H2.
clear H.
exists t2.
split.
- apply weak_seq_nil_left.
- apply weak_seq_cons_left.
assumption.
}
{ destruct H1.
symmetry in H0. destruct H0.
symmetry in H2. destruct H2.
symmetry in H5. destruct H5.
specialize IHt with (t1:=t3) (t1A:=t1) (t1B:=t1B) (t2:=t2).
assert (exists tm : Trace, is_weak_seq t1B t2 tm /\ is_weak_seq t1 tm t).
{ apply IHt ; assumption. }
destruct H0 as (tm,H0).
destruct H0.
exists tm.
split.
- assumption.
- apply weak_seq_cons_left.
assumption.
}
{ destruct H1.
symmetry in H0. destruct H0.
destruct H3. destruct H2.
specialize IHt with (t1:=t0) (t1A:=t1) (t1B:=t4) (t2:=t2).
assert (exists tm : Trace, is_weak_seq t4 t2 tm /\ is_weak_seq t1 tm t).
{ apply IHt ; assumption. }
destruct H0 as (tm,H0).
destruct H0.
exists (a::tm).
split.
- apply weak_seq_cons_left. assumption.
- apply weak_seq_cons_right.
+ assumption.
+ assumption.
}
+ destruct H4.
symmetry in H1. destruct H1.
symmetry in H2. destruct H2.
symmetry in H3. destruct H3.
clear H0.
specialize IHt with (t1:=t1) (t1A:=t1A) (t1B:=t1B) (t2:=t4).
assert (exists tm : Trace, is_weak_seq t1B t4 tm /\ is_weak_seq t1A tm t).
{ apply IHt ; assumption. }
destruct H0 as (tm,H0).
destruct H0.
exists (a::tm).
apply (no_conflict_weak_seq t1A t1B t1 a) in H.
apply H in H6. destruct H6.
split.
{ apply weak_seq_cons_right ; assumption. }
{ apply weak_seq_cons_right ; assumption. }
Qed.
Lemma is_weak_seq_right_associativity (t1 t2 t2A t2B t:Trace) :
( (is_weak_seq t2A t2B t2) /\ (is_weak_seq t1 t2 t) )
-> (exists tm:Trace, (is_weak_seq t1 t2A tm) /\ (is_weak_seq tm t2B t) ).
Proof.
intros.
destruct H.
dependent induction t generalizing t1 t2 t2A t2B.
- apply is_weak_seq_nil_prop1 in H0.
destruct H0.
symmetry in H0. destruct H0.
symmetry in H1. destruct H1.
apply is_weak_seq_nil_prop1 in H.
destruct H.
symmetry in H0. destruct H0.
symmetry in H. destruct H.
exists nil.
split ; apply weak_seq_nil_left.
- inversion H0.
+ exists t2A.
split.
* apply weak_seq_nil_left.
* rewrite <- H3. assumption.
+ destruct H2.
apply is_weak_seq_nil_prop1 in H.
destruct H.
symmetry in H. destruct H.
symmetry in H2. destruct H2.
exists (a::t).
split ; apply weak_seq_nil_right.
+ destruct H2.
symmetry in H1. destruct H1.
symmetry in H3. destruct H3.
symmetry in H5. destruct H5.
assert (exists tm : Trace, is_weak_seq t3 t2A tm /\ is_weak_seq tm t2B t).
{ apply (IHt t3 t2 t2A t2B) ; assumption. }
destruct H1 as (tm,H1). destruct H1.
exists (a::tm).
split.
* apply weak_seq_cons_left. assumption.
* apply weak_seq_cons_left. assumption.
+ destruct H4.
symmetry in H1. destruct H1.
symmetry in H2. destruct H2.
symmetry in H3. destruct H3.
clear H0.
inversion H.
{ destruct H0. destruct H1.
symmetry in H2. destruct H2.
clear H.
exists t1.
split.
- apply weak_seq_nil_right.
- apply weak_seq_cons_right ; assumption.
}
{ destruct H0. destruct H1.
symmetry in H2. destruct H2.
clear H.
exists (a::t).
split.
- apply weak_seq_cons_right ; assumption.