-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSJ_CG.v
2019 lines (1869 loc) · 51.6 KB
/
SJ_CG.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
Require Import Coq.Lists.List.
Require Import Aniceto.Graphs.Graph.
Require Import Aniceto.Graphs.FGraph.
Require Import Aniceto.Graphs.DAG.
Require Import Omega.
Require CG.
Require Import SafeJoins.
Require Import Tid.
Require Import Node.
Require Import Coq.Structures.OrderedTypeEx.
Module MN := FMapAVL.Make Nat_as_OT.
Module MN_Facts := FMapFacts.Facts MN.
Module MN_Props := FMapFacts.Properties MN.
Require Import Aniceto.Map.
Module MN_Extra := MapUtil MN.
Module Events.
(** Reduces the known-set interpreting events of type [CG.event]. *)
Section Defs.
Notation known_set := (list (tid * tid)).
Inductive SJ: CG.trace -> known_set -> Prop :=
| sj_nil:
SJ nil nil
| sj_init:
forall k x t,
SJ t k ->
SJ ((x, CG.INIT)::t) k
| sj_fork:
forall k k' x y t,
SJ t k ->
SafeJoins.CheckOp k {| op_t := FORK; op_src := x; op_dst := y |} k' ->
SJ ((x, CG.FORK y)::t) k'
| sj_join:
forall k k' x y t,
SJ t k ->
SafeJoins.CheckOp k {| op_t := JOIN; op_src := x; op_dst := y |} k' ->
SJ ((x, CG.JOIN y)::t) k'
| sj_continue:
forall k x t,
SJ t k ->
SJ ((x, CG.CONTINUE)::t) k.
End Defs.
(*
Ltac simpl_red :=
repeat match goal with
| [ H : Reduces _ (_, CG.JOIN _) _ |- _ ] =>
inversion H; subst; clear H;
match goal with
| [ H1 : SafeJoins.CheckOp _ {| op_t := JOIN; op_src := _; op_dst := _ |} _ |- _ ] =>
inversion H1; subst; clear H1
end
| [ H: Reduces _ (_, CG.CONTINUE) _ |- _ ] =>
inversion H; subst; clear H
| [ H: Reduces _ (_, CG.INIT) _ |- _ ] =>
inversion H; subst; clear H
| [ H : Reduces _ (_, CG.FORK _) _ |- _ ] =>
inversion H; subst; clear H;
match goal with
| [ H1 : SafeJoins.CheckOp _ {| op_t := FORK; op_src := _; op_dst := _ |} _ |- _ ] =>
inversion H1; subst; clear H1
end
end.
*)
End Events.
Section Props.
Notation known_set := (list (tid * tid)).
Inductive command :=
| Cons: tid -> node -> command
| Copy : node -> command
| Append: node -> node -> command
| Nil: command.
Definition cg_safe_joins := list command.
Inductive CanJoin : node -> tid -> cg_safe_joins -> Prop :=
| can_join_cons:
forall l n c x,
CanJoin n x l ->
CanJoin n x (c :: l)
| can_join_eq:
forall l n x,
CanJoin (fresh l) x (Cons x n::l)
| can_join_neq:
forall l y n x,
CanJoin n x l ->
x <> y ->
CanJoin (fresh l) x (Cons y n :: l)
| can_join_copy:
forall n l x,
CanJoin n x l ->
CanJoin (fresh l) x (Copy n :: l)
| can_join_append_left:
forall x n' l n,
CanJoin n x l ->
CanJoin (fresh l) x (Append n n' :: l)
| can_join_append_right:
forall n' l n x,
CanJoin n' x l ->
CanJoin (fresh l) x (Append n n' :: l).
Inductive Free x (l:cg_safe_joins) : Prop :=
| free_def:
forall n,
List.In (Cons x n) l ->
Free x l.
Inductive Knows (vs:list tid) (sj:cg_safe_joins): tid * tid -> Prop :=
| knows_def:
forall x y nx,
MapsTo x nx vs ->
CanJoin nx y sj ->
Knows vs sj (x, y).
Definition EdgeToKnows vs sj k :=
forall p,
List.In p k ->
Knows vs sj p.
Definition KnowsToEdge vs sj k :=
forall p,
Knows vs sj p ->
List.In p k.
Definition FreeInGraph vs sj :=
forall x,
Free x sj ->
List.In x vs.
End Props.
Inductive SJ : CG.trace -> CG.computation_graph -> cg_safe_joins -> Prop :=
| sj_nil:
SJ nil (nil, nil) nil
| sj_init:
forall x cg cg' t sj,
SJ t cg sj ->
CG.CG ((x, CG.INIT)::t) cg' ->
SJ ((x, CG.INIT)::t) cg' (Nil::sj)
(**
Case Fork:
x -- fork --> y
\
`-- continue --> x'
We know that `x` is connected to y through a `fork` edge
and that `x` is connected to `x'` through a `continue` edge.
Let `ty` be the name of task associated with node `y`.
The result is:
- x' is defined as `Cons ty x`, which means that the names of `x'` are defined as
the names from `x` and also `ty`.
- y is defined as `Copy x` which means that it contains the same names as in `x`.
*)
| sj_fork:
forall x y x' ty vs es a b t cg sj,
SJ t cg sj ->
CG.CG ((a, CG.FORK b)::t) (ty::vs, CG.F (x,y)::CG.C (x,x')::es) ->
SJ ((a, CG.FORK b)::t) (ty::vs, CG.F (x,y)::CG.C (x,x')::es) (Copy x::Cons ty x::sj)
| sj_join:
forall x y x' ty vs es a b t sj cg,
SJ t cg sj ->
CG.CG ((a, CG.JOIN b)::t) (vs, CG.J (y,x') :: CG.C (x,x')::es) ->
MapsTo ty y vs ->
CanJoin x ty sj -> (* check: ty \in x *)
SJ ((a, CG.JOIN b)::t) (vs, CG.J (y,x') :: CG.C (x,x')::es) (Append x y :: sj)
| sj_continue:
forall x x' a es vs sj t cg,
SJ t cg sj ->
CG.CG ((a, CG.CONTINUE)::t) (vs, CG.C (x,x')::es) ->
SJ ((a, CG.CONTINUE)::t) (vs, CG.C (x,x')::es) (Copy x :: sj).
Ltac do_simpl :=
match goal with
| [ H: SJ ((_,CG.INIT) :: _) _ _ |- _ ] => inversion H; subst; clear H
| [ H: SJ ((_,CG.FORK _) :: _) _ _ |- _ ] => inversion H; subst; clear H
| [ H: SJ ((_,CG.JOIN _) :: _) _ _ |- _ ] => inversion H; subst; clear H
| [ H: SJ ((_,CG.CONTINUE) :: _) _ _ |- _ ] => inversion H; subst; clear H
end.
Section SJ_TO_CG.
Lemma sj_to_cg:
forall t cg sj,
SJ t cg sj ->
CG.CG t cg.
Proof.
intros.
inversion H; subst; auto using CG.cg_nil.
Qed.
Lemma sj_cg_fun:
forall t cg1 cg2 sj,
SJ t cg1 sj ->
CG.CG t cg2 ->
cg1 = cg2.
Proof.
eauto using sj_to_cg, CG.cg_fun.
Qed.
End SJ_TO_CG.
Ltac simpl_sj :=
repeat match goal with
| [ H1 : SJ ?t ?cg1 _, H2: CG.CG ?t ?cg2 |- _ ] =>
assert (cg1 = cg2) by eauto using sj_cg_fun; subst;
clear H2
end.
Ltac simpl_red :=
CG.simpl_red;
try simpl_sj.
Section LengthPreserves.
(* -------------------------------------------------- *)
Lemma sj_to_length:
forall t cg sj,
SJ t cg sj ->
length (fst cg) = length sj.
Proof.
induction t; intros; inversion H; subst; clear H; simpl; auto;
simpl_red;
try (inversion H5; subst; simpl_node; clear H5);
apply IHt in H2; simpl; auto with *.
Qed.
Lemma sj_to_length_0:
forall t vs es sj,
SJ t (vs, es) sj ->
length vs = length sj.
Proof.
intros.
assert (length (fst (vs, es)) = length sj) by eauto using sj_to_length.
simpl in *.
assumption.
Qed.
End LengthPreserves.
Section FreeInGraph.
(* -------------------------------------------------- *)
Lemma sj_to_free_in_graph:
forall t cg sj,
SJ t cg sj ->
FreeInGraph (fst cg) sj.
Proof.
induction t; intros. {
inversion H; subst.
unfold FreeInGraph; simpl; intros.
inversion H0.
inversion H1.
}
inversion H; subst; clear H; simpl_red; simpl in *;
apply IHt in H2; simpl in *; unfold FreeInGraph in *; intros;
inversion H; subst; clear H;
inversion H0; subst; clear H0;
eauto using in_cons, free_def;
inversion H; subst; clear H.
- inversion H0; subst; clear H0.
auto using in_eq.
- eauto using in_cons, free_def.
Qed.
Lemma sj_free_in_nodes:
forall t vs es sj x,
SJ t (vs, es) sj ->
Free x sj ->
List.In x vs.
Proof.
intros.
assert (Hf: FreeInGraph (fst (vs, es)) sj) by
eauto using sj_to_free_in_graph.
auto.
Qed.
End FreeInGraph.
Section ESafeJoins.
Let free_cons:
forall x sj c,
Free x sj ->
Free x (c::sj).
Proof.
intros.
inversion H.
eauto using List.in_cons, free_def.
Qed.
Let free_eq:
forall x n sj,
Free x (Cons x n :: sj).
Proof.
eauto using free_def, List.in_eq.
Qed.
Lemma can_join_to_free:
forall sj x n ,
CanJoin n x sj ->
Free x sj.
Proof.
induction sj; intros. {
inversion H.
}
inversion H; subst; clear H; eauto.
Qed.
Lemma can_join_absurd_lt:
forall sj n b,
NODE.lt (fresh sj) n ->
~ CanJoin n b sj.
Proof.
unfold NODE.lt, fresh, not; intros.
induction H0; simpl in *; auto with *.
Qed.
Let can_join_lt_fresh:
forall sj n b,
CanJoin n b sj ->
NODE.lt n (fresh sj).
Proof.
intros.
unfold NODE.lt, fresh.
induction H; simpl in *; auto with *.
Qed.
Lemma can_join_absurd_fresh:
forall sj b,
~ CanJoin (fresh sj) b sj.
Proof.
intros.
unfold not; intros.
apply can_join_lt_fresh in H.
unfold NODE.lt, fresh, not in *.
omega.
Qed.
Lemma can_join_lt:
forall x n sj c,
NODE.lt n (fresh sj) ->
CanJoin n x (c :: sj) ->
CanJoin n x sj.
Proof.
intros.
inversion H0; subst; try apply Lt.lt_irrefl in H; auto; contradiction.
Qed.
Lemma can_join_inv_cons_1:
forall sj x y n,
CanJoin (fresh sj) x (Cons y n :: sj) ->
x = y \/ (CanJoin n x sj /\ x <> y).
Proof.
intros.
inversion H; clear H.
- subst; apply can_join_absurd_fresh in H3; contradiction.
- intuition.
- subst.
intuition.
Qed.
Lemma can_join_inv_cons_2:
forall n x y sj,
CanJoin n x (Cons y n :: sj) ->
(x = y /\ CanJoin n y sj) \/ (x <> y /\ CanJoin n x sj) \/ (x = y /\ n = fresh sj).
Proof.
intros.
destruct (tid_eq_dec x y);
inversion H; subst; clear H; auto.
Qed.
Lemma can_join_inv_append:
forall x nx ny sj,
CanJoin (fresh sj) x (Append nx ny :: sj) ->
CanJoin nx x sj \/ CanJoin ny x sj.
Proof.
intros.
inversion H; clear H.
- subst; apply can_join_absurd_fresh in H3; contradiction.
- intuition.
- intuition.
Qed.
Lemma can_join_inv_copy_1:
forall sj x n,
CanJoin (fresh sj) x (Copy n :: sj) ->
CanJoin n x sj.
Proof.
intros.
inversion H; clear H.
- subst; apply can_join_absurd_fresh in H3; contradiction.
- auto.
Qed.
Lemma can_join_inv_copy_2:
forall n x sj,
CanJoin n x (Copy n :: sj) ->
CanJoin n x sj.
Proof.
intros.
inversion H; subst; clear H; assumption.
Qed.
Lemma knows_cons:
forall vs sj a b c x,
Knows vs sj (a, b) ->
x <> a ->
Knows (x :: vs) (c :: sj) (a, b).
Proof.
intros.
inversion H; subst; clear H.
simpl in *.
eauto using knows_def, can_join_cons, maps_to_cons.
Qed.
Lemma knows_cons_neq:
forall x y z n sj vs,
x <> y ->
y <> z ->
MapsTo x n vs ->
Knows vs sj (x, z) ->
length vs = length sj ->
Knows (x :: vs) (Cons y n :: sj) (x, z).
Proof.
intros.
inversion_clear H2.
simpl_node.
apply knows_def with (nx:=fresh vs).
- auto using maps_to_eq.
- apply maps_to_length_rw in H3.
rewrite H3.
apply can_join_neq; auto.
Qed.
Lemma knows_neq:
forall vs sj a b x c,
Knows vs sj (a, b) ->
a <> x ->
Knows (x :: vs) (c :: sj) (a, b).
Proof.
intros.
inversion H; subst; clear H.
eauto using knows_def, maps_to_cons, can_join_cons.
Qed.
Lemma knows_eq:
forall a vs b n sj,
length vs = length sj ->
Knows (a :: vs) (Cons b n :: sj) (a, b).
Proof.
intros.
apply knows_def with (nx:=fresh vs).
- auto using maps_to_eq.
- apply maps_to_length_rw in H.
rewrite H.
apply can_join_eq.
Qed.
Lemma knows_copy:
forall vs sj x y z n,
length vs = length sj ->
MapsTo x n vs ->
Knows vs sj (x, y) ->
Knows (z :: vs) (Copy n :: sj) (z, y).
Proof.
intros.
inversion H1; subst; clear H1.
apply knows_def with (nx:=fresh vs).
- auto using maps_to_eq.
- apply maps_to_length_rw in H.
rewrite H.
apply can_join_copy.
assert (nx = n) by eauto using maps_to_fun_2; subst.
assumption.
Qed.
Lemma knows_append_right:
forall y ny nx x vs b sj,
length vs = length sj ->
MapsTo y ny vs ->
Knows vs sj (y, b) ->
Knows (x :: vs) (Append nx ny :: sj) (x, b).
Proof.
intros.
inversion H1; subst; clear H1.
assert (nx0 = ny) by eauto using maps_to_fun_2; subst.
apply knows_def with (nx:=fresh vs).
- auto using maps_to_eq.
- apply maps_to_length_rw in H.
rewrite H.
apply can_join_append_right.
assumption.
Qed.
Lemma knows_append_left:
forall ny nx x vs b sj,
length vs = length sj ->
MapsTo x nx vs ->
Knows vs sj (x, b) ->
Knows (x :: vs) (Append nx ny :: sj) (x, b).
Proof.
intros.
inversion H1; subst; clear H1.
assert (nx0 = nx) by eauto using maps_to_fun_2; subst.
apply knows_def with (nx:=fresh vs).
- auto using maps_to_eq.
- apply maps_to_length_rw in H.
rewrite H.
apply can_join_append_left.
assumption.
Qed.
Lemma knows_to_free:
forall sj vs x y,
Knows vs sj (x, y) ->
Free y sj.
Proof.
induction sj; intros; inversion_clear H. {
inversion H1.
}
inversion_clear H1; eauto using free_cons, knows_def, can_join_to_free.
Qed.
Lemma knows_to_in_l:
forall x y vs sj,
Knows vs sj (x, y) ->
List.In x vs.
Proof.
intros.
inversion H; subst.
eauto using maps_to_to_in.
Qed.
Lemma knows_to_in_r:
forall x y vs sj t es,
SJ t (vs, es) sj ->
Knows vs sj (x, y) ->
List.In y vs.
Proof.
intros.
eapply sj_free_in_nodes; eauto using knows_to_free.
Qed.
Let knows_continue:
forall sj vs a b x nx,
MapsTo x nx vs ->
Knows vs sj (a, b) ->
length sj = length vs ->
Knows (x :: vs) (Copy nx :: sj) (a, b).
Proof.
intros.
destruct (tid_eq_dec a x). {
subst.
eauto using knows_copy.
}
auto using knows_neq.
Qed.
Lemma knows_fork_1:
forall vs es sj x y z n t,
SJ t (vs, es) sj ->
~ List.In y vs ->
MapsTo x n vs ->
Knows vs sj (x, z) ->
x <> y ->
Knows (x :: vs) (Cons y n :: sj) (x, z).
Proof.
intros.
apply knows_cons_neq; auto; eauto using sj_to_length_0.
unfold not; intros; subst.
eapply knows_to_in_r in H2; eauto.
Qed.
Lemma knows_fork_2:
forall x y z vs n sj t es,
SJ t (vs, es) sj ->
~ List.In z vs ->
MapsTo x n vs ->
x <> z ->
Knows vs sj (x, y) ->
Knows (z :: x :: vs) (Copy n :: Cons z n :: sj) (z, y).
Proof.
intros.
assert (Knows (x::vs) (Cons z n :: sj) (x, y)) by eauto using knows_fork_1.
apply knows_def with (nx:=fresh (x::vs)); auto using maps_to_eq.
assert (R: fresh (x::vs) = fresh (Cons z n :: sj)). {
apply maps_to_length_rw.
assert (R: length vs = length sj) by eauto using sj_to_length_0.
simpl; rewrite R; trivial.
}
rewrite R.
apply can_join_copy.
apply can_join_cons.
inversion H3; subst.
simpl_node.
assumption.
Qed.
Lemma knows_fork_3:
forall x y vs es sj t n,
SJ t (vs, es) sj ->
x <> y ->
Knows (y :: x :: vs) (Copy n :: Cons y n :: sj) (x, y).
Proof.
intros.
apply knows_cons; auto.
apply knows_eq; eauto using sj_to_length_0.
Qed.
Lemma knows_fork_4:
forall t vs es sj a b n y x,
SJ t (vs, es) sj ->
~ List.In y vs ->
MapsTo x n vs ->
Knows vs sj (a, b) ->
Knows (y :: x :: vs) (Copy n :: Cons y n :: sj) (a, b).
Proof.
intros.
assert (y <> a). {
unfold not; intros; subst.
apply knows_to_in_l in H2.
contradiction.
}
apply knows_cons; auto.
destruct (tid_eq_dec x a). {
subst.
assert (y <> b). {
unfold not; intros; subst.
eapply knows_to_in_r in H2; eauto.
}
apply knows_cons_neq; eauto using sj_to_length_0.
}
apply knows_cons; auto.
Qed.
Lemma knows_init:
forall a b sj vs x,
~ List.In x vs ->
Knows vs sj (a, b) ->
Knows (x :: vs) (Nil :: sj) (a, b).
Proof.
intros.
inversion H0; subst; clear H0.
apply knows_def with (nx:=nx).
- apply maps_to_cons; auto.
unfold not; intros; subst.
apply maps_to_to_in in H3.
contradiction.
- auto using can_join_cons.
Qed.
Lemma knows_inv_init:
forall x p vs sj,
length vs = length sj ->
Knows (x :: vs) (Nil :: sj) p ->
Knows vs sj p.
Proof.
intros.
inversion H0; subst; clear H0.
apply maps_to_inv in H1.
destruct H1 as [(?,?)|(?,mt)].
- subst.
apply maps_to_length_rw in H.
rewrite H in *.
inversion H2; subst.
apply can_join_absurd_fresh in H4.
contradiction.
- inversion H2; subst; clear H2.
eauto using knows_def.
Qed.
Lemma knows_inv_fork:
forall vs sj n x y a b,
length vs = length sj ->
Knows (y :: x :: vs) (Copy n :: Cons y n :: sj) (a, b) ->
(a = y /\ CanJoin (fresh (x::vs)) b (Copy n :: Cons y n :: sj)) \/
(a <> y /\ a = x /\ (CanJoin (fresh vs) b (Copy n :: Cons y n :: sj))) \/
(a <> y /\ a <> x /\ Knows vs sj (a,b)).
Proof.
intros.
inversion H0; subst; clear H0.
apply maps_to_inv in H3.
assert (R: fresh (x::vs) = fresh (Cons y n :: sj)). {
assert (R: length (x::vs) = length (Cons y n :: sj)). {
simpl.
rewrite H.
trivial.
}
auto using maps_to_length_rw.
}
destruct H3 as [(?,?)|(?,mt)]. {
left.
subst.
auto.
}
right.
apply maps_to_inv in mt.
destruct mt as [(?,?)|(?,mt)]. {
subst.
auto.
}
inversion H4; subst; clear H4. {
inversion H6; subst; clear H6.
- right.
split; auto; split; eauto using knows_def.
- apply maps_to_length_rw in H.
rewrite <- H in *.
simpl_node.
- apply maps_to_length_rw in H.
rewrite <- H in *.
simpl_node.
}
rewrite <- R in *.
rewrite fresh_cons_rw_next in *.
simpl_node.
Qed.
Lemma can_join_to_in:
forall vs es t sj x n,
SJ t (vs,es) sj ->
CanJoin n x sj ->
List.In x vs.
Proof.
eauto using can_join_to_free, sj_free_in_nodes.
Qed.
Definition KnowsTrans vs sj :=
forall x y z,
Knows vs sj (x, y) ->
Knows vs sj (y, z) ->
Knows vs sj (x, z).
Lemma can_join_inv_cons_3:
forall n x y sj,
n <> fresh sj ->
CanJoin n x (Cons y n :: sj) ->
CanJoin n x sj.
Proof.
intros.
apply can_join_inv_cons_2 in H0.
destruct H0 as [(?,?)|[(?,?)|(?,?)]].
- subst; auto.
- auto.
- contradiction.
Qed.
Lemma can_join_inv_fork_1:
forall x y n sj,
CanJoin (fresh sj) x (Copy n :: Cons y n :: sj) ->
x = y \/ CanJoin n x sj.
Proof.
intros.
inversion H; subst; clear H. {
apply can_join_inv_cons_1 in H3.
destruct H3 as [?|(?,?)]; subst; auto.
}
simpl in *.
omega.
Qed.
Lemma knows_append_2:
forall a b nx ny sj vs x y,
length vs = length sj ->
MapsTo x nx vs ->
Knows vs sj (a, b) ->
Knows vs sj (x, y) ->
Knows (x :: vs) (Append nx ny :: sj) (a, b).
Proof.
intros.
destruct (tid_eq_dec x a). {
subst.
inversion H1; inversion H2; subst; clear H1 H2.
simpl_node.
apply knows_def with (nx:=fresh sj).
+ apply maps_to_length_rw in H.
rewrite <- H.
auto using maps_to_eq.
+ auto using can_join_append_left.
}
auto using knows_cons.
Qed.
Lemma sj_to_edge_to_knows:
forall t k cg sj,
Events.SJ t k ->
SJ t cg sj ->
EdgeToKnows (fst cg) sj k.
Proof.
induction t; intros. {
inversion H0; subst; clear H0.
inversion H; subst; clear H.
unfold EdgeToKnows; simpl; intros.
contradiction.
}
inversion H0; subst; clear H0; simpl_red;
inversion H;subst; clear H; simpl in *;
rename sj0 into sj;
try (rename vs0 into vs);
try (rename k0 into k_; rename k into k'; rename k_ into k);
(assert (He: EdgeToKnows (fst (vs, es)) sj k) by auto; simpl in *);
unfold EdgeToKnows in *; intros;try (apply He in H);
destruct p as (c,d).
- apply knows_cons; auto.
unfold not; intros; subst.
apply knows_to_in_l in H.
contradiction.
- inversion H6; subst; clear H6.
apply fork_inv_in in H.
destruct H as [(?,?)|[(?,?)|?]]; subst;
eauto using knows_fork_2, knows_fork_3, knows_fork_4.
- inversion H7; subst; clear H7.
apply join_inv_in in H.
unfold FGraph.Edge in *.
apply He in H4.
destruct H as [(?,Hi)|Hi]; subst;
apply He in Hi; clear He IHt.
+ eapply knows_append_right; eauto using sj_to_length_0.
+ eauto using knows_append_2, sj_to_length_0.
- destruct (tid_eq_dec a0 c). {
subst.
apply knows_def with (nx:=fresh vs); auto using maps_to_eq.
assert (R: fresh vs = fresh sj). {
eauto using maps_to_length_rw, sj_to_length_0.
}
rewrite R.
apply can_join_copy.
inversion H; subst; clear H.
simpl_node.
auto.
}
auto using knows_cons.
Qed.
Lemma sj_edge_to_knows_0:
forall t k vs es sj p,
Events.SJ t k ->
SJ t (vs,es) sj ->
List.In p k ->
Knows vs sj p.
Proof.
assert (X:= sj_to_edge_to_knows).
unfold EdgeToKnows in *.
intros.
eapply X in H1; eauto.
simpl in *.
assumption.
Qed.
End ESafeJoins.
Section KnowsToEdge.
(* -------------------------------------------------- *)
Let nat_absurd_succ:
forall n,
n <> S n.
Proof.
intros.
unfold not; intros.
induction n.
- inversion H.
- inversion H; auto.
Qed.
Lemma knows_inv_append:
forall x n1 n2 a b sj vs,
length vs = length sj ->
Knows (x :: vs) (Append n1 n2 :: sj) (a,b) ->
(a = x /\ (CanJoin n1 b sj \/ CanJoin n2 b sj))
\/
(a <> x /\ Knows vs sj (a, b)).
Proof.
intros.
apply maps_to_length_rw in H.
inversion H0; subst; clear H0.
apply maps_to_inv in H3.
destruct H3 as [(?,?)|(?,?)]. {
subst.
rewrite H in *.
apply can_join_inv_append in H4.
intuition.
}
inversion H4; subst; clear H4.
- eauto using knows_def.
- rewrite <- H in *.
simpl_node.
- rewrite <- H in *.
simpl_node.
Qed.
Lemma knows_inv_copy:
forall x vs sj a b n,
length vs = length sj ->
Knows (x :: vs) (Copy n :: sj) (a,b) ->
(a = x /\ CanJoin n b sj) \/
(a <> x /\ Knows vs sj (a,b)).
Proof.
intros.
apply maps_to_length_rw in H.
inversion H0; subst; clear H0.
apply maps_to_inv in H3.
destruct H3 as [(?,?)|(?,?)].
+ subst.
rewrite H in *.
apply can_join_inv_copy_1 in H4.
auto.
+ inversion H4; subst; clear H4. {
eauto using knows_def.
}
rewrite <- H in *.
simpl_node.
Qed.
Lemma sj_to_knows_to_edge:
forall t cg k sj,
Events.SJ t k ->
SJ t cg sj ->
KnowsToEdge (fst cg) sj k.
Proof.
induction t; intros. {
inversion H; subst.
inversion H0; subst.
unfold KnowsToEdge; intros.
inversion H1; subst; simpl in *.
inversion H2.
}
inversion H0; subst; clear H0; simpl_red;
inversion H;subst; clear H; simpl in *;
rename sj0 into sj;
try (rename vs0 into vs);
try (rename k0 into k_; rename k into k'; rename k_ into k);
unfold KnowsToEdge in *; intros.
- apply knows_inv_init in H; eauto using sj_to_length_0.
- destruct p as (a,b).
inversion H6; subst; clear H6.
assert (R: fresh (a0::vs) = fresh (Cons ty x :: sj)). {
assert (length (a0::vs) = length (Cons ty x :: sj)). {
simpl.
erewrite sj_to_length_0; eauto.
}
auto using maps_to_length_rw.
}
assert (R2: fresh vs = fresh sj) by eauto using sj_to_length_0, maps_to_length_rw.
apply knows_inv_fork in H; eauto using sj_to_length_0.
destruct H as [(?,?)|[(?,(?,?))|(?,(?,?))]]; subst.
+ rewrite R in *.
apply can_join_inv_copy_1 in H0.
apply can_join_inv_cons_2 in H0.
destruct H0 as [(?,?)|[(?,?)|(?,?)]]; subst.
* eapply can_join_to_in in H0; eauto.
contradiction.
* eauto using in_fork_2, knows_def.
* rewrite <- R2 in *.
simpl_node.
+ rewrite R2 in *.
apply can_join_inv_fork_1 in H1.
destruct H1 as [?|?]. {
subst.
auto using in_fork_5.
}
eauto using in_fork, knows_def.
+ eauto using in_fork.
- inversion H7; subst; clear H7.
destruct p as (c,d).
apply knows_inv_append in H; eauto using sj_to_length_0.
destruct H as [(?,[?|?])|(?,?)];
subst; eauto using knows_def, in_join_2, in_join.
- destruct p as (a,b).
apply knows_inv_copy in H; eauto using sj_to_length_0.
destruct H as [(?,?)|(?,?)].
+ subst.
eauto using knows_def.
+ eauto.
Qed.
Lemma sj_to_knows_to_edge_0:
forall t vs es k sj p,
Events.SJ t k ->
SJ t (vs, es) sj ->
Knows vs sj p ->
List.In p k.
Proof.