-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUMO.v
1791 lines (1610 loc) · 64.1 KB
/
UMO.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
From VLSM.Lib Require Import Itauto.
From Coq Require Import FunctionalExtensionality.
From stdpp Require Import prelude finite.
From VLSM.Lib Require Import Preamble StdppExtras StdppListSet.
From VLSM.Core Require Import VLSM VLSMProjections Composition Equivocation ProjectionTraces.
From VLSM.Examples Require Import BaseELMO.
(** * ELMO: Protocol Definitions and Properties for UMO
This module contains definitions and properties of UMO components and
the UMO protocol.
*)
Section sec_UMO.
Context
{Address : Type}
`{EqDecision Address}
(State := @State Address)
(Observation := @Observation Address)
(Message := @Message Address).
(** ** Component definition *)
(** The initial state has no observations and the same address as the component. *)
Definition UMO_component_initial_state_prop (i : Address) (st : State) : Prop :=
obs st = [] /\ adr st = i.
Definition UMO_component_initial_state_type (i : Address) : Type :=
{st : State | UMO_component_initial_state_prop i st}.
Program Definition UMO_component_initial_state
(i : Address) : UMO_component_initial_state_type i := MkState [] i.
Next Obligation.
Proof.
by compute.
Defined.
#[export] Instance Inhabited_UMO_component_initial_state_type (i : Address) :
Inhabited (UMO_component_initial_state_type i) :=
populate (UMO_component_initial_state i).
Definition UMO_component_transition
(l : Label) (s : State) (om : option Message)
: State * option Message :=
match l, om with
| Send, Some m => (s, om)
| Send, None =>
let ob := MkObservation Send (MkMessage s) in
let st := s <+> ob in
let msg := Some (MkMessage s) in
(st, msg)
| Receive, None => (s, None)
| Receive, Some m =>
let ob := MkObservation Receive m in
let st := s <+> ob in
let msg := None in
(st, msg)
end.
Inductive UMO_component_valid : Label -> State -> option Message -> Prop :=
| OCV_Send : forall st : State, UMO_component_valid Send st None
| OCV_Receive : forall (st : State) (msg : Message), UMO_component_valid Receive st (Some msg).
Ltac invert_UMO_component_valid :=
repeat match goal with
| H : UMO_component_valid Receive _ None |- _ => inversion H; subst; clear H
| H : UMO_component_valid Send _ (Some _) |- _ => inversion H; subst; clear H
end.
Definition UMO_component_machine (i : Address) : VLSMMachine ELMO_component_type :=
{|
initial_state_prop := UMO_component_initial_state_prop i;
initial_message_prop := const False;
s0 := Inhabited_UMO_component_initial_state_type i;
transition := fun l '(st, om) => UMO_component_transition l st om;
valid := fun l '(st, om) => UMO_component_valid l st om;
|}.
Definition UMO_component (i : Address) : VLSM Message :=
{|
vlsm_type := ELMO_component_type;
vlsm_machine := UMO_component_machine i;
|}.
(** UMO components have a unique initial state. *)
Lemma UMO_component_initial_state_unique :
forall {i : Address} {s1 s2 : State},
UMO_component_initial_state_prop i s1 ->
UMO_component_initial_state_prop i s2 ->
s1 = s2.
Proof.
by do 2 inversion 1; destruct s1, s2; cbn in *; subst.
Qed.
Lemma UMO_component_initial_state_spec :
forall {i : Address} {s : State},
UMO_component_initial_state_prop i s -> s = MkState [] i.
Proof.
by inversion 1; destruct s; cbn in *; subst.
Qed.
#[export] Instance HasBeenSentCapability_UMO_component
(i : Address) : HasBeenSentCapability (UMO_component i).
Proof.
apply Build_HasBeenSentCapability with (fun s m => m ∈ sentMessages s)
; [by intros s m; typeclasses eauto |].
split.
- by intros [] []; cbn in *; subst; cbn; apply not_elem_of_nil.
- intros l s im s' om [(Hvsp & Hovmp & Hv) Ht] m; cbn in *.
destruct l, im; cbn in *; invert_UMO_component_valid
; inversion Ht; subst; clear Ht; cbn.
+ by rewrite decide_False; cbn; firstorder congruence.
+ rewrite decide_True by done; cbn.
unfold Message; rewrite elem_of_cons.
by firstorder congruence.
Defined.
#[export] Instance HasBeenReceivedCapability_UMO_component
(i : Address) : HasBeenReceivedCapability (UMO_component i).
Proof.
eapply Build_HasBeenReceivedCapability with (fun s m => m ∈ receivedMessages s)
; [intros s m; typeclasses eauto | split].
- by intros [] []; cbn in *; subst; cbn; apply not_elem_of_nil.
- intros l s im s' om [(Hvsp & Hovmp & Hv) Ht] m; cbn in *.
destruct l, im; cbn in *; invert_UMO_component_valid
; inversion Ht; subst; clear Ht; cbn.
+ rewrite decide_True by done; cbn.
unfold Message; rewrite elem_of_cons.
by firstorder congruence.
+ by rewrite decide_False; cbn; firstorder congruence.
Defined.
#[export] Instance HasBeenDirectlyObservedCapability_UMO_component
(i : Address) : HasBeenDirectlyObservedCapability (UMO_component i) :=
HasBeenDirectlyObservedCapability_from_sent_received (UMO_component i).
(**
A reachability predicate specialized for VLSMs refining UMO.
[UMO_reachable C s] is equivalent to [constrained_state_prop V s] if
the valid transitions of VLSM <<V>> follow [UMO_component_transition]
and the validity predicate is a refinement of [UMO_component_valid]
which does not further restrict the [Send] case.
*)
Inductive UMO_reachable (C : State -> Message -> Prop) : State -> Prop :=
| reach_init :
forall a, UMO_reachable C (MkState [] a)
| reach_send :
forall s, UMO_reachable C s -> UMO_reachable C (s <+> MkObservation Send (MkMessage s))
| reach_recv :
forall s msg, C s msg -> UMO_reachable C s ->
UMO_reachable C (s <+> MkObservation Receive msg).
(**
An alternative induction principle for [UMO_reachable]
which has a single case for [addObservation] that covers
both [Send] and [Receive]. The hypotheses available in that
case use a [match] on the label to cover the differences between
the cases. This is useful for proofs where the [Send] and [Receive]
cases share some reasoning.
*)
Lemma UMO_reachable_ind'
(C : State -> Message -> Prop) (P : State -> Prop)
(Hinit : forall a, P (MkState [] a))
(Hextend : forall s l msg,
UMO_reachable C s ->
match l with
| Send => msg = MkMessage s
| Receive => C s msg
end ->
P s -> P (s <+> MkObservation l msg)) :
forall s, UMO_reachable C s -> P s.
Proof.
intros s Hs; induction Hs.
- by apply Hinit.
- by apply Hextend.
- by apply Hextend.
Qed.
(**
A specialized induction principle for [UMO_reachable]
when the conclusion begins with [forall m, m ∈ messages s -> ...].
This handles splitting [m ∈ messages (s <+> ob)] into
cases for [m ∈ messages s] and for the new observation,
and uses a new case [HPrev] to handle the [m ∈ messages s]
parts for both [Send] and [Receive].
Unfortunately the <<induction _ using _>> variant of the
[induction] tactic cannot recognize this lemma as an induction
principle, so it must be used with [refine] or [apply].
*)
Lemma UMO_reachable_elem_of_messages_ind
(C : State -> Message -> Prop)
(P : State -> Message -> Prop)
(HPrev : forall s (Hs : UMO_reachable C s) m ob,
m ∈ messages s ->
P s m -> P (s <+> ob) m)
(HSend : forall s (Hs : UMO_reachable C s),
(forall m', m' ∈ messages s -> P s m') ->
P (s <+> MkObservation Send (MkMessage s)) (MkMessage s))
(HRecv : forall s (Hs : UMO_reachable C s) mr,
C s mr ->
(forall m', m' ∈ messages s -> P s m') ->
P (s <+> MkObservation Receive mr) mr) :
forall s, UMO_reachable C s ->
forall m', m' ∈ messages s -> P s m'.
Proof.
intros s Hs; induction Hs.
- by inversion 1.
- by intros m' [-> | Hm']%elem_of_messages_addObservation; eauto.
- by intros m' [-> | Hm']%elem_of_messages_addObservation; eauto.
Qed.
Lemma UMO_reachable_impl (P Q : State -> Message -> Prop) (HPQ : forall s m, P s m -> Q s m) :
forall s, UMO_reachable P s -> UMO_reachable Q s.
Proof.
by induction 1; constructor; auto.
Qed.
(** [Send] transitions in a constrained state are ok. *)
Lemma input_constrained_transition_Send :
forall (i : Address) (m : Message),
constrained_state_prop (UMO_component i) (state m) ->
input_constrained_transition (UMO_component i)
Send (state m, None) (state m <+> MkObservation Send m, Some m).
Proof.
intros; do 2 (red; cbn); split_and!.
- done.
- by apply option_valid_message_None.
- by constructor.
- by do 3 f_equal; apply eq_Message.
Qed.
(** [Receive] transitions in a constrained state are ok. *)
Lemma input_constrained_transition_Receive :
forall (i : Address) (s : State) (m : Message),
constrained_state_prop (UMO_component i) s ->
input_constrained_transition (UMO_component i)
Receive (s, Some m) (s <+> MkObservation Receive m, None).
Proof.
intros; do 2 (red; cbn); split_and!; [done | | | done].
- by apply any_message_is_valid_in_preloaded.
- by constructor.
Qed.
(**
This lemma shows that for a VLSM based on UMO
reachability in the VLSM according to [constrained_state_prop]
is equivalent to [UMO_reachable] with a predicate
based on the VLSM's [valid] predicate, plus
a condition on the address.
In particular the VLSM must work over the same
[VLSMType] as UMO, of [Message], [State], and [Label],
the transition function must be [UMO_component_transition],
and the [valid] and [initial_state_prop] must be
restrictions of UMO's predicates.
This lemma usually should not be used directly, but
instead used to prove a "view" lemma for a
specific VLSM, such as [ELMO_reachable_view]
in the [VLSM.ELMO.ELMO] module.
*)
Lemma UMO_based_valid_reachable
(VM : VLSMMachine (Build_VLSMType Message State Label))
(V := mk_vlsm VM)
(Hinit_empty : forall si, initial_state_prop V si -> obs si = [])
(Hsend_spec : forall s om, constrained_state_prop V s -> valid V Send (s, om) <-> om = None)
(Htransition : forall l s om, transition V l (s, om) = UMO_component_transition l s om) :
forall (s : State),
constrained_state_prop V s
<->
UMO_reachable (fun s m => VM.(valid) Receive (s, Some m)) s
/\ initial_state_prop V (MkState [] (adr s)).
Proof.
split.
- intros Hs; induction Hs using valid_state_prop_ind.
+ destruct s as [ol a].
cbn in *; replace ol with (@nil Observation) in * by (specialize (Hinit_empty _ Hs); done).
by split; [apply reach_init |].
+ destruct Ht as [(_ & _ & Hvalid) Ht].
cbn in Ht; rewrite Htransition in Ht.
destruct IHHs as [IH Hadr].
by destruct l, om; inversion Ht; subst; auto using @UMO_reachable.
- intros [Hs Hadr].
induction Hs.
+ by apply initial_state_is_valid.
+ apply input_valid_transition_destination
with (l := Send) (s := s) (om := None) (om' := Some (MkMessage s)).
repeat split.
* by apply IHHs.
* by apply option_valid_message_None.
* by apply Hsend_spec; [apply IHHs |].
* by cbn; rewrite Htransition.
+ apply input_valid_transition_destination
with (l := Receive) (s := s) (om := Some msg) (om' := None).
repeat split; [| | done |].
* by apply IHHs.
* by apply any_message_is_valid_in_preloaded.
* by cbn; rewrite Htransition.
Qed.
(** ** Every valid state contains a unique valid trace leading to it
To prove this, we will need some basic properties of UMO components.
*)
Section sec_UMO_component_lemmas.
(** [Ui] is a notation for an [UMO_component] of address [i]. *)
Context
{i : Address}
(Ui : VLSM Message := UMO_component i)
.
Lemma UMO_reachable_valid_state_prop :
forall s, valid_state_prop Ui s ->
UMO_reachable (const (const True)) s /\ adr s = i.
Proof.
induction 1 using valid_state_prop_ind;
[by destruct s, Hs as [Hobs Hadr]; cbn in *; subst; split; [constructor 1 |] |].
by destruct Ht as [(_ & _ & Hv) Ht]; inversion Hv; subst; inversion Ht; subst;
destruct_and!; (split; [constructor |]).
Qed.
Lemma UMO_reachable_constrained_state_prop :
forall (s : State),
constrained_state_prop (UMO_component i) s
<->
UMO_reachable (fun _ _ => True) s /\ adr s = i.
Proof.
split.
- induction 1 using valid_state_prop_ind;
[by destruct s, Hs as [Hobs Hadr]; cbn in *; subst; split; [constructor 1 |] |].
by destruct Ht as [(_ & _ & Hv) Ht]; inversion Hv; subst; inversion Ht; subst;
destruct_and!; (split; [constructor |]).
- intros [Hur Hadr].
induction Hur; red; cbn in Hadr.
+ by apply initial_state_is_valid; cbv.
+ by eapply input_valid_transition_destination, input_constrained_transition_Send, IHHur.
+ by eapply input_valid_transition_destination, input_constrained_transition_Receive, IHHur.
Qed.
(** The initial state of [Ui] is unique. *)
Lemma vs0_uniqueness :
forall is : State,
UMO_component_initial_state_prop i is ->
is = ``(vs0 Ui).
Proof.
by intros []; inversion 1; cbv in *; by subst.
Qed.
(** Transitions of an UMO component preserve the address of the component. *)
Lemma UMO_component_transition_adr :
forall (s1 s2 : State) (iom oom : option Message) (lbl : Label),
UMO_component_transition lbl s1 iom = (s2, oom) ->
adr s2 = adr s1.
Proof.
by intros s1 s2 [im |] oom []; inversion_clear 1.
Qed.
(** For every trace segment, the initial and final state have the same address. *)
Lemma adr_of_states_within_constrained_trace :
forall (is s : State) (tr : list transition_item),
finite_constrained_trace_from_to Ui is s tr ->
adr s = adr is.
Proof.
induction 1; [done |].
transitivity (adr s); [done |].
eapply UMO_component_transition_adr.
by destruct Ht as [_ Ht]; cbn in Ht.
Qed.
Lemma adr_of_states_within_valid_trace :
forall (is s : State) (tr : list transition_item),
finite_valid_trace_from_to Ui is s tr ->
adr s = adr is.
Proof.
induction 1; [done |].
transitivity (adr s); [done |].
eapply UMO_component_transition_adr.
by destruct Ht as [_ Ht]; cbn in Ht.
Qed.
(** If a state is reachable, its address is the same as the address of the component. *)
Lemma adr_of_constrained_trace :
forall (is s : State) (tr : list transition_item),
finite_constrained_trace_init_to Ui is s tr ->
adr s = i.
Proof.
intros is s tr [Hfvt Hinit].
transitivity (adr is).
- by eapply adr_of_states_within_constrained_trace.
- by destruct Hinit, is; cbn in *.
Qed.
Lemma adr_of_valid_trace :
forall (is s : State) (tr : list transition_item),
finite_valid_trace_init_to Ui is s tr ->
adr s = i.
Proof.
intros is s tr [Hfvt Hinit].
transitivity (adr is).
- by eapply adr_of_states_within_valid_trace.
- by destruct Hinit, is; cbn in *.
Qed.
(** The address of a valid state is the same as the address of the component. *)
Lemma adr_of_constrained_state :
forall s : State,
constrained_state_prop Ui s -> adr s = i.
Proof.
intros s Hvsp.
apply valid_state_has_trace in Hvsp as (is & tr & Hfvti).
by eapply adr_of_constrained_trace.
Qed.
Lemma adr_of_valid_state :
forall s : State,
valid_state_prop Ui s -> adr s = i.
Proof.
intros s Hvsp.
apply valid_state_has_trace in Hvsp as (is & tr & Hfvti).
by eapply adr_of_valid_trace.
Qed.
(** Valid transitions lead to bigger states. *)
Lemma UMO_component_valid_transition_size :
forall (s1 s2 : State) (iom oom : option Message) (lbl : Label),
UMO_component_valid lbl s1 iom ->
UMO_component_transition lbl s1 iom = (s2, oom) ->
sizeState s1 < sizeState s2.
Proof.
by intros [] s2 [im |] oom []; do 2 inversion_clear 1; cbn; lia.
Qed.
Lemma input_constrained_transition_size :
forall (s1 s2 : State) (iom oom : option Message) (lbl : Label),
input_constrained_transition Ui lbl (s1, iom) (s2, oom) ->
sizeState s1 < sizeState s2.
Proof.
intros s1 s2 iom oom lbl [(_ & _ & Hvalid) Ht]; cbn in *.
by eapply UMO_component_valid_transition_size.
Qed.
(**
A [finite_valid_trace] is either empty or its final state is bigger than
its initial state.
*)
Lemma finite_constrained_trace_from_to_size :
forall (s1 s2 : State) (tr : list transition_item),
finite_constrained_trace_from_to Ui s1 s2 tr ->
s1 = s2 /\ tr = []
\/
sizeState s1 < sizeState s2.
Proof.
induction 1; [by left |].
assert (sizeState s' < sizeState s)
by (eapply input_constrained_transition_size; done).
by destruct IHfinite_valid_trace_from_to; [itauto congruence | itauto lia].
Qed.
(** If a trace leads from a state to itself, then it is empty. *)
Lemma finite_constrained_trace_from_to_inv :
forall (s : State) (tr : list transition_item),
finite_constrained_trace_from_to Ui s s tr -> tr = [].
Proof.
by intros s tr Hfvt; apply finite_constrained_trace_from_to_size in Hfvt; itauto lia.
Qed.
(**
The same lemmas as above, but for the component [Ui]. They follow from the
above lemmas because there is a VLSM inclusion from [Ui] to [Ui] preloaded
with all messages.
*)
Lemma input_valid_transition_size :
forall (s1 s2 : State) (iom oom : option Message) (lbl : Label),
input_valid_transition Ui lbl (s1, iom) (s2, oom) ->
sizeState s1 < sizeState s2.
Proof.
intros s1 s2 iom oom lbl Hivt.
eapply input_constrained_transition_size.
apply (@VLSM_incl_input_valid_transition _ Ui Ui); [| done].
by apply vlsm_incl_preloaded_with_all_messages_vlsm.
Qed.
Lemma finite_valid_trace_from_to_size :
forall (s1 s2 : State) (tr : list transition_item),
finite_valid_trace_from_to Ui s1 s2 tr ->
s1 = s2 /\ tr = []
\/
sizeState s1 < sizeState s2.
Proof.
intros s1 s2 tr Hfvt.
eapply finite_constrained_trace_from_to_size.
apply (@VLSM_incl_finite_valid_trace_from_to _ Ui Ui); [| done].
by apply vlsm_incl_preloaded_with_all_messages_vlsm.
Qed.
Lemma finite_valid_trace_from_to_inv :
forall (s : State) (tr : list transition_item),
finite_valid_trace_from_to Ui s s tr -> tr = [].
Proof.
intros s tr Hfvt.
eapply finite_constrained_trace_from_to_inv.
apply (@VLSM_incl_finite_valid_trace_from_to _ Ui Ui); [| done].
by apply vlsm_incl_preloaded_with_all_messages_vlsm.
Qed.
(**
[transition]s in any VLSM are deterministic, i.e., the final state and output
message are determined by the label, initial state and input message.
For UMO components, an extremely strong converse property also holds: the
label, initial state, input message and output message are all determined
by the final state of a valid transition. Basically, this is true because
every state contains the whole trace/history.
*)
Lemma input_constrained_transition_deterministic_conv :
forall (s1 s2 f : State) (iom1 iom2 oom1 oom2 : option Message) (lbl1 lbl2 : Label),
input_constrained_transition Ui lbl1 (s1, iom1) (f, oom1) ->
input_constrained_transition Ui lbl2 (s2, iom2) (f, oom2) ->
lbl1 = lbl2 /\ s1 = s2 /\ iom1 = iom2 /\ oom1 = oom2.
Proof.
intros s1 s2 f iom1 iom2 oom1 oom2 lbl1 lbl2 Hivt1 Hivt2
; inversion Hivt1 as [(_ & _ & Hvalid1) Ht1]; subst
; inversion Hivt2 as [(_ & _ & Hvalid2) Ht2]; subst.
destruct lbl1, lbl2, iom1, iom2; cbn in *
; inversion Ht1; subst; clear Ht1
; inversion Ht2; subst; clear Ht2
; invert_UMO_component_valid; auto.
by destruct s1, s2; cbn in *; subst; itauto.
Qed.
Lemma input_valid_transition_deterministic_conv :
forall (s1 s2 f : State) (iom1 iom2 oom1 oom2 : option Message) (lbl1 lbl2 : Label),
input_valid_transition Ui lbl1 (s1, iom1) (f, oom1) ->
input_valid_transition Ui lbl2 (s2, iom2) (f, oom2) ->
lbl1 = lbl2 /\ s1 = s2 /\ iom1 = iom2 /\ oom1 = oom2.
Proof.
intros s1 s2 f iom1 iom2 oom1 oom2 lbl1 lbl2 Hivt1 Hivt2.
by eapply input_constrained_transition_deterministic_conv;
apply (@VLSM_incl_input_valid_transition _ Ui Ui); [| done | | done];
apply vlsm_incl_preloaded_with_all_messages_vlsm.
Qed.
(** Every trace segment is fully determined by its initial and final state. *)
Lemma finite_constrained_trace_from_to_unique :
forall (s1 s2 : State) (l1 l2 : list transition_item),
finite_constrained_trace_from_to Ui s1 s2 l1 ->
finite_constrained_trace_from_to Ui s1 s2 l2 ->
l1 = l2.
Proof.
intros s1 s2 l1 l2 Hfvt1 Hfvt2; revert l2 Hfvt2.
induction Hfvt1 using finite_valid_trace_from_to_rev_ind; intros.
- by apply finite_constrained_trace_from_to_size in Hfvt2; itauto (congruence + lia).
- destruct Hfvt2 using finite_valid_trace_from_to_rev_ind; [| clear IHHfvt2].
+ apply finite_constrained_trace_from_to_size in Hfvt1.
apply input_constrained_transition_size in Ht.
by decompose [and or] Hfvt1; subst; clear Hfvt1; lia.
+ assert (l = l0 /\ s = s0 /\ iom = iom0 /\ oom = oom0)
by (eapply input_constrained_transition_deterministic_conv; done).
decompose [and] H; subst; clear H.
by f_equal; apply IHHfvt1.
Qed.
Lemma finite_valid_trace_from_to_unique :
forall (s1 s2 : State) (l1 l2 : list transition_item),
finite_valid_trace_from_to Ui s1 s2 l1 ->
finite_valid_trace_from_to Ui s1 s2 l2 ->
l1 = l2.
Proof.
by intros s1 s2 l1 l2 Hfvt1 Hfvt2;
eapply finite_constrained_trace_from_to_unique;
apply VLSM_incl_finite_valid_trace_from_to; [| done | | done];
apply vlsm_incl_preloaded_with_all_messages_vlsm.
Qed.
(** Every trace is determined by its final state. *)
(** Uniqueness *)
Lemma finite_constrained_trace_init_to_unique :
forall (s f : State) (l1 l2 : list transition_item),
finite_constrained_trace_init_to Ui s f l1 ->
finite_constrained_trace_init_to Ui s f l2 ->
l1 = l2.
Proof.
intros s f l1 l2 [Ht1 _] [Ht2 _].
by eapply finite_constrained_trace_from_to_unique.
Qed.
Lemma finite_valid_trace_init_to_unique :
forall (s f : State) (l1 l2 : list transition_item),
finite_valid_trace_init_to Ui s f l1 ->
finite_valid_trace_init_to Ui s f l2 ->
l1 = l2.
Proof.
by intros s f l1 l2 Hfvit1 Hfvit2;
eapply finite_constrained_trace_init_to_unique;
apply VLSM_incl_finite_valid_trace_init_to; [| done | | done];
apply vlsm_incl_preloaded_with_all_messages_vlsm.
Qed.
(** If a valid trace leads to state s, the trace extracted from s also leads to s. *)
Lemma finite_constrained_trace_init_to_state2trace :
forall (is s : State) (tr : list transition_item),
finite_constrained_trace_init_to Ui is s tr ->
finite_constrained_trace_init_to Ui is s (state2trace s).
Proof.
intros is s tr [Hfv Hinit]; cbn in *; revert Hinit.
induction Hfv using finite_valid_trace_from_to_rev_ind; intros.
- inversion Hinit; clear Hinit.
destruct si; cbn in *; subst; cbn.
repeat constructor. exists None.
by repeat constructor.
- specialize (IHHfv Hinit).
destruct Ht as [Hvalid Ht]; cbn in Ht.
destruct s as [obs adr], l, iom as [im |]
; inversion Ht; subst; clear Ht; cbn in *
; cycle 1; [done | done | |].
+ constructor; [| done].
by eapply extend_right_finite_trace_from_to; [apply IHHfv |]; auto.
+ constructor; [| done].
by eapply extend_right_finite_trace_from_to; [apply IHHfv |]; auto.
Qed.
Lemma finite_valid_trace_init_to_state2trace :
forall (is s : State) (tr : list transition_item),
finite_valid_trace_init_to Ui is s tr ->
finite_valid_trace_init_to Ui is s (state2trace s).
Proof.
intros is s tr [Hfv Hinit]; cbn in *; revert Hinit.
induction Hfv using finite_valid_trace_from_to_rev_ind; intros.
- inversion Hinit; clear Hinit.
destruct si; cbn in *; subst; cbn.
repeat constructor. exists None.
by repeat constructor.
- specialize (IHHfv Hinit).
destruct Ht as [Hvalid Ht]; cbn in Ht.
destruct s as [obs adr], l, iom as [im |]
; inversion Ht; subst; clear Ht; cbn in *
; cycle 1; [done | done | |].
+ constructor; [| done].
by eapply extend_right_finite_trace_from_to; [apply IHHfv |]; auto.
+ constructor; [| done].
by eapply extend_right_finite_trace_from_to; [apply IHHfv |]; auto.
Qed.
(** The trace extracted from the final state of another trace is equal to that trace. *)
Lemma finite_constrained_trace_init_to_state2trace_inv :
forall (is s : State) (tr : list transition_item),
finite_constrained_trace_init_to Ui is s tr ->
state2trace s = tr.
Proof.
intros is s tr Hfvti.
assert (Hfvti' : finite_constrained_trace_init_to Ui is s (state2trace s))
by (eapply finite_constrained_trace_init_to_state2trace; done).
by eapply finite_constrained_trace_init_to_unique.
Qed.
Lemma finite_valid_trace_init_to_state2trace_inv :
forall (is s : State) (tr : list transition_item),
finite_valid_trace_init_to Ui is s tr ->
state2trace s = tr.
Proof.
by intros is s tr Hfvti;
eapply finite_constrained_trace_init_to_state2trace_inv;
apply VLSM_incl_finite_valid_trace_init_to; [| done];
apply vlsm_incl_preloaded_with_all_messages_vlsm.
Qed.
(** The trace extracted from a reachable state [s] leads to [s]. *)
(** Existence *)
Lemma finite_constrained_trace_init_to_state2trace' :
forall (s : State),
constrained_state_prop Ui s ->
finite_constrained_trace_init_to Ui (``(vs0 Ui)) s (state2trace s).
Proof.
intros s Hs.
apply valid_state_has_trace in Hs as (is & tr & Htr).
apply finite_constrained_trace_init_to_state2trace_inv in Htr as Heqtr; subst.
replace (``(vs0 Ui)) with is; [done |].
by apply vs0_uniqueness, Htr.
Qed.
Lemma constrained_state_contains_unique_constrained_trace :
forall s : State,
constrained_state_prop Ui s ->
exists tr : list transition_item,
finite_constrained_trace_init_to Ui (``(vs0 Ui)) s tr
/\
forall tr' : list transition_item,
finite_constrained_trace_init_to Ui (``(vs0 Ui)) s tr' -> tr' = tr.
Proof.
intros s Hvsp.
exists (state2trace s); split.
- by eapply finite_constrained_trace_init_to_state2trace'.
- intros tr' Hfvt. symmetry.
by eapply finite_constrained_trace_init_to_state2trace_inv.
Qed.
(** Existence *)
Lemma finite_valid_trace_init_to_state2trace' :
forall (s : State),
valid_state_prop Ui s ->
finite_valid_trace_init_to Ui (``(vs0 Ui)) s (state2trace s).
Proof.
intros s Hs.
apply valid_state_has_trace in Hs as (is & tr & Htr).
apply finite_valid_trace_init_to_state2trace_inv in Htr as Heqtr; subst.
replace (``(vs0 Ui)) with is; [done |].
by apply vs0_uniqueness, Htr.
Qed.
Lemma valid_state_contains_unique_valid_trace :
forall s : State,
valid_state_prop Ui s ->
exists tr : list transition_item,
finite_valid_trace_init_to Ui (``(vs0 Ui)) s tr
/\
forall tr' : list transition_item,
finite_valid_trace_init_to Ui (``(vs0 Ui)) s tr' -> tr' = tr.
Proof.
intros s Hvsp.
exists (state2trace s); split.
- by eapply finite_valid_trace_init_to_state2trace'.
- intros tr' Hfvt. symmetry.
by eapply finite_valid_trace_init_to_state2trace_inv.
Qed.
(** ** The suffix ordering on states is a strict total order
<<s1>> is a state-suffix of <<s2>> if they have the same address and
<<s1>>'s observations are a strict suffix of <<s2>>'s observations.
*)
Record state_suffix (s1 s2 : State) : Prop :=
{
adrs_eq : adr s1 = adr s2;
obs_prefix : strict suffix (obs s1) (obs s2);
}.
#[export] Instance state_suffix_dec : RelDecision state_suffix :=
fun s1 s2 =>
match decide (adr s1 = adr s2) with
| left addr_eq =>
match decide (strict suffix (obs s1) (obs s2)) with
| left is_suffix => left (Build_state_suffix _ _ addr_eq is_suffix)
| right Hnot_suffix => right (fun H => Hnot_suffix (obs_prefix _ _ H))
end
| right Hnot_addr => right (fun H => Hnot_addr (adrs_eq _ _ H))
end.
(** We also define a variant of the suffix relation for messages. *)
Definition message_suffix (m1 m2 : Message) : Prop :=
state_suffix (state m1) (state m2).
(** The state-prefix relation is a strict partial order. *)
#[export] Instance Irreflexive_state_suffix :
Irreflexive state_suffix.
Proof.
by intros s (Hadr & Hobs1 & Hobs2).
Qed.
#[export] Instance Transitive_state_suffix :
Transitive state_suffix.
Proof.
intros s1 s2 s3 (Hadr12 & Hobs12 & Hobs12') (Hadr23 & Hobs23 & Hobs23').
split; [by congruence |].
by transitivity (obs s2).
Qed.
#[export] Instance StrictOrder_state_suffix :
StrictOrder state_suffix.
Proof.
by split; typeclasses eauto.
Qed.
Lemma state_suffix_empty_minimal :
forall (s : State) (a : Address), ~ state_suffix s (MkState [] a).
Proof.
intros s a [_ [[os Hsuf] Hstrict]]; contradict Hstrict.
by symmetry in Hsuf; apply app_nil in Hsuf as [-> ->]; exists [].
Qed.
Lemma state_suffix_empty_minimum :
forall (s : State), s = MkState [] (adr s) \/ state_suffix (MkState [] (adr s)) s.
Proof.
intros [[| ob obs] a]; cbn; [by left | right].
split; cbn; [done |].
split; cbn; [by apply suffix_nil |].
by intros H; apply suffix_nil_inv in H; subst.
Qed.
(**
If we add an observation to a state <<s>>, <<s>> is a suffix
of the resulting state.
*)
Lemma state_suffix_addObservation :
forall (s : State) (ob : Observation),
state_suffix s (s <+> ob).
Proof.
intros s ob.
constructor; cbn; [done |].
unfold addObservation; split.
- by apply suffix_cons_r.
- by apply suffix_cons_not.
Qed.
Lemma state_suffix_addObservations :
forall (s : State) (obs' : list Observation),
obs' <> [] -> state_suffix s (s <++> obs').
Proof.
intros s obs'.
constructor; cbn; [done |].
split.
- by apply suffix_app_r.
- by intros Hsuf; apply (suffix_app_inv obs' []), suffix_nil_inv in Hsuf.
Qed.
(** The initial state of a valid transition is a [state_suffix] of the final state. *)
Lemma state_suffix_of_UMO_component_valid_transition :
forall (lbl : Label) (s1 s2 : State) (iom oom : option Message),
UMO_component_valid lbl s1 iom ->
UMO_component_transition lbl s1 iom = (s2, oom) ->
state_suffix s1 s2.
Proof.
intros [] s1 s2 [im |] oom HValid; cbn
; intros H; inversion H; subst; clear H.
- by apply state_suffix_addObservation.
- by invert_UMO_component_valid.
- by invert_UMO_component_valid.
- by apply state_suffix_addObservation.
Qed.
(** The previous property carries over from transitions to valid transitions. *)
Lemma state_suffix_of_input_constrained_transition :
forall (lbl : Label) (s1 s2 : State) (iom oom : option Message),
input_constrained_transition Ui lbl (s1, iom) (s2, oom) ->
state_suffix s1 s2.
Proof.
intros lbl s1 s2 iom oom [(Hvsp & Hovmp & Hvalid) Ht]; cbn in Ht.
by eapply state_suffix_of_UMO_component_valid_transition; cycle 1.
Qed.
(**
If there is a trace segment from <<s1>> to <<s2>>, then either the states are
equal (because the trace is empty), or <<s1>> is a state-suffix of <<s2>>.
*)
Lemma state_suffix_of_finite_constrained_trace_from_to :
forall (s1 s2 : State) (tr : list transition_item),
finite_constrained_trace_from_to Ui s1 s2 tr ->
s1 = s2 \/ state_suffix s1 s2.
Proof.
induction 1; [by left |].
destruct IHfinite_valid_trace_from_to as [-> | IH]; right.
- by eapply state_suffix_of_input_constrained_transition; eauto.
- transitivity s; [| done].
by eapply state_suffix_of_input_constrained_transition; eauto.
Qed.
(**
[state_suffix_of_finite_constrained_trace_from_to] carries over from
trace segments to traces.
*)
Lemma state_suffix_of_finite_constrained_trace_init_to :
forall (s1 s2 : State) (tr : list transition_item),
finite_constrained_trace_init_to Ui s1 s2 tr ->
s1 = s2 \/ state_suffix s1 s2.
Proof.
intros s1 s2 tr [Hfvt Hinit].
by eapply state_suffix_of_finite_constrained_trace_from_to.
Qed.
(**
Every reachable state is either initial or the target of some transition.
This transition comes from a source state which is also reachable.
Additionally, if the label of the transition is [Send], we know that the
observation contains the source state.
*)
Lemma UMO_reachable_inv P :
forall s : State,
UMO_reachable P s ->
obs s = [] \/
exists (lbl : Label) (iom oom : option Message) (s' : State) (ob : Observation),
UMO_component_transition lbl s' iom = (s, oom) /\
s = s' <+> ob /\
UMO_reachable P s' /\
(lbl = Send -> message ob = MkMessage s').
Proof.
intros s Hs.
inversion Hs; [by left | right..].
- by eexists Send, None, (Some (MkMessage s0)), s0, _.
- by eexists Receive, (Some msg), None, s0, _.
Qed.
(**
If a reachable state <<s2>> is a result of adding an observation to a state
<<s1>>, then <<s1>> is also reachable. Additionally, if the observation's
label is [Send], then we can characterize the state <<s1>>.
*)
Lemma UMO_reachable_addObservation_inv P :
forall (s : State) (ob : Observation),
UMO_reachable P (s <+> ob) -> UMO_reachable P s.
Proof.
intros s ob Hvsp.
apply UMO_reachable_inv in Hvsp
as [[=] | (lbl & iom & oom & s' & ob' & Ht & Hadd & Hvsp & Hss')]; cbn in *.
by apply addObservation_inj in Hadd as [_ ->].
Qed.
Lemma UMO_reachable_addObservation_inv_Send_state P :
forall (s : State) (m : Message),
UMO_reachable P (s <+> MkObservation Send m) ->
s = state m.
Proof.
intros s m Hvsp.
apply UMO_reachable_inv in Hvsp
as [[=] | (lbl & iom & oom & s' & ob' & Ht & Hadd & Hvsp & Hlbl)]; cbn in *.
inversion Hadd.
replace (state m) with (state (message ob')) by (rewrite <- H0; cbn; done).
rewrite Hlbl; [by apply eq_State |].
by destruct lbl, iom; cbn in *; inversion Ht; subst; [| | done]
; apply (f_equal (fun x => length (obs x))) in Hadd; cbn in Hadd; lia.
Qed.
Lemma UMO_reachable_addObservation_inv_Send P :
forall (s : State) (m : Message),
UMO_reachable P (s <+> MkObservation Send m) ->
UMO_reachable P (state m).
Proof.
intros s m Hvsp.
erewrite <- UMO_reachable_addObservation_inv_Send_state; [| done].
by eapply UMO_reachable_addObservation_inv.
Qed.
Lemma UMO_reachable_addObservation_inv_message P :
forall (s : State) (ob : Observation),
UMO_reachable P (s <+> ob) -> label ob = Send ->
message ob = MkMessage s.
Proof.
intros s ob Hvsp Heq.
apply UMO_reachable_inv in Hvsp
as [[=] | (lbl & iom & oom & s' & ob' & Ht & Hadd & Hvsp & Hss')]; cbn in *.
apply addObservation_inj in Hadd as [-> ->].
apply Hss'. destruct lbl, iom; inversion Ht; subst; clear Ht; cbn in *; [done | | done | done].
by symmetry in H0; apply addObservation_acyclic in H0.
Qed.
(**
If a reachable state <<s2>> results from adding observations to a state <<s1>>,
then <<s1>> is also reachable.
*)
Lemma UMO_reachable_addObservations_inv P :
forall (s : State) (obs' : list Observation),
UMO_reachable P (s <++> obs') -> UMO_reachable P s.
Proof.
intros s obs'; revert s.
induction obs' as [| ob' obs']; cbn; intros s Hvsp.
- by rewrite <- addObservations_nil.
- by apply IHobs', UMO_reachable_addObservation_inv with ob'.
Qed.
(** If a state is constrained, after sending a message it's still constrained. *)
Lemma constrained_state_prop_Send :
forall (m : Message),
constrained_state_prop (UMO_component i) (state m) ->
constrained_state_prop (UMO_component i) (state m <+> MkObservation Send m).
Proof.
setoid_rewrite UMO_reachable_constrained_state_prop; cbn.
intros m [Hur Hadr]; split; [| done].
by destruct m; constructor.
Qed.
(** If a state is constrained, after receiving a message it's still constrained. *)
Lemma constrained_state_prop_Receive :
forall (s : State) (m : Message),
constrained_state_prop (UMO_component i) s ->
constrained_state_prop (UMO_component i) (s <+> MkObservation Receive m).
Proof.
setoid_rewrite UMO_reachable_constrained_state_prop; cbn.
intros s m [Hur Hadr]; split; [| done].
by destruct m; constructor.
Qed.
(**