-
Notifications
You must be signed in to change notification settings - Fork 2
/
CG.v
1447 lines (1313 loc) · 34.3 KB
/
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 Aniceto.Graphs.Graph.
Require Aniceto.Graphs.DAG.
Require Trace.
Require Import Coq.Lists.List.
Require Import Coq.Relations.Relation_Definitions.
Require Import Coq.Lists.ListSet.
Require Import Aniceto.ListSet.
Require Import Aniceto.Graphs.Graph.
Require Import Omega.
Require Import Tid.
Require Import Mid.
Require Import Cid.
Require Import Var.
Require Import Dep.
Require Import Node.
(* ----- end of boiler-plate code ---- *)
Set Implicit Arguments.
Require Import Aniceto.Graphs.DAG.
Require Import Coq.Relations.Relation_Operators.
Require Import Coq.Structures.OrderedTypeEx.
Section Defs.
Inductive op :=
| INIT: op
| FORK : tid -> op
| JOIN : tid -> op
| CONTINUE : op.
Definition event := (tid * op) % type.
Definition trace := list event.
Inductive edge_type :=
| E_FORK
| E_JOIN
| E_CONTINUE.
Definition cg_edge := (edge_type * (node * node)) % type.
Definition e_edge (e:cg_edge) := snd e.
Definition e_t (e:cg_edge) := fst e.
End Defs.
Notation F e := (E_FORK, e).
Notation J e := (E_JOIN, e).
Notation C e := (E_CONTINUE, e).
Notation cg_edges es := (map e_edge es).
Section Edges.
(**
When creating a tee, the inter edge is the only thing
that changes depending on the type of the node.
*)
Notation edge := (node * node) % type.
Definition computation_graph := (list tid * list cg_edge) % type.
Inductive Edge : list cg_edge -> edge_type -> (node * node) -> Prop :=
| edge_def:
forall es e,
List.In e es ->
Edge es (e_t e) (e_edge e).
Inductive HB_Edge es e : Prop :=
| hb_edge_def:
forall t,
Edge es t e ->
HB_Edge es e.
Lemma edge_eq:
forall es t x y,
List.In (t, (x,y)) es ->
Edge es t (x, y).
Proof.
intros.
remember (t,(x, y)) as e.
assert (R:(x, y) = e_edge e) by (subst; auto).
rewrite R.
assert (R2:t = e_t e) by (subst; auto).
rewrite R2.
auto using edge_def.
Qed.
Lemma hb_edge_in:
forall e es,
List.In e es ->
HB_Edge es (e_edge e).
Proof.
eauto using hb_edge_def, edge_def.
Qed.
Inductive CG: trace -> computation_graph -> Prop :=
| cg_nil:
CG nil (nil, nil)
| cg_init:
forall vs es x t,
CG t (vs, es) ->
~ List.In x vs ->
CG ((x, INIT)::t) (x::vs, es)
| cg_fork:
forall vs es y x nx nx' ny t,
CG t (vs, es) ->
~ List.In y vs ->
MapsTo x nx vs ->
MapsTo y ny (y::x::vs) ->
MapsTo x nx' (x::vs) ->
CG ((x, FORK y)::t) (y::x::vs, F (nx,ny) :: C (nx, nx') :: es)
| cg_join:
forall vs es x y nx ny nx' t,
CG t (vs, es) ->
x <> y ->
MapsTo x nx vs ->
MapsTo x nx' (x::vs) ->
MapsTo y ny (x::vs) ->
CG ((x, JOIN y)::t) (x::vs, J (ny, nx') :: C (nx, nx') :: es)
| cg_continue:
forall vs (es:list cg_edge) x prev curr t,
CG t (vs, es) ->
MapsTo x prev vs ->
MapsTo x curr (x::vs) ->
CG ((x, CONTINUE)::t) (x::vs, C (prev, curr) :: es).
Definition cg_nodes (cg:computation_graph) := fst cg.
(** Every node of the CG is an index of the list of vertices. *)
Definition EdgeToNode (cg:computation_graph) :=
forall x y,
HB_Edge (snd cg) (x, y) ->
Node x (fst cg) /\ Node y (fst cg).
Inductive SpawnPoint (x:tid) (n:node) : trace -> computation_graph -> Prop :=
| spawn_point_init:
forall vs es y t,
~ List.In y vs ->
SpawnPoint x n t (vs, es) ->
SpawnPoint x n ((y, INIT)::t) (y::vs, es)
| spawn_point_eq:
forall vs es n' n'' t y,
SpawnPoint x n ((y, FORK x)::t) (x::vs, F (n', n'') :: C(n', n) :: es)
| spawn_point_neq:
forall vs es e y z t e',
x <> y ->
SpawnPoint x n t (vs, es) ->
SpawnPoint x n ((z, FORK y)::t) (y::z::vs, (F e) :: (C e') :: es)
| spawn_point_continue:
forall vs es e y t,
SpawnPoint x n t (vs, es) ->
SpawnPoint x n ((y,CONTINUE)::t) (y::vs, (C e) :: es)
| spawn_point_join:
forall vs es e y z t e',
SpawnPoint x n t (vs, es) ->
SpawnPoint x n ((y,JOIN z)::t) (y::vs, (J e) :: (C e') :: es).
End Edges.
Section Props.
Inductive Prec : (node * node) -> cg_edge -> Prop :=
| prec_def:
forall e,
Prec (e_edge e) e.
Variable es: list cg_edge.
Let HB_Edge_alt e := List.Exists (Prec e) es.
Definition HB := Reaches (HB_Edge es).
Definition MHP x y : Prop := ~ HB x y /\ ~ HB y x.
Definition Le x y := x = y \/ HB x y.
Let in_edges_to_tees:
forall e,
List.In e (map e_edge es) ->
exists x, List.In x es /\ Prec e x.
Proof.
intros.
rewrite in_map_iff in *.
destruct H as (x, (Hi, He)).
exists x; split; auto.
subst; eauto using prec_def.
Qed.
Let in_tees_to_edges:
forall x e,
List.In x es ->
Prec e x ->
List.In e (map e_edge es).
Proof.
intros.
rewrite in_map_iff in *.
inversion H0;
subst;
eauto.
Qed.
Lemma hb_trans:
forall x y z,
HB x y ->
HB y z ->
HB x z.
Proof.
intros.
unfold HB in *.
eauto using reaches_trans.
Qed.
(** Comparable with respect to the happens-before relation [n1 < n2 \/ n2 < n1] *)
Inductive Comparable n1 n2 : Prop :=
| comparable_left_right:
HB n1 n2 ->
Comparable n1 n2
| comparable_right_left:
HB n2 n1 ->
Comparable n1 n2.
Lemma comparable_symm:
forall x y,
Comparable x y ->
Comparable y x.
Proof.
intros.
inversion H; auto using comparable_left_right, comparable_right_left.
Qed.
Lemma comparable_to_not_mhp:
forall x y,
Comparable x y ->
~ MHP x y.
Proof.
intros.
unfold not; intros.
inversion H0.
inversion H; contradiction.
Qed.
Inductive Relation x y : Prop :=
| L_HB_R: HB x y -> Relation x y
| R_HB_L: HB y x -> Relation x y
| EQ: x = y -> Relation x y
| PAR: MHP x y -> Relation x y.
Require Aniceto.Graphs.FGraph.
Lemma hb_dec:
forall x y,
{ HB x y } + { ~ HB x y }.
Proof.
Admitted.
(* TODO: prove this at the graph-level *)
End Props.
Section HB.
Lemma hb_edge_spec:
forall e es,
HB_Edge es e <-> List.In e (map e_edge es).
Proof.
split; intros.
- destruct H.
inversion H; subst; clear H.
simpl.
auto using in_map.
- rewrite in_map_iff in *.
destruct H as (?,(?,?)); subst.
simpl in *.
eauto using hb_edge_in.
Qed.
Lemma node_lt_length_left:
forall n1 n2 vs es,
EdgeToNode (vs,es) ->
List.In (n1, n2) (map e_edge es) ->
NODE.lt n1 (fresh vs).
Proof.
intros.
apply hb_edge_spec in H0.
apply H in H0.
destruct H0.
auto using node_lt.
Qed.
Let walk2_edge_false:
forall {A:Type} (x y:A) w,
~ Walk2 (fun _ => False) x y w.
Proof.
intuition.
destruct H.
destruct w.
- eauto using starts_with_inv_nil.
- eapply walk_to_edge; eauto using in_eq.
Qed.
Let reaches_edge_false:
forall {A:Type} (x y:A),
~ Reaches (fun _ => False) x y.
Proof.
intuition.
inversion H.
apply walk2_edge_false in H0; auto.
Qed.
Lemma hb_to_fgraph:
forall es x y,
HB es x y ->
Reaches (FGraph.Edge (map e_edge es)) x y.
Proof.
unfold HB.
intros.
apply reaches_impl with (E:=HB_Edge es); auto.
intros.
rewrite hb_edge_spec in *.
simpl in *.
auto.
Qed.
Lemma fgraph_to_hb:
forall es x y,
Reaches (FGraph.Edge (map e_edge es)) x y ->
HB es x y.
Proof.
unfold HB; intros.
apply reaches_impl with (E:=FGraph.Edge (map e_edge es)); auto.
intros.
rewrite hb_edge_spec.
auto.
Qed.
Lemma hb_fgraph_spec:
forall es x y,
HB es x y <->
Reaches (FGraph.Edge (map e_edge es)) x y.
Proof.
split; eauto using hb_to_fgraph, fgraph_to_hb.
Qed.
Lemma hb_cons:
forall e es x y,
HB es x y ->
HB (e :: es) x y.
Proof.
intros.
rewrite hb_fgraph_spec in *.
eauto using FGraph.reaches_cons.
Qed.
Lemma edge_to_hb:
forall x y t es,
HB ( (t, (x,y)) :: es) x y.
Proof.
intros.
rewrite hb_fgraph_spec.
simpl.
unfold FGraph.Edge.
auto using edge_to_reaches, in_eq.
Qed.
End HB.
Ltac simpl_red :=
repeat match goal with
| [ H: CG ((_, FORK _)::_) _ |- _ ] => inversion H; subst; clear H; simpl_node
| [ H: CG ((_, JOIN _)::_) _ |- _ ] => inversion H; subst; clear H; simpl_node
| [ H: CG ((_, CONTINUE)::_) _ |- _ ] => inversion H; subst; clear H; simpl_node
| [ H: CG ((_, INIT)::_) _ |- _ ] => inversion H; subst; clear H; simpl_node
end.
Section PropsEx.
(*
Lemma make_edge_to_node:
forall x,
EdgeToNode (make_cg x).
Proof.
intros.
unfold make_cg, EdgeToNode.
intros.
simpl in *.
rewrite hb_edge_spec in H.
simpl in *.
contradiction.
Qed.
*)
Lemma edge_to_node_nil:
EdgeToNode (nil, nil).
Proof.
unfold EdgeToNode; intros.
simpl in *.
rewrite hb_edge_spec in H.
inversion H.
Qed.
Lemma edge_to_node_init:
forall vs es x,
EdgeToNode (vs, es) ->
~ List.In x vs ->
EdgeToNode (x :: vs, es).
Proof.
unfold EdgeToNode; intros.
assert (Hx: HB_Edge (snd (vs, es)) (x0, y)). {
simpl in *; auto.
}
apply H in Hx.
destruct Hx; simpl in *.
split; auto using node_cons.
Qed.
Lemma edge_to_node_fork:
forall vs es y x n,
EdgeToNode (vs, es) ->
~ List.In y vs ->
MapsTo x n vs ->
EdgeToNode (y :: x :: vs, F (n, fresh (x :: vs)) :: C (n, fresh vs) :: es).
Proof.
unfold EdgeToNode; intros; simpl in *.
apply hb_edge_spec in H2; simpl in *.
destruct H2 as [Heq|[Heq|Hi]];
try (inversion Heq; subst;
split; eauto using maps_to_to_node, node_cons, node_eq).
apply hb_edge_spec in Hi.
apply H in Hi.
destruct Hi; split; auto using node_cons.
Qed.
Lemma edge_to_node_join:
forall vs es x y nx ny,
EdgeToNode (vs, es) ->
x <> y ->
MapsTo x nx vs ->
MapsTo y ny vs ->
EdgeToNode (x :: vs, J (ny, fresh vs) :: C (nx, fresh vs) :: es).
Proof.
unfold EdgeToNode; intros.
apply hb_edge_spec in H3; simpl in *.
destruct H3 as [Heq|[Heq|Hi]];
try (inversion Heq; subst;
split; eauto using maps_to_to_node, node_cons, node_eq).
apply hb_edge_spec in Hi.
apply H in Hi.
destruct Hi; split; auto using node_cons.
Qed.
Lemma edge_to_node_continue:
forall x n vs es,
EdgeToNode (vs, es) ->
MapsTo x n vs ->
EdgeToNode (x :: vs, C (n, fresh vs) :: es).
Proof.
unfold EdgeToNode; intros.
apply hb_edge_spec in H1; simpl in *.
destruct H1 as [Heq|Hi];
try (inversion Heq; subst;
split; eauto using maps_to_to_node, node_cons, node_eq).
apply hb_edge_spec in Hi.
apply H in Hi.
destruct Hi; split; auto using node_cons.
Qed.
Let edge_to_node_in:
forall vs es e a b,
EdgeToNode (vs, es) ->
List.In e es ->
e_edge e = (a, b) ->
Node a vs /\ Node b vs.
Proof.
intros.
assert (He: HB_Edge es (e_edge e)) by auto using hb_edge_in.
rewrite H1 in *.
apply H in He.
simpl in *.
assumption.
Qed.
Let edge_to_node_in_fst:
forall vs es e a b,
EdgeToNode (vs, es) ->
List.In e es ->
e_edge e = (a, b) ->
Node a vs.
Proof.
intros.
assert (He : Node a vs /\ Node b vs) by eauto.
destruct He; auto.
Qed.
Let edge_to_node_in_snd:
forall vs es e a b,
EdgeToNode (vs, es) ->
List.In e es ->
e_edge e = (a, b) ->
Node b vs.
Proof.
intros.
assert (He : Node a vs /\ Node b vs) by eauto.
destruct He; auto.
Qed.
Lemma cg_to_edge_to_node:
forall t cg,
CG t cg ->
EdgeToNode cg.
Proof.
induction t; intros. {
inversion H; subst; clear H.
auto using edge_to_node_nil.
}
inversion H; subst; clear H;
apply IHt in H2; auto; simpl_node.
- auto using edge_to_node_init.
- auto using edge_to_node_fork.
- eauto using edge_to_node_join.
- auto using edge_to_node_continue.
Qed.
Lemma f_edge_to_hb_edge:
forall es a b,
FGraph.Edge (map e_edge es) (a, b) ->
HB_Edge es (a, b).
Proof.
intros.
rewrite hb_edge_spec.
auto.
Qed.
Lemma edge_to_node_fresh_not_in:
forall vs es,
EdgeToNode (vs, es) ->
~ In (FGraph.Edge (map e_edge es)) (fresh vs).
Proof.
unfold not; intros.
destruct H0 as ((v1,v2),(Hx,Hy)).
assert (He: HB_Edge es (v1, v2)) by eauto using f_edge_to_hb_edge.
apply H in He.
destruct He as (Ha,Hb).
simpl in *.
destruct Hy; simpl in *; subst.
- apply node_absurd_fresh in Ha; contradiction.
- apply node_absurd_fresh in Hb; contradiction.
Qed.
Lemma in_edge_to_hb_edge:
forall p es,
List.In p (cg_edges es) ->
HB_Edge es p.
Proof.
intros.
apply in_map_iff in H.
destruct H as (e, (?,He)); subst.
auto using hb_edge_in.
Qed.
Lemma cg_edge_to_node_l:
forall t vs es x y,
CG t (vs, es) ->
List.In (x, y) (map e_edge es) ->
Node x vs.
Proof.
intros.
assert (Hen: EdgeToNode (vs, es)) by eauto using cg_to_edge_to_node.
assert (He: HB_Edge (snd (vs,es)) (x, y)). {
auto using in_edge_to_hb_edge.
}
apply Hen in He.
destruct He; auto.
Qed.
Lemma cg_edge_to_node_r:
forall t vs es x y,
CG t (vs, es) ->
List.In (x, y) (map e_edge es) ->
Node y vs.
Proof.
intros.
assert (Hen: EdgeToNode (vs, es)) by eauto using cg_to_edge_to_node.
assert (He: HB_Edge (snd (vs,es)) (x, y)). {
auto using in_edge_to_hb_edge.
}
apply Hen in He.
destruct He; auto.
Qed.
Lemma cg_hb_edge_to_node_r:
forall t vs es x y,
CG t (vs, es) ->
HB_Edge es (x, y) ->
Node y vs.
Proof.
intros.
assert (Hen: EdgeToNode (vs, es)) by eauto using cg_to_edge_to_node.
assert (He: HB_Edge (snd (vs,es)) (x, y)). {
auto using in_edge_to_hb_edge.
}
apply Hen in He.
destruct He; auto.
Qed.
Lemma edge_to_node_hb:
forall vs es x y,
EdgeToNode (vs, es) ->
HB es x y ->
Node x vs /\ Node y vs.
Proof.
intros.
destruct H0.
destruct w. {
apply walk2_nil_inv in H0; contradiction.
}
destruct w. {
apply walk2_inv_pair in H0.
destruct H0.
eauto.
}
apply walk2_inv in H0.
destruct H0 as (z, (R, (Hx, Hy))).
subst.
apply H in Hx.
destruct Hx as (Hx,_); split; auto; clear Hx.
destruct Hy.
destruct H1 as ((v3,v4), (Hx, Hy)).
simpl in *; subst.
eapply end_to_edge in Hx; eauto.
apply H in Hx.
destruct Hx; auto.
Qed.
Lemma edge_to_node_hb_fst:
forall vs es x y,
EdgeToNode (vs, es) ->
HB es x y ->
Node x vs.
Proof.
intros.
eapply edge_to_node_hb in H0; eauto.
destruct H0; auto.
Qed.
Lemma edge_to_node_hb_snd:
forall vs es x y,
EdgeToNode (vs, es) ->
HB es x y ->
Node y vs.
Proof.
intros.
eapply edge_to_node_hb in H0; eauto.
destruct H0; auto.
Qed.
Lemma hb_to_node_snd:
forall t vs es x y,
CG t (vs, es) ->
HB es x y ->
Node y vs.
Proof.
eauto using edge_to_node_hb_snd, cg_to_edge_to_node.
Qed.
Lemma hb_to_node_fst:
forall t vs es x y,
CG t (vs, es) ->
HB es x y ->
Node x vs.
Proof.
eauto using edge_to_node_hb_fst, cg_to_edge_to_node.
Qed.
Lemma hb_edge_cons:
forall es e a b,
HB_Edge es (a, b) ->
HB_Edge (e :: es) (a, b).
Proof.
intros.
rewrite hb_edge_spec in *.
simpl in *.
intuition.
Qed.
Lemma hb_impl_cons:
forall es x y e,
HB es x y ->
HB (e::es) x y.
Proof.
intros.
rewrite hb_fgraph_spec in *; simpl in *;
eauto using FGraph.reaches_impl_cons.
Qed.
Lemma cg_fun:
forall t cg cg',
CG t cg ->
CG t cg' ->
cg' = cg.
Proof.
induction t; intros. {
inversion H; inversion H0; subst; auto.
}
inversion H; subst; clear H; simpl_node;
inversion H0; subst; clear H0;
assert (Heq: (vs0, es0) = (vs,es)) by auto;
inversion Heq; subst; clear Heq; simpl_node; trivial.
Qed.
Lemma hb_impl:
forall a t cg cg',
CG t cg ->
CG (a::t) cg' ->
forall x y,
HB (snd cg) x y ->
HB (snd cg') x y.
Proof.
intros.
destruct a as (?,[]);
inversion H0; subst; clear H0; simpl_node; simpl in *;
assert (cg = (vs,es)) by eauto using cg_fun; subst;
eauto using hb_impl_cons.
Qed.
Lemma hb_impl_0:
forall a t vs es vs' es',
CG t (vs,es) ->
CG (a::t) (vs', es') ->
forall x y,
HB es x y ->
HB es' x y.
Proof.
intros.
assert (R1: es = snd (vs,es)) by auto.
assert (R2: es' = snd (vs',es')) by auto.
rewrite R1 in H1.
rewrite R2.
eauto using hb_impl.
Qed.
Lemma hb_absurd_node_l:
forall vs es n,
EdgeToNode (vs, es) ->
~ HB es (fresh vs) n.
Proof.
intros.
unfold not; intros N.
apply edge_to_node_hb_fst with (vs:=vs) in N; eauto; simpl_node.
Qed.
Lemma hb_absurd_node_r:
forall vs es n,
EdgeToNode (vs, es) ->
~ HB es n (fresh vs).
Proof.
intros.
unfold not; intros N.
apply edge_to_node_hb_snd with (vs:=vs) in N; eauto; simpl_node.
Qed.
Lemma hb_absurd_node_next_l:
forall vs es n,
EdgeToNode (vs, es) ->
~ HB es (node_next (fresh vs)) n.
Proof.
intros.
unfold not; intros N.
apply edge_to_node_hb_fst with (vs:=vs) in N; eauto; simpl_node.
Qed.
Lemma hb_absurd_node_next_r:
forall vs es n,
EdgeToNode (vs, es) ->
~ HB es n (node_next (fresh vs)).
Proof.
intros.
unfold not; intros N.
apply edge_to_node_hb_snd with (vs:=vs) in N; eauto; simpl_node.
Qed.
End PropsEx.
Ltac hb_simpl :=
repeat match goal with
| [ H1:HB ?es (fresh ?vs) _,H2: EdgeToNode (?vs, ?es) |- _] =>
apply hb_absurd_node_l in H1; auto; contradiction
| [ H1:HB ?es (node_next (fresh ?vs) )_,H2: EdgeToNode (?vs, ?es) |- _] =>
apply hb_absurd_node_next_l in H1; auto; contradiction
end.
Section DAG.
Import Aniceto.Graphs.DAG.
Let LtEdge e := NODE.lt (fst e) (snd e).
Definition LtEdges es := List.Forall LtEdge es.
Let Sup x (e:node*node) := NODE.lt (snd e) x.
Definition HasSup cg := List.Forall (Sup (fresh (A:=tid) (fst cg))) (map e_edge (snd cg)).
Let edge_to_lt:
forall es x y,
LtEdges es ->
FGraph.Edge es (x, y) ->
NODE.lt x y.
Proof.
intros.
unfold FGraph.Edge in *.
unfold LtEdges in *.
rewrite List.Forall_forall in H.
apply H in H0.
auto.
Qed.
Let walk_2_to_lt:
forall w x y es,
LtEdges es ->
Walk2 (FGraph.Edge es) x y w ->
NODE.lt x y.
Proof.
induction w; intros. {
apply walk2_nil_inv in H0.
contradiction.
}
inversion H0; subst; clear H0.
destruct a as (v1,v2).
apply starts_with_eq in H1; subst.
destruct w as [|(a,b)]. {
apply ends_with_eq in H2.
subst.
assert (Hi: FGraph.Edge es (x,y)). {
eapply walk_to_edge; eauto using List.in_eq.
}
eauto.
}
assert (Hlt: NODE.lt x v2). {
assert (FGraph.Edge es (x, v2)) by (eapply walk_to_edge; eauto using List.in_eq).
eauto.
}
inversion H3; subst; clear H3.
apply linked_inv in H6; symmetry in H6; subst.
apply ends_with_inv in H2.
assert (NODE.lt a y) by eauto using walk2_def, starts_with_def.
eauto using NODE.lt_trans.
Qed.
Let reaches_to_lt:
forall x y es,
LtEdges es ->
Reaches (FGraph.Edge es) x y ->
NODE.lt x y.
Proof.
intros.
inversion H0.
eauto.
Qed.
Lemma hb_to_lt:
forall x y es,
LtEdges (map e_edge es) ->
HB es x y ->
NODE.lt x y.
Proof.
intros.
apply hb_to_fgraph in H0.
eauto.
Qed.
Lemma lt_edges_to_dag:
forall (es:list (node*node)),
LtEdges es ->
DAG (FGraph.Edge es).
Proof.
intros.
unfold DAG.
intros.
unfold not; intros.
apply reaches_to_lt in H0; auto.
unfold NODE.lt in *.
omega.
Qed.
Let maps_to_lt_edge_cons:
forall {A:Type} (x:A) n vs,
MapsTo x n vs ->
LtEdge (n, fresh (x :: vs)).
Proof.
intros.
apply maps_to_lt in H.
unfold NODE.lt, fresh in *.
unfold LtEdge; simpl in *.
omega.
Qed.
Let maps_to_lt_edge:
forall {A:Type} (x:A) n vs,
MapsTo x n vs ->
LtEdge (n, fresh vs).
Proof.
intros.
apply maps_to_lt in H.
unfold NODE.lt, fresh in *.
unfold LtEdge; simpl in *.
omega.
Qed.
Lemma cg_to_lt_edges:
forall t (cg:computation_graph),
CG t cg ->
LtEdges (map e_edge (snd cg)).
Proof.
induction t; intros. {
inversion H; subst; simpl.
unfold LtEdges.
auto using List.Forall_nil.
}
inversion H; subst; clear H; simpl_node; simpl in *; auto;
apply IHt in H2; simpl in *; unfold LtEdges in *; auto;
eauto using List.Forall_cons.
Qed.
Lemma cg_to_lt_edges_0:
forall t vs es,
CG t (vs, es) ->
LtEdges (map e_edge es).
Proof.
intros.
assert (R: es = snd (vs,es)) by auto; rewrite R.
eauto using cg_to_lt_edges.
Qed.
Lemma hb_irrefl:
forall x es,
LtEdges (map e_edge es) ->
~ HB es x x.
Proof.
intros.
apply lt_edges_to_dag in H.
unfold DAG in *.
unfold not; intros.
apply hb_fgraph_spec in H0.
simpl in *.
apply H in H0.
contradiction.
Qed.
Lemma cg_irrefl:
forall t cg,
CG t cg ->
forall x, ~ HB (snd cg) x x.
Proof.
intros.
apply cg_to_lt_edges in H.
auto using hb_irrefl.
Qed.
Lemma cg_irrefl_0:
forall t vs es,
CG t (vs, es) ->
forall x, ~ HB es x x.
Proof.
intros.
eapply cg_irrefl in H; simpl; eauto.
Qed.
Let sub_fresh_cons_lhs:
forall {A:Type} (x:A) vs n,
Sup (fresh (x :: vs)) (n, fresh vs).
Proof.
intros.
unfold Sup.
simpl.
unfold NODE.lt, fresh; simpl; omega.
Qed.
Let sub_fresh_cons_cons:
forall {A:Type} (x y:A) vs n,
MapsTo x n vs ->
Sup (fresh (y :: x :: vs)) (n, fresh vs).
Proof.
intros.
unfold Sup.
simpl.
unfold NODE.lt, fresh; simpl; omega.
Qed.
Let lt_fresh_cons:
forall {A:Type} (x:A) vs,
NODE.lt (fresh vs) (fresh (x::vs)).
Proof.
intros.
unfold NODE.lt, fresh; simpl; auto.
Qed.
Let sub_fresh_cons:
forall vs x (t:tid),
Sup (fresh vs) x ->
Sup (fresh (t :: vs)) x.
Proof.